costclaw 0.5.0 → 0.5.2

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