#!/usr/bin/env bash
# Run from each checkout after vp i, with a fresh worktree-local .t3.
# Requires @opencode/cli@2.2.7 and agent-browser.
# Start separately: T3CODE_DEV_SEED=0 vp run dev
# Configure .t3/userdata/settings.json providerInstances.opencode:
# {"driver":"opencode","enabled":true,"config":{"enabled":true,"binaryPath":"<2.2.7 binary>"}}
# Arguments: empty git project path, private pairing URL, output directory.
set -eu
project=$1
pairing_url=$2
out=$3
mkdir -p "$out"
git init "$project"
node apps/server/src/bin.ts project add --base-dir .t3 --title 'Goal clear reproduction' "$project"
node apps/server/src/bin.ts thread start --base-dir .t3 --provider opencode --model anthropic/claude-haiku-4-5 --wait --json "$project" '/goal clear' > "$out/turn.json" 2>&1 || true
agent-browser --session goal-proof set viewport 1440 900
agent-browser --session goal-proof open "$pairing_url"
agent-browser --session goal-proof wait --text 'Goal clear reproduction'
agent-browser --session goal-proof find role button click --name '/goal clear, Goal clear reproduction'
# On base, the button name includes Failed; use the matching snapshot ref instead.
# Close thread details if open before recording, to exclude environment details.
agent-browser --session goal-proof snapshot -i
# The evidence used snapshot refs for this same action sequence:
agent-browser --session goal-proof record start "$out/flow.mp4"
agent-browser --session goal-proof find role textbox fill --name 'Message /goal clear' '/goal clear'
agent-browser --session goal-proof press Enter
# Wait for terminal status via `t3 thread show --base-dir .t3 <threadId> --json`.
# Base: failed, generic provider error; head: completed, activeRunId null.
# Capture twice at least 500 ms apart and compare for stability before keeping final.png.
agent-browser --session goal-proof screenshot "$out/final.png"
agent-browser --session goal-proof record stop
