Skip to content

Commit 0a5d9e2

Browse files
committed
use vscode.lm tools
1 parent 64901c8 commit 0a5d9e2

File tree

18 files changed

+752
-59
lines changed

18 files changed

+752
-59
lines changed

.husky/pre-commit

Lines changed: 0 additions & 27 deletions
This file was deleted.

.husky/pre-push

Lines changed: 0 additions & 29 deletions
This file was deleted.

packages/types/src/tool.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { z } from "zod"
44
* ToolGroup
55
*/
66

7-
export const toolGroups = ["read", "edit", "browser", "command", "mcp", "modes"] as const
7+
export const toolGroups = ["read", "edit", "browser", "command", "vsclmt", "mcp", "modes"] as const
88

99
export const toolGroupsSchema = z.enum(toolGroups)
1010

@@ -25,6 +25,7 @@ export const toolNames = [
2525
"list_files",
2626
"list_code_definition_names",
2727
"browser_action",
28+
"use_vsclmt",
2829
"use_mcp_tool",
2930
"access_mcp_resource",
3031
"ask_followup_question",

src/core/assistant-message/presentAssistantMessage.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { listCodeDefinitionNamesTool } from "../tools/listCodeDefinitionNamesToo
1818
import { searchFilesTool } from "../tools/searchFilesTool"
1919
import { browserActionTool } from "../tools/browserActionTool"
2020
import { executeCommandTool } from "../tools/executeCommandTool"
21+
import { useVSCLMT } from "../tools/vsclmt"
2122
import { useMcpToolTool } from "../tools/useMcpToolTool"
2223
import { accessMcpResourceTool } from "../tools/accessMcpResourceTool"
2324
import { askFollowupQuestionTool } from "../tools/askFollowupQuestionTool"
@@ -193,6 +194,8 @@ export async function presentAssistantMessage(cline: Task) {
193194
return `[${block.name} for '${block.params.path}']`
194195
case "browser_action":
195196
return `[${block.name} for '${block.params.action}']`
197+
case "use_vsclmt":
198+
return `[${block.name} for '${block.params.tool_name}']`
196199
case "use_mcp_tool":
197200
return `[${block.name} for '${block.params.server_name}']`
198201
case "access_mcp_resource":
@@ -475,6 +478,9 @@ export async function presentAssistantMessage(cline: Task) {
475478
case "execute_command":
476479
await executeCommandTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
477480
break
481+
case "use_vsclmt":
482+
await useVSCLMT(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
483+
break
478484
case "use_mcp_tool":
479485
await useMcpToolTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
480486
break

src/core/prompts/sections/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export { getSystemInfoSection } from "./system-info"
33
export { getObjectiveSection } from "./objective"
44
export { addCustomInstructions } from "./custom-instructions"
55
export { getSharedToolUseSection } from "./tool-use"
6+
export { getVSCLMTSection } from "./vsclmt"
67
export { getMcpServersSection } from "./mcp-servers"
78
export { getToolUseGuidelinesSection } from "./tool-use-guidelines"
89
export { getCapabilitiesSection } from "./capabilities"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import type { ToolInfo } from "../../../services/vsclm/VSCLMToolsService"
2+
3+
export function getVSCLMTSection(selectedVSCLMT: ToolInfo[]): string {
4+
if (!selectedVSCLMT || selectedVSCLMT.length === 0) {
5+
return ""
6+
}
7+
8+
const toolDescriptions = selectedVSCLMT.map(tool => {
9+
const displayName = tool.displayName || tool.name
10+
const description = tool.description || tool.userDescription || "No description available"
11+
12+
let toolSection = `### ${displayName}
13+
**Provider Extension:** ${tool.providerExtensionDisplayName} (${tool.providerExtensionId})
14+
**Description:** ${description}
15+
16+
**Tool Name:** ${tool.name}`
17+
18+
// Add input schema information if available
19+
if (tool.inputSchema && typeof tool.inputSchema === 'object') {
20+
try {
21+
const schemaStr = JSON.stringify(tool.inputSchema, null, 2)
22+
toolSection += `
23+
**Input Schema:**
24+
\`\`\`json
25+
${schemaStr}
26+
\`\`\``
27+
} catch (error) {
28+
// If schema can't be serialized, skip it
29+
console.log(`Error serializing input schema for tool ${tool.name}:`, error)
30+
}
31+
}
32+
33+
// Add tags if available
34+
if (tool.tags && tool.tags.length > 0) {
35+
toolSection += `
36+
**Tags:** ${tool.tags.join(', ')}`
37+
}
38+
39+
return toolSection
40+
}).join('\n\n')
41+
42+
return `## VS Code Language Model Tools
43+
44+
The following VS Code Language Model tools are available for use. You can invoke them using the \`use_vsclmt\` tool with the appropriate tool name and arguments.
45+
46+
${toolDescriptions}
47+
48+
**Usage:** To use any of these tools, use the \`use_vsclmt\` tool with the \`tool_name\` parameter set to the exact tool name shown above, and provide any required arguments as a JSON string in the \`arguments\` parameter.`
49+
}

src/core/prompts/system.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Mode, modes, defaultModeSlug, getModeBySlug, getGroupName, getModeSelec
77
import { DiffStrategy } from "../../shared/tools"
88
import { formatLanguage } from "../../shared/language"
99

10+
import { VSCLMToolsService } from "../../services/vsclm/VSCLMToolsService"
1011
import { McpHub } from "../../services/mcp/McpHub"
1112
import { CodeIndexManager } from "../../services/code-index/manager"
1213

@@ -18,6 +19,7 @@ import {
1819
getSystemInfoSection,
1920
getObjectiveSection,
2021
getSharedToolUseSection,
22+
getVSCLMTSection,
2123
getMcpServersSection,
2224
getToolUseGuidelinesSection,
2325
getCapabilitiesSection,
@@ -31,6 +33,7 @@ async function generatePrompt(
3133
cwd: string,
3234
supportsComputerUse: boolean,
3335
mode: Mode,
36+
vsclmtService?: VSCLMToolsService,
3437
mcpHub?: McpHub,
3538
diffStrategy?: DiffStrategy,
3639
browserViewportSize?: string,
@@ -56,8 +59,11 @@ async function generatePrompt(
5659
const modeConfig = getModeBySlug(mode, customModeConfigs) || modes.find((m) => m.slug === mode) || modes[0]
5760
const { roleDefinition, baseInstructions } = getModeSelection(mode, promptComponent, customModeConfigs)
5861

59-
const [modesSection, mcpServersSection] = await Promise.all([
62+
const [modesSection, vsclmtSection, mcpServersSection] = await Promise.all([
6063
getModesSection(context),
64+
vsclmtService
65+
? getVSCLMTSection(vsclmtService.getSelectedTools())
66+
: Promise.resolve(""),
6167
modeConfig.groups.some((groupEntry) => getGroupName(groupEntry) === "mcp")
6268
? getMcpServersSection(mcpHub, effectiveDiffStrategy, enableMcpServerCreation)
6369
: Promise.resolve(""),
@@ -87,6 +93,8 @@ ${getToolDescriptionsForMode(
8793
8894
${getToolUseGuidelinesSection(codeIndexManager)}
8995
96+
${vsclmtSection}
97+
9098
${mcpServersSection}
9199
92100
${getCapabilitiesSection(cwd, supportsComputerUse, mcpHub, effectiveDiffStrategy, codeIndexManager)}
@@ -108,6 +116,7 @@ export const SYSTEM_PROMPT = async (
108116
context: vscode.ExtensionContext,
109117
cwd: string,
110118
supportsComputerUse: boolean,
119+
vsclmtService?: VSCLMToolsService,
111120
mcpHub?: McpHub,
112121
diffStrategy?: DiffStrategy,
113122
browserViewportSize?: string,
@@ -182,6 +191,7 @@ ${customInstructions}`
182191
cwd,
183192
supportsComputerUse,
184193
currentMode.slug,
194+
vsclmtService,
185195
mcpHub,
186196
effectiveDiffStrategy,
187197
browserViewportSize,

src/core/prompts/tools/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { getListCodeDefinitionNamesDescription } from "./list-code-definition-na
1717
import { getBrowserActionDescription } from "./browser-action"
1818
import { getAskFollowupQuestionDescription } from "./ask-followup-question"
1919
import { getAttemptCompletionDescription } from "./attempt-completion"
20+
import { getVSCLMTDescription } from "./vsclmt"
2021
import { getUseMcpToolDescription } from "./use-mcp-tool"
2122
import { getAccessMcpResourceDescription } from "./access-mcp-resource"
2223
import { getSwitchModeDescription } from "./switch-mode"
@@ -26,6 +27,7 @@ import { CodeIndexManager } from "../../../services/code-index/manager"
2627

2728
// Map of tool names to their description functions
2829
const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined> = {
30+
use_vsclmt: (args) => getVSCLMTDescription(args),
2931
execute_command: (args) => getExecuteCommandDescription(args),
3032
read_file: (args) => getReadFileDescription(args),
3133
fetch_instructions: () => getFetchInstructionsDescription(),
@@ -135,6 +137,7 @@ export {
135137
getBrowserActionDescription,
136138
getAskFollowupQuestionDescription,
137139
getAttemptCompletionDescription,
140+
getVSCLMTDescription,
138141
getUseMcpToolDescription,
139142
getAccessMcpResourceDescription,
140143
getSwitchModeDescription,

src/core/prompts/tools/vsclmt.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { ToolArgs } from "./types"
2+
3+
export function getVSCLMTDescription(args: ToolArgs): string {
4+
return `## use_vsclmt
5+
6+
Access and invoke VS Code Language Model tools that are selected and available in the current workspace.
7+
8+
Required parameters:
9+
- tool_name: The name of the VS Code LM tool to invoke
10+
11+
Optional parameters:
12+
- arguments: JSON string containing the arguments for the tool
13+
14+
The tool will:
15+
1. Validate that the specified VS Code LM tool is available and selected
16+
2. Parse and validate the provided arguments
17+
3. Invoke the tool using VS Code's native language model tool system
18+
4. Return the tool's result or any error messages
19+
20+
Use this tool to leverage VS Code's ecosystem of language model tools for enhanced functionality.
21+
22+
Example:
23+
<use_vsclmt>
24+
<tool_name>example-tool</tool_name>
25+
<arguments>{"param1": "value1", "param2": "value2"}</arguments>
26+
</use_vsclmt>`
27+
}

src/core/task/Task.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ export class Task extends EventEmitter<ClineEvents> {
15621562
}
15631563

15641564
private async getSystemPrompt(): Promise<string> {
1565+
const vsclmtService= this.providerRef.deref()?.getVSCLMToolService()
15651566
const { mcpEnabled } = (await this.providerRef.deref()?.getState()) ?? {}
15661567
let mcpHub: McpHub | undefined
15671568
if (mcpEnabled ?? true) {
@@ -1613,6 +1614,7 @@ export class Task extends EventEmitter<ClineEvents> {
16131614
provider.context,
16141615
this.cwd,
16151616
(this.api.getModel().info.supportsComputerUse ?? false) && (browserToolEnabled ?? true),
1617+
vsclmtService,
16161618
mcpHub,
16171619
this.diffStrategy,
16181620
browserViewportSize,

0 commit comments

Comments
 (0)