#!/usr/bin/env python3
"""Start only a capture checkout, saving process-group PID for safe teardown."""
import json, os, pathlib, subprocess, sys
root=pathlib.Path(__file__).resolve().parent
side=sys.argv[1]
config=json.loads((root/(side+'-fixture.json')).read_text())
cwd='/home/ubuntu/wt/issue-24067-cap-'+side
env={**os.environ,'T3CODE_DEV_SEED':'0','CODEX_HOME':config['CODEX_HOME'],'CLAUDE_CONFIG_DIR':config['CLAUDE_CONFIG_DIR']}
name=side+('-video' if len(sys.argv)>2 else '')
command=['vp','run','dev']
if len(sys.argv)>2: command+=['--home-dir',sys.argv[2]]
with (root/(name+'-server.log')).open('w') as output:
    process=subprocess.Popen(command,cwd=cwd,env=env,stdout=output,stderr=subprocess.STDOUT,start_new_session=True)
(root/(name+'-server.pid')).write_text(str(process.pid)+'\n')
print(side, process.pid)
