"""Manual proof driver. Run once in each commit checkout on fresh state.
Start: T3CODE_DEV_SEED=0 vp run dev
Browser: 1280x800, light theme. Pair using that server's startup link.
After launch completes, open the returned thread, record, and click its sidebar Settle.
Base settles and clears the task; head refuses and preserves it.
Public captures mask the environment label and model selector only.
"""
import argparse, subprocess, json, pathlib, datetime
p=argparse.ArgumentParser()
p.add_argument("--home", required=True)
p.add_argument("--project", required=True)
p.add_argument("--provider", required=True)
p.add_argument("--model", required=True)
p.add_argument("--output", required=True)
a=p.parse_args()
out=pathlib.Path(a.output)/datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
out.mkdir(parents=True)
workspace=pathlib.Path(a.project)
workspace.mkdir(parents=True,exist_ok=True)
def run(*args):
 return subprocess.run(args,check=True,text=True,capture_output=True).stdout
run("git","init","--quiet","--initial-branch","main",str(workspace))
run("git","-C",str(workspace),"-c","user.name=Demo","-c","user.email=demo@example.invalid","commit","--allow-empty","--quiet","-m","Initial")
cli=["node","apps/server/src/bin.ts"]
run(*cli,"project","add",str(workspace),"--title","Background work demo","--base-dir",a.home)
prompt="Launch Bash with run_in_background=true running exactly: sleep 300; echo BACKGROUND_FINISHED. Then call t3_background_wait with the returned task ID to mark it awaited. Do not poll, stop, or wait synchronously. End your parent turn immediately with exactly: Background command is running and awaited. Do not mention model names or filesystem paths in your reply."
result=run(*cli,"thread","start",str(workspace),prompt,"--title","Awaited background command","--provider",a.provider,"--model",a.model,"--base-dir",a.home,"--json")
(out/"launch.json").write_text(result)
print(result)
# Browser action on the opened thread, after its parent turn completes:
# document.querySelectorAll('button[aria-label="Settle thread"]')[1].click()
