96
97
public async collect(variables: ChatRequestVariableSet, token: CancellationToken): Promise<void> {
99
>
const startTime = performance.now();
100
>
const instructionFiles = await this._promptsService.getInstructionFiles(token);
101
>
102
>
this._logService.trace(`[InstructionsContextComputer] ${instructionFiles.length} instruction files available.`);
103
>
104
>
const telemetryEvent: InstructionsCollectionEvent = newInstructionsCollectionEvent();
105
>
const debugInfo: InstructionsCollectionDebugInfo = newInstructionsCollectionDebugInfo();
106
>
const context = this._getContext(variables);
107
>
108
>
// find instructions where the `applyTo` matches the attached context
109
>
await this.addApplyingInstructions(instructionFiles, context, variables, telemetryEvent, debugInfo, token);
110
>
111
>
// add all instructions referenced by all instruction files that are in the context
112
>
await this._addReferencedInstructions(variables, telemetryEvent, debugInfo, token);
113
>
114
>
// get copilot instructions
115
>
await this._addAgentInstructions(variables, telemetryEvent, debugInfo, token);
116
>
117
>
const customizationsIndexVariable = await this._getCustomizationsIndex(instructionFiles, variables, telemetryEvent, debugInfo, token);
118
>
if (customizationsIndexVariable) {
119
variables.add(customizationsIndexVariable);
120
telemetryEvent.listedInstructionsCount++;
121
}
123
>
debugInfo.durationInMillis = performance.now() - startTime;
124
>
this.sendTelemetry(telemetryEvent);
125
>
lastInstructionsCollectionResult = { telemetryEvent, debugInfo };
126
>
}
127
128
private sendTelemetry(telemetryEvent: InstructionsCollectionEvent): void {
130
>
telemetryEvent.totalInstructionsCount = telemetryEvent.agentInstructionsCount + telemetryEvent.referencedInstructionsCount + telemetryEvent.applyingInstructionsCount + telemetryEvent.listedInstructionsCount;
131
>
this._telemetryService.publicLog2<InstructionsCollectionEvent, InstructionsCollectionClassification>('instructionsCollected', telemetryEvent);
132
>
}
133
134
private async _logSkillLoadedTelemetry(skills: readonly IAgentSkill[]): Promise<void> {