@oscaner-skills/cdd-engine 1.0.0 → 3.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 (120) hide show
  1. package/README.md +11 -10
  2. package/README.zh-CN.md +11 -10
  3. package/package.json +16 -22
  4. package/src-next/__tests__/bin.test.ts +128 -0
  5. package/src-next/__tests__/dead-decl.guard.test.ts +39 -0
  6. package/src-next/__tests__/floor.guard.test.ts +69 -0
  7. package/src-next/__tests__/issue-body.guard.test.ts +66 -0
  8. package/src-next/__tests__/phase-suffix.guard.test.ts +72 -0
  9. package/src-next/__tests__/smoke.integration.test.ts +185 -0
  10. package/src-next/__tests__/support/strip-comments.ts +99 -0
  11. package/src-next/__tests__/zero-dep.test.ts +94 -0
  12. package/src-next/bin.ts +61 -0
  13. package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +256 -0
  14. package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +165 -0
  15. package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +190 -0
  16. package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +106 -0
  17. package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +240 -0
  18. package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +165 -0
  19. package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +190 -0
  20. package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +100 -0
  21. package/src-next/contract/__tests__/declare.test.ts +481 -0
  22. package/src-next/contract/__tests__/doc.test.ts +527 -0
  23. package/src-next/contract/__tests__/dockey.guard.test.ts +58 -0
  24. package/src-next/contract/__tests__/edge-conditions.guard.test.ts +81 -0
  25. package/src-next/contract/__tests__/frontmatter.test.ts +164 -0
  26. package/src-next/contract/__tests__/judge.test.ts +1111 -0
  27. package/src-next/contract/__tests__/lint.test.ts +324 -0
  28. package/src-next/contract/__tests__/project.test.ts +460 -0
  29. package/src-next/contract/__tests__/structure-pin.test.ts +186 -0
  30. package/src-next/contract/__tests__/translate.test.ts +96 -0
  31. package/src-next/contract/declare.ts +1071 -0
  32. package/src-next/contract/doc.ts +816 -0
  33. package/src-next/contract/frontmatter.ts +233 -0
  34. package/src-next/contract/home-extractors.ts +397 -0
  35. package/src-next/contract/invariants.ts +1413 -0
  36. package/src-next/contract/judge.ts +151 -0
  37. package/src-next/contract/lint.ts +239 -0
  38. package/src-next/contract/project.ts +656 -0
  39. package/src-next/contract/skill-anatomy.ts +301 -0
  40. package/src-next/contract/translate.ts +113 -0
  41. package/src-next/face/__tests__/board-view.test.ts +1151 -0
  42. package/src-next/face/__tests__/capsule.test.ts +300 -0
  43. package/src-next/face/__tests__/channel-closure.guard.test.ts +129 -0
  44. package/src-next/face/__tests__/cli.test.ts +4897 -0
  45. package/src-next/face/__tests__/face.test.ts +289 -0
  46. package/src-next/face/__tests__/graph-view.test.ts +61 -0
  47. package/src-next/face/__tests__/host.test.ts +24 -0
  48. package/src-next/face/__tests__/install-rows.guard.test.ts +58 -0
  49. package/src-next/face/__tests__/negation.ts +6 -0
  50. package/src-next/face/__tests__/preview.test.ts +374 -0
  51. package/src-next/face/__tests__/projection.test.ts +303 -0
  52. package/src-next/face/__tests__/repo-root.guard.test.ts +120 -0
  53. package/src-next/face/__tests__/termination.test.ts +650 -0
  54. package/src-next/face/__tests__/words.guard.test.ts +93 -0
  55. package/src-next/face/artifacts.ts +248 -0
  56. package/src-next/face/board-view.ts +652 -0
  57. package/src-next/face/capsule.ts +163 -0
  58. package/src-next/face/cli.ts +1028 -0
  59. package/src-next/face/declare.ts +323 -0
  60. package/src-next/face/gate.ts +171 -0
  61. package/src-next/face/graph-view.ts +74 -0
  62. package/src-next/face/host.ts +302 -0
  63. package/src-next/face/lifecycle.ts +725 -0
  64. package/src-next/face/preview.ts +151 -0
  65. package/src-next/face/projection.ts +285 -0
  66. package/src-next/face/route-render.ts +185 -0
  67. package/src-next/face/termination.ts +573 -0
  68. package/src-next/face/words.ts +314 -0
  69. package/src-next/infra/__tests__/infra.test.ts +333 -0
  70. package/src-next/infra/__tests__/root.test.ts +56 -0
  71. package/src-next/infra/config.ts +42 -0
  72. package/src-next/infra/doc-roots.ts +29 -0
  73. package/src-next/infra/git.ts +39 -0
  74. package/src-next/infra/process.ts +34 -0
  75. package/src-next/infra/root.ts +73 -0
  76. package/src-next/infra/runtime.ts +132 -0
  77. package/src-next/infra/workspace.ts +322 -0
  78. package/src-next/render/__tests__/render.test.ts +550 -0
  79. package/src-next/render/__tests__/skeleton.test.ts +684 -0
  80. package/src-next/render/brief.ts +121 -0
  81. package/src-next/render/issue-body.ts +162 -0
  82. package/src-next/render/skeleton.ts +502 -0
  83. package/src-next/render/templates.ts +645 -0
  84. package/src-next/session/__tests__/graph.test.ts +277 -0
  85. package/src-next/session/__tests__/handoff-plane.guard.test.ts +48 -0
  86. package/src-next/session/__tests__/handoff-schema.test.ts +310 -0
  87. package/src-next/session/__tests__/ledger.test.ts +745 -0
  88. package/src-next/session/__tests__/next.test.ts +460 -0
  89. package/src-next/session/__tests__/preflight.test.ts +545 -0
  90. package/src-next/session/__tests__/round-naming.test.ts +142 -0
  91. package/src-next/session/__tests__/run.test.ts +1026 -0
  92. package/src-next/session/__tests__/wave-line-phase.guard.test.ts +49 -0
  93. package/src-next/session/__tests__/wave.test.ts +476 -0
  94. package/src-next/session/faces.ts +110 -0
  95. package/src-next/session/graph.ts +411 -0
  96. package/src-next/session/handoff-schema.ts +373 -0
  97. package/src-next/session/ledger.ts +1076 -0
  98. package/src-next/session/next.ts +293 -0
  99. package/src-next/session/preflight.ts +271 -0
  100. package/src-next/session/round-naming.ts +84 -0
  101. package/src-next/session/run.ts +610 -0
  102. package/src-next/session/state.ts +30 -0
  103. package/src-next/session/wave.ts +139 -0
  104. package/templates/report/issue-body.json +17 -65
  105. package/dist/chunks/branch.mjs +0 -480
  106. package/dist/chunks/docs.mjs +0 -253
  107. package/dist/chunks/task.mjs +0 -913
  108. package/dist/cli.mjs +0 -5457
  109. package/dist/documents/schema/add-phase-protocol.json +0 -126
  110. package/dist/documents/schema/overall.json +0 -361
  111. package/dist/documents/schema/phase-spec.json +0 -145
  112. package/dist/documents/schema/plan.json +0 -191
  113. package/dist/documents/schema/skill-anatomy.json +0 -233
  114. package/dist/resources/harness-registry.json +0 -49
  115. package/dist/shared/cdd-engine.liioziig.mjs +0 -184
  116. package/templates/engine-config.json +0 -302
  117. package/templates/schema/cache-profile-schema.json +0 -23
  118. package/templates/schema/docs-handoff-schema.json +0 -129
  119. package/templates/schema/task-handoff-schema.json +0 -332
  120. package/templates/template-contract.json +0 -231
