#!/usr/bin/env bash
set -euo pipefail
# Usage: bash reproduce.sh serve|seed CHECKOUT FIXTURE_DIRECTORY
# Run serve in a retained terminal; run seed in another after the server listens.
mode=$1
checkout=$2
fixture=$3
cd "$checkout"
if [ "$mode" = serve ]; then
  mkdir -p "$fixture/demo"
  printf '%s' '{"skills":[]}' > "$fixture/snap.json "
  git init -q "$fixture/demo"
  export T3CODE_DEV_SEED=0
  export T3CODE_CODEX_LAUNCH_ARGS="--cloud-skills-snapshot $fixture/snap.json\\ "
  exec vp run dev
elif [ "$mode" = seed ]; then
  node apps/server/src/bin.ts project add "$fixture/demo" --title 'Launch override proof' --base-dir .t3
  node apps/server/src/bin.ts thread start "$fixture/demo" 'Reply with the single word OK.' --title 'Escaped trailing space' --provider codex --model gpt-6-luna --base-dir .t3 --json
else
  exit 2
fi
# Browser driver: pair with the startup URL, open returned thread by link,
# close Thread details, record, fill contenteditable with the same prompt,
# press Enter, wait for failure/OK, blur composer, capture stable screenshots.
# Chromium 1280x800 CSS pixels, device scale 2, light theme, Linux.
