#!/usr/bin/env bash
set -euo pipefail
# Run from either installed checkout with its isolated dev server running.
# MODEL is a configured OpenCode model; its private identifier is not published.
: "${MODEL:?Set an available OpenCode model}"
: "${PROJECT:?Set a synthetic Git project directory}"
: "${OUTPUT:?Set a new output directory}"
mkdir -p "$OUTPUT"
cli=(node apps/server/src/bin.ts)
"${cli[@]}" project add "$PROJECT" --title 'Worktree tools' --base-dir .t3
"${cli[@]}" thread start "$PROJECT" 'This is a tool availability check. Search your tool catalog for delegate_task, orchestrator_capabilities and t3_* tools. Call orchestrator_capabilities if available, then report only which of those tool groups are available. Do not report runtime model identifiers or filesystem paths. Do not move the session yet.' --title 'Native worktree tool check' --provider opencode --model "$MODEL" --base-dir .t3 --wait --json > "$OUTPUT/initial.json"
thread_id=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["threadId"])' "$OUTPUT/initial.json")
"${cli[@]}" thread send "$thread_id" 'Use the native opencode.worktree_create tool to create a worktree, then call opencode.session_move to move THIS current session into the returned worktree. Do not use shell git commands or T3 workspace changes. Do not report filesystem paths or runtime model identifiers in your reply. Report only whether the native move succeeded.' --base-dir .t3 --wait --json > "$OUTPUT/move.json"
# Open this thread in the web client and start recording before the next command.
"${cli[@]}" thread send "$thread_id" 'Re-check the LIVE tool catalog now, do not rely on earlier messages. Search for delegate_task, orchestrator_capabilities and t3_* tools. If present call orchestrator_capabilities and use delegate_task for a minimal task with the configured Grok provider: reply with exactly delegation-ok. Wait for its completion. If any tools are missing report that. Do not report model identifiers, machine names, or filesystem paths.' --base-dir .t3 --wait --json > "$OUTPUT/after-move.json"
# The published recordings cover this final turn. No assertions or replay provider.
