Skip to content

feat: implement Gemini CLI as sandbox external agent (#2424) - #2535

Merged
yannickmonney merged 6 commits into
mainfrom
feat/gemini-cli-external-agent-2424
Jul 7, 2026
Merged

yannickmonney merged 6 commits into
mainfrom
feat/gemini-cli-external-agent-2424

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

Summary

  • Add agentKind: gemini as a first-class external sandbox runtime alongside Claude Code, Cursor, and Hermes Agent.
  • Ship a Gemini CLI adapter (buildExec + stream-json parser), the tale-gemini-run wrapper, sandbox image tooling (pinned @google/[email protected]), a built-in chat composer entry, and docs/i18n (en/de/fr).
  • Managed runs route through the platform LLM gateway's Google GenAI-compatible route: GOOGLE_GEMINI_BASE_URL=<gateway>/genai + the session virtual key as GEMINI_API_KEY, with the auth type pinned to gemini-api-key via a per-exec system settings file (with the base-URL env set alone, the CLI's env inference selects its gateway auth type, which headless auth validation rejects at 0.49.0 — verified against the real CLI). Models are the catalog gateway ids (openrouter/google/gemini-3.1-pro-preview; Bifrost's /genai {model:*} matcher takes slashed ids — verified live against the pinned CLI and Bifrost v1.5.13 sources).
  • BYO injects no gateway env; the CLI authenticates with the user's GEMINI_API_KEY (or GOOGLE_API_KEY + GOOGLE_GENAI_USE_VERTEXAI for Vertex). Shipped catalog-shaped refs translate to Google-native ids via new nativeModelId entries on the catalog's Gemini models (byoModelIdSource: 'vendor-native').
  • Governance: managed runs exclude the CLI's native google_web_search/web_fetch via tools.exclude unless nativeWebTools: true (the interactive ask_user tool is force-excluded by the CLI itself in headless mode); Playwright MCP + the integrations dispatch bridge ride the settings mcpServers map, with the session key referenced as ${TALE_GATEWAY_TOKEN} env interpolation so it never appears in the staged settings file.
  • Prompt, system-prompt append, and settings travel as one JSON object on stdin — never argv. The append is staged as a per-exec ~/.gemini/tale-context-<uuid>.md added to context.fileName alongside GEMINI.md (append semantics; GEMINI_SYSTEM_MD would replace the core prompt) and cleaned up after the run; delivery to the model request was verified end-to-end against a mock GenAI gateway.
  • Session resume uses the CLI's --resume <uuid> (verified working headless at 0.49.0); the parser carries the init event's session_id onto the result. Usage comes from the result event's stats (real token counts); zero-token runs emit no usage event. Reached max session turns maps to the max-turns result status. fallbackModel is deliberately ignored (no availability-fallback chain) and the docs make no fallback claim.
  • Fixture fixtures/gemini/shell-turn.jsonl is a sanitized capture of a REAL 0.49.0 headless turn (including a real run_shell_command round trip) recorded against a local mock GenAI gateway; record-fixture.md documents the recipe.

All shared-file edits are strictly additive (union widenings + new blocks) so the concurrent Codex (#2422) merge stays mechanical.

Closes #2424

Test plan

  • vitest --project server lib/agent-adapters (98 tests, includes the real-capture Gemini fixture + chunked parses)
  • Full platform suite vitest --project server --project pii (703 files, 74 858 tests)
  • tsc --noEmit, oxlint --type-aware, oxfmt --check, ruff format/check (wrapper), knip, migrations:check (schema/config snapshots: data-safe, no migration needed)
  • docs vitest suite (content manifest regenerated minimally)
  • Live verification against the pinned CLI on a mock GenAI gateway: headless stdin prompt, stream-json event shapes, --resume <uuid>, tools.exclude removing web tools from the request, system-prompt append reaching the request body, wrapper end-to-end (exit codes, staging + cleanup)
  • CI container image build (not runnable locally — the smoke-test flag check was pre-verified against the pinned CLI locally)

Adapter (buildExec + stream-json parser) for @google/gemini-cli 0.49.0
driven through the tale-gemini-run wrapper. Managed runs route via the
gateway's Google GenAI-compatible /genai route (GOOGLE_GEMINI_BASE_URL
+ session VK as GEMINI_API_KEY); BYO uses GEMINI_API_KEY / Vertex vars
with vendor-native model ids (catalog gemini entries gain nativeModelId).
Managed runs deny the CLI's native google_web_search/web_fetch unless
nativeWebTools; prompt + system-prompt append + settings ride stdin,
never argv. Parser verified against a sanitized real 0.49.0 capture;
zero-token runs emit no usage event.
Extend the agentKind unions (turn actions, lifecycle, serializable
config, readiness, chat/editor UI) with 'gemini', label it in en/de/fr,
and ship the built-in Gemini CLI composer agent (managed, Gemini 3
Pro/Flash via the OpenRouter catalog).
Install @google/[email protected] into /opt/agents and add the
tale-gemini-run wrapper, which stages per-exec system settings
(GEMINI_CLI_SYSTEM_SETTINGS_PATH) and the per-exec ~/.gemini context
file carrying the system-prompt append, then pipes the prompt into the
headless CLI. The image smoke test asserts the binaries and that every
gemini flag the wrapper passes exists in the pinned CLI's --help.
@yannickmonney
yannickmonney enabled auto-merge (squash) July 7, 2026 06:04
@yannickmonney
yannickmonney merged commit d0bb0fe into main Jul 7, 2026
16 of 18 checks passed
@yannickmonney
yannickmonney deleted the feat/gemini-cli-external-agent-2424 branch July 7, 2026 06:49
yannickmonney added a commit that referenced this pull request Jul 7, 2026
…leet

The budget was set at 4400 MB when the image was ~4.0 GB; the six external
agent CLIs added since (Cursor #2481, Hermes #2500, Gemini #2535, Codex
#2536, Pi #2550, OpenClaw #2555) grew it to ~4.9 GB and none of those PRs
updated the budget, so the Validate images gate is red on main too. Document
the fleet as a named cost and restore the ~10% headroom convention at 5400.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Implement Gemini CLI as a sandbox external agent (Claude Code parity)

1 participant