@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
package/dist/refs.js ADDED
@@ -0,0 +1,137 @@
1
+ /**
2
+ * References — edges as data (04 §4), and config references (F35).
3
+ *
4
+ * $ref creates a *data* edge and compiles 1:1 to a pipeline_edges row.
5
+ * slot.* creates a *config* reference, which is resolved before execution and is
6
+ * therefore not an edge and creates no dependency in the graph.
7
+ * @experimental
8
+ */
9
+ /** @experimental */
10
+ export function $ref(node, port = 'main') {
11
+ return { __ref: 'data', node, port };
12
+ }
13
+ const addr = (n) => (typeof n === 'object' ? n.node : n);
14
+ const isEnvoyAddress = (n) => typeof n === 'object' && n !== null && typeof n.envoy === 'string';
15
+ /**
16
+ * The address an envoy's config lives at in the resolved config — the
17
+ * synthetic node key `envoy:<key>`. One spelling, shared by the compiler
18
+ * (`resolvedRefs`), the executor (`resolveConfig`'s key list) and the host's
19
+ * projection, so the three cannot disagree about where a mascot's prompt is.
20
+ * @internal
21
+ */
22
+ export const ENVOY_CONFIG_PREFIX = 'envoy:';
23
+ /** @experimental */
24
+ export const envoyConfigKey = (key) => `${ENVOY_CONFIG_PREFIX}${key}`;
25
+ /** @internal */
26
+ export const isEnvoyConfigKey = (key) => key.startsWith(ENVOY_CONFIG_PREFIX);
27
+ /** @public */
28
+ export const slot = {
29
+ connection: (ofNode) => ({
30
+ __ref: 'slot',
31
+ slot: 'connection',
32
+ ofNode: addr(ofNode),
33
+ }),
34
+ sampling: (ofNode) => ({
35
+ __ref: 'slot',
36
+ slot: 'sampling',
37
+ ofNode: addr(ofNode),
38
+ }),
39
+ /**
40
+ * With a target, the slot is *shared*: the node reads the target's authored
41
+ * prompts and declares none of its own to configure. One authored text, one
42
+ * place to edit it — three nodes that each demanded the same system prompt
43
+ * is the defect this exists to close (13 §12 finding i).
44
+ */
45
+ prompts: (of) => isEnvoyAddress(of)
46
+ ? { __ref: 'slot', slot: 'prompts', ofEnvoy: of.envoy }
47
+ : {
48
+ __ref: 'slot',
49
+ slot: 'prompts',
50
+ ofNode: addr(of),
51
+ },
52
+ template: () => ({ __ref: 'slot', slot: 'template' }),
53
+ /**
54
+ * With a target, the slot's **shared** fields resolve at the target — and
55
+ * only those (R-7 P2, refined 2026-09-16; `FieldDecl.shared`).
56
+ *
57
+ * A definition marks the `params` fields several nodes of one spec hold in
58
+ * common — the lore lanes' seven scan knobs, the embed pair's switch —
59
+ * `shared: true`; a spec then names ONE owner and the other nodes reference
60
+ * it here. A referencing node's *unmarked* fields stay its own and resolve
61
+ * at its own address through the same reference: each lore lane's share
62
+ * of the window is that lane's, while the scan depth they run on is one
63
+ * number. One reference, both halves, and the panel draws the same line.
64
+ *
65
+ * ⚠ It used to read the whole slot at the target, and its docblock argued
66
+ * for the ranker as the owner of "every query's minimums and weights". That
67
+ * is the per-source map on the ranker 16 §5a rejected; per-source intent
68
+ * lives on the source now (R-7 P5) and travels as candidate metadata, so
69
+ * nothing needs to read the ranker's params from a query any more.
70
+ */
71
+ params: (ofNode) => ({
72
+ __ref: 'slot',
73
+ slot: 'params',
74
+ ofNode: addr(ofNode),
75
+ }),
76
+ /**
77
+ * With a target, the slot is *shared* — the same reading as `prompts`. A node
78
+ * that consumes another's rendered variables reads that node's selections
79
+ * rather than declaring a parallel set nobody would think to keep in step.
80
+ */
81
+ variables: (ofNode) => ({
82
+ __ref: 'slot',
83
+ slot: 'variables',
84
+ ofNode: addr(ofNode),
85
+ }),
86
+ /** Explicit oracle reference — always unambiguous. */
87
+ oracleRef: (node) => ({
88
+ __ref: 'slot',
89
+ slot: 'connection',
90
+ ofNode: addr(node),
91
+ }),
92
+ connectionOf: (node) => ({
93
+ __ref: 'slot',
94
+ slot: 'connection',
95
+ ofNode: addr(node),
96
+ }),
97
+ samplingOf: (node) => ({
98
+ __ref: 'slot',
99
+ slot: 'sampling',
100
+ ofNode: addr(node),
101
+ }),
102
+ /**
103
+ * Resolves at publish to the first oracle reachable forward. Compiles to the
104
+ * explicit form, so nothing implicit survives into rows (16 §5b-i).
105
+ */
106
+ downstreamOracle: () => ({
107
+ __ref: 'slot',
108
+ slot: 'connection',
109
+ resolveDownstreamOracle: true,
110
+ }),
111
+ };
112
+ /** @experimental */
113
+ export const isDataRef = (v) => typeof v === 'object' && v !== null && v.__ref === 'data';
114
+ /** @internal */
115
+ export const isSlotRef = (v) => typeof v === 'object' && v !== null && v.__ref === 'slot';
116
+ /** Walk a config object and collect every data ref, with the key path it sat at. @experimental */
117
+ export function collectDataRefs(config, path = []) {
118
+ if (isDataRef(config))
119
+ return [{ path, ref: config }];
120
+ if (Array.isArray(config))
121
+ return config.flatMap((v, i) => collectDataRefs(v, [...path, String(i)]));
122
+ if (config && typeof config === 'object' && !isSlotRef(config)) {
123
+ return Object.entries(config).flatMap(([k, v]) => collectDataRefs(v, [...path, k]));
124
+ }
125
+ return [];
126
+ }
127
+ /** @experimental */
128
+ export function collectSlotRefs(config) {
129
+ if (isSlotRef(config))
130
+ return [config];
131
+ if (Array.isArray(config))
132
+ return config.flatMap(collectSlotRefs);
133
+ if (config && typeof config === 'object')
134
+ return Object.values(config).flatMap(collectSlotRefs);
135
+ return [];
136
+ }
137
+ //# sourceMappingURL=refs.js.map
@@ -0,0 +1,230 @@
1
+ /**
2
+ * The pipeline type registry — the ruling on 13 §10c.
3
+ *
4
+ * ## Where a type's shape comes from, at three different moments
5
+ *
6
+ * The question underneath "schema sources" is which artefact is authoritative, and the
7
+ * honest answer is that a different one is authoritative at each moment. Writing that
8
+ * down is the ruling; pretending there is a single source is what would go wrong.
9
+ *
10
+ * | moment | source of truth | why |
11
+ * |---|---|---|
12
+ * | authoring | the `Descriptor` in code | the author is *defining* the type; nothing else knows it yet |
13
+ * | compiling a spec | generated `/contracts` | frozen per release, so a pin resolves the same way forever (04 §2) |
14
+ * | installing | **the registry row** | the only one core can read without executing the plugin |
15
+ *
16
+ * The third row is the whole point. Core must decide whether a plugin is installable
17
+ * before it ever runs the plugin's code — F6 means core imports documents, never
18
+ * authoring JS — so install-time validation reads two things that are both plain data:
19
+ * the plugin's **manifest** (types summarized, permissions compiled from usage) and its
20
+ * **documents** (nodes pinned by `definitionId@version`, edges carrying the shapes they were
21
+ * compiled against).
22
+ *
23
+ * ## What that makes checkable
24
+ *
25
+ * The interesting failure is not a plugin that pins a type nobody has — that one is
26
+ * obvious and fails loudly. It is a plugin **built against a different release**, where
27
+ * every id still resolves but a port now produces a different shape. The document
28
+ * records the shape each edge was compiled against, so comparing it to the registry
29
+ * catches exactly that, and catches it at install rather than mid-run.
30
+ */
31
+ import { type DefinitionPolicy, type Descriptor, type EntryShape, type ScriptPointDecl, type SlotDecl } from './descriptors.js';
32
+ import type { MediaCapability } from './media.js';
33
+ import { type ScriptKindDecl } from './scripts.js';
34
+ import type { SettingsSchema } from './settings.js';
35
+ import type { SpecDocument } from './document.js';
36
+ /**
37
+ * A `pipeline_definition_registry` row (02 §3), as data.
38
+ *
39
+ * Two halves, and the row carries both (plans/31 V6): every **contract**
40
+ * field of the `Descriptor` (`DESCRIPTOR_CONTRACT_KEYS`) — so a row read back
41
+ * hashes to the `content_hash` it was written under, and a plugin can be
42
+ * judged against rows without being executed (F6) — and the **policy** half,
43
+ * on `policy`, `i18n` and `public`, which the hash never sees and a sync
44
+ * refreshes in place.
45
+ * @internal
46
+ */
47
+ export interface RegistryEntry {
48
+ id: string;
49
+ version: number;
50
+ kind: string;
51
+ /**
52
+ * Failing is tolerated (see `Descriptor.optional`). Carried into the row
53
+ * because it is part of the contract a pin freezes: the ports do not move
54
+ * when it flips, but every spec pinning the version changes behaviour on
55
+ * failure.
56
+ */
57
+ optional?: boolean;
58
+ /**
59
+ * The four other contract flags and the three contract declarations that
60
+ * had no column until plans/31 V6 — carried for the same reason `optional`
61
+ * is: each is in the hash, and a hashed field the row cannot carry is a
62
+ * row that cannot reproduce its own pointer. `review.fields` is also what
63
+ * a `transport: process` outlet's gate form is read from.
64
+ */
65
+ declaresRandomness?: boolean;
66
+ earlyExit?: boolean;
67
+ liveRow?: boolean;
68
+ review?: {
69
+ fields: readonly string[];
70
+ };
71
+ /** Connection kind for providers (== produced shape) — `Descriptor.shape`. */
72
+ shape?: string;
73
+ media?: MediaCapability;
74
+ /**
75
+ * Interior script points (18 §4e) — carried into the row for the same
76
+ * reason `slots` is: the panel offers one chain option per point and must
77
+ * render it without loading the plugin (F6). Keys and `accepts` are
78
+ * contract and hash; labels are display text, stripped like `i18n`
79
+ * everywhere else. Always the full shape — the projection copies through
80
+ * `scriptPointsOf`, and `register()` refuses a bare string or a point
81
+ * without `accepts`, so a row never carries one.
82
+ */
83
+ scriptPoints?: ScriptPointDecl[];
84
+ /**
85
+ * The chat-shape contract (19 §1) — present only on mode-bearing input
86
+ * types. Carried for the reason `slots` is: the mode picker and the chat
87
+ * settings render from rows (F6), never from a loaded spec. Hashed —
88
+ * widening a capability changes what existing sessions legally contain —
89
+ * with any embedded `i18n`/`description` stripped like everywhere.
90
+ */
91
+ sessionShape?: unknown;
92
+ ports: {
93
+ in: Record<string, string | undefined>;
94
+ out: Record<string, string | undefined>;
95
+ };
96
+ /**
97
+ * The **declarations**, not their names.
98
+ *
99
+ * This carried `string[]` until 0.6.0, and that quietly broke the promise the
100
+ * column exists to keep. 12 §2 says slot declarations live in the type descriptor
101
+ * *"so a plugin Provider's prompt fields render next to core's automatically, with
102
+ * no UI work"*, and the table above says the registry row is what core reads
103
+ * **without executing the plugin**. A name list satisfies neither: a form
104
+ * generator given `['prompts', 'params']` knows a form exists and nothing about
105
+ * what is in it, so it has to fall back to the in-process descriptor map — which
106
+ * exists for core types, does not exist for a `transport: 'process'` plugin type,
107
+ * and is the exact thing F6 forbids reaching for.
108
+ *
109
+ * Storing the declaration makes the pipeline view (05 §0a) and the lens view
110
+ * (05 §3) generated from rows, which is what lets a plugin's sliders appear beside
111
+ * core's with nothing authored twice.
112
+ *
113
+ * One of them the author did not write: `settings` (R-9), which the
114
+ * projection derives from `optional` / `effects` / `reviewDefault` so the
115
+ * panel finds the switch and the gate here like any slot. It is left out
116
+ * of the content hash — `authoredSlots` — for the reason that file gives.
117
+ */
118
+ slots: Record<string, SlotDecl>;
119
+ /**
120
+ * The entry-row contract (Part 1), minus its `fields` — present only on
121
+ * entry types. Carried for the reason `slots` is: the ranker, the assembler
122
+ * and the constraint projection all read the declaration from **rows**, and
123
+ * the row is the only source that exists for a type this process never
124
+ * loaded (F6).
125
+ *
126
+ * Hashed whole. Roles decide where a row competes, how it sorts, who may
127
+ * see it and where it renders, so moving one changes what an untouched
128
+ * install does — `@N+1`, deliberately.
129
+ */
130
+ entryShape?: Omit<EntryShape, 'fields'>;
131
+ /**
132
+ * The declared schema of the type-specific half of a row — `entryShape.fields`,
133
+ * living in the column that already exists for a declared schema rather
134
+ * than riding inside the blob above.
135
+ *
136
+ * Split out because the readers differ: the boot step that projects CHECK
137
+ * constraints and indexes wants a schema, generically, from a column it can
138
+ * name — the same shape the form renderer already reads everywhere else.
139
+ * Hashed for the reason the constraint projection makes unavoidable: a
140
+ * schema change *is* a constraint change.
141
+ */
142
+ configSchema?: SettingsSchema;
143
+ /**
144
+ * What the type calls itself — the name a screen shows for it.
145
+ *
146
+ * Outside the content hash, like every other piece of display text: naming
147
+ * a node better is not a contract change. Carried in the row for the same
148
+ * reason `slots` is — the pipeline builder renders from rows and never
149
+ * loads the plugin (F6), so a name only the descriptor knows is a name no
150
+ * plugin's node can have.
151
+ */
152
+ i18n?: unknown;
153
+ /**
154
+ * Script types only: how a chain of this operation treats what its links
155
+ * return — `transform` folds into the flowing bag, `verdict` is consumed by
156
+ * the hook and reduced (18 §5).
157
+ *
158
+ * Hashed, and it has to be. Flipping it moves no port and keeps every
159
+ * attachment compiling, while turning "each link rewrites the text" into
160
+ * "the earliest answer wins" — the same shape of silent behaviour change
161
+ * `optional` was, and the reason that one is hashed.
162
+ */
163
+ semantics?: string;
164
+ effects?: string;
165
+ causesEvent?: string;
166
+ /** The in-port whose literal names the event a write causes. */
167
+ causesEventFrom?: string;
168
+ /** Inlet only: the event payloads it reads (R33) — hashed with the contract. */
169
+ payloads?: string[];
170
+ public?: boolean;
171
+ /**
172
+ * The policy half (plans/31 V6): `provisional` (plans/29 R-2 — the row
173
+ * also reads it as `status: 'provisional'`), `reviewDefault`,
174
+ * `timeoutMs`, `timeoutKind`, `toggleable`. Never hashed; a sync writes
175
+ * it on insert and refreshes it in place when it moves, so flipping a
176
+ * flag reaches every install without a pointer move. Absent on a script
177
+ * kind's row, which declares none of them.
178
+ */
179
+ policy?: DefinitionPolicy;
180
+ /** Null for core types; the plugin slug for plugin types (12 §3b). */
181
+ owner?: string;
182
+ /** Which SP release seeded this row. */
183
+ release?: string;
184
+ }
185
+ /** Project descriptors into registry rows — how core seeds and refreshes the table. @experimental */
186
+ export declare function snapshotRegistry(types: Array<Descriptor | ScriptKindDecl>, meta?: {
187
+ owner?: string;
188
+ release?: string;
189
+ }): RegistryEntry[];
190
+ /** @experimental */
191
+ export type InstallCode = 'E_UNKNOWN_TYPE' | 'E_SHAPE_DRIFT' | 'E_REDECLARES_CORE' | 'E_PRIVATE_TYPE' | 'E_MISSING_BINDING' | 'E_IN_PROCESS_HOOK' | 'W_NEWER_VERSION';
192
+ /** @experimental */
193
+ export interface InstallFinding {
194
+ severity: 'error' | 'warning';
195
+ code: InstallCode;
196
+ message: string;
197
+ /** What the admin or author does about it. Never omitted (15 §1.3). */
198
+ fix: string;
199
+ where?: string;
200
+ }
201
+ /** @experimental */
202
+ export interface InstallInput {
203
+ /** The plugin's own declared types, as summarized in its manifest. */
204
+ declares: Array<{
205
+ id: string;
206
+ binding?: string;
207
+ ports?: RegistryEntry['ports'];
208
+ runtime?: string;
209
+ }>;
210
+ /** The pipeline documents shipped beside the manifest. */
211
+ documents: SpecDocument[];
212
+ /** The installing instance's registry. */
213
+ registry: RegistryEntry[];
214
+ /** Type ids the plugin enumerates hooks for — a declared type with no binding cannot run. */
215
+ bound?: string[];
216
+ owner?: string;
217
+ }
218
+ /**
219
+ * Decide whether a plugin is installable, from data alone.
220
+ *
221
+ * Never loads the plugin. Every finding names what to do, because the reader is an admin
222
+ * who did not write the plugin and cannot be expected to infer the fix from the symptom.
223
+ * @internal
224
+ */
225
+ export declare function checkInstall(input: InstallInput): InstallFinding[];
226
+ /** @internal */
227
+ export declare const installable: (f: InstallFinding[]) => boolean;
228
+ /** @internal */
229
+ export declare function renderInstall(findings: InstallFinding[]): string;
230
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1,273 @@
1
+ /**
2
+ * The pipeline type registry — the ruling on 13 §10c.
3
+ *
4
+ * ## Where a type's shape comes from, at three different moments
5
+ *
6
+ * The question underneath "schema sources" is which artefact is authoritative, and the
7
+ * honest answer is that a different one is authoritative at each moment. Writing that
8
+ * down is the ruling; pretending there is a single source is what would go wrong.
9
+ *
10
+ * | moment | source of truth | why |
11
+ * |---|---|---|
12
+ * | authoring | the `Descriptor` in code | the author is *defining* the type; nothing else knows it yet |
13
+ * | compiling a spec | generated `/contracts` | frozen per release, so a pin resolves the same way forever (04 §2) |
14
+ * | installing | **the registry row** | the only one core can read without executing the plugin |
15
+ *
16
+ * The third row is the whole point. Core must decide whether a plugin is installable
17
+ * before it ever runs the plugin's code — F6 means core imports documents, never
18
+ * authoring JS — so install-time validation reads two things that are both plain data:
19
+ * the plugin's **manifest** (types summarized, permissions compiled from usage) and its
20
+ * **documents** (nodes pinned by `definitionId@version`, edges carrying the shapes they were
21
+ * compiled against).
22
+ *
23
+ * ## What that makes checkable
24
+ *
25
+ * The interesting failure is not a plugin that pins a type nobody has — that one is
26
+ * obvious and fails loudly. It is a plugin **built against a different release**, where
27
+ * every id still resolves but a port now produces a different shape. The document
28
+ * records the shape each edge was compiled against, so comparing it to the registry
29
+ * catches exactly that, and catches it at install rather than mid-run.
30
+ */
31
+ import { pluginRuleRef } from './pluginRuleRef.js';
32
+ import { definitionPolicy, scriptPointsOf, } from './descriptors.js';
33
+ import { isScriptKindId } from './scripts.js';
34
+ import { settingsSlotFor } from './settingsSlot.js';
35
+ const versionOf = (id) => Number(/@(\d+)$/.exec(id)?.[1] ?? 1);
36
+ const bare = (id) => id.replace(/@\d+$/, '');
37
+ const shapeId = (s) => typeof s === 'string' ? s : (s?.id ?? undefined);
38
+ /** Project descriptors into registry rows — how core seeds and refreshes the table. @experimental */
39
+ export function snapshotRegistry(types, meta = {}) {
40
+ return types.map((t) => isScriptKindId(t.id) ? scriptEntry(t, meta) : nodeEntry(t, meta));
41
+ }
42
+ /**
43
+ * A script type as a registry row.
44
+ *
45
+ * ⚠ Projected through the *same* function as node types, deliberately. 18 §2
46
+ * puts scripts "under the same sync, conflict-refusal and re-projection rules
47
+ * as node types", and the cheapest way to keep that true is for there to be one
48
+ * projection, one hash and one sync rather than a parallel set that drifts.
49
+ *
50
+ * `blastRadius` rides inside `i18n` rather than earning a column, because that
51
+ * is what it is: display text, stripped from the hash, read from the row by a
52
+ * panel that must not load the plugin to render a badge (F6). `semantics` does
53
+ * earn one — it is contract.
54
+ */
55
+ function scriptEntry(d, meta) {
56
+ return {
57
+ id: bare(d.id),
58
+ version: versionOf(d.id),
59
+ kind: 'script',
60
+ semantics: d.semantics,
61
+ ports: { in: { ...d.ports.in }, out: { ...d.ports.out } },
62
+ // No slots: a script type is a contract, not a configurable surface.
63
+ // What is configurable about a script is the script — its source and its
64
+ // declared variable I/O — which lives on its row, not on its type.
65
+ slots: {},
66
+ i18n: { ...(d.i18n ?? {}), blastRadius: d.blastRadius },
67
+ owner: meta.owner,
68
+ release: meta.release,
69
+ };
70
+ }
71
+ function nodeEntry(d, meta) {
72
+ // The substrate's slot, after the author's so an author's own key order
73
+ // is what the panel walks. `register` has already refused an authored
74
+ // `settings`, so the spread cannot be shadowing one.
75
+ const settings = settingsSlotFor(d);
76
+ return {
77
+ id: bare(d.id),
78
+ version: versionOf(d.id),
79
+ kind: d.kind,
80
+ ports: {
81
+ in: Object.fromEntries(Object.entries(d.ports?.in ?? {}).map(([k, v]) => [k, shapeId(v)])),
82
+ out: Object.fromEntries(Object.entries(d.ports?.out ?? {}).map(([k, v]) => [k, shapeId(v)])),
83
+ },
84
+ slots: { ...(d.slots ?? {}), ...(settings ? { settings } : {}) },
85
+ /**
86
+ * What the type calls itself.
87
+ *
88
+ * ⚠ Not projected until 0.6, so the column existed and was always NULL
89
+ * — and every reader that wanted a name invented one from the id
90
+ * instead. The pipeline builder rendered
91
+ * `core:query/graph-context@1` as "Graph context" while its
92
+ * declaration said "Graph relationships", and nothing anywhere showed
93
+ * the second.
94
+ *
95
+ * Excluded from the content hash, like every other piece of display
96
+ * text, which is exactly why it has to be *refreshed* rather than only
97
+ * written on insert: a renamed type never takes the conflict path.
98
+ */
99
+ i18n: d.i18n,
100
+ /**
101
+ * Entry types only, and split in two on the way into the row: the
102
+ * facets to `entryShape`, the declared `fields` schema to
103
+ * `configSchema`. `undefined` on every node type, and `JSON.stringify`
104
+ * drops undefined keys, so no node type's hash moves by this being
105
+ * here.
106
+ */
107
+ entryShape: d.entryShape ? entryFacets(d.entryShape) : undefined,
108
+ configSchema: d.entryShape?.fields,
109
+ effects: d.effects,
110
+ causesEvent: d.causesEvent,
111
+ causesEventFrom: d.causesEventFrom,
112
+ payloads: d.payloads?.length ? [...d.payloads] : undefined,
113
+ public: d.public,
114
+ optional: d.optional,
115
+ declaresRandomness: d.declaresRandomness,
116
+ earlyExit: d.earlyExit,
117
+ liveRow: d.liveRow,
118
+ review: d.review,
119
+ shape: d.shape,
120
+ media: d.media,
121
+ // The policy half, whole — what the row's `status` and the panel's
122
+ // defaults are read from, and what the hash never sees.
123
+ policy: definitionPolicy(d),
124
+ // Copied on the way in, so a row is always the full shape the panel
125
+ // renders (`register()` refused anything less).
126
+ scriptPoints: d.scriptPoints ? scriptPointsOf(d) : undefined,
127
+ sessionShape: d.sessionShape,
128
+ owner: meta.owner,
129
+ release: meta.release,
130
+ };
131
+ }
132
+ /** The entry contract without the half that has its own column. */
133
+ function entryFacets(shape) {
134
+ const { fields: _fields, ...facets } = shape;
135
+ return facets;
136
+ }
137
+ /**
138
+ * Decide whether a plugin is installable, from data alone.
139
+ *
140
+ * Never loads the plugin. Every finding names what to do, because the reader is an admin
141
+ * who did not write the plugin and cannot be expected to infer the fix from the symptom.
142
+ * @internal
143
+ */
144
+ export function checkInstall(input) {
145
+ const findings = [];
146
+ const byId = new Map(input.registry.map((r) => [`${r.id}@${r.version}`, r]));
147
+ const latest = new Map();
148
+ for (const r of input.registry)
149
+ latest.set(r.id, Math.max(latest.get(r.id) ?? 0, r.version));
150
+ // 1. A plugin may not redeclare a type it does not own.
151
+ for (const d of input.declares) {
152
+ const existing = byId.get(d.id.includes('@') ? d.id : `${d.id}@1`);
153
+ if (existing && existing.owner !== input.owner)
154
+ findings.push({
155
+ severity: 'error',
156
+ code: 'E_REDECLARES_CORE',
157
+ where: d.id,
158
+ message: `${d.id} is already registered${existing.owner ? ` by '${existing.owner}'` : ' by core'}`,
159
+ fix: `publish it under your own namespace instead. Ownership is what lets an update ` +
160
+ `replace the right rows — two owners for one id means an update cannot tell which ` +
161
+ `rows are its own (12 §3b).`,
162
+ });
163
+ }
164
+ const declared = new Set(input.declares.map((d) => (d.id.includes('@') ? d.id : `${d.id}@1`)));
165
+ for (const doc of input.documents) {
166
+ for (const n of doc.nodes) {
167
+ const pin = `${n.definitionId}@${n.definitionVersion}`;
168
+ const entry = byId.get(pin);
169
+ // 2. A pin that resolves to nothing.
170
+ if (!entry && !declared.has(pin)) {
171
+ const known = latest.get(n.definitionId);
172
+ findings.push({
173
+ severity: 'error',
174
+ code: 'E_UNKNOWN_TYPE',
175
+ where: `${doc.id} · ${n.key}`,
176
+ message: `pins ${pin}, which this pub does not have`,
177
+ fix: known
178
+ ? `this pub has ${n.definitionId}@${known}. Pins are frozen on purpose, so the plugin has to be rebuilt against this release rather than silently re-pinned here.`
179
+ : `no version of ${n.definitionId} is registered. It comes from another plugin — install that one first, or the pipeline has a dependency its manifest does not declare.`,
180
+ });
181
+ continue;
182
+ }
183
+ // 3. A private type belonging to someone else.
184
+ if (entry && entry.owner && entry.owner !== input.owner && !entry.public)
185
+ findings.push({
186
+ severity: 'error',
187
+ code: 'E_PRIVATE_TYPE',
188
+ where: `${doc.id} · ${n.key}`,
189
+ message: `pins ${pin}, which is private to '${entry.owner}'`,
190
+ fix: `ask '${entry.owner}' to make its handler public — handler(definition, fn, { visibility: 'public' }). ` +
191
+ `A private node is one its owner may change without warning, so using it across a plugin boundary ` +
192
+ `would break on their next release.` +
193
+ pluginRuleRef('private-nodes'),
194
+ });
195
+ // 4. Informational: a newer version exists. The pin still runs — that is what
196
+ // pinning is for — but an author reading the install log should know.
197
+ const newest = latest.get(n.definitionId);
198
+ if (entry && newest && newest > n.definitionVersion)
199
+ findings.push({
200
+ severity: 'warning',
201
+ code: 'W_NEWER_VERSION',
202
+ where: `${doc.id} · ${n.key}`,
203
+ message: `pins ${pin}; this pub also has @${newest}`,
204
+ fix: `nothing is required — the pin resolves and runs. Upgrade deliberately if you want the newer behaviour.`,
205
+ });
206
+ }
207
+ // 5. The one that matters: built against a different release. Every id resolves,
208
+ // but a port produces a different shape than the document was compiled against.
209
+ for (const e of doc.edges) {
210
+ if (!e.shape)
211
+ continue;
212
+ const from = doc.nodes.find((n) => n.key === e.from);
213
+ if (!from)
214
+ continue;
215
+ const entry = byId.get(`${from.definitionId}@${from.definitionVersion}`);
216
+ const now = entry?.ports.out[e.fromPort];
217
+ if (entry && now && now !== e.shape)
218
+ findings.push({
219
+ severity: 'error',
220
+ code: 'E_SHAPE_DRIFT',
221
+ where: `${doc.id} · ${e.from}.${e.fromPort} → ${e.to}.${e.toPort}`,
222
+ message: `compiled against ${e.shape}; this pub publishes ${now}`,
223
+ fix: `rebuild the plugin against this release. This is the failure a version number ` +
224
+ `alone would not have caught: the id resolved, so nothing looked wrong until the ` +
225
+ `value reached a node that could not read it.`,
226
+ });
227
+ }
228
+ }
229
+ // 5a. A hook that wants to run inside Serene Pub's process.
230
+ //
231
+ // Refused from the manifest, before anything is loaded — which is the only
232
+ // moment it *can* be refused, since by the time the code is running it is
233
+ // already in the host's process. An in-process hook cannot be stopped: a
234
+ // runaway loop or a blocking call takes the whole application down with it,
235
+ // and F36's promise that every invocation is bounded stops being enforceable
236
+ // (13 §7h).
237
+ for (const d of input.declares)
238
+ if (d.runtime && d.runtime !== 'process')
239
+ findings.push({
240
+ severity: 'error',
241
+ code: 'E_IN_PROCESS_HOOK',
242
+ where: d.id,
243
+ message: `declares runtime '${d.runtime}'; extension hooks run in their own process`,
244
+ fix: `rebuild with the current SDK, which no longer offers an in-process runtime. ` +
245
+ `A hook inside the host's process cannot be timed out or killed, so one bad ` +
246
+ `loop stops Serene Pub rather than one node.`,
247
+ });
248
+ // 6. A declared type nobody bound is a node the executor cannot invoke.
249
+ if (input.bound) {
250
+ const bound = new Set(input.bound);
251
+ for (const d of input.declares)
252
+ if (!bound.has(d.id))
253
+ findings.push({
254
+ severity: 'error',
255
+ code: 'E_MISSING_BINDING',
256
+ where: d.id,
257
+ message: `declared as a type but no hook implements it`,
258
+ fix: `add a handler() for ${d.id}, or drop the declaration. A definition with no handler is a node a user can add to a pipeline that then fails at run time.`,
259
+ });
260
+ }
261
+ return findings;
262
+ }
263
+ /** @internal */
264
+ export const installable = (f) => !f.some((x) => x.severity === 'error');
265
+ /** @internal */
266
+ export function renderInstall(findings) {
267
+ if (!findings.length)
268
+ return 'installable';
269
+ return findings
270
+ .map((f) => `${f.severity === 'error' ? '✗' : '⚠'} ${f.where ?? ''} [${f.code}] ${f.message}\n → ${f.fix}`)
271
+ .join('\n');
272
+ }
273
+ //# sourceMappingURL=registry.js.map