mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-16 17:11:04 -07:00
118 lines
3.1 KiB
TypeScript
118 lines
3.1 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2025 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import type React from 'react';
|
|
import { Box, Text } from 'ink';
|
|
import { theme } from '../semantic-colors.js';
|
|
import { type IdeContext, type MCPServerConfig } from '@google/gemini-cli-core';
|
|
import { useTerminalSize } from '../hooks/useTerminalSize.js';
|
|
import { isNarrowWidth } from '../utils/isNarrowWidth.js';
|
|
|
|
interface ContextSummaryDisplayProps {
|
|
geminiMdFileCount: number;
|
|
contextFileNames: string[];
|
|
mcpServers?: Record<string, MCPServerConfig>;
|
|
blockedMcpServers?: Array<{ name: string; extensionName: string }>;
|
|
ideContext?: IdeContext;
|
|
skillCount: number;
|
|
}
|
|
|
|
export const ContextSummaryDisplay: React.FC<ContextSummaryDisplayProps> = ({
|
|
geminiMdFileCount,
|
|
contextFileNames,
|
|
mcpServers,
|
|
blockedMcpServers,
|
|
ideContext,
|
|
skillCount,
|
|
}) => {
|
|
const { columns: terminalWidth } = useTerminalSize();
|
|
const isNarrow = isNarrowWidth(terminalWidth);
|
|
const mcpServerCount = Object.keys(mcpServers || {}).length;
|
|
const blockedMcpServerCount = blockedMcpServers?.length || 0;
|
|
const openFileCount = ideContext?.workspaceState?.openFiles?.length ?? 0;
|
|
|
|
if (
|
|
geminiMdFileCount === 0 &&
|
|
mcpServerCount === 0 &&
|
|
blockedMcpServerCount === 0 &&
|
|
openFileCount === 0 &&
|
|
skillCount === 0
|
|
) {
|
|
return <Text> </Text>; // Render an empty space to reserve height
|
|
}
|
|
|
|
const openFilesText = (() => {
|
|
if (openFileCount === 0) {
|
|
return '';
|
|
}
|
|
return `${openFileCount} open file${
|
|
openFileCount > 1 ? 's' : ''
|
|
} (ctrl+g to view)`;
|
|
})();
|
|
|
|
const geminiMdText = (() => {
|
|
if (geminiMdFileCount === 0) {
|
|
return '';
|
|
}
|
|
const allNamesTheSame = new Set(contextFileNames).size < 2;
|
|
const name = allNamesTheSame ? contextFileNames[0] : 'context';
|
|
return `${geminiMdFileCount} ${name} file${
|
|
geminiMdFileCount > 1 ? 's' : ''
|
|
}`;
|
|
})();
|
|
|
|
const mcpText = (() => {
|
|
if (mcpServerCount === 0 && blockedMcpServerCount === 0) {
|
|
return '';
|
|
}
|
|
|
|
const parts = [];
|
|
if (mcpServerCount > 0) {
|
|
parts.push(
|
|
`${mcpServerCount} MCP server${mcpServerCount > 1 ? 's' : ''}`,
|
|
);
|
|
}
|
|
|
|
if (blockedMcpServerCount > 0) {
|
|
let blockedText = `${blockedMcpServerCount} Blocked`;
|
|
if (mcpServerCount === 0) {
|
|
blockedText += ` MCP server${blockedMcpServerCount > 1 ? 's' : ''}`;
|
|
}
|
|
parts.push(blockedText);
|
|
}
|
|
return parts.join(', ');
|
|
})();
|
|
|
|
const skillText = (() => {
|
|
if (skillCount === 0) {
|
|
return '';
|
|
}
|
|
return `${skillCount} skill${skillCount > 1 ? 's' : ''}`;
|
|
})();
|
|
|
|
const summaryParts = [openFilesText, geminiMdText, mcpText, skillText].filter(
|
|
Boolean,
|
|
);
|
|
|
|
if (isNarrow) {
|
|
return (
|
|
<Box flexDirection="column" paddingX={1}>
|
|
{summaryParts.map((part, index) => (
|
|
<Text key={index} color={theme.text.secondary}>
|
|
- {part}
|
|
</Text>
|
|
))}
|
|
</Box>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Box paddingX={1}>
|
|
<Text color={theme.text.secondary}>{summaryParts.join(' | ')}</Text>
|
|
</Box>
|
|
);
|
|
};
|