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 to understand its structure and locate the relevant files for the gemini-cli agent. Let's first get a high-level view.
- Assistant
Let me explore the repository structure more thoroughly.
- Assistant
Let me look at the project structure, especially the agents directory.
- Assistant
Let me first examine the existing codex auth implementation and the gemini-cli agent to understand what needs to be mirrored.
- Assistant
Now let me look at the gemini-cli agent to understand its current implementation.
- Assistant
Now let me look at the existing codex auth test to understand the pattern:
- Assistant
Let me also look at the test conftest.py to understand the fixtures:
- Assistant
Let me check conftest files more carefully.
- Assistant
Let me look at the conftest files.
- Assistant
Let me look at the existing gemini_cli test:
- Assistant
Let me look at the
runmethod of gemini_cli.py more carefully: - Assistant
Let me look at the full run method.
- Assistant
Let me also look at the base class to understand
_get_envand how extra_env works: - Assistant
Let me also look at
parse_bool_env_valueutility: - Assistant
Now let me look at the base class constructor and how
_get_envworks: - Assistant
Now I have a clear understanding of the structure. Let me also look at the base class
exec_as_agentmethod: - Assistant
Let me look at how codex handles its install and the
_REMOTE_*constants: - Assistant
Let me look at the codex
run()method more carefully to see how the auth resolution flows through: - Assistant
Let me look at the codex run method more carefully:
- Assistant
Let me look at the codex run method more carefully.
- Assistant
Now I have a clear picture. Let me also check if
PurePosixPathis already imported in gemini_cli.py: - Assistant
Now I have a clear picture. Let me also look at the
EnvironmentPathsimport to understand how it's used: - Assistant
Now I have a thorough understanding. Let me plan and implement the changes:
- Modify
gemini_cli.pyto add_resolve_oauth_creds_path()and modifyrun()to upload OAuth creds - Create test file
test_gemini_cli_auth.pyported fromtest_codex_auth.py
Let me start implementing:
- Modify
- Assistant
Now I'll implement the changes. First, let me update
gemini_cli.py: - Assistant
First, let me add the necessary imports and add the
_resolve_oauth_creds_pathmethod and class constants. Let me also check ifparse_bool_env_valueis already used in the codex module: - Assistant
Now I have a clear understanding of the codebase. Let me implement the changes step by step.
Plan:
- Add
PurePosixPathandparse_bool_env_valueimports togemini_cli.py - Add
_REMOTE_GEMINI_SECRETS_DIRclass constant - Add
_resolve_oauth_creds_path()method (mirroring codex's pattern) - Modify
run()method to handle OAuth creds upload - Create
test_gemini_cli_auth.pytests ported fromtest_codex_auth.py
Let me start with the imports:
- Add
- Assistant
Now add the
parse_bool_env_valueimport: - Assistant
I see there are duplicate imports. Let me fix that:
- Assistant
There's still a duplicate line. Let me fix it:
- Assistant
Good, the imports are clean now. Now let me add the
_REMOTE_GEMINI_SECRETS_DIRclass constant and the_resolve_oauth_creds_path()method. Let me first see the exact line numbers: - Assistant
Now let me add the
_REMOTE_GEMINI_SECRETS_DIRclass constant and the_resolve_oauth_creds_path()method. Let me add them after the CLI_FLAGS section: - Assistant
Now let me add the
_REMOTE_GEMINI_SECRETS_DIRclass constant and the_resolve_oauth_creds_path()method. I'll add them right after the_image_counterline: - Assistant
Good. Now I need to add the
_resolve_oauth_creds_path()method. Let me add it after the_validate_reasoning_effortmethod. Let me find the right location: - Assistant
Let me add the
_resolve_oauth_creds_path()method after_validate_reasoning_effort: - Assistant
Now I need to modify the
run()method to handle the OAuth creds. Let me find therun()method: - Assistant
Let me look at the full
run()method: - Assistant
Now let me modify the
run()method to handle OAuth creds. Let me open the file at that section: - Assistant
Now let me modify the
run()method to handle OAuth creds. I'll replace the relevant section: - Assistant
I see there's a duplicate comment. Let me fix that:
- Assistant
Good! Now I need to also add a cleanup step in the finally block to remove the secrets directory. Let me look at the end of the run method:
- Assistant
Let me add a cleanup step after the session copy to remove the secrets directory. Let me look at the codex cleanup pattern:
- Assistant
Let me add a cleanup step to the finally block to remove the secrets directory:
- Assistant
I see there's a duplicate
finally:on line 773. Let me fix that: - Assistant
I see there's an indentation issue. Let me fix the finally block properly:
- Assistant
I need to fix the try/finally block. Let me replace the entire section from line 762 to end:
- Assistant
Now let me verify the changes by running a Python syntax check on the file:
- Assistant
Great! The syntax is correct. Now let me run the existing gemini_cli tests to make sure I didn't break anything:
- Assistant
Need to install harbor in the venv.
- Assistant
Let me try running the tests again.
- Assistant
I need to install pytest-asyncio. Let me check the pyproject.toml for test dependencies.
- Assistant
Let me check the pyproject.toml for the right asyncio mode setting.
- Assistant
Let me upgrade pytest-asyncio to a version that supports the
asyncio_modeoption: - Assistant
Let me check what version was installed:
- Assistant
Let me check what version supports asyncio_mode:
- Assistant
Let me check the pyproject.toml for the correct pytest-asyncio version:
- Assistant
Let me try using the venv's pytest directly:
- Assistant
All existing tests pass. Now let me also run the codex auth tests to make sure they still pass:
- Assistant
All existing tests pass. Now I need to create the test file for the gemini-cli OAuth creds feature. Let me create
test_gemini_cli_auth.pyported fromtest_codex_auth.py: - Assistant
Now let me write the test file. Let me first look at the codex auth tests again to understand the pattern:
- Assistant
Now let me create the test file for gemini-cli OAuth creds feature. I'll port the tests from test_codex_auth.py:
- Assistant
Now let me run the new tests to make sure 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 tests pass. Now let me also verify the gemini_cli_mcp tests pass since they might import from gemini_cli:
- Assistant
All tests pass. Let me also run the env_passthrough tests to make sure they pass:
- Assistant
All tests pass. Let me now verify the final state of the code by looking at the changes I made:
- Assistant
Let me check the diff to make sure everything looks good:
- Assistant
Let me also check the new test file was created:
- Assistant
Let me also run a broader test suite to make sure I haven't broken anything:
- Assistant
All 600 tests pass. Let me now also check the final file to make sure it looks correct:
- Assistant
Let me add a blank line between the
_REMOTE_GEMINI_SECRETS_DIRand@staticmethodfor proper formatting: - Assistant
I notice I imported
EnvironmentPathsbut I'm not using it. Let me check if it's needed. Let me search for it in the file: - Assistant
I see that
EnvironmentPathsis imported but not used in my changes. Let me remove it: - Assistant
Good, the code looks clean now. Let me run the tests one more time to make sure everything still passes:
- Assistant
All 58 tests pass. Let me now verify the final diff to make sure everything is correct:
- Assistant
Let me also verify the test file was created correctly:
- Assistant
Let me also run a broader test suite to make sure all tests pass:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.