Skip to content

feat(rate-limits): add API-key-based ClinePass usage tracking - #13827

Open
euclodius wants to merge 4 commits into
stablyai:mainfrom
euclodius:feat/clinepass-usage
Open

euclodius wants to merge 4 commits into
stablyai:mainfrom
euclodius:feat/clinepass-usage

Conversation

@euclodius

@euclodius euclodius commented Aug 11, 2026 •

Copy link
Copy Markdown

Scope

This is an API-key-based implementation related to #13032. It supports Windows + WSL setups through an Orca-owned credential: the user enters the key once in Settings, the Windows Orca process stores it and queries the quota API directly, and the Cline agent can continue running in WSL. No WSL-specific credential access is required for this flow.

Automatic import of an environment variable or CLI session that exists exclusively inside a WSL distribution is not included. This PR therefore does not claim WSL credential auto-discovery and does not close #13032.

Summary

  • Add API-key-based ClinePass subscription quota tracking to the Usage status bar and AI Provider Accounts.
  • Fetch the 5-hour, weekly, and monthly windows from Cline's account usage API with explicit auth, rate-limit, network, server, and parse failure states.
  • Support either a stored API key or CLINE_API_KEY from the Orca process environment; stored keys use Electron safeStorage, fail closed when secure storage is unavailable (including Linux basic_text), and never cross into renderer state.
  • Keep ClinePass subscription quota distinct from Cline PAYG/BYOK usage.

Related to #13032 (explicit API-key path; does not close it).

Screenshots

Screenshots are not attached because the local end-to-end smoke used live account/quota data. I visually verified both the Usage roster and the ClinePass Accounts section without publishing private account values.

Testing

  • pnpm lint — not run project-wide; check-changed-code-quality.mjs passed with 0 new code-quality, type-aware, or React Doctor errors across 43 changed files.
  • pnpm typecheck — node, web, and CLI TypeScript targets passed independently; the review-fix commit also passed the web target again.
  • pnpm test — not run project-wide; 16 focused suites passed locally (401 tests). The review-fix commit additionally passed the two affected UI suites (15 tests). Upstream CI has not independently run the full focused set yet.
  • pnpm build — not run as a production build; Electron dev runtime launched successfully.
  • Added or updated high-quality tests for credential storage/IPC trust, response mapping and errors, service races/stale state, status visibility/migrations, search/toggles, Settings recovery states, and failure-specific credential guidance.
  • Localization catalog and extraction verification passed locally.
  • check-max-lines-ratchet.mjs passed locally.
  • Live smoke: a real ClinePass account rendered 5h, weekly, and monthly quota plus reset data in the Usage roster; Accounts showed the environment credential source without exposing the key.

AI Review Report

Reviewed the full credential → IPC/preload → rate-limit service → shared state → renderer path. The review checked provider exhaustiveness, account-key generation races, stale-snapshot policy, optional mixed-version state, status-item migrations, Settings search/toggle coverage, loading/error recovery, and test contracts. It found two UI omissions before the PR was opened; both were fixed and covered by focused tests. CodeRabbit subsequently found misleading secondary copy after a credential-status load failure and three noncanonical localization keys; both findings were fixed in eec5ab02b and reverified.

Cross-platform review covered macOS, Linux, and Windows storage/path behavior, Electron renderer trust boundaries, old main/remote payload fallback, and the SSH/folder-workspace case. Explicit API-key entry works when Cline runs in WSL because Orca owns the credential and performs the quota request. The remaining convenience gap is automatic import of credentials that exist only inside WSL.

Security Audit

The security review checked secret-at-rest handling, environment precedence, IPC sender authorization, renderer/remote exposure, auth-header/error leakage, redirect/proxy behavior, and save/clear/fetch races. It found and fixed two blocking issues before this PR was opened:

  • credential persistence now fails closed instead of degrading to plaintext when safeStorage is unavailable or Linux selects basic_text; users can use CLINE_API_KEY instead;
  • every clinePassCredentials:* handler now rejects untrusted renderers before reading, writing, clearing, or refreshing credentials.

The key is sent only as a fixed HTTPS Bearer header to api.cline.bot, is never returned to the renderer, and is never included in rate-limit state or logs.

Notes

@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 305ebd5c-4844-451a-9012-5b34acb2c20e

📥 Commits

Reviewing files that changed from the base of the PR and between 77ac12986c4f5d78e60eede86455553fe0ce74c2 and 2daf87b4f12db1780b3a0033e6a64c2c74f525c9.

📒 Files selected for processing (1)
  • src/main/rate-limits/clinepass-fetcher.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/rate-limits/clinepass-fetcher.test.ts

📝 Walkthrough

Walkthrough

