Skip to content

Fix config rules not matching commands with global flags#137

Open
berk-karaal wants to merge 2 commits intoldayton:mainfrom
berk-karaal:fix/config-match-global-flags
Open

Fix config rules not matching commands with global flags#137
berk-karaal wants to merge 2 commits intoldayton:mainfrom
berk-karaal:fix/config-match-global-flags

Conversation

@berk-karaal
Copy link
Copy Markdown

@berk-karaal berk-karaal commented Apr 5, 2026

Summary

Fixes #136

Config rules like allow git commit fail to match commands with global flags such as git -C /path commit. This happens because the config matcher operates on raw tokens, where -C /path breaks the prefix match — even though Dippy displays the command as "git commit" when asking for permission (fixed in #17).

Approach: Two-Pass Config Matching

  • Step 1 (unchanged): Match raw tokens against config rules. This preserves explicit rules like deny git -C * commit.
  • Step 1.5 (new): If step 1 finds no match, strip global flags using handler-exported GLOBAL_FLAGS_WITH_ARG / GLOBAL_FLAGS_NO_ARG constants 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: Added strip_global_flags() — reads global flag constants from handlers via getattr(), strips them from tokens, returns cleaned tokens or None if 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

  • Unit tests for strip_global_flags() covering git, docker, unknown commands, and edge cases (tests/test_strip_global_flags.py)
  • Integration tests via analyze() verifying end-to-end behavior including precedence of explicit flag rules (tests/test_analyzer_bugs.py::TestConfigGlobalFlagStripping)
  • Full test suite passes (10,922 tests)
  • just check passes

🤖 Generated with Claude Code

berk-karaal and others added 2 commits April 5, 2026 11:52
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config rules don't match commands with global flags (e.g. git -C /path commit)

1 participant