"""Usage: python3 seed-installs.py SCRATCH BASE_CHECKOUT HEAD_CHECKOUT
Place the real Vite+ v0.3.0 executable at SCRATCH/vp first. Run against fresh checkouts only.
Starts neither app; run T3CODE_DEV_SEED=0 vp run dev in each checkout.
The synthetic hostnamectl shim in SCRATCH/bin supplies the neutral capture label.
"""
import os,json,pathlib,subprocess,sys
root=pathlib.Path(sys.argv[1]).resolve()
checkouts=[pathlib.Path(sys.argv[2]).resolve(),pathlib.Path(sys.argv[3]).resolve()]
for side in ['before','after']:
 d=root/side
 subprocess.run([str(root/'vp'),'env','setup'],env={**os.environ,'VP_HOME':str(d/'.vite-plus')},check=True,stdout=subprocess.DEVNULL)
 subprocess.run([str(root/'vp'),'i','-g','opencode-ai@1.19.4'],env={**os.environ,'VP_HOME':str(d/'.vite-plus')},check=True)
 subprocess.run(['npm','i','-g','--prefix',str(d/'sysprefix'),'opencode-ai@1.19.4'],check=True)
 subprocess.run([str(root/'vp'),'env','off'],env={**os.environ,'VP_HOME':str(d/'.vite-plus')},check=True)
 wt=checkouts[0 if side=='before' else 1]
 home=wt/'.t3/userdata'; home.mkdir(parents=True,exist_ok=True)
 instances={p:{'driver':p,'enabled':False} for p in ['codex','claudeAgent','cursor','grok','muse','pi','opencode','antigravity']}
 instances['opencode']={'driver':'opencode','enabled':True,'environment':[{'name':k,'value':v,'sensitive':False} for k,v in {'VP_HOME':str(d/'.vite-plus'),'PATH':str(d/'.vite-plus/bin')+':'+str(d/'sysprefix/bin')+':/usr/local/bin:/usr/bin:/bin'}.items()]}
 (home/'settings.json').write_text(json.dumps({'providerInstances':instances}))
(root/'bin').mkdir(exist_ok=True)
f=root/'bin/hostnamectl'; f.write_text('#!/bin/sh\necho "Update demo"\n');f.chmod(0o755)
