#!/bin/bash
# Run separately in each built checkout, against its own isolated T3 home.
# Service and Electron must inherit a graphical DISPLAY and D-Bus session.
# Pair the service's LAN endpoint in Electron Settings with Local environment disabled.
# Supply CHECKOUT, T3_HOME and OUTPUT, then run capture.cjs with CDP_URL and OUTPUT.
set -eu
: "${CHECKOUT:?}" "${T3_HOME:?}" "${OUTPUT:?}"
mkdir -p "$OUTPUT/workspace/Local-launch-demo"
project="$OUTPUT/workspace/Local-launch-demo"
printf '# Local launch demo\n\nA synthetic project for checking editor and file manager actions.\n' > "$project/README.md"
git -C "$project" init -q -b main
git -C "$project" add README.md
git -C "$project" -c user.name=Demo -c user.email=demo@example.invalid commit -qm 'Initial demo'
cd "$CHECKOUT"
node apps/server/src/bin.ts project add "$project" --title Local-launch-demo --base-dir "$T3_HOME"
node apps/server/src/bin.ts thread start "$project" 'Inspect this project.' --title 'Local editor actions' --provider devReplay --model multi-turn --wait --json --base-dir "$T3_HOME" > "$OUTPUT/thread.json"
# Mint the short-lived pairing credential locally; never publish its output.
node apps/server/src/bin.ts pair --base-dir "$T3_HOME" > "$OUTPUT/pairing-private.txt"
