claude-everything-workflow 0.2.5 → 0.2.7

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 (43) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/.mcp.json +14 -0
  4. package/AGENTS.md +6 -0
  5. package/CLAUDE.md +2 -0
  6. package/README.md +20 -0
  7. package/README.zh-CN.md +20 -0
  8. package/agents/e2e-runner.md +1 -0
  9. package/bin/claude-everything-workflow.js +15 -0
  10. package/docs/plugins.md +4 -0
  11. package/harness/manifest.json +1 -1
  12. package/package.json +3 -1
  13. package/rules/01-base.md +4 -1
  14. package/rules/02-implementation.md +1 -1
  15. package/rules/08-specialty-rules-index.md +1 -1
  16. package/rules/common/testing.md +7 -0
  17. package/scripts/install-rules.js +8 -4
  18. package/scripts/install.ps1 +28 -44
  19. package/scripts/install.sh +31 -3
  20. package/scripts/learning/migrate-homunculus.js +10 -5
  21. package/scripts/learning/project-utils.js +9 -0
  22. package/scripts/learning/promote.js +27 -10
  23. package/scripts/legacy-common-rule-hashes.json +16 -1
  24. package/scripts/merge-claude-settings.cjs +88 -25
  25. package/scripts/verify/install-rules.test.js +213 -11
  26. package/scripts/verify/learning.test.js +122 -0
  27. package/scripts/verify/metadata-checks.js +1 -1
  28. package/scripts/verify/plugin-distribution.test.js +3 -0
  29. package/scripts/verify/skill-invocation.test.js +6 -1
  30. package/scripts/verify/skill-manifest-checks.js +7 -4
  31. package/scripts/verify/workflow-checks.js +0 -1
  32. package/skills/README.md +1 -1
  33. package/skills/code-review/SKILL.md +7 -2
  34. package/skills/code-review/references/spec-reviewer-prompt.md +7 -4
  35. package/skills/continuous-learning-v2/SKILL.md +1 -0
  36. package/skills/continuous-learning-v2/config.json +1 -1
  37. package/skills/continuous-learning-v2/hooks/observe-v2.js +2 -9
  38. package/skills/e2e-testing/SKILL.md +1 -1
  39. package/skills/feature-acceptance/SKILL.md +13 -5
  40. package/skills/feature-acceptance/references/project-verification.md +55 -0
  41. package/skills/implement/SKILL.md +3 -1
  42. package/skills/implement/agents/openai.yaml +2 -0
  43. package/skills/using-superpowers/SKILL.md +9 -1
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  const fs = require("fs");
4
+ const os = require("os");
5
+ const path = require("path");
6
+
7
+ const RUNNER = "hooks/runtime/run-with-flags.js";
8
+ const LEGACY_RUNNER = "scripts/hooks/run-with-flags.js";
9
+ const HOME_PREFIX = "$HOME/.claude";
4
10
 
