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 how it's organized and find the relevant files for implementing the OAuth credential injection for gemini-cli.
Assistant
Let me explore the structure more, especially looking for the codex auth implementation and gemini-cli agent.
Assistant
Let me look at the adapters directory since this seems to be about agent adapters, and also look at the codex auth implementation.
Assistant
These are benchmarks, not the agent adapters. Let me look at the src directory.
Assistant
Let me look at the harbor package structure.
Assistant
Let me look at the agents directory, which likely contains the gemini-cli and codex agent implementations.
Assistant
Let me explore the installed agents directory and also look for gemini-cli and codex references.
Assistant
Let me read the codex.py file to understand the existing auth.json pattern.
Assistant
Now let me read the gemini_cli.py file:
Assistant
Now I understand the issue and the codebase. Let me analyze:
-
The
codex.pyhas an_resolve_auth_json_path()method that checks for:CODEX_AUTH_JSON_PATHenv var for a specific pathCODEX_FORCE_AUTH_JSONenv var to use~/.codex/auth.json
-
The
gemini_cli.pycurrently only usesGEMINI_API_KEY/ Vertex env vars for authentication. -
The issue asks to add OAuth credential injection to
gemini_cli.py, mirroring the codex pattern:GEMINI_OAUTH_CREDS_PATH/GEMINI_FORCE_OAUTH- Default behavior unchanged (backward-compatible)
- The OAuth creds file would be at
~/.gemini/oauth_creds.json
Let me look at:
- How the codex upload and chown works for auth.json
- The existing base agent methods for environment interaction
- The
parse_bool_env_valueutility
Let me also look at the base.py for the installed agents to understand the
_get_envmethod andexec_as_root.<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/agents/installed/base.py </tool_call>
-
Assistant
I need to use the proper tool call format. Let me read the base.py file.
Assistant
Now let me look at the test files for codex auth:
Assistant
Let me read the codex auth test file to understand the test patterns:
Assistant
Let me also check the conftest for the test fixtures:
Assistant
Now let me look at the conftest.py to understand the
temp_dirfixture and other shared fixtures:Assistant
Now let me read the existing gemini_cli tests:
Assistant
Now I have a thorough understanding of the codebase. Let me implement the OAuth credential injection for gemini-cli, mirroring the codex pattern. Let me first check the current state of the gemini_cli.py file more carefully:
Assistant
Let me look at the relevant part of the run method:
Assistant
Now I have a complete understanding. Let me implement the OAuth credential injection for gemini-cli, mirroring the codex pattern. I'll:
- Add
_resolve_oauth_creds_path()method - Modify the
run()method to handle OAuth creds injection
- Add
Assistant
Now I'll implement the changes to
gemini_cli.pyto add OAuth credential injection mirroring the codex pattern:Assistant
The tool call format seems wrong. Let me use the proper edit command format.
Assistant
I need to use the
editcommand with proper formatting. Looking at the special commands section, theeditcommand expects:edit --file PATH LINE_RANGE REPLACEMENT_TEXT
Let me try using the proper tool call format.
Assistant
Good, the import was added. Let me verify it's in the right place:
Assistant
I need to add the import for parse_bool_env_value in the proper location. Let me first check the current state of the imports, then I'll need to:
- Add the import
- Add the _resolve_oauth_creds_path method
- Modify the run() method to handle OAuth creds
Let me use sed to properly insert the import in the right place (with other imports).
Assistant
Let me add the import properly using sed to insert it before the class definition.
Assistant
Let me find the right place to insert the import:
Assistant
I need to add the import for parse_bool_env_value after the existing harbor imports (after line 27, before _ImageMediaType).
Assistant
Now I need to:
- Verify the import was added
- Add the
_resolve_oauth_creds_pathmethod - Modify the
run()method to handle OAuth creds
Let me first verify the import was added correctly, then add the _resolve_oauth_creds_path method.
Assistant
Good, the import was added. Now I need to find the line numbers for the
_build_settings_commandmethod and therunmethod to add the_resolve_oauth_creds_pathmethod and modifyrun().Assistant
I was in the middle of implementing the OAuth credential injection for gemini-cli. Let me continue by:
- Adding the
_resolve_oauth_creds_pathmethod before_build_settings_command - Modifying the
run()method to handle OAuth creds
Let me first check the exact line numbers and content around where I need to add the new method:
- Adding the
Assistant
Now I'll add the
_resolve_oauth_creds_pathmethod. I'll insert it before_build_settings_command(before line 638):Assistant
Let me verify the method was added correctly:
Assistant
The
_resolve_oauth_creds_pathmethod was added. Now I need to modify therun()method to handle OAuth creds injection. Let me see the current run() method:Assistant
Let me check the exact line numbers in the run() method to properly insert the OAuth handling code:
Assistant
I need to continue implementing the OAuth handling in the
run()method. Let me see the exact area where I need to insert the code:Assistant
Now I need to add the OAuth handling code after the auth_vars loop (after line 708) and before the skills_command. Let me add it:
Assistant
Let me verify the current state of the file to see if the OAuth handling code was inserted correctly:
Assistant
I see there's a Unicode encoding issue with the arrow character (→) in the comments. Let me fix that first, and then I need to verify that the
setup_oauthvariable is actually being used in the command. Let me check the full context:Assistant
I notice a few issues:
- The Unicode arrows got corrupted (showing
342206222instead of→) - The
setup_oauthvariable is defined but never used - it needs to be executed viaexec_as_agent
Let me rewrite the run method properly. First, let me see the full run method:
- The Unicode arrows got corrupted (showing
Assistant
Let me look at the full structure of the run method to properly rewrite it:
Assistant
I see the issue - the Unicode arrows got corrupted and the
setup_oauthis defined but never executed. Let me fix this properly by rewriting the entire run method to mirror the codex pattern correctly.First, let me see the full file length and the exact structure:
Assistant
I need to fix several issues: the corrupted Unicode arrows, the unused
setup_oauthvariable, and ensure proper cleanup. Let me use Python to make a clean replacement of the run method.Assistant
Let me verify the changes to the file are correct:
Assistant
The file has been updated. Let me verify the Python syntax is correct and then check the test file:
Assistant
Now let me verify the full implementation by running the existing tests:
Assistant
I need to install the harbor package in development mode. Let me check what package manager is being used.
Assistant
Let me install the package in development mode:
Assistant
The package is installed. Let me run the tests now:
Assistant
Let me try using the virtual environment directly:
Assistant
All existing tests pass. Now let me create a test file for the OAuth creds functionality, mirroring the codex auth tests:
Assistant
Let me run the new OAuth auth tests to verify they pass:
Assistant
All 17 OAuth tests pass. Let me also run the codex auth tests and existing gemini tests to make sure everything is working:
Assistant
All tests pass. Let me verify the final state of the gemini_cli.py file to make sure everything is correct:
Assistant
The implementation is complete. Let me run a final comprehensive test to ensure everything is working properly:
Assistant
All 63 tests pass. Let me verify the final diff and make sure everything is clean:
Assistant
All tests pass and the implementation is complete. Let me do a final verification of the diff and then submit.
Assistant
The implementation is complete. Here's a summary of what was implemented:
Changes Made
1.
src/harbor/agents/installed/gemini_cli.py-
Added import:
parse_bool_env_valuefromharbor.utils.env -
Added
_resolve_oauth_creds_path()method: Mirrors the codex pattern with the same priority logic:GEMINI_OAUTH_CREDS_PATH=<path>→ use that specific fileGEMINI_FORCE_OAUTH=<truthy>→ use~/.gemini/oauth_creds.json- Default →
None(backward-compatible, uses GEMINI_API_KEY)
-
Modified
run()method:- Resolves OAuth creds path before executing
- When OAuth creds are present: uploads to container, chowns, symlinks to
~/.gemini/oauth_creds.json - When no OAuth creds: uses existing GEMINI_API_KEY flow
- Batches setup commands together
- Cleans up temporary OAuth directory after run
-
Assistant
The implementation is complete. Let me verify everything works with one final comprehensive test run before submitting:
Assistant
The user wants me to submit my changes since everything is working correctly. All 63 tests pass, the implementation is complete, and I've verified the changes work properly. I should use the submit command.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.