@aestheticfunction/dspack-emit 0.4.1 → 0.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.
Files changed (64) hide show
  1. package/README.md +16 -6
  2. package/dist/cli.js +56 -0
  3. package/dist/index.d.ts +4 -1
  4. package/dist/index.js +3 -1
  5. package/dist/targets/a2ui/diagnostics.d.ts +110 -0
  6. package/dist/targets/a2ui/diagnostics.js +94 -0
  7. package/dist/targets/a2ui/surface.d.ts +28 -9
  8. package/dist/targets/a2ui/surface.js +566 -224
  9. package/dist/transform/desugar.d.ts +32 -0
  10. package/dist/transform/desugar.js +156 -0
  11. package/dist/transform/emit.js +59 -0
  12. package/dist/transform/index.js +4 -0
  13. package/dist/transform/mapping.d.ts +0 -6
  14. package/dist/transform/mapping.js +50 -0
  15. package/dist/transform/model.d.ts +275 -0
  16. package/dist/transform/model.js +148 -0
  17. package/dist/transform/parse-v2.d.ts +78 -0
  18. package/dist/transform/parse-v2.js +305 -0
  19. package/dist/transform/profile-load.d.ts +7 -6
  20. package/dist/transform/profile-load.js +99 -20
  21. package/dist/transform/profile-schema-v2.d.ts +9 -0
  22. package/dist/transform/profile-schema-v2.js +430 -0
  23. package/dist/transform/profiles.d.ts +31 -1
  24. package/dist/transform/scaffold.d.ts +29 -12
  25. package/dist/transform/scaffold.js +91 -31
  26. package/dist/transform/shadcn-v2-respelling.d.ts +12 -0
  27. package/dist/transform/shadcn-v2-respelling.js +49 -0
  28. package/dist/transform/validate-v2.d.ts +36 -0
  29. package/dist/transform/validate-v2.js +100 -0
  30. package/dist/types.d.ts +19 -0
  31. package/dist/validate/ajv.js +96 -25
  32. package/package.json +2 -2
  33. package/src/__snapshots__/byte-neutral.test.ts.snap +66 -0
  34. package/src/byte-neutral.test.ts +246 -0
  35. package/src/cli.ts +60 -0
  36. package/src/dangling-ref.test.ts +118 -0
  37. package/src/desugar.test.ts +162 -0
  38. package/src/engine-boundary.test.ts +248 -0
  39. package/src/eval-fixture.test.ts +89 -0
  40. package/src/functions.test.ts +182 -0
  41. package/src/index.ts +4 -1
  42. package/src/profile-load.test.ts +99 -1
  43. package/src/profile-v2.test.ts +363 -0
  44. package/src/review-findings.test.ts +292 -0
  45. package/src/schema-mirrors.test.ts +5 -0
  46. package/src/surface-fidelity.test.ts +213 -0
  47. package/src/targets/a2ui/diagnostics.ts +136 -0
  48. package/src/targets/a2ui/surface.ts +920 -242
  49. package/src/transform/desugar.ts +194 -0
  50. package/src/transform/emit.ts +65 -0
  51. package/src/transform/index.ts +5 -0
  52. package/src/transform/mapping.ts +42 -0
  53. package/src/transform/model.ts +325 -0
  54. package/src/transform/parse-v2.ts +397 -0
  55. package/src/transform/profile-load.ts +104 -22
  56. package/src/transform/profile-schema-v2.ts +430 -0
  57. package/src/transform/profile.v2.schema.json +422 -0
  58. package/src/transform/profiles.ts +32 -1
  59. package/src/transform/scaffold.ts +124 -47
  60. package/src/transform/shadcn-v2-respelling.ts +61 -0
  61. package/src/transform/validate-v2.ts +138 -0
  62. package/src/types.ts +20 -0
  63. package/src/validate/ajv.ts +89 -26
  64. package/src/validate-v2.test.ts +173 -0
package/README.md CHANGED
@@ -50,7 +50,7 @@ https://github.com/user-attachments/assets/510a781b-4214-49b3-b997-9cbecdc36961
50
50
 
51
51
  | Path | What |
52
52
  | --- | --- |
53
- | `input/shadcn-ui.dspack.json` | Example input: a dspack v0.4 contract from a React+Tailwind system (shadcn/ui). |
53
+ | `input/shadcn-ui.dspack.json` | Example input: a dspack v0.4 contract from a React+Tailwind system (shadcn/ui). **Pinned to v2.3.0 (8 components) — not current shadcn coverage;** see [`docs/CONTRACT-PIN.md`](docs/CONTRACT-PIN.md). |
54
54
  | `src/` | The transformer: source-agnostic engine + data-only profile + versioned emitter + validator. |
55
55
  | `surface/settings-card.surface.json` | Hand-authored A2UI v0.9.1 surface instantiating the compiled components. |
56
56
  | `out/catalog.v0_9_1.json`, `out/catalog.v1_0.json` | Generated catalogs (no external `$ref`, versioned `catalogId`). |
@@ -88,11 +88,21 @@ npm run transform -- --in input/shadcn-ui.dspack.json --a2ui-version 1.0 --out o
88
88
 
89
89
  ### Profiles as JSON (`--profile`, `loadProfile`, `scaffoldProfile`)
90
90
 
91
- The `Profile` has always been pure data; it is now also *reachable* as data.
92
- A `*.profile.json` document (schema:
93
- [`src/transform/profile.v1.schema.json`](src/transform/profile.v1.schema.json),
94
- a 1:1 mirror of the `Profile` type plus a `profileVersion: "1"` envelope)
95
- drives the engine byte-identically to a TypeScript profile. The package
91
+ The `Profile` has always been pure data; it is now also *reachable* as data,
92
+ in two languages dispatched explicitly on `profileVersion`:
93
+
94
+ - **v2 — the primitive language** (schema:
95
+ [`src/transform/profile.v2.schema.json`](src/transform/profile.v2.schema.json))
96
+ authors the transformation model directly: Identity / Route / Collect in a
97
+ closed string syntax, plus declared catalog `functions`. New profiles should
98
+ be v2 — [docs/PROFILES.md](docs/PROFILES.md) teaches it.
99
+ - **v1 — compatibility syntax** (schema:
100
+ [`src/transform/profile.v1.schema.json`](src/transform/profile.v1.schema.json)),
101
+ the original surface-plan directives. Frozen: v1 documents keep loading and
102
+ emitting byte-identically, indefinitely, desugaring into the same internal
103
+ model the engine reads for both languages.
104
+
105
+ Either drives the engine byte-identically to a TypeScript profile. The package
96
106
  installs a `dspack-emit` bin, so out-of-repo contracts emit from any CI:
97
107
 
