claude-everything-workflow 0.1.9 → 0.2.2

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 (135) hide show
  1. package/AGENTS.md +19 -20
  2. package/README.md +112 -104
  3. package/agents/code-reviewer.md +15 -44
  4. package/agents/harness-optimizer.md +3 -2
  5. package/agents/planner.md +23 -107
  6. package/commands/code-review.md +25 -9
  7. package/commands/learn.md +97 -0
  8. package/commands/pr.md +4 -0
  9. package/commands/to-spec.md +11 -0
  10. package/hooks/check-code-size.js +33 -12
  11. package/hooks/check-console-log.js +72 -24
  12. package/package.json +5 -2
  13. package/rules/01-base.md +19 -42
  14. package/rules/02-code-size.md +6 -17
  15. package/rules/03-architecture.md +16 -54
  16. package/rules/04-error-handling.md +4 -25
  17. package/rules/05-git-workflow.md +9 -37
  18. package/rules/06-comments.md +3 -37
  19. package/rules/07-forbidden.md +6 -30
  20. package/rules/08-specialty-rules-index.md +18 -0
  21. package/rules/09-first-principles-adversarial-testing.md +6 -18
  22. package/rules/common/agent-orchestration.md +10 -47
  23. package/rules/common/context-hygiene.md +9 -72
  24. package/rules/common/harness-engineering.md +11 -38
  25. package/rules/common/hooks.md +11 -82
  26. package/rules/common/performance.md +8 -71
  27. package/rules/common/pr-automation.md +7 -68
  28. package/rules/common/skills-learning.md +12 -36
  29. package/rules/common/testing.md +15 -59
  30. package/scripts/cleanup-retired-skills.js +214 -0
  31. package/scripts/install.ps1 +73 -85
  32. package/scripts/install.sh +54 -77
  33. package/scripts/learning/review-confidence.js +1 -4
  34. package/scripts/merge-claude-settings.cjs +75 -0
  35. package/scripts/retired-skill-files.json +37 -0
  36. package/scripts/upstream-capability-baseline.json +27 -0
  37. package/scripts/upstream-capability-map.json +150 -0
  38. package/scripts/verify/core.js +91 -0
  39. package/scripts/verify/grilling-spec-gate-checks.js +260 -0
  40. package/scripts/verify/metadata-checks.js +724 -0
  41. package/scripts/verify/repository-checks.js +435 -0
  42. package/scripts/verify/runtime-checks.js +593 -0
  43. package/scripts/verify/workflow-checks.js +741 -0
  44. package/scripts/verify/workflow-ownership-fixtures.js +371 -0
  45. package/scripts/verify/workflow-ownership.js +780 -0
  46. package/scripts/verify-harness.js +16 -1075
  47. package/scripts/verify-upstream-capability-map.js +117 -0
  48. package/skills/README.md +24 -11
  49. package/skills/code-review/SKILL.md +50 -0
  50. package/skills/code-review/references/spec-reviewer-prompt.md +24 -0
  51. package/skills/code-review/references/standards-reviewer-prompt.md +35 -0
  52. package/skills/codebase-design/SKILL.md +63 -0
  53. package/skills/codebase-design/references/deepening.md +27 -0
  54. package/skills/codebase-design/references/design-it-twice.md +17 -0
  55. package/skills/continuous-learning-v2/SKILL.md +7 -7
  56. package/skills/continuous-learning-v2/config.json +0 -4
  57. package/skills/domain-modeling/SKILL.md +100 -0
  58. package/skills/feature-acceptance/SKILL.md +89 -0
  59. package/skills/grilling/SKILL.md +83 -0
  60. package/skills/handoff/SKILL.md +56 -0
  61. package/skills/implement/SKILL.md +97 -0
  62. package/skills/improve-codebase-architecture/SKILL.md +48 -0
  63. package/skills/iterative-retrieval/SKILL.md +10 -1
  64. package/skills/learn/README.md +2 -2
  65. package/skills/project-context/SKILL.md +94 -0
  66. package/skills/project-context/agents/openai.yaml +6 -0
  67. package/skills/project-context/references/project-context-template.md +61 -0
  68. package/skills/prototype/SKILL.md +50 -0
  69. package/skills/prototype/references/logic.md +28 -0
  70. package/skills/prototype/references/ui.md +30 -0
  71. package/skills/research/SKILL.md +48 -0
  72. package/skills/resolving-merge-conflicts/SKILL.md +27 -0
  73. package/skills/spec-gate/SKILL.md +149 -0
  74. package/skills/spec-gate/agents/openai.yaml +4 -0
  75. package/skills/spec-gate/references/spec-document-reviewer-prompt.md +31 -0
  76. package/skills/subagent-driven-development/SKILL.md +95 -414
  77. package/skills/systematic-debugging/SKILL.md +7 -51
  78. package/skills/systematic-debugging/references/diagnosing-bugs.upstream.md +129 -0
  79. package/skills/systematic-debugging/scripts/hitl-loop.template.js +75 -0
  80. package/skills/systematic-debugging/scripts/hitl-loop.template.sh +41 -0
  81. package/skills/test-driven-development/SKILL.md +18 -2
  82. package/skills/to-tickets/SKILL.md +94 -0
  83. package/skills/triage/SKILL.md +53 -0
  84. package/skills/triage/references/agent-brief.md +32 -0
  85. package/skills/triage/references/out-of-scope.md +14 -0
  86. package/skills/using-superpowers/SKILL.md +140 -40
  87. package/skills/visual-companion/SKILL.md +62 -0
  88. package/skills/visual-companion/agents/openai.yaml +4 -0
  89. package/skills/{brainstorming/visual-companion.md → visual-companion/references/guide.md} +1 -1
  90. package/skills/{brainstorming → visual-companion}/scripts/frame-template.html +42 -12
  91. package/skills/visual-companion/scripts/pages.cjs +28 -0
  92. package/skills/visual-companion/scripts/server-utils.cjs +82 -0
  93. package/skills/{brainstorming → visual-companion}/scripts/server.cjs +108 -248
  94. package/skills/{brainstorming → visual-companion}/scripts/start-server.sh +18 -4
  95. package/skills/visual-companion/scripts/websocket.cjs +86 -0
  96. package/skills/wayfinder/SKILL.md +57 -0
  97. package/commands/e2e.md +0 -28
  98. package/commands/evolve.md +0 -42
  99. package/commands/harness-audit.md +0 -27
  100. package/commands/instinct-status.md +0 -38
  101. package/commands/learn-eval.md +0 -91
  102. package/commands/projects.md +0 -27
  103. package/commands/promote.md +0 -29
  104. package/commands/prune.md +0 -46
  105. package/commands/tdd.md +0 -27
  106. package/homunculus/instincts/personal/always-test-first.md +0 -28
  107. package/homunculus/instincts/personal/pr-ci-quality-gate.md +0 -30
  108. package/rules/08-ecc-integration.md +0 -46
  109. package/rules/common/implementation.md +0 -25
  110. package/rules/common/security.md +0 -19
  111. package/skills/brainstorming/SKILL.md +0 -185
  112. package/skills/brainstorming/agents/openai.yaml +0 -3
  113. package/skills/brainstorming/spec-document-reviewer-prompt.md +0 -49
  114. package/skills/context-budget/SKILL.md +0 -59
  115. package/skills/discover-unknowns-zh/SKILL.md +0 -112
  116. package/skills/discover-unknowns-zh/agents/openai.yaml +0 -4
  117. package/skills/discover-unknowns-zh/references/prompt-patterns.md +0 -144
  118. package/skills/documentation-lookup/SKILL.md +0 -90
  119. package/skills/executing-plans/SKILL.md +0 -66
  120. package/skills/skill-creator/LICENSE.txt +0 -202
  121. package/skills/skill-creator/SKILL.md +0 -356
  122. package/skills/skill-creator/references/output-patterns.md +0 -82
  123. package/skills/skill-creator/references/workflows.md +0 -28
  124. package/skills/skill-creator/scripts/init_skill.py +0 -303
  125. package/skills/skill-creator/scripts/package_skill.py +0 -110
  126. package/skills/skill-creator/scripts/quick_validate.py +0 -95
  127. package/skills/subagent-driven-development/implementer-prompt.md +0 -139
  128. package/skills/subagent-driven-development/scripts/review-package +0 -44
  129. package/skills/subagent-driven-development/scripts/sdd-workspace +0 -22
  130. package/skills/subagent-driven-development/scripts/task-brief +0 -40
  131. package/skills/subagent-driven-development/task-reviewer-prompt.md +0 -188
  132. package/skills/writing-plans/SKILL.md +0 -206
  133. package/skills/writing-plans/plan-document-reviewer-prompt.md +0 -49
  134. /package/skills/{brainstorming → visual-companion}/scripts/helper.js +0 -0
  135. /package/skills/{brainstorming → visual-companion}/scripts/stop-server.sh +0 -0
