The open source coding agent.
TypeScript
core: tweak edit and write tool outputs to prevent agent from thinking edit didn't apply
Aiden Cline66f9bdab32b2
diff --git a/packages/opencode/src/tool/edit.ts b/packages/opencode/src/tool/edit.tsindex b68078f1428..7ace4e4a262 100644--- a/packages/opencode/src/tool/edit.ts+++ b/packages/opencode/src/tool/edit.ts@@ -119,7 +119,7 @@ export const EditTool = Tool.define("edit", {},})- let output = ""+ let output = "Edit applied successfully."await LSP.touchFile(filePath, true)const diagnostics = await LSP.diagnostics()const normalizedFilePath = Filesystem.normalizePath(filePath)@@ -129,7 +129,7 @@ export const EditTool = Tool.define("edit", {const limited = errors.slice(0, MAX_DIAGNOSTICS_PER_FILE)const suffix =errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""- output += `\nThis file has errors, please fix\n<file_diagnostics>\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</file_diagnostics>\n`+ output += `\n\nLSP errors detected in this file:\n<diagnostics file="${filePath}">\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</diagnostics>`}return {diff --git a/packages/opencode/src/tool/write.ts b/packages/opencode/src/tool/write.tsindex 222bac3f8fb..d621a6e26bf 100644--- a/packages/opencode/src/tool/write.ts+++ b/packages/opencode/src/tool/write.ts@@ -47,7 +47,7 @@ export const WriteTool = Tool.define("write", {})FileTime.read(ctx.sessionID, filepath)- let output = ""+ let output = "Wrote file successfully."await LSP.touchFile(filepath, true)const diagnostics = await LSP.diagnostics()const normalizedFilepath = Filesystem.normalizePath(filepath)@@ -59,12 +59,12 @@ export const WriteTool = Tool.define("write", {const suffix =errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""if (file === normalizedFilepath) {- output += `\nThis file has errors, please fix\n<file_diagnostics>\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</file_diagnostics>\n`+ output += `\n\nLSP errors detected in this file:\n<diagnostics file="${filepath}">\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</diagnostics>`continue}if (projectDiagnosticsCount >= MAX_PROJECT_DIAGNOSTICS_FILES) continueprojectDiagnosticsCount++- output += `\n<project_diagnostics>\n${file}\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</project_diagnostics>\n`+ output += `\n\nLSP errors detected in other files:\n<diagnostics file="${file}">\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</diagnostics>`}return {