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 the relevant files for implementing the proposed feature. Let's first check what kind of repository this is.
- Assistant
Let me explore the repository structure more broadly.
- Assistant
Let me explore the repository structure to understand the codebase, particularly focusing on the
gemini-cliadapter and the existingcodexauth pattern. - Assistant
Let me find the gemini-cli adapter.
- Assistant
Let me look for gemini-cli more broadly.
- Assistant
Let me look for gemini-cli or codex adapter files.
- Assistant
Let me look at the gemini-cli agent implementation and also find the codex auth pattern.
- Assistant
Let me look at the gemini-cli agent implementation and the codex auth implementation for reference.
- Assistant
Let me look at the full gemini_cli.py file and then the codex.py file to understand the pattern.
- Assistant
Let me continue reading the file to understand the full implementation.
- Assistant
Let me continue reading the file to understand the full implementation.
- Assistant
Let me continue reading the file to understand the full implementation.
- Assistant
Let me continue reading to find the
runmethod and understand how the environment is set up, especially the API key handling. - Assistant
Let me continue reading to find the run method and environment setup.
- Assistant
Let me see the rest of the file.
- Assistant
Now let me look at the codex agent to understand the OAuth pattern.
- Assistant
Let me search for the OAuth credential handling in the codex agent.
- Assistant
Let me look at the codex auth implementation to understand the pattern.
- Assistant
Let me see the rest of the run method to understand the full pattern.
- Assistant
Now let me look at the test file for codex auth to understand the test pattern.
- Assistant
Let me continue reading the test file to understand the full test pattern.
- Assistant
Let me see the rest of the test file.
- Assistant
Now let me look at how the
claude-codeagent handles OAuth tokens: - Assistant
Let me look at the claude_code.py to see how CLAUDE_CODE_OAUTH_TOKEN is handled.
- Assistant
Let me look at how it's handled in the run method:
- Assistant
Now let me look at the
parse_bool_env_valueutility and the_get_envmethod to understand the pattern better: - Assistant
Now let me check the base agent class to understand the
_get_envmethod and howextra_envworks: - Assistant
Let me look at the
_get_envmethod and the base agent class to understand the pattern better. - Assistant
Now let me look at the existing test for gemini_cli to understand the test patterns:
- Assistant
Let me check the test fixtures (conftest) to understand how
temp_diris set up: - Assistant
Let me look at the conftest to understand the temp_dir fixture.
- Assistant
Let me also look at the
parse_bool_env_valueutility since the codex auth uses it: - Assistant
Now I have a good understanding of the codebase. Let me also check the
_get_envmethod and understand how GeminiCli gets its environment variables. Let me also check theEnvironmentPaths: - Assistant
Let me look at the EnvironmentPaths model:
- Assistant
Now I have a good understanding of the codebase. Let me plan the implementation:
- Add a
_resolve_oauth_creds_pathmethod to GeminiCli that mirrors_resolve_auth_json_pathin Codex - Modify the
runmethod to use OAuth credentials when available, similar to how Codex handles auth.json - Add tests for the new functionality
Let me start by implementing the changes. First, I'll look at the full GeminiCli run method to understand the current flow better.
- Add a
- Assistant
Now I have a comprehensive understanding. Let me check if there are any references to how
gemini-cliuses OAuth credentials internally: - Assistant
Let me check the AGENTS.md for any relevant info about gemini-cli auth:
- Assistant
Now let me run the existing gemini-cli tests to make sure they pass before making changes:
- Assistant
Need to install the package first.
- Assistant
Now let me run the tests:
- Assistant
The tests aren't running. Let me check the pytest config:
- Assistant
Let me check the pyproject.toml for the async mode setting:
- Assistant
The pyproject.toml has
asyncio_mode = "auto"but the installed version of pytest-asyncio might not support it. Let me install a newer version: - Assistant
Let me check the version of pytest-asyncio that's installed:
- Assistant
Let me check what version is used in the venv:
- Assistant
Let me check if there's a venv with a different python version:
- Assistant
Let me check what's inside the venv bin:
- Assistant
The venv is using the same Python, let me just try running the tests using the venv's pytest.
- Assistant
All existing tests pass. Now let me run the codex auth tests to see how they work:
- Assistant
Now I have a thorough understanding of the codebase. Let me plan the implementation:
- Add
_resolve_oauth_creds_pathmethod toGeminiCliclass (mirroring_resolve_auth_json_pathinCodex) - Modify the
runmethod to handle OAuth credentials - upload to container, chown, symlink to~/.gemini/oauth_creds.json - Add tests ported from
test_codex_auth.py
Let me also check how the environment works with the upload_file method:
- Add
- Assistant
Now I have a thorough understanding of the codebase. Let me implement the changes. First, let me check the full imports and what's already imported in gemini_cli.py:
- Assistant
Now let me implement the changes. I'll need to:
- Add imports for
PurePosixPathandparse_bool_env_value - Add class constants for remote paths
- Add
_resolve_oauth_creds_path()method - Modify
run()method to handle OAuth credentials
Let me start by adding the necessary imports:
- Add imports for
- Assistant
Now let me implement the changes. First, I'll add the necessary imports and constants:
- Assistant
Good. Now let me add the import for
parse_bool_env_value: - Assistant
Now let me add the class constants for the remote paths and the
_resolve_oauth_creds_pathmethod. I'll add them after the class definition: - Assistant
Good. Now I need to add the
_resolve_oauth_creds_pathmethod. Let me add it after the_validate_reasoning_effortmethod and before theinstallmethod: - Assistant
Good. Now I need to modify the
runmethod to handle OAuth credentials. Let me find the currentrunmethod: - Assistant
Let me look at the run method:
- Assistant
Now I need to modify the
runmethod to handle OAuth credentials. Let me replace the entire run method: - Assistant
Let me verify the full run method:
- Assistant
Good. The implementation looks correct. Now let me create the test file. I'll port the tests from
test_codex_auth.pyto createtest_gemini_cli_oauth.py: - Assistant
It seems the file was not created properly. Let me check and create it again:
- Assistant
Good. Now let me run the new tests to see if they pass:
- Assistant
All 18 tests pass. Now let me also run the existing gemini-cli tests to make sure I didn't break anything:
- Assistant
All existing tests pass. Let me also run the codex auth tests to make sure they still pass (just to be safe):
- Assistant
All tests pass. Let me also run the MCP test for gemini-cli to make sure I didn't break anything:
- Assistant
All tests pass. Let me also run the full unit test suite to make sure I didn't break anything:
- Assistant
Let me try without the timeout option:
- Assistant
All 2521 tests pass, including my new 18 tests. Let me verify the changes I made by looking at the diff:
- Assistant
Let me also check the git status to see what files I've changed and created:
- Assistant
Let me review the full implementation one more time to make sure everything looks good:
- Assistant
Everything looks great! Let me now also verify the test file:
- Assistant
Let me verify the test file looks good:
- Assistant
Everything looks great. Let me run the full test suite one more time to make sure everything passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.