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

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 (230) hide show
  1. package/README.md +23 -19
  2. package/dist/actions.d.ts +178 -69
  3. package/dist/actions.js +109 -40
  4. package/dist/annexFields.d.ts +12 -5
  5. package/dist/annexFields.js +6 -2
  6. package/dist/announce.d.ts +220 -30
  7. package/dist/announce.js +212 -7
  8. package/dist/attributes.d.ts +290 -11
  9. package/dist/attributes.js +317 -32
  10. package/dist/bands.d.ts +41 -6
  11. package/dist/bands.js +83 -33
  12. package/dist/bridges.d.ts +61 -0
  13. package/dist/bridges.js +112 -0
  14. package/dist/builder.d.ts +436 -106
  15. package/dist/builder.js +389 -46
  16. package/dist/cadences.d.ts +578 -0
  17. package/dist/cadences.js +1111 -0
  18. package/dist/candidates.d.ts +5 -3
  19. package/dist/candidates.js +3 -2
  20. package/dist/capabilities.d.ts +93 -15
  21. package/dist/capabilities.js +57 -6
  22. package/dist/checkMethods.d.ts +240 -0
  23. package/dist/checkMethods.js +362 -0
  24. package/dist/clauses.d.ts +2 -1
  25. package/dist/clauses.js +2 -1
  26. package/dist/component.d.ts +24 -7
  27. package/dist/component.js +16 -6
  28. package/dist/componentBuild.d.ts +16 -5
  29. package/dist/componentBuild.js +14 -5
  30. package/dist/componentClient.d.ts +61 -30
  31. package/dist/componentClient.js +11 -1
  32. package/dist/componentImports.d.ts +8 -5
  33. package/dist/componentImports.js +23 -4
  34. package/dist/componentModule.js +2 -1
  35. package/dist/componentWire.d.ts +2 -1
  36. package/dist/componentWire.js +34 -2
  37. package/dist/composerStates.d.ts +96 -0
  38. package/dist/composerStates.js +190 -0
  39. package/dist/conditions.d.ts +424 -0
  40. package/dist/conditions.js +521 -0
  41. package/dist/config.d.ts +69 -19
  42. package/dist/config.js +64 -26
  43. package/dist/connections.d.ts +9 -4
  44. package/dist/connections.js +7 -4
  45. package/dist/conversions.d.ts +41 -0
  46. package/dist/conversions.js +50 -0
  47. package/dist/declarations.d.ts +70 -18
  48. package/dist/declarations.js +194 -24
  49. package/dist/descriptors.d.ts +427 -100
  50. package/dist/descriptors.js +344 -59
  51. package/dist/dev.d.ts +6 -5
  52. package/dist/dev.js +6 -5
  53. package/dist/document.d.ts +121 -27
  54. package/dist/document.js +77 -24
  55. package/dist/dowry.d.ts +241 -0
  56. package/dist/dowry.js +315 -0
  57. package/dist/engines.d.ts +16 -7
  58. package/dist/engines.js +6 -4
  59. package/dist/entities.d.ts +156 -0
  60. package/dist/entities.js +259 -0
  61. package/dist/eventMapLaws.d.ts +19 -8
  62. package/dist/eventMapLaws.js +9 -6
  63. package/dist/events.d.ts +648 -40
  64. package/dist/events.js +451 -34
  65. package/dist/executor.d.ts +123 -41
  66. package/dist/executor.js +210 -103
  67. package/dist/exposure.d.ts +128 -0
  68. package/dist/exposure.js +168 -0
  69. package/dist/extension.d.ts +99 -35
  70. package/dist/extension.js +43 -9
  71. package/dist/facets.d.ts +2 -1
  72. package/dist/facets.js +4 -2
  73. package/dist/fit.d.ts +198 -0
  74. package/dist/fit.js +351 -0
  75. package/dist/foldedSections.d.ts +4 -2
  76. package/dist/foldedSections.js +2 -1
  77. package/dist/functions.d.ts +554 -0
  78. package/dist/functions.js +712 -0
  79. package/dist/genres.d.ts +408 -130
  80. package/dist/genres.js +412 -108
  81. package/dist/guardedConnection.d.ts +4 -3
  82. package/dist/guardedConnection.js +4 -3
  83. package/dist/handlebarsReach.d.ts +1 -1
  84. package/dist/handlebarsReach.js +1 -1
  85. package/dist/hash.d.ts +16 -5
  86. package/dist/hash.js +14 -4
  87. package/dist/hookGrants.d.ts +4 -3
  88. package/dist/hookGrants.js +7 -5
  89. package/dist/hooks.d.ts +42 -21
  90. package/dist/hooks.js +17 -12
  91. package/dist/hostElements.d.ts +47 -17
  92. package/dist/hostElements.js +62 -17
  93. package/dist/hostState.d.ts +110 -0
  94. package/dist/hostState.js +140 -0
  95. package/dist/i18n.d.ts +5 -3
  96. package/dist/i18n.js +5 -3
  97. package/dist/identity.d.ts +5 -4
  98. package/dist/identity.js +5 -4
  99. package/dist/index.d.ts +26 -0
  100. package/dist/index.js +55 -0
  101. package/dist/jsonSchema.d.ts +178 -0
  102. package/dist/jsonSchema.js +558 -0
  103. package/dist/layout.d.ts +36 -15
  104. package/dist/layout.js +2 -2
  105. package/dist/loadouts.d.ts +97 -0
  106. package/dist/loadouts.js +81 -0
  107. package/dist/media.d.ts +153 -16
  108. package/dist/media.js +47 -2
  109. package/dist/messageBlocks.d.ts +223 -37
  110. package/dist/messageBlocks.js +231 -24
  111. package/dist/migration.d.ts +16 -8
  112. package/dist/migration.js +14 -8
  113. package/dist/names.d.ts +2 -1
  114. package/dist/names.js +2 -1
  115. package/dist/nodeInput.d.ts +2 -1
  116. package/dist/nodeInput.js +2 -1
  117. package/dist/participants.d.ts +54 -24
  118. package/dist/participants.js +27 -14
  119. package/dist/personGate.d.ts +2 -1
  120. package/dist/personGate.js +2 -1
  121. package/dist/pluginHarness.d.ts +22 -35
  122. package/dist/pluginHarness.js +18 -143
  123. package/dist/pluginPermissions.d.ts +2 -1
  124. package/dist/pluginPermissions.js +13 -2
  125. package/dist/pluginRuleRef.d.ts +2 -2
  126. package/dist/pluginRuleRef.js +1 -1
  127. package/dist/predicates.d.ts +16 -11
  128. package/dist/predicates.js +7 -6
  129. package/dist/preview.d.ts +53 -7
  130. package/dist/preview.js +54 -13
  131. package/dist/primers.d.ts +177 -0
  132. package/dist/primers.js +265 -0
  133. package/dist/promptBlocks.d.ts +5 -3
  134. package/dist/promptBlocks.js +5 -3
  135. package/dist/rankingDecisions.d.ts +2 -1
  136. package/dist/rankingDecisions.js +2 -1
  137. package/dist/receipt.d.ts +76 -29
  138. package/dist/receipt.js +9 -4
  139. package/dist/receiverRules.js +3 -2
  140. package/dist/refs.d.ts +42 -9
  141. package/dist/refs.js +45 -13
  142. package/dist/registrations.d.ts +384 -0
  143. package/dist/registrations.js +625 -0
  144. package/dist/registry.d.ts +42 -23
  145. package/dist/registry.js +7 -5
  146. package/dist/repertoires.d.ts +502 -0
  147. package/dist/repertoires.js +666 -0
  148. package/dist/review.d.ts +16 -5
  149. package/dist/review.js +11 -4
  150. package/dist/rulesetDocument.d.ts +95 -0
  151. package/dist/rulesetDocument.js +190 -0
  152. package/dist/rulesetSections.d.ts +597 -0
  153. package/dist/rulesetSections.js +1249 -0
  154. package/dist/rulesetTemplates.d.ts +161 -0
  155. package/dist/rulesetTemplates.js +242 -0
  156. package/dist/rulesets.d.ts +899 -0
  157. package/dist/rulesets.js +1378 -0
  158. package/dist/sampling.d.ts +54 -0
  159. package/dist/sampling.js +95 -3
  160. package/dist/sceneSettings.d.ts +320 -0
  161. package/dist/sceneSettings.js +433 -0
  162. package/dist/scope.d.ts +50 -7
  163. package/dist/scope.js +22 -3
  164. package/dist/scripts.d.ts +112 -22
  165. package/dist/scripts.js +135 -19
  166. package/dist/sessionDossier.d.ts +638 -0
  167. package/dist/sessionDossier.js +33 -0
  168. package/dist/sessionLayout.d.ts +492 -55
  169. package/dist/sessionLayout.js +697 -90
  170. package/dist/sessionSettings.d.ts +32 -5
  171. package/dist/settings.d.ts +66 -20
  172. package/dist/settings.js +19 -12
  173. package/dist/settingsSlot.d.ts +11 -8
  174. package/dist/settingsSlot.js +11 -8
  175. package/dist/shapes.d.ts +139 -37
  176. package/dist/shapes.js +152 -38
  177. package/dist/sheets.d.ts +4 -2
  178. package/dist/sheets.js +6 -3
  179. package/dist/statShapes.d.ts +10 -2
  180. package/dist/statShapes.js +10 -2
  181. package/dist/status.d.ts +27 -9
  182. package/dist/status.js +20 -6
  183. package/dist/storage.d.ts +11 -67
  184. package/dist/storage.js +9 -13
  185. package/dist/storyTime.d.ts +13 -7
  186. package/dist/storyTime.js +11 -6
  187. package/dist/strokes.d.ts +176 -0
  188. package/dist/strokes.js +281 -0
  189. package/dist/surfaces.d.ts +54 -25
  190. package/dist/surfaces.js +3 -3
  191. package/dist/template.d.ts +9 -5
  192. package/dist/template.js +5 -3
  193. package/dist/templateCheck.d.ts +2 -2
  194. package/dist/templateCheck.js +2 -2
  195. package/dist/templateFit.d.ts +37 -8
  196. package/dist/templateFit.js +92 -8
  197. package/dist/templateIds.d.ts +3 -3
  198. package/dist/templateIds.js +3 -3
  199. package/dist/templateScopeAt.d.ts +22 -12
  200. package/dist/templateScopeAt.js +32 -19
  201. package/dist/testing.d.ts +11 -4
  202. package/dist/testing.js +13 -5
  203. package/dist/ties.d.ts +210 -0
  204. package/dist/ties.js +300 -0
  205. package/dist/tokenizers.d.ts +2 -2
  206. package/dist/tokenizers.js +2 -2
  207. package/dist/turnLock.d.ts +4 -2
  208. package/dist/turnLock.js +2 -1
  209. package/dist/turnOrder.d.ts +39 -22
  210. package/dist/turnOrder.js +30 -13
  211. package/dist/validate.d.ts +11 -8
  212. package/dist/validate.js +195 -29
  213. package/dist/values.d.ts +17 -8
  214. package/dist/values.js +11 -6
  215. package/dist/variables.d.ts +46 -7
  216. package/dist/variables.js +87 -6
  217. package/dist/verdicts.d.ts +20 -13
  218. package/dist/verdicts.js +17 -11
  219. package/dist/vocabularies.d.ts +192 -0
  220. package/dist/vocabularies.js +326 -0
  221. package/dist/widgetDecls.d.ts +20 -4
  222. package/dist/widgetDecls.js +6 -2
  223. package/dist/widgets.d.ts +1580 -111
  224. package/dist/widgets.js +113 -18
  225. package/dist/wire.d.ts +13 -6
  226. package/dist/wire.js +3 -3
  227. package/dist/worldinfo.d.ts +11 -6
  228. package/dist/worldinfo.js +8 -4
  229. package/host-elements.d.ts +101 -0
  230. package/package.json +1 -1
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * ## Three levels, and only the middle one is new here
5
5
  *
