@oscaner-skills/cdd-engine 4.12.0 → 4.14.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.
@@ -34,17 +34,21 @@
34
34
  //
35
35
  // Module-level exports are types / constants / the classes — zero behavior-carrying
36
36
  // bare functions (the plan's zero-bare-function discipline).
37
+ var _a;
37
38
  import { readFileSync } from "node:fs";
38
39
  import path from "node:path";
39
40
  import { FrontMatterExtractor } from "../contract/frontmatter.js";
40
41
  import { DOC_KEYS } from "../contract/project.js";
42
+ import { REGRADE_NOTE_SEPARATOR, regradeNote } from "../contract/review-criteria.js";
41
43
  import { ConfigLoader } from "../infra/config.js";
42
44
  import { RepoRoot } from "../infra/root.js";
43
45
  import { ENGINE_RUNTIME } from "../infra/runtime.js";
44
46
  import { SlugIndex } from "../infra/slug-index.js";
45
47
  import { Workspace, WorkspaceRoot } from "../infra/workspace.js";
46
- import { CarrierIntegrity } from "../session/carrier-integrity.js";
47
- import { Ledger, RoundRecords } from "../session/ledger.js";
48
+ import { ArtifactReads } from "../session/artifact-reads.js";
49
+ import { CarrierIntegrity, CarrierMismatchError } from "../session/carrier-integrity.js";
50
+ import { HandoffSchema } from "../session/handoff-schema.js";
51
+ import { Ledger, RoundRecords, } from "../session/ledger.js";
48
52
  import { PipelineFrontier } from "../session/pipeline.js";
49
53
  import { PROGRESS_LEGEND, PROGRESS_MARKERS } from "./graph-view.js";
50
54
  import { RouteRenderer } from "./route-render.js";
@@ -55,6 +59,11 @@ const VERB_ORDER = ["implement", "review", "branch-review", "fix"];
55
59
  /** The judgement glyphs of one aggregated token (spec §5.3 — the mark is MANDATORY:
56
60
  * `✓` a completed round, `✗` a round that failed its target action). */
57
61
  const JUDGEMENT_MARKERS = { passed: "✓", failed: "✗", recovered: "✗→✓" };
62
+ /** The closed projection — no matrix, default view. The value a caller that observes
63
+ * no artifacts passes (a `null` registry answers zero `art:` rows). */
64
+ export const NO_ARTIFACTS = { registry: null, showAll: false };
65
+ /** The empty slot — one shared value, never a freshly minted arm. */
66
+ const NO_DOC = { kind: "none" };
58
67
  /** The DocKey domain of the `doc-type:` declaration — the declared value must
59
68
  * be one of the four keys; anything else reads null (present facts, never a
60
69
  * fabricated type). Derived from the ONE DocKey declaration (contract/project.ts
@@ -73,6 +82,17 @@ const PHASE_TITLE_MAX = 60;
73
82
  /** The label column of the board's line rows — ` ` + the label padded to this
74
83
  * width (`overall` is the longest verb at 7), so every value starts in one column. */
75
84
  const LABEL_WIDTH = 9;
85
+ /** The `art:` fact block's continuation keys — the board's OWN spelling of the three
86
+ * facts a judgment carries (spec §2.6). Deliberately independent of
87
+ * `Words#artifactIdentity`: that row is the gate's §2.4 contract (`derived: `,
88
+ * a colon inside its own two-space column), while the board's rows are the §2.6
89
+ * contract (`derived`, no colon, the board's continuation column). One source per
90
+ * contract, and the board's half is pinned by its byte assertions. */
91
+ const ARTIFACT_FACT_LABELS = {
92
+ derived: "derived",
93
+ found: "found",
94
+ reason: "reason",
95
+ };
76
96
  /** One board line's carrier facts — the `+N` count's WHOLE read face (spec §2.7 ·
77
97
  * §2.10). The record's path comes from the ledger's ONE accessor, bound to this
78
98
  * line's type + key; ownership excludes a legacy record whose path a later round of
@@ -82,6 +102,13 @@ const LABEL_WIDTH = 9;
82
102
  export class LineCarriers {
83
103
  #records;
84
104
  #pathOf;
105
+ /** The ONE per-record read's cache — the carrier bytes are read (and parsed) once
106
+ * per record, then both projections (`countOf` / `findingsOf`) take their cell from
107
+ * the same value (P37 §5.2). */
108
+ #content = new Map();
109
+ /** The findings projection's schema face — the SAME `HandoffSchema.findingsOf` the
110
+ * round read-back uses (one projection, two consumers). */
111
+ #schema = new HandoffSchema();
85
112
  constructor(records, pathOf) {
86
113
  this.#records = records;
87
114
  this.#pathOf = pathOf;
@@ -89,35 +116,92 @@ export class LineCarriers {
89
116
  /** The judgment over one line's records, with the caller supplying each record's
90
117
  * carrier path — the board's own derivation is `ofLedger` below. */
91
118
  static of(records, pathOf) {
92
- return new LineCarriers(records, pathOf);
119
+ return new _a(records, pathOf);
93
120
  }
94
121
  /** The board's derivation — the ledger's ONE accessor, bound to this line's type +
95
122
  * key. No ledger (no workspace to observe) resolves no path for every record. */
96
123
  static ofLedger(ledger, type, key, records) {
97
- return LineCarriers.of(records, (record) => ledger?.carrierPathOf(type, key, record) ?? "");
124
+ return _a.of(records, (record) => ledger?.carrierPathOf(type, key, record) ?? "");
98
125
  }
99
126
  /** One record's graded findings count — zero for a record that resolves no path or
100
127
  * whose path a later round overwrote; a tampered carrier THROWS (the checked read). */
101
128
  countOf(record) {
129
+ return this.#contentOf(record).count;
130
+ }
131
+ /** One record's findings as the round-finding projection (P37 §5.2) — the board's
132
+ * per-record read face, sharing `countOf`'s ONE carrier read and ONE parse. The
133
+ * projection is `HandoffSchema.findingsOf` (unknown severities still dropped), so
134
+ * the count's native array length and this filtered row set are two cells of the
135
+ * same read, never two reads. */
136
+ findingsOf(record) {
137
+ return this.#contentOf(record).findings;
138
+ }
139
+ /** One record's downgrade note (P37 §5.1 · §5.2) — its findings judged against the
140
+ * nearest EARLIER record on this line whose findings projection is non-empty (an
141
+ * implement / fix record with no findings never resets the reference, so a downgrade
142
+ * cannot slip through a clean neighbour). `undefined` when nothing was downgraded,
143
+ * the mark when a row owes its reason, the stated reason when the row carries one. */
144
+ regradeNoteOf(record) {
145
+ const prior = this.#priorOf(record);
146
+ const current = this.findingsOf(record);
147
+ return regradeNote(HandoffSchema.downgrades(prior, current).length, HandoffSchema.regradeReasons(prior, current));
148
+ }
149
+ /** The earlier records of this line, newest first — the "previous round" walk's
150
+ * candidate list (the nearest one with a non-empty findings projection wins). */
151
+ #priorOf(record) {
152
+ const earlier = this.#records
153
+ .filter((other) => _a.#earlierRound(other, record))
154
+ .sort((left, right) => left.cycle === right.cycle ? right.attempt - left.attempt : right.cycle - left.cycle);
155
+ for (const other of earlier) {
156
+ const findings = this.findingsOf(other);
157
+ if (findings.length > 0)
158
+ return findings;
159
+ }
160
+ return [];
161
+ }
162
+ /** Whether `other` precedes `record` on the line — the `(cycle, attempt)` order. */
163
+ static #earlierRound(other, record) {
164
+ return other.cycle === record.cycle
165
+ ? other.attempt < record.attempt
166
+ : other.cycle < record.cycle;
167
+ }
168
+ /** One record's carrier content, read ONCE — the path guard, the ownership judgment,
169
+ * the digest-checked read and the JSON parse all live here, so a second projection
170
+ * can never become a second read. */
171
+ #contentOf(record) {
172
+ const cached = this.#content.get(record);
173
+ if (cached !== undefined)
174
+ return cached;
175
+ const content = this.#readFresh(record);
176
+ this.#content.set(record, content);
177
+ return content;
178
+ }
179
+ /** The read behind `#contentOf` — zeroes for a record with no path or an overwritten
180
+ * one, and for bytes that hold no findings array or are not JSON. */
181
+ #readFresh(record) {
102
182
  const path = this.#pathOf(record);
