"""Run on each checkout with its own fresh T3 home and a signed-in Codex installation.
Configure two Codex instances: codex (parent) and hookProof (child).
Child launch arguments: -c model_auto_compact_token_limit=20000
Use gpt-6-luna for both. Trust the synthetic PreCompact hook below.
Start T3 with T3CODE_DEV_SEED=0. Record the parent thread in the web client.
"""
import pathlib,json,subprocess,sys
checkout,home,workspace=sys.argv[1:]
w=pathlib.Path(workspace);w.mkdir(parents=True,exist_ok=True)
subprocess.run(["git","init","--quiet","--initial-branch=main",workspace],check=True)
(w/"README.md").write_text("Synthetic checkpoint hook reproduction.\n")
(w/"payload.txt").write_text("checkpoint evidence sample data\n"*15000)
hooks={"hooks":{"PreCompact":[{"hooks":[{"type":"command","command": "printf '%s' '{\"continue\":false,\"stopReason\":\"Save a current task checkpoint before compaction.\"}' "}]}]}}
print("Install and trust this hook in the isolated Codex home's hooks.json:",json.dumps(hooks))
# The configured hook is trusted before starting the app-server instances.
prompt=pathlib.Path(__file__).with_name("prompt.txt").read_text()
def cli(*args,**kw):return subprocess.run(["node","apps/server/src/bin.ts",*args,"--base-dir",home],cwd=checkout,check=True,**kw)
cli("project","add",workspace,"--title","Checkpoint demo")
cli("thread","start",workspace,"-","--provider","codex","--model","gpt-6-luna","--title","Checkpoint hook result","--json",input=prompt,text=True)
