#!/bin/bash
# Pre-Command Hook for StringRay
# 
# Checks context window usage before each command.
# If context is at 95%+ (configurable), auto-generates a reflection.
#
# Usage:
#   ./scripts/hooks/pre-command        # Normal call
#   ./scripts/hooks/pre-command --dry-run  # Check without generating
#   ./scripts/hooks/pre-command --ci     # CI mode (less verbose)

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"

export HOOK_PROJECT_ROOT="$PROJECT_ROOT"
export HOOK_REFLECTIONS_DIR="${REFLECTIONS_DIR:-docs/reflections}"
export HOOK_DRY_RUN="${HOOK_DRY_RUN:-0}"

if [[ "$1" == "--dry-run" ]]; then
    export HOOK_DRY_RUN=1
elif [[ "$1" == "--ci" ]]; then
    export CI=true
fi

cd "$PROJECT_ROOT"
exec node "$SCRIPT_DIR/pre-command.mjs" "$@"