#!/usr/bin/env bash
# Run from either isolated checkout. Inputs are its server port and disposable T3 home.
set -euo pipefail
port="$1"
base_dir="$2"
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
node "$script_dir/seed.mjs" "$port" "$base_dir"
# This uses the real CLI's MCP path, which generates an mcp:<uuid> ID.
launch_result="$(node apps/server/src/bin.ts thread start \
  84f71ed8-6aa9-44bb-b140-c99588d1f001 'Ready for restart check.' \
  --title 'MCP cold-start check' --provider devReplay --model todo-list \
  --base-dir "$base_dir" --json)"
printf '%s\n' "$launch_result"
thread_id="$(printf '%s' "$launch_result" | node -e 'let s=""; for await (const chunk of process.stdin) s+=chunk; console.log(JSON.parse(s).threadId)')"
node "$script_dir/archive-scaffolding.mjs" "$port" "$base_dir" "$thread_id"
