@serene-pub/sdk 0.6.0-pr-2 → 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 +24 -20
  2. package/dist/actions.d.ts +150 -68
  3. package/dist/actions.js +90 -36
  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 +195 -96
  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 +5 -4
  74. package/dist/identity.js +5 -4
  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 +103 -41
  136. package/dist/shapes.js +105 -40
  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
@@ -8,10 +8,9 @@
8
8
  * (`sandbox="allow-scripts"`, never `allow-same-origin`). Zero ambient
9
9
  * anything: no cookies, no DOM reach, no socket. Everything it knows arrives
10
10
  * on the MessageChannel the host owns (the frame protocol below). This is the
11
- * shape the app ships today — session-view replacement, page, panel grid
12
- * (20 §12, 21 §7).
11
+ * shape the app ships today — session-view replacement, page, panel grid.
13
12
  *
14
- * **component** — a module the page's UI worker runs (§3.5, R25): one
13
+ * **component** — a module the page's UI worker runs: one
15
14
  * worker per owner per session page, no DOM, no network. It places
16
15
  * elements from the host vocabulary (`SP_HOST_ELEMENTS`, `hostElements.ts`)
17
16
  * and the host mirrors them into the widget box, dropping anything not
@@ -46,11 +45,12 @@
46
45
  * a frame receives the same sections a native widget reads off its context,
47
46
  * one push per section. `FRAME_PROTOCOL` says which vintage of that wire the
48
47
  * host speaks.
48
+ * @ruling 20 §12, 21 §7, §3.5, R25
49
49
  */
50
50
  import type { TurnOrderV1 } from './turnOrder.js';
51
51
  import type { ComponentFramework } from './extension.js';
52
52
  import type { SettingsSchema } from './settings.js';
53
- import { type ActionsV1, type AnnexV1, type LayoutV1, type MessageV1, type SessionV1, type ViewerV1, type WidgetRequestKind, type WidgetEvent, type WidgetPayload, type WidgetProtocolVersion, type WidgetScopedSectionName, type WidgetSectionScope } from './widgets.js';
53
+ import { type ActionsV1, type AnnexV1, type AttendanceV1, type LayoutV1, type MessageV1, type SessionV1, type ViewerV1, type WidgetRequestKind, type WidgetEvent, type WidgetPayload, type WidgetProtocolVersion, type WidgetScopedSectionName, type WidgetSectionScope, type WidgetWriteGrant } from './widgets.js';
54
54
  /**
55
55
  * Where a package's entry module lives, in the order the toolchain looks.
56
56
  * One list, shared by `serene-pub build` and the preview harness, so "the
@@ -107,14 +107,15 @@ export declare function parsePluginWidgetId(id: string): {
107
107
  */
