Skip to content

feat: add usage alerts before session resets#446

Open
fathiraz wants to merge 5 commits intorobinebers:mainfrom
fathiraz:feat/usage-alerts
Open

feat: add usage alerts before session resets#446
fathiraz wants to merge 5 commits intorobinebers:mainfrom
fathiraz:feat/usage-alerts

Conversation

@fathiraz
Copy link
Copy Markdown

@fathiraz fathiraz commented May 6, 2026

Description

  • add usage alert feature so user get notified before there session limit resets
  • support multiple threshold option (10%, 20%, 30%, custom) and pick alert sound
  • work with claude, codex, kimi, minimax, opencode go, zai.
  • new deps: tauri notification plugin for cross-platform desktop alerts.

Related Issue

#326

Type of Change

  • Bug fix
  • New feature
  • New provider plugin
  • Documentation
  • Performance improvement
  • Other (describe below)

Testing

  • I ran bun run build and it succeeded

  • I ran bun run test and all tests pass

  • I tested the change locally with bun tauri dev

Screenshots

Claude below threshold

Settings - default

Settings - enabled

Settings - with custom percentage

Settings - change sound notification

Settings - clicked button send test notification

Checklist

  • I read CONTRIBUTING.md
  • My PR targets the main branch
  • I did not introduce new dependencies without justification

Summary by cubic

Add usage alerts that notify you before a session limit resets. Choose presets or a custom %, pick a sound, and get cross-platform desktop notifications via @tauri-apps/plugin-notification/tauri-plugin-notification for Claude, Codex, Kimi, MiniMax, OpenCode Go, and Zai.

  • New Features

    • Toggle desktop alerts when remaining % drops below a threshold (10%, 20%, 30%, or custom 1–99%).
    • Choose a notification sound and use “Send Test Notification” in Settings.
    • Alerts include the plugin icon and fire once per provider until usage rises above the threshold.
  • Bug Fixes

    • Validate and clamp usage alert preferences (round custom values to 1–99) and persist them safely.
    • Only notify when a valid “Session” line is present with finite limits; use remaining percent for timing.
    • Canonicalize icon file paths and restrict them to the plugin directory before attaching to notifications.
    • Prevent duplicate alerts when notification sending fails by marking the provider as notified on error.

Written for commit b54acba. Summary will update on new commits.

add desktop notification when your near the usage limit before it reset.
pick from threshold presets or set custom value, choose alert sound too.
support claude, codex, kimi, minimax, opencode go, zai plugins.

add tauri notification plugin for cross-platform alerts.

tests included for settings and bootstrap.
@github-actions github-actions Bot added rust Pull requests that update rust code core labels May 6, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 21 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/lib/settings.ts">

<violation number="1" location="src/lib/settings.ts:360">
P2: `isUsageAlertThreshold` accepts `25`, which is not in `UsageAlertThreshold`; this makes the type guard unsound and can return an invalid threshold from `loadUsageAlertThreshold`.</violation>
</file>

<file name="src/hooks/app/use-usage-alert.ts">

<violation number="1" location="src/hooks/app/use-usage-alert.ts:54">
P2: Marks the provider as notified before the async notification completes, so failed notification attempts are never retried.</violation>
</file>

<file name="src-tauri/src/plugin_engine/manifest.rs">

<violation number="1" location="src-tauri/src/plugin_engine/manifest.rs:112">
P1: Icon path is canonicalized and read without any plugin-directory containment check, enabling reads of files outside the plugin directory.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread src-tauri/src/plugin_engine/manifest.rs
Comment thread src/lib/settings.ts Outdated
Comment thread src/hooks/app/use-usage-alert.ts Outdated
@fathiraz fathiraz changed the title Add usage alerts before session resets feat: add usage alerts before session resets May 6, 2026
@validatedev validatedev requested a review from Copilot May 6, 2026 09:27
@validatedev
Copy link
Copy Markdown
Collaborator

@codex review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a cross-platform “Usage Alerts” feature that triggers a desktop notification when a provider’s session usage drops below a configured remaining-% threshold, with settings for enablement, threshold presets/custom value, and notification sound. This integrates into the existing probe/update flow so alerts can fire as fresh usage data is fetched.

