2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { CancellationToken } from '../../../../../base/common/cancellation.js';
7
>
import { match, splitGlobAware } from '../../../../../base/common/glob.js';
8
>
import { ResourceMap, ResourceSet } from '../../../../../base/common/map.js';
9
>
import { Schemas } from '../../../../../base/common/network.js';
10
>
import { OperatingSystem } from '../../../../../base/common/platform.js';
11
>
import { basename, dirname } from '../../../../../base/common/resources.js';
12
>
import { URI } from '../../../../../base/common/uri.js';
13
>
import { localize } from '../../../../../nls.js';
14
>
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
15
>
import { IFileService } from '../../../../../platform/files/common/files.js';
16
>
import { ILabelService } from '../../../../../platform/label/common/label.js';
17
>
import { ILogService } from '../../../../../platform/log/common/log.js';
18
>
import { IRemoteAgentService } from '../../../../services/remote/common/remoteAgentService.js';
19
>
import { ITelemetryService } from '../../../../../platform/telemetry/common/telemetry.js';
20
>
import { IWorkspaceContextService } from '../../../../../platform/workspace/common/workspace.js';
21
>
import { ChatRequestVariableSet, IChatRequestVariableEntry, isPromptFileVariableEntry, toPromptFileVariableEntry, toPromptTextVariableEntry, PromptFileVariableKind, IPromptTextVariableEntry, ChatRequestToolReferenceEntry, toToolVariableEntry } from '../attachments/chatVariableEntries.js';
22
>
import { ILanguageModelToolsService, IToolData, VSCodeToolReference } from '../tools/languageModelToolsService.js';
23
>
import { PromptsConfig } from './config/config.js';
24
>
import { isInClaudeAgentsFolder, isInClaudeRulesFolder, isPromptOrInstructionsFile } from './config/promptFileLocations.js';
25
>
import { ParsedPromptFile } from './promptFileParser.js';
26
>
import { AgentInstructionFileType, IAgentSkill, ICustomAgent, IInstructionFile, IPromptsService, matchesSessionType, newInstructionsCollectionEvent, newInstructionsCollectionDebugInfo, type InstructionsCollectionEvent, type InstructionsCollectionDebugInfo } from './service/promptsService.js';
27
>
export type { InstructionsCollectionEvent, InstructionsCollectionDebugInfo } from './service/promptsService.js';
28
>
export { newInstructionsCollectionEvent, newInstructionsCollectionDebugInfo } from './service/promptsService.js';
29
>
import { AGENT_DEBUG_LOG_FILE_LOGGING_ENABLED_SETTING, TROUBLESHOOT_SKILL_PATH } from './promptTypes.js';
30
>
import { OffsetRange } from '../../../../../editor/common/core/ranges/offsetRange.js';
31
>
import { ChatModeKind } from '../constants.js';
32
>
import { UserSelectedTools } from '../participants/chatAgents.js';
33
>
import { hash } from '../../../../../base/common/hash.js';
34
>
import { IAgentPlugin, IAgentPluginService } from '../plugins/agentPluginService.js';
35
>
36
>
export interface InstructionsCollectionResult {
37
>
readonly telemetryEvent: InstructionsCollectionEvent;
38
>
readonly debugInfo: InstructionsCollectionDebugInfo;
39
>
}
40
>
41
>
/**
42
>
* The result of the most recent {@link ComputeAutomaticInstructions.collect} call.
43
>
* Consumed by debug contributions for logging; not sent as telemetry.
44
>
*/
45
>
export let lastInstructionsCollectionResult: InstructionsCollectionResult | undefined;
46
>
47
>
type InstructionsCollectionClassification = {
48
>
applyingInstructionsCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Number of instructions added via pattern matching.' };
49
>
referencedInstructionsCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Number of instructions added via references from other instruction files.' };
50
>
agentInstructionsCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Number of agent instructions added (copilot-instructions.md and agents.md).' };
51
>
listedInstructionsCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Number of instruction patterns added.' };
52
>
totalInstructionsCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Total number of instruction entries added to variables.' };
53
>
claudeRulesCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Number of Claude rules files (.claude/rules/) added via pattern matching.' };
54
>
claudeMdCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Number of CLAUDE.md agent instruction files added.' };
55
>
claudeAgentsCount: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; isMeasurement: true; comment: 'Number of Claude agent files (.claude/agents/) listed as subagents.' };
56
>
owner: 'digitarald';
57
>
comment: 'Tracks automatic instruction collection usage in chat prompt system.';
58
>
};
59
>
60
>
export class ComputeAutomaticInstructions {
61
>
62
>
private _parseResults: ResourceMap<ParsedPromptFile> = new ResourceMap();
63
>
64
>
constructor(
65
private readonly _modeKind: ChatModeKind,
66
private readonly _enabledTools: UserSelectedTools | undefined,