claude-everything-workflow 0.2.7 → 0.2.9

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/AGENTS.md +11 -18
  4. package/agents/e2e-runner.md +1 -1
  5. package/commands/pr.md +3 -1
  6. package/evals/routing-scenarios.json +253 -0
  7. package/harness/manifest.json +2 -28
  8. package/hooks/check-console-log.js +2 -2
  9. package/package.json +4 -2
  10. package/rules/01-base.md +2 -2
  11. package/rules/02-implementation.md +7 -6
  12. package/rules/05-git-workflow.md +4 -6
  13. package/rules/common/agent-orchestration.md +1 -1
  14. package/rules/common/pr-automation.md +1 -1
  15. package/rules/common/testing.md +2 -2
  16. package/scripts/eval-scenarios.js +106 -0
  17. package/scripts/install-rules.js +186 -17
  18. package/scripts/install.ps1 +42 -15
  19. package/scripts/install.sh +31 -12
  20. package/scripts/legacy-common-rule-hashes.json +4 -0
  21. package/scripts/retired-skill-files.json +7 -0
  22. package/scripts/verify/install-rules.test.js +80 -24
  23. package/scripts/verify/metadata-checks.js +7 -8
  24. package/scripts/verify/repository-checks.js +44 -368
  25. package/scripts/verify/scenario-checks.js +108 -0
  26. package/scripts/verify/scenario-checks.test.js +84 -0
  27. package/scripts/verify/workflow-checks.js +85 -586
  28. package/scripts/verify-harness.js +2 -0
  29. package/skills/README.md +2 -4
  30. package/skills/feature-acceptance/SKILL.md +8 -8
  31. package/skills/{e2e-testing/SKILL.md → feature-acceptance/references/e2e-testing.md} +3 -9
  32. package/skills/implement/SKILL.md +2 -0
  33. package/skills/{subagent-driven-development/SKILL.md → implement/references/parallel-delivery.md} +7 -9
  34. package/skills/implement/references/ticket-delivery.md +1 -1
  35. package/skills/using-superpowers/SKILL.md +24 -103
  36. package/rules/07-forbidden.md +0 -20
  37. package/rules/08-specialty-rules-index.md +0 -18
  38. package/rules/09-first-principles-adversarial-testing.md +0 -30
  39. package/scripts/verify/continuation-checks.test.js +0 -101
  40. package/scripts/verify/grilling-spec-gate-checks.js +0 -297
  41. package/scripts/verify/workflow-ownership-fixtures.js +0 -371
  42. package/scripts/verify/workflow-ownership.js +0 -780
  43. /package/skills/{e2e-testing → feature-acceptance}/references/playwright-patterns.md +0 -0
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ /**
5
+ * 可选真实模型路由场景评测脚本(不进入 CI,需本地已登录 claude 或 codex CLI)。
6
+ * 用法:
7
+ * node scripts/eval-scenarios.js --host claude --limit 5
8
+ * node scripts/eval-scenarios.js --host codex --id bug-diagnosis
9
+ */
10
+
11
+ const fs = require("node:fs");
12
+ const path = require("node:path");
13
+ const os = require("node:os");
14
+ const { spawnSync } = require("node:child_process");
15
+
16
+ const root = path.resolve(__dirname, "..");
17
+ const scenariosPath = path.join(root, "evals/routing-scenarios.json");
18
+
19
+ function parseArgs(argv) {
20
+ const opts = { host: "claude", limit: Infinity, id: null, dryRun: false };
21
+ for (let i = 0; i < argv.length; i += 1) {
22
+ const arg = argv[i];
23
+ if (arg === "--host") opts.host = argv[++i];
24
+ else if (arg === "--limit") opts.limit = Number(argv[++i]);
25
+ else if (arg === "--id") opts.id = argv[++i];
26
+ else if (arg === "--dry-run") opts.dryRun = true;
27
+ else if (arg === "-h" || arg === "--help") {
28
+ console.log("Usage: node scripts/eval-scenarios.js [--host claude|codex] [--limit N] [--id <id>] [--dry-run]");
29
+ process.exit(0);
30
+ } else {
31
+ throw new Error(`Unknown option: ${arg}`);
32
+ }
33
+ }
34
+ if (!["claude", "codex"].includes(opts.host)) {
35
+ throw new Error(`Unsupported --host: ${opts.host}`);
36
+ }
37
+ return opts;
38
+ }
39
+
40
+ function buildEvalPrompt(scenario) {
41
+ return [
42
+ "这是一个只读工作流路由测试:不要修改任何文件,不要执行写操作。",
43
+ "请根据当前仓库的 AGENTS.md、skills/using-superpowers/SKILL.md 与各 skill 的 description,选择处理以下请求的第一个 Skill 或规则。只输出一个 JSON 对象,target 填完整的仓库相对文件路径(包含文件名);无需进入工程路由时填字符串 NONE。不要加 Markdown 围栏。",
44
+ "",
45
+ `用户请求:${scenario.prompt}`,
46
+ ].join("\n");
47
+ }
48
+
49
+ function runHost(host, prompt) {
50
+ const options = { cwd: root, encoding: "utf8", timeout: 120000 };
51
+ if (host === "claude") {
52
+ const result = spawnSync("claude", ["-p", "--output-format", "text", prompt], options);
53
+ return { result, answer: result.stdout };
54
+ }
55
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "cew-eval-"));
56
+ try {
57
+ const finalMessage = path.join(dir, "answer.json");
58
+ const result = spawnSync("codex", ["exec", "--output-last-message", finalMessage, prompt], options);
59
+ const answer = result.status === 0 && fs.existsSync(finalMessage) ? fs.readFileSync(finalMessage, "utf8") : "";
60
+ return { result, answer };
61
+ } finally {
62
+ fs.rmSync(dir, { recursive: true, force: true });
63
+ }
64
+ }
65
+
66
+ function selectedTarget(answer) {
67
+ try {
68
+ const value = JSON.parse(answer);
69
+ return typeof value?.target === "string" ? value.target : null;
70
+ } catch (error) {
71
+ if (error instanceof SyntaxError) return null;
72
+ throw error;
73
+ }
74
+ }
75
+
76
+ function main() {
77
+ const opts = parseArgs(process.argv.slice(2));
78
+ const data = JSON.parse(fs.readFileSync(scenariosPath, "utf8"));
79
+ let list = data.scenarios;
80
+ if (opts.id) list = list.filter((s) => s.id === opts.id);
81
+ if (Number.isFinite(opts.limit)) list = list.slice(0, opts.limit);
82
+
83
+ let passed = 0;
84
+ for (const scenario of list) {
85
+ const evalPrompt = buildEvalPrompt(scenario);
86
+ if (opts.dryRun) {
87
+ console.log(`[dry-run] ${scenario.id} -> expected: ${scenario.expectedTarget || "NONE"}`);
88
+ passed += 1;
89
+ continue;
90
+ }
91
+ const { result, answer } = runHost(opts.host, evalPrompt);
92
+ const expected = scenario.expectedTarget ?? "NONE";
93
+ const selected = selectedTarget(answer);
94
+ const ok = result.status === 0 && selected === expected;
95
+ if (ok) passed += 1;
96
+ console.log(`${ok ? "PASS" : "FAIL"} ${scenario.id} (expected: ${scenario.expectedTarget || "NONE"})`);
97
+ if (!ok) {
98
+ const diagnostic = result.error?.message || result.stderr || "";
99
+ console.log(` exit=${result.status} target=${JSON.stringify(selected)} ${diagnostic.trim().slice(0, 200)}`);
100
+ }
101
+ }
102
+ console.log(`\nSummary: ${passed}/${list.length} passed.`);
103
+ if (passed !== list.length) process.exitCode = 1;
104
+ }
105
+
106
+ main();
@@ -5,11 +5,26 @@ const fs = require("node:fs");
5
5
  const path = require("node:path");
6
6
  const crypto = require("node:crypto");
7
7
 
8
+ const BACKUP_ROOT_NAME = ".cew-backups";
9
+ const LEGACY_TOP_LEVEL_BAK = /^(?:CLAUDE\.md|AGENTS\.md|settings\.json)\.bak\..+$/;
10
+ const LEGACY_RULE_BAK = /\.md\.bak\..+$/;
11
+
8
12
  const digest = (content) => crypto.createHash("sha256")
9
13
  .update(content.toString("utf8").replace(/\r\n/g, "\n")).digest("hex");
10
14
 
11
- // Only cross-task policies belong in Claude's automatically loaded rules directory.
12
- const claudeResidentRules = new Set(["01-base.md", "05-git-workflow.md", "07-forbidden.md"]);
15
+ function defaultBackupId() {
16
+ const d = new Date();
17
+ const pad = (n) => String(n).padStart(2, "0");
18
+ return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
19
+ }
20
+
21
+ // Top-level rules stay in Claude's auto-loaded rules/; common/* loads on demand from references/rules/.
22
+ const claudeResidentRules = new Set(["01-base.md", "02-implementation.md", "05-git-workflow.md"]);
23
+ const retiredTopLevelRules = [
24
+ "07-forbidden.md",
25
+ "08-specialty-rules-index.md",
26
+ "09-first-principles-adversarial-testing.md",
27
+ ];
13
28
 
14
29
  // Check the root and every descendant before touching a managed file; do not follow links.
