@oscaner-skills/cdd-engine 1.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/README.md +11 -10
  2. package/README.zh-CN.md +11 -10
  3. package/package.json +16 -22
  4. package/src-next/__tests__/bin.test.ts +128 -0
  5. package/src-next/__tests__/dead-decl.guard.test.ts +39 -0
  6. package/src-next/__tests__/floor.guard.test.ts +69 -0
  7. package/src-next/__tests__/issue-body.guard.test.ts +66 -0
  8. package/src-next/__tests__/phase-suffix.guard.test.ts +72 -0
  9. package/src-next/__tests__/smoke.integration.test.ts +185 -0
  10. package/src-next/__tests__/support/strip-comments.ts +99 -0
  11. package/src-next/__tests__/zero-dep.test.ts +94 -0
  12. package/src-next/bin.ts +61 -0
  13. package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +256 -0
  14. package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +165 -0
  15. package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +190 -0
  16. package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +106 -0
  17. package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +240 -0
  18. package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +165 -0
  19. package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +190 -0
  20. package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +100 -0
  21. package/src-next/contract/__tests__/declare.test.ts +481 -0
  22. package/src-next/contract/__tests__/doc.test.ts +527 -0
  23. package/src-next/contract/__tests__/dockey.guard.test.ts +58 -0
  24. package/src-next/contract/__tests__/edge-conditions.guard.test.ts +81 -0
  25. package/src-next/contract/__tests__/frontmatter.test.ts +164 -0
  26. package/src-next/contract/__tests__/judge.test.ts +1111 -0
  27. package/src-next/contract/__tests__/lint.test.ts +324 -0
  28. package/src-next/contract/__tests__/project.test.ts +460 -0
  29. package/src-next/contract/__tests__/structure-pin.test.ts +186 -0
  30. package/src-next/contract/__tests__/translate.test.ts +96 -0
  31. package/src-next/contract/declare.ts +1071 -0
  32. package/src-next/contract/doc.ts +816 -0
  33. package/src-next/contract/frontmatter.ts +233 -0
  34. package/src-next/contract/home-extractors.ts +397 -0
  35. package/src-next/contract/invariants.ts +1413 -0
  36. package/src-next/contract/judge.ts +151 -0
  37. package/src-next/contract/lint.ts +239 -0
  38. package/src-next/contract/project.ts +656 -0
  39. package/src-next/contract/skill-anatomy.ts +301 -0
  40. package/src-next/contract/translate.ts +113 -0
  41. package/src-next/face/__tests__/board-view.test.ts +1151 -0
  42. package/src-next/face/__tests__/capsule.test.ts +300 -0
  43. package/src-next/face/__tests__/channel-closure.guard.test.ts +129 -0
  44. package/src-next/face/__tests__/cli.test.ts +4897 -0
  45. package/src-next/face/__tests__/face.test.ts +289 -0
  46. package/src-next/face/__tests__/graph-view.test.ts +61 -0
  47. package/src-next/face/__tests__/host.test.ts +24 -0
  48. package/src-next/face/__tests__/install-rows.guard.test.ts +58 -0
  49. package/src-next/face/__tests__/negation.ts +6 -0
  50. package/src-next/face/__tests__/preview.test.ts +374 -0
  51. package/src-next/face/__tests__/projection.test.ts +303 -0
  52. package/src-next/face/__tests__/repo-root.guard.test.ts +120 -0
  53. package/src-next/face/__tests__/termination.test.ts +650 -0
  54. package/src-next/face/__tests__/words.guard.test.ts +93 -0
  55. package/src-next/face/artifacts.ts +248 -0
  56. package/src-next/face/board-view.ts +652 -0
  57. package/src-next/face/capsule.ts +163 -0
  58. package/src-next/face/cli.ts +1028 -0
  59. package/src-next/face/declare.ts +323 -0
  60. package/src-next/face/gate.ts +171 -0
  61. package/src-next/face/graph-view.ts +74 -0
  62. package/src-next/face/host.ts +302 -0
  63. package/src-next/face/lifecycle.ts +725 -0
  64. package/src-next/face/preview.ts +151 -0
  65. package/src-next/face/projection.ts +285 -0
  66. package/src-next/face/route-render.ts +185 -0
  67. package/src-next/face/termination.ts +573 -0
  68. package/src-next/face/words.ts +314 -0
  69. package/src-next/infra/__tests__/infra.test.ts +333 -0
  70. package/src-next/infra/__tests__/root.test.ts +56 -0
  71. package/src-next/infra/config.ts +42 -0
  72. package/src-next/infra/doc-roots.ts +29 -0
  73. package/src-next/infra/git.ts +39 -0
  74. package/src-next/infra/process.ts +34 -0
  75. package/src-next/infra/root.ts +73 -0
  76. package/src-next/infra/runtime.ts +132 -0
  77. package/src-next/infra/workspace.ts +322 -0
  78. package/src-next/render/__tests__/render.test.ts +550 -0
  79. package/src-next/render/__tests__/skeleton.test.ts +684 -0
  80. package/src-next/render/brief.ts +121 -0
  81. package/src-next/render/issue-body.ts +162 -0
  82. package/src-next/render/skeleton.ts +502 -0
  83. package/src-next/render/templates.ts +645 -0
  84. package/src-next/session/__tests__/graph.test.ts +277 -0
  85. package/src-next/session/__tests__/handoff-plane.guard.test.ts +48 -0
  86. package/src-next/session/__tests__/handoff-schema.test.ts +310 -0
  87. package/src-next/session/__tests__/ledger.test.ts +745 -0
  88. package/src-next/session/__tests__/next.test.ts +460 -0
  89. package/src-next/session/__tests__/preflight.test.ts +545 -0
  90. package/src-next/session/__tests__/round-naming.test.ts +142 -0
  91. package/src-next/session/__tests__/run.test.ts +1026 -0
  92. package/src-next/session/__tests__/wave-line-phase.guard.test.ts +49 -0
  93. package/src-next/session/__tests__/wave.test.ts +476 -0
  94. package/src-next/session/faces.ts +110 -0
  95. package/src-next/session/graph.ts +411 -0
  96. package/src-next/session/handoff-schema.ts +373 -0
  97. package/src-next/session/ledger.ts +1076 -0
  98. package/src-next/session/next.ts +293 -0
  99. package/src-next/session/preflight.ts +271 -0
  100. package/src-next/session/round-naming.ts +84 -0
  101. package/src-next/session/run.ts +610 -0
  102. package/src-next/session/state.ts +30 -0
  103. package/src-next/session/wave.ts +139 -0
  104. package/templates/report/issue-body.json +17 -65
  105. package/dist/chunks/branch.mjs +0 -480
  106. package/dist/chunks/docs.mjs +0 -253
  107. package/dist/chunks/task.mjs +0 -913
  108. package/dist/cli.mjs +0 -5457
  109. package/dist/documents/schema/add-phase-protocol.json +0 -126
  110. package/dist/documents/schema/overall.json +0 -361
  111. package/dist/documents/schema/phase-spec.json +0 -145
  112. package/dist/documents/schema/plan.json +0 -191
  113. package/dist/documents/schema/skill-anatomy.json +0 -233
  114. package/dist/resources/harness-registry.json +0 -49
  115. package/dist/shared/cdd-engine.liioziig.mjs +0 -184
  116. package/templates/engine-config.json +0 -302
  117. package/templates/schema/cache-profile-schema.json +0 -23
  118. package/templates/schema/docs-handoff-schema.json +0 -129
  119. package/templates/schema/task-handoff-schema.json +0 -332
  120. package/templates/template-contract.json +0 -231