Changes:

  • Added new persisted preferences for usage alerts (enabled, threshold preset/custom, sound) and bootstrapped them on app start.
  • Introduced a useUsageAlert hook wired into probe results to send Tauri desktop notifications (optionally with provider icon attachment).
  • Extended plugin metadata to include an icon file path (in addition to the existing icon data URL) and enabled the Tauri notification plugin/capability.

Reviewed changes

Copilot reviewed 20 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/stores/app-preferences-store.ts Adds usage alert preferences + setters to the preferences store.
src/pages/settings.tsx Adds “Usage Alerts” settings UI + test notification button.
src/lib/settings.ts Defines alert types/options/defaults; adds load/save helpers for new settings.
src/lib/settings.test.ts Updates PluginMeta fixtures for new iconFilePath field.
src/lib/plugin-types.ts Extends PluginMeta with iconFilePath.
src/hooks/app/use-usage-alert.ts New hook to evaluate usage and trigger desktop notifications.
src/hooks/app/use-settings-display-actions.ts Adds persistence/actions for usage alert settings.
src/hooks/app/use-settings-bootstrap.ts Loads usage alert settings during bootstrap and populates state.
src/hooks/app/use-settings-bootstrap.test.ts Updates mocks/fixtures to cover new settings + iconFilePath.
src/hooks/app/use-probe.ts Updates onProbeResult callback to receive PluginOutput.
src/hooks/app/use-probe-state.ts Passes probe output to onProbeResult.
src/components/app/app-content.tsx Plumbs usage alert props through to Settings page.
src/App.tsx Wires probe results into useUsageAlert and passes settings handlers.
src/App.test.tsx Updates plugin meta fixtures for new iconFilePath field.
src-tauri/src/plugin_engine/runtime.rs Updates test fixture for new loaded plugin field.
src-tauri/src/plugin_engine/manifest.rs Canonicalizes/validates icon path and stores it on loaded plugin.
src-tauri/src/lib.rs Exposes icon_file_path to frontend; initializes notification plugin.
src-tauri/Cargo.toml Adds tauri-plugin-notification.
src-tauri/Cargo.lock Locks new notification dependency tree.
src-tauri/capabilities/default.json Enables notification:default capability.
package.json Adds @tauri-apps/plugin-notification.
bun.lock Locks new JS notification dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/settings.tsx Outdated
Comment thread src/lib/settings.ts Outdated
Comment thread src/hooks/app/use-usage-alert.ts
Comment thread src/pages/settings.tsx Outdated
Comment on lines +43 to +48
async function sendNotificationAsync(payload: Parameters<
typeof import("@tauri-apps/plugin-notification").sendNotification
>[0]) {
const { sendNotification } = await import("@tauri-apps/plugin-notification")
return sendNotification(payload)
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

resolved at a62d911

Comment thread src/lib/settings.ts
@fathiraz fathiraz force-pushed the feat/usage-alerts branch from 855dfe2 to da7d302 Compare May 6, 2026 21:47
fathiraz added 2 commits May 7, 2026 06:42
- Move sendNotificationAsync into src/lib/notification.ts
- Fix duplicate alert bug by marking provider notified on error
* main:
  chore: bump version to 0.6.23
  chore(analytics): drop UI-side Aptabase events (robinebers#449)
  fix(claude): remove peak hours indicator integration (robinebers#447)
@validatedev
Copy link
Copy Markdown
Collaborator

not sure about this one. we're not tracking usage in real time. the thresholds are set specifically to avoid hammering the providers' endpoints. if the data isn't guaranteed to be current sending alerts feels misleading. a late notification is worse than no notification imo

@fathiraz
Copy link
Copy Markdown
Author

fathiraz commented May 8, 2026

not sure about this one. we're not tracking usage in real time. the thresholds are set specifically to avoid hammering the providers' endpoints. if the data isn't guaranteed to be current sending alerts feels misleading. a late notification is worse than no notification imo

fair concern @validatedev . the non realtime data definitely makes this less reliable than i initially thought

would you be open to keeping it as an experimental opt-in feature with clear disclaimers? or do you think its better to just close this?

either way works for me, since i dont want to push something that doesnt fit the apps philosophy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants