import os
import pathlib
import subprocess
import sys

label, checkout, *extra = sys.argv[1:]
scratch = pathlib.Path('/tmp/issue-lead-33381-r1/evidence-capture/20261109-run1')
with (scratch / (label + '-server.log')).open('w') as log:
    process = subprocess.Popen(
        ['setsid', 'vp', 'run', 'dev', '--home-dir', str(scratch / (label.split('-')[0] + '-home')), '--no-browser', '--host', '0.0.0.0', *extra],
        cwd=checkout,
        env=dict(os.environ, T3CODE_DEV_SEED='0'),
        stdin=subprocess.DEVNULL, stdout=log, stderr=subprocess.STDOUT,
    )
    (scratch / (label + '.pid')).write_text(str(process.pid))
    print(process.pid)
