Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.
TypeScript agent-teamagentic-aiai-agentsai-assistantclaude-codecodexcursorelectrongrokgrok-bot-alternativelinuxlocal-firstmacosmcpmulti-agentopenclaw-alternativeopencodewindows
Detect Gemini CLI models dynamically from the installed package (#90)
Gabriel Simionato Ambrósio72ae2a8d63e1
diff --git a/src/core/engines/detect.ts b/src/core/engines/detect.tsindex a7eb5fd..e923f82 100644--- a/src/core/engines/detect.ts+++ b/src/core/engines/detect.ts@@ -234,7 +234,7 @@ export async function detectGemini(): Promise<{ status: EngineStatus; models: stconst v = await run(path, ['--version'])const home = join(process.env['GEMINI_CLI_HOME'] || homedir(), '.gemini')const signedIn = existsSync(join(home, 'oauth_creds.json')) || !!(process.env['GEMINI_API_KEY'] || process.env['GOOGLE_API_KEY'] || process.env['GOOGLE_GENAI_USE_VERTEXAI'])- const models = geminiModels()+ const models = geminiModels(path)return {status: {installed: true,diff --git a/src/core/engines/gemini.ts b/src/core/engines/gemini.tsindex 583eaed..5ab1f85 100644--- a/src/core/engines/gemini.ts+++ b/src/core/engines/gemini.ts@@ -1,7 +1,7 @@-import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'+import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'import { randomBytes } from 'node:crypto'import { homedir } from 'node:os'-import { join } from 'node:path'+import { dirname, join } from 'node:path'import { GATEWAY_NAME } from './claude'import { lastLines, num, parseJson, runCli, type Parser } from './cli'import type { Engine, EngineEvent, Turn } from './types'@@ -183,8 +183,55 @@ export function geminiEngine(bin: () => string | undefined, appDir: string, shel}}-// The model ids Gemini can run. Without a reliable list from the CLI, the known-// current models are offered and the person can also type another by name.-export function geminiModels(): string[] {- return ['gemini/gemini-2.5-pro', 'gemini/gemini-2.5-flash', 'gemini/gemini-2.5-flash-lite']+// Dynamically extracts model definitions from the installed @google/gemini-cli+// bundle when available, matching what the CLI exposes in `/model`.+export function detectGeminiCliModels(binPath?: string): string[] {+ if (!binPath) return []+ try {+ const real = realpathSync(binPath)+ const marker = join('@google', 'gemini-cli')+ const idx = real.indexOf(marker)+ const pkgDir =+ idx !== -1+ ? real.slice(0, idx + marker.length)+ : existsSync(join(dirname(real), 'node_modules', '@google', 'gemini-cli'))+ ? join(dirname(real), 'node_modules', '@google', 'gemini-cli')+ : undefined+ if (!pkgDir) return []+ const bundleDir = join(pkgDir, 'bundle')+ if (!existsSync(bundleDir)) return []+ for (const file of readdirSync(bundleDir)) {+ if (!file.endsWith('.js') || !file.startsWith('chunk-')) continue+ const content = readFileSync(join(bundleDir, file), 'utf8')+ if (!content.includes('isVisible')) continue+ const regex = /"([a-z0-9.-]+)"\s*:\s*\{[^}]*isVisible\s*:\s*true/g+ let match: RegExpExecArray | null+ const found: string[] = []+ while ((match = regex.exec(content)) !== null) {+ if (match[1]) found.push(match[1])+ }+ if (found.length > 0) return [...new Set(found)].map((m) => `gemini/${m}`)+ }+ } catch {+ // not resolvable or readable: use default models+ }+ return []+}++// The model ids Gemini can run. Dynamically discovered from the installed+// @google/gemini-cli package when present, falling back to known models.+export function geminiModels(binPath?: string): string[] {+ const dynamic = detectGeminiCliModels(binPath)+ if (dynamic.length > 0) return dynamic+ return [+ 'gemini/gemini-3.1-pro-preview',+ 'gemini/gemini-3-flash-preview',+ 'gemini/gemini-3.8-flash',+ 'gemini/gemini-3.5-flash-lite',+ 'gemini/gemini-2.5-pro',+ 'gemini/gemini-2.5-flash',+ 'gemini/gemini-2.5-flash-lite',+ 'gemini/gemma-4-31b-it',+ 'gemini/gemma-4-26b-a4b-it'+ ]}diff --git a/test/engines.test.ts b/test/engines.test.tsindex 1bccbf1..c02ecbf 100644--- a/test/engines.test.ts+++ b/test/engines.test.ts@@ -5,7 +5,7 @@ import { describe, expect, it } from 'vitest'import type { Parser } from '../src/core/engines/cli'import { claudeArgs, claudeInput, claudeParser, userProvider } from '../src/core/engines/claude'import { CODEX_DISABLED_FEATURES, codexArgs, codexEnv, codexParser, userCodexProvider } from '../src/core/engines/codex'-import { geminiArgs, geminiEnv, geminiHome, geminiParser } from '../src/core/engines/gemini'+import { detectGeminiCliModels, geminiArgs, geminiEnv, geminiHome, geminiModels, geminiParser } from '../src/core/engines/gemini'import { cursorArgs, cursorCleanup, cursorConfig, cursorEngine, cursorHomeEnv, cursorParser, cursorSignedIn, cursorSlug, cursorWorkerSocket, cursorTurnDirs, imageRefused, parseCursorModels } from '../src/core/engines/cursor'import { customModel, modelInfo, usable } from '../src/shared/types'import type { EngineEvent } from '../src/core/engines/types'@@ -314,6 +314,26 @@ describe('Gemini config', () => {const b = geminiHome(appDir, { system: 'b', mcpUrl: undefined, web: false }, userHome)expect(a).not.toBe(b)})++ it('lists default models when no bin path is provided', () => {+ const list = geminiModels()+ expect(list).toContain('gemini/gemini-3.8-flash')+ expect(list).toContain('gemini/gemini-3.1-pro-preview')+ })++ it('dynamically extracts models from an installed @google/gemini-cli package', () => {+ const root = mkdtempSync(join(tmpdir(), 'gemini-pkg-'))+ const bundle = join(root, 'node_modules', '@google', 'gemini-cli', 'bundle')+ mkdirSync(bundle, { recursive: true })+ writeFileSync(+ join(bundle, 'chunk-models.js'),+ 'var defs = { "gemini-3.9-flash": { isVisible: true }, "gemini-4-pro": { isVisible: true }, "internal-hidden": { isVisible: false } };'+ )+ const bin = join(root, 'gemini.cmd')+ writeFileSync(bin, '@ECHO off')+ expect(detectGeminiCliModels(bin)).toEqual(['gemini/gemini-3.9-flash', 'gemini/gemini-4-pro'])+ expect(geminiModels(bin)).toEqual(['gemini/gemini-3.9-flash', 'gemini/gemini-4-pro'])+ })})describe('Cursor stream', () => {