Skip to content

chore: add dependency-free pre-commit hooks (SPDX + cookbook drift)#510

Merged
w1ne merged 2 commits into
developfrom
chore/precommit-hooks
Jun 18, 2026
Merged

chore: add dependency-free pre-commit hooks (SPDX + cookbook drift)#510
w1ne merged 2 commits into
developfrom
chore/precommit-hooks

Conversation

@w1ne

@w1ne w1ne commented Jun 18, 2026

Copy link
Copy Markdown
Owner

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:

  • (a) Missing SPDX headers on new/edited TS source under src/.
  • (b) Stale cookbook artifacts (src/agent/skills/kernelcad-authoring/SKILL.md) when their cookbook source (src/agent/cookbook/**) is part of the commit.

How it works

  • No dependencies / no husky. Wired via git's native core.hooksPath, pointed at the committed .githooks/ dir by the prepare npm script (git config core.hooksPath .githooks || true; npm run build:studio). npm ci / npm install sets it up automatically; the || true keeps CI/non-git checkouts from failing, and it composes with the existing build:studio prepare step.
  • Fast & staged-scoped. It only inspects git diff --cached --name-only --diff-filter=ACM:
    • SPDX: runs node scripts/addSpdxHeaders.mjs only when staged src/**/*.ts(x) exist, then re-stages only the staged files it actually touched (never sweeps unrelated working-tree changes). Idempotent — quiet when nothing changes.
    • Cookbook: runs npm run cookbook:build only when a src/agent/cookbook/** file is staged, then re-stages the regenerated SKILL.md. It never runs on commits that don't touch cookbook source.
  • Skippable. git commit --no-verify bypasses it via git's standard mechanism.
  • Robust on partial checkouts. If node or 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.
  • Functional test: created a header-less 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.hooksPath resolves to .githooks after the prepare wiring runs.

@w1ne w1ne enabled auto-merge June 18, 2026 15:07
@w1ne w1ne merged commit 2e80be1 into develop Jun 18, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant