feat(config): support multi-word entries in exclude_commands for subcommand-level exclusion#1396
Open
atgim wants to merge 1 commit intortk-ai:developfrom
Open
feat(config): support multi-word entries in exclude_commands for subcommand-level exclusion#1396atgim wants to merge 1 commit intortk-ai:developfrom
atgim wants to merge 1 commit intortk-ai:developfrom
Conversation
Collaborator
📊 Automated PR Analysis
SummaryExtends the Review Checklist
Linked issues: #1282, #1313, #1392 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
faa3bc1 to
5168852
Compare
Extends exclude_commands matching from first-word-only equality to whitespace-aware token matching. Entries containing whitespace match the command's first N tokens (where N is the entry's token count), enabling subcommand-level exclusion without blocking the parent command. Example config: [hooks] exclude_commands = ["curl", "git diff", "kubectl describe"] - "curl" behaves exactly as before (excludes all curl invocations) - "git diff" excludes `git diff` with any args, but NOT `git status` - Word boundaries use whitespace, so "git diff" never matches `git difference` or `git diffoo` - Whitespace in both entry and command is normalized (handled by split_whitespace on both sides) Rationale: first-word-only matching forces all-or-nothing exclusion, making it impossible to exclude diff/patch-producing subcommands (`git diff`, `git show -p`) while keeping `git status` / `git log` filtered. Silent output corruption on these subcommands is particularly harmful for LLM agents that read diffs to make edits, since stripped context lines can lead to wrong interpretation of file state. Backward compatible: existing single-word entries unchanged. All existing tests pass. New tests cover multi-word exclusion, partial word safety, whitespace normalization, and mixed entry coexistence. Refs: rtk-ai#1282, rtk-ai#1313
5168852 to
ac8ab08
Compare
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
Extends
[hooks].exclude_commandsmatching from first-word-only equality to whitespace-aware token matching. Entries containing whitespace match the command's first N tokens (where N is the entry's token count), enabling subcommand-level exclusion without blocking the parent command."curl"behaves exactly as before (excludes allcurlinvocations)"git diff"now excludesgit diffwith any args, but notgit status/git log"git diff"never matchesgit differenceorgit diffoosplit_whitespaceon both sides)Motivation
First-word-only matching forces all-or-nothing exclusion: users cannot exclude
git difffrom rewriting while keepinggit statusfiltered, because both start withgit. This is particularly harmful for diff/patch-producing subcommands where silent output corruption (stripped context lines, removed headers, dropped blob hashes) leads LLM-based agents to misinterpret file state and produce wrong edits.The existing
RTK_DISABLED=1env-var escape hatch requires the user to remember it on every invocation, which is not viable for agent-driven pipelines. A persistent, config-level knob at subcommand granularity is what was missing.Related issues
rtk curlbreaks downstream parsers (motivating the silent-corruption concern)This PR addresses a concrete slice of #1313: users who know which specific subcommands they need raw output for can now declare it in config instead of patching the binary or sprinkling
RTK_DISABLED=1.Behavior
Implementation is a small helper function called from the existing exclude check:
The call site in
rewrite_segment_innerchanges from:to:
Backward compatibility
split_whitespace().eq()reduces to first-word equality)Test plan
test_rewrite_multi_word_excludes_git_diff— two-word entry blocks subcommand + argstest_rewrite_multi_word_allows_other_git_subcommands— other subcommands still filtertest_rewrite_multi_word_no_partial_word_match—git diffentry does not matchgit diffoo/git differencetest_rewrite_multi_word_and_single_word_coexist— mixed entries work independentlytest_is_command_excluded_whitespace_normalization— multi-space handled correctlytest_is_command_excluded_empty_entry_never_matches— empty/whitespace-only entries safecargo fmt --all && cargo clippy --all-targets && cargo test --all— all 1596 tests pass, no new clippy warnings introduced🤖 Generated with Claude Code