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 analyze the issue. The task is to add OAuth credential support to
gemini-cliagent, mirroring the pattern used incodexagent. Let me first explore the repository structure to understand how it's organized and find the relevant files.Assistant
Let me explore the repository structure more to understand the codebase, especially the gemini-cli and codex agents.
Assistant
These look like benchmark/adapters directories. Let me look for the gemini-cli and codex agent implementations. They might be in the packages or src directories.
Assistant
Now I have the key files. Let me look at the codex agent implementation to understand the OAuth pattern, and the gemini-cli agent to see what needs to be modified.
Assistant
The user is trying to use the
opencommand but made a syntax error. Let me check the correct syntax for the open command.Assistant
The open command seems to not accept FILE as a parameter. Let me try without the keyword argument.
Assistant
Now let me look at the gemini-cli agent implementation:
Assistant
Now let me check for existing tests for the codex auth pattern and gemini-cli tests:
Assistant
Now let me look at the gemini-cli tests to understand the existing test patterns:
Assistant
Let me also check the utility function used for parsing boolean env values and the base agent class:
Assistant
Now let me look at the base agent class to understand how
_get_envworks:Assistant
Now let me check the
PurePosixPathimport and how it's used in the codex agent for the remote paths, so I can mirror that pattern:Assistant
Now I have a good understanding of the codebase. Let me plan the implementation:
-
Add
_resolve_oauth_creds_path()method toGeminiClimirroring_resolve_auth_json_path()fromCodex -
Add remote path constants for secrets dir
-
Modify the
run()method to:- Upload OAuth creds if present
- Chown the uploaded file
- Symlink to
~/.geminidirectory - Fall back to existing API key behavior when no OAuth creds
-
Create tests mirroring
test_codex_auth.py
Let me also check what
EnvironmentPathslooks like:-
Assistant
Now I have a comprehensive understanding of the codebase. Let me implement the OAuth credential support for
gemini-cliby:- Adding
_resolve_oauth_creds_path()method toGeminiCli(mirroring codex) - Adding remote path constants
- Modifying
run()to handle OAuth creds (upload, chown, symlink to~/.gemini) - Creating corresponding tests
Let me start by modifying the
gemini_cli.pyfile:- Adding
Assistant
Now I'll implement the changes. First, let me update the imports and add the necessary constants and methods:
Assistant
Let me use the correct edit format with the file specified:
Assistant
I need to use the replace command instead since edit requires a file to be open first. Let me use replace to modify the file.
Assistant
The user seems to be having trouble with the edit/replace commands. Let me try using sed instead to modify the file. }
<tool_call> <function=bash_terminal> <parameter=command> sed -i 's/from pathlib import Path$/from pathlib import Path, PurePosixPath/' /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
The user is having trouble with the edit/replace commands. Let me use the bash_terminal command to make the changes using sed.
Assistant
The user wants me to continue working on the issue. Let me check the current state of the file and continue implementing the OAuth credential support for gemini-cli.
I need to:
- Add the import for PurePosixPath (done)
- Add the import for parse_bool_env_value
- Add the import for EnvironmentPaths
- Add remote path constants
- Add _resolve_oauth_creds_path method
- Modify the run() method to handle OAuth credentials
- Create tests
Let me continue by checking the current state of the file.
Assistant
Good, the PurePosixPath import is done. Now I need to add the other imports and implement the OAuth support. Let me add the required imports first:
Assistant
The user wants me to continue working on the issue. Let me check what happened with the sed command and verify the imports were added correctly.
Assistant
The sed command corrupted the file. Let me restore it and use a Python script to make the changes properly.
Assistant
Let me use a Python script to make all the necessary changes properly:
Assistant
Let me verify the patch was applied correctly by checking the modified file:
Assistant
Good, the imports look correct. Let me check the rest of the file to verify the constants and methods were added correctly.
Assistant
The changes look good. Let me verify the
_resolve_oauth_creds_pathmethod and therunmethod:Assistant
Good, the
_resolve_oauth_creds_pathmethod looks correct. Let me check the run method:Assistant
The implementation is progressing well. Let me verify the cleanup section at the end of the run method and then move on to creating the tests.
Assistant
I notice that the cleanup of the secrets directory wasn't added to the end of the file. Let me check if it was added properly and if not, I need to add it. Looking at the patch script, the cleanup code should have been added after the last
except Exception: passblock. Let me verify and fix if needed.Assistant
The cleanup code for the secrets directory wasn't added. I need to add it at the end of the file, after the last
except Exception: passblock.Assistant
The cleanup code wasn't added. Looking at the patch script, it seems the logic to replace the last
except Exception: passblock with the cleanup code didn't work correctly. I need to add the cleanup code at the end of the file.Let me look at the end of the file and add the cleanup code manually.
Assistant
I need to add the cleanup code at the end of the file. The last
except Exception: passblock needs to be followed by the secrets cleanup code.Assistant
I need to verify that the cleanup code was appended correctly and check the indentation. Let me see the end of the file to make sure it looks right.
Assistant
The cleanup code looks like it was added correctly but I need to verify the indentation is proper - it should be inside the finally block. Let me check the indentation by looking at more context around that area.
Assistant
Good, the cleanup code is properly inside the
finallyblock. Now let me verify the Python file is syntactically correct:Assistant
Now let me create the tests for the OAuth credential resolution, mirroring the codex auth tests. First, let me check the existing test fixtures:
Assistant
Now I need to create the test file for Gemini CLI OAuth auth, mirroring the test_codex_auth.py tests. Let me create it.
Assistant
Now let me run the new tests to verify they pass:
Assistant
The tests are failing because the module can't be found. I need to run the tests from the correct environment where harbor is installed. Let me check how the existing tests are run.
Assistant
The existing codex tests pass. Now let me run the new gemini cli auth tests using the venv python:
Assistant
I see the issue - the test is looking for
~/.gemini/oauth_creds.jsonbut the actual command uses$HOME/.gemini/oauth_creds.json. Let me fix the test:Assistant
Let me re-run the tests to make sure they all pass now.
Assistant
All 19 tests pass. Now let me verify the existing tests still pass to make sure I haven't broken anything:
Assistant
Let me verify all the changes and run a broader test suite to ensure nothing is broken.
Assistant
The user is asking me to continue. Let me check the status of what I've done and run the broader test suite to make sure everything is working correctly. I should also verify the changes by looking at the git diff.
Assistant
The diff looks good. Let me run a broader test suite to make sure nothing is broken.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.