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 understanding the repository structure and the issue at hand. The issue is about adding OAuth credential injection support to
gemini-cli, similar to howcodexhandles it. I need to:- First explore the repository structure
- Understand how codex implements its OAuth flow
- Implement the same pattern for gemini-cli
- Test the implementation
Let me begin by exploring the repository.
Assistant
Let me explore more to find the adapters (agents) for both codex and gemini-cli.
Assistant
The
adaptersdirectory is at/harbor/adapters. Let me explore that.Assistant
Let me look for gemini-cli and codex adapters specifically:
Assistant
Let me look for the adapters more carefully - they might be YAML/JSON files or in a different location:
Assistant
No gemini or codex directories at maxdepth 2. Let me search deeper and also look for files containing these names.
Assistant
Let me look at the gemini-cli related files to understand the project structure:
Assistant
Now I understand. The
adaptersdirectory contains benchmark adapters, not agent adapters. Thegemini-cliis likely an agent definition somewhere in the project. Let me search for where agents are defined.Assistant
The agents directory is at
/harbor/src/harbor/agents. Let me look at it.Assistant
Let me look at the installed agents directory and factory:
Assistant
I can see both
codex.pyandgemini_cli.py. Let me study both to understand the OAuth pattern in codex and the current gemini-cli implementation.Assistant
Now let me look at the gemini_cli.py file to understand the current implementation:
<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me open the file using the open command.
Assistant
The user is providing an error message indicating that my tool call wasn't properly formatted. Let me try again with the correct format.
Assistant
Now I have a clear understanding of both files:
-
codex.py has the OAuth pattern with
_resolve_auth_json_path()method that:- Checks
CODEX_AUTH_JSON_PATHfor an explicit path - Checks
CODEX_FORCE_AUTH_JSONfor forcing the default~/.codex/auth.json - Falls back to API key authentication if neither is set
- Checks
-
gemini_cli.py currently only uses environment variables for auth (GEMINI_API_KEY, Vertex auth vars) with no OAuth credential injection support.
I need to add the same OAuth pattern to gemini_cli.py:
- Add
_resolve_oauth_creds_path()method similar to codex's_resolve_auth_json_path() - Add
GEMINI_OAUTH_CREDS_PATHandGEMINI_FORCE_OAUTHenvironment variable support - Default behavior unchanged (fully backward-compatible)
- Upload the OAuth credentials file, chown it, and set it up in
~/.gemini/oauth_creds.json
Let me also check if there are any tests for the codex auth:
<tool_call> <function=bash_terminal> <parameter=command> find /harbor -name "testcodex" -o -name "auth" 2>/dev/null | grep -v ".venv" </tool_call>
-
Assistant
The user is pointing out that I didn't make a proper tool call. I need to use the bash_terminal tool properly with a command parameter. Let me fix this.
Assistant
Let me look at the codex auth test file:
Assistant
Now I have a comprehensive understanding of the issue. Let me:
- Check test fixtures/conftest to understand
temp_dirfixture - Look at
parse_bool_env_valueutility - Implement OAuth support in
gemini_cli.py - Create corresponding tests
- Check test fixtures/conftest to understand
Assistant
Now I understand the full picture. Let me also check the conftest for the
temp_dirfixture:Assistant
Let me check the current state of the gemini_cli.py file, particularly the imports and the
runmethod to plan my changes carefully:Assistant
Let me now plan and implement the changes:
-
In
gemini_cli.py:- Add
parse_bool_env_valueimport fromharbor.utils.env - Add
_resolve_oauth_creds_path()method (mirroring codex's_resolve_auth_json_path()) - Modify the
run()method to handle OAuth credentials:- Check for
GEMINI_OAUTH_CREDS_PATH(explicit path) orGEMINI_FORCE_OAUTH(force ~/.gemini/oauth_creds.json) - Upload the OAuth credentials file to the container
- Chown the file
- Set it up in the container's ~/.gemini/oauth_creds.json
- Check for
- Add
-
Create tests in
tests/unit/agents/installed/test_gemini_cli_auth.py(mirroring test_codex_auth.py)
Let me first check what the
_get_envmethod looks like in the base class:-
Assistant
Let me implement the OAuth support for gemini_cli.py. I need to:
- Add the
parse_bool_env_valueimport - Add
_resolve_oauth_creds_path()method - Modify
run()to handle OAuth credentials
Let me first look at how the run method currently handles auth to understand where to add the OAuth logic.
- Add the
Assistant
Now I have a complete understanding. Let me implement the changes to gemini_cli.py:
Assistant
The user is showing me an error message about a broken tool call. I need to be careful to always use proper tool calls. Let me continue my analysis and start implementing.
Assistant
Now I have a complete understanding. Let me implement the OAuth support for gemini_cli.py. I need to:
- Add the
parse_bool_env_valueimport fromharbor.utils.env - Add
_resolve_oauth_creds_path()method (mirroring codex's_resolve_auth_json_path()) - Modify the
run()method to handle OAuth credentials - Create corresponding tests
Let me start implementing:
- Add the
Assistant
I need to:
- Add import for
parse_bool_env_valuefromharbor.utils.env - Add the
_resolve_oauth_creds_path()method - Modify the
run()method to handle OAuth credentials
Let me look at the exact lines in gemini_cli.py to plan my edits precisely.
First, let me see the complete file structure:
- Add import for
Assistant
Let me check the total line count and then find where to insert the import and the new method:
Assistant
Let me understand the full picture:
- The gemini_cli.py file has 715 lines
- The imports are at lines 1-27
- The class starts at line 35
- The
run()method is somewhere in the file
I need to:
- Add the
parse_bool_env_valueimport (line 7 area, after existing imports) - Add the
_resolve_oauth_creds_path()method somewhere in the class - Modify the
run()method to handle OAuth credentials
Let me find where the
run()method starts and the current auth handling is:<tool_call> <function=bash_terminal> <parameter=command> grep -n "async def run|auth_vars|GEMINI_API_KEY|GOOGLE_APPLICATION" /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
The user is showing me that I made a mistake - I forgot to include the tool call for the bash terminal command. I need to use the bash_terminal tool properly with a "command" argument. Let me fix this and continue with my analysis and implementation.
Assistant
Now I have a complete picture. Let me implement the OAuth support for gemini_cli.py. I need to:
- Add the
parse_bool_env_valueimport - Add
_resolve_oauth_creds_path()method - Modify the
run()method to handle OAuth credentials
Let me first see the full
run()method:- Add the
Assistant
Now I have a complete understanding. Let me implement the OAuth support for gemini_cli.py. I need to:
- Add the
parse_bool_env_valueimport - Add
_resolve_oauth_creds_path()method - Modify the
run()method to handle OAuth credentials
Let me start with the import:
- Add the
Assistant
Good, the import was added. Now I need to add the
_resolve_oauth_creds_path()method to the GeminiCli class. Let me find a good place to add it - typically after the__init__method and before the main business logic. Let me find where to insert it:Assistant
Let me look at lines 95-105 to find the exact insertion point:
Assistant
Now I need to add the
_resolve_oauth_creds_path()method. I'll insert it at line 101 (before theinstallmethod):Assistant
Let me verify the method was inserted correctly.
Assistant
The method was inserted correctly. Now I need to modify the
run()method to handle OAuth credentials. Let me find where therun()method is now:Assistant
Let me view the run() method:
Assistant
Now I need to modify the
run()method to handle OAuth credentials. I'll add the OAuth logic after the auth_vars section and before the skills_command. Let me replace the relevant section:Assistant
I need to modify the
run()method to handle OAuth credentials. I'll add the OAuth logic after the auth_vars section and before the skills_command. Let me edit the file:Assistant
I need to modify the
run()method to handle OAuth credentials. Let me replace the relevant section:Assistant
The user is showing me an error about my tool call format. Let me fix this and continue with the implementation.
Assistant
Good, I can see the OAuth handling was added. However, I need to verify the file is syntactically correct and check for any duplicate or missing lines. Let me check the relevant section:
Assistant
I see the file got corrupted during patching - there are duplicate lines and missing the skills_command exec call. Let me restore and redo this properly.
Assistant
Good, I restored the original file. Let me take a more careful approach and make the changes properly. I'll use a script to do the edits.
Assistant
Let me be very careful with my tool calls. I'll implement the changes step by step.
First, let me add the import:
Assistant
Good. Now let me add the
_resolve_oauth_creds_path()method. Let me find the exact line number:Assistant
Good. Now I'll insert the
_resolve_oauth_creds_path()method before line 101:Assistant
The user is showing me an error message about my tool call format. I need to continue with my implementation. Let me verify the method was inserted correctly and then modify the
run()method.Assistant
Good. Now I need to modify the
run()method to handle OAuth credentials. Let me find the exact lines:Assistant
I need to insert OAuth handling code after the
for var in auth_varsloop and before theskills_commandline. Let me use a Python script to do this carefully:Assistant
Let me verify the changes are correct:
Assistant
The changes look good. Let me verify the entire file is syntactically correct by checking if Python can parse it:
Assistant
The syntax is correct. Now let me run the existing tests to make sure nothing is broken:
Assistant
Let me check if there's a virtual environment and install the package properly:
Assistant
Good, the package is installed. Let me run the tests again:
Assistant
The user is showing me that the test collection is failing because of a pytest configuration issue with
asyncio_mode. Let me check the pyproject.toml and fix this to run the tests properly.Assistant
I need to install pytest-asyncio properly to run the tests.
Assistant
Now let me run the codex auth tests to verify they still pass:
Assistant
All 18 codex auth tests pass. Now let me check if there are existing gemini_cli tests:
Assistant
I see there's already a
test_gemini_cli.pyfile. The issue mentions that tests should be ported 1:1 fromtest_codex_auth.py. I need to create a new test filetest_gemini_cli_auth.pythat mirrors the codex auth tests. Let me first check the existingtest_gemini_cli.pyto understand patterns:Assistant
Let me create the test file that mirrors the codex auth tests for gemini_cli:
Assistant
The user is showing me that the test file was created successfully. Now I need to run the new tests to make sure they pass. Let me run the tests.
Assistant
All 17 new tests pass. Let me also run the existing gemini_cli tests to make sure nothing is broken:
Assistant
All existing gemini_cli tests still pass. Let me also run all the agent installed tests to make sure nothing is broken:
Assistant
The user is showing me that there's a missing
hypothesisdependency for some tests. Let me install it and run the tests again, excluding that problematic file since it's not related to my changes.Assistant
All 547 tests pass. Let me now verify the changes I made and summarize:
Assistant
The user is showing me the git status. I can see that only the
gemini_cli.pyfile shows up in the diff (51 insertions). My new test file is untracked. Let me check the full status and verify everything looks good.Assistant
All tests pass. Let me submit my changes now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.