@rafter-security/cli 0.7.7 → 0.8.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 +27 -681
- package/dist/commands/agent/baseline.js +15 -15
- package/dist/commands/agent/components.js +282 -138
- package/dist/commands/agent/index.js +2 -2
- package/dist/commands/agent/init.js +564 -174
- package/dist/commands/agent/scan.js +76 -47
- package/dist/commands/agent/status.js +19 -10
- package/dist/commands/agent/update-betterleaks.js +39 -0
- package/dist/commands/agent/verify.js +230 -29
- package/dist/commands/brief.js +13 -45
- package/dist/commands/completion.js +15 -15
- package/dist/commands/issues/from-scan.js +6 -3
- package/dist/commands/mcp/server.js +11 -11
- package/dist/core/config-manager.js +6 -0
- package/dist/core/custom-patterns.js +86 -4
- package/dist/core/policy-loader.js +60 -1
- package/dist/scanners/{gitleaks.js → betterleaks.js} +49 -61
- package/dist/scanners/regex-scanner.js +4 -5
- package/dist/scanners/secret-patterns.js +1 -1
- package/dist/utils/binary-manager.js +205 -109
- package/dist/utils/skill-manager.js +96 -16
- package/package.json +1 -1
- package/resources/agents/rafter.md +81 -0
- package/resources/continue-rules/rafter-code-review.md +15 -0
- package/resources/continue-rules/rafter-secure-design.md +15 -0
- package/resources/continue-rules/rafter-skill-review.md +15 -0
- package/resources/continue-rules/rafter.md +16 -0
- package/resources/cursor-rules/rafter-code-review.mdc +14 -0
- package/resources/cursor-rules/rafter-secure-design.mdc +14 -0
- package/resources/cursor-rules/rafter-skill-review.mdc +14 -0
- package/resources/cursor-rules/rafter.mdc +15 -0
- package/resources/rafter-security-skill.md +18 -10
- package/resources/skills/rafter/SKILL.md +1 -1
- package/resources/skills/rafter/docs/cli-reference.md +5 -5
- package/resources/windsurf-rules/rafter-code-review.md +14 -0
- package/resources/windsurf-rules/rafter-secure-design.md +14 -0
- package/resources/windsurf-rules/rafter-skill-review.md +14 -0
- package/resources/windsurf-rules/rafter.md +15 -0
- package/dist/commands/agent/update-gitleaks.js +0 -40
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Command } from "commander";
|
|
2
2
|
import { RegexScanner } from "../../scanners/regex-scanner.js";
|
|
3
|
-
import {
|
|
3
|
+
import { BetterleaksScanner } from "../../scanners/betterleaks.js";
|
|
4
4
|
import { ConfigManager } from "../../core/config-manager.js";
|
|
5
5
|
import { AuditLogger } from "../../core/audit-logger.js";
|
|
6
|
+
import { applySuppressions, loadSuppressions, policyIgnoreToSuppressions, } from "../../core/custom-patterns.js";
|
|
6
7
|
import { execFileSync } from "child_process";
|
|
7
8
|
import fs from "fs";
|
|
8
9
|
import os from "os";
|
|
@@ -44,13 +45,13 @@ export function createScanCommand() {
|
|
|
44
45
|
.option("--format <format>", "Output format: text, json, sarif", "text")
|
|
45
46
|
.option("--staged", "Scan only git staged files")
|
|
46
47
|
.option("--diff <ref>", "Scan files changed since a git ref")
|
|
47
|
-
.option("--engine <engine>", "Scan engine:
|
|
48
|
+
.option("--engine <engine>", "Scan engine: betterleaks or patterns", "auto")
|
|
48
49
|
.option("--baseline", "Filter findings present in the saved baseline")
|
|
49
50
|
.option("--watch", "Watch for file changes and re-scan on change")
|
|
50
|
-
.option("--history", "Scan git history for secrets (requires
|
|
51
|
+
.option("--history", "Scan git history for secrets (requires betterleaks engine)")
|
|
51
52
|
.action(async (scanPath, opts) => {
|
|
52
|
-
// Validate flags before doing any work
|
|
53
|
-
const validEngines = ["auto", "
|
|
53
|
+
// Validate flags before doing any work.
|
|
54
|
+
const validEngines = ["auto", "betterleaks", "patterns"];
|
|
54
55
|
const engineValue = opts.engine || "auto";
|
|
55
56
|
if (!validEngines.includes(engineValue)) {
|
|
56
57
|
console.error(`Invalid engine: ${engineValue}. Valid values: ${validEngines.join(", ")}`);
|
|
@@ -69,19 +70,20 @@ export function createScanCommand() {
|
|
|
69
70
|
if (isAgentScan) {
|
|
70
71
|
process.stderr.write("Warning: rafter agent scan is deprecated and will be removed in a future major version. Use rafter secrets instead.\n");
|
|
71
72
|
}
|
|
72
|
-
// Load policy-merged config for excludePaths/customPatterns
|
|
73
|
+
// Load policy-merged config for excludePaths/customPatterns/ignore
|
|
73
74
|
const manager = new ConfigManager();
|
|
74
75
|
const cfg = manager.loadWithPolicy();
|
|
75
76
|
const scanCfg = cfg.agent?.scan;
|
|
77
|
+
const suppressions = collectSuppressions(scanCfg?.ignore);
|
|
76
78
|
const baselineEntries = opts.baseline ? loadBaselineEntries() : [];
|
|
77
79
|
// Handle --diff flag
|
|
78
80
|
if (opts.diff) {
|
|
79
|
-
await scanDiffFiles(opts.diff, opts, scanCfg, baselineEntries, path.resolve(scanPath));
|
|
81
|
+
await scanDiffFiles(opts.diff, opts, scanCfg, baselineEntries, path.resolve(scanPath), suppressions);
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
84
|
// Handle --staged flag
|
|
83
85
|
if (opts.staged) {
|
|
84
|
-
await scanStagedFiles(opts, scanCfg, baselineEntries, path.resolve(scanPath));
|
|
86
|
+
await scanStagedFiles(opts, scanCfg, baselineEntries, path.resolve(scanPath), suppressions);
|
|
85
87
|
return;
|
|
86
88
|
}
|
|
87
89
|
const resolvedPath = path.resolve(scanPath);
|
|
@@ -92,7 +94,7 @@ export function createScanCommand() {
|
|
|
92
94
|
}
|
|
93
95
|
// Handle --watch flag
|
|
94
96
|
if (opts.watch) {
|
|
95
|
-
await watchAndScan(resolvedPath, opts, scanCfg);
|
|
97
|
+
await watchAndScan(resolvedPath, opts, scanCfg, suppressions);
|
|
96
98
|
return;
|
|
97
99
|
}
|
|
98
100
|
// Determine scan engine
|
|
@@ -112,7 +114,7 @@ export function createScanCommand() {
|
|
|
112
114
|
}
|
|
113
115
|
results = await scanFile(resolvedPath, engine, scanCfg);
|
|
114
116
|
}
|
|
115
|
-
outputScanResults(applyBaseline(results, baselineEntries), opts);
|
|
117
|
+
outputScanResults(applyBaseline(results, baselineEntries), opts, undefined, true, suppressions);
|
|
116
118
|
});
|
|
117
119
|
}
|
|
118
120
|
/**
|
|
@@ -123,9 +125,17 @@ export function createScanCommand() {
|
|
|
123
125
|
export function createSecretsCommand() {
|
|
124
126
|
const cmd = createScanCommand();
|
|
125
127
|
cmd.name("secrets");
|
|
126
|
-
cmd.description("Scan files/directories for hardcoded secrets (regex +
|
|
128
|
+
cmd.description("Scan files/directories for hardcoded secrets (regex + betterleaks). Secrets only — not a code analysis. For full SAST/SCA, use 'rafter run'.");
|
|
127
129
|
return cmd;
|
|
128
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Combine .rafterignore + policy ignore rules into a single Suppression list.
|
|
133
|
+
* Order matters — first match wins, and policy rules are checked first so an
|
|
134
|
+
* explicit reason wins over a bare .rafterignore line covering the same finding.
|
|
135
|
+
*/
|
|
136
|
+
function collectSuppressions(policyIgnore) {
|
|
137
|
+
return [...policyIgnoreToSuppressions(policyIgnore), ...loadSuppressions()];
|
|
138
|
+
}
|
|
129
139
|
/**
|
|
130
140
|
* Emit SARIF 2.1.0 JSON for GitHub/GitLab security tab integration
|
|
131
141
|
*/
|
|
@@ -180,18 +190,21 @@ function outputSarif(results) {
|
|
|
180
190
|
/**
|
|
181
191
|
* Shared output logic for scan results
|
|
182
192
|
*/
|
|
183
|
-
function outputScanResults(results, opts, context, exitOnFindings = true) {
|
|
193
|
+
function outputScanResults(results, opts, context, exitOnFindings = true, suppressions = []) {
|
|
184
194
|
const format = opts.format ?? (opts.json ? "json" : "text");
|
|
185
195
|
if (!["text", "json", "sarif"].includes(format)) {
|
|
186
196
|
console.error(`Invalid format: ${format}. Valid values: text, json, sarif`);
|
|
187
197
|
process.exit(2);
|
|
188
198
|
}
|
|
199
|
+
// Split suppressed findings off the main result list. Both engines feed
|
|
200
|
+
// through here, so policy-driven suppression applies regardless of source.
|
|
201
|
+
const { results: keptResults, suppressed } = applySuppressions(results, suppressions);
|
|
189
202
|
if (format === "sarif") {
|
|
190
|
-
outputSarif(
|
|
203
|
+
outputSarif(keptResults);
|
|
191
204
|
return;
|
|
192
205
|
}
|
|
193
206
|
if (format === "json" || opts.json) {
|
|
194
|
-
const
|
|
207
|
+
const filesOut = keptResults.map((r) => ({
|
|
195
208
|
file: r.file,
|
|
196
209
|
matches: r.matches.map((m) => ({
|
|
197
210
|
pattern: { name: m.pattern.name, severity: m.pattern.severity, description: m.pattern.description || "" },
|
|
@@ -200,12 +213,28 @@ function outputScanResults(results, opts, context, exitOnFindings = true) {
|
|
|
200
213
|
redacted: m.redacted || "",
|
|
201
214
|
})),
|
|
202
215
|
}));
|
|
216
|
+
const out = {
|
|
217
|
+
_note: "Local-only scan: pattern-based detection without agentic-intelligence triage. " +
|
|
218
|
+
"Findings have not been evaluated for context (public exposure, key validity, " +
|
|
219
|
+
"deployment environment). Investigate each before acting; do not dismiss. " +
|
|
220
|
+
"Run 'rafter run' for backend agentic analysis.",
|
|
221
|
+
scan_mode: "local",
|
|
222
|
+
triage_applied: false,
|
|
223
|
+
results: filesOut,
|
|
224
|
+
};
|
|
225
|
+
if (suppressed.length > 0) {
|
|
226
|
+
out._suppressed = suppressed;
|
|
227
|
+
}
|
|
203
228
|
console.log(JSON.stringify(out, null, 2));
|
|
204
229
|
if (exitOnFindings)
|
|
205
|
-
process.exit(
|
|
230
|
+
process.exit(keptResults.length > 0 ? 1 : 0);
|
|
206
231
|
return;
|
|
207
232
|
}
|
|
208
|
-
|
|
233
|
+
// Text output — note suppression on stderr so stdout remains parseable.
|
|
234
|
+
if (suppressed.length > 0 && !opts.quiet) {
|
|
235
|
+
console.error(fmt.info(`(${suppressed.length} finding(s) hidden by .rafter.yml)`));
|
|
236
|
+
}
|
|
237
|
+
if (keptResults.length === 0) {
|
|
209
238
|
if (!opts.quiet) {
|
|
210
239
|
const msg = context ? `No secrets detected in ${context}` : "No secrets detected";
|
|
211
240
|
console.log(`\n${fmt.success(msg)}\n`);
|
|
@@ -214,9 +243,9 @@ function outputScanResults(results, opts, context, exitOnFindings = true) {
|
|
|
214
243
|
process.exit(0);
|
|
215
244
|
return;
|
|
216
245
|
}
|
|
217
|
-
console.log(`\n${fmt.warning(`Found secrets in ${
|
|
246
|
+
console.log(`\n${fmt.warning(`Found secrets in ${keptResults.length} file(s):`)}\n`);
|
|
218
247
|
let totalMatches = 0;
|
|
219
|
-
for (const result of
|
|
248
|
+
for (const result of keptResults) {
|
|
220
249
|
console.log(`\n${fmt.info(result.file)}`);
|
|
221
250
|
for (const match of result.matches) {
|
|
222
251
|
totalMatches++;
|
|
@@ -229,7 +258,7 @@ function outputScanResults(results, opts, context, exitOnFindings = true) {
|
|
|
229
258
|
console.log();
|
|
230
259
|
}
|
|
231
260
|
}
|
|
232
|
-
console.log(`\n${fmt.warning(`Total: ${totalMatches} secret(s) detected in ${
|
|
261
|
+
console.log(`\n${fmt.warning(`Total: ${totalMatches} secret(s) detected in ${keptResults.length} file(s)`)}\n`);
|
|
233
262
|
if (context === "staged files") {
|
|
234
263
|
console.log(`${fmt.error("Commit blocked. Remove secrets before committing.")}\n`);
|
|
235
264
|
}
|
|
@@ -242,7 +271,7 @@ function outputScanResults(results, opts, context, exitOnFindings = true) {
|
|
|
242
271
|
/**
|
|
243
272
|
* Scan files changed since a git ref
|
|
244
273
|
*/
|
|
245
|
-
async function scanDiffFiles(ref, opts, scanCfg, baselineEntries = [], scanPath) {
|
|
274
|
+
async function scanDiffFiles(ref, opts, scanCfg, baselineEntries = [], scanPath, suppressions = []) {
|
|
246
275
|
const cwd = scanPath && fs.existsSync(scanPath) && fs.statSync(scanPath).isDirectory() ? scanPath : undefined;
|
|
247
276
|
try {
|
|
248
277
|
const diffOutput = execFileSync("git", ["diff", "--name-only", "--diff-filter=ACM", ref], {
|
|
@@ -251,7 +280,7 @@ async function scanDiffFiles(ref, opts, scanCfg, baselineEntries = [], scanPath)
|
|
|
251
280
|
stdio: ["pipe", "pipe", "ignore"],
|
|
252
281
|
}).trim();
|
|
253
282
|
if (!diffOutput) {
|
|
254
|
-
outputScanResults([], opts, `files changed since ${ref}
|
|
283
|
+
outputScanResults([], opts, `files changed since ${ref}`, true, suppressions);
|
|
255
284
|
return;
|
|
256
285
|
}
|
|
257
286
|
const changedFiles = diffOutput.split("\n").map(f => f.trim()).filter(f => f);
|
|
@@ -275,7 +304,7 @@ async function scanDiffFiles(ref, opts, scanCfg, baselineEntries = [], scanPath)
|
|
|
275
304
|
const results = await scanFile(filePath, engine, scanCfg);
|
|
276
305
|
allResults.push(...results);
|
|
277
306
|
}
|
|
278
|
-
outputScanResults(applyBaseline(allResults, baselineEntries), opts, `files changed since ${ref}
|
|
307
|
+
outputScanResults(applyBaseline(allResults, baselineEntries), opts, `files changed since ${ref}`, true, suppressions);
|
|
279
308
|
}
|
|
280
309
|
catch (error) {
|
|
281
310
|
if (error.status === 128) {
|
|
@@ -288,7 +317,7 @@ async function scanDiffFiles(ref, opts, scanCfg, baselineEntries = [], scanPath)
|
|
|
288
317
|
/**
|
|
289
318
|
* Scan git staged files for secrets
|
|
290
319
|
*/
|
|
291
|
-
async function scanStagedFiles(opts, scanCfg, baselineEntries = [], scanPath) {
|
|
320
|
+
async function scanStagedFiles(opts, scanCfg, baselineEntries = [], scanPath, suppressions = []) {
|
|
292
321
|
const cwd = scanPath && fs.existsSync(scanPath) && fs.statSync(scanPath).isDirectory() ? scanPath : undefined;
|
|
293
322
|
try {
|
|
294
323
|
const stagedFilesOutput = execFileSync("git", ["diff", "--cached", "--name-only", "--diff-filter=ACM"], {
|
|
@@ -297,7 +326,7 @@ async function scanStagedFiles(opts, scanCfg, baselineEntries = [], scanPath) {
|
|
|
297
326
|
stdio: ["pipe", "pipe", "ignore"]
|
|
298
327
|
}).trim();
|
|
299
328
|
if (!stagedFilesOutput) {
|
|
300
|
-
outputScanResults([], opts, "staged files");
|
|
329
|
+
outputScanResults([], opts, "staged files", true, suppressions);
|
|
301
330
|
return;
|
|
302
331
|
}
|
|
303
332
|
const stagedFiles = stagedFilesOutput.split("\n").map(f => f.trim()).filter(f => f);
|
|
@@ -321,7 +350,7 @@ async function scanStagedFiles(opts, scanCfg, baselineEntries = [], scanPath) {
|
|
|
321
350
|
const results = await scanFile(filePath, engine, scanCfg);
|
|
322
351
|
allResults.push(...results);
|
|
323
352
|
}
|
|
324
|
-
outputScanResults(applyBaseline(allResults, baselineEntries), opts, "staged files");
|
|
353
|
+
outputScanResults(applyBaseline(allResults, baselineEntries), opts, "staged files", true, suppressions);
|
|
325
354
|
}
|
|
326
355
|
catch (error) {
|
|
327
356
|
if (error.status === 128) {
|
|
@@ -338,38 +367,38 @@ async function selectEngine(preference, quiet) {
|
|
|
338
367
|
if (preference === "patterns") {
|
|
339
368
|
return "patterns";
|
|
340
369
|
}
|
|
341
|
-
if (preference === "
|
|
342
|
-
const
|
|
343
|
-
const available = await
|
|
370
|
+
if (preference === "betterleaks") {
|
|
371
|
+
const bl = new BetterleaksScanner();
|
|
372
|
+
const available = await bl.isAvailable();
|
|
344
373
|
if (!available) {
|
|
345
374
|
if (!quiet) {
|
|
346
|
-
console.error(fmt.warning("
|
|
375
|
+
console.error(fmt.warning("Betterleaks requested but not available, using patterns"));
|
|
347
376
|
}
|
|
348
377
|
return "patterns";
|
|
349
378
|
}
|
|
350
|
-
return "
|
|
379
|
+
return "betterleaks";
|
|
351
380
|
}
|
|
352
381
|
if (preference !== "auto") {
|
|
353
|
-
console.error(`Invalid engine: ${preference}. Valid values: auto,
|
|
382
|
+
console.error(`Invalid engine: ${preference}. Valid values: auto, betterleaks, patterns`);
|
|
354
383
|
process.exit(2);
|
|
355
384
|
}
|
|
356
|
-
// Auto mode: try
|
|
357
|
-
const
|
|
358
|
-
const available = await
|
|
359
|
-
return available ? "
|
|
385
|
+
// Auto mode: try Betterleaks, fall back to patterns
|
|
386
|
+
const bl = new BetterleaksScanner();
|
|
387
|
+
const available = await bl.isAvailable();
|
|
388
|
+
return available ? "betterleaks" : "patterns";
|
|
360
389
|
}
|
|
361
390
|
/**
|
|
362
391
|
* Scan a file with selected engine
|
|
363
392
|
*/
|
|
364
393
|
async function scanFile(filePath, engine, scanCfg) {
|
|
365
|
-
if (engine === "
|
|
394
|
+
if (engine === "betterleaks") {
|
|
366
395
|
try {
|
|
367
|
-
const
|
|
368
|
-
const result = await
|
|
396
|
+
const bl = new BetterleaksScanner();
|
|
397
|
+
const result = await bl.scanFile(filePath);
|
|
369
398
|
return result.matches.length > 0 ? [result] : [];
|
|
370
399
|
}
|
|
371
400
|
catch (e) {
|
|
372
|
-
console.error(fmt.warning("
|
|
401
|
+
console.error(fmt.warning("Betterleaks scan failed, falling back to patterns"));
|
|
373
402
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
374
403
|
const result = scanner.scanFile(filePath);
|
|
375
404
|
return result.matches.length > 0 ? [result] : [];
|
|
@@ -385,13 +414,13 @@ async function scanFile(filePath, engine, scanCfg) {
|
|
|
385
414
|
* Scan a directory with selected engine
|
|
386
415
|
*/
|
|
387
416
|
async function scanDirectory(dirPath, engine, scanCfg, history) {
|
|
388
|
-
if (engine === "
|
|
417
|
+
if (engine === "betterleaks") {
|
|
389
418
|
try {
|
|
390
|
-
const
|
|
391
|
-
return await
|
|
419
|
+
const bl = new BetterleaksScanner();
|
|
420
|
+
return await bl.scanDirectory(dirPath, { useGit: history ?? false });
|
|
392
421
|
}
|
|
393
422
|
catch (e) {
|
|
394
|
-
console.error(fmt.warning("
|
|
423
|
+
console.error(fmt.warning("Betterleaks scan failed, falling back to patterns"));
|
|
395
424
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
396
425
|
return scanner.scanDirectory(dirPath, { excludePaths: scanCfg?.excludePaths });
|
|
397
426
|
}
|
|
@@ -404,7 +433,7 @@ async function scanDirectory(dirPath, engine, scanCfg, history) {
|
|
|
404
433
|
/**
|
|
405
434
|
* Watch a path for changes and re-scan on each change
|
|
406
435
|
*/
|
|
407
|
-
async function watchAndScan(watchPath, opts, scanCfg) {
|
|
436
|
+
async function watchAndScan(watchPath, opts, scanCfg, suppressions = []) {
|
|
408
437
|
const { watch } = await import("chokidar");
|
|
409
438
|
const logger = new AuditLogger();
|
|
410
439
|
const engine = await selectEngine(opts.engine || "auto", opts.quiet || false);
|
|
@@ -418,7 +447,7 @@ async function watchAndScan(watchPath, opts, scanCfg) {
|
|
|
418
447
|
: await scanFile(watchPath, engine, scanCfg);
|
|
419
448
|
if (initialResults.length > 0) {
|
|
420
449
|
console.log(fmt.warning(`\n[Initial scan] Found secrets:`));
|
|
421
|
-
outputScanResults(initialResults, { ...opts, quiet: false }, undefined, /* exitOnFindings= */ false);
|
|
450
|
+
outputScanResults(initialResults, { ...opts, quiet: false }, undefined, /* exitOnFindings= */ false, suppressions);
|
|
422
451
|
logWatchFindings(logger, initialResults);
|
|
423
452
|
}
|
|
424
453
|
else if (!opts.quiet) {
|
|
@@ -442,7 +471,7 @@ async function watchAndScan(watchPath, opts, scanCfg) {
|
|
|
442
471
|
return;
|
|
443
472
|
const results = await scanFile(filePath, engine, scanCfg);
|
|
444
473
|
if (results.length > 0) {
|
|
445
|
-
outputScanResults(results, { ...opts, quiet: false }, undefined, /* exitOnFindings= */ false);
|
|
474
|
+
outputScanResults(results, { ...opts, quiet: false }, undefined, /* exitOnFindings= */ false, suppressions);
|
|
446
475
|
logWatchFindings(logger, results);
|
|
447
476
|
}
|
|
448
477
|
else if (!opts.quiet) {
|
|
@@ -459,7 +488,7 @@ async function watchAndScan(watchPath, opts, scanCfg) {
|
|
|
459
488
|
return;
|
|
460
489
|
const results = await scanFile(filePath, engine, scanCfg);
|
|
461
490
|
if (results.length > 0) {
|
|
462
|
-
outputScanResults(results, { ...opts, quiet: false }, undefined, /* exitOnFindings= */ false);
|
|
491
|
+
outputScanResults(results, { ...opts, quiet: false }, undefined, /* exitOnFindings= */ false, suppressions);
|
|
463
492
|
logWatchFindings(logger, results);
|
|
464
493
|
}
|
|
465
494
|
else if (!opts.quiet) {
|
|
@@ -6,6 +6,7 @@ import { execSync } from "child_process";
|
|
|
6
6
|
import { getRafterDir, getAuditLogPath, getBinDir } from "../../core/config-defaults.js";
|
|
7
7
|
import { AuditLogger } from "../../core/audit-logger.js";
|
|
8
8
|
import { ConfigManager } from "../../core/config-manager.js";
|
|
9
|
+
import { BinaryManager } from "../../utils/binary-manager.js";
|
|
9
10
|
export function createStatusCommand() {
|
|
10
11
|
return new Command("status")
|
|
11
12
|
.description("Show agent security status dashboard")
|
|
@@ -30,25 +31,33 @@ export function createStatusCommand() {
|
|
|
30
31
|
else {
|
|
31
32
|
console.log(`\nConfig: not found — run: rafter agent init`);
|
|
32
33
|
}
|
|
33
|
-
// ---
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
// --- Betterleaks ---
|
|
35
|
+
const exeExt = process.platform === "win32" ? ".exe" : "";
|
|
36
|
+
const localBetterleaks = path.join(getBinDir(), `betterleaks${exeExt}`);
|
|
37
|
+
let betterleaksStatus = "not found — run: rafter agent init --with-betterleaks";
|
|
36
38
|
try {
|
|
37
|
-
const ver = execSync("
|
|
38
|
-
|
|
39
|
+
const ver = execSync("betterleaks version", { timeout: 5000, encoding: "utf-8", stdio: ["pipe", "pipe", "ignore"] }).trim();
|
|
40
|
+
betterleaksStatus = `${ver} (PATH)`;
|
|
39
41
|
}
|
|
40
42
|
catch {
|
|
41
|
-
if (fs.existsSync(
|
|
43
|
+
if (fs.existsSync(localBetterleaks)) {
|
|
42
44
|
try {
|
|
43
|
-
const ver = execSync(`"${
|
|
44
|
-
|
|
45
|
+
const ver = execSync(`"${localBetterleaks}" version`, { timeout: 5000, encoding: "utf-8", stdio: ["pipe", "pipe", "ignore"] }).trim();
|
|
46
|
+
betterleaksStatus = `${ver} (local)`;
|
|
45
47
|
}
|
|
46
48
|
catch {
|
|
47
|
-
|
|
49
|
+
betterleaksStatus = `${localBetterleaks} (binary error)`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// Legacy install — surface a hint instead of "not found"
|
|
54
|
+
const legacy = new BinaryManager().findLegacyGitleaks();
|
|
55
|
+
if (legacy) {
|
|
56
|
+
betterleaksStatus = `not found — legacy gitleaks at ${legacy}; run: rafter agent update-betterleaks`;
|
|
48
57
|
}
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
|
-
console.log(`
|
|
60
|
+
console.log(`Betterleaks: ${betterleaksStatus}`);
|
|
52
61
|
// --- Claude Code hooks ---
|
|
53
62
|
const settingsPath = path.join(home, ".claude", "settings.json");
|
|
54
63
|
let pretoolOk = false;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { BinaryManager, BETTERLEAKS_VERSION } from "../../utils/binary-manager.js";
|
|
3
|
+
import { fmt } from "../../utils/formatter.js";
|
|
4
|
+
export function createUpdateBetterleaksCommand() {
|
|
5
|
+
return new Command("update-betterleaks")
|
|
6
|
+
.description("Update (or reinstall) the managed betterleaks binary")
|
|
7
|
+
.option("--version <version>", "Betterleaks version to install", BETTERLEAKS_VERSION)
|
|
8
|
+
.action(async (opts) => {
|
|
9
|
+
const bm = new BinaryManager();
|
|
10
|
+
if (!bm.isPlatformSupported()) {
|
|
11
|
+
const { platform, arch } = bm.getPlatformInfo();
|
|
12
|
+
console.error(fmt.error(`Betterleaks not available for ${platform}/${arch}`));
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
if (bm.isBetterleaksInstalled()) {
|
|
16
|
+
const current = await bm.getBetterleaksVersion();
|
|
17
|
+
console.log(fmt.info(`Current: ${current}`));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
console.log(fmt.info("Betterleaks not currently installed (managed binary)"));
|
|
21
|
+
}
|
|
22
|
+
console.log(fmt.info(`Installing betterleaks v${opts.version}...`));
|
|
23
|
+
console.log();
|
|
24
|
+
try {
|
|
25
|
+
await bm.downloadBetterleaks((msg) => console.log(` ${msg}`), opts.version);
|
|
26
|
+
console.log();
|
|
27
|
+
const installed = await bm.getBetterleaksVersion();
|
|
28
|
+
console.log(fmt.success(`Betterleaks updated: ${installed}`));
|
|
29
|
+
console.log(fmt.info(` Binary: ${bm.getBetterleaksPath()}`));
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
console.log();
|
|
33
|
+
console.error(fmt.error(`Update failed: ${e}`));
|
|
34
|
+
console.log(fmt.info("To fix: install betterleaks manually (https://github.com/betterleaks/betterleaks/releases) " +
|
|
35
|
+
"and ensure it is on PATH."));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|