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,429 @@
1
+ import { readdir, stat } from 'fs/promises';
2
+ import { basename, join } from 'path';
3
+ import { homedir } from 'os';
4
+ import { readSessionFile, readSessionLines } from '../fs-utils.js';
5
+ import { calculateCost, ownValue } from '../models.js';
6
+ import { extractBashCommands } from '../bash-utils.js';
7
+ import { normalizeContentBlocks } from '../content-utils.js';
8
+ const toolNameMap = {
9
+ bash: 'Bash',
10
+ read: 'Read',
11
+ edit: 'Edit',
12
+ write: 'Write',
13
+ glob: 'Glob',
14
+ grep: 'Grep',
15
+ task: 'Agent',
16
+ dispatch_agent: 'Agent',
17
+ fetch: 'WebFetch',
18
+ search: 'WebSearch',
19
+ todo: 'TodoWrite',
20
+ patch: 'Patch',
21
+ };
22
+ // Pi/OMP have no dedicated skill tool the way Claude Code does. A native skill
23
+ // load is emitted as an ordinary `read` tool call whose path points at the
24
+ // skill's `SKILL.md` (Pi resolves skills from many roots: ~/.pi/agent/skills,
25
+ // project .pi/skills, .agents/skills, package skills/, --skill <path>), or, in
26
+ // newer OMP builds, at a `skill://<name>` URI. Left untouched these inflate the
27
+ // Read tool count and leave the Skills dimension empty (issue #588). Return the
28
+ // skill name when a read is really a skill load, else null so it stays a Read.
29
+ function skillLoadName(name, args) {
30
+ if (name !== 'read')
31
+ return null;
32
+ const raw = args?.['path'] ?? args?.['file_path'];
33
+ if (typeof raw !== 'string')
34
+ return null;
35
+ const path = raw.trim();
36
+ if (path.length === 0)
37
+ return null;
38
+ if (path.startsWith('skill://')) {
39
+ const rest = path.slice('skill://'.length).replace(/^\/+/, '');
40
+ const first = rest.split(/[/?#]/)[0]?.trim() ?? '';
41
+ return first.length > 0 ? first : null;
42
+ }
43
+ // Match on the SKILL.md basename, not a directory prefix, because skill roots
44
+ // live in many locations. Split on both separators so Windows paths work.
45
+ const segments = path.split(/[\\/]/).filter(Boolean);
46
+ if (segments[segments.length - 1] !== 'SKILL.md')
47
+ return null;
48
+ const parent = segments[segments.length - 2]?.trim();
49
+ return parent && parent.length > 0 ? parent : null;
50
+ }
51
+ // OMP logs side calls outside the assistant transcript as `model_usage`
52
+ // entries: find and judge decisions (Jev), cache warming, and similar. They
53
+ // never duplicate an assistant message, so each one counts as its own call.
54
+ // The tool column carries the purpose, such as `find`, so a report can split
55
+ // decision spend from chat spend.
56
+ function modelUsageCall(entry, source, sessionId, lineIdx, sessionTimestamp, seenKeys) {
57
+ const usage = entry.usage;
58
+ if (!usage)
59
+ return null;
60
+ const input = usage.input ?? 0;
61
+ const output = usage.output ?? 0;
62
+ const cacheRead = usage.cacheRead ?? 0;
63
+ const cacheWrite = usage.cacheWrite ?? 0;
64
+ if (input === 0 && output === 0 && cacheRead === 0)
65
+ return null;
66
+ const bare = entry.model ?? '';
67
+ // OMP writes routed ids such as `~typesafe/jev-latest` beside provider
68
+ // `openrouter`. The provider prefix keeps them distinct and priceable.
69
+ const model = !entry.provider || bare.startsWith(`${entry.provider}/`) ? bare : `${entry.provider}/${bare}`;
70
+ if (!model)
71
+ return null;
72
+ const dedupKey = `${source.provider}:${source.path}:model_usage:${entry.id || entry.timestamp || String(lineIdx)}`;
73
+ if (seenKeys.has(dedupKey))
74
+ return null;
75
+ seenKeys.add(dedupKey);
76
+ const reported = usage.cost?.total;
77
+ const costUSD = typeof reported === 'number' && Number.isFinite(reported) && reported !== 0
78
+ ? reported
79
+ : calculateCost(model, input, output, cacheWrite, cacheRead, 0);
80
+ const timestamp = entry.timestamp || sessionTimestamp;
81
+ if (!timestamp)
82
+ return null;
83
+ return {
84
+ provider: source.provider,
85
+ model,
86
+ inputTokens: input,
87
+ outputTokens: output,
88
+ cacheCreationInputTokens: cacheWrite,
89
+ cacheReadInputTokens: cacheRead,
90
+ cachedInputTokens: cacheRead,
91
+ reasoningTokens: 0,
92
+ webSearchRequests: 0,
93
+ costUSD,
94
+ tools: [entry.purpose ? `omp:${entry.purpose}` : 'omp:side-call'],
95
+ bashCommands: [],
96
+ skills: [],
97
+ timestamp,
98
+ speed: 'standard',
99
+ deduplicationKey: dedupKey,
100
+ userMessage: '',
101
+ sessionId,
102
+ };
103
+ }
104
+ function getPiSessionsDir(override) {
105
+ return override ?? join(homedir(), '.pi', 'agent', 'sessions');
106
+ }
107
+ function getOmpSessionsDir(override) {
108
+ return override ?? join(homedir(), '.omp', 'agent', 'sessions');
109
+ }
110
+ // OMP can write a fixed-width title metadata line (`type: "title"`) before the
111
+ // `type: "session"` header (issue #845), and either provider may pad the
112
+ // header with blank lines. Scan a bounded number of leading lines rather than
113
+ // just the first one, and rather than the whole file (issue #846 read each
114
+ // transcript in full to reach line 0), so discovery stays cheap even when a
115
+ // file turns out to have no session record at all (a message-only file, or a
116
+ // pathological run of blank/junk lines).
117
+ const MAX_HEADER_LINES_SCANNED = 20;
118
+ function looksAbsolutePath(value) {
119
+ const trimmed = value.trim();
120
+ if (!trimmed)
121
+ return false;
122
+ return trimmed.startsWith('/') || /^[a-zA-Z]:[\\/]/.test(trimmed);
123
+ }
124
+ async function readSessionEntry(filePath) {
125
+ let linesScanned = 0;
126
+ for await (const line of readSessionLines(filePath)) {
127
+ if (linesScanned >= MAX_HEADER_LINES_SCANNED)
128
+ break;
129
+ linesScanned++;
130
+ const trimmed = line.trim();
131
+ if (!trimmed)
132
+ continue;
133
+ try {
134
+ const entry = JSON.parse(trimmed);
135
+ if (entry.type === 'session')
136
+ return entry;
137
+ }
138
+ catch {
139
+ continue;
140
+ }
141
+ }
142
+ return null;
143
+ }
144
+ async function discoverSessionsInDir(sessionsDir, providerName) {
145
+ const sources = [];
146
+ let projectDirs;
147
+ try {
148
+ projectDirs = await readdir(sessionsDir);
149
+ }
150
+ catch {
151
+ return sources;
152
+ }
153
+ for (const dirName of projectDirs) {
154
+ const dirPath = join(sessionsDir, dirName);
155
+ const dirStat = await stat(dirPath).catch(() => null);
156
+ if (!dirStat?.isDirectory())
157
+ continue;
158
+ let entries;
159
+ try {
160
+ entries = await readdir(dirPath, { withFileTypes: true });
161
+ }
162
+ catch {
163
+ continue;
164
+ }
165
+ const addSession = async (filePath, agentName) => {
166
+ const entry = await readSessionEntry(filePath);
167
+ if (!entry)
168
+ return;
169
+ // Prefer the session header cwd when present. Keep basename(project) for
170
+ // display, but retain the absolute cwd on sourcePath so parse/grouping
171
+ // never have to infer identity from the sole observed leaf name (#1260).
172
+ const rawCwd = typeof entry.cwd === 'string' ? entry.cwd.trim() : '';
173
+ const cwd = rawCwd || dirName;
174
+ const absCwd = looksAbsolutePath(cwd) ? cwd : undefined;
175
+ sources.push({
176
+ path: filePath,
177
+ project: basename(cwd) || cwd,
178
+ provider: providerName,
179
+ ...(absCwd ? { sourcePath: absCwd } : {}),
180
+ ...(agentName ? {
181
+ agentName,
182
+ ...(typeof entry.timestamp === 'string' ? { agentStartedAt: entry.timestamp } : {}),
183
+ } : {}),
184
+ });
185
+ };
186
+ for (const entry of entries) {
187
+ if (entry.isFile() && entry.name.endsWith('.jsonl')) {
188
+ await addSession(join(dirPath, entry.name));
189
+ continue;
190
+ }
191
+ if (providerName !== 'omp' || !entry.isDirectory())
192
+ continue;
193
+ const agentDir = join(dirPath, entry.name);
194
+ const agentEntries = await readdir(agentDir, { withFileTypes: true }).catch(() => []);
195
+ for (const agentEntry of agentEntries) {
196
+ if (!agentEntry.isFile() || !agentEntry.name.endsWith('.jsonl'))
197
+ continue;
198
+ await addSession(join(agentDir, agentEntry.name), basename(agentEntry.name, '.jsonl'));
199
+ }
200
+ }
201
+ }
202
+ return sources;
203
+ }
204
+ // OMP records a session-level model (`model_change` entry) plus an optional
205
+ // per-message `model`. The per-message value may be a bare model name without
206
+ // the provider prefix (e.g. "gpt-5.6-terra" vs "openai-codex/gpt-5.6-terra").
207
+ // Prefer the fully-qualified form when the two agree; fall back to whatever
208
+ // the message carries, then the session model, then a safe default.
209
+ function resolveMessageModel(messageModel, resolvedModel) {
210
+ if (messageModel.includes('/'))
211
+ return messageModel;
212
+ if (resolvedModel && (!messageModel || resolvedModel === messageModel || resolvedModel.endsWith(`/${messageModel}`))) {
213
+ return resolvedModel;
214
+ }
215
+ return messageModel || resolvedModel || 'gpt-5';
216
+ }
217
+ function createParser(source, seenKeys) {
218
+ return {
219
+ async *parse() {
220
+ const content = await readSessionFile(source.path);
221
+ if (content === null)
222
+ return;
223
+ // Last-resort timestamp so a call whose entry/user/session timestamps are
224
+ // all missing lands inside the session's window instead of being dropped.
225
+ const fileStat = await stat(source.path).catch(() => null);
226
+ const fileMtime = fileStat?.mtime.toISOString() ?? '';
227
+ const lines = content.split('\n').filter(l => l.trim());
228
+ let sessionId = basename(source.path, '.jsonl');
229
+ let resolvedModel = '';
230
+ let pendingUserMessage = '';
231
+ let sessionTimestamp = '';
232
+ let pendingUserTimestamp = '';
233
+ // Absolute session cwd from the header (or discovery sourcePath). Must
234
+ // survive into projectPath/workingDirectory so cross-provider merge can
235
+ // key by real path instead of basename-only (#1260).
236
+ let sessionCwd = typeof source.sourcePath === 'string' && looksAbsolutePath(source.sourcePath)
237
+ ? source.sourcePath.trim()
238
+ : '';
239
+ for (const [lineIdx, line] of lines.entries()) {
240
+ let entry;
241
+ try {
242
+ entry = JSON.parse(line);
243
+ }
244
+ catch {
245
+ continue;
246
+ }
247
+ if (entry.type === 'session') {
248
+ sessionId = entry.id ?? sessionId;
249
+ if (typeof entry.timestamp === 'string' && entry.timestamp)
250
+ sessionTimestamp = entry.timestamp;
251
+ if (typeof entry.cwd === 'string' && entry.cwd.trim()) {
252
+ const headerCwd = entry.cwd.trim();
253
+ if (looksAbsolutePath(headerCwd))
254
+ sessionCwd = headerCwd;
255
+ }
256
+ continue;
257
+ }
258
+ if (entry.type === 'model_change') {
259
+ if (typeof entry.model === 'string' && entry.model)
260
+ resolvedModel = entry.model;
261
+ continue;
262
+ }
263
+ if (entry.type === 'model_usage') {
264
+ const call = modelUsageCall(entry, source, sessionId, lineIdx, sessionTimestamp, seenKeys);
265
+ if (call)
266
+ yield call;
267
+ continue;
268
+ }
269
+ if (entry.type !== 'message')
270
+ continue;
271
+ const msg = entry.message;
272
+ if (!msg)
273
+ continue;
274
+ if (msg.role === 'user') {
275
+ const attributedTimestamp = msg.attribution?.timestamp;
276
+ if (typeof entry.timestamp === 'string' && entry.timestamp) {
277
+ pendingUserTimestamp = entry.timestamp;
278
+ }
279
+ else if (typeof attributedTimestamp === 'number' && Number.isFinite(attributedTimestamp)) {
280
+ pendingUserTimestamp = new Date(attributedTimestamp).toISOString();
281
+ }
282
+ const texts = normalizeContentBlocks(msg.content)
283
+ .filter(c => c.type === 'text')
284
+ .map(c => c.text ?? '')
285
+ .filter(Boolean);
286
+ if (texts.length > 0)
287
+ pendingUserMessage = texts.join(' ');
288
+ continue;
289
+ }
290
+ if (msg.role !== 'assistant' || !msg.usage)
291
+ continue;
292
+ // Coerce undefined/null token fields to 0. Pi/OMP session files
293
+ // sometimes omit individual usage fields; pass only numeric values to
294
+ // the pricing fallback so it cannot contaminate aggregates with NaN.
295
+ const input = msg.usage.input ?? 0;
296
+ const output = msg.usage.output ?? 0;
297
+ const cacheRead = msg.usage.cacheRead ?? 0;
298
+ const cacheWrite = msg.usage.cacheWrite ?? 0;
299
+ if (input === 0 && output === 0)
300
+ continue;
301
+ const messageModel = msg.model ?? '';
302
+ const model = resolveMessageModel(messageModel, resolvedModel);
303
+ const responseId = msg.responseId ?? '';
304
+ const dedupKey = `${source.provider}:${source.path}:${responseId || entry.id || entry.timestamp || String(lineIdx)}`;
305
+ if (seenKeys.has(dedupKey))
306
+ continue;
307
+ seenKeys.add(dedupKey);
308
+ const toolCalls = normalizeContentBlocks(msg.content).filter(c => c.type === 'toolCall' && c.name);
309
+ // A SKILL.md-loading read is surfaced as the `Skill` tool (not `Read`)
310
+ // and its name is recorded in `skills`. This mirrors how the Claude
311
+ // parser represents a skill invocation, so the shared classifier tags
312
+ // the turn `general` and the "Skills & Agents" breakdown picks it up,
313
+ // instead of over-counting a Read and leaving Skills empty (#588).
314
+ // Every other call stays a normal tool.
315
+ const tools = [];
316
+ const skills = [];
317
+ for (const c of toolCalls) {
318
+ const skill = skillLoadName(c.name, c.arguments);
319
+ if (skill !== null) {
320
+ skills.push(skill);
321
+ tools.push('Skill');
322
+ continue;
323
+ }
324
+ tools.push(ownValue(toolNameMap, c.name) ?? c.name);
325
+ }
326
+ const bashCommands = toolCalls
327
+ .filter(c => c.name === 'bash')
328
+ .flatMap(c => {
329
+ const cmd = c.arguments?.['command'];
330
+ return typeof cmd === 'string' ? extractBashCommands(cmd) : [];
331
+ });
332
+ const reportedCost = msg.usage.cost?.total;
333
+ // A zero reported cost acts as absent: OMP writes cost.total = 0 for
334
+ // xai-oauth calls, so the alias table and price overrides never apply.
335
+ // A genuinely free call would recompute to a small nonzero number;
336
+ // that is the trade-off we accept for fixing the OAuth zero.
337
+ // Per-message USD, never a running session total (verified against
338
+ // real Pi transcripts: cost.total equals this message's own
339
+ // input+output+cacheRead+cacheWrite and does not increase monotonically).
340
+ const isReported = typeof reportedCost === 'number' && Number.isFinite(reportedCost) && reportedCost !== 0;
341
+ const costUSD = isReported
342
+ ? reportedCost
343
+ : calculateCost(messageModel || resolvedModel || model, input, output, cacheWrite, cacheRead, 0);
344
+ const timestamp = entry.timestamp || pendingUserTimestamp || sessionTimestamp || fileMtime;
345
+ if (!timestamp)
346
+ continue;
347
+ yield {
348
+ provider: source.provider,
349
+ model,
350
+ inputTokens: input,
351
+ outputTokens: output,
352
+ cacheCreationInputTokens: cacheWrite,
353
+ cacheReadInputTokens: cacheRead,
354
+ cachedInputTokens: cacheRead,
355
+ reasoningTokens: 0,
356
+ webSearchRequests: 0,
357
+ costUSD,
358
+ ...(isReported ? { costFromBilling: true } : {}),
359
+ tools,
360
+ bashCommands,
361
+ skills,
362
+ timestamp,
363
+ speed: 'standard',
364
+ deduplicationKey: dedupKey,
365
+ userMessage: pendingUserMessage,
366
+ sessionId,
367
+ project: source.project,
368
+ ...(sessionCwd ? {
369
+ projectPath: sessionCwd,
370
+ workingDirectory: sessionCwd,
371
+ } : {}),
372
+ };
373
+ pendingUserMessage = '';
374
+ }
375
+ },
376
+ };
377
+ }
378
+ export function createPiProvider(sessionsDir) {
379
+ const dir = getPiSessionsDir(sessionsDir);
380
+ return {
381
+ name: 'pi',
382
+ async probeRoots() {
383
+ return [{ path: dir, label: 'sessions' }];
384
+ },
385
+ displayName: 'Pi',
386
+ // No local display table (#1530): every entry one used to carry exists in
387
+ // the global SHORT_NAMES with the same label, and a local list that lags
388
+ // behind it re-creates the #1530 inconsistency (a bare `gpt-5` key
389
+ // swallowing `gpt-5-mini` into "GPT-5"). Echoing the raw id lets the
390
+ // report layer's fallbackRawModelDisplayName resolve every id with the
391
+ // one global getShortModelName all providers share.
392
+ modelDisplayName(model) {
393
+ return model;
394
+ },
395
+ toolDisplayName(rawTool) {
396
+ return ownValue(toolNameMap, rawTool) ?? rawTool;
397
+ },
398
+ async discoverSessions() {
399
+ return discoverSessionsInDir(dir, 'pi');
400
+ },
401
+ createSessionParser(source, seenKeys) {
402
+ return createParser(source, seenKeys);
403
+ },
404
+ };
405
+ }
406
+ export const pi = createPiProvider();
407
+ export function createOmpProvider(sessionsDir) {
408
+ const dir = getOmpSessionsDir(sessionsDir);
409
+ return {
410
+ name: 'omp',
411
+ async probeRoots() {
412
+ return [{ path: dir, label: 'sessions' }];
413
+ },
414
+ displayName: 'OMP',
415
+ modelDisplayName(model) {
416
+ return model;
417
+ },
418
+ toolDisplayName(rawTool) {
419
+ return ownValue(toolNameMap, rawTool) ?? rawTool;
420
+ },
421
+ async discoverSessions() {
422
+ return discoverSessionsInDir(dir, 'omp');
423
+ },
424
+ createSessionParser(source, seenKeys) {
425
+ return createParser(source, seenKeys);
426
+ },
427
+ };
428
+ }
429
+ export const omp = createOmpProvider();