Skip to content

Commit 624dd94

Browse files
authored
tweak: tool outputs to be more llm friendly (#13269)
1 parent d86f24b commit 624dd94

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

packages/opencode/src/tool/edit.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const EditTool = Tool.define("edit", {
3838
}
3939

4040
if (params.oldString === params.newString) {
41-
throw new Error("oldString and newString must be different")
41+
throw new Error("No changes to apply: oldString and newString are identical.")
4242
}
4343

4444
const filePath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
@@ -617,7 +617,7 @@ export function trimDiff(diff: string): string {
617617

618618
export function replace(content: string, oldString: string, newString: string, replaceAll = false): string {
619619
if (oldString === newString) {
620-
throw new Error("oldString and newString must be different")
620+
throw new Error("No changes to apply: oldString and newString are identical.")
621621
}
622622

623623
let notFound = true
@@ -647,9 +647,9 @@ export function replace(content: string, oldString: string, newString: string, r
647647
}
648648

649649
if (notFound) {
650-
throw new Error("oldString not found in content")
650+
throw new Error(
651+
"Could not find oldString in the file. It must match exactly, including whitespace, indentation, and line endings.",
652+
)
651653
}
652-
throw new Error(
653-
"Found multiple matches for oldString. Provide more surrounding lines in oldString to identify the correct match.",
654-
)
654+
throw new Error("Found multiple matches for oldString. Provide more surrounding context to make the match unique.")
655655
}

packages/opencode/src/tool/glob.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ export const GlobTool = Tool.define("glob", {
6262
output.push(...files.map((f) => f.path))
6363
if (truncated) {
6464
output.push("")
65-
output.push("(Results are truncated. Consider using a more specific path or pattern.)")
65+
output.push(
66+
`(Results are truncated: showing first ${limit} results. Consider using a more specific path or pattern.)`,
67+
)
6668
}
6769
}
6870

packages/opencode/src/tool/grep.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ export const GrepTool = Tool.define("grep", {
109109
}
110110
}
111111

112-
const outputLines = [`Found ${finalMatches.length} matches`]
112+
const totalMatches = matches.length
113+
const outputLines = [`Found ${totalMatches} matches${truncated ? ` (showing first ${limit})` : ""}`]
113114

114115
let currentFile = ""
115116
for (const match of finalMatches) {
@@ -127,7 +128,9 @@ export const GrepTool = Tool.define("grep", {
127128

128129
if (truncated) {
129130
outputLines.push("")
130-
outputLines.push("(Results are truncated. Consider using a more specific path or pattern.)")
131+
outputLines.push(
132+
`(Results truncated: showing ${limit} of ${totalMatches} matches (${totalMatches - limit} hidden). Consider using a more specific path or pattern.)`,
133+
)
131134
}
132135

133136
if (hasErrors) {
@@ -138,7 +141,7 @@ export const GrepTool = Tool.define("grep", {
138141
return {
139142
title: params.pattern,
140143
metadata: {
141-
matches: finalMatches.length,
144+
matches: totalMatches,
142145
truncated,
143146
},
144147
output: outputLines.join("\n"),

0 commit comments

Comments
 (0)