Repository navigation
feat(hooks): report where the git-hook floor is and whether it can fail - #498
Merged
Merged
Conversation
README calls git hooks the agent-agnostic enforcement floor, and nothing reported on them: kit check had a row for memory hooks and one for the PreToolUse gates, none for these. Two measured states were invisible. #496 — the floor can live OUTSIDE the repo. resolveHooksDir() honors core.hooksPath, which is right (installing into .git/hooks while git reads elsewhere is a silent no-op), but only the WRITER used it: check-hooks.ts and `kit hooks add`'s own already-installed pre-check hardcoded <gitDir>/hooks, so kit installed to one directory and reported on another. Writer and readers now share the resolver. Measured consequence of the silence: a checkout copied from another inherits its absolute core.hooksPath, so its hooks live in the other clone's tree — deleting that unrelated directory let a staged fake credential commit cleanly, exit 0, with every report green. #497 — `kit hooks add context-check` installed a gate that could not fail. With no [context] block there is nothing to compare the live CLI state against, so the pre-push hook passed every push under a ✓ installed. It now refuses (with --force for someone about to declare the block), the installed hook runs `kit context check --require-declaration` so a block that disappears later fails the push, and each built-in prints how to exercise ITSELF instead of secret-scan's stage-a-credential recipe. New `git hook floor` row in the security gate: fail for a gone hooksPath directory (every hook is off) or an unarmed gate, warn when the floor resolves outside the repo, pass naming what is wired, skip when the repo has no kit-managed hooks — kit does not claim a floor nobody asked for. Also corrects fix.ts's claim that git-hook installs "land inside the repo, which the repo-rooted [scope].fs covers": true only while core.hooksPath is unset or repo-relative. Closes #496 Closes #497 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
✅ Docker image built successfully
|
…ment flags CI's Lint step (inside build-and-test) tolerates warnings but not errors, and these two were errors. `npm run lint` locally reported them too — I had checked before the file existed.
|
✅ Docker image built successfully
|
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.
Closes #496. Closes #497.
The root cause was narrower than #496 said
resolveHooksDir()honorscore.hooksPath— correct, andsrc/hooks.ts:8-18explains why: installing into.git/hookswhile git reads elsewhere is a silent no-op. But only the writer used it. Two readers hardcoded<gitDir>/hooks:check-hooks.ts:checkHooks— sokit hooksreported declared hooks as missing while they were installed and firing;commands/hooks.ts's own already-installed pre-check — so everykit hooks addre-reported a freshinstalledfor a hook that was already there.Writer and reader disagreeing is the defect. Both now call the same resolver, and a test pins that an installed hook in an external directory is not reported missing.
What the gate now says
New
git hook floorrow (kit check), ranked by what an operator must do:core.hooksPathpoints at a directory that does not existcontext-checkwith no[context])rm -rfremoves themkit hooks addprints the resolved directory when it is external, instead of a bare✓ installed.Detection is deliberately narrow: a hook counts as kit's floor only if it carries the
Generated by kitmarker and the command it was installed for. A hand-writtenpre-commitis not claimed, and a repo-relativecore.hooksPath(.githooks, the husky case) is correctly not external — both asserted.The gate that could not fail
kit hooks add context-checkwith no[context]block installed a pre-push hook that passed every push under a✓ installed. Now:The installed hook runs
kit context check --require-declaration, so a[context]block that disappears later fails the push instead of passing it. The bare command still exits 0 with the ready-to-paste suggestion — a repo may legitimately have no lock, and a read-only report should not invent one. Only the caller that asked for enforcement gets the strict answer.Per-hook test hints, too:
post-pull-auditandcontext-checkboth used to print secret-scan's "stage a fake credential and commit", which exercises nothing for a post-merge or pre-push gate.Corrected claims
fix.tssaid git-hook installs "land inside the repo, which the repo-rooted[scope].fscovers". True only whilecore.hooksPathis unset or repo-relative. The comment now says so and points at the new row; expressing the resolved directory inscopeNeedsneeds a dynamic declaration this static one cannot carry, so that stays out of scope rather than being faked.Tests
src/hook-floor.test.ts— 17, driving temp repos with realcore.hooksPathvalues and the compiled CLI:.githooks(repo-relative) is not external; an external dir is; a deletedhooksPathdirectory means every hook is offcontext-checkunarmed vs armedskipwhen nothing is installed--force, per-hook hints, the external-path warning naming the directory, thegit hook floorrow inkit check --json, and reader/writer agreement on an external floorVerification
npm test: 4342 tests, 0 fail, 0 skipped (macOS, non-root)kit self-audit: 16 rules, 0 fail, 0 warnprettier --check "src/**/*.ts"clean; flag surface regenerated (--force,--require-declaration) and its drift test green🤖 Generated with Claude Code