@serene-pub/sdk 0.6.0-pr-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +17 -0
  3. package/README.md +368 -0
  4. package/dist/actions.d.ts +572 -0
  5. package/dist/actions.js +829 -0
  6. package/dist/annexFields.d.ts +234 -0
  7. package/dist/annexFields.js +413 -0
  8. package/dist/announce.d.ts +464 -0
  9. package/dist/announce.js +426 -0
  10. package/dist/attributes.d.ts +670 -0
  11. package/dist/attributes.js +904 -0
  12. package/dist/bands.d.ts +125 -0
  13. package/dist/bands.js +256 -0
  14. package/dist/builder.d.ts +683 -0
  15. package/dist/builder.js +677 -0
  16. package/dist/candidates.d.ts +109 -0
  17. package/dist/candidates.js +118 -0
  18. package/dist/capabilities.d.ts +744 -0
  19. package/dist/capabilities.js +679 -0
  20. package/dist/channels.d.ts +106 -0
  21. package/dist/channels.js +129 -0
  22. package/dist/clauses.d.ts +40 -0
  23. package/dist/clauses.js +43 -0
  24. package/dist/component.d.ts +33 -0
  25. package/dist/component.js +27 -0
  26. package/dist/componentBuild.d.ts +48 -0
  27. package/dist/componentBuild.js +84 -0
  28. package/dist/componentClient.d.ts +100 -0
  29. package/dist/componentClient.js +13 -0
  30. package/dist/componentImports.d.ts +51 -0
  31. package/dist/componentImports.js +106 -0
  32. package/dist/componentModule.d.ts +8 -0
  33. package/dist/componentModule.js +270 -0
  34. package/dist/componentWire.d.ts +130 -0
  35. package/dist/componentWire.js +280 -0
  36. package/dist/config.d.ts +295 -0
  37. package/dist/config.js +231 -0
  38. package/dist/connections.d.ts +89 -0
  39. package/dist/connections.js +131 -0
  40. package/dist/declarations.d.ts +290 -0
  41. package/dist/declarations.js +794 -0
  42. package/dist/descriptors.d.ts +1774 -0
  43. package/dist/descriptors.js +1329 -0
  44. package/dist/dev.d.ts +136 -0
  45. package/dist/dev.js +161 -0
  46. package/dist/document.d.ts +202 -0
  47. package/dist/document.js +312 -0
  48. package/dist/engines.d.ts +117 -0
  49. package/dist/engines.js +203 -0
  50. package/dist/eventMapLaws.d.ts +63 -0
  51. package/dist/eventMapLaws.js +128 -0
  52. package/dist/events.d.ts +554 -0
  53. package/dist/events.js +633 -0
  54. package/dist/executor.d.ts +771 -0
  55. package/dist/executor.js +1829 -0
  56. package/dist/extension.d.ts +448 -0
  57. package/dist/extension.js +315 -0
  58. package/dist/facets.d.ts +53 -0
  59. package/dist/facets.js +60 -0
  60. package/dist/foldedSections.d.ts +74 -0
  61. package/dist/foldedSections.js +161 -0
  62. package/dist/genres.d.ts +507 -0
  63. package/dist/genres.js +633 -0
  64. package/dist/guardedConnection.d.ts +138 -0
  65. package/dist/guardedConnection.js +341 -0
  66. package/dist/handlebarsReach.d.ts +122 -0
  67. package/dist/handlebarsReach.js +222 -0
  68. package/dist/hash.d.ts +146 -0
  69. package/dist/hash.js +166 -0
  70. package/dist/hookGrants.d.ts +47 -0
  71. package/dist/hookGrants.js +68 -0
  72. package/dist/hooks.d.ts +290 -0
  73. package/dist/hooks.js +113 -0
  74. package/dist/hostElements.d.ts +447 -0
  75. package/dist/hostElements.js +702 -0
  76. package/dist/i18n.d.ts +94 -0
  77. package/dist/i18n.js +123 -0
  78. package/dist/identity.d.ts +93 -0
  79. package/dist/identity.js +135 -0
  80. package/dist/index.d.ts +85 -0
  81. package/dist/index.js +176 -0
  82. package/dist/layout.d.ts +194 -0
  83. package/dist/layout.js +40 -0
  84. package/dist/media.d.ts +202 -0
  85. package/dist/media.js +70 -0
  86. package/dist/messageBlocks.d.ts +487 -0
  87. package/dist/messageBlocks.js +683 -0
  88. package/dist/migration.d.ts +128 -0
  89. package/dist/migration.js +261 -0
  90. package/dist/names.d.ts +78 -0
  91. package/dist/names.js +136 -0
  92. package/dist/nodeInput.d.ts +399 -0
  93. package/dist/nodeInput.js +178 -0
  94. package/dist/participants.d.ts +291 -0
  95. package/dist/participants.js +252 -0
  96. package/dist/personGate.d.ts +62 -0
  97. package/dist/personGate.js +77 -0
  98. package/dist/pick.d.ts +84 -0
  99. package/dist/pick.js +103 -0
  100. package/dist/pluginHarness.d.ts +235 -0
  101. package/dist/pluginHarness.js +558 -0
  102. package/dist/pluginPermissions.d.ts +25 -0
  103. package/dist/pluginPermissions.js +97 -0
  104. package/dist/pluginRuleRef.d.ts +13 -0
  105. package/dist/pluginRuleRef.js +10 -0
  106. package/dist/predicates.d.ts +182 -0
  107. package/dist/predicates.js +249 -0
  108. package/dist/preview.d.ts +120 -0
  109. package/dist/preview.js +82 -0
  110. package/dist/promptBlocks.d.ts +130 -0
  111. package/dist/promptBlocks.js +197 -0
  112. package/dist/rankingDecisions.d.ts +60 -0
  113. package/dist/rankingDecisions.js +48 -0
  114. package/dist/receipt.d.ts +313 -0
  115. package/dist/receipt.js +60 -0
  116. package/dist/receiverRules.d.ts +24 -0
  117. package/dist/receiverRules.js +94 -0
  118. package/dist/refs.d.ts +117 -0
  119. package/dist/refs.js +137 -0
  120. package/dist/registry.d.ts +230 -0
  121. package/dist/registry.js +273 -0
  122. package/dist/review.d.ts +108 -0
  123. package/dist/review.js +97 -0
  124. package/dist/sampling.d.ts +152 -0
  125. package/dist/sampling.js +712 -0
  126. package/dist/scope.d.ts +65 -0
  127. package/dist/scope.js +128 -0
  128. package/dist/scripts.d.ts +243 -0
  129. package/dist/scripts.js +326 -0
  130. package/dist/sessionLayout.d.ts +339 -0
  131. package/dist/sessionLayout.js +503 -0
  132. package/dist/sessionSettings.d.ts +70 -0
  133. package/dist/sessionSettings.js +2 -0
  134. package/dist/settings.d.ts +501 -0
  135. package/dist/settings.js +604 -0
  136. package/dist/settingsSlot.d.ts +108 -0
  137. package/dist/settingsSlot.js +166 -0
  138. package/dist/shapes.d.ts +373 -0
  139. package/dist/shapes.js +408 -0
  140. package/dist/sheets.d.ts +165 -0
  141. package/dist/sheets.js +251 -0
  142. package/dist/statShapes.d.ts +96 -0
  143. package/dist/statShapes.js +112 -0
  144. package/dist/status.d.ts +103 -0
  145. package/dist/status.js +125 -0
  146. package/dist/storage.d.ts +145 -0
  147. package/dist/storage.js +33 -0
  148. package/dist/storyTime.d.ts +308 -0
  149. package/dist/storyTime.js +560 -0
  150. package/dist/surfaces.d.ts +501 -0
  151. package/dist/surfaces.js +292 -0
  152. package/dist/template.d.ts +312 -0
  153. package/dist/template.js +554 -0
  154. package/dist/templateCheck.d.ts +60 -0
  155. package/dist/templateCheck.js +516 -0
  156. package/dist/templateFit.d.ts +157 -0
  157. package/dist/templateFit.js +349 -0
  158. package/dist/templateIds.d.ts +138 -0
  159. package/dist/templateIds.js +144 -0
  160. package/dist/templateScopeAt.d.ts +131 -0
  161. package/dist/templateScopeAt.js +354 -0
  162. package/dist/testing.d.ts +177 -0
  163. package/dist/testing.js +383 -0
  164. package/dist/tokenizers.d.ts +113 -0
  165. package/dist/tokenizers.js +184 -0
  166. package/dist/turnLock.d.ts +96 -0
  167. package/dist/turnLock.js +79 -0
  168. package/dist/turnOrder.d.ts +143 -0
  169. package/dist/turnOrder.js +128 -0
  170. package/dist/validate.d.ts +74 -0
  171. package/dist/validate.js +1399 -0
  172. package/dist/values.d.ts +212 -0
  173. package/dist/values.js +390 -0
  174. package/dist/variables.d.ts +493 -0
  175. package/dist/variables.js +662 -0
  176. package/dist/verdicts.d.ts +275 -0
  177. package/dist/verdicts.js +348 -0
  178. package/dist/widgetDecls.d.ts +88 -0
  179. package/dist/widgetDecls.js +119 -0
  180. package/dist/widgets.d.ts +1527 -0
  181. package/dist/widgets.js +208 -0
  182. package/dist/wire.d.ts +126 -0
  183. package/dist/wire.js +140 -0
  184. package/dist/worldinfo.d.ts +150 -0
  185. package/dist/worldinfo.js +212 -0
  186. package/host-elements.d.ts +914 -0
  187. package/package.json +67 -0
@@ -0,0 +1,662 @@
1
+ /**
2
+ * Context variables as an open registry (F2 — ids namespaced, `core:` reserved).
3
+ *
4
+ * ## The inversion this exists to make
5
+ *
6
+ * A context template today writes `{{{characters}}}` and gets back a blob of
7
+ * JSON whose shape was decided in TypeScript — indentation and all. Which means
8
+ * "I want my characters rendered as prose instead of JSON" is not a
9
+ * configuration question at all; it is a code change. The template can decide
10
+ * *whether* characters appear and *where*, and has no say whatsoever in what
11
+ * they look like when they do.
12
+ *
13
+ * A variable declaration moves that decision into data. The producing node says
14
+ * "this slot renders `core:var/characters@1`", the registry says what is in
15
+ * scope when it renders and what a representative value looks like, and the
16
+ * actual presentation becomes a swappable row the same way a prompt is.
17
+ *
18
+ * ## Why `scope` is on the declaration and not inferred
19
+ *
20
+ * This is the same argument `SlotDecl.variables` makes for source templates and
21
+ * for the same reason (see descriptors.ts): the shape an author needs to write
22
+ * against lives *inside* a payload, not on a port. Typed ports can say a node
23
+ * emits `core:shape/json@1`; they cannot tell whoever is writing
24
+ * `{{#each characters}}{{ this.nickname }}` whether `nickname` is a field.
25
+ * Declaring it is what makes lint and autocomplete possible at all, and it is
26
+ * the "pass expected shapes down to the configuration" half of the feature.
27
+ *
28
+ * `sample` is the other half. A preview that renders against real chat data
29
+ * needs a chat; a preview that renders against a declared sample needs nothing,
30
+ * which is what lets the template editor show output while you type.
31
+ */
32
+ import { checkScopeSample, } from './template.js';
33
+ import { refuseUnlessIdentical } from './hash.js';
34
+ const variables = new Map();
35
+ /**
36
+ * Register a variable declaration.
37
+ *
38
+ * Two refusals, both the same rule the engine and renderer registries enforce:
39
+ * an id has exactly one owner, and `core:` is not for the taking. A plugin that
40
+ * could redefine `core:var/characters@1` would change how characters render in
41
+ * every pipeline on the instance without appearing in a single spec — invisible
42
+ * in exactly the way a prompt change is not.
43
+ * @experimental
44
+ */
45
+ export function defineVariable(decl) {
46
+ const existing = variables.get(decl.id);
47
+ if (existing)
48
+ refuseUnlessIdentical(existing, decl, `duplicate variable id: ${decl.id}`);
49
+ variables.set(decl.id, decl);
50
+ return decl;
51
+ }
52
+ /**
53
+ * The plugin-facing door. Same registration, minus the ability to claim core's
54
+ * namespace — checked here rather than in `defineVariable` so core's own
55
+ * declarations do not have to argue their way past their own guard.
56
+ * @experimental
57
+ */
58
+ export function definePluginVariable(pluginId, decl) {
59
+ if (decl.id.startsWith('core:'))
60
+ throw new Error(`plugin '${pluginId}' may not declare '${decl.id}': the 'core:' namespace is ` +
61
+ `reserved. Publish it under your own namespace — a variable two parties can ` +
62
+ `define is one where every template renders differently depending on load order.`);
63
+ return defineVariable(decl);
64
+ }
65
+ /** @internal */
66
+ export const getVariable = (id) => variables.get(id);
67
+ /** @internal */
68
+ export const allVariables = () => [...variables.values()];
69
+ /** @internal */
70
+ export function _clearVariables() {
71
+ variables.clear();
72
+ }
73
+ /**
74
+ * Take one variable back out of the registry — a HOST's door, for a plugin's
75
+ * variables it registered from a stored manifest and withdraws on uninstall
76
+ * (the way `_withdrawGenre` serves a plugin's genres). Refuses `core:` ids: core's
77
+ * variables are this build's, and nothing a plugin's lifecycle does removes them.
78
+ * @internal
79
+ */
80
+ export function _withdrawVariable(id) {
81
+ if (id.startsWith('core:'))
82
+ throw new Error(`'${id}' is core's; it is never withdrawn`);
83
+ return variables.delete(id);
84
+ }
85
+ /**
86
+ * What is wrong with a package's variable list, one sentence each — the check
87
+ * `defineExtension`, the packager and a host's install share (typed templates,
88
+ * 2026-09-27). Every id sits under the package's own namespace: `core:` is
89
+ * reserved and another package's namespace is theirs (F2). A list naming one
90
+ * id twice with different content is refused — an id means one thing.
91
+ * @experimental
92
+ */
93
+ export function pluginVariableFindings(slug, raw, at = 'variables') {
94
+ if (raw === undefined)
95
+ return [];
96
+ if (!Array.isArray(raw))
97
+ return [`'${at}' is not a list of variable declarations`];
98
+ const out = [];
99
+ const seen = new Map();
100
+ for (const [i, v] of raw.entries()) {
101
+ const d = v;
102
+ const id = typeof d?.id === 'string' ? d.id : '';
103
+ if (!id) {
104
+ out.push(`${at}[${i}] has no id — a variable is '<slug>:var/<name>@<major>'`);
105
+ continue;
106
+ }
107
+ const ns = id.includes(':') ? id.slice(0, id.indexOf(':')) : '';
108
+ if (ns === 'core')
109
+ out.push(`variable '${id}': the 'core:' namespace is reserved. Declare it as ` +
110
+ `'${slug}:${id.slice(id.indexOf(':') + 1)}'.`);
111
+ else if (ns !== slug)
112
+ out.push(`variable '${id}' is not in this package's namespace — declare it under ` +
113
+ `'${slug}:var/…'. A variable two packages can define renders differently by install order.`);
114
+ if (!d?.scope || typeof d.scope !== 'object' || Array.isArray(d.scope))
115
+ out.push(`variable '${id}' has no scope — what a template rendering it can name`);
116
+ const sig = JSON.stringify(d);
117
+ const prior = seen.get(id);
118
+ if (prior !== undefined && prior !== sig)
119
+ out.push(`variable '${id}' is declared twice with different content — an id means one thing`);
120
+ seen.set(id, sig);
121
+ }
122
+ return out;
123
+ }
124
+ // ── Core's variables ────────────────────────────────────────────────────────
125
+ //
126
+ // One per top-level value a context template renders. Declared here rather than
127
+ // in the host so that `slots.renders` in the contracts package can name them,
128
+ // and so a plugin reading the registry sees core's on the same terms as its own.
129
+ /**
130
+ * One character card, as `compileCharacter` actually builds it.
131
+ *
132
+ * ⚠ `exampleDialogue` is not on the card. It is a top-level variable
133
+ * (`core:var/example-dialogue@1`) resolved from the *speaking* character, and
134
+ * `compileCharacter` never puts it on a card.
135
+ *
136
+ * Nor is lore. Lore bound to a cast member that fit the budget is Assemble's
137
+ * `characterLore` (`core:var/character-lore@1`), a variable of its own that a
138
+ * context template places where it wants it — the card is the character as
139
+ * written, and nothing folds retrieved text into it.
140
+ *
141
+ * Everything but `name` is optional because `compileCharacter` deletes any key
142
+ * that came back null or undefined — deliberately, since these cards are
143
+ * stringified into the prompt and a `"personality": null` is a line the model
144
+ * reads. `personality` is also absent for every non-speaker when the
145
+ * session's `characterDetail` is `brief`, which is the whole point of that
146
+ * level; at `speaker-only` only the speaker's card is in the list at all.
147
+ */
148
+ const CHARACTER_CARD = {
149
+ type: 'object',
150
+ fields: {
151
+ name: { type: 'string', description: { en: 'What the character is called in the prompt.' } },
152
+ nickname: {
153
+ type: 'string',
154
+ optional: true,
155
+ description: { en: 'Their short name, when they have one.' },
156
+ },
157
+ description: {
158
+ type: 'string',
159
+ optional: true,
160
+ description: { en: 'Who they are.' },
161
+ },
162
+ personality: {
163
+ type: 'string',
164
+ optional: true,
165
+ description: { en: 'How they behave. Absent for a non-speaker when the session shows brief character detail.' },
166
+ },
167
+ },
168
+ };
169
+ const ash = {
170
+ name: 'Ash',
171
+ nickname: 'Ash',
172
+ description: 'A rider who patrols the ash wastes.',
173
+ personality: 'Terse, loyal, slow to trust.',
174
+ };
175
+ // No nickname. A sample where every row is fully populated
176
+ // teaches an author that every row will be, and the optional fields here are
177
+ // the ones a real cast drops most often.
178
+ const brannoc = {
179
+ name: 'Brannoc',
180
+ description: 'A caravan master who has crossed the wastes eleven times.',
181
+ personality: 'Genial, and counting.',
182
+ };
183
+ /** @experimental */
184
+ export const varInstructions = defineVariable({
185
+ id: 'core:var/instructions@1',
186
+ i18n: { name: { en: 'Instructions' } },
187
+ description: {
188
+ en: 'The system instructions for the reply, after macros are substituted.',
189
+ },
190
+ scope: { instructions: { type: 'string' } },
191
+ // Already interpolated, because that is how it arrives: macros expand
192
+ // upstream, and a sample still carrying `{{char}}` would read as a preview
193
+ // showing that macros do not work.
194
+ sample: 'You are Ash. Stay in character and never speak for Rell.',
195
+ });
196
+ /** @experimental */
197
+ export const varCharacters = defineVariable({
198
+ id: 'core:var/characters@1',
199
+ i18n: { name: { en: 'Characters' } },
200
+ description: {
201
+ en: 'Everyone in the scene except the user, with their descriptions.',
202
+ },
203
+ scope: { characters: { type: 'list', of: CHARACTER_CARD } },
204
+ sample: [ash, brannoc],
205
+ });
206
+ /** @experimental */
207
+ export const varPersonas = defineVariable({
208
+ id: 'core:var/personas@1',
209
+ i18n: { name: { en: 'Personas' } },
210
+ // Two fields. A persona's private lore is Assemble's `characterLore`, like
211
+ // every cast member's, never a field of this card.
212
+ //
213
+ // `description` is optional for a different reason than a character's is:
214
+ // personas are built by hand in `resolveContextInput` and never go through
215
+ // `compileCharacter`, so nothing strips a null. The key is always present
216
+ // and its value can be null, which a template cannot tell from absent.
217
+ description: { en: 'Who the user is playing, as the prompt sees them.' },
218
+ scope: {
219
+ personas: {
220
+ type: 'list',
221
+ of: {
222
+ type: 'object',
223
+ fields: {
224
+ name: { type: 'string' },
225
+ description: { type: 'string', optional: true },
226
+ },
227
+ },
228
+ },
229
+ },
230
+ sample: [{ name: 'Rell', description: 'A cartographer looking for a way north.' }],
231
+ });
232
+ /** @experimental */
233
+ export const varScenario = defineVariable({
234
+ id: 'core:var/scenario@1',
235
+ i18n: { name: { en: 'Scenario' } },
236
+ description: { en: 'The situation the scene opens in.' },
237
+ scope: { scenario: { type: 'string' } },
238
+ sample: 'The caravan has stopped at the edge of the wastes.',
239
+ });
240
+ /** @experimental */
241
+ export const varExampleDialogue = defineVariable({
242
+ id: 'core:var/example-dialogue@1',
243
+ i18n: { name: { en: 'Example dialogue' } },
244
+ description: { en: 'Sample exchanges that show the model how the characters speak.' },
245
+ scope: { exampleDialogue: { type: 'string' } },
246
+ // Interpolated, like `instructions` — the speaker's name is already
247
+ // substituted by the time a layout sees this.
248
+ sample: 'Ash: "Ash in the water again."',
249
+ });
250
+ /** @experimental */
251
+ export const varPostHistoryInstructions = defineVariable({
252
+ id: 'core:var/post-history-instructions@1',
253
+ i18n: { name: { en: 'Post-history instructions' } },
254
+ description: {
255
+ en: 'The reminder placed next to the generation point, after the conversation.',
256
+ },
257
+ scope: { postHistoryInstructions: { type: 'string' } },
258
+ sample: 'Stay in character and write one paragraph.',
259
+ });
260
+ /** @experimental */
261
+ export const varCharacterNames = defineVariable({
262
+ id: 'core:var/character-names@1',
263
+ i18n: { name: { en: 'Character names' } },
264
+ description: { en: 'Just the names of the characters in the scene.' },
265
+ // A **string**, not a list. `joinWithAnd` runs upstream, so what a layout
266
+ // receives is already "Ash and Brannoc" — and declaring it as a list would
267
+ // be the same class of lie the hand-written preview data used to tell about
268
+ // `worldLore`: a template written against it looks right in the editor and
269
+ // renders wrong in a chat. Saying `type: 'string'` is the first time the
270
+ // declaration has been able to state this rather than leave it to a comment.
271
+ scope: { characterNames: { type: 'string' } },
272
+ sample: 'Ash and Brannoc',
273
+ });
274
+ /** @experimental */
275
+ export const varPersonaNames = defineVariable({
276
+ id: 'core:var/persona-names@1',
277
+ i18n: { name: { en: 'Persona names' } },
278
+ description: { en: "Just the names of the user's personas in the scene." },
279
+ scope: { personaNames: { type: 'string' } },
280
+ sample: 'Rell',
281
+ });
282
+ // ── Produced during assembly ────────────────────────────────────────────────
283
+ //
284
+ // These come out the other side of the budget, so what reaches a layout
285
+ // is what actually *fit* — the entries allocation kept, not everything
286
+ // retrieval found. That is the reason they are declared at Assemble rather than
287
+ // alongside the cast: no earlier node knows the answer.
288
+ //
289
+ // `characterLore` is one of them: lore bound to a cast member, placed by the
290
+ // context template like world lore. It reaches the prompt only where a
291
+ // template writes `{{{characterLore}}}` — the shipped template does.
292
+ /** @experimental */
293
+ export const varWorldLore = defineVariable({
294
+ id: 'core:var/world-lore@1',
295
+ i18n: { name: { en: 'World lore' } },
296
+ description: {
297
+ en: 'Lorebook entries about the world that fit the budget, keyed by entry name.',
298
+ },
299
+ // `'any'` could not say this, and the shape it could not say is exactly the
300
+ // one a hand-written preview got wrong once already.
301
+ scope: { worldLore: { type: 'record', of: { type: 'string' } } },
302
+ sample: {
303
+ 'The Ashguard': 'Riders who patrol the ash wastes.',
304
+ 'The Long Winter': 'Nine years without a thaw.',
305
+ },
306
+ });
307
+ /** @experimental */
308
+ export const varHistory = defineVariable({
309
+ id: 'core:var/history@1',
310
+ // "Story history" until 0.6. It is a *list of dated history entries*, and
311
+ // calling it a story invited people to look for the story — the summary of
312
+ // the chat so far, which is a different feature that does not exist here.
313
+ i18n: { name: { en: 'History entries' } },
314
+ description: {
315
+ en: 'Earlier events from the chat that fit the budget, newest first, keyed by date.',
316
+ },
317
+ scope: { history: { type: 'record', of: { type: 'string' } } },
318
+ sample: {
319
+ 'Year 412, Month 3': 'The caravan reached the wastes.',
320
+ 'Year 412, Month 1': 'Ash left the Ashguard.',
321
+ },
322
+ });
323
+ /**
324
+ * Documentation excerpts retrieved for the latest question — the band
325
+ * `core:query/docs-search@1` publishes (the guide genre's retrieval; declared
326
+ * 2026-09-27). Its own band, not `worldLore`: an excerpt is the app's manual,
327
+ * not a fact about a story's world, and a template has to be able to frame it
328
+ * as the one source of truth about the app — and to say so when it is empty.
329
+ *
330
+ * Keyed by "Page › Section"; each value begins with the page's path
331
+ * (`Path: /docs/<slug>#<anchor>`), so the address a reply cites is the one
332
+ * the compiled docs actually serve.
333
+ * @experimental
334
+ */
335
+ export const varDocsExcerpts = defineVariable({
336
+ id: 'core:var/docs-excerpts@1',
337
+ i18n: { name: { en: 'Documentation excerpts' } },
338
+ description: {
339
+ en: 'Documentation sections that match the latest question and fit the budget, keyed by page and section; each starts with the page path.',
340
+ },
341
+ scope: { docsExcerpts: { type: 'record', of: { type: 'string' } } },
342
+ sample: {
343
+ 'Connections › Adding and removing by hand': 'Path: /docs/connections#adding-and-removing-by-hand\nOpen Connections and choose Add…',
344
+ },
345
+ });
346
+ /**
347
+ * Recalled lines — older transcript lines found again because they name what
348
+ * the current context names: the band `core:query/entity-search@1` publishes
349
+ * on its `messages` out-port (declared 2026-09-27, owner ruling option b).
350
+ *
351
+ * Its own band, not `messages`: the transcript renders from the recent
352
+ * window (`sessionMessages`), so a recalled line in the transcript's band was
353
+ * budgeted and then rendered nowhere. As a declared band a template places it
354
+ * where it belongs — `{{{recalledLines}}}` — per genre; nothing places it
355
+ * automatically.
356
+ *
357
+ * One entry per line, oldest first. `turn` is the line's 1-based position in
358
+ * its channel's visible transcript, so "turn 12" is the twelfth message a
359
+ * reader of that channel would count; `speaker` is named by the same chain
360
+ * that names the transcript's own lines.
361
+ *
362
+ * Not *recall* the measurement (precision/recall): a **recalled line** is a
363
+ * line, and the qualifier is what keeps the two apart (R3).
364
+ * @experimental
365
+ */
366
+ export const varRecalledLines = defineVariable({
367
+ id: 'core:var/recalled-lines@1',
368
+ i18n: { name: { en: 'Recalled lines' } },
369
+ description: {
370
+ en: 'Earlier lines of the conversation that name what the scene is naming now and fit the budget, oldest first — each with its speaker, turn and text.',
371
+ },
372
+ scope: {
373
+ recalledLines: {
374
+ type: 'list',
375
+ of: {
376
+ type: 'object',
377
+ fields: {
378
+ speaker: { type: 'string', description: { en: 'Who said it.' } },
379
+ turn: {
380
+ type: 'number',
381
+ description: {
382
+ en: "The line's position in its channel's conversation, counting from 1.",
383
+ },
384
+ },
385
+ text: { type: 'string', description: { en: 'What was said.' } },
386
+ },
387
+ },
388
+ },
389
+ },
390
+ sample: [
391
+ { speaker: 'Mira', turn: 12, text: 'I hid the brass key under the chapel floor.' },
392
+ { speaker: 'Ada', turn: 31, text: 'The chapel? Mira, the chapel burned.' },
393
+ ],
394
+ });
395
+ /**
396
+ * One admitted character-lore entry: its title, whose it is, and its text.
397
+ *
398
+ * `castMember` is the member the entry is bound to, named as the session's
399
+ * reading has them (a card's name, nickname first, else the member's own).
400
+ * Absent for an entry bound to nobody — the world's knowledge, which only the
401
+ * narrator reads.
402
+ */
403
+ const CHARACTER_LORE_ENTRY = {
404
+ type: 'object',
405
+ fields: {
406
+ title: { type: 'string', description: { en: 'The entry’s title.' } },
407
+ castMember: {
408
+ type: 'string',
409
+ optional: true,
410
+ description: { en: 'Whose lore it is. Absent when the entry is bound to nobody.' },
411
+ },
412
+ content: { type: 'string', description: { en: 'What the entry says.' } },
413
+ },
414
+ };
415
+ /**
416
+ * Lore bound to a cast member that fit the budget — Assemble's
417
+ * `characterLore`, one entry per admitted row in the order they were ranked.
418
+ *
419
+ * Privacy is decided before this: the lore read gives a speaker only the
420
+ * entries that speaker may see (`core:policy/binding-visibility@1`) — their
421
+ * own and the personas'; for the narrator, the background members' and the
422
+ * entries bound to nobody. A template renders it where it wants it,
423
+ * typically beside the character cards.
424
+ * @experimental
425
+ */
426
+ export const varCharacterLore = defineVariable({
427
+ id: 'core:var/character-lore@1',
428
+ i18n: { name: { en: 'Character lore' } },
429
+ description: {
430
+ en: 'Lore bound to a cast member that fit the budget: each entry’s title, whose it is, and its text.',
431
+ },
432
+ scope: { characterLore: { type: 'list', of: CHARACTER_LORE_ENTRY } },
433
+ sample: [
434
+ { title: 'The Ashguard brand', castMember: 'Ash', content: 'Carries a brand from the Ashguard.' },
435
+ ],
436
+ });
437
+ /** One relationship as the prompt sees it — `relEntry` in graphContextFormatter. */
438
+ const RELATIONSHIP = {
439
+ type: 'object',
440
+ fields: {
441
+ type: { type: 'string', description: { en: 'What the relationship is.' } },
442
+ secrecy: {
443
+ type: 'string',
444
+ description: { en: 'Who knows about it — "Only I know", "We both know", and so on.' },
445
+ },
446
+ status: {
447
+ type: 'string',
448
+ optional: true,
449
+ description: { en: 'Only present when it is something other than active.' },
450
+ },
451
+ theirState: {
452
+ type: 'string',
453
+ optional: true,
454
+ description: { en: "The other party's node state, when it is not active." },
455
+ },
456
+ note: { type: 'string', optional: true, description: { en: 'The written detail.' } },
457
+ },
458
+ };
459
+ /** Relationships grouped under the *other* party's name. */
460
+ const BY_OTHER = { type: 'record', of: { type: 'list', of: RELATIONSHIP } };
461
+ /**
462
+ * The speaker-centric relationship summary from the narrative graph.
463
+ *
464
+ * ⚠ This was declared `'any'` and carried a **pre-stringified string** —
465
+ * `buildGraphContext` called `JSON.stringify(graph, null, 1)` before the value
466
+ * ever reached a template, so the layout was a passthrough. That made it the
467
+ * one context value a layout could do nothing with: not prose, not a dropped
468
+ * section, not even a different indent, because the shape had already been
469
+ * flattened upstream. The node now emits the structure and the layout does the
470
+ * rendering, which is the same inversion `characters` got.
471
+ *
472
+ * All three sections are conditional. An install with no legendary figures has
473
+ * no `legendaryFigures` key at all rather than an empty object, and the shipped
474
+ * layout's guards are written against exactly that.
475
+ *
476
+ * Distinct from `narrativeGraph`, which the infill engines populated and which
477
+ * nothing renders any more: this one is speaker-centric and always-on wherever
478
+ * a chat has a lorebook and the speaker has a bound node.
479
+ */
480
+ /**
481
+ * How the speaking character regards everyone else.
482
+ *
483
+ * ⚠ Split, with its sibling below, out of `core:var/speaker-relationships@1`.
484
+ * That one variable held both directions and the legendary figures under a
485
+ * single "Your relationships:" heading — so a model was handed what the speaker
486
+ * thinks of Brannoc and what Rell thinks of the speaker as one undifferentiated
487
+ * list, and a user who wanted one and not the other had no setting for it. Two
488
+ * variables means two layouts, two priorities and two switches.
489
+ * @experimental
490
+ */
491
+ export const varRelationshipsPerspectives = defineVariable({
492
+ id: 'core:var/relationships-perspectives@1',
493
+ i18n: { name: { en: 'Relationships: their perspective' } },
494
+ description: {
495
+ en: 'How the speaking character regards each of the others, from the narrative graph.',
496
+ },
497
+ scope: {
498
+ relationshipsPerspectives: {
499
+ ...BY_OTHER,
500
+ description: { en: 'How the speaker regards each other character.' },
501
+ },
502
+ },
503
+ sample: {
504
+ Brannoc: [
505
+ {
506
+ type: 'wary respect',
507
+ secrecy: 'Only I know',
508
+ note: 'Ash has never forgotten who opened the lower gate.',
509
+ },
510
+ ],
511
+ },
512
+ });
513
+ /**
514
+ * How everyone else regards the speaking character, and who the world knows of.
515
+ *
516
+ * `legendaryFigures` sits here rather than in its own variable because it is
517
+ * the same kind of claim — what is publicly known — and the opposite kind from
518
+ * "what you think of them". A third variable would put a mostly-empty block in
519
+ * every prompt on every install that has never marked a node legendary.
520
+ *
521
+ * Both sections are conditional: an install with no legendary figures has no
522
+ * `legendaryFigures` key at all rather than an empty object, and the shipped
523
+ * layout's guards are written against exactly that.
524
+ * @experimental
525
+ */
526
+ export const varRelationshipsKnown = defineVariable({
527
+ id: 'core:var/relationships-known@1',
528
+ i18n: { name: { en: 'Relationships: how others see them' } },
529
+ description: {
530
+ en: 'How the others regard the speaking character, plus any figures the world knows of.',
531
+ },
532
+ scope: {
533
+ relationshipsKnown: {
534
+ type: 'object',
535
+ fields: {
536
+ howOthersRegardYou: {
537
+ ...BY_OTHER,
538
+ optional: true,
539
+ description: { en: 'How each other character regards the speaker.' },
540
+ },
541
+ legendaryFigures: {
542
+ type: 'record',
543
+ optional: true,
544
+ description: { en: 'Figures the world knows of, and their public relationships.' },
545
+ of: {
546
+ type: 'object',
547
+ fields: {
548
+ summary: { type: 'string', optional: true },
549
+ state: { type: 'string', optional: true },
550
+ relationships: { ...BY_OTHER, optional: true },
551
+ },
552
+ },
553
+ },
554
+ },
555
+ },
556
+ },
557
+ sample: {
558
+ howOthersRegardYou: {
559
+ Rell: [
560
+ {
561
+ type: 'debt',
562
+ secrecy: 'We both know',
563
+ status: 'evolved',
564
+ note: 'Rell owes Ash for the crossing.',
565
+ },
566
+ ],
567
+ },
568
+ },
569
+ });
570
+ /** @experimental */
571
+ export const varCurrentDate = defineVariable({
572
+ id: 'core:var/current-date@1',
573
+ i18n: { name: { en: 'Current date' } },
574
+ description: {
575
+ en: "The story's present date: the lorebook's clock when it is set, else the most recent history entry.",
576
+ },
577
+ /**
578
+ * ⚠ Was `{ currentDate: { type: 'string' } }` with the sample
579
+ * `'Year 412, Month 3'`, and the sample was **wrong** — the value arrived
580
+ * pre-formatted by `formatDate` as `412-03`, so the preview showed a
581
+ * rendering the prompt never contained. That is the failure mode a sample
582
+ * exists to prevent, and it happened because the shape was a finished
583
+ * string: nothing could disagree with the formatting, so nothing did.
584
+ *
585
+ * The parts travel separately now and the layout joins them, which is what
586
+ * makes "state the date differently" a setting rather than a code change.
587
+ * `month` and `day` are absent rather than null when the entry has no such
588
+ * precision — `{{#if (isSet …)}}` is what a layout tests.
589
+ */
590
+ scope: {
591
+ currentDate: {
592
+ type: 'object',
593
+ fields: {
594
+ year: { type: 'number', description: { en: 'The story year.' } },
595
+ month: {
596
+ type: 'number',
597
+ optional: true,
598
+ description: { en: 'Absent when the entry is only dated to a year.' },
599
+ },
600
+ day: {
601
+ type: 'number',
602
+ optional: true,
603
+ description: { en: 'Absent when the entry is only dated to a month.' },
604
+ },
605
+ hour: {
606
+ type: 'number',
607
+ optional: true,
608
+ description: { en: "The clock's hour (0–23), when the present has a time of day." },
609
+ },
610
+ minute: {
611
+ type: 'number',
612
+ optional: true,
613
+ description: { en: "The clock's minute, when the present has a time of day." },
614
+ },
615
+ label: {
616
+ type: 'string',
617
+ optional: true,
618
+ description: {
619
+ en: "The date spelled through the lorebook's calendar; absent when the book is free-form.",
620
+ },
621
+ },
622
+ },
623
+ },
624
+ },
625
+ sample: { year: 412, month: 3, day: 5 },
626
+ });
627
+ // ── Samples ─────────────────────────────────────────────────────────────────
628
+ /**
629
+ * A declaration's `sample`, spread across the keys of its `scope`.
630
+ *
631
+ * Nearly every variable declares a single-key scope named for itself, and its
632
+ * `sample` is that key's value. A declaration with several keys has to supply
633
+ * an object covering them, which is the only reading that lets a variable whose
634
+ * presentation depends on a second value describe itself at all.
635
+ *
636
+ * This lives here rather than in the host because two things need it and they
637
+ * must agree: the preview that renders a layout against the sample, and the
638
+ * check that the sample matches the schema. A convention implemented twice is
639
+ * one that eventually holds in one place and not the other, and the failure
640
+ * would be a preview quietly rendering against `undefined`.
641
+ * @internal
642
+ */
643
+ export function sampleValues(decl) {
644
+ const keys = Object.keys(decl.scope);
645
+ if (keys.length === 1)
646
+ return { [keys[0]]: decl.sample };
647
+ const asRecord = (decl.sample ?? {});
648
+ return Object.fromEntries(keys.map((k) => [k, asRecord[k]]));
649
+ }
650
+ /**
651
+ * Every declared variable whose sample does not match its own schema.
652
+ *
653
+ * Exported rather than left in the test because it is the same check a plugin's
654
+ * variable needs at publish time, and because "the sample is a lie" is a defect
655
+ * an installed plugin can carry just as easily as core can — as core did, in
656
+ * two fields of one declaration, for the entire life of this registry.
657
+ * @experimental
658
+ */
659
+ export function checkVariableSamples(decls = allVariables()) {
660
+ return decls.flatMap((d) => checkScopeSample(sampleValues(d), d.scope, d.id));
661
+ }
662
+ //# sourceMappingURL=variables.js.map