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, mirroring the codex pattern.
Assistant
Let me explore more to understand the structure, especially looking for codex auth and gemini-related code.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /harbor/ </tool_call>
Assistant
The user wants me to continue exploring the repository structure. I need to list the contents of the /harbor directory to understand the repository layout. Let me use the bash_terminal tool to do this.
Assistant
Let me explore the adapters directory and look for the codex and gemini-related code:
Assistant
The exit code 1 from grep means no matches were found. Let me look at all adapters to understand the structure better.
Assistant
The adapters directory doesn't seem to contain codex or gemini. Let me look at the src directory and other areas of the repository to understand the structure better. The issue mentions "gemini-cli" and "codex" agents, so I need to find where these agent implementations are.
Assistant
Let me look for the agents directory which likely contains codex and gemini implementations.
Assistant
Let me explore the agents directory to understand the structure.
Assistant
Let me look at the installed agents directory to find codex and gemini implementations.
Assistant
I found both
codex.pyandgemini_cli.py. Let me read the codex implementation first to understand the OAuth pattern.Assistant
Now let me look at the gemini_cli.py to understand its current implementation:
<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me read the gemini_cli.py file to understand its current implementation:
Assistant
Now let me look at the codex auth tests:
Assistant
Let me read the codex auth test file:
Assistant
Now let me look at the base class to understand how
_get_envworks:Assistant
Let me see more of the base.py file, especially the
_get_envmethod:<tool_call> <function=bash_terminal> <parameter=command> grep -n "_get_env|extra_env" /harbor/src/harbor/agents/installed/base.py </tool_call>
Assistant
I need to look at the base.py file to understand how _get_env works. Let me search for it.
Assistant
Let me look at the
parse_bool_env_valueutility:Assistant
Now let me look at the test conftest to understand the fixtures:
Assistant
Now I have a clear understanding of the codebase. Let me also check the gemini directory structure and how the
runmethod works more carefully:Assistant
Now I have a complete understanding of both the codex auth implementation and the gemini_cli implementation. Let me now implement the OAuth credential injection for gemini-cli, mirroring the codex pattern.
First, let me see the existing gemini 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. I'll need to:
- Add
_resolve_oauth_creds_path()method togemini_cli.py - Modify the
run()method to handle OAuth credential injection - Create tests mirroring
test_codex_auth.py
Let me start with the
gemini_cli.pychanges:- Add
Assistant
Let me see the exact line numbers of the
runmethod in gemini_cli.py:Assistant
Now I have a clear understanding. Let me implement the OAuth credential injection for gemini-cli. I'll:
- Add constants for remote OAuth paths
- Add
_resolve_oauth_creds_path()method mirroring codex - Modify the
run()method to handle OAuth credential injection
Let me first see the exact lines of the
installmethod end and the_save_imagestart:Assistant
Now I'll implement the OAuth credential injection for gemini-cli. Let me add the necessary changes:
Assistant
Now I have a complete understanding. Let me implement the OAuth credential injection for gemini-cli. I'll:
- Add class constants for remote OAuth paths
- Add
_resolve_oauth_creds_path()method mirroring codex - Modify the
run()method to handle OAuth credential injection - Create tests mirroring
test_codex_auth.py
Let me start with the implementation:
Assistant
Let me fix the edit command. I need to look at the current line 1 and update the import.
Assistant
Let me try with the proper syntax for the edit command:
Assistant
I need to update the import statement to include
PurePosixPath. Let me use sed for this since the edit command seems to have issues with the JSON format.Assistant
Let me verify the import change was successful.
Assistant
Now let me add the class constants for remote OAuth paths. I need to find the right location after the class definition:
Assistant
Good. Now let me add the class constants for remote OAuth paths after
_image_counter:Assistant
Let me verify the change and then find the right location to add the
_resolve_oauth_creds_path()method:Assistant
Now let me add the
_resolve_oauth_creds_path()method. Let me find the right location (after__init__and beforeinstall):Assistant
Let me check where
_validate_reasoning_effortends to add the new method there:Assistant
I need to continue adding the OAuth credential injection functionality to gemini_cli.py. Let me add the
_resolve_oauth_creds_path()method after_validate_reasoning_effort:Assistant
Now let me insert this method into gemini_cli.py after the
_validate_reasoning_effortmethod:Assistant
Now I'll insert the
_resolve_oauth_creds_path()method after line 99 (after_validate_reasoning_effort):Assistant
Let me verify the method was inserted correctly and then continue with modifying the
run()method:Assistant
The
_resolve_oauth_creds_path()method was inserted successfully. Now I need to modify therun()method to use OAuth credential injection. Let me find therun()method:Assistant
Let me look at the full run method to understand how to modify it:
Assistant
Now I need to modify the
run()method to handle OAuth credential injection. Let me look at the current auth_vars section more closely and then replace it with the OAuth-aware version:Assistant
Now I need to replace the auth_vars section with OAuth-aware code. Let me create the replacement code:
Assistant
Let me look at the exact line numbers to replace:
Assistant
Now let me replace the old auth_vars section with the new OAuth-aware code. I'll need to delete lines 699-719 and insert the new code:
Assistant
Now let me insert the new OAuth-aware code at line 699:
Assistant
Let me verify the changes:
Assistant
I see there's a duplicate line for
env = {"GEMINI_CLI_TRUST_WORKSPACE": "true"}. Let me fix that:Assistant
Let me verify the duplicate line was removed:
Assistant
Now let me check if
EnvironmentPathsis imported (it's used in the mkdir command):Assistant
Let me check if
EnvironmentPathsis imported in the gemini_cli.py file:Assistant
I need to add the
EnvironmentPathsimport since it's used in the new code. Let me add it:Assistant
Let me verify the import was added correctly:
Assistant
Good, the import was added. Now let me check the complete
run()method to verify everything is in order:Assistant
Let me see the end of the file to make sure it's complete:
Assistant
The file looks complete. Let me verify the syntax is correct:
Assistant
Now let me run the existing gemini tests to ensure I haven't broken anything:
Assistant
Let me check how to run the tests properly with the virtual environment:
Assistant
All existing tests pass. Now let me create the test file for the OAuth credential injection in gemini_cli.py, mirroring the
test_codex_auth.pypattern.Assistant
Now let me create the test file for the OAuth credential injection in gemini_cli.py, mirroring the
test_codex_auth.pypattern:Assistant
Now let me run the new OAuth tests to verify they work:
Assistant
All 17 tests pass. Let me also run all the existing gemini tests to make sure everything still works:
Assistant
All tests pass. Let me also run the codex auth tests to make sure they still pass (I didn't modify them, but I want to verify nothing is broken):
<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 </tool_call>
Assistant
Let me continue by running the codex auth tests to ensure nothing is broken:
Assistant
All codex auth tests pass too. Let me run a broader set of tests to make sure nothing is broken across the entire agent installed tests:
Assistant
All 599 tests pass. Let me now verify the complete implementation by reviewing the changes made:
Assistant
The user is waiting for me to verify the implementation and review the changes made. I need to check the git diff to see the changes I've made to the gemini_cli.py file and verify the implementation is complete and correct.
Assistant
Let me verify the test file exists and summarize the changes:
Assistant
I've successfully implemented the OAuth credential injection for gemini-cli, mirroring the codex pattern. Here's a summary of all the changes:
Changes Made
1. Modified
src/harbor/agents/installed/gemini_cli.py- Added imports:
PurePosixPathfrompathlibandEnvironmentPathsfromharbor.models.trial.paths - Added class constant:
_REMOTE_OAUTH_SECRETS_DIR = PurePosixPath("/tmp/gemini-oauth-secrets") - Added
_resolve_oauth_creds_path()method: Resolves OAuth credentials with the same priority logic as codex:
- Added imports:
Assistant
Let me check what files have been changed and what new files have been created. The user wants me to submit the changes. Let me verify the git status to see all the changes.
Assistant
The user is asking me to submit my changes. I've completed the implementation of OAuth credential injection for gemini-cli, mirroring the codex pattern. Let me submit the 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.