#!/usr/bin/env python3
"""Synthetic projects only. Draft payloads are entered through native UI."""
import subprocess,sys,pathlib,json,datetime
ROOT=pathlib.Path('/tmp/lead-26800-r1/evidence-capture-1')
side,action,*args=sys.argv[1:]
repo='/home/ubuntu/wt/pr-26800'+('-base' if side=='base' else '')
home=str(ROOT/('scratch-light-home' if side=='scratchlight' else 'scratch-home')) if side.startswith('scratch') else repo+'/.t3'
if action=='add':
 name=args[0]; folder=ROOT/'workspaces'/name; folder.mkdir(parents=True,exist_ok=True)
 subprocess.run(['git','init','-q',str(folder)],check=True)
 subprocess.run(['git','-C',str(folder),'-c','user.name=Proof','-c','user.email=proof@example.invalid','commit','--allow-empty','-qm','Synthetic fixture'],check=True)
 cmd=['project','add',str(folder),'--title',name]
elif action=='remove': cmd=['project','remove',str(ROOT/'workspaces'/args[0])]
elif action=='rename': cmd=['project','rename',str(ROOT/'workspaces'/args[0]),args[1]]
else: raise SystemExit('add/remove/rename')
p=subprocess.run(['node','apps/server/src/bin.ts',*cmd,'--base-dir',home],cwd=repo,text=True,capture_output=True)
with open(ROOT/'seed.jsonl','a') as f: f.write(json.dumps({'utc':datetime.datetime.now(datetime.timezone.utc).isoformat(),'side':side,'cmd':cmd,'stdout':p.stdout,'stderr':p.stderr,'code':p.returncode})+'\n')
print(p.stdout,end='');print(p.stderr,end='',file=sys.stderr);sys.exit(p.returncode)
