computeAutomaticInstructions.ts ×13

Frontier kind: Code frontier

unlabeled · c_5a3b4268005b

257 tests · 40938 LOC · 183 files · introduces 0 tests · 91 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges91 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3276 ranges40938 lines · 183 files · Browse complete extent
All tests (intent)
257 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 91 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/promptSyntax/computeAutomaticInstructions.ts 91 introduced LOC · 13 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- computeAutomaticInstructions.ts
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,
79 ) {
80 }
82 > private async _parseInstructionsFile(uri: URI, token: CancellationToken): Promise<ParsedPromptFile | undefined> {
83 if (this._parseResults.has(uri)) {
84 return this._parseResults.get(uri)!;
94
95 }
97 > public async collect(variables: ChatRequestVariableSet, token: CancellationToken): Promise<void> {
98
99 const startTime = performance.now();
125 lastInstructionsCollectionResult = { telemetryEvent, debugInfo };
126 }
128 > private sendTelemetry(telemetryEvent: InstructionsCollectionEvent): void {
129 // Emit telemetry
130 telemetryEvent.totalInstructionsCount = telemetryEvent.agentInstructionsCount + telemetryEvent.referencedInstructionsCount + telemetryEvent.applyingInstructionsCount + telemetryEvent.listedInstructionsCount;
131 this._telemetryService.publicLog2<InstructionsCollectionEvent, InstructionsCollectionClassification>('instructionsCollected', telemetryEvent);
132 }
134 > private async _logSkillLoadedTelemetry(skills: readonly IAgentSkill[]): Promise<void> {
135 type SkillLoadedIntoContextEvent = {
136 skillNameHash: string;
180 }
181 }
183 > /** public for testing */
184 > public async addApplyingInstructions(instructionFiles: readonly IInstructionFile[], context: { files: ResourceSet; instructions: ResourceSet }, variables: ChatRequestVariableSet, telemetryEvent: InstructionsCollectionEvent, debugInfo: InstructionsCollectionDebugInfo, token: CancellationToken): Promise<void> {
185 const includeApplyingInstructions = this._configurationService.getValue(PromptsConfig.INCLUDE_APPLYING_INSTRUCTIONS);
186 if (!includeApplyingInstructions && this._modeKind !== ChatModeKind.Edit) {
237 }
238 }
240 > private _getContext(attachedContext: ChatRequestVariableSet): { files: ResourceSet; instructions: ResourceSet } {
241 const files = new ResourceSet();
242 const instructions = new ResourceSet();
254 return { files, instructions };
255 }
257 > private async _addAgentInstructions(variables: ChatRequestVariableSet, telemetryEvent: InstructionsCollectionEvent, debugInfo: InstructionsCollectionDebugInfo, token: CancellationToken): Promise<void> {
258 const logger = {
259 logInfo: (message: string) => this._logService.trace(`[InstructionsContextComputer] ${message}`)
291 }
292 }
294 > private _matches(files: ResourceSet, applyToPattern: string): { pattern: string; file?: URI } | undefined {
295 const patterns = splitGlobAware(applyToPattern, ',');
296 const patterMatches = (pattern: string): { pattern: string; file?: URI } | undefined => {
328 return undefined;
329 }
331 > private _getTool(referenceName: string): { tool: IToolData; variable: string } | undefined {
332 if (!this._enabledTools) {
333 return undefined;
339 return undefined;
340 }
342 > private async _getCustomizationsIndex(instructionFiles: readonly IInstructionFile[], _existingVariables: ChatRequestVariableSet, telemetryEvent: InstructionsCollectionEvent, debugInfo: InstructionsCollectionDebugInfo, token: CancellationToken): Promise<IPromptTextVariableEntry | undefined> {
343 const readTool = this._getTool('readFile');
344 const runInTerminalTool = this._getTool('runInTerminal');
568 return toPromptTextVariableEntry(content, true, toolReferences);
569 }
571 > private async _addReferencedInstructions(attachedContext: ChatRequestVariableSet, telemetryEvent: InstructionsCollectionEvent, debugInfo: InstructionsCollectionDebugInfo, token: CancellationToken): Promise<void> {
572 const includeReferencedInstructions = this._configurationService.getValue(PromptsConfig.INCLUDE_REFERENCED_INSTRUCTIONS);
573 if (!includeReferencedInstructions && this._modeKind !== ChatModeKind.Edit) {
621 }
622 }
624 >
625 >
626 > export function getFilePath(uri: URI, remoteOS: OperatingSystem | undefined, isRemote = false): string {
627 // When connected to a remote, local file:// URIs must be represented using
628 // the vscode-local scheme so the remote extension host can read them via the