@serene-pub/sdk 0.6.0-pr-4 → 0.6.0-pr-5

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 (186) hide show
  1. package/README.md +23 -19
  2. package/dist/actions.d.ts +149 -67
  3. package/dist/actions.js +89 -35
  4. package/dist/annexFields.d.ts +8 -4
  5. package/dist/annexFields.js +5 -2
  6. package/dist/announce.d.ts +78 -28
  7. package/dist/announce.js +14 -5
  8. package/dist/attributes.d.ts +9 -6
  9. package/dist/attributes.js +9 -5
  10. package/dist/bands.d.ts +41 -6
  11. package/dist/bands.js +83 -33
  12. package/dist/builder.d.ts +161 -58
  13. package/dist/builder.js +128 -22
  14. package/dist/candidates.d.ts +5 -3
  15. package/dist/candidates.js +3 -2
  16. package/dist/clauses.d.ts +2 -1
  17. package/dist/clauses.js +2 -1
  18. package/dist/component.d.ts +24 -7
  19. package/dist/component.js +16 -6
  20. package/dist/componentBuild.d.ts +16 -5
  21. package/dist/componentBuild.js +14 -5
  22. package/dist/componentClient.d.ts +61 -30
  23. package/dist/componentClient.js +11 -1
  24. package/dist/componentImports.d.ts +8 -5
  25. package/dist/componentImports.js +23 -4
  26. package/dist/componentModule.js +2 -1
  27. package/dist/componentWire.d.ts +2 -1
  28. package/dist/componentWire.js +34 -2
  29. package/dist/config.d.ts +28 -14
  30. package/dist/config.js +20 -10
  31. package/dist/connections.d.ts +9 -4
  32. package/dist/connections.js +7 -4
  33. package/dist/declarations.d.ts +46 -17
  34. package/dist/declarations.js +46 -15
  35. package/dist/descriptors.d.ts +242 -97
  36. package/dist/descriptors.js +145 -41
  37. package/dist/dev.d.ts +6 -5
  38. package/dist/dev.js +6 -5
  39. package/dist/document.d.ts +74 -25
  40. package/dist/document.js +32 -11
  41. package/dist/dowry.d.ts +241 -0
  42. package/dist/dowry.js +315 -0
  43. package/dist/engines.d.ts +16 -7
  44. package/dist/engines.js +6 -4
  45. package/dist/eventMapLaws.d.ts +19 -8
  46. package/dist/eventMapLaws.js +9 -6
  47. package/dist/events.d.ts +101 -39
  48. package/dist/events.js +106 -33
  49. package/dist/executor.d.ts +122 -41
  50. package/dist/executor.js +188 -95
  51. package/dist/extension.d.ts +99 -35
  52. package/dist/extension.js +43 -9
  53. package/dist/facets.d.ts +2 -1
  54. package/dist/facets.js +4 -2
  55. package/dist/foldedSections.d.ts +4 -2
  56. package/dist/foldedSections.js +2 -1
  57. package/dist/genres.d.ts +123 -41
  58. package/dist/genres.js +127 -22
  59. package/dist/guardedConnection.d.ts +4 -3
  60. package/dist/guardedConnection.js +4 -3
  61. package/dist/handlebarsReach.d.ts +1 -1
  62. package/dist/handlebarsReach.js +1 -1
  63. package/dist/hash.d.ts +16 -5
  64. package/dist/hash.js +14 -4
  65. package/dist/hookGrants.d.ts +3 -2
  66. package/dist/hookGrants.js +6 -4
  67. package/dist/hooks.d.ts +21 -16
  68. package/dist/hooks.js +12 -10
  69. package/dist/hostElements.d.ts +41 -17
  70. package/dist/hostElements.js +49 -17
  71. package/dist/i18n.d.ts +5 -3
  72. package/dist/i18n.js +5 -3
  73. package/dist/identity.d.ts +4 -3
  74. package/dist/identity.js +4 -3
  75. package/dist/index.d.ts +5 -0
  76. package/dist/index.js +15 -0
  77. package/dist/layout.d.ts +36 -15
  78. package/dist/layout.js +2 -2
  79. package/dist/loadouts.d.ts +97 -0
  80. package/dist/loadouts.js +81 -0
  81. package/dist/media.d.ts +26 -4
  82. package/dist/media.js +2 -1
  83. package/dist/messageBlocks.d.ts +44 -32
  84. package/dist/messageBlocks.js +23 -18
  85. package/dist/migration.d.ts +16 -8
  86. package/dist/migration.js +14 -8
  87. package/dist/names.d.ts +2 -1
  88. package/dist/names.js +2 -1
  89. package/dist/nodeInput.d.ts +2 -1
  90. package/dist/nodeInput.js +2 -1
  91. package/dist/participants.d.ts +22 -15
  92. package/dist/participants.js +14 -12
  93. package/dist/personGate.d.ts +2 -1
  94. package/dist/personGate.js +2 -1
  95. package/dist/pluginHarness.d.ts +8 -3
  96. package/dist/pluginHarness.js +4 -2
  97. package/dist/pluginPermissions.d.ts +2 -1
  98. package/dist/pluginPermissions.js +12 -1
  99. package/dist/pluginRuleRef.d.ts +2 -2
  100. package/dist/pluginRuleRef.js +1 -1
  101. package/dist/predicates.d.ts +16 -11
  102. package/dist/predicates.js +7 -6
  103. package/dist/preview.d.ts +8 -3
  104. package/dist/preview.js +2 -1
  105. package/dist/promptBlocks.d.ts +5 -3
  106. package/dist/promptBlocks.js +5 -3
  107. package/dist/rankingDecisions.d.ts +2 -1
  108. package/dist/rankingDecisions.js +2 -1
  109. package/dist/receipt.d.ts +65 -29
  110. package/dist/receipt.js +9 -4
  111. package/dist/receiverRules.js +3 -2
  112. package/dist/refs.d.ts +34 -9
  113. package/dist/refs.js +33 -13
  114. package/dist/registry.d.ts +42 -23
  115. package/dist/registry.js +7 -5
  116. package/dist/review.d.ts +16 -5
  117. package/dist/review.js +11 -4
  118. package/dist/sampling.d.ts +54 -0
  119. package/dist/sampling.js +95 -3
  120. package/dist/sceneSettings.d.ts +312 -0
  121. package/dist/sceneSettings.js +425 -0
  122. package/dist/scope.d.ts +6 -4
  123. package/dist/scope.js +4 -3
  124. package/dist/scripts.d.ts +81 -14
  125. package/dist/scripts.js +90 -11
  126. package/dist/sessionDossier.d.ts +521 -0
  127. package/dist/sessionDossier.js +33 -0
  128. package/dist/sessionLayout.d.ts +303 -19
  129. package/dist/sessionLayout.js +354 -40
  130. package/dist/sessionSettings.d.ts +8 -5
  131. package/dist/settings.d.ts +45 -20
  132. package/dist/settings.js +19 -12
  133. package/dist/settingsSlot.d.ts +11 -8
  134. package/dist/settingsSlot.js +11 -8
  135. package/dist/shapes.d.ts +99 -36
  136. package/dist/shapes.js +101 -35
  137. package/dist/sheets.d.ts +4 -2
  138. package/dist/sheets.js +6 -3
  139. package/dist/statShapes.d.ts +2 -1
  140. package/dist/statShapes.js +2 -1
  141. package/dist/status.d.ts +13 -9
  142. package/dist/status.js +8 -6
  143. package/dist/storage.d.ts +2 -1
  144. package/dist/storage.js +2 -1
  145. package/dist/storyTime.d.ts +13 -7
  146. package/dist/storyTime.js +11 -6
  147. package/dist/strokes.d.ts +176 -0
  148. package/dist/strokes.js +281 -0
  149. package/dist/surfaces.d.ts +54 -25
  150. package/dist/surfaces.js +3 -3
  151. package/dist/template.d.ts +9 -5
  152. package/dist/template.js +5 -3
  153. package/dist/templateCheck.d.ts +2 -2
  154. package/dist/templateCheck.js +2 -2
  155. package/dist/templateFit.d.ts +37 -8
  156. package/dist/templateFit.js +92 -8
  157. package/dist/templateIds.d.ts +3 -3
  158. package/dist/templateIds.js +3 -3
  159. package/dist/templateScopeAt.d.ts +21 -11
  160. package/dist/templateScopeAt.js +21 -11
  161. package/dist/testing.d.ts +11 -4
  162. package/dist/testing.js +13 -5
  163. package/dist/tokenizers.d.ts +2 -2
  164. package/dist/tokenizers.js +2 -2
  165. package/dist/turnLock.d.ts +4 -2
  166. package/dist/turnLock.js +2 -1
  167. package/dist/turnOrder.d.ts +17 -11
  168. package/dist/turnOrder.js +9 -5
  169. package/dist/validate.d.ts +11 -8
  170. package/dist/validate.js +81 -10
  171. package/dist/values.d.ts +17 -8
  172. package/dist/values.js +11 -6
  173. package/dist/variables.d.ts +46 -7
  174. package/dist/variables.js +87 -6
  175. package/dist/verdicts.d.ts +20 -13
  176. package/dist/verdicts.js +17 -11
  177. package/dist/widgetDecls.d.ts +8 -4
  178. package/dist/widgetDecls.js +4 -2
  179. package/dist/widgets.d.ts +987 -94
  180. package/dist/widgets.js +93 -18
  181. package/dist/wire.d.ts +13 -6
  182. package/dist/wire.js +3 -3
  183. package/dist/worldinfo.d.ts +11 -6
  184. package/dist/worldinfo.js +8 -4
  185. package/host-elements.d.ts +13 -0
  186. package/package.json +1 -1
