#!/usr/bin/env bash
set -euo pipefail
# Run once per checkout with a new scratch directory and server port.
# Usage: reproduce.sh CHECKOUT SCRATCH PORT
checkout="$1"
scratch="$2"
port="$3"
mkdir -p "$scratch/bin" "$scratch/project"
git init "$scratch/project"
ln -s "$(command -v node)" "$scratch/bin/node"
cat > "$scratch/bin/clean-shell" <<'SH'
#!/bin/sh
exec /bin/sh -c "$2"
SH
chmod +x "$scratch/bin/clean-shell"
cd "$checkout"
T3CODE_DEV_SEED=0 SHELL="$scratch/bin/clean-shell" PATH="$scratch/bin:/usr/bin:/bin"   node apps/server/src/bin.ts --no-browser --host 0.0.0.0 --port "$port"   --base-dir "$scratch/home" --auto-bootstrap-project-from-cwd "$scratch/project"
# In a separate shell: run mobile:install android --prepare, lease Pixel 9,
# install using --session, and start dev:client on an unused port.
# Pair with test-t3-mobile/scripts/pair-client.sh using a device-reachable origin.
# Rename the connection to Test host in Settings > Environments > details > Label.
# Tap Chats > New thread > project. Verify the environment chip says Connected.
# Capture the fallback, then run the same interaction on each revision:
# agent-device record start typing.mp4 --session SESSION
# agent-device fill 'role="text-field" label="Ask anything"' 'hello from repro' --session SESSION --settle
# agent-device back --session SESSION --settle
# agent-device record stop --session SESSION
