From 78467127b5b2124cd6d0d6570ba71f5c432637a5 Mon Sep 17 00:00:00 2001 From: Johnny Huynh <27847622+johnnyhuy@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:35:33 +0700 Subject: [PATCH 1/3] fix: bound long-line tool diff previews Co-authored-by: OpenAI Codex --- src/renderer/components/WorkbenchControls.tsx | 20 +++- tests/e2e/tool-preview.test.ts | 109 ++++++++++++++++++ tests/integration/ToolCard.test.tsx | 64 +++++++++- 3 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 tests/e2e/tool-preview.test.ts diff --git a/src/renderer/components/WorkbenchControls.tsx b/src/renderer/components/WorkbenchControls.tsx index 7624781..db4e0b2 100644 --- a/src/renderer/components/WorkbenchControls.tsx +++ b/src/renderer/components/WorkbenchControls.tsx @@ -396,17 +396,20 @@ function ToolDiffSection({ }) { const [showAll, setShowAll] = useState(false); const rows = diffLines(oldText, newText); - const isLong = text.length > TOOL_TEXT_PREVIEW_LIMIT; + const isLong = + rows.reduce((length, row) => length + row.text.length + 1, 0) > + TOOL_TEXT_PREVIEW_LIMIT; let visible = rows; if (isLong && !showAll) { visible = []; - let used = 0; + let remaining = TOOL_TEXT_PREVIEW_LIMIT; for (const row of rows) { - used += row.text.length + 1; - if (used > TOOL_TEXT_PREVIEW_LIMIT) break; - visible.push(row); + if (remaining <= 0) break; + // Include the diff marker in the budget and clip even a single long row. + const clipped = row.text.slice(0, remaining - 1); + visible.push({ ...row, text: clipped }); + remaining -= clipped.length + 1; } - if (visible.length === 0 && rows.length > 0) visible = [rows[0]]; } return ( @@ -422,6 +425,11 @@ function ToolDiffSection({ ))} {visible.length === 0 &&
No changes.
} + {isLong && !showAll && ( +

+ Input preview shortened. Show more or copy the full input. +

+ )} {isLong && (