teleo-infrastructure/scripts/nightly-reweave.sh
m3taversal d2aec7fee3
Some checks are pending
CI / lint-and-test (push) Waiting to run
feat: reorganize repo with clear directory boundaries and agent ownership
Move scattered root-level files into categorized directories:
- deploy/ — deployment + mirror scripts (Ship)
- scripts/ — one-off backfills + migrations (Ship)
- research/ — nightly research + prompts (Ship)
- docs/ — all operational documentation (shared)

Delete 3 dead cron scripts replaced by pipeline daemon:
- batch-extract-50.sh, evaluate-trigger.sh, extract-cron.sh

Add CODEOWNERS mapping every path to its owning agent.
Add README with directory structure, ownership table, and VPS layout.
Update deploy.sh paths to match new structure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 18:20:13 +01:00

48 lines
1.6 KiB
Bash
Executable file

#!/bin/bash
# Nightly reweave — connect orphan claims via vector similarity + Haiku classification.
# Creates a PR per run for Leo to review.
#
# Cron: 0 1 * * * /opt/teleo-eval/pipeline/ops/nightly-reweave.sh >> /opt/teleo-eval/logs/reweave.log 2>&1
#
# Pentagon-Agent: Epimetheus <0144398e-4ed3-4fe2-95a3-3d72e1abf887>
set -euo pipefail
PIPELINE_DIR="/opt/teleo-eval/pipeline"
EMBED_SCRIPT="/opt/teleo-eval/embed-claims.py"
REWEAVE_SCRIPT="${PIPELINE_DIR}/reweave.py"
LOG_DIR="/opt/teleo-eval/logs"
LOCK_FILE="/opt/teleo-eval/workspaces/.reweave-nightly.lock"
# Batch size per night — 50 orphans is ~$0.05 in Haiku calls
BATCH_SIZE=50
echo "=== Nightly reweave started at $(date -u +%Y-%m-%dT%H:%M:%SZ) ==="
# Prevent concurrent runs
if [ -f "$LOCK_FILE" ]; then
LOCK_AGE=$(( $(date +%s) - $(stat -c %Y "$LOCK_FILE" 2>/dev/null || stat -f %m "$LOCK_FILE") ))
if [ "$LOCK_AGE" -lt 3600 ]; then
echo "Lock file exists and is ${LOCK_AGE}s old — another reweave is running. Exiting."
exit 0
fi
echo "Stale lock (${LOCK_AGE}s old) — removing."
rm -f "$LOCK_FILE"
fi
trap 'rm -f "$LOCK_FILE"' EXIT
touch "$LOCK_FILE"
# Step 1: Backfill missing embeddings
echo "--- Step 1: Embedding backfill ---"
if [ -f "$EMBED_SCRIPT" ]; then
python3 "$EMBED_SCRIPT" 2>&1 | tail -5
echo "Embedding backfill complete."
else
echo "WARNING: embed-claims.py not found at ${EMBED_SCRIPT} — skipping backfill"
fi
# Step 2: Run reweave
echo "--- Step 2: Reweave (batch=${BATCH_SIZE}) ---"
python3 "$REWEAVE_SCRIPT" --max-orphans "$BATCH_SIZE" 2>&1
echo "=== Nightly reweave finished at $(date -u +%Y-%m-%dT%H:%M:%SZ) ==="