@serene-pub/sdk 0.6.0-pr-1

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 (187) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +17 -0
  3. package/README.md +368 -0
  4. package/dist/actions.d.ts +572 -0
  5. package/dist/actions.js +829 -0
  6. package/dist/annexFields.d.ts +234 -0
  7. package/dist/annexFields.js +413 -0
  8. package/dist/announce.d.ts +464 -0
  9. package/dist/announce.js +426 -0
  10. package/dist/attributes.d.ts +670 -0
  11. package/dist/attributes.js +904 -0
  12. package/dist/bands.d.ts +125 -0
  13. package/dist/bands.js +256 -0
  14. package/dist/builder.d.ts +683 -0
  15. package/dist/builder.js +677 -0
  16. package/dist/candidates.d.ts +109 -0
  17. package/dist/candidates.js +118 -0
  18. package/dist/capabilities.d.ts +744 -0
  19. package/dist/capabilities.js +679 -0
  20. package/dist/channels.d.ts +106 -0
  21. package/dist/channels.js +129 -0
  22. package/dist/clauses.d.ts +40 -0
  23. package/dist/clauses.js +43 -0
  24. package/dist/component.d.ts +33 -0
  25. package/dist/component.js +27 -0
  26. package/dist/componentBuild.d.ts +48 -0
  27. package/dist/componentBuild.js +84 -0
  28. package/dist/componentClient.d.ts +100 -0
  29. package/dist/componentClient.js +13 -0
  30. package/dist/componentImports.d.ts +51 -0
  31. package/dist/componentImports.js +106 -0
  32. package/dist/componentModule.d.ts +8 -0
  33. package/dist/componentModule.js +270 -0
  34. package/dist/componentWire.d.ts +130 -0
  35. package/dist/componentWire.js +280 -0
  36. package/dist/config.d.ts +295 -0
  37. package/dist/config.js +231 -0
  38. package/dist/connections.d.ts +89 -0
  39. package/dist/connections.js +131 -0
  40. package/dist/declarations.d.ts +290 -0
  41. package/dist/declarations.js +794 -0
  42. package/dist/descriptors.d.ts +1774 -0
  43. package/dist/descriptors.js +1329 -0
  44. package/dist/dev.d.ts +136 -0
  45. package/dist/dev.js +161 -0
  46. package/dist/document.d.ts +202 -0
  47. package/dist/document.js +312 -0
  48. package/dist/engines.d.ts +117 -0
  49. package/dist/engines.js +203 -0
  50. package/dist/eventMapLaws.d.ts +63 -0
  51. package/dist/eventMapLaws.js +128 -0
  52. package/dist/events.d.ts +554 -0
  53. package/dist/events.js +633 -0
  54. package/dist/executor.d.ts +771 -0
  55. package/dist/executor.js +1829 -0
  56. package/dist/extension.d.ts +448 -0
  57. package/dist/extension.js +315 -0
  58. package/dist/facets.d.ts +53 -0
  59. package/dist/facets.js +60 -0
  60. package/dist/foldedSections.d.ts +74 -0
  61. package/dist/foldedSections.js +161 -0
  62. package/dist/genres.d.ts +507 -0
  63. package/dist/genres.js +633 -0
  64. package/dist/guardedConnection.d.ts +138 -0
  65. package/dist/guardedConnection.js +341 -0
  66. package/dist/handlebarsReach.d.ts +122 -0
  67. package/dist/handlebarsReach.js +222 -0
  68. package/dist/hash.d.ts +146 -0
  69. package/dist/hash.js +166 -0
  70. package/dist/hookGrants.d.ts +47 -0
  71. package/dist/hookGrants.js +68 -0
  72. package/dist/hooks.d.ts +290 -0
  73. package/dist/hooks.js +113 -0
  74. package/dist/hostElements.d.ts +447 -0
  75. package/dist/hostElements.js +702 -0
  76. package/dist/i18n.d.ts +94 -0
  77. package/dist/i18n.js +123 -0
  78. package/dist/identity.d.ts +93 -0
  79. package/dist/identity.js +135 -0
  80. package/dist/index.d.ts +85 -0
  81. package/dist/index.js +176 -0
  82. package/dist/layout.d.ts +194 -0
  83. package/dist/layout.js +40 -0
  84. package/dist/media.d.ts +202 -0
  85. package/dist/media.js +70 -0
  86. package/dist/messageBlocks.d.ts +487 -0
  87. package/dist/messageBlocks.js +683 -0
  88. package/dist/migration.d.ts +128 -0
  89. package/dist/migration.js +261 -0
  90. package/dist/names.d.ts +78 -0
  91. package/dist/names.js +136 -0
  92. package/dist/nodeInput.d.ts +399 -0
  93. package/dist/nodeInput.js +178 -0
  94. package/dist/participants.d.ts +291 -0
  95. package/dist/participants.js +252 -0
  96. package/dist/personGate.d.ts +62 -0
  97. package/dist/personGate.js +77 -0
  98. package/dist/pick.d.ts +84 -0
  99. package/dist/pick.js +103 -0
  100. package/dist/pluginHarness.d.ts +235 -0
  101. package/dist/pluginHarness.js +558 -0
  102. package/dist/pluginPermissions.d.ts +25 -0
  103. package/dist/pluginPermissions.js +97 -0
  104. package/dist/pluginRuleRef.d.ts +13 -0
  105. package/dist/pluginRuleRef.js +10 -0
  106. package/dist/predicates.d.ts +182 -0
  107. package/dist/predicates.js +249 -0
  108. package/dist/preview.d.ts +120 -0
  109. package/dist/preview.js +82 -0
  110. package/dist/promptBlocks.d.ts +130 -0
  111. package/dist/promptBlocks.js +197 -0
  112. package/dist/rankingDecisions.d.ts +60 -0
  113. package/dist/rankingDecisions.js +48 -0
  114. package/dist/receipt.d.ts +313 -0
  115. package/dist/receipt.js +60 -0
  116. package/dist/receiverRules.d.ts +24 -0
  117. package/dist/receiverRules.js +94 -0
  118. package/dist/refs.d.ts +117 -0
  119. package/dist/refs.js +137 -0
  120. package/dist/registry.d.ts +230 -0
  121. package/dist/registry.js +273 -0
  122. package/dist/review.d.ts +108 -0
  123. package/dist/review.js +97 -0
  124. package/dist/sampling.d.ts +152 -0
  125. package/dist/sampling.js +712 -0
  126. package/dist/scope.d.ts +65 -0
  127. package/dist/scope.js +128 -0
  128. package/dist/scripts.d.ts +243 -0
  129. package/dist/scripts.js +326 -0
  130. package/dist/sessionLayout.d.ts +339 -0
  131. package/dist/sessionLayout.js +503 -0
  132. package/dist/sessionSettings.d.ts +70 -0
  133. package/dist/sessionSettings.js +2 -0
  134. package/dist/settings.d.ts +501 -0
  135. package/dist/settings.js +604 -0
  136. package/dist/settingsSlot.d.ts +108 -0
  137. package/dist/settingsSlot.js +166 -0
  138. package/dist/shapes.d.ts +373 -0
  139. package/dist/shapes.js +408 -0
  140. package/dist/sheets.d.ts +165 -0
  141. package/dist/sheets.js +251 -0
  142. package/dist/statShapes.d.ts +96 -0
  143. package/dist/statShapes.js +112 -0
  144. package/dist/status.d.ts +103 -0
  145. package/dist/status.js +125 -0
  146. package/dist/storage.d.ts +145 -0
  147. package/dist/storage.js +33 -0
  148. package/dist/storyTime.d.ts +308 -0
  149. package/dist/storyTime.js +560 -0
  150. package/dist/surfaces.d.ts +501 -0
  151. package/dist/surfaces.js +292 -0
  152. package/dist/template.d.ts +312 -0
  153. package/dist/template.js +554 -0
  154. package/dist/templateCheck.d.ts +60 -0
  155. package/dist/templateCheck.js +516 -0
  156. package/dist/templateFit.d.ts +157 -0
  157. package/dist/templateFit.js +349 -0
  158. package/dist/templateIds.d.ts +138 -0
  159. package/dist/templateIds.js +144 -0
  160. package/dist/templateScopeAt.d.ts +131 -0
  161. package/dist/templateScopeAt.js +354 -0
  162. package/dist/testing.d.ts +177 -0
  163. package/dist/testing.js +383 -0
  164. package/dist/tokenizers.d.ts +113 -0
  165. package/dist/tokenizers.js +184 -0
  166. package/dist/turnLock.d.ts +96 -0
  167. package/dist/turnLock.js +79 -0
  168. package/dist/turnOrder.d.ts +143 -0
  169. package/dist/turnOrder.js +128 -0
  170. package/dist/validate.d.ts +74 -0
  171. package/dist/validate.js +1399 -0
  172. package/dist/values.d.ts +212 -0
  173. package/dist/values.js +390 -0
  174. package/dist/variables.d.ts +493 -0
  175. package/dist/variables.js +662 -0
  176. package/dist/verdicts.d.ts +275 -0
  177. package/dist/verdicts.js +348 -0
  178. package/dist/widgetDecls.d.ts +88 -0
  179. package/dist/widgetDecls.js +119 -0
  180. package/dist/widgets.d.ts +1527 -0
  181. package/dist/widgets.js +208 -0
  182. package/dist/wire.d.ts +126 -0
  183. package/dist/wire.js +140 -0
  184. package/dist/worldinfo.d.ts +150 -0
  185. package/dist/worldinfo.js +212 -0
  186. package/host-elements.d.ts +914 -0
  187. package/package.json +67 -0
@@ -0,0 +1,315 @@
1
+ /**
2
+ * `defineExtension` — the one entry point a plugin author starts from (03, 09).
3
+ *
4
+ * Before this existed, the SDK could express a pipeline and nothing else. An author could
5
+ * build a spec but had nowhere to say *"this is my plugin, here are its lifecycle
6
+ * callbacks, its settings, its node definitions, its components, and the pipelines it
7
+ * ships."* That is the
8
+ * difference between authoring a pipeline and writing a plugin, and it is most of what
9
+ * "download the SDK" has to mean.
10
+ *
11
+ * Since D-1 it says the rest of it too — the **genres**, **surfaces**, **presets**,
12
+ * **configs**, **prompts** and declared **permissions** that were only sayable through
13
+ * `announce()`. One declaration, one build: `serene-pub build` emits a single manifest
14
+ * carrying both halves, and a package no longer has to choose which half of itself to
15
+ * ship. It is the one authoring entry: a package with no code at all declares itself
16
+ * here too — core's own catalog does — and `announcementOf()` compiles it to the
17
+ * announcement document a host syncs.
18
+ *
19
+ * Everything here is a **literal declaration**, because the compiler extracts it from the
20
+ * source without executing it (F6, 03 §3, 13/§30). A registration assembled at runtime is
21
+ * a lint error rather than a silent omission — the manifest has to be a complete statement
22
+ * of what a plugin can do, or the permission model is a guess.
23
+ */
24
+ import { ownWidgets } from './widgetDecls.js';
25
+ import { pluginRuleRef } from './pluginRuleRef.js';
26
+ import { templateSeedProblems } from './templateIds.js';
27
+ import { i18nFindings } from './i18n.js';
28
+ import { isSessionEventDecl } from './events.js';
29
+ import { preset, storedConfig, storedEventDeclaration, } from './announce.js';
30
+ import { annexFieldListFindings } from './annexFields.js';
31
+ import { pluginVariableFindings } from './variables.js';
32
+ import { declarationFindings, storedSwap, swapInputFindings, } from './declarations.js';
33
+ /** @public */
34
+ export function handler(definition, fn, opts = {}) {
35
+ const descriptor = ('descriptor' in definition ? definition.descriptor : definition);
36
+ return {
37
+ __decl: 'handler',
38
+ type: descriptor,
39
+ // The one knob (R62): a node is as public as its handler, private
40
+ // unless its author says otherwise here.
41
+ visibility: opts.visibility ?? 'private',
42
+ handler: fn,
43
+ // Not configurable. See the note on the field.
44
+ runtime: 'process',
45
+ };
46
+ }
47
+ /** @experimental */
48
+ export const lifecycleCallback = (moment, handler, opts = {}) => ({ __decl: 'lifecycle-callback', moment, handler, ...opts });
49
+ /** @public */
50
+ export const eventListener = (event, handler, opts = {}) => ({
51
+ __decl: 'event-listener',
52
+ event: isSessionEventDecl(event) ? event.id : event,
53
+ handler,
54
+ ...opts,
55
+ });
56
+ /** The component frameworks SDK 1.0 ships (R35). The list grows; it never shrinks. @experimental */
57
+ export const COMPONENT_FRAMEWORKS = ['svelte', 'vanilla'];
58
+ /** @public */
59
+ export const component = (d) => ({
60
+ __decl: 'component',
61
+ ...d,
62
+ });
63
+ /** The quota band an author may ask for. An instance clamps into its own. @experimental */
64
+ export const MIN_STORAGE_QUOTA = 1024;
65
+ /** @experimental */
66
+ export const MAX_STORAGE_QUOTA = 256 * 1024 * 1024;
67
+ /**
68
+ * A declared fetch host: an exact host, a `*.suffix` / bare `*` wildcard, each
69
+ * with an optional `:port`. The instance enforces the match and the internal-IP
70
+ * block at call time; this only pins the authoring vocabulary.
71
+ */
72
+ const HOSTNAME = /^(?:\*|(?:\*\.)?[a-z0-9-]+(?:\.[a-z0-9-]+)*)(?::\d+)?$/i;
73
+ /**
74
+ * What is wrong with a declared permission set, in the same words the CLI's
75
+ * sandbox-manifest compiler uses — a package that moves from a separate
76
+ * manifest to this field gets the same answer to the same mistake.
77
+ * @experimental
78
+ */
79
+ export function permissionFindings(p) {
80
+ const out = [];
81
+ if (!p)
82
+ return out;
83
+ if (p.storage) {
84
+ const q = p.storage.quotaBytes;
85
+ if (q !== undefined &&
86
+ (typeof q !== 'number' || !Number.isFinite(q) || q < MIN_STORAGE_QUOTA || q > MAX_STORAGE_QUOTA))
87
+ out.push(`permissions.storage.quotaBytes must be ${MIN_STORAGE_QUOTA}…${MAX_STORAGE_QUOTA}. ` +
88
+ `A pub clamps whatever it is handed, so a number outside the band is not a ` +
89
+ `bigger grant — it is a declaration that says something other than what you get.`);
90
+ }
91
+ if (p.network) {
92
+ const hosts = p.network.hosts ?? [];
93
+ if (!Array.isArray(hosts) || hosts.length === 0)
94
+ out.push(`permissions.network requires a non-empty hosts allowlist — name the hosts you reach ` +
95
+ `('api.example.com', '*.example.com'). A network request naming none reaches nothing.`);
96
+ else
97
+ for (const host of hosts)
98
+ if (typeof host !== 'string' || !HOSTNAME.test(host))
99
+ out.push(`permissions.network host '${String(host)}' is not a valid host, wildcard, or host:port.`);
100
+ }
101
+ return out;
102
+ }
103
+ /** The template-engine id grammar — `<namespace>:template/<name>@<major>`. */
104
+ const TEMPLATE_ENGINE_ID = /^([a-z0-9][a-z0-9.-]*):template\/([a-z0-9][a-z0-9-]*)@(\d+)$/;
105
+ /** @experimental */
106
+ export class ExtensionError extends Error {
107
+ }
108
+ const SLUG = /^[a-z0-9]+([.-][a-z0-9]+)*$/;
109
+ /**
110
+ * Declare a plugin. Validated here rather than at install, because an error an author
111
+ * sees while writing costs a minute and the same error at install costs a support thread.
112
+ * @public
113
+ */
114
+ export function defineExtension(d) {
115
+ const problems = [];
116
+ if (!SLUG.test(d.slug)) {
117
+ problems.push(`'${d.slug}' is not a valid plugin slug — lowercase letters, digits, dots and hyphens ` +
118
+ `(e.g. 'chariot.dice-tray'). It is the namespace every id you register must sit under.`);
119
+ }
120
+ if (!/^\d+\.\d+\.\d+/.test(d.version)) {
121
+ problems.push(`'${d.version}' is not semver. A plugin upgrades by version comparison (12 §3b).`);
122
+ }
123
+ // The display text (R-20): the name the plugin list shows and the
124
+ // description under it. The packager and the install repeat this check
125
+ // over the manifest, because a bundle may have been built against an
126
+ // older SDK.
127
+ problems.push(...i18nFindings(d.name, 'name', { required: true }));
128
+ problems.push(...i18nFindings(d.description, 'description'));
129
+ // `engines` is version ranges only (R1). A namespaced key there is a
130
+ // template engine put in the wrong map — no host reads it as one, so it
131
+ // would silently never register.
132
+ for (const key of Object.keys((d.engines ?? {})))
133
+ if (key.includes(':'))
134
+ problems.push(`engines['${key}'] is a template engine id — 'engines' holds Serene Pub version ` +
135
+ `ranges only. Declare it under templateEngines: { '${key}': renderFn }.`);
136
+ // A template engine sits under this plugin's namespace, like every id it
137
+ // registers — an engine two plugins could claim renders differently by
138
+ // install order.
139
+ for (const [id, fn] of Object.entries(d.templateEngines ?? {})) {
140
+ const m = TEMPLATE_ENGINE_ID.exec(id);
141
+ if (!m)
142
+ problems.push(`templateEngines['${id}'] is not a template engine id. The grammar is ` +
143
+ `'<slug>:template/<name>@<major>' — '${d.slug}:template/mustache@1'.`);
144
+ else if (m[1] !== d.slug)
145
+ problems.push(`templateEngines['${id}'] is not in this plugin's namespace — declare it as ` +
146
+ `'${d.slug}:template/${m[2]}@${m[3]}'.`);
147
+ if (typeof fn !== 'function')
148
+ problems.push(`templateEngines['${id}'] must be the function that renders it.`);
149
+ }
150
+ // Every id a plugin registers must sit under its own namespace. `core:` is reserved
151
+ // and the registry rejects it, but a plugin claiming *another plugin's* namespace
152
+ // would be accepted and would break ownership-based updates (12 §3b).
153
+ // `hooks` declares points; the code a plugin runs is `handlers` (R54).
154
+ if (Array.isArray(d.hooks))
155
+ problems.push(`'hooks' is a list — the code a plugin runs is declared under 'handlers' now: rename ` +
156
+ `hooks: [handler(…), …] to handlers: [handler(…), …]. 'hooks' declares the points your ` +
157
+ `package defines, by key.`);
158
+ for (const h of d.handlers ?? []) {
159
+ if (h.__decl !== 'handler')
160
+ continue;
161
+ const ns = h.type.id.split(':')[0];
162
+ if (ns !== d.slug) {
163
+ problems.push(`type '${h.type.id}' is registered by plugin '${d.slug}' but sits under namespace '${ns}'. ` +
164
+ `Rename it to '${d.slug}:…' — ownership is what lets an update replace your rows and ` +
165
+ `leave everyone else's alone.`);
166
+ }
167
+ }
168
+ for (const p of d.pipelines ?? []) {
169
+ const ns = p.id.split(':')[0];
170
+ if (p.id.includes(':') && ns !== d.slug) {
171
+ problems.push(`pipeline '${p.id}' sits under namespace '${ns}', not '${d.slug}'.`);
172
+ }
173
+ }
174
+ // Same ownership rule as a handler's definition id, one kind over, plus the
175
+ // per-kind shape check — an author who ships a Liquid source with no engine
176
+ // finds out while writing rather than when an instance renders `{% %}` at a
177
+ // model. Duplicates are refused here because the id is the sync key: two
178
+ // entries under one id would race to be the row on every enable.
179
+ const templateIds = new Set();
180
+ for (const t of d.templates ?? []) {
181
+ problems.push(...templateSeedProblems(t, d.slug));
182
+ if (templateIds.has(t.id))
183
+ problems.push(`duplicate template id '${t.id}' — the id is the sync key (12 §3b).`);
184
+ templateIds.add(t.id);
185
+ }
186
+ problems.push(...permissionFindings(d.permissions));
187
+ problems.push(...annexFieldListFindings(d.annexFields));
188
+ // The variables an instance registers from the manifest — the declared
189
+ // list and every band's own (typed templates, 2026-09-27).
190
+ problems.push(...pluginVariableFindings(d.slug, variablesOf(d)));
191
+ // Whose widgets these are (R71): recorded now, so a genre anywhere that
192
+ // names one by value names the id the page knows it by.
193
+ try {
194
+ ownWidgets(d.slug, d.widgets ?? []);
195
+ }
196
+ catch (e) {
197
+ problems.push(e.message);
198
+ }
199
+ // References are values (R48): read each down to its id here, where a
200
+ // mistake still names the author's own declaration.
201
+ const stored = (list, fn) => {
202
+ if (!list)
203
+ return undefined;
204
+ const out = [];
205
+ for (const item of list) {
206
+ try {
207
+ out.push(fn(item));
208
+ }
209
+ catch (e) {
210
+ problems.push(e.message);
211
+ }
212
+ }
213
+ return out;
214
+ };
215
+ problems.push(...swapInputFindings(d.swaps ?? []));
216
+ // A swap runs the contributed node in another package's pipeline, so its
217
+ // handler must be public (R62): a private one would be offered, picked,
218
+ // and then refused on every turn.
219
+ for (const c of d.swaps ?? []) {
220
+ const id = typeof c?.definition === 'string' ? c.definition : c?.definition?.id;
221
+ const impl = (d.handlers ?? []).find((h) => h.__decl === 'handler' && h.type?.id === id);
222
+ if (impl && impl.visibility !== 'public')
223
+ problems.push(`swap contributes '${id}', whose handler is private — a swap runs your node in another ` +
224
+ `package's pipeline; write handler(definition, fn, { visibility: 'public' })` +
225
+ pluginRuleRef('private-nodes'));
226
+ }
227
+ const configs = stored(d.configs, storedConfig);
228
+ const presets = stored(d.presets, preset);
229
+ const events = stored(d.events, storedEventDeclaration);
230
+ // Everything a package declares rather than implements — genres, the input
231
+ // lock, create pipelines, contributed actions, prompts, configs, presets,
232
+ // surfaces, components — is checked by the pass `announce()` runs too
233
+ // (D-1), so one mistake gets one sentence wherever it was written. The
234
+ // namespace rules above are the exception: a definition id and a pipeline id
235
+ // are refused here in words that name the plugin slug.
236
+ problems.push(...declarationFindings({
237
+ ns: d.slug,
238
+ genres: d.genres,
239
+ pipelines: d.pipelines,
240
+ prompts: d.prompts,
241
+ configs,
242
+ presets,
243
+ surfaces: d.surfaces,
244
+ components: d.components,
245
+ widgets: d.widgets,
246
+ swaps: d.swaps,
247
+ events,
248
+ // Declared nothing is `[]`: every key a pipeline of this package
249
+ // writes to its own annex must be declared (ruling 2026-09-26).
250
+ annexFields: d.annexFields ?? [],
251
+ }).errors);
252
+ if (problems.length) {
253
+ throw new ExtensionError(`invalid extension '${d.slug}':\n` + problems.map((p) => ` • ${p}`).join('\n'));
254
+ }
255
+ return {
256
+ __extension: true,
257
+ ...d,
258
+ ...(configs ? { configs } : {}),
259
+ ...(presets ? { presets } : {}),
260
+ ...(events ? { events } : {}),
261
+ ...(d.swaps ? { swaps: d.swaps.map(storedSwap) } : {}),
262
+ };
263
+ }
264
+ // ── Derived views ───────────────────────────────────────────────────────────
265
+ /** @experimental */
266
+ export const handlersOf = (e) => (e.handlers ?? []).filter((h) => h.__decl === 'handler');
267
+ /** @experimental */
268
+ export const lifecycleCallbacksOf = (e) => (e.handlers ?? []).filter((h) => h.__decl === 'lifecycle-callback');
269
+ /** @experimental */
270
+ export const eventListenersOf = (e) => (e.handlers ?? []).filter((h) => h.__decl === 'event-listener');
271
+ /**
272
+ * Every variable a package declares, as its manifest carries them: the
273
+ * `variables` list first, then each variable a band of its handlers'
274
+ * definitions holds (`Descriptor.bands`) — a band is a value holding its
275
+ * variable, so the author never lists it twice. One entry per distinct
276
+ * declaration: the same variable reached twice (two definitions declaring
277
+ * one band) is one entry; one id with two different contents stays two, and
278
+ * `pluginVariableFindings` refuses it.
279
+ * @experimental
280
+ */
281
+ export function variablesOf(e) {
282
+ const out = [];
283
+ const seen = new Set();
284
+ const add = (v) => {
285
+ if (!v || typeof v !== 'object')
286
+ return; // a band naming its variable by id is a reference
287
+ const sig = JSON.stringify(v);
288
+ if (seen.has(sig))
289
+ return;
290
+ seen.add(sig);
291
+ out.push(v);
292
+ };
293
+ for (const v of e.variables ?? [])
294
+ add(v);
295
+ for (const h of e.handlers ?? []) {
296
+ if (h.__decl !== 'handler')
297
+ continue;
298
+ const bands = h.type?.bands;
299
+ for (const v of Object.values(bands ?? {}))
300
+ add(v);
301
+ }
302
+ return out;
303
+ }
304
+ /**
305
+ * The bindings map the executor wants, built from the declaration. So an author's tests
306
+ * run their real handlers rather than a hand-maintained parallel map that drifts.
307
+ * @experimental
308
+ */
309
+ export function bindingsOf(e) {
310
+ const out = {};
311
+ for (const h of handlersOf(e))
312
+ out[h.type.id] = h.handler;
313
+ return out;
314
+ }
315
+ //# sourceMappingURL=extension.js.map
@@ -0,0 +1,53 @@
1
+ /**
2
+ * What *kind* of setting something is, as a declaration.
3
+ *
4
+ * A slot already carries a `facet` — `prompts`, `weights`, `review` — and the
5
+ * configuration panel groups on it, because a facet names a kind and never a
6
+ * node key, a count or an order (05 §0a). What the panel did *not* have was any
7
+ * way to know a facet's heading, its position, or whether it leads the panel or
8
+ * sits behind the tuning door. All three lived in a hardcoded list in the
9
+ * client.
10
+ *
11
+ * That list had the failure mode a hardcoded list always has: it was not a
12
+ * fallback, it was the filter. Options were matched *into* it, so a facet the
13
+ * client had never heard of — a plugin's `retrieval`, say — matched no group
14
+ * and rendered **nowhere**. Settings that existed, were writable, and were
15
+ * invisible.
16
+ *
17
+ * So a facet is declared here, and the client renders what it is sent. An
18
+ * undeclared facet still gets a group of its own rather than disappearing:
19
+ * unknown is not the same as absent, and the panel should say so.
20
+ */
21
+ import type { I18n } from './descriptors.js';
22
+ /** @experimental */
23
+ export interface FacetDecl {
24
+ id: string;
25
+ /**
26
+ * The heading it renders under.
27
+ *
28
+ * **Two facets sharing a heading are one group.** That is how `connection`
29
+ * and `sampling` become a single "Model" section — they are different kinds
30
+ * of setting and the same question to the person reading. Merging by
31
+ * heading keeps that in data rather than in a client-side pairing.
32
+ */
33
+ i18n: I18n;
34
+ /** Lower sorts first. A group takes the lowest order of its members. */
35
+ order: number;
36
+ /**
37
+ * Leads the panel, rather than sitting behind the tuning door.
38
+ *
39
+ * The split is about audience, not importance: this panel is for people who
40
+ * do not need to know what a pipeline is, and per-step weights belong in
41
+ * the builder. They stay reachable either way.
42
+ */
43
+ simple?: boolean;
44
+ }
45
+ /** @experimental */
46
+ export declare function defineFacet(decl: FacetDecl): FacetDecl;
47
+ /** @internal */
48
+ export declare const getFacet: (id: string) => FacetDecl | undefined;
49
+ /** @experimental */
50
+ export declare const allFacets: () => FacetDecl[];
51
+ /** @experimental */
52
+ export declare function _clearFacets(): void;
53
+ //# sourceMappingURL=facets.d.ts.map
package/dist/facets.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * What *kind* of setting something is, as a declaration.
3
+ *
4
+ * A slot already carries a `facet` — `prompts`, `weights`, `review` — and the
5
+ * configuration panel groups on it, because a facet names a kind and never a
6
+ * node key, a count or an order (05 §0a). What the panel did *not* have was any
7
+ * way to know a facet's heading, its position, or whether it leads the panel or
8
+ * sits behind the tuning door. All three lived in a hardcoded list in the
9
+ * client.
10
+ *
11
+ * That list had the failure mode a hardcoded list always has: it was not a
12
+ * fallback, it was the filter. Options were matched *into* it, so a facet the
13
+ * client had never heard of — a plugin's `retrieval`, say — matched no group
14
+ * and rendered **nowhere**. Settings that existed, were writable, and were
15
+ * invisible.
16
+ *
17
+ * So a facet is declared here, and the client renders what it is sent. An
18
+ * undeclared facet still gets a group of its own rather than disappearing:
19
+ * unknown is not the same as absent, and the panel should say so.
20
+ */
21
+ import { refuseUnlessIdentical } from './hash.js';
22
+ const facets = new Map();
23
+ /** @experimental */
24
+ export function defineFacet(decl) {
25
+ const existing = facets.get(decl.id);
26
+ if (existing)
27
+ refuseUnlessIdentical(existing, decl, `duplicate facet: ${decl.id}`);
28
+ facets.set(decl.id, decl);
29
+ return decl;
30
+ }
31
+ /** @internal */
32
+ export const getFacet = (id) => facets.get(id);
33
+ /** @experimental */
34
+ export const allFacets = () => [...facets.values()].sort((a, b) => a.order - b.order);
35
+ /** @experimental */
36
+ export function _clearFacets() {
37
+ facets.clear();
38
+ }
39
+ // ── Core's facets ───────────────────────────────────────────────────────────
40
+ //
41
+ // The order and headings the panel shipped with, now stated where the slots
42
+ // that reference them can be read beside them.
43
+ defineFacet({ id: 'prompts', i18n: { en: 'Prompt' }, order: 0, simple: true });
44
+ defineFacet({ id: 'connection', i18n: { en: 'Model' }, order: 1, simple: true });
45
+ /** Shares "Model" with `connection` — one question, two slots. */
46
+ defineFacet({ id: 'sampling', i18n: { en: 'Model' }, order: 2, simple: true });
47
+ defineFacet({ id: 'variables', i18n: { en: 'Layout' }, order: 3 });
48
+ defineFacet({ id: 'templates', i18n: { en: 'Template' }, order: 4 });
49
+ defineFacet({ id: 'weights', i18n: { en: 'Tuning' }, order: 5 });
50
+ defineFacet({ id: 'review', i18n: { en: 'Review' }, order: 6, simple: true });
51
+ /**
52
+ * The substrate's own (`settingsSlot.ts`): an optional node's switch, a gather
53
+ * clause's mode. Declared since R-9 (2026-09-16) — it resolved through the
54
+ * undeclared-facet fallback before, which is the path meant for a plugin's
55
+ * word, not core's. Same heading; behind the tuning door as it always was.
56
+ */
57
+ defineFacet({ id: 'settings', i18n: { en: 'Settings' }, order: 7 });
58
+ /** `context-budget` and friends declare a bare `parameters` slot. */
59
+ defineFacet({ id: 'params', i18n: { en: 'Tuning' }, order: 5 });
60
+ //# sourceMappingURL=facets.js.map
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Folded sections (B4; decision D5, 2026-09-27) — the checks a host makes on
3
+ * the message outlets' `sections` in-port, the one reading of where a row keeps
4
+ * them, and the one `core:section` part each becomes. Pure: the host's write,
5
+ * its projection to parts and a widget's fallback all read through here, so
6
+ * there is one answer to "which sections does this alternative carry".
7
+ *
8
+ * Where a row keeps them: `metadata.sections` while the row has no
9
+ * alternatives; `metadata.swipes.sectionsHistory`, parallel to `history`, once
10
+ * a write gives one of them sections. Until that array exists the first
11
+ * alternative's sections are the row's `sections` — the ones it had before
12
+ * anybody swiped.
13
+ * @experimental
14
+ */
15
+ import type { FoldedSectionPartDataV1, FoldedSectionV1 } from './widgets.js';
16
+ /**
17
+ * How many folded sections one reply may carry. Bounded because they are laid
18
+ * out in the host's own part slots, between a narrator's instructions and the
19
+ * reply's reasoning and body. @experimental
20
+ */
21
+ export declare const MAX_FOLDED_SECTIONS = 6;
22
+ /** A folded section's `kind`: a lowercase slug. @experimental */
23
+ export declare const FOLDED_SECTION_KIND: RegExp;
24
+ /**
25
+ * Check a `sections` value and return it normalized, or the reason it is
26
+ * refused (1-based position, the field, what is wrong). `undefined`/`null` is
27
+ * "none given". A section with nothing to show — blank text, an empty list —
28
+ * is left out rather than refused: a formatter that found nothing is an
29
+ * ordinary state.
30
+ * @experimental
31
+ */
32
+ export declare function checkFoldedSections(value: unknown): {
33
+ sections?: FoldedSectionV1[];
34
+ refusal?: string;
35
+ };
36
+ /**
37
+ * The folded sections alternative `slot` of a row carries, read from its
38
+ * metadata. `slot` defaults to the alternative the row shows.
39
+ * @experimental
40
+ */
41
+ export declare function foldedSectionsOf(metadata: unknown, slot?: number): FoldedSectionV1[];
42
+ /**
43
+ * Metadata with the SHOWN alternative's folded sections replaced by
44
+ * `sections` — whole, so an empty list clears them. Every other alternative
45
+ * keeps its own. Returns a new object; the input is not touched.
46
+ * @experimental
47
+ */
48
+ export declare function withFoldedSections<M extends object>(metadata: M | null | undefined, sections: FoldedSectionV1[]): M;
49
+ /**
50
+ * One folded section as the `core:section` part it is stored as: `content` is
51
+ * its text, or its items as a markdown bullet list (what a renderer that knows
52
+ * nothing of `items` shows); `data` is {@link FoldedSectionPartDataV1}.
53
+ * @experimental
54
+ */
55
+ export declare function foldedSectionPart(section: FoldedSectionV1): {
56
+ type: 'core:section';
57
+ content: string;
58
+ data: FoldedSectionPartDataV1;
59
+ };
60
+ /**
61
+ * The readable lines a document's lists make — what `core:task/list-section@1`
62
+ * folds into one section's `items` (lair pass B5, decision D5, 2026-09-27).
63
+ *
64
+ * `path` names the keys to read, comma-separated and in order (`'beats,speakers'`);
65
+ * empty reads the document itself. A list contributes one line per entry and
66
+ * anything else one line: a string is itself, a number or a boolean its text,
67
+ * and an object its own scalar values joined with ` — ` in key order, so a
68
+ * planner's `{ name, intent }` reads "Mara — check the door" and never as JSON.
69
+ * Nested lists and objects inside an entry are left out rather than printed.
70
+ * Blank lines are dropped, so a document with nothing to say makes no lines.
71
+ * @experimental
72
+ */
73
+ export declare function sectionItemsOf(document: unknown, path?: string): string[];
74
+ //# sourceMappingURL=foldedSections.d.ts.map
@@ -0,0 +1,161 @@
1
+ /**
2
+ * How many folded sections one reply may carry. Bounded because they are laid
3
+ * out in the host's own part slots, between a narrator's instructions and the
4
+ * reply's reasoning and body. @experimental
5
+ */
6
+ export const MAX_FOLDED_SECTIONS = 6;
7
+ /** A folded section's `kind`: a lowercase slug. @experimental */
8
+ export const FOLDED_SECTION_KIND = /^[a-z][a-z0-9-]*$/;
9
+ /**
10
+ * Check a `sections` value and return it normalized, or the reason it is
11
+ * refused (1-based position, the field, what is wrong). `undefined`/`null` is
12
+ * "none given". A section with nothing to show — blank text, an empty list —
13
+ * is left out rather than refused: a formatter that found nothing is an
14
+ * ordinary state.
15
+ * @experimental
16
+ */
17
+ export function checkFoldedSections(value) {
18
+ if (value === undefined || value === null)
19
+ return {};
20
+ if (!Array.isArray(value))
21
+ return { refusal: 'sections must be a list of { kind, label, content | items }' };
22
+ if (value.length > MAX_FOLDED_SECTIONS)
23
+ return { refusal: `a reply carries at most ${MAX_FOLDED_SECTIONS} sections — this has ${value.length}` };
24
+ const sections = [];
25
+ for (let i = 0; i < value.length; i++) {
26
+ const at = `section ${i + 1}`;
27
+ const s = value[i];
28
+ if (!s || typeof s !== 'object' || Array.isArray(s))
29
+ return { refusal: `${at} is not an object` };
30
+ if (typeof s.kind !== 'string' || !FOLDED_SECTION_KIND.test(s.kind))
31
+ return { refusal: `${at} needs a kind: a lowercase slug such as 'plan'` };
32
+ const label = typeof s.label === 'string' ? s.label.trim() : '';
33
+ if (!label)
34
+ return { refusal: `${at} needs a label: the heading its button shows` };
35
+ const hasContent = s.content !== undefined && s.content !== null;
36
+ const hasItems = s.items !== undefined && s.items !== null;
37
+ if (hasContent === hasItems)
38
+ return { refusal: `${at} needs exactly one of content and items` };
39
+ if (hasContent) {
40
+ if (typeof s.content !== 'string')
41
+ return { refusal: `${at}'s content must be text` };
42
+ if (s.content.trim())
43
+ sections.push({ kind: s.kind, label, content: s.content });
44
+ continue;
45
+ }
46
+ if (!Array.isArray(s.items) || !s.items.every((x) => typeof x === 'string'))
47
+ return { refusal: `${at}'s items must be a list of text` };
48
+ const items = s.items.map((x) => x.trim()).filter(Boolean);
49
+ if (items.length)
50
+ sections.push({ kind: s.kind, label, items });
51
+ }
52
+ return { sections };
53
+ }
54
+ /** A stored value read back leniently: what `checkFoldedSections` would keep, or nothing. */
55
+ function stored(value) {
56
+ return checkFoldedSections(value).sections ?? [];
57
+ }
58
+ /**
59
+ * The folded sections alternative `slot` of a row carries, read from its
60
+ * metadata. `slot` defaults to the alternative the row shows.
61
+ * @experimental
62
+ */
63
+ export function foldedSectionsOf(metadata, slot) {
64
+ const meta = (metadata && typeof metadata === 'object' ? metadata : {});
65
+ const swipes = meta.swipes;
66
+ if (!swipes || !Array.isArray(swipes.history) || !swipes.history.length)
67
+ return stored(meta.sections);
68
+ const i = slot ?? swipes.currentIdx ?? 0;
69
+ if (Array.isArray(swipes.sectionsHistory))
70
+ return stored(swipes.sectionsHistory[i]);
71
+ return i === 0 ? stored(meta.sections) : [];
72
+ }
73
+ /**
74
+ * Metadata with the SHOWN alternative's folded sections replaced by
75
+ * `sections` — whole, so an empty list clears them. Every other alternative
76
+ * keeps its own. Returns a new object; the input is not touched.
77
+ * @experimental
78
+ */
79
+ export function withFoldedSections(metadata, sections) {
80
+ const meta = { ...(metadata ?? {}) };
81
+ const swipes = meta.swipes;
82
+ const value = sections.length ? sections : null;
83
+ if (!swipes || !Array.isArray(swipes.history) || !swipes.history.length) {
84
+ if (value)
85
+ meta.sections = value;
86
+ else
87
+ delete meta.sections;
88
+ return meta;
89
+ }
90
+ const length = swipes.history.length;
91
+ const history = Array.isArray(swipes.sectionsHistory)
92
+ ? swipes.sectionsHistory.map((s) => (stored(s).length ? stored(s) : null))
93
+ : [stored(meta.sections).length ? stored(meta.sections) : null];
94
+ while (history.length < length)
95
+ history.push(null);
96
+ history.length = length;
97
+ const idx = Math.max(0, Math.min(swipes.currentIdx ?? 0, length - 1));
98
+ history[idx] = value;
99
+ meta.swipes = { ...swipes, sectionsHistory: history };
100
+ return meta;
101
+ }
102
+ /**
103
+ * One folded section as the `core:section` part it is stored as: `content` is
104
+ * its text, or its items as a markdown bullet list (what a renderer that knows
105
+ * nothing of `items` shows); `data` is {@link FoldedSectionPartDataV1}.
106
+ * @experimental
107
+ */
108
+ export function foldedSectionPart(section) {
109
+ const items = section.items;
110
+ return {
111
+ type: 'core:section',
112
+ content: items ? items.map((x) => `- ${x}`).join('\n') : (section.content ?? ''),
113
+ data: { title: section.label, kind: section.kind, ...(items ? { items: [...items] } : {}) },
114
+ };
115
+ }
116
+ /**
117
+ * The readable lines a document's lists make — what `core:task/list-section@1`
118
+ * folds into one section's `items` (lair pass B5, decision D5, 2026-09-27).
119
+ *
120
+ * `path` names the keys to read, comma-separated and in order (`'beats,speakers'`);
121
+ * empty reads the document itself. A list contributes one line per entry and
122
+ * anything else one line: a string is itself, a number or a boolean its text,
123
+ * and an object its own scalar values joined with ` — ` in key order, so a
124
+ * planner's `{ name, intent }` reads "Mara — check the door" and never as JSON.
125
+ * Nested lists and objects inside an entry are left out rather than printed.
126
+ * Blank lines are dropped, so a document with nothing to say makes no lines.
127
+ * @experimental
128
+ */
129
+ export function sectionItemsOf(document, path = '') {
130
+ const keys = path
131
+ .split(',')
132
+ .map((k) => k.trim())
133
+ .filter(Boolean);
134
+ const sources = keys.length
135
+ ? keys.map((k) => document && typeof document === 'object' && !Array.isArray(document)
136
+ ? document[k]
137
+ : undefined)
138
+ : [document];
139
+ const lines = [];
140
+ for (const source of sources)
141
+ for (const entry of Array.isArray(source) ? source : [source]) {
142
+ const line = lineOf(entry);
143
+ if (line)
144
+ lines.push(line);
145
+ }
146
+ return lines;
147
+ }
148
+ /** One entry as one readable line, or '' when it has nothing scalar to show. */
149
+ function lineOf(entry) {
150
+ if (typeof entry === 'string')
151
+ return entry.trim();
152
+ if (typeof entry === 'number' || typeof entry === 'boolean')
153
+ return String(entry);
154
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry))
155
+ return '';
156
+ return Object.values(entry)
157
+ .map((v) => (typeof v === 'string' ? v.trim() : typeof v === 'number' || typeof v === 'boolean' ? String(v) : ''))
158
+ .filter(Boolean)
159
+ .join(' — ');
160
+ }
161
+ //# sourceMappingURL=foldedSections.js.map