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,405 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { readdir } from 'fs/promises';
|
|
3
|
+
import { basename, join } from 'path';
|
|
4
|
+
import { readSessionLines } from './fs-utils.js';
|
|
5
|
+
import { fileFacts } from './scan-facts.js';
|
|
6
|
+
import { behavioralCallWeight, isBehavioralCall } from './behavioral-weight.js';
|
|
7
|
+
import { modelRowKey } from './models.js';
|
|
8
|
+
import { callBillableOutputTokens } from './session-output.js';
|
|
9
|
+
import { sessionCacheHitPercent } from './sessions-report.js';
|
|
10
|
+
const PLANNING_TOOLS = new Set(['TaskCreate', 'TaskUpdate', 'TodoWrite', 'EnterPlanMode', 'ExitPlanMode']);
|
|
11
|
+
/// The turn's primary model: the model of its FIRST BEHAVIORAL call. Undefined
|
|
12
|
+
/// when the turn has none — accounting-only turns carry no behavioral evidence,
|
|
13
|
+
/// so they are excluded from efficiency comparisons (their spend still appears
|
|
14
|
+
/// in every spend report).
|
|
15
|
+
function primaryTurnModel(turn) {
|
|
16
|
+
return turn.assistantCalls.find(isBehavioralCall)?.model;
|
|
17
|
+
}
|
|
18
|
+
export function aggregateModelStats(projects) {
|
|
19
|
+
const byModel = new Map();
|
|
20
|
+
const ensure = (model) => {
|
|
21
|
+
let s = byModel.get(model);
|
|
22
|
+
if (!s) {
|
|
23
|
+
s = { model, calls: 0, cost: 0, outputTokens: 0, inputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0, totalTurns: 0, editTurns: 0, oneShotTurns: 0, retries: 0, selfCorrections: 0, editCost: 0, firstSeen: '', lastSeen: '' };
|
|
24
|
+
byModel.set(model, s);
|
|
25
|
+
}
|
|
26
|
+
return s;
|
|
27
|
+
};
|
|
28
|
+
for (const project of projects) {
|
|
29
|
+
for (const session of project.sessions) {
|
|
30
|
+
for (const turn of session.turns) {
|
|
31
|
+
const primaryModel = primaryTurnModel(turn);
|
|
32
|
+
if (primaryModel === undefined || primaryModel === '<synthetic>')
|
|
33
|
+
continue;
|
|
34
|
+
const ms = ensure(primaryModel);
|
|
35
|
+
ms.totalTurns++;
|
|
36
|
+
if (turn.hasEdits) {
|
|
37
|
+
ms.editTurns++;
|
|
38
|
+
if (turn.retries === 0)
|
|
39
|
+
ms.oneShotTurns++;
|
|
40
|
+
for (const c of turn.assistantCalls) {
|
|
41
|
+
if (c.model !== '<synthetic>')
|
|
42
|
+
ms.editCost += c.costUSD;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
ms.retries += turn.retries;
|
|
46
|
+
for (const call of turn.assistantCalls) {
|
|
47
|
+
if (call.model === '<synthetic>')
|
|
48
|
+
continue;
|
|
49
|
+
const cs = call.model === primaryModel ? ms : ensure(call.model);
|
|
50
|
+
cs.calls += behavioralCallWeight(call);
|
|
51
|
+
cs.cost += call.costUSD;
|
|
52
|
+
cs.outputTokens += callBillableOutputTokens(call);
|
|
53
|
+
cs.inputTokens += call.usage.inputTokens;
|
|
54
|
+
cs.cacheReadTokens += call.usage.cacheReadInputTokens;
|
|
55
|
+
cs.cacheWriteTokens += call.usage.cacheCreationInputTokens;
|
|
56
|
+
if (!cs.firstSeen || call.timestamp < cs.firstSeen)
|
|
57
|
+
cs.firstSeen = call.timestamp;
|
|
58
|
+
if (!cs.lastSeen || call.timestamp > cs.lastSeen)
|
|
59
|
+
cs.lastSeen = call.timestamp;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return [...byModel.values()].sort((a, b) => b.cost - a.cost);
|
|
65
|
+
}
|
|
66
|
+
/// Look up a model by the exact canonical id (what --model-a/--model-b has
|
|
67
|
+
/// always accepted) or, failing that, by its display name (what the compare
|
|
68
|
+
/// picker actually shows the user, e.g. "Opus 4.8") - case-insensitively.
|
|
69
|
+
/// Reuses getShortModelName, the existing canonical -> display mapping,
|
|
70
|
+
/// rather than a new alias table.
|
|
71
|
+
export function findModelStat(models, input) {
|
|
72
|
+
return models.find(m => m.model === input)
|
|
73
|
+
?? models.find(m => modelRowKey(m.model).toLowerCase() === input.toLowerCase());
|
|
74
|
+
}
|
|
75
|
+
const METRICS = [
|
|
76
|
+
{
|
|
77
|
+
section: 'Performance',
|
|
78
|
+
label: 'One-shot rate',
|
|
79
|
+
formatFn: 'percent',
|
|
80
|
+
higherIsBetter: true,
|
|
81
|
+
compute: s => s.editTurns > 0 ? (s.oneShotTurns / s.editTurns) * 100 : null,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
section: 'Performance',
|
|
85
|
+
label: 'Retry rate',
|
|
86
|
+
formatFn: 'decimal',
|
|
87
|
+
higherIsBetter: false,
|
|
88
|
+
compute: s => s.editTurns > 0 ? s.retries / s.editTurns : null,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
section: 'Performance',
|
|
92
|
+
label: 'Self-correction',
|
|
93
|
+
formatFn: 'percent',
|
|
94
|
+
higherIsBetter: false,
|
|
95
|
+
compute: s => s.totalTurns > 0 ? (s.selfCorrections / s.totalTurns) * 100 : null,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
section: 'Efficiency',
|
|
99
|
+
label: 'Cost / call',
|
|
100
|
+
formatFn: 'cost',
|
|
101
|
+
higherIsBetter: false,
|
|
102
|
+
compute: s => s.calls > 0 ? s.cost / s.calls : null,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
section: 'Efficiency',
|
|
106
|
+
label: 'Cost / edit',
|
|
107
|
+
formatFn: 'cost',
|
|
108
|
+
higherIsBetter: false,
|
|
109
|
+
compute: s => s.editTurns > 0 ? s.editCost / s.editTurns : null,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
section: 'Efficiency',
|
|
113
|
+
label: 'Output tok / call',
|
|
114
|
+
formatFn: 'number',
|
|
115
|
+
higherIsBetter: false,
|
|
116
|
+
compute: s => s.calls > 0 ? Math.round(s.outputTokens / s.calls) : null,
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
section: 'Efficiency',
|
|
120
|
+
label: 'Cache hit rate',
|
|
121
|
+
formatFn: 'percent',
|
|
122
|
+
higherIsBetter: true,
|
|
123
|
+
compute: s => sessionCacheHitPercent(s.inputTokens, s.cacheReadTokens, s.cacheWriteTokens),
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
function pickWinner(valueA, valueB, higherIsBetter) {
|
|
127
|
+
if (valueA === null || valueB === null)
|
|
128
|
+
return 'none';
|
|
129
|
+
if (valueA === valueB)
|
|
130
|
+
return 'tie';
|
|
131
|
+
if (higherIsBetter)
|
|
132
|
+
return valueA > valueB ? 'a' : 'b';
|
|
133
|
+
return valueA < valueB ? 'a' : 'b';
|
|
134
|
+
}
|
|
135
|
+
export function computeComparison(a, b) {
|
|
136
|
+
return METRICS.map(m => {
|
|
137
|
+
const valueA = m.compute(a);
|
|
138
|
+
const valueB = m.compute(b);
|
|
139
|
+
return {
|
|
140
|
+
section: m.section,
|
|
141
|
+
label: m.label,
|
|
142
|
+
valueA,
|
|
143
|
+
valueB,
|
|
144
|
+
formatFn: m.formatFn,
|
|
145
|
+
winner: pickWinner(valueA, valueB, m.higherIsBetter),
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
export function computeCategoryComparison(projects, modelA, modelB) {
|
|
150
|
+
const mapA = new Map();
|
|
151
|
+
const mapB = new Map();
|
|
152
|
+
const ensure = (map, cat) => {
|
|
153
|
+
let a = map.get(cat);
|
|
154
|
+
if (!a) {
|
|
155
|
+
a = { turns: 0, editTurns: 0, oneShotTurns: 0 };
|
|
156
|
+
map.set(cat, a);
|
|
157
|
+
}
|
|
158
|
+
return a;
|
|
159
|
+
};
|
|
160
|
+
for (const project of projects) {
|
|
161
|
+
for (const session of project.sessions) {
|
|
162
|
+
for (const turn of session.turns) {
|
|
163
|
+
const primary = primaryTurnModel(turn);
|
|
164
|
+
if (primary !== modelA && primary !== modelB)
|
|
165
|
+
continue;
|
|
166
|
+
const acc = ensure(primary === modelA ? mapA : mapB, turn.category);
|
|
167
|
+
acc.turns++;
|
|
168
|
+
if (turn.hasEdits) {
|
|
169
|
+
acc.editTurns++;
|
|
170
|
+
if (turn.retries === 0)
|
|
171
|
+
acc.oneShotTurns++;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const allCats = new Set([...mapA.keys(), ...mapB.keys()]);
|
|
177
|
+
const result = [];
|
|
178
|
+
for (const category of allCats) {
|
|
179
|
+
const a = mapA.get(category);
|
|
180
|
+
const b = mapB.get(category);
|
|
181
|
+
if ((!a || a.editTurns === 0) && (!b || b.editTurns === 0))
|
|
182
|
+
continue;
|
|
183
|
+
const rateA = a && a.editTurns > 0 ? (a.oneShotTurns / a.editTurns) * 100 : null;
|
|
184
|
+
const rateB = b && b.editTurns > 0 ? (b.oneShotTurns / b.editTurns) * 100 : null;
|
|
185
|
+
result.push({
|
|
186
|
+
category,
|
|
187
|
+
turnsA: a?.turns ?? 0,
|
|
188
|
+
editTurnsA: a?.editTurns ?? 0,
|
|
189
|
+
oneShotRateA: rateA,
|
|
190
|
+
turnsB: b?.turns ?? 0,
|
|
191
|
+
editTurnsB: b?.editTurns ?? 0,
|
|
192
|
+
oneShotRateB: rateB,
|
|
193
|
+
winner: pickWinner(rateA, rateB, true),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return result.sort((a, b) => (b.turnsA + b.turnsB) - (a.turnsA + a.turnsB));
|
|
197
|
+
}
|
|
198
|
+
export function computeWorkingStyle(projects, modelA, modelB) {
|
|
199
|
+
const sA = { totalTurns: 0, agentSpawns: 0, planModeUses: 0, totalToolCalls: 0, fastModeCalls: 0 };
|
|
200
|
+
const sB = { totalTurns: 0, agentSpawns: 0, planModeUses: 0, totalToolCalls: 0, fastModeCalls: 0 };
|
|
201
|
+
for (const project of projects) {
|
|
202
|
+
for (const session of project.sessions) {
|
|
203
|
+
for (const turn of session.turns) {
|
|
204
|
+
const primary = primaryTurnModel(turn);
|
|
205
|
+
if (primary !== modelA && primary !== modelB)
|
|
206
|
+
continue;
|
|
207
|
+
const s = primary === modelA ? sA : sB;
|
|
208
|
+
s.totalTurns++;
|
|
209
|
+
const behavioralCalls = turn.assistantCalls.filter(isBehavioralCall);
|
|
210
|
+
const turnTools = behavioralCalls.flatMap(c => c.tools);
|
|
211
|
+
if (turnTools.some(t => PLANNING_TOOLS.has(t)) || behavioralCalls.some(c => c.hasPlanMode)) {
|
|
212
|
+
s.planModeUses++;
|
|
213
|
+
}
|
|
214
|
+
for (const call of behavioralCalls) {
|
|
215
|
+
s.totalToolCalls += call.tools.length;
|
|
216
|
+
if (call.hasAgentSpawn)
|
|
217
|
+
s.agentSpawns++;
|
|
218
|
+
if (call.speed === 'fast')
|
|
219
|
+
s.fastModeCalls++;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const pct = (num, den) => den > 0 ? (num / den) * 100 : null;
|
|
225
|
+
const avg = (num, den) => den > 0 ? num / den : null;
|
|
226
|
+
return [
|
|
227
|
+
{ label: 'Delegation rate', valueA: pct(sA.agentSpawns, sA.totalTurns), valueB: pct(sB.agentSpawns, sB.totalTurns), formatFn: 'percent' },
|
|
228
|
+
{ label: 'Planning rate', valueA: pct(sA.planModeUses, sA.totalTurns), valueB: pct(sB.planModeUses, sB.totalTurns), formatFn: 'percent' },
|
|
229
|
+
{ label: 'Avg tools / turn', valueA: avg(sA.totalToolCalls, sA.totalTurns), valueB: avg(sB.totalToolCalls, sB.totalTurns), formatFn: 'decimal' },
|
|
230
|
+
{ label: 'Fast mode usage', valueA: pct(sA.fastModeCalls, sA.totalTurns), valueB: pct(sB.fastModeCalls, sB.totalTurns), formatFn: 'percent' },
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
export function buildCompareJson(projects, modelA, modelB, label, provider) {
|
|
234
|
+
return {
|
|
235
|
+
period: { label, provider },
|
|
236
|
+
modelA,
|
|
237
|
+
modelB,
|
|
238
|
+
metrics: computeComparison(modelA, modelB),
|
|
239
|
+
categories: computeCategoryComparison(projects, modelA.model, modelB.model),
|
|
240
|
+
workingStyle: computeWorkingStyle(projects, modelA.model, modelB.model),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
export function renderCompareJson(report) {
|
|
244
|
+
return JSON.stringify(report, null, 2);
|
|
245
|
+
}
|
|
246
|
+
const SELF_CORRECTION_PATTERNS = [
|
|
247
|
+
/\bmy mistake\b/i,
|
|
248
|
+
/\bmy bad\b/i,
|
|
249
|
+
/\bmy apolog/i,
|
|
250
|
+
/\bI apologize\b/i,
|
|
251
|
+
/\bI was wrong\b/i,
|
|
252
|
+
/\bI was incorrect\b/i,
|
|
253
|
+
/\bI made (a |an )?(error|mistake)\b/i,
|
|
254
|
+
/\bI incorrectly\b/i,
|
|
255
|
+
/\bI mistakenly\b/i,
|
|
256
|
+
/\bthat was (incorrect|wrong|an error)\b/i,
|
|
257
|
+
/\blet me correct that\b/i,
|
|
258
|
+
/\bI need to correct\b/i,
|
|
259
|
+
/\byou're right[.,]? I/i,
|
|
260
|
+
/\bsorry about that\b/i,
|
|
261
|
+
];
|
|
262
|
+
function extractText(content) {
|
|
263
|
+
if (typeof content === 'string')
|
|
264
|
+
return content;
|
|
265
|
+
if (!Array.isArray(content))
|
|
266
|
+
return '';
|
|
267
|
+
return content
|
|
268
|
+
.filter((b) => b !== null && typeof b === 'object' && b.type === 'text' && typeof b.text === 'string')
|
|
269
|
+
.map(b => b.text)
|
|
270
|
+
.join(' ');
|
|
271
|
+
}
|
|
272
|
+
function isCompactFile(name) {
|
|
273
|
+
return name.includes('compact');
|
|
274
|
+
}
|
|
275
|
+
async function collectJsonlFiles(sessionDir) {
|
|
276
|
+
const entries = await readdir(sessionDir, { withFileTypes: true });
|
|
277
|
+
const files = [];
|
|
278
|
+
for (const entry of entries) {
|
|
279
|
+
if (entry.isFile() && entry.name.endsWith('.jsonl') && !isCompactFile(entry.name)) {
|
|
280
|
+
files.push(join(sessionDir, entry.name));
|
|
281
|
+
}
|
|
282
|
+
else if (entry.isDirectory() && entry.name === 'subagents') {
|
|
283
|
+
const subEntries = await readdir(join(sessionDir, entry.name), { withFileTypes: true });
|
|
284
|
+
for (const sub of subEntries) {
|
|
285
|
+
if (sub.isFile() && sub.name.endsWith('.jsonl') && !isCompactFile(sub.name)) {
|
|
286
|
+
files.push(join(sessionDir, entry.name, sub.name));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return files;
|
|
292
|
+
}
|
|
293
|
+
/// Session ids of every session in `projects`. For Claude transcripts the id IS
|
|
294
|
+
/// the `.jsonl` stem, which is what lets a compare scope the self-correction
|
|
295
|
+
/// scan to the sessions it actually reported on (period and project filter).
|
|
296
|
+
export function projectSessionIds(projects) {
|
|
297
|
+
return new Set(projects.flatMap(p => p.sessions.map(s => s.sessionId)));
|
|
298
|
+
}
|
|
299
|
+
/// One transcript's self-corrections, whatever the period: each message that
|
|
300
|
+
/// matched, keyed the way the scan dedupes (model and raw timestamp) and carrying
|
|
301
|
+
/// its instant for the range test. Within a file the first line of a key decides,
|
|
302
|
+
/// as the scan always did.
|
|
303
|
+
async function scanFileCorrections(file, resume) {
|
|
304
|
+
const hits = resume ? [...resume.facts] : [];
|
|
305
|
+
// ponytail: a resumed read only knows the keys that matched, so a later line
|
|
306
|
+
// repeating a key an earlier unmatched line claimed would count; measured on
|
|
307
|
+
// 807k assistant lines, no key ever changes verdict inside a file.
|
|
308
|
+
const seen = new Set(hits.map(([model, ts]) => `${model}:${ts}`));
|
|
309
|
+
const tracker = { lastCompleteLineOffset: resume?.fromOffset ?? 0 };
|
|
310
|
+
// Streamed: a whole-file string read throws past V8's ~512 MiB string limit.
|
|
311
|
+
const lines = readSessionLines(file, undefined, {
|
|
312
|
+
byteOffsetTracker: tracker,
|
|
313
|
+
...(resume ? { startByteOffset: resume.fromOffset } : {}),
|
|
314
|
+
});
|
|
315
|
+
for await (const line of lines) {
|
|
316
|
+
const trimmed = line.trim();
|
|
317
|
+
if (!trimmed)
|
|
318
|
+
continue;
|
|
319
|
+
let parsed;
|
|
320
|
+
try {
|
|
321
|
+
parsed = JSON.parse(trimmed);
|
|
322
|
+
}
|
|
323
|
+
catch {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
const rec = parsed;
|
|
327
|
+
if (!rec || typeof rec !== 'object' || rec['type'] !== 'assistant')
|
|
328
|
+
continue;
|
|
329
|
+
const ts = rec['timestamp'];
|
|
330
|
+
const msg = rec['message'];
|
|
331
|
+
if (msg === null || typeof msg !== 'object')
|
|
332
|
+
continue;
|
|
333
|
+
const msgRec = msg;
|
|
334
|
+
const model = msgRec['model'];
|
|
335
|
+
if (typeof model !== 'string' || model === '<synthetic>')
|
|
336
|
+
continue;
|
|
337
|
+
const dedupeKey = `${model}:${ts}`;
|
|
338
|
+
if (seen.has(dedupeKey))
|
|
339
|
+
continue;
|
|
340
|
+
seen.add(dedupeKey);
|
|
341
|
+
const text = extractText(msgRec['content']);
|
|
342
|
+
if (SELF_CORRECTION_PATTERNS.some(p => p.test(text))) {
|
|
343
|
+
const atMs = new Date(typeof ts === 'string' ? ts : NaN).getTime();
|
|
344
|
+
hits.push([model, String(ts), Number.isNaN(atMs) ? null : atMs]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
return { facts: hits, offset: tracker.lastCompleteLineOffset };
|
|
348
|
+
}
|
|
349
|
+
/// `sessionIds`, when given, restricts the scan to transcripts whose file stem
|
|
350
|
+
/// is one of them; omitted, every file under `projectDirs` is read as before.
|
|
351
|
+
/// `range`, when given, counts only messages timestamped inside it, the same
|
|
352
|
+
/// gate the parser applies to calls. Each transcript is read once per version
|
|
353
|
+
/// of the file (see scan-facts.ts); a message copied into several transcripts
|
|
354
|
+
/// counts once.
|
|
355
|
+
export async function scanSelfCorrections(projectDirs, sessionIds, range) {
|
|
356
|
+
const counts = new Map();
|
|
357
|
+
const seen = new Set();
|
|
358
|
+
const startMs = range?.start.getTime();
|
|
359
|
+
const endMs = range?.end.getTime();
|
|
360
|
+
for (const dir of projectDirs) {
|
|
361
|
+
let entries;
|
|
362
|
+
try {
|
|
363
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
const allFiles = [];
|
|
369
|
+
for (const entry of entries) {
|
|
370
|
+
if (entry.isFile() && entry.name.endsWith('.jsonl') && !isCompactFile(entry.name)) {
|
|
371
|
+
allFiles.push(join(dir, entry.name));
|
|
372
|
+
}
|
|
373
|
+
else if (entry.isDirectory()) {
|
|
374
|
+
try {
|
|
375
|
+
const sessionFiles = await collectJsonlFiles(join(dir, entry.name));
|
|
376
|
+
allFiles.push(...sessionFiles);
|
|
377
|
+
}
|
|
378
|
+
catch {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
for (const file of allFiles) {
|
|
384
|
+
if (sessionIds && !sessionIds.has(basename(file, '.jsonl')))
|
|
385
|
+
continue;
|
|
386
|
+
let hits;
|
|
387
|
+
try {
|
|
388
|
+
hits = await fileFacts('corrections', file, resume => scanFileCorrections(file, resume));
|
|
389
|
+
}
|
|
390
|
+
catch {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
for (const [model, ts, atMs] of hits) {
|
|
394
|
+
if (range && (atMs === null || atMs < startMs || atMs > endMs))
|
|
395
|
+
continue;
|
|
396
|
+
const dedupeKey = `${model}:${ts}`;
|
|
397
|
+
if (seen.has(dedupeKey))
|
|
398
|
+
continue;
|
|
399
|
+
seen.add(dedupeKey);
|
|
400
|
+
counts.set(model, (counts.get(model) ?? 0) + 1);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return counts;
|
|
405
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { readFile, writeFile, mkdir, rename } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { randomBytes } from 'crypto';
|
|
6
|
+
import { PLAN_PROVIDERS } from './plans.js';
|
|
7
|
+
// Read synchronously by the aggregator on every period build, so it is set
|
|
8
|
+
// once per process from config.json (the `preAction` hook), the same way
|
|
9
|
+
// models.ts holds the pricing config.
|
|
10
|
+
let includeGatewayInTotals = false;
|
|
11
|
+
export function setIncludeGatewayInTotals(value) {
|
|
12
|
+
includeGatewayInTotals = value;
|
|
13
|
+
}
|
|
14
|
+
export function gatewayIncludedInTotals() {
|
|
15
|
+
return includeGatewayInTotals;
|
|
16
|
+
}
|
|
17
|
+
export function getConfigDir() {
|
|
18
|
+
return join(homedir(), '.config', 'codeburn');
|
|
19
|
+
}
|
|
20
|
+
function getConfigPath() {
|
|
21
|
+
return join(getConfigDir(), 'config.json');
|
|
22
|
+
}
|
|
23
|
+
let warnedUnreadable = false;
|
|
24
|
+
export async function readConfig() {
|
|
25
|
+
try {
|
|
26
|
+
const raw = await readFile(getConfigPath(), 'utf-8');
|
|
27
|
+
return JSON.parse(raw);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (err.code !== 'ENOENT' && !warnedUnreadable) {
|
|
31
|
+
warnedUnreadable = true;
|
|
32
|
+
process.stderr.write(`codeburn: ignoring ${getConfigPath()} (${err.message}); using defaults\n`);
|
|
33
|
+
}
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export async function saveConfig(config) {
|
|
38
|
+
await mkdir(getConfigDir(), { recursive: true });
|
|
39
|
+
const configPath = getConfigPath();
|
|
40
|
+
// The caller's config came from readConfig, which falls back to {} on an
|
|
41
|
+
// unreadable file; writing it would erase every setting the file still holds.
|
|
42
|
+
let existing;
|
|
43
|
+
try {
|
|
44
|
+
existing = await readFile(configPath, 'utf-8');
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (err.code !== 'ENOENT') {
|
|
48
|
+
process.stderr.write(`codeburn: cannot read ${configPath} (${err.message}); nothing saved\n`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (existing !== undefined) {
|
|
53
|
+
try {
|
|
54
|
+
JSON.parse(existing);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
const moved = `${configPath}.corrupt-${Date.now()}`;
|
|
58
|
+
await rename(configPath, moved);
|
|
59
|
+
process.stderr.write(`codeburn: ${configPath} is not valid JSON; moved it to ${moved} and saved nothing. Fix it, move it back and run the command again.\n`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Randomize the temp path so two simultaneous saveConfig calls (from
|
|
64
|
+
// overlapping menubar + CLI runs, for example) do not race on the same
|
|
65
|
+
// staging file. The previous fixed `.tmp` suffix could leave one
|
|
66
|
+
// process reading partial bytes the other was mid-writing.
|
|
67
|
+
const tmpPath = `${configPath}.${randomBytes(8).toString('hex')}.tmp`;
|
|
68
|
+
await writeFile(tmpPath, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
69
|
+
await rename(tmpPath, configPath);
|
|
70
|
+
}
|
|
71
|
+
export async function readPlan() {
|
|
72
|
+
const plans = await readPlans();
|
|
73
|
+
for (const provider of PLAN_PROVIDERS) {
|
|
74
|
+
const plan = plans[provider];
|
|
75
|
+
if (plan)
|
|
76
|
+
return plan;
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
function planFromConfig(provider, plan) {
|
|
81
|
+
if (!plan)
|
|
82
|
+
return undefined;
|
|
83
|
+
return {
|
|
84
|
+
...plan,
|
|
85
|
+
provider,
|
|
86
|
+
setAt: plan.setAt ?? '',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function normalizePlans(config) {
|
|
90
|
+
const plans = {};
|
|
91
|
+
if (config.plans && Object.keys(config.plans).length > 0) {
|
|
92
|
+
for (const provider of PLAN_PROVIDERS) {
|
|
93
|
+
const plan = planFromConfig(provider, config.plans[provider]);
|
|
94
|
+
if (plan)
|
|
95
|
+
plans[provider] = plan;
|
|
96
|
+
}
|
|
97
|
+
if (plans.all && PLAN_PROVIDERS.some(provider => provider !== 'all' && plans[provider])) {
|
|
98
|
+
delete plans.all;
|
|
99
|
+
}
|
|
100
|
+
return plans;
|
|
101
|
+
}
|
|
102
|
+
if (config.plan) {
|
|
103
|
+
plans[config.plan.provider] = config.plan;
|
|
104
|
+
}
|
|
105
|
+
return plans;
|
|
106
|
+
}
|
|
107
|
+
export async function readPlans() {
|
|
108
|
+
return normalizePlans(await readConfig());
|
|
109
|
+
}
|
|
110
|
+
export async function savePlan(plan) {
|
|
111
|
+
const config = await readConfig();
|
|
112
|
+
const plans = normalizePlans(config);
|
|
113
|
+
if (plan.provider === 'all') {
|
|
114
|
+
config.plans = { all: plan };
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
delete plans.all;
|
|
118
|
+
plans[plan.provider] = plan;
|
|
119
|
+
config.plans = plans;
|
|
120
|
+
}
|
|
121
|
+
delete config.plan;
|
|
122
|
+
await saveConfig(config);
|
|
123
|
+
}
|
|
124
|
+
export async function clearPlan(provider) {
|
|
125
|
+
const config = await readConfig();
|
|
126
|
+
if (provider) {
|
|
127
|
+
const plans = normalizePlans(config);
|
|
128
|
+
delete plans[provider];
|
|
129
|
+
if (Object.keys(plans).length > 0) {
|
|
130
|
+
config.plans = plans;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
delete config.plans;
|
|
134
|
+
}
|
|
135
|
+
delete config.plan;
|
|
136
|
+
await saveConfig(config);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
delete config.plan;
|
|
140
|
+
delete config.plans;
|
|
141
|
+
await saveConfig(config);
|
|
142
|
+
}
|
|
143
|
+
export function getConfigFilePath() {
|
|
144
|
+
return getConfigPath();
|
|
145
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
/// Normalize a message's `content` into an array of content blocks.
|
|
3
|
+
///
|
|
4
|
+
/// Most agent session formats write `content` as an array of typed blocks
|
|
5
|
+
/// (`{ type: 'text' | 'tool_use' | ... }`), and the parsers filter over that
|
|
6
|
+
/// array. But some agents (Pi, and others for programmatically injected turns)
|
|
7
|
+
/// legitimately write `content` as a plain **string**. A raw string reaching
|
|
8
|
+
/// `.filter`/`.some` throws a TypeError mid-parse — and because the 365-day
|
|
9
|
+
/// daily-cache backfill swallows parse errors, that single bad record silently
|
|
10
|
+
/// wipes the entire trend/history (issue #441).
|
|
11
|
+
///
|
|
12
|
+
/// This coerces defensively: arrays pass through, a string becomes one text
|
|
13
|
+
/// block, and anything else (null/undefined/number/object) becomes empty.
|
|
14
|
+
export function normalizeContentBlocks(content) {
|
|
15
|
+
if (Array.isArray(content)) {
|
|
16
|
+
// A clean array (the overwhelming common case) is returned by reference — no
|
|
17
|
+
// copy. Only when an element is a non-object (null/undefined/primitive) do we
|
|
18
|
+
// filter, since the call sites read `.type` on each element and a null would
|
|
19
|
+
// throw — the same crash class this helper exists to prevent, one level down.
|
|
20
|
+
const isBlock = (b) => b != null && typeof b === 'object';
|
|
21
|
+
return content.every(isBlock) ? content : content.filter(isBlock);
|
|
22
|
+
}
|
|
23
|
+
if (typeof content === 'string')
|
|
24
|
+
return [{ type: 'text', text: content }];
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
/// Take a bounded prefix of a string as a FLAT copy.
|
|
28
|
+
///
|
|
29
|
+
/// `String.prototype.slice` returns a V8 SlicedString — a view object that
|
|
30
|
+
/// retains a reference to its ENTIRE parent string. Session files routinely
|
|
31
|
+
/// carry 100KB+ message strings (agent-injected system prompts, tool
|
|
32
|
+
/// results); storing a short `.slice()` of each in a long-lived structure
|
|
33
|
+
/// (the session cache) pins every parent buffer for the life of the process.
|
|
34
|
+
/// Across thousands of session files this balloons a cold parse of a few GB
|
|
35
|
+
/// of JSONL into an out-of-memory crash (~5.5GB peak observed), while a warm
|
|
36
|
+
/// run — whose strings were flattened by the cache's JSON round-trip — needs
|
|
37
|
+
/// only ~300MB for the same data.
|
|
38
|
+
///
|
|
39
|
+
/// Round-tripping through a Buffer forces a fresh flat string with no parent
|
|
40
|
+
/// reference. This always runs, even when `s` is already within `max`:
|
|
41
|
+
/// callers may pass an already-sliced view (provider adapters pre-truncate
|
|
42
|
+
/// with `.slice(0, 500)` before the cache-site call), and that view is
|
|
43
|
+
/// itself a SlicedString pinning its own large parent.
|
|
44
|
+
export function flatSlice(s, max) {
|
|
45
|
+
return Buffer.from(s.slice(0, max), 'utf16le').toString('utf16le');
|
|
46
|
+
}
|
|
47
|
+
/// Force a FLAT copy of a string regardless of length.
|
|
48
|
+
///
|
|
49
|
+
/// Companion to `flatSlice` for strings that are ALREADY short but were
|
|
50
|
+
/// produced as views over a large parent — regex match groups
|
|
51
|
+
/// (`match[1]` retains the entire subject string) and `trim()` results
|
|
52
|
+
/// both come back as V8 SlicedStrings. Use this when storing such values
|
|
53
|
+
/// in long-lived structures; use `flatSlice` when also bounding length.
|
|
54
|
+
export function flatString(s) {
|
|
55
|
+
return Buffer.from(s, 'utf16le').toString('utf16le');
|
|
56
|
+
}
|