From e78eacb40e1850d8792d7c508d7b267f3002bb15 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 14 Apr 2026 09:01:20 -0500 Subject: [PATCH 1/2] fix: keep assistant text visible when thinking traces are long Cap thinking trace render height when assistant text is present so interactive questions remain visible.\n\nFixes #4181. --- .../interactive/components/assistant-message.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts b/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts index c558b7cfc..3d5177492 100644 --- a/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts +++ b/packages/pi-coding-agent/src/modes/interactive/components/assistant-message.ts @@ -54,6 +54,7 @@ export class AssistantMessageComponent extends Container { const hasVisibleContent = message.content.some( (c) => (c.type === "text" && c.text.trim()) || (c.type === "thinking" && c.thinking.trim()), ); + const hasTextContent = message.content.some((c) => c.type === "text" && c.text.trim().length > 0); if (hasVisibleContent) { this.contentContainer.addChild(new Spacer(1)); @@ -81,12 +82,15 @@ export class AssistantMessageComponent extends Container { } } else { // Thinking traces in thinkingText color, italic - this.contentContainer.addChild( - new Markdown(content.thinking.trim(), 1, 0, this.markdownTheme, { - color: (text: string) => theme.fg("thinkingText", text), - italic: true, - }), - ); + const thinkingMarkdown = new Markdown(content.thinking.trim(), 1, 0, this.markdownTheme, { + color: (text: string) => theme.fg("thinkingText", text), + italic: true, + }); + // Keep assistant text/questions visible even when thinking traces are long. + if (hasTextContent) { + thinkingMarkdown.maxLines = 8; + } + this.contentContainer.addChild(thinkingMarkdown); if (hasVisibleContentAfter) { this.contentContainer.addChild(new Spacer(1)); } From 759bed7dae69d71c6c8df415e8c679bd9a4188f9 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 14 Apr 2026 09:05:29 -0500 Subject: [PATCH 2/2] test: add regression coverage for thinking/chat visibility Add a regression test for #4181 to ensure assistant-message caps thinking block height when text content is present. --- ...istant-message-thinking-visibility.test.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/tests/assistant-message-thinking-visibility.test.ts diff --git a/src/tests/assistant-message-thinking-visibility.test.ts b/src/tests/assistant-message-thinking-visibility.test.ts new file mode 100644 index 000000000..29fc356ee --- /dev/null +++ b/src/tests/assistant-message-thinking-visibility.test.ts @@ -0,0 +1,34 @@ +// Regression test for #4181: +// When assistant messages include both thinking + text, cap visible thinking +// lines so question/chat text remains visible without toggling thinking off. +import test from "node:test"; +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { join } from "node:path"; + +const assistantMessagePath = join( + process.cwd(), + "packages", + "pi-coding-agent", + "src", + "modes", + "interactive", + "components", + "assistant-message.ts", +); + +test("assistant-message caps thinking block height when text content is present", () => { + const src = readFileSync(assistantMessagePath, "utf-8"); + + assert.match( + src, + /const hasTextContent = message\.content\.some\(\(c\) => c\.type === "text" && c\.text\.trim\(\)\.length > 0\);/, + "assistant-message should detect text presence in mixed thinking+text messages", + ); + + assert.match( + src, + /if \(hasTextContent\)\s*\{\s*thinkingMarkdown\.maxLines = 8;\s*\}/s, + "assistant-message should cap visible thinking lines when assistant text also exists", + ); +});