#!/bin/bash
# PostToolUse hook: mcp__routinecode__build_check
# 빌드 실패 시 get_similar_errors 호출을 강제 리마인드

# stdin에서 hook input 읽기
INPUT=$(cat)
TOOL_OUTPUT=$(echo "$INPUT" | python3 -c "
import sys, json
try:
    data = json.load(sys.stdin)
    print(data.get('tool_output', ''))
except:
    print('')
" 2>/dev/null)

if echo "$TOOL_OUTPUT" | grep -q '"success":false\|"success": false'; then
  cat <<'HOOK_OUTPUT'
{"continue":true,"systemMessage":"[HOOK] Build FAILED. REQUIRED: call mcp__intelligence__get_similar_errors with the error signature before attempting a fix. Then call mcp__routinecode__record_attempt to track this failure."}
HOOK_OUTPUT
else
  echo '{"continue":true}'
fi