98
108
  ```bash
package/dist/cli.js CHANGED
@@ -38,6 +38,13 @@ import { generateJsonRenderModules } from "./targets/json-render/codegen.js";
38
38
  import { emitJsonRenderSpec, EmitJsonRenderError, validateSpecAgainstModel } from "./targets/json-render/emit.js";
39
39
  /** Flags that take no value; their presence means `true`. */
40
40
  const BOOLEAN_FLAGS = new Set(["strict-coverage"]);
41
+ /**
42
+ * Flags whose value is optional: bare `--strict-surface` means the default
43
+ * class set; `--strict-surface=lossy,synthesis-defaults` configures it.
44
+ */
45
+ const OPTIONAL_VALUE_FLAGS = new Set(["strict-surface"]);
46
+ const STRICT_SURFACE_DEFAULT = ["lossy", "cannot-represent"];
47
+ const FIDELITY_CLASSES = new Set(["maps-cleanly", "synthesis-defaults", "lossy", "cannot-represent"]);
41
48
  function parseArgs(argv) {
42
49
  // Supports `--key value`, `--key=value`, and valueless boolean flags; fails fast
43
50
  // on a malformed flag or a value-taking `--key` missing its value.
@@ -53,6 +60,16 @@ function parseArgs(argv) {
53
60
  else if (BOOLEAN_FLAGS.has(tok.slice(2))) {
54
61
  m.set(tok.slice(2), "true");
55
62
  }
63
+ else if (OPTIONAL_VALUE_FLAGS.has(tok.slice(2))) {
64
+ const next = argv[i + 1];
65
+ if (next !== undefined && !next.startsWith("--")) {
66
+ m.set(tok.slice(2), next);
67
+ i++;
68
+ }
69
+ else {
70
+ m.set(tok.slice(2), "");
71
+ }
72
+ }
56
73
  else {
57
74
  const value = argv[++i];
58
75
  if (value === undefined)
@@ -86,8 +103,46 @@ function parseArgs(argv) {
86
103
  profile,
87
104
  emitSurface: m.get("emit-surface"),
88
105
  strictCoverage: m.get("strict-coverage") === "true",
106
+ strictSurface: parseStrictSurface(m),
89
107
  };
90
108
  }
109
+ function parseStrictSurface(m) {
110
+ if (!m.has("strict-surface"))
111
+ return undefined;
112
+ const raw = m.get("strict-surface");
113
+ const classes = raw === "" ? STRICT_SURFACE_DEFAULT : raw.split(",").map((c) => c.trim());
114
+ for (const c of classes) {
115
+ if (!FIDELITY_CLASSES.has(c)) {
116
+ fail(`--strict-surface: unknown fidelity class '${c}' (known: ${[...FIDELITY_CLASSES].join(", ")})`);
117
+ }
118
+ }
119
+ return classes;
120
+ }
121
+ /**
122
+ * The strict-surface gate: print the emitted surface's fidelity ledger, then
123
+ * fail (exit 5) when any entry's class is in the configured set. Loss is
124
+ * never invisible — without the flag the ledger still prints; the flag makes
125
+ * the configured classes FATAL rather than informational.
126
+ */
127
+ function gateSurfaceFidelity(tag, fidelity, strict) {
128
+ const counts = new Map();
129
+ for (const f of fidelity)
130
+ counts.set(f.class, (counts.get(f.class) ?? 0) + 1);
131
+ const summary = [...counts.entries()].map(([c, n]) => `${c}=${n}`).join(" ") || "none";
132
+ console.log(`${tag} fidelity ${fidelity.length} transformation(s): ${summary}`);
133
+ if (!strict)
134
+ return;
135
+ const failing = fidelity.filter((f) => strict.includes(f.class));
136
+ if (failing.length === 0) {
137
+ console.log(`${tag} PASS strict-surface (no ${strict.join("/")} transformations)`);
138
+ return;
139
+ }
140
+ console.error(`${tag} STRICT-SURFACE: ${failing.length} transformation(s) in failing class(es) ${strict.join(", ")}:`);
141
+ for (const f of failing) {
142
+ console.error(`${tag} [${f.class}] ${f.kind} ${f.source} -> ${f.destination} (${f.origin})${f.note ? ` — ${f.note}` : ""}`);
143
+ }
144
+ process.exit(5);
145
+ }
91
146
  function fail(msg) {
92
147
  console.error(`error: ${msg}`);
93
148
  process.exit(2);
@@ -196,6 +251,7 @@ function main() {
196
251
  writeFileSync(outPath, JSON.stringify({ messages: emitted.messages }, null, 2) + "\n");
197
252
  for (const w of emitted.warnings)
198
253
  console.log(`${tag} note ${w.code}: ${w.message}`);
254
+ gateSurfaceFidelity(tag, emitted.fidelity, args.strictSurface);
199
255
  // Gate A3 over the emitted surface: its instances must validate against the
200
256
  // catalog generated in this same run.
201
257
  const check = transform(doc, args.version, { messages: emitted.messages }, profile);
package/dist/index.d.ts CHANGED
@@ -7,7 +7,10 @@
7
7
  */
8
8
  export { transform, transformFromJson, type TransformOutput } from "./transform/index.js";
9
9
  export { shadcnProfile, type Profile, type ComponentPlan, type SurfacePlanDirectives } from "./transform/profiles.js";
10
- export { loadProfile, profileSchema, ProfileLoadError, type ProfileLoadIssue } from "./transform/profile-load.js";
10
+ export { loadProfile, profileSchema, profileSchemaV2, ProfileLoadError, type ProfileLoadIssue } from "./transform/profile-load.js";
11
+ export { ProfileContractError, type ProfileContractIssue } from "./transform/validate-v2.js";
12
+ export { ProfileParseError, type ParseIssue, type SurfaceV2 } from "./transform/parse-v2.js";
13
+ export type { SurfaceFidelityEntry } from "./types.js";
11
14
  export { scaffoldProfile, type ScaffoldOptions, type ScaffoldResult, type ScaffoldNote } from "./transform/scaffold.js";
12
15
  export { validateCatalog, extractInstances, type ValidationReport, type GateResult } from "./validate/ajv.js";
13
16
  export { emitSurface, slug, EmitSurfaceError, type EmitSurfaceResult, type EmitSurfaceOptions, } from "./targets/a2ui/surface.js";
package/dist/index.js CHANGED
@@ -7,7 +7,9 @@
7
7
  */
8
8
  export { transform, transformFromJson } from "./transform/index.js";
9
9
  export { shadcnProfile } from "./transform/profiles.js";
10
- export { loadProfile, profileSchema, ProfileLoadError } from "./transform/profile-load.js";
10
+ export { loadProfile, profileSchema, profileSchemaV2, ProfileLoadError } from "./transform/profile-load.js";
11
+ export { ProfileContractError } from "./transform/validate-v2.js";
12
+ export { ProfileParseError } from "./transform/parse-v2.js";
11
13
  export { scaffoldProfile } from "./transform/scaffold.js";
12
14
  export { validateCatalog, extractInstances } from "./validate/ajv.js";
13
15
  export { emitSurface, slug, EmitSurfaceError, } from "./targets/a2ui/surface.js";
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Ordered surface diagnostics.
3
+ *
4
+ * The v1 engine emitted warnings by pushing them onto an array wherever it
5
+ * happened to be. That made the emitted order an ACCIDENT of method order and
6
+ * traversal — invisible while one implementation existed, and load-bearing the
7
+ * moment a second one appeared, because the byte gate hashes warnings.
8
+ *
9
+ * An engine driven by routes and collects resolves work in declaration order,
10
+ * which is NOT v1's method order. Left implicit, the rewrite would emit the
11
+ * same warnings in a different sequence and fail the gate for a reason that has
12
+ * nothing to do with correctness — and the temptation would be to "fix" it by
13
+ * re-baselining the hashes, which would silently discard the guarantee.
14
+ *
15
+ * So order becomes explicit data. Every diagnostic carries a sort key; the
16
+ * engine collects them in whatever order it likes and sorts once at the end.
17
+ * The key reproduces v1 exactly, and — because it is declared rather than
18
+ * emergent — keeps reproducing it under later refactors.
19
+ *
20
+ * The phases below are DERIVED from the v1 engine, not designed: each is the
21
+ * point in `emitNode` where that warning was pushed. They are numbered in that
22
+ * method's execution order, and the numbering is the compatibility contract.
23
+ */
24
+ import type { SurfaceFidelityEntry, Warning } from "../../types.js";
25
+ /**
26
+ * Legacy emission phases, in v1 `emitNode` execution order.
27
+ *
28
+ * Read alongside the pre-rewrite `emitNode`: id allocation happened first, then
29
+ * prop projection, then the two consuming strategies (each ending with its own
30
+ * composition warning), then text-child synthesis, then the synthesized action,
31
+ * then the child-list rewrite — and only after every child had emitted did the
32
+ * single-slot wrap run.
33
+ */
34
+ export declare enum Phase {
35
+ /** `allocateId` for this node — v1 allocated before any projection. */
36
+ IdAllocation = 0,
37
+ /** `applyPropMap`: dropped props and unprojectable values. */
38
+ PropMap = 1,
39
+ /** `applySubContent`'s audited label lift. */
40
+ LabelLift = 2,
41
+ /** `applySubContent`'s closing composition-flattened warning. */
42
+ SubContentFlatten = 3,
43
+ /** `applySubTable`'s per-cell flattening and per-sub drops. */
44
+ TableBody = 4,
45
+ /** `applySubTable`'s closing composition-flattened warning. */
46
+ TableFlatten = 5,
47
+ /** `emitTextPrimitive` invoked by the text-child route. */
48
+ TextChild = 6,
49
+ /** The synthesized declarative action. */
50
+ Action = 7,
51
+ /** `flattenSubs` rewriting the child list before children emit. */
52
+ ChildRewrite = 8,
53
+ /** `wrapInColumn` — runs AFTER every child has emitted. */
54
+ Wrap = 9
55
+ }
56
+ /**
57
+ * Where a diagnostic sits relative to this node's children. v1's array order is
58
+ * a pre-order walk in which a parent's pre-child warnings precede all of its
59
+ * descendants' warnings, and its post-child warnings follow all of them — so a
60
+ * flat `(node, phase)` sort would wrongly hoist the wrap warning above the
61
+ * children it wraps.
62
+ */
63
+ export declare enum Band {
64
+ BeforeChildren = 0,
65
+ Children = 1,
66
+ AfterChildren = 2
67
+ }
68
+ export interface Diagnostic {
69
+ warning: Warning;
70
+ /**
71
+ * Lexicographically ordered key. Shape, per tree level:
72
+ * [...ancestorPath, Band.Children, childIndex] repeated to reach the node,
73
+ * then [band, phase, rule, seq].
74
+ * Nesting bands this way is what makes a parent's post-child diagnostics sort
75
+ * after its whole subtree without any special case.
76
+ */
77
+ key: number[];
78
+ }
79
+ /** Compares two diagnostic keys lexicographically; shorter sorts first on a tie. */
80
+ export declare function compareKeys(a: number[], b: number[]): number;
81
+ /**
82
+ * Collects diagnostics with explicit ordering and returns them in legacy order.
83
+ *
84
+ * `seq` is a monotonic counter used only as the final tie-breaker, so two
85
+ * diagnostics identical in every declared dimension still order deterministically
86
+ * — by the order the engine produced them, which is itself deterministic.
87
+ */
88
+ export declare class Diagnostics {
89
+ private readonly items;
90
+ private readonly fidelityItems;
91
+ private seq;
92
+ /**
93
+ * @param path the node's tree path (alternating Band.Children / child index)
94
+ * @param band where this sits relative to the node's children
95
+ * @param phase the legacy emission phase
96
+ * @param rule index of the desugared rule that produced it, for stable order
97
+ * among several routes writing in the same phase
98
+ */
99
+ push(warning: Warning, path: readonly number[], band: Band, phase: Phase, rule?: number): void;
100
+ /** Legacy-ordered warnings. Sorting once at the end is the whole point. */
101
+ ordered(): Warning[];
102
+ /**
103
+ * The fidelity ledger rides the same ordering discipline as the warnings —
104
+ * an entry's position is declared by (path, band, phase, rule), never by
105
+ * when the engine happened to record it.
106
+ */
107
+ pushFidelity(entry: SurfaceFidelityEntry, path: readonly number[], band: Band, phase: Phase, rule?: number): void;
108
+ orderedFidelity(): SurfaceFidelityEntry[];
109
+ get length(): number;
110
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Legacy emission phases, in v1 `emitNode` execution order.
3
+ *
4
+ * Read alongside the pre-rewrite `emitNode`: id allocation happened first, then
5
+ * prop projection, then the two consuming strategies (each ending with its own
6
+ * composition warning), then text-child synthesis, then the synthesized action,
7
+ * then the child-list rewrite — and only after every child had emitted did the
8
+ * single-slot wrap run.
9
+ */
10
+ export var Phase;
11
+ (function (Phase) {
12
+ /** `allocateId` for this node — v1 allocated before any projection. */
13
+ Phase[Phase["IdAllocation"] = 0] = "IdAllocation";
14
+ /** `applyPropMap`: dropped props and unprojectable values. */
15
+ Phase[Phase["PropMap"] = 1] = "PropMap";
16
+ /** `applySubContent`'s audited label lift. */
17
+ Phase[Phase["LabelLift"] = 2] = "LabelLift";
18
+ /** `applySubContent`'s closing composition-flattened warning. */
19
+ Phase[Phase["SubContentFlatten"] = 3] = "SubContentFlatten";
20
+ /** `applySubTable`'s per-cell flattening and per-sub drops. */
21
+ Phase[Phase["TableBody"] = 4] = "TableBody";
22
+ /** `applySubTable`'s closing composition-flattened warning. */
23
+ Phase[Phase["TableFlatten"] = 5] = "TableFlatten";
24
+ /** `emitTextPrimitive` invoked by the text-child route. */
25
+ Phase[Phase["TextChild"] = 6] = "TextChild";
26
+ /** The synthesized declarative action. */
27
+ Phase[Phase["Action"] = 7] = "Action";
28
+ /** `flattenSubs` rewriting the child list before children emit. */
29
+ Phase[Phase["ChildRewrite"] = 8] = "ChildRewrite";
30
+ /** `wrapInColumn` — runs AFTER every child has emitted. */
31
+ Phase[Phase["Wrap"] = 9] = "Wrap";
32
+ })(Phase || (Phase = {}));
33
+ /**
34
+ * Where a diagnostic sits relative to this node's children. v1's array order is
35
+ * a pre-order walk in which a parent's pre-child warnings precede all of its
36
+ * descendants' warnings, and its post-child warnings follow all of them — so a
37
+ * flat `(node, phase)` sort would wrongly hoist the wrap warning above the
38
+ * children it wraps.
39
+ */
40
+ export var Band;
41
+ (function (Band) {
42
+ Band[Band["BeforeChildren"] = 0] = "BeforeChildren";
43
+ Band[Band["Children"] = 1] = "Children";
44
+ Band[Band["AfterChildren"] = 2] = "AfterChildren";
45
+ })(Band || (Band = {}));
46
+ /** Compares two diagnostic keys lexicographically; shorter sorts first on a tie. */
47
+ export function compareKeys(a, b) {
48
+ const n = Math.min(a.length, b.length);
49
+ for (let i = 0; i < n; i++) {
50
+ if (a[i] !== b[i])
51
+ return a[i] - b[i];
52
+ }
53
+ return a.length - b.length;
54
+ }
55
+ /**
56
+ * Collects diagnostics with explicit ordering and returns them in legacy order.
57
+ *
58
+ * `seq` is a monotonic counter used only as the final tie-breaker, so two
59
+ * diagnostics identical in every declared dimension still order deterministically
60
+ * — by the order the engine produced them, which is itself deterministic.
61
+ */
62
+ export class Diagnostics {
63
+ items = [];
64
+ fidelityItems = [];
65
+ seq = 0;
66
+ /**
67
+ * @param path the node's tree path (alternating Band.Children / child index)
68
+ * @param band where this sits relative to the node's children
69
+ * @param phase the legacy emission phase
70
+ * @param rule index of the desugared rule that produced it, for stable order
71
+ * among several routes writing in the same phase
72
+ */
73
+ push(warning, path, band, phase, rule = 0) {
74
+ this.items.push({ warning, key: [...path, band, phase, rule, this.seq++] });
75
+ }
76
+ /** Legacy-ordered warnings. Sorting once at the end is the whole point. */
77
+ ordered() {
78
+ return [...this.items].sort((a, b) => compareKeys(a.key, b.key)).map((d) => d.warning);
79
+ }
80
+ /**
81
+ * The fidelity ledger rides the same ordering discipline as the warnings —
82
+ * an entry's position is declared by (path, band, phase, rule), never by
83
+ * when the engine happened to record it.
84
+ */
85
+ pushFidelity(entry, path, band, phase, rule = 0) {
86
+ this.fidelityItems.push({ entry, key: [...path, band, phase, rule, this.seq++] });
87
+ }
88
+ orderedFidelity() {
89
+ return [...this.fidelityItems].sort((a, b) => compareKeys(a.key, b.key)).map((d) => d.entry);
90
+ }
91
+ get length() {
92
+ return this.items.length;
93
+ }
94
+ }
@@ -8,16 +8,28 @@
8
8
  * id-referenced component list.
9
9
  *
10
10
  * Deterministic by construction: same surface + contract + profile => same
11
- * messages. All projection knowledge is data in the profile's `surfacePlan`
12
- * directives; this engine contains no component-name-specific code.
11
+ * messages. All projection knowledge is data, and this engine contains no
12
+ * component-name-specific code.
13
+ *
14
+ * It also contains no DIRECTIVE-specific code. The engine reads only the
15
+ * internal Identity / Route / Collect model (transform/model.ts); the authored
16
+ * v1 directives are surface syntax that transform/desugar.ts translates, and
17
+ * that module is the only compatibility boundary. src/engine-boundary.test.ts
18
+ * fails if a legacy directive name reappears here.
19
+ *
20
+ * Two orderings are declared rather than emergent, because both are observable
21
+ * in hashed artifacts and neither should be decided by the shape of a method:
22
+ * `WriteOrder` fixes when each route and collect writes (object key order), and
23
+ * the diagnostics' phase/band keys fix the emitted warning sequence.
13
24
  *
14
25
  * Honest scope (mirrors MAPPING.md):
15
- * - Compound composition flattens per the documented casualty mapping
16
- * (`subText` / `subButtonText` consume the node's whole subtree). When no
17
- * label-bearing component carries a `subButtonText` label, the first
18
- * direct text under that sub is LIFTED (audited, `surface-label-lifted`;
19
- * spec v0.4 amendment 2026-07-04) — relocation of existing text, never
20
- * synthesis.
26
+ * - Compound composition flattens per the documented casualty mapping:
27
+ * consuming routes absorb the node's whole subtree, resolved by ONE
28
+ * document-order walk so that position, not declaration order, decides
29
+ * which sibling claims a destination. When no label-bearing component
30
+ * carries a label, the first direct text under that sub is LIFTED (audited,
31
+ * `surface-label-lifted`; spec v0.4 amendment 2026-07-04) — relocation of
32
+ * existing text, never synthesis.
21
33
  * - A2UI requires declarative actions the surface format does not express;
22
34
  * they are synthesized (deterministic event-name slug) and recorded as
23
35
  * warnings, not silently invented.
@@ -26,7 +38,7 @@
26
38
  * are version-independent and instance-validate (gate A3) against both
27
39
  * generated catalogs.
28
40
  */
29
- import type { DspackDoc, DspackSurface, Json, Warning } from "../../types.js";
41
+ import type { DspackDoc, DspackSurface, Json, SurfaceFidelityEntry, Warning } from "../../types.js";
30
42
  import { type Profile } from "../../transform/profiles.js";
31
43
  export declare class EmitSurfaceError extends Error {
32
44
  readonly path: string;
@@ -37,6 +49,13 @@ export interface EmitSurfaceResult {
37
49
  messages: Json[];
38
50
  /** Every synthesis/drop performed — nothing is silent. */
39
51
  warnings: Warning[];
52
+ /**
53
+ * The transformation ledger: what every route, collect, projection, and
54
+ * synthesis DID to this surface — source, destination, originating profile
55
+ * rule, kind, and fidelity class. Additive alongside the byte-frozen
56
+ * messages and warnings; `--strict-surface` fails on configured classes.
57
+ */
58
+ fidelity: SurfaceFidelityEntry[];
40
59
  }
41
60
  export interface EmitSurfaceOptions {
42
61
  profile?: Profile;