import json, pathlib, subprocess, sys
checkout, home = map(pathlib.Path, sys.argv[1:3])
rows=[]
def cli(*args):
    return subprocess.check_output(['node','apps/server/src/bin.ts',*map(str,args),'--base-dir',str(home)],cwd=checkout,text=True)
for repository in ['zeit/swr','vercel/swr']:
    workspace=home/'workspaces'/repository.replace('/','-')
    workspace.parent.mkdir(parents=True,exist_ok=True)
    subprocess.run(['git','clone','--quiet','--depth=1','https://github.com/'+repository+'.git',str(workspace)],check=True)
    cli('project','add',workspace,'--title',repository)
    thread=json.loads(cli('thread','start',workspace,'go','--provider','devReplay','--model','multi-turn','--title',repository+' alias proof','--wait','--json'))
    rows.append({'repository':repository,'threadId':thread['threadId']})
print(json.dumps(rows))
