"""Run against an already-started isolated T3 dev server; never use a live home.
Usage: python3 seed-and-start.py CHECKOUT T3_HOME
Start server first with T3CODE_DEV_SEED=0 vp run dev --home-dir T3_HOME
settings.json under T3_HOME/userdata must contain idleCompaction: beforeCacheExpires.
Then run observe.py T3_HOME base|head OUTPUT_DIRECTORY.
Wait until cache expiry, then create T3_HOME/fixture/release to wake the child.
"""
import json, random, subprocess, sys
from pathlib import Path
checkout,home=map(lambda s:Path(s).resolve(),sys.argv[1:])
project=home/"fixture"
project.mkdir(exist_ok=True)
for i in range(14):
 g=random.Random(i)
 (project/f"padding-{i:02}.txt").write_text("\n".join(" ".join(str(g.randrange(100000,999999)) for _ in range(18)) for _ in range(400)))
def run(args,**kw):
 return subprocess.run(args,cwd=checkout,check=True,text=True,**kw)
run(["git","init","-q",str(project)])
run(["git","-C",str(project),"add","."])
run(["git","-C",str(project),"-c","user.name=Evidence","-c","user.email=evidence@example.com","commit","-qm","Synthetic fixture"])
cli=["node","apps/server/src/bin.ts"]
run(cli+["project","add",str(project),"--title","Idle compaction evidence","--base-dir",str(home)])
prompt=Path(__file__).with_name("prompt.txt").read_text()
run(cli+["thread","start","--base-dir",str(home),"--title","Idle compaction with delegated child","--provider","claudeAgent","--model","claude-sonnet-5-5",str(project),"-"],input=prompt)