108
108
  export interface SurfacesDecl {
109
109
  /**
110
- * Replaces the whole message section for a genre that names it (19 `view`).
110
+ * Replaces the whole message section for a genre that names it.
111
111
  *
112
112
  * Spelled `session-view`, not `sessionView`, because that is the key the
113
113
  * app's `surfacesOf` reads out of a stored manifest — and the announcement
114
- * *is* the manifest (24 §6), so there is no layer in between to translate
114
+ * *is* the manifest, so there is no layer in between to translate
115
115
  * it. A camelCase spelling here compiled, previewed, installed, and then
116
116
  * silently never mounted: the exact class of bug this file's docstring
117
117
  * claims cannot happen. One spelling, end to end.
118
+ * @ruling 19 `view`, 24 §6
118
119
  */
119
120
  'session-view'?: FrameSurfaceDecl;
120
121
  /** A standalone page under the app's plugin route shell. */
@@ -139,6 +140,7 @@ export type RequestDeclineCode = 'unmounted';
139
140
  * members (`settings`, `layout`, `scoped`, `grants`) are widget data that
140
141
  * only a component is sent — a frame never is one.
141
142
  * @experimental
143
+ * @ruling R57, 10 §6, RESEARCH §7b, C0b, C5, W10
142
144
  */
143
145
  export type HostFrameMessage = {
144
146
  t: 'init';
@@ -182,7 +184,9 @@ export type HostFrameMessage = {
182
184
  t: 'layout';
183
185
  layout: LayoutV1;
184
186
  }
185
- /** The viewer's view of the session annex (R57), on open and on every change — `annex.v1`. */
187
+ /**
188
+ * The viewer's view of the session annex, on open and on every change — `annex.v1`.
189
+ */
186
190
  | {
187
191
  t: 'annex';
188
192
  annex: AnnexV1;
@@ -208,11 +212,11 @@ export type HostFrameMessage = {
208
212
  actions: ActionsV1;
209
213
  }
210
214
  /**
211
- * The host's active theme, as data (10 §6: *"the active theme id is a
212
- * prop"*). An in-document component reads it off `ctx.theme`; a frame is
215
+ * The host's active theme, as data: the active theme id is a
216
+ * prop. An in-document component reads it off `ctx.theme`; a frame is
213
217
  * its own document, so it arrives here.
214
218
  *
215
- * Values, never tokens. RESEARCH §7b is explicit that SP publishes no
219
+ * Values, never tokens. SP deliberately publishes no
216
220
  * token artifact of any kind — the frame applies the id and the mode to
217
221
  * its own `<html>` (`data-theme` / `data-mode`) and lets the stylesheet it
218
222
  * linked resolve them, exactly as the top document does. That keeps the
@@ -261,7 +265,7 @@ export type HostFrameMessage = {
261
265
  state: Record<string, unknown>;
262
266
  }
263
267
  /**
264
- * 🚧 The answer to any `request` but `messages` (C0b), echoing its
268
+ * 🚧 The answer to any `request` but `messages`, echoing its
265
269
  * `requestId`: `ok` with the kind's result, or declined with why — and,
266
270
  * when the decline is one a component may tell apart, its
267
271
  * {@link RequestDeclineCode} (`code`; absent from an older host).
@@ -274,23 +278,36 @@ export type HostFrameMessage = {
274
278
  error?: string;
275
279
  code?: RequestDeclineCode;
276
280
  }
277
- /** 🚧 Translations of strings the frame asked for with `translate` (C0b). */
281
+ /**
282
+ * 🚧 Translations of strings the frame asked for with `translate`.
283
+ */
278
284
  | {
279
285
  t: 'strings';
280
286
  strings: Record<string, string>;
281
287
  }
282
- /** 🚧 Who is looking — the envelope's `viewer.v1` (C0b). */
288
+ /**
289
+ * 🚧 Who is looking — the envelope's `viewer.v1`.
290
+ */
283
291
  | {
284
292
  t: 'viewer';
285
293
  viewer: ViewerV1;
286
294
  }
287
- /** The session's turn order — the envelope's `turnOrder.v1` (C5), on open and on every change. */
295
+ /**
296
+ * The session's turn order — the envelope's `turnOrder.v1`, on open and on every change.
297
+ */
288
298
  | {
289
299
  t: 'turn-order';
290
300
  turnOrder: TurnOrderV1;
291
301
  }
292
302
  /**
293
- * 🚧 A scoped section the widget was granted (C0b) — named as the SDK's
303
+ * The session's attendance — the envelope's `attendance.v1`, on open and on every change.
304
+ */
305
+ | {
306
+ t: 'attendance';
307
+ attendance: AttendanceV1;
308
+ }
309
+ /**
310
+ * 🚧 A scoped section the widget was granted — named as the SDK's
294
311
  * one table posts it (`WidgetScopedSections`: `session_full`,
295
312
  * `session_state`, `persona`, `characters`, `lore`), the envelope's
296
313
  * `<name>.v1` — posted when it changes; `value: null` withdraws it (the
@@ -303,8 +320,9 @@ export type HostFrameMessage = {
303
320
  value: unknown;
304
321
  }
305
322
  /**
306
- * 🚧 The scopes the widget holds, BARE (`session:state`, never the
307
- * permission key `widget:session:state`) — sent before the first push
323
+ * 🚧 The scopes and write grants the widget holds, BARE (`session:state`,
324
+ * `channel:main:write`; never the permission key `widget:session:state`)
325
+ * — sent before the first push
308
326
  * of its sections and again whenever they change (an admin grants or
309
327
  * revokes one while it is open). What lets a widget tell a scope that was
310
328
  * NOT granted (its section will never come: say so) from one whose
@@ -313,7 +331,7 @@ export type HostFrameMessage = {
313
331
  */
314
332
  | {
315
333
  t: 'grants';
316
- grants: WidgetSectionScope[];
334
+ grants: (WidgetSectionScope | WidgetWriteGrant)[];
317
335
  };
318
336
  /**
319
337
  * frame → host. Deliberately tiny: a frame proposes, the host decides.
@@ -326,6 +344,7 @@ export type HostFrameMessage = {
326
344
  * giving up control — they are the frame reporting, requesting and naming,
327
345
  * with the host still deciding.
328
346
  * @experimental
347
+ * @ruling C0b
329
348
  */
330
349
  export type FrameHostMessage = {
331
350
  t: 'ready';
@@ -368,9 +387,10 @@ export type FrameHostMessage = {
368
387
  messageId?: number;
369
388
  payload?: WidgetPayload;
370
389
  /**
371
- * The form this press answers — a block's id within `messageId`
372
- * (R-15 *Forms*). Absent on every other press; the frame half of
390
+ * The form this press answers — a block's id within `messageId`.
391
+ * Absent on every other press; the frame half of
373
392
  * `WidgetInvokeArgs.blockId`.
393
+ * @ruling R-15 *Forms*
374
394
  */
375
395
  blockId?: string;
376
396
  /** The text the press supplies (a slash argument) — the frame half of `WidgetInvokeArgs.text`. */
@@ -402,7 +422,7 @@ export type FrameHostMessage = {
402
422
  limit?: number;
403
423
  }
404
424
  /**
405
- * 🚧 Ask the host for anything else in {@link WidgetRequests} (C0b) — a
425
+ * 🚧 Ask the host for anything else in {@link WidgetRequests} — a
406
426
  * host view opened, a picker shown. Answered with `response`.
407
427
  */
408
428
  | {
@@ -411,7 +431,9 @@ export type FrameHostMessage = {
411
431
  what: Exclude<WidgetRequestKind, 'messages'>;
412
432
  params: unknown;
413
433
  }
414
- /** 🚧 English UI strings the frame wants in the viewer's language (C0b); answered with `strings`. */
434
+ /**
435
+ * 🚧 English UI strings the frame wants in the viewer's language; answered with `strings`.
436
+ */
415
437
  | {
416
438
  t: 'translate';
417
439
  sources: string[];
@@ -460,14 +482,21 @@ export interface PreviewTarget {
460
482
  kind: 'frame' | 'component';
461
483
  /**
462
484
  * For a frame, one of `FramePoint`. For a component, the mount point it
463
- * renders at — `widget` today (a page mount point comes later, R25).
485
+ * renders at — `widget` today (a page mount point comes later).
486
+ * @ruling R25
464
487
  */
465
488
  point: string;
466
489
  /** Path to the entry, exactly as declared — relative to the package root. */
467
490
  entry: string;
468
- /** Components only: which adapter renders it (10 §7). */
491
+ /**
492
+ * Components only: which adapter renders it.
493
+ * @ruling 10 §7
494
+ */
469
495
  framework?: ComponentFramework;
470
- /** Components only: settings the target reads through `ctx` (12 §6). */
496
+ /**
497
+ * Components only: settings the target reads through `ctx`.
498
+ * @ruling 12 §6
499
+ */
471
500
  settings?: SettingsSchema;
472
501
  /** Where the declaration came from, for the harness's "declared in" line. */
473
502
  source: 'surfaces' | 'components';
package/dist/surfaces.js CHANGED
@@ -8,10 +8,9 @@
8
8
  * (`sandbox="allow-scripts"`, never `allow-same-origin`). Zero ambient
9
9
  * anything: no cookies, no DOM reach, no socket. Everything it knows arrives
10
10
  * on the MessageChannel the host owns (the frame protocol below). This is the
11
- * shape the app ships today — session-view replacement, page, panel grid
12
- * (20 §12, 21 §7).
11
+ * shape the app ships today — session-view replacement, page, panel grid.
13
12
  *
14
- * **component** — a module the page's UI worker runs (§3.5, R25): one
13
+ * **component** — a module the page's UI worker runs: one
15
14
  * worker per owner per session page, no DOM, no network. It places
16
15
  * elements from the host vocabulary (`SP_HOST_ELEMENTS`, `hostElements.ts`)
17
16
  * and the host mirrors them into the widget box, dropping anything not
@@ -46,6 +45,7 @@
46
45
  * a frame receives the same sections a native widget reads off its context,
47
46
  * one push per section. `FRAME_PROTOCOL` says which vintage of that wire the
48
47
  * host speaks.
48
+ * @ruling 20 §12, 21 §7, §3.5, R25
49
49
  */
50
50
  import { WIDGET_PROTOCOL, } from './widgets.js';
51
51
  /**
@@ -1,11 +1,12 @@
1
1
  /**
2
- * A minimal template engine, enough to demonstrate variable awareness (16 §4).
2
+ * A minimal template engine, enough to demonstrate variable awareness.
3
3
  *
4
4
  * Supports `{{ a.b.c }}` and `{% for x in items %}…{% endfor %}`. Not Jinja — just
5
5
  * enough surface to answer the question the docs make a promise about: *can the editor
6
6
  * tell an author which variables exist, and flag one that doesn't?*
7
7
  *
8
- * ⚠ Writing this surfaced a correction to 16 §4 — see `templateScope`.
8
+ * ⚠ Writing this surfaced a correction to the variable-awareness design — see `templateScope`.
9
+ * @ruling 16 §4, 16 §4
9
10
  */
10
11
  import type { I18n, SlotDecl } from './descriptors.js';
11
12
  import type { FieldDecl } from './settings.js';
@@ -22,14 +23,15 @@ export interface TemplateRef {
22
23
  * Extract top-level variable references. Loop-bound names are marked so they are not
23
24
  * reported as unknown, and anything computed is marked dynamic rather than verified —
24
25
  * an editor that promises correctness and lets a typo through is worse than one that
25
- * says what it checks (16 §4).
26
+ * says what it checks.
26
27
  * @experimental
28
+ * @ruling 16 §4
27
29
  */
28
30
  export declare function extractRefs(src: string): TemplateRef[];
29
31
  /** Render. Missing values become empty strings — templates never throw at run time. @experimental */
30
32
  export declare function render(src: string, baseScope: Record<string, unknown>): string;
31
33
  /**
32
- * ⚠ CORRECTION TO 16 §4.
34
+ * ⚠ CORRECTION TO THE VARIABLE-AWARENESS DESIGN.
33
35
  *
34
36
  * The docs say template variable awareness "falls out of typed ports with no new
35
37
  * mechanism." Building it shows that is only true for the **assembly** template, whose
@@ -42,6 +44,7 @@ export declare function render(src: string, baseScope: Record<string, unknown>):
42
44
  * So the template slot must **declare its own variable scope**. That is one extra field on
43
45
  * the descriptor, not a new mechanism, but the docs currently claim something that isn't
44
46
  * quite true and would have been discovered by the first plugin author who tried it.
47
+ * @ruling 16 §4
45
48
  */
46
49
  /**
47
50
  * The kinds a declared value can be.
@@ -148,8 +151,9 @@ export type TemplateFindingKind = 'syntax' | 'unknown-name' | 'unknown-path' | '
148
151
  * What a host's engines register, as names — the checker's input
149
152
  * (`@serene-pub/sdk/template-check`). Declared here, on the barrel, so a
150
153
  * dependency-free module can take a checker as a value without importing the
151
- * engines (typed templates P5).
154
+ * engines.
152
155
  * @experimental
156
+ * @ruling typed templates P5
153
157
  */
154
158
  export interface TemplateCheckOptions {
155
159
  /** Handlebars helpers the host registers beyond the built-ins. */
package/dist/template.js CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
- * A minimal template engine, enough to demonstrate variable awareness (16 §4).
2
+ * A minimal template engine, enough to demonstrate variable awareness.
3
3
  *
4
4
  * Supports `{{ a.b.c }}` and `{% for x in items %}…{% endfor %}`. Not Jinja — just
5
5
  * enough surface to answer the question the docs make a promise about: *can the editor
6
6
  * tell an author which variables exist, and flag one that doesn't?*
7
7
  *
8
- * ⚠ Writing this surfaced a correction to 16 §4 — see `templateScope`.
8
+ * ⚠ Writing this surfaced a correction to the variable-awareness design — see `templateScope`.
9
+ * @ruling 16 §4, 16 §4
9
10
  */
10
11
  const EXPR = /\{\{\s*([^}]+?)\s*\}\}/g;
11
12
  const FOR = /\{%\s*for\s+(\w+)\s+in\s+([\w.]+)\s*%\}/g;
@@ -14,8 +15,9 @@ const IF = /\{%\s*if\s+([^%]+?)\s*%\}/g;
14
15
  * Extract top-level variable references. Loop-bound names are marked so they are not
15
16
  * reported as unknown, and anything computed is marked dynamic rather than verified —
16
17
  * an editor that promises correctness and lets a typo through is worse than one that
17
- * says what it checks (16 §4).
18
+ * says what it checks.
18
19
  * @experimental
20
+ * @ruling 16 §4
19
21
  */
20
22
  export function extractRefs(src) {
21
23
  const bound = new Set();
@@ -1,12 +1,12 @@
1
1
  /**
2
- * The one template checker (typed templates P4): does this Handlebars or
2
+ * The one template checker: does this Handlebars or
3
3
  * Liquid source parse, and does every name it reads exist in the scope it will
4
4
  * be rendered against?
5
5
  *
6
6
  * ## Why a separate entry point
7
7
  *
8
8
  * `@serene-pub/sdk/template-check`, not the barrel. The checker parses with
9
- * the real engines — `handlebars` and `liquidjs`, parse only (Q5) — and the
9
+ * the real engines — `handlebars` and `liquidjs`, parse only — and the
10
10
  * barrel is what every node author and plugin bundle imports; it has no
11
11
  * dependencies and stays that way. A host (the editor lint, a save, a
12
12
  * packager) imports this on purpose. Nothing here renders: the host keeps its
@@ -1,12 +1,12 @@
1
1
  /**
2
- * The one template checker (typed templates P4): does this Handlebars or
2
+ * The one template checker: does this Handlebars or
3
3
  * Liquid source parse, and does every name it reads exist in the scope it will
4
4
  * be rendered against?
5
5
  *
6
6
  * ## Why a separate entry point
7
7
  *
8
8
  * `@serene-pub/sdk/template-check`, not the barrel. The checker parses with
9
- * the real engines — `handlebars` and `liquidjs`, parse only (Q5) — and the
9
+ * the real engines — `handlebars` and `liquidjs`, parse only — and the
10
10
  * barrel is what every node author and plugin bundle imports; it has no
11
11
  * dependencies and stays that way. A host (the editor lint, a save, a
12
12
  * packager) imports this on purpose. Nothing here renders: the host keeps its
@@ -1,13 +1,13 @@
1
1
  /**
2
- * Does this template fit this node? (typed templates P5, 2026-09-27)
2
+ * Does this template fit this node?
3
3
  *
4
- * The refusals of design §4, in one place: a template is checked against the
4
+ * The template-fit refusals, in one place: a template is checked against the
5
5
  * typed scope of the node that renders it (`templateScopeReport`), and a name
6
6
  * or path nothing there supplies is REFUSED — at selection (the host), at a
7
- * spec's save and publish (law T1, `validate()`), and at packaging (a plugin's
7
+ * spec's save and publish (`validate()`), and at packaging (a plugin's
8
8
  * shipped template seeds). Warnings never refuse, and nor does anything while
9
9
  * a producer upstream declares no types (`untyped`): its keys may still
10
- * arrive, so the checker only warns (owner Q6: refuse new selections and new
10
+ * arrive, so the checker only warns (refuse new selections and new
11
11
  * saves; a stored row becomes a notice, never a retroactive refusal).
12
12
  *
13
13
  * ## The checker is a value
@@ -16,7 +16,7 @@
16
16
  * which carries `handlebars` and `liquidjs`); this module is on the barrel,
17
17
  * which stays dependency-free. So every door here takes the checker as an
18
18
  * argument — `{ check: checkTemplateSourceReport }` — and a caller without one
19
- * gets the checker-free half of T1 (scope collisions, forbidden kinds, a band
19
+ * gets the checker-free half of the law (scope collisions, forbidden kinds, a band
20
20
  * with no variable) and no name check. One way to check; the engines stay
21
21
  * where they were imported on purpose.
22
22
  *
@@ -28,6 +28,7 @@
28
28
  * package do not carry; a host that passes its own vocabulary may widen
29
29
  * `refuse`.
30
30
  * @experimental
31
+ * @ruling typed templates P5 (2026-09-27), design §4, law T1, owner Q6, T1
31
32
  */
32
33
  import { type BandSource } from './bands.js';
33
34
  import type { DocEdge, DocNode } from './document.js';
@@ -93,7 +94,7 @@ interface LawFinding {
93
94
  }
94
95
  type Describe = (node: DocNode) => (ScopeSource & BandSource) | undefined;
95
96
  /**
96
- * Law T1 over one document (design §4.2):
97
+ * The template-fit law over one document:
97
98
  *
98
99
  * - a root two declarers claim at a template node, or a forbidden kind in its
99
100
  * scope — refused, naming both declarers (`templateScopeReport`);
@@ -103,10 +104,11 @@ type Describe = (node: DocNode) => (ScopeSource & BandSource) | undefined;
103
104
  * configured value, each preset's) is checked against the typed scope of
104
105
  * the slot it fills, and a name or path nothing supplies is refused.
105
106
  *
106
- * Also law T2 (P6, `annexPortFindings`): the annex in-port.
107
+ * Also the annex in-port law (`annexPortFindings`).
107
108
  *
108
109
  * Errors only: a warning is the editor's and the receipt's to say.
109
110
  * @experimental
111
+ * @ruling law T1, design §4.2, law T2, P6
110
112
  */
111
113
  export declare function templateLawFindings(doc: Doc & {
112
114
  presets?: ReadonlyArray<{
@@ -123,15 +125,42 @@ export declare const TEMPLATE_ANNEX_QUERY = "core:query/session-annex";
123
125
  /** @experimental */
124
126
  export declare const TEMPLATE_ANNEX_VIEW = "template";
125
127
  /**
126
- * Law T2 (typed templates P6, owner ruling Q1): a template node's `annex`
128
+ * The annex in-port law: a template node's `annex`
127
129
  * in-port is fed only by `core:query/session-annex@1` reading `view:
128
130
  * 'template'` — every declared key of every owner in scope, and nothing a
129
131
  * declaration does not cover — and a template-view read feeds nothing but
130
132
  * such a port. Either half broken would put undeclared data into a prompt, or
131
133
  * the prompt's data somewhere a prompt is not. Errors only.
132
134
  * @experimental
135
+ * @ruling law T2, typed templates P6, owner ruling Q1
133
136
  */
134
137
  export declare function annexPortFindings(doc: Doc, describe?: Describe): LawFinding[];
138
+ /** One variable-layout seed that does not fit its variable. @experimental */
139
+ export interface VariableSeedFinding {
140
+ /** The seed's template id. */
141
+ template: string;
142
+ variableId: string;
143
+ /** `warning` when the variable is not registered here, so nothing could be checked. */
144
+ severity: 'error' | 'warning';
145
+ message: string;
146
+ fix: string;
147
+ }
148
+ /**
149
+ * Check a package's **variable layout** seeds (`TemplateSeed` kind
150
+ * `variables`) against the scope of the variable each one lays out (owner
151
+ * ruling 2026-10-13, ★4). A layout is rendered with its variable's scope and
152
+ * nothing else, so a name the scope does not declare renders nothing — the
153
+ * same silent failure the host's editor lints for, caught at packaging.
154
+ *
155
+ * A seed may lay out a variable the package does not own — a "prose cast"
156
+ * layout for `core:var/characters@1` — and is checked against that scope the
157
+ * same way. One whose variable is not registered where the package is built
158
+ * (another package's) is a warning: nothing here can see its scope.
159
+ * @experimental
160
+ */
161
+ export declare function variableSeedFindings(seeds: readonly TemplateSeed[], checking: TemplateChecking, variable?: (id: string) => {
162
+ scope: TemplateScope;
163
+ } | undefined): VariableSeedFinding[];
135
164
  /** One refused seed: which, where, and the sentence. @experimental */
136
165
  export interface TemplateSeedFinding {
137
166
  /** The seed's template id. */
@@ -1,13 +1,13 @@
1
1
  /**
2
- * Does this template fit this node? (typed templates P5, 2026-09-27)
2
+ * Does this template fit this node?
3
3
  *
4
- * The refusals of design §4, in one place: a template is checked against the
4
+ * The template-fit refusals, in one place: a template is checked against the
5
5
  * typed scope of the node that renders it (`templateScopeReport`), and a name
6
6
  * or path nothing there supplies is REFUSED — at selection (the host), at a
7
- * spec's save and publish (law T1, `validate()`), and at packaging (a plugin's
7
+ * spec's save and publish (`validate()`), and at packaging (a plugin's
8
8
  * shipped template seeds). Warnings never refuse, and nor does anything while
9
9
  * a producer upstream declares no types (`untyped`): its keys may still
10
- * arrive, so the checker only warns (owner Q6: refuse new selections and new
10
+ * arrive, so the checker only warns (refuse new selections and new
11
11
  * saves; a stored row becomes a notice, never a retroactive refusal).
12
12
  *
13
13
  * ## The checker is a value
@@ -16,7 +16,7 @@
16
16
  * which carries `handlebars` and `liquidjs`); this module is on the barrel,
17
17
  * which stays dependency-free. So every door here takes the checker as an
18
18
  * argument — `{ check: checkTemplateSourceReport }` — and a caller without one
19
- * gets the checker-free half of T1 (scope collisions, forbidden kinds, a band
19
+ * gets the checker-free half of the law (scope collisions, forbidden kinds, a band
20
20
  * with no variable) and no name check. One way to check; the engines stay
21
21
  * where they were imported on purpose.
22
22
  *
@@ -28,6 +28,7 @@
28
28
  * package do not carry; a host that passes its own vocabulary may widen
29
29
  * `refuse`.
30
30
  * @experimental
31
+ * @ruling typed templates P5 (2026-09-27), design §4, law T1, owner Q6, T1
31
32
  */
32
33
  import { BandCollisionError, rendersAt } from './bands.js';
33
34
  import { getDefinition } from './descriptors.js';
@@ -130,7 +131,7 @@ function templateSourcesAt(doc, node, slotName, first) {
130
131
  return out;
131
132
  }
132
133
  /**
133
- * Law T1 over one document (design §4.2):
134
+ * The template-fit law over one document:
134
135
  *
135
136
  * - a root two declarers claim at a template node, or a forbidden kind in its
136
137
  * scope — refused, naming both declarers (`templateScopeReport`);
@@ -140,10 +141,11 @@ function templateSourcesAt(doc, node, slotName, first) {
140
141
  * configured value, each preset's) is checked against the typed scope of
141
142
  * the slot it fills, and a name or path nothing supplies is refused.
142
143
  *
143
- * Also law T2 (P6, `annexPortFindings`): the annex in-port.
144
+ * Also the annex in-port law (`annexPortFindings`).
144
145
  *
145
146
  * Errors only: a warning is the editor's and the receipt's to say.
146
147
  * @experimental
148
+ * @ruling law T1, design §4.2, law T2, P6
147
149
  */
148
150
  export function templateLawFindings(doc, checking, env = {}) {
149
151
  const f = [];
@@ -154,6 +156,37 @@ export function templateLawFindings(doc, checking, env = {}) {
154
156
  if (!d)
155
157
  continue;
156
158
  const slots = (d.slots ?? {});
159
+ // The spec's own `renders` on this node (owner ruling 2026-10-13): each
160
+ // key one of the definition's `variables` slots renders, each variable
161
+ // registered with the key in its scope — the builder refuses the same
162
+ // at authoring; this is the same check for a document from anywhere
163
+ // else (the canvas editor, an import).
164
+ const rendered = Object.values(slots)
165
+ .filter((s) => s.kind === 'variables')
166
+ .flatMap((s) => Object.keys(s.renders ?? {}));
167
+ for (const [key, id] of Object.entries(node.renders ?? {})) {
168
+ // Every lookup through `variable` — the caller's registry — and only
169
+ // that; the key is one the definition renders, so it is already an
170
+ // identifier and not one of Assemble's names (`register()` checked).
171
+ const v = variable(id);
172
+ const problem = !rendered.includes(key)
173
+ ? `'${key}', which '${node.definitionId}' does not render — a spec says what a key means, it does not add one`
174
+ : !v
175
+ ? `'${key}' as '${id}', which is not registered here`
176
+ : !Object.prototype.hasOwnProperty.call(v.scope, key)
177
+ ? `'${key}' as '${id}', whose scope does not declare '${key}'`
178
+ : undefined;
179
+ if (problem)
180
+ f.push({
181
+ law: 'T1',
182
+ severity: 'error',
183
+ nodeKey: node.key,
184
+ message: `'${node.key}' renders ${problem}`,
185
+ fix: rendered.includes(key)
186
+ ? `name a registered variable whose scope declares '${key}', or drop '${key}' from the node's renders`
187
+ : `drop '${key}' from the node's renders — '${node.definitionId}' renders ${rendered.map((r) => `'${r}'`).join(', ') || 'nothing'}`,
188
+ });
189
+ }
157
190
  for (const slot of Object.values(slots)) {
158
191
  if (slot.kind !== 'variables' || !slot.rendersBands)
159
192
  continue;
@@ -230,13 +263,14 @@ export const TEMPLATE_ANNEX_VIEW = 'template';
230
263
  const headOf = (p) => p.split('.')[0];
231
264
  const isDataRef = (v) => !!v && typeof v === 'object' && v.__ref === 'data';
232
265
  /**
233
- * Law T2 (typed templates P6, owner ruling Q1): a template node's `annex`
266
+ * The annex in-port law: a template node's `annex`
234
267
  * in-port is fed only by `core:query/session-annex@1` reading `view:
235
268
  * 'template'` — every declared key of every owner in scope, and nothing a
236
269
  * declaration does not cover — and a template-view read feeds nothing but
237
270
  * such a port. Either half broken would put undeclared data into a prompt, or
238
271
  * the prompt's data somewhere a prompt is not. Errors only.
239
272
  * @experimental
273
+ * @ruling law T2, typed templates P6, owner ruling Q1
240
274
  */
241
275
  export function annexPortFindings(doc, describe = defaultDescribe) {
242
276
  const f = [];
@@ -300,6 +334,56 @@ export function annexPortFindings(doc, describe = defaultDescribe) {
300
334
  }
301
335
  return f;
302
336
  }
337
+ /**
338
+ * Check a package's **variable layout** seeds (`TemplateSeed` kind
339
+ * `variables`) against the scope of the variable each one lays out (owner
340
+ * ruling 2026-10-13, ★4). A layout is rendered with its variable's scope and
341
+ * nothing else, so a name the scope does not declare renders nothing — the
342
+ * same silent failure the host's editor lints for, caught at packaging.
343
+ *
344
+ * A seed may lay out a variable the package does not own — a "prose cast"
345
+ * layout for `core:var/characters@1` — and is checked against that scope the
346
+ * same way. One whose variable is not registered where the package is built
347
+ * (another package's) is a warning: nothing here can see its scope.
348
+ * @experimental
349
+ */
350
+ export function variableSeedFindings(seeds, checking, variable = getVariable) {
351
+ const out = [];
352
+ for (const seed of seeds) {
353
+ if (seed.kind !== 'variables' || typeof seed.body !== 'string' || !seed.engine || !seed.variableId)
354
+ continue;
355
+ const decl = variable(seed.variableId);
356
+ if (!decl) {
357
+ out.push({
358
+ template: seed.id,
359
+ variableId: seed.variableId,
360
+ severity: 'warning',
361
+ message: `lays out '${seed.variableId}', which is not registered here, so its source was not checked`,
362
+ fix: `declare '${seed.variableId}' in this package, or check the layout on an instance that has it`,
363
+ });
364
+ continue;
365
+ }
366
+ const result = checking.check(seed.engine, seed.body, decl.scope, checking.options);
367
+ const refuse = new Set(checking.refuse ?? SCOPE_FINDING_KINDS);
368
+ // Names and paths the scope does not supply — never a parse finding:
369
+ // the packager does not know the instance's helpers, filters and block
370
+ // tags, so a Liquid layout using core's `jsonValue` would read as a
371
+ // syntax error here and render fine there. The same rule
372
+ // `templateSeedFindings` follows.
373
+ const refusals = result.findings.filter((f) => f.severity === 'error' && f.kind !== undefined && refuse.has(f.kind));
374
+ if (!refusals.length)
375
+ continue;
376
+ out.push({
377
+ template: seed.id,
378
+ variableId: seed.variableId,
379
+ severity: 'error',
380
+ message: refusals.map((f) => f.message).join('; '),
381
+ fix: refusals[0].fix ||
382
+ `read only what '${seed.variableId}' declares: ${Object.keys(decl.scope).map((k) => `'${k}'`).join(', ')}`,
383
+ });
384
+ }
385
+ return out;
386
+ }
303
387
  /**
304
388
  * Check a package's `context template` seeds (`TemplateSeed` kind
305
389
  * `template`) against every node of its own specs that renders them — the
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * **Template ids** — the owner-namespaced name a spec uses to reference a
3
- * template row, and the declaration a plugin ships one under (R19).
3
+ * template row, and the declaration a plugin ships one under.
4
4
  *
5
5
  * ## The problem this closes
6
6
  *
@@ -45,8 +45,8 @@
45
45
  * (`engines.ts`) and share this kind segment. The two never meet in one field:
46
46
  * an engine id is only ever read from an `engine` column or an engine registry,
47
47
  * a template id only from `template_id` or a config value's `templateId`. The
48
- * overlap is recorded here rather than left to be discovered — see the report
49
- * accompanying R19.
48
+ * overlap is recorded here rather than left to be discovered.
49
+ * @ruling R19, R19
50
50
  */
51
51
  import type { EngineId } from './engines.js';
52
52
  /**
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * **Template ids** — the owner-namespaced name a spec uses to reference a
3
- * template row, and the declaration a plugin ships one under (R19).
3
+ * template row, and the declaration a plugin ships one under.
4
4
  *
5
5
  * ## The problem this closes
6
6
  *
@@ -45,8 +45,8 @@
45
45
  * (`engines.ts`) and share this kind segment. The two never meet in one field:
46
46
  * an engine id is only ever read from an `engine` column or an engine registry,
47
47
  * a template id only from `template_id` or a config value's `templateId`. The
48
- * overlap is recorded here rather than left to be discovered — see the report
49
- * accompanying R19.
48
+ * overlap is recorded here rather than left to be discovered.
49
+ * @ruling R19, R19
50
50
  */
51
51
  /**
52
52
  * The grammar, mirroring the attribute slot id's exactly one kind segment over.