6
- * A stat is three things, not one (entries plan Part 3): a **declaration**
6
+ * A stat is three things, not one: a **declaration**
7
7
  * ("Health is an integer with a max, and it attaches to cast members"), a
8
8
  * **configuration** ("this character's Health caps at 20"), and a **value**
9
9
  * ("health = 12, as of message 47"). This file owns the first. The other two
@@ -57,7 +57,7 @@
57
57
  * than part of it, and writing one down must not force an `@N+1` on everything
58
58
  * already storing values under the id.
59
59
  *
60
- * ⚠ **"Slot" here is not a pipeline slot.** NOMENCLATURE §"slot" is a declared
60
+ * ⚠ **"Slot" here is not a pipeline slot.** A pipeline *slot* is a declared
61
61
  * parameter address on a node type (`SlotDecl` in descriptors.ts). This is an
62
62
  * *attribute* slot, and prose says the qualified word. The two never meet: one
63
63
  * is a key on a descriptor, the other is an id in this registry.
@@ -69,11 +69,13 @@
69
69
  * will be imported wrong. The *types* keep the short names (`SlotId`,
70
70
  * `SlotConfig`, `SlotValue`): they are only ever written next to this file's
71
71
  * functions, so they cannot be mistaken at a call site.
72
+ * @ruling entries plan Part 3
72
73
  */