Added encrypted ClinePass API-key storage with environment fallback and credential status reporting. Added trusted IPC and preload APIs for saving, reading, and clearing credentials. Added authenticated ClinePass quota fetching with session, weekly, and monthly windows. Integrated credential and quota state into refresh handling, settings, the status bar, tooltips, localization, web fallbacks, and status-bar migrations. Added comprehensive tests across these flows.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR meets provider, quota, status-bar, settings, error-state, and separation goals, but lacks automatic credential resolution from configured WSL state. Implement credential resolution from the configured Cline WSL or runtime state without requiring manual API-key entry or copying between environments.
Docstring Coverage ⚠️ Warning Docstring coverage is 10.53% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: API-key-based ClinePass usage tracking in the rate-limits feature.
Description check ✅ Passed The description covers scope, behavior, linked issue context, testing, security, and UI impact, but omits several template headings and required visual proof.
Out of Scope Changes check ✅ Passed The changes focus on ClinePass credential storage, fetching, rate-limit state, settings, status-bar presentation, localization, and related tests.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 19ba095b-b0b3-4491-9bee-e554592bb95a

📥 Commits

Reviewing files that changed from the base of the PR and between a0a654c and 94cf2f1a1debc4ca63286523abeccabad2c4e189.

📒 Files selected for processing (44)
  • src/main/clinepass/clinepass-api-key-store.test.ts
  • src/main/clinepass/clinepass-api-key-store.ts
  • src/main/ipc/clinepass-credentials.test.ts
  • src/main/ipc/clinepass-credentials.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/main/rate-limits/clinepass-fetcher.test.ts
  • src/main/rate-limits/clinepass-fetcher.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/service.ts
  • src/main/runtime/rpc/methods/client-ui-schemas.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/settings/ClinePassAccountsSection.test.tsx
  • src/renderer/src/components/settings/ClinePassAccountsSection.tsx
  • src/renderer/src/components/settings/ClinePassApiKeyForm.tsx
  • src/renderer/src/components/settings/ClinePassCredentialStatus.tsx
  • src/renderer/src/components/settings/accounts-search.test.ts
  • src/renderer/src/components/settings/accounts-search.ts
  • src/renderer/src/components/settings/appearance-status-bar-search.test.ts
  • src/renderer/src/components/settings/appearance-status-bar-search.ts
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/StatusBarUsageEmptyCta.tsx
  • src/renderer/src/components/status-bar/status-bar-agent-gating.test.ts
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.ts
  • src/renderer/src/components/status-bar/tooltip.test.ts
  • src/renderer/src/components/status-bar/tooltip.tsx
  • src/renderer/src/components/status-bar/usage-error-copy.test.ts
  • src/renderer/src/components/status-bar/usage-error-copy.ts
  • src/renderer/src/components/status-bar/usage-provider-settings-target.test.ts
  • src/renderer/src/components/status-bar/usage-provider-settings-target.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/store/slices/rate-limits.test.ts
  • src/renderer/src/store/slices/rate-limits.ts
  • src/renderer/src/store/slices/ui.test.ts
  • src/renderer/src/store/slices/ui.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/clinepass-credentials.ts
  • src/shared/rate-limit-types.test.ts
  • src/shared/rate-limit-types.ts
  • src/shared/status-bar-defaults.ts
  • src/shared/types.ts

@euclodius euclodius changed the title feat(rate-limits): add ClinePass usage tracking feat(rate-limits): add API-key-based ClinePass usage tracking Aug 11, 2026
@euclodius

euclodius commented Aug 11, 2026 •

Copy link
Copy Markdown
Author

Clarification on the WSL scope: this implementation deliberately treats the ClinePass API key as an Orca-owned credential. The user enters CLINE_API_KEY once in Orca Settings; the Windows Orca process stores it with Electron safeStorage and queries the Cline API directly. The Cline agent can still run in WSL—quota retrieval does not depend on the agent runtime, so manually providing the key is sufficient for a Windows + WSL setup.

WSL-specific credential resolution would only be needed as a convenience feature to automatically reuse an environment variable or CLI session that exists exclusively inside a WSL distribution. This PR does not claim automatic import of WSL Cline CLI authentication; it provides the explicit API-key path, which does not require such discovery.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/i18n/locales/en.json (1)

10604-10636: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Complete the environment-key description.

Change "A saved key overrides the environment" to "A saved key overrides the environment variable."


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f8f3720-7305-4f4f-b530-b61dd4793006

📥 Commits

Reviewing files that changed from the base of the PR and between 94cf2f1a1debc4ca63286523abeccabad2c4e189 and eec5ab02b7c1b98009184ec48425028eedc131f3.

📒 Files selected for processing (5)
  • src/renderer/src/components/settings/ClinePassAccountsSection.test.tsx
  • src/renderer/src/components/settings/ClinePassCredentialStatus.tsx
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/usage-error-copy.ts
  • src/renderer/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/renderer/src/components/settings/ClinePassCredentialStatus.tsx
  • src/renderer/src/components/status-bar/usage-error-copy.ts
  • src/renderer/src/components/status-bar/StatusBar.tsx

@euclodius

Copy link
Copy Markdown
Author

Addressed the follow-up CodeRabbit suggestion from the outside-diff review in 2fda6a66e: the copy now says “A saved key overrides the environment variable.” The source fallback, canonical localization key/catalog entry, and focused assertion were updated together. Settings test (11/11), web typecheck, localization catalog/extraction, and changed-code quality all pass.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d036aa88-794e-4ce0-a55a-05aeaae16c07

