Skip to content

window: promote chat session focus events to stable API#306518

Closed
RockyWearsAHat wants to merge 6 commits intomicrosoft:mainfrom
RockyWearsAHat:feature/promote-chat-session-events
Closed

window: promote chat session focus events to stable API#306518
RockyWearsAHat wants to merge 6 commits intomicrosoft:mainfrom
RockyWearsAHat:feature/promote-chat-session-events

Conversation

@RockyWearsAHat
Copy link
Copy Markdown

Summary

Promote activeChatSessionUri and onDidChangeActiveChatSession from proposed API to stable window namespace, enabling extensions to react to chat panel focus changes without adopting a proposed API.

Closes #306497

Problem

Extensions that manage per-chat state — such as branch-per-chat workflows, session-scoped terminals, or context-aware tooling — need to know which chat panel the user is interacting with. The activeChatPanelSessionResource and onDidChangeChatPanelActiveSession events exist on ExtHostChatAgents2 but are gated behind a proposed API. This means:

  1. Extensions must enable chatParticipantAdditions proposed API to access the events
  2. Extensions using proposed APIs cannot be published to the Marketplace
  3. The events are not discoverable through standard vscode.window API surface

Approach

Expose two new members on the window namespace, ungated:

// Get the URI of the currently focused chat session (undefined if none)
const uri = vscode.window.activeChatSessionUri;

// React to chat session focus changes
vscode.window.onDidChangeActiveChatSession(uri => {
    console.log('Active chat session:', uri?.toString());
});

Implementation:

  • extHost.api.impl.ts: Added activeChatSessionUri getter and onDidChangeActiveChatSession event to the window namespace object, delegating to extHostChatAgents2.activeChatPanelSessionResource and the corresponding event.
  • vscode.d.ts: Stable type declarations in the window namespace (placed after onDidChangeActiveTerminal for logical grouping with other focus-change events).

Design notes:

  • No proposed API gate — these are stable additions. The underlying implementation already exists and is exercised by the chat participant system.
  • The event reuses the existing ExtHostChatAgents2 infrastructure, so there is no new IPC channel or protocol change.
  • Returns Uri | undefined consistent with other active* properties on window.

Use Cases

  • Branch-per-chat session management: When the user focuses a different chat panel, the extension switches the visible branch/worktree to match that session's context.
  • Session-scoped terminals: An extension can create and show a terminal tied to the active chat session, automatically switching when focus changes.
  • Context-aware tool configuration: MCP servers or tool providers can adjust their behavior based on which chat session is active.
  • Session state persistence: Extensions can save/restore per-session state (open files, cursor positions, debug configs) keyed by chat session URI.

Testing

Manual verification that:

  1. vscode.window.activeChatSessionUri returns the URI of the focused chat panel
  2. vscode.window.onDidChangeActiveChatSession fires when switching between chat panels
  3. Both return undefined when no chat panel is focused

Add activeChatSessionUri getter and onDidChangeActiveChatSession event
to the stable window namespace. These delegate to the existing
extHostChatAgents2 implementation (activeChatPanelSessionResource).

The proposed API versions (chatParticipantPrivate) remain unchanged
for backward compatibility.

Extensions that maintain per-conversation state need to detect chat
session switches without requiring proposed API access and manual
argv.json configuration.

Fixes microsoft#306497
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 promotes chat session focus tracking from a proposed API to the stable vscode.window namespace so extensions can react to chat panel focus/session changes without enabling proposed APIs.

Changes:

  • Add stable vscode.window.activeChatSessionUri to expose the currently active chat session URI (or undefined).
  • Add stable vscode.window.onDidChangeActiveChatSession to notify extensions when the active chat session changes.
  • Wire both stable members to the existing ExtHostChatAgents2 active chat panel session resource and event.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vscode-dts/vscode.d.ts Adds stable type declarations for activeChatSessionUri and onDidChangeActiveChatSession on window.
src/vs/workbench/api/common/extHost.api.impl.ts Implements the new stable window members by delegating to extHostChatAgents2.

Comment thread src/vs/workbench/api/common/extHost.api.impl.ts
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

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/vs/workbench/api/common/extHost.api.impl.ts
…tSession

Verify the window.activeChatSessionUri property and
window.onDidChangeActiveChatSession event are accessible and fire
correctly when a new chat session is opened.
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

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Comment thread extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts Outdated
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

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Comment thread extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts Outdated
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

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Comment thread extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts Outdated
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

Copilot reviewed 2 out of 3 changed files in this pull request and generated no new comments.

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.

Promote chat session focus events to stable API

3 participants