ISSUE DESCRIPTION gemini-cli: support Login with Google (oauth-personal), mirroring…
- User
ISSUE DESCRIPTION
gemini-cli: support Login with Google (oauth-personal), mirroring codex auth.json The
codexagent 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), andclaude-codeacceptsCLAUDE_CODE_OAUTH_TOKEN(#173).gemini-clihas no equivalent — it only wiresGEMINI_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-cliagent, 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 fromtest_codex_auth.py, verified end-to-end (gemini-cli --ae GEMINI_FORCE_OAUTH=truecompleted hello-world, reward 1.0). Happy to open the PR or hand it off — whichever you prefer.ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /harbor, current file: none) bash-$
- Assistant
I’ll first map the agent/auth structure and locate the existing Codex implementation and tests, then mirror its behavior for Gemini with the requested opt-in environment variables. After editing, I’ll run the focused tests and relevant broader suite, inspect the diff, and explicitly verify each checklist item.
- Assistant
The repository has a direct precedent in
codex.py, while Gemini’s current setup only forwards key/Vertex variables. I’ll now compare lifecycle methods and the exact Codex auth tests so the Gemini change follows established sandbox upload, ownership, precedence, and error semantics rather than inventing a parallel pattern. - Assistant
Gemini already creates
~/.geminiduring install/settings, so the requested flow can be smaller than Codex’s custom-home setup: resolve an explicit file first, otherwise honor a strictly parsed force flag, upload to the agent’s~/.gemini/oauth_creds.json, and chown after root-owned upload. I’m checking helper imports, mock environment APIs, and the complete Codex test expectations before implementing; notably, agent config environment overrides should use_get_env, not directos.environ, for the new controls. - Assistant
The Codex tests confirm the desired edge cases: default remains disabled even if a cached credential exists, explicit path outranks force, all accepted/falsy boolean spellings work, malformed values fail clearly, and chown is conditional on
default_user. Before choosing the upload destination, I’ll inspect how this codebase addresses agent home paths and any other credential-file injection, sinceupload_filecannot expand~and the destination must match Gemini CLI’s actual home. - Assistant
A temporary remote staging path followed by an agent-user move is the robust choice: it avoids assuming every sandbox user lives under
/home/<name>, ensures~resolves under the same user that launches Gemini, and leaves no duplicate credential in/tmp. In OAuth mode I’ll also omit API-key/Vertex auth variables so “force OAuth” cannot be silently preempted by an ambient key; with neither opt-in set, the existing auth-variable behavior remains unchanged. - Assistant
The implementation is in place; lint correctly identified that switching auth forwarding to
_get_envmade Gemini’s directosimport obsolete. I’ll remove that import, inspect the resulting section, and run the existing Gemini and Codex focused tests. Then I’ll exercise the new resolver/run behavior with an inline temporary harness (without adding or modifying repository tests, per instruction). - Assistant
All 54 relevant existing tests pass. Formatting wants only line wrapping, which I’ll apply. The new flow’s important semantics still need direct verification: environment and
extra_envresolution, explicit-over-force precedence, strict truthy/falsy handling, missing-file errors, upload/chown/move ordering, no chown for a userless environment, suppression of ambient API keys in OAuth mode, and unchanged key forwarding by default. I’ll cover these via an inline async harness and then run the broader installed-agent test directory. - Assistant
The broad installed-agent suite passes (582 tests). The inline harness failed only because I mistakenly modeled “unset” as an empty string; consistent with Codex’s strict parser, an explicitly empty force flag is invalid rather than absent. That is expected and desirable. The harness also prompted one backward-compatibility refinement: existing Gemini code forwards auth variables whenever present, including an explicit empty value, so I’ll preserve that exact behavior instead of using truthiness, then rerun the corrected harness and static checks.
- Assistant
The second harness reached the run-path assertions but one assertion was too broad: Gemini’s
finallytrajectory-copy call may inherit agent-level environment handling independently of the OAuth setup. I’ll print the mocked calls to identify the exact mismatch, then tighten verification to the actual Gemini launch call and setup ordering rather than asserting across unrelated cleanup calls. - Assistant
The call trace shows the implementation is correct;
exec_as_*prependsset -o pipefailand mergesextra_envcontrols into each call, so the failed equality check was harness-specific. One subtle point is thatextra_envitself is globally merged by the base class: if a caller explicitly supplies both an API key and the OAuth opt-in through--ae, both will reach Gemini regardless of this local env dictionary. That is existing framework behavior and should not be altered here; the normal reported use case (--ae GEMINI_FORCE_OAUTH=truewith an ambient host key) correctly suppresses the ambient key. I’ll run corrected targeted assertions and inspect base merging to ensure there is no safe established exclusion mechanism. - Assistant
The corrected harness now passes, as do the 36 directly affected tests and all formatting/lint checks. Before finalizing, I’m checking one end-to-end compatibility concern against Gemini CLI’s auth selection behavior: whether the presence of
oauth_creds.jsonalone selectsoauth-personal, or whether generatedsettings.jsonmust also declare the auth type. This matters because Harbor regenerates Gemini settings during each run and must not accidentally leave noninteractive OAuth unable to select a provider. - Assistant
No local Gemini package is installed, and Harbor only rewrites settings for MCP/reasoning configurations. To avoid guessing, I’ll inspect the published Gemini CLI source package’s noninteractive auth resolver. If it auto-detects a cached OAuth credential, no settings change is needed; if it requires
security.auth.selectedType, I’ll integrate that into Harbor’s generated settings without disturbing MCP/reasoning configuration. - Assistant
The environment lacks a system
npm(Gemini installs Node only inside trial sandboxes), and the failed temporary-shell command left the terminal’s working directory pointing at the removed temp directory. I’ll return to the repository and query/extract the npm registry tarball using Python instead. - Assistant
Published Gemini CLI 0.50.0 confirms that headless auth is selected from
security.auth.selectedType; absent that setting, it falls back to API-key auth even whenoauth_creds.jsonexists. Therefore credential injection alone is insufficient on current Gemini versions. I’ll make the settings builder addoauth-personalonly in opt-in OAuth mode, while preserving byte-for-byte behavior for default API-key/Vertex runs and composing correctly with MCP/reasoning settings. - Assistant
OAuth settings selection now composes with generated settings, and the focused tests plus a JSON-level settings harness pass. I’ll perform the final verification pass: all installed-agent tests after this last change, repository type/lint checks applicable to the file, and a complete diff/status review for accidental files or regressions.
- Assistant
Final review is clean: exactly one source file changed; 582 installed-agent tests pass; Ruff formatting/lint,
ty, andgit diff --checkall pass.Checklist:
- If an error was reported, reproduced it. The pre-change Gemini run path had no OAuth resolver/upload and only populated API-key/Vertex variables. Inspection of current Gemini CLI 0.50.0 also confirmed that a cached credential without
security.auth.selectedType=oauth-personalfalls back to key auth. A live personal OAuth token was neither available nor needed to reproduce the missing wiring. - Confirmed the fix resolves it. Inline async harnesses verified explicit and forced credential resolution, upload → root chown → agent-home move ordering, OAuth auth selection in generated settings, ambient API-key suppression in OAuth mode, and unchanged key forwarding by default.
- Considered edge cases. Explicit path takes priority; environment and
extra_envcontrols work; truthy/falsy spellings use the shared strict parser; invalid booleans and missing files raise clear errors; absent opt-in remains disabled even if the cache exists;default_user=Noneskips chown; arbitrary agent home directories work because~resolves under the executing user; OAuth settings compose with MCP/reasoning settings. - Ran affected existing tests. All 582 tests under
tests/unit/agents/installedpass after the final change, including Gemini, Codex auth, MCP, and environment passthrough coverage. Ruff, formatter, type checker, and whitespace checks also pass.
I’m satisfied the implementation is backward-compatible by default and complete for headless Login with Google, so I’ll submit it now.
- If an error was reported, reproduced it. The pre-change Gemini run path had no OAuth resolver/upload and only populated API-key/Vertex variables. Inspection of current Gemini CLI 0.50.0 also confirmed that a cached credential without
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →