@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,234 @@
1
+ /**
2
+ * Annex fields — every key an owner keeps in the session annex, declared once
3
+ * (owner-approved 2026-09-26; generalised the same day by the owner ruling
4
+ * "one annex declaration per owner").
5
+ *
6
+ * An owner's **annex declaration** is the list of its annex fields: each key
7
+ * it uses, the shape its value must have, who may see it and — optionally —
8
+ * who may set it. It is the single source of truth for that owner's annex
9
+ * document:
10
+ *
11
+ * - a `set-session-annex` step may write only declared keys (refused by name
12
+ * at `validate()` and the package pass when the keys are literal, and by
13
+ * the host at the write always);
14
+ * - the audience stored with a value is the declaration's `see`;
15
+ * - a value is checked against the declared `shape` at every write;
16
+ * - `annexSchemaOf(owner)` is the shape, for a template to type
17
+ * `annex.<owner>.<key>`.
18
+ *
19
+ * `act` present makes the field **settable**: the host offers it as one
20
+ * action (`<owner>:annex#<key>`) and serves every press with ONE core
21
+ * pipeline (`core:spec/set-annex-field`), writing through the same annex
22
+ * write as `set-session-annex`. `act` absent is **pipeline-written only**: no
23
+ * action, and a press is refused.
24
+ *
25
+ * ```ts
26
+ * defineExtension({
27
+ * slug: 'acme.dice',
28
+ * // …
29
+ * annexFields: [
30
+ * annexField({ key: 'last-roll', shape: { type: 'integer', min: 1, max: 20 }, see: ['person'], act: ['participant'] }),
31
+ * annexField({ key: 'streak', shape: { type: 'integer' } }), // pipelines write it; nobody sees it
32
+ * ],
33
+ * })
34
+ * // in the widget:
35
+ * invoke(annexFieldAction('acme.dice', 'last-roll'), { payload: { value: 17 } })
36
+ * ```
37
+ *
38
+ * Declared on the extension (`defineExtension({ annexFields })`): every
39
+ * session the plugin is on, or — with `genre` — that genre's sessions only.
40
+ * The **owner** is the declaring package's slug, never named by the
41
+ * declaration, so a field can only ever describe its own package's document.
42
+ * Core's own keys are core-catalog's `CORE_ANNEX_FIELDS`, under `core`.
43
+ *
44
+ * Never credentials or personal data (R61): a shape holding a `secret`
45
+ * anywhere is refused at the declaration.
46
+ *
47
+ * @experimental 🚧 provisional — the vocabulary (annex field, annex
48
+ * declaration, settable, the `<owner>:annex#<key>` identity) is new with this
49
+ * module.
50
+ */
51
+ import { type FieldDecl, type SettingsSchema } from './settings.js';
52
+ import { type I18n } from './i18n.js';
53
+ import type { VarField } from './template.js';
54
+ /** An annex field's key: a lowercase kebab token, the second half of its action identity. @experimental */
55
+ export declare const ANNEX_FIELD_KEY: RegExp;
56
+ /**
57
+ * The one core pipeline every annex field's press runs. Contributes no
58
+ * action of its own: only the host's door, having judged the press, runs it.
59
+ * @experimental
60
+ */
61
+ export declare const ANNEX_FIELD_SPEC_ID = "core:spec/set-annex-field";
62
+ /** What an annex field's action identity carries as its spec slug: `<owner>` + this. @experimental */
63
+ export declare const ANNEX_FIELD_SLUG_SUFFIX = ":annex";
64
+ /** One annex field, as a package declares it. @experimental */
65
+ export interface AnnexFieldDecl {
66
+ readonly __decl: 'annex-field';
67
+ /** The annex key the value is stored under, in the owner's document. */
68
+ readonly key: string;
69
+ /** What the value must be — the settings vocabulary's `FieldDecl`, checked by `checkValues`. */
70
+ readonly shape: FieldDecl;
71
+ /**
72
+ * Who may SEE the stored value besides pipelines (R57) — a data
73
+ * audience (participant references). `[]` (the default) is
74
+ * pipelines only (R59): a widget cannot read back a value nobody may see.
75
+ */
76
+ readonly see: readonly string[];
77
+ /**
78
+ * Who may SET it through its ready-made action (`<owner>:annex#<key>`) —
79
+ * the action's `act` audience. Absent: pipeline-written only — no action
80
+ * is offered and a press is refused.
81
+ */
82
+ readonly act?: readonly string[];
83
+ /** The genre id whose sessions offer it; absent is every session the package is on. */
84
+ readonly genre?: string;
85
+ /** What a listing calls the action. Default: the key. */
86
+ readonly label?: I18n;
87
+ readonly description?: I18n;
88
+ }
89
+ /** What `annexField()` takes. @experimental */
90
+ export type AnnexFieldInput = {
91
+ key: string;
92
+ shape: FieldDecl;
93
+ see?: readonly string[];
94
+ act?: readonly string[];
95
+ /** Only this genre's sessions — the genre value (or its id). */
96
+ genre?: {
97
+ readonly id: string;
98
+ } | string;
99
+ label?: I18n;
100
+ description?: I18n;
101
+ };
102
+ /**
103
+ * Why this is not an annex field, one sentence per fault — `[]` when it is.
104
+ * The host runs it again over a stored manifest, which an older SDK built.
105
+ * @experimental
106
+ */
107
+ export declare function annexFieldFindings(raw: unknown, at?: string): string[];
108
+ /**
109
+ * Declare an annex field. Throws with every fault at once — an author sees
110
+ * them while writing, never at a press.
111
+ * @experimental
112
+ */
113
+ export declare function annexField(d: AnnexFieldInput): AnnexFieldDecl;
114
+ /** Faults in a list of fields: each one's, and a key declared twice. @experimental */
115
+ export declare function annexFieldListFindings(raw: unknown, at?: string): string[];
116
+ /**
117
+ * The action identity a widget invokes to set a field:
118
+ * `annexFieldAction('acme.dice', 'last-roll')` → `acme.dice:annex#last-roll`.
119
+ * @experimental
120
+ */
121
+ export declare const annexFieldAction: (owner: string, key: string) => string;
122
+ /** Is this spec slug an annex field's (`<owner>:annex`)? @experimental */
123
+ export declare const isAnnexFieldSlug: (specSlug: string) => boolean;
124
+ /** Take an annex field's identity apart; null for any other identity. @experimental */
125
+ export declare function parseAnnexFieldAction(id: unknown): {
126
+ owner: string;
127
+ key: string;
128
+ } | null;
129
+ /**
130
+ * Why this press's payload cannot be stored under the field, as the
131
+ * validator's sentence — or null when it can. The payload is `{ value }`.
132
+ * @experimental
133
+ */
134
+ export declare function annexFieldValueRefusal(field: Pick<AnnexFieldDecl, 'key' | 'shape'>, payload: unknown): string | null;
135
+ /**
136
+ * Register an owner's annex declaration — its whole list of annex fields,
137
+ * replacing whatever was registered for it. Checked as a list (a key declared
138
+ * twice is refused); a stored entry an older SDK built is normalised through
139
+ * `annexField()`. Throws with every fault at once. The host's and
140
+ * core-catalog's to call: a package declares on `defineExtension({ annexFields })`.
141
+ * @internal
142
+ */
143
+ export declare function declareAnnex(owner: string, fields: readonly unknown[]): readonly AnnexFieldDecl[];
144
+ /** Forget an owner's declaration (uninstall, reinstall). @internal */
145
+ export declare function _withdrawAnnex(owner: string): void;
146
+ /** Every declaration, for a test to put back what it found. @internal */
147
+ export declare function _clearAnnexDeclarations(): void;
148
+ /** Every owner with a declaration registered in this process, in registration order. @experimental */
149
+ export declare const annexOwners: () => string[];
150
+ /**
151
+ * An owner's annex declaration as registered in this process, or undefined
152
+ * when the owner is unknown here. @experimental
153
+ */
154
+ export declare const annexDeclarationOf: (owner: string) => readonly AnnexFieldDecl[] | undefined;
155
+ /**
156
+ * The fields of a declaration in force for a session of `genre`: every
157
+ * unscoped field and the ones scoped to that genre. With no genre — a
158
+ * document judged before it knows its session — every field, whatever genre
159
+ * it is scoped to. Pure. @experimental
160
+ */
161
+ export declare function annexFieldsInGenre(fields: readonly AnnexFieldDecl[], genre?: string): AnnexFieldDecl[];
162
+ /** Whether a declared field may be set by a person, through its ready-made action. @experimental */
163
+ export declare const isSettableAnnexField: (f: Pick<AnnexFieldDecl, 'act'>) => boolean;
164
+ /**
165
+ * An owner's annex schema — key → declared shape — for a session of `genre`
166
+ * (or every genre, with none). Undefined when the owner is unknown here; `{}`
167
+ * when it declares nothing. What a typed template reads `annex.<owner>.<key>`
168
+ * against (typed-templates §1b, P6). @experimental
169
+ */
170
+ export declare function annexSchemaOf(owner: string, genre?: string): SettingsSchema | undefined;
171
+ /**
172
+ * The same schema as a template variable: an `object` whose members are the
173
+ * declared keys, each optional (a key is absent until something writes it).
174
+ * Undefined when the owner is unknown here. @experimental
175
+ */
176
+ export declare function annexVarFieldOf(owner: string, genre?: string): VarField | undefined;
177
+ /** Whose annex a spec writes by default: the namespace of its id, before the colon. @experimental */
178
+ export declare const annexOwnerOfSpec: (specId: string | undefined) => string;
179
+ /**
180
+ * The keys a `set-session-annex` step writes, read off its config: the
181
+ * members of a `value` object (literal or assembled from refs). Null when the
182
+ * step wires `value` whole, so its keys are known only at the write. `[]`
183
+ * when it writes nothing. Pure. @experimental
184
+ */
185
+ export declare function annexWriteKeysOf(config: Record<string, unknown> | undefined, edgesIntoValue?: readonly string[]): string[] | null;
186
+ /** One write to an owner's annex document, as a judge sees it. @experimental */
187
+ export interface AnnexWrite {
188
+ owner: string;
189
+ /** The keys written. */
190
+ keys: readonly string[];
191
+ /** The session's genre; undefined judges against every genre's fields. */
192
+ genre?: string;
193
+ /** The values, when known (the host's write): each is held to its declared shape. */
194
+ values?: Record<string, unknown>;
195
+ }
196
+ /**
197
+ * Why this write is refused under the owner's declaration — one sentence per
198
+ * fault, `[]` when it may be stored. The one judge `validate()`, the package
199
+ * pass and the host's write all quote:
200
+ *
201
+ * - a key the owner does not declare (for this genre) is refused by name;
202
+ * - a value is held to its declared shape (the validator's sentence).
203
+ *
204
+ * `fields` undefined is an owner that declares nothing: every key is refused.
205
+ * @experimental
206
+ */
207
+ export declare function annexWriteRefusals(fields: readonly AnnexFieldDecl[] | undefined, w: AnnexWrite): string[];
208
+ /**
209
+ * The `set-session-annex` steps of one pipeline that a declaration refuses,
210
+ * judged where the keys are literal — the package pass's and `validate()`'s
211
+ * shared reading. `fieldsOf(owner)` answers undefined for an owner it cannot
212
+ * judge (another package's, unknown here): those steps are left to the host.
213
+ * @internal
214
+ */
215
+ export declare function annexStepFindings(spec: {
216
+ id: string;
217
+ input?: {
218
+ genre?: string;
219
+ };
220
+ nodes: ReadonlyArray<{
221
+ key: string;
222
+ definitionId: string;
223
+ config: Record<string, unknown>;
224
+ }>;
225
+ edges?: ReadonlyArray<{
226
+ to: string;
227
+ toPort: string;
228
+ }>;
229
+ }, fieldsOf: (owner: string) => readonly AnnexFieldDecl[] | undefined): Array<{
230
+ nodeKey: string;
231
+ owner: string;
232
+ refusals: string[];
233
+ }>;
234
+ //# sourceMappingURL=annexFields.d.ts.map
@@ -0,0 +1,413 @@
1
+ /**
2
+ * Annex fields — every key an owner keeps in the session annex, declared once
3
+ * (owner-approved 2026-09-26; generalised the same day by the owner ruling
4
+ * "one annex declaration per owner").
5
+ *
6
+ * An owner's **annex declaration** is the list of its annex fields: each key
7
+ * it uses, the shape its value must have, who may see it and — optionally —
8
+ * who may set it. It is the single source of truth for that owner's annex
9
+ * document:
10
+ *
11
+ * - a `set-session-annex` step may write only declared keys (refused by name
12
+ * at `validate()` and the package pass when the keys are literal, and by
13
+ * the host at the write always);
14
+ * - the audience stored with a value is the declaration's `see`;
15
+ * - a value is checked against the declared `shape` at every write;
16
+ * - `annexSchemaOf(owner)` is the shape, for a template to type
17
+ * `annex.<owner>.<key>`.
18
+ *
19
+ * `act` present makes the field **settable**: the host offers it as one
20
+ * action (`<owner>:annex#<key>`) and serves every press with ONE core
21
+ * pipeline (`core:spec/set-annex-field`), writing through the same annex
22
+ * write as `set-session-annex`. `act` absent is **pipeline-written only**: no
23
+ * action, and a press is refused.
24
+ *
25
+ * ```ts
26
+ * defineExtension({
27
+ * slug: 'acme.dice',
28
+ * // …
29
+ * annexFields: [
30
+ * annexField({ key: 'last-roll', shape: { type: 'integer', min: 1, max: 20 }, see: ['person'], act: ['participant'] }),
31
+ * annexField({ key: 'streak', shape: { type: 'integer' } }), // pipelines write it; nobody sees it
32
+ * ],
33
+ * })
34
+ * // in the widget:
35
+ * invoke(annexFieldAction('acme.dice', 'last-roll'), { payload: { value: 17 } })
36
+ * ```
37
+ *
38
+ * Declared on the extension (`defineExtension({ annexFields })`): every
39
+ * session the plugin is on, or — with `genre` — that genre's sessions only.
40
+ * The **owner** is the declaring package's slug, never named by the
41
+ * declaration, so a field can only ever describe its own package's document.
42
+ * Core's own keys are core-catalog's `CORE_ANNEX_FIELDS`, under `core`.
43
+ *
44
+ * Never credentials or personal data (R61): a shape holding a `secret`
45
+ * anywhere is refused at the declaration.
46
+ *
47
+ * @experimental 🚧 provisional — the vocabulary (annex field, annex
48
+ * declaration, settable, the `<owner>:annex#<key>` identity) is new with this
49
+ * module.
50
+ */
51
+ import { dataAudienceFindings, isParticipantRef } from './participants.js';
52
+ import { checkSchema, checkValues } from './settings.js';
53
+ import { i18nFindings } from './i18n.js';
54
+ import { isDataRef } from './refs.js';
55
+ /** An annex field's key: a lowercase kebab token, the second half of its action identity. @experimental */
56
+ export const ANNEX_FIELD_KEY = /^[a-z][a-z0-9-]*$/;
57
+ /**
58
+ * The one core pipeline every annex field's press runs. Contributes no
59
+ * action of its own: only the host's door, having judged the press, runs it.
60
+ * @experimental
61
+ */
62
+ export const ANNEX_FIELD_SPEC_ID = 'core:spec/set-annex-field';
63
+ /** What an annex field's action identity carries as its spec slug: `<owner>` + this. @experimental */
64
+ export const ANNEX_FIELD_SLUG_SUFFIX = ':annex';
65
+ /** References that cannot press anything: the model's context, a message, a run. @internal */
66
+ const NOT_A_PRESSER = new Set(['ai', 'item', 'run-owner']);
67
+ /** Does this shape hold a `secret` anywhere — at the top, in a list's item, in an object's member? @internal */
68
+ function holdsSecret(shape) {
69
+ if (!shape || typeof shape !== 'object')
70
+ return false;
71
+ if (shape.type === 'secret')
72
+ return true;
73
+ if (shape.type === 'list')
74
+ return holdsSecret(shape.item);
75
+ if (shape.type === 'object')
76
+ return Object.values(shape.fields ?? {}).some((f) => holdsSecret(f));
77
+ return false;
78
+ }
79
+ /**
80
+ * Why this is not an annex field, one sentence per fault — `[]` when it is.
81
+ * The host runs it again over a stored manifest, which an older SDK built.
82
+ * @experimental
83
+ */
84
+ export function annexFieldFindings(raw, at = 'annexFields') {
85
+ if (!raw || typeof raw !== 'object')
86
+ return [`${at}: an annex field is annexField({ key, shape, see?, act? })`];
87
+ const f = raw;
88
+ const where = `${at}[${typeof f.key === 'string' ? f.key : '?'}]`;
89
+ const out = [];
90
+ if (typeof f.key !== 'string' || !ANNEX_FIELD_KEY.test(f.key))
91
+ out.push(`${where}: 'key' is a lowercase kebab token (${ANNEX_FIELD_KEY.source}) — the field sits in ` +
92
+ `your own package's annex document, so it never names an owner`);
93
+ const shape = f.shape;
94
+ if (!shape || typeof shape !== 'object' || typeof shape.type !== 'string')
95
+ out.push(`${where}: 'shape' is a field declaration — { type: 'integer', min: 1, max: 20 }`);
96
+ else if (holdsSecret(shape))
97
+ out.push(`${where}: the shape holds a secret — the annex never keeps credentials or personal data ` +
98
+ `(R61); keep a secret in plugin settings`);
99
+ else
100
+ for (const finding of checkSchema({ [String(f.key)]: shape }))
101
+ if (finding.severity === 'error')
102
+ out.push(`${where}: ${finding.message} — ${finding.fix}`);
103
+ const see = dataAudienceFindings(f.see);
104
+ if (see)
105
+ out.push(`${where}.see: ${see}`);
106
+ if (f.act !== undefined) {
107
+ if (!Array.isArray(f.act) || !f.act.length)
108
+ out.push(`${where}.act: a non-empty list of participant references — who may set the value`);
109
+ else
110
+ for (const r of f.act) {
111
+ if (!isParticipantRef(r))
112
+ out.push(`${where}.act: '${String(r)}' is not a participant reference`);
113
+ else if (NOT_A_PRESSER.has(String(r).trim()))
114
+ out.push(`${where}.act: '${String(r)}' cannot press anything — name who sets the value`);
115
+ }
116
+ }
117
+ if (f.genre !== undefined) {
118
+ const g = typeof f.genre === 'string' ? f.genre : f.genre?.id;
119
+ if (typeof g !== 'string' || !/^[a-z0-9.-]+:genre\/[a-z0-9.-]+/.test(g))
120
+ out.push(`${where}.genre: a genre — the value genre() returned, or its id ('acme.dice:genre/table')`);
121
+ }
122
+ out.push(...i18nFindings(f.label, `${where}.label`));
123
+ out.push(...i18nFindings(f.description, `${where}.description`));
124
+ return out;
125
+ }
126
+ /**
127
+ * Declare an annex field. Throws with every fault at once — an author sees
128
+ * them while writing, never at a press.
129
+ * @experimental
130
+ */
131
+ export function annexField(d) {
132
+ const problems = annexFieldFindings(d, 'annexField');
133
+ if (problems.length)
134
+ throw new Error(problems.join('\n'));
135
+ return Object.freeze({
136
+ __decl: 'annex-field',
137
+ key: d.key,
138
+ shape: d.shape,
139
+ see: Object.freeze([...(d.see ?? [])]),
140
+ ...(d.act !== undefined ? { act: Object.freeze([...d.act]) } : {}),
141
+ ...(d.genre !== undefined ? { genre: typeof d.genre === 'string' ? d.genre : d.genre.id } : {}),
142
+ ...(d.label !== undefined ? { label: d.label } : {}),
143
+ ...(d.description !== undefined ? { description: d.description } : {}),
144
+ });
145
+ }
146
+ /** Faults in a list of fields: each one's, and a key declared twice. @experimental */
147
+ export function annexFieldListFindings(raw, at = 'annexFields') {
148
+ if (raw === undefined)
149
+ return [];
150
+ if (!Array.isArray(raw))
151
+ return [`${at}: a list of annexField(…) values`];
152
+ const out = [];
153
+ const seen = new Set();
154
+ for (const f of raw) {
155
+ out.push(...annexFieldFindings(f, at));
156
+ const key = f?.key;
157
+ if (typeof key === 'string') {
158
+ if (seen.has(key))
159
+ out.push(`${at}: '${key}' is declared twice — a key has one shape and one audience`);
160
+ seen.add(key);
161
+ }
162
+ }
163
+ return out;
164
+ }
165
+ /**
166
+ * The action identity a widget invokes to set a field:
167
+ * `annexFieldAction('acme.dice', 'last-roll')` → `acme.dice:annex#last-roll`.
168
+ * @experimental
169
+ */
170
+ export const annexFieldAction = (owner, key) => `${owner}${ANNEX_FIELD_SLUG_SUFFIX}#${key}`;
171
+ /** Is this spec slug an annex field's (`<owner>:annex`)? @experimental */
172
+ export const isAnnexFieldSlug = (specSlug) => specSlug.endsWith(ANNEX_FIELD_SLUG_SUFFIX) && specSlug.length > ANNEX_FIELD_SLUG_SUFFIX.length;
173
+ /** Take an annex field's identity apart; null for any other identity. @experimental */
174
+ export function parseAnnexFieldAction(id) {
175
+ if (typeof id !== 'string')
176
+ return null;
177
+ const i = id.lastIndexOf('#');
178
+ if (i <= 0)
179
+ return null;
180
+ const slug = id.slice(0, i);
181
+ const key = id.slice(i + 1);
182
+ if (!isAnnexFieldSlug(slug) || !ANNEX_FIELD_KEY.test(key))
183
+ return null;
184
+ return { owner: slug.slice(0, -ANNEX_FIELD_SLUG_SUFFIX.length), key };
185
+ }
186
+ /**
187
+ * Why this press's payload cannot be stored under the field, as the
188
+ * validator's sentence — or null when it can. The payload is `{ value }`.
189
+ * @experimental
190
+ */
191
+ export function annexFieldValueRefusal(field, payload) {
192
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload) || !('value' in payload))
193
+ return `'${field.key}' is set with { payload: { value } }`;
194
+ const value = payload.value;
195
+ if (value === undefined)
196
+ return `'${field.key}' is set with { payload: { value } }`;
197
+ if (holdsSecret(field.shape))
198
+ return `'${field.key}' holds a secret, which the annex never keeps (R61)`;
199
+ const faults = checkValues({ [field.key]: field.shape }, { [field.key]: value }).filter((f) => f.severity === 'error');
200
+ return faults.length ? faults.map((f) => f.message).join('; ') : null;
201
+ }
202
+ // ── The annex declaration: one per owner (owner ruling 2026-09-26) ──────────
203
+ /**
204
+ * The owners whose annex declaration this process knows — core's (registered
205
+ * by core-catalog) and each installed package's (registered by the host from
206
+ * its stored manifest). An owner absent here is **unknown**, which is not the
207
+ * same as declaring nothing: `validate()` cannot judge an unknown owner's
208
+ * keys and leaves them to the package pass and the host.
209
+ * @internal
210
+ */
211
+ const declarations = new Map();
212
+ /**
213
+ * Register an owner's annex declaration — its whole list of annex fields,
214
+ * replacing whatever was registered for it. Checked as a list (a key declared
215
+ * twice is refused); a stored entry an older SDK built is normalised through
216
+ * `annexField()`. Throws with every fault at once. The host's and
217
+ * core-catalog's to call: a package declares on `defineExtension({ annexFields })`.
218
+ * @internal
219
+ */
220
+ export function declareAnnex(owner, fields) {
221
+ if (typeof owner !== 'string' || !owner.trim() || owner.includes('#'))
222
+ throw new Error(`declareAnnex: '${String(owner)}' is not an owner — a package slug, or 'core'`);
223
+ const faults = annexFieldListFindings(fields, `${owner}.annexFields`);
224
+ if (faults.length)
225
+ throw new Error(faults.join('\n'));
226
+ const list = Object.freeze(fields.map((f) => annexField(f)));
227
+ declarations.set(owner, list);
228
+ return list;
229
+ }
230
+ /** Forget an owner's declaration (uninstall, reinstall). @internal */
231
+ export function _withdrawAnnex(owner) {
232
+ declarations.delete(owner);
233
+ }
234
+ /** Every declaration, for a test to put back what it found. @internal */
235
+ export function _clearAnnexDeclarations() {
236
+ declarations.clear();
237
+ }
238
+ /** Every owner with a declaration registered in this process, in registration order. @experimental */
239
+ export const annexOwners = () => [...declarations.keys()];
240
+ /**
241
+ * An owner's annex declaration as registered in this process, or undefined
242
+ * when the owner is unknown here. @experimental
243
+ */
244
+ export const annexDeclarationOf = (owner) => declarations.get(owner);
245
+ /**
246
+ * The fields of a declaration in force for a session of `genre`: every
247
+ * unscoped field and the ones scoped to that genre. With no genre — a
248
+ * document judged before it knows its session — every field, whatever genre
249
+ * it is scoped to. Pure. @experimental
250
+ */
251
+ export function annexFieldsInGenre(fields, genre) {
252
+ return fields.filter((f) => f.genre === undefined || genre === undefined || f.genre === genre);
253
+ }
254
+ /** Whether a declared field may be set by a person, through its ready-made action. @experimental */
255
+ export const isSettableAnnexField = (f) => !!f.act?.length;
256
+ /**
257
+ * An owner's annex schema — key → declared shape — for a session of `genre`
258
+ * (or every genre, with none). Undefined when the owner is unknown here; `{}`
259
+ * when it declares nothing. What a typed template reads `annex.<owner>.<key>`
260
+ * against (typed-templates §1b, P6). @experimental
261
+ */
262
+ export function annexSchemaOf(owner, genre) {
263
+ const fields = declarations.get(owner);
264
+ if (!fields)
265
+ return undefined;
266
+ return Object.fromEntries(annexFieldsInGenre(fields, genre).map((f) => [f.key, f.shape]));
267
+ }
268
+ /**
269
+ * The same schema as a template variable: an `object` whose members are the
270
+ * declared keys, each optional (a key is absent until something writes it).
271
+ * Undefined when the owner is unknown here. @experimental
272
+ */
273
+ export function annexVarFieldOf(owner, genre) {
274
+ const schema = annexSchemaOf(owner, genre);
275
+ if (!schema)
276
+ return undefined;
277
+ return {
278
+ type: 'object',
279
+ fields: Object.fromEntries(Object.entries(schema).map(([k, d]) => [k, { ...varFieldOfDecl(d), optional: true }])),
280
+ };
281
+ }
282
+ /** A settings field declaration read as a template variable. @internal */
283
+ function varFieldOfDecl(d) {
284
+ const described = (v) => d.description !== undefined ? { ...v, description: d.description } : v;
285
+ switch (d.type) {
286
+ case 'integer':
287
+ case 'number':
288
+ return described({ type: 'number' });
289
+ case 'boolean':
290
+ return described({ type: 'boolean' });
291
+ case 'string[]':
292
+ return described({ type: 'list', of: { type: 'string' } });
293
+ case 'list':
294
+ return described({ type: 'list', of: d.item ? varFieldOfDecl(d.item) : { type: 'string' } });
295
+ case 'object':
296
+ return described({
297
+ type: 'object',
298
+ fields: Object.fromEntries(Object.entries(d.fields ?? {}).map(([k, m]) => [
299
+ k,
300
+ m.required ? varFieldOfDecl(m) : { ...varFieldOfDecl(m), optional: true },
301
+ ])),
302
+ });
303
+ case 'share':
304
+ case 'perMember':
305
+ case 'strengths':
306
+ return described({ type: 'record', of: { type: 'number' } });
307
+ default:
308
+ return described({ type: 'string' });
309
+ }
310
+ }
311
+ /** Whose annex a spec writes by default: the namespace of its id, before the colon. @experimental */
312
+ export const annexOwnerOfSpec = (specId) => {
313
+ if (!specId)
314
+ return 'core';
315
+ const at = specId.indexOf(':');
316
+ return at > 0 ? specId.slice(0, at) : specId;
317
+ };
318
+ /**
319
+ * The keys a `set-session-annex` step writes, read off its config: the
320
+ * members of a `value` object (literal or assembled from refs). Null when the
321
+ * step wires `value` whole, so its keys are known only at the write. `[]`
322
+ * when it writes nothing. Pure. @experimental
323
+ */
324
+ export function annexWriteKeysOf(config, edgesIntoValue = []) {
325
+ if (edgesIntoValue.includes('value'))
326
+ return null;
327
+ const value = config?.value;
328
+ const fromEdges = edgesIntoValue.filter((p) => p.startsWith('value.')).map((p) => p.split('.')[1]);
329
+ if (value === undefined)
330
+ return [...new Set(fromEdges)];
331
+ if (isDataRef(value) || !value || typeof value !== 'object' || Array.isArray(value))
332
+ return null;
333
+ return [...new Set([...Object.keys(value), ...fromEdges])];
334
+ }
335
+ /**
336
+ * Why this write is refused under the owner's declaration — one sentence per
337
+ * fault, `[]` when it may be stored. The one judge `validate()`, the package
338
+ * pass and the host's write all quote:
339
+ *
340
+ * - a key the owner does not declare (for this genre) is refused by name;
341
+ * - a value is held to its declared shape (the validator's sentence).
342
+ *
343
+ * `fields` undefined is an owner that declares nothing: every key is refused.
344
+ * @experimental
345
+ */
346
+ export function annexWriteRefusals(fields, w) {
347
+ const out = [];
348
+ const inForce = annexFieldsInGenre(fields ?? [], w.genre);
349
+ for (const key of w.keys) {
350
+ const decl = inForce.find((f) => f.key === key);
351
+ if (!decl) {
352
+ const elsewhere = (fields ?? []).find((f) => f.key === key);
353
+ out.push(`'${key}' is not a key '${w.owner}' declares in its annex` +
354
+ (elsewhere?.genre ? ` for this genre (it is declared for '${elsewhere.genre}')` : '') +
355
+ ` — declare it once, with annexField({ key: '${key}', shape, see }) on the owner's annexFields`);
356
+ continue;
357
+ }
358
+ if (w.values && Object.hasOwn(w.values, key)) {
359
+ const value = w.values[key];
360
+ if (value !== null && value !== undefined) {
361
+ const fault = annexFieldValueRefusal(decl, { value });
362
+ if (fault)
363
+ out.push(fault);
364
+ }
365
+ }
366
+ }
367
+ return out;
368
+ }
369
+ /**
370
+ * The `set-session-annex` steps of one pipeline that a declaration refuses,
371
+ * judged where the keys are literal — the package pass's and `validate()`'s
372
+ * shared reading. `fieldsOf(owner)` answers undefined for an owner it cannot
373
+ * judge (another package's, unknown here): those steps are left to the host.
374
+ * @internal
375
+ */
376
+ export function annexStepFindings(spec, fieldsOf) {
377
+ const out = [];
378
+ const specOwner = annexOwnerOfSpec(spec.id);
379
+ for (const n of spec.nodes) {
380
+ if (n.definitionId !== 'core:outlet/set-session-annex')
381
+ continue;
382
+ const params = (n.config?.params ?? {});
383
+ const named = typeof params.owner === 'string' && params.owner.trim() ? params.owner.trim() : null;
384
+ const owner = named && params.sharedAnnex === true ? named : specOwner;
385
+ const fields = fieldsOf(owner);
386
+ if (fields === undefined)
387
+ continue;
388
+ const into = (spec.edges ?? []).filter((e) => e.to === n.key).map((e) => e.toPort);
389
+ const keys = annexWriteKeysOf(n.config, into.filter((p) => p === 'value' || p.startsWith('value.')));
390
+ const refusals = annexWriteRefusals(fields, {
391
+ owner,
392
+ keys: keys ?? [],
393
+ genre: spec.input?.genre,
394
+ values: keys && n.config?.value && typeof n.config.value === 'object' && !isDataRef(n.config.value)
395
+ ? Object.fromEntries(Object.entries(n.config.value).filter(([, v]) => !collectsRef(v)))
396
+ : undefined,
397
+ });
398
+ if (refusals.length)
399
+ out.push({ nodeKey: n.key, owner, refusals });
400
+ }
401
+ return out;
402
+ }
403
+ /** Whether a literal holds a data ref somewhere (then its value is known only at run time). @internal */
404
+ function collectsRef(v) {
405
+ if (isDataRef(v))
406
+ return true;
407
+ if (Array.isArray(v))
408
+ return v.some(collectsRef);
409
+ if (v && typeof v === 'object')
410
+ return Object.values(v).some(collectsRef);
411
+ return false;
412
+ }
413
+ //# sourceMappingURL=annexFields.js.map