5
11
  const LEGACY_HOOK_PATTERNS = [
6
- "scripts/hooks/run-with-flags.js",
12
+ LEGACY_RUNNER,
7
13
  "scripts/hooks/commit-quality.js",
8
14
  "scripts/hooks/session-start.js",
9
15
  "scripts/hooks/session-end.js",
@@ -17,40 +23,94 @@ const LEGACY_HOOK_PATTERNS = [
17
23
  "hooks/pre-compact.js",
18
24
  "hooks/runtime/session-utils.js",
19
25
  ];
26
+ const LEGACY_WRAPPED_TARGETS = new Map([
27
+ ["session:start", ["scripts/hooks/session-start.js", "hooks/session-start.js"]],
28
+ ["session:end", ["scripts/hooks/session-end.js", "hooks/session-end.js"]],
29
+ ["stop:evaluate-session", ["hooks/evaluate-session.js"]],
30
+ ["precompact:save-context", ["hooks/pre-compact.js"]],
31
+ ["post:observe", ["hooks/observe.js"]],
32
+ ["post:write:console-log", ["hooks/check-console-log.js"]],
33
+ ["post:multiedit:console-log", ["hooks/check-console-log.js"]],
34
+ ]);
20
35
 
21
- function isLegacyHook(hookDefinition) {
22
- if (typeof hookDefinition !== "object" || !hookDefinition.command) return false;
23
- return LEGACY_HOOK_PATTERNS.some((pattern) => hookDefinition.command.includes(pattern));
36
+ function installedPath(script, installRoot) {
37
+ if (!script) return undefined;
38
+ const prefix = [HOME_PREFIX, installRoot.replace(/\\/g, "/")].find((prefix) =>
39
+ process.platform === "win32"
40
+ ? script.toLowerCase().startsWith(`${prefix.toLowerCase()}/`)
41
+ : script.startsWith(`${prefix}/`));
42
+ return prefix ? script.slice(prefix.length + 1) : undefined;
24
43
  }
25
44
 
26
- function filterHooks(entries) {
27
- if (!Array.isArray(entries)) return entries;
28
- return entries
29
- .map((entry) => {
30
- if (!entry || !Array.isArray(entry.hooks)) return entry;
31
- const hooks = entry.hooks.filter((hook) => !isLegacyHook(hook));
32
- return { ...entry, hooks };
33
- })
34
- .filter((entry) => entry.hooks && entry.hooks.length > 0);
45
+ function hookCommand(hook, installRoot) {
46
+ const match = hook?.type === "command" && typeof hook.command === "string" &&
47
+ /^\s*node\s+(?:"([^"]+)"|'([^']+)'|(\S+))(?:\s+(\S+)\s+(?:"([^"]+)"|'([^']+)'|(\S+)))?/i.exec(hook.command);
48
+ if (!match) return {};
49
+ const executable = (match[1] ?? match[2] ?? match[3]).replace(/\\/g, "/");
50
+ const target = (match[5] ?? match[6] ?? match[7])?.replace(/\\/g, "/");
51
+ const relativeLegacyRunner = executable === LEGACY_RUNNER;
52
+ return {
53
+ script: installedPath(executable, installRoot),
54
+ id: match[4],
55
+ target: relativeLegacyRunner ? target : installedPath(target, installRoot),
56
+ relativeLegacyRunner,
57
+ };
35
58
  }
36
59
 
37
- function cleanHooks(hooks) {
38
- if (!hooks || typeof hooks !== "object") return hooks;
39
- const cleaned = {};
40
- for (const [eventType, entries] of Object.entries(hooks)) {
41
- const filtered = filterHooks(entries);
42
- if (filtered.length > 0) cleaned[eventType] = filtered;
60
+ function validateHookGroups(events) {
61
+ for (const [event, groups] of Object.entries(events)) {
62
+ if (!Array.isArray(groups) || groups.some((group) => !Array.isArray(group?.hooks))) {
63
+ throw new Error(`Invalid Claude settings hook groups for ${event}`);
64
+ }
43
65
  }
44
- return cleaned;
45
66
  }
46
67
 
47
- function mergeSettings(source, existing) {
68
+ function mergeHookGroups(current, incoming, installRoot, windowsPaths) {
69
+ const managedTargets = new Map();
70
+ const managedGroups = incoming.map((group) => {
71
+ const hooks = group.hooks.filter((hook) => {
72
+ const command = hookCommand(hook, installRoot);
73
+ if (command.script !== RUNNER || !command.id) return true;
74
+ if (managedTargets.has(command.id)) return false;
75
+ managedTargets.set(command.id, command.target);
76
+ return true;
77
+ }).map((hook) => windowsPaths && hook?.type === "command"
78
+ ? { ...hook, command: hook.command.replaceAll(HOME_PREFIX, () => installRoot) }
79
+ : hook);
80
+ return { ...group, hooks };
81
+ });
82
+ const userGroups = current.map((group) => ({
83
+ ...group,
84
+ hooks: group.hooks.filter((hook) => {
85
+ const { script, id, target, relativeLegacyRunner } = hookCommand(hook, installRoot);
86
+ if (LEGACY_HOOK_PATTERNS.includes(script)) return false;
87
+ if (!relativeLegacyRunner && script !== RUNNER) return true;
88
+ if (LEGACY_WRAPPED_TARGETS.get(id)?.includes(target)) return false;
89
+ return !target || managedTargets.get(id) !== target;
90
+ }),
91
+ }));
92
+ return [...userGroups, ...managedGroups].filter((group) => group.hooks.length > 0);
93
+ }
94
+
95
+ function mergeSettings(source, existing, { installRoot = path.join(os.homedir(), ".claude"), windowsPaths = false } = {}) {
96
+ const current = existing.hooks || {};
97
+ const incoming = source.hooks || {};
98
+ validateHookGroups(current);
99
+ validateHookGroups(incoming);
100
+ const hooks = Object.fromEntries([...new Set([...Object.keys(current), ...Object.keys(incoming)])]
101
+ .map((event) => [event, mergeHookGroups(
102
+ Object.hasOwn(current, event) ? current[event] : [],
103
+ Object.hasOwn(incoming, event) ? incoming[event] : [],
104
+ installRoot,
105
+ windowsPaths,
106
+ )])
107
+ .filter(([, groups]) => groups.length > 0));
48
108
  return {
49
109
  ...existing,
50
110
  ...source,
51
111
  env: { ...(source.env || {}), ...(existing.env || {}) },
52
112
  mcpServers: { ...(source.mcpServers || {}), ...(existing.mcpServers || {}) },
53
- hooks: cleanHooks({ ...(existing.hooks || {}), ...(source.hooks || {}) }),
113
+ hooks,
54
114
  };
55
115
  }
56
116
 
@@ -61,15 +121,18 @@ function readJson(path) {
61
121
  }
62
122
 
63
123
  function main() {
64
- const [, , sourcePath, destinationPath] = process.argv;
124
+ const [, , sourcePath, destinationPath, mode] = process.argv;
65
125
  const source = readJson(sourcePath);
66
126
  const existing = fs.existsSync(destinationPath)
67
127
  ? readJson(destinationPath)
68
128
  : {};
69
- const merged = mergeSettings(source, existing);
129
+ const merged = mergeSettings(source, existing, {
130
+ installRoot: path.dirname(path.resolve(destinationPath)),
131
+ windowsPaths: mode === "--windows-paths",
132
+ });
70
133
  fs.writeFileSync(destinationPath, JSON.stringify(merged, null, 2) + "\n");
71
134
  }
72
135
 
73
136
  if (require.main === module) main();
74
137
 
75
- module.exports = { cleanHooks, mergeSettings };
138
+ module.exports = { mergeSettings };
@@ -44,6 +44,126 @@ function checkLegacyMigration() {
44
44
  assert.equal(read(cold + ".bak." + hash), previous);
45
45
  }
46
46
 
47
+ function checkInstallerCliOptions() {
48
+ const profile = path.join(tempRoot, "invalid-cli-profile");
49
+ for (const [options, message] of [
50
+ [["--unknown-option"], /Unknown option: --unknown-option/],
51
+ [["--claude-only", "--codex-only"], /cannot be used together/],
52
+ [["--codex-only", "--claude-only"], /cannot be used together/],
53
+ [["--claude-only", "--codex-only", "--help"], /cannot be used together/],
54
+ ]) {
55
+ const result = spawnSync(process.execPath, [
56
+ path.join(sourceRoot, "bin/claude-everything-workflow.js"), "install", ...options,
57
+ ], {
58
+ cwd: sourceRoot, env: { ...process.env, USERPROFILE: profile, HOME: profile },
59
+ encoding: "utf8", timeout: 60000, maxBuffer: 8 * 1024 * 1024,
60
+ });
61
+ assert.ifError(result.error);
62
+ assert.notEqual(result.status, 0, "invalid CLI options must fail before installation");
63
+ assert.match(result.stderr, message);
64
+ }
65
+ for (const host of [".claude", ".codex"]) {
66
+ assert.equal(fs.existsSync(path.join(profile, host)), false);
67
+ }
68
+ for (const help of ["--help", "-h"]) {
69
+ const result = spawnSync(process.execPath, [
70
+ path.join(sourceRoot, "bin/claude-everything-workflow.js"), "install", help,
71
+ ], {
72
+ cwd: sourceRoot, env: { ...process.env, USERPROFILE: profile, HOME: profile },
73
+ encoding: "utf8", timeout: 60000,
74
+ });
75
+ assert.ifError(result.error);
76
+ assert.equal(result.status, 0, "install help must succeed without installing");
77
+ assert.match(result.stdout, /Usage:/);
78
+ for (const host of [".claude", ".codex"]) {
79
+ assert.equal(fs.existsSync(path.join(profile, host)), false);
80
+ }
81
+ }
82
+ }
83
+
84
+ function checkBashHelpOptions() {
85
+ const executable = process.env.CEW_TEST_BASH || (process.platform === "win32" ? null : "bash");
86
+ if (!executable) return;
87
+ const profile = path.join(tempRoot, "bash options profile");
88
+ const invalidOptions = [
89
+ ["--help", "--claude-only", "--codex-only"],
90
+ ["--claude-only", "--help", "--codex-only"],
91
+ ["--claude-only", "--codex-only", "--help"],
92
+ ["--help", "--unknown-option"],
93
+ ["--unknown-option", "--help"],
94
+ ];
95
+ for (const options of [...invalidOptions, ["--help"], ["-h"]]) {
96
+ const result = spawnSync(executable, ["scripts/install.sh", ...options], {
97
+ cwd: sourceRoot, env: { ...process.env, HOME: profile },
98
+ encoding: "utf8", timeout: 60000,
99
+ });
100
+ assert.ifError(result.error);
101
+ if (options.length === 1) {
102
+ assert.equal(result.status, 0, result.stderr);
103
+ assert.match(result.stdout, /Usage:/);
104
+ } else {
105
+ assert.notEqual(result.status, 0, `Bash must reject invalid options even with help: ${options.join(" ")}`);
106
+ assert.match(result.stderr, /Unknown option|cannot be used together/);
107
+ }
108
+ for (const host of [".claude", ".codex"]) {
109
+ assert.equal(fs.existsSync(path.join(profile, host)), false);
110
+ }
111
+ }
112
+ }
113
+
114
+ function checkInstallerLinkedRoots() {
115
+ for (const host of [".claude", ".codex"]) {
116
+ const profile = path.join(tempRoot, "linked-profile" + host);
117
+ const outside = path.join(tempRoot, "linked-outside" + host);
118
+ fs.mkdirSync(profile);
119
+ fs.mkdirSync(outside);
120
+ fs.writeFileSync(path.join(outside, "AGENTS.md"), "Keep external user content\n");
121
+ fs.symlinkSync(outside, path.join(profile, host), process.platform === "win32" ? "junction" : "dir");
122
+ const result = spawnSync(process.execPath, [
123
+ path.join(sourceRoot, "bin/claude-everything-workflow.js"), "install",
124
+ host === ".claude" ? "--claude-only" : "--codex-only",
125
+ ], {
126
+ cwd: sourceRoot,
127
+ env: {
128
+ ...process.env, USERPROFILE: profile, HOME: profile,
129
+ ...(process.platform === "win32" ? {
130
+ PSModulePath: path.join(process.env.SystemRoot, "System32/WindowsPowerShell/v1.0/Modules"),
131
+ } : {}),
132
+ },
133
+ encoding: "utf8", timeout: 60000, maxBuffer: 8 * 1024 * 1024,
134
+ });
135
+ assert.ifError(result.error);
136
+ assert.notEqual(result.status, 0, "linked install roots must be rejected");
137
+ assert.match(result.stderr, /symlink/i);
138
+ assert.deepEqual(fs.readdirSync(outside), ["AGENTS.md"], "reject links before any external writes");
139
+ assert.equal(read(path.join(outside, "AGENTS.md")), "Keep external user content\n");
140
+ }
141
+ }
142
+
143
+ function checkInstallerMergeFailure() {
144
+ if (process.platform !== "win32") return;
145
+ const profile = path.join(tempRoot, "merge failure profile");
146
+ const settingsPath = path.join(profile, ".claude/settings.json");
147
+ fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
148
+ const previous = JSON.stringify({ env: { KEEP: "yes" }, hooks: { SessionStart: null } });
149
+ fs.writeFileSync(settingsPath, previous);
150
+ const result = spawnSync(process.execPath, [
151
+ path.join(sourceRoot, "bin/claude-everything-workflow.js"), "install", "--claude-only",
152
+ ], {
153
+ cwd: sourceRoot,
154
+ env: {
155
+ ...process.env, USERPROFILE: profile, HOME: profile,
156
+ PSModulePath: path.join(process.env.SystemRoot, "System32/WindowsPowerShell/v1.0/Modules"),
157
+ },
158
+ encoding: "utf8", timeout: 60000, maxBuffer: 8 * 1024 * 1024,
159
+ });
160
+ assert.ifError(result.error);
161
+ assert.notEqual(result.status, 0, "a failed settings merge must fail the installation");
162
+ assert.match(result.stderr, /Claude settings merge failed/);
163
+ assert.doesNotMatch(result.stdout, /Install complete/);
164
+ assert.equal(fs.readFileSync(settingsPath, "utf8"), previous);
165
+ }
166
+
47
167
  function checkInstallerEntrypoint() {
48
168
  const profile = path.join(tempRoot, "installer-profile");
49
169
  const windows = process.platform === "win32";
@@ -53,6 +173,27 @@ function checkInstallerEntrypoint() {
53
173
  : [path.join(sourceRoot, "scripts/install.sh")];
54
174
  // The child gets a disposable profile; never update this process's home or the user's installation.
55
175
  const env = { ...process.env, USERPROFILE: profile, HOME: profile };
176
+ const invalid = spawnSync(executable, [...args, windows ? "-UnknownOption" : "--unknown-option"], {
177
+ cwd: sourceRoot, env, encoding: "utf8", timeout: 60000, maxBuffer: 8 * 1024 * 1024,
178
+ });
179
+ assert.ifError(invalid.error);
180
+ assert.notEqual(invalid.status, 0, "direct installer must reject unknown options before writing");
181
+ assert.equal(fs.existsSync(path.join(profile, ".claude")), false);
182
+ assert.equal(fs.existsSync(path.join(profile, ".codex")), false);
183
+ for (const only of [
184
+ windows ? ["-ClaudeOnly", "-CodexOnly"] : ["--claude-only", "--codex-only"],
185
+ windows ? ["-CodexOnly", "-ClaudeOnly"] : ["--codex-only", "--claude-only"],
186
+ ]) {
187
+ const conflict = spawnSync(executable, [...args, ...only], {
188
+ cwd: sourceRoot, env, encoding: "utf8", timeout: 60000, maxBuffer: 8 * 1024 * 1024,
189
+ });
190
+ assert.ifError(conflict.error);
191
+ assert.notEqual(conflict.status, 0, "direct installer must reject conflicting host options");
192
+ assert.match(conflict.stderr, /cannot be used together/);
193
+ for (const host of [".claude", ".codex"]) {
194
+ assert.equal(fs.existsSync(path.join(profile, host)), false);
195
+ }
196
+ }
56
197
  const run = (extra = []) => {
57
198
  const result = spawnSync(executable, [...args, ...extra], {
58
199
  cwd: sourceRoot, env, encoding: "utf8", timeout: 60000, maxBuffer: 8 * 1024 * 1024,
@@ -88,13 +229,52 @@ function checkInstallerEntrypoint() {
88
229
  fs.writeFileSync(path.join(skills, "handoff/agents/openai.yaml"),
89
230
  "policy:\n allow_implicit_invocation: false\n");
90
231
  }
232
+ const settingsPath = path.join(profile, ".claude/settings.json");
233
+ fs.mkdirSync(path.dirname(settingsPath), { recursive: true });
234
+ const userHookGroup = {
235
+ matcher: "Edit|Write|MultiEdit",
236
+ hooks: [
237
+ { type: "command", command: 'node "$HOME/.claude/my-hooks/observe.js"', timeout: 7 },
238
+ { type: "command", command: 'node "$HOME/.claude/hooks/runtime/run-with-flags.js" post:edit:console-log "$HOME/.claude/hooks/my-team-check.js" standard,strict' },
239
+ { type: "prompt", prompt: "Keep this user hook" },
240
+ ],
241
+ };
242
+ const unrelatedHook = {
243
+ matcher: "Bash",
244
+ hooks: [{ type: "command", command: 'node "./hooks/session-start.js"' }],
245
+ };
246
+ const retiredSession = {
247
+ type: "command",
248
+ command: 'node "$HOME/.claude/hooks/runtime/run-with-flags.js" session:start "$HOME/.claude/hooks/session-start.js" minimal,standard,strict',
249
+ };
250
+ const retiredConsole = {
251
+ type: "command",
252
+ command: 'node scripts/hooks/run-with-flags.js post:write:console-log hooks/check-console-log.js standard,strict',
253
+ };
254
+ fs.writeFileSync(settingsPath, JSON.stringify({
255
+ hooks: {
256
+ PostToolUse: [{ ...userHookGroup, hooks: [...userHookGroup.hooks, retiredConsole] }],
257
+ SessionStart: [{ ...unrelatedHook, hooks: [...unrelatedHook.hooks, retiredSession] }],
258
+ },
259
+ }));
91
260
  run();
261
+ const installedSettings = JSON.parse(read(settingsPath).replace(/^\uFEFF/, ""));
262
+ assert.deepEqual(installedSettings.hooks.PostToolUse[0], userHookGroup);
263
+ assert.deepEqual(installedSettings.hooks.SessionStart, [unrelatedHook]);
264
+ assert.equal(installedSettings.hooks.PostToolUse.flatMap(({ hooks }) => hooks)
265
+ .filter(({ command }) => command?.includes("hooks/check-console-log.js")).length, 1);
266
+ run();
267
+ assert.deepEqual(JSON.parse(read(settingsPath).replace(/^\uFEFF/, "")), installedSettings,
268
+ "reinstallation must preserve user hooks and add each managed hook only once");
92
269
  assert.equal(read(path.join(profile, ".claude/references/rules/common/testing.md")),
93
270
  read(path.join(sourceRoot, "rules/common/testing.md")));
94
271
  assert.equal(fs.existsSync(path.join(profile, ".claude/rules/common/testing.md")), false);
95
272
  assert.equal(read(path.join(profile, ".codex/rules/common/testing.md")),
96
273
  read(path.join(sourceRoot, "rules/common/testing.md")));
97
- assert.match(read(path.join(profile, ".claude/CLAUDE.md")), /^@AGENTS\.md$/m);
274
+ const claudeBootstrap = read(path.join(profile, ".claude/CLAUDE.md"));
275
+ assert.match(claudeBootstrap, /^@AGENTS\.md$/m);
276
+ assert.ok(claudeBootstrap.includes("~/.claude/references/rules/"),
277
+ "Claude's installed entry must locate on-demand rules outside the startup directory");
98
278
  for (const host of [".claude", ".codex"]) {
99
279
  assert.equal(read(path.join(profile, host, "references/git-worktrees.md")),
100
280
  read(path.join(sourceRoot, "references/git-worktrees.md")));
@@ -110,6 +290,8 @@ function checkInstallerEntrypoint() {
110
290
  "安装不应保留仅供包内验证的续接测试");
111
291
  assert.equal(fs.existsSync(path.join(profile, host, "scripts/verify/plugin-distribution.test.js")), false,
112
292
  "安装不应保留仅供包内验证的插件分发测试");
293
+ assert.equal(fs.existsSync(path.join(profile, host, "scripts/verify/learning.test.js")), false,
294
+ "安装不应保留仅供包内验证的持续学习测试");
113
295
  assert.match(read(path.join(profile, host, "skills/handoff/agents/openai.yaml")),
114
296
  /allow_implicit_invocation: true/);
115
297
  }
@@ -120,17 +302,18 @@ try {
120
302
  const fresh = path.join(tempRoot, "fresh");
121
303
  const common = fs.readdirSync(path.join(sourceRoot, "rules/common"));
122
304
  assert.equal(common.length, 8);
123
- for (const file of common) {
124
- assert.equal(read(path.join(fresh, "references/rules/common", file)),
125
- read(path.join(sourceRoot, "rules/common", file)));
126
- assert.equal(fs.existsSync(path.join(fresh, "rules/common", file)), false);
127
- }
128
- assert.equal(read(path.join(fresh, "rules/07-forbidden.md")),
129
- read(path.join(sourceRoot, "rules/07-forbidden.md")));
130
-
305
+ const resident = ["01-base.md", "05-git-workflow.md", "07-forbidden.md"];
306
+ const onDemand = [
307
+ "02-implementation.md", "08-specialty-rules-index.md", "09-first-principles-adversarial-testing.md",
308
+ ];
309
+ assert.deepEqual(fs.readdirSync(path.join(fresh, "rules")).sort(), resident);
131
310
  install("codex", "codex");
132
- assert.equal(read(path.join(tempRoot, "codex/rules/common/testing.md")),
133
- read(path.join(sourceRoot, "rules/common/testing.md")));
311
+ for (const file of [...resident, ...onDemand, ...common.map((name) => `common/${name}`)]) {
312
+ const source = read(path.join(sourceRoot, "rules", file));
313
+ const claudeDir = resident.includes(file) ? "rules" : "references/rules";
314
+ assert.equal(read(path.join(fresh, claudeDir, file)), source);
315
+ assert.equal(read(path.join(tempRoot, "codex/rules", file)), source);
316
+ }
134
317
  install("preview", "claude-code", true);
135
318
  assert.equal(fs.existsSync(path.join(tempRoot, "preview")), false);
136
319
 
@@ -140,6 +323,15 @@ try {
140
323
  path.join(upgrade, "rules/common/testing.md"));
141
324
  fs.writeFileSync(path.join(upgrade, "rules/common/hooks.md"), "Personal hook policy\n");
142
325
  fs.writeFileSync(path.join(upgrade, "rules/common/personal.md"), "Keep my rules\n");
326
+ for (const file of onDemand) {
327
+ fs.copyFileSync(path.join(sourceRoot, "rules", file), path.join(upgrade, "rules", file));
328
+ }
329
+ const customRule = "02-implementation.md";
330
+ const personal = path.join(upgrade, "rules", customRule);
331
+ fs.writeFileSync(personal, "Personal implementation rules\n");
332
+ install("upgrade", "claude-code", true);
333
+ assert.equal(fs.existsSync(path.join(upgrade, "references")), false);
334
+ for (const file of onDemand) assert.ok(fs.existsSync(path.join(upgrade, "rules", file)));
143
335
  install("upgrade");
144
336
  assert.equal(fs.existsSync(path.join(upgrade, "rules/common/testing.md")), false);
145
337
  assert.equal(read(path.join(upgrade, "rules/common/hooks.md")), "Personal hook policy\n");
@@ -148,6 +340,12 @@ try {
148
340
  install("upgrade");
149
341
  assert.equal(read(path.join(upgrade, "rules/common/hooks.md")), "Personal hook policy\n");
150
342
 
343
+ assert.equal(read(personal), "Personal implementation rules\n");
344
+ for (const file of onDemand) {
345
+ assert.equal(fs.existsSync(path.join(upgrade, "rules", file)), file === customRule);
346
+ assert.equal(read(path.join(upgrade, "references/rules", file)), read(path.join(sourceRoot, "rules", file)));
347
+ }
348
+
151
349
  const outside = path.join(tempRoot, "outside");
152
350
  fs.mkdirSync(outside);
153
351
  const linked = path.join(tempRoot, "linked");
@@ -157,6 +355,10 @@ try {
157
355
  assert.deepEqual(fs.readdirSync(outside), []);
158
356
  assert.throws(() => install("invalid", "unknown"), /host/i);
159
357
  checkLegacyMigration();
358
+ checkInstallerCliOptions();
359
+ checkBashHelpOptions();
360
+ checkInstallerLinkedRoots();
361
+ checkInstallerMergeFailure();
160
362
  checkInstallerEntrypoint();
161
363
  console.log("Rule installation tests passed (migration, backups, custom rules, symlink safety, both hosts, installer dry-run and execution).");
162
364
  } finally {
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ const assert = require("node:assert/strict");
4
+ const { spawnSync } = require("node:child_process");
5
+ const fs = require("node:fs");
6
+ const os = require("node:os");
7
+ const path = require("node:path");
8
+ const { test } = require("node:test");
9
+
10
+ const root = path.resolve(__dirname, "../..");
11
+ const skill = "skills/continuous-learning-v2";
12
+ const observer = `${skill}/hooks/observe-v2.js`;
13
+
14
+ function fixture(t) {
15
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), "cew-learning-"));
16
+ t.after(() => fs.rmSync(cwd, { recursive: true, force: true }));
17
+ const data = path.join(cwd, "data");
18
+ const config = { homunculus: { data_root: data } };
19
+ const configPath = path.join(cwd, skill, "config.json");
20
+ fs.mkdirSync(path.dirname(configPath), { recursive: true });
21
+ fs.writeFileSync(configPath, JSON.stringify(config));
22
+ return { cwd, data };
23
+ }
24
+
25
+ function run(cwd, script, args, input) {
26
+ const result = spawnSync(process.execPath, [path.join(root, script), ...args], {
27
+ cwd, input, encoding: "utf8", env: { ...process.env, HOME: cwd, USERPROFILE: cwd, XDG_DATA_HOME: cwd },
28
+ timeout: 10000,
29
+ });
30
+ assert.ifError(result.error);
31
+ return result;
32
+ }
33
+
34
+ function writeInstinct(base, filename, confidence) {
35
+ const directory = path.join(base, "personal");
36
+ fs.mkdirSync(directory, { recursive: true });
37
+ fs.writeFileSync(path.join(directory, filename), `---\nconfidence: ${confidence}\n---\nA fixture instinct.\n`);
38
+ }
39
+
40
+ test("project migration preview creates neither registry nor instinct files", (t) => {
41
+ const { cwd, data } = fixture(t);
42
+ const legacy = path.join(cwd, "legacy");
43
+ writeInstinct(legacy, "keep.md", 0.8);
44
+ const args = ["--source", legacy];
45
+ for (const flags of [[], ["--dry-run"]]) {
46
+ const preview = run(cwd, "scripts/learning/migrate-homunculus.js", [...args, ...flags]);
47
+ assert.equal(preview.status, 0, preview.stderr);
48
+ assert.match(preview.stdout, /keep\.md/);
49
+ assert.equal(fs.existsSync(data), false);
50
+ }
51
+ const applied = run(cwd, "scripts/learning/migrate-homunculus.js", [...args, "--apply"]);
52
+ assert.equal(applied.status, 0, applied.stderr);
53
+ const registry = JSON.parse(fs.readFileSync(path.join(data, "projects.json"), "utf8"));
54
+ const [id] = Object.keys(registry.projects);
55
+ assert.equal(fs.existsSync(path.join(data, "projects", id, "instincts/personal/keep.md")), true);
56
+ });
57
+
58
+ test("conflicting preview and apply flags are rejected without writes", (t) => {
59
+ const { cwd, data } = fixture(t);
60
+ const instincts = path.join(data, "projects/example/instincts");
61
+ writeInstinct(instincts, "candidate.md", 0.8);
62
+ const commands = [
63
+ ["scripts/learning/migrate-homunculus.js", "--source", instincts],
64
+ ["scripts/learning/promote.js", "--project-id", "example"],
65
+ ];
66
+ for (const [script, ...args] of commands) {
67
+ const result = run(cwd, script, [...args, "--dry-run", "--apply"]);
68
+ assert.notEqual(result.status, 0);
69
+ assert.match(result.stderr, /--dry-run.*--apply/);
70
+ assert.deepEqual(fs.readdirSync(data), ["projects"]);
71
+ assert.deepEqual(fs.readdirSync(path.join(data, "projects")), ["example"]);
72
+ }
73
+ });
74
+
75
+ test("an invalid promotion threshold fails before any global write", (t) => {
76
+ const { cwd, data } = fixture(t);
77
+ writeInstinct(path.join(data, "projects/example/instincts"), "candidate.md", 0.8);
78
+ for (const value of [[], [""], ["abc"], ["0.4oops"], ["0x0"], ["Infinity"], ["-0.1"], ["1.1"]]) {
79
+ const result = run(cwd, "scripts/learning/promote.js",
80
+ ["--project-id", "example", "--apply", "--min-confidence", ...value]);
81
+ assert.notEqual(result.status, 0, JSON.stringify(value));
82
+ assert.match(result.stderr, /--min-confidence/);
83
+ assert.equal(fs.existsSync(path.join(data, "global")), false);
84
+ }
85
+ for (const flags of [["--min-confidence=abc"], ["--min-confidence", "0.7", "--min-confidence", "abc"]]) {
86
+ const result = run(cwd, "scripts/learning/promote.js", ["--project-id", "example", "--apply", ...flags]);
87
+ assert.notEqual(result.status, 0);
88
+ assert.match(result.stderr, /--min-confidence/);
89
+ assert.equal(fs.existsSync(path.join(data, "global")), false);
90
+ }
91
+ });
92
+
93
+ test("promotion copies only candidates with a valid confidence at or above the threshold", (t) => {
94
+ const { cwd, data } = fixture(t);
95
+ const instincts = path.join(data, "projects/example/instincts");
96
+ writeInstinct(instincts, "at-threshold.md", 0.7);
97
+ writeInstinct(instincts, "low.md", 0.6);
98
+ writeInstinct(instincts, "malformed.md", "0.9oops");
99
+ writeInstinct(instincts, "out-of-range.md", 1.5);
100
+ const args = ["--project-id", "example", "--min-confidence", "0.7"];
101
+ const preview = run(cwd, "scripts/learning/promote.js", [...args, "--dry-run"]);
102
+ assert.equal(preview.status, 0, preview.stderr);
103
+ assert.equal(fs.existsSync(path.join(data, "global")), false);
104
+ const result = run(cwd, "scripts/learning/promote.js", [...args, "--apply"]);
105
+ assert.equal(result.status, 0, result.stderr);
106
+ assert.deepEqual(fs.readdirSync(path.join(data, "global/instincts/personal")), ["at-threshold.md"]);
107
+ });
108
+
109
+ test("observation leaves the profile untouched with default, missing or invalid config", (t) => {
110
+ const { cwd } = fixture(t);
111
+ const configPath = path.join(cwd, ".claude", skill, "config.json");
112
+ fs.mkdirSync(path.dirname(configPath), { recursive: true });
113
+ const input = JSON.stringify({ tool: "Edit", tool_name: "Edit", cwd, session_id: "fixture" });
114
+ const shipped = fs.readFileSync(path.join(root, skill, "config.json"), "utf8");
115
+ for (const config of [null, "{", shipped, '{"observation":{"enabled":"false"}}', "null"]) {
116
+ if (config !== null) fs.writeFileSync(configPath, config);
117
+ const result = run(cwd, observer, ["post"], input);
118
+ assert.equal(result.status, 0, result.stderr);
119
+ assert.deepEqual(fs.readdirSync(cwd).sort(), [".claude", "skills"]);
120
+ assert.deepEqual(fs.readdirSync(path.join(cwd, ".claude")), ["skills"]);
121
+ }
122
+ });
@@ -31,6 +31,7 @@ const PACKAGE_ONLY_PATHS = [
31
31
  "scripts/verify/skill-invocation.test.js",
32
32
  "scripts/verify/continuation-checks.test.js",
33
33
  "scripts/verify/install-rules.test.js",
34
+ "scripts/verify/learning.test.js",
34
35
  "scripts/verify/plugin-distribution.test.js",
35
36
  ];
36
37
 
@@ -311,7 +312,6 @@ function checkHookConfigReferences() {
311
312
 
312
313
  requireTokens("scripts/merge-claude-settings.cjs", [
313
314
  "LEGACY_HOOK_PATTERNS",
314
- "cleanHooks",
315
315
  "mergeSettings",
316
316
  ]);
317
317
 
@@ -24,6 +24,9 @@ test("both marketplaces resolve to the same self-contained, versioned workflow p
24
24
  const source = market.plugins[0].source;
25
25
  assert.equal(path.resolve(root, typeof source === "string" ? source : source.path), root);
26
26
  }
27
+ const mcp = readJson(".mcp.json");
28
+ assert.equal(mcp.mcpServers["chrome-devtools"].command, "npx");
29
+ assert.ok(mcp.mcpServers["chrome-devtools"].args.includes("--autoConnect"));
27
30
  assert.ok(fs.existsSync(path.join(root, codex.skills, "using-superpowers/SKILL.md")));
28
31
  assert.ok(!("hooks" in codex), "Claude hook events must not be advertised as Codex hooks");
29
32
  const hooks = readJson(claude.hooks).hooks;
@@ -71,6 +71,11 @@ const path = require("node:path");
71
71
  const YAML = require("yaml");
72
72
  const root = path.resolve(__dirname, "../..");
73
73
  const manifest = require("../../harness/manifest.json");
74
+ const implement = manifest.skills.find((skill) => skill.name === "implement");
75
+ assert.equal(implement?.invocation, "explicit-only");
76
+ const routerBody = fs.readFileSync(path.join(root, "skills/using-superpowers/SKILL.md"), "utf8");
77
+ assert.match(routerBody, /-> read-reference skills\/implement\/SKILL\.md/);
78
+ assert.deepEqual(validateNativeRoutes(manifest, routerBody), []);
74
79
  for (const name of ["handoff", "improve-codebase-architecture", "triage"]) {
75
80
  const entry = manifest.skills.find((skill) => skill.name === name);
76
81
  assert.equal(entry?.invocation, "implicit", name);
@@ -84,4 +89,4 @@ for (const name of ["research", "wayfinder", "find-skills", "project-context", "
84
89
  assert.equal(manifest.skills.some((skill) => skill.name === name), false);
85
90
  assert.equal(fs.existsSync(path.join(root, "skills", name, "SKILL.md")), false, name);
86
91
  }
87
- console.log("Skill invocation tests passed (33 host-gate scenarios, three natural-language entries, seven retired skills).");
92
+ console.log("Skill invocation tests passed (host gates, router references, natural-language entries and retired skills).");
@@ -185,10 +185,13 @@ function runSkillManifestChecks(context) {
185
185
  function validateNativeRoutes(manifest, routerBody) {
186
186
  const errors = [];
187
187
  const skills = Array.isArray(manifest?.skills) ? manifest.skills : [];
188
- for (const match of routerBody.matchAll(/->\s*(native-entry\s+)?(skills\/[a-z0-9-]+\/SKILL\.md|[a-z0-9-]+)[ \t]*\r?$/gm)) {
189
- const skill = skills.find((entry) => entry?.path === match[2] || entry?.name === match[2]);
190
- if (skill?.invocation === "explicit-only" && !match[1]) {
191
- errors.push(`router must use native-entry for explicit-only Skill: ${skill.name}`);
188
+ for (const [, mode, target] of routerBody.matchAll(/->\s*(?:(native-entry|read-reference)\s+)?(skills\/[a-z0-9-]+\/SKILL\.md|[a-z0-9-]+)[ \t]*\r?$/gm)) {
189
+ const skill = skills.find((entry) => entry?.path === target || entry?.name === target);
190
+ if (mode === "read-reference" && skill?.path !== target) {
191
+ errors.push(`read-reference must name a registered Skill file: ${target}`);
192
+ }
193
+ if (skill?.invocation === "explicit-only" && !mode) {
194
+ errors.push(`router must use native-entry or read-reference for explicit-only Skill: ${skill.name}`);
192
195
  }
193
196
  }
194
197
  return errors;
@@ -376,7 +376,6 @@ function checkCapabilityRouting() {
376
376
 
377
377
  for (const deliverySkill of [
378
378
  "skills/to-tickets/SKILL.md",
379
- "skills/implement/SKILL.md",
380
379
  "skills/subagent-driven-development/SKILL.md",
381
380
  ]) {
382
381
  if (read(deliverySkill).includes("disable-model-invocation: true")) {
package/skills/README.md CHANGED
@@ -34,7 +34,7 @@
34
34
  - `systematic-debugging`:区分普通明确失败与疑难故障;预期 TDD RED 留在实现循环。
35
35
  - `resolving-merge-conflicts`:按双方原始意图逐 hunk 解决 merge/rebase 冲突。
36
36
  - `e2e-testing`:Playwright E2E 模式、CI、制品和 flaky 处理。
37
- - `feature-acceptance`:用户明确要求真实流程验收、截图或日志证据时,输出用例矩阵与复核结论。
37
+ - `feature-acceptance`:建立/维护项目验收工具与功能地图;按用户或项目验收合同执行真实流程并复核证据。
38
38
 
39
39
  ## Harness / 上下文与编排
40
40