#!/usr/bin/env python3
"""run.py — the delegation-map demonstration. Runs the fixed prompt (prompt.txt) through two Claude
models via the claude CLI, headless, from an empty folder, with every tool disabled (no web), three runs
each, and saves each reply with the model id the CLI reports. Pinned by the pre-registration.
    python3 run.py
"""
import json, os, subprocess, tempfile, pathlib, datetime
HERE = pathlib.Path(__file__).resolve().parent
PROMPT = (HERE / "prompt.txt").read_text()
MODELS = ["sonnet", "opus"]
RUNS = 3
out = []
with tempfile.TemporaryDirectory() as empty:
    for m in MODELS:
        for r in range(1, RUNS + 1):
            p = subprocess.run(["claude", "-p", "--model", m, "--output-format", "json",
                                "--system-prompt", "You are a helpful assistant.",
                                "--disallowedTools", "WebSearch,WebFetch,Bash,Read,Write,Edit,Glob,Grep,Task",
                                PROMPT], cwd=empty, capture_output=True, text=True, timeout=600)
            try:
                j = json.loads(p.stdout)
                text = j.get("result", "")
                model_id = ",".join((j.get("modelUsage") or {}).keys()) or m
            except Exception:
                text, model_id = p.stdout, m
            out.append({"alias": m, "model": model_id, "run": r, "reply": text,
                        "at": datetime.datetime.utcnow().isoformat() + "Z"})
            print(m, r, len(text.split()), "words")
(HERE / "replies.json").write_text(json.dumps(out, indent=1, ensure_ascii=False))
