Skip to content

fix(kimi): support Kimi Code CLI v2 storage and wire schema - #85

Open
wangerry wants to merge 1 commit into
yigitkonur:mainfrom
wangerry:main
Open

fix(kimi): support Kimi Code CLI v2 storage and wire schema#85
wangerry wants to merge 1 commit into
yigitkonur:mainfrom
wangerry:main

Conversation

@wangerry

@wangerry wangerry commented Aug 29, 2026

Copy link
Copy Markdown

Summary

Kimi Code CLI >= 0.39 changed its storage location and schema: session data
moved from ~/.kimi/ to ~/.kimi-code/ (env KIMI_CODE_HOME), and the
context.jsonl/metadata.json/state.json v1 layout was replaced by a
session_index.jsonl index, workspaces.json, v2 state.json, and a
protocol-1.5 event log at agents/main/wire.jsonl. The existing parser was
stuck on the old format and found no sessions.

Changes

  • Discovery: read session_index.jsonl ({sessionId, sessionDir, workDir}) with a sessions/wd_*/session_*/ directory-scan fallback;
    resolve cwd from state.json, the index workDir, or workspaces.json
  • Metadata: parse v2 state.json (id, cwd, epoch-ms
    createdAt/updatedAt, archived, title, lastPrompt,
    agents.main.homedir, lastTurnReason); extract model from
    profile.bind/llm.request
  • Conversation: reconstruct messages from the protocol-1.5 wire log in a
    single streaming pass — turn.prompt user turns (task/injection origins
    skipped), content.part text/think blocks, tool.call records (object
    args), usage.record token totals
  • Fidelity: emit a warning when the wire log records a full context
    compaction; keep dropped-record counting and source metadata
  • Legacy fallback: pre-0.39 ~/.kimi/sessions/<md5>/ sessions with
    context.jsonl/metadata.json remain readable
  • Registry: storagePath~/.kimi-code/sessions/, envVar
    KIMI_CODE_HOME (KIMI_SHARE_DIR kept in extraEnvVars for cache
    invalidation)
  • Schemas/tests/docs: add KimiStateV2Schema,
    KimiSessionIndexEntrySchema, KimiWireRecordSchema; rewrite Kimi
    fixtures/parser tests for the v2 layout; update README and all
    docs/parser-documentation Kimi files

Verification

  • pnpm run check — no new lint/build errors (3 pre-existing errors
    unrelated to this change)
  • pnpm test — 925 passed / 2 skipped
  • End-to-end on a real machine: continues list discovers 2 real v2
    sessions; continues resume <kimi-session> --in codex --debug-prompt
    generates a full handoff (43KB markdown, conversation + 189 tool calls +
    pending tasks + fidelity warning for compaction), and the
    .continues-handoff.md file is written to the project directory

Summary 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 a session_index.jsonl index, workspaces.json, v2 state.json, and a protocol-1.5 wire.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

  • Discovers sessions via the index with a sessions/wd_*/session_*/ scan fallback, resolving cwd from state.json, the index workDir, or workspaces.json.
  • Reconstructs messages and tool calls from agents/main/wire.jsonl, mapping user turns, text/think blocks, tool.call records, and token usage.
  • Extracts v2 metadata (epoch-ms timestamps, title, archived flag, model) and warns when the wire log records a full context compaction.

Registry, schemas, and tests

  • Updates registry storagePath to ~/.kimi-code/sessions/ and envVar to KIMI_CODE_HOME, keeping KIMI_SHARE_DIR for cache invalidation.
  • Adds KimiStateV2Schema, KimiSessionIndexEntrySchema, and KimiWireRecordSchema and rewrites fixtures, parser tests, and Kimi docs.

Written for commit 29a997c. Summary will update on new commits.

Review in cubic

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
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.

1 participant