#!/usr/bin/env bash
set -euo pipefail
# Run from the commit's checkout after vp i and T3CODE_DEV_SEED=0 vp run dev.
# Enable a Pi provider instance named pi, with launch arguments --approve.
# Pass a new scratch project directory as the first argument.
project_dir=$1
mkdir -p "$project_dir/.pi/extensions"
git -C "$project_dir" init
cat > "$project_dir/.pi/extensions/newsess.ts" <<'TS'
export default function (pi) {
  pi.registerCommand("newsess", {
    description: "Start a new session with parent tracking",
    handler: async (_args, ctx) => {
      await ctx.newSession({ parentSession: ctx.sessionManager.getSessionFile() });
    },
  });
}
TS
node apps/server/src/bin.ts project add --base-dir .t3 --title 'Pi fork proof' "$project_dir"
started=$(node apps/server/src/bin.ts thread start --base-dir .t3 --title 'ALPHA historical fork' --provider pi --model anthropic/claude-haiku-4-5-20251001 --wait --json "$project_dir" 'Remember the word ALPHA. Reply exactly: ALPHA noted.')
thread_id=$(python3 -c 'import json,sys;print(json.load(sys.stdin)["threadId"])' <<< "$started")
printf '%s\n' "$started"
node apps/server/src/bin.ts thread send --base-dir .t3 --wait --json "$thread_id" 'Remember the word BRAVO. Reply exactly: BRAVO noted.'
printf 'Open this thread in the web client: %s\n' "$thread_id"
# Browser steps used on BOTH commits, in the same 1280x800 light-theme viewport:
# 1. Open the seeded thread by its environment/thread URL.
# 2. Type /newsess, Enter to select the extension, Enter to submit; wait for idle.
# 3. Send: Remember the word CHARLIE. Reply exactly: CHARLIE noted.
# 4. Snapshot the source files with audit-sessions.py snapshot before forking.
# 5. Click the first 'Fork from this response' (ALPHA noted.).
# 6. Send: List every word I asked you to remember. Reply only with the words.
# 7. Wait for completion; capture the result, expand any native-fork warning.
# 8. Run audit-sessions.py audit for the fork thread and inspect session provenance.
# Record steps 2-7. Hide navigation/details for the final stills. Capture two
# identical screenshots at least 500 ms apart before retaining the still.
