Cap thinking output for tool-bearing assistant turns

This commit is contained in:
Jeremy 2026-04-14 10:15:43 -05:00
parent 2cafd66bed
commit bc22ce95bc
2 changed files with 12 additions and 4 deletions

View file

@ -88,6 +88,7 @@ export class AssistantMessageComponent extends Container {
(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);
const hasToolContent = message.content.some((c) => c.type === "toolCall" || c.type === "serverToolUse");
if (hasVisibleContent) {
this.contentContainer.addChild(new Spacer(1));
@ -119,8 +120,9 @@ export class AssistantMessageComponent extends Container {
color: (text: string) => theme.fg("thinkingText", text),
italic: true,
});
// Keep assistant text/questions visible even when thinking traces are long.
if (hasTextContent) {
// Keep visible chat output readable when thinking traces are long.
// Tool-bearing turns can stream text in a later assistant message.
if (hasTextContent || hasToolContent) {
thinkingMarkdown.maxLines = 8;
}
this.contentContainer.addChild(thinkingMarkdown);

View file

@ -28,7 +28,13 @@ test("assistant-message caps thinking block height when text content is present"
assert.match(
src,
/if \(hasTextContent\)\s*\{\s*thinkingMarkdown\.maxLines = 8;\s*\}/s,
"assistant-message should cap visible thinking lines when assistant text also exists",
/const hasToolContent = message\.content\.some\(\(c\) => c\.type === "toolCall" \|\| c\.type === "serverToolUse"\);/,
"assistant-message should detect tool blocks in mixed turns",
);
assert.match(
src,
/if \(hasTextContent \|\| hasToolContent\)\s*\{\s*thinkingMarkdown\.maxLines = 8;\s*\}/s,
"assistant-message should cap visible thinking lines when assistant text exists or tool blocks are present",
);
});