Skip to content

Publish live Grok tokens and xAI spend into Usage & Spend - #3085

Merged
steipete merged 13 commits into
steipete:mainfrom
Chipagosfinest:agent/grok-xai-live-spend
Aug 20, 2026
Merged

Publish live Grok tokens and xAI spend into Usage & Spend#3085
steipete merged 13 commits into
steipete:mainfrom
Chipagosfinest:agent/grok-xai-live-spend

Conversation

@Chipagosfinest

@Chipagosfinest Chipagosfinest commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Put enabled Grok and xAI into the shared Usage & Spend catalog that Overview already counts.
  • Map xAI Management API daily spend (the existing billing chart) as vendor-metered USD. Prepaid ledger balance stays remaining credit, not spend.
  • Map Grok ~/.grok/sessions/**/signals.json into per-day token buckets. SuperGrok/X Premium+ credits stay a quota window and are never converted into dollars.
  • UTC day labels for xAI follow the same dashboard calendar mapping as Mistral and OpenRouter.

This continues the Overview spend work in #3023, #3054, #3063, and #3067: every enabled subscription should contribute the strongest truthful signal instead of silently dropping out.

Why this slice

#2759 / #2855 were closed so review could happen concern-by-concern. After #3067, Grok and xAI were still supportsTokenCost: false, so they inflated Overview coverage (x of y subscriptions have spend) without publishing live data.

Test plan

  • GrokLocalSessionScannerTests — daily local buckets, no invented dollars, empty home publishes nothing, and local scan time owns Today
  • XAICostUsageMappingTests — chart → vendor-metered catalog; prepaid balance alone is not spend; partial history stays estimated
  • GrokXAISpendCatalogTests — both providers are snapshot-backed spend sources plus opt-in redacted live catalog proof
  • XAIProviderTests — existing golden balance/chart behavior unchanged; malformed successful history stays unavailable
  • GrokMenuCardModelTests — credit-bar presentation unchanged
  • PopupLocalizationTests — OpenRouter generic details localize titles/row labels via L() after 84a4ca7, while values and chart points stay canonical

Exact-head verification

Verified on a4f80675a4d1a2d1d76beafd335be6e2a5267002 after rebase onto main and Peter's merge of 84a4ca725:

make check
# passed: SwiftFormat, SwiftLint, JS/TS lint, generated-resource and repository gates

swift test --filter PopupLocalizationTests
# 6 tests in 1 suite passed

swift test --filter 'PopupLocalizationTests|GrokLocalSessionScannerTests|XAICostUsageMappingTests|XAIProviderTests|GrokXAISpendCatalogTests'
# 29 tests in 5 suites passed on the prior head; PopupLocalizationTests re-verified on this head

Redacted after-fix output from the real local Grok scanner through SpendDashboardModel.build:

catalog_source=grok
today_tokens=4841945
last_30_days_tokens=4841945
daily_buckets=1
available_sources=grok

No paths, account identifiers, session identifiers, prompts, or model names are included in this proof.

Residual risk

  • xAI still needs a Management API key + team ID for dollars to appear. Without them the provider stays enabled and reports unavailable, not $0.
  • Grok token totals are local session signals, not the SuperGrok bill. That is intentional.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

Chipagosfinest added a commit to Chipagosfinest/CodexBar that referenced this pull request Aug 20, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 26fd232eef

ℹ️ 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".

Comment thread Sources/CodexBarCore/Providers/XAI/XAICostUsageMapping.swift Outdated
Comment thread Sources/CodexBar/UsageStore+TokenCost.swift
Comment thread Sources/CodexBarCore/Providers/XAI/XAICostUsageMapping.swift Outdated
Comment thread Sources/CodexBarCore/Providers/Grok/GrokLocalSessionScanner.swift Outdated
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codex review: needs changes before merge. Reviewed August 20, 2026, 8:17 AM ET / 12:17 UTC.

ClawSweeper review

What this changes

This PR adds Grok local-session token history and xAI Management API daily spend to CodexBar’s shared Usage & Spend catalog.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep open: the current head still rescans Grok session files while constructing the dashboard request, contrary to the shared catalog’s cache-only UI boundary. The existing redacted terminal proof is sufficient for the intended local-token behavior, but this P2 performance/availability issue must be fixed before merge.

Priority: P2
Reviewed head: a45b4854d0e0d161aea8c770e65b74b36adfc366

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful feature work with credible local proof, capped by the unresolved main-actor scanner path.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body supplies redacted after-fix terminal output from a real local Grok scanner through the shared catalog; redact the same classes of local data in any follow-up proof.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body supplies redacted after-fix terminal output from a real local Grok scanner through the shared catalog; redact the same classes of local data in any follow-up proof.
Evidence reviewed 5 items UI-path filesystem scan: The Grok-specific branch calls the token mapper during request construction; that mapper enumerates ~/.grok/sessions and reads signals.json files rather than using the publication captured around refresh.
Shared-catalog contract: Repository research explicitly requires menu construction to remain cache-only and prohibits filesystem scans on that path.
Current-line provenance: Blame attributes the remaining Grok bypass to the current PR head; it is also the same unresolved P2 noted in the prior ClawSweeper review cycle.
Findings 2 actionable findings [P2] Use the published Grok snapshot
[P3] Remove the release-owned changelog entry
Security None None.

Live Verification

Command: swift run codexbar --help

Result: FAIL (failed) — execution before step 1 run: sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.22.0.tgz

sh -lc pnpm install --ignore-scripts --frozen-lockfile failed: ! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-11.22.0.tgz

Assertions:

  • FAIL expect_output: Print local cost usage as text or JSON

How this fits together

Provider probes and local session data are converted into token/spend snapshots, then published to a shared catalog consumed by Overview and the Usage & Spend dashboard. Grok contributes local token totals, while xAI contributes vendor-metered daily USD spend.

flowchart LR
A[Provider API and local session data] --> B[Provider snapshots]
B --> C[Published spend catalog]
C --> D[Overview]
C --> E[Usage and Spend dashboard]
F[Refresh pipeline] --> C
Loading

Before merge

  • Use the published Grok snapshot (P2) - This branch still calls tokenSnapshot while building the main-actor dashboard request. For Grok that enumerates and reads every local session file, despite the refresh pipeline already publishing the refreshed snapshot. Use the captured current publication so menu/dashboard construction stays cache-only and large session trees cannot stall it.
  • Remove the release-owned changelog entry (P3) - CHANGELOG.md is release-owned under the repository policy, so this normal feature PR should not add its own release note. Leave release-note context in the PR description instead.
  • Resolve merge risk (P1) - A large ~/.grok/sessions tree can be enumerated and parsed on the main-actor dashboard/menu request path, causing visible stalls and bypassing publication revisions.
  • Complete next step (P2) - The two remaining findings are a narrow mechanical repair on the existing PR branch.

Findings

  • [P2] Use the published Grok snapshot — Sources/CodexBar/SpendDashboardController.swift:276-279
  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:9
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
PR surface 20 files changed; +601/-82 lines The feature spans provider parsing, shared-catalog projection, documentation, and regression coverage.
Code versus tests production +238; tests +352/-61 The sizable production extension is paired with focused parser and catalog coverage, but the publication-boundary regression is still absent.

Merge-risk options

Maintainer options:

  1. Restore cache-only Grok projection (recommended)
    Remove the Grok request-path scanner bypass and use the validated current publication after refresh, with regression coverage that dashboard construction does not rescan sessions.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Consume the current Grok token publication in request construction, remove direct scanner calls from the dashboard path, add a cache-only regression, and remove the release-owned CHANGELOG entry.

Technical review

Best possible solution:

Publish Grok’s local scan during refresh, then have both Overview and Usage & Spend consume only the current validated publication; keep release notes owned by the release process.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: the main-actor request builder directly invokes a mapper that enumerates and reads Grok session files. A large session tree exercises the stall-prone path.

Is this the best way to solve the issue?

No. The existing immutable publication already carries the refreshed Grok snapshot; consuming it is narrower and preserves the documented cache-only rendering contract.

Full review comments:

  • [P2] Use the published Grok snapshot — Sources/CodexBar/SpendDashboardController.swift:276-279
    This branch still calls tokenSnapshot while building the main-actor dashboard request. For Grok that enumerates and reads every local session file, despite the refresh pipeline already publishing the refreshed snapshot. Use the captured current publication so menu/dashboard construction stays cache-only and large session trees cannot stall it.
    Confidence: 0.99
  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:9
    CHANGELOG.md is release-owned under the repository policy, so this normal feature PR should not add its own release note. Leave release-note context in the PR description instead.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e92d89ab2003.

Labels

Label justifications:

  • P2: The direct local scan can degrade active menu/dashboard responsiveness for users with many Grok sessions.
  • merge-risk: 🚨 availability: Merging preserves a main-actor filesystem scan in a path the repository defines as cache-only.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body supplies redacted after-fix terminal output from a real local Grok scanner through the shared catalog; redact the same classes of local data in any follow-up proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies redacted after-fix terminal output from a real local Grok scanner through the shared catalog; redact the same classes of local data in any follow-up proof.

Evidence

Acceptance criteria:

  • [P1] swift test --filter 'GrokLocalSessionScannerTests|GrokXAISpendCatalogTests'.
  • [P1] make check.

What I checked:

Likely related people:

  • steipete: Current-head blame assigns the affected dashboard path to this revision, and the feature history shows sustained ownership of the spend-controller area. (role: recent shared-catalog contributor; confidence: high; commits: a45b4854d0e0, 40297051639b; files: Sources/CodexBar/SpendDashboardController.swift, Sources/CodexBar/UsageStore+TokenCost.swift)
  • Chipagosfinest: The merged shared-catalog commit credits Alec Gutman, Chip, and this PR extends that architecture. (role: shared-catalog contributor; confidence: medium; commits: 40297051639b; files: docs/research/shared-spend-source-publications.md, Sources/CodexBar/SpendDashboardController.swift)
  • olddonkey: Recent Grok billing and settings-path commits establish relevant ownership of the adjacent provider behavior. (role: recent Grok-area contributor; confidence: medium; commits: 453e4f2a0480, c7a6355cee8a; files: Sources/CodexBarCore/Providers/Grok/GrokStatusProbe.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Replace the Grok scanner bypass with the captured publication and add a cache-only regression.
  • Remove the release-owned CHANGELOG.md entry.
  • Run the focused Grok/xAI tests and make check on the updated head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-20T01:15:17.742Z sha bef86db :: needs real behavior proof before merge. :: [P1] Preserve xAI analytics failures as unavailable | [P2] Publish Grok tokens without a remote snapshot | [P2] Use xAI’s current UTC day for Today | [P2] Use Grok’s current local-day bucket for Today | [P2] Limit xAI coverage to its 30-day response
  • reviewed 2026-08-20T01:36:58.552Z sha 4a93fbe :: needs real behavior proof before merge. :: [P1] Reject malformed xAI usage responses before publishing zero spend | [P2] Anchor Grok’s local Today value to the local scan time
  • reviewed 2026-08-20T06:55:01.271Z sha c44ec7a :: needs changes before merge. :: [P2] Cache Grok scans outside menu rendering
  • reviewed 2026-08-20T07:32:30.082Z sha c48d4a2 :: needs changes before merge. :: [P2] Read Grok cost history from the cached publication
  • reviewed 2026-08-20T08:07:23.347Z sha a4f8067 :: needs changes before merge. :: [P2] Read Grok catalog data from the published snapshot | [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-20T09:05:18.821Z sha f00f229 :: needs changes before merge. :: [P2] Reuse the refreshed Grok snapshot | [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-20T09:36:16.883Z sha 1ba4389 :: needs changes before merge. :: [P2] Reuse the published Grok snapshot | [P3] Remove the release-owned changelog entry
  • reviewed 2026-08-20T10:37:14.888Z sha bda138a :: needs changes before merge. :: [P2] Reuse the published Grok snapshot | [P3] Remove the release-owned changelog entry

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 20, 2026
@Chipagosfinest

Copy link
Copy Markdown
Contributor Author

Addressed the ClawSweeper/Codex source-state findings on the current head:

  1. xAI /usage failures stay unavailable (missing chart). Successful empty history is confirmed empty.
  2. Grok local ~/.grok/sessions tokens publish even when remote billing fails.
  3. xAI Today is the UTC day of updatedAt, not the newest point.
  4. Grok Today is the current local-day bucket; idle days are not reused.
  5. xAI coverage stays a 30-day vendor source even when the dashboard asks for 365.

Focused tests: GrokLocalSessionScannerTests, XAICostUsageMappingTests, XAIProviderTests, GrokXAISpendCatalogTests — 20 passed.

Redacted local Grok proof from this machine after the fix (no identity):

signals_files=6
aggregate_tokens=1242673
models=['grok-4.6']

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 20, 2026
@Chipagosfinest

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Exact head c44ec7abc: both durable findings are fixed, make check passes, 23 focused tests pass, and the PR body now includes redacted real Grok scanner → shared catalog output. All four Codex review threads are resolved.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Aug 20, 2026
Enabled Grok and xAI now join the shared spend catalog instead of only
inflating the unavailable denominator. xAI contributes vendor-metered
daily USD from the Management API chart; Grok contributes local session
tokens. SuperGrok credits and xAI prepaid balance stay quotas, not spend.
Wrap no-data copy under 120 characters and drop a redundant throws
on the prepaid-balance mapping test.
Preserve xAI analytics failures as unavailable instead of known-zero
spend, publish local Grok tokens when remote billing fails, pin Today
to the current UTC/local day, and keep xAI history as a 30-day source.
steipete#3086 scoped localizedProviderDetails to DeepSeek and z.ai, so generic
OpenRouter details keep canonical English. The merge test still expected
zh-Hant "API 金鑰" and failed macOS shard 0.
@Chipagosfinest
Chipagosfinest force-pushed the agent/grok-xai-live-spend branch from c44ec7a to c48d4a2 Compare August 20, 2026 07:28
@Chipagosfinest

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Exact head c48d4a2bb: rebased onto current main and fixed the macOS shard 0 failure from #3086. That PR scoped localizedProviderDetails to DeepSeek/z.ai, so generic OpenRouter details stay canonical English; the merge test still expected API 金鑰. make check passes; 29 focused tests in 5 suites pass.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

steipete and others added 2 commits August 20, 2026 00:58
Peter restored generic title/row L() localization in 84a4ca7 after
steipete#3086 scoped it away. The merge kept the canonical-English assertion
from the earlier CI fix; match the restored shared catalog instead.
@Chipagosfinest

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Exact head a4f80675a: Peter merged main (84a4ca725 restored generic title/row L() localization). The OpenRouter popup test now matches that restored catalog. make check and PopupLocalizationTests pass on this head.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@steipete
steipete merged commit 3bfbffd into steipete:main Aug 20, 2026
9 checks passed
steipete added a commit that referenced this pull request Aug 20, 2026
steipete added a commit that referenced this pull request Aug 20, 2026
* feat(kiro): show overage credits against their cap

kiro-cli /usage states plan credits alone and omits the overage section
for organization accounts, so a spent plan looks like the account is out.
Read GetUsageLimits with the CLI's own token (read-only) and surface
overage as a second credit window plus charges against the overage budget.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): reject impossible usage counters from GetUsageLimits

An overage larger than total usage would clamp planUsed to zero and
overwrite valid CLI numbers. Honor API-disabled overage over a stale
CLI Enabled line so enrichment cannot resurrect a cap the API says is off.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): reject GetUsageLimits payloads that exceed the plan

Drop enrichment when plan usage is above the plan ceiling, and treat an unrecognized overage status as unknown so the CLI overage line can still stand.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: import FoundationNetworking for Linux URLSession types

* fix(kiro): resolve the CLI state database on Linux

GetUsageLimits enrichment always looked under macOS Application Support,
so Linux refreshes never found data.sqlite3.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): reject overage above cap and honor API currency

Best-effort GetUsageLimits data should not present a spend window
above its ceiling or format non-USD charges as dollars.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): propagate cancellation from usage-limits enrichment

A cancelled GetUsageLimits call now fails the refresh instead of publishing a CLI-only snapshot as success.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): drop CLI USD overage estimate when the API currency is not USD

A missing overageCharges field no longer lets a dollar CLI fallback render in the API's non-USD currency.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): add locale entries for overage copy

Translate the new Overage window title and Overage credits left detail row in every app catalog so non-English UIs no longer fall back to English.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): honor API-disabled overage and localize cap phrases

GetUsageLimits DISABLED now replaces a stale CLI Enabled status, and Kiro "of N" detail values go through the of %@ localization key.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(i18n): expect localized OpenRouter API key details in zh-Hant

Provider detail titles and catalogued labels go through L after #3084, so the popup test must assert the Traditional Chinese strings.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): clamp overage that runs slightly past the cap

Rejecting over-cap counters dropped the whole GetUsageLimits payload and hid overage on organization accounts, so the gauge now clamps to the cap instead.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): keep over-cap overage and localize credit units

Clamping hid the amount Kiro actually billed, and overage usage still rendered the English "credits" suffix in other locales.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kiro): keep CLI overage when API omits the cap

ENABLED without overageCapWithPrecision is incomplete enrichment, not a disabled account.

* fix(kiro): mark API-enabled overage when the CLI omits it

Organization accounts skip the CLI overage section, so the menu-bar modes never saw an Enabled row.

* fix(kiro): keep CLI plan usage when API bonuses are present

GetUsageLimits folds bonus spend into currentUsage, so overwriting the plan gauge would double-count bonus credits.

* fix(kiro): parse bonus-inclusive usage above the plan limit

GetUsageLimits folds bonus spend into currentUsage, so rejecting planUsed > planLimit dropped overage enrichment for those accounts.

* fix: preserve stacked menu bar layout line breaks (#3094)

* Preserve card menu-item subclass during cached swaps (#3093)

* Preserve menu item subclasses during cached swaps

* Add native menu proof for cached shell swaps

---------

Co-authored-by: Kiran Magic <262980978+kiranmagic7@users.noreply.github.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>

* docs: changelog for #3093

* Extend menu bar conditionals beyond usage percentages (#3088)

* Extend menu bar conditionals beyond usage percentages

Conditional predicates could only compare four percent-used windows. They now
compare 18 metrics across four units: percent windows, the direct
primary/secondary/tertiary lanes, four reset countdowns, three pace deltas,
run-out, credit balance, and today/30-day cost. Metrics with two readings
(percent windows, lanes, balance) gain a used/remaining select, so
"session > 50% used and session resets in < 2h" is expressible.

Pace, run-out, balance and cost were only carried as display strings, which
cannot be compared, so MenuBarLayoutRenderMetrics carries their numeric twins
pre-rounded to the same granularity as the text they mirror.

Three refresh gates needed widening for the new data dependencies:
- The title cache key had no component that moves with the clock, so a
  countdown predicate would have served its pre-flip title indefinitely. It now
  keys on the per-conditional outcome, evaluated once per render.
- The four observation signatures gated on display tokens; a predicate on cost
  or balance has no token. They now also read the conditionals' metrics, which
  additionally fixes lane tokens inside conditional branches being invisible to
  the lane signature.
- A reset-countdown predicate flips at an instant nothing else ticks on, so the
  countdown scheduler wakes at `resetsAt - threshold`.

The conditional library is now decoded element-wise: this change makes
forward-incompatible metric values possible for the first time, and one unknown
value would otherwise have wiped the whole library on a downgrade.

Ships an "Auto % / Resets in" default that renders the automatic percentage
while the lane has headroom and the reset countdown once it is spent.

* Sign the readings conditional predicates actually compare

Three observation-signature gaps let a predicate flip without a redraw:

- Cost signatures recorded only the currency-formatted string, so two token-cost
  updates could cross a threshold while both formatted to the same cent. A
  referenced cost metric now signs the unrounded amount losslessly.
- The balance signature recorded only the rendered "Remaining" row, so a
  `balance used` predicate — which reads the "Used" row no token surfaces — was
  entirely unsigned. Both amounts are now signed.
- The lane signature recorded the displayed reading, which follows
  `usageBarsShowUsed` and clamps remaining at zero, while `RateWindow.usedPercent`
  deliberately preserves over-quota values. A used-direction predicate such as
  `primaryLane > 105%` could move 104% -> 106% against a constant `0.000`.

The lane signature is now scoped to what the layout renders, and a new
conditional-window signature covers what conditionals read: the raw used percent
(which remaining derives from, so it covers both directions) plus `resetsAt`,
which countdown predicates depend on and no display token contributes.

* Tick clock-derived predicates that no token schedules

`menuBarWeeklyPaceRefreshDelays` is gated on a placed `.pace(.weekly)` token and
only wakes once, at the pace-eligibility boundary. Excluding `runsOutIn` from the
conditional reset schedule on the assumption that scheduler covered it therefore
left a hole: a layout whose only pace or run-out reference is a predicate got no
clock wake-up at all, so it kept rendering the branch that was true when the
value last moved.

Referenced weekly-pace predicates now also trigger the eligibility wake-up, and
any referenced pace or run-out predicate schedules a minute tick. Both numbers
are pre-rounded to the granularity the menu bar shows -- whole percentage points
and whole minutes -- so a minute tick is exactly enough, and it is the cadence a
`.resetCountdown` token already costs. Money predicates deliberately schedule
nothing: they move only when new provider data arrives.

* Keep older releases' conditional libraries readable on downgrade

Decoding the library element-wise only helps builds that already have the
lenient decoder. The build a user actually downgrades to decodes
`menuBarLayoutConditionals` strictly and falls back to `[]`, so one saved rule
using a new metric would empty the entire library there.

The conditional library now dual-writes the way layouts already do:
`menuBarLayoutConditionalsV2` keeps full fidelity, and the original key keeps an
older-readable projection. `loadLibrary` mirrors `preferredLayout` — the current
key wins unless the legacy key disagrees with its own projection, which only
happens when an older release wrote it, and that edit must survive.

The projection drops an entry when any clause uses a metric outside the original
four, and also when any clause uses a non-`.used` direction. The second case is
the subtler one: an older release's synthesized decoder ignores the unknown
`direction` key, so `session remaining > 80` would come back as
`session used > 80` and render the opposite branch. A missing rule is visibly
missing; an inverted one is not.

* Drop cost metrics that could not be converted to USD

`UsageFormatter.convertedCost` returns the source amount unchanged when it has no
rate for the provider's currency, and both cost producers passed that value
straight through as `costTodayUSD`/`cost30dUSD`. A `Cost today > 5 USD` rule
would then compare, say, €6 against a $5 threshold and pick the wrong branch.

Both producers now keep the amount only when the conversion actually landed in
USD. Otherwise the predicate sees no value and evaluates false, which is the
existing contract for a metric the provider does not report. The rendered text is
untouched and still shows the provider's own currency.

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>

* Prevent RPC pipe writes from aborting after child exit (#3095)

* fix: prevent RPC pipe writes from aborting after child exit

* test: repin UsageFetcher codex identity anchor after pipe-write refactor

* Publish live Grok tokens and xAI spend into Usage & Spend (#3085)

* Publish live Grok tokens and xAI spend into Usage & Spend

Enabled Grok and xAI now join the shared spend catalog instead of only
inflating the unavailable denominator. xAI contributes vendor-metered
daily USD from the Management API chart; Grok contributes local session
tokens. SuperGrok credits and xAI prepaid balance stay quotas, not spend.

* docs: add #3085 to changelog

* Fix lint on Grok and xAI spend messages

Wrap no-data copy under 120 characters and drop a redundant throws
on the prepaid-balance mapping test.

* Fix Grok/xAI spend publication, Today, and coverage

Preserve xAI analytics failures as unavailable instead of known-zero
spend, publish local Grok tokens when remote billing fails, pin Today
to the current UTC/local day, and keep xAI history as a 30-day source.

* Fix Grok and xAI spend edge cases

* Fix OpenRouter localization test after #3086

#3086 scoped localizedProviderDetails to DeepSeek and z.ai, so generic
OpenRouter details keep canonical English. The merge test still expected
zh-Hant "API 金鑰" and failed macOS shard 0.

* Align OpenRouter localization test with main

Peter restored generic title/row L() localization in 84a4ca7 after
#3086 scoped it away. The merge kept the canonical-English assertion
from the earlier CI fix; match the restored shared catalog instead.

* test: reconcile gatekeeper anchors and fingerprints with Grok/xAI spend clusters

* test: include Grok and xAI in the cost-capable dashboard source contract

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>

* docs: credit #3085 and #3088 changelog entries

* chore: finalize 0.54.0 changelog and bump build to 127

* docs: update appcast for 0.54.0

* chore: open 0.54.1 unreleased changelog section

* Clarify five-hour quota wording in Simplified Chinese (#3070)

* Clarify Simplified Chinese five-hour quota label

* Derive Simplified Chinese session quota labels from duration

---------

Co-authored-by: UNGETSU <ungetsu@UNGETSUdeMacBook-Air.local>

* Fix agent session menu width (#3096)

* fix(alibaba): resolve mainland Personal/Solo sec_token from the console shell (#3098)

Mainland Personal/Solo Token Plan (cn-personal) fails with a 200
`BailianGateway.Login.NotLogined` body ("Alibaba Token Plan login required")
even with fresh, valid aliyun cookies, because the request lacks the
`sec_token` the OneConsole gateway requires. #2533 already forwards the token
when present, but it was never resolvable for this path for two reasons:

- The console shell only server-renders `window.ALIYUN_CONSOLE_CONFIG.SEC_TOKEN`
  for a genuine same-origin document navigation; a bare GET receives a
  token-less shell. Send the browser-navigation headers (Referer, Sec-Fetch-*,
  Accept-Language) so the shell includes the token.
- The shell embeds it as an upper-case, unquoted key (`SEC_TOKEN: "..."`), but
  `extractSECToken` only matched the lower-case `secToken`/`sec_token` shapes.
  Add the `SEC_TOKEN` pattern.

With both, the scraper resolves the Personal `sec_token`, the gateway returns
real usage, and the mainland Personal/Solo card renders. Verified end-to-end
on a real cn-personal account: `secTokenSource=resolved`, body `message=Success`,
5-hour/weekly windows populated (was "login required").

Adds AlibabaTokenPlanSECTokenScrapeTests covering the upper-case shell format,
the existing lower-case shapes, and the no-token case.

Refs #2500, #2349, #2370, #2533.

Co-authored-by: LeoLin <leolin990405@gmail.com>

* Add BigModel CN account balance to z.ai provider (#3109)

* Add BigModel CN account balance to z.ai provider

* Bound balance timeout, region-aware override validation, null-safe amounts

---------

Co-authored-by: RunhuaHuang <RunhuaHuang@users.noreply.github.com>

* docs: credit #3070 #3096 #3098 #3109 changelog entries

* test: repair gatekeeper anchors after #3096 menu refactor

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
Co-authored-by: kiranmagic7 <kiranmagic@proton.me>
Co-authored-by: Kiran Magic <262980978+kiranmagic7@users.noreply.github.com>
Co-authored-by: William Mitchell <13799071+wdmitchelluk@users.noreply.github.com>
Co-authored-by: Alec Gutman, Chip <44984861+Chipagosfinest@users.noreply.github.com>
Co-authored-by: UNGETSU <44204222+YunyueLi@users.noreply.github.com>
Co-authored-by: UNGETSU <ungetsu@UNGETSUdeMacBook-Air.local>
Co-authored-by: KaranocaVe <39995482+KaranocaVe@users.noreply.github.com>
Co-authored-by: Zhongyue Lin <101193087+LeoLin990405@users.noreply.github.com>
Co-authored-by: LeoLin <leolin990405@gmail.com>
Co-authored-by: Xigua <rh2897@columbia.edu>
Co-authored-by: RunhuaHuang <RunhuaHuang@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants