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,217 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { readdir, stat } from 'fs/promises';
|
|
3
|
+
import { basename, dirname, join } from 'path';
|
|
4
|
+
import { homedir, platform } from 'os';
|
|
5
|
+
import { readSessionLines } from '../fs-utils.js';
|
|
6
|
+
import { calculateCost } from '../models.js';
|
|
7
|
+
const PROVIDER_NAME = 'open-design';
|
|
8
|
+
const ENV_DIR = 'CODEBURN_OPEN_DESIGN_DIR';
|
|
9
|
+
const modelDisplayNames = new Map([
|
|
10
|
+
['openai-codex:gpt-5.5', 'GPT-5.5'],
|
|
11
|
+
['glm-5.2', 'GLM-5.2'],
|
|
12
|
+
['GLM-5.2', 'GLM-5.2'],
|
|
13
|
+
]);
|
|
14
|
+
function isRecord(value) {
|
|
15
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
function stringValue(value) {
|
|
18
|
+
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
19
|
+
}
|
|
20
|
+
function tokenValue(value) {
|
|
21
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0;
|
|
22
|
+
}
|
|
23
|
+
function timestampValue(value) {
|
|
24
|
+
const text = stringValue(value);
|
|
25
|
+
if (text)
|
|
26
|
+
return text;
|
|
27
|
+
if (typeof value !== 'number' || !Number.isFinite(value))
|
|
28
|
+
return '';
|
|
29
|
+
const date = new Date(value);
|
|
30
|
+
return Number.isNaN(date.getTime()) ? '' : date.toISOString();
|
|
31
|
+
}
|
|
32
|
+
function parseEvent(line) {
|
|
33
|
+
const text = (typeof line === 'string' ? line : line.toString('utf-8')).trim();
|
|
34
|
+
if (!text)
|
|
35
|
+
return null;
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(text);
|
|
38
|
+
return isRecord(parsed) ? parsed : null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function parseUsage(data) {
|
|
45
|
+
if (!isRecord(data) || data['type'] !== 'usage')
|
|
46
|
+
return null;
|
|
47
|
+
const usage = data['usage'];
|
|
48
|
+
if (!isRecord(usage))
|
|
49
|
+
return null;
|
|
50
|
+
return {
|
|
51
|
+
inputTokens: tokenValue(usage['input_tokens']),
|
|
52
|
+
outputTokens: tokenValue(usage['output_tokens']),
|
|
53
|
+
cacheReadTokens: tokenValue(usage['cached_read_tokens']),
|
|
54
|
+
reasoningTokens: tokenValue(usage['thought_tokens']),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function getOpenDesignDir() {
|
|
58
|
+
const override = process.env[ENV_DIR];
|
|
59
|
+
if (override)
|
|
60
|
+
return override;
|
|
61
|
+
const home = homedir();
|
|
62
|
+
const os = platform();
|
|
63
|
+
if (os === 'darwin') {
|
|
64
|
+
return join(home, 'Library', 'Application Support', 'Open Design');
|
|
65
|
+
}
|
|
66
|
+
if (os === 'win32') {
|
|
67
|
+
return join(process.env['APPDATA'] ?? join(home, 'AppData', 'Roaming'), 'Open Design');
|
|
68
|
+
}
|
|
69
|
+
return join(home, '.config', 'Open Design');
|
|
70
|
+
}
|
|
71
|
+
function namespaceFromDataDir(dataDir) {
|
|
72
|
+
const ns = basename(dirname(dataDir));
|
|
73
|
+
return ns && ns !== 'namespaces' ? ns : PROVIDER_NAME;
|
|
74
|
+
}
|
|
75
|
+
function namespaceFromRunsDir(runsDir) {
|
|
76
|
+
return namespaceFromDataDir(dirname(runsDir));
|
|
77
|
+
}
|
|
78
|
+
async function discoverRunsDir(runsDir, project) {
|
|
79
|
+
const sources = [];
|
|
80
|
+
let runDirs;
|
|
81
|
+
try {
|
|
82
|
+
runDirs = await readdir(runsDir);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return sources;
|
|
86
|
+
}
|
|
87
|
+
for (const runDir of runDirs) {
|
|
88
|
+
const eventsPath = join(runsDir, runDir, 'events.jsonl');
|
|
89
|
+
const s = await stat(eventsPath).catch(() => null);
|
|
90
|
+
if (!s?.isFile())
|
|
91
|
+
continue;
|
|
92
|
+
sources.push({ path: eventsPath, project, provider: PROVIDER_NAME });
|
|
93
|
+
}
|
|
94
|
+
return sources;
|
|
95
|
+
}
|
|
96
|
+
async function discoverNamespacesDir(namespacesDir) {
|
|
97
|
+
const sources = [];
|
|
98
|
+
let namespaces;
|
|
99
|
+
try {
|
|
100
|
+
namespaces = await readdir(namespacesDir);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return sources;
|
|
104
|
+
}
|
|
105
|
+
for (const ns of namespaces) {
|
|
106
|
+
const runsDir = join(namespacesDir, ns, 'data', 'runs');
|
|
107
|
+
sources.push(...await discoverRunsDir(runsDir, ns));
|
|
108
|
+
}
|
|
109
|
+
return sources;
|
|
110
|
+
}
|
|
111
|
+
function dedupeSources(sources) {
|
|
112
|
+
const seen = new Set();
|
|
113
|
+
const out = [];
|
|
114
|
+
for (const source of sources) {
|
|
115
|
+
if (seen.has(source.path))
|
|
116
|
+
continue;
|
|
117
|
+
seen.add(source.path);
|
|
118
|
+
out.push(source);
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
async function discoverOpenDesignSessions(baseDir) {
|
|
123
|
+
const baseName = basename(baseDir);
|
|
124
|
+
if (baseName === 'runs') {
|
|
125
|
+
return discoverRunsDir(baseDir, namespaceFromRunsDir(baseDir));
|
|
126
|
+
}
|
|
127
|
+
if (baseName === 'data') {
|
|
128
|
+
return discoverRunsDir(join(baseDir, 'runs'), namespaceFromDataDir(baseDir));
|
|
129
|
+
}
|
|
130
|
+
const sources = [];
|
|
131
|
+
sources.push(...await discoverRunsDir(join(baseDir, 'data', 'runs'), basename(baseDir) || PROVIDER_NAME));
|
|
132
|
+
sources.push(...await discoverRunsDir(join(baseDir, 'runs'), basename(baseDir) || PROVIDER_NAME));
|
|
133
|
+
sources.push(...await discoverNamespacesDir(baseName === 'namespaces' ? baseDir : join(baseDir, 'namespaces')));
|
|
134
|
+
return dedupeSources(sources);
|
|
135
|
+
}
|
|
136
|
+
function createParser(source, seenKeys) {
|
|
137
|
+
return {
|
|
138
|
+
async *parse() {
|
|
139
|
+
const sessionId = basename(dirname(source.path));
|
|
140
|
+
let currentModel = '';
|
|
141
|
+
let fallbackEventCounter = 0;
|
|
142
|
+
for await (const line of readSessionLines(source.path)) {
|
|
143
|
+
const entry = parseEvent(line);
|
|
144
|
+
if (!entry)
|
|
145
|
+
continue;
|
|
146
|
+
const eventName = stringValue(entry.event);
|
|
147
|
+
const data = entry.data;
|
|
148
|
+
if (eventName === 'start' && isRecord(data)) {
|
|
149
|
+
const model = stringValue(data['model']);
|
|
150
|
+
if (model)
|
|
151
|
+
currentModel = model;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (eventName !== 'agent' || !isRecord(data))
|
|
155
|
+
continue;
|
|
156
|
+
if (data['type'] === 'status') {
|
|
157
|
+
const model = stringValue(data['model']);
|
|
158
|
+
if (model)
|
|
159
|
+
currentModel = model;
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
const usage = parseUsage(data);
|
|
163
|
+
if (!usage || !currentModel)
|
|
164
|
+
continue;
|
|
165
|
+
const eventId = stringValue(entry.id) ?? `line-${fallbackEventCounter++}`;
|
|
166
|
+
const dedupKey = `${PROVIDER_NAME}:${sessionId}:${eventId}`;
|
|
167
|
+
if (seenKeys.has(dedupKey))
|
|
168
|
+
continue;
|
|
169
|
+
seenKeys.add(dedupKey);
|
|
170
|
+
const uncachedInputTokens = Math.max(0, usage.inputTokens - usage.cacheReadTokens);
|
|
171
|
+
const costUSD = calculateCost(currentModel, uncachedInputTokens, usage.outputTokens + usage.reasoningTokens, 0, usage.cacheReadTokens, 0);
|
|
172
|
+
yield {
|
|
173
|
+
provider: PROVIDER_NAME,
|
|
174
|
+
sessionId,
|
|
175
|
+
project: source.project,
|
|
176
|
+
model: currentModel,
|
|
177
|
+
inputTokens: uncachedInputTokens,
|
|
178
|
+
outputTokens: usage.outputTokens,
|
|
179
|
+
cacheCreationInputTokens: 0,
|
|
180
|
+
cacheReadInputTokens: usage.cacheReadTokens,
|
|
181
|
+
cachedInputTokens: usage.cacheReadTokens,
|
|
182
|
+
reasoningTokens: usage.reasoningTokens,
|
|
183
|
+
webSearchRequests: 0,
|
|
184
|
+
costUSD,
|
|
185
|
+
tools: [],
|
|
186
|
+
bashCommands: [],
|
|
187
|
+
timestamp: timestampValue(entry.timestamp),
|
|
188
|
+
speed: 'standard',
|
|
189
|
+
deduplicationKey: dedupKey,
|
|
190
|
+
userMessage: '',
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
export function createOpenDesignProvider(overrideDir) {
|
|
197
|
+
return {
|
|
198
|
+
name: PROVIDER_NAME,
|
|
199
|
+
displayName: 'Open Design',
|
|
200
|
+
modelDisplayName(model) {
|
|
201
|
+
return modelDisplayNames.get(model) ?? model;
|
|
202
|
+
},
|
|
203
|
+
toolDisplayName(rawTool) {
|
|
204
|
+
return rawTool;
|
|
205
|
+
},
|
|
206
|
+
async probeRoots() {
|
|
207
|
+
return [{ path: overrideDir ?? getOpenDesignDir(), label: 'sessions' }];
|
|
208
|
+
},
|
|
209
|
+
async discoverSessions() {
|
|
210
|
+
return discoverOpenDesignSessions(overrideDir ?? getOpenDesignDir());
|
|
211
|
+
},
|
|
212
|
+
createSessionParser(source, seenKeys) {
|
|
213
|
+
return createParser(source, seenKeys);
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
export const openDesign = createOpenDesignProvider();
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
// OpenClaude (npm `@gitlawb/openclaude`) is a Claude Code fork that runs the
|
|
3
|
+
// same agent loop against any LLM (DeepSeek, OpenAI, etc.). Each session is a
|
|
4
|
+
// Claude-Code-schema JSONL transcript under a project slug:
|
|
5
|
+
//
|
|
6
|
+
// ~/.openclaude/projects/<project-slug>/<uuid>.jsonl
|
|
7
|
+
//
|
|
8
|
+
// Every transcript has a sibling `<uuid>.replay.json` that only carries replay
|
|
9
|
+
// state; discovery only picks up `.jsonl` files, so the replay files are
|
|
10
|
+
// skipped. Subagent (sidechain) traffic is interleaved in the same transcript
|
|
11
|
+
// with `isSidechain: true`; those lines are real spend and are counted like
|
|
12
|
+
// any other assistant line. The transcript reports no cost field, so every
|
|
13
|
+
// call's cost is computed from token counts via calculateCost and always
|
|
14
|
+
// flagged costIsEstimated: true.
|
|
15
|
+
import { readdir } from 'fs/promises';
|
|
16
|
+
import { homedir } from 'os';
|
|
17
|
+
import { basename, join } from 'path';
|
|
18
|
+
import { extractBashCommands } from '../bash-utils.js';
|
|
19
|
+
import { readSessionFile } from '../fs-utils.js';
|
|
20
|
+
import { calculateCost, getShortModelName } from '../models.js';
|
|
21
|
+
const PROVIDER_NAME = 'openclaude';
|
|
22
|
+
const DISPLAY_NAME = 'OpenClaude';
|
|
23
|
+
const MIN_REASONABLE_TIMESTAMP_MS = 1_000_000_000_000;
|
|
24
|
+
// Mirrors the CLI's own resolution chain, each level individually overridable:
|
|
25
|
+
// root := CODEBURN_OPENCLAUDE_DIR ?? ~/.openclaude
|
|
26
|
+
// projects := <root>/projects
|
|
27
|
+
function openClaudeRootDir() {
|
|
28
|
+
return process.env['CODEBURN_OPENCLAUDE_DIR']?.trim() || join(homedir(), '.openclaude');
|
|
29
|
+
}
|
|
30
|
+
export function getOpenClaudeProjectsDir() {
|
|
31
|
+
return join(openClaudeRootDir(), 'projects');
|
|
32
|
+
}
|
|
33
|
+
function isRecord(value) {
|
|
34
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
35
|
+
}
|
|
36
|
+
function nonEmptyString(value) {
|
|
37
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
38
|
+
}
|
|
39
|
+
function safeNonNegativeNumber(value) {
|
|
40
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : 0;
|
|
41
|
+
}
|
|
42
|
+
function safeTokenCount(value) {
|
|
43
|
+
return Math.floor(Math.min(safeNonNegativeNumber(value), Number.MAX_SAFE_INTEGER));
|
|
44
|
+
}
|
|
45
|
+
// The transcript only ever carries ISO timestamps, but keep the epoch-millis
|
|
46
|
+
// branch so an exotic export can never silently land in 1970, matching the
|
|
47
|
+
// guard cline-cli.ts uses on the same hazard.
|
|
48
|
+
function isoTimestamp(value, fallback) {
|
|
49
|
+
if (typeof value === 'number' && Number.isFinite(value) && value > 0) {
|
|
50
|
+
// Promote seconds-resolution values to milliseconds, then reject anything
|
|
51
|
+
// that stays implausible.
|
|
52
|
+
const ms = value < MIN_REASONABLE_TIMESTAMP_MS ? value * 1000 : value;
|
|
53
|
+
const date = new Date(ms);
|
|
54
|
+
if (!Number.isNaN(date.getTime()) && date.getTime() >= MIN_REASONABLE_TIMESTAMP_MS) {
|
|
55
|
+
return date.toISOString();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const parsed = nonEmptyString(value);
|
|
59
|
+
if (parsed) {
|
|
60
|
+
const date = new Date(parsed);
|
|
61
|
+
if (!Number.isNaN(date.getTime()))
|
|
62
|
+
return date.toISOString();
|
|
63
|
+
}
|
|
64
|
+
return fallback;
|
|
65
|
+
}
|
|
66
|
+
function firstString(input, keys) {
|
|
67
|
+
if (!isRecord(input))
|
|
68
|
+
return undefined;
|
|
69
|
+
for (const key of keys) {
|
|
70
|
+
const value = nonEmptyString(input[key]);
|
|
71
|
+
if (value)
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
// Tool names are already codeburn-canonical (Write, Read, Bash, Grep, Edit,
|
|
77
|
+
// Task, Skill, WebFetch, ...) because OpenClaude is a Claude Code fork, so no
|
|
78
|
+
// mapping table is needed: the raw name is used as-is.
|
|
79
|
+
function collectTools(content) {
|
|
80
|
+
const collected = {
|
|
81
|
+
tools: [], bashCommands: [], toolSequence: [], skills: [], subagentTypes: [],
|
|
82
|
+
};
|
|
83
|
+
if (!Array.isArray(content))
|
|
84
|
+
return collected;
|
|
85
|
+
const turnTools = [];
|
|
86
|
+
for (const block of content) {
|
|
87
|
+
if (!isRecord(block) || block['type'] !== 'tool_use')
|
|
88
|
+
continue;
|
|
89
|
+
const name = nonEmptyString(block['name']);
|
|
90
|
+
if (!name)
|
|
91
|
+
continue;
|
|
92
|
+
const input = block['input'];
|
|
93
|
+
const toolCall = { tool: name };
|
|
94
|
+
const file = firstString(input, ['path', 'file_path', 'paths', 'file']);
|
|
95
|
+
if (file)
|
|
96
|
+
toolCall.file = file;
|
|
97
|
+
if (name === 'Bash') {
|
|
98
|
+
const command = firstString(input, ['command']);
|
|
99
|
+
if (command) {
|
|
100
|
+
toolCall.command = command;
|
|
101
|
+
collected.bashCommands.push(...extractBashCommands(command));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (name === 'Skill') {
|
|
105
|
+
const skill = firstString(input, ['name', 'skill']);
|
|
106
|
+
if (skill)
|
|
107
|
+
collected.skills.push(skill);
|
|
108
|
+
}
|
|
109
|
+
if (name === 'Task') {
|
|
110
|
+
const subagentType = firstString(input, ['subagent_type']);
|
|
111
|
+
if (subagentType)
|
|
112
|
+
collected.subagentTypes.push(subagentType);
|
|
113
|
+
}
|
|
114
|
+
collected.tools.push(name);
|
|
115
|
+
turnTools.push(toolCall);
|
|
116
|
+
}
|
|
117
|
+
if (turnTools.length > 0)
|
|
118
|
+
collected.toolSequence.push(turnTools);
|
|
119
|
+
return collected;
|
|
120
|
+
}
|
|
121
|
+
function textFromContent(content) {
|
|
122
|
+
if (typeof content === 'string')
|
|
123
|
+
return content;
|
|
124
|
+
if (!Array.isArray(content))
|
|
125
|
+
return '';
|
|
126
|
+
for (const block of content) {
|
|
127
|
+
if (!isRecord(block) || block['type'] !== 'text')
|
|
128
|
+
continue;
|
|
129
|
+
const text = nonEmptyString(block['text']);
|
|
130
|
+
if (text)
|
|
131
|
+
return text;
|
|
132
|
+
}
|
|
133
|
+
return '';
|
|
134
|
+
}
|
|
135
|
+
// The session's prompt is the first user line carrying real text. Tool results
|
|
136
|
+
// also arrive as user lines but as blocks with no text block, so they are
|
|
137
|
+
// skipped here.
|
|
138
|
+
function firstUserMessage(lines) {
|
|
139
|
+
for (const line of lines) {
|
|
140
|
+
if (!isRecord(line) || line['type'] !== 'user')
|
|
141
|
+
continue;
|
|
142
|
+
const message = line['message'];
|
|
143
|
+
if (!isRecord(message))
|
|
144
|
+
continue;
|
|
145
|
+
const text = textFromContent(message['content']);
|
|
146
|
+
if (text)
|
|
147
|
+
return text;
|
|
148
|
+
}
|
|
149
|
+
return '';
|
|
150
|
+
}
|
|
151
|
+
function projectFromCwd(cwd) {
|
|
152
|
+
const parts = cwd.replace(/[\\/]+$/, '').split(/[\\/]/).filter(Boolean);
|
|
153
|
+
return parts.at(-1);
|
|
154
|
+
}
|
|
155
|
+
function createParser(source, seenKeys) {
|
|
156
|
+
return {
|
|
157
|
+
async *parse() {
|
|
158
|
+
const raw = await readSessionFile(source.path);
|
|
159
|
+
if (raw === null)
|
|
160
|
+
return;
|
|
161
|
+
// Decode the file once, skipping blank and corrupt lines, so the
|
|
162
|
+
// timestamp, cwd, and user-message scans below share a single parse.
|
|
163
|
+
const parsedLines = [];
|
|
164
|
+
for (const line of raw.split('\n')) {
|
|
165
|
+
if (!line.trim())
|
|
166
|
+
continue;
|
|
167
|
+
try {
|
|
168
|
+
parsedLines.push(JSON.parse(line));
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
// Corrupt line - skip it.
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// File-level fallback timestamp: the first valid ISO timestamp in the
|
|
175
|
+
// file, so a line missing one still lands inside the session's window.
|
|
176
|
+
let fileTimestamp = new Date(0).toISOString();
|
|
177
|
+
for (const line of parsedLines) {
|
|
178
|
+
if (!isRecord(line))
|
|
179
|
+
continue;
|
|
180
|
+
const ts = nonEmptyString(line['timestamp']);
|
|
181
|
+
if (!ts)
|
|
182
|
+
continue;
|
|
183
|
+
const date = new Date(ts);
|
|
184
|
+
if (Number.isNaN(date.getTime()))
|
|
185
|
+
continue;
|
|
186
|
+
fileTimestamp = date.toISOString();
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
const userMessage = firstUserMessage(parsedLines);
|
|
190
|
+
// The project is the basename of the first cwd seen in the transcript
|
|
191
|
+
// (what the user recognizes); the discovery-time slug is the fallback.
|
|
192
|
+
let firstSeenCwd;
|
|
193
|
+
for (const line of parsedLines) {
|
|
194
|
+
if (!isRecord(line))
|
|
195
|
+
continue;
|
|
196
|
+
const cwd = nonEmptyString(line['cwd']);
|
|
197
|
+
if (!cwd)
|
|
198
|
+
continue;
|
|
199
|
+
firstSeenCwd = cwd;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
const project = firstSeenCwd
|
|
203
|
+
? (projectFromCwd(firstSeenCwd) ?? source.project)
|
|
204
|
+
: source.project;
|
|
205
|
+
for (const [index, line] of parsedLines.entries()) {
|
|
206
|
+
if (!isRecord(line) || line['type'] !== 'assistant')
|
|
207
|
+
continue;
|
|
208
|
+
const message = line['message'];
|
|
209
|
+
if (!isRecord(message))
|
|
210
|
+
continue;
|
|
211
|
+
// Only assistant lines carrying a usage record become calls; the rest
|
|
212
|
+
// of the transcript (queue-operation, last-prompt, user lines) is
|
|
213
|
+
// skipped silently.
|
|
214
|
+
const usage = message['usage'];
|
|
215
|
+
if (!isRecord(usage))
|
|
216
|
+
continue;
|
|
217
|
+
const inputTokens = safeTokenCount(usage['input_tokens']);
|
|
218
|
+
const outputTokens = safeTokenCount(usage['output_tokens']);
|
|
219
|
+
const cacheWriteTokens = safeTokenCount(usage['cache_creation_input_tokens']);
|
|
220
|
+
const cacheReadTokens = safeTokenCount(usage['cache_read_input_tokens']);
|
|
221
|
+
const webSearchRequests = safeTokenCount(isRecord(usage['server_tool_use']) ? usage['server_tool_use']['web_search_requests'] : undefined);
|
|
222
|
+
const model = nonEmptyString(message['model']) ?? 'unknown';
|
|
223
|
+
const sessionId = nonEmptyString(line['sessionId']) ?? basename(source.path).replace(/\.jsonl$/, '');
|
|
224
|
+
const messageId = nonEmptyString(message['id']) ?? nonEmptyString(line['uuid']) ?? String(index);
|
|
225
|
+
const deduplicationKey = `${PROVIDER_NAME}:${sessionId}:${messageId}`;
|
|
226
|
+
if (seenKeys.has(deduplicationKey))
|
|
227
|
+
continue;
|
|
228
|
+
seenKeys.add(deduplicationKey);
|
|
229
|
+
const { tools, bashCommands, toolSequence, skills, subagentTypes } = collectTools(message['content']);
|
|
230
|
+
yield {
|
|
231
|
+
provider: PROVIDER_NAME,
|
|
232
|
+
model,
|
|
233
|
+
inputTokens,
|
|
234
|
+
outputTokens,
|
|
235
|
+
cacheCreationInputTokens: cacheWriteTokens,
|
|
236
|
+
cacheReadInputTokens: cacheReadTokens,
|
|
237
|
+
cachedInputTokens: 0,
|
|
238
|
+
reasoningTokens: 0,
|
|
239
|
+
webSearchRequests,
|
|
240
|
+
costUSD: calculateCost(model, inputTokens, outputTokens, cacheWriteTokens, cacheReadTokens, 0),
|
|
241
|
+
costIsEstimated: true,
|
|
242
|
+
tools,
|
|
243
|
+
bashCommands,
|
|
244
|
+
skills: skills.length > 0 ? skills : undefined,
|
|
245
|
+
subagentTypes: subagentTypes.length > 0 ? subagentTypes : undefined,
|
|
246
|
+
timestamp: isoTimestamp(line['timestamp'], fileTimestamp),
|
|
247
|
+
speed: 'standard',
|
|
248
|
+
deduplicationKey,
|
|
249
|
+
turnId: `${sessionId}:${messageId}`,
|
|
250
|
+
toolSequence: toolSequence.length > 0 ? toolSequence : undefined,
|
|
251
|
+
userMessage,
|
|
252
|
+
sessionId,
|
|
253
|
+
project,
|
|
254
|
+
projectPath: firstSeenCwd,
|
|
255
|
+
workingDirectory: nonEmptyString(line['cwd']),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
export function createOpenClaudeProvider(overrideProjectsDir) {
|
|
262
|
+
const projectsDir = () => overrideProjectsDir ?? getOpenClaudeProjectsDir();
|
|
263
|
+
return {
|
|
264
|
+
name: PROVIDER_NAME,
|
|
265
|
+
displayName: DISPLAY_NAME,
|
|
266
|
+
modelDisplayName(model) {
|
|
267
|
+
return getShortModelName(model);
|
|
268
|
+
},
|
|
269
|
+
toolDisplayName(rawTool) {
|
|
270
|
+
// OpenClaude tool names are already codeburn-canonical - pass through.
|
|
271
|
+
return rawTool;
|
|
272
|
+
},
|
|
273
|
+
async probeRoots() {
|
|
274
|
+
return [{ path: projectsDir(), label: 'projects' }];
|
|
275
|
+
},
|
|
276
|
+
async discoverSessions() {
|
|
277
|
+
const dir = projectsDir();
|
|
278
|
+
const projectEntries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
279
|
+
const sources = [];
|
|
280
|
+
for (const projectEntry of projectEntries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
281
|
+
if (!projectEntry.isDirectory())
|
|
282
|
+
continue;
|
|
283
|
+
const projectDir = join(dir, projectEntry.name);
|
|
284
|
+
const fileEntries = await readdir(projectDir, { withFileTypes: true }).catch(() => []);
|
|
285
|
+
for (const fileEntry of fileEntries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
286
|
+
if (!fileEntry.isFile())
|
|
287
|
+
continue;
|
|
288
|
+
// Only transcripts; the sibling `<uuid>.replay.json` files end in
|
|
289
|
+
// `.json` and never match.
|
|
290
|
+
if (!fileEntry.name.endsWith('.jsonl'))
|
|
291
|
+
continue;
|
|
292
|
+
sources.push({
|
|
293
|
+
path: join(projectDir, fileEntry.name),
|
|
294
|
+
// The whole slug is the discovery-time fallback; parse-time
|
|
295
|
+
// project naming prefers the basename of the first cwd seen in
|
|
296
|
+
// the transcript.
|
|
297
|
+
project: projectEntry.name,
|
|
298
|
+
provider: PROVIDER_NAME,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return sources;
|
|
303
|
+
},
|
|
304
|
+
createSessionParser(source, seenKeys) {
|
|
305
|
+
return createParser(source, seenKeys);
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
export const openclaude = createOpenClaudeProvider();
|