chompyy 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +11 -0
  2. package/dist/agentlimits.js +77 -0
  3. package/dist/agentusage.js +96 -0
  4. package/dist/appstate.js +63 -3
  5. package/dist/away.js +44 -5
  6. package/dist/blueprint.js +3 -7
  7. package/dist/board.js +1 -0
  8. package/dist/cli.js +263 -5
  9. package/dist/codexquota.js +106 -0
  10. package/dist/codexusage.js +10 -0
  11. package/dist/config.js +2 -0
  12. package/dist/context.js +30 -0
  13. package/dist/costs.js +1 -0
  14. package/dist/demon.js +20 -0
  15. package/dist/label.js +33 -0
  16. package/dist/menu.js +17 -0
  17. package/dist/nightcap.js +60 -0
  18. package/dist/nudge.js +47 -18
  19. package/dist/pacing.js +16 -1
  20. package/dist/questions.js +71 -0
  21. package/dist/recap.js +74 -0
  22. package/dist/receipt.js +48 -0
  23. package/dist/recipe.js +79 -0
  24. package/dist/stamps.js +14 -0
  25. package/dist/triggers.js +5 -0
  26. package/dist/usage.js +21 -1
  27. package/dist/vendor/codeburn/antigravity.js +309 -0
  28. package/dist/vendor/codeburn/codex.js +429 -0
  29. package/dist/vendor/codeburn/copilot.js +292 -0
  30. package/dist/vendor/codeburn/gemini.js +195 -0
  31. package/dist/vendor/codeburn/grokbot.js +182 -0
  32. package/dist/vendor/codeburn/kimi.js +178 -0
  33. package/dist/vendor/codeburn/shims/chalk.js +14 -0
  34. package/dist/vendor/codeburn/shims/strip-ansi.js +6 -0
  35. package/dist/vendor/codeburn/src/act/backup.js +83 -0
  36. package/dist/vendor/codeburn/src/act/model-defaults.js +151 -0
  37. package/dist/vendor/codeburn/src/act/types.js +37 -0
  38. package/dist/vendor/codeburn/src/bash-utils.js +204 -0
  39. package/dist/vendor/codeburn/src/behavioral-weight.js +47 -0
  40. package/dist/vendor/codeburn/src/cache-dir.js +26 -0
  41. package/dist/vendor/codeburn/src/cache-refresh-lock.js +543 -0
  42. package/dist/vendor/codeburn/src/cache-sweep.js +67 -0
  43. package/dist/vendor/codeburn/src/classifier.js +209 -0
  44. package/dist/vendor/codeburn/src/claude-identity.js +223 -0
  45. package/dist/vendor/codeburn/src/codex-cache.js +377 -0
  46. package/dist/vendor/codeburn/src/codex-fork-replay.js +232 -0
  47. package/dist/vendor/codeburn/src/codex-jsonl-fields.js +99 -0
  48. package/dist/vendor/codeburn/src/codex-session-index.js +113 -0
  49. package/dist/vendor/codeburn/src/codex-throughput.js +544 -0
  50. package/dist/vendor/codeburn/src/compare-stats.js +405 -0
  51. package/dist/vendor/codeburn/src/config.js +145 -0
  52. package/dist/vendor/codeburn/src/content-utils.js +56 -0
  53. package/dist/vendor/codeburn/src/context-tree-codex.js +329 -0
  54. package/dist/vendor/codeburn/src/context-tree.js +664 -0
  55. package/dist/vendor/codeburn/src/copilot-aiu.js +16 -0
  56. package/dist/vendor/codeburn/src/currency.js +189 -0
  57. package/dist/vendor/codeburn/src/cursor-cache.js +238 -0
  58. package/dist/vendor/codeburn/src/cursor-import.js +402 -0
  59. package/dist/vendor/codeburn/src/cursor-sync.js +256 -0
  60. package/dist/vendor/codeburn/src/daily-cache.js +2036 -0
  61. package/dist/vendor/codeburn/src/data/litellm-snapshot.json +1 -0
  62. package/dist/vendor/codeburn/src/data/pricing-fallback.json +1 -0
  63. package/dist/vendor/codeburn/src/day-aggregator.js +327 -0
  64. package/dist/vendor/codeburn/src/editor-data-dir.js +11 -0
  65. package/dist/vendor/codeburn/src/fetch-utils.js +18 -0
  66. package/dist/vendor/codeburn/src/format.js +118 -0
  67. package/dist/vendor/codeburn/src/fs-utils.js +270 -0
  68. package/dist/vendor/codeburn/src/git-origin.js +334 -0
  69. package/dist/vendor/codeburn/src/granular-history.js +328 -0
  70. package/dist/vendor/codeburn/src/hermes-session-ledger.js +512 -0
  71. package/dist/vendor/codeburn/src/launcher-homes.js +142 -0
  72. package/dist/vendor/codeburn/src/live-sessions.js +358 -0
  73. package/dist/vendor/codeburn/src/math-utils.js +8 -0
  74. package/dist/vendor/codeburn/src/menubar-json.js +294 -0
  75. package/dist/vendor/codeburn/src/models.js +1879 -0
  76. package/dist/vendor/codeburn/src/optimize-one-hour-cache.js +92 -0
  77. package/dist/vendor/codeburn/src/optimize.js +4110 -0
  78. package/dist/vendor/codeburn/src/parse-workers.js +219 -0
  79. package/dist/vendor/codeburn/src/parser.js +6953 -0
  80. package/dist/vendor/codeburn/src/path-privacy.js +26 -0
  81. package/dist/vendor/codeburn/src/plans.js +135 -0
  82. package/dist/vendor/codeburn/src/pr-signals.js +132 -0
  83. package/dist/vendor/codeburn/src/project-filter-warnings.js +33 -0
  84. package/dist/vendor/codeburn/src/provider-issues.js +30 -0
  85. package/dist/vendor/codeburn/src/providers/amp.js +286 -0
  86. package/dist/vendor/codeburn/src/providers/antigravity.js +1731 -0
  87. package/dist/vendor/codeburn/src/providers/claude.js +551 -0
  88. package/dist/vendor/codeburn/src/providers/cline-cli.js +401 -0
  89. package/dist/vendor/codeburn/src/providers/cline.js +63 -0
  90. package/dist/vendor/codeburn/src/providers/codebuff.js +336 -0
  91. package/dist/vendor/codeburn/src/providers/codewhale.js +442 -0
  92. package/dist/vendor/codeburn/src/providers/codex.js +1720 -0
  93. package/dist/vendor/codeburn/src/providers/command-code.js +196 -0
  94. package/dist/vendor/codeburn/src/providers/copilot.js +3278 -0
  95. package/dist/vendor/codeburn/src/providers/crush.js +226 -0
  96. package/dist/vendor/codeburn/src/providers/cursor-agent.js +837 -0
  97. package/dist/vendor/codeburn/src/providers/cursor.js +1163 -0
  98. package/dist/vendor/codeburn/src/providers/devin.js +569 -0
  99. package/dist/vendor/codeburn/src/providers/droid.js +324 -0
  100. package/dist/vendor/codeburn/src/providers/dsh.js +690 -0
  101. package/dist/vendor/codeburn/src/providers/forge.js +245 -0
  102. package/dist/vendor/codeburn/src/providers/gemini.js +230 -0
  103. package/dist/vendor/codeburn/src/providers/goose.js +252 -0
  104. package/dist/vendor/codeburn/src/providers/grok.js +581 -0
  105. package/dist/vendor/codeburn/src/providers/grokbot.js +290 -0
  106. package/dist/vendor/codeburn/src/providers/hermes.js +771 -0
  107. package/dist/vendor/codeburn/src/providers/ibm-bob.js +53 -0
  108. package/dist/vendor/codeburn/src/providers/index.js +360 -0
  109. package/dist/vendor/codeburn/src/providers/kilo-code.js +50 -0
  110. package/dist/vendor/codeburn/src/providers/kimi.js +363 -0
  111. package/dist/vendor/codeburn/src/providers/kimicode.js +402 -0
  112. package/dist/vendor/codeburn/src/providers/kiro.js +1174 -0
  113. package/dist/vendor/codeburn/src/providers/lingtai-tui.js +372 -0
  114. package/dist/vendor/codeburn/src/providers/mistral-vibe-unified.js +236 -0
  115. package/dist/vendor/codeburn/src/providers/mistral-vibe.js +405 -0
  116. package/dist/vendor/codeburn/src/providers/mux.js +242 -0
  117. package/dist/vendor/codeburn/src/providers/open-design.js +217 -0
  118. package/dist/vendor/codeburn/src/providers/openclaude.js +309 -0
  119. package/dist/vendor/codeburn/src/providers/openclaw.js +442 -0
  120. package/dist/vendor/codeburn/src/providers/opencode-file-parser.js +131 -0
  121. package/dist/vendor/codeburn/src/providers/opencode.js +91 -0
  122. package/dist/vendor/codeburn/src/providers/pi.js +429 -0
  123. package/dist/vendor/codeburn/src/providers/quickdesk.js +491 -0
  124. package/dist/vendor/codeburn/src/providers/qwen.js +193 -0
  125. package/dist/vendor/codeburn/src/providers/session-message.js +118 -0
  126. package/dist/vendor/codeburn/src/providers/sqlite-session-parser.js +457 -0
  127. package/dist/vendor/codeburn/src/providers/types.js +5 -0
  128. package/dist/vendor/codeburn/src/providers/vercel-gateway.js +135 -0
  129. package/dist/vendor/codeburn/src/providers/vscode-cline-parser.js +212 -0
  130. package/dist/vendor/codeburn/src/providers/warp.js +575 -0
  131. package/dist/vendor/codeburn/src/providers/zcode.js +249 -0
  132. package/dist/vendor/codeburn/src/providers/zed.js +187 -0
  133. package/dist/vendor/codeburn/src/providers/zerostack.js +139 -0
  134. package/dist/vendor/codeburn/src/quota/antigravity.js +310 -0
  135. package/dist/vendor/codeburn/src/quota/claude.js +244 -0
  136. package/dist/vendor/codeburn/src/quota/cursor.js +301 -0
  137. package/dist/vendor/codeburn/src/quota/security.js +299 -0
  138. package/dist/vendor/codeburn/src/quota/types.js +1 -0
  139. package/dist/vendor/codeburn/src/scan-facts.js +99 -0
  140. package/dist/vendor/codeburn/src/session-cache.js +3040 -0
  141. package/dist/vendor/codeburn/src/session-count-label.js +14 -0
  142. package/dist/vendor/codeburn/src/session-output.js +139 -0
  143. package/dist/vendor/codeburn/src/session-population.js +30 -0
  144. package/dist/vendor/codeburn/src/sessions-report.js +1342 -0
  145. package/dist/vendor/codeburn/src/sqlite.js +528 -0
  146. package/dist/vendor/codeburn/src/sync/otlp.js +420 -0
  147. package/dist/vendor/codeburn/src/telemetry-snapshot.js +244 -0
  148. package/dist/vendor/codeburn/src/token-estimate.js +5 -0
  149. package/dist/vendor/codeburn/src/types.js +16 -0
  150. package/dist/vendor/codeburn/src/work-units.js +126 -0
  151. package/dist/vendor/codeburn/src/workflow-insights.js +228 -0
  152. package/dist/vendor/codeburn/src/wsl.js +198 -0
  153. package/dist/vendor/codeburn/src/yield.js +666 -0
  154. package/package.json +1 -1
