"""Run once per checkout against its running, freshly seeded dev server.
Usage: python3 reproduce.py CHECKOUT OUTPUT_DIRECTORY
Start the app first: T3CODE_DEV_SEED=0 vp run dev
Pair the preview browser with that server's printed URL.
"""
import json
import subprocess
import sys
from datetime import datetime, timezone
from pathlib import Path

checkout = Path(sys.argv[1]).resolve()
run = Path(sys.argv[2]).resolve() / datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S%fZ")
repo = run / "sample"
repo.mkdir(parents=True)
(repo / "gone.ts").write_bytes(b"")
def call(args, cwd=checkout):
    return subprocess.run(args, cwd=cwd, check=True, capture_output=True, text=True).stdout
call(["git", "init", "-q"], repo)
call(["git", "add", "gone.ts"], repo)
call(["git", "-c", "user.name=Evidence", "-c", "user.email=evidence@example.com", "commit", "-qm", "Initial empty file"], repo)
cli = ["node", "apps/server/src/bin.ts"]
call(cli + ["project", "add", "--base-dir", ".t3", "--title", "Empty file patch", str(repo)])
prompt = "Use exactly ONE apply_patch call (a single patch with three file sections) to: (1) add zero-byte empty.ts, (2) add b.ts containing export const b = 2;, (3) delete the existing empty file gone.ts."
result = json.loads(call(cli + ["thread", "start", "--base-dir", ".t3", "--title", "Empty file patch", "--provider", "codex", "--model", "gpt-6.1-sol", "--wait", "--json", str(repo), prompt]))
print(json.dumps(result, indent=2))
print("Open this thread in the paired browser. Expand Worked for, then Changed 3 files, then Open diff.")
print("Hide the sidebar and thread details; maximize the Diff panel for privacy.")
print("Collapse all files. Start recording. Expand all files. Capture the tool-call diff.")
print("Use 1280x800, light theme, stacked diff on both sides.")
print(json.dumps({"emptyBytes": (repo / "empty.ts").stat().st_size, "bContent": (repo / "b.ts").read_text(), "goneExists": (repo / "gone.ts").exists()}))
