#!/usr/bin/env bash
set -euo pipefail
# Run from either checkout, with its fresh dev server already running.
# Setup in the web UI: add Antigravity, Gemini API key, synthetic-test-key,
# then select the instance and Connect. agy version used: 1.5.18.
# Start dev with T3CODE_DEV_SEED=0 and GOOGLE_GEMINI_BASE_URL set to the
# available Gemini-compatible endpoint. Never upload its credentials.
phase=$1
case "$phase" in
  seed)
    project_path=$2
    node apps/server/src/bin.ts project add --base-dir .t3 --title 'Trajectory recovery demo' "$project_path"
    ;;
  first-turn)
    project_id=$2
    node apps/server/src/bin.ts thread start --base-dir .t3 --provider antigravity --model gemini-3.8-flash --title 'Missing trajectory recovery' --wait --json "$project_id" 'reply PINEAPPLE'
    ;;
  *) echo 'Usage: reproduce.sh seed <empty-project-path> | first-turn <project-id>' >&2; exit 2 ;;
esac
# After PINEAPPLE completes, use the real web client at 1280x800, dark theme.
# Open the returned thread, collapse sidebar and thread details for privacy.
# Capture the ACP PID from your own server process tree. Verify server ownership
# and the process --gemini-dir before terminating only that ACP child with TERM.
# Read the native session UUID from the test database provider-thread payload.
# Remove ONLY these four files in that instance private antigravity-acp folder:
# conversations/<UUID>.db, conversations/<UUID>.db-wal,
# conversations/<UUID>.db-shm, annotations/<UUID>.pbtxt.
# Start recording; type `reply MANGO` into the composer and press Enter once.
# Base: provider error, no MANGO reply. Head: context handoff and MANGO reply.
# No retry or third turn was sent. No initialize timeout was injected.
