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 start by exploring the repository structure to understand what we're working with. The issue is about adding OAuth credential injection to
gemini-cliagent, mirroring the codex pattern. Let me first explore the repository.Assistant
Let me explore the structure more, particularly looking for the gemini-cli agent and codex agent for comparison.
Assistant
Let me look at the adapters directory since the issue mentions gemini-cli agent
Assistant
Let me look at the src directory and find the agents code
Assistant
Let's look at the harbor source module.
Assistant
Let me examine the two key files: codex.py (the model) and gemini_cli.py (what needs to be updated
Assistant
Now let me look at the gemini_cli.py file and the base agent class
Assistant
Now let me look at the test files to understand the existing tests:
Assistant
Let me examine the codex auth test and the gemini cli test
Assistant
Now let me look at the gemini_cli test and the utils/env.py:
Assistant
Let me look at the relevant utility files and the base installed agent class
Assistant
Let me look at the base installed agent to understand
_get_envandextra_envAssistant
Let me also look at the base Agent class
Assistant
Let me look at the existing test_gemini_cli_mcp.py and test_simple_agents.py to understand how gemini-cli is tested
Assistant
Let me look at the test_simple_agents.py to understand the testing patterns.
Assistant
Let me check the conftest.py for test fixtures
Assistant
Now I have a comprehensive understanding of the codebase. Let me plan my implementation:
- Add
_resolve_oauth_creds_path()method toGeminiCli(mirroringCodex._resolve_auth_json_path) - Wire the OAuth credential injection into the
run()method - Add tests for the new functionality
Let me first check if there's any specific env variable that gemini CLI recognizes for oauth credentials:
- Add
Assistant
Now let me implement the changes. First, let me add the
_resolve_oauth_creds_pathmethod and update therun()method ingemini_cli.py:Assistant
Let me use the correct syntax. The open command needs to use
--fileflag.Assistant
Let me just directly use the
opencommand without--file.Assistant
Let me see the full run method:
Assistant
Let me see the run method:
Assistant
Let me see the rest of the run method
Assistant
Now I have a full understanding. Let me implement the changes. First, I'll add the
_resolve_oauth_creds_pathmethod and update therunmethod.Assistant
Let me use the heredoc syntax for the edit command
Assistant
Now let me add the
_resolve_oauth_creds_pathmethod. Let me find the right location - right before_build_register_skills_command:Assistant
Now let me insert the
_resolve_oauth_creds_pathmethod before_build_register_skills_command:Assistant
Now I need to fix the blank line between the methods and update the
run()method. Let me first fix the blankAssistant
I see a duplicate line. Let me fix it
Assistant
Now let me see the complete run method to update it:
Assistant
Now let me update the
run()method to inject OAuth credentials. I'll insert the OAuth handling right after the auth_vars loop and before skills_commandAssistant
I see a duplicate line for
settings_command, model_alias. Let me fix itAssistant
Good. Let me verify the full file looks correct by viewing the complete run method and the new
_resolve_oauth_creds_pathmethod:Assistant
Let me check how
upload_filehandles the remote path to make sure~expansion works properlyAssistant
Let me see the upload_file implementation
Assistant
Let me check how docker handles the target path
Assistant
Let me check the docker_unix platform:
Assistant
Let me check what EnvironmentPaths provides
Assistant
Let me look at how other agents handle file uploads to user home directories
Assistant
I need to fix the upload approach. The
upload_fileneeds an absolute path because docker cp doesn't expand~. Let me use a temp path approach like codex does (upload to/tmp/, then use exec_as_agent to move to `~/.gemini/Assistant
Now let me create the test file for the OAuth credential resolution, mirroring the codex auth tests:
Assistant
Now let me write the test file
Assistant
Now let me run the existing tests to verify nothing is
Assistant
Let me check how to run the tests properly
Assistant
Let me check the pytest config and then run the tests:
Assistant
Let me install pytest-asyn
Assistant
Now let me run the existing gemini tests to make sure nothing broke
Assistant
Existing tests pass. Now let's run the new OAuth test
Assistant
The test issue is that the finally block's
exec_as_agentcall doesn't passenv, and it gets picked up as the last "gemini" call. Let me fix the test to be more specific:Assistant
There's a duplicate. Let me fix it
Assistant
I see the duplicate is still there. Let me fix this properly by removing lines 179-183.
Assistant
Let me just rewrite the file clean
Assistant
Let me just rewrite the file cleanly via a shell command
Assistant
Now let me run the tests
Assistant
All tests pass. Let me also run the broader test suites to make sure nothing else breaks
Assistant
All tests pass. Let me also run the gemini CLI MCP tests and the installed
Assistant
All 39 additional tests pass. Let me now verify the final state of my changes by looking at the git diff:
Assistant
Let me see the full diff
Assistant
Let me also check that the test file is included as a new
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.