2025-11-19 15:49:39 -08:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2026-01-22 16:02:14 -08:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2025-11-19 15:49:39 -08:00
|
|
|
import { Box, Text } from 'ink';
|
2026-02-13 17:20:14 -05:00
|
|
|
import { ToolCallStatus, mapCoreStatusToDisplayStatus } from '../../types.js';
|
2026-03-03 16:10:09 -08:00
|
|
|
import { CliSpinner } from '../CliSpinner.js';
|
2025-11-19 15:49:39 -08:00
|
|
|
import {
|
|
|
|
|
SHELL_COMMAND_NAME,
|
|
|
|
|
SHELL_NAME,
|
|
|
|
|
TOOL_STATUS,
|
2026-01-22 16:02:14 -08:00
|
|
|
SHELL_FOCUS_HINT_DELAY_MS,
|
2025-11-19 15:49:39 -08:00
|
|
|
} from '../../constants.js';
|
|
|
|
|
import { theme } from '../../semantic-colors.js';
|
2026-01-22 16:02:14 -08:00
|
|
|
import {
|
|
|
|
|
type Config,
|
|
|
|
|
SHELL_TOOL_NAME,
|
2026-02-12 16:49:07 -05:00
|
|
|
isCompletedAskUserTool,
|
2026-01-22 16:02:14 -08:00
|
|
|
type ToolResultDisplay,
|
2026-02-13 17:20:14 -05:00
|
|
|
CoreToolCallStatus,
|
2026-01-22 16:02:14 -08:00
|
|
|
} from '@google/gemini-cli-core';
|
|
|
|
|
import { useInactivityTimer } from '../../hooks/useInactivityTimer.js';
|
2026-03-09 23:26:33 +00:00
|
|
|
import { formatCommand } from '../../key/keybindingUtils.js';
|
|
|
|
|
import { Command } from '../../key/keyBindings.js';
|
2025-11-19 15:49:39 -08:00
|
|
|
|
|
|
|
|
export const STATUS_INDICATOR_WIDTH = 3;
|
|
|
|
|
|
2026-01-22 16:02:14 -08:00
|
|
|
/**
|
|
|
|
|
* Returns true if the tool name corresponds to a shell tool.
|
|
|
|
|
*/
|
|
|
|
|
export function isShellTool(name: string): boolean {
|
|
|
|
|
return (
|
|
|
|
|
name === SHELL_COMMAND_NAME ||
|
|
|
|
|
name === SHELL_NAME ||
|
|
|
|
|
name === SHELL_TOOL_NAME
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if the shell tool call is currently focusable.
|
|
|
|
|
*/
|
|
|
|
|
export function isThisShellFocusable(
|
|
|
|
|
name: string,
|
2026-02-13 17:20:14 -05:00
|
|
|
status: CoreToolCallStatus,
|
2026-01-22 16:02:14 -08:00
|
|
|
config?: Config,
|
|
|
|
|
): boolean {
|
|
|
|
|
return !!(
|
|
|
|
|
isShellTool(name) &&
|
2026-02-13 17:20:14 -05:00
|
|
|
status === CoreToolCallStatus.Executing &&
|
2026-01-22 16:02:14 -08:00
|
|
|
config?.getEnableInteractiveShell()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if this specific shell tool call is currently focused.
|
|
|
|
|
*/
|
|
|
|
|
export function isThisShellFocused(
|
|
|
|
|
name: string,
|
2026-02-13 17:20:14 -05:00
|
|
|
status: CoreToolCallStatus,
|
2026-01-22 16:02:14 -08:00
|
|
|
ptyId?: number,
|
|
|
|
|
activeShellPtyId?: number | null,
|
|
|
|
|
embeddedShellFocused?: boolean,
|
|
|
|
|
): boolean {
|
|
|
|
|
return !!(
|
|
|
|
|
isShellTool(name) &&
|
2026-02-13 17:20:14 -05:00
|
|
|
status === CoreToolCallStatus.Executing &&
|
2026-01-22 16:02:14 -08:00
|
|
|
ptyId === activeShellPtyId &&
|
|
|
|
|
embeddedShellFocused
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Hook to manage focus hint state.
|
|
|
|
|
*/
|
|
|
|
|
export function useFocusHint(
|
|
|
|
|
isThisShellFocusable: boolean,
|
|
|
|
|
isThisShellFocused: boolean,
|
|
|
|
|
resultDisplay: ToolResultDisplay | undefined,
|
|
|
|
|
) {
|
|
|
|
|
const [userHasFocused, setUserHasFocused] = useState(false);
|
2026-02-18 22:39:32 -08:00
|
|
|
|
|
|
|
|
// Derive a stable reset key for the inactivity timer. For strings and arrays
|
|
|
|
|
// (shell output), we use the length to capture updates without referential
|
|
|
|
|
// identity issues or expensive deep comparisons.
|
|
|
|
|
const resetKey =
|
|
|
|
|
typeof resultDisplay === 'string'
|
|
|
|
|
? resultDisplay.length
|
|
|
|
|
: Array.isArray(resultDisplay)
|
|
|
|
|
? resultDisplay.length
|
|
|
|
|
: !!resultDisplay;
|
|
|
|
|
|
2026-01-22 16:02:14 -08:00
|
|
|
const showFocusHint = useInactivityTimer(
|
|
|
|
|
isThisShellFocusable,
|
2026-02-18 22:39:32 -08:00
|
|
|
resetKey,
|
2026-01-22 16:02:14 -08:00
|
|
|
SHELL_FOCUS_HINT_DELAY_MS,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isThisShellFocused) {
|
|
|
|
|
setUserHasFocused(true);
|
|
|
|
|
}
|
|
|
|
|
}, [isThisShellFocused]);
|
|
|
|
|
|
|
|
|
|
const shouldShowFocusHint =
|
|
|
|
|
isThisShellFocusable && (showFocusHint || userHasFocused);
|
|
|
|
|
|
|
|
|
|
return { shouldShowFocusHint };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Component to render the focus hint.
|
|
|
|
|
*/
|
|
|
|
|
export const FocusHint: React.FC<{
|
|
|
|
|
shouldShowFocusHint: boolean;
|
|
|
|
|
isThisShellFocused: boolean;
|
|
|
|
|
}> = ({ shouldShowFocusHint, isThisShellFocused }) => {
|
|
|
|
|
if (!shouldShowFocusHint) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box marginLeft={1} flexShrink={0}>
|
2026-03-03 16:10:09 -08:00
|
|
|
<Text color={isThisShellFocused ? theme.ui.focus : theme.ui.active}>
|
2026-02-06 10:36:14 -08:00
|
|
|
{isThisShellFocused
|
|
|
|
|
? `(${formatCommand(Command.UNFOCUS_SHELL_INPUT)} to unfocus)`
|
|
|
|
|
: `(${formatCommand(Command.FOCUS_SHELL_INPUT)} to focus)`}
|
2026-01-22 16:02:14 -08:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-19 15:49:39 -08:00
|
|
|
export type TextEmphasis = 'high' | 'medium' | 'low';
|
|
|
|
|
|
|
|
|
|
type ToolStatusIndicatorProps = {
|
2026-02-13 17:20:14 -05:00
|
|
|
status: CoreToolCallStatus;
|
2025-11-19 15:49:39 -08:00
|
|
|
name: string;
|
2026-03-03 16:10:09 -08:00
|
|
|
isFocused?: boolean;
|
2025-11-19 15:49:39 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const ToolStatusIndicator: React.FC<ToolStatusIndicatorProps> = ({
|
2026-02-13 17:20:14 -05:00
|
|
|
status: coreStatus,
|
2025-11-19 15:49:39 -08:00
|
|
|
name,
|
2026-03-03 16:10:09 -08:00
|
|
|
isFocused,
|
2025-11-19 15:49:39 -08:00
|
|
|
}) => {
|
2026-02-13 17:20:14 -05:00
|
|
|
const status = mapCoreStatusToDisplayStatus(coreStatus);
|
2026-01-22 16:02:14 -08:00
|
|
|
const isShell = isShellTool(name);
|
2026-03-03 16:10:09 -08:00
|
|
|
const statusColor = isFocused
|
|
|
|
|
? theme.ui.focus
|
|
|
|
|
: isShell
|
|
|
|
|
? theme.ui.active
|
|
|
|
|
: theme.status.warning;
|
2025-11-19 15:49:39 -08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box minWidth={STATUS_INDICATOR_WIDTH}>
|
|
|
|
|
{status === ToolCallStatus.Pending && (
|
|
|
|
|
<Text color={theme.status.success}>{TOOL_STATUS.PENDING}</Text>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Executing && (
|
2026-03-03 16:10:09 -08:00
|
|
|
<Text color={statusColor}>
|
|
|
|
|
<CliSpinner type="toggle" />
|
|
|
|
|
</Text>
|
2025-11-19 15:49:39 -08:00
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Success && (
|
|
|
|
|
<Text color={theme.status.success} aria-label={'Success:'}>
|
|
|
|
|
{TOOL_STATUS.SUCCESS}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Confirming && (
|
|
|
|
|
<Text color={statusColor} aria-label={'Confirming:'}>
|
|
|
|
|
{TOOL_STATUS.CONFIRMING}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Canceled && (
|
|
|
|
|
<Text color={statusColor} aria-label={'Canceled:'} bold>
|
|
|
|
|
{TOOL_STATUS.CANCELED}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Error && (
|
|
|
|
|
<Text color={theme.status.error} aria-label={'Error:'} bold>
|
|
|
|
|
{TOOL_STATUS.ERROR}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type ToolInfoProps = {
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
2026-02-13 17:20:14 -05:00
|
|
|
status: CoreToolCallStatus;
|
2025-11-19 15:49:39 -08:00
|
|
|
emphasis: TextEmphasis;
|
2026-03-07 15:17:10 -08:00
|
|
|
progressMessage?: string;
|
2026-02-23 19:57:00 -08:00
|
|
|
originalRequestName?: string;
|
2025-11-19 15:49:39 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const ToolInfo: React.FC<ToolInfoProps> = ({
|
|
|
|
|
name,
|
|
|
|
|
description,
|
2026-02-13 17:20:14 -05:00
|
|
|
status: coreStatus,
|
2025-11-19 15:49:39 -08:00
|
|
|
emphasis,
|
2026-03-07 15:17:10 -08:00
|
|
|
progressMessage: _progressMessage,
|
2026-02-23 19:57:00 -08:00
|
|
|
originalRequestName,
|
2025-11-19 15:49:39 -08:00
|
|
|
}) => {
|
2026-02-13 17:20:14 -05:00
|
|
|
const status = mapCoreStatusToDisplayStatus(coreStatus);
|
2025-11-19 15:49:39 -08:00
|
|
|
const nameColor = React.useMemo<string>(() => {
|
|
|
|
|
switch (emphasis) {
|
|
|
|
|
case 'high':
|
|
|
|
|
return theme.text.primary;
|
|
|
|
|
case 'medium':
|
|
|
|
|
return theme.text.primary;
|
|
|
|
|
case 'low':
|
|
|
|
|
return theme.text.secondary;
|
|
|
|
|
default: {
|
|
|
|
|
const exhaustiveCheck: never = emphasis;
|
|
|
|
|
return exhaustiveCheck;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [emphasis]);
|
2026-01-27 13:30:44 -05:00
|
|
|
|
|
|
|
|
// Hide description for completed Ask User tools (the result display speaks for itself)
|
2026-02-12 16:49:07 -05:00
|
|
|
const isCompletedAskUser = isCompletedAskUserTool(name, status);
|
2026-01-27 13:30:44 -05:00
|
|
|
|
2025-11-19 15:49:39 -08:00
|
|
|
return (
|
|
|
|
|
<Box overflow="hidden" height={1} flexGrow={1} flexShrink={1}>
|
|
|
|
|
<Text strikethrough={status === ToolCallStatus.Canceled} wrap="truncate">
|
|
|
|
|
<Text color={nameColor} bold>
|
|
|
|
|
{name}
|
2026-01-27 13:30:44 -05:00
|
|
|
</Text>
|
2026-02-23 19:57:00 -08:00
|
|
|
{originalRequestName && originalRequestName !== name && (
|
|
|
|
|
<Text color={theme.text.secondary} italic>
|
|
|
|
|
{' '}
|
|
|
|
|
(redirection from {originalRequestName})
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
2026-01-27 13:30:44 -05:00
|
|
|
{!isCompletedAskUser && (
|
|
|
|
|
<>
|
|
|
|
|
{' '}
|
2026-02-24 09:13:51 -08:00
|
|
|
<Text color={theme.text.secondary}>{description}</Text>
|
2026-01-27 13:30:44 -05:00
|
|
|
</>
|
|
|
|
|
)}
|
2025-11-19 15:49:39 -08:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-02-24 09:13:51 -08:00
|
|
|
export interface McpProgressIndicatorProps {
|
|
|
|
|
progress: number;
|
|
|
|
|
total?: number;
|
|
|
|
|
message?: string;
|
|
|
|
|
barWidth: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const McpProgressIndicator: React.FC<McpProgressIndicatorProps> = ({
|
|
|
|
|
progress,
|
|
|
|
|
total,
|
|
|
|
|
message,
|
|
|
|
|
barWidth,
|
|
|
|
|
}) => {
|
|
|
|
|
const percentage =
|
|
|
|
|
total && total > 0
|
|
|
|
|
? Math.min(100, Math.round((progress / total) * 100))
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
let rawFilled: number;
|
|
|
|
|
if (total && total > 0) {
|
|
|
|
|
rawFilled = Math.round((progress / total) * barWidth);
|
|
|
|
|
} else {
|
|
|
|
|
rawFilled = Math.floor(progress) % (barWidth + 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const filled = Math.max(
|
|
|
|
|
0,
|
|
|
|
|
Math.min(Number.isFinite(rawFilled) ? rawFilled : 0, barWidth),
|
|
|
|
|
);
|
|
|
|
|
const empty = Math.max(0, barWidth - filled);
|
|
|
|
|
const progressBar = '\u2588'.repeat(filled) + '\u2591'.repeat(empty);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box flexDirection="column">
|
|
|
|
|
<Box>
|
|
|
|
|
<Text color={theme.text.accent}>
|
|
|
|
|
{progressBar} {percentage !== null ? `${percentage}%` : `${progress}`}
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
{message && (
|
|
|
|
|
<Text color={theme.text.secondary} wrap="truncate">
|
|
|
|
|
{message}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2025-11-19 15:49:39 -08:00
|
|
|
export const TrailingIndicator: React.FC = () => (
|
|
|
|
|
<Text color={theme.text.primary} wrap="truncate">
|
|
|
|
|
{' '}
|
|
|
|
|
←
|
|
|
|
|
</Text>
|
|
|
|
|
);
|