src/vs/platform/agentHost/node/claude/claudePromptResolver.ts

94 LOC · 92 covered · 2 uncovered · 21 ranges · 357 concepts · 11 introducers · 200 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

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 related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- claudeAgent.ts ×91
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 type Anthropic from '@anthropic-ai/sdk';
7 > import { URI } from '../../../../base/common/uri.js';
8 > import { isAgentFeedbackAnnotationsAttachment, renderAgentFeedbackAnnotationsAttachment } from '../../common/meta/agentFeedbackAttachments.js';
9 > import { MessageAttachmentKind, type MessageAttachment } from '../../common/state/protocol/state.js';
10 >
11 > /**
12 > * Build the {@link Anthropic.ContentBlockParam}[] payload for an
13 > * {@link SDKUserMessage} from a plain text prompt and the protocol
14 > * attachments accompanying the user message.
15 > *
16 > * Phase 6 keeps the resolver pure and minimal: a single `text` block
17 > * carrying the prompt, plus additional text blocks for attachments. This
18 > * mirrors the production extension's resolver shape so a future phase that
19 > * adds image rendering or inline range substitution can extend without
20 > * restructuring.
21 > *
22 > * Selections are rendered as URI references with an optional line
23 > * suffix. The protocol's {@link TextSelection} carries range metadata
24 > * only; the selected text is not included inline.
25 > *
26 > * Resource attachments and simple attachments with model representations
27 > * are honoured today. Embedded resources are dropped because the current
28 > * Claude path does not have a place to consume them.
29 > */
30 > export function resolvePromptToContentBlocks(
31 > prompt: string, claudePromptResolver.ts ×1
32 > attachments?: readonly MessageAttachment[],
33 > ): Anthropic.ContentBlockParam[] {
34 > const blocks: Anthropic.ContentBlockParam[] = [{ type: 'text', text: prompt }];
35 > if (!attachments?.length) {
36 > return blocks; claudePromptResolver.ts ×1
37 > }
38 > const refLines: string[] = []; claudePromptResolver.ts ×4
39 > const simpleBlocks: string[] = [];
40 > const feedbackBlocks: string[] = [];
41 > for (const att of attachments) {
42 > if (isAgentFeedbackAnnotationsAttachment(att)) {
43 > const rendered = renderAgentFeedbackAnnotationsAttachment(att); claudePromptResolver.ts ×2
44 > if (rendered) {
45 > feedbackBlocks.push(rendered);
46 > }
47 > continue;
48 > }
49 > if (att.type === MessageAttachmentKind.Simple) { claudePromptResolver.ts ×1
50 > if (att.modelRepresentation) { claudePromptResolver.ts ×2
51 > simpleBlocks.push(att.modelRepresentation);
52 > }
53 > continue;
54 > }
55 > if (att.type !== MessageAttachmentKind.Resource) { claudePromptResolver.ts ×5
56 continue;
57 }
58 > const uri = URI.parse(att.uri); claudePromptResolver.ts ×5
59 > if (att.displayKind === 'selection') {
60 > const startLine = att.selection ? `:${att.selection.range.start.line + 1}` : ''; claudePromptResolver.ts ×1
61 > refLines.push(`- ${uriToString(uri)}${startLine}`);
63 > refLines.push(`- ${uriToString(uri)}`); claudePromptResolver.ts ×1
64 > }
66 > if (feedbackBlocks.length > 0) {
67 > blocks.push({ claudePromptResolver.ts ×2
68 > type: 'text',
69 > text: feedbackBlocks.join('\n\n'),
70 > });
71 > }
72 > if (simpleBlocks.length > 0) { claudePromptResolver.ts ×4
73 > blocks.push({ claudePromptResolver.ts ×2
74 > type: 'text',
75 > text: simpleBlocks.join('\n\n'),
76 > });
77 > }
78 > if (refLines.length === 0) { claudePromptResolver.ts ×4
79 > return blocks; claudePromptResolver.ts ×1
80 > }
81 > blocks.push({ claudePromptResolver.ts ×5
82 > type: 'text',
83 > text: '<system-reminder>\nThe user provided the following references:\n' +
84 > refLines.join('\n') +
85 > '\n\nIMPORTANT: this context may or may not be relevant to your tasks. ' +
86 > 'You should not respond to this context unless it is highly relevant to your task.\n' +
87 > '</system-reminder>',
88 > });
89 > return blocks;
90 > }
92 > function uriToString(uri: URI): string { claudePromptResolver.ts ×5
93 > return uri.scheme === 'file' ? uri.fsPath : uri.toString();
94 > }