Gemini CLI Core - Core functionality library for the open-source AI agent that brings the power of Gemini directly into your terminal.
Overall
score
87%
Evaluation — 87%
↑ 1.01xAgent success when using this tile
Comprehensive service layer providing file discovery, git operations, shell execution, chat recording, and system integration capabilities.
Service for discovering, filtering, and managing files within projects with support for ignore patterns and filtering options.
/**
* File discovery and filtering service with ignore pattern support
*/
class FileDiscoveryService {
constructor(projectRoot?: string);
/**
* Filter file paths based on provided options
* @param filePaths - Array of file paths to filter
* @param options - Filtering options
* @returns Filtered array of file paths
*/
filterFiles(filePaths: string[], options?: FilterFilesOptions): string[];
/**
* Check if file should be ignored by git
* @param filePath - Path to check
* @returns True if file should be git ignored
*/
shouldGitIgnoreFile(filePath: string): boolean;
/**
* Check if file should be ignored by Gemini
* @param filePath - Path to check
* @returns True if file should be Gemini ignored
*/
shouldGeminiIgnoreFile(filePath: string): boolean;
/**
* Check if file should be ignored based on options
* @param filePath - Path to check
* @param options - Filtering options
* @returns True if file should be ignored
*/
shouldIgnoreFile(filePath: string, options?: FilterFilesOptions): boolean;
/**
* Get Gemini-specific ignore patterns
* @returns Array of ignore patterns
*/
getGeminiIgnorePatterns(): string[];
}
/**
* File filtering options
*/
interface FilterFilesOptions {
excludePatterns?: string[];
includePatterns?: string[];
maxFileSize?: number;
excludeHidden?: boolean;
respectGitIgnore?: boolean;
respectGeminiIgnore?: boolean;
fileTypes?: string[];
}Service for git repository operations including status checking, commit operations, and repository information.
/**
* Git repository operations service
*/
class GitService {
constructor(repositoryPath: string);
// Repository information
isGitRepository(): Promise<boolean>;
getCurrentBranch(): Promise<string>;
getRemoteUrl(): Promise<string | null>;
getRootPath(): Promise<string>;
// Status operations
getStatus(): Promise<GitStatus>;
getUnstagedFiles(): Promise<string[]>;
getStagedFiles(): Promise<string[]>;
getUntrackedFiles(): Promise<string[]>;
// File operations
addFiles(files: string[]): Promise<void>;
commitFiles(message: string, files?: string[]): Promise<string>;
// History operations
getCommitHistory(maxCount?: number): Promise<GitCommit[]>;
getFileHistory(filePath: string, maxCount?: number): Promise<GitCommit[]>;
// Diff operations
getDiff(ref1?: string, ref2?: string): Promise<string>;
getFileDiff(filePath: string, ref?: string): Promise<string>;
}
/**
* Git repository status
*/
interface GitStatus {
current: string | null;
tracking: string | null;
ahead: number;
behind: number;
staged: GitFileStatus[];
unstaged: GitFileStatus[];
untracked: string[];
}
/**
* Git file status
*/
interface GitFileStatus {
path: string;
index: string;
workingTree: string;
}
/**
* Git commit information
*/
interface GitCommit {
hash: string;
date: Date;
message: string;
author: GitAuthor;
refs: string[];
}
/**
* Git author information
*/
interface GitAuthor {
name: string;
email: string;
}Service for recording, storing, and managing chat conversations and interactions.
/**
* Service for recording and managing chat conversations
*/
class ChatRecordingService {
constructor(config: Config, storage: Storage);
// Recording management
startRecording(sessionId: string): Promise<void>;
stopRecording(): Promise<void>;
isRecording(): boolean;
// Message recording
recordUserMessage(message: string, timestamp?: Date): Promise<void>;
recordAssistantMessage(message: string, timestamp?: Date): Promise<void>;
recordSystemMessage(message: string, timestamp?: Date): Promise<void>;
// Tool call recording
recordToolCall(
toolName: string,
parameters: any,
result?: any,
timestamp?: Date
): Promise<void>;
// History management
getRecordedHistory(sessionId: string): Promise<ChatRecord[]>;
getAllSessions(): Promise<string[]>;
deleteSession(sessionId: string): Promise<boolean>;
// Export operations
exportSession(sessionId: string, format: 'json' | 'markdown'): Promise<string>;
exportAllSessions(format: 'json' | 'markdown'): Promise<string>;
}
/**
* Chat record entry
*/
interface ChatRecord {
id: string;
sessionId: string;
timestamp: Date;
type: 'user' | 'assistant' | 'system' | 'tool_call';
content: string;
metadata?: any;
}Abstract file system service interface with concrete implementations for different environments.
/**
* Abstract file system service interface
*/
abstract class FileSystemService {
// File operations
abstract readFile(path: string): Promise<string>;
abstract writeFile(path: string, content: string): Promise<void>;
abstract appendFile(path: string, content: string): Promise<void>;
abstract deleteFile(path: string): Promise<void>;
// Directory operations
abstract readDir(path: string): Promise<string[]>;
abstract createDir(path: string, recursive?: boolean): Promise<void>;
abstract deleteDir(path: string, recursive?: boolean): Promise<void>;
// Path operations
abstract exists(path: string): Promise<boolean>;
abstract isFile(path: string): Promise<boolean>;
abstract isDirectory(path: string): Promise<boolean>;
abstract getStats(path: string): Promise<FileStats>;
// Utility operations
abstract copy(src: string, dest: string): Promise<void>;
abstract move(src: string, dest: string): Promise<void>;
abstract glob(pattern: string, options?: GlobOptions): Promise<string[]>;
}
/**
* Node.js file system service implementation
*/
class NodeFileSystemService extends FileSystemService {
constructor();
// Implements all FileSystemService abstract methods
readFile(path: string): Promise<string>;
writeFile(path: string, content: string): Promise<void>;
// ... other implementations
}
/**
* File statistics
*/
interface FileStats {
size: number;
created: Date;
modified: Date;
accessed: Date;
isFile: boolean;
isDirectory: boolean;
permissions: FilePermissions;
}
/**
* File permissions
*/
interface FilePermissions {
readable: boolean;
writable: boolean;
executable: boolean;
}
/**
* Glob options
*/
interface GlobOptions {
cwd?: string;
ignore?: string[];
dot?: boolean;
absolute?: boolean;
}Service for executing shell commands and managing command execution environments.
/**
* Service for executing shell commands and managing execution environments
*/
class ShellExecutionService {
constructor(config?: ShellExecutionConfig);
/**
* Execute a shell command
* @param command - Command to execute
* @param options - Execution options
* @returns Execution result
*/
execute(
command: string,
options?: ShellExecutionOptions
): Promise<ShellExecutionResult>;
/**
* Execute command with streaming output
* @param command - Command to execute
* @param options - Execution options
* @returns Async generator for streaming output
*/
executeStream(
command: string,
options?: ShellExecutionOptions
): AsyncGenerator<ShellOutputChunk>;
/**
* Execute multiple commands in sequence
* @param commands - Commands to execute
* @param options - Execution options
* @returns Array of execution results
*/
executeBatch(
commands: string[],
options?: ShellExecutionOptions
): Promise<ShellExecutionResult[]>;
/**
* Check if command exists in PATH
* @param command - Command name to check
* @returns True if command exists
*/
commandExists(command: string): Promise<boolean>;
/**
* Get current working directory
* @returns Current working directory path
*/
getCwd(): Promise<string>;
/**
* Set working directory for future executions
* @param path - New working directory
*/
setCwd(path: string): Promise<void>;
}
/**
* Shell execution configuration
*/
interface ShellExecutionConfig {
defaultTimeout?: number;
defaultCwd?: string;
defaultEnv?: Record<string, string>;
shell?: string;
encoding?: string;
}
/**
* Shell execution options
*/
interface ShellExecutionOptions {
cwd?: string;
env?: Record<string, string>;
timeout?: number;
input?: string;
shell?: string;
killSignal?: string;
}
/**
* Shell execution result
*/
interface ShellExecutionResult {
stdout: string;
stderr: string;
exitCode: number;
signal: string | null;
command: string;
duration: number;
}
/**
* Shell output chunk for streaming
*/
interface ShellOutputChunk {
type: 'stdout' | 'stderr';
data: string;
timestamp: Date;
}Service for detecting and preventing infinite loops in AI agent interactions.
/**
* Service for detecting and preventing infinite loops in AI interactions
*/
class LoopDetectionService {
constructor(config: LoopDetectionConfig);
/**
* Check if current interaction might be part of a loop
* @param interaction - Current interaction data
* @returns Loop detection result
*/
checkForLoop(interaction: InteractionData): LoopDetectionResult;
/**
* Record an interaction for loop detection analysis
* @param interaction - Interaction to record
*/
recordInteraction(interaction: InteractionData): void;
/**
* Reset loop detection state
*/
reset(): void;
/**
* Get current loop detection statistics
* @returns Loop detection statistics
*/
getStats(): LoopDetectionStats;
}
/**
* Loop detection configuration
*/
interface LoopDetectionConfig {
maxRepeats: number;
windowSize: number;
similarityThreshold: number;
enabled: boolean;
}
/**
* Interaction data for loop detection
*/
interface InteractionData {
id: string;
type: string;
content: string;
timestamp: Date;
metadata?: any;
}
/**
* Loop detection result
*/
interface LoopDetectionResult {
isLoop: boolean;
confidence: number;
similarInteractions: InteractionData[];
recommendation: 'continue' | 'break' | 'modify';
}
/**
* Loop detection statistics
*/
interface LoopDetectionStats {
totalInteractions: number;
detectedLoops: number;
averageConfidence: number;
lastDetection: Date | null;
}Usage Examples:
import {
FileDiscoveryService,
GitService,
ChatRecordingService,
ShellExecutionService,
Storage,
Config
} from '@google/gemini-cli-core';
// File discovery and filtering
const fileDiscovery = new FileDiscoveryService('/project/root');
const allFiles = ['/src/main.ts', '/src/test.ts', '/node_modules/lib.js'];
const filteredFiles = fileDiscovery.filterFiles(allFiles, {
excludePatterns: ['node_modules/**', '*.test.ts'],
maxFileSize: 1024 * 1024 // 1MB
});
// Git operations
const gitService = new GitService('/project/root');
const isRepo = await gitService.isGitRepository();
if (isRepo) {
const status = await gitService.getStatus();
console.log(`Branch: ${status.current}`);
console.log(`Staged files: ${status.staged.length}`);
// Commit changes
await gitService.addFiles(['src/main.ts']);
const commitHash = await gitService.commitFiles('Update main functionality');
console.log(`Committed: ${commitHash}`);
}
// Chat recording
const config = new Config();
const storage = new Storage();
const chatRecording = new ChatRecordingService(config, storage);
await chatRecording.startRecording('session-123');
await chatRecording.recordUserMessage('What files are in the project?');
await chatRecording.recordAssistantMessage('I found 15 files in your project...');
await chatRecording.recordToolCall('ls', {path: '.'}, ['file1.ts', 'file2.ts']);
// Export chat history
const history = await chatRecording.exportSession('session-123', 'markdown');
console.log(history);
// Shell command execution
const shellService = new ShellExecutionService();
const result = await shellService.execute('git status --porcelain', {
cwd: '/project/root',
timeout: 10000
});
console.log('Git status output:', result.stdout);
console.log('Exit code:', result.exitCode);
// Streaming command execution
for await (const chunk of shellService.executeStream('npm install')) {
if (chunk.type === 'stdout') {
process.stdout.write(chunk.data);
} else {
process.stderr.write(chunk.data);
}
}Install with Tessl CLI
npx tessl i tessl/npm-google--gemini-cli-coredocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10