chore: add dependency-free pre-commit hooks (SPDX + cookbook drift)#510
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a lightweight, dependency-free git pre-commit hook that catches — locally, before push — the two "forgot to regenerate the derived artifact" failures that have repeatedly wasted CI on PRs:
src/.src/agent/skills/kernelcad-authoring/SKILL.md) when their cookbook source (src/agent/cookbook/**) is part of the commit.How it works
core.hooksPath, pointed at the committed.githooks/dir by thepreparenpm script (git config core.hooksPath .githooks || true; npm run build:studio).npm ci/npm installsets it up automatically; the|| truekeeps CI/non-git checkouts from failing, and it composes with the existingbuild:studioprepare step.git diff --cached --name-only --diff-filter=ACM:node scripts/addSpdxHeaders.mjsonly when stagedsrc/**/*.ts(x)exist, then re-stages only the staged files it actually touched (never sweeps unrelated working-tree changes). Idempotent — quiet when nothing changes.npm run cookbook:buildonly when asrc/agent/cookbook/**file is staged, then re-stages the regeneratedSKILL.md. It never runs on commits that don't touch cookbook source.git commit --no-verifybypasses it via git's standard mechanism.nodeor the scripts are missing, it warns and exits 0 rather than blocking commits.Behavior choice (auto-fix vs fail-fast)
The hook auto-fixes and re-stages rather than failing, because both fixers are deterministic regenerators (insert canonical header / regenerate a
<!-- COOKBOOK -->block) — fixing in place is faster and less surprising than aborting the commit and asking the dev to re-run a command by hand. Notices are printed to stderr so the dev sees what was added.Verification
bash -n .githooks/pre-commit— syntax OK.src/studio/__hooktest__.ts, staged it, ran the hook directly → it inserted the two-line SPDX header and re-staged the file (working tree matched index afterward). Temp file removed, not committed.core.hooksPathresolves to.githooksafter the prepare wiring runs.