"""Manual comparison driver, applied identically to each running checkout.
Start each checkout with T3CODE_DEV_SEED=0 and CODEX_HOME pointing to a scratch
Codex home configured with the guard.py SessionStart hook, trusted through
hooks/list's currentHash (trust-hook.py shows that discovery).
Usage: python3 seed-and-drive.py CHECKOUT OUTPUT_DIRECTORY
Run sides sequentially. The marker must be absent for the initial parent turn.
Browser: pair, open the returned parent thread, record delegation, inspect the
raw task_status output, then open the returned child and expand its task/warning.
"""
import datetime, json, pathlib, subprocess, sys
checkout = pathlib.Path(sys.argv[1]).resolve()
output = pathlib.Path(sys.argv[2]).resolve() / datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')
output.mkdir(parents=True)
workspace = checkout / '.t3/workspaces/Hook-proof'
workspace.mkdir(parents=True)
(workspace/'README.md').write_text('Synthetic workspace for the provider-hook reproduction.\n')
(workspace/'AGENTS.md').write_text('Follow the user task exactly. Do not inspect unrelated files.\n')
for args in [['init','-q'],['add','.'],['-c','user.name=Proof','-c','user.email=proof@example.invalid','commit','-qm','Initial synthetic workspace']]:
    subprocess.run(['git',*args],cwd=workspace,check=True)
def cli(args, stdin=None):
    return subprocess.check_output(['node','apps/server/src/bin.ts',*args,'--base-dir','.t3'],cwd=checkout,input=stdin,text=True)
cli(['project','add','--title','Hook proof',str(workspace)])
marker = pathlib.Path(__file__).with_name('blocked')
if marker.exists():
    raise SystemExit('Remove the marker before starting a fresh parent session.')
parent = json.loads(cli(['thread','start','--provider','codex','--model','gpt-6-astra','--title','Hook stop parent','--json','--wait',str(workspace),'Reply with exactly OK']))
(output/'parent.json').write_text(json.dumps(parent,indent=2))
marker.touch()
prompt = pathlib.Path(__file__).with_name('delegate-prompt.txt').read_text()
result = cli(['thread','send','--json','--wait',parent['threadId'],'-'],prompt)
(output/'result.json').write_text(result)
print(result)
