costclaw 0.4.0 → 0.5.1
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 +7 -5
- package/dist/index.js +341 -99
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ unit is framed to match how you actually pay.
|
|
|
82
82
|
## Options
|
|
83
83
|
|
|
84
84
|
```
|
|
85
|
-
costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--card [file]]
|
|
85
|
+
costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--no-html] [--card [file]]
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
- `--path <dir>` audit a specific projects directory (default `~/.claude/projects`).
|
|
@@ -91,10 +91,12 @@ costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--h
|
|
|
91
91
|
- `--plan <api|pro|max5x|max20x>` declare how you pay for Claude (see above);
|
|
92
92
|
persisted for later runs.
|
|
93
93
|
- `--json` print the raw, derived `AuditRecord` instead of the human report.
|
|
94
|
-
-
|
|
95
|
-
`costclaw-report.html` in the current directory)
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
- The HTML report is written and opened in your browser **by default**
|
|
95
|
+
(`costclaw-report.html` in the current directory). The file inlines
|
|
96
|
+
everything, so nothing is fetched and nothing is uploaded; the terminal
|
|
97
|
+
report still prints (in color on interactive terminals; set `NO_COLOR` to
|
|
98
|
+
disable). `--html <file>` picks the path; `--no-html` skips the file;
|
|
99
|
+
`--json` runs stay file-free unless `--html` is passed explicitly.
|
|
98
100
|
- `--card [file]` also write a shareable score card SVG (default
|
|
99
101
|
`costclaw-card.svg`): your score, band, recoverable spend, cache hit rate, and
|
|
100
102
|
strongest pillar. A static file, no fonts or network calls.
|
package/dist/index.js
CHANGED
|
@@ -13,8 +13,10 @@ function isPlan(value) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
// ../../packages/engine/src/pricing.ts
|
|
16
|
-
var PRICING_SNAPSHOT_DATE = "2026-
|
|
16
|
+
var PRICING_SNAPSHOT_DATE = "2026-08-03";
|
|
17
17
|
var PRICES_PER_MTOK = Object.freeze({
|
|
18
|
+
"claude-opus-4-8": { input: 5, output: 25, cache_write: 6.25, cache_read: 0.5 },
|
|
19
|
+
"claude-sonnet-5": { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 },
|
|
18
20
|
"claude-opus-4-7": { input: 15, output: 75, cache_write: 18.75, cache_read: 1.5 },
|
|
19
21
|
"claude-opus-4-7[1m]": { input: 15, output: 75, cache_write: 18.75, cache_read: 1.5 },
|
|
20
22
|
"claude-opus-4-6": { input: 15, output: 75, cache_write: 18.75, cache_read: 1.5 },
|
|
@@ -25,14 +27,20 @@ var PRICES_PER_MTOK = Object.freeze({
|
|
|
25
27
|
});
|
|
26
28
|
var FALLBACK = { input: 3, output: 15, cache_write: 3.75, cache_read: 0.3 };
|
|
27
29
|
function priceFor(model) {
|
|
28
|
-
|
|
30
|
+
return lookup(model) ?? FALLBACK;
|
|
31
|
+
}
|
|
32
|
+
function isKnownModel(model) {
|
|
33
|
+
return lookup(model) !== null;
|
|
34
|
+
}
|
|
35
|
+
function lookup(model) {
|
|
36
|
+
if (!model) return null;
|
|
29
37
|
const exact = PRICES_PER_MTOK[model];
|
|
30
38
|
if (exact) return exact;
|
|
31
39
|
const noTag = model.replace(/\[[^\]]*\]$/, "");
|
|
32
40
|
if (PRICES_PER_MTOK[noTag]) return PRICES_PER_MTOK[noTag];
|
|
33
41
|
const noDate = noTag.replace(/-\d{8}$/, "");
|
|
34
42
|
if (PRICES_PER_MTOK[noDate]) return PRICES_PER_MTOK[noDate];
|
|
35
|
-
return
|
|
43
|
+
return null;
|
|
36
44
|
}
|
|
37
45
|
var num = (v) => Number(v) || 0;
|
|
38
46
|
function costForUsage(model, usage) {
|
|
@@ -67,6 +75,17 @@ var EM_OR_EN = /[—–]/;
|
|
|
67
75
|
function hasEmDash(text2) {
|
|
68
76
|
return EM_OR_EN.test(text2);
|
|
69
77
|
}
|
|
78
|
+
var PATH_ENCODED = /^-|^[A-Za-z]--|[\\/]/;
|
|
79
|
+
function slugLooksLikePath(slug) {
|
|
80
|
+
return PATH_ENCODED.test(slug);
|
|
81
|
+
}
|
|
82
|
+
function sanitizeProjectSlug(slug) {
|
|
83
|
+
if (slug == null) return null;
|
|
84
|
+
if (!slugLooksLikePath(slug)) return slug;
|
|
85
|
+
let h = 5381;
|
|
86
|
+
for (let i = 0; i < slug.length; i++) h = (h * 33 ^ slug.charCodeAt(i)) >>> 0;
|
|
87
|
+
return `project-${h.toString(36)}`;
|
|
88
|
+
}
|
|
70
89
|
function sanitizeText(input) {
|
|
71
90
|
let out = input;
|
|
72
91
|
out = out.replace(/[‘’‚‛]/g, "'");
|
|
@@ -180,7 +199,7 @@ function parseSession(text2, opts = {}) {
|
|
|
180
199
|
if (rec.type === "user") s.userRecords += 1;
|
|
181
200
|
else s.assistantRecords += 1;
|
|
182
201
|
const model = rec.message?.model;
|
|
183
|
-
if (model) modelCounts.set(model, (modelCounts.get(model) ?? 0) + 1);
|
|
202
|
+
if (model && model !== "<synthetic>") modelCounts.set(model, (modelCounts.get(model) ?? 0) + 1);
|
|
184
203
|
if (rec.type === "assistant") {
|
|
185
204
|
const { names, events } = extractTools(rec.message?.content);
|
|
186
205
|
for (const n of names) s.toolUsage[n] = (s.toolUsage[n] ?? 0) + 1;
|
|
@@ -634,7 +653,9 @@ function runOptimizer(ctx) {
|
|
|
634
653
|
function analyzeUploads(files) {
|
|
635
654
|
const sessions = files.map(
|
|
636
655
|
(f) => parseSession(f.text, {
|
|
637
|
-
|
|
656
|
+
// Path-encoded slugs are anonymized before grouping so no downstream
|
|
657
|
+
// consumer (optimizer prose, synthesize, the AuditRecord) ever sees one.
|
|
658
|
+
projectSlug: sanitizeProjectSlug(f.projectSlug ?? null),
|
|
638
659
|
kind: f.kind ?? "main",
|
|
639
660
|
parentSessionId: f.parentSessionId ?? null
|
|
640
661
|
})
|
|
@@ -1239,7 +1260,7 @@ function synthesize(report, pillars, cmd, plan = "api") {
|
|
|
1239
1260
|
};
|
|
1240
1261
|
const sevForUsd = (n) => n >= 50 ? "critical" : n >= 10 ? "warn" : "info";
|
|
1241
1262
|
const sWord = (k) => k === 1 ? "session" : "sessions";
|
|
1242
|
-
const exposureMaterial =
|
|
1263
|
+
const exposureMaterial = round23(exposure) > 0;
|
|
1243
1264
|
if (exposureMaterial) {
|
|
1244
1265
|
const ranked = report.projects.map((p) => {
|
|
1245
1266
|
let contrib = 0;
|
|
@@ -2133,7 +2154,7 @@ import { spawn } from "child_process";
|
|
|
2133
2154
|
|
|
2134
2155
|
// src/read-sessions.ts
|
|
2135
2156
|
import { readdir } from "fs/promises";
|
|
2136
|
-
import { readFileSync, openSync, closeSync } from "fs";
|
|
2157
|
+
import { readFileSync, openSync, closeSync, readSync } from "fs";
|
|
2137
2158
|
import { join, relative, sep } from "path";
|
|
2138
2159
|
import { homedir } from "os";
|
|
2139
2160
|
function defaultProjectsPath() {
|
|
@@ -2176,6 +2197,41 @@ function lazyLog(full, meta) {
|
|
|
2176
2197
|
}
|
|
2177
2198
|
};
|
|
2178
2199
|
}
|
|
2200
|
+
var CWD_PROBE_BYTES = 65536;
|
|
2201
|
+
var CWD_PROBE_LINES = 40;
|
|
2202
|
+
function projectNameFromLogs(files) {
|
|
2203
|
+
for (const full of files.slice(0, 3)) {
|
|
2204
|
+
let fd;
|
|
2205
|
+
try {
|
|
2206
|
+
fd = openSync(full, "r");
|
|
2207
|
+
} catch {
|
|
2208
|
+
continue;
|
|
2209
|
+
}
|
|
2210
|
+
try {
|
|
2211
|
+
const buf = Buffer.alloc(CWD_PROBE_BYTES);
|
|
2212
|
+
const n = readSync(fd, buf, 0, CWD_PROBE_BYTES, 0);
|
|
2213
|
+
const lines = buf.toString("utf8", 0, n).split("\n").slice(0, CWD_PROBE_LINES);
|
|
2214
|
+
for (const line of lines) {
|
|
2215
|
+
const trimmed = line.trim();
|
|
2216
|
+
if (!trimmed) continue;
|
|
2217
|
+
let rec;
|
|
2218
|
+
try {
|
|
2219
|
+
rec = JSON.parse(trimmed);
|
|
2220
|
+
} catch {
|
|
2221
|
+
continue;
|
|
2222
|
+
}
|
|
2223
|
+
if (typeof rec.cwd === "string" && rec.cwd) {
|
|
2224
|
+
const parts = rec.cwd.split(/[\\/]+/).filter(Boolean);
|
|
2225
|
+
const base = parts.at(-1);
|
|
2226
|
+
if (base) return base;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
} finally {
|
|
2230
|
+
closeSync(fd);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
return null;
|
|
2234
|
+
}
|
|
2179
2235
|
async function readSessions(rootPath) {
|
|
2180
2236
|
const logs = [];
|
|
2181
2237
|
const skipped = [];
|
|
@@ -2195,13 +2251,14 @@ async function readSessions(rootPath) {
|
|
|
2195
2251
|
continue;
|
|
2196
2252
|
}
|
|
2197
2253
|
const files = await collectJsonl(projPath);
|
|
2254
|
+
const projectSlug = projectNameFromLogs(files) ?? dir.name;
|
|
2198
2255
|
for (const full of files) {
|
|
2199
2256
|
const rel = relative(projPath, full).split(sep).join("/");
|
|
2200
2257
|
const name = `${dir.name}/${rel}`;
|
|
2201
2258
|
const { kind, parentSessionId } = classify(rel);
|
|
2202
2259
|
try {
|
|
2203
2260
|
closeSync(openSync(full, "r"));
|
|
2204
|
-
logs.push(lazyLog(full, { name, kind, parentSessionId, projectSlug
|
|
2261
|
+
logs.push(lazyLog(full, { name, kind, parentSessionId, projectSlug }));
|
|
2205
2262
|
} catch {
|
|
2206
2263
|
skipped.push(name);
|
|
2207
2264
|
}
|
|
@@ -2210,19 +2267,94 @@ async function readSessions(rootPath) {
|
|
|
2210
2267
|
return { logs, skipped };
|
|
2211
2268
|
}
|
|
2212
2269
|
|
|
2270
|
+
// src/ansi.ts
|
|
2271
|
+
var ESC = String.fromCharCode(27);
|
|
2272
|
+
function bandCode(score) {
|
|
2273
|
+
if (score < 40) return "38;5;160";
|
|
2274
|
+
if (score < 60) return "38;5;173";
|
|
2275
|
+
if (score < 75) return "38;5;178";
|
|
2276
|
+
if (score < 90) return "38;5;71";
|
|
2277
|
+
return "38;5;29";
|
|
2278
|
+
}
|
|
2279
|
+
function ansi(enabled) {
|
|
2280
|
+
const wrap = (open, close) => (s) => enabled ? `${ESC}[${open}m${s}${ESC}[${close}m` : s;
|
|
2281
|
+
return {
|
|
2282
|
+
bold: wrap("1", "22"),
|
|
2283
|
+
dim: wrap("2", "22"),
|
|
2284
|
+
brand: wrap("1;38;5;209", "0"),
|
|
2285
|
+
score: (n, s) => enabled ? `${ESC}[${bandCode(n)}m${s}${ESC}[39m` : s
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2213
2289
|
// src/format.ts
|
|
2214
2290
|
function usd2(n) {
|
|
2215
2291
|
return `$${(Math.round(n * 100) / 100).toFixed(2)}`;
|
|
2216
2292
|
}
|
|
2217
|
-
|
|
2218
|
-
|
|
2293
|
+
var WRAP_WIDTH = 92;
|
|
2294
|
+
function wrapLines(text2, indent = 0) {
|
|
2295
|
+
const pad = " ".repeat(indent);
|
|
2296
|
+
const words = text2.split(/\s+/).filter((w) => w.length > 0);
|
|
2297
|
+
const out = [];
|
|
2298
|
+
let line = "";
|
|
2299
|
+
for (const word of words) {
|
|
2300
|
+
const candidate = line.length > 0 ? `${line} ${word}` : word;
|
|
2301
|
+
if (line.length > 0 && pad.length + candidate.length > WRAP_WIDTH) {
|
|
2302
|
+
out.push(pad + line);
|
|
2303
|
+
line = word;
|
|
2304
|
+
} else {
|
|
2305
|
+
line = candidate;
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
if (line.length > 0) out.push(pad + line);
|
|
2309
|
+
if (out.length < 2) return out.length > 0 ? out : [pad];
|
|
2310
|
+
const last = (out[out.length - 1] ?? "").trim();
|
|
2311
|
+
const prevWords = (out[out.length - 2] ?? "").trim().split(" ");
|
|
2312
|
+
const borrowed = prevWords[prevWords.length - 1];
|
|
2313
|
+
if (borrowed !== void 0 && prevWords.length >= 3 && !last.includes(" ") && pad.length + borrowed.length + 1 + last.length <= WRAP_WIDTH) {
|
|
2314
|
+
out[out.length - 2] = pad + prevWords.slice(0, -1).join(" ");
|
|
2315
|
+
out[out.length - 1] = `${pad}${borrowed} ${last}`;
|
|
2316
|
+
}
|
|
2317
|
+
return out;
|
|
2318
|
+
}
|
|
2319
|
+
function pushProse(lines, text2, indent = 0, style = (s) => s) {
|
|
2320
|
+
for (const line of wrapLines(text2, indent)) lines.push(style(line));
|
|
2321
|
+
}
|
|
2322
|
+
function plural(n, noun) {
|
|
2323
|
+
return n === 1 ? noun : `${noun}s`;
|
|
2324
|
+
}
|
|
2325
|
+
function statRows(rows, a) {
|
|
2326
|
+
const plain = (c) => `${c.k}: ${c.v}`;
|
|
2327
|
+
const leadWidth = Math.max(...rows.map((r) => r[0] ? plain(r[0]).length : 0));
|
|
2328
|
+
const gap = " ";
|
|
2329
|
+
return rows.map(
|
|
2330
|
+
(row) => row.map((c, i) => {
|
|
2331
|
+
const styled = `${a.dim(c.k + ":")} ${a.bold(c.v)}`;
|
|
2332
|
+
const padding = i === 0 ? Math.max(0, leadWidth - plain(c).length) : 0;
|
|
2333
|
+
return styled + " ".repeat(padding);
|
|
2334
|
+
}).join(gap).trimEnd()
|
|
2335
|
+
);
|
|
2336
|
+
}
|
|
2337
|
+
function bar(score, a, width = 20) {
|
|
2338
|
+
if (score === null) return a.dim("n/a");
|
|
2219
2339
|
const filled = Math.round(score / 100 * width);
|
|
2220
|
-
return `[${"#".repeat(filled)}${".".repeat(width - filled)}] ${score}`;
|
|
2340
|
+
return `[${a.score(score, "#".repeat(filled))}${a.dim(".".repeat(width - filled))}] ${a.bold(String(score))}`;
|
|
2221
2341
|
}
|
|
2222
2342
|
function shortModel(id) {
|
|
2223
2343
|
const m = /(opus|sonnet|haiku|fable)/i.exec(id);
|
|
2224
2344
|
return m && m[1] ? m[1].toLowerCase() : id;
|
|
2225
2345
|
}
|
|
2346
|
+
function unknownModelNote(breakdown) {
|
|
2347
|
+
let unknown = 0;
|
|
2348
|
+
let total = 0;
|
|
2349
|
+
for (const [model, spend] of Object.entries(breakdown)) {
|
|
2350
|
+
if (spend <= 0) continue;
|
|
2351
|
+
total += spend;
|
|
2352
|
+
if (!isKnownModel(model)) unknown += spend;
|
|
2353
|
+
}
|
|
2354
|
+
if (total <= 0 || unknown / total < 0.01) return null;
|
|
2355
|
+
const pct2 = Math.round(unknown / total * 100);
|
|
2356
|
+
return `${pct2}% of spend used models missing from the rate card and is priced at approximate (Sonnet) rates.`;
|
|
2357
|
+
}
|
|
2226
2358
|
function modelMix(breakdown) {
|
|
2227
2359
|
const merged = /* @__PURE__ */ new Map();
|
|
2228
2360
|
for (const [model, spend] of Object.entries(breakdown)) {
|
|
@@ -2245,94 +2377,127 @@ function unassessedLine(pillars) {
|
|
|
2245
2377
|
});
|
|
2246
2378
|
return `Not yet scored: ${parts.join(" ")}`;
|
|
2247
2379
|
}
|
|
2248
|
-
function formatAudit(record, meta) {
|
|
2380
|
+
function formatAudit(record, meta, color = false) {
|
|
2381
|
+
const a = ansi(color);
|
|
2249
2382
|
const m = record.usageMetrics;
|
|
2250
2383
|
const subscription = record.plan !== void 0 && record.plan !== "api";
|
|
2251
2384
|
const share = record.headlineWasteShare ?? (m.spendUsd > 0 ? record.headlineWasteUsd / m.spendUsd : 0);
|
|
2252
2385
|
const shareText = `${(share * 100).toFixed(1)}%`;
|
|
2253
2386
|
const lines = [];
|
|
2254
|
-
lines.push("CostClaw audit");
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2387
|
+
lines.push(a.bold("CostClaw audit"));
|
|
2388
|
+
pushProse(
|
|
2389
|
+
lines,
|
|
2390
|
+
`Source: ${meta.root} (${meta.sessionCount} ${plural(meta.sessionCount, "session")} across ${m.projectsCount} ${plural(m.projectsCount, "project")})`,
|
|
2391
|
+
0,
|
|
2392
|
+
a.dim
|
|
2260
2393
|
);
|
|
2394
|
+
if (meta.claudeMdSource) pushProse(lines, `CLAUDE.md: ${meta.claudeMdSource}`, 0, a.dim);
|
|
2395
|
+
lines.push(a.dim("-".repeat(WRAP_WIDTH)));
|
|
2261
2396
|
lines.push("");
|
|
2262
2397
|
lines.push(
|
|
2263
|
-
|
|
2398
|
+
subscription ? `${a.bold(record.headlineWasteLabel + ":")} ${a.brand(shareText + " of analyzed usage")} (${usd2(record.headlineWasteUsd)} at API rates)` : `${a.bold(record.headlineWasteLabel + ":")} ${a.brand(usd2(record.headlineWasteUsd))}`
|
|
2264
2399
|
);
|
|
2265
|
-
lines.push(
|
|
2400
|
+
lines.push("");
|
|
2266
2401
|
const mix = modelMix(m.modelBreakdown);
|
|
2267
|
-
|
|
2402
|
+
const statBlock = [
|
|
2403
|
+
[
|
|
2404
|
+
{ k: subscription ? "Usage analyzed (API-equivalent)" : "Spend analyzed", v: usd2(m.spendUsd) },
|
|
2405
|
+
{ k: "Cache hit", v: `${(m.cacheHitRate * 100).toFixed(1)}%` },
|
|
2406
|
+
{ k: "Active hours", v: m.durationHours.toFixed(1) }
|
|
2407
|
+
],
|
|
2408
|
+
[
|
|
2409
|
+
{ k: "Pricing snapshot", v: m.pricingSnapshotDate },
|
|
2410
|
+
...mix ? [{ k: "Model spend", v: mix }] : []
|
|
2411
|
+
]
|
|
2412
|
+
];
|
|
2413
|
+
for (const row of statRows(statBlock, a)) lines.push(row);
|
|
2414
|
+
const unknownNote = unknownModelNote(m.modelBreakdown);
|
|
2415
|
+
if (unknownNote) pushProse(lines, unknownNote, 0, a.dim);
|
|
2268
2416
|
const w = record.usageWindows;
|
|
2269
2417
|
if (subscription) {
|
|
2270
|
-
lines.push(
|
|
2271
|
-
|
|
2418
|
+
lines.push("");
|
|
2419
|
+
pushProse(
|
|
2420
|
+
lines,
|
|
2421
|
+
`Plan: ${record.plan}. Dollar figures are API-equivalent token value, not money back; recovering them buys rate-limit headroom (more work per usage window).`,
|
|
2422
|
+
0,
|
|
2423
|
+
a.dim
|
|
2272
2424
|
);
|
|
2273
2425
|
if (w?.assessed) {
|
|
2274
2426
|
lines.push(
|
|
2275
|
-
|
|
2427
|
+
`${a.dim("Usage windows (5h, like your rate limit):")} median ${a.bold(usd2(w.medianWindowUsd))}, busiest ${a.bold(usd2(w.p90WindowUsd))}`
|
|
2276
2428
|
);
|
|
2429
|
+
lines.push(`${a.dim("Busiest week:")} ${a.bold(usd2(w.maxWeekUsd))} ${a.dim("(API-equivalent)")}`);
|
|
2277
2430
|
if (share >= 0.01 && share < 1) {
|
|
2278
2431
|
const gain = share / (1 - share);
|
|
2279
2432
|
const extraMinutes = Math.round(w.p90WindowActiveMinutes * gain);
|
|
2433
|
+
lines.push("");
|
|
2280
2434
|
lines.push(
|
|
2281
|
-
`Recovering ${shareText} buys about ${Math.round(gain * 100)}% more work per window
|
|
2435
|
+
`Recovering ${shareText} buys about ${a.bold(`${Math.round(gain * 100)}% more work per window`)}:`
|
|
2282
2436
|
);
|
|
2437
|
+
lines.push(` up to ${a.brand(`~${extraMinutes} extra minutes`)} in a window like your busiest.`);
|
|
2283
2438
|
}
|
|
2284
2439
|
}
|
|
2285
2440
|
} else if (meta.planSource === "default") {
|
|
2286
2441
|
const burn = w?.assessed && w.medianWeekUsd >= 50 ? ` Your median week burns ${usd2(w.medianWeekUsd)} at API rates.` : "";
|
|
2287
|
-
lines.push(
|
|
2288
|
-
|
|
2442
|
+
lines.push("");
|
|
2443
|
+
pushProse(lines, `Dollar figures are API-equivalent rates.${burn}`, 0, a.dim);
|
|
2444
|
+
pushProse(
|
|
2445
|
+
lines,
|
|
2446
|
+
"On a Claude subscription? Rerun with --plan max20x (or pro, max5x) to frame results as token efficiency.",
|
|
2447
|
+
0,
|
|
2448
|
+
a.dim
|
|
2289
2449
|
);
|
|
2290
2450
|
}
|
|
2291
2451
|
if (m.topProjects.length > 0) {
|
|
2292
2452
|
lines.push("");
|
|
2293
|
-
lines.push("Top projects by spend:");
|
|
2453
|
+
lines.push(a.bold("Top projects by spend:"));
|
|
2294
2454
|
for (const p of m.topProjects.slice(0, 5)) {
|
|
2295
2455
|
const name = p.slug.length > 30 ? p.slug.slice(0, 27) + "..." : p.slug;
|
|
2296
2456
|
const model = p.modelPrimary ? shortModel(p.modelPrimary) : "n/a";
|
|
2457
|
+
const sessions = `${String(p.sessionsCount).padStart(4)} ${plural(p.sessionsCount, "session")}`;
|
|
2458
|
+
const cache = `cache ${(p.cacheHitRate * 100).toFixed(1)}%`;
|
|
2297
2459
|
lines.push(
|
|
2298
|
-
` ${name.padEnd(32)}${usd2(p.costUsd).padStart(10)} ${
|
|
2460
|
+
` ${name.padEnd(32)}${a.bold(usd2(p.costUsd).padStart(10))} ${sessions.padEnd(16)}${a.dim(`${cache.padEnd(15)}${model}`)}`
|
|
2299
2461
|
);
|
|
2300
2462
|
}
|
|
2301
2463
|
}
|
|
2302
2464
|
lines.push("");
|
|
2303
|
-
lines.push(
|
|
2465
|
+
lines.push(
|
|
2466
|
+
`${a.bold("Overall setup score:")} ${a.score(record.overallScore, `${record.overallScore} / 100`)} (${a.score(record.overallScore, record.band.label)})`
|
|
2467
|
+
);
|
|
2304
2468
|
for (const p of record.pillarScores) {
|
|
2305
|
-
lines.push(` ${p.name.padEnd(22)} ${bar(p.score)}`);
|
|
2469
|
+
lines.push(` ${p.name.padEnd(22)} ${bar(p.score, a)}`);
|
|
2306
2470
|
}
|
|
2307
2471
|
lines.push("");
|
|
2308
2472
|
const dollarFixes = record.fixes.filter((f) => f.wasteUsd > 0);
|
|
2309
2473
|
const otherIssues = record.fixes.filter((f) => f.wasteUsd === 0);
|
|
2310
|
-
lines.push("Top fixes by recoverable spend:");
|
|
2474
|
+
lines.push(a.bold("Top fixes by recoverable spend:"));
|
|
2311
2475
|
if (dollarFixes.length === 0) {
|
|
2312
2476
|
lines.push(" No directly recoverable dollars found. See issues below.");
|
|
2313
2477
|
} else {
|
|
2314
|
-
for (const f of dollarFixes) {
|
|
2315
|
-
|
|
2316
|
-
lines.push(`
|
|
2317
|
-
|
|
2478
|
+
for (const [i, f] of dollarFixes.entries()) {
|
|
2479
|
+
if (i > 0) lines.push("");
|
|
2480
|
+
lines.push(` - [${a.brand(usd2(f.wasteUsd))}] ${a.bold(f.title)}`);
|
|
2481
|
+
pushProse(lines, f.action, 6);
|
|
2482
|
+
if (f.basis) pushProse(lines, `Evidence: ${f.basis}`, 6, a.dim);
|
|
2318
2483
|
}
|
|
2319
2484
|
}
|
|
2320
2485
|
if (otherIssues.length > 0) {
|
|
2321
2486
|
lines.push("");
|
|
2322
|
-
lines.push("Other issues to tighten:");
|
|
2487
|
+
lines.push(a.bold("Other issues to tighten:"));
|
|
2323
2488
|
for (const f of otherIssues) {
|
|
2324
2489
|
lines.push(` - ${f.title}`);
|
|
2325
|
-
if (f.basis) lines
|
|
2490
|
+
if (f.basis) pushProse(lines, `Evidence: ${f.basis}`, 6, a.dim);
|
|
2326
2491
|
}
|
|
2327
2492
|
}
|
|
2328
2493
|
if (meta.skipped.length > 0) {
|
|
2329
2494
|
lines.push("");
|
|
2330
|
-
lines
|
|
2495
|
+
pushProse(lines, `Note: ${meta.skipped.length} file(s) could not be read and were skipped.`, 0, a.dim);
|
|
2331
2496
|
}
|
|
2332
2497
|
const gapLine = unassessedLine(record.pillarScores);
|
|
2333
2498
|
if (gapLine) {
|
|
2334
2499
|
lines.push("");
|
|
2335
|
-
lines.push(gapLine);
|
|
2500
|
+
lines.push(a.dim(gapLine));
|
|
2336
2501
|
}
|
|
2337
2502
|
return lines.join("\n");
|
|
2338
2503
|
}
|
|
@@ -2374,20 +2539,22 @@ function projectChart(projects) {
|
|
|
2374
2539
|
if (projects.length === 0) {
|
|
2375
2540
|
return `<p class="muted">No project spend to chart.</p>`;
|
|
2376
2541
|
}
|
|
2377
|
-
const rowH =
|
|
2378
|
-
const gap =
|
|
2379
|
-
const labelW =
|
|
2380
|
-
const
|
|
2381
|
-
const
|
|
2542
|
+
const rowH = 28;
|
|
2543
|
+
const gap = 8;
|
|
2544
|
+
const labelW = 200;
|
|
2545
|
+
const valW = 90;
|
|
2546
|
+
const barMax = 400;
|
|
2547
|
+
const barH = 14;
|
|
2382
2548
|
const width = labelW + barMax + valW;
|
|
2383
2549
|
const height = projects.length * (rowH + gap) - gap;
|
|
2384
2550
|
const maxCost = Math.max(...projects.map((p) => p.costUsd), 0.01);
|
|
2385
2551
|
const rows = projects.map((p, i) => {
|
|
2386
2552
|
const y = i * (rowH + gap);
|
|
2387
|
-
const w = Math.max(
|
|
2553
|
+
const w = Math.max(barH, Math.round(p.costUsd / maxCost * barMax));
|
|
2388
2554
|
const mid = y + rowH / 2;
|
|
2389
|
-
const
|
|
2390
|
-
|
|
2555
|
+
const barY = mid - barH / 2;
|
|
2556
|
+
const label = esc(truncate(p.slug, 30));
|
|
2557
|
+
return `<text x="0" y="${mid}" class="c-lbl" dominant-baseline="middle">${label}</text><rect x="${labelW}" y="${barY}" width="${barMax}" height="${barH}" rx="${barH / 2}" fill="#f5ece6"></rect><rect x="${labelW}" y="${barY}" width="${w}" height="${barH}" rx="${barH / 2}" fill="#e07a5f"></rect><text x="${width}" y="${mid}" class="c-val" text-anchor="end" dominant-baseline="middle">${esc(usd3(p.costUsd))}</text>`;
|
|
2391
2558
|
}).join("");
|
|
2392
2559
|
return `<svg viewBox="0 0 ${width} ${height}" width="100%" height="${height}" role="img" aria-label="Top projects by cost" preserveAspectRatio="xMinYMin meet">${rows}</svg>`;
|
|
2393
2560
|
}
|
|
@@ -2409,64 +2576,129 @@ function otherFixCard(f) {
|
|
|
2409
2576
|
return `<li class="fix other"><div class="fix-head"><span class="fix-title">${esc(f.title)}</span></div><p class="fix-action">${esc(f.action)}</p>` + (f.basis ? `<p class="fix-basis">${esc(f.basis)}</p>` : "") + `</li>`;
|
|
2410
2577
|
}
|
|
2411
2578
|
var STYLE = `
|
|
2412
|
-
:root {
|
|
2579
|
+
:root {
|
|
2580
|
+
color-scheme: light;
|
|
2581
|
+
/* Warm clay-on-paper palette. Clay is graphic only (bars, rules, gradients);
|
|
2582
|
+
colored text is always umber, so every label clears WCAG AA on paper. */
|
|
2583
|
+
--ink: #251d1a;
|
|
2584
|
+
--paper: #fefaf7;
|
|
2585
|
+
--card: #fffdfb;
|
|
2586
|
+
--umber: #822d1d;
|
|
2587
|
+
--clay: #e07a5f;
|
|
2588
|
+
--line: #f0e2da;
|
|
2589
|
+
--track: #f5ece6;
|
|
2590
|
+
--body: #5a4a43;
|
|
2591
|
+
--muted: #6f5f58;
|
|
2592
|
+
--faint: #7f6d64;
|
|
2593
|
+
/* 4px spacing scale; every gap below comes from it. */
|
|
2594
|
+
--s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px;
|
|
2595
|
+
--s6: 24px; --s7: 32px; --s8: 40px; --s9: 48px; --s10: 64px;
|
|
2596
|
+
--sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
2597
|
+
--mono: ui-monospace, SFMono-Regular, "SF Mono", "JetBrains Mono", Menlo, Consolas,
|
|
2598
|
+
"Liberation Mono", monospace;
|
|
2599
|
+
}
|
|
2413
2600
|
* { box-sizing: border-box; }
|
|
2414
2601
|
body {
|
|
2415
2602
|
margin: 0;
|
|
2416
|
-
font-family:
|
|
2417
|
-
color:
|
|
2418
|
-
background:
|
|
2603
|
+
font-family: var(--sans);
|
|
2604
|
+
color: var(--ink);
|
|
2605
|
+
background: var(--paper);
|
|
2419
2606
|
line-height: 1.5;
|
|
2607
|
+
-webkit-font-smoothing: antialiased;
|
|
2608
|
+
}
|
|
2609
|
+
.wrap { max-width: 780px; margin: 0 auto; padding: var(--s8) var(--s6) var(--s10); }
|
|
2610
|
+
.mark { width: 28px; height: 3px; border-radius: 2px; background: var(--clay); margin: 0 0 var(--s4); }
|
|
2611
|
+
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 var(--s3); letter-spacing: -0.015em; }
|
|
2612
|
+
h2 {
|
|
2613
|
+
font-size: 17px; line-height: 1.3; letter-spacing: 0.01em; color: var(--umber);
|
|
2614
|
+
margin: var(--s8) 0 var(--s4); padding-top: var(--s5); border-top: 1px solid var(--line);
|
|
2420
2615
|
}
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2616
|
+
/* Numbers, paths, and model ids are data: one monospace face everywhere. */
|
|
2617
|
+
.mono, .meta, .stat .v, .p-score, .score-head .big, .fix-amt, .banner .amount-sub {
|
|
2618
|
+
font-family: var(--mono); font-variant-numeric: tabular-nums;
|
|
2619
|
+
}
|
|
2620
|
+
.meta { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 0; word-break: break-word; }
|
|
2621
|
+
.sub { color: var(--muted); font-size: 14px; margin: var(--s4) 0 0; max-width: 74ch; }
|
|
2425
2622
|
.banner {
|
|
2426
|
-
margin:
|
|
2427
|
-
background: linear-gradient(135deg,
|
|
2623
|
+
margin: var(--s7) 0 0; padding: var(--s6) var(--s6) var(--s5); border-radius: 14px;
|
|
2624
|
+
background: linear-gradient(135deg, var(--umber), var(--clay)); color: var(--paper);
|
|
2428
2625
|
box-shadow: 0 8px 24px rgba(130, 45, 29, 0.18);
|
|
2429
2626
|
}
|
|
2430
|
-
.banner .label { font-size:
|
|
2431
|
-
.banner .amount { font-size: 40px; font-weight: 700; margin-top:
|
|
2432
|
-
.banner .amount-sub { font-size: 15px; font-weight: 500; margin-top:
|
|
2433
|
-
|
|
2434
|
-
.
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
.
|
|
2439
|
-
|
|
2440
|
-
|
|
2627
|
+
.banner .label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.92; }
|
|
2628
|
+
.banner .amount { font-size: 40px; line-height: 1.1; font-weight: 700; margin-top: var(--s2); letter-spacing: -0.02em; }
|
|
2629
|
+
.banner .amount-sub { font-size: 15px; font-weight: 500; margin-top: var(--s1); opacity: 0.92; }
|
|
2630
|
+
/* One column rhythm for every stat row, so tile edges line up across rows. */
|
|
2631
|
+
.stats {
|
|
2632
|
+
display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
|
|
2633
|
+
gap: var(--s3); margin: var(--s4) 0 0;
|
|
2634
|
+
}
|
|
2635
|
+
.stat {
|
|
2636
|
+
display: flex; flex-direction: column; gap: var(--s2);
|
|
2637
|
+
padding: var(--s3) var(--s4); background: var(--card);
|
|
2638
|
+
border: 1px solid var(--line); border-radius: 10px;
|
|
2639
|
+
}
|
|
2640
|
+
.stat .k { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
|
|
2641
|
+
/* Values sit on the tile floor, so a two-line label never drops its number. */
|
|
2642
|
+
.stat .v { font-size: 20px; font-weight: 600; line-height: 1.2; margin-top: auto; }
|
|
2643
|
+
.stat .v-small { font-size: 13px; font-weight: 500; line-height: 1.4; }
|
|
2644
|
+
.nb { white-space: nowrap; }
|
|
2645
|
+
.score-head { display: flex; align-items: baseline; gap: var(--s3); margin: 0 0 var(--s4); }
|
|
2646
|
+
.score-head .big { font-size: 30px; font-weight: 700; letter-spacing: -0.01em; }
|
|
2647
|
+
.score-head .band { font-size: 15px; color: var(--umber); font-weight: 600; }
|
|
2648
|
+
.pillar { display: flex; align-items: center; gap: var(--s3); margin: var(--s2) 0; }
|
|
2441
2649
|
.p-name { flex: 0 0 190px; font-size: 14px; }
|
|
2442
|
-
.p-track { flex: 1; height: 14px; background:
|
|
2650
|
+
.p-track { flex: 1; height: 14px; background: var(--track); border-radius: 7px; overflow: hidden; }
|
|
2443
2651
|
.p-fill { display: block; height: 100%; border-radius: 7px; }
|
|
2444
2652
|
.p-fill.p-na { background: repeating-linear-gradient(45deg, #ece0d8, #ece0d8 6px, #f5ece6 6px, #f5ece6 12px); }
|
|
2445
|
-
.p-score { flex: 0 0 40px; text-align: right; font-
|
|
2446
|
-
.muted { color:
|
|
2447
|
-
.chart {
|
|
2448
|
-
|
|
2449
|
-
|
|
2653
|
+
.p-score { flex: 0 0 40px; text-align: right; font-weight: 600; font-size: 14px; }
|
|
2654
|
+
.muted { color: var(--faint); font-weight: 500; }
|
|
2655
|
+
.chart {
|
|
2656
|
+
background: var(--card); border: 1px solid var(--line); border-radius: 12px;
|
|
2657
|
+
padding: var(--s5); overflow-x: auto;
|
|
2658
|
+
}
|
|
2659
|
+
/* height:auto lets the viewBox aspect drive the box, so the chart fills the
|
|
2660
|
+
card's width exactly with no letterboxing at any viewport. */
|
|
2661
|
+
.chart svg { display: block; height: auto; }
|
|
2662
|
+
.c-lbl { font-size: 13px; fill: var(--body); font-family: var(--mono); }
|
|
2663
|
+
.c-val { font-size: 13px; fill: var(--umber); font-weight: 600; font-family: var(--mono); }
|
|
2450
2664
|
ul.fixes { list-style: none; margin: 0; padding: 0; }
|
|
2451
|
-
.fix {
|
|
2665
|
+
.fix {
|
|
2666
|
+
background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--clay);
|
|
2667
|
+
border-radius: 10px; padding: var(--s4) var(--s5); margin: 0 0 var(--s3);
|
|
2668
|
+
}
|
|
2669
|
+
.fix:last-child { margin-bottom: 0; }
|
|
2452
2670
|
.fix.other { border-left-color: #cbb8ae; }
|
|
2453
|
-
.fix-head { display: flex; align-items: baseline; gap:
|
|
2454
|
-
.fix-amt { font-size: 18px; font-weight: 700; color:
|
|
2455
|
-
.fix-title { font-size: 15px; font-weight: 600; }
|
|
2456
|
-
.fix
|
|
2457
|
-
.fix-
|
|
2458
|
-
.fix-
|
|
2459
|
-
.
|
|
2460
|
-
.footer {
|
|
2461
|
-
|
|
2671
|
+
.fix-head { display: flex; align-items: baseline; gap: var(--s3); }
|
|
2672
|
+
.fix-amt { font-size: 18px; font-weight: 700; color: var(--umber); }
|
|
2673
|
+
.fix-title { font-size: 15px; font-weight: 600; line-height: 1.35; }
|
|
2674
|
+
.fix p { max-width: 74ch; }
|
|
2675
|
+
.fix-problem { margin: var(--s2) 0 0; color: var(--body); font-size: 14px; }
|
|
2676
|
+
.fix-action { margin: var(--s1) 0 0; font-size: 14px; }
|
|
2677
|
+
.fix-basis { margin: var(--s2) 0 0; font-size: 13px; color: var(--faint); }
|
|
2678
|
+
.footer {
|
|
2679
|
+
margin-top: var(--s9); padding-top: var(--s5); border-top: 1px solid var(--line);
|
|
2680
|
+
color: var(--muted); font-size: 13px; max-width: 72ch;
|
|
2681
|
+
}
|
|
2682
|
+
.footer strong { color: var(--ink); }
|
|
2683
|
+
.footer .gen { margin: var(--s2) 0 0; }
|
|
2684
|
+
/* The timestamp is one token; never let it break across lines. */
|
|
2685
|
+
.footer .gen .mono { white-space: nowrap; }
|
|
2686
|
+
@media (max-width: 560px) {
|
|
2687
|
+
.wrap { padding: var(--s6) var(--s4) var(--s8); }
|
|
2688
|
+
h1 { font-size: 24px; }
|
|
2689
|
+
.banner .amount { font-size: 32px; }
|
|
2690
|
+
.p-name { flex: 0 0 130px; font-size: 13px; }
|
|
2691
|
+
}
|
|
2462
2692
|
`;
|
|
2463
2693
|
function renderHtml(record, meta) {
|
|
2464
2694
|
const m = record.usageMetrics;
|
|
2465
2695
|
const mix = modelMix(m.modelBreakdown);
|
|
2696
|
+
const unknownNote = unknownModelNote(m.modelBreakdown);
|
|
2697
|
+
const mixCells = mix ? mix.split(" / ").map((part) => `<span class="nb">${esc(part)}</span>`).join(" / ") : "";
|
|
2466
2698
|
const subscription = record.plan !== void 0 && record.plan !== "api";
|
|
2467
2699
|
const share = record.headlineWasteShare ?? (m.spendUsd > 0 ? record.headlineWasteUsd / m.spendUsd : 0);
|
|
2468
2700
|
const shareText = `${(share * 100).toFixed(1)}%`;
|
|
2469
|
-
const bannerAmount = subscription ? `<div class="amount">${shareText} of analyzed usage</div><div class="amount-sub">${esc(usd3(record.headlineWasteUsd))} at API rates</div>` : `<div class="amount">${esc(usd3(record.headlineWasteUsd))}</div>`;
|
|
2701
|
+
const bannerAmount = subscription ? `<div class="amount">${shareText} of analyzed usage</div><div class="amount-sub">${esc(usd3(record.headlineWasteUsd))} at API rates</div>` : `<div class="amount mono">${esc(usd3(record.headlineWasteUsd))}</div>`;
|
|
2470
2702
|
const spendLabel = subscription ? "Usage analyzed (API-equivalent)" : "Spend analyzed";
|
|
2471
2703
|
const w = record.usageWindows;
|
|
2472
2704
|
let headroom = "";
|
|
@@ -2483,6 +2715,11 @@ function renderHtml(record, meta) {
|
|
|
2483
2715
|
const dollarSection = dollarFixes.length === 0 ? `<p class="muted">No directly recoverable dollars found. See issues below.</p>` : `<ul class="fixes">${dollarFixes.map(dollarFixCard).join("")}</ul>`;
|
|
2484
2716
|
const otherSection = otherIssues.length === 0 ? "" : `<h2>Other issues to tighten</h2><ul class="fixes">${otherIssues.map(otherFixCard).join("")}</ul>`;
|
|
2485
2717
|
const skippedNote = meta.skipped.length > 0 ? `<p class="sub">Note: ${meta.skipped.length} file(s) could not be read and were skipped.</p>` : "";
|
|
2718
|
+
const metaBlock = [
|
|
2719
|
+
`Source: ${esc(meta.root)} (${meta.sessionCount} ${plural(meta.sessionCount, "session")} across ${m.projectsCount} ${plural(m.projectsCount, "project")})`,
|
|
2720
|
+
meta.claudeMdSource ? `CLAUDE.md: ${esc(meta.claudeMdSource)}` : "",
|
|
2721
|
+
`Pricing snapshot: ${esc(m.pricingSnapshotDate)}`
|
|
2722
|
+
].filter((line) => line.length > 0).map((line) => `<p class="meta">${line}</p>`).join("\n");
|
|
2486
2723
|
return `<!doctype html>
|
|
2487
2724
|
<html lang="en">
|
|
2488
2725
|
<head>
|
|
@@ -2493,10 +2730,9 @@ function renderHtml(record, meta) {
|
|
|
2493
2730
|
</head>
|
|
2494
2731
|
<body>
|
|
2495
2732
|
<div class="wrap">
|
|
2733
|
+
<div class="mark" aria-hidden="true"></div>
|
|
2496
2734
|
<h1>CostClaw audit</h1>
|
|
2497
|
-
|
|
2498
|
-
${meta.claudeMdSource ? `<p class="sub">CLAUDE.md: ${esc(meta.claudeMdSource)}</p>` : ""}
|
|
2499
|
-
<p class="sub">Pricing snapshot: ${esc(m.pricingSnapshotDate)}</p>
|
|
2735
|
+
${metaBlock}
|
|
2500
2736
|
|
|
2501
2737
|
<div class="banner">
|
|
2502
2738
|
<div class="label">${esc(record.headlineWasteLabel)}</div>
|
|
@@ -2507,8 +2743,9 @@ ${planNote}
|
|
|
2507
2743
|
<div class="stat"><div class="k">${spendLabel}</div><div class="v">${esc(usd3(m.spendUsd))}</div></div>
|
|
2508
2744
|
<div class="stat"><div class="k">Cache hit rate</div><div class="v">${(m.cacheHitRate * 100).toFixed(1)}%</div></div>
|
|
2509
2745
|
<div class="stat"><div class="k">Active hours</div><div class="v">${m.durationHours.toFixed(1)}</div></div>
|
|
2510
|
-
${mix ? `<div class="stat"><div class="k">Model spend</div><div class="v v-small">${
|
|
2746
|
+
${mix ? `<div class="stat"><div class="k">Model spend</div><div class="v v-small">${mixCells}</div></div>` : ""}
|
|
2511
2747
|
</div>
|
|
2748
|
+
${unknownNote ? `<p class="meta">${esc(unknownNote)}</p>` : ""}
|
|
2512
2749
|
${windowTiles}
|
|
2513
2750
|
|
|
2514
2751
|
<h2>Spend by project</h2>
|
|
@@ -2528,7 +2765,8 @@ ${skippedNote}
|
|
|
2528
2765
|
|
|
2529
2766
|
<div class="footer">
|
|
2530
2767
|
<strong>This report was generated locally on your machine.</strong> Nothing was uploaded:
|
|
2531
|
-
your prompts, file contents, and paths never left this computer.
|
|
2768
|
+
your prompts, file contents, and paths never left this computer.
|
|
2769
|
+
<div class="gen">Generated <span class="mono">${esc(record.createdAt)}</span>.</div>
|
|
2532
2770
|
</div>
|
|
2533
2771
|
</div>
|
|
2534
2772
|
</body>
|
|
@@ -2721,7 +2959,8 @@ async function runAudit(opts) {
|
|
|
2721
2959
|
process.stderr.write(`Could not save the audit snapshot: ${err instanceof Error ? err.message : String(err)}
|
|
2722
2960
|
`);
|
|
2723
2961
|
}
|
|
2724
|
-
|
|
2962
|
+
const color = !opts.json && process.stdout.isTTY === true && !process.env["NO_COLOR"];
|
|
2963
|
+
let output = opts.json ? JSON.stringify(record, null, 2) : formatAudit(record, { root, sessionCount: logs.length, skipped, claudeMdSource, planSource }, color);
|
|
2725
2964
|
const notices = [];
|
|
2726
2965
|
if (snapshotNotice) notices.push(snapshotNotice);
|
|
2727
2966
|
if (opts.html) {
|
|
@@ -3737,14 +3976,16 @@ function planFlag(args) {
|
|
|
3737
3976
|
return value;
|
|
3738
3977
|
}
|
|
3739
3978
|
function parseAuditFlags(args) {
|
|
3740
|
-
const
|
|
3979
|
+
const json = args.includes("--json");
|
|
3980
|
+
const htmlExplicit = args.includes("--html");
|
|
3981
|
+
const html = args.includes("--no-html") ? false : htmlExplicit || !json;
|
|
3741
3982
|
const card = args.includes("--card");
|
|
3742
3983
|
return {
|
|
3743
3984
|
path: getFlag(args, "--path"),
|
|
3744
3985
|
claudeMdPath: getFlag(args, "--claude-md"),
|
|
3745
|
-
json
|
|
3986
|
+
json,
|
|
3746
3987
|
html,
|
|
3747
|
-
htmlPath:
|
|
3988
|
+
htmlPath: htmlExplicit ? optionalPathAfter(args, "--html") : void 0,
|
|
3748
3989
|
card,
|
|
3749
3990
|
cardPath: card ? optionalPathAfter(args, "--card") : void 0,
|
|
3750
3991
|
plan: planFlag(args)
|
|
@@ -3758,14 +3999,14 @@ function parseBadgeFlags(args) {
|
|
|
3758
3999
|
};
|
|
3759
4000
|
}
|
|
3760
4001
|
function cliVersion() {
|
|
3761
|
-
return true ? "0.
|
|
4002
|
+
return true ? "0.5.1" : "0.0.0-dev";
|
|
3762
4003
|
}
|
|
3763
4004
|
function helpText() {
|
|
3764
4005
|
return [
|
|
3765
4006
|
"CostClaw - privacy-first Claude Code cost and setup audit",
|
|
3766
4007
|
"",
|
|
3767
4008
|
"Usage:",
|
|
3768
|
-
" costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--card [file]]",
|
|
4009
|
+
" costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--no-html] [--card [file]]",
|
|
3769
4010
|
" costclaw diff [<baseline.json> <current.json>] [--json]",
|
|
3770
4011
|
" costclaw badge [--path <dir>] [--claude-md <file>] [--out <file>]",
|
|
3771
4012
|
" costclaw optimize [--path <dir>] [--claude-md <file>] [--project <dir>] [--out <dir>] [--write <file>] [--apply-settings [file]] [--force]",
|
|
@@ -3775,8 +4016,9 @@ function helpText() {
|
|
|
3775
4016
|
"",
|
|
3776
4017
|
"audit reads your Claude Code logs from ~/.claude/projects (or --path) on this",
|
|
3777
4018
|
"machine and prints a cost report plus a six-pillar setup score. It is free.",
|
|
3778
|
-
"
|
|
3779
|
-
"it in your browser;
|
|
4019
|
+
"By default it also writes a self-contained HTML report (costclaw-report.html)",
|
|
4020
|
+
"and opens it in your browser; --no-html skips that, --html <file> picks the",
|
|
4021
|
+
"path, and --json runs stay file-free unless --html is passed explicitly.",
|
|
3780
4022
|
"--card writes a shareable 600x315 score card SVG (default: costclaw-card.svg):",
|
|
3781
4023
|
"score, band, recoverable spend, cache hit rate, and your strongest pillar.",
|
|
3782
4024
|
"--plan <api|pro|max5x|max20x> declares how you pay for Claude. On a",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "costclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Local cost and setup audit for Claude Code. Finds recoverable token spend and scores your setup across six pillars, with your prompts never leaving your machine.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|