#!/usr/bin/env bash
set -euo pipefail
# Run from the checkout under test; use separate fresh T3 homes for base and head.
# Parameters: fresh home, demo git workspace, agent-device session, reachable server origin.
HOME_DIR=$1
WORKSPACE=$2
SESSION=$3
ORIGIN=$4
mkdir -p "$HOME_DIR/userdata" "$WORKSPACE"
python3 - "$HOME_DIR" <<'CONFIG'
import json,sys
from pathlib import Path
settings = {
 "defaultModelSelection":{"instanceId":"localAcp","model":"anthropic/claude-haiku-5-5"},
 "providerInstances":{
  "localAcp":{"driver":"acpRegistry","displayName":"Local ACP","enabled":True,
    "config":{"source":"local","commandPath":"opencode","commandArgs":["acp"]}},
  "codex":{"driver":"codex","enabled":False},
  "claudeAgent":{"driver":"claudeAgent","enabled":False}}
}
(Path(sys.argv[1])/"userdata/settings.json").write_text(json.dumps(settings))
CONFIG
# Start before continuing (in another retained terminal):
# T3CODE_DEV_SEED=0 T3CODE_ENVIRONMENT_LABEL='Steering demo' vp run dev --host 0.0.0.0 --home-dir "$HOME_DIR"
# Start Metro from apps/mobile on all interfaces and open its dev-client link on the leased Pixel 9.
# Install only using: vp run mobile:install android --session "$SESSION" --metro <reachable-Metro-origin>
git -C "$WORKSPACE" init --initial-branch=main
git -C "$WORKSPACE" -c user.name=Demo -c user.email=demo@example.invalid commit --allow-empty -m 'Initial commit'
node apps/server/src/bin.ts project add "$WORKSPACE" --title 'Steering demo' --base-dir "$HOME_DIR"
node apps/server/src/bin.ts thread start "$WORKSPACE" 'Reply READY.' --title 'ACP steering' --provider localAcp --model anthropic/claude-haiku-5-5 --base-dir "$HOME_DIR" --json
# Pair with .agents/skills/test-t3-mobile/scripts/pair-client.sh, open Chats and ACP steering.
# Record BEFORE sending sleep; substitute the threadId printed above for THREAD_ID.
# agent-device record start <side.mp4> --scope app --hide-touches --session "$SESSION"
# node apps/server/src/bin.ts thread send "$THREAD_ID" 'Run the shell command `sleep 150` and then reply with just the word DONE.' --base-dir "$HOME_DIR" --json
# Wait until mobile shows Working / Running sleep. Then:
# agent-device fill 'label="Ask anything" editable=true' 'Mobile steer: stop and reply STEERED' --session "$SESSION"
# agent-device snapshot -i --session "$SESSION"  # confirm the button is Steer
# agent-device press 'label="Steer" role=button' --session "$SESSION"
# Observe queue vs immediate Steer message and STEERED reply; do not press Send now.
# agent-device screenshot <side.png> --session "$SESSION"
# agent-device record stop --session "$SESSION"