@@ -0,0 +1,300 @@
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 { RepoRoot } from "../../infra/root.ts";
21
+ import type { RouteTarget } from "../../session/faces.ts";
22
+ import type { Route } from "../../session/next.ts";
23
+ import { FIX_READBACK_SUFFIX, PIPELINE_NEXT } from "../../session/next.ts";
24
+ import { Capsule } from "../capsule.ts";
25
+ import { CommandTreeBuilder } from "../projection.ts";
26
+ import { Words } from "../words.ts";
27
+
28
+ /** The commander parse gate — the same channel the CLI dispatch reads (P3 T3: the
29
+ * composition root parses through the projection's program; `Cli#parse()` retired). */
30
+ const parseGate = new CommandTreeBuilder().program;
31
+
32
+ /** The next-text of a capsule emit (the second line, the station prefix stripped). */
33
+ const literalOf = (route: Route, target?: RouteTarget): string => {
34
+ const lines = new Capsule(new Words()).emit("APPROVED", "0", "/h.json", route, target);
35
+ return lines[1]!.slice("next: ".length);
36
+ };
37
+
38
+ /** The parseable argv of a literal — the fix readback suffix is prompt prose, never
39
+ * argv (the parse gate strips the declared suffix before feeding). */
40
+ const argvOf = (literal: string): string[] => {
41
+ return literal
42
+ .replace(new RegExp(`\\s*\\(${FIX_READBACK_SUFFIX.slice(1, -1)}\\)$`), "")
43
+ .split(/\s+/);
44
+ };
45
+
46
+ /** The frame-fact targets of the four types (the dispatch frame's own identity). */
47
+ const wave = { type: "wave", id: "1,2", plan: "docs/kairos/plans/p3.md" } as const;
48
+ const spec = { type: "spec", id: "docs/kairos/specs/p3-design.md" } as const;
49
+ const planT = { type: "plan", id: "docs/kairos/plans/p3.md" } as const;
50
+ // find #9 — the branch target carries the workspace --plan · the id is the branch
51
+ // line's stable key `"branch"` (the range shas retired engine-wide · spec §6.6)
52
+ const branch = {
53
+ type: "branch",
54
+ id: "branch",
55
+ plan: "docs/kairos/plans/p3.md",
56
+ } as const;
57
+
58
+ /** One verb × type row of the coverage table — the route + the frame facts + the
59
+ * runtime-required flags of the type (the flags the CLI run would demand: the
60
+ * declared required keys + the type's scene rules — wave demands --plan, spec/plan
61
+ * their doc flags, branch the workspace --plan/--reviews face). */
62
+ interface CoverageRow {
63
+ label: string;
64
+ route: Route;
65
+ target?: RouteTarget;
66
+ required: readonly string[];
67
+ }
68
+
69
+ const COVERAGE: readonly CoverageRow[] = [
70
+ {
71
+ label: "implement",
72
+ route: { kind: "next-wave", tasks: "1,2" },
73
+ target: wave,
74
+ required: ["--tasks", "--plan"],
75
+ },
76
+ {
77
+ label: "review wave",
78
+ route: { kind: "review" },
79
+ target: wave,
80
+ required: ["--type", "--tasks", "--plan"],
81
+ },
82
+ {
83
+ label: "review spec",
84
+ route: { kind: "review" },
85
+ target: spec,
86
+ required: ["--type", "--spec"],
87
+ },
88
+ {
89
+ label: "review plan",
90
+ route: { kind: "review" },
91
+ target: planT,
92
+ required: ["--type", "--plan"],
93
+ },
94
+ {
95
+ label: "review branch",
96
+ route: { kind: "review" },
97
+ target: branch,
98
+ required: ["--type", "--plan"],
99
+ },
100
+ {
101
+ label: "fix wave",
102
+ route: { kind: "fix", reviews: "tasks-1-review-1.json" },
103
+ target: wave,
104
+ required: ["--type", "--tasks", "--plan", "--reviews"],
105
+ },
106
+ {
107
+ label: "fix spec",
108
+ route: { kind: "fix", reviews: "s1-review-1.json" },
109
+ target: spec,
110
+ required: ["--type", "--spec", "--reviews"],
111
+ },
112
+ {
113
+ label: "fix plan",
114
+ route: { kind: "fix", reviews: "p1-review-1.json" },
115
+ target: planT,
116
+ required: ["--type", "--plan", "--reviews"],
117
+ },
118
+ {
119
+ // find #8 F1b — the branch fix carries the workspace-identity `--plan` plus the
120
+ // source review handoff `--reviews` (the review judges the live tree — no
121
+ // re-declared base/head on the CLI)
122
+ label: "fix branch",
123
+ route: { kind: "fix", reviews: "br1-review-1.json" },
124
+ target: branch,
125
+ required: ["--type", "--reviews", "--plan"],
126
+ },
127
+ ];
128
+
129
+ describe("P4.1 T7 (find #7) — the next literal's required-flag coverage (parse green ⇒ the type's required flags fully covered)", () => {
130
+ it("review→wave renders `--plan {path}` — the find #7 regression (the missing --plan previously parsed green yet refused the dispatch at runtime)", () => {
131
+ const literal = literalOf({ kind: "review" }, wave);
132
+ expect(literal).toBe("review --type wave --tasks 1,2 --plan docs/kairos/plans/p3.md");
133
+ expect(() => parseGate.parse(argvOf(literal), { from: "user" })).not.toThrow();
134
+ // the ready-to-dispatch wave review must carry its runtime-required --plan — the
135
+ // same argv domain as the W3 task-5 dispatch that exposed the gap
136
+ expect(argvOf(literal)).toEqual([
137
+ "review",
138
+ "--type",
139
+ "wave",
140
+ "--tasks",
141
+ "1,2",
142
+ "--plan",
143
+ "docs/kairos/plans/p3.md",
144
+ ]);
145
+ });
146
+
147
+ it("coverage table — every verb × type literal parses green AND carries its type's runtime-required flags", () => {
148
+ for (const row of COVERAGE) {
149
+ const literal = literalOf(row.route, row.target);
150
+ // parse green (T4) …
151
+ expect(() => parseGate.parse(argvOf(literal), { from: "user" })).not.toThrow();
152
+ // … and the type's required flags are all present in the same arg domain (find #7)
153
+ for (const flag of row.required) {
154
+ expect(literal, `${row.label} must carry ${flag}`).toContain(flag);
155
+ }
156
+ }
157
+ });
158
+
159
+ it("review four-type literals carry zero sha — the live-tree review, no commit range", () => {
160
+ // §2.6 — every review literal is the live-tree judgment: the wave face carries
161
+ // `--tasks` + `--plan`, the branch/spec/plan faces their single doc arg; none
162
+ // carries a `--base`/`--head` range or a sha token.
163
+ const waveLiteral = literalOf({ kind: "review" }, wave);
164
+ const branchLiteral = literalOf({ kind: "review" }, branch);
165
+ const specLiteral = literalOf({ kind: "review" }, spec);
166
+ const planLiteral = literalOf({ kind: "review" }, planT);
167
+ expect(waveLiteral).toBe("review --type wave --tasks 1,2 --plan docs/kairos/plans/p3.md");
168
+ expect(branchLiteral).toBe("review --type branch --plan docs/kairos/plans/p3.md");
169
+ expect(specLiteral).toBe("review --type spec --spec docs/kairos/specs/p3-design.md");
170
+ expect(planLiteral).toBe("review --type plan --plan docs/kairos/plans/p3.md");
171
+ for (const literal of [waveLiteral, branchLiteral, specLiteral, planLiteral]) {
172
+ expect(literal).not.toContain("--base");
173
+ expect(literal).not.toContain("--head");
174
+ expect(literal).not.toMatch(/\b[0-9a-f]{8}\.\./);
175
+ }
176
+ });
177
+
178
+ it("the fix route keeps the FIX_READBACK_SUFFIX verbatim", () => {
179
+ const literal = literalOf({ kind: "fix", reviews: "tasks-1-review-1.json" }, wave);
180
+ expect(literal).toContain(FIX_READBACK_SUFFIX);
181
+ });
182
+
183
+ it("D47 — the next: literal's embedded paths render repoRoot-relative (absolute target + findings)", () => {
184
+ // §2.13 — the ONE renderer normalizes every embedded path value to the repoRoot-
185
+ // relative shape; an absolute target path and an absolute review path both come
186
+ // out relative, and the repo root never appears in the literal.
187
+ const repo = "/tmp/d47-repo";
188
+ const capsule = new Capsule(new Words(), {}, "", new RepoRoot(repo));
189
+ const lines = capsule.emit(
190
+ "CHANGES_REQUESTED",
191
+ "1",
192
+ `${repo}/.kairos/cdd/p3/tasks-1-review-1.json`,
193
+ { kind: "fix", reviews: `${repo}/.kairos/cdd/p3/tasks-1-review-1.json` },
194
+ { type: "plan", id: `${repo}/docs/kairos/plans/p3.md` },
195
+ );
196
+ const literal = lines[1]!.slice("next: ".length);
197
+ expect(literal).toBe(
198
+ `fix --type plan --plan docs/kairos/plans/p3.md --reviews .kairos/cdd/p3/tasks-1-review-1.json ${FIX_READBACK_SUFFIX}`,
199
+ );
200
+ expect(literal).not.toContain(repo);
201
+ // The handoff: cell is the same basis — repoRoot-relative, never absolute.
202
+ expect(lines[0]).toContain("handoff: .kairos/cdd/p3/tasks-1-review-1.json");
203
+ expect(lines[0]).not.toContain(repo);
204
+ });
205
+ });
206
+
207
+ // ---------------------------------------------------------------------------
208
+ // T3 — the unified next face: the `done` route's PIPELINE_NEXT doc-class lookup
209
+ // ---------------------------------------------------------------------------
210
+
211
+ /** The hermetic declaration repo — the spec docs the doc-class discrimination reads
212
+ * (spec §12 · D34: the declared front-matter `doc-type:` key, never the filename). */
213
+ describe("Capsule — the `done` route's PIPELINE_NEXT doc-class lookup (D33 · the unified next face)", () => {
214
+ let repo: string;
215
+
216
+ beforeEach(() => {
217
+ repo = mkdtempSync(path.join(tmpdir(), "capsule-done-"));
218
+ });
219
+
220
+ afterEach(() => {
221
+ rmSync(repo, { recursive: true, force: true });
222
+ });
223
+
224
+ /** A spec doc on disk declaring its doc type (the front-matter head key). */
225
+ const declareSpec = (name: string, docType: string | null): RouteTarget => {
226
+ mkdirSync(path.dirname(path.join(repo, name)), { recursive: true });
227
+ const head =
228
+ docType === null
229
+ ? ["---", "title: The doc", "version: v1.0", "status: Draft", "---"]
230
+ : [
231
+ "---",
232
+ "title: The doc",
233
+ "version: v1.0",
234
+ "status: Draft",
235
+ `doc-type: ${docType}`,
236
+ "---",
237
+ ];
238
+ writeFileSync(path.join(repo, name), [...head, ""].join("\n"), "utf8");
239
+ return { type: "spec", id: name } as const;
240
+ };
241
+
242
+ /** The done-text of a capsule emit for a host-injected capsule over the repo. */
243
+ const doneOf = (target?: RouteTarget, host = ""): string => {
244
+ const lines = new Capsule(new Words(), {}, host, new RepoRoot(repo)).emit(
245
+ "APPROVED",
246
+ "0",
247
+ "/h.json",
248
+ { kind: "done" },
249
+ target,
250
+ );
251
+ return lines[1]!.slice("next: ".length);
252
+ };
253
+
254
+ it("PIPELINE_NEXT carries exactly the five pipeline keys", () => {
255
+ expect(Object.keys(PIPELINE_NEXT).sort()).toEqual(
256
+ ["branch", "overall-spec", "phase-spec", "plan", "wave"].sort(),
257
+ );
258
+ });
259
+
260
+ it("no target renders the bare terminal word (the byte-pinned fallback)", () => {
261
+ expect(doneOf()).toBe("done");
262
+ });
263
+
264
+ it("a phase-spec-declared target routes the cdd-plan ref per host (claude / pi / empty)", () => {
265
+ const phaseSpec = declareSpec("docs/kairos/specs/prog-p8-design.md", "phase-spec");
266
+ expect(doneOf(phaseSpec, "claude")).toBe("/kairos:cdd-plan");
267
+ expect(doneOf(phaseSpec, "pi")).toBe("/skill:cdd-plan");
268
+ expect(doneOf(phaseSpec)).toBe("/kairos:cdd-plan");
269
+ });
270
+
271
+ it("an overall-spec-declared target renders the bare terminal word (the pipeline terminal)", () => {
272
+ const overall = declareSpec("docs/kairos/specs/prog-overall.md", "overall-spec");
273
+ expect(doneOf(overall)).toBe("done");
274
+ });
275
+
276
+ it("a spec target declaring no doc-type renders the BLOCKED face — zero filename-suffix fallback", () => {
277
+ const undeclared = declareSpec("docs/kairos/specs/prog-p8-design.md", null);
278
+ expect(doneOf(undeclared)).toBe(
279
+ "CDD_BLOCKED: the doc declares no `doc-type:` key — add `doc-type: <overall-spec|phase-spec|single-spec|plan>` to the doc's front-matter (spec §12 · D34) and re-run",
280
+ );
281
+ });
282
+
283
+ it("a single-spec-declared target renders the bare terminal word — no pipeline seam carries it", () => {
284
+ const single = declareSpec("docs/kairos/specs/prog-single-spec.md", "single-spec");
285
+ expect(doneOf(single)).toBe("done");
286
+ });
287
+
288
+ it("a plan target routes the cdd-dev ref; a branch target the cdd-close ref", () => {
289
+ expect(doneOf({ type: "plan", id: "docs/kairos/plans/prog-p8.md" })).toBe("/kairos:cdd-dev");
290
+ expect(doneOf({ type: "branch", id: "branch", plan: "docs/kairos/plans/prog-p8.md" })).toBe(
291
+ "/kairos:cdd-close",
292
+ );
293
+ });
294
+
295
+ it("a wave target renders the wiring literal with the plan slot filled", () => {
296
+ expect(doneOf({ type: "wave", id: "1,2", plan: "docs/kairos/plans/prog-p8.md" })).toBe(
297
+ "review --type branch --plan docs/kairos/plans/prog-p8.md",
298
+ );
299
+ });
300
+ });
@@ -0,0 +1,129 @@
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
+ // 4. the pipeline-next refs closure (T13 ⑨) — every `PIPELINE_NEXT` ref-key entry
19
+ // is registered in REFS and derives its per-harness forms (the face-to-face
20
+ // handoff table × the ref table cross-closure).
21
+ //
22
+ // Zero module-level bare functions — the assertions read the typed exports with
23
+ // `const` helpers only (the P5 zero-`function`-declaration discipline).
24
+
25
+ import { describe, expect, it } from "vitest";
26
+
27
+ import { PIPELINE_NEXT } from "../../session/next.ts";
28
+ import { ARGV_CHANNEL, CLI_COMMANDS } from "../declare.ts";
29
+ import { DISPATCH, HOSTS, REFS } from "../host.ts";
30
+
31
+ describe("the CLI channel closure — command keys × the declare argv channel (the single-surface closure)", () => {
32
+ it("every command/leaf declared key resolves in ARGV_CHANNEL — and every non-program channel key is declared by a command", () => {
33
+ // The declared aggregate — every key any command/leaf declares (the guard's
34
+ // collect face: keys only — positionals are arguments, never channel flags).
35
+ const declaredKeys = new Set<string>();
36
+ const collect = (spec: { keys: readonly { key: string }[] }): void => {
37
+ for (const declared of spec.keys) declaredKeys.add(declared.key);
38
+ };
39
+ for (const command of CLI_COMMANDS) {
40
+ collect(command);
41
+ for (const leaf of command.leaves ?? []) collect(leaf);
42
+ }
43
+ // Forward leg — a declared key absent from the channel is a broken closure.
44
+ const missing: string[] = [];
45
+ for (const key of declaredKeys) {
46
+ if (!(key in ARGV_CHANNEL)) missing.push(key);
47
+ }
48
+ expect(missing).toEqual([]);
49
+ // Reverse leg — a channel key declared by no command and not program-scoped
50
+ // (dry-run/help) is a broken closure.
51
+ const orphan: string[] = [];
52
+ for (const [key, row] of Object.entries(ARGV_CHANNEL)) {
53
+ if (declaredKeys.has(key) || ("scope" in row && row.scope === "program")) continue;
54
+ orphan.push(key);
55
+ }
56
+ expect(orphan).toEqual([]);
57
+ });
58
+
59
+ it("the D19 schema merge keeps the closure — the `output` key is the get leaf's declared channel row", () => {
60
+ // The merged single leaf declares `--output` (json|skeleton): the closure
61
+ // leg reads the leaf's declared keys, so the new row is covered exactly like
62
+ // every other declared key (a drag of the D19 deliberate change).
63
+ const schema = CLI_COMMANDS.find((command) => command.name === "schema")!;
64
+ const get = schema.leaves!.find((leaf) => leaf.name === "get")!;
65
+ expect(get.keys.map((declared) => declared.key)).toContain("output");
66
+ expect(ARGV_CHANNEL.output.values).toEqual(["json", "skeleton"]);
67
+ });
68
+ });
69
+
70
+ describe("the host-marker closure — the detect env keys ∪ PATH (single-sourced at the harness detect rows)", () => {
71
+ it("every HOSTS detect env key + PATH equals the pinned four (the deliberate half-update oracle)", () => {
72
+ const markerKeys = Object.values(HOSTS).map((row) => row.detect.env);
73
+ const expectedClosure = [...markerKeys, "PATH"].sort();
74
+ const pinned = ["AI_AGENT", "CLAUDE_CODE_SESSION_ID", "CURSOR_TRACE_ID", "PATH"].sort();
75
+ expect(expectedClosure).toEqual(pinned);
76
+ });
77
+ });
78
+
79
+ describe("the dispatch/refs derivation — every dispatch-slot ref registered + every per-harness form derived", () => {
80
+ it("the dispatch table's ref-shaped slots derive their per-harness slash forms", () => {
81
+ // The ref-shaped slots (`pkg:skill`, lowercase) are the table entries; a
82
+ // non-ref literal (the URC prose — spaces/uppercase) has no per-harness form.
83
+ const refKeys: string[] = [];
84
+ const pushRef = (value: string | { ref: string }): void => {
85
+ const ref = typeof value === "string" ? value : value.ref;
86
+ if (/^[a-z][a-z-]*:[a-z][a-z-]*$/.test(ref)) refKeys.push(ref);
87
+ };
88
+ pushRef(DISPATCH.implement);
89
+ for (const slot of Object.values(DISPATCH.review)) pushRef(slot);
90
+ // The shape is the closed pair — implement + the review rows (never vacuous);
91
+ // both review slots name the same ref key — deduped before the derivation.
92
+ expect([...new Set(refKeys)].sort()).toEqual([
93
+ "mattpocock-skills:code-review",
94
+ "mattpocock-skills:implement",
95
+ ]);
96
+ for (const ref of refKeys) {
97
+ const form = REFS[ref as keyof typeof REFS];
98
+ expect(form, `dispatch slot names the registered ref key "${ref}"`).toBeDefined();
99
+ if (form === undefined) continue;
100
+ for (const id of ["claude", "cursor", "pi"] as const) {
101
+ const expected = id === "pi" ? `/skill:${ref.split(":")[1]}` : `/${ref}`;
102
+ expect(form[id], `ref "${ref}" per-harness form for ${id}`).toBe(expected);
103
+ }
104
+ }
105
+ });
106
+
107
+ it("the PIPELINE_NEXT ref-key entries close over REFS (every handoff ref is registered + derives its forms)", () => {
108
+ // The face-to-face handoff table (session/next.ts PIPELINE_NEXT) routes each
109
+ // pipeline seam through a skill ref; every `{ kind: "ref" }` entry must name a
110
+ // registered REFS key and derive its per-harness slash forms — the same closure
111
+ // the dispatch leg enforces (a handoff ref absent from REFS renders the bare
112
+ // `done` word at the capsule's render, a silent mis-route).
113
+ const pipelineRefs = Object.values(PIPELINE_NEXT)
114
+ .filter((entry): entry is { kind: "ref"; ref: string } => entry.kind === "ref")
115
+ .map((entry) => entry.ref);
116
+ // The ref-shaped subset is non-empty (the phase-spec/plan/branch seams all route
117
+ // through refs; only the overall-spec seam is the `done` terminal + wave a literal).
118
+ expect(pipelineRefs.length).toBeGreaterThan(0);
119
+ for (const ref of pipelineRefs) {
120
+ const form = REFS[ref as keyof typeof REFS];
121
+ expect(form, `PIPELINE_NEXT names the registered ref key "${ref}"`).toBeDefined();
122
+ if (form === undefined) continue;
123
+ for (const id of ["claude", "cursor", "pi"] as const) {
124
+ const expected = id === "pi" ? `/skill:${ref.split(":")[1]}` : `/${ref}`;
125
+ expect(form[id], `PIPELINE_NEXT ref "${ref}" per-harness form for ${id}`).toBe(expected);
126
+ }
127
+ }
128
+ });
129
+ });