@rafter-security/cli 0.7.9 → 0.8.1
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/commands/agent/baseline.js +15 -15
- package/dist/commands/agent/index.js +2 -2
- package/dist/commands/agent/init.js +165 -24
- package/dist/commands/agent/scan.js +24 -24
- package/dist/commands/agent/status.js +19 -10
- package/dist/commands/agent/update-betterleaks.js +39 -0
- package/dist/commands/agent/verify.js +19 -8
- package/dist/commands/completion.js +15 -15
- package/dist/commands/issues/from-scan.js +2 -2
- package/dist/commands/mcp/server.js +11 -11
- package/dist/scanners/{gitleaks.js → betterleaks.js} +49 -61
- package/dist/scanners/secret-patterns.js +1 -1
- package/dist/utils/binary-manager.js +205 -109
- package/package.json +1 -1
- package/resources/agents/rafter.md +1 -1
- package/resources/rafter-security-skill.md +3 -3
- package/resources/skills/rafter/SKILL.md +1 -1
- package/resources/skills/rafter/docs/cli-reference.md +5 -5
- package/dist/commands/agent/update-gitleaks.js +0 -40
|
@@ -4,7 +4,7 @@ import os from "os";
|
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { fmt } from "../../utils/formatter.js";
|
|
6
6
|
import { RegexScanner } from "../../scanners/regex-scanner.js";
|
|
7
|
-
import {
|
|
7
|
+
import { BetterleaksScanner } from "../../scanners/betterleaks.js";
|
|
8
8
|
import { ConfigManager } from "../../core/config-manager.js";
|
|
9
9
|
const BASELINE_PATH = path.join(os.homedir(), ".rafter", "baseline.json");
|
|
10
10
|
function loadBaseline() {
|
|
@@ -38,9 +38,9 @@ function createBaselineCreateCommand() {
|
|
|
38
38
|
return new Command("create")
|
|
39
39
|
.description("Scan and save all current findings as the baseline")
|
|
40
40
|
.argument("[path]", "Path to scan", ".")
|
|
41
|
-
.option("--engine <engine>", "Scan engine:
|
|
41
|
+
.option("--engine <engine>", "Scan engine: betterleaks or patterns", "auto")
|
|
42
42
|
.action(async (scanPath, opts) => {
|
|
43
|
-
const validEngines = ["auto", "
|
|
43
|
+
const validEngines = ["auto", "betterleaks", "patterns"];
|
|
44
44
|
const engineValue = opts.engine || "auto";
|
|
45
45
|
if (!validEngines.includes(engineValue)) {
|
|
46
46
|
console.error(`Invalid engine: ${engineValue}. Valid values: ${validEngines.join(", ")}`);
|
|
@@ -169,22 +169,22 @@ function createBaselineAddCommand() {
|
|
|
169
169
|
async function selectEngine(preference) {
|
|
170
170
|
if (preference === "patterns")
|
|
171
171
|
return "patterns";
|
|
172
|
-
if (preference === "
|
|
173
|
-
const
|
|
174
|
-
return (await
|
|
172
|
+
if (preference === "betterleaks") {
|
|
173
|
+
const b = new BetterleaksScanner();
|
|
174
|
+
return (await b.isAvailable()) ? "betterleaks" : "patterns";
|
|
175
175
|
}
|
|
176
176
|
if (preference !== "auto") {
|
|
177
|
-
console.error(`Invalid engine: ${preference}. Valid values: auto,
|
|
177
|
+
console.error(`Invalid engine: ${preference}. Valid values: auto, betterleaks, patterns`);
|
|
178
178
|
process.exit(2);
|
|
179
179
|
}
|
|
180
|
-
const
|
|
181
|
-
return (await
|
|
180
|
+
const b = new BetterleaksScanner();
|
|
181
|
+
return (await b.isAvailable()) ? "betterleaks" : "patterns";
|
|
182
182
|
}
|
|
183
183
|
async function scanFile(filePath, engine) {
|
|
184
|
-
if (engine === "
|
|
184
|
+
if (engine === "betterleaks") {
|
|
185
185
|
try {
|
|
186
|
-
const
|
|
187
|
-
const r = await
|
|
186
|
+
const b = new BetterleaksScanner();
|
|
187
|
+
const r = await b.scanFile(filePath);
|
|
188
188
|
return r.matches.length > 0 ? [r] : [];
|
|
189
189
|
}
|
|
190
190
|
catch {
|
|
@@ -198,10 +198,10 @@ async function scanFile(filePath, engine) {
|
|
|
198
198
|
return r.matches.length > 0 ? [r] : [];
|
|
199
199
|
}
|
|
200
200
|
async function scanDirectory(dirPath, engine, scanCfg) {
|
|
201
|
-
if (engine === "
|
|
201
|
+
if (engine === "betterleaks") {
|
|
202
202
|
try {
|
|
203
|
-
const
|
|
204
|
-
return await
|
|
203
|
+
const b = new BetterleaksScanner();
|
|
204
|
+
return await b.scanDirectory(dirPath);
|
|
205
205
|
}
|
|
206
206
|
catch {
|
|
207
207
|
const s = new RegexScanner();
|
|
@@ -9,7 +9,7 @@ import { createAuditSkillCommand } from "./audit-skill.js";
|
|
|
9
9
|
import { createInstallHookCommand } from "./install-hook.js";
|
|
10
10
|
import { createVerifyCommand } from "./verify.js";
|
|
11
11
|
import { createStatusCommand } from "./status.js";
|
|
12
|
-
import {
|
|
12
|
+
import { createUpdateBetterleaksCommand } from "./update-betterleaks.js";
|
|
13
13
|
import { createBaselineCommand } from "./baseline.js";
|
|
14
14
|
import { createListCommand } from "./list.js";
|
|
15
15
|
import { createEnableCommand } from "./enable.js";
|
|
@@ -28,7 +28,7 @@ export function createAgentCommand() {
|
|
|
28
28
|
agent.addCommand(createInstallHookCommand());
|
|
29
29
|
agent.addCommand(createVerifyCommand());
|
|
30
30
|
agent.addCommand(createStatusCommand());
|
|
31
|
-
agent.addCommand(
|
|
31
|
+
agent.addCommand(createUpdateBetterleaksCommand());
|
|
32
32
|
agent.addCommand(createBaselineCommand());
|
|
33
33
|
agent.addCommand(createListCommand());
|
|
34
34
|
agent.addCommand(createEnableCommand());
|
|
@@ -26,6 +26,125 @@ const AGENT_SKILLS = [
|
|
|
26
26
|
{ name: "rafter-secure-design", description: "Rafter Secure Design" },
|
|
27
27
|
{ name: "rafter-code-review", description: "Rafter Code Review" },
|
|
28
28
|
];
|
|
29
|
+
/**
|
|
30
|
+
* Print every file path the install would touch — without writing anything.
|
|
31
|
+
*
|
|
32
|
+
* Lists are derived from the resolved want* booleans (which already account
|
|
33
|
+
* for --all, --with-*, detection, and --local scope), so the printed plan
|
|
34
|
+
* mirrors exactly what the install path would do. Implements rf-hrtd.
|
|
35
|
+
*/
|
|
36
|
+
function printDryRunPlan(plan) {
|
|
37
|
+
const home = os.homedir();
|
|
38
|
+
let writeCount = 0;
|
|
39
|
+
let downloadCount = 0;
|
|
40
|
+
const W = (p, note) => {
|
|
41
|
+
writeCount++;
|
|
42
|
+
console.log(` WRITE ${p}${note ? ` (${note})` : ""}`);
|
|
43
|
+
};
|
|
44
|
+
const D = (p, note) => {
|
|
45
|
+
downloadCount++;
|
|
46
|
+
console.log(` DOWNLOAD ${p}${note ? ` (${note})` : ""}`);
|
|
47
|
+
};
|
|
48
|
+
const R = (p, note) => {
|
|
49
|
+
console.log(` REMOVE ${p}${note ? ` (${note})` : ""}`);
|
|
50
|
+
};
|
|
51
|
+
console.log();
|
|
52
|
+
console.log(fmt.info("DRY RUN — no files will be created or modified."));
|
|
53
|
+
console.log(fmt.info(`Scope: ${plan.scope}${plan.scope === "project" ? ` (cwd: ${plan.root})` : ""}`));
|
|
54
|
+
console.log();
|
|
55
|
+
console.log(fmt.divider());
|
|
56
|
+
console.log("Always:");
|
|
57
|
+
W(path.join(home, ".rafter", "config.json"), `riskLevel: ${plan.riskLevel}`);
|
|
58
|
+
W(path.join(home, ".rafter", "bin/"), "directory");
|
|
59
|
+
W(path.join(home, ".rafter", "patterns/"), "directory");
|
|
60
|
+
if (plan.wantBetterleaks) {
|
|
61
|
+
console.log();
|
|
62
|
+
console.log("Betterleaks (--with-betterleaks / --all):");
|
|
63
|
+
D(path.join(home, ".rafter", "bin", "betterleaks"), "binary, ~12MB from GitHub releases");
|
|
64
|
+
}
|
|
65
|
+
if (plan.wantClaudeCode) {
|
|
66
|
+
console.log();
|
|
67
|
+
console.log("Claude Code (--with-claude-code):");
|
|
68
|
+
W(path.join(plan.root, ".claude", "settings.json"), "PreToolUse + PostToolUse hooks merged");
|
|
69
|
+
for (const s of ["rafter", "rafter-secure-design", "rafter-code-review", "rafter-skill-review"]) {
|
|
70
|
+
W(path.join(plan.root, ".claude", "skills", s, "SKILL.md"));
|
|
71
|
+
}
|
|
72
|
+
W(path.join(plan.root, ".claude", "agents", "rafter.md"), "sub-agent");
|
|
73
|
+
W(path.join(plan.root, ".claude", "CLAUDE.md"), "rafter:start/end marker block");
|
|
74
|
+
W(path.join(plan.root, ".mcp.json"), "project-scope MCP config");
|
|
75
|
+
}
|
|
76
|
+
if (plan.wantCodex) {
|
|
77
|
+
console.log();
|
|
78
|
+
console.log("Codex CLI (--with-codex):");
|
|
79
|
+
W(path.join(plan.root, ".codex", "hooks.json"), "PreToolUse: Bash|apply_patch, PostToolUse: .*");
|
|
80
|
+
for (const s of AGENT_SKILLS) {
|
|
81
|
+
W(path.join(plan.root, ".agents", "skills", s.name, "SKILL.md"));
|
|
82
|
+
}
|
|
83
|
+
const agentsMd = plan.scope === "user" ? path.join(plan.root, ".codex", "AGENTS.md") : path.join(plan.root, "AGENTS.md");
|
|
84
|
+
W(agentsMd, "shared with Windsurf when --with-windsurf");
|
|
85
|
+
}
|
|
86
|
+
if (plan.wantGemini) {
|
|
87
|
+
console.log();
|
|
88
|
+
console.log("Gemini CLI (--with-gemini):");
|
|
89
|
+
W(path.join(plan.root, ".gemini", "settings.json"), "MCP + BeforeTool/AfterTool hooks");
|
|
90
|
+
for (const s of AGENT_SKILLS) {
|
|
91
|
+
W(path.join(plan.root, ".agents", "skills", s.name, "SKILL.md"), "shared with Codex");
|
|
92
|
+
}
|
|
93
|
+
const geminiMd = plan.scope === "user" ? path.join(plan.root, ".gemini", "GEMINI.md") : path.join(plan.root, "GEMINI.md");
|
|
94
|
+
W(geminiMd);
|
|
95
|
+
if (plan.scope === "user") {
|
|
96
|
+
console.log(` EXEC gemini skills link ${path.join(plan.root, ".agents", "skills", "rafter")} (per-skill, runtime registration)`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (plan.wantCursor) {
|
|
100
|
+
console.log();
|
|
101
|
+
console.log("Cursor (--with-cursor):");
|
|
102
|
+
W(path.join(plan.root, ".cursor", "hooks.json"), "preToolUse + postToolUse + beforeShellExecution");
|
|
103
|
+
for (const s of ["rafter", "rafter-secure-design", "rafter-code-review", "rafter-skill-review"]) {
|
|
104
|
+
W(path.join(plan.root, ".cursor", "rules", `${s}.mdc`));
|
|
105
|
+
}
|
|
106
|
+
W(path.join(plan.root, ".cursor", "agents", "rafter.md"), "sub-agent (Cursor reads .claude/agents/ too)");
|
|
107
|
+
W(path.join(plan.root, ".cursor", "mcp.json"));
|
|
108
|
+
}
|
|
109
|
+
if (plan.wantWindsurf) {
|
|
110
|
+
console.log();
|
|
111
|
+
console.log("Windsurf (--with-windsurf):");
|
|
112
|
+
if (plan.scope === "user") {
|
|
113
|
+
W(path.join(home, ".codeium", "windsurf", "mcp_config.json"), "user-scope MCP only");
|
|
114
|
+
}
|
|
115
|
+
for (const s of ["rafter", "rafter-secure-design", "rafter-code-review", "rafter-skill-review"]) {
|
|
116
|
+
W(path.join(plan.root, ".windsurf", "rules", `${s}.md`));
|
|
117
|
+
}
|
|
118
|
+
W(path.join(plan.root, "AGENTS.md"), "shared with Codex; idempotent if already written");
|
|
119
|
+
}
|
|
120
|
+
if (plan.wantContinue) {
|
|
121
|
+
console.log();
|
|
122
|
+
console.log("Continue.dev (--with-continue):");
|
|
123
|
+
if (plan.scope === "user") {
|
|
124
|
+
W(path.join(home, ".continue", "config.json"), "MCP entry; preserves existing keys");
|
|
125
|
+
}
|
|
126
|
+
for (const s of ["rafter", "rafter-secure-design", "rafter-code-review", "rafter-skill-review"]) {
|
|
127
|
+
W(path.join(plan.root, ".continue", "rules", `${s}.md`));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (plan.wantAider) {
|
|
131
|
+
console.log();
|
|
132
|
+
console.log("Aider (--with-aider):");
|
|
133
|
+
W(path.join(plan.root, "RAFTER.md"), "rafter:start/end marker block");
|
|
134
|
+
W(path.join(plan.root, ".aider.conf.yml"), "appends RAFTER.md to read: list; strips legacy mcp-server-command line");
|
|
135
|
+
}
|
|
136
|
+
if (plan.wantOpenClaw) {
|
|
137
|
+
console.log();
|
|
138
|
+
console.log("OpenClaw (--with-openclaw):");
|
|
139
|
+
W(path.join(home, ".openclaw", "workspace", "skills", "rafter-security", "SKILL.md"), "ClawHub-shape");
|
|
140
|
+
R(path.join(home, ".openclaw", "skills", "rafter-security.md"), "legacy file from rafter ≤ 0.7.7, if present");
|
|
141
|
+
}
|
|
142
|
+
console.log();
|
|
143
|
+
console.log(fmt.divider());
|
|
144
|
+
console.log(fmt.info(`Plan: ${writeCount} write${writeCount === 1 ? "" : "s"}, ${downloadCount} download${downloadCount === 1 ? "" : "s"}.`));
|
|
145
|
+
console.log(fmt.info("Re-run without --dry-run to apply."));
|
|
146
|
+
console.log();
|
|
147
|
+
}
|
|
29
148
|
/**
|
|
30
149
|
* Install instruction files for platforms that support them, at either user
|
|
31
150
|
* or project scope.
|
|
@@ -782,12 +901,13 @@ export function createInitCommand() {
|
|
|
782
901
|
.option("--with-cursor", "Install Cursor integration")
|
|
783
902
|
.option("--with-windsurf", "Install Windsurf integration")
|
|
784
903
|
.option("--with-continue", "Install Continue.dev integration")
|
|
785
|
-
.option("--with-
|
|
786
|
-
.option("--all", "Install all detected integrations and download
|
|
904
|
+
.option("--with-betterleaks", "Download and install Betterleaks binary")
|
|
905
|
+
.option("--all", "Install all detected integrations and download Betterleaks")
|
|
787
906
|
.option("-i, --interactive", "Guided setup — prompts for each detected integration")
|
|
788
|
-
.option("--update", "Re-download
|
|
907
|
+
.option("--update", "Re-download betterleaks and reinstall integrations without resetting config")
|
|
789
908
|
.option("--local", "Install integration configs project-locally (in CWD) instead of user-globally. " +
|
|
790
909
|
"Supported for Claude Code, Codex, Gemini, Cursor. Other platforms are skipped in local mode.")
|
|
910
|
+
.option("--dry-run", "Print every file path that would be created, modified, or downloaded — without making any changes (rf-hrtd).")
|
|
791
911
|
.action(async (opts) => {
|
|
792
912
|
console.log(fmt.header("Rafter Agent Security Setup"));
|
|
793
913
|
console.log(fmt.divider());
|
|
@@ -833,7 +953,7 @@ export function createInitCommand() {
|
|
|
833
953
|
// Aider can install at --local scope (writes RAFTER.md + .aider.conf.yml
|
|
834
954
|
// in cwd) since rf-du2o.
|
|
835
955
|
let wantAider = opts.withAider || opts.all;
|
|
836
|
-
let
|
|
956
|
+
let wantBetterleaks = opts.withBetterleaks || (opts.all && !opts.local);
|
|
837
957
|
// Interactive mode: prompt for each detected integration
|
|
838
958
|
if (opts.interactive && !opts.all) {
|
|
839
959
|
console.log();
|
|
@@ -855,8 +975,8 @@ export function createInitCommand() {
|
|
|
855
975
|
wantContinue = await askYesNo("Install Continue.dev MCP server?");
|
|
856
976
|
if (hasAider && !wantAider)
|
|
857
977
|
wantAider = await askYesNo("Install Aider MCP server?");
|
|
858
|
-
if (!
|
|
859
|
-
|
|
978
|
+
if (!wantBetterleaks)
|
|
979
|
+
wantBetterleaks = await askYesNo("Download Betterleaks binary (enhanced scanning)?");
|
|
860
980
|
console.log();
|
|
861
981
|
}
|
|
862
982
|
// Show detected environments with opt-in hints
|
|
@@ -903,6 +1023,27 @@ export function createInitCommand() {
|
|
|
903
1023
|
if (wantAider && !hasAider)
|
|
904
1024
|
console.log(fmt.warning("Aider requested but not detected (~/.aider.conf.yml not found)"));
|
|
905
1025
|
}
|
|
1026
|
+
// --dry-run: print every file path the command would touch, then
|
|
1027
|
+
// exit before any filesystem write happens (rf-hrtd). The plan is
|
|
1028
|
+
// built from the SAME resolved want* / has* booleans the install
|
|
1029
|
+
// path uses, so the listing mirrors what would actually run.
|
|
1030
|
+
if (opts.dryRun) {
|
|
1031
|
+
printDryRunPlan({
|
|
1032
|
+
root,
|
|
1033
|
+
scope,
|
|
1034
|
+
wantOpenClaw: wantOpenClaw && (hasOpenClaw),
|
|
1035
|
+
wantClaudeCode: wantClaudeCode && (hasClaudeCode || opts.local),
|
|
1036
|
+
wantCodex: wantCodex && (hasCodex || opts.local),
|
|
1037
|
+
wantGemini: wantGemini && (hasGemini || opts.local),
|
|
1038
|
+
wantCursor: wantCursor && (hasCursor || opts.local),
|
|
1039
|
+
wantWindsurf: wantWindsurf && (hasWindsurf || opts.local),
|
|
1040
|
+
wantContinue: wantContinue && (hasContinueDev || opts.local),
|
|
1041
|
+
wantAider: wantAider && (hasAider || opts.local),
|
|
1042
|
+
wantBetterleaks,
|
|
1043
|
+
riskLevel: opts.riskLevel,
|
|
1044
|
+
});
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
906
1047
|
// Initialize directory structure
|
|
907
1048
|
try {
|
|
908
1049
|
await manager.initialize();
|
|
@@ -921,8 +1062,8 @@ export function createInitCommand() {
|
|
|
921
1062
|
}
|
|
922
1063
|
manager.set("agent.riskLevel", opts.riskLevel);
|
|
923
1064
|
console.log(fmt.success(`Set risk level: ${opts.riskLevel}`));
|
|
924
|
-
// Check / download
|
|
925
|
-
if (
|
|
1065
|
+
// Check / download Betterleaks binary (opt-in via --with-betterleaks or --all)
|
|
1066
|
+
if (wantBetterleaks) {
|
|
926
1067
|
const binaryManager = new BinaryManager();
|
|
927
1068
|
const platformInfo = binaryManager.getPlatformInfo();
|
|
928
1069
|
// Helper: show diagnostics for a failing binary (mirrors Python's agent init)
|
|
@@ -935,56 +1076,56 @@ export function createInitCommand() {
|
|
|
935
1076
|
console.log(fmt.info("Diagnostics:"));
|
|
936
1077
|
console.log(diag);
|
|
937
1078
|
}
|
|
938
|
-
console.log(fmt.info("To fix: install
|
|
1079
|
+
console.log(fmt.info("To fix: install betterleaks (https://github.com/betterleaks/betterleaks/releases) and ensure it is on PATH, then re-run 'rafter agent init'."));
|
|
939
1080
|
console.log();
|
|
940
1081
|
};
|
|
941
|
-
if (!opts.update && binaryManager.
|
|
1082
|
+
if (!opts.update && binaryManager.isBetterleaksInstalled()) {
|
|
942
1083
|
// Local binary exists — verify it actually works
|
|
943
|
-
const verResult = await binaryManager.
|
|
1084
|
+
const verResult = await binaryManager.verifyBetterleaksVerbose();
|
|
944
1085
|
if (verResult.ok) {
|
|
945
|
-
console.log(fmt.success(`
|
|
1086
|
+
console.log(fmt.success(`Betterleaks already installed (${verResult.stdout})`));
|
|
946
1087
|
}
|
|
947
1088
|
else {
|
|
948
|
-
console.log(fmt.warning("
|
|
949
|
-
console.log(fmt.info(` Binary: ${binaryManager.
|
|
950
|
-
await showDiagnostics(binaryManager.
|
|
1089
|
+
console.log(fmt.warning("Betterleaks binary found locally but failed to execute."));
|
|
1090
|
+
console.log(fmt.info(` Binary: ${binaryManager.getBetterleaksPath()}`));
|
|
1091
|
+
await showDiagnostics(binaryManager.getBetterleaksPath(), verResult);
|
|
951
1092
|
}
|
|
952
1093
|
}
|
|
953
1094
|
else {
|
|
954
1095
|
// Not installed locally (or --update forcing re-download) — check PATH first
|
|
955
1096
|
// unless --update was passed (in that case force a fresh managed install)
|
|
956
|
-
const pathBinary = opts.update ? null : binaryManager.
|
|
1097
|
+
const pathBinary = opts.update ? null : binaryManager.findBetterleaksOnPath();
|
|
957
1098
|
if (pathBinary) {
|
|
958
|
-
const verResult = await binaryManager.
|
|
1099
|
+
const verResult = await binaryManager.verifyBetterleaksVerbose(pathBinary);
|
|
959
1100
|
if (verResult.ok) {
|
|
960
|
-
console.log(fmt.success(`
|
|
1101
|
+
console.log(fmt.success(`Betterleaks available on PATH (${verResult.stdout})`));
|
|
961
1102
|
}
|
|
962
1103
|
else {
|
|
963
|
-
console.log(fmt.warning("
|
|
1104
|
+
console.log(fmt.warning("Betterleaks found on PATH but failed to execute."));
|
|
964
1105
|
console.log(fmt.info(` Binary: ${pathBinary}`));
|
|
965
1106
|
await showDiagnostics(pathBinary, verResult);
|
|
966
1107
|
}
|
|
967
1108
|
}
|
|
968
1109
|
else if (!platformInfo.supported) {
|
|
969
|
-
console.log(fmt.info(`
|
|
1110
|
+
console.log(fmt.info(`Betterleaks not available for ${platformInfo.platform}/${platformInfo.arch}`));
|
|
970
1111
|
console.log(fmt.success("Using pattern-based scanning (21 patterns)"));
|
|
971
1112
|
}
|
|
972
1113
|
else {
|
|
973
1114
|
// Not on PATH, not installed locally — download
|
|
974
1115
|
console.log();
|
|
975
|
-
console.log(fmt.info("Downloading
|
|
1116
|
+
console.log(fmt.info("Downloading Betterleaks (enhanced secret detection)..."));
|
|
976
1117
|
try {
|
|
977
|
-
await binaryManager.
|
|
1118
|
+
await binaryManager.downloadBetterleaks((msg) => {
|
|
978
1119
|
console.log(` ${msg}`);
|
|
979
1120
|
});
|
|
980
1121
|
console.log();
|
|
981
1122
|
}
|
|
982
1123
|
catch (e) {
|
|
983
1124
|
console.log();
|
|
984
|
-
console.log(fmt.error(`
|
|
1125
|
+
console.log(fmt.error(`Betterleaks setup failed — pattern-based scanning will be used instead.`));
|
|
985
1126
|
console.log(fmt.warning(String(e)));
|
|
986
1127
|
console.log();
|
|
987
|
-
console.log(fmt.info("To fix: install
|
|
1128
|
+
console.log(fmt.info("To fix: install betterleaks manually (https://github.com/betterleaks/betterleaks/releases) and ensure it is on PATH, then re-run 'rafter agent init'."));
|
|
988
1129
|
console.log();
|
|
989
1130
|
}
|
|
990
1131
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
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
6
|
import { applySuppressions, loadSuppressions, policyIgnoreToSuppressions, } from "../../core/custom-patterns.js";
|
|
@@ -45,13 +45,13 @@ export function createScanCommand() {
|
|
|
45
45
|
.option("--format <format>", "Output format: text, json, sarif", "text")
|
|
46
46
|
.option("--staged", "Scan only git staged files")
|
|
47
47
|
.option("--diff <ref>", "Scan files changed since a git ref")
|
|
48
|
-
.option("--engine <engine>", "Scan engine:
|
|
48
|
+
.option("--engine <engine>", "Scan engine: betterleaks or patterns", "auto")
|
|
49
49
|
.option("--baseline", "Filter findings present in the saved baseline")
|
|
50
50
|
.option("--watch", "Watch for file changes and re-scan on change")
|
|
51
|
-
.option("--history", "Scan git history for secrets (requires
|
|
51
|
+
.option("--history", "Scan git history for secrets (requires betterleaks engine)")
|
|
52
52
|
.action(async (scanPath, opts) => {
|
|
53
|
-
// Validate flags before doing any work
|
|
54
|
-
const validEngines = ["auto", "
|
|
53
|
+
// Validate flags before doing any work.
|
|
54
|
+
const validEngines = ["auto", "betterleaks", "patterns"];
|
|
55
55
|
const engineValue = opts.engine || "auto";
|
|
56
56
|
if (!validEngines.includes(engineValue)) {
|
|
57
57
|
console.error(`Invalid engine: ${engineValue}. Valid values: ${validEngines.join(", ")}`);
|
|
@@ -125,7 +125,7 @@ export function createScanCommand() {
|
|
|
125
125
|
export function createSecretsCommand() {
|
|
126
126
|
const cmd = createScanCommand();
|
|
127
127
|
cmd.name("secrets");
|
|
128
|
-
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'.");
|
|
129
129
|
return cmd;
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
@@ -367,38 +367,38 @@ async function selectEngine(preference, quiet) {
|
|
|
367
367
|
if (preference === "patterns") {
|
|
368
368
|
return "patterns";
|
|
369
369
|
}
|
|
370
|
-
if (preference === "
|
|
371
|
-
const
|
|
372
|
-
const available = await
|
|
370
|
+
if (preference === "betterleaks") {
|
|
371
|
+
const bl = new BetterleaksScanner();
|
|
372
|
+
const available = await bl.isAvailable();
|
|
373
373
|
if (!available) {
|
|
374
374
|
if (!quiet) {
|
|
375
|
-
console.error(fmt.warning("
|
|
375
|
+
console.error(fmt.warning("Betterleaks requested but not available, using patterns"));
|
|
376
376
|
}
|
|
377
377
|
return "patterns";
|
|
378
378
|
}
|
|
379
|
-
return "
|
|
379
|
+
return "betterleaks";
|
|
380
380
|
}
|
|
381
381
|
if (preference !== "auto") {
|
|
382
|
-
console.error(`Invalid engine: ${preference}. Valid values: auto,
|
|
382
|
+
console.error(`Invalid engine: ${preference}. Valid values: auto, betterleaks, patterns`);
|
|
383
383
|
process.exit(2);
|
|
384
384
|
}
|
|
385
|
-
// Auto mode: try
|
|
386
|
-
const
|
|
387
|
-
const available = await
|
|
388
|
-
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";
|
|
389
389
|
}
|
|
390
390
|
/**
|
|
391
391
|
* Scan a file with selected engine
|
|
392
392
|
*/
|
|
393
393
|
async function scanFile(filePath, engine, scanCfg) {
|
|
394
|
-
if (engine === "
|
|
394
|
+
if (engine === "betterleaks") {
|
|
395
395
|
try {
|
|
396
|
-
const
|
|
397
|
-
const result = await
|
|
396
|
+
const bl = new BetterleaksScanner();
|
|
397
|
+
const result = await bl.scanFile(filePath);
|
|
398
398
|
return result.matches.length > 0 ? [result] : [];
|
|
399
399
|
}
|
|
400
400
|
catch (e) {
|
|
401
|
-
console.error(fmt.warning("
|
|
401
|
+
console.error(fmt.warning("Betterleaks scan failed, falling back to patterns"));
|
|
402
402
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
403
403
|
const result = scanner.scanFile(filePath);
|
|
404
404
|
return result.matches.length > 0 ? [result] : [];
|
|
@@ -414,13 +414,13 @@ async function scanFile(filePath, engine, scanCfg) {
|
|
|
414
414
|
* Scan a directory with selected engine
|
|
415
415
|
*/
|
|
416
416
|
async function scanDirectory(dirPath, engine, scanCfg, history) {
|
|
417
|
-
if (engine === "
|
|
417
|
+
if (engine === "betterleaks") {
|
|
418
418
|
try {
|
|
419
|
-
const
|
|
420
|
-
return await
|
|
419
|
+
const bl = new BetterleaksScanner();
|
|
420
|
+
return await bl.scanDirectory(dirPath, { useGit: history ?? false });
|
|
421
421
|
}
|
|
422
422
|
catch (e) {
|
|
423
|
-
console.error(fmt.warning("
|
|
423
|
+
console.error(fmt.warning("Betterleaks scan failed, falling back to patterns"));
|
|
424
424
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
425
425
|
return scanner.scanDirectory(dirPath, { excludePaths: scanCfg?.excludePaths });
|
|
426
426
|
}
|
|
@@ -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
|
+
}
|
|
@@ -7,17 +7,28 @@ import path from "path";
|
|
|
7
7
|
import os from "os";
|
|
8
8
|
import yaml from "js-yaml";
|
|
9
9
|
import { fmt } from "../../utils/formatter.js";
|
|
10
|
-
async function
|
|
10
|
+
async function checkBetterleaks() {
|
|
11
11
|
const binaryManager = new BinaryManager();
|
|
12
|
-
const name = "
|
|
12
|
+
const name = "Betterleaks";
|
|
13
13
|
// Check PATH first (e.g. Homebrew), then fall back to ~/.rafter/bin
|
|
14
|
-
const pathBinary = binaryManager.
|
|
15
|
-
const hasBinary = pathBinary !== null || binaryManager.
|
|
14
|
+
const pathBinary = binaryManager.findBetterleaksOnPath();
|
|
15
|
+
const hasBinary = pathBinary !== null || binaryManager.isBetterleaksInstalled();
|
|
16
16
|
if (!hasBinary) {
|
|
17
|
-
|
|
17
|
+
// Soft-degrade if a legacy gitleaks install is still present — the user
|
|
18
|
+
// upgraded rafter but hasn't rerun `agent init --with-betterleaks` yet.
|
|
19
|
+
const legacy = binaryManager.findLegacyGitleaks();
|
|
20
|
+
if (legacy) {
|
|
21
|
+
return {
|
|
22
|
+
name,
|
|
23
|
+
passed: false,
|
|
24
|
+
optional: true,
|
|
25
|
+
detail: `Not installed; found legacy gitleaks at ${legacy}. Run: rafter agent update-betterleaks`,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return { name, passed: false, detail: `Not found on PATH or at ${binaryManager.getBetterleaksPath()}` };
|
|
18
29
|
}
|
|
19
|
-
const binaryPath = pathBinary ?? binaryManager.
|
|
20
|
-
const { ok, stdout, stderr } = await binaryManager.
|
|
30
|
+
const binaryPath = pathBinary ?? binaryManager.getBetterleaksPath();
|
|
31
|
+
const { ok, stdout, stderr } = await binaryManager.verifyBetterleaksVerbose(binaryPath);
|
|
21
32
|
if (!ok) {
|
|
22
33
|
const diag = await binaryManager.collectBinaryDiagnostics(binaryPath);
|
|
23
34
|
return { name, passed: false, detail: `Binary found at ${binaryPath} but failed to execute\n${stdout ? ` stdout: ${stdout}\n` : ""}${stderr ? ` stderr: ${stderr}\n` : ""}${diag}` };
|
|
@@ -329,7 +340,7 @@ export function createVerifyCommand() {
|
|
|
329
340
|
}
|
|
330
341
|
const results = [
|
|
331
342
|
checkConfig(),
|
|
332
|
-
await
|
|
343
|
+
await checkBetterleaks(),
|
|
333
344
|
checkClaudeCode(),
|
|
334
345
|
checkOpenClaw(),
|
|
335
346
|
checkCodex(),
|