@@ -0,0 +1,322 @@
1
+ // packages/cdd-engine/src-next/infra/workspace.ts
2
+ // T12 — the workspace data plane: the WorkspaceRoot + Workspace pair owns every
3
+ // on-disk workspace concern of the new tree.
4
+ // WorkspaceRoot — the repo-scoped workspace base (`<repoRoot>/<workspaceRoot>`,
5
+ // one dispatch family's home; the segment single-sources the engine config's
6
+ // handoffNamespace.workspaceRoot and is never a hard-coded literal).
7
+ // Workspace — one dispatch workspace (`<base>/<slug>/`): ensure() mkdirs the
8
+ // slug dir, readJson/writeJson are the JSON read/write pair (mkdir before
9
+ // write; readJson is tri-state — ok / missing / malformed), readJsonLenient is
10
+ // the sub-agent-authored draft face (jsonc-parser + trailing-comma/comment
11
+ // tolerance — a child-LLM slip never voids a round, a real break still reports
12
+ // malformed; D39), resolve() is the
13
+ // child-path single fact, slugFromDoc is the doc-file → slug derivation
14
+ // (`-design`/`-plan` suffix strip), docsOfSlug is the slug → doc-tree reverse
15
+ // derivation (the board's file-system-only truth, phase-suffix parse included).
16
+
17
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
18
+ import path from "node:path";
19
+ import { type ParseError, parse } from "jsonc-parser";
20
+ import { RepoRoot } from "./root.ts";
21
+ import { ENGINE_RUNTIME } from "./runtime.ts";
22
+
23
+ /** The tri-state JSON read — the read's three DISTINCT outcomes, discriminated: a
24
+ * `missing` file (never written) and a `malformed` file (present but unparseable)
25
+ * are different facts, so a read-back reconstruct reports each truly — a corrupt
26
+ * draft is never misreported as "not written" (D27 · single-fact honesty). The
27
+ * other-IO-error case (EACCES, EISDIR …) is a present-but-unreadable file and rides
28
+ * the `malformed` side: it is never silently "missing". The lenient face (D39)
29
+ * carries the parser's PRECISE error codes on the `malformed` side for diagnosis
30
+ * (the strict face and the IO-error case leave `errors` absent). */
31
+ export type JsonRead<T> =
32
+ | { kind: "ok"; value: T }
33
+ | { kind: "missing" }
34
+ | { kind: "malformed"; errors?: readonly ParseError[] };
35
+
36
+ /** The slug phase-suffix syntax — the trailing `-p<major>(.<minor>)*` segment
37
+ * (spec §3.2 ⑬). This is the ONE source of the phase-suffix grammar: both the
38
+ * suffix parse (`Workspace.phaseSuffixOf`, the `-p…$` form) and the board's
39
+ * suffix-only match (`BoardView.scanPhases`, the `^p…$` form) compose their
40
+ * patterns from this fragment. (Distinct from the doc-contract design-unit value
41
+ * syntax `P\d+(\.\d+)*-design` — uppercase + `-design` tail — which is another
42
+ * fact, never merged here.) */
43
+ export const PHASE_SUFFIX_CORE = "p\\d+(?:\\.\\d+)*";
44
+
45
+ /** The phase-suffix parse — the trailing `-p<major>(.<minor>)*` segment captured
46
+ * as the named `suffix` group (composed from PHASE_SUFFIX_CORE: the ONE grammar). */
47
+ const PHASE_SUFFIX_TAIL = new RegExp(`(?<program>.+?)(?<suffix>-${PHASE_SUFFIX_CORE})$`);
48
+
49
+ /** The suffix-only match — a bare `<major>(.<minor>)*` phase path (composed from
50
+ * the SAME PHASE_SUFFIX_CORE; the board's scan uses this form). */
51
+ export const PHASE_SUFFIX_BARE = new RegExp(`^${PHASE_SUFFIX_CORE}$`);
52
+
53
+ /** The persisted path-field keys — the JSON fields whose value is a PATH (the
54
+ * progress.json `reviewedRevision.doc` / `.plan` layers · the base.json `plan`
55
+ * field). The read-time normalization (P9 T4 §2.11) relativizes exactly these
56
+ * values, never an arbitrary string (a carrier's `notes` prose is never treated as
57
+ * a path). */
58
+ const PERSISTED_PATH_KEYS: ReadonlySet<string> = new Set(["doc", "plan"]);
59
+
60
+ /** The repo-scoped workspace base — `<repoRoot>/<workspaceRoot>`. */
61
+ export class WorkspaceRoot {
62
+ readonly repoRoot: string;
63
+ /** The repo-basis value object (T1 `RepoRoot`) — constructed ONCE here, at the
64
+ * workspace's own boundary, and shared by every reader that needs the basis
65
+ * (the ledger's write/read normalization, the CLI's capsule/graph render, the
66
+ * board's doc cells): the single repo-basis fact is threaded as the value object,
67
+ * never re-wrapped per call (branch-review-1 F2 — Data Clumps / Primitive
68
+ * Obsession: one basis, one form). */
69
+ readonly basis: RepoRoot;
70
+ readonly path: string;
71
+
72
+ constructor(repoRoot: string, workspaceRoot: string) {
73
+ this.repoRoot = repoRoot;
74
+ this.basis = new RepoRoot(repoRoot);
75
+ this.path = path.join(repoRoot, workspaceRoot);
76
+ }
77
+
78
+ /** Idempotently create the workspace root + self-publish the namespace root's
79
+ * `.gitignore` (a single `*` — everything under `.kairos/` is engine-owned, so
80
+ * the git face ignores the whole namespace wholesale, the `cdd/` workspace and
81
+ * any future sibling alike). The tree-clean gate then reads git's own judgment
82
+ * — `isClean` with zero engine-side exclusion — a consumer repo with no `.kairos`
83
+ * entry in its own `.gitignore` still stays clean across dispatches, because
84
+ * the workspace publishes its keep-out marker at ensure time, before the gate
85
+ * ever reads the tree (the F1 fix: the engine's run artifacts are engine-owned,
86
+ * never "uncommitted user work"). The ignore affects only untracked files — a
87
+ * user who git-tracks the workspace keeps seeing its changes on the gate. */
88
+ ensure(): WorkspaceRoot {
89
+ mkdirSync(this.path, { recursive: true });
90
+ // The namespace root — the workspace root's parent (`.kairos/cdd` → `.kairos`):
91
+ // the keep-out marker sits at the namespace's top, never per-workspace (the
92
+ // consumer-facing convention: ignore the whole `.kairos` namespace at once).
93
+ const namespaceRoot = path.dirname(this.path);
94
+ mkdirSync(namespaceRoot, { recursive: true });
95
+ const ignore = path.join(namespaceRoot, ".gitignore");
96
+ if (!existsSync(ignore)) writeFileSync(ignore, "*\n", "utf8");
97
+ return this;
98
+ }
99
+ }
100
+
101
+ /** One slug's doc-tree paths — the reverse-derived artifact paths of a program or
102
+ * phase slug (each member null when the file does not exist on disk; the file
103
+ * system is the only truth, nothing is synthesized). */
104
+ export interface SlugDocs {
105
+ /** The program's overall spec (`specs/<program>-overall.md`); null when absent. */
106
+ overall: string | null;
107
+ /** The phase's design spec (`specs/<slug>-design.md`); null when absent or the
108
+ * slug is a program slug. */
109
+ spec: string | null;
110
+ /** The phase's plan (`plans/<slug>.md`); null when absent or the slug is a
111
+ * program slug. */
112
+ plan: string | null;
113
+ /** The phase suffix (`-p7`, `-p4.1`, `-p3.2.1` …); null for a program slug. */
114
+ phaseSuffix: string | null;
115
+ }
116
+
117
+ /** One dispatch workspace — `<base>/<slug>/`. */
118
+ export class Workspace {
119
+ readonly root: WorkspaceRoot;
120
+ readonly slug: string;
121
+ readonly path: string;
122
+
123
+ constructor(root: WorkspaceRoot, slug: string) {
124
+ this.root = root;
125
+ this.slug = slug;
126
+ this.path = path.join(root.path, slug);
127
+ }
128
+
129
+ /** The doc-file → slug derivation: strip `.md`, then one trailing `-design` or
130
+ * `-plan` suffix (anchored, mutually exclusive — spec and plan converge). */
131
+ static slugFromDoc(doc: string): string {
132
+ const base = path.basename(doc).replace(/\.md$/, "");
133
+ return base.replace(/-(?:design|plan)$/, "");
134
+ }
135
+
136
+ /** The slug's phase-suffix parse — the trailing `-p<major>(.<minor>)*` segment
137
+ * (null when the slug is a program slug, i.e. carries no phase suffix). The
138
+ * grammar is PHASE_SUFFIX_TAIL, composed from the shared PHASE_SUFFIX_CORE. */
139
+ static phaseSuffixOf(slug: string): string | null {
140
+ const match = PHASE_SUFFIX_TAIL.exec(slug);
141
+ return match?.groups?.suffix ?? null;
142
+ }
143
+
144
+ /** The slug → doc-tree reverse derivation: from a program or phase slug, derive
145
+ * the artifact paths the doc tree should carry, judged by `existsSync` (the
146
+ * file system is the only truth — an absent file is null, never synthesized).
147
+ * A phase slug's overall anchors at the nearest existing `<ancestor>-overall.md`
148
+ * walking up the dotted phase path (`-p7.1` → `-p7` → program root) — no
149
+ * overall-declared table is parsed (the Phase inventory is stale-prone). */
150
+ static docsOfSlug(slug: string, repoRoot: string): SlugDocs {
151
+ const specs = path.join(repoRoot, ENGINE_RUNTIME.docRoots.specs);
152
+ const plans = path.join(repoRoot, ENGINE_RUNTIME.docRoots.plans);
153
+ const suffix = Workspace.phaseSuffixOf(slug);
154
+ if (suffix === null) {
155
+ const overall = path.join(specs, `${slug}-overall.md`);
156
+ return {
157
+ overall: existsSync(overall) ? overall : null,
158
+ spec: null,
159
+ plan: null,
160
+ phaseSuffix: null,
161
+ };
162
+ }
163
+ const overall = Workspace.#nearestOverall(specs, slug, suffix);
164
+ const spec = path.join(specs, `${slug}-design.md`);
165
+ const plan = path.join(plans, `${slug}.md`);
166
+ return {
167
+ overall,
168
+ spec: existsSync(spec) ? spec : null,
169
+ plan: existsSync(plan) ? plan : null,
170
+ phaseSuffix: suffix,
171
+ };
172
+ }
173
+
174
+ /** The nearest existing overall anchor walking up the dotted phase path: for a
175
+ * deep suffix (`-p7.1`) the candidates are `<program>-p7`, then the program
176
+ * root; for a single-segment suffix the program root only. Null when no
177
+ * candidate's overall file exists — nothing synthesized. */
178
+ static #nearestOverall(specs: string, slug: string, suffix: string): string | null {
179
+ const stem = slug.slice(0, slug.length - suffix.length);
180
+ const segments = suffix.slice(2).split(".");
181
+ for (let keep = segments.length - 1; keep >= 0; keep--) {
182
+ const candidate =
183
+ keep === 0
184
+ ? path.join(specs, `${stem}-overall.md`)
185
+ : path.join(specs, `${stem}-p${segments.slice(0, keep).join(".")}-overall.md`);
186
+ if (existsSync(candidate)) return candidate;
187
+ }
188
+ return null;
189
+ }
190
+
191
+ /** Idempotently create the workspace directory. */
192
+ ensure(): Workspace {
193
+ this.root.ensure();
194
+ mkdirSync(this.path, { recursive: true });
195
+ return this;
196
+ }
197
+
198
+ /** A child path inside this workspace. */
199
+ resolve(name: string): string {
200
+ return path.join(this.path, name);
201
+ }
202
+
203
+ /** Read a JSON child — the tri-state face: `{kind:"ok",value}` on a present,
204
+ * parseable file; `{kind:"missing"}` when the path does not exist; `{kind:
205
+ * "malformed"}` when the file is present but its bytes are unparseable (a bad
206
+ * JSON draft) OR unreadable for any other I/O reason (a present-but-broken file is
207
+ * never silently "missing" — the reconstruct reports the true cause). The STRICT
208
+ * read — engine-authored files (`JSON.stringify` output) are always legal JSON, so
209
+ * they never need leniency; a lenient read of a strict file would only mask a real
210
+ * engine bug. */
211
+ readJson<T>(name: string): JsonRead<T> {
212
+ const target = this.resolve(name);
213
+ const text = this.#readText(target);
214
+ if (text.kind !== "ok") return text;
215
+ try {
216
+ // The read-time path backstop (P9 T4 §2.11): a path field persisted by an
217
+ // older build (an absolute form) is relativized on read, so an un-migrated
218
+ // file still yields the ONE canonical shape downstream. A no-op on
219
+ // already-relative values (relativize is idempotent).
220
+ return { kind: "ok", value: this.#normalizePaths(JSON.parse(text.value)) as T };
221
+ } catch {
222
+ return { kind: "malformed" };
223
+ }
224
+ }
225
+
226
+ /** Read a JSON child LENIENTLY — the sub-agent-authored handoff-draft face (D39).
227
+ * A child LLM writes handoff carriers (`tasks-*-implement.json` …) from prose, and
228
+ * a trailing comma or a stray comment is a routine model slip, not a real defect —
229
+ * the strict `readJson` vetoes the WHOLE implement+review round on one such comma
230
+ * (the W3 {5,11} block: a `notes` array trailing comma, the draft otherwise whole).
231
+ * jsonc-parser with `allowTrailingComma` tolerates ONLY the lenient-dialect surface
232
+ * (trailing commas · comments) and still reports a real break (a missing brace, …)
233
+ * — so a corrupt draft stays fail-loud while a cosmetic slip no longer voids a round.
234
+ * The leniency is scoped to THIS face alone: engine-authored files (including the
235
+ * test-evidence sibling, which the engine/child writes as machine JSON) keep the
236
+ * strict `readJson` — the JSON contract is never widened for engine bytes. */
237
+ readJsonLenient<T>(name: string): JsonRead<T> {
238
+ const target = this.resolve(name);
239
+ const text = this.#readText(target);
240
+ if (text.kind !== "ok") return text;
241
+ const errors: ParseError[] = [];
242
+ const value = parse(text.value, errors, {
243
+ allowTrailingComma: true,
244
+ disallowComments: false,
245
+ }) as T;
246
+ // A real break carries the parser's precise error codes (offset/length/error)
247
+ // for diagnosis; a tolerated slip parses clean (errors empty).
248
+ return errors.length === 0 ? { kind: "ok", value } : { kind: "malformed", errors };
249
+ }
250
+
251
+ /** Read a child's text — the shared tri-state file leg of both JSON reads: a
252
+ * genuinely absent path is `missing`; a present-but-unreadable one (EACCES, EISDIR …)
253
+ * is `malformed` — never silently "missing" (D27 · single-fact honesty). */
254
+ #readText(target: string): { kind: "ok"; value: string } | JsonRead<never> {
255
+ let text: string;
256
+ try {
257
+ text = readFileSync(target, "utf8");
258
+ } catch (raw) {
259
+ const code = (raw as { code?: unknown }).code;
260
+ return code === "ENOENT" ? { kind: "missing" } : { kind: "malformed" };
261
+ }
262
+ return { kind: "ok", value: text };
263
+ }
264
+
265
+ /** Write a JSON child — mkdir before write. The declared path fields (`doc` /
266
+ * `plan`) are normalized to the canonical repoRoot-relative shape on write (P9
267
+ * T4 §2.7), so every engine-persisted path field lands relative — the read-time
268
+ * backstop then only covers legacy bytes (migration handles history, the read
269
+ * normalizes any straggler). The written bytes carry exactly one trailing `\n`
270
+ * (the repo's EOF rule), so an engine-written file is byte-canonical and the
271
+ * one-time migration leaves it byte-identical (zero churn). */
272
+ writeJson(name: string, value: unknown): void {
273
+ this.ensure();
274
+ const normalized = this.#normalizePaths(value);
275
+ writeFileSync(this.resolve(name), `${JSON.stringify(normalized, null, 2)}\n`, "utf8");
276
+ }
277
+
278
+ /** Write a text child — mkdir before write (the text twin of `writeJson`; the
279
+ * engine-rendered brief is the one text artifact the engine authors itself).
280
+ * Returns the resolved path. */
281
+ writeText(name: string, text: string): string {
282
+ this.ensure();
283
+ const target = this.resolve(name);
284
+ writeFileSync(target, text, "utf8");
285
+ return target;
286
+ }
287
+
288
+ /** The workspace's repo-basis value object — the ONE conversion exit the
289
+ * read-time path backstop normalizes through. The basis is the root's OWN
290
+ * value object (`WorkspaceRoot.basis`, built once at the root's boundary) —
291
+ * never re-wrapped here (branch-review-1 F2: one basis, one form). */
292
+ #repoBasis(): RepoRoot {
293
+ return this.root.basis;
294
+ }
295
+
296
+ /** The read-time path backstop (P9 T4 §2.11) — deep-normalize every DECLARED
297
+ * path field (`doc` / `plan` — the `reviewedRevision` two-layer layers + the
298
+ * base artifact's `plan`) to the canonical repoRoot-relative shape, so an
299
+ * un-migrated file (a legacy absolute value) still reads as the ONE shape.
300
+ * Only the declared path keys are touched (never arbitrary prose); the walk is
301
+ * a pure clone (arrays + plain objects), recursing into `waves[]` rows and the
302
+ * reviewed-revision records alike. Relativizing an already-relative value is a
303
+ * no-op (idempotent). */
304
+ #normalizePaths(value: unknown): unknown {
305
+ const root = this.#repoBasis();
306
+ const walk = (node: unknown): unknown => {
307
+ if (Array.isArray(node)) return node.map(walk);
308
+ if (node !== null && typeof node === "object") {
309
+ const out: Record<string, unknown> = {};
310
+ for (const [key, child] of Object.entries(node as Record<string, unknown>)) {
311
+ out[key] =
312
+ PERSISTED_PATH_KEYS.has(key) && typeof child === "string"
313
+ ? root.relativize(child)
314
+ : walk(child);
315
+ }
316
+ return out;
317
+ }
318
+ return node;
319
+ };
320
+ return walk(value);
321
+ }
322
+ }