2026-05-16 20:10:49 -04:00
|
|
|
/**
|
|
|
|
|
* @fileoverview Resolve the Gemini CLI binary across common install paths.
|
|
|
|
|
*
|
|
|
|
|
* Mirrors codex-cli-resolver.ts and opencode-cli-resolver.ts. Finds the
|
|
|
|
|
* `gemini` binary and provides an augmented PATH directory for tmux sessions.
|
|
|
|
|
*
|
|
|
|
|
* @module utils/gemini-cli-resolver
|
|
|
|
|
*/
|
|
|
|
|
|
2026-08-20 12:47:42 -04:00
|
|
|
import { join } from 'node:path';
|
2026-05-16 20:10:49 -04:00
|
|
|
import { homedir } from 'node:os';
|
2026-08-20 12:47:42 -04:00
|
|
|
import { createCliExecutableResolver, formatCliNotFoundMessage } from './cli-executable-resolver.js';
|
2026-05-16 20:10:49 -04:00
|
|
|
|
|
|
|
|
/** Common directories where the Gemini CLI binary may be installed */
|
|
|
|
|
const GEMINI_SEARCH_DIRS = [
|
|
|
|
|
join(homedir(), '.gemini', 'bin'),
|
|
|
|
|
join(homedir(), '.local', 'bin'),
|
|
|
|
|
'/usr/local/bin',
|
|
|
|
|
join(homedir(), '.bun', 'bin'),
|
|
|
|
|
join(homedir(), '.npm-global', 'bin'),
|
|
|
|
|
join(homedir(), 'bin'),
|
|
|
|
|
];
|
|
|
|
|
|
2026-08-20 12:47:42 -04:00
|
|
|
const geminiResolver = createCliExecutableResolver({ binary: 'gemini', searchDirs: GEMINI_SEARCH_DIRS });
|
|
|
|
|
const GEMINI_NOT_FOUND = 'Gemini CLI not found. Install with: npm install -g @google/gemini-cli';
|
2026-05-16 20:10:49 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Finds the directory containing the `gemini` binary.
|
|
|
|
|
* Checks `which gemini` first, then falls back to common install locations.
|
|
|
|
|
*
|
|
|
|
|
* @returns Directory path, or null if not found
|
|
|
|
|
*/
|
|
|
|
|
export function resolveGeminiDir(): string | null {
|
2026-08-20 12:47:42 -04:00
|
|
|
return geminiResolver.resolve()?.directory ?? null;
|
2026-05-16 20:10:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if Gemini CLI is available on the system.
|
|
|
|
|
*/
|
|
|
|
|
export function isGeminiAvailable(): boolean {
|
|
|
|
|
return resolveGeminiDir() !== null;
|
|
|
|
|
}
|
2026-08-20 12:47:42 -04:00
|
|
|
|
|
|
|
|
export function getGeminiNotFoundMessage(): string {
|
|
|
|
|
return formatCliNotFoundMessage(GEMINI_NOT_FOUND, geminiResolver.diagnostics());
|
|
|
|
|
}
|