agentHost: support attaching virtual resources (untitled, notebook cells)#320040
Merged
Conversation
…lls) Consolidates the agent host's permission and virtual-resource services into a single `IAgentHostResourceService` that owns the gated FS surface (`list`/`read`/`write`/`del`/`move`/`copy`/`resolve`/`mkdir`), the permission policy, and an `ITextModelService`-backed fallback for content that isn't on disk. Both the in-process local channel and the remote protocol client's reverse-RPC handler now reduce to a thin wire adapter that dispatches frames to the same service. - Adds a single `IAgentHostResourceService` (platform decorator + types, workbench implementation) replacing `IAgentHostPermissionService` and `IAgentHostVirtualResourceProvider`. - `read`, `write`, and `resolve` (stat) transparently fall back to `ITextModelService` when `IFileService` cannot satisfy the request, so attached untitled documents and notebook cells round-trip end to end. - `AgentHostClientResourceChannel` (local in-process) and `RemoteAgentHostProtocolClient._handleReverseRequest` (remote) shrink to thin adapters that translate JSON-RPC frames into service calls and surface `AgentHostResourcePermissionError` as `PermissionDenied` frames so the host's standard `resourceRequest` -> retry loop still works. - Local agent host short-circuits the permission gate (sentinel address `'local'`): the utility process already has the renderer's FS access, so gating it adds no security and would just produce unprompted denials. - `createAgentHostClientResourceConnection` now exposes `resourceRequest`, completing the local prompt/retry loop. - `agentClientUri` preserves `query` and `fragment` across the round trip and uses a `!` scheme-slot marker to faithfully round-trip opaque-path URIs such as `untitled:Untitled-1`. Fixes #319802 (Commit message generated by Copilot)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR unifies agent-host-facing filesystem access and permission prompting behind a single IAgentHostResourceService, enabling attachments backed by virtual resources (e.g. untitled editors, notebook cells) to round-trip through the agent host.
Changes:
- Introduces
IAgentHostResourceService(platform) andAgentHostResourceService(workbench) to combine permission gating + FS operations, withITextModelServicefallback for non-disk resources. - Refactors both local (in-process) and remote (protocol) reverse-RPC handlers into thin adapters that dispatch to the shared service and translate permission denials into
PermissionDeniedframes. - Improves URI round-tripping via
agentClientUriby preserving query/fragment and supporting opaque-path URIs likeuntitled:Untitled-1.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/workbench.common.main.ts | Switches workbench bootstrap import to the unified resource service. |
| src/vs/workbench/services/agentHost/test/common/agentHostResourceService.test.ts | Updates unit tests to construct/use AgentHostResourceService. |
| src/vs/workbench/services/agentHost/electron-browser/agentHostService.ts | Updates comment to reflect the current remote client implementation name. |
| src/vs/workbench/services/agentHost/common/agentHostResourceService.ts | Implements unified resource service with permission gating + virtual resource fallback. |
| src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostPermissionUiContribution.test.ts | Updates test wiring to stub IAgentHostResourceService. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts | Allows non-file attachments and closes a session-state hydration race. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostPermissionUiContribution.ts | Migrates UI contribution to IAgentHostResourceService. |
| src/vs/sessions/sessions.common.main.ts | Switches sessions bootstrap import to the unified resource service. |
| src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHost.contribution.ts | Updates setting import to new resource service module. |
| src/vs/platform/agentHost/test/electron-browser/remoteAgentHostProtocolClient.test.ts | Reworks protocol client tests around IAgentHostResourceService and permission-denial frames. |
| src/vs/platform/agentHost/test/electron-browser/localAhpJsonlLogging.test.ts | Removes channel-specific logging test now that channel implementation is refactored. |
| src/vs/platform/agentHost/test/common/agentHostClientResourceChannel.test.ts | Adds focused tests for the new resource-channel adapter behavior. |
| src/vs/platform/agentHost/test/common/agentClientUri.test.ts | Adds coverage for query/fragment and opaque-path URI round-tripping. |
| src/vs/platform/agentHost/node/agentService.ts | Avoids masking the original error when a fallback readFile attempt fails. |
| src/vs/platform/agentHost/electron-browser/localAgentHostService.ts | Switches local resource channel registration to DI-created channel (injecting resource service). |
| src/vs/platform/agentHost/common/agentHostResourceService.ts | Adds the new unified platform service contract + permission error type. |
| src/vs/platform/agentHost/common/agentHostPermissionService.ts | Removes the old permission-only service contract. |
| src/vs/platform/agentHost/common/agentHostClientResourceChannel.ts | Refactors local reverse-RPC resource channel to delegate to IAgentHostResourceService. |
| src/vs/platform/agentHost/common/agentClientUri.ts | Preserves query/fragment and supports opaque-path URIs using a scheme-slot marker. |
| src/vs/platform/agentHost/browser/remoteAgentHostProtocolClient.ts | Refactors reverse-RPC handling to dispatch to IAgentHostResourceService. |
Copilot's findings
- Files reviewed: 20/20 changed files
- Comments generated: 2
DonJayamanne
previously approved these changes
Jun 5, 2026
lszomoru
approved these changes
Jun 5, 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.
agentHost: support attaching virtual resources (untitled, notebook cells)Consolidates the agent host's permission and virtual-resource services into a single
IAgentHostResourceServicethat owns the gated FS surface (list/read/write/del/move/copy/resolve/mkdir), the permission policy, and anITextModelService-backed fallback for content that isn't on disk. Both the in-process local channel and the remote protocol client's reverse-RPC handler now reduce to a thin wire adapter that dispatches frames to the same service.- Adds a singleIAgentHostResourceService(platform decorator + types, workbench implementation) replacingIAgentHostPermissionServiceandIAgentHostVirtualResourceProvider.-read,write, andresolve(stat) transparently fall back toITextModelServicewhenIFileServicecannot satisfy the request, so attached untitled documents and notebook cells round-trip end to end.-AgentHostClientResourceChannel(local in-process) andRemoteAgentHostProtocolClient._handleReverseRequest(remote) shrink to thin adapters that translate JSON-RPC frames into service calls and surfaceAgentHostResourcePermissionErrorasPermissionDeniedframes so the host's standardresourceRequest-> retry loop still works.- Local agent host short-circuits the permission gate (sentinel address'local'): the utility process already has the renderer's FS access, so gating it adds no security and would just produce unprompted denials.-createAgentHostClientResourceConnectionnow exposesresourceRequest, completing the local prompt/retry loop.-agentClientUripreservesqueryandfragmentacross the round trip and uses a!scheme-slot marker to faithfully round-trip opaque-path URIs such asuntitled:Untitled-1.Fixes #319802 message generated by Copilot)