#!/usr/bin/env bash
# Run for each checkout against its own fresh dev server, started with T3CODE_DEV_SEED=0.
set -euo pipefail
: "${CHECKOUT:?Set CHECKOUT to the isolated checkout}"
: "${ARTIFACTS:?Set ARTIFACTS to a private output directory}"
: "${EVIDENCE_MODEL:?Set EVIDENCE_MODEL to the same available OpenCode model on both sides}"
run_dir="$ARTIFACTS/$(date -u +%Y%m%dT%H%M%SZ)"
mkdir -p "$run_dir/project"
git init "$run_dir/project"
python3 - "$CHECKOUT/.t3/userdata/settings.json" <<'PY'
import json,sys
from pathlib import Path
p=Path(sys.argv[1]); s=json.loads(p.read_text())
s.setdefault('providerInstances',{})['opencode']={'driver':'opencode','enabled':True,'config':{'enabled':True}}
p.write_text(json.dumps(s,indent=2))
PY
cd "$CHECKOUT"
node apps/server/src/bin.ts project add --base-dir .t3 "$run_dir/project" --title 'Archive demonstration'
node apps/server/src/bin.ts thread start --base-dir .t3 --provider opencode --model "$EVIDENCE_MODEL" --title 'Parent to archive' --wait --json "$run_dir/project" 'Use your native task tool to launch exactly one general subagent. Set its description to Reply OK and prompt to Reply with exactly OK. Wait for it to finish, then reply Done. Do not use T3 delegation tools, only the native task tool.' > "$run_dir/turn-private.json"
# The output above is private scratch: never upload provider logs or runtime metadata.
