#!/usr/bin/env bash
set -eu
out=$1
tree=$2
port=$3
mkdir -p "$out"
driver_dir=$(cd "$(dirname "$0")" && pwd)
: "${T3CODE_DEV_AUTH_TOKEN:?Set the isolated server dev credential}"
# This shell runs only the synthetic driver; no prompt or command paths are displayed.
cat > "$out/terminal.sh" <<EOF
#!/usr/bin/env bash
sleep 5
node '$driver_dir/drive.mjs' '$tree' '$port' | tee '$out/transcript.txt'
sleep 10
EOF
chmod +x "$out/terminal.sh"
gnome-terminal --wait --title="Skill discovery evidence" --geometry=140x40 -- "$out/terminal.sh" &
terminal_pid=$!
window=$(xdotool search --sync --onlyvisible --name "Skill discovery evidence" | head -1)
xdotool windowsize "$window" 1280 800
xdotool windowmove "$window" 0 0
ffmpeg -y -loglevel error -f x11grab -video_size 1280x800 -framerate 10 -i "$DISPLAY" -t 13 -c:v libx264 -pix_fmt yuv420p "$out/recording.mp4"
wait "$terminal_pid"
