#!/usr/bin/env bash
# Run in each isolated checkout after `vp i`. No real data is seeded.
set -euo pipefail
proof_dir="$PWD/.t3/pi-proof"
mkdir -p "$proof_dir/workspace" "$PWD/.t3/userdata"
cat > "$proof_dir/pi-discovery-wrapper" <<'WRAPPER'
#!/bin/sh
for arg in "$@"; do
  if [ "$arg" = "--offline" ]; then
    echo "induced discovery failure" >&2
    exit 1
  fi
done
exec pi "$@"
WRAPPER
chmod +x "$proof_dir/pi-discovery-wrapper"
git init "$proof_dir/workspace"
python3 - "$proof_dir/pi-discovery-wrapper" <<'SETTINGS'
import json,sys
from pathlib import Path
Path('.t3/userdata/settings.json').write_text(json.dumps({
  'providerInstances': {'pi': {'driver': 'pi', 'enabled': True,
    'config': {'binaryPath': sys.argv[1]}}},
  'defaultModelSelection': {'instanceId': 'pi', 'model': 'default'}
}))
SETTINGS
printf '%s\n' 'Start in another terminal: T3CODE_DEV_SEED=0 vp run dev'
printf '%s\n' 'After the server starts, run:'
printf 'node apps/server/src/bin.ts project add --base-dir .t3 --title "Pi model validation proof" "%s/workspace"\n' "$proof_dir"
printf '%s\n' 'Then start a thread with the printed project id:'
printf '%s\n' "node apps/server/src/bin.ts thread start --base-dir .t3 --provider pi --model default --title 'Explicit Pi model before discovery' --json PROJECT_ID 'Call orchestrator_capabilities once, then delegate_task once with target providerInstanceId pi, model anthropic/claude-haiku-5-5, task Reply with exactly hello, mode wait. Do not use other tools. Report the exact delegate_task result.'"
# Direct provider control, run from the synthetic workspace:
# pi --model anthropic/claude-haiku-5-5 -p 'Reply with exactly hello'
# Open the startup pairing URL, then the printed thread in the web app.
# Captures used a 1440x1000 viewport, light theme, sidebar and details closed.
# Repeat the identical prompt once through the composer while recording.
