"""Run from either checkout after seed.py and starting the isolated dev server.
Usage: python driver.py CHECKOUT PROJECT_PATH
Before starting the server, configure provider claudeAgent:
  driver: claudeAgent
  environment: [{name: CLAUDE_CODE_ENABLE_EXPERIMENTAL_ADVISOR_TOOL, value: "1", sensitive: false}]
  config: {launchArgs: "--advisor claude-opus-5-5", autoCompactWindow: "1000000", idleCompaction: "off"}
Set global idleCompaction to "off" and T3CODE_DEV_SEED=0.
Web capture: 1280x800 CSS pixels, device scale 2, light theme.
Show Context window using the thread details context menu.
Capture/record after advisor finishes, before sending the final OK request.
"""
import json
import subprocess
import sys
from datetime import datetime, timezone
from pathlib import Path
checkout, project = map(Path, sys.argv[1:3])
out = Path(__file__).parent / datetime.now(timezone.utc).strftime("run-%Y%m%d-%H%M%S")
out.mkdir()
def cli(*args):
    r = subprocess.run(["node", "apps/server/src/bin.ts", *args, "--base-dir", ".t3"], cwd=checkout, capture_output=True, text=True)
    if r.returncode:
        raise RuntimeError(r.stderr)
    return r.stdout
cli("project", "add", str(project))
read = "Read notes-1.txt, notes-2.txt, and notes-3.txt in full and reply DONE. Use the Read tool in chunks of 500 lines until all 4200 lines of each file have been loaded. Do not summarize or use a script to inspect them. Your context window is 1 million tokens, enough for all three files."
advisor = "Call the advisor tool once and ask it which word appears most often in those notes files. Then finish with one plain-text sentence. Do not call any other tools."
result = json.loads(cli("thread", "start", str(project), read, "--provider", "claudeAgent", "--model", "claude-opus-5-5", "--title", "Advisor context comparison", "--wait", "--json"))
(out / "read.json").write_text(json.dumps(result, indent=2))
thread = result["threadId"]
(out / "advisor.json").write_text(cli("thread", "send", thread, advisor, "--wait", "--json"))
print("Advisor complete; capture the real app now. Thread:", thread)
input("Press Enter after capture to send the normal follow-up: ")
(out / "normal.json").write_text(cli("thread", "send", thread, "Reply with just the word OK. No tools.", "--wait", "--json"))
