#!/bin/bash
# Run from either installed checkout. Use distinct T3CODE_HOME and XDG_CONFIG_HOME.
# Start the web renderer first with T3CODE_DEV_SEED=0 vp run dev:web.
# Supply its printed web port as argument 1 and the printed server port as argument 2.
set -eu
root=$PWD
: "${T3CODE_HOME:?Use a fresh isolated T3 home}"
: "${XDG_CONFIG_HOME:?Use a fresh isolated Electron config directory}"
export T3CODE_DEV_SEED=0 T3CODE_PORT="$2" VITE_DEV_SERVER_URL="http://localhost:$1"
mkdir -p "$T3CODE_HOME/userdata"
node --input-type=module - "$root" <<'JS'
import fs from 'node:fs';
const root=process.argv[2];
fs.writeFileSync(process.env.T3CODE_HOME+'/userdata/settings.json',JSON.stringify({providerInstances:{devReplay:{driver:'acpRegistry',displayName:'Replay (dev)',enabled:true,config:{source:'local',commandPath:process.execPath,commandArgs:[root+'/apps/server/scripts/dev-replay-agent.ts']}}}}));
JS
unset ELECTRON_RUN_AS_NODE T3CODE_DESKTOP_REMOTE_DEBUGGING_PORT
cd apps/desktop
exec headless-desktop node_modules/electron/dist/electron --no-sandbox --disable-gpu dist-electron/main.cjs
# Once ready, in another terminal from the same checkout:
# node apps/server/src/bin.ts project add <fixture-page-directory> --title 'Browser proof' --base-dir "$T3CODE_HOME"
# node apps/server/src/bin.ts thread start <fixture-page-directory> Ready --title 'Browser proof' --provider devReplay --model multi-turn --base-dir "$T3CODE_HOME" --json
# In the app: disable onboarding imports, open Browser proof, Ctrl+Shift+J,
# expand Browser, and navigate to the fixture HTTP server. Do not click the guest.
# The driver reloads the page before its first recorded guest click.
