KeiSeiKit-1.0/scripts/precommit-counts-check.sh
Parfii-bot d04e6efe1e refactor(v0.17): README counts auto-generation via markers + regen script
Eliminates README counts drift class (RULE 0.10 recurrence — 3rd
drift in one week: RUST_CRATES 23→24, SKILLS 38→39, PROFILE_FULL
36→37, PROFILE_DEV 4→10, BLOCKS 73→78).

Mechanism: HTML-comment markers wrap every auto-countable value:
  <!-- count:RUST_CRATES -->24<!-- /count:RUST_CRATES -->

16 marker types cover: RUST_CRATES, RUST/SHELL/TOTAL_PRIMITIVES,
SKILLS, HOOKS, BLOCKS, AGENTS, BRIDGES, PROFILE_FULL/MCP/DEV/OPS/
FRONTEND/CORE, LBM_PORTS.

scripts/regen-counts.sh (117 LOC, POSIX sh) — computes every count
from source (MANIFEST.toml, Cargo.toml, find on skills/hooks/blocks/
manifests/bridges) and rewrites markers in place. --check mode
(side-effect-free via mktemp+cmp+diff) exits 1 on drift.

scripts/precommit-counts-check.sh (26 LOC) — invokes regen-counts
--check, blocks commit on drift with fix-it hint.

README gains 'Regenerating counts' subsection documenting both
commands and pre-commit wiring.

No Python/jq/yq hard deps. macOS /bin/sh compat (3.2-era). Idempotent.

Constructor Pattern: largest script 117 LOC (<120), largest awk fn
10 LOC (<30).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 15:24:05 +08:00

26 lines
628 B
Bash
Executable file

#!/bin/sh
# precommit-counts-check.sh — pre-commit gate for README count drift.
# Runs scripts/regen-counts.sh --check; exits non-zero on drift.
# Install: ln -s ../../scripts/precommit-counts-check.sh .git/hooks/pre-commit
# or add to your hook manager of choice.
set -eu
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
REGEN="$ROOT/scripts/regen-counts.sh"
[ -x "$REGEN" ] || {
printf 'precommit-counts-check: %s not executable\n' "$REGEN" >&2
exit 2
}
if "$REGEN" --check; then
exit 0
fi
cat >&2 <<'EOF'
Counts drift detected in README.md.
Run: ./scripts/regen-counts.sh && git add README.md
EOF
exit 1