#!/usr/bin/env bash
# Request graceful stop of a running wake. Defaults to track "main".
# Override with --track <name>.
#
# The running wake checks for this file between SDK messages (not mid-tool-call),
# so a tool call in flight finishes before the abort takes effect. The lock
# auto-releases on exit.
#
# Usage:
#   bin/reflect-stop                   # stop main track
#   bin/reflect-stop --track content   # stop a named track
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$PROJECT_ROOT"

track="main"
[[ "${1:-}" == "--track" ]] && track="${2:-main}"

stop_file="agent/runtime/tracks/${track}/stop.requested"
mkdir -p "$(dirname "$stop_file")"
touch "$stop_file"
echo "stop requested for track: $track"
echo "  file: $stop_file"
echo "  wake will abort at next message boundary; lock auto-releases on exit."
