#!/usr/bin/env bash # ipal-audit — deterministic checks of an ipal-kit project against AGENT.md. # Run from the project root: # bash .agents/skills/ipal-audit/scripts/audit.sh # all checks + tsc + build # bash .agents/skills/ipal-audit/scripts/audit.sh --quick # static checks only # bash .agents/skills/ipal-audit/scripts/audit.sh --help # Exit code: 0 = no errors (warnings allowed), 1 = at least one error. set -u QUICK=0 for arg in "$@"; do case "$arg" in --quick) QUICK=1 ;; --help|-h) sed -n '2,7p' "$0" | sed 's/^# \{0,1\}//' exit 0 ;; esac done if [ ! -d src ]; then echo "ipal-audit: run from the project root (no ./src found)." >&2 exit 2 fi ERRORS=0 WARNINGS=0 # report LEVEL "title" "rule" <<< "$matches" report() { local level="$1" title="$2" rule="$3" matches="$4" [ -z "$matches" ] && return 0 local count count=$(printf '%s\n' "$matches" | grep -c .) if [ "$level" = ERROR ]; then ERRORS=$((ERRORS + count)); else WARNINGS=$((WARNINGS + count)); fi printf '\n[%s] %s (%s) — %s\n' "$level" "$title" "$count" "$rule" printf '%s\n' "$matches" | head -20 | sed 's/^/ /' [ "$count" -gt 20 ] && printf ' … and %s more\n' "$((count - 20))" } g() { grep -rnE "$@" 2>/dev/null || true; } # drop matches that sit inside a // or /* comment (keeps http:// URLs) nc() { grep -vE "(^|[^:])//.*$1|/\*.*$1" || true; } dirs() { for d in "$@"; do [ -d "$d" ] && printf '%s ' "$d"; done; } BLOCKS=$(dirs src/blocks) UI=$(dirs src/blocks src/components) echo "ipal-audit — $(pwd)" # --- Architecture (AGENT.md §4) --- report ERROR "middleware.ts exists" "§4.1 Next 16 uses proxy.ts only" \ "$(ls src/middleware.ts middleware.ts 2>/dev/null)" report ERROR "
in app" "§4.2 no explicit — metadata ends up in " \ "$(g ']' src/app --include=*.tsx | nc '/dev/null) for p in $PAGES; do grep -q 'revalidate' "$p" || report ERROR "no ISR" "§4.3 export const revalidate" "$p" grep -q 'generateStaticParams' "$p" || report ERROR "no generateStaticParams" "§4.4 without it the route is dynamic and metadata lands in " "$p" report WARNING "searchParams in catch-all page" "§4.6 deoptimizes SSG/ISR — only for paginated archives" \ "$(grep -n 'searchParams' "$p" | nc 'searchParams' | sed "s|^|$p:|")" done for r in src/app/sitemap.ts src/app/manifest.ts src/app/llms.txt/route.ts src/app/sitemap.xml/route.ts src/app/api/health/route.ts; do [ -f "$r" ] && ! grep -q "dynamic = 'force-dynamic'" "$r" && \ report ERROR "DB route without force-dynamic" "§4.7 build without DB will crash" "$r" done report ERROR "headers() in blocks/components" "§4.6 forces dynamic rendering — pass locale via enhanceProps" \ "$( [ -n "$UI" ] && g "from 'next/headers'" $UI)" # --- Hardcoding & types (§2, §8) --- report ERROR "hardcoded locale map / any / ts-ignore" "§2, §8" \ "$(g 'localizedRoutes|as any\b|@ts-ignore|: any\b' src --include=*.ts --include=*.tsx | grep -v '/payload-types.ts:')" report ERROR "hardcoded locale list" "§2 languages come from i18n.config.ts" \ "$(g "\[ *'(pl|en|de|fr|es|it)' *, *'(pl|en|de|fr|es|it)'" src --include=*.ts --include=*.tsx | grep -v 'i18n.config.ts')" # --- Sections (§6) --- if [ -n "$BLOCKS" ]; then report ERROR "forbidden field names" "§6.5 use links/link/media (linksField, linkField, upload)" \ "$(g "name: *'[a-zA-Z]*([cC]ta|[bB]utton|Url|Href|[pP]df|[iI]mage)[a-zA-Z]*'" $BLOCKS --include=config.ts)" report ERROR "hardcoded href/src/file paths in blocks" "§2, §6 use CMSLink / Media" \ "$(g 'href=\{?["`]/|