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 start by exploring the repository structure to understand the codebase and locate relevant files for gemini-cli and codex auth patterns. Let's first get an overview.
- Assistant
Let me explore the repository structure more broadly to find gemini-cli and codex related files.
- Assistant
Let me look at the relevant files - gemini_cli.py, codex.py, and the test files.
- Assistant
Let me look at the files one at a time.
- Assistant
Let me see the full gemini_cli.py file, focusing on the
runmethod and auth handling: - Assistant
Now let me find the test files for codex auth:
- Assistant
Let me look at the test_codex_auth.py file:
- Assistant
Now let me look at the existing test file for gemini_cli:
- Assistant
Let me look at the existing gemini_cli tests to understand the structure:
- Assistant
Now let me look at the base class to understand
_get_envand other utilities: - Assistant
Let me see the rest of the base.py to understand the
_get_envmethod: - Assistant
Let me see the implementation:
- Assistant
Now let me look at the
claude_code.pyto see how they handled OAuth: - Assistant
Now let me look at the
parse_bool_env_valueutility: - Assistant
Let me look at the conftest.py for test fixtures:
- Assistant
Now let me look at the test conftest.py for fixtures:
- Assistant
Now let me check the conftest at the agents/installed level:
- Assistant
Let me look at the unit tests directory for conftest:
- Assistant
Now I have a clear understanding of the codebase. Let me implement the OAuth credential injection for gemini-cli. I'll:
- Add
_resolve_oauth_creds_path()method to GeminiCli - Modify the
run()method to upload and wire OAuth credentials - Add tests mirroring
test_codex_auth.py
Let me start by understanding the current run method's env handling:
- Add
- Assistant
Let me see the full run method:
- Assistant
Now I have a clear picture. Let me implement the changes. First, let me add the
_resolve_oauth_creds_path()method and update therun()method: - Assistant
Now let me add the import and implement the changes. First, I need to add the
parse_bool_env_valueimport: - Assistant
I see there's a duplicate import. Let me fix that:
- Assistant
Good. Now let me add the class-level constants and the
_resolve_oauth_creds_pathmethod. I'll add them after the_image_counterattribute: - Assistant
I'll add the constants and method after the
_image_counterline. Let me do this step by step. First add the constants: - Assistant
Now I need to add the
_resolve_oauth_creds_pathmethod. I'll add it after the_validate_reasoning_effortmethod and before theinstallmethod: - Assistant
I see there's a duplicate line. Let me fix that:
- Assistant
Let me fix the duplicate line:
- Assistant
Good. Now I need to update the
run()method to handle OAuth credentials. Let me find the run method: - Assistant
Let me look at the run method:
- Assistant
Now I need to update the run method to handle OAuth credentials. Let me carefully replace the relevant section:
- Assistant
Now I need to create the test file for gemini OAuth. Let me create a test file mirroring
test_codex_auth.py: - Assistant
Now let me run the tests to verify everything works:
- Assistant
Let me check how the test environment is set up:
- Assistant
Now let me run the tests again:
- Assistant
The
asyncio_modeconfig option is causing issues. Let me check the pyproject.toml: - Assistant
Let me check if pytest-asyncio is installed:
- Assistant
The pytest-asyncio plugin is not installed. Let me install it.
- Assistant
Now let me run the tests again:
- Assistant
Excellent! All 18 tests pass! Now let me run the existing gemini tests to make sure I didn't break anything:
- Assistant
Perfect! All existing tests pass. Now let me also run the codex auth tests to make sure I didn't break anything there:
- Assistant
All codex auth tests pass too. Now let me run a broader test suite to make sure I haven't broken anything else:
- Assistant
The error is about missing
hypothesismodule for a different test file. Let me run just the tests that are relevant to our changes: - Assistant
All 45 tests pass. Let me also check if there are any other tests that might be affected. Let me run all unit tests in the agents/installed directory, skipping the hypothesis-dependent test:
- Assistant
All 548 tests pass! Now let me review the changes I made to make sure they are correct. Let me look at the final state of the gemini_cli.py file:
- Assistant
The diff looks clean. Let me also check the test file I created:
- Assistant
Let me check if the test file is there:
- Assistant
The test file exists. Now let me check the git status to see what files are untracked:
- Assistant
Perfect! Now let me verify the final state of the implementation by looking at the key parts:
- Assistant
Now let me verify the run method changes:
- Assistant
Perfect! The implementation looks correct. Now let me submit the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.