#!/usr/bin/env python3
"""Run from either evidence checkout with its isolated dev server already running.
Start server with T3CODE_DEV_SEED=0 vp run dev. No live database is seeded.
Pass the configured Claude model alias as an argument; it is intentionally not recorded here.
"""
import argparse, pathlib, subprocess
p=argparse.ArgumentParser()
p.add_argument('--model', required=True)
a=p.parse_args()
root=pathlib.Path.cwd()
home=root/'.t3'
workspace=home/'background-wait-demo'
workspace.mkdir(parents=True, exist_ok=True)
(workspace/'README.md').write_text('Synthetic background wait reproduction.\n')
def run(args, cwd=root):
    return subprocess.run(args, cwd=cwd, check=True)
if not (workspace/'.git').exists():
    run(['git','init','-q'],workspace)
    run(['git','add','README.md'],workspace)
    run(['git','-c','user.name=Demo','-c','user.email=demo@example.invalid',
         'commit','-qm','Initial'],workspace)
cli=['node','apps/server/src/bin.ts']
run(cli+['project','add',str(workspace),'--title','Background wait demo','--base-dir',str(home)])
prompt=pathlib.Path(__file__).with_name('prompt.txt').read_text()
run(cli+['thread','start',str(workspace),prompt,'--title','Background wait proof',
         '--provider','claudeAgent','--model',a.model,'--base-dir',str(home),'--json'])
# In the web client, open this thread, expand Worked for ... and its tool groups.
# Expand the placeholder wait to inspect taskIds and the raw result.
# Then expand the four successful wait/clear calls to inspect the controls.
