Fix config rules not matching commands with global flags#137
Open
berk-karaal wants to merge 2 commits intoldayton:mainfrom
Open
Fix config rules not matching commands with global flags#137berk-karaal wants to merge 2 commits intoldayton:mainfrom
berk-karaal wants to merge 2 commits intoldayton:mainfrom
Conversation
Config rules like "allow git commit" failed to match "git -C /path commit" because _match_words() matched against raw tokens where global flags broke the prefix match. Add a two-pass approach: step 1 matches raw tokens (preserving explicit rules like "deny git -C * commit"), step 1.5 strips handler-recognized global flags and re-matches if step 1 found nothing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Fixes #136
Config rules like
allow git commitfail to match commands with global flags such asgit -C /path commit. This happens because the config matcher operates on raw tokens, where-C /pathbreaks the prefix match — even though Dippy displays the command as "git commit" when asking for permission (fixed in #17).Approach: Two-Pass Config Matching
deny git -C * commit.GLOBAL_FLAGS_WITH_ARG/GLOBAL_FLAGS_NO_ARGconstants and re-match.This ensures the config matcher recognizes the same command the user sees in the permission prompt.
Changes
src/dippy/cli/__init__.py: Addedstrip_global_flags()— reads global flag constants from handlers viagetattr(), strips them from tokens, returns cleaned tokens orNoneif no change.src/dippy/core/analyzer.py: Added step 1.5 between config matching and wrapper command handling. Extracted_config_match_decision()helper to deduplicate the match-to-decision conversion.Test plan
strip_global_flags()covering git, docker, unknown commands, and edge cases (tests/test_strip_global_flags.py)analyze()verifying end-to-end behavior including precedence of explicit flag rules (tests/test_analyzer_bugs.py::TestConfigGlobalFlagStripping)just checkpasses🤖 Generated with Claude Code