feat: exclude single file edit for capable models
This commit is contained in:
parent
24df311fbb
commit
fb3d6dd7f1
3 changed files with 51 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<ModelServiceState>(
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue