"""Run from either T3 checkout, after T3CODE_DEV_SEED=0 vp run dev.
Real OpenCode 2.4.2 must be enabled; its Haiku 5.5 model must be configured.
Pass a fresh synthetic project path and that server's base-dir as arguments.
Then open each returned thread in the web app, click Fork from this response
on its FIRST reply, and submit PROBE below. Record this interaction on each side.
Viewport: Chromium 1280x800 CSS pixels, light theme, device scale factor 2.
Hide sidebar and thread details before captures; forks reopen thread details.
"""
import json
from pathlib import Path
import subprocess
import sys

PROBE = "List every user message you have received in this conversation, verbatim, and quote any product draft you wrote. Include inherited history. Do not read files or use tools."
project, home = map(Path, sys.argv[1:3])
project.mkdir(parents=True, exist_ok=True)
command = project / ".opencode/commands/draft.md"
command.parent.mkdir(parents=True, exist_ok=True)
command.write_text("---\ndescription: Draft a product announcement\n---\nWrite a two-sentence draft announcement about: $ARGUMENTS. Return only the announcement.\n")
subprocess.run(["git", "init", "-q", str(project)], check=True)

def cli(*args):
    p = subprocess.run(["node", "apps/server/src/bin.ts", *args, "--base-dir", str(home)], text=True, capture_output=True, check=True)
    return p.stdout.strip()

print(cli("project", "add", str(project), "--title", "Fork proof"))
for name, first, product, followup in [
    ("Case A: command and follow-up", "FIRST REPLY OK", "PURPLE PELICAN 7Q", True),
    ("Case B: command is last turn", "FIRST REPLY B", "GREEN WALRUS 3X", False),
]:
    started = json.loads(cli("thread", "start", str(project), "Reply with exactly: " + first,
        "--provider", "opencode", "--model", "anthropic/claude-haiku-5-5", "--title", name, "--wait", "--json"))
    print(json.dumps(started))
    thread = started["threadId"]
    print(cli("thread", "send", thread, "/draft the launch of the " + product + " product", "--wait", "--json"))
    if followup:
        print(cli("thread", "send", thread, "Reply with exactly: FOLLOWUP OK", "--wait", "--json"))
    print("In the web app, fork from " + first + " and send: " + PROBE)
