From 8841361a6f42da268a59df15376bce895d10c982 Mon Sep 17 00:00:00 2001 From: Dmitry Lyalin Date: Sat, 31 Jan 2026 11:07:06 -0500 Subject: [PATCH] Stabilize inline thinking box during streaming --- .../src/ui/components/HistoryItemDisplay.tsx | 3 + .../src/ui/components/MainContent.test.tsx | 20 +++--- .../components/messages/ThinkingMessage.tsx | 70 ++++++++++++------- 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/packages/cli/src/ui/components/HistoryItemDisplay.tsx b/packages/cli/src/ui/components/HistoryItemDisplay.tsx index 64b725a879..f83c2d34d9 100644 --- a/packages/cli/src/ui/components/HistoryItemDisplay.tsx +++ b/packages/cli/src/ui/components/HistoryItemDisplay.tsx @@ -70,6 +70,9 @@ export const HistoryItemDisplay: React.FC = ({ )} {itemForDisplay.type === 'user' && ( diff --git a/packages/cli/src/ui/components/MainContent.test.tsx b/packages/cli/src/ui/components/MainContent.test.tsx index fc78c84034..06a7209d70 100644 --- a/packages/cli/src/ui/components/MainContent.test.tsx +++ b/packages/cli/src/ui/components/MainContent.test.tsx @@ -12,15 +12,19 @@ import { Box, Text } from 'ink'; import type React from 'react'; // Mock dependencies -vi.mock('../contexts/SettingsContext.js', () => ({ - useSettings: () => ({ - merged: { - ui: { - showInlineThinking: false, +vi.mock('../contexts/SettingsContext.js', async () => { + const actual = await vi.importActual('../contexts/SettingsContext.js'); + return { + ...actual, + useSettings: () => ({ + merged: { + ui: { + showInlineThinking: false, + }, }, - }, - }), -})); + }), + }; +}); vi.mock('../contexts/AppContext.js', async () => { const actual = await vi.importActual('../contexts/AppContext.js'); diff --git a/packages/cli/src/ui/components/messages/ThinkingMessage.tsx b/packages/cli/src/ui/components/messages/ThinkingMessage.tsx index 99e789f1c0..e1453add44 100644 --- a/packages/cli/src/ui/components/messages/ThinkingMessage.tsx +++ b/packages/cli/src/ui/components/messages/ThinkingMessage.tsx @@ -7,40 +7,56 @@ import type React from 'react'; import { Box, Text } from 'ink'; import type { ThoughtSummary } from '@google/gemini-cli-core'; +import { MaxSizedBox, MINIMUM_MAX_HEIGHT } from '../shared/MaxSizedBox.js'; interface ThinkingMessageProps { thoughts: ThoughtSummary[]; terminalWidth: number; + availableTerminalHeight?: number; } export const ThinkingMessage: React.FC = ({ thoughts, terminalWidth, -}) => ( - - - - - Thinking - - ({thoughts.length}) - - {thoughts.map((thought, index) => ( - - {thought.subject && ( - - {thought.subject} - - )} - {thought.description || ' '} + availableTerminalHeight, +}) => { + const contentMaxHeight = + availableTerminalHeight !== undefined + ? Math.max(availableTerminalHeight - 4, MINIMUM_MAX_HEIGHT) + : undefined; + + return ( + + + + + Thinking + + ({thoughts.length}) - ))} - -); + + {thoughts.map((thought, index) => ( + + {thought.subject && ( + + {thought.subject} + + )} + {thought.description || ' '} + + ))} + + + ); +};