2025-04-18 17:44:24 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2025-08-26 00:04:53 +02:00
|
|
|
import type React from 'react';
|
|
|
|
|
import { useMemo } from 'react';
|
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 { Box } from 'ink';
|
2025-08-26 00:04:53 +02:00
|
|
|
import type { IndividualToolCallDisplay } from '../../types.js';
|
|
|
|
|
import { ToolCallStatus } from '../../types.js';
|
2025-04-18 19:09:41 -04:00
|
|
|
import { ToolMessage } from './ToolMessage.js';
|
|
|
|
|
import { ToolConfirmationMessage } from './ToolConfirmationMessage.js';
|
2025-08-15 20:18:31 -07:00
|
|
|
import { Colors } from '../../colors.js';
|
2025-08-26 00:04:53 +02:00
|
|
|
import type { Config } from '@google/gemini-cli-core';
|
2025-07-18 17:30:28 -07:00
|
|
|
import { SHELL_COMMAND_NAME } from '../../constants.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
|
|
|
|
|
|
|
|
interface ToolGroupMessageProps {
|
2025-04-25 17:11:08 -07:00
|
|
|
groupId: number;
|
2025-04-17 18:06:21 -04:00
|
|
|
toolCalls: IndividualToolCallDisplay[];
|
2025-06-19 20:17:23 +00:00
|
|
|
availableTerminalHeight?: number;
|
|
|
|
|
terminalWidth: number;
|
2025-08-26 10:02:22 -07:00
|
|
|
config: Config;
|
2025-06-12 02:21:54 +01:00
|
|
|
isFocused?: boolean;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Main component renders the border and maps the tools using ToolMessage
|
2025-04-18 19:09:41 -04:00
|
|
|
export const ToolGroupMessage: React.FC<ToolGroupMessageProps> = ({
|
2025-04-17 18:06:21 -04:00
|
|
|
toolCalls,
|
2025-05-15 00:19:41 -07:00
|
|
|
availableTerminalHeight,
|
2025-06-19 20:17:23 +00:00
|
|
|
terminalWidth,
|
2025-06-08 18:56:58 +01:00
|
|
|
config,
|
2025-06-12 02:21:54 +01:00
|
|
|
isFocused = true,
|
2025-04-17 18:06:21 -04:00
|
|
|
}) => {
|
2025-04-22 07:48:12 -04:00
|
|
|
const hasPending = !toolCalls.every(
|
|
|
|
|
(t) => t.status === ToolCallStatus.Success,
|
|
|
|
|
);
|
2025-07-18 17:30:28 -07:00
|
|
|
const isShellCommand = toolCalls.some((t) => t.name === SHELL_COMMAND_NAME);
|
|
|
|
|
const borderColor =
|
2025-08-15 20:18:31 -07:00
|
|
|
hasPending || isShellCommand ? Colors.AccentYellow : Colors.Gray;
|
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-15 00:19:41 -07:00
|
|
|
const staticHeight = /* border */ 2 + /* marginBottom */ 1;
|
2025-06-19 20:17:23 +00:00
|
|
|
// This is a bit of a magic number, but it accounts for the border and
|
|
|
|
|
// marginLeft.
|
|
|
|
|
const innerWidth = terminalWidth - 4;
|
2025-05-15 00:19:41 -07:00
|
|
|
|
2025-05-23 05:28:31 +00:00
|
|
|
// only prompt for tool approval on the first 'confirming' tool in the list
|
|
|
|
|
// note, after the CTA, this automatically moves over to the next 'confirming' tool
|
2025-05-22 05:57:53 +00:00
|
|
|
const toolAwaitingApproval = useMemo(
|
|
|
|
|
() => toolCalls.find((tc) => tc.status === ToolCallStatus.Confirming),
|
|
|
|
|
[toolCalls],
|
|
|
|
|
);
|
|
|
|
|
|
2025-06-19 20:17:23 +00:00
|
|
|
let countToolCallsWithResults = 0;
|
|
|
|
|
for (const tool of toolCalls) {
|
|
|
|
|
if (tool.resultDisplay !== undefined && tool.resultDisplay !== '') {
|
|
|
|
|
countToolCallsWithResults++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const countOneLineToolCalls = toolCalls.length - countToolCallsWithResults;
|
|
|
|
|
const availableTerminalHeightPerToolMessage = availableTerminalHeight
|
|
|
|
|
? Math.max(
|
|
|
|
|
Math.floor(
|
|
|
|
|
(availableTerminalHeight - staticHeight - countOneLineToolCalls) /
|
|
|
|
|
Math.max(1, countToolCallsWithResults),
|
|
|
|
|
),
|
|
|
|
|
1,
|
|
|
|
|
)
|
|
|
|
|
: undefined;
|
|
|
|
|
|
2025-04-17 18:06:21 -04:00
|
|
|
return (
|
2025-04-22 07:48:12 -04:00
|
|
|
<Box
|
|
|
|
|
flexDirection="column"
|
|
|
|
|
borderStyle="round"
|
2025-04-25 17:11:08 -07:00
|
|
|
/*
|
|
|
|
|
This width constraint is highly important and protects us from an Ink rendering bug.
|
|
|
|
|
Since the ToolGroup can typically change rendering states frequently, it can cause
|
|
|
|
|
Ink to render the border of the box incorrectly and span multiple lines and even
|
|
|
|
|
cause tearing.
|
|
|
|
|
*/
|
|
|
|
|
width="100%"
|
|
|
|
|
marginLeft={1}
|
2025-04-22 07:48:12 -04:00
|
|
|
borderDimColor={hasPending}
|
|
|
|
|
borderColor={borderColor}
|
2025-08-25 11:26:06 -07:00
|
|
|
gap={1}
|
2025-04-22 07:48:12 -04:00
|
|
|
>
|
2025-05-23 05:28:31 +00:00
|
|
|
{toolCalls.map((tool) => {
|
|
|
|
|
const isConfirming = toolAwaitingApproval?.callId === tool.callId;
|
|
|
|
|
return (
|
2025-06-09 12:19:42 -07:00
|
|
|
<Box key={tool.callId} flexDirection="column" minHeight={1}>
|
2025-05-23 05:28:31 +00:00
|
|
|
<Box flexDirection="row" alignItems="center">
|
|
|
|
|
<ToolMessage
|
|
|
|
|
callId={tool.callId}
|
|
|
|
|
name={tool.name}
|
|
|
|
|
description={tool.description}
|
|
|
|
|
resultDisplay={tool.resultDisplay}
|
|
|
|
|
status={tool.status}
|
2025-04-18 18:08:43 -04:00
|
|
|
confirmationDetails={tool.confirmationDetails}
|
2025-06-19 20:17:23 +00:00
|
|
|
availableTerminalHeight={availableTerminalHeightPerToolMessage}
|
|
|
|
|
terminalWidth={innerWidth}
|
2025-05-23 05:28:31 +00:00
|
|
|
emphasis={
|
|
|
|
|
isConfirming
|
|
|
|
|
? 'high'
|
|
|
|
|
: toolAwaitingApproval
|
|
|
|
|
? 'low'
|
|
|
|
|
: 'medium'
|
|
|
|
|
}
|
2025-05-30 12:43:59 -07:00
|
|
|
renderOutputAsMarkdown={tool.renderOutputAsMarkdown}
|
2025-05-23 05:28:31 +00:00
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
{tool.status === ToolCallStatus.Confirming &&
|
|
|
|
|
isConfirming &&
|
|
|
|
|
tool.confirmationDetails && (
|
|
|
|
|
<ToolConfirmationMessage
|
|
|
|
|
confirmationDetails={tool.confirmationDetails}
|
2025-06-08 18:56:58 +01:00
|
|
|
config={config}
|
2025-06-12 02:21:54 +01:00
|
|
|
isFocused={isFocused}
|
2025-06-19 20:17:23 +00:00
|
|
|
availableTerminalHeight={
|
|
|
|
|
availableTerminalHeightPerToolMessage
|
|
|
|
|
}
|
|
|
|
|
terminalWidth={innerWidth}
|
2025-05-23 05:28:31 +00: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
|
|
|
};
|