From 8fa265dfada7a184f044347243936648e7269d8f Mon Sep 17 00:00:00 2001 From: akougkas Date: Mon, 27 Apr 2026 19:10:52 -0500 Subject: [PATCH] fix(interactive): clip thinking preview to terminal width The collapsed thinking preview built `thinking: ` against a fixed 60-column budget and ignored the actual terminal width. Terminals narrower than ~70 columns crashed pi-tui's render with `Rendered line N exceeds terminal width (60 > )` because the custom component emitted a line wider than the terminal. Wrap the composed line in an outer `truncateToWidth(line, max(1, width), "...", false)` so very narrow terminals (33-col user report) get a clipped one-line preview instead of an overflow throw. The inner 60-col preview budget still hugs the wide-terminal target; the outer clip is a safety net. --- src/interactive/chat-panel.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/interactive/chat-panel.ts b/src/interactive/chat-panel.ts index 7001a07..b83a185 100644 --- a/src/interactive/chat-panel.ts +++ b/src/interactive/chat-panel.ts @@ -248,7 +248,13 @@ function renderThinkingLines(thinking: string, expanded: boolean, width: number) const collapsed = thinking.replace(/\s+/g, " ").trim(); const contentBudget = Math.max(1, THINKING_PREVIEW_WIDTH - THINKING_PREVIEW_LABEL.length); const preview = truncateToWidth(collapsed, contentBudget, "...", false); - return [dimWrap(`${THINKING_PREVIEW_LABEL}${preview}`)]; + // Clip the composed line to the actual terminal width so very narrow + // terminals (e.g. 33 cols) do not overflow pi-tui's render check. The + // inner preview budget hugs the ~60-col target on wide terminals; the + // outer truncate is a safety net for the narrow case. + const composed = `${THINKING_PREVIEW_LABEL}${preview}`; + const lineBudget = Math.max(1, width); + return [dimWrap(truncateToWidth(composed, lineBudget, "...", false))]; } const splitLines = thinking.split("\n"); const visible: string[] =