feat(kimicode): Kimi Code CLI provider, parse ~/.kimi-code wire sessions#750
Open
ozymandiashh wants to merge 2 commits into
Open
feat(kimicode): Kimi Code CLI provider, parse ~/.kimi-code wire sessions#750ozymandiashh wants to merge 2 commits into
ozymandiashh wants to merge 2 commits into
Conversation
…ons (getagentseal#747) Adds a provider for Kimi Code CLI (MoonshotAI/kimi-code, the successor of kimi-cli), reading ~/.kimi-code/sessions/wd_*/session_*/: state.json for session metadata and per-agent agents/<id>/wire.jsonl event streams. - Usage from usage.record events: inputOther->input, output->output, inputCacheRead->cacheRead, inputCacheCreation->cacheWrite. The store has no cost fields, so cost is computed from tokens and flagged estimated. - Real model attribution: usage.record.model carries the config ALIAS; the real model id lives on llm.request events. Rows resolve the alias through the alias->model map first, with the nearest preceding request as fallback, so aliases never leak into reports. - Subagent wire files parse as separate sources under one session without double counting; multi-turn continuations in one wire.jsonl are one session with multiple turns; retry-only failed sessions parse to zero usage; malformed JSONL lines are skipped. - Tool calls feed the tool breakdown; tool state resets at turn boundaries so a failed turn cannot bleed its tools into the next row. - KIMI_CODE_HOME override, eager registration, PROVIDER_ENV_VARS and PROVIDER_PARSE_VERSIONS entries, probeRoots for doctor, docs page.
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.
Adds a
kimicodeprovider for Kimi Code CLI (MoonshotAI/kimi-code, the successor of kimi-cli). Requested in #747.Schema provenance: verified live, not reverse engineered
Unlike the usual new-provider flow, this one was built against a live Kimi Code CLI install (0.27.0, macOS arm64): real sessions were generated locally (success single-turn, multi-tool, multi-turn continuation, retry-only failure), the store was inspected on disk, and the provider was validated against that real store before this PR. The observed schema:
~/.kimi-code/sessions/wd_<project>_<hash>/session_<uuid>/withstate.json(title, workDir, ISO timestamps, agents map) and per-agentagents/<id>/wire.jsonlevent streams (metadatacarriesprotocol_version: "1.4").usage.recordevents:inputOther-> input,output-> output,inputCacheRead-> cacheRead,inputCacheCreation-> cacheWrite. No cost fields exist anywhere, so cost is computed from tokens viacalculateCostand flagged estimated (kimi-k3 pricing has been in the fallback since fix(pricing): add kimi-k3 to the pricing fallback #709).usage.record.modelis the config ALIAS (for examplek3), while the real model id (for examplekimi-k3) lives onllm.requestevents. Rows resolve through the alias-to-model map first with the nearest preceding request as fallback, so aliases never leak into reports. This exact case is exercised by a regression test.llm.requestwithattempt, nousage.record) parse to zero usage without throwing; malformed JSONL lines are skipped.tool.callloop events) feed the tool breakdown; tool state resets at turn boundaries so a failed turn cannot bleed tools into the next row.Robustness
Hardened after an adversarial multi-model review pass: alias-first model resolution, turn-boundary tool-state resets, and the dedup key's store invariant (per-agent wire exclusivity) documented in the provider docs.
Validation
report --provider=kimicodereturns 2 usage-bearing sessions, 9 calls, correct token mapping (non-zero cacheRead), and the real model id in the models table;doctorshows the resolved~/.kimi-codeprobe root with 4/4 sessions parsed.npx tsc --noEmitclean; kimicode + registry + full local suites green.Scope note
kimi-cli (the predecessor) is being wound down and Kimi Code CLI migrates its config and sessions into
~/.kimi-codeon install, so this provider targets the kimi-code store only.KIMI_CODE_HOMEoverrides the root.Closes #747