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,245 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { extractBashCommands } from '../bash-utils.js';
|
|
6
|
+
import { calculateCost } from '../models.js';
|
|
7
|
+
import { getSqliteLoadError, isSqliteAvailable, openDatabase } from '../sqlite.js';
|
|
8
|
+
const DEFAULT_DB_PATH = join(homedir(), '.forge', '.forge.db');
|
|
9
|
+
function validateSchema(db) {
|
|
10
|
+
try {
|
|
11
|
+
db.query('SELECT conversation_id, title, CAST(workspace_id AS TEXT) AS workspace_id, context, created_at, updated_at FROM conversations LIMIT 1');
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function sqliteTimestampToIso(value) {
|
|
19
|
+
if (!value)
|
|
20
|
+
return new Date(0).toISOString();
|
|
21
|
+
const match = value.match(/^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2}:\d{2})(?:\.(\d+))?$/);
|
|
22
|
+
if (match) {
|
|
23
|
+
const ms = (match[3] ?? '').padEnd(3, '0').slice(0, 3);
|
|
24
|
+
const parsed = new Date(`${match[1]}T${match[2]}.${ms}Z`);
|
|
25
|
+
if (!Number.isNaN(parsed.getTime()))
|
|
26
|
+
return parsed.toISOString();
|
|
27
|
+
}
|
|
28
|
+
const parsed = new Date(value);
|
|
29
|
+
return Number.isNaN(parsed.getTime()) ? new Date(0).toISOString() : parsed.toISOString();
|
|
30
|
+
}
|
|
31
|
+
function actual(value) {
|
|
32
|
+
if (!value || typeof value !== 'object')
|
|
33
|
+
return 0;
|
|
34
|
+
const raw = value['actual'];
|
|
35
|
+
return typeof raw === 'number' && Number.isFinite(raw) ? raw : 0;
|
|
36
|
+
}
|
|
37
|
+
function usageActual(usage, key) {
|
|
38
|
+
if (!usage || typeof usage !== 'object')
|
|
39
|
+
return 0;
|
|
40
|
+
return actual(usage[key]);
|
|
41
|
+
}
|
|
42
|
+
function mapToolName(name) {
|
|
43
|
+
switch (name) {
|
|
44
|
+
case 'shell':
|
|
45
|
+
case 'bash':
|
|
46
|
+
return 'Bash';
|
|
47
|
+
case 'read':
|
|
48
|
+
case 'Read':
|
|
49
|
+
return 'Read';
|
|
50
|
+
case 'write':
|
|
51
|
+
case 'Write':
|
|
52
|
+
return 'Write';
|
|
53
|
+
case 'patch':
|
|
54
|
+
case 'Edit':
|
|
55
|
+
case 'edit':
|
|
56
|
+
return 'Edit';
|
|
57
|
+
case 'fs_search':
|
|
58
|
+
case 'grep':
|
|
59
|
+
return 'Grep';
|
|
60
|
+
case 'task':
|
|
61
|
+
case 'dispatch_agent':
|
|
62
|
+
return 'Agent';
|
|
63
|
+
default:
|
|
64
|
+
return name;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function pushUnique(values, value) {
|
|
68
|
+
if (!values.includes(value))
|
|
69
|
+
values.push(value);
|
|
70
|
+
}
|
|
71
|
+
function toolCalls(value) {
|
|
72
|
+
return Array.isArray(value) ? value.filter(v => v && typeof v === 'object') : [];
|
|
73
|
+
}
|
|
74
|
+
function extractToolsAndCommands(calls) {
|
|
75
|
+
const tools = [];
|
|
76
|
+
const bashCommands = [];
|
|
77
|
+
let firstCallId;
|
|
78
|
+
for (const call of calls) {
|
|
79
|
+
const rawName = call['name'];
|
|
80
|
+
if (typeof rawName !== 'string')
|
|
81
|
+
continue;
|
|
82
|
+
if (!firstCallId && typeof call['call_id'] === 'string')
|
|
83
|
+
firstCallId = call['call_id'];
|
|
84
|
+
const tool = mapToolName(rawName);
|
|
85
|
+
pushUnique(tools, tool);
|
|
86
|
+
if (tool === 'Bash') {
|
|
87
|
+
const args = call['arguments'];
|
|
88
|
+
if (args && typeof args === 'object') {
|
|
89
|
+
const command = args['command'];
|
|
90
|
+
if (typeof command === 'string') {
|
|
91
|
+
for (const cmd of extractBashCommands(command))
|
|
92
|
+
pushUnique(bashCommands, cmd);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return { tools, bashCommands, firstCallId };
|
|
98
|
+
}
|
|
99
|
+
function splitSourcePath(path) {
|
|
100
|
+
const idx = path.lastIndexOf(':');
|
|
101
|
+
if (idx < 0)
|
|
102
|
+
return null;
|
|
103
|
+
return { dbPath: path.slice(0, idx), conversationId: path.slice(idx + 1) };
|
|
104
|
+
}
|
|
105
|
+
function createParser(source, seenKeys) {
|
|
106
|
+
return {
|
|
107
|
+
async *parse() {
|
|
108
|
+
if (!isSqliteAvailable()) {
|
|
109
|
+
process.stderr.write(getSqliteLoadError() + '\n');
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const split = splitSourcePath(source.path);
|
|
113
|
+
if (!split)
|
|
114
|
+
return;
|
|
115
|
+
let db;
|
|
116
|
+
try {
|
|
117
|
+
db = openDatabase(split.dbPath);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
if (!validateSchema(db))
|
|
124
|
+
return;
|
|
125
|
+
const rows = db.query(`SELECT conversation_id, title, CAST(workspace_id AS TEXT) AS workspace_id, context, created_at, updated_at
|
|
126
|
+
FROM conversations
|
|
127
|
+
WHERE conversation_id = ?`, [split.conversationId]);
|
|
128
|
+
const row = rows[0];
|
|
129
|
+
if (!row?.context)
|
|
130
|
+
return;
|
|
131
|
+
let parsed;
|
|
132
|
+
try {
|
|
133
|
+
parsed = JSON.parse(row.context);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const messages = Array.isArray(parsed.messages)
|
|
139
|
+
? parsed.messages
|
|
140
|
+
: [];
|
|
141
|
+
let userMessage = '';
|
|
142
|
+
for (let i = 0; i < messages.length; i++) {
|
|
143
|
+
const text = messages[i]?.message?.text;
|
|
144
|
+
const role = typeof text?.role === 'string' ? text.role.toLowerCase() : '';
|
|
145
|
+
const content = typeof text?.content === 'string' ? text.content : '';
|
|
146
|
+
if (role === 'user') {
|
|
147
|
+
userMessage = content.length > 500 ? content.slice(0, 500) : content;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (role !== 'assistant')
|
|
151
|
+
continue;
|
|
152
|
+
const promptTokens = usageActual(messages[i]?.usage, 'prompt_tokens');
|
|
153
|
+
const outputTokens = usageActual(messages[i]?.usage, 'completion_tokens');
|
|
154
|
+
const cachedInputTokens = usageActual(messages[i]?.usage, 'cached_tokens');
|
|
155
|
+
const inputTokens = Math.max(0, promptTokens - cachedInputTokens);
|
|
156
|
+
if (inputTokens === 0 && outputTokens === 0)
|
|
157
|
+
continue;
|
|
158
|
+
const model = typeof text?.model === 'string' ? text.model : 'unknown';
|
|
159
|
+
const calls = toolCalls(text?.tool_calls);
|
|
160
|
+
const { tools, bashCommands, firstCallId } = extractToolsAndCommands(calls);
|
|
161
|
+
const stableId = firstCallId ?? `${model}:${promptTokens}:${outputTokens}:${i}`;
|
|
162
|
+
const deduplicationKey = `forge:${row.conversation_id}:${stableId}`;
|
|
163
|
+
if (seenKeys.has(deduplicationKey))
|
|
164
|
+
continue;
|
|
165
|
+
seenKeys.add(deduplicationKey);
|
|
166
|
+
yield {
|
|
167
|
+
provider: 'forge',
|
|
168
|
+
model,
|
|
169
|
+
inputTokens,
|
|
170
|
+
outputTokens,
|
|
171
|
+
cacheCreationInputTokens: 0,
|
|
172
|
+
cacheReadInputTokens: cachedInputTokens,
|
|
173
|
+
cachedInputTokens,
|
|
174
|
+
reasoningTokens: 0,
|
|
175
|
+
webSearchRequests: 0,
|
|
176
|
+
costUSD: calculateCost(model, inputTokens, outputTokens, 0, cachedInputTokens, 0),
|
|
177
|
+
tools,
|
|
178
|
+
bashCommands,
|
|
179
|
+
timestamp: sqliteTimestampToIso(row.updated_at ?? row.created_at),
|
|
180
|
+
speed: 'standard',
|
|
181
|
+
deduplicationKey,
|
|
182
|
+
userMessage,
|
|
183
|
+
sessionId: row.conversation_id,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
db.close();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
async function discoverFromDb(dbPath) {
|
|
194
|
+
if (!existsSync(dbPath))
|
|
195
|
+
return [];
|
|
196
|
+
let db;
|
|
197
|
+
try {
|
|
198
|
+
db = openDatabase(dbPath);
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
if (!validateSchema(db))
|
|
205
|
+
return [];
|
|
206
|
+
const rows = db.query(`SELECT conversation_id, title, CAST(workspace_id AS TEXT) AS workspace_id
|
|
207
|
+
FROM conversations
|
|
208
|
+
WHERE context IS NOT NULL`);
|
|
209
|
+
return rows.map(row => ({
|
|
210
|
+
path: `${dbPath}:${row.conversation_id}`,
|
|
211
|
+
project: row.title ?? String(row.workspace_id),
|
|
212
|
+
provider: 'forge',
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
finally {
|
|
219
|
+
db.close();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
export function createForgeProvider(dbPath = DEFAULT_DB_PATH) {
|
|
223
|
+
return {
|
|
224
|
+
name: 'forge',
|
|
225
|
+
displayName: 'Forge',
|
|
226
|
+
modelDisplayName(model) {
|
|
227
|
+
return model;
|
|
228
|
+
},
|
|
229
|
+
toolDisplayName(rawTool) {
|
|
230
|
+
return rawTool;
|
|
231
|
+
},
|
|
232
|
+
async probeRoots() {
|
|
233
|
+
return [{ path: dbPath, label: 'db' }];
|
|
234
|
+
},
|
|
235
|
+
async discoverSessions() {
|
|
236
|
+
if (!isSqliteAvailable())
|
|
237
|
+
return [];
|
|
238
|
+
return discoverFromDb(dbPath);
|
|
239
|
+
},
|
|
240
|
+
createSessionParser(source, seenKeys) {
|
|
241
|
+
return createParser(source, seenKeys);
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
export const forge = createForgeProvider();
|
|
@@ -0,0 +1,230 @@
|
|
|
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_file: 'Write',
|
|
11
|
+
edit_file: 'Edit',
|
|
12
|
+
create_file: 'Write',
|
|
13
|
+
delete_file: 'Delete',
|
|
14
|
+
list_dir: 'LS',
|
|
15
|
+
grep_search: 'Grep',
|
|
16
|
+
search_files: 'Grep',
|
|
17
|
+
find_files: 'Glob',
|
|
18
|
+
run_command: 'Bash',
|
|
19
|
+
web_search: 'WebSearch',
|
|
20
|
+
ReadFile: 'Read',
|
|
21
|
+
WriteFile: 'Write',
|
|
22
|
+
EditFile: 'Edit',
|
|
23
|
+
ListDir: 'LS',
|
|
24
|
+
SearchText: 'Grep',
|
|
25
|
+
Shell: 'Bash',
|
|
26
|
+
};
|
|
27
|
+
function parseSession(data, seenKeys) {
|
|
28
|
+
const results = [];
|
|
29
|
+
let lastUserMessage = '';
|
|
30
|
+
let turnOrdinal = 0;
|
|
31
|
+
let currentTurnId = `${data.sessionId}:prelude`;
|
|
32
|
+
let geminiOrdinal = 0;
|
|
33
|
+
for (const msg of data.messages) {
|
|
34
|
+
if (msg.type === 'user') {
|
|
35
|
+
if (Array.isArray(msg.content)) {
|
|
36
|
+
lastUserMessage = msg.content.map(c => c.text).join(' ').slice(0, 500);
|
|
37
|
+
}
|
|
38
|
+
else if (typeof msg.content === 'string') {
|
|
39
|
+
lastUserMessage = msg.content.slice(0, 500);
|
|
40
|
+
}
|
|
41
|
+
currentTurnId = `${data.sessionId}:turn-${turnOrdinal++}`;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (msg.type !== 'gemini' || !msg.tokens || !msg.model)
|
|
45
|
+
continue;
|
|
46
|
+
const t = msg.tokens;
|
|
47
|
+
const totalInput = t.input ?? 0;
|
|
48
|
+
const totalOutput = t.output ?? 0;
|
|
49
|
+
const totalCached = t.cached ?? 0;
|
|
50
|
+
const totalThoughts = t.thoughts ?? 0;
|
|
51
|
+
if (totalInput === 0 && totalOutput === 0 && totalCached === 0 && totalThoughts === 0)
|
|
52
|
+
continue;
|
|
53
|
+
const messageKey = msg.id || `idx-${geminiOrdinal}`;
|
|
54
|
+
geminiOrdinal++;
|
|
55
|
+
const dedupKey = `gemini:${data.sessionId}:${messageKey}`;
|
|
56
|
+
if (seenKeys.has(dedupKey))
|
|
57
|
+
continue;
|
|
58
|
+
const tools = [];
|
|
59
|
+
const bashCommands = [];
|
|
60
|
+
if (msg.toolCalls) {
|
|
61
|
+
for (const tc of msg.toolCalls) {
|
|
62
|
+
const mapped = ownValue(toolNameMap, tc.displayName ?? '') ?? ownValue(toolNameMap, tc.name) ?? tc.displayName ?? tc.name;
|
|
63
|
+
tools.push(mapped);
|
|
64
|
+
if (mapped === 'Bash' && tc.args && typeof tc.args.command === 'string') {
|
|
65
|
+
bashCommands.push(...extractBashCommands(tc.args.command));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Gemini's `input` count includes `cached` tokens as a subset, so fresh
|
|
70
|
+
// input must subtract cached to avoid double-charging at both rates.
|
|
71
|
+
const freshInput = Math.max(0, totalInput - totalCached);
|
|
72
|
+
const tsDate = new Date(msg.timestamp || data.startTime);
|
|
73
|
+
if (isNaN(tsDate.getTime()) || tsDate.getTime() < 1_000_000_000_000)
|
|
74
|
+
continue;
|
|
75
|
+
seenKeys.add(dedupKey);
|
|
76
|
+
// Gemini bills thoughts at the output token rate; calculateCost does not
|
|
77
|
+
// accept a reasoning parameter, so fold thoughts into the output count for
|
|
78
|
+
// pricing while keeping outputTokens / reasoningTokens reported separately.
|
|
79
|
+
const costUSD = calculateCost(msg.model, freshInput, totalOutput + totalThoughts, 0, totalCached, 0);
|
|
80
|
+
results.push({
|
|
81
|
+
provider: 'gemini',
|
|
82
|
+
model: msg.model,
|
|
83
|
+
inputTokens: freshInput,
|
|
84
|
+
outputTokens: totalOutput,
|
|
85
|
+
cacheCreationInputTokens: 0,
|
|
86
|
+
cacheReadInputTokens: totalCached,
|
|
87
|
+
cachedInputTokens: totalCached,
|
|
88
|
+
reasoningTokens: totalThoughts,
|
|
89
|
+
webSearchRequests: 0,
|
|
90
|
+
costUSD,
|
|
91
|
+
tools: [...new Set(tools)],
|
|
92
|
+
bashCommands: [...new Set(bashCommands)],
|
|
93
|
+
timestamp: tsDate.toISOString(),
|
|
94
|
+
speed: 'standard',
|
|
95
|
+
deduplicationKey: dedupKey,
|
|
96
|
+
turnId: currentTurnId,
|
|
97
|
+
userMessage: lastUserMessage,
|
|
98
|
+
sessionId: data.sessionId,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return results;
|
|
102
|
+
}
|
|
103
|
+
function parseJsonl(raw) {
|
|
104
|
+
const lines = raw.split('\n').filter(l => l.trim());
|
|
105
|
+
if (lines.length === 0)
|
|
106
|
+
return null;
|
|
107
|
+
let sessionId = '';
|
|
108
|
+
let startTime = '';
|
|
109
|
+
let projectHash;
|
|
110
|
+
let lastUpdated;
|
|
111
|
+
let kind;
|
|
112
|
+
const messages = [];
|
|
113
|
+
for (const line of lines) {
|
|
114
|
+
let obj;
|
|
115
|
+
try {
|
|
116
|
+
obj = JSON.parse(line);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (obj['$set'] !== undefined)
|
|
122
|
+
continue;
|
|
123
|
+
if (obj['sessionId'] && obj['startTime'] && !sessionId) {
|
|
124
|
+
sessionId = obj['sessionId'];
|
|
125
|
+
startTime = obj['startTime'];
|
|
126
|
+
projectHash = obj['projectHash'];
|
|
127
|
+
lastUpdated = obj['lastUpdated'];
|
|
128
|
+
kind = obj['kind'];
|
|
129
|
+
}
|
|
130
|
+
else if (obj['id'] && obj['type']) {
|
|
131
|
+
messages.push(obj);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!sessionId)
|
|
135
|
+
return null;
|
|
136
|
+
return { sessionId, projectHash, startTime, lastUpdated, kind, messages };
|
|
137
|
+
}
|
|
138
|
+
function createParser(source, seenKeys) {
|
|
139
|
+
return {
|
|
140
|
+
async *parse() {
|
|
141
|
+
const raw = await readSessionFile(source.path);
|
|
142
|
+
if (raw === null)
|
|
143
|
+
return;
|
|
144
|
+
let data = null;
|
|
145
|
+
// Try single JSON first (Gemini CLI <=0.38), then JSONL (>=0.39)
|
|
146
|
+
try {
|
|
147
|
+
const parsed = JSON.parse(raw);
|
|
148
|
+
if (parsed.messages && parsed.sessionId) {
|
|
149
|
+
data = parsed;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch { /* not single JSON */ }
|
|
153
|
+
if (!data) {
|
|
154
|
+
data = parseJsonl(raw);
|
|
155
|
+
}
|
|
156
|
+
if (!data?.messages || !data.sessionId)
|
|
157
|
+
return;
|
|
158
|
+
const calls = parseSession(data, seenKeys);
|
|
159
|
+
for (const call of calls) {
|
|
160
|
+
yield call;
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
export function getGeminiTmpDir() {
|
|
166
|
+
return join(homedir(), '.gemini', 'tmp');
|
|
167
|
+
}
|
|
168
|
+
async function discoverSessions() {
|
|
169
|
+
const sources = [];
|
|
170
|
+
const tmpDir = getGeminiTmpDir();
|
|
171
|
+
let projectDirs;
|
|
172
|
+
try {
|
|
173
|
+
const entries = await readdir(tmpDir, { withFileTypes: true });
|
|
174
|
+
projectDirs = entries.filter(e => e.isDirectory()).map(e => e.name);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
return sources;
|
|
178
|
+
}
|
|
179
|
+
for (const project of projectDirs) {
|
|
180
|
+
const chatsDir = join(tmpDir, project, 'chats');
|
|
181
|
+
let files;
|
|
182
|
+
try {
|
|
183
|
+
const entries = await readdir(chatsDir);
|
|
184
|
+
files = entries.filter(f => f.startsWith('session-') && (f.endsWith('.json') || f.endsWith('.jsonl')));
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
for (const file of files) {
|
|
190
|
+
const filePath = join(chatsDir, file);
|
|
191
|
+
const s = await stat(filePath).catch(() => null);
|
|
192
|
+
if (!s?.isFile())
|
|
193
|
+
continue;
|
|
194
|
+
sources.push({ path: filePath, project, provider: 'gemini' });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return sources;
|
|
198
|
+
}
|
|
199
|
+
export function createGeminiProvider() {
|
|
200
|
+
return {
|
|
201
|
+
name: 'gemini',
|
|
202
|
+
displayName: 'Gemini',
|
|
203
|
+
modelDisplayName(model) {
|
|
204
|
+
if (model === 'gemini-auto')
|
|
205
|
+
return 'Gemini (auto)';
|
|
206
|
+
const display = {
|
|
207
|
+
'gemini-3-flash-preview': 'Gemini 3 Flash',
|
|
208
|
+
'gemini-3.5-flash': 'Gemini 3.5 Flash',
|
|
209
|
+
'gemini-3.1-pro-preview': 'Gemini 3.1 Pro',
|
|
210
|
+
'gemini-2.5-pro': 'Gemini 2.5 Pro',
|
|
211
|
+
'gemini-2.5-flash': 'Gemini 2.5 Flash',
|
|
212
|
+
'gemini-2.0-flash': 'Gemini 2.0 Flash',
|
|
213
|
+
};
|
|
214
|
+
return ownValue(display, model) ?? model;
|
|
215
|
+
},
|
|
216
|
+
toolDisplayName(rawTool) {
|
|
217
|
+
return ownValue(toolNameMap, rawTool) ?? rawTool;
|
|
218
|
+
},
|
|
219
|
+
async probeRoots() {
|
|
220
|
+
return [{ path: getGeminiTmpDir(), label: 'tmp' }];
|
|
221
|
+
},
|
|
222
|
+
async discoverSessions() {
|
|
223
|
+
return discoverSessions();
|
|
224
|
+
},
|
|
225
|
+
createSessionParser(source, seenKeys) {
|
|
226
|
+
return createParser(source, seenKeys);
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
export const gemini = createGeminiProvider();
|