costclaw 0.2.1 → 0.2.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.
- package/README.md +10 -2
- package/dist/index.js +85 -33
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,12 +20,18 @@ That reads `~/.claude/projects` (override with `--path <dir>`) and prints:
|
|
|
20
20
|
```
|
|
21
21
|
CostClaw audit
|
|
22
22
|
Source: ~/.claude/projects (N sessions across M projects)
|
|
23
|
+
CLAUDE.md: ~/.claude/CLAUDE.md
|
|
23
24
|
|
|
24
25
|
Recoverable spend (cache-miss exposure): $XXX.XX
|
|
25
26
|
|
|
26
27
|
Spend analyzed: $X,XXX.XX Cache hit: 96.3% Active hours: XXX.X
|
|
28
|
+
Model spend: opus 71% / sonnet 24% / haiku 5%
|
|
29
|
+
|
|
30
|
+
Top projects by spend:
|
|
31
|
+
C--Projects-demo $XXX.XX 312 sessions cache 96.4% opus
|
|
32
|
+
|
|
27
33
|
Overall setup score: 91 / 100 (Dialed in)
|
|
28
|
-
CLAUDE.md quality
|
|
34
|
+
CLAUDE.md quality [#################...] 85
|
|
29
35
|
Context hygiene [###################.] 95
|
|
30
36
|
Prompting patterns [##################..] 92
|
|
31
37
|
Session management [####################] 100
|
|
@@ -35,6 +41,7 @@ Overall setup score: 91 / 100 (Dialed in)
|
|
|
35
41
|
Top fixes by recoverable spend:
|
|
36
42
|
- [$XXX.XX] Recover spend lost to cache misses
|
|
37
43
|
Keep the start of each session stable so the prompt cache is reused.
|
|
44
|
+
Evidence: XX% of input tokens missed the cache across N sessions.
|
|
38
45
|
```
|
|
39
46
|
|
|
40
47
|
## Options
|
|
@@ -44,7 +51,8 @@ costclaw audit [--path <dir>] [--claude-md <file>] [--json] [--html [file]] [--c
|
|
|
44
51
|
```
|
|
45
52
|
|
|
46
53
|
- `--path <dir>` audit a specific projects directory (default `~/.claude/projects`).
|
|
47
|
-
- `--claude-md <file>` score a CLAUDE.md file's quality
|
|
54
|
+
- `--claude-md <file>` score a specific CLAUDE.md file's quality (by default the
|
|
55
|
+
audit scores `~/.claude/CLAUDE.md` when it exists).
|
|
48
56
|
- `--json` print the raw, derived `AuditRecord` instead of the human report.
|
|
49
57
|
- `--html [file]` also write a self-contained HTML report (default
|
|
50
58
|
`costclaw-report.html` in the current directory) and open it in your browser.
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,8 @@ import { pathToFileURL } from "url";
|
|
|
5
5
|
|
|
6
6
|
// src/audit-command.ts
|
|
7
7
|
import { readFile as readFile2, writeFile } from "fs/promises";
|
|
8
|
-
import { resolve } from "path";
|
|
8
|
+
import { join as join3, resolve } from "path";
|
|
9
|
+
import { homedir as homedir3 } from "os";
|
|
9
10
|
import { spawn } from "child_process";
|
|
10
11
|
|
|
11
12
|
// ../../packages/engine/src/types.ts
|
|
@@ -939,7 +940,7 @@ function buildChecks(report, cmd, answers, setup) {
|
|
|
939
940
|
"claude_md",
|
|
940
941
|
"Size",
|
|
941
942
|
cmd.present ? cmd.sizeScore : null,
|
|
942
|
-
cmd.present ? `Your CLAUDE.md is ${cmd.chars.toLocaleString()} characters, about ${cmd.estTokens.toLocaleString()} tokens loaded on every turn.` : "No CLAUDE.md was
|
|
943
|
+
cmd.present ? `Your CLAUDE.md is ${cmd.chars.toLocaleString()} characters, about ${cmd.estTokens.toLocaleString()} tokens loaded on every turn.` : "No CLAUDE.md was provided.",
|
|
943
944
|
"claudemd"
|
|
944
945
|
)
|
|
945
946
|
);
|
|
@@ -949,7 +950,7 @@ function buildChecks(report, cmd, answers, setup) {
|
|
|
949
950
|
"claude_md",
|
|
950
951
|
"Structure",
|
|
951
952
|
cmd.present ? cmd.structureScore : null,
|
|
952
|
-
cmd.present ? `${cmd.headings} heading${cmd.headings === 1 ? "" : "s"} and ${cmd.bullets} bullet point${cmd.bullets === 1 ? "" : "s"} across ${cmd.chars.toLocaleString()} characters.` : "No CLAUDE.md was
|
|
953
|
+
cmd.present ? `${cmd.headings} heading${cmd.headings === 1 ? "" : "s"} and ${cmd.bullets} bullet point${cmd.bullets === 1 ? "" : "s"} across ${cmd.chars.toLocaleString()} characters.` : "No CLAUDE.md was provided.",
|
|
953
954
|
"claudemd"
|
|
954
955
|
)
|
|
955
956
|
);
|
|
@@ -959,7 +960,7 @@ function buildChecks(report, cmd, answers, setup) {
|
|
|
959
960
|
"claude_md",
|
|
960
961
|
"Cache stability",
|
|
961
962
|
cmd.present ? cmd.stabilityScore : null,
|
|
962
|
-
cmd.present ? `${cmd.volatileMarkers} volatile marker${cmd.volatileMarkers === 1 ? "" : "s"} (dates, TODOs, "updated" notes) that change between sessions and reset the cache.` : "No CLAUDE.md was
|
|
963
|
+
cmd.present ? `${cmd.volatileMarkers} volatile marker${cmd.volatileMarkers === 1 ? "" : "s"} (dates, TODOs, "updated" notes) that change between sessions and reset the cache.` : "No CLAUDE.md was provided.",
|
|
963
964
|
"claudemd"
|
|
964
965
|
)
|
|
965
966
|
);
|
|
@@ -2030,12 +2031,29 @@ function bar(score, width = 20) {
|
|
|
2030
2031
|
const filled = Math.round(score / 100 * width);
|
|
2031
2032
|
return `[${"#".repeat(filled)}${".".repeat(width - filled)}] ${score}`;
|
|
2032
2033
|
}
|
|
2034
|
+
function shortModel(id) {
|
|
2035
|
+
const m = /(opus|sonnet|haiku|fable)/i.exec(id);
|
|
2036
|
+
return m && m[1] ? m[1].toLowerCase() : id;
|
|
2037
|
+
}
|
|
2038
|
+
function modelMix(breakdown) {
|
|
2039
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2040
|
+
for (const [model, spend] of Object.entries(breakdown)) {
|
|
2041
|
+
if (spend <= 0) continue;
|
|
2042
|
+
const key = shortModel(model);
|
|
2043
|
+
merged.set(key, (merged.get(key) ?? 0) + spend);
|
|
2044
|
+
}
|
|
2045
|
+
const total = [...merged.values()].reduce((a, b) => a + b, 0);
|
|
2046
|
+
if (total <= 0) return null;
|
|
2047
|
+
const parts = [...merged.entries()].sort((a, b) => b[1] - a[1]).map(([name, spend]) => [name, Math.round(spend / total * 100)]).filter(([, pct]) => pct >= 1).map(([name, pct]) => `${name} ${pct}%`);
|
|
2048
|
+
return parts.length > 0 ? parts.join(" / ") : null;
|
|
2049
|
+
}
|
|
2033
2050
|
function unassessedLine(pillars) {
|
|
2034
2051
|
const gaps = pillars.filter((p) => !p.assessed);
|
|
2035
2052
|
if (gaps.length === 0) return null;
|
|
2036
2053
|
const parts = gaps.map((p) => {
|
|
2037
2054
|
const reason = p.checks[0]?.basis;
|
|
2038
|
-
|
|
2055
|
+
const hint = p.id === "claude_md" ? " Pass --claude-md <file> to score it." : "";
|
|
2056
|
+
return reason ? `${p.name} (${reason}${hint})` : p.name;
|
|
2039
2057
|
});
|
|
2040
2058
|
return `Not yet scored: ${parts.join(" ")}`;
|
|
2041
2059
|
}
|
|
@@ -2044,11 +2062,25 @@ function formatAudit(record, meta) {
|
|
|
2044
2062
|
const lines = [];
|
|
2045
2063
|
lines.push("CostClaw audit");
|
|
2046
2064
|
lines.push(`Source: ${meta.root} (${meta.sessionCount} sessions across ${m.projectsCount} projects)`);
|
|
2065
|
+
if (meta.claudeMdSource) lines.push(`CLAUDE.md: ${meta.claudeMdSource}`);
|
|
2047
2066
|
lines.push("");
|
|
2048
2067
|
lines.push(`${record.headlineWasteLabel}: ${usd2(record.headlineWasteUsd)}`);
|
|
2049
2068
|
lines.push("");
|
|
2050
2069
|
lines.push(`Spend analyzed: ${usd2(m.spendUsd)} Cache hit: ${(m.cacheHitRate * 100).toFixed(1)}% Active hours: ${m.durationHours.toFixed(1)}`);
|
|
2051
2070
|
lines.push(`Pricing snapshot: ${m.pricingSnapshotDate}`);
|
|
2071
|
+
const mix = modelMix(m.modelBreakdown);
|
|
2072
|
+
if (mix) lines.push(`Model spend: ${mix}`);
|
|
2073
|
+
if (m.topProjects.length > 0) {
|
|
2074
|
+
lines.push("");
|
|
2075
|
+
lines.push("Top projects by spend:");
|
|
2076
|
+
for (const p of m.topProjects.slice(0, 5)) {
|
|
2077
|
+
const name = p.slug.length > 30 ? p.slug.slice(0, 27) + "..." : p.slug;
|
|
2078
|
+
const model = p.modelPrimary ? shortModel(p.modelPrimary) : "n/a";
|
|
2079
|
+
lines.push(
|
|
2080
|
+
` ${name.padEnd(32)}${usd2(p.costUsd).padStart(10)} ${String(p.sessionsCount).padStart(4)} sessions cache ${(p.cacheHitRate * 100).toFixed(1)}% ${model}`
|
|
2081
|
+
);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2052
2084
|
lines.push("");
|
|
2053
2085
|
lines.push(`Overall setup score: ${record.overallScore} / 100 (${record.band.label})`);
|
|
2054
2086
|
for (const p of record.pillarScores) {
|
|
@@ -2064,6 +2096,7 @@ function formatAudit(record, meta) {
|
|
|
2064
2096
|
for (const f of dollarFixes.slice(0, 6)) {
|
|
2065
2097
|
lines.push(` - [${usd2(f.wasteUsd)}] ${f.title}`);
|
|
2066
2098
|
lines.push(` ${f.action}`);
|
|
2099
|
+
if (f.basis) lines.push(` Evidence: ${f.basis}`);
|
|
2067
2100
|
}
|
|
2068
2101
|
}
|
|
2069
2102
|
if (otherIssues.length > 0) {
|
|
@@ -2071,6 +2104,7 @@ function formatAudit(record, meta) {
|
|
|
2071
2104
|
lines.push("Other issues to tighten:");
|
|
2072
2105
|
for (const f of otherIssues.slice(0, 6)) {
|
|
2073
2106
|
lines.push(` - ${f.title}`);
|
|
2107
|
+
if (f.basis) lines.push(` ${f.basis}`);
|
|
2074
2108
|
}
|
|
2075
2109
|
if (otherIssues.length > 6) {
|
|
2076
2110
|
lines.push(` ... and ${otherIssues.length - 6} more`);
|
|
@@ -2154,10 +2188,10 @@ function pillarBars(pillars) {
|
|
|
2154
2188
|
}).join("");
|
|
2155
2189
|
}
|
|
2156
2190
|
function dollarFixCard(f) {
|
|
2157
|
-
return `<li class="fix"><div class="fix-head"><span class="fix-amt">${esc(usd3(f.wasteUsd))}</span><span class="fix-title">${esc(f.title)}</span></div><p class="fix-problem">${esc(f.problem)}</p><p class="fix-action">${esc(f.action)}</p
|
|
2191
|
+
return `<li class="fix"><div class="fix-head"><span class="fix-amt">${esc(usd3(f.wasteUsd))}</span><span class="fix-title">${esc(f.title)}</span></div><p class="fix-problem">${esc(f.problem)}</p><p class="fix-action">${esc(f.action)}</p>` + (f.basis ? `<p class="fix-basis">${esc(f.basis)}</p>` : "") + `</li>`;
|
|
2158
2192
|
}
|
|
2159
2193
|
function otherFixCard(f) {
|
|
2160
|
-
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
|
|
2194
|
+
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>`;
|
|
2161
2195
|
}
|
|
2162
2196
|
var STYLE = `
|
|
2163
2197
|
:root { color-scheme: light; }
|
|
@@ -2205,11 +2239,14 @@ ul.fixes { list-style: none; margin: 0; padding: 0; }
|
|
|
2205
2239
|
.fix-title { font-size: 15px; font-weight: 600; }
|
|
2206
2240
|
.fix-problem { margin: 8px 0 4px; color: #5a4a43; font-size: 14px; }
|
|
2207
2241
|
.fix-action { margin: 4px 0 0; font-size: 14px; }
|
|
2242
|
+
.fix-basis { margin: 6px 0 0; font-size: 13px; color: #9a8a82; }
|
|
2243
|
+
.stat .v-small { font-size: 14px; font-weight: 600; margin-top: 6px; }
|
|
2208
2244
|
.footer { margin-top: 48px; padding-top: 18px; border-top: 1px solid #f0e2da; color: #7a6a63; font-size: 13px; }
|
|
2209
2245
|
.footer strong { color: #251d1a; }
|
|
2210
2246
|
`;
|
|
2211
2247
|
function renderHtml(record, meta) {
|
|
2212
2248
|
const m = record.usageMetrics;
|
|
2249
|
+
const mix = modelMix(m.modelBreakdown);
|
|
2213
2250
|
const dollarFixes = record.fixes.filter((f) => f.wasteUsd > 0).sort((a, b) => b.wasteUsd - a.wasteUsd);
|
|
2214
2251
|
const otherIssues = record.fixes.filter((f) => f.wasteUsd === 0);
|
|
2215
2252
|
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>`;
|
|
@@ -2227,6 +2264,7 @@ function renderHtml(record, meta) {
|
|
|
2227
2264
|
<div class="wrap">
|
|
2228
2265
|
<h1>CostClaw audit</h1>
|
|
2229
2266
|
<p class="sub">Source: ${esc(meta.root)} (${meta.sessionCount} sessions across ${m.projectsCount} projects)</p>
|
|
2267
|
+
${meta.claudeMdSource ? `<p class="sub">CLAUDE.md: ${esc(meta.claudeMdSource)}</p>` : ""}
|
|
2230
2268
|
<p class="sub">Pricing snapshot: ${esc(m.pricingSnapshotDate)}</p>
|
|
2231
2269
|
|
|
2232
2270
|
<div class="banner">
|
|
@@ -2238,6 +2276,7 @@ function renderHtml(record, meta) {
|
|
|
2238
2276
|
<div class="stat"><div class="k">Spend analyzed</div><div class="v">${esc(usd3(m.spendUsd))}</div></div>
|
|
2239
2277
|
<div class="stat"><div class="k">Cache hit rate</div><div class="v">${(m.cacheHitRate * 100).toFixed(1)}%</div></div>
|
|
2240
2278
|
<div class="stat"><div class="k">Active hours</div><div class="v">${m.durationHours.toFixed(1)}</div></div>
|
|
2279
|
+
${mix ? `<div class="stat"><div class="k">Model spend</div><div class="v v-small">${esc(mix)}</div></div>` : ""}
|
|
2241
2280
|
</div>
|
|
2242
2281
|
|
|
2243
2282
|
<h2>Spend by project</h2>
|
|
@@ -2368,20 +2407,33 @@ async function loadAuditInputs(opts) {
|
|
|
2368
2407
|
throw new Error(`No .jsonl sessions found under ${root}. Set CLAUDE_PROJECTS_PATH or pass --path <dir>.`);
|
|
2369
2408
|
}
|
|
2370
2409
|
let claudeMd;
|
|
2410
|
+
let claudeMdSource = null;
|
|
2371
2411
|
if (opts.claudeMdPath) {
|
|
2372
2412
|
claudeMd = await readFile2(opts.claudeMdPath, "utf8");
|
|
2413
|
+
claudeMdSource = resolve(opts.claudeMdPath);
|
|
2414
|
+
} else {
|
|
2415
|
+
const fallback = join3(opts.home ?? homedir3(), ".claude", "CLAUDE.md");
|
|
2416
|
+
try {
|
|
2417
|
+
claudeMd = await readFile2(fallback, "utf8");
|
|
2418
|
+
claudeMdSource = fallback;
|
|
2419
|
+
} catch {
|
|
2420
|
+
}
|
|
2373
2421
|
}
|
|
2374
|
-
return { logs, claudeMd, root, skipped };
|
|
2422
|
+
return { logs, claudeMd, claudeMdSource, root, skipped };
|
|
2375
2423
|
}
|
|
2376
2424
|
async function runAudit(opts) {
|
|
2377
|
-
const { logs, claudeMd, root, skipped } = await loadAuditInputs(
|
|
2425
|
+
const { logs, claudeMd, claudeMdSource, root, skipped } = await loadAuditInputs({
|
|
2426
|
+
path: opts.path,
|
|
2427
|
+
claudeMdPath: opts.claudeMdPath,
|
|
2428
|
+
home: opts.home
|
|
2429
|
+
});
|
|
2378
2430
|
const setup = await readSetup();
|
|
2379
2431
|
const record = buildAudit({ logs, claudeMd, questionnaire: {}, setup });
|
|
2380
|
-
let output = opts.json ? JSON.stringify(record, null, 2) : formatAudit(record, { root, sessionCount: logs.length, skipped });
|
|
2432
|
+
let output = opts.json ? JSON.stringify(record, null, 2) : formatAudit(record, { root, sessionCount: logs.length, skipped, claudeMdSource });
|
|
2381
2433
|
const notices = [];
|
|
2382
2434
|
if (opts.html) {
|
|
2383
2435
|
const target = resolve(opts.htmlPath || DEFAULT_HTML_FILE);
|
|
2384
|
-
const doc = renderHtml(record, { root, sessionCount: logs.length, skipped });
|
|
2436
|
+
const doc = renderHtml(record, { root, sessionCount: logs.length, skipped, claudeMdSource });
|
|
2385
2437
|
await writeFile(target, doc, "utf8");
|
|
2386
2438
|
openInBrowser(target);
|
|
2387
2439
|
notices.push(`HTML report written to ${target}`);
|
|
@@ -2402,11 +2454,11 @@ async function runAudit(opts) {
|
|
|
2402
2454
|
|
|
2403
2455
|
// src/optimize-command.ts
|
|
2404
2456
|
import { mkdir, writeFile as writeFile2, readFile as readFile4, stat as stat2 } from "fs/promises";
|
|
2405
|
-
import { join as
|
|
2457
|
+
import { join as join5, dirname } from "path";
|
|
2406
2458
|
|
|
2407
2459
|
// src/project-scan.ts
|
|
2408
2460
|
import { readdir as readdir2, readFile as readFile3, stat } from "fs/promises";
|
|
2409
|
-
import { join as
|
|
2461
|
+
import { join as join4, basename } from "path";
|
|
2410
2462
|
var NOISE_DIRS = /* @__PURE__ */ new Set([
|
|
2411
2463
|
"node_modules",
|
|
2412
2464
|
".git",
|
|
@@ -2546,7 +2598,7 @@ async function detectTestsLocation(dir, files, dirs) {
|
|
|
2546
2598
|
if (dirs.includes("__tests__")) return "tests in __tests__/";
|
|
2547
2599
|
if (files.some((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f))) return "tests alongside source (*.test.* / *.spec.*)";
|
|
2548
2600
|
if (dirs.includes("src")) {
|
|
2549
|
-
const sub = await listEntries(
|
|
2601
|
+
const sub = await listEntries(join4(dir, "src"));
|
|
2550
2602
|
if (sub.files.some((f) => /\.(test|spec)\.[cm]?[jt]sx?$/.test(f))) {
|
|
2551
2603
|
return "tests alongside source (*.test.* / *.spec.*)";
|
|
2552
2604
|
}
|
|
@@ -2629,7 +2681,7 @@ async function scanNode(dir, files, dirs, pkg, profile) {
|
|
|
2629
2681
|
if (oneFileCmd !== null && "test" in scripts) {
|
|
2630
2682
|
profile.commands.push({ label: "test one file", command: oneFileCmd });
|
|
2631
2683
|
}
|
|
2632
|
-
const tsconfig = parseJson(await readText(
|
|
2684
|
+
const tsconfig = parseJson(await readText(join4(dir, "tsconfig.json")));
|
|
2633
2685
|
if (tsconfig) {
|
|
2634
2686
|
const co = tsconfig.compilerOptions;
|
|
2635
2687
|
if (co && co.strict === true) pushUnique(profile.codeStyle, "TypeScript strict mode");
|
|
@@ -2732,7 +2784,7 @@ async function scanPython(dir, files, profile) {
|
|
|
2732
2784
|
const deps = [];
|
|
2733
2785
|
const tables = /* @__PURE__ */ new Set();
|
|
2734
2786
|
let hasPoetry = false;
|
|
2735
|
-
const pyprojectText = await readText(
|
|
2787
|
+
const pyprojectText = await readText(join4(dir, "pyproject.toml"));
|
|
2736
2788
|
if (pyprojectText !== null) {
|
|
2737
2789
|
const parsed = parsePyproject(pyprojectText);
|
|
2738
2790
|
name = parsed.name;
|
|
@@ -2742,7 +2794,7 @@ async function scanPython(dir, files, profile) {
|
|
|
2742
2794
|
hasPoetry = parsed.hasPoetry;
|
|
2743
2795
|
}
|
|
2744
2796
|
if (files.includes("requirements.txt")) {
|
|
2745
|
-
const reqText = await readText(
|
|
2797
|
+
const reqText = await readText(join4(dir, "requirements.txt"));
|
|
2746
2798
|
if (reqText !== null) for (const d of pyDepsFromRequirements(reqText)) pushUnique(deps, d);
|
|
2747
2799
|
}
|
|
2748
2800
|
if (name !== null && name.trim() !== "") profile.name = name;
|
|
@@ -2776,7 +2828,7 @@ async function scanPython(dir, files, profile) {
|
|
|
2776
2828
|
}
|
|
2777
2829
|
}
|
|
2778
2830
|
async function scanRust(dir, profile) {
|
|
2779
|
-
const text2 = await readText(
|
|
2831
|
+
const text2 = await readText(join4(dir, "Cargo.toml"));
|
|
2780
2832
|
pushUnique(profile.stack, "Rust");
|
|
2781
2833
|
profile.packageManager = "cargo";
|
|
2782
2834
|
if (text2 !== null) {
|
|
@@ -2802,7 +2854,7 @@ async function scanRust(dir, profile) {
|
|
|
2802
2854
|
profile.commands.push({ label: "lint", command: "cargo clippy" });
|
|
2803
2855
|
}
|
|
2804
2856
|
async function scanGo(dir, profile) {
|
|
2805
|
-
const text2 = await readText(
|
|
2857
|
+
const text2 = await readText(join4(dir, "go.mod"));
|
|
2806
2858
|
pushUnique(profile.stack, "Go");
|
|
2807
2859
|
profile.packageManager = "go";
|
|
2808
2860
|
if (text2 !== null) {
|
|
@@ -2867,7 +2919,7 @@ async function scanProject(dir) {
|
|
|
2867
2919
|
const profile = emptyProfile(basename(dir));
|
|
2868
2920
|
const { files, dirs } = await listEntries(dir);
|
|
2869
2921
|
if (files.includes("package.json")) {
|
|
2870
|
-
const pkg = parseJson(await readText(
|
|
2922
|
+
const pkg = parseJson(await readText(join4(dir, "package.json")));
|
|
2871
2923
|
if (pkg) await scanNode(dir, files, dirs, pkg, profile);
|
|
2872
2924
|
}
|
|
2873
2925
|
if (files.includes("pyproject.toml") || files.includes("requirements.txt") || files.includes("setup.py")) {
|
|
@@ -2880,7 +2932,7 @@ async function scanProject(dir) {
|
|
|
2880
2932
|
await scanGo(dir, profile);
|
|
2881
2933
|
}
|
|
2882
2934
|
if (files.includes("Makefile") && profile.commands.length === 0) {
|
|
2883
|
-
const text2 = await readText(
|
|
2935
|
+
const text2 = await readText(join4(dir, "Makefile"));
|
|
2884
2936
|
if (text2 !== null) {
|
|
2885
2937
|
for (const t of parseMakefile(text2)) {
|
|
2886
2938
|
profile.commands.push({ label: t, command: `make ${t}` });
|
|
@@ -2890,7 +2942,7 @@ async function scanProject(dir) {
|
|
|
2890
2942
|
if (profile.description === null || profile.name === basename(dir)) {
|
|
2891
2943
|
const readmeName = files.find((f) => /^readme(\.md|\.markdown|\.txt)?$/i.test(f));
|
|
2892
2944
|
if (readmeName) {
|
|
2893
|
-
const text2 = await readText(
|
|
2945
|
+
const text2 = await readText(join4(dir, readmeName));
|
|
2894
2946
|
if (text2 !== null) {
|
|
2895
2947
|
const parsed = parseReadme(text2);
|
|
2896
2948
|
if (profile.name === basename(dir) && parsed.name !== null) profile.name = parsed.name;
|
|
@@ -2903,7 +2955,7 @@ async function scanProject(dir) {
|
|
|
2903
2955
|
profile.structure = await detectStructure(dir, dirs);
|
|
2904
2956
|
const envFile = files.includes(".env.example") ? ".env.example" : files.includes(".env.sample") ? ".env.sample" : null;
|
|
2905
2957
|
if (envFile) {
|
|
2906
|
-
const text2 = await readText(
|
|
2958
|
+
const text2 = await readText(join4(dir, envFile));
|
|
2907
2959
|
if (text2 !== null) profile.envVars = parseEnvNames(text2);
|
|
2908
2960
|
}
|
|
2909
2961
|
return profile;
|
|
@@ -3028,11 +3080,11 @@ async function runOptimize(opts) {
|
|
|
3028
3080
|
const project = await scanProject(projectDir);
|
|
3029
3081
|
const result = optimize({ report, scores: pillars, fixes, currentClaudeMd: claudeMd, project });
|
|
3030
3082
|
const recoverable = cacheMissExposureUsd(report);
|
|
3031
|
-
const outDir = opts.out ||
|
|
3083
|
+
const outDir = opts.out || join5(process.cwd(), "costclaw-out");
|
|
3032
3084
|
await mkdir(outDir, { recursive: true });
|
|
3033
|
-
const playbookPath =
|
|
3085
|
+
const playbookPath = join5(outDir, PLAYBOOK_NAME);
|
|
3034
3086
|
await writeFile2(playbookPath, result.playbook, "utf8");
|
|
3035
|
-
const settingsPath =
|
|
3087
|
+
const settingsPath = join5(outDir, SETTINGS_NAME);
|
|
3036
3088
|
await writeFile2(settingsPath, result.settingsJson, "utf8");
|
|
3037
3089
|
const lines = [];
|
|
3038
3090
|
lines.push("CostClaw optimize");
|
|
@@ -3062,7 +3114,7 @@ async function runOptimize(opts) {
|
|
|
3062
3114
|
lines.push("Warning: this scaffold has placeholders to fill in. Search it for <!-- ... --> and replace each with your project's real details.");
|
|
3063
3115
|
lines.push("A suggested settings.json was written to the out dir for review; it is not applied in place.");
|
|
3064
3116
|
} else {
|
|
3065
|
-
const optimizedPath =
|
|
3117
|
+
const optimizedPath = join5(outDir, OPTIMIZED_NAME);
|
|
3066
3118
|
await writeFile2(optimizedPath, result.optimizedClaudeMd, "utf8");
|
|
3067
3119
|
lines.push("Dry run (no files of yours were changed).");
|
|
3068
3120
|
lines.push(`Wrote the optimized CLAUDE.md scaffold to ${optimizedPath}`);
|
|
@@ -3079,7 +3131,7 @@ async function runOptimize(opts) {
|
|
|
3079
3131
|
lines.push("To merge it into the project's .claude/settings.json for you (with a backup and a diff first), rerun with --apply-settings.");
|
|
3080
3132
|
}
|
|
3081
3133
|
if (opts.applySettings) {
|
|
3082
|
-
const target = opts.applySettingsPath ||
|
|
3134
|
+
const target = opts.applySettingsPath || join5(projectDir, ".claude", "settings.json");
|
|
3083
3135
|
const applyLines = await applyDerivedSettings(target, result.settingsJson, opts.force ?? false);
|
|
3084
3136
|
lines.push("");
|
|
3085
3137
|
lines.push(...applyLines);
|
|
@@ -3127,8 +3179,8 @@ async function runBadge(opts) {
|
|
|
3127
3179
|
|
|
3128
3180
|
// src/license.ts
|
|
3129
3181
|
import { mkdir as mkdir2, readFile as readFile5, writeFile as writeFile4, rm } from "fs/promises";
|
|
3130
|
-
import { join as
|
|
3131
|
-
import { homedir as
|
|
3182
|
+
import { join as join6 } from "path";
|
|
3183
|
+
import { homedir as homedir4, hostname } from "os";
|
|
3132
3184
|
import { createPublicKey, verify as cryptoVerify } from "crypto";
|
|
3133
3185
|
var LICENSE_PRODUCT = "costclaw-optimize";
|
|
3134
3186
|
var DEFAULT_PUBLIC_KEY_PEM = `-----BEGIN PUBLIC KEY-----
|
|
@@ -3153,10 +3205,10 @@ var INVALID_MESSAGE = [
|
|
|
3153
3205
|
"costclaw audit stays free."
|
|
3154
3206
|
].join("\n");
|
|
3155
3207
|
function defaultConfigDir() {
|
|
3156
|
-
return
|
|
3208
|
+
return join6(homedir4(), ".costclaw");
|
|
3157
3209
|
}
|
|
3158
3210
|
function licenseFile(dir) {
|
|
3159
|
-
return
|
|
3211
|
+
return join6(dir, "license.json");
|
|
3160
3212
|
}
|
|
3161
3213
|
function base64UrlDecode(part) {
|
|
3162
3214
|
return Buffer.from(part.replace(/-/g, "+").replace(/_/g, "/"), "base64");
|
|
@@ -3268,7 +3320,7 @@ function parseBadgeFlags(args) {
|
|
|
3268
3320
|
};
|
|
3269
3321
|
}
|
|
3270
3322
|
function cliVersion() {
|
|
3271
|
-
return true ? "0.2.
|
|
3323
|
+
return true ? "0.2.2" : "0.0.0-dev";
|
|
3272
3324
|
}
|
|
3273
3325
|
function helpText() {
|
|
3274
3326
|
return [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "costclaw",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.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": {
|