teleo-infrastructure/ops/backfill-descriptions.py
m3taversal 681afad506
Some checks failed
CI / lint-and-test (push) Has been cancelled
Consolidate pipeline code from teleo-codex + VPS into single repo
Sources merged:
- teleo-codex/ops/pipeline-v2/ (11 newer lib files, 5 new lib modules)
- teleo-codex/ops/ (agent-state, diagnostics expansion, systemd units, ops scripts)
- VPS /opt/teleo-eval/telegram/ (10 new bot files, agent configs)
- VPS /opt/teleo-eval/pipeline/ops/ (vector-gc, backfill-descriptions)
- VPS /opt/teleo-eval/sync-mirror.sh (Bug 2 + Step 2.5 fixes)

Non-trivial merges:
- connect.py: kept codex threshold (0.65) + added infra domain parameter
- watchdog.py: kept infra version (stale_pr integration, superset of codex)
- deploy.sh: codex rsync version (interim, until VPS git clone migration)
- diagnostics/app.py: codex decomposed dashboard (14 new route modules)

81 files changed, +17105/-200 lines

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 16:52:26 +01:00

60 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Backfill description column for merged PRs that have no description.
Reads claim frontmatter from branches via git show (works on bare repos).
"""
import sqlite3
import yaml
import os
import sys
REPO = os.environ.get("REPO_DIR", "/opt/teleo-eval/workspaces/teleo-codex.git")
DB = os.environ.get("PIPELINE_DB", "/opt/teleo-eval/pipeline/pipeline.db")
def extract_description(branch):
result = os.popen(f"cd {REPO} && git diff --name-only origin/main...origin/{branch} 2>/dev/null").read()
changed = [f for f in result.strip().split("\n") if f.endswith(".md") and "domains/" in f]
descs = []
for fpath in changed[:10]:
content = os.popen(f"cd {REPO} && git show origin/{branch}:{fpath} 2>/dev/null").read()[:2000]
if not content or not content.startswith("---"):
continue
end = content.find("---", 3)
if end < 0:
continue
try:
fm = yaml.safe_load(content[3:end])
except Exception:
continue
if fm and isinstance(fm, dict) and fm.get("description"):
d = fm["description"].strip().strip('"')
if len(d) > 10:
descs.append(d)
return " | ".join(descs[:5]) if descs else None
def main():
conn = sqlite3.connect(DB)
rows = conn.execute(
"SELECT number, branch FROM prs WHERE status='merged' AND (description IS NULL OR description='')"
).fetchall()
print(f"PRs needing descriptions: {len(rows)}")
updated = 0
for pr_num, branch in rows:
desc = extract_description(branch)
if desc:
conn.execute("UPDATE prs SET description=? WHERE number=?", (desc, pr_num))
updated += 1
if updated % 50 == 0:
conn.commit()
print(f" ...{updated} updated")
conn.commit()
conn.close()
print(f"Done. Updated {updated}/{len(rows)} PRs with descriptions.")
if __name__ == "__main__":
main()