#!/usr/bin/env bash
# Run from each checkout. HOME_DIR, DEMO, DEVICE_HOST, SERVER_PORT, METRO_PORT,
# SESSION and OUT are caller-supplied disposable locations and device configuration.
set -eu
export T3CODE_DEV_SEED=0 T3CODE_ENVIRONMENT_LABEL='Share demo' T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD=0
# Start in a retained terminal:
# vp run dev:server --host 0.0.0.0 --port "$SERVER_PORT" --home-dir "$HOME_DIR" --no-seed
# Start in apps/mobile in another retained terminal:
# APP_VARIANT=development CI=1 EXPO_NO_METRO_LAZY=1 REACT_NATIVE_PACKAGER_HOSTNAME="$DEVICE_HOST" vp run dev:client --port "$METRO_PORT"
node apps/server/src/bin.ts project add "$DEMO" --title 'Share demo' --base-dir "$HOME_DIR"
node apps/server/src/bin.ts thread start "$DEMO" first --title 'Share a response' --provider devReplay --model multi-turn --wait --json --base-dir "$HOME_DIR"
node apps/server/src/bin.ts auth pairing create --ttl 15m --label proof --base-url "http://$DEVICE_HOST:$SERVER_PORT" --base-dir "$HOME_DIR" > "$OUT/pair.txt"
# Install the cached native client and open the Metro URL for this checkout:
vp run mobile:install android --session "$SESSION" --metro "http://$DEVICE_HOST:$METRO_PORT"
# Open the pairing link through t3code-dev://connections/new?pairingUrl=<encoded URL>&autoConnect=1.
# In the native app: tap Share a response; capture the completed response footer.
# Record Copy message, Share response (when present), and the system destination.
# Base has Copy and Fork. Head adds Share response between them.
# Capture both frames at least 500ms apart and compare before retaining a still.
