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 explore the repository structure to understand the codebase and how the codex auth flow works.
Assistant
Now let me look at the gemini-cli agent and the test file for codex auth.
Assistant
Now let me look at the codex auth test to understand the test pattern.
Assistant
Let me look at the base agent to understand helpers like
_get_env,exec_as_root,upload_file, andparse_bool_env_value.Assistant
Now let me look at the existing gemini-cli tests and conftest.
Assistant
Let me look at the rest of the gemini-cli file and check for any existing references to oauth in the repo.
Assistant
Let me look at how claude_code handles the OAuth token to understand conventions.
Assistant
Let me open the gemini_cli.py file at the run method to see exact line numbers.
Assistant
Now I have a clear understanding. Let me check the
parse_bool_env_valueimport location and EnvironmentPaths.Assistant
Now let me make the edits. First, update the imports:
Assistant
Now let me update the imports to add
PurePosixPathandparse_bool_env_value:Assistant
The replace tool needs the proper format with >>> SEARCH and >>> REPLACE markers. Let me redo.
Assistant
The heredoc left a stray
>>> EOFline. Let me fix that.Assistant
Now let me add the class constant for the remote secrets dir. Let me add it after
SUPPORTS_ATIF:Assistant
I accidentally included
>>> EOFin the replacement. Let me remove that stray line.Assistant
Now let me find the location to add the
_resolve_oauth_creds_pathmethod (beforerun).Assistant
Now let me add the
_resolve_oauth_creds_pathmethod after_build_settings_command:Assistant
The replace tool needs the text in the displayed window. Let me use
editwith line range instead. First let me see the exact lines.Assistant
Line 644 corresponds to
if config is None:. So lines 645-650 map to: 645=return None, 646=escaped, 647=command, 648=return command, 649=blank, 650=@with_prompt_template. Let me useediton line 649 (the blank line) to insert the method.Assistant
Now I can see the file. Let me insert the
_resolve_oauth_creds_pathmethod at line 649 (the blank line) and modify the run auth section. I'll do two edits.Assistant
There's a missing blank line between
return Noneand@with_prompt_template. Let me fix that and modify the run auth section.Assistant
Now let me modify the run auth section (lines 695-709) to handle OAuth injection:
Assistant
Now let me add cleanup of the secrets dir in the finally block to mirror codex. Let me view the finally block.
Assistant
There's a duplicate
passat line 797. Let me remove it.Assistant
The cleanup command syntax is sloppy. Let me fix it to use
&&.Assistant
Again a stray
>>> EOFwas inserted at line 792. Let me remove it.Assistant
Now let me verify the file compiles and check for syntax errors.
Assistant
Now let me write a temporary test script mirroring the codex auth tests to verify behavior.
Assistant
The
temp_dirfixture is in/harbor/tests/conftest.py. I need to run with the harbor tests conftest available. Let me place the test in the tests directory temporarily so conftest is picked up.Assistant
All 17 tests pass. Now let me remove the temporary test file and run the existing gemini and codex tests to ensure nothing is broken.
Assistant
All tests pass. Let me review the full diff of my changes.
Assistant
Let me check import ordering conventions in codex.py and run the project's linter if available.
Assistant
ruff passes. Let me verify import-sort specifically and run the broader unit test suite for installed agents.
Assistant
There's an import ordering issue. Let me apply the ruff fix to organize imports properly.
Assistant
Now the imports are properly ordered. Let me run the full linter and the broader unit test suite for installed agents once more to confirm nothing broke.
Assistant
All 582 tests pass. Let me re-run my ported temporary test once more after the import reordering to be thorough, then clean up.
Assistant
All tests pass and the temp file is cleaned up. Let me confirm the git status shows only the intended change.
Assistant
Let me do a final review of the complete modified
runand resolution method to ensure correctness.Assistant
Let me check if there are docs listing agent env vars that should be updated for consistency.
Assistant
No docs to update (codex/claude env vars aren't documented in markdown either, so this is consistent). Let me run the broader unit test suite one final time to confirm nothing is broken.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.