103
- if (path === "" || !RoundRecords.ownerOf(this.#records, record, this.#pathOf))
104
- return 0;
183
+ if (path === "" || !RoundRecords.ownerOf(this.#records, record, this.#pathOf)) {
184
+ return EMPTY_CARRIER_CONTENT;
185
+ }
105
186
  const text = CarrierIntegrity.read(path, record.carrierDigest ?? null);
106
- return text === null ? 0 : LineCarriers.#findingsCountOf(text);
107
- }
108
- /** The `findings` array length of one carrier's bytes — zero when the payload holds
109
- * none (a work-plane carrier declares no findings) or is not JSON. */
110
- static #findingsCountOf(text) {
187
+ if (text === null)
188
+ return EMPTY_CARRIER_CONTENT;
111
189
  try {
112
190
  const value = JSON.parse(text);
113
191
  const findings = value?.findings;
114
- return Array.isArray(findings) ? findings.length : 0;
192
+ if (!Array.isArray(findings))
193
+ return EMPTY_CARRIER_CONTENT;
194
+ return { count: findings.length, findings: this.#schema.findingsOf(findings) };
115
195
  }
116
196
  catch {
117
- return 0;
197
+ return EMPTY_CARRIER_CONTENT;
118
198
  }
119
199
  }
120
200
  }
201
+ _a = LineCarriers;
202
+ /** The unreadable / findings-free content — a shared frozen value (no allocation per
203
+ * empty record). */
204
+ const EMPTY_CARRIER_CONTENT = { count: 0, findings: [] };
121
205
  /**
122
206
  * BoardView — the entry-document → board face. The identity index (`SlugIndex`)
123
207
  * is the ONLY node source: the entry document's declared `doc-type:` picks the
@@ -184,22 +268,70 @@ export class BoardView {
184
268
  * the program overall the identity's `program:` names. An entry that is itself
185
269
  * a plan contributes the plan and resolves its spec by the same slug. The
186
270
  * `programMissing` fact is the phase-spec hard gate: a `program:` that names no
187
- * on-disk overall (or no `program:` at all). Zero filename derivation. */
271
+ * on-disk overall (or no `program:` at all). Zero filename derivation and zero
272
+ * "first document": each slot is the index's SET answer (0 / 1 / n).
273
+ *
274
+ * Naming the entry document on argv (`cdd board --spec` / `--plan`) does NOT
275
+ * exempt its slot from the set: the entry's identity is still its slug, so a
276
+ * second same-class document makes that slot `many` and the row renders the
277
+ * marker plus every declared home. `own` survives only where the set cannot be
278
+ * asked — no legal slug, or an undeclared `doc-type:` that no class can hold. */
188
279
  static #nodeSources(index, entry) {
189
280
  const slug = BoardView.#validSlug(entry);
190
281
  const isPlan = entry.docType === "plan";
191
- const spec = slug === null ? (isPlan ? null : entry) : isPlan ? index.identityDoc(slug) : entry;
192
- const plan = isPlan ? entry : slug === null ? null : index.planOf(slug);
193
- const overall = spec?.docType === "phase-spec" && spec.program !== null
194
- ? index.overallOf(spec.program)
282
+ const own = { kind: "one", entry };
283
+ const spec = slug === null
284
+ ? isPlan
285
+ ? NO_DOC
286
+ : own
287
+ : entry.docType === null
288
+ ? own
289
+ : BoardView.#docSlotOf(index, slug, "identity");
290
+ const plan = slug === null ? (isPlan ? own : NO_DOC) : BoardView.#docSlotOf(index, slug, "plan");
291
+ const specEntry = BoardView.#slotEntry(spec);
292
+ const overall = specEntry?.docType === "phase-spec" && specEntry.program !== null
293
+ ? index.overallOf(specEntry.program)
195
294
  : null;
196
295
  return {
197
296
  spec,
198
297
  plan,
199
298
  overall,
200
- programMissing: spec !== null && BoardView.#programMissing(index, spec),
299
+ programMissing: specEntry !== null && BoardView.#programMissing(index, specEntry),
201
300
  };
202
301
  }
302
+ /** One doc slot — the index's SET answer for a class, filtered and then counted,
303
+ * never searched with `.find`. Two documents of the class are `many`, and every
304
+ * caller renders the marker and the whole set instead of choosing one. */
305
+ static #docSlotOf(index, slug, role) {
306
+ const docs = index
307
+ .docsOf(slug)
308
+ .filter((doc) => role === "plan" ? doc.docType === "plan" : doc.docType !== null && doc.docType !== "plan");
309
+ if (docs.length === 0)
310
+ return NO_DOC;
311
+ if (docs.length === 1)
312
+ return { kind: "one", entry: docs[0] };
313
+ return { kind: "many", found: docs };
314
+ }
315
+ /** The single document a slot carries — `null` for both the empty and the
316
+ * ambiguous arm: neither has ONE document to speak about. */
317
+ static #slotEntry(slot) {
318
+ return slot.kind === "one" ? slot.entry : null;
319
+ }
320
+ /** One document slot's violation marker — the single arm asks `#entryMark` (the ONE
321
+ * duplicate / identity judgment the pre-flight gate shares), and an ambiguous set
322
+ * renders the same `duplicated` marker the doc domain's `read` refuses on. */
323
+ static #slotMark(index, slot, role) {
324
+ if (slot.kind === "one")
325
+ return BoardView.#entryMark(index, slot.entry, role);
326
+ return slot.kind === "many" ? MARK_SLUG_DUPLICATED : null;
327
+ }
328
+ /** The cell of a doc row whose slug names MORE than one document of its class: the
329
+ * existing duplicate marker plus every path of the set. No version, no status, no
330
+ * rounds — those are facts of ONE document, and this identity has none. */
331
+ static #duplicateDocLine(label, found) {
332
+ const paths = found.map((doc) => doc.rel).join(" · ");
333
+ return ` ${label.padEnd(LABEL_WIDTH)}${MARK_SLUG_DUPLICATED} ${paths}`;
334
+ }
203
335
  /** The entry's valid slug — the workspace key, or null when the declaration is
204
336
  * absent or illegal (an illegal value is a violation, never a directory name). */
205
337
  static #validSlug(entry) {
@@ -235,7 +367,7 @@ export class BoardView {
235
367
  * `overall` line). The ledger is the one that OWNS `progress` — a node board reads
236
368
  * the overall line from the program's workspace, never the node's. */
237
369
  static #lineOf(label, key, entry, progress, ledger) {
238
- const rounds = BoardView.#rowRounds(progress, key, entry?.docType ?? null);
370
+ const rounds = BoardView.#rowRounds(progress, key);
239
371
  return {
240
372
  label,
241
373
  version: entry?.version ?? null,
@@ -244,6 +376,8 @@ export class BoardView {
244
376
  rounds,
245
377
  carriers: LineCarriers.ofLedger(ledger, key, key, rounds),
246
378
  marker: null,
379
+ type: key,
380
+ key,
247
381
  };
248
382
  }
249
383
  /** summaryCell(records) — the line's aggregated rounds cell (P24 §12): the SUCCESS
@@ -306,9 +440,17 @@ export class BoardView {
306
440
  * fact. A record that resolves no carrier (a legacy row, or a work-plane round whose
307
441
  * carrier declares no findings) contributes zero. */
308
442
  static #summaryToken(verb, body, mark, run, carriers) {
443
+ // Rule zero (class-size limit): this file is well past the limit and predates it —
444
+ // splitting it is P39's work (design spec D95 ②), not this round's.
309
445
  const findings = run.reduce((total, record) => total + carriers.countOf(record), 0);
310
446
  const suffix = findings === 0 ? "" : `+${findings}`;
311
- return `${verb} ${body} ${mark}${suffix}`;
447
+ // P37 §5.2 — the downgrade note rides the SAME token, after its `+N`: the mark when
448
+ // a row owes its reason, the stated reason when the row carries one (both composed
449
+ // by the criteria module's ONE note). One token, one line, no new entry — the note is
450
+ // display, never a finding.
451
+ const notes = run.flatMap((record) => carriers.regradeNoteOf(record) ?? []);
452
+ const note = notes.length === 0 ? "" : ` ${notes.join(REGRADE_NOTE_SEPARATOR)}`;
453
+ return `${verb} ${body} ${mark}${suffix}${note}`;
312
454
  }
313
455
  /** attemptSuffix(record) — the re-dispatch superscript: `attempt === 1` renders
314
456
  * nothing (an `a1` never appears), otherwise `a{attempt}`. */
@@ -432,7 +574,7 @@ export class BoardView {
432
574
  // the render face (spec §5.3) — the entry document → board layout + next render
433
575
  // -------------------------------------------------------------------------
434
576
  /** render(readTable, plan, index, entry, repoRoot, words, host, channels, holding,
435
- * next) — the entry document's board (spec §3.1): the entry's declared `doc-type:`
577
+ * next, projection) — the entry document's board (spec §3.1): the declared `doc-type:`
436
578
  * picks the shape — `overall` → the program board, every other type → the node
437
579
  * board. The index supplies every related node (`program:` → overall; same slug →
438
580
  * spec / plan), so no filename grammar participates. `next` is the INJECTED
@@ -451,8 +593,12 @@ export class BoardView {
451
593
  * the wave segment reads. A single-document board is a table of length 1 — its one
452
594
  * row is the argv face's read (solo `--plan`) or the derived face's (`--spec`).
453
595
  * The board therefore holds no plan-reading seam of its own: the ONE read point is
454
- * the injected `PlanSource`, and a value is never re-read here. */
455
- static render(readTable, plan, index, entry, repoRoot, words, host, channels = {}, holding = { kind: "absent" }, next = null) {
596
+ * the injected `PlanSource`, and a value is never re-read here.
597
+ *
598
+ * `projection` is the artifact observation's ONE input (the matrix seam plus the
599
+ * `--artifacts` switch) — the two halves travel together so neither can arrive
600
+ * without the other. */
601
+ static render(readTable, plan, index, entry, repoRoot, words, host, channels = {}, holding = { kind: "absent" }, next = null, projection = NO_ARTIFACTS) {
456
602
  const lines = [`cdd board: ${entry.slug ?? "(none)"}`, ""];
457
603
  // The repo-basis value object — constructed ONCE at this boundary, the ONE
458
604
  // conversion exit the doc cells and the `next:` render normalize their embedded
@@ -461,12 +607,12 @@ export class BoardView {
461
607
  // one form).
462
608
  const root = new RepoRoot(repoRoot);
463
609
  const exitCode = entry.docType === "overall"
464
- ? BoardView.#programBoard(readTable, plan, lines, index, entry, root, words)
610
+ ? BoardView.#programBoard(readTable, plan, lines, index, entry, root, words, projection)
465
611
  : BoardView.#nodeBoard(
466
612
  // A node board is ONE document: the caller's single row. An empty table
467
613
  // means no document was read at all — the seam's own undeclared value is
468
614
  // that read result (no file is opened, so this mints no second read).
469
- readTable[0] ?? plan.readFor(null), plan, lines, index, entry, root, words, host, channels, holding, next);
615
+ readTable[0] ?? plan.readFor(null), plan, lines, index, entry, root, words, host, channels, holding, next, projection);
470
616
  lines.push("", PROGRESS_LEGEND.board);
471
617
  return { lines, exitCode };
472
618
  }
