feat(kimi): support kimi-code alongside legacy kimi-cli - #682
Merged
Conversation
- Parse kimi-code wire.jsonl format (usage.record lines) from
~/.kimi-code/sessions/{workspace}/{session}/agents/{agent}/wire.jsonl
- Route parser selection via is_kimi_code_path() in lib.rs
- Scanner discovers both ~/.kimi/sessions (legacy) and ~/.kimi-code/sessions
- Usage query reads credentials from ~/.kimi-code first, fallback to ~/.kimi
- Respect KIMI_CODE_HOME environment variable for custom data directories
- Update README to reflect Kimi Code support
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
There was a problem hiding this comment.
2 issues found across 7 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
- is_kimi_code_path() now checks KIMI_CODE_HOME env var in addition to the literal .kimi-code path segment, fixing mis-routing for custom installation directories. - Add serial_test-guarded test for custom KIMI_CODE_HOME paths. - Update README (EN/ZH/KO) to document the KIMI_CODE_HOME override.
Mirror the kimi-code documentation added to README.md, README.ko.md, and README.zh-cn.md in junhoyeo#682, which missed the Japanese translation: client table row, cross-platform path table row, and the Kimi Code wire.jsonl format section.
kimi-code tags every usage.record with usageScope: "turn" for per-step LLM calls made inside a user turn, and "session" for non-turn bookkeeping such as context compaction rollups. Upstream's own tooling (apps/vis context-projector) treats a missing usageScope as session-scoped, so the parser now requires an explicit "turn" before counting a record. Constraint: all public kimi-code releases always write usageScope on usage.record lines Rejected: counting records with a missing usageScope | upstream attributes them to the session scope, not a turn Rejected: also counting session-scoped compaction usage | review verdict for junhoyeo#682 was to count turn-scoped usage only Confidence: high Scope-risk: narrow Not-tested: real wire.jsonl files containing compaction-emitted session-scoped records
cargo fmt over the kimi-code changes from junhoyeo#682 plus the merged scanner.rs, and replace three .len() >= 1 assertions on the Gjc scan results (from junhoyeo#685 on main, only linted under --all-targets) with !is_empty() so cargo clippy --all-targets -- -D warnings passes.
junhoyeo
approved these changes
Jun 9, 2026
junhoyeo
left a comment
Owner
There was a problem hiding this comment.
Reviewed: kimi-code parser correctly scoped to usageScope=="turn" records (verified against upstream MoonshotAI/kimi-code source), no double-count between kimi-cli/kimi-code paths, README x4 aligned, 887 core + 595 CLI tests pass on merged tree. Merging.
junhoyeo
added a commit
that referenced
this pull request
Jun 9, 2026
…parsing Replace the KIMI_CODE_HOME env read inside is_kimi_code_path() with a structural check: kimi-code always writes <root>/sessions/WORKSPACE/SESSION/agents/AGENT/wire.jsonl while legacy kimi-cli writes <root>/sessions/GROUP/UUID/wire.jsonl, so the grandparent component being `agents` identifies the format regardless of scan root. This removes the only production env read among the sessions/* parsers and drops the serial_test requirement from kimi.rs. Also merge the field-identical KimiCodeUsage into TokenUsage via serde aliases (snake_case names stay canonical, camelCase added as aliases — purely additive for legacy parsing), extract the shared clamp/skip-zero logic into TokenUsage::to_breakdown(), collapse the duplicated load_or_parse_source routing branch in lib.rs into a single fn-pointer call, tighten kimi-code test assertions, repoint the model-normalization test at normalize_kimi_code_model with edge cases, and fix the "| Kimi Code|" spacing and "``` json" fence typos across all four READMEs. Constraint: behavior must be preserved exactly; slop cleanup of PR #682 only Constraint: scanner walks both kimi roots matching file_name == "wire.jsonl" at any depth, so routed paths always carry the client-created layout Rejected: keep env read in parser | only parser with a production env read; ignored use_env_roots and forced serial tests Rejected: pass format flag from scanner to parser | larger plumbing change for the same routing decision Confidence: high Scope-risk: narrow Directive: the agents/ grandparent check relies on kimi-code's on-disk layout; if kimi-code ever changes its session tree, update is_kimi_code_path and the module docs together Not-tested: a legacy kimi-cli session whose GROUP directory is literally named "agents" (would now route to the kimi-code parser; not a real kimi-cli layout)
pinion05
added a commit
to pinion05/tokscale
that referenced
this pull request
Jun 23, 2026
…parsing Replace the KIMI_CODE_HOME env read inside is_kimi_code_path() with a structural check: kimi-code always writes <root>/sessions/WORKSPACE/SESSION/agents/AGENT/wire.jsonl while legacy kimi-cli writes <root>/sessions/GROUP/UUID/wire.jsonl, so the grandparent component being `agents` identifies the format regardless of scan root. This removes the only production env read among the sessions/* parsers and drops the serial_test requirement from kimi.rs. Also merge the field-identical KimiCodeUsage into TokenUsage via serde aliases (snake_case names stay canonical, camelCase added as aliases — purely additive for legacy parsing), extract the shared clamp/skip-zero logic into TokenUsage::to_breakdown(), collapse the duplicated load_or_parse_source routing branch in lib.rs into a single fn-pointer call, tighten kimi-code test assertions, repoint the model-normalization test at normalize_kimi_code_model with edge cases, and fix the "| Kimi Code|" spacing and "``` json" fence typos across all four READMEs. Constraint: behavior must be preserved exactly; slop cleanup of PR junhoyeo#682 only Constraint: scanner walks both kimi roots matching file_name == "wire.jsonl" at any depth, so routed paths always carry the client-created layout Rejected: keep env read in parser | only parser with a production env read; ignored use_env_roots and forced serial tests Rejected: pass format flag from scanner to parser | larger plumbing change for the same routing decision Confidence: high Scope-risk: narrow Directive: the agents/ grandparent check relies on kimi-code's on-disk layout; if kimi-code ever changes its session tree, update is_kimi_code_path and the module docs together Not-tested: a legacy kimi-cli session whose GROUP directory is literally named "agents" (would now route to the kimi-code parser; not a real kimi-cli layout)
t1000040
pushed a commit
to tmobi-internal/tokscale
that referenced
this pull request
Jun 30, 2026
* feat(kimi): support kimi-code alongside legacy kimi-cli
- Parse kimi-code wire.jsonl format (usage.record lines) from
~/.kimi-code/sessions/{workspace}/{session}/agents/{agent}/wire.jsonl
- Route parser selection via is_kimi_code_path() in lib.rs
- Scanner discovers both ~/.kimi/sessions (legacy) and ~/.kimi-code/sessions
- Usage query reads credentials from ~/.kimi-code first, fallback to ~/.kimi
- Respect KIMI_CODE_HOME environment variable for custom data directories
- Update README to reflect Kimi Code support
* fix(kimi): respect KIMI_CODE_HOME in parser routing and docs
- is_kimi_code_path() now checks KIMI_CODE_HOME env var in addition
to the literal .kimi-code path segment, fixing mis-routing for
custom installation directories.
- Add serial_test-guarded test for custom KIMI_CODE_HOME paths.
- Update README (EN/ZH/KO) to document the KIMI_CODE_HOME override.
* docs(readme.ja): add kimi-code data path and wire format
Mirror the kimi-code documentation added to README.md, README.ko.md,
and README.zh-cn.md in junhoyeo#682, which missed the Japanese translation:
client table row, cross-platform path table row, and the Kimi Code
wire.jsonl format section.
* fix(kimi): count only turn-scoped usage.record lines
kimi-code tags every usage.record with usageScope: "turn" for per-step
LLM calls made inside a user turn, and "session" for non-turn
bookkeeping such as context compaction rollups. Upstream's own tooling
(apps/vis context-projector) treats a missing usageScope as
session-scoped, so the parser now requires an explicit "turn" before
counting a record.
Constraint: all public kimi-code releases always write usageScope on usage.record lines
Rejected: counting records with a missing usageScope | upstream attributes them to the session scope, not a turn
Rejected: also counting session-scoped compaction usage | review verdict for junhoyeo#682 was to count turn-scoped usage only
Confidence: high
Scope-risk: narrow
Not-tested: real wire.jsonl files containing compaction-emitted session-scoped records
* style: rustfmt kimi additions and fix clippy len_zero in scanner tests
cargo fmt over the kimi-code changes from junhoyeo#682 plus the merged
scanner.rs, and replace three .len() >= 1 assertions on the Gjc scan
results (from junhoyeo#685 on main, only linted under --all-targets) with
!is_empty() so cargo clippy --all-targets -- -D warnings passes.
---------
Co-authored-by: Junho Yeo <i@junho.io>
t1000040
pushed a commit
to tmobi-internal/tokscale
that referenced
this pull request
Jun 30, 2026
…parsing Replace the KIMI_CODE_HOME env read inside is_kimi_code_path() with a structural check: kimi-code always writes <root>/sessions/WORKSPACE/SESSION/agents/AGENT/wire.jsonl while legacy kimi-cli writes <root>/sessions/GROUP/UUID/wire.jsonl, so the grandparent component being `agents` identifies the format regardless of scan root. This removes the only production env read among the sessions/* parsers and drops the serial_test requirement from kimi.rs. Also merge the field-identical KimiCodeUsage into TokenUsage via serde aliases (snake_case names stay canonical, camelCase added as aliases — purely additive for legacy parsing), extract the shared clamp/skip-zero logic into TokenUsage::to_breakdown(), collapse the duplicated load_or_parse_source routing branch in lib.rs into a single fn-pointer call, tighten kimi-code test assertions, repoint the model-normalization test at normalize_kimi_code_model with edge cases, and fix the "| Kimi Code|" spacing and "``` json" fence typos across all four READMEs. Constraint: behavior must be preserved exactly; slop cleanup of PR junhoyeo#682 only Constraint: scanner walks both kimi roots matching file_name == "wire.jsonl" at any depth, so routed paths always carry the client-created layout Rejected: keep env read in parser | only parser with a production env read; ignored use_env_roots and forced serial tests Rejected: pass format flag from scanner to parser | larger plumbing change for the same routing decision Confidence: high Scope-risk: narrow Directive: the agents/ grandparent check relies on kimi-code's on-disk layout; if kimi-code ever changes its session tree, update is_kimi_code_path and the module docs together Not-tested: a legacy kimi-cli session whose GROUP directory is literally named "agents" (would now route to the kimi-code parser; not a real kimi-cli layout)
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.
feat(kimi): support kimi-code alongside legacy kimi-cli
This PR adds full support for Kimi Code (the new Node.js-based CLI at
~/.kimi-code/) while keeping backward compatibility with the legacy kimi-cli (Python-based,~/.kimi/).What's Changed
Session Parsing
parse_kimi_code_file()insessions/kimi.rsto handle theusage.recordwire format used by kimi-codeis_kimi_code_path()helper to route files to the correct parser based on path (.kimi-codevs.kimi)lib.rsfor bothparse_all_messages_with_pricingandparse_local_clientsScanner
~/.kimi-code/sessions/in addition to the legacy~/.kimi/sessions/KIMI_CODE_HOMEenvironment variable for custom data directoriesUsage Query
~/.kimi-code/credentials/kimi-code.jsonfirst, fallback to~/.kimi/credentials/kimi-code.jsonKIMI_CODE_HOMEoverride for credential lookupDocumentation
Coexistence Strategy
Both tools can be installed side-by-side. The implementation prioritizes kimi-code paths when both are present, falling back to legacy paths when only the old installation exists.
Testing
All new code paths are covered by existing or new unit tests.
Summary by cubic
Adds full support for Kimi Code (
~/.kimi-code/) alongside legacykimi-cli(~/.kimi/). The scanner, parsers, and theusagecommand handle both and prefer Kimi Code when present.New Features
tokscale-core: Parse Kimi Codewire.jsonl(usage.record) viaparse_kimi_code_file(), auto-routed byis_kimi_code_path().tokscale-core: Scanner discovers~/.kimi-code/sessions/in addition to~/.kimi/sessions/.tokscale-cli: Usage reads credentials from~/.kimi-code/credentials/kimi-code.jsonfirst and writes refreshed tokens back to the same file.KIMI_CODE_HOME, and wire format (EN/ZH/KO/JA).Bug Fixes
is_kimi_code_path()now respectsKIMI_CODE_HOME, fixing parser routing for custom install paths.usageScope: "turn"usage.recordlines to avoid session-scoped bookkeeping.Written for commit 0d03444. Summary will update on new commits.