feat: バナーに claude.ai サブスクリプションの使用リミットを表示 - #44
Merged
Merged
Conversation
SDK の rate_limit_event(rate_limit_info)から、claude.ai サブスクリプションの 使用状況(5時間枠=現在のセッション・週次枠など)をバナーに表示する。 「現在のセッション 5% 使用 ・ 4時間45分後にリセット」のように、使用率と リセットまでの残り時間を出す。API キー利用時は枠が来ないため非表示。 - core/rate-limit.ts(純粋): rate_limit_info の正規化(resetsAt 秒→ms、 utilization 0-100%)、リセット残り時間の算出、表示順ソート+同一ラベルの 重複除去、churn 回避用の等価判定。 - Session: onRateLimit(DI) で rate_limit_event を manager へ転送。既存の rejected→rate_limited のセッション状態遷移はそのまま維持(追加のみ)。 - SessionManager: ウィンドウ種別ごとに最新値を集約し、安定参照の getRateLimits() を公開(無変更イベントでは再描画しない)。 - Banner + useRateLimit: アカウント横断の使用状況セクションを描画。 文言は i18n(ja/en)に追加。 - docs/ARCHITECTURE.md に集約フローを追記。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
CodivaのバナーにClaude Subscription(claude.ai)の使用リミットを表示できるようにしました。Claude Code / claude.ai の Web で見られる「現在のセッション / N% 使用 / X時間後にリセット」相当の情報が、一覧画面のバナーに出ます。
(英語では
Current session 5% used · resets in 4h 45m)実現方法
Claude Agent SDK は claude.ai サブスクリプション利用時に
rate_limit_event(rate_limit_info)を配信します。ここにrateLimitType(five_hour/seven_dayなど)・utilization(使用率%)・resetsAt(リセット時刻)が入っており、これを集約して表示します。src/core/__fixtures__/session-basic.jsonl)で確認:resetsAtは Unix秒、utilizationは 0-100のパーセント。パーサで秒→msに正規化。onRateLimit(DI) でSessionManagerに集約し、ウィンドウ種別ごとに最新値を保持。rate_limit_eventが来ないため、使用状況セクションは自動的に非表示。変更点
core/rate-limit.ts(新規・純粋)rate_limit_infoの正規化・リセット残り時間算出・表示順ソート+同一ラベルの重複除去・等価判定core/session.tsonRateLimit(DI) でrate_limit_eventを転送(既存のrejected → rate_limited遷移はそのまま)core/session-manager.tsgetRateLimits()(無変更イベントでは再描画しない)ui/banner.tsx+ui/hooks.ts(useRateLimit)core/i18n.tsdocs/ARCHITECTURE.md設計上のポイント
core/rate-limit.ts(純関数)に閉じ込め、UI は計算しない。getRateLimits()は無変更イベントで同一参照を返すためuseSyncExternalStoreが無限ループしない。seven_dayとseven_day_overage_includedは同じ「今週」ラベルに畳まれるため、優先度の高い種別のみ残す。テスト計画
npm test— 690 tests passed(core/utils カバレッジ 80%+ 維持)npm run lint(Biome)cleannpm run typecheckcleannpm run build成功rate-limit.tsの単体テスト(実フィクスチャの形で秒→ms・パーセント・重複除去・クランプを検証)Session/SessionManagerの集約・安定参照テストBannerの ja/en 描画テストfive_hour/seven_dayの実値表示)