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,569 @@
1
+ // @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
2
+ import { existsSync } from "fs";
3
+ import { readdir, stat } from "fs/promises";
4
+ import { basename, join } from "path";
5
+ import { homedir } from "os";
6
+ import { calculateCost, getShortModelName } from "../models.js";
7
+ import { isSqliteBusyError, openDatabase } from "../sqlite.js";
8
+ import { readSessionFile } from "../fs-utils.js";
9
+ import { isPositiveNumber, safeNumber } from "../parser.js";
10
+ function isTextContentPart(contentPart) {
11
+ return contentPart.type === "text";
12
+ }
13
+ const DEFAULT_DEVIN_CLI_DIR = join(homedir(), ".local", "share", "devin", "cli");
14
+ const DEFAULT_MODEL_NAME = "devin";
15
+ const DEVIN_PROVIDER_NAME = "devin";
16
+ const DEVIN_PROVIDER_DISPLAY_NAME = "Devin";
17
+ const DEVIN_TRANSCRIPTS_SUBDIR = "transcripts";
18
+ const DEVIN_SESSIONS_DB = "sessions.db";
19
+ const DEVIN_EFFORT_TIERS = new Set(["xhigh", "high", "medium", "low"]);
20
+ function parseTranscript(raw) {
21
+ try {
22
+ return JSON.parse(raw);
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ function parseNumericTimestamp(value) {
29
+ const millis = value < 10_000_000_000 ? value * 1000 : value;
30
+ return new Date(millis).toISOString();
31
+ }
32
+ function hasAnyTokenField(metrics) {
33
+ if (!metrics)
34
+ return false;
35
+ return [
36
+ metrics.prompt_tokens,
37
+ metrics.completion_tokens,
38
+ metrics.cached_tokens,
39
+ metrics.extra?.cache_creation_input_tokens,
40
+ ].some((value) => value != null);
41
+ }
42
+ function getMetricsFromStep(step) {
43
+ // Prefer step.metrics (standard ATIF v1.7) only when it actually carries
44
+ // token fields; a present-but-empty metrics object must not shadow the
45
+ // legacy metadata.metrics location.
46
+ if (hasAnyTokenField(step.metrics)) {
47
+ return step.metrics ?? null;
48
+ }
49
+ if (step.metadata) {
50
+ return getDevinMetricsFromMetadata(step.metadata);
51
+ }
52
+ return step.metrics ?? null;
53
+ }
54
+ function getDevinMetricsFromMetadata(metadata) {
55
+ const input = metadata.metrics?.input_tokens;
56
+ return {
57
+ // Devin's own metrics count input_tokens without the cache reads, unlike
58
+ // the OpenAI-style prompt_tokens getUsage carves them out of.
59
+ prompt_tokens: input == null ? input : input + safeNumber(metadata.metrics?.cache_read_tokens),
60
+ completion_tokens: metadata.metrics?.output_tokens,
61
+ cached_tokens: metadata.metrics?.cache_read_tokens,
62
+ extra: {
63
+ cache_creation_input_tokens: metadata.metrics?.cache_creation_tokens,
64
+ },
65
+ };
66
+ }
67
+ function getUsage(step) {
68
+ const metrics = getMetricsFromStep(step);
69
+ const hasAnyUsage = [
70
+ metrics?.prompt_tokens,
71
+ metrics?.completion_tokens,
72
+ metrics?.extra?.cache_creation_input_tokens,
73
+ metrics?.cached_tokens,
74
+ ].some((x) => isPositiveNumber(x));
75
+ if (!hasAnyUsage)
76
+ return null;
77
+ const cacheReadInputTokens = safeNumber(metrics?.cached_tokens);
78
+ return {
79
+ // Devin reports OpenAI-style prompt_tokens, with the cached tokens counted
80
+ // inside it; Anthropic semantics (what calculateCost expects) keep them
81
+ // apart, so the cached share is carved out instead of billed twice.
82
+ inputTokens: Math.max(0, safeNumber(metrics?.prompt_tokens) - cacheReadInputTokens),
83
+ outputTokens: safeNumber(metrics?.completion_tokens),
84
+ cacheCreationInputTokens: safeNumber(metrics?.extra?.cache_creation_input_tokens),
85
+ cacheReadInputTokens,
86
+ };
87
+ }
88
+ function getSessionId(source, transcript) {
89
+ const fromTranscript = transcript.session_id?.trim();
90
+ return fromTranscript || basename(source.path, ".json");
91
+ }
92
+ function projectNameFromPath(path) {
93
+ const normalized = path.trim().replace(/[/\\]+$/, "");
94
+ return normalized.split(/[/\\]/).filter(Boolean).pop() ?? path;
95
+ }
96
+ function getProjectName(source, session) {
97
+ if (session?.workingDirectory)
98
+ return projectNameFromPath(session.workingDirectory);
99
+ if (session?.title)
100
+ return session.title;
101
+ return source.project;
102
+ }
103
+ function getProjectPath(session) {
104
+ return session?.workingDirectory;
105
+ }
106
+ function getTimestamp(step, session) {
107
+ return [
108
+ step.metadata?.created_at,
109
+ session?.lastActivityAt,
110
+ session?.createdAt,
111
+ ]
112
+ .filter(Boolean)
113
+ .shift();
114
+ }
115
+ function firstPresentString(...values) {
116
+ for (const value of values) {
117
+ const trimmed = value?.trim();
118
+ if (trimmed)
119
+ return trimmed;
120
+ }
121
+ return undefined;
122
+ }
123
+ function getFriendlyGptName(model) {
124
+ const shortName = getShortModelName(model);
125
+ const match = model.match(/^gpt-(\d+(?:\.\d+)*)(?:-(.+))?$/);
126
+ if (!match)
127
+ return shortName;
128
+ const suffixParts = match[2]?.split("-").filter(Boolean) ?? [];
129
+ // A purely numeric suffix token means this is a dated snapshot id such as
130
+ // gpt-4-1106-preview, not a clean version+word id. Fabricating a friendly
131
+ // name here would mislabel the date as text (e.g. "GPT-4 1106 Preview"), so
132
+ // defer to getShortModelName, which passes unknown snapshots through raw.
133
+ if (suffixParts.some((part) => /^\d+$/.test(part)))
134
+ return shortName;
135
+ const suffix = suffixParts
136
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
137
+ .join(" ");
138
+ const reconstructed = `GPT-${match[1]}${suffix ? ` ${suffix}` : ""}`;
139
+ if (shortName !== model && (!suffix || shortName !== `GPT-${match[1]}`)) {
140
+ return shortName;
141
+ }
142
+ return reconstructed;
143
+ }
144
+ // Devin minor versions are always a single digit (gpt-5-3-codex,
145
+ // swe-1-7-lightning). Restrict the dash-to-dot rewrite to a single-digit minor
146
+ // at a token boundary so a dated snapshot like gpt-4-1106-preview is not
147
+ // misread as version 4.1106.
148
+ function normalizeDevinGptId(model) {
149
+ return model.replace(/^(gpt|swe)-(\d+)-(\d)(?=-|$)/, "$1-$2.$3");
150
+ }
151
+ function getDevinDisplayModelName(generationModel, modelName) {
152
+ if (!generationModel || /^MODEL_/.test(generationModel)) {
153
+ return getShortModelName(modelName);
154
+ }
155
+ if (generationModel.startsWith("gpt-")) {
156
+ const normalized = normalizeDevinGptId(generationModel);
157
+ const effortMatch = normalized.match(/-([^-]+)$/);
158
+ const effort = effortMatch && DEVIN_EFFORT_TIERS.has(effortMatch[1])
159
+ ? effortMatch[1]
160
+ : undefined;
161
+ const base = effort ? normalized.slice(0, -(effort.length + 1)) : normalized;
162
+ const friendlyBase = getFriendlyGptName(base);
163
+ return effort ? `${friendlyBase} (${effort})` : friendlyBase;
164
+ }
165
+ return getShortModelName(generationModel);
166
+ }
167
+ function getModels(agentModel, step, session) {
168
+ const generationModel = firstPresentString(step.metadata?.generation_model, step.extra?.generation_model);
169
+ const modelName = firstPresentString(step.model_name, agentModel, session?.model) ?? DEFAULT_MODEL_NAME;
170
+ const pricingModel = !generationModel || /^MODEL_/.test(generationModel)
171
+ ? modelName
172
+ : normalizeDevinGptId(generationModel);
173
+ return {
174
+ pricingModel,
175
+ displayModel: getDevinDisplayModelName(generationModel, modelName),
176
+ };
177
+ }
178
+ function getToolNames(step) {
179
+ return (step.tool_calls ?? []).map((call) => call.function_name);
180
+ }
181
+ function normalizeContentPartMessage(contentPart) {
182
+ if (isTextContentPart(contentPart)) {
183
+ return contentPart.text;
184
+ }
185
+ else {
186
+ return contentPart.source.path;
187
+ }
188
+ }
189
+ function normalizeStepMessage(message) {
190
+ if (Array.isArray(message)) {
191
+ return message.map((x) => normalizeContentPartMessage(x).trim()).join(" ");
192
+ }
193
+ return message.trim();
194
+ }
195
+ // Real transcripts mark the user's turn with source "user" and leave
196
+ // is_user_input unset; older ones do the opposite.
197
+ function isUserStep(step) {
198
+ return step.metadata?.is_user_input === true || step.source === "user";
199
+ }
200
+ function getFirstUserMessageBeforeStep(steps, index) {
201
+ for (let i = index - 1; i >= 0; i--) {
202
+ const step = steps[i];
203
+ if (!step || !isUserStep(step))
204
+ continue;
205
+ const message = step.message
206
+ ? normalizeStepMessage(step.message)
207
+ : undefined;
208
+ if (message)
209
+ return message;
210
+ }
211
+ return null;
212
+ }
213
+ // Devin only fills sessions.title once it has summarised the session, so an
214
+ // unsummarised session falls back to what the user actually typed first.
215
+ function loadFirstPrompts(db) {
216
+ const prompts = new Map();
217
+ try {
218
+ const rows = db.query(`SELECT session_id, content FROM prompt_history ORDER BY id`);
219
+ for (const row of rows) {
220
+ const content = row.content?.trim();
221
+ if (!row.session_id || !content || prompts.has(row.session_id))
222
+ continue;
223
+ prompts.set(row.session_id, content);
224
+ }
225
+ }
226
+ catch {
227
+ // Older Devin builds have no prompt_history table.
228
+ }
229
+ return prompts;
230
+ }
231
+ const SESSION_COLUMNS = "id, working_directory, model, title, created_at, last_activity_at, hidden";
232
+ function toSessionMetadata(row, firstPrompt) {
233
+ return {
234
+ id: row.id,
235
+ workingDirectory: row.working_directory,
236
+ model: row.model,
237
+ title: row.title?.trim() || firstPrompt,
238
+ createdAt: parseNumericTimestamp(row.created_at),
239
+ lastActivityAt: parseNumericTimestamp(row.last_activity_at),
240
+ hidden: !!row.hidden,
241
+ };
242
+ }
243
+ function loadSessionMetadata(dbPath) {
244
+ const sessions = new Map();
245
+ let db = null;
246
+ try {
247
+ db = openDatabase(dbPath);
248
+ const rows = db.query(`SELECT ${SESSION_COLUMNS} FROM sessions`);
249
+ const firstPrompts = loadFirstPrompts(db);
250
+ for (const row of rows) {
251
+ if (!row.id)
252
+ continue;
253
+ sessions.set(row.id, toSessionMetadata(row, firstPrompts.get(row.id)));
254
+ }
255
+ }
256
+ catch {
257
+ return sessions;
258
+ }
259
+ finally {
260
+ db?.close();
261
+ }
262
+ return sessions;
263
+ }
264
+ class DevinSessionParser {
265
+ source;
266
+ seenKeys;
267
+ sessionMetadata;
268
+ constructor(source, seenKeys, sessionMetadata) {
269
+ this.source = source;
270
+ this.seenKeys = seenKeys;
271
+ this.sessionMetadata = sessionMetadata;
272
+ }
273
+ async *parse() {
274
+ const raw = await readSessionFile(this.source.path);
275
+ if (!raw)
276
+ return;
277
+ const transcript = parseTranscript(raw);
278
+ if (!transcript?.steps)
279
+ return;
280
+ const sessionId = getSessionId(this.source, transcript);
281
+ const session = this.sessionMetadata.get(sessionId) ?? null;
282
+ if (session?.hidden)
283
+ return;
284
+ const project = getProjectName(this.source, session);
285
+ const projectPath = getProjectPath(session);
286
+ for (let index = 0; index < transcript.steps.length; index++) {
287
+ const step = transcript.steps[index];
288
+ if (isUserStep(step))
289
+ continue;
290
+ const usage = getUsage(step);
291
+ if (!usage)
292
+ continue;
293
+ const timestamp = getTimestamp(step, session) ?? "";
294
+ const deduplicationKey = `devin:${sessionId}:${step.step_id}`;
295
+ if (this.seenKeys.has(deduplicationKey))
296
+ continue;
297
+ this.seenKeys.add(deduplicationKey);
298
+ yield toParsedCall({
299
+ step,
300
+ usage,
301
+ agentModel: transcript.agent?.model_name,
302
+ session,
303
+ timestamp,
304
+ deduplicationKey,
305
+ userMessage: getFirstUserMessageBeforeStep(transcript.steps, index) ??
306
+ session?.title ??
307
+ "",
308
+ sessionId,
309
+ project,
310
+ projectPath,
311
+ });
312
+ }
313
+ }
314
+ }
315
+ function toParsedCall(call) {
316
+ const { step, usage, session } = call;
317
+ const { pricingModel, displayModel } = getModels(call.agentModel, step, session);
318
+ return {
319
+ provider: DEVIN_PROVIDER_NAME,
320
+ model: displayModel,
321
+ inputTokens: usage.inputTokens,
322
+ outputTokens: usage.outputTokens,
323
+ cacheCreationInputTokens: usage.cacheCreationInputTokens,
324
+ cacheReadInputTokens: usage.cacheReadInputTokens,
325
+ cachedInputTokens: usage.cacheReadInputTokens,
326
+ reasoningTokens: 0,
327
+ webSearchRequests: 0,
328
+ costUSD: calculateCost(pricingModel, usage.inputTokens, usage.outputTokens, usage.cacheCreationInputTokens, usage.cacheReadInputTokens, 0),
329
+ tools: getToolNames(step),
330
+ bashCommands: [],
331
+ timestamp: call.timestamp,
332
+ speed: "standard",
333
+ deduplicationKey: call.deduplicationKey,
334
+ userMessage: call.userMessage,
335
+ sessionId: call.sessionId,
336
+ project: call.project,
337
+ projectPath: call.projectPath,
338
+ };
339
+ }
340
+ // Keyset batches keep one batch of rows in memory, not a whole session, and
341
+ // the SQL pulls only the fields used so tool output never reaches JS.
342
+ const MESSAGE_BATCH_ROWS = 2000;
343
+ // Every sibling retry of a request is stored as its own node carrying the same
344
+ // request_id and metrics, so the request id is the dedup key. Branches off the
345
+ // main chain are real distinct requests and count too.
346
+ class DevinDbSessionParser {
347
+ source;
348
+ seenKeys;
349
+ constructor(source, seenKeys) {
350
+ this.source = source;
351
+ this.seenKeys = seenKeys;
352
+ }
353
+ async *parse() {
354
+ const idx = this.source.path.lastIndexOf(":");
355
+ const dbPath = this.source.path.slice(0, idx);
356
+ const sessionId = this.source.path.slice(idx + 1);
357
+ let db;
358
+ try {
359
+ db = openDatabase(dbPath);
360
+ }
361
+ catch (err) {
362
+ if (isSqliteBusyError(err))
363
+ throw err;
364
+ return;
365
+ }
366
+ const calls = [];
367
+ try {
368
+ const row = db.query(`SELECT ${SESSION_COLUMNS} FROM sessions WHERE id = ?`, [sessionId])[0];
369
+ if (!row || row.hidden)
370
+ return;
371
+ const firstPrompt = db.query(`SELECT content FROM prompt_history WHERE session_id = ? ORDER BY id LIMIT 1`, [sessionId])[0]?.content?.trim();
372
+ const session = toSessionMetadata(row, firstPrompt);
373
+ const project = getProjectName(this.source, session);
374
+ // Parents always precede children, so one forward pass hands each node
375
+ // the prompt of its nearest user ancestor.
376
+ const promptByNode = new Map();
377
+ let lastNodeId = -1;
378
+ for (;;) {
379
+ const rows = db.query(`SELECT node_id, parent_node_id,
380
+ json_extract(chat_message, '$.role') AS role,
381
+ CASE WHEN json_type(chat_message, '$.metadata') = 'object'
382
+ THEN json_object(
383
+ 'created_at', chat_message -> '$.metadata.created_at',
384
+ 'generation_model', chat_message -> '$.metadata.generation_model',
385
+ 'is_user_input', chat_message -> '$.metadata.is_user_input',
386
+ 'request_id', chat_message -> '$.metadata.request_id',
387
+ 'metrics', chat_message -> '$.metadata.metrics') END AS metadata,
388
+ (SELECT json_group_array(json_extract(value, '$.name'))
389
+ FROM json_each(chat_message, '$.tool_calls')) AS tool_names,
390
+ CASE WHEN json_extract(chat_message, '$.role') = 'user'
391
+ AND json_type(chat_message, '$.content') = 'text'
392
+ THEN json_extract(chat_message, '$.content') END AS content
393
+ FROM message_nodes
394
+ WHERE session_id = ? AND node_id > ?
395
+ ORDER BY node_id
396
+ LIMIT ?`, [sessionId, lastNodeId, MESSAGE_BATCH_ROWS]);
397
+ for (const node of rows) {
398
+ lastNodeId = Number(node.node_id);
399
+ const metadata = parseJson(node.metadata);
400
+ const inherited = node.parent_node_id == null
401
+ ? undefined
402
+ : promptByNode.get(Number(node.parent_node_id));
403
+ const ownPrompt = node.role === "user" &&
404
+ metadata?.is_user_input === true &&
405
+ typeof node.content === "string"
406
+ ? node.content.trim() || undefined
407
+ : undefined;
408
+ promptByNode.set(lastNodeId, ownPrompt ?? inherited);
409
+ if (node.role !== "assistant" || !metadata)
410
+ continue;
411
+ const step = {
412
+ step_id: lastNodeId,
413
+ source: "agent",
414
+ message: "",
415
+ metadata,
416
+ tool_calls: (parseJson(node.tool_names) ?? [])
417
+ .filter((name) => !!name)
418
+ .map((name) => ({ tool_call_id: "", function_name: name, arguments: null })),
419
+ };
420
+ const usage = getUsage(step);
421
+ if (!usage)
422
+ continue;
423
+ const deduplicationKey = `devin:${sessionId}:${metadata.request_id ?? `node-${lastNodeId}`}`;
424
+ if (this.seenKeys.has(deduplicationKey))
425
+ continue;
426
+ this.seenKeys.add(deduplicationKey);
427
+ calls.push(toParsedCall({
428
+ step,
429
+ usage,
430
+ agentModel: undefined,
431
+ session,
432
+ timestamp: getTimestamp(step, session) ?? "",
433
+ deduplicationKey,
434
+ userMessage: ownPrompt ?? inherited ?? session.title ?? "",
435
+ sessionId,
436
+ project,
437
+ projectPath: getProjectPath(session),
438
+ }));
439
+ }
440
+ if (rows.length < MESSAGE_BATCH_ROWS)
441
+ break;
442
+ }
443
+ }
444
+ finally {
445
+ db.close();
446
+ }
447
+ yield* calls;
448
+ }
449
+ }
450
+ function parseJson(raw) {
451
+ if (!raw)
452
+ return null;
453
+ try {
454
+ return JSON.parse(raw);
455
+ }
456
+ catch {
457
+ return null;
458
+ }
459
+ }
460
+ // null when the database is missing or predates message_nodes, so the
461
+ // caller falls back to transcripts. BUSY propagates so the refresh retries
462
+ // instead of reading a locked store as empty.
463
+ function discoverDbSessions(dbPath) {
464
+ if (!existsSync(dbPath))
465
+ return null;
466
+ let db;
467
+ try {
468
+ db = openDatabase(dbPath);
469
+ }
470
+ catch (err) {
471
+ if (isSqliteBusyError(err))
472
+ throw err;
473
+ return null;
474
+ }
475
+ try {
476
+ const rows = db.query(`SELECT id, working_directory, title FROM sessions
477
+ WHERE hidden = 0 AND id IN (SELECT DISTINCT session_id FROM message_nodes)
478
+ ORDER BY id`);
479
+ return rows.map((row) => ({
480
+ path: `${dbPath}:${row.id}`,
481
+ project: (row.working_directory && projectNameFromPath(row.working_directory)) ||
482
+ row.title?.trim() ||
483
+ DEVIN_PROVIDER_NAME,
484
+ provider: DEVIN_PROVIDER_NAME,
485
+ }));
486
+ }
487
+ catch (err) {
488
+ if (isSqliteBusyError(err))
489
+ throw err;
490
+ return null;
491
+ }
492
+ finally {
493
+ db.close();
494
+ }
495
+ }
496
+ function resolveDevinCliDir(override) {
497
+ return override && override.trim() ? override : DEFAULT_DEVIN_CLI_DIR;
498
+ }
499
+ function getDevinDiscoveryRoots(cliDir) {
500
+ return {
501
+ transcriptsDir: join(cliDir, DEVIN_TRANSCRIPTS_SUBDIR),
502
+ sessionsDbPath: join(cliDir, DEVIN_SESSIONS_DB),
503
+ };
504
+ }
505
+ export function createDevinProvider(cliDir) {
506
+ const resolvedCliDir = resolveDevinCliDir(cliDir);
507
+ const { transcriptsDir, sessionsDbPath } = getDevinDiscoveryRoots(resolvedCliDir);
508
+ let sessionMetadata = null;
509
+ const getSessionMetadata = () => {
510
+ if (!sessionMetadata)
511
+ sessionMetadata = loadSessionMetadata(sessionsDbPath);
512
+ return sessionMetadata;
513
+ };
514
+ return {
515
+ name: DEVIN_PROVIDER_NAME,
516
+ displayName: DEVIN_PROVIDER_DISPLAY_NAME,
517
+ modelDisplayName(model) {
518
+ return model;
519
+ },
520
+ toolDisplayName(rawTool) {
521
+ return rawTool;
522
+ },
523
+ async probeRoots() {
524
+ return [
525
+ { path: transcriptsDir, label: "transcripts" },
526
+ { path: sessionsDbPath, label: "sessions.db" },
527
+ ];
528
+ },
529
+ async discoverSessions() {
530
+ // Transcripts are export-only snapshots of what sessions.db holds, so
531
+ // they are read only when the database cannot be.
532
+ const dbSources = discoverDbSessions(sessionsDbPath);
533
+ if (dbSources)
534
+ return dbSources;
535
+ const entries = await readdir(transcriptsDir).catch(() => []);
536
+ const metadata = getSessionMetadata();
537
+ const sources = [];
538
+ for (const entry of entries) {
539
+ if (!entry.endsWith(".json"))
540
+ continue;
541
+ const filePath = join(transcriptsDir, entry);
542
+ const pathStats = await stat(filePath).catch(() => null);
543
+ if (!pathStats?.isFile())
544
+ continue;
545
+ const session = metadata.get(basename(filePath, ".json")) ?? null;
546
+ if (session?.hidden)
547
+ continue;
548
+ const tmpSource = {
549
+ path: filePath,
550
+ project: DEVIN_PROVIDER_NAME,
551
+ provider: DEVIN_PROVIDER_NAME,
552
+ };
553
+ const project = getProjectName(tmpSource, session);
554
+ sources.push({
555
+ path: filePath,
556
+ project,
557
+ provider: DEVIN_PROVIDER_NAME,
558
+ });
559
+ }
560
+ return sources;
561
+ },
562
+ createSessionParser(source, seenKeys) {
563
+ return source.path.endsWith(".json")
564
+ ? new DevinSessionParser(source, seenKeys, getSessionMetadata())
565
+ : new DevinDbSessionParser(source, seenKeys);
566
+ },
567
+ };
568
+ }
569
+ export const devin = createDevinProvider(DEFAULT_DEVIN_CLI_DIR);