#!/usr/bin/env bash
# spool SessionStart hook (managed by `spool mcp install`).
#
# Outputs a wakeup packet block to stdout when Claude Code starts a
# new session in this project. The marker comments make the spool
# region easy to identify (or strip) by other tools.
#
# Failure-silent: any non-zero exit from spool is swallowed so Claude
# Code never sees a hook failure (D7).

set -e

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

if [ ! -x "$SPOOL_BIN" ]; then
  echo "<!-- spool hook: binary missing at $SPOOL_BIN -->"
  exit 0
fi

"$SPOOL_BIN" hook session-start --config "$SPOOL_CONFIG" --cwd "$CWD" 2>/dev/null || true
exit 0
