import { CancellationToken } from "../../../../../../base/common/cancellation.js"; import { Event } from "../../../../../../base/common/event.js"; import { Disposable, IDisposable } from "../../../../../../base/common/lifecycle.js"; import { ResourceSet } from "../../../../../../base/common/map.js"; import { URI } from "../../../../../../base/common/uri.js"; import { type ITextModel } from "../../../../../../editor/common/model.js"; import { IModelService } from "../../../../../../editor/common/services/model.service.js"; import { IConfigurationService } from "../../../../../../platform/configuration/common/configuration.service.js"; import { IExtensionDescription } from "../../../../../../platform/extensions/common/extensions.js"; import { IFileService } from "../../../../../../platform/files/common/files.service.js"; import { IInstantiationService } from "../../../../../../platform/instantiation/common/instantiation.js"; import { ILabelService } from "../../../../../../platform/label/common/label.service.js"; import { ILogService } from "../../../../../../platform/log/common/log.service.js"; import { IStorageService } from "../../../../../../platform/storage/common/storage.service.js"; import { ITelemetryService } from "../../../../../../platform/telemetry/common/telemetry.service.js"; import { IUserDataProfileService } from "../../../../../services/userDataProfile/common/userDataProfile.service.js"; import { IResolvedPromptSourceFolder } from "../config/promptFileLocations.js"; import { PromptsType } from "../promptTypes.js"; import { PromptFilesLocator } from "../utils/promptFilesLocator.js"; import { ParsedPromptFile } from "../promptFileParser.js"; import { IAgentSource, IChatPromptSlashCommand, IConfiguredHooksInfo, ICustomAgent, IBuiltinPromptPath, IPromptPath, IAgentSkill, IInstructionFile, PromptsStorage, IPromptFileContext, IPromptFileResource, IPromptDiscoveryInfo, IAgentInstructionFile, Logger, IResolvedChatPromptSlashCommand } from "./promptsService.js"; import { IPromptsService } from "./promptsService.service.js"; import { ChatRequestHooks } from "../hookSchema.js"; import { IWorkspaceContextService } from "../../../../../../platform/workspace/common/workspace.service.js"; import { IWorkspaceTrustManagementService } from "../../../../../../platform/workspace/common/workspaceTrust.service.js"; import { IPathService } from "../../../../../services/path/common/pathService.js"; import { IAgentPluginService } from "../../plugins/agentPluginService.service.js"; /** * Provides prompt services. */ export declare class PromptsService extends Disposable implements IPromptsService { readonly logger: ILogService; private readonly labelService; private readonly modelService; protected readonly instantiationService: IInstantiationService; private readonly userDataService; protected readonly configurationService: IConfigurationService; protected readonly fileService: IFileService; private readonly storageService; private readonly telemetryService; private readonly workspaceService; protected readonly pathService: IPathService; private readonly agentPluginService; private readonly workspaceTrustService; readonly _serviceBrand: undefined; /** * Bounds how many prompt files discovery reads in parallel. * * Owned by the service rather than created per invocation on purpose: an * invalidation clears the cached discovery promise without cancelling the * computation it was tracking, so several passes can run at once. A limiter * per invocation would give each pass its own quota and the aggregate would * still grow with the number of passes, which is the exhaustion this bound * exists to prevent. */ private readonly _discoveryLimiter; /** * Queues a discovery file read on the shared, service-wide limiter. */ private queueDiscoveryRead; /** * Prompt files locator utility. */ private readonly fileLocator; /** * Cached agent discovery info. */ private readonly cachedCustomAgents; /** * Cached slash command discovery info. */ private readonly cachedSlashCommands; /** * Cached hooks. Invalidated when hook files change. */ private readonly cachedHooks; /** * Cached skill discovery info. */ private readonly cachedSkills; /** * Cached instructions. */ private readonly cachedInstructions; private readonly agentInstructionsWatcher; private readonly _onDidChangeAgentInstructions; /** * Synchronous mirror of the names exposed by {@link getPromptSlashCommands}, * maintained for {@link hasPromptSlashCommand} so callers (e.g. the chat request * parser) can disambiguate `:` vs bare `` without an async hop. */ private readonly knownPromptSlashCommandNames; /** * Cache for parsed prompt files keyed by URI. * The number in the returned tuple is textModel.getVersionId(), which is an internal VS Code counter that increments every time the text model's content changes. */ private readonly cachedParsedPromptFromModels; /** * Cached file locations commands. Caching only happens if the corresponding `fileLocatorEvents` event is used. */ private readonly cachedFileLocations; /** * Lazily created events that notify listeners when the file locations for a given prompt type change. * An event is created on demand for each prompt type and can be used by consumers to react to updates * in the set of prompt files (e.g., when prompt files are added, removed, or modified). */ private readonly fileLocatorEvents; /** * Owns the registry of extension-contributed prompt files (both via * contribution points and via provider API). */ private readonly extensionPromptFiles; private readonly _onDidPluginPromptFilesChange; private readonly _onDidPluginHooksChange; private _pluginPromptFilesByType; constructor(logger: ILogService, labelService: ILabelService, modelService: IModelService, instantiationService: IInstantiationService, userDataService: IUserDataProfileService, configurationService: IConfigurationService, fileService: IFileService, storageService: IStorageService, telemetryService: ITelemetryService, workspaceService: IWorkspaceContextService, pathService: IPathService, agentPluginService: IAgentPluginService, workspaceTrustService: IWorkspaceTrustManagementService); private watchPluginPromptFilesForType; protected createPromptFilesLocator(): PromptFilesLocator; private getFileLocatorEvent; getParsedPromptFile(textModel: ITextModel): ParsedPromptFile; listPromptFiles(type: PromptsType, token: CancellationToken): Promise; private computeListPromptFiles; /** * Collects diagnostic information about which source folders were searched for display in the debug panel. */ private _collectSourceFolderDiagnostics; /** * Registers a prompt file provider (CustomAgentProvider, InstructionsProvider, or PromptFileProvider). * This will be called by the extension host bridge when * an extension registers a provider via vscode.chat.registerCustomAgentProvider(), * registerInstructionsProvider(), or registerPromptFileProvider(). */ registerPromptFileProvider(extension: IExtensionDescription, type: PromptsType, provider: { onDidChangePromptFiles?: Event; providePromptFiles: (context: IPromptFileContext, token: CancellationToken) => Promise; }): IDisposable; listPromptFilesForStorage(type: PromptsType, storage: PromptsStorage, token: CancellationToken, root?: URI): Promise; private getExtensionPromptFiles; /** * Returns the built-in prompt files of the given type. The base service ships * no built-in prompts; subclasses (e.g. the Agents app) override this to * contribute bundled prompts such as built-in skills. */ protected getBuiltinPromptFiles(type: PromptsType, token: CancellationToken): Promise; /** Notifies discovery and slash-command consumers when a subclass changes its built-in prompt files. */ protected get onDidChangeBuiltinPromptFiles(): Event; getSourceFolders(type: PromptsType): Promise; getResolvedSourceFolders(type: PromptsType): Promise; private areStandalonePromptFilesBlocked; private areAgentHooksAllowed; /** * Emitter for slash commands change events. */ get onDidChangeSlashCommands(): Event; getPromptSlashCommands(token: CancellationToken): Promise; /** * Computes discovery info for slash commands, combining prompts and skills. */ private computeSlashCommandDiscoveryInfo; /** * Derives IChatPromptSlashCommand[] from cached discovery info. */ private slashCommandsFromDiscoveryInfo; isValidSlashCommandName(command: string): boolean; hasPromptSlashCommand(name: string): boolean; private knownPromptSlashCommandsHydrationStarted; private refreshKnownPromptSlashCommandNames; resolvePromptSlashCommand(name: string, sessionType: string | undefined, token: CancellationToken): Promise; private asChatPromptSlashCommand; getPromptSlashCommandName(uri: URI, token: CancellationToken): Promise; /** * Emitter for custom agents change events. */ get onDidChangeCustomAgents(): Event; get onDidChangeInstructions(): Event; get onDidChangeAgentInstructions(): Event; getCustomAgents(token: CancellationToken): Promise; /** * Derives ICustomAgent[] from cached discovery info. */ private agentsFromDiscoveryInfo; private computeAgentDiscoveryInfo; parseNew(uri: URI, token: CancellationToken): Promise; registerContributedFile(type: PromptsType, uri: URI, extension: IExtensionDescription, name?: string, description?: string, when?: string, sessionTypes?: readonly string[]): IDisposable; getPromptLocationLabel(promptPath: IPromptPath): string; listNestedAgentMDs(token: CancellationToken): Promise; listAgentInstructions(token: CancellationToken, logger: Logger | undefined): Promise; getVoiceInstructions(token: CancellationToken): Promise; getDictationInstructions(token: CancellationToken): Promise; private getSpeechInstructions; getAgentFileURIFromModeFile(oldURI: URI): URI | undefined; private readonly disabledPromptsStorageKeyPrefix; getDisabledPromptFiles(type: PromptsType): ResourceSet; setDisabledPromptFiles(type: PromptsType, uris: ResourceSet): void; private sanitizeAgentSkillText; private truncateAgentSkillName; private truncateAgentSkillDescription; get onDidChangeSkills(): Event; get onDidChangeHooks(): Event; findAgentSkills(token: CancellationToken): Promise; /** * Derives IAgentSkill[] from cached discovery info. */ private skillsFromDiscoveryInfo; /** * Computes the full skill discovery info, including source folders and telemetry. */ private computeSkillDiscovery; getHooks(token: CancellationToken): Promise; getDiscoveryInfo(type: PromptsType, token: CancellationToken): Promise; getInstructionFiles(token: CancellationToken): Promise; private instructionsFromDiscoveryInfo; private withPromptPathMetadata; private computeInstructionFiles; private computeHooks; /** * Precedence used when deduplicating skills that share the same canonical * name: workspace > personal > plugin > extension API > extension contribution. * Lower numbers win. */ private getSkillPriority; /** * Returns the discovery results for skill files. */ private computeSkillDiscoveryInfo; private getInstructionsDiscoveryInfo; } export declare namespace CustomAgent { function fromParsedPromptFile(ast: ParsedPromptFile, extra: { name?: string; description?: string; source: IAgentSource; hooks?: ChatRequestHooks; sessionTypes: readonly string[] | undefined; enabled: boolean; }): ICustomAgent; }