Repository navigation
fix(hook): pass the post-tool entry when the installed discipline predates it - #785
Merged
Merged
Conversation
…dates it A release before v0.22.0 rejects `hook run --event post-tool` with a clap usage error and exit 2. Claude Code reports exit 2 from a PostToolUse hook as a blocking error, so every shell call in a repository whose hook files come from v0.22.0 failed on a machine with an older discipline on PATH (seen live with Homebrew discipline 0.20.0). The generated post-tool entry now first runs `discipline hook run --help` and, when it does not list `post-tool`, says so in one line on stderr and exits 0. The witness never blocks by design, so this changes no verdict. The pre-tool, check and session-start entries are unchanged. The OpenCode plugin already ignores the witness's exit code and is unchanged. A v0.22.0 file without the probe is still read as a release's (so `--upgrade` rewrites it); the probe in front of any other entry is not. The repository's hook files are regenerated with `hook install --observe --upgrade`. Signed-off-by: Nicolas Brousse <nicolas@brousse.info>
…es-38d596 Signed-off-by: Nicolas Brousse <nicolas@brousse.info> # Conflicts: # docs/ROADMAP.md
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 #784
What
The post-tool entry
discipline hook installwrites (since v0.22.0) now checks the installed release first:discipline hook run --help 2>/dev/null | grep -q post-tool || { echo '<notice>' >&2; exit 0; }. A release before v0.22.0 does not listpost-toolin its help, so the entry prints one line on stderr and exits 0 instead of running--event post-tool.Why
A release before v0.22.0 rejects
--event post-toolwith a clap usage error and exit 2. Claude Code treats exit 2 from a PostToolUse hook as a blocking error, so every shell call in a repository with v0.22.0 hook files reported "PostToolUse:Bash hook blocking error" on a machine with discipline 0.20.0 on PATH. The post-tool witness never blocks by design, so skipping it changes no verdict.The pre-tool, check and session-start entries are unchanged and keep failing closed. The OpenCode plugin is unchanged: it already ignores the witness's exit code (READ). A v0.22.0 hook file without the check is still recognised as generated, so
--upgraderewrites it. A file with the check in front of any other entry is not recognised as generated..claude/settings.json,.agents/hooks.jsonand.github/hooks/discipline.jsonare regenerated withhook install --observe --upgrade. The ledger row is| unreleased |(bug fix).Evidence
.claude/settings.jsonpost-tool command, run throughshwith discipline 0.20.0 on PATH, printsdiscipline on PATH predates v0.22.0 (no --event post-tool); the post-tool hook did not run (...)and exits 0. With this branch's binary on PATH it exits 0 with no notice.the_post_tool_entry_passes_with_a_release_that_predates_it(tests/test_agent_hooks.rs). It covers Claude Code, Codex, Qwen Code, Copilot CLI and agy and runs each installed post-tool entry with a fake olderdisciplineon PATH.--event post-tool.post-toolgets the witness call.hook run --helplistspost-tool.grep -q post-toolwith an always-matchinggrep -q possiblemakes that e2e test fail. The mutant was restored.json_commandmakes the new unit testthe_post_tool_release_probe_is_read_on_the_witness_onlyfail. The mutant was restored.cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo test --no-fail-fastall passed before the merge from main. After merging main,cargo test --test test_agent_hooks --test test_docspasses.allow-agent-instructions: .claude/settings.json the post-tool entry skips with a notice when the installed discipline predates v0.22.0
allow-agent-instructions: .agents/hooks.json the post-tool entry skips with a notice when the installed discipline predates v0.22.0
allow-agent-instructions: .github/hooks/discipline.json the post-tool entry skips with a notice when the installed discipline predates v0.22.0