import subprocess,json,sys,pathlib,time
side,checkout=sys.argv[1:]
out=pathlib.Path(__file__).parent/(side+'-'+str(int(time.time())))
out.mkdir()
def cli(*args):
 r=subprocess.run(['node','apps/server/src/bin.ts',*args,'--base-dir',checkout+'/.t3'],cwd=checkout,text=True,capture_output=True)
 if r.returncode: raise RuntimeError(r.stderr)
 return r.stdout
# Create synthetic seed data and register it on a fresh server.
repo=pathlib.Path(__file__).parent/'repro'
repo.mkdir(exist_ok=True)
if not (repo/'.git').exists():
 subprocess.run(['git','init','-q'],cwd=repo,check=True)
 subprocess.run(['git','-c','user.name=Evidence','-c','user.email=evidence@example.invalid','commit','--allow-empty','-qm','Initial'],cwd=repo,check=True)
project=cli('project','add','--title','CLI attribution proof',str(pathlib.Path(__file__).parent/'repro'))
question='Does the text of this turn start with a line beginning [T3 Code: ? Quote it, or say NO-LINE.'
start=json.loads(cli('thread','start','--json','--wait','--provider','claudeAgent','--model','claude-haiku-5-5','--title','CLI attribution proof',str(pathlib.Path(__file__).parent/'repro'),question))
(out/'start.json').write_text(json.dumps(start,indent=2))
print('START',json.dumps(start),flush=True)
send=json.loads(cli('thread','send','--json','--wait',start['threadId'],question))
(out/'send.json').write_text(json.dumps(send,indent=2))
print('SEND',json.dumps(send),flush=True)
show=json.loads(cli('thread','show','--json',start['threadId']))
summary={'side':side,'question':question,'start':start,'send':send,'createdBy':show['thread'].get('createdBy'),'creationSource':show['thread'].get('creationSource')}
(out/'evidence.json').write_text(json.dumps(summary,indent=2))
print('OUTPUT',out,flush=True)
