Skip to content

Commit 66f9bda

Browse files
committed
core: tweak edit and write tool outputs to prevent agent from thinking edit didn't apply
1 parent efaa916 commit 66f9bda

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

packages/opencode/src/tool/edit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const EditTool = Tool.define("edit", {
119119
},
120120
})
121121

122-
let output = ""
122+
let output = "Edit applied successfully."
123123
await LSP.touchFile(filePath, true)
124124
const diagnostics = await LSP.diagnostics()
125125
const normalizedFilePath = Filesystem.normalizePath(filePath)
@@ -129,7 +129,7 @@ export const EditTool = Tool.define("edit", {
129129
const limited = errors.slice(0, MAX_DIAGNOSTICS_PER_FILE)
130130
const suffix =
131131
errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""
132-
output += `\nThis file has errors, please fix\n<file_diagnostics>\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</file_diagnostics>\n`
132+
output += `\n\nLSP errors detected in this file:\n<diagnostics file="${filePath}">\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</diagnostics>`
133133
}
134134

135135
return {

packages/opencode/src/tool/write.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const WriteTool = Tool.define("write", {
4747
})
4848
FileTime.read(ctx.sessionID, filepath)
4949

50-
let output = ""
50+
let output = "Wrote file successfully."
5151
await LSP.touchFile(filepath, true)
5252
const diagnostics = await LSP.diagnostics()
5353
const normalizedFilepath = Filesystem.normalizePath(filepath)
@@ -59,12 +59,12 @@ export const WriteTool = Tool.define("write", {
5959
const suffix =
6060
errors.length > MAX_DIAGNOSTICS_PER_FILE ? `\n... and ${errors.length - MAX_DIAGNOSTICS_PER_FILE} more` : ""
6161
if (file === normalizedFilepath) {
62-
output += `\nThis file has errors, please fix\n<file_diagnostics>\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</file_diagnostics>\n`
62+
output += `\n\nLSP errors detected in this file:\n<diagnostics file="${filepath}">\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</diagnostics>`
6363
continue
6464
}
6565
if (projectDiagnosticsCount >= MAX_PROJECT_DIAGNOSTICS_FILES) continue
6666
projectDiagnosticsCount++
67-
output += `\n<project_diagnostics>\n${file}\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</project_diagnostics>\n`
67+
output += `\n\nLSP errors detected in other files:\n<diagnostics file="${file}">\n${limited.map(LSP.Diagnostic.pretty).join("\n")}${suffix}\n</diagnostics>`
6868
}
6969

7070
return {

0 commit comments

Comments
 (0)