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
Let me understand the issue:
- This is about a repository that has multiple AI agent implementations (codex, claude-code, gemini-cli)
- The
codexagent has OAuth credential injection via~/.codex/auth.json, controlled byCODEX_AUTH_JSON_PATH/CODEX_FORCE_AUTH_JSON - The
claude-codeagent acceptsCLAUDE_CODE_OAUTH_TOKEN - The
gemini-cliagent only wiresGEMINI_API_KEY/ Vertex env, but doesn't support OAuth credentials - The proposal is to add
GEMINI_OAUTH_CREDS_PATH/GEMINI_FORCE_OAUTHto gemini-cli, mirroring the codex pattern
Let me explore the repository structure first.
Assistant
Let me explore the agents file and any related auth files.
Assistant
Need to run commands one at a time.
Assistant
Let me look at the key files. First, the gemini_cli agent and codex-related files.
Assistant
Let me read the codex agent (reference implementation) and gemini_cli agent:
Assistant
Now let me read the gemini_cli.py
Assistant
Now let me look at the test files to understand the patterns
Assistant
Now let me check the existing gemini_cli test file:
Assistant
Let me look at the utility functions and base class:
Assistant
Let me look at the base class to understand
_get_env:Assistant
Now I have a clear picture. Let me look at the existing
runmethod more carefully and plan the implementation:Assistant
Let me read the full run method from line 649 onwards.
Assistant
Now I have a clear plan. Let me implement the changes:
- Add
_resolve_oauth_creds_pathmethod toGeminiCli - In
run, add OAuth credential injection - Add tests
Let me start by adding the import of
parse_bool_env_valueto gemini_cli.py and adding the `_resolve_oauth_creds_path- Add
Assistant
Let me make the changes. First, add the import for `parse_bool_env_value
Assistant
Let me add the import for
parse_bool_env_value:Assistant
Let me use the replace command to add the import line
Assistant
Let me try the heredoc approach:
Assistant
Let me use sed to add the import
Assistant
Let me verify the edit:
Assistant
Good. Now let me add the
_resolve_oauth_creds_pathmethod. Let me find the right location - before therunmethod:Assistant
Let me see lines 643 to 655
Assistant
Now let me add the
_resolve_oauth_creds_pathmethod before `runAssistant
Let me verify the new method looks good
Assistant
Now let me modify the
runmethod to add OAuth credential injection. Let me see the current run method againAssistant
Let me check how
upload_fileworks:Assistant
Let me look at the upload_file method in the base environment class:
Assistant
Now let me modify the
runmethod to add OAuth injection. I need to add the resolution and upload after the auth_vars blockAssistant
I'll add the OAuth creds resolution between the auth_vars for loop (ends at line 709) and the skills_command (line 711). Let me use sed to insert the code.
Assistant
Let me verify the changes:
Assistant
Wait, I need to fix the
upload_filecall - it needs an absolute path, not a shell variable. Let me fix this to use a temp secrets dir like codex doesAssistant
Let me check what happened
Assistant
Let me restore the file and redo this
Assistant
Let me use a Python script to make the edits cleanly.
Assistant
Let me verify the changes
Assistant
Let me verify the key sections of the file
Assistant
Let me verify the full run method
Assistant
The code looks good. Let me also verify the
_resolve_oauth_creds_pathmethodAssistant
Now let me also add cleanup of the secrets dir in the final block. Let me look at the existing finally block
Assistant
Let me add cleanup of the secrets dir in the finally
Assistant
Let me verify syntax and the changes
Assistant
Let me verify the cleanup code is correctly
Assistant
The cleanup didn't get inserted correctly. Let me check:
Assistant
Let me look at what's after line 785:
Assistant
Let me check the file length:
Assistant
The file is only 782 lines. Let me see the last 30 lines:
Assistant
The file was truncated! Let me restore it and redo more carefully.
Assistant
Let me look at the full structure of the file
Assistant
Now I have the full picture. Let me make all changes with a single careful Python script.
Assistant
Let me look at the area around line 780
Assistant
I need to restore and redo. Let me use git to restore
Assistant
Let me write a more careful script
Assistant
Let me try a different approach - make all replacements in one pass using a Python script that processes the full content
Assistant
The file was already modified by the first script run. Let me reset it fully.
Assistant
Good. Now let me write a script that does all modifications at once correctly:
Assistant
Let me reset properly
Assistant
No diff, so the file is clean. But the script failed at change 4. The issue is that the old4 text might have been changed by change 2 (which inserted a method before run). Let me look at what the file looks like after changes 1-3. Actually the script failed because changes 1-3 were applied but they changed the file, and old4 no longer matched.
Let me look at what the file looks like now (after partial application) to debug.
Assistant
The file was already partially modified from the first attempt! The
_convert_gemini_to_atifis at line 188. But theexcept Exception:is at line 714 which is consistent with the original file. Let me check what's around line 714.Wait, actually the file should still be clean - git diff showed nothing. Let me check line count.
Actually the git diff showed no diff, so the file is clean. The issue is that
old4is matching on the original content before changes 1-3. Let me look at what the content looks like after changes 1-3 to find the right text for change 4.Let me just check: after changes 1-3, is the old4 string still present? Let me verify by running just changes 1-3.
Assistant
Good, back to 715 lines. Let me check the exact text around the finally block
Assistant
The file ends at line 715 with
pass. Let me check the end of file more carefullyAssistant
The
_convert_gemini_to_atifis BEFORErun, not after it. The file ends with therunmethod. Let me update the script.Assistant
Let me verify syntax and key areas:
Assistant
Let me verify the key sections:
Assistant
Let me verify the cleanup section and the end of file:
Assistant
Let me verify the
_resolve_oauth_creds_pathmethod and OAuth injection sectionAssistant
The implementation looks good. Let me run the existing gemini_cli tests first
Assistant
Let me install the package and run
Assistant
Now let me run the existing gemini_cli tests
Assistant
There seems to be a pytest config issue. Let me check
Assistant
Let me try running with an updated approach
Assistant
All 9 existing tests pass. Now let me also run the codex auth tests to confirm they pass
Assistant
All codex auth tests pass. Now let me write the gemini auth tests, mirroring
test_codex_auth.py.Assistant
Now let me run the new tests:
Assistant
All 19 tests pass! Let me also make sure the old tests still pass
Assistant
All 46 tests pass. Let me also run a broader test to make sure the gemini_cli MCP tests and other related tests still work:
Assistant
All tests pass. Let me also run the full test suite to ensure nothing is broken:
Assistant
Let me run without the timeout flag:
Assistant
Those are unrelated errors (missing external dependencies). Let me run only the agent installed tests to confirm my changes didn't break anything:
Assistant
Let me run the gemini and codex related tests only:
Assistant
All 95 tests pass! Let me verify the final diff
Assistant
Let me check the git diff more carefully and make sure the test file is tracked
Assistant
The test file is new. Let me check if it's untracked
Assistant
Let me see the full diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.