📥 Commits

Reviewing files that changed from the base of the PR and between d957e1c and 77ac12986c4f5d78e60eede86455553fe0ce74c2.

📒 Files selected for processing (44)
  • src/main/clinepass/clinepass-api-key-store.test.ts
  • src/main/clinepass/clinepass-api-key-store.ts
  • src/main/ipc/clinepass-credentials.test.ts
  • src/main/ipc/clinepass-credentials.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/main/rate-limits/clinepass-fetcher.test.ts
  • src/main/rate-limits/clinepass-fetcher.ts
  • src/main/rate-limits/service.test.ts
  • src/main/rate-limits/service.ts
  • src/main/runtime/rpc/methods/client-ui-schemas.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/settings/ClinePassAccountsSection.test.tsx
  • src/renderer/src/components/settings/ClinePassAccountsSection.tsx
  • src/renderer/src/components/settings/ClinePassApiKeyForm.tsx
  • src/renderer/src/components/settings/ClinePassCredentialStatus.tsx
  • src/renderer/src/components/settings/accounts-search.test.ts
  • src/renderer/src/components/settings/accounts-search.ts
  • src/renderer/src/components/settings/appearance-status-bar-search.test.ts
  • src/renderer/src/components/settings/appearance-status-bar-search.ts
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/StatusBarUsageEmptyCta.tsx
  • src/renderer/src/components/status-bar/status-bar-agent-gating.test.ts
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.ts
  • src/renderer/src/components/status-bar/tooltip.test.ts
  • src/renderer/src/components/status-bar/tooltip.tsx
  • src/renderer/src/components/status-bar/usage-error-copy.test.ts
  • src/renderer/src/components/status-bar/usage-error-copy.ts
  • src/renderer/src/components/status-bar/usage-provider-settings-target.test.ts
  • src/renderer/src/components/status-bar/usage-provider-settings-target.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/store/slices/rate-limits.test.ts
  • src/renderer/src/store/slices/rate-limits.ts
  • src/renderer/src/store/slices/ui.test.ts
  • src/renderer/src/store/slices/ui.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/clinepass-credentials.ts
  • src/shared/rate-limit-types.test.ts
  • src/shared/rate-limit-types.ts
  • src/shared/status-bar-defaults.ts
  • src/shared/types.ts
🚧 Files skipped from review as they are similar to previous changes (43)
  • src/renderer/src/components/status-bar/usage-error-copy.test.ts
  • src/main/ipc/register-core-handlers.ts
  • src/shared/status-bar-defaults.ts
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/shared/types.ts
  • src/renderer/src/components/status-bar/StatusBarUsageEmptyCta.tsx
  • src/renderer/src/components/status-bar/usage-provider-settings-target.test.ts
  • src/shared/rate-limit-types.test.ts
  • src/renderer/src/components/settings/accounts-search.test.ts
  • src/renderer/src/components/status-bar/status-bar-agent-gating.test.ts
  • src/main/ipc/register-core-handlers.test.ts
  • src/renderer/src/store/slices/ui.ts
  • src/preload/api-types.ts
  • src/renderer/src/store/slices/rate-limits.ts
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts
  • src/renderer/src/components/status-bar/usage-provider-settings-target.ts
  • src/renderer/src/store/slices/ui.test.ts
  • src/preload/index.ts
  • src/renderer/src/store/slices/rate-limits.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.ts
  • src/renderer/src/components/status-bar/tooltip.test.ts
  • src/main/ipc/clinepass-credentials.test.ts
  • src/main/runtime/rpc/methods/client-ui-schemas.ts
  • src/renderer/src/components/settings/appearance-status-bar-search.ts
  • src/renderer/src/components/settings/appearance-status-bar-search.test.ts
  • src/renderer/src/components/settings/ClinePassAccountsSection.tsx
  • src/renderer/src/components/status-bar/tooltip.tsx
  • src/renderer/src/components/status-bar/usage-error-copy.ts
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/main/rate-limits/service.test.ts
  • src/renderer/src/components/settings/ClinePassApiKeyForm.tsx
  • src/shared/rate-limit-types.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/renderer/src/components/settings/accounts-search.ts
  • src/renderer/src/components/settings/ClinePassAccountsSection.test.tsx
  • src/shared/clinepass-credentials.ts
  • src/main/clinepass/clinepass-api-key-store.ts
  • src/main/ipc/clinepass-credentials.ts
  • src/main/rate-limits/clinepass-fetcher.ts
  • src/main/clinepass/clinepass-api-key-store.test.ts
  • src/renderer/src/components/settings/ClinePassCredentialStatus.tsx
  • src/main/rate-limits/service.ts

@euclodius
euclodius force-pushed the feat/clinepass-usage branch 4 times, most recently from 4a97bbb to 82a999c Compare August 15, 2026 10:46
@euclodius
euclodius force-pushed the feat/clinepass-usage branch from 82a999c to 2dbf43e Compare August 17, 2026 09:49
@nwparker nwparker removed the P2 label Aug 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add ClinePass quota tracking to the status bar and AI Provider Accounts

4 participants