#!/usr/bin/env python3
"""Real Claude reproduction driver. Run from either installed checkout with its dev server running.
Usage: python3 reproduce.py seed /path/to/new/project [900]
       python3 reproduce.py ignore /path/to/project
       python3 reproduce.py send THREAD_ID "Reply with the word ok."
       python3 reproduce.py show THREAD_ID
Open the returned thread in the paired app; browser sends used the same text.
Use fresh server state (T3CODE_DEV_SEED=0 vp run dev), a light 1280x800 viewport,
and the same synthetic project on both revisions. Never copy a live database.
For refresh proof, use a separate project and 90 seconds; ask about vendor/foo
in workspace_folders before and after natural completion. Compare provider
process PIDs in the isolated server's provider-processes ownership records.
For policy guard: model picker > Permissions > Supervised, then send again.
Capture with the real app browser recorder; hide only the machine label for
public evidence. No provider replacement, mock, or recorded model replies.
"""
import json, pathlib, subprocess, sys

def cli(*args):
    return subprocess.check_output(["node", "apps/server/src/bin.ts", *args, "--base-dir", ".t3"], text=True)

phase, target = sys.argv[1:3]
if phase == "seed":
    root = pathlib.Path(target).resolve()
    root.mkdir(parents=True, exist_ok=False)
    subprocess.run(["git", "init", str(root)], check=True)
    nested = root / "vendor/foo"
    nested.mkdir(parents=True)
    subprocess.run(["git", "init", str(nested)], check=True)
    print(cli("project", "add", "--title", "Repository discovery proof", str(root)))
    seconds = int(sys.argv[3]) if len(sys.argv) > 3 else 900
    prompt = f"Use the Bash tool to run sleep {seconds} with run_in_background true. Do not wait for completion. Finish your turn by saying Background command started."
    print(cli("thread", "start", "--provider", "claudeAgent", "--model", "claude-haiku-5-5", "--title", "Repository discovery proof", str(root), prompt, "--json"))
elif phase == "ignore":
    (pathlib.Path(target) / "t3.json").write_text(json.dumps({"ignoreRepositories": ["vendor/foo"]}) + "\n")
elif phase == "send":
    print(cli("thread", "send", target, sys.argv[3], "--json"))
elif phase == "show":
    print(cli("thread", "show", target, "--json"))
else:
    raise SystemExit("unknown phase")
