@rafter-security/cli 0.7.7 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -681
- package/dist/commands/agent/baseline.js +15 -15
- package/dist/commands/agent/components.js +282 -138
- package/dist/commands/agent/index.js +2 -2
- package/dist/commands/agent/init.js +564 -174
- package/dist/commands/agent/scan.js +76 -47
- package/dist/commands/agent/status.js +19 -10
- package/dist/commands/agent/update-betterleaks.js +39 -0
- package/dist/commands/agent/verify.js +230 -29
- package/dist/commands/brief.js +13 -45
- package/dist/commands/completion.js +15 -15
- package/dist/commands/issues/from-scan.js +6 -3
- package/dist/commands/mcp/server.js +11 -11
- package/dist/core/config-manager.js +6 -0
- package/dist/core/custom-patterns.js +86 -4
- package/dist/core/policy-loader.js +60 -1
- package/dist/scanners/{gitleaks.js → betterleaks.js} +49 -61
- package/dist/scanners/regex-scanner.js +4 -5
- package/dist/scanners/secret-patterns.js +1 -1
- package/dist/utils/binary-manager.js +205 -109
- package/dist/utils/skill-manager.js +96 -16
- package/package.json +1 -1
- package/resources/agents/rafter.md +81 -0
- package/resources/continue-rules/rafter-code-review.md +15 -0
- package/resources/continue-rules/rafter-secure-design.md +15 -0
- package/resources/continue-rules/rafter-skill-review.md +15 -0
- package/resources/continue-rules/rafter.md +16 -0
- package/resources/cursor-rules/rafter-code-review.mdc +14 -0
- package/resources/cursor-rules/rafter-secure-design.mdc +14 -0
- package/resources/cursor-rules/rafter-skill-review.mdc +14 -0
- package/resources/cursor-rules/rafter.mdc +15 -0
- package/resources/rafter-security-skill.md +18 -10
- package/resources/skills/rafter/SKILL.md +1 -1
- package/resources/skills/rafter/docs/cli-reference.md +5 -5
- package/resources/windsurf-rules/rafter-code-review.md +14 -0
- package/resources/windsurf-rules/rafter-secure-design.md +14 -0
- package/resources/windsurf-rules/rafter-skill-review.md +14 -0
- package/resources/windsurf-rules/rafter.md +15 -0
- package/dist/commands/agent/update-gitleaks.js +0 -40
|
@@ -11,6 +11,7 @@ import { createRequire } from "module";
|
|
|
11
11
|
import { createInterface } from "readline";
|
|
12
12
|
import { fmt } from "../../utils/formatter.js";
|
|
13
13
|
import { injectInstructionFile } from "./instruction-block.js";
|
|
14
|
+
import yaml from "js-yaml";
|
|
14
15
|
const __filename = fileURLToPath(import.meta.url);
|
|
15
16
|
const __dirname = path.dirname(__filename);
|
|
16
17
|
/**
|
|
@@ -25,6 +26,125 @@ const AGENT_SKILLS = [
|
|
|
25
26
|
{ name: "rafter-secure-design", description: "Rafter Secure Design" },
|
|
26
27
|
{ name: "rafter-code-review", description: "Rafter Code Review" },
|
|
27
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
|
+
}
|
|
28
148
|
/**
|
|
29
149
|
* Install instruction files for platforms that support them, at either user
|
|
30
150
|
* or project scope.
|
|
@@ -54,17 +174,23 @@ function installGlobalInstructions(platforms, root, scope) {
|
|
|
54
174
|
console.log(fmt.warning(`Failed to write Claude Code instructions: ${e}`));
|
|
55
175
|
}
|
|
56
176
|
}
|
|
57
|
-
//
|
|
58
|
-
|
|
177
|
+
// AGENTS.md — read natively by Codex AND Windsurf. Codex at user scope keeps
|
|
178
|
+
// its own copy at ~/.codex/AGENTS.md; everything else (project scope, or any
|
|
179
|
+
// scope where Windsurf is in play) writes <root>/AGENTS.md once.
|
|
180
|
+
if (platforms.codex || platforms.windsurf) {
|
|
59
181
|
try {
|
|
60
|
-
const
|
|
182
|
+
const codexUser = scope === "user" && platforms.codex && !platforms.windsurf;
|
|
183
|
+
const filePath = codexUser
|
|
61
184
|
? path.join(root, ".codex", "AGENTS.md")
|
|
62
185
|
: path.join(root, "AGENTS.md");
|
|
63
186
|
injectInstructionFile(filePath);
|
|
64
|
-
|
|
187
|
+
const readers = [platforms.codex && "Codex", platforms.windsurf && "Windsurf"]
|
|
188
|
+
.filter(Boolean)
|
|
189
|
+
.join(" + ");
|
|
190
|
+
console.log(fmt.success(`Installed Rafter instructions for ${readers} to ${filePath}`));
|
|
65
191
|
}
|
|
66
192
|
catch (e) {
|
|
67
|
-
console.log(fmt.warning(`Failed to write
|
|
193
|
+
console.log(fmt.warning(`Failed to write AGENTS.md: ${e}`));
|
|
68
194
|
}
|
|
69
195
|
}
|
|
70
196
|
// Gemini — ~/.gemini/GEMINI.md (user) or <cwd>/GEMINI.md (project)
|
|
@@ -80,17 +206,10 @@ function installGlobalInstructions(platforms, root, scope) {
|
|
|
80
206
|
console.log(fmt.warning(`Failed to write Gemini instructions: ${e}`));
|
|
81
207
|
}
|
|
82
208
|
}
|
|
83
|
-
// Cursor
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
injectInstructionFile(filePath);
|
|
88
|
-
console.log(fmt.success(`Installed Rafter instructions to ${filePath}`));
|
|
89
|
-
}
|
|
90
|
-
catch (e) {
|
|
91
|
-
console.log(fmt.warning(`Failed to write Cursor instructions: ${e}`));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
209
|
+
// Cursor uses per-skill rules at <root>/.cursor/rules/<skill>.mdc and the
|
|
210
|
+
// rafter sub-agent at <root>/.cursor/agents/rafter.md (installed in the
|
|
211
|
+
// Cursor branch above). The consolidated rafter-security.mdc was retired
|
|
212
|
+
// in rf-svn3 in favor of per-skill rules with trigger-first descriptions.
|
|
94
213
|
}
|
|
95
214
|
function installClaudeCodeHooks(root) {
|
|
96
215
|
const settingsPath = path.join(root, ".claude", "settings.json");
|
|
@@ -170,11 +289,30 @@ function installCodexHooks(root) {
|
|
|
170
289
|
// Remove existing rafter hooks
|
|
171
290
|
config.hooks.PreToolUse = config.hooks.PreToolUse.filter((entry) => !(entry.hooks || []).some((h) => h.command?.startsWith("rafter hook pretool")));
|
|
172
291
|
config.hooks.PostToolUse = config.hooks.PostToolUse.filter((entry) => !(entry.hooks || []).some((h) => h.command?.startsWith("rafter hook posttool")));
|
|
173
|
-
|
|
292
|
+
// PreToolUse intercepts the tools Codex documents support for: Bash and
|
|
293
|
+
// apply_patch (file edits). Per developers.openai.com/codex/hooks PreToolUse
|
|
294
|
+
// also covers MCP tool calls via patterns like `mcp__<server>__<tool>` —
|
|
295
|
+
// when an MCP server is wired up, install a separate matcher for it.
|
|
296
|
+
// (rf-ovql verification 2026-05-03.)
|
|
297
|
+
config.hooks.PreToolUse.push({ matcher: "Bash|apply_patch", hooks: [preHook] });
|
|
298
|
+
// PostToolUse fires for the same tool surface; .* keeps all events in the
|
|
299
|
+
// audit log without filtering.
|
|
174
300
|
config.hooks.PostToolUse.push({ matcher: ".*", hooks: [postHook] });
|
|
175
301
|
fs.writeFileSync(hooksPath, JSON.stringify(config, null, 2), "utf-8");
|
|
176
302
|
console.log(fmt.success(`Installed hooks to ${hooksPath}`));
|
|
177
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Install Cursor hooks at <root>/.cursor/hooks.json.
|
|
306
|
+
*
|
|
307
|
+
* Covers the full pre/post-tool lifecycle plus shell-specific gating:
|
|
308
|
+
* - preToolUse — rafter classifies every tool call
|
|
309
|
+
* - postToolUse — rafter post-hook (audit, telemetry)
|
|
310
|
+
* - beforeShellExecution — narrower complement; some Cursor versions
|
|
311
|
+
* fire this without firing preToolUse for shell.
|
|
312
|
+
*
|
|
313
|
+
* Idempotent — repeated installs do not duplicate rafter entries.
|
|
314
|
+
* Non-rafter entries (other tools' hooks, unrelated events) are preserved.
|
|
315
|
+
*/
|
|
178
316
|
function installCursorHooks(root) {
|
|
179
317
|
const cursorDir = path.join(root, ".cursor");
|
|
180
318
|
if (!fs.existsSync(cursorDir)) {
|
|
@@ -194,18 +332,116 @@ function installCursorHooks(root) {
|
|
|
194
332
|
config.version = 1;
|
|
195
333
|
if (!config.hooks)
|
|
196
334
|
config.hooks = {};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
335
|
+
const events = [
|
|
336
|
+
{ event: "preToolUse", command: "rafter hook pretool --format cursor" },
|
|
337
|
+
{ event: "postToolUse", command: "rafter hook posttool --format cursor" },
|
|
338
|
+
{ event: "beforeShellExecution", command: "rafter hook pretool --format cursor" },
|
|
339
|
+
];
|
|
340
|
+
for (const { event, command } of events) {
|
|
341
|
+
if (!Array.isArray(config.hooks[event]))
|
|
342
|
+
config.hooks[event] = [];
|
|
343
|
+
config.hooks[event] = config.hooks[event].filter((entry) => !entry?.command?.includes("rafter hook"));
|
|
344
|
+
config.hooks[event].push({ command, type: "command", timeout: 5000 });
|
|
345
|
+
}
|
|
206
346
|
fs.writeFileSync(hooksPath, JSON.stringify(config, null, 2), "utf-8");
|
|
207
347
|
console.log(fmt.success(`Installed hooks to ${hooksPath}`));
|
|
208
348
|
}
|
|
349
|
+
/** Skills shipped as both Cursor rules and (Claude Code / Codex / Gemini) skills. */
|
|
350
|
+
const CURSOR_RULE_SKILLS = [
|
|
351
|
+
"rafter",
|
|
352
|
+
"rafter-secure-design",
|
|
353
|
+
"rafter-code-review",
|
|
354
|
+
"rafter-skill-review",
|
|
355
|
+
];
|
|
356
|
+
/**
|
|
357
|
+
* Install per-skill Cursor rules at <root>/.cursor/rules/<skill>.mdc.
|
|
358
|
+
*
|
|
359
|
+
* One file per shipped skill. Each rule's frontmatter description is reused
|
|
360
|
+
* verbatim from the skill's SKILL.md frontmatter (trigger-first phrasing per
|
|
361
|
+
* rf-4ei / rf-8po) so Cursor surfaces it on the same triggers as Claude Code.
|
|
362
|
+
*
|
|
363
|
+
* Replaces the legacy consolidated `.cursor/rules/rafter-security.mdc` — that
|
|
364
|
+
* single file is no longer written by the Cursor install path.
|
|
365
|
+
*/
|
|
366
|
+
function installCursorRules(root) {
|
|
367
|
+
const rulesDir = path.join(root, ".cursor", "rules");
|
|
368
|
+
fs.mkdirSync(rulesDir, { recursive: true });
|
|
369
|
+
// Resolve resources/cursor-rules relative to this module.
|
|
370
|
+
// After build: dist/commands/agent/init.js -> ../../../resources/cursor-rules
|
|
371
|
+
const candidates = [
|
|
372
|
+
path.resolve(__dirname, "..", "..", "..", "resources", "cursor-rules"),
|
|
373
|
+
path.resolve(__dirname, "..", "..", "resources", "cursor-rules"),
|
|
374
|
+
];
|
|
375
|
+
const sourceDir = candidates.find((p) => fs.existsSync(p));
|
|
376
|
+
if (!sourceDir) {
|
|
377
|
+
console.log(fmt.warning(`Cursor rule templates not found in resources/cursor-rules`));
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
for (const name of CURSOR_RULE_SKILLS) {
|
|
381
|
+
const src = path.join(sourceDir, `${name}.mdc`);
|
|
382
|
+
const dest = path.join(rulesDir, `${name}.mdc`);
|
|
383
|
+
if (!fs.existsSync(src)) {
|
|
384
|
+
console.log(fmt.warning(`Cursor rule template missing: ${src}`));
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
fs.copyFileSync(src, dest);
|
|
388
|
+
console.log(fmt.success(`Installed Cursor rule to ${dest}`));
|
|
389
|
+
}
|
|
390
|
+
// Remove the legacy consolidated rule if present, so reinstall on top of
|
|
391
|
+
// an old layout migrates cleanly.
|
|
392
|
+
const legacy = path.join(rulesDir, "rafter-security.mdc");
|
|
393
|
+
if (fs.existsSync(legacy)) {
|
|
394
|
+
try {
|
|
395
|
+
fs.unlinkSync(legacy);
|
|
396
|
+
console.log(fmt.info(`Removed legacy ${legacy} (superseded by per-skill rules)`));
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
/* best-effort */
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Install Cursor sub-agent at <root>/.cursor/agents/rafter.md.
|
|
405
|
+
*
|
|
406
|
+
* Reuses the Claude-Code sub-agent body (rf-q7j) with one shape difference:
|
|
407
|
+
* Cursor's frontmatter has no `tools:` field — tools inherit from the parent
|
|
408
|
+
* agent. The hard rules in the body (no code modification, no commits) still
|
|
409
|
+
* apply, since Cursor relies on prompt-level constraints rather than
|
|
410
|
+
* structural restriction.
|
|
411
|
+
*/
|
|
412
|
+
function installCursorSubAgents(root) {
|
|
413
|
+
const agentsDir = path.join(root, ".cursor", "agents");
|
|
414
|
+
fs.mkdirSync(agentsDir, { recursive: true });
|
|
415
|
+
const candidates = [
|
|
416
|
+
path.resolve(__dirname, "..", "..", "..", "resources", "agents", "rafter.md"),
|
|
417
|
+
path.resolve(__dirname, "..", "..", "resources", "agents", "rafter.md"),
|
|
418
|
+
];
|
|
419
|
+
const src = candidates.find((p) => fs.existsSync(p));
|
|
420
|
+
if (!src) {
|
|
421
|
+
console.log(fmt.warning(`Rafter sub-agent template not found in resources/agents`));
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const raw = fs.readFileSync(src, "utf-8");
|
|
425
|
+
const cursored = stripToolsFromFrontmatter(raw);
|
|
426
|
+
const dest = path.join(agentsDir, "rafter.md");
|
|
427
|
+
fs.writeFileSync(dest, cursored, "utf-8");
|
|
428
|
+
console.log(fmt.success(`Installed Cursor sub-agent to ${dest}`));
|
|
429
|
+
}
|
|
430
|
+
/** Strip the Claude-Code `tools:` line from sub-agent frontmatter — Cursor doesn't have it. */
|
|
431
|
+
function stripToolsFromFrontmatter(content) {
|
|
432
|
+
if (!content.startsWith("---\n"))
|
|
433
|
+
return content;
|
|
434
|
+
const fmEnd = content.indexOf("\n---", 4);
|
|
435
|
+
if (fmEnd === -1)
|
|
436
|
+
return content;
|
|
437
|
+
const frontmatter = content.slice(4, fmEnd);
|
|
438
|
+
const body = content.slice(fmEnd);
|
|
439
|
+
const cleaned = frontmatter
|
|
440
|
+
.split("\n")
|
|
441
|
+
.filter((line) => !/^tools:\s/.test(line))
|
|
442
|
+
.join("\n");
|
|
443
|
+
return `---\n${cleaned}${body}`;
|
|
444
|
+
}
|
|
209
445
|
function installGeminiHooks(root) {
|
|
210
446
|
const geminiDir = path.join(root, ".gemini");
|
|
211
447
|
if (!fs.existsSync(geminiDir)) {
|
|
@@ -230,8 +466,12 @@ function installGeminiHooks(root) {
|
|
|
230
466
|
// Remove existing rafter hooks
|
|
231
467
|
settings.hooks.BeforeTool = settings.hooks.BeforeTool.filter((entry) => !(entry.hooks || []).some((h) => h.command?.includes("rafter hook pretool")));
|
|
232
468
|
settings.hooks.AfterTool = settings.hooks.AfterTool.filter((entry) => !(entry.hooks || []).some((h) => h.command?.includes("rafter hook posttool")));
|
|
469
|
+
// Gemini matchers are regexes against built-in tool names per
|
|
470
|
+
// geminicli.com/docs/hooks/reference. Match the mutating tools by name
|
|
471
|
+
// explicitly: run_shell_command, write_file, replace, edit. (rf-044o
|
|
472
|
+
// verification 2026-05-03 — schema confirmed against current Gemini docs.)
|
|
233
473
|
settings.hooks.BeforeTool.push({
|
|
234
|
-
matcher: "
|
|
474
|
+
matcher: "run_shell_command|write_file|replace|edit",
|
|
235
475
|
hooks: [{ type: "command", command: "rafter hook pretool --format gemini", timeout: 5000 }],
|
|
236
476
|
});
|
|
237
477
|
settings.hooks.AfterTool.push({
|
|
@@ -241,71 +481,47 @@ function installGeminiHooks(root) {
|
|
|
241
481
|
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
242
482
|
console.log(fmt.success(`Installed hooks to ${settingsPath}`));
|
|
243
483
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
show_output: true,
|
|
275
|
-
});
|
|
276
|
-
fs.writeFileSync(hooksPath, JSON.stringify(config, null, 2), "utf-8");
|
|
277
|
-
console.log(fmt.success(`Installed hooks to ${hooksPath}`));
|
|
278
|
-
}
|
|
279
|
-
function installContinueDevHooks(root) {
|
|
280
|
-
const continueDir = path.join(root, ".continue");
|
|
281
|
-
if (!fs.existsSync(continueDir)) {
|
|
282
|
-
fs.mkdirSync(continueDir, { recursive: true });
|
|
484
|
+
/** Skills shipped as Windsurf per-workspace rules at .windsurf/rules/<skill>.md (rf-0vr3). */
|
|
485
|
+
const WINDSURF_RULE_SKILLS = [
|
|
486
|
+
"rafter",
|
|
487
|
+
"rafter-secure-design",
|
|
488
|
+
"rafter-code-review",
|
|
489
|
+
"rafter-skill-review",
|
|
490
|
+
];
|
|
491
|
+
/**
|
|
492
|
+
* Install per-skill Windsurf rules at <root>/.windsurf/rules/<skill>.md.
|
|
493
|
+
*
|
|
494
|
+
* Windsurf reads workspace rules from .windsurf/rules/*.md (12KB cap per file
|
|
495
|
+
* per docs). Each file uses Windsurf YAML frontmatter (`trigger: model_decision`
|
|
496
|
+
* + `description:`) so the agent fetches the rule when its description matches
|
|
497
|
+
* the task. Body content mirrors the Cursor pointer-rule pattern.
|
|
498
|
+
*
|
|
499
|
+
* Replaces the prior `~/.windsurf/hooks.json` install, which was a silent
|
|
500
|
+
* no-op — Windsurf has no documented hook surface as of v1.x (research bead
|
|
501
|
+
* rf-s1n3, gap reports rf-p1ri / rf-vayl).
|
|
502
|
+
*/
|
|
503
|
+
function installWindsurfRules(root) {
|
|
504
|
+
const rulesDir = path.join(root, ".windsurf", "rules");
|
|
505
|
+
fs.mkdirSync(rulesDir, { recursive: true });
|
|
506
|
+
const candidates = [
|
|
507
|
+
path.resolve(__dirname, "..", "..", "..", "resources", "windsurf-rules"),
|
|
508
|
+
path.resolve(__dirname, "..", "..", "resources", "windsurf-rules"),
|
|
509
|
+
];
|
|
510
|
+
const sourceDir = candidates.find((p) => fs.existsSync(p));
|
|
511
|
+
if (!sourceDir) {
|
|
512
|
+
console.log(fmt.warning(`Windsurf rule templates not found in resources/windsurf-rules`));
|
|
513
|
+
return;
|
|
283
514
|
}
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
catch {
|
|
291
|
-
console.log(fmt.warning("Existing Continue.dev settings.json was unreadable, creating new one"));
|
|
515
|
+
for (const name of WINDSURF_RULE_SKILLS) {
|
|
516
|
+
const src = path.join(sourceDir, `${name}.md`);
|
|
517
|
+
const dest = path.join(rulesDir, `${name}.md`);
|
|
518
|
+
if (!fs.existsSync(src)) {
|
|
519
|
+
console.log(fmt.warning(`Windsurf rule template missing: ${src}`));
|
|
520
|
+
continue;
|
|
292
521
|
}
|
|
522
|
+
fs.copyFileSync(src, dest);
|
|
523
|
+
console.log(fmt.success(`Installed Windsurf rule to ${dest}`));
|
|
293
524
|
}
|
|
294
|
-
if (!settings.hooks)
|
|
295
|
-
settings.hooks = {};
|
|
296
|
-
if (!settings.hooks.PreToolUse)
|
|
297
|
-
settings.hooks.PreToolUse = [];
|
|
298
|
-
if (!settings.hooks.PostToolUse)
|
|
299
|
-
settings.hooks.PostToolUse = [];
|
|
300
|
-
// Continue.dev uses the same protocol as Claude Code
|
|
301
|
-
const preHook = { type: "command", command: "rafter hook pretool" };
|
|
302
|
-
const postHook = { type: "command", command: "rafter hook posttool" };
|
|
303
|
-
settings.hooks.PreToolUse = settings.hooks.PreToolUse.filter((entry) => !(entry.hooks || []).some((h) => h.command?.startsWith("rafter hook pretool")));
|
|
304
|
-
settings.hooks.PostToolUse = settings.hooks.PostToolUse.filter((entry) => !(entry.hooks || []).some((h) => h.command?.startsWith("rafter hook posttool")));
|
|
305
|
-
settings.hooks.PreToolUse.push({ matcher: "Bash", hooks: [preHook] }, { matcher: "Write|Edit", hooks: [preHook] });
|
|
306
|
-
settings.hooks.PostToolUse.push({ matcher: ".*", hooks: [postHook] });
|
|
307
|
-
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), "utf-8");
|
|
308
|
-
console.log(fmt.success(`Installed hooks to ${settingsPath}`));
|
|
309
525
|
}
|
|
310
526
|
/** MCP server entry for rafter — shared across MCP-native clients */
|
|
311
527
|
const RAFTER_MCP_ENTRY = {
|
|
@@ -409,6 +625,46 @@ function installWindsurfMcp(root) {
|
|
|
409
625
|
console.log(fmt.success(`Installed Rafter MCP server to ${mcpPath}`));
|
|
410
626
|
return true;
|
|
411
627
|
}
|
|
628
|
+
/** Skills shipped as Continue.dev rules at .continue/rules/<skill>.md (rf-acz0). */
|
|
629
|
+
const CONTINUE_RULE_SKILLS = [
|
|
630
|
+
"rafter",
|
|
631
|
+
"rafter-secure-design",
|
|
632
|
+
"rafter-code-review",
|
|
633
|
+
"rafter-skill-review",
|
|
634
|
+
];
|
|
635
|
+
/**
|
|
636
|
+
* Install per-skill Continue.dev rules at <root>/.continue/rules/<skill>.md.
|
|
637
|
+
*
|
|
638
|
+
* Continue.dev reads workspace rules from .continue/rules/*.md (per-rule files,
|
|
639
|
+
* lexicographic load order). Frontmatter: `name`, `description`, `alwaysApply`.
|
|
640
|
+
* Each rule body mirrors the Cursor / Windsurf pointer-rule pattern.
|
|
641
|
+
*
|
|
642
|
+
* Continue.dev has no documented hook surface (the prior hooks install was
|
|
643
|
+
* pruned in rf-cia phase b). Rules + MCP are the only intercepts.
|
|
644
|
+
*/
|
|
645
|
+
function installContinueDevRules(root) {
|
|
646
|
+
const rulesDir = path.join(root, ".continue", "rules");
|
|
647
|
+
fs.mkdirSync(rulesDir, { recursive: true });
|
|
648
|
+
const candidates = [
|
|
649
|
+
path.resolve(__dirname, "..", "..", "..", "resources", "continue-rules"),
|
|
650
|
+
path.resolve(__dirname, "..", "..", "resources", "continue-rules"),
|
|
651
|
+
];
|
|
652
|
+
const sourceDir = candidates.find((p) => fs.existsSync(p));
|
|
653
|
+
if (!sourceDir) {
|
|
654
|
+
console.log(fmt.warning(`Continue.dev rule templates not found in resources/continue-rules`));
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
for (const name of CONTINUE_RULE_SKILLS) {
|
|
658
|
+
const src = path.join(sourceDir, `${name}.md`);
|
|
659
|
+
const dest = path.join(rulesDir, `${name}.md`);
|
|
660
|
+
if (!fs.existsSync(src)) {
|
|
661
|
+
console.log(fmt.warning(`Continue.dev rule template missing: ${src}`));
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
fs.copyFileSync(src, dest);
|
|
665
|
+
console.log(fmt.success(`Installed Continue.dev rule to ${dest}`));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
412
668
|
/**
|
|
413
669
|
* Install MCP server config for Continue.dev (~/.continue/config.json)
|
|
414
670
|
*/
|
|
@@ -447,50 +703,129 @@ function installContinueDevMcp(root) {
|
|
|
447
703
|
return true;
|
|
448
704
|
}
|
|
449
705
|
/**
|
|
450
|
-
* Install
|
|
451
|
-
*
|
|
706
|
+
* Install Rafter context for Aider (rf-du2o).
|
|
707
|
+
*
|
|
708
|
+
* Aider has no native MCP support and no plugin/hook surface. Its only
|
|
709
|
+
* intercept-friendly persistent-context primitive is the `read:` flag in
|
|
710
|
+
* `.aider.conf.yml`, which injects read-only files into every session.
|
|
711
|
+
*
|
|
712
|
+
* Behavior:
|
|
713
|
+
* 1. Write `<root>/RAFTER.md` with the rafter instruction block.
|
|
714
|
+
* 2. Update `<root>/.aider.conf.yml` so `read:` includes `RAFTER.md`
|
|
715
|
+
* (preserves any pre-existing `read:` entries; preserves other YAML keys).
|
|
716
|
+
* 3. Strip the legacy `mcp-server-command: rafter mcp serve` line if present
|
|
717
|
+
* — it was a silent no-op in earlier rafter versions (Aider has no MCP).
|
|
718
|
+
*
|
|
719
|
+
* Returns true on success.
|
|
452
720
|
*/
|
|
453
|
-
function
|
|
721
|
+
function installAiderRead(root) {
|
|
722
|
+
const rafterMdPath = path.join(root, "RAFTER.md");
|
|
454
723
|
const configPath = path.join(root, ".aider.conf.yml");
|
|
455
|
-
|
|
456
|
-
|
|
724
|
+
const RAFTER_READ_ENTRY = "RAFTER.md";
|
|
725
|
+
// 1. Write RAFTER.md (idempotent — the marker block is replaced in place).
|
|
726
|
+
injectInstructionFile(rafterMdPath);
|
|
727
|
+
// 2. Update .aider.conf.yml read: list.
|
|
728
|
+
let raw = "";
|
|
457
729
|
if (fs.existsSync(configPath)) {
|
|
458
|
-
|
|
730
|
+
raw = fs.readFileSync(configPath, "utf-8");
|
|
459
731
|
}
|
|
460
|
-
//
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
732
|
+
// 2a. Strip the legacy mcp-server-command line(s). Match a contiguous block
|
|
733
|
+
// that may include the preceding `# Rafter security MCP server` comment.
|
|
734
|
+
raw = raw.replace(/\n?#\s*Rafter security MCP server\s*\nmcp-server-command:\s*rafter\s+mcp\s+serve\s*\n?/g, "\n");
|
|
735
|
+
raw = raw.replace(/^mcp-server-command:\s*rafter\s+mcp\s+serve\s*\n?/gm, "");
|
|
736
|
+
// 2b. Parse remaining YAML, normalize read:.
|
|
737
|
+
let parsed = {};
|
|
738
|
+
if (raw.trim().length > 0) {
|
|
739
|
+
try {
|
|
740
|
+
const loaded = yaml.load(raw);
|
|
741
|
+
if (loaded && typeof loaded === "object" && !Array.isArray(loaded)) {
|
|
742
|
+
parsed = loaded;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
catch {
|
|
746
|
+
console.log(fmt.warning(`Existing ${configPath} was not valid YAML — preserving raw content and appending read: entry`));
|
|
747
|
+
// Append the read: line at the bottom rather than rewriting an
|
|
748
|
+
// unparseable file. We still need to make sure RAFTER.md ends up in it.
|
|
749
|
+
if (!new RegExp(`^read:\\s*\\[?[^\\n]*\\b${RAFTER_READ_ENTRY}\\b`, "m").test(raw)) {
|
|
750
|
+
const sep = raw.length > 0 && !raw.endsWith("\n") ? "\n" : "";
|
|
751
|
+
raw = `${raw}${sep}read:\n - ${RAFTER_READ_ENTRY}\n`;
|
|
752
|
+
fs.writeFileSync(configPath, raw, "utf-8");
|
|
753
|
+
}
|
|
754
|
+
console.log(fmt.success(`Installed Rafter read-only context to ${configPath}`));
|
|
755
|
+
return true;
|
|
756
|
+
}
|
|
464
757
|
}
|
|
465
|
-
//
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
758
|
+
// Normalize `read:` to a string array.
|
|
759
|
+
let reads = [];
|
|
760
|
+
if (Array.isArray(parsed.read)) {
|
|
761
|
+
reads = parsed.read.map(String);
|
|
762
|
+
}
|
|
763
|
+
else if (typeof parsed.read === "string") {
|
|
764
|
+
reads = [parsed.read];
|
|
765
|
+
}
|
|
766
|
+
if (!reads.includes(RAFTER_READ_ENTRY)) {
|
|
767
|
+
reads.push(RAFTER_READ_ENTRY);
|
|
768
|
+
}
|
|
769
|
+
parsed.read = reads;
|
|
770
|
+
fs.writeFileSync(configPath, yaml.dump(parsed), "utf-8");
|
|
771
|
+
console.log(fmt.success(`Installed Rafter read-only context to ${rafterMdPath} + ${configPath}`));
|
|
469
772
|
return true;
|
|
470
773
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
774
|
+
// Copies an entire skill source directory (SKILL.md + any subfolders like docs/)
|
|
775
|
+
// into the destination. Without this, `docs/` reference material referenced from
|
|
776
|
+
// SKILL.md would never reach users — only SKILL.md would.
|
|
777
|
+
function installSkillDir(sourceSkillDir, destSkillDir, label) {
|
|
778
|
+
const sourceSkillFile = path.join(sourceSkillDir, "SKILL.md");
|
|
779
|
+
if (!fs.existsSync(sourceSkillFile)) {
|
|
780
|
+
console.log(fmt.warning(`${label} skill template not found at ${sourceSkillFile}`));
|
|
781
|
+
return;
|
|
474
782
|
}
|
|
783
|
+
fs.mkdirSync(destSkillDir, { recursive: true });
|
|
784
|
+
fs.cpSync(sourceSkillDir, destSkillDir, { recursive: true });
|
|
785
|
+
console.log(fmt.success(`Installed ${label} skill to ${destSkillDir}`));
|
|
786
|
+
}
|
|
787
|
+
function skillResourceDir(name) {
|
|
788
|
+
return path.join(__dirname, "..", "..", "..", "resources", "skills", name);
|
|
789
|
+
}
|
|
790
|
+
function installSkillsTo(skillsDir) {
|
|
791
|
+
fs.mkdirSync(skillsDir, { recursive: true });
|
|
475
792
|
for (const skill of AGENT_SKILLS) {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
793
|
+
installSkillDir(skillResourceDir(skill.name), path.join(skillsDir, skill.name), skill.description);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
async function installClaudeCodeSkills(root) {
|
|
797
|
+
installSkillsTo(path.join(root, ".claude", "skills"));
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Sub-agents shipped by `rafter agent init --with-claude-code`.
|
|
801
|
+
*
|
|
802
|
+
* These land in <root>/.claude/agents/<name>.md and become first-class
|
|
803
|
+
* delegation targets (Agent(subagent_type='<name>')) in the calling Claude
|
|
804
|
+
* Code session — distinct from skills, which only surface in the activation
|
|
805
|
+
* prompt. Source files live in `resources/agents/<name>.md`.
|
|
806
|
+
*
|
|
807
|
+
* Keep this list in sync with the Python installer.
|
|
808
|
+
*/
|
|
809
|
+
const CLAUDE_CODE_SUBAGENTS = [
|
|
810
|
+
{ name: "rafter", description: "Rafter Security" },
|
|
811
|
+
];
|
|
812
|
+
function installClaudeCodeSubAgents(root) {
|
|
813
|
+
const agentsDir = path.join(root, ".claude", "agents");
|
|
814
|
+
if (!fs.existsSync(agentsDir)) {
|
|
815
|
+
fs.mkdirSync(agentsDir, { recursive: true });
|
|
816
|
+
}
|
|
817
|
+
for (const sub of CLAUDE_CODE_SUBAGENTS) {
|
|
818
|
+
const destPath = path.join(agentsDir, `${sub.name}.md`);
|
|
819
|
+
const srcPath = path.join(__dirname, "..", "..", "..", "resources", "agents", `${sub.name}.md`);
|
|
482
820
|
if (fs.existsSync(srcPath)) {
|
|
483
821
|
fs.copyFileSync(srcPath, destPath);
|
|
484
|
-
console.log(fmt.success(`Installed ${
|
|
822
|
+
console.log(fmt.success(`Installed ${sub.description} sub-agent to ${destPath}`));
|
|
485
823
|
}
|
|
486
824
|
else {
|
|
487
|
-
console.log(fmt.warning(`${
|
|
825
|
+
console.log(fmt.warning(`${sub.description} sub-agent template not found at ${srcPath}`));
|
|
488
826
|
}
|
|
489
827
|
}
|
|
490
828
|
}
|
|
491
|
-
async function installClaudeCodeSkills(root) {
|
|
492
|
-
installSkillsTo(path.join(root, ".claude", "skills"));
|
|
493
|
-
}
|
|
494
829
|
function installCodexSkills(root) {
|
|
495
830
|
installSkillsTo(path.join(root, ".agents", "skills"));
|
|
496
831
|
}
|
|
@@ -566,12 +901,13 @@ export function createInitCommand() {
|
|
|
566
901
|
.option("--with-cursor", "Install Cursor integration")
|
|
567
902
|
.option("--with-windsurf", "Install Windsurf integration")
|
|
568
903
|
.option("--with-continue", "Install Continue.dev integration")
|
|
569
|
-
.option("--with-
|
|
570
|
-
.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")
|
|
571
906
|
.option("-i, --interactive", "Guided setup — prompts for each detected integration")
|
|
572
|
-
.option("--update", "Re-download
|
|
907
|
+
.option("--update", "Re-download betterleaks and reinstall integrations without resetting config")
|
|
573
908
|
.option("--local", "Install integration configs project-locally (in CWD) instead of user-globally. " +
|
|
574
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).")
|
|
575
911
|
.action(async (opts) => {
|
|
576
912
|
console.log(fmt.header("Rafter Agent Security Setup"));
|
|
577
913
|
console.log(fmt.divider());
|
|
@@ -598,15 +934,26 @@ export function createInitCommand() {
|
|
|
598
934
|
// Resolve opt-in flags (--all enables all detected, --interactive prompts).
|
|
599
935
|
// In --local scope, --all is restricted to platforms that have a project-local
|
|
600
936
|
// config story (claudeCode, codex, gemini, cursor). The rest require user scope.
|
|
937
|
+
// OpenClaw returns to --all in rf-zgwj — the integration was rebuilt
|
|
938
|
+
// to ship a ClawHub-shaped skill at the canonical workspace path
|
|
939
|
+
// (~/.openclaw/workspace/skills/rafter-security/SKILL.md), so OpenClaw
|
|
940
|
+
// actually auto-discovers it now. (User-scope only; --local doesn't
|
|
941
|
+
// apply since the platform is user-config-driven.)
|
|
601
942
|
let wantOpenClaw = opts.withOpenclaw || (opts.all && !opts.local);
|
|
602
943
|
let wantClaudeCode = opts.withClaudeCode || opts.all;
|
|
603
944
|
let wantCodex = opts.withCodex || opts.all;
|
|
604
945
|
let wantGemini = opts.withGemini || opts.all;
|
|
605
946
|
let wantCursor = opts.withCursor || opts.all;
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
let
|
|
609
|
-
|
|
947
|
+
// Windsurf can install at --local scope (project rules + AGENTS.md)
|
|
948
|
+
// since rf-0vr3. User scope still also installs the MCP entry.
|
|
949
|
+
let wantWindsurf = opts.withWindsurf || opts.all;
|
|
950
|
+
// Continue.dev can install at --local scope (project rules) since rf-acz0.
|
|
951
|
+
// User scope additionally registers the MCP entry.
|
|
952
|
+
let wantContinue = opts.withContinue || opts.all;
|
|
953
|
+
// Aider can install at --local scope (writes RAFTER.md + .aider.conf.yml
|
|
954
|
+
// in cwd) since rf-du2o.
|
|
955
|
+
let wantAider = opts.withAider || opts.all;
|
|
956
|
+
let wantBetterleaks = opts.withBetterleaks || (opts.all && !opts.local);
|
|
610
957
|
// Interactive mode: prompt for each detected integration
|
|
611
958
|
if (opts.interactive && !opts.all) {
|
|
612
959
|
console.log();
|
|
@@ -625,11 +972,11 @@ export function createInitCommand() {
|
|
|
625
972
|
if (hasWindsurf && !wantWindsurf)
|
|
626
973
|
wantWindsurf = await askYesNo("Install Windsurf MCP + hooks?");
|
|
627
974
|
if (hasContinueDev && !wantContinue)
|
|
628
|
-
wantContinue = await askYesNo("Install Continue.dev MCP
|
|
975
|
+
wantContinue = await askYesNo("Install Continue.dev MCP server?");
|
|
629
976
|
if (hasAider && !wantAider)
|
|
630
977
|
wantAider = await askYesNo("Install Aider MCP server?");
|
|
631
|
-
if (!
|
|
632
|
-
|
|
978
|
+
if (!wantBetterleaks)
|
|
979
|
+
wantBetterleaks = await askYesNo("Download Betterleaks binary (enhanced scanning)?");
|
|
633
980
|
console.log();
|
|
634
981
|
}
|
|
635
982
|
// Show detected environments with opt-in hints
|
|
@@ -676,6 +1023,27 @@ export function createInitCommand() {
|
|
|
676
1023
|
if (wantAider && !hasAider)
|
|
677
1024
|
console.log(fmt.warning("Aider requested but not detected (~/.aider.conf.yml not found)"));
|
|
678
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
|
+
}
|
|
679
1047
|
// Initialize directory structure
|
|
680
1048
|
try {
|
|
681
1049
|
await manager.initialize();
|
|
@@ -694,8 +1062,8 @@ export function createInitCommand() {
|
|
|
694
1062
|
}
|
|
695
1063
|
manager.set("agent.riskLevel", opts.riskLevel);
|
|
696
1064
|
console.log(fmt.success(`Set risk level: ${opts.riskLevel}`));
|
|
697
|
-
// Check / download
|
|
698
|
-
if (
|
|
1065
|
+
// Check / download Betterleaks binary (opt-in via --with-betterleaks or --all)
|
|
1066
|
+
if (wantBetterleaks) {
|
|
699
1067
|
const binaryManager = new BinaryManager();
|
|
700
1068
|
const platformInfo = binaryManager.getPlatformInfo();
|
|
701
1069
|
// Helper: show diagnostics for a failing binary (mirrors Python's agent init)
|
|
@@ -708,56 +1076,56 @@ export function createInitCommand() {
|
|
|
708
1076
|
console.log(fmt.info("Diagnostics:"));
|
|
709
1077
|
console.log(diag);
|
|
710
1078
|
}
|
|
711
|
-
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'."));
|
|
712
1080
|
console.log();
|
|
713
1081
|
};
|
|
714
|
-
if (!opts.update && binaryManager.
|
|
1082
|
+
if (!opts.update && binaryManager.isBetterleaksInstalled()) {
|
|
715
1083
|
// Local binary exists — verify it actually works
|
|
716
|
-
const verResult = await binaryManager.
|
|
1084
|
+
const verResult = await binaryManager.verifyBetterleaksVerbose();
|
|
717
1085
|
if (verResult.ok) {
|
|
718
|
-
console.log(fmt.success(`
|
|
1086
|
+
console.log(fmt.success(`Betterleaks already installed (${verResult.stdout})`));
|
|
719
1087
|
}
|
|
720
1088
|
else {
|
|
721
|
-
console.log(fmt.warning("
|
|
722
|
-
console.log(fmt.info(` Binary: ${binaryManager.
|
|
723
|
-
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);
|
|
724
1092
|
}
|
|
725
1093
|
}
|
|
726
1094
|
else {
|
|
727
1095
|
// Not installed locally (or --update forcing re-download) — check PATH first
|
|
728
1096
|
// unless --update was passed (in that case force a fresh managed install)
|
|
729
|
-
const pathBinary = opts.update ? null : binaryManager.
|
|
1097
|
+
const pathBinary = opts.update ? null : binaryManager.findBetterleaksOnPath();
|
|
730
1098
|
if (pathBinary) {
|
|
731
|
-
const verResult = await binaryManager.
|
|
1099
|
+
const verResult = await binaryManager.verifyBetterleaksVerbose(pathBinary);
|
|
732
1100
|
if (verResult.ok) {
|
|
733
|
-
console.log(fmt.success(`
|
|
1101
|
+
console.log(fmt.success(`Betterleaks available on PATH (${verResult.stdout})`));
|
|
734
1102
|
}
|
|
735
1103
|
else {
|
|
736
|
-
console.log(fmt.warning("
|
|
1104
|
+
console.log(fmt.warning("Betterleaks found on PATH but failed to execute."));
|
|
737
1105
|
console.log(fmt.info(` Binary: ${pathBinary}`));
|
|
738
1106
|
await showDiagnostics(pathBinary, verResult);
|
|
739
1107
|
}
|
|
740
1108
|
}
|
|
741
1109
|
else if (!platformInfo.supported) {
|
|
742
|
-
console.log(fmt.info(`
|
|
1110
|
+
console.log(fmt.info(`Betterleaks not available for ${platformInfo.platform}/${platformInfo.arch}`));
|
|
743
1111
|
console.log(fmt.success("Using pattern-based scanning (21 patterns)"));
|
|
744
1112
|
}
|
|
745
1113
|
else {
|
|
746
1114
|
// Not on PATH, not installed locally — download
|
|
747
1115
|
console.log();
|
|
748
|
-
console.log(fmt.info("Downloading
|
|
1116
|
+
console.log(fmt.info("Downloading Betterleaks (enhanced secret detection)..."));
|
|
749
1117
|
try {
|
|
750
|
-
await binaryManager.
|
|
1118
|
+
await binaryManager.downloadBetterleaks((msg) => {
|
|
751
1119
|
console.log(` ${msg}`);
|
|
752
1120
|
});
|
|
753
1121
|
console.log();
|
|
754
1122
|
}
|
|
755
1123
|
catch (e) {
|
|
756
1124
|
console.log();
|
|
757
|
-
console.log(fmt.error(`
|
|
1125
|
+
console.log(fmt.error(`Betterleaks setup failed — pattern-based scanning will be used instead.`));
|
|
758
1126
|
console.log(fmt.warning(String(e)));
|
|
759
1127
|
console.log();
|
|
760
|
-
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'."));
|
|
761
1129
|
console.log();
|
|
762
1130
|
}
|
|
763
1131
|
}
|
|
@@ -793,6 +1161,7 @@ export function createInitCommand() {
|
|
|
793
1161
|
if ((hasClaudeCode || opts.withClaudeCode || (opts.local && wantClaudeCode)) && wantClaudeCode) {
|
|
794
1162
|
try {
|
|
795
1163
|
await installClaudeCodeSkills(root);
|
|
1164
|
+
installClaudeCodeSubAgents(root);
|
|
796
1165
|
installClaudeCodeHooks(root);
|
|
797
1166
|
if (scope === "project") {
|
|
798
1167
|
const components = (manager.get("agent.components") ?? {});
|
|
@@ -842,12 +1211,14 @@ export function createInitCommand() {
|
|
|
842
1211
|
console.error(fmt.error(`Failed to install Gemini CLI integration: ${e}`));
|
|
843
1212
|
}
|
|
844
1213
|
}
|
|
845
|
-
// Install Cursor MCP + hooks if opted in
|
|
1214
|
+
// Install Cursor MCP + hooks + per-skill rules + sub-agent if opted in
|
|
846
1215
|
let cursorOk = false;
|
|
847
1216
|
if ((hasCursor || (opts.local && wantCursor)) && wantCursor) {
|
|
848
1217
|
try {
|
|
849
1218
|
cursorOk = installCursorMcp(root);
|
|
850
1219
|
installCursorHooks(root);
|
|
1220
|
+
installCursorRules(root);
|
|
1221
|
+
installCursorSubAgents(root);
|
|
851
1222
|
if (cursorOk && scope === "user")
|
|
852
1223
|
manager.set("agent.environments.cursor.enabled", true);
|
|
853
1224
|
}
|
|
@@ -855,59 +1226,78 @@ export function createInitCommand() {
|
|
|
855
1226
|
console.error(fmt.error(`Failed to install Cursor integration: ${e}`));
|
|
856
1227
|
}
|
|
857
1228
|
}
|
|
858
|
-
// Install Windsurf
|
|
1229
|
+
// Install Windsurf integration if opted in.
|
|
1230
|
+
// - User scope: MCP entry under ~/.codeium/windsurf/ + per-skill rules
|
|
1231
|
+
// at .windsurf/rules/ (workspace) + AGENTS.md (workspace, written by
|
|
1232
|
+
// installGlobalInstructions below).
|
|
1233
|
+
// - Project scope (--local): per-skill rules + AGENTS.md only (no
|
|
1234
|
+
// user-scope MCP entry written from a project init).
|
|
1235
|
+
// The previous ~/.windsurf/hooks.json install was pruned: Windsurf has
|
|
1236
|
+
// no documented hook surface (rf-0vr3).
|
|
859
1237
|
let windsurfOk = false;
|
|
860
|
-
if (
|
|
1238
|
+
if (wantWindsurf && (hasWindsurf || opts.local)) {
|
|
861
1239
|
try {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
1240
|
+
if (hasWindsurf) {
|
|
1241
|
+
windsurfOk = installWindsurfMcp(root);
|
|
1242
|
+
if (windsurfOk)
|
|
1243
|
+
manager.set("agent.environments.windsurf.enabled", true);
|
|
1244
|
+
}
|
|
1245
|
+
installWindsurfRules(root);
|
|
1246
|
+
// AGENTS.md is written below in installGlobalInstructions when
|
|
1247
|
+
// platforms.windsurf is true.
|
|
1248
|
+
if (!hasWindsurf)
|
|
1249
|
+
windsurfOk = true; // local-scope success: rules + AGENTS.md
|
|
866
1250
|
}
|
|
867
1251
|
catch (e) {
|
|
868
1252
|
console.error(fmt.error(`Failed to install Windsurf integration: ${e}`));
|
|
869
1253
|
}
|
|
870
1254
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
//
|
|
1255
|
+
// Install Continue.dev integration if opted in (rf-acz0).
|
|
1256
|
+
// - User scope: per-skill rules (.continue/rules/) + MCP entry under
|
|
1257
|
+
// ~/.continue/config.json.
|
|
1258
|
+
// - Project scope (--local): rules only.
|
|
1259
|
+
// Continue.dev has no hook surface — the prior hooks install was pruned
|
|
1260
|
+
// in rf-cia phase b.
|
|
875
1261
|
let continueOk = false;
|
|
876
|
-
if (
|
|
1262
|
+
if (wantContinue && (hasContinueDev || opts.local)) {
|
|
877
1263
|
try {
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
1264
|
+
if (hasContinueDev) {
|
|
1265
|
+
continueOk = installContinueDevMcp(root);
|
|
1266
|
+
if (continueOk)
|
|
1267
|
+
manager.set("agent.environments.continueDev.enabled", true);
|
|
1268
|
+
}
|
|
1269
|
+
installContinueDevRules(root);
|
|
1270
|
+
if (!hasContinueDev)
|
|
1271
|
+
continueOk = true; // local-scope success: rules only
|
|
882
1272
|
}
|
|
883
1273
|
catch (e) {
|
|
884
1274
|
console.error(fmt.error(`Failed to install Continue.dev integration: ${e}`));
|
|
885
1275
|
}
|
|
886
1276
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
//
|
|
1277
|
+
// Install Aider integration if opted in (rf-du2o).
|
|
1278
|
+
// Aider has no MCP and no hook surface — its only intercept is the
|
|
1279
|
+
// `read:` flag in .aider.conf.yml. We write RAFTER.md and ensure
|
|
1280
|
+
// `read:` includes it. The legacy mcp-server-command YAML line (a
|
|
1281
|
+
// silent no-op) is stripped on reinstall.
|
|
891
1282
|
let aiderOk = false;
|
|
892
|
-
if (
|
|
1283
|
+
if (wantAider && (hasAider || opts.local)) {
|
|
893
1284
|
try {
|
|
894
|
-
aiderOk =
|
|
895
|
-
if (aiderOk)
|
|
1285
|
+
aiderOk = installAiderRead(root);
|
|
1286
|
+
if (aiderOk && hasAider)
|
|
896
1287
|
manager.set("agent.environments.aider.enabled", true);
|
|
897
1288
|
}
|
|
898
1289
|
catch (e) {
|
|
899
1290
|
console.error(fmt.error(`Failed to install Aider integration: ${e}`));
|
|
900
1291
|
}
|
|
901
1292
|
}
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
// Install global instruction files for platforms that support them
|
|
1293
|
+
// Install global instruction files for platforms that support them.
|
|
1294
|
+
// Cursor is intentionally absent — Cursor uses per-skill rules + the
|
|
1295
|
+
// rafter sub-agent installed in the Cursor branch above (rf-svn3).
|
|
906
1296
|
installGlobalInstructions({
|
|
907
1297
|
claudeCode: claudeCodeOk,
|
|
908
1298
|
codex: codexOk,
|
|
909
1299
|
gemini: geminiOk,
|
|
910
|
-
|
|
1300
|
+
windsurf: windsurfOk,
|
|
911
1301
|
}, root, scope);
|
|
912
1302
|
console.log();
|
|
913
1303
|
console.log(fmt.success("Agent security initialized!"));
|
|
@@ -930,7 +1320,7 @@ export function createInitCommand() {
|
|
|
930
1320
|
if (continueOk)
|
|
931
1321
|
console.log(" - Restart Continue.dev to load MCP server");
|
|
932
1322
|
if (aiderOk)
|
|
933
|
-
console.log(" - Restart Aider to load
|
|
1323
|
+
console.log(" - Restart Aider to load RAFTER.md from .aider.conf.yml read:");
|
|
934
1324
|
}
|
|
935
1325
|
else if (scope === "project") {
|
|
936
1326
|
console.log("No integrations were installed. In --local mode, pass one or more opt-in flags:");
|