feat(kimi): add Kimi Code CLI OAuth quota tracking (rebase of #88)#106
Merged
Conversation
Track Moonshot Kimi Code (not Open Platform balance) via local OAuth credentials and GET /coding/v1/usages. Auto-detects ~/.kimi-code/credentials/kimi-code.json, refreshes access tokens, and surfaces weekly/window quotas on the dashboard. Co-authored-by: Grok 4.5 (high effort) <302482056+a-grok-build-bot[bot]@users.noreply.github.com>
Align labels with the Kimi Code product UI and official client parsing: payload.usage is the 7-day bucket (not a generic weekly card), window limits map to 5-hour, and totalQuota is ignored because it is not a reliable total-usage meter. Co-authored-by: Grok 4.5 (high effort) <302482056+a-grok-build-bot[bot]@users.noreply.github.com>
Discover OAuth credentials under ~/.kimi-code and ~/.kimi (plus KIMI_CODE_HOME / KIMI_SHARE_DIR overrides), prefer a fresh token, and fall back across all candidates when refresh fails. Co-authored-by: Grok 4.5 (high effort) <302482056+a-grok-build-bot[bot]@users.noreply.github.com>
Drop unused totalQuota mapping, non-5h windows, and the Membership plan-level insight so the UI matches the Code /usages surface. Co-authored-by: Grok 4.5 (high effort) <302482056+a-grok-build-bot[bot]@users.noreply.github.com>
Restore Membership in Insights and show Allegretto-style plan names instead of raw LEVEL_* enums from /usages. Co-authored-by: Grok 4.5 (high effort) <302482056+a-grok-build-bot[bot]@users.noreply.github.com>
When both CLI credential stores exist, lock to kimi-code (single tab). Skip OAuth refresh while access is still valid; on 401 re-read disk first and refresh only if that store is expired. Co-authored-by: Grok 4.5 (high effort) <302482056+a-grok-build-bot[bot]@users.noreply.github.com>
Only read/write ~/.kimi-code (and KIMI_CODE_* overrides). Never touch ~/.kimi so OAuth refresh cannot rotate a second token chain. Co-authored-by: Grok 4.5 (high effort) <302482056+a-grok-build-bot[bot]@users.noreply.github.com>
… 401 kimi-code access tokens last ~15 minutes. Auto-detect was copying the access token into NewKimiClient as staticToken, which skipped disk re-read and OAuth refresh for the whole daemon lifetime — after expiry every poll returned unauthorized even while ~/.kimi-code credentials stayed valid. - Pass empty token for KimiAutoToken so the client uses the kimi-code store - On usages 401, re-read disk then force-refresh (access can be dead before expires_at); still never touch kimi-cli paths - Regression test for unexpired-but-401 force refresh
Kimi current payload only set snake_case resets_at. Menubar normalizeQuotas reads camelCase resetsAt + timeUntilReset, so the reset clock line stayed empty for Kimi cards. Align with other providers; keep resets_at for dashboard JS. Co-authored-by: Grok 4.5 (high effort) <302482056+a-grok-build-bot[bot]@users.noreply.github.com>
# Conflicts: # internal/web/handlers.go # internal/web/menubar_test.go # internal/web/templates/dashboard.html
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Conflict-resolution/rebase of #88 onto current main. Original work by @yesme (commits preserved via merge).
Security-reviewed: refresh only on token expiry/401 (burn-avoidance), rotated refresh token persisted immediately (one-time-use handled), no token values logged, response body capped at 1MB, credential files 0600.
Conflicts resolved (grok vs kimi coexistence):
handlers.go: keep both grok + kimi in provider list andisProviderConfigured.dashboard.html: kept main's<img>+ProviderLabelstab rendering.menubar_test.go: kept all tests (Kimi reset + main's account-label/dashboard-label/Grok-reset).Verified: build + vet clean; internal/web,api,store,agent,tracker tests pass.
Follow-up (noted): wire the #99
auto_refresh_tokenskill-switch into the Kimi refresh path for consistency (Kimi already avoids refreshing valid tokens).Closes #88.