chompyy 0.4.7 → 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 +40 -6
- package/dist/advice.js +2 -1
- package/dist/agentlimits.js +77 -0
- package/dist/agentusage.js +96 -0
- package/dist/appstate.js +72 -5
- package/dist/away.js +44 -5
- package/dist/blueprint.js +3 -7
- package/dist/board.js +4 -0
- package/dist/cli.js +328 -15
- 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/daytime.js +68 -0
- package/dist/demon.js +20 -0
- package/dist/didwork.js +46 -0
- package/dist/label.js +33 -0
- package/dist/learning.js +35 -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/send.js +46 -20
- package/dist/stamps.js +14 -0
- package/dist/taste.js +67 -7
- package/dist/triggers.js +5 -0
- package/dist/unkeep.js +220 -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 +11 -3
|
@@ -0,0 +1,401 @@
|
|
|
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 { homedir } from 'os';
|
|
4
|
+
import { basename, join } from 'path';
|
|
5
|
+
import { extractBashCommands } from '../bash-utils.js';
|
|
6
|
+
import { readSessionFile } from '../fs-utils.js';
|
|
7
|
+
import { calculateCost, getShortModelName, ownValue } from '../models.js';
|
|
8
|
+
// The Cline CLI (npm `cline`, 3.x) stores sessions in a layout unrelated to the
|
|
9
|
+
// VS Code extension's tasks/ui_messages.json tree that `cline.ts` reads:
|
|
10
|
+
//
|
|
11
|
+
// <sessions>/<sessionId>/<sessionId>.json metadata + rolled-up usage
|
|
12
|
+
// <sessions>/<sessionId>/<sessionId>.messages.json per-message metrics
|
|
13
|
+
//
|
|
14
|
+
// Kept as its own provider rather than a third root on `cline` so the shared
|
|
15
|
+
// Cline-family parser (also serving KiloCode and IBM Bob) stays untouched.
|
|
16
|
+
const PROVIDER_NAME = 'cline-cli';
|
|
17
|
+
const DISPLAY_NAME = 'Cline CLI';
|
|
18
|
+
const MIN_REASONABLE_TIMESTAMP_MS = 1_000_000_000_000;
|
|
19
|
+
// Mirrors the CLI's own resolution chain, each level individually overridable:
|
|
20
|
+
// sessions := CLINE_SESSION_DATA_DIR ?? <data>/sessions
|
|
21
|
+
// data := CLINE_DATA_DIR ?? <root>/data
|
|
22
|
+
// root := CLINE_DIR ?? ~/.cline
|
|
23
|
+
function clineRootDir() {
|
|
24
|
+
return process.env['CLINE_DIR']?.trim() || join(homedir(), '.cline');
|
|
25
|
+
}
|
|
26
|
+
function clineDataDir() {
|
|
27
|
+
return process.env['CLINE_DATA_DIR']?.trim() || join(clineRootDir(), 'data');
|
|
28
|
+
}
|
|
29
|
+
export function getClineCliSessionsDir() {
|
|
30
|
+
return process.env['CLINE_SESSION_DATA_DIR']?.trim() || join(clineDataDir(), 'sessions');
|
|
31
|
+
}
|
|
32
|
+
const toolNameMap = {
|
|
33
|
+
run_commands: 'Bash',
|
|
34
|
+
read_files: 'Read',
|
|
35
|
+
editor: 'Edit',
|
|
36
|
+
apply_patch: 'Edit',
|
|
37
|
+
search_codebase: 'Grep',
|
|
38
|
+
fetch_web_content: 'WebFetch',
|
|
39
|
+
skills: 'Skill',
|
|
40
|
+
spawn_agent: 'Agent',
|
|
41
|
+
team_spawn_teammate: 'Agent',
|
|
42
|
+
team_run_task: 'Agent',
|
|
43
|
+
ask_question: 'AskUser',
|
|
44
|
+
};
|
|
45
|
+
function mapToolName(rawTool) {
|
|
46
|
+
return ownValue(toolNameMap, rawTool) ?? rawTool;
|
|
47
|
+
}
|
|
48
|
+
function isRecord(value) {
|
|
49
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
50
|
+
}
|
|
51
|
+
function nonEmptyString(value) {
|
|
52
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
53
|
+
}
|
|
54
|
+
function safeNonNegativeNumber(value) {
|
|
55
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
56
|
+
}
|
|
57
|
+
function safeTokenCount(value) {
|
|
58
|
+
return Math.floor(Math.min(safeNonNegativeNumber(value), Number.MAX_SAFE_INTEGER));
|
|
59
|
+
}
|
|
60
|
+
// A cost counts as metered only when it is actually present and non-negative.
|
|
61
|
+
// `0` is a legitimate metered value (a free/cached call) and must stay reported,
|
|
62
|
+
// so this is a presence check, not a truthiness check.
|
|
63
|
+
function isReportedCost(value) {
|
|
64
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
65
|
+
}
|
|
66
|
+
function parseMetrics(value) {
|
|
67
|
+
if (!isRecord(value))
|
|
68
|
+
return null;
|
|
69
|
+
const cacheReadTokens = safeTokenCount(value['cacheReadTokens']);
|
|
70
|
+
const cacheWriteTokens = safeTokenCount(value['cacheWriteTokens']);
|
|
71
|
+
const metrics = {
|
|
72
|
+
// Cline's inputTokens is the full prompt, cache read and write included
|
|
73
|
+
// (its own pricing bills max(0, input - cacheRead - cacheWrite) at the input rate).
|
|
74
|
+
inputTokens: Math.max(0, safeTokenCount(value['inputTokens']) - cacheReadTokens - cacheWriteTokens),
|
|
75
|
+
outputTokens: safeTokenCount(value['outputTokens']),
|
|
76
|
+
cacheReadTokens,
|
|
77
|
+
cacheWriteTokens,
|
|
78
|
+
cost: safeNonNegativeNumber(value['cost']),
|
|
79
|
+
// A negative cost is not a credit we can represent — treat it as absent and
|
|
80
|
+
// fall back to token pricing, rather than reporting a clamped $0 as metered.
|
|
81
|
+
costReported: isReportedCost(value['cost']),
|
|
82
|
+
};
|
|
83
|
+
const hasTokens = metrics.inputTokens > 0 || metrics.outputTokens > 0
|
|
84
|
+
|| metrics.cacheReadTokens > 0 || metrics.cacheWriteTokens > 0;
|
|
85
|
+
return hasTokens || metrics.cost > 0 ? metrics : null;
|
|
86
|
+
}
|
|
87
|
+
function projectName(workspace) {
|
|
88
|
+
if (!workspace)
|
|
89
|
+
return DISPLAY_NAME;
|
|
90
|
+
const parts = workspace.replace(/[\\/]+$/, '').split(/[\\/]/).filter(Boolean);
|
|
91
|
+
return parts.at(-1) ?? DISPLAY_NAME;
|
|
92
|
+
}
|
|
93
|
+
function isoTimestamp(value, fallback) {
|
|
94
|
+
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
|
|
95
|
+
// The CLI writes epoch milliseconds, but a seconds-resolution value would
|
|
96
|
+
// otherwise silently land in 1970. Promote it and reject what stays
|
|
97
|
+
// implausible, matching the guard kiro.ts uses on the same hazard.
|
|
98
|
+
const ms = value < MIN_REASONABLE_TIMESTAMP_MS ? value * 1000 : value;
|
|
99
|
+
const date = new Date(ms);
|
|
100
|
+
if (!Number.isNaN(date.getTime()) && date.getTime() >= MIN_REASONABLE_TIMESTAMP_MS) {
|
|
101
|
+
return date.toISOString();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const parsed = nonEmptyString(value);
|
|
105
|
+
if (parsed) {
|
|
106
|
+
const date = new Date(parsed);
|
|
107
|
+
if (!Number.isNaN(date.getTime()))
|
|
108
|
+
return date.toISOString();
|
|
109
|
+
}
|
|
110
|
+
return fallback;
|
|
111
|
+
}
|
|
112
|
+
// `run_commands` carries its commands as a JSON-encoded array in a string
|
|
113
|
+
// field; anything else is treated as a single command line.
|
|
114
|
+
function commandsFrom(input) {
|
|
115
|
+
if (!isRecord(input))
|
|
116
|
+
return [];
|
|
117
|
+
const raw = input['commands'] ?? input['command'];
|
|
118
|
+
if (Array.isArray(raw))
|
|
119
|
+
return raw.filter((c) => typeof c === 'string');
|
|
120
|
+
const text = nonEmptyString(raw);
|
|
121
|
+
if (!text)
|
|
122
|
+
return [];
|
|
123
|
+
if (text.startsWith('[')) {
|
|
124
|
+
try {
|
|
125
|
+
const parsed = JSON.parse(text);
|
|
126
|
+
if (Array.isArray(parsed))
|
|
127
|
+
return parsed.filter((c) => typeof c === 'string');
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Not JSON after all - fall through and treat the whole string as one command.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return [text];
|
|
134
|
+
}
|
|
135
|
+
function firstString(input, keys) {
|
|
136
|
+
if (!isRecord(input))
|
|
137
|
+
return undefined;
|
|
138
|
+
for (const key of keys) {
|
|
139
|
+
const value = nonEmptyString(input[key]);
|
|
140
|
+
if (value)
|
|
141
|
+
return value;
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
function collectTools(content) {
|
|
146
|
+
const collected = {
|
|
147
|
+
tools: [], bashCommands: [], toolSequence: [], skills: [], subagentTypes: [], webSearchRequests: 0,
|
|
148
|
+
};
|
|
149
|
+
if (!Array.isArray(content))
|
|
150
|
+
return collected;
|
|
151
|
+
const turnTools = [];
|
|
152
|
+
for (const block of content) {
|
|
153
|
+
if (!isRecord(block) || block['type'] !== 'tool_use')
|
|
154
|
+
continue;
|
|
155
|
+
const rawName = nonEmptyString(block['name']);
|
|
156
|
+
if (!rawName)
|
|
157
|
+
continue;
|
|
158
|
+
const mapped = mapToolName(rawName);
|
|
159
|
+
const input = block['input'];
|
|
160
|
+
const toolCall = { tool: mapped };
|
|
161
|
+
const file = firstString(input, ['path', 'file_path', 'paths', 'file']);
|
|
162
|
+
if (file)
|
|
163
|
+
toolCall.file = file;
|
|
164
|
+
if (mapped === 'Bash') {
|
|
165
|
+
const commands = commandsFrom(input);
|
|
166
|
+
const [first] = commands;
|
|
167
|
+
if (first)
|
|
168
|
+
toolCall.command = first;
|
|
169
|
+
for (const command of commands)
|
|
170
|
+
collected.bashCommands.push(...extractBashCommands(command));
|
|
171
|
+
}
|
|
172
|
+
if (mapped === 'Skill') {
|
|
173
|
+
const skill = firstString(input, ['name', 'skill', 'skill_name']);
|
|
174
|
+
if (skill)
|
|
175
|
+
collected.skills.push(skill);
|
|
176
|
+
}
|
|
177
|
+
if (mapped === 'Agent') {
|
|
178
|
+
const subagentType = firstString(input, ['agent', 'agent_type', 'type', 'name']);
|
|
179
|
+
if (subagentType)
|
|
180
|
+
collected.subagentTypes.push(subagentType);
|
|
181
|
+
}
|
|
182
|
+
if (mapped === 'WebFetch')
|
|
183
|
+
collected.webSearchRequests++;
|
|
184
|
+
collected.tools.push(mapped);
|
|
185
|
+
turnTools.push(toolCall);
|
|
186
|
+
}
|
|
187
|
+
if (turnTools.length > 0)
|
|
188
|
+
collected.toolSequence.push(turnTools);
|
|
189
|
+
return collected;
|
|
190
|
+
}
|
|
191
|
+
function textFromContent(content) {
|
|
192
|
+
if (typeof content === 'string')
|
|
193
|
+
return content;
|
|
194
|
+
if (!Array.isArray(content))
|
|
195
|
+
return '';
|
|
196
|
+
for (const block of content) {
|
|
197
|
+
if (!isRecord(block) || block['type'] !== 'text')
|
|
198
|
+
continue;
|
|
199
|
+
const text = nonEmptyString(block['text']);
|
|
200
|
+
if (text)
|
|
201
|
+
return text;
|
|
202
|
+
}
|
|
203
|
+
return '';
|
|
204
|
+
}
|
|
205
|
+
function firstUserMessage(messages) {
|
|
206
|
+
for (const message of messages) {
|
|
207
|
+
if (!isRecord(message) || message['role'] !== 'user')
|
|
208
|
+
continue;
|
|
209
|
+
const text = textFromContent(message['content']);
|
|
210
|
+
// Tool results come back as role:user too; they carry no text block.
|
|
211
|
+
if (text)
|
|
212
|
+
return text;
|
|
213
|
+
}
|
|
214
|
+
return '';
|
|
215
|
+
}
|
|
216
|
+
async function readJson(path) {
|
|
217
|
+
const raw = await readSessionFile(path);
|
|
218
|
+
if (raw === null)
|
|
219
|
+
return null;
|
|
220
|
+
try {
|
|
221
|
+
return JSON.parse(raw);
|
|
222
|
+
}
|
|
223
|
+
catch {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function createParser(source, seenKeys) {
|
|
228
|
+
return {
|
|
229
|
+
async *parse() {
|
|
230
|
+
// `source.path` is the growing `<sessionId>.messages.json` file (see
|
|
231
|
+
// `discoverSessions` / review finding C-G1) — the static per-session
|
|
232
|
+
// metadata lives in the sibling `<sessionId>.json`, read below.
|
|
233
|
+
const metaPath = source.path.replace(/\.messages\.json$/, '.json');
|
|
234
|
+
const meta = await readJson(metaPath);
|
|
235
|
+
if (!isRecord(meta))
|
|
236
|
+
return;
|
|
237
|
+
const sessionId = nonEmptyString(meta['session_id']) ?? basename(metaPath).replace(/\.json$/, '');
|
|
238
|
+
const metadata = isRecord(meta['metadata']) ? meta['metadata'] : {};
|
|
239
|
+
const workspace = nonEmptyString(meta['workspace_root']) ?? nonEmptyString(meta['cwd']);
|
|
240
|
+
const sessionModel = nonEmptyString(meta['model']) ?? 'unknown';
|
|
241
|
+
const startedAt = isoTimestamp(meta['started_at'], new Date(0).toISOString());
|
|
242
|
+
// Always populated by discoverSessions; projectName falls back to the
|
|
243
|
+
// display name, so there is nothing left to default to here.
|
|
244
|
+
const project = source.project;
|
|
245
|
+
// Prefer the co-located messages file (source.path itself) over a
|
|
246
|
+
// recorded absolute path, which is stale once a session directory is
|
|
247
|
+
// copied between machines.
|
|
248
|
+
let doc = await readJson(source.path);
|
|
249
|
+
if (!isRecord(doc)) {
|
|
250
|
+
const recorded = nonEmptyString(meta['messages_path']);
|
|
251
|
+
if (recorded)
|
|
252
|
+
doc = await readJson(recorded);
|
|
253
|
+
}
|
|
254
|
+
const messages = isRecord(doc) && Array.isArray(doc['messages']) ? doc['messages'] : [];
|
|
255
|
+
const userMessage = firstUserMessage(messages);
|
|
256
|
+
// Whether the session carried any per-message metrics at all. Set before
|
|
257
|
+
// the dedup check below so a session whose calls were all deduped (e.g. a
|
|
258
|
+
// duplicated session directory reusing a session_id) still declines the
|
|
259
|
+
// rollup fallback rather than double-counting its cost through it.
|
|
260
|
+
let hadMetrics = false;
|
|
261
|
+
for (const [index, message] of messages.entries()) {
|
|
262
|
+
if (!isRecord(message) || message['role'] !== 'assistant')
|
|
263
|
+
continue;
|
|
264
|
+
const metrics = parseMetrics(message['metrics']);
|
|
265
|
+
if (!metrics)
|
|
266
|
+
continue;
|
|
267
|
+
hadMetrics = true;
|
|
268
|
+
const modelInfo = isRecord(message['modelInfo']) ? message['modelInfo'] : {};
|
|
269
|
+
const model = nonEmptyString(modelInfo['id']) ?? sessionModel;
|
|
270
|
+
const messageId = nonEmptyString(message['id']) ?? String(index);
|
|
271
|
+
const deduplicationKey = `${PROVIDER_NAME}:${sessionId}:${messageId}`;
|
|
272
|
+
if (seenKeys.has(deduplicationKey))
|
|
273
|
+
continue;
|
|
274
|
+
seenKeys.add(deduplicationKey);
|
|
275
|
+
const { tools, bashCommands, toolSequence, skills, subagentTypes, webSearchRequests } = collectTools(message['content']);
|
|
276
|
+
yield {
|
|
277
|
+
provider: PROVIDER_NAME,
|
|
278
|
+
model,
|
|
279
|
+
inputTokens: metrics.inputTokens,
|
|
280
|
+
outputTokens: metrics.outputTokens,
|
|
281
|
+
cacheCreationInputTokens: metrics.cacheWriteTokens,
|
|
282
|
+
cacheReadInputTokens: metrics.cacheReadTokens,
|
|
283
|
+
cachedInputTokens: 0,
|
|
284
|
+
reasoningTokens: 0,
|
|
285
|
+
webSearchRequests,
|
|
286
|
+
costUSD: metrics.costReported
|
|
287
|
+
? metrics.cost
|
|
288
|
+
: calculateCost(model, metrics.inputTokens, metrics.outputTokens, metrics.cacheWriteTokens, metrics.cacheReadTokens, 0),
|
|
289
|
+
costIsEstimated: !metrics.costReported,
|
|
290
|
+
tools,
|
|
291
|
+
bashCommands,
|
|
292
|
+
skills: skills.length > 0 ? skills : undefined,
|
|
293
|
+
subagentTypes: subagentTypes.length > 0 ? subagentTypes : undefined,
|
|
294
|
+
timestamp: isoTimestamp(message['ts'], startedAt),
|
|
295
|
+
speed: 'standard',
|
|
296
|
+
deduplicationKey,
|
|
297
|
+
turnId: `${sessionId}:${messageId}`,
|
|
298
|
+
toolSequence: toolSequence.length > 0 ? toolSequence : undefined,
|
|
299
|
+
userMessage,
|
|
300
|
+
sessionId,
|
|
301
|
+
project,
|
|
302
|
+
projectPath: workspace,
|
|
303
|
+
workingDirectory: nonEmptyString(meta['cwd']),
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
if (hadMetrics)
|
|
307
|
+
return;
|
|
308
|
+
// No per-message metrics: fall back to the session rollup so an
|
|
309
|
+
// interrupted or older session still reports its spend. Deliberately
|
|
310
|
+
// reads `usage` and not `aggregateUsage`, which folds in spawned
|
|
311
|
+
// subagents that are themselves separate session directories.
|
|
312
|
+
const rollup = parseMetrics(isRecord(metadata['usage']) ? metadata['usage'] : null);
|
|
313
|
+
if (!rollup)
|
|
314
|
+
return;
|
|
315
|
+
const deduplicationKey = `${PROVIDER_NAME}:${sessionId}:rollup`;
|
|
316
|
+
if (seenKeys.has(deduplicationKey))
|
|
317
|
+
return;
|
|
318
|
+
seenKeys.add(deduplicationKey);
|
|
319
|
+
// Same presence-not-truthiness rule as the per-message path: a metered
|
|
320
|
+
// $0 rollup stays reported instead of being re-estimated from tokens.
|
|
321
|
+
const rawRollupCost = (isRecord(metadata['usage']) ? metadata['usage']['totalCost'] : undefined)
|
|
322
|
+
?? metadata['totalCost'];
|
|
323
|
+
const rollupCostReported = isReportedCost(rawRollupCost);
|
|
324
|
+
const rollupCost = safeNonNegativeNumber(rawRollupCost);
|
|
325
|
+
yield {
|
|
326
|
+
provider: PROVIDER_NAME,
|
|
327
|
+
model: sessionModel,
|
|
328
|
+
inputTokens: rollup.inputTokens,
|
|
329
|
+
outputTokens: rollup.outputTokens,
|
|
330
|
+
cacheCreationInputTokens: rollup.cacheWriteTokens,
|
|
331
|
+
cacheReadInputTokens: rollup.cacheReadTokens,
|
|
332
|
+
cachedInputTokens: 0,
|
|
333
|
+
reasoningTokens: 0,
|
|
334
|
+
webSearchRequests: 0,
|
|
335
|
+
costUSD: rollupCostReported
|
|
336
|
+
? rollupCost
|
|
337
|
+
: calculateCost(sessionModel, rollup.inputTokens, rollup.outputTokens, rollup.cacheWriteTokens, rollup.cacheReadTokens, 0),
|
|
338
|
+
costIsEstimated: !rollupCostReported,
|
|
339
|
+
tools: [],
|
|
340
|
+
bashCommands: [],
|
|
341
|
+
timestamp: isoTimestamp(meta['ended_at'], startedAt),
|
|
342
|
+
speed: 'standard',
|
|
343
|
+
deduplicationKey,
|
|
344
|
+
turnId: `${sessionId}:rollup`,
|
|
345
|
+
userMessage,
|
|
346
|
+
sessionId,
|
|
347
|
+
project,
|
|
348
|
+
projectPath: workspace,
|
|
349
|
+
workingDirectory: nonEmptyString(meta['cwd']),
|
|
350
|
+
};
|
|
351
|
+
},
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
export function createClineCliProvider(overrideDir) {
|
|
355
|
+
const sessionsDir = () => overrideDir ?? getClineCliSessionsDir();
|
|
356
|
+
return {
|
|
357
|
+
name: PROVIDER_NAME,
|
|
358
|
+
displayName: DISPLAY_NAME,
|
|
359
|
+
modelDisplayName(model) {
|
|
360
|
+
return getShortModelName(model);
|
|
361
|
+
},
|
|
362
|
+
toolDisplayName(rawTool) {
|
|
363
|
+
return mapToolName(rawTool);
|
|
364
|
+
},
|
|
365
|
+
async probeRoots() {
|
|
366
|
+
return [{ path: sessionsDir(), label: 'Cline CLI sessions' }];
|
|
367
|
+
},
|
|
368
|
+
async discoverSessions() {
|
|
369
|
+
const dir = sessionsDir();
|
|
370
|
+
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
371
|
+
const sources = [];
|
|
372
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
373
|
+
if (!entry.isDirectory())
|
|
374
|
+
continue;
|
|
375
|
+
const sessionId = entry.name;
|
|
376
|
+
const metaPath = join(dir, sessionId, `${sessionId}.json`);
|
|
377
|
+
const meta = await readJson(metaPath);
|
|
378
|
+
if (!isRecord(meta))
|
|
379
|
+
continue;
|
|
380
|
+
// Fingerprint the sibling that actually accumulates new turns, not
|
|
381
|
+
// the metadata file written once at session start — a live session's
|
|
382
|
+
// corpus fingerprint must move as new turns append, or a menubar
|
|
383
|
+
// poll can serve the pre-activity snapshot forever (review finding
|
|
384
|
+
// C-G1). `computeCorpusFingerprint` degrades this to "contributes
|
|
385
|
+
// nothing yet" if the messages file doesn't exist (a session with no
|
|
386
|
+
// turns), the same as any other missing/not-yet-created file.
|
|
387
|
+
const workspace = nonEmptyString(meta['workspace_root']) ?? nonEmptyString(meta['cwd']);
|
|
388
|
+
sources.push({
|
|
389
|
+
path: join(dir, sessionId, `${sessionId}.messages.json`),
|
|
390
|
+
project: projectName(workspace),
|
|
391
|
+
provider: PROVIDER_NAME,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
return sources;
|
|
395
|
+
},
|
|
396
|
+
createSessionParser(source, seenKeys) {
|
|
397
|
+
return createParser(source, seenKeys);
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
export const clineCli = createClineCliProvider();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { stat } from 'fs/promises';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { basename, dirname, join } from 'path';
|
|
5
|
+
import { discoverClineTasks, createClineParser, clineTaskRoots } from './vscode-cline-parser.js';
|
|
6
|
+
const EXTENSION_ID = 'saoudrizwan.claude-dev';
|
|
7
|
+
export function getClineDataPath() {
|
|
8
|
+
return join(homedir(), '.cline', 'data');
|
|
9
|
+
}
|
|
10
|
+
function normalizeOverrideDirs(overrideDirs) {
|
|
11
|
+
if (overrideDirs === undefined)
|
|
12
|
+
return undefined;
|
|
13
|
+
// Cline has several default roots, so tests and future callers can override one or all.
|
|
14
|
+
return Array.isArray(overrideDirs) ? overrideDirs : [overrideDirs];
|
|
15
|
+
}
|
|
16
|
+
async function dedupeTaskSources(sources) {
|
|
17
|
+
const candidates = await Promise.all(sources.map(async (source) => ({
|
|
18
|
+
source,
|
|
19
|
+
mtimeMs: (await stat(source.path).catch(() => null))?.mtimeMs ?? 0,
|
|
20
|
+
})));
|
|
21
|
+
const seenTaskIds = new Set();
|
|
22
|
+
const deduped = [];
|
|
23
|
+
for (const { source } of candidates.sort((a, b) => b.mtimeMs - a.mtimeMs)) {
|
|
24
|
+
const taskId = basename(dirname(source.path));
|
|
25
|
+
if (seenTaskIds.has(taskId))
|
|
26
|
+
continue;
|
|
27
|
+
seenTaskIds.add(taskId);
|
|
28
|
+
deduped.push(source);
|
|
29
|
+
}
|
|
30
|
+
return deduped;
|
|
31
|
+
}
|
|
32
|
+
export function createClineProvider(overrideDirs) {
|
|
33
|
+
const configuredDirs = normalizeOverrideDirs(overrideDirs);
|
|
34
|
+
// Cline may be installed in any VS Code variant (stable, Insiders, VSCodium),
|
|
35
|
+
// so every globalStorage root is scanned - same as the KiloCode
|
|
36
|
+
// sibling - plus Cline's own home-data root. Shared by discovery and
|
|
37
|
+
// probeRoots so doctor can never report a root discovery does not read.
|
|
38
|
+
const taskRoots = () => configuredDirs ?? [
|
|
39
|
+
...clineTaskRoots(EXTENSION_ID),
|
|
40
|
+
getClineDataPath(),
|
|
41
|
+
];
|
|
42
|
+
return {
|
|
43
|
+
name: 'cline',
|
|
44
|
+
displayName: 'Cline',
|
|
45
|
+
modelDisplayName(model) {
|
|
46
|
+
return model;
|
|
47
|
+
},
|
|
48
|
+
toolDisplayName(rawTool) {
|
|
49
|
+
return rawTool;
|
|
50
|
+
},
|
|
51
|
+
async probeRoots() {
|
|
52
|
+
return taskRoots().map(path => ({ path, label: 'tasks' }));
|
|
53
|
+
},
|
|
54
|
+
async discoverSessions() {
|
|
55
|
+
const baseDirs = taskRoots();
|
|
56
|
+
return dedupeTaskSources(await discoverClineTasks(EXTENSION_ID, 'cline', 'Cline', baseDirs));
|
|
57
|
+
},
|
|
58
|
+
createSessionParser(source, seenKeys) {
|
|
59
|
+
return createClineParser(source, seenKeys, 'cline');
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export const cline = createClineProvider();
|