"""Run from either evidence checkout, with its fresh dev server running.

Usage: python3 seed.py SAMPLE_DIRECTORY
Start the server with T3CODE_DEV_SEED=0 vp run dev.
Then open the printed parent thread in the paired web client.
While turn 2 is running, click 'Fork from this response' on turn 1.
Wait for the fork composer, then send:
Without using tools, what access phrase did you read in a.txt, and which tool did you use?
Record the UI through completion. Inspect the isolated database and Claude JSONL
for context handoffs, forkedFrom, and preserved Read tool_use/tool_result.
"""
import json
from pathlib import Path
import subprocess
import sys

sample = Path(sys.argv[1]).resolve()
sample.mkdir(parents=True, exist_ok=True)
(sample / "a.txt").write_text("The lighthouse access phrase is amber otter.\n")
subprocess.run(["git", "init", "-q", str(sample)], check=True)
subprocess.run(["git", "-C", str(sample), "add", "a.txt"], check=True)
subprocess.run(["git", "-C", str(sample), "-c", "user.name=Demo", "-c",
                "user.email=demo@example.com", "commit", "-qm", "Initial sample"], check=True)
cli = ["node", "apps/server/src/bin.ts"]
subprocess.run(cli + ["project", "add", "--base-dir", ".t3", "--title",
                      "Native history demo", str(sample)], check=True)
result = subprocess.run(cli + ["thread", "start", "--base-dir", ".t3",
    "--provider", "claudeAgent", "--model", "haiku", "--title", "Parent thread",
    "--wait", "--json", str(sample),
    "Use the Read tool to read a.txt, then state its access phrase in one sentence. Do not use any other tools."],
    check=True, text=True, capture_output=True)
parent = json.loads(result.stdout)["threadId"]
print("Parent:", parent, flush=True)
input("Open the parent thread and start browser recording; press Enter to send turn 2: ")
subprocess.run(cli + ["thread", "send", "--base-dir", ".t3", "--json", parent,
    "Write a 2500-word story about a lighthouse keeper and an otter. Do not use tools. Write the complete story in this response."], check=True)
