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.Interface
No new interfaces are introduced.
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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Now let me look at the agents directory structure and find the gemini-cli and codex agents.
Assistant
Now let me look at the codex agent and the codex auth tests to understand the pattern:
Assistant
Now let me look at the gemini-cli agent:
Assistant
Now let me look at the gemini-cli tests to understand the existing test patterns:
Assistant
Now let me check the helper utility
parse_bool_env_value:Assistant
Let me look at the BaseInstalledAgent and understand
_get_env:Assistant
Now let me look at the entire gemini_cli.py to understand its full structure:
Assistant
Now let me look at the conftest.py and understand the test fixtures:
Assistant
Now let me look at the full codex.py for the run method:
Assistant
Now let me look at how the existing
runmethod is structured for gemini-cli to understand the full flow:Assistant
Let me look at
exec_as_agentandexec_as_root:Assistant
Now let me look at the
BaseEnvironmentclass to understand theupload_filemethod:Assistant
Let me look at how the upload_file is used in codex to understand the full flow:
Assistant
Now let me check the existing codex tests:
Assistant
Now let me run the existing tests to ensure they pass:
Assistant
Now let me run the existing gemini-cli tests:
Assistant
Now let me look at the run method of codex to understand the exact flow once more:
Assistant
Now let me look at the install method of codex:
Assistant
Let me check if there are any existing references to oauth_creds:
Assistant
Let me also check how the install flow creates directories for gemini-cli:
Assistant
Now I have a thorough understanding. Let me check if there are any existing references to
parse_bool_env_valuein gemini_cli.py:Assistant
Now let me make the changes to the gemini_cli.py file. First, let me view the imports section to add
parse_bool_env_value:Assistant
Now let me add the import and implement the changes:
Assistant
Let me add the import for
parse_bool_env_value:Assistant
Let me use the
replacetool instead:Assistant
Let me try again with a simpler edit.
Assistant
Now let me look at the run method again to add the OAuth logic:
Assistant
Now let me add the
_resolve_oauth_creds_pathmethod. First, let me find a good place to add it:Assistant
Now I'll add the
_resolve_oauth_creds_pathmethod after_build_settings_command:Assistant
Now let me insert this method after
_build_settings_commandand before therunmethod. The line right after the_build_settings_commandmethod is at line 647 (return command, model_alias) and therunmethod starts at line 649 with@with_prompt_template. Let me look at the exact lines to insert:Assistant
Now let me modify the
runmethod to use the OAuth creds when configured. Let me first re-examine the run method:Assistant
Now let me modify the
runmethod to add the OAuth handling. I'll use thereplacetool:Assistant
Now let me look at the exact lines in the current file that I want to replace:
Assistant
Let me use a Python script to do the replacement carefully:
Assistant
Now let me verify the changes:
Assistant
The implementation is in place. Let me also verify the full file compiles correctly:
Assistant
Let me run the existing tests to make sure I haven't broken anything:
Assistant
Now let me create a test file mirroring the codex auth tests:
Assistant
Now let me run the new tests:
Assistant
All 19 tests pass. Let me also run all the other gemini-cli tests to confirm I haven't broken anything:
Assistant
All 41 tests pass. Now let me also run the codex auth tests to make sure I haven't broken them:
Assistant
All codex tests still pass. Let me also run the broader test suite to make sure nothing else is broken:
Assistant
All 714 tests pass. Let me also run a wider scope of unit tests to make sure I haven't introduced any regressions:
Assistant
All 2522 unit tests pass. Now let me check the linter and formatter:
Assistant
I notice the formatter has changed the
->to a Unicode arrow→in the comments. Let me check the file directly to see this:Assistant
Let me verify the actual character:
Assistant
Yes, the formatter has changed
->to the Unicode arrow→. Let me check that this is consistent with the rest of the codebase (specifically the codex.py):Assistant
Good, the Unicode arrow is the standard format used in this codebase. Now let me check that the comment in the
runmethod also uses this:Assistant
The formatter only converted some arrows. Let me look at the codex comments more carefully:
Assistant
Let me update the comments to use the Unicode arrow for consistency with the codebase:
Assistant
Now let me check the test file diff:
Assistant
Let me also verify the new test file:
Assistant
Now let me run the new tests one more time to confirm they all pass:
Assistant
All 19 tests pass. Let me also check the type checker:
Assistant
Let me also verify the final state of the gemini_cli.py file:
Assistant
Excellent! The implementation looks great. Let me do a final check to ensure all unit tests pass:
Assistant
All 2522 unit tests pass. Now let me also do a final review of the diff to ensure everything is clean:
Assistant
Let me also run the test one more time to ensure everything is in order:
Assistant
All 41 tests pass. Now let me do a quick sanity check on the file to make sure it still has all the necessary structure:
Assistant
Let me also do a manual smoke test to make sure the changes work as expected:
Assistant
The smoke test has an issue with how I'm using mocks. Let me fix it:
Assistant
All smoke tests pass. The implementation works correctly. Let me clean up the temporary test file:
Assistant
Now let me view the final diff of all changes:
Assistant
Now let me also confirm the new test file:
Assistant
Now let me run all the tests one more time to ensure everything works:
Assistant
All 601 tests pass. Let me also run the entire unit test suite to ensure nothing else is broken:
Assistant
All 2522 unit tests pass. Now let me also verify the formatting and linting is good:
Assistant
All checks pass:
- Ruff lint: All checks passed
- Ruff format: Already formatted
- Type checker (ty): All checks passed
Checklist
Let me now go over the checklist:
-
If an error was reported in the issue description, I have successfully reproduced it.
Assistant
Summary
I successfully implemented the OAuth credential injection feature for the
gemini-cliagent, mirroring the codex auth.json pattern.Changes made:
1.
src/harbor/agents/installed/gemini_cli.py- Added import for
parse_bool_env_valuefromharbor.utils.env - Added new
_resolve_oauth_creds_path()method that mirrors codex's_resolve_auth_json_path():- Returns
PathifGEMINI_OAUTH_CREDS_PATHenv var is set to a valid file - Returns
Path.home() / ".gemini" / "oauth_creds.json"ifGEMINI_FORCE_OAUTHis truthy - Returns (default behavior) otherwise
- Returns
- Added import for
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.