mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-02 23:23:45 +00:00
tweak(edit): separate edit tool error message with clearer guidance to avoid llm doom editing loop (#2051)
This commit is contained in:
committed by
GitHub
parent
66a5d58221
commit
900fe5ca04
@@ -594,6 +594,8 @@ export function replace(content: string, oldString: string, newString: string, r
|
||||
throw new Error("oldString and newString must be different")
|
||||
}
|
||||
|
||||
let notFound = true
|
||||
|
||||
for (const replacer of [
|
||||
SimpleReplacer,
|
||||
LineTrimmedReplacer,
|
||||
@@ -608,6 +610,7 @@ export function replace(content: string, oldString: string, newString: string, r
|
||||
for (const search of replacer(content, oldString)) {
|
||||
const index = content.indexOf(search)
|
||||
if (index === -1) continue
|
||||
notFound = false
|
||||
if (replaceAll) {
|
||||
return content.replaceAll(search, newString)
|
||||
}
|
||||
@@ -616,5 +619,9 @@ export function replace(content: string, oldString: string, newString: string, r
|
||||
return content.substring(0, index) + newString + content.substring(index + search.length)
|
||||
}
|
||||
}
|
||||
throw new Error("oldString not found in content or was found multiple times")
|
||||
|
||||
if (notFound) {
|
||||
throw new Error("oldString not found in content")
|
||||
}
|
||||
throw new Error("oldString found multiple times and requires more code context to uniquely identify the intended match")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user