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 find the relevant files for implementing the OAuth credential support for
gemini-cli.Assistant
Let me explore the adapters directory to find the gemini-cli agent and the codex agent (for reference).
Assistant
The adapters directory seems to be benchmarks. Let me look in the
srcdirectory and thepackagesdirectory for the actual agent implementations.Assistant
Now let me look at the key files: the gemini-cli agent, the codex agent (for reference), and the codex auth test.
Assistant
Now let me look at the codex agent to see how the auth.json pattern is implemented there.
<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/agents/installed/codex.py </tool_call>
Assistant
Let me properly use the bash_terminal tool to view the codex.py file.
Assistant
Now I can see the codex pattern clearly. Let me also look at the test file for codex auth to understand what tests I need to port:
Assistant
Now let me look at the existing gemini-cli tests to understand the test patterns:
Assistant
Let me also check the utility functions and understand what Gemini CLI expects for OAuth credentials:
Assistant
Now let me understand the Gemini CLI OAuth credential file structure. Let me also check the conftest.py for shared fixtures:
Assistant
Now I have a clear understanding of the codebase. Let me plan the implementation:
- Add
_resolve_oauth_creds_path()method toGeminiCli- mirroring_resolve_auth_json_path()from Codex - Modify the
run()method to upload OAuth creds if present - Create tests mirroring
test_codex_auth.py
Let me first check what remote path patterns are used in the gemini-cli run method:
- Add
Assistant
Let me check the base class to understand the
_get_envmethod:Assistant
Now I have all the information I need. Let me create the implementation. The plan is:
- Add
_resolve_oauth_creds_path()method toGeminiCli(mirroring_resolve_auth_json_path()from Codex) - Modify
run()to upload OAuth credentials when available, adding a remote secrets directory pattern similar to codex - Create corresponding tests
Let me now implement the changes:
- Add
Assistant
Now let me open the gemini_cli.py file and implement the changes:
Assistant
Now I'll implement the changes. First, I need to add the necessary imports and then add the OAuth credential resolution method and modify the run method.
Assistant
Let me use a different approach - directly editing the file with the
editcommand:Assistant
Let me use a simpler Python script to make the modifications:
Assistant
Let me make the changes step by step using the
editcommand:Assistant
Now I'll make the changes step by step. First, add the PurePosixPath import:
Assistant
Let me use the proper edit syntax:
Assistant
Good, now let me add the
parse_bool_env_valueimport:Assistant
Now let me add the class-level constant for the remote secrets directory and add the
_resolve_oauth_creds_pathmethod. First, let me add the class constant after SUPPORTS_ATIF:Assistant
I need to add the
_resolve_oauth_creds_pathmethod after line 100 (after the_validate_reasoning_effortmethod ends). Let me add it there.Assistant
Now I need to modify the
runmethod to handle OAuth credential injection. Let me find the run method:Assistant
I need to scroll to the run method to see its current content and modify it to add OAuth credential handling.
Assistant
I need to modify the run method to add OAuth credential injection. I'll replace the auth_vars section to include OAuth handling.
Assistant
Good, the run method is now updated. Now I need to create the test file. Let me first check if the code compiles properly:
Assistant
The module import error is just because the package isn't installed. Let me use the virtual environment:
Assistant
Excellent! The import is successful. Now let me create the test file for the OAuth credential resolution, mirroring the codex auth tests:
Assistant
Now let me run the existing tests to make sure I haven't broken anything:
Assistant
Excellent! All existing tests pass. Now let me run my new tests:
Assistant
All 17 tests pass. Now let me also run the other gemini_cli related tests to make sure nothing is broken:
Assistant
Let me run more tests to verify everything is working correctly.
Assistant
All tests pass. Let me verify the implementation is complete by reviewing 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.