gemini-cli: support Login with Google (oauth-personal), mirroring codex auth.json
The codex agent injects a cached OAuth credential (~/.codex/auth.json) so runs can use a login instead of an API key (CODEX_AUTH_JSON_PATH / CODEX_FORCE_AUTH_JSON), and claude-code accepts CLAUDE_CODE_OAUTH_TOKEN (#173). gemini-cli has no equivalent — it only wires GEMINI_API_KEY / Vertex env, so users with a "Login with Google" session (~/.gemini/oauth_creds.json) must keep a separate API key for runs.
Proposal: add the same opt-in OAuth-credential injection to the gemini-cli agent, mirroring the codex pattern — GEMINI_OAUTH_CREDS_PATH / GEMINI_FORCE_OAUTH, default behavior unchanged (fully backward-compatible).
I have a working implementation that mirrors the codex auth flow (_resolve_oauth_creds_path → upload → chown → ~/.gemini) with tests ported 1:1 from test_codex_auth.py, verified end-to-end (gemini-cli --ae GEMINI_FORCE_OAUTH=true completed hello-world, reward 1.0). Happy to open the PR or hand it off — whichever you prefer.
Interface
No new interfaces are introduced.
Assistant
Now update run() to resolve, upload, chown, and place the credentials:
Assistant
Done. The gemini-cli agent now supports opt-in "Login with Google" OAuth credential injection, mirroring the codex auth.json pattern:
src/harbor/agents/installed/gemini_cli.py
_resolve_oauth_creds_path() — same priority logic as codex's _resolve_auth_json_path:
GEMINI_OAUTH_CREDS_PATH=<path> → use that specific file (raises if missing)
GEMINI_FORCE_OAUTH=<truthy> → use ~/.gemini/oauth_creds.json (raises if missing; invalid bool values raise via )
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
run() — when OAuth is resolved: uploads the creds to /tmp/gemini-secrets/oauth_creds.json, chowns to the agent user (skipped when default_user is None, so the CLI can also rewrite it on token refresh), copies it into ~/.gemini/oauth_creds.json, and cleans up the secrets dir. Conflicting GEMINI_API_KEY/GOOGLE_API_KEY/Vertex vars aren't forwarded in OAuth mode (mirroring codex, which drops OPENAI_API_KEY when injecting auth.json), but GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION still are, since Code Assist accounts may need them.
_build_settings_config(..., use_oauth=) — writes security.auth.selectedType: "oauth-personal" into ~/.gemini/settings.json so the CLI's non-interactive auth validation selects the cached login instead of falling back to env-var auth.
tests/unit/agents/installed/test_gemini_cli_auth.py — ported 1:1 from test_codex_auth.py (default-off, explicit path via env and --ae extra_env, truthy/falsy/invalid force values, missing-file errors) plus run-wiring tests: upload + chown + placement in ~/.gemini, chown skip, API-key fallback, no API-key forwarding under OAuth, settings selection, and no settings rewrite in the default path.
Verified: 22 new tests pass, full unit suite passes (2525 passed, 1 skipped), and ruff check, ruff format, and ty check are all clean. Default behavior is fully backward-compatible — with neither env var set, nothing changes.