costclaw 0.8.0 → 0.8.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 +3 -1
- package/dist/index.js +33 -9
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -111,7 +111,9 @@ costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--h
|
|
|
111
111
|
everything, so nothing is fetched and nothing is uploaded; the terminal
|
|
112
112
|
report still prints (in color on interactive terminals; set `NO_COLOR` to
|
|
113
113
|
disable). `--html <file>` picks the path; `--no-html` skips the file;
|
|
114
|
-
`--json` runs stay file-free unless `--html` is passed explicitly.
|
|
114
|
+
`--json` runs stay file-free unless `--html` is passed explicitly. Set
|
|
115
|
+
`COSTCLAW_NO_OPEN=1` to write reports without launching a browser (CI and
|
|
116
|
+
test runners are detected and never open one).
|
|
115
117
|
- `--card [file]` also write a shareable score card SVG (default
|
|
116
118
|
`costclaw-card.svg`): your score, band, recoverable spend, cache hit rate, and
|
|
117
119
|
strongest pillar. A static file, no fonts or network calls.
|
package/dist/index.js
CHANGED
|
@@ -128,13 +128,25 @@ function projectFromCwd(cwd) {
|
|
|
128
128
|
const parts = cwd.split(/[\\/]+/).filter(Boolean);
|
|
129
129
|
return parts.length ? parts[parts.length - 1] : null;
|
|
130
130
|
}
|
|
131
|
+
function commandTarget(command) {
|
|
132
|
+
let s = command.trim();
|
|
133
|
+
const hop = /^(?:cd|Set-Location|pushd)\s+(?:"[^"]*"|'[^']*'|\S+)\s*(?:&&|;)\s*/i;
|
|
134
|
+
const env = /^[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|\S*)\s+/;
|
|
135
|
+
for (; ; ) {
|
|
136
|
+
const next = s.replace(hop, "").replace(env, "");
|
|
137
|
+
if (next === s) break;
|
|
138
|
+
s = next;
|
|
139
|
+
}
|
|
140
|
+
const words = s.split(/\s+/).filter(Boolean);
|
|
141
|
+
if (words.length === 0) return null;
|
|
142
|
+
return words.slice(0, 2).join(" ").slice(0, 60);
|
|
143
|
+
}
|
|
131
144
|
function targetFor(name, input) {
|
|
132
145
|
const s = (v, n) => typeof v === "string" && v.length ? v.slice(0, n) : null;
|
|
133
146
|
if (["Read", "Edit", "Write", "NotebookEdit"].includes(name)) return s(input.file_path, 200);
|
|
134
147
|
if (["Grep", "Glob"].includes(name)) return s(input.path ?? input.glob ?? input.pattern, 160);
|
|
135
148
|
if (["Bash", "PowerShell"].includes(name)) {
|
|
136
|
-
|
|
137
|
-
return cmd ? cmd.slice(0, 60) : null;
|
|
149
|
+
return typeof input.command === "string" ? commandTarget(input.command) : null;
|
|
138
150
|
}
|
|
139
151
|
if (name.startsWith("Task")) return s(input.subject ?? input.description, 80);
|
|
140
152
|
if (["WebFetch", "WebSearch"].includes(name)) return s(input.url ?? input.query, 60);
|
|
@@ -353,6 +365,8 @@ var HIT_FLOOR = 0.5;
|
|
|
353
365
|
var STREAK = 3;
|
|
354
366
|
var HOT_PROJECT_SHARE = 0.6;
|
|
355
367
|
var HEAVY_TOOL_FIRES = 100;
|
|
368
|
+
var HEAVY_TOOL_MIN_SHARE = 0.6;
|
|
369
|
+
var REDUNDANT_TARGET_MIN_SHARE = 0.25;
|
|
356
370
|
var SHORT_SESSION_MAX_MINUTES = 10;
|
|
357
371
|
var SHORT_SESSION_MIN_COST = 5;
|
|
358
372
|
var MARATHON_MIN_TURNS = 40;
|
|
@@ -368,6 +382,11 @@ var MISROUTE_BASELINE = "claude-sonnet-4-6";
|
|
|
368
382
|
var WORKFLOW_MIN_COST = 5;
|
|
369
383
|
var WORKFLOW_WARN_SHARE = 0.5;
|
|
370
384
|
var REDUNDANT_TARGET_MIN_FIRES = 10;
|
|
385
|
+
function toolCallTotal(s) {
|
|
386
|
+
let sum = 0;
|
|
387
|
+
for (const n of Object.values(s.toolUsage)) sum += n;
|
|
388
|
+
return Math.max(sum, s.toolEvents.length);
|
|
389
|
+
}
|
|
371
390
|
function thirdHit(turns, lo, hi) {
|
|
372
391
|
let read = 0;
|
|
373
392
|
let total = 0;
|
|
@@ -436,8 +455,9 @@ function ruleHeavyToolLoops(ctx) {
|
|
|
436
455
|
const byTool = /* @__PURE__ */ new Map();
|
|
437
456
|
for (const s of proj.sessions) {
|
|
438
457
|
if (s.kind !== "main") continue;
|
|
458
|
+
const total = toolCallTotal(s);
|
|
439
459
|
for (const [tool, fires] of Object.entries(s.toolUsage)) {
|
|
440
|
-
if (fires < HEAVY_TOOL_FIRES) continue;
|
|
460
|
+
if (fires < HEAVY_TOOL_FIRES || fires < total * HEAVY_TOOL_MIN_SHARE) continue;
|
|
441
461
|
const entry = byTool.get(tool) ?? { sessionsAffected: 0, maxFires: 0, sessionUuids: [] };
|
|
442
462
|
entry.sessionsAffected += 1;
|
|
443
463
|
entry.maxFires = Math.max(entry.maxFires, fires);
|
|
@@ -473,6 +493,7 @@ function ruleRedundantTargetThrash(ctx) {
|
|
|
473
493
|
const byTool = /* @__PURE__ */ new Map();
|
|
474
494
|
for (const s of proj.sessions) {
|
|
475
495
|
if (s.kind !== "main") continue;
|
|
496
|
+
const total = toolCallTotal(s);
|
|
476
497
|
const counts = /* @__PURE__ */ new Map();
|
|
477
498
|
for (const e of s.toolEvents) {
|
|
478
499
|
if (e.target == null) continue;
|
|
@@ -483,7 +504,7 @@ function ruleRedundantTargetThrash(ctx) {
|
|
|
483
504
|
const perToolMax = /* @__PURE__ */ new Map();
|
|
484
505
|
for (const [tool, byTarget] of counts) {
|
|
485
506
|
for (const n of byTarget.values()) {
|
|
486
|
-
if (n < REDUNDANT_TARGET_MIN_FIRES) continue;
|
|
507
|
+
if (n < REDUNDANT_TARGET_MIN_FIRES || n < total * REDUNDANT_TARGET_MIN_SHARE) continue;
|
|
487
508
|
perToolMax.set(tool, Math.max(perToolMax.get(tool) ?? 0, n));
|
|
488
509
|
}
|
|
489
510
|
}
|
|
@@ -1068,7 +1089,7 @@ function buildChecks(report, cmd, answers, setup) {
|
|
|
1068
1089
|
"prompting",
|
|
1069
1090
|
"Tool looping",
|
|
1070
1091
|
s.sessionsCount > 0 ? clamp2(100 - thrashShare * 180) : null,
|
|
1071
|
-
s.sessionsCount === 0 ? "No sessions to assess." : thrashSessions === 0 ? "No sign of a stuck tool loop." : `${thrashSessions} of ${s.sessionsCount} sessions (${thrashPct}%) showed heavy tool repetition: one tool
|
|
1092
|
+
s.sessionsCount === 0 ? "No sessions to assess." : thrashSessions === 0 ? "No sign of a stuck tool loop." : `${thrashSessions} of ${s.sessionsCount} sessions (${thrashPct}%) showed heavy tool repetition: one tool making 100 or more calls and most of the session's tool calls, or the same file, command, or target hit 10 or more times and a quarter of the session's tool calls.`,
|
|
1072
1093
|
"metrics"
|
|
1073
1094
|
)
|
|
1074
1095
|
);
|
|
@@ -1189,7 +1210,7 @@ function scorePillars(report, cmd, answers, setup) {
|
|
|
1189
1210
|
const cfg = PILLARS[id];
|
|
1190
1211
|
const pillarChecks = checks.filter((c) => c.pillar === id);
|
|
1191
1212
|
const assessedChecks = pillarChecks.filter((c) => c.assessed);
|
|
1192
|
-
const assessed = assessedChecks.length > 0;
|
|
1213
|
+
const assessed = assessedChecks.length > 0 && assessedChecks.length * 2 >= pillarChecks.length;
|
|
1193
1214
|
const score = assessed ? Math.round(assessedChecks.reduce((sum, c) => sum + c.score, 0) / assessedChecks.length) : null;
|
|
1194
1215
|
return { id, name: cfg.name, weight: cfg.weight, assessed, score, checks: pillarChecks };
|
|
1195
1216
|
});
|
|
@@ -2807,6 +2828,7 @@ import { homedir as homedir3 } from "os";
|
|
|
2807
2828
|
// src/open.ts
|
|
2808
2829
|
import { spawn } from "child_process";
|
|
2809
2830
|
function openInBrowser(target) {
|
|
2831
|
+
if (process.env["VITEST"] || process.env["CI"] || process.env["COSTCLAW_NO_OPEN"]) return;
|
|
2810
2832
|
try {
|
|
2811
2833
|
const platform = process.platform;
|
|
2812
2834
|
const [cmd, args] = platform === "win32" ? ["cmd", ["/c", "start", "", target]] : platform === "darwin" ? ["open", [target]] : ["xdg-open", [target]];
|
|
@@ -3070,9 +3092,11 @@ function unassessedLine(pillars) {
|
|
|
3070
3092
|
const gaps = pillars.filter((p) => !p.assessed);
|
|
3071
3093
|
if (gaps.length === 0) return null;
|
|
3072
3094
|
const parts = gaps.map((p) => {
|
|
3073
|
-
const reason = p.checks
|
|
3095
|
+
const reason = p.checks.find((c) => !c.assessed)?.basis;
|
|
3074
3096
|
const hint = p.id === "claude_md" ? " Pass --claude-md <file> to score it." : "";
|
|
3075
|
-
|
|
3097
|
+
const partial = p.checks.filter((c) => c.assessed && c.score !== null).map((c) => `${c.label} alone scores ${c.score}`).join(", ");
|
|
3098
|
+
const tail = partial ? ` ${partial}.` : "";
|
|
3099
|
+
return reason ? `${p.name} (${reason}${hint}${tail})` : p.name;
|
|
3076
3100
|
});
|
|
3077
3101
|
return `Not yet scored: ${parts.join(" ")}`;
|
|
3078
3102
|
}
|
|
@@ -5293,7 +5317,7 @@ function parseBadgeFlags(args) {
|
|
|
5293
5317
|
};
|
|
5294
5318
|
}
|
|
5295
5319
|
function cliVersion() {
|
|
5296
|
-
return true ? "0.8.
|
|
5320
|
+
return true ? "0.8.1" : "0.0.0-dev";
|
|
5297
5321
|
}
|
|
5298
5322
|
function isHelpRequest(command, args) {
|
|
5299
5323
|
if (command === void 0) return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "costclaw",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.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": {
|
|
@@ -34,10 +34,12 @@
|
|
|
34
34
|
"diff": "tsx src/index.ts diff",
|
|
35
35
|
"optimize": "tsx src/index.ts optimize",
|
|
36
36
|
"dev": "tsx src/index.ts",
|
|
37
|
-
"build": "tsup",
|
|
38
|
-
"test": "vitest run",
|
|
37
|
+
"build": "npm run check:privacy && tsup",
|
|
38
|
+
"test": "npm run check:no-network && vitest run",
|
|
39
39
|
"typecheck": "tsc --noEmit",
|
|
40
|
-
"
|
|
40
|
+
"check:no-network": "node ../../scripts/check-no-network.mjs",
|
|
41
|
+
"check:privacy": "npm --prefix ../../packages/engine run test -- tests/audit.test.ts",
|
|
42
|
+
"prepublishOnly": "npm run check:no-network && npm run build"
|
|
41
43
|
},
|
|
42
44
|
"devDependencies": {
|
|
43
45
|
"@costclaw/engine": "*",
|