import pathlib, subprocess, sys, json, time
checkout, home, fixtures = map(pathlib.Path, sys.argv[1:])
root = fixtures / str(time.time_ns()) / 'repository-demo'
root.mkdir(parents=True)
for i in range(1,31):
    repo = root / f'repo-{i:02d}'
    repo.mkdir()
    (repo/'README.md').write_text(f'Synthetic repository {i}\n')
    for args in [['init','-q','--initial-branch=main'], ['add','.'], ['-c','user.name=Scenario','-c','user.email=scenario@example.invalid','commit','-q','-m','Initial commit']]:
        subprocess.run(['git',*args], cwd=repo, check=True)
def cli(*args):
    return subprocess.check_output(['node','apps/server/src/bin.ts',*args,'--base-dir',str(home)],cwd=checkout,text=True)
cli('project','add',str(root),'--title','Repository collection')
thread = json.loads(cli('thread','start',str(root),'Start','--title','Thirty repositories','--provider','devReplay','--model','multi-turn','--wait','--json'))
(home/'fixture.json').write_text(json.dumps({'threadId':thread['threadId'],'root':str(root)}))
print(thread['threadId'])
