Skip to content

feat(mobile): show all usage providers with visibility controls - #9274

Closed
bbingz wants to merge 9 commits into
stablyai:mainfrom
bbingz:feat/mobile-provider-usage-continuation
Closed

bbingz wants to merge 9 commits into
stablyai:mainfrom
bbingz:feat/mobile-provider-usage-continuation

Conversation

@bbingz

@bbingz bbingz commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Continues and supersedes #8571 by @audichuang.

  • Preserves the original author's three commits and authorship, then resolves the current main conflicts on top.
  • Gives mobile the same eight usage providers exposed by desktop: Claude, Codex, Gemini, Antigravity, OpenCode Go, Kimi, MiniMax, and Grok.
  • Adds Settings → Account usage switches. Claude and Codex remain enabled by default; the persisted selection controls both Home and each host's Accounts screen.
  • Keeps Claude/Codex account switching unchanged. The other six providers are display-only and render their actual named buckets or session/weekly/monthly windows, including reset countdowns on the detailed Accounts screen.
  • Handles legacy cached snapshots, rapid/concurrent preference writes, failed writes, focus reloads, loading/error/stale data, and non-finite percentages safely.

Screenshots

Mobile viewport (390 × 844), showing the default Claude + Codex selection and all eight provider controls:

Mobile Account usage settings showing all eight providers

Testing

  • corepack [email protected] --dir mobile lint
  • corepack [email protected] --dir mobile typecheck
  • corepack [email protected] --dir mobile test — 290 files passed; 2080 tests passed, 2 skipped
  • CI=true corepack [email protected] --dir mobile exec expo export --platform web
  • Added regression coverage for all provider mappings, Antigravity/legacy snapshots, dynamic windows and reset labels, Home/Accounts visibility, focus/write races, settings accessibility, persistence failures, and display-only Accounts rendering
  • Playwright mobile-web smoke at 390 × 844: all eight switches exposed with stable accessible names; Antigravity persisted across reload; no feature console errors
  • Root pnpm build — not run; this is mobile-only, and the mobile production export above is the relevant build gate
  • Native iOS/Android visual smoke — no installed simulator/emulator was available on this host

AI Review Report

Claude Opus (claude-opus-4-8) reviewed the full origin/main..HEAD diff after the latest main merge and returned Ready to merge: Yes with no Critical or Important findings.

Earlier review rounds caught or prompted verification of focus-refresh coverage, dynamic bucket + weekly/monthly coexistence, the preference write/return race, Accounts display-only render coverage, and non-finite usage handling. Those items were fixed or adjudicated against source and covered by tests before the final approval.

Cross-platform review found no new shortcut, label, filesystem-path, shell, or Electron platform behavior. The UI uses React Native primitives and existing theme tokens. Remote/SSH hosts use the existing host-scoped accounts.list / accounts.subscribe RPC; current main was verified to send the full eight-provider RateLimitState.

Security Audit

  • No dependencies, command execution, shell input, path handling, auth flows, IPC methods, or secret storage were added.
  • Preference input is restricted to the canonical provider allowlist; unknown/stale IDs are discarded.
  • Existing account-selection RPC remains statically limited to Claude and Codex; display-only providers cannot route to account switching.
  • Usage snapshots contain the same account/rate-limit metadata already exposed by the existing Accounts RPC. No tokens or credentials are added to the payload.

Notes

ELI5

Mobile can show the same set of usage providers as desktop, with settings toggles for which ones appear. You control visibility on Home and each host's Accounts screen.

@coderabbitai

coderabbitai Bot commented Jul 18, 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
📝 Walkthrough

Walkthrough

The mobile app now supports visibility controls for eight account-usage providers. Visibility preferences are loaded, normalized, persisted with serialized updates, and exposed through a new settings route and focus-aware hook. Home and account usage screens render selected managed and display-only providers using shared usage-window components. Provider state selectors now support additional snapshot fields, dynamic windows, reset labels, and expanded renderability rules, with tests covering persistence, settings interactions, selectors, and rendering.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding usage-provider visibility controls on mobile.
Description check ✅ Passed The description includes all required sections and gives a mostly complete summary, testing, review, security, and notes.
Linked Issues check ✅ Passed The changes match #8571: eight providers, visibility settings, managed vs display-only behavior, window rendering, and race-safe persistence.
Out of Scope Changes check ✅ Passed The diff appears focused on the mobile usage-provider feature and related tests, with no clear unrelated scope creep.

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

Run ID: 7b9e8cbd-6212-4fc7-8d1a-9d3d02fe0927

📥 Commits

Reviewing files that changed from the base of the PR and between 0532765 and 383d7b0d28df857faa67b0877adbb72696184161.

📒 Files selected for processing (16)
  • mobile/app/_layout.tsx
  • mobile/app/account-usage-settings.tsx
  • mobile/app/h/[hostId]/accounts.tsx
  • mobile/app/index.tsx
  • mobile/app/settings.tsx
  • mobile/src/account-usage-settings-route.test.ts
  • mobile/src/accounts-route-display-provider.test.ts
  • mobile/src/components/AccountUsage.tsx
  • mobile/src/components/HomeAccountUsageCard.tsx
  • mobile/src/components/account-usage-state.test.ts
  • mobile/src/components/account-usage-state.ts
  • mobile/src/components/home-account-usage-card.test.ts
  • mobile/src/components/use-visible-usage-providers.test.ts
  • mobile/src/components/use-visible-usage-providers.ts
  • mobile/src/storage/preferences.test.ts
  • mobile/src/storage/preferences.ts

Comment thread mobile/src/storage/preferences.ts Resolved
@AmethystLiang AmethystLiang self-assigned this Jul 18, 2026
@AmethystLiang
AmethystLiang self-requested a review July 18, 2026 16:47
@bbingz
bbingz force-pushed the feat/mobile-provider-usage-continuation branch from d9d43e5 to 8afd15c Compare July 22, 2026 01:35
@bbingz

bbingz commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (34c160442f9e77d8162b4c54ecd9b39f0ba6a4f2). Conflicts resolved in: AccountUsage.tsx / account-usage-state.ts (multi-provider windows + main reset countdown), index.tsx (HomeAccountUsageCard), preferences.test.ts (visibility prefs imports). Ready for re-review.

@bbingz

bbingz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current origin/main (6d55c7fa16).

Kept main's clockEnabled/useNow focus clock and this PR's usage-provider visibility (useVisibleUsageProviders + Gauge), cleaning up a post-restack duplicate state declaration.

Branch is restacked and ready for re-review.

@bbingz
bbingz force-pushed the feat/mobile-provider-usage-continuation branch from 8afd15c to f5604b0 Compare July 23, 2026 02:22
audichuang and others added 9 commits July 26, 2026 15:24
桌面已支援 Claude/Codex/Gemini/OpenCode Go/Kimi/MiniMax/Grok 的用量顯示,
行動端卻只顯示 Claude+Codex。此變更讓行動端顯示全部 provider,並於
Settings → Account usage 提供每個 provider 的開關(預設只開 Claude+Codex,
其餘 opt-in,避免手機一次塞滿)。

- 純 client 變更:host 已在 accounts.list / accounts.subscribe 的 snapshot
  送出完整 RateLimitState,零後端 / 協定改動。
- 拆 ManagedAccountProviderKey(可切換)vs UsageProviderKey(唯讀顯示);
  display-only provider 走不可點路徑,不會觸發帳號切換。
- 以 canonical descriptor 對應 wire id 與 snapshot 欄位(解 opencode-go /
  opencodeGo 不一致);新欄位為 optional 並以 ?? null 正規化舊 v1 快取。
- getProviderUsageWindows 依實際視窗渲染:Gemini 具名 buckets、OpenCode Go
  monthly、其餘 session/weekly,不再硬寫 5h/7d。
- 可見性偏好存於本地 AsyncStorage,沿用既有 focus-reload 慣例。
- home 卡片抽成 HomeAccountUsageCard 以符合 max-lines。
… load

The Account-usage settings screen started on the default set {claude,codex}
while the stored visibility set loaded asynchronously. A toggle fired before
that load resolved persisted the whole set against the stale default, silently
dropping any provider that lived only in the stored set (e.g. an opted-in
Grok).

- Gate the switches until the stored set loads, so no toggle can persist
  against the default base.
- Move persistence to a serialized read-modify-write in preferences
  (`setUsageProviderVisible`): each toggle re-reads the latest stored set and
  changes only its own provider, so concurrent toggles can't clobber each
  other and the write survives an unmount.
- Load once on mount via a settled read (the screen is the sole writer), so a
  focus-reload can't overwrite the optimistic UI with a pre-write snapshot.
