#!/usr/bin/env bash
# spool onSessionEnd hook for Cursor (managed by `spool mcp install`).
#
# Cursor sends this hook when the session ends. We run the distill
# pipeline (R3 self-tag heuristics -> ledger).
#
# Failure-silent: any non-zero exit from spool is swallowed (D7).
set -e

SPOOL_BIN="@@SPOOL_BIN@@"
SPOOL_CONFIG="@@SPOOL_CONFIG@@"
CWD="${CURSOR_PROJECT_DIR:-$PWD}"

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

"$SPOOL_BIN" hook stop \
  --config "$SPOOL_CONFIG" \
  --cwd "$CWD" \
  >/dev/null 2>&1 || true
exit 0
