@rafter-security/cli 0.11.7 → 0.12.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.
Files changed (51) hide show
  1. package/dist/commands/agent/auto-update.js +171 -0
  2. package/dist/commands/agent/components.js +50 -176
  3. package/dist/commands/agent/enable.js +11 -1
  4. package/dist/commands/agent/index.js +2 -0
  5. package/dist/commands/agent/init.js +654 -764
  6. package/dist/commands/agent/install-files.js +689 -0
  7. package/dist/commands/agent/instruction-block.js +82 -40
  8. package/dist/commands/agent/scan.js +70 -21
  9. package/dist/commands/agent/status.js +11 -0
  10. package/dist/commands/agent/update.js +179 -0
  11. package/dist/commands/agent/verify.js +11 -0
  12. package/dist/commands/backend/get.js +5 -10
  13. package/dist/commands/backend/run.js +10 -20
  14. package/dist/commands/backend/scan-status.js +16 -3
  15. package/dist/commands/backend/usage.js +3 -6
  16. package/dist/commands/brief.js +6 -12
  17. package/dist/commands/counters.js +146 -0
  18. package/dist/commands/gates.js +36 -0
  19. package/dist/commands/hook/pretool.js +22 -9
  20. package/dist/commands/mcp/server.js +1 -1
  21. package/dist/commands/skill/registry.js +48 -0
  22. package/dist/core/usage-counters.js +439 -0
  23. package/dist/index.js +36 -0
  24. package/dist/scanners/gate-scanner.js +721 -0
  25. package/dist/scanners/regex-scanner.js +26 -25
  26. package/dist/utils/skill-manager.js +8 -338
  27. package/package.json +1 -1
  28. package/resources/continue-rules/rafter-code-review.md +6 -6
  29. package/resources/continue-rules/rafter-secure-design.md +3 -4
  30. package/resources/continue-rules/rafter-skill-review.md +4 -4
  31. package/resources/continue-rules/rafter.md +2 -2
  32. package/resources/cursor-rules/rafter-code-review.mdc +6 -6
  33. package/resources/cursor-rules/rafter-secure-design.mdc +3 -4
  34. package/resources/cursor-rules/rafter-skill-review.mdc +4 -4
  35. package/resources/cursor-rules/rafter.mdc +2 -2
  36. package/resources/rafter-security-skill.md +1 -1
  37. package/resources/shipped-hashes.json +332 -0
  38. package/resources/skills/rafter/SKILL.md +7 -7
  39. package/resources/skills/rafter/docs/cli-reference.md +37 -10
  40. package/resources/skills/rafter/docs/finding-triage.md +1 -1
  41. package/resources/skills/rafter/docs/guardrails.md +2 -2
  42. package/resources/skills/rafter/docs/shift-left.md +4 -4
  43. package/resources/skills/rafter-code-review/SKILL.md +43 -14
  44. package/resources/skills/rafter-code-review/docs/llm.md +2 -2
  45. package/resources/skills/rafter-code-review/docs/security-gates.md +53 -0
  46. package/resources/skills/rafter-secure-design/SKILL.md +1 -0
  47. package/resources/skills/rafter-skill-review/SKILL.md +1 -0
  48. package/resources/windsurf-rules/rafter-code-review.md +6 -6
  49. package/resources/windsurf-rules/rafter-secure-design.md +3 -4
  50. package/resources/windsurf-rules/rafter-skill-review.md +4 -4
  51. package/resources/windsurf-rules/rafter.md +2 -2
