"""Run from an installed evidence checkout with its isolated dev server running.
Place handoff-proof.ts alongside this script. No credentials are embedded.
"""
import json
import pathlib
import shutil
import subprocess

root = pathlib.Path.cwd()
shutil.copy(pathlib.Path(__file__).with_name("handoff-proof.ts"), root / "handoff-proof.ts")
settings_path = root / ".t3/userdata/settings.json"
settings = json.loads(settings_path.read_text())
settings.setdefault("providerInstances", {})["pi"] = {
    "driver": "pi", "enabled": True, "displayName": "Pi",
    "config": {
        "enabled": True,
        "launchArgs": "--no-context-files --no-skills --no-mcp --no-extensions -e "
        + str(root / "handoff-proof.ts")
        + " --approve --provider anthropic --model claude-haiku-5-5",
    },
}
settings_path.write_text(json.dumps(settings, indent=2))
(root / "handoff-demo").mkdir(exist_ok=True)
cli = ["node", "apps/server/src/bin.ts"]
subprocess.run(cli + ["project", "add", "--base-dir", ".t3", "--title", "Pi handoff proof", "./handoff-demo"], check=True)
subprocess.run(cli + ["thread", "start", "--base-dir", ".t3", "--provider", "pi", "--model", "default", "--title", "Handoff context after restart", "./handoff-demo", "Reply ORIGINAL SESSION READY. There is no handoff verification secret in this conversation.", "--json"], check=True)
