@rafter-security/cli 0.8.9 → 0.9.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/dist/commands/agent/components.js +57 -1
- package/dist/commands/agent/init.js +100 -2
- package/dist/commands/agent/status.js +2 -0
- package/dist/commands/agent/verify.js +29 -0
- package/dist/commands/backend/run.js +18 -1
- package/dist/commands/hook/posttool.js +5 -0
- package/dist/commands/hook/pretool.js +5 -0
- package/dist/commands/scan/index.js +4 -0
- package/dist/core/command-interceptor.js +29 -3
- package/dist/core/risk-rules.js +14 -0
- package/dist/scanners/secret-patterns.js +7 -0
- package/dist/utils/git.js +63 -4
- package/package.json +4 -4
- package/resources/rafter-security-skill.md +1 -1
|
@@ -112,7 +112,9 @@ function claudeCodeHooks() {
|
|
|
112
112
|
delete settings.hooks.SessionStart;
|
|
113
113
|
}
|
|
114
114
|
settings.hooks.PreToolUse.push({ matcher: "Bash", hooks: [pre] }, { matcher: "Write|Edit", hooks: [pre] });
|
|
115
|
-
|
|
115
|
+
// Narrow to tools that produce scannable output (shell output + file
|
|
116
|
+
// writes); avoids firing posttool on every Read/MCP call (latency).
|
|
117
|
+
settings.hooks.PostToolUse.push({ matcher: "Bash|Write|Edit|MultiEdit", hooks: [post] });
|
|
116
118
|
writeJson(settingsPath, settings);
|
|
117
119
|
},
|
|
118
120
|
uninstall: () => {
|
|
@@ -851,6 +853,59 @@ function hermesMcp() {
|
|
|
851
853
|
},
|
|
852
854
|
};
|
|
853
855
|
}
|
|
856
|
+
/**
|
|
857
|
+
* OpenCode MCP server entry (~/.config/opencode/opencode.json).
|
|
858
|
+
*
|
|
859
|
+
* OpenCode's schema differs from Cursor/Windsurf: the block is `mcp` (not
|
|
860
|
+
* `mcpServers`), each local server carries `type: "local"`, and command + args
|
|
861
|
+
* are a single `command` array. Verified against
|
|
862
|
+
* https://opencode.ai/docs/mcp-servers/ (sable-l8e5).
|
|
863
|
+
*/
|
|
864
|
+
function openCodeMcp() {
|
|
865
|
+
const home = os.homedir();
|
|
866
|
+
const configPath = path.join(home, ".config", "opencode", "opencode.json");
|
|
867
|
+
const entry = {
|
|
868
|
+
type: "local",
|
|
869
|
+
command: [RAFTER_MCP_ENTRY.command, ...RAFTER_MCP_ENTRY.args],
|
|
870
|
+
enabled: true,
|
|
871
|
+
};
|
|
872
|
+
return {
|
|
873
|
+
id: "opencode.mcp",
|
|
874
|
+
platform: "opencode",
|
|
875
|
+
kind: "mcp",
|
|
876
|
+
description: "OpenCode MCP server entry (~/.config/opencode/opencode.json)",
|
|
877
|
+
detectDir: path.join(home, ".config", "opencode"),
|
|
878
|
+
path: configPath,
|
|
879
|
+
isInstalled: () => {
|
|
880
|
+
if (!fs.existsSync(configPath))
|
|
881
|
+
return false;
|
|
882
|
+
const cfg = readJson(configPath);
|
|
883
|
+
return !!cfg.mcp?.rafter;
|
|
884
|
+
},
|
|
885
|
+
install: () => {
|
|
886
|
+
const dir = path.join(home, ".config", "opencode");
|
|
887
|
+
if (!fs.existsSync(dir))
|
|
888
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
889
|
+
let cfg = fs.existsSync(configPath) ? readJson(configPath) : {};
|
|
890
|
+
// Guard against valid-but-non-object top-level JSON (array/string/number).
|
|
891
|
+
if (!cfg || typeof cfg !== "object" || Array.isArray(cfg))
|
|
892
|
+
cfg = {};
|
|
893
|
+
if (!cfg.$schema)
|
|
894
|
+
cfg.$schema = "https://opencode.ai/config.json";
|
|
895
|
+
if (!cfg.mcp || typeof cfg.mcp !== "object" || Array.isArray(cfg.mcp))
|
|
896
|
+
cfg.mcp = {};
|
|
897
|
+
cfg.mcp.rafter = { ...entry };
|
|
898
|
+
writeJson(configPath, cfg);
|
|
899
|
+
},
|
|
900
|
+
uninstall: () => {
|
|
901
|
+
if (!fs.existsSync(configPath))
|
|
902
|
+
return;
|
|
903
|
+
const cfg = readJson(configPath);
|
|
904
|
+
if (removeKey(cfg.mcp, "rafter"))
|
|
905
|
+
writeJson(configPath, cfg);
|
|
906
|
+
},
|
|
907
|
+
};
|
|
908
|
+
}
|
|
854
909
|
/**
|
|
855
910
|
* Aider read-only context: writes RAFTER.md and adds it to .aider.conf.yml `read:`.
|
|
856
911
|
*
|
|
@@ -999,6 +1054,7 @@ export function getComponentRegistry() {
|
|
|
999
1054
|
continueMcp(),
|
|
1000
1055
|
aiderRead(),
|
|
1001
1056
|
hermesMcp(),
|
|
1057
|
+
openCodeMcp(),
|
|
1002
1058
|
openclawSkill(),
|
|
1003
1059
|
];
|
|
1004
1060
|
}
|
|
@@ -144,6 +144,11 @@ function printDryRunPlan(plan) {
|
|
|
144
144
|
console.log("Hermes (--with-hermes):");
|
|
145
145
|
W(path.join(plan.root, ".hermes", "config.yaml"), "mcp_servers.rafter entry merged into existing YAML");
|
|
146
146
|
}
|
|
147
|
+
if (plan.wantOpenCode) {
|
|
148
|
+
console.log();
|
|
149
|
+
console.log("OpenCode (--with-opencode):");
|
|
150
|
+
W(path.join(plan.root, ".config", "opencode", "opencode.json"), "mcp.rafter local/stdio entry merged into existing JSON");
|
|
151
|
+
}
|
|
147
152
|
if (plan.wantOpenClaw) {
|
|
148
153
|
console.log();
|
|
149
154
|
console.log("OpenClaw (--with-openclaw):");
|
|
@@ -268,7 +273,10 @@ function installClaudeCodeHooks(root) {
|
|
|
268
273
|
}
|
|
269
274
|
// Add Rafter hooks
|
|
270
275
|
settings.hooks.PreToolUse.push({ matcher: "Bash", hooks: [preHook] }, { matcher: "Write|Edit", hooks: [preHook] });
|
|
271
|
-
|
|
276
|
+
// Narrow to tools that produce scannable output (shell output + file
|
|
277
|
+
// writes). Firing posttool on every tool — including Read and MCP calls —
|
|
278
|
+
// added latency to operations that never produce secrets to redact.
|
|
279
|
+
settings.hooks.PostToolUse.push({ matcher: "Bash|Write|Edit|MultiEdit", hooks: [postHook] });
|
|
272
280
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
273
281
|
console.log(fmt.success(`Installed PreToolUse hooks to ${settingsPath}`));
|
|
274
282
|
console.log(fmt.success(`Installed PostToolUse hooks to ${settingsPath}`));
|
|
@@ -769,6 +777,60 @@ function installHermesMcp(root) {
|
|
|
769
777
|
console.log(fmt.success(`Installed Rafter MCP server to ${configPath}`));
|
|
770
778
|
return true;
|
|
771
779
|
}
|
|
780
|
+
/**
|
|
781
|
+
* OpenCode MCP server entry. OpenCode's schema differs from Cursor/Windsurf:
|
|
782
|
+
* the block is `mcp` (not `mcpServers`), each local server has `type: "local"`,
|
|
783
|
+
* and the command + args are a single `command` array (not split). Verified
|
|
784
|
+
* against https://opencode.ai/docs/mcp-servers/ (rf-opencode).
|
|
785
|
+
*/
|
|
786
|
+
const RAFTER_OPENCODE_MCP_ENTRY = {
|
|
787
|
+
type: "local",
|
|
788
|
+
command: [RAFTER_MCP_ENTRY.command, ...RAFTER_MCP_ENTRY.args],
|
|
789
|
+
enabled: true,
|
|
790
|
+
};
|
|
791
|
+
/**
|
|
792
|
+
* Install MCP server config for OpenCode (~/.config/opencode/opencode.json).
|
|
793
|
+
*
|
|
794
|
+
* OpenCode reads a global config at ~/.config/opencode/opencode.json and a
|
|
795
|
+
* project-level opencode.json (project takes precedence). We register the
|
|
796
|
+
* local stdio server `rafter mcp serve` under the `mcp` block. The `$schema`
|
|
797
|
+
* pointer is seeded on first write so editors get completion. Any existing
|
|
798
|
+
* keys / other MCP servers are preserved.
|
|
799
|
+
*/
|
|
800
|
+
function installOpenCodeMcp(root) {
|
|
801
|
+
const openCodeDir = path.join(root, ".config", "opencode");
|
|
802
|
+
const configPath = path.join(openCodeDir, "opencode.json");
|
|
803
|
+
if (!fs.existsSync(openCodeDir)) {
|
|
804
|
+
fs.mkdirSync(openCodeDir, { recursive: true });
|
|
805
|
+
}
|
|
806
|
+
let config = {};
|
|
807
|
+
if (fs.existsSync(configPath)) {
|
|
808
|
+
try {
|
|
809
|
+
const parsed = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
810
|
+
// Guard against valid-but-non-object top-level JSON (array/string/number).
|
|
811
|
+
// Mirrors the Python `isinstance(loaded, dict)` check so a wrong-shaped
|
|
812
|
+
// file is replaced rather than silently mangled by property assignment.
|
|
813
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
814
|
+
config = parsed;
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
console.log(fmt.warning("Existing OpenCode opencode.json was not a JSON object, creating new one"));
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
catch {
|
|
821
|
+
console.log(fmt.warning("Existing OpenCode opencode.json was unreadable, creating new one"));
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
if (!config.$schema)
|
|
825
|
+
config.$schema = "https://opencode.ai/config.json";
|
|
826
|
+
if (!config.mcp || typeof config.mcp !== "object" || Array.isArray(config.mcp)) {
|
|
827
|
+
config.mcp = {};
|
|
828
|
+
}
|
|
829
|
+
config.mcp.rafter = { ...RAFTER_OPENCODE_MCP_ENTRY };
|
|
830
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
831
|
+
console.log(fmt.success(`Installed Rafter MCP server to ${configPath}`));
|
|
832
|
+
return true;
|
|
833
|
+
}
|
|
772
834
|
function installAiderRead(root) {
|
|
773
835
|
const rafterMdPath = path.join(root, "RAFTER.md");
|
|
774
836
|
const configPath = path.join(root, ".aider.conf.yml");
|
|
@@ -939,6 +1001,7 @@ export function createInitCommand() {
|
|
|
939
1001
|
.option("--with-windsurf", "Install Windsurf integration")
|
|
940
1002
|
.option("--with-continue", "Install Continue.dev integration")
|
|
941
1003
|
.option("--with-hermes", "Install Hermes integration")
|
|
1004
|
+
.option("--with-opencode", "Install OpenCode integration")
|
|
942
1005
|
.option("--with-betterleaks", "Download and install Betterleaks binary")
|
|
943
1006
|
.option("--with-skill-scanner", "Install the optional skill-scanner deep engine (heavy; audit-skill --deep)")
|
|
944
1007
|
.option("--all", "Install all detected integrations and download Betterleaks")
|
|
@@ -971,6 +1034,7 @@ export function createInitCommand() {
|
|
|
971
1034
|
const hasContinueDev = scope === "user" && fs.existsSync(path.join(os.homedir(), ".continue"));
|
|
972
1035
|
const hasAider = scope === "user" && fs.existsSync(path.join(os.homedir(), ".aider.conf.yml"));
|
|
973
1036
|
const hasHermes = scope === "user" && fs.existsSync(path.join(os.homedir(), ".hermes"));
|
|
1037
|
+
const hasOpenCode = scope === "user" && fs.existsSync(path.join(os.homedir(), ".config", "opencode"));
|
|
974
1038
|
// Resolve opt-in flags (--all enables all detected, --interactive prompts).
|
|
975
1039
|
// In --local scope, --all is restricted to platforms that have a project-local
|
|
976
1040
|
// config story (claudeCode, codex, gemini, cursor). The rest require user scope.
|
|
@@ -997,6 +1061,12 @@ export function createInitCommand() {
|
|
|
997
1061
|
// reads ~/.hermes/config.yaml; the project-local install story isn't
|
|
998
1062
|
// established. Excluded from --all in --local for the same reason.
|
|
999
1063
|
let wantHermes = opts.withHermes || (opts.all && !opts.local);
|
|
1064
|
+
// OpenCode: MCP-based, user scope only. OpenCode reads a global config at
|
|
1065
|
+
// ~/.config/opencode/opencode.json; a project-local install story via
|
|
1066
|
+
// --local isn't wired here, so (like Hermes) it's excluded from --all in
|
|
1067
|
+
// --local scope. It supports MCP local/stdio servers and AGENTS.md
|
|
1068
|
+
// natively (https://opencode.ai/docs/mcp-servers/, sable-l8e5).
|
|
1069
|
+
let wantOpenCode = opts.withOpencode || (opts.all && !opts.local);
|
|
1000
1070
|
let wantBetterleaks = opts.withBetterleaks || (opts.all && !opts.local);
|
|
1001
1071
|
// skill-scanner is heavy and opt-in only — deliberately NOT folded into --all.
|
|
1002
1072
|
const wantSkillScanner = !!opts.withSkillScanner;
|
|
@@ -1023,6 +1093,8 @@ export function createInitCommand() {
|
|
|
1023
1093
|
wantAider = await askYesNo("Install Aider MCP server?");
|
|
1024
1094
|
if (hasHermes && !wantHermes)
|
|
1025
1095
|
wantHermes = await askYesNo("Install Hermes MCP server?");
|
|
1096
|
+
if (hasOpenCode && !wantOpenCode)
|
|
1097
|
+
wantOpenCode = await askYesNo("Install OpenCode MCP server?");
|
|
1026
1098
|
if (!wantBetterleaks)
|
|
1027
1099
|
wantBetterleaks = await askYesNo("Download Betterleaks binary (enhanced scanning)?");
|
|
1028
1100
|
console.log();
|
|
@@ -1047,6 +1119,8 @@ export function createInitCommand() {
|
|
|
1047
1119
|
detected.push("Aider");
|
|
1048
1120
|
if (hasHermes)
|
|
1049
1121
|
detected.push("Hermes");
|
|
1122
|
+
if (hasOpenCode)
|
|
1123
|
+
detected.push("OpenCode");
|
|
1050
1124
|
if (detected.length > 0) {
|
|
1051
1125
|
console.log(fmt.info(`Detected environments: ${detected.join(", ")}`));
|
|
1052
1126
|
}
|
|
@@ -1074,6 +1148,8 @@ export function createInitCommand() {
|
|
|
1074
1148
|
console.log(fmt.warning("Aider requested but not detected (~/.aider.conf.yml not found)"));
|
|
1075
1149
|
if (wantHermes && !hasHermes)
|
|
1076
1150
|
console.log(fmt.warning("Hermes requested but not detected (~/.hermes not found)"));
|
|
1151
|
+
if (wantOpenCode && !hasOpenCode)
|
|
1152
|
+
console.log(fmt.warning("OpenCode requested but not detected (~/.config/opencode not found)"));
|
|
1077
1153
|
}
|
|
1078
1154
|
// --dry-run: print every file path the command would touch, then
|
|
1079
1155
|
// exit before any filesystem write happens (rf-hrtd). The plan is
|
|
@@ -1092,6 +1168,7 @@ export function createInitCommand() {
|
|
|
1092
1168
|
wantContinue: wantContinue && (hasContinueDev || opts.local),
|
|
1093
1169
|
wantAider: wantAider && (hasAider || opts.local),
|
|
1094
1170
|
wantHermes: wantHermes && hasHermes,
|
|
1171
|
+
wantOpenCode: wantOpenCode && hasOpenCode,
|
|
1095
1172
|
wantBetterleaks,
|
|
1096
1173
|
wantSkillScanner,
|
|
1097
1174
|
riskLevel: opts.riskLevel,
|
|
@@ -1386,6 +1463,21 @@ export function createInitCommand() {
|
|
|
1386
1463
|
console.error(fmt.error(`Failed to install Hermes integration: ${e}`));
|
|
1387
1464
|
}
|
|
1388
1465
|
}
|
|
1466
|
+
// Install OpenCode integration if opted in (sable-l8e5).
|
|
1467
|
+
// User scope only — OpenCode reads a global config at
|
|
1468
|
+
// ~/.config/opencode/opencode.json. MCP-based: we register the local
|
|
1469
|
+
// stdio server `rafter mcp serve` under the `mcp` block.
|
|
1470
|
+
let openCodeOk = false;
|
|
1471
|
+
if (wantOpenCode && hasOpenCode) {
|
|
1472
|
+
try {
|
|
1473
|
+
openCodeOk = installOpenCodeMcp(root);
|
|
1474
|
+
if (openCodeOk)
|
|
1475
|
+
manager.set("agent.environments.opencode.enabled", true);
|
|
1476
|
+
}
|
|
1477
|
+
catch (e) {
|
|
1478
|
+
console.error(fmt.error(`Failed to install OpenCode integration: ${e}`));
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1389
1481
|
// Install global instruction files for platforms that support them.
|
|
1390
1482
|
// Cursor is intentionally absent — Cursor uses per-skill rules + the
|
|
1391
1483
|
// rafter sub-agent installed in the Cursor branch above (rf-svn3).
|
|
@@ -1398,7 +1490,7 @@ export function createInitCommand() {
|
|
|
1398
1490
|
console.log();
|
|
1399
1491
|
console.log(fmt.success("Agent security initialized!"));
|
|
1400
1492
|
console.log();
|
|
1401
|
-
const anyIntegration = openclawOk || claudeCodeOk || codexOk || geminiOk || cursorOk || windsurfOk || continueOk || aiderOk;
|
|
1493
|
+
const anyIntegration = openclawOk || claudeCodeOk || codexOk || geminiOk || cursorOk || windsurfOk || continueOk || aiderOk || hermesOk || openCodeOk;
|
|
1402
1494
|
if (anyIntegration) {
|
|
1403
1495
|
console.log("Next steps:");
|
|
1404
1496
|
if (openclawOk)
|
|
@@ -1417,6 +1509,10 @@ export function createInitCommand() {
|
|
|
1417
1509
|
console.log(" - Restart Continue.dev to load MCP server");
|
|
1418
1510
|
if (aiderOk)
|
|
1419
1511
|
console.log(" - Restart Aider to load RAFTER.md from .aider.conf.yml read:");
|
|
1512
|
+
if (hermesOk)
|
|
1513
|
+
console.log(" - Restart Hermes to load MCP server");
|
|
1514
|
+
if (openCodeOk)
|
|
1515
|
+
console.log(" - Restart OpenCode to load MCP server");
|
|
1420
1516
|
}
|
|
1421
1517
|
else if (scope === "project") {
|
|
1422
1518
|
console.log("No integrations were installed. In --local mode, pass one or more opt-in flags:");
|
|
@@ -1446,6 +1542,8 @@ export function createInitCommand() {
|
|
|
1446
1542
|
console.log(" rafter agent init --with-aider # Aider only");
|
|
1447
1543
|
if (hasHermes)
|
|
1448
1544
|
console.log(" rafter agent init --with-hermes # Hermes only");
|
|
1545
|
+
if (hasOpenCode)
|
|
1546
|
+
console.log(" rafter agent init --with-opencode # OpenCode only");
|
|
1449
1547
|
}
|
|
1450
1548
|
else {
|
|
1451
1549
|
console.log("No agent environments detected. Install an agent tool and re-run with --with-<tool>.");
|
|
@@ -148,6 +148,7 @@ export function createStatusCommand() {
|
|
|
148
148
|
{ name: "Windsurf", flag: "--with-windsurf", configDir: path.join(home, ".codeium", "windsurf"), configFile: path.join(home, ".codeium", "windsurf", "mcp_config.json"), needle: "rafter" },
|
|
149
149
|
{ name: "Continue.dev", flag: "--with-continue", configDir: path.join(home, ".continue"), configFile: path.join(home, ".continue", "config.json"), needle: "rafter" },
|
|
150
150
|
{ name: "Hermes", flag: "--with-hermes", configDir: path.join(home, ".hermes"), configFile: path.join(home, ".hermes", "config.yaml"), needle: "rafter" },
|
|
151
|
+
{ name: "OpenCode", flag: "--with-opencode", configDir: path.join(home, ".config", "opencode"), configFile: path.join(home, ".config", "opencode", "opencode.json"), needle: "rafter" },
|
|
151
152
|
];
|
|
152
153
|
for (const agent of mcpAgents) {
|
|
153
154
|
const label = `${agent.name}:`.padEnd(14);
|
|
@@ -251,6 +252,7 @@ function detectAgents(home) {
|
|
|
251
252
|
["continue", path.join(home, ".continue")],
|
|
252
253
|
["aider", path.join(home, ".aider.conf.yml")],
|
|
253
254
|
["hermes", path.join(home, ".hermes")],
|
|
255
|
+
["opencode", path.join(home, ".config", "opencode")],
|
|
254
256
|
];
|
|
255
257
|
return candidates
|
|
256
258
|
.filter(([, p]) => fs.existsSync(p))
|
|
@@ -287,6 +287,34 @@ function checkHermes() {
|
|
|
287
287
|
return { name, passed: false, optional: true, detail: `Cannot read config: ${e}` };
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
|
+
function checkOpenCode() {
|
|
291
|
+
// OpenCode uses ~/.config/opencode/opencode.json with an `mcp` block
|
|
292
|
+
// (local/stdio servers carry type: "local"; sable-l8e5).
|
|
293
|
+
const name = "OpenCode";
|
|
294
|
+
const homeDir = os.homedir();
|
|
295
|
+
const openCodeDir = path.join(homeDir, ".config", "opencode");
|
|
296
|
+
if (!fs.existsSync(openCodeDir)) {
|
|
297
|
+
return { name, passed: false, optional: true, detail: `Not detected — run 'rafter agent init --with-opencode' to enable` };
|
|
298
|
+
}
|
|
299
|
+
const configPath = path.join(openCodeDir, "opencode.json");
|
|
300
|
+
if (!fs.existsSync(configPath)) {
|
|
301
|
+
return { name, passed: false, optional: true, detail: `Config not found: ${configPath} — run 'rafter agent init --with-opencode'` };
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
const loaded = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
305
|
+
const servers = (loaded && typeof loaded === "object" && !Array.isArray(loaded))
|
|
306
|
+
? loaded.mcp
|
|
307
|
+
: undefined;
|
|
308
|
+
const hasRafterMcp = servers && typeof servers === "object" && servers.rafter != null;
|
|
309
|
+
if (!hasRafterMcp) {
|
|
310
|
+
return { name, passed: false, optional: true, detail: "Rafter MCP server not configured — run 'rafter agent init --with-opencode'" };
|
|
311
|
+
}
|
|
312
|
+
return { name, passed: true, detail: "MCP server configured" };
|
|
313
|
+
}
|
|
314
|
+
catch (e) {
|
|
315
|
+
return { name, passed: false, optional: true, detail: `Cannot read config: ${e}` };
|
|
316
|
+
}
|
|
317
|
+
}
|
|
290
318
|
/**
|
|
291
319
|
* Probe the Claude Code hook integration end-to-end (rf-65zg).
|
|
292
320
|
*
|
|
@@ -378,6 +406,7 @@ export function createVerifyCommand() {
|
|
|
378
406
|
checkContinueDev(),
|
|
379
407
|
checkAider(),
|
|
380
408
|
checkHermes(),
|
|
409
|
+
checkOpenCode(),
|
|
381
410
|
];
|
|
382
411
|
if (opts.probe) {
|
|
383
412
|
// Only Claude Code has a probe today (rf-65zg). Codex/Cursor/Gemini
|
|
@@ -11,8 +11,13 @@ export async function runRemoteScan(opts) {
|
|
|
11
11
|
const key = resolveKey(opts.apiKey);
|
|
12
12
|
const ghToken = opts.githubToken || process.env.RAFTER_GITHUB_TOKEN;
|
|
13
13
|
let repo, branch;
|
|
14
|
+
let detectedProvider, detectedRepoUrl;
|
|
14
15
|
try {
|
|
15
|
-
({ repo, branch
|
|
16
|
+
({ repo, branch, provider: detectedProvider, repo_url: detectedRepoUrl } = detectRepo({
|
|
17
|
+
repo: opts.repo,
|
|
18
|
+
branch: opts.branch,
|
|
19
|
+
quiet: opts.quiet,
|
|
20
|
+
}));
|
|
16
21
|
}
|
|
17
22
|
catch (e) {
|
|
18
23
|
if (e instanceof Error) {
|
|
@@ -23,6 +28,9 @@ export async function runRemoteScan(opts) {
|
|
|
23
28
|
}
|
|
24
29
|
process.exit(EXIT_GENERAL_ERROR);
|
|
25
30
|
}
|
|
31
|
+
// Explicit flags override inferred values.
|
|
32
|
+
const provider = opts.provider ?? detectedProvider;
|
|
33
|
+
const repoUrl = opts.repoUrl ?? detectedRepoUrl;
|
|
26
34
|
const body = {
|
|
27
35
|
repository_name: repo,
|
|
28
36
|
branch_name: branch,
|
|
@@ -30,6 +38,13 @@ export async function runRemoteScan(opts) {
|
|
|
30
38
|
};
|
|
31
39
|
if (ghToken)
|
|
32
40
|
body.github_token = ghToken;
|
|
41
|
+
// Additive, backward-compatible: only send provider + repo_url for non-github
|
|
42
|
+
// remotes. For github (or an unknown host that defaulted to github), omit both
|
|
43
|
+
// so the request body is byte-identical to the legacy github-only behavior.
|
|
44
|
+
if (provider && provider !== "github" && repoUrl) {
|
|
45
|
+
body.provider = provider;
|
|
46
|
+
body.repo_url = repoUrl;
|
|
47
|
+
}
|
|
33
48
|
if (!opts.quiet) {
|
|
34
49
|
const spinner = ora("Submitting scan").start();
|
|
35
50
|
try {
|
|
@@ -99,6 +114,8 @@ function addRunOptions(cmd) {
|
|
|
99
114
|
.option("-f, --format <format>", "json | md", "md")
|
|
100
115
|
.option("-m, --mode <mode>", "scan mode: fast | plus", "fast")
|
|
101
116
|
.option("--github-token <token>", "GitHub PAT for private repos (or RAFTER_GITHUB_TOKEN env var)")
|
|
117
|
+
.option("--provider <provider>", "git provider: gitlab | gitea | bitbucket (default: auto-detected; github requires nothing)")
|
|
118
|
+
.option("--repo-url <url>", "full https clone URL for non-github remotes (default: auto-detected)")
|
|
102
119
|
.option("--skip-interactive", "do not wait for scan to complete")
|
|
103
120
|
.option("--quiet", "suppress status messages");
|
|
104
121
|
}
|
|
@@ -4,6 +4,11 @@ import { AuditLogger } from "../../core/audit-logger.js";
|
|
|
4
4
|
export function createHookPosttoolCommand() {
|
|
5
5
|
return new Command("posttool")
|
|
6
6
|
.description("PostToolUse hook handler (reads stdin, redacts secrets in output, writes JSON to stdout)")
|
|
7
|
+
// Tolerate extra flags/args the host harness appends to the hook command
|
|
8
|
+
// (e.g. Claude Code adds `--hook-json <data>`). Hook input comes from stdin,
|
|
9
|
+
// so anything else is unused — discard it instead of erroring out.
|
|
10
|
+
.allowUnknownOption()
|
|
11
|
+
.allowExcessArguments()
|
|
7
12
|
.option("--format <format>", "Output format: claude (default, also Codex/Continue), cursor, gemini, windsurf", "claude")
|
|
8
13
|
.action(async (opts) => {
|
|
9
14
|
const format = (opts.format || "claude");
|
|
@@ -65,6 +65,11 @@ function formatApprovalMessage(command, evaluation) {
|
|
|
65
65
|
export function createHookPretoolCommand() {
|
|
66
66
|
return new Command("pretool")
|
|
67
67
|
.description("PreToolUse hook handler (reads stdin, writes JSON decision to stdout)")
|
|
68
|
+
// Tolerate extra flags/args the host harness appends to the hook command
|
|
69
|
+
// (e.g. Claude Code adds `--hook-json <data>`). Hook input comes from stdin,
|
|
70
|
+
// so anything else is unused — discard it instead of erroring out.
|
|
71
|
+
.allowUnknownOption()
|
|
72
|
+
.allowExcessArguments()
|
|
68
73
|
.option("--format <format>", "Output format: claude (default, also Codex/Continue), cursor, gemini, windsurf", "claude")
|
|
69
74
|
.action(async (opts) => {
|
|
70
75
|
const format = (opts.format || "claude");
|
|
@@ -23,6 +23,8 @@ export function createScanGroupCommand() {
|
|
|
23
23
|
.option("-f, --format <format>", "json | md", "md")
|
|
24
24
|
.option("-m, --mode <mode>", "scan mode: fast | plus", "fast")
|
|
25
25
|
.option("--github-token <token>", "GitHub PAT for private repos (or RAFTER_GITHUB_TOKEN env var)")
|
|
26
|
+
.option("--provider <provider>", "git provider: gitlab | gitea | bitbucket (default: auto-detected; github requires nothing)")
|
|
27
|
+
.option("--repo-url <url>", "full https clone URL for non-github remotes (default: auto-detected)")
|
|
26
28
|
.option("--skip-interactive", "do not wait for scan to complete")
|
|
27
29
|
.option("--quiet", "suppress status messages")
|
|
28
30
|
.action(async (opts) => {
|
|
@@ -38,6 +40,8 @@ export function createScanGroupCommand() {
|
|
|
38
40
|
.option("-f, --format <format>", "json | md", "md")
|
|
39
41
|
.option("-m, --mode <mode>", "scan mode: fast | plus", "fast")
|
|
40
42
|
.option("--github-token <token>", "GitHub PAT for private repos (or RAFTER_GITHUB_TOKEN env var)")
|
|
43
|
+
.option("--provider <provider>", "git provider: gitlab | gitea | bitbucket (default: auto-detected; github requires nothing)")
|
|
44
|
+
.option("--repo-url <url>", "full https clone URL for non-github remotes (default: auto-detected)")
|
|
41
45
|
.option("--skip-interactive", "do not wait for scan to complete")
|
|
42
46
|
.option("--quiet", "suppress status messages");
|
|
43
47
|
scanGroup.addCommand(localCmd, { hidden: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConfigManager } from "./config-manager.js";
|
|
2
2
|
import { AuditLogger } from "./audit-logger.js";
|
|
3
|
-
import { assessCommandRisk } from "./risk-rules.js";
|
|
3
|
+
import { assessCommandRisk, matchedCriticalPattern } from "./risk-rules.js";
|
|
4
4
|
export class CommandInterceptor {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.config = new ConfigManager();
|
|
@@ -10,13 +10,39 @@ export class CommandInterceptor {
|
|
|
10
10
|
* Evaluate if a command should be allowed
|
|
11
11
|
*/
|
|
12
12
|
evaluate(command) {
|
|
13
|
+
const riskLevel = this.assessRisk(command);
|
|
14
|
+
// Unconditional hard-block: catastrophic destructive commands (rm -rf /,
|
|
15
|
+
// fork bombs, disk wipes, mkfs, …) are NEVER allowed, regardless of the
|
|
16
|
+
// configured policy — or its absence. Security must not depend on a policy
|
|
17
|
+
// being present (the default config may be missing one) or on the chosen
|
|
18
|
+
// mode (even allow-all / a custom deny-list cannot opt out of these).
|
|
19
|
+
if (riskLevel === "critical") {
|
|
20
|
+
return {
|
|
21
|
+
command,
|
|
22
|
+
riskLevel,
|
|
23
|
+
allowed: false,
|
|
24
|
+
requiresApproval: false,
|
|
25
|
+
reason: "Matches built-in blocked pattern (critical destructive command)",
|
|
26
|
+
matchedPattern: matchedCriticalPattern(command) ?? "builtin:critical-destructive"
|
|
27
|
+
};
|
|
28
|
+
}
|
|
13
29
|
const cfg = this.config.loadWithPolicy();
|
|
14
30
|
const policy = cfg.agent?.commandPolicy;
|
|
15
31
|
if (!policy) {
|
|
16
|
-
// No policy configured
|
|
32
|
+
// No policy configured — fall back to safe built-in defaults rather than
|
|
33
|
+
// allow-all: high-risk commands still require approval.
|
|
34
|
+
if (riskLevel === "high") {
|
|
35
|
+
return {
|
|
36
|
+
command,
|
|
37
|
+
riskLevel,
|
|
38
|
+
allowed: false,
|
|
39
|
+
requiresApproval: true,
|
|
40
|
+
reason: "High risk command requires approval"
|
|
41
|
+
};
|
|
42
|
+
}
|
|
17
43
|
return {
|
|
18
44
|
command,
|
|
19
|
-
riskLevel
|
|
45
|
+
riskLevel,
|
|
20
46
|
allowed: true,
|
|
21
47
|
requiresApproval: false
|
|
22
48
|
};
|
package/dist/core/risk-rules.js
CHANGED
|
@@ -87,3 +87,17 @@ export function assessCommandRisk(command) {
|
|
|
87
87
|
}
|
|
88
88
|
return "low";
|
|
89
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Return the source of the first CRITICAL pattern matching the command, or null.
|
|
92
|
+
* Mirrors assessCommandRisk's lowercasing. Intended to be called only once a
|
|
93
|
+
* command is already classified "critical" (safe-prefix exclusion is handled by
|
|
94
|
+
* assessCommandRisk), to surface *which* built-in rule matched.
|
|
95
|
+
*/
|
|
96
|
+
export function matchedCriticalPattern(command) {
|
|
97
|
+
const cmd = command.toLowerCase().trim();
|
|
98
|
+
for (const pattern of CRITICAL_PATTERNS) {
|
|
99
|
+
if (pattern.test(cmd))
|
|
100
|
+
return pattern.source;
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
@@ -146,6 +146,13 @@ export const DEFAULT_SECRET_PATTERNS = [
|
|
|
146
146
|
regex: "pypi-AgEIcHlwaS5vcmc[A-Za-z0-9\\-_]{50,1024}",
|
|
147
147
|
severity: "critical",
|
|
148
148
|
description: "PyPI API token detected"
|
|
149
|
+
},
|
|
150
|
+
// DigitalOcean
|
|
151
|
+
{
|
|
152
|
+
name: "DigitalOcean Personal Access Token",
|
|
153
|
+
regex: "dop_v1_[a-f0-9]{64}",
|
|
154
|
+
severity: "critical",
|
|
155
|
+
description: "DigitalOcean Personal Access Token detected"
|
|
149
156
|
}
|
|
150
157
|
];
|
|
151
158
|
/**
|
package/dist/utils/git.js
CHANGED
|
@@ -19,19 +19,78 @@ export function parseRemote(url) {
|
|
|
19
19
|
const parts = url.split("/");
|
|
20
20
|
return parts.slice(-2).join("/"); // owner/repo
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Map a git remote host to a provider. `github` is the backward-compatible
|
|
24
|
+
* default for any host we don't recognize — a GitHub user's request is
|
|
25
|
+
* unaffected, and unknown self-hosted hosts fall back to the legacy behavior.
|
|
26
|
+
*/
|
|
27
|
+
export function providerForHost(host) {
|
|
28
|
+
host = host.toLowerCase();
|
|
29
|
+
if (host === "github.com")
|
|
30
|
+
return "github";
|
|
31
|
+
if (host === "gitlab.com" || host.endsWith(".gitlab.com"))
|
|
32
|
+
return "gitlab";
|
|
33
|
+
if (host === "bitbucket.org")
|
|
34
|
+
return "bitbucket";
|
|
35
|
+
if (host === "codeberg.org" || host.endsWith(".gitea.io"))
|
|
36
|
+
return "gitea";
|
|
37
|
+
return "github"; // backward-compatible default
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Split a git remote URL into its host + owner/repo slug, handling both
|
|
41
|
+
* `git@host:owner/repo(.git)` (scp-like) and `https://host/owner/repo(.git)`.
|
|
42
|
+
* Returns null when the URL can't be parsed into host + slug.
|
|
43
|
+
*/
|
|
44
|
+
function splitRemote(url) {
|
|
45
|
+
let rest = url.replace(/^(https?:\/\/|git@)/, "").replace(":", "/");
|
|
46
|
+
if (rest.endsWith(".git"))
|
|
47
|
+
rest = rest.slice(0, -4);
|
|
48
|
+
const parts = rest.split("/").filter((p) => p.length > 0);
|
|
49
|
+
if (parts.length < 3)
|
|
50
|
+
return null; // need host + owner + repo
|
|
51
|
+
const host = parts[0];
|
|
52
|
+
const slug = parts.slice(-2).join("/");
|
|
53
|
+
return { host, slug };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Infer the provider and a canonical `https://<host>/<owner>/<repo>` clone URL
|
|
57
|
+
* from a git remote (either scp-like `git@` or `https://` form). Falls back to
|
|
58
|
+
* `{ provider: "github", repoUrl: undefined }` when the URL can't be parsed.
|
|
59
|
+
*/
|
|
60
|
+
export function inferRemote(url) {
|
|
61
|
+
const parts = splitRemote(url);
|
|
62
|
+
if (!parts)
|
|
63
|
+
return { provider: "github" };
|
|
64
|
+
return {
|
|
65
|
+
provider: providerForHost(parts.host),
|
|
66
|
+
repoUrl: `https://${parts.host}/${parts.slug}`,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
22
69
|
export function detectRepo(opts) {
|
|
70
|
+
// Both explicit — return them as-is. No provider/repo_url is inferred here;
|
|
71
|
+
// the caller's --provider/--repo-url flags fill that in when needed.
|
|
23
72
|
if (opts.repo && opts.branch)
|
|
24
|
-
return opts;
|
|
73
|
+
return { repo: opts.repo, branch: opts.branch };
|
|
25
74
|
const repoEnv = process.env.GITHUB_REPOSITORY || process.env.CI_REPOSITORY;
|
|
26
75
|
const branchEnv = process.env.GITHUB_REF_NAME || process.env.CI_COMMIT_BRANCH || process.env.CI_BRANCH;
|
|
27
76
|
let repoSlug = opts.repo || repoEnv;
|
|
28
77
|
let branch = opts.branch || branchEnv;
|
|
78
|
+
let provider;
|
|
79
|
+
let repoUrl;
|
|
29
80
|
try {
|
|
30
81
|
if (!repoSlug || !branch) {
|
|
31
82
|
if (git("rev-parse --is-inside-work-tree") !== "true")
|
|
32
83
|
throw new Error("not a repo");
|
|
33
|
-
|
|
34
|
-
|
|
84
|
+
// Read the remote once when we need to detect the slug, and reuse it to
|
|
85
|
+
// infer the provider + canonical clone URL. When repo/branch come from
|
|
86
|
+
// env (CI), we never touch git here — behavior is byte-identical.
|
|
87
|
+
if (!repoSlug) {
|
|
88
|
+
const remoteUrl = git("remote get-url origin");
|
|
89
|
+
repoSlug = parseRemote(remoteUrl);
|
|
90
|
+
const inferred = inferRemote(remoteUrl);
|
|
91
|
+
provider = inferred.provider;
|
|
92
|
+
repoUrl = inferred.repoUrl;
|
|
93
|
+
}
|
|
35
94
|
if (!branch) {
|
|
36
95
|
try {
|
|
37
96
|
branch = safeBranch(git);
|
|
@@ -44,7 +103,7 @@ export function detectRepo(opts) {
|
|
|
44
103
|
if ((!opts.repo || !opts.branch) && !opts.quiet) {
|
|
45
104
|
console.error(`Repo auto-detected: ${repoSlug} @ ${branch} (note: scanning remote)`);
|
|
46
105
|
}
|
|
47
|
-
return { repo: repoSlug, branch };
|
|
106
|
+
return { repo: repoSlug, branch, provider, repo_url: repoUrl };
|
|
48
107
|
}
|
|
49
108
|
catch {
|
|
50
109
|
throw new Error("Could not auto-detect Git repository. Please pass --repo and --branch explicitly.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rafter-security/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
34
|
-
"axios": "^1.
|
|
34
|
+
"axios": "^1.16.0",
|
|
35
35
|
"chalk": "^5.3.0",
|
|
36
36
|
"chokidar": "^5.0.0",
|
|
37
37
|
"commander": "^11.1.0",
|
|
38
38
|
"dotenv": "^16.4.5",
|
|
39
|
-
"js-yaml": "^4.
|
|
39
|
+
"js-yaml": "^4.2.0",
|
|
40
40
|
"minimatch": "^10.2.4",
|
|
41
41
|
"ora": "^7.0.1",
|
|
42
|
-
"tar": "^7.5.
|
|
42
|
+
"tar": "^7.5.16"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -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.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
homepage: https://rafter.so
|
|
6
6
|
metadata:
|
|
7
7
|
openclaw:
|