@@ -0,0 +1,402 @@
1
+ // @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
2
+ import { readdir, readFile, stat } from 'node:fs/promises';
3
+ import { homedir } from 'node:os';
4
+ import { basename, dirname, join, resolve } from 'node:path';
5
+ import { extractBashCommands } from '../bash-utils.js';
6
+ import { calculateCost, ownValue, pricingModelAt } from '../models.js';
7
+ import { FS_SCAN_CONCURRENCY, mapWithConcurrency } from '../fs-utils.js';
8
+ const toolNameMap = {
9
+ Bash: 'Bash',
10
+ Shell: 'Bash',
11
+ bash: 'Bash',
12
+ shell: 'Bash',
13
+ Read: 'Read',
14
+ ReadFile: 'Read',
15
+ read_file: 'Read',
16
+ Write: 'Write',
17
+ WriteFile: 'Write',
18
+ write_file: 'Write',
19
+ Edit: 'Edit',
20
+ EditFile: 'Edit',
21
+ edit_file: 'Edit',
22
+ Grep: 'Grep',
23
+ grep: 'Grep',
24
+ Glob: 'Glob',
25
+ glob: 'Glob',
26
+ Agent: 'Agent',
27
+ Task: 'Agent',
28
+ };
29
+ function asObject(value) {
30
+ return value !== null && typeof value === 'object' && !Array.isArray(value)
31
+ ? value
32
+ : null;
33
+ }
34
+ function stringValue(value) {
35
+ return typeof value === 'string' ? value.trim() : '';
36
+ }
37
+ function nonNegativeNumber(value) {
38
+ const number = typeof value === 'number'
39
+ ? value
40
+ : typeof value === 'string' && value.trim() ? Number(value) : NaN;
41
+ return Number.isFinite(number) && number >= 0 ? Math.trunc(number) : 0;
42
+ }
43
+ function timestampIso(value) {
44
+ if (typeof value === 'string') {
45
+ const date = new Date(value);
46
+ return Number.isNaN(date.getTime()) ? '' : date.toISOString();
47
+ }
48
+ if (typeof value !== 'number' || !Number.isFinite(value))
49
+ return '';
50
+ const milliseconds = value > 1_000_000_000_000 ? value : value * 1000;
51
+ const date = new Date(milliseconds);
52
+ return Number.isNaN(date.getTime()) ? '' : date.toISOString();
53
+ }
54
+ export function kimicodeHomes(override) {
55
+ const explicit = override || process.env['KIMI_CODE_HOME'];
56
+ if (explicit)
57
+ return [resolve(explicit)];
58
+ // Default stores. Beyond the CLI's own ~/.kimi-code, embedded runtimes keep
59
+ // the same wire layout under their own home (Kimi desktop app, Kimi Code
60
+ // IDE); each home is scanned so embedded-agent usage is not invisible.
61
+ const home = homedir();
62
+ const homes = [
63
+ join(home, '.kimi-code'),
64
+ join(home, 'Library', 'Application Support', 'kimi-desktop', 'daimon-share', 'daimon', 'runtime', 'kimi-code', 'home'),
65
+ ];
66
+ return [...new Set(homes.map(h => resolve(h)))];
67
+ }
68
+ async function directoryEntries(path) {
69
+ try {
70
+ return await readdir(path, { withFileTypes: true });
71
+ }
72
+ catch {
73
+ return [];
74
+ }
75
+ }
76
+ async function isFile(path) {
77
+ try {
78
+ return (await stat(path)).isFile();
79
+ }
80
+ catch {
81
+ return false;
82
+ }
83
+ }
84
+ export async function readState(sessionDir) {
85
+ try {
86
+ const state = asObject(JSON.parse(await readFile(join(sessionDir, 'state.json'), 'utf8')));
87
+ if (!state)
88
+ return {};
89
+ const agents = asObject(state['agents']);
90
+ let agentsMap;
91
+ if (agents) {
92
+ agentsMap = {};
93
+ for (const [name, descriptor] of Object.entries(agents)) {
94
+ const desc = asObject(descriptor);
95
+ if (!desc)
96
+ continue;
97
+ const parent = desc['parentAgentId'];
98
+ agentsMap[name] = { parentAgentId: parent === null || typeof parent === 'string' ? parent : undefined };
99
+ }
100
+ }
101
+ return {
102
+ createdAt: stringValue(state['createdAt']) || undefined,
103
+ createdAtMs: nonNegativeNumber(state['createdAt']) || undefined,
104
+ cwd: stringValue(state['cwd']) || undefined,
105
+ updatedAt: stringValue(state['updatedAt']) || undefined,
106
+ workDir: stringValue(state['workDir']) || undefined,
107
+ ...(agentsMap ? { agents: agentsMap } : {}),
108
+ };
109
+ }
110
+ catch {
111
+ return {};
112
+ }
113
+ }
114
+ export function projectFromWorkDir(workDir, workDirKey) {
115
+ if (workDir)
116
+ return basename(workDir.replace(/[\\/]+$/, '')) || workDir;
117
+ const match = /^wd_(.+)_[a-f0-9]{12}$/i.exec(workDirKey);
118
+ return match?.[1] || workDirKey.replace(/^wd_/, '') || 'kimicode';
119
+ }
120
+ // Walked one level at a time with each level fanned out, rather than as nested
121
+ // serial loops: the tree is thousands of tiny state.json reads and wire.jsonl
122
+ // stats, and issuing them one at a time left the corpus scan waiting on the
123
+ // kernel. The final sort makes the result order independent of completion order.
124
+ async function discoverSources(root) {
125
+ const sessionsDir = join(root, 'sessions');
126
+ const workDirs = (await directoryEntries(sessionsDir))
127
+ .filter(e => e.isDirectory() && /^w[dm]_/.test(e.name))
128
+ .map(e => ({ key: e.name, path: join(sessionsDir, e.name) }));
129
+ // Session dir naming differs by host product: the CLI uses session_*,
130
+ // embedded runtimes (desktop app, IDE) use conv-*/ctitle-*. Any directory is
131
+ // accepted; the agents/*/wire.jsonl probe below gates real sessions.
132
+ const sessionDirs = (await mapWithConcurrency(workDirs, FS_SCAN_CONCURRENCY, async (wd) => (await directoryEntries(wd.path))
133
+ .filter(e => e.isDirectory())
134
+ .map(e => ({ workDirKey: wd.key, sessionDir: join(wd.path, e.name) })))).flat();
135
+ const agents = (await mapWithConcurrency(sessionDirs, FS_SCAN_CONCURRENCY, async (sd) => {
136
+ const state = await readState(sd.sessionDir);
137
+ const workDir = state.workDir ?? state.cwd;
138
+ const project = projectFromWorkDir(workDir ?? '', sd.workDirKey);
139
+ const agentsDir = join(sd.sessionDir, 'agents');
140
+ return (await directoryEntries(agentsDir))
141
+ .filter(e => e.isDirectory())
142
+ .map(e => ({ agentName: e.name, wirePath: join(agentsDir, e.name, 'wire.jsonl'), project, workDir }));
143
+ })).flat();
144
+ const present = await mapWithConcurrency(agents, FS_SCAN_CONCURRENCY, a => isFile(a.wirePath));
145
+ const sources = [];
146
+ for (const [i, a] of agents.entries()) {
147
+ if (!present[i])
148
+ continue;
149
+ sources.push({
150
+ path: a.wirePath,
151
+ project: a.project,
152
+ provider: 'kimicode',
153
+ sourceId: a.agentName,
154
+ sourceLabel: a.agentName,
155
+ sourcePath: a.workDir,
156
+ });
157
+ }
158
+ return sources.sort((a, b) => a.path.localeCompare(b.path));
159
+ }
160
+ function sessionDirForWire(path) {
161
+ return dirname(dirname(dirname(path)));
162
+ }
163
+ function sessionIdForWire(path) {
164
+ return basename(sessionDirForWire(path)).replace(/^session_/, '');
165
+ }
166
+ function agentIdForWire(path) {
167
+ return basename(dirname(path));
168
+ }
169
+ /// Provider-recorded parent/child lineage for a single Kimi Code source.
170
+ /// The provider writes `state.json` `agents[<name>].parentAgentId` for every
171
+ /// agent in the session - `null` (or absent) for `main`, an agent name
172
+ /// otherwise. A non-`main` agent whose `parentAgentId === 'main'` is a
173
+ /// child of the session's own root. A `main` agent is a root when at
174
+ /// least one non-`main` entry exists alongside it. Returns `undefined`
175
+ /// when `state.json` is missing or carries no `agents` map, so the
176
+ /// install path can omit the field without a default.
177
+ export async function kimicodeLineageForSource(path, agentId) {
178
+ const state = await readState(sessionDirForWire(path));
179
+ const agents = state.agents;
180
+ if (!agents)
181
+ return undefined;
182
+ if (agentId !== 'main') {
183
+ const self = agents[agentId];
184
+ if (!self)
185
+ return undefined;
186
+ // The parent is `main` (the canonical session root). Provider-recorded.
187
+ if (self.parentAgentId !== 'main')
188
+ return undefined;
189
+ return { parentSessionId: 'main', role: 'child', evidence: 'provider-recorded' };
190
+ }
191
+ // `main` is a root only when another agent sits alongside it. A
192
+ // standalone main session has no children to be the parent of.
193
+ const hasChild = Object.entries(agents).some(([name, desc]) => name !== 'main' && desc.parentAgentId === 'main');
194
+ if (!hasChild)
195
+ return undefined;
196
+ return { role: 'root', evidence: 'provider-recorded' };
197
+ }
198
+ function turnIdFromStep(value) {
199
+ const turnStep = stringValue(value);
200
+ if (!turnStep)
201
+ return '';
202
+ return turnStep.split('.', 1)[0] ?? '';
203
+ }
204
+ function inputText(value) {
205
+ if (typeof value === 'string')
206
+ return value;
207
+ if (!Array.isArray(value))
208
+ return '';
209
+ return value
210
+ .map(part => {
211
+ const record = asObject(part);
212
+ return record?.['type'] === 'text' ? stringValue(record['text']) : '';
213
+ })
214
+ .filter(Boolean)
215
+ .join('\n');
216
+ }
217
+ function toolDetails(value) {
218
+ const event = asObject(value);
219
+ if (!event || stringValue(event['type']) !== 'tool.call')
220
+ return null;
221
+ const rawName = stringValue(event['name']);
222
+ if (!rawName)
223
+ return null;
224
+ const name = ownValue(toolNameMap, rawName) ?? rawName;
225
+ let args = asObject(event['args']);
226
+ if (!args && typeof event['args'] === 'string') {
227
+ try {
228
+ args = asObject(JSON.parse(event['args']));
229
+ }
230
+ catch {
231
+ args = null;
232
+ }
233
+ }
234
+ const command = stringValue(args?.['command']);
235
+ const path = stringValue(args?.['path']);
236
+ const step = { tool: name };
237
+ if (path)
238
+ step.file = path;
239
+ if (command)
240
+ step.command = command;
241
+ return {
242
+ name,
243
+ bashCommands: name === 'Bash' && command ? extractBashCommands(command) : [],
244
+ step,
245
+ };
246
+ }
247
+ function createParser(source, seenKeys) {
248
+ return {
249
+ async *parse() {
250
+ let contents;
251
+ try {
252
+ contents = await readFile(source.path, 'utf8');
253
+ }
254
+ catch {
255
+ return;
256
+ }
257
+ const sessionDir = sessionDirForWire(source.path);
258
+ const sessionId = sessionIdForWire(source.path);
259
+ const agentId = source.sourceId || agentIdForWire(source.path);
260
+ const state = await readState(sessionDir);
261
+ const fallbackTimestamp = timestampIso(state.updatedAt) || timestampIso(state.createdAt);
262
+ const projectPath = state.workDir || state.cwd || source.sourcePath;
263
+ const aliasModels = new Map();
264
+ const prompts = new Map();
265
+ let currentPrompt = '';
266
+ let currentRequest = null;
267
+ let pendingTools = [];
268
+ let pendingBashCommands = [];
269
+ let pendingToolSequence = [];
270
+ let usageOrdinal = 0;
271
+ const lines = contents.split(/\r?\n/);
272
+ for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
273
+ const line = lines[lineIndex].trim();
274
+ if (!line)
275
+ continue;
276
+ let record;
277
+ try {
278
+ record = asObject(JSON.parse(line));
279
+ }
280
+ catch {
281
+ continue;
282
+ }
283
+ if (!record)
284
+ continue;
285
+ const type = stringValue(record['type']);
286
+ if (type === 'turn.prompt') {
287
+ pendingTools = [];
288
+ pendingBashCommands = [];
289
+ pendingToolSequence = [];
290
+ currentPrompt = inputText(record['input']);
291
+ continue;
292
+ }
293
+ if (type === 'llm.request') {
294
+ const model = stringValue(record['model']);
295
+ const modelAlias = stringValue(record['modelAlias']);
296
+ const turnId = turnIdFromStep(record['turnStep']);
297
+ if (model && modelAlias)
298
+ aliasModels.set(modelAlias, model);
299
+ if (turnId && currentPrompt)
300
+ prompts.set(turnId, currentPrompt);
301
+ currentRequest = {
302
+ model,
303
+ modelAlias,
304
+ turnId,
305
+ timestamp: timestampIso(record['time']),
306
+ };
307
+ continue;
308
+ }
309
+ if (type === 'context.append_loop_event') {
310
+ const tool = toolDetails(record['event']);
311
+ if (tool) {
312
+ pendingTools.push(tool.name);
313
+ pendingBashCommands.push(...tool.bashCommands);
314
+ pendingToolSequence.push([tool.step]);
315
+ }
316
+ continue;
317
+ }
318
+ if (type !== 'usage.record')
319
+ continue;
320
+ const usage = asObject(record['usage']);
321
+ if (!usage)
322
+ continue;
323
+ const usageAlias = stringValue(record['model']);
324
+ const realModel = aliasModels.get(usageAlias) ?? (currentRequest?.model || 'kimicode-unknown');
325
+ const turnId = currentRequest?.turnId || '';
326
+ const inputTokens = nonNegativeNumber(usage['inputOther']);
327
+ const outputTokens = nonNegativeNumber(usage['output']);
328
+ const cacheReadInputTokens = nonNegativeNumber(usage['inputCacheRead']);
329
+ const cacheCreationInputTokens = nonNegativeNumber(usage['inputCacheCreation']);
330
+ const timestamp = timestampIso(record['time']) || currentRequest?.timestamp || fallbackTimestamp;
331
+ if (!timestamp) {
332
+ pendingTools = [];
333
+ pendingBashCommands = [];
334
+ pendingToolSequence = [];
335
+ continue;
336
+ }
337
+ const deduplicationKey = `kimicode:${sessionId}:${agentId}:${lineIndex + 1}:${usageOrdinal}`;
338
+ usageOrdinal++;
339
+ if (seenKeys.has(deduplicationKey)) {
340
+ pendingTools = [];
341
+ pendingBashCommands = [];
342
+ pendingToolSequence = [];
343
+ continue;
344
+ }
345
+ seenKeys.add(deduplicationKey);
346
+ yield {
347
+ provider: 'kimicode',
348
+ model: realModel,
349
+ inputTokens,
350
+ outputTokens,
351
+ cacheCreationInputTokens,
352
+ cacheReadInputTokens,
353
+ cachedInputTokens: cacheReadInputTokens,
354
+ reasoningTokens: 0,
355
+ webSearchRequests: 0,
356
+ costUSD: calculateCost(pricingModelAt(realModel, timestamp), inputTokens, outputTokens, cacheCreationInputTokens, cacheReadInputTokens, 0),
357
+ costIsEstimated: true,
358
+ tools: pendingTools,
359
+ bashCommands: pendingBashCommands,
360
+ toolSequence: pendingToolSequence.length > 0 ? pendingToolSequence : undefined,
361
+ timestamp,
362
+ speed: 'standard',
363
+ deduplicationKey,
364
+ turnId: turnId || undefined,
365
+ userMessage: prompts.get(turnId) ?? currentPrompt,
366
+ sessionId,
367
+ project: source.project,
368
+ projectPath,
369
+ };
370
+ pendingTools = [];
371
+ pendingBashCommands = [];
372
+ pendingToolSequence = [];
373
+ }
374
+ },
375
+ };
376
+ }
377
+ export function createKimicodeProvider(homeOverride) {
378
+ return {
379
+ name: 'kimicode',
380
+ displayName: 'Kimi Code',
381
+ modelDisplayName(model) {
382
+ return model;
383
+ },
384
+ toolDisplayName(rawTool) {
385
+ return ownValue(toolNameMap, rawTool) ?? rawTool;
386
+ },
387
+ async probeRoots() {
388
+ return kimicodeHomes(homeOverride).map(path => ({ path, label: 'Kimi Code home' }));
389
+ },
390
+ async discoverSessions() {
391
+ const all = [];
392
+ for (const home of kimicodeHomes(homeOverride)) {
393
+ all.push(...await discoverSources(home));
394
+ }
395
+ return all.sort((a, b) => a.path.localeCompare(b.path));
396
+ },
397
+ createSessionParser(source, seenKeys) {
398
+ return createParser(source, seenKeys);
399
+ },
400
+ };
401
+ }
402
+ export const kimicode = createKimicodeProvider();