Skip to content

Commit 9134861

Browse files
Hi there! I've just received an update that enhances my abilities to help you with your code.
This update brings several improvements: **Editing Enhancements:** * I can now view specific line ranges within your files more effectively, including reading all the way to the end of a file. * When searching and replacing text, I have a new option to ensure that a specific string is found exactly once before making a change. My existing capabilities for broader searches are still available. * I'm now more careful when inserting content, ensuring the line numbers you provide are valid for the file. * I have new ways to manage lines: I can now delete a specific line or replace a specific line with new content. * I can now undo the last approved edit I made to a file. This means I'm keeping track of changes as I make them. * I've become better at validating the context of changes before applying them. This helps prevent unintended large-scale modifications to your files by checking for overall file similarity and how much the line count has changed. **Core Logic Improvements:** * I'm now better equipped to make multiple attempts at solving a problem if the first try isn't successful. This involves a more structured approach to trying different solutions. * I can now validate the changes I'm proposing more effectively, checking if they are empty, make no real difference, or only modify test files. This helps me provide better feedback sooner. These changes are designed to make me more precise, robust, and strategic in how I approach code manipulation and problem-solving for you.
1 parent 39d6535 commit 9134861

18 files changed

+1262
-48
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ToolArgs } from "./types";
2+
3+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4+
export function getDeleteLineDescription(args: ToolArgs): string {
5+
return `
6+
<tool_description>
7+
<tool_name>delete_line</tool_name>
8+
<description>Deletes a specific line from a file.</description>
9+
<parameters>
10+
<parameter>
11+
<name>path</name>
12+
<type>string</type>
13+
<description>The relative path to the file.</description>
14+
</parameter>
15+
<parameter>
16+
<name>line_number</name>
17+
<type>integer</type>
18+
<description>The 1-indexed line number to delete. Must be within the file's line bounds.</description>
19+
</parameter>
20+
</parameters>
21+
</tool_description>
22+
`.trim();
23+
}

