@rafter-security/cli 0.8.3 → 0.8.4
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/components.js +57 -0
- package/dist/commands/agent/init.js +75 -1
- package/dist/commands/agent/scan.js +93 -5
- package/dist/commands/agent/status.js +130 -8
- package/dist/commands/agent/verify.js +29 -0
- package/dist/core/policy-loader.js +45 -4
- package/dist/scanners/secret-patterns.js +7 -0
- package/package.json +1 -1
- package/resources/rafter-security-skill.md +1 -1
|
@@ -795,6 +795,62 @@ function continueMcp() {
|
|
|
795
795
|
},
|
|
796
796
|
};
|
|
797
797
|
}
|
|
798
|
+
/**
|
|
799
|
+
* Hermes MCP server entry (~/.hermes/config.yaml).
|
|
800
|
+
*
|
|
801
|
+
* Hermes uses a YAML config with a snake_case `mcp_servers:` block (unlike the
|
|
802
|
+
* camelCase `mcpServers` of Cursor/Windsurf/Claude Code). Per-server schema is
|
|
803
|
+
* {command, args, env}. MCP-only v0 — hooks deferred pending confirmation
|
|
804
|
+
* Hermes exposes a hook surface (sable-gyw).
|
|
805
|
+
*/
|
|
806
|
+
function hermesMcp() {
|
|
807
|
+
const home = os.homedir();
|
|
808
|
+
const configPath = path.join(home, ".hermes", "config.yaml");
|
|
809
|
+
const readYaml = () => {
|
|
810
|
+
if (!fs.existsSync(configPath))
|
|
811
|
+
return {};
|
|
812
|
+
try {
|
|
813
|
+
const loaded = yaml.load(fs.readFileSync(configPath, "utf-8"));
|
|
814
|
+
if (loaded && typeof loaded === "object" && !Array.isArray(loaded)) {
|
|
815
|
+
return loaded;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
catch { /* unparseable — treat as empty */ }
|
|
819
|
+
return {};
|
|
820
|
+
};
|
|
821
|
+
return {
|
|
822
|
+
id: "hermes.mcp",
|
|
823
|
+
platform: "hermes",
|
|
824
|
+
kind: "mcp",
|
|
825
|
+
description: "Hermes MCP server entry (~/.hermes/config.yaml)",
|
|
826
|
+
detectDir: path.join(home, ".hermes"),
|
|
827
|
+
path: configPath,
|
|
828
|
+
isInstalled: () => {
|
|
829
|
+
const servers = readYaml().mcp_servers;
|
|
830
|
+
return !!(servers && typeof servers === "object" && !Array.isArray(servers) && servers.rafter);
|
|
831
|
+
},
|
|
832
|
+
install: () => {
|
|
833
|
+
const dir = path.join(home, ".hermes");
|
|
834
|
+
if (!fs.existsSync(dir))
|
|
835
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
836
|
+
const cfg = readYaml();
|
|
837
|
+
if (!cfg.mcp_servers || typeof cfg.mcp_servers !== "object" || Array.isArray(cfg.mcp_servers)) {
|
|
838
|
+
cfg.mcp_servers = {};
|
|
839
|
+
}
|
|
840
|
+
cfg.mcp_servers.rafter = { ...RAFTER_MCP_ENTRY };
|
|
841
|
+
fs.writeFileSync(configPath, yaml.dump(cfg), "utf-8");
|
|
842
|
+
},
|
|
843
|
+
uninstall: () => {
|
|
844
|
+
if (!fs.existsSync(configPath))
|
|
845
|
+
return;
|
|
846
|
+
const cfg = readYaml();
|
|
847
|
+
const servers = cfg.mcp_servers;
|
|
848
|
+
if (servers && typeof servers === "object" && !Array.isArray(servers) && removeKey(servers, "rafter")) {
|
|
849
|
+
fs.writeFileSync(configPath, yaml.dump(cfg), "utf-8");
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
};
|
|
853
|
+
}
|
|
798
854
|
/**
|
|
799
855
|
* Aider read-only context: writes RAFTER.md and adds it to .aider.conf.yml `read:`.
|
|
800
856
|
*
|
|
@@ -942,6 +998,7 @@ export function getComponentRegistry() {
|
|
|
942
998
|
continueRules(),
|
|
943
999
|
continueMcp(),
|
|
944
1000
|
aiderRead(),
|
|
1001
|
+
hermesMcp(),
|
|
945
1002
|
openclawSkill(),
|
|
946
1003
|
];
|
|
947
1004
|
}
|
|
@@ -133,6 +133,11 @@ function printDryRunPlan(plan) {
|
|
|
133
133
|
W(path.join(plan.root, "RAFTER.md"), "rafter:start/end marker block");
|
|
134
134
|
W(path.join(plan.root, ".aider.conf.yml"), "appends RAFTER.md to read: list; strips legacy mcp-server-command line");
|
|
135
135
|
}
|
|
136
|
+
if (plan.wantHermes) {
|
|
137
|
+
console.log();
|
|
138
|
+
console.log("Hermes (--with-hermes):");
|
|
139
|
+
W(path.join(plan.root, ".hermes", "config.yaml"), "mcp_servers.rafter entry merged into existing YAML");
|
|
140
|
+
}
|
|
136
141
|
if (plan.wantOpenClaw) {
|
|
137
142
|
console.log();
|
|
138
143
|
console.log("OpenClaw (--with-openclaw):");
|
|
@@ -718,6 +723,46 @@ function installContinueDevMcp(root) {
|
|
|
718
723
|
*
|
|
719
724
|
* Returns true on success.
|
|
720
725
|
*/
|
|
726
|
+
/**
|
|
727
|
+
* Install MCP server config for Hermes (<root>/.hermes/config.yaml).
|
|
728
|
+
*
|
|
729
|
+
* Hermes uses a YAML config with an `mcp_servers:` block (snake_case, unlike
|
|
730
|
+
* Cursor/Windsurf/Claude Code which use `mcpServers` camelCase). Schema per
|
|
731
|
+
* server is {command, args, env}. We use js-yaml (already a dep, used by
|
|
732
|
+
* installAiderRead and elsewhere) to merge in the rafter entry while
|
|
733
|
+
* preserving any existing servers.
|
|
734
|
+
*
|
|
735
|
+
* Hooks (preToolUse/postToolUse equivalents) deferred to a follow-on bead
|
|
736
|
+
* pending confirmation Hermes exposes a hook surface — landing MCP-only as
|
|
737
|
+
* v0 mirrors how Gemini and Continue.dev were initially shipped.
|
|
738
|
+
*/
|
|
739
|
+
function installHermesMcp(root) {
|
|
740
|
+
const hermesDir = path.join(root, ".hermes");
|
|
741
|
+
const configPath = path.join(hermesDir, "config.yaml");
|
|
742
|
+
if (!fs.existsSync(hermesDir)) {
|
|
743
|
+
fs.mkdirSync(hermesDir, { recursive: true });
|
|
744
|
+
}
|
|
745
|
+
let config = {};
|
|
746
|
+
if (fs.existsSync(configPath)) {
|
|
747
|
+
const raw = fs.readFileSync(configPath, "utf-8");
|
|
748
|
+
try {
|
|
749
|
+
const loaded = yaml.load(raw);
|
|
750
|
+
if (loaded && typeof loaded === "object" && !Array.isArray(loaded)) {
|
|
751
|
+
config = loaded;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
catch {
|
|
755
|
+
console.log(fmt.warning(`Existing Hermes config.yaml was not valid YAML, creating new one`));
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
if (!config.mcp_servers || typeof config.mcp_servers !== "object" || Array.isArray(config.mcp_servers)) {
|
|
759
|
+
config.mcp_servers = {};
|
|
760
|
+
}
|
|
761
|
+
config.mcp_servers.rafter = { ...RAFTER_MCP_ENTRY };
|
|
762
|
+
fs.writeFileSync(configPath, yaml.dump(config), "utf-8");
|
|
763
|
+
console.log(fmt.success(`Installed Rafter MCP server to ${configPath}`));
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
721
766
|
function installAiderRead(root) {
|
|
722
767
|
const rafterMdPath = path.join(root, "RAFTER.md");
|
|
723
768
|
const configPath = path.join(root, ".aider.conf.yml");
|
|
@@ -901,6 +946,7 @@ export function createInitCommand() {
|
|
|
901
946
|
.option("--with-cursor", "Install Cursor integration")
|
|
902
947
|
.option("--with-windsurf", "Install Windsurf integration")
|
|
903
948
|
.option("--with-continue", "Install Continue.dev integration")
|
|
949
|
+
.option("--with-hermes", "Install Hermes integration")
|
|
904
950
|
.option("--with-betterleaks", "Download and install Betterleaks binary")
|
|
905
951
|
.option("--all", "Install all detected integrations and download Betterleaks")
|
|
906
952
|
.option("-i, --interactive", "Guided setup — prompts for each detected integration")
|
|
@@ -931,6 +977,7 @@ export function createInitCommand() {
|
|
|
931
977
|
const hasWindsurf = scope === "user" && fs.existsSync(path.join(os.homedir(), ".codeium", "windsurf"));
|
|
932
978
|
const hasContinueDev = scope === "user" && fs.existsSync(path.join(os.homedir(), ".continue"));
|
|
933
979
|
const hasAider = scope === "user" && fs.existsSync(path.join(os.homedir(), ".aider.conf.yml"));
|
|
980
|
+
const hasHermes = scope === "user" && fs.existsSync(path.join(os.homedir(), ".hermes"));
|
|
934
981
|
// Resolve opt-in flags (--all enables all detected, --interactive prompts).
|
|
935
982
|
// In --local scope, --all is restricted to platforms that have a project-local
|
|
936
983
|
// config story (claudeCode, codex, gemini, cursor). The rest require user scope.
|
|
@@ -953,6 +1000,10 @@ export function createInitCommand() {
|
|
|
953
1000
|
// Aider can install at --local scope (writes RAFTER.md + .aider.conf.yml
|
|
954
1001
|
// in cwd) since rf-du2o.
|
|
955
1002
|
let wantAider = opts.withAider || opts.all;
|
|
1003
|
+
// Hermes: MCP-only v0 (no hooks confirmed yet). User scope only — Hermes
|
|
1004
|
+
// reads ~/.hermes/config.yaml; the project-local install story isn't
|
|
1005
|
+
// established. Excluded from --all in --local for the same reason.
|
|
1006
|
+
let wantHermes = opts.withHermes || (opts.all && !opts.local);
|
|
956
1007
|
let wantBetterleaks = opts.withBetterleaks || (opts.all && !opts.local);
|
|
957
1008
|
// Interactive mode: prompt for each detected integration
|
|
958
1009
|
if (opts.interactive && !opts.all) {
|
|
@@ -975,6 +1026,8 @@ export function createInitCommand() {
|
|
|
975
1026
|
wantContinue = await askYesNo("Install Continue.dev MCP server?");
|
|
976
1027
|
if (hasAider && !wantAider)
|
|
977
1028
|
wantAider = await askYesNo("Install Aider MCP server?");
|
|
1029
|
+
if (hasHermes && !wantHermes)
|
|
1030
|
+
wantHermes = await askYesNo("Install Hermes MCP server?");
|
|
978
1031
|
if (!wantBetterleaks)
|
|
979
1032
|
wantBetterleaks = await askYesNo("Download Betterleaks binary (enhanced scanning)?");
|
|
980
1033
|
console.log();
|
|
@@ -997,6 +1050,8 @@ export function createInitCommand() {
|
|
|
997
1050
|
detected.push("Continue.dev");
|
|
998
1051
|
if (hasAider)
|
|
999
1052
|
detected.push("Aider");
|
|
1053
|
+
if (hasHermes)
|
|
1054
|
+
detected.push("Hermes");
|
|
1000
1055
|
if (detected.length > 0) {
|
|
1001
1056
|
console.log(fmt.info(`Detected environments: ${detected.join(", ")}`));
|
|
1002
1057
|
}
|
|
@@ -1022,6 +1077,8 @@ export function createInitCommand() {
|
|
|
1022
1077
|
console.log(fmt.warning("Continue.dev requested but not detected (~/.continue not found)"));
|
|
1023
1078
|
if (wantAider && !hasAider)
|
|
1024
1079
|
console.log(fmt.warning("Aider requested but not detected (~/.aider.conf.yml not found)"));
|
|
1080
|
+
if (wantHermes && !hasHermes)
|
|
1081
|
+
console.log(fmt.warning("Hermes requested but not detected (~/.hermes not found)"));
|
|
1025
1082
|
}
|
|
1026
1083
|
// --dry-run: print every file path the command would touch, then
|
|
1027
1084
|
// exit before any filesystem write happens (rf-hrtd). The plan is
|
|
@@ -1039,6 +1096,7 @@ export function createInitCommand() {
|
|
|
1039
1096
|
wantWindsurf: wantWindsurf && (hasWindsurf || opts.local),
|
|
1040
1097
|
wantContinue: wantContinue && (hasContinueDev || opts.local),
|
|
1041
1098
|
wantAider: wantAider && (hasAider || opts.local),
|
|
1099
|
+
wantHermes: wantHermes && hasHermes,
|
|
1042
1100
|
wantBetterleaks,
|
|
1043
1101
|
riskLevel: opts.riskLevel,
|
|
1044
1102
|
});
|
|
@@ -1138,7 +1196,7 @@ export function createInitCommand() {
|
|
|
1138
1196
|
const result = await skillManager.installRafterSkillVerbose();
|
|
1139
1197
|
openclawOk = result.ok;
|
|
1140
1198
|
if (result.ok) {
|
|
1141
|
-
console.log(fmt.success(
|
|
1199
|
+
console.log(fmt.success(`Installed Rafter Security skill to ${result.destPath}`));
|
|
1142
1200
|
manager.set("agent.environments.openclaw.enabled", true);
|
|
1143
1201
|
}
|
|
1144
1202
|
else {
|
|
@@ -1290,6 +1348,20 @@ export function createInitCommand() {
|
|
|
1290
1348
|
console.error(fmt.error(`Failed to install Aider integration: ${e}`));
|
|
1291
1349
|
}
|
|
1292
1350
|
}
|
|
1351
|
+
// Install Hermes integration if opted in (sable-gyw).
|
|
1352
|
+
// User scope only — Hermes reads ~/.hermes/config.yaml. MCP-only v0;
|
|
1353
|
+
// hooks deferred pending confirmation Hermes exposes a hook surface.
|
|
1354
|
+
let hermesOk = false;
|
|
1355
|
+
if (wantHermes && hasHermes) {
|
|
1356
|
+
try {
|
|
1357
|
+
hermesOk = installHermesMcp(root);
|
|
1358
|
+
if (hermesOk)
|
|
1359
|
+
manager.set("agent.environments.hermes.enabled", true);
|
|
1360
|
+
}
|
|
1361
|
+
catch (e) {
|
|
1362
|
+
console.error(fmt.error(`Failed to install Hermes integration: ${e}`));
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1293
1365
|
// Install global instruction files for platforms that support them.
|
|
1294
1366
|
// Cursor is intentionally absent — Cursor uses per-skill rules + the
|
|
1295
1367
|
// rafter sub-agent installed in the Cursor branch above (rf-svn3).
|
|
@@ -1348,6 +1420,8 @@ export function createInitCommand() {
|
|
|
1348
1420
|
console.log(" rafter agent init --with-continue # Continue.dev only");
|
|
1349
1421
|
if (hasAider)
|
|
1350
1422
|
console.log(" rafter agent init --with-aider # Aider only");
|
|
1423
|
+
if (hasHermes)
|
|
1424
|
+
console.log(" rafter agent init --with-hermes # Hermes only");
|
|
1351
1425
|
}
|
|
1352
1426
|
else {
|
|
1353
1427
|
console.log("No agent environments detected. Install an agent tool and re-run with --with-<tool>.");
|
|
@@ -10,6 +10,7 @@ import os from "os";
|
|
|
10
10
|
import path from "path";
|
|
11
11
|
import { fmt } from "../../utils/formatter.js";
|
|
12
12
|
import { createRequire } from "module";
|
|
13
|
+
import { minimatch } from "minimatch";
|
|
13
14
|
const _require = createRequire(import.meta.url);
|
|
14
15
|
const { version: CLI_VERSION } = _require("../../../package.json");
|
|
15
16
|
function loadBaselineEntries() {
|
|
@@ -24,6 +25,72 @@ function loadBaselineEntries() {
|
|
|
24
25
|
return [];
|
|
25
26
|
}
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Does `relPath` (forward-slash relative path) match an `exclude_paths`
|
|
30
|
+
* entry from `.rafter.yml`?
|
|
31
|
+
*
|
|
32
|
+
* sable-yz0 — single source of truth for `scan.exclude_paths` semantics
|
|
33
|
+
* across both scan engines and the staged / diff modes. Rules (any one
|
|
34
|
+
* matches → exclude):
|
|
35
|
+
*
|
|
36
|
+
* 1. Exact match: `relPath === pattern` (the pattern is the full file path)
|
|
37
|
+
* 2. Directory-prefix: `relPath` starts with `pattern + "/"` (the pattern
|
|
38
|
+
* is a directory; everything under it is excluded). Trailing "/" on
|
|
39
|
+
* the pattern is ignored — `scripts/` and `scripts` mean the same.
|
|
40
|
+
* 3. Dir-name anywhere: any segment of `relPath` equals `pattern` (preserves
|
|
41
|
+
* the historical RegexScanner walker behavior — `node_modules` skips
|
|
42
|
+
* `pkg/foo/node_modules/...` too).
|
|
43
|
+
* 4. Glob: if `pattern` contains `* ? [`, run it through minimatch with
|
|
44
|
+
* `dot:true, matchBase:true`. Same defaults as `policyIgnoreToSuppressions`.
|
|
45
|
+
*/
|
|
46
|
+
function pathMatchesExcludePattern(relPath, pattern) {
|
|
47
|
+
const rel = relPath.replace(/\\/g, "/");
|
|
48
|
+
const p = pattern.replace(/\\/g, "/").replace(/\/+$/, "");
|
|
49
|
+
if (!p)
|
|
50
|
+
return false;
|
|
51
|
+
if (rel === p)
|
|
52
|
+
return true;
|
|
53
|
+
if (rel.startsWith(p + "/"))
|
|
54
|
+
return true;
|
|
55
|
+
if (rel.split("/").includes(p))
|
|
56
|
+
return true;
|
|
57
|
+
if (/[*?[]/.test(p)) {
|
|
58
|
+
if (minimatch(rel, p, { dot: true, matchBase: true }))
|
|
59
|
+
return true;
|
|
60
|
+
// Auto-anchor relative globs so `foo/**` matches anywhere in the tree.
|
|
61
|
+
if (!p.startsWith("/") && !p.startsWith("**")) {
|
|
62
|
+
if (minimatch(rel, "**/" + p, { dot: true }))
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Strip findings whose file path matches any `scan.exclude_paths` entry.
|
|
70
|
+
* Called at the `scanDirectory` chokepoint so both the betterleaks and
|
|
71
|
+
* patterns engines get the same filter (and the same semantics).
|
|
72
|
+
*
|
|
73
|
+
* `scanRoot` is the absolute directory the scan was rooted at; finding
|
|
74
|
+
* paths are converted to scan-root-relative before matching, so users
|
|
75
|
+
* write `components/common/Mermaid.tsx` in their `.rafter.yml`, not the
|
|
76
|
+
* absolute path on the CI runner.
|
|
77
|
+
*/
|
|
78
|
+
function applyExcludePaths(results, excludePaths, scanRoot) {
|
|
79
|
+
if (!excludePaths || excludePaths.length === 0)
|
|
80
|
+
return results;
|
|
81
|
+
const root = path.resolve(scanRoot).replace(/\\/g, "/");
|
|
82
|
+
return results.filter((r) => {
|
|
83
|
+
const abs = path.resolve(r.file).replace(/\\/g, "/");
|
|
84
|
+
let rel = abs;
|
|
85
|
+
if (abs === root) {
|
|
86
|
+
rel = "";
|
|
87
|
+
}
|
|
88
|
+
else if (abs.startsWith(root + "/")) {
|
|
89
|
+
rel = abs.slice(root.length + 1);
|
|
90
|
+
}
|
|
91
|
+
return !excludePaths.some((pat) => pathMatchesExcludePattern(rel, pat));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
27
94
|
function applyBaseline(results, entries) {
|
|
28
95
|
if (entries.length === 0)
|
|
29
96
|
return results;
|
|
@@ -305,7 +372,11 @@ async function scanDiffFiles(ref, opts, scanCfg, baselineEntries = [], scanPath,
|
|
|
305
372
|
const results = await scanFile(filePath, engine, scanCfg);
|
|
306
373
|
allResults.push(...results);
|
|
307
374
|
}
|
|
308
|
-
|
|
375
|
+
// sable-yz0 — honor scan.exclude_paths in --diff mode too (was previously
|
|
376
|
+
// dropped). Use the repo root as scanRoot so user-relative paths in
|
|
377
|
+
// .rafter.yml resolve consistently with the directory-scan behavior.
|
|
378
|
+
const filteredDiff = applyExcludePaths(allResults, scanCfg?.excludePaths, repoRoot);
|
|
379
|
+
outputScanResults(applyBaseline(filteredDiff, baselineEntries), opts, `files changed since ${ref}`, true, suppressions);
|
|
309
380
|
}
|
|
310
381
|
catch (error) {
|
|
311
382
|
if (error.status === 128) {
|
|
@@ -351,7 +422,9 @@ async function scanStagedFiles(opts, scanCfg, baselineEntries = [], scanPath, su
|
|
|
351
422
|
const results = await scanFile(filePath, engine, scanCfg);
|
|
352
423
|
allResults.push(...results);
|
|
353
424
|
}
|
|
354
|
-
|
|
425
|
+
// sable-yz0 — honor scan.exclude_paths in --staged mode too.
|
|
426
|
+
const filteredStaged = applyExcludePaths(allResults, scanCfg?.excludePaths, repoRoot);
|
|
427
|
+
outputScanResults(applyBaseline(filteredStaged, baselineEntries), opts, "staged files", true, suppressions);
|
|
355
428
|
}
|
|
356
429
|
catch (error) {
|
|
357
430
|
if (error.status === 128) {
|
|
@@ -418,15 +491,16 @@ async function scanDirectory(dirPath, engine, scanCfg, history, respectGitignore
|
|
|
418
491
|
// respectGitignore default is true. The patterns engine honors it via
|
|
419
492
|
// RegexScanner.scanDirectory; betterleaks honors it natively (gitleaks
|
|
420
493
|
// ancestry — reads .gitignore unless --no-git is set).
|
|
494
|
+
let results;
|
|
421
495
|
if (engine === "betterleaks") {
|
|
422
496
|
try {
|
|
423
497
|
const bl = new BetterleaksScanner();
|
|
424
|
-
|
|
498
|
+
results = await bl.scanDirectory(dirPath, { useGit: history ?? false });
|
|
425
499
|
}
|
|
426
500
|
catch (e) {
|
|
427
501
|
console.error(fmt.warning("Betterleaks scan failed, falling back to patterns"));
|
|
428
502
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
429
|
-
|
|
503
|
+
results = scanner.scanDirectory(dirPath, {
|
|
430
504
|
excludePaths: scanCfg?.excludePaths,
|
|
431
505
|
respectGitignore,
|
|
432
506
|
});
|
|
@@ -434,11 +508,25 @@ async function scanDirectory(dirPath, engine, scanCfg, history, respectGitignore
|
|
|
434
508
|
}
|
|
435
509
|
else {
|
|
436
510
|
const scanner = new RegexScanner(scanCfg?.customPatterns);
|
|
437
|
-
|
|
511
|
+
results = scanner.scanDirectory(dirPath, {
|
|
438
512
|
excludePaths: scanCfg?.excludePaths,
|
|
439
513
|
respectGitignore,
|
|
440
514
|
});
|
|
441
515
|
}
|
|
516
|
+
// sable-yz0 — post-filter by `.rafter.yml scan.exclude_paths`. Two bugs
|
|
517
|
+
// motivated this chokepoint:
|
|
518
|
+
// 1. The betterleaks happy-path above never received excludePaths,
|
|
519
|
+
// so `auto`-engine scans (the default when betterleaks is on disk)
|
|
520
|
+
// silently ignored user policy.
|
|
521
|
+
// 2. The patterns engine's walker only matches `excludePaths` entries
|
|
522
|
+
// against single directory NAMES (`entry.name`), so a customer
|
|
523
|
+
// writing `components/common/Mermaid.tsx` (file path) or
|
|
524
|
+
// `supabase/migrations/foo.sql` (multi-segment path) got no
|
|
525
|
+
// filtering at all.
|
|
526
|
+
// The post-filter applies the same path-aware semantics to BOTH engines
|
|
527
|
+
// (exact path, directory-prefix, dir-name-anywhere, glob via minimatch),
|
|
528
|
+
// catching whatever leaks through the walker-level optimization.
|
|
529
|
+
return applyExcludePaths(results, scanCfg?.excludePaths, dirPath);
|
|
442
530
|
}
|
|
443
531
|
/**
|
|
444
532
|
* Watch a path for changes and re-scan on each change
|
|
@@ -3,21 +3,28 @@ import fs from "fs";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import os from "os";
|
|
5
5
|
import { execSync } from "child_process";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
6
7
|
import { getRafterDir, getAuditLogPath, getBinDir } from "../../core/config-defaults.js";
|
|
7
8
|
import { AuditLogger } from "../../core/audit-logger.js";
|
|
8
9
|
import { ConfigManager } from "../../core/config-manager.js";
|
|
9
10
|
import { BinaryManager } from "../../utils/binary-manager.js";
|
|
11
|
+
import { SkillManager } from "../../utils/skill-manager.js";
|
|
10
12
|
export function createStatusCommand() {
|
|
11
13
|
return new Command("status")
|
|
12
14
|
.description("Show agent security status dashboard")
|
|
13
|
-
.
|
|
15
|
+
.option("--json", "Output status as JSON")
|
|
16
|
+
.action(async (opts) => {
|
|
14
17
|
const rafterDir = getRafterDir();
|
|
15
18
|
const auditPath = getAuditLogPath();
|
|
16
19
|
const home = os.homedir();
|
|
20
|
+
const configPath = path.join(rafterDir, "config.json");
|
|
21
|
+
if (opts.json) {
|
|
22
|
+
console.log(JSON.stringify(buildStatusJson(home, configPath, auditPath), null, 2));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
17
25
|
console.log("Rafter Agent Status");
|
|
18
26
|
console.log("=".repeat(50));
|
|
19
27
|
// --- Config ---
|
|
20
|
-
const configPath = path.join(rafterDir, "config.json");
|
|
21
28
|
if (fs.existsSync(configPath)) {
|
|
22
29
|
try {
|
|
23
30
|
const cfg = new ConfigManager().load();
|
|
@@ -86,13 +93,21 @@ export function createStatusCommand() {
|
|
|
86
93
|
console.log(`PreToolUse: ${pretoolOk ? "installed" : "not installed — run: rafter agent init --with-claude-code"}`);
|
|
87
94
|
console.log(`PostToolUse: ${posttoolOk ? "installed" : "not installed — run: rafter agent init --with-claude-code"}`);
|
|
88
95
|
// --- OpenClaw skill ---
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
// rf-zgwj moved the skill to the canonical ClawHub workspace path
|
|
97
|
+
// (~/.openclaw/workspace/skills/rafter-security/SKILL.md) and strips the
|
|
98
|
+
// legacy flat file. Detect via SkillManager so this matches `agent verify`
|
|
99
|
+
// and the installer — checking the legacy path here is a false negative.
|
|
100
|
+
const skillManager = new SkillManager();
|
|
101
|
+
if (skillManager.isRafterSkillInstalled()) {
|
|
102
|
+
console.log(`OpenClaw: skill installed (${skillManager.getRafterSkillPath()})`);
|
|
93
103
|
}
|
|
94
|
-
else if (
|
|
95
|
-
|
|
104
|
+
else if (skillManager.isOpenClawInstalled()) {
|
|
105
|
+
if (skillManager.hasLegacyRafterSkill()) {
|
|
106
|
+
console.log(`OpenClaw: legacy skill at ${skillManager.getLegacyRafterSkillPath()} (not loaded) — run: rafter agent init --with-openclaw to migrate`);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.log("OpenClaw: detected but skill missing — run: rafter agent init --with-openclaw");
|
|
110
|
+
}
|
|
96
111
|
}
|
|
97
112
|
else {
|
|
98
113
|
console.log("OpenClaw: not detected (optional)");
|
|
@@ -115,6 +130,7 @@ export function createStatusCommand() {
|
|
|
115
130
|
{ name: "Cursor", flag: "--with-cursor", configDir: path.join(home, ".cursor"), configFile: path.join(home, ".cursor", "mcp.json"), needle: "rafter" },
|
|
116
131
|
{ name: "Windsurf", flag: "--with-windsurf", configDir: path.join(home, ".codeium", "windsurf"), configFile: path.join(home, ".codeium", "windsurf", "mcp_config.json"), needle: "rafter" },
|
|
117
132
|
{ name: "Continue.dev", flag: "--with-continue", configDir: path.join(home, ".continue"), configFile: path.join(home, ".continue", "config.json"), needle: "rafter" },
|
|
133
|
+
{ name: "Hermes", flag: "--with-hermes", configDir: path.join(home, ".hermes"), configFile: path.join(home, ".hermes", "config.yaml"), needle: "rafter" },
|
|
118
134
|
];
|
|
119
135
|
for (const agent of mcpAgents) {
|
|
120
136
|
const label = `${agent.name}:`.padEnd(14);
|
|
@@ -183,3 +199,109 @@ export function createStatusCommand() {
|
|
|
183
199
|
console.log();
|
|
184
200
|
});
|
|
185
201
|
}
|
|
202
|
+
function buildStatusJson(home, configPath, auditPath) {
|
|
203
|
+
return {
|
|
204
|
+
installed: fs.existsSync(configPath),
|
|
205
|
+
version: getPkgVersion(),
|
|
206
|
+
agents_detected: detectAgents(home),
|
|
207
|
+
hooks_installed: detectGitHooks(home),
|
|
208
|
+
betterleaks_available: isBetterleaksAvailable(),
|
|
209
|
+
config_path: formatHomePath(configPath, home),
|
|
210
|
+
audit_log_path: formatHomePath(auditPath, home),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function detectAgents(home) {
|
|
214
|
+
const candidates = [
|
|
215
|
+
["claude-code", path.join(home, ".claude")],
|
|
216
|
+
["openclaw", path.join(home, ".openclaw")],
|
|
217
|
+
["codex", path.join(home, ".codex")],
|
|
218
|
+
["gemini", path.join(home, ".gemini")],
|
|
219
|
+
["cursor", path.join(home, ".cursor")],
|
|
220
|
+
["windsurf", path.join(home, ".codeium", "windsurf")],
|
|
221
|
+
["continue", path.join(home, ".continue")],
|
|
222
|
+
["aider", path.join(home, ".aider.conf.yml")],
|
|
223
|
+
["hermes", path.join(home, ".hermes")],
|
|
224
|
+
];
|
|
225
|
+
return candidates
|
|
226
|
+
.filter(([, p]) => fs.existsSync(p))
|
|
227
|
+
.map(([name]) => name);
|
|
228
|
+
}
|
|
229
|
+
function detectGitHooks(home) {
|
|
230
|
+
const hooks = new Set();
|
|
231
|
+
const specs = [
|
|
232
|
+
["pre-commit", "Rafter Security Pre-Commit Hook"],
|
|
233
|
+
["pre-push", "Rafter Security Pre-Push Hook"],
|
|
234
|
+
];
|
|
235
|
+
for (const [hookName, marker] of specs) {
|
|
236
|
+
const globalHook = path.join(home, ".rafter", "git-hooks", hookName);
|
|
237
|
+
if (fileContains(globalHook, marker))
|
|
238
|
+
hooks.add(hookName);
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
const gitDir = execSync("git rev-parse --git-dir", {
|
|
242
|
+
encoding: "utf-8",
|
|
243
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
244
|
+
timeout: 5000,
|
|
245
|
+
}).trim();
|
|
246
|
+
const hooksDir = path.resolve(gitDir, "hooks");
|
|
247
|
+
for (const [hookName, marker] of specs) {
|
|
248
|
+
if (fileContains(path.join(hooksDir, hookName), marker))
|
|
249
|
+
hooks.add(hookName);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
// Not in a git repository, or git unavailable.
|
|
254
|
+
}
|
|
255
|
+
return [...hooks].sort();
|
|
256
|
+
}
|
|
257
|
+
function isBetterleaksAvailable() {
|
|
258
|
+
const exeExt = process.platform === "win32" ? ".exe" : "";
|
|
259
|
+
const localBetterleaks = path.join(getBinDir(), `betterleaks${exeExt}`);
|
|
260
|
+
try {
|
|
261
|
+
execSync("betterleaks version", {
|
|
262
|
+
timeout: 5000,
|
|
263
|
+
encoding: "utf-8",
|
|
264
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
265
|
+
});
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
if (fs.existsSync(localBetterleaks))
|
|
270
|
+
return true;
|
|
271
|
+
return Boolean(new BinaryManager().findLegacyGitleaks());
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
function fileContains(filePath, needle) {
|
|
275
|
+
try {
|
|
276
|
+
return fs.readFileSync(filePath, "utf-8").includes(needle);
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function formatHomePath(filePath, home) {
|
|
283
|
+
const relative = path.relative(home, filePath);
|
|
284
|
+
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) {
|
|
285
|
+
return path.join("~", relative).replace(/\\/g, "/");
|
|
286
|
+
}
|
|
287
|
+
return filePath;
|
|
288
|
+
}
|
|
289
|
+
function getPkgVersion() {
|
|
290
|
+
try {
|
|
291
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
292
|
+
let dir = path.dirname(__filename);
|
|
293
|
+
for (let i = 0; i < 6; i++) {
|
|
294
|
+
const candidate = path.join(dir, "package.json");
|
|
295
|
+
if (fs.existsSync(candidate)) {
|
|
296
|
+
const pkg = JSON.parse(fs.readFileSync(candidate, "utf-8"));
|
|
297
|
+
if (pkg.version)
|
|
298
|
+
return pkg.version;
|
|
299
|
+
}
|
|
300
|
+
dir = path.dirname(dir);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
// fall through
|
|
305
|
+
}
|
|
306
|
+
return "unknown";
|
|
307
|
+
}
|
|
@@ -259,6 +259,34 @@ function checkAider() {
|
|
|
259
259
|
}
|
|
260
260
|
return { name, passed: true, detail: `RAFTER.md + read: entry in ${conf}` };
|
|
261
261
|
}
|
|
262
|
+
function checkHermes() {
|
|
263
|
+
// Hermes uses ~/.hermes/config.yaml with a snake_case `mcp_servers:` block
|
|
264
|
+
// (MCP-only v0 — no hook surface confirmed yet; sable-gyw).
|
|
265
|
+
const name = "Hermes";
|
|
266
|
+
const homeDir = os.homedir();
|
|
267
|
+
const hermesDir = path.join(homeDir, ".hermes");
|
|
268
|
+
if (!fs.existsSync(hermesDir)) {
|
|
269
|
+
return { name, passed: false, optional: true, detail: `Not detected — run 'rafter agent init --with-hermes' to enable` };
|
|
270
|
+
}
|
|
271
|
+
const configPath = path.join(hermesDir, "config.yaml");
|
|
272
|
+
if (!fs.existsSync(configPath)) {
|
|
273
|
+
return { name, passed: false, optional: true, detail: `Config not found: ${configPath} — run 'rafter agent init --with-hermes'` };
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
const loaded = yaml.load(fs.readFileSync(configPath, "utf-8"));
|
|
277
|
+
const servers = (loaded && typeof loaded === "object" && !Array.isArray(loaded))
|
|
278
|
+
? loaded.mcp_servers
|
|
279
|
+
: undefined;
|
|
280
|
+
const hasRafterMcp = servers && typeof servers === "object" && servers.rafter != null;
|
|
281
|
+
if (!hasRafterMcp) {
|
|
282
|
+
return { name, passed: false, optional: true, detail: "Rafter MCP server not configured — run 'rafter agent init --with-hermes'" };
|
|
283
|
+
}
|
|
284
|
+
return { name, passed: true, detail: "MCP server configured" };
|
|
285
|
+
}
|
|
286
|
+
catch (e) {
|
|
287
|
+
return { name, passed: false, optional: true, detail: `Cannot read config: ${e}` };
|
|
288
|
+
}
|
|
289
|
+
}
|
|
262
290
|
/**
|
|
263
291
|
* Probe the Claude Code hook integration end-to-end (rf-65zg).
|
|
264
292
|
*
|
|
@@ -349,6 +377,7 @@ export function createVerifyCommand() {
|
|
|
349
377
|
checkWindsurf(),
|
|
350
378
|
checkContinueDev(),
|
|
351
379
|
checkAider(),
|
|
380
|
+
checkHermes(),
|
|
352
381
|
];
|
|
353
382
|
if (opts.probe) {
|
|
354
383
|
// Only Claude Code has a probe today (rf-65zg). Codex/Cursor/Gemini
|
|
@@ -2,15 +2,36 @@ import fs from "fs";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { execSync } from "child_process";
|
|
4
4
|
import yaml from "js-yaml";
|
|
5
|
-
const POLICY_FILENAMES = [".rafter.yml", ".rafter.yaml"];
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
6
|
+
* Policy file candidates, in precedence order.
|
|
7
|
+
*
|
|
8
|
+
* sable-c1c — the cloud scanner (rafter-backend) reads `.rafter/config.yml`
|
|
9
|
+
* (subdir + `config.yml`), while the CLI canonical is `.rafter.yml`. To
|
|
10
|
+
* unbreak customers writing either shape, the CLI now reads both
|
|
11
|
+
* indefinitely. Precedence: canonical dotfile first; backend file is the
|
|
12
|
+
* fallback. If both are present, the dotfile wins (canonical).
|
|
13
|
+
*
|
|
14
|
+
* Schema compatibility is handled separately in `mapPolicy` — top-level
|
|
15
|
+
* `exclude_paths` / `custom_patterns` (backend flat shape) is accepted
|
|
16
|
+
* alongside `scan.exclude_paths` / `scan.custom_patterns` (CLI nested).
|
|
17
|
+
*/
|
|
18
|
+
const POLICY_FILE_CANDIDATES = [
|
|
19
|
+
".rafter.yml",
|
|
20
|
+
".rafter.yaml",
|
|
21
|
+
path.join(".rafter", "config.yml"),
|
|
22
|
+
path.join(".rafter", "config.yaml"),
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Find a policy file by walking from cwd up to git root.
|
|
26
|
+
*
|
|
27
|
+
* For each directory, check candidates in precedence order; the first hit
|
|
28
|
+
* wins. The walk only ascends — siblings are not considered.
|
|
8
29
|
*/
|
|
9
30
|
export function findPolicyFile() {
|
|
10
31
|
let dir = process.cwd();
|
|
11
32
|
const root = getGitRoot() || path.parse(dir).root;
|
|
12
33
|
while (true) {
|
|
13
|
-
for (const filename of
|
|
34
|
+
for (const filename of POLICY_FILE_CANDIDATES) {
|
|
14
35
|
const candidate = path.join(dir, filename);
|
|
15
36
|
if (fs.existsSync(candidate)) {
|
|
16
37
|
return candidate;
|
|
@@ -76,6 +97,22 @@ function mapPolicy(raw) {
|
|
|
76
97
|
}));
|
|
77
98
|
}
|
|
78
99
|
}
|
|
100
|
+
// sable-c1c — backend flat-shape compat. rafter-backend reads
|
|
101
|
+
// exclude_paths / custom_patterns at the top level (no `scan:` nesting),
|
|
102
|
+
// so customers writing the backend shape get the same behavior locally.
|
|
103
|
+
// Nested form takes precedence if both are present in the same file.
|
|
104
|
+
if (!policy.scan?.excludePaths && Array.isArray(raw.exclude_paths)) {
|
|
105
|
+
policy.scan = policy.scan || {};
|
|
106
|
+
policy.scan.excludePaths = raw.exclude_paths;
|
|
107
|
+
}
|
|
108
|
+
if (!policy.scan?.customPatterns && Array.isArray(raw.custom_patterns)) {
|
|
109
|
+
policy.scan = policy.scan || {};
|
|
110
|
+
policy.scan.customPatterns = raw.custom_patterns.map((p) => ({
|
|
111
|
+
name: p.name,
|
|
112
|
+
regex: p.regex,
|
|
113
|
+
severity: p.severity || "high",
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
79
116
|
if (Array.isArray(raw.ignore)) {
|
|
80
117
|
const rules = [];
|
|
81
118
|
for (const entry of raw.ignore) {
|
|
@@ -178,7 +215,11 @@ function deriveDocId(source, kind) {
|
|
|
178
215
|
const crypto = require("crypto");
|
|
179
216
|
return crypto.createHash("sha256").update(source).digest("hex").slice(0, 8);
|
|
180
217
|
}
|
|
181
|
-
const VALID_TOP_LEVEL_KEYS = new Set([
|
|
218
|
+
const VALID_TOP_LEVEL_KEYS = new Set([
|
|
219
|
+
"version", "risk_level", "command_policy", "scan", "ignore", "audit", "docs",
|
|
220
|
+
// sable-c1c — backend flat-shape compat keys.
|
|
221
|
+
"exclude_paths", "custom_patterns",
|
|
222
|
+
]);
|
|
182
223
|
const VALID_RISK_LEVELS = new Set(["minimal", "moderate", "aggressive"]);
|
|
183
224
|
const VALID_COMMAND_MODES = new Set(["allow-all", "approve-dangerous", "deny-list"]);
|
|
184
225
|
const VALID_LOG_LEVELS = new Set(["debug", "info", "warn", "error"]);
|
|
@@ -87,6 +87,13 @@ export const DEFAULT_SECRET_PATTERNS = [
|
|
|
87
87
|
severity: "critical",
|
|
88
88
|
description: "Twilio API Key detected"
|
|
89
89
|
},
|
|
90
|
+
// HashiCorp Vault
|
|
91
|
+
{
|
|
92
|
+
name: "HashiCorp Vault Token",
|
|
93
|
+
regex: "hvs\\.[a-zA-Z0-9_-]{90,}",
|
|
94
|
+
severity: "critical",
|
|
95
|
+
description: "HashiCorp Vault service token detected"
|
|
96
|
+
},
|
|
90
97
|
// Generic patterns
|
|
91
98
|
{
|
|
92
99
|
name: "Generic API Key",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: rafter-security
|
|
3
3
|
description: Security toolkit for AI workflows. Use when scanning code or repos for vulnerabilities, auditing third-party skills/MCPs/agent configs before installing, evaluating shell commands before running them, or generating secure design questions for new features. Provides `rafter run` (remote SAST + SCA, needs RAFTER_API_KEY), `rafter secrets` (offline secrets-only), `rafter agent exec --dry-run` (command-risk classification), and `rafter skill review`.
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.4
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|