@oscaner-skills/cdd-engine 1.0.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +9 -8
  2. package/README.zh-CN.md +9 -8
  3. package/package.json +15 -22
  4. package/src-next/__tests__/bin.test.ts +128 -0
  5. package/src-next/__tests__/smoke.integration.test.ts +202 -0
  6. package/src-next/__tests__/zero-dep.test.ts +134 -0
  7. package/src-next/bin.ts +61 -0
  8. package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +238 -0
  9. package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +153 -0
  10. package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +173 -0
  11. package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +89 -0
  12. package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +225 -0
  13. package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +155 -0
  14. package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +175 -0
  15. package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +85 -0
  16. package/src-next/contract/__tests__/declare.test.ts +242 -0
  17. package/src-next/contract/__tests__/doc.test.ts +358 -0
  18. package/src-next/contract/__tests__/judge.test.ts +873 -0
  19. package/src-next/contract/__tests__/lint.test.ts +314 -0
  20. package/src-next/contract/__tests__/project.test.ts +419 -0
  21. package/src-next/contract/__tests__/translate.test.ts +96 -0
  22. package/src-next/contract/declare.ts +983 -0
  23. package/src-next/contract/doc.ts +753 -0
  24. package/src-next/contract/invariants.ts +1268 -0
  25. package/src-next/contract/judge.ts +142 -0
  26. package/src-next/contract/lint.ts +275 -0
  27. package/src-next/contract/project.ts +596 -0
  28. package/src-next/contract/skill-anatomy.ts +273 -0
  29. package/src-next/contract/translate.ts +113 -0
  30. package/src-next/face/__tests__/board-view.test.ts +948 -0
  31. package/src-next/face/__tests__/capsule.test.ts +276 -0
  32. package/src-next/face/__tests__/channel-closure.guard.test.ts +102 -0
  33. package/src-next/face/__tests__/cli.test.ts +4643 -0
  34. package/src-next/face/__tests__/face.test.ts +289 -0
  35. package/src-next/face/__tests__/graph-view.test.ts +61 -0
  36. package/src-next/face/__tests__/host.test.ts +24 -0
  37. package/src-next/face/__tests__/negation.ts +6 -0
  38. package/src-next/face/__tests__/projection.test.ts +301 -0
  39. package/src-next/face/__tests__/sync-runner.test.ts +70 -0
  40. package/src-next/face/__tests__/words.guard.test.ts +93 -0
  41. package/src-next/face/artifacts.ts +195 -0
  42. package/src-next/face/board-view.ts +662 -0
  43. package/src-next/face/capsule.ts +149 -0
  44. package/src-next/face/cli.ts +819 -0
  45. package/src-next/face/declare.ts +326 -0
  46. package/src-next/face/gate.ts +170 -0
  47. package/src-next/face/graph-view.ts +74 -0
  48. package/src-next/face/host.ts +326 -0
  49. package/src-next/face/lifecycle.ts +700 -0
  50. package/src-next/face/projection.ts +282 -0
  51. package/src-next/face/route-render.ts +160 -0
  52. package/src-next/face/words.ts +296 -0
  53. package/src-next/infra/__tests__/infra.test.ts +287 -0
  54. package/src-next/infra/config.ts +42 -0
  55. package/src-next/infra/git.ts +39 -0
  56. package/src-next/infra/process.ts +34 -0
  57. package/src-next/infra/runtime.ts +185 -0
  58. package/src-next/infra/workspace.ts +232 -0
  59. package/src-next/render/__tests__/render.test.ts +499 -0
  60. package/src-next/render/__tests__/skeleton.test.ts +466 -0
  61. package/src-next/render/brief.ts +121 -0
  62. package/src-next/render/issue-body.ts +159 -0
  63. package/src-next/render/skeleton.ts +437 -0
  64. package/src-next/render/templates.ts +650 -0
  65. package/src-next/session/__tests__/graph.test.ts +270 -0
  66. package/src-next/session/__tests__/handoff-plane.guard.test.ts +48 -0
  67. package/src-next/session/__tests__/handoff-schema.test.ts +310 -0
  68. package/src-next/session/__tests__/ledger.test.ts +744 -0
  69. package/src-next/session/__tests__/next.test.ts +368 -0
  70. package/src-next/session/__tests__/preflight.test.ts +491 -0
  71. package/src-next/session/__tests__/run.test.ts +1014 -0
  72. package/src-next/session/__tests__/wave-line-phase.guard.test.ts +49 -0
  73. package/src-next/session/__tests__/wave.test.ts +469 -0
  74. package/src-next/session/faces.ts +110 -0
  75. package/src-next/session/graph.ts +411 -0
  76. package/src-next/session/handoff-schema.ts +373 -0
  77. package/src-next/session/ledger.ts +1004 -0
  78. package/src-next/session/next.ts +192 -0
  79. package/src-next/session/preflight.ts +240 -0
  80. package/src-next/session/run.ts +606 -0
  81. package/src-next/session/state.ts +30 -0
  82. package/src-next/session/wave.ts +139 -0
  83. package/templates/report/issue-body.json +18 -20
  84. package/dist/chunks/branch.mjs +0 -480
  85. package/dist/chunks/docs.mjs +0 -253
  86. package/dist/chunks/task.mjs +0 -913
  87. package/dist/cli.mjs +0 -5457
  88. package/dist/documents/schema/add-phase-protocol.json +0 -126
  89. package/dist/documents/schema/overall.json +0 -361
  90. package/dist/documents/schema/phase-spec.json +0 -145
  91. package/dist/documents/schema/plan.json +0 -191
  92. package/dist/documents/schema/skill-anatomy.json +0 -233
  93. package/dist/resources/harness-registry.json +0 -49
  94. package/dist/shared/cdd-engine.liioziig.mjs +0 -184
  95. package/templates/engine-config.json +0 -302
  96. package/templates/schema/cache-profile-schema.json +0 -23
  97. package/templates/schema/docs-handoff-schema.json +0 -129
  98. package/templates/schema/task-handoff-schema.json +0 -332
  99. package/templates/template-contract.json +0 -231
