2025-09-06 01:39:02 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
2026-02-09 21:53:10 -05:00
|
|
|
* Copyright 2026 Google LLC
|
2025-09-06 01:39:02 -04:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-11-11 07:50:11 -08:00
|
|
|
import { useState } from 'react';
|
2026-02-09 13:44:39 -08:00
|
|
|
import { Box, useIsScreenReaderEnabled } from 'ink';
|
2025-09-06 01:39:02 -04:00
|
|
|
import { LoadingIndicator } from './LoadingIndicator.js';
|
2026-01-06 15:52:12 -05:00
|
|
|
import { StatusDisplay } from './StatusDisplay.js';
|
2026-01-21 10:19:47 -05:00
|
|
|
import { ApprovalModeIndicator } from './ApprovalModeIndicator.js';
|
2025-09-06 01:39:02 -04:00
|
|
|
import { ShellModeIndicator } from './ShellModeIndicator.js';
|
|
|
|
|
import { DetailedMessagesDisplay } from './DetailedMessagesDisplay.js';
|
2025-10-16 11:23:36 -07:00
|
|
|
import { RawMarkdownIndicator } from './RawMarkdownIndicator.js';
|
2026-02-06 11:33:39 -08:00
|
|
|
import { ShortcutsHint } from './ShortcutsHint.js';
|
|
|
|
|
import { ShortcutsHelp } from './ShortcutsHelp.js';
|
2025-10-09 19:27:20 -07:00
|
|
|
import { InputPrompt } from './InputPrompt.js';
|
2025-09-26 21:27:00 -04:00
|
|
|
import { Footer } from './Footer.js';
|
2025-09-06 01:39:02 -04:00
|
|
|
import { ShowMoreLines } from './ShowMoreLines.js';
|
2025-09-18 11:54:09 -07:00
|
|
|
import { QueuedMessageDisplay } from './QueuedMessageDisplay.js';
|
2026-02-06 11:33:39 -08:00
|
|
|
import { HorizontalLine } from './shared/HorizontalLine.js';
|
2025-09-06 01:39:02 -04:00
|
|
|
import { OverflowProvider } from '../contexts/OverflowContext.js';
|
|
|
|
|
import { isNarrowWidth } from '../utils/isNarrowWidth.js';
|
|
|
|
|
import { useUIState } from '../contexts/UIStateContext.js';
|
|
|
|
|
import { useUIActions } from '../contexts/UIActionsContext.js';
|
|
|
|
|
import { useVimMode } from '../contexts/VimModeContext.js';
|
|
|
|
|
import { useConfig } from '../contexts/ConfigContext.js';
|
|
|
|
|
import { useSettings } from '../contexts/SettingsContext.js';
|
2025-11-11 07:50:11 -08:00
|
|
|
import { useAlternateBuffer } from '../hooks/useAlternateBuffer.js';
|
2026-02-06 11:33:39 -08:00
|
|
|
import { StreamingState, ToolCallStatus } from '../types.js';
|
2025-09-08 16:37:36 -07:00
|
|
|
import { ConfigInitDisplay } from '../components/ConfigInitDisplay.js';
|
2025-10-19 05:22:01 -07:00
|
|
|
import { TodoTray } from './messages/Todo.js';
|
2026-02-09 19:24:41 -08:00
|
|
|
import { getInlineThinkingMode } from '../utils/inlineThinkingMode.js';
|
2025-09-06 01:39:02 -04:00
|
|
|
|
2026-01-23 20:32:35 -05:00
|
|
|
export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => {
|
2025-09-06 01:39:02 -04:00
|
|
|
const config = useConfig();
|
|
|
|
|
const settings = useSettings();
|
2025-09-26 21:27:00 -04:00
|
|
|
const isScreenReaderEnabled = useIsScreenReaderEnabled();
|
2025-09-06 01:39:02 -04:00
|
|
|
const uiState = useUIState();
|
|
|
|
|
const uiActions = useUIActions();
|
2026-01-29 23:31:47 -08:00
|
|
|
const { vimEnabled, vimMode } = useVimMode();
|
2026-02-09 19:24:41 -08:00
|
|
|
const inlineThinkingMode = getInlineThinkingMode(settings);
|
2025-09-06 01:39:02 -04:00
|
|
|
const terminalWidth = process.stdout.columns;
|
|
|
|
|
const isNarrow = isNarrowWidth(terminalWidth);
|
|
|
|
|
const debugConsoleMaxHeight = Math.floor(Math.max(terminalWidth * 0.2, 5));
|
2025-11-11 07:50:11 -08:00
|
|
|
const [suggestionsVisible, setSuggestionsVisible] = useState(false);
|
2025-09-06 01:39:02 -04:00
|
|
|
|
2025-11-11 07:50:11 -08:00
|
|
|
const isAlternateBuffer = useAlternateBuffer();
|
2026-01-21 10:19:47 -05:00
|
|
|
const { showApprovalModeIndicator } = uiState;
|
2025-11-11 07:50:11 -08:00
|
|
|
const suggestionsPosition = isAlternateBuffer ? 'above' : 'below';
|
|
|
|
|
const hideContextSummary =
|
|
|
|
|
suggestionsVisible && suggestionsPosition === 'above';
|
2026-02-06 11:33:39 -08:00
|
|
|
const hasPendingToolConfirmation = (uiState.pendingHistoryItems ?? []).some(
|
|
|
|
|
(item) =>
|
|
|
|
|
item.type === 'tool_group' &&
|
|
|
|
|
item.tools.some((tool) => tool.status === ToolCallStatus.Confirming),
|
|
|
|
|
);
|
|
|
|
|
const hasPendingActionRequired =
|
|
|
|
|
hasPendingToolConfirmation ||
|
|
|
|
|
Boolean(uiState.commandConfirmationRequest) ||
|
|
|
|
|
Boolean(uiState.authConsentRequest) ||
|
|
|
|
|
(uiState.confirmUpdateExtensionRequests?.length ?? 0) > 0 ||
|
|
|
|
|
Boolean(uiState.loopDetectionConfirmationRequest) ||
|
2026-02-09 21:53:10 -05:00
|
|
|
Boolean(uiState.quota.proQuotaRequest) ||
|
|
|
|
|
Boolean(uiState.quota.validationRequest) ||
|
2026-02-06 11:33:39 -08:00
|
|
|
Boolean(uiState.customDialog);
|
|
|
|
|
const showLoadingIndicator =
|
|
|
|
|
(!uiState.embeddedShellFocused || uiState.isBackgroundShellVisible) &&
|
|
|
|
|
uiState.streamingState === StreamingState.Responding &&
|
|
|
|
|
!hasPendingActionRequired;
|
2026-02-06 19:23:59 -05:00
|
|
|
const showApprovalIndicator = !uiState.shellModeActive;
|
2026-02-06 11:33:39 -08:00
|
|
|
const showRawMarkdownIndicator = !uiState.renderMarkdown;
|
2025-09-06 01:39:02 -04:00
|
|
|
|
|
|
|
|
return (
|
2025-11-11 07:50:11 -08:00
|
|
|
<Box
|
|
|
|
|
flexDirection="column"
|
2026-01-26 15:23:54 -08:00
|
|
|
width={uiState.terminalWidth}
|
2025-11-11 07:50:11 -08:00
|
|
|
flexGrow={0}
|
|
|
|
|
flexShrink={0}
|
|
|
|
|
>
|
2026-01-26 19:59:20 +03:00
|
|
|
{(!uiState.slashCommands ||
|
|
|
|
|
!uiState.isConfigInitialized ||
|
|
|
|
|
uiState.isResuming) && (
|
|
|
|
|
<ConfigInitDisplay
|
|
|
|
|
message={uiState.isResuming ? 'Resuming session...' : undefined}
|
|
|
|
|
/>
|
2025-10-14 18:15:57 -07:00
|
|
|
)}
|
2025-09-08 16:37:36 -07:00
|
|
|
|
2025-09-18 11:54:09 -07:00
|
|
|
<QueuedMessageDisplay messageQueue={uiState.messageQueue} />
|
2025-09-06 01:39:02 -04:00
|
|
|
|
2025-10-21 15:40:45 -07:00
|
|
|
<TodoTray />
|
|
|
|
|
|
2026-02-06 11:33:39 -08:00
|
|
|
<Box marginTop={1} width="100%" flexDirection="column">
|
|
|
|
|
<Box
|
|
|
|
|
width="100%"
|
|
|
|
|
flexDirection={isNarrow ? 'column' : 'row'}
|
|
|
|
|
alignItems={isNarrow ? 'flex-start' : 'center'}
|
|
|
|
|
justifyContent={isNarrow ? 'flex-start' : 'space-between'}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
marginLeft={1}
|
|
|
|
|
marginRight={isNarrow ? 0 : 1}
|
|
|
|
|
flexDirection="row"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
flexGrow={1}
|
|
|
|
|
>
|
|
|
|
|
{showLoadingIndicator && (
|
|
|
|
|
<LoadingIndicator
|
|
|
|
|
inline
|
|
|
|
|
thought={
|
|
|
|
|
uiState.streamingState ===
|
|
|
|
|
StreamingState.WaitingForConfirmation ||
|
|
|
|
|
config.getAccessibility()?.enableLoadingPhrases === false
|
|
|
|
|
? undefined
|
|
|
|
|
: uiState.thought
|
|
|
|
|
}
|
|
|
|
|
currentLoadingPhrase={
|
|
|
|
|
config.getAccessibility()?.enableLoadingPhrases === false
|
|
|
|
|
? undefined
|
|
|
|
|
: uiState.currentLoadingPhrase
|
|
|
|
|
}
|
2026-02-09 19:24:41 -08:00
|
|
|
thoughtLabel={
|
|
|
|
|
inlineThinkingMode === 'full' ? 'Thinking ...' : undefined
|
|
|
|
|
}
|
2026-02-06 11:33:39 -08:00
|
|
|
elapsedTime={uiState.elapsedTime}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
<Box
|
|
|
|
|
marginTop={isNarrow ? 1 : 0}
|
|
|
|
|
flexDirection="column"
|
|
|
|
|
alignItems={isNarrow ? 'flex-start' : 'flex-end'}
|
|
|
|
|
>
|
2026-02-06 22:35:14 -08:00
|
|
|
{!hasPendingActionRequired && <ShortcutsHint />}
|
2026-02-06 11:33:39 -08:00
|
|
|
</Box>
|
2025-09-06 01:39:02 -04:00
|
|
|
</Box>
|
2026-02-06 11:33:39 -08:00
|
|
|
{uiState.shortcutsHelpVisible && <ShortcutsHelp />}
|
2026-02-06 22:35:14 -08:00
|
|
|
<HorizontalLine />
|
2026-02-06 11:33:39 -08:00
|
|
|
<Box
|
|
|
|
|
justifyContent={
|
|
|
|
|
settings.merged.ui.hideContextSummary
|
|
|
|
|
? 'flex-start'
|
|
|
|
|
: 'space-between'
|
|
|
|
|
}
|
|
|
|
|
width="100%"
|
|
|
|
|
flexDirection={isNarrow ? 'column' : 'row'}
|
|
|
|
|
alignItems={isNarrow ? 'flex-start' : 'center'}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
marginLeft={1}
|
|
|
|
|
marginRight={isNarrow ? 0 : 1}
|
|
|
|
|
flexDirection="row"
|
|
|
|
|
alignItems="center"
|
|
|
|
|
flexGrow={1}
|
|
|
|
|
>
|
|
|
|
|
{!showLoadingIndicator && (
|
|
|
|
|
<Box
|
|
|
|
|
flexDirection={isNarrow ? 'column' : 'row'}
|
|
|
|
|
alignItems={isNarrow ? 'flex-start' : 'center'}
|
|
|
|
|
>
|
|
|
|
|
{showApprovalIndicator && (
|
|
|
|
|
<ApprovalModeIndicator
|
|
|
|
|
approvalMode={showApprovalModeIndicator}
|
2026-02-06 19:23:59 -05:00
|
|
|
isPlanEnabled={config.isPlanEnabled()}
|
2026-02-06 11:33:39 -08:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{uiState.shellModeActive && (
|
|
|
|
|
<Box
|
|
|
|
|
marginLeft={showApprovalIndicator && !isNarrow ? 1 : 0}
|
|
|
|
|
marginTop={showApprovalIndicator && isNarrow ? 1 : 0}
|
|
|
|
|
>
|
|
|
|
|
<ShellModeIndicator />
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
{showRawMarkdownIndicator && (
|
|
|
|
|
<Box
|
|
|
|
|
marginLeft={
|
|
|
|
|
(showApprovalIndicator || uiState.shellModeActive) &&
|
|
|
|
|
!isNarrow
|
|
|
|
|
? 1
|
|
|
|
|
: 0
|
|
|
|
|
}
|
|
|
|
|
marginTop={
|
|
|
|
|
(showApprovalIndicator || uiState.shellModeActive) &&
|
|
|
|
|
isNarrow
|
|
|
|
|
? 1
|
|
|
|
|
: 0
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<RawMarkdownIndicator />
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
<Box
|
|
|
|
|
marginTop={isNarrow ? 1 : 0}
|
|
|
|
|
flexDirection="column"
|
|
|
|
|
alignItems={isNarrow ? 'flex-start' : 'flex-end'}
|
|
|
|
|
>
|
|
|
|
|
{!showLoadingIndicator && (
|
|
|
|
|
<StatusDisplay hideContextSummary={hideContextSummary} />
|
2025-09-06 01:39:02 -04:00
|
|
|
)}
|
2026-02-06 11:33:39 -08:00
|
|
|
</Box>
|
2025-09-06 01:39:02 -04:00
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
|
|
{uiState.showErrorDetails && (
|
|
|
|
|
<OverflowProvider>
|
|
|
|
|
<Box flexDirection="column">
|
|
|
|
|
<DetailedMessagesDisplay
|
|
|
|
|
messages={uiState.filteredConsoleMessages}
|
|
|
|
|
maxHeight={
|
|
|
|
|
uiState.constrainHeight ? debugConsoleMaxHeight : undefined
|
|
|
|
|
}
|
2026-01-26 15:23:54 -08:00
|
|
|
width={uiState.terminalWidth}
|
2025-11-11 07:50:11 -08:00
|
|
|
hasFocus={uiState.showErrorDetails}
|
2025-09-06 01:39:02 -04:00
|
|
|
/>
|
|
|
|
|
<ShowMoreLines constrainHeight={uiState.constrainHeight} />
|
|
|
|
|
</Box>
|
|
|
|
|
</OverflowProvider>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{uiState.isInputActive && (
|
|
|
|
|
<InputPrompt
|
|
|
|
|
buffer={uiState.buffer}
|
|
|
|
|
inputWidth={uiState.inputWidth}
|
|
|
|
|
suggestionsWidth={uiState.suggestionsWidth}
|
|
|
|
|
onSubmit={uiActions.handleFinalSubmit}
|
|
|
|
|
userMessages={uiState.userMessages}
|
2025-11-18 12:01:16 -05:00
|
|
|
setBannerVisible={uiActions.setBannerVisible}
|
2025-09-06 01:39:02 -04:00
|
|
|
onClearScreen={uiActions.handleClearScreen}
|
|
|
|
|
config={config}
|
2025-10-14 18:15:57 -07:00
|
|
|
slashCommands={uiState.slashCommands || []}
|
2025-09-06 01:39:02 -04:00
|
|
|
commandContext={uiState.commandContext}
|
|
|
|
|
shellModeActive={uiState.shellModeActive}
|
|
|
|
|
setShellModeActive={uiActions.setShellModeActive}
|
2026-01-21 10:19:47 -05:00
|
|
|
approvalMode={showApprovalModeIndicator}
|
2025-09-06 01:39:02 -04:00
|
|
|
onEscapePromptChange={uiActions.onEscapePromptChange}
|
2026-01-23 20:32:35 -05:00
|
|
|
focus={isFocused}
|
2025-09-06 01:39:02 -04:00
|
|
|
vimHandleInput={uiActions.vimHandleInput}
|
2025-09-20 10:59:37 -07:00
|
|
|
isEmbeddedShellFocused={uiState.embeddedShellFocused}
|
2025-10-16 17:04:13 -07:00
|
|
|
popAllMessages={uiActions.popAllMessages}
|
2025-09-06 01:39:02 -04:00
|
|
|
placeholder={
|
|
|
|
|
vimEnabled
|
2026-01-29 23:31:47 -08:00
|
|
|
? vimMode === 'INSERT'
|
|
|
|
|
? " Press 'Esc' for NORMAL mode."
|
|
|
|
|
: " Press 'i' for INSERT mode."
|
2025-12-19 23:37:45 +05:30
|
|
|
: uiState.shellModeActive
|
|
|
|
|
? ' Type your shell command'
|
|
|
|
|
: ' Type your message or @path/to/file'
|
2025-09-06 01:39:02 -04:00
|
|
|
}
|
2025-10-15 22:32:50 +05:30
|
|
|
setQueueErrorMessage={uiActions.setQueueErrorMessage}
|
|
|
|
|
streamingState={uiState.streamingState}
|
2025-11-11 07:50:11 -08:00
|
|
|
suggestionsPosition={suggestionsPosition}
|
|
|
|
|
onSuggestionsVisibilityChange={setSuggestionsVisible}
|
2025-09-06 01:39:02 -04:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-01-15 09:26:10 -08:00
|
|
|
{!settings.merged.ui.hideFooter && !isScreenReaderEnabled && <Footer />}
|
2025-09-06 01:39:02 -04:00
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|