@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/sheets.js ADDED
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Attribute sheets — a named, ordered bundle of attribute slots.
3
+ *
4
+ * A slot says what one value is; a sheet says which values a thing has, and in
5
+ * what order they are read. *Adventure* is `hp`, `stamina`, `mood`, `trust`,
6
+ * `location`, `time-of-day`, `weather` — declared once, named by a genre,
7
+ * attached to an owner, and the same seven in the same order everywhere they
8
+ * appear. Owners hold sheets; the vocabulary of an owner is the union of the
9
+ * genre's sheets and the sheets down its chain, deduped by id.
10
+ *
11
+ * ## Why this is a registry of its own, beside the slots
12
+ *
13
+ * The two answer different questions. `attributes.ts` answers *may this value
14
+ * be stored?* and everything in it is about one value — bounds, options, what
15
+ * the model reads. This answers *what does this thing have?* and carries
16
+ * nothing about any one value beyond the three things naming it on a sheet
17
+ * decides. Folded into one registry, a single `get` would return two kinds of
18
+ * thing and a single `retire` would mean two different things to the rows
19
+ * underneath. The id grammar, the reserved owners and the origin rule are
20
+ * shared — imported from there, not restated here, so there is one answer to
21
+ * "who may claim this namespace" rather than two that agree today.
22
+ *
23
+ * ## Order is the declaration
24
+ *
25
+ * `slots` is a list and not a set. It is the order a panel draws, the order a
26
+ * state block renders to the model, and the order rules are evaluated in.
27
+ * Re-ordering a sheet is therefore a change to behaviour, inside the hash like
28
+ * any other, which is why the union a genre computes preserves the order rather
29
+ * than sorting it.
30
+ *
31
+ * ⚠ **Not a layout sheet.** §26 uses *sheet* for what a side zone becomes below
32
+ * `roomy`, and *More sheet* for the mobile overflow; those are places on a
33
+ * screen. Prose says the qualified word — *attribute sheet* — exactly as it
34
+ * does for an attribute slot, and the exported API says it too.
35
+ *
36
+ * ⚠ Never an *attachment* (that is a message part) and never a *template*
37
+ * (taken three times over already).
38
+ */
39
+ import { i18nFindings } from './i18n.js';
40
+ import { refuseUnlessIdentical } from './hash.js';
41
+ import { checkSlotValue, getAttributeSlot, isReservedAttributeOwner, resolveSlotConfig, slotOwner, } from './attributes.js';
42
+ const SHEET_ID = /^[a-z0-9]+(?:[.-][a-z0-9]+)*:sheet\/[a-z0-9]+(?:-[a-z0-9]+)*@\d+$/;
43
+ /** @experimental */
44
+ export function assertSheetId(id) {
45
+ if (!SHEET_ID.test(id))
46
+ throw new Error(`'${id}' is not a valid attribute sheet id. Use 'owner:sheet/name@N' — ` +
47
+ `'core:sheet/adventure@1'. The id is what an owner holds to say it carries this ` +
48
+ `bundle; the name a person reads lives in the declaration.`);
49
+ }
50
+ /**
51
+ * 🚧 The owners a sheet entry puts its slot on: the entry's own narrowing, or
52
+ * the declaration's `appliesTo` when it states none. The one reader, so a host
53
+ * and a widget cannot disagree about whether a character carries it.
54
+ * @experimental
55
+ */
56
+ export const sheetSlotAppliesTo = (entry, decl) => entry.appliesTo ? decl.appliesTo.filter((o) => entry.appliesTo.includes(o)) : decl.appliesTo;
57
+ const registry = new Map();
58
+ /**
59
+ * Display text this registry carries outside `i18n`/`description`.
60
+ *
61
+ * `label` only, and for once there is no model-facing counterpart to keep out:
62
+ * a sheet ships no prose to a prompt. What the model reads is each slot's own
63
+ * `descriptor`, hashed in that slot's declaration where it belongs.
64
+ * @experimental
65
+ */
66
+ export const SHEET_DISPLAY_KEYS = { display: ['label'] };
67
+ const crossOriginRefusal = (id, held) => held === 'code'
68
+ ? `'${id}' is declared in code by the package that owns it, so an authored sheet may ` +
69
+ `not claim it. Author yours under your own namespace instead.`
70
+ : `'${id}' is already held by a sheet somebody authored here. Code claiming it would ` +
71
+ `silently change what every owner carrying it has.`;
72
+ /** One way in, two origins — the split is the one `register` explains in attributes.ts. */
73
+ function register(id, rawProps, origin, authorUserId) {
74
+ assertSheetId(id);
75
+ // The display text (R-20): refused where an author writes code; on a
76
+ // stored row it is dropped with a warning, on the terms attributes.ts gives.
77
+ const props = origin === 'code' ? assertDisplayText(id, rawProps) : withDisplayTextTolerated(id, rawProps);
78
+ checkSheetDeclaration(id, props);
79
+ const decl = Object.freeze({
80
+ ...props,
81
+ id,
82
+ slots: Object.freeze([...props.slots]),
83
+ origin,
84
+ ...(authorUserId === undefined ? {} : { authorUserId }),
85
+ });
86
+ const existing = registry.get(id);
87
+ if (existing) {
88
+ if (existing.origin !== origin)
89
+ throw new Error(crossOriginRefusal(id, existing.origin));
90
+ if (origin === 'code')
91
+ refuseUnlessIdentical(existing, decl, `duplicate attribute sheet id: ${id}`, SHEET_DISPLAY_KEYS);
92
+ }
93
+ registry.set(id, decl);
94
+ return decl;
95
+ }
96
+ /**
97
+ * Declare an attribute sheet in code.
98
+ *
99
+ * Written **below** the slots it gathers, and that is not a style note: the
100
+ * slots have to be in the registry already, because a sheet naming one nothing
101
+ * declares is a vocabulary that validates against nothing.
102
+ * @experimental
103
+ */
104
+ export function defineAttributeSheet(id, props) {
105
+ return register(id, props, 'code');
106
+ }
107
+ /** The plugin-facing door — same registration, minus the ability to claim core's namespace. @experimental */
108
+ export function definePluginAttributeSheet(pluginId, id, props) {
109
+ if (id.startsWith('core:'))
110
+ throw new Error(`plugin '${pluginId}' may not declare '${id}': the 'core:' namespace is reserved. ` +
111
+ `Publish it under your own namespace — a sheet two parties can define is one ` +
112
+ `where what a character has depends on load order.`);
113
+ return defineAttributeSheet(id, props);
114
+ }
115
+ /** The person-facing door, on the same reserved-owner terms as `defineStoredAttributeSlot`. @experimental */
116
+ export function defineStoredAttributeSheet(id, props, meta) {
117
+ assertSheetId(id);
118
+ const owner = slotOwner(id);
119
+ if (isReservedAttributeOwner(owner))
120
+ throw new Error(`'${id}' is authored under the reserved owner '${owner}'. 'core' and every installed ` +
121
+ `plugin id are reserved: a stored sheet sharing one would be redefined the next ` +
122
+ `time that package loaded. Author it under your own namespace.`);
123
+ return register(id, props, 'stored', meta.userId);
124
+ }
125
+ /** @experimental */
126
+ export const getAttributeSheet = (id) => registry.get(id);
127
+ /** @experimental */
128
+ export const attributeSheets = () => [...registry.values()];
129
+ /** @experimental */
130
+ export function _clearAttributeSheets() {
131
+ registry.clear();
132
+ }
133
+ /**
134
+ * Withdraw a package's sheet declaration — the sheet half of
135
+ * `_withdrawAttributeSlot`, on the same terms.
136
+ * @internal
137
+ */
138
+ export function _withdrawAttributeSheet(id) {
139
+ const decl = registry.get(id);
140
+ if (!decl || decl.origin !== 'code' || id.startsWith('core:'))
141
+ return false;
142
+ return registry.delete(id);
143
+ }
144
+ /**
145
+ * Retire a stored sheet: offered nowhere new, kept everywhere it already is.
146
+ *
147
+ * `stored` only, for the reason a slot is — a code sheet arrives and leaves
148
+ * with its package, and retiring one by hand would leave the registry saying
149
+ * something the installed code contradicts on the next boot.
150
+ * @experimental
151
+ */
152
+ export function retireAttributeSheet(id) {
153
+ const decl = registry.get(id);
154
+ if (!decl)
155
+ throw new Error(`cannot retire '${id}': no sheet is declared under that id. Check the id, and that ` +
156
+ `the row was loaded into the registry.`);
157
+ if (decl.origin !== 'stored')
158
+ throw new Error(`'${id}' is declared in code, and code declarations are never retired by hand. ` +
159
+ `Uninstall or upgrade the package that declares it; every value stays where it ` +
160
+ `is either way. Only a sheet somebody authored here can be retired.`);
161
+ const next = Object.freeze({ ...decl, retired: true });
162
+ registry.set(id, next);
163
+ return next;
164
+ }
165
+ /** The reverse of `retireAttributeSheet`, with the same `stored`-only rule. @experimental */
166
+ export function reviveAttributeSheet(id) {
167
+ const decl = registry.get(id);
168
+ if (!decl)
169
+ throw new Error(`cannot revive '${id}': no sheet is declared under that id. Check the id, and that ` +
170
+ `the row was loaded into the registry.`);
171
+ if (decl.origin !== 'stored')
172
+ throw new Error(`'${id}' is declared in code and was never retired by hand, so there is nothing ` +
173
+ `to revive. Only a sheet somebody authored here moves between retired and live.`);
174
+ const { retired: _wasRetired, ...rest } = decl;
175
+ const next = Object.freeze(rest);
176
+ registry.set(id, next);
177
+ return next;
178
+ }
179
+ /**
180
+ * The display-text findings of one sheet declaration (R-20): a sheet is
181
+ * offered by its `label`, so the label is required; the `description` is what
182
+ * a person reads under the offer. Run by the code door here and by the host's
183
+ * **write** door for an authored sheet, never by a reload.
184
+ * @experimental
185
+ */
186
+ export function attributeSheetDisplayFindings(id, props) {
187
+ return [
188
+ ...i18nFindings(props.label, `${id} label`, { required: true }),
189
+ ...i18nFindings(props.description, `${id} description`),
190
+ ];
191
+ }
192
+ function assertDisplayText(id, props) {
193
+ const display = attributeSheetDisplayFindings(id, props);
194
+ if (display.length)
195
+ throw new Error(`${id} declares display text a publish refuses (R-20):\n · ${display.join('\n · ')}`);
196
+ return props;
197
+ }
198
+ /**
199
+ * A stored row reloading at boot is never refused for its display text (ruled
200
+ * 2026-09-17, U5i review): the offending field is dropped and a warning names
201
+ * the row — a sheet with no readable label is listed by its id, and a sheet
202
+ * that vanished from every boot would be the worse answer.
203
+ */
204
+ function withDisplayTextTolerated(id, props) {
205
+ const findings = attributeSheetDisplayFindings(id, props);
206
+ if (!findings.length)
207
+ return props;
208
+ console.warn(`[attributes] stored sheet '${id}' carries display text a publish refuses; ` +
209
+ `dropped on reload, fix the row: ${findings.join('; ')}`);
210
+ const tolerated = { ...props };
211
+ if (i18nFindings(props.label, 'label').length)
212
+ delete tolerated.label;
213
+ if (i18nFindings(props.description, 'description').length)
214
+ delete tolerated.description;
215
+ return tolerated;
216
+ }
217
+ /** What a sheet must satisfy before an owner is allowed to carry it. */
218
+ function checkSheetDeclaration(id, props) {
219
+ const seen = new Set();
220
+ props.slots?.forEach((entry, i) => {
221
+ const decl = getAttributeSlot(entry.id);
222
+ if (!decl)
223
+ throw new Error(`${id} names '${entry.id}' at position ${i}, and nothing declares it. A sheet ` +
224
+ `gathers slots that exist: one that does not would be an owner whose values ` +
225
+ `validate against nothing. Declare the slot first — a sheet is written below ` +
226
+ `the slots it gathers, not above them.`);
227
+ if (seen.has(entry.id))
228
+ throw new Error(`${id} names '${entry.id}' twice. A sheet's order is what a panel draws and what ` +
229
+ `rules run in, so a repeat has no reading at all — say it once, at the ` +
230
+ `position you want it in.`);
231
+ seen.add(entry.id);
232
+ if (entry.appliesTo !== undefined) {
233
+ if (!entry.appliesTo.length)
234
+ throw new Error(`${id} puts '${entry.id}' on no owner at all. Leave \`appliesTo\` out to keep ` +
235
+ `every owner the slot declares, or name the ones this sheet carries it on.`);
236
+ const beyond = entry.appliesTo.filter((o) => !decl.appliesTo.includes(o));
237
+ if (beyond.length)
238
+ throw new Error(`${id} puts '${entry.id}' on ${beyond.join(' and ')}, and the slot attaches only ` +
239
+ `to ${decl.appliesTo.join(' and ')}. A sheet narrows where a slot goes; it ` +
240
+ `never takes it somewhere its declaration does not.`);
241
+ }
242
+ if (entry.default !== undefined) {
243
+ const complaint = checkSlotValue(decl, entry.default, resolveSlotConfig(decl, entry.config));
244
+ if (complaint)
245
+ throw new Error(`${id} gives '${entry.id}' a default its own configuration refuses: ` +
246
+ `${complaint} A default nothing may store is a session creation that ` +
247
+ `fails for everybody who picks this sheet.`);
248
+ }
249
+ });
250
+ }
251
+ //# sourceMappingURL=sheets.js.map
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Stat shapes — the named shapes a stat's value may take, in the SDK's one
3
+ * field language.
4
+ *
5
+ * A **stat shape** is a `FieldDecl` with a name: *number* is
6
+ * `{ type: 'integer' }`, *list* is `{ type: 'list', item: { type: 'string' } }`.
7
+ * An attribute slot says what its value is by naming one
8
+ * (`shape: 'core:stat-shape/number@1'`) or by writing its own `FieldDecl`
9
+ * inline (ruled 2026-09-25: stat shapes are the field language, and core
10
+ * SEEDS a catalogue of common ones so stats stay predictable). Core's
11
+ * catalogue is declared in `@serene-pub/core-catalog` through this file's
12
+ * door, like anybody's would be (R26).
13
+ *
14
+ * ## Open in the declaration, closed in the behaviour
15
+ *
16
+ * A shape is open — any `FieldDecl` — but only the fields core can STORE,
17
+ * check and draw are stat shapes. `statShapeKindOf` is that line, and it
18
+ * names the six kinds core implements: a number (a bar when bounded), a
19
+ * choice, a list, a story time, a line of text, a switch. A `share`, a
20
+ * `media` reference or an `object` is a perfectly good field and not yet a
21
+ * stat, and declaring a shape of one is refused with a sentence rather than
22
+ * stored as a value nothing can draw.
23
+ *
24
+ * ⚠ **Not a `shape`.** `shapes.ts` owns the bare word — a versioned edge
25
+ * contract between two nodes. This is always the qualified *stat shape*, in
26
+ * prose and in the id segment (`:stat-shape/`).
27
+ *
28
+ * ⚠ Lore entry types keep their own fixed shapes (`entryShape`); a stat
29
+ * shape describes a value an owner holds, never a lorebook row.
30
+ */
31
+ import type { I18n } from './descriptors.js';
32
+ import type { FieldDecl } from './settings.js';
33
+ /** `owner:stat-shape/name@N` — `core:stat-shape/number@1`. @experimental */
34
+ export type StatShapeId = string;
35
+ /** @experimental */
36
+ export declare function assertStatShapeId(id: string): void;
37
+ /**
38
+ * What core can do with a stat, by the field it is declared as:
39
+ *
40
+ * - `number` — `integer` or `number`; a bar when a floor and a ceiling are in force.
41
+ * - `choice` — `enum`: one of a closed set, a chip over a menu.
42
+ * - `list` — `list` of text: an ordered list whose items are text or lore
43
+ * references (`SlotLoreRef`), added, removed and reordered.
44
+ * - `story-time` — `string` with `format: 'story-time'`: a position on the
45
+ * story calendar (`storyTime.ts`), shown through the calendar.
46
+ * - `text` — `string` / `text`: a line of prose.
47
+ * - `boolean` — on or off.
48
+ * @experimental
49
+ */
50
+ export type StatShapeKind = 'number' | 'choice' | 'list' | 'story-time' | 'text' | 'boolean';
51
+ /**
52
+ * Which kind of stat a field is, or `undefined` when it is a field core cannot
53
+ * keep as a stat. The one reader of that question — the write gate, the
54
+ * host's projection and the widgets all ask it here.
55
+ * @experimental
56
+ */
57
+ export declare function statShapeKindOf(field: FieldDecl | undefined): StatShapeKind | undefined;
58
+ /** @experimental */
59
+ export interface StatShapeProps {
60
+ /** The name a person reads where shapes are offered. Display text: stripped from the hash. */
61
+ label: I18n;
62
+ /** What it is for. Display text: stripped. */
63
+ description?: I18n;
64
+ /**
65
+ * The value's declaration. What it bounds (`min`/`max`, `of`) is the
66
+ * floor every slot of this shape starts from; a slot's own `config`
67
+ * deviates from it exactly as any layer does.
68
+ */
69
+ field: FieldDecl;
70
+ }
71
+ /** @experimental */
72
+ export interface StatShapeDecl extends StatShapeProps {
73
+ readonly id: StatShapeId;
74
+ }
75
+ /** Display text this registry carries outside `i18n`/`description`. @internal */
76
+ export declare const STAT_SHAPE_DISPLAY_KEYS: {
77
+ readonly display: readonly ['label'];
78
+ };
79
+ /**
80
+ * Declare a stat shape.
81
+ *
82
+ * The registry discipline every other one here keeps: an id has one owner,
83
+ * an identical re-declaration is a no-op (a dev-server reload re-running a
84
+ * module must not throw), and a *different* one under a claimed id throws
85
+ * with both hashes named. Declared ABOVE the slots that name it — a slot
86
+ * naming a shape nothing declares is refused.
87
+ * @experimental
88
+ */
89
+ export declare function defineStatShape(id: StatShapeId, props: StatShapeProps): StatShapeDecl;
90
+ /** @experimental */
91
+ export declare const getStatShape: (id: StatShapeId) => StatShapeDecl | undefined;
92
+ /** Every declared stat shape, in declaration order — the catalogue a picker offers. @experimental */
93
+ export declare const statShapes: () => StatShapeDecl[];
94
+ /** @internal */
95
+ export declare function _clearStatShapes(): void;
96
+ //# sourceMappingURL=statShapes.d.ts.map
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Stat shapes — the named shapes a stat's value may take, in the SDK's one
3
+ * field language.
4
+ *
5
+ * A **stat shape** is a `FieldDecl` with a name: *number* is
6
+ * `{ type: 'integer' }`, *list* is `{ type: 'list', item: { type: 'string' } }`.
7
+ * An attribute slot says what its value is by naming one
8
+ * (`shape: 'core:stat-shape/number@1'`) or by writing its own `FieldDecl`
9
+ * inline (ruled 2026-09-25: stat shapes are the field language, and core
10
+ * SEEDS a catalogue of common ones so stats stay predictable). Core's
11
+ * catalogue is declared in `@serene-pub/core-catalog` through this file's
12
+ * door, like anybody's would be (R26).
13
+ *
14
+ * ## Open in the declaration, closed in the behaviour
15
+ *
16
+ * A shape is open — any `FieldDecl` — but only the fields core can STORE,
17
+ * check and draw are stat shapes. `statShapeKindOf` is that line, and it
18
+ * names the six kinds core implements: a number (a bar when bounded), a
19
+ * choice, a list, a story time, a line of text, a switch. A `share`, a
20
+ * `media` reference or an `object` is a perfectly good field and not yet a
21
+ * stat, and declaring a shape of one is refused with a sentence rather than
22
+ * stored as a value nothing can draw.
23
+ *
24
+ * ⚠ **Not a `shape`.** `shapes.ts` owns the bare word — a versioned edge
25
+ * contract between two nodes. This is always the qualified *stat shape*, in
26
+ * prose and in the id segment (`:stat-shape/`).
27
+ *
28
+ * ⚠ Lore entry types keep their own fixed shapes (`entryShape`); a stat
29
+ * shape describes a value an owner holds, never a lorebook row.
30
+ */
31
+ import { i18nFindings } from './i18n.js';
32
+ import { refuseUnlessIdentical } from './hash.js';
33
+ const STAT_SHAPE_ID = /^[a-z0-9]+(?:[.-][a-z0-9]+)*:stat-shape\/[a-z0-9]+(?:-[a-z0-9]+)*@\d+$/;
34
+ /** @experimental */
35
+ export function assertStatShapeId(id) {
36
+ if (!STAT_SHAPE_ID.test(id))
37
+ throw new Error(`'${id}' is not a valid stat shape id. Use 'owner:stat-shape/name@N' — ` +
38
+ `'core:stat-shape/number@1'. The id is what a slot names to say what its value is.`);
39
+ }
40
+ /**
41
+ * Which kind of stat a field is, or `undefined` when it is a field core cannot
42
+ * keep as a stat. The one reader of that question — the write gate, the
43
+ * host's projection and the widgets all ask it here.
44
+ * @experimental
45
+ */
46
+ export function statShapeKindOf(field) {
47
+ switch (field?.type) {
48
+ case 'integer':
49
+ case 'number':
50
+ return 'number';
51
+ case 'enum':
52
+ return 'choice';
53
+ case 'boolean':
54
+ return 'boolean';
55
+ case 'string':
56
+ case 'text':
57
+ return field.format === 'story-time' ? 'story-time' : field.format === undefined ? 'text' : undefined;
58
+ case 'list': {
59
+ // Items are text (free, or closed by the item's own `of`); lore
60
+ // references ride beside them. A list of numbers or objects is a
61
+ // field, not yet a stat.
62
+ const item = field.item;
63
+ if (!item)
64
+ return 'list';
65
+ if ((item.type === 'string' || item.type === 'text') && item.format === undefined)
66
+ return 'list';
67
+ if (item.type === 'enum')
68
+ return 'list';
69
+ return undefined;
70
+ }
71
+ default:
72
+ return undefined;
73
+ }
74
+ }
75
+ const registry = new Map();
76
+ /** Display text this registry carries outside `i18n`/`description`. @internal */
77
+ export const STAT_SHAPE_DISPLAY_KEYS = { display: ['label'] };
78
+ /**
79
+ * Declare a stat shape.
80
+ *
81
+ * The registry discipline every other one here keeps: an id has one owner,
82
+ * an identical re-declaration is a no-op (a dev-server reload re-running a
83
+ * module must not throw), and a *different* one under a claimed id throws
84
+ * with both hashes named. Declared ABOVE the slots that name it — a slot
85
+ * naming a shape nothing declares is refused.
86
+ * @experimental
87
+ */
88
+ export function defineStatShape(id, props) {
89
+ assertStatShapeId(id);
90
+ const display = [...i18nFindings(props.label, `${id} label`, { required: true }), ...i18nFindings(props.description, `${id} description`)];
91
+ if (display.length)
92
+ throw new Error(`${id} declares display text a publish refuses (R-20):\n · ${display.join('\n · ')}`);
93
+ if (!statShapeKindOf(props.field))
94
+ throw new Error(`${id} declares a '${props.field?.type}' field${props.field?.format ? ` with format '${props.field.format}'` : ''}, ` +
95
+ `which is not a value core can keep as a stat. A stat shape is a number, a choice, a list of ` +
96
+ `text, a story time, a line of text or a switch.`);
97
+ const decl = Object.freeze({ ...props, id, field: Object.freeze({ ...props.field }) });
98
+ const existing = registry.get(id);
99
+ if (existing)
100
+ refuseUnlessIdentical(existing, decl, `duplicate stat shape id: ${id}`, STAT_SHAPE_DISPLAY_KEYS);
101
+ registry.set(id, decl);
102
+ return decl;
103
+ }
104
+ /** @experimental */
105
+ export const getStatShape = (id) => registry.get(id);
106
+ /** Every declared stat shape, in declaration order — the catalogue a picker offers. @experimental */
107
+ export const statShapes = () => [...registry.values()];
108
+ /** @internal */
109
+ export function _clearStatShapes() {
110
+ registry.clear();
111
+ }
112
+ //# sourceMappingURL=statShapes.js.map
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Statuses (plans/29 R-19, R-21; 09-B B11) — what a node says it is doing,
3
+ * from inside its execution.
4
+ *
5
+ * `ctx.status({ i18n, vars })` is callable at any point, by any kind: a query
6
+ * says *{speaker} is thinking*, the oracle five nodes later says *{speaker} is
7
+ * typing*. It is **ephemeral** — never a parameter, never declared on a
8
+ * definition, never a node row on the receipt (F34) — and it persists until
9
+ * the next status or the run's end. The one exception R-21 took: the **last**
10
+ * status is recorded on the receipt when a run ends `halt`, `err` or
11
+ * `cancelled`, because "what was it doing when it died" is a question the
12
+ * receipt should answer.
13
+ *
14
+ * Text is display text with variables — a string, or a locale map (R-20);
15
+ * the CLIENT resolves the locale, so a handler never sees a language. `{speaker}` is the one variable the HOST
16
+ * fills — see `HOST_FILLED_STATUS_VARS` — because a handler is blind to who
17
+ * is speaking and must stay so.
18
+ *
19
+ * ⚠ Not HTTP's `statusText` (a reason phrase beside a code) and not a run's
20
+ * *outcome* (`ok · halt · err · cancelled`): a status is prose about progress,
21
+ * and it decides nothing.
22
+ */
23
+ import { type I18n, type LocaleMap } from './i18n.js';
24
+ /**
25
+ * One status: display text (R-20 — a string or a locale map with `en`), and
26
+ * the values its `{vars}` take. A bare string is `en`, so `ctx.status({ i18n:
27
+ * '{speaker} is thinking' })` is the short spelling of the map form.
28
+ * @experimental
29
+ */
30
+ export interface StatusText {
31
+ i18n: I18n;
32
+ vars?: Record<string, string | number>;
33
+ }
34
+ /**
35
+ * A grey widget action's reason, as the host lists it (`WidgetAction.reason`):
36
+ * a locale map, never a bare string.
37
+ *
38
+ * Declared here beside `StatusText` rather than in `widgets.ts` beside
39
+ * `WidgetAction`, because the API reference's anchor for the property
40
+ * `WidgetAction.reason` and for an interface named `WidgetActionReason` on the
41
+ * same page are one slug (`widgetactionreason`) — TypeDoc then links this type
42
+ * as `#widgetactionreason-1`, which is no heading, and the docs site refuses
43
+ * the dead link.
44
+ * @experimental
45
+ */
46
+ export interface WidgetActionReason extends StatusText {
47
+ i18n: LocaleMap;
48
+ }
49
+ /**
50
+ * The receipt's one record of a status — the last one set, and the node that
51
+ * set it — present only when the run ended `halt`, `err` or `cancelled`
52
+ * (R-21, "optional, taken"). Never on an `ok` receipt, and never a node row.
53
+ * @experimental
54
+ */
55
+ export interface LastStatus {
56
+ nodeKey: string;
57
+ text: StatusText;
58
+ }
59
+ /**
60
+ * The variables a host fills, by name, when a status's text mentions them and
61
+ * the handler did not supply a value. One entry: `speaker` — the display name
62
+ * of the run's speaker (a character's or an envoy's), which the handler cannot
63
+ * know and the host always can. A text naming `{speaker}` on a run with no
64
+ * speaker keeps the variable unset; see `renderStatusText` for what a reader
65
+ * sees then.
66
+ * @experimental
67
+ */
68
+ export declare const HOST_FILLED_STATUS_VARS: readonly ['speaker'];
69
+ /**
70
+ * Is this a status a run can carry? `i18n` is display text a publish accepts
71
+ * (R-20): a non-blank string, or a locale map whose `en` is non-blank. The
72
+ * executor drops a status that is not, with a note on the receipt — a status
73
+ * is advisory and never halts a run.
74
+ * @internal
75
+ */
76
+ export declare function isStatusText(value: unknown): value is StatusText;
77
+ /** The variable names a status's text mentions, across every locale it carries. @internal */
78
+ export declare function statusVarsMentioned(text: StatusText): string[];
79
+ /**
80
+ * A status with the given variables filled in — for every name the text
81
+ * mentions that its own `vars` does not already set. The text's own values
82
+ * win: a handler that supplied a value said what it meant.
83
+ *
84
+ * Returns the same object when nothing changes, so a caller can dedupe by
85
+ * identity as well as by content.
86
+ * @internal
87
+ */
88
+ export declare function fillStatusVars(text: StatusText, values: Record<string, string | number | undefined>): StatusText;
89
+ /**
90
+ * The status as a person reads it: the requested locale, else `en`, with
91
+ * every `{var}` the text sets substituted. A variable the text mentions and
92
+ * nobody filled stays as written — a visible `{speaker}` mid-sentence is a
93
+ * defect a reader can report — EXCEPT a leading `{speaker} `, which is
94
+ * dropped rather than shown literally: a run with nobody to name (a
95
+ * summarize, a graph build) leaves `speaker` unset by design, and "is
96
+ * thinking" reads fine with nobody named. An empty gap elsewhere is one
97
+ * nobody would notice.
98
+ * @internal
99
+ */
100
+ export declare function renderStatusText(text: StatusText, language?: string): string;
101
+ /** Two statuses that would render identically in every locale. @internal */
102
+ export declare function sameStatus(a: StatusText | undefined, b: StatusText | undefined): boolean;
103
+ //# sourceMappingURL=status.d.ts.map