15
30
  function checkedPath(root, relative) {
@@ -30,15 +45,18 @@ function checkedPath(root, relative) {
30
45
  return target;
31
46
  }
32
47
 
33
- function copyRule({ source, root, relative, dryRun, log }) {
48
+ function copyRule({ source, root, relative, backupId, dryRun, log }) {
34
49
  const target = checkedPath(root, relative);
35
50
  const content = fs.readFileSync(source);
36
51
  if (fs.existsSync(target)) {
37
52
  const previous = fs.readFileSync(target);
38
53
  if (content.equals(previous)) return;
39
- const backup = checkedPath(root, relative + ".bak." + digest(previous));
54
+ const backup = checkedPath(root, path.posix.join(BACKUP_ROOT_NAME, backupId, relative));
40
55
  log(`${dryRun ? "[dry-run] " : ""}备份规则: ${backup}`);
41
- if (!dryRun && !fs.existsSync(backup)) fs.copyFileSync(target, backup, fs.constants.COPYFILE_EXCL);
56
+ if (!dryRun) {
57
+ fs.mkdirSync(path.dirname(backup), { recursive: true });
58
+ fs.copyFileSync(target, backup);
59
+ }
42
60
  }
43
61
  log(`${dryRun ? "[dry-run] " : ""}安装规则: ${target}`);
44
62
  if (!dryRun) {
@@ -47,11 +65,39 @@ function copyRule({ source, root, relative, dryRun, log }) {
47
65
  }
48
66
  }
49
67
 
68
+ function installPromotedRule({ source, root, relative, knownHashes, backupId, dryRun, log }) {
69
+ const oldPath = checkedPath(root, `references/rules/${relative}`);
70
+ const destination = `rules/${relative}`;
71
+ const resident = checkedPath(root, destination);
72
+ const distributed = new Set([...knownHashes, digest(fs.readFileSync(source))]);
73
+ const personalContent = (file) => {
74
+ if (!fs.existsSync(file)) return null;
75
+ const content = fs.readFileSync(file);
76
+ return distributed.has(digest(content)) ? null : content;
77
+ };
78
+ const residentPolicy = personalContent(resident);
79
+ const oldPolicy = personalContent(oldPath);
80
+ if (residentPolicy) {
81
+ log(`保留常驻个人规则: ${resident}`);
82
+ if (oldPolicy && !residentPolicy.equals(oldPolicy)) {
83
+ log(`保留内容不同的个人参考副本: ${oldPath}`);
84
+ return;
85
+ }
86
+ } else {
87
+ copyRule({ source: oldPolicy ? oldPath : source, root, relative: destination, backupId, dryRun, log });
88
+ }
89
+ if (fs.existsSync(oldPath)) {
90
+ log(`${dryRun ? "[dry-run] " : ""}移除已迁入常驻目录的规则: ${oldPath}`);
91
+ if (!dryRun) fs.unlinkSync(oldPath);
92
+ }
93
+ }
94
+
50
95
  function retireRule({ source, root, relative, knownHashes, dryRun, log }) {
51
96
  const target = checkedPath(root, relative);
52
97
  if (!fs.existsSync(target)) return;
53
98
  const hash = digest(fs.readFileSync(target));
54
- if (hash !== digest(fs.readFileSync(source)) && !knownHashes.includes(hash)) {
99
+ const matchesSource = source && fs.existsSync(source) && hash === digest(fs.readFileSync(source));
100
+ if (!matchesSource && !knownHashes.includes(hash)) {
55
101
  log(`保留个人修改,仍可能自动加载: ${target}`);
56
102
  return;
57
103
  }
@@ -59,7 +105,70 @@ function retireRule({ source, root, relative, knownHashes, dryRun, log }) {
59
105
  if (!dryRun) fs.unlinkSync(target);
60
106
  }
61
107
 
62
- function installRules({ sourceRoot, installRoot, host, dryRun = false, log = console.log }) {
108
+ function archiveLegacyBackups(root, relDir, pattern, recursive, dryRun, log) {
109
+ const dir = checkedPath(root, relDir);
110
+ if (!fs.existsSync(dir)) return;
111
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
112
+ if (entry.isSymbolicLink()) continue;
113
+ const childRel = relDir === "." ? entry.name : path.posix.join(relDir, entry.name);
114
+ if (entry.isDirectory()) {
115
+ if (recursive) archiveLegacyBackups(root, childRel, pattern, true, dryRun, log);
116
+ } else if (entry.isFile() && pattern.test(entry.name)) {
117
+ const target = checkedPath(root, childRel);
118
+ const archive = checkedPath(root, path.join(BACKUP_ROOT_NAME, "legacy", childRel));
119
+ log(`${dryRun ? "[dry-run] " : ""}归档历史备份: ${target}`);
120
+ if (dryRun) continue;
121
+ fs.mkdirSync(path.dirname(archive), { recursive: true });
122
+ try {
123
+ fs.copyFileSync(target, archive, fs.constants.COPYFILE_EXCL);
124
+ } catch (error) {
125
+ if (error.code !== "EEXIST") throw error;
126
+ if (!fs.readFileSync(target).equals(fs.readFileSync(archive))) continue;
127
+ }
128
+ fs.unlinkSync(target);
129
+ }
130
+ }
131
+ }
132
+
133
+ // Snapshots are sparse. Only retire a file after seeing a newer backup of the same path.
134
+ function pruneSupersededFiles(snapshot, relative, seen, dryRun, log) {
135
+ const dir = checkedPath(snapshot, relative);
136
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
137
+ const child = path.join(relative, entry.name);
138
+ if (entry.isDirectory()) {
139
+ pruneSupersededFiles(snapshot, child, seen, dryRun, log);
140
+ } else if (entry.isFile()) {
141
+ if (seen.has(child)) {
142
+ const file = checkedPath(snapshot, child);
143
+ log(`${dryRun ? "[dry-run] " : ""}清理已有较新副本的备份: ${file}`);
144
+ if (!dryRun) fs.unlinkSync(file);
145
+ }
146
+ seen.add(child);
147
+ }
148
+ }
149
+ if (!dryRun && fs.readdirSync(dir).length === 0) fs.rmdirSync(dir);
150
+ }
151
+
152
+ function finalizeBackups({ installRoot, dryRun = false, log = console.log }) {
153
+ const root = path.resolve(installRoot);
154
+ if (!fs.existsSync(root)) return;
155
+ archiveLegacyBackups(root, ".", LEGACY_TOP_LEVEL_BAK, false, dryRun, log);
156
+ archiveLegacyBackups(root, "rules", LEGACY_RULE_BAK, true, dryRun, log);
157
+ archiveLegacyBackups(root, "references/rules", LEGACY_RULE_BAK, true, dryRun, log);
158
+
159
+ const backupRoot = checkedPath(root, BACKUP_ROOT_NAME);
160
+ if (!fs.existsSync(backupRoot)) return;
161
+ const snapshots = fs.readdirSync(backupRoot, { withFileTypes: true })
162
+ .filter((entry) => entry.isDirectory() && /^\d{14}$/.test(entry.name))
163
+ .map((entry) => entry.name)
164
+ .sort().reverse();
165
+ const seen = new Set();
166
+ for (const snapshot of snapshots) {
167
+ pruneSupersededFiles(checkedPath(backupRoot, snapshot), "", seen, dryRun, log);
168
+ }
169
+ }
170
+
171
+ function installRules({ sourceRoot, installRoot, host, backupId = defaultBackupId(), dryRun = false, log = console.log }) {
63
172
  if (!["claude-code", "codex"].includes(host)) throw new Error(`Invalid host: ${host}`);
64
173
  const root = path.resolve(installRoot);
65
174
  const rulesRoot = path.join(sourceRoot, "rules");
@@ -71,32 +180,92 @@ function installRules({ sourceRoot, installRoot, host, dryRun = false, log = con
71
180
  .filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
72
181
  .map((entry) => `common/${entry.name}`);
73
182
  const installedOnDemand = (relative) => host === "claude-code" && !claudeResidentRules.has(relative);
183
+ const promoted = (relative) => host === "claude-code" && relative === "02-implementation.md";
74
184
  // Validate all managed destinations before the first write, including upgrade cleanup paths.
185
+ checkedPath(root, BACKUP_ROOT_NAME);
75
186
  for (const relative of [...files, ...commonFiles]) {
76
187
  checkedPath(root, `rules/${relative}`);
77
- if (installedOnDemand(relative)) {
188
+ if (installedOnDemand(relative) || promoted(relative)) {
78
189
  checkedPath(root, `references/rules/${relative}`);
79
190
  }
80
191
  }
192
+ for (const retired of retiredTopLevelRules) {
193
+ checkedPath(root, `rules/${retired}`);
194
+ if (host === "claude-code") checkedPath(root, `references/rules/${retired}`);
195
+ }
81
196
  for (const relative of [...files, ...commonFiles]) {
82
197
  const source = path.join(rulesRoot, relative);
198
+ if (promoted(relative)) {
199
+ installPromotedRule({ source, root, relative, knownHashes: legacy.files[relative] || [], backupId, dryRun, log });
200
+ continue;
201
+ }
83
202
  const cold = installedOnDemand(relative);
84
- copyRule({ source, root, relative: `${cold ? "references/rules" : "rules"}/${relative}`, dryRun, log });
85
- if (cold) retireRule({ source, root, relative: `rules/${relative}`,
86
- knownHashes: legacy.files[relative] || [], dryRun, log });
203
+ copyRule({ source, root, relative: `${cold ? "references/rules" : "rules"}/${relative}`, backupId, dryRun, log });
204
+ if (cold) {
205
+ retireRule({
206
+ source, root, relative: `rules/${relative}`,
207
+ knownHashes: legacy.files[relative] || [], dryRun, log,
208
+ });
209
+ }
210
+ }
211
+ for (const retired of retiredTopLevelRules) {
212
+ const knownHashes = legacy.files[retired] || [];
213
+ retireRule({ source: null, root, relative: `rules/${retired}`, knownHashes, dryRun, log });
214
+ if (host === "claude-code") {
215
+ retireRule({ source: null, root, relative: `references/rules/${retired}`, knownHashes, dryRun, log });
216
+ }
87
217
  }
88
218
  }
89
219
 
90
- module.exports = { installRules };
220
+ module.exports = { BACKUP_ROOT_NAME, installRules, finalizeBackups };
221
+
222
+ function parseCli(argv) {
223
+ let dryRun = false;
224
+ let backupId;
225
+ let finalize = false;
226
+ const positional = [];
227
+ for (let i = 0; i < argv.length; i += 1) {
228
+ const arg = argv[i];
229
+ if (arg === "--dry-run") {
230
+ dryRun = true;
231
+ } else if (arg === "--finalize-backups") {
232
+ finalize = true;
233
+ } else if (arg === "--backup-id") {
234
+ backupId = argv[++i];
235
+ if (!backupId || backupId.includes("/") || backupId.includes("\\") || backupId.includes("..")) {
236
+ throw new Error("Invalid --backup-id");
237
+ }
238
+ } else if (arg.startsWith("-")) {
239
+ throw new Error(`Unknown option: ${arg}`);
240
+ } else {
241
+ positional.push(arg);
242
+ }
243
+ }
244
+ return { dryRun, backupId, finalize, positional };
245
+ }
91
246
 
92
247
  if (require.main === module) {
93
- const [host, installRoot, ...options] = process.argv.slice(2);
94
248
  try {
95
- if (!installRoot || options.some((option) => option !== "--dry-run")) {
96
- throw new Error("Usage: install-rules.js <claude-code|codex> <install-root> [--dry-run]");
249
+ const { dryRun, backupId, finalize, positional } = parseCli(process.argv.slice(2));
250
+ if (finalize) {
251
+ const [installRoot] = positional;
252
+ if (!installRoot || positional.length !== 1) {
253
+ throw new Error("Usage: install-rules.js --finalize-backups <install-root> [--backup-id <id>] [--dry-run]");
254
+ }
255
+ finalizeBackups({ installRoot, backupId, dryRun });
256
+ } else {
257
+ const [host, installRoot] = positional;
258
+ if (!host || !installRoot || positional.length !== 2) {
259
+ throw new Error("Usage: install-rules.js <claude-code|codex> <install-root> [--backup-id <id>] [--dry-run]");
260
+ }
261
+ installRules({
262
+ sourceRoot: path.resolve(__dirname, ".."),
263
+ installRoot,
264
+ host,
265
+ backupId: backupId || defaultBackupId(),
266
+ dryRun,
267
+ });
97
268
  }
98
- installRules({ sourceRoot: path.resolve(__dirname, ".."), installRoot, host,
99
- dryRun: options.includes("--dry-run") });
100
269
  } catch (error) {
101
270
  process.stderr.write(`${error.message}\n`);
102
271
  process.exitCode = 1;
@@ -22,6 +22,7 @@ if (-not $HomeDir) {
22
22
 
23
23
  $InstallClaude = -not $CodexOnly
24
24
  $InstallCodex = -not $ClaudeOnly
25
+ $BackupId = Get-Date -Format 'yyyyMMddHHmmss'
25
26
 
26
27
  function Invoke-InstallCommand {
27
28
  param(
@@ -40,7 +41,8 @@ function Invoke-InstallCommand {
40
41
  function Backup-IfChanged {
41
42
  param(
42
43
  [string]$Source,
43
- [string]$Destination
44
+ [string]$Destination,
45
+ [string]$InstallRoot
44
46
  )
45
47
 
46
48
  if (-not (Test-Path -LiteralPath $Destination)) {
@@ -53,8 +55,19 @@ function Backup-IfChanged {
53
55
  return
54
56
  }
55
57
 
56
- $backup = "$Destination.bak.$(Get-Date -Format 'yyyyMMddHHmmss')"
58
+ $backupRoot = Join-Path $InstallRoot ".cew-backups"
59
+ $existingBackupRoot = Get-Item -LiteralPath $backupRoot -Force -ErrorAction SilentlyContinue
60
+ if ($null -ne $existingBackupRoot -and ($existingBackupRoot.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
61
+ throw "Refusing symlinked backup directory: $backupRoot"
62
+ }
63
+
64
+ $relative = [IO.Path]::GetFileName($Destination)
65
+ $backupDir = Join-Path $backupRoot $BackupId
66
+ $backup = Join-Path $backupDir $relative
57
67
  Write-Host "Backup: $Destination -> $backup"
68
+ Invoke-InstallCommand `
69
+ -Description "New-Item -ItemType Directory '$backupDir'" `
70
+ -Action { New-Item -ItemType Directory -Path $backupDir -Force | Out-Null }
58
71
  Invoke-InstallCommand `
59
72
  -Description "Copy-Item '$Destination' '$backup'" `
60
73
  -Action { Copy-Item -LiteralPath $Destination -Destination $backup -Force }
@@ -63,10 +76,11 @@ function Backup-IfChanged {
63
76
  function Copy-ConfigFile {
64
77
  param(
65
78
  [string]$Source,
66
- [string]$Destination
79
+ [string]$Destination,
80
+ [string]$InstallRoot
67
81
  )
68
82
 
69
- Backup-IfChanged -Source $Source -Destination $Destination
83
+ Backup-IfChanged -Source $Source -Destination $Destination -InstallRoot $InstallRoot
70
84
  Invoke-InstallCommand `
71
85
  -Description "Copy-Item '$Source' '$Destination'" `
72
86
  -Action { Copy-Item -LiteralPath $Source -Destination $Destination -Force }
@@ -75,10 +89,11 @@ function Copy-ConfigFile {
75
89
  function Copy-ClaudeSettings {
76
90
  param(
77
91
  [string]$Source,
78
- [string]$Destination
92
+ [string]$Destination,
93
+ [string]$InstallRoot
79
94
  )
80
95
 
81
- Backup-IfChanged -Source $Source -Destination $Destination
96
+ Backup-IfChanged -Source $Source -Destination $Destination -InstallRoot $InstallRoot
82
97
 
83
98
  if ($DryRun) {
84
99
  Write-Host "[dry-run] Merge '$Source' into '$Destination' preserving existing user hooks, env and mcpServers"
@@ -145,19 +160,18 @@ function Remove-PackageOnlyPaths {
145
160
  "scripts\install.ps1",
146
161
  "scripts\install-rules.js",
147
162
  "scripts\legacy-common-rule-hashes.json",
163
+ "scripts\eval-scenarios.js",
148
164
  "scripts\verify-harness.js",
149
165
  "scripts\verify\core.js",
150
- "scripts\verify\grilling-spec-gate-checks.js",
151
166
  "scripts\verify\metadata-checks.js",
152
167
  "scripts\verify\repository-checks.js",
153
168
  "scripts\verify\runtime-checks.js",
154
169
  "scripts\verify\workflow-checks.js",
155
- "scripts\verify\workflow-ownership-fixtures.js",
156
- "scripts\verify\workflow-ownership.js",
170
+ "scripts\verify\scenario-checks.js",
171
+ "scripts\verify\scenario-checks.test.js",
157
172
  "scripts\verify\skill-manifest-checks.js",
158
173
  "scripts\verify\skill-manifest-checks.test.js",
159
174
  "scripts\verify\skill-invocation.test.js",
160
- "scripts\verify\continuation-checks.test.js",
161
175
  "scripts\verify\install-rules.test.js",
162
176
  "scripts\verify\learning.test.js",
163
177
  "scripts\verify\plugin-distribution.test.js"
@@ -284,14 +298,15 @@ function Install-ClaudeWorkflow {
284
298
  -Action { New-Item -ItemType Directory -Path $dest -Force | Out-Null }
285
299
 
286
300
  Remove-ObsoleteWorkflowPaths -Destination $dest
287
- Copy-ConfigFile -Source (Join-Path $RootDir "CLAUDE.md") -Destination (Join-Path $dest "CLAUDE.md")
288
- Copy-ConfigFile -Source (Join-Path $RootDir "AGENTS.md") -Destination (Join-Path $dest "AGENTS.md")
301
+ Copy-ConfigFile -Source (Join-Path $RootDir "CLAUDE.md") -Destination (Join-Path $dest "CLAUDE.md") -InstallRoot $dest
302
+ Copy-ConfigFile -Source (Join-Path $RootDir "AGENTS.md") -Destination (Join-Path $dest "AGENTS.md") -InstallRoot $dest
289
303
  $settingsPath = Join-Path $dest "settings.json"
290
- Copy-ClaudeSettings -Source (Join-Path $RootDir "settings.json") -Destination $settingsPath
304
+ Copy-ClaudeSettings -Source (Join-Path $RootDir "settings.json") -Destination $settingsPath -InstallRoot $dest
291
305
  Install-SharedDirs -Destination $dest
292
306
  Install-WorkflowRules -Destination $dest -HostName "claude-code"
293
307
  Remove-RetiredSkills -Destination $dest
294
308
  Remove-PackageOnlyPaths -Destination $dest
309
+ Complete-WorkflowBackups -Destination $dest
295
310
  }
296
311
 
297
312
  function Install-CodexWorkflow {
@@ -303,17 +318,18 @@ function Install-CodexWorkflow {
303
318
  -Action { New-Item -ItemType Directory -Path $dest -Force | Out-Null }
304
319
 
305
320
  Remove-ObsoleteWorkflowPaths -Destination $dest
306
- Copy-ConfigFile -Source (Join-Path $RootDir "AGENTS.md") -Destination (Join-Path $dest "AGENTS.md")
321
+ Copy-ConfigFile -Source (Join-Path $RootDir "AGENTS.md") -Destination (Join-Path $dest "AGENTS.md") -InstallRoot $dest
307
322
  Install-SharedDirs -Destination $dest
308
323
  Install-WorkflowRules -Destination $dest -HostName "codex"
309
324
  Remove-RetiredSkills -Destination $dest
310
325
  Remove-PackageOnlyPaths -Destination $dest
326
+ Complete-WorkflowBackups -Destination $dest
311
327
  }
312
328
 
313
329
  function Install-WorkflowRules {
314
330
  param([string]$Destination, [string]$HostName)
315
331
 
316
- $ruleArgs = @((Join-Path $RootDir "scripts\install-rules.js"), $HostName, $Destination)
332
+ $ruleArgs = @((Join-Path $RootDir "scripts\install-rules.js"), $HostName, $Destination, "--backup-id", $BackupId)
317
333
  if ($DryRun) { $ruleArgs += "--dry-run" }
318
334
  & node @ruleArgs
319
335
  if ($LASTEXITCODE -ne 0) {
@@ -321,6 +337,17 @@ function Install-WorkflowRules {
321
337
  }
322
338
  }
323
339
 
340
+ function Complete-WorkflowBackups {
341
+ param([string]$Destination)
342
+
343
+ $backupArgs = @((Join-Path $RootDir "scripts\install-rules.js"), "--finalize-backups", $Destination, "--backup-id", $BackupId)
344
+ if ($DryRun) { $backupArgs += "--dry-run" }
345
+ & node @backupArgs
346
+ if ($LASTEXITCODE -ne 0) {
347
+ throw "Backup finalization failed with exit code $LASTEXITCODE"
348
+ }
349
+ }
350
+
324
351
  if ($InstallClaude) {
325
352
  Test-InstallRoot -Destination (Join-Path $HomeDir ".claude")
326
353
  }
@@ -8,6 +8,7 @@ INSTALL_CLAUDE=1
8
8
  INSTALL_CODEX=1
9
9
  DRY_RUN=0
10
10
  SHOW_HELP=0
11
+ BACKUP_ID="$(date +%Y%m%d%H%M%S)"
11
12
 
12
13
  usage() {
13
14
  cat <<'EOF'
@@ -75,29 +76,39 @@ run() {
75
76
  backup_if_changed() {
76
77
  local src="$1"
77
78
  local dest="$2"
79
+ local install_root="$3"
78
80
 
79
81
  if [ ! -f "$dest" ] || cmp -s "$src" "$dest"; then
80
82
  return
81
83
  fi
82
84
 
83
- local backup="${dest}.bak.$(date +%Y%m%d%H%M%S)"
85
+ if [ -L "$install_root/.cew-backups" ]; then
86
+ echo "Refusing symlinked backup directory: $install_root/.cew-backups" >&2
87
+ exit 1
88
+ fi
89
+
90
+ local rel_name="${dest#"$install_root"/}"
91
+ local backup="$install_root/.cew-backups/$BACKUP_ID/$rel_name"
84
92
  echo "Backup: $dest -> $backup"
93
+ run mkdir -p "$(dirname "$backup")"
85
94
  run cp "$dest" "$backup"
86
95
  }
87
96
 
88
97
  copy_file() {
89
98
  local src="$1"
90
99
  local dest="$2"
100
+ local install_root="$3"
91
101
 
92
- backup_if_changed "$src" "$dest"
102
+ backup_if_changed "$src" "$dest" "$install_root"
93
103
  run cp "$src" "$dest"
94
104
  }
95
105
 
96
106
  copy_claude_settings() {
97
107
  local src="$1"
98
108
  local dest="$2"
109
+ local install_root="$3"
99
110
 
100
- backup_if_changed "$src" "$dest"
111
+ backup_if_changed "$src" "$dest" "$install_root"
101
112
  if [ "$DRY_RUN" -eq 1 ]; then
102
113
  echo "[dry-run] merge '$src' into '$dest' preserving existing user hooks, env and mcpServers"
103
114
  echo "[dry-run] purge legacy hook paths while merging Claude settings"
@@ -156,19 +167,18 @@ remove_package_only_paths() {
156
167
  "scripts/install.ps1" \
157
168
  "scripts/install-rules.js" \
158
169
  "scripts/legacy-common-rule-hashes.json" \
170
+ "scripts/eval-scenarios.js" \
159
171
  "scripts/verify-harness.js" \
160
172
  "scripts/verify/core.js" \
161
- "scripts/verify/grilling-spec-gate-checks.js" \
162
173
  "scripts/verify/metadata-checks.js" \
163
174
  "scripts/verify/repository-checks.js" \
164
175
  "scripts/verify/runtime-checks.js" \
165
176
  "scripts/verify/workflow-checks.js" \
166
- "scripts/verify/workflow-ownership-fixtures.js" \
167
- "scripts/verify/workflow-ownership.js" \
177
+ "scripts/verify/scenario-checks.js" \
178
+ "scripts/verify/scenario-checks.test.js" \
168
179
  "scripts/verify/skill-manifest-checks.js" \
169
180
  "scripts/verify/skill-manifest-checks.test.js" \
170
181
  "scripts/verify/skill-invocation.test.js" \
171
- "scripts/verify/continuation-checks.test.js" \
172
182
  "scripts/verify/install-rules.test.js" \
173
183
  "scripts/verify/learning.test.js" \
174
184
  "scripts/verify/plugin-distribution.test.js"
@@ -259,13 +269,14 @@ install_claude() {
259
269
  echo "Installing Claude workflow to $dest"
260
270
  run mkdir -p "$dest"
261
271
  remove_obsolete_workflow_paths "$dest"
262
- copy_file "$ROOT_DIR/CLAUDE.md" "$dest/CLAUDE.md"
263
- copy_file "$ROOT_DIR/AGENTS.md" "$dest/AGENTS.md"
264
- copy_claude_settings "$ROOT_DIR/settings.json" "$dest/settings.json"
272
+ copy_file "$ROOT_DIR/CLAUDE.md" "$dest/CLAUDE.md" "$dest"
273
+ copy_file "$ROOT_DIR/AGENTS.md" "$dest/AGENTS.md" "$dest"
274
+ copy_claude_settings "$ROOT_DIR/settings.json" "$dest/settings.json" "$dest"
265
275
  install_shared_dirs "$dest"
266
276
  install_workflow_rules claude-code "$dest"
267
277
  cleanup_retired_skills "$dest"
268
278
  remove_package_only_paths "$dest"
279
+ finalize_backups "$dest"
269
280
  }
270
281
 
271
282
  install_codex() {
@@ -274,18 +285,26 @@ install_codex() {
274
285
  echo "Installing Codex workflow to $dest"
275
286
  run mkdir -p "$dest"
276
287
  remove_obsolete_workflow_paths "$dest"
277
- copy_file "$ROOT_DIR/AGENTS.md" "$dest/AGENTS.md"
288
+ copy_file "$ROOT_DIR/AGENTS.md" "$dest/AGENTS.md" "$dest"
278
289
  install_shared_dirs "$dest"
279
290
  install_workflow_rules codex "$dest"
280
291
  cleanup_retired_skills "$dest"
281
292
  remove_package_only_paths "$dest"
293
+ finalize_backups "$dest"
282
294
  }
283
295
 
284
296
  install_workflow_rules() {
285
297
  local host_name="$1"
286
298
  local dest="$2"
287
299
  # Bash <4.4 treats empty arrays as unset under set -u.
288
- local options=("$ROOT_DIR/scripts/install-rules.js" "$host_name" "$dest")
300
+ local options=("$ROOT_DIR/scripts/install-rules.js" "$host_name" "$dest" "--backup-id" "$BACKUP_ID")
301
+ if [ "$DRY_RUN" -eq 1 ]; then options+=(--dry-run); fi
302
+ node "${options[@]}"
303
+ }
304
+
305
+ finalize_backups() {
306
+ local dest="$1"
307
+ local options=("$ROOT_DIR/scripts/install-rules.js" "--finalize-backups" "$dest" "--backup-id" "$BACKUP_ID")
289
308
  if [ "$DRY_RUN" -eq 1 ]; then options+=(--dry-run); fi
290
309
  node "${options[@]}"
291
310
  }
@@ -8,6 +8,7 @@
8
8
  "700331676ad40d65acdeb469a67cf802cddff78ebf0861ec5e4427b5a3d23620"
9
9
  ],
10
10
  "08-specialty-rules-index.md": [
11
+ "11d3be1b194abcf30517a416df1f337cb356fa9bc04604bcfb95274478012050",
11
12
  "283aba947990fd768597546f3aab12f8754d4d91968d6d119c3f5828c6be40dd",
12
13
  "3fe1bcb7bdbad9ff8b074a36afd96b96fdf0da21c483b842c4ce2042ca398999",
13
14
  "70f531356fd1fbd11d62ea0b2b43be82c278e975b43335a8b3956c207a930ef1",
@@ -88,6 +89,9 @@
88
89
  "c9f169a9720c038749d729f15cb110fe67d0f748fc7de73e301b3726509651ae",
89
90
  "f10250dbc8a67c47b514defca1f97ce00cb2096aa9dada92ce410f308c9ffda5",
90
91
  "f593217cd46431850e8f1c135c5e604cb71da7bd0c6614e8036d7bd7b0e9e92a"
92
+ ],
93
+ "07-forbidden.md": [
94
+ "925a8a1e3df9a734522d570f967912ca7b6f69a83aceb8499bda3e292dcd16a5"
91
95
  ]
92
96
  }
93
97
  }
@@ -58,6 +58,13 @@
58
58
  ],
59
59
  "verification-before-completion": [
60
60
  "SKILL.md"
61
+ ],
62
+ "subagent-driven-development": [
63
+ "SKILL.md"
64
+ ],
65
+ "e2e-testing": [
66
+ "SKILL.md",
67
+ "references/playwright-patterns.md"
61
68
  ]
62
69
  }
63
70
  }