#!/usr/bin/env bash
# spool PostToolUse hook (managed by `spool mcp install`).
#
# Appends a signal envelope to <cwd>/.spool/distill-pending.queue.
# Tier-1 / Tier-2 distillation consumes the queue at Stop (R3+).
set -e

SPOOL_BIN="@@SPOOL_BIN@@"
SPOOL_CONFIG="@@SPOOL_CONFIG@@"
CWD="${CLAUDE_PROJECT_DIR:-$PWD}"
TOOL_NAME="${CLAUDE_TOOL_NAME:-unknown}"

if [ ! -x "$SPOOL_BIN" ]; then
  exit 0
fi

"$SPOOL_BIN" hook post-tool-use \
  --config "$SPOOL_CONFIG" \
  --cwd "$CWD" \
  --tool-name "$TOOL_NAME" \
  >/dev/null 2>&1 || true
exit 0
