"""Portable manual proof driver (synthetic data only).
1. In each checkout: vp i; T3CODE_DEV_SEED=0 T3CODE_ENVIRONMENT_LABEL=Evidence
   T3CODE_ENVIRONMENT_MACHINE_KIND=laptop vp run dev (choose separate T3CODE_PORT_OFFSETs).
2. Run: python3 reproduce.py turns CHECKOUT SYNTHETIC_GIT_REPO
   Wait for replay model discovery if command-output is initially unavailable.
3. Stop that server; run: python3 reproduce.py seed CHECKOUT
4. Restart the same server. Pair the web client, open the printed thread directly,
   use light theme and 1440 x 1320 CSS viewport, expand all five Worked for rows.
   Browser DOM action used on each side:
   [...document.querySelectorAll('button')]
     .filter(b => b.textContent.startsWith('Worked for')).forEach(b => b.click());
   document.activeElement?.blur();
5. Capture twice at least 500 ms apart; compare decoded pixels and inspect each image.
The recording is the repository's unchanged command-output replay fixture.
Only command display inputs are changed; this does not claim those commands ran.
"""
import subprocess,json,sys,pathlib,sqlite3
mode,checkout,*rest=sys.argv[1:]
checkout=pathlib.Path(checkout)
def cli(*args):
 r=subprocess.run(['node','apps/server/src/bin.ts',*args,'--base-dir','.t3'],cwd=checkout,text=True,capture_output=True,check=True)
 return r.stdout.strip()
if mode=='turns':
 repo=rest[0]
 print(cli('project','add',repo,'--title','Shell labels'))
 result=json.loads(cli('thread','start',repo,'Heredoc','--title','Quoted shell expansions','--provider','devReplay','--model','command-output','--wait','--json'))
 thread=result['threadId'];print(thread)
 for message in ['Apostrophe','Subshell comment','Assignment','Control']:
  print(cli('thread','send',thread,message,'--wait','--json'))
elif mode=='seed':
 commands=['bash -lc "echo $(cat <<EOF\n(\nEOF\n)"',"bash -lc \"echo ${FOO:-don't}\"", "bash -lc \"echo $( (echo hi)# don't break\n)\"", 'VAR="$(cat <<EOF\n(\nEOF\n)" && pnpm test', 'bash -lc "echo $(echo hi)"']
 c=sqlite3.connect(checkout/'.t3/userdata/statev2.sqlite');i=0
 for rowid,raw in c.execute('select rowid,payload_json from orchestration_v2_projection_turn_items order by rowid').fetchall():
  p=json.loads(raw)
  if p.get('type')=='command_execution' and p.get('input','').startswith('node -e'):
   p['input']=commands[i];i+=1
   c.execute('update orchestration_v2_projection_turn_items set payload_json=? where rowid=?',(json.dumps(p),rowid))
 assert i==5,i
 c.commit();print('Updated five replay command inputs.')
else: raise SystemExit('Use turns or seed')
