@@ -12,13 +12,14 @@ import { DisposableStore, IDisposable } from '../../../../../base/common/lifecyc
1212import { ResourceSet } from '../../../../../base/common/map.js' ;
1313import { Schemas } from '../../../../../base/common/network.js' ;
1414import { autorun , constObservable , IObservable } from '../../../../../base/common/observable.js' ;
15- import { basename , dirname , isEqualOrParent , relativePath } from '../../../../../base/common/resources.js' ;
15+ import { basename , dirname , isEqualOrParent , joinPath , relativePath } from '../../../../../base/common/resources.js' ;
1616import { ThemeIcon } from '../../../../../base/common/themables.js' ;
1717import { URI } from '../../../../../base/common/uri.js' ;
1818import { localize } from '../../../../../nls.js' ;
1919import { type AgentHostUriMapper , LOCAL_AGENT_HOST_AUTHORITY , toAgentHostContentUri , toAgentHostUri } from '../../../../../platform/agentHost/common/agentHostUri.js' ;
20- import { type IAgentSessionMetadata } from '../../../../../platform/agentHost/common/agent.js' ;
20+ import { AgentSession , type IAgentSessionMetadata } from '../../../../../platform/agentHost/common/agent.js' ;
2121import { affectsAgentHostProviderPreference , IAgentConnection , IAgentHostService , shouldSurfaceLocalAgentHostProvider } from '../../../../../platform/agentHost/common/agentService.js' ;
22+ import { workspacelessScratchDir } from '../../../../../platform/agentHost/common/workspacelessScratchDir.js' ;
2223import type { AgentCustomization , ISessionGitState } from '../../../../../platform/agentHost/common/state/sessionState.js' ;
2324import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js' ;
2425import { IInstantiationService } from '../../../../../platform/instantiation/common/instantiation.js' ;
@@ -34,13 +35,15 @@ import { IPreparedNewSession, ISessionsProviderAutomations, type ISessionsProvid
3435import { WorkspaceNotTrustedError } from '../../../../services/sessions/common/sessionsManagement.js' ;
3536import { IAgentHostActiveClientService } from '../../../../../workbench/contrib/chat/browser/agentSessions/agentHost/agentHostActiveClientService.js' ;
3637import { IChatWidgetService } from '../../../../../workbench/contrib/chat/browser/chat.js' ;
37- import { getCopilotCliSessionRawId , migratedCopilotCliResource } from '../../../../../workbench/contrib/chat/browser/copilotCliEventsUri.js' ;
38+ import { buildLocalSessionStateUri , getCopilotCliSessionRawId , migratedCopilotCliResource } from '../../../../../workbench/contrib/chat/browser/copilotCliEventsUri.js' ;
3839import { adoptLegacyCopilotCliResource , isLegacyMigrationEnabledAtStartup , LEGACY_MIGRATION_RESTORE_TIMEOUT_MS , LEGACY_MIGRATION_TIMEOUT_MS } from '../../../../../workbench/contrib/chat/browser/agentSessions/agentHost/agentHostLegacyMigration.js' ;
3940import { IChatService } from '../../../../../workbench/contrib/chat/common/chatService/chatService.js' ;
4041import { IChatSessionsService } from '../../../../../workbench/contrib/chat/common/chatSessionsService.js' ;
4142import { ILanguageModelsService , type ILanguageModelChatMetadata } from '../../../../../workbench/contrib/chat/common/languageModels.js' ;
4243import { IWorkbenchEnvironmentService } from '../../../../../workbench/services/environment/common/environmentService.js' ;
4344import { isAgentHostProvider , LOCAL_AGENT_HOST_PROVIDER_ID , type IAgentHostSessionsProvider } from '../../../../common/agentHostSessionsProvider.js' ;
45+ import { IPathService } from '../../../../../workbench/services/path/common/pathService.js' ;
46+ import { ResourceLabelHomeStore } from '../../../../../workbench/services/label/common/resourceLabelHomeStore.js' ;
4447import { buildAgentHostSessionWorkspace , readBranchProtectionPatterns } from '../../../../common/agentHostSessionWorkspace.js' ;
4548import { IDevContainerAgentHostService } from '../../../../common/devContainerAgentHostService.js' ;
4649import { ChatModelSource , IGitHubInfo , ISession , ISessionWorkspace , ISessionWorkspaceBrowseAction , SESSION_WORKSPACE_GROUP_LOCAL } from '../../../../services/sessions/common/session.js' ;
@@ -118,6 +121,7 @@ export class LocalAgentHostSessionsProvider extends BaseAgentHostSessionsProvide
118121 private _automationSessionResources = new ResourceSet ( ) ;
119122 private readonly _devContainerAvailableDrafts = new Set < string > ( ) ;
120123 private readonly _devContainerDrafts = new Set < string > ( ) ;
124+ private readonly _resourceLabelHomes : ResourceLabelHomeStore ;
121125
122126 override get order ( ) : number {
123127 return - 1 ;
@@ -172,8 +176,10 @@ export class LocalAgentHostSessionsProvider extends BaseAgentHostSessionsProvide
172176 @IWorkspaceTrustRequestService private readonly _workspaceTrustRequestService : IWorkspaceTrustRequestService ,
173177 @IDevContainerAgentHostService private readonly _devContainerAgentHostService : IDevContainerAgentHostService ,
174178 @ISessionsProvidersService private readonly _sessionsProvidersService : ISessionsProvidersService ,
179+ @IPathService pathService : IPathService ,
175180 ) {
176181 super ( chatSessionsService , chatService , chatWidgetService , languageModelsService , _configurationService , logService , gitHubService , instantiationService , sessionsService , activeClientService , storageService , dialogService , workspaceTrustManagementService ) ;
182+ this . _resourceLabelHomes = this . _register ( instantiationService . createInstance ( ResourceLabelHomeStore ) ) ;
177183 const legacyAutomations = this . _register ( instantiationService . createInstance ( AutomationStore , providerAutomationStorageKey ( this . id ) ) ) ;
178184 const automations = this . _register ( instantiationService . createInstance ( ReconnectableAgentHostAutomationStore , this . id , legacyAutomations , {
179185 toHost : resource => resource ,
@@ -194,6 +200,35 @@ export class LocalAgentHostSessionsProvider extends BaseAgentHostSessionsProvide
194200 // started and the first `listSessions()` round-trip (gated on
195201 // authentication settling below) reconciles them.
196202 this . _enableSessionCachePersistence ( LOCAL_AGENT_HOST_CACHED_SESSIONS_STORAGE_KEY , LOCAL_AGENT_HOST_CACHED_SESSIONS_STORAGE_KEY_LEGACY ) ;
203+
204+ const updateResourceLabelHomes = ( ) => {
205+ const homes = this . getResourceLabelHomes ( ) ;
206+ const userHome = pathService . userHome ( { preferLocal : true } ) ;
207+ const sessionStateRoot = buildLocalSessionStateUri ( userHome ) ;
208+ for ( const session of this . getKnownSessions ( ) ) {
209+ const rawId = AgentSession . id ( session . resource ) ;
210+ const label = this . getResourceLabelHomeLabel ( session ) ;
211+ if ( session . isQuickChat ?. get ( ) && ( session . sessionType === 'copilotcli' || session . sessionType === 'claude' ) ) {
212+ homes . push ( { uri : workspacelessScratchDir ( userHome , rawId ) , label } ) ;
213+ }
214+ if ( session . sessionType === 'copilotcli' ) {
215+ homes . push ( { uri : joinPath ( sessionStateRoot , rawId ) , label } ) ;
216+ for ( const artifact of session . artifacts ?. get ( ) ?? [ ] ) {
217+ if ( ! artifact . uri || ! isEqualOrParent ( artifact . uri , sessionStateRoot ) ) {
218+ continue ;
219+ }
220+ const artifactSessionId = relativePath ( sessionStateRoot , artifact . uri ) ?. split ( '/' ) [ 0 ] ;
221+ if ( artifactSessionId ) {
222+ homes . push ( { uri : joinPath ( sessionStateRoot , artifactSessionId ) , label } ) ;
223+ }
224+ }
225+ }
226+ }
227+ this . _resourceLabelHomes . set ( homes ) ;
228+ } ;
229+ this . _register ( this . _onDidChangeSessionsImmediately ( updateResourceLabelHomes ) ) ;
230+ this . _register ( this . _onDidChangeDraftSessions . event ( updateResourceLabelHomes ) ) ;
231+ updateResourceLabelHomes ( ) ;
197232 this . _register ( autorun ( reader => {
198233 this . _automationSessionResources = new ResourceSet ( this . automations . runs . read ( reader ) . flatMap ( run => run . sessionResource ? [ run . sessionResource ] : [ ] ) ) ;
199234 const changed = this . syncAutomationSessionMarkers ( this . _sessionCache . values ( ) ) ;
0 commit comments