From 30065c51fb1a6f6df4d0472ff290d050465891c9 Mon Sep 17 00:00:00 2001 From: Jacob Richman Date: Wed, 28 Jan 2026 13:23:51 -0800 Subject: [PATCH] Change height for the ToolConfirmationQueue. (#17799) --- .../components/ToolConfirmationQueue.test.tsx | 50 +++ .../ui/components/ToolConfirmationQueue.tsx | 18 +- .../SettingsDialog.test.tsx.snap | 368 ------------------ .../ToolConfirmationQueue.test.tsx.snap | 20 + 4 files changed, 82 insertions(+), 374 deletions(-) diff --git a/packages/cli/src/ui/components/ToolConfirmationQueue.test.tsx b/packages/cli/src/ui/components/ToolConfirmationQueue.test.tsx index 1bd3879b16..f0e11bddd4 100644 --- a/packages/cli/src/ui/components/ToolConfirmationQueue.test.tsx +++ b/packages/cli/src/ui/components/ToolConfirmationQueue.test.tsx @@ -137,6 +137,56 @@ describe('ToolConfirmationQueue', () => { expect(lastFrame()).toContain('Press ctrl-o to show more lines'); }); + it('calculates availableContentHeight based on availableTerminalHeight from UI state', async () => { + const longDiff = '@@ -1,1 +1,50 @@\n' + '+line\n'.repeat(50); + const confirmingTool = { + tool: { + callId: 'call-1', + name: 'replace', + description: 'edit file', + status: ToolCallStatus.Confirming, + confirmationDetails: { + type: 'edit' as const, + title: 'Confirm edit', + fileName: 'test.ts', + filePath: '/test.ts', + fileDiff: longDiff, + originalContent: 'old', + newContent: 'new', + onConfirm: vi.fn(), + }, + }, + index: 1, + total: 1, + }; + + // Use a small availableTerminalHeight to force truncation + const { lastFrame } = renderWithProviders( + , + { + config: mockConfig, + useAlternateBuffer: false, + uiState: { + terminalWidth: 80, + terminalHeight: 40, + availableTerminalHeight: 10, + constrainHeight: true, + streamingState: StreamingState.WaitingForConfirmation, + }, + }, + ); + + // With availableTerminalHeight = 10: + // maxHeight = Math.max(10 - 1, 4) = 9 + // availableContentHeight = Math.max(9 - 6, 4) = 4 + // MaxSizedBox in ToolConfirmationMessage will use 4 + // It should show truncation message + await waitFor(() => expect(lastFrame()).toContain('first 49 lines hidden')); + expect(lastFrame()).toMatchSnapshot(); + }); + it('does not render expansion hint when constrainHeight is false', () => { const longDiff = 'line\n'.repeat(50); const confirmingTool = { diff --git a/packages/cli/src/ui/components/ToolConfirmationQueue.tsx b/packages/cli/src/ui/components/ToolConfirmationQueue.tsx index 35a3a66da2..71f57b7a3a 100644 --- a/packages/cli/src/ui/components/ToolConfirmationQueue.tsx +++ b/packages/cli/src/ui/components/ToolConfirmationQueue.tsx @@ -26,17 +26,23 @@ export const ToolConfirmationQueue: React.FC = ({ }) => { const config = useConfig(); const isAlternateBuffer = useAlternateBuffer(); - const { mainAreaWidth, terminalHeight, constrainHeight } = useUIState(); + const { + mainAreaWidth, + terminalHeight, + constrainHeight, + availableTerminalHeight: uiAvailableHeight, + } = useUIState(); const { tool, index, total } = confirmingTool; // Safety check: ToolConfirmationMessage requires confirmationDetails if (!tool.confirmationDetails) return null; - // V1: Constrain the queue to at most 50% of the terminal height to ensure - // some history is always visible and to prevent flickering. - // We pass this to ToolConfirmationMessage so it can calculate internal - // truncation while keeping buttons visible. - const maxHeight = Math.floor(terminalHeight * 0.5); + // Render up to 100% of the available terminal height (minus 1 line for safety) + // to maximize space for diffs and other content. + const maxHeight = + uiAvailableHeight !== undefined + ? Math.max(uiAvailableHeight - 1, 4) + : Math.floor(terminalHeight * 0.5); // ToolConfirmationMessage needs to know the height available for its OWN content. // We subtract the lines used by the Queue wrapper: diff --git a/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap index 93fa48bf93..da745e2843 100644 --- a/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap +++ b/packages/cli/src/ui/components/__snapshots__/SettingsDialog.test.tsx.snap @@ -413,371 +413,3 @@ exports[`SettingsDialog > Snapshot Tests > should render 'various boolean settin │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" `; - -exports[`SettingsDialog > Snapshot Tests > should render accessibility settings enabled correctly 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -│ > Settings │ -│ │ -│ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ -│ │ Search to filter │ │ -│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ -│ │ -│ ▲ │ -│ ● Preview Features (e.g., models) false │ -│ Enable preview features (e.g., preview models). │ -│ │ -│ Vim Mode false │ -│ Enable Vim keybindings │ -│ │ -│ Enable Auto Update true │ -│ Enable automatic updates. │ -│ │ -│ Enable Prompt Completion false │ -│ Enable AI-powered prompt completion suggestions while typing. │ -│ │ -│ Debug Keystroke Logging false │ -│ Enable debug logging of keystrokes to the console. │ -│ │ -│ Enable Session Cleanup false │ -│ Enable automatic session cleanup │ -│ │ -│ Output Format Text │ -│ The format of the CLI output. Can be \`text\` or \`json\`. │ -│ │ -│ Hide Window Title false │ -│ Hide the window title bar │ -│ │ -│ ▼ │ -│ │ -│ Apply To │ -│ ● User Settings │ -│ Workspace Settings │ -│ System Settings │ -│ │ -│ (Use Enter to select, Tab to change focus, Esc to close) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" -`; - -exports[`SettingsDialog > Snapshot Tests > should render all boolean settings disabled correctly 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -│ > Settings │ -│ │ -│ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ -│ │ Search to filter │ │ -│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ -│ │ -│ ▲ │ -│ ● Preview Features (e.g., models) false* │ -│ Enable preview features (e.g., preview models). │ -│ │ -│ Vim Mode false* │ -│ Enable Vim keybindings │ -│ │ -│ Enable Auto Update false* │ -│ Enable automatic updates. │ -│ │ -│ Enable Prompt Completion false │ -│ Enable AI-powered prompt completion suggestions while typing. │ -│ │ -│ Debug Keystroke Logging false │ -│ Enable debug logging of keystrokes to the console. │ -│ │ -│ Enable Session Cleanup false │ -│ Enable automatic session cleanup │ -│ │ -│ Output Format Text │ -│ The format of the CLI output. Can be \`text\` or \`json\`. │ -│ │ -│ Hide Window Title false │ -│ Hide the window title bar │ -│ │ -│ ▼ │ -│ │ -│ Apply To │ -│ ● User Settings │ -│ Workspace Settings │ -│ System Settings │ -│ │ -│ (Use Enter to select, Tab to change focus, Esc to close) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" -`; - -exports[`SettingsDialog > Snapshot Tests > should render default state correctly 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -│ > Settings │ -│ │ -│ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ -│ │ Search to filter │ │ -│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ -│ │ -│ ▲ │ -│ ● Preview Features (e.g., models) false │ -│ Enable preview features (e.g., preview models). │ -│ │ -│ Vim Mode false │ -│ Enable Vim keybindings │ -│ │ -│ Enable Auto Update true │ -│ Enable automatic updates. │ -│ │ -│ Enable Prompt Completion false │ -│ Enable AI-powered prompt completion suggestions while typing. │ -│ │ -│ Debug Keystroke Logging false │ -│ Enable debug logging of keystrokes to the console. │ -│ │ -│ Enable Session Cleanup false │ -│ Enable automatic session cleanup │ -│ │ -│ Output Format Text │ -│ The format of the CLI output. Can be \`text\` or \`json\`. │ -│ │ -│ Hide Window Title false │ -│ Hide the window title bar │ -│ │ -│ ▼ │ -│ │ -│ Apply To │ -│ ● User Settings │ -│ Workspace Settings │ -│ System Settings │ -│ │ -│ (Use Enter to select, Tab to change focus, Esc to close) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" -`; - -exports[`SettingsDialog > Snapshot Tests > should render file filtering settings configured correctly 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -│ > Settings │ -│ │ -│ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ -│ │ Search to filter │ │ -│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ -│ │ -│ ▲ │ -│ ● Preview Features (e.g., models) false │ -│ Enable preview features (e.g., preview models). │ -│ │ -│ Vim Mode false │ -│ Enable Vim keybindings │ -│ │ -│ Enable Auto Update true │ -│ Enable automatic updates. │ -│ │ -│ Enable Prompt Completion false │ -│ Enable AI-powered prompt completion suggestions while typing. │ -│ │ -│ Debug Keystroke Logging false │ -│ Enable debug logging of keystrokes to the console. │ -│ │ -│ Enable Session Cleanup false │ -│ Enable automatic session cleanup │ -│ │ -│ Output Format Text │ -│ The format of the CLI output. Can be \`text\` or \`json\`. │ -│ │ -│ Hide Window Title false │ -│ Hide the window title bar │ -│ │ -│ ▼ │ -│ │ -│ Apply To │ -│ ● User Settings │ -│ Workspace Settings │ -│ System Settings │ -│ │ -│ (Use Enter to select, Tab to change focus, Esc to close) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" -`; - -exports[`SettingsDialog > Snapshot Tests > should render focused on scope selector correctly 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -│ Settings │ -│ │ -│ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ -│ │ Search to filter │ │ -│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ -│ │ -│ ▲ │ -│ Preview Features (e.g., models) false │ -│ Enable preview features (e.g., preview models). │ -│ │ -│ Vim Mode false │ -│ Enable Vim keybindings │ -│ │ -│ Enable Auto Update true │ -│ Enable automatic updates. │ -│ │ -│ Enable Prompt Completion false │ -│ Enable AI-powered prompt completion suggestions while typing. │ -│ │ -│ Debug Keystroke Logging false │ -│ Enable debug logging of keystrokes to the console. │ -│ │ -│ Enable Session Cleanup false │ -│ Enable automatic session cleanup │ -│ │ -│ Output Format Text │ -│ The format of the CLI output. Can be \`text\` or \`json\`. │ -│ │ -│ Hide Window Title false │ -│ Hide the window title bar │ -│ │ -│ ▼ │ -│ │ -│ > Apply To │ -│ ● 1. User Settings │ -│ 2. Workspace Settings │ -│ 3. System Settings │ -│ │ -│ (Use Enter to select, Tab to change focus, Esc to close) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" -`; - -exports[`SettingsDialog > Snapshot Tests > should render mixed boolean and number settings correctly 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -│ > Settings │ -│ │ -│ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ -│ │ Search to filter │ │ -│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ -│ │ -│ ▲ │ -│ ● Preview Features (e.g., models) false │ -│ Enable preview features (e.g., preview models). │ -│ │ -│ Vim Mode true* │ -│ Enable Vim keybindings │ -│ │ -│ Enable Auto Update true │ -│ Enable automatic updates. │ -│ │ -│ Enable Prompt Completion false │ -│ Enable AI-powered prompt completion suggestions while typing. │ -│ │ -│ Debug Keystroke Logging false │ -│ Enable debug logging of keystrokes to the console. │ -│ │ -│ Enable Session Cleanup false │ -│ Enable automatic session cleanup │ -│ │ -│ Output Format Text │ -│ The format of the CLI output. Can be \`text\` or \`json\`. │ -│ │ -│ Hide Window Title false │ -│ Hide the window title bar │ -│ │ -│ ▼ │ -│ │ -│ Apply To │ -│ ● User Settings │ -│ Workspace Settings │ -│ System Settings │ -│ │ -│ (Use Enter to select, Tab to change focus, Esc to close) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" -`; - -exports[`SettingsDialog > Snapshot Tests > should render tools and security settings correctly 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -│ > Settings │ -│ │ -│ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ -│ │ Search to filter │ │ -│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ -│ │ -│ ▲ │ -│ ● Preview Features (e.g., models) false │ -│ Enable preview features (e.g., preview models). │ -│ │ -│ Vim Mode false │ -│ Enable Vim keybindings │ -│ │ -│ Enable Auto Update true │ -│ Enable automatic updates. │ -│ │ -│ Enable Prompt Completion false │ -│ Enable AI-powered prompt completion suggestions while typing. │ -│ │ -│ Debug Keystroke Logging false │ -│ Enable debug logging of keystrokes to the console. │ -│ │ -│ Enable Session Cleanup false │ -│ Enable automatic session cleanup │ -│ │ -│ Output Format Text │ -│ The format of the CLI output. Can be \`text\` or \`json\`. │ -│ │ -│ Hide Window Title false │ -│ Hide the window title bar │ -│ │ -│ ▼ │ -│ │ -│ Apply To │ -│ ● User Settings │ -│ Workspace Settings │ -│ System Settings │ -│ │ -│ (Use Enter to select, Tab to change focus, Esc to close) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" -`; - -exports[`SettingsDialog > Snapshot Tests > should render various boolean settings enabled correctly 1`] = ` -"╭──────────────────────────────────────────────────────────────────────────────────────────────────╮ -│ │ -│ > Settings │ -│ │ -│ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │ -│ │ Search to filter │ │ -│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │ -│ │ -│ ▲ │ -│ ● Preview Features (e.g., models) true* │ -│ Enable preview features (e.g., preview models). │ -│ │ -│ Vim Mode true* │ -│ Enable Vim keybindings │ -│ │ -│ Enable Auto Update true │ -│ Enable automatic updates. │ -│ │ -│ Enable Prompt Completion false │ -│ Enable AI-powered prompt completion suggestions while typing. │ -│ │ -│ Debug Keystroke Logging false │ -│ Enable debug logging of keystrokes to the console. │ -│ │ -│ Enable Session Cleanup false │ -│ Enable automatic session cleanup │ -│ │ -│ Output Format Text │ -│ The format of the CLI output. Can be \`text\` or \`json\`. │ -│ │ -│ Hide Window Title false │ -│ Hide the window title bar │ -│ │ -│ ▼ │ -│ │ -│ Apply To │ -│ ● User Settings │ -│ Workspace Settings │ -│ System Settings │ -│ │ -│ (Use Enter to select, Tab to change focus, Esc to close) │ -│ │ -╰──────────────────────────────────────────────────────────────────────────────────────────────────╯" -`; diff --git a/packages/cli/src/ui/components/__snapshots__/ToolConfirmationQueue.test.tsx.snap b/packages/cli/src/ui/components/__snapshots__/ToolConfirmationQueue.test.tsx.snap index 4cac209e18..8f5abfa7a9 100644 --- a/packages/cli/src/ui/components/__snapshots__/ToolConfirmationQueue.test.tsx.snap +++ b/packages/cli/src/ui/components/__snapshots__/ToolConfirmationQueue.test.tsx.snap @@ -1,5 +1,25 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`ToolConfirmationQueue > calculates availableContentHeight based on availableTerminalHeight from UI state 1`] = ` +"╭──────────────────────────────────────────────────────────────────────────────╮ +│ Action Required 1 of 1 │ +│ │ +│ ? replace edit file │ +│ │ +│ ... first 49 lines hidden ... │ +│ 50 line │ +│ Apply this change? │ +│ │ +│ ● 1. Allow once │ +│ 2. Allow for this session │ +│ 3. Modify with external editor │ +│ 4. No, suggest changes (esc) │ +│ │ +╰──────────────────────────────────────────────────────────────────────────────╯ + Press ctrl-o to show more lines +" +`; + exports[`ToolConfirmationQueue > does not render expansion hint when constrainHeight is false 1`] = ` "╭──────────────────────────────────────────────────────────────────────────────╮ │ Action Required 1 of 1 │