Skip to content

agent host pwsh tool should use pwsh grammar for terminal auto-approval - #328133

Merged
Anthony Kim (anthonykim1) merged 12 commits into
mainfrom
anthonykim1/pwshApprove
Jul 30, 2026
Merged

Anthony Kim (anthonykim1) merged 12 commits into
mainfrom
anthonykim1/pwshApprove

Conversation

@anthonykim1

@anthonykim1 Anthony Kim (anthonykim1) commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Resolves: #328052

  • Select the terminal grammar from the tool that actually executes the command: correlate SDK shell permissions with tool.execution_start, and recognize Agent Host terminal overrides reported as custom-tool requests named bash or powershell.
  • Carry an explicit bash or powershell language on Agent Host's internal confirmation signal. Only those values are eligible for terminal-rule auto-approval and rule suggestions; missing language requires confirmation.
  • Load the Bash and PowerShell tree-sitter grammars independently so one unavailable grammar does not disable the other.
  • Parse PowerShell pipelines, script blocks, subexpressions, backtick continuations, $null and no-space redirects, and --flag=value arguments with PowerShell-specific handling.
  • Match parsed PowerShell subcommands case-insensitively while preserving configured regex casing for full-command rules. Keep full-command deny-before-allow precedence; a full-command allow can approve only with a usable parse, no denied subcommand, and successful redirect validation.
  • Require confirmation for PowerShell parse errors, assignments, method/static invocations, runtime-expanded redirect destinations, and other constructs that cannot be analyzed safely. Literal workspace destinations and $null remain eligible for auto-approval.
  • Keep the shell-language signal internal to Agent Host; no protocol action or public API changes.

Inspirations from:

Copilot AI review requested due to automatic review settings July 29, 2026 23:39

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

Adds shell-aware Agent Host terminal auto-approval, particularly for PowerShell.

Changes:

  • Propagates shell-language metadata through permission handling.
  • Adds PowerShell parsing, matching, and redirect safeguards.
  • Expands focused test coverage across the approval flow.
Show a summary per file
File Description
common/agentService.ts Defines shell-language signal metadata.
node/agentSideEffects.ts Forwards shell language to permissions.
node/commandAutoApprover.ts Implements PowerShell-aware approval analysis.
node/copilot/copilotAgentSession.ts Correlates SDK shell tools with languages.
node/sessionPermissions.ts Applies language-aware rules and redirect checks.
test/node/agentSideEffects.test.ts Tests metadata forwarding.
test/node/commandAutoApprover.test.ts Tests PowerShell parsing and approval behavior.
test/node/copilotAgentSession.test.ts Tests shell-tool correlation.
test/node/sessionPermissions.test.ts Tests language and redirect enforcement.

Review details

Comments suppressed due to low confidence (1)

src/vs/platform/agentHost/node/commandAutoApprover.ts:110

  • PowerShell permits an output redirect to be adjacent to the preceding argument (for example, Write-Host hi>../../outside.txt). The grammar can keep hi>../../outside.txt as one generic_token, but this anchored check only recognizes tokens that begin with the redirect operator. The command is then matched by the Write-Host allow rule with no unsafe destination recorded, so an out-of-workspace write can be auto-approved. Treat any > in a PowerShell generic token as a redirect candidate (escaped/literal cases can conservatively require confirmation), and add coverage for redirects with no whitespace on either side.
const pwshNoSpaceRedirectRegex = /^[0-9*]?>>?/;
  • Files reviewed: 9/9 changed files
  • Comments generated: 1
  • Review effort level: Medium

@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review July 30, 2026 05:11
@anthonykim1 Anthony Kim (anthonykim1) added this to the 1.132.0 milestone Jul 30, 2026
@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as draft July 30, 2026 05:45
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Agent Host terminal auto-approve should use PowerShell grammar for PowerShell commands

4 participants