#!/usr/bin/env bash
set -euo pipefail
# Run from an installed app checkout. Start the app separately with:
# T3CODE_DEV_SEED=0 T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD=0 vp run dev --home-dir .t3/proof
# Set DEMO_ROOT to a new synthetic repository directory, and DEMO_MODEL to
# an available low-cost Claude model. No credentials or model ids are stored here.
: "${DEMO_ROOT:?set a new synthetic repository directory}"
: "${DEMO_MODEL:?set an available low-cost Claude model}"
if [ "${1:-prepare}" = prepare ]; then
  mkdir -p "$DEMO_ROOT"
  git -C "$DEMO_ROOT" init -b main
  git -C "$DEMO_ROOT" config user.name Demo
  git -C "$DEMO_ROOT" config user.email demo@example.invalid
  printf 'Synthetic branch tracking demonstration\n' > "$DEMO_ROOT/README.md"
  git -C "$DEMO_ROOT" add .
  git -C "$DEMO_ROOT" commit -m Initial
  git -C "$DEMO_ROOT" checkout -b fix/preview-uri-expiry-retry
  git -C "$DEMO_ROOT" worktree add .claude/worktrees/home-screen-design -b home-screen-design
  node apps/server/src/bin.ts project add "$DEMO_ROOT" --title 'Branch demo' --base-dir .t3/proof
  node apps/server/src/bin.ts thread start "$DEMO_ROOT" 'Reply Ready only. Do not use tools yet.' --provider claudeAgent --model "$DEMO_MODEL" --title 'Branch follows session' --wait --json --base-dir .t3/proof
else
  : "${DEMO_THREAD:?set the threadId returned by prepare}"
  node apps/server/src/bin.ts thread send "$DEMO_THREAD" 'Use the EnterWorktree tool with path .claude/worktrees/home-screen-design to enter the existing linked worktree. Then run pwd && git branch --show-current. Do not edit files. Reply with only the branch name.' --wait --json --base-dir .t3/proof
fi
# Browser: pair, open Branch follows session, record before sending the move,
# then inspect the sidebar and the open Thread details panel when it finishes.
# Expand Worked for to inspect EnterWorktree and Bash results.
