#!/usr/bin/env bash
set -euo pipefail
# Manual proof driver. Run setup with seed.sh and pair the dev client first.
# SESSION is an already leased Pixel 9; SERVER_PORT is this checkout's isolated backend.
# OUTPUT_DIR must be a new timestamped directory outside the checkout.
: "${SESSION:?}" "${SERVER_PORT:?}" "${OUTPUT_DIR:?}"
ad() { agent-device "$@" --session "$SESSION"; }
ad record start "$OUTPUT_DIR/run.mp4" --hide-touches
sudo -n iptables -I INPUT 1 ! -i lo -p tcp --dport "$SERVER_PORT" -j REJECT
trap 'sudo -n iptables -D INPUT ! -i lo -p tcp --dport "$SERVER_PORT" -j REJECT 2>/dev/null || true' EXIT
ad fill 'label="Ask anything"' 'offline follow-up two 48963' --settle
ad press 'label="Send"' --settle
ad back --settle
# In the localhost web client: sidebar Archive proof context menu > Archive thread.
read -r -p 'After archiving in web, press Enter: '
ad open com.t3tools.t3code.dev --relaunch
ad wait 'text="Archive proof"' 30000
ad snapshot -i
# Confirm the thread says messages queued to send before restoring the connection.
sudo -n iptables -D INPUT ! -i lo -p tcp --dport "$SERVER_PORT" -j REJECT
trap - EXIT
ad wait absent 'text="Archive proof"' 60000
ad snapshot -i
# In web Settings > Archive: Unarchive Archive proof.
read -r -p 'After unarchiving in web, press Enter: '
ad wait 'text="Archive proof"' 30000
ad press 'text="Archive proof"' --settle
ad wait 'label="Model and reasoning settings, Multi turn"' 30000
ad snapshot -i
ad screenshot "$OUTPUT_DIR/final-a.png"
ad wait 500
ad screenshot "$OUTPUT_DIR/final-b.png"
ad record stop
