Add a Kimi usage collector - #7394
Conversation
omarchy-agent-usage-kimi prints the shared agents-panel record from kimi-code session wires (usage.record) and the api.kimi.com usages endpoint the CLI's /usage command already calls. Session-scope running totals are skipped so they are not counted twice. The panel needs no QML change.
There was a problem hiding this comment.
Pull request overview
This PR adds bin/omarchy-agent-usage-kimi, a new usage collector for the omarchy.agents bar panel, so Kimi joins Claude, Codex, and Fireworks. The panel needs no changes: it renders any record dropped in ~/.local/state/omarchy/agents/usage/, and omarchy-agent-usage-update picks up the new collector by glob. The collector scans local wire.jsonl session events for token stats, fetches weekly/5-hour quotas from api.kimi.com/coding/v1/usages, resolves auth via KIMI_API_KEY → kimi-code store → legacy store (with CLI-style OAuth refresh), and maps membership level to a plan label.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Changes:
- New Python collector
omarchy-agent-usage-kimi(local scan + quota/limits + OAuth token refresh) plus a scanner test. - Enables
kimiin the plugin manifest defaults and shipskimi.svg/kimi-light.svgassets. - Documents Kimi in the plugin README and the user manual.
Reviewed changes
Copilot reviewed 4 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
bin/omarchy-agent-usage-kimi |
New collector: local wire scan, quota fetch, OAuth refresh, limits/plan mapping |
test/shell.d/agent-usage-kimi-scanner-test.sh |
Tests token buckets, auth precedence, refresh rotation, endpoint trust, limits mapping |
shell/plugins/agents/manifest.json |
Enables kimi provider by default; updates description |
shell/plugins/agents/README.md |
Adds Kimi row and auth/env documentation |
shell/plugins/agents/assets/kimi.svg |
Kimi K-mark glyph (dark surface) |
shell/plugins/agents/assets/kimi-light.svg |
Kimi K-mark glyph (light surface) |
manual/17-ai.md |
Lists Kimi among out-of-the-box agents |
Key points from the review:
- The
session_keyderivation collapses to the constant"agents", sotodaySessions/totalSessionsare capped at 1 for the documented directory layout. request_refreshsends the refresh token without enforcing the trusted domain, weakening the "tokens only to kimi.com" guarantee thatfetch_quotaupholds.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
What
Adds
omarchy-agent-usage-kimiso the existingomarchy.agentspanel grows a Kimi tab the same way it already does for Claude, Codex, and Fireworks. No QML change: the panel draws any record that lands in~/.local/state/omarchy/agents/usage/.How
$KIMI_CODE_HOME(default~/.kimi-code). Eachusage.recordwith turn scope is one prompt. Session-scope rows are running totals and are skipped. Cache read/write stay out ofinputTokens.api.kimi.com/coding/v1/usagespayload Kimi's/usagecommand renders: weekly quota plus the 5-hour session window. Membership level becomes the plan line (LEVEL_ALLEGRETO→Allegreto).KIMI_API_KEYwins, then~/.kimi-code/credentials/kimi-code.json, then the legacy~/.kimistore. Expired OAuth tokens are refreshed the way the CLI does (form POST toauth.kimi.com, flock, persist the rotated single-use refresh token at mode 0600). Tokens are sent only tokimi.comover HTTPS; redirects are refused.kimiin the widget defaults.The tab stays hidden until a machine has a signed-in Kimi account or recorded session usage — same self-hiding as the other collectors.
Related: #7261 (make Kimi a default agent), #7274, #6477. Happy to close this in favor of whichever lands.
Tests
Covers empty/unauthenticated records, turn vs session scope,
KIMI_CODE_HOME, env-key precedence, kimi-code vs legacy store, refresh rotation, endpoint trust, weekly/5-hour payload mapping, and--limits-onlycache reuse.Live-verified on this machine against Kimi Code 0.37.1 (
managed:kimi-codeOAuth, Standard plan). The collector readapi.kimi.com/coding/v1/usagesand the stockomarchy.agentspanel grew a Kimi tab with Standard, a Weekly 5% meter, and a Session (5-hour) 7% meter. Tokens-by-day stayed empty because this account has not yet written ausage.recordsession wire.