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.
- Assistant
I’ll first map the agent/auth implementation and locate the existing Codex flow and tests, then mirror its conventions for Gemini while preserving default behavior. After implementing, I’ll run the focused test suites and inspect the final diff.
- Assistant
The relevant implementation is isolated in
codex.py, with a dedicated auth test module. I’ll compare the Codex constructor/setup path against Gemini’s corresponding lifecycle methods and inspect base-agent helpers (especially environment precedence and upload semantics) before editing. - Assistant
Gemini currently reads auth variables directly from
os.environ, while Codex uses_get_env, which intentionally supports both process env andextra_env(--ae). The proposed flags therefore need_get_envresolution, a local-path validator, upload/chown, and placement at~/.gemini/oauth_creds.jsonbefore the CLI starts. I’ll verify helper behavior and exact test fixtures, then make the smallest source-only change (without adding/modifying repository tests per the task constraints). - Assistant
The helper confirms
extra_envtakes precedence, and Codex rejects invalid booleans and missing files. For Gemini, uploading directly to a shell-expanded~path is unsafe becauseupload_filedoes not perform shell expansion and container home paths vary. I’ll use a stable temporary upload path, chown it when an agent user exists, then install it as the agent into~/.gemini/oauth_creds.json; this preserves ownership and reliably targets Gemini’s actual home. I’ll also switch existing Gemini auth-var collection to_get_envso OAuth flags and ordinary credentials consistently honor--ae. - Assistant
Because
exec_as_agentalready merges allextra_env, I won’t broaden the existing auth-variable logic or claim that OAuth flags suppress separately supplied API keys; the requested behavior is credential injection, and preserving the current env behavior minimizes compatibility risk. I’ll now add the resolver and stage/copy flow, using the same boolean parser and precedence rules as Codex. - Assistant
The source change now has: explicit-path priority, opt-in default cache lookup, strict boolean validation, no automatic cache use, upload/chown/install with mode
0600, and no upload on the legacy path. I’ll exercise those cases through an inline temporary harness (includingextra_env, missing files, invalid values, default-user/no-user runs), then run Gemini and Codex focused tests plus formatting/type lint. - Assistant
The custom harness passed all requested auth branches. The focused pytest command did not run because one guessed filename (
test_gemini_cli_reasoning.py) does not exist, so this is an invocation issue rather than a test failure. Ruff also reports only formatting changes. I’ll apply Ruff formatting, enumerate the actual Gemini test modules, and rerun the valid focused suite. - Assistant
The valid focused suite passes (27 tests), and formatting/lint are clean. I’ll now include Gemini MCP tests and the broader installed-agent unit directory to catch lifecycle regressions, then review the exact diff for accidental behavior changes and repository cleanliness.
- Assistant
The broader installed-agent suite passes all 582 tests, including Gemini MCP and environment passthrough coverage. The final diff is limited to the Gemini agent and preserves the no-flag path. One final static type check will verify the new
Path | Noneresolver and async calls; then I’ll confirm status and submit.Checklist review:
- Reported error reproduced: The pre-change inspection showed Gemini had no OAuth resolver/upload path and only forwarded API-key/Vertex env; this is the reported missing capability rather than a thrown runtime exception.
- Fix confirmed: The inline harness demonstrated explicit and forced OAuth resolution and verified upload, chown, copy, permissions, and no-user behavior.
- Edge cases considered: Default remains opt-out; explicit path wins;
extra_envworks; truthy/falsy parsing is case-insensitive; invalid booleans and missing/non-file paths raise; chown is skipped without a default user. - Affected tests run: Focused tests passed (27), and the entire installed-agent unit suite passed (582); Ruff lint/format and diff whitespace checks also passed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.