costclaw 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.js +238 -14
- 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,19 +128,64 @@ 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);
|
|
141
153
|
if (name === "Agent") return s(input.subagent_type ?? input.description, 60);
|
|
142
154
|
return null;
|
|
143
155
|
}
|
|
156
|
+
var PLAN_TOOLS = /* @__PURE__ */ new Set(["EnterPlanMode", "ExitPlanMode", "TodoWrite", "TaskCreate", "Skill", "Workflow"]);
|
|
157
|
+
var VERIFY_RE = /^(?:(?:npm|pnpm|yarn|bun|deno|npx|python3?|py|make|dotnet|mvn|gradle|cargo|go)(?:\s+\S+)*?\s+(?:test|tests|vitest|jest|pytest|typecheck|tsc|lint|build|check|verify|clippy|vet)(?:[:\s]|$)|(?:pytest|tsc|vitest|jest|eslint|ruff|mypy|golangci-lint)(?:\s|$))/i;
|
|
158
|
+
var CORRECTION_RE = /^(?:no[,.!\s]|nope\b|wrong\b|that'?s (?:not|wrong)|not what i|undo\b|revert\b|stop\b|don'?t\b|why did you|you broke|still (?:broken|failing|wrong|not))/i;
|
|
159
|
+
var RICH_RE = /(?:^|\s)@\S|[A-Za-z]:[\\/]|(?:^|\s)\.?\/\S+\/|https?:\/\/|```|\n\s*[-*]\s/;
|
|
160
|
+
var SLASH_PREFIXES = ["<command-name>", "<local-command", "<command-message>"];
|
|
161
|
+
var INTERRUPT_MARK = "[Request interrupted by user";
|
|
162
|
+
function isVerifyCommand(command) {
|
|
163
|
+
let s = command.trim();
|
|
164
|
+
const hop = /^(?:cd|Set-Location|pushd)\s+(?:"[^"]*"|'[^']*'|\S+)\s*(?:&&|;)\s*/i;
|
|
165
|
+
for (; ; ) {
|
|
166
|
+
const next = s.replace(hop, "");
|
|
167
|
+
if (next === s) break;
|
|
168
|
+
s = next;
|
|
169
|
+
}
|
|
170
|
+
return VERIFY_RE.test(s);
|
|
171
|
+
}
|
|
172
|
+
function humanText(rec) {
|
|
173
|
+
if (rec.isMeta) return null;
|
|
174
|
+
const c = rec.message?.content;
|
|
175
|
+
if (typeof c === "string") return c.trim() ? { text: c, hasImage: false } : null;
|
|
176
|
+
if (!Array.isArray(c)) return null;
|
|
177
|
+
let text2 = "";
|
|
178
|
+
let hasImage = false;
|
|
179
|
+
for (const b of c) {
|
|
180
|
+
if (!b || typeof b !== "object") continue;
|
|
181
|
+
if (b.type === "text" && typeof b.text === "string") text2 += (text2 ? "\n" : "") + b.text;
|
|
182
|
+
else if (b.type === "image") hasImage = true;
|
|
183
|
+
}
|
|
184
|
+
return text2.trim() || hasImage ? { text: text2, hasImage } : null;
|
|
185
|
+
}
|
|
186
|
+
function emptyPromptSignals() {
|
|
187
|
+
return { humanPrompts: 0, openerWords: null, openerRich: false, corrections: 0, interrupts: 0, slashCommands: 0, planEvents: 0, verifyRuns: 0 };
|
|
188
|
+
}
|
|
144
189
|
var isToolUse = (b) => !!b && typeof b === "object" && b.type === "tool_use" && typeof b.name === "string";
|
|
145
190
|
function extractTools(content) {
|
|
146
191
|
const names = [];
|
|
@@ -180,8 +225,10 @@ function parseSession(text2, opts = {}) {
|
|
|
180
225
|
kind: opts.kind ?? "main",
|
|
181
226
|
parentSessionId: opts.parentSessionId ?? null,
|
|
182
227
|
turnCache: [],
|
|
183
|
-
costBuckets: []
|
|
228
|
+
costBuckets: [],
|
|
229
|
+
prompting: emptyPromptSignals()
|
|
184
230
|
};
|
|
231
|
+
const ps = s.prompting;
|
|
185
232
|
const seen = /* @__PURE__ */ new Set();
|
|
186
233
|
const buckets = /* @__PURE__ */ new Map();
|
|
187
234
|
const BUCKET_MS = 15 * 60 * 1e3;
|
|
@@ -203,13 +250,36 @@ function parseSession(text2, opts = {}) {
|
|
|
203
250
|
if (s.endedAt === null || rec.timestamp > s.endedAt) s.endedAt = rec.timestamp;
|
|
204
251
|
}
|
|
205
252
|
if (rec.type !== "user" && rec.type !== "assistant") continue;
|
|
206
|
-
if (rec.type === "user")
|
|
207
|
-
|
|
253
|
+
if (rec.type === "user") {
|
|
254
|
+
s.userRecords += 1;
|
|
255
|
+
const h = humanText(rec);
|
|
256
|
+
if (h) {
|
|
257
|
+
const t = h.text.trimStart();
|
|
258
|
+
if (t.includes(INTERRUPT_MARK)) ps.interrupts += 1;
|
|
259
|
+
else if (SLASH_PREFIXES.some((p) => t.startsWith(p))) ps.slashCommands += 1;
|
|
260
|
+
else if (!t.startsWith("<") || h.hasImage) {
|
|
261
|
+
ps.humanPrompts += 1;
|
|
262
|
+
if (ps.openerWords === null) {
|
|
263
|
+
ps.openerWords = t.split(/\s+/).filter(Boolean).length;
|
|
264
|
+
ps.openerRich = h.hasImage || RICH_RE.test(h.text);
|
|
265
|
+
}
|
|
266
|
+
if (CORRECTION_RE.test(t)) ps.corrections += 1;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
} else s.assistantRecords += 1;
|
|
208
270
|
const model = rec.message?.model;
|
|
209
271
|
if (model && model !== "<synthetic>") modelCounts.set(model, (modelCounts.get(model) ?? 0) + 1);
|
|
210
272
|
if (rec.type === "assistant") {
|
|
211
273
|
const { names, events } = extractTools(rec.message?.content);
|
|
212
|
-
for (const n of names)
|
|
274
|
+
for (const n of names) {
|
|
275
|
+
s.toolUsage[n] = (s.toolUsage[n] ?? 0) + 1;
|
|
276
|
+
if (PLAN_TOOLS.has(n)) ps.planEvents += 1;
|
|
277
|
+
}
|
|
278
|
+
if (Array.isArray(rec.message?.content)) {
|
|
279
|
+
for (const b of rec.message.content) {
|
|
280
|
+
if (isToolUse(b) && (b.name === "Bash" || b.name === "PowerShell") && typeof b.input?.command === "string" && isVerifyCommand(b.input.command)) ps.verifyRuns += 1;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
213
283
|
const requestId = rec.requestId || rec.message?.requestId || null;
|
|
214
284
|
for (const e of events) s.toolEvents.push({ name: e.name, requestId, target: e.target });
|
|
215
285
|
const usage = rec.message?.usage;
|
|
@@ -353,6 +423,8 @@ var HIT_FLOOR = 0.5;
|
|
|
353
423
|
var STREAK = 3;
|
|
354
424
|
var HOT_PROJECT_SHARE = 0.6;
|
|
355
425
|
var HEAVY_TOOL_FIRES = 100;
|
|
426
|
+
var HEAVY_TOOL_MIN_SHARE = 0.6;
|
|
427
|
+
var REDUNDANT_TARGET_MIN_SHARE = 0.25;
|
|
356
428
|
var SHORT_SESSION_MAX_MINUTES = 10;
|
|
357
429
|
var SHORT_SESSION_MIN_COST = 5;
|
|
358
430
|
var MARATHON_MIN_TURNS = 40;
|
|
@@ -368,6 +440,11 @@ var MISROUTE_BASELINE = "claude-sonnet-4-6";
|
|
|
368
440
|
var WORKFLOW_MIN_COST = 5;
|
|
369
441
|
var WORKFLOW_WARN_SHARE = 0.5;
|
|
370
442
|
var REDUNDANT_TARGET_MIN_FIRES = 10;
|
|
443
|
+
function toolCallTotal(s) {
|
|
444
|
+
let sum = 0;
|
|
445
|
+
for (const n of Object.values(s.toolUsage)) sum += n;
|
|
446
|
+
return Math.max(sum, s.toolEvents.length);
|
|
447
|
+
}
|
|
371
448
|
function thirdHit(turns, lo, hi) {
|
|
372
449
|
let read = 0;
|
|
373
450
|
let total = 0;
|
|
@@ -436,8 +513,9 @@ function ruleHeavyToolLoops(ctx) {
|
|
|
436
513
|
const byTool = /* @__PURE__ */ new Map();
|
|
437
514
|
for (const s of proj.sessions) {
|
|
438
515
|
if (s.kind !== "main") continue;
|
|
516
|
+
const total = toolCallTotal(s);
|
|
439
517
|
for (const [tool, fires] of Object.entries(s.toolUsage)) {
|
|
440
|
-
if (fires < HEAVY_TOOL_FIRES) continue;
|
|
518
|
+
if (fires < HEAVY_TOOL_FIRES || fires < total * HEAVY_TOOL_MIN_SHARE) continue;
|
|
441
519
|
const entry = byTool.get(tool) ?? { sessionsAffected: 0, maxFires: 0, sessionUuids: [] };
|
|
442
520
|
entry.sessionsAffected += 1;
|
|
443
521
|
entry.maxFires = Math.max(entry.maxFires, fires);
|
|
@@ -473,6 +551,7 @@ function ruleRedundantTargetThrash(ctx) {
|
|
|
473
551
|
const byTool = /* @__PURE__ */ new Map();
|
|
474
552
|
for (const s of proj.sessions) {
|
|
475
553
|
if (s.kind !== "main") continue;
|
|
554
|
+
const total = toolCallTotal(s);
|
|
476
555
|
const counts = /* @__PURE__ */ new Map();
|
|
477
556
|
for (const e of s.toolEvents) {
|
|
478
557
|
if (e.target == null) continue;
|
|
@@ -483,7 +562,7 @@ function ruleRedundantTargetThrash(ctx) {
|
|
|
483
562
|
const perToolMax = /* @__PURE__ */ new Map();
|
|
484
563
|
for (const [tool, byTarget] of counts) {
|
|
485
564
|
for (const n of byTarget.values()) {
|
|
486
|
-
if (n < REDUNDANT_TARGET_MIN_FIRES) continue;
|
|
565
|
+
if (n < REDUNDANT_TARGET_MIN_FIRES || n < total * REDUNDANT_TARGET_MIN_SHARE) continue;
|
|
487
566
|
perToolMax.set(tool, Math.max(perToolMax.get(tool) ?? 0, n));
|
|
488
567
|
}
|
|
489
568
|
}
|
|
@@ -792,7 +871,7 @@ var PILLARS = {
|
|
|
792
871
|
id: "prompting",
|
|
793
872
|
name: "Prompting patterns",
|
|
794
873
|
weight: 0.15,
|
|
795
|
-
description: "Whether you plan before
|
|
874
|
+
description: "Whether you give the agent a check to run, plan before big changes, open with specifics, correct early, and reuse skills instead of retyping.",
|
|
796
875
|
color: "#60A5FA"
|
|
797
876
|
},
|
|
798
877
|
session_mgmt: {
|
|
@@ -943,6 +1022,70 @@ function optionScore(question, optionId) {
|
|
|
943
1022
|
return opt ? opt.score : null;
|
|
944
1023
|
}
|
|
945
1024
|
|
|
1025
|
+
// ../../packages/engine/src/prompting.ts
|
|
1026
|
+
var SUBSTANTIAL_MIN_TURNS = 20;
|
|
1027
|
+
var SHORT_OPENER_MAX_WORDS = 12;
|
|
1028
|
+
var CHURN_MIN_CORRECTIONS = 3;
|
|
1029
|
+
var EDIT_TOOLS = ["Edit", "Write", "MultiEdit", "NotebookEdit"];
|
|
1030
|
+
var REUSE_TOOLS = ["Skill", "Workflow", "Agent"];
|
|
1031
|
+
function editCalls(s) {
|
|
1032
|
+
let n = 0;
|
|
1033
|
+
for (const t of EDIT_TOOLS) n += s.toolUsage[t] ?? 0;
|
|
1034
|
+
return n;
|
|
1035
|
+
}
|
|
1036
|
+
function reuseCalls(s) {
|
|
1037
|
+
let n = 0;
|
|
1038
|
+
for (const t of REUSE_TOOLS) n += s.toolUsage[t] ?? 0;
|
|
1039
|
+
return n;
|
|
1040
|
+
}
|
|
1041
|
+
function aggregatePrompting(report) {
|
|
1042
|
+
const out = {
|
|
1043
|
+
sessions: 0,
|
|
1044
|
+
editSessions: 0,
|
|
1045
|
+
verifiedSessions: 0,
|
|
1046
|
+
substantialSessions: 0,
|
|
1047
|
+
plannedSessions: 0,
|
|
1048
|
+
openerSessions: 0,
|
|
1049
|
+
shortOpeners: 0,
|
|
1050
|
+
medianOpenerWords: null,
|
|
1051
|
+
promptedSessions: 0,
|
|
1052
|
+
churnSessions: 0,
|
|
1053
|
+
reuseSessions: 0
|
|
1054
|
+
};
|
|
1055
|
+
const openers = [];
|
|
1056
|
+
for (const p of report.projects) {
|
|
1057
|
+
for (const s of p.sessions) {
|
|
1058
|
+
if (s.kind !== "main" || !s.prompting) continue;
|
|
1059
|
+
const ps = s.prompting;
|
|
1060
|
+
out.sessions += 1;
|
|
1061
|
+
const edits = editCalls(s);
|
|
1062
|
+
if (edits > 0) {
|
|
1063
|
+
out.editSessions += 1;
|
|
1064
|
+
if (ps.verifyRuns > 0) out.verifiedSessions += 1;
|
|
1065
|
+
if (s.assistantRecords >= SUBSTANTIAL_MIN_TURNS) {
|
|
1066
|
+
out.substantialSessions += 1;
|
|
1067
|
+
if (ps.planEvents > 0) out.plannedSessions += 1;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
if (ps.openerWords !== null) {
|
|
1071
|
+
out.openerSessions += 1;
|
|
1072
|
+
openers.push(ps.openerWords);
|
|
1073
|
+
if (ps.openerWords < SHORT_OPENER_MAX_WORDS && !ps.openerRich) out.shortOpeners += 1;
|
|
1074
|
+
}
|
|
1075
|
+
if (ps.humanPrompts > 0) {
|
|
1076
|
+
out.promptedSessions += 1;
|
|
1077
|
+
if (ps.corrections + ps.interrupts >= CHURN_MIN_CORRECTIONS) out.churnSessions += 1;
|
|
1078
|
+
}
|
|
1079
|
+
if (ps.slashCommands > 0 || reuseCalls(s) > 0) out.reuseSessions += 1;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (openers.length > 0) {
|
|
1083
|
+
openers.sort((a, b) => a - b);
|
|
1084
|
+
out.medianOpenerWords = openers[Math.floor(openers.length / 2)] ?? null;
|
|
1085
|
+
}
|
|
1086
|
+
return out;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
946
1089
|
// ../../packages/engine/src/scoring.ts
|
|
947
1090
|
function clamp2(n, lo = 0, hi = 100) {
|
|
948
1091
|
return Math.max(lo, Math.min(hi, n));
|
|
@@ -1051,6 +1194,64 @@ function buildChecks(report, cmd, answers, setup) {
|
|
|
1051
1194
|
)
|
|
1052
1195
|
);
|
|
1053
1196
|
checks.push(questionnaireCheck("clear_between", "Clearing between tasks", answers));
|
|
1197
|
+
const pr = aggregatePrompting(report);
|
|
1198
|
+
const pct2 = (n, d) => d > 0 ? Math.round(n / d * 100) : 0;
|
|
1199
|
+
const plural3 = (n, w) => `${n} ${w}${n === 1 ? "" : "s"}`;
|
|
1200
|
+
const verifiedShare = pr.editSessions > 0 ? pr.verifiedSessions / pr.editSessions : 0;
|
|
1201
|
+
checks.push(
|
|
1202
|
+
makeCheck(
|
|
1203
|
+
"verify_loop",
|
|
1204
|
+
"prompting",
|
|
1205
|
+
"Verification loop",
|
|
1206
|
+
pr.editSessions > 0 ? clamp2(verifiedShare / 0.6 * 100) : null,
|
|
1207
|
+
pr.editSessions === 0 ? "No session edited files, so there is nothing to verify." : `${pr.verifiedSessions} of ${plural3(pr.editSessions, "session")} that edited files (${pct2(pr.verifiedSessions, pr.editSessions)}%) also ran a test, build, typecheck, or lint. Without a check the agent can run, "looks done" is the only signal and you become the verification loop.`,
|
|
1208
|
+
"metrics"
|
|
1209
|
+
)
|
|
1210
|
+
);
|
|
1211
|
+
const plannedShare = pr.substantialSessions > 0 ? pr.plannedSessions / pr.substantialSessions : 0;
|
|
1212
|
+
checks.push(
|
|
1213
|
+
makeCheck(
|
|
1214
|
+
"plan_before_code",
|
|
1215
|
+
"prompting",
|
|
1216
|
+
"Plan before code",
|
|
1217
|
+
pr.substantialSessions > 0 ? clamp2(plannedShare / 0.6 * 100) : null,
|
|
1218
|
+
pr.substantialSessions === 0 ? `No session reached ${SUBSTANTIAL_MIN_TURNS} turns with edits, so planning was not assessed.` : `${pr.plannedSessions} of ${plural3(pr.substantialSessions, "substantial session")} (${SUBSTANTIAL_MIN_TURNS}+ turns with edits, ${pct2(pr.plannedSessions, pr.substantialSessions)}%) used plan mode, a task list, a skill, or a workflow before building. Small clear fixes are excluded on purpose.`,
|
|
1219
|
+
"metrics"
|
|
1220
|
+
)
|
|
1221
|
+
);
|
|
1222
|
+
const shortShare = pr.openerSessions > 0 ? pr.shortOpeners / pr.openerSessions : 0;
|
|
1223
|
+
checks.push(
|
|
1224
|
+
makeCheck(
|
|
1225
|
+
"prompt_specificity",
|
|
1226
|
+
"prompting",
|
|
1227
|
+
"Prompt specificity",
|
|
1228
|
+
pr.openerSessions > 0 ? clamp2(100 - shortShare * 180) : null,
|
|
1229
|
+
pr.openerSessions === 0 ? "No human opening prompt was found." : `${pr.shortOpeners} of ${plural3(pr.openerSessions, "session")} (${pct2(pr.shortOpeners, pr.openerSessions)}%) opened with under ${SHORT_OPENER_MAX_WORDS} words and no file, path, link, image, or pasted context; the median opener is ${pr.medianOpenerWords ?? 0} words. Vague openers cost corrections later.`,
|
|
1230
|
+
"metrics"
|
|
1231
|
+
)
|
|
1232
|
+
);
|
|
1233
|
+
const churnShare = pr.promptedSessions > 0 ? pr.churnSessions / pr.promptedSessions : 0;
|
|
1234
|
+
checks.push(
|
|
1235
|
+
makeCheck(
|
|
1236
|
+
"correction_churn",
|
|
1237
|
+
"prompting",
|
|
1238
|
+
"Correction churn",
|
|
1239
|
+
pr.promptedSessions > 0 ? clamp2(100 - churnShare * 300) : null,
|
|
1240
|
+
pr.promptedSessions === 0 ? "No human prompts were found." : `${pr.churnSessions} of ${plural3(pr.promptedSessions, "session")} (${pct2(pr.churnSessions, pr.promptedSessions)}%) hit ${CHURN_MIN_CORRECTIONS} or more corrections or interrupts. After two failed corrections the context is full of failed approaches; clear and re-prompt with what you learned.`,
|
|
1241
|
+
"metrics"
|
|
1242
|
+
)
|
|
1243
|
+
);
|
|
1244
|
+
const reuseShare = pr.sessions > 0 ? pr.reuseSessions / pr.sessions : 0;
|
|
1245
|
+
checks.push(
|
|
1246
|
+
makeCheck(
|
|
1247
|
+
"reusable_workflows",
|
|
1248
|
+
"prompting",
|
|
1249
|
+
"Reusable workflows",
|
|
1250
|
+
pr.sessions > 0 ? clamp2(reuseShare / 0.3 * 100) : null,
|
|
1251
|
+
pr.sessions === 0 ? "No sessions carried prompt signals." : `${pr.reuseSessions} of ${plural3(pr.sessions, "session")} (${pct2(pr.reuseSessions, pr.sessions)}%) used a slash command, skill, workflow, or subagent. Repeated work belongs in a skill so the prompt is written once and the research stays out of your main context.`,
|
|
1252
|
+
"metrics"
|
|
1253
|
+
)
|
|
1254
|
+
);
|
|
1054
1255
|
checks.push(questionnaireCheck("plan_first", "Planning first", answers));
|
|
1055
1256
|
checks.push(questionnaireCheck("success_criteria", "Self-verification", answers));
|
|
1056
1257
|
const heavyLoops = report.findings.filter((f) => f.ruleId === "HEAVY_TOOL_LOOPS" || f.ruleId === "REDUNDANT_TARGET_THRASH");
|
|
@@ -1068,7 +1269,7 @@ function buildChecks(report, cmd, answers, setup) {
|
|
|
1068
1269
|
"prompting",
|
|
1069
1270
|
"Tool looping",
|
|
1070
1271
|
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
|
|
1272
|
+
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
1273
|
"metrics"
|
|
1073
1274
|
)
|
|
1074
1275
|
);
|
|
@@ -1189,7 +1390,7 @@ function scorePillars(report, cmd, answers, setup) {
|
|
|
1189
1390
|
const cfg = PILLARS[id];
|
|
1190
1391
|
const pillarChecks = checks.filter((c) => c.pillar === id);
|
|
1191
1392
|
const assessedChecks = pillarChecks.filter((c) => c.assessed);
|
|
1192
|
-
const assessed = assessedChecks.length > 0;
|
|
1393
|
+
const assessed = assessedChecks.length > 0 && assessedChecks.length * 2 >= pillarChecks.length;
|
|
1193
1394
|
const score = assessed ? Math.round(assessedChecks.reduce((sum, c) => sum + c.score, 0) / assessedChecks.length) : null;
|
|
1194
1395
|
return { id, name: cfg.name, weight: cfg.weight, assessed, score, checks: pillarChecks };
|
|
1195
1396
|
});
|
|
@@ -1207,6 +1408,26 @@ function scorePillars(report, cmd, answers, setup) {
|
|
|
1207
1408
|
|
|
1208
1409
|
// ../../packages/engine/src/synthesize.ts
|
|
1209
1410
|
var CHECK_FIX = {
|
|
1411
|
+
verify_loop: {
|
|
1412
|
+
title: "Give the agent a check it can run",
|
|
1413
|
+
action: "End the prompt with the check: 'run the tests after implementing', 'verify the build succeeds', or a screenshot to compare. The loop then closes on its own instead of waiting for you to notice a mistake."
|
|
1414
|
+
},
|
|
1415
|
+
plan_before_code: {
|
|
1416
|
+
title: "Plan before multi-file changes",
|
|
1417
|
+
action: "For work that touches several files or unfamiliar code, start in plan mode (Shift+Tab) or ask for a plan first, approve it, then implement. Skip the plan when you could describe the diff in one sentence."
|
|
1418
|
+
},
|
|
1419
|
+
prompt_specificity: {
|
|
1420
|
+
title: "Open with specifics, not a headline",
|
|
1421
|
+
action: "Name the file with @, paste the error or screenshot, state the scenario and what 'fixed' looks like. 'fix the login bug' becomes 'login fails after session timeout; check src/auth token refresh; write a failing test, then fix it'."
|
|
1422
|
+
},
|
|
1423
|
+
correction_churn: {
|
|
1424
|
+
title: "Clear and re-prompt after two corrections",
|
|
1425
|
+
action: "When a session needs a third correction, run /clear and write a fresh prompt that includes what you learned. A clean session with a better prompt beats a long one full of failed approaches."
|
|
1426
|
+
},
|
|
1427
|
+
reusable_workflows: {
|
|
1428
|
+
title: "Turn repeated prompts into skills",
|
|
1429
|
+
action: "Put any workflow you have typed twice into .claude/skills/<name>/SKILL.md and invoke it with /name. Delegate broad investigation to a subagent so the reading stays out of your main context."
|
|
1430
|
+
},
|
|
1210
1431
|
cmd_structure: {
|
|
1211
1432
|
title: "Give CLAUDE.md clear structure",
|
|
1212
1433
|
action: "Break the file into sections with headings and short bulleted rules so the agent finds the right guidance fast instead of scanning a wall of text."
|
|
@@ -2807,6 +3028,7 @@ import { homedir as homedir3 } from "os";
|
|
|
2807
3028
|
// src/open.ts
|
|
2808
3029
|
import { spawn } from "child_process";
|
|
2809
3030
|
function openInBrowser(target) {
|
|
3031
|
+
if (process.env["VITEST"] || process.env["CI"] || process.env["COSTCLAW_NO_OPEN"]) return;
|
|
2810
3032
|
try {
|
|
2811
3033
|
const platform = process.platform;
|
|
2812
3034
|
const [cmd, args] = platform === "win32" ? ["cmd", ["/c", "start", "", target]] : platform === "darwin" ? ["open", [target]] : ["xdg-open", [target]];
|
|
@@ -3070,9 +3292,11 @@ function unassessedLine(pillars) {
|
|
|
3070
3292
|
const gaps = pillars.filter((p) => !p.assessed);
|
|
3071
3293
|
if (gaps.length === 0) return null;
|
|
3072
3294
|
const parts = gaps.map((p) => {
|
|
3073
|
-
const reason = p.checks
|
|
3295
|
+
const reason = p.checks.find((c) => !c.assessed)?.basis;
|
|
3074
3296
|
const hint = p.id === "claude_md" ? " Pass --claude-md <file> to score it." : "";
|
|
3075
|
-
|
|
3297
|
+
const partial = p.checks.filter((c) => c.assessed && c.score !== null).map((c) => `${c.label} alone scores ${c.score}`).join(", ");
|
|
3298
|
+
const tail = partial ? ` ${partial}.` : "";
|
|
3299
|
+
return reason ? `${p.name} (${reason}${hint}${tail})` : p.name;
|
|
3076
3300
|
});
|
|
3077
3301
|
return `Not yet scored: ${parts.join(" ")}`;
|
|
3078
3302
|
}
|
|
@@ -5293,7 +5517,7 @@ function parseBadgeFlags(args) {
|
|
|
5293
5517
|
};
|
|
5294
5518
|
}
|
|
5295
5519
|
function cliVersion() {
|
|
5296
|
-
return true ? "0.
|
|
5520
|
+
return true ? "0.9.0" : "0.0.0-dev";
|
|
5297
5521
|
}
|
|
5298
5522
|
function isHelpRequest(command, args) {
|
|
5299
5523
|
if (command === void 0) return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "costclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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": "*",
|