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,442 @@
1
+ // @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
2
+ import { open, readdir, stat } from 'fs/promises';
3
+ import { homedir } from 'os';
4
+ import { join } from 'path';
5
+ import { extractBashCommands } from '../bash-utils.js';
6
+ import { readSessionFile } from '../fs-utils.js';
7
+ import { calculateCost, getShortModelName } from '../models.js';
8
+ const METADATA_PREFIX_BYTES = 64 * 1024;
9
+ const toolNameMap = {
10
+ exec_shell: 'Bash',
11
+ exec_shell_wait: 'Bash',
12
+ exec_shell_interact: 'Bash',
13
+ exec_shell_cancel: 'Bash',
14
+ task_shell_start: 'Bash',
15
+ task_shell_wait: 'Bash',
16
+ terminal_run: 'Bash',
17
+ terminal_send: 'Bash',
18
+ terminal_wait: 'Bash',
19
+ terminal_cancel: 'Bash',
20
+ read_file: 'Read',
21
+ write_file: 'Write',
22
+ edit_file: 'Edit',
23
+ fim_edit: 'Edit',
24
+ apply_patch: 'Edit',
25
+ list_dir: 'Glob',
26
+ grep_files: 'Grep',
27
+ web_search: 'WebSearch',
28
+ fetch_url: 'WebFetch',
29
+ 'web.run': 'WebSearch',
30
+ agent: 'Agent',
31
+ 'agents/list': 'Agent',
32
+ 'agents/message': 'Agent',
33
+ 'agents/followup': 'Agent',
34
+ 'agents/interrupt': 'Agent',
35
+ 'agents/wait': 'Agent',
36
+ todo_write: 'TodoWrite',
37
+ todo_add: 'TodoWrite',
38
+ todo_update: 'TodoWrite',
39
+ todo_list: 'TodoWrite',
40
+ checklist_write: 'TodoWrite',
41
+ checklist_add: 'TodoWrite',
42
+ checklist_update: 'TodoWrite',
43
+ checklist_list: 'TodoWrite',
44
+ update_plan: 'TodoWrite',
45
+ load_skill: 'Skill',
46
+ request_user_input: 'AskUser',
47
+ };
48
+ function isRecord(value) {
49
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
50
+ }
51
+ function nonEmptyString(value) {
52
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
53
+ }
54
+ function safeNonNegativeNumber(value) {
55
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
56
+ }
57
+ function safeTokenCount(value) {
58
+ return Math.floor(Math.min(safeNonNegativeNumber(value), Number.MAX_SAFE_INTEGER));
59
+ }
60
+ function parseMetadata(value) {
61
+ if (!isRecord(value))
62
+ return null;
63
+ const id = nonEmptyString(value['id']);
64
+ if (!id)
65
+ return null;
66
+ return {
67
+ id,
68
+ created_at: nonEmptyString(value['created_at']),
69
+ updated_at: nonEmptyString(value['updated_at']),
70
+ total_tokens: safeTokenCount(value['total_tokens']),
71
+ model: nonEmptyString(value['model']),
72
+ model_provider: nonEmptyString(value['model_provider']),
73
+ workspace: nonEmptyString(value['workspace']),
74
+ cost: isRecord(value['cost']) ? value['cost'] : undefined,
75
+ };
76
+ }
77
+ function findStringEnd(source, start) {
78
+ for (let i = start + 1; i < source.length; i++) {
79
+ if (source.charCodeAt(i) === 0x5c) {
80
+ i++;
81
+ }
82
+ else if (source.charCodeAt(i) === 0x22) {
83
+ return i;
84
+ }
85
+ }
86
+ return -1;
87
+ }
88
+ function findObjectEnd(source, start) {
89
+ let depth = 0;
90
+ let inString = false;
91
+ for (let i = start; i < source.length; i++) {
92
+ const ch = source.charCodeAt(i);
93
+ if (inString) {
94
+ if (ch === 0x5c)
95
+ i++;
96
+ else if (ch === 0x22)
97
+ inString = false;
98
+ continue;
99
+ }
100
+ if (ch === 0x22)
101
+ inString = true;
102
+ else if (ch === 0x7b)
103
+ depth++;
104
+ else if (ch === 0x7d && --depth === 0)
105
+ return i;
106
+ }
107
+ return -1;
108
+ }
109
+ // CodeWhale itself reads only the first 64 KiB when listing sessions. Mirror
110
+ // that fast path so discovery does not parse every multi-megabyte transcript.
111
+ function extractTopLevelMetadata(source) {
112
+ let depth = 0;
113
+ for (let i = 0; i < source.length; i++) {
114
+ const ch = source.charCodeAt(i);
115
+ if (ch === 0x7b) {
116
+ depth++;
117
+ continue;
118
+ }
119
+ if (ch === 0x7d) {
120
+ depth--;
121
+ continue;
122
+ }
123
+ if (ch !== 0x22)
124
+ continue;
125
+ const end = findStringEnd(source, i);
126
+ if (end === -1)
127
+ return null;
128
+ if (depth !== 1) {
129
+ i = end;
130
+ continue;
131
+ }
132
+ let key;
133
+ try {
134
+ key = JSON.parse(source.slice(i, end + 1));
135
+ }
136
+ catch {
137
+ return null;
138
+ }
139
+ i = end;
140
+ if (key !== 'metadata')
141
+ continue;
142
+ let cursor = end + 1;
143
+ while (cursor < source.length && /\s/.test(source[cursor]))
144
+ cursor++;
145
+ if (source[cursor] !== ':')
146
+ continue;
147
+ cursor++;
148
+ while (cursor < source.length && /\s/.test(source[cursor]))
149
+ cursor++;
150
+ if (source[cursor] !== '{')
151
+ return null;
152
+ const objectEnd = findObjectEnd(source, cursor);
153
+ if (objectEnd === -1)
154
+ return null;
155
+ try {
156
+ return parseMetadata(JSON.parse(source.slice(cursor, objectEnd + 1)));
157
+ }
158
+ catch {
159
+ return null;
160
+ }
161
+ }
162
+ return null;
163
+ }
164
+ async function readSessionMetadata(filePath) {
165
+ const handle = await open(filePath, 'r').catch(() => null);
166
+ if (!handle)
167
+ return null;
168
+ try {
169
+ try {
170
+ const prefix = Buffer.alloc(METADATA_PREFIX_BYTES);
171
+ const { bytesRead } = await handle.read(prefix, 0, prefix.length, 0);
172
+ const metadata = extractTopLevelMetadata(prefix.subarray(0, bytesRead).toString('utf-8'));
173
+ if (metadata)
174
+ return metadata;
175
+ }
176
+ catch {
177
+ return null;
178
+ }
179
+ }
180
+ finally {
181
+ await handle.close().catch(() => { });
182
+ }
183
+ const raw = await readSessionFile(filePath);
184
+ if (raw === null)
185
+ return null;
186
+ try {
187
+ const parsed = JSON.parse(raw);
188
+ return parseMetadata(parsed.metadata);
189
+ }
190
+ catch {
191
+ return null;
192
+ }
193
+ }
194
+ function defaultSessionDirs() {
195
+ const configuredHome = process.env['CODEWHALE_HOME']?.trim();
196
+ if (configuredHome)
197
+ return [join(configuredHome, 'sessions')];
198
+ return [
199
+ join(homedir(), '.codewhale', 'sessions'),
200
+ join(homedir(), '.deepseek', 'sessions'),
201
+ ];
202
+ }
203
+ function projectName(workspace) {
204
+ if (!workspace)
205
+ return 'CodeWhale';
206
+ const parts = workspace.replace(/[\\/]+$/, '').split(/[\\/]/).filter(Boolean);
207
+ return parts.at(-1) ?? 'CodeWhale';
208
+ }
209
+ async function discoverInDir(dir) {
210
+ const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
211
+ const results = [];
212
+ for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
213
+ if (!entry.isFile() || !entry.name.endsWith('.json'))
214
+ continue;
215
+ const path = join(dir, entry.name);
216
+ const metadata = await readSessionMetadata(path);
217
+ if (!metadata)
218
+ continue;
219
+ results.push({
220
+ id: metadata.id,
221
+ source: {
222
+ path,
223
+ project: projectName(metadata.workspace),
224
+ provider: 'codewhale',
225
+ },
226
+ });
227
+ }
228
+ return results;
229
+ }
230
+ function normalizeTimestamp(value) {
231
+ if (!value)
232
+ return '';
233
+ const timestamp = Date.parse(value);
234
+ return Number.isFinite(timestamp) ? new Date(timestamp).toISOString() : '';
235
+ }
236
+ function firstUserMessage(messages) {
237
+ for (const message of messages) {
238
+ if (message.role !== 'user')
239
+ continue;
240
+ const text = typeof message.content === 'string'
241
+ ? message.content
242
+ : Array.isArray(message.content)
243
+ ? message.content
244
+ .filter(block => block?.type === 'text' && typeof block.text === 'string')
245
+ .map(block => block.text)
246
+ .join(' ')
247
+ : '';
248
+ if (text.trim())
249
+ return Array.from(text.trim()).slice(0, 500).join('');
250
+ }
251
+ return '';
252
+ }
253
+ function mapToolName(rawName) {
254
+ if (rawName.startsWith('mcp__'))
255
+ return rawName;
256
+ if (rawName.startsWith('agents/'))
257
+ return 'Agent';
258
+ return Object.prototype.hasOwnProperty.call(toolNameMap, rawName)
259
+ ? toolNameMap[rawName]
260
+ : rawName;
261
+ }
262
+ function toolInput(value) {
263
+ return isRecord(value) ? value : {};
264
+ }
265
+ function firstString(input, keys) {
266
+ for (const key of keys) {
267
+ const value = nonEmptyString(input[key]);
268
+ if (value)
269
+ return value;
270
+ }
271
+ return undefined;
272
+ }
273
+ function collectTools(messages) {
274
+ const tools = [];
275
+ const bashCommands = [];
276
+ const toolSequence = [];
277
+ const skills = [];
278
+ const subagentTypes = [];
279
+ let webSearchRequests = 0;
280
+ for (const message of messages) {
281
+ if (message.role !== 'assistant' || !Array.isArray(message.content))
282
+ continue;
283
+ const turnTools = [];
284
+ for (const block of message.content) {
285
+ if (block?.type !== 'tool_use' && block?.type !== 'server_tool_use')
286
+ continue;
287
+ const rawName = nonEmptyString(block.name);
288
+ if (!rawName)
289
+ continue;
290
+ const mapped = mapToolName(rawName);
291
+ const input = toolInput(block.input);
292
+ const toolCall = { tool: mapped };
293
+ const file = firstString(input, ['file_path', 'path', 'target_file', 'file']);
294
+ if (file)
295
+ toolCall.file = file;
296
+ const command = firstString(input, ['command', 'cmd']);
297
+ if (command)
298
+ toolCall.command = command;
299
+ if (mapped === 'Bash' && command) {
300
+ bashCommands.push(...extractBashCommands(command));
301
+ }
302
+ if (mapped === 'Skill') {
303
+ const skill = firstString(input, ['name', 'skill', 'skill_name']);
304
+ if (skill)
305
+ skills.push(skill);
306
+ }
307
+ if (mapped === 'Agent') {
308
+ const subagentType = firstString(input, ['type', 'agent_type', 'profile']);
309
+ if (subagentType)
310
+ subagentTypes.push(subagentType);
311
+ }
312
+ if (mapped === 'WebSearch')
313
+ webSearchRequests++;
314
+ tools.push(mapped);
315
+ turnTools.push(toolCall);
316
+ }
317
+ if (turnTools.length > 0)
318
+ toolSequence.push(turnTools);
319
+ }
320
+ return { tools, bashCommands, toolSequence, skills, subagentTypes, webSearchRequests };
321
+ }
322
+ function reportedCost(cost) {
323
+ if (!cost || typeof cost !== 'object')
324
+ return { value: 0, exact: false };
325
+ const hasSessionCost = Object.prototype.hasOwnProperty.call(cost, 'session_cost_usd');
326
+ const hasSubagentCost = Object.prototype.hasOwnProperty.call(cost, 'subagent_cost_usd');
327
+ if (!hasSessionCost && !hasSubagentCost)
328
+ return { value: 0, exact: false };
329
+ return {
330
+ value: safeNonNegativeNumber(cost.session_cost_usd) + safeNonNegativeNumber(cost.subagent_cost_usd),
331
+ exact: true,
332
+ };
333
+ }
334
+ function createParser(source, seenKeys) {
335
+ return {
336
+ async *parse() {
337
+ const raw = await readSessionFile(source.path);
338
+ let metadata = null;
339
+ let messages = [];
340
+ if (raw !== null) {
341
+ try {
342
+ const saved = JSON.parse(raw);
343
+ metadata = parseMetadata(saved.metadata);
344
+ messages = Array.isArray(saved.messages)
345
+ ? saved.messages.filter(isRecord)
346
+ : [];
347
+ }
348
+ catch {
349
+ // A truncated transcript can still have complete, authoritative
350
+ // aggregate metadata at the front of the file.
351
+ }
352
+ }
353
+ metadata ??= await readSessionMetadata(source.path);
354
+ if (!metadata)
355
+ return;
356
+ const totalTokens = safeTokenCount(metadata.total_tokens);
357
+ const model = metadata.model ?? metadata.model_provider ?? 'unknown';
358
+ const localCost = reportedCost(metadata.cost);
359
+ const costUSD = localCost.exact
360
+ ? localCost.value
361
+ : calculateCost(model, totalTokens, 0, 0, 0, 0);
362
+ if (totalTokens === 0 && costUSD === 0)
363
+ return;
364
+ const deduplicationKey = `codewhale:${metadata.id}`;
365
+ if (seenKeys.has(deduplicationKey))
366
+ return;
367
+ seenKeys.add(deduplicationKey);
368
+ let timestamp = normalizeTimestamp(metadata.updated_at) || normalizeTimestamp(metadata.created_at);
369
+ if (!timestamp) {
370
+ const fileStat = await stat(source.path).catch(() => null);
371
+ timestamp = fileStat?.mtime.toISOString() ?? '';
372
+ }
373
+ const { tools, bashCommands, toolSequence, skills, subagentTypes, webSearchRequests } = collectTools(messages);
374
+ const workspace = metadata.workspace;
375
+ yield {
376
+ provider: 'codewhale',
377
+ model,
378
+ // CodeWhale persists only one aggregate token counter. Preserve it
379
+ // losslessly in the input column instead of inventing a split.
380
+ inputTokens: totalTokens,
381
+ outputTokens: 0,
382
+ cacheCreationInputTokens: 0,
383
+ cacheReadInputTokens: 0,
384
+ cachedInputTokens: 0,
385
+ reasoningTokens: 0,
386
+ webSearchRequests,
387
+ costUSD,
388
+ costIsEstimated: !localCost.exact,
389
+ tools,
390
+ bashCommands,
391
+ skills,
392
+ subagentTypes,
393
+ timestamp,
394
+ speed: 'standard',
395
+ deduplicationKey,
396
+ turnId: `${metadata.id}:session`,
397
+ toolSequence: toolSequence.length > 0 ? toolSequence : undefined,
398
+ userMessage: firstUserMessage(messages),
399
+ sessionId: metadata.id,
400
+ project: projectName(workspace),
401
+ projectPath: workspace,
402
+ };
403
+ },
404
+ };
405
+ }
406
+ export function createCodeWhaleProvider(overrideDirs) {
407
+ const configuredDirs = overrideDirs === undefined
408
+ ? undefined
409
+ : Array.isArray(overrideDirs) ? overrideDirs : [overrideDirs];
410
+ return {
411
+ name: 'codewhale',
412
+ displayName: 'CodeWhale',
413
+ modelDisplayName(model) {
414
+ return getShortModelName(model);
415
+ },
416
+ toolDisplayName(rawTool) {
417
+ return mapToolName(rawTool);
418
+ },
419
+ async probeRoots() {
420
+ return (configuredDirs ?? defaultSessionDirs()).map(path => ({ path, label: 'sessions' }));
421
+ },
422
+ async discoverSessions() {
423
+ const seenSessionIds = new Set();
424
+ const sources = [];
425
+ // Primary comes before legacy so an id already migrated by CodeWhale is
426
+ // not counted twice and the primary copy wins without modifying either.
427
+ for (const dir of configuredDirs ?? defaultSessionDirs()) {
428
+ for (const candidate of await discoverInDir(dir)) {
429
+ if (seenSessionIds.has(candidate.id))
430
+ continue;
431
+ seenSessionIds.add(candidate.id);
432
+ sources.push(candidate.source);
433
+ }
434
+ }
435
+ return sources;
436
+ },
437
+ createSessionParser(source, seenKeys) {
438
+ return createParser(source, seenKeys);
439
+ },
440
+ };
441
+ }
442
+ export const codewhale = createCodeWhaleProvider();