@oscaner-skills/cdd-engine 2.0.0 → 3.0.1

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 (127) hide show
  1. package/README.md +2 -2
  2. package/README.zh-CN.md +2 -2
  3. package/{src-next/bin.ts → dist/bin.js} +18 -21
  4. package/dist/contract/declare.js +998 -0
  5. package/dist/contract/doc.js +565 -0
  6. package/dist/contract/frontmatter.js +209 -0
  7. package/dist/contract/home-extractors.js +379 -0
  8. package/dist/contract/invariants.js +1030 -0
  9. package/dist/contract/judge.js +109 -0
  10. package/dist/contract/lint.js +206 -0
  11. package/dist/contract/project.js +371 -0
  12. package/dist/contract/skill-anatomy.js +156 -0
  13. package/dist/contract/translate.js +85 -0
  14. package/dist/face/artifacts.js +189 -0
  15. package/dist/face/board-view.js +522 -0
  16. package/dist/face/capsule.js +141 -0
  17. package/dist/face/cli.js +891 -0
  18. package/dist/face/declare.js +241 -0
  19. package/dist/face/gate.js +158 -0
  20. package/dist/face/graph-view.js +66 -0
  21. package/dist/face/host.js +211 -0
  22. package/dist/face/lifecycle.js +603 -0
  23. package/dist/face/preview.js +136 -0
  24. package/dist/face/projection.js +259 -0
  25. package/dist/face/route-render.js +162 -0
  26. package/dist/face/termination.js +482 -0
  27. package/dist/face/words.js +220 -0
  28. package/{src-next/infra/config.ts → dist/infra/config.js} +19 -24
  29. package/dist/infra/doc-roots.js +19 -0
  30. package/dist/infra/git.js +37 -0
  31. package/dist/infra/process.js +22 -0
  32. package/dist/infra/root.js +62 -0
  33. package/dist/infra/runtime.js +85 -0
  34. package/dist/infra/workspace.js +276 -0
  35. package/dist/render/brief.js +82 -0
  36. package/dist/render/issue-body.js +129 -0
  37. package/dist/render/skeleton.js +434 -0
  38. package/dist/render/templates.js +520 -0
  39. package/dist/session/faces.js +38 -0
  40. package/dist/session/graph.js +309 -0
  41. package/dist/session/handoff-schema.js +295 -0
  42. package/dist/session/ledger.js +762 -0
  43. package/dist/session/next.js +211 -0
  44. package/dist/session/preflight.js +194 -0
  45. package/dist/session/round-naming.js +73 -0
  46. package/dist/session/run.js +441 -0
  47. package/dist/session/state.js +8 -0
  48. package/dist/session/wave.js +92 -0
  49. package/package.json +8 -7
  50. package/templates/report/issue-body.json +0 -46
  51. package/src-next/__tests__/bin.test.ts +0 -128
  52. package/src-next/__tests__/smoke.integration.test.ts +0 -202
  53. package/src-next/__tests__/zero-dep.test.ts +0 -134
  54. package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +0 -238
  55. package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +0 -153
  56. package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +0 -173
  57. package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +0 -89
  58. package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +0 -225
  59. package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +0 -155
  60. package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +0 -175
  61. package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +0 -85
  62. package/src-next/contract/__tests__/declare.test.ts +0 -242
  63. package/src-next/contract/__tests__/doc.test.ts +0 -358
  64. package/src-next/contract/__tests__/judge.test.ts +0 -873
  65. package/src-next/contract/__tests__/lint.test.ts +0 -314
  66. package/src-next/contract/__tests__/project.test.ts +0 -419
  67. package/src-next/contract/__tests__/translate.test.ts +0 -96
  68. package/src-next/contract/declare.ts +0 -983
  69. package/src-next/contract/doc.ts +0 -753
  70. package/src-next/contract/invariants.ts +0 -1268
  71. package/src-next/contract/judge.ts +0 -142
  72. package/src-next/contract/lint.ts +0 -275
  73. package/src-next/contract/project.ts +0 -596
  74. package/src-next/contract/skill-anatomy.ts +0 -273
  75. package/src-next/contract/translate.ts +0 -113
  76. package/src-next/face/__tests__/board-view.test.ts +0 -948
  77. package/src-next/face/__tests__/capsule.test.ts +0 -276
  78. package/src-next/face/__tests__/channel-closure.guard.test.ts +0 -102
  79. package/src-next/face/__tests__/cli.test.ts +0 -4643
  80. package/src-next/face/__tests__/face.test.ts +0 -289
  81. package/src-next/face/__tests__/graph-view.test.ts +0 -61
  82. package/src-next/face/__tests__/host.test.ts +0 -24
  83. package/src-next/face/__tests__/negation.ts +0 -6
  84. package/src-next/face/__tests__/projection.test.ts +0 -301
  85. package/src-next/face/__tests__/sync-runner.test.ts +0 -70
  86. package/src-next/face/__tests__/words.guard.test.ts +0 -93
  87. package/src-next/face/artifacts.ts +0 -195
  88. package/src-next/face/board-view.ts +0 -662
  89. package/src-next/face/capsule.ts +0 -149
  90. package/src-next/face/cli.ts +0 -819
  91. package/src-next/face/declare.ts +0 -326
  92. package/src-next/face/gate.ts +0 -170
  93. package/src-next/face/graph-view.ts +0 -74
  94. package/src-next/face/host.ts +0 -326
  95. package/src-next/face/lifecycle.ts +0 -700
  96. package/src-next/face/projection.ts +0 -282
  97. package/src-next/face/route-render.ts +0 -160
  98. package/src-next/face/words.ts +0 -296
  99. package/src-next/infra/__tests__/infra.test.ts +0 -287
  100. package/src-next/infra/git.ts +0 -39
  101. package/src-next/infra/process.ts +0 -34
  102. package/src-next/infra/runtime.ts +0 -185
  103. package/src-next/infra/workspace.ts +0 -232
  104. package/src-next/render/__tests__/render.test.ts +0 -499
  105. package/src-next/render/__tests__/skeleton.test.ts +0 -466
  106. package/src-next/render/brief.ts +0 -121
  107. package/src-next/render/issue-body.ts +0 -159
  108. package/src-next/render/skeleton.ts +0 -437
  109. package/src-next/render/templates.ts +0 -650
  110. package/src-next/session/__tests__/graph.test.ts +0 -270
  111. package/src-next/session/__tests__/handoff-plane.guard.test.ts +0 -48
  112. package/src-next/session/__tests__/handoff-schema.test.ts +0 -310
  113. package/src-next/session/__tests__/ledger.test.ts +0 -744
  114. package/src-next/session/__tests__/next.test.ts +0 -368
  115. package/src-next/session/__tests__/preflight.test.ts +0 -491
  116. package/src-next/session/__tests__/run.test.ts +0 -1014
  117. package/src-next/session/__tests__/wave-line-phase.guard.test.ts +0 -49
  118. package/src-next/session/__tests__/wave.test.ts +0 -469
  119. package/src-next/session/faces.ts +0 -110
  120. package/src-next/session/graph.ts +0 -411
  121. package/src-next/session/handoff-schema.ts +0 -373
  122. package/src-next/session/ledger.ts +0 -1004
  123. package/src-next/session/next.ts +0 -192
  124. package/src-next/session/preflight.ts +0 -240
  125. package/src-next/session/run.ts +0 -606
  126. package/src-next/session/state.ts +0 -30
  127. package/src-next/session/wave.ts +0 -139
