@@ -8,7 +8,7 @@ import * as l10n from '@vscode/l10n';
88import { createReadStream } from 'node:fs' ;
99import { devNull } from 'node:os' ;
1010import { createInterface } from 'node:readline' ;
11- import type { ChatRequest , ChatSessionItem } from 'vscode' ;
11+ import type { ChatCustomAgent , ChatRequest , ChatSessionItem } from 'vscode' ;
1212import { IChatDebugFileLoggerService } from '../../../../platform/chat/common/chatDebugFileLoggerService' ;
1313import { ConfigKey , IConfigurationService } from '../../../../platform/configuration/common/configurationService' ;
1414import { INativeEnvService } from '../../../../platform/env/common/envService' ;
@@ -18,7 +18,7 @@ import { RelativePattern } from '../../../../platform/filesystem/common/fileType
1818import { ILogService } from '../../../../platform/log/common/logService' ;
1919import { deriveCopilotCliOTelEnv } from '../../../../platform/otel/common/agentOTelEnv' ;
2020import { IOTelService } from '../../../../platform/otel/common/otelService' ;
21- import { ParsedPromptFile } from '../../../../platform/promptFiles/common/promptsService' ;
21+ import { IPromptsService } from '../../../../platform/promptFiles/common/promptsService' ;
2222import { IWorkspaceService } from '../../../../platform/workspace/common/workspaceService' ;
2323import { createServiceIdentifier } from '../../../../util/common/services' ;
2424import { coalesce } from '../../../../util/vs/base/common/arrays' ;
@@ -34,7 +34,6 @@ import { IInstantiationService } from '../../../../util/vs/platform/instantiatio
3434import { ChatRequestTurn2 , ChatResponseTurn2 , ChatSessionStatus , Uri } from '../../../../vscodeTypes' ;
3535import { IPromptVariablesService } from '../../../prompt/node/promptVariablesService' ;
3636import { IAgentSessionsWorkspace } from '../../common/agentSessionsWorkspace' ;
37- import { IChatPromptFileService } from '../../common/chatPromptFileService' ;
3837import { IChatSessionMetadataStore , RequestDetails , StoredModeInstructions } from '../../common/chatSessionMetadataStore' ;
3938import { IChatSessionWorkspaceFolderService } from '../../common/chatSessionWorkspaceFolderService' ;
4039import { IChatSessionWorktreeService } from '../../common/chatSessionWorktreeService' ;
@@ -165,7 +164,7 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
165164 @IOTelService private readonly _otelService : IOTelService ,
166165 @IPromptVariablesService private readonly _promptVariablesService : IPromptVariablesService ,
167166 @IChatDebugFileLoggerService private readonly _debugFileLogger : IChatDebugFileLoggerService ,
168- @IChatPromptFileService private readonly _chatPromptFileService : IChatPromptFileService ,
167+ @IPromptsService private readonly _promptsService : IPromptsService ,
169168 ) {
170169 super ( ) ;
171170 this . monitorSessionFiles ( ) ;
@@ -647,7 +646,7 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
647646 protected async createSessionsOptions ( options : ICreateSessionOptions & { mcpServers ?: SessionOptions [ 'mcpServers' ] } ) : Promise < Readonly < SessionOptions > > {
648647 const [ agentInfos , skillLocations ] = await Promise . all ( [
649648 this . agents . getAgents ( ) ,
650- this . copilotCLISkills . getSkillsLocations ( ) ,
649+ this . copilotCLISkills . getSkillsLocations ( CancellationToken . None ) ,
651650 ] ) ;
652651 const customAgents = agentInfos . map ( i => i . agent ) ;
653652 const variablesContext = this . _promptVariablesService . buildTemplateVariablesContext ( options . sessionId , options . debugTargetSessionIds ) ;
@@ -791,14 +790,14 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
791790 const [ agentId , storedDetails ] = await Promise . all ( [ agentIdPromise , requestDetailsPromise ] ) ;
792791
793792 // Build lookup from copilotRequestId → RequestDetails for the callback
794- const customAgentLookup = this . createCustomAgentLookup ( ) ;
793+ const customAgentLookup = await this . createCustomAgentLookup ( ) ;
795794 const legacyMappings : RequestDetails [ ] = [ ] ;
796795 const detailsByCopilotId = new Map < string , RequestIdDetails > ( ) ;
797- const defaultModeInstructions = agentId ? this . resolveAgentModeInstructions ( agentId , customAgentLookup ) : undefined ;
796+ const defaultModeInstructions = agentId ? await this . resolveAgentModeInstructions ( agentId , customAgentLookup ) : undefined ;
798797
799798 for ( const d of storedDetails ) {
800799 if ( d . copilotRequestId ) {
801- const modeInstructions = d . modeInstructions ?? this . resolveAgentModeInstructions ( d . agentId , customAgentLookup ) ?? defaultModeInstructions ;
800+ const modeInstructions = d . modeInstructions ?? await this . resolveAgentModeInstructions ( d . agentId , customAgentLookup ) ?? defaultModeInstructions ;
802801 detailsByCopilotId . set ( d . copilotRequestId , { requestId : d . vscodeRequestId , toolIdEditMap : d . toolIdEditMap , modeInstructions } ) ;
803802 }
804803 }
@@ -831,36 +830,38 @@ export class CopilotCLISessionService extends Disposable implements ICopilotCLIS
831830 return { history, events } ;
832831 }
833832
834- private createCustomAgentLookup ( ) : Map < string , ParsedPromptFile > {
835- const agents = this . _chatPromptFileService . customAgentPromptFiles ;
836- const lookup = new Map < string , ParsedPromptFile > ( ) ;
833+ private async createCustomAgentLookup ( ) : Promise < Map < string , [ ChatCustomAgent , Lazy < Promise < string > > ] > > {
834+ const agents = await this . _promptsService . getCustomAgents ( CancellationToken . None ) ;
835+ const lookup = new Map < string , [ ChatCustomAgent , Lazy < Promise < string > > ] > ( ) ;
837836 for ( const agent of agents ) {
837+ const lazyContent = new Lazy ( ( ) => this . _promptsService . parseFile ( agent . uri , CancellationToken . None ) . then ( parsed => parsed . body ?. getContent ( ) ?? '' ) ) ;
838838 const keys = [
839- agent . header ?. name ?. trim ( ) ,
839+ agent . name ?. trim ( ) ,
840840 agent . uri . toString ( ) ,
841841 getAgentFileNameFromFilePath ( agent . uri ) ,
842842 ] ;
843843 for ( const key of keys ) {
844844 if ( key && ! lookup . has ( key ) ) {
845- lookup . set ( key , agent ) ;
845+ lookup . set ( key , [ agent , lazyContent ] ) ;
846846 }
847847 }
848848 }
849849 return lookup ;
850850 }
851851
852- private resolveAgentModeInstructions ( agentId : string | undefined , customAgentLookup : Map < string , ParsedPromptFile > ) : StoredModeInstructions | undefined {
852+ private async resolveAgentModeInstructions ( agentId : string | undefined , customAgentLookup : Map < string , [ ChatCustomAgent , Lazy < Promise < string > > ] > ) : Promise < StoredModeInstructions | undefined > {
853853 if ( ! agentId ) {
854854 return undefined ;
855855 }
856- const agent = customAgentLookup . get ( agentId ) ;
857- if ( ! agent ) {
856+ const agentEntry = customAgentLookup . get ( agentId ) ;
857+ if ( ! agentEntry ) {
858858 return undefined ;
859859 }
860+ const [ agent , lazyContent ] = agentEntry ;
860861 return {
861862 uri : agent . uri . toString ( ) ,
862- name : agent . header ?. name ?. trim ( ) || agentId ,
863- content : agent . body ?. getContent ( ) ?? '' ,
863+ name : agent . name ?. trim ( ) || agentId ,
864+ content : await lazyContent . value ,
864865 } ;
865866 }
866867
0 commit comments