@@ -0,0 +1,171 @@
1
+ /**
2
+ * The pretool hook's auto-update: after a CLI upgrade, bring installed skill,
3
+ * rule and sub-agent files up to this version without waiting for the user to
4
+ * run `rafter agent update`.
5
+ *
6
+ * It only rewrites files whose hash proves they hold rafter's own content (the
7
+ * InstallSession policy); a file the user modified is kept, with the new
8
+ * version written beside it as <file>.rafter-new and reported. Hooks, MCP
9
+ * entries and instruction blocks are left to `rafter agent update`, so the
10
+ * manifest keeps its old cliVersion and `agent status` still says to run it.
11
+ *
12
+ * Runs at most once a day per CLI version (stamp file), user scope only, never
13
+ * throws, and writes nothing to stdout (stdout is the hook's decision).
14
+ * RAFTER_DISABLE_AUTO_UPDATE=1 turns it off. Mirrors
15
+ * python/rafter_cli/commands/auto_update.py.
16
+ */
17
+ import fs from "fs";
18
+ import os from "os";
19
+ import path from "path";
20
+ import { InstallSession, NEW_VERSION_SUFFIX, WHOLE_FILE_PLATFORMS, cleanupLegacyOpenClaw, cleanupRetiredRules, cliVersion, isSymlink, manifestPath, platformArtifacts, } from "./install-files.js";
21
+ import { detectInstalledPlatforms, versionOlder } from "./update.js";
22
+ export const AUTO_UPDATE_INTERVAL_MS = 24 * 60 * 60 * 1000;
23
+ /** A lock older than this is from a hook that died mid-update. */
24
+ const LOCK_STALE_MS = 60 * 1000;
25
+ export function autoUpdateStampPath(home) {
26
+ return path.join(home, ".rafter", ".update-check");
27
+ }
28
+ function readJson(p) {
29
+ try {
30
+ return JSON.parse(fs.readFileSync(p, "utf-8"));
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ }
36
+ /** True when the stamp says this version was checked within the interval. */
37
+ function checkedRecently(home, version, now) {
38
+ const stamp = readJson(autoUpdateStampPath(home));
39
+ return !!stamp && stamp.version === version && typeof stamp.checkedAt === "number" &&
40
+ now - stamp.checkedAt >= 0 && now - stamp.checkedAt < AUTO_UPDATE_INTERVAL_MS;
41
+ }
42
+ function writeStamp(home, version, now) {
43
+ const p = autoUpdateStampPath(home);
44
+ fs.mkdirSync(path.dirname(p), { recursive: true });
45
+ fs.writeFileSync(p, JSON.stringify({ version, checkedAt: now }) + "\n", "utf-8");
46
+ }
47
+ /** Take the update lock; false when another hook holds a live one. */
48
+ function acquireLock(lock, now) {
49
+ for (let attempt = 0; attempt < 2; attempt++) {
50
+ try {
51
+ fs.closeSync(fs.openSync(lock, "wx"));
52
+ return true;
53
+ }
54
+ catch (e) {
55
+ if (e.code !== "EEXIST")
56
+ return false;
57
+ try {
58
+ if (now - fs.statSync(lock).mtimeMs < LOCK_STALE_MS)
59
+ return false;
60
+ fs.unlinkSync(lock);
61
+ }
62
+ catch {
63
+ return false;
64
+ }
65
+ }
66
+ }
67
+ return false;
68
+ }
69
+ /**
70
+ * The installed unit an artifact belongs to: a skill directory for skill files,
71
+ * otherwise the file itself. A unit with no file on disk was never installed or
72
+ * was removed by the user, and the hook does not bring it back.
73
+ */
74
+ function unitOf(a) {
75
+ const m = a.resourceKey.match(/^skills\/([^/]+)\//);
76
+ if (!m)
77
+ return a.dest;
78
+ const rel = a.resourceKey.slice("skills/".length + m[1].length + 1);
79
+ return a.dest.slice(0, a.dest.length - rel.length - 1);
80
+ }
81
+ /**
82
+ * Apply this CLI's whole-file content to the user-scope install if it is older.
83
+ * Returns null when nothing ran (checked recently, already current, nothing
84
+ * installed, disabled, or another hook is running it).
85
+ */
86
+ export function maybeAutoUpdate(opts = {}) {
87
+ if (/^(1|true|yes)$/i.test(process.env.RAFTER_DISABLE_AUTO_UPDATE ?? ""))
88
+ return null;
89
+ const home = opts.home ?? os.homedir();
90
+ const now = opts.now ?? Date.now();
91
+ const version = opts.version ?? cliVersion();
92
+ if (checkedRecently(home, version, now))
93
+ return null;
94
+ const recorded = readJson(manifestPath(home))?.cliVersion;
95
+ if (typeof recorded === "string" && !versionOlder(recorded, version)) {
96
+ writeStamp(home, version, now);
97
+ return null;
98
+ }
99
+ const platforms = detectInstalledPlatforms(home, "user").filter((p) => WHOLE_FILE_PLATFORMS.includes(p));
100
+ if (platforms.length === 0) {
101
+ writeStamp(home, version, now);
102
+ return null;
103
+ }
104
+ const lock = path.join(home, ".rafter", ".update-lock");
105
+ fs.mkdirSync(path.dirname(lock), { recursive: true });
106
+ if (!acquireLock(lock, now))
107
+ return null;
108
+ try {
109
+ // Stamp first: an update that fails is not retried on every tool call.
110
+ writeStamp(home, version, now);
111
+ const silent = { info: () => { }, warn: () => { } };
112
+ const session = new InstallSession({ root: home, out: silent, version, keepManifestVersion: true });
113
+ for (const platform of platforms) {
114
+ const artifacts = platformArtifacts(platform, home);
115
+ const present = new Set(artifacts.filter((a) => fs.existsSync(a.dest)).map(unitOf));
116
+ // A symlink at a file or its .rafter-new is skipped: an unattended write
117
+ // must not follow a link to a path nobody chose. `agent update` still does.
118
+ session.applyAll(artifacts.filter((a) => present.has(unitOf(a)) && !isSymlink(a.dest) && !isSymlink(a.dest + NEW_VERSION_SUFFIX)));
119
+ }
120
+ // Retired rule files and the legacy OpenClaw file go only when their hash
121
+ // is rafter's. Retired skill directories are left to `agent update`: there
122
+ // a publisher tag alone is enough to remove one, and that is not hash proof.
123
+ if (platforms.includes("cursor"))
124
+ cleanupRetiredRules(session, "cursor");
125
+ if (platforms.includes("windsurf"))
126
+ cleanupRetiredRules(session, "windsurf");
127
+ if (platforms.includes("continue"))
128
+ cleanupRetiredRules(session, "continue");
129
+ if (platforms.includes("openclaw"))
130
+ cleanupLegacyOpenClaw(session);
131
+ session.save();
132
+ return {
133
+ updated: session.count("updated") + session.count("added"),
134
+ needsReconcile: session.keptFiles(),
135
+ version,
136
+ };
137
+ }
138
+ finally {
139
+ try {
140
+ fs.unlinkSync(lock);
141
+ }
142
+ catch {
143
+ /* already gone */
144
+ }
145
+ }
146
+ }
147
+ /** The one stderr line the hook prints after an auto-update; null when there is nothing to say. */
148
+ export function autoUpdateLine(r) {
149
+ if (!r || (r.updated === 0 && r.needsReconcile.length === 0))
150
+ return null;
151
+ const parts = [];
152
+ if (r.updated > 0)
153
+ parts.push(`updated ${r.updated} skill/rule file${r.updated === 1 ? "" : "s"} to ${r.version}`);
154
+ const n = r.needsReconcile.length;
155
+ if (n > 0) {
156
+ parts.push(`${n} file${n === 1 ? "" : "s"} you modified need${n === 1 ? "s" : ""} reconciling with ` +
157
+ `${r.needsReconcile[0]}${NEW_VERSION_SUFFIX}${n > 1 ? " and others" : ""} (run 'rafter agent status')`);
158
+ }
159
+ return `rafter: ${parts.join("; ")}`;
160
+ }
161
+ /** Hook entry point: run the auto-update and print its line to stderr. Never throws. */
162
+ export function runHookAutoUpdate() {
163
+ try {
164
+ const line = autoUpdateLine(maybeAutoUpdate());
165
+ if (line)
166
+ process.stderr.write(line + "\n");
167
+ }
168
+ catch {
169
+ /* the hook's decision is already written; an update failure must not change it */
170
+ }
171
+ }
@@ -2,11 +2,10 @@ import fs from "fs";
2
2
  import path from "path";
3
3
  import os from "os";
4
4
  import yaml from "js-yaml";
5
- import { RAFTER_MARKER_START, RAFTER_MARKER_END, injectInstructionFile, } from "./instruction-block.js";
5
+ import { RAFTER_MARKER_START, RAFTER_MARKER_END, AIDER_NOTE_MARKER_START, AIDER_NOTE_MARKER_END, injectInstructionFile, injectAiderNote, retireInstructionFile, stripMarkerBlock, } from "./instruction-block.js";
6
6
  import { ConfigManager } from "../../core/config-manager.js";
7
- import { fileURLToPath } from "url";
8
- const __filename = fileURLToPath(import.meta.url);
9
- const __dirname = path.dirname(__filename);
7
+ import { KNOWN_SKILL_NAMES } from "../skill/registry.js";
8
+ import { InstallSession, RULE_SKILLS, cleanupLegacyOpenClaw, cleanupRetiredRules, cleanupRetiredSkills, cursorAgentArtifacts, openclawSkillArtifacts, openclawSkillPath, ruleArtifacts, skillArtifacts, } from "./install-files.js";
10
9
  const RAFTER_MCP_ENTRY = {
11
10
  command: "rafter",
12
11
  args: ["mcp", "serve"],
@@ -45,22 +44,6 @@ function hookEntryMatchesRafter(entry, prefix) {
45
44
  return false;
46
45
  return hooks.some((h) => String(h?.command ?? "").startsWith(prefix));
47
46
  }
48
- /** Strip the rafter marker block from a text file, writing only if the file actually changed. */
49
- function stripMarkerBlock(filePath) {
50
- if (!fs.existsSync(filePath))
51
- return false;
52
- const content = fs.readFileSync(filePath, "utf-8");
53
- const startIdx = content.indexOf(RAFTER_MARKER_START);
54
- const endIdx = content.indexOf(RAFTER_MARKER_END);
55
- if (startIdx === -1 || endIdx === -1)
56
- return false;
57
- const before = content.slice(0, startIdx).trimEnd();
58
- const after = content.slice(endIdx + RAFTER_MARKER_END.length);
59
- const trailing = after.replace(/^\s*\n+/, "");
60
- const next = (before ? before + "\n" : "") + trailing;
61
- fs.writeFileSync(filePath, next, "utf-8");
62
- return true;
63
- }
64
47
  /** True when a file exists and contains the rafter marker block. */
65
48
  function hasMarkerBlock(filePath) {
66
49
  if (!fs.existsSync(filePath))
@@ -155,20 +138,22 @@ function claudeCodeInstructions() {
155
138
  },
156
139
  };
157
140
  }
158
- function skillTemplatePath(name) {
159
- return path.join(__dirname, "..", "..", "..", "resources", "skills", name, "SKILL.md");
141
+ /** Run `fn` with the caller's session, or a fresh one that is saved afterwards. */
142
+ function withSession(session, fn) {
143
+ const s = session ?? new InstallSession({
144
+ root: os.homedir(),
145
+ out: { info: (m) => console.log(m ?? ""), warn: (m) => console.log(m) },
146
+ });
147
+ fn(s);
148
+ if (!session)
149
+ s.save();
160
150
  }
161
151
  /**
162
152
  * Canonical rafter-authored skills that a per-platform "skills" component
163
- * installs. Mirrors `python/rafter_cli/commands/agent_components.py`. Keep in
164
- * sync with the SKILL.md files shipped under `node/resources/skills/`.
153
+ * installs — the single `KNOWN_SKILL_NAMES` list in `../skill/registry.js`,
154
+ * so this and `agent init` (install-files.ts) can't drift apart.
165
155
  */
166
- const COMPONENT_SKILL_NAMES = [
167
- "rafter",
168
- "rafter-secure-design",
169
- "rafter-code-review",
170
- "rafter-skill-review",
171
- ];
156
+ const COMPONENT_SKILL_NAMES = KNOWN_SKILL_NAMES;
172
157
  function skillsDirComponent(opts) {
173
158
  const destPaths = COMPONENT_SKILL_NAMES.map((name) => path.join(opts.skillsBaseDir, name, "SKILL.md"));
174
159
  return {
@@ -179,18 +164,13 @@ function skillsDirComponent(opts) {
179
164
  detectDir: opts.detectDir,
180
165
  path: opts.skillsBaseDir,
181
166
  isInstalled: () => destPaths.some((p) => fs.existsSync(p)),
182
- install: () => {
183
- for (const name of COMPONENT_SKILL_NAMES) {
184
- const src = skillTemplatePath(name);
185
- const dst = path.join(opts.skillsBaseDir, name, "SKILL.md");
186
- if (!fs.existsSync(src))
187
- continue;
188
- const dir = path.dirname(dst);
189
- if (!fs.existsSync(dir))
190
- fs.mkdirSync(dir, { recursive: true });
191
- fs.copyFileSync(src, dst);
192
- }
193
- },
167
+ install: (session) => withSession(session, (s) => {
168
+ // SKILL.md only, matching what uninstall removes (init also installs docs/).
169
+ s.applyAll(skillArtifacts(opts.skillsBaseDir, opts.platform, opts.id).filter((a) => path.basename(a.dest) === "SKILL.md"));
170
+ // Clean up any rafter skill directory left over from a rename — never a
171
+ // user's own or a modified one (publisher tag or hash proof required).
172
+ cleanupRetiredSkills(s, opts.skillsBaseDir);
173
+ }),
194
174
  uninstall: () => {
195
175
  for (const p of destPaths) {
196
176
  if (fs.existsSync(p)) {
@@ -385,35 +365,7 @@ function cursorHooks() {
385
365
  },
386
366
  };
387
367
  }
388
- const CURSOR_RULE_SKILLS = [
389
- "rafter",
390
- "rafter-secure-design",
391
- "rafter-code-review",
392
- "rafter-skill-review",
393
- ];
394
- function cursorRuleSourceDir() {
395
- // After build: dist/commands/agent/components.js -> ../../../resources/cursor-rules
396
- const candidates = [
397
- path.resolve(__dirname, "..", "..", "..", "resources", "cursor-rules"),
398
- path.resolve(__dirname, "..", "..", "resources", "cursor-rules"),
399
- ];
400
- return candidates.find((p) => fs.existsSync(p)) ?? null;
401
- }
402
- function cursorAgentSourceFile() {
403
- const candidates = [
404
- path.resolve(__dirname, "..", "..", "..", "resources", "agents", "rafter.md"),
405
- path.resolve(__dirname, "..", "..", "resources", "agents", "rafter.md"),
406
- ];
407
- return candidates.find((p) => fs.existsSync(p)) ?? null;
408
- }
409
- /**
410
- * Cursor instructions = per-skill rules under .cursor/rules/ + the rafter
411
- * sub-agent at .cursor/agents/rafter.md (rf-svn3). The legacy consolidated
412
- * rafter-security.mdc was retired.
413
- *
414
- * `path` reports the rules dir for diagnostics; install/uninstall manage
415
- * both rules and the sub-agent file together.
416
- */
368
+ const CURSOR_RULE_SKILLS = RULE_SKILLS;
417
369
  function cursorInstructions() {
418
370
  const home = os.homedir();
419
371
  const rulesDir = path.join(home, ".cursor", "rules");
@@ -430,58 +382,24 @@ function cursorInstructions() {
430
382
  const rulesPresent = CURSOR_RULE_SKILLS.every((n) => fs.existsSync(path.join(rulesDir, `${n}.mdc`)));
431
383
  return rulesPresent && fs.existsSync(agentPath);
432
384
  },
433
- install: () => {
434
- fs.mkdirSync(rulesDir, { recursive: true });
435
- const ruleSrc = cursorRuleSourceDir();
436
- if (ruleSrc) {
437
- for (const name of CURSOR_RULE_SKILLS) {
438
- const src = path.join(ruleSrc, `${name}.mdc`);
439
- if (fs.existsSync(src)) {
440
- fs.copyFileSync(src, path.join(rulesDir, `${name}.mdc`));
441
- }
442
- }
443
- }
444
- // Migrate away from the legacy consolidated rule.
445
- if (fs.existsSync(legacyPath)) {
446
- try {
447
- fs.unlinkSync(legacyPath);
448
- }
449
- catch { /* best-effort */ }
450
- }
451
- const agentSrc = cursorAgentSourceFile();
452
- if (agentSrc) {
453
- fs.mkdirSync(path.dirname(agentPath), { recursive: true });
454
- const raw = fs.readFileSync(agentSrc, "utf-8");
455
- const cursored = stripFrontmatterField(raw, "tools");
456
- fs.writeFileSync(agentPath, cursored, "utf-8");
457
- }
458
- },
385
+ install: (session) => withSession(session, (s) => {
386
+ s.applyAll(ruleArtifacts("cursor", home));
387
+ cleanupRetiredRules(s, "cursor");
388
+ retireInstructionFile(legacyPath);
389
+ s.applyAll(cursorAgentArtifacts(home));
390
+ }),
459
391
  uninstall: () => {
460
392
  for (const name of CURSOR_RULE_SKILLS) {
461
393
  const p = path.join(rulesDir, `${name}.mdc`);
462
394
  if (fs.existsSync(p))
463
395
  fs.rmSync(p, { force: true });
464
396
  }
465
- if (fs.existsSync(legacyPath))
466
- fs.rmSync(legacyPath, { force: true });
397
+ retireInstructionFile(legacyPath);
467
398
  if (fs.existsSync(agentPath))
468
399
  fs.rmSync(agentPath, { force: true });
469
400
  },
470
401
  };
471
402
  }
472
- /** Strip a single-line frontmatter field from a markdown file's frontmatter. */
473
- function stripFrontmatterField(content, field) {
474
- if (!content.startsWith("---\n"))
475
- return content;
476
- const fmEnd = content.indexOf("\n---", 4);
477
- if (fmEnd === -1)
478
- return content;
479
- const frontmatter = content.slice(4, fmEnd);
480
- const body = content.slice(fmEnd);
481
- const re = new RegExp(`^${field}:\\s.*$`, "m");
482
- const cleaned = frontmatter.replace(re, "").replace(/\n\n+/g, "\n").replace(/^\n/, "");
483
- return `---\n${cleaned}${body}`;
484
- }
485
403
  function cursorMcp() {
486
404
  const home = os.homedir();
487
405
  const mcpPath = path.join(home, ".cursor", "mcp.json");
@@ -608,20 +526,7 @@ function geminiMcp() {
608
526
  },
609
527
  };
610
528
  }
611
- /** Skills shipped as Windsurf rules at .windsurf/rules/<skill>.md (rf-0vr3). */
612
- const WINDSURF_RULE_SKILLS = [
613
- "rafter",
614
- "rafter-secure-design",
615
- "rafter-code-review",
616
- "rafter-skill-review",
617
- ];
618
- function windsurfRuleSourceDir() {
619
- const candidates = [
620
- path.resolve(__dirname, "..", "..", "..", "resources", "windsurf-rules"),
621
- path.resolve(__dirname, "..", "..", "resources", "windsurf-rules"),
622
- ];
623
- return candidates.find((p) => fs.existsSync(p)) ?? null;
624
- }
529
+ const WINDSURF_RULE_SKILLS = RULE_SKILLS;
625
530
  /**
626
531
  * Windsurf rules component: per-skill files at .windsurf/rules/<skill>.md.
627
532
  *
@@ -644,18 +549,9 @@ function windsurfRules() {
644
549
  detectDir: path.join(home, ".codeium", "windsurf"),
645
550
  path: rulesDir,
646
551
  isInstalled: () => WINDSURF_RULE_SKILLS.every((n) => fs.existsSync(path.join(rulesDir, `${n}.md`))),
647
- install: () => {
648
- fs.mkdirSync(rulesDir, { recursive: true });
649
- const src = windsurfRuleSourceDir();
650
- if (!src)
651
- return;
652
- for (const name of WINDSURF_RULE_SKILLS) {
653
- const from = path.join(src, `${name}.md`);
654
- if (fs.existsSync(from)) {
655
- fs.copyFileSync(from, path.join(rulesDir, `${name}.md`));
656
- }
657
- }
658
- },
552
+ install: (session) => withSession(session, (s) => {
553
+ s.applyAll(ruleArtifacts("windsurf", process.cwd()));
554
+ }),
659
555
  uninstall: () => {
660
556
  for (const name of WINDSURF_RULE_SKILLS) {
661
557
  const p = path.join(rulesDir, `${name}.md`);
@@ -699,20 +595,7 @@ function windsurfMcp() {
699
595
  },
700
596
  };
701
597
  }
702
- /** Skills shipped as Continue.dev rules at .continue/rules/<skill>.md (rf-acz0). */
703
- const CONTINUE_RULE_SKILLS = [
704
- "rafter",
705
- "rafter-secure-design",
706
- "rafter-code-review",
707
- "rafter-skill-review",
708
- ];
709
- function continueRuleSourceDir() {
710
- const candidates = [
711
- path.resolve(__dirname, "..", "..", "..", "resources", "continue-rules"),
712
- path.resolve(__dirname, "..", "..", "resources", "continue-rules"),
713
- ];
714
- return candidates.find((p) => fs.existsSync(p)) ?? null;
715
- }
598
+ const CONTINUE_RULE_SKILLS = RULE_SKILLS;
716
599
  /** Continue.dev rules component: .continue/rules/<skill>.md, workspace-scope (rf-acz0). */
717
600
  function continueRules() {
718
601
  const home = os.homedir();
@@ -725,18 +608,9 @@ function continueRules() {
725
608
  detectDir: path.join(home, ".continue"),
726
609
  path: rulesDir,
727
610
  isInstalled: () => CONTINUE_RULE_SKILLS.every((n) => fs.existsSync(path.join(rulesDir, `${n}.md`))),
728
- install: () => {
729
- fs.mkdirSync(rulesDir, { recursive: true });
730
- const src = continueRuleSourceDir();
731
- if (!src)
732
- return;
733
- for (const name of CONTINUE_RULE_SKILLS) {
734
- const from = path.join(src, `${name}.md`);
735
- if (fs.existsSync(from)) {
736
- fs.copyFileSync(from, path.join(rulesDir, `${name}.md`));
737
- }
738
- }
739
- },
611
+ install: (session) => withSession(session, (s) => {
612
+ s.applyAll(ruleArtifacts("continue", process.cwd()));
613
+ }),
740
614
  uninstall: () => {
741
615
  for (const name of CONTINUE_RULE_SKILLS) {
742
616
  const p = path.join(rulesDir, `${name}.md`);
@@ -950,6 +824,7 @@ function aiderRead() {
950
824
  },
951
825
  install: () => {
952
826
  injectInstructionFile(rafterMdPath);
827
+ injectAiderNote(rafterMdPath);
953
828
  let raw = fs.existsSync(configPath) ? fs.readFileSync(configPath, "utf-8") : "";
954
829
  // Strip legacy mcp-server-command silent-no-op (rf-du2o migration).
955
830
  raw = raw.replace(/\n?#\s*Rafter security MCP server\s*\nmcp-server-command:\s*rafter\s+mcp\s+serve\s*\n?/g, "\n");
@@ -985,7 +860,11 @@ function aiderRead() {
985
860
  // Excise only the managed block; any user content in RAFTER.md survives.
986
861
  // If the file was ours alone (nothing but the block), remove it.
987
862
  // A RAFTER.md with no markers is user-authored — leave it untouched.
988
- if (fs.existsSync(rafterMdPath) && stripMarkerBlock(rafterMdPath)) {
863
+ // Both managed blocks go: the main one and the Aider note that refers
864
+ // to "the skill names above" — left alone it would be an orphan.
865
+ const strippedMain = stripMarkerBlock(rafterMdPath);
866
+ const strippedNote = stripMarkerBlock(rafterMdPath, AIDER_NOTE_MARKER_START, AIDER_NOTE_MARKER_END);
867
+ if (fs.existsSync(rafterMdPath) && (strippedMain || strippedNote)) {
989
868
  try {
990
869
  if (fs.readFileSync(rafterMdPath, "utf-8").trim() === "") {
991
870
  fs.rmSync(rafterMdPath, { force: true });
@@ -1016,24 +895,19 @@ function aiderRead() {
1016
895
  }
1017
896
  function openclawSkill() {
1018
897
  const home = os.homedir();
1019
- const skillPath = path.join(home, ".openclaw", "skills", "rafter-security.md");
898
+ const skillPath = openclawSkillPath(home);
1020
899
  return {
1021
900
  id: "openclaw.skills",
1022
901
  platform: "openclaw",
1023
902
  kind: "skills",
1024
- description: "OpenClaw rafter-security skill",
903
+ description: "OpenClaw rafter-security skill (~/.openclaw/workspace/skills/rafter-security/SKILL.md)",
1025
904
  detectDir: path.join(home, ".openclaw"),
1026
905
  path: skillPath,
1027
906
  isInstalled: () => fs.existsSync(skillPath),
1028
- install: () => {
1029
- const dir = path.dirname(skillPath);
1030
- if (!fs.existsSync(dir))
1031
- fs.mkdirSync(dir, { recursive: true });
1032
- const template = skillTemplatePath("rafter");
1033
- if (fs.existsSync(template)) {
1034
- fs.copyFileSync(template, skillPath);
1035
- }
1036
- },
907
+ install: (session) => withSession(session, (s) => {
908
+ s.applyAll(openclawSkillArtifacts(home));
909
+ cleanupLegacyOpenClaw(s);
910
+ }),
1037
911
  uninstall: () => {
1038
912
  if (fs.existsSync(skillPath))
1039
913
  fs.rmSync(skillPath, { force: true });
@@ -1,7 +1,9 @@
1
1
  import { Command } from "commander";
2
2
  import fs from "fs";
3
+ import os from "os";
3
4
  import { resolveComponent, recordComponentState, getComponentRegistry } from "./components.js";
4
5
  import { fmt } from "../../utils/formatter.js";
6
+ import { InstallSession, reportKeptSummary, reportUnchangedSummary } from "./install-files.js";
5
7
  /**
6
8
  * `rafter agent enable <component-id>...` — install one or more specific components.
7
9
  * This is the fine-grained complement to `rafter agent init --with-<platform>`; it
@@ -17,6 +19,11 @@ export function createEnableCommand() {
17
19
  .option("--force", "Install even if platform is not detected on this machine")
18
20
  .action((components, opts) => {
19
21
  let exitCode = 0;
22
+ // Skill / rule / sub-agent files keep local edits, as in `agent init`.
23
+ const session = new InstallSession({
24
+ root: os.homedir(),
25
+ out: { info: (m) => console.log(m ?? ""), warn: (m) => console.log(m) },
26
+ });
20
27
  const seenIds = new Set();
21
28
  for (const raw of components) {
22
29
  if (seenIds.has(raw))
@@ -36,7 +43,7 @@ export function createEnableCommand() {
36
43
  continue;
37
44
  }
38
45
  try {
39
- spec.install();
46
+ spec.install(session);
40
47
  recordComponentState(spec.id, true);
41
48
  console.log(fmt.success(`Enabled ${spec.id} → ${spec.path}`));
42
49
  }
@@ -45,6 +52,9 @@ export function createEnableCommand() {
45
52
  exitCode = 1;
46
53
  }
47
54
  }
55
+ session.save();
56
+ reportUnchangedSummary(session);
57
+ reportKeptSummary(session, "remove the file and re-run 'rafter agent enable' to replace it");
48
58
  process.exit(exitCode);
49
59
  });
50
60
  }
@@ -16,6 +16,7 @@ import { createBaselineCommand } from "./baseline.js";
16
16
  import { createListCommand } from "./list.js";
17
17
  import { createEnableCommand } from "./enable.js";
18
18
  import { createDisableCommand } from "./disable.js";
19
+ import { createUpdateCommand } from "./update.js";
19
20
  export function createAgentCommand() {
20
21
  const agent = new Command("agent")
21
22
  .description("Agent security features");
@@ -37,5 +38,6 @@ export function createAgentCommand() {
37
38
  agent.addCommand(createListCommand());
38
39
  agent.addCommand(createEnableCommand());
39
40
  agent.addCommand(createDisableCommand());
41
+ agent.addCommand(createUpdateCommand());
40
42
  return agent;
41
43
  }