Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 10, 2025

Auto-approve was failing to recognize subcommands when CLI flags appeared before them. Commands like mvn -DskipIT test wouldn't match the approved mvn test rule, 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: Added findNextNonFlagArg helper that returns the index of the first non-flag argument after a given position
  • Logic updates:
    • Uses parts.slice(0, subCommandIndex + 1).join(' ') to include all arguments from command through subcommand (including flags)
    • Handles both single subcommands and sub-sub-commands
    • Single subcommands: mvn -DskipIT test suggests mvn -DskipIT test
    • Sub-sub-commands: npm --silent run test suggests npm --silent run test
  • Tests: 12 new test cases covering flags before/between subcommands, multiple flags, and edge cases

Example

// Before: Would check parts[1] directly
if (parts.length >= 2 && !parts[1].startsWith('-')) {
    return `${parts[0]} ${parts[1]}`;  // Fails when parts[1] is a flag
}

// After: Find subcommand index and include everything up to it
const subCommandIndex = findNextNonFlagArg(parts, 1);
if (subCommandIndex !== undefined) {
    return parts.slice(0, subCommandIndex + 1).join(' ');
}

Now correctly suggests (including flags):

  • mvn -DskipIT test → "Always allow mvn -DskipIT test"
  • mvn -abc foo bar → "Always allow mvn -abc foo"
  • gradle --info build → "Always allow gradle --info build"
  • npm --silent run test → "Always allow npm --silent run test"
Original prompt

This section details on the original issue you should resolve

<issue_title>GitHub Copilot auto-approve not recognizing commands because of CLI option order.</issue_title>
<issue_description>I have GitHub Copilot configured in Agent mode to accept a lot of Bash commands such as mvn compile. When it runs into a new one, it usually asks me if I want to auto-approve the command, such as mvn foobar.

Just now Claude Haiku 4.5 wanted to run this command:

cd /…/globalmentor/globalmentor-base && mvn -DskipIT test -q && echo "✓ All tests passed"

It didn't auto-approve. Worse, it didn't even give me the option to auto-approve in the future.

Expectation A: The command should have run automatically.

Expectation A: If there was a command it hadn't seen before, a button with "Approve", with a choice to "Always allow mvn test in the future" (or echo or whatever command it is that it was seeing for the first time).

Actual: The default button said "Allow", but the choices were "Always Allow Exact Command Line" and "Configure Auto Approve".

Note that there were no commands it hasn't seen. mvn test is already approved in settings.json. I don't think cd and echo need approval.

Was that the problem? Do I need to add cd and echo to settings.json? But I don't think that's the problem; I never have to approve cd and echo.

My hunch is that the real problem here is that the GitHub Copilot Bash command parser is really basic and naive, and only recognizes the form mvn test -DskipIT. If it sees a CLI parameter before the subcommand, such as mvn -DskipIT test, it doesn't know what to do, and doesn't even know what command to suggest for auto-approval.

If that is the issue, GitHub Copilot needs to improve the CLI parser to normalize the command requested. This should be straightforward, as CLIs have become pretty standardized and there are even CLI guidelines for example.

Version: 1.106.3 (user setup)
Commit: bf9252a2fb45be6893dd8870c0bf37e2e1766d61
Date: 2025-11-25T22:28:18.024Z
Electron: 37.7.0
ElectronBuildId: 12781156
Chromium: 138.0.7204.251
Node.js: 22.20.0
V8: 13.8.258.32-electron.0
OS: Windows_NT x64 10.0.26200
```</issue_description>

<agent_instructions>Add the ability to suggest sub-command approvals when there is an argument starting with `-` between the command and sub-command here: https://github.com/microsoft/vscode/blob/26b983fd4ad62c43798c8435a45fad68ad20214f/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.ts#L121-L133</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@Tyriar</author><body>
> It didn't auto-approve. Worse, it didn't even give me the option to auto-approve in the future.

> My hunch is that the real problem here is that the GitHub Copilot Bash command parser is really basic and naive, and only recognizes the form mvn test -DskipIT. If it sees a CLI parameter before the subcommand, such as mvn -DskipIT test, it doesn't know what to do, and doesn't even know what command to suggest for auto-approval.

Close, `mvn` is one of the handful of commands where we suggest subcommands for instead:

https://github.com/microsoft/vscode/blob/26b983fd4ad62c43798c8435a45fad68ad20214f/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.ts#L101-L102

So you're hitting that case and then it's not getting the rules due to this:

https://github.com/microsoft/vscode/blob/26b983fd4ad62c43798c8435a45fad68ad20214f/src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/runInTerminalHelpers.ts#L121-L133

The parser was naive before 1.106 but now it uses the [bash tree sitter grammar](https://github.com/tree-sitter/tree-sitter-bash) which is so much more capable.

My normal recommendation would be to either add one of these rules

```jsonc
{
  "mvn -DskipIT test": true,
  "/^mvn \\-[a-zA-Z]+ test/": true // ⚠️ if you want to approve any flag
}

But I'm thinking we can support this case where we look for a single argument between the command and the sub-command and end up suggesting allowing mvn -DskipIT test as a future rule.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix auto-approve recognition for CLI commands Fix auto-approve subcommand detection when flags precede subcommand Dec 10, 2025
Copilot AI requested a review from Tyriar December 10, 2025 13:14
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this isn't the solution I suggested. The auto approve command suggestion should include the exact flag as specified. So for the command line mvn -abc foo bar, mvn -abc foo should be the new rule.

Changed implementation to suggest the exact command with flags included
(e.g., `mvn -DskipIT test` instead of just `mvn test`). This matches
the requirement that for `mvn -abc foo bar`, the suggestion should be
`mvn -abc foo` (including the flags between command and subcommand).

Co-authored-by: Tyriar <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 10, 2025

@copilot this isn't the solution I suggested. The auto approve command suggestion should include the exact flag as specified. So for the command line mvn -abc foo bar, mvn -abc foo should be the n...

Fixed in 137cd8d. The implementation now includes flags in the suggestions as you specified. For mvn -abc foo bar, it suggests mvn -abc foo. For the original issue example mvn -DskipIT test -q, it suggests mvn -DskipIT test.

Copilot AI changed the title Fix auto-approve subcommand detection when flags precede subcommand Fix auto-approve to suggest commands with flags when flags precede subcommand Dec 10, 2025
Copilot AI requested a review from Tyriar December 10, 2025 15:05
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.

GitHub Copilot auto-approve not recognizing commands because of CLI option order.

2 participants