Skip to content

Commit e925e7b

Browse files
authored
Merge pull request #6970 from continuedev/dallin/search-replace-read-file
fix: always read file before search and replace
2 parents 7d54246 + 7401a3a commit e925e7b

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

core/tools/definitions/searchAndReplaceInFile.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ export interface SearchAndReplaceInFileArgs {
1111
export const NO_PARALLEL_TOOL_CALLING_INSRUCTION =
1212
"Note this tool CANNOT be called in parallel.";
1313

14-
const SEARCH_AND_REPLACE_TOOL_DESCRIPTION = `Request to replace sections of content in an existing file using multiple SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file. ${NO_PARALLEL_TOOL_CALLING_INSRUCTION}`;
15-
const SEARCH_AND_REPLACE_FILEPATH_DESCRIPTION =
16-
"The path of the file to modify, relative to the root of the workspace.";
1714
const SEARCH_AND_REPLACE_EXAMPLE_BLOCK = `------- SEARCH
1815
[exact content to find]
1916
=======
@@ -40,7 +37,8 @@ const SEARCH_AND_REPLACE_RULES = `Critical rules:
4037
* DO NOT make back-to-back tool calls. Instead interleave with brief explanation of what each will do. For example, instead of [explanation, tool call, tool call] you should do [explanation, tool call, explanation, tool call]
4138
6. Special operations:
4239
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
43-
* To delete code: Use empty REPLACE section`;
40+
* To delete code: Use empty REPLACE section
41+
7. You should always read the file before trying to edit it, to ensure you know the up-to-date file contents`;
4442

4543
const SEARCH_AND_REPLACE_DIFFS_DESCRIPTION = `An array of strings, each containing one or more SEARCH/REPLACE blocks following this exact format:
4644
\`\`\`
@@ -73,14 +71,14 @@ export const searchAndReplaceInFileTool: Tool = {
7371
isInstant: false,
7472
function: {
7573
name: BuiltInToolNames.SearchAndReplaceInFile,
76-
description: SEARCH_AND_REPLACE_TOOL_DESCRIPTION,
74+
description: `Request to replace sections of content in an existing file using multiple SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file. ${NO_PARALLEL_TOOL_CALLING_INSRUCTION}`,
7775
parameters: {
7876
type: "object",
7977
required: ["filepath", "diffs"],
8078
properties: {
8179
filepath: {
8280
type: "string",
83-
description: SEARCH_AND_REPLACE_FILEPATH_DESCRIPTION,
81+
description: `The path of the file to modify, relative to the root of the workspace.`,
8482
},
8583
diffs: {
8684
type: "array",
@@ -94,7 +92,7 @@ export const searchAndReplaceInFileTool: Tool = {
9492
},
9593
systemMessageDescription: createSystemMessageExampleCall(
9694
BuiltInToolNames.SearchAndReplaceInFile,
97-
`To make targeted edits by replacing sections of content in an existing file, use the ${BuiltInToolNames.SearchAndReplaceInFile} tool with a "diffs" argument containing an array of SEARCH/REPLACE blocks that define exact changes to specific parts of the file.
95+
`To make targeted edits by replacing sections of content in an existing file, use the ${BuiltInToolNames.SearchAndReplaceInFile} tool with a filepath (relative to the root of the workspace) and a "diffs" argument containing an array of SEARCH/REPLACE blocks that define exact changes to specific parts of the file.
9896
Each block should follow this format:
9997
${SEARCH_AND_REPLACE_EXAMPLE_BLOCK}
10098
@@ -106,16 +104,8 @@ ${SEARCH_AND_REPLACE_RULES}
106104
[
107105
"diffs",
108106
`[
109-
"------- SEARCH
110-
[exact content to find]
111-
=======
112-
[new content to replace with]
113-
+++++++ REPLACE",
114-
"------- SEARCH
115-
[exact content to find]
116-
=======
117-
[new content to replace with]
118-
+++++++ REPLACE"
107+
"${SEARCH_AND_REPLACE_EXAMPLE_BLOCK}",
108+
"${SEARCH_AND_REPLACE_EXAMPLE_BLOCK}"
119109
]`,
120110
],
121111
],

0 commit comments

Comments
 (0)