Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
A comprehensive collection of Agent Skills for context engineering, multi-agent architectures, and production agent systems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
researcher/scripts/loop_status.py
1#!/usr/bin/env python32"""Human-facing status dashboard for the autonomous research loop."""34from __future__ import annotations56import argparse7import json8import sys9from pathlib import Path10from typing import Any1112from loop_common import (13QUEUE_DIR,14REPORTS_DIR,15RESEARCHER,16ROOT,17categorize_runs,18load_run_state,19read_jsonl,20runs_created_today,21utc_now,22)232425STATUS_FILE = REPORTS_DIR / "status.md"26PARKED_REVIEW_FILE = REPORTS_DIR / "parked-review.md"272829def latest_benchmark() -> dict[str, Any] | None:30history = REPORTS_DIR / "benchmark-history.jsonl"31if not history.exists():32return None33last: dict[str, Any] | None = None34for line in history.read_text(encoding="utf-8").splitlines():35if not line.strip():36continue37try:38last = json.loads(line)39except json.JSONDecodeError:40continue41return last424344def latest_snapshot() -> Path | None:45snapshot_dir = REPORTS_DIR / "snapshots"46if not snapshot_dir.exists():47return None48candidates = sorted(snapshot_dir.glob("*.md"))49return candidates[-1] if candidates else None505152def render_status() -> dict[str, Any]:53buckets = categorize_runs()54parked = read_jsonl(QUEUE_DIR / "parked.jsonl")55inbox = read_jsonl(QUEUE_DIR / "inbox.jsonl")56quarantine = read_jsonl(QUEUE_DIR / "quarantine.jsonl")57done = read_jsonl(QUEUE_DIR / "done.jsonl")58bench = latest_benchmark()59snapshot = latest_snapshot()6061lines = [62f"# Researcher Loop Status",63f"_generated {utc_now()}_",64"",65"## Queue",66f"- inbox: {len(inbox)}",67f"- active runs: {len(buckets['active'])}",68f"- parked runs: {len(parked)}",69f"- closed runs (state): {len(buckets['closed'])}",70f"- done ledger: {len(done)}",71f"- quarantined: {len(quarantine)}",72f"- runs created today: {runs_created_today()}",73"",74"## Latest Benchmark",75]76if bench:77summary = bench.get("summary", {})78lines.extend(79[80f"- timestamp: {bench.get('timestamp')}",81f"- ok: {bench.get('ok')}",82f"- checks: {summary.get('benchmarks')} failures: {summary.get('failures')} scenarios: {summary.get('scenarios')}",83]84)85else:86lines.append("- no benchmark history yet")87lines.append("")88lines.append("## Latest Snapshot")89lines.append(f"- {snapshot.relative_to(ROOT)}" if snapshot else "- no snapshot yet")90lines.append("")91lines.append("## Active Runs")92if not buckets["active"]:93lines.append("- none")94for run_dir in buckets["active"]:95state = load_run_state(run_dir) or {}96lines.append(97f"- {run_dir.name}: state={state.get('current_state')} updated={state.get('updated_at')}"98)99lines.append("")100lines.append("## Parked Runs")101if not parked:102lines.append("- none")103for record in parked:104lines.append(f"- {record.get('run_id')}: {record.get('reason')} (parked {record.get('parked_at')})")105lines.append("")106lines.append("## Inbox Preview")107if not inbox:108lines.append("- empty")109for record in inbox[:5]:110lines.append(f"- {record.get('source_id')} {record.get('url')}")111112STATUS_FILE.parent.mkdir(parents=True, exist_ok=True)113STATUS_FILE.write_text("\n".join(lines) + "\n", encoding="utf-8")114115if parked:116parked_lines = [f"# Parked Runs Needing Review", f"_generated {utc_now()}_", ""]117for record in parked:118run_dir = RESEARCHER / "runs" / record.get("run_id", "")119state = load_run_state(run_dir) or {}120parked_lines.extend(121[122f"## {record.get('run_id')}",123f"- reason: {record.get('reason')}",124f"- parked at: {record.get('parked_at')}",125f"- current state: {state.get('current_state')}",126f"- title: {state.get('title')}",127f"- source: {state.get('source_url')}",128f"- thread: {(run_dir / 'THREAD.md').relative_to(ROOT) if (run_dir / 'THREAD.md').exists() else 'missing'}",129"",130]131)132PARKED_REVIEW_FILE.write_text("\n".join(parked_lines), encoding="utf-8")133elif PARKED_REVIEW_FILE.exists():134PARKED_REVIEW_FILE.write_text("# Parked Runs Needing Review\n\n- none\n", encoding="utf-8")135136return {137"status_path": str(STATUS_FILE.relative_to(ROOT)),138"parked_review_path": str(PARKED_REVIEW_FILE.relative_to(ROOT)) if parked else None,139"queue": {140"inbox": len(inbox),141"active": len(buckets["active"]),142"parked": len(parked),143"closed": len(buckets["closed"]),144"done": len(done),145"quarantine": len(quarantine),146},147"runs_created_today": runs_created_today(),148"latest_benchmark_ok": bench.get("ok") if bench else None,149}150151152def main() -> int:153parser = argparse.ArgumentParser(description="Write loop status dashboard")154parser.add_argument("--json", action="store_true")155args = parser.parse_args()156result = render_status()157if args.json:158print(json.dumps(result, indent=2))159else:160print(f"status written to {result['status_path']}")161if result["parked_review_path"]:162print(f"parked review at {result['parked_review_path']}")163return 0164165166if __name__ == "__main__":167sys.exit(main())168