Skip to content

feat(kimi): add Kimi Code CLI OAuth quota tracking (rebase of #88)#106

Merged
prakersh merged 10 commits into
mainfrom
resolve-pr88
Jul 23, 2026
Merged

feat(kimi): add Kimi Code CLI OAuth quota tracking (rebase of #88)#106
prakersh merged 10 commits into
mainfrom
resolve-pr88

Conversation

@prakersh

Copy link
Copy Markdown
Contributor

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 and isProviderConfigured.
  • dashboard.html: kept main's <img>+ProviderLabels tab 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_tokens kill-switch into the Kimi refresh path for consistency (Kimi already avoids refreshing valid tokens).

Closes #88.

yesme and others added 10 commits July 14, 2026 22:09
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
@prakersh
prakersh merged commit 48fa180 into main Jul 23, 2026
5 checks passed
@prakersh
prakersh deleted the resolve-pr88 branch July 23, 2026 20:14
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.

2 participants