package/dist/builder.js CHANGED
@@ -1,32 +1,61 @@
1
1
  /**
2
- * The builder (04 §4). Kind-named methods — `.inlet() .query() .task() .oracle()
2
+ * The builder. Kind-named methods — `.inlet() .query() .task() .oracle()
3
3
  * .outlet()` — so reading a spec top to bottom shows the effect taxonomy, and so
4
4
  * the type system can enforce laws that a generic .step() could only find at
5
- * validation time (04 §4a). Clauses are `.gather() .each() .loop() .junction()`
6
- * (R-14, ruled 2026-09-15).
5
+ * validation time. Clauses are `.gather() .each() .loop() .junction()`.
7
6
  *
8
7
  * The chain is a *value*. It compiles to a document; SP imports the document and
9
- * never this code (F6).
8
+ * never this code.
10
9
  *
11
10
  * Every node method takes either a pinned constructor or a **callback that receives the
12
11
  * scope** — `$ => C.assemble({ messages: $.history.messages })`. The callback form is
13
12
  * preferred: it types the node key and the port, and it makes a forward reference
14
13
  * impossible to write rather than a finding to read (src/scope.ts). Both forms compile
15
14
  * to the same rows.
15
+ * @ruling 04 §4, 04 §4a, R-14 (2026-09-15), F6
16
16
  */
