Skip to content

Add shellIntegrationNonce support to TerminalOptions and ExtensionTerminalOptions#253008

Merged
Tyriar merged 7 commits intomainfrom
copilot/fix-190253
Aug 11, 2025
Merged

Add shellIntegrationNonce support to TerminalOptions and ExtensionTerminalOptions#253008
Tyriar merged 7 commits intomainfrom
copilot/fix-190253

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 30, 2025

This PR implements support for custom shell integration nonces in VS Code terminals, allowing extensions to enable shell integration features for shells that VS Code doesn't natively support.

Problem

Previously, the VSCODE_NONCE environment variable was only available for VS Code's natively supported shells (bash, zsh, pwsh, etc.). This prevented extensions like Julia from implementing shell integration features because:

  1. Shell integration injection would fail for unsupported shells
  2. No VSCODE_NONCE environment variable would be set
  3. Extensions couldn't send trusted shell integration sequences

Solution

Added a new optional shellIntegrationNonce property to both TerminalOptions and ExtensionTerminalOptions interfaces, enabling extensions to provide their own nonce for shell integration.

API Changes

export interface TerminalOptions {
  // ... existing properties
  shellIntegrationNonce?: string;
}

export interface ExtensionTerminalOptions {
  // ... existing properties  
  shellIntegrationNonce?: string;
}

Usage Example

// Extensions can now enable shell integration for any shell:
const terminal = vscode.window.createTerminal({
  name: 'Julia REPL',
  shellPath: '/usr/bin/julia',
  shellArgs: ['-i'],
  shellIntegrationNonce: 'custom-nonce-12345'
});

// The VSCODE_NONCE environment variable will be available
// in the terminal, allowing shell integration sequences:
// print("\x1b]633;A;$(ENV["VSCODE_NONCE"])\x07")

Implementation Details

  1. API Extension: Added shellIntegrationNonce to VS Code's public API
  2. Flow Implementation: Nonce passes through ExtHost → MainThread → Terminal Process
  3. Critical Fix: Modified terminal process to set VSCODE_NONCE environment variable even when shell integration injection fails for unsupported shells
  4. Security: Maintains nonce verification model while extending to all shells

Benefits

  • ✅ Extensions can implement shell integration for any shell type
  • ✅ Works with both regular terminals and pseudoterminals
  • ✅ Maintains security through nonce verification
  • ✅ Backward compatible - existing code unchanged
  • ✅ Enables rich terminal features (command detection, decorations, etc.) for custom shells

This enables extensions like Julia to provide the same shell integration capabilities that were previously only available for VS Code's natively supported shells.

Fixes #190253.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Tyriar Tyriar added this to the June 2025 milestone Jun 30, 2025
Copilot AI changed the title [WIP] Shell integration nonce unavailable in unknown shells and Pseudoterminal-based extension terminals Add shellIntegrationNonce support to TerminalOptions and ExtensionTerminalOptions Jun 30, 2025
Copilot AI requested a review from Tyriar June 30, 2025 14:55
@Tyriar Tyriar modified the milestones: June 2025, July 2025 Jun 30, 2025
@Tyriar Tyriar marked this pull request as ready for review August 10, 2025 13:54
@Tyriar Tyriar requested review from jrieken and mjbvz as code owners August 10, 2025 13:54
@Tyriar
Copy link
Copy Markdown
Contributor

Tyriar commented Aug 10, 2025

Verified it works for both types of options.

@Tyriar Tyriar enabled auto-merge August 10, 2025 13:55
Copy link
Copy Markdown
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

API changes lgtm

@Tyriar Tyriar merged commit bbd1961 into main Aug 11, 2025
18 checks passed
@Tyriar Tyriar deleted the copilot/fix-190253 branch August 11, 2025 22:11
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Sep 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell integration nonce unavailable in unknown shells and Pseudoterminal-based extension terminals

4 participants