- Distinguish an I/O read failure (abort the write) from corrupt content
  (missing / malformed JSON / non-array → re-base on the default and self-heal).

Tests cover: stored-only provider survives a pre-load toggle, concurrent
toggles serialize, I/O read failure aborts the write, malformed JSON self-heals.
…11y, guard NaN

Review follow-ups on the multi-provider usage feature:
- The Home usage card now keeps a display-only provider visible while it is
  fetching or in error (spinner / last bars) instead of dropping it, matching
  the accounts screen and making the previously-unreachable fetching branch
  reachable.
- Each visibility Switch gets an accessibilityLabel so a screen reader names
  the provider being toggled.
- UsageBar treats a non-finite percent (NaN/Infinity) as no data so it never
  renders `width: "NaN%"`.
@bbingz
bbingz force-pushed the feat/mobile-provider-usage-continuation branch from f5604b0 to 0ad8149 Compare July 26, 2026 07:29

@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)
mobile/src/components/accounts-snapshot.ts (1)

88-98: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject WSL runtime metadata without a distro.

Both refinements accept runtime: 'wsl' with no wslDistro. That permits an ambiguous WSL target through decoding, despite the accounts route using it for targeted Codex account selection.

  • mobile/src/components/accounts-snapshot.ts#L88-L98: require a non-empty, untrimmed wslDistro whenever runtime is wsl.
  • mobile/src/components/accounts-snapshot.ts#L157-L167: enforce the same invariant for WSL-managed Codex accounts.
  • mobile/src/components/accounts-snapshot.test.ts#L144-L149: add rejection cases for WSL runtime values with null or omitted distros.
Proposed validation change
-    if (
-      target.runtime === 'wsl' &&
-      target.wslDistro !== null &&
-      target.wslDistro.trim() !== target.wslDistro
-    ) {
+    if (
+      target.runtime === 'wsl' &&
+      (target.wslDistro === null || target.wslDistro.trim() !== target.wslDistro)
+    ) {

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b959ae4f-185e-46a0-af82-496addfee187

📥 Commits

Reviewing files that changed from the base of the PR and between f5604b0 and 0ad8149.

📒 Files selected for processing (18)
  • mobile/app/_layout.tsx
  • mobile/app/account-usage-settings.tsx
  • mobile/app/h/[hostId]/accounts.tsx
  • mobile/app/index.tsx
  • mobile/app/settings.tsx
  • mobile/src/account-usage-settings-route.test.ts
  • mobile/src/accounts-route-display-provider.test.ts
  • mobile/src/components/AccountUsage.tsx
  • mobile/src/components/HomeAccountUsageCard.tsx
  • mobile/src/components/account-usage-state.test.ts
  • mobile/src/components/account-usage-state.ts
  • mobile/src/components/accounts-snapshot.test.ts
  • mobile/src/components/accounts-snapshot.ts
  • mobile/src/components/home-account-usage-card.test.ts
  • mobile/src/components/use-visible-usage-providers.test.ts
  • mobile/src/components/use-visible-usage-providers.ts
  • mobile/src/storage/preferences.test.ts
  • mobile/src/storage/preferences.ts
🚧 Files skipped from review as they are similar to previous changes (12)
  • mobile/src/components/HomeAccountUsageCard.tsx
  • mobile/src/components/home-account-usage-card.test.ts
  • mobile/src/account-usage-settings-route.test.ts
  • mobile/src/accounts-route-display-provider.test.ts
  • mobile/app/settings.tsx
  • mobile/src/storage/preferences.test.ts
  • mobile/app/account-usage-settings.tsx
  • mobile/app/h/[hostId]/accounts.tsx
  • mobile/src/components/AccountUsage.tsx
  • mobile/app/index.tsx
  • mobile/src/storage/preferences.ts
  • mobile/src/components/account-usage-state.test.ts

@nwparker nwparker added the enhancement New feature or request label Jul 27, 2026
@bbingz

bbingz commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Closing as part of fork PR backlog cleanup.

This branch is long-conflicted (DIRTY) against current main and is not on the active campaign rebase list. Feel free to reopen or cut a fresh PR from an updated branch if the change is still needed.

@bbingz bbingz closed this Aug 10, 2026
karlorz added a commit to karlorz/orca that referenced this pull request Aug 26, 2026
Port stablyai#9274 onto fork-main. Claude and Codex stay default-on.
Grok and the other extra providers are Settings → Account usage opt-in.
No versionCode bump.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants