Skip to content

Add reset warnings for unused credits approaching window reset#619

Open
0-CYBERDYNE-SYSTEMS-0 wants to merge 1 commit intosteipete:mainfrom
0-CYBERDYNE-SYSTEMS-0:feature/reset-warnings
Open

Add reset warnings for unused credits approaching window reset#619
0-CYBERDYNE-SYSTEMS-0 wants to merge 1 commit intosteipete:mainfrom
0-CYBERDYNE-SYSTEMS-0:feature/reset-warnings

Conversation

@0-CYBERDYNE-SYSTEMS-0
Copy link
Copy Markdown
Contributor

Summary

Notifies users when a usage window (session or weekly) is about to reset and they still have significant capacity remaining. This helps plan long-running tasks to use credits before they expire.

How it works

  • Evaluation: After each refresh cycle, checks all enabled providers' primary and secondary RateWindow entries. A warning triggers when remainingPercent >= 20% AND resetsAt is within the configured advance time (default 8 hours).
  • macOS notification: Fires a system notification like "Claude weekly resets in 7h — You still have 72% remaining. Consider starting long-running tasks."
  • Cooldown: Won't re-notify for the same provider/window within 1 hour to avoid spam.
  • Menu card banner: When a warning is active, an amber banner appears above the metrics in the provider's menu card showing the countdown and remaining percentage.

Settings

  • Reset warnings toggle in Preferences > General > Automation (on by default)
  • Warning advance time picker: 1, 2, 4, 8, 12, 24, or 48 hours (default: 8h)

Files changed

File Change
CodexBarCore/ResetWarningState.swift New — ResetWarning model + ResetWarningEvaluator logic
UsageStore.swift Warning evaluation after refresh + notification posting
SessionQuotaNotifications.swift Extended protocol with postResetWarning
MenuCardView.swift Amber banner view wired into card model
PreferencesGeneralPane.swift Settings toggle + advance time picker
SettingsStore* (3 files) New persisted settings fields
StatusItemController+Menu.swift Passes warnings to card model
PreferencesProvidersPane.swift Passes warnings to card model
ResetWarningTests.swift 11 Swift Testing cases

Open questions for maintainer

  • Is 20% remaining threshold the right default, or should it be configurable?
  • Should there be per-provider enable/disable, or is the global toggle sufficient?
  • Any preference on the banner styling (amber was chosen to stand out without being alarming)?

Testing

Built and verified on macOS arm64. SwiftFormat passes clean. Unit tests cover boundary conditions, cooldown logic, and edge cases (nil reset time, past reset, low remaining).

Notifies users via macOS notification when a usage window (session or
weekly) is about to reset and they still have significant capacity
remaining (>=20%). This helps users plan long-running tasks to use
credits before they expire.

- Configurable warning advance time (1-48 hours, default 8h)
- Menu card banner with amber styling when warning is active
- 1-hour notification cooldown to avoid spam
- Applies to all enabled providers with reset time data
- Settings toggle in Preferences > General > Automation

New files:
- ResetWarningState.swift: evaluation logic + dedup
- ResetWarningTests.swift: 11 Swift Testing cases
Copy link
Copy Markdown

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

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: c312f4b6f7

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

let warning = ResetWarningEvaluator.evaluate(
provider: provider,
window: primary,
windowKind: .session,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use provider-specific window kinds for reset warnings

This hard-codes the primary window as .session (and secondary as .weekly a few lines below), but several providers do not map their windows that way. For example, Kimi’s primary is weekly quota and secondary is a 5-hour rate-limit window, so warnings/notifications end up mislabeled and can notify on the wrong semantic lane. That makes the new warning text inaccurate for those providers and can confuse users about what is actually resetting.

Useful? React with 👍 / 👎.

await self.refreshCreditsIfNeeded(minimumSnapshotUpdatedAt: refreshStartedAt)
}

self.checkResetWarnings()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recompute reset warnings when warning settings change

Reset warnings are only recalculated inside the refresh path here, but the new settings (resetWarningEnabled / resetWarningHours) are not observed in UsageStore.observeSettingsChanges. As a result, changing those preferences does not immediately clear/re-evaluate activeResetWarnings; in Manual refresh mode, stale warning banners can remain indefinitely until the user triggers a refresh.

Useful? React with 👍 / 👎.

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