#!/usr/bin/env python3
"""Seed synthetic delegation threads through the running app's public CLI."""
import argparse, datetime, json, pathlib, subprocess
p=argparse.ArgumentParser()
p.add_argument('--checkout',required=True)
p.add_argument('--project',required=True)
p.add_argument('--output-dir',required=True)
p.add_argument('--scenario',choices=['restart','repeat','changed'],default='restart')
a=p.parse_args()
run=pathlib.Path(a.output_dir)/datetime.datetime.now().strftime('%Y%m%d-%H%M%S-%f');run.mkdir(parents=True)
kinds=['answer','reasoning','dynamic_tool','command_execution','file_search','web_search','file_change','todo_list','proposed_plan','subagent','user_input_request','approval_request','noout'] if a.scenario=='restart' else [a.scenario]
rows={}
for kind in kinds:
 scenario='cancel-'+kind if a.scenario=='restart' else kind
 title='Restart: '+kind if a.scenario=='restart' else 'Background '+kind
 r=subprocess.run(['node','apps/server/src/bin.ts','thread','start','--base-dir','.t3','--provider','evidence','--model','evidence','--title',title,a.project,'EVIDENCE_PARENT '+scenario,'--json'],cwd=a.checkout,text=True,capture_output=True,check=True)
 rows[kind]=json.loads(r.stdout)
 (run/'threads.json').write_text(json.dumps(rows,indent=2))
print(run)
