import json, pathlib, subprocess, sys
checkout, home = sys.argv[1:]
project = pathlib.Path('/tmp/factory-pr-23251-a2-evidence-1/terminal-recovery')
if not project.exists():
    project.mkdir()
    (project/'README.md').write_text('Disposable terminal recovery demonstration.\n')
    subprocess.run(['git','init','--quiet','--initial-branch=main',str(project)],check=True)
    subprocess.run(['git','-C',str(project),'add','.'],check=True)
    subprocess.run(['git','-C',str(project),'-c','user.name=Scenario','-c','user.email=scenario@example.invalid','commit','--quiet','-m','Initial commit'],check=True)
def cli(args):
    return subprocess.check_output(['node','apps/server/src/bin.ts',*args,'--base-dir',home],cwd=checkout,text=True)
cli(['project','add',str(project),'--title','terminal-recovery'])
result=cli(['thread','start',str(project),'Ready','--provider','devReplay','--model','multi-turn','--title','Terminal recovery','--wait','--json'])
pathlib.Path(home,'seed-result.json').write_text(result)
print('Synthetic project and replay thread ready')
