costclaw 0.2.2 → 0.2.3
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 +21 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { pathToFileURL } from "url";
|
|
5
5
|
|
|
6
6
|
// src/audit-command.ts
|
|
7
|
-
import { readFile as readFile2, writeFile } from "fs/promises";
|
|
7
|
+
import { mkdir, readFile as readFile2, writeFile } from "fs/promises";
|
|
8
8
|
import { join as join3, resolve } from "path";
|
|
9
9
|
import { homedir as homedir3 } from "os";
|
|
10
10
|
import { spawn } from "child_process";
|
|
@@ -2093,7 +2093,7 @@ function formatAudit(record, meta) {
|
|
|
2093
2093
|
if (dollarFixes.length === 0) {
|
|
2094
2094
|
lines.push(" No directly recoverable dollars found. See issues below.");
|
|
2095
2095
|
} else {
|
|
2096
|
-
for (const f of dollarFixes
|
|
2096
|
+
for (const f of dollarFixes) {
|
|
2097
2097
|
lines.push(` - [${usd2(f.wasteUsd)}] ${f.title}`);
|
|
2098
2098
|
lines.push(` ${f.action}`);
|
|
2099
2099
|
if (f.basis) lines.push(` Evidence: ${f.basis}`);
|
|
@@ -2102,13 +2102,10 @@ function formatAudit(record, meta) {
|
|
|
2102
2102
|
if (otherIssues.length > 0) {
|
|
2103
2103
|
lines.push("");
|
|
2104
2104
|
lines.push("Other issues to tighten:");
|
|
2105
|
-
for (const f of otherIssues
|
|
2105
|
+
for (const f of otherIssues) {
|
|
2106
2106
|
lines.push(` - ${f.title}`);
|
|
2107
2107
|
if (f.basis) lines.push(` ${f.basis}`);
|
|
2108
2108
|
}
|
|
2109
|
-
if (otherIssues.length > 6) {
|
|
2110
|
-
lines.push(` ... and ${otherIssues.length - 6} more`);
|
|
2111
|
-
}
|
|
2112
2109
|
}
|
|
2113
2110
|
if (meta.skipped.length > 0) {
|
|
2114
2111
|
lines.push("");
|
|
@@ -2429,8 +2426,20 @@ async function runAudit(opts) {
|
|
|
2429
2426
|
});
|
|
2430
2427
|
const setup = await readSetup();
|
|
2431
2428
|
const record = buildAudit({ logs, claudeMd, questionnaire: {}, setup });
|
|
2429
|
+
let snapshotNotice = null;
|
|
2430
|
+
try {
|
|
2431
|
+
const historyDir = join3(opts.home ?? homedir3(), ".costclaw", "history");
|
|
2432
|
+
await mkdir(historyDir, { recursive: true });
|
|
2433
|
+
const name = record.createdAt.replace(/[:.]/g, "-") + ".json";
|
|
2434
|
+
await writeFile(join3(historyDir, name), JSON.stringify(record, null, 2), "utf8");
|
|
2435
|
+
snapshotNotice = "Snapshot saved for costclaw diff.";
|
|
2436
|
+
} catch (err) {
|
|
2437
|
+
process.stderr.write(`Could not save the audit snapshot: ${err instanceof Error ? err.message : String(err)}
|
|
2438
|
+
`);
|
|
2439
|
+
}
|
|
2432
2440
|
let output = opts.json ? JSON.stringify(record, null, 2) : formatAudit(record, { root, sessionCount: logs.length, skipped, claudeMdSource });
|
|
2433
2441
|
const notices = [];
|
|
2442
|
+
if (snapshotNotice) notices.push(snapshotNotice);
|
|
2434
2443
|
if (opts.html) {
|
|
2435
2444
|
const target = resolve(opts.htmlPath || DEFAULT_HTML_FILE);
|
|
2436
2445
|
const doc = renderHtml(record, { root, sessionCount: logs.length, skipped, claudeMdSource });
|
|
@@ -2453,7 +2462,7 @@ async function runAudit(opts) {
|
|
|
2453
2462
|
}
|
|
2454
2463
|
|
|
2455
2464
|
// src/optimize-command.ts
|
|
2456
|
-
import { mkdir, writeFile as writeFile2, readFile as readFile4, stat as stat2 } from "fs/promises";
|
|
2465
|
+
import { mkdir as mkdir2, writeFile as writeFile2, readFile as readFile4, stat as stat2 } from "fs/promises";
|
|
2457
2466
|
import { join as join5, dirname } from "path";
|
|
2458
2467
|
|
|
2459
2468
|
// src/project-scan.ts
|
|
@@ -3058,7 +3067,7 @@ async function applyDerivedSettings(target, suggestedJson, force) {
|
|
|
3058
3067
|
mergedPerms.deny = unionStrings(asStringArray(existingPerms.deny), suggestedDeny);
|
|
3059
3068
|
const merged = { ...existing, permissions: mergedPerms };
|
|
3060
3069
|
const mergedText = JSON.stringify(merged, null, 2) + "\n";
|
|
3061
|
-
await
|
|
3070
|
+
await mkdir2(dirname(target), { recursive: true });
|
|
3062
3071
|
await writeFile2(backup, existingText, "utf8");
|
|
3063
3072
|
await writeFile2(target, mergedText, "utf8");
|
|
3064
3073
|
return [
|
|
@@ -3081,7 +3090,7 @@ async function runOptimize(opts) {
|
|
|
3081
3090
|
const result = optimize({ report, scores: pillars, fixes, currentClaudeMd: claudeMd, project });
|
|
3082
3091
|
const recoverable = cacheMissExposureUsd(report);
|
|
3083
3092
|
const outDir = opts.out || join5(process.cwd(), "costclaw-out");
|
|
3084
|
-
await
|
|
3093
|
+
await mkdir2(outDir, { recursive: true });
|
|
3085
3094
|
const playbookPath = join5(outDir, PLAYBOOK_NAME);
|
|
3086
3095
|
await writeFile2(playbookPath, result.playbook, "utf8");
|
|
3087
3096
|
const settingsPath = join5(outDir, SETTINGS_NAME);
|
|
@@ -3178,7 +3187,7 @@ async function runBadge(opts) {
|
|
|
3178
3187
|
}
|
|
3179
3188
|
|
|
3180
3189
|
// src/license.ts
|
|
3181
|
-
import { mkdir as
|
|
3190
|
+
import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile4, rm } from "fs/promises";
|
|
3182
3191
|
import { join as join6 } from "path";
|
|
3183
3192
|
import { homedir as homedir4, hostname } from "os";
|
|
3184
3193
|
import { createPublicKey, verify as cryptoVerify } from "crypto";
|
|
@@ -3240,7 +3249,7 @@ async function readStoredLicense(dir) {
|
|
|
3240
3249
|
}
|
|
3241
3250
|
}
|
|
3242
3251
|
async function writeStoredLicense(dir, lic) {
|
|
3243
|
-
await
|
|
3252
|
+
await mkdir3(dir, { recursive: true });
|
|
3244
3253
|
await writeFile4(licenseFile(dir), JSON.stringify(lic, null, 2) + "\n", "utf8");
|
|
3245
3254
|
}
|
|
3246
3255
|
async function clearStoredLicense(dir) {
|
|
@@ -3320,7 +3329,7 @@ function parseBadgeFlags(args) {
|
|
|
3320
3329
|
};
|
|
3321
3330
|
}
|
|
3322
3331
|
function cliVersion() {
|
|
3323
|
-
return true ? "0.2.
|
|
3332
|
+
return true ? "0.2.3" : "0.0.0-dev";
|
|
3324
3333
|
}
|
|
3325
3334
|
function helpText() {
|
|
3326
3335
|
return [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "costclaw",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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": {
|