Skip to content

Account-wide entitlement usage visibility and usage_get capability - #1240

Merged
kody-bot merged 3 commits into
mainfrom
cursor/user-entitlement-visibility-5c65
Aug 5, 2026
Merged

kody-bot merged 3 commits into
mainfrom
cursor/user-entitlement-visibility-5c65

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

What

Makes it easy for a signed-in user to see what is affecting their entitlements:

  • Account usage API (/account/usage.json) now returns all 15 entitlement resources, each with group, kind, whatCounts, howToReduce, current, limit, percentOfLimit, and overEightyPercent.
  • Usage page (packages/worker/client/routes/account-usage.tsx): resources grouped into daily rates (with UTC-midnight reset note), counts, storage, and per-item limits; progress bars; amber >80% warnings with upgrade links to /account/billing; per-resource plain-language guidance on what counts and how to reduce it (e.g. discard idle repo sessions — they are also swept automatically after 7 idle days).
  • Billing page: each plan card links "See your current usage".
  • MCP parity: new read-only, self-scoped usage_get capability on the account domain returning the same snapshot, so agents can answer "what's eating my quota".

Key files

  • packages/worker/src/entitlements/resource-visibility.ts — visibility copy + resource ordering
  • packages/worker/src/entitlements/usage-snapshot.ts — shared snapshot reader
  • packages/worker/src/app/account-usage-data.ts — account loader
  • packages/worker/client/routes/account-usage.tsx — usage page UI
  • packages/worker/src/mcp/capabilities/account/usage-get.ts — MCP capability

Testing

npm run validate green in the implementing environment (1,857 tests; one known-flaky meta_list_capabilities timeout passed on rerun). New tests: usage-snapshot.node.test.ts, usage-get.node.test.ts, updated account-usage-data.node.test.ts.

System recap — extends existing primitives (medium risk)

Mode: recap · Base: main · Head: d26ae960

Classification: extends — adds a user-facing read surface over the existing entitlements registry and a new self-scoped MCP capability; no enforcement changes.

Primitives touched

Primitive Group Impact
entitlements auth extends — visibility metadata + shared usage snapshot reader (read-only)
app-ui surfaces extends — account usage page groups all resources with warnings and guidance
capability-registry assistant extends — new read-only usage_get account capability

System map

The account usage page and the new usage_get capability both read one shared entitlement usage snapshot; no enforcement paths change.

Legend: green = composes (wiring only) · amber = extended by this PR · red = new primitive · gray = context (unchanged, included only when an edge crosses it).

flowchart LR
	appUi["app-ui<br/>Browser app"]:::extended
	capabilityRegistry["capability-registry<br/>Capability registry"]:::extended
	entitlements["entitlements<br/>Plans & entitlements"]:::extended
	appUi -->|"/account/usage.json snapshot"| entitlements
	capabilityRegistry -->|"usage_get reads same snapshot"| entitlements
	classDef touched fill:#1a7f37,color:#fff
	classDef extended fill:#9a6700,color:#fff
	classDef added fill:#cf222e,color:#fff
	classDef untouched fill:#57606a,color:#fff
Loading

Conductor report

Implemented by the user-entitlement-visibility track; PR opened and shepherded by the conductor after the track's environment could not create PRs. Status: awaiting CI + CodeRabbit, then squash-merge.

Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features
    • Added account usage links to billing plan cards.
    • Redesigned account usage with grouped entitlement sections, progress bars, labels, and explanatory details.
    • Added clearer formatting for email, boolean, and per-item limits.
    • Added warnings near usage limits, with reduction guidance and billing links.
    • Added an account usage capability for retrieving plan limits, consumption, and warnings.
  • Bug Fixes
    • Usage percentages are now capped appropriately, and unsupported percentage displays are handled correctly.

…lity

Extend the account usage page with all entitlement resources grouped by
daily rates, counts, storage, and per-item limits. Each row shows current
use, plan limit, percent, a progress bar, near-limit warnings (>80%), and
plain-language guidance on what counts and how to reduce usage.

