claude-everything-workflow 0.2.4 → 0.2.6
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/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +6 -4
- package/bin/claude-everything-workflow.js +15 -0
- package/commands/pr.md +2 -2
- package/harness/manifest.json +1 -1
- package/hooks/check-code-size.js +1 -1
- package/package.json +2 -1
- package/rules/01-base.md +4 -1
- package/rules/02-implementation.md +27 -0
- package/rules/05-git-workflow.md +2 -1
- package/rules/08-specialty-rules-index.md +1 -1
- package/rules/09-first-principles-adversarial-testing.md +1 -2
- package/rules/common/testing.md +1 -0
- package/scripts/install.ps1 +28 -44
- package/scripts/install.sh +31 -3
- package/scripts/learning/migrate-homunculus.js +10 -5
- package/scripts/learning/project-utils.js +9 -0
- package/scripts/learning/promote.js +27 -10
- package/scripts/merge-claude-settings.cjs +88 -25
- package/scripts/verify/install-rules.test.js +183 -0
- package/scripts/verify/learning.test.js +122 -0
- package/scripts/verify/metadata-checks.js +57 -4
- package/scripts/verify/skill-invocation.test.js +6 -1
- package/scripts/verify/skill-manifest-checks.js +7 -4
- package/scripts/verify/workflow-checks.js +0 -1
- package/skills/README.md +1 -1
- package/skills/code-review/SKILL.md +7 -2
- package/skills/code-review/references/spec-reviewer-prompt.md +7 -4
- package/skills/continuous-learning-v2/SKILL.md +1 -0
- package/skills/continuous-learning-v2/config.json +1 -1
- package/skills/continuous-learning-v2/hooks/observe-v2.js +2 -9
- package/skills/feature-acceptance/SKILL.md +13 -5
- package/skills/feature-acceptance/references/project-verification.md +55 -0
- package/skills/implement/SKILL.md +3 -1
- package/skills/implement/agents/openai.yaml +2 -0
- package/skills/spec-gate/SKILL.md +9 -21
- package/skills/spec-gate/references/spec-template.md +23 -0
- package/skills/systematic-debugging/SKILL.md +6 -6
- package/skills/systematic-debugging/references/debugging-methods.md +30 -0
- package/skills/systematic-debugging/references/diagnostic-scenarios.md +1 -1
- package/skills/using-superpowers/SKILL.md +9 -1
- package/rules/02-code-size.md +0 -7
- package/rules/03-architecture.md +0 -12
- package/rules/04-error-handling.md +0 -5
- package/rules/06-comments.md +0 -4
|
@@ -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
|
-
|
|
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
|
|
22
|
-
if (
|
|
23
|
-
|
|
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
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
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
|
|
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 = {
|
|
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,7 +229,43 @@ 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
|
+
}));
|
|
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);
|
|
91
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);
|
|
@@ -110,6 +287,8 @@ function checkInstallerEntrypoint() {
|
|
|
110
287
|
"安装不应保留仅供包内验证的续接测试");
|
|
111
288
|
assert.equal(fs.existsSync(path.join(profile, host, "scripts/verify/plugin-distribution.test.js")), false,
|
|
112
289
|
"安装不应保留仅供包内验证的插件分发测试");
|
|
290
|
+
assert.equal(fs.existsSync(path.join(profile, host, "scripts/verify/learning.test.js")), false,
|
|
291
|
+
"安装不应保留仅供包内验证的持续学习测试");
|
|
113
292
|
assert.match(read(path.join(profile, host, "skills/handoff/agents/openai.yaml")),
|
|
114
293
|
/allow_implicit_invocation: true/);
|
|
115
294
|
}
|
|
@@ -157,6 +336,10 @@ try {
|
|
|
157
336
|
assert.deepEqual(fs.readdirSync(outside), []);
|
|
158
337
|
assert.throws(() => install("invalid", "unknown"), /host/i);
|
|
159
338
|
checkLegacyMigration();
|
|
339
|
+
checkInstallerCliOptions();
|
|
340
|
+
checkBashHelpOptions();
|
|
341
|
+
checkInstallerLinkedRoots();
|
|
342
|
+
checkInstallerMergeFailure();
|
|
160
343
|
checkInstallerEntrypoint();
|
|
161
344
|
console.log("Rule installation tests passed (migration, backups, custom rules, symlink safety, both hosts, installer dry-run and execution).");
|
|
162
345
|
} 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
|
|
|
@@ -339,7 +339,7 @@ function runCommand(command, args, { allowFailure = false, ...options } = {}) {
|
|
|
339
339
|
return result;
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
-
function releaseScenario({ exactPublished = false, publishFails = false, tagAt }) {
|
|
342
|
+
function releaseScenario({ exactPublished = false, publishFails = false, lookupFails = false, tagAt }) {
|
|
343
343
|
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "cew-release-"));
|
|
344
344
|
const repository = path.join(tempRoot, "repository");
|
|
345
345
|
const remote = path.join(tempRoot, "remote.git");
|
|
@@ -375,9 +375,15 @@ function releaseScenario({ exactPublished = false, publishFails = false, tagAt }
|
|
|
375
375
|
const currentCommit = git(["-C", repository, "rev-parse", "HEAD"]).stdout.trim();
|
|
376
376
|
git(["-C", repository, "remote", "add", "origin", remote]);
|
|
377
377
|
|
|
378
|
+
let taggedCommit = "";
|
|
378
379
|
if (tagAt) {
|
|
379
|
-
|
|
380
|
-
|
|
380
|
+
taggedCommit = tagAt === "current" ? currentCommit : firstCommit;
|
|
381
|
+
if (tagAt === "unrelated") {
|
|
382
|
+
taggedCommit = git([
|
|
383
|
+
"-C", repository, "commit-tree", `${currentCommit}^{tree}`, "-m", "unrelated release",
|
|
384
|
+
]).stdout.trim();
|
|
385
|
+
}
|
|
386
|
+
git(["-C", repository, "tag", "-a", "v0.2.2", taggedCommit, "-m", "test tag"]);
|
|
381
387
|
git(["-C", repository, "push", "origin", "v0.2.2"]);
|
|
382
388
|
}
|
|
383
389
|
|
|
@@ -388,6 +394,10 @@ function releaseScenario({ exactPublished = false, publishFails = false, tagAt }
|
|
|
388
394
|
const args = process.argv.slice(2);
|
|
389
395
|
fs.appendFileSync(process.env.NPM_CALL_LOG, JSON.stringify(args) + "\\n");
|
|
390
396
|
if (args[0] === "view" && args[1].includes("@0.2.2")) {
|
|
397
|
+
if (process.env.LOOKUP_FAILS === "true") {
|
|
398
|
+
process.stderr.write("npm error code E503\\n");
|
|
399
|
+
process.exit(1);
|
|
400
|
+
}
|
|
391
401
|
if (process.env.EXACT_PUBLISHED === "true") {
|
|
392
402
|
process.stdout.write("0.2.2\\n");
|
|
393
403
|
process.exit(0);
|
|
@@ -424,6 +434,7 @@ process.exit(2);
|
|
|
424
434
|
GITHUB_SHA: currentCommit,
|
|
425
435
|
NPM_CALL_LOG: npmLog,
|
|
426
436
|
PUBLISH_FAILS: String(publishFails),
|
|
437
|
+
LOOKUP_FAILS: String(lookupFails),
|
|
427
438
|
},
|
|
428
439
|
},
|
|
429
440
|
);
|
|
@@ -443,6 +454,7 @@ process.exit(2);
|
|
|
443
454
|
calls,
|
|
444
455
|
currentCommit,
|
|
445
456
|
firstCommit,
|
|
457
|
+
taggedCommit,
|
|
446
458
|
localTag: localTag.status === 0 ? localTag.stdout.trim() : "",
|
|
447
459
|
remoteTag: remoteTag.status === 0 ? remoteTag.stdout.trim() : "",
|
|
448
460
|
result,
|
|
@@ -494,6 +506,16 @@ function checkReleaseRecoveryBehavior() {
|
|
|
494
506
|
fail("release script must publish when the correct tag already exists");
|
|
495
507
|
}
|
|
496
508
|
|
|
509
|
+
const publishedBeforeCurrent = releaseScenario({ exactPublished: true, tagAt: "previous" });
|
|
510
|
+
if (
|
|
511
|
+
publishedBeforeCurrent.result.status !== 0 ||
|
|
512
|
+
publishedBeforeCurrent.calls.some(([command]) => command === "publish") ||
|
|
513
|
+
publishedBeforeCurrent.localTag !== publishedBeforeCurrent.firstCommit ||
|
|
514
|
+
publishedBeforeCurrent.remoteTag !== publishedBeforeCurrent.firstCommit
|
|
515
|
+
) {
|
|
516
|
+
fail("release script must skip a published version tagged at an ancestor without moving its tag");
|
|
517
|
+
}
|
|
518
|
+
|
|
497
519
|
const mismatchedTag = releaseScenario({ tagAt: "previous" });
|
|
498
520
|
if (
|
|
499
521
|
mismatchedTag.result.status === 0 ||
|
|
@@ -502,6 +524,37 @@ function checkReleaseRecoveryBehavior() {
|
|
|
502
524
|
) {
|
|
503
525
|
fail("release script must reject a tag that points to another commit");
|
|
504
526
|
}
|
|
527
|
+
|
|
528
|
+
const alreadyReleased = releaseScenario({ exactPublished: true, tagAt: "current" });
|
|
529
|
+
if (
|
|
530
|
+
alreadyReleased.result.status !== 0 ||
|
|
531
|
+
alreadyReleased.calls.some(([command]) => command === "publish") ||
|
|
532
|
+
alreadyReleased.localTag !== alreadyReleased.currentCommit ||
|
|
533
|
+
alreadyReleased.remoteTag !== alreadyReleased.currentCommit
|
|
534
|
+
) {
|
|
535
|
+
fail("release script must keep a completed release unchanged on retry");
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const unrelatedTag = releaseScenario({ exactPublished: true, tagAt: "unrelated" });
|
|
539
|
+
if (
|
|
540
|
+
unrelatedTag.result.status === 0 ||
|
|
541
|
+
unrelatedTag.calls.some(([command]) => command === "publish") ||
|
|
542
|
+
unrelatedTag.localTag !== unrelatedTag.taggedCommit ||
|
|
543
|
+
unrelatedTag.remoteTag !== unrelatedTag.taggedCommit
|
|
544
|
+
) {
|
|
545
|
+
fail("release script must reject a published version tagged outside the current history");
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const failedLookup = releaseScenario({ exactPublished: true, lookupFails: true, tagAt: "previous" });
|
|
549
|
+
if (
|
|
550
|
+
failedLookup.result.status === 0 ||
|
|
551
|
+
!failedLookup.result.stderr.includes("E503") ||
|
|
552
|
+
failedLookup.calls.some(([command]) => command === "publish") ||
|
|
553
|
+
failedLookup.localTag !== failedLookup.firstCommit ||
|
|
554
|
+
failedLookup.remoteTag !== failedLookup.firstCommit
|
|
555
|
+
) {
|
|
556
|
+
fail("release script must fail a registry lookup error without publishing or moving its tag");
|
|
557
|
+
}
|
|
505
558
|
}
|
|
506
559
|
|
|
507
560
|
function checkGitHubWorkflows() {
|
|
@@ -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 (
|
|
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
|
|
189
|
-
const skill = skills.find((entry) => entry?.path ===
|
|
190
|
-
if (
|
|
191
|
-
errors.push(`
|
|
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")) {
|