#!/usr/bin/env bash
set -euo pipefail
# Rebuild the two revisions using fresh, synthetic state. Logs can contain tokens;
# keep *.private.log local. Do not use the live install as a database seed.
scratch=/tmp/issue-lead-33740-r1/capture-2
run_dir="$scratch/$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$run_dir"
git -C /home/user/t3code worktree add /home/user/wt/issue-33740-before 4c361199f47f6ea32a2c14835df392640d0f7c63
git -C /home/user/t3code worktree add /home/user/wt/issue-33740-after b5b9a154b43e0fc72e821d41df26de314f585f24
for side in before after; do
  checkout="/home/user/wt/issue-33740-$side"
  (cd "$checkout" && vp install) > "$run_dir/install-$side.log" 2>&1
  (cd "$checkout" && exec env T3CODE_DEV_SEED=0 vp run dev) > "$run_dir/server-$side.private.log" 2>&1 &
  printf '%s\n' "$!" > "$run_dir/server-$side.pid"
done
printf 'Private runtime logs and wrapper PIDs: %s\n' "$run_dir"
# Read only the [dev-runner] port line from each log, then open /pair on its web
# port in a new preview tab. In each checkout mint a private token with:
# node apps/server/src/bin.ts pair --base-dir <checkout>/.t3
# Paste into Pairing token and Continue. Never print or upload the token.
# Fresh app state supplies project server and one stopped New thread.

# Keep this terminal session alive while both captured server processes run.
wait