@@ -479,14 +625,18 @@ export class BoardView {
479
625
  * ONE plan value (spec §2.1): the plan row, the wave row and the `! no-spec`
480
626
  * spec row all take their facts from it, so the document the board names and
481
627
  * the document it read are one fact. */
482
- static #nodeBoard(read, plan, lines, index, entry, root, words, host, channels, holding, next) {
628
+ static #nodeBoard(read, plan, lines, index, entry, root, words, host, channels, holding, next, projection) {
483
629
  const repoRoot = root.absolute;
484
630
  const sources = BoardView.#nodeSources(index, entry);
485
631
  const nodeSlug = BoardView.#validSlug(entry);
486
- const ledger = nodeSlug === null ? null : BoardView.#ledgerOf(plan, nodeSlug, repoRoot);
632
+ const nodeSeat = nodeSlug === null ? null : BoardView.#ledgerOf(plan, nodeSlug, repoRoot, projection.registry);
633
+ const ledger = nodeSeat?.ledger ?? null;
487
634
  const progress = ledger?.readProgress() ?? null;
488
635
  const overallSlug = BoardView.#validSlug(sources.overall);
489
- const overallLedger = overallSlug === null ? null : BoardView.#ledgerOf(plan, overallSlug, repoRoot);
636
+ const overallSeat = overallSlug === null
637
+ ? null
638
+ : BoardView.#ledgerOf(plan, overallSlug, repoRoot, projection.registry);
639
+ const overallLedger = overallSeat?.ledger ?? null;
490
640
  const overallProgress = overallLedger?.readProgress() ?? null;
491
641
  // The tree's dispatch fact + the node workspace's orphan drafts + the node's
492
642
  // crashed rounds render before the line rows (a reader answers "is anyone working
@@ -505,23 +655,25 @@ export class BoardView {
505
655
  // identity breakage outranks the read value, so neither the plan row nor the spec
506
656
  // row asks a `PlanRead` accessor, and no `! no-spec` literal (the orphan fold or
507
657
  // the degraded wave row) can appear beside a broken identity.
508
- const specMark = BoardView.#entryMark(index, sources.spec, "identity") ??
658
+ const specMark = BoardView.#slotMark(index, sources.spec, "identity") ??
509
659
  (sources.programMissing ? MARK_PROGRAM_MISSING : null);
510
- const planMark = BoardView.#entryMark(index, sources.plan, "plan");
660
+ const planMark = BoardView.#slotMark(index, sources.plan, "plan");
661
+ const specEntry = BoardView.#slotEntry(sources.spec);
662
+ const planEntry = BoardView.#slotEntry(sources.plan);
511
663
  const planIdentityClean = planMark === null;
512
664
  const identityClean = planIdentityClean && specMark === null;
513
665
  const docRows = [
514
666
  {
515
667
  label: "overall",
516
- entry: sources.overall,
668
+ slot: sources.overall === null ? NO_DOC : { kind: "one", entry: sources.overall },
517
669
  line: BoardView.#lineOf("overall", "overall", sources.overall, overallProgress, overallLedger),
518
670
  mark: BoardView.#entryMark(index, sources.overall, "identity"),
519
671
  override: null,
520
672
  },
521
673
  {
522
674
  label: "spec",
523
- entry: sources.spec,
524
- line: BoardView.#lineOf("spec", BoardView.#lineWordOf(sources.spec), sources.spec, progress, ledger),
675
+ slot: sources.spec,
676
+ line: BoardView.#lineOf("spec", BoardView.#lineWordOf(specEntry), specEntry, progress, ledger),
525
677
  mark: specMark,
526
678
  // The reverse-lookup orphan's spec row (spec §2.7 ①): the identity-clean
527
679
  // row bypasses `#entryMark` / `#docCell` accounting — landing in the mark
@@ -530,24 +682,29 @@ export class BoardView {
530
682
  },
531
683
  {
532
684
  label: "plan",
533
- entry: sources.plan,
534
- line: BoardView.#lineOf("plan", "plan", sources.plan, progress, ledger),
685
+ slot: sources.plan,
686
+ line: BoardView.#lineOf("plan", "plan", planEntry, progress, ledger),
535
687
  mark: planMark,
536
- override: BoardView.#planCellOf(read, sources.plan, planMark, words),
688
+ override: BoardView.#planCellOf(read, planEntry, planMark, words),
537
689
  },
538
690
  ];
539
691
  // The doc-name column is fixed-width: every name is padded to the widest one, so
540
692
  // the version column aligns down the block (spec §5.3).
541
- const nameWidth = Math.max(0, ...docRows
542
- .filter((row) => row.entry !== null)
543
- .map((row) => path.basename(row.entry.path).length));
693
+ const nameWidth = Math.max(0, ...docRows.flatMap((row) => row.slot.kind === "one" ? [path.basename(row.slot.entry.path).length] : []));
544
694
  let blocked = false;
545
695
  for (const row of docRows) {
696
+ // An ambiguous set is its own row: the marker plus every path, never one
697
+ // document's header facts (spec §2.3 — the read face answers a set with a set).
698
+ if (row.slot.kind === "many") {
699
+ lines.push(BoardView.#duplicateDocLine(row.label, row.slot.found));
700
+ blocked = true;
701
+ continue;
702
+ }
546
703
  if (row.override !== null) {
547
704
  lines.push(` ${row.label.padEnd(LABEL_WIDTH)}${row.override}`.trimEnd());
548
705
  continue;
549
706
  }
550
- const cell = BoardView.#docCell(row.entry, row.line, nameWidth, row.mark);
707
+ const cell = BoardView.#docCell(BoardView.#slotEntry(row.slot), row.line, nameWidth, row.mark);
551
708
  lines.push(` ${row.label.padEnd(LABEL_WIDTH)}${cell.text}`.trimEnd());
552
709
  blocked ||= cell.blocked;
553
710
  }
@@ -560,11 +717,13 @@ export class BoardView {
560
717
  // render, so a reader can tell a missing plan from a plan that does not read.
561
718
  const specAbsent = read.orphan()?.cause === "spec-absent";
562
719
  const degraded = specAbsent && !planIdentityClean ? null : read.degradedWaveRow(words);
720
+ // The wave segment is derived ONCE — the rendered rows and the `art:` projection's
721
+ // record set read the same lines (never a second derivation over the same read).
722
+ const waves = degraded === null ? BoardView.#waveLines(read, progress, ledger) : [];
563
723
  if (degraded !== null) {
564
724
  lines.push(` ${"wave".padEnd(LABEL_WIDTH)}${degraded}`);
565
725
  }
566
726
  else {
567
- const waves = BoardView.#waveLines(read, progress, ledger);
568
727
  if (waves.length === 0) {
569
728
  lines.push(` ${"wave".padEnd(LABEL_WIDTH)}(none)`);
570
729
  }
@@ -585,7 +744,7 @@ export class BoardView {
585
744
  // (`Ledger#lineStateAt`, identity document = the plan): a drifted plan reopens the
586
745
  // branch face, so the mark can never print `✔ closed` while `next:` names the
587
746
  // review the gate accepts — the reopened line renders as the CURRENT face (`▶`).
588
- const branchState = ledger?.lineStateAt("branch", "branch", sources.plan?.path ?? null) ?? "open";
747
+ const branchState = ledger?.lineStateAt("branch", "branch", planEntry?.path ?? null) ?? "open";
589
748
  const branchMark = branchState === "closed"
590
749
  ? `${PROGRESS_MARKERS.done} closed`
591
750
  : branchState === "reopened"
@@ -593,6 +752,23 @@ export class BoardView {
593
752
  : `${PROGRESS_MARKERS.pending} open`;
594
753
  const branchRounds = BoardView.summaryCell(branchLine.rounds, branchLine.carriers);
595
754
  lines.push(` ${"branch".padEnd(LABEL_WIDTH)}${branchMark}${branchRounds === "" ? "" : ` ${branchRounds}`}`.trimEnd());
755
+ // The `art:` fact block — the artifact inventory this node's rounds resolve to,
756
+ // rendered AFTER the line rows and BEFORE `next:` / `reason:` (the two last rows
757
+ // stay last, spec §2.6). A healthy tree adds zero bytes: only a `misplaced` /
758
+ // `invalid` judgment prints, and `--artifacts` alone opens the full inventory. The
759
+ // block never joins the tail counts — the findings axis and the artifact axis are
760
+ // two axes.
761
+ const artifactRows = BoardView.#artifactRows(BoardView.#artifactScopes({
762
+ docLines: docRows.map((row) => row.line),
763
+ waves,
764
+ branchLine,
765
+ nodeSeat,
766
+ overallSeat,
767
+ }), projection);
768
+ if (artifactRows.length > 0) {
769
+ lines.push("");
770
+ lines.push(...artifactRows);
771
+ }
596
772
  lines.push("");
597
773
  if (next === null) {
598
774
  lines.push(" next: (none)");
@@ -609,11 +785,21 @@ export class BoardView {
609
785
  * never participates in next, spec §6.5). The phase set derives from the ONE
610
786
  * index (`program:` grouping — no overall child-list array). A phase row's primary
611
787
  * key is its `slug:`, annotated with the truncated `title:`; any overall/phase
612
- * violation renders its marker and exits 2 (spec §3.1 — zero silent fallback). */
613
- static #programBoard(readTable, plan, lines, index, entry, root, words) {
788
+ * violation renders its marker and exits 2 (spec §3.1 — zero silent fallback).
789
+ *
790
+ * The `art:` projection is the SAME one the node board renders (spec §2.4 · §2.6):
791
+ * the overall line is dispatched from the program workspace, so its own review
792
+ * rounds are the rounds a docs-fix gate judges, and the board must show that
793
+ * judgment before the dispatch. The scope binds the overall line to the program
794
+ * seat — the seat this render already holds — and `--artifacts` therefore opens the
795
+ * same inventory view here as on a node board (never a silent no-op). */
796
+ static #programBoard(readTable, plan, lines, index, entry, root, words, projection) {
614
797
  const repoRoot = root.absolute;
615
798
  const overallSlug = BoardView.#validSlug(entry);
616
- const ledger = overallSlug === null ? null : BoardView.#ledgerOf(plan, overallSlug, repoRoot);
799
+ const seat = overallSlug === null
800
+ ? null
801
+ : BoardView.#ledgerOf(plan, overallSlug, repoRoot, projection.registry);
802
+ const ledger = seat?.ledger ?? null;
617
803
  const overallLine = BoardView.#lineOf("overall", "overall", entry, ledger?.readProgress() ?? null, ledger);
618
804
  const overallDoc = BoardView.#docCell(entry, overallLine, path.basename(entry.path).length, BoardView.#entryMark(index, entry, "identity"));
619
805
  lines.push(` ${"overall".padEnd(LABEL_WIDTH)}${overallDoc.text}`);
@@ -630,15 +816,18 @@ export class BoardView {
630
816
  throw new Error("cdd: the board's per-phase plan table is shorter than its phase list");
631
817
  const read = readTable[pos];
632
818
  const phaseSlug = BoardView.#validSlug(phase);
633
- const phaseLedger = phaseSlug === null ? null : BoardView.#ledgerOf(plan, phaseSlug, repoRoot);
819
+ const phaseLedger = phaseSlug === null
820
+ ? null
821
+ : BoardView.#ledgerOf(plan, phaseSlug, repoRoot, projection.registry).ledger;
634
822
  const phaseProgress = phaseLedger?.readProgress() ?? null;
635
823
  const specLine = BoardView.#lineOf("spec", "phase-spec", phase, phaseProgress, phaseLedger);
636
- const planEntry = phaseSlug === null ? null : index.planOf(phaseSlug);
824
+ const planSlot = phaseSlug === null ? NO_DOC : BoardView.#docSlotOf(index, phaseSlug, "plan");
825
+ const planEntry = BoardView.#slotEntry(planSlot);
637
826
  const planLine = BoardView.#lineOf("plan", "plan", planEntry, phaseProgress, phaseLedger);
638
827
  const branchLine = BoardView.#roundsLine("branch", "branch", phaseProgress, phaseLedger);
639
828
  const mark = BoardView.#entryMark(index, phase, "identity") ??
640
829
  (BoardView.#programMissing(index, phase) ? MARK_PROGRAM_MISSING : null);
641
- const planMark = BoardView.#entryMark(index, planEntry, "plan");
830
+ const planMark = BoardView.#slotMark(index, planSlot, "plan");
642
831
  blocked ||= mark !== null || planMark !== null;
643
832
  const status = mark ?? phase.status ?? "Pending";
644
833
  // The phase's wave summary token (spec §5.3): the wave segment's first wave
@@ -648,10 +837,15 @@ export class BoardView {
648
837
  // `""` only for a true undeclared phase, and null hands the healthy cell back
649
838
  // to today's derivation.
650
839
  const waveCell = read.cell(words) ?? BoardView.#waveCellOf(read, phaseProgress, phaseLedger);
840
+ // The plan cell of a phase whose slug names TWO plans: the marker plus both
841
+ // paths, never the first plan's summary (spec §2.3 — a set is answered by a set).
842
+ const planCell = planSlot.kind === "many"
843
+ ? [MARK_SLUG_DUPLICATED, planSlot.found.map((doc) => doc.rel).join(" · ")].join(" ")
844
+ : BoardView.summaryCell(planLine.rounds, planLine.carriers);
651
845
  const parts = [];
652
846
  const cells = [
653
847
  ["spec", BoardView.summaryCell(specLine.rounds, specLine.carriers)],
654
- ["plan", BoardView.summaryCell(planLine.rounds, planLine.carriers)],
848
+ ["plan", planCell],
655
849
  ["wave", waveCell],
656
850
  ["branch", BoardView.summaryCell(branchLine.rounds, branchLine.carriers)],
657
851
  ];
@@ -662,6 +856,15 @@ export class BoardView {
662
856
  const note = BoardView.#titleNote(phase.title);
663
857
  lines.push(` phase ${phase.slug ?? "(none)"} ${status}${tail === "" ? "" : ` ${tail}`}${note === "" ? "" : ` title: ${note}`}`);
664
858
  }
859
+ // The `art:` fact block, after the phase rows and before the rows that stay last
860
+ // (spec §2.6). One scope: the overall line, bound to the program seat — a phase's
861
+ // rounds belong to the phase's own board, exactly as a node board reads the
862
+ // program line through the program seat alone.
863
+ const artifactRows = BoardView.#artifactRows(seat === null ? [] : [{ lines: [overallLine], seat }], projection);
864
+ if (artifactRows.length > 0) {
865
+ lines.push("");
866
+ lines.push(...artifactRows);
867
+ }
665
868
  lines.push("");
666
869
  lines.push(" next: done");
667
870
  return blocked ? 2 : 0;
@@ -747,16 +950,146 @@ export class BoardView {
747
950
  cells.push(rounds);
748
951
  return { text: cells.join(" "), blocked: false };
749
952
  }
953
+ // -------------------------------------------------------------------------
954
+ // the artifact projection (spec §2.6) — the matrix's judgment as an `art:` fact row
955
+ // -------------------------------------------------------------------------
956
+ /** The `art:` projection's scopes — the node's own lines bound to the node seat and
957
+ * the program's overall line bound to the program seat. The board OBSERVES names;
958
+ * it never mints one: every observed round's carrier path comes from the ledger's
959
+ * ONE accessor and every judgment from `ArtifactReads`. One record in, one scope set
960
+ * out (the two seats are told apart by name, never by argument position). */
961
+ static #artifactScopes(input) {
962
+ const scopes = [];
963
+ const overall = input.docLines[0];
964
+ if (input.overallSeat !== null && overall !== undefined) {
965
+ scopes.push({ lines: [overall], seat: input.overallSeat });
966
+ }
967
+ if (input.nodeSeat !== null) {
968
+ scopes.push({
969
+ lines: [...input.docLines.slice(1), ...input.waves, input.branchLine],
970
+ seat: input.nodeSeat,
971
+ });
972
+ }
973
+ return scopes;
974
+ }
975
+ /** The `art:` fact rows — one observed REVIEW round per record of each scope's lines,
976
+ * in `(cycle, attempt)` order. The observed set is the record sequence, never the
977
+ * workspace's name list: a `*.rulings.json` no record claims stays an `orphan:`
978
+ * observation and never enters this block (one name, one face). The judgment is the
979
+ * dispatch gate's own kind — `rulings` — read through the frame-free seam, so the
980
+ * board composes nothing a gate would compose differently.
981
+ *
982
+ * Default (no `--artifacts`): only the anomalous rounds render, so a healthy tree
983
+ * adds zero bytes. `--artifacts` opens the whole inventory: one row per observed
984
+ * round, one column per kind. */
985
+ static #artifactRows(scopes, projection) {
986
+ const artifacts = projection.registry;
987
+ if (artifacts === null)
988
+ return [];
989
+ const reads = (seat) => new ArtifactReads(artifacts, seat.workspace);
990
+ const observed = scopes.flatMap((scope) => BoardView.#observedOf(scope, artifacts, reads(scope.seat)));
991
+ observed.sort((left, right) => left.cycle - right.cycle || left.attempt - right.attempt);
992
+ return observed.flatMap((entry) => BoardView.#artifactBlockOf(entry, projection.showAll));
993
+ }
994
+ /** One scope's observed review rounds — the round records carrying a resolvable
995
+ * carrier, each read through the seam. A tampered carrier (a digest mismatch) is the
996
+ * `invalid` arm carrying the integrity message, never a thrown board. */
997
+ static #observedOf(scope, artifacts, reads) {
998
+ const basis = scope.seat.workspace.root.basis;
999
+ const observed = [];
1000
+ for (const line of scope.lines) {
1001
+ for (const record of line.rounds) {
1002
+ if (record.op !== "review")
1003
+ continue;
1004
+ const carrier = scope.seat.ledger.carrierPathOf(line.type, line.key, record);
1005
+ if (carrier === "")
1006
+ continue;
1007
+ observed.push({
1008
+ line: BoardView.#artifactLineOf(artifacts, carrier, line.type),
1009
+ kind: "rulings",
1010
+ cycle: record.cycle,
1011
+ attempt: record.attempt,
1012
+ read: BoardView.#artifactReadOf(reads, carrier, record.carrierDigest ?? null),
1013
+ relName: (name) => basis.relativize(scope.seat.workspace.resolve(name)),
1014
+ relPath: (value) => basis.relativize(value),
1015
+ });
1016
+ }
1017
+ }
1018
+ return observed;
1019
+ }
1020
+ /** The observed round's line word — the carrier's OWN attributed identity (the
1021
+ * reviewed round), falling back to the rendering line's word for a name the matrix
1022
+ * cannot place. */
1023
+ static #artifactLineOf(artifacts, carrier, fallback) {
1024
+ const attributed = artifacts.attribute(path.basename(carrier));
1025
+ return attributed !== null && attributed.identity.domain === "round"
1026
+ ? attributed.identity.line
1027
+ : fallback;
1028
+ }
1029
+ /** One composed read, with the integrity refusal folded into the `invalid` arm: a
1030
+ * tampered carrier is a fact the board reports, never a crash of the read face. */
1031
+ static #artifactReadOf(reads, carrier, digest) {
1032
+ try {
1033
+ return reads.read("rulings", carrier, digest);
1034
+ }
1035
+ catch (raw) {
1036
+ if (!(raw instanceof CarrierMismatchError))
1037
+ throw raw;
1038
+ return { read: { kind: "invalid", path: "", reason: raw.message }, rulings: [] };
1039
+ }
1040
+ }
1041
+ /** One observed round's `art:` block — the fact row plus its continuation lines. The
1042
+ * default face prints anomalies alone; `--artifacts` prints every observed round and
1043
+ * names its coordinate, so a troubleshooting view is one row per round while the
1044
+ * daily view keeps its bytes. */
1045
+ static #artifactBlockOf(entry, showAll) {
1046
+ const read = entry.read.read;
1047
+ const anomalous = read.kind === "misplaced" || read.kind === "invalid";
1048
+ if (!showAll && !anomalous)
1049
+ return [];
1050
+ const coordinate = showAll ? ` · c${entry.cycle}·a${entry.attempt}` : "";
1051
+ const arm = anomalous ? `! ${read.kind}` : read.kind;
1052
+ const header = ` ${"art:".padEnd(LABEL_WIDTH)}${entry.line} · ${entry.kind}${coordinate} ${arm}`;
1053
+ return [header, ...BoardView.#artifactFactsOf(entry, read)];
1054
+ }
1055
+ /** One `art:` block's continuation lines — the same facts the dispatch gate's
1056
+ * `derived:` / `found:` report prints, on the board's own 9-column continuation
1057
+ * shape. A healthy round carries none.
1058
+ *
1059
+ * The labels come from `ARTIFACT_FACT_LABELS`, NOT from `Words#artifactIdentity`:
1060
+ * the two faces are two pinned contracts with different bytes — §2.4 fixes the
1061
+ * gate's rows as ` derived: <value>` (colon, two-space column) while §2.6 fixes
1062
+ * the board's as ` derived <value>` (no colon, the board's own
1063
+ * continuation column). Sharing a label source would force one contract's bytes
1064
+ * into the other; the words are therefore deliberately re-declared here once and
1065
+ * pinned by the board's byte assertions. */
1066
+ static #artifactFactsOf(entry, read) {
1067
+ const labels = ARTIFACT_FACT_LABELS;
1068
+ const value = (key, fact) => ` ${key.padEnd(LABEL_WIDTH)}${fact}`;
1069
+ if (read.kind === "misplaced") {
1070
+ const found = read.found.map((name) => entry.relName(name)).join(" · ");
1071
+ return [value(labels.derived, entry.relName(read.derived)), value(labels.found, found)];
1072
+ }
1073
+ if (read.kind === "invalid") {
1074
+ const derived = read.path === "" ? [] : [value(labels.derived, entry.relPath(read.path))];
1075
+ return [...derived, value(labels.reason, read.reason)];
1076
+ }
1077
+ return [];
1078
+ }
750
1079
  /** The node's ledger — the progress.json read face the render's closure/next
751
1080
  * derivation consumes (each node reads its OWN workspace). The plan read seam is
752
1081
  * the caller's per-command instance, threaded down unchanged: the board never
753
1082
  * mints a second `PlanSource`. */
754
- static #ledgerOf(plan, nodeSlug, repoRoot) {
1083
+ static #ledgerOf(plan, nodeSlug, repoRoot, artifacts = null) {
755
1084
  const root = new WorkspaceRoot(repoRoot, ENGINE_RUNTIME.handoffNamespace.workspaceRoot);
756
- return new Ledger(new Workspace(root, nodeSlug), new ConfigLoader(), plan);
1085
+ // ONE workspace instance per node: the ledger resolves names inside it and the
1086
+ // `art:` projection's read seam takes the SAME instance (`ArtifactReads` binds its
1087
+ // base at construction), so a board never observes two spellings of one directory.
1088
+ const workspace = new Workspace(root, nodeSlug);
1089
+ return { ledger: new Ledger(workspace, new ConfigLoader(), plan, artifacts), workspace };
757
1090
  }
758
- /** pipelineFacts(read, plan, index, entry, root) — the board's FACTS about the
759
- * pipeline (spec §5.2): the node's ledger and the pipeline frontier's declared
1091
+ /** pipelineFacts(read, plan, index, entry, root, projection) — the board's FACTS
1092
+ * about the pipeline (spec §5.2): the node's ledger and the pipeline frontier's declared
760
1093
  * input (the spec word and path, the plan path, the plan read). The board reports
761
1094
  * facts only — the per-face observations and the four face-order rules live in the
762
1095
  * session plane's `PipelineFrontier`. Null when the node holds no legal slug (no
@@ -765,22 +1098,22 @@ export class BoardView {
765
1098
  * `read` is the caller's ONE plan read (the same `PlanSource` instance): the
766
1099
  * frontier's graph input is the value's own `graph()`, and the declared `planPath`
767
1100
  * is that same value's `stationPath()` — the document the board read and the path
768
- * the frontier receives are ONE fact, with no fallback to `index.planOf(slug)`.
1101
+ * the frontier receives are ONE fact, with no fallback to a second plan lookup.
769
1102
  * The wave segment reads the same value through `#waveLines`; the board has no
770
1103
  * second plan read point. */
771
- static pipelineFacts(read, plan, index, entry, root) {
1104
+ static pipelineFacts(read, plan, index, entry, root, projection = NO_ARTIFACTS) {
772
1105
  const nodeSlug = BoardView.#validSlug(entry);
773
1106
  if (nodeSlug === null)
774
1107
  return null;
775
- const ledger = BoardView.#ledgerOf(plan, nodeSlug, root.absolute);
1108
+ const ledger = BoardView.#ledgerOf(plan, nodeSlug, root.absolute, projection.registry).ledger;
776
1109
  const sources = BoardView.#nodeSources(index, entry);
777
- const specPath = sources.spec?.path ?? null;
1110
+ const specPath = BoardView.#slotEntry(sources.spec)?.path ?? null;
778
1111
  // The path the frontier receives IS the path of the document this read opened —
779
1112
  // never a second index-derived candidate that could name another file.
780
1113
  const planPath = read.stationPath();
781
1114
  // The identity line's OWN word — the document's DECLARED `doc-type:` — keys the
782
1115
  // line and names the pipeline station (`single-spec` closes onto its `done` row).
783
- const specType = BoardView.#lineWordOf(sources.spec);
1116
+ const specType = BoardView.#lineWordOf(BoardView.#slotEntry(sources.spec));
784
1117
  return {
785
1118
  ledger,
786
1119
  input: { specType, specPath, planPath, plan: read },
@@ -797,16 +1130,18 @@ export class BoardView {
797
1130
  rounds,
798
1131
  carriers: LineCarriers.ofLedger(ledger, key, key, rounds),
799
1132
  marker: null,
1133
+ type: key,
1134
+ key,
800
1135
  };
801
1136
  }
802
1137
  /** The node's round RECORDS for one key — read through the ledger's ONE row lookup
803
- * (`Ledger.rowFor`: the retired `spec` row reads as the line its workspace DECLARES)
804
- * and the ONE record normalizer (`RoundRecords.of`, legacy forms folded); the
1138
+ * (`Ledger.rowFor`, literal: a retired `spec` row answers no document word) and the
1139
+ * ONE record normalizer (`RoundRecords.of`, legacy COUNT forms folded); the
805
1140
  * aggregation and the judgement glyphs read these records, never a pre-grouped cycle
806
1141
  * map. Failed rounds stay on the board (they consumed an identity slot); an absent row
807
1142
  * yields an empty list. */
808
- static #rowRounds(progress, key, identity = null) {
809
- const row = progress === null ? undefined : Ledger.rowFor(progress, key, identity);
1143
+ static #rowRounds(progress, key) {
1144
+ const row = progress === null ? undefined : Ledger.rowFor(progress, key);
810
1145
  return RoundRecords.of(row);
811
1146
  }
812
1147
  /** The node's wave segment — one line per derived wave (its ✔/▶/○ marker rides the
@@ -841,6 +1176,8 @@ export class BoardView {
841
1176
  rounds,
842
1177
  carriers: LineCarriers.ofLedger(ledger, "wave", key, rounds),
843
1178
  marker,
1179
+ type: "wave",
1180
+ key,
844
1181
  };
845
1182
  });
846
1183
  }
@@ -859,16 +1196,22 @@ export class BoardNext {
859
1196
  /** The board's ONE `NextHop` — null when the entry holds no legal slug (no
860
1197
  * workspace to observe), when the board is the program board (cross-phase never
861
1198
  * participates in next, spec §6.5), or when the plan read carries no evidence to
862
- * route on (spec §2.3): an `unreadable` plan and a `spec-absent` orphan
863
- * short-circuit to the existing hop-less shape (` next: (none)`, no `reason:`
864
- * row). The predicate is the SAME pair §2.3 uses, never a third condition;
865
- * `undeclared` is NOT in it ("spec written, no plan yet" is the standing
866
- * `kairos:cdd-plan` route) and `slug-absent` is not either (the identity channel
867
- * owns its exit code). */
868
- static of(read, plan, index, entry, root) {
1199
+ * route on (spec §2.3): an `unreadable` plan, a `spec-absent` orphan and the
1200
+ * `duplicated` set short-circuit to the existing hop-less shape (` next:
1201
+ * (none)`, no `reason:` row). The predicate is the SAME pair §2.3 uses, never a
1202
+ * third condition; `undeclared` is NOT in it ("spec written, no plan yet" is the
1203
+ * standing `kairos:cdd-plan` route — and so is the undecided read, whose board
1204
+ * bytes are today's) and `slug-absent` is not either (the identity channel owns
1205
+ * its exit code). The duplicated set is not: two plans answer no single
1206
+ * document, so the plan route may not be printed (§2.7 (d)). */
1207
+ static of(read, plan, index, entry, root, projection = NO_ARTIFACTS) {
1208
+ if (read.kind === "duplicated")
1209
+ return null;
869
1210
  if (read.kind === "unreadable" || read.orphan()?.cause === "spec-absent")
870
1211
  return null;
871
- const facts = entry.docType === "overall" ? null : BoardView.pipelineFacts(read, plan, index, entry, root);
1212
+ const facts = entry.docType === "overall"
1213
+ ? null
1214
+ : BoardView.pipelineFacts(read, plan, index, entry, root, projection);
872
1215
  return facts === null ? null : BoardNext.#hopOf(facts, root);
873
1216
  }
874
1217
  /** The session plane's ONE assembly, called with the board's facts and the face