From bd5ed72f92fceffe2ee482ed173dac5d32295bbf Mon Sep 17 00:00:00 2001 From: Charles Packer Date: Mon, 23 Mar 2026 15:18:00 -0700 Subject: [PATCH] fix(tui): clip legacy bash fallback output path (#1433) Co-authored-by: Letta Code --- src/cli/components/BashCommandMessage.tsx | 5 +++- src/tests/tools/clip-tool-return.test.ts | 30 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/tests/tools/clip-tool-return.test.ts diff --git a/src/cli/components/BashCommandMessage.tsx b/src/cli/components/BashCommandMessage.tsx index b6b3d66..195d340 100644 --- a/src/cli/components/BashCommandMessage.tsx +++ b/src/cli/components/BashCommandMessage.tsx @@ -1,6 +1,7 @@ import { Box } from "ink"; import { memo } from "react"; import { INTERRUPTED_BY_USER } from "../../constants"; +import { clipToolReturn } from "../../tools/manager"; import type { StreamingState } from "../helpers/accumulator"; import { useTerminalWidth } from "../hooks/useTerminalWidth"; import { BlinkDot } from "./BlinkDot.js"; @@ -90,7 +91,9 @@ export const BashCommandMessage = memo( {" ⎿ "} - + )} diff --git a/src/tests/tools/clip-tool-return.test.ts b/src/tests/tools/clip-tool-return.test.ts new file mode 100644 index 0000000..4d3cb68 --- /dev/null +++ b/src/tests/tools/clip-tool-return.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, test } from "bun:test"; +import { clipToolReturn } from "../../tools/manager"; + +describe("clipToolReturn", () => { + test("clips long single-line output and appends ellipsis", () => { + const long = "A".repeat(1200); + const clipped = clipToolReturn(long); + + expect(clipped.length).toBeLessThan(400); + expect(clipped.endsWith("…")).toBe(true); + }); + + test("clips by line count for multiline output", () => { + const text = "line1\nline2\nline3\nline4\nline5"; + const clipped = clipToolReturn(text, 3, 10_000); + + expect(clipped).toContain("line1"); + expect(clipped).toContain("line2"); + expect(clipped).toContain("line3"); + expect(clipped).not.toContain("line4"); + expect(clipped.endsWith("…")).toBe(true); + }); + + test("does not clip user-denial reasons", () => { + const denial = `Error: request to call tool denied. User reason: ${"B".repeat(800)}`; + const clipped = clipToolReturn(denial); + + expect(clipped).toBe(denial); + }); +});