From 491efe32e8547075842e448d873fc01b2ffabf3a Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Mon, 15 Sep 2025 11:02:47 -0400 Subject: [PATCH] Tool error backticks (#53) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This looks more reasonable now, because the code is now rendered in a monospace font: Screenshot 2025-09-15 at 10 58 20 AM That said, this definitely would benefit from a horizontal scroll bar on the code blocks. You can't really read what it's saying without copying the text out of the block. Of course, in this particular case the relevant info is all in the beginning of the error message (namely, that it failed to find the `old_string`), and this does look overall better than before (where it was just this big jumble of non-monospaced code), so I think it's worth merging as-is and then revisiting horizontal scrolling later. --- src/tests/acp-agent.test.ts | 5 ++++- src/tools.ts | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/tests/acp-agent.test.ts b/src/tests/acp-agent.test.ts index ecada971..0a1a259e 100644 --- a/src/tests/acp-agent.test.ts +++ b/src/tests/acp-agent.test.ts @@ -778,7 +778,10 @@ describe("tool conversions", () => { // Should return empty object when parsing fails expect(update).toEqual({ content: [ - { content: { type: "text", text: "Failed to find `old_string`" }, type: "content" }, + { + content: { type: "text", text: "```\nFailed to find `old_string`\n```" }, + type: "content", + }, ], }); }); diff --git a/src/tools.ts b/src/tools.ts index 593cadee..c0fc6df6 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -487,7 +487,7 @@ export function toolUpdateFromToolResult( case "Write": { if (toolResult.is_error && toolResult.content?.length > 0) { // Only return errors - return toAcpContentUpdate(toolResult.content); + return toAcpContentUpdate(toolResult.content, true); } return {}; } @@ -511,17 +511,26 @@ export function toolUpdateFromToolResult( case "WebSearch": case "Other": default: { - return toAcpContentUpdate(toolResult.content); + return toAcpContentUpdate(toolResult.content, toolResult.is_error); } } } -function toAcpContentUpdate(content: any): { content?: ToolCallContent[] } { +function toAcpContentUpdate( + content: any, + isError: boolean = false, +): { content?: ToolCallContent[] } { if (Array.isArray(content) && content.length > 0) { return { content: content.map((content: any) => ({ type: "content", - content, + content: + isError && content.type === "text" + ? { + ...content, + text: `\`\`\`\n${content.text}\n\`\`\``, + } + : content, })), }; } else if (typeof content === "string" && content.length > 0) { @@ -531,7 +540,7 @@ function toAcpContentUpdate(content: any): { content?: ToolCallContent[] } { type: "content", content: { type: "text", - text: content, + text: isError ? `\`\`\`\n${content}\n\`\`\`` : content, }, }, ],