fix(coding-agent): do not highlight read errors (#6731)

This commit is contained in:
Danila Poyarkov
2026-07-17 10:02:50 +03:00
committed by GitHub
parent 056c8cbb80
commit a2c5ee33eb
2 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -176,7 +176,7 @@ function formatReadResult(
const rawPath = str(args?.file_path ?? args?.path); const rawPath = str(args?.file_path ?? args?.path);
const output = getTextOutput(result, showImages); const output = getTextOutput(result, showImages);
const lang = rawPath ? getLanguageFromPath(rawPath) : undefined; const lang = !isError && rawPath ? getLanguageFromPath(rawPath) : undefined;
const renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split("\n"); const renderedLines = lang ? highlightCode(replaceTabs(output), lang) : output.split("\n");
const lines = trimTrailingEmptyLines(renderedLines); const lines = trimTrailingEmptyLines(renderedLines);
const maxLines = options.expanded ? lines.length : 10; const maxLines = options.expanded ? lines.length : 10;
@@ -8,7 +8,7 @@ import { type BashOperations, createBashToolDefinition } from "../src/core/tools
import { createReadTool, createReadToolDefinition } from "../src/core/tools/read.ts"; import { createReadTool, createReadToolDefinition } from "../src/core/tools/read.ts";
import { createWriteToolDefinition } from "../src/core/tools/write.ts"; import { createWriteToolDefinition } from "../src/core/tools/write.ts";
import { ToolExecutionComponent } from "../src/modes/interactive/components/tool-execution.ts"; import { ToolExecutionComponent } from "../src/modes/interactive/components/tool-execution.ts";
import { initTheme } from "../src/modes/interactive/theme/theme.ts"; import { initTheme, theme } from "../src/modes/interactive/theme/theme.ts";
import { stripAnsi } from "../src/utils/ansi.ts"; import { stripAnsi } from "../src/utils/ansi.ts";
function createBaseToolDefinition(name = "custom_tool"): ToolDefinition { function createBaseToolDefinition(name = "custom_tool"): ToolDefinition {
@@ -401,6 +401,24 @@ describe("ToolExecutionComponent parity", () => {
expect(rendered).not.toContain("two\n\n"); expect(rendered).not.toContain("two\n\n");
}); });
test("does not syntax-highlight read errors based on the requested file path", () => {
const component = new ToolExecutionComponent(
"read",
"tool-read-error-highlighting",
{ path: "config.exs", offset: 120, limit: 130 },
{},
createReadToolDefinition(process.cwd()),
createFakeTui(),
process.cwd(),
);
const error = "Offset 120 is beyond end of file (96 lines total)";
component.updateResult({ content: [{ type: "text", text: error }], details: undefined, isError: true }, false);
const rendered = component.render(120).join("\n");
expect(stripAnsi(rendered)).toContain(error);
expect(rendered).toContain(theme.fg("toolOutput", error));
});
test("collapses ordinary read results until expanded", () => { test("collapses ordinary read results until expanded", () => {
const component = new ToolExecutionComponent( const component = new ToolExecutionComponent(
"read", "read",