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 codebase and find the relevant files for the codex auth pattern and gemini-cli agent.
Assistant
Now let me look at the gemini_cli.py file and the codex auth tests:
Assistant
Now let me look at the base agent to understand
_get_envandparse_bool_env_value:Assistant
Now let me look at
parse_bool_env_valueand the BaseEnvironment:Assistant
Now let me look at existing gemini_cli tests and the conftest:
Assistant
Now let me look at the full run() method of gemini_cli with line numbers:
Assistant
Now let me implement. First, update the imports in gemini_cli.py:
Assistant
Wait, I need to be careful about alphabetical ordering of imports? Not necessarily. Let me check that the import placement is fine. Let me view the imports.
Assistant
The import ordering is messed up. Let me reorder alphabetically:
Assistant
Now let me add the class constant for the remote secrets dir. Let me add it near the class top:
Assistant
Now let me add the
_resolve_oauth_creds_pathmethod. Let me add it right before therun()method (after_build_settings_command):Assistant
Let me use the edit command with line ranges instead:
Assistant
There's a duplicate
@with_prompt_template. Let me fix it by removing the extra one:Assistant
Still a duplicate. Let me remove the extra decorator line:
Assistant
Now the structure is correct. Let me modify the
run()method to inject the OAuth creds. Let me update the auth_vars loop area and the finally block:Assistant
Now let me add cleanup in the finally block. Let me view the rest:
Assistant
The edit broke the structure. Let me view and fix:
Assistant
Let me rewrite the whole finally block correctly:
Assistant
Now the structure looks correct. Let me verify the file compiles:
Assistant
Let me fix the cleanup to use
rm -rfsince the secrets dir is a directory:Assistant
Now let me verify the module imports correctly:
Assistant
Now let me run the existing gemini and codex tests to make sure nothing is broken:
Assistant
Now let me create a temporary test script (mirroring the codex auth tests) to validate the new behavior:
Assistant
All 17 tests pass. Now let me clean up the temporary test file and run the full test suite for the installed agents:
Assistant
Let me reconsider auth precedence. To truly mirror the codex pattern (where opting into the credential file suppresses the API key), I should ensure that when OAuth creds are injected, the API-key env vars (
GEMINI_API_KEY,GOOGLE_API_KEY) are not passed, so the "Login with Google" session actually takes precedence. Let me update the auth_vars loop:Assistant
Let me re-add the temporary test with an additional check for API key suppression, and verify:
Assistant
All 18 tests pass including the API key suppression. Let me clean up the temp test and run the broader test suite:
Assistant
Let me run ruff to ensure code style compliance:
Assistant
Let me view the final state of the modified run() method and the new method to confirm everything is consistent:
Assistant
Ruff passed, but let me check the import ordering more carefully —
harbor.utils.envis placed beforeharbor.models.trajectorieswhich isn't alphabetical. Let me check the ruff config and reorder for cleanliness:Assistant
Ruff isort is configured but it passed, meaning ruff didn't flag the ordering. Let me check - ruff might consider
harboras first-party and sort within first-party separately. The order within first-party should be alphabetical:harbor.agents,harbor.environments,harbor.models.agent.context,harbor.models.agent.name,harbor.models.trajectories,harbor.utils.env.But my current order has
harbor.utils.envbeforeharbor.models.trajectories. That's out of order. Yet ruff said "All checks passed!" and "1 file already formatted".Hmm, wait — maybe ruff format doesn't sort imports, and ruff check's isort (I) rule might not be enabled in the default select. Let me check the lint select config.
Assistant
Ruff doesn't enforce isort by default, but let me reorder the import to be properly alphabetical to match the existing code style:
Assistant
I removed the import line. Let me add it back after the trajectories import block:
Assistant
There's a duplicate
_ImageMediaTypeand an extra blank line. Let me fix:Assistant
Now let me verify imports work, run ruff, and run the tests again:
Assistant
Let me run the broader unit test suite to ensure nothing else is affected:
Assistant
All tests pass. Let me check if there's documentation or a registry that documents these env vars (codex pattern) so I can mirror for gemini:
Assistant
No docs for CODEX_AUTH_JSON_PATH. Let me check the registry.json to see if there's agent config there.
Assistant
Let me check the docs folder for any agent auth documentation that should be mirrored:
Assistant
No auth-specific docs to update. Let me do a final review of the complete diff:
Assistant
The implementation is complete. Let me verify there are no leftover temp files and confirm only the intended file changed:
Assistant
Only the intended file changed and no leftover temp files. Let me do a final comprehensive test run to confirm everything passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.