Skip to content

feat(overlay): expose weekly cap utilization bar [GET-19]#52

Merged
DevanshuNEU merged 4 commits into
OpenCodeIntel:mainfrom
DevanshuNEU:feat/lco-19-overlay-weekly-cap
Apr 24, 2026
Merged

feat(overlay): expose weekly cap utilization bar [GET-19]#52
DevanshuNEU merged 4 commits into
OpenCodeIntel:mainfrom
DevanshuNEU:feat/lco-19-overlay-weekly-cap

Conversation

@DevanshuNEU

@DevanshuNEU DevanshuNEU commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a weekly cap utilization bar to the overlay widget. Before this PR, users whose weekly cap was at 71% but whose 5-hour session was at 3% would see the overlay show a nearly-empty bar and believe they were fine. They were not. The weekly bar closes that gap by surfacing the most actionable number — cap lockout risk — in the surface users always see.

The bar is derived from the same computeUsageBudget call path the side panel already uses, so the two surfaces are guaranteed to agree to the percent point for the same snapshot.

Type of change

  • New feature

What was changed

  • lib/overlay-state.ts — added usageBudget: UsageBudgetResult | null field to OverlayState; added applyUsageBudget transition function
  • entrypoints/claude-ai.content.ts — changed fetchAndStoreUsageLimits return type from number | null to UsageBudgetResult | null; computes the budget from the same parsed response before forwarding to background storage; both call sites (ORGANIZATION_DETECTED + post-STREAM_COMPLETE) now apply the budget to overlay state and re-render
  • ui/overlay.ts — added .lco-weekly-row bar below the session-limit bar; hidden when usageBudget is null, visible with correct zone class + scaleX fill + NN% weekly label when set
  • ui/overlay-styles.ts — added .lco-bar-fill--comfortable, --moderate, --tight zone fill variants (critical already existed); prefers-reduced-motion covered by existing .lco-bar-fill { transition: none } rule
  • tests/unit/overlay-state.test.ts — added applyUsageBudget unit tests (7 cases)
  • tests/unit/overlay-weekly-cap.test.ts — new file: visibility, fill transform, zone class, label text, overlay/side-panel weeklyPct invariant (21 cases)

How to test

  1. Load the extension on claude.ai (active Pro or free account with usage data)
  2. Open the overlay — weekly bar should NOT appear until a response completes (or on page load if usage data is available)
  3. After a response: overlay should show NN% weekly bar below the session-limit bar
  4. Color should match the UsageBudgetCard in the side panel for the same session
  5. At ≥90% weekly: bar turns red (critical); 75-89%: orange (tight); 50-74%: amber (moderate); <50%: green (comfortable)
  6. On a non-claude.ai tab: weekly bar should be hidden (no data)

Related issues

Closes GET-19

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a weekly usage cap bar to display your weekly limit progress with color-coded status indicators.
    • Enhanced usage budget tracking to account for both immediate and extended utilization metrics.
  • Bug Fixes

    • Fixed overlay refresh to consistently display updated usage budget data.

@vercel

vercel Bot commented Apr 24, 2026

Copy link
Copy Markdown

@DevanshuNEU is attempting to deploy a commit to the Dev's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Apr 24, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@DevanshuNEU has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 39 minutes and 16 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 39 minutes and 16 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e8858cd4-45ff-468d-84b5-a09e2e756761

📥 Commits

Reviewing files that changed from the base of the PR and between 3b4abd3 and 6bbb2a5.

📒 Files selected for processing (2)
  • entrypoints/claude-ai.content.ts
  • ui/overlay-styles.ts
📝 Walkthrough

Walkthrough

The PR extends the usage budget tracking system by restructuring the fetchAndStoreUsageLimits return type to include weekly utilization data, adding overlay state management for the new UsageBudgetResult, and rendering a weekly usage cap bar in the overlay UI with zone-based styling.

Changes

