desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs
Comment 1, line 1
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:1
//! Shared Kimi wire JSONL helpers for Kimi Code A12 and Kimi Work A13 (M4).Comment 2, line 2
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:2
//!Comment 3, line 3
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:3
//! The products share a wire protocol family but retain separate identities, as specifiedComment 4, line 4
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:4
//! in adapters.md: separate data roots, instances, and log revisions. This root-level module,Comment 5, line 5
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:5
//! like jsonl.rs, shares only helper behavior checked against native data from both products.Comment 6, line 6
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:6
//!Comment 7, line 7
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:7
//! - First-line metadata detection: protocol_version is a string in observed 1.5/1.4 files.Comment 8, line 8
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:8
//! - usage.record has four exclusive camelCase fields: inputOther, output, inputCacheRead,Comment 9, line 9
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:9
//! inputCacheCreation; no native total, as documented in the M0 local-read results.Comment 10, line 10
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:10
//! - All 82 locally read wire.jsonl files use epoch milliseconds (1.78e12–1.79e12).Comment 11, line 11
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:11
//! No seconds samples exist here; diagnose and skip implausible times without guessing a ×1000 conversion.Comment 12, line 12
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:12
//! - step.end event.usage within context.append_loop_event repeats usage.record field values.Comment 13, line 13
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:13
//! Count usage.record alone and use repeats only for reconciliation, preventing double-counting.Comment 14, line 14
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:14
//! Observed repeats: 958/960 for 1.5 and 1329/1329 for 1.4; interrupted steps can lack repeats.Comment 15, line 15
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:15
//! The observed repeats are a subset; excess repeated totals signal a format difference.Comment 16, line 16
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:16
//! - Main-wire subagent.completed.usage is a cumulative snapshot of child-wire callsComment 17, line 17
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:17
//! through completed.time; local 2026-09-25 checks matched fields individually.Comment 18, line 18
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:18
//! Child wire records count independently; completed snapshots produce no events.Comment 19, line 19
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:19
//! - Observed usageScope: turn identifies main-loop LLM calls; session identifiesComment 20, line 20
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:20
//! auxiliary calls. Local session records occurred within full_compaction.begin…complete,Comment 21, line 21
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:21
//! corresponding to llm.request kind=compaction, and count as auxiliary usage.Comment 22, line 22
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:22
//! - usage.record has no uuid/messageId. Those IDs appear only in repeatedComment 23, line 23
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:23
//! step.end records, without a key linking them to usage.record. Event keys useComment 24, line 24
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:24
//! {session directory}:{agent}:{time}:{same-millisecond sequence}. Kimi Work hadComment 25, line 25
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:25
//! two pairs of child/main usage.record completions at the same millisecond across files.Comment 26, line 26
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:26
//! Keep session/agent identity; same-file duplicate times get a deterministic sequence and diagnostic.Comment 27, line 27
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:27
//!Comment 28, line 28
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:28
//! Product differences checked separately in tests/fixtures/kimi-code and kimi-work:Comment 29, line 29
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:29
//! - Kimi Code protocol 1.5: usage.record includes agentId; sessions/<wd>/session_<uuid>/;Comment 30, line 30
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:30
//! model is alias/model. The observed desktop product version was 1.0.3.Comment 31, line 31
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:31
//! - Kimi Work protocol 1.4: usage.record lacks agentId; use agents/<id>/ directory identity;Comment 32, line 32
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:32
//! sessions/<wd>/<conv-*|ctitle-*>/; model is a bare ID; daimon hostComment 33, line 33
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:33
//! uses state.json createdBy=daimon-kernel-adapter.Comment 34, line 50
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:50
/// Minimum plausible epoch milliseconds; skip lower values without assuming seconds or converting them.Comment 35, line 52
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:52
/// Maximum epoch milliseconds in year 2286; observed local values reached only 1.79e12.Comment 36, line 55
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:55
/// Four exclusive native usage.record fields, without a native total (M0 local reads).Comment 37, line 56
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:56
/// Shared by Kimi Code/Work; moved from usage_map.rs into the M4 family module.Comment 38, line 65
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:65
/// Derive input_total/total_tokens from the four exclusive wire fields.Comment 39, line 66
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:66
/// No native total or reasoning field; reasoning remains unknown.Comment 40, line 96
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:96
/// Product identity supplied by each product's scan implementation; this module holds no product state.Comment 41, line 98
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:98
/// Event-key namespace: adapter_id kimi-code or kimi-work.Comment 42, line 100
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:100
/// Agent name used in statistics: kimi-code or kimi-work.Comment 43, line 102
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:102
/// Parser version for this product implementation.Comment 44, line 106
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:106
/// Observed non-usage types are ignored; diagnose unlisted types once.Comment 45, line 107
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:107
/// Covers the union of observed types across 82 native protocol-1.5/1.4 wire.jsonl files.Comment 46, line 109
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:109
// Lifecycle/control records.Comment 47, line 134
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:134
// Child-agent lifecycle; completed snapshots have separate non-event handling.Comment 48, line 139
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:139
// Context/compaction control records.Comment 49, line 147
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:147
// Request/tool snapshots; llm.request has no stable key linking it to usage.record, so do not combine them.Comment 50, line 154
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:154
// token_counting describes estimated/cumulative context; exclude it from per-call usage.Comment 51, line 159
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:159
// File history and miscellaneous records.Comment 52, line 164
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:164
/// Shared first-line metadata detection result for detect and scan.Comment 53, line 170
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:170
/// First-line result: Pending without a complete line; Metadata with an identified header;Comment 54, line 171
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:171
/// NotMetadata with a rejection reason. I/O failures return Err.Comment 55, line 179
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:179
/// Bounded first-line read identifying the family's metadata fingerprint.Comment 56, line 201
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:201
// Observed protocol versions 1.4/1.5 are strings; other types become None for registry fallback.Comment 57, line 209
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:209
/// Persist counters, reconciliation totals, and one-time diagnostics across incremental rounds.Comment 58, line 214
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:214
/// Increment the event-key sequence for same-millisecond repeats within one file; none were locally observed.Comment 59, line 218
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:218
/// Saturating i64 reconciliation totals; repeated values do not contribute to usage.Comment 60, line 219
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:219
/// Sum only turn-scope records: session-scope compaction has no corresponding repeated usage.Comment 61, line 220
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:220
/// Native 1.4 had 1329 repeats for 1329 turn records and no repeats for 8 session records.Comment 62, line 271
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:271
/// Check plausible epoch milliseconds; diagnose out-of-range times without converting seconds.Comment 63, line 276
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:276
/// Parse four exclusive usage fields; missing/invalid/negative/excessive values return None for caller diagnostics.Comment 64, line 301
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:301
/// Derive identity from …/<session>/agents/<agent>/wire.jsonl:Comment 65, line 302
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:302
/// agent is the parent directory; session is the parent of the agents directory.Comment 66, line 303
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:303
/// Kimi Work 1.4 usage.record has no agentId; obtain identity from directories.Comment 67, line 320
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:320
/// Build a shared usage.record event; identity and calculation references are in the module documentation.Comment 68, line 337
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:337
// Stable identity: namespace + session directory + agent + record time + same-millisecond sequence.Comment 69, line 338
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:338
// usage.record lacks uuid/messageId. Keep session/agent because Kimi Work had two pairsComment 70, line 339
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:339
// of child/main usage.record completions sharing a millisecond across files;Comment 71, line 340
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:340
// time+sequence alone would collide across those files and lose events during conflict handling.Comment 72, line 390
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:390
/// Shared incremental scan called by kimi-code and kimi-work version implementations.Comment 73, line 448
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:448
// Product-supplied version registry shared by detection and scanning.Comment 74, line 493
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:493
// Deterministic same-millisecond sequence remains stable on rescans.Comment 75, line 524
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:524
// session scope identifies auxiliary compaction calls in native samples;Comment 76, line 525
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:525
// turn scope uses agent identity: an agent other than main is sub_agent.Comment 77, line 561
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:561
// step.end event.usage repeats usage.record; count usage.record only:Comment 78, line 562
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:562
// retain repeated totals for reconciliation without creating events.Comment 79, line 575
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:575
// The main-wire snapshot matched child-wire sums through completed.time in M0/local checks.Comment 80, line 576
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:576
// Child-wire calls count independently; retain only a completed-snapshot count for reconciliation notes.Comment 81, line 619
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:619
// Reconcile repeated totals only at end-of-file, avoiding comparisons against a partial read.Comment 82, line 622
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:622
// Sum turn records; repeated usage is a subset because interrupted steps can lack it (observed 958/960).Comment 83, line 623
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:623
// A positive difference describes that subset; repeated totals exceeding records signal a possible format change.Comment 84, line 650
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:650
// Main-wire subagent.completed details live in another child wire file/instance;Comment 85, line 651
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:651
// retain the count and no_detail_in_file without inventing a comparison.Comment 86, line 665
desktop/src-tauri/crates/core/src/adapters/kimi_wire.rs:665
// Files without usage, such as error-only steps, remain valid; do not degrade health or insert zero usage.