@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,683 @@
1
+ /**
2
+ * The builder (04 §4). Kind-named methods — `.inlet() .query() .task() .oracle()
3
+ * .outlet()` — so reading a spec top to bottom shows the effect taxonomy, and so
4
+ * the type system can enforce laws that a generic .step() could only find at
5
+ * validation time (04 §4a). Clauses are `.gather() .each() .loop() .junction()`
6
+ * (R-14, ruled 2026-09-15).
7
+ *
8
+ * The chain is a *value*. It compiles to a document; SP imports the document and
9
+ * never this code (F6).
10
+ *
11
+ * Every node method takes either a pinned constructor or a **callback that receives the
12
+ * scope** — `$ => C.assemble({ messages: $.history.messages })`. The callback form is
13
+ * preferred: it types the node key and the port, and it makes a forward reference
14
+ * impossible to write rather than a finding to read (src/scope.ts). Both forms compile
15
+ * to the same rows.
16
+ */
17
+ import { type NodeSpec, type Kind, type PortDecl, type OutPortsOf, type Descriptor } from './descriptors.js';
18
+ import { ITEM, type Scope } from './scope.js';
19
+ import { type DataRef } from './refs.js';
20
+ import type { SessionShape } from './descriptors.js';
21
+ import type { TemplateValue } from './engines.js';
22
+ import { type EnvoyDecl, type GenreDecl } from './genres.js';
23
+ import type { ExternalRef } from './announce.js';
24
+ import { type SessionEventDecl } from './events.js';
25
+ import { type I18n } from './i18n.js';
26
+ import { type ActionDecl } from './actions.js';
27
+ /** @experimental */
28
+ export interface SpecMeta {
29
+ /**
30
+ * Semver. **The upgrade key, not part of the identity** — an import replaces the
31
+ * installed copy when newer and is ignored when it is not (src/identity.ts).
32
+ */
33
+ version: string;
34
+ /**
35
+ * Who ships this spec: a plugin slug, `core`, or absent for a hand-imported document.
36
+ * Defaults to the owner segment of the id, so it only needs stating when they differ.
37
+ *
38
+ * Ownership is what stops an update from silently taking over a spec an admin
39
+ * imported by hand, or one another plugin ships — "newer" is not a licence to
40
+ * overwrite somebody else's row.
41
+ */
42
+ owner?: string;
43
+ /**
44
+ * For the genre's create pipeline this carries the genre's declaration
45
+ * (24 §3): display name, family, standing `SessionShape`, event surface.
46
+ * Stored on the version row so shape checks stay SELECTs, never document
47
+ * loads.
48
+ */
49
+ genre?: {
50
+ name: unknown;
51
+ family: string;
52
+ /** The picker card's subtitle. */
53
+ description?: unknown;
54
+ shape?: SessionShape;
55
+ /**
56
+ * The genre's event surface (24 §5), persisted with the declaration
57
+ * so "which events exist and which are required" stays a SELECT —
58
+ * the genre dashboard and the preset editor read it off the row.
59
+ */
60
+ events?: Record<string, {
61
+ required?: boolean;
62
+ open?: boolean;
63
+ }>;
64
+ /**
65
+ * The genre's envoys (R-18), persisted with the declaration for the
66
+ * same reason the events are: a host reads "which speakers does this
67
+ * genre bring" off the create spec's row, never from the running
68
+ * registry — which is also what makes them part of the spec's hash.
69
+ */
70
+ envoys?: readonly EnvoyDecl[];
71
+ /**
72
+ * What a person's persona-less line is called (R4), persisted with the
73
+ * declaration on the same terms as the envoys: the host names those
74
+ * lines off the create spec's row. See `GenreDecl.playerLabel`.
75
+ */
76
+ playerLabel?: unknown;
77
+ /**
78
+ * The genre's pinned settings (PLAN-turn-order §4.13), persisted
79
+ * with the declaration on the same terms as the envoys: the host
80
+ * resolves the settings cascade off the create spec's row, never
81
+ * from the running registry. See `GenreDecl.settings`.
82
+ */
83
+ settings?: Readonly<Record<string, unknown>>;
84
+ };
85
+ i18n?: {
86
+ name?: unknown;
87
+ };
88
+ /**
89
+ * Where this spec sits in the catalogue (ruled 2026-08-27): declared
90
+ * metadata, **never** encoded into the id — an id is an address that
91
+ * receipts and configs hold forever, while a classification is a claim
92
+ * that changes. The admin surface sorts, groups and filters on these;
93
+ * nothing may parse them out of the id.
94
+ */
95
+ taxonomy?: SpecTaxonomy;
96
+ /**
97
+ * What this spec contributes to *other* surfaces (19 §3–§4). **Actions**
98
+ * are the first kind: "I offer this function on sessions of that genre,
99
+ * at these venues" — the narrate spec contributes the narrator button to
100
+ * the standard genre, and the genre never has to know. Rides the document
101
+ * (hashed with it, stored with it, exported with it), so contribution is
102
+ * content, not registration.
103
+ *
104
+ * The action model (plans/29 R-15, 30 §U5c): every action declares a
105
+ * **venue** (where, per channel), an **audience** (who sees, who acts),
106
+ * `quick` (primary set or overflow), a **slash name** and a localised
107
+ * `label` — see `actions.ts`.
108
+ */
109
+ contributes?: {
110
+ /**
111
+ * Each action is offered to the genre of the spec's inlet lock, so an
112
+ * action never names a genre — `.inlet()` fills it in.
113
+ */
114
+ actions?: Array<Omit<ActionDecl, 'genre'> & {
115
+ genre?: never;
116
+ }>;
117
+ };
118
+ }
119
+ /**
120
+ * The catalogue claims (ruled 2026-08-27). All optional — an undeclared spec
121
+ * still lists, it just sorts under "unclassified" — and all open to change on
122
+ * republish without touching identity.
123
+ * @experimental
124
+ */
125
+ export interface SpecTaxonomy {
126
+ /**
127
+ * What the pipeline is to its genre: `create` instantiates sessions of its
128
+ * type (23 §7 — the required one; the spec IS the session type), `primary`
129
+ * carries the main turn, `action` is invoked by a person or trigger,
130
+ * `maintenance` runs off the critical path (summaries, graph builds).
131
+ */
132
+ role?: 'create' | 'primary' | 'action' | 'maintenance';
133
+ /**
134
+ * The one session genre this spec serves — a genre id (24 §3), e.g.
135
+ * `core:genre/chat`. **Never written by an author**: `.inlet()`
136
+ * copies it from the lock, so the catalogue and the lock cannot
137
+ * disagree. A document read back carries it.
138
+ */
139
+ genre?: never;
140
+ }
141
+ /** @experimental */
142
+ export interface BuiltNode {
143
+ key: string;
144
+ kind: Kind;
145
+ definitionId: string;
146
+ definitionVersion: number;
147
+ config: Record<string, unknown>;
148
+ /** Set when the node sits inside a clause — a gather, an each, a loop, a junction. */
149
+ clauseId?: string;
150
+ clauseKind?: ClauseKind;
151
+ clauseChain?: string;
152
+ position: number;
153
+ /**
154
+ * Where this node's controls may be shown beyond the admin's pipeline
155
+ * panel (PLAN-turn-order §4.11, R12). `session: true` marks the node's
156
+ * rebind (on a strategy node) or its params as a **declared session
157
+ * setting**: the session settings form renders a card for the spec with
158
+ * exactly the marked keys, and nothing else. Stored in the document, so
159
+ * the form reads it off the registry. Absent = admin panel only.
160
+ *
161
+ * `swaps` (R28, the modder pass): the definition ids a session may seat
162
+ * here instead of the pin, in the order a picker lists them. The pin is
163
+ * the default and is always offered first, so it is never listed. Present
164
+ * only when non-empty; a node with swaps is always `session: true`.
165
+ *
166
+ * `stream` and `status` (lair pass B3/B18, ruled 2026-09-27, D6/D5) are
167
+ * what the node shows **while it runs**:
168
+ *
169
+ * · `stream: true` — **the streaming step**: this oracle's tokens are
170
+ * the reply's prose, routed into the run's live row as they arrive.
171
+ * Declared, never inferred (D6): a spec that marks nothing streams
172
+ * nothing and shows its status until the write lands. At most one on
173
+ * any single execution path — steps in mutually exclusive branches of
174
+ * one junction may each stream, and the one that runs does (W2) — an
175
+ * oracle with a streaming out-port — a JSON step never
176
+ * streams — and never inside an `each` or a `loop`; `validate()`
177
+ * refuses the rest (law `streaming step`).
178
+ * · `status` — **the step status**: the sentence the row and the
179
+ * progress card show while this node runs (*Planning the turn*), a
180
+ * string or a locale map (R-20), `{speaker}` filled by the host. It
181
+ * wins over any status the node's own handler sets, for this node
182
+ * only.
183
+ *
184
+ * `label` and `purpose` (config grouping, ruled 2026-09-30) are what the
185
+ * settings call this step:
186
+ *
187
+ * · `label` — **the step label**: this step's own name wherever the
188
+ * settings name it — the heading of the group a model call leads, and
189
+ * its legend among Advanced settings. Wins over the step status and the
190
+ * node definition's name. Any node may carry one.
191
+ * · `purpose` — **the step purpose**: one or two plain sentences under
192
+ * that group's heading, saying what this model call is for. Only on a
193
+ * model call — an oracle whose definition declares a `connection` slot
194
+ * (`isModelCall`); no other step heads a group, so a purpose anywhere
195
+ * else would never be read.
196
+ *
197
+ * Display text (R-20), hashed with the document like `status`: a spec that
198
+ * sets neither hashes as it always did.
199
+ */
200
+ expose?: {
201
+ session?: boolean;
202
+ swaps?: string[];
203
+ stream?: true;
204
+ status?: I18n;
205
+ label?: I18n;
206
+ purpose?: I18n;
207
+ };
208
+ }
209
+ /**
210
+ * One branch's condition (20 §10). Exactly one of `equals` / `equalsPath` /
211
+ * `truthy` / `default` per predicate; `path` narrows what the condition reads
212
+ * off the junction's value (dot path, e.g. `call.tool`). Deliberately not a
213
+ * rules engine — a decision too rich for this table belongs in a Task that
214
+ * computes a value this table can read.
215
+ *
216
+ * The shape is `predicates.ts`'s, which an action's *enabled-when* reads too,
217
+ * so a branch and a greyed button can never mean two different things by the
218
+ * same words.
219
+ * @experimental
220
+ */
221
+ export interface JunctionPredicate {
222
+ /** Dot path read off the junction's value first. Absent = the value itself. */
223
+ path?: string;
224
+ /** Fires when the (possibly path-read) value strictly equals this literal. */
225
+ equals?: unknown;
226
+ /**
227
+ * Fires when the value strictly equals the value at **another path on the
228
+ * same junction value** (D-4a, 2026-09-17) — `{ path: 'accused',
229
+ * equalsPath: 'culprit' }` over a task publishing both.
230
+ *
231
+ * `equals` takes a literal, so without this a branch could ask *is the
232
+ * accused Vell?* and never *is the accused the culprit?* — the one
233
+ * question a genre that DERIVES its hidden fact has to ask. ⚠ Either side
234
+ * absent fires nothing: two unwired ports must not compare equal and route
235
+ * the branch that means *you got it right*.
236
+ */
237
+ equalsPath?: string;
238
+ /** Fires when the value is truthy. */
239
+ truthy?: boolean;
240
+ /** Fires exactly when no other branch fired. At most one per junction. */
241
+ default?: boolean;
242
+ }
243
+ /**
244
+ * The four clause rules (R-14, ruled 2026-09-15). A **clause** is a container of
245
+ * nodes with a repetition or branching rule of its own: **gather** collects
246
+ * several chains (was `async`; `mode` is a setting and, by the equivalence law,
247
+ * unobservable), **each** runs once per item (was `map`), **loop** repeats
248
+ * while a predicate holds, **junction** runs the branches whose predicates
249
+ * fired (was `route`). Stored documents say these words; the content hash
250
+ * moved once, with the kinds.
251
+ * @experimental
252
+ */
253
+ export type ClauseKind = 'gather' | 'each' | 'loop' | 'junction';
254
+ /** @experimental */
255
+ export interface BuiltClause {
256
+ id: string;
257
+ kind: ClauseKind;
258
+ mode: 'sequential' | 'parallel';
259
+ /** each only — the list to iterate. */
260
+ over?: unknown;
261
+ /**
262
+ * **Mandatory for each and loop.** An unbounded repeat is the most likely source of a
263
+ * surprise bill in the system, and for a loop it is also the only thing standing
264
+ * between a bad predicate and a run that never ends.
265
+ */
266
+ max?: number;
267
+ /**
268
+ * loop only. A **port reference**, not an expression: the loop repeats while this
269
+ * value is truthy, re-evaluated at the end of each iteration (do-while — a tool
270
+ * loop always wants one generate before it can know whether to stop).
271
+ *
272
+ * A reference rather than an expression is what keeps the construct renderable
273
+ * ("repeats while generate.hasToolCalls, max 8") and keeps a second expression
274
+ * language out of the design.
275
+ */
276
+ repeatWhile?: unknown;
277
+ /**
278
+ * junction only. The value the branches are chosen on — a port reference
279
+ * resolved when the clause runs. A reference for the same reason
280
+ * `repeatWhile` is one: the construct stays renderable ("junction on
281
+ * parse.call") and no second expression language enters the design (20 §10).
282
+ */
283
+ on?: unknown;
284
+ /**
285
+ * junction only. Each branch's declared predicate over the value. Any
286
+ * subset of branches may fire; a `default: true` branch fires exactly when
287
+ * nothing else did. Declarations, never code — the executor evaluates
288
+ * them, the receipt records every evaluation, and the panel can render
289
+ * the whole table without running anything.
290
+ */
291
+ branches?: Record<string, JunctionPredicate>;
292
+ chains: string[];
293
+ /** Clauses nest: which clause and chain this one sits inside. Undefined = the spine. */
294
+ clauseId?: string;
295
+ clauseChain?: string;
296
+ /** Ordering against sibling nodes at the same level. */
297
+ position: number;
298
+ }
299
+ /**
300
+ * A preset the **spec author** ships — "Balanced", "Lore-heavy", "Fast" (12 §3).
301
+ *
302
+ * The scope chain's layer 5 is a single author default per slot, which is enough for one
303
+ * opinion and no help at all for "here are three coherent ways to run this." Named author
304
+ * presets fill that, and they need no schema: they seed `config_presets` and
305
+ * `node_overrides` rows at `scope_kind='config'` on install, which both already exist.
306
+ *
307
+ * Two rulings ride on this — see 12 §3a.
308
+ * @experimental
309
+ */
310
+ export interface BuiltPreset {
311
+ /**
312
+ * **The identity.** Stable, PK-agnostic, and the reference an update or a defaults
313
+ * sync matches on — same convention as the events registry (13 §7g), now applied to
314
+ * every seeded row rather than to events alone.
315
+ *
316
+ * The consequence worth knowing: the slug is the identity and the label is the
317
+ * display, so renaming "Lore-heavy" to "World-focused" is free and keeps every
318
+ * user's selection intact. Changing the *slug* is a delete plus a create.
319
+ */
320
+ slug: string;
321
+ /** The name a picker lists it by — a string or a locale map with `en` (R-20). */
322
+ label: I18n;
323
+ description?: I18n;
324
+ /** At most one author preset may be the shipped default. */
325
+ default?: boolean;
326
+ /**
327
+ * Who owns this preset, for update and sync. Defaults to the spec's owner, and is
328
+ * stated explicitly only in the case that justifies the field existing: a **preset
329
+ * pack** — a plugin shipping presets for a pipeline someone else ships. Uninstalling
330
+ * the pack must remove its presets and leave the pipeline alone, which is only
331
+ * decidable if the preset says who it belongs to (12 §3b).
332
+ */
333
+ owner?: string;
334
+ /** Flat override rows, exactly the shape `node_overrides` stores. */
335
+ values: Array<{
336
+ nodeKey: string;
337
+ slot: string;
338
+ value: unknown;
339
+ }>;
340
+ }
341
+ /** @experimental */
342
+ export interface BuiltSpec {
343
+ id: string;
344
+ meta: SpecMeta;
345
+ nodes: BuiltNode[];
346
+ clauses: BuiltClause[];
347
+ /** Fragments included, recorded for provenance after expansion (16 §3a). */
348
+ includes: Array<{
349
+ key: string;
350
+ fragmentId: string;
351
+ }>;
352
+ /** Author-shipped named configurations (12 §3a). Round-trips with the document (F4). */
353
+ presets: BuiltPreset[];
354
+ /**
355
+ * The usage lock (24 §4): the session event this spec's input answers,
356
+ * and the genre it serves. Declared on `.input()`, serialized with the
357
+ * document, hashed with it, enforced at compile, publish and dispatch.
358
+ *
359
+ * `events` (PLAN-turn-order §4.1, 2026-09-21): the alternative to one
360
+ * `event` — a spec that answers several session events (the turn-order
361
+ * spec answers nine). A dispatched event is accepted when it is the
362
+ * locked `event` or is in `events`. Preset bindings are unchanged: a
363
+ * spec bound to N events has N binding rows.
364
+ */
365
+ input?: {
366
+ genre?: string;
367
+ event?: string;
368
+ events?: string[];
369
+ };
370
+ }
371
+ /** What a node method accepts: the value, or a function of the scope that returns it. @experimental */
372
+ export type NodeArg<N, Nodes extends Record<string, PortDecl>> = N | (($: Scope<Nodes>) => N);
373
+ /**
374
+ * The optional third argument of a node method (PLAN-turn-order §4.11):
375
+ * `{ expose: { session: true } }` marks the node's controls as a declared
376
+ * session setting — see `BuiltNode.expose`. Additive: every existing call
377
+ * passes nothing and lands exactly the row it landed before.
378
+ *
379
+ * `swaps` (R28) lists the pins a session may seat instead of this node's —
380
+ * pins, not strings, so a typo is a compile error and the fit is checked
381
+ * here: each must be the same kind with the same in- and out-ports, by name
382
+ * and shape. Listing swaps implies `session: true`.
383
+ * @experimental
384
+ */
385
+ export interface NodeOpts {
386
+ expose?: {
387
+ session?: boolean;
388
+ swaps?: readonly {
389
+ readonly id: string;
390
+ readonly descriptor: Descriptor<any, any, any>;
391
+ }[];
392
+ /** This oracle is the streaming step — see `BuiltNode.expose` (B3, D6). */
393
+ stream?: true;
394
+ /** The step status shown while this node runs — see `BuiltNode.expose` (B18, D5). */
395
+ status?: I18n;
396
+ /** The step label: this step's name in settings — see `BuiltNode.expose`. */
397
+ label?: I18n;
398
+ /** The step purpose: what this model call is for, under its settings heading — see `BuiltNode.expose`. */
399
+ purpose?: I18n;
400
+ };
401
+ }
402
+ /**
403
+ * Whether a definition is a **model call**: an oracle that declares a
404
+ * `connection` slot — the only step a step purpose may sit on (see
405
+ * `BuiltNode.expose`). An assemble's `connection` slot says which model the
406
+ * prompt is formatted for; it calls none, so it does not count.
407
+ * @internal
408
+ */
409
+ export declare function isModelCall(def: {
410
+ kind: string;
411
+ slots?: Readonly<Record<string, {
412
+ kind: string;
413
+ }>>;
414
+ }): boolean;
415
+ /** The one sentence a misplaced step purpose is refused with, at construction and at `validate()`. @internal */
416
+ export declare const stepPurposeRefusal: (key: string, definitionId: string) => string;
417
+ /**
418
+ * A pinned constructor of a given kind. Constraining each method to its own kind makes
419
+ * `.query('x', C.generateText())` a **compile** error rather than a throw — 04 §4a said
420
+ * the method names the kind, and this is that claim actually enforced by the type system
421
+ * instead of by a message at authoring time.
422
+ * @experimental
423
+ */
424
+ export type NodeOf<K extends Kind> = NodeSpec<Descriptor<any, any> & {
425
+ kind: K;
426
+ }>;
427
+ /**
428
+ * What an each iterates. Kept as a closed union rather than `unknown | fn`, because a
429
+ * union with `unknown` collapses to `unknown` and the callback's parameter loses its
430
+ * type — the exact thing this whole change exists to prevent.
431
+ * @experimental
432
+ */
433
+ export type EachOver<Nodes extends Record<string, PortDecl>> = (($: Scope<Nodes>) => DataRef) | DataRef | readonly unknown[];
434
+ /**
435
+ * Node keys accumulate **fully qualified**, exactly as they land in the rows (F21) — so
436
+ * a node declared inside a clause enters the scope as `gather.semantic.embed`, and the
437
+ * scope type expands the dots back into a path (src/scope.ts).
438
+ */
439
+ type Qualify<Prefix extends string, K extends string> = Prefix extends '' ? K : `${Prefix}.${K}`;
440
+ type Add<Nodes extends Record<string, PortDecl>, K extends string, N> = Nodes & {
441
+ [P in K]: OutPortsOf<N>;
442
+ };
443
+ /** Like `Add`, but for a construct whose ports are known directly rather than via a descriptor. */
444
+ type AddPorts<Nodes extends Record<string, PortDecl>, K extends string, P extends PortDecl> = Nodes & {
445
+ [X in K]: P;
446
+ };
447
+ /** Pull the accumulated node map back out of a builder the author handed us. @experimental */
448
+ export type NodesOf<B> = B extends ChainBuilder<infer M, any> ? M : B extends GatherBuilder<infer M, any> ? M : never;
449
+ /**
450
+ * What a clause publishes. Addressable like a node, because it is the only well-defined
451
+ * handle on a construct that ran more than once — "whichever iteration happened to run
452
+ * last" is not a value anyone means.
453
+ * @experimental
454
+ */
455
+ export type BranchPorts = {
456
+ main: string;
457
+ values: string;
458
+ branches: string;
459
+ ok: string;
460
+ };
461
+ /**
462
+ * What a junction publishes (M4, PLAN-turn-order §4.14): the clause ports,
463
+ * and the fired branch's own ports beside them — `$.decide.order`. Open at
464
+ * the type level (any port name reads); `validate()` holds the document to
465
+ * ports every branch's last node actually publishes, with one shape.
466
+ * @experimental
467
+ */
468
+ export type JunctionPorts = BranchPorts & {
469
+ [port: string]: string;
470
+ };
471
+ /** Namespace a fragment's nodes under the include key, at publish and in the type (16 §3a). */
472
+ type Prefixed<K extends string, M> = {
473
+ [P in keyof M & string as `${K}.${P}`]: M[P];
474
+ };
475
+ /** @experimental */
476
+ declare class ChainBuilder<Nodes extends Record<string, PortDecl> = {}, Prefix extends string = ''> {
477
+ protected spec: BuiltSpec;
478
+ protected clauseCtx?: {
479
+ clauseId: string;
480
+ chain: string;
481
+ } | undefined;
482
+ constructor(spec: BuiltSpec, clauseCtx?: {
483
+ clauseId: string;
484
+ chain: string;
485
+ } | undefined);
486
+ /** Resolve the callback form against the nodes declared so far. */
487
+ protected resolve<N>(arg: NodeArg<N, Nodes>): N;
488
+ protected add(kind: Kind, key: string, arg: NodeArg<NodeSpec<any>, Nodes>, opts?: NodeOpts): any;
489
+ protected qualify(key: string): string;
490
+ /** Where a clause declared here sits, so clauses nest exactly as nodes do. */
491
+ protected declareClause(b: Omit<BuiltClause, 'clauseId' | 'clauseChain' | 'position'>): BuiltClause;
492
+ /**
493
+ * A **gather** clause: several chains collected and awaited together (01 §4).
494
+ * `mode` is a setting — by the equivalence law (C8) parallel and sequential
495
+ * are unobservable, which is why the construct is named for what it does
496
+ * (gather) and not for how (was `.async()`).
497
+ */
498
+ gather<Id extends string, R extends GatherBuilder<any, any>>(id: Id, opts: {
499
+ mode?: 'sequential' | 'parallel';
500
+ }, fn: (b: GatherBuilder<Nodes, Qualify<Prefix, Id>>) => R): ChainBuilder<AddPorts<NodesOf<R>, Qualify<Prefix, Id>, BranchPorts>, Prefix>;
501
+ /** An **each** clause: one contained chain, once per item of a list (01 §4). Was `.map()`. */
502
+ each<Id extends string, R extends ChainBuilder<any, any>>(id: Id, opts: {
503
+ over: EachOver<Nodes>;
504
+ max: number;
505
+ mode?: 'sequential' | 'parallel';
506
+ }, fn: (c: ChainBuilder<Nodes & {
507
+ [ITEM]: PortDecl;
508
+ }, `${Qualify<Prefix, Id>}.item`>) => R): ChainBuilder<AddPorts<NodesOf<R>, Qualify<Prefix, Id>, BranchPorts>, Prefix>;
509
+ /**
510
+ * One contained chain, repeated while a declared port stays truthy — bounded by a
511
+ * mandatory `max` (01 §4a).
512
+ *
513
+ * This is the construct that makes tool-calling expressible on the spine. It is **not
514
+ * a back-edge**: like `each`, the repetition lives in the clause's declaration rather
515
+ * than in an edge that points backwards, and the executor already knew how to run a
516
+ * chain more than once. A loop is an each whose iteration count comes from a predicate
517
+ * instead of a list length.
518
+ *
519
+ * Always sequential — each iteration depends on the last, so `mode` would be a lie.
520
+ */
521
+ loop<Id extends string, R extends ChainBuilder<any, any>>(id: Id, opts: {
522
+ repeatWhile: (($: Scope<any>) => DataRef) | DataRef;
523
+ max: number;
524
+ }, fn: (c: ChainBuilder<Nodes, `${Qualify<Prefix, Id>}.item`>) => R): ChainBuilder<AddPorts<NodesOf<R>, Qualify<Prefix, Id>, BranchPorts>, Prefix>;
525
+ /** Internal: the callback resolver, reachable from `loop` after the body is built. */
526
+ resolvePublic<N>(arg: NodeArg<N, any>): N;
527
+ /**
528
+ * A **junction** clause (was `.route()`): branches selected by declared
529
+ * predicates over a value on the spine (20 §10). Any subset fires — one,
530
+ * several, or none — plus an optional `otherwise` that fires exactly when
531
+ * nothing else did. The decision is *data a task computed* (the value the
532
+ * junction is `on`); the branching is declaration; the receipt records
533
+ * every predicate's evaluation, fired and skipped alike. Not a back-edge
534
+ * and not code in the executor — the loop clause's whole argument, applied
535
+ * to fan-out. 01 §4 amended: branching exists as a declared junction; no
536
+ * back-edges.
537
+ *
538
+ * Skipped branches publish `halt('not selected')` results marked
539
+ * `fired: false`; the union's `ok`/`values` read the *fired* branches, so
540
+ * downstream folds see what ran, in declaration order (13 §1).
541
+ */
542
+ junction<Id extends string, R extends JunctionBuilder<any, any>>(id: Id, opts: {
543
+ on: (($: Scope<any>) => DataRef) | DataRef;
544
+ mode?: 'sequential' | 'parallel';
545
+ }, fn: (r: JunctionBuilder<Nodes, Qualify<Prefix, Id>>) => R): ChainBuilder<AddPorts<NodesOf<R>, Qualify<Prefix, Id>, JunctionPorts>, Prefix>;
546
+ query<K extends string, N extends NodeOf<'query'>>(key: K, node: NodeArg<N, Nodes>, opts?: NodeOpts): ChainBuilder<Add<Nodes, Qualify<Prefix, K>, N>, Prefix>;
547
+ task<K extends string, N extends NodeOf<'task'>>(key: K, node: NodeArg<N, Nodes>, opts?: NodeOpts): ChainBuilder<Add<Nodes, Qualify<Prefix, K>, N>, Prefix>;
548
+ oracle<K extends string, N extends NodeOf<'oracle'>>(key: K, node: NodeArg<N, Nodes>, opts?: NodeOpts): ChainBuilder<Add<Nodes, Qualify<Prefix, K>, N>, Prefix>;
549
+ outlet<K extends string, N extends NodeOf<'outlet'>>(key: K, node: NodeArg<N, Nodes>, opts?: NodeOpts): ChainBuilder<Add<Nodes, Qualify<Prefix, K>, N>, Prefix>;
550
+ }
551
+ declare class GatherBuilder<Nodes extends Record<string, PortDecl> = {}, Id extends string = string> {
552
+ private spec;
553
+ private clauseId;
554
+ constructor(spec: BuiltSpec, clauseId: string);
555
+ /**
556
+ * Each chain's nodes accumulate into the clause's type, so by the time `.gather()`
557
+ * returns, the spine's scope contains every node the clause declared — under the
558
+ * qualified key it actually has.
559
+ */
560
+ chain<Name extends string, R extends ChainBuilder<any, any>>(name: Name, fn: (c: ChainBuilder<Nodes, Qualify<Id, Name>>) => R): GatherBuilder<NodesOf<R>, Id>;
561
+ }
562
+ /**
563
+ * The junction clause's own builder: every branch is a named chain *with a
564
+ * declared predicate*, and the two are stated together so a branch without a
565
+ * condition cannot be written at all.
566
+ * @experimental
567
+ */
568
+ export declare class JunctionBuilder<Nodes extends Record<string, PortDecl> = {}, Id extends string = string> {
569
+ private spec;
570
+ private clauseId;
571
+ private clause;
572
+ constructor(spec: BuiltSpec, clauseId: string, clause: BuiltClause);
573
+ /** A branch that fires when its predicate matches the junction's value. */
574
+ when<Name extends string, R extends ChainBuilder<any, any>>(name: Name, predicate: Omit<JunctionPredicate, 'default'>, fn: (c: ChainBuilder<Nodes, Qualify<Id, Name>>) => R): JunctionBuilder<NodesOf<R>, Id>;
575
+ /** The branch that fires exactly when nothing else did. At most one. */
576
+ otherwise<Name extends string, R extends ChainBuilder<any, any>>(name: Name, fn: (c: ChainBuilder<Nodes, Qualify<Id, Name>>) => R): JunctionBuilder<NodesOf<R>, Id>;
577
+ }
578
+ /**
579
+ * Slot-named methods, for the same reason the chain has kind-named ones (04 §4a): the
580
+ * method names the slot, so setting a slot a node never declared is caught by name rather
581
+ * than becoming an override row that silently matches nothing.
582
+ * @experimental
583
+ */
584
+ export declare class PresetBuilder<Nodes extends Record<string, PortDecl> = {}> {
585
+ private preset;
586
+ constructor(preset: BuiltPreset);
587
+ private set;
588
+ /** Node behaviour knobs — retrieval `weight`, `minInclude`, `topK` (12 §2). */
589
+ params(nodeKey: keyof Nodes & string, value: Record<string, unknown>): this;
590
+ /** Authored text fields the node declares. */
591
+ prompts(nodeKey: keyof Nodes & string, value: Record<string, unknown>): this;
592
+ /** A template **and its engine** — the engine travels on the value (src/engines.ts). */
593
+ template(nodeKey: keyof Nodes & string, value: TemplateValue): this;
594
+ /** Generation parameters: a reference to a named config, or field overrides on top. */
595
+ sampling(nodeKey: keyof Nodes & string, value: Record<string, unknown>): this;
596
+ /** Node toggles and the review position. */
597
+ settings(nodeKey: keyof Nodes & string, value: Record<string, unknown>): this;
598
+ }
599
+ /** @experimental */
600
+ export declare class SpecBuilder<Nodes extends Record<string, PortDecl> = {}> extends ChainBuilder<Nodes> {
601
+ private inletDone;
602
+ constructor(rawId: string, meta: SpecMeta);
603
+ query<K extends string, N extends NodeOf<'query'>>(key: K, node: NodeArg<N, Nodes>, opts?: NodeOpts): SpecBuilder<Add<Nodes, K, N>>;
604
+ task<K extends string, N extends NodeOf<'task'>>(key: K, node: NodeArg<N, Nodes>, opts?: NodeOpts): SpecBuilder<Add<Nodes, K, N>>;
605
+ oracle<K extends string, N extends NodeOf<'oracle'>>(key: K, node: NodeArg<N, Nodes>, opts?: NodeOpts): SpecBuilder<Add<Nodes, K, N>>;
606
+ outlet<K extends string, N extends NodeOf<'outlet'>>(key: K, node: NodeArg<N, Nodes>, opts?: NodeOpts): SpecBuilder<Add<Nodes, K, N>>;
607
+ /**
608
+ * A named configuration the spec ships with (12 §3a). Declared **after** the nodes,
609
+ * so the node keys it addresses are the ones that exist — same accumulation the
610
+ * scope uses, so a typo is a compile error rather than a dead override row.
611
+ *
612
+ * ```ts
613
+ * .preset('lore-heavy', { label: 'Lore-heavy' }, p => p
614
+ * .params ('lore', { weight: 0.5, minInclude: 3 })
615
+ * .prompts ('generate', { system: LORE_SYSTEM })
616
+ * .template('prompt', jinja(LORE_ASSEMBLY)))
617
+ * ```
618
+ */
619
+ preset(slug: string, meta: {
620
+ label: I18n;
621
+ description?: I18n;
622
+ default?: boolean;
623
+ owner?: string;
624
+ }, fn: (p: PresetBuilder<Nodes>) => unknown): this;
625
+ /**
626
+ * Exactly one **inlet**, positionally first (01 §2). Enforced here rather than
627
+ * by the validator, so it is a throw at authoring time.
628
+ *
629
+ * The optional third argument is the **usage lock** (24 §4): the session
630
+ * event this inlet answers and the genre it serves. A session-event spec
631
+ * without it does not compile — required for now, and relaxing later
632
+ * (`genre: string[]`, `"*"`) is additive, never breaking. **The lock is the
633
+ * only subscription** (R-4, 09-B B5): `.on()` and `subscribes` were deleted
634
+ * 2026-09-16 — nothing read them at dispatch.
635
+ */
636
+ inlet<K extends string, N extends NodeOf<'inlet'>>(key: K, node: N, binding?: {
637
+ genre: GenreDecl | ExternalRef;
638
+ event: string | SessionEventDecl;
639
+ } | {
640
+ genre: GenreDecl | ExternalRef;
641
+ events: Array<string | SessionEventDecl>;
642
+ }): SpecBuilder<Add<Nodes, K, N>>;
643
+ gather<Id extends string, R extends GatherBuilder<any, any>>(id: Id, opts: {
644
+ mode?: 'sequential' | 'parallel';
645
+ }, fn: (b: GatherBuilder<Nodes, Id>) => R): SpecBuilder<AddPorts<NodesOf<R>, Id, BranchPorts>>;
646
+ each<Id extends string, R extends ChainBuilder<any, any>>(id: Id, opts: {
647
+ over: EachOver<Nodes>;
648
+ max: number;
649
+ mode?: 'sequential' | 'parallel';
650
+ }, fn: (c: ChainBuilder<Nodes & {
651
+ [ITEM]: PortDecl;
652
+ }, `${Id}.item`>) => R): SpecBuilder<AddPorts<NodesOf<R>, Id, BranchPorts>>;
653
+ loop<Id extends string, R extends ChainBuilder<any, any>>(id: Id, opts: {
654
+ repeatWhile: (($: Scope<any>) => DataRef) | DataRef;
655
+ max: number;
656
+ }, fn: (c: ChainBuilder<Nodes, `${Id}.item`>) => R): SpecBuilder<AddPorts<NodesOf<R>, Id, BranchPorts>>;
657
+ junction<Id extends string, R extends JunctionBuilder<any, any>>(id: Id, opts: {
658
+ on: (($: Scope<any>) => DataRef) | DataRef;
659
+ mode?: 'sequential' | 'parallel';
660
+ }, fn: (r: JunctionBuilder<Nodes, Id>) => R): SpecBuilder<AddPorts<NodesOf<R>, Id, JunctionPorts>>;
661
+ /** Compile-time include — expanded here, so rows hold the flat chain (16 §3a). */
662
+ include<K extends string, F extends Fragment<any>>(key: K, fragment: F): SpecBuilder<Nodes & Prefixed<K, F extends Fragment<infer M> ? M : {}>>;
663
+ build(): BuiltSpec;
664
+ }
665
+ /** @public */
666
+ export declare function spec(id: string, meta: SpecMeta): SpecBuilder<{}>;
667
+ /**
668
+ * A fragment carries its node map in its type, so `.include('ctx', contextInfill)` puts
669
+ * `ctx.embed`, `ctx.search`, `ctx.merge` into the including spec's scope — namespaced by
670
+ * the include key in the type exactly as they are namespaced in the rows (16 §3a).
671
+ * @experimental
672
+ */
673
+ export interface Fragment<Nodes extends Record<string, PortDecl> = {}> {
674
+ id: string;
675
+ nodes: BuiltNode[];
676
+ clauses: BuiltClause[];
677
+ /** Phantom — carries the node map. Never populated at runtime. */
678
+ readonly __nodes?: Nodes;
679
+ }
680
+ /** @experimental */
681
+ export declare function fragment<R extends ChainBuilder<any, any>>(id: string, fn: (c: ChainBuilder<{}, ''>) => R): Fragment<NodesOf<R>>;
682
+ export { ChainBuilder };
683
+ //# sourceMappingURL=builder.d.ts.map