#!/bin/bash # # check_headers.sh — Metrika # # Author: Simon-Pierre Boucher # Contact: contact@spboucher.ai # Copyright © 2026 Simon-Pierre Boucher. All rights reserved. # # Rejects any source file (.swift, .metal, .sh, .py, .zyq) missing the # mandatory Metrika file header (CLAUDE.md §0). With --staged, checks only # files staged in git (pre-commit mode); otherwise checks the whole tree. # set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" MODE="${1:-all}" if [[ "$MODE" == "--staged" ]]; then FILES=$(git -C "$ROOT" diff --cached --name-only --diff-filter=ACMR \ | grep -E '\.(swift|metal|sh|py|zyq)$' || true) else FILES=$(cd "$ROOT" && find . \ -not -path './.git/*' -not -path '*/.build/*' -not -path '*/build/*' \ -not -path '*/DerivedData/*' -not -path '*/.swiftpm/*' \ \( -name '*.swift' -o -name '*.metal' -o -name '*.sh' -o -name '*.py' -o -name '*.zyq' \) \ | sed 's|^\./||') fi FAIL=0 for f in $FILES; do [[ -f "$ROOT/$f" ]] || continue HEAD_BLOCK=$(head -n 12 "$ROOT/$f") if ! grep -q 'Author: Simon-Pierre Boucher' <<<"$HEAD_BLOCK" \ || ! grep -q 'Contact: contact@spboucher.ai' <<<"$HEAD_BLOCK"; then echo "❌ missing Metrika header: $f" FAIL=1 fi done if [[ $FAIL -ne 0 ]]; then echo "" echo "Every source file must begin with the Metrika header (see CLAUDE.md §0)." exit 1 fi echo "✅ header check passed"