@@ -0,0 +1,211 @@
1
+ // packages/cdd-engine/src-next/session/next.ts
2
+ // T7 — NextStepRouter single point (design spec §3.2): the ONLY `next:` generation
3
+ // face of the new tree. The C5 decision table (the spec's pinned semantics, v1.20:
4
+ // the closure single-verdict — close() is the one closure point every review/fix
5
+ // approval shares):
6
+ // review zero findings → close(state) — the ready batch decides next-wave | done
7
+ // review findings → fix (one-way — a review never previews what a fix will do)
8
+ // fix blocker>0 → a re-review hop (the live tree, no commit identity)
9
+ // fix blocker==0 → close(state) — the warn/nit-only / clean closure (#278,
10
+ // no APPROVED-mandated re-review)
11
+ // fix soft cap → the "BLOCKED: review-cycle-cap" suggestion (user adjudicates)
12
+ // BLOCKED/TIMEOUT → null (no next line — the CDD_BLOCKED channel owns the face)
13
+ //
14
+ // close(state) — the v1.20 unified closure terminal: every closure point (a review
15
+ // with zero findings / a fix whose source blockers cleared) renders the SAME route
16
+ // family — `next-wave` when another wave is ready, `done` when the run is exhausted.
17
+ // The `none` word is RETIRED (closure is `done`, never "no suggestion"), and a
18
+ // completed non-failed round producing null is now a hard error on the dispatch face
19
+ // (no next line = abnormal) — never a silent approved-without-next.
20
+ //
21
+ // The table judges the round carrier (ledger.ts — the fix round's own findings are
22
+ // the source review's input, C5-1) against the execution state (state.ts — the
23
+ // ready batch decides next-wave vs done). The Route output carries the structured
24
+ // facts the capsule face renders into the `next:` line — including the fix-route
25
+ // readback copy, authored here once as FIX_READBACK_SUFFIX (the declared wording
26
+ // the capsule renders verbatim, never a literal restate).
27
+ //
28
+ // D40 — ONE "next step" concept: the face-INTERNAL C5 hop and the face-TO-face
29
+ // handoff are the SAME `Route` union (a `handoff` kind carries the pipeline entry),
30
+ // so a consumer never consults a second table. `NextStepRouter.resolve` is the ONE
31
+ // "one line → next" resolver: an active C5 hop passes through, a drained line yields
32
+ // the face-to-face handoff. Both the board (its per-line walk) and the capsule
33
+ // (the round's own line) call it — single resolver, single renderer.
34
+ //
35
+ // Module-level exports are types / constants / the class — zero behavior-carrying
36
+ // bare functions (the plan's zero-bare-function discipline).
37
+ /** The review-cycle soft cap — the consecutive-S1 run length at which the fix face
38
+ * defers the next hop to user adjudication (soft by nature: a default suggestion,
39
+ * never a hard stop — the user / the plan write authority override it). */
40
+ export const REVIEW_CYCLE_CAP = 20;
41
+ /** The decision-edge words of the Route union — the C5 hop kinds that a review/fix
42
+ * closure decision edge renders as a `next:` label (`done` · `next-wave` · `review`
43
+ * · `fix` · `soft-cap`). The pure face-to-face `handoff` kind is EXCLUDED: it carries
44
+ * no decision word (it renders the pipeline entry ref/literal, never a branch label).
45
+ * The skill-anatomy contract's `edgeConditionWords` derives from this tuple — the
46
+ * runtime Route lexicon is the ONE source, never a second hand-written list. */
47
+ export const ROUTE_DECISION_WORDS = ["done", "next-wave", "review", "fix", "soft-cap"];
48
+ /** The pipeline next table — the ONE face-indirection source (D33 · single-addressed
49
+ * at session/next.ts):
50
+ * the doc-class key → the next pipeline entrypoint. The skill refs ride REFS
51
+ * (face/host.ts) resolved per host at the render — never a hard-coded plugin
52
+ * spelling; the wave literal's `<plan>` slot is filled by the capsule with the
53
+ * frame's plan fact. */
54
+ export const PIPELINE_NEXT = {
55
+ "phase-spec": { kind: "ref", ref: "kairos:cdd-plan" },
56
+ "overall-spec": { kind: "done" },
57
+ plan: { kind: "ref", ref: "kairos:cdd-dev" },
58
+ wave: { kind: "literal", literal: "review --type branch --plan <plan>" },
59
+ branch: { kind: "ref", ref: "kairos:cdd-close" },
60
+ };
61
+ /** The pipeline's phase-level face order (D40) — the face-to-face traversal
62
+ * `spec → plan → wave → branch`, the ONE order declaration; `NextStepRouter.walk`
63
+ * iterates it, so a consumer maps key → facts and declares NO order of its own. */
64
+ export const PIPELINE_FACES = ["phase-spec", "plan", "wave", "branch"];
65
+ /** The review-cycle soft-cap suggestion (the C5-0 suggestion face — user adjudicates). */
66
+ export const SOFT_CAP_SUGGESTION = "BLOCKED: review-cycle-cap — user adjudicates";
67
+ /** The fix-route readback suffix — appended verbatim to the fix findings path on the
68
+ * route's `next:` render (`(confirm the findings · if a finding needs a ruling,
69
+ * record the ruling in the findings file)`), a pure wording prompt: the
70
+ * anti-blind-fix mechanical guard is the ledger round / C5-1, the suffix only
71
+ * reminds the orchestrator to confirm the captured findings and, when a finding
72
+ * needs a user ruling, record that ruling back into the findings file the fix
73
+ * round consumes. `annotate` names the carrier action alone — distinct from
74
+ * `backfill` (a durable fact landed into its owning doc), which stays the
75
+ * ruling's destination when it asserts a project-level fact. */
76
+ export const FIX_READBACK_SUFFIX = "(confirm the findings · if a finding needs a ruling, record the ruling in the findings file)";
77
+ /** The failure face — a BLOCKED/TIMEOUT round goes the stderr CDD_BLOCKED channel and
78
+ * produces no `next:` line on any op. Exported as the ONE failure-status set: the
79
+ * skill-anatomy contract's `edgeConditionWords` derivation reads it to exclude the
80
+ * failure statuses from the decision-edge status words (a failure round carries no
81
+ * closure edge — the reason rides the CDD_BLOCKED channel). */
82
+ export const FAILED_STATUS = new Set(["BLOCKED", "TIMEOUT"]);
83
+ /**
84
+ * NextStepRouter — the C5 decision table as one instance method. The router keeps
85
+ * no hidden state: every judgment reads the execution state + the round carrier.
86
+ */
87
+ export class NextStepRouter {
88
+ /** next(state, ref) — the C5 derivation: the next-hop Route, or null when the round
89
+ * produces no next line (the BLOCKED/TIMEOUT failure-mode face). */
90
+ next(state, ref) {
91
+ // The failure face first — a BLOCKED/TIMEOUT round never gets a next suggestion.
92
+ if (ref.status !== undefined && FAILED_STATUS.has(ref.status))
93
+ return null;
94
+ switch (ref.phase) {
95
+ case "implement":
96
+ // The implement round completes → the group's review is the next hop. A
97
+ // review judges the live tree, so the hop carries no commit identity.
98
+ return { kind: "review" };
99
+ case "review":
100
+ // One-way: any findings (any severity) → the fix round — a review never previews
101
+ // what the fix will do (C5-1). Zero findings (approved) → the unified closure: the
102
+ // ready batch decides whether the next wave continues or the run is exhausted.
103
+ if (ref.findings.length > 0)
104
+ return { kind: "fix", reviews: ref.reviewsPath };
105
+ return this.#close(state);
106
+ case "fix": {
107
+ // C5-1: the fix face is the re-review / closure decision point. The soft cap
108
+ // outranks the blocker row — a capped run defers to the user, never auto-loops.
109
+ if (ref.consecutiveS1 >= REVIEW_CYCLE_CAP) {
110
+ return { kind: "soft-cap", message: SOFT_CAP_SUGGESTION };
111
+ }
112
+ if (this.#blockerCount(ref) > 0) {
113
+ // Blockers remain in the input findings → the fix delta is re-reviewed. A
114
+ // review judges the live tree, so the hop carries no commit identity.
115
+ return { kind: "review" };
116
+ }
117
+ // No blockers → the unified closure: the ready batch decides next-wave | done
118
+ // (a warn/nit-only fix closes — the #278 REVIEW_FIX state, no re-review preview).
119
+ return this.#close(state);
120
+ }
121
+ case "branch-review":
122
+ // The branch terminal face — findings route the fix; zero findings close the line
123
+ // through the same unified closure terminal.
124
+ return ref.findings.length > 0
125
+ ? { kind: "fix", reviews: ref.reviewsPath }
126
+ : this.#close(state);
127
+ }
128
+ }
129
+ /** The unified closure terminal (v1.20) — the single way a review/fix closure renders
130
+ * its next hop: the ready batch decides `next-wave` vs `done` (a closing review with
131
+ * another wave ready continues the run; an exhausted run reports `done`). */
132
+ #close(state) {
133
+ const ready = state.readyBatch();
134
+ return ready.length > 0 ? { kind: "next-wave", tasks: ready.join(",") } : { kind: "done" };
135
+ }
136
+ /** The blocker count of the round's findings — the C5-1 severity count. */
137
+ #blockerCount(ref) {
138
+ return ref.findings.filter((finding) => finding.severity === "blocker").length;
139
+ }
140
+ /** The face-to-face handoff route for a pipeline doc-class (D40) — the next-face
141
+ * entry (`PIPELINE_NEXT[key]`). One of the two ways the ONE "next step" concept
142
+ * is produced (the C5 hop is the other), so a consumer never consults a second
143
+ * table. */
144
+ static handoff(key) {
145
+ return { kind: "handoff", entry: PIPELINE_NEXT[key] };
146
+ }
147
+ /** Resolve a line's next step (D40) — the capsule's "one line → next" point for the
148
+ * round's OWN line: an ACTIVE C5 hop (`review` / `fix` / `implement` / `next-wave` /
149
+ * `soft-cap`) passes through as the line's next step; a drained / not-yet-started
150
+ * line (the C5 `done` / no active round) yields the face-to-face handoff carrying
151
+ * the pipeline entry. A null doc-class (no face seam — the overall line / a bare
152
+ * terminal) renders the bare `done` word. A whole-slug walk is `walk` (the board's
153
+ * face-to-face traversal); this is the single-line form the capsule holds. Pure. */
154
+ static resolve(active, key) {
155
+ if (active !== null && active.kind !== "done")
156
+ return active;
157
+ return key === null ? { kind: "done" } : NextStepRouter.handoff(key);
158
+ }
159
+ /** Walk(face report) → the ONE next step (D40 · the board's face-to-face traversal
160
+ * as a single router method). The caller REPORTS each face's facts keyed by its
161
+ * `PIPELINE_FACES` key; the router iterates the ONE order and DECIDES the next step
162
+ * — so no consumer re-derives the order OR the face-transition rule (the retired
163
+ * board fork handed off via the frontier LINE's own key, so a slug whose spec just
164
+ * closed but whose plan was not yet authored rendered `plan`'s exit `cdd-dev`
165
+ * instead of the spec's exit `cdd-plan` — a face-boundary off-by-one the ONE walk
166
+ * eliminates). The rule:
167
+ * · the FRONTIER face (first not-closed) with an active C5 hop → render that hop
168
+ * (the in-flight work — `review` / `fix` / `implement` / `next-wave`);
169
+ * · the frontier has no active hop but IS entered (`target` present — an empty
170
+ * wave segment, a drained-but-reached face) → its OWN pipeline exit entry;
171
+ * · the frontier is NOT entered (no target — an absent doc, e.g. no plan yet) →
172
+ * the transition INTO it, i.e. the PRECEDING entered face's exit entry (so a
173
+ * just-closed spec hands off to the spec's exit `cdd-plan`, never the absent
174
+ * plan's exit); no preceding entered face → the FIRST face's exit entry;
175
+ * · every face closed → the LAST entered face's exit entry (the pipeline
176
+ * terminus — `cdd-close` for a phase slug). */
177
+ static walk(report) {
178
+ const states = PIPELINE_FACES.map((key) => report[key]);
179
+ const frontierIndex = states.findIndex((face) => !face.closed);
180
+ if (frontierIndex === -1) {
181
+ const terminalIndex = NextStepRouter.#lastEnteredIndex(states);
182
+ const terminal = terminalIndex === -1 ? null : states[terminalIndex];
183
+ return terminal === null
184
+ ? { route: { kind: "done" }, target: null }
185
+ : {
186
+ route: NextStepRouter.handoff(PIPELINE_FACES[terminalIndex]),
187
+ target: terminal.target,
188
+ };
189
+ }
190
+ const frontier = states[frontierIndex];
191
+ if (frontier.active !== null)
192
+ return { route: frontier.active, target: frontier.target };
193
+ const anchorIndex = frontier.target !== null
194
+ ? frontierIndex
195
+ : Math.max(0, NextStepRouter.#lastEnteredIndex(states.slice(0, frontierIndex)));
196
+ const anchor = states[anchorIndex];
197
+ return {
198
+ route: NextStepRouter.handoff(PIPELINE_FACES[anchorIndex]),
199
+ target: anchor.target,
200
+ };
201
+ }
202
+ /** The index of the last OBSERVED face carrying a render target — the last face the
203
+ * pipeline has REACHED (a face with no target was never entered). -1 when none is. */
204
+ static #lastEnteredIndex(states) {
205
+ for (let i = states.length - 1; i >= 0; i--) {
206
+ if (states[i].target !== null)
207
+ return i;
208
+ }
209
+ return -1;
210
+ }
211
+ }
@@ -0,0 +1,194 @@
1
+ // packages/cdd-engine/src-next/session/preflight.ts
2
+ // P4.1 T1 — the lifecycle pre-flight seam (design spec §1): the dispatch gates
3
+ // converge into ONE single-entry gate a work command consults before ANY child
4
+ // dispatch — the clean-tree hard gate (tree-clean → BLOCKED with the commit/discard
5
+ // guidance, the skill-side claim `engine entry gate: dirty → BLOCKED` finally made
6
+ // real), then the wave-side gates (graph validate + the three-verb WaveGate)
7
+ // and the doc-side gate (Contract.validate over the target doc).
8
+ //
9
+ // Gate order (the design's pinned sequence, judgeable on every verdict):
10
+ // tree-clean → (wave/plan faces) graph validate → (wave face) WaveGate.vet →
11
+ // (spec/plan faces) Contract.validate → dispatch
12
+ // The evidence/read-back gates stay at the dispatch child face (the seam never
13
+ // touches the round's produced artifacts — non-pre-flight by design).
14
+ //
15
+ // The verdict is the single BLOCK carrier: `gate` names the refusing gate, `reason`
16
+ // the named refusal row, `message` the CDD_BLOCKED wording (pinned rows), `details`
17
+ // the named issue/finding lines the renderer prints, `order` the gates that ran
18
+ // (the CLI never re-implements a gate — the seam owns the whole sequence). BLOCK
19
+ // wording rides the word table (the capsule station + the preflight rows), never a
20
+ // CLI restate.
21
+ //
22
+ // Module-level exports are types / the class — zero behavior-carrying bare
23
+ // functions (the plan's zero-bare-function discipline).
24
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
25
+ import { PlanDocType } from "../contract/doc.js";
26
+ import { FrontMatterExtractor } from "../contract/frontmatter.js";
27
+ import { RepoRoot } from "../infra/root.js";
28
+ import { TaskGraph } from "./graph.js";
29
+ import { WaveGate } from "./wave.js";
30
+ /**
31
+ * PreFlight — the single pre-flight seam of the work dispatch. One `vet` call runs
32
+ * the whole gate sequence in the pinned order and returns the verdict the CLI
33
+ * renders (or approves): the seam owns the gates, the CLI only orchestrates the
34
+ * call + the render — zero second implementation on the CLI face.
35
+ */
36
+ export class PreFlight {
37
+ /** The git seam the tree-clean gate reads. */
38
+ #git;
39
+ /** The doc-contract coordinator the doc faces judge through. */
40
+ #contract;
41
+ /** The three-verb unified wave gate the wave face consults. */
42
+ #waveGate;
43
+ /** The word table the BLOCK wording rides. */
44
+ #words;
45
+ /** The filesystem seam the doc-contract gate reads (defaults to node:fs). */
46
+ #fs;
47
+ constructor(opts) {
48
+ this.#git = opts.git;
49
+ this.#contract = opts.contract;
50
+ this.#words = opts.words;
51
+ this.#waveGate = opts.waveGate ?? new WaveGate();
52
+ this.#fs = opts.fs ?? new NodeFs();
53
+ }
54
+ /** vet(ctx) — the single seam call: tree-clean → graph → wave → doc-contract.
55
+ * The first refused gate owns the verdict; the gates that ran precede it (the
56
+ * judgeable order). */
57
+ async vet(ctx) {
58
+ const gates = [];
59
+ // 1. tree-clean — the hard gate all three verbs share: a dirty working tree
60
+ // BLOCKs BEFORE any other judgment (review's baseline = the committed state). isClean is
61
+ // fail-open-false (a non-repo counts dirty — the CDD flow needs git).
62
+ gates.push("tree-clean");
63
+ if (!(await this.#git.isClean(ctx.repoRoot))) {
64
+ return {
65
+ ok: false,
66
+ gate: "tree-clean",
67
+ reason: "dirty-tree",
68
+ message: this.#words.preflightWords().dirtyTree,
69
+ order: gates,
70
+ };
71
+ }
72
+ // 2. graph — the wave/plan faces' structural gate: the plan's DependsOn
73
+ // graph must validate (missing-edge / missing-id / self-loop / cycle) before
74
+ // the dispatch reads it. The task-loss class dies here, never silently.
75
+ let graph = null;
76
+ if ((ctx.type === "wave" || ctx.type === "plan") && ctx.planText !== null) {
77
+ gates.push("graph");
78
+ graph = new TaskGraph(new PlanDocType("plan").parse(ctx.planText.split("\n")));
79
+ const issues = graph.validate();
80
+ if (issues.length > 0) {
81
+ return {
82
+ ok: false,
83
+ gate: "graph",
84
+ reason: "graph",
85
+ message: this.#words.preflightWords().graph.replace("{count}", String(issues.length)),
86
+ details: issues.map((issue) => `${issue.kind}@T${issue.task}: ${issue.message}`),
87
+ order: gates,
88
+ };
89
+ }
90
+ }
91
+ // 3. wave — the three-verb unified wave gate (the task face's phase authority):
92
+ // the requested `--tasks` must be EXACTLY the derived open wave at the verb's
93
+ // phase. The refusal wording rides the wave-gate word-table rows.
94
+ if (ctx.type === "wave" && graph !== null && ctx.ledger !== null && ctx.tasks !== null) {
95
+ gates.push("wave");
96
+ const verdict = this.#waveGate.vet(ctx.tasks, ctx.verb, graph, ctx.ledger, this.#words);
97
+ if (!verdict.ok) {
98
+ return {
99
+ ok: false,
100
+ gate: "wave",
101
+ reason: verdict.reason,
102
+ message: verdict.message ?? "",
103
+ order: gates,
104
+ };
105
+ }
106
+ }
107
+ // 4. doc-contract — the doc faces' structural gate: the target doc must pass
108
+ // Contract.validate (the interpreter's single judgment entry) before its
109
+ // review/fix round dispatches. An unreadable doc carries no judgment (no
110
+ // fabricated findings from an absent surface). A PRESENT doc carrying no
111
+ // `doc-type:` key BLOCKs (spec §12 · D34: the declared type is
112
+ // the one reading face, zero filename-suffix fallback).
113
+ if (ctx.type === "spec" || ctx.type === "plan") {
114
+ gates.push("doc-contract");
115
+ const doc = ctx.doc;
116
+ // The relative `RepoPath` erases to the absolute syscall form through the ONE
117
+ // value object (the seam's OWN `RepoRoot(ctx.repoRoot)`) just before the read.
118
+ const docAbsolute = doc === null ? null : new RepoRoot(ctx.repoRoot).resolve(doc.path);
119
+ const content = docAbsolute === null ? null : this.#fs.read(docAbsolute);
120
+ if (content !== null && doc !== null && docAbsolute !== null) {
121
+ // D1 (position-carrying error): a front-matter block the `yaml` engine cannot parse is
122
+ // BLOCKed with the REAL failure (line · column · reason) BEFORE the
123
+ // doc-type judgment — an unparseable head also reads no doc-type, so the
124
+ // parse check must precede the missing-key check (the misread fix: a
125
+ // `[`-led author line reports "invalid YAML", never "no doc-type").
126
+ const { head } = FrontMatterExtractor.split(content);
127
+ const parseError = head.parseError;
128
+ if (parseError !== null) {
129
+ return {
130
+ ok: false,
131
+ gate: "doc-contract",
132
+ reason: "doc-contract",
133
+ message: this.#words
134
+ .routeWord("frontmatterParse")
135
+ .replace("{reason}", parseError.reason)
136
+ .replace("{line}", String(parseError.line))
137
+ .replace("{column}", String(parseError.column))
138
+ .replace("{source}", parseError.source),
139
+ order: gates,
140
+ };
141
+ }
142
+ if (doc.docKey === null) {
143
+ return {
144
+ ok: false,
145
+ gate: "doc-contract",
146
+ reason: "doc-contract",
147
+ message: this.#words.routeWord("docType"),
148
+ order: gates,
149
+ };
150
+ }
151
+ const findings = this.#contract.validate({
152
+ docKey: doc.docKey,
153
+ path: docAbsolute,
154
+ content,
155
+ root: ctx.repoRoot,
156
+ fs: this.#fs,
157
+ });
158
+ if (findings.length > 0) {
159
+ return {
160
+ ok: false,
161
+ gate: "doc-contract",
162
+ reason: "doc-contract",
163
+ message: this.#words.preflightWords().docContract,
164
+ details: findings.map((finding) => `${finding.kind}@${finding.field}: ${finding.message}`),
165
+ order: gates,
166
+ };
167
+ }
168
+ }
169
+ }
170
+ return { ok: true, order: gates };
171
+ }
172
+ }
173
+ /** The node:fs default — the production seam for the doc-contract's file reads. */
174
+ class NodeFs {
175
+ read(p) {
176
+ try {
177
+ return readFileSync(p, "utf8");
178
+ }
179
+ catch {
180
+ return null;
181
+ }
182
+ }
183
+ exists(p) {
184
+ return existsSync(p);
185
+ }
186
+ list(p) {
187
+ try {
188
+ return readdirSync(p);
189
+ }
190
+ catch {
191
+ return [];
192
+ }
193
+ }
194
+ }
@@ -0,0 +1,73 @@
1
+ // packages/cdd-engine/src-next/session/round-naming.ts
2
+ // P11 T4 — the round-naming single source: the frame → artifact-name derivations
3
+ // (report · evidence · brief) the lifecycle's read-back and the dry-run preview
4
+ // share, plus the frame → family-op mapping those names key on. The handoff carrier
5
+ // name is NOT derived here — it stays with the Ledger's HANDOFF_FAMILIES table (the
6
+ // naming table is the single truth, never a second list).
7
+ //
8
+ // Module-level exports are the class — zero behavior-carrying bare functions.
9
+ /**
10
+ * RoundNaming — the one home of a round's prescribed artifact names. A frame's
11
+ * report / evidence / brief names derive here, so every consumer (the lifecycle's
12
+ * write-back and read-back, the dry-run preview, the brief render) names the same
13
+ * artifacts by the same rule — one fact, one place. The class holds only the
14
+ * workspace the names resolve against.
15
+ */
16
+ export class RoundNaming {
17
+ #workspace;
18
+ constructor(workspace) {
19
+ this.#workspace = workspace;
20
+ }
21
+ /** The handoff-family op of a frame — branch-review rides the review family. The
22
+ * artifact stems embed this op, so the mapping is a naming fact owned here (the
23
+ * lifecycle's op read delegates, never a second copy of the rule). */
24
+ op(frame) {
25
+ return frame.phase === "branch-review" ? "review" : frame.phase;
26
+ }
27
+ /** The engine-rendered brief path of a wave's task group —
28
+ * `tasks-{tasks}-brief.md` (the implement dispatch's read input; its producer is
29
+ * `CliGate#renderBrief`). */
30
+ brief(tasks) {
31
+ return this.#workspace.resolve(this.briefName(tasks));
32
+ }
33
+ /** The brief's workspace-relative NAME — the write face takes the name, the read
34
+ * faces take the resolved path (one derivation, both spellings). */
35
+ briefName(tasks) {
36
+ return `tasks-${tasks}-brief.md`;
37
+ }
38
+ /** The prescribed report path of a round — the doc line's
39
+ * `{type}-{op}-{round}-report.md` stem, the wave/branch line's
40
+ * `{family}-{op}{-round}-report.md` (the implement round carries no round token:
41
+ * the line keys the implement round alone). */
42
+ report(frame) {
43
+ if (frame.type === "spec" || frame.type === "plan") {
44
+ return this.#workspace.resolve(`${frame.type}-${this.op(frame)}-${frame.round}-report.md`);
45
+ }
46
+ const family = frame.type === "wave" ? `tasks-${frame.params.tasks ?? ""}` : "branch";
47
+ const suffix = frame.phase === "implement" ? "" : `-${frame.round}`;
48
+ return this.#workspace.resolve(`${family}-${this.op(frame)}${suffix}-report.md`);
49
+ }
50
+ /** The prescribed test-evidence path of a round — "" off the work faces (the doc
51
+ * lines and the review rounds prescribe no evidence file). */
52
+ evidence(frame) {
53
+ const name = this.evidenceName(frame);
54
+ return name === "" ? "" : this.#workspace.resolve(name);
55
+ }
56
+ /** The test-evidence file NAME of a work frame — the workspace-relative face the
57
+ * read-back gate reads it by (`{line}-test-evidence.json`: the task families key
58
+ * the line, the branch line names the family alone). "" off the work faces. */
59
+ evidenceName(frame) {
60
+ if (frame.type === "spec" || frame.type === "plan")
61
+ return "";
62
+ if (frame.phase !== "implement" && frame.phase !== "fix")
63
+ return "";
64
+ const key = frame.type === "wave" ? (frame.params.tasks ?? "") : "";
65
+ const line = key === "" ? this.prefix(frame) : `${this.prefix(frame)}-${key}`;
66
+ return `${line}-test-evidence.json`;
67
+ }
68
+ /** The evidence file's family prefix — `tasks` for the wave families, `branch`
69
+ * for the branch line (never the misleading tasks- spine). */
70
+ prefix(frame) {
71
+ return frame.type === "wave" ? "tasks" : "branch";
72
+ }
73
+ }