Skip to content

feat(status-bar): choose used or remaining usage - #7574

Merged
AmethystLiang merged 1 commit into
stablyai:mainfrom
suiramdev:feat/session-usage-used-toggle
Jul 11, 2026
Merged

AmethystLiang merged 1 commit into
stablyai:mainfrom
suiramdev:feat/session-usage-used-toggle

Conversation

@suiramdev

@suiramdev suiramdev commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add a Usage percentages segmented setting under Appearance → Window & Sidebar → Status Bar so users can choose Used or Remaining.
  • Persist the choice through the existing UI settings pipeline and normalize missing or invalid values to the current Used behavior.
  • Apply the preference to status-bar labels, provider detail panels, inactive-account previews, and Claude Fable usage across current providers.
  • Keep meter fill and color consumption-based in both modes, so empty/green still means little quota consumed and full/red means near the limit.

This revives the original proposal and implementation by @suiramdev on current main. It incorporates the persistence, provider-coverage, and test hardening from #8308 by @gatsby74, who is retained as a commit co-author.

Addresses #7551.
Fixes #8304.

Screen recording

trimmed.used.remaining.mov

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — 2,695 files passed; 28,339 tests passed; 7 files / 42 tests skipped
  • pnpm build — desktop, web, relay, CLI, and native macOS targets
  • Electron validation — switched both modes through the real Appearance UI, verified status-bar and provider-panel copy, confirmed consumption-based meter widths, and confirmed persistence after renderer reload
  • Added regression coverage for normalization, used/remaining formatting, preference persistence and hydration, settings search and interaction, Claude Fable/inactive-account rows, provider panel copy, and current usage providers

Review notes

  • Correctness: percentages are finite and bounded; Remaining is the complement of provider-reported usage; bar fill and color continue to represent consumption.
  • Desktop/web/remote: the preference uses the existing client UI state RPC and web-state merge path. It changes presentation only and makes no local-host assumption, so SSH and remote usage data follow the same renderer behavior.
  • Cross-platform: platform-neutral UI and persistence logic; no shortcuts, paths, shell behavior, or Electron platform branches were added.
  • Performance: one narrow scalar store subscription and constant-time formatting on already-rendered usage surfaces; no polling, provider fetches, listeners, subprocesses, or unbounded state.
  • UI quality: uses the existing settings-row and segmented-control primitives and documented tokens. Live Electron validation found no overlap, clipping, wrapping, or hierarchy regression.
  • Localization: English, Spanish, Japanese, Korean, and Chinese copy is included and catalog/coverage checks pass.

Security audit

  • The persisted value is a two-value enum validated by the existing UI RPC schema and normalized at persistence/hydration boundaries.
  • Provider percentages are checked for finiteness, clamped to 0–100, and rounded before display.
  • No command execution, filesystem/path handling, network request, authentication flow, credential handling, dependency, or new IPC channel was added.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a persisted UI setting, usageShowUsed, that switches status bar and tooltip usage indicators between “% left” and “% used”. It updates the RPC schema, persisted UI types, store slice, settings UI, status bar and tooltip rendering, tests, and locale strings in five languages. A separate change replaces a default switch branch with case null in the source control manual review URL builder.

Changes

Cohort / File(s) Summary
Schema & store Add usageShowUsed to RPC validation, persisted UI state, and UI store update/hydration paths
Settings UI Add a searchable toggle for the usage display option
Status bar Update usage rendering and add a dropdown toggle for used/left display
Tooltip Add showUsed handling to ProviderPanel and switch bar/label rendering
Tests Add coverage for used-percent rendering in status bar and tooltip
Localization Add toggle, label, and settings copy strings across locale files
Unrelated Change switch fallback from default: to case null:

Sequence Diagram(s)

sequenceDiagram
  participant StatusBarInner
  participant AppStore
  participant ProviderSegment
  participant WindowLabel
  StatusBarInner->>AppStore: setUsageShowUsed(!usageShowUsed)
  AppStore-->>ProviderSegment: usageShowUsed
  ProviderSegment->>WindowLabel: showUsed prop
  WindowLabel-->>ProviderSegment: shown percentage (used or left)
