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.
- package/README.md +11 -0
- package/dist/agentlimits.js +77 -0
- package/dist/agentusage.js +96 -0
- package/dist/appstate.js +63 -3
- package/dist/away.js +44 -5
- package/dist/blueprint.js +3 -7
- package/dist/board.js +1 -0
- package/dist/cli.js +263 -5
- package/dist/codexquota.js +106 -0
- package/dist/codexusage.js +10 -0
- package/dist/config.js +2 -0
- package/dist/context.js +30 -0
- package/dist/costs.js +1 -0
- package/dist/demon.js +20 -0
- package/dist/label.js +33 -0
- package/dist/menu.js +17 -0
- package/dist/nightcap.js +60 -0
- package/dist/nudge.js +47 -18
- package/dist/pacing.js +16 -1
- package/dist/questions.js +71 -0
- package/dist/recap.js +74 -0
- package/dist/receipt.js +48 -0
- package/dist/recipe.js +79 -0
- package/dist/stamps.js +14 -0
- package/dist/triggers.js +5 -0
- package/dist/usage.js +21 -1
- package/dist/vendor/codeburn/antigravity.js +309 -0
- package/dist/vendor/codeburn/codex.js +429 -0
- package/dist/vendor/codeburn/copilot.js +292 -0
- package/dist/vendor/codeburn/gemini.js +195 -0
- package/dist/vendor/codeburn/grokbot.js +182 -0
- package/dist/vendor/codeburn/kimi.js +178 -0
- package/dist/vendor/codeburn/shims/chalk.js +14 -0
- package/dist/vendor/codeburn/shims/strip-ansi.js +6 -0
- package/dist/vendor/codeburn/src/act/backup.js +83 -0
- package/dist/vendor/codeburn/src/act/model-defaults.js +151 -0
- package/dist/vendor/codeburn/src/act/types.js +37 -0
- package/dist/vendor/codeburn/src/bash-utils.js +204 -0
- package/dist/vendor/codeburn/src/behavioral-weight.js +47 -0
- package/dist/vendor/codeburn/src/cache-dir.js +26 -0
- package/dist/vendor/codeburn/src/cache-refresh-lock.js +543 -0
- package/dist/vendor/codeburn/src/cache-sweep.js +67 -0
- package/dist/vendor/codeburn/src/classifier.js +209 -0
- package/dist/vendor/codeburn/src/claude-identity.js +223 -0
- package/dist/vendor/codeburn/src/codex-cache.js +377 -0
- package/dist/vendor/codeburn/src/codex-fork-replay.js +232 -0
- package/dist/vendor/codeburn/src/codex-jsonl-fields.js +99 -0
- package/dist/vendor/codeburn/src/codex-session-index.js +113 -0
- package/dist/vendor/codeburn/src/codex-throughput.js +544 -0
- package/dist/vendor/codeburn/src/compare-stats.js +405 -0
- package/dist/vendor/codeburn/src/config.js +145 -0
- package/dist/vendor/codeburn/src/content-utils.js +56 -0
- package/dist/vendor/codeburn/src/context-tree-codex.js +329 -0
- package/dist/vendor/codeburn/src/context-tree.js +664 -0
- package/dist/vendor/codeburn/src/copilot-aiu.js +16 -0
- package/dist/vendor/codeburn/src/currency.js +189 -0
- package/dist/vendor/codeburn/src/cursor-cache.js +238 -0
- package/dist/vendor/codeburn/src/cursor-import.js +402 -0
- package/dist/vendor/codeburn/src/cursor-sync.js +256 -0
- package/dist/vendor/codeburn/src/daily-cache.js +2036 -0
- package/dist/vendor/codeburn/src/data/litellm-snapshot.json +1 -0
- package/dist/vendor/codeburn/src/data/pricing-fallback.json +1 -0
- package/dist/vendor/codeburn/src/day-aggregator.js +327 -0
- package/dist/vendor/codeburn/src/editor-data-dir.js +11 -0
- package/dist/vendor/codeburn/src/fetch-utils.js +18 -0
- package/dist/vendor/codeburn/src/format.js +118 -0
- package/dist/vendor/codeburn/src/fs-utils.js +270 -0
- package/dist/vendor/codeburn/src/git-origin.js +334 -0
- package/dist/vendor/codeburn/src/granular-history.js +328 -0
- package/dist/vendor/codeburn/src/hermes-session-ledger.js +512 -0
- package/dist/vendor/codeburn/src/launcher-homes.js +142 -0
- package/dist/vendor/codeburn/src/live-sessions.js +358 -0
- package/dist/vendor/codeburn/src/math-utils.js +8 -0
- package/dist/vendor/codeburn/src/menubar-json.js +294 -0
- package/dist/vendor/codeburn/src/models.js +1879 -0
- package/dist/vendor/codeburn/src/optimize-one-hour-cache.js +92 -0
- package/dist/vendor/codeburn/src/optimize.js +4110 -0
- package/dist/vendor/codeburn/src/parse-workers.js +219 -0
- package/dist/vendor/codeburn/src/parser.js +6953 -0
- package/dist/vendor/codeburn/src/path-privacy.js +26 -0
- package/dist/vendor/codeburn/src/plans.js +135 -0
- package/dist/vendor/codeburn/src/pr-signals.js +132 -0
- package/dist/vendor/codeburn/src/project-filter-warnings.js +33 -0
- package/dist/vendor/codeburn/src/provider-issues.js +30 -0
- package/dist/vendor/codeburn/src/providers/amp.js +286 -0
- package/dist/vendor/codeburn/src/providers/antigravity.js +1731 -0
- package/dist/vendor/codeburn/src/providers/claude.js +551 -0
- package/dist/vendor/codeburn/src/providers/cline-cli.js +401 -0
- package/dist/vendor/codeburn/src/providers/cline.js +63 -0
- package/dist/vendor/codeburn/src/providers/codebuff.js +336 -0
- package/dist/vendor/codeburn/src/providers/codewhale.js +442 -0
- package/dist/vendor/codeburn/src/providers/codex.js +1720 -0
- package/dist/vendor/codeburn/src/providers/command-code.js +196 -0
- package/dist/vendor/codeburn/src/providers/copilot.js +3278 -0
- package/dist/vendor/codeburn/src/providers/crush.js +226 -0
- package/dist/vendor/codeburn/src/providers/cursor-agent.js +837 -0
- package/dist/vendor/codeburn/src/providers/cursor.js +1163 -0
- package/dist/vendor/codeburn/src/providers/devin.js +569 -0
- package/dist/vendor/codeburn/src/providers/droid.js +324 -0
- package/dist/vendor/codeburn/src/providers/dsh.js +690 -0
- package/dist/vendor/codeburn/src/providers/forge.js +245 -0
- package/dist/vendor/codeburn/src/providers/gemini.js +230 -0
- package/dist/vendor/codeburn/src/providers/goose.js +252 -0
- package/dist/vendor/codeburn/src/providers/grok.js +581 -0
- package/dist/vendor/codeburn/src/providers/grokbot.js +290 -0
- package/dist/vendor/codeburn/src/providers/hermes.js +771 -0
- package/dist/vendor/codeburn/src/providers/ibm-bob.js +53 -0
- package/dist/vendor/codeburn/src/providers/index.js +360 -0
- package/dist/vendor/codeburn/src/providers/kilo-code.js +50 -0
- package/dist/vendor/codeburn/src/providers/kimi.js +363 -0
- package/dist/vendor/codeburn/src/providers/kimicode.js +402 -0
- package/dist/vendor/codeburn/src/providers/kiro.js +1174 -0
- package/dist/vendor/codeburn/src/providers/lingtai-tui.js +372 -0
- package/dist/vendor/codeburn/src/providers/mistral-vibe-unified.js +236 -0
- package/dist/vendor/codeburn/src/providers/mistral-vibe.js +405 -0
- package/dist/vendor/codeburn/src/providers/mux.js +242 -0
- package/dist/vendor/codeburn/src/providers/open-design.js +217 -0
- package/dist/vendor/codeburn/src/providers/openclaude.js +309 -0
- package/dist/vendor/codeburn/src/providers/openclaw.js +442 -0
- package/dist/vendor/codeburn/src/providers/opencode-file-parser.js +131 -0
- package/dist/vendor/codeburn/src/providers/opencode.js +91 -0
- package/dist/vendor/codeburn/src/providers/pi.js +429 -0
- package/dist/vendor/codeburn/src/providers/quickdesk.js +491 -0
- package/dist/vendor/codeburn/src/providers/qwen.js +193 -0
- package/dist/vendor/codeburn/src/providers/session-message.js +118 -0
- package/dist/vendor/codeburn/src/providers/sqlite-session-parser.js +457 -0
- package/dist/vendor/codeburn/src/providers/types.js +5 -0
- package/dist/vendor/codeburn/src/providers/vercel-gateway.js +135 -0
- package/dist/vendor/codeburn/src/providers/vscode-cline-parser.js +212 -0
- package/dist/vendor/codeburn/src/providers/warp.js +575 -0
- package/dist/vendor/codeburn/src/providers/zcode.js +249 -0
- package/dist/vendor/codeburn/src/providers/zed.js +187 -0
- package/dist/vendor/codeburn/src/providers/zerostack.js +139 -0
- package/dist/vendor/codeburn/src/quota/antigravity.js +310 -0
- package/dist/vendor/codeburn/src/quota/claude.js +244 -0
- package/dist/vendor/codeburn/src/quota/cursor.js +301 -0
- package/dist/vendor/codeburn/src/quota/security.js +299 -0
- package/dist/vendor/codeburn/src/quota/types.js +1 -0
- package/dist/vendor/codeburn/src/scan-facts.js +99 -0
- package/dist/vendor/codeburn/src/session-cache.js +3040 -0
- package/dist/vendor/codeburn/src/session-count-label.js +14 -0
- package/dist/vendor/codeburn/src/session-output.js +139 -0
- package/dist/vendor/codeburn/src/session-population.js +30 -0
- package/dist/vendor/codeburn/src/sessions-report.js +1342 -0
- package/dist/vendor/codeburn/src/sqlite.js +528 -0
- package/dist/vendor/codeburn/src/sync/otlp.js +420 -0
- package/dist/vendor/codeburn/src/telemetry-snapshot.js +244 -0
- package/dist/vendor/codeburn/src/token-estimate.js +5 -0
- package/dist/vendor/codeburn/src/types.js +16 -0
- package/dist/vendor/codeburn/src/work-units.js +126 -0
- package/dist/vendor/codeburn/src/workflow-insights.js +228 -0
- package/dist/vendor/codeburn/src/wsl.js +198 -0
- package/dist/vendor/codeburn/src/yield.js +666 -0
- package/package.json +1 -1
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { readdir, stat } from 'fs/promises';
|
|
3
|
+
import { basename, dirname, join } from 'path';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { readSessionFile, readSessionLines } from '../fs-utils.js';
|
|
6
|
+
import { calculateCost, ownValue } from '../models.js';
|
|
7
|
+
import { extractBashCommands } from '../bash-utils.js';
|
|
8
|
+
import { safeNumber } from '../parser.js';
|
|
9
|
+
import { wslHomes } from '../wsl.js';
|
|
10
|
+
import { readUnifiedVibeCalls } from './mistral-vibe-unified.js';
|
|
11
|
+
const METADATA_FILENAME = 'meta.json';
|
|
12
|
+
const MESSAGES_FILENAME = 'messages.jsonl';
|
|
13
|
+
const DEFAULT_MODEL = 'mistral-medium-3.5';
|
|
14
|
+
const modelDisplayNames = {
|
|
15
|
+
'mistral-medium-3.5': 'Mistral Medium 3.5',
|
|
16
|
+
'mistral-vibe-cli-latest': 'Mistral Vibe CLI',
|
|
17
|
+
'devstral-small': 'Devstral Small',
|
|
18
|
+
'devstral-small-latest': 'Devstral Small',
|
|
19
|
+
devstral: 'Devstral',
|
|
20
|
+
local: 'Local',
|
|
21
|
+
};
|
|
22
|
+
const toolNameMap = {
|
|
23
|
+
bash: 'Bash',
|
|
24
|
+
read_file: 'Read',
|
|
25
|
+
write_file: 'Write',
|
|
26
|
+
search_replace: 'Edit',
|
|
27
|
+
grep: 'Grep',
|
|
28
|
+
task: 'Agent',
|
|
29
|
+
todo: 'TodoWrite',
|
|
30
|
+
skill: 'Skill',
|
|
31
|
+
web_fetch: 'WebFetch',
|
|
32
|
+
web_search: 'WebSearch',
|
|
33
|
+
ask_user_question: 'AskUser',
|
|
34
|
+
exit_plan_mode: 'ExitPlanMode',
|
|
35
|
+
};
|
|
36
|
+
export function getMistralVibeSessionsDir(override) {
|
|
37
|
+
if (override)
|
|
38
|
+
return override;
|
|
39
|
+
const configuredHome = process.env['VIBE_HOME'];
|
|
40
|
+
const vibeHome = configuredHome ? expandHome(configuredHome) : join(homedir(), '.vibe');
|
|
41
|
+
return join(vibeHome, 'logs', 'session');
|
|
42
|
+
}
|
|
43
|
+
function expandHome(path) {
|
|
44
|
+
if (path === '~')
|
|
45
|
+
return homedir();
|
|
46
|
+
if (path.startsWith('~/'))
|
|
47
|
+
return join(homedir(), path.slice(2));
|
|
48
|
+
return path;
|
|
49
|
+
}
|
|
50
|
+
async function isFile(path) {
|
|
51
|
+
const s = await stat(path).catch(() => null);
|
|
52
|
+
return Boolean(s?.isFile());
|
|
53
|
+
}
|
|
54
|
+
async function isDirectory(path) {
|
|
55
|
+
const s = await stat(path).catch(() => null);
|
|
56
|
+
return Boolean(s?.isDirectory());
|
|
57
|
+
}
|
|
58
|
+
async function hasSessionFiles(dir) {
|
|
59
|
+
const [hasMetadata, hasMessages] = await Promise.all([
|
|
60
|
+
isFile(join(dir, METADATA_FILENAME)),
|
|
61
|
+
isFile(join(dir, MESSAGES_FILENAME)),
|
|
62
|
+
]);
|
|
63
|
+
return hasMetadata && hasMessages;
|
|
64
|
+
}
|
|
65
|
+
async function readJsonFile(path) {
|
|
66
|
+
const raw = await readSessionFile(path);
|
|
67
|
+
if (raw === null)
|
|
68
|
+
return null;
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(raw);
|
|
71
|
+
return typeof parsed === 'object' && parsed !== null ? parsed : null;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function discoverSessionDirs(root) {
|
|
78
|
+
const sessionDirs = [];
|
|
79
|
+
let entries;
|
|
80
|
+
try {
|
|
81
|
+
entries = (await readdir(root)).sort();
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return sessionDirs;
|
|
85
|
+
}
|
|
86
|
+
for (const entry of entries) {
|
|
87
|
+
const dir = join(root, entry);
|
|
88
|
+
if (!await isDirectory(dir))
|
|
89
|
+
continue;
|
|
90
|
+
if (await hasSessionFiles(dir)) {
|
|
91
|
+
sessionDirs.push(dir);
|
|
92
|
+
}
|
|
93
|
+
const agentsDir = join(dir, 'agents');
|
|
94
|
+
if (!await isDirectory(agentsDir))
|
|
95
|
+
continue;
|
|
96
|
+
let agentEntries;
|
|
97
|
+
try {
|
|
98
|
+
agentEntries = (await readdir(agentsDir)).sort();
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
for (const agentEntry of agentEntries) {
|
|
104
|
+
const agentDir = join(agentsDir, agentEntry);
|
|
105
|
+
if (await isDirectory(agentDir) && await hasSessionFiles(agentDir)) {
|
|
106
|
+
sessionDirs.push(agentDir);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return sessionDirs;
|
|
111
|
+
}
|
|
112
|
+
// Vibe resolves an unpinned session to config.toml's top-level active_model.
|
|
113
|
+
async function configuredModel(sessionsDir) {
|
|
114
|
+
const raw = await readSessionFile(join(sessionsDir, '..', '..', 'config.toml'));
|
|
115
|
+
const topLevel = raw?.split(/^\s*\[/m)[0] ?? '';
|
|
116
|
+
return topLevel.match(/^\s*active_model\s*=\s*["']([^"']+)["']/m)?.[1] ?? DEFAULT_MODEL;
|
|
117
|
+
}
|
|
118
|
+
function activeModelConfig(metadata) {
|
|
119
|
+
const activeModel = metadata.config?.active_model;
|
|
120
|
+
const models = metadata.config?.models;
|
|
121
|
+
if (!activeModel || !Array.isArray(models))
|
|
122
|
+
return null;
|
|
123
|
+
return models.find(m => m.alias === activeModel || m.name === activeModel) ?? null;
|
|
124
|
+
}
|
|
125
|
+
function resolveModel(metadata) {
|
|
126
|
+
const activeModel = metadata.config?.active_model;
|
|
127
|
+
if (activeModel)
|
|
128
|
+
return activeModel;
|
|
129
|
+
const configured = activeModelConfig(metadata);
|
|
130
|
+
return configured?.alias ?? configured?.name ?? DEFAULT_MODEL;
|
|
131
|
+
}
|
|
132
|
+
function calculateSessionCost(metadata, model, inputTokens, outputTokens) {
|
|
133
|
+
const stats = metadata.stats ?? {};
|
|
134
|
+
const sessionCost = safeNumber(stats.session_cost);
|
|
135
|
+
if (sessionCost > 0)
|
|
136
|
+
return sessionCost;
|
|
137
|
+
const configured = activeModelConfig(metadata);
|
|
138
|
+
const inputPrice = safeNumber(stats.input_price_per_million) || safeNumber(configured?.input_price);
|
|
139
|
+
const outputPrice = safeNumber(stats.output_price_per_million) || safeNumber(configured?.output_price);
|
|
140
|
+
if (inputPrice > 0 || outputPrice > 0) {
|
|
141
|
+
return (inputTokens / 1_000_000) * inputPrice + (outputTokens / 1_000_000) * outputPrice;
|
|
142
|
+
}
|
|
143
|
+
return calculateCost(model, inputTokens, outputTokens, 0, 0, 0);
|
|
144
|
+
}
|
|
145
|
+
function normalizeContent(content) {
|
|
146
|
+
if (typeof content === 'string')
|
|
147
|
+
return content;
|
|
148
|
+
if (Array.isArray(content)) {
|
|
149
|
+
return content
|
|
150
|
+
.map(part => {
|
|
151
|
+
if (typeof part === 'string')
|
|
152
|
+
return part;
|
|
153
|
+
if (part && typeof part === 'object' && 'text' in part && typeof part.text === 'string')
|
|
154
|
+
return part.text;
|
|
155
|
+
return '';
|
|
156
|
+
})
|
|
157
|
+
.filter(Boolean)
|
|
158
|
+
.join(' ');
|
|
159
|
+
}
|
|
160
|
+
return '';
|
|
161
|
+
}
|
|
162
|
+
function parseToolArguments(raw) {
|
|
163
|
+
if (!raw)
|
|
164
|
+
return {};
|
|
165
|
+
if (typeof raw === 'object')
|
|
166
|
+
return raw;
|
|
167
|
+
try {
|
|
168
|
+
const parsed = JSON.parse(raw);
|
|
169
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function extractMessageTools(message) {
|
|
176
|
+
const tools = [];
|
|
177
|
+
const bashCommands = [];
|
|
178
|
+
if (message.role !== 'assistant')
|
|
179
|
+
return { tools, bashCommands };
|
|
180
|
+
for (const toolCall of message.tool_calls ?? []) {
|
|
181
|
+
const rawName = toolCall.function?.name;
|
|
182
|
+
if (!rawName)
|
|
183
|
+
continue;
|
|
184
|
+
const mappedName = ownValue(toolNameMap, rawName) ?? rawName;
|
|
185
|
+
tools.push(mappedName);
|
|
186
|
+
if (mappedName !== 'Bash')
|
|
187
|
+
continue;
|
|
188
|
+
const args = parseToolArguments(toolCall.function?.arguments);
|
|
189
|
+
const command = args['command'];
|
|
190
|
+
if (typeof command === 'string') {
|
|
191
|
+
bashCommands.push(...extractBashCommands(command));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
tools: [...new Set(tools)],
|
|
196
|
+
bashCommands: [...new Set(bashCommands)],
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function extractTools(messages) {
|
|
200
|
+
const tools = [];
|
|
201
|
+
const bashCommands = [];
|
|
202
|
+
for (const message of messages) {
|
|
203
|
+
const extracted = extractMessageTools(message);
|
|
204
|
+
tools.push(...extracted.tools);
|
|
205
|
+
bashCommands.push(...extracted.bashCommands);
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
tools: [...new Set(tools)],
|
|
209
|
+
bashCommands: [...new Set(bashCommands)],
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
async function readMessages(path) {
|
|
213
|
+
const messages = [];
|
|
214
|
+
for await (const line of readSessionLines(path)) {
|
|
215
|
+
if (!line.trim())
|
|
216
|
+
continue;
|
|
217
|
+
try {
|
|
218
|
+
const parsed = JSON.parse(line);
|
|
219
|
+
if (parsed && typeof parsed === 'object')
|
|
220
|
+
messages.push(parsed);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return messages;
|
|
227
|
+
}
|
|
228
|
+
function firstUserMessage(messages, fallback) {
|
|
229
|
+
for (const message of messages) {
|
|
230
|
+
if (message.role !== 'user')
|
|
231
|
+
continue;
|
|
232
|
+
const text = normalizeContent(message.content).trim();
|
|
233
|
+
if (text)
|
|
234
|
+
return text.slice(0, 500);
|
|
235
|
+
}
|
|
236
|
+
return (fallback ?? '').slice(0, 500);
|
|
237
|
+
}
|
|
238
|
+
function allocateInteger(total, index, count) {
|
|
239
|
+
if (count <= 1)
|
|
240
|
+
return total;
|
|
241
|
+
const base = Math.floor(total / count);
|
|
242
|
+
const remainder = total % count;
|
|
243
|
+
return base + (index < remainder ? 1 : 0);
|
|
244
|
+
}
|
|
245
|
+
function allocateCost(total, count) {
|
|
246
|
+
return count <= 1 ? total : total / count;
|
|
247
|
+
}
|
|
248
|
+
function createParser(source, seenKeys) {
|
|
249
|
+
return {
|
|
250
|
+
async *parse() {
|
|
251
|
+
const metadataPath = join(source.path, METADATA_FILENAME);
|
|
252
|
+
const messagesPath = join(source.path, MESSAGES_FILENAME);
|
|
253
|
+
const metadata = await readJsonFile(metadataPath);
|
|
254
|
+
if (!metadata)
|
|
255
|
+
return;
|
|
256
|
+
const stats = metadata.stats ?? {};
|
|
257
|
+
const inputTokens = safeNumber(stats.session_prompt_tokens);
|
|
258
|
+
const outputTokens = safeNumber(stats.session_completion_tokens);
|
|
259
|
+
if (inputTokens === 0 && outputTokens === 0)
|
|
260
|
+
return;
|
|
261
|
+
const sessionId = metadata.session_id || basename(source.path);
|
|
262
|
+
const messages = await readMessages(messagesPath);
|
|
263
|
+
const model = resolveModel(metadata);
|
|
264
|
+
const costUSD = calculateSessionCost(metadata, model, inputTokens, outputTokens);
|
|
265
|
+
const assistantMessages = messages.filter(m => m.role === 'assistant');
|
|
266
|
+
const fallbackTimestamp = metadata.end_time ?? metadata.start_time ?? '';
|
|
267
|
+
if (assistantMessages.length === 0) {
|
|
268
|
+
const deduplicationKey = `mistral-vibe:${sessionId}`;
|
|
269
|
+
if (seenKeys.has(deduplicationKey))
|
|
270
|
+
return;
|
|
271
|
+
seenKeys.add(deduplicationKey);
|
|
272
|
+
const { tools, bashCommands } = extractTools(messages);
|
|
273
|
+
yield {
|
|
274
|
+
provider: 'mistral-vibe',
|
|
275
|
+
model,
|
|
276
|
+
inputTokens,
|
|
277
|
+
outputTokens,
|
|
278
|
+
cacheCreationInputTokens: 0,
|
|
279
|
+
cacheReadInputTokens: 0,
|
|
280
|
+
cachedInputTokens: 0,
|
|
281
|
+
reasoningTokens: 0,
|
|
282
|
+
webSearchRequests: 0,
|
|
283
|
+
costUSD,
|
|
284
|
+
tools,
|
|
285
|
+
bashCommands,
|
|
286
|
+
timestamp: fallbackTimestamp,
|
|
287
|
+
speed: 'standard',
|
|
288
|
+
deduplicationKey,
|
|
289
|
+
userMessage: firstUserMessage(messages, metadata.title),
|
|
290
|
+
sessionId,
|
|
291
|
+
};
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
let currentUserMessage = (metadata.title ?? '').slice(0, 500);
|
|
295
|
+
let turnOrdinal = 0;
|
|
296
|
+
let currentTurnId = `${sessionId}:prelude`;
|
|
297
|
+
let assistantOrdinal = 0;
|
|
298
|
+
for (const message of messages) {
|
|
299
|
+
if (message.role === 'user') {
|
|
300
|
+
const text = normalizeContent(message.content).trim();
|
|
301
|
+
if (text)
|
|
302
|
+
currentUserMessage = text.slice(0, 500);
|
|
303
|
+
currentTurnId = `${sessionId}:turn-${turnOrdinal++}`;
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (message.role !== 'assistant')
|
|
307
|
+
continue;
|
|
308
|
+
const messageKey = message.message_id || `idx-${assistantOrdinal}`;
|
|
309
|
+
const deduplicationKey = `mistral-vibe:${sessionId}:${messageKey}`;
|
|
310
|
+
const allocationIndex = assistantOrdinal;
|
|
311
|
+
assistantOrdinal++;
|
|
312
|
+
if (seenKeys.has(deduplicationKey))
|
|
313
|
+
continue;
|
|
314
|
+
seenKeys.add(deduplicationKey);
|
|
315
|
+
const { tools, bashCommands } = extractMessageTools(message);
|
|
316
|
+
yield {
|
|
317
|
+
provider: 'mistral-vibe',
|
|
318
|
+
model,
|
|
319
|
+
inputTokens: allocateInteger(inputTokens, allocationIndex, assistantMessages.length),
|
|
320
|
+
outputTokens: allocateInteger(outputTokens, allocationIndex, assistantMessages.length),
|
|
321
|
+
cacheCreationInputTokens: 0,
|
|
322
|
+
cacheReadInputTokens: 0,
|
|
323
|
+
cachedInputTokens: 0,
|
|
324
|
+
reasoningTokens: 0,
|
|
325
|
+
webSearchRequests: 0,
|
|
326
|
+
costUSD: allocateCost(costUSD, assistantMessages.length),
|
|
327
|
+
tools,
|
|
328
|
+
bashCommands,
|
|
329
|
+
timestamp: message.timestamp ?? fallbackTimestamp,
|
|
330
|
+
speed: 'standard',
|
|
331
|
+
deduplicationKey,
|
|
332
|
+
turnId: currentTurnId,
|
|
333
|
+
userMessage: currentUserMessage,
|
|
334
|
+
sessionId,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
export function createMistralVibeProvider(sessionsDir) {
|
|
341
|
+
const dir = getMistralVibeSessionsDir(sessionsDir);
|
|
342
|
+
// Extra WSL homes' ~/.vibe/logs/session; empty off-win32 and when a
|
|
343
|
+
// caller passes an explicit sessionsDir. Resolved lazily: probing spawns wsl.exe.
|
|
344
|
+
const wslDirs = () => sessionsDir ? [] : wslHomes().map(home => join(home, '.vibe', 'logs', 'session'));
|
|
345
|
+
return {
|
|
346
|
+
name: 'mistral-vibe',
|
|
347
|
+
displayName: 'Mistral Vibe',
|
|
348
|
+
modelDisplayName(model) {
|
|
349
|
+
return ownValue(modelDisplayNames, model) ?? model;
|
|
350
|
+
},
|
|
351
|
+
toolDisplayName(rawTool) {
|
|
352
|
+
return ownValue(toolNameMap, rawTool) ?? rawTool;
|
|
353
|
+
},
|
|
354
|
+
async probeRoots() {
|
|
355
|
+
return [dir, ...wslDirs()].map(path => ({ path, label: 'sessions' }));
|
|
356
|
+
},
|
|
357
|
+
async discoverSessions() {
|
|
358
|
+
const sources = [];
|
|
359
|
+
for (const root of [dir, ...wslDirs()])
|
|
360
|
+
sources.push(...await discoverRoot(root));
|
|
361
|
+
return sources;
|
|
362
|
+
},
|
|
363
|
+
createSessionParser(source, seenKeys) {
|
|
364
|
+
if (basename(source.path) === 'CURRENT') {
|
|
365
|
+
return { async *parse() {
|
|
366
|
+
const defaultModel = await configuredModel(dirname(dirname(dirname(source.path))));
|
|
367
|
+
for (const call of await readUnifiedVibeCalls(source.path, name => ownValue(toolNameMap, name) ?? name, defaultModel)) {
|
|
368
|
+
if (seenKeys.has(call.deduplicationKey))
|
|
369
|
+
continue;
|
|
370
|
+
seenKeys.add(call.deduplicationKey);
|
|
371
|
+
yield call;
|
|
372
|
+
}
|
|
373
|
+
} };
|
|
374
|
+
}
|
|
375
|
+
return createParser(source, seenKeys);
|
|
376
|
+
},
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
async function discoverRoot(dir) {
|
|
380
|
+
const dirs = await discoverSessionDirs(dir);
|
|
381
|
+
const sources = [];
|
|
382
|
+
for (const sessionDir of dirs) {
|
|
383
|
+
const metadata = await readJsonFile(join(sessionDir, METADATA_FILENAME));
|
|
384
|
+
if (!metadata)
|
|
385
|
+
continue;
|
|
386
|
+
const cwd = metadata.environment?.working_directory;
|
|
387
|
+
sources.push({
|
|
388
|
+
path: sessionDir,
|
|
389
|
+
project: cwd ? basename(cwd) : basename(sessionDir),
|
|
390
|
+
provider: 'mistral-vibe',
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
const unifiedDir = join(dir, 'unified');
|
|
394
|
+
for (const entry of (await readdir(unifiedDir).catch(() => [])).sort()) {
|
|
395
|
+
const sessionDir = join(unifiedDir, entry);
|
|
396
|
+
const currentPath = join(sessionDir, 'CURRENT');
|
|
397
|
+
if (!await isFile(currentPath))
|
|
398
|
+
continue;
|
|
399
|
+
const metadata = await readJsonFile(join(sessionDir, METADATA_FILENAME));
|
|
400
|
+
const cwd = metadata?.environment?.working_directory;
|
|
401
|
+
sources.push({ path: currentPath, project: cwd ? basename(cwd) : entry, provider: 'mistral-vibe' });
|
|
402
|
+
}
|
|
403
|
+
return sources;
|
|
404
|
+
}
|
|
405
|
+
export const mistralVibe = createMistralVibeProvider();
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { readdir, readFile, stat } from 'fs/promises';
|
|
3
|
+
import { basename, dirname, join, resolve } from 'path';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { readSessionLines } from '../fs-utils.js';
|
|
6
|
+
import { calculateCost, getShortModelName, ownValue } from '../models.js';
|
|
7
|
+
import { extractBashCommands } from '../bash-utils.js';
|
|
8
|
+
import { safeNumber } from '../parser.js';
|
|
9
|
+
const toolNameMap = {
|
|
10
|
+
bash: 'Bash',
|
|
11
|
+
file_read: 'Read',
|
|
12
|
+
file_edit_replace_string: 'Edit',
|
|
13
|
+
file_edit_replace_lines: 'Edit',
|
|
14
|
+
file_edit_insert: 'Edit',
|
|
15
|
+
file_edit_operation: 'Edit',
|
|
16
|
+
web_fetch: 'WebFetch',
|
|
17
|
+
web_search: 'WebSearch',
|
|
18
|
+
task: 'Agent',
|
|
19
|
+
todo: 'TodoWrite',
|
|
20
|
+
};
|
|
21
|
+
function expandHome(p) {
|
|
22
|
+
if (p === '~')
|
|
23
|
+
return homedir();
|
|
24
|
+
if (p.startsWith('~/') || p.startsWith('~\\'))
|
|
25
|
+
return join(homedir(), p.slice(2));
|
|
26
|
+
return p;
|
|
27
|
+
}
|
|
28
|
+
function getMuxRoot(override) {
|
|
29
|
+
if (override)
|
|
30
|
+
return resolve(expandHome(override));
|
|
31
|
+
const codeburnOverride = process.env['CODEBURN_MUX_DIR'];
|
|
32
|
+
if (codeburnOverride)
|
|
33
|
+
return resolve(expandHome(codeburnOverride));
|
|
34
|
+
const muxRoot = process.env['MUX_ROOT'];
|
|
35
|
+
if (muxRoot)
|
|
36
|
+
return resolve(expandHome(muxRoot));
|
|
37
|
+
return join(homedir(), '.mux');
|
|
38
|
+
}
|
|
39
|
+
// Splits on the first colon only, leaving any colon inside the id intact.
|
|
40
|
+
function stripProvider(model) {
|
|
41
|
+
const i = model.indexOf(':');
|
|
42
|
+
return i >= 0 ? model.slice(i + 1) : model;
|
|
43
|
+
}
|
|
44
|
+
function asRecord(v) {
|
|
45
|
+
return v !== null && typeof v === 'object' ? v : undefined;
|
|
46
|
+
}
|
|
47
|
+
// Guard against non-finite / out-of-range ms, which make toISOString() throw.
|
|
48
|
+
function toIsoTimestamp(ts, createdAt) {
|
|
49
|
+
if (typeof ts === 'number' && Number.isFinite(ts)) {
|
|
50
|
+
const d = new Date(ts);
|
|
51
|
+
if (!Number.isNaN(d.getTime()))
|
|
52
|
+
return d.toISOString();
|
|
53
|
+
}
|
|
54
|
+
return typeof createdAt === 'string' ? createdAt : '';
|
|
55
|
+
}
|
|
56
|
+
// config.json shape: { projects: [[projectPath, { workspaces: [{ id }] }], ...] }
|
|
57
|
+
async function loadProjectMap(root) {
|
|
58
|
+
const map = new Map();
|
|
59
|
+
let data;
|
|
60
|
+
try {
|
|
61
|
+
data = JSON.parse(await readFile(join(root, 'config.json'), 'utf-8'));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return map;
|
|
65
|
+
}
|
|
66
|
+
const projects = asRecord(data)?.['projects'];
|
|
67
|
+
if (!Array.isArray(projects))
|
|
68
|
+
return map;
|
|
69
|
+
for (const pair of projects) {
|
|
70
|
+
if (!Array.isArray(pair) || pair.length < 2)
|
|
71
|
+
continue;
|
|
72
|
+
const projectPath = pair[0];
|
|
73
|
+
if (typeof projectPath !== 'string')
|
|
74
|
+
continue;
|
|
75
|
+
const label = basename(projectPath) || projectPath;
|
|
76
|
+
const workspaces = asRecord(pair[1])?.['workspaces'];
|
|
77
|
+
if (!Array.isArray(workspaces))
|
|
78
|
+
continue;
|
|
79
|
+
for (const ws of workspaces) {
|
|
80
|
+
const id = asRecord(ws)?.['id'];
|
|
81
|
+
if (typeof id === 'string' && id)
|
|
82
|
+
map.set(id, label);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return map;
|
|
86
|
+
}
|
|
87
|
+
async function pushChatSource(sources, chatPath, project) {
|
|
88
|
+
const s = await stat(chatPath).catch(() => null);
|
|
89
|
+
if (s?.isFile())
|
|
90
|
+
sources.push({ path: chatPath, project, provider: 'mux' });
|
|
91
|
+
}
|
|
92
|
+
async function discoverSessions(root) {
|
|
93
|
+
const sessionsDir = join(root, 'sessions');
|
|
94
|
+
let workspaceIds;
|
|
95
|
+
try {
|
|
96
|
+
workspaceIds = await readdir(sessionsDir);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
const projectMap = await loadProjectMap(root);
|
|
102
|
+
const sources = [];
|
|
103
|
+
for (const workspaceId of workspaceIds) {
|
|
104
|
+
const workspaceDir = join(sessionsDir, workspaceId);
|
|
105
|
+
const project = projectMap.get(workspaceId) ?? workspaceId;
|
|
106
|
+
// The workspace's own turns.
|
|
107
|
+
await pushChatSource(sources, join(workspaceDir, 'chat.jsonl'), project);
|
|
108
|
+
// Sub-agent turns. Each spawned sub-agent is a separate LLM-client session
|
|
109
|
+
// recorded at subagent-transcripts/<childTaskId>/chat.jsonl — mux does NOT
|
|
110
|
+
// mirror these into a top-level sessions/<id> dir, so they are only
|
|
111
|
+
// reachable here. They carry real token usage (often the bulk of a
|
|
112
|
+
// session's spend) and are attributed to the parent workspace's project.
|
|
113
|
+
// Dedup stays correct: the parser keys off the child-task dir name, which
|
|
114
|
+
// is distinct from every workspace id, so each call is still counted once.
|
|
115
|
+
const subagentDir = join(workspaceDir, 'subagent-transcripts');
|
|
116
|
+
let childTaskIds;
|
|
117
|
+
try {
|
|
118
|
+
childTaskIds = await readdir(subagentDir);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
for (const childTaskId of childTaskIds) {
|
|
124
|
+
await pushChatSource(sources, join(subagentDir, childTaskId, 'chat.jsonl'), project);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return sources;
|
|
128
|
+
}
|
|
129
|
+
function createParser(source, seenKeys) {
|
|
130
|
+
return {
|
|
131
|
+
async *parse() {
|
|
132
|
+
const workspaceId = basename(dirname(source.path));
|
|
133
|
+
let pendingUserMessage = '';
|
|
134
|
+
let lineIdx = 0;
|
|
135
|
+
for await (const line of readSessionLines(source.path)) {
|
|
136
|
+
lineIdx++;
|
|
137
|
+
let msg;
|
|
138
|
+
try {
|
|
139
|
+
msg = JSON.parse(line);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (!msg || typeof msg !== 'object')
|
|
145
|
+
continue;
|
|
146
|
+
if (msg.role === 'user') {
|
|
147
|
+
const texts = (Array.isArray(msg.parts) ? msg.parts : [])
|
|
148
|
+
.filter(p => p?.type === 'text' && typeof p.text === 'string')
|
|
149
|
+
.map(p => p.text)
|
|
150
|
+
.filter(Boolean);
|
|
151
|
+
if (texts.length > 0)
|
|
152
|
+
pendingUserMessage = texts.join(' ').slice(0, 500);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (msg.role !== 'assistant')
|
|
156
|
+
continue;
|
|
157
|
+
const meta = msg.metadata;
|
|
158
|
+
const usage = asRecord(meta?.usage);
|
|
159
|
+
if (!meta || !usage)
|
|
160
|
+
continue;
|
|
161
|
+
const pm = meta.providerMetadata ?? {};
|
|
162
|
+
const anthropic = asRecord(pm['anthropic']);
|
|
163
|
+
// mux reports inputTokens inclusive of cache read+creation and
|
|
164
|
+
// outputTokens inclusive of reasoning; decompose to codeburn's
|
|
165
|
+
// cache/reasoning-exclusive convention. Cache creation is Anthropic-only.
|
|
166
|
+
// The AI SDK v6 normalizes reasoning into usage.reasoningTokens across
|
|
167
|
+
// every provider family, so that field is the single source of truth.
|
|
168
|
+
const cacheRead = safeNumber(usage['cachedInputTokens']);
|
|
169
|
+
const cacheCreate = safeNumber(anthropic?.['cacheCreationInputTokens']);
|
|
170
|
+
const reasoning = safeNumber(usage['reasoningTokens']);
|
|
171
|
+
const inputTokens = Math.max(0, safeNumber(usage['inputTokens']) - cacheRead - cacheCreate);
|
|
172
|
+
const outputTokens = Math.max(0, safeNumber(usage['outputTokens']) - reasoning);
|
|
173
|
+
if (inputTokens === 0 && outputTokens === 0 && cacheRead === 0 && cacheCreate === 0 && reasoning === 0) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
// Strip the "provider:" prefix — codeburn's getCanonicalName only strips
|
|
177
|
+
// slash prefixes, so a colon-prefixed model would price at $0.
|
|
178
|
+
const rawModel = typeof meta.model === 'string' && meta.model ? meta.model : 'unknown';
|
|
179
|
+
const model = stripProvider(rawModel);
|
|
180
|
+
const id = typeof msg.id === 'string' && msg.id ? msg.id : `L${lineIdx}`;
|
|
181
|
+
const dedupKey = `mux:${workspaceId}:${id}`;
|
|
182
|
+
if (seenKeys.has(dedupKey))
|
|
183
|
+
continue;
|
|
184
|
+
seenKeys.add(dedupKey);
|
|
185
|
+
const toolParts = (Array.isArray(msg.parts) ? msg.parts : []).filter(p => p?.type === 'dynamic-tool' && typeof p.toolName === 'string');
|
|
186
|
+
const tools = toolParts.map(p => ownValue(toolNameMap, p.toolName) ?? p.toolName);
|
|
187
|
+
const bashCommands = toolParts
|
|
188
|
+
.filter(p => p.toolName === 'bash')
|
|
189
|
+
.flatMap(p => {
|
|
190
|
+
const input = asRecord(p.input);
|
|
191
|
+
const script = input?.['script'] ?? input?.['command'];
|
|
192
|
+
return typeof script === 'string' ? extractBashCommands(script) : [];
|
|
193
|
+
});
|
|
194
|
+
const costUSD = calculateCost(model, inputTokens, outputTokens + reasoning, cacheCreate, cacheRead, 0);
|
|
195
|
+
const timestamp = toIsoTimestamp(meta.timestamp, msg.createdAt);
|
|
196
|
+
yield {
|
|
197
|
+
provider: 'mux',
|
|
198
|
+
model,
|
|
199
|
+
inputTokens,
|
|
200
|
+
outputTokens,
|
|
201
|
+
cacheCreationInputTokens: cacheCreate,
|
|
202
|
+
cacheReadInputTokens: cacheRead,
|
|
203
|
+
cachedInputTokens: cacheRead,
|
|
204
|
+
reasoningTokens: reasoning,
|
|
205
|
+
webSearchRequests: 0,
|
|
206
|
+
costUSD,
|
|
207
|
+
tools,
|
|
208
|
+
bashCommands,
|
|
209
|
+
timestamp,
|
|
210
|
+
speed: 'standard',
|
|
211
|
+
deduplicationKey: dedupKey,
|
|
212
|
+
userMessage: pendingUserMessage,
|
|
213
|
+
sessionId: workspaceId,
|
|
214
|
+
};
|
|
215
|
+
pendingUserMessage = '';
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
export function createMuxProvider(muxRoot) {
|
|
221
|
+
const root = getMuxRoot(muxRoot);
|
|
222
|
+
return {
|
|
223
|
+
name: 'mux',
|
|
224
|
+
displayName: 'Mux',
|
|
225
|
+
modelDisplayName(model) {
|
|
226
|
+
return getShortModelName(stripProvider(model));
|
|
227
|
+
},
|
|
228
|
+
toolDisplayName(rawTool) {
|
|
229
|
+
return ownValue(toolNameMap, rawTool) ?? rawTool;
|
|
230
|
+
},
|
|
231
|
+
async probeRoots() {
|
|
232
|
+
return [{ path: root, label: 'root' }];
|
|
233
|
+
},
|
|
234
|
+
async discoverSessions() {
|
|
235
|
+
return discoverSessions(root);
|
|
236
|
+
},
|
|
237
|
+
createSessionParser(source, seenKeys) {
|
|
238
|
+
return createParser(source, seenKeys);
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
export const mux = createMuxProvider();
|