Skip to content

Restore user/workspace terminal bash auto-approve actions for Agent Host Copilot - #327947

Merged
Anthony Kim (anthonykim1) merged 7 commits into
mainfrom
anthonykim1/autoApproveJul21
Jul 29, 2026
Merged

Anthony Kim (anthonykim1) merged 7 commits into
mainfrom
anthonykim1/autoApproveJul21

Conversation

@anthonykim1

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

Copy link
Copy Markdown
Contributor

Part of: #324136

  • Generate the run-in-terminal auto-approve dropdown actions ("Allow <cmd> in this Workspace", "Always Allow <cmd>", exact-command-line variants) for Agent Host Copilot terminal confirmations, which arrive without pre-computed actions.
  • Add ITerminalChatService.getAutoApproveActions: parse the command with TreeSitterCommandParser, evaluate sub-commands with CommandLineAutoApprover against persisted configuration rules only (never workbench session rules — the agent host does not consume them), and reuse generateAutoApproveActions so suggestions match the built-in tool.
  • Stamp autoApproveRulesApply tool-call metadata in the Agent Host via SessionPermissionManager.canFutureRuleSuppressPrompt, only when a missing allow rule is the sole blocker: the command parsed, matched no deny rule, and has no unapproved write redirect. Managed approvals, sandbox-bypass prompts, denials, and unparseable commands are never marked, so the dropdown never offers a rule that could not suppress future prompts.
  • Keep getAutoApproval untouched: eligibility re-evaluates the command instead of restructuring the approval path's return type (parse is sub-millisecond, compiled rules are cached).
  • Only generate actions for agent-host-copilotcli sessions when chat.tools.terminal.enableAutoApprove is on, and update the confirmation buttons in place when actions arrive asynchronously, guarded against disposal and already-resolved confirmations.
  • Skip all session-scoped actions (skipSessionScoped): workbench session rules are not forwarded to the Agent Host yet, so offering them would appear to work while later commands still prompt. That half of Agent Host: bring back granular "sticky" terminal auto-approve controls (allow for session / always allow exact command line) #324136 stays open.
  • Known limitation: the Agent Host approver parses with the bash grammar only. For the SDK's powershell tool, PowerShell-specific syntax can yield a suggested rule the bash-grammar enforcement won't match; follow-up is loading tree-sitter-powershell.wasm (already shipped in the same package) in the approver. ----> Agent Host terminal auto-approve should use PowerShell grammar for PowerShell commands #328052
  • Tests: evaluate() outcome table (approved, denied, unknown command, transient env-var, unsafe redirects, parser unavailable), _meta stamping for plain vs sandbox-bypass vs managed confirmations, canFutureRuleSuppressPrompt gates, adapter meta-to-tool-data copy, getAutoApproveActions empty/parse-failure paths, and the skipSessionScoped action snapshot. Follow-up: an electron-browser integration test with real tree-sitter parsing (browser unit suites cannot load the wasm).

Inspirations from:

  • The action-generation input shape ({ subCommandResults, commandLineResult }) and the "only when not auto-approved and auto-approve is enabled" condition come from the built-in tool's call site in commandLineAutoApproveAnalyzer.ts.
  • The suggestion labels and rule construction are reused directly from generateAutoApproveActions rather than reimplemented; this PR only adds the skipSessionScoped option to it.
  • The _meta well-known-key producer pattern (merge into the outgoing state via toToolCallMeta) comes from the existing autoApproveBySetting stamp in agentSideEffects.ts.
  • The policy that auto-approve rules never satisfy sandbox-bypass confirmations comes from the requestSandboxBypass early return in SessionPermissionManager.getAutoApproval and the intentional omission of permissionKind: 'shell' for unsandboxed-command confirmations in copilotAgentSession.ts.

Copilot AI review requested due to automatic review settings July 29, 2026 02:14

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 persistent auto-approve rule actions to Agent Host Copilot terminal confirmations.

Changes:

  • Generates workspace/user rule actions using existing terminal analyzers.
  • Propagates Agent Host metadata to gate eligible confirmations.
  • Adds coverage for action filtering and metadata stamping.
Show a summary per file
File Description
runInTerminalHelpers.test.ts Tests session-action filtering.
runInTerminalHelpers.ts Supports omitting session-scoped actions.
terminalChatService.ts Lazily generates auto-approve actions.
terminal.ts Exposes action-generation API.
chatService.ts Adds rule-applicability terminal metadata.
chatTerminalToolConfirmationSubPart.ts Asynchronously updates confirmation actions.
stateToProgressAdapter.ts Maps Agent Host metadata into terminal data.
agentSideEffects.test.ts Tests metadata stamping.
agentSideEffects.ts Stamps shell-confirmation metadata.
agentToolCallMeta.ts Defines and validates the metadata key.

Review details

  • Files reviewed: 10/10 changed files
  • Comments generated: 3
  • Review effort level: Medium

@github-actions

This comment was marked as low quality.

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.

Review details

Comments suppressed due to low confidence (1)

src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatTerminalToolConfirmationSubPart.ts:233

  • This asynchronous refresh replaces both button DOM nodes. ChatCustomConfirmationWidget.updateButtons removes every child before recreating them (chatConfirmationWidget.ts:426-465), so if a keyboard or screen-reader user has already focused Allow or Skip while tree-sitter is loading, focus is discarded when the actions arrive. Please preserve and restore the focused button (or update the existing Allow control in place) when refreshing the actions.
				confirmWidget.updateButtons(this._createButtons(buildMoreActions()));
  • Files reviewed: 14/14 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@anthonykim1
Anthony Kim (anthonykim1) marked this pull request as ready for review July 29, 2026 18:25
@anthonykim1 Anthony Kim (anthonykim1) changed the title Offer auto-approve rule actions on Agent Host Copilot terminal confirmations Restore user/workspace terminal bash auto-approve actions for Agent Host Copilot Jul 29, 2026
@anthonykim1
Anthony Kim (anthonykim1) merged commit c368512 into main Jul 29, 2026
29 checks passed
@anthonykim1
Anthony Kim (anthonykim1) deleted the anthonykim1/autoApproveJul21 branch July 29, 2026 18:37
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Sep 12, 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.

3 participants