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 code for implementing the OAuth credential injection for gemini-cli.
The issue description mentions:
codexagent has OAuth credential injection via~/.codex/auth.jsonwith env varsCODEX_AUTH_JSON_PATH/CODEX_FORCE_AUTH_JSONclaude-codeacceptsCLAUDE_CODE_OAUTH_TOKENgemini-clishould have equivalent support withGEMINI_OAUTH_CREDS_PATH/GEMINI_FORCE_OAUTH
Let me first explore the repository structure to understand the codebase.
Assistant
Let me explore the repository structure to understand the codebase. I'll start by looking at the directory contents.
<tool_call> <function=bash_terminal> <parameter=command> ls -la src/ </tool_call>
Assistant
I need to explore the src directory to understand the structure of the project.
Assistant
Let me explore the harbor directory to understand the structure of the agents.
<tool_call> <function=bash_terminal> <parameter=command> ls -la src/harbor/ </tool_call>
Assistant
Let me explore the harbor directory to see the structure of the codebase.
Assistant
Let me look at the agents directory to understand how agents are structured and find the gemini-cli and codex agents.
<tool_call> <function=bash_terminal> <parameter=command> ls -la src/harbor/agents/ </tool_call>
Assistant
Let me continue exploring the repository structure. I need to find the agents directory and understand how they're organized.
Assistant
Let me explore the installed directory where the agents might be installed.
<tool_call> <function=bash_terminal> <parameter=command> ls -la src/harbor/agents/installed/ </tool_call>
Assistant
Let me continue exploring the agents directory.
Assistant
Now I found the agents. Let me look at the codex.py file first to understand how OAuth credentials are handled there, since the issue says to mirror that implementation.
<tool_call> <function=bash_terminal> <parameter=command> cat src/harbor/agents/installed/codex.py </tool_call>
Assistant
I need to read the codex.py file to understand how the OAuth credentials are handled there.
Assistant
Now let me look at the gemini_cli.py file to understand the current implementation and see what needs to be added.
<tool_call> <function=bash_terminal> <parameter=command> cat src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me read the gemini_cli.py file to understand the current implementation.
Assistant
Now I have a good understanding of both the codex.py and gemini_cli.py implementations. Let me also look at the test file to understand what tests are needed for the OAuth credential injection.
Let me also check the tests directory to understand how tests are structured.
<tool_call> <function=bash_terminal> <parameter=command> find tests -name "codex" -o -name "auth" 2>/dev/null </tool_call>
Assistant
Let me search for test files related to codex and auth to understand the test patterns.
Assistant
Let me look at the test_codex_auth.py file to understand how the codex auth tests work.
Assistant
Now I have a good understanding of the structure. Let me also check the base.py file for the installed agents to understand how the _get_env method works and how extra_env is handled.
<tool_call> <function=bash_terminal> <parameter=command> cat src/harbor/agents/installed/base.py </tool_call>
Assistant
Let me read the base.py file to understand the agent base class and how extra_env is handled.
Assistant
Now I have a good understanding of the structure. Let me also check the utils/env.py to understand the parse_bool_env_value function.
<tool_call> <function=bash_terminal> <parameter=command> cat src/harbor/utils/env.py </tool_call>
Assistant
Let me check the env.py utility file for the parse_bool_env_value function.
Assistant
Now I have a good understanding of the codebase. Let me also check if there are any tests for gemini_cli to understand the existing tests.
<tool_call> <function=bash_terminal> <parameter=command> find tests -name "gemini" 2>/dev/null </tool_call>
Assistant
Now I understand the structure well. Let me check for any existing gemini_cli tests and then implement the OAuth credential injection for gemini-cli.
Assistant
Now I understand the structure. Let me look at the existing gemini_cli tests to understand the testing pattern.
<tool_call> <function=bash_terminal> <parameter=command> cat tests/unit/agents/installed/test_gemini_cli.py </tool_call>
Assistant
Let me read the gemini_cli test file to understand the testing pattern.
Assistant
Now I have a good understanding of the codebase. Let me implement the OAuth credential injection for gemini-cli. I need to:
- Add a
_resolve_oauth_creds_path()method similar to codex's_resolve_auth_json_path() - Modify the
run()method to handle OAuth credential injection
Let me first view the current gemini_cli.py run method more closely to understand where to add the changes:
- Add a
Assistant
Let me view the run method to see its full structure:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '649,720p' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me view the run method to understand its structure:
Assistant
Now I have a clear picture of how to implement the OAuth credential injection for gemini-cli. Based on the codex implementation and the issue description, I need to:
-
Add a
_resolve_oauth_creds_path()method that:- Checks for
GEMINI_OAUTH_CREDS_PATHenvironment variable (likeCODEX_AUTH_JSON_PATH) - Falls back to
~/.gemini/oauth_creds.jsonifGEMINI_FORCE_OAUTHis truthy (likeCODEX_FORCE_AUTH_JSON) - Returns None by default (backward compatible)
- Checks for
-
Modify the
run()method to:- Resolve the OAuth credentials path
- Upload the OAuth credentials file to the container if present
- Chown the file for the agent user (if default_user is set)
- Use the OAuth credentials instead of the API keys
Let me now implement these changes:
<tool_call> <function=bash_terminal> <parameter=command> cat src/harbor/agents/installed/gemini_cli.py | head -50 </tool_call>
-
Assistant
Now I understand the structure well. Let me implement the OAuth credential injection for gemini-cli. I'll:
- Add a
_resolve_oauth_creds_path()method similar to codex's implementation - Modify the
run()method to handle OAuth credential injection
- Add a
Assistant
Now let me apply the changes to the gemini_cli.py file. I'll add the
_resolve_oauth_creds_path()method and modify therun()method.Assistant
Let me add the
_resolve_oauth_creds_path()method after_build_settings_command:Assistant
Good, the
_resolve_oauth_creds_path()method was added successfully. Now I need to modify therun()method to use this new method to handle OAuth credentials. I need to add:- Resolve OAuth creds path
- Upload OAuth creds if present
- Chown the file for the agent user
- Use OAuth creds instead of env var auth
Let me find the current state of the run method and modify it:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '678,760p' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
I need to modify the
run()method to add OAuth credential injection support. Let me view the current run method and then make the necessary changes.Assistant
Now I need to modify the
run()method to add OAuth credential injection. The changes need to:- Add constants for the OAuth secrets directory
- Resolve OAuth creds path after the model variable
- Set up the OAuth secrets directory
- Upload OAuth creds if present and chown them
- Skip env var auth if using OAuth creds
Let me make the changes:
<tool_call> <function=bash_terminal> <parameter=command> sed -i '685,693s/^/ # Gemini CLI OAuth secrets directory\n _REMOTE_OAUTH_CREDS_DIR = Path("/tmp/gemini-oauth")\n _REMOTE_OAUTH_CREDS_PATH = _REMOTE_OAUTH_CREDS_DIR / "oauth_creds.json"\n/' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
The sed command didn't work as expected. Let me try a different approach - I'll use the edit command to modify the run method properly.
Assistant
The file wasn't modified by the sed command. Let me view the full file first to see the current state, and then make the changes properly.
<tool_call> <function=bash_terminal> <parameter=command> wc -l src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me check the current state of the file to see if it was modified correctly.
Assistant
The file was updated. Now I need to modify the
run()method to add OAuth credential injection. Let me view the current run method:Assistant
Now I need to modify the
run()method to add OAuth credential injection. Let me replace the method with one that includes OAuth support:Assistant
The changes have been applied successfully. Now let me verify the file looks correct by viewing the rest of the run method:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '760,800p' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me check the rest of the run method to ensure it's complete.
Assistant
The changes look complete. Now let me verify that the file syntax is correct by running Python to check for any syntax errors:
<tool_call> <function=bash_terminal> <parameter=command> python3 -m py_compile src/harbor/agents/installed/gemini_cli.py && echo "Syntax OK" </tool_call>
Assistant
Let me check the syntax of the file.
Assistant
The syntax is correct. Now let me run the existing tests to ensure my changes haven't broken anything:
Assistant
The test failed because the module isn't installed in the Python path. Let me try to install the project in development mode or use the right PYTHONPATH:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && pip install -e . 2>&1 | tail -20 </tool_call>
Assistant
Let me install the package properly and run the tests.
Assistant
Now let me run the tests again.
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && pip install pytest-asyncio 2>&1 | tail -5 </tool_call>
Assistant
The package installation succeeded. Let me try running the tests again now that the package is installed.
Assistant
All existing tests pass. Now let me run the codex auth tests to see the testing pattern for the OAuth credentials, and then create similar tests for gemini-cli.
Let me also check if there are existing tests for the codex auth pattern that I can mirror:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && python -m 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 see how they work.
Assistant
All the codex auth tests pass. Now let me create similar tests for the gemini-cli OAuth credential injection. I'll mirror the test patterns from test_codex_auth.py.
Assistant
Now let me run the new tests to verify my implementation is correct:
Assistant
The tests are failing because
parse_bool_env_valueis not imported. I need to add the import at the top of the file. Let me check the current imports:Assistant
I need to add the import for
parse_bool_env_value. Let me fix the import statement:Assistant
Now let me verify the import was added correctly:
Assistant
Now let me run the tests again to verify the fix:
Assistant
The test is failing because the path comparison expects a string but gets a PosixPath. Let me fix the test to handle the path type correctly. This is a minor test issue, not an implementation issue.
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's|assert mock_env.upload_file.call_args[0][1] == "/tmp/gemini-oauth/oauth_creds.json"|assert str(mock_env.upload_file.call_args[0][1]) == "/tmp/gemini-oauth/oauth_creds.json"|' tests/unit/agents/installed/test_gemini_cli_auth.py </tool_call>
Assistant
Let me verify the fix was applied:
Assistant
The sed command didn't apply correctly. Let me try again with proper escaping.
<tool_call> <function=bash_terminal> <parameter=command> cat tests/unit/agents/installed/test_gemini_cli_auth.py | head -140 | tail -15 </tool_call>
Assistant
Let me view and fix the test file:
Assistant
Let me use sed to fix line 132:
Assistant
Let me use a different approach - I'll recreate the test file with the fix:
Assistant
Now let me run the tests again to verify all tests pass:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && python -m pytest tests/unit/agents/installed/test_gemini_cli_auth.py -v 2>&1 | head -50 </tool_call>
Assistant
Let me run the tests again to verify all tests pass.
Assistant
All tests pass! Now let me also run the original gemini_cli tests and codex tests to ensure I didn't break anything:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && python -m pytest tests/unit/agents/installed/test_gemini_cli.py tests/unit/agents/installed/test_codex_auth.py -v 2>&1 | tail -30 </tool_call>
Assistant
Let me run the tests and make sure all existing tests pass.
Assistant
All existing tests pass. Now let me also verify that my implementation follows the same pattern as the codex implementation by viewing the current state of the gemini_cli.py file and comparing with the codex implementation.
Let me also view the changes I made to the gemini_cli.py 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 git diff to see what changes were made to gemini_cli.py.
Assistant
The changes look correct. Now let me also check the test file that was added:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && git status </tool_call>
Assistant
Let me check the git status to see what files were modified or added.
Assistant
Now let me verify the implementation is complete by reviewing the changes. The implementation includes:
- Added
parse_bool_env_valueimport fromharbor.utils.env - Added
_resolve_oauth_creds_path()method that mirrors the codex implementation - Modified the
run()method to:- Resolve OAuth credentials path
- Upload the OAuth credentials file if present
- Chown the file for the agent user (if default_user is set)
- Pass the OAuth credentials path via environment variables
- Fall back to env var auth if no OAuth credentials are found
- Clean up the OAuth secrets directory after the run
The implementation also includes:
- A new test file
tests/unit/agents/installed/test_gemini_cli_auth.pywith tests mirroring the codex auth tests
Let me now run a comprehensive test to make sure everything works correctly, and also check if there are any other tests in the repository that might be affected:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && python -m pytest tests/unit/agents/installed/ -v -k "gemini or codex" 2>&1 | tail -50 </tool_call>
- Added
Assistant
Let me run a comprehensive test to verify all the changes work correctly.
Assistant
I see there's a bug in my implementation. The error
TypeError: cannot unpack non-iterable NoneType objecton line 747 suggests thatself._build_settings_command(model)is returningNoneinstead of a tuple.Looking at the error, the problem is that when
settings_commandisNone, the original code handled it with an if check:if settings_command:. But when we changed the order to call_build_settings_commandearlier, we didn't preserve this check correctly.Let me look at the current code and fix this issue:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '740,760p' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me view the code around line 747 to understand the issue better.
Assistant
The issue is that
_build_settings_command(model)returns a tuple(config, model_alias). IfconfigisNone, the function returns(None, model_alias). But if both areNone, it returns(None, None)which is valid. The error occurs when the return value isNoneinstead of a tuple.Wait, looking at the error more closely, it says
cannot unpack non-iterable NoneType object. This means_build_settings_commandis returningNoneinstead of a tuple. Let me check the method:<tool_call> <function=bash_terminal> <parameter=command> sed -n '637,650p' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me check the
_build_settings_commandmethod:Assistant
Let me view the method definition:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '637,650p' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
The grep shows there's something wrong with how I'm viewing the lines. Let me check the actual file content around that area more carefully.
Assistant
I see the issue! The
_build_settings_commandmethod is missing thereturnstatement. The command variable is created but never returned. Let me fix this:Assistant
I see the issue! The
_build_settings_commandmethod is missing thereturn command, model_aliasstatement. The edit I made earlier accidentally removed this line. Let me fix it:Assistant
I see that there's now a duplicate line 646 (
escaped = shlex.quote(json.dumps(config, indent=2))) and a duplicate definition of_resolve_oauth_creds_pathstarting at lines 650 and 652. Let me fix these issues.First, let me check what happened more carefully:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '640,685p' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me check the duplicate lines and fix them.
Assistant
I see the issue - there's a duplicate line and duplicate method definition. Let me fix this by removing the extra lines:
Assistant
Now let me also remove the duplicate method definition on line 650 (which is now 649 after the deletion):
Assistant
Let me remove the empty line and the duplicate function signature:
<tool_call> <function=bash_terminal> <parameter=command> sed -i '648,649d' src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me verify the fix was applied:
Assistant
The deletion didn't work properly. Let me use the edit command to fix this properly. I need to remove the empty line 648 and the duplicate function signature on line 649:
Assistant
Let me use the edit command to remove lines 649 (the empty line) and line 650 (the duplicate function signature):
Assistant
Great, the duplicate lines have been fixed. Now let me verify the syntax is correct and run the tests again:
<tool_call> <function=bash_terminal> <parameter=command> python3 -m py_compile src/harbor/agents/installed/gemini_cli.py && echo "Syntax OK" </tool_call>
Assistant
Let me verify the syntax is correct.
Assistant
The syntax is correct. Now let me run the tests again to verify all tests pass:
Assistant
All 45 tests pass! Now let me also run the MCP tests that were failing before to make sure they're fixed now:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && python -m pytest tests/unit/agents/installed/test_gemini_cli_mcp.py -v 2>&1 | tail -30 </tool_call>
Assistant
Let me run the MCP tests to verify they pass now.
Assistant
All MCP tests pass! Now let me run all the gemini and codex related tests to make sure everything works correctly:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && python -m pytest tests/unit/agents/installed/ -v -k "gemini or codex" 2>&1 | tail -40 </tool_call>
Assistant
Let me run the comprehensive test to make sure all gemini and codex related tests pass.
Assistant
All 80 tests pass! The implementation is complete. Let me also check the git diff to see the final changes:
<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 git diff to see the final changes made to the gemini_cli.py file.
Assistant
The implementation looks complete. Let me summarize what was done:
- Added
parse_bool_env_valueimport fromharbor.utils.env - Added
_resolve_oauth_creds_path()method that mirrors the codex implementation - Modified the
run()method to handle OAuth credential injection - Created tests in
test_gemini_cli_auth.py
Let me now verify the final status and submit the changes.
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && git status </tool_call>
- Added
Assistant
Let me verify the final status and then submit the changes.
Assistant
Let me run a final comprehensive test to make sure all tests pass before submitting.
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && source .venv/bin/activate && python -m pytest tests/unit/agents/installed/ -v -k "gemini or codex" --tb=short 2>&1 | tail -20 </tool_call>
Assistant
Let me run a final comprehensive test to make sure all tests pass before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.