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.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 analyze the issue. The task is to add OAuth credential injection support to the
gemini-cliagent, mirroring the pattern used in thecodexagent. Let me start by exploring the repository structure to understand the codebase.Assistant
This is a larger repository. Let me look for the gemini-cli agent and the codex agent to understand the pattern I need to mirror.
Assistant
Let me search for the agents module in the source code.
Assistant
Now I can see the agents.py file with the
CodexCLIclass. But the issue mentions a separate OAuth auth flow. Let me search for the codex auth pattern and the gemini-cli agent.Assistant
Let me try a broader search.
Assistant
It seems like the OAuth/auth related code isn't in the agents.py file. Let me search for the codex auth test file and gemini-cli related code.
Assistant
Let me look at the test files for agents and also search for gemini-cli related code.
Assistant
Now let me look for the runner.py which likely orchestrates the agents and may have environment variable handling:
Assistant
I need to search more broadly for gemini-cli and codex auth patterns. Let me look for test files and session.py.
Assistant
Let me search more broadly for gemini-cli and codex auth patterns.
<tool_call> <function=bash_terminal> <parameter=command> grep -rn "gemini|GEMINI" /harbor --include="*.py" --exclude-dir=".venv" | head -30 </tool_call>
Assistant
Let me try the search again with the proper format.
Assistant
Now I can see there's a gemini-cli related file at
/harbor/src/harbor/agents/installed/antigravity_cli.py. Let me also look for the codex auth pattern. Let me search for the codex auth pattern and the antigravity_cli.py file.Assistant
Now I found the key files. Let me look at both the codex.py auth pattern and the antigravity_cli.py (gemini-cli) file.
Assistant
Now let me look at the antigravity_cli.py file which is the gemini-cli agent:
Assistant
Now I understand the pattern. Let me look at the base class to understand the helper methods available:
Assistant
Now I understand the codebase structure. I need to:
- Add OAuth credential injection support to the
AntigravityCli(gemini-cli) agent, mirroring theCodexpattern. - The codex pattern uses
_resolve_auth_json_path()to resolve an auth file, then uploads it to a remote secrets directory, and creates a symlink. - For gemini-cli, I need to:
- Add
_resolve_oauth_creds_path()method - Add
GEMINI_OAUTH_CREDS_PATHandGEMINI_FORCE_OAUTHenvironment variable support - Default OAuth creds path is
~/.gemini/oauth_creds.json - Upload the OAuth creds file and symlink it in the environment
- Add
Let me also check if there are tests for the codex auth pattern that I should mirror.
<tool_call> <function=bash_terminal> <parameter=command> find /harbor/tests -name "*.py" -exec grep -l "codex|auth" {} ; </tool_call>
- Add OAuth credential injection support to the
Assistant
Let me fix my command syntax.
Assistant
The command executed correctly. Let me continue searching for the test files related to codex auth.
Assistant
Let me search for any test files related to codex auth or gemini-cli that might already exist, or look for test patterns I should follow.
Assistant
Found the key files. Let me examine the codex auth tests and the gemini-cli tests.
Assistant
Now let me look at the existing gemini-cli test file:
Assistant
I see this test file references
GeminiClifromharbor.agents.installed.gemini_cli, notAntigravityCli. Let me check if there's a separate gemini_cli.py file.Assistant
There's a separate
gemini_cli.pyfile. Let me examine it.Assistant
Now I have a complete picture of the codebase. Let me summarize what I need to do:
-
The
GeminiCliagent (in/harbor/src/harbor/agents/installed/gemini_cli.py) currently only supports API key auth via environment variables (GEMINI_API_KEY,GOOGLE_API_KEY, etc.) -
The
Codexagent (in/harbor/src/harbor/agents/installed/codex.py) has an OAuth/auth.json pattern that I need to mirror:_resolve_auth_json_path()method that checks:CODEX_AUTH_JSON_PATHenv var for explicit pathCODEX_FORCE_AUTH_JSONenv var to use~/.codex/auth.json
-
Assistant
The command executed but no output was shown. Let me try again with a different approach.
Assistant
Now I have a complete understanding. Let me implement the OAuth credential injection for
GeminiCli. I'll:- Add
_resolve_oauth_creds_path()method togemini_cli.py - Modify the
run()method to upload and symlink OAuth credentials - Create test file
test_gemini_cli_auth.pymirroringtest_codex_auth.py
Let me start by adding the import and the
_resolve_oauth_creds_pathmethod:- Add
Assistant
Now I have a clear picture. I need to:
- Add the
parse_bool_env_valueimport fromharbor.utils.envtogemini_cli.py - Add class-level constants for remote paths (like Codex has)
- Add
_resolve_oauth_creds_path()method - Modify
run()to handle OAuth credential injection - Create
test_gemini_cli_auth.pymirroringtest_codex_auth.py
Let me implement these changes now.
- Add the
Assistant
Let me try the correct syntax for the open command.
Assistant
The file has 715 lines. Let me look at the full file to understand its structure better, then make my edits. I need to:
- Add
PurePosixPathimport andparse_bool_env_valueimport - Add class-level constants for remote gemini secrets dir
- Add
_resolve_oauth_creds_path()method - Modify
run()to handle OAuth credential injection
Let me first look at the key sections of the file.
- Add
Assistant
I need to edit the gemini_cli.py file to add OAuth credential injection support. Let me start by making the necessary changes.
First, let me add the necessary imports and class-level constants:
Assistant
The edit command needs a file to be open first. Let me use the bash command to edit the file instead.
Assistant
Let me continue with the edits. I need to add the parse_bool_env_value import and then make the other changes to the file.
Assistant
Let me continue editing the gemini_cli.py file. I need to:
- Add class-level constants for remote gemini secrets dir
- Add _resolve_oauth_creds_path() method
- Modify run() to handle OAuth credential injection
Let me use sed to add the class-level constants after the CLI_FLAGS definition.
Assistant
The command executed but the output was cut off. Let me check what line the CLI_FLAGS ends on so I can add the remote path constants after it.
Assistant
Now I'll add the remote path constants after line 52 (after the CLI_FLAGS closing bracket). Let me insert them using sed.
Assistant
tool_response
Assistant
Now I need to add the
_resolve_oauth_creds_path()method. Let me find a good place to insert it - I'll put it before the_build_register_skills_commandmethod.Assistant
Let me see the lines before _build_register_skills_command:
Assistant
I'll insert the
_resolve_oauth_creds_path()method right before_build_register_skills_commandat line 586.Assistant
The command executed successfully. Now I need to modify the
run()method to handle OAuth credential injection. Let me first check the currentrun()method.Assistant
I need to modify the
run()method to:- Resolve OAuth creds path
- Create remote directories
- Upload OAuth creds if available
- Symlink OAuth creds to
~/.gemini/oauth_creds.json - Clean up secrets at the end
Let me create a Python script to do the complex edit:
Assistant
The patch script ran successfully. Now I need to verify the changes were applied correctly and then create the test file for OAuth credentials. Let me check the modified run() method first.
Assistant
The run() method is now correctly updated. Let me also verify the _resolve_oauth_creds_path method and the imports are correct:
Assistant
Good, the imports are in place. Now let me verify the
_resolve_oauth_creds_pathmethod was added correctly:Assistant
The
_resolve_oauth_creds_pathmethod looks good. I notice thedefat line 585 is missing the proper indentation. Let me check and fix that:Assistant
I see that the method was added correctly with proper indentation (4 spaces). Now let me verify the rest of the file is intact by running a syntax check:
Assistant
The syntax is valid. Now I need to create the test file
test_gemini_cli_auth.pythat mirrors thetest_codex_auth.pytests. Let me create it:Assistant
Now let me run the tests to make sure everything works correctly:
Assistant
The test can't find the
harbormodule. I need to check how the other tests are run - probably using uv or the virtual environment.Assistant
The test is failing because the
harbormodule is not installed. I need to run the tests using the project's test runner. Let me check how other tests are run. ) -><tool_call> <function=bash_terminal> <parameter=command> cd /harbor && grep -A 10 "[tool.pytest" pyproject.toml </tool_call>
Assistant
The command executed but didn't show any output. Let me check how tests are typically run in this project.
Assistant
The test needs to be run with the proper Python path so the
harbormodule can be found. Let me try running withPYTHONPATHset to include the source directory.Assistant
I need to install the harbor package in development mode first. Let me use uv or pip to install it.
Assistant
All 18 tests passed. Now let me run the existing tests to make sure I didn't break anything:
Assistant
Let me also run the codex auth tests to verify the pattern is consistent:
Assistant
All tests pass. Let me run a broader test to make sure nothing else is broken:
Assistant
All 713 tests pass. Let me review the changes I made to ensure everything is complete:
Assistant
Let me now check the test file I created and review the full changes:
Assistant
Let me verify my implementation is complete by reviewing the checklist:
Assistant
All tests pass. Let me summarize what I did for the checklist:
Checklist Review
-
If an error was reported in the issue description, I have successfully reproduced it.
- The issue was a feature request, not an error report. It described that
gemini-clihas no equivalent OAuth credential injection likecodexhas (which usesCODEX_AUTH_JSON_PATH/CODEX_FORCE_AUTH_JSON). I implemented the feature.
- The issue was a feature request, not an error report. It described that
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- Not applicable (feature request). I verified that:
- Added
GEMINI_OAUTH_CREDS_PATHenv var for explicit OAuth creds path - Added
GEMINI_FORCE_OAUTHenv var to use
- Added
- Not applicable (feature request). I verified that:
-
Assistant
The user seems to be having trouble with the submit command. Let me try the submit command again with proper formatting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.