Skip to content

Add a Kimi usage collector to the agents panel - #7274

Merged
dhh merged 5 commits into
omacom:quattrofrom
sorenmat:add-kimi-usage-collector
Oct 14, 2026
Merged

dhh merged 5 commits into
omacom:quattrofrom
sorenmat:add-kimi-usage-collector

Conversation

@sorenmat

@sorenmat sorenmat commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Kimi can be selected as Omarchy's coding agent, but its account limits are missing from the agents panel. Add a discovered omarchy-agent-usage-kimi collector and enable Kimi alongside the existing providers. The panel shows the current CLI's session, weekly, and monthly quotas, with the code-specific monthly allowance using its existing scoped meter. Legacy quota responses remain supported. The record contains account limits without local token or prompt statistics.

Authentication uses KIMI_API_KEY or the CLI's saved sign-in. An explicit KIMI_CODE_HOME stays isolated; default installs prefer ~/.kimi-code and can fall back to the legacy ~/.kimi store. Refresh coordinates with the current CLI's renewable directory lock or the legacy file lock, rereads credentials after acquisition, and privately flushes and atomically publishes the rotated token pair. Refresh fails when its lock cannot be acquired. A sign-in or logout completed during the refresh request takes precedence over publishing its result. Credentials are sent only to trusted Kimi HTTPS hosts, redirects are refused, and service error bodies cannot publish tokens.

Failed probes retain measured limits with their original timestamp and stale status. Cached quotas are bound to the token, home, and endpoint used by the request; verified refreshes carry the same account's previous result forward. --force bypasses one-minute probe reuse. Invalid overriding API keys receive guidance to update or unset the key. The plugin README and manual describe the quota-only provider.

No separate issue is closed.

omarchy-agent-usage-kimi prints the Kimi for Coding quota as a usage
record: the weekly quota and per-window limits (such as the 5-hour
session) from api.kimi.com's usage monitor, the same payload the CLI's
/usage command renders. The bearer token comes from KIMI_API_KEY when
set, otherwise from the kimi-code sign-in under KIMI_CODE_HOME
(default ~/.kimi-code), falling back to the legacy kimi-cli store.
Expired tokens are refreshed the way the CLI does, under flock, with
the rotated single-use refresh token persisted back so the CLI keeps
working from the same file. Tokens only leave the machine for kimi.com
over HTTPS and redirects are refused.

The panel gains the tab through the existing collector discovery; the
manifest enables the provider by default.
Copilot AI balanced review requested due to automatic review settings August 17, 2026 12:28

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new “Kimi” provider to the agents usage panel by introducing a Kimi usage collector, wiring it into the agents plugin manifest, and documenting + testing its auth/limits behavior.

Changes:

  • Added omarchy-agent-usage-kimi Python collector that reads/refreshes Kimi credentials and prints a display-ready JSON record.
  • Added an end-to-end-ish shell test validating auth precedence, token refresh rotation, endpoint trust rules, and limit rendering.
  • Updated agents plugin manifest + docs to list/enable the new kimi provider.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/shell.d/agent-usage-kimi-test.sh Adds regression coverage for Kimi collector auth, refresh, trust, and limits formatting.
shell/plugins/agents/manifest.json Enables the new kimi provider and updates description text.
shell/plugins/agents/README.md Documents Kimi provider behavior and credential lookup/refresh rules.
manual/17-ai.md Updates user-facing manual to include Kimi among supported agents.
bin/omarchy-agent-usage-kimi Introduces the Kimi usage collector implementation (auth, refresh, trust, limits).

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

@sorenmat

Copy link
Copy Markdown
Contributor Author

Confirmed the credential resolution against the official docs: Kimi Code CLI stores all runtime data, including OAuth credentials, under ~/.kimi-code/ (or $KIMI_CODE_HOME), with credentials at credentials/<name>.json (data locations). The collector's lookup order — KIMI_API_KEY → $KIMI_CODE_HOME/credentials/kimi-code.json → ~/.kimi-code/credentials/kimi-code.json → legacy ~/.kimi/credentials/kimi-code.json — matches that, with the last entry only serving installs still on the legacy kimi-cli.

@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
dhh and others added 4 commits October 14, 2026 04:42
Read all current quota windows, isolate explicit homes, coordinate single-use refresh tokens with the current directory lease or legacy flock, and publish rotated credentials privately after flushing them. Restrict credential destinations and redact service errors. Keep last-known limits visible on failed probes and distinguish quota from local history.

Co-Authored-By: GPT-6 in Codex <[email protected]>

Co-Authored-By: Codex Medium (GPT-6.1-sol) <[email protected]>
Bind cached limits to the token actually used for the request, and carry last-good quota across a refresh only when this collector verifies the same-account grant. This prevents concurrent sign-in from assigning one account’s limits to another and preserves stale meters after successful rotation followed by an outage. Label the code-specific monthly allowance through the panel’s existing scoped-meter contract.

Co-Authored-By: GPT-6 in Codex <[email protected]>

Co-Authored-By: Codex Medium (GPT-6.1-sol) <[email protected]>
Reread credentials after the HTTP exchange so a sign-in or logout completed while the request was in flight is preserved. Use the new account’s fresh credentials or report the changed sign-in rather than restoring an older account. Validate the complete rotated token pair before publishing it, matching the current CLI grant contract.

Co-Authored-By: GPT-6 in Codex <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Pushed fa3681f. The branch applies cleanly to current quattro and retains the merged Kimi launcher and unconditional provisioning policy. The collector reads the current Kimi CLI's session, weekly, and monthly quotas, using the existing scoped meter for the code-specific monthly allowance. Legacy quota responses remain supported; no local token or prompt history is claimed.

GPT-6 in Codex verified the change on disposable Omarchy ISO workers without credentials. All 25 Kimi checks passed, along with updater and panel checks. Restoring the reviewed prior implementations reproduced unsafe refresh destinations, cross-home credential fallback, incompatible locking, insecure token writes, missing quotas, disappearing error state, misleading API-key guidance, cache rotation/account races, and sign-in/logout being overwritten. Kimi's exact native lock-library version was exercised in both directions, including a slow refresh protected by its heartbeat. The live panel was inspected with synthetic quota and outage responses: scoped monthly limits render, and failed probes retain measured limits with their age and error guidance. The protocol was checked against the official quota parser and refresh manager.

The final ./test/all run recorded 6,074 passing assertions. Three of 411 shell test files failed, each reproduced on a separately linked clean base at 9099461: ASCII width, plain-block branding animation, and cold compositor startup. Five checks skipped for unavailable hardware, locale, Kitty, or package fixtures. An initial network-panel reopen failure disappeared in two complete reruns and a candidate focused recheck; five focused base runs also passed. That intermittent failure was not reproduced on base.

Codex Medium (GPT-6.1-sol) contributed verified authentication and cache findings and reviewed the final published head with no remaining actionable issues. Independence of its final agreement is not guaranteed. Authenticated production Kimi API behavior was not exercised. The PR description reflects the final implementation; this is awaiting the maintainer's decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants