@oscaner-skills/cdd-engine 4.3.0 → 4.5.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.
@@ -0,0 +1,282 @@
1
+ // packages/cdd-engine/src-next/session/dispatch-authority.ts
2
+ // P27 §2 — the dispatch authority: ONE verdict over the three legs, in ONE priority
3
+ // order (structure → upstream → line, short-circuiting on the first refusal).
4
+ //
5
+ // Before this object the dispatch question was answered at two call sites by two
6
+ // independent authorities: the wave face's phase by `WaveGate.vet` (from
7
+ // session/preflight.ts) and the doc/branch face's by `CliGate#lineGate` (from
8
+ // face/cli.ts). The order between them was implicit in the two call sites, the two
9
+ // refusal vocabularies never met, and the station object (`NextHop`) had no dispatch
10
+ // reader at all — so a `next:` could name a round the dispatch face then refused.
11
+ //
12
+ // The legs:
13
+ // · structure — the pre-flight seam's verdict (tree-clean · in-flight · graph ·
14
+ // plan-ledger · doc-contract), handed in already judged: its inputs (the git
15
+ // tree, the in-flight lock) are the seam's to read, and the seam's report face
16
+ // (the ordered gate rows + the named findings) renders beside the refusal. The
17
+ // leg names no hop — a dirty tree has no `next:` round.
18
+ // · upstream — the station's reviewed-identity + closure pair over the faces that
19
+ // precede the request's face (P27 §2.3): the faces are read off `PIPELINE_FACES`
20
+ // (the ONE order), each judged by ① whether its reviewed identity moved (a doc
21
+ // line's `reviewGate` · a wave line's `briefDrifted`) and ② whether it has closed
22
+ // for the request (a doc line's `lineStateAt` · the wave face's exhaustion over
23
+ // `closedWaves()`). A face the pipeline never entered holds no station — its
24
+ // line carries no round to hold the request — so the request face is the
25
+ // pipeline's own first entry. `waveLineRoute !== null` is never a closure judge:
26
+ // a never-entered face's `active` is null, and a closed-but-drifted wave is ①'s
27
+ // catch, because exhaustion only answers "every task is done".
28
+ // · line — this line's own phase: the wave face's five rows (the `WaveGate` stays
29
+ // the leg's judge) and the doc/branch face's rows (pending-fix · unchanged ·
30
+ // face-closed, plus the drift reopen, which ADMITS the review round).
31
+ //
32
+ // The verdict's `next` is the pipeline frontier's own hop (`PipelineFrontier#hopOf`)
33
+ // — the object the capsule and the board already render, never a second shape and
34
+ // never a second derivation. The refusal line is correspondingly ONE line
35
+ // (§2.6): `reason · next: <command>` on the line leg, `reason · <wording>` on the
36
+ // structure leg (no hop to name). The command renderer itself stays on the face
37
+ // plane (the argv channel / host / repo-basis facts are the face's to hold).
38
+ //
39
+ // Module-level exports are types / the class — zero behavior-carrying bare functions.
40
+ var _a;
41
+ import { TargetFaceTable, targetFaces, } from "./faces.js";
42
+ import { DISPATCH_REASON, PIPELINE_FACES, } from "./next.js";
43
+ import { PipelineFrontier } from "./pipeline.js";
44
+ import { WaveGate } from "./wave.js";
45
+ /**
46
+ * DispatchAuthority — the ONE dispatch verdict (§2.1/§2.2). One `verdict` call walks
47
+ * the three legs in priority order and returns the single verdict the CLI renders,
48
+ * the capsule's `next:` and the board's `next:` all read the same hop through it.
49
+ *
50
+ * Rule zero on the ≤200-line class cap (broke by design, not by accident): the three
51
+ * legs are one short-circuit chain over one `next:` assembly — extracted, the chain's
52
+ * order moves to a caller and a refusal can name a round another leg contradicts.
53
+ */
54
+ export class DispatchAuthority {
55
+ /** The wave face's five rows — this leg's wave judge (the judgment body stays in
56
+ * `WaveGate`, whose verdict rows are the reason table's `leg: "line"` rows). */
57
+ #waveGate;
58
+ constructor(opts = {}) {
59
+ this.#waveGate = opts.waveGate ?? new WaveGate();
60
+ }
61
+ /** verdict(request) — the priority chain: structure, then upstream, then the line.
62
+ * The first leg that refuses owns the verdict (§2.2: report the most upstream
63
+ * cause — the actionable one). */
64
+ verdict(request) {
65
+ const structure = this.structureRefusal(request.structure);
66
+ if (structure !== null)
67
+ return structure;
68
+ const upstream = this.#upstreamLeg(request);
69
+ if (upstream !== null)
70
+ return upstream;
71
+ return this.#lineLeg(request);
72
+ }
73
+ /** message(verdict, render) — the ONE refusal line (§2.6): `reason · next: ` plus
74
+ * the command the hop renders, or `reason · <wording>` on the structure leg. */
75
+ message(verdict, render) {
76
+ if (verdict.next === null) {
77
+ return render.detail === undefined || render.detail === ""
78
+ ? verdict.reason
79
+ : `${verdict.reason} · ${render.detail}`;
80
+ }
81
+ const command = render.command === undefined ? "" : render.command(verdict.next);
82
+ return `${verdict.reason} · next: ${command}`;
83
+ }
84
+ /** The structure leg's verdict — the seam's refusal re-expressed as this chain's
85
+ * first row. Its token is the refusing gate's own id (the table's structure rows:
86
+ * `tree-clean` · `in-flight` · `graph` · `plan-ledger` · `doc-contract`), never a
87
+ * new spelling. Public because the lifecycle re-states a seam refusal (the
88
+ * structurally unreachable dispatch-entry path) through the same shape. */
89
+ structureRefusal(preflight) {
90
+ if (preflight.ok)
91
+ return null;
92
+ const gate = preflight.gate;
93
+ // A refused pre-flight always names its gate; a gate-less refusal is no
94
+ // structure verdict at all (the seam keeps its own report face).
95
+ if (gate === undefined)
96
+ return null;
97
+ return { allowed: false, leg: "structure", reason: gate, next: null };
98
+ }
99
+ /** The upstream leg (§2.3) — the faces that PRECEDE the request's face, in the ONE
100
+ * `PIPELINE_FACES` order: the request face's index cuts the order, and the first
101
+ * upstream face that reports owns the verdict. Its `next` is the pipeline
102
+ * frontier's own hop — the object the capsule and the board render — so a refusal
103
+ * never names a round another face contradicts. */
104
+ #upstreamLeg(request) {
105
+ const index = _a.#faceIndexOf(request.type);
106
+ if (index <= 0)
107
+ return null;
108
+ for (const face of PIPELINE_FACES.slice(0, index)) {
109
+ const station = this.#stationOf(face, request.line);
110
+ if (station === null)
111
+ continue;
112
+ const next = this.#hopOf(request.line);
113
+ const reason = station === "drift" ? DISPATCH_REASON.docDrift.token : next.reason;
114
+ return { allowed: false, leg: "upstream", reason, next };
115
+ }
116
+ return null;
117
+ }
118
+ /** One upstream face's station sign — ① first (a moved reviewed identity refuses as
119
+ * `doc-drift` whatever the closure cell says), then ② (the face has not closed for
120
+ * the request, so the frontier's own hop reason rules). */
121
+ #stationOf(face, facts) {
122
+ if (face === "wave")
123
+ return this.#waveStation(facts);
124
+ const line = _a.#docFaceOf(face, facts.pipeline);
125
+ if (line === null)
126
+ return null;
127
+ const ledger = facts.ledger;
128
+ // A line with no recorded round was never entered: no station, nothing to hold.
129
+ if (!_a.#docEntered(ledger, line))
130
+ return null;
131
+ if (ledger.reviewGate(line.key, line.doc, line.type).kind === "open")
132
+ return "drift";
133
+ return ledger.lineStateAt(line.key, line.type, line.doc) === "closed" ? null : "open";
134
+ }
135
+ /** The wave face's station — read off the SAME two judges the frontier runs, never a
136
+ * local walk: entered over the three dispatch modes, drifted over the derived
137
+ * batches' reviewed briefs, exhausted over `closedWaves()`. */
138
+ #waveStation(facts) {
139
+ const graph = facts.pipeline.planGraph;
140
+ if (graph === null)
141
+ return null;
142
+ const frontier = this.#frontierOf(facts);
143
+ if (!frontier.wavesEntered(graph))
144
+ return null;
145
+ const drifted = graph.batches().some((batch) => facts.ledger.briefDrifted(batch.join(",")));
146
+ if (drifted)
147
+ return "drift";
148
+ return frontier.wavesExhausted(graph) ? null : "open";
149
+ }
150
+ /** The line leg — this line's phase against the requested one, with the refusal's
151
+ * `next` read from the pipeline frontier only when the line actually refuses. */
152
+ #lineLeg(request) {
153
+ const ruling = request.type === "wave" ? this.#waveRuling(request) : this.#docRuling(request);
154
+ if (ruling.kind === "allowed")
155
+ return { allowed: true };
156
+ const next = this.#hopOf(request.line);
157
+ const reason = ruling.kind === "row" ? ruling.reason : next.reason;
158
+ return { allowed: false, leg: "line", reason, next };
159
+ }
160
+ /** The wave face's rows — the three-verb gate judged whole (its order IS the
161
+ * judgment: a shape matching an earlier row keeps that earlier row's cause). */
162
+ #waveRuling(request) {
163
+ const facts = request.line;
164
+ if (facts.graph === null || facts.tasks === null)
165
+ return { kind: "allowed" };
166
+ const verdict = this.#waveGate.vet(facts.tasks, request.verb, facts.graph, facts.ledger, facts.words);
167
+ if (verdict.ok || verdict.reason === undefined)
168
+ return { kind: "allowed" };
169
+ return { kind: "row", reason: verdict.reason };
170
+ }
171
+ /** linePhaseFacts(ledger, input) — this line's phase, read ONCE (§2.7): the drift
172
+ * reopen (which ADMITS the review lead), the derived pending fix, then the
173
+ * rounds/routes judge. The face gate renders this value; this object's line leg
174
+ * judges it — one derivation, two readers, no second walk to drift from. */
175
+ linePhaseFacts(ledger, input) {
176
+ const gate = input.key !== null && input.doc !== null
177
+ ? ledger.reviewGate(input.key, input.doc, input.type)
178
+ : null;
179
+ if (input.key !== null && gate !== null && ledger.docReopens(input.key, input.type, gate)) {
180
+ return { phase: targetFaces[input.type].product.reviewLead, verdict: null, reviewed: null };
181
+ }
182
+ if (gate !== null && gate.kind === "same") {
183
+ return gate.pending
184
+ ? { phase: "fix", verdict: "pending-fix", reviewed: gate.reviewed }
185
+ : this.#sameDocFallback(ledger, input, gate.reviewed);
186
+ }
187
+ return { phase: this.#lineRoutePhase(ledger, input), verdict: null, reviewed: null };
188
+ }
189
+ /** An unchanged doc holding no pending fix — the legacy rounds/routes fall-through:
190
+ * a completed-fix line reopens the review lead through its fix round's route, while
191
+ * a truly closed line keeps the "same" verdict (the revision-aware BLOCK's face). */
192
+ #sameDocFallback(ledger, input, reviewed) {
193
+ const open = this.#lineRoutePhase(ledger, input);
194
+ return open !== null
195
+ ? { phase: open, verdict: null, reviewed: null }
196
+ : { phase: null, verdict: "same", reviewed };
197
+ }
198
+ /** The rounds/routes phase — the ledger's SINGLE line-phase judge (D40). */
199
+ #lineRoutePhase(ledger, input) {
200
+ return input.key === null ? null : ledger.linePhase(input.key, input.type);
201
+ }
202
+ /** The doc/branch face's rows, in order: the line's phase (the drift reopen is a ROW
203
+ * that admits the review lead), then the named refusals, then the hop's own fact
204
+ * when the line sits at another open round. */
205
+ #docRuling(request) {
206
+ const facts = request.line;
207
+ const phase = this.linePhaseFacts(facts.ledger, {
208
+ key: facts.lineKey,
209
+ doc: facts.doc,
210
+ type: request.type,
211
+ });
212
+ if (phase.phase === this.#expectedPhase(request.type, request.verb)) {
213
+ return { kind: "allowed" };
214
+ }
215
+ // A pending fix is the line's own row: the fix it awaits is a present fact, and
216
+ // the refusal names it whatever the requested verb was.
217
+ if (phase.phase === "fix")
218
+ return { kind: "row", reason: DISPATCH_REASON.pendingFix.token };
219
+ if (phase.phase !== null)
220
+ return { kind: "hop" };
221
+ // The closed line: the doc shapes name their unchanged reviewed identity (the
222
+ // anti-spin row); every other line keeps the generic closed face.
223
+ const unchanged = TargetFaceTable.isDocShape(request.type) && phase.verdict === "same";
224
+ return {
225
+ kind: "row",
226
+ reason: unchanged ? DISPATCH_REASON.unchanged.token : DISPATCH_REASON.faceClosed.token,
227
+ };
228
+ }
229
+ /** The phase the requested verb dispatches on this face — the review verb asks for
230
+ * the face's OWN review lead (the branch line's `branch-review`). */
231
+ #expectedPhase(type, verb) {
232
+ if (verb === "implement")
233
+ return "implement";
234
+ if (verb === "fix")
235
+ return "fix";
236
+ return targetFaces[type].product.reviewLead;
237
+ }
238
+ /** The refusal's `next` — the pipeline frontier's ONE assembly (§2.1), the object
239
+ * the capsule and the board render. */
240
+ #hopOf(facts) {
241
+ return this.#frontierOf(facts).hopOf(facts.pipeline, {
242
+ docClassOf: facts.docClassOf,
243
+ });
244
+ }
245
+ /** The pipeline frontier over this line's ledger — ONE construction per read. */
246
+ #frontierOf(facts) {
247
+ return new PipelineFrontier(facts.ledger);
248
+ }
249
+ /** The pipeline face a target type occupies — the identity slot's declared words
250
+ * (`phase-spec` / `single-spec`) share face 0, every node face is its own key, and
251
+ * the charter (`overall`) occupies no pipeline face at all (-1). Read off
252
+ * `PIPELINE_FACES` (the ONE order declaration), never a second order table. */
253
+ static #faceIndexOf(type) {
254
+ const face = type === "single-spec" ? "phase-spec" : type;
255
+ return _a.#isPipelineFace(face) ? PIPELINE_FACES.indexOf(face) : -1;
256
+ }
257
+ static #isPipelineFace(key) {
258
+ return PIPELINE_FACES.includes(key);
259
+ }
260
+ /** One upstream doc face's line identity — a node face's own key/document, the
261
+ * identity slot's DECLARED word (`specType`, the `single-spec` / `phase-spec`
262
+ * spelling the document carries). A face with no document was never entered; the
263
+ * charter is no pipeline face at all, so it is never an upstream station. */
264
+ static #docFaceOf(face, pipeline) {
265
+ if (face === "plan" || face === "branch") {
266
+ return pipeline.planPath === null ? null : { type: face, key: face, doc: pipeline.planPath };
267
+ }
268
+ if (pipeline.specType === "overall")
269
+ return null;
270
+ const type = pipeline.specType ?? "phase-spec";
271
+ return pipeline.specPath === null ? null : { type, key: type, doc: pipeline.specPath };
272
+ }
273
+ /** Whether an upstream doc face was ever WORKED — its line carries at least one
274
+ * recorded round (the review lead or a fix). A face the pipeline never entered
275
+ * holds no station: the request face is the pipeline's own first entry. */
276
+ static #docEntered(ledger, line) {
277
+ const lead = targetFaces[line.type].product.reviewLead;
278
+ return (ledger.roundCount(line.key, lead, line.type) > 0 ||
279
+ ledger.roundCount(line.key, "fix", line.type) > 0);
280
+ }
281
+ }
282
+ _a = DispatchAuthority;
@@ -23,6 +23,7 @@
23
23
  var _a;
