Skip to content

Add sandbox policy reports to Copilot agent sessions - #335918

Open
Dileep Yavanmandha (dileepyavan) wants to merge 1 commit into
mainfrom
DileepY/sandbox_diagnostics
Open

Add sandbox policy reports to Copilot agent sessions#335918
Dileep Yavanmandha (dileepyavan) wants to merge 1 commit into
mainfrom
DileepY/sandbox_diagnostics

Conversation

@dileepyavan

@dileepyavan Dileep Yavanmandha (dileepyavan) commented Sep 12, 2026

Copy link
Copy Markdown
Member

Summary

20260912-0056-47.9836396.mp4

Add /sandbox-policy to Copilot agent-host sessions. The VS Code command invokes the SDK's existing /sandbox policy command and presents its effective policy as a persisted Markdown report, without starting a model turn or changing sandbox enforcement.

User experience

  • Offer /sandbox-policy in slash-command completion while keeping native /sandbox subcommands hidden.
  • Show an Open Sandbox Policy link in the response that opens the formatted report in Markdown preview.
  • Use normal theme-aware chat link colors, including hover and active states.
  • Support mouse, Enter, and Space activation, with accessible-help guidance.
  • Save a unique report for each invocation so earlier links continue to show their original snapshots.

Implementation

  • Introduce optional host-side getInvocation and getOutput hooks on resolved slash commands, separate from SDK catalog metadata. Omitted hooks or hooks returning undefined preserve the existing SDK invocation and output behavior.
  • Support structured text and link output with optional Markdown and preview flags. Keep command lifecycle, mode handling, and runtime-settings invalidation in the session.
  • Keep sandbox-specific argument validation, SDK mapping, policy formatting, and report persistence in CopilotSandboxPolicyDisplay.
  • Strip ANSI styling, preserve SDK Markdown, format recognized terminal policy reports, and safely fence unrecognized plain text. Propagate invocation and file-write failures instead of emitting broken links.
  • Preserve preview metadata across local and remote Agent Host URI rewriting without passing it to filesystem providers.
  • Extract a reusable single-anchor rendering helper to avoid a second anchor scan. Repeated decoration does not register duplicate widgets or listeners.
  • Reuse the shared SDK command type in completion handling.

Compatibility

  • Existing commands retain their default invocation and rendering when no custom behavior applies.
  • Preserve native sandbox aliases and raw SDK input; do not format unrelated sandbox subcommands or client commands as policy reports.
  • Reserve the host alias against runtime name collisions and keep it discoverable when SDK command discovery fails.
  • No SDK dependency changes, new permissions, or sandbox-policy enforcement changes.

Validation

  • 803 targeted tests passed across Copilot session, command-handler, completion, Markdown rendering, inline-anchor, URI adapter, and accessibility-help suites.
  • Regression coverage includes local/remote preview links, rich links enabled/disabled, keyboard activation, report formatting and persistence, error propagation, optional-hook fallbacks, and duplicate-widget prevention.
  • A 1,001-link regression test verifies a single anchor scan with 1,000 ordinary links and one preview link.
  • Core typecheck and transpile watchers completed with zero errors.
  • ESLint passed for changed refactor files; CSS lint passed with only pre-existing design-token suggestions.
  • Dark and light Component Explorer fixtures render without errors; preview-link colors were checked against regular chat links.
  • git diff --check passed.

Copilot AI balanced review requested due to automatic review settings September 12, 2026 01:01

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.

Copilot review overview

🟡 Changes recommended

Output hooks can skip cache invalidation or discard custom output, and accessibility help omits Space activation.

Get a fresh assessment by requesting another Copilot review.

Review tier: Balanced
Findings: 2 Medium severity · 1 Low severity

Open findings (3)
What changed in this PR

Adds persisted, previewable sandbox-policy reports to Copilot Agent Host sessions.

Changes:

  • Adds /sandbox-policy command handling, formatting, and persistence.
  • Adds Markdown-preview link rendering with URI rewriting and keyboard support.
  • Adds extensive completion, lifecycle, rendering, accessibility, and persistence tests.
File Description
chatWidget.fixture.ts Adds sandbox-policy link fixture.
chatMarkdownContentPart.test.ts Tests preview links and anchor scanning.
chatInlineAnchorWidget.test.ts Tests rendering and activation.
stateToProgressAdapter.test.ts Tests preview metadata preservation.
chatAccessibilityHelp.test.ts Tests accessibility guidance.
chatInlineAnchorWidget.css Adds theme-aware preview-link colors.
chatMarkdownDecorationsRenderer.ts Renders preview anchors during decoration.
chatInlineAnchorWidget.ts Adds filtered rendering and preview activation.
stateToProgressAdapter.ts Preserves metadata across URI rewriting.
chatAccessibilityHelp.ts Documents sandbox-policy usage.
copilotSlashCommandCompletionProvider.test.ts Tests command discovery and collisions.
copilotSlashCommand.test.ts Tests hooks and output rendering.
copilotAgentSession.test.ts Tests policy command lifecycle and persistence.
copilotSlashCommandProvider.ts Adds host command and handler resolution.
copilotSlashCommandCompletionProvider.ts Reuses shared command metadata type.
copilotSlashCommand.ts Defines command hooks and structured output.
copilotSandboxPolicyDisplay.ts Formats and persists policy reports.
copilotAgentSession.ts Integrates invocation and output hooks.
copilotAgent.ts Updates provider construction.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

this._logService.error(err, `[Copilot:${this.sessionId}] rpc.commands.invoke(${slashCommand.command}) failed`);
throw err;
}
const output = await runtimeSlashCommand.getOutput?.(slashCommand.rest, result);
throw err;
}
const output = await runtimeSlashCommand.getOutput?.(slashCommand.rest, result);
const renderedOutput = output ? renderCopilotSlashCommandOutput(output) : undefined;
content.push(localize('workbench.action.openAgentsWindow', 'To open the Agents Window, invoke the Open Agents Window command{0}. In screen reader mode, this keybinding includes Alt to avoid conflicts with screen reader shortcuts.', '<keybinding:workbench.action.openAgentsWindow>'));
content.push(localize('workbench.action.chat.openAgentHostFolderPicker', 'When starting an agent session in a multi-root workspace, you can choose which root folder it runs in by invoking the Folder command{0}, then selecting a folder from the list.', '<keybinding:workbench.action.chat.openAgentHostFolderPicker>'));
content.push(localize('chat.agentHostApprovalsPicker', 'When an agent session exposes approval presets, use Tab to reach the Approvals picker and choose how it handles workspace access, commands, and the internet.'));
content.push(localize('chat.agentHostSandboxPolicy', "In Copilot agent-host sessions, use /sandbox-policy to view the effective sandbox policy. In the response, use Tab to focus Open Sandbox Policy and Enter to open the formatted report."));
@github-actions

Copy link
Copy Markdown
Contributor

Screenshot Changes

Base: 298764bb Current: 74fc1842

3 insignificant change(s) omitted (≤20 px, Δ≤2). See CI logs for details.

Added (2)

chat/widget/chatWidget/SandboxPolicyLink/Dark

current

chat/widget/chatWidget/SandboxPolicyLink/Light

current

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants