Skip to content

feat(kimi): break monthly Total usage down into Kimi Code and other features - #4759

Open
Redwinam wants to merge 1 commit into
steipete:mainfrom
Redwinam:kimi-monthly-breakdown
Open

Redwinam wants to merge 1 commit into
steipete:mainfrom
Redwinam:kimi-monthly-breakdown

Conversation

@Redwinam

Copy link
Copy Markdown

Summary

Kimi's monthly membership pool is shared across Kimi features (chat, agents, Kimi Code). CodexBar shows that pool as the Total usage lane, but both Kimi sources also report how much of it Kimi Code used, and CodexBar currently drops that:

This PR adds a Total usage detail section with two rows, shown only when both ratios are present:

Row Value
Kimi Code Code share of the pool (limit_month_code / kimiCodeUsedRatio)
Other features total − Code, floored at 0

Design notes

  • Detail rows, not rate windows. Both shares draw on one limit, so neither is an independent quota. Making them windows would bring in pace, monthly blocking and menu-bar window selection for something that isn't a limit. extraRateWindows stays ["kimi-monthly"], and the Total usage headline still uses the shared pool, as decided in [codex] Add Kimi monthly subscription usage #1839.
  • Ratios come from one source. The Code share always comes from the source that supplied the Total usage lane: Code API pools first, then the web subscription balance. That order is unchanged. A web Code ratio is never combined with a Code API total, so the two rows always add up to the Total usage lane. To guarantee this, the existing monthly-window closure moved into monthlyPool(), which returns the window, its used ratio and the matching Code ratio. Its guards are unchanged.
  • Rows have stable ids (kimi-monthly-code, kimi-monthly-other) and progress (total: 1), so their bars add up to the Total usage bar. Values use UsageFormatter.usageLine(…, showUsed: true) ("4% used") because a per-feature "left" value means nothing.
  • Missing, negative or non-finite ratios produce no section, so existing output is unchanged for responses without a Code share.
  • The section is placed before Bonus credits.
  • Localization: the title reuses the existing "Total usage" key, and "Kimi Code" is a product name. "Other features" is new, added to all 23 app catalogs (check-app-locales.mjs passes). Native speakers are welcome to refine the translations.

Example

Code API pools limit_month_total: 0.5761, limit_month_code: 0.0426:

Kimi Code: 4% used
Other features: 53% used
"details": [{"title": "Total usage", "rows": [
  {"id": "kimi-monthly-code",  "label": "Kimi Code",      "value": "4% used",  "progress": {"used": 0.0426, "total": 1}},
  {"id": "kimi-monthly-other", "label": "Other features", "value": "53% used", "progress": {"used": 0.5335, "total": 1}}
]}]

When the pool is exhausted, the breakdown stays visible next to "Blocked by monthly limit", which shows where the pool went.

Tests

  • New KimiMonthlyBreakdownTests: Code API pools; web stats through both web and Code-API enrichment; no mixing of sources; missing or invalid ratios; Code share above the total (Other floors at 0); exhausted pool shown with bonus credits in the menu card model and no new metrics; JSON encoding with stable ids.
  • New KimiMonthlyBreakdownCLITests: CLI text and card lines.
  • KimiGiftBalanceTests.fetch gains an optional codeAPI fixture parameter, with the old default.

Commands run (macOS, Swift 6.4):

make test-fast FILTER='KimiMonthlyBreakdown|KimiGiftBalance|KimiRatioPool|KimiMonthlyBlocking|KimiContradictoryUsage|KimiSubscriptionEnrichment|KimiProviderTests|KimiWebFallback|KimiMonthlyNativeProof'
  → 120 tests in 15 suites passed
make test-skip-build FILTER='CLIUnificationGoldenTests|StatusMenuProviderNativeProofTests|ProviderArchitectureGatekeeperTests|UserFacingLocalizationCoverageTests|LocalizationLanguageCatalogTests|LocalizationBundleTests|ProviderSettingsDescriptorTests|MenuBarLayoutTests|WidgetTileLayoutTests|CodexbarTests'
  → 312 tests in 9 suites passed
make check  → passed (SwiftFormat, SwiftLint strict: 0 violations, app locales OK)

The full suite is left to PR CI, per AGENTS.md. No live provider probes or Keychain access; only fixture/stub transports. No screenshot: the only UI change is two rows in the existing provider-details section, covered through the menu card model.

Related: #3694, #4306, #2741.

🤖 Generated with Claude Code

…eatures

