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,491 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { readdir, readFile, stat } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { basename, isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
import { calculateCost, ownValue } from '../models.js';
|
|
6
|
+
import { estimateTokensFromChars } from '../token-estimate.js';
|
|
7
|
+
import { blobToText, isSqliteAvailable, isSqliteBusyError, openDatabase } from '../sqlite.js';
|
|
8
|
+
const METRICS_FILE_RE = /^metrics-(\d{4})-(\d{2})-(\d{2})\.jsonl$/;
|
|
9
|
+
const modelDisplayNames = {
|
|
10
|
+
'claude-sonnet-4-5': 'Sonnet 4.5',
|
|
11
|
+
'claude-sonnet-4-6': 'Sonnet 4.6',
|
|
12
|
+
};
|
|
13
|
+
const toolNameMap = {
|
|
14
|
+
readFile: 'Read',
|
|
15
|
+
read_file: 'Read',
|
|
16
|
+
writeFile: 'Edit',
|
|
17
|
+
write_file: 'Edit',
|
|
18
|
+
editFile: 'Edit',
|
|
19
|
+
edit_file: 'Edit',
|
|
20
|
+
runCommand: 'Bash',
|
|
21
|
+
run_command: 'Bash',
|
|
22
|
+
executeBash: 'Bash',
|
|
23
|
+
shell: 'Bash',
|
|
24
|
+
grep: 'Grep',
|
|
25
|
+
searchFiles: 'Grep',
|
|
26
|
+
search_files: 'Grep',
|
|
27
|
+
};
|
|
28
|
+
function quickworkHome() {
|
|
29
|
+
return resolve(process.env['QUICKWORK_HOME'] || join(homedir(), '.quickwork'));
|
|
30
|
+
}
|
|
31
|
+
function asRecord(value) {
|
|
32
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
33
|
+
? value
|
|
34
|
+
: null;
|
|
35
|
+
}
|
|
36
|
+
function stringValue(value) {
|
|
37
|
+
return typeof value === 'string' ? value.trim() : '';
|
|
38
|
+
}
|
|
39
|
+
function finiteNumber(value) {
|
|
40
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
41
|
+
}
|
|
42
|
+
function nonNegativeNumber(value) {
|
|
43
|
+
const number = finiteNumber(value);
|
|
44
|
+
return number !== undefined && number >= 0 ? number : undefined;
|
|
45
|
+
}
|
|
46
|
+
async function resolveProfileBases() {
|
|
47
|
+
const root = quickworkHome();
|
|
48
|
+
try {
|
|
49
|
+
const parsed = asRecord(JSON.parse(await readFile(join(root, 'profiles.json'), 'utf8')));
|
|
50
|
+
const entries = parsed?.['entries'];
|
|
51
|
+
if (Array.isArray(entries)) {
|
|
52
|
+
const bases = [];
|
|
53
|
+
const seenPaths = new Set();
|
|
54
|
+
for (const rawEntry of entries) {
|
|
55
|
+
const entry = asRecord(rawEntry);
|
|
56
|
+
const profile = stringValue(entry?.['id']);
|
|
57
|
+
const dataPath = stringValue(entry?.['data_path']);
|
|
58
|
+
if (!profile || !dataPath)
|
|
59
|
+
continue;
|
|
60
|
+
const basePath = isAbsolute(dataPath) ? resolve(dataPath) : resolve(root, dataPath);
|
|
61
|
+
if (seenPaths.has(basePath))
|
|
62
|
+
continue;
|
|
63
|
+
seenPaths.add(basePath);
|
|
64
|
+
bases.push({ path: basePath, profile });
|
|
65
|
+
}
|
|
66
|
+
if (bases.length > 0) {
|
|
67
|
+
const legacyDbPath = join(root, 'sessions', 'sessions.db');
|
|
68
|
+
if (!seenPaths.has(root) && await isFile(legacyDbPath)) {
|
|
69
|
+
bases.push({ path: root, profile: 'default' });
|
|
70
|
+
}
|
|
71
|
+
return bases;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Missing, unreadable, or malformed profiles.json is the legacy root layout.
|
|
77
|
+
}
|
|
78
|
+
return [{ path: root, profile: 'default' }];
|
|
79
|
+
}
|
|
80
|
+
async function isFile(path) {
|
|
81
|
+
try {
|
|
82
|
+
return (await stat(path)).isFile();
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function metricsFiles(basePath) {
|
|
89
|
+
const metricsDir = join(basePath, 'metrics');
|
|
90
|
+
try {
|
|
91
|
+
const entries = await readdir(metricsDir, { withFileTypes: true });
|
|
92
|
+
return entries
|
|
93
|
+
.filter(entry => entry.isFile() && METRICS_FILE_RE.test(entry.name))
|
|
94
|
+
.map(entry => join(metricsDir, entry.name))
|
|
95
|
+
.sort();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async function discoverSources() {
|
|
102
|
+
const sources = [];
|
|
103
|
+
for (const base of await resolveProfileBases()) {
|
|
104
|
+
for (const metricsPath of await metricsFiles(base.path)) {
|
|
105
|
+
sources.push({
|
|
106
|
+
path: metricsPath,
|
|
107
|
+
project: base.profile,
|
|
108
|
+
provider: 'quickdesk',
|
|
109
|
+
sourceId: 'metrics',
|
|
110
|
+
sourcePath: base.path,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const dbPath = join(base.path, 'sessions', 'sessions.db');
|
|
114
|
+
if (await isFile(dbPath)) {
|
|
115
|
+
sources.push({
|
|
116
|
+
path: dbPath,
|
|
117
|
+
project: base.profile,
|
|
118
|
+
provider: 'quickdesk',
|
|
119
|
+
sourceId: 'sessions-db',
|
|
120
|
+
sourcePath: base.path,
|
|
121
|
+
durable: false,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return sources;
|
|
126
|
+
}
|
|
127
|
+
function tableNames(db) {
|
|
128
|
+
const rows = db.query("SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('sessions', 'session_messages')");
|
|
129
|
+
return new Set(rows.map(row => stringValue(row.name)).filter(Boolean));
|
|
130
|
+
}
|
|
131
|
+
function tableColumns(db, table) {
|
|
132
|
+
const rows = db.query(`PRAGMA table_info(${table})`);
|
|
133
|
+
return new Set(rows.map(row => stringValue(row.name)).filter(Boolean));
|
|
134
|
+
}
|
|
135
|
+
function selectColumn(columns, name, fallback = 'NULL') {
|
|
136
|
+
return columns.has(name) ? name : `${fallback} AS ${name}`;
|
|
137
|
+
}
|
|
138
|
+
function toolNames(value) {
|
|
139
|
+
const text = value instanceof Uint8Array ? blobToText(value) : stringValue(value);
|
|
140
|
+
if (!text)
|
|
141
|
+
return [];
|
|
142
|
+
try {
|
|
143
|
+
const parsed = JSON.parse(text);
|
|
144
|
+
if (Array.isArray(parsed)) {
|
|
145
|
+
return parsed.flatMap(entry => {
|
|
146
|
+
if (typeof entry === 'string')
|
|
147
|
+
return entry.trim() ? [entry.trim()] : [];
|
|
148
|
+
const record = asRecord(entry);
|
|
149
|
+
const name = stringValue(record?.['name']) || stringValue(record?.['tool_name']) || stringValue(record?.['toolName']);
|
|
150
|
+
return name ? [name] : [];
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Older stores may use a comma-separated tool_names value instead of JSON.
|
|
156
|
+
}
|
|
157
|
+
return text.split(',').map(name => name.trim()).filter(Boolean);
|
|
158
|
+
}
|
|
159
|
+
function uniqueMappedTools(values) {
|
|
160
|
+
return [...new Set(values.map(value => ownValue(toolNameMap, value) ?? value).filter(Boolean))];
|
|
161
|
+
}
|
|
162
|
+
function timestampSeconds(value) {
|
|
163
|
+
const number = finiteNumber(value);
|
|
164
|
+
return number !== undefined && number >= 0 ? number : undefined;
|
|
165
|
+
}
|
|
166
|
+
function unixSecondsIso(value) {
|
|
167
|
+
const date = new Date(value * 1000);
|
|
168
|
+
return Number.isNaN(date.getTime()) ? null : date.toISOString();
|
|
169
|
+
}
|
|
170
|
+
function loadDatabaseSnapshot(basePath) {
|
|
171
|
+
const empty = { sessions: new Map(), canEstimate: false };
|
|
172
|
+
if (!isSqliteAvailable())
|
|
173
|
+
return empty;
|
|
174
|
+
let db;
|
|
175
|
+
try {
|
|
176
|
+
db = openDatabase(join(basePath, 'sessions', 'sessions.db'));
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
// A locked store must defer the parse, not read as a store with no sessions.
|
|
180
|
+
if (isSqliteBusyError(err))
|
|
181
|
+
throw err;
|
|
182
|
+
return empty;
|
|
183
|
+
}
|
|
184
|
+
try {
|
|
185
|
+
const tables = tableNames(db);
|
|
186
|
+
if (!tables.has('sessions'))
|
|
187
|
+
return empty;
|
|
188
|
+
const sessionColumns = tableColumns(db, 'sessions');
|
|
189
|
+
if (!sessionColumns.has('id'))
|
|
190
|
+
return empty;
|
|
191
|
+
const deletionKnown = sessionColumns.has('deleted_at');
|
|
192
|
+
const sessionRows = db.query(`SELECT id,
|
|
193
|
+
${selectColumn(sessionColumns, 'title')},
|
|
194
|
+
${selectColumn(sessionColumns, 'agent_mode')},
|
|
195
|
+
${selectColumn(sessionColumns, 'created_at')},
|
|
196
|
+
${selectColumn(sessionColumns, 'deleted_at')}
|
|
197
|
+
FROM sessions`);
|
|
198
|
+
const sessions = new Map();
|
|
199
|
+
for (const row of sessionRows) {
|
|
200
|
+
const id = stringValue(row.id);
|
|
201
|
+
if (!id)
|
|
202
|
+
continue;
|
|
203
|
+
sessions.set(id, {
|
|
204
|
+
id,
|
|
205
|
+
title: stringValue(row.title),
|
|
206
|
+
agentMode: stringValue(row.agent_mode),
|
|
207
|
+
createdAt: timestampSeconds(row.created_at),
|
|
208
|
+
deleted: deletionKnown && row.deleted_at !== null && row.deleted_at !== undefined,
|
|
209
|
+
firstUserMessage: '',
|
|
210
|
+
inputChars: 0,
|
|
211
|
+
outputChars: 0,
|
|
212
|
+
tools: [],
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
if (!tables.has('session_messages')) {
|
|
216
|
+
return { sessions, canEstimate: false };
|
|
217
|
+
}
|
|
218
|
+
const messageColumns = tableColumns(db, 'session_messages');
|
|
219
|
+
if (!messageColumns.has('session_id') || !messageColumns.has('role') || !messageColumns.has('content')) {
|
|
220
|
+
return { sessions, canEstimate: false };
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
const orderBy = messageColumns.has('timestamp') ? 'ORDER BY timestamp ASC' : '';
|
|
224
|
+
const rows = db.query(`SELECT session_id,
|
|
225
|
+
role,
|
|
226
|
+
CAST(content AS BLOB) AS content,
|
|
227
|
+
${messageColumns.has('tool_names') ? 'CAST(tool_names AS BLOB) AS tool_names' : 'NULL AS tool_names'}
|
|
228
|
+
FROM session_messages
|
|
229
|
+
${orderBy}`);
|
|
230
|
+
for (const row of rows) {
|
|
231
|
+
const sessionId = stringValue(row.session_id);
|
|
232
|
+
const session = sessions.get(sessionId);
|
|
233
|
+
if (!session)
|
|
234
|
+
continue;
|
|
235
|
+
const role = stringValue(row.role).toLowerCase();
|
|
236
|
+
const content = row.content instanceof Uint8Array ? blobToText(row.content) : stringValue(row.content);
|
|
237
|
+
if (role === 'assistant')
|
|
238
|
+
session.outputChars += content.length;
|
|
239
|
+
else
|
|
240
|
+
session.inputChars += content.length;
|
|
241
|
+
if (role === 'user' && !session.firstUserMessage && content.trim()) {
|
|
242
|
+
session.firstUserMessage = content.trim();
|
|
243
|
+
}
|
|
244
|
+
session.tools.push(...toolNames(row.tool_names));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (err) {
|
|
248
|
+
if (isSqliteBusyError(err))
|
|
249
|
+
throw err;
|
|
250
|
+
return { sessions, canEstimate: false };
|
|
251
|
+
}
|
|
252
|
+
for (const session of sessions.values())
|
|
253
|
+
session.tools = uniqueMappedTools(session.tools);
|
|
254
|
+
return { sessions, canEstimate: true };
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
if (isSqliteBusyError(err))
|
|
258
|
+
throw err;
|
|
259
|
+
return empty;
|
|
260
|
+
}
|
|
261
|
+
finally {
|
|
262
|
+
db.close();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async function readMetricsRecords(path) {
|
|
266
|
+
let contents;
|
|
267
|
+
try {
|
|
268
|
+
contents = await readFile(path, 'utf8');
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
return [];
|
|
272
|
+
}
|
|
273
|
+
const records = [];
|
|
274
|
+
const lines = contents.split(/\r?\n/);
|
|
275
|
+
for (let index = 0; index < lines.length; index++) {
|
|
276
|
+
const line = lines[index].trim();
|
|
277
|
+
if (!line)
|
|
278
|
+
continue;
|
|
279
|
+
try {
|
|
280
|
+
const record = asRecord(JSON.parse(line));
|
|
281
|
+
if (record)
|
|
282
|
+
records.push({ record });
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
// A partially-written or malformed JSONL line must not hide later records.
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return records;
|
|
289
|
+
}
|
|
290
|
+
function usageRecord(record) {
|
|
291
|
+
return Boolean(stringValue(record['Model']))
|
|
292
|
+
&& nonNegativeNumber(record['InputTokens']) !== undefined
|
|
293
|
+
&& nonNegativeNumber(record['OutputTokens']) !== undefined;
|
|
294
|
+
}
|
|
295
|
+
function sessionId(record) {
|
|
296
|
+
return stringValue(record['session_id']);
|
|
297
|
+
}
|
|
298
|
+
function toolsKey(record) {
|
|
299
|
+
return sessionId(record);
|
|
300
|
+
}
|
|
301
|
+
function collectMetricTools(records) {
|
|
302
|
+
const tools = new Map();
|
|
303
|
+
for (const { record } of records) {
|
|
304
|
+
const key = toolsKey(record);
|
|
305
|
+
const tool = stringValue(record['ToolName']);
|
|
306
|
+
if (!key || !tool)
|
|
307
|
+
continue;
|
|
308
|
+
const current = tools.get(key) ?? [];
|
|
309
|
+
current.push(ownValue(toolNameMap, tool) ?? tool);
|
|
310
|
+
tools.set(key, current);
|
|
311
|
+
}
|
|
312
|
+
for (const [key, values] of tools)
|
|
313
|
+
tools.set(key, [...new Set(values)]);
|
|
314
|
+
return tools;
|
|
315
|
+
}
|
|
316
|
+
function fallbackTimestamp(path) {
|
|
317
|
+
const match = METRICS_FILE_RE.exec(basename(path));
|
|
318
|
+
if (!match)
|
|
319
|
+
return null;
|
|
320
|
+
const year = Number(match[1]);
|
|
321
|
+
const month = Number(match[2]);
|
|
322
|
+
const day = Number(match[3]);
|
|
323
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
324
|
+
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day)
|
|
325
|
+
return null;
|
|
326
|
+
return date.toISOString();
|
|
327
|
+
}
|
|
328
|
+
function metricsTimestamp(record, path) {
|
|
329
|
+
const aws = asRecord(record['_aws']);
|
|
330
|
+
const timestampMs = finiteNumber(aws?.['Timestamp']);
|
|
331
|
+
if (timestampMs !== undefined) {
|
|
332
|
+
const date = new Date(timestampMs);
|
|
333
|
+
if (!Number.isNaN(date.getTime()))
|
|
334
|
+
return date.toISOString();
|
|
335
|
+
}
|
|
336
|
+
return fallbackTimestamp(path);
|
|
337
|
+
}
|
|
338
|
+
async function metricSessionIds(basePath) {
|
|
339
|
+
const ids = new Set();
|
|
340
|
+
for (const path of await metricsFiles(basePath)) {
|
|
341
|
+
for (const { record } of await readMetricsRecords(path)) {
|
|
342
|
+
if (!usageRecord(record))
|
|
343
|
+
continue;
|
|
344
|
+
const id = sessionId(record);
|
|
345
|
+
if (id)
|
|
346
|
+
ids.add(id);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return ids;
|
|
350
|
+
}
|
|
351
|
+
async function allMetricSessionIds() {
|
|
352
|
+
const ids = new Set();
|
|
353
|
+
for (const base of await resolveProfileBases()) {
|
|
354
|
+
for (const id of await metricSessionIds(base.path))
|
|
355
|
+
ids.add(id);
|
|
356
|
+
}
|
|
357
|
+
return ids;
|
|
358
|
+
}
|
|
359
|
+
function basePathFor(source) {
|
|
360
|
+
if (source.sourcePath)
|
|
361
|
+
return source.sourcePath;
|
|
362
|
+
return resolve(source.path, '..', '..');
|
|
363
|
+
}
|
|
364
|
+
function commonCallFields(source, basePath) {
|
|
365
|
+
return {
|
|
366
|
+
provider: 'quickdesk',
|
|
367
|
+
cacheCreationInputTokens: 0,
|
|
368
|
+
cacheReadInputTokens: 0,
|
|
369
|
+
cachedInputTokens: 0,
|
|
370
|
+
reasoningTokens: 0,
|
|
371
|
+
webSearchRequests: 0,
|
|
372
|
+
bashCommands: [],
|
|
373
|
+
speed: 'standard',
|
|
374
|
+
project: source.project,
|
|
375
|
+
projectPath: basePath,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function createMetricsParser(source, seenKeys) {
|
|
379
|
+
return {
|
|
380
|
+
async *parse() {
|
|
381
|
+
const records = await readMetricsRecords(source.path);
|
|
382
|
+
const basePath = basePathFor(source);
|
|
383
|
+
const linkedTools = collectMetricTools(records);
|
|
384
|
+
const snapshot = loadDatabaseSnapshot(basePath);
|
|
385
|
+
const fileId = basename(source.path);
|
|
386
|
+
for (const { record } of records) {
|
|
387
|
+
if (!usageRecord(record))
|
|
388
|
+
continue;
|
|
389
|
+
const model = stringValue(record['Model']);
|
|
390
|
+
const inputTokens = nonNegativeNumber(record['InputTokens']);
|
|
391
|
+
const outputTokens = nonNegativeNumber(record['OutputTokens']);
|
|
392
|
+
const timestamp = metricsTimestamp(record, source.path);
|
|
393
|
+
if (!timestamp)
|
|
394
|
+
continue;
|
|
395
|
+
const linkedSessionId = sessionId(record);
|
|
396
|
+
const metadata = linkedSessionId ? snapshot.sessions.get(linkedSessionId) : undefined;
|
|
397
|
+
if (metadata?.deleted)
|
|
398
|
+
continue;
|
|
399
|
+
const fallbackId = `${source.project}:${fileId}`;
|
|
400
|
+
const deduplicationKey = `quickdesk:${linkedSessionId || fallbackId}:${timestamp}:${model}:${inputTokens}:${outputTokens}`;
|
|
401
|
+
if (seenKeys.has(deduplicationKey))
|
|
402
|
+
continue;
|
|
403
|
+
seenKeys.add(deduplicationKey);
|
|
404
|
+
const recordedCost = nonNegativeNumber(record['CostUSD']);
|
|
405
|
+
const costIsEstimated = recordedCost === undefined;
|
|
406
|
+
const metricTools = linkedTools.get(toolsKey(record)) ?? [];
|
|
407
|
+
const tools = uniqueMappedTools([...metricTools, ...(metadata?.tools ?? [])]);
|
|
408
|
+
yield {
|
|
409
|
+
...commonCallFields(source, basePath),
|
|
410
|
+
model,
|
|
411
|
+
inputTokens,
|
|
412
|
+
outputTokens,
|
|
413
|
+
costUSD: recordedCost ?? calculateCost(model, inputTokens, outputTokens, 0, 0, 0),
|
|
414
|
+
costIsEstimated,
|
|
415
|
+
tools,
|
|
416
|
+
timestamp,
|
|
417
|
+
deduplicationKey,
|
|
418
|
+
userMessage: metadata?.firstUserMessage ?? '',
|
|
419
|
+
sessionId: linkedSessionId || fileId,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
function createDatabaseParser(source, seenKeys) {
|
|
426
|
+
return {
|
|
427
|
+
async *parse() {
|
|
428
|
+
const basePath = basePathFor(source);
|
|
429
|
+
const snapshot = loadDatabaseSnapshot(basePath);
|
|
430
|
+
if (!snapshot.canEstimate)
|
|
431
|
+
return;
|
|
432
|
+
const meteredSessions = await allMetricSessionIds();
|
|
433
|
+
for (const metadata of snapshot.sessions.values()) {
|
|
434
|
+
if (metadata.deleted || meteredSessions.has(metadata.id) || metadata.createdAt === undefined)
|
|
435
|
+
continue;
|
|
436
|
+
const createdAtSeconds = metadata.createdAt > 1_000_000_000_000
|
|
437
|
+
? metadata.createdAt / 1000
|
|
438
|
+
: metadata.createdAt;
|
|
439
|
+
const timestamp = unixSecondsIso(createdAtSeconds);
|
|
440
|
+
if (!timestamp)
|
|
441
|
+
continue;
|
|
442
|
+
const inputTokens = estimateTokensFromChars(metadata.inputChars);
|
|
443
|
+
const outputTokens = estimateTokensFromChars(metadata.outputChars);
|
|
444
|
+
if (inputTokens + outputTokens === 0)
|
|
445
|
+
continue;
|
|
446
|
+
const deduplicationKey = `quickdesk-est:${metadata.id}`;
|
|
447
|
+
if (seenKeys.has(deduplicationKey))
|
|
448
|
+
continue;
|
|
449
|
+
seenKeys.add(deduplicationKey);
|
|
450
|
+
const model = 'quickdesk-auto';
|
|
451
|
+
yield {
|
|
452
|
+
...commonCallFields(source, basePath),
|
|
453
|
+
model,
|
|
454
|
+
inputTokens,
|
|
455
|
+
outputTokens,
|
|
456
|
+
costUSD: calculateCost(model, inputTokens, outputTokens, 0, 0, 0),
|
|
457
|
+
costIsEstimated: true,
|
|
458
|
+
tools: metadata.tools,
|
|
459
|
+
timestamp,
|
|
460
|
+
deduplicationKey,
|
|
461
|
+
userMessage: metadata.firstUserMessage,
|
|
462
|
+
sessionId: metadata.id,
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
export const quickdesk = {
|
|
469
|
+
name: 'quickdesk',
|
|
470
|
+
displayName: 'Quick Desktop',
|
|
471
|
+
durableSources: true,
|
|
472
|
+
modelDisplayName(model) {
|
|
473
|
+
if (model === 'quickdesk-auto')
|
|
474
|
+
return 'Quick Desktop (auto)';
|
|
475
|
+
return ownValue(modelDisplayNames, model) ?? model;
|
|
476
|
+
},
|
|
477
|
+
toolDisplayName(rawTool) {
|
|
478
|
+
return ownValue(toolNameMap, rawTool) ?? rawTool;
|
|
479
|
+
},
|
|
480
|
+
async probeRoots() {
|
|
481
|
+
return (await resolveProfileBases()).map(base => ({ path: base.path, label: base.profile }));
|
|
482
|
+
},
|
|
483
|
+
async discoverSessions() {
|
|
484
|
+
return discoverSources();
|
|
485
|
+
},
|
|
486
|
+
createSessionParser(source, seenKeys) {
|
|
487
|
+
return source.sourceId === 'sessions-db' || basename(source.path) === 'sessions.db'
|
|
488
|
+
? createDatabaseParser(source, seenKeys)
|
|
489
|
+
: createMetricsParser(source, seenKeys);
|
|
490
|
+
},
|
|
491
|
+
};
|
|
@@ -0,0 +1,193 @@
|
|
|
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 { join } from 'path';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { readSessionFile } from '../fs-utils.js';
|
|
6
|
+
import { calculateCost, ownValue } from '../models.js';
|
|
7
|
+
import { extractBashCommands } from '../bash-utils.js';
|
|
8
|
+
const toolNameMap = {
|
|
9
|
+
read_file: 'Read',
|
|
10
|
+
write_to_file: 'Write',
|
|
11
|
+
edit_file: 'Edit',
|
|
12
|
+
execute_command: 'Bash',
|
|
13
|
+
search_files: 'Grep',
|
|
14
|
+
list_files: 'LS',
|
|
15
|
+
list_directory: 'LS',
|
|
16
|
+
browser_action: 'WebFetch',
|
|
17
|
+
web_search: 'WebSearch',
|
|
18
|
+
ask_followup_question: 'AskUser',
|
|
19
|
+
attempt_completion: 'Complete',
|
|
20
|
+
};
|
|
21
|
+
function getQwenProjectsDir() {
|
|
22
|
+
return process.env['QWEN_DATA_DIR'] ?? join(homedir(), '.qwen', 'projects');
|
|
23
|
+
}
|
|
24
|
+
function projectNameFromDirName(dirName) {
|
|
25
|
+
const parts = dirName.replace(/^-/, '').split('-');
|
|
26
|
+
return parts[parts.length - 1] || dirName;
|
|
27
|
+
}
|
|
28
|
+
// Validate the entry timestamp and fall back to the file mtime when it is
|
|
29
|
+
// missing/unparseable, so the call lands on a real day instead of an empty
|
|
30
|
+
// string that parser.ts date filters exclude from period reports.
|
|
31
|
+
function isoTimestamp(value, fallback) {
|
|
32
|
+
if (value) {
|
|
33
|
+
const date = new Date(value);
|
|
34
|
+
if (!Number.isNaN(date.getTime()))
|
|
35
|
+
return date.toISOString();
|
|
36
|
+
}
|
|
37
|
+
return fallback;
|
|
38
|
+
}
|
|
39
|
+
// Qwen Code's outputTokenCount (packages/core/src/telemetry/gen-ai-usage.ts):
|
|
40
|
+
// thoughts sit inside candidates on the OpenAI-compatible, Responses and Qwen
|
|
41
|
+
// OAuth backends and beside them elsewhere; a total in the band both allow
|
|
42
|
+
// decides, else the auth type does. Records older than the auth type on user
|
|
43
|
+
// records leave it unknown, and then thoughts are not added: the converters
|
|
44
|
+
// Qwen Code ships mostly fold them in, and its own cost ledger bills
|
|
45
|
+
// candidates alone without a total.
|
|
46
|
+
const THOUGHTS_IN_CANDIDATES = new Set(['openai', 'openai-responses', 'qwen-oauth']);
|
|
47
|
+
function billedOutputTokens(candidates, thoughts, total, prompt, authType) {
|
|
48
|
+
const derived = total - prompt;
|
|
49
|
+
if (total > 0 && derived >= candidates && derived <= candidates + thoughts)
|
|
50
|
+
return derived;
|
|
51
|
+
return authType === undefined || THOUGHTS_IN_CANDIDATES.has(authType) ? candidates : candidates + thoughts;
|
|
52
|
+
}
|
|
53
|
+
function extractTools(parts) {
|
|
54
|
+
const tools = [];
|
|
55
|
+
const bashCommands = [];
|
|
56
|
+
for (const part of parts) {
|
|
57
|
+
if (part.functionCall?.name) {
|
|
58
|
+
const mapped = ownValue(toolNameMap, part.functionCall.name) ?? part.functionCall.name;
|
|
59
|
+
tools.push(mapped);
|
|
60
|
+
if (mapped === 'Bash' && part.functionCall.args && typeof part.functionCall.args['command'] === 'string') {
|
|
61
|
+
bashCommands.push(...extractBashCommands(part.functionCall.args['command']));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { tools, bashCommands };
|
|
66
|
+
}
|
|
67
|
+
function createParser(source, seenKeys) {
|
|
68
|
+
return {
|
|
69
|
+
async *parse() {
|
|
70
|
+
const raw = await readSessionFile(source.path);
|
|
71
|
+
if (raw === null)
|
|
72
|
+
return;
|
|
73
|
+
const fileStat = await stat(source.path).catch(() => null);
|
|
74
|
+
const fileMtime = fileStat?.mtime.toISOString() ?? '';
|
|
75
|
+
const lines = raw.split('\n').filter(l => l.trim());
|
|
76
|
+
let pendingUserMessage = '';
|
|
77
|
+
let authType;
|
|
78
|
+
for (const line of lines) {
|
|
79
|
+
let entry;
|
|
80
|
+
try {
|
|
81
|
+
entry = JSON.parse(line);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
// Qwen Code stamps each user record with the auth type in force then (it can change mid-session).
|
|
87
|
+
if (entry.type === 'user')
|
|
88
|
+
authType = typeof entry.executionContext?.authType === 'string' ? entry.executionContext.authType : undefined;
|
|
89
|
+
if (entry.type === 'user' && entry.message) {
|
|
90
|
+
const texts = (entry.message.parts ?? [])
|
|
91
|
+
.filter(p => p.text && !p.thought)
|
|
92
|
+
.map(p => p.text);
|
|
93
|
+
if (texts.length > 0) {
|
|
94
|
+
pendingUserMessage = texts.join(' ').slice(0, 500);
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (entry.type !== 'assistant' || !entry.usageMetadata)
|
|
99
|
+
continue;
|
|
100
|
+
const usage = entry.usageMetadata;
|
|
101
|
+
if (usage.promptTokenCount === 0 && usage.candidatesTokenCount === 0)
|
|
102
|
+
continue;
|
|
103
|
+
const dedupKey = `qwen:${entry.sessionId}:${entry.uuid}`;
|
|
104
|
+
if (seenKeys.has(dedupKey))
|
|
105
|
+
continue;
|
|
106
|
+
seenKeys.add(dedupKey);
|
|
107
|
+
const model = entry.model || 'qwen-auto';
|
|
108
|
+
const { tools, bashCommands } = extractTools(entry.message?.parts ?? []);
|
|
109
|
+
// promptTokenCount includes the cached tokens, as in Gemini CLI.
|
|
110
|
+
const prompt = Math.max(0, usage.promptTokenCount ?? 0);
|
|
111
|
+
const candidates = usage.candidatesTokenCount ?? 0;
|
|
112
|
+
const thoughts = usage.thoughtsTokenCount ?? 0;
|
|
113
|
+
const cachedTokens = Math.min(Math.max(0, usage.cachedContentTokenCount ?? 0), prompt);
|
|
114
|
+
const inputTokens = prompt - cachedTokens;
|
|
115
|
+
const billedOutput = billedOutputTokens(candidates, thoughts, usage.totalTokenCount ?? 0, prompt, authType);
|
|
116
|
+
const reasoningTokens = Math.min(thoughts, billedOutput);
|
|
117
|
+
const outputTokens = billedOutput - reasoningTokens;
|
|
118
|
+
const costUSD = calculateCost(model, inputTokens, billedOutput, 0, cachedTokens, 0);
|
|
119
|
+
yield {
|
|
120
|
+
provider: 'qwen',
|
|
121
|
+
model,
|
|
122
|
+
inputTokens,
|
|
123
|
+
outputTokens,
|
|
124
|
+
cacheCreationInputTokens: 0,
|
|
125
|
+
cacheReadInputTokens: cachedTokens,
|
|
126
|
+
cachedInputTokens: cachedTokens,
|
|
127
|
+
reasoningTokens,
|
|
128
|
+
webSearchRequests: 0,
|
|
129
|
+
costUSD,
|
|
130
|
+
tools: [...new Set(tools)],
|
|
131
|
+
bashCommands: [...new Set(bashCommands)],
|
|
132
|
+
timestamp: isoTimestamp(entry.timestamp, fileMtime),
|
|
133
|
+
speed: 'standard',
|
|
134
|
+
deduplicationKey: dedupKey,
|
|
135
|
+
userMessage: pendingUserMessage,
|
|
136
|
+
sessionId: entry.sessionId,
|
|
137
|
+
};
|
|
138
|
+
pendingUserMessage = '';
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export function createQwenProvider(overrideDir) {
|
|
144
|
+
const projectsDir = overrideDir ?? getQwenProjectsDir();
|
|
145
|
+
return {
|
|
146
|
+
name: 'qwen',
|
|
147
|
+
displayName: 'Qwen',
|
|
148
|
+
modelDisplayName(model) {
|
|
149
|
+
return model;
|
|
150
|
+
},
|
|
151
|
+
toolDisplayName(rawTool) {
|
|
152
|
+
return ownValue(toolNameMap, rawTool) ?? rawTool;
|
|
153
|
+
},
|
|
154
|
+
async probeRoots() {
|
|
155
|
+
return [{ path: projectsDir, label: 'projects' }];
|
|
156
|
+
},
|
|
157
|
+
async discoverSessions() {
|
|
158
|
+
const sources = [];
|
|
159
|
+
let projectDirs;
|
|
160
|
+
try {
|
|
161
|
+
projectDirs = await readdir(projectsDir);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
return sources;
|
|
165
|
+
}
|
|
166
|
+
for (const projDir of projectDirs) {
|
|
167
|
+
const chatsDir = join(projectsDir, projDir, 'chats');
|
|
168
|
+
const project = projectNameFromDirName(projDir);
|
|
169
|
+
let chatFiles;
|
|
170
|
+
try {
|
|
171
|
+
chatFiles = await readdir(chatsDir);
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
for (const file of chatFiles) {
|
|
177
|
+
if (!file.endsWith('.jsonl'))
|
|
178
|
+
continue;
|
|
179
|
+
const filePath = join(chatsDir, file);
|
|
180
|
+
const s = await stat(filePath).catch(() => null);
|
|
181
|
+
if (!s?.isFile())
|
|
182
|
+
continue;
|
|
183
|
+
sources.push({ path: filePath, project, provider: 'qwen' });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return sources;
|
|
187
|
+
},
|
|
188
|
+
createSessionParser(source, seenKeys) {
|
|
189
|
+
return createParser(source, seenKeys);
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
export const qwen = createQwenProvider();
|