@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
@@ -0,0 +1,425 @@
1
+ /**
2
+ * 🚧 **Scene settings** (PROPOSAL-live-scenes §4, §5; lane D, 2026-10-13):
3
+ * how a session's **scene boundaries** are placed while it is played, and
4
+ * when a scene's summary runs. The genre states a default
5
+ * (`SessionShape.scenes`); a session may override it (the app keeps the
6
+ * override on the session row); `resolveSceneSettings` is the one cascade
7
+ * both read through.
8
+ *
9
+ * Three parts:
10
+ *
11
+ * · `mode` — what happens at a **boundary trigger**: `manual` (nothing; a
12
+ * person places every boundary), `suggested` (a quiet *New scene?* chip at
13
+ * the line — the app's **scene cue** — that one tap accepts or dismisses),
14
+ * `automatic` (the boundary is placed). Default `suggested`.
15
+ * · `triggers` — which deterministic signals count, none of them a model:
16
+ * the story clock crossed a day (`dayCrossed`), a time action moved the
17
+ * clock (`timeAction`), the place the genre's state names changed
18
+ * (`placeChanged`) — those three on by default — and, off by default, a
19
+ * narrator or system line (`narration`), a scene grown past `length`
20
+ * lines or tokens, and a real-world `pause` of some hours between lines.
21
+ * · `summary` — when a scene's summary runs: `onClose` (in the background
22
+ * the moment it closes), `onRequest` (the person presses *Summarize*; the
23
+ * default — the person decides when to pay), `never`.
24
+ *
25
+ * Nothing here moves the story clock and nothing asks a model: a trigger is
26
+ * read off stamps and rows a person or a fixed tick already wrote.
27
+ *
28
+ * ⚠ Not the **story clock** (the session's present), not a **scene** (the run
29
+ * between two boundaries) and not `SessionShape.writes.scenes` (whether a
30
+ * genre's sessions may write scenes at all — a genre that may not is Manual
31
+ * with nothing to place).
32
+ *
33
+ * Two declarations ride beside the settings, both the genre's alone (live
34
+ * scenes §15 G1–G2, 2026-10-13):
35
+ *
36
+ * · the **place** (`SessionShape.scenes.place`, `ScenePlaceDecl`) — which
37
+ * state key holds where the story is, so *place changed* can fire and a
38
+ * scene's name can carry it;
39
+ * · the genre's own **declared boundary triggers** (`BoundaryTriggerDecl`,
40
+ * ★9) — carried by its summarize-scene spec (`summarizeScene(…, {
41
+ * boundaries })`, on the document as `contributes.boundaryTriggers`), each
42
+ * a switch a session may turn off under `triggers[key]`.
43
+ *
44
+ * Imports nothing at run time (one erased type import), so `descriptors.ts`
45
+ * and `widgets.ts` name these types without a cycle.
46
+ * @ruling PROPOSAL-live-scenes ★1 (Suggested; day crossed, time action, place changed on), ★9 (2026-10-13)
47
+ */
48
+ /** What happens at a boundary trigger. @experimental */
49
+ export const SCENE_MODES = ['manual', 'suggested', 'automatic'];
50
+ /** When a scene's summary runs. @experimental */
51
+ export const SCENE_SUMMARY_MODES = ['onClose', 'onRequest', 'never'];
52
+ /**
53
+ * The **boundary triggers**, in the order a settings form lists them. Each is
54
+ * deterministic: read off message stamps, rows and the clock, never a model.
55
+ * @experimental
56
+ */
57
+ export const SCENE_BOUNDARY_TRIGGERS = [
58
+ 'dayCrossed',
59
+ 'timeAction',
60
+ 'placeChanged',
61
+ 'narration',
62
+ 'length',
63
+ 'pause',
64
+ ];
65
+ /**
66
+ * What a session runs on when neither its genre nor the session says
67
+ * anything: **Suggested**, with *day crossed*, *time action* and *place
68
+ * changed* on and the rest off; summaries **on request** (★1).
69
+ * @experimental
70
+ */
71
+ export const DEFAULT_SCENE_SETTINGS = Object.freeze({
72
+ mode: 'suggested',
73
+ triggers: Object.freeze({
74
+ dayCrossed: true,
75
+ timeAction: true,
76
+ placeChanged: true,
77
+ narration: false,
78
+ length: null,
79
+ pause: null,
80
+ }),
81
+ summary: 'onRequest',
82
+ });
83
+ const isObject = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
84
+ const isPositiveInt = (v) => typeof v === 'number' && Number.isInteger(v) && v > 0;
85
+ const isPositive = (v) => typeof v === 'number' && Number.isFinite(v) && v > 0;
86
+ /**
87
+ * Every fault in one scene-settings declaration, as sentences — empty when it
88
+ * is sound. Shared by `genre()` (a genre's `shape.scenes`) and `register()`
89
+ * (an inlet's `sessionShape.scenes`), and by a host checking a session's
90
+ * override before it stores it.
91
+ *
92
+ * A trigger key this release does not know is refused rather than ignored,
93
+ * unless it is one of `options.declaredTriggers`: a genre's own boundary
94
+ * trigger (a new floor, say) is declared on its summarize-scene spec
95
+ * (`BoundaryTriggerDecl`, ★9) and only a session switches it, and a key that
96
+ * silently did nothing would read as if it did.
97
+ * @experimental
98
+ */
99
+ export function sceneSettingsFindings(raw, at = 'scenes', options = {}) {
100
+ if (raw === undefined)
101
+ return [];
102
+ const layer = options.layer ?? 'genre';
103
+ const declared = options.declaredTriggers;
104
+ if (!isObject(raw))
105
+ return [
106
+ `${at}: scene settings are { mode?, triggers?, summary?${layer === 'genre' ? ', place?' : ''} } — ` +
107
+ `mode one of ${SCENE_MODES.join(', ')}, summary one of ${SCENE_SUMMARY_MODES.join(', ')}`,
108
+ ];
109
+ const out = [];
110
+ for (const key of Object.keys(raw))
111
+ if (key === 'place' && layer === 'session')
112
+ out.push(`${at}.place: the place is the genre's to name (its shape.scenes.place) — a session cannot set it`);
113
+ else if (key !== 'mode' && key !== 'triggers' && key !== 'summary' && key !== 'place')
114
+ out.push(`${at}.${key}: not a scene setting — the keys are mode, triggers, summary${layer === 'genre' ? ' and place' : ''}`);
115
+ if (raw.mode !== undefined && !SCENE_MODES.includes(raw.mode))
116
+ out.push(`${at}.mode: one of ${SCENE_MODES.join(', ')} — not ${JSON.stringify(raw.mode)}`);
117
+ if (raw.summary !== undefined && !SCENE_SUMMARY_MODES.includes(raw.summary))
118
+ out.push(`${at}.summary: one of ${SCENE_SUMMARY_MODES.join(', ')} — not ${JSON.stringify(raw.summary)}`);
119
+ if (layer === 'genre' && raw.place !== undefined)
120
+ out.push(...scenePlaceFindings(raw.place, `${at}.place`));
121
+ const t = raw.triggers;
122
+ if (t !== undefined) {
123
+ if (!isObject(t))
124
+ out.push(`${at}.triggers: an object of boundary triggers — ${SCENE_BOUNDARY_TRIGGERS.join(', ')}`);
125
+ else
126
+ for (const [key, value] of Object.entries(t)) {
127
+ const where = `${at}.triggers.${key}`;
128
+ if (!SCENE_BOUNDARY_TRIGGERS.includes(key)) {
129
+ const switchable = declared === 'any' || (Array.isArray(declared) && declared.includes(key));
130
+ if (switchable && (value === undefined || typeof value === 'boolean'))
131
+ continue;
132
+ if (switchable) {
133
+ out.push(`${where}: a declared trigger is on or off — true or false, not ${JSON.stringify(value)}`);
134
+ continue;
135
+ }
136
+ out.push(`${where}: not a boundary trigger — one of ${SCENE_BOUNDARY_TRIGGERS.join(', ')}` +
137
+ (Array.isArray(declared) && declared.length ? `, or this genre's own: ${declared.join(', ')}` : '') +
138
+ `. A genre's own trigger is declared on its summarize-scene spec (summarizeScene(…, { boundaries })), ` +
139
+ `and only a session's override switches it`);
140
+ continue;
141
+ }
142
+ if (value === undefined)
143
+ continue;
144
+ if (key === 'length') {
145
+ if (value === false)
146
+ continue;
147
+ if (!isObject(value)) {
148
+ out.push(`${where}: false, or { lines?, tokens? } — at least one, each a whole number above 0`);
149
+ continue;
150
+ }
151
+ const { lines, tokens, ...rest } = value;
152
+ if (Object.keys(rest).length)
153
+ out.push(`${where}: only lines and tokens — not ${Object.keys(rest).join(', ')}`);
154
+ if (lines === undefined && tokens === undefined)
155
+ out.push(`${where}: say lines, tokens or both — or false for off`);
156
+ if (lines !== undefined && !isPositiveInt(lines))
157
+ out.push(`${where}.lines: a whole number above 0`);
158
+ if (tokens !== undefined && !isPositiveInt(tokens))
159
+ out.push(`${where}.tokens: a whole number above 0`);
160
+ continue;
161
+ }
162
+ if (key === 'pause') {
163
+ if (value === false)
164
+ continue;
165
+ if (!isObject(value) || !isPositive(value.hours) || Object.keys(value).length !== 1)
166
+ out.push(`${where}: false, or { hours } — a number of real hours above 0`);
167
+ continue;
168
+ }
169
+ if (typeof value !== 'boolean')
170
+ out.push(`${where}: true or false — not ${JSON.stringify(value)}`);
171
+ }
172
+ }
173
+ return out;
174
+ }
175
+ /** A template's word for a state value: `location`, `core_location`. */
176
+ const STATE_KEY = /^[A-Za-z_][A-Za-z0-9_]*$/;
177
+ /** Every fault in a `place` declaration, as sentences. @internal */
178
+ function scenePlaceFindings(raw, at) {
179
+ if (!isObject(raw) || typeof raw.stateKey !== 'string')
180
+ return [`${at}: { stateKey } — the state key that holds where the story is, e.g. { stateKey: 'location' }`];
181
+ const out = [];
182
+ for (const key of Object.keys(raw))
183
+ if (key !== 'stateKey')
184
+ out.push(`${at}.${key}: only stateKey — not ${key}`);
185
+ if (!STATE_KEY.test(raw.stateKey))
186
+ out.push(`${at}.stateKey: a state key as a template reads it (letters, digits, _) — not ${JSON.stringify(raw.stateKey)}`);
187
+ return out;
188
+ }
189
+ /**
190
+ * 🚧 The place a genre's shape names (`shape.scenes.place`), or null — what a
191
+ * host reads to know which state key is where the story is (live scenes §15
192
+ * G2). Takes `unknown` on purpose, as `resolveSceneSettings` does: a shape
193
+ * from a stored row whose place does not read names none.
194
+ * @experimental
195
+ */
196
+ export function declaredScenePlace(shape) {
197
+ const scenes = isObject(shape) ? shape.scenes : undefined;
198
+ const place = isObject(scenes) ? scenes.place : undefined;
199
+ if (place === undefined || scenePlaceFindings(place, 'place').length)
200
+ return null;
201
+ return { stateKey: place.stateKey };
202
+ }
203
+ /**
204
+ * A shape's `scenes` refused with its sentences — at the declaration, where
205
+ * the author is, as `assertSessionWrites` refuses `writes`.
206
+ * @experimental
207
+ */
208
+ export function assertSceneSettings(shape, who) {
209
+ const findings = sceneSettingsFindings(shape?.scenes, `${who}.scenes`);
210
+ if (findings.length)
211
+ throw new Error(findings.join('\n'));
212
+ }
213
+ /** One layer laid over the resolved settings below it; a part it cannot read is skipped. */
214
+ function overlay(base, raw) {
215
+ if (!isObject(raw))
216
+ return base;
217
+ const out = { ...base, triggers: { ...base.triggers } };
218
+ if (SCENE_MODES.includes(raw.mode))
219
+ out.mode = raw.mode;
220
+ if (SCENE_SUMMARY_MODES.includes(raw.summary))
221
+ out.summary = raw.summary;
222
+ const t = raw.triggers;
223
+ if (isObject(t)) {
224
+ for (const key of ['dayCrossed', 'timeAction', 'placeChanged', 'narration'])
225
+ if (typeof t[key] === 'boolean')
226
+ out.triggers[key] = t[key];
227
+ if (t.length === false)
228
+ out.triggers.length = null;
229
+ else if (isObject(t.length)) {
230
+ const lines = isPositiveInt(t.length.lines) ? t.length.lines : null;
231
+ const tokens = isPositiveInt(t.length.tokens) ? t.length.tokens : null;
232
+ out.triggers.length = lines !== null || tokens !== null ? { lines, tokens } : null;
233
+ }
234
+ if (t.pause === false)
235
+ out.triggers.pause = null;
236
+ else if (isObject(t.pause) && isPositive(t.pause.hours))
237
+ out.triggers.pause = { hours: t.pause.hours };
238
+ }
239
+ return out;
240
+ }
241
+ /**
242
+ * The cascade: the session's own (`session`), else the genre's
243
+ * (`shape.scenes`), else `DEFAULT_SCENE_SETTINGS` — part by part, so a
244
+ * session that says only `summary` keeps its genre's mode and triggers.
245
+ *
246
+ * Pure, and takes `unknown` on purpose: a host reads a shape that arrived from
247
+ * a stored registry row and an override from a stored session row, not typed
248
+ * declarations. Whatever cannot be read falls through to the layer below —
249
+ * the "a policy that cannot be read refuses nothing" posture `resolveWrites`
250
+ * keeps.
251
+ * @experimental
252
+ */
253
+ export function resolveSceneSettings(shape, session) {
254
+ const declared = isObject(shape) ? shape.scenes : undefined;
255
+ return overlay(overlay(DEFAULT_SCENE_SETTINGS, declared), session);
256
+ }
257
+ /**
258
+ * The resolved settings as a declaration again — what a host stores as a
259
+ * session's override when a person saves the settings form. `declared` is
260
+ * the switch of each **declared boundary trigger** (`declaredTriggerStates`),
261
+ * written beside the core ones under `triggers`.
262
+ * @experimental
263
+ */
264
+ export function sceneSettingsDecl(settings, declared) {
265
+ const t = settings.triggers;
266
+ return {
267
+ mode: settings.mode,
268
+ summary: settings.summary,
269
+ triggers: {
270
+ dayCrossed: t.dayCrossed,
271
+ timeAction: t.timeAction,
272
+ placeChanged: t.placeChanged,
273
+ narration: t.narration,
274
+ length: t.length
275
+ ? {
276
+ ...(t.length.lines !== null ? { lines: t.length.lines } : {}),
277
+ ...(t.length.tokens !== null ? { tokens: t.length.tokens } : {}),
278
+ }
279
+ : false,
280
+ pause: t.pause ? { hours: t.pause.hours } : false,
281
+ ...(declared ?? {}),
282
+ },
283
+ };
284
+ }
285
+ // ── 🚧 Declared boundary triggers (★9, live scenes §15 G1) ──────────────────
286
+ /**
287
+ * Who voiced a line, as a declared trigger's `speaker` reads it:
288
+ *
289
+ * · `person` — a person's own line (role `user`, under a persona or not);
290
+ * · `character` — a cast member's line (a character's, not a narration);
291
+ * · `narrator` — the story's own voice: a narrator response, a system line,
292
+ * an envoy's line or the pipeline's own voice (the Lair's Castellan).
293
+ * @experimental
294
+ */
295
+ export const BOUNDARY_TRIGGER_SPEAKERS = ['person', 'character', 'narrator'];
296
+ /** The predicates a declared boundary trigger may state, in the order a sentence names them. @experimental */
297
+ export const BOUNDARY_TRIGGER_PREDICATES = ['channel', 'narration', 'speaker', 'actionKey', 'stateKey'];
298
+ /** A declared trigger's key: camelCase, like core's. */
299
+ const TRIGGER_KEY = /^[a-z][A-Za-z0-9]{0,39}$/;
300
+ /** An action key, a plugin's namespaced: `trigger-trap`, `acme.roll`. */
301
+ const ACTION_KEY = /^[a-z0-9][a-z0-9._-]{0,79}$/;
302
+ /** Core's trigger keys and the cue trigger no setting switches (`endedHere`). */
303
+ const RESERVED_TRIGGER_KEYS = new Set([...SCENE_BOUNDARY_TRIGGERS, 'endedHere']);
304
+ const isDisplayText = (v) => (typeof v === 'string' && v.trim() !== '') ||
305
+ (isObject(v) &&
306
+ typeof v.en === 'string' &&
307
+ v.en.trim() !== '' &&
308
+ Object.values(v).every((x) => typeof x === 'string'));
309
+ /**
310
+ * Every fault in a list of declared boundary triggers, as sentences — empty
311
+ * when it is sound. `channels` are the slugs the genre declares; given, a
312
+ * `channel` predicate must name one of them (a trigger on a channel the
313
+ * genre does not have would never fire). Used by the builder, where the
314
+ * author is, and by a host reading a stored document.
315
+ * @experimental
316
+ */
317
+ export function boundaryTriggerFindings(raw, at = 'boundaries', options = {}) {
318
+ if (raw === undefined)
319
+ return [];
320
+ if (!Array.isArray(raw))
321
+ return [`${at}: a list of boundary triggers — [{ key, label, when: { ${BOUNDARY_TRIGGER_PREDICATES.join('?, ')}? } }]`];
322
+ const out = [];
323
+ const seen = new Set();
324
+ raw.forEach((entry, i) => {
325
+ const here = `${at}[${isObject(entry) && typeof entry.key === 'string' ? entry.key : i}]`;
326
+ if (!isObject(entry)) {
327
+ out.push(`${here}: { key, label, when }`);
328
+ return;
329
+ }
330
+ for (const k of Object.keys(entry))
331
+ if (k !== 'key' && k !== 'label' && k !== 'when')
332
+ out.push(`${here}.${k}: not part of a boundary trigger — key, label and when`);
333
+ const key = entry.key;
334
+ if (typeof key !== 'string' || !TRIGGER_KEY.test(key))
335
+ out.push(`${here}.key: camelCase letters and digits, starting lower-case (newFloor) — not ${JSON.stringify(key)}`);
336
+ else if (RESERVED_TRIGGER_KEYS.has(key))
337
+ out.push(`${here}.key: '${key}' is core's own trigger — name the genre's something else`);
338
+ else if (seen.has(key))
339
+ out.push(`${here}.key: '${key}' is declared twice`);
340
+ else
341
+ seen.add(key);
342
+ if (!isDisplayText(entry.label))
343
+ out.push(`${here}.label: display text — what the chip says after "New scene? —", e.g. 'the party reached a new floor'`);
344
+ const when = entry.when;
345
+ if (!isObject(when)) {
346
+ out.push(`${here}.when: { ${BOUNDARY_TRIGGER_PREDICATES.join('?, ')}? } — at least one`);
347
+ return;
348
+ }
349
+ const stated = Object.keys(when).filter((k) => when[k] !== undefined);
350
+ if (!stated.length)
351
+ out.push(`${here}.when: state at least one of ${BOUNDARY_TRIGGER_PREDICATES.join(', ')}`);
352
+ for (const k of stated) {
353
+ const v = when[k];
354
+ const where = `${here}.when.${k}`;
355
+ if (!BOUNDARY_TRIGGER_PREDICATES.includes(k)) {
356
+ out.push(`${where}: not a predicate — one of ${BOUNDARY_TRIGGER_PREDICATES.join(', ')}, each read off the line, never a model`);
357
+ continue;
358
+ }
359
+ if (k === 'channel') {
360
+ if (typeof v !== 'string' || !v.trim()) {
361
+ out.push(`${where}: a channel slug — 'main', 'sanctum', or a lane such as 'sanctum:2'`);
362
+ continue;
363
+ }
364
+ const slug = v.split(':')[0];
365
+ if (options.channels && !options.channels.includes(slug))
366
+ out.push(`${where}: '${v}' is not a channel the genre declares (${options.channels.join(', ')}) — the trigger would never fire`);
367
+ }
368
+ else if (k === 'narration') {
369
+ if (typeof v !== 'boolean')
370
+ out.push(`${where}: true or false — not ${JSON.stringify(v)}`);
371
+ }
372
+ else if (k === 'speaker') {
373
+ if (!BOUNDARY_TRIGGER_SPEAKERS.includes(v))
374
+ out.push(`${where}: one of ${BOUNDARY_TRIGGER_SPEAKERS.join(', ')} — not ${JSON.stringify(v)}`);
375
+ }
376
+ else if (k === 'actionKey') {
377
+ if (typeof v !== 'string' || !ACTION_KEY.test(v))
378
+ out.push(`${where}: an action's key, as its spec declares it ('trigger-trap', 'acme.roll') — not ${JSON.stringify(v)}`);
379
+ }
380
+ else if (k === 'stateKey') {
381
+ if (typeof v !== 'string' || !STATE_KEY.test(v))
382
+ out.push(`${where}: a state key as a template reads it ('floor') — not ${JSON.stringify(v)}`);
383
+ }
384
+ }
385
+ });
386
+ return out;
387
+ }
388
+ /**
389
+ * The declared boundary triggers a stored spec document carries
390
+ * (`contributes.boundaryTriggers`), each checked on its own: one that does
391
+ * not read is left out rather than refusing the rest, and a key met twice
392
+ * keeps its first. What a host's boundary watcher and settings form read.
393
+ * @experimental
394
+ */
395
+ export function boundaryTriggersOf(contributes) {
396
+ const list = isObject(contributes) ? contributes.boundaryTriggers : undefined;
397
+ if (!Array.isArray(list))
398
+ return [];
399
+ const out = [];
400
+ const seen = new Set();
401
+ for (const entry of list) {
402
+ if (boundaryTriggerFindings([entry]).length)
403
+ continue;
404
+ const t = entry;
405
+ if (seen.has(t.key))
406
+ continue;
407
+ seen.add(t.key);
408
+ out.push({ key: t.key, label: t.label, when: { ...t.when } });
409
+ }
410
+ return out;
411
+ }
412
+ /**
413
+ * Each declared trigger's switch for one session: on, unless the session's
414
+ * override (`triggers[key]`) says `false`. Like `resolveSceneSettings`, it
415
+ * takes the override as `unknown` and skips what it cannot read.
416
+ * @experimental
417
+ */
418
+ export function declaredTriggerStates(declared, session) {
419
+ const t = isObject(session) && isObject(session.triggers) ? session.triggers : {};
420
+ const out = {};
421
+ for (const { key } of declared)
422
+ out[key] = typeof t[key] === 'boolean' ? t[key] : true;
423
+ return out;
424
+ }
425
+ //# sourceMappingURL=sceneSettings.js.map
package/dist/scope.d.ts CHANGED
@@ -6,15 +6,16 @@
6
6
  * mistyped port, a reference to a node that does not exist *yet*. All three were