Cohort / File(s) Summary
Budget Result Handling
entrypoints/claude-ai.content.ts
Modified fetch and application flow to return structured UsageBudgetResult on ORGANIZATION_DETECTED and STREAM_COMPLETE events; now snapshots utilization and applies budget state with immediate rendering.
Overlay State Management
lib/overlay-state.ts
Added usageBudget field to track weekly cap data and introduced applyUsageBudget pure state transition for updating budget state.
UI Rendering
ui/overlay.ts, ui/overlay-styles.ts
Added weekly usage cap bar row to overlay with dynamic scaleX fill transform, zone-based CSS classes, and visibility toggled by usageBudget presence; added three new zone modifier classes for cap bar fill styling.
Test Coverage
tests/unit/overlay-state.test.ts, tests/unit/overlay-weekly-cap.test.ts
Added unit tests validating applyUsageBudget state transition, initial state setup, field isolation, and weekly cap bar rendering logic including fill scale clamping, zone classification, and label formatting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 A weekly cap arrives in sight,
With zones of color, green and bright!
The budget flows through state with grace,
While overlay bars find their place. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% 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 accurately and specifically describes the main feature added: exposing a weekly cap utilization bar in the overlay.
Description check ✅ Passed The description is comprehensive and well-structured, covering summary, type of change, detailed file changes, testing instructions, and related issues.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
entrypoints/claude-ai.content.ts (1)

61-75: ⚠️ Potential issue | 🟡 Minor

Stale JSDoc after return type change.

The doc block still says "return the 5-hour session utilization percentage" and "The returned utilization value is used for delta tracking," but the signature at line 76 now returns UsageBudgetResult | null. Callers obtain the delta input via budget.sessionPct (see lines 296 and 468).

Proposed update
 /**
  * Fetch the Anthropic usage limits for this account, forward to background for
- * storage, and return the 5-hour session utilization percentage.
+ * storage, and return the computed UsageBudgetResult (session + weekly
+ * utilization with reset metadata).
  *
  * The usage endpoint returns exact session and weekly utilization with reset
  * timestamps — the same data shown on claude.ai/settings/limits.
  *
  * Called on ORGANIZATION_DETECTED (page load) and after each STREAM_COMPLETE.
- * The returned utilization value is used for delta tracking: the caller snapshots
- * the before-value, calls this, and subtracts to get the exact session cost of
- * the last message.
+ * Callers use `result.sessionPct` for delta tracking: snapshot the before-value,
+ * call this, and subtract to get the exact session cost of the last message.
+ * The `result.weeklyPct` drives the overlay weekly-cap bar and the side panel
+ * Usage Budget card.
  *
  * Returns null on any failure (network error, malformed response). The caller
  * treats null as "delta uncomputable" and records the turn without a delta.
  */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@entrypoints/claude-ai.content.ts` around lines 61 - 75, Update the stale
JSDoc to reflect the new return type UsageBudgetResult | null: remove the
phrasing that says the function returns "the 5-hour session utilization
percentage" and instead document that it returns a UsageBudgetResult object (or
null on failure) containing fields like sessionPct (the session utilization
percentage used by callers for delta tracking) and any other returned
timestamps/weekly/session fields; also note callers read the delta from
budget.sessionPct. Ensure the description still covers when it is called
(ORGANIZATION_DETECTED/after STREAM_COMPLETE) and that null means "delta
uncomputable."
🧹 Nitpick comments (1)
ui/overlay-styles.ts (1)

362-365: Optional: consolidate duplicate zone/health color declarations.

lco-bar-fill--comfortable and lco-bar-fill--moderate share identical background and box-shadow values with lco-bar-fill--healthy (line 358) and lco-bar-fill--degrading (line 359) respectively. If the intent is for zone and health colors to stay in lockstep, you can group selectors to avoid drift. If they are expected to diverge in the future, the current split is fine and this can be ignored.

Proposed consolidation
-.lco-bar-fill--healthy   { background: `#86efac`; box-shadow: 0 0 6px rgba(134, 239, 172, 0.3); }
-.lco-bar-fill--degrading { background: `#f59e0b`; box-shadow: 0 0 6px rgba(245, 158, 11, 0.3); }
 .lco-bar-fill--critical  { background: `#ef4444`; box-shadow: 0 0 6px rgba(239, 68, 68, 0.3); }

 /* Budget zone fill colors — used by the weekly cap bar */
