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 howcodexagent handles authentication. The proposal is to add:GEMINI_OAUTH_CREDS_PATHenvironment variable (to specify path to OAuth credentials)GEMINI_FORCE_OAUTHenvironment variable (to force OAuth authentication)- Default behavior should remain unchanged (backward-compatible)
Let me first explore the repository structure to understand what we're working with.
Assistant
This is a Harbor repository. Let me look at the apps directory to find the gemini-cli application.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /harbor/apps </tool_call>
Assistant
Let me list the apps directory to find the gemini-cli application.
Assistant
The apps directory only contains a viewer. Let me look for gemini-cli elsewhere in the repository. Let me check the src directory and also search for gemini-cli.
<tool_call> <function=bash_terminal> <parameter=command> find /harbor -type d -name "gemini" 2>/dev/null </tool_call>
Assistant
I need to find the gemini-cli directory in the repository. Let me search for it.
Assistant
These are just virtual environment packages. Let me search for the actual gemini-cli source code or check the adapters directory since this might be an adapter-based architecture.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /harbor/adapters </tool_call>
Assistant
Let me list the adapters directory to find gemini-cli.
Assistant
The adapters directory seems to contain benchmark adapters, not the gemini-cli application. Let me search for gemini-cli in a different way - maybe looking for Python files with "gemini" in the name.
<tool_call> <function=bash_terminal> <parameter=command> find /harbor -name "gemini" -type f 2>/dev/null | head -30 </tool_call>
Assistant
Let me search for gemini-cli related files in the repository.
Assistant
I found the gemini-cli source file at
/harbor/src/harbor/agents/installed/gemini_cli.py. Let me examine this file to understand its current structure and how authentication is handled.<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me open the gemini_cli.py file to examine its structure.
Assistant
Now I understand the gemini_cli.py file. It's a Harbor agent that wraps the Google Gemini CLI tool. The current implementation handles authentication through environment variables like
GEMINI_API_KEY,GOOGLE_APPLICATION_CREDENTIALS, etc.The issue asks to add OAuth credential injection support similar to how
codexagent handles it. Let me look at how codex handles this to understand the pattern better.Let me search for codex-related code to understand the auth pattern.
<tool_call> <function=bash_terminal> <parameter=command> find /harbor -name "codex" -type f 2>/dev/null | head -20 </tool_call>
Assistant
Let me search for codex-related files in the repository to understand the auth pattern.
Assistant
Now let me examine the codex.py file and the test_codex_auth.py file to understand how the OAuth authentication is implemented there.
<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/agents/installed/codex.py </tool_call>
Assistant
I need to read the codex.py file. Let me use bash to cat it.
Assistant
Now I can see how Codex handles OAuth authentication. Let me also look at the test file to understand the test patterns.
<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/tests/unit/agents/installed/test_codex_auth.py </tool_call>
Assistant
Let me read the test file to understand how the auth is tested.
Assistant
Now let me look at the base class to understand the
_get_envmethod that's used for reading environment variables.<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/agents/installed/base.py </tool_call>
Assistant
Let me read the base class to understand the available methods.
Assistant
Now I have a good understanding of the codebase. Let me also look at the existing test file for gemini_cli to understand how tests are structured for this agent.
<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/tests/unit/agents/installed/test_gemini_cli.py </tool_call>
Assistant
I need to read the gemini_cli test file to understand the testing patterns for this agent.
Assistant
Now I have a good understanding of the codebase. Let me also check the
parse_bool_env_valueutility function that's used by codex for parsing boolean environment variables.<tool_call> <function=bash_terminal> <parameter=command> grep -r "parse_bool_env_value" /harbor/src --include="*.py" | head -5 </tool_call>
Assistant
Let me search for the parse_bool_env_value function to understand how it works.
Assistant
Now let me examine the env.py file to see the
parse_bool_env_valuefunction:<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/utils/env.py </tool_call>
Assistant
Let me read the env.py file to understand the parse_bool_env_value function.
Assistant
Now I have all the information I need to implement OAuth authentication for gemini-cli, mirroring the codex pattern. Let me summarize what I need to do:
- Add a
_resolve_oauth_creds_path()method to theGeminiCliclass, similar toCodex._resolve_auth_json_path() - Modify the
run()method to use the OAuth credentials when available (viaGEMINI_OAUTH_CREDS_PATHorGEMINI_FORCE_OAUTH) - Upload the OAuth credentials file to the container
- Set up a symlink or copy it to the appropriate location for Gemini CLI to use
- Set the appropriate environment variable (
GEMINI_CLI_OAUTH_TOKENor similar)
Let me check what the issue description says about the path format:
GEMINI_OAUTH_CREDS_PATH- environment variable to specify the path to OAuth credentialsGEMINI_FORCE_OAUTH- environment variable to force OAuth authentication- Default behavior should be unchanged (backward-compatible)
- Uses
~/.gemini/oauth_creds.jsonby default
- Add a
Assistant
Let me search for any existing OAuth references in the gemini_cli.py file.
Assistant
Based on my research, I now understand the requirements. I need to implement OAuth credential injection for the gemini-cli agent that mirrors the codex auth pattern. Let me implement the changes to the gemini_cli.py file.
The key points from the issue description:
- Add
GEMINI_OAUTH_CREDS_PATHenvironment variable (to specify path to OAuth credentials) - Add
GEMINI_FORCE_OAUTHenvironment variable (to force OAuth authentication) - Default behavior should remain unchanged (fully backward-compatible)
- Mirror the codex pattern with
_resolve_oauth_creds_path→ upload → chown →~/.gemini
Let me now implement the changes. </tool_call>
- Add
Assistant
Now I have a complete understanding of what needs to be implemented. Let me implement the OAuth authentication support for gemini-cli by modifying the gemini_cli.py file. I'll mirror the codex pattern:
Assistant
Now let me implement the changes to add OAuth authentication support to gemini_cli.py. I need to:
- Import
parse_bool_env_valuefromharbor.utils.env - Add a
_resolve_oauth_creds_path()method similar to codex's_resolve_auth_json_path() - Modify the
run()method to handle OAuth credentials - Add OAuth-related environment variables
Let me make these changes:
- Import
Assistant
That sed command might have caused issues. Let me check the file to see its current state:
Assistant
I see the file got corrupted. Let me reset it using git and make the changes more carefully.
Assistant
Now let me view the file again to understand its structure:
Assistant
Now I understand the complete structure. Let me implement the OAuth authentication support. I'll start by modifying the imports to include
parse_bool_env_value:Assistant
Let me make the changes using the
editcommand. I'll add the import forparse_bool_env_value:Assistant
I need to add the import for
parse_bool_env_valueafter the imports fromharbor.models.trajectories. Let me use the edit command to add this import.Assistant
Let me try the correct syntax for the edit command:
Assistant
The file got corrupted. Let me reset it and take a different approach - I'll create the full modified file:
Assistant
Let me use a different approach - I'll write the complete modified file to a temporary file and then copy it over.
Assistant
Let me use Python to modify the file programmatically to avoid issues with the edit command:
<tool_call> <function=bash_terminal> <parameter=command> python3 << 'PYEOF' import re
Read the original file
with open('/harbor/src/harbor/agents/installed/gemini_cli.py', 'r') as f: content = f.read()
1. Add import for parse_bool_env_value after the trajectories imports
Find the import block and add the new import
import_pattern = r'(from harbor.models.trajectories import ([^)]+))' import_replacement = r'\1\nfrom harbor.utils.env import parse_bool_env_value' content = re.sub(import_pattern, import_replacement, content, flags=re.DOTALL)
Write the modified content back
with open('/harbor/src/harbor/agents/installed/gemini_cli.py', 'w') as f: f.write(content)
print("Import added successfully") PYEOF </tool_call>
Assistant
Let me run the Python command to add the import.
Assistant
Good, the import was added. Let me verify it:
Assistant
The import was added correctly. Now I need to add the
_resolve_oauth_creds_path()method and modify therun()method to handle OAuth credentials. Let me read the file to find the right places to make changes:Assistant
I need to see the run method and the lines before it to add the OAuth credentials method and modify the run method. Let me get the content around line 650.
Assistant
Now let me add the
_resolve_oauth_creds_path()method before therun()method and modify therun()method. I'll write the entire modified run method and the new method.Assistant
Now I need to modify the run() method to use OAuth credentials when available. Let me first see the current run method to understand what needs to be modified.
Assistant
Now I need to modify the run() method to handle OAuth credentials similar to how codex does it. The key changes are:
- Resolve the OAuth creds path
- Upload the OAuth creds file to the container if present
- Set up the file properly (chown, symlink)
- Set the appropriate environment variable for Gemini CLI
Let me see the rest of the run method:
Assistant
Now let me look at the complete run method to understand the structure better. Let me see lines 680 to 740 to get a better picture.
Assistant
Now I understand the structure. I need to modify the run() method to add OAuth credential handling. Looking at the codex implementation, the flow is:
- Resolve auth.json path
- Create remote directory
- If auth.json present, upload it, chown it, and symlink it
- Otherwise, write synthetic auth.json from API key
- Continue with normal execution
For Gemini CLI, I need to adapt this to:
- Resolve OAuth creds path
- Create remote directory for OAuth creds
- If OAuth creds present, upload it and set it up
- Set GEMINI_CLI_OAUTH_TOKEN or similar env var
- Continue with normal execution
Let me modify the run method to add OAuth credential handling. I'll need to replace the section that starts with
env = {"GEMINI_CLI_TRUST_WORKSPACE": "true"}to include the OAuth handling.Assistant
Let me verify the changes were applied correctly:
Assistant
The changes look good! Now let me check if there's a syntax error by trying to parse the file with Python:
<tool_call> <function=bash_terminal> <parameter=command> python3 -m py_compile /harbor/src/harbor/agents/installed/gemini_cli.py && echo "Syntax OK" </tool_call>
Assistant
Let me run the syntax check command.
Assistant
The syntax is valid. Now let me look at the full file to ensure everything is correctly placed, including the
_resolve_oauth_creds_pathmethod:<tool_call> <function=bash_terminal> <parameter=command> sed -n '655,705p' /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me view the file around lines 655-705 to check the _resolve_oauth_creds_path method.
Assistant
The method looks correct. Let me check that the whole file is syntactically correct and also look at the entire flow to make sure everything is properly connected. Let me also check for edge cases - I should ensure that the OAuth credential path is properly handled when no credentials are provided.
Now let me run the existing tests to make sure the changes don't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && python -m pytest tests/unit/agents/installed/test_gemini_cli.py -v 2>&1 | head -50 </tool_call>
Assistant
Let me run the tests to verify my changes don't break anything.
Assistant
Let me run the tests with the proper Python path:
Assistant
The tests need the package to be installed. Let me try running the tests using uv, which is the package manager for this project:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && uv run pytest tests/unit/agents/installed/test_gemini_cli.py -v 2>&1 | head -80 </tool_call>
Assistant
Let me run the tests using uv to get the proper environment set up.
Assistant
The existing tests pass. Now let me also run the codex auth tests to ensure my implementation follows the same pattern correctly:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && uv run pytest tests/unit/agents/installed/test_codex_auth.py -v 2>&1 | head -80 </tool_call>
Assistant
Let me run the codex auth tests to verify my understanding is correct.
Assistant
Assistant
The test file was created. Now let me run these tests to verify my implementation is correct.
Assistant
The file wasn't created. Let me try again:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /harbor/tests/unit/agents/installed/ </tool_call>
Assistant
Let me check if the file was created in the right location.
Assistant
Assistant
The test file was created using a different method. Let me verify it was created and run the tests.
Assistant
Assistant
The Python command to create the test file was executed. Let me verify the file was created and run the tests.
Assistant
Assistant
Let me try a simpler approach to create the test file by using a Python script file:
Assistant
Now let me run the tests to verify my implementation:
Assistant
All tests pass! Now let me also run the existing tests to make sure the changes didn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && uv run pytest tests/unit/agents/installed/test_gemini_cli.py -v 2>&1 </tool_call>
Assistant
Let me run the existing tests to make sure the changes didn't break anything.
Assistant
All existing tests pass. Now let me also run the test_gemini_cli_mcp.py tests to make sure those still work:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && uv run pytest tests/unit/agents/installed/test_gemini_cli_mcp.py -v 2>&1 </tool_call>
Assistant
The tests are still running. Let me wait for the output to see if they pass.
Assistant
Great! All tests pass. Now let me review the changes I made to ensure the implementation is complete and correct. Let me view the final version of the modified file:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && git diff src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me check the diff to see all the changes I've made to the gemini_cli.py file.
Assistant
The changes look correct. Now let me also check if there are any other tests I should run to ensure the implementation is complete. Let me also check if there's any documentation that needs to be updated.
Let me also review the implementation to make sure it mirrors the codex auth pattern correctly:
- ✅ Added import for
parse_bool_env_value - ✅ Added
_resolve_oauth_creds_path()method that:- Returns
Noneby default (backward compatible) - Uses
GEMINI_OAUTH_CREDS_PATHif set to a specific file - Uses
~/.gemini/oauth_creds.jsonifGEMINI_FORCE_OAUTHis truthy - Raises
ValueErrorif the file doesn't exist when forced - Raises
ValueErrorif the path is invalid
- Returns
- ✅ Modified
run()method to:- Resolve OAuth creds path
- Create remote directory
- Upload OAuth creds file when present
- Chown the file to the agent user
- ✅ Added import for
Assistant
Let me verify the test file was created and check the diff again.
Assistant
Now I can see the test file exists. Let me check the git status to see all the changes I've made:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && git status </tool_call>
Assistant
Let me check the git status to see all the changes I've made.
Assistant
I can see both files have been modified. Let me now check if there's anything I may have missed by looking at the issue description again. The issue mentions that
gemini-clishould supportGEMINI_OAUTH_CREDS_PATHandGEMINI_FORCE_OAUTHenvironment variables to mirror the codex auth pattern.Let me verify the implementation is complete by running a broader set of tests to ensure nothing is broken:
Assistant
All 599 tests pass! The implementation is complete and correct. Let me now summarize what was done:
Summary of Changes
Modified Files:
- src/harbor/agents/installed/gemini_cli.py:
- Added import for
parse_bool_env_valuefromharbor.utils.env - Added
_resolve_oauth_creds_path()method to resolve OAuth credentials path based on environment variables - Modified
run()method to handle OAuth credentials injection
- Added import for
New Files:
- tests/unit/agents/installed/test_gemini_cli_auth.py: Unit tests for the OAuth credential injection functionality
Implementation Details:
The implementation mirrors the codex auth pattern:
- src/harbor/agents/installed/gemini_cli.py:
Assistant
Let me review the diff one more time and then submit the changes.
Assistant
The implementation is complete and all tests pass. Let me submit the changes:
Assistant
The tool call for submit needs to be a command. Let me try running it correctly:
<tool_call> <function=bash_terminal> <parameter=command> submit </tool_call>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.