Skip to content

Commit 20a6fe1

Browse files
I've made some improvements to how I handle editing files. This should make my code modifications more robust and precise, especially for changes that involve multiple lines.
Here's a summary of what I've done: 1. **Enhanced File Editing Logic**: I've developed a new core way to reconstruct file content. It allows me to accurately replace, insert, or delete blocks of text based on the line numbers you specify. 2. **New Editing Capability**: I now have a primary way to make these precise file modifications. It takes the file path, the starting and ending line numbers for the change, and the new content. It also includes checks and allows you to review the changes. 3. **Updated Internal Guidance**: I've updated my internal understanding to use this new capability for all types of line and block edits, whether it's replacing, deleting, or inserting content. 4. **Streamlined My Approach**: I've consolidated some of my previous, more specific editing methods, as their functionality is now covered by this new, more comprehensive approach. This simplifies how I manage code changes. 5. **Ensured Effective Guidance**: I've confirmed that my existing instructions, combined with the details of this new editing capability, are sufficient to guide me effectively when I'm making changes to your code. This update aims to provide you with safer and more precise block-level edits.
1 parent 9134861 commit 20a6fe1

File tree

11 files changed

+337
-696
lines changed

11 files changed

+337
-696
lines changed

src/core/prompts/tools/delete-line.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/core/prompts/tools/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import { getFetchInstructionsDescription } from "./fetch-instructions"
1111
import { getWriteToFileDescription } from "./write-to-file"
1212
import { getSearchFilesDescription } from "./search-files"
1313
import { getListFilesDescription } from "./list-files"
14-
import { getInsertContentDescription } from "./insert-content"
14+
// Removed: import { getInsertContentDescription } from "./insert-content"
1515
import { getSearchAndReplaceDescription } from "./search-and-replace"
1616
import { getListCodeDefinitionNamesDescription } from "./list-code-definition-names"
17-
import { getDeleteLineDescription } from "./delete-line" // Added
18-
import { getReplaceLineDescription } from "./replace-line" // Added
17+
// Removed: import { getDeleteLineDescription } from "./delete-line" // Added
18+
// Removed: import { getReplaceLineDescription } from "./replace-line" // Added
1919
import { getUndoEditDescription } from "./undo-edit" // Added
20+
import { getReplaceTextRangeDescription } from "./replace-text-range"; // Added
2021
import { getBrowserActionDescription } from "./browser-action"
2122
import { getAskFollowupQuestionDescription } from "./ask-followup-question"
2223
import { getAttemptCompletionDescription } from "./attempt-completion"
@@ -44,11 +45,12 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
4445
codebase_search: () => getCodebaseSearchDescription(),
4546
switch_mode: () => getSwitchModeDescription(),
4647
new_task: (args) => getNewTaskDescription(args),
47-
insert_content: (args) => getInsertContentDescription(args),
48+
// Removed: insert_content: (args) => getInsertContentDescription(args),
4849
search_and_replace: (args) => getSearchAndReplaceDescription(args),
49-
delete_line: (args) => getDeleteLineDescription(args), // Added
50-
replace_line: (args) => getReplaceLineDescription(args), // Added
50+
// Removed: delete_line: (args) => getDeleteLineDescription(args), // Added
51+
// Removed: replace_line: (args) => getReplaceLineDescription(args), // Added
5152
undo_edit: (args) => getUndoEditDescription(args), // Added
53+
replace_text_range: (args) => getReplaceTextRangeDescription(args), // Added
5254
apply_diff: (args) =>
5355
args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "",
5456
}
@@ -143,10 +145,11 @@ export {
143145
getUseMcpToolDescription,
144146
getAccessMcpResourceDescription,
145147
getSwitchModeDescription,
146-
getInsertContentDescription,
148+
// Removed: getInsertContentDescription,
147149
getSearchAndReplaceDescription,
148150
getCodebaseSearchDescription,
149-
getDeleteLineDescription, // Added
150-
getReplaceLineDescription, // Added
151+
// Removed: getDeleteLineDescription, // Added
152+
// Removed: getReplaceLineDescription, // Added
151153
getUndoEditDescription, // Added
154+
getReplaceTextRangeDescription, // Added
152155
}

src/core/prompts/tools/insert-content.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/core/prompts/tools/replace-line.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ToolArgs } from "./types";
2+
3+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4+
export function getReplaceTextRangeDescription(args: ToolArgs): string {
5+
return `
6+
<tool_description>
7+
<tool_name>replace_text_range</tool_name>
8+
<description>Replaces a range of lines in a file with new content. This is the primary tool for all line-level and block-level modifications.
9+
- To **replace** lines L to M: use start_line=L, end_line=M, and provide the new_content.
10+
- To **delete** lines L to M: use start_line=L, end_line=M, and provide an empty string for new_content.
11+
- To **insert** new_content *before* line L: use start_line=L, end_line=L-1, and provide the new_content. (e.g., to insert before line 1, use start_line=1, end_line=0).
12+
- To **append** new_content *after* the last line (N): use start_line=N+1, end_line=N, and provide new_content.</description>
13+
<parameters>
14+
<parameter>
15+
<name>path</name>
16+
<type>string</type>
17+
<description>The relative path to the file.</description>
18+
</parameter>
19+
<parameter>
20+
<name>start_line</name>
21+
<type>integer</type>
22+
<description>The 1-indexed line number for the start of the range (inclusive). For insertion before line L, this is L. For appending after the last line N, this is N+1.</description>
23+
</parameter>
24+
<parameter>
25+
<name>end_line</name>
26+
<type>integer</type>
27+
<description>The 1-indexed line number for the end of the range (inclusive). For insertion before line L, this is L-1. For appending after the last line N, this is N. For replacing/deleting a single line L, end_line is L.</description>
28+
</parameter>
29+
<parameter>
30+
<name>new_content</name>
31+
<type>string</type>
32+
<description>The new content for the specified range. This can be multi-line. For deletion, provide an empty string ("").</description>
33+
</parameter>
34+
</parameters>
35+
</tool_description>
36+
`.trim();
37+
}

src/core/tools/deleteLineTool.ts

Lines changed: 0 additions & 185 deletions
This file was deleted.

0 commit comments

Comments
 (0)