fix(kimi): support Kimi Code CLI v2 storage and wire schema - #85
Open
wangerry wants to merge 1 commit into
Open
Conversation
Kimi Code CLI >= 0.39 moved session data from ~/.kimi to ~/.kimi-code and replaced the context.jsonl/state.json v1 layout with a session_index.jsonl index, workspaces.json, state.json v2, and agents/main/wire.jsonl protocol 1.5 event log. Changes: - Discover sessions via session_index.jsonl (with sessions/wd_*/session_*/ scan fallback) and resolve cwd from state.json, index workDir, or workspaces.json - Parse state.json v2 metadata (id, cwd, epoch-ms timestamps, archived, title, lastPrompt, agents.main.homedir, model) - Reconstruct conversation from wire.jsonl: turn.prompt user turns, content.part text/think blocks, tool.call records with object args, and usage.record token totals; skip task/injection origins - Emit fidelity warning when wire log records a full context compaction - Keep legacy ~/.kimi md5 layout as a fallback for pre-0.39 sessions - Update registry env var to KIMI_CODE_HOME (KIMI_SHARE_DIR in extra env vars for cache invalidation), storagePath, schemas, fixtures, tests, and parser documentation
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.
Summary
Kimi Code CLI >= 0.39 changed its storage location and schema: session data
moved from
~/.kimi/to~/.kimi-code/(envKIMI_CODE_HOME), and thecontext.jsonl/metadata.json/state.jsonv1 layout was replaced by asession_index.jsonlindex,workspaces.json, v2state.json, and aprotocol-1.5 event log at
agents/main/wire.jsonl. The existing parser wasstuck on the old format and found no sessions.
Changes
session_index.jsonl({sessionId, sessionDir, workDir}) with asessions/wd_*/session_*/directory-scan fallback;resolve
cwdfromstate.json, the indexworkDir, orworkspaces.jsonstate.json(id,cwd, epoch-mscreatedAt/updatedAt,archived,title,lastPrompt,agents.main.homedir,lastTurnReason); extract model fromprofile.bind/llm.requestsingle streaming pass —
turn.promptuser turns (task/injection originsskipped),
content.parttext/think blocks,tool.callrecords (objectargs),
usage.recordtoken totalscompaction; keep dropped-record counting and source metadata
~/.kimi/sessions/<md5>/sessions withcontext.jsonl/metadata.jsonremain readablestoragePath→~/.kimi-code/sessions/,envVar→KIMI_CODE_HOME(KIMI_SHARE_DIRkept inextraEnvVarsfor cacheinvalidation)
KimiStateV2Schema,KimiSessionIndexEntrySchema,KimiWireRecordSchema; rewrite Kimifixtures/parser tests for the v2 layout; update README and all
docs/parser-documentationKimi filesVerification
pnpm run check— no new lint/build errors (3 pre-existing errorsunrelated to this change)
pnpm test— 925 passed / 2 skippedcontinues listdiscovers 2 real v2sessions;
continues resume <kimi-session> --in codex --debug-promptgenerates a full handoff (43KB markdown, conversation + 189 tool calls +
pending tasks + fidelity warning for compaction), and the
.continues-handoff.mdfile is written to the project directorySummary by cubic
Fixes Kimi session discovery for Kimi Code CLI >= 0.39, which moved storage from
~/.kimi/to~/.kimi-code/and swapped the v1 layout for asession_index.jsonlindex,workspaces.json, v2state.json, and a protocol-1.5wire.jsonl. The parser previously found no sessions with the new CLI; it now reads the new layout, with pre-0.39~/.kimi/sessions still readable as a fallback.Session discovery and parsing
sessions/wd_*/session_*/scan fallback, resolvingcwdfromstate.json, the indexworkDir, orworkspaces.json.agents/main/wire.jsonl, mapping user turns, text/think blocks,tool.callrecords, and token usage.Registry, schemas, and tests
storagePathto~/.kimi-code/sessions/andenvVartoKIMI_CODE_HOME, keepingKIMI_SHARE_DIRfor cache invalidation.KimiStateV2Schema,KimiSessionIndexEntrySchema, andKimiWireRecordSchemaand rewrites fixtures, parser tests, and Kimi docs.Written for commit 29a997c. Summary will update on new commits.