fix: support trailing wildcards in auto-approve command matching#11759
Draft
roomote[bot] wants to merge 1 commit intomainfrom
Draft
fix: support trailing wildcards in auto-approve command matching#11759roomote[bot] wants to merge 1 commit intomainfrom
roomote[bot] wants to merge 1 commit intomainfrom
Conversation
Strip trailing asterisk(s) from command prefixes before performing startsWith checks. This allows patterns like "git*" and "git *" to work as users expect when configuring allowed auto-execute commands. - "git*" normalizes to "git" and matches any command starting with "git" - "git *" normalizes to "git " and matches "git commit" but not "gitk" - Standalone "*" (match-all) behavior remains unchanged - Original prefix length preserved for longest-prefix-match comparisons - Updated UI description to clarify prefix and wildcard behavior - Added comprehensive tests for trailing wildcard patterns Fixes #11756
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.
Related GitHub Issue
Closes: #11756
Description
This PR attempts to address Issue #11756. Feedback and guidance are welcome.
The auto-approve system already uses prefix matching -- adding
gitto allowed commands matchesgit commit -m "...",git push, etc. However, users naturally try glob-style wildcards likegit*orgit *, which failed because the trailing*was treated as a literal character.Changes:
findLongestPrefixMatch()(src/core/auto-approval/commands.ts): Strip trailing*characters from prefixes before thestartsWithcheck. The original prefix length (including*) is preserved for longest-prefix-match comparisons, sogit*(4 chars) still beats a standalone*(1 char).isAutoApprovedSingleCommand()(src/core/auto-approval/commands.ts): Same trailing-wildcard normalization applied to the inline allowlist check (used when no denylist is provided).UI description (
webview-ui/src/i18n/locales/en/settings.json): Updated the allowed commands description to clarify that entries work as prefixes and that trailing wildcards likegit*are supported.Behavior:
git*normalizes togitand matches any command starting withgit(includinggitk)git *normalizes togit(with space) and matchesgit commitbut NOTgitk*(match-all) behavior remains unchangedTest Procedure
src/core/auto-approval/__tests__/commands.spec.tscovering:git*matchinggit commit -m "..."andgitkgit *matchinggit commitbut notgitk*characters being stripped**fallback when no other prefix matchesisAutoApprovedSingleCommandwith trailing wildcardsgetCommandDecisionwith trailing wildcards interacting with deny listPre-Submission Checklist
Documentation Updates
No external documentation updates are required. The UI description for allowed commands has been updated inline to clarify prefix and wildcard behavior.
Additional Notes
This is a minimal, backward-compatible change. Existing prefix entries (without
*) continue to work exactly as before. The only new behavior is that trailing*characters are now stripped before matching, which aligns with user expectations.Interactively review PR in Roo Code Cloud