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 { render } from 'ink';
|
2025-04-18 19:09:41 -04:00
|
|
|
import { App } from './ui/App.js';
|
2025-04-19 19:45:42 +01:00
|
|
|
import { loadCliConfig } from './config/config.js';
|
2025-04-18 16:14:20 -07: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
|
|
|
async function main() {
|
2025-04-19 19:45:42 +01:00
|
|
|
// Load configuration
|
|
|
|
|
const config = loadCliConfig();
|
|
|
|
|
// Render UI, passing necessary config values
|
2025-04-18 17:06:16 +01:00
|
|
|
render(
|
|
|
|
|
React.createElement(App, {
|
2025-04-19 19:45:42 +01:00
|
|
|
config,
|
2025-04-18 17:06:16 +01: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
|
|
|
}
|
|
|
|
|
|
2025-04-16 16:53:56 -07:00
|
|
|
// --- Global Unhandled Rejection Handler ---
|
2025-04-18 16:38:01 -07:00
|
|
|
process.on('unhandledRejection', (reason, _promise) => {
|
2025-04-17 18:06:21 -04:00
|
|
|
// Check if this is the known 429 ClientError that sometimes escapes
|
|
|
|
|
// this is a workaround for a specific issue with the way we are calling gemini
|
|
|
|
|
// where a 429 error is thrown but not caught, causing an unhandled rejection
|
|
|
|
|
// TODO(adh): Remove this when the race condition is fixed
|
|
|
|
|
const isKnownEscaped429 =
|
|
|
|
|
reason instanceof Error &&
|
|
|
|
|
reason.name === 'ClientError' &&
|
|
|
|
|
reason.message.includes('got status: 429');
|
2025-04-16 16:53:56 -07:00
|
|
|
|
2025-04-17 18:06:21 -04:00
|
|
|
if (isKnownEscaped429) {
|
|
|
|
|
// Log it differently and DON'T exit, as it's likely already handled visually
|
|
|
|
|
console.warn('-----------------------------------------');
|
|
|
|
|
console.warn(
|
|
|
|
|
'WORKAROUND: Suppressed known escaped 429 Unhandled Rejection.',
|
|
|
|
|
);
|
|
|
|
|
console.warn('-----------------------------------------');
|
|
|
|
|
console.warn('Reason:', reason);
|
2025-04-21 12:15:47 -07:00
|
|
|
return;
|
|
|
|
|
// No process.exit(1); Don't exit.
|
2025-04-17 18:06:21 -04:00
|
|
|
}
|
2025-04-21 12:15:47 -07:00
|
|
|
|
|
|
|
|
// Log other unexpected unhandled rejections as critical errors
|
|
|
|
|
console.error('=========================================');
|
|
|
|
|
console.error('CRITICAL: Unhandled Promise Rejection!');
|
|
|
|
|
console.error('=========================================');
|
|
|
|
|
console.error('Reason:', reason);
|
|
|
|
|
console.error('Stack trace may follow:');
|
|
|
|
|
if (!(reason instanceof Error)) {
|
|
|
|
|
console.error(reason);
|
|
|
|
|
}
|
|
|
|
|
// Exit for genuinely unhandled errors
|
|
|
|
|
process.exit(1);
|
2025-04-16 16:53:56 -07: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
|
|
|
// --- Global Entry Point ---
|
|
|
|
|
main().catch((error) => {
|
2025-04-17 18:06:21 -04:00
|
|
|
console.error('An unexpected critical error occurred:');
|
|
|
|
|
if (error instanceof Error) {
|
|
|
|
|
console.error(error.message);
|
|
|
|
|
} else {
|
|
|
|
|
console.error(String(error));
|
|
|
|
|
}
|
|
|
|
|
process.exit(1);
|
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
|
|
|
});
|