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';
|
2026-01-27 11:59:00 -08:00
|
|
|
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 { Text, Box } from 'ink';
|
2025-09-10 10:57:07 -07:00
|
|
|
import { theme } from '../../semantic-colors.js';
|
2025-08-28 20:52:14 +00:00
|
|
|
import { SCREEN_READER_USER_PREFIX } from '../../textConstants.js';
|
2025-08-26 11:51:27 +08:00
|
|
|
import { isSlashCommand as checkIsSlashCommand } from '../../utils/commandUtils.js';
|
2026-01-27 11:59:00 -08:00
|
|
|
import {
|
|
|
|
|
calculateTransformationsForLine,
|
|
|
|
|
calculateTransformedLine,
|
|
|
|
|
} from '../shared/text-buffer.js';
|
2026-01-26 15:23:54 -08:00
|
|
|
import { HalfLinePaddedBox } from '../shared/HalfLinePaddedBox.js';
|
|
|
|
|
import { DEFAULT_BACKGROUND_OPACITY } from '../../constants.js';
|
|
|
|
|
import { useConfig } from '../../contexts/ConfigContext.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 UserMessageProps {
|
2025-04-17 18:06:21 -04:00
|
|
|
text: string;
|
2025-11-11 07:50:11 -08:00
|
|
|
width: number;
|
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-11-11 07:50:11 -08:00
|
|
|
export const UserMessage: React.FC<UserMessageProps> = ({ text, width }) => {
|
2025-04-17 18:06:21 -04:00
|
|
|
const prefix = '> ';
|
|
|
|
|
const prefixWidth = prefix.length;
|
2025-08-26 11:51:27 +08:00
|
|
|
const isSlashCommand = checkIsSlashCommand(text);
|
2026-01-26 15:23:54 -08:00
|
|
|
const config = useConfig();
|
|
|
|
|
const useBackgroundColor = config.getUseBackgroundColor();
|
2025-07-31 16:24:23 -07:00
|
|
|
|
2025-09-10 10:57:07 -07:00
|
|
|
const textColor = isSlashCommand ? theme.text.accent : theme.text.secondary;
|
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
|
|
|
|
2026-01-27 11:59:00 -08:00
|
|
|
const displayText = useMemo(() => {
|
|
|
|
|
if (!text) return text;
|
|
|
|
|
return text
|
|
|
|
|
.split('\n')
|
|
|
|
|
.map((line) => {
|
|
|
|
|
const transformations = calculateTransformationsForLine(line);
|
|
|
|
|
// We pass a cursor position of [-1, -1] so that no transformations are expanded (e.g. images remain collapsed)
|
|
|
|
|
const { transformedLine } = calculateTransformedLine(
|
|
|
|
|
line,
|
|
|
|
|
0, // line index doesn't matter since cursor is [-1, -1]
|
|
|
|
|
[-1, -1],
|
|
|
|
|
transformations,
|
|
|
|
|
);
|
|
|
|
|
return transformedLine;
|
|
|
|
|
})
|
|
|
|
|
.join('\n');
|
|
|
|
|
}, [text]);
|
|
|
|
|
|
2025-04-17 18:06:21 -04:00
|
|
|
return (
|
2026-01-26 15:23:54 -08:00
|
|
|
<HalfLinePaddedBox
|
2026-02-10 09:36:20 -08:00
|
|
|
backgroundBaseColor={theme.text.secondary}
|
2026-01-26 15:23:54 -08:00
|
|
|
backgroundOpacity={DEFAULT_BACKGROUND_OPACITY}
|
|
|
|
|
useBackgroundColor={useBackgroundColor}
|
2025-11-11 07:50:11 -08:00
|
|
|
>
|
2026-01-26 15:23:54 -08:00
|
|
|
<Box
|
|
|
|
|
flexDirection="row"
|
|
|
|
|
paddingY={0}
|
|
|
|
|
marginY={useBackgroundColor ? 0 : 1}
|
|
|
|
|
paddingX={useBackgroundColor ? 1 : 0}
|
|
|
|
|
alignSelf="flex-start"
|
|
|
|
|
width={width}
|
|
|
|
|
>
|
|
|
|
|
<Box width={prefixWidth} flexShrink={0}>
|
|
|
|
|
<Text
|
|
|
|
|
color={theme.text.accent}
|
|
|
|
|
aria-label={SCREEN_READER_USER_PREFIX}
|
|
|
|
|
>
|
|
|
|
|
{prefix}
|
|
|
|
|
</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
<Box flexGrow={1}>
|
|
|
|
|
<Text wrap="wrap" color={textColor}>
|
2026-01-27 11:59:00 -08:00
|
|
|
{displayText}
|
2026-01-26 15:23:54 -08:00
|
|
|
</Text>
|
|
|
|
|
</Box>
|
2025-04-17 18:06:21 -04:00
|
|
|
</Box>
|
2026-01-26 15:23:54 -08:00
|
|
|
</HalfLinePaddedBox>
|
2025-04-17 18:06:21 -04:00
|
|
|
);
|
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
|
|
|
};
|