Add shared entitlement usage snapshot logic, resource visibility copy, and
the read-only account usage_get MCP capability for agent parity. Cross-link
billing plan cards and usage warnings to /account/billing.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 38573735-df3a-41d2-854a-b874b78c8d7b

📥 Commits

Reviewing files that changed from the base of the PR and between 9afb610 and 92b835a.

📒 Files selected for processing (2)
  • packages/worker/client/routes/account-usage.tsx
  • packages/worker/src/entitlements/usage-snapshot.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/worker/src/entitlements/usage-snapshot.ts
  • packages/worker/client/routes/account-usage.tsx

📝 Walkthrough

Walkthrough

The change centralizes entitlement usage calculation in snapshots, adds resource visibility metadata, updates account usage presentation with grouped progress panels and warnings, links billing plans to usage, and exposes the same data through the authenticated usage_get capability.

Changes

Entitlement usage reporting

Layer / File(s) Summary
Resource visibility and usage contracts
packages/worker/src/entitlements/resource-visibility.ts, packages/worker/src/app/loader-data.ts
Entitlement resources now define display groups, ordering, allowance kinds, counting descriptions, and reduction guidance.
Usage snapshot collection
packages/worker/src/entitlements/usage-snapshot.ts, packages/worker/src/entitlements/usage-snapshot.node.test.ts
A shared snapshot reader collects resource usage, plan limits, percentages, and 80%-threshold warnings. Tests cover threshold behavior and complete resource coverage.
Account usage integration and presentation
packages/worker/src/app/account-usage-data.ts, packages/worker/src/app/account-usage-data.node.test.ts, packages/worker/client/routes/account-usage.tsx, packages/worker/client/routes/account-billing.tsx
Account data maps snapshots into enriched usage rows. The UI groups resources, formats values, renders capped progress bars, displays guidance, and links billing plans to current usage.
MCP usage capability
packages/worker/src/mcp/capabilities/account/usage-get.ts, packages/worker/src/mcp/capabilities/account/domain.ts, packages/worker/src/mcp/capabilities/account/usage-get.node.test.ts
The account domain registers authenticated usage_get, which returns validated plan, date, resource, and warning data.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AccountUser
  participant AccountUsagePage
  participant accountUsageData
  participant readEntitlementUsageSnapshot
  participant UsageSources
  AccountUser->>AccountUsagePage: open account usage
  AccountUsagePage->>accountUsageData: load usage data
  accountUsageData->>readEntitlementUsageSnapshot: request snapshot
  readEntitlementUsageSnapshot->>UsageSources: collect usage and limits
  UsageSources-->>readEntitlementUsageSnapshot: resource rows and warnings
  readEntitlementUsageSnapshot-->>accountUsageData: plan, day, rows, warnings
  accountUsageData-->>AccountUsagePage: grouped usage data
  AccountUsagePage-->>AccountUser: render progress, guidance, and billing links
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 summarizes the main changes: account-wide entitlement usage visibility and the new usage_get capability.
Description check ✅ Passed The description clearly explains the intent, changes, testing, affected files, and system impact, although it does not use the template's exact section headings.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/user-entitlement-visibility-5c65

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.

@kody-bot
kody-bot marked this pull request as ready for review August 5, 2026 16:48
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-1240.kody-a99.workers.dev

Worker: kody-pr-1240
D1: kody-pr-1240-db
KV: kody-pr-1240-oauth-kv

Mocks:

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9afb610. Configure here.

Comment thread packages/worker/src/entitlements/usage-snapshot.ts

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

Actionable comments posted: 2

🧹 Nitpick comments (4)
packages/worker/src/entitlements/resource-visibility.ts (1)

142-159: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider enforcing completeness of the ordered resource list.

satisfies ReadonlyArray<EntitlementResource> only proves each entry is a valid resource. It does not prove that every registered resource appears. If a new resource is added to EntitlementResource, entitlementResourceVisibility fails to compile, but this list silently omits the resource, and the account page and usage_get then hide it.

♻️ Proposed compile-time completeness check
 ] as const satisfies ReadonlyArray<EntitlementResource>