Kimi's monthly membership pool is shared across features, and both sources
already report Kimi Code's share of it: `limit_month_code` from the Code API
and `kimiCodeUsedRatio` from web membership statistics. Show that share as a
"Total usage" detail section with Kimi Code and Other features rows, taking
the Code ratio from the same source that supplies the Total usage lane. The
shares draw on one limit, so they stay detail rows rather than quota windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-24T12:56:06.777977Z
We couldn’t complete this review. Comment @codex review to try again.
06b249b PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge.

What this changes

This PR adds Kimi Code and Other features detail rows beneath the shared monthly Total usage pool.

Example: The Code API reports monthly total usage of 0.5761 and Code usage of 0.0426.

  • Before: CodexBar shows the monthly total without identifying which features consumed it.
  • After: Details show Kimi Code: 4% used and Other features: 53% used.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch has useful fixture coverage and no identified code defect, but required runtime proof is absent and feature acceptance remains undecided.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Needs a maintainer decision · Fix scope: Complete
User problem: Kimi users can see how much monthly allowance is consumed but cannot distinguish Code consumption from other features.
Reason: The feature has concrete supporting provider data and preserves existing quota semantics, but adding automatic detail rows requires owner direction.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this PR adds a distinct breakdown absent from main, with no concrete correctness findings; the new feature needs an owner decision.

Priority: P2
Reviewed head: 06b249bef4c781e5e4302c4761d32934dbf1419f
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should Kimi display the Code and Other features breakdown automatically whenever matching monthly ratios are available?
  • Recommendation: Accept the detail-row feature: Approve the narrowly scoped attribution display while preserving quota selection and monthly blocking behavior.
  • Why: Earlier merged work establishes the ratios' meaning, but no owner has approved this additional feature on this PR or its linked reports.

Before merge

  • Add real behavior proof - The changed Kimi converter is covered through parser, fetcher, menu-model, JSON, and CLI-renderer tests, but all supplied execution uses fixtures or stub transports; attach a screenshot of the new menu rows or redacted shipped-CLI output showing Total usage and its Code/Other breakdown from a real response, removing credentials, IPs, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Tests

  • Missing end-to-end proof: Show the new breakdown through a freshly built app or shipped CLI using a real Kimi response; the submitted tests exercise production owners with stub transports, and no base-fail/head-pass run is supplied.
Agent review details

How this fits together

Kimi response models feed the provider snapshot converter, which selects authoritative quota data and supplies shared detail rows to menu and CLI renderers.

flowchart LR
 A[Code API pools] --> C[Kimi usage snapshot]
 B[Web membership statistics] --> C
 C --> D[Same source monthly selection]
 D --> E[Shared quota and detail rows]
 E --> F[Menu card]
 E --> G[CLI output]
Loading

Technical review

Best possible solution:

Use existing provider-detail rows for same-source monthly attribution while retaining Total usage as the shared monthly quota.

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

Source inspection confirms main ignores limit_month_code and does not render kimiCodeUsedRatio; linked real response fixtures establish that both sources can supply the requested attribution.

Is this the best way to solve the issue?

The implementation is appropriately small: it selects total and Code ratios together, preserves existing quota precedence and guards, and reuses shared detail rendering without adding competing quota windows.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d34fbb47afe7.

Provenance checked

  • Monthly quota selection keeps the original intent (51ed16b: Support Code API ratio responses, preserve weekly/session ordering, and expose authoritative monthly Total usage with optional web fallback.)
  • Shared monthly pool semantics keeps the original intent (2fa61d0: Use amountUsedRatio for subscription consumption because Code is only one contributor to the shared pool.)
  • Gift-credit details keeps the original intent (e439651: Expose promotional balances separately from recurring quota windows and monthly blocking.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e9b2823 adds Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift:189 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e9b2823d6fd0; files: Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift)
  • Dino🦖: Raw commit e439651 adds Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift:166 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e439651eab11; files: Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift)

Review metrics

Metric Value Why it matters
Production and test changes Swift production +51/-18; tests +149/-2 The focused converter change reuses existing rendering infrastructure, with coverage for source isolation, missing ratios, exhaustion, and CLI output.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded provider-display improvement without evidence of an urgent regression or blocked workflow.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

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

  • Attach redacted app or shipped-CLI evidence showing the new monthly attribution rows.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-24T13:08:45.930Z sha 06b249b :: needs real behavior proof before merge. :: none

Reviewed October 24, 2026, 9:10 AM ET / 13:10 UTC (Revision 2).

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 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

P2 Normal priority bug or improvement with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant