#!/usr/bin/env bash
# Run from the pre-upgrade checkout after enabling Pi in Settings > Providers.
# Supply an isolated data dir and an empty synthetic project directory.
set -euo pipefail
base_dir=$1
project_dir=$2
node apps/server/src/bin.ts project add --base-dir "$base_dir" --title 'Pi checkpoint proof' "$project_dir"
reply=$(node apps/server/src/bin.ts thread start --base-dir "$base_dir" --provider pi --model default --title 'Legacy Pi checkpoint' --wait --json "$project_dir" 'Reply with exactly: ONE')
thread_id=$(printf '%s' "$reply" | python3 -c 'import json,sys; print(json.load(sys.stdin)["threadId"])')
node apps/server/src/bin.ts thread send --base-dir "$base_dir" --wait --json "$thread_id" 'Reply with exactly: TWO'
printf 'Thread: %s\n' "$thread_id"
# Stop the pre-upgrade server. Preserve this synthetic data for both sides.
# Add --extension <absolute path to handoff.ts> to Pi launch arguments.
# Start each comparison checkout on its own copy of the saved data, then run:
# node apps/server/src/bin.ts thread send --base-dir "$base_dir" --wait --json "$thread_id" '/handoff Reply with exactly: THREE'