24
24
  import { createHash } from "node:crypto";
25
25
  import { readdirSync, readFileSync } from "node:fs";
26
+ import { DocBodyProjection } from "../contract/doc-body.js";
26
27
  import { BriefRenderer } from "../render/brief.js";
27
28
  import { targetFaces } from "./faces.js";
28
29
  import { HandoffSchema } from "./handoff-schema.js";
@@ -142,10 +143,15 @@ const RETIRED_SPEC_LINE_KEYS = new Set([
142
143
  * derivation point — typed data, zero prose.
143
144
  */
144
145
  export class ReviewRefs {
145
- /** The doc-revision two-layer binding — the doc path + the content-hash revision
146
- * (sha1 of the reviewed file content — the second layer of the doc ref). */
146
+ /** The doc-revision two-layer binding — the doc path + the BODY's content-hash
147
+ * revision (sha1 of the reviewed body — the second layer of the doc ref). The
148
+ * bookkeeping faces (front matter, `## Change history`) are projected away by the
149
+ * `contract/` projection first (P26 T1): a closed-out registration write never
150
+ * reopens a reviewed line, while a substantive body edit still drifts. */
147
151
  docRevision(doc, content) {
148
- return { kind: "doc-revision", doc, doc_hash: this.#hash(content) };
152
+ const body = typeof content === "string" ? content : content.toString("utf8");
153
+ const projected = new DocBodyProjection().project(body);
154
+ return { kind: "doc-revision", doc, doc_hash: this.#hash(projected) };
149
155
  }
150
156
  /** The brief-revision two-layer binding (D30) — the plan path the brief renders
151
157
  * from + the RENDERED brief content's hash (the wave line's reviewed identity). */
@@ -167,7 +173,7 @@ export class ReviewRefs {
167
173
  #hash(content) {
168
174
  // The revision hash is a content digest (a fingerprint of the reviewed bytes),
169
175
  // never a commit ref — the full sha1 hex stays unsliced so the bind basis covers
170
- // the whole content, not a truncated prefix.
176
+ // the whole input, not a truncated prefix.
171
177
  return createHash("sha1").update(content).digest("hex");
172
178
  }
173
179
  }
@@ -394,10 +400,10 @@ export class Ledger {
394
400
  return cycles.length > 0 ? Math.max(...cycles) + 1 : 1;
395
401
  }
396
402
  /** Record a line's reviewed identity — the identity-aware gate's basis (written
397
- * when the review round completes: the line reopens on drift from this recorded
398
- * revision, and BLOCKs revision-aware when unchanged). The kind IS part of the
399
- * identity: a doc line binds a doc-revision (T7), a wave line a brief-revision
400
- * (D30) — one row, one reviewed identity. */
403
+ * when a review or a fix round completes: the line reopens on drift from this
404
+ * recorded revision, and BLOCKs revision-aware when unchanged). The kind IS part
405
+ * of the identity: a doc line binds a doc-revision (T7), a wave line a
406
+ * brief-revision (D30) — one row, one reviewed identity. */
401
407
  recordReviewedRevision(key, revision, identity = null) {
402
408
  const data = this.readProgress() ?? this.emptyProgress();
403
409
  let row = _a.rowFor(data, key, identity);
@@ -569,8 +575,7 @@ export class Ledger {
569
575
  return { kind: "review" };
570
576
  if (route?.kind === "fix") {
571
577
  // The fix-awaited face — a drifted wave BRIEF reopens at review (D30/D16), else fix.
572
- const reviewed = this.reviewedRevisionOf(waveKey);
573
- if (reviewed !== null && this.#briefDrift(waveKey, reviewed))
578
+ if (this.briefDrifted(waveKey))
574
579
  return { kind: "review" };
575
580
  return {
576
581
  kind: "fix",
@@ -603,9 +608,12 @@ export class Ledger {
603
608
  * (the append-only backfill case the whole-plan hash wrongly flagged). An
604
609
  * underivable brief (unreadable plan / absent task) is not a drift (present
605
610
  * facts only). A row bound to a non-brief kind (a doc kind, only via a corrupt
606
- * hand-write) is not a wave brief — no drift. */
607
- #briefDrift(waveKey, reviewed) {
608
- if (reviewed.kind !== "brief-revision")
611
+ * hand-write) is not a wave brief — no drift. The ONE public read of the fact:
612
+ * `waveLineRoute`'s D30 leg and the next-hop assembly's reason-only `briefDrift`
613
+ * cell both come through here. */
614
+ briefDrifted(waveKey) {
615
+ const reviewed = this.reviewedRevisionOf(waveKey);
616
+ if (reviewed === null || reviewed.kind !== "brief-revision")
609
617
  return false;
610
618
  const current = this.#briefRevision(waveKey, reviewed.plan);
611
619
  if (current === null)
@@ -781,8 +789,8 @@ export class Ledger {
781
789
  return route?.kind === "review" ? route : null;
782
790
  }
783
791
  /** The single-target line's open phase — the rounds/routes walk the lifecycle's
784
- * frame frontier (run.ts #nextLinePhase) and the CLI gate (gate.ts #linePhase)
785
- * BOTH consume (one judge, one source — the retired twin copies), mapped from
792
+ * frame frontier (run.ts #nextLinePhase) and the authority's line-phase read both
793
+ * consume (one judge, one source — the retired twin copies), mapped from
786
794
  * `lineRoute`'s active C5 hop: the review-lead hop reads the face's own review-lead
787
795
  * mode word (branch→branch-review, the others→review), the fix hop `"fix"`, a closed
788
796
  * line null. */
@@ -796,16 +804,23 @@ export class Ledger {
796
804
  * line's OWN facts and handed to the router's ONE derivation: the drift-aware gate
797
805
  * verdict, the ONE doc-class verdict (the declared station the face axis is read
798
806
  * out of), the caller's route (the count table's row for a single line, the
799
- * pipeline walk's route for the board) and the judged document. Every read face
800
- * (capsule · CLI rejection · board · the lifecycle frontier) comes through here,
801
- * so the four faces share one object by construction — no face assembles a second
802
- * copy of the inputs, and no judgment is re-made here (the route is the count
803
- * table's). The ONE exception is the drift-reopened line: the gate's `drift`
804
- * verdict IS the reopen, and the closure-side route the count table recorded
805
- * predates the document movement — so the assembly hands the derivation the
806
- * reopened review hop in that case. A presentation-level substitution: the count
807
- * table's judgment (`NextStepRouter#next`) stays the only judge, and a still-open
808
- * hop (review / fix) is never overridden by the drift fact. */
807
+ * pipeline walk's route for the board) and the judged document. TWO assemblies
808
+ * call this derivation (the line frontier's and the pipeline frontier's
809
+ * `PipelineFrontier#hopOf`) and neither keeps a private copy of the inputs — the
810
+ * line frontier serves `peekNext` and the CLI rejection, the pipeline assembly
811
+ * serves the capsule and the board — and no judgment is re-made here (the route is
812
+ * the count table's). TWO drift values leave this assembly, kept apart on purpose:
813
+ * · the ROUTE SUBSTITUTION driver reads the gate verdict alone (a doc line's
814
+ * `reviewGate`); the injected `briefDrift` cell never moves a route — a wave's
815
+ * exit-side station (`handoff`) is never rewritten into a review;
816
+ * · the REASON cell adds the caller-injected wave brief-drift fact to that
817
+ * verdict, so a drifted wave names `doc-drift` without a second judgment.
818
+ * The ONE exception to the route being the caller's is the drift-reopened doc
819
+ * line: the gate's `drift` verdict IS its reopen, and the closure-side route the
820
+ * count table recorded predates the document movement — so the assembly hands the
821
+ * derivation the reopened review hop in that case. A presentation-level
822
+ * substitution: the count table's judgment (`NextStepRouter#next`) stays the only
823
+ * judge, and a still-open hop (review / fix) is never overridden by the drift fact. */
809
824
  nextHopOf(input) {
810
825
  const drift = input.doc != null && input.type !== "wave"
811
826
  ? this.reviewGate(input.key, input.doc, input.type).kind === "open"
@@ -822,9 +837,13 @@ export class Ledger {
822
837
  // The face axis is the ONE verdict this assembly reads (spec §5.2's doc-class
823
838
  // discrimination): no target carries no judgeable class (the bare terminal).
824
839
  const verdict = input.target === null ? "terminal" : input.docClassOf(input.target);
840
+ // The REASON cell's drift value — `drift` above plus the caller-injected wave
841
+ // brief-drift fact. The two are kept apart: only `drift` drives the route
842
+ // substitution, so a wave's exit-side station keeps its bytes while its `reason:`
843
+ // row still names the movement.
825
844
  return this.#router.nextHop({
826
845
  target: input.target,
827
- gate: { drift },
846
+ gate: { drift: drift || (input.briefDrift ?? false) },
828
847
  verdict,
829
848
  route,
830
849
  nextLineOpen: input.nextLineOpen,
@@ -3,7 +3,8 @@
3
3
  // Today's session carried two parallel comparisons (the doc line's doc-revision and
4
4
  // the wave line's brief-revision); the branch line had none at all. This class is the
5
5
  // single identity face all three read:
6
- // · spec / plan — the document's `doc-revision` (a hash of the whole content);
6
+ // · spec / plan — the document's `doc-revision` (a hash of the BODY: front matter
7
+ // and `## Change history` are projected away, P26 T1);
7
8
  // · wave — the RENDERED brief's `brief-revision` (its task sections plus the
8
9
  // plan's `## Constraints` — a plan edit elsewhere is not a drift);
9
10
  // · branch — its plan document's `doc-revision` (the SAME kind, no new ref
@@ -30,8 +30,8 @@
30
30
  // so a consumer never consults a second table. The face-to-face station selection
31
31
  // rides the ONE derivation (`nextHop`): a `done` route's `to` cell is
32
32
  // `PIPELINE_NEXT`'s row for the judged doc class, a `handoff` route carries its own
33
- // entry, and the pipeline traversal itself belongs to the board's assembly face —
34
- // no second resolver.
33
+ // entry, and the pipeline traversal itself belongs to the session plane's
34
+ // `PipelineFrontier` — no second resolver.
35
35
  //
36
36
  // Module-level exports are types / constants / the class — zero behavior-carrying
37
37
  // bare functions (the plan's zero-bare-function discipline).
@@ -55,34 +55,74 @@ export { MAX_TASKS_PER_WAVE } from "../contract/wave-width.js";
55
55
  export const ROUTE_DECISION_WORDS = ["done", "next-wave", "review", "fix", "soft-cap"];
56
56
  /** The pipeline next table — the ONE face-indirection source (D33 · single-addressed
57
57
  * at session/next.ts), keyed by the SAME TargetType the CLI declares: the target
58
- * type → the next pipeline entrypoint. The two program-level rows (`overall` and
59
- * the standalone `single-spec`) are the pipeline's terminals — nothing follows a
60
- * closed charter line. The skill refs ride REFS (face/host.ts) resolved per host
61
- * at the render — never a hard-coded plugin spelling; the wave literal's `<plan>`
62
- * slot is filled by the capsule with the frame's plan fact. */
58
+ * type → the next pipeline entrypoint. The ONE program-level terminal row is
59
+ * `overall` — nothing follows a closed charter line; a closed `single-spec` is a
60
+ * spec line like any other, so it hands off to `cdd-plan`. The skill refs ride REFS
61
+ * (face/host.ts) resolved per host at the render — never a hard-coded plugin
62
+ * spelling; the wave literal's `<plan>` slot is filled by the capsule with the
63
+ * frame's plan fact. */
63
64
  export const PIPELINE_NEXT = {
64
65
  "phase-spec": { kind: "ref", ref: "kairos:cdd-plan" },
65
66
  overall: { kind: "done" },
66
67
  plan: { kind: "ref", ref: "kairos:cdd-dev" },
67
- "single-spec": { kind: "done" },
68
+ "single-spec": { kind: "ref", ref: "kairos:cdd-plan" },
68
69
  wave: { kind: "literal", literal: "review --type branch --plan <plan>" },
69
70
  branch: { kind: "ref", ref: "kairos:cdd-close" },
70
71
  };
71
72
  /** The pipeline's phase-level face order (D40) — the face-to-face traversal
72
- * `spec → plan → wave → branch`, the ONE order declaration: the board's assembly
73
- * face iterates it, so a consumer maps key → facts and declares NO order of its own. */
73
+ * `spec → plan → wave → branch`, the ONE order declaration: the session plane's
74
+ * `PipelineFrontier` iterates it, so a consumer maps key → facts and declares NO
75
+ * order of its own. */
74
76
  export const PIPELINE_FACES = ["phase-spec", "plan", "wave", "branch"];
75
- /** The single reason table (§5.2) — every `NextHop.reason` value comes from here, so
76
- * the four read faces and the CLI rejection message name a fact by ONE spelling (a
77
- * hyphenated fact name, never a sentence). */
77
+ /** The single reason table (§2.5) — every refusal row and every `NextHop.reason`
78
+ * value names a fact by ONE spelling from here (a hyphenated fact name, never a
79
+ * sentence). The structure rows reuse the pre-flight gate ids as their tokens (no
80
+ * newly minted token); the line rows are the wave gate's five plus the doc/branch
81
+ * refusals (including the same-revision `unchanged` row); the station rows are the
82
+ * signs a `next:` hop is named by. */
83
+ export const DISPATCH_REASON = {
84
+ // structure — the pre-flight gate ids, reused as tokens
85
+ treeClean: { token: "tree-clean", leg: "structure" },
86
+ inFlight: { token: "in-flight", leg: "structure" },
87
+ graph: { token: "graph", leg: "structure" },
88
+ planLedger: { token: "plan-ledger", leg: "structure" },
89
+ docContract: { token: "doc-contract", leg: "structure" },
90
+ // line — the wave gate's five rows
91
+ mixedBatch: { token: "mixed-batch", leg: "line" },
92
+ waveTooWide: { token: "wave-too-wide", leg: "line" },
93
+ tooManyTasks: { token: "too-many-tasks", leg: "line" },
94
+ split: { token: "split", leg: "line" },
95
+ wrongPhase: { token: "wrong-phase", leg: "line" },
96
+ // line — the doc/branch refusals
97
+ pendingFix: { token: "pending-fix", leg: "line" },
98
+ unchanged: { token: "unchanged", leg: "line" },
99
+ closedLine: { token: "closed-line", leg: "line" },
100
+ faceClosed: { token: "face-closed", leg: "line" },
101
+ // station — the signs a `next:` hop is named by
102
+ docDrift: { token: "doc-drift", leg: "station" },
103
+ softCap: { token: "soft-cap", leg: "station" },
104
+ taskOpen: { token: "task-open", leg: "station" },
105
+ docClassBlocked: { token: "doc-class-blocked", leg: "station" },
106
+ };
107
+ /** The wave gate's five rows — the table's `leg: "line"` wave rows as a typed view
108
+ * (the token spellings live in the table ONLY; `wave.ts` carries no second copy). */
109
+ export const WAVE_GATE_REASON = {
110
+ mixedBatch: DISPATCH_REASON.mixedBatch.token,
111
+ waveTooWide: DISPATCH_REASON.waveTooWide.token,
112
+ tooManyTasks: DISPATCH_REASON.tooManyTasks.token,
113
+ split: DISPATCH_REASON.split.token,
114
+ wrongPhase: DISPATCH_REASON.wrongPhase.token,
115
+ };
116
+ /** The named accessors for `NextHop.reason` — every value is the table's own token
117
+ * (one spelling source; the hop reason domain spans both the line and station legs). */
78
118
  export const NEXT_HOP_REASON = {
79
- docDrift: "doc-drift",
80
- pendingFix: "pending-fix",
81
- closedLine: "closed-line",
82
- faceClosed: "face-closed",
83
- softCap: "soft-cap",
84
- taskOpen: "task-open",
85
- docClassBlocked: "doc-class-blocked",
119
+ docDrift: DISPATCH_REASON.docDrift.token,
120
+ pendingFix: DISPATCH_REASON.pendingFix.token,
121
+ closedLine: DISPATCH_REASON.closedLine.token,
122
+ faceClosed: DISPATCH_REASON.faceClosed.token,
123
+ softCap: DISPATCH_REASON.softCap.token,
124
+ taskOpen: DISPATCH_REASON.taskOpen.token,
125
+ docClassBlocked: DISPATCH_REASON.docClassBlocked.token,
86
126
  };
87
127
  /** The review-cycle soft-cap suggestion (the C5-0 suggestion face — user adjudicates). */
88
128
  export const SOFT_CAP_SUGGESTION = "BLOCKED: review-cycle-cap — user adjudicates";
@@ -240,7 +280,8 @@ export class NextStepRouter {
240
280
  return PIPELINE_NEXT[verdict];
241
281
  }
242
282
  /** The named fact behind the hop — one `NEXT_HOP_REASON` row, in this order: the
243
- * soft cap · a pending fix · a drift-reopened line · an open line advancing · an
283
+ * soft cap · a pending fix · a drift-reopened line (its reviewed identity moved —
284
+ * a doc revision or a wave's brief revision) · an open line advancing · an
244
285
  * unjudgeable doc class · a closed face · the closed line's handoff. Drift never
245
286
  * outranks a pending fix (an unclosed line's blocker keeps the fix hop). */
246
287
  #reasonOf(input, route, verdict) {