@aestheticfunction/dspack-emit 0.5.0 → 0.6.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.
@@ -40,6 +40,18 @@ export function mapDspack(doc: DspackDoc, profile: Profile): MappingResult {
40
40
  const warnings: Warning[] = [];
41
41
 
42
42
  const addComponent = (plan: ComponentPlan) => {
43
+ // T1: a transparent plan emits no catalog entry — nothing can instantiate
44
+ // a component that dissolves at emission. Its disposition is recorded in
45
+ // coverage; its absence from anyComponent is what keeps A3 honest.
46
+ if (surfaceModelOf(plan).transparent) {
47
+ fidelity.push({
48
+ source: `plan.${plan.dspackId ?? plan.a2ui}`,
49
+ target: "(no catalog entry)",
50
+ class: "synthesis-defaults",
51
+ note: "transparent identity: dissolves at emission; children rise to the parent's destination.",
52
+ });
53
+ return;
54
+ }
43
55
  const dspackComp = plan.dspackId ? doc.components?.[plan.dspackId] : undefined;
44
56
  if (plan.dspackId && !dspackComp) {
45
57
  warnings.push({
@@ -109,9 +121,13 @@ function computeCoverage(
109
121
  fidelity: FidelityEntry[],
110
122
  ): CoverageEntry[] {
111
123
  const mapped = new Map<string, string>(); // dspackId -> A2UI name
124
+ const byId = new Map<string, ComponentPlan>();
112
125
  // Both `components` and any `synthesized` plan that declares a `dspackId` count as mapped.
113
126
  for (const p of [...profile.components, ...profile.synthesized]) {
114
- if (p.dspackId) mapped.set(p.dspackId, p.a2ui);
127
+ if (p.dspackId) {
128
+ mapped.set(p.dspackId, p.a2ui);
129
+ byId.set(p.dspackId, p);
130
+ }
115
131
  }
116
132
 
117
133
  const casualties = new Map<string, (typeof profile.casualtyComponents)[number]>();
@@ -122,7 +138,11 @@ function computeCoverage(
122
138
  const coverage: CoverageEntry[] = [];
123
139
  for (const id of Object.keys(doc.components ?? {})) {
124
140
  if (mapped.has(id)) {
125
- coverage.push({ id, disposition: "mapped", detail: `-> ${mapped.get(id)}` });
141
+ coverage.push({
142
+ id,
143
+ disposition: "mapped",
144
+ detail: byId.get(id) && surfaceModelOf(byId.get(id)!).transparent ? "-> (transparent: dissolves at emission)" : `-> ${mapped.get(id)}`,
145
+ });
126
146
  } else if (omitted.has(id)) {
127
147
  coverage.push({ id, disposition: "omitted", detail: "declared in profile.intentionallyOmitted" });
128
148
  } else if (casualties.has(id)) {
@@ -156,10 +176,6 @@ function computeCoverage(
156
176
  // validateProfileAgainstContract refuses them at entry. Measured before
157
177
  // enforcement: pinned shadcn v2.3.0, astryx and acme all derive zero
158
178
  // unresolved subs, so no shipped artifact changes.
159
- const byId = new Map<string, ComponentPlan>();
160
- for (const p of [...profile.components, ...profile.synthesized]) {
161
- if (p.dspackId) byId.set(p.dspackId, p);
162
- }
163
179
  for (const [id, component] of Object.entries(doc.components ?? {})) {
164
180
  const subs =
165
181
  (component as { composition?: { subComponents?: Array<{ id: string }> } }).composition?.subComponents ?? [];
@@ -52,11 +52,36 @@ import type { Json } from "../types.js";
52
52
  export type Identity =
53
53
  /** Emits one instance of the named A2UI component. */
54
54
  | { kind: "mapped"; a2ui: string }
55
- /** Emits nothing; its children rise to the destination its parent would use. */
56
- | { kind: "transparent" }
55
+ /**
56
+ * Emits nothing; its children rise to the destination its parent would use.
57
+ * A transparent identity may carry DONATIONS (T1's constrained control
58
+ * donation): each dissolved instance harvests the donated values from its
59
+ * own subtree and hands them to the single eligible emitted control within
60
+ * that subtree — the boundary IS the scope, which is what makes a
61
+ * three-field form donate three labels to three inputs instead of refusing.
62
+ */
63
+ | { kind: "transparent"; donate?: Donation[] }
57
64
  /** Emits as the profile's synthesized text primitive, carrying its subtree text. */
58
65
  | { kind: "as-text"; variant: string };
59
66
 
67
+ /**
68
+ * One constrained control donation (the ratified `onto: "control"` mechanism):
69
+ * a value harvested inside a dissolving boundary, written onto the boundary's
70
+ * single eligible control. Fail-closed at emit: zero or multiple eligible
71
+ * controls refuse; the receiving plan must declare the destination. The write
72
+ * is carried EXPLICITLY in the rewritten child list and applied as a pre-write
73
+ * when the control's own emission constructs its instance — never by mutating
74
+ * another node's committed instance mid-traversal.
75
+ */
76
+ export interface Donation {
77
+ /** Where the value comes from, inside the dissolving boundary. */
78
+ from: Selector;
79
+ /** The receiving prop on the control (`prop:` destinations only). */
80
+ to: Destination;
81
+ /** Which authored rule produced this — provenance for the ledger. */
82
+ origin: string;
83
+ }
84
+
60
85
  /**
61
86
  * Where information comes from. A closed enumeration: every selector is
62
87
  * statically checkable against the contract before emission runs.
@@ -83,6 +108,22 @@ export type Selector =
83
108
  | { kind: "subtree-text"; subs: string[] }
84
109
  /** This node's ordered children, emitted as instances. */
85
110
  | { kind: "children" }
111
+ /**
112
+ * T4: the ordered children of exactly one descendant instance of the named
113
+ * sub, emitted as instances into a slot. The sub is the compound's declared
114
+ * structural region (dialog-content, sheet-footer, …); its children go
115
+ * through the same rewriting as any parent's child list, so nested subs
116
+ * resolve by THIS plan's dispositions and claimed subs are skipped. Zero
117
+ * instances leave the destination absent (gate A3 arbitrates); more than
118
+ * one refuses — a slot names one region, never a series.
119
+ */
120
+ | { kind: "sub-children"; subs: string[] }
121
+ /**
122
+ * T2: the node's own surface `id`. Item-local — only valid inside a
123
+ * collect's item fields, where each repeated item contributes the one
124
+ * datum it carries (the production radio-group-item carries nothing else).
125
+ */
126
+ | { kind: "self-id" }
86
127
  /** No source: a declarative A2UI action synthesized from a deterministic slug. */
87
128
  | { kind: "synthesized-action" };
88
129
 
@@ -124,6 +165,8 @@ export enum WriteOrder {
124
165
  /** The node's own text. */
125
166
  SelfText = 40,
126
167
  SelfTextChild = 41,
168
+ /** T4 slot routes: instance emission from a named sub's children. */
169
+ Slot = 45,
127
170
  /** Synthesis with no source in the subtree. */
128
171
  Action = 50,
129
172
  /** Children as instance references, once every value destination is settled. */
@@ -157,6 +200,21 @@ export interface Route {
157
200
  export interface Collect {
158
201
  /** When this collect writes, relative to every other route and collect. */
159
202
  order: WriteOrder;
203
+ /**
204
+ * T2 item-mode: each descendant matching `of` becomes ONE RECORD whose
205
+ * fields resolve against that item's own node (self.text, self.props.X,
206
+ * self.id — never joins, never siblings). Mutually exclusive with the
207
+ * table-mode `item`/`scalar` nesting.
208
+ */
209
+ fields?: Record<string, Selector>;
210
+ /**
211
+ * T3: a DECLARED key join onto a sibling sub-family. Each left item's key
212
+ * must match exactly one counterpart (0..1 when `optional`); zero, several,
213
+ * duplicate keys on either side, missing key values, and dangling
214
+ * counterparts all refuse. The profile names the relation; the emitter
215
+ * never infers one — no positions, no nearest-sibling, no similarity.
216
+ */
217
+ join?: CollectJoin;
160
218
  /**
161
219
  * True when every repetition's cells concatenate into ONE flat list (v1's
162
220
  * header semantics: two header rows append into a single column list);
@@ -184,10 +242,39 @@ export interface Collect {
184
242
  * Sub-components this plan explicitly discards, with the authored reason. v1
185
243
  * spelled this inside `subTable.drops`; it is not a table concept.
186
244
  */
245
+ export interface CollectJoin {
246
+ /** The joined sub-family (sub-component or component ids). */
247
+ with: string[];
248
+ /** Key extracted from each LEFT item (item-local selector). */
249
+ leftKey: Selector;
250
+ /** Key extracted from each JOINED item (item-local selector). */
251
+ rightKey: Selector;
252
+ /**
253
+ * Record fields sourced from the JOINED side. Item-local selectors, plus
254
+ * the slot-valued `{ kind: "joined-children" }`: the counterpart's children
255
+ * emit as instances and the record carries the reference — Repetition's
256
+ * ratified slot-valued field, NOT T4 multi-slot routing.
257
+ */
258
+ fields: Record<string, Selector | { kind: "joined-children" }>;
259
+ /** 0..1 counterparts allowed when true; exactly one required otherwise. */
260
+ optional: boolean;
261
+ /** Which authored rule produced this — provenance for the ledger. */
262
+ origin: string;
263
+ }
264
+
187
265
  export type Drops = Record<string, string>;
188
266
 
189
267
  /** The whole of how a plan projects a surface node. Replaces SurfacePlanDirectives. */
190
268
  export interface SurfaceModel {
269
+ /**
270
+ * T1: this plan's component emits NO instance — every node using it
271
+ * dissolves at its parent's child-collection, children rising in place,
272
+ * with `transparentDonate` harvested per dissolved instance. Refused for
273
+ * the surface root at emit (renderers need components[0] = "root").
274
+ */
275
+ transparent: boolean;
276
+ /** Donations carried by a transparent PLAN (per dissolved instance). */
277
+ transparentDonate: Donation[];
191
278
  routes: Route[];
192
279
  collects: Collect[];
193
280
  /** Identity assigned to named sub-components met inside this node's subtree. */
@@ -202,6 +289,8 @@ export interface SurfaceModel {
202
289
  }
203
290
 
204
291
  export const emptySurfaceModel = (): SurfaceModel => ({
292
+ transparent: false,
293
+ transparentDonate: [],
205
294
  routes: [],
206
295
  collects: [],
207
296
  subIdentity: {},
@@ -230,6 +319,10 @@ export function describeSelector(s: Selector): string {
230
319
  return `sub(${s.subs.join("|")}).subtreeText`;
231
320
  case "children":
232
321
  return "children";
322
+ case "sub-children":
323
+ return `sub(${s.subs.join("|")}).children`;
324
+ case "self-id":
325
+ return "self.id";
233
326
  case "synthesized-action":
234
327
  return "synthesized.action";
235
328
  }
@@ -267,17 +360,20 @@ export function referencedSubs(model: SurfaceModel): Map<string, string> {
267
360
  };
268
361
 
269
362
  const fromSelector = (s: Selector, how: string): void => {
270
- if (s.kind === "sub-text" || s.kind === "sub-label" || s.kind === "sub-text-lift" || s.kind === "subtree-text") {
363
+ if (s.kind === "sub-text" || s.kind === "sub-label" || s.kind === "sub-text-lift" || s.kind === "subtree-text" || s.kind === "sub-children") {
271
364
  for (const id of s.subs) note(id, how);
272
365
  }
273
366
  };
274
367
 
275
368
  for (const r of model.routes) {
276
- for (const s of r.from) fromSelector(s, `consumed into ${describeDestination(r.to)}`);
369
+ for (const s of r.from) {
370
+ fromSelector(s, s.kind === "sub-children" ? `routed to ${describeDestination(r.to)}` : `consumed into ${describeDestination(r.to)}`);
371
+ }
277
372
  }
278
373
 
279
374
  const walk = (c: Collect): void => {
280
375
  for (const id of c.of) note(id, `collected into ${describeDestination(c.as)}`);
376
+ if (c.join) for (const id of c.join.with) note(id, `joined into ${describeDestination(c.as)}`);
281
377
  for (const field of Object.values(c.item ?? {})) {
282
378
  if (isCollect(field)) walk(field);
283
379
  else for (const s of field.from) fromSelector(s, `collected into ${describeDestination(field.to)}`);
@@ -287,8 +383,14 @@ export function referencedSubs(model: SurfaceModel): Map<string, string> {
287
383
  for (const c of model.collects) walk(c);
288
384
 
289
385
  for (const [id, identity] of Object.entries(model.subIdentity)) {
290
- note(id, identity.kind === "as-text" ? `re-identified as text (${identity.variant})` : "transparent grouping");
386
+ if (identity.kind === "as-text") {
387
+ note(id, `re-identified as text (${identity.variant})`);
388
+ } else if (identity.kind === "transparent") {
389
+ note(id, "transparent grouping");
390
+ for (const d of identity.donate ?? []) fromSelector(d.from, `donated to ${describeDestination(d.to)}`);
391
+ }
291
392
  }
393
+ for (const d of model.transparentDonate) fromSelector(d.from, `donated to ${describeDestination(d.to)}`);
292
394
  for (const [id, reason] of Object.entries(model.drops)) note(id, `dropped: ${reason}`);
293
395
 
294
396
  return subs;
@@ -14,12 +14,11 @@
14
14
  * computed destination names, and no cross-instance routing. Those absences
15
15
  * are the design: a plan you cannot write is a plan nobody has to audit.
16
16
  *
17
- * Capability note: v2 in this foundation expresses exactly the transformation
18
- * surface the engine has today — the v1 semantic surface, respelled. The
19
- * grammar refuses spellings whose engine support has not landed (plan-level
20
- * `transparent` identity, `onto` donation, `joinOn` pairing, multi-slot
21
- * children routing). Each arrives with its capability class (T1–T5), as an
22
- * addition to this grammar, never as a reinterpretation of it.
17
+ * Capability note: the grammar admits exactly what the engine can emit. T1
18
+ * (transparent identity + constrained control donation) landed as the
19
+ * `transparent` / `donate` spellings below; spellings whose engine support
20
+ * has not landed (`joinOn` pairing — T3, multi-slot children routing — T4,
21
+ * variant identity — T5) are still refused, never reinterpreted.
23
22
  */
24
23
  import type { ComponentPlan } from "./profiles.js";
25
24
  import {
@@ -27,7 +26,9 @@ import {
27
26
  emptySurfaceModel,
28
27
  isCollect,
29
28
  type Collect,
29
+ type CollectJoin,
30
30
  type Destination,
31
+ type Donation,
31
32
  type Route,
32
33
  type Selector,
33
34
  type SurfaceModel,
@@ -65,23 +66,61 @@ export interface SurfaceV2Route {
65
66
  }
66
67
 
67
68
  export interface SurfaceV2Collect {
68
- /** Sections: direct children that open the collection. */
69
+ /** Sections (table-mode) or the repeated items themselves (item-mode). */
69
70
  of: string[];
70
71
  /** Array-valued destination (`prop:<name>`). */
71
72
  into: string;
72
- /** `flat`: all rows concatenate into one list. `records`: one record per row. */
73
- shape: "flat" | "records";
74
- /** Record field carrying each row's cells; required when shape is `records`. */
73
+ /** table-mode: `flat` concatenates all rows into one list; `records` keeps one record per row. */
74
+ shape?: "flat" | "records";
75
+ /** table-mode: record field carrying each row's cells; required when shape is `records`. */
75
76
  field?: string;
76
- /** Repetitions inside a section. */
77
- row: string[];
78
- /** Cells inside a repetition, flattened to their subtree text. */
79
- cells: string[];
77
+ /** table-mode: repetitions inside a section. */
78
+ row?: string[];
79
+ /** table-mode: cells inside a repetition, flattened to their subtree text. */
80
+ cells?: string[];
81
+ /**
82
+ * T2 item-mode: each matching descendant becomes one record; every field
83
+ * resolves against THAT item's own node. Selectors: `self.text`,
84
+ * `self.props.<prop>`, `self.id`.
85
+ */
86
+ item?: Record<string, string>;
87
+ /**
88
+ * T3: a DECLARED key join onto a sibling sub-family. `on.left` extracts the
89
+ * key from each item, `on.right` from each counterpart; `fields` source
90
+ * record fields from the JOINED side (item-local selectors, or the literal
91
+ * `"children"` for the slot-valued field: the counterpart's children emit
92
+ * as instances and the record carries the reference). `optional: true`
93
+ * relaxes exactly-one to 0..1. The profile names the relation; nothing is
94
+ * ever inferred from position or adjacency.
95
+ */
96
+ join?: {
97
+ with: string[];
98
+ on: { left: string; right: string };
99
+ fields: Record<string, string>;
100
+ optional?: boolean;
101
+ };
80
102
  }
81
103
 
82
- export type SurfaceV2Sub = "transparent" | { asText: string } | { drop: string };
104
+ export interface SurfaceV2Donate {
105
+ /** `self.text` or `sub(<id>|…).text` — where the donated value comes from. */
106
+ from: string;
107
+ /** `prop:<name>` on the boundary's single eligible control. */
108
+ to: string;
109
+ }
110
+
111
+ export type SurfaceV2Sub =
112
+ | "transparent"
113
+ | { transparent: true | { donate: SurfaceV2Donate[] } }
114
+ | { asText: string }
115
+ | { drop: string };
83
116
 
84
117
  export interface SurfaceV2 {
118
+ /**
119
+ * T1 transparent identity: this component emits no instance; children rise.
120
+ * `true`, or an object carrying constrained control donations scoped to
121
+ * each dissolved instance's subtree.
122
+ */
123
+ transparent?: true | { donate: SurfaceV2Donate[] };
85
124
  routes?: SurfaceV2Route[];
86
125
  collects?: SurfaceV2Collect[];
87
126
  /** Identity or disposition of named sub-components met in this node's subtree. */
@@ -95,7 +134,7 @@ export interface SurfaceV2 {
95
134
  const ID = "[a-z][a-z0-9-]*";
96
135
  const PROP = "[A-Za-z][A-Za-z0-9]*";
97
136
  const SELECTOR = new RegExp(
98
- `^(self\\.text|self\\.props\\.(${PROP})|sub\\((${ID}(?:\\|${ID})*)\\)\\.(text|label|firstText|subtreeText)|children|synthesized\\.action)$`,
137
+ `^(self\\.text|self\\.id|self\\.props\\.(${PROP})|sub\\((${ID}(?:\\|${ID})*)\\)\\.(text|label|firstText|subtreeText|children)|children|synthesized\\.action)$`,
99
138
  );
100
139
  const DESTINATION = new RegExp(`^(prop|textChild|slot|slots|action):(${PROP})$`);
101
140
 
@@ -103,6 +142,7 @@ export function parseSelector(raw: string): Selector | null {
103
142
  const m = SELECTOR.exec(raw);
104
143
  if (!m) return null;
105
144
  if (m[1] === "self.text") return { kind: "self-text" };
145
+ if (m[1] === "self.id") return { kind: "self-id" };
106
146
  if (m[1] === "children") return { kind: "children" };
107
147
  if (m[1] === "synthesized.action") return { kind: "synthesized-action" };
108
148
  if (m[2]) return { kind: "self-prop", prop: m[2] };
@@ -114,6 +154,8 @@ export function parseSelector(raw: string): Selector | null {
114
154
  return { kind: "sub-label", subs };
115
155
  case "firstText":
116
156
  return { kind: "sub-text-lift", subs };
157
+ case "children":
158
+ return { kind: "sub-children", subs };
117
159
  default:
118
160
  return { kind: "subtree-text", subs };
119
161
  }
@@ -154,8 +196,12 @@ function orderOfSelector(s: Selector, to: Destination): WriteOrder {
154
196
  return WriteOrder.CollectLead;
155
197
  case "self-text":
156
198
  return to.kind === "text-child" ? WriteOrder.SelfTextChild : WriteOrder.SelfText;
199
+ case "self-id":
200
+ return WriteOrder.SelfText; // unreachable in routes: `compatible` refuses it
157
201
  case "synthesized-action":
158
202
  return WriteOrder.Action;
203
+ case "sub-children":
204
+ return WriteOrder.Slot;
159
205
  case "children":
160
206
  return WriteOrder.Children;
161
207
  }
@@ -166,10 +212,15 @@ function compatible(s: Selector, to: Destination): boolean {
166
212
  switch (s.kind) {
167
213
  case "children":
168
214
  return to.kind === "slot" || to.kind === "slots";
215
+ case "sub-children":
216
+ // T4: instance emission from a named region lands in exactly one slot.
217
+ return to.kind === "slot";
169
218
  case "synthesized-action":
170
219
  return to.kind === "action";
171
220
  case "self-text":
172
221
  return to.kind === "prop" || to.kind === "text-child";
222
+ case "self-id":
223
+ return false; // item-field-only: a route may not read self.id
173
224
  default:
174
225
  return to.kind === "prop";
175
226
  }
@@ -189,10 +240,53 @@ function compatible(s: Selector, to: Destination): boolean {
189
240
  * self-props are declared, derived coverage is complete) run at transform
190
241
  * time, where the contract is in hand — see validate-v2.ts.
191
242
  */
243
+ /** Parses one donate entry; donation selectors and destinations are narrower than routes'. */
244
+ function parseDonation(d: SurfaceV2Donate, at: string, issues: ParseIssue[], origin: string): Donation | null {
245
+ const from = parseSelector(d.from);
246
+ if (!from || (from.kind !== "self-text" && from.kind !== "sub-text")) {
247
+ issues.push({ path: `${at}/from`, message: `'${d.from}' is not a donation source (donations harvest text: self.text or sub(<id>|…).text)` });
248
+ return null;
249
+ }
250
+ const to = parseDestination(d.to);
251
+ if (!to || to.kind !== "prop") {
252
+ issues.push({ path: `${at}/to`, message: `'${d.to}' is not a donation destination (donations write prop:<name> on the receiving control)` });
253
+ return null;
254
+ }
255
+ return { from, to, origin };
256
+ }
257
+
192
258
  export function parseSurfaceV2(surface: SurfaceV2, plan: ComponentPlan, path: string): SurfaceModel {
193
259
  const issues: ParseIssue[] = [];
194
260
  const model = emptySurfaceModel();
195
261
 
262
+ // T1: transparent identity. A transparent plan emits nothing, so nothing it
263
+ // could declare for an instance is meaningful — routes, collects, structural
264
+ // slots, propMap, required all refuse. Only sub dispositions (for its own
265
+ // dissolved subtree) and donations survive.
266
+ if (surface.transparent !== undefined) {
267
+ model.transparent = true;
268
+ if (typeof surface.transparent === "object") {
269
+ surface.transparent.donate.forEach((d, i) => {
270
+ const parsed = parseDonation(d, `${path}/transparent/donate/${i}`, issues, `v2:transparent/donate/${i}`);
271
+ if (parsed) model.transparentDonate.push(parsed);
272
+ });
273
+ }
274
+ if ((surface.routes ?? []).length > 0 || (surface.collects ?? []).length > 0) {
275
+ issues.push({ path, message: "a transparent plan emits no instance; routes and collects have nowhere to land (donations are the only writes it may carry)" });
276
+ }
277
+ for (const [field, label] of [
278
+ [plan.structural ?? {}, "structural"],
279
+ [plan.propMap ?? {}, "propMap"],
280
+ ] as const) {
281
+ if (Object.keys(field).length > 0) {
282
+ issues.push({ path, message: `a transparent plan declares no catalog surface; remove its ${label} block` });
283
+ }
284
+ }
285
+ if ((plan.required ?? []).length > 0) {
286
+ issues.push({ path, message: "a transparent plan declares no catalog surface; remove its required list" });
287
+ }
288
+ }
289
+
196
290
  // The plan's own declared destination names: structural slots plus the
197
291
  // a2ui-side names its propMap writes. Gate A3 catches an OMITTED property
198
292
  // but silently passes an INVENTED one, so this is where invention dies.
@@ -325,6 +419,98 @@ export function parseSurfaceV2(surface: SurfaceV2, plan: ComponentPlan, path: st
325
419
  if (!declared.has(into.name)) {
326
420
  issues.push({ path: `${at}/into`, message: `destination '${into.name}' is not declared by this plan` });
327
421
  }
422
+
423
+ // T2 item-mode and table-mode are distinct shapes; mixing them is a
424
+ // contradiction, not a preference.
425
+ const itemMode = c.item !== undefined;
426
+ const tableKeys = [c.shape, c.field, c.row, c.cells].some((v) => v !== undefined);
427
+ if (itemMode && tableKeys) {
428
+ issues.push({ path: at, message: "a collect is either item-mode (item) or table-mode (shape/row/cells/field), never both" });
429
+ continue;
430
+ }
431
+ if (itemMode) {
432
+ const fields: Record<string, Selector> = {};
433
+ let ok = true;
434
+ for (const [fieldName, raw] of Object.entries(c.item!)) {
435
+ const sel = parseSelector(raw);
436
+ const itemLocal = sel && (sel.kind === "self-text" || sel.kind === "self-prop" || sel.kind === "self-id");
437
+ if (!itemLocal) {
438
+ issues.push({
439
+ path: `${at}/item/${fieldName}`,
440
+ message: `'${raw}' is not an item field source (item fields resolve on the item's own node: self.text, self.props.<prop>, self.id — sibling reads and joins are T3)`,
441
+ });
442
+ ok = false;
443
+ continue;
444
+ }
445
+ fields[fieldName] = sel;
446
+ }
447
+ if (!ok || Object.keys(fields).length === 0) {
448
+ if (Object.keys(c.item!).length === 0) issues.push({ path: `${at}/item`, message: "an item-mode collect names at least one field" });
449
+ continue;
450
+ }
451
+ // T3 join, only on item-mode collects.
452
+ let join: CollectJoin | undefined;
453
+ if (c.join) {
454
+ const jAt = `${at}/join`;
455
+ const left = parseSelector(c.join.on.left);
456
+ const right = parseSelector(c.join.on.right);
457
+ const itemLocal = (sel: Selector | null): sel is Selector =>
458
+ sel !== null && (sel.kind === "self-text" || sel.kind === "self-prop" || sel.kind === "self-id");
459
+ let jOk = true;
460
+ if (!itemLocal(left)) {
461
+ issues.push({ path: `${jAt}/on/left`, message: `'${c.join.on.left}' is not a join key source (item-local: self.id, self.props.<prop>, self.text)` });
462
+ jOk = false;
463
+ }
464
+ if (!itemLocal(right)) {
465
+ issues.push({ path: `${jAt}/on/right`, message: `'${c.join.on.right}' is not a join key source (item-local: self.id, self.props.<prop>, self.text)` });
466
+ jOk = false;
467
+ }
468
+ const jFields: CollectJoin["fields"] = {};
469
+ for (const [fieldName, raw] of Object.entries(c.join.fields)) {
470
+ if (raw === "children") {
471
+ jFields[fieldName] = { kind: "joined-children" };
472
+ continue;
473
+ }
474
+ const sel = parseSelector(raw);
475
+ if (!itemLocal(sel)) {
476
+ issues.push({ path: `${jAt}/fields/${fieldName}`, message: `'${raw}' is not a joined-side field source (item-local selectors, or "children" for the slot-valued field)` });
477
+ jOk = false;
478
+ continue;
479
+ }
480
+ jFields[fieldName] = sel;
481
+ }
482
+ for (const fieldName of Object.keys(jFields)) {
483
+ if (fieldName in fields) {
484
+ issues.push({ path: `${jAt}/fields/${fieldName}`, message: `field '${fieldName}' is already sourced from the left item; one record field, one source` });
485
+ jOk = false;
486
+ }
487
+ }
488
+ if (Object.keys(jFields).length === 0) {
489
+ issues.push({ path: `${jAt}/fields`, message: "a join names at least one joined-side field — a join that contributes nothing is not a relation" });
490
+ jOk = false;
491
+ }
492
+ if (jOk) {
493
+ join = { with: c.join.with, leftKey: left as Selector, rightKey: right as Selector, fields: jFields, optional: c.join.optional === true, origin: `v2:collects/${i}/join` };
494
+ } else {
495
+ continue;
496
+ }
497
+ }
498
+ claim(into.name, WriteOrder.Collect, `collects/${i}`, `${at}/into`);
499
+ model.collects.push({
500
+ order: WriteOrder.Collect,
501
+ flatten: false,
502
+ of: c.of,
503
+ as: into,
504
+ fields,
505
+ ...(join ? { join } : {}),
506
+ origin: `v2:collects/${i}`,
507
+ });
508
+ continue;
509
+ }
510
+ if (c.shape === undefined || c.row === undefined || c.cells === undefined) {
511
+ issues.push({ path: at, message: "a table-mode collect declares shape, row, and cells (or use item-mode with `item`)" });
512
+ continue;
513
+ }
328
514
  if (c.shape === "records" && !c.field) {
329
515
  issues.push({ path: `${at}/field`, message: "a records collect names the field its rows' cells land in" });
330
516
  continue;
@@ -359,6 +545,15 @@ export function parseSurfaceV2(surface: SurfaceV2, plan: ComponentPlan, path: st
359
545
  const at = `${path}/subs/${sub}`;
360
546
  if (disposition === "transparent") {
361
547
  model.subIdentity[sub] = { kind: "transparent" };
548
+ } else if (typeof disposition === "object" && "transparent" in disposition) {
549
+ const donate: Donation[] = [];
550
+ if (typeof disposition.transparent === "object") {
551
+ disposition.transparent.donate.forEach((d, i) => {
552
+ const parsed = parseDonation(d, `${at}/transparent/donate/${i}`, issues, `v2:subs/${sub}/donate/${i}`);
553
+ if (parsed) donate.push(parsed);
554
+ });
555
+ }
556
+ model.subIdentity[sub] = donate.length > 0 ? { kind: "transparent", donate } : { kind: "transparent" };
362
557
  } else if ("asText" in disposition) {
363
558
  model.subIdentity[sub] = { kind: "as-text", variant: disposition.asText };
364
559
  } else {
@@ -381,7 +576,23 @@ export function parseSurfaceV2(surface: SurfaceV2, plan: ComponentPlan, path: st
381
576
  // also emit that subtree as children.
382
577
  model.consumesSubtree =
383
578
  model.collects.length > 0 ||
384
- model.routes.some((r) => r.order === WriteOrder.Consume || r.order === WriteOrder.CollectLead);
579
+ model.routes.some((r) => r.order === WriteOrder.Consume || r.order === WriteOrder.CollectLead || r.order === WriteOrder.Slot);
580
+
581
+ // T4: one region, one slot — a sub named by several sub-children routes
582
+ // (or the same route naming several subs) would make one child list land
583
+ // twice; and a mixed from-list has no fallback semantics for regions.
584
+ const slotRoutes = model.routes.filter((r) => r.from.some((sel) => sel.kind === "sub-children"));
585
+ for (const r of slotRoutes) {
586
+ if (r.from.length !== 1 || r.from[0].kind !== "sub-children") {
587
+ issues.push({ path, message: `a sub(x).children route takes exactly one selector — regions have no fallback chain` });
588
+ } else if (r.from[0].subs.length !== 1) {
589
+ issues.push({ path, message: `sub(${r.from[0].subs.join("|")}).children names ${r.from[0].subs.length} subs; a slot route names exactly one region` });
590
+ }
591
+ }
592
+ const slotSources = slotRoutes.flatMap((r) => (r.from[0].kind === "sub-children" ? r.from[0].subs : []));
593
+ for (const dup of slotSources.filter((id, i) => slotSources.indexOf(id) !== i)) {
594
+ issues.push({ path, message: `sub-component '${dup}' is the source of more than one slot route; one region, one slot` });
595
+ }
385
596
 
386
597
  const childrenRoute = model.routes.find((r) => r.from[0].kind === "children");
387
598
  if (model.consumesSubtree && childrenRoute) {