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 the codebase and how it's organized. I need to understand:
- The overall structure of the repository
- How the codex agent handles OAuth credentials
- How the gemini-cli agent currently works
- What needs to be implemented to mirror the codex auth pattern for gemini-cli
Let me begin by exploring the repository.
Assistant
Let me explore the structure more broadly to find the gemini-cli agent and the codex auth implementation.
Assistant
Let me explore the agents directory in src/ and the adapters to understand the structure better.
Assistant
The repository has a
src/harbordirectory with Python code, and there's also anadaptersdirectory. Let me look at both to understand how agents are implemented.Assistant
Let me look at the agents directory and also explore adapters.
Assistant
Let me explore the installed agents and adapters to find gemini-cli and codex implementations.
Assistant
I found the key files. Let me look at both
gemini_cli.pyandcodex.pyto understand the current implementation.Assistant
Now let me look at the gemini_cli.py 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 use the proper tool call format to read the file.
Assistant
Now let me look at the codex auth tests to understand what pattern I need to mirror.
Assistant
Let me look at the codex auth test file to understand the pattern I need to mirror for gemini-cli.
Assistant
Now let me check the base agent class to understand
_get_envand howparse_bool_env_valueworks.Assistant
Now let me look at the base agent class to understand the
_get_envmethod and how extra_env is used.Assistant
Now let me look at the base agent's
_get_envmethod and also check the test directory structure.Assistant
Let me also check the existing test file structure for the agents:
Assistant
Let me also check how claude_code handles its OAuth token:
Assistant
Now I have a thorough understanding of the codebase. Let me examine the full gemini_cli.py run method to understand the exact implementation needed:
Assistant
Now I have a thorough understanding. Let me look at the exact line numbers of the gemini_cli.py run method:
Assistant
Now I have a thorough understanding of the codebase. Let me implement the OAuth credential injection for
gemini_cli.py, mirroring the codex auth pattern. I'll need to:- Add a
_resolve_oauth_creds_pathmethod toGeminiCli - Modify the
runmethod to handle OAuth credential injection - Create tests mirroring
test_codex_auth.py
Let me start by implementing the changes:
- Add a
Assistant
Now I need to implement the changes. Let me first add the import for
parse_bool_env_valueand the_resolve_oauth_creds_pathmethod:Assistant
I need to use the bash_terminal tool to execute shell commands. Let me use sed to make the changes.
Assistant
Let me use sed to add the import for
parse_bool_env_value:Assistant
Wait, I think I need to use the
bash_terminaltool for commands. Let me try a different approach to add the import.Assistant
The sed command inserted the import line multiple times incorrectly. Let me restore the file and use a more careful approach.
Assistant
Let me check the file is restored.
Assistant
Good, the file is restored. Now let me use Python to make the changes properly:
Assistant
Let me verify the import was added correctly and then continue with the rest of the implementation.
Assistant
Now let me find the line number where the
_resolve_auth_json_pathmethod ends in codex.py so I can mirror it, and also find the right place in gemini_cli.py to insert the new method:Assistant
Now I need to add the
_resolve_oauth_creds_pathmethod to the GeminiCli class. Looking at the codex.py implementation, the method should be placed somewhere logical. Let me look at the structure of gemini_cli.py to find the best place to insert it.Looking at the structure:
_build_register_skills_command(line 583)_build_settings_config(somewhere around there)_build_settings_commandasync def run(line 650)
The
_resolve_oauth_creds_pathmethod should be placed near the_build_settings_commandmethod, beforerun. Let me look at what's between line 583 and 650.Assistant
Now let me add the
_resolve_oauth_creds_pathmethod and modify therunmethod. I'll do this with a Python script:Assistant
Let me verify the method was inserted correctly.
Assistant
Good, the method was inserted correctly. Now I need to modify the
runmethod to use OAuth credentials when available. Let me look at the current run method:Assistant
Now I need to modify the
runmethod to use OAuth credentials when available. Let me make the change:Assistant
Let me verify the changes were applied correctly:
Assistant
I notice there's a bug in my code - the
exec_as_rootcommand for creating the secrets directory is incorrect. Let me fix it to match the codex pattern more closely:Assistant
Now let me verify the complete run method is correct:
Assistant
The implementation looks correct. Now let me create the test file mirroring the codex auth tests. First, let me verify the Python syntax is valid:
Assistant
The syntax is valid. Now let me create the test file mirroring the codex auth tests:
Assistant
Now let me run the tests to verify everything works:
Assistant
The test needs the proper Python path. Let me check how existing tests are run:
Assistant
The test couldn't import the harbor module because the Python path isn't configured. Let me check how other tests handle this.
Assistant
The test is failing to import. Let me check if there's a virtual environment or conda environment that needs to be used.
Assistant
I need to run the tests from within the virtual environment. Let me try activating it first.
Assistant
The existing codex auth tests pass. Now let me run my new gemini_cli_auth tests:
Assistant
All 18 tests pass. Now let me run the existing gemini_cli tests to make sure I haven't broken anything:
Assistant
All existing gemini_cli tests pass. Let me also run the gemini_cli_mcp tests to make sure nothing was affected:
Assistant
All existing gemini_cli tests pass. Let me also run all the agents/installed tests to be thorough:
Assistant
All 600 tests pass. Let me verify the final state of my changes:
Assistant
The tests all pass. Let me now verify my changes are complete and correct. Let me review the full diff to make sure everything is in order.
Assistant
The diff looks clean and mirrors the codex auth pattern correctly. Let me also verify the test file exists:
Assistant
The implementation is complete. Let me verify all tests pass one more time before submitting:
Assistant
All 58 tests pass, including:
- 18 new
test_gemini_cli_auth.pytests (mirroring the codex auth tests 1:1) - 9 existing
test_gemini_cli.pytests - 13 existing
test_gemini_cli_mcp.pytests - 18 existing
test_codex_auth.pytests
The implementation is complete. Here's a summary of what was done:
Summary of Changes
1.
src/harbor/agents/installed/gemini_cli.py- Added import for
parse_bool_env_valuefromharbor.utils.env - Added
_resolve_oauth_creds_path()method that mirrors the codex_resolve_auth_json_path()method:GEMINI_OAUTH_CREDS_PATH=<path>→ use that specific oauth_creds.json fileGEMINI_FORCE_OAUTH=<truthy>→ use~/.gemini/oauth_creds.json
- 18 new
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.