"""Run for each checkout before starting T3CODE_DEV_SEED=0 vp run dev.
Requires Node, npm, authenticated gh with Copilot access, and the same scratch root on both sides.
The driver requires a paired agent-browser session at each dev origin.
"""
import argparse,json,subprocess
from pathlib import Path
p=argparse.ArgumentParser();p.add_argument('--checkout',type=Path,required=True);p.add_argument('--scratch',type=Path,required=True);a=p.parse_args()
a.scratch.mkdir(parents=True,exist_ok=True)
subprocess.run(['npm','install','--prefix',str(a.scratch/'copilot'),'@github/copilot@1.0.110'],check=True)
(a.scratch/'bin').mkdir(exist_ok=True)
wrapper=a.scratch/'bin/copilot'
wrapper.write_text('#!/bin/bash\nexport GITHUB_TOKEN="$(gh auth token)"\nexec "'+str(a.scratch/'copilot/node_modules/.bin/copilot')+'" --acp\n');wrapper.chmod(0o755)
settings={'providerInstances':{'acpRegistry_copilot':{'driver':'acpRegistry','displayName':'Copilot','config':{'source':'local','commandPath':str(wrapper),'commandArgs':[]}},**{d:{'driver':d,'enabled':False} for d in ['codex','claudeAgent','cursor','grok','muse','pi','opencode','antigravity']}},'defaultModelSelection':{'instanceId':'acpRegistry_copilot','model':'claude-haiku-5.5'}}
home=a.checkout/'.t3/userdata';home.mkdir(parents=True,exist_ok=True);(home/'settings.json').write_text(json.dumps(settings))
project=a.scratch/'demo';project.mkdir(exist_ok=True);(project/'README.md').write_text('Synthetic ACP completion demonstration.\n')
if not (project/'.git').exists():
 for args in [['init','-q'],['add','.'],['-c','user.name=Demo','-c','user.email=demo@example.invalid','commit','-qm','Initial']]:subprocess.run(['git',*args],cwd=project,check=True)
print('After starting the server, add the synthetic project with:')
print('node apps/server/src/bin.ts project add '+str(project)+' --title "ACP completion demo" --base-dir .t3')
