#!/usr/bin/env python3
"""Run once per isolated checkout after T3CODE_DEV_SEED=0 vp run dev.
Usage: python3 reproduce.py CHECKOUT SCRATCH REAL_CODEX
Then pair the web client, open the returned thread, collapse Thread details,
dismiss any provider banners, record typing the same prompt and pressing Enter.
Capture the completed reply or session-open failure. Use 1280x800, light theme.
"""
import json, pathlib, subprocess, sys
checkout, scratch, codex = map(pathlib.Path, sys.argv[1:])
scratch.mkdir(parents=True, exist_ok=True)
wrapper = scratch / "codex-wrapper.py"
wrapper.write_text("#!/usr/bin/env python3\nimport os,sys,json\nfrom pathlib import Path\nwith (Path(__file__).parent/'argv.jsonl').open('a') as f: f.write(json.dumps(sys.argv[1:])+'\\n')\nos.execv(" + repr(str(codex)) + ",['codex',*sys.argv[1:]])\n")
wrapper.chmod(0o755)
settings = checkout / '.t3/userdata/settings.json'
data = json.loads(settings.read_text())
data.setdefault('providerInstances', {})['codex'] = {'driver':'codex','enabled':True,'config':{'binaryPath':str(wrapper),'launchArgs':'--config model="gpt-6.1-sol" ' + chr(92) + chr(10) + '--strict-config'}}
settings.write_text(json.dumps(data, indent=2) + '\n')
project = scratch / 'continuation-demo'
project.mkdir(exist_ok=True)
(project/'README.md').write_text('Synthetic CLI continuation reproduction.\n')
def run(args, cwd):
 return subprocess.run(args, cwd=cwd, check=True)
run(['git','init','--quiet','--initial-branch=main'],project)
run(['git','add','README.md'],project)
run(['git','-c','user.name=Evidence','-c','user.email=evidence@example.invalid','commit','--quiet','-m','Synthetic reproduction project'],project)
cli=['node','apps/server/src/bin.ts']
run(cli+['project','add',str(project),'--title','Continuation demo','--base-dir','.t3'],checkout)
run(cli+['thread','start',str(project),'Reply with the single word: pong','--title','Line continuation','--provider','codex','--model','gpt-6.1-sol','--json','--base-dir','.t3'],checkout)
