#!/usr/bin/env bash
set -eu
# Run from either checked-out revision after vp i and T3CODE_DEV_SEED=0 vp run dev.
# Usage: bash seed-and-steps.sh /absolute/path/to/new/demo
project_dir=$1
mkdir -p "$project_dir"
cat > "$project_dir/server.mjs" <<'JS'
import http from "node:http";
const server = http.createServer((req,res)=>res.end("Stop demo"));
server.listen(18743,"127.0.0.1",()=>console.log("Listening on 18743"));
process.on("SIGTERM",()=>server.close(()=>process.exit(0)));
JS
git -C "$project_dir" init -q
git -C "$project_dir" add server.mjs
git -C "$project_dir" -c user.name=Demo -c user.email=demo@example.com commit -qm 'Add demo server'
node apps/server/src/bin.ts project add --base-dir .t3 --title 'User stop demo' "$project_dir"
node apps/server/src/bin.ts thread start --base-dir .t3 --provider codex --model gpt-6.1-sol --title 'Intentional server stop' "$project_dir" 'Start node server.mjs as a long-running background exec command, keep its exec session running, and end your turn once it is listening. Do not detach it, use systemd, nohup, or shell backgrounding. Do not edit files. If the command later exits, report what happened and do not restart it.' --json
# Pair the web client and open the returned thread link in the local app.
# Wait for Running and Servers > localhost:18743.
# Hide only the Workspace region for privacy in both recordings:
# document.querySelector('[aria-label="Workspace"]').style.visibility='hidden';
# Start recording, then invoke the real Servers-panel stop button:
# document.querySelector('button[aria-label="Stop localhost:18743"]').click();
# Observe the stopped command and any unsolicited new turn.
# Confirm using: node apps/server/src/bin.ts thread show --base-dir .t3 THREAD_ID --json
