From fb3d6dd7f10fb7cf804918119c418c8c45fb1ce7 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Mon, 15 Sep 2025 15:41:58 -0700 Subject: [PATCH] feat: exclude single file edit for capable models --- core/tools/index.ts | 3 +- extensions/cli/src/tools/index.tsx | 50 +++++++++++++++++++++++++-- extensions/cli/src/tools/multiEdit.ts | 5 ++- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/core/tools/index.ts b/core/tools/index.ts index 3a45ea295..9d50cc8ab 100644 --- a/core/tools/index.ts +++ b/core/tools/index.ts @@ -4,7 +4,6 @@ import * as toolDefinitions from "./definitions"; // I'm writing these as functions because we've messed up 3 TIMES by pushing to const, causing duplicate tool definitions on subsequent config loads. export const getBaseToolDefinitions = () => [ toolDefinitions.readFileTool, - toolDefinitions.createNewFileTool, toolDefinitions.runTerminalCommandTool, toolDefinitions.globSearchTool, @@ -13,7 +12,6 @@ export const getBaseToolDefinitions = () => [ toolDefinitions.lsTool, toolDefinitions.createRuleBlock, toolDefinitions.fetchUrlContentTool, - toolDefinitions.singleFindAndReplaceTool, ]; export const getConfigDependentToolDefinitions = ( @@ -42,6 +40,7 @@ export const getConfigDependentToolDefinitions = ( tools.push(toolDefinitions.multiEditTool); } else { tools.push(toolDefinitions.editFileTool); + tools.push(toolDefinitions.singleFindAndReplaceTool); } // missing support for remote os calls: https://github.com/microsoft/vscode/issues/252269 diff --git a/extensions/cli/src/tools/index.tsx b/extensions/cli/src/tools/index.tsx index a4cb3dcb7..05e2cd02e 100644 --- a/extensions/cli/src/tools/index.tsx +++ b/extensions/cli/src/tools/index.tsx @@ -6,8 +6,10 @@ import { serviceContainer, } from "../services/index.js"; import type { ToolPermissionServiceState } from "../services/ToolPermissionService.js"; +import type { ModelServiceState } from "../services/types.js"; import { telemetryService } from "../telemetry/telemetryService.js"; import { logger } from "../util/logger.js"; +import { isModelCapable } from "../utils/index.js"; import { editTool } from "./edit.js"; import { exitTool } from "./exit.js"; @@ -66,9 +68,53 @@ function getDynamicTools(): Tool[] { return dynamicTools; } -// Get all builtin tools including dynamic ones +// Check if the current model is capable and should exclude Edit tool +function shouldExcludeEditTool(): boolean { + try { + const modelServiceResult = getServiceSync( + SERVICE_NAMES.MODEL, + ); + + if ( + modelServiceResult.state === "ready" && + modelServiceResult.value?.model + ) { + const { name, provider } = modelServiceResult.value.model; + + // Check if model is capable + const isCapable = isModelCapable(provider, name, provider); + + logger.debug("Capability-based tool filtering", { + provider, + name, + isCapable, + willExcludeEdit: isCapable, + }); + + return isCapable; + } + } catch (error) { + logger.debug("Error checking model capability for tool filtering", { + error, + }); + } + return false; +} + +// Get all builtin tools including dynamic ones, with capability-based filtering export function getAllBuiltinTools(): Tool[] { - return [...BUILTIN_TOOLS, ...getDynamicTools()]; + let builtinTools = [...BUILTIN_TOOLS]; + + // Apply capability-based filtering for edit tools + // If model is capable, exclude editTool in favor of multiEditTool + if (shouldExcludeEditTool()) { + builtinTools = builtinTools.filter((tool) => tool.name !== editTool.name); + logger.debug( + "Excluded Edit tool for capable model - MultiEdit will be used instead", + ); + } + + return [...builtinTools, ...getDynamicTools()]; } export function getToolDisplayName(toolName: string): string { diff --git a/extensions/cli/src/tools/multiEdit.ts b/extensions/cli/src/tools/multiEdit.ts index 2164c6742..351a37afe 100644 --- a/extensions/cli/src/tools/multiEdit.ts +++ b/extensions/cli/src/tools/multiEdit.ts @@ -9,7 +9,6 @@ import { getLanguageFromFilePath, } from "../telemetry/utils.js"; -import { editTool } from "./edit.js"; import { readFilesSet, readFileTool } from "./readFile.js"; import { Tool } from "./types.js"; import { generateDiff } from "./writeFile.js"; @@ -133,8 +132,8 @@ export const multiEditTool: Tool = { displayName: "MultiEdit", readonly: false, isBuiltIn: true, - description: `This is a tool for making multiple edits to a single file in one operation. It is built on top of the ${editTool.name} tool and allows you to perform multiple find-and-replace operations efficiently. -Prefer this tool over the ${editTool.name} tool when you need to make multiple edits to the same file. + description: `This is a tool for making multiple edits to a single file in one operation. It allows you to perform multiple find-and-replace operations efficiently. +This tool is ideal when you need to make multiple edits to the same file. To make multiple edits to a file, provide the following: 1. file_path: The absolute path to the file to modify (must be absolute, not relative)