#!/bin/bash
# PreToolUse hook: Edit
# 에스컬레이션 상태일 때 Edit 도구 차단

STATE_FILE="/tmp/routinecode-escalation.json"

if [ -f "$STATE_FILE" ]; then
  ESCALATED=$(python3 -c "
import json
try:
    with open('$STATE_FILE') as f:
        print(json.load(f).get('escalated', False))
except:
    print('False')
" 2>/dev/null)

  if [ "$ESCALATED" = "True" ]; then
    cat <<'HOOK_OUTPUT'
{"decision":"block","reason":"[HOOK] Escalation active: 3+ failed attempts on the same issue. You MUST consult the reviewer agent before making more edits. Call mcp__routinecode__check_escalation to see attempt history, then delegate to reviewer."}
HOOK_OUTPUT
    exit 0
  fi
fi

echo '{"continue":true}'
