[STACKED] agentHost: correctly rewrite links in markdown for remote files#311041
[STACKED] agentHost: correctly rewrite links in markdown for remote files#311041connor4312 merged 5 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves how Agent Host–provided content is represented in the chat UI by (a) rewriting remote-resource markdown links so they resolve through the vscode-agent-host:// filesystem mapping, and (b) enhancing write-permission confirmations to carry richer “before/after” content URIs for diff previews.
Changes:
- Rewrite markdown link targets in agent-host streamed/history content to
vscode-agent-host://<authority>/...while preserving code spans/blocks. - Add support for diff previews during write-permission confirmations via a
pending-edit-content:in-memory filesystem and new “content URI” fields for modified-files confirmations. - Extend chat reference/opening logic to prefer explicit original/modified content URIs when opening diffs.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/test/browser/agentSessions/stateToProgressAdapter.test.ts | Adds coverage for markdown link rewriting (including code fence/codespan exclusions) and updates helpers for new adapter signatures. |
| src/vs/workbench/contrib/chat/common/chatService/chatService.ts | Extends chat reference/modified-files confirmation data to support explicit original/modified content URIs for diff rendering. |
| src/vs/workbench/contrib/chat/browser/widget/chatContentParts/toolInvocationParts/chatModifiedFilesConfirmationSubPart.ts | Uses new content URI fields when opening single diffs and multi-diff views. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/stateToProgressAdapter.ts | Implements markdown link rewriting via marked + toAgentHostUri, threads connectionAuthority through adapters, and maps pending edits into modified-files confirmations. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionListController.ts | Tightens diffs parameter typing to readonly. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts | Threads connectionAuthority into adapter calls so rewritten URIs can be produced. |
| src/vs/sessions/common/agentHostDiffs.ts | Switches to protocol ISessionFileDiff typing for diff-to-change conversion helpers. |
| src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts | Reduces flakiness by awaiting tool_ready progress explicitly. |
| src/vs/platform/agentHost/node/copilot/pendingEditContentStore.ts | Introduces pending-edit-content: scheme + provider registration helper for transient “after” content. |
| src/vs/platform/agentHost/node/copilot/copilotToolDisplay.ts | Adjusts permission display link formatting. |
| src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts | Builds write-permission edit previews by writing “after” content into pending-edit-content: and emitting edits with diff counts. |
| src/vs/platform/agentHost/node/copilot/copilotAgent.ts | Updates session config typing to ResumeSessionConfig. |
| src/vs/platform/agentHost/node/agentHostServerMain.ts | Registers the pending-edit-content: in-memory provider. |
| src/vs/platform/agentHost/node/agentHostMain.ts | Registers the pending-edit-content: in-memory provider. |
| src/vs/platform/agentHost/node/agentEventMapper.ts | Maps edits onto the tool-ready action payload. |
| src/vs/platform/agentHost/common/state/protocol/.ahp-version | Bumps protocol version pointer. |
| src/vs/platform/agentHost/common/agentService.ts | Extends IAgentToolReadyEvent to include optional edits preview data. |
Copilot's findings
- Files reviewed: 17/17 changed files
- Comments generated: 4
| @@ -1132,7 +1132,7 @@ export class AgentHostSessionHandler extends Disposable implements IChatSessionC | |||
| ? tc.invocationMessage | |||
| : new MarkdownString(tc.invocationMessage.markdown); | |||
| this._reviveTerminalIfNeeded(existing, tc, ctx.backendSession); | |||
| updateRunningToolSpecificData(existing, tc); | |||
| updateRunningToolSpecificData(existing, tc, this._config.connectionAuthority); | |||
There was a problem hiding this comment.
In _updateToolCallState, the Running || PendingResultConfirmation branch still constructs new MarkdownString(tc.invocationMessage.markdown) directly. That bypasses the new markdown link rewriting, and for PendingResultConfirmation it’s currently the only place that sets invocationMessage (since updateRunningToolSpecificData returns early unless status is Running). Consider reusing the same markdown-to-IMarkdownString helper that applies rewriteMarkdownLinks (or adjusting updateRunningToolSpecificData to handle PendingResultConfirmation) so remote file:/agenthost-content: links continue to resolve correctly in this state too.
See below for a potential fix:
const updatedInvocation = toolCallStateToInvocation(tc, undefined, ctx.backendSession, this._config.connectionAuthority);
existing.invocationMessage = updatedInvocation.invocationMessage;
The merge-base changed after approval.
The merge-base changed after approval.
Stacked on #311025, but we don't have stacked PRs enabled for vscode yet 😓 . Just review the commit matching the PR title.