@serene-pub/sdk 0.6.0-pr-2 → 0.6.0-pr-5

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 (186) hide show
  1. package/README.md +24 -20
  2. package/dist/actions.d.ts +150 -68
  3. package/dist/actions.js +90 -36
  4. package/dist/annexFields.d.ts +8 -4
  5. package/dist/annexFields.js +5 -2
  6. package/dist/announce.d.ts +78 -28
  7. package/dist/announce.js +14 -5
  8. package/dist/attributes.d.ts +9 -6
  9. package/dist/attributes.js +9 -5
  10. package/dist/bands.d.ts +41 -6
  11. package/dist/bands.js +83 -33
  12. package/dist/builder.d.ts +161 -58
  13. package/dist/builder.js +128 -22
  14. package/dist/candidates.d.ts +5 -3
  15. package/dist/candidates.js +3 -2
  16. package/dist/clauses.d.ts +2 -1
  17. package/dist/clauses.js +2 -1
  18. package/dist/component.d.ts +24 -7
  19. package/dist/component.js +16 -6
  20. package/dist/componentBuild.d.ts +16 -5
  21. package/dist/componentBuild.js +14 -5
  22. package/dist/componentClient.d.ts +61 -30
  23. package/dist/componentClient.js +11 -1
  24. package/dist/componentImports.d.ts +8 -5
  25. package/dist/componentImports.js +23 -4
  26. package/dist/componentModule.js +2 -1
  27. package/dist/componentWire.d.ts +2 -1
  28. package/dist/componentWire.js +34 -2
  29. package/dist/config.d.ts +28 -14
  30. package/dist/config.js +20 -10
  31. package/dist/connections.d.ts +9 -4
  32. package/dist/connections.js +7 -4
  33. package/dist/declarations.d.ts +46 -17
  34. package/dist/declarations.js +46 -15
  35. package/dist/descriptors.d.ts +242 -97
  36. package/dist/descriptors.js +145 -41
  37. package/dist/dev.d.ts +6 -5
  38. package/dist/dev.js +6 -5
  39. package/dist/document.d.ts +74 -25
  40. package/dist/document.js +32 -11
  41. package/dist/dowry.d.ts +241 -0
  42. package/dist/dowry.js +315 -0
  43. package/dist/engines.d.ts +16 -7
  44. package/dist/engines.js +6 -4
  45. package/dist/eventMapLaws.d.ts +19 -8
  46. package/dist/eventMapLaws.js +9 -6
  47. package/dist/events.d.ts +101 -39
  48. package/dist/events.js +106 -33
  49. package/dist/executor.d.ts +122 -41
  50. package/dist/executor.js +195 -96
  51. package/dist/extension.d.ts +99 -35
  52. package/dist/extension.js +43 -9
  53. package/dist/facets.d.ts +2 -1
  54. package/dist/facets.js +4 -2
  55. package/dist/foldedSections.d.ts +4 -2
  56. package/dist/foldedSections.js +2 -1
  57. package/dist/genres.d.ts +123 -41
  58. package/dist/genres.js +127 -22
  59. package/dist/guardedConnection.d.ts +4 -3
  60. package/dist/guardedConnection.js +4 -3
  61. package/dist/handlebarsReach.d.ts +1 -1
  62. package/dist/handlebarsReach.js +1 -1
  63. package/dist/hash.d.ts +16 -5
  64. package/dist/hash.js +14 -4
  65. package/dist/hookGrants.d.ts +3 -2
  66. package/dist/hookGrants.js +6 -4
  67. package/dist/hooks.d.ts +21 -16
  68. package/dist/hooks.js +12 -10
  69. package/dist/hostElements.d.ts +41 -17
  70. package/dist/hostElements.js +49 -17
  71. package/dist/i18n.d.ts +5 -3
  72. package/dist/i18n.js +5 -3
  73. package/dist/identity.d.ts +5 -4
  74. package/dist/identity.js +5 -4
  75. package/dist/index.d.ts +5 -0
  76. package/dist/index.js +15 -0
  77. package/dist/layout.d.ts +36 -15
  78. package/dist/layout.js +2 -2
  79. package/dist/loadouts.d.ts +97 -0
  80. package/dist/loadouts.js +81 -0
  81. package/dist/media.d.ts +26 -4
  82. package/dist/media.js +2 -1
  83. package/dist/messageBlocks.d.ts +44 -32
  84. package/dist/messageBlocks.js +23 -18
  85. package/dist/migration.d.ts +16 -8
  86. package/dist/migration.js +14 -8
  87. package/dist/names.d.ts +2 -1
  88. package/dist/names.js +2 -1
  89. package/dist/nodeInput.d.ts +2 -1
  90. package/dist/nodeInput.js +2 -1
  91. package/dist/participants.d.ts +22 -15
  92. package/dist/participants.js +14 -12
  93. package/dist/personGate.d.ts +2 -1
  94. package/dist/personGate.js +2 -1
  95. package/dist/pluginHarness.d.ts +8 -3
  96. package/dist/pluginHarness.js +4 -2
  97. package/dist/pluginPermissions.d.ts +2 -1
  98. package/dist/pluginPermissions.js +12 -1
  99. package/dist/pluginRuleRef.d.ts +2 -2
  100. package/dist/pluginRuleRef.js +1 -1
  101. package/dist/predicates.d.ts +16 -11
  102. package/dist/predicates.js +7 -6
  103. package/dist/preview.d.ts +8 -3
  104. package/dist/preview.js +2 -1
  105. package/dist/promptBlocks.d.ts +5 -3
  106. package/dist/promptBlocks.js +5 -3
  107. package/dist/rankingDecisions.d.ts +2 -1
  108. package/dist/rankingDecisions.js +2 -1
  109. package/dist/receipt.d.ts +65 -29
  110. package/dist/receipt.js +9 -4
  111. package/dist/receiverRules.js +3 -2
  112. package/dist/refs.d.ts +34 -9
  113. package/dist/refs.js +33 -13
  114. package/dist/registry.d.ts +42 -23
  115. package/dist/registry.js +7 -5
  116. package/dist/review.d.ts +16 -5
  117. package/dist/review.js +11 -4
  118. package/dist/sampling.d.ts +54 -0
  119. package/dist/sampling.js +95 -3
  120. package/dist/sceneSettings.d.ts +312 -0
  121. package/dist/sceneSettings.js +425 -0
  122. package/dist/scope.d.ts +6 -4
  123. package/dist/scope.js +4 -3
  124. package/dist/scripts.d.ts +81 -14
  125. package/dist/scripts.js +90 -11
  126. package/dist/sessionDossier.d.ts +521 -0
  127. package/dist/sessionDossier.js +33 -0
  128. package/dist/sessionLayout.d.ts +303 -19
  129. package/dist/sessionLayout.js +354 -40
  130. package/dist/sessionSettings.d.ts +8 -5
  131. package/dist/settings.d.ts +45 -20
  132. package/dist/settings.js +19 -12
  133. package/dist/settingsSlot.d.ts +11 -8
  134. package/dist/settingsSlot.js +11 -8
  135. package/dist/shapes.d.ts +103 -41
  136. package/dist/shapes.js +105 -40
  137. package/dist/sheets.d.ts +4 -2
  138. package/dist/sheets.js +6 -3
  139. package/dist/statShapes.d.ts +2 -1
  140. package/dist/statShapes.js +2 -1
  141. package/dist/status.d.ts +13 -9
  142. package/dist/status.js +8 -6
  143. package/dist/storage.d.ts +2 -1
  144. package/dist/storage.js +2 -1
  145. package/dist/storyTime.d.ts +13 -7
  146. package/dist/storyTime.js +11 -6
  147. package/dist/strokes.d.ts +176 -0
  148. package/dist/strokes.js +281 -0
  149. package/dist/surfaces.d.ts +54 -25
  150. package/dist/surfaces.js +3 -3
  151. package/dist/template.d.ts +9 -5
  152. package/dist/template.js +5 -3
  153. package/dist/templateCheck.d.ts +2 -2
  154. package/dist/templateCheck.js +2 -2
  155. package/dist/templateFit.d.ts +37 -8
  156. package/dist/templateFit.js +92 -8
  157. package/dist/templateIds.d.ts +3 -3
  158. package/dist/templateIds.js +3 -3
  159. package/dist/templateScopeAt.d.ts +21 -11
  160. package/dist/templateScopeAt.js +21 -11
  161. package/dist/testing.d.ts +11 -4
  162. package/dist/testing.js +13 -5
  163. package/dist/tokenizers.d.ts +2 -2
  164. package/dist/tokenizers.js +2 -2
  165. package/dist/turnLock.d.ts +4 -2
  166. package/dist/turnLock.js +2 -1
  167. package/dist/turnOrder.d.ts +17 -11
  168. package/dist/turnOrder.js +9 -5
  169. package/dist/validate.d.ts +11 -8
  170. package/dist/validate.js +81 -10
  171. package/dist/values.d.ts +17 -8
  172. package/dist/values.js +11 -6
  173. package/dist/variables.d.ts +46 -7
  174. package/dist/variables.js +87 -6
  175. package/dist/verdicts.d.ts +20 -13
  176. package/dist/verdicts.js +17 -11
  177. package/dist/widgetDecls.d.ts +8 -4
  178. package/dist/widgetDecls.js +4 -2
  179. package/dist/widgets.d.ts +987 -94
  180. package/dist/widgets.js +93 -18
  181. package/dist/wire.d.ts +13 -6
  182. package/dist/wire.js +3 -3
  183. package/dist/worldinfo.d.ts +11 -6
  184. package/dist/worldinfo.js +8 -4
  185. package/host-elements.d.ts +13 -0
  186. package/package.json +1 -1
