#!/usr/bin/env bash
set -euo pipefail
# Run from either checkout after vp i and starting its own fresh dev server.
# Server environment: T3CODE_DEV_SEED=0 and the supplied Gemini hub base URL.
# In Settings > Providers add Antigravity, choose Gemini API key, enter a
# non-empty test key and click Connect. Runtime used: agy 1.5.19.
# Usage: bash reproduce.sh <base-dir> <synthetic-project-folder> delegated|manual
proof_base_dir=$1
proof_workspace=$2
proof_mode=$3
node apps/server/src/bin.ts project add --base-dir "$proof_base_dir" --title 'Question demo' "$proof_workspace"
if [ "$proof_mode" = delegated ]; then
  node apps/server/src/bin.ts thread start --base-dir "$proof_base_dir" --title 'Pending question and steer' --provider antigravity --model gemini-3.8-flash "$proof_workspace" 'Start a delegated background task using delegate_task: ask it to wait about 45 seconds and then reply DONE, without editing files. Immediately after starting it, use request_user_input to ask me to choose red or blue. Keep the question open and wait for my answer. Do not answer it yourself. This is a pending-question interaction check.'
  # Open the printed thread in the web client. Leave its question unanswered.
  # Wait for the delegated task to finish. Base loses the question and fails.
  # Then run (substitute the printed thread id):
  # node apps/server/src/bin.ts thread send --base-dir <base-dir> <thread-id> 'After the color answer, reply FOLLOWUP_OK.'
  # On head, the question remains. Submit it; the follow-up returns FOLLOWUP_OK.
else
  node apps/server/src/bin.ts thread start --base-dir "$proof_base_dir" --title 'Manual steer with open question' --provider antigravity --model gemini-3.8-flash "$proof_workspace" 'Use request_user_input to ask me to choose red or blue. Keep the question open and wait for my answer. Do not answer it yourself.'
  # Open the thread and leave its question unanswered. Queue a message:
  # node apps/server/src/bin.ts thread send --base-dir <base-dir> <thread-id> 'Manual steer: after my answer, reply MANUAL_OK.'
  # Click Send now on that queued message, while the question is pending.
  # Base fails and loses the question. Head leaves the message queued.
  # On head, the captured run first submitted the blank answer; the agent
  # asked again in the queued turn. Selecting Red then returned MANUAL_OK.
  # Send another message on both sides:
  # node apps/server/src/bin.ts thread send --base-dir <base-dir> <thread-id> 'Reply RECOVERY_OK.'
  # Base fails again; head responds RECOVERY_OK.
fi