17
17
  import { eventsLockFindings, swapFitFinding, } from './descriptors.js';
18
18
  import { makeScope, ITEM } from './scope.js';
19
- import { isDataRef, isSlotRef } from './refs.js';
19
+ import { isDataRef, isSlotRef, slot } from './refs.js';
20
20
  import { assertSpecId, parseSpecId } from './identity.js';
21
21
  import { TURN_ORDER_CHANGED_IS_INTERNAL, genreIdOf, sessionEvents } from './genres.js';
22
22
  import { eventById, isSessionEventDecl, notADeclaredEvent, packageEventById } from './events.js';
23
23
  import { i18nFindings } from './i18n.js';
24
+ import { rendersProblem } from './bands.js';
24
25
  import { actionFindings, normalizeContributes, slashCollisions, } from './actions.js';
26
+ import { boundaryTriggerFindings } from './sceneSettings.js';
25
27
  /**
26
- * The stored mark (R28): swaps as ids, present only when non-empty and
28
+ * A placement's `renders`, checked against its definition and stored as ids
29
+ * — `undefined` when it says nothing, so a node that states none hashes as it
30
+ * always did.
31
+ */
32
+ function rendersOf(key, pinned, renders) {
33
+ const out = {};
34
+ const slots = Object.values((pinned.slots ?? {}))
35
+ .filter((s) => s.kind === 'variables');
36
+ const rendered = slots.flatMap((s) => Object.keys(s.renders ?? {}));
37
+ for (const [k, v] of Object.entries(renders)) {
38
+ const id = typeof v === 'string' ? v : v?.id;
39
+ // Saying a key means what its definition already says is no statement:
40
+ // not stored, so it does not move the document's hash.
41
+ if (slots.some((s) => s.renders?.[k] === id))
42
+ continue;
43
+ if (!rendered.includes(k))
44
+ throw new Error(`node '${key}': renders names '${k}', which '${pinned.id}' does not render — a spec says ` +
45
+ `what a key means, it does not add one. It renders ${rendered.map((r) => `'${r}'`).join(', ') || 'nothing'}.`);
46
+ const problem = rendersProblem(k, id);
47
+ if (problem)
48
+ throw new Error(`node '${key}': renders ${problem}`);
49
+ out[k] = id;
50
+ }
51
+ return Object.keys(out).length ? out : undefined;
52
+ }
53
+ /**
54
+ * The stored mark: swaps as ids, present only when non-empty and
27
55
  * implying `session: true`, plus the streaming step and step status
28
- * (B3/B18) when stated; `undefined` when the mark says nothing, so a
56
+ * when stated; `undefined` when the mark says nothing, so a
29
57
  * node that declares nothing hashes as it always did.
58
+ * @ruling R28, B3/B18
30
59
  */
31
60
  function exposeOf(key, pinned, expose) {
32
61
  if (expose.session === false && expose.swaps?.length)
@@ -71,10 +100,11 @@ export function isModelCall(def) {
71
100
  export const stepPurposeRefusal = (key, definitionId) => `node '${key}': expose.purpose says what a model call is for, but ${definitionId} calls no model — ` +
72
101
  `put the purpose on the oracle that does, or give this step a label instead`;
73
102
  /**
74
- * The swap list a node declares, refused where it cannot work (R28, R26):
103
+ * The swap list a node declares, refused where it cannot work:
75
104
  * a swap that does not fit would seat a node the spec's edges and config
76
105
  * cannot feed, and a person would pick it and get a broken run with no
77
106
  * sentence. Returns the stored form — definition ids.
107
+ * @ruling R28, R26
78
108
  */
79
109
  function swapIds(key, pinned, swaps) {
80
110
  const out = [];
@@ -176,6 +206,12 @@ class ChainBuilder {
176
206
  const expose = opts?.expose ? exposeOf(key, node.descriptor, opts.expose) : undefined;
177
207
  return expose ? { expose } : {};
178
208
  })(),
209
+ // Only when stated, for the same reason as `expose`.
210
+ ...(opts?.prefers && Object.keys(opts.prefers).length ? { prefers: { ...opts.prefers } } : {}),
211
+ ...(() => {
212
+ const renders = opts?.renders ? rendersOf(key, node.descriptor, opts.renders) : undefined;
213
+ return renders ? { renders } : {};
214
+ })(),
179
215
  });
180
216
  return this;
181
217
  }
@@ -196,10 +232,11 @@ class ChainBuilder {
196
232
  return clause;
197
233
  }
198
234
  /**
199
- * A **gather** clause: several chains collected and awaited together (01 §4).
200
- * `mode` is a setting — by the equivalence law (C8) parallel and sequential
235
+ * A **gather** clause: several chains collected and awaited together.
236
+ * `mode` is a setting — by the equivalence law parallel and sequential
201
237
  * are unobservable, which is why the construct is named for what it does
202
238
  * (gather) and not for how (was `.async()`).
239
+ * @ruling 01 §4, C8
203
240
  */