7
7
  * publish-time findings. With a scope object accumulated as the chain is built, all
8
8
  * three become **compile errors**, which is the same move the kind-named methods made
9
- * for the five laws they enforce (04 §4a).
9
+ * for the five laws they enforce.
10
10
  *
11
11
  * The one that matters most is the third. `$` contains only the nodes declared *above*
12
- * the call, so a reference to a later node does not type-check — **"no back-edges" (F9)
12
+ * the call, so a reference to a later node does not type-check — **"no back-edges"
13
13
  * stops being a rule the validator checks and becomes a thing you cannot write.**
14
14
  *
15
15
  * Nothing about the compiled document changes. A scope access produces exactly the
16
16
  * `DataRef` that `$ref` produces, so the rows, the edges and the canonical hash are
17
- * byte-identical (F3, F6). This is authoring sugar over an unchanged value.
17
+ * byte-identical. This is authoring sugar over an unchanged value.
18
+ * @ruling 04 §4a, F9, F3, F6
18
19
  */
19
20
  import { type DataRef } from './refs.js';
20
21
  import type { PortDecl } from './descriptors.js';
@@ -28,12 +29,13 @@ export type NodeAccessor<Out extends PortDecl> = DataRef & {
28
29
  };
29
30
  /**
30
31
  * Node keys accumulate **flat and dotted** — `'gather.semantic.embed'` — because that is
31
- * exactly what the row's `node_key` is (F21). The scope then expands them back into a
32
+ * exactly what the row's `node_key` is. The scope then expands them back into a
32
33
  * nested shape, so `$.gather.semantic.embed.vector` reads like the key it compiles to.
33
34
  *
34
35
  * Blocks are not nodes, so a block name alone is not a ref: `$.gather` is a path, and
35
36
  * only the leaf carries the accessor. That falls out of the split below rather than
36
37
  * needing a rule.
38
+ * @ruling F21
37
39
  */