src/core/prompts/tools/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { getListFilesDescription } from "./list-files"
1414
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
19+
import { getUndoEditDescription } from "./undo-edit" // Added
1720
import { getBrowserActionDescription } from "./browser-action"
1821
import { getAskFollowupQuestionDescription } from "./ask-followup-question"
1922
import { getAttemptCompletionDescription } from "./attempt-completion"
@@ -43,6 +46,9 @@ const toolDescriptionMap: Record<string, (args: ToolArgs) => string | undefined>
4346
new_task: (args) => getNewTaskDescription(args),
4447
insert_content: (args) => getInsertContentDescription(args),
4548
search_and_replace: (args) => getSearchAndReplaceDescription(args),
49+
delete_line: (args) => getDeleteLineDescription(args), // Added
50+
replace_line: (args) => getReplaceLineDescription(args), // Added
51+
undo_edit: (args) => getUndoEditDescription(args), // Added
4652
apply_diff: (args) =>
4753
args.diffStrategy ? args.diffStrategy.getToolDescription({ cwd: args.cwd, toolOptions: args.toolOptions }) : "",
4854
}
@@ -140,4 +146,7 @@ export {
140146
getInsertContentDescription,
141147
getSearchAndReplaceDescription,
142148
getCodebaseSearchDescription,
149+
getDeleteLineDescription, // Added
150+
getReplaceLineDescription, // Added
151+
getUndoEditDescription, // Added
143152
}

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ Description: Use this tool specifically for adding new lines of content into a f
66
77
Parameters:
88
- path: (required) File path relative to workspace directory ${args.cwd.toPosix()}
9-
- line: (required) Line number where content will be inserted (1-based)
10-
Use 0 to append at end of file
11-
Use any positive number to insert before that line
12-
- content: (required) The content to insert at the specified line
9+
- line: (required) Line number where content will be inserted (1-based). Must be between 1 and N+1 (where N is the current number of lines in the file), inclusive. Use 1 to insert at the beginning of the file. Use N+1 to append at the end of the file (or use 0, which is an alias for N+1).
10+
- content: (required) The content to insert. Can be multiple lines.
1311
1412
Example for inserting imports at start of file:
1513
<insert_content>
@@ -21,12 +19,21 @@ import { sum } from './math';
2119
</content>
2220
</insert_content>
2321
24-
Example for appending to the end of file:
22+
Example for appending to the end of file (using N+1, assuming file has 100 lines, so insert at 101):
23+
<insert_content>
24+
<path>src/utils.ts</path>
25+
<line>101</line>
26+
<content>
27+
// This is appended to the end of the file
28+
</content>
29+
</insert_content>
30+
31+
Example for appending to the end of file (using 0):
2532
<insert_content>
2633
<path>src/utils.ts</path>
2734
<line>0</line>
2835
<content>
29-
// This is the end of the file
36+
// This is also appended to the end of the file
3037
</content>
3138
</insert_content>
3239
`

src/core/prompts/tools/read-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ${args.partialReadsEnabled ? `By specifying line ranges, you can efficiently rea
1313
Parameters:
1414
- args: Contains one or more file elements, where each file contains:
1515
- path: (required) File path (relative to workspace directory ${args.cwd})
16-
${args.partialReadsEnabled ? `- line_range: (optional) One or more line range elements in format "start-end" (1-based, inclusive)` : ""}
16+
${args.partialReadsEnabled ? `- line_range: (optional) One or more line range elements in format "START-END" (1-based, inclusive). END can be -1 to read until the end of the file.` : ""}
1717
1818
Usage:
1919
<read_file>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { ToolArgs } from "./types";
2+
3+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4+
export function getReplaceLineDescription(args: ToolArgs): string {
5+
return `
6+
<tool_description>
7+
<tool_name>replace_line</tool_name>
8+
<description>Replaces a specific line in a file with new content. The new content must not contain newline characters.</description>
9+
<parameters>
10+
<parameter>
11+
<name>path</name>
12+
<type>string</type>
13+
<description>The relative path to the file.</description>
14+
</parameter>
15+
<parameter>
16+
<name>line_number</name>
17+
<type>integer</type>
18+
<description>The 1-indexed line number to replace. Must be within the file's line bounds.</description>
19+
</parameter>
20+
<parameter>
21+
<name>content</name>
22+
<type>string</type>
23+
<description>The new content for the line. Must not contain newline characters.</description>
24+
</parameter>
25+
</parameters>
26+
</tool_description>
27+
`.trim();
28+
}

src/core/prompts/tools/search-and-replace.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ Optional Parameters:
1414
- end_line: Ending line number for restricted replacement (1-based)
1515
- use_regex: Set to "true" to treat search as a regex pattern (default: false)
1616
- ignore_case: Set to "true" to ignore case when matching (default: false)
17+
- requireUniqueMatch: Set to "true" to ensure only one match is found and replaced (default: false). If true, 'search' is a literal string, 'use_regex' is ignored for matching (though 'ignore_case' is still respected). If 0 or >1 matches, an error occurs.
1718
1819
Notes:
19-
- When use_regex is true, the search parameter is treated as a regular expression pattern
20-
- When ignore_case is true, the search is case-insensitive regardless of regex mode
20+
- When use_regex is true (and requireUniqueMatch is false), the search parameter is treated as a regular expression pattern.
21+
- When ignore_case is true, the search is case-insensitive.
22+
- If requireUniqueMatch is true, the 'search' string is treated as a literal string and the tool will only perform a replacement if exactly one occurrence is found. 'use_regex' is ignored for matching purposes if requireUniqueMatch is true (though 'ignore_case' is still respected for the literal match). If 0 or more than 1 match is found, an error is returned.
2123
2224
Examples:
2325
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { ToolArgs } from "./types";
2+
3+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4+
export function getUndoEditDescription(args: ToolArgs): string {
5+
return `
6+
<tool_description>
7+
<tool_name>undo_edit</tool_name>
8+
<description>Reverts the last approved edit made to a file using Roo's editing tools. If multiple edits were made to the same file, it undoes the most recent one for which history is available.</description>
9+
<parameters>
10+
<parameter>
11+
<name>path</name>
12+
<type>string</type>
13+
<description>The relative path to the file to undo an edit for.</description>
14+
</parameter>
15+
</parameters>
16+
</tool_description>
17+
`.trim();
18+
}

0 commit comments

Comments
 (0)