Skip to content

Hide sandbox wrapper from terminal command metadata#309346

Merged
dileepyavan merged 3 commits intomicrosoft:mainfrom
dileepyavan:DileepY/303713_1
Apr 13, 2026
Merged

Hide sandbox wrapper from terminal command metadata#309346
dileepyavan merged 3 commits intomicrosoft:mainfrom
dileepyavan:DileepY/303713_1

Conversation

@dileepyavan
Copy link
Copy Markdown
Member

Summary

Fix terminal command metadata for sandboxed run_in_terminal executions so chat terminal context reports the user-facing command instead of the internal sandbox wrapper.

The terminal tool can rewrite a command into a sandbox-runtime invocation before sending it to the shell. Previously, that rewritten command was also passed into terminal command metadata via setNextCommandId, causing terminal context to show values like:

PATH="$PATH:..." TMPDIR="..." node sandbox-runtime ... -c 'npm --version'

instead of:

npm --version

This change threads an optional metadata command line through the rich terminal execution path. The terminal still executes the rewritten sandbox command, but command detection metadata records the display/original command when sandboxing is enabled.

Changes

  • Add optional commandLineForMetadata to ITerminalInstance.runCommand.
  • Use commandLineForMetadata ?? commandLine for terminal command metadata (setNextCommandId).
  • Thread optional metadata command line through ITerminalExecuteStrategy, RichExecuteStrategy, and ActiveTerminalExecution.
  • Pass the display/original command from RunInTerminalTool when terminal sandboxing is enabled.
  • Add focused test coverage for executing a wrapped command while reporting separate command metadata.

Validation

  • npm run transpile-client
  • ./scripts/test.sh --run src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/richExecuteStrategy.test.ts
    • 2 passing
  • ./scripts/test.sh --run src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/runInTerminalTool.test.ts
    • 154 passing, 105 pending

Fixes #303713

Copilot AI review requested due to automatic review settings April 13, 2026 02:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates terminal execution plumbing so that when run_in_terminal rewrites a command for sandbox execution, terminal command metadata (used for chat terminal context/“Last Command”) records the user-facing/original command instead of the internal sandbox wrapper.

Changes:

  • Adds an optional commandLineForMetadata parameter through the terminal execution stack (ITerminalExecuteStrategy, RichExecuteStrategy, ActiveTerminalExecution, ITerminalInstance.runCommand).
  • Updates TerminalInstance.runCommand to use commandLineForMetadata ?? commandLine when calling setNextCommandId.
  • Adds a focused unit test to ensure rich execution passes separate metadata for wrapped commands.
Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/richExecuteStrategy.test.ts Adds coverage verifying rich execution forwards a separate metadata command line.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts Computes and passes a metadata command line for sandbox-enabled executions.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/richExecuteStrategy.ts Threads metadata command line into ITerminalInstance.runCommand.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/noneExecuteStrategy.ts Updates strategy signature to accept (unused) metadata command line parameter.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/executeStrategy.ts Extends ITerminalExecuteStrategy.execute contract with commandLineForMetadata.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/basicExecuteStrategy.ts Updates strategy signature to accept (unused) metadata command line parameter.
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Adds commandLineForMetadata to runCommand and uses it for command ID metadata.
src/vs/workbench/contrib/terminal/browser/terminal.ts Updates ITerminalInstance.runCommand signature to include commandLineForMetadata.

Copilot's findings

  • Files reviewed: 8/8 changed files
  • Comments generated: 1

@dileepyavan dileepyavan merged commit 108506b into microsoft:main Apr 13, 2026
25 of 26 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.117.0 milestone Apr 13, 2026
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.

Terminal context shows the sandboxed command

3 participants