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
Assistant
Now let me look at the gemini_cli.py to understand the current
Assistant
Now let me look at the existing tests for codex auth to understand the test patterns:
Assistant
let me look at the existing tests for gemini_cli to understand its structure:
Assistant
Now let me look at the BaseInstalledAgent and helpers:Now let me look at the BaseInstalledAgent and helpers:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cat src/harbor/agents/installed/base.py]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me retry with proper tool invocation
Assistant
Now let me look at the parse_bool_env_value helper:
Assistant
Now let me check the test fixtures used:
Assistant
Now let me look at the codex run method to understand its full implementation pattern:
Assistant
Now let me look at the actual codex run method to understand the auth.json upload flow fully:
Assistant
Now I have a clear understanding. Let me look at the rest of the gemini_cli.py run method:
Assistant
Now let me look at the EnvironmentPaths and figure out where the agent logs go:
Assistant
Now let me check the existing test_gemini_cli.py and tests directory:
Assistant
Now let me look at the docs to understand how this should be documented:
Assistant
Let me look at the install method in gemini_cli.py and confirm where the agent home is:
Assistant
Let me look at the full codex run() function pattern including the cleanup logic:
Assistant
Let me look at how default_user is used and confirm the environment interface:
Assistant
me check how the
extra_envparameter is used:Assistant
Now I have a comprehensive understanding. Let me check the docs for codex auth:
Assistant
I have a complete understanding. Let me check the run() method of gemini_cli.py once more to understand the exact location of changes:
Assistant
Now let me also look at imports in gemini_cli.py to see what is needed:Now let me look at the imports in gemini_cli.py:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[sed -n '1,20p' src/harbor/agents/installed/gemini_cli.py]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me also check where
parse_bool_env_valueis used in gemini_cli.py:Assistant
Let me first run the existing codex auth tests to confirm they pass as a baseline:
Assistant
All 18 codex auth tests pass. Now let me also run the gemini_cli tests as a baseline:
Assistant
All tests pass. Now let me implement the changes. First, let me modify
gemini_cli.pyto add OAuth support:Assistant
edit made a mess of the imports. Let me revert and try again:
Assistant
Now let me make targeted edits one at a time. First, add the import:
Assistant
Good. Now let me add the class constants for secrets dir:
Assistant
Now let me find the location of the
_build_settings_commandmethod so I can add_resolve_oauth_creds_pathmethod beforerun:Assistant
Now let me add the
_resolve_oauth_creds_pathmethod and updaterun():Assistant
me check the exact content of that area:
Assistant
Let me check with a smaller search:
Assistant
I see - the search tool needs an actual newline character. Let me use
editwith line ranges instead:Assistant
I see I lost the
@with_prompt_templatedecorator and a blank line. Let me fix:Assistant
Let me also fix the double blank line:
Assistant
I see a duplicate line. Let me fix it:
Assistant
Now let me view the rest of the file to see the cleanup finally block:
Assistant
Now let me update the
run()method to integrate OAuth support:Assistant
Now I need to add cleanup of the secrets dir after the run. Let me also notice that the run() lost the
cli_flags,extra_flags, andrun_modellines:Assistant
I made a mess. Let me reset and try again:
Assistant
Now let me apply the edits in a cleaner way. First, add the import:
Assistant
Now let me try the edit one line at a time:
Assistant
Let me write a Python script to apply changes carefully:
Assistant
Now let me verify the file is correct so far:
Assistant
Now let me update the run() method. Let me find the exact section to modify:
Assistant
Now let me apply the run() method changes with another script:
Assistant
Now let me also revert the previous attempt where the old text didn't match - that should have already failed and not applied:
Assistant
The first script applied but didn't run the run() method part. Now I need to apply the run() method changes. Let me do it:
Assistant
Let me verify the run() method:
Assistant
Now let me verify the file is syntactically valid:
Assistant
Now let me verify existing tests still pass:
Assistant
All existing gemini_cli tests pass. Now let me create the test file mirroring
test_codex_auth.py:Assistant
Now let me create the test file for gemini-cli auth:
Assistant
Now let me run the new tests to confirm everything works:
Assistant
Excellent! 19 out of 20 pass. The cleanup test was over-strict - the test string was matching both the setup
rm -f ~/.gemini/oauth_creds.json && ln -sf ...and the cleanup. Let me fix the test:Assistant
The edit messed up the test file. Let me reset it:
Assistant
Let me recreate the test file with a Python script:
Assistant
I see - the base
_execwraps commands withset -o pipefail;prefix. Let me adjust the test to match:Assistant
There's a duplicate
assert len(cleanup_calls) == 1. Let me fix that:Assistant
All 20 new tests pass. Now let me also ensure all existing gemini-cli tests still pass:
Assistant
All 60 tests pass (existing gemini-cli tests, codex auth tests, and new gemini-cli auth tests).
Now let me also check that all other tests in the agents directory still pass:
Assistant
All 602 tests in the agents/installed directory pass. Now let me verify the file structure once more:
Assistant
Let me also run a quick sanity check on the full file:
Assistant
Let me also do a manual end-to-end sanity check to verify the run() method behavior:
Assistant
All three scenarios work as expected:
- Default (no oauth) - no upload, just uses API key auth (existing behavior preserved)
GEMINI_OAUTH_CREDS_PATH- uploads to/tmp/gemini-secrets/oauth_creds.json, chowns, symlinks to~/.gemini/oauth_creds.json, cleans up afterGEMINI_FORCE_OAUTH=true- uses~/.gemini/oauth_creds.jsonfrom host, same upload/symlink/cleanup flow
Now let me run all tests one more time to ensure no regression:
Assistant
All 2523 unit tests pass. Let me also clean up my temporary scripts:
Assistant
Let me check the diff of all the changes I made:
Assistant
The diff looks great. Let me also verify the new test file is correct:
Assistant
Let me also check the final code one more time:
Assistant
Let me also verify the file final state with a quick sanity check on edge cases by running the entire gemini test suite:
Assistant
All 42 tests pass. Now let me think about edge cases that I should consider:
-
Edge case: What if both
GEMINI_OAUTH_CREDS_PATHandGEMINI_FORCE_OAUTHare set? TheGEMINI_OAUTH_CREDS_PATHtakes priority (matching the codex pattern). ✓ (tested) -
Edge case: What if
~/.gemini/oauth_creds.jsonalready exists from a previous run? My code doesrm -fbeforeln -sf, so it handles this. ✓ -
Edge case: What if
GEMINI_API_KEYis set but alsoGEMINI_OAUTH_CREDS_PATH? The OAuth path takes priority and API key is NOT included in env. ✓ (tested intest_oauth_mode_omits_api_key_env) -
Edge case: What if the credentials file is invalid? The
upload_filewould fail - the error propagates up. ✓ -
Edge case: What if there's no
default_user(running as root)? The chown is skipped. ✓ (tested) -
Edge case: Cleanup happens even on failure (in the
finallyblock). ✓ (existing finally block pattern)
-
Assistant
All methods are properly present. Now let me also do a final test run to verify everything:
Assistant
All 2523 tests pass. Now let me go through the checklist:
Checklist Review
1. If an error was reported in the issue description, I have successfully reproduced it.
- The issue describes a missing feature (OAuth credential support for gemini-cli), not an error. I created a sanity check script that confirmed the original behavior (no upload, no OAuth) and the new behavior works correctly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.