fix(hooks): delegate the generated pre-commit hook to the runtime - #684
Merged
Merged
Conversation
The generated `.githooks/pre-commit` was a 53-byte whitespace guard while
`preCommit()` — a language-aware format/lint gate for JS/TS, Rust, and
Python — already existed in `runtime-core.mjs` behind an argv dispatch that
nothing invoked. Every consumer committed ungated and found those errors on
CI instead.
Three gaps:
- The template never called the gate. It now launches the CLI, which
dispatches to `preCommit()`, with the whitespace check kept as an offline
fallback so an unavailable npx cannot block a commit.
- `preCommit()` is now exported so the CLI can reach it. runtime-core's own
argv dispatch is guarded by an entry-point check, because importing it
would otherwise run the gate a second time on import.
- `preCommit()` did not run `ci('type_check')`, so type errors still reached
CI. Added to the JS/TS branch, where the dependency graph is already warm.
`doctor` could not detect this: it asserted only that `core.hooksPath` was
set, so a correctly enabled but inert hook reported "Repository doctor
passed". It now checks the hook delegates, and warns when it is missing.
Also moves three agent directories from the consumer gitignores into the
shared template — `.zcode/`, `.kiro/`, and `.goose/` — so they are ignored
once rather than re-added per repository.
Verified: 557 tests pass; lint, format, and type-check clean. Against a
consumer with a staged unused import the gate blocks the commit and prints
the oxlint finding. Doctor warns on the old template and the missing file,
and stays silent on the new one.
0xPlayerOne
marked this pull request as draft
October 1, 2026 14:52
The file is copied into every consumer repository, so a multi-paragraph explanation of why the launcher exists becomes clutter in each one. Keep the provenance line and the logic.
0xPlayerOne
marked this pull request as ready for review
October 1, 2026 15:30
The generated hook ran `npx --yes code-foundry@latest`, a mutable dist-tag, on every commit with --yes suppressing the install prompt. Any publish under that tag would execute on every developer machine at commit time with the working tree and local credentials in reach. sync now substitutes the package version into the hook, so the gate a repository receives is the gate that generated it. Added three tests: the version is pinned, no mutable dist-tag survives generation, and the whitespace fallback stays a fallback rather than a short-circuit.
Building a RegExp from the package version drew js/incomplete-sanitization. The substring check states the same thing and needs no escaping.
This was referenced Oct 1, 2026
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 #683.
Problem
The generated
.githooks/pre-commitwas a 53-byte whitespace guard:Meanwhile
preCommit()— a language-aware gate for JS/TS, Rust, and Python —already existed in
src/runtime-core.mjs, reachable only through an argvdispatch that nothing invoked:
The template is the intended one, not drift: it is byte-identical to
package/.githooks/pre-commit, andsync --dry-runreports the consumer'scopy as already correct.
Every consumer committed ungated. Formatting, lint, and type errors were
discovered on CI instead.
Changes
The template delegates. It launches the CLI, which dispatches to
preCommit(). The whitespace check stays as an offline fallback so anunavailable
npxcannot block a commit.preCommit()is exported so the CLI can reach it. runtime-core's argvdispatch is now guarded by an entry-point check — without it, importing the
module for
preCommitwould run the gate a second time at import.preCommit()runsci('type_check'). It did format and lint but nevertypecheck, though
ci('type_check')already existed. Type errors were themost common reason a green-looking commit failed CI later.
doctorcan see this now. It asserted only thatcore.hooksPathwas set,so a correctly enabled but inert hook reported
Repository doctor passed. Itnow warns when the hook is missing or does not delegate.
Agent directories moved to the shared template.
.zcode/,.kiro/, and.goose/were being added per repository; they now ship insrc/templates/gitignoreso they are ignored once.Verification
commit and prints the oxlint finding.
doctorwarns on the old template and on a missing hook, and stays silenton the new one.
Note on diagnosis
Worth recording, since it cost time here:
code-foundry@1.33.0contains nomention of
hooksPath,pre-commit, orgithooksanywhere. Auditing aconsumer against an older CLI suggests hooks are unmanaged when they are in
fact generated. Pin the CLI to
runtime_refbefore auditing.Follow-up
syncsources templates from the installed package root(
source: packageRoot), so consumers pick this up on the next release.