@@ -0,0 +1,276 @@
1
+ // packages/cdd-engine/src-next/face/__tests__/capsule.test.ts
2
+ // P4.1 T7 — find #7 closeout (design §5.6): the complete-executable next literal's
3
+ // required-flag coverage. One literal per verb × type must secondary-parse with zero
4
+ // errors (T4) AND carry every runtime-required flag of its type — the design §5.6
5
+ // "parse green ⇒ full required-flag coverage" rule. The regression the suite pins: #routeText's review→wave
6
+ // branch rendered `review --type wave --tasks <n>` WITHOUT the runtime-required
7
+ // `--plan` (the implement/next-wave and fix→wave branches both carried it — a
8
+ // composition-face inconsistency), so the literal parsed green yet BLOCKED the
9
+ // dispatch at run time (`missing required --plan <path>`), as first observed in the
10
+ // W3 task-5 review dispatch.
11
+ //
12
+ // Module-level: the literals come from the Capsule face over the ROUTE + the frame's
13
+ // own facts (type + id + plan — the RouteTarget), then re-parse through the CLI's
14
+ // own parse gate (the same channel the dispatch reads).
15
+
16
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
17
+ import { tmpdir } from "node:os";
18
+ import path from "node:path";
19
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
20
+ import type { RouteTarget } from "../../session/faces.ts";
21
+ import type { Route } from "../../session/next.ts";
22
+ import { FIX_READBACK_SUFFIX, PIPELINE_NEXT } from "../../session/next.ts";
23
+ import { Capsule } from "../capsule.ts";
24
+ import { CommandTreeBuilder } from "../projection.ts";
25
+ import { Words } from "../words.ts";
26
+
27
+ /** The commander parse gate — the same channel the CLI dispatch reads (P3 T3: the
28
+ * composition root parses through the projection's program; `Cli#parse()` retired). */
29
+ const parseGate = new CommandTreeBuilder().program;
30
+
31
+ /** The next-text of a capsule emit (the second line, the station prefix stripped). */
32
+ const literalOf = (route: Route, target?: RouteTarget): string => {
33
+ const lines = new Capsule(new Words()).emit("APPROVED", "0", "/h.json", route, target);
34
+ return lines[1]!.slice("next: ".length);
35
+ };
36
+
37
+ /** The parseable argv of a literal — the fix readback suffix is prompt prose, never
38
+ * argv (the parse gate strips the declared suffix before feeding). */
39
+ const argvOf = (literal: string): string[] => {
40
+ return literal
41
+ .replace(new RegExp(`\\s*\\(${FIX_READBACK_SUFFIX.slice(1, -1)}\\)$`), "")
42
+ .split(/\s+/);
43
+ };
44
+
45
+ /** The frame-fact targets of the four types (the dispatch frame's own identity). */
46
+ const wave = { type: "wave", id: "1,2", plan: "docs/kairos/plans/p3.md" } as const;
47
+ const spec = { type: "spec", id: "docs/kairos/specs/p3-design.md" } as const;
48
+ const planT = { type: "plan", id: "docs/kairos/plans/p3.md" } as const;
49
+ // find #9 — the branch target carries the workspace --plan · the id is the branch
50
+ // line's stable key `"branch"` (the range shas retired engine-wide · spec §6.6)
51
+ const branch = {
52
+ type: "branch",
53
+ id: "branch",
54
+ plan: "docs/kairos/plans/p3.md",
55
+ } as const;
56
+
57
+ /** One verb × type row of the coverage table — the route + the frame facts + the
58
+ * runtime-required flags of the type (the flags the CLI run would demand: the
59
+ * declared required keys + the type's scene rules — wave demands --plan, spec/plan
60
+ * their doc flags, branch the workspace --plan/--findings face). */
61
+ interface CoverageRow {
62
+ label: string;
63
+ route: Route;
64
+ target?: RouteTarget;
65
+ required: readonly string[];
66
+ }
67
+
68
+ const COVERAGE: readonly CoverageRow[] = [
69
+ {
70
+ label: "implement",
71
+ route: { kind: "next-wave", tasks: "1,2" },
72
+ target: wave,
73
+ required: ["--tasks", "--plan"],
74
+ },
75
+ {
76
+ label: "review wave",
77
+ route: { kind: "review" },
78
+ target: wave,
79
+ required: ["--type", "--tasks", "--plan"],
80
+ },
81
+ {
82
+ label: "review spec",
83
+ route: { kind: "review" },
84
+ target: spec,
85
+ required: ["--type", "--spec"],
86
+ },
87
+ {
88
+ label: "review plan",
89
+ route: { kind: "review" },
90
+ target: planT,
91
+ required: ["--type", "--plan"],
92
+ },
93
+ {
94
+ label: "review branch",
95
+ route: { kind: "review" },
96
+ target: branch,
97
+ required: ["--type", "--plan"],
98
+ },
99
+ {
100
+ label: "fix wave",
101
+ route: { kind: "fix", findings: "tasks-1-review-1.json" },
102
+ target: wave,
103
+ required: ["--type", "--tasks", "--plan", "--findings"],
104
+ },
105
+ {
106
+ label: "fix spec",
107
+ route: { kind: "fix", findings: "s1-review-1.json" },
108
+ target: spec,
109
+ required: ["--type", "--spec", "--findings"],
110
+ },
111
+ {
112
+ label: "fix plan",
113
+ route: { kind: "fix", findings: "p1-review-1.json" },
114
+ target: planT,
115
+ required: ["--type", "--plan", "--findings"],
116
+ },
117
+ {
118
+ // find #8 F1b — the branch fix carries the workspace-identity `--plan` plus the
119
+ // source review handoff `--findings` (the review judges the live tree — no
120
+ // re-declared base/head on the CLI)
121
+ label: "fix branch",
122
+ route: { kind: "fix", findings: "br1-review-1.json" },
123
+ target: branch,
124
+ required: ["--type", "--findings", "--plan"],
125
+ },
126
+ ];
127
+
128
+ describe("P4.1 T7 (find #7) — the next literal's required-flag coverage (parse green ⇒ the type's required flags fully covered)", () => {
129
+ it("review→wave renders `--plan {path}` — the find #7 regression (the missing --plan previously parsed green yet refused the dispatch at runtime)", () => {
130
+ const literal = literalOf({ kind: "review" }, wave);
131
+ expect(literal).toBe("review --type wave --tasks 1,2 --plan docs/kairos/plans/p3.md");
132
+ expect(() => parseGate.parse(argvOf(literal), { from: "user" })).not.toThrow();
133
+ // the ready-to-dispatch wave review must carry its runtime-required --plan — the
134
+ // same argv domain as the W3 task-5 dispatch that exposed the gap
135
+ expect(argvOf(literal)).toEqual([
136
+ "review",
137
+ "--type",
138
+ "wave",
139
+ "--tasks",
140
+ "1,2",
141
+ "--plan",
142
+ "docs/kairos/plans/p3.md",
143
+ ]);
144
+ });
145
+
146
+ it("coverage table — every verb × type literal parses green AND carries its type's runtime-required flags", () => {
147
+ for (const row of COVERAGE) {
148
+ const literal = literalOf(row.route, row.target);
149
+ // parse green (T4) …
150
+ expect(() => parseGate.parse(argvOf(literal), { from: "user" })).not.toThrow();
151
+ // … and the type's required flags are all present in the same arg domain (find #7)
152
+ for (const flag of row.required) {
153
+ expect(literal, `${row.label} must carry ${flag}`).toContain(flag);
154
+ }
155
+ }
156
+ });
157
+
158
+ it("review four-type literals carry zero sha — the live-tree review, no commit range", () => {
159
+ // §2.6 — every review literal is the live-tree judgment: the wave face carries
160
+ // `--tasks` + `--plan`, the branch/spec/plan faces their single doc arg; none
161
+ // carries a `--base`/`--head` range or a sha token.
162
+ const waveLiteral = literalOf({ kind: "review" }, wave);
163
+ const branchLiteral = literalOf({ kind: "review" }, branch);
164
+ const specLiteral = literalOf({ kind: "review" }, spec);
165
+ const planLiteral = literalOf({ kind: "review" }, planT);
166
+ expect(waveLiteral).toBe("review --type wave --tasks 1,2 --plan docs/kairos/plans/p3.md");
167
+ expect(branchLiteral).toBe("review --type branch --plan docs/kairos/plans/p3.md");
168
+ expect(specLiteral).toBe("review --type spec --spec docs/kairos/specs/p3-design.md");
169
+ expect(planLiteral).toBe("review --type plan --plan docs/kairos/plans/p3.md");
170
+ for (const literal of [waveLiteral, branchLiteral, specLiteral, planLiteral]) {
171
+ expect(literal).not.toContain("--base");
172
+ expect(literal).not.toContain("--head");
173
+ expect(literal).not.toMatch(/\b[0-9a-f]{8}\.\./);
174
+ }
175
+ });
176
+
177
+ it("the fix route keeps the FIX_READBACK_SUFFIX verbatim", () => {
178
+ const literal = literalOf({ kind: "fix", findings: "tasks-1-review-1.json" }, wave);
179
+ expect(literal).toContain(FIX_READBACK_SUFFIX);
180
+ });
181
+ });
182
+
183
+ // ---------------------------------------------------------------------------
184
+ // T3 — the unified next face: the `done` route's PIPELINE_NEXT doc-class lookup
185
+ // ---------------------------------------------------------------------------
186
+
187
+ /** The hermetic declaration repo — the spec docs the doc-class discrimination reads
188
+ * (spec §12 · D34: the declared `- **Doc type**:` line, never the filename). */
189
+ describe("Capsule — the `done` route's PIPELINE_NEXT doc-class lookup (D33 · the unified next face)", () => {
190
+ let repo: string;
191
+
192
+ beforeEach(() => {
193
+ repo = mkdtempSync(path.join(tmpdir(), "capsule-done-"));
194
+ });
195
+
196
+ afterEach(() => {
197
+ rmSync(repo, { recursive: true, force: true });
198
+ });
199
+
200
+ /** A spec doc on disk declaring its doc type (the header declaration line). */
201
+ const declareSpec = (name: string, docType: string | null): RouteTarget => {
202
+ mkdirSync(path.dirname(path.join(repo, name)), { recursive: true });
203
+ const header =
204
+ docType === null
205
+ ? ["# The doc", "", "- **Version**: v1.0", "- **Status**: Draft", ""]
206
+ : [
207
+ "# The doc",
208
+ "",
209
+ "- **Version**: v1.0",
210
+ "- **Status**: Draft",
211
+ `- **Doc type**: ${docType}`,
212
+ "",
213
+ ];
214
+ writeFileSync(path.join(repo, name), header.join("\n"), "utf8");
215
+ return { type: "spec", id: name } as const;
216
+ };
217
+
218
+ /** The done-text of a capsule emit for a host-injected capsule over the repo. */
219
+ const doneOf = (target?: RouteTarget, host = ""): string => {
220
+ const lines = new Capsule(new Words(), {}, host, repo).emit(
221
+ "APPROVED",
222
+ "0",
223
+ "/h.json",
224
+ { kind: "done" },
225
+ target,
226
+ );
227
+ return lines[1]!.slice("next: ".length);
228
+ };
229
+
230
+ it("PIPELINE_NEXT carries exactly the five pipeline keys", () => {
231
+ expect(Object.keys(PIPELINE_NEXT).sort()).toEqual(
232
+ ["branch", "overall-spec", "phase-spec", "plan", "wave"].sort(),
233
+ );
234
+ });
235
+
236
+ it("no target renders the bare terminal word (the byte-pinned fallback)", () => {
237
+ expect(doneOf()).toBe("done");
238
+ });
239
+
240
+ it("a phase-spec-declared target routes the cdd-plan ref per host (claude / pi / empty)", () => {
241
+ const phaseSpec = declareSpec("docs/kairos/specs/prog-p8-design.md", "phase-spec");
242
+ expect(doneOf(phaseSpec, "claude")).toBe("/kairos:cdd-plan");
243
+ expect(doneOf(phaseSpec, "pi")).toBe("/skill:cdd-plan");
244
+ expect(doneOf(phaseSpec)).toBe("/kairos:cdd-plan");
245
+ });
246
+
247
+ it("an overall-spec-declared target renders the bare terminal word (the pipeline terminal)", () => {
248
+ const overall = declareSpec("docs/kairos/specs/prog-overall.md", "overall-spec");
249
+ expect(doneOf(overall)).toBe("done");
250
+ });
251
+
252
+ it("a spec target declaring no Doc type renders the BLOCKED face — zero filename-suffix fallback", () => {
253
+ const undeclared = declareSpec("docs/kairos/specs/prog-p8-design.md", null);
254
+ expect(doneOf(undeclared)).toBe(
255
+ "CDD_BLOCKED: the doc declares no `- **Doc type**:` line — add `- **Doc type**: <overall-spec|phase-spec|single-spec|plan>` to the doc's header (spec §12) and re-run",
256
+ );
257
+ });
258
+
259
+ it("a single-spec-declared target renders the bare terminal word — no pipeline seam carries it", () => {
260
+ const single = declareSpec("docs/kairos/specs/prog-single-spec.md", "single-spec");
261
+ expect(doneOf(single)).toBe("done");
262
+ });
263
+
264
+ it("a plan target routes the cdd-dev ref; a branch target the cdd-close ref", () => {
265
+ expect(doneOf({ type: "plan", id: "docs/kairos/plans/prog-p8.md" })).toBe("/kairos:cdd-dev");
266
+ expect(doneOf({ type: "branch", id: "branch", plan: "docs/kairos/plans/prog-p8.md" })).toBe(
267
+ "/kairos:cdd-close",
268
+ );
269
+ });
270
+
271
+ it("a wave target renders the wiring literal with the plan slot filled", () => {
272
+ expect(doneOf({ type: "wave", id: "1,2", plan: "docs/kairos/plans/prog-p8.md" })).toBe(
273
+ "review --type branch --plan docs/kairos/plans/prog-p8.md",
274
+ );
275
+ });
276
+ });
@@ -0,0 +1,102 @@
1
+ // packages/cdd-engine/src-next/face/__tests__/channel-closure.guard.test.ts
2
+ // P5 — the engine-side channel-closure pin, colocated after the D17 six-premise
3
+ // ownership-migration (the root guard's checkChannels assertion face re-homed into the engine
4
+ // test plane — every check lives in its owning package's suite, zero root
5
+ // validation implementation). The three closure legs read the engine's OWN typed
6
+ // single sources — `face/declare.ts` (CLI_COMMANDS + ARGV_CHANNEL) and
7
+ // `face/host.ts` (HOSTS detect rows · DISPATCH · REFS) — the same surfaces the
8
+ // runtime consumes, never a parallel allowlist:
9
+ //
10
+ // 1. the CLI channel closure — every command-declared key resolves in the
11
+ // declare argv channel, and every non-program channel key is declared by a
12
+ // command (the single-surface closure);
13
+ // 2. the host-marker closure — the detect env keys ∪ PATH match the pinned
14
+ // four, derived from the harness detect rows as the live single source;
15
+ // 3. the dispatch/refs derivation — every dispatch-slot ref is registered and
16
+ // every per-harness slash form derives (`pi` /skill:<bare>, claude/cursor
17
+ // /<ref>).
18
+ //
19
+ // Zero module-level bare functions — the assertions read the typed exports with
20
+ // `const` helpers only (the P5 zero-`function`-declaration discipline).
21
+
22
+ import { describe, expect, it } from "vitest";
23
+
24
+ import { ARGV_CHANNEL, CLI_COMMANDS } from "../declare.ts";
25
+ import { DISPATCH, HOSTS, REFS } from "../host.ts";
26
+
27
+ describe("the CLI channel closure — command keys × the declare argv channel (the single-surface closure)", () => {
28
+ it("every command/leaf declared key resolves in ARGV_CHANNEL — and every non-program channel key is declared by a command", () => {
29
+ // The declared aggregate — every key any command/leaf declares (the guard's
30
+ // collect face: keys only — positionals are arguments, never channel flags).
31
+ const declaredKeys = new Set<string>();
32
+ const collect = (spec: { keys: readonly { key: string }[] }): void => {
33
+ for (const declared of spec.keys) declaredKeys.add(declared.key);
34
+ };
35
+ for (const command of CLI_COMMANDS) {
36
+ collect(command);
37
+ for (const leaf of command.leaves ?? []) collect(leaf);
38
+ }
39
+ // Forward leg — a declared key absent from the channel is a broken closure.
40
+ const missing: string[] = [];
41
+ for (const key of declaredKeys) {
42
+ if (!(key in ARGV_CHANNEL)) missing.push(key);
43
+ }
44
+ expect(missing).toEqual([]);
45
+ // Reverse leg — a channel key declared by no command and not program-scoped
46
+ // (dry-run/help) is a broken closure.
47
+ const orphan: string[] = [];
48
+ for (const [key, row] of Object.entries(ARGV_CHANNEL)) {
49
+ if (declaredKeys.has(key) || ("scope" in row && row.scope === "program")) continue;
50
+ orphan.push(key);
51
+ }
52
+ expect(orphan).toEqual([]);
53
+ });
54
+
55
+ it("the D19 schema merge keeps the closure — the `output` key is the get leaf's declared channel row", () => {
56
+ // The merged single leaf declares `--output` (json|skeleton): the closure
57
+ // leg reads the leaf's declared keys, so the new row is covered exactly like
58
+ // every other declared key (a drag of the D19 deliberate change).
59
+ const schema = CLI_COMMANDS.find((command) => command.name === "schema")!;
60
+ const get = schema.leaves!.find((leaf) => leaf.name === "get")!;
61
+ expect(get.keys.map((declared) => declared.key)).toContain("output");
62
+ expect(ARGV_CHANNEL.output.values).toEqual(["json", "skeleton"]);
63
+ });
64
+ });
65
+
66
+ describe("the host-marker closure — the detect env keys ∪ PATH (single-sourced at the harness detect rows)", () => {
67
+ it("every HOSTS detect env key + PATH equals the pinned four (the deliberate half-update oracle)", () => {
68
+ const markerKeys = Object.values(HOSTS).map((row) => row.detect.env);
69
+ const expectedClosure = [...markerKeys, "PATH"].sort();
70
+ const pinned = ["AI_AGENT", "CLAUDE_CODE_SESSION_ID", "CURSOR_TRACE_ID", "PATH"].sort();
71
+ expect(expectedClosure).toEqual(pinned);
72
+ });
73
+ });
74
+
75
+ describe("the dispatch/refs derivation — every dispatch-slot ref registered + every per-harness form derived", () => {
76
+ it("the dispatch table's ref-shaped slots derive their per-harness slash forms", () => {
77
+ // The ref-shaped slots (`pkg:skill`, lowercase) are the table entries; a
78
+ // non-ref literal (the URC prose — spaces/uppercase) has no per-harness form.
79
+ const refKeys: string[] = [];
80
+ const pushRef = (value: string | { ref: string }): void => {
81
+ const ref = typeof value === "string" ? value : value.ref;
82
+ if (/^[a-z][a-z-]*:[a-z][a-z-]*$/.test(ref)) refKeys.push(ref);
83
+ };
84
+ pushRef(DISPATCH.implement);
85
+ for (const slot of Object.values(DISPATCH.review)) pushRef(slot);
86
+ // The shape is the closed pair — implement + the review rows (never vacuous);
87
+ // both review slots name the same ref key — deduped before the derivation.
88
+ expect([...new Set(refKeys)].sort()).toEqual([
89
+ "mattpocock-skills:code-review",
90
+ "mattpocock-skills:implement",
91
+ ]);
92
+ for (const ref of refKeys) {
93
+ const form = REFS[ref as keyof typeof REFS];
94
+ expect(form, `dispatch slot names the registered ref key "${ref}"`).toBeDefined();
95
+ if (form === undefined) continue;
96
+ for (const id of ["claude", "cursor", "pi"] as const) {
97
+ const expected = id === "pi" ? `/skill:${ref.split(":")[1]}` : `/${ref}`;
98
+ expect(form[id], `ref "${ref}" per-harness form for ${id}`).toBe(expected);
99
+ }
100
+ }
101
+ });
102
+ });