Skip to content

Allow agent host copilot cli to use selection text and range #314245

Merged
anthonykim1 merged 14 commits intomainfrom
anthonykim1/agentHost-selection-attachment
May 7, 2026
Merged

Allow agent host copilot cli to use selection text and range #314245
anthonykim1 merged 14 commits intomainfrom
anthonykim1/agentHost-selection-attachment

Conversation

@anthonykim1
Copy link
Copy Markdown
Contributor

@anthonykim1 anthonykim1 commented May 4, 2026

Resolves: #314184

After PR:
Screenshot 2026-05-04 at 7 55 34 PM

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

/cc @DonJayamanne

@anthonykim1 anthonykim1 added this to the 1.120.0 milestone May 4, 2026
@anthonykim1 anthonykim1 self-assigned this May 4, 2026
Copilot AI review requested due to automatic review settings May 4, 2026 21:39
@anthonykim1 anthonykim1 moved this to In Progress in Agent Host Protocol May 4, 2026
@github-actions

This comment was marked as 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

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

Comment thread src/vs/platform/agentHost/node/agentSideEffects.ts
Comment thread src/vs/platform/agentHost/common/state/protocol/state.ts
Comment thread src/vs/platform/agentHost/node/protocolServerHandler.ts Outdated
Comment thread src/vs/platform/agentHost/node/agentSideEffects.ts
@anthonykim1 anthonykim1 force-pushed the anthonykim1/agentHost-selection-attachment branch from c764905 to a156414 Compare May 4, 2026 22:09
@anthonykim1 anthonykim1 closed this May 4, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Agent Host Protocol May 4, 2026
@anthonykim1 anthonykim1 reopened this May 4, 2026
@anthonykim1 anthonykim1 marked this pull request as ready for review May 5, 2026 02:54
@anthonykim1 anthonykim1 moved this from Done to In Progress in Agent Host Protocol May 5, 2026
Comment thread src/vs/platform/agentHost/node/agentSideEffects.ts Outdated
@anthonykim1 anthonykim1 marked this pull request as draft May 6, 2026 23:07
@anthonykim1 anthonykim1 marked this pull request as ready for review May 7, 2026 03:10
@anthonykim1 anthonykim1 requested a review from connor4312 May 7, 2026 03:10
@anthonykim1 anthonykim1 enabled auto-merge (squash) May 7, 2026 04:03
@anthonykim1 anthonykim1 merged commit 5af88b2 into main May 7, 2026
26 checks passed
@anthonykim1 anthonykim1 deleted the anthonykim1/agentHost-selection-attachment branch May 7, 2026 04:09
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Agent Host Protocol May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

AgentHost: Selection attachments drop selected text and range

4 participants