#!/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 # UTF-8 for grep: in the C locale a multibyte class like [ąę…] matches single bytes (an en dash hit "Polish"). export LC_ALL="${LC_ALL:-C.UTF-8}" 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))" } # grep that skips the starter's alternative lines (`//: …` after `file:line:`) — commented-out # variants inside @starter:if markers, not code the site runs. g() { grep -rnE "$@" 2>/dev/null | grep -vE '^[^:]+:[0-9]+:[[:space:]]*//:' || true; } # drop matches that sit inside a // or /* comment (keeps http:// URLs) # (also a whole-line comment right after grep's "file:line:" prefix) nc() { grep -vE "^[^:]+:[0-9]+:[[:space:]]*(//|/?\*)|(^|[^:])//.*$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)" # --- Skill templates must not be compiled as project code --- if [ -d .agents ] && [ -f tsconfig.json ]; then report ERROR "tsconfig.json does not exclude .agents" "skill templates (.ts/.tsx) break tsc / next build — \"exclude\": [\"node_modules\", \".agents\"]" \ "$(tr -d '\n' < tsconfig.json | grep -qE '"exclude"[^]]*\.agents' || echo tsconfig.json)" fi # --- Sitemap: one route, look from the plugin (seo.md) --- SM_TS=$(ls src/app/sitemap.ts 2>/dev/null) SM_ROUTE=$(ls src/app/sitemap.xml/route.ts 2>/dev/null) if [ -n "$SM_TS" ] && [ -n "$SM_ROUTE" ]; then report ERROR "two sitemaps" "seo.md — keep src/app/sitemap.xml/route.ts (sitemapRoute), delete src/app/sitemap.ts" "$(printf '%s\n%s' "$SM_TS" "$SM_ROUTE")" fi report WARNING "project copy of the sitemap stylesheet" "seo.md — sitemapRoute serves the look from the plugin; delete it (and cssUrl)" \ "$(ls public/sitemap.css 2>/dev/null)" # --- 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()/cookies() in blocks/components" "§4.6 forces dynamic rendering — pass locale via enhanceProps" \ "$( [ -n "$UI" ] && g "from 'next/headers'" $UI)" report ERROR "headers()/cookies() in static page tree" "§4.6 SSG/ISR → 'Page changed from static to dynamic' — not-found: LocaleView (pages.md)" \ "$(g "from 'next/headers'" src/app --include=page.tsx --include=layout.tsx --include=not-found.tsx --include=template.tsx | grep -v '/api/\|(payload)')" # --- 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=\{?["`]/|