Add Gemini provider (Windows parity) - #34
Conversation
Reads ~/.gemini/oauth_creds.json, refreshes tokens via Google OAuth using client credentials from the file or environment, and surfaces Pro/Flash quota bars with tier labels from the Code Assist API. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds Gemini as a macOS usage provider using Gemini CLI OAuth credentials, automatic token refresh, tier and quota parsing, reset countdowns, local credential discovery, settings support, provider registration, and XCTest coverage. ChangesGemini provider
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant GeminiUsageProvider
participant GeminiAuthFileStore
participant GeminiTokenRefresh
participant GeminiQuotaAPI
participant GeminiUsageParser
User->>GeminiUsageProvider: Request usage refresh
GeminiUsageProvider->>GeminiAuthFileStore: Read OAuth credentials
GeminiUsageProvider->>GeminiTokenRefresh: Refresh expired access token
GeminiTokenRefresh->>GeminiQuotaAPI: Send token refresh request
GeminiQuotaAPI-->>GeminiTokenRefresh: Return refreshed token
GeminiUsageProvider->>GeminiAuthFileStore: Persist refreshed credentials
GeminiUsageProvider->>GeminiQuotaAPI: Fetch tier and quota
GeminiQuotaAPI-->>GeminiUsageProvider: Return tier and quota JSON
GeminiUsageProvider->>GeminiUsageParser: Parse Pro and Flash usage
GeminiUsageParser-->>User: Display usage and reset countdowns
Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9f555274fb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Use Windows-style split installed-app OAuth defaults when credentials omit client secrets, and mark transient Gemini failures as incomplete refreshes. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@CHANGELOG.md`:
- Line 24: Remove the changelog entry describing live Gemini quota fetching
through Gemini CLI OAuth credentials, and do not ship or document that
OAuth-based integration until a supported API path or explicit authorization is
available.
In `@CodexBarMac/Services/GeminiAuthFileStore.swift`:
- Around line 26-28: Update the credential-writing flow around existingFileMode
to always use 0600 instead of preserving the prior mode, and make the chmod
call’s failure propagate as an error rather than discarding its result. Keep the
atomic write behavior unchanged.
In `@CodexBarMac/Services/GeminiTokenRefresh.swift`:
- Around line 6-30: Add an expired-token Gemini refresh test in
CodexBarMacTests/CodexBarMacTests.swift near the existing Gemini parsing and
quota-fetch tests, mocking the token endpoint and asserting refreshed
credentials are persisted and reused on subsequent requests; no direct change is
required in GeminiTokenRefresh.resolveClientID, resolveClientSecret, or
makeRefreshTokenRequestBody.
In `@CodexBarMac/Services/GeminiUsageParser.swift`:
- Around line 62-83: Update the bucket aggregation in the Gemini usage parser to
classify only explicitly recognized Pro and Flash model families, ignoring
missing or unrelated model IDs. Track whether each family has been selected so
its first matching bucket is accepted even when remainingFraction is 1.0, while
retaining the reset date from that selected full bucket and continuing to
replace it only when a later matching bucket has lower remaining usage.
In `@CodexBarMac/Services/GeminiUsageProvider.swift`:
- Around line 212-228: Update the tier-fetch flow around tierCache.markFetched
so failures from network, non-2xx HTTP responses, or GeminiUsageParser.parseTier
do not mark the cache as fetched. Clear fetchInProgress on every exit, and set
fetched only after a valid tier name is successfully stored; adjust the
corresponding logic in the additional indicated tier-fetch path as well.
In `@CodexBarMacTests/CodexBarMacTests.swift`:
- Around line 3027-3047: Update
testGeminiTokenRefreshBuildsRequestBodyFromResolvedCredentials to use
refresh-token, client ID, and client secret values containing reserved
characters such as +, /, =, &, and spaces. Assert the encoded request body
contains each value’s correct percent-encoded representation rather than raw
values, while retaining the grant_type assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 5aab3377-2b70-4b21-b38e-904d56b57440
📒 Files selected for processing (17)
CHANGELOG.mdCodexBarMac.xcodeproj/project.pbxprojCodexBarMac/Models/GeminiCredentials.swiftCodexBarMac/Models/ProviderAccountConfiguration.swiftCodexBarMac/Models/ProviderID.swiftCodexBarMac/Services/GeminiAuthFileStore.swiftCodexBarMac/Services/GeminiCredentialsParser.swiftCodexBarMac/Services/GeminiTokenRefresh.swiftCodexBarMac/Services/GeminiUsageParser.swiftCodexBarMac/Services/GeminiUsageProvider.swiftCodexBarMac/Services/LocalCredentialDiscovery.swiftCodexBarMac/Services/ProviderConfigurationStore.swiftCodexBarMac/Services/UsageRefreshService.swiftCodexBarMac/Views/ProviderSettingsView.swiftCodexBarMac/Views/ProviderUsageCard.swiftCodexBarMac/Views/SettingsView.swiftCodexBarMacTests/CodexBarMacTests.swift
Only mark tier cache fetched after a successful parse, ignore unrelated quota buckets, enforce 0600 on OAuth file writes, and add expired-token refresh coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4fb426109e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Cache cloudaicompanionProject alongside tier metadata and include it in retrieveUserQuota requests when available. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
@coderabbitai review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f3d4c54ae
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Use GOOGLE_CLOUD_PROJECT-style env vars when loadCodeAssist does not return cloudaicompanionProject. Co-authored-by: Cursor <cursoragent@cursor.com>
✅ Action performedReview finished.
|
Use the lowest remaining fraction per model family across REQUESTS, INPUT_TOKENS, and OUTPUT_TOKENS so token limits surface before request quota is exhausted. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 058f388fc7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
✅ Action performedReview finished.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15925a563b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Keep auth-mode gating aligned with injected oauthFilePath so provider tests and custom homes are not blocked by the machine-wide CLI settings file. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5454e01f1e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Resolve Code Assist project from GOOGLE_CLOUD_PROJECT before quota overrides, and follow Resource Manager nextPageToken until a labeled or gen-lang-client project is found. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@codex review |
|
@coderabbitai review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a24e13aaa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
✅ Action performedReview finished.
|
Only cache Resource Manager projects that look like Code Assist (generative-language label or gen-lang-client); otherwise leave quota project unset. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@codex review |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@codex review |
4 similar comments
|
@codex review |
|
@codex review |
|
@codex review |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Closes #16
Summary
~/.gemini/oauth_creds.json.loadCodeAssist.Verification
./test.sh— 108 tests passed (including new Gemini parser/provider tests)Residual risk
CODEXBAR_GOOGLE_CLIENT_ID/CODEXBAR_GOOGLE_CLIENT_SECRET(also acceptsGEMINI_OAUTH_*).Made with Cursor
Note
Add Gemini as a provider with OAuth authentication and usage quota display
ProviderID.geminiand wires it into provider settings, icon display, and default account configuration with OAuth as the auth method.GeminiUsageProviderwhich reads local OAuth credentials, refreshes expired tokens via Google's token endpoint, and fetches quota from CloudCode endpoints, mapping results to usage bars viaGeminiUsageParser.LocalCredentialDiscoverysupport for Gemini: auto-adds a Gemini account when~/.gemini/oauth_creds.jsonis present and CLI settings indicate OAuth/login mode; suppresses re-discovery after account removal.GeminiAuthFileStore,GeminiCredentialsParser,GeminiTokenRefresh, andGeminiCLISettingsto handle credential I/O, JSON parsing, token refresh, and CLI settings detection.Macroscope summarized aa1a994.