#!/usr/bin/env bash
# run-stop-guard.sh  -  Stop hook for the multi-agent pipeline.
#
# A session driving a pipeline run that tries to end its turn mid-run, with no
# halt recorded, is told to continue or record the halt. The decision is in
# run-stop-guard.mjs; this wrapper exists because every hook the pipeline
# registers is a `bash "$HOME/.<host>/scripts/<name>"` command.
#
# Contract (Claude Code Stop hook):
#   - Reads the hook JSON on stdin.
#   - Prints {"decision":"block","reason":...} to keep the session going, or
#     {"systemMessage":...} when it gives up and records the halt itself, or
#     nothing.
#   - Exits 0 on every path. A missing node or any internal error means no
#     output: this is a completion aid, not a security gate.

set -u

HERE="$(cd "$(dirname "$0")" 2>/dev/null && pwd || true)"
CORE="$HERE/run-stop-guard.mjs"
[ -f "$CORE" ] || exit 0
command -v node >/dev/null 2>&1 || exit 0

node "$CORE" 2>/dev/null || true
exit 0
