Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/coding-agent/src/core/tools/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function formatReadResult(

const rawPath = str(args?.file_path ?? args?.path);
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 lines = trimTrailingEmptyLines(renderedLines);
const maxLines = options.expanded ? lines.length : 10;
Expand Down
20 changes: 19 additions & 1 deletion packages/coding-agent/test/tool-execution-component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { type BashOperations, createBashToolDefinition } from "../src/core/tools
import { createReadTool, createReadToolDefinition } from "../src/core/tools/read.ts";
import { createWriteToolDefinition } from "../src/core/tools/write.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";

function createBaseToolDefinition(name = "custom_tool"): ToolDefinition {
Expand Down Expand Up @@ -401,6 +401,24 @@ describe("ToolExecutionComponent parity", () => {
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", () => {
const component = new ToolExecutionComponent(
"read",
Expand Down
Loading