"""Reproduction setup helper. Run separately for each isolated checkout.
Usage: python3 reproduce.py CHECKOUT SCRATCH REAL_CLAUDE_BINARY
Start the app with T3CODE_DEV_SEED=0 vp run dev after this setup.
After startup:
 node apps/server/src/bin.ts project add --base-dir .t3 --title 'CLI update demo' SCRATCH/demo
 node apps/server/src/bin.ts thread start --base-dir .t3 --provider claude --model claude-haiku-5-5 --title 'CLI update proof' --wait --json SCRATCH/demo 'Reply with exactly: turn one ok'
Open the returned thread in the paired web client. Repoint SCRATCH/claude atomically
from claude-2.1.329 to claude-2.1.330. Use the model picker to select Sonnet 5.5
(default High effort), then send 'Reply with exactly: turn two ok'.
Record the model switch and second turn. Run observe.py against spawn.log and the
thread's provider event log while the server still runs.
Both wrappers exec the same real binary: the version numbers identify which
executable path was resolved, not different underlying Claude implementations.
"""
import json, shlex, subprocess, sys
from pathlib import Path
checkout, scratch, real = map(lambda s: Path(s).resolve(), sys.argv[1:])
scratch.mkdir(parents=True, exist_ok=True)
for version in ['2.1.329', '2.1.330']:
    wrapper = scratch / ('claude-' + version)
    wrapper.write_text('#!/bin/sh\nprintf "%s\\n" "spawned version=' + version + ' pid=$$ args=$*" >> ' + shlex.quote(str(scratch/'spawn.log')) + '\nexec ' + shlex.quote(str(real)) + ' "$@"\n')
    wrapper.chmod(0o755)
(scratch/'claude').symlink_to(scratch/'claude-2.1.329')
(scratch/'demo').mkdir()
subprocess.run(['git', 'init', str(scratch/'demo')], check=True)
p = checkout/'.t3/userdata/settings.json'
p.parent.mkdir(parents=True, exist_ok=True)
s = json.loads(p.read_text()) if p.exists() else {}
s.setdefault('providerInstances', {})['claude'] = {'driver':'claudeAgent', 'displayName':'Claude', 'config':{'binaryPath':str(scratch/'claude')}}
p.write_text(json.dumps(s, indent=2))
