#!/usr/bin/env python3 """Write evidences/agent-runs/evidence-agent.json from the collector summary. Fast-path handoff writer for evidence-agent: after the standard collector (collect_evidence.py) succeeds, this script converts evidences/evidence_summary_for_agent.json into the evidence-agent output contract without loading any evidence artifact into the chat context. Run from the workspace root (the directory containing evidences/). """ from __future__ import annotations import json import sys from pathlib import Path def main() -> int: root = Path("evidences") summary_path = root / "evidence_summary_for_agent.json" if not summary_path.is_file(): print( f"error: {summary_path} not found; run the standard collector first " "or write evidence-agent.json manually from collected evidence", file=sys.stderr, ) return 1 summary = json.loads(summary_path.read_text(encoding="utf-8")) agent_dir = root / "agent-runs" agent_dir.mkdir(parents=True, exist_ok=True) evidence_files = sorted( str(path) for path in root.glob("*.json") if path.is_file() ) txt_summary = root / "evidence_summary_for_agent.txt" if txt_summary.exists(): evidence_files.append(str(txt_summary)) perf = root / "perf.jsonl" if perf.exists(): evidence_files.append(str(perf)) payload = { "agent": "evidence-agent", "status": summary.get("status") or "ok", "summary": summary.get("summary") or "Standard collector completed; see evidence artifacts.", "scope": summary.get("scope") or {}, "evidence_files": evidence_files, "missing_evidence": summary.get("missing_evidence") or [], "warnings": summary.get("warnings") or [], "next_recommended_skills": summary.get("next_recommended_skills") or [], "critical_evidence_hints": summary.get("critical_evidence_hints") or [], } (agent_dir / "evidence-agent.json").write_text( json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8", ) print( "evidence-agent.json written:", f"status={payload['status']}", f"files={len(payload['evidence_files'])}", f"hints={len(payload['critical_evidence_hints'])}", f"missing={len(payload['missing_evidence'])}", ) return 0 if __name__ == "__main__": raise SystemExit(main())