Skip to content

Add a Kimi usage collector - #7394

Open
fuziontech wants to merge 1 commit into
basecamp:quattrofrom
fuziontech:add-kimi-agent-usage
Open

Add a Kimi usage collector#7394
fuziontech wants to merge 1 commit into
basecamp:quattrofrom
fuziontech:add-kimi-agent-usage

Conversation

@fuziontech

@fuziontech fuziontech commented Aug 18, 2026

Copy link
Copy Markdown

What

Adds omarchy-agent-usage-kimi so the existing omarchy.agents panel 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

  • Local stats come from documented Kimi Code session wires under $KIMI_CODE_HOME (default ~/.kimi-code). Each usage.record with turn scope is one prompt. Session-scope rows are running totals and are skipped. Cache read/write stay out of inputTokens.
  • Limits and plan come from the same api.kimi.com/coding/v1/usages payload Kimi's /usage command renders: weekly quota plus the 5-hour session window. Membership level becomes the plan line (LEVEL_ALLEGRETOAllegreto).
  • Auth: KIMI_API_KEY wins, then ~/.kimi-code/credentials/kimi-code.json, then the legacy ~/.kimi store. Expired OAuth tokens are refreshed the way the CLI does (form POST to auth.kimi.com, flock, persist the rotated single-use refresh token at mode 0600). Tokens are sent only to kimi.com over HTTPS; redirects are refused.
  • Ships the official Kimi K-mark plus a light-surface twin, and enables kimi in 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

./test/shell.d/agent-usage-kimi-scanner-test.sh
./test/shell.d/agent-usage-update-test.sh

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-only cache reuse.

Live-verified on this machine against Kimi Code 0.37.1 (managed:kimi-code OAuth, Standard plan). The collector read api.kimi.com/coding/v1/usages and the stock omarchy.agents panel 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 a usage.record session wire.

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.
Copilot AI balanced review requested due to automatic review settings August 18, 2026 15:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 kimi in the plugin manifest defaults and ships kimi.svg / kimi-light.svg assets.
  • 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_key derivation collapses to the constant "agents", so todaySessions/totalSessions are capped at 1 for the documented directory layout.
  • request_refresh sends the refresh token without enforcing the trusted domain, weakening the "tokens only to kimi.com" guarantee that fetch_quota upholds.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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