Kimi Code's calls reached the usage ledger in #1607, but no session reader
was ever written for it: allFiles had no Kimi entry, so its sessions were
missing from Sessions and from Usage > Sessions (both read sessions.List).
kimi.go reads a session folder, sessions/<workdir slug>/<id>/, as Kimi Code
itself does (packages/agent-core-v2, checked at MoonshotAI/kimi-code afd95f6):
- state.json: the title, custom or Kimi's own (isCustomTitle, titleKind,
an old customTitle, as normalizeSessionTitle decides), cwd or 1.4's
workDir, createdAt as epoch ms or an RFC 3339 string. Its size and mtime
join the main file's, so a rename reads the session again.
- each agent's wire.jsonl: usage.record tokens (a magpie/ model counted
under its own name: here it is the session's spend), turn.prompt typed by
the user (a subagent's system_trigger and a skill_activation aren't),
step.end end_turn as replies, tool.call names.
- a fork counts only what follows its last {"type":"forked"} marker
(copyAgentWire + appendForkedMarker); one without a marker is cut at its
createdAt.
- resume: kimi --session <id>.
The same files feed the calls reader (kimiCallFiles now shares
kimiFilesIn). Siblings: Kimi's ~/.kimi-code in a WSL distro is listed
(wslAgents) and its calls are counted (callSources); the Usage page's
Sessions tab reads the same List.
ggbdpq described a reader on the issue; the patch they mentioned didn't
come through as an attachment, so this is written from their notes and
Kimi's source. Co-authored for the design.
Tests (testdata/kimi-code-sessions: the #1607 reporter's whole real files,
6 sessions, totals equal to their README's): TestKimiCodeSessions,
TestKimiCodeSessionCounts, TestKimiCodeSessionFork, TestWSLKimiCode. Broken
by hand, each goes red: no kimiFiles in allFiles, no marker cut (the
clock-set-back fork), no createdAt cut, no WSL entry, any origin as a
prompt, no workDir, no resume case.
Run: go test -tags nogui ./internal/sessions/ ./internal/gui/ in a sandbox
HOME, gofmt -l, GOOS=linux and windows go vet. Not tried with a live Kimi
Code install (the fixtures are real files from one).
Co-authored-by: ggbdpq <ggbdpq@gmail.com>