Loading

Related issues: None identified.

Related PRs: None identified.

Suggested labels: enhancement, ui, i18n

Suggested reviewers: Not determinable from provided context.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes an unrelated source-control switch-exhaustiveness fix in source-control-manual-review-url.ts that is outside the session-usage toggle scope. Move the source-control/manual-review-url cleanup into a separate PR, or remove it if it is not required for this feature.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR implements the linked #7551 request by adding a toggle that switches Session Usage between remaining and used across the main UI surfaces.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and accurately summarizes the main change: choosing used versus remaining usage display.
Description check ✅ Passed It covers the main required content, including summary, visuals, testing, review notes, and security audit, with only minor heading mismatches.

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.

🧹 Nitpick comments (3)
src/renderer/src/components/status-bar/StatusBar.tsx (2)

911-946: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract repeated left/shown computation into a helper.

The session/weekly/fableWeekly blocks each repeat the same left/shown formula. Adding shown doubled the duplicated logic; a small helper keeps the three call sites in sync if the formula changes again.

♻️ Proposed refactor
+function computeUsageWindow(
+  key: string,
+  w: RateLimitWindow | null | undefined,
+  showUsed: boolean,
+  label: string
+): { key: string; left: number; shown: number; label: string } | null {
+  if (!w) return null
+  const left = Math.max(0, Math.round(100 - w.usedPercent))
+  const shown = showUsed ? Math.min(100, Math.max(0, Math.round(w.usedPercent))) : left
+  return { key, left, shown, label }
+}
+
 const usageWindows = [
-  limits.session
-    ? {
-        key: 'session',
-        left: Math.max(0, Math.round(100 - limits.session.usedPercent)),
-        shown: showUsed
-          ? Math.min(100, Math.max(0, Math.round(limits.session.usedPercent)))
-          : Math.max(0, Math.round(100 - limits.session.usedPercent)),
-        label: translate('auto.components.status.bar.StatusBar.d79c3362c4', '% 5h')
-      }
-    : null,
-  limits.weekly
-    ? {
-        key: 'weekly',
-        left: Math.max(0, Math.round(100 - limits.weekly.usedPercent)),
-        shown: showUsed
-          ? Math.min(100, Math.max(0, Math.round(limits.weekly.usedPercent)))
-          : Math.max(0, Math.round(100 - limits.weekly.usedPercent)),
-        label: translate('auto.components.status.bar.StatusBar.5c938d39ac', '% wk')
-      }
-    : null,
-  limits.fableWeekly
-    ? {
-        key: 'fableWeekly',
-        left: Math.max(0, Math.round(100 - limits.fableWeekly.usedPercent)),
-        shown: showUsed
-          ? Math.min(100, Math.max(0, Math.round(limits.fableWeekly.usedPercent)))
-          : Math.max(0, Math.round(100 - limits.fableWeekly.usedPercent)),
-        label: translate('auto.components.status.bar.StatusBar.54e8d6bb2d', '% Fable')
-      }
-    : null
+  computeUsageWindow(
+    'session',
+    limits.session,
+    showUsed,
+    translate('auto.components.status.bar.StatusBar.d79c3362c4', '% 5h')
+  ),
+  computeUsageWindow(
+    'weekly',
+    limits.weekly,
+    showUsed,
+    translate('auto.components.status.bar.StatusBar.5c938d39ac', '% wk')
+  ),
+  computeUsageWindow(
+    'fableWeekly',
+    limits.fableWeekly,
+    showUsed,
+    translate('auto.components.status.bar.StatusBar.54e8d6bb2d', '% Fable')
+  )
 ].filter(
   (window): window is { key: string; left: number; shown: number; label: string } =>
     window !== null
 )

2204-2213: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

New toggle skips recordFeatureInteraction.

Every other checkbox item in this menu (Claude, Codex, Gemini, OpenCode Go, Kimi, MiniMax, SSH, Resource Manager, Ports) calls recordFeatureInteraction on change. This new item doesn't, so usage-toggle interactions won't be tracked consistently.

🔧 Proposed fix
           <DropdownMenuCheckboxItem
             checked={usageShowUsed}
-            onCheckedChange={() => setUsageShowUsed(!usageShowUsed)}
+            onCheckedChange={() => {
+              recordFeatureInteraction('usage-tracking')
+              setUsageShowUsed(!usageShowUsed)
+            }}
           >
src/renderer/src/components/settings/AppearanceWindowSidebarSection.tsx (1)

164-176: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Usage toggle skips feature-interaction recording used by sibling toggles.

Every other status-bar toggle in this list calls recordStatusBarToggleInteraction(toggle.id, recordFeatureInteraction) before mutating state; the new usage-display switch calls setUsageShowUsed(!usageShowUsed) directly with no interaction tracking. If usage/adoption of this toggle needs to be observable like the others, consider recording it too.

♻️ Optional: record the interaction like sibling toggles
                 <SettingsSwitchRow
                   label={usageDisplayTitle}
                   description={usageDisplayDescription}
                   checked={usageShowUsed}
-                  onChange={() => setUsageShowUsed(!usageShowUsed)}
+                  onChange={() => {
+                    recordFeatureInteraction('usageShowUsed')
+                    setUsageShowUsed(!usageShowUsed)
+                  }}
                   ariaLabel={usageDisplayTitle}
                 />

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 353c96bd-a657-4b38-97ed-bb3008f4efb4

📥 Commits

Reviewing files that changed from the base of the PR and between 9d9ebe6 and 81dedc0b5b0430c28b2e9774f06f729a82b1982a.

📒 Files selected for processing (14)
  • src/main/runtime/rpc/methods/client-ui.ts
  • src/renderer/src/components/right-sidebar/source-control-manual-review-url.ts
  • src/renderer/src/components/settings/AppearanceWindowSidebarSection.tsx
  • src/renderer/src/components/status-bar/StatusBar.tsx
  • src/renderer/src/components/status-bar/inline-usage-bars.test.tsx
  • src/renderer/src/components/status-bar/tooltip.test.ts
  • src/renderer/src/components/status-bar/tooltip.tsx
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/store/slices/ui.ts
  • src/shared/types.ts

@suiramdev

Copy link
Copy Markdown
Contributor Author

I’ve also tested it. I just updated the PR description to include screenshots of the output.

@suiramdev
suiramdev force-pushed the feat/session-usage-used-toggle branch from 81dedc0 to 97e5b6c Compare July 7, 2026 15:03
@AmethystLiang

AmethystLiang commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Really thoughtful PR — thank you for shipping this.

Your framing of the problem def inspired us to fix the display. We ended up using a hard-coded session usage to % used everywhere in #8167, with the bar fill/color and labels aligned the same way.

Closing this as superseded by #8167 / the hard-coded flip.

Please keep the PRs coming — thank you so much for this one and we'll get your next one in!

Add a persisted Appearance setting that switches provider usage labels between percent used and percent remaining while keeping meter fill consumption-based.

Cover desktop and web persistence, current providers, settings search, localized copy, and regression tests.

Co-authored-by: gatsby74 <[email protected]>
@AmethystLiang AmethystLiang reopened this Jul 11, 2026
@AmethystLiang AmethystLiang changed the title feat(status-bar): toggle session usage between used and remaining feat(status-bar): choose used or remaining usage Jul 11, 2026
@AmethystLiang

Copy link
Copy Markdown
Contributor

@suiramdev I’ve revived this so we can land your original contribution with you as the primary author. I have the current-main implementation fully reviewed and validated, but GitHub is rejecting the branch update because Allow edits from maintainers is currently disabled on this PR. Could you enable that checkbox? Once enabled, I’ll push the update, run CI, and merge it. Thanks again for starting this.

@AmethystLiang
AmethystLiang force-pushed the feat/session-usage-used-toggle branch from 97e5b6c to 75f304a Compare July 11, 2026 20:31

@AmethystLiang AmethystLiang 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.

Thanks @suiramdev — revived and updated on current main with you retained as the primary author. This now uses an explicit Used/Remaining preference, covers desktop/web persistence and current providers, keeps meter direction consumption-based, and includes localized regression coverage. I incorporated the hardening from #8308 with @gatsby74 retained as a commit co-author. Full tests, lint, typecheck, build, and live Electron validation all passed locally.

@AmethystLiang
AmethystLiang merged commit 6d3ab9f into stablyai:main Jul 11, 2026
3 checks passed
AmethystLiang added a commit that referenced this pull request Jul 12, 2026
* fix: work-item naming, usage % rounding, and terminal/delete copy

Address prod-release-scan P2s:

- #8238: recognize Bitbucket Server (/projects|users/.../repos/.../pull-requests/N)
  and Azure DevOps (/_git/REPO/pullrequest/N) PR URL shapes in
  work-item-reference, alongside Bitbucket Cloud; graceful fallback preserved.

- #7574: getDisplayedUsagePercentage now rounds the used value before taking the
  `remaining` complement, so the compact status bar (raw usedPercent) and tooltip
  (pre-rounded clampUsedPercent) can no longer disagree by 1% at a .5 fraction.
  clampUsedPercent moves to the shared module as the single rounding source.

- #7459: mixed remote+local batch delete confirm no longer claims the whole
  batch is a permanent "remote host" delete — it now states remote items are
  permanent while local items move to the Trash/Recycle Bin.

- #8322: right-click-to-paste settings copy is platform-aware — "Control-click"
  on macOS, "Ctrl+right-click" on Windows/Linux — matching the ctrlKey gate.

Localization catalog synced (also picks up pre-existing UsagePercentageDisplayChangeNotice drift).

* Fix NaN% usage bar and label for non-finite provider values

Non-finite usedPercent inputs (NaN/Infinity) propagated through Math.round/min/max into the CSS bar width (`NaN%`) and displayed copy. clampUsedPercent now short-circuits to 0 in that case, with a test covering the divergence from getDisplayedUsagePercentage for the 'remaining' case.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Add a persisted Appearance setting that switches provider usage labels between percent used and percent remaining while keeping meter fill consumption-based.

Cover desktop and web persistence, current providers, settings search, localized copy, and regression tests.

Co-authored-by: gatsby74 <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix: work-item naming, usage % rounding, and terminal/delete copy

Address prod-release-scan P2s:

- stablyai#8238: recognize Bitbucket Server (/projects|users/.../repos/.../pull-requests/N)
  and Azure DevOps (/_git/REPO/pullrequest/N) PR URL shapes in
  work-item-reference, alongside Bitbucket Cloud; graceful fallback preserved.

- stablyai#7574: getDisplayedUsagePercentage now rounds the used value before taking the
  `remaining` complement, so the compact status bar (raw usedPercent) and tooltip
  (pre-rounded clampUsedPercent) can no longer disagree by 1% at a .5 fraction.
  clampUsedPercent moves to the shared module as the single rounding source.

- stablyai#7459: mixed remote+local batch delete confirm no longer claims the whole
  batch is a permanent "remote host" delete — it now states remote items are
  permanent while local items move to the Trash/Recycle Bin.

- stablyai#8322: right-click-to-paste settings copy is platform-aware — "Control-click"
  on macOS, "Ctrl+right-click" on Windows/Linux — matching the ctrlKey gate.

Localization catalog synced (also picks up pre-existing UsagePercentageDisplayChangeNotice drift).

* Fix NaN% usage bar and label for non-finite provider values

Non-finite usedPercent inputs (NaN/Infinity) propagated through Math.round/min/max into the CSS bar width (`NaN%`) and displayed copy. clampUsedPercent now short-circuits to 0 in that case, with a test covering the divergence from getDisplayedUsagePercentage for the 'remaining' case.
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]: Show amount 'left' per account, not amount 'used'

3 participants