Skip to content

Commit 0ef9569

Browse files
committed
Add Expirement Toggle for VS Code LM Function Calling Feature
1 parent b8da0aa commit 0ef9569

File tree

5 files changed

+59
-9
lines changed

5 files changed

+59
-9
lines changed

src/core/Cline.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import { OpenRouterHandler } from "../api/providers/openrouter"
6363
import { McpHub } from "../services/mcp/McpHub"
6464
import crypto from "crypto"
6565
import { insertGroups } from "./diff/insert-groups"
66-
import { EXPERIMENT_IDS, experiments as Experiments } from "../shared/experiments"
66+
import { EXPERIMENT_IDS, experiments as Experiments, experimentDefault } from "../shared/experiments"
6767

6868
const cwd =
6969
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
@@ -1263,6 +1263,7 @@ export class Cline {
12631263
// Validate tool use before execution
12641264
const { mode, customModes } = (await this.providerRef.deref()?.getState()) ?? {}
12651265
try {
1266+
const { experiments } = (await this.providerRef.deref()?.getState()) ?? {}
12661267
validateToolUse(
12671268
block.name as ToolName,
12681269
mode ?? defaultModeSlug,
@@ -1271,6 +1272,7 @@ export class Cline {
12711272
apply_diff: this.diffEnabled,
12721273
},
12731274
block.params,
1275+
experiments,
12741276
)
12751277
} catch (error) {
12761278
this.consecutiveMistakeCount++
@@ -2513,14 +2515,22 @@ export class Cline {
25132515
break
25142516
}
25152517
}
2516-
25172518
case "list_vscode_lm_tools": {
25182519
try {
2519-
// Get all registered VS Code LM tools
2520-
const tools = vscode.lm.tools
2520+
// Check if experiment is enabled
2521+
const { experiments = experimentDefault } =
2522+
(await this.providerRef.deref()?.getState()) ?? {}
2523+
if (!Experiments.isEnabled(experiments, EXPERIMENT_IDS.VSCODE_LM_TOOLS)) {
2524+
pushToolResult(
2525+
formatResponse.toolError(
2526+
"VSCode LM Tools experiment is not enabled. Enable it in Settings > Advanced Settings > Experimental Features.",
2527+
),
2528+
)
2529+
break
2530+
}
25212531

25222532
// Format tool information
2523-
const toolsList = tools.map((tool) => ({
2533+
const toolsList = vscode.lm.tools.map((tool) => ({
25242534
name: tool.name,
25252535
description: tool.description,
25262536
inputSchema: tool.inputSchema,
@@ -2551,6 +2561,18 @@ export class Cline {
25512561
const arguments_str: string | undefined = block.params.arguments
25522562

25532563
try {
2564+
// Check if experiment is enabled
2565+
const { experiments = experimentDefault } =
2566+
(await this.providerRef.deref()?.getState()) ?? {}
2567+
if (!Experiments.isEnabled(experiments, EXPERIMENT_IDS.VSCODE_LM_TOOLS)) {
2568+
pushToolResult(
2569+
formatResponse.toolError(
2570+
"VSCode LM Tools experiment is not enabled. Enable it in Settings > Advanced Settings > Experimental Features.",
2571+
),
2572+
)
2573+
break
2574+
}
2575+
25542576
if (block.partial) {
25552577
const partialMessage = JSON.stringify({
25562578
tool: "callVsCodeLmTool",

src/core/mode-validator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ export function validateToolUse(
1010
customModes?: ModeConfig[],
1111
toolRequirements?: Record<string, boolean>,
1212
toolParams?: Record<string, unknown>,
13+
experiments?: Record<string, boolean>,
1314
): void {
14-
if (!isToolAllowedForMode(toolName, mode, customModes ?? [], toolRequirements, toolParams)) {
15+
if (!isToolAllowedForMode(toolName, mode, customModes ?? [], toolRequirements, toolParams, experiments)) {
1516
throw new Error(`Tool "${toolName}" is not allowed in ${mode} mode.`)
1617
}
1718
}

src/shared/experiments.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export const EXPERIMENT_IDS = {
22
DIFF_STRATEGY: "experimentalDiffStrategy",
33
SEARCH_AND_REPLACE: "search_and_replace",
44
INSERT_BLOCK: "insert_content",
5+
VSCODE_LM_TOOLS: "vscodeLmTools",
56
} as const
67

78
export type ExperimentKey = keyof typeof EXPERIMENT_IDS
@@ -30,11 +31,16 @@ export const experimentConfigsMap: Record<ExperimentKey, ExperimentConfig> = {
3031
},
3132
INSERT_BLOCK: {
3233
name: "Use experimental insert content tool",
33-
3434
description:
3535
"Enable the experimental insert content tool, allowing Roo to insert content at specific line numbers without needing to create a diff.",
3636
enabled: false,
3737
},
38+
VSCODE_LM_TOOLS: {
39+
name: "Use VSCode Language Model Tools",
40+
description:
41+
"Enable integration with VSCode's language model tools. This allows Roo to list and invoke VSCode's built-in AI capabilities.",
42+
enabled: false,
43+
},
3844
}
3945

4046
export const experimentDefault = Object.fromEntries(

src/shared/modes.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ export const modes: readonly ModeConfig[] = [
8383
name: "Architect",
8484
roleDefinition:
8585
"You are Roo, an experienced technical leader who is inquisitive and an excellent planner. Your goal is to gather information and get context to create a detailed plan for accomplishing the user's task, which the user will review and approve before they switch into another mode to implement the solution.",
86-
groups: ["read", ["edit", { fileRegex: "\\.md$", description: "Markdown files only" }], "browser", "mcp", "vscode_lm"],
86+
groups: [
87+
"read",
88+
["edit", { fileRegex: "\\.md$", description: "Markdown files only" }],
89+
"browser",
90+
"mcp",
91+
"vscode_lm",
92+
],
8793
customInstructions:
8894
"Depending on the user's request, you may need to do some information gathering (for example using read_file or search_files) to get more context about the task. You may also ask the user clarifying questions to get a better understanding of the task. Once you've gained more context about the user's request, you should create a detailed plan for how to accomplish the task. (You can write the plan to a markdown file if it seems appropriate.)\n\nThen you might ask the user if they are pleased with this plan, or if they would like to make any changes. Think of this as a brainstorming session where you can discuss the task and plan the best way to accomplish it. Finally once it seems like you've reached a good plan, use the switch_mode tool to request that the user switch to another mode to implement the solution.",
8995
},
@@ -92,7 +98,13 @@ export const modes: readonly ModeConfig[] = [
9298
name: "Ask",
9399
roleDefinition:
94100
"You are Roo, a knowledgeable technical assistant focused on answering questions and providing information about software development, technology, and related topics.",
95-
groups: ["read", "browser", "mcp", "vscode_lm"],
101+
groups: [
102+
"read",
103+
["edit", { fileRegex: "\\.md$", description: "Markdown files only" }],
104+
"browser",
105+
"mcp",
106+
"vscode_lm",
107+
],
96108
customInstructions:
97109
"You can analyze code, explain concepts, and access external resources. Make sure to answer the user's questions and don't rush to switch to implementing code.",
98110
},
@@ -202,6 +214,13 @@ export function isToolAllowedForMode(
202214
continue
203215
}
204216

217+
// Check if group requires an experiment to be enabled
218+
if (groupConfig.requireExperiment && experiments) {
219+
if (!experiments[groupConfig.requireExperiment]) {
220+
continue
221+
}
222+
}
223+
205224
// If there are no options, allow the tool
206225
if (!options) {
207226
return true

src/shared/tool-groups.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export type ToolGroupConfig = {
33
tools: readonly string[]
44
alwaysAvailable?: boolean // Whether this group is always available and shouldn't show in prompts view
5+
requireExperiment?: string // Experiment ID that must be enabled for this group to be available
56
}
67

78
// Map of tool slugs to their display names
@@ -47,6 +48,7 @@ export const TOOL_GROUPS: Record<string, ToolGroupConfig> = {
4748
},
4849
vscode_lm: {
4950
tools: ["list_vscode_lm_tools", "call_vscode_lm_tool"],
51+
requireExperiment: "vscodeLmTools",
5052
},
5153
}
5254

0 commit comments

Comments
 (0)