fix: skip AI review for directories without AGENTS.md (opt-in model)

Components must have their own AGENTS.md to be included in AI code review.
This allows teams like API to opt-in when ready without blocking their workflow.
This commit is contained in:
Alan Buscaglia
2025-12-16 13:49:13 +01:00
parent eb1fc2b269
commit e2344b4fc6
+48
View File
@@ -1,12 +1,16 @@
#!/bin/bash
# Gentleman Guardian Angel (gga) - AI Code Review Hook
# This script is called by pre-commit after all formatters/linters have run
#
# Only reviews files in directories that have an AGENTS.md file.
# This allows teams to opt-in to AI code review by adding AGENTS.md to their component.
set -e
# Colors
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
GREEN='\033[0;32m'
NC='\033[0m'
# Check if AI code review is enabled
@@ -15,6 +19,50 @@ if [ "${CODE_REVIEW_ENABLED:-false}" != "true" ]; then
exit 0
fi
# Check if AGENTS-CODE-REVIEW.md exists
if [ ! -f "AGENTS-CODE-REVIEW.md" ]; then
echo -e "${YELLOW}⏭️ AI code review skipped (AGENTS-CODE-REVIEW.md not found)${NC}"
exit 0
fi
# Get staged files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(ts|tsx|js|jsx|py)$' || true)
if [ -z "$STAGED_FILES" ]; then
echo -e "${YELLOW}⏭️ No matching files staged for AI review${NC}"
exit 0
fi
# Filter out files from directories without AGENTS.md (opt-in model)
FILES_TO_REVIEW=""
SKIPPED_DIRS=""
for file in $STAGED_FILES; do
# Get the top-level directory of the file
TOP_DIR=$(echo "$file" | cut -d'/' -f1)
# Check if this directory has an AGENTS.md file
if [ -f "${TOP_DIR}/AGENTS.md" ]; then
FILES_TO_REVIEW="$FILES_TO_REVIEW $file"
else
# Track skipped directories (only unique)
if [[ ! "$SKIPPED_DIRS" =~ $TOP_DIR ]]; then
SKIPPED_DIRS="$SKIPPED_DIRS $TOP_DIR"
fi
fi
done
# Report skipped directories
if [ -n "$SKIPPED_DIRS" ]; then
echo -e "${YELLOW}️ Skipping directories without AGENTS.md:${SKIPPED_DIRS}${NC}"
fi
# Check if there are files to review after filtering
if [ -z "$(echo "$FILES_TO_REVIEW" | tr -d ' ')" ]; then
echo -e "${GREEN}✅ No files to review (all staged files are in directories without AGENTS.md)${NC}"
exit 0
fi
# Install gga if not present
if ! command -v gga &> /dev/null; then
echo -e "${BLUE}📦 Installing Gentleman Guardian Angel (gga)...${NC}"