Skip to content

[PoC] Make use of vscode.lm tools contributed by arbitrary VSCode extensions #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .husky/pre-push
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this delete should probably be reverted

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely if Kilo would accept this PR.

it's deleted as tests have not been updated to pass, according to function/class signature changes for the functionalities. serve as a workaround to make it pushable for initial discussion.

the tests are less concert, compared to tool approval ui/logic, which would need major workouts beyond done so far.

anyway, let's see it working and discuss/decide further directions for now.

This file was deleted.

3 changes: 2 additions & 1 deletion packages/types/src/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { z } from "zod"
* ToolGroup
*/

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

export const toolGroupsSchema = z.enum(toolGroups)

Expand All @@ -25,6 +25,7 @@ export const toolNames = [
"list_files",
"list_code_definition_names",
"browser_action",
"use_vsclmt",
"use_mcp_tool",
"access_mcp_resource",
"ask_followup_question",
Expand Down
6 changes: 6 additions & 0 deletions src/core/assistant-message/presentAssistantMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { listCodeDefinitionNamesTool } from "../tools/listCodeDefinitionNamesToo
import { searchFilesTool } from "../tools/searchFilesTool"
import { browserActionTool } from "../tools/browserActionTool"
import { executeCommandTool } from "../tools/executeCommandTool"
import { useVSCLMT } from "../tools/vsclmt"
import { useMcpToolTool } from "../tools/useMcpToolTool"
import { accessMcpResourceTool } from "../tools/accessMcpResourceTool"
import { askFollowupQuestionTool } from "../tools/askFollowupQuestionTool"
Expand Down Expand Up @@ -195,6 +196,8 @@ export async function presentAssistantMessage(cline: Task) {
return `[${block.name} for '${block.params.path}']`
case "browser_action":
return `[${block.name} for '${block.params.action}']`
case "use_vsclmt":
return `[${block.name} for '${block.params.tool_name}']`
case "use_mcp_tool":
return `[${block.name} for '${block.params.server_name}']`
case "access_mcp_resource":
Expand Down Expand Up @@ -481,6 +484,9 @@ export async function presentAssistantMessage(cline: Task) {
case "execute_command":
await executeCommandTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
case "use_vsclmt":
await useVSCLMT(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
case "use_mcp_tool":
await useMcpToolTool(cline, block, askApproval, handleError, pushToolResult, removeClosingTag)
break
Expand Down
1 change: 1 addition & 0 deletions src/core/prompts/sections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { getSystemInfoSection } from "./system-info"
export { getObjectiveSection } from "./objective"
export { addCustomInstructions } from "./custom-instructions"
export { getSharedToolUseSection } from "./tool-use"
export { getVSCLMTSection } from "./vsclmt"
export { getMcpServersSection } from "./mcp-servers"
export { getToolUseGuidelinesSection } from "./tool-use-guidelines"
export { getCapabilitiesSection } from "./capabilities"
Expand Down
51 changes: 51 additions & 0 deletions src/core/prompts/sections/vsclmt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { ToolInfo } from "../../../services/vsclm/VSCLMToolsService"

export function getVSCLMTSection(selectedVSCLMT: ToolInfo[]): string {
if (!selectedVSCLMT || selectedVSCLMT.length === 0) {
return ""
}

const toolDescriptions = selectedVSCLMT
.map((tool) => {
const displayName = tool.displayName || tool.name
const description = tool.description || tool.userDescription || "No description available"

let toolSection = `### ${displayName}
**Provider Extension:** ${tool.providerExtensionDisplayName} (${tool.providerExtensionId})
**Description:** ${description}

**Tool Name:** ${tool.name}`

// Add input schema information if available
if (tool.inputSchema && typeof tool.inputSchema === "object") {
try {
const schemaStr = JSON.stringify(tool.inputSchema, null, 2)
toolSection += `
**Input Schema:**
\`\`\`json
${schemaStr}
\`\`\``
} catch (error) {
// If schema can't be serialized, skip it
console.log(`Error serializing input schema for tool ${tool.name}:`, error)
}
}

// Add tags if available
if (tool.tags && tool.tags.length > 0) {
toolSection += `
**Tags:** ${tool.tags.join(", ")}`
}

return toolSection
})
.join("\n\n")

return `## VS Code Language Model Tools

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.

${toolDescriptions}

**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.`
}
10 changes: 9 additions & 1 deletion src/core/prompts/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Mode, modes, defaultModeSlug, getModeBySlug, getGroupName, getModeSelec
import { DiffStrategy } from "../../shared/tools"
import { formatLanguage } from "../../shared/language"

import { VSCLMToolsService } from "../../services/vsclm/VSCLMToolsService"
import { McpHub } from "../../services/mcp/McpHub"
import { CodeIndexManager } from "../../services/code-index/manager"

Expand All @@ -18,6 +19,7 @@ import {
getSystemInfoSection,
getObjectiveSection,
getSharedToolUseSection,
getVSCLMTSection,
getMcpServersSection,
getToolUseGuidelinesSection,
getCapabilitiesSection,
Expand All @@ -31,6 +33,7 @@ async function generatePrompt(
cwd: string,
supportsComputerUse: boolean,
mode: Mode,
vsclmtService?: VSCLMToolsService,
mcpHub?: McpHub,
diffStrategy?: DiffStrategy,
browserViewportSize?: string,
Expand All @@ -56,8 +59,9 @@ async function generatePrompt(
const modeConfig = getModeBySlug(mode, customModeConfigs) || modes.find((m) => m.slug === mode) || modes[0]
const { roleDefinition, baseInstructions } = getModeSelection(mode, promptComponent, customModeConfigs)

const [modesSection, mcpServersSection] = await Promise.all([
const [modesSection, vsclmtSection, mcpServersSection] = await Promise.all([
getModesSection(context),
vsclmtService ? getVSCLMTSection(vsclmtService.getSelectedTools()) : Promise.resolve(""),
modeConfig.groups.some((groupEntry) => getGroupName(groupEntry) === "mcp")
? getMcpServersSection(mcpHub, effectiveDiffStrategy, enableMcpServerCreation)
: Promise.resolve(""),
Expand Down Expand Up @@ -87,6 +91,8 @@ ${getToolDescriptionsForMode(

${getToolUseGuidelinesSection(codeIndexManager)}

${vsclmtSection}

${mcpServersSection}

${getCapabilitiesSection(cwd, supportsComputerUse, mcpHub, effectiveDiffStrategy, codeIndexManager)}
Expand All @@ -113,6 +119,7 @@ export const SYSTEM_PROMPT = async (
context: vscode.ExtensionContext,
cwd: string,
supportsComputerUse: boolean,
vsclmtService?: VSCLMToolsService,
mcpHub?: McpHub,
diffStrategy?: DiffStrategy,
browserViewportSize?: string,
Expand Down Expand Up @@ -187,6 +194,7 @@ ${customInstructions}`
cwd,
supportsComputerUse,
currentMode.slug,
vsclmtService,
mcpHub,
effectiveDiffStrategy,
browserViewportSize,
Expand Down
3 changes: 3 additions & 0 deletions src/core/prompts/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { getListCodeDefinitionNamesDescription } from "./list-code-definition-na
import { getBrowserActionDescription } from "./browser-action"
import { getAskFollowupQuestionDescription } from "./ask-followup-question"
import { getAttemptCompletionDescription } from "./attempt-completion"
import { getVSCLMTDescription } from "./vsclmt"
import { getUseMcpToolDescription } from "./use-mcp-tool"
import { getAccessMcpResourceDescription } from "./access-mcp-resource"
import { getSwitchModeDescription } from "./switch-mode"
Expand All @@ -26,6 +27,7 @@ import { CodeIndexManager } from "../../../services/code-index/manager"

// Map of tool names to their description functions
const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined> = {
use_vsclmt: (args) => getVSCLMTDescription(args),
execute_command: (args) => getExecuteCommandDescription(args),
read_file: (args) => getReadFileDescription(args),
fetch_instructions: () => getFetchInstructionsDescription(),
Expand Down Expand Up @@ -135,6 +137,7 @@ export {
getBrowserActionDescription,
getAskFollowupQuestionDescription,
getAttemptCompletionDescription,
getVSCLMTDescription,
getUseMcpToolDescription,
getAccessMcpResourceDescription,
getSwitchModeDescription,
Expand Down
27 changes: 27 additions & 0 deletions src/core/prompts/tools/vsclmt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ToolArgs } from "./types"

export function getVSCLMTDescription(args: ToolArgs): string {
return `## use_vsclmt

Access and invoke VS Code Language Model tools that are selected and available in the current workspace.

Required parameters:
- tool_name: The name of the VS Code LM tool to invoke

Optional parameters:
- arguments: JSON string containing the arguments for the tool

The tool will:
1. Validate that the specified VS Code LM tool is available and selected
2. Parse and validate the provided arguments
3. Invoke the tool using VS Code's native language model tool system
4. Return the tool's result or any error messages

Use this tool to leverage VS Code's ecosystem of language model tools for enhanced functionality.

Example:
<use_vsclmt>
<tool_name>example-tool</tool_name>
<arguments>{"param1": "value1", "param2": "value2"}</arguments>
</use_vsclmt>`
}
2 changes: 2 additions & 0 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ export class Task extends EventEmitter<ClineEvents> {
// kilocode_change end

/*private kilocode_change*/ async getSystemPrompt(): Promise<string> {
const vsclmtService = this.providerRef.deref()?.getVSCLMToolService()
const { mcpEnabled } = (await this.providerRef.deref()?.getState()) ?? {}
let mcpHub: McpHub | undefined
if (mcpEnabled ?? true) {
Expand Down Expand Up @@ -1710,6 +1711,7 @@ export class Task extends EventEmitter<ClineEvents> {
provider.context,
this.cwd,
(this.api.getModel().info.supportsComputerUse ?? false) && (browserToolEnabled ?? true),
vsclmtService,
mcpHub,
this.diffStrategy,
browserViewportSize,
Expand Down
Loading