-.lco-bar-fill--comfortable { background: `#86efac`; box-shadow: 0 0 6px rgba(134, 239, 172, 0.3); }
-.lco-bar-fill--moderate    { background: `#f59e0b`; box-shadow: 0 0 6px rgba(245, 158, 11, 0.3); }
+.lco-bar-fill--healthy,
+.lco-bar-fill--comfortable { background: `#86efac`; box-shadow: 0 0 6px rgba(134, 239, 172, 0.3); }
+.lco-bar-fill--degrading,
+.lco-bar-fill--moderate    { background: `#f59e0b`; box-shadow: 0 0 6px rgba(245, 158, 11, 0.3); }
 .lco-bar-fill--tight       { background: `#fb923c`; box-shadow: 0 0 6px rgba(251, 146, 60, 0.3); }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ui/overlay-styles.ts` around lines 362 - 365, The CSS repeats identical rules
for zone and health states: merge selectors that share the same background and
box-shadow to prevent drift—specifically group .lco-bar-fill--healthy with
.lco-bar-fill--comfortable for the green styles, and .lco-bar-fill--degrading
with .lco-bar-fill--moderate for the amber styles—so update the rule
declarations for those selectors (referencing .lco-bar-fill--healthy,
.lco-bar-fill--comfortable, .lco-bar-fill--degrading, .lco-bar-fill--moderate)
to use grouped selectors instead of duplicate blocks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@entrypoints/claude-ai.content.ts`:
- Around line 61-75: Update the stale JSDoc to reflect the new return type
UsageBudgetResult | null: remove the phrasing that says the function returns
"the 5-hour session utilization percentage" and instead document that it returns
a UsageBudgetResult object (or null on failure) containing fields like
sessionPct (the session utilization percentage used by callers for delta
tracking) and any other returned timestamps/weekly/session fields; also note
callers read the delta from budget.sessionPct. Ensure the description still
covers when it is called (ORGANIZATION_DETECTED/after STREAM_COMPLETE) and that
null means "delta uncomputable."

---

Nitpick comments:
In `@ui/overlay-styles.ts`:
- Around line 362-365: The CSS repeats identical rules for zone and health
states: merge selectors that share the same background and box-shadow to prevent
drift—specifically group .lco-bar-fill--healthy with .lco-bar-fill--comfortable
for the green styles, and .lco-bar-fill--degrading with .lco-bar-fill--moderate
for the amber styles—so update the rule declarations for those selectors
(referencing .lco-bar-fill--healthy, .lco-bar-fill--comfortable,
.lco-bar-fill--degrading, .lco-bar-fill--moderate) to use grouped selectors
instead of duplicate blocks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f16fab02-b28c-42c7-89ba-408b2a49b752

📥 Commits

Reviewing files that changed from the base of the PR and between 2e9f49b and 3b4abd3.

📒 Files selected for processing (6)
  • entrypoints/claude-ai.content.ts
  • lib/overlay-state.ts
  • tests/unit/overlay-state.test.ts
  • tests/unit/overlay-weekly-cap.test.ts
  • ui/overlay-styles.ts
  • ui/overlay.ts

@vercel

vercel Bot commented Apr 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
getsaar Ready Ready Preview, Comment Apr 24, 2026 4:49am

@DevanshuNEU DevanshuNEU merged commit 65b8b11 into OpenCodeIntel:main Apr 24, 2026
7 checks passed
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.

1 participant