73
- import { i18nFindings } from './i18n.js';
74
+ import { i18nFindings, i18nText } from './i18n.js';
74
75
  import { refuseUnlessIdentical } from './hash.js';
75
76
  import { getStatShape, statShapeKindOf } from './statShapes.js';
76
77
  import { parseStoryTime } from './storyTime.js';
78
+ import { _repertoireTimeUnit, checkPiece, getRepertoire, RULESET_ID_PATTERN } from './repertoires.js';
77
79
  const SLOT_ID = /^[a-z0-9]+(?:[.-][a-z0-9]+)*:slot\/[a-z0-9]+(?:-[a-z0-9]+)*@\d+$/;
78
80
  /** @experimental */
79
81
  export function assertSlotId(id) {
@@ -170,10 +172,16 @@ export const derivations = Object.freeze({
170
172
  });
171
173
  /** @experimental */
172
174
  export const getDerivation = (id) => Object.values(derivations).find((d) => d.id === id);
175
+ /** 🚧 Is this list item a piece? @experimental */
176
+ export const isSlotPiece = (item) => !!item &&
177
+ typeof item === 'object' &&
178
+ !Array.isArray(item) &&
179
+ (item.kind === 'inline' || item.kind === 'lore' || item.kind === 'compendium');
173
180
  /** Is this list item a lore reference? @experimental */
174
181
  export const isSlotLoreRef = (item) => !!item &&
175
182
  typeof item === 'object' &&
176
183
  !Array.isArray(item) &&
184
+ !('kind' in item) &&
177
185
  Number.isInteger(item.entryId) &&
178
186
  item.entryId > 0;
179
187
  /** 🚧 How many of its entry a reference holds: its `count`, or one when it states none. @experimental */
@@ -190,8 +198,8 @@ export function heldCountIn(value, entryId) {
190
198
  return 0;
191
199
  let held = 0;
192
200
  for (const item of value)
193
- if (isSlotLoreRef(item) && item.entryId === entryId)
194
- held += slotLoreRefCount(item);
201
+ if ((isSlotLoreRef(item) || (isSlotPiece(item) && item.kind === 'lore')) && item.entryId === entryId)
202
+ held += typeof item.count === 'number' ? item.count : 1;
195
203
  return held;
196
204
  }
197
205
  /**
@@ -203,6 +211,17 @@ export function heldCountIn(value, entryId) {
203
211
  * @experimental
204
212
  */
205
213
  export function slotListItemText(item) {
214
+ if (isSlotPiece(item)) {
215
+ const named = item.kind === 'inline' ? undefined : item.overrides?.name;
216
+ const overridden = typeof named === 'string' ? named : undefined;
217
+ const title = item.kind === 'inline'
218
+ ? item.name
219
+ : overridden?.trim() ||
220
+ item.name?.trim() ||
221
+ (item.kind === 'lore' ? `entry ${item.entryId}` : item.pieceId);
222
+ const count = typeof item.count === 'number' ? item.count : 1;
223
+ return count > 1 ? `${title} ×${count}` : title;
224
+ }
206
225
  if (isSlotLoreRef(item)) {
207
226
  const title = item.name?.trim() || `entry ${item.entryId}`;
208
227
  const count = slotLoreRefCount(item);
@@ -226,22 +245,119 @@ export function slotValueForStorage(value) {
226
245
  return { entryId: value.entryId };
227
246
  if (!Array.isArray(value))
228
247
  return value;
229
- return value.map((item) => isSlotLoreRef(item)
230
- ? // One held is stored bare (phase 4): `count: 1` and no count are
231
- // one value, and it has one spelling on disk.
232
- item.count === undefined || item.count === 1
233
- ? { entryId: item.entryId }
234
- : { entryId: item.entryId, count: item.count }
235
- : item);
236
- }
237
- /** The identity two list items are "the same item" by: a word by its text, a reference by its entry. */
238
- const listItemKey = (item) => isSlotLoreRef(item) ? `entry:${item.entryId}` : `${typeof item}:${String(item)}`;
248
+ return value.map((item) => isSlotPiece(item)
249
+ ? pieceForStorage(item)
250
+ : isSlotLoreRef(item)
251
+ ? // One held is stored bare (phase 4): `count: 1` and no count are
252
+ // one value, and it has one spelling on disk.
253
+ item.count === undefined || item.count === 1
254
+ ? { entryId: item.entryId }
255
+ : { entryId: item.entryId, count: item.count }
256
+ : item);
257
+ }
258
+ /**
259
+ * 🚧 The words a value reads at a table that keeps no numbers: the first
260
+ * band its share of `max` fits (`max` absent or 0: a value above none is the
261
+ * whole), or `null` when the slot declares none.
262
+ * @experimental
263
+ */
264
+ export function slotWordsFor(bands, value, max) {
265
+ if (!bands?.length || typeof value !== 'number' || !Number.isFinite(value))
266
+ return null;
267
+ const top = typeof max === 'number' && max > 0 ? max : null;
268
+ const share = top === null ? (value > 0 ? 1 : 0) : Math.max(0, Math.min(1, value / top));
269
+ for (const b of bands)
270
+ if (share <= b.upTo)
271
+ return b.label;
272
+ return bands[bands.length - 1].label;
273
+ }
274
+ /** A piece as stored: the host-filled `name` and `resolved` of a reference dropped, a count of one spelled bare. */
275
+ function pieceForStorage(item) {
276
+ const { count, ...rest } = item;
277
+ const kept = { ...rest };
278
+ if (item.kind !== 'inline') {
279
+ delete kept.name;
280
+ delete kept.resolved;
281
+ }
282
+ return (count === undefined || count === 1 ? kept : { ...kept, count });
283
+ }
284
+ /**
285
+ * The identity two list items are "the same item" by: a word by its text, a
286
+ * reference (or a lore piece) by its entry, a compendium piece by its row, an
287
+ * inline piece by its name.
288
+ */
289
+ const listItemKey = (item) => isSlotPiece(item)
290
+ ? item.kind === 'lore'
291
+ ? `entry:${item.entryId}`
292
+ : item.kind === 'compendium'
293
+ ? `compendium:${item.compendiumId}/${item.pieceId}`
294
+ : `piece:${String(item.name).trim().toLowerCase()}`
295
+ : isSlotLoreRef(item)
296
+ ? `entry:${item.entryId}`
297
+ : `${typeof item}:${String(item)}`;
239
298
  /** 🚧 The earshots a slot may declare. @experimental */
240
299
  export const SLOT_EARSHOTS = Object.freeze(['all', 'holder']);
241
300
  /** 🚧 A slot's earshot, the default read in: `'holder'` only when it says so. @experimental */
242
301
  export const slotEarshot = (decl) => decl.earshot === 'holder' ? 'holder' : 'all';
243
302
  /** 🚧 May a session pick this slot as an attribute of its own or carry it in from its world? @experimental */
244
303
  export const slotPickable = (decl) => decl.pickable !== false;
304
+ /**
305
+ * Which rulesets own each slot by listing it under their `stats` (not
306
+ * `borrowed`) — filled by `rulesets.ts` as each ruleset registers, so a
307
+ * ruleset's own slots need not spell `rulesetOwned` 20 times over.
308
+ */
309
+ const listedOwners = new Map();
310
+ /** Record the slots a registering ruleset owns. Called by `rulesets.ts` only. @internal */
311
+ export function _registerRulesetStats(rulesetId, slotIds) {
312
+ for (const id of slotIds) {
313
+ let owners = listedOwners.get(id);
314
+ if (!owners)
315
+ listedOwners.set(id, (owners = new Set()));
316
+ owners.add(rulesetId);
317
+ }
318
+ }
319
+ /** @internal */
320
+ export function _clearRulesetStats() {
321
+ listedOwners.clear();
322
+ }
323
+ /**
324
+ * 🚧 Forget that one ruleset lists any slot (`_registerRulesetStats`'s
325
+ * inverse); a slot nobody lists any more is dropped from the index.
326
+ * @internal
327
+ */
328
+ export function _withdrawRulesetStats(rulesetId) {
329
+ for (const [id, owners] of [...listedOwners]) {
330
+ owners.delete(rulesetId);
331
+ if (!owners.size)
332
+ listedOwners.delete(id);
333
+ }
334
+ }
335
+ /**
336
+ * 🚧 The rulesets that own a slot: every registered ruleset that lists it
337
+ * under its `stats` (not `borrowed`), with the slot's own `rulesetOwned` if
338
+ * it spells one. Empty: no ruleset's — pickable in every session.
339
+ * @experimental
340
+ */
341
+ export function slotRulesetOwners(decl) {
342
+ const owners = new Set(decl.id !== undefined ? (listedOwners.get(decl.id) ?? []) : []);
343
+ if (decl.rulesetOwned !== undefined)
344
+ owners.add(decl.rulesetOwned);
345
+ return [...owners];
346
+ }
347
+ /**
348
+ * 🚧 May a session whose ruleset is `sessionRuleset` pick this slot? A slot a
349
+ * ruleset owns (`slotRulesetOwners`: listed under its `stats`, or spelled
350
+ * `rulesetOwned`) is pickable only in the sessions of a ruleset that owns
351
+ * it; every other slot answers as `slotPickable` does. Pass the declaration
352
+ * with its `id`, so the derived owners are read.
353
+ * @experimental
354
+ */
355
+ export const slotPickableIn = (decl, sessionRuleset) => {
356
+ if (!slotPickable(decl))
357
+ return false;
358
+ const owners = slotRulesetOwners(decl);
359
+ return !owners.length || (typeof sessionRuleset === 'string' && owners.includes(sessionRuleset));
360
+ };
245
361
  const registry = new Map();
246
362
  /**
247
363
  * What is kept out of this registry's content hash beyond `i18n`/`description`.
@@ -312,6 +428,16 @@ function register(id, rawProps, origin, authorUserId) {
312
428
  export function defineAttributeSlot(id, props) {
313
429
  return register(id, props, 'code');
314
430
  }
431
+ /**
432
+ * 🚧 The rulesets' door: the slot a ruleset's own attribute files its values
433
+ * under (`rulesetAttributeSlotDecls`, `<owner>.<ruleset>:slot/<attribute>@N`),
434
+ * registered by `defineRuleset` with the ruleset and withdrawn with it. A
435
+ * code declaration, so an identical re-declaration is a no-op.
436
+ * @internal
437
+ */
438
+ export function _defineRulesetAttributeSlot(id, props) {
439
+ return register(id, props, 'code');
440
+ }
315
441
  /**
316
442
  * The plugin-facing door — same registration, minus the ability to claim core's
317
443
  * namespace. A plugin that could redefine `core:slot/hp@1` would change what
@@ -407,12 +533,13 @@ export function reviveAttributeSlot(id) {
407
533
  return next;
408
534
  }
409
535
  /**
410
- * The display-text findings of one slot declaration (R-20): `label` and
536
+ * The display-text findings of one slot declaration: `label` and
411
537
  * `description`, both optional — a slot may be listed by its id — but a blank
412
538
  * one is a label that draws nothing where the author meant to say something.
413
539
  * Run by the code door here and by the host's **write** door for an authored
414
540
  * slot (the app's `declareSlot` / `updateSlot`), never by a reload.
415
541
  * @internal
542
+ * @ruling R-20
416
543
  */
417
544
  export function attributeSlotDisplayFindings(id, props) {
418
545
  return [
@@ -428,11 +555,12 @@ function assertDisplayText(id, props) {
428
555
  }
429
556
  /**
430
557
  * A stored row reloading at boot is never refused for its display text
431
- * (ruled 2026-09-17, U5i review): the gate is the write door, and a row that
558
+ * (ruled 2026-09-17): the gate is the write door, and a row that
432
559
  * was stored with a blank `description` would otherwise vanish from every
433
560
  * boot after. The offending field is dropped — a blank label reads as "listed
434
561
  * by id" — and a warning names the row and the finding, so the defect is
435
562
  * visible without the slot being lost.
563
+ * @ruling U5i review
436
564
  */
437
565
  function withDisplayTextTolerated(id, props) {
438
566
  const findings = attributeSlotDisplayFindings(id, props);
@@ -499,7 +627,7 @@ export function slotField(decl) {
499
627
  /** The catalogue shape a slot names, when it names one (an inline `FieldDecl` names none). @experimental */
500
628
  export const slotStatShapeId = (decl) => typeof decl.shape === 'string' ? decl.shape : undefined;
501
629
  /** Which kind of stat a slot is; `undefined` for a derived slot, which is computed rather than kept. @experimental */
502
- export const slotStatShapeKind = (decl) => statShapeKindOf(slotField(decl));
630
+ export const slotStatShapeKind = (decl) => statShapeKindOf(slotField(decl), { repertoire: decl.config?.repertoire });
503
631
  /**
504
632
  * What a field bounds, as the configuration keys a layer deviates from: a
505
633
  * number's `min`/`max`; a choice's options (`of`, or its `members`' keys); a
@@ -546,6 +674,82 @@ export function fieldSlotConfig(field) {
546
674
  }
547
675
  return out;
548
676
  }
677
+ /**
678
+ * 🚧 The configuration keys an owner may set on this slot: what its stat
679
+ * shape bounds (`fieldSlotConfig`'s keys) — a number's `min` and `max`; a
680
+ * choice's `of`; a list's `maxItems` and, by its item, `of` or
681
+ * `maxLength`; a line's `maxLength` — and, on every kept slot, the
682
+ * `descriptor` (the model-facing sentence in this world, R5). A derived
683
+ * slot takes none. Nothing else is stored per owner: a key outside these
684
+ * would be kept and read by nobody.
685
+ * @experimental
686
+ */
687
+ export function statConfigKeys(decl) {
688
+ const field = slotField(decl);
689
+ if (!field)
690
+ return [];
691
+ switch (statShapeKindOf(field)) {
692
+ case 'number':
693
+ return ['min', 'max', 'descriptor'];
694
+ case 'choice':
695
+ return ['of', 'descriptor'];
696
+ case 'list':
697
+ return field.item?.type === 'enum' ? ['maxItems', 'of', 'descriptor'] : ['maxItems', 'maxLength', 'descriptor'];
698
+ case 'text':
699
+ return ['maxLength', 'descriptor'];
700
+ default:
701
+ return ['descriptor'];
702
+ }
703
+ }
704
+ /**
705
+ * 🚧 Why this owner configuration may not be stored for this slot — one
706
+ * sentence per fault, empty when it may. Asked of the document's `config`
707
+ * alone; whether its `min` still sits under the owner's `max` once merged
708
+ * with what is in force is the writer's to ask (it holds the layers).
709
+ * @experimental
710
+ */
711
+ export function statConfigRefusals(decl, config) {
712
+ const label = i18nText(decl.label) ?? decl.id;
713
+ if (!config || typeof config !== 'object' || Array.isArray(config))
714
+ return [`a stat configuration is an object of the keys to change, such as { max: 30 }.`];
715
+ if (decl.type === 'derived')
716
+ return [`${label} is derived, so there is nothing to configure: it is computed every time it is read.`];
717
+ const keys = statConfigKeys(decl);
718
+ const out = [];
719
+ const entries = Object.entries(config);
720
+ if (!entries.length)
721
+ out.push(`the configuration for ${label} changes nothing; name a key: ${keys.join(', ')}.`);
722
+ for (const [key, value] of entries) {
723
+ if (!keys.includes(key)) {
724
+ out.push(`${label} has no '${key}' to configure; it takes ${keys.join(', ')}.`);
725
+ continue;
726
+ }
727
+ switch (key) {
728
+ case 'min':
729
+ case 'max':
730
+ if (typeof value !== 'number' || !Number.isFinite(value))
731
+ out.push(`${label}'s ${key} is a number; '${String(value)}' is not one.`);
732
+ break;
733
+ case 'maxItems':
734
+ case 'maxLength':
735
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < 1)
736
+ out.push(`${label}'s ${key} is a whole number above zero; '${String(value)}' is not one.`);
737
+ break;
738
+ case 'of':
739
+ if (!Array.isArray(value) || !value.length || value.some((v) => typeof v !== 'string' || !v.trim()))
740
+ out.push(`${label}'s options are a list of words; '${JSON.stringify(value)}' is not one.`);
741
+ break;
742
+ case 'descriptor':
743
+ if (typeof value !== 'string' || !value.trim())
744
+ out.push(`${label} cannot be described as nothing here; leave 'descriptor' out to keep the declaration's own.`);
745
+ break;
746
+ }
747
+ }
748
+ const { min, max } = config;
749
+ if (typeof min === 'number' && typeof max === 'number' && min > max)
750
+ out.push(`${label}'s min (${min}) is above its max (${max}).`);
751
+ return out;
752
+ }
549
753
  /**
550
754
  * The type a declaration is, from what it said: `type`, `shape`, or both
551
755
  * agreeing. Refused with a sentence when neither is said, when the shape is
@@ -570,7 +774,7 @@ function typeOfDeclaration(id, props) {
570
774
  }
571
775
  else
572
776
  field = props.shape;
573
- const kind = statShapeKindOf(field);
777
+ const kind = statShapeKindOf(field, { repertoire: props.config?.repertoire });
574
778
  if (!kind)
575
779
  throw new Error(`${id} is shaped as a '${field?.type}' field, which is not a value core can keep as a stat. ` +
576
780
  `A stat is a number, a choice, a list of text, a story time, a line of text or a switch.`);
@@ -584,6 +788,45 @@ function typeOfDeclaration(id, props) {
584
788
  function checkSlotDeclaration(id, props) {
585
789
  if (props.pickable !== undefined && props.pickable !== false)
586
790
  throw new Error(`${id}.pickable: only \`false\` is said — a slot is pickable unless it says otherwise.`);
791
+ if (props.rulesetOwned !== undefined && !(typeof props.rulesetOwned === 'string' && RULESET_ID_PATTERN.test(props.rulesetOwned)))
792
+ throw new Error(`${id}.rulesetOwned is '${String(props.rulesetOwned)}'. Name the ruleset that declares the slot — ` +
793
+ `'owner:ruleset/name@N', 'core:ruleset/vis-itineris@1'.`);
794
+ if (props.minSeats !== undefined && !(Number.isInteger(props.minSeats) && props.minSeats >= 1))
795
+ throw new Error(`${id}.minSeats is ${String(props.minSeats)}. Say how many active player seats a session needs ` +
796
+ `before this slot is tracked — a whole number from 1 — or leave it out.`);
797
+ if (props.whenRulesetSetting !== undefined) {
798
+ const w = props.whenRulesetSetting;
799
+ const ok = !!w &&
800
+ typeof w === 'object' &&
801
+ typeof w.ruleset === 'string' &&
802
+ RULESET_ID_PATTERN.test(w.ruleset) &&
803
+ typeof w.setting === 'string' &&
804
+ w.setting.trim() !== '' &&
805
+ Array.isArray(w.is) &&
806
+ w.is.length > 0 &&
807
+ w.is.every((c) => typeof c === 'string' && c.trim() !== '');
808
+ if (!ok)
809
+ throw new Error(`${id}.whenRulesetSetting is { ruleset, setting, is }: the ruleset ('owner:ruleset/name@N'), ` +
810
+ `the name of one of its settings, and the choices under which the slot is tracked — ` +
811
+ `{ ruleset: 'core:ruleset/vis-itineris@1', setting: 'casting', is: ['points'] } — or leave it out.`);
812
+ }
813
+ if (props.shownWhenSet !== undefined && props.shownWhenSet !== true)
814
+ throw new Error(`${id}.shownWhenSet is true or left out: a stat drawn only while it holds something.`);
815
+ if (props.words !== undefined) {
816
+ const bands = props.words;
817
+ const ok = Array.isArray(bands) &&
818
+ bands.length > 0 &&
819
+ bands.every((b, i) => !!b &&
820
+ typeof b === 'object' &&
821
+ typeof b.upTo === 'number' &&
822
+ b.upTo >= 0 &&
823
+ b.upTo <= 1 &&
824
+ (i === 0 || b.upTo > bands[i - 1].upTo) &&
825
+ !!b.label);
826
+ if (!ok)
827
+ throw new Error(`${id}.words is a list of bands, first fitting first — each { upTo, label }, upTo a share of the ` +
828
+ `stat's maximum from 0 to 1 and rising — [{ upTo: 0, label: { en: "at death's door" } }, …] — or leave it out.`);
829
+ }
587
830
  if (props.earshot !== undefined && !SLOT_EARSHOTS.includes(props.earshot))
588
831
  throw new Error(`${id}.earshot is '${String(props.earshot)}'. A slot is heard by 'all' (the default) or ` +
589
832
  `by its 'holder' alone.`);
@@ -671,10 +914,11 @@ export function resolveSlotConfig(decl, ...layers) {
671
914
  * inventing three wordings for one rule is how a validator stops being one.
672
915
  *
673
916
  * ⚠ A value is checked against the configuration valid at **its own anchor**,
674
- * not against the current one (plan Part 3). Callers pass that config in; this
917
+ * not against the current one. Callers pass that config in; this
675
918
  * function never reaches for a current one, because doing so is precisely the
676
919
  * mistake that retroactively invalidates a legitimate historical value.
677
920
  * @internal
921
+ * @ruling plan Part 3
678
922
  */
679
923
  export function checkSlotValue(decl, value, config = resolveSlotConfig(decl)) {
680
924
  // Retirement answers first. It is the newest fact about the slot and the
@@ -741,6 +985,26 @@ export function checkSlotValue(decl, value, config = resolveSlotConfig(decl)) {
741
985
  const unique = config.unique !== false;
742
986
  const seen = new Set();
743
987
  for (const item of items) {
988
+ // 🚧 A piece — legal only where the slot names a repertoire,
989
+ // and checked against that repertoire's piece shape.
990
+ if (isSlotPiece(item)) {
991
+ if (!config.repertoire)
992
+ return `${decl.id} holds words and lore references; a piece belongs in a list whose config names a repertoire.`;
993
+ if (of)
994
+ return `${decl.id} holds items from ${of.join(', ') || '(nothing declared)'}; a piece is not one of them.`;
995
+ const rep = getRepertoire(String(config.repertoire));
996
+ if (!rep)
997
+ return `${decl.id} names the repertoire '${String(config.repertoire)}', which no installed ruleset declares — nothing new is written to it until one does.`;
998
+ const why = checkPiece(rep, item, { timeUnit: _repertoireTimeUnit(String(config.repertoire)) });
999
+ if (why)
1000
+ return `${decl.id}: ${why}`;
1001
+ const key = listItemKey(item);
1002
+ // A reference is held once whatever `unique` says — its count is its multiplicity.
1003
+ if ((item.kind !== 'inline' || unique) && seen.has(key))
1004
+ return `${decl.id} holds each piece once${item.kind === 'inline' ? '' : ', with a count'}; '${slotListItemText(item)}' is in it twice.`;
1005
+ seen.add(key);
1006
+ continue;
1007
+ }
744
1008
  // A lore reference is an item in its own right — unless the
745
1009
  // list is closed over words, where only those words are.
746
1010
  if (isSlotLoreRef(item)) {
@@ -822,6 +1086,22 @@ export function applyListOp(current, op, items, config = {}) {
822
1086
  ...(count === 1 ? {} : { count }),
823
1087
  ...(ref.name === undefined ? {} : { name: ref.name }),
824
1088
  });
1089
+ // 🚧 A piece that references something — a lore entry or a compendium
1090
+ // row — holds a count the same way a lore reference does: the same
1091
+ // reference twice is one holding with a count, never two items. An inline
1092
+ // piece is its own thing and is never merged. @experimental
1093
+ const isCountedPiece = (item) => isSlotPiece(item) && (item.kind === 'lore' || item.kind === 'compendium');
1094
+ const isCounted = (item) => isSlotLoreRef(item) || isCountedPiece(item);
1095
+ const countOf = (item) => isSlotLoreRef(item) ? slotLoreRefCount(item) : isCountedPiece(item) ? (item.count ?? 1) : 1;
1096
+ const statedCount = (item) => isSlotLoreRef(item) || isCountedPiece(item) ? item.count : undefined;
1097
+ const recount = (item, count) => {
1098
+ if (isSlotLoreRef(item))
1099
+ return withCount(item, count);
1100
+ if (!isCountedPiece(item))
1101
+ return item;
1102
+ const { count: _was, ...rest } = item;
1103
+ return count === 1 ? rest : { ...rest, count };
1104
+ };
825
1105
  let next;
826
1106
  switch (op) {
827
1107
  case 'set':
@@ -834,15 +1114,17 @@ export function applyListOp(current, op, items, config = {}) {
834
1114
  const out = [...held];
835
1115
  const rest = [];
836
1116
  for (const item of items) {
837
- if (!isSlotLoreRef(item) || item.count === undefined) {
1117
+ const stated = statedCount(item);
1118
+ if (!isCounted(item) || stated === undefined) {
838
1119
  rest.push(item);
839
1120
  continue;
840
1121
  }
841
- const at = out.findIndex((h) => isSlotLoreRef(h) && h.entryId === item.entryId);
1122
+ const key = listItemKey(item);
1123
+ const at = out.findIndex((h) => isCounted(h) && listItemKey(h) === key);
842
1124
  if (at < 0)
843
- out.push(withCount(item, item.count));
1125
+ out.push(recount(item, stated));
844
1126
  else
845
- out[at] = withCount(out[at], slotLoreRefCount(out[at]) + item.count);
1127
+ out[at] = recount(out[at], countOf(out[at]) + stated);
846
1128
  }
847
1129
  next = dedup([...out, ...rest]);
848
1130
  break;
@@ -850,18 +1132,21 @@ export function applyListOp(current, op, items, config = {}) {
850
1132
  case 'remove': {
851
1133
  // A counted reference takes that many and drops the item at zero;
852
1134
  // an uncounted one (and every word) takes the item out entirely.
853
- const out = new Set(items.filter((item) => !isSlotLoreRef(item) || item.count === undefined).map(listItemKey));
1135
+ const out = new Set(items.filter((item) => !isCounted(item) || statedCount(item) === undefined).map(listItemKey));
854
1136
  const less = new Map();
855
- for (const item of items)
856
- if (isSlotLoreRef(item) && item.count !== undefined)
857
- less.set(item.entryId, (less.get(item.entryId) ?? 0) + item.count);
1137
+ for (const item of items) {
1138
+ const stated = statedCount(item);
1139
+ if (isCounted(item) && stated !== undefined)
1140
+ less.set(listItemKey(item), (less.get(listItemKey(item)) ?? 0) + stated);
1141
+ }
858
1142
  next = held.flatMap((item) => {
859
- if (out.has(listItemKey(item)))
1143
+ const key = listItemKey(item);
1144
+ if (out.has(key))
860
1145
  return [];
861
- if (!isSlotLoreRef(item) || !less.has(item.entryId))
1146
+ if (!isCounted(item) || !less.has(key))
862
1147
  return [item];
863
- const left = slotLoreRefCount(item) - less.get(item.entryId);
864
- return left > 0 ? [withCount(item, left)] : [];
1148
+ const left = countOf(item) - less.get(key);
1149
+ return left > 0 ? [recount(item, left)] : [];
865
1150
  });
866
1151
  break;
867
1152
  }
package/dist/bands.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Bands as template variables (typed templates P2, 2026-09-27).
2
+ * Bands as template variables.
3
3
  *
4
4
  * A **band** is the ranker's word for one source's slice of the context window
5
5
  * (`bandIntent`, candidates.ts). A source that puts its own band in the window
@@ -27,6 +27,7 @@
27
27
  * when the slot says `rendersBands` — every band declared upstream of the
28
28
  * named in-port, followed through any node that takes candidates in
29
29
  * (concatenation, fusion, ranking). `rendersAt` is that answer.
30
+ * @ruling typed templates P2 (2026-09-27)
30
31
  */
31
32
  import { type Descriptor, type SlotDecl } from './descriptors.js';
32
33
  import type { DocEdge, DocNode } from './document.js';
@@ -53,20 +54,54 @@ export declare const ASSEMBLE_OWN_TEMPLATE_NAMES: readonly string[];
53
54
  * - the key is an identifier (a band is a template name);
54
55
  * - the variable is registered (`defineVariable` / `definePluginVariable`) and
55
56
  * its scope declares the key, because a layout renders `{ [key]: value }`;
56
- * - the key does not shadow a name core renders — Assemble's own, or a
57
- * core variable's that is not this band's own variable;
58
- * - no other registered definition declares the key with a different variable.
57
+ * - the key is not one of Assemble's own names.
58
+ *
59
+ * **Not refused here: a key some other definition, or some core variable,
60
+ * already uses** (owner ruling 2026-10-13, ★1). A key is a local name and
61
+ * means one variable *within one template's scope* — `bandsReaching` and
62
+ * `rendersAt` refuse two meanings meeting in one document, and law T1 reports
63
+ * it. Two pipelines that never meet may each mean their own `characterLore`.
59
64
  *
60
65
  * Each refusal names the fix.
61
66
  * @internal
62
67
  */
63
- export declare function checkBandDeclarations(d: Descriptor, others: Iterable<Descriptor>): void;
68
+ export declare function checkBandDeclarations(d: Descriptor): void;
69
+ /**
70
+ * What is wrong with a node rendering `key` as `id`, as the end of a sentence
71
+ * that begins with what renders it — or `undefined` when nothing is.
72
+ *
73
+ * The facts a band declaration states, asked of every rendered key: a layout
74
+ * is written against its variable's scope and renders `{ [key]: value }`, so
75
+ * a key the scope does not name reaches no layout, and a variable nobody
76
+ * registered has no layout, no type and no picker.
77
+ * @internal
78
+ */
79
+ export declare function rendersProblem(key: string, id: unknown): string | undefined;
80
+ /**
81
+ * Refuse a definition's static `renders` (owner ruling 2026-10-13) — at
82
+ * `describe…Definition`, like its bands, and for the same reasons
83
+ * (`rendersProblem`). Until then nothing read a `renders` entry until a run
84
+ * did, and a key whose variable did not declare it rendered nothing.
85
+ * @internal
86
+ */
87
+ export declare function checkRendersDeclarations(d: Descriptor): void;
88
+ /**
89
+ * What one placement's `variables` slot renders, before any band: the slot's
90
+ * static `renders`, with each key the **spec's own `renders`** names for this
91
+ * node (`NodeOpts.renders`, owner ruling 2026-10-13) re-pointed at the
92
+ * spec's variable. Only keys the slot already renders — the spec says what a
93
+ * key *means* here, it does not add keys; `validate()` reports one it names
94
+ * that no slot renders (law T1).
95
+ * @experimental
96
+ */
97
+ export declare function effectiveRenders(slot: Pick<SlotDecl, 'renders'>, node?: Pick<DocNode, 'renders'>): Record<string, VariableId>;
64
98
  /**
65
99
  * What `bandsReaching` needs from a node's definition: its in-ports and the
66
100
  * bands it declares. A `Descriptor` satisfies it, and so does a registry row
67
101
  * (whose policy carries the band ids, `DefinitionPolicy.bands`) — which is how
68
- * a host reading rows answers without loading a plugin (F6).
102
+ * a host reading rows answers without loading a plugin.
69
103
  * @experimental
104
+ * @ruling F6
70
105
  */
71
106
  export interface BandSource {
72
107
  ports?: {