Repository navigation
Conversation
Extracts the commit message from only the top-level segment matching `git commit`, not the whole compound command, so an earlier quoted string or an unrelated later heredoc can no longer be mistaken for the commit message and block a valid conventional commit. Closes #981 Entire-Checkpoint: ba459169448e
Entire-Checkpoint: c8c06bc2dd66
6 tasks
…it guard Scoping commit-message extraction to the git-commit segment (#981) created the inverse defect: when the chosen segment held no `-m`, MSG came back empty and the conventional-commit guard skipped validation entirely, so a non-conventional message that the pre-#981 code blocked now sailed through. Two shapes hit it, both regressions against main: git commit \ -m "updated stuff" # `\`+newline split the segment at the # backslash, stranding -m outside it echo "run git commit later"; git commit -m "updated stuff" # the quoted mention won segment selection, # and that segment supplies no -m raw_commit_segment now honours backslash line-continuation (both at the unquoted level and inside double quotes, where it also stops `\"` being read as the closing quote), and selects segments on a quote-blanked CODE form rather than the raw text — mirroring what emit_segments/seg_match already do, so this scan agrees with the guard that invoked it. Verified by running both hook copies against 22 crafted commands: all six previously-passing #981 cases still allow, both fail-opens now block with an accurate `Got:` line, and no case regresses against main. Refs #981 Entire-Checkpoint: fb819d0e2f47
Entire-Checkpoint: 0bcaeab9d782
…dies not Selecting segments on a fully blanked code form (d17c745) made a `git commit` inside `( ... )` or `$( ... )` invisible: no segment qualified, raw_commit_segment returned empty, and extraction fell back to the whole command — reinstating the original #981 false positive for echo "mirrors byte-identical"; (cd sub && git commit -m "fix(#943): real") which had worked at 632e5ac. Subshell-wrapping a commit to scope a `cd` is a common idiom, and the issue's own repro opens with one. Subshell CODE now counts toward selection. A heredoc BODY inside the subshell still does not: once a `<<` introducer is seen at depth > 0 the rest of that subshell is blanked. Without the guard, a body whose first line reads `fix: this is heredoc data` wins selection, gets validated as though it were the message, and the real `git commit -m "updated stuff"` two segments later is never examined — verified as a genuine fail-open before the guard was added. Verified across a 32-command differential matrix run through the real hook entry point on four builds (main, 632e5ac, 6aa876a, this): 0 mismatches, and this is the only build correct on every case. Adds 4 regression tests. Refs #981 Entire-Checkpoint: 9af4958e4b1b
Entire-Checkpoint: 6970a32c125d
…skip heredoc bodies inside subshells (#981)
…e only, and keeps -F- heredoc validation (#981)
… cannot skip validation (#981)
…oc-delimiter scan (#981)
…ia one validator (#981)
… and the verbatim cd-prefixed repro (#981)
…mand assignment (#981)
…e commit, last assignment wins (#981)
…eading commit segment scans nothing (#981)
…opy; no-match is zero-width (#981)
…t segments get distinct windows (#981)
…-commit-message-validator-extracts-from-t # Conflicts: # CHANGELOG.md
admarble
deleted the
feature/981-fix-hooks-commit-message-validator-extracts-from-t
branch
September 8, 2026 01:34
This was referenced Sep 8, 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.
Summary
Pre-PR AC Verification
__tests__/pre-tool-hook.integration.test.ts:864"981 AC-1"__tests__/pre-tool-hook.integration.test.ts:879"981 AC-2"Got:text__tests__/pre-tool-hook.integration.test.ts:897"981 AC-3"__tests__/pre-tool-hook.integration.test.ts:912,929"981 AC-4"md5 -q templates/hooks/pre-tool.sh .claude/hooks/pre-tool.sh hooks/pre-tool.sh | uniq | wc -l→1npx vitest run __tests__/pre-tool-hook.integration.test.ts→ 252/252 passedTest plan
npx vitest run __tests__/pre-tool-hook.integration.test.ts— 252/252 passednpm run build— passesnpm run lint— passesmd5check across the three hook copies — identicalbash -nsyntax check on all three hook copiesCloses #981
A+ pass (runner, 2026-09-07, commit 0fc9f52)
Addresses the QA round-3 notes (two latent
hdseeninconsistencies, both masked by the-m-anchoring gap the issue's own Suggested-fix named) — and, found while baselining them, a fail-open: a non-conventional commit after a heredoc inside the same subshell was never validated (echo "x"; (cat <<'EOF' … EOF\ngit commit -m "updated stuff")exited 0 on97f6cbcaand onmain).raw_commit_segment: inside a subshell,<<<is no longer a heredoc introducer (herestring exclusion, symmetric with the depth-0 branches); a real heredoc records its delimiter and the body is consumed to its terminator line, so a commit later in the same( … )counts for segment selection again instead of blanking the rest of the subshell.commit_message_from: the message is read from the commit's own-margument (anchored on thegit committoken, then its-m; handles-m "…",-m '…'with escapes, and the-m "$(cat <<'EOF' … EOF)"idiom), replacing the three grep/sed/awk steps that took the segment's first<<.*EOFheredoc or first double-quoted string. That is what made the twohdseenfixes observable and closes--author="A B" -m …too.<<-form, herestring,--authoranchoring); 288/288 pass. Three copies byte-identical. CHANGELOG updated.Differential run of 21 shapes (13 allow / 8 block) through the real hook at that commit: 0 mismatches — but see round 4 below: QA's wider differential against
mainfound three shapes this pass had regressed that my 21 did not cover.A+ round 4 (runner, 2026-09-07, commit d631f2e)
QA round 4 ran a wider differential against
mainand found three shapes the-m-anchored extractor had weakened. All three are fixed and pinned:-minside an earlier quoted argument (--author="uses -m flag" -m "updated stuff"): the scan now skips quoted regions and keeps scanning past a candidate-mthat is not followed by a quote, instead of aborting.-mlaundering (-m "wip\n\nfix: sneaky"): only the subject line is validated (head -n 1on the extracted message), so a conventional-looking body line cannot pass a non-conventional subject.-F-/--file=-with a heredoc: with no quoted-m, the extractor falls back to the first line of the heredoc feeding the commit — whatmain's<<.*EOFbranch validated. This neededraw_commit_segmentto keep a depth-0 heredoc body in the raw segment text (blanked in the code form, so selection is unaffected), which it had been dropping.Three new cases (both polarities, all three copies), 297/297 pass; copies byte-identical; the
commit_message_fromheader now states the-Ffallback accurately; CHANGELOG counts the three fail-opens closed. Local differential at this commit: 16 shapes (8 allow / 8 block), 0 mismatches — and this time the set includes QA's three.A+ round 5 (runner, 2026-09-07, commit 276c68c)
raw_commit_segmentnow prints every qualifying segment (\\001-separated, in order) instead of only the first, and the guard walks them and validates the first that yields a message. A-m-less segment that merely mentionsgit commit— a comment line,git commit-tree,--amend --no-edit, an unquoted echo — can no longer leaveMSGempty and skip validation; QA's four repros all block withGot: updated stuff, and the two valid counterparts plus a lone--amend --no-edit/ baregit commitstill pass. Pinned by a new case over all three copies; 300/300 pass; local differential at this commit: 28 shapes (12 allow / 16 block), 0 mismatches, including every shape any QA round has named.raw_commit_segmentare near-duplicates (~20 lines each); a refactor into one awk function is a follow-up, not a behaviour change. The spec plan asked for mutation records on AC-1–AC-4 whileisGateTestEvidenceclassifies none of the six ACs as gate tests (they are behavioural exit-code assertions); no record is claimed for them and the parser finds none to reject.A+ round 6 (runner, 2026-09-07, commit 6a1776d)
--message=…,--message …, and short-flag clusters ending inm(-am,-sm, …) are now validated like-m— the pre-existing adjacent fail-open QA round 6 named.commit_message_fromrecognises the flag forms and hands the argument to onemessage_atroutine (quoted string,$(cat <<'EOF'idiom, or nothing for an unquoted word). Pinned with both polarities over all three copies;--message-xand-F- </dev/nullare untouched.raw_commit_segment's depth-0 and subshell branches now share oneheredoc_delimawk function (the third copy, inemit_segments, is a different scanner and is left alone).A+ round 7 (runner, 2026-09-07, commit 7427aa2)
validate_commit_subjectfunction called for each segment that yields a message, so a decoy conventional commit earlier in a compound command no longer shields a later non-conventional one (thefix: ok ; updated stuffand$(… "fix: decoy")shapes now block on the later message); two conventional commits chained still pass. Pinned by a new case over all three copies. CHANGELOG states it. 306/306 pass; copies byte-identical; local differential at this commit: 41 shapes (17 allow / 24 block), 0 mismatches.isGateTestEvidencedoes not classify these behavioural ACs as gate tests, so the parser accepts these without gating on them):Mutation-verified: AC-1 — replaced
templates/hooks/pre-tool.shwithorigin/main's copy (the pre-fix extractor);__tests__/pre-tool-hook.integration.test.ts(981 AC-1) failed (1 failed | 2 passed — the two untouched copies); restored via checkout on a clean tree.Mutation-verified: AC-2 — same mutation as AC-1;
__tests__/pre-tool-hook.integration.test.ts(981 AC-2) failed (1 failed | 2 passed); restored.Mutation-verified: AC-3 — made the short-flag scan never recognise
m(substr(s, e - 1, 1) == "m"→== "z") so the extractor yields nothing;__tests__/pre-tool-hook.integration.test.ts(981 AC-3) failed (1 failed | 2 passed); restored. (Reverting tomain's hook does not fail AC-3 —mainalready blocked that shape — so AC-3 is a regression guard and needed a skip-validation mutation.)Mutation-verified: AC-4 — disabled the
-m "$(cat <<'EOF'idiom branch ("$(cat "→"$(xxx ");__tests__/pre-tool-hook.integration.test.ts(both981 AC-4cases) failed (2 failed | 4 passed); restored.A+ round 8 (runner, 2026-09-07, commit ca448ce)
raw_commit_segmentheader now states the per-segment validation the code performs (every segment that yields a message is checked), replacing the stale "first one wins" sentence. All three copies byte-identical.mainand out of scope:-F <file>(a message file on disk) is not validated;commit-tree … -mplumbing is blocked by the same guard.mainfound a shape the segment-scoped extractor had regressed or an adjacent fail-open it exposed (--message=,-am, chained commits). Every addition is pinned by a test in both polarities over all three copies, the CHANGELOG enumerates the new blocking behaviour, and the final differential (41 shapes) shows no valid conventional commit newly blocked. The owner may still prefer to split the message-flag additions out; they are the commits6a1776d5and7427aa22.A+ round 9 (runner, 2026-09-07, commit eba633e)
main): an unquoted#comment at a word boundary is blanked inraw_commit_segment's code form to end-of-line (raw text kept), andcommit_message_fromruns its anchor and flag scan on a comment-stripped copy of the segment — so# git commit -m "wip stuff"above a valid commit no longer blocks it (at depth 0 or inside a subshell), while a comment carrying a conventional decoy cannot shield a real non-conventional commit, and a trailing# commentafter a real commit is ignored. Pinned in both polarities over all three copies (four allow shapes, three block shapes); 309/309 pass; copies byte-identical; local differential: 45 shapes (21 allow / 24 block), 0 mismatches.pause_for_human): left to the owner as stated in round 8 — the separable commits are6a1776d5,7427aa22and this one. Each round's expansion was driven by a differential-against-mainfinding that the issue's Done-when clause ("a non-conventional one still is [blocked]" / "never blocked because of text outside its own segment") made a defect, not by new feature intent.A+ round 10 (runner, 2026-09-07, commit 1a46a8f)
main):message_atkeyed the heredoc branch on the exact literal$(catand so blocked$( cat,$( cat, a tab,$(cat<<,$(/bin/cat, and a newline after$(, printing the substitution text asGot:. The branch is now taken whenever the double-quoted argument opens a command substitution that contains a<<introducer; with no heredoc inside (or a<<<herestring) it falls through to the generic quoted reader, so-m "fix: ok $(date)"still reads as a plain message. Pinned in both polarities for six spellings over all three copies.cd … && diff a.md b.md && echo …, is now a test as written (the earlier case had dropped thecdprefix thatresolve_cd_targetreads).A+ round 11 (runner, 2026-09-07, commit df28e2c)
-m "$MSG"no longer blocks on the literal$MSG(QA round 11's allow→block flip vsmain): a message that is one bare variable reference ($NAME/${NAME}) cannot be validated statically, so it is treated like an unquoted word and nothing is validated — matchingmain's bare-form behaviour instead ofmain's accidental pass (its extractor read the assignment's quoted string). Literal text alongside a variable is still validated as written (Got: $MSG updated stuff). Pinned in both polarities over all three copies; CHANGELOG states it. 318/318 pass; copies byte-identical.main:git commitwith multiple spaces bypassesseg_match 'git commit'entirely (pre-existing; the guard's own entry condition, not this PR's extractor).pause_for_human— whether to split the adjacent fail-open closures (6a1776d5message-flag forms,7427aa22per-segment validation,eba633efcomment stripping) into their own PR. The reviewer states this is the only thing between the PR and READY_FOR_MERGE. I am not making that call; the PR is otherwise complete, and the runner stops here for fix(hooks): commit-message validator extracts from the whole command, so an earlier quoted string or unrelated heredoc blocks a valid conventional commit #981.A+ round 12 (runner, 2026-09-07, commit d01b916)
mainhad by accident, done on purpose (QA round 12): a subject that is one bare$NAME/${NAME}is resolved through the firstNAME=assignment in the same command ("…",'…', or a bare word; first line of the value) and that literal is validated — soMSG="updated stuff"; git commit -m "$MSG"blocks withGot: updated stuffexactly as onmain, andMSG="fix: ok"; …passes. Only a variable the command never assigns validates nothing (unknowable; like an unquoted word). The round-11 comment that misstatedmain's behaviour is gone with the exemption. Pinned in both polarities over all three copies; CHANGELOG corrected. 318/318 pass; copies byte-identical.--no-verifywhole-input scan (pre-existing fail-open the extractor fix makes newly reachable): recorded as PLAN §9 OQ-21 on PR docs(plan): 2026-09 backlog graph (16 nodes, /graph-run ready) #998 rather than filed (§5 I-7); recommendation there is to scope that scan and the--amend/--allow-emptysibling to thegit commitsegment through the sameraw_commit_segmentseam.$'…'quoting and nested$( $( ) )are not exercised by the suite; the hand-rolled tokenizer fails open (empty extraction skips validation) rather than loud on them — unchanged frommain.A+ round 13 (runner, 2026-09-07, commit 9561151)
literal_assignment_valueis now an awk scanner that readsNAME=assignments only in code context — quoted strings,#comments and heredoc bodies are skipped as data — and only in the text before the commit segment (the caller passes the segment's offset), last assignment wins as in the shell. QA's two regressions (# set MSG=updated …andecho 'usage: MSG=updated ./s.sh'above a realMSG="fix: real") now pass; a double-quoted mention and a heredoc-body mention likewise;MSG="fix: a"; MSG="updated stuff"; …now blocks on the value the commit actually carries (an improvement onmain's first-match); an assignment after the commit is ignored. Pinned in both polarities over all three copies; CHANGELOG states the resolution scope. 321/321 pass; copies byte-identical.A+ round 14 (runner, 2026-09-07, commit f89a78e)
limit=0sentinel collision fixed (QA round 14):literal_assignment_valuenow takes-1for "whole command";0is a genuine zero-width window, so a commit that is the first segment resolves$MSGagainst nothing and an assignment after it can no longer block a valid commit. The fallback path passes-1explicitly; the per-segment path keeps passing the segment offset. The CHANGELOG's "last assignment before the commit" sentence is accurate as written now. Pinned with the reviewer's pair (git commit -m "$MSG" && MSG="…"with and without a leadingtrue &&) over all three copies. 324/324 pass; copies byte-identical.case/esac, process substitution<(…)and$'…'quoting are not modelled by the segmenter; they degrade to the fail-safe whole-command fallback, not a bypass.A+ round 15 (runner, 2026-09-07, commit 2012bd1)
raw_commit_segmentdrops backslash-newline, so a segment containing a continuation no longer matched the raw input and the "before the commit" window silently became the whole command. The window is now located on a continuation-normalized copy of the input (the same copy the resolver scans), and a segment that still cannot be located gets a zero-width window — validating a bare$VARagainst nothing — instead of everything. Pinned with the reviewer's shape in both polarities over all three copies. 327/327 pass; copies byte-identical.git -C <dir> commitnever matches the guard's entry conditionseg_match 'git commit'(pre-existing, identical onmain): added to PLAN §9 OQ-21 on PR docs(plan): 2026-09 backlog graph (16 nodes, /graph-run ready) #998 alongside the--no-verifywhole-input scan, rather than filed (§5 I-7).A+ round 16 (runner, 2026-09-07, commit 49432ad)
Both findings live in the variable-resolution work; both fixed and pinned:
MSG=$(echo "fix: generated")was read as the bare word$(echoand blocked a valid commit. A value carrying$, a backtick or a backslash — quoted or bare — now neither supplies nor overrides a value (the same ruleresolve_cd_targetapplies tocdtargets), so the commit validates nothing rather than text the author never wrote. CHANGELOG states it.git commit -m "$MSG"; MSG="updated stuff"; git commit -m "$MSG"now blocks on the second commit (Got: updated stuff), while two identical valid commits still pass.A+ round 17 (runner, 2026-09-07) — loop stopped for #981
The reviewer's remaining items are not code changes inside this PR:
49432ad1againstmain, hook latency delta is +85 ms at 2 KB, +12 ms at 20 KB, +1.81 s at 60 KB, +1.99 s at 131 KB (3.39 s vs 1.39 s at 131 KB). The character-by-character awk scans are super-linear; typical commit commands are well under 2 KB.--no-verifyunmasking: the secret/sensitive-file guard greps--no-verifyagainst the whole command, soecho "use --no-verify to skip"; git commit -m "fix: x"skips that guard — pre-existing, butmainaccidentally blocked such shapes via the very false positive this PR fixes, so this merge makes it newly reachable. Tracked as PLAN §9 OQ-21 on PR docs(plan): 2026-09 backlog graph (16 nodes, /graph-run ready) #998; the owner may want to raise its priority or land it first.6a1776d5,7427aa22,eba633ef, and the variable-resolution commitsdf28e2cf…49432ad1): the owner's call, escalated since round 8.All six ACs are met with executed evidence, CI is green, copies are byte-identical, 330/330 tests pass. The runner stops here.