Skip to content

Commit 22b04d0

Browse files
committed
Restore apply_diff tool, correctly controlled by diffEnabled.
1 parent 3e2c3dd commit 22b04d0

File tree

8 files changed

+24
-9
lines changed

8 files changed

+24
-9
lines changed

packages/types/src/tool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const toolNames = [
3333
"fetch_instructions",
3434
"codebase_search",
3535
// kilocode_change start
36+
"search_and_replace",
3637
"edit_file",
3738
"new_rule",
3839
"report_bug",

src/core/prompts/tools/__tests__/filter-tools-for-mode.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ describe("filterNativeToolsForMode", () => {
118118
// Should include all tools (code mode has all groups)
119119
expect(toolNames).toContain("read_file")
120120
expect(toolNames).toContain("write_to_file")
121-
expect(toolNames).toContain("apply_diff")
122121
expect(toolNames).toContain("execute_command")
123122
expect(toolNames).toContain("browser_action")
124123
expect(toolNames).toContain("ask_followup_question")

src/core/prompts/tools/filter-tools-for-mode.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ export function filterNativeToolsForMode(
9797
allowedToolNames.delete("run_slash_command")
9898
}
9999

100+
// Conditionally exclude run_slash_command if experiment is not enabled
101+
if (!experiments?.runSlashCommand) {
102+
allowedToolNames.delete("run_slash_command")
103+
}
104+
105+
// Conditionally exclude apply_diff if disabled in settings
106+
if (state?.apiConfiguration?.diffEnabled != true) {
107+
allowedToolNames.delete("apply_diff")
108+
} else {
109+
allowedToolNames.add("search_and_replace")
110+
}
111+
100112
// Conditionally exclude browser_action if disabled in settings
101113
if (
102114
settings?.browserToolEnabled === false ||

src/core/prompts/tools/native-tools/apply_diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type OpenAI from "openai"
22

3-
export const apply_diff_single_file = {
3+
export const apply_diff = {
44
type: "function",
55
function: {
66
name: "apply_diff",

src/core/prompts/tools/native-tools/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import searchFiles from "./search_files"
1616
import switchMode from "./switch_mode"
1717
import updateTodoList from "./update_todo_list"
1818
import writeToFile from "./write_to_file"
19-
// import { apply_diff_single_file } from "./apply_diff" // kilocode_change
19+
import { apply_diff } from "./apply_diff" // kilocode_change
2020

2121
import searchAndReplace from "./kilocode/search_and_replace"
2222
import deleteFile from "./kilocode/delete_file"
@@ -47,6 +47,7 @@ export const nativeTools = [
4747
listFiles,
4848
newTask,
4949
read_file,
50+
apply_diff, //kilocode_change
5051
runSlashCommand,
5152
searchFiles,
5253
switchMode,

src/core/prompts/tools/native-tools/kilocode/search_and_replace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type SearchAndReplaceParameters = z.infer<typeof SearchAndReplaceParamete
1616
export default {
1717
type: "function",
1818
function: {
19-
name: "apply_diff",
19+
name: "search_and_replace",
2020
description: "Replace a specific string in a file with a new string. This is used for making precise edits.",
2121
strict: true,
2222
parameters: z.toJSONSchema(SearchAndReplaceParametersSchema),

src/core/tools/kilocode/searchAndReplaceTool.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export async function searchAndReplaceTool(
100100

101101
if (!fileExists) {
102102
cline.consecutiveMistakeCount++
103-
cline.recordToolError("apply_diff", "file_does_not_exist")
103+
cline.recordToolError("search_and_replace", "file_does_not_exist")
104104
const formattedError = formatResponse.toolError(
105105
`File does not exist at path: ${absolutePath}\nThe specified file could not be found. Please verify the file path and try again.`,
106106
)
@@ -118,7 +118,7 @@ export async function searchAndReplaceTool(
118118
fileContent = await fs.readFile(absolutePath, "utf-8")
119119
} catch (error) {
120120
cline.consecutiveMistakeCount++
121-
cline.recordToolError("apply_diff", "exception")
121+
cline.recordToolError("search_and_replace", "exception")
122122
const errorMessage = `Error reading file: ${absolutePath}\nFailed to read the file content: ${
123123
error instanceof Error ? error.message : String(error)
124124
}\nPlease verify file permissions and try again.`
@@ -138,7 +138,7 @@ export async function searchAndReplaceTool(
138138
const matchCount = fileContent.match(searchPattern)?.length ?? 0
139139
if (matchCount > 1) {
140140
cline.consecutiveMistakeCount++
141-
cline.recordToolError("apply_diff", "multiple_matches")
141+
cline.recordToolError("search_and_replace", "multiple_matches")
142142
pushToolResult(
143143
formatResponse.toolError(
144144
`Found ${matchCount} matches for replacement text. Please provide more context to make a unique match.`,
@@ -156,7 +156,7 @@ export async function searchAndReplaceTool(
156156
const diff = formatResponse.createPrettyPatch(validRelPath, fileContent, newContent)
157157
if (!diff) {
158158
cline.consecutiveMistakeCount++
159-
cline.recordToolError("apply_diff", "no_match")
159+
cline.recordToolError("search_and_replace", "no_match")
160160
pushToolResult(
161161
formatResponse.toolError(
162162
`No match found for replacement in '${validRelPath}'. Please check your text and try again.`,
@@ -227,7 +227,7 @@ export async function searchAndReplaceTool(
227227
pushToolResult(message)
228228

229229
// Record successful tool usage and cleanup
230-
cline.recordToolUsage("apply_diff")
230+
cline.recordToolUsage("search_and_replace")
231231
await cline.diffViewProvider.reset()
232232

233233
// Process any queued messages after file edit completes

src/shared/tools.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export const TOOL_DISPLAY_NAMES: Record<ToolName, string> = {
253253
write_to_file: "write files",
254254
apply_diff: "apply changes",
255255
// kilocode_change start
256+
search_and_replace: "search and replace contents in files",
256257
edit_file: "edit file",
257258
delete_file: "delete files",
258259
report_bug: "report bug",
@@ -291,6 +292,7 @@ export const TOOL_GROUPS: Record<ToolGroup, ToolGroupConfig> = {
291292
edit: {
292293
tools: [
293294
"apply_diff",
295+
"search_and_replace", // kilocode_change
294296
"edit_file", // kilocode_change: Morph fast apply
295297
"write_to_file",
296298
"delete_file", // kilocode_change

0 commit comments

Comments
 (0)