@@ -0,0 +1,593 @@
1
+ "use strict";
2
+
3
+ const fs = require("fs");
4
+ const os = require("os");
5
+ const path = require("path");
6
+ const { spawnSync } = require("child_process");
7
+
8
+ let root;
9
+ let rel;
10
+ let exists;
11
+ let read;
12
+ let managedFiles;
13
+ let fail;
14
+ let warn;
15
+ let requireTokens;
16
+ let isVerifierImplementation;
17
+
18
+ function bindContext(context) {
19
+ ({
20
+ root,
21
+ rel,
22
+ exists,
23
+ read,
24
+ managedFiles,
25
+ fail,
26
+ warn,
27
+ requireTokens,
28
+ isVerifierImplementation,
29
+ } = context);
30
+ }
31
+
32
+ function checkScriptLayout() {
33
+ for (const legacyPath of [
34
+ "scripts/hooks/run-with-flags.js",
35
+ "scripts/hooks/commit-quality.js",
36
+ "scripts/hooks/session-start.js",
37
+ "scripts/hooks/session-end.js",
38
+ "scripts/lib/hook-flags.js",
39
+ "scripts/lib/utils.js",
40
+ "scripts/learning/utils.js",
41
+ "hooks/review-confidence.js",
42
+ "hooks/session-start.js",
43
+ "hooks/session-end.js",
44
+ "hooks/evaluate-session.js",
45
+ "hooks/pre-compact.js",
46
+ "hooks/runtime/session-utils.js",
47
+ ]) {
48
+ if (exists(legacyPath)) {
49
+ fail(`${legacyPath} should not exist after script layout cleanup`);
50
+ }
51
+ }
52
+
53
+ for (const requiredPath of [
54
+ "hooks/runtime/run-with-flags.js",
55
+ "hooks/runtime/hook-flags.js",
56
+ "hooks/commit-quality.js",
57
+ "hooks/check-console-log.js",
58
+ "hooks/check-code-size.js",
59
+ "scripts/learning/review-confidence.js",
60
+ "scripts/learning/project-utils.js",
61
+ "scripts/learning/projects.js",
62
+ "scripts/learning/promote.js",
63
+ "scripts/learning/migrate-homunculus.js",
64
+ "scripts/merge-claude-settings.cjs",
65
+ ]) {
66
+ if (!exists(requiredPath)) {
67
+ fail(`${requiredPath} is missing after script layout cleanup`);
68
+ }
69
+ }
70
+
71
+ requireTokens("settings.json", [
72
+ "hooks/runtime/run-with-flags.js",
73
+ "hooks/check-console-log.js",
74
+ "hooks/check-code-size.js",
75
+ "hooks/commit-quality.js",
76
+ "skills/continuous-learning-v2/hooks/observe-v2.js",
77
+ ]);
78
+
79
+ requireTokens("scripts/install.ps1", [
80
+ "Remove-ObsoleteWorkflowPaths",
81
+ "Remove-RetiredSkills",
82
+ "Test-RetiredSkillManifest",
83
+ "scripts\\hooks\\run-with-flags.js",
84
+ "hooks\\review-confidence.js",
85
+ "rules\\08-ecc-integration.md",
86
+ ]);
87
+
88
+ requireTokens("scripts/install.sh", [
89
+ "remove_obsolete_workflow_paths",
90
+ "cleanup_retired_skills",
91
+ "validate_retired_skill_manifest",
92
+ "scripts/hooks/run-with-flags.js",
93
+ "hooks/review-confidence.js",
94
+ "rules/08-ecc-integration.md",
95
+ ]);
96
+
97
+ checkLegacyScriptReferences();
98
+ }
99
+
100
+ function checkLegacyScriptReferences() {
101
+ for (const file of managedFiles()) {
102
+ if (
103
+ isVerifierImplementation(file) ||
104
+ [
105
+ "scripts/install.ps1",
106
+ "scripts/install.sh",
107
+ "scripts/merge-claude-settings.cjs",
108
+ ].includes(file)
109
+ ) continue;
110
+ if (!/\.(md|json|js|ps1|sh)$/.test(file)) continue;
111
+
112
+ const body = read(file);
113
+ for (const forbidden of [
114
+ "scripts/hooks/run-with-flags.js",
115
+ "scripts/lib/hook-flags.js",
116
+ "hooks/review-confidence.js",
117
+ "hooks/session-start.js",
118
+ "hooks/session-end.js",
119
+ "hooks/evaluate-session.js",
120
+ "hooks/pre-compact.js",
121
+ "hooks/runtime/session-utils.js",
122
+ ]) {
123
+ if (body.includes(forbidden)) {
124
+ fail(`${file} references legacy path ${forbidden}`);
125
+ }
126
+ }
127
+ }
128
+ }
129
+
130
+ function checkContinuousLearningV21() {
131
+ requireTokens("skills/continuous-learning-v2/config.json", [
132
+ '"version": "2.1"',
133
+ '"data_root": "~/.local/share/ecc-homunculus"',
134
+ '"project_scoped": true',
135
+ '"promotion_min_confidence": 0.7',
136
+ ]);
137
+
138
+ requireTokens("skills/continuous-learning-v2/SKILL.md", [
139
+ "Continuous Learning v2.1",
140
+ "projects/<project-id>/",
141
+ "observations.jsonl",
142
+ "/learn projects",
143
+ "/learn promote --dry-run",
144
+ "migrate-homunculus.js --dry-run",
145
+ "observer.enabled",
146
+ ]);
147
+
148
+ requireTokens("skills/continuous-learning-v2/hooks/observe-v2.js", [
149
+ "registerProject",
150
+ "projects",
151
+ "observations.jsonl",
152
+ ]);
153
+
154
+ requireTokens("scripts/learning/review-confidence.js", [
155
+ "--scope <范围>",
156
+ "project",
157
+ "global",
158
+ "legacy",
159
+ ]);
160
+
161
+ requireTokens("commands/learn.md", [
162
+ "/learn projects",
163
+ "scripts/learning/projects.js",
164
+ "--register-current",
165
+ "/learn promote",
166
+ "scripts/learning/promote.js",
167
+ "--dry-run",
168
+ "--apply",
169
+ ]);
170
+ }
171
+
172
+ function checkObserveV2() {
173
+ const hook = rel("skills/continuous-learning-v2/hooks/observe-v2.js");
174
+ const config = rel("skills/continuous-learning-v2/config.json");
175
+ if (fs.existsSync(rel("hooks/observe.js"))) {
176
+ fail("legacy hooks/observe.js should not exist; use observe-v2 only");
177
+ }
178
+ if (!fs.existsSync(hook)) return fail("observe-v2.js is missing");
179
+ if (!fs.existsSync(config))
180
+ return fail("continuous-learning-v2 config is missing");
181
+
182
+ const tempHome = rel(".tmp-verify-harness");
183
+ const tempConfigDir = path.join(
184
+ tempHome,
185
+ ".claude",
186
+ "skills",
187
+ "continuous-learning-v2",
188
+ );
189
+ const observationsPath = path.join(
190
+ tempHome,
191
+ ".claude",
192
+ "homunculus",
193
+ "observations.jsonl",
194
+ );
195
+
196
+ fs.rmSync(tempHome, { recursive: true, force: true });
197
+ fs.mkdirSync(tempConfigDir, { recursive: true });
198
+
199
+ const cfg = JSON.parse(fs.readFileSync(config, "utf8"));
200
+ cfg.observation = cfg.observation || {};
201
+ cfg.observation.enabled = true;
202
+ cfg.observation.store_path = observationsPath;
203
+ fs.writeFileSync(
204
+ path.join(tempConfigDir, "config.json"),
205
+ JSON.stringify(cfg, null, 2),
206
+ );
207
+
208
+ const input = JSON.stringify({
209
+ tool: "Edit",
210
+ cwd: root,
211
+ tool_input: { file_path: "README.md" },
212
+ session_id: "verify-harness",
213
+ });
214
+
215
+ const result = spawnSync(process.execPath, [hook, "post"], {
216
+ cwd: root,
217
+ input,
218
+ encoding: "utf8",
219
+ env: {
220
+ ...process.env,
221
+ HOME: tempHome,
222
+ USERPROFILE: tempHome,
223
+ },
224
+ timeout: 10000,
225
+ });
226
+
227
+ if (result.error)
228
+ fail(`observe-v2 smoke test failed: ${result.error.message}`);
229
+ if (result.status !== 0)
230
+ fail(`observe-v2 exited ${result.status}: ${result.stderr}`);
231
+ if (!fs.existsSync(observationsPath)) {
232
+ fail("observe-v2 did not write observations.jsonl");
233
+ } else {
234
+ const firstLine = fs
235
+ .readFileSync(observationsPath, "utf8")
236
+ .split(/\r?\n/)[0];
237
+ try {
238
+ const event = JSON.parse(firstLine);
239
+ if (event.tool !== "Edit" || event.event !== "tool_complete") {
240
+ fail("observe-v2 wrote unexpected observation payload");
241
+ }
242
+ } catch (err) {
243
+ fail(`observe-v2 wrote invalid JSON: ${err.message}`);
244
+ }
245
+ }
246
+
247
+ fs.rmSync(tempHome, { recursive: true, force: true });
248
+ }
249
+
250
+ function runCodexInstall(tempHome) {
251
+ fs.mkdirSync(tempHome, { recursive: true });
252
+ const result = spawnSync(
253
+ "bash",
254
+ [rel("scripts/install.sh"), "--codex-only"],
255
+ {
256
+ cwd: root,
257
+ encoding: "utf8",
258
+ env: { ...process.env, HOME: tempHome, USERPROFILE: tempHome },
259
+ timeout: 30000,
260
+ },
261
+ );
262
+ if (result.error) {
263
+ fail(`Codex install smoke test failed: ${result.error.message}`);
264
+ return false;
265
+ }
266
+ if (result.status !== 0) {
267
+ fail(`Codex install smoke test exited ${result.status}: ${result.stderr}`);
268
+ return false;
269
+ }
270
+ return true;
271
+ }
272
+
273
+ function installedRuntimeSources(directory) {
274
+ if (!fs.existsSync(directory)) return [];
275
+ const sources = [];
276
+ const pending = [directory];
277
+ while (pending.length > 0) {
278
+ const current = pending.pop();
279
+ for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
280
+ const target = path.join(current, entry.name);
281
+ if (entry.isDirectory()) pending.push(target);
282
+ // Installed Node runtimes may use .js, .cjs, or .mjs module conventions.
283
+ if (entry.isFile() && /\.(?:c|m)?js$/.test(entry.name)) sources.push(target);
284
+ }
285
+ }
286
+ return sources;
287
+ }
288
+
289
+ function checkInstalledCommonmarkIsolation(codexHome) {
290
+ // Match CommonJS, dynamic/side-effect imports, package subpaths, and static `from` imports.
291
+ const commonmarkImport =
292
+ /(?:require|import)\s*(?:\(\s*)?["']commonmark(?:\/[^"']*)?["']|\bfrom\s*["']commonmark(?:\/[^"']*)?["']/;
293
+ for (const source of installedRuntimeSources(codexHome)) {
294
+ if (commonmarkImport.test(fs.readFileSync(source, "utf8"))) {
295
+ fail(`${source} must not import package-only commonmark`);
296
+ }
297
+ }
298
+ }
299
+
300
+ function checkInstalledPackageOnlyPaths() {
301
+ if (process.platform === "win32") return;
302
+
303
+ const tempRoot = fs.mkdtempSync(
304
+ path.join(os.tmpdir(), "cew-install-package-only-"),
305
+ );
306
+ try {
307
+ const cleanHome = path.join(tempRoot, "clean");
308
+ if (!runCodexInstall(cleanHome)) return;
309
+ const cleanScripts = path.join(cleanHome, ".codex", "scripts");
310
+ for (const relative of ["verify-harness.js", "verify"]) {
311
+ if (fs.existsSync(path.join(cleanScripts, relative))) {
312
+ fail(`Codex install must omit package-only scripts/${relative}`);
313
+ }
314
+ }
315
+ checkInstalledCommonmarkIsolation(path.join(cleanHome, ".codex"));
316
+
317
+ const preserveHome = path.join(tempRoot, "preserve");
318
+ const userFile = path.join(
319
+ preserveHome,
320
+ ".codex",
321
+ "scripts",
322
+ "verify",
323
+ "user-notes.js",
324
+ );
325
+ fs.mkdirSync(path.dirname(userFile), { recursive: true });
326
+ fs.writeFileSync(userFile, "// user-owned fixture\n");
327
+ if (!runCodexInstall(preserveHome)) return;
328
+ if (!fs.existsSync(userFile)) {
329
+ fail("Codex install removed an unknown user-owned verifier file");
330
+ }
331
+ checkInstalledCommonmarkIsolation(path.join(preserveHome, ".codex"));
332
+ } finally {
333
+ fs.rmSync(tempRoot, { recursive: true, force: true });
334
+ }
335
+ }
336
+
337
+ function createRetiredSkillFixture() {
338
+ const tempRoot = fs.mkdtempSync(
339
+ path.join(os.tmpdir(), "cew-retired-skill-cleanup-"),
340
+ );
341
+ const at = (...parts) => path.join(tempRoot, ...parts);
342
+ const fixture = {
343
+ tempRoot,
344
+ known: at("skills", "brainstorming", "SKILL.md"),
345
+ unknown: at("skills", "brainstorming", "user-notes.md"),
346
+ dryRunKnown: at("skills", "discover-unknowns-zh", "SKILL.md"),
347
+ creatorKnown: at("skills", "skill-creator", "scripts", "quick_validate.py"),
348
+ creatorUnknown: at("skills", "skill-creator", "user-template.md"),
349
+ nestedSymlink: at("skills", "brainstorming", "scripts"),
350
+ nestedExternalKnown: at("outside-nested-directory", "helper.js"),
351
+ rootSymlinkInstall: at("root-symlink-install"),
352
+ rootSymlink: at(
353
+ "root-symlink-install",
354
+ "skills",
355
+ "discover-unknowns-zh",
356
+ ),
357
+ rootExternalKnown: at("outside-retired-skill", "SKILL.md"),
358
+ leafSymlinkInstall: at("leaf-symlink-install"),
359
+ leafSymlink: at(
360
+ "leaf-symlink-install",
361
+ "skills",
362
+ "discover-unknowns-zh",
363
+ "SKILL.md",
364
+ ),
365
+ leafExternalKnown: at("outside-leaf-symlink", "SKILL.md"),
366
+ permissionInstall: at("permission-install"),
367
+ permissionSkillsRoot: at("permission-install", "skills"),
368
+ testLeafSymlink: process.platform !== "win32",
369
+ };
370
+
371
+ for (const file of [
372
+ fixture.known,
373
+ fixture.unknown,
374
+ fixture.dryRunKnown,
375
+ fixture.creatorKnown,
376
+ fixture.creatorUnknown,
377
+ ]) {
378
+ fs.mkdirSync(path.dirname(file), { recursive: true });
379
+ fs.writeFileSync(file, "fixture");
380
+ }
381
+ fs.mkdirSync(path.dirname(fixture.rootExternalKnown), { recursive: true });
382
+ fs.writeFileSync(fixture.rootExternalKnown, "must stay");
383
+ fs.mkdirSync(path.dirname(fixture.rootSymlink), { recursive: true });
384
+ fs.symlinkSync(
385
+ path.dirname(fixture.rootExternalKnown),
386
+ fixture.rootSymlink,
387
+ process.platform === "win32" ? "junction" : "dir",
388
+ );
389
+ fs.mkdirSync(path.dirname(fixture.nestedSymlink), { recursive: true });
390
+ fs.mkdirSync(path.dirname(fixture.nestedExternalKnown), { recursive: true });
391
+ fs.writeFileSync(fixture.nestedExternalKnown, "must also stay");
392
+ fs.symlinkSync(
393
+ path.dirname(fixture.nestedExternalKnown),
394
+ fixture.nestedSymlink,
395
+ process.platform === "win32" ? "junction" : "dir",
396
+ );
397
+ if (fixture.testLeafSymlink) {
398
+ fs.mkdirSync(path.dirname(fixture.leafSymlink), { recursive: true });
399
+ fs.mkdirSync(path.dirname(fixture.leafExternalKnown), { recursive: true });
400
+ fs.writeFileSync(fixture.leafExternalKnown, "must stay linked");
401
+ fs.symlinkSync(fixture.leafExternalKnown, fixture.leafSymlink, "file");
402
+ }
403
+ fs.mkdirSync(fixture.permissionSkillsRoot, { recursive: true });
404
+ return fixture;
405
+ }
406
+
407
+ function runRetiredSkillCleanup(cleanup, args) {
408
+ return spawnSync(process.execPath, [cleanup, ...args], {
409
+ cwd: root,
410
+ encoding: "utf8",
411
+ timeout: 10000,
412
+ });
413
+ }
414
+
415
+ function isSymlink(file) {
416
+ try {
417
+ return fs.lstatSync(file).isSymbolicLink();
418
+ } catch (error) {
419
+ if (error.code === "ENOENT") return false;
420
+ throw error;
421
+ }
422
+ }
423
+
424
+ function assertRetiredSkillCleanup(fixture) {
425
+ if (
426
+ fs.existsSync(fixture.known) ||
427
+ fs.existsSync(fixture.dryRunKnown) ||
428
+ fs.existsSync(fixture.creatorKnown)
429
+ ) {
430
+ fail("retired skill cleanup did not remove known files");
431
+ }
432
+ if (
433
+ !fs.existsSync(fixture.unknown) ||
434
+ !fs.existsSync(fixture.creatorUnknown)
435
+ ) {
436
+ fail("retired skill cleanup removed an unknown user file");
437
+ }
438
+ if (
439
+ !fs.existsSync(fixture.rootExternalKnown) ||
440
+ !isSymlink(fixture.rootSymlink)
441
+ ) {
442
+ fail("retired skill cleanup followed a symlinked skill directory");
443
+ }
444
+ if (
445
+ !fs.existsSync(fixture.nestedExternalKnown) ||
446
+ !isSymlink(fixture.nestedSymlink)
447
+ ) {
448
+ fail("retired skill cleanup followed a nested directory symlink");
449
+ }
450
+ const leafSymlinkPreserved =
451
+ !fixture.testLeafSymlink ||
452
+ (
453
+ fs.existsSync(fixture.leafExternalKnown) &&
454
+ isSymlink(fixture.leafSymlink)
455
+ );
456
+ if (!leafSymlinkPreserved) {
457
+ fail("retired skill cleanup removed a leaf symlink");
458
+ }
459
+ }
460
+
461
+ function checkPermissionFailure(cleanup, fixture) {
462
+ if (process.platform === "win32") return;
463
+
464
+ fs.chmodSync(fixture.permissionInstall, 0o000);
465
+ try {
466
+ const result = runRetiredSkillCleanup(cleanup, [
467
+ fixture.permissionInstall,
468
+ ]);
469
+ if (result.status === 0) {
470
+ fail("retired skill cleanup ignored an inaccessible install root");
471
+ }
472
+ } finally {
473
+ fs.chmodSync(fixture.permissionInstall, 0o700);
474
+ }
475
+ }
476
+
477
+ function checkRetiredSkillCleanup() {
478
+ const cleanup = rel("scripts/cleanup-retired-skills.js");
479
+ const manifest = rel("scripts/retired-skill-files.json");
480
+ if (!fs.existsSync(cleanup)) return fail("retired skill cleanup script is missing");
481
+ if (!fs.existsSync(manifest)) return fail("retired skill manifest is missing");
482
+
483
+ const fixture = createRetiredSkillFixture();
484
+ try {
485
+ const validation = runRetiredSkillCleanup(cleanup, ["--validate"]);
486
+ if (validation.status !== 0) {
487
+ fail(`retired skill manifest validation failed: ${validation.stderr}`);
488
+ }
489
+
490
+ const dryRun = runRetiredSkillCleanup(cleanup, [
491
+ fixture.tempRoot,
492
+ "--dry-run",
493
+ ]);
494
+ if (dryRun.status !== 0) {
495
+ fail(`retired skill cleanup dry-run failed: ${dryRun.stderr}`);
496
+ }
497
+ if (!dryRun.stdout.includes("Preserve unknown retired skill path")) {
498
+ fail("retired skill cleanup dry-run did not report preserved unknown files");
499
+ }
500
+ if (
501
+ !fs.existsSync(fixture.known) ||
502
+ !fs.existsSync(fixture.dryRunKnown) ||
503
+ !fs.existsSync(fixture.creatorKnown)
504
+ ) {
505
+ fail("retired skill cleanup dry-run modified files");
506
+ }
507
+
508
+ for (let attempt = 1; attempt <= 2; attempt += 1) {
509
+ const result = runRetiredSkillCleanup(cleanup, [fixture.tempRoot]);
510
+ if (result.status !== 0) {
511
+ fail(`retired skill cleanup attempt ${attempt} failed: ${result.stderr}`);
512
+ }
513
+ }
514
+ const rootSymlink = runRetiredSkillCleanup(cleanup, [
515
+ fixture.rootSymlinkInstall,
516
+ ]);
517
+ if (rootSymlink.status !== 0) {
518
+ fail(`retired skill root symlink cleanup failed: ${rootSymlink.stderr}`);
519
+ }
520
+ if (fixture.testLeafSymlink) {
521
+ const leafSymlink = runRetiredSkillCleanup(cleanup, [
522
+ fixture.leafSymlinkInstall,
523
+ ]);
524
+ if (leafSymlink.status !== 0) {
525
+ fail(`retired skill leaf symlink cleanup failed: ${leafSymlink.stderr}`);
526
+ }
527
+ }
528
+ checkPermissionFailure(cleanup, fixture);
529
+ assertRetiredSkillCleanup(fixture);
530
+ } finally {
531
+ fs.rmSync(fixture.tempRoot, { recursive: true, force: true });
532
+ }
533
+ }
534
+
535
+ function checkUpstreamCapabilityVerifier() {
536
+ const verifier = rel("scripts/verify-upstream-capability-map.js");
537
+ const baseline = rel("scripts/upstream-capability-baseline.json");
538
+ if (!fs.existsSync(verifier)) {
539
+ fail("upstream capability verifier is missing");
540
+ return;
541
+ }
542
+ if (!fs.existsSync(baseline)) {
543
+ fail("upstream capability baseline is missing");
544
+ return;
545
+ }
546
+ const result = spawnSync(process.execPath, [verifier], {
547
+ cwd: root,
548
+ encoding: "utf8",
549
+ timeout: 10000,
550
+ });
551
+ if (result.error) {
552
+ fail(`upstream capability verifier failed: ${result.error.message}`);
553
+ } else if (result.status !== 0) {
554
+ fail(`upstream capability verifier exited ${result.status}: ${result.stderr}`);
555
+ }
556
+ }
557
+
558
+ function checkGitDiffWhitespace() {
559
+ const isRepo = spawnSync("git", ["rev-parse", "--is-inside-work-tree"], {
560
+ cwd: root,
561
+ encoding: "utf8",
562
+ timeout: 30000,
563
+ });
564
+
565
+ if (isRepo.status !== 0) {
566
+ return;
567
+ }
568
+
569
+ const result = spawnSync("git", ["diff", "--check"], {
570
+ cwd: root,
571
+ encoding: "utf8",
572
+ timeout: 30000,
573
+ });
574
+
575
+ if (result.status !== 0) {
576
+ fail(`git diff --check failed:\n${result.stdout}${result.stderr}`);
577
+ } else if (result.stderr.trim()) {
578
+ warn(result.stderr.trim());
579
+ }
580
+ }
581
+
582
+ function runRuntimeChecks(context) {
583
+ bindContext(context);
584
+ checkScriptLayout();
585
+ checkContinuousLearningV21();
586
+ checkObserveV2();
587
+ checkInstalledPackageOnlyPaths();
588
+ checkRetiredSkillCleanup();
589
+ checkUpstreamCapabilityVerifier();
590
+ checkGitDiffWhitespace();
591
+ }
592
+
593
+ module.exports = { runRuntimeChecks };