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.
/*---------------------------------------------------------------------------------------------
claudeAgent.ts ×91
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type Anthropic from '@anthropic-ai/sdk';
import { URI } from '../../../../base/common/uri.js';
import { isAgentFeedbackAnnotationsAttachment, renderAgentFeedbackAnnotationsAttachment } from '../../common/meta/agentFeedbackAttachments.js';
import { MessageAttachmentKind, type MessageAttachment } from '../../common/state/protocol/state.js';
/**
* Build the {@link Anthropic.ContentBlockParam}[] payload for an
* {@link SDKUserMessage} from a plain text prompt and the protocol
* attachments accompanying the user message.
*
* Phase 6 keeps the resolver pure and minimal: a single `text` block
* carrying the prompt, plus additional text blocks for attachments. This
* mirrors the production extension's resolver shape so a future phase that
* adds image rendering or inline range substitution can extend without
* restructuring.
*
* Selections are rendered as URI references with an optional line
* suffix. The protocol's {@link TextSelection} carries range metadata
* only; the selected text is not included inline.
*
* Resource attachments and simple attachments with model representations
* are honoured today. Embedded resources are dropped because the current
* Claude path does not have a place to consume them.
*/
export function resolvePromptToContentBlocks(
attachments?: readonly MessageAttachment[],
): Anthropic.ContentBlockParam[] {
const blocks: Anthropic.ContentBlockParam[] = [{ type: 'text', text: prompt }];
if (!attachments?.length) {
}
const simpleBlocks: string[] = [];
const feedbackBlocks: string[] = [];
for (const att of attachments) {
if (isAgentFeedbackAnnotationsAttachment(att)) {
if (rendered) {
feedbackBlocks.push(rendered);
}
continue;
}
simpleBlocks.push(att.modelRepresentation);
}
continue;
}
continue;
}
if (att.displayKind === 'selection') {
const startLine = att.selection ? `:${att.selection.range.start.line + 1}` : '';
claudePromptResolver.ts ×1
refLines.push(`- ${uriToString(uri)}${startLine}`);
}
if (feedbackBlocks.length > 0) {
type: 'text',
text: feedbackBlocks.join('\n\n'),
});
}
type: 'text',
text: simpleBlocks.join('\n\n'),
});
}
}
type: 'text',
text: '<system-reminder>\nThe user provided the following references:\n' +
refLines.join('\n') +
'\n\nIMPORTANT: this context may or may not be relevant to your tasks. ' +
'You should not respond to this context unless it is highly relevant to your task.\n' +
'</system-reminder>',
});
return blocks;
}
return uri.scheme === 'file' ? uri.fsPath : uri.toString();
}