204
241
  gather(id, opts, fn) {
205
242
  const qualified = this.qualify(id);
@@ -212,7 +249,10 @@ class ChainBuilder {
212
249
  fn(new GatherBuilder(this.spec, qualified));
213
250
  return this;
214
251
  }
215
- /** An **each** clause: one contained chain, once per item of a list (01 §4). Was `.map()`. */
252
+ /**
253
+ * An **each** clause: one contained chain, once per item of a list. Was `.map()`.
254
+ * @ruling 01 §4
255
+ */
216
256
  each(id, opts, fn) {
217
257
  const qualified = this.qualify(id);
218
258
  this.declareClause({
@@ -228,7 +268,7 @@ class ChainBuilder {
228
268
  }
229
269
  /**
230
270
  * One contained chain, repeated while a declared port stays truthy — bounded by a
231
- * mandatory `max` (01 §4a).
271
+ * mandatory `max`.
232
272
  *
233
273
  * This is the construct that makes tool-calling expressible on the spine. It is **not
234
274
  * a back-edge**: like `each`, the repetition lives in the clause's declaration rather
@@ -237,6 +277,7 @@ class ChainBuilder {
237
277
  * instead of a list length.
238
278
  *
239
279
  * Always sequential — each iteration depends on the last, so `mode` would be a lie.
280
+ * @ruling 01 §4a
240
281
  */
241
282
  loop(id, opts, fn) {
242
283
  const qualified = this.qualify(id);
@@ -265,18 +306,19 @@ class ChainBuilder {
265
306
  }
266
307
  /**
267
308
  * A **junction** clause (was `.route()`): branches selected by declared
268
- * predicates over a value on the spine (20 §10). Any subset fires — one,
309
+ * predicates over a value on the spine. Any subset fires — one,
269
310
  * several, or none — plus an optional `otherwise` that fires exactly when
270
311
  * nothing else did. The decision is *data a task computed* (the value the
271
312
  * junction is `on`); the branching is declaration; the receipt records
272
313
  * every predicate's evaluation, fired and skipped alike. Not a back-edge
273
314
  * and not code in the executor — the loop clause's whole argument, applied
274
- * to fan-out. 01 §4 amended: branching exists as a declared junction; no
315
+ * to fan-out. Branching exists as a declared junction; there are no
275
316
  * back-edges.
276
317
  *
277
318
  * Skipped branches publish `halt('not selected')` results marked
278
319
  * `fired: false`; the union's `ok`/`values` read the *fired* branches, so
279
- * downstream folds see what ran, in declaration order (13 §1).
320
+ * downstream folds see what ran, in declaration order.
321
+ * @ruling 20 §10, 01 §4 amended, 13 §1
280
322
  */
281
323
  junction(id, opts, fn) {
282
324
  const qualified = this.qualify(id);
@@ -363,10 +405,11 @@ export class JunctionBuilder {
363
405
  }
364
406
  }
365
407
  /**
366
- * Slot-named methods, for the same reason the chain has kind-named ones (04 §4a): the
408
+ * Slot-named methods, for the same reason the chain has kind-named ones: the
367
409
  * method names the slot, so setting a slot a node never declared is caught by name rather
368
410
  * than becoming an override row that silently matches nothing.
369
411
  * @experimental
412
+ * @ruling 04 §4a
370
413
  */
371
414
  export class PresetBuilder {
372
415
  preset;
@@ -377,7 +420,10 @@ export class PresetBuilder {
377
420
  this.preset.values.push({ nodeKey, slot, value });
378
421
  return this;
379
422
  }
380
- /** Node behaviour knobs — retrieval `weight`, `minInclude`, `topK` (12 §2). */
423
+ /**
424
+ * Node behaviour knobs — retrieval `weight`, `minInclude`, `topK`.
425
+ * @ruling 12 §2
426
+ */
381
427
  params(nodeKey, value) {
382
428
  return this.set(nodeKey, 'params', value);
383
429
  }
@@ -397,6 +443,15 @@ export class PresetBuilder {
397
443
  settings(nodeKey, value) {
398
444
  return this.set(nodeKey, 'settings', value);
399
445
  }
446
+ /**
447
+ * The **loadout** this model call runs on — `slot.loadout(id)` or the
448
+ * id itself. Unlike a connection this is allowed in an author preset: a
449
+ * loadout names no compute of the user's (a shipped one has no pair), it
450
+ * names the *kind* of engine, and the admin fills or merges it.
451
+ */
452
+ loadout(nodeKey, value) {
453
+ return this.set(nodeKey, 'loadout', typeof value === 'string' ? slot.loadout(value) : value);
454
+ }
400
455
  }
401
456
  /** @experimental */
402
457
  export class SpecBuilder extends ChainBuilder {
@@ -441,6 +496,11 @@ export class SpecBuilder extends ChainBuilder {
441
496
  const faults = actions.flatMap((a) => actionFindings({ ...a, genre: PENDING_GENRE }, id));
442
497
  if (faults.length)
443
498
  throw new Error(`spec '${id}' declares an action core cannot offer:\n · ${faults.join('\n · ')}`);
499
+ // 🚧 The boundary triggers (★9): their shape here; the channels
500
+ // against the genre where one is at hand (`summarizeScene`).
501
+ const triggerFaults = boundaryTriggerFindings(normalized.contributes?.boundaryTriggers, 'contributes.boundaryTriggers');
502
+ if (triggerFaults.length)
503
+ throw new Error(`spec '${id}' declares a boundary trigger core cannot watch:\n · ${triggerFaults.join('\n · ')}`);
444
504
  }
445
505
  super({
446
506
  id,
@@ -466,7 +526,7 @@ export class SpecBuilder extends ChainBuilder {
466
526
  return this.add('outlet', key, node, opts);
467
527
  }
468
528
  /**
469
- * A named configuration the spec ships with (12 §3a). Declared **after** the nodes,
529
+ * A named configuration the spec ships with. Declared **after** the nodes,
470
530
  * so the node keys it addresses are the ones that exist — same accumulation the
471
531
  * scope uses, so a typo is a compile error rather than a dead override row.
472
532
  *
@@ -476,6 +536,7 @@ export class SpecBuilder extends ChainBuilder {
476
536
  * .prompts ('generate', { system: LORE_SYSTEM })
477
537
  * .template('prompt', jinja(LORE_ASSEMBLY)))
478
538
  * ```
539
+ * @ruling 12 §3a
479
540
  */
480
541
  preset(slug, meta, fn) {
481
542
  if (!SLUG.test(slug)) {
@@ -510,15 +571,16 @@ export class SpecBuilder extends ChainBuilder {
510
571
  return this;
511
572
  }
512
573
  /**
513
- * Exactly one **inlet**, positionally first (01 §2). Enforced here rather than
574
+ * Exactly one **inlet**, positionally first. Enforced here rather than
514
575
  * by the validator, so it is a throw at authoring time.
515
576
  *
516
- * The optional third argument is the **usage lock** (24 §4): the session
577
+ * The optional third argument is the **usage lock**: the session
517
578
  * event this inlet answers and the genre it serves. A session-event spec
518
579
  * without it does not compile — required for now, and relaxing later
519
580
  * (`genre: string[]`, `"*"`) is additive, never breaking. **The lock is the
520
- * only subscription** (R-4, 09-B B5): `.on()` and `subscribes` were deleted
581
+ * only subscription**: `.on()` and `subscribes` were deleted
521
582
  * 2026-09-16 — nothing read them at dispatch.
583
+ * @ruling 01 §2, 24 §4, R-4, 09-B B5
522
584
  */
523
585
  inlet(key, node, binding) {
524
586
  // An event is named by value where a package declared it: its id.
@@ -625,13 +687,29 @@ export class SpecBuilder extends ChainBuilder {
625
687
  junction(id, opts, fn) {
626
688
  return super.junction(id, opts, fn);
627
689
  }
628
- /** Compile-time include — expanded here, so rows hold the flat chain (16 §3a). */
690
+ /**
691
+ * Compile-time include — expanded here, so rows hold the flat chain.
692
+ * @ruling 16 §3a
693
+ */
629
694
  include(key, fragment) {
630
695
  this.spec.includes.push({ key, fragmentId: fragment.id });
696
+ // The fragment's internal wiring moves with it: a reference that names one of
697
+ // its own nodes or clauses (or a clause's current item) is re-addressed under
698
+ // the prefix; a reference to anything outside the fragment is left alone.
699
+ const own = new Set();
700
+ for (const n of fragment.nodes)
701
+ own.add(n.key);
702
+ for (const b of fragment.clauses) {
703
+ own.add(b.id);
704
+ own.add(`${b.id}.${ITEM}`);
705
+ }
706
+ const rekey = (k) => (own.has(k) ? `${key}.${k}` : k);
707
+ const rewrite = (v) => rewriteFragmentRefs(v, rekey);
631
708
  for (const n of fragment.nodes) {
632
709
  this.spec.nodes.push({
633
710
  ...n,
634
711
  key: `${key}.${n.key}`,
712
+ config: rewrite(n.config),
635
713
  clauseId: n.clauseId ? `${key}.${n.clauseId}` : undefined,
636
714
  position: this.spec.nodes.length,
637
715
  });
@@ -640,6 +718,9 @@ export class SpecBuilder extends ChainBuilder {
640
718
  this.spec.clauses.push({
641
719
  ...b,
642
720
  id: `${key}.${b.id}`,
721
+ ...(b.over !== undefined ? { over: rewrite(b.over) } : {}),
722
+ ...(b.on !== undefined ? { on: rewrite(b.on) } : {}),
723
+ ...(b.repeatWhile !== undefined ? { repeatWhile: rewrite(b.repeatWhile) } : {}),
643
724
  clauseId: b.clauseId ? `${key}.${b.clauseId}` : undefined,
644
725
  position: this.spec.nodes.length,
645
726
  });
@@ -660,6 +741,31 @@ const PENDING_GENRE = 'pending:genre/lock';
660
741
  export function spec(id, meta) {
661
742
  return new SpecBuilder(id, meta);
662
743
  }
744
+ /**
745
+ * Deep-copy `value`, re-addressing every `DataRef.node` and `SlotRef.ofNode`
746
+ * through `rekey`. Plain objects and arrays are walked; everything else is
747
+ * returned as is. Used by `include` to carry a fragment's internal wiring
748
+ * under its key prefix.
749
+ * @internal
750
+ */
751
+ function rewriteFragmentRefs(value, rekey) {
752
+ const walk = (v) => {
753
+ if (isDataRef(v))
754
+ return { ...v, node: rekey(v.node) };
755
+ if (isSlotRef(v))
756
+ return v.ofNode !== undefined ? { ...v, ofNode: rekey(v.ofNode) } : { ...v };
757
+ if (Array.isArray(v))
758
+ return v.map(walk);
759
+ if (v && typeof v === 'object' && Object.getPrototypeOf(v) === Object.prototype) {
760
+ const out = {};
761
+ for (const [k, x] of Object.entries(v))
762
+ out[k] = walk(x);
763
+ return out;
764
+ }
765
+ return v;
766
+ };
767
+ return walk(value);
768
+ }
663
769
  /** @experimental */
664
770
  export function fragment(id, fn) {
665
771
  const inner = {
@@ -2,7 +2,7 @@
2
2
  * The wire value of `core:shape/context-candidates@1`, and the one thing it
3
3
  * carries besides candidates: each source's **band intent**.
4
4
  *
5
- * ## Queries declare, the ranker resolves (16 §5a; R-7 P5, ruled 2026-09-15)
5
+ * ## Queries declare, the ranker resolves (ruled 2026-09-15)
6
6
  *
7
7
  * *Per-source* intent — how much of the window a source wants (`share`), the
8
8
  * most entries it may contribute (`maxEntries`), the fewest it keeps when room
@@ -11,7 +11,7 @@
11
11
  * the source, as ordinary `params`, and travels to the ranker as metadata on
12
12
  * the candidates it publishes. The ranker declares only what is
13
13
  * *cross-source*: how mechanisms and signals weigh, and how the shares
14
- * normalise. A per-source map on the ranker is the design 16 §5a rejected: it
14
+ * normalise. A per-source map on the ranker is the design that was rejected: it
15
15
  * goes stale when a source is added, and a plugin source cannot participate
16
16
  * without somebody editing it.
17
17
  *
@@ -42,6 +42,7 @@
42
42
  * — a band no source declared falls back to the ranker's own table for the
43
43
  * five core bands and is excluded with a receipt for any other, which is what
44
44
  * makes a plugin source's participation a matter of publishing one element.
45
+ * @ruling 16 §5a, R-7 P5, 16 §5a
45
46
  */
46
47
  /**
47
48
  * How strongly a band resists being trimmed once its minimum is met.
@@ -64,7 +65,8 @@ export declare const isBandPriority: (v: unknown) => v is BandPriority;
64
65
  export interface BandIntentFields {
65
66
  /**
66
67
  * The band's slice of the window, relative to every other band's. `0` is
67
- * the band's off switch. NOMENCLATURE §7: a share, never a weight.
68
+ * the band's off switch. A share, never a weight.
69
+ * @ruling NOMENCLATURE §7
68
70
  */
69
71
  share?: number;
70
72
  /** The most entries this band may contribute. Absent means no ceiling. */
@@ -2,7 +2,7 @@
2
2
  * The wire value of `core:shape/context-candidates@1`, and the one thing it
3
3
  * carries besides candidates: each source's **band intent**.
4
4
  *
5
- * ## Queries declare, the ranker resolves (16 §5a; R-7 P5, ruled 2026-09-15)
5
+ * ## Queries declare, the ranker resolves (ruled 2026-09-15)
6
6
  *
7
7
  * *Per-source* intent — how much of the window a source wants (`share`), the
8
8
  * most entries it may contribute (`maxEntries`), the fewest it keeps when room
@@ -11,7 +11,7 @@
11
11
  * the source, as ordinary `params`, and travels to the ranker as metadata on
12
12
  * the candidates it publishes. The ranker declares only what is
13
13
  * *cross-source*: how mechanisms and signals weigh, and how the shares
14
- * normalise. A per-source map on the ranker is the design 16 §5a rejected: it
14
+ * normalise. A per-source map on the ranker is the design that was rejected: it
15
15
  * goes stale when a source is added, and a plugin source cannot participate
16
16
  * without somebody editing it.
17
17
  *
@@ -42,6 +42,7 @@
42
42
  * — a band no source declared falls back to the ranker's own table for the
43
43
  * five core bands and is excluded with a receipt for any other, which is what
44
44
  * makes a plugin source's participation a matter of publishing one element.
45
+ * @ruling 16 §5a, R-7 P5, 16 §5a
45
46
  */
46
47
  /**
47
48
  * How strongly a band resists being trimmed once its minimum is met.
package/dist/clauses.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * A gather clause's execution mode, as a setting rather than only an authoring
3
- * choice (R-14: `mode` is a setting, the construct is the clause).
3
+ * choice: `mode` is a setting, the construct is the clause.
4
4
  *
5
5
  * `gather` chains are declared `parallel` or `sequential` by whoever wrote the
6
6
  * spec, and until now that was the end of it. But the right answer is not a
@@ -13,6 +13,7 @@
13
13
  * on exactly the terms `review` already uses (see `resolvePosition`): same
14
14
  * `settings` slot, same precedence, same refusal to let an author forbid the
15
15
  * override.
16
+ * @ruling R-14
16
17
  */
17
18
  import type { I18n } from './descriptors.js';
18
19
  /** @experimental */
package/dist/clauses.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * A gather clause's execution mode, as a setting rather than only an authoring
3
- * choice (R-14: `mode` is a setting, the construct is the clause).
3
+ * choice: `mode` is a setting, the construct is the clause.
4
4
  *
5
5
  * `gather` chains are declared `parallel` or `sequential` by whoever wrote the
6
6
  * spec, and until now that was the end of it. But the right answer is not a
@@ -13,6 +13,7 @@
13
13
  * on exactly the terms `review` already uses (see `resolvePosition`): same
14
14
  * `settings` slot, same precedence, same refusal to let an author forbid the
15
15
  * override.
16
+ * @ruling R-14
16
17
  */
17
18
  /** @experimental */
18
19
  export const CLAUSE_MODES = ['parallel', 'sequential'];
@@ -1,6 +1,6 @@
1
1
  /**
2
- * `@serene-pub/sdk/component` — what a COMPONENT imports from the SDK
3
- * (§3.5, C6 P1). Experimental: grows additively until SDK 1.0 freezes it.
2
+ * `@serene-pub/sdk/component` — what a COMPONENT imports from the SDK.
3
+ * Experimental: grows additively until SDK 1.0 freezes it.
4
4
  *
5
5
  * A component runs in a UI worker and may import only `COMPONENT_IMPORTS`
6
6
  * (`componentImports.ts`). The SDK's root barrel is not on that list — it is
@@ -12,16 +12,26 @@
12
12
  *
13
13
  * Every name here is the root barrel's own, re-exported: `import { x } from
14
14
  * '@serene-pub/sdk'` and from this subpath are the same binding.
15
+ * @ruling §3.5, C6 P1
15
16
  */
16
17
  /** An action's stable identity (a verb's key in a row or a palette). */
17
18
  export { actionIdentity } from './identity.js';
18
- /** Display text (R-20): a plain string or a locale map, resolved. */
19
+ /**
20
+ * Display text: a plain string or a locale map, resolved.
21
+ * @ruling R-20
22
+ */
19
23
  export { i18nText, type I18n } from './i18n.js';
20
24
  /** The empty turn order a widget starts from before the host's first push. */
21
25
  export { EMPTY_TURN_ORDER, type TurnOrderV1 } from './turnOrder.js';
22
- /** The widget data contract's protocol version. */
23
- export { WIDGET_PROTOCOL } from './widgets.js';
24
- /** The folded sections a row's shown alternative carries, read from its metadata (B4). */
26
+ /**
27
+ * The widget data contract's protocol version; the empty attendance a widget starts from.
28
+ * @ruling W10
29
+ */
30
+ export { WIDGET_PROTOCOL, EMPTY_ATTENDANCE } from './widgets.js';
31
+ /**
32
+ * The folded sections a row's shown alternative carries, read from its metadata.
33
+ * @ruling B4
34
+ */
25
35
  export { foldedSectionsOf } from './foldedSections.js';
26
36
  export type { ComponentContext } from './componentClient.js';
27
37
  /** A declined `request`'s error, and the `code` it may carry. */
@@ -29,5 +39,12 @@ export type { RequestDeclined } from './componentWire.js';
29
39
  export type { RequestDeclineCode } from './surfaces.js';
30
40
  export type { HostKeyEventDetail } from './hostElements.js';
31
41
  export type { StatusText, WidgetActionReason } from './status.js';
32
- export type { AuthorsNoteV1, AuthorsNoteValueV1, FoldedSectionPartDataV1, FoldedSectionV1, LayoutV1, MessageErrorConnectionV1, MessageErrorV1, MessageMetadataV1, MessagePartV1, MessageSwipesV1, MessageV1, SessionCharactersV1, SessionEntryV1, SessionStateV1, ViewerV1, WidgetAction, WidgetEvent, WidgetEventKind, WidgetRequestKind, WidgetRequests, } from './widgets.js';
42
+ export type { AttendanceV1, AttendeeV1, AuthorsNoteV1, AuthorsNoteValueV1, HistoryEntriesV1, HistoryEntryV1, HistorySceneV1, FoldedSectionPartDataV1, FoldedSectionV1, LayoutV1, MessageErrorConnectionV1, MessageErrorV1, MessageMetadataV1, MessagePartV1, MessageSwipesV1, MessageV1, PlaceLinkV1, PlaceV1, SessionCharactersV1, SessionEntryV1, SessionPersonaV1, SessionPlacesV1, SessionStateV1, StatTrailChangeV1, StoryClockV1, WayV1, ViewerV1, WidgetAction, WidgetEvent, WidgetEventKind, WidgetRequestKind, WidgetRequests, } from './widgets.js';
43
+ /**
44
+ * 🚧 A story time and what a story clock steps by (Chronicle).
45
+ * @ruling W3
46
+ */
47
+ export type { StoryTime, StoryTimeUnit } from './storyTime.js';
48
+ /** The conversation dossier — `session_full.v1`, for a widget granted `session:full`. */
49
+ export type { SessionDossierV1 } from './sessionDossier.js';
33
50
  //# sourceMappingURL=component.d.ts.map
package/dist/component.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * `@serene-pub/sdk/component` — what a COMPONENT imports from the SDK
3
- * (§3.5, C6 P1). Experimental: grows additively until SDK 1.0 freezes it.
2
+ * `@serene-pub/sdk/component` — what a COMPONENT imports from the SDK.
3
+ * Experimental: grows additively until SDK 1.0 freezes it.
4
4
  *
5
5
  * A component runs in a UI worker and may import only `COMPONENT_IMPORTS`
6
6
  * (`componentImports.ts`). The SDK's root barrel is not on that list — it is
@@ -12,16 +12,26 @@
12
12
  *
13
13
  * Every name here is the root barrel's own, re-exported: `import { x } from
14
14
  * '@serene-pub/sdk'` and from this subpath are the same binding.
15
+ * @ruling §3.5, C6 P1
15
16
  */
16
17
  // ── runtime helpers ─────────────────────────────────────────────────────────
17
18
  /** An action's stable identity (a verb's key in a row or a palette). */
18
19
  export { actionIdentity } from './identity.js';
19
- /** Display text (R-20): a plain string or a locale map, resolved. */
20
+ /**
21
+ * Display text: a plain string or a locale map, resolved.
22
+ * @ruling R-20
23
+ */
20
24
  export { i18nText } from './i18n.js';
21
25
  /** The empty turn order a widget starts from before the host's first push. */
22
26
  export { EMPTY_TURN_ORDER } from './turnOrder.js';
23
- /** The widget data contract's protocol version. */
24
- export { WIDGET_PROTOCOL } from './widgets.js';
25
- /** The folded sections a row's shown alternative carries, read from its metadata (B4). */
27
+ /**
28
+ * The widget data contract's protocol version; the empty attendance a widget starts from.
29
+ * @ruling W10
30
+ */
31
+ export { WIDGET_PROTOCOL, EMPTY_ATTENDANCE } from './widgets.js';
32
+ /**
33
+ * The folded sections a row's shown alternative carries, read from its metadata.
34
+ * @ruling B4
35
+ */
26
36
  export { foldedSectionsOf } from './foldedSections.js';
27
37
  //# sourceMappingURL=component.js.map
@@ -1,4 +1,7 @@
1
- /** @experimental What a built component was built against (F1). Additive: a reader ignores fields it does not know. */
1
+ /**
2
+ * @experimental What a built component was built against. Additive: a reader ignores fields it does not know.
3
+ * @ruling F1
4
+ */
2
5
  export interface ComponentBuiltAgainst {
3
6
  /** The widget protocol (`WIDGET_PROTOCOL`) the artifact speaks. */
4
7
  widgetProtocol: number;
@@ -10,22 +13,29 @@ export interface ComponentBuiltAgainst {
10
13
  componentClient?: string;
11
14
  }
12
15
  /**
13
- * @experimental (F1)
16
+ * @experimental
14
17
  *
15
18
  * The widget protocols this host mounts a component built for. A host that
16
19
  * moves to a new protocol keeps the old one here for as long as it still
17
20
  * speaks it; one it drops is refused, by name.
21
+ * @ruling F1
18
22
  */
19
23
  export declare const HOST_WIDGET_PROTOCOLS: readonly number[];
20
- /** @experimental The host-element vocabulary majors this host mounts a component built for (F1). */
24
+ /**
25
+ * @experimental The host-element vocabulary majors this host mounts a component built for.
26
+ * @ruling F1
27
+ */
21
28
  export declare const HOST_ELEMENTS_MAJORS: readonly number[];
22
- /** @experimental The contract this SDK's build records: the two versions that decide (F1). */
29
+ /**
30
+ * @experimental The contract this SDK's build records: the two versions that decide.
31
+ * @ruling F1
32
+ */
23
33
  export declare function currentBuiltAgainst(versions?: {
24
34
  sdk?: string;
25
35
  componentClient?: string;
26
36
  }): ComponentBuiltAgainst;
27
37
  /**
28
- * @experimental (F1)
38
+ * @experimental
29
39
  *
30
40
  * Why this host must NOT mount a component built against `builtAgainst`, as
31
41
  * a sentence — or `undefined` when it may. Absent (`undefined` / `null`) is
@@ -39,6 +49,7 @@ export declare function currentBuiltAgainst(versions?: {
39
49
  * {@link HOST_ELEMENTS_VERSION}).
40
50
  *
41
51
  * `host` defaults to this SDK's own contract.
52
+ * @ruling F1
42
53
  */
43
54
  export declare function componentBuiltAgainstFinding(builtAgainst: unknown, host?: {
44
55
  widgetProtocols?: readonly number[];
@@ -1,5 +1,5 @@
1
1
  /**
2
- * What a built component was built AGAINST (F1): the host contract a
2
+ * What a built component was built AGAINST: the host contract a
3
3
  * compiled artifact assumes, recorded beside it so a host that has moved on
4
4
  * refuses it with a sentence instead of mounting it into a failure nobody can
5
5
  * read.
@@ -16,20 +16,28 @@
16
16
  * (`components[].builtAgainst`) and by the in-app compiler on each compile.
17
17
  * An entry WITHOUT one predates the record and is judged compatible — every
18
18
  * component built before it was built for protocol 2, vocabulary 1.
19
+ * @ruling F1
19
20
  */
20
21
  import { HOST_ELEMENTS_VERSION } from './hostElements.js';
21
22
  import { WIDGET_PROTOCOL } from './widgets.js';
22
23
  /**
23
- * @experimental (F1)
24
+ * @experimental
24
25
  *
25
26
  * The widget protocols this host mounts a component built for. A host that
26
27
  * moves to a new protocol keeps the old one here for as long as it still
27
28
  * speaks it; one it drops is refused, by name.
29
+ * @ruling F1
28
30
  */
29
31
  export const HOST_WIDGET_PROTOCOLS = Object.freeze([WIDGET_PROTOCOL]);
30
- /** @experimental The host-element vocabulary majors this host mounts a component built for (F1). */
32
+ /**
33
+ * @experimental The host-element vocabulary majors this host mounts a component built for.
34
+ * @ruling F1
35
+ */
31
36
  export const HOST_ELEMENTS_MAJORS = Object.freeze([vocabularyMajor(HOST_ELEMENTS_VERSION)]);
32
- /** @experimental The contract this SDK's build records: the two versions that decide (F1). */
37
+ /**
38
+ * @experimental The contract this SDK's build records: the two versions that decide.
39
+ * @ruling F1
40
+ */
33
41
  export function currentBuiltAgainst(versions = {}) {
34
42
  return {
35
43
  widgetProtocol: WIDGET_PROTOCOL,
@@ -46,7 +54,7 @@ function vocabularyMajor(v) {
46
54
  }
47
55
  const list = (xs) => (xs.length === 1 ? String(xs[0]) : `${xs.slice(0, -1).join(', ')} or ${xs[xs.length - 1]}`);
48
56
  /**
49
- * @experimental (F1)
57
+ * @experimental
50
58
  *
51
59
  * Why this host must NOT mount a component built against `builtAgainst`, as
52
60
  * a sentence — or `undefined` when it may. Absent (`undefined` / `null`) is
@@ -60,6 +68,7 @@ const list = (xs) => (xs.length === 1 ? String(xs[0]) : `${xs.slice(0, -1).join(
60
68
  * {@link HOST_ELEMENTS_VERSION}).
61
69
  *
62
70
  * `host` defaults to this SDK's own contract.
71
+ * @ruling F1
63
72
  */
64
73
  export function componentBuiltAgainstFinding(builtAgainst, host = {}) {
65
74
  if (builtAgainst === undefined || builtAgainst === null)