#!/usr/bin/env bash
# Run separately in each clean checkout after vp i.
# Start its dev server first with T3CODE_DEV_SEED=0 and GH_TOKEN supplied securely.
# Usage: bash reproduce.sh /absolute/path/to/copilot /absolute/path/to/synthetic-project
set -euo pipefail
COPILOT_PROOF_BIN="$1"
COPILOT_PROOF_PROJECT="$2"
export COPILOT_PROOF_BIN
python3 - <<'PY'
import json,os
p='.t3/userdata/settings.json'
with open(p) as f:d=json.load(f)
d.setdefault('providerInstances',{})['copilot-proof']={
 'driver':'acpRegistry','displayName':'Copilot',
 'config':{'source':'local','commandPath':os.environ['COPILOT_PROOF_BIN'],
           'commandArgs':['--acp','--no-auto-update']}}
with open(p,'w') as f:json.dump(d,f,indent=2)
PY
node apps/server/src/bin.ts project add --base-dir .t3 --title 'Copilot lifecycle proof' "$COPILOT_PROOF_PROJECT"
node apps/server/src/bin.ts thread start --base-dir .t3 --provider copilot-proof --model auto --title 'Runtime exit verification' "$COPILOT_PROOF_PROJECT" "Launch ONE background subagent using the task tool in background mode. Tell that subagent: run \`sleep 900 && echo done\` in the foreground and wait for the command to finish; do not background the shell command. You (the parent) must not wait for the subagent. Reply 'launched'." --json
# Open the returned thread's link in the local web client and start recording.
# Wait for 'launched', Running, Waiting, and Lineage · 1 running.
# Run kill-runtime.py <server-port> <checkout-root> <side>.
# Leave idle and capture. Then send 'Reply with just the word pong'.
# Repeat the same background-subagent prompt with sleep 901 and use kill-runtime-901.py.
