#!/usr/bin/env bash
# Run once per isolated checkout after T3CODE_DEV_SEED=0 vp run dev.
# Arguments: checkout directory, output directory, configured Claude model.
set -euo pipefail
checkout=$1
out=$2
selected_model=$3
script_dir=$(cd -- "$(dirname -- "$0")" && pwd)
run="$out/run-$(date +%Y%m%dT%H%M%S)-$$"
mkdir -p "$run"
cd "$checkout"
node apps/server/src/bin.ts auth session issue --base-dir .t3 --scope settings:write --scope providers:manage --scope orchestration:read --scope orchestration:operate --token-only > "$run/private-token"
patch=$(python3 - "$script_dir/capture-claude.py" <<'PY'
import json,sys
print(json.dumps({'patch':{'enableAgentDeviceAccess':True,'enableDeviceSupport':False,'providerInstances':{'claudeAgent':{'driver':'claudeAgent','config':{'binaryPath':sys.argv[1]}}}}}))
PY
)
node "$script_dir/rpc.mjs" . "$run/private-token" server.updateSettings "$patch" > "$run/private-settings-response.json"
node apps/server/src/bin.ts thread start --base-dir .t3 --provider claudeAgent --model "$selected_model" --title 'Device context inspection' apps/server 'Spawn exactly one native subagent using the Agent tool. Ask it to report whether its supplied context contains a section headed T3 Code devices. Report the same for your own system context. Do not read files or call device tools. Return only parent_device_instructions=yes/no and child_device_instructions=yes/no.' --json > "$run/private-launch.json"
# Open the returned thread in the paired web browser while recording.
# Wait for "Worked for" and the completed parent response before stopping.
# Logs contain credentials: publish only selected device context fields.
