"""Run from either checkout after T3CODE_DEV_SEED=0 vp run dev.
Uses the replay fixture only; all state is made through the real app CLI.
"""
import concurrent.futures, json, pathlib, subprocess
root = pathlib.Path.cwd()
cli = ['node', 'apps/server/src/bin.ts']
def call(args):
    p = subprocess.run(cli + args + ['--base-dir', '.t3'], text=True, capture_output=True)
    if p.returncode: raise RuntimeError(p.stderr)
    return p.stdout.strip()
def start(index):
    return json.loads(call(['thread','start',str(root),'Synthetic greeting', '--title',f'Concurrent synthetic {index}', '--provider','devReplay','--model','multi-turn','--wait','--json']))
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
    threads=list(pool.map(start,range(3)))
for index in range(5):
    result=json.loads(call(['thread','send',threads[0]['threadId'],f'Synthetic continuation {index+1}','--wait','--json']))
    print(json.dumps({'step':index+1,'status':result['status'],'reply':result['reply']}),flush=True)
print(json.dumps({'threadCount':3,'sequentialContinuations':5,'completed':True}))
