#!/usr/bin/env bash
# spool PreCompact hook (managed by `spool mcp install`).
#
# R2 writes a `last-pre-compact.unix` marker. R3 will dump self-tagged
# segments from the active context to the ledger before compaction
# erases them.
set -e

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

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

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