2025-04-18 17:44:24 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
Initial commit of Gemini Code CLI
This commit introduces the initial codebase for the Gemini Code CLI, a command-line interface designed to facilitate interaction with the Gemini API for software engineering tasks.
The code was migrated from a previous git repository as a single squashed commit.
Core Features & Components:
* **Gemini Integration:** Leverages the `@google/genai` SDK to interact with the Gemini models, supporting chat history, streaming responses, and function calling (tools).
* **Terminal UI:** Built with Ink (React for CLIs) providing an interactive chat interface within the terminal, including input prompts, message display, loading indicators, and tool interaction elements.
* **Tooling Framework:** Implements a robust tool system allowing Gemini to interact with the local environment. Includes tools for:
* File system listing (`ls`)
* File reading (`read-file`)
* Content searching (`grep`)
* File globbing (`glob`)
* File editing (`edit`)
* File writing (`write-file`)
* Executing bash commands (`terminal`)
* **State Management:** Handles the streaming state of Gemini responses and manages the conversation history.
* **Configuration:** Parses command-line arguments (`yargs`) and loads environment variables (`dotenv`) for setup.
* **Project Structure:** Organized into `core`, `ui`, `tools`, `config`, and `utils` directories using TypeScript. Includes basic build (`tsc`) and start scripts.
This initial version establishes the foundation for a powerful CLI tool enabling developers to use Gemini for coding assistance directly in their terminal environment.
---
Created by yours truly: __Gemini Code__
2025-04-15 21:41:08 -07:00
|
|
|
import React from 'react';
|
|
|
|
|
import { Box, Text } from 'ink';
|
2025-05-28 18:17:19 +00:00
|
|
|
import { IndividualToolCallDisplay, ToolCallStatus } from '../../types.js';
|
2025-04-21 10:53:11 -04:00
|
|
|
import { DiffRenderer } from './DiffRenderer.js';
|
|
|
|
|
import { Colors } from '../../colors.js';
|
2025-05-15 00:36:08 -07:00
|
|
|
import { MarkdownDisplay } from '../../utils/MarkdownDisplay.js';
|
2025-05-28 18:17:19 +00:00
|
|
|
import { GeminiRespondingSpinner } from '../GeminiRespondingSpinner.js';
|
Initial commit of Gemini Code CLI
This commit introduces the initial codebase for the Gemini Code CLI, a command-line interface designed to facilitate interaction with the Gemini API for software engineering tasks.
The code was migrated from a previous git repository as a single squashed commit.
Core Features & Components:
* **Gemini Integration:** Leverages the `@google/genai` SDK to interact with the Gemini models, supporting chat history, streaming responses, and function calling (tools).
* **Terminal UI:** Built with Ink (React for CLIs) providing an interactive chat interface within the terminal, including input prompts, message display, loading indicators, and tool interaction elements.
* **Tooling Framework:** Implements a robust tool system allowing Gemini to interact with the local environment. Includes tools for:
* File system listing (`ls`)
* File reading (`read-file`)
* Content searching (`grep`)
* File globbing (`glob`)
* File editing (`edit`)
* File writing (`write-file`)
* Executing bash commands (`terminal`)
* **State Management:** Handles the streaming state of Gemini responses and manages the conversation history.
* **Configuration:** Parses command-line arguments (`yargs`) and loads environment variables (`dotenv`) for setup.
* **Project Structure:** Organized into `core`, `ui`, `tools`, `config`, and `utils` directories using TypeScript. Includes basic build (`tsc`) and start scripts.
This initial version establishes the foundation for a powerful CLI tool enabling developers to use Gemini for coding assistance directly in their terminal environment.
---
Created by yours truly: __Gemini Code__
2025-04-15 21:41:08 -07:00
|
|
|
|
2025-05-23 05:28:31 +00:00
|
|
|
const STATIC_HEIGHT = 1;
|
|
|
|
|
const RESERVED_LINE_COUNT = 5; // for tool name, status, padding etc.
|
|
|
|
|
const STATUS_INDICATOR_WIDTH = 3;
|
|
|
|
|
|
|
|
|
|
export type TextEmphasis = 'high' | 'medium' | 'low';
|
|
|
|
|
|
2025-05-15 00:19:41 -07:00
|
|
|
export interface ToolMessageProps extends IndividualToolCallDisplay {
|
|
|
|
|
availableTerminalHeight: number;
|
2025-05-23 05:28:31 +00:00
|
|
|
emphasis?: TextEmphasis;
|
2025-05-30 12:43:59 -07:00
|
|
|
renderOutputAsMarkdown?: boolean;
|
2025-05-15 00:19:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ToolMessage: React.FC<ToolMessageProps> = ({
|
2025-04-17 18:06:21 -04:00
|
|
|
name,
|
|
|
|
|
description,
|
|
|
|
|
resultDisplay,
|
|
|
|
|
status,
|
2025-05-15 00:19:41 -07:00
|
|
|
availableTerminalHeight,
|
2025-05-23 05:28:31 +00:00
|
|
|
emphasis = 'medium',
|
2025-05-30 12:43:59 -07:00
|
|
|
renderOutputAsMarkdown = true,
|
2025-04-17 18:06:21 -04:00
|
|
|
}) => {
|
2025-05-23 05:28:31 +00:00
|
|
|
const contentHeightEstimate =
|
|
|
|
|
availableTerminalHeight - STATIC_HEIGHT - RESERVED_LINE_COUNT;
|
|
|
|
|
const resultIsString =
|
|
|
|
|
typeof resultDisplay === 'string' && resultDisplay.trim().length > 0;
|
|
|
|
|
const lines = React.useMemo(
|
|
|
|
|
() => (resultIsString ? resultDisplay.split('\n') : []),
|
|
|
|
|
[resultIsString, resultDisplay],
|
|
|
|
|
);
|
2025-05-15 00:19:41 -07:00
|
|
|
|
|
|
|
|
// Truncate the overall string content if it's too long.
|
|
|
|
|
// MarkdownRenderer will handle specific truncation for code blocks within this content.
|
2025-05-23 05:28:31 +00:00
|
|
|
// Estimate available height for this specific tool message content area
|
|
|
|
|
// This is a rough estimate; ideally, we'd have a more precise measurement.
|
|
|
|
|
const displayableResult = React.useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
resultIsString
|
2025-05-30 01:58:09 -07:00
|
|
|
? lines.slice(-contentHeightEstimate).join('\n')
|
2025-05-23 05:28:31 +00:00
|
|
|
: resultDisplay,
|
|
|
|
|
[lines, resultIsString, contentHeightEstimate, resultDisplay],
|
|
|
|
|
);
|
|
|
|
|
const hiddenLines = lines.length - contentHeightEstimate;
|
2025-05-15 00:19:41 -07:00
|
|
|
|
2025-04-17 18:06:21 -04:00
|
|
|
return (
|
2025-04-22 07:48:12 -04:00
|
|
|
<Box paddingX={1} paddingY={0} flexDirection="column">
|
|
|
|
|
<Box minHeight={1}>
|
2025-05-24 00:44:17 -07:00
|
|
|
<ToolStatusIndicator status={status} />
|
2025-05-23 05:28:31 +00:00
|
|
|
<ToolInfo
|
|
|
|
|
name={name}
|
|
|
|
|
status={status}
|
|
|
|
|
description={description}
|
|
|
|
|
emphasis={emphasis}
|
|
|
|
|
/>
|
|
|
|
|
{emphasis === 'high' && <TrailingIndicator />}
|
2025-04-22 07:48:12 -04:00
|
|
|
</Box>
|
2025-05-23 05:28:31 +00:00
|
|
|
{displayableResult && (
|
2025-05-30 01:58:09 -07:00
|
|
|
<Box paddingLeft={STATUS_INDICATOR_WIDTH} width="100%" marginTop={1}>
|
2025-05-15 00:19:41 -07:00
|
|
|
<Box flexDirection="column">
|
2025-05-30 01:58:09 -07:00
|
|
|
{hiddenLines > 0 && (
|
|
|
|
|
<Box>
|
2025-06-05 14:35:47 -07:00
|
|
|
<Text color={Colors.Gray}>
|
2025-05-30 01:58:09 -07:00
|
|
|
... first {hiddenLines} line{hiddenLines === 1 ? '' : 's'}{' '}
|
|
|
|
|
hidden ...
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2025-05-30 12:43:59 -07:00
|
|
|
{typeof displayableResult === 'string' &&
|
|
|
|
|
renderOutputAsMarkdown && (
|
|
|
|
|
<Box flexDirection="column">
|
|
|
|
|
<MarkdownDisplay
|
|
|
|
|
text={displayableResult}
|
|
|
|
|
isPending={false}
|
|
|
|
|
availableTerminalHeight={availableTerminalHeight}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
{typeof displayableResult === 'string' &&
|
|
|
|
|
!renderOutputAsMarkdown && (
|
|
|
|
|
<Box flexDirection="column">
|
|
|
|
|
<Text>{displayableResult}</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
2025-05-23 05:28:31 +00:00
|
|
|
{typeof displayableResult !== 'string' && (
|
2025-05-15 23:51:53 -07:00
|
|
|
<DiffRenderer
|
|
|
|
|
diffContent={displayableResult.fileDiff}
|
|
|
|
|
filename={displayableResult.fileName}
|
|
|
|
|
/>
|
2025-05-15 00:19:41 -07:00
|
|
|
)}
|
2025-04-22 07:48:12 -04:00
|
|
|
</Box>
|
Initial commit of Gemini Code CLI
This commit introduces the initial codebase for the Gemini Code CLI, a command-line interface designed to facilitate interaction with the Gemini API for software engineering tasks.
The code was migrated from a previous git repository as a single squashed commit.
Core Features & Components:
* **Gemini Integration:** Leverages the `@google/genai` SDK to interact with the Gemini models, supporting chat history, streaming responses, and function calling (tools).
* **Terminal UI:** Built with Ink (React for CLIs) providing an interactive chat interface within the terminal, including input prompts, message display, loading indicators, and tool interaction elements.
* **Tooling Framework:** Implements a robust tool system allowing Gemini to interact with the local environment. Includes tools for:
* File system listing (`ls`)
* File reading (`read-file`)
* Content searching (`grep`)
* File globbing (`glob`)
* File editing (`edit`)
* File writing (`write-file`)
* Executing bash commands (`terminal`)
* **State Management:** Handles the streaming state of Gemini responses and manages the conversation history.
* **Configuration:** Parses command-line arguments (`yargs`) and loads environment variables (`dotenv`) for setup.
* **Project Structure:** Organized into `core`, `ui`, `tools`, `config`, and `utils` directories using TypeScript. Includes basic build (`tsc`) and start scripts.
This initial version establishes the foundation for a powerful CLI tool enabling developers to use Gemini for coding assistance directly in their terminal environment.
---
Created by yours truly: __Gemini Code__
2025-04-15 21:41:08 -07:00
|
|
|
</Box>
|
2025-04-17 18:06:21 -04:00
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
Initial commit of Gemini Code CLI
This commit introduces the initial codebase for the Gemini Code CLI, a command-line interface designed to facilitate interaction with the Gemini API for software engineering tasks.
The code was migrated from a previous git repository as a single squashed commit.
Core Features & Components:
* **Gemini Integration:** Leverages the `@google/genai` SDK to interact with the Gemini models, supporting chat history, streaming responses, and function calling (tools).
* **Terminal UI:** Built with Ink (React for CLIs) providing an interactive chat interface within the terminal, including input prompts, message display, loading indicators, and tool interaction elements.
* **Tooling Framework:** Implements a robust tool system allowing Gemini to interact with the local environment. Includes tools for:
* File system listing (`ls`)
* File reading (`read-file`)
* Content searching (`grep`)
* File globbing (`glob`)
* File editing (`edit`)
* File writing (`write-file`)
* Executing bash commands (`terminal`)
* **State Management:** Handles the streaming state of Gemini responses and manages the conversation history.
* **Configuration:** Parses command-line arguments (`yargs`) and loads environment variables (`dotenv`) for setup.
* **Project Structure:** Organized into `core`, `ui`, `tools`, `config`, and `utils` directories using TypeScript. Includes basic build (`tsc`) and start scripts.
This initial version establishes the foundation for a powerful CLI tool enabling developers to use Gemini for coding assistance directly in their terminal environment.
---
Created by yours truly: __Gemini Code__
2025-04-15 21:41:08 -07:00
|
|
|
};
|
2025-05-23 05:28:31 +00:00
|
|
|
|
2025-05-23 10:25:17 -07:00
|
|
|
type ToolStatusIndicatorProps = {
|
2025-05-23 05:28:31 +00:00
|
|
|
status: ToolCallStatus;
|
|
|
|
|
};
|
2025-05-28 18:17:19 +00:00
|
|
|
|
2025-05-23 10:25:17 -07:00
|
|
|
const ToolStatusIndicator: React.FC<ToolStatusIndicatorProps> = ({
|
|
|
|
|
status,
|
2025-05-28 18:17:19 +00:00
|
|
|
}) => (
|
|
|
|
|
<Box minWidth={STATUS_INDICATOR_WIDTH}>
|
|
|
|
|
{status === ToolCallStatus.Pending && (
|
|
|
|
|
<Text color={Colors.AccentGreen}>o</Text>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Executing && (
|
|
|
|
|
<GeminiRespondingSpinner
|
|
|
|
|
spinnerType="toggle"
|
|
|
|
|
nonRespondingDisplay={'⊷'}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Success && (
|
|
|
|
|
<Text color={Colors.AccentGreen}>✔</Text>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Confirming && (
|
|
|
|
|
<Text color={Colors.AccentYellow}>?</Text>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Canceled && (
|
|
|
|
|
<Text color={Colors.AccentYellow} bold>
|
|
|
|
|
-
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
{status === ToolCallStatus.Error && (
|
|
|
|
|
<Text color={Colors.AccentRed} bold>
|
|
|
|
|
x
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
2025-05-23 05:28:31 +00:00
|
|
|
|
|
|
|
|
type ToolInfo = {
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
|
|
|
|
status: ToolCallStatus;
|
|
|
|
|
emphasis: TextEmphasis;
|
|
|
|
|
};
|
|
|
|
|
const ToolInfo: React.FC<ToolInfo> = ({
|
|
|
|
|
name,
|
|
|
|
|
description,
|
|
|
|
|
status,
|
|
|
|
|
emphasis,
|
|
|
|
|
}) => {
|
|
|
|
|
const nameColor = React.useMemo<string>(() => {
|
|
|
|
|
switch (emphasis) {
|
|
|
|
|
case 'high':
|
|
|
|
|
return Colors.Foreground;
|
|
|
|
|
case 'medium':
|
|
|
|
|
return Colors.Foreground;
|
|
|
|
|
case 'low':
|
2025-06-05 14:35:47 -07:00
|
|
|
return Colors.Gray;
|
2025-05-23 05:28:31 +00:00
|
|
|
default: {
|
|
|
|
|
const exhaustiveCheck: never = emphasis;
|
|
|
|
|
return exhaustiveCheck;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, [emphasis]);
|
|
|
|
|
return (
|
|
|
|
|
<Box>
|
|
|
|
|
<Text
|
|
|
|
|
wrap="truncate-end"
|
|
|
|
|
strikethrough={status === ToolCallStatus.Canceled}
|
|
|
|
|
>
|
|
|
|
|
<Text color={nameColor} bold>
|
|
|
|
|
{name}
|
|
|
|
|
</Text>{' '}
|
2025-06-05 14:35:47 -07:00
|
|
|
<Text color={Colors.Gray}>{description}</Text>
|
2025-05-23 05:28:31 +00:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const TrailingIndicator: React.FC = () => (
|
|
|
|
|
<Text color={Colors.Foreground}> ←</Text>
|
|
|
|
|
);
|