costclaw 0.8.1 → 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/dist/index.js +206 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -153,6 +153,39 @@ function targetFor(name, input) {
|
|
|
153
153
|
if (name === "Agent") return s(input.subagent_type ?? input.description, 60);
|
|
154
154
|
return null;
|
|
155
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
|
+
}
|
|
156
189
|
var isToolUse = (b) => !!b && typeof b === "object" && b.type === "tool_use" && typeof b.name === "string";
|
|
157
190
|
function extractTools(content) {
|
|
158
191
|
const names = [];
|
|
@@ -192,8 +225,10 @@ function parseSession(text2, opts = {}) {
|
|
|
192
225
|
kind: opts.kind ?? "main",
|
|
193
226
|
parentSessionId: opts.parentSessionId ?? null,
|
|
194
227
|
turnCache: [],
|
|
195
|
-
costBuckets: []
|
|
228
|
+
costBuckets: [],
|
|
229
|
+
prompting: emptyPromptSignals()
|
|
196
230
|
};
|
|
231
|
+
const ps = s.prompting;
|
|
197
232
|
const seen = /* @__PURE__ */ new Set();
|
|
198
233
|
const buckets = /* @__PURE__ */ new Map();
|
|
199
234
|
const BUCKET_MS = 15 * 60 * 1e3;
|
|
@@ -215,13 +250,36 @@ function parseSession(text2, opts = {}) {
|
|
|
215
250
|
if (s.endedAt === null || rec.timestamp > s.endedAt) s.endedAt = rec.timestamp;
|
|
216
251
|
}
|
|
217
252
|
if (rec.type !== "user" && rec.type !== "assistant") continue;
|
|
218
|
-
if (rec.type === "user")
|
|
219
|
-
|
|
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;
|
|
220
270
|
const model = rec.message?.model;
|
|
221
271
|
if (model && model !== "<synthetic>") modelCounts.set(model, (modelCounts.get(model) ?? 0) + 1);
|
|
222
272
|
if (rec.type === "assistant") {
|
|
223
273
|
const { names, events } = extractTools(rec.message?.content);
|
|
224
|
-
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
|
+
}
|
|
225
283
|
const requestId = rec.requestId || rec.message?.requestId || null;
|
|
226
284
|
for (const e of events) s.toolEvents.push({ name: e.name, requestId, target: e.target });
|
|
227
285
|
const usage = rec.message?.usage;
|
|
@@ -813,7 +871,7 @@ var PILLARS = {
|
|
|
813
871
|
id: "prompting",
|
|
814
872
|
name: "Prompting patterns",
|
|
815
873
|
weight: 0.15,
|
|
816
|
-
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.",
|
|
817
875
|
color: "#60A5FA"
|
|
818
876
|
},
|
|
819
877
|
session_mgmt: {
|
|
@@ -964,6 +1022,70 @@ function optionScore(question, optionId) {
|
|
|
964
1022
|
return opt ? opt.score : null;
|
|
965
1023
|
}
|
|
966
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
|
+
|
|
967
1089
|
// ../../packages/engine/src/scoring.ts
|
|
968
1090
|
function clamp2(n, lo = 0, hi = 100) {
|
|
969
1091
|
return Math.max(lo, Math.min(hi, n));
|
|
@@ -1072,6 +1194,64 @@ function buildChecks(report, cmd, answers, setup) {
|
|
|
1072
1194
|
)
|
|
1073
1195
|
);
|
|
1074
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
|
+
);
|
|
1075
1255
|
checks.push(questionnaireCheck("plan_first", "Planning first", answers));
|
|
1076
1256
|
checks.push(questionnaireCheck("success_criteria", "Self-verification", answers));
|
|
1077
1257
|
const heavyLoops = report.findings.filter((f) => f.ruleId === "HEAVY_TOOL_LOOPS" || f.ruleId === "REDUNDANT_TARGET_THRASH");
|
|
@@ -1228,6 +1408,26 @@ function scorePillars(report, cmd, answers, setup) {
|
|
|
1228
1408
|
|
|
1229
1409
|
// ../../packages/engine/src/synthesize.ts
|
|
1230
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
|
+
},
|
|
1231
1431
|
cmd_structure: {
|
|
1232
1432
|
title: "Give CLAUDE.md clear structure",
|
|
1233
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."
|
|
@@ -5317,7 +5517,7 @@ function parseBadgeFlags(args) {
|
|
|
5317
5517
|
};
|
|
5318
5518
|
}
|
|
5319
5519
|
function cliVersion() {
|
|
5320
|
-
return true ? "0.
|
|
5520
|
+
return true ? "0.9.0" : "0.0.0-dev";
|
|
5321
5521
|
}
|
|
5322
5522
|
function isHelpRequest(command, args) {
|
|
5323
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": {
|