mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 06:32:43 +00:00
fix(agents): only recover edit when oldText no longer in file (review feedback)
This commit is contained in:
committed by
Peter Steinberger
parent
bf6aa7ca67
commit
0fb3f188b2
@@ -717,13 +717,25 @@ function wrapHostEditToolWithPostWriteRecovery(base: AnyAgentTool, root: string)
|
||||
: record && typeof record.new_string === "string"
|
||||
? record.new_string
|
||||
: undefined;
|
||||
const oldText =
|
||||
record && typeof record.oldText === "string"
|
||||
? record.oldText
|
||||
: record && typeof record.old_string === "string"
|
||||
? record.old_string
|
||||
: undefined;
|
||||
if (!pathParam || !newText) {
|
||||
throw err;
|
||||
}
|
||||
try {
|
||||
const absolutePath = resolveHostEditPath(root, pathParam);
|
||||
const content = await fs.readFile(absolutePath, "utf-8");
|
||||
if (content.includes(newText)) {
|
||||
// Only recover when the replacement likely occurred: newText is present and oldText
|
||||
// is no longer present. This avoids false success when upstream threw before writing
|
||||
// (e.g. oldText not found) but the file already contained newText (review feedback).
|
||||
const hasNew = content.includes(newText);
|
||||
const stillHasOld =
|
||||
oldText !== undefined && oldText.length > 0 && content.includes(oldText);
|
||||
if (hasNew && !stillHasOld) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user