You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
oldString: z.string().describe("The text to replace"),
25
25
newString: z.string().describe("The text to replace it with (must be different from oldString)"),
26
26
replaceAll: z.boolean().optional().describe("Replace all occurrences of oldString (default false)"),
27
+
range: z
28
+
.string()
29
+
.optional()
30
+
.describe(
31
+
"Line range in format 'start:end' (e.g., '140:233') - inclusive of both start and end lines. When provided, restricts oldString matching to the range. Ensures strong match performance.",
@@ -621,6 +648,6 @@ export function replace(content: string, oldString: string, newString: string, r
621
648
thrownewError("oldString not found in content")
622
649
}
623
650
thrownewError(
624
-
"oldString found multiple times and requires more code context to uniquely identify the intended match",
651
+
"oldString found multiple times. Either use the `range` parameter or provide more code context to uniquely identify the intended match. You can also use `replaceAll`: true to replace all instances of oldString (make sure this is intentional).",
Copy file name to clipboardExpand all lines: packages/opencode/src/tool/edit.txt
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ Usage:
6
6
- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
7
7
- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
8
8
- Use `replaceAll` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.
9
+
- Use `range` to specify a line range (e.g., '140:233') when `oldString` appears multiple times in the file. The range restricts the search and replacement to only those lines, allowing you to disambiguate which occurrence to replace.
9
10
10
11
CRITICAL:
11
12
- ALWAYS MAKE SURE TO SUPPLY SUFFICIENT CONTEXT TO UNIQUELY IDENTIFY `oldString` OTHERWISE THE EDIT WILL FAIL
13
+
- SPECIFYING THE RANGE OF THE EDIT WILL ENSURE BETTER `oldString` MATCHING
0 commit comments