#!/usr/bin/env bash
# planu-review-panel-trigger.sh — PreToolUse hook: suggest panel review on large PRs
# SPEC-593: Optional suggestion only — safe no-op if conditions are not met.
#
# Wired as a PreToolUse hook for the Bash tool.
# When Claude Code is about to run a git diff or review command and the diff is
# large (>500 LOC), this hook prints a suggestion to use multi_teammate_review.
# It NEVER blocks execution — exit 0 always.

set -uo pipefail

# Only run on git diff or gh pr diff calls (heuristic from tool_input)
TOOL_INPUT="${CLAUDE_TOOL_INPUT:-}"
if ! echo "$TOOL_INPUT" | grep -qE '(git diff|gh pr diff|review_pr)'; then
  exit 0
fi

# Count LOC in the current diff (best-effort, ignore errors)
LOC=0
if command -v git &>/dev/null; then
  LOC=$(git diff HEAD 2>/dev/null | grep -cE '^[+-]' 2>/dev/null || echo 0)
fi

THRESHOLD=500
if [[ "$LOC" -gt "$THRESHOLD" ]]; then
  echo ""
  echo "💡 Planu tip: This diff is ${LOC} LOC (threshold: ${THRESHOLD})."
  echo "   Consider running the 5-specialist panel review for thorough analysis:"
  echo "   → multi_teammate_review({ projectPath: \"$(pwd)\", diff: \"<paste diff here>\" })"
  echo "   Or use the /planu-multi-teammate-review skill."
  echo ""
fi

exit 0