package/dist/dowry.js ADDED
@@ -0,0 +1,315 @@
1
+ /**
2
+ * The card dowry — the stats a character card brings with it.
3
+ *
4
+ * ## What it is
5
+ *
6
+ * `extensions.serenepub.dowry` on an exported card (format 1): the sheets the
7
+ * card holds, its card-layer stat rows (configurations and values), the
8
+ * **declarations** those rows need that the receiving install may not have —
9
+ * stored and plugin slots and sheets, embedded with their props and content
10
+ * hash — and **refs** to core declarations, by id and hash only. It is what
11
+ * lets a card round-trip between Serene Pub installs with its numbers intact.
12
+ * A reader that is not Serene Pub sees nothing of it; the prose card is
13
+ * complete without it.
14
+ *
15
+ * ## What it is NOT
16
+ *
17
+ * · **Not a style pack, and not a lorebook export.** It carries one card's
18
+ * state and the vocabulary that state is filed under — nothing about how
19
+ * anything looks, and no world. Session-layer rows never travel.
20
+ * · **Not an importer.** Everything here is pure: `planDowryImport` reads the
21
+ * install through a view the host supplies and answers with a plan — what
22
+ * to use, register, rename, re-own, keep opaque or refuse, the id map, the
23
+ * rewritten sheets and rows, and the summary lines a person reads. The host
24
+ * writes; this decides.
25
+ * · **Not a carrier for core.** Core declarations are referenced, never
26
+ * embedded: a card cannot redefine `core:slot/hp@1` on the install that
27
+ * reads it.
28
+ */
29
+ import { i18nText } from './i18n.js';
30
+ import { declarationHash } from './hash.js';
31
+ import { SLOT_DISPLAY_KEYS, slotOwner, slotSlug, slotVersion, } from './attributes.js';
32
+ import { SHEET_DISPLAY_KEYS } from './sheets.js';
33
+ /**
34
+ * The caps a dowry is held to at import. Each row is measured by what the
35
+ * importer stores from it — a configuration's `config`, a value's `value` —
36
+ * as the lorebook's stat import is.
37
+ * @experimental
38
+ */
39
+ export const DOWRY_LIMITS = Object.freeze({
40
+ maxRows: 2000,
41
+ maxRowJsonBytes: 16_384,
42
+ /** Slots and sheets together. */
43
+ maxDeclarations: 200,
44
+ });
45
+ // ── The hash ────────────────────────────────────────────────────────────────
46
+ /**
47
+ * Keys never part of a declaration's dowry hash beyond each registry's own
48
+ * display keys: the registry-held fields (`id`, `origin`, `authorUserId`,
49
+ * `retired`), so a full declaration and its bare props hash alike, and
50
+ * `importedFrom`, so a re-owned copy hashes as the declaration it came from —
51
+ * which is what lets a repeat import find it.
52
+ */
53
+ const DOWRY_EXTRA_DISPLAY = ['id', 'origin', 'authorUserId', 'retired', 'importedFrom'];
54
+ /**
55
+ * The content hash a dowry carries for a declaration — `declarationHash`
56
+ * (hash.ts), the hasher every registry here shares, over the props with the
57
+ * registry's display keys stripped (`SLOT_DISPLAY_KEYS` / `SHEET_DISPLAY_KEYS`).
58
+ * A slot's `earshot: 'all'` is the default said aloud and hashes as absent,
59
+ * as the slot registry stores it.
60
+ * @experimental
61
+ */
62
+ export function dowryDeclarationHash(kind, props) {
63
+ const base = kind === 'slot' ? SLOT_DISPLAY_KEYS.display : SHEET_DISPLAY_KEYS.display;
64
+ let material = props;
65
+ if (kind === 'slot' && props.earshot === 'all') {
66
+ const { earshot: _all, ...rest } = props;
67
+ material = rest;
68
+ }
69
+ return declarationHash(material, { display: [...base, ...DOWRY_EXTRA_DISPLAY] });
70
+ }
71
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
72
+ const ATTR_ID = /^([a-z0-9]+(?:[.-][a-z0-9]+)*):(slot|sheet)\/([a-z0-9]+(?:-[a-z0-9]+)*)@(\d+)$/;
73
+ const kindOfId = (id) => ATTR_ID.exec(id)?.[2] ?? undefined;
74
+ const utf8 = (s) => new TextEncoder().encode(s).length;
75
+ /**
76
+ * A dowry against its shape and `DOWRY_LIMITS`. Empty means it may be planned.
77
+ * An embedded hash that does not match its props is a finding: the file was
78
+ * edited, and `planDowryImport` trusts the content, never the claim.
79
+ * @experimental
80
+ */
81
+ export function validateDowry(dowry) {
82
+ const out = [];
83
+ if (!isObj(dowry))
84
+ return [{ path: 'dowry', message: 'a dowry is an object' }];
85
+ if (dowry.format !== 1)
86
+ out.push({ path: 'format', message: `format ${String(dowry.format)} is not one this install reads (1)` });
87
+ const L = DOWRY_LIMITS;
88
+ if (!Array.isArray(dowry.sheets))
89
+ out.push({ path: 'sheets', message: 'sheets is a list of sheet ids' });
90
+ else
91
+ dowry.sheets.forEach((id, i) => {
92
+ if (typeof id !== 'string' || kindOfId(id) !== 'sheet')
93
+ out.push({ path: `sheets[${i}]`, message: `'${String(id)}' is not a sheet id` });
94
+ });
95
+ if (!Array.isArray(dowry.rows))
96
+ out.push({ path: 'rows', message: 'rows is a list' });
97
+ else {
98
+ if (dowry.rows.length > L.maxRows)
99
+ out.push({ path: 'rows', message: `a card carries at most ${L.maxRows} stat rows; this one has ${dowry.rows.length}` });
100
+ dowry.rows.forEach((row, i) => {
101
+ const at = `rows[${i}]`;
102
+ if (!isObj(row))
103
+ return void out.push({ path: at, message: 'a row is an object' });
104
+ if (typeof row.slotId !== 'string' || kindOfId(row.slotId) !== 'slot')
105
+ out.push({ path: `${at}.slotId`, message: `'${String(row.slotId)}' is not a slot id` });
106
+ const hasConfig = row.config !== undefined;
107
+ const hasValue = row.value !== undefined;
108
+ if (hasConfig === hasValue)
109
+ out.push({ path: at, message: 'a row carries exactly one of config or value' });
110
+ if (hasConfig && !isObj(row.config))
111
+ out.push({ path: `${at}.config`, message: 'config is an object' });
112
+ if (hasValue && (!isObj(row.value) || !('v' in row.value)))
113
+ out.push({ path: `${at}.value`, message: 'value is { v }' });
114
+ const payload = hasConfig ? row.config : row.value;
115
+ if (payload !== undefined) {
116
+ const bytes = utf8(JSON.stringify(payload) ?? '');
117
+ if (bytes > L.maxRowJsonBytes)
118
+ out.push({
119
+ path: hasConfig ? `${at}.config` : `${at}.value`,
120
+ message: `a stat row is at most ${L.maxRowJsonBytes} bytes; this one is ${bytes}`,
121
+ });
122
+ }
123
+ });
124
+ }
125
+ const decls = dowry.declarations;
126
+ if (!isObj(decls))
127
+ out.push({ path: 'declarations', message: 'declarations is { slots, sheets }' });
128
+ else {
129
+ let count = 0;
130
+ for (const kind of ['slot', 'sheet']) {
131
+ const key = kind === 'slot' ? 'slots' : 'sheets';
132
+ const list = decls[key];
133
+ if (!Array.isArray(list)) {
134
+ out.push({ path: `declarations.${key}`, message: `declarations.${key} is a list` });
135
+ continue;
136
+ }
137
+ count += list.length;
138
+ const seen = new Set();
139
+ list.forEach((d, i) => {
140
+ const at = `declarations.${key}[${i}]`;
141
+ if (!isObj(d))
142
+ return void out.push({ path: at, message: 'a declaration is an object' });
143
+ if (typeof d.id !== 'string' || kindOfId(d.id) !== kind)
144
+ return void out.push({ path: `${at}.id`, message: `'${String(d.id)}' is not a ${kind} id` });
145
+ if (seen.has(d.id))
146
+ out.push({ path: `${at}.id`, message: `'${d.id}' is declared twice` });
147
+ seen.add(d.id);
148
+ if (slotOwner(d.id) === 'core')
149
+ out.push({ path: `${at}.id`, message: `'${d.id}' is core's — core declarations are referenced, never embedded` });
150
+ if (d.origin !== undefined && d.origin !== 'stored' && d.origin !== 'plugin')
151
+ out.push({ path: `${at}.origin`, message: "origin is 'stored' or 'plugin'" });
152
+ if (!isObj(d.props))
153
+ return void out.push({ path: `${at}.props`, message: 'props is an object' });
154
+ if (kind === 'sheet' && !Array.isArray(d.props.slots))
155
+ out.push({ path: `${at}.props.slots`, message: 'a sheet lists its slots' });
156
+ if (typeof d.hash !== 'string')
157
+ out.push({ path: `${at}.hash`, message: 'a declaration carries its content hash' });
158
+ else if (d.hash !== dowryDeclarationHash(kind, d.props))
159
+ out.push({ path: `${at}.hash`, message: `'${d.id}' does not match its hash — its content was edited` });
160
+ });
161
+ }
162
+ if (count > L.maxDeclarations)
163
+ out.push({
164
+ path: 'declarations',
165
+ message: `a card carries at most ${L.maxDeclarations} declarations; this one has ${count}`,
166
+ });
167
+ }
168
+ if (!Array.isArray(dowry.refs))
169
+ out.push({ path: 'refs', message: 'refs is a list' });
170
+ else
171
+ dowry.refs.forEach((r, i) => {
172
+ if (!isObj(r) || typeof r.id !== 'string' || !kindOfId(r.id) || typeof r.hash !== 'string')
173
+ out.push({ path: `refs[${i}]`, message: 'a ref is { id, hash } naming a slot or sheet' });
174
+ });
175
+ return out;
176
+ }
177
+ const idOf = (owner, kind, slug, version) => `${owner}:${kind}/${slug}@${version}`;
178
+ const labelOf = (props, id) => i18nText(props?.label) ?? (slotSlug(id) || id);
179
+ /**
180
+ * Plan a dowry's import against the install — the import rules as a function.
181
+ *
182
+ * Slots first, then sheets (a sheet names slots, so its entries are
183
+ * rewritten through the slot map before its own hash is taken), then the
184
+ * card's sheet list and rows through the whole map, then the core refs.
185
+ *
186
+ * Per embedded declaration, by its id's owner segment:
187
+ *
188
+ * 1. An **installed plugin's**: the plugin's live declaration if it has the
189
+ * id (a note when the content differs), else refused — a card cannot
190
+ * declare into a namespace a package owns.
191
+ * 2. Another **reserved** owner's (core): the install's own if present,
192
+ * else refused — core is referenced, never embedded.
193
+ * 3. A **plugin's not installed** here: kept **opaque** (or the install's
194
+ * last-seen copy, when it holds the same content).
195
+ * 4. **Held here** with the same hash: used. With a different hash:
196
+ * **renamed** into the importer's namespace with the first free `-2`,
197
+ * `-3`… suffix; never overwritten.
198
+ * 5. The **importer's own**, unknown here: **registered** as is.
199
+ * 6. **Another person's**, unknown here: **re-owned** to the importer —
200
+ * unless an earlier import already made it (`existingByNameAndHash`), in
201
+ * which case that copy is used.
202
+ *
203
+ * A rename or re-own whose candidate id is already held with the same hash
204
+ * uses that copy too: the same card imported twice makes one declaration.
205
+ * Run `validateDowry` first; the planner assumes a well-formed dowry.
206
+ * @experimental
207
+ */
208
+ export function planDowryImport(dowry, local, importer) {
209
+ const idMap = {};
210
+ const dropped = [];
211
+ const summary = [];
212
+ const me = importer.ownerSegment;
213
+ const held = (kind, id) => (kind === 'slot' ? local.slot(id) : local.sheet(id));
214
+ const noun = (kind) => (kind === 'slot' ? 'stat' : 'stat sheet');
215
+ /** The first id in the importer's namespace that is free or already holds this content. */
216
+ const findHome = (kind, slug, version, hash, startAt) => {
217
+ for (let n = startAt;; n++) {
218
+ const id = idOf(me, kind, n === 1 ? slug : `${slug}-${n}`, version);
219
+ const there = held(kind, id);
220
+ if (!there)
221
+ return { id, existing: false };
222
+ if (there.hash === hash)
223
+ return { id, existing: true };
224
+ }
225
+ };
226
+ function decide(kind, d, props) {
227
+ const original = d.id;
228
+ const owner = slotOwner(original);
229
+ const slug = slotSlug(original);
230
+ const version = slotVersion(original);
231
+ const hash = dowryDeclarationHash(kind, props);
232
+ const label = labelOf(props, original);
233
+ const base = { kind, original, props, hash };
234
+ const here = held(kind, original);
235
+ const plan = (a) => {
236
+ if ('id' in a && a.id !== original)
237
+ idMap[original] = a.id;
238
+ if (a.action === 'refuse')
239
+ dropped.push(original);
240
+ return { ...base, ...a };
241
+ };
242
+ if (local.installedPlugin(owner)) {
243
+ if (here) {
244
+ if (here.hash !== hash)
245
+ summary.push(`The ${noun(kind)} "${label}" differs from the one the installed plugin "${owner}" declares; the plugin's is used.`);
246
+ return plan({ action: 'use-local', id: original });
247
+ }
248
+ summary.push(`The ${noun(kind)} "${label}" was left out: the installed plugin "${owner}" does not declare it.`);
249
+ return plan({ action: 'refuse', reason: `the installed plugin '${owner}' does not declare '${original}'` });
250
+ }
251
+ if (local.isReservedOwner(owner)) {
252
+ if (here)
253
+ return plan({ action: 'use-local', id: original });
254
+ summary.push(`The ${noun(kind)} "${label}" was left out: "${owner}" is a reserved name here.`);
255
+ return plan({ action: 'refuse', reason: `'${owner}' is a reserved owner and holds no '${original}' here` });
256
+ }
257
+ if (d.origin === 'plugin') {
258
+ if (here && here.hash === hash)
259
+ return plan({ action: 'use-local', id: original });
260
+ summary.push(`The ${noun(kind)} "${label}" comes from the plugin "${owner}", which is not installed; its values are kept and shown greyed.`);
261
+ return plan({ action: 'opaque', id: original });
262
+ }
263
+ if (here) {
264
+ if (here.hash === hash)
265
+ return plan({ action: 'use-local', id: original });
266
+ const prior = local.existingByNameAndHash(kind, slug, hash);
267
+ const home = prior ? { id: prior, existing: true } : findHome(kind, slug, version, hash, 2);
268
+ if (home.existing)
269
+ return plan({ action: 'use-local', id: home.id });
270
+ summary.push(`The ${noun(kind)} "${label}" on this card differs from yours with the same id, so it was added as ${home.id}.`);
271
+ return plan({ action: 'rename', id: home.id, from: original });
272
+ }
273
+ if (owner === me)
274
+ return plan({ action: 'register', id: original });
275
+ const prior = local.existingByNameAndHash(kind, slug, hash);
276
+ if (prior)
277
+ return plan({ action: 'use-local', id: prior });
278
+ const home = findHome(kind, slug, version, hash, 1);
279
+ if (home.existing)
280
+ return plan({ action: 'use-local', id: home.id });
281
+ summary.push(`The ${noun(kind)} "${label}" was added to your stats as ${home.id}.`);
282
+ return plan({ action: 'reown', id: home.id, from: original });
283
+ }
284
+ const mapId = (id) => idMap[id] ?? id;
285
+ const isDropped = (id) => dropped.includes(id);
286
+ const slots = dowry.declarations.slots.map((d) => decide('slot', d, d.props));
287
+ const sheets = dowry.declarations.sheets.map((d) => {
288
+ const gone = d.props.slots.filter((e) => isDropped(e.id));
289
+ if (gone.length)
290
+ summary.push(`The stat sheet "${labelOf(d.props, d.id)}" lost ${gone.length} stat${gone.length === 1 ? '' : 's'} that could not be brought in.`);
291
+ const props = {
292
+ ...d.props,
293
+ slots: d.props.slots.filter((e) => !isDropped(e.id)).map((e) => ({ ...e, id: mapId(e.id) })),
294
+ };
295
+ return decide('sheet', d, props);
296
+ });
297
+ const sheetList = dowry.sheets.filter((id) => !isDropped(id)).map(mapId);
298
+ const rows = dowry.rows.filter((r) => !isDropped(r.slotId)).map((r) => ({ ...r, slotId: mapId(r.slotId) }));
299
+ const lostRows = dowry.rows.length - rows.length;
300
+ if (lostRows)
301
+ summary.push(`${lostRows} stat value${lostRows === 1 ? ' was' : 's were'} left out with the stats they belong to.`);
302
+ for (const ref of dowry.refs) {
303
+ const kind = kindOfId(ref.id);
304
+ if (!kind)
305
+ continue;
306
+ const here = held(kind, ref.id);
307
+ const name = slotSlug(ref.id) || ref.id;
308
+ if (!here)
309
+ summary.push(`The ${noun(kind)} "${name}" is not on this install; values filed under it are kept but not shown.`);
310
+ else if (here.hash !== ref.hash)
311
+ summary.push(`The ${noun(kind)} "${name}" is a newer or older version here than where this card was made; this install's is used.`);
312
+ }
313
+ return { declarations: { slots, sheets }, idMap, dropped, sheets: sheetList, rows, summary };
314
+ }
315
+ //# sourceMappingURL=dowry.js.map
package/dist/engines.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Template engines are a registry, not a hardcoded choice (F2 — types are open
2
+ * Template engines are a registry, not a hardcoded choice (types are open
3
3
  * registries, ids namespaced, `core:` reserved).
4
4
  *
5
5
  * `SlotDecl.engine` used to be the literal `'jinja2'`, which quietly said "there is one
@@ -9,13 +9,13 @@
9
9
  * — so two slots in one spec may use different engines.
10
10
  *
11
11
  * That is safe for a reason worth stating: source templates render *before* Assemble
12
- * (16 §3b, enforced by port shapes), so only text crosses into allocation. Mixing engines
12
+ * (enforced by port shapes), so only text crosses into allocation. Mixing engines
13
13
  * cannot confuse the budget, because the budget never sees a template — it sees rendered
14
14
  * blocks and a cost profile.
15
15
  *
16
16
  * ## The cost profile is why this interface has four members instead of one
17
17
  *
18
- * The budget guarantee (16 §7) is that Assemble's estimate is a **ceiling**: literals are
18
+ * The budget guarantee is that Assemble's estimate is a **ceiling**: literals are
19
19
  * counted exactly, per-iteration literals are counted once and multiplied, conditionals
20
20
  * take their largest branch. That is a static analysis of the template, so it can only be
21
21
  * done by whoever understands the syntax — the engine.
@@ -24,6 +24,7 @@
24
24
  * widens its safety margin, and the receipt records that the estimate was approximate. So
25
25
  * a sloppy engine costs its users context headroom rather than correctness — a pressure
26
26
  * gradient rather than a ban.
27
+ * @ruling F2, 16 §3b, 16 §7
27
28
  */
28
29
  import { type TemplateFinding, type TemplateScope } from "./template.js";
29
30
  /** @experimental */
@@ -42,7 +43,8 @@ export interface CostProfile {
42
43
  /**
43
44
  * False when the engine could not analyse statically and these numbers are a guess.
44
45
  * Assemble widens its margin and the receipt says so — the estimate degrades to
45
- * conservative rather than to wrong (16 §7).
46
+ * conservative rather than to wrong.
47
+ * @ruling 16 §7
46
48
  */
47
49
  exact: boolean;
48
50
  }
@@ -52,9 +54,15 @@ export interface TemplateEngine {
52
54
  /** Human-facing, for the template editor's language picker. */
53
55
  label: string;
54
56
  render(source: string, scope: Record<string, unknown>): string;
55
- /** Variables the source references — feeds the editor and publish-time checking (16 §4). */
57
+ /**
58
+ * Variables the source references — feeds the editor and publish-time checking.
59
+ * @ruling 16 §4
60
+ */
56
61
  extract(source: string): string[];
57
- /** Publish-time diagnostics against the slot's declared `variables` (13 §7j-a). */
62
+ /**
63
+ * Publish-time diagnostics against the slot's declared `variables`.
64
+ * @ruling 13 §7j-a
65
+ */
58
66
  check(source: string, declared: TemplateScope): TemplateFinding[];
59
67
  /**
60
68
  * Static token cost, given a tokenizer. Called once per (source, tokenizer) and
@@ -85,7 +93,7 @@ export declare const plain: TemplateEngine;
85
93
  * Handlebars — **the engine Serene Pub's context templates are actually written in.**
86
94
  *
87
95
  * Registered as a declaration rather than an implementation: a template's engine is a
88
- * datapoint on the slot (12 §2a), and the host supplies the renderer. The SDK ships no
96
+ * datapoint on the slot, and the host supplies the renderer. The SDK ships no
89
97
  * Handlebars dependency, so `render` here refuses rather than silently producing
90
98
  * something that is not what core would produce — a near-miss renderer is worse than an
91
99
  * absent one, because parity would fail in a way that looks like a template bug.
@@ -95,6 +103,7 @@ export declare const plain: TemplateEngine;
95
103
  * template-engine registry is exactly the mechanism that makes that a one-line change
96
104
  * rather than a redesign, which is the argument for having built it.
97
105
  * @experimental
106
+ * @ruling 12 §2a
98
107
  */
99
108
  export declare const handlebars: TemplateEngine;
100
109
  /**
package/dist/engines.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Template engines are a registry, not a hardcoded choice (F2 — types are open
2
+ * Template engines are a registry, not a hardcoded choice (types are open
3
3
  * registries, ids namespaced, `core:` reserved).
4
4
  *
5
5
  * `SlotDecl.engine` used to be the literal `'jinja2'`, which quietly said "there is one
@@ -9,13 +9,13 @@
9
9
  * — so two slots in one spec may use different engines.
10
10
  *
11
11
  * That is safe for a reason worth stating: source templates render *before* Assemble
12
- * (16 §3b, enforced by port shapes), so only text crosses into allocation. Mixing engines
12
+ * (enforced by port shapes), so only text crosses into allocation. Mixing engines
13
13
  * cannot confuse the budget, because the budget never sees a template — it sees rendered
14
14
  * blocks and a cost profile.
15
15
  *
16
16
  * ## The cost profile is why this interface has four members instead of one
17
17
  *
18
- * The budget guarantee (16 §7) is that Assemble's estimate is a **ceiling**: literals are
18
+ * The budget guarantee is that Assemble's estimate is a **ceiling**: literals are
19
19
  * counted exactly, per-iteration literals are counted once and multiplied, conditionals
20
20
  * take their largest branch. That is a static analysis of the template, so it can only be
21
21
  * done by whoever understands the syntax — the engine.
@@ -24,6 +24,7 @@
24
24
  * widens its safety margin, and the receipt records that the estimate was approximate. So
25
25
  * a sloppy engine costs its users context headroom rather than correctness — a pressure
26
26
  * gradient rather than a ban.
27
+ * @ruling F2, 16 §3b, 16 §7
27
28
  */
28
29
  import { render as renderJinja, extractRefs, checkTemplate } from "./template.js";
29
30
  import { refuseUnlessIdentical } from './hash.js';
@@ -111,7 +112,7 @@ export const plain = defineEngine({
111
112
  * Handlebars — **the engine Serene Pub's context templates are actually written in.**
112
113
  *
113
114
  * Registered as a declaration rather than an implementation: a template's engine is a
114
- * datapoint on the slot (12 §2a), and the host supplies the renderer. The SDK ships no
115
+ * datapoint on the slot, and the host supplies the renderer. The SDK ships no
115
116
  * Handlebars dependency, so `render` here refuses rather than silently producing
116
117
  * something that is not what core would produce — a near-miss renderer is worse than an
117
118
  * absent one, because parity would fail in a way that looks like a template bug.
@@ -121,6 +122,7 @@ export const plain = defineEngine({
121
122
  * template-engine registry is exactly the mechanism that makes that a one-line change
122
123
  * rather than a redesign, which is the argument for having built it.
123
124
  * @experimental
125
+ * @ruling 12 §2a
124
126
  */
125
127
  export const handlebars = defineEngine({
126
128
  id: "core:template/handlebars@1",
@@ -1,19 +1,20 @@
1
1
  /**
2
- * The event map's two laws (PLAN-turn-order §B3), as pure functions the
3
- * conformance kit (C28, C29) and a host's boot check both call — one
2
+ * The event map's two laws, as pure functions the
3
+ * conformance kit and a host's boot check both call — one
4
4
  * judgement, two callers, so the kit and the warning cannot disagree.
5
5
  *
6
- * **C28 — every event a genre lists is caused or a declared root.** A
6
+ * **Every event a genre lists is caused or a declared root.** A
7
7
  * listed event that nothing writes and nobody starts is a slot a preset can
8
8
  * bind and nothing will ever fire.
9
9
  *
10
- * **C29 — every cycle has a termination policy.** The event map (events,
10
+ * **Every cycle has a termination policy.** The event map (events,
11
11
  * pipelines, listeners; binds · causes · listens) may loop: a reply completes a
12
12
  * message, the message recomputes the turn order, auto-advance asks for the
13
13
  * next reply. A loop is fine when something in it declares how it stops —
14
14
  * auto-advance's cause rule and cap, or the host's run caps, which park a
15
15
  * run tree for its owner. A loop where nothing does runs until the host
16
16
  * falls over.
17
+ * @ruling PLAN-turn-order §B3, C28, C29
17
18
  */
18
19
  /** @experimental */
19
20
  export type EventGraphNodeKind = 'event' | 'spec' | 'listener';
@@ -31,33 +32,43 @@ export interface EventGraph {
31
32
  kind: EventGraphEdgeKind;
32
33
  }>;
33
34
  }
34
- /** One C28 finding: a genre lists an event that nothing causes and nobody starts. @experimental */
35
+ /**
36
+ * One uncaused-event finding: a genre lists an event that nothing causes and nobody starts.
37
+ * @experimental
38
+ * @ruling C28
39
+ */
35
40
  export interface UncausedEventFinding {
36
41
  genre: string;
37
42
  event: string;
38
43
  sentence: string;
39
44
  }
40
45
  /**
41
- * C28 over one genre's event surface. An event the registry does not know
46
+ * The caused-or-root law over one genre's event surface. An event the registry does not know
42
47
  * is a finding too: it cannot be caused, because it does not exist.
43
48
  * @experimental
49
+ * @ruling C28
44
50
  */
45
51
  export declare function uncausedGenreEvents(genre: {
46
52
  id: string;
47
53
  events?: Readonly<Record<string, unknown>>;
48
54
  }): UncausedEventFinding[];
49
- /** One C29 finding: a cycle in which no node declares a termination policy. @experimental */
55
+ /**
56
+ * One unterminated-cycle finding: a cycle in which no node declares a termination policy.
57
+ * @experimental
58
+ * @ruling C29
59
+ */
50
60
  export interface UnterminatedCycleFinding {
51
61
  /** The cycle's members (one strongly connected component), sorted. */
52
62
  members: string[];
53
63
  sentence: string;
54
64
  }
55
65
  /**
56
- * C29 over one drawn map. `terminationOf(id)` is the host's termination
66
+ * The termination law over one drawn map. `terminationOf(id)` is the host's termination
57
67
  * policy for a loop through that node — auto-advance's cause rule and cap, the run
58
68
  * caps that park a tree — or undefined. Every strongly connected component
59
69
  * that holds a cycle must hold a node with a termination policy.
60
70
  * @experimental
71
+ * @ruling C29
61
72
  */
62
73
  export declare function unterminatedCycles(graph: EventGraph, terminationOf: (nodeId: string) => string | undefined): UnterminatedCycleFinding[];
63
74
  //# sourceMappingURL=eventMapLaws.d.ts.map
@@ -1,25 +1,27 @@
1
1
  /**
2
- * The event map's two laws (PLAN-turn-order §B3), as pure functions the
3
- * conformance kit (C28, C29) and a host's boot check both call — one
2
+ * The event map's two laws, as pure functions the
3
+ * conformance kit and a host's boot check both call — one
4
4
  * judgement, two callers, so the kit and the warning cannot disagree.
5
5
  *
6
- * **C28 — every event a genre lists is caused or a declared root.** A
6
+ * **Every event a genre lists is caused or a declared root.** A
7
7
  * listed event that nothing writes and nobody starts is a slot a preset can
8
8
  * bind and nothing will ever fire.
9
9
  *
10
- * **C29 — every cycle has a termination policy.** The event map (events,
10
+ * **Every cycle has a termination policy.** The event map (events,
11
11
  * pipelines, listeners; binds · causes · listens) may loop: a reply completes a
12
12
  * message, the message recomputes the turn order, auto-advance asks for the
13
13
  * next reply. A loop is fine when something in it declares how it stops —
14
14
  * auto-advance's cause rule and cap, or the host's run caps, which park a
15
15
  * run tree for its owner. A loop where nothing does runs until the host
16
16
  * falls over.
17
+ * @ruling PLAN-turn-order §B3, C28, C29
17
18
  */
18
19
  import { eventById } from './events.js';
19
20
  /**
20
- * C28 over one genre's event surface. An event the registry does not know
21
+ * The caused-or-root law over one genre's event surface. An event the registry does not know
21
22
  * is a finding too: it cannot be caused, because it does not exist.
22
23
  * @experimental
24
+ * @ruling C28
23
25
  */
24
26
  export function uncausedGenreEvents(genre) {
25
27
  const out = [];
@@ -42,11 +44,12 @@ export function uncausedGenreEvents(genre) {
42
44
  return out;
43
45
  }
44
46
  /**
45
- * C29 over one drawn map. `terminationOf(id)` is the host's termination
47
+ * The termination law over one drawn map. `terminationOf(id)` is the host's termination
46
48
  * policy for a loop through that node — auto-advance's cause rule and cap, the run
47
49
  * caps that park a tree — or undefined. Every strongly connected component
48
50
  * that holds a cycle must hold a node with a termination policy.
49
51
  * @experimental
52
+ * @ruling C29
50
53
  */
51
54
  export function unterminatedCycles(graph, terminationOf) {
52
55
  const next = new Map();