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.
Assistant
Let me explore the structure more to find the gemini-cli adapter and the codex adapter to understand the pattern.
Assistant
The adapters directory seems to be for benchmarks. Let me look at the main source code structure.
Assistant
Now let me look at the codex.py file to understand the OAuth pattern, then the gemini_cli.py file to understand its current implementation.
Assistant
The
opencommand doesn't take afileargument, let me check the proper usage.Assistant
Now let me look at the gemini_cli.py file:
Assistant
Now let me look at the existing tests for codex auth to understand the pattern:
Assistant
Now let me check if there are any existing gemini tests:
Assistant
Now let me also check the
parse_bool_env_valueutility function used by codex:Assistant
Now I have a clear understanding of the codebase. Let me also look at the
_REMOTE_CODEX_HOMEpattern and understand how the environment paths work:Assistant
Now let me look at the base installed agent class to understand the
_get_envmethod:Assistant
Now I have a complete understanding. Let me create my implementation plan:
Plan:
- Add
_resolve_oauth_creds_path()method toGeminiCli(mirroring_resolve_auth_json_path()from Codex) - Add the OAuth credential injection logic in the
run()method - Create the test file
test_gemini_cli_auth.py(porting tests fromtest_codex_auth.py) - Run the tests to confirm everything works
Let me also check how the import for
parse_bool_env_valueshould be done in gemini_cli.py:- Add
Assistant
Now let me implement the changes. I'll modify
gemini_cli.pyto add the OAuth credential support:Assistant
I need to use the
opencommand without thefileparameter. Let me check the correct usage.Assistant
Now let me add the import for
parse_bool_env_valueandPurePosixPath:Assistant
Good. Now let me add the import for
parse_bool_env_valueand also the import forEnvironmentPaths:Assistant
Good. Now I need to add the
parse_bool_env_valueimport fromharbor.utils.env:Assistant
Now let me add the class-level constants for OAuth and the
_resolve_oauth_creds_pathmethod. Let me first see the class definition:Assistant
I'll add the class constants
_REMOTE_GEMINI_SECRETS_DIRafter_image_counter:Assistant
Now let me add the
_resolve_oauth_creds_pathmethod. I'll find a good place to insert it (before_save_image):Assistant
Let me find where
_save_imageis defined:Assistant
I'll add the
_resolve_oauth_creds_pathmethod right before_save_image. Let me see the lines around line 135:Assistant
Now I'll insert the
_resolve_oauth_creds_pathmethod before_save_image. Let me usesedto insert at line 136:Assistant
Let me verify the method was added correctly:
Assistant
The method was added correctly. Now I need to modify the
run()method to inject OAuth credentials. Let me find therunmethod:Assistant
Now I need to modify the
run()method to add OAuth credential injection. I need to:- After copying the auth vars to env, resolve OAuth creds path
- Before the main
exec_as_agentcall, upload and symlink the OAuth credentials if present
Let me replace the run method with the modified version:
Assistant
I need to replace the run method. Let me create the new version:
Assistant
I need to replace lines 681-750 with the new run method. Let me do this carefully:
Assistant
The run method starts at line 681 and ends at the end of the file (line 748). Let me delete those lines and insert the new method:
Assistant
Let me verify the file is correct now:
Assistant
Good. Now let me verify the complete file structure:
Assistant
Now let me create the test file for OAuth auth, ported 1:1 from
test_codex_auth.py:Assistant
Now let me run the tests to see if everything works:
Assistant
let me check how the existing tests are run and what's the pytest configuration:
Assistant
The existing tests also have the same issue. Let me check how to run tests properly:
Assistant
The issue is the module import. Let me check if there's a conftest.py that sets up the path:
Assistant
The tests need the harbor module to be installed. Let me check if the package needs to be installed in editable mode, or if there's a PYTHONPATH setup.
Assistant
Now let's run the tests:
Assistant
Most tests pass. There's one test failure that's in my test code, not the implementation. The issue is that the last exec call in
finallyblock doesn't passenv(it's None). Let me fix the test:Assistant
All 18 tests pass. Now let me also run the existing gemini_cli tests and the codex auth tests to make sure nothing is broken:
Assistant
All tests pass. Let me also run the gemini_cli MCP tests to make sure nothing is broken:
Assistant
All tests pass. Let me verify the final state of the modified file:
Assistant
I notice the import statement is not on a separate line. Let me fix that:
Assistant
The import is still in the wrong place. Let me fix this properly by moving it to the correct location (right after the other imports, before the type aliases):
Assistant
Good. Now let me verify the syntax is still valid and run all tests again:
Assistant
All 58 tests pass. Let me also check the git diff to see a summary of all changes:
Assistant
I notice there's a duplicate import for
parse_bool_env_value. Let me fix that:Assistant
There's a duplicate import. Let me remove the second one:
Assistant
Let me verify the syntax and re-run all tests:
Assistant
All 58 tests pass. Let me now review the final diff to make sure everything is clean:
Assistant
Let me also run any broader agent tests that might be affected:
Assistant
That error is unrelated to my changes (missing
hypothesismodule). Let me exclude that test file and run the rest:Assistant
All 661 tests pass (excluding the one unrelated test that requires
hypothesis).Now let me verify the final state of my changes by viewing the git status:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.