+
+// Fails to compile when a resource is missing from the ordered list above.
+type MissingUsageResource = Exclude<
+	EntitlementResource,
+	(typeof accountUsageEntitlementResources)[number]
+>
+const _allResourcesListed: MissingUsageResource extends never ? true : never =
+	true
+void _allResourcesListed
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/worker/src/entitlements/resource-visibility.ts` around lines 142 -
159, Update accountUsageEntitlementResources to enforce compile-time
completeness against the full EntitlementResource union, not only validate
individual entries. Add a type-level check that fails when any registered
resource is omitted while preserving the existing ordered list and
EntitlementResource entry validation.
packages/worker/src/entitlements/usage-snapshot.node.test.ts (1)

104-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add assertions for non-counter resource kinds.

Both tests exercise counters only. Add a case that asserts percentOfLimit is null and overEightyPercent is false for email_message_bytes (per_unit_max) and for persistent_package_services (boolean_allowance). That case pins the behavior discussed in packages/worker/src/entitlements/usage-snapshot.ts lines 60-77 and prevents the 300% regression from returning.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/worker/src/entitlements/usage-snapshot.node.test.ts` around lines
104 - 117, Extend the usage snapshot tests around readEntitlementUsageSnapshot
to cover non-counter resources: assert email_message_bytes with kind
per_unit_max has percentOfLimit null and overEightyPercent false, and
persistent_package_services with kind boolean_allowance has the same values.
Keep the existing all-resources assertion and use the returned snapshot resource
entries to verify both behaviors.
packages/worker/client/routes/account-usage.tsx (1)

40-58: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Group and kind metadata is restated in three places instead of imported. packages/worker/src/entitlements/resource-visibility.ts already exports EntitlementResourceGroup, EntitlementResourceVisibilityKind, entitlementResourceGroupOrder, entitlementResourceGroupLabels, and entitlementResourceGroupNotes. Three consumers redeclare the same values, so a new group or kind requires four coordinated edits and drift produces silently dropped rows or a validation error rather than a compile error.

  • packages/worker/client/routes/account-usage.tsx#L40-L58: import entitlementResourceGroupOrder, entitlementResourceGroupLabels, and entitlementResourceGroupNotes instead of redefining entitlementGroupOrder, entitlementGroupLabels, and entitlementGroupNotes. If a client bundle cannot import from src/entitlements, re-export the three constants and both union types from #app/loader-data.ts and import them from there.
  • packages/worker/src/app/loader-data.ts#L1273-L1276: replace the inline literal unions with the exported EntitlementResourceGroup and EntitlementResourceVisibilityKind types.
  • packages/worker/src/mcp/capabilities/account/usage-get.ts#L13-L14: derive both enums from the shared order and kind values, for example z.enum(entitlementResourceGroupOrder), so a new group cannot fail output validation at runtime.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/worker/client/routes/account-usage.tsx` around lines 40 - 58,
Centralize entitlement group and kind metadata across all three sites: in
packages/worker/client/routes/account-usage.tsx lines 40-58, import and use
entitlementResourceGroupOrder, entitlementResourceGroupLabels, and
entitlementResourceGroupNotes instead of local definitions, re-exporting them
and both union types through `#app/loader-data.ts` if client imports require it;
in packages/worker/src/app/loader-data.ts lines 1273-1276, replace inline unions
with EntitlementResourceGroup and EntitlementResourceVisibilityKind; in
packages/worker/src/mcp/capabilities/account/usage-get.ts lines 13-14, derive
both Zod enums from the shared group order and kind values.
packages/worker/client/routes/account-billing.tsx (1)

568-572: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reuse the server-provided usage href.

Line 498 links to usage through billing.usageHref. This new link hardcodes the same path. Use one source so both links stay correct if the server changes the usage path.

♻️ Proposed change
 											<p mix={css({ margin: 0 })}>
