chompyy 0.5.0 → 0.7.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 +14 -1
- package/dist/advice.js +98 -1
- package/dist/agentlimits.js +77 -0
- package/dist/agentusage.js +96 -0
- package/dist/approvals.js +129 -0
- package/dist/appstate.js +73 -3
- package/dist/away.js +48 -5
- package/dist/blueprint.js +3 -7
- package/dist/board.js +1 -0
- package/dist/cli.js +343 -18
- 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 +41 -2
- package/dist/demon.js +20 -0
- package/dist/detect.js +38 -6
- package/dist/didwork.js +26 -0
- package/dist/label.js +33 -0
- package/dist/menu.js +17 -0
- package/dist/nightcap.js +72 -0
- package/dist/nudge.js +70 -24
- package/dist/pacing.js +16 -1
- package/dist/punchcard.js +39 -0
- 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/savings.js +111 -0
- package/dist/stamps.js +14 -0
- package/dist/suggest.js +15 -5
- 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 +6955 -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/dist/wastechecks.js +233 -0
- package/package.json +1 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { billableOutputTokens, calculateCost } from '../models.js';
|
|
5
|
+
import { isSqliteAvailable, getSqliteLoadError, isSqliteBusyError, openDatabase } from '../sqlite.js';
|
|
6
|
+
// Provider-neutral explicit-reference capture, mirrored from parser.ts (a
|
|
7
|
+
// provider cannot import the parser without a cycle). Full URLs only: a bare
|
|
8
|
+
// "#123" is repository-ambiguous and must never silently move spend between
|
|
9
|
+
// repositories.
|
|
10
|
+
const PR_URL_IN_TEXT_RE = /https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/pull\/\d+/g;
|
|
11
|
+
function extractGithubPullUrls(text) {
|
|
12
|
+
return [...new Set(text.match(PR_URL_IN_TEXT_RE) ?? [])];
|
|
13
|
+
}
|
|
14
|
+
/// Per-turn user prompt text plus the session-wide set of GitHub PR URLs the
|
|
15
|
+
/// user referenced. The turn text feeds the parser layer's per-turn prRefs
|
|
16
|
+
/// extraction; the URL set seeds the cached file's session-level prLinks, the
|
|
17
|
+
/// gate every PR-attributed session must pass. Both degrade to empty on a DB
|
|
18
|
+
/// without `message`/`part` tables (older schema, or the test fixture), which
|
|
19
|
+
/// keeps usage rows exactly as they were before.
|
|
20
|
+
function loadPromptReferences(db, sessionId) {
|
|
21
|
+
const turnTextByTurnId = new Map();
|
|
22
|
+
const prUrls = new Set();
|
|
23
|
+
try {
|
|
24
|
+
const messages = db.query(`SELECT id, data FROM message
|
|
25
|
+
WHERE session_id = ? AND json_extract(data, '$.role') = 'user'
|
|
26
|
+
ORDER BY time_created ASC, sequence ASC, id ASC`, [sessionId]);
|
|
27
|
+
if (messages.length === 0)
|
|
28
|
+
return { turnTextByTurnId, prLinks: [] };
|
|
29
|
+
// Prompt text lives in `metadata.inputIntent.text` when the CLI recorded
|
|
30
|
+
// it, otherwise in the message's `text` parts (queued/injected inputs).
|
|
31
|
+
const partTextByMessage = new Map();
|
|
32
|
+
for (const part of db.query(`SELECT p.message_id as message_id, json_extract(p.data, '$.text') as text
|
|
33
|
+
FROM part p
|
|
34
|
+
WHERE p.session_id = ? AND json_extract(p.data, '$.type') = 'text'
|
|
35
|
+
AND p.message_id IN (SELECT id FROM message WHERE session_id = ? AND json_extract(data, '$.role') = 'user')
|
|
36
|
+
ORDER BY p.message_id, p.sequence ASC`, [sessionId, sessionId])) {
|
|
37
|
+
if (!part.text)
|
|
38
|
+
continue;
|
|
39
|
+
const existing = partTextByMessage.get(part.message_id);
|
|
40
|
+
partTextByMessage.set(part.message_id, existing ? `${existing}\n${part.text}` : part.text);
|
|
41
|
+
}
|
|
42
|
+
for (const message of messages) {
|
|
43
|
+
let parsed;
|
|
44
|
+
try {
|
|
45
|
+
parsed = JSON.parse(message.data);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const inputIntent = parsed.metadata?.inputIntent?.text;
|
|
51
|
+
const text = (typeof inputIntent === 'string' && inputIntent.trim()
|
|
52
|
+
? inputIntent
|
|
53
|
+
: partTextByMessage.get(message.id)) ?? '';
|
|
54
|
+
if (!text.trim())
|
|
55
|
+
continue;
|
|
56
|
+
for (const url of extractGithubPullUrls(text))
|
|
57
|
+
prUrls.add(url);
|
|
58
|
+
const turnId = parsed.anchor?.turnId;
|
|
59
|
+
if (!turnId)
|
|
60
|
+
continue;
|
|
61
|
+
const existing = turnTextByTurnId.get(turnId);
|
|
62
|
+
turnTextByTurnId.set(turnId, existing ? `${existing}\n${text}` : text);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (isSqliteBusyError(err))
|
|
67
|
+
throw err;
|
|
68
|
+
// message/part are an optional read; usage rows still count without them.
|
|
69
|
+
}
|
|
70
|
+
return { turnTextByTurnId, prLinks: [...prUrls].sort() };
|
|
71
|
+
}
|
|
72
|
+
function getDbPath(override) {
|
|
73
|
+
return override ?? join(homedir(), '.zcode', 'cli', 'db', 'db.sqlite');
|
|
74
|
+
}
|
|
75
|
+
function sanitizeProject(path) {
|
|
76
|
+
return path.replace(/^\//, '').replace(/\//g, '-');
|
|
77
|
+
}
|
|
78
|
+
function epochMsToIso(ms) {
|
|
79
|
+
if (ms === null || !Number.isFinite(ms) || ms <= 0)
|
|
80
|
+
return new Date(0).toISOString();
|
|
81
|
+
return new Date(ms).toISOString();
|
|
82
|
+
}
|
|
83
|
+
function validateSchema(db) {
|
|
84
|
+
try {
|
|
85
|
+
db.query('SELECT COUNT(*) as cnt FROM model_usage LIMIT 1');
|
|
86
|
+
db.query('SELECT COUNT(*) as cnt FROM session LIMIT 1');
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function discover(dbPath) {
|
|
94
|
+
let db;
|
|
95
|
+
try {
|
|
96
|
+
db = openDatabase(dbPath);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
if (!validateSchema(db))
|
|
103
|
+
return [];
|
|
104
|
+
const rows = db.query(`SELECT DISTINCT s.id as id, s.directory as directory
|
|
105
|
+
FROM session s
|
|
106
|
+
JOIN model_usage m ON m.session_id = s.id
|
|
107
|
+
WHERE m.input_tokens > 0 OR m.output_tokens > 0 OR m.reasoning_tokens > 0
|
|
108
|
+
OR m.cache_read_input_tokens > 0 OR m.cache_creation_input_tokens > 0`);
|
|
109
|
+
return rows.map(row => ({
|
|
110
|
+
path: `${dbPath}:${row.id}`,
|
|
111
|
+
project: sanitizeProject(row.directory),
|
|
112
|
+
provider: 'zcode',
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return [];
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
db.close();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function createParser(source, seenKeys) {
|
|
123
|
+
return {
|
|
124
|
+
async *parse() {
|
|
125
|
+
if (!isSqliteAvailable()) {
|
|
126
|
+
process.stderr.write(getSqliteLoadError() + '\n');
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
// Source paths are `<dbPath>:<sessionId>`. Split from the right so a colon
|
|
130
|
+
// in the path (Windows drive letter) doesn't corrupt the session id.
|
|
131
|
+
const segments = source.path.split(':');
|
|
132
|
+
const sessionId = segments[segments.length - 1];
|
|
133
|
+
const dbPath = segments.slice(0, -1).join(':');
|
|
134
|
+
let db;
|
|
135
|
+
try {
|
|
136
|
+
db = openDatabase(dbPath);
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
process.stderr.write(`codeburn: cannot open ZCode database: ${err instanceof Error ? err.message : err}\n`);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
if (!validateSchema(db))
|
|
144
|
+
return;
|
|
145
|
+
// model_usage rows don't link to individual tool calls, only to a turn,
|
|
146
|
+
// so collect each turn's tools and attach them to one request per turn
|
|
147
|
+
// (below) to avoid double-counting across a turn's multiple requests.
|
|
148
|
+
const toolRows = db.query(`SELECT turn_id, tool_name FROM tool_usage
|
|
149
|
+
WHERE session_id = ? AND turn_id IS NOT NULL
|
|
150
|
+
ORDER BY started_at ASC`, [sessionId]);
|
|
151
|
+
const toolsByTurn = new Map();
|
|
152
|
+
for (const tool of toolRows) {
|
|
153
|
+
if (!tool.turn_id)
|
|
154
|
+
continue;
|
|
155
|
+
const list = toolsByTurn.get(tool.turn_id) ?? [];
|
|
156
|
+
list.push(tool.tool_name);
|
|
157
|
+
toolsByTurn.set(tool.turn_id, list);
|
|
158
|
+
}
|
|
159
|
+
const rows = db.query(`SELECT id, turn_id, model_id, input_tokens, output_tokens, reasoning_tokens,
|
|
160
|
+
cache_creation_input_tokens, cache_read_input_tokens, started_at, completed_at
|
|
161
|
+
FROM model_usage WHERE session_id = ?
|
|
162
|
+
ORDER BY started_at ASC`, [sessionId]);
|
|
163
|
+
const turnsWithToolsEmitted = new Set();
|
|
164
|
+
const { turnTextByTurnId, prLinks } = loadPromptReferences(db, sessionId);
|
|
165
|
+
for (const row of rows) {
|
|
166
|
+
const cacheRead = row.cache_read_input_tokens ?? 0;
|
|
167
|
+
const cacheCreation = row.cache_creation_input_tokens ?? 0;
|
|
168
|
+
const output = row.output_tokens ?? 0;
|
|
169
|
+
const reasoning = row.reasoning_tokens ?? 0;
|
|
170
|
+
// ZCode folds cached tokens into input_tokens (OpenAI-style). Split
|
|
171
|
+
// them back out so fresh input bills at the input rate and cached at
|
|
172
|
+
// the cache-read rate, matching the pricing table's Anthropic-style
|
|
173
|
+
// semantics.
|
|
174
|
+
const freshInput = Math.max(0, (row.input_tokens ?? 0) - cacheRead - cacheCreation);
|
|
175
|
+
if (freshInput === 0 && output === 0 && reasoning === 0 && cacheRead === 0 && cacheCreation === 0) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const dedupKey = `zcode:${row.id}`;
|
|
179
|
+
if (seenKeys.has(dedupKey))
|
|
180
|
+
continue;
|
|
181
|
+
seenKeys.add(dedupKey);
|
|
182
|
+
let tools = [];
|
|
183
|
+
if (row.turn_id && !turnsWithToolsEmitted.has(row.turn_id)) {
|
|
184
|
+
const turnTools = toolsByTurn.get(row.turn_id);
|
|
185
|
+
if (turnTools && turnTools.length > 0) {
|
|
186
|
+
tools = turnTools;
|
|
187
|
+
turnsWithToolsEmitted.add(row.turn_id);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const model = row.model_id;
|
|
191
|
+
// ZCode reports reasoning as a separate bucket and 'zcode' is not in
|
|
192
|
+
// REASONING_INCLUDED_IN_OUTPUT, so bill it via the output-equivalent
|
|
193
|
+
// (billableOutputTokens adds it back). Not doing so left reasoning
|
|
194
|
+
// tokens unbilled.
|
|
195
|
+
const costUSD = calculateCost(model, freshInput, billableOutputTokens('zcode', output, reasoning), cacheCreation, cacheRead, 0);
|
|
196
|
+
yield {
|
|
197
|
+
provider: 'zcode',
|
|
198
|
+
model,
|
|
199
|
+
inputTokens: freshInput,
|
|
200
|
+
outputTokens: output,
|
|
201
|
+
cacheCreationInputTokens: cacheCreation,
|
|
202
|
+
cacheReadInputTokens: cacheRead,
|
|
203
|
+
cachedInputTokens: 0,
|
|
204
|
+
reasoningTokens: reasoning,
|
|
205
|
+
webSearchRequests: 0,
|
|
206
|
+
costUSD,
|
|
207
|
+
tools,
|
|
208
|
+
bashCommands: [],
|
|
209
|
+
timestamp: epochMsToIso(row.completed_at ?? row.started_at),
|
|
210
|
+
speed: 'standard',
|
|
211
|
+
deduplicationKey: dedupKey,
|
|
212
|
+
turnId: row.turn_id ?? undefined,
|
|
213
|
+
userMessage: row.turn_id ? turnTextByTurnId.get(row.turn_id) ?? '' : '',
|
|
214
|
+
...(prLinks.length > 0 ? { prLinks } : {}),
|
|
215
|
+
sessionId,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
db.close();
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
export function createZcodeProvider(dbPathOverride) {
|
|
226
|
+
const dbPath = getDbPath(dbPathOverride);
|
|
227
|
+
return {
|
|
228
|
+
name: 'zcode',
|
|
229
|
+
displayName: 'ZCode',
|
|
230
|
+
modelDisplayName(model) {
|
|
231
|
+
return model;
|
|
232
|
+
},
|
|
233
|
+
toolDisplayName(rawTool) {
|
|
234
|
+
return rawTool;
|
|
235
|
+
},
|
|
236
|
+
async probeRoots() {
|
|
237
|
+
return [{ path: dbPath, label: 'db' }];
|
|
238
|
+
},
|
|
239
|
+
async discoverSessions() {
|
|
240
|
+
if (!isSqliteAvailable())
|
|
241
|
+
return [];
|
|
242
|
+
return discover(dbPath);
|
|
243
|
+
},
|
|
244
|
+
createSessionParser(source, seenKeys) {
|
|
245
|
+
return createParser(source, seenKeys);
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
export const zcode = createZcodeProvider();
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import zlib from 'zlib';
|
|
6
|
+
import { calculateCost } from '../models.js';
|
|
7
|
+
import { getSqliteLoadError, isSqliteAvailable, isSqliteBusyError, openDatabase } from '../sqlite.js';
|
|
8
|
+
// Zed's built-in agent stores one row per thread in a single SQLite database;
|
|
9
|
+
// the `data` blob is zstd-compressed JSON carrying `request_token_usage`
|
|
10
|
+
// (per-request Anthropic-shaped token counts) and the thread's model.
|
|
11
|
+
// Format documented in issue #480.
|
|
12
|
+
function getZedThreadsDbPath() {
|
|
13
|
+
if (process.platform === 'darwin') {
|
|
14
|
+
return join(homedir(), 'Library', 'Application Support', 'Zed', 'threads', 'threads.db');
|
|
15
|
+
}
|
|
16
|
+
if (process.platform === 'win32') {
|
|
17
|
+
return join(homedir(), 'AppData', 'Local', 'Zed', 'threads', 'threads.db');
|
|
18
|
+
}
|
|
19
|
+
return join(homedir(), '.local', 'share', 'zed', 'threads', 'threads.db');
|
|
20
|
+
}
|
|
21
|
+
const THREADS_QUERY = `
|
|
22
|
+
SELECT id, summary, updated_at, data_type, data
|
|
23
|
+
FROM threads
|
|
24
|
+
ORDER BY updated_at ASC
|
|
25
|
+
`;
|
|
26
|
+
function num(value) {
|
|
27
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
28
|
+
}
|
|
29
|
+
function usageIsEmpty(usage) {
|
|
30
|
+
return (num(usage.input_tokens) === 0 &&
|
|
31
|
+
num(usage.output_tokens) === 0 &&
|
|
32
|
+
num(usage.cache_creation_input_tokens) === 0 &&
|
|
33
|
+
num(usage.cache_read_input_tokens) === 0);
|
|
34
|
+
}
|
|
35
|
+
function buildCall(opts) {
|
|
36
|
+
const input = num(opts.usage.input_tokens);
|
|
37
|
+
const output = num(opts.usage.output_tokens);
|
|
38
|
+
const cacheWrite = num(opts.usage.cache_creation_input_tokens);
|
|
39
|
+
const cacheRead = num(opts.usage.cache_read_input_tokens);
|
|
40
|
+
return {
|
|
41
|
+
provider: 'zed',
|
|
42
|
+
model: opts.model,
|
|
43
|
+
inputTokens: input,
|
|
44
|
+
outputTokens: output,
|
|
45
|
+
cacheCreationInputTokens: cacheWrite,
|
|
46
|
+
cacheReadInputTokens: cacheRead,
|
|
47
|
+
cachedInputTokens: cacheRead,
|
|
48
|
+
reasoningTokens: 0,
|
|
49
|
+
webSearchRequests: 0,
|
|
50
|
+
costUSD: calculateCost(opts.model, input, output, cacheWrite, cacheRead, 0),
|
|
51
|
+
tools: [],
|
|
52
|
+
bashCommands: [],
|
|
53
|
+
timestamp: opts.timestamp,
|
|
54
|
+
speed: 'standard',
|
|
55
|
+
deduplicationKey: `zed:${opts.threadId}:${opts.requestKey}`,
|
|
56
|
+
userMessage: opts.userMessage,
|
|
57
|
+
sessionId: opts.threadId,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function parseThreads(db, seenKeys) {
|
|
61
|
+
const calls = [];
|
|
62
|
+
let skipped = 0;
|
|
63
|
+
let rows;
|
|
64
|
+
try {
|
|
65
|
+
rows = db.query(THREADS_QUERY);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
// The whole store is one source: a locked read must defer, not cache as empty.
|
|
69
|
+
if (isSqliteBusyError(err))
|
|
70
|
+
throw err;
|
|
71
|
+
return calls;
|
|
72
|
+
}
|
|
73
|
+
for (const row of rows) {
|
|
74
|
+
try {
|
|
75
|
+
// Zed's DataType enum is "zstd" (current save path) or "json" (legacy
|
|
76
|
+
// uncompressed rows); anything else is unknown.
|
|
77
|
+
if (!row.id || !row.data || (row.data_type !== 'zstd' && row.data_type !== 'json')) {
|
|
78
|
+
if (row.data != null)
|
|
79
|
+
skipped++;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const parsedAt = new Date(row.updated_at ?? '');
|
|
83
|
+
if (Number.isNaN(parsedAt.getTime()))
|
|
84
|
+
continue;
|
|
85
|
+
const timestamp = parsedAt.toISOString();
|
|
86
|
+
const jsonText = row.data_type === 'zstd'
|
|
87
|
+
? zlib.zstdDecompressSync(Buffer.from(row.data)).toString('utf-8')
|
|
88
|
+
: Buffer.from(row.data).toString('utf-8');
|
|
89
|
+
const thread = JSON.parse(jsonText);
|
|
90
|
+
const model = thread.model?.model || 'unknown';
|
|
91
|
+
const userMessage = row.summary ?? '';
|
|
92
|
+
const requests = Object.entries(thread.request_token_usage ?? {}).filter(([, usage]) => usage != null && !usageIsEmpty(usage));
|
|
93
|
+
// The per-request map is keyed by user message and does not cover every
|
|
94
|
+
// request (verified on a real thread: cumulative was ~3x the map sum),
|
|
95
|
+
// so a remainder entry tops the thread up to the exact cumulative
|
|
96
|
+
// counter. Threads with an empty map degrade to one cumulative call.
|
|
97
|
+
const entries = [...requests];
|
|
98
|
+
const cumulative = thread.cumulative_token_usage;
|
|
99
|
+
if (cumulative && !usageIsEmpty(cumulative)) {
|
|
100
|
+
let sumIn = 0, sumOut = 0, sumWrite = 0, sumRead = 0;
|
|
101
|
+
for (const [, usage] of requests) {
|
|
102
|
+
sumIn += num(usage.input_tokens);
|
|
103
|
+
sumOut += num(usage.output_tokens);
|
|
104
|
+
sumWrite += num(usage.cache_creation_input_tokens);
|
|
105
|
+
sumRead += num(usage.cache_read_input_tokens);
|
|
106
|
+
}
|
|
107
|
+
const remainder = {
|
|
108
|
+
input_tokens: Math.max(0, num(cumulative.input_tokens) - sumIn),
|
|
109
|
+
output_tokens: Math.max(0, num(cumulative.output_tokens) - sumOut),
|
|
110
|
+
cache_creation_input_tokens: Math.max(0, num(cumulative.cache_creation_input_tokens) - sumWrite),
|
|
111
|
+
cache_read_input_tokens: Math.max(0, num(cumulative.cache_read_input_tokens) - sumRead),
|
|
112
|
+
};
|
|
113
|
+
if (!usageIsEmpty(remainder))
|
|
114
|
+
entries.push(['cumulative-remainder', remainder]);
|
|
115
|
+
}
|
|
116
|
+
for (const [requestKey, usage] of entries) {
|
|
117
|
+
const call = buildCall({ threadId: row.id, requestKey, usage, model, timestamp, userMessage });
|
|
118
|
+
if (seenKeys.has(call.deduplicationKey))
|
|
119
|
+
continue;
|
|
120
|
+
seenKeys.add(call.deduplicationKey);
|
|
121
|
+
calls.push(call);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
skipped++;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (skipped > 0) {
|
|
129
|
+
process.stderr.write(`codeburn: skipped ${skipped} unreadable Zed threads\n`);
|
|
130
|
+
}
|
|
131
|
+
return calls;
|
|
132
|
+
}
|
|
133
|
+
function createParser(source, seenKeys) {
|
|
134
|
+
return {
|
|
135
|
+
async *parse() {
|
|
136
|
+
if (!isSqliteAvailable()) {
|
|
137
|
+
process.stderr.write(getSqliteLoadError() + '\n');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
let db;
|
|
141
|
+
try {
|
|
142
|
+
db = openDatabase(source.path);
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
if (isSqliteBusyError(err))
|
|
146
|
+
throw err;
|
|
147
|
+
process.stderr.write(`codeburn: cannot open Zed database: ${err instanceof Error ? err.message : err}\n`);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
try {
|
|
151
|
+
for (const call of parseThreads(db, seenKeys)) {
|
|
152
|
+
yield call;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
db.close();
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
export function createZedProvider(dbPathOverride) {
|
|
162
|
+
return {
|
|
163
|
+
name: 'zed',
|
|
164
|
+
displayName: 'Zed',
|
|
165
|
+
modelDisplayName(model) {
|
|
166
|
+
return model;
|
|
167
|
+
},
|
|
168
|
+
toolDisplayName(rawTool) {
|
|
169
|
+
return rawTool;
|
|
170
|
+
},
|
|
171
|
+
async probeRoots() {
|
|
172
|
+
return [{ path: dbPathOverride ?? getZedThreadsDbPath(), label: 'threads.db' }];
|
|
173
|
+
},
|
|
174
|
+
async discoverSessions() {
|
|
175
|
+
if (!isSqliteAvailable())
|
|
176
|
+
return [];
|
|
177
|
+
const dbPath = dbPathOverride ?? getZedThreadsDbPath();
|
|
178
|
+
if (!existsSync(dbPath))
|
|
179
|
+
return [];
|
|
180
|
+
return [{ path: dbPath, project: 'zed', provider: 'zed' }];
|
|
181
|
+
},
|
|
182
|
+
createSessionParser(source, seenKeys) {
|
|
183
|
+
return createParser(source, seenKeys);
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export const zed = createZedProvider();
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { readdir } from 'fs/promises';
|
|
3
|
+
import { basename, join } from 'path';
|
|
4
|
+
import { homedir, platform } from 'os';
|
|
5
|
+
import { readSessionFile } from '../fs-utils.js';
|
|
6
|
+
import { calculateCost, getShortModelName, ownValue } from '../models.js';
|
|
7
|
+
// zerostack (https://github.com/gi-dellav/zerostack) is a minimal Rust coding
|
|
8
|
+
// agent. Each session is a single JSON file under <dataDir>/zerostack/sessions/.
|
|
9
|
+
// Token counts are stored as CUMULATIVE session totals (total_input_tokens,
|
|
10
|
+
// total_output_tokens, total_cost) — there is no per-call breakdown — so we emit
|
|
11
|
+
// one ParsedProviderCall per session.
|
|
12
|
+
const toolNameMap = {
|
|
13
|
+
bash: 'Bash',
|
|
14
|
+
read: 'Read',
|
|
15
|
+
write: 'Write',
|
|
16
|
+
edit: 'Edit',
|
|
17
|
+
grep: 'Grep',
|
|
18
|
+
glob: 'Glob',
|
|
19
|
+
fetch: 'WebFetch',
|
|
20
|
+
search: 'WebSearch',
|
|
21
|
+
task: 'Agent',
|
|
22
|
+
};
|
|
23
|
+
// zerostack uses the platform data dir (Rust `dirs::data_dir`): macOS maps to
|
|
24
|
+
// ~/Library/Application Support, everything else to $XDG_DATA_HOME or
|
|
25
|
+
// ~/.local/share, then a `zerostack` subdir. ZS_DATA_DIR overrides the whole
|
|
26
|
+
// data dir (sessions live directly under it). Matches src/session/storage.rs.
|
|
27
|
+
function defaultSessionsDir() {
|
|
28
|
+
const override = process.env['ZS_DATA_DIR'];
|
|
29
|
+
if (override)
|
|
30
|
+
return join(override, 'sessions');
|
|
31
|
+
const base = platform() === 'darwin'
|
|
32
|
+
? join(homedir(), 'Library', 'Application Support')
|
|
33
|
+
: process.env['XDG_DATA_HOME'] ?? join(homedir(), '.local', 'share');
|
|
34
|
+
return join(base, 'zerostack', 'sessions');
|
|
35
|
+
}
|
|
36
|
+
function firstUserMessage(messages) {
|
|
37
|
+
const msg = messages.find(m => m.role === 'user');
|
|
38
|
+
if (!msg)
|
|
39
|
+
return '';
|
|
40
|
+
if (typeof msg.content === 'string')
|
|
41
|
+
return msg.content;
|
|
42
|
+
return (msg.content ?? []).map(c => c.text ?? '').filter(Boolean).join(' ');
|
|
43
|
+
}
|
|
44
|
+
async function readSession(path) {
|
|
45
|
+
const content = await readSessionFile(path);
|
|
46
|
+
if (content === null)
|
|
47
|
+
return null;
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(content);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function createParser(source, seenKeys) {
|
|
56
|
+
return {
|
|
57
|
+
async *parse() {
|
|
58
|
+
const session = await readSession(source.path);
|
|
59
|
+
if (!session)
|
|
60
|
+
return;
|
|
61
|
+
const input = session.total_input_tokens ?? 0;
|
|
62
|
+
const output = session.total_output_tokens ?? 0;
|
|
63
|
+
if (input === 0 && output === 0)
|
|
64
|
+
return;
|
|
65
|
+
const timestamp = session.updated_at ?? session.created_at ?? '';
|
|
66
|
+
const sessionId = session.id ?? basename(source.path, '.json');
|
|
67
|
+
const dedupKey = `${source.provider}:${source.path}:${timestamp}:${sessionId}`;
|
|
68
|
+
if (seenKeys.has(dedupKey))
|
|
69
|
+
return;
|
|
70
|
+
seenKeys.add(dedupKey);
|
|
71
|
+
const model = session.model ?? '';
|
|
72
|
+
yield {
|
|
73
|
+
provider: source.provider,
|
|
74
|
+
model,
|
|
75
|
+
inputTokens: input,
|
|
76
|
+
outputTokens: output,
|
|
77
|
+
cacheCreationInputTokens: 0,
|
|
78
|
+
cacheReadInputTokens: 0,
|
|
79
|
+
cachedInputTokens: 0,
|
|
80
|
+
reasoningTokens: 0,
|
|
81
|
+
webSearchRequests: 0,
|
|
82
|
+
costUSD: calculateCost(model, input, output, 0, 0, 0),
|
|
83
|
+
// zerostack persists only final assistant text, not tool-call records,
|
|
84
|
+
// so there is nothing to extract here.
|
|
85
|
+
tools: [],
|
|
86
|
+
bashCommands: [],
|
|
87
|
+
timestamp,
|
|
88
|
+
speed: 'standard',
|
|
89
|
+
deduplicationKey: dedupKey,
|
|
90
|
+
userMessage: firstUserMessage(session.messages ?? []),
|
|
91
|
+
sessionId,
|
|
92
|
+
project: source.project,
|
|
93
|
+
projectPath: session.working_dir,
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function createZerostackProvider(sessionsDir) {
|
|
99
|
+
const dir = sessionsDir ?? defaultSessionsDir();
|
|
100
|
+
return {
|
|
101
|
+
name: 'zerostack',
|
|
102
|
+
displayName: 'Zerostack',
|
|
103
|
+
modelDisplayName(model) {
|
|
104
|
+
// OpenRouter routes arrive prefixed (e.g. "deepseek/deepseek-v4-pro").
|
|
105
|
+
return getShortModelName(model.replace(/^[^/]+\//, ''));
|
|
106
|
+
},
|
|
107
|
+
toolDisplayName(rawTool) {
|
|
108
|
+
return ownValue(toolNameMap, rawTool) ?? rawTool;
|
|
109
|
+
},
|
|
110
|
+
async probeRoots() {
|
|
111
|
+
return [{ path: dir, label: 'sessions' }];
|
|
112
|
+
},
|
|
113
|
+
async discoverSessions() {
|
|
114
|
+
let files;
|
|
115
|
+
try {
|
|
116
|
+
files = await readdir(dir);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const sources = [];
|
|
122
|
+
for (const file of files) {
|
|
123
|
+
if (!file.endsWith('.json'))
|
|
124
|
+
continue;
|
|
125
|
+
const path = join(dir, file);
|
|
126
|
+
const session = await readSession(path);
|
|
127
|
+
if (!session)
|
|
128
|
+
continue;
|
|
129
|
+
const project = session.working_dir ? basename(session.working_dir) : basename(file, '.json');
|
|
130
|
+
sources.push({ path, project, provider: 'zerostack' });
|
|
131
|
+
}
|
|
132
|
+
return sources;
|
|
133
|
+
},
|
|
134
|
+
createSessionParser(source, seenKeys) {
|
|
135
|
+
return createParser(source, seenKeys);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export const zerostack = createZerostackProvider();
|