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
`The old string ${JSON.stringify(oldStr)} was not found in the file, skipping. Please try again with a different old string that matches the file content exactly.`,
// count the number of occurrences of oldStr in initialContent
124
+
constcount=initialContent.split(oldStr).length-1
125
+
if(count===1){
126
+
return{success: true, oldStr }
127
+
}
128
+
if(!allowMultiple&&count>1){
129
+
return{
130
+
success: false,
131
+
error: `Found ${count} occurrences of ${JSON.stringify(oldStr)} in the file. Please try again with a longer (more specified) old string or set allowMultiple to true.`,
// Try matching without any whitespace as a last resort
132
145
constnoWhitespaceSearch=oldStr.replace(/\s+/g,'')
@@ -164,9 +177,12 @@ const tryMatchOldStr = (
164
177
)
165
178
if(initialContent.includes(actualContent)){
166
179
logger.debug('Matched with whitespace removed')
167
-
returnactualContent
180
+
return{success: true,oldStr: actualContent}
168
181
}
169
182
}
170
183
}
171
-
returnnull
184
+
return{
185
+
success: false,
186
+
error: `The old string ${JSON.stringify(oldStr)} was not found in the file, skipping. Please try again with a different old string that matches the file content exactly.`,
Use this tool to make edits within existing files. Prefer this tool over the write_file tool for existing files, unless you need to make major changes throughout the file, in which case use write_file.
12
10
13
11
Important:
14
-
If you are making multiple edits in a row to a file, use only one <str_replace> call with multiple replacements instead of multiple str_replace tool calls.
15
-
16
-
Don't forget to close the <str_replace> tag with ${closeXml('str_replace')} after you have finished making all the replacements.
12
+
If you are making multiple edits in a row to a file, use only one str_replace call with multiple replacements instead of multiple str_replace tool calls.
0 commit comments