-												<a href="/account/usage" mix={css(primaryLinkCss)}>
+												<a href={billing.usageHref} mix={css(primaryLinkCss)}>
 													See your current usage
 												</a>
 											</p>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/worker/client/routes/account-billing.tsx` around lines 568 - 572,
Update the usage link in account-billing.tsx to reuse the existing
server-provided billing.usageHref value instead of hardcoding the /account/usage
path. Keep the existing link styling and text, and make the new link follow the
same source of truth as the other usage link so both stay aligned if the
server-side route changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/worker/client/routes/account-usage.tsx`:
- Around line 356-364: Remove the literal period and following space between
item.whatCounts and item.howToReduce in the rendering span, so the existing
punctuation in whatCounts is not duplicated while preserving the separator
before howToReduce.

In `@packages/worker/src/entitlements/usage-snapshot.ts`:
- Around line 60-77: Update the percentOfLimit calculation in the usage snapshot
mapping to return null for both boolean_allowance and per_unit_max resources,
while preserving numeric percentage calculation for measurable limits and the
existing warning logic based on non-null percentages.

---

Nitpick comments:
In `@packages/worker/client/routes/account-billing.tsx`:
- Around line 568-572: Update the usage link in account-billing.tsx to reuse the
existing server-provided billing.usageHref value instead of hardcoding the
/account/usage path. Keep the existing link styling and text, and make the new
link follow the same source of truth as the other usage link so both stay
aligned if the server-side route changes.

In `@packages/worker/client/routes/account-usage.tsx`:
- Around line 40-58: Centralize entitlement group and kind metadata across all
three sites: in packages/worker/client/routes/account-usage.tsx lines 40-58,
import and use entitlementResourceGroupOrder, entitlementResourceGroupLabels,
and entitlementResourceGroupNotes instead of local definitions, re-exporting
them and both union types through `#app/loader-data.ts` if client imports require
it; in packages/worker/src/app/loader-data.ts lines 1273-1276, replace inline
unions with EntitlementResourceGroup and EntitlementResourceVisibilityKind; in
packages/worker/src/mcp/capabilities/account/usage-get.ts lines 13-14, derive
both Zod enums from the shared group order and kind values.

In `@packages/worker/src/entitlements/resource-visibility.ts`:
- Around line 142-159: Update accountUsageEntitlementResources to enforce
compile-time completeness against the full EntitlementResource union, not only
validate individual entries. Add a type-level check that fails when any
registered resource is omitted while preserving the existing ordered list and
EntitlementResource entry validation.

In `@packages/worker/src/entitlements/usage-snapshot.node.test.ts`:
- Around line 104-117: Extend the usage snapshot tests around
readEntitlementUsageSnapshot to cover non-counter resources: assert
email_message_bytes with kind per_unit_max has percentOfLimit null and
overEightyPercent false, and persistent_package_services with kind
boolean_allowance has the same values. Keep the existing all-resources assertion
and use the returned snapshot resource entries to verify both behaviors.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c2fe6c4-68ba-4baf-8780-7d9026b7b1ab

📥 Commits

Reviewing files that changed from the base of the PR and between 910c5f0 and 9afb610.

📒 Files selected for processing (11)
  • packages/worker/client/routes/account-billing.tsx
  • packages/worker/client/routes/account-usage.tsx
  • packages/worker/src/app/account-usage-data.node.test.ts
  • packages/worker/src/app/account-usage-data.ts
  • packages/worker/src/app/loader-data.ts
  • packages/worker/src/entitlements/resource-visibility.ts
  • packages/worker/src/entitlements/usage-snapshot.node.test.ts
  • packages/worker/src/entitlements/usage-snapshot.ts
  • packages/worker/src/mcp/capabilities/account/domain.ts
  • packages/worker/src/mcp/capabilities/account/usage-get.node.test.ts
  • packages/worker/src/mcp/capabilities/account/usage-get.ts

Comment thread packages/worker/client/routes/account-usage.tsx
Comment thread packages/worker/src/entitlements/usage-snapshot.ts
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kody-bot
kody-bot merged commit 0d20318 into main Aug 5, 2026
10 checks passed
@kody-bot
kody-bot deleted the cursor/user-entitlement-visibility-5c65 branch August 5, 2026 17:05
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.

3 participants