38
40
  type Head<K extends string> = K extends `${infer H}.${string}` ? H : K;
39
41
  type ChildrenOf<N, H extends string> = {
package/dist/scope.js CHANGED
@@ -6,15 +6,16 @@
6
6
  * mistyped port, a reference to a node that does not exist *yet*. All three were
7
7
  * publish-time findings. With a scope object accumulated as the chain is built, all
8
8
  * three become **compile errors**, which is the same move the kind-named methods made
9
- * for the five laws they enforce (04 §4a).
9
+ * for the five laws they enforce.
10
10
  *
11
11
  * The one that matters most is the third. `$` contains only the nodes declared *above*
12
- * the call, so a reference to a later node does not type-check — **"no back-edges" (F9)
12
+ * the call, so a reference to a later node does not type-check — **"no back-edges"
13
13
  * stops being a rule the validator checks and becomes a thing you cannot write.**
14
14
  *
15
15
  * Nothing about the compiled document changes. A scope access produces exactly the
16
16
  * `DataRef` that `$ref` produces, so the rows, the edges and the canonical hash are
17
- * byte-identical (F3, F6). This is authoring sugar over an unchanged value.
17
+ * byte-identical. This is authoring sugar over an unchanged value.
18
+ * @ruling 04 §4a, F9, F3, F6
18
19
  */
19
20
  import { $ref } from './refs.js';
20
21
  const REF_KEYS = new Set(['__ref', 'node', 'port']);