Skip to content

Fix PowerShell parsing for standalone -- tokens - #335465

Open
Ingvar Stepanyan (RReverser) wants to merge 3 commits into
microsoft:mainfrom
RReverser:fix-pwsh-auto-approve-bare-double-dash
Open

Fix PowerShell parsing for standalone -- tokens#335465
Ingvar Stepanyan (RReverser) wants to merge 3 commits into
microsoft:mainfrom
RReverser:fix-pwsh-auto-approve-bare-double-dash

Conversation

@RReverser

@RReverser Ingvar Stepanyan (RReverser) commented Sep 10, 2026

Copy link
Copy Markdown

This PR fixes an issue where VSCode would keep asking for approvals for any commands using -- for argument separation, even if such commands have already been included in the autoApprove patterns.

This is caused by treesitter being unable to parse this separator and VSCode forcing explicit approval for any unparsed commands.

Inspired by a similar fix in #310839.

Copilot AI balanced review requested due to automatic review settings September 10, 2026 13:10
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/treeSitterCommandParser.ts
  • src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/treeSitterCommandParser.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Terminal auto-approval parsing is security-sensitive and warrants final human review of PowerShell edge cases.

Pull request overview

Fixes PowerShell parsing of standalone -- tokens used by native CLI tools.

Changes:

  • Masks standalone -- tokens before tree-sitter parsing while preserving offsets.
  • Adds regression coverage for Git pathspecs and npm exec.
File summaries
File Description
treeSitterCommandParser.ts Extends PowerShell native-argument masking.
treeSitterCommandParser.test.ts Adds standalone -- parsing tests.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@iket0731

Copy link
Copy Markdown

Hi Ingvar Stepanyan (@RReverser)

I was also looking into the standalone -- issue in PowerShell. I noticed one concern while reading your PR.

pwshStandaloneDoubleDashRegex replaces standalone -- with __ regardless of context. For example:

$val --  ->  $val __

In my local testing, Tree-sitter parses the original $val -- successfully, but reports an error for $val __. This means that cases where -- is not being used as a native CLI argument separator could become unanalyzable, even though they were previously parsed successfully.

Rather than masking every standalone --, it may be worth revisiting the masking approach so that it only applies when -- is used as a native CLI argument separator. Sharing this in case it is useful.

@RReverser

Copy link
Copy Markdown
Author

Tree-sitter parses the original $val -- successfully, but reports an error for $val __.

Ugh it just keeps getting weirder. So tree sitter is fine with trailing -- but not a standalone one?

But yeah, good catch if so, I'll update the PR.

@iket0731

Copy link
Copy Markdown

tree-sitter-powershell accepts -- as a decrement operator in PowerShell syntax, but reports it as an error when it appears in a command. (This appears to be a bug or limitation of tree-sitter-powershell.)
This behavior does not depend on the position of --.

$val --  # OK
-- $val  # OK
git diff --  # Error
git diff -- file.txt  # Error

@RReverser

Copy link
Copy Markdown
Author

Ugh that's trickier to distinguish. I guess an easy option might be to replace -- with (double space instead of __) - in most cases they are equivalent, and it would preserve $val -- -> $val and -- $val -> $val as valid syntax too.

@RReverser
Ingvar Stepanyan (RReverser) force-pushed the fix-pwsh-auto-approve-bare-double-dash branch from d15b09a to 2e599be Compare September 11, 2026 20:07
@RReverser

Copy link
Copy Markdown
Author

I guess an easy option might be to replace -- with (double space instead of __) - in most cases they are equivalent, and it would preserve $val -- -> $val and -- $val -> $val as valid syntax too.

Did this. I think it's conceptually more correct too - standalone -- is normally used as a whitespace-style separator between whole arguments, which is why the --flag -> __flag trick doesn't apply here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants