chompyy 0.1.0 → 0.4.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 +82 -8
- package/THIRD_PARTY_NOTICES.md +29 -1
- package/dist/appstate.js +121 -4
- package/dist/away.js +191 -25
- package/dist/blueprint.js +102 -7
- package/dist/board.js +143 -15
- package/dist/catalog.js +81 -0
- package/dist/claudesettings.js +23 -0
- package/dist/cli.js +804 -55
- package/dist/coldstart.js +208 -0
- package/dist/config.js +43 -8
- package/dist/costs.js +162 -0
- package/dist/deps.js +124 -0
- package/dist/dream.js +422 -0
- package/dist/duration.js +3 -3
- package/dist/gate.js +40 -5
- package/dist/history.js +308 -0
- package/dist/live.js +255 -0
- package/dist/livequota.js +42 -5
- package/dist/macapp.js +25 -2
- package/dist/pacing.js +189 -0
- package/dist/permissions.js +106 -0
- package/dist/picture.js +124 -0
- package/dist/picturetype.js +208 -0
- package/dist/preflight.js +168 -0
- package/dist/projects.js +5 -4
- package/dist/quota.js +31 -5
- package/dist/refresh.js +290 -0
- package/dist/report.js +41 -21
- package/dist/review.js +111 -11
- package/dist/runner.js +318 -10
- package/dist/taste.js +528 -0
- package/dist/tokens.js +75 -0
- package/dist/tokenstore.js +61 -0
- package/dist/trace.js +284 -0
- package/dist/triggers.js +193 -0
- package/dist/usage.js +467 -0
- package/dist/vendor/codeburn/prices.js +45 -0
- package/dist/verify.js +150 -0
- package/dist/verifycard.js +146 -0
- package/dist/workspace.js +132 -18
- package/package.json +4 -2
- package/skills/taste/SKILL.md +4 -1
- package/vendor/diagram-design/LICENSE +21 -0
- package/vendor/diagram-design/SKILL.md +399 -0
- package/vendor/diagram-design/UPSTREAM.md +18 -0
- package/vendor/diagram-design/assets/example-arc-diagram.html +111 -0
- package/vendor/diagram-design/assets/example-architecture-containment.html +205 -0
- package/vendor/diagram-design/assets/example-architecture-delta.html +193 -0
- package/vendor/diagram-design/assets/example-architecture.html +183 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-campus.html +108 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-coffee-shop.html +121 -0
- package/vendor/diagram-design/assets/example-axonometric-plan-warehouse.html +127 -0
- package/vendor/diagram-design/assets/example-axonometric-plan.html +114 -0
- package/vendor/diagram-design/assets/example-bar.html +129 -0
- package/vendor/diagram-design/assets/example-beeswarm.html +384 -0
- package/vendor/diagram-design/assets/example-box-plot.html +127 -0
- package/vendor/diagram-design/assets/example-bubble.html +147 -0
- package/vendor/diagram-design/assets/example-bump.html +142 -0
- package/vendor/diagram-design/assets/example-data-flow.html +143 -0
- package/vendor/diagram-design/assets/example-datalake.html +269 -0
- package/vendor/diagram-design/assets/example-db-schema.html +302 -0
- package/vendor/diagram-design/assets/example-dependency.html +224 -0
- package/vendor/diagram-design/assets/example-deployment.html +190 -0
- package/vendor/diagram-design/assets/example-dp-integration.html +81 -0
- package/vendor/diagram-design/assets/example-dp-security-matrix.html +88 -0
- package/vendor/diagram-design/assets/example-er.html +202 -0
- package/vendor/diagram-design/assets/example-event-modeling.html +64 -0
- package/vendor/diagram-design/assets/example-exploded-ai-stack.html +85 -0
- package/vendor/diagram-design/assets/example-exploded-keyboard.html +84 -0
- package/vendor/diagram-design/assets/example-exploded-phone.html +83 -0
- package/vendor/diagram-design/assets/example-exploded-unboxing.html +84 -0
- package/vendor/diagram-design/assets/example-exploded.html +83 -0
- package/vendor/diagram-design/assets/example-fishbone.html +152 -0
- package/vendor/diagram-design/assets/example-flowchart.html +163 -0
- package/vendor/diagram-design/assets/example-gantt.html +137 -0
- package/vendor/diagram-design/assets/example-heatmap.html +224 -0
- package/vendor/diagram-design/assets/example-high-level-vertical.html +325 -0
- package/vendor/diagram-design/assets/example-high-level.html +301 -0
- package/vendor/diagram-design/assets/example-import-drawio.html +185 -0
- package/vendor/diagram-design/assets/example-import-excalidraw.html +70 -0
- package/vendor/diagram-design/assets/example-import-mermaid.html +70 -0
- package/vendor/diagram-design/assets/example-import-plantuml.html +107 -0
- package/vendor/diagram-design/assets/example-it-state.html +128 -0
- package/vendor/diagram-design/assets/example-journey.html +148 -0
- package/vendor/diagram-design/assets/example-kanban.html +174 -0
- package/vendor/diagram-design/assets/example-layers.html +123 -0
- package/vendor/diagram-design/assets/example-line.html +111 -0
- package/vendor/diagram-design/assets/example-loop.html +100 -0
- package/vendor/diagram-design/assets/example-marimekko.html +148 -0
- package/vendor/diagram-design/assets/example-medallion.html +159 -0
- package/vendor/diagram-design/assets/example-nested.html +136 -0
- package/vendor/diagram-design/assets/example-org-chart.html +45 -0
- package/vendor/diagram-design/assets/example-polar.html +116 -0
- package/vendor/diagram-design/assets/example-process.html +64 -0
- package/vendor/diagram-design/assets/example-pyramid.html +119 -0
- package/vendor/diagram-design/assets/example-quadrant-consultant.html +166 -0
- package/vendor/diagram-design/assets/example-quadrant.html +135 -0
- package/vendor/diagram-design/assets/example-radar.html +139 -0
- package/vendor/diagram-design/assets/example-requirement-traceability.html +122 -0
- package/vendor/diagram-design/assets/example-ridgeline.html +104 -0
- package/vendor/diagram-design/assets/example-sankey.html +150 -0
- package/vendor/diagram-design/assets/example-sbgn.html +213 -0
- package/vendor/diagram-design/assets/example-scatter.html +141 -0
- package/vendor/diagram-design/assets/example-sequence-oauth.html +227 -0
- package/vendor/diagram-design/assets/example-sequence.html +222 -0
- package/vendor/diagram-design/assets/example-service-blueprint.html +185 -0
- package/vendor/diagram-design/assets/example-slopegraph.html +119 -0
- package/vendor/diagram-design/assets/example-state-lifecycle.html +92 -0
- package/vendor/diagram-design/assets/example-state.html +147 -0
- package/vendor/diagram-design/assets/example-steps.html +78 -0
- package/vendor/diagram-design/assets/example-story-map.html +184 -0
- package/vendor/diagram-design/assets/example-streamgraph.html +99 -0
- package/vendor/diagram-design/assets/example-swimlane.html +172 -0
- package/vendor/diagram-design/assets/example-timeline.html +135 -0
- package/vendor/diagram-design/assets/example-tree-block-decomposition.html +151 -0
- package/vendor/diagram-design/assets/example-tree.html +173 -0
- package/vendor/diagram-design/assets/example-treemap.html +107 -0
- package/vendor/diagram-design/assets/example-uml-class.html +188 -0
- package/vendor/diagram-design/assets/example-unit-grid.html +141 -0
- package/vendor/diagram-design/assets/example-venn.html +110 -0
- package/vendor/diagram-design/assets/example-wardley.html +153 -0
- package/vendor/diagram-design/assets/example-waterfall.html +129 -0
- package/vendor/diagram-design/assets/template-dark.html +99 -0
- package/vendor/diagram-design/assets/template.html +100 -0
- package/vendor/diagram-design/references/layout-budget.md +103 -0
- package/vendor/diagram-design/references/output-spec.md +277 -0
- package/vendor/diagram-design/references/primitive-annotation.md +36 -0
- package/vendor/diagram-design/references/primitive-sketchy.md +43 -0
- package/vendor/diagram-design/references/primitives-core.md +146 -0
- package/vendor/diagram-design/references/semantic-patterns.md +154 -0
- package/vendor/diagram-design/references/style-guide.md +234 -0
- package/vendor/diagram-design/references/type-architecture-delta.md +143 -0
- package/vendor/diagram-design/references/type-architecture.md +117 -0
- package/vendor/diagram-design/references/type-axonometric-plan.md +83 -0
- package/vendor/diagram-design/references/type-bar.md +108 -0
- package/vendor/diagram-design/references/type-data-flow.md +371 -0
- package/vendor/diagram-design/references/type-db-schema.md +48 -0
- package/vendor/diagram-design/references/type-dependency.md +113 -0
- package/vendor/diagram-design/references/type-deployment.md +45 -0
- package/vendor/diagram-design/references/type-dp-integration.md +407 -0
- package/vendor/diagram-design/references/type-dp-security-matrix.md +379 -0
- package/vendor/diagram-design/references/type-er.md +25 -0
- package/vendor/diagram-design/references/type-event-modeling.md +36 -0
- package/vendor/diagram-design/references/type-exploded.md +115 -0
- package/vendor/diagram-design/references/type-fishbone.md +75 -0
- package/vendor/diagram-design/references/type-flowchart.md +23 -0
- package/vendor/diagram-design/references/type-gantt.md +45 -0
- package/vendor/diagram-design/references/type-heatmap.md +80 -0
- package/vendor/diagram-design/references/type-high-level.md +470 -0
- package/vendor/diagram-design/references/type-it-state.md +468 -0
- package/vendor/diagram-design/references/type-journey.md +55 -0
- package/vendor/diagram-design/references/type-kanban.md +49 -0
- package/vendor/diagram-design/references/type-layers.md +26 -0
- package/vendor/diagram-design/references/type-line.md +337 -0
- package/vendor/diagram-design/references/type-loop.md +223 -0
- package/vendor/diagram-design/references/type-medallion.md +356 -0
- package/vendor/diagram-design/references/type-nested.md +22 -0
- package/vendor/diagram-design/references/type-org-chart.md +44 -0
- package/vendor/diagram-design/references/type-polar.md +136 -0
- package/vendor/diagram-design/references/type-process.md +490 -0
- package/vendor/diagram-design/references/type-pyramid.md +33 -0
- package/vendor/diagram-design/references/type-quadrant.md +81 -0
- package/vendor/diagram-design/references/type-radar.md +82 -0
- package/vendor/diagram-design/references/type-requirement-traceability.md +45 -0
- package/vendor/diagram-design/references/type-sankey.md +75 -0
- package/vendor/diagram-design/references/type-sbgn.md +80 -0
- package/vendor/diagram-design/references/type-scatter.md +276 -0
- package/vendor/diagram-design/references/type-sequence.md +130 -0
- package/vendor/diagram-design/references/type-service-blueprint.md +103 -0
- package/vendor/diagram-design/references/type-state.md +30 -0
- package/vendor/diagram-design/references/type-steps.md +180 -0
- package/vendor/diagram-design/references/type-story-map.md +46 -0
- package/vendor/diagram-design/references/type-swimlane.md +22 -0
- package/vendor/diagram-design/references/type-timeline.md +20 -0
- package/vendor/diagram-design/references/type-tree.md +24 -0
- package/vendor/diagram-design/references/type-treemap.md +137 -0
- package/vendor/diagram-design/references/type-uml-class.md +65 -0
- package/vendor/diagram-design/references/type-unit-grid.md +63 -0
- package/vendor/diagram-design/references/type-venn.md +26 -0
- package/vendor/diagram-design/references/type-wardley.md +39 -0
- package/vendor/diagram-design/references/type-waterfall.md +75 -0
- package/vendor/diagram-design/scripts/self_check.py +1177 -0
- package/vendor/diagram-design/scripts/verify_geometry.py +696 -0
package/dist/usage.js
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
// The usage ledger: every Claude Code request on this Mac, with its tokens and API-value cost.
|
|
2
|
+
// One engine for both pillars: the monitor zooms out (days, projects, models), the trace zooms in (one
|
|
3
|
+
// conversation). Research: research/monitoring/PICKS.md.
|
|
4
|
+
//
|
|
5
|
+
// - Reads only numbers and structure from ~/.claude/projects (usage, model, time, folder, the AI-written title),
|
|
6
|
+
// never what you or Claude wrote.
|
|
7
|
+
// - Dedupe: Claude Code writes one row per content block, each carrying the same usage. Summing rows counts
|
|
8
|
+
// 2.15× the real tokens on the first Mac we measured. Rows are grouped by message.id + requestId, keeping
|
|
9
|
+
// the largest (codeburn parser.ts, ccusage dedupe.rs; MIT).
|
|
10
|
+
// - Cost is *calculated* from LiteLLM prices (vendor/codeburn/prices.ts): the logs carry no cost. Away runs
|
|
11
|
+
// come from Chompyy's own records, where Claude Code *recorded* the cost.
|
|
12
|
+
// - A per-file cache (size + mtime) keeps re-reads fast, and keeps rows of files Claude Code has since cleaned up.
|
|
13
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
14
|
+
import { join } from 'node:path';
|
|
15
|
+
import { projectsDir } from './dream.js';
|
|
16
|
+
import { homePath, readJson, writeJson } from './home.js';
|
|
17
|
+
import { CLAUDE_PRICES } from './vendor/codeburn/prices.js';
|
|
18
|
+
/** Bump when parsing or pricing changes, so old cached rows are re-read. */
|
|
19
|
+
export const CACHE_VERSION = 3;
|
|
20
|
+
export function usageCachePath() {
|
|
21
|
+
return homePath('usage-cache.json');
|
|
22
|
+
}
|
|
23
|
+
// ---------- prices ----------
|
|
24
|
+
/** USD for one request at list prices (codeburn models.ts calculateCost rules). Null when the model has no price. */
|
|
25
|
+
export function priceOf(model, t, fast = false) {
|
|
26
|
+
const row = priceRow(model);
|
|
27
|
+
if (!row)
|
|
28
|
+
return null;
|
|
29
|
+
const [baseIn, baseOut, baseWrite, baseRead, fastMul, tier] = row;
|
|
30
|
+
const prompt = t.input + t.cacheRead + t.cacheWrite5m + t.cacheWrite1h;
|
|
31
|
+
const long = tier && prompt > tier.threshold ? tier : null;
|
|
32
|
+
const input = long?.input ?? baseIn;
|
|
33
|
+
const output = long?.output ?? baseOut;
|
|
34
|
+
const write = (long ? long.cacheWrite : baseWrite) ?? input * 1.25;
|
|
35
|
+
const read = (long ? long.cacheRead : baseRead) ?? input * 0.1;
|
|
36
|
+
const usd = t.input * input + t.output * output + t.cacheWrite5m * write + t.cacheWrite1h * write * 1.6 + t.cacheRead * read;
|
|
37
|
+
return usd * (fast && fastMul ? fastMul : 1);
|
|
38
|
+
}
|
|
39
|
+
function priceRow(model) {
|
|
40
|
+
const m = model.replace(/\[.*\]$/, '');
|
|
41
|
+
return CLAUDE_PRICES[m] ?? CLAUDE_PRICES[m.replace(/-\d{8}$/, '')] ?? null;
|
|
42
|
+
}
|
|
43
|
+
// ---------- reading ----------
|
|
44
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) && v > 0 ? v : 0);
|
|
45
|
+
const total = (r) => r.input + r.output + r.cacheRead + r.cacheWrite5m + r.cacheWrite1h;
|
|
46
|
+
/** One session file → its requests (deduped within the file) and conversation titles. */
|
|
47
|
+
export function parseSessionFile(file) {
|
|
48
|
+
const byKey = new Map();
|
|
49
|
+
const titles = {};
|
|
50
|
+
const prs = new Map();
|
|
51
|
+
let workspace = '';
|
|
52
|
+
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
53
|
+
// Only rows that can matter are parsed; message rows are mostly text we don't read.
|
|
54
|
+
const usage = line.includes('"usage"');
|
|
55
|
+
if (!usage && !line.includes('"ai-title"') && !line.includes('"pr-link"'))
|
|
56
|
+
continue;
|
|
57
|
+
let e;
|
|
58
|
+
try {
|
|
59
|
+
e = JSON.parse(line);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (e.type === 'ai-title' && typeof e.aiTitle === 'string' && typeof e.sessionId === 'string') {
|
|
65
|
+
titles[e.sessionId] = e.aiTitle.slice(0, 120);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (e.type === 'pr-link' && typeof e.prUrl === 'string' && typeof e.sessionId === 'string') {
|
|
69
|
+
// Claude Code writes the same link many times (2,084 rows, 115 distinct on the first Mac): keep the first.
|
|
70
|
+
const k = `${e.sessionId} ${e.prUrl}`;
|
|
71
|
+
if (!prs.has(k))
|
|
72
|
+
prs.set(k, { session: e.sessionId, repo: String(e.prRepository ?? ''), number: Number(e.prNumber ?? 0), url: e.prUrl, at: String(e.timestamp ?? '') });
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const msg = e.message;
|
|
76
|
+
if (e.type !== 'assistant' || !msg?.id || !msg.usage || !msg.model || msg.model === '<synthetic>')
|
|
77
|
+
continue;
|
|
78
|
+
if (!workspace && typeof e.cwd === 'string')
|
|
79
|
+
workspace = e.cwd;
|
|
80
|
+
const u = msg.usage;
|
|
81
|
+
const cc = (u.cache_creation ?? {});
|
|
82
|
+
const write = num(u.cache_creation_input_tokens);
|
|
83
|
+
const write1h = Math.min(write, num(cc.ephemeral_1h_input_tokens));
|
|
84
|
+
const row = {
|
|
85
|
+
key: `${msg.id}:${typeof e.requestId === 'string' ? e.requestId : ''}`,
|
|
86
|
+
session: String(e.sessionId ?? ''),
|
|
87
|
+
...(typeof e.agentId === 'string' ? { agent: e.agentId } : {}),
|
|
88
|
+
workspace, // where the conversation started: Claude cd-ing into cli/ mid-session is still the same project
|
|
89
|
+
model: msg.model,
|
|
90
|
+
at: String(e.timestamp ?? ''),
|
|
91
|
+
input: num(u.input_tokens),
|
|
92
|
+
output: num(u.output_tokens),
|
|
93
|
+
cacheRead: num(u.cache_read_input_tokens),
|
|
94
|
+
cacheWrite5m: write - write1h,
|
|
95
|
+
cacheWrite1h: write1h,
|
|
96
|
+
costUsd: 0,
|
|
97
|
+
basis: 'calculated',
|
|
98
|
+
tools: Array.isArray(msg.content) ? [...new Set(msg.content.filter((b) => b?.type === 'tool_use' && b.name).map((b) => b.name))] : [],
|
|
99
|
+
};
|
|
100
|
+
const price = priceOf(row.model, row, u.speed === 'fast');
|
|
101
|
+
row.costUsd = price ?? 0;
|
|
102
|
+
if (price === null)
|
|
103
|
+
row.basis = 'unpriced';
|
|
104
|
+
const had = byKey.get(row.key);
|
|
105
|
+
// Keep the largest (in practice the last) copy, but the first copy's time: when the request happened.
|
|
106
|
+
// One row per content block: gather every block's tools onto the kept copy.
|
|
107
|
+
const tools = [...new Set([...(had?.tools ?? []), ...(row.tools ?? [])])];
|
|
108
|
+
if (!had)
|
|
109
|
+
byKey.set(row.key, row);
|
|
110
|
+
else if (total(row) >= total(had))
|
|
111
|
+
byKey.set(row.key, { ...row, at: had.at || row.at, tools });
|
|
112
|
+
else
|
|
113
|
+
had.tools = tools;
|
|
114
|
+
}
|
|
115
|
+
return { rows: [...byKey.values()], titles, prs: [...prs.values()] };
|
|
116
|
+
}
|
|
117
|
+
/** Every session file: projects/<folder>/<session>.jsonl and their subagents/<agent>.jsonl. */
|
|
118
|
+
export function sessionFiles(root = projectsDir()) {
|
|
119
|
+
if (!existsSync(root))
|
|
120
|
+
return [];
|
|
121
|
+
const out = [];
|
|
122
|
+
const walk = (dir, depth) => {
|
|
123
|
+
let names;
|
|
124
|
+
try {
|
|
125
|
+
names = readdirSync(dir, { withFileTypes: true });
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
for (const n of names) {
|
|
131
|
+
const p = join(dir, n.name);
|
|
132
|
+
if (n.isFile() && n.name.endsWith('.jsonl'))
|
|
133
|
+
out.push(p);
|
|
134
|
+
else if (n.isDirectory() && depth < 3)
|
|
135
|
+
walk(p, depth + 1);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
walk(root, 0);
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
/** All requests on this Mac, deduped across files, plus Chompyy's away runs. */
|
|
142
|
+
export function loadLedger() {
|
|
143
|
+
const cache = readJson(usageCachePath(), { version: CACHE_VERSION, files: {} });
|
|
144
|
+
if (cache.version !== CACHE_VERSION)
|
|
145
|
+
cache.files = {};
|
|
146
|
+
const files = sessionFiles();
|
|
147
|
+
let parsed = 0;
|
|
148
|
+
for (const f of files) {
|
|
149
|
+
let st;
|
|
150
|
+
try {
|
|
151
|
+
st = statSync(f);
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
const had = cache.files[f];
|
|
157
|
+
if (had && had.size === st.size && had.mtimeMs === st.mtimeMs)
|
|
158
|
+
continue;
|
|
159
|
+
cache.files[f] = { size: st.size, mtimeMs: st.mtimeMs, ...parseSessionFile(f) };
|
|
160
|
+
parsed++;
|
|
161
|
+
}
|
|
162
|
+
// Files Claude Code has cleaned up stay in the cache: the ledger outlives the transcripts.
|
|
163
|
+
if (parsed)
|
|
164
|
+
writeJson(usageCachePath(), { version: CACHE_VERSION, files: cache.files });
|
|
165
|
+
const byKey = new Map();
|
|
166
|
+
const titles = {};
|
|
167
|
+
const prs = new Map();
|
|
168
|
+
for (const entry of Object.values(cache.files)) {
|
|
169
|
+
Object.assign(titles, entry.titles);
|
|
170
|
+
for (const p of entry.prs ?? []) {
|
|
171
|
+
const k = `${p.session} ${p.url}`;
|
|
172
|
+
if (!prs.has(k) || p.at < prs.get(k).at)
|
|
173
|
+
prs.set(k, p);
|
|
174
|
+
}
|
|
175
|
+
for (const r of entry.rows) {
|
|
176
|
+
const had = byKey.get(r.key);
|
|
177
|
+
if (!had || total(r) > total(had))
|
|
178
|
+
byKey.set(r.key, r);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const rows = [...byKey.values(), ...awayRows(titles)];
|
|
182
|
+
return { rows, titles, prs: [...prs.values()], files: files.length, parsed };
|
|
183
|
+
}
|
|
184
|
+
/** Away runs aren't saved as sessions (--no-session-persistence); their tokens and cost come from Chompyy's records. */
|
|
185
|
+
function awayRows(titles) {
|
|
186
|
+
const path = homePath('runs.jsonl');
|
|
187
|
+
if (!existsSync(path))
|
|
188
|
+
return [];
|
|
189
|
+
const out = [];
|
|
190
|
+
readFileSync(path, 'utf8').split('\n').forEach((line, i) => {
|
|
191
|
+
if (!line.trim())
|
|
192
|
+
return;
|
|
193
|
+
try {
|
|
194
|
+
const r = JSON.parse(line);
|
|
195
|
+
if (!r.tokens)
|
|
196
|
+
return;
|
|
197
|
+
titles[`chompyy-card-${r.card}`] = `#${r.card} ${r.title}`.slice(0, 120);
|
|
198
|
+
out.push({
|
|
199
|
+
key: `chompyy-run-${i}`,
|
|
200
|
+
session: `chompyy-card-${r.card}`,
|
|
201
|
+
workspace: r.cwd,
|
|
202
|
+
model: r.tokens.models[0] ?? 'unknown',
|
|
203
|
+
at: r.at,
|
|
204
|
+
input: r.tokens.input,
|
|
205
|
+
output: r.tokens.output,
|
|
206
|
+
cacheRead: r.tokens.cacheRead,
|
|
207
|
+
cacheWrite5m: r.tokens.cacheWrite,
|
|
208
|
+
cacheWrite1h: 0,
|
|
209
|
+
costUsd: r.tokens.costUsd,
|
|
210
|
+
basis: 'recorded',
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
catch { }
|
|
214
|
+
});
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
const zero = () => ({ requests: 0, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, tokens: 0, costUsd: 0 });
|
|
218
|
+
function add(t, r) {
|
|
219
|
+
t.requests++;
|
|
220
|
+
t.input += r.input;
|
|
221
|
+
t.output += r.output;
|
|
222
|
+
t.cacheRead += r.cacheRead;
|
|
223
|
+
t.cacheWrite += r.cacheWrite5m + r.cacheWrite1h;
|
|
224
|
+
t.tokens += total(r);
|
|
225
|
+
t.costUsd += r.costUsd;
|
|
226
|
+
return t;
|
|
227
|
+
}
|
|
228
|
+
const round = (t) => ({ ...t, costUsd: Math.round(t.costUsd * 100) / 100 });
|
|
229
|
+
/** Local calendar day (YYYY-MM-DD). */
|
|
230
|
+
export function localDay(iso) {
|
|
231
|
+
const d = new Date(iso);
|
|
232
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* `canShowTitle`: may this folder's conversation titles be shown? The CLI passes the nightly read's ticks, so a
|
|
236
|
+
* desktop-app chat or a folder you left unticked shows its numbers but not what it was about.
|
|
237
|
+
*/
|
|
238
|
+
export function usageView(ledger, now, days = 7, top = 10, canShowTitle = () => true) {
|
|
239
|
+
const start = new Date(now);
|
|
240
|
+
start.setHours(0, 0, 0, 0);
|
|
241
|
+
start.setDate(start.getDate() - (days - 1));
|
|
242
|
+
const from = start.toISOString();
|
|
243
|
+
const inRange = ledger.rows.filter((r) => r.at >= from && r.at <= now.toISOString());
|
|
244
|
+
const dayMap = new Map();
|
|
245
|
+
for (let i = 0; i < days; i++) {
|
|
246
|
+
const d = new Date(start);
|
|
247
|
+
d.setDate(d.getDate() + i);
|
|
248
|
+
dayMap.set(localDay(d.toISOString()), zero());
|
|
249
|
+
}
|
|
250
|
+
const ws = new Map();
|
|
251
|
+
const models = new Map();
|
|
252
|
+
const convs = new Map();
|
|
253
|
+
const helperOnly = new Set();
|
|
254
|
+
const all = zero();
|
|
255
|
+
for (const r of inRange) {
|
|
256
|
+
add(all, r);
|
|
257
|
+
add(dayMap.get(localDay(r.at)) ?? zero(), r);
|
|
258
|
+
add(ws.get(r.workspace) ?? ws.set(r.workspace, zero()).get(r.workspace), r);
|
|
259
|
+
add(models.get(r.model) ?? models.set(r.model, zero()).get(r.model), r);
|
|
260
|
+
let c = convs.get(r.session);
|
|
261
|
+
// A conversation's folder (and so whether its title shows) comes from the main session, never a subagent
|
|
262
|
+
// working elsewhere: a helper's temp folder hid the title of a whole conversation (2026-11-21).
|
|
263
|
+
if (c && !r.agent && helperOnly.has(r.session)) {
|
|
264
|
+
helperOnly.delete(r.session);
|
|
265
|
+
const shown = c.away || canShowTitle(r.workspace);
|
|
266
|
+
Object.assign(c, { workspace: r.workspace, title: shown ? ledger.titles[r.session] ?? null : null, private: !shown });
|
|
267
|
+
}
|
|
268
|
+
if (!c) {
|
|
269
|
+
if (r.agent)
|
|
270
|
+
helperOnly.add(r.session);
|
|
271
|
+
const away = r.basis === 'recorded';
|
|
272
|
+
const shown = away || canShowTitle(r.workspace);
|
|
273
|
+
c = { ...zero(), session: r.session, title: shown ? ledger.titles[r.session] ?? null : null, workspace: r.workspace, start: r.at, end: r.at, models: [], away, private: !shown };
|
|
274
|
+
convs.set(r.session, c);
|
|
275
|
+
}
|
|
276
|
+
add(c, r);
|
|
277
|
+
if (r.at < c.start)
|
|
278
|
+
c.start = r.at;
|
|
279
|
+
if (r.at > c.end)
|
|
280
|
+
c.end = r.at;
|
|
281
|
+
if (!c.models.includes(r.model))
|
|
282
|
+
c.models.push(r.model);
|
|
283
|
+
}
|
|
284
|
+
const sortTally = (xs) => xs.sort((a, b) => b.total.costUsd - a.total.costUsd);
|
|
285
|
+
const today = dayMap.get(localDay(now.toISOString())) ?? zero();
|
|
286
|
+
return {
|
|
287
|
+
from,
|
|
288
|
+
days: [...dayMap].map(([day, t]) => ({ day, total: round(t) })),
|
|
289
|
+
total: round(all),
|
|
290
|
+
today: round(today),
|
|
291
|
+
byWorkspace: sortTally([...ws].map(([workspace, t]) => ({ workspace, total: round(t) }))),
|
|
292
|
+
byModel: sortTally([...models].map(([model, t]) => ({ model, total: round(t) }))),
|
|
293
|
+
conversations: [...convs.values()].sort((a, b) => b.costUsd - a.costUsd).slice(0, top).map((c) => ({ ...c, ...round(c) })),
|
|
294
|
+
unpriced: inRange.filter((r) => r.basis === 'unpriced').length,
|
|
295
|
+
files: ledger.files,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
export function compactTokens(n) {
|
|
299
|
+
if (n >= 1e9)
|
|
300
|
+
return `${(n / 1e9).toFixed(1)}B`;
|
|
301
|
+
if (n >= 1e6)
|
|
302
|
+
return `${(n / 1e6).toFixed(1)}M`;
|
|
303
|
+
if (n >= 1e3)
|
|
304
|
+
return `${Math.round(n / 1e3)}k`;
|
|
305
|
+
return String(n);
|
|
306
|
+
}
|
|
307
|
+
const usd = (n) => `$${n >= 100 ? Math.round(n) : n.toFixed(2)}`;
|
|
308
|
+
export function formatUsage(v, home = '') {
|
|
309
|
+
const short = (p) => (home && p.startsWith(home) ? `~${p.slice(home.length)}` : p) || '(unknown folder)';
|
|
310
|
+
const peak = Math.max(1, ...v.days.map((d) => d.total.tokens));
|
|
311
|
+
const lines = [
|
|
312
|
+
`Claude Code on this Mac, last ${v.days.length} days · ${compactTokens(v.total.tokens)} tokens · ${usd(v.total.costUsd)} at API prices`,
|
|
313
|
+
`(On a subscription you pay your plan, not this: it's the value you got. Cost is calculated from list prices; away runs are as Claude Code recorded them.)`,
|
|
314
|
+
'',
|
|
315
|
+
`Today ${compactTokens(v.today.tokens).padStart(6)} ${usd(v.today.costUsd).padStart(8)} ${v.today.requests} requests`,
|
|
316
|
+
'',
|
|
317
|
+
'Day by day',
|
|
318
|
+
...v.days.map((d) => ` ${d.day.slice(5)} ${'█'.repeat(Math.round((d.total.tokens / peak) * 24)).padEnd(24)} ${compactTokens(d.total.tokens).padStart(6)} ${usd(d.total.costUsd).padStart(8)}`),
|
|
319
|
+
'',
|
|
320
|
+
'By project',
|
|
321
|
+
...v.byWorkspace.slice(0, 6).map((w) => ` ${usd(w.total.costUsd).padStart(8)} ${compactTokens(w.total.tokens).padStart(6)} ${short(w.workspace)}`),
|
|
322
|
+
'',
|
|
323
|
+
'By model',
|
|
324
|
+
...v.byModel.map((m) => ` ${usd(m.total.costUsd).padStart(8)} ${compactTokens(m.total.tokens).padStart(6)} ${m.model}`),
|
|
325
|
+
'',
|
|
326
|
+
'Costliest conversations',
|
|
327
|
+
...v.conversations.map((c) => ` ${usd(c.costUsd).padStart(8)} ${compactTokens(c.tokens).padStart(6)} ${c.away ? '[away] ' : ''}${c.private ? '(title hidden: not a workspace you ticked)' : c.title ?? c.session.slice(0, 8)} · ${short(c.workspace).split('/').pop()} · ${c.requests} request${c.requests === 1 ? '' : 's'} · ${c.start.slice(5, 10)}`),
|
|
328
|
+
];
|
|
329
|
+
const cacheIn = v.total.input + v.total.cacheRead + v.total.cacheWrite;
|
|
330
|
+
if (cacheIn)
|
|
331
|
+
lines.push('', `Cache: ${Math.round((v.total.cacheRead / cacheIn) * 100)}% of input was read from the cache (cheap); ${compactTokens(v.total.cacheWrite)} written to it.`);
|
|
332
|
+
if (v.unpriced)
|
|
333
|
+
lines.push(`${v.unpriced} request(s) use a model with no price yet; counted as $0.`);
|
|
334
|
+
return lines.join('\n');
|
|
335
|
+
}
|
|
336
|
+
// ---------- kinds of work, periods, comparisons, pull requests ----------
|
|
337
|
+
/**
|
|
338
|
+
* What a request did, from the tools it called: works in any language and reads no text (codeburn guesses
|
|
339
|
+
* from the words of your prompt instead). Order is priority: a request that edits and reads is "Coding".
|
|
340
|
+
*/
|
|
341
|
+
export const KINDS = ['Coding', 'Delegating', 'Research', 'Running commands', 'Reading code', 'Planning', 'Conversation'];
|
|
342
|
+
const EDIT = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit']);
|
|
343
|
+
const READ = new Set(['Read', 'Grep', 'Glob', 'LS']);
|
|
344
|
+
const WEB = new Set(['WebSearch', 'WebFetch']);
|
|
345
|
+
const DELEGATE = new Set(['Task', 'Agent']);
|
|
346
|
+
const PLAN = new Set(['TodoWrite', 'TaskCreate', 'TaskUpdate', 'ExitPlanMode', 'AskUserQuestion']);
|
|
347
|
+
export function kindOf(tools) {
|
|
348
|
+
const t = tools ?? [];
|
|
349
|
+
if (t.some((x) => EDIT.has(x)))
|
|
350
|
+
return 'Coding';
|
|
351
|
+
if (t.some((x) => DELEGATE.has(x)))
|
|
352
|
+
return 'Delegating';
|
|
353
|
+
if (t.some((x) => WEB.has(x)))
|
|
354
|
+
return 'Research';
|
|
355
|
+
if (t.includes('Bash'))
|
|
356
|
+
return 'Running commands';
|
|
357
|
+
if (t.some((x) => READ.has(x)))
|
|
358
|
+
return 'Reading code';
|
|
359
|
+
if (t.some((x) => PLAN.has(x)))
|
|
360
|
+
return 'Planning';
|
|
361
|
+
return t.length ? 'Running commands' : 'Conversation';
|
|
362
|
+
}
|
|
363
|
+
export const PERIODS = ['today', '7d', '30d', 'month'];
|
|
364
|
+
/** Days a period covers, ending today: "month" is the 1st of this month to today. */
|
|
365
|
+
export function periodDays(p, now) {
|
|
366
|
+
return p === 'today' ? 1 : p === '7d' ? 7 : p === '30d' ? 30 : now.getDate();
|
|
367
|
+
}
|
|
368
|
+
export function byKind(ledger, from, to) {
|
|
369
|
+
const m = new Map();
|
|
370
|
+
for (const r of ledger.rows) {
|
|
371
|
+
if (r.at < from || r.at > to)
|
|
372
|
+
continue;
|
|
373
|
+
const k = r.basis === 'recorded' ? 'Coding' : kindOf(r.tools); // away runs: cards change code
|
|
374
|
+
add(m.get(k) ?? m.set(k, zero()).get(k), r);
|
|
375
|
+
}
|
|
376
|
+
return [...m].map(([kind, t]) => ({ kind, total: round(t) })).sort((a, b) => b.total.costUsd - a.total.costUsd);
|
|
377
|
+
}
|
|
378
|
+
/** Cost per pull request opened in [from, to]. Titles follow the same rule as conversations. */
|
|
379
|
+
export function prCosts(ledger, from, to, canShowTitle = () => true) {
|
|
380
|
+
const bySession = new Map();
|
|
381
|
+
for (const p of ledger.prs)
|
|
382
|
+
(bySession.get(p.session) ?? bySession.set(p.session, []).get(p.session)).push(p);
|
|
383
|
+
const rowsBySession = new Map();
|
|
384
|
+
for (const r of ledger.rows)
|
|
385
|
+
(rowsBySession.get(r.session) ?? rowsBySession.set(r.session, []).get(r.session)).push(r);
|
|
386
|
+
const out = [];
|
|
387
|
+
for (const [session, links] of bySession) {
|
|
388
|
+
links.sort((a, b) => a.at.localeCompare(b.at));
|
|
389
|
+
const rows = rowsBySession.get(session) ?? [];
|
|
390
|
+
const main = rows.find((r) => !r.agent);
|
|
391
|
+
links.forEach((p, i) => {
|
|
392
|
+
if (p.at < from || p.at > to)
|
|
393
|
+
return;
|
|
394
|
+
const since = links[i - 1]?.at ?? '';
|
|
395
|
+
const t = zero();
|
|
396
|
+
for (const r of rows)
|
|
397
|
+
if (r.at > since && r.at <= p.at)
|
|
398
|
+
add(t, r);
|
|
399
|
+
if (!t.requests)
|
|
400
|
+
return; // a PR it only mentioned, with no work before it
|
|
401
|
+
out.push({ repo: p.repo, number: p.number, url: p.url, session, title: main && canShowTitle(main.workspace) ? ledger.titles[session] ?? null : null, at: p.at, total: round(t) });
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
return out.sort((a, b) => b.at.localeCompare(a.at));
|
|
405
|
+
}
|
|
406
|
+
/** List prices per month (USD) by the plan label the quota reader reports; override with config `planPriceUsd`. */
|
|
407
|
+
export const PLAN_PRICES = { Pro: 20, 'Max 5x': 100, Max: 100, 'Max 20x': 200, Ultra: 200 };
|
|
408
|
+
const pct = (a, b) => (b > 0 ? Math.round(((a - b) / b) * 100) : null);
|
|
409
|
+
export function compare(ledger, now, plan) {
|
|
410
|
+
const dayStart = (offset) => {
|
|
411
|
+
const d = new Date(now);
|
|
412
|
+
d.setHours(0, 0, 0, 0);
|
|
413
|
+
d.setDate(d.getDate() + offset);
|
|
414
|
+
return d.toISOString();
|
|
415
|
+
};
|
|
416
|
+
const sum = (from, to) => {
|
|
417
|
+
const t = zero();
|
|
418
|
+
for (const r of ledger.rows)
|
|
419
|
+
if (r.at >= from && r.at < to)
|
|
420
|
+
add(t, r);
|
|
421
|
+
return t;
|
|
422
|
+
};
|
|
423
|
+
const today = sum(dayStart(0), now.toISOString());
|
|
424
|
+
const yesterday = sum(dayStart(-1), dayStart(0));
|
|
425
|
+
const week = sum(dayStart(-7), dayStart(0));
|
|
426
|
+
const avg7 = { ...week, requests: Math.round(week.requests / 7), input: week.input / 7, output: week.output / 7, cacheRead: week.cacheRead / 7, cacheWrite: week.cacheWrite / 7, tokens: week.tokens / 7, costUsd: week.costUsd / 7 };
|
|
427
|
+
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1).toISOString();
|
|
428
|
+
const toDate = sum(monthStart, now.toISOString());
|
|
429
|
+
const lastStart = new Date(now.getFullYear(), now.getMonth() - 1, 1);
|
|
430
|
+
const lastEnd = new Date(lastStart);
|
|
431
|
+
lastEnd.setDate(Math.min(now.getDate(), new Date(now.getFullYear(), now.getMonth(), 0).getDate()));
|
|
432
|
+
lastEnd.setHours(now.getHours(), now.getMinutes(), now.getSeconds());
|
|
433
|
+
const lastMonthSameDays = sum(lastStart.toISOString(), lastEnd.toISOString());
|
|
434
|
+
const daysInMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0).getDate();
|
|
435
|
+
const elapsed = (now.getTime() - Date.parse(monthStart)) / 86400_000;
|
|
436
|
+
const projectedUsd = elapsed > 0 ? (toDate.costUsd / elapsed) * daysInMonth : 0;
|
|
437
|
+
const price = plan.priceUsd ?? (plan.label ? PLAN_PRICES[plan.label] ?? null : null);
|
|
438
|
+
return {
|
|
439
|
+
yesterday: round(yesterday),
|
|
440
|
+
avg7: round(avg7),
|
|
441
|
+
vsYesterdayPct: pct(today.costUsd, yesterday.costUsd),
|
|
442
|
+
month: {
|
|
443
|
+
toDate: round(toDate),
|
|
444
|
+
lastMonthSameDays: round(lastMonthSameDays),
|
|
445
|
+
vsLastMonthPct: pct(toDate.costUsd, lastMonthSameDays.costUsd),
|
|
446
|
+
projectedUsd: Math.round(projectedUsd * 100) / 100,
|
|
447
|
+
plan: price && plan.label ? { label: plan.label, priceUsd: price, multiple: Math.round((toDate.costUsd / price) * 10) / 10, projectedMultiple: Math.round((projectedUsd / price) * 10) / 10 } : null,
|
|
448
|
+
},
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
export function formatExtras(kinds, prs, c) {
|
|
452
|
+
const lines = ['', 'What the work was (by the tools each request used)'];
|
|
453
|
+
const all = kinds.reduce((n, k) => n + k.total.costUsd, 0) || 1;
|
|
454
|
+
for (const k of kinds)
|
|
455
|
+
lines.push(` ${usd(k.total.costUsd).padStart(8)} ${String(Math.round((k.total.costUsd / all) * 100)).padStart(3)}% ${k.kind}`);
|
|
456
|
+
if (prs.length) {
|
|
457
|
+
lines.push('', 'Pull requests (what the conversation spent until it opened each one)');
|
|
458
|
+
for (const p of prs.slice(0, 10))
|
|
459
|
+
lines.push(` ${usd(p.total.costUsd).padStart(8)} ${p.repo.split('/').pop()}#${p.number}${p.title ? ` · ${p.title}` : ''} · ${p.at.slice(5, 10)}`);
|
|
460
|
+
}
|
|
461
|
+
const m = c.month;
|
|
462
|
+
lines.push('', `Yesterday ${usd(c.yesterday.costUsd)} · 7-day average ${usd(c.avg7.costUsd)}${c.vsYesterdayPct === null ? '' : ` · today vs yesterday ${c.vsYesterdayPct > 0 ? '+' : ''}${c.vsYesterdayPct}%`}`);
|
|
463
|
+
lines.push(`This month ${usd(m.toDate.costUsd)} so far${m.vsLastMonthPct === null ? '' : ` (${m.vsLastMonthPct > 0 ? '+' : ''}${m.vsLastMonthPct}% vs the same days last month)`} · on pace for ${usd(m.projectedUsd)}`);
|
|
464
|
+
if (m.plan)
|
|
465
|
+
lines.push(`Your ${m.plan.label} plan ($${m.plan.priceUsd}/month) has done ${m.plan.multiple}× its price in API-priced work this month; on pace for ${m.plan.projectedMultiple}×.`);
|
|
466
|
+
return lines.join('\n');
|
|
467
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const CLAUDE_PRICES = {
|
|
2
|
+
"claude-3-5-haiku": [1e-06, 5e-06],
|
|
3
|
+
"claude-3-5-sonnet": [3e-06, 1.5e-05, null, 3e-07],
|
|
4
|
+
"claude-3-7-sonnet": [3e-06, 1.5e-05, null, 3e-07],
|
|
5
|
+
"claude-3-haiku": [2.5e-07, 1.25e-06],
|
|
6
|
+
"claude-3-opus": [1.5e-05, 7.5e-05],
|
|
7
|
+
"claude-3-sonnet": [3e-06, 1.5e-05],
|
|
8
|
+
"claude-4-opus": [5e-06, 2.5e-05, null, 5e-07],
|
|
9
|
+
"claude-4-sonnet": [3e-06, 1.5e-05, null, 3e-07],
|
|
10
|
+
"claude-fable-5": [1e-05, 5e-05, 1.25e-05, 1e-06],
|
|
11
|
+
"claude-fable-5-1": [1e-05, 5e-05, 1.25e-05, 2.5e-07],
|
|
12
|
+
"claude-fable-5.1": [1e-05, 5e-05, 1.25e-05, 2.5e-07],
|
|
13
|
+
"claude-haiku-4-5": [1e-06, 5e-06, 1.25e-06, 1e-07],
|
|
14
|
+
"claude-haiku-4-5-20251001": [1e-06, 5e-06, 1.25e-06, 1e-07],
|
|
15
|
+
"claude-haiku-4.5": [1e-06, 5e-06, 1.25e-06, 1e-07],
|
|
16
|
+
"claude-haiku-5-5": [1e-07, 5e-07, 1.25e-07, 1e-08, null, { "threshold": 100000, "input": 5e-07, "output": 2.5e-06, "cacheWrite": 6.25e-07, "cacheRead": 5e-08 }],
|
|
17
|
+
"claude-haiku-5.5": [1e-07, 5e-07, 1.25e-07, 1e-08, null, { "threshold": 100000, "input": 5e-07, "output": 2.5e-06, "cacheWrite": 6.25e-07, "cacheRead": 5e-08 }],
|
|
18
|
+
"claude-mythos-5": [1e-05, 5e-05, 1.25e-05, 1e-06],
|
|
19
|
+
"claude-mythos-5-1": [1e-05, 5e-05, 1.25e-05, 2.5e-07],
|
|
20
|
+
"claude-mythos-preview": [1e-05, 5e-05, 1.25e-05, 1e-06],
|
|
21
|
+
"claude-opus-4": [1.5e-05, 7.5e-05, 1.875e-05, 1.5e-06],
|
|
22
|
+
"claude-opus-4-5": [5e-06, 2.5e-05, 6.25e-06, 5e-07],
|
|
23
|
+
"claude-opus-4-5-20251101": [5e-06, 2.5e-05, 6.25e-06, 5e-07],
|
|
24
|
+
"claude-opus-4-6": [5e-06, 2.5e-05, 6.25e-06, 5e-07],
|
|
25
|
+
"claude-opus-4-6-20260205": [5e-06, 2.5e-05, 6.25e-06, 5e-07],
|
|
26
|
+
"claude-opus-4-7": [5e-06, 2.5e-05, 6.25e-06, 5e-07],
|
|
27
|
+
"claude-opus-4-7-20260416": [5e-06, 2.5e-05, 6.25e-06, 5e-07],
|
|
28
|
+
"claude-opus-4-8": [5e-06, 2.5e-05, 6.25e-06, 5e-07, 2],
|
|
29
|
+
"claude-opus-4-8-think": [5e-06, 2.5e-05, 6.25e-06, 5e-07],
|
|
30
|
+
"claude-opus-4.8": [5e-06, 2.5e-05, 6.25e-06, 5e-07],
|
|
31
|
+
"claude-opus-4.8-fast": [1e-05, 5e-05, 1.25e-05, 1e-06],
|
|
32
|
+
"claude-opus-5": [5e-06, 2.5e-05, 6.25e-06, 5e-07, 2],
|
|
33
|
+
"claude-opus-5-5": [4e-06, 2e-05, 5e-06, 2e-07, 2],
|
|
34
|
+
"claude-opus-5-5-fast": [8e-06, 4e-05, 1e-05, 4e-07],
|
|
35
|
+
"claude-opus-5.5": [4e-06, 2e-05, 5e-06, 2e-07],
|
|
36
|
+
"claude-sonnet-4": [3e-06, 1.5e-05, 3.75e-06, 3e-07],
|
|
37
|
+
"claude-sonnet-4-5": [3e-06, 1.5e-05, 3.75e-06, 3e-07, null, { "threshold": 200000, "input": 6e-06, "output": 2.25e-05, "cacheWrite": 7.5e-06, "cacheRead": 6e-07 }],
|
|
38
|
+
"claude-sonnet-4-5-20250929": [3e-06, 1.5e-05, 3.75e-06, 3e-07, null, { "threshold": 200000, "input": 6e-06, "output": 2.25e-05, "cacheWrite": 7.5e-06, "cacheRead": 6e-07 }],
|
|
39
|
+
"claude-sonnet-4-5-20250929-v1:0": [3e-06, 1.5e-05, 3.75e-06, 3e-07, null, { "threshold": 200000, "input": 6e-06, "output": 2.25e-05, "cacheWrite": 7.5e-06, "cacheRead": 6e-07 }],
|
|
40
|
+
"claude-sonnet-4-6": [3e-06, 1.5e-05, 3.75e-06, 3e-07],
|
|
41
|
+
"claude-sonnet-4.6": [3e-06, 1.5e-05, 3.75e-06, 3e-07],
|
|
42
|
+
"claude-sonnet-5": [2e-06, 1e-05, 2.5e-06, 2e-07],
|
|
43
|
+
"claude-sonnet-5-5": [2e-06, 1e-05, 2.5e-06, 1e-07],
|
|
44
|
+
"claude-sonnet-5.5": [2e-06, 1e-05, 2.5e-06, 1e-07],
|
|
45
|
+
};
|
package/dist/verify.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Independent check (FEATURES §5): after a card runs, Chompyy runs the repo's own tests itself, so "Checks
|
|
2
|
+
// pass" no longer rests only on the agent grading its own work. The tests are code the agent may have
|
|
3
|
+
// written, so they run in a macOS sandbox (sandbox-exec): writes only in the card's folder, the tool cache and
|
|
4
|
+
// temp folders; no network; no reads of credential folders. Elsewhere the check is skipped, never run open.
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync, rmSync, symlinkSync } from 'node:fs';
|
|
7
|
+
import { homedir, tmpdir } from 'node:os';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
/** Signs in test output that the sandbox, not the code, stopped it. */
|
|
10
|
+
export function looksSandboxBlocked(output) {
|
|
11
|
+
return /\bEPERM\b|Operation not permitted|ENOTFOUND|EAI_AGAIN|getaddrinfo|network is unreachable|Could not resolve host/i.test(output);
|
|
12
|
+
}
|
|
13
|
+
const read = (p) => (existsSync(p) ? readFileSync(p, 'utf8') : '');
|
|
14
|
+
/** The repo's test command, from what's in the folder. `override` (from config) wins. */
|
|
15
|
+
export function detectCheck(dir, override) {
|
|
16
|
+
if (override?.trim())
|
|
17
|
+
return { argv: ['sh', '-c', override], label: override.trim() };
|
|
18
|
+
const pkg = read(join(dir, 'package.json'));
|
|
19
|
+
if (pkg) {
|
|
20
|
+
try {
|
|
21
|
+
const test = JSON.parse(pkg).scripts?.test;
|
|
22
|
+
if (test && !/no test specified/.test(test)) {
|
|
23
|
+
const pm = existsSync(join(dir, 'pnpm-lock.yaml')) ? 'pnpm' : existsSync(join(dir, 'yarn.lock')) ? 'yarn' : 'npm';
|
|
24
|
+
return { argv: [pm, 'test'], label: `${pm} test`, node: true };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
28
|
+
}
|
|
29
|
+
if (existsSync(join(dir, 'go.mod')))
|
|
30
|
+
return { argv: ['go', 'test', './...'], label: 'go test ./...' };
|
|
31
|
+
if (existsSync(join(dir, 'Cargo.toml')))
|
|
32
|
+
return { argv: ['cargo', 'test', '--offline'], label: 'cargo test --offline' };
|
|
33
|
+
const py = read(join(dir, 'pyproject.toml')) + read(join(dir, 'setup.cfg')) + read(join(dir, 'tox.ini'));
|
|
34
|
+
const hasPyTests = existsSync(join(dir, 'pytest.ini')) || /pytest/.test(py) || (existsSync(join(dir, 'tests')) && readdirSync(join(dir, 'tests')).some((f) => /^test_.*\.py$/.test(f)));
|
|
35
|
+
if (hasPyTests)
|
|
36
|
+
return { argv: ['python3', '-m', 'pytest', '-q'], label: 'pytest' };
|
|
37
|
+
if (/^test:/m.test(read(join(dir, 'Makefile'))))
|
|
38
|
+
return { argv: ['make', 'test'], label: 'make test' };
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Temp folders every box allows writes to: the agent's sandbox during a card AND Chompyy's own check box.
|
|
43
|
+
* One list, so a command that works in one works in the other. macOS tools save files through the per-user
|
|
44
|
+
* temp folder (/private/var/folders/<x>/<y>/T and C): `swift build` writes output-file-map.json via a temp file
|
|
45
|
+
* there, and failed with a permission error in the agent's sandbox while passing in Chompyy's (2026-11-18).
|
|
46
|
+
*/
|
|
47
|
+
export function boxTempDirs() {
|
|
48
|
+
let user;
|
|
49
|
+
try {
|
|
50
|
+
user = dirname(realpathSync(tmpdir()));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
user = '/private/var/folders';
|
|
54
|
+
}
|
|
55
|
+
// tmpdir() is normally <user>/T; anywhere else (TMPDIR overridden), allow it as it is.
|
|
56
|
+
if (!user.startsWith('/private/var/folders/'))
|
|
57
|
+
user = tmpdir();
|
|
58
|
+
return ['/private/tmp', user];
|
|
59
|
+
}
|
|
60
|
+
const sbString = (p) => `"${p.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`;
|
|
61
|
+
const expand = (p) => (p.startsWith('~/') ? join(homedir(), p.slice(2)) : p);
|
|
62
|
+
/** The sandbox-exec profile: everything readable except credentials; writes only where the check needs them. */
|
|
63
|
+
export function sandboxProfile(opts) {
|
|
64
|
+
return [
|
|
65
|
+
'(version 1)',
|
|
66
|
+
'(allow default)',
|
|
67
|
+
'(deny network*)',
|
|
68
|
+
'(allow network* (local unix))',
|
|
69
|
+
'(deny file-write*)',
|
|
70
|
+
`(allow file-write* ${[...opts.writable.map((p) => `(subpath ${sbString(p)})`), ...boxTempDirs().map((p) => `(subpath ${sbString(p)})`), '(literal "/dev/null")', '(literal "/dev/tty")'].join(' ')})`,
|
|
71
|
+
...opts.denyRead.map((p) => `(deny file-read* (subpath ${sbString(expand(p))}))`),
|
|
72
|
+
].join('\n');
|
|
73
|
+
}
|
|
74
|
+
function tail(text, lines = 15) {
|
|
75
|
+
return text
|
|
76
|
+
.replace(/\u001b\[[0-9;]*[A-Za-z]/g, '') // colour codes
|
|
77
|
+
.trimEnd().split('\n').slice(-lines).join('\n').slice(-2000);
|
|
78
|
+
}
|
|
79
|
+
/** Run the repo's tests in the card's folder, sandboxed. Never throws. */
|
|
80
|
+
export async function verifyRun(opts) {
|
|
81
|
+
const at = () => opts.now().toISOString();
|
|
82
|
+
const check = detectCheck(opts.dir, opts.override);
|
|
83
|
+
if (!check)
|
|
84
|
+
return { result: 'not run', why: 'no test command found in the repo', at: at() };
|
|
85
|
+
if (!opts.unsandboxed && (process.platform !== 'darwin' || !existsSync('/usr/bin/sandbox-exec'))) {
|
|
86
|
+
return { result: 'not run', command: check.label, why: 'needs the macOS sandbox (sandbox-exec) to run tests safely', at: at() };
|
|
87
|
+
}
|
|
88
|
+
// A fresh worktree has no node_modules (it's gitignored): borrow your checkout's for the check.
|
|
89
|
+
const writable = [opts.dir, opts.cacheDir];
|
|
90
|
+
let linked = '';
|
|
91
|
+
if (check.node && opts.repoRoot) {
|
|
92
|
+
const mine = join(opts.dir, 'node_modules');
|
|
93
|
+
const theirs = join(opts.repoRoot, 'node_modules');
|
|
94
|
+
if (!existsSync(mine) && existsSync(theirs)) {
|
|
95
|
+
symlinkSync(theirs, mine, 'dir');
|
|
96
|
+
linked = mine;
|
|
97
|
+
writable.push(join(theirs, '.vite'), join(theirs, '.vite-temp'), join(theirs, '.cache')); // test runners' caches and temp files
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const argv = opts.unsandboxed ? check.argv : ['/usr/bin/sandbox-exec', '-p', sandboxProfile({ writable, denyRead: opts.denyRead }), ...check.argv];
|
|
101
|
+
try {
|
|
102
|
+
const r = await run(argv, opts.dir, { ...process.env, ...opts.env, CI: '1', NO_COLOR: '1', FORCE_COLOR: '0' }, opts.timeoutMs);
|
|
103
|
+
if (r.timedOut)
|
|
104
|
+
return { result: 'failed', command: check.label, why: `took longer than ${Math.round(opts.timeoutMs / 60_000)} minutes`, at: at(), tail: tail(r.output) };
|
|
105
|
+
if (r.code === 0)
|
|
106
|
+
return { result: 'passed', command: check.label, why: `${check.label} passed`, at: at() };
|
|
107
|
+
if (!opts.unsandboxed && looksSandboxBlocked(r.output)) {
|
|
108
|
+
return { result: 'failed', command: check.label, why: `${check.label} failed, but the sandbox blocked something it needs (a write outside the folder or the network), so it may not be the change`, at: at(), tail: tail(r.output), sandboxBlocked: true };
|
|
109
|
+
}
|
|
110
|
+
return { result: 'failed', command: check.label, why: `${check.label} exited with ${r.code}`, at: at(), tail: tail(r.output) };
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
return { result: 'not run', command: check.label, why: `couldn't start: ${err instanceof Error ? err.message : err}`, at: at() };
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
if (linked && lstatSync(linked).isSymbolicLink())
|
|
117
|
+
rmSync(linked);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function run(argv, cwd, env, timeoutMs) {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
const child = spawn(argv[0], argv.slice(1), { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: true });
|
|
123
|
+
let output = '';
|
|
124
|
+
let timedOut = false;
|
|
125
|
+
const add = (d) => {
|
|
126
|
+
output = (output + d.toString()).slice(-20_000);
|
|
127
|
+
};
|
|
128
|
+
child.stdout.on('data', add);
|
|
129
|
+
child.stderr.on('data', add);
|
|
130
|
+
const kill = () => {
|
|
131
|
+
try {
|
|
132
|
+
if (child.pid)
|
|
133
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
134
|
+
}
|
|
135
|
+
catch { }
|
|
136
|
+
};
|
|
137
|
+
const timer = setTimeout(() => {
|
|
138
|
+
timedOut = true;
|
|
139
|
+
kill();
|
|
140
|
+
}, timeoutMs);
|
|
141
|
+
child.on('error', (err) => {
|
|
142
|
+
clearTimeout(timer);
|
|
143
|
+
reject(err);
|
|
144
|
+
});
|
|
145
|
+
child.on('close', (code) => {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
resolve({ code, output, timedOut });
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
}
|