Skip to content

Fix terminal auto-approve splitting commands at --flag=value in powershell - #310839

Merged
Anthony Kim (anthonykim1) merged 2 commits into
mainfrom
anthonykim1/fix294010
Apr 16, 2026
Merged

Anthony Kim (anthonykim1) merged 2 commits into
mainfrom
anthonykim1/fix294010

Conversation

@anthonykim1

@anthonykim1 Anthony Kim (anthonykim1) commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Resolves: #294010
/cc Megan Rogge (@meganrogge)

Easy repro on windows powershell , set git log as entry to "chat.tools.terminal.autoApprove": { in settings.json

Before:
image

After:
image

What the problem was:

  • When Copilot proposes a PowerShell command that contains a POSIX-style
    --flag=value argument (very common: git log --format="…" etc.), the terminal auto-approve flow splits the command line incorrectly and refuses to auto-approve commands that should match the user's allow rules.

  • Likely upstream tree-sitter-powershell grammar: word= at command-argument position is parsed as an assignment
    expression, which terminates the containing command. So git log --format="a|b" HEAD -1 becomes roughly
    ["git log --format", "b\" HEAD -1"] instead of one git log command.

What this PR does:
Replaces the = in PowerShell --flag=value argument patterns with a space so the tree-sitter PowerShell grammar treats the argument as a normal command parameter. Character positions and overall length are preserved so node ranges from the parsed (masked) tree can be used to slice the original command line.

  • In extractSubCommands, for PowerShell only, mask --flag= / -flag= to --flag / -flag before parsing. The replacement is length-preserving, so node start/end indices from the parsed (masked) tree still index correctly into the original command line — we slice the original so the returned sub-commands keep the user-visible =.

  • I believe we do similar with CommandLinePwshChainOperatorRewriter, which works around a separate
    gap in the same grammar (chain operators / &&).

Long term:
I've added TODO to remove "workaround" once issue is addressed in https://github.com/airbus-cert/tree-sitter-powershell

Alex Ross (@alexr00) Is the protocol for tree-sitter that we file issue under airbus first, then we update https://github.com/microsoft/vscode-tree-sitter-wasm and eventually update https://github.com/microsoft/vscode-tree-sitter-wasm in core?

Copilot AI review requested due to automatic review settings April 16, 2026 20:11
@anthonykim1 Anthony Kim (anthonykim1) changed the title Fix to put fix in treeSitterCommandParser Fix pwsh auto-approve incorrectly parsing command 294010 Apr 16, 2026
@anthonykim1 Anthony Kim (anthonykim1) added this to the 1.117.0 milestone Apr 16, 2026

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.

Pull request overview

Addresses a PowerShell tree-sitter grammar limitation that mis-parses POSIX-style --flag=value arguments (e.g. git log --format="a|b") as assignment expressions, which can truncate extracted sub-commands and break terminal chat auto-approval parsing.

Changes:

  • Add a PowerShell-specific masking step that replaces = in -flag= / --flag= tokens before tree-sitter parsing, then slices results from the original command line to preserve user-visible text.
  • Add regression tests for common git log --format=... scenarios (including | in quoted values and chained commands).
Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/treeSitterCommandParser.ts Implements PowerShell-only masking for --flag=value patterns to prevent command truncation during tree-sitter parsing.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/treeSitterCommandParser.test.ts Adds coverage for the reported PowerShell parsing regression with --flag=value arguments.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@github-actions

github-actions Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: b47efc0a Current: e8b0607d

Changed (3)

chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Light
Before After
before after
chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Dark
Before After
before after
editor/inlineCompletions/other/JumpToHint/Dark
Before After
before after

@anthonykim1 Anthony Kim (anthonykim1) changed the title Fix pwsh auto-approve incorrectly parsing command 294010 Fix terminal auto-approve splitting commands at --flag=value in powershell Apr 16, 2026
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review April 16, 2026 22:41
@anthonykim1
Anthony Kim (anthonykim1) merged commit 5289257 into main Apr 16, 2026
26 checks passed
@anthonykim1
Anthony Kim (anthonykim1) deleted the anthonykim1/fix294010 branch April 16, 2026 23:11
@alexr00

Copy link
Copy Markdown
Member

Long term:
I've added TODO to remove "workaround" once issue is addressed in https://github.com/airbus-cert/tree-sitter-powershell

Alex Ross (@alexr00) Is the protocol for tree-sitter that we file issue under airbus first, then we update https://github.com/microsoft/vscode-tree-sitter-wasm and eventually update https://github.com/microsoft/vscode-tree-sitter-wasm in core?

Yep, that would be the path forward.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PowerShell auto approve incorrectly parsing command

4 participants