#!/usr/bin/env bash
# Commands used for each side after installing, opening, and pairing the iOS dev client.
# Run from that side's checkout with a fresh server and synthetic project named server.
# SESSION, CAPTURE_DIR and T3_HOME identify the disposable device and server state.
set -euo pipefail
: "${SESSION:?}" "${CAPTURE_DIR:?}" "${T3_HOME:?}"
agent-device press 'label="New chat"' --session "$SESSION" --settle
agent-device press 'label="server" role=button' --session "$SESSION" --settle
agent-device record start "$CAPTURE_DIR/flow.mp4" --session "$SESSION" --fps 10 --hide-touches
agent-device press 'label="Model and reasoning settings, Showcase"' --session "$SESSION" --settle
agent-device press 'label="Showcase" role=cell' --session "$SESSION" --settle
agent-device press 'label="Done" role=button' --session "$SESSION" --settle
prompt=$'    if ready:\n        print("go")'
agent-device fill 'label="Ask anything"' "$prompt" --session "$SESSION" --settle
agent-device screenshot "$CAPTURE_DIR/before-send.png" --session "$SESSION"
agent-device press 'label="Send" role=button' --session "$SESSION" --settle
agent-device wait 'label="Send" role=button' 60000 --session "$SESSION"
agent-device scroll top --session "$SESSION" --settle
agent-device screenshot "$CAPTURE_DIR/after-send.png" --session "$SESSION"
agent-device record stop --session "$SESSION"
agent-device fill 'label="Ask anything"' "$prompt" --session "$SESSION" --settle
agent-device press 'label="Send" role=button' --session "$SESSION" --settle
agent-device wait 'label="Send" role=button' 60000 --session "$SESSION"
sqlite3 -readonly -json "$T3_HOME/userdata/statev2.sqlite" "select json_extract(payload_json,'$.text') as text from orchestration_v2_projection_messages where role='user' order by created_at;" > "$CAPTURE_DIR/stored-text.json"
