Fix auto-approve to suggest commands with flags when flags precede subcommand #282471
+201
−10
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.
Auto-approve was failing to recognize subcommands when CLI flags appeared before them. Commands like
mvn -DskipIT testwouldn't match the approvedmvn testrule, and users wouldn't see an option to auto-approve—only "Always Allow Exact Command Line."This fix enables the system to detect subcommands even when flags appear before them, and suggests approval rules that include the flags as specified in the command.
Changes
runInTerminalHelpers.ts: AddedfindNextNonFlagArghelper that returns the index of the first non-flag argument after a given positionparts.slice(0, subCommandIndex + 1).join(' ')to include all arguments from command through subcommand (including flags)mvn -DskipIT testsuggestsmvn -DskipIT testnpm --silent run testsuggestsnpm --silent run testExample
Now correctly suggests (including flags):
mvn -DskipIT test→ "Always allowmvn -DskipIT test"mvn -abc foo bar→ "Always allowmvn -abc foo"gradle --info build→ "Always allowgradle --info build"npm --silent run test→ "Always allownpm --silent run test"Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.