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 the
gemini-cliagent and thecodexagent's OAuth implementation that I need to mirror.Assistant
Let me explore the repository structure more, especially looking for agents, adapters, and especially the codex auth implementation.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /harbor/ </tool_call> <tool_call> <function=bash_terminal> <parameter=command> find /harbor -type d -name "agents" | head -10 </tool_call> <tool_call> <function=bash_terminal> <parameter=command> find /harbor -type d -name "adapters" | head -10 </tool_call>
Assistant
The user wants me to explore the repository structure. Let me run the commands one at a time.
Assistant
The user wants me to explore the repository structure to understand how to implement OAuth support for gemini-cli. Let me start by exploring the directory structure to understand the codebase.
Assistant
Let me explore more to find the gemini-cli and codex adapters.
Assistant
The grep command didn't return results because exit code 1. Let me try a different approach.
Assistant
Let me try searching differently, perhaps using find.
Assistant
Let me search more broadly for gemini-cli related files:
Assistant
Let me search for codex-related code and explore the src directory structure to understand how adapters work:
Assistant
The user wants me to implement OAuth support for gemini-cli. Let me explore the repository structure to understand:
- Where adapters live
- How the codex auth pattern works
- Where gemini-cli related code exists
Let me explore the src directory and understand the project structure better.
Assistant
Let me explore the src/harbor directory to understand the codebase structure.
Assistant
The user wants me to implement OAuth support for gemini-cli, mirroring the codex auth pattern. Let me continue exploring the repository structure to understand:
- How adapters work in this codebase
- Where codex auth is implemented
- Where gemini-cli related code exists or should be added
Let me continue exploring.
Assistant
Good, I can see there's an
agentsdirectory. Let me explore it to find the codex and gemini-cli agents.Assistant
The user wants me to implement OAuth support for gemini-cli. Let me continue exploring the agents directory to find codex and gemini-cli related code.
Assistant
Now I found the relevant files. Let me read the codex.py to understand the auth pattern, then gemini_cli.py to see its current state.
Assistant
Now let me read the gemini_cli.py file to understand its current state:
Assistant
Now let me look at the base agent class and the codex auth tests to understand the patterns:
Assistant
Now I have a good understanding of the codebase. Let me now look at the base agent class to understand
_get_env:<tool_call> <function=bash_terminal> <parameter=command> grep -A 5 "def _get_env" /harbor/src/harbor/agents/installed/base.py </tool_call>
Assistant
Let me continue exploring the codebase to understand the
_get_envmethod and find existing codex auth tests:Assistant
Good. Let me understand the base class better to see how
_get_envworks. This is important because the codex agent uses_get_envrather thanos.environfor reading environment variables.Assistant
Now let me find the codex auth tests to understand what tests I need to port:
Assistant
Now I have a good understanding of the repository. Let me read the codex auth test file to understand the patterns I need to mirror:
Assistant
Now I have a complete understanding of the codebase. Let me also look at the
parse_bool_env_valuefunction to understand how it works:Assistant
Now I have a complete understanding. Let me check if there are existing tests for gemini_cli:
Assistant
Now I have a complete understanding of the codebase. Let me implement the OAuth support for gemini-cli by:
- Adding
_resolve_oauth_creds_path()method togemini_cli.py - Modifying the
run()method to handle OAuth credential injection - Creating tests ported from the codex auth tests
Let me start by implementing the changes to
gemini_cli.py:- Adding
Assistant
Let me check the imports in gemini_cli.py and understand the current structure better:
Assistant
Now I have a complete understanding of the codebase. Let me implement the OAuth support for gemini-cli. I need to:
- Add the
parse_bool_env_valueimport - Add
_resolve_oauth_creds_path()method mirroring codex's_resolve_auth_json_path() - Modify the
run()method to handle OAuth credential injection
Let me start by adding the import:
- Add the
Assistant
Let me try a different approach. I need to use the
editcommand properly with LINE_RANGE parameter.The issue is that my tool call format isn't correct. Let me use the proper format.
Assistant
Let me try a different approach - first open the file:
Assistant
The tool calls are failing because the environment is expecting a specific format. Let me look at the function definitions more carefully and use the proper format. The tool definition says:
edit [OPTIONS] LINE_RANGE [REPLACEMENT_TEXT]Options include
--file PATH. Let me try using the proper format with all parameters as part of the command string.Wait, looking at the error messages more carefully:
- "Cannot extract command from tool call"
This suggests the tool call format isn't being parsed correctly. Let me look at how the tools are being called. I think the issue might be with how I'm formatting the tool call. Let me try a simpler approach first.
Assistant
Good, I can see the current state of the file. Let me continue working on the implementation. I'll need to:
- Add the
parse_bool_env_valueimport - Add a
_resolve_oauth_creds_path()method - Modify the
run()method to handle OAuth credential injection - Create tests
Let me first check what tests fixtures are available:
- Add the
Assistant
Let me find where the conftest.py is that defines the
temp_dirfixture:Assistant
Now I have a complete understanding. Let me use
sedto make the edits since the edit tool isn't working as expected.Assistant
Let me continue exploring the repository to understand the current structure of the gemini_cli.py file and implement the OAuth support:
Assistant
Let me continue exploring the structure to understand where to make the changes:
Assistant
Now I understand the repository structure. I need to:
- Add
parse_bool_env_valueimport to gemini_cli.py - Add
_resolve_oauth_creds_path()method - Modify
run()to handle OAuth credential injection - Create tests
Let me make the changes step by step:
- Add
Assistant
Now let me verify the import was added correctly and check the file structure:
Assistant
Good, the import was added correctly. Now let me add the
_resolve_oauth_creds_path()method. Let me find the right place to add it - just before therun()method:Assistant
Now I need to add the
_resolve_oauth_creds_path()method and modify therun()method. Let me find the exact location:Assistant
Let me use a Python script to make the changes more precisely:
Assistant
Now let me verify the changes were applied correctly:
Assistant
Good, the method was added. Let me verify the full changes:
Assistant
Let me verify the indentation is correct for the
_resolve_oauth_creds_pathmethod:Assistant
The indentation looks correct. Now let me verify the Python syntax is valid:
Assistant
The syntax is valid. Now let me run the existing tests for gemini_cli to ensure nothing is broken:
Assistant
The tests need the harbor package to be installed. Let me check how to run tests:
Assistant
Let me try running tests with the virtual environment:
Assistant
All existing gemini_cli tests pass. Now let me create the test file for the new OAuth functionality, mirroring the codex auth tests:
Assistant
Now let me run the tests to verify the implementation works:
Assistant
All 20 tests pass. Let me also run the existing gemini_cli tests and codex auth tests to ensure everything still works:
Assistant
All 27 tests pass (9 existing gemini_cli tests + 14 codex auth tests + 20 new gemini_cli auth tests = 43 total, but some overlap in counts). Let me verify the final state of the implementation and check for any edge cases:
Assistant
The user wants me to verify my implementation is complete. Let me check the git status to see what files have been modified and what new files have been created. I should also run a broader test to make sure I haven't broken anything.
Assistant
Let me verify the full implementation and run a broader test suite to ensure everything is working correctly:
Assistant
The user wants me to verify the implementation is complete. Let me check the current state and run all related tests to confirm everything works correctly.
Assistant
All 47 tests pass. Let me also run the MCP tests for gemini_cli to make sure I haven't broken anything else:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.