#!/bin/bash
# GLM Keyword Detector Hook
# Detects @glm, -glm, --glm in user prompts and injects GLM execution instructions

input=$(cat)
prompt=$(echo "$input" | jq -r '.prompt')

# Check for GLM keywords
if echo "$prompt" | grep -iE '(@glm|^-glm|[[:space:]]-glm|--glm)' > /dev/null; then
    cat <<'EOF'
{
  "hookSpecificOutput": {
    "hookEventName": "UserPromptSubmit",
    "additionalContext": "GLM MODE ACTIVATED:\n\n1. ALWAYS use `glm -q \"...\" -o FILEPATH` to save directly to file\n2. Determine appropriate filepath from context or ask user\n3. Profiles: -p frontend-design | api-integration | database-ops | web-crawler\n4. Complexity check: >200 lines or recursive → warn user, suggest Claude\n5. After GLM execution, verify the generated file\n\nExample: glm -q \"Create a REST API client for weather\" -o src/api/weather.ts -p api-integration"
  }
}
EOF
else
    # No GLM keyword - allow normal processing
    echo ""
fi

exit 0
