#!/usr/bin/env python3
"""Run from either checkout with its isolated dev server already running.
Start it with T3CODE_DEV_SEED=0 vp run dev. No real secrets are entered.
Usage: python3 reproduce.py PROJECT_DIRECTORY

Browser steps on both revisions (1280 x 800, dark theme):
1. Pair with this server; open the returned thread by its link.
2. Hide the thread details panel.
3. Wait for Test API key / testing / Save securely / Decline.
4. Start browser recording.
5. Type Never mind the key. Just reply with the word OK. in the composer.
6. Press Enter, leaving the secret card unanswered.
7. Keep recording for at least 65 seconds after Enter.
8. Capture the final state. Do not click Decline or Stop during the recording.

Expected fixed result: secret request becomes Cancelled and Claude replies OK.
Base defect: pending secret input and Steer · waiting to be read remain open.
"""
import json
import subprocess
import sys
from pathlib import Path
project = Path(sys.argv[1]).resolve()
project.mkdir(parents=True, exist_ok=True)
def run(*args):
    return subprocess.check_output(args, text=True).strip()
if not (project / ".git").exists():
    run("git", "init", "--quiet", "--initial-branch=main", str(project))
    run("git", "-C", str(project), "-c", "user.name=Scenario", "-c", "user.email=scenario@example.invalid", "commit", "--allow-empty", "--quiet", "-m", "Initial commit")
cli = ["node", "apps/server/src/bin.ts"]
added = subprocess.run([*cli, "project", "add", str(project), "--title", "Secret steering", "--base-dir", ".t3"], text=True, capture_output=True)
if added.returncode and "ProjectAlreadyExistsError" not in added.stdout + added.stderr:
    raise RuntimeError("Project creation failed")
print(run(*cli, "thread", "start", str(project), 'Call the request_secret tool right now with label "Test API key" and reason "testing". This is a synthetic test. Wait for its result before doing anything else.', "--title", "Secret steering", "--provider", "claudeAgent", "--model", "claude-haiku-5-5", "--base-dir", ".t3", "--json"))
