#!/usr/bin/env python3
"""Run from an installed, running T3 checkout. Creates only synthetic data.
Usage: python3 reproduce.py <new-project-directory> [--seed-only]
Start app separately with T3CODE_DEV_SEED=0 vp run dev.
"""
import json, random, subprocess, sys
from pathlib import Path
p = Path(sys.argv[1]).resolve()
p.mkdir()
subprocess.run(['git', 'init', '-q', str(p)], check=True)
(p / 'README.md').write_text('Synthetic background wake demonstration.\n')
subprocess.run(['git', '-C', str(p), 'add', 'README.md'], check=True)
subprocess.run(['git', '-C', str(p), '-c', 'user.name=Demo', '-c', 'user.email=demo@example.com', 'commit', '-qm', 'Initial'], check=True)
rng = random.Random(22998)
for i in range(14000):
    (p / f'payload-{i:05}.txt').write_text('\n'.join(rng.randbytes(31).hex() for _ in range(645)) + '\n')
if '--seed-only' in sys.argv:
    sys.exit(0)
settings_path = Path('.t3/userdata/settings.json')
settings = json.loads(settings_path.read_text())
settings.setdefault('providerInstances', {})['claude'] = {'driver':'claudeAgent','enabled':True,'config':{}}
settings_path.write_text(json.dumps(settings, indent=2))
subprocess.run(['node','apps/server/src/bin.ts','project','add','--base-dir','.t3','--title','Wake replay proof',str(p)],check=True)
prompt = 'Run exactly three Bash tools immediately, each with run_in_background true: sleep 30; echo ALPHA, sleep 33; echo BRAVO, sleep 36; echo CHARLIE. Do not wait or poll them. End your initial reply with STARTED. When ALPHA or BRAVO background task notifications arrive, respond with only ALPHA handled or BRAVO handled respectively. When CHARLIE arrives, first call orchestrator_capabilities, then delegate_task for a Claude Haiku subagent whose task is Reply only CHILD READY. Report the actual delegation outcome. Do not use native Agent for that delegation.'
subprocess.run(['node','apps/server/src/bin.ts','thread','start','--base-dir','.t3','--provider','claude','--model','claude-haiku-5-5','--title','Overlapping background wakes',str(p),prompt,'--json'],check=True)
