tweak: tool outputs to be more llm friendly (#13269)

This commit is contained in:
Aiden Cline
2026-02-12 00:33:18 -06:00
committed by GitHub
parent d86f24b6b3
commit 624dd94b5d
3 changed files with 15 additions and 10 deletions

View File

@@ -38,7 +38,7 @@ export const EditTool = Tool.define("edit", {
} }
if (params.oldString === params.newString) { if (params.oldString === params.newString) {
throw new Error("oldString and newString must be different") throw new Error("No changes to apply: oldString and newString are identical.")
} }
const filePath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath) const filePath = path.isAbsolute(params.filePath) ? params.filePath : path.join(Instance.directory, params.filePath)
@@ -617,7 +617,7 @@ export function trimDiff(diff: string): string {
export function replace(content: string, oldString: string, newString: string, replaceAll = false): string { export function replace(content: string, oldString: string, newString: string, replaceAll = false): string {
if (oldString === newString) { if (oldString === newString) {
throw new Error("oldString and newString must be different") throw new Error("No changes to apply: oldString and newString are identical.")
} }
let notFound = true let notFound = true
@@ -647,9 +647,9 @@ export function replace(content: string, oldString: string, newString: string, r
} }
if (notFound) { if (notFound) {
throw new Error("oldString not found in content") throw new Error(
"Could not find oldString in the file. It must match exactly, including whitespace, indentation, and line endings.",
)
} }
throw new Error( throw new Error("Found multiple matches for oldString. Provide more surrounding context to make the match unique.")
"Found multiple matches for oldString. Provide more surrounding lines in oldString to identify the correct match.",
)
} }

View File

@@ -62,7 +62,9 @@ export const GlobTool = Tool.define("glob", {
output.push(...files.map((f) => f.path)) output.push(...files.map((f) => f.path))
if (truncated) { if (truncated) {
output.push("") output.push("")
output.push("(Results are truncated. Consider using a more specific path or pattern.)") output.push(
`(Results are truncated: showing first ${limit} results. Consider using a more specific path or pattern.)`,
)
} }
} }

View File

@@ -109,7 +109,8 @@ export const GrepTool = Tool.define("grep", {
} }
} }
const outputLines = [`Found ${finalMatches.length} matches`] const totalMatches = matches.length
const outputLines = [`Found ${totalMatches} matches${truncated ? ` (showing first ${limit})` : ""}`]
let currentFile = "" let currentFile = ""
for (const match of finalMatches) { for (const match of finalMatches) {
@@ -127,7 +128,9 @@ export const GrepTool = Tool.define("grep", {
if (truncated) { if (truncated) {
outputLines.push("") outputLines.push("")
outputLines.push("(Results are truncated. Consider using a more specific path or pattern.)") outputLines.push(
`(Results truncated: showing ${limit} of ${totalMatches} matches (${totalMatches - limit} hidden). Consider using a more specific path or pattern.)`,
)
} }
if (hasErrors) { if (hasErrors) {
@@ -138,7 +141,7 @@ export const GrepTool = Tool.define("grep", {
return { return {
title: params.pattern, title: params.pattern,
metadata: { metadata: {
matches: finalMatches.length, matches: totalMatches,
truncated, truncated,
}, },
output: outputLines.join("\n"), output: outputLines.join("\n"),