Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,43 @@ describe('<ThinkMessage />', () => {
expect(output).toContain('Thought for');
expect(output).toContain('2m 5s');
});

it('should render full streaming content when pending and expanded', () => {
const longText =
'Line 1: initial analysis\nLine 2: deeper reasoning\nLine 3: more thought\nLine 4: conclusions';
const { lastFrame } = render(
<ThinkMessage
{...defaultProps}
text={longText}
isPending={true}
expanded={true}
/>,
);
const output = lastFrame();
expect(output).toContain('Thinking');
expect(output).toContain('Line 1');
expect(output).toContain('Line 2');
expect(output).toContain('Line 3');
expect(output).toContain('Line 4');
});

it('should only show tail lines when pending and not expanded', () => {
const lines = Array.from({ length: 20 }, (_, i) => `Line ${i + 1}`);
const longText = lines.join('\n');
const { lastFrame } = render(
<ThinkMessage
{...defaultProps}
text={longText}
isPending={true}
expanded={false}
contentWidth={40}
/>,
);
const output = lastFrame();
expect(output).toContain('Thinking');
expect(output).toContain('Line 20');
expect(output).not.toContain('Line 1\n');
});
});

describe('<ThinkMessageContent />', () => {
Expand Down Expand Up @@ -148,4 +185,22 @@ describe('<ThinkMessageContent />', () => {
const output = lastFrame();
expect(output).toContain('Continuation of the reasoning');
});

it('should render full streaming content when pending and expanded', () => {
const longText =
'Line 1: step one\nLine 2: step two\nLine 3: step three\nLine 4: step four';
const { lastFrame } = render(
<ThinkMessageContent
{...defaultProps}
text={longText}
isPending={true}
expanded={true}
/>,
);
const output = lastFrame();
expect(output).toContain('Line 1');
expect(output).toContain('Line 2');
expect(output).toContain('Line 3');
expect(output).toContain('Line 4');
});
});
152 changes: 71 additions & 81 deletions packages/cli/src/ui/components/messages/ConversationMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,50 @@ function tailVisualLines(
return lines.slice(-maxLines).join('\n');
}

const ThinkBody: React.FC<{
text: string;
isPending: boolean;
expanded: boolean;
availableTerminalHeight?: number;
contentWidth: number;
}> = ({ text, isPending, expanded, availableTerminalHeight, contentWidth }) => {
if (!isPending && !expanded) return null;

if (isPending && !expanded) {
const innerWidth = Math.max(contentWidth - 2, 20);
const maxLines =
availableTerminalHeight != null
? Math.max(
1,
Math.min(
MAX_STREAMING_THINKING_VISUAL_LINES,
Math.floor(availableTerminalHeight / 3),
),
)
: MAX_STREAMING_THINKING_VISUAL_LINES;
const display = tailVisualLines(text, innerWidth, maxLines);
return (
<Box paddingLeft={2}>
<Text dimColor wrap="truncate">
{display}
</Text>
</Box>
);
}

return (
<Box paddingLeft={2} flexDirection="column">
<MarkdownDisplay
text={text}
isPending={isPending}
availableTerminalHeight={availableTerminalHeight}
contentWidth={contentWidth - 2}
textColor={theme.text.secondary}
/>
</Box>
);
};

export const ThinkMessage: React.FC<ThinkMessageProps> = ({
text,
isPending,
Expand Down Expand Up @@ -315,54 +359,30 @@ export const ThinkMessage: React.FC<ThinkMessageProps> = ({
);
}

if (isPending) {
const innerWidth = Math.max(contentWidth - 2, 20);
const maxLines =
availableTerminalHeight != null
? Math.max(
1,
Math.min(
MAX_STREAMING_THINKING_VISUAL_LINES,
Math.floor(availableTerminalHeight / 3),
),
)
: MAX_STREAMING_THINKING_VISUAL_LINES;
const display = tailVisualLines(text, innerWidth, maxLines);
return (
<Box flexDirection="column">
<Text dimColor italic>
{THINKING_ICON_PENDING}
{t('Thinking')}…{durationSuffix}
</Text>
<Box paddingLeft={2}>
<Text dimColor wrap="truncate">
{display}
</Text>
</Box>
</Box>
);
}

const expandedLabel =
durationMs != null
const label = isPending
? `${t('Thinking')}…${durationSuffix}`
: durationMs != null
? `${t('Thought for')} ${formatDuration(durationMs)}`
: `${t('Thinking')}…`;
const collapseHint =
!isPending && expanded

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] The collapseHint is gated on !isPending && expanded, so when a user expands a streaming thinking block via Alt+T, the header shows only "Thinking..." with no "(Alt+T to collapse)" hint. The toggle still works, but the user has no visual affordance to re-collapse. When streaming finishes and isPending flips to false, the hint suddenly appears — inconsistent UX.

Suggested change
!isPending && expanded
const collapseHint =
expanded
? ` ${t('({{keyHint}} to collapse)', { keyHint: toggleKeyHint })}`
: '';

— qwen3.7-max via Qwen Code /review

? ` ${t('({{keyHint}} to collapse)', { keyHint: toggleKeyHint })}`
: '';

return (
<Box flexDirection="column">
<Text dimColor italic>
{THINKING_ICON}
{expandedLabel}{' '}
{t('({{keyHint}} to collapse)', { keyHint: toggleKeyHint })}
{isPending ? THINKING_ICON_PENDING : THINKING_ICON}
{label}
{collapseHint}
</Text>
<Box paddingLeft={2} flexDirection="column">
<MarkdownDisplay
text={text}
isPending={false}
availableTerminalHeight={availableTerminalHeight}
contentWidth={contentWidth - 2}
textColor={theme.text.secondary}
/>
</Box>
<ThinkBody
text={text}
isPending={isPending}
expanded={expanded}
availableTerminalHeight={availableTerminalHeight}
contentWidth={contentWidth}
/>
</Box>
);
};
Expand All @@ -373,42 +393,12 @@ export const ThinkMessageContent: React.FC<ThinkMessageContentProps> = ({
expanded = false,
availableTerminalHeight,
contentWidth,
}) => {
if (!isPending && !expanded) {
return null;
}

if (isPending) {
const innerWidth = Math.max(contentWidth - 2, 20);
const maxLines =
availableTerminalHeight != null
? Math.max(
1,
Math.min(
MAX_STREAMING_THINKING_VISUAL_LINES,
Math.floor(availableTerminalHeight / 3),
),
)
: MAX_STREAMING_THINKING_VISUAL_LINES;
const display = tailVisualLines(text, innerWidth, maxLines);
return (
<Box paddingLeft={2}>
<Text dimColor wrap="truncate">
{display}
</Text>
</Box>
);
}

return (
<Box paddingLeft={2} flexDirection="column">
<MarkdownDisplay
text={text}
isPending={false}
availableTerminalHeight={availableTerminalHeight}
contentWidth={contentWidth - 2}
textColor={theme.text.secondary}
/>
</Box>
);
};
}) => (
<ThinkBody
text={text}
isPending={isPending}
expanded={expanded}
availableTerminalHeight={availableTerminalHeight}
contentWidth={contentWidth}
/>
);
Loading