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.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /harbor, current file: none) bash-$
Assistant
I'll start by exploring the repository structure to understand the codebase and how the codex agent implements its OAuth credential injection.
Assistant
Let me explore the repository structure first.
Assistant
Let me read the codex agent (with its auth flow) and the gemini-cli agent to understand the patterns.
Assistant
Now let me read the gemini_cli agent and the codex auth test:
Assistant
Now let me look at the gemini cli test and the base class to understand
_get_env,extra_env, etc.:Assistant
Now let me understand the gemini oauth creds flow. The codex flow uploads
auth.jsonto/tmp/codex-secrets/auth.json, then symlinks$CODEX_HOME/auth.jsonto it. For gemini, the OAuth creds file is~/.gemini/oauth_creds.json.Let me look at how the gemini run works. The gemini agent uses
~/.geminifor settings. The OAuth creds go into~/.gemini/oauth_creds.json.Let me look at the
parse_bool_env_valueutil:Assistant
Now I have a clear understanding. Let me look at the exact
runmethod section and the imports in gemini_cli.py:Assistant
Let me check the existing gemini tests to make sure I don't break expectations:
Assistant
Now I have a full understanding. Let me implement the changes. First, the imports:
Assistant
Now add the class constant and the
_resolve_oauth_creds_pathmethod. Let me add the constant near the class definition:Assistant
Now let me add the
_resolve_oauth_creds_pathmethod right before therunmethod, and modifyrun. Let me view the area around_build_settings_commandandrun:Assistant
Now let me modify the
runmethod body to inject the oauth creds. Let me view the current run body:Assistant
Now let me rewrite the run body to inject the oauth creds, mirroring the codex pattern:
Assistant
Let me verify the file is correct - check the finally block and the run method:
Assistant
The finally block is intact. Now let me verify the file imports correctly:
Assistant
Import works. Now let me create the test file, ported from
test_codex_auth.pybut adapted for gemini. Let me check the conftest for thetemp_dirfixture:Assistant
Now let me create the test file for gemini oauth creds, ported 1:1 from the codex auth test:
Assistant
All 18 tests pass. Now let me run the existing gemini tests and codex auth tests to ensure nothing broke:
Assistant
All pass. Now let me check that the
EnvironmentPathsimport I added is actually used — it's not used in gemini_cli.py (codex uses it, but gemini doesn't). Let me remove the unused import to avoid lint issues:Assistant
EnvironmentPathsis imported but not used. Let me remove it and verifyPurePosixPathis used:Assistant
Now let me run the broader installed agents test suite to make sure nothing else broke:
Assistant
All 600 tests pass. Let me also run a lint check (ruff) if available, since the repo may enforce it:
Assistant
Ruff passes (including import sorting). Let me check if there's documentation referencing the codex auth env vars that should be mirrored for gemini:
Assistant
No docs reference these env vars, so nothing to mirror there. Let me write a quick reproduction script to verify both the default (backward-compat) and oauth paths behave correctly end-to-end:
Assistant
Both paths work as expected. Let me clean up the temp script (already inline) and run the full installed test suite once more plus the codex tests to confirm everything is green:
Assistant
Let me do a final review of the complete diff:
Assistant
The diff is clean. Let me verify the new test file is tracked and check git status:
Assistant
I need to remove the new test file before submitting — the instructions explicitly state not to add new tests to the repository (it causes evaluation errors). The test file served its purpose in validating the implementation. Since
submitusesgit diff(which excludes untracked files anyway), I'll remove it to comply:Assistant
Let me run the existing tests one final time to confirm everything passes without my removed test file:
Assistant
All existing tests pass. Let me do a final lint check on the modified source file:
Assistant
The implementation is complete. Let me summarize what I did and verify the checklist:
Summary
I added opt-in OAuth-credential ("Login with Google") injection to the
gemini-cliagent, mirroring the existingcodexauth.json pattern.Changes to
src/harbor/agents/installed/gemini_cli.py-
Imports: Added
PurePosixPathandparse_bool_env_value. -
Class constant:
_REMOTE_GEMINI_SECRETS_DIR = PurePosixPath("/tmp/gemini-secrets")— a temp dir outside the persisted logs for the uploaded creds (mirrors codex's/tmp/codex-secrets). -
_resolve_oauth_creds_path(): MirrorsCodex._resolve_auth_json_path():GEMINI_OAUTH_CREDS_PATH=<path>→ use that specific file (raises if missing)GEMINI_FORCE_OAUTH=<truthy>→ use~/.gemini/oauth_creds.json(raises if missing or invalid bool value)- Default →
None(GEMINI_API_KEY / Vertex auth), fully backward-compatible
-
run():- Resolves the oauth creds path; only injects the API-key/Vertex env vars when no oauth creds are present (mirrors codex suppressing
OPENAI_API_KEYwhen auth.json is used). - When oauth creds are present: creates the secrets dir → uploads the file →
chownto the default user (skipped ifdefault_user is None) → symlinks~/.gemini/oauth_creds.jsonto it. - In the
finallyblock: best-effort cleanup of/tmp/gemini-secrets.
- Resolves the oauth creds path; only injects the API-key/Vertex env vars when no oauth creds are present (mirrors codex suppressing
Checklist
- [x] Reproduced the error: The issue described a missing feature (no equivalent to codex auth). I confirmed
gemini_cli.pyonly wiredGEMINI_API_KEY/Vertex env and had no OAuth path. I wrote a reproduction/verification script confirming the default path and the new oauth path behave correctly. - [x] Confirmed the fix resolves the error: My verification script confirmed: default path propagates
GEMINI_API_KEYwith no upload; oauth path uploads → chowns → symlinks into~/.gemini→ suppresses the API key → cleans up. The ported tests (run during validation, then removed per repo rules) all passed (18/18). - [x] Edge cases handled: missing explicit file raises; missing
~/.gemini/oauth_creds.jsonraises; invalidGEMINI_FORCE_OAUTHbool raises; falsy values return None;default_user is Noneskips chown; cleanup is best-effort and doesn't interfere with the session-copy infinally; default behavior is byte-for-byte unchanged when no oauth env is set. - [x] Ran existing tests: All 600 installed-agent tests pass (including the existing
test_gemini_cli,test_gemini_cli_mcp, andtest_codex_auth). Ruff lint passes. The new validation test file was removed per the instruction not to add new tests to the repository.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →