Skip to content

feat: kimi client — K3 wire facts made first-class#47

Merged
lroolle merged 3 commits into
mainfrom
feat/kimi-k3
Jul 20, 2026
Merged

feat: kimi client — K3 wire facts made first-class#47
lroolle merged 3 commits into
mainfrom
feat/kimi-k3

Conversation

@lroolle

@lroolle lroolle commented Jul 20, 2026

Copy link
Copy Markdown
Member

What

Hardens the Kimi Code integration against the real K3 wire (devlog 2026-07-20-kimi-k3-wire-facts.org), fixing the three gaps the review surfaced plus repo hygiene.

Session identity (prompt_cache_key)

K3 sends prompt_cache_key: "session_<uuid>" in every request body — stable across subagent threads, auto-compaction, and --resume across processes. New declarative sessionBodyField in the wire table; extractSessionId reads it (bare uuid), compact stubs preserve it. Session chip + cross-run --continue stitching now work for kimi (the resume trace's 9 previously-unattributed turns attribute clean).

Compaction reunification

Kimi's auto-compaction restarts the packing with the original first user message with later user text merged in — not verbatim — so the first-user-text sig split the thread and the boundary was invisible (the devlog's "main thread does not split" claim didn't hold on rebuild). openai-dialect reunification is marker-gated on the re-sent summary preamble ("The conversation so far has been compacted..."): structural signals alone could false-claim a tail subagent, since kimi subagents share the session id. A marker-merged continuation appends without the 10-turn-drop heuristic — the repack is known, not inferred. Verified against the live 78-call trace: one main thread, one displayed boundary, zero unattributed, zero false rewinds.

Pricing as estimate

The cost chip is an estimate, not a bill — it already prices Claude Max OAuth traffic at API rates. Coding-plan wire ids now estimate at the equivalent pay-per-token rates via CATALOG_ALIASES (k3 -> moonshotai/kimi-k3 $3/$15, kimi-for-coding -> kimi-k2.7-code). models.dev's kimi-for-coding provider lists $0 subscription entries; we never use them.

Also

  • Media tool results: image_url parts map to Anthropic-shape image blocks (were silently dropped)
  • tests/mitm.test.ts scrubs all six proxy env vars per test (proxied dev shells leaked into the suite)
  • New synthetic K3 fixture incl. the mct=131072 compaction call + msgs=4 restart; K2.7 fixture stays as the adapter tripwire; both privacy-scanned
  • Repo hygiene: manual-test dirs -> temp/ (ignored), internal notes -> docs/internal/ (ignored), stale package-lock.json dropped

Tests

bun test: 476 pass, 0 fail (27 files). New regression coverage: K3 session rebuild (reunification + boundary + attribution), pck extraction incl. through compact stubs, catalog aliases.

🤖 Generated with Claude Code

lroolle and others added 3 commits July 20, 2026 10:12
Kimi Code integration (OpenAI Chat Completions adapted into the
Responses model) hardened against the real K3 wire (devlog
2026-07-20-kimi-k3-wire-facts):

- session id: K3 sends prompt_cache_key ("session_<uuid>") in every
  request body, stable across subagents, auto-compaction, and --resume.
  New wire-table field sessionBodyField; extractSessionId reads it
  (bare uuid), compact stubs preserve it -> session chip + cross-run
  --continue stitching work for kimi.
- compaction: the restart packing merges later user text into the
  first user message (NOT verbatim), so the sig fallback split the
  thread and the boundary vanished. openai-dialect reunification is
  marker-gated on the re-sent summary preamble ("The conversation so
  far has been compacted..."); a marker-merged continuation appends
  without the 10-turn-drop heuristic (the repack is known, not
  inferred). Verified against the live 78-call trace: one main thread,
  one boundary, zero unattributed turns, resume trace stitches clean.
- pricing: coding-plan wire ids estimate at the equivalent
  pay-per-token rates (CATALOG_ALIASES: k3 -> moonshotai/kimi-k3,
  kimi-for-coding -> kimi-k2.7-code). The cost chip is an estimate,
  same convention as Claude Max OAuth traffic; models.dev's
  kimi-for-coding provider lists $0 subscription entries we never use.
- media: tool-message parts arrays pass through; image_url parts map
  to Anthropic-shape image blocks instead of hitting the floor.
- fixtures: kimi-k3-session.jsonl.zst (synthetic, mirrors the observed
  wire incl. the mct=131072 compaction call + msgs=4 restart) joins
  the K2.7 adapter tripwire; mitm tests scrub all six proxy env vars.

Repo hygiene: manual-test dirs -> temp/ (ignored), internal notes ->
docs/internal/ (ignored), stale package-lock.json dropped.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…round-trip

Two-axis review findings applied:

- openaiCompleted chat detection: request shape (messages[] without
  input[]) is now the primary signal and the SSE marker keeps its
  quotes ('"object":"chat.completion') — a bare indexOf misrouted any
  codex Responses stream whose CONTENT merely discussed the Chat
  Completions API, dropping its output and usage.
- openai marker reunification also requires the two dialect-neutral
  structural facts (parent quiet forever, continuation starts smaller
  than the deepest packing) — a user literally typing the summary
  preamble mid-session no longer merges threads.
- The devlog's open question closes: rebuild identical pre/post
  cctrace compact on the K3 fixture (reunification + boundary +
  attribution through supersede-stubs), regression-tested.
- CHANGELOG: 0.19.0 entry (CONTRIBUTING requires it; missed in the
  feature commit).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lroolle
lroolle merged commit 3559bc9 into main Jul 20, 2026
1 check passed
@lroolle
lroolle deleted the feat/kimi-k3 branch July 20, 2026 17:21
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