@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
@@ -1,11 +1,12 @@
1
1
  /**
2
- * Document compilation (04 §5a, F3, F6).
2
+ * Document compilation.
3
3
  *
4
4
  * The builder chain is an *authoring format only*. SP imports the document and
5
5
  * never the JS — there is no importer path that evaluates a builder chain.
6
6
  *
7
7
  * Edges are derived here, 1:1 with pipeline_edges rows: the linear chain carries a
8
8
  * default edge, and every $ref becomes an explicit one.
9
+ * @ruling 04 §5a, F3, F6
9
10
  */
10
11
  import type { BuiltSpec } from './builder.js';
11
12
  import { type ConnectionRequirement } from './connections.js';
@@ -32,14 +33,17 @@ export interface DocNode {
32
33
  clauseKind?: string;
33
34
  clauseChain?: string;
34
35
  position: number;
35
- /** Config references resolved at publish and stored explicitly (16 §5b-i). */
36
+ /**
37
+ * Config references resolved at publish and stored explicitly.
38
+ * @ruling 16 §5b-i
39
+ */
36
40
  resolvedRefs?: Record<string, string>;
37
41
  /**
38
- * What the node shows beyond the admin panel — the session-settings mark
39
- * (PLAN-turn-order §4.11, R28), the streaming step and the step status
40
- * (lair pass B3/B18, 2026-09-27), and the step label and step purpose
41
- * the settings name it by (2026-09-30) — see `BuiltNode.expose`. Present
42
+ * What the node shows beyond the admin panel — the session-settings mark,
43
+ * the streaming step and the step status, and the step label and step
44
+ * purpose the settings name it by — see `BuiltNode.expose`. Present
42
45
  * only when stated.
46
+ * @ruling PLAN-turn-order §4.11, R28, lair pass B3/B18 (2026-09-27), 2026-09-30
43
47
  */
44
48
  expose?: {
45
49
  session?: boolean;
@@ -49,22 +53,46 @@ export interface DocNode {
49
53
  label?: I18n;
50
54
  purpose?: I18n;
51
55
  };
56
+ /**
57
+ * What this placement's rendered keys **mean** (owner ruling 2026-10-13):
58
+ * a key its definition's `variables` slot renders, re-pointed at another
59
+ * registered variable — `{ characterLore: 'acme:var/ranked-lore@1' }`.
60
+ * The key stays the template's word; the variable decides which layouts
61
+ * the picker offers, the default row, the floor and the absence rule.
62
+ * Stated by the spec's author, hashed with the document, never by a
63
+ * config or a session. Present only when stated.
64
+ * @ruling PROPOSAL-variable-layout-accounting ★2, ★5
65
+ */
66
+ renders?: Record<string, string>;
52
67
  }
53
68
  /** @experimental */
54
69
  export interface SpecDocument {
55
70
  schemaVersion: 1;
56
71
  id: string;
57
72
  version: string;
58
- /** The genre declaration a create pipeline carries (24 §3). */
73
+ /**
74
+ * The genre declaration a create pipeline carries.
75
+ * @ruling 24 §3
76
+ */
59
77
  genre?: unknown;
60
- /** Contributed surfaces (19 §3–§4) — content like `genre`, hashed with the document. */
78
+ /**
79
+ * Contributed surfaces — content like `genre`, hashed with the document.
80
+ * @ruling 19 §3–§4
81
+ */
61
82
  contributes?: unknown;
62
- /** Catalogue claims (ruled 2026-08-27) — content like the two above, hashed with the document. */
83
+ /**
84
+ * Catalogue claims — content like the two above, hashed with the document.
85
+ * @ruling ruled 2026-08-27
86
+ */
63
87
  taxonomy?: unknown;
64
88
  /**
65
- * The usage lock (24 §4): { genre, event } the inlet declared. Hashed with
66
- * the document. **The only subscription** (R-4) — `subscribes` was deleted
67
- * 2026-09-16 with `.on()`.
89
+ * The usage lock: the genre the inlet declared, and **either** one
90
+ * `event` **or** several `events` — never assume `event`: a
91
+ * `turnOrderSpec()` document is locked on `events` (every event it
92
+ * recomputes on). Read the first with `input.event ?? input.events?.[0]`.
93
+ * Hashed with the document. **The only subscription** — `subscribes` was
94
+ * deleted 2026-09-16 with `.on()`.
95
+ * @ruling 24 §4, R-4
68
96
  */
69
97
  input?: {
70
98
  genre?: string;
@@ -75,19 +103,27 @@ export interface SpecDocument {
75
103
  key: string;
76
104
  fragmentId: string;
77
105
  }>;
78
- /** Author-shipped presets. Execution-affecting, so they round-trip (F4). */
106
+ /**
107
+ * Author-shipped presets. Execution-affecting, so they round-trip.
108
+ * @ruling F4
109
+ */
79
110
  presets: BuiltSpec['presets'];
80
111
  nodes: DocNode[];
81
112
  edges: DocEdge[];
82
113
  clauses: BuiltSpec['clauses'];
83
114
  }
84
- /** A clause's own ports; a junction's fired-branch ports never shadow them (M4). @experimental */
115
+ /**
116
+ * A clause's own ports; a junction's fired-branch ports never shadow them.
117
+ * @experimental
118
+ * @ruling M4
119
+ */
85
120
  export declare const JUNCTION_CLAUSE_PORTS: ReadonlySet<string>;
86
121
  /**
87
- * A junction's branch-end nodes (M4): the last node of each chain, by
122
+ * A junction's branch-end nodes: the last node of each chain, by
88
123
  * position. What a junction publishes beyond its clause ports is read off
89
124
  * these.
90
125
  * @experimental
126
+ * @ruling M4
91
127
  */
92
128
  export declare function junctionBranchEnds(nodes: ReadonlyArray<{
93
129
  key: string;
@@ -123,23 +159,33 @@ export declare function junctionBranchEnds(nodes: ReadonlyArray<{
123
159
  export declare function compile(built: BuiltSpec | SpecDocument): SpecDocument;
124
160
  /**
125
161
  * Follow the spine forward from `fromKey` to the first oracle. Linearity is what
126
- * makes this well-defined (F25). Ambiguity or absence is a publish error that names
127
- * the candidates — the teaching-error pattern (15 §1.3).
162
+ * makes this well-defined. Ambiguity or absence is a publish error that names
163
+ * the candidates — the teaching-error pattern.
128
164
  * @experimental
165
+ * @ruling F25, 15 §1.3
129
166
  */
130
167
  export declare function resolveDownstreamOracle(built: BuiltSpec, fromKey: string): string;
131
168
  /**
132
- * Canonical form — stable key order, for hashing and round-trip identity (F3).
169
+ * Canonical form — stable key order, for hashing and round-trip identity.
133
170
  *
134
171
  * The sort and the digest below moved to `hash.ts` unchanged, because the type
135
172
  * registries now need the same two and a document and a declaration must not
136
173
  * disagree about what identical content is. Same bytes in, same string out.
137
174
  * @experimental
175
+ * @ruling F3
138
176
  */
139
177
  export declare function canonical(doc: SpecDocument): string;
140
- /** Cheap deterministic content hash — stands in for the real canonical_hash (02 §3). @experimental */
178
+ /**
179
+ * Cheap deterministic content hash — stands in for the real canonical_hash.
180
+ * @experimental
181
+ * @ruling 02 §3
182
+ */
141
183
  export declare function canonicalHash(doc: SpecDocument): string;
142
- /** Import: document → the same in-memory form. `import(export(x))` is identity (F3). @experimental */
184
+ /**
185
+ * Import: document → the same in-memory form. `import(export(x))` is identity.
186
+ * @experimental
187
+ * @ruling F3
188
+ */
143
189
  export declare function importDocument(doc: SpecDocument): SpecDocument;
144
190
  /** @experimental */
145
191
  export interface ExportOptions {
@@ -149,14 +195,15 @@ export interface ExportOptions {
149
195
  */
150
196
  presets?: 'all' | 'none' | string[];
151
197
  /**
152
- * How preset bindings travel — the same explicit fork pipeline export already offers
153
- * (02 §6), never decided silently.
198
+ * How preset bindings travel — the same explicit fork pipeline export already offers,
199
+ * never decided silently.
154
200
  *
155
201
  * - `base` keeps `$ref` references by slug. Portable only where the target is itself a
156
202
  * seeded, slugged row; a reference to something a user made locally resolves to
157
203
  * nothing on the far side.
158
204
  * - `flattened` inlines the values. Always portable, and it forks the config — the
159
205
  * importing instance can no longer swap the named thing in one place.
206
+ * @ruling 02 §6
160
207
  */
161
208
  bindings?: 'base' | 'flattened';
162
209
  /** Resolve a `$ref` when flattening. Absent values are dropped and reported. */
@@ -172,19 +219,21 @@ export interface ExportResult {
172
219
  }>;
173
220
  /**
174
221
  * Every connection the importing instance must wire, derived from the types rather
175
- * than from what this instance happened to have configured (13 §10a). Complete even
222
+ * than from what this instance happened to have configured. Complete even
176
223
  * when the exporter never set one up.
224
+ * @ruling 13 §10a
177
225
  */
178
226
  requires: ConnectionRequirement[];
179
227
  }
180
228
  /**
181
- * Export a document, with the presets a user selected (12 §7).
229
+ * Export a document, with the presets a user selected.
182
230
  *
183
231
  * **A filtered export is a different document, not a lossy copy of the same one**, so its
184
- * canonical hash legitimately differs from the source's. F3's identity law is about a
232
+ * canonical hash legitimately differs from the source's. The identity law is about a
185
233
  * given export round-tripping — `import(export(x)) === export(x)` — and that still holds
186
234
  * exactly.
187
235
  * @experimental
236
+ * @ruling 12 §7, F3
188
237
  */
189
238
  export declare function exportDocument(doc: SpecDocument, opts?: ExportOptions): ExportResult;
190
239
  /**
package/dist/document.js CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
- * Document compilation (04 §5a, F3, F6).
2
+ * Document compilation.
3
3
  *
4
4
  * The builder chain is an *authoring format only*. SP imports the document and
5
5
  * never the JS — there is no importer path that evaluates a builder chain.
6
6
  *
7
7
  * Edges are derived here, 1:1 with pipeline_edges rows: the linear chain carries a
8
8
  * default edge, and every $ref becomes an explicit one.
9
+ * @ruling 04 §5a, F3, F6
9
10
  */
10
11
  import { collectDataRefs, envoyConfigKey, isEnvoyConfigKey, isSlotRef } from './refs.js';
11
12
  import { getDefinition } from './descriptors.js';
@@ -16,13 +17,18 @@ const CREATE_MESSAGE_ID = 'core:outlet/create-message';
16
17
  import { requiredConnections } from './connections.js';
17
18
  import { isStreaming } from './shapes.js';
18
19
  import { canonicalize, contentHash } from './hash.js';
19
- /** A clause's own ports; a junction's fired-branch ports never shadow them (M4). @experimental */
20
+ /**
21
+ * A clause's own ports; a junction's fired-branch ports never shadow them.
22
+ * @experimental
23
+ * @ruling M4
24
+ */
20
25
  export const JUNCTION_CLAUSE_PORTS = new Set(['main', 'values', 'branches', 'ok']);
21
26
  /**
22
- * A junction's branch-end nodes (M4): the last node of each chain, by
27
+ * A junction's branch-end nodes: the last node of each chain, by
23
28
  * position. What a junction publishes beyond its clause ports is read off
24
29
  * these.
25
30
  * @experimental
31
+ * @ruling M4
26
32
  */
27
33
  export function junctionBranchEnds(nodes, clause, clauses = []) {
28
34
  return clause.chains.map((chain) => {
@@ -35,7 +41,10 @@ export function junctionBranchEnds(nodes, clause, clauses = []) {
35
41
  return { chain, node: endsInClause ? undefined : last };
36
42
  });
37
43
  }
38
- /** The shape every branch of junction `id` agrees `port` has, else undefined (M4). */
44
+ /**
45
+ * The shape every branch of junction `id` agrees `port` has, else undefined.
46
+ * @ruling M4
47
+ */
39
48
  function junctionPortShape(built, id, port) {
40
49
  const clause = built.clauses.find((c) => c.id === id);
41
50
  if (!clause || clause.kind !== 'junction' || JUNCTION_CLAUSE_PORTS.has(port))
@@ -70,6 +79,7 @@ export function compile(built) {
70
79
  clauseChain: n.clauseChain,
71
80
  position: n.position,
72
81
  ...(n.expose ? { expose: n.expose } : {}),
82
+ ...(n.renders ? { renders: n.renders } : {}),
73
83
  }));
74
84
  const edges = [];
75
85
  // Explicit $ref edges.
@@ -199,9 +209,10 @@ export function compile(built) {
199
209
  }
200
210
  /**
201
211
  * Follow the spine forward from `fromKey` to the first oracle. Linearity is what
202
- * makes this well-defined (F25). Ambiguity or absence is a publish error that names
203
- * the candidates — the teaching-error pattern (15 §1.3).
212
+ * makes this well-defined. Ambiguity or absence is a publish error that names
213
+ * the candidates — the teaching-error pattern.
204
214
  * @experimental
215
+ * @ruling F25, 15 §1.3
205
216
  */
206
217
  export function resolveDownstreamOracle(built, fromKey) {
207
218
  const ordered = built.nodes.slice().sort((a, b) => a.position - b.position);
@@ -219,32 +230,42 @@ export function resolveDownstreamOracle(built, fromKey) {
219
230
  return spineOracles[0].key;
220
231
  }
221
232
  /**
222
- * Canonical form — stable key order, for hashing and round-trip identity (F3).
233
+ * Canonical form — stable key order, for hashing and round-trip identity.
223
234
  *
224
235
  * The sort and the digest below moved to `hash.ts` unchanged, because the type
225
236
  * registries now need the same two and a document and a declaration must not
226
237
  * disagree about what identical content is. Same bytes in, same string out.
227
238
  * @experimental
239
+ * @ruling F3
228
240
  */
229
241
  export function canonical(doc) {
230
242
  return canonicalize(doc);
231
243
  }
232
- /** Cheap deterministic content hash — stands in for the real canonical_hash (02 §3). @experimental */
244
+ /**
245
+ * Cheap deterministic content hash — stands in for the real canonical_hash.
246
+ * @experimental
247
+ * @ruling 02 §3
248
+ */
233
249
  export function canonicalHash(doc) {
234
250
  return contentHash(doc);
235
251
  }
236
- /** Import: document → the same in-memory form. `import(export(x))` is identity (F3). @experimental */
252
+ /**
253
+ * Import: document → the same in-memory form. `import(export(x))` is identity.
254
+ * @experimental
255
+ * @ruling F3
256
+ */
237
257
  export function importDocument(doc) {
238
258
  return JSON.parse(JSON.stringify(doc));
239
259
  }
240
260
  /**
241
- * Export a document, with the presets a user selected (12 §7).
261
+ * Export a document, with the presets a user selected.
242
262
  *
243
263
  * **A filtered export is a different document, not a lossy copy of the same one**, so its
244
- * canonical hash legitimately differs from the source's. F3's identity law is about a
264
+ * canonical hash legitimately differs from the source's. The identity law is about a
245
265
  * given export round-tripping — `import(export(x)) === export(x)` — and that still holds
246
266
  * exactly.
247
267
  * @experimental
268
+ * @ruling 12 §7, F3
248
269
  */
249
270
  export function exportDocument(doc, opts = {}) {
250
271
  const omitted = [];
@@ -0,0 +1,241 @@
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 { type AttributeSlotProps, type SlotId, type SlotOrigin } from './attributes.js';
30
+ import { type AttributeSheetProps, type SheetId } from './sheets.js';
31
+ /** Which registry a declaration belongs to — the id's own kind segment. @experimental */
32
+ export type DowryDeclarationKind = 'slot' | 'sheet';
33
+ /**
34
+ * One embedded declaration: its id as the exporting install knew it, the
35
+ * content hash (`dowryDeclarationHash`) and the props.
36
+ *
37
+ * `origin` says whether a person authored it (`stored`, the default) or a
38
+ * plugin declared it (`plugin`). The id grammar cannot tell a username from a
39
+ * plugin id, and the two are imported on opposite rules — so the
40
+ * exporter, which knows, says.
41
+ * @experimental
42
+ */
43
+ export interface DowryDeclaration<P> {
44
+ id: string;
45
+ hash: string;
46
+ props: P;
47
+ origin?: 'stored' | 'plugin';
48
+ }
49
+ /** A core declaration the card uses: id and content hash, never props. @experimental */
50
+ export interface DowryRef {
51
+ id: string;
52
+ hash: string;
53
+ }
54
+ /**
55
+ * One card-layer stat row, the lorebook export's row shape minus its owner
56
+ * addressing (the owner is the card): a configuration row carries `config`, a
57
+ * value row `value` (`{ v }`). Exactly one of the two.
58
+ * @experimental
59
+ */
60
+ export interface DowryRow {
61
+ slotId: SlotId;
62
+ /** A configuration row's deviations. */
63
+ config?: Record<string, unknown>;
64
+ /** A value row's wrapped value. */
65
+ value?: {
66
+ v: unknown;
67
+ };
68
+ updatedBy?: string;
69
+ note?: string | null;
70
+ }
71
+ /** `extensions.serenepub.dowry`, format 1. @experimental */
72
+ export interface CardDowry {
73
+ format: 1;
74
+ /** The card's sheets, in order — `owner_sheets`. */
75
+ sheets: SheetId[];
76
+ rows: DowryRow[];
77
+ declarations: {
78
+ slots: DowryDeclaration<AttributeSlotProps>[];
79
+ sheets: DowryDeclaration<AttributeSheetProps>[];
80
+ };
81
+ refs: DowryRef[];
82
+ }
83
+ /**
84
+ * The caps a dowry is held to at import. Each row is measured by what the
85
+ * importer stores from it — a configuration's `config`, a value's `value` —
86
+ * as the lorebook's stat import is.
87
+ * @experimental
88
+ */
89
+ export declare const DOWRY_LIMITS: Readonly<{
90
+ readonly maxRows: 2000;
91
+ readonly maxRowJsonBytes: 16384;
92
+ /** Slots and sheets together. */
93
+ readonly maxDeclarations: 200;
94
+ }>;
95
+ /**
96
+ * The content hash a dowry carries for a declaration — `declarationHash`
97
+ * (hash.ts), the hasher every registry here shares, over the props with the
98
+ * registry's display keys stripped (`SLOT_DISPLAY_KEYS` / `SHEET_DISPLAY_KEYS`).
99
+ * A slot's `earshot: 'all'` is the default said aloud and hashes as absent,
100
+ * as the slot registry stores it.
101
+ * @experimental
102
+ */
103
+ export declare function dowryDeclarationHash(kind: DowryDeclarationKind, props: AttributeSlotProps | AttributeSheetProps): string;
104
+ /** One thing wrong with a dowry. @experimental */
105
+ export interface DowryFinding {
106
+ /** e.g. `rows[12].value` */
107
+ path: string;
108
+ message: string;
109
+ }
110
+ /**
111
+ * A dowry against its shape and `DOWRY_LIMITS`. Empty means it may be planned.
112
+ * An embedded hash that does not match its props is a finding: the file was
113
+ * edited, and `planDowryImport` trusts the content, never the claim.
114
+ * @experimental
115
+ */
116
+ export declare function validateDowry(dowry: unknown): DowryFinding[];
117
+ /** What the install already holds under an id. @experimental */
118
+ export interface DowryLocalDeclaration {
119
+ hash: string;
120
+ origin: SlotOrigin;
121
+ }
122
+ /**
123
+ * The install, as the planner reads it. Every answer is the host's; the
124
+ * planner never reaches a registry itself, so a plan is a pure function of
125
+ * this view.
126
+ * @experimental
127
+ */
128
+ export interface DowryLocalView {
129
+ /** The slot held under this id — its dowry hash (`dowryDeclarationHash`) and origin. */
130
+ slot(id: SlotId): DowryLocalDeclaration | undefined;
131
+ sheet(id: SheetId): DowryLocalDeclaration | undefined;
132
+ /** `core` and every installed plugin id (`isReservedAttributeOwner`). */
133
+ isReservedOwner(segment: string): boolean;
134
+ installedPlugin(segment: string): boolean;
135
+ /**
136
+ * A declaration this install already made from one named `name` (the
137
+ * original id's slug) whose dowry hash is `hash` — a re-owned or renamed
138
+ * copy from an earlier import of the same card. How a card imported twice
139
+ * makes one declaration.
140
+ */
141
+ existingByNameAndHash(kind: DowryDeclarationKind, name: string, hash: string): string | undefined;
142
+ }
143
+ /** Who is importing: the owner segment declarations are re-owned to. @experimental */
144
+ export interface DowryImporter {
145
+ ownerSegment: string;
146
+ }
147
+ /**
148
+ * What to do with one embedded declaration — the import rules as data.
149
+ *
150
+ * - `use-local` — the install's own under `id` (the original, or the copy an
151
+ * earlier import made); nothing written.
152
+ * - `register` — unknown here and already the importer's: write it as is.
153
+ * - `rename` — same id here with different content: register under `id` in
154
+ * the importer's namespace, suffixed; `from` is the original id.
155
+ * - `reown` — unknown here, a person's: register under `id` in the
156
+ * importer's namespace; keep `from` as where it came from.
157
+ * - `opaque` — a plugin's that is not installed: keep it as the last-seen
158
+ * record, values kept, shown greyed.
159
+ * - `refuse` — not taken; its rows and sheet entries are dropped.
160
+ * @experimental
161
+ */
162
+ export type DowryDeclarationAction = {
163
+ action: 'use-local';
164
+ id: string;
165
+ } | {
166
+ action: 'register';
167
+ id: string;
168
+ } | {
169
+ action: 'rename';
170
+ id: string;
171
+ from: string;
172
+ } | {
173
+ action: 'reown';
174
+ id: string;
175
+ from: string;
176
+ } | {
177
+ action: 'opaque';
178
+ id: string;
179
+ } | {
180
+ action: 'refuse';
181
+ reason: string;
182
+ };
183
+ /** One embedded declaration's verdict, with the props to write (rewritten for a sheet). @experimental */
184
+ export type DowryPlannedDeclaration<P> = {
185
+ kind: DowryDeclarationKind;
186
+ /** The id as the card carried it. */
187
+ original: string;
188
+ /** The content to write, for `register`/`rename`/`reown`/`opaque` — a sheet's slot ids already mapped. */
189
+ props: P;
190
+ /** Its dowry hash, computed here — never the file's claim. */
191
+ hash: string;
192
+ } & DowryDeclarationAction;
193
+ /** @experimental */
194
+ export interface DowryImportPlan {
195
+ /** One verdict per embedded declaration, in the dowry's order — slots, then sheets. */
196
+ declarations: {
197
+ slots: DowryPlannedDeclaration<AttributeSlotProps>[];
198
+ sheets: DowryPlannedDeclaration<AttributeSheetProps>[];
199
+ };
200
+ /** Every id whose address changed, old → new. Read as `idMap[id] ?? id`. */
201
+ idMap: Record<string, string>;
202
+ /** Ids refused — their rows and sheet entries are not written. */
203
+ dropped: string[];
204
+ /** The card's sheets, ids rewritten, refused ones gone — `owner_sheets`, in order. */
205
+ sheets: SheetId[];
206
+ /** The card's rows, slot ids rewritten, rows of refused slots gone. */
207
+ rows: DowryRow[];
208
+ /** What a person reads in the import summary, one line each. */
209
+ summary: string[];
210
+ }
211
+ /**
212
+ * Plan a dowry's import against the install — the import rules as a function.
213
+ *
214
+ * Slots first, then sheets (a sheet names slots, so its entries are
215
+ * rewritten through the slot map before its own hash is taken), then the
216
+ * card's sheet list and rows through the whole map, then the core refs.
217
+ *
218
+ * Per embedded declaration, by its id's owner segment:
219
+ *
220
+ * 1. An **installed plugin's**: the plugin's live declaration if it has the
221
+ * id (a note when the content differs), else refused — a card cannot
222
+ * declare into a namespace a package owns.
223
+ * 2. Another **reserved** owner's (core): the install's own if present,
224
+ * else refused — core is referenced, never embedded.
225
+ * 3. A **plugin's not installed** here: kept **opaque** (or the install's
226
+ * last-seen copy, when it holds the same content).
227
+ * 4. **Held here** with the same hash: used. With a different hash:
228
+ * **renamed** into the importer's namespace with the first free `-2`,
229
+ * `-3`… suffix; never overwritten.
230
+ * 5. The **importer's own**, unknown here: **registered** as is.
231
+ * 6. **Another person's**, unknown here: **re-owned** to the importer —
232
+ * unless an earlier import already made it (`existingByNameAndHash`), in
233
+ * which case that copy is used.
234
+ *
235
+ * A rename or re-own whose candidate id is already held with the same hash
236
+ * uses that copy too: the same card imported twice makes one declaration.
237
+ * Run `validateDowry` first; the planner assumes a well-formed dowry.
238
+ * @experimental
239
+ */
240
+ export declare function planDowryImport(dowry: CardDowry, local: DowryLocalView, importer: DowryImporter): DowryImportPlan;
241
+ //# sourceMappingURL=dowry.d.ts.map