costclaw 0.15.1 → 0.16.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/dist/index.js +272 -44
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3938,7 +3938,7 @@ function diffAudits(a, b) {
|
|
|
3938
3938
|
const curFixes = new Map(cur.fixes.map((f) => [f.id, f]));
|
|
3939
3939
|
const resolved = base.fixes.filter((f) => !curFixes.has(f.id)).map((f) => ({ id: f.id, title: f.title, wasteUsd: round22(f.wasteUsd) }));
|
|
3940
3940
|
const appeared = cur.fixes.filter((f) => !baseFixes.has(f.id)).map((f) => ({ id: f.id, title: f.title, wasteUsd: round22(f.wasteUsd) }));
|
|
3941
|
-
const
|
|
3941
|
+
const changed2 = cur.fixes.filter((f) => baseFixes.has(f.id)).map((f) => {
|
|
3942
3942
|
const beforeUsd = round22(baseFixes.get(f.id).wasteUsd);
|
|
3943
3943
|
const afterUsd = round22(f.wasteUsd);
|
|
3944
3944
|
return { id: f.id, title: f.title, beforeUsd, afterUsd, deltaUsd: round22(afterUsd - beforeUsd) };
|
|
@@ -3963,7 +3963,7 @@ function diffAudits(a, b) {
|
|
|
3963
3963
|
cacheHitRatePoints: round42(cm.cacheHitRate - bm.cacheHitRate)
|
|
3964
3964
|
},
|
|
3965
3965
|
pillars,
|
|
3966
|
-
fixes: { resolved, appeared, changed }
|
|
3966
|
+
fixes: { resolved, appeared, changed: changed2 }
|
|
3967
3967
|
};
|
|
3968
3968
|
}
|
|
3969
3969
|
var SINCE_BASELINE_MIN_TOKENS = 1e6;
|
|
@@ -5928,7 +5928,7 @@ async function runAudit(opts) {
|
|
|
5928
5928
|
|
|
5929
5929
|
// src/optimize-command.ts
|
|
5930
5930
|
import { mkdir as mkdir6, writeFile as writeFile6, readFile as readFile10, stat as stat3 } from "fs/promises";
|
|
5931
|
-
import { basename as
|
|
5931
|
+
import { basename as basename4, join as join10, resolve as resolve6 } from "path";
|
|
5932
5932
|
import { homedir as homedir6 } from "os";
|
|
5933
5933
|
|
|
5934
5934
|
// src/claude-md-imports.ts
|
|
@@ -5959,7 +5959,7 @@ async function resolveClaudeMdImports(claudeMdPath, text2, home) {
|
|
|
5959
5959
|
|
|
5960
5960
|
// src/apply-command.ts
|
|
5961
5961
|
import { mkdir as mkdir4, writeFile as writeFile4, readFile as readFile6, rm as rm3, stat, copyFile } from "fs/promises";
|
|
5962
|
-
import { join as join7, dirname as dirname3 } from "path";
|
|
5962
|
+
import { join as join7, dirname as dirname3, basename as basename2 } from "path";
|
|
5963
5963
|
import { homedir as homedir5 } from "os";
|
|
5964
5964
|
var IMPORT_LINE2 = "@.claude/costclaw.md";
|
|
5965
5965
|
var INCLUDE_REL = ".claude/costclaw.md";
|
|
@@ -6048,6 +6048,12 @@ function ensureImportLine(claudeMd) {
|
|
|
6048
6048
|
function stripImportLine(claudeMd) {
|
|
6049
6049
|
return stripLine(claudeMd, IMPORT_LINE2);
|
|
6050
6050
|
}
|
|
6051
|
+
async function contentOrNull(path) {
|
|
6052
|
+
return await pathExists(path) ? await readFile6(path, "utf8") : null;
|
|
6053
|
+
}
|
|
6054
|
+
function changed(path, label, before, after) {
|
|
6055
|
+
return before === after ? null : { path, label, before, after };
|
|
6056
|
+
}
|
|
6051
6057
|
async function runInclude(opts) {
|
|
6052
6058
|
const { projectDir, artifactsDir } = opts;
|
|
6053
6059
|
const includeSrc = join7(artifactsDir, INCLUDE_ARTIFACT);
|
|
@@ -6058,8 +6064,12 @@ async function runInclude(opts) {
|
|
|
6058
6064
|
const claudeDir = join7(projectDir, ".claude");
|
|
6059
6065
|
await mkdir4(claudeDir, { recursive: true });
|
|
6060
6066
|
const includeDest = join7(projectDir, INCLUDE_REL);
|
|
6067
|
+
const includeBefore = await contentOrNull(includeDest);
|
|
6061
6068
|
await writeFile4(includeDest, includeMd, "utf8");
|
|
6062
6069
|
const wrote = [includeDest];
|
|
6070
|
+
const files = [];
|
|
6071
|
+
const includeChange = changed(includeDest, INCLUDE_REL, includeBefore, includeMd);
|
|
6072
|
+
if (includeChange) files.push(includeChange);
|
|
6063
6073
|
const lines = [`Wrote ${INCLUDE_REL}`, ...describeIncludeSections(await readIncludeSections(artifactsDir))];
|
|
6064
6074
|
const claudeMdPath = join7(projectDir, "CLAUDE.md");
|
|
6065
6075
|
const existing = await pathExists(claudeMdPath) ? await readFile6(claudeMdPath, "utf8") : null;
|
|
@@ -6067,6 +6077,7 @@ async function runInclude(opts) {
|
|
|
6067
6077
|
if (added) {
|
|
6068
6078
|
await writeFile4(claudeMdPath, text2, "utf8");
|
|
6069
6079
|
wrote.push(claudeMdPath);
|
|
6080
|
+
files.push({ path: claudeMdPath, label: "CLAUDE.md", before: existing, after: text2 });
|
|
6070
6081
|
lines.push(`Added "${IMPORT_LINE2}" to CLAUDE.md`);
|
|
6071
6082
|
} else {
|
|
6072
6083
|
lines.push("CLAUDE.md already imports it");
|
|
@@ -6088,20 +6099,24 @@ async function runInclude(opts) {
|
|
|
6088
6099
|
const settingsSrc = join7(artifactsDir, "settings.suggested.json");
|
|
6089
6100
|
const suggestedJson = await readFile6(settingsSrc, "utf8");
|
|
6090
6101
|
const target = opts.applySettingsPath ?? join7(projectDir, ".claude", "settings.json");
|
|
6091
|
-
const
|
|
6092
|
-
lines.push(...
|
|
6102
|
+
const settings = await applyDerivedSettings(target, suggestedJson);
|
|
6103
|
+
lines.push(...settings.lines);
|
|
6093
6104
|
wrote.push(target);
|
|
6105
|
+
if (settings.file) files.push(settings.file);
|
|
6094
6106
|
}
|
|
6095
|
-
return { lines, wrote, removed: [] };
|
|
6107
|
+
return { lines, wrote, removed: [], files };
|
|
6096
6108
|
}
|
|
6097
6109
|
async function runRemove(opts) {
|
|
6098
6110
|
const { projectDir } = opts;
|
|
6099
6111
|
const includeDest = join7(projectDir, INCLUDE_REL);
|
|
6100
6112
|
const companionDir = join7(projectDir, APPLY_DIR_REL);
|
|
6101
6113
|
const removed = [];
|
|
6102
|
-
|
|
6114
|
+
const files = [];
|
|
6115
|
+
const includeBefore = await contentOrNull(includeDest);
|
|
6116
|
+
if (includeBefore !== null) {
|
|
6103
6117
|
await rm3(includeDest, { force: true });
|
|
6104
6118
|
removed.push(includeDest);
|
|
6119
|
+
files.push({ path: includeDest, label: INCLUDE_REL, before: includeBefore, after: null });
|
|
6105
6120
|
}
|
|
6106
6121
|
if (await pathExists(companionDir)) {
|
|
6107
6122
|
await rm3(companionDir, { recursive: true, force: true });
|
|
@@ -6116,14 +6131,16 @@ async function runRemove(opts) {
|
|
|
6116
6131
|
if (text2 === "") {
|
|
6117
6132
|
await rm3(claudeMdPath, { force: true });
|
|
6118
6133
|
removed.push(claudeMdPath);
|
|
6134
|
+
files.push({ path: claudeMdPath, label: "CLAUDE.md", before: existing, after: null });
|
|
6119
6135
|
lines.push("Removed CLAUDE.md (it held only the import line)");
|
|
6120
6136
|
} else {
|
|
6121
6137
|
await writeFile4(claudeMdPath, text2, "utf8");
|
|
6138
|
+
files.push({ path: claudeMdPath, label: "CLAUDE.md", before: existing, after: text2 });
|
|
6122
6139
|
lines.push(`Removed "${IMPORT_LINE2}" from CLAUDE.md`);
|
|
6123
6140
|
}
|
|
6124
6141
|
}
|
|
6125
6142
|
}
|
|
6126
|
-
return { lines, wrote: [], removed };
|
|
6143
|
+
return { lines, wrote: [], removed, files };
|
|
6127
6144
|
}
|
|
6128
6145
|
async function runReplace(opts) {
|
|
6129
6146
|
const { projectDir, artifactsDir } = opts;
|
|
@@ -6150,7 +6167,12 @@ async function runReplace(opts) {
|
|
|
6150
6167
|
"",
|
|
6151
6168
|
backup ? `Undo: git checkout -- CLAUDE.md (or restore ${backup})` : "Undo: git checkout -- CLAUDE.md"
|
|
6152
6169
|
];
|
|
6153
|
-
return {
|
|
6170
|
+
return {
|
|
6171
|
+
lines,
|
|
6172
|
+
wrote: backup ? [claudeMdPath, backup] : [claudeMdPath],
|
|
6173
|
+
removed: [],
|
|
6174
|
+
files: [{ path: claudeMdPath, label: "CLAUDE.md", before: original === "" ? null : original, after: optimized }]
|
|
6175
|
+
};
|
|
6154
6176
|
}
|
|
6155
6177
|
async function runApply(opts) {
|
|
6156
6178
|
if (opts.global) return runGlobal(opts);
|
|
@@ -6165,20 +6187,25 @@ async function runGlobal(opts) {
|
|
|
6165
6187
|
if (opts.mode === "remove") {
|
|
6166
6188
|
const removed = [];
|
|
6167
6189
|
const lines2 = [];
|
|
6168
|
-
|
|
6190
|
+
const files2 = [];
|
|
6191
|
+
const includeBefore = await contentOrNull(includeDest);
|
|
6192
|
+
if (includeBefore !== null) {
|
|
6169
6193
|
await rm3(includeDest, { force: true });
|
|
6170
6194
|
removed.push(includeDest);
|
|
6195
|
+
files2.push({ path: includeDest, label: GLOBAL_INCLUDE_REL, before: includeBefore, after: null });
|
|
6171
6196
|
lines2.push(`Removed ${GLOBAL_INCLUDE_REL}`);
|
|
6172
6197
|
}
|
|
6173
|
-
|
|
6174
|
-
|
|
6198
|
+
const mdBefore = await contentOrNull(claudeMdPath);
|
|
6199
|
+
if (mdBefore !== null) {
|
|
6200
|
+
const { text: text2, removed: didRemove } = stripLine(mdBefore, GLOBAL_IMPORT_LINE);
|
|
6175
6201
|
if (didRemove) {
|
|
6176
6202
|
await writeFile4(claudeMdPath, text2, "utf8");
|
|
6203
|
+
files2.push({ path: claudeMdPath, label: "~/.claude/CLAUDE.md", before: mdBefore, after: text2 });
|
|
6177
6204
|
lines2.push(`Removed "${GLOBAL_IMPORT_LINE}" from ${claudeMdPath}`);
|
|
6178
6205
|
}
|
|
6179
6206
|
}
|
|
6180
6207
|
if (lines2.length === 0) lines2.push("Nothing to remove: the global include was not applied.");
|
|
6181
|
-
return { lines: lines2, wrote: [], removed };
|
|
6208
|
+
return { lines: lines2, wrote: [], removed, files: files2 };
|
|
6182
6209
|
}
|
|
6183
6210
|
const includeSrc = join7(opts.artifactsDir, GLOBAL_INCLUDE_ARTIFACT);
|
|
6184
6211
|
const optimizedSrc = join7(opts.artifactsDir, GLOBAL_OPTIMIZED_ARTIFACT);
|
|
@@ -6192,10 +6219,15 @@ async function runGlobal(opts) {
|
|
|
6192
6219
|
const backup = await backupFile(claudeMdPath);
|
|
6193
6220
|
const wrote = [];
|
|
6194
6221
|
const lines = [];
|
|
6222
|
+
const files = [];
|
|
6195
6223
|
await mkdir4(dirname3(claudeMdPath), { recursive: true });
|
|
6196
6224
|
if (hasInclude) {
|
|
6197
|
-
|
|
6225
|
+
const includeAfter = await readFile6(includeSrc, "utf8");
|
|
6226
|
+
const includeBefore = await contentOrNull(includeDest);
|
|
6227
|
+
await writeFile4(includeDest, includeAfter, "utf8");
|
|
6198
6228
|
wrote.push(includeDest);
|
|
6229
|
+
const c = changed(includeDest, GLOBAL_INCLUDE_REL, includeBefore, includeAfter);
|
|
6230
|
+
if (c) files.push(c);
|
|
6199
6231
|
lines.push(`Wrote ${GLOBAL_INCLUDE_REL}`);
|
|
6200
6232
|
} else {
|
|
6201
6233
|
lines.push("Your audit produced no global sections to add, so no include file was written.");
|
|
@@ -6211,6 +6243,7 @@ async function runGlobal(opts) {
|
|
|
6211
6243
|
}
|
|
6212
6244
|
await writeFile4(claudeMdPath, optimized, "utf8");
|
|
6213
6245
|
wrote.push(claudeMdPath);
|
|
6246
|
+
files.push({ path: claudeMdPath, label: "~/.claude/CLAUDE.md", before: original, after: optimized });
|
|
6214
6247
|
lines.push(
|
|
6215
6248
|
`Rewrote ${claudeMdPath} with every reviewed removal applied`,
|
|
6216
6249
|
"",
|
|
@@ -6222,6 +6255,7 @@ async function runGlobal(opts) {
|
|
|
6222
6255
|
if (added) {
|
|
6223
6256
|
await writeFile4(claudeMdPath, text2, "utf8");
|
|
6224
6257
|
wrote.push(claudeMdPath);
|
|
6258
|
+
files.push({ path: claudeMdPath, label: "~/.claude/CLAUDE.md", before: original, after: text2 });
|
|
6225
6259
|
lines.push(`Added "${GLOBAL_IMPORT_LINE}" to ${claudeMdPath}`);
|
|
6226
6260
|
} else {
|
|
6227
6261
|
lines.push("Your global CLAUDE.md already imports it");
|
|
@@ -6232,7 +6266,7 @@ async function runGlobal(opts) {
|
|
|
6232
6266
|
}
|
|
6233
6267
|
if (backup) lines.push(`Backed up the original to ${backup}`);
|
|
6234
6268
|
lines.push("Undo: costclaw apply --global --remove");
|
|
6235
|
-
return { lines, wrote, removed: [] };
|
|
6269
|
+
return { lines, wrote, removed: [], files };
|
|
6236
6270
|
}
|
|
6237
6271
|
function lineDiff(oldText, newText) {
|
|
6238
6272
|
const oldLines = oldText.split(/\r?\n/);
|
|
@@ -6303,17 +6337,100 @@ async function applyDerivedSettings(target, suggestedJson) {
|
|
|
6303
6337
|
mergedPerms.deny = unionStrings(asStringArray(existingPerms.deny), suggestedDeny);
|
|
6304
6338
|
const merged = { ...existing, permissions: mergedPerms };
|
|
6305
6339
|
const mergedText = JSON.stringify(merged, null, 2) + "\n";
|
|
6340
|
+
if (mergedText === existingText) {
|
|
6341
|
+
return {
|
|
6342
|
+
lines: [`${target} already has every derived permission; nothing to merge.`],
|
|
6343
|
+
file: null
|
|
6344
|
+
};
|
|
6345
|
+
}
|
|
6306
6346
|
await mkdir4(dirname3(target), { recursive: true });
|
|
6307
6347
|
const backup = await backupFile(target);
|
|
6308
6348
|
await writeFile4(target, mergedText, "utf8");
|
|
6309
|
-
return
|
|
6310
|
-
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6349
|
+
return {
|
|
6350
|
+
lines: [
|
|
6351
|
+
`Merged the derived permission allowlist into ${target}`,
|
|
6352
|
+
...backup ? [`Backed up the previous file to ${backup}`] : [],
|
|
6353
|
+
"Only permissions.allow and permissions.deny changed (deduped union, existing entries kept and ordered first). Every other key was left as it was.",
|
|
6354
|
+
"",
|
|
6355
|
+
"Diff (previous vs merged):",
|
|
6356
|
+
lineDiff(existingText, mergedText)
|
|
6357
|
+
],
|
|
6358
|
+
file: changed(target, basename2(target), existingText === "" ? null : existingText, mergedText)
|
|
6359
|
+
};
|
|
6360
|
+
}
|
|
6361
|
+
|
|
6362
|
+
// src/line-align.ts
|
|
6363
|
+
var MAX_LINES = 4e3;
|
|
6364
|
+
function splitLines(text2) {
|
|
6365
|
+
if (text2 === null) return [];
|
|
6366
|
+
const lines = text2.split(/\r?\n/);
|
|
6367
|
+
if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
|
|
6368
|
+
return lines;
|
|
6369
|
+
}
|
|
6370
|
+
function alignLines(before, after) {
|
|
6371
|
+
const a = splitLines(before);
|
|
6372
|
+
const b = splitLines(after);
|
|
6373
|
+
if (a.length > MAX_LINES || b.length > MAX_LINES) {
|
|
6374
|
+
const rows2 = [
|
|
6375
|
+
...a.map((text2, i2) => ({ kind: "remove", left: text2, right: null, leftNo: i2 + 1, rightNo: null })),
|
|
6376
|
+
...b.map((text2, i2) => ({ kind: "add", left: null, right: text2, leftNo: null, rightNo: i2 + 1 }))
|
|
6377
|
+
];
|
|
6378
|
+
return { rows: rows2, added: b.length, removed: a.length, truncated: true };
|
|
6379
|
+
}
|
|
6380
|
+
const lcs = Array.from({ length: a.length + 1 }, () => new Array(b.length + 1).fill(0));
|
|
6381
|
+
for (let i2 = a.length - 1; i2 >= 0; i2--) {
|
|
6382
|
+
for (let j2 = b.length - 1; j2 >= 0; j2--) {
|
|
6383
|
+
lcs[i2][j2] = a[i2] === b[j2] ? lcs[i2 + 1][j2 + 1] + 1 : Math.max(lcs[i2 + 1][j2], lcs[i2][j2 + 1]);
|
|
6384
|
+
}
|
|
6385
|
+
}
|
|
6386
|
+
const rows = [];
|
|
6387
|
+
let added = 0;
|
|
6388
|
+
let removed = 0;
|
|
6389
|
+
let i = 0;
|
|
6390
|
+
let j = 0;
|
|
6391
|
+
while (i < a.length && j < b.length) {
|
|
6392
|
+
if (a[i] === b[j]) {
|
|
6393
|
+
rows.push({ kind: "same", left: a[i], right: b[j], leftNo: i + 1, rightNo: j + 1 });
|
|
6394
|
+
i++;
|
|
6395
|
+
j++;
|
|
6396
|
+
} else if (lcs[i + 1][j] >= lcs[i][j + 1]) {
|
|
6397
|
+
rows.push({ kind: "remove", left: a[i], right: null, leftNo: i + 1, rightNo: null });
|
|
6398
|
+
removed++;
|
|
6399
|
+
i++;
|
|
6400
|
+
} else {
|
|
6401
|
+
rows.push({ kind: "add", left: null, right: b[j], leftNo: null, rightNo: j + 1 });
|
|
6402
|
+
added++;
|
|
6403
|
+
j++;
|
|
6404
|
+
}
|
|
6405
|
+
}
|
|
6406
|
+
for (; i < a.length; i++) {
|
|
6407
|
+
rows.push({ kind: "remove", left: a[i], right: null, leftNo: i + 1, rightNo: null });
|
|
6408
|
+
removed++;
|
|
6409
|
+
}
|
|
6410
|
+
for (; j < b.length; j++) {
|
|
6411
|
+
rows.push({ kind: "add", left: null, right: b[j], leftNo: null, rightNo: j + 1 });
|
|
6412
|
+
added++;
|
|
6413
|
+
}
|
|
6414
|
+
return { rows, added, removed, truncated: false };
|
|
6415
|
+
}
|
|
6416
|
+
function collapseUnchanged(rows, context = 3) {
|
|
6417
|
+
const keep = /* @__PURE__ */ new Set();
|
|
6418
|
+
for (let i = 0; i < rows.length; i++) {
|
|
6419
|
+
if (rows[i].kind === "same") continue;
|
|
6420
|
+
for (let k = Math.max(0, i - context); k <= Math.min(rows.length - 1, i + context); k++) keep.add(k);
|
|
6421
|
+
}
|
|
6422
|
+
const out = [];
|
|
6423
|
+
let gap = false;
|
|
6424
|
+
for (let i = 0; i < rows.length; i++) {
|
|
6425
|
+
if (keep.has(i)) {
|
|
6426
|
+
out.push(rows[i]);
|
|
6427
|
+
gap = false;
|
|
6428
|
+
} else if (!gap) {
|
|
6429
|
+
out.push(null);
|
|
6430
|
+
gap = true;
|
|
6431
|
+
}
|
|
6432
|
+
}
|
|
6433
|
+
return out;
|
|
6317
6434
|
}
|
|
6318
6435
|
|
|
6319
6436
|
// src/optimize-dashboard.ts
|
|
@@ -6403,6 +6520,30 @@ ul.warn b{font-weight:650}
|
|
|
6403
6520
|
.file a{margin-top:auto;font-size:.83rem;color:var(--ink);text-decoration:none;border-bottom:1px solid var(--line);
|
|
6404
6521
|
align-self:flex-start;padding-bottom:1px}
|
|
6405
6522
|
.file a:hover{border-color:var(--accent)}
|
|
6523
|
+
|
|
6524
|
+
/* A file card that opens in place instead of navigating to raw markdown. */
|
|
6525
|
+
details.viewer{padding:0}
|
|
6526
|
+
/* An opened file takes the whole row. Left in its grid column it would stretch
|
|
6527
|
+
every sibling card to the height of the file and read as a broken layout. */
|
|
6528
|
+
details.viewer[open]{grid-column:1/-1}
|
|
6529
|
+
details.viewer>summary{cursor:pointer;list-style:none;padding:15px 16px;display:flex;flex-direction:column;
|
|
6530
|
+
gap:6px;border-radius:10px}
|
|
6531
|
+
details.viewer>summary::-webkit-details-marker{display:none}
|
|
6532
|
+
/* Closed, the action row sits at the card's bottom so the grid's cards line up.
|
|
6533
|
+
Open, that same auto margin would leave a band of empty space above the file. */
|
|
6534
|
+
details.viewer .acts2{margin-top:auto;display:flex;align-items:baseline;gap:12px}
|
|
6535
|
+
details.viewer[open]>summary .acts2{margin-top:0}
|
|
6536
|
+
details.viewer .open,details.viewer .shut{font-size:.83rem;border-bottom:1px solid var(--line);padding-bottom:1px}
|
|
6537
|
+
details.viewer>summary:hover .open,details.viewer>summary:hover .shut{border-color:var(--accent)}
|
|
6538
|
+
details.viewer .shut{display:none}
|
|
6539
|
+
details.viewer[open]>summary .open{display:none}
|
|
6540
|
+
details.viewer[open]>summary .shut{display:inline}
|
|
6541
|
+
details.viewer .raw{font-size:.74rem;color:var(--ink2);margin-top:0;align-self:baseline}
|
|
6542
|
+
details.viewer>.note{margin:0 16px 8px}
|
|
6543
|
+
/* Scrollable and selectable: the point is to read and copy from it in place. */
|
|
6544
|
+
.filebody{margin:0;padding:12px 16px;max-height:60vh;overflow:auto;white-space:pre-wrap;word-break:break-word;
|
|
6545
|
+
font-family:var(--mono);font-size:.76rem;line-height:1.55;border-top:1px solid var(--line);
|
|
6546
|
+
background:color-mix(in srgb,var(--ink) 3%,transparent);border-radius:0 0 10px 10px}
|
|
6406
6547
|
.cta{background:var(--panel);border:1px solid var(--line);border-left:3px solid var(--good);
|
|
6407
6548
|
border-radius:10px;padding:18px 20px}
|
|
6408
6549
|
code.cmd{display:block;font-family:var(--mono);font-size:.86rem;background:color-mix(in srgb,var(--ink) 6%,transparent);
|
|
@@ -6685,12 +6826,24 @@ var PLAYBOOK_NAME = "PLAYBOOK.md";
|
|
|
6685
6826
|
var SETTINGS_NAME = "settings.suggested.json";
|
|
6686
6827
|
var HARNESS_NAME = "HARNESS-UPGRADE.md";
|
|
6687
6828
|
var INCLUDE_NAME = "costclaw.md";
|
|
6829
|
+
var VIEWER_MAX_LINES = 600;
|
|
6830
|
+
function renderFileCard(name, desc, text2) {
|
|
6831
|
+
const head = `<span class="nm">${esc(name)}</span><span class="ds">${esc(desc)}</span>`;
|
|
6832
|
+
if (text2 === void 0) {
|
|
6833
|
+
return `<div class="file">${head}<a href="${esc(name)}">Open file</a></div>`;
|
|
6834
|
+
}
|
|
6835
|
+
const lines = text2.replace(/\s*$/, "").split("\n");
|
|
6836
|
+
const clipped = lines.length > VIEWER_MAX_LINES;
|
|
6837
|
+
const shown = clipped ? lines.slice(0, VIEWER_MAX_LINES) : lines;
|
|
6838
|
+
const note = clipped ? `<p class="note">Showing the first ${num5(VIEWER_MAX_LINES)} of ${num5(lines.length)} lines. Open the raw file for the rest.</p>` : "";
|
|
6839
|
+
return `<details class="file viewer"><summary>${head}<span class="acts2"><span class="open">Open</span><span class="shut">Close</span><a href="${esc(name)}" class="raw">raw</a></span></summary>` + note + `<pre class="filebody">${esc(shown.join("\n"))}</pre></details>`;
|
|
6840
|
+
}
|
|
6688
6841
|
function renderArtifactCards(input) {
|
|
6689
6842
|
const { before, after } = input.claudeMdTokens;
|
|
6690
6843
|
const lighter = before !== null && after < before ? ` and ${fmtTokens(before - after)} tokens lighter` : "";
|
|
6691
6844
|
const placeholders = `${input.placeholdersRemaining} ${plural2(input.placeholdersRemaining, "placeholder")} to fill.`;
|
|
6692
6845
|
const claudeDesc = before === null ? `A new CLAUDE.md scaffold for your project. ${placeholders}` : `Your CLAUDE.md, restructured${lighter}. ${placeholders}`;
|
|
6693
|
-
const card = (name, desc) =>
|
|
6846
|
+
const card = (name, desc) => renderFileCard(name, desc, input.artifactText?.[name]);
|
|
6694
6847
|
return `<div class="files">` + card(OPTIMIZED_NAME, claudeDesc) + card(PLAYBOOK_NAME, "The ranked plan above, as a file you can keep or paste into an issue.") + card(SETTINGS_NAME, "A conservative permission allowlist derived from what you already run. Never applied unless you ask.") + card(HARNESS_NAME, "A work order for your own Claude Code. It merges the CLAUDE.md and applies what you approve.") + card(
|
|
6695
6848
|
INCLUDE_NAME,
|
|
6696
6849
|
"The generated sections as a standalone include. apply writes it to .claude/costclaw.md and adds one @ line to your CLAUDE.md."
|
|
@@ -6912,7 +7065,74 @@ td code.cmd{margin-top:0;font-size:.78rem;white-space:pre-wrap;word-break:break-
|
|
|
6912
7065
|
.state{font-size:.82rem}
|
|
6913
7066
|
.state.on{color:var(--good);font-weight:650}
|
|
6914
7067
|
.state.off{color:var(--ink2)}
|
|
7068
|
+
|
|
7069
|
+
/* What changed: one always-open block per project, each holding real diffs.
|
|
7070
|
+
The project name is a link to that project's report, not a toggle. */
|
|
7071
|
+
.chg{border:1px solid var(--line);border-radius:10px;margin:0 0 10px;background:var(--panel)}
|
|
7072
|
+
.chghead{padding:10px 14px;display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}
|
|
7073
|
+
.chgname{font-weight:650;font-size:.95rem;color:var(--ink);text-decoration:none}
|
|
7074
|
+
a.chgname{border-bottom:1px solid var(--line);padding-bottom:1px}
|
|
7075
|
+
a.chgname:hover{border-color:var(--accent);color:var(--accent)}
|
|
7076
|
+
.chg>ul{margin:0;padding:0 18px 10px 32px;font-size:.88rem}
|
|
7077
|
+
.chgstat{font-size:.78rem;color:var(--ink2);font-family:var(--mono)}
|
|
7078
|
+
.plus{color:var(--good);font-weight:650}
|
|
7079
|
+
.minus{color:var(--bad);font-weight:650}
|
|
7080
|
+
details.filediff{margin:0 14px 14px;border:1px solid var(--line);border-radius:9px;overflow:hidden}
|
|
7081
|
+
.fhead{display:flex;align-items:center;gap:10px;flex-wrap:wrap;padding:8px 12px;cursor:pointer;
|
|
7082
|
+
list-style:none;background:color-mix(in srgb,var(--ink) 4%,transparent)}
|
|
7083
|
+
.fhead::-webkit-details-marker{display:none}
|
|
7084
|
+
.fhead::before{content:"\\25B8";color:var(--ink2);font-size:.8rem;display:inline-block;
|
|
7085
|
+
transition:transform .12s ease}
|
|
7086
|
+
details.filediff[open] .fhead{border-bottom:1px solid var(--line)}
|
|
7087
|
+
details.filediff[open] .fhead::before{transform:rotate(90deg)}
|
|
7088
|
+
.fhead:hover code{color:var(--accent)}
|
|
7089
|
+
.fhead code{font-size:.82rem}
|
|
7090
|
+
.tag{font-size:.7rem;text-transform:uppercase;letter-spacing:.04em;padding:2px 7px;border-radius:999px;
|
|
7091
|
+
border:1px solid var(--line);color:var(--ink2)}
|
|
7092
|
+
.tag.created{color:var(--good);border-color:color-mix(in srgb,var(--good) 45%,var(--line))}
|
|
7093
|
+
.tag.removed{color:var(--bad);border-color:color-mix(in srgb,var(--bad) 45%,var(--line))}
|
|
7094
|
+
table.sbs{width:100%;border-collapse:collapse;table-layout:fixed;font-family:var(--mono);font-size:.76rem}
|
|
7095
|
+
table.sbs th{text-align:left;font-family:var(--sans);font-size:.72rem;color:var(--ink2);font-weight:600;
|
|
7096
|
+
padding:6px 10px;border-bottom:1px solid var(--line)}
|
|
7097
|
+
table.sbs td{padding:1px 8px;vertical-align:top;white-space:pre-wrap;word-break:break-word;
|
|
7098
|
+
border-bottom:1px solid color-mix(in srgb,var(--line) 40%,transparent)}
|
|
7099
|
+
table.sbs col.cn{width:46px}
|
|
7100
|
+
table.sbs col.cs{width:auto}
|
|
7101
|
+
table.sbs td.ln{text-align:right;color:var(--ink2);user-select:none;opacity:.7}
|
|
7102
|
+
table.sbs tr.add td.r{background:color-mix(in srgb,var(--good) 16%,transparent)}
|
|
7103
|
+
table.sbs tr.remove td.l{background:color-mix(in srgb,var(--bad) 16%,transparent)}
|
|
7104
|
+
table.sbs tr.gap td{text-align:center;color:var(--ink2);letter-spacing:.3em;padding:3px 0;opacity:.6}
|
|
6915
7105
|
`;
|
|
7106
|
+
function renderProjectChange(c) {
|
|
7107
|
+
const cut = c.lines.findIndex((l) => /^Diff \(/.test(l.trim()));
|
|
7108
|
+
const summary = (cut < 0 ? c.lines : c.lines.slice(0, cut)).filter((l) => l.trim().length > 0);
|
|
7109
|
+
const files = c.files ?? [];
|
|
7110
|
+
const totals = files.map((f) => alignLines(f.before, f.after));
|
|
7111
|
+
const added = totals.reduce((s, t) => s + t.added, 0);
|
|
7112
|
+
const removed = totals.reduce((s, t) => s + t.removed, 0);
|
|
7113
|
+
const name = c.href ? `<a class="chgname" href="${esc(c.href)}" target="_blank" rel="noopener">${esc(c.slug)}</a>` : `<b class="chgname">${esc(c.slug)}</b>`;
|
|
7114
|
+
const head = `<div class="chghead">${name}` + (files.length > 0 ? `<span class="chgstat">${files.length} ${plural2(files.length, "file")} <span class="plus">+${added}</span> <span class="minus">-${removed}</span></span>` : `<span class="chgstat">no file changed</span>`) + (c.href ? `<span class="chgstat">open the full report</span>` : "") + `</div>`;
|
|
7115
|
+
return `<div class="chg">${head}<ul>${summary.map((l) => `<li>${esc(l)}</li>`).join("")}</ul>` + files.map((f, i) => renderFileDiff(f, totals[i])).join("") + `</div>`;
|
|
7116
|
+
}
|
|
7117
|
+
function renderFileDiff(file, align) {
|
|
7118
|
+
const state = file.before === null ? "created" : file.after === null ? "removed" : "changed";
|
|
7119
|
+
const rows = collapseUnchanged(align.rows).map((r) => {
|
|
7120
|
+
if (r === null) {
|
|
7121
|
+
return `<tr class="gap"><td colspan="4">· · ·</td></tr>`;
|
|
7122
|
+
}
|
|
7123
|
+
const cls = r.kind === "same" ? "" : ` class="${r.kind}"`;
|
|
7124
|
+
return `<tr${cls}><td class="ln">${r.leftNo ?? ""}</td><td class="side l">${r.left === null ? "" : esc(r.left)}</td><td class="ln">${r.rightNo ?? ""}</td><td class="side r">${r.right === null ? "" : esc(r.right)}</td></tr>`;
|
|
7125
|
+
}).join("");
|
|
7126
|
+
return (
|
|
7127
|
+
// Collapsed by default: the project block above is always open, so ten
|
|
7128
|
+
// projects' worth of open diffs would bury the summary lines.
|
|
7129
|
+
`<details class="filediff"><summary class="fhead"><code>${esc(file.label)}</code><span class="tag ${state}">${state}</span><span class="chgstat"><span class="plus">+${align.added}</span> <span class="minus">-${align.removed}</span></span></summary>` + (align.truncated ? `<p class="note">This file is too large to pair line by line, so the two sides are listed in full instead.</p>` : "") + // table-layout:fixed takes its widths from the first row, and the first row
|
|
7130
|
+
// is the header, whose cells are colspan'd across the two number columns.
|
|
7131
|
+
// Without an explicit colgroup the browser splits four equal columns and the
|
|
7132
|
+
// gutters eat half the width.
|
|
7133
|
+
`<table class="sbs"><colgroup><col class="cn"><col class="cs"><col class="cn"><col class="cs"></colgroup><thead><tr><th colspan="2">Before</th><th colspan="2">After</th></tr></thead><tbody>${rows}</tbody></table><p class="note">${esc(file.path)}</p></details>`
|
|
7134
|
+
);
|
|
7135
|
+
}
|
|
6916
7136
|
function indexTokens(tokens) {
|
|
6917
7137
|
if (tokens.before === null) return `${esc(approxTokens(tokens.after))} (new file)`;
|
|
6918
7138
|
return `${esc(approxTokens(tokens.before))} to ${esc(approxTokens(tokens.after))}`;
|
|
@@ -6968,9 +7188,7 @@ function renderOptimizeIndex(input) {
|
|
|
6968
7188
|
// a run, and this card carries it when a previous session left files behind.
|
|
6969
7189
|
(applied > 0 && !priorRun ? `<button type="submit" name="action" value="revert-all">Revert everything</button>` : "") + `</div><label class="opt"><input type="checkbox" name="settings" value="1" checked> also merge the suggested permission allowlist (backs up your settings first)</label><p class="note">Uncheck any project in the table below to leave it out.</p></div>` : "";
|
|
6970
7190
|
const run = priorRun;
|
|
6971
|
-
const
|
|
6972
|
-
(c) => `<div class="chg"><b>${esc(c.slug)}</b><ul>` + c.lines.map((l) => `<li>${esc(l)}</li>`).join("") + `</ul></div>`
|
|
6973
|
-
).join("") + (run.reverted ? `<p class="note">Everything costclaw added has been removed.</p>` : `<div class="acts" style="margin-top:12px"><button type="submit" name="action" value="revert-all" class="go">Revert everything</button></div><p class="note">Reverts every project checked in the table below.</p>`) + `</div>` : "";
|
|
7191
|
+
const changed2 = run ? `<h2>What changed<span class="n">${run.reverted ? "reverted" : "written just now"}</span></h2><div class="panel changed">` + run.changes.map((c) => renderProjectChange(c)).join("") + (run.reverted ? `<p class="note">Everything costclaw added has been removed.</p>` : `<div class="acts" style="margin-top:12px"><button type="submit" name="action" value="revert-all" class="go">Revert everything</button></div><p class="note">Reverts every project checked in the table below.</p>`) + `</div>` : "";
|
|
6974
7192
|
const banner = input.serve?.message ? `<p class="banner">${esc(input.serve.message)}</p>` : "";
|
|
6975
7193
|
const done = input.serve ? `<div class="acts" style="margin:0 0 22px"><form method="post" action="/done"><input type="hidden" name="token" value="${esc(input.serve.token)}"><button type="submit">Done</button></form></div>` : "";
|
|
6976
7194
|
const how = input.serve ? `<p class="note">Apply writes <code>.claude/costclaw.md</code> and adds one <code>@.claude/costclaw.md</code> line to that project's CLAUDE.md. Every line you wrote stays where it is. Remove undoes both.</p>` : `<p class="note">Run the line on a project's row to apply it. It writes <code>.claude/costclaw.md</code> and adds one <code>@.claude/costclaw.md</code> line to that project's CLAUDE.md; every line you wrote stays where it is. Undo with <code>--remove</code>.</p>`;
|
|
@@ -6993,7 +7211,7 @@ artifacts in ${esc(input.root)}/</p></header>
|
|
|
6993
7211
|
${banner}${done}
|
|
6994
7212
|
${serve ? `<form method="post" action="/apply">
|
|
6995
7213
|
<input type="hidden" name="token" value="${esc(serve.token)}">` : ""}
|
|
6996
|
-
${
|
|
7214
|
+
${changed2}
|
|
6997
7215
|
${oneButton}
|
|
6998
7216
|
${input.review ? `<h2>${serve ? "Or hand it to your own Claude" : "Start here"}<span class="n">${serve ? "it knows your project" : "two ways to do this, pick one"}</span></h2>
|
|
6999
7217
|
${renderStartHere(input.review, input.rows.length)}` : ""}
|
|
@@ -7018,7 +7236,7 @@ Nothing was written inside any project. No network calls, no telemetry, no model
|
|
|
7018
7236
|
|
|
7019
7237
|
// src/project-scan.ts
|
|
7020
7238
|
import { readdir as readdir3, readFile as readFile7, stat as stat2 } from "fs/promises";
|
|
7021
|
-
import { join as join8, basename as
|
|
7239
|
+
import { join as join8, basename as basename3 } from "path";
|
|
7022
7240
|
var NOISE_DIRS = /* @__PURE__ */ new Set([
|
|
7023
7241
|
"node_modules",
|
|
7024
7242
|
".git",
|
|
@@ -7492,7 +7710,7 @@ function parseReadme(text2) {
|
|
|
7492
7710
|
return { name, description };
|
|
7493
7711
|
}
|
|
7494
7712
|
async function scanProject(dir) {
|
|
7495
|
-
const profile = emptyProfile(
|
|
7713
|
+
const profile = emptyProfile(basename3(dir));
|
|
7496
7714
|
const { files, dirs } = await listEntries(dir);
|
|
7497
7715
|
if (files.includes("package.json")) {
|
|
7498
7716
|
const pkg = parseJson(await readText(join8(dir, "package.json")));
|
|
@@ -7515,13 +7733,13 @@ async function scanProject(dir) {
|
|
|
7515
7733
|
}
|
|
7516
7734
|
}
|
|
7517
7735
|
}
|
|
7518
|
-
if (profile.description === null || profile.name ===
|
|
7736
|
+
if (profile.description === null || profile.name === basename3(dir)) {
|
|
7519
7737
|
const readmeName = files.find((f) => /^readme(\.md|\.markdown|\.txt)?$/i.test(f));
|
|
7520
7738
|
if (readmeName) {
|
|
7521
7739
|
const text2 = await readText(join8(dir, readmeName));
|
|
7522
7740
|
if (text2 !== null) {
|
|
7523
7741
|
const parsed = parseReadme(text2);
|
|
7524
|
-
if (profile.name ===
|
|
7742
|
+
if (profile.name === basename3(dir) && parsed.name !== null) profile.name = parsed.name;
|
|
7525
7743
|
if (profile.description === null && parsed.description !== null) {
|
|
7526
7744
|
profile.description = parsed.description;
|
|
7527
7745
|
}
|
|
@@ -7719,8 +7937,9 @@ async function startApplyServer(opts) {
|
|
|
7719
7937
|
const changes = [];
|
|
7720
7938
|
const errors = [];
|
|
7721
7939
|
for (const { entry, action } of targets) {
|
|
7940
|
+
const href = `${entry.dir}/${DASHBOARD_NAME}`;
|
|
7722
7941
|
try {
|
|
7723
|
-
const lines = await opts.apply(entry, action);
|
|
7942
|
+
const { lines, files } = await opts.apply(entry, action);
|
|
7724
7943
|
if (action === "remove") {
|
|
7725
7944
|
delete entry.appliedAt;
|
|
7726
7945
|
delete entry.appliedMode;
|
|
@@ -7728,11 +7947,11 @@ async function startApplyServer(opts) {
|
|
|
7728
7947
|
entry.appliedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7729
7948
|
entry.appliedMode = action;
|
|
7730
7949
|
}
|
|
7731
|
-
changes.push({ slug: entry.slug, lines });
|
|
7950
|
+
changes.push({ slug: entry.slug, lines, files, href });
|
|
7732
7951
|
} catch (err) {
|
|
7733
7952
|
const text2 = `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
7734
7953
|
errors.push(text2);
|
|
7735
|
-
changes.push({ slug: entry.slug, lines: [text2] });
|
|
7954
|
+
changes.push({ slug: entry.slug, lines: [text2], files: [], href });
|
|
7736
7955
|
}
|
|
7737
7956
|
}
|
|
7738
7957
|
if (opts.onManifestChange) await opts.onManifestChange(manifest);
|
|
@@ -7933,7 +8152,7 @@ function projectRecoverable(report, slug) {
|
|
|
7933
8152
|
return row ? row.usd : null;
|
|
7934
8153
|
}
|
|
7935
8154
|
async function generateForProject(ctx, projectDir, artifactsDir) {
|
|
7936
|
-
const slug =
|
|
8155
|
+
const slug = basename4(resolve6(projectDir));
|
|
7937
8156
|
let currentClaudeMd = ctx.claudeMdOverride;
|
|
7938
8157
|
let claudeMdSource = ctx.claudeMdOverride !== void 0 ? ctx.claudeMdFallbackSource : null;
|
|
7939
8158
|
if (currentClaudeMd === void 0) {
|
|
@@ -7993,7 +8212,16 @@ async function generateForProject(ctx, projectDir, artifactsDir) {
|
|
|
7993
8212
|
headlineWasteShare: auditSpend > 0 ? auditRecoverable2 / auditSpend : 0,
|
|
7994
8213
|
headlineWasteUsd: auditRecoverable2,
|
|
7995
8214
|
applyCommand,
|
|
7996
|
-
review
|
|
8215
|
+
review,
|
|
8216
|
+
// The generated text itself, so each file card opens in place instead of
|
|
8217
|
+
// navigating the reader away to the browser's raw-markdown rendering.
|
|
8218
|
+
artifactText: {
|
|
8219
|
+
[OPTIMIZED_NAME2]: result.optimizedClaudeMd,
|
|
8220
|
+
[PLAYBOOK_NAME2]: result.playbook,
|
|
8221
|
+
[SETTINGS_NAME2]: result.settingsJson,
|
|
8222
|
+
[HARNESS_NAME2]: result.harnessPrompt,
|
|
8223
|
+
[INCLUDE_NAME2]: result.includeMd
|
|
8224
|
+
}
|
|
7997
8225
|
});
|
|
7998
8226
|
await writeFile6(join10(artifactsDir, DASHBOARD_NAME2), html, "utf8");
|
|
7999
8227
|
}
|
|
@@ -8050,7 +8278,7 @@ async function generateForProject(ctx, projectDir, artifactsDir) {
|
|
|
8050
8278
|
return {
|
|
8051
8279
|
entry: {
|
|
8052
8280
|
slug,
|
|
8053
|
-
dir:
|
|
8281
|
+
dir: basename4(artifactsDir),
|
|
8054
8282
|
projectDir,
|
|
8055
8283
|
artifactsDir,
|
|
8056
8284
|
spendUsd: spend ?? 0,
|
|
@@ -8310,7 +8538,7 @@ async function runOptimize(opts) {
|
|
|
8310
8538
|
artifactsDir: entry.artifactsDir,
|
|
8311
8539
|
applySettings: action === "settings"
|
|
8312
8540
|
});
|
|
8313
|
-
return outcome.lines;
|
|
8541
|
+
return { lines: outcome.lines, files: outcome.files };
|
|
8314
8542
|
},
|
|
8315
8543
|
onManifestChange: (m) => writeManifest(manifestRoot, m)
|
|
8316
8544
|
});
|
|
@@ -8430,7 +8658,7 @@ function formatDiff(d) {
|
|
|
8430
8658
|
`Plan: ${d.current.plan}. Dollar figures are estimated current API-equivalent valuations, not money back, actual quota, or a promise of more work.`
|
|
8431
8659
|
);
|
|
8432
8660
|
}
|
|
8433
|
-
const { resolved, appeared, changed } = d.fixes;
|
|
8661
|
+
const { resolved, appeared, changed: changed2 } = d.fixes;
|
|
8434
8662
|
if (resolved.length > 0) {
|
|
8435
8663
|
lines.push("");
|
|
8436
8664
|
lines.push("Fixes resolved since the baseline:");
|
|
@@ -8441,10 +8669,10 @@ function formatDiff(d) {
|
|
|
8441
8669
|
lines.push("New since the baseline:");
|
|
8442
8670
|
for (const f of appeared) lines.push(` - [${usd7(f.wasteUsd)} estimated valuation] ${f.title}`);
|
|
8443
8671
|
}
|
|
8444
|
-
if (
|
|
8672
|
+
if (changed2.length > 0) {
|
|
8445
8673
|
lines.push("");
|
|
8446
8674
|
lines.push("Fixes that moved:");
|
|
8447
|
-
for (const c of
|
|
8675
|
+
for (const c of changed2) {
|
|
8448
8676
|
lines.push(` - ${c.title}: ${usd7(c.beforeUsd)} -> ${usd7(c.afterUsd)} (${signedUsd(c.deltaUsd)} estimated valuation)`);
|
|
8449
8677
|
}
|
|
8450
8678
|
}
|
|
@@ -8556,7 +8784,7 @@ function parseApplyFlags(args) {
|
|
|
8556
8784
|
};
|
|
8557
8785
|
}
|
|
8558
8786
|
function cliVersion() {
|
|
8559
|
-
return true ? "0.
|
|
8787
|
+
return true ? "0.16.2" : "0.0.0-dev";
|
|
8560
8788
|
}
|
|
8561
8789
|
function isHelpRequest(command, args) {
|
|
8562
8790
|
if (command === void 0) return false;
|