Allow agent host copilot cli to use selection text and range #314245
Merged
anthonykim1 merged 14 commits intomainfrom May 7, 2026
Merged
Allow agent host copilot cli to use selection text and range #314245anthonykim1 merged 14 commits intomainfrom
anthonykim1 merged 14 commits intomainfrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Agent Host chat path to carry richer attachment data for selections so Copilot CLI requests can preserve selected text and ranges, aligning the Agent Host flow more closely with the existing chat-panel CLI behavior.
Changes:
- Preserve selection text/range when converting chat variables into Agent Host message attachments.
- Translate the new protocol attachment shape through side effects and Copilot session sending.
- Sync generated agent-host protocol types for richer attachments, completions, and response-part variants.
Show a summary per file
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts |
Updates chat contribution tests for resource-style attachments and selection metadata. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts |
Converts request variables into richer Agent Host attachments and reads selection text from models. |
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Extends Copilot session tests to assert selection text/range forwarding. |
src/vs/platform/agentHost/test/node/agentSideEffects.test.ts |
Adds coverage for mapping protocol attachment metadata into agent attachments. |
src/vs/platform/agentHost/node/protocolServerHandler.ts |
Registers the new protocol completions request handler. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Forwards selection attachment text/range into the Copilot SDK payload. |
src/vs/platform/agentHost/node/agentSideEffects.ts |
Maps protocol message attachments into IAgentAttachment values for agent backends. |
src/vs/platform/agentHost/common/state/sessionState.ts |
Re-exports the renamed message attachment enum from protocol state. |
src/vs/platform/agentHost/common/state/protocol/state.ts |
Syncs generated protocol state for richer attachments, model metadata, and new response-part kinds. |
src/vs/platform/agentHost/common/state/protocol/messages.ts |
Adds the generated completions command to the protocol message map. |
src/vs/platform/agentHost/common/state/protocol/commands.ts |
Syncs generated protocol command types for completions and richer initialize data. |
src/vs/platform/agentHost/common/state/protocol/.ahp-version |
Bumps the synced agent-host protocol version pointer. |
src/vs/platform/agentHost/common/agentService.ts |
Introduces agent-side attachment enums and selection metadata types. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts:2455
- This has the same worktree mismatch as the earlier location branch: the attachment URI is rebased to the resolved worktree, but the selected text is still read from
v.value.uri. When the worktree copy has diverged from the original workspace file, the agent will receive a worktree path paired with stale selection contents from the wrong file revision.
const attachmentUri = this._rebaseAttachmentUri(uri, request.sessionResource);
const selectionMetadata = isLocation(v.value) ? await this._readSelectionAttachmentMetadata(v.value.uri, v.value.range) : undefined;
- Files reviewed: 13/13 changed files
- Comments generated: 7
c764905 to
a156414
Compare
connor4312
reviewed
May 5, 2026
DonJayamanne
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves: #314184
After PR:

wires selected text/range through the VS Code -> Agent Host -> Copilot SDK path.
We'd prob eventually want: #314248
/cc @DonJayamanne