Repository navigation
Fix terminal auto-approve splitting commands at --flag=value in powershell - #310839
Conversation
There was a problem hiding this comment.
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
--flag=value in powershell
Yep, that would be the path forward. |
Resolves: #294010
/cc Megan Rogge (@meganrogge)
Easy repro on windows powershell , set
git logas entry to"chat.tools.terminal.autoApprove": {in settings.jsonBefore:

After:

What the problem was:
When Copilot proposes a PowerShell command that contains a POSIX-style
--flag=valueargument (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-powershellgrammar:word=at command-argument position is parsed as an assignmentexpression, which terminates the containing command. So
git log --format="a|b" HEAD -1becomes roughly["git log --format", "b\" HEAD -1"]instead of onegit logcommand.What this PR does:
Replaces the
=in PowerShell--flag=valueargument 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/-flagbefore 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 separategap 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?