@serene-pub/sdk 0.6.0-pr-6 → 0.6.0-pr-8

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 (111) hide show
  1. package/dist/actions.d.ts +23 -0
  2. package/dist/actions.js +36 -1
  3. package/dist/annexFields.d.ts +42 -1
  4. package/dist/annexFields.js +54 -5
  5. package/dist/announce.d.ts +26 -13
  6. package/dist/announce.js +31 -0
  7. package/dist/appletCard.d.ts +17 -0
  8. package/dist/appletCard.js +60 -0
  9. package/dist/attributes.d.ts +51 -2
  10. package/dist/attributes.js +32 -1
  11. package/dist/builder.d.ts +25 -8
  12. package/dist/builder.js +59 -7
  13. package/dist/cadences.d.ts +18 -2
  14. package/dist/cadences.js +34 -2
  15. package/dist/capabilities.d.ts +13 -2
  16. package/dist/capabilities.js +28 -1
  17. package/dist/characterProfile.d.ts +137 -0
  18. package/dist/characterProfile.js +24 -0
  19. package/dist/component.d.ts +6 -1
  20. package/dist/componentClient.d.ts +42 -6
  21. package/dist/componentImports.d.ts +1 -1
  22. package/dist/componentImports.js +2 -0
  23. package/dist/componentWire.js +22 -4
  24. package/dist/declarations.d.ts +15 -0
  25. package/dist/declarations.js +33 -0
  26. package/dist/descriptors.d.ts +168 -2
  27. package/dist/descriptors.js +110 -5
  28. package/dist/document.d.ts +8 -0
  29. package/dist/document.js +44 -1
  30. package/dist/events.d.ts +199 -4
  31. package/dist/events.js +74 -3
  32. package/dist/executor.js +26 -5
  33. package/dist/extension.d.ts +144 -3
  34. package/dist/extension.js +43 -0
  35. package/dist/fit.d.ts +4 -1
  36. package/dist/fit.js +43 -1
  37. package/dist/functions.d.ts +7 -1
  38. package/dist/functions.js +3 -1
  39. package/dist/genres.d.ts +27 -2
  40. package/dist/genres.js +72 -5
  41. package/dist/hookGrants.d.ts +14 -0
  42. package/dist/hookGrants.js +21 -10
  43. package/dist/hooks.d.ts +15 -2
  44. package/dist/hostElements.d.ts +1 -1
  45. package/dist/hostElements.js +8 -2
  46. package/dist/index.d.ts +8 -0
  47. package/dist/index.js +17 -0
  48. package/dist/jsonSchema.js +14 -2
  49. package/dist/layout.d.ts +18 -0
  50. package/dist/libraryDraft.d.ts +29 -0
  51. package/dist/libraryDraft.js +29 -0
  52. package/dist/lorebookFile.d.ts +52 -0
  53. package/dist/lorebookFile.js +223 -0
  54. package/dist/participants.d.ts +53 -8
  55. package/dist/participants.js +9 -5
  56. package/dist/pluginHarness.d.ts +50 -2
  57. package/dist/pluginHarness.js +65 -4
  58. package/dist/pluginPermissions.d.ts +15 -1
  59. package/dist/pluginPermissions.js +29 -2
  60. package/dist/promptBlocks.d.ts +5 -1
  61. package/dist/promptBlocks.js +23 -8
  62. package/dist/receiverRules.js +9 -0
  63. package/dist/registry.js +6 -3
  64. package/dist/rulesetDocument.d.ts +21 -0
  65. package/dist/rulesetDocument.js +64 -2
  66. package/dist/rulesetSections.d.ts +37 -3
  67. package/dist/rulesetSections.js +47 -8
  68. package/dist/sceneSettings.d.ts +4 -0
  69. package/dist/sceneSettings.js +7 -4
  70. package/dist/sessionDossier.d.ts +90 -0
  71. package/dist/sessionLayout.d.ts +296 -85
  72. package/dist/sessionLayout.js +397 -133
  73. package/dist/settings.d.ts +102 -5
  74. package/dist/settings.js +343 -6
  75. package/dist/shapes.d.ts +46 -1
  76. package/dist/shapes.js +54 -2
  77. package/dist/sheetLatitude.d.ts +148 -0
  78. package/dist/sheetLatitude.js +161 -0
  79. package/dist/speech.d.ts +333 -0
  80. package/dist/speech.js +199 -0
  81. package/dist/storage.d.ts +44 -0
  82. package/dist/storyTime.d.ts +25 -1
  83. package/dist/storyTime.js +48 -6
  84. package/dist/surfaces.d.ts +25 -2
  85. package/dist/template.d.ts +45 -2
  86. package/dist/template.js +25 -11
  87. package/dist/templateCheck.d.ts +24 -0
  88. package/dist/templateCheck.js +299 -7
  89. package/dist/templateFit.js +4 -0
  90. package/dist/templateIds.d.ts +6 -0
  91. package/dist/templateIds.js +9 -0
  92. package/dist/ties.d.ts +1 -0
  93. package/dist/ties.js +2 -1
  94. package/dist/turnLock.d.ts +10 -1
  95. package/dist/turnLock.js +6 -1
  96. package/dist/turnOrder.d.ts +37 -4
  97. package/dist/turnOrder.js +49 -11
  98. package/dist/userAnnex.d.ts +126 -0
  99. package/dist/userAnnex.js +214 -0
  100. package/dist/validate.d.ts +4 -2
  101. package/dist/validate.js +15 -11
  102. package/dist/values.js +6 -0
  103. package/dist/variableLayouts.d.ts +141 -0
  104. package/dist/variableLayouts.js +183 -0
  105. package/dist/variables.d.ts +35 -7
  106. package/dist/variables.js +34 -1
  107. package/dist/widgetDecls.js +12 -0
  108. package/dist/widgets.d.ts +848 -48
  109. package/dist/widgets.js +221 -3
  110. package/host-elements.d.ts +5 -3
  111. package/package.json +1 -1
package/dist/actions.d.ts CHANGED
@@ -100,6 +100,25 @@ export interface CollectedText {
100
100
  * @ruling R-20
101
101
  */
102
102
  ifEmpty?: I18n;
103
+ /**
104
+ * Ready-made answers the modal offers as chips above the box; choosing one
105
+ * fills the box with its `value`. `common` ones show first, the rest sit
106
+ * behind a "More" disclosure. `icon` is a lucide kebab name. Display text.
107
+ */
108
+ suggestions?: Array<{
109
+ value: string;
110
+ label: I18n;
111
+ icon?: string;
112
+ common?: boolean;
113
+ }>;
114
+ /** `session`: the viewer's last answer to this action is remembered per session and offered next time. */
115
+ remember?: (typeof TEXT_REMEMBER)[number];
116
+ /**
117
+ * A one-line preview drawn under the box while it holds a value:
118
+ * `{subject}` is the first words of the message the action was pressed on,
119
+ * `{value}` the box's text. Display text.
120
+ */
121
+ preview?: I18n;
103
122
  }
104
123
  /**
105
124
  * The cast members an action collects before it fires: a multiselect over
@@ -165,6 +184,10 @@ export declare const CLOCK_STEP_MAX = 10000;
165
184
  * @experimental
166
185
  */
167
186
  export declare function clockStepRefusal(raw: unknown): string | null;
187
+ /** The most suggestions one collected text may offer. @experimental */
188
+ export declare const MAX_TEXT_SUGGESTIONS = 40;
189
+ /** Where a collected text's last value is remembered (per viewer). @experimental */
190
+ export declare const TEXT_REMEMBER: readonly ['session'];
168
191
  /**
169
192
  * The venues a `world` action may appear in: never a form, the extra tab or a
170
193
  * widget.
package/dist/actions.js CHANGED
@@ -95,7 +95,19 @@ export function clockStepRefusal(raw) {
95
95
  /** The keys `ActionDecl.collects` may carry, and each request's own keys. */
96
96
  const COLLECTS_KEYS = ['text', 'recipients', 'clockStep'];
97
97
  const COLLECTED_CLOCK_STEP_KEYS = ['label', 'default'];
98
- const COLLECTED_TEXT_KEYS = ['need', 'label', 'placeholder', 'ifEmpty'];
98
+ const COLLECTED_TEXT_KEYS = [
99
+ 'need',
100
+ 'label',
101
+ 'placeholder',
102
+ 'ifEmpty',
103
+ 'suggestions',
104
+ 'remember',
105
+ 'preview',
106
+ ];
107
+ /** The most suggestions one collected text may offer. @experimental */
108
+ export const MAX_TEXT_SUGGESTIONS = 40;
109
+ /** Where a collected text's last value is remembered (per viewer). @experimental */
110
+ export const TEXT_REMEMBER = ['session'];
99
111
  const COLLECTED_RECIPIENTS_KEYS = ['label', 'min', 'max', 'overwrites'];
100
112
  /**
101
113
  * The venues a `world` action may appear in: never a form, the extra tab or a
@@ -305,6 +317,29 @@ export function collectsFindings(raw, where) {
305
317
  `empty submit does ('The room decides.')`);
306
318
  else
307
319
  out.push(...i18nFindings(t.ifEmpty, `${at}.ifEmpty`));
320
+ out.push(...i18nFindings(t.preview, `${at}.preview`));
321
+ if (t.remember !== undefined && !TEXT_REMEMBER.includes(t.remember))
322
+ out.push(`${at}.remember is one of ${TEXT_REMEMBER.join(', ')} — where the last answer is remembered`);
323
+ if (t.suggestions !== undefined) {
324
+ const sg = t.suggestions;
325
+ if (!Array.isArray(sg) || sg.length === 0 || sg.length > MAX_TEXT_SUGGESTIONS)
326
+ out.push(`${at}.suggestions is a list of 1 to ${MAX_TEXT_SUGGESTIONS} { value, label, icon?, common? }`);
327
+ else
328
+ sg.forEach((x, i) => {
329
+ const w = `${at}.suggestions[${i}]`;
330
+ if (!x || typeof x !== 'object' || Array.isArray(x))
331
+ return void out.push(`${w} is { value, label, icon?, common? }`);
332
+ const o = x;
333
+ unknownKeys(o, ['value', 'label', 'icon', 'common'], w);
334
+ if (typeof o.value !== 'string' || !o.value.trim())
335
+ out.push(`${w}.value is the text the chip fills in — a non-empty string`);
336
+ out.push(...i18nFindings(o.label, `${w}.label`, { required: true }));
337
+ if (o.icon !== undefined && (typeof o.icon !== 'string' || !/^[a-z0-9]+(-[a-z0-9]+)*$/.test(o.icon)))
338
+ out.push(`${w}.icon is a lucide kebab name ('smile')`);
339
+ if (o.common !== undefined && typeof o.common !== 'boolean')
340
+ out.push(`${w}.common is a boolean`);
341
+ });
342
+ }
308
343
  }
309
344
  }
310
345
  if (c.recipients !== undefined) {
@@ -84,6 +84,34 @@ export interface AnnexFieldDecl {
84
84
  readonly act?: readonly string[];
85
85
  /** The genre id whose sessions offer it; absent is every session the package is on. */
86
86
  readonly genre?: string;
87
+ /**
88
+ * 🚧 Which annex holds the value (M0, SHAPES L9): `session` — the
89
+ * **session annex**, as every field before; `lorebook` — the **lorebook
90
+ * annex**, the book's own document under the same owner. Absent reads as
91
+ * `session`.
92
+ * 🚧 (M2b) `user` — the **user annex**: the acting person's own documents
93
+ * under the same owner. A user-scoped field's `key` is an exact key
94
+ * (`profile`) or a family ending in `/` (`saves/` covers `saves/<anything>`);
95
+ * its `shape` applies to each document; `act`, `see` and `genre` are refused
96
+ * on it (only the person and the package reach those documents).
97
+ * ⚠ Not an attribute's `scope` (`session` | `world`, whether a stat
98
+ * survives sessions) — the annex's own question, which document.
99
+ */
100
+ readonly scope?: 'session' | 'lorebook' | 'user';
101
+ /** 🚧 The value follows the player into the next chapter (M0, F5): a `next-chapter` session copies it. */
102
+ readonly nextChapter?: true;
103
+ /**
104
+ * 🚧 The value stays when the turn that wrote it is replaced — a swipe, a
105
+ * regenerate, a failed run — and goes when the turn leaves (Back, delete).
106
+ * For a genre that tells a turn again from what it decided: its plan is not
107
+ * written again, so it must not be taken back. Absent means it goes with the
108
+ * turn either way. `session` scope only: only a session's annex is taken back
109
+ * with a turn.
110
+ * @experimental
111
+ * ⚠ Not a cast member's _retold_ field (NOMENCLATURE §8 **retold** — a card
112
+ * field told in the member's own words); a near-neighbour word.
113
+ */
114
+ readonly keepOnRetell?: true;
87
115
  /** What a listing calls the action. Default: the key. */
88
116
  readonly label?: I18n;
89
117
  readonly description?: I18n;
@@ -98,6 +126,12 @@ export type AnnexFieldInput = {
98
126
  genre?: {
99
127
  readonly id: string;
100
128
  } | string;
129
+ /** 🚧 `session` (the default) or `lorebook` — {@link AnnexFieldDecl.scope}. */
130
+ scope?: 'session' | 'lorebook' | 'user';
131
+ /** 🚧 The value follows the player into the next chapter — {@link AnnexFieldDecl.nextChapter}. */
132
+ nextChapter?: true;
133
+ /** 🚧 The value stays when its turn is replaced — {@link AnnexFieldDecl.keepOnRetell}. */
134
+ keepOnRetell?: true;
101
135
  label?: I18n;
102
136
  description?: I18n;
103
137
  };
@@ -159,11 +193,18 @@ export declare const annexOwners: () => string[];
159
193
  export declare const annexDeclarationOf: (owner: string) => readonly AnnexFieldDecl[] | undefined;
160
194
  /**
161
195
  * The fields of a declaration in force for a session of `genre`: every
162
- * unscoped field and the ones scoped to that genre. With no genre — a
196
+ * unscoped field and the ones scoped to that genre (a `user`-scoped field
197
+ * never — it lives in no session). With no genre — a
163
198
  * document judged before it knows its session — every field, whatever genre
164
199
  * it is scoped to. Pure. @experimental
165
200
  */
166
201
  export declare function annexFieldsInGenre(fields: readonly AnnexFieldDecl[], genre?: string): AnnexFieldDecl[];
202
+ /**
203
+ * 🚧 (M2b) The declared field covering a user annex key: the exact key first,
204
+ * then the longest family (`saves/`) that prefixes it. Only `scope: 'user'`
205
+ * fields are considered. Pure. @experimental
206
+ */
207
+ export declare function userAnnexFieldFor(fields: readonly AnnexFieldDecl[], key: string): AnnexFieldDecl | undefined;
167
208
  /** Whether a declared field may be set by a person, through its ready-made action. @experimental */
168
209
  export declare const isSettableAnnexField: (f: Pick<AnnexFieldDecl, 'act'>) => boolean;
169
210
  /**
@@ -53,6 +53,7 @@ import { dataAudienceFindings, isParticipantRef } from './participants.js';
53
53
  import { checkSchema, checkValues } from './settings.js';
54
54
  import { i18nFindings } from './i18n.js';
55
55
  import { isDataRef } from './refs.js';
56
+ import { userAnnexKeyRefusal } from './userAnnex.js';
56
57
  /** An annex field's key: a lowercase kebab token, the second half of its action identity. @experimental */
57
58
  export const ANNEX_FIELD_KEY = /^[a-z][a-z0-9-]*$/;
58
59
  /**
@@ -88,7 +89,13 @@ export function annexFieldFindings(raw, at = 'annexFields') {
88
89
  const f = raw;
89
90
  const where = `${at}[${typeof f.key === 'string' ? f.key : '?'}]`;
90
91
  const out = [];
91
- if (typeof f.key !== 'string' || !ANNEX_FIELD_KEY.test(f.key))
92
+ if (f.scope === 'user') {
93
+ const bare = typeof f.key === 'string' && f.key.endsWith('/') ? f.key.slice(0, -1) : f.key;
94
+ const why = userAnnexKeyRefusal(bare);
95
+ if (why)
96
+ out.push(`${where}: ${why} A user-scoped field's key is an exact key ('profile') or a family ending in '/' ('saves/').`);
97
+ }
98
+ else if (typeof f.key !== 'string' || !ANNEX_FIELD_KEY.test(f.key))
92
99
  out.push(`${where}: 'key' is a lowercase kebab token (${ANNEX_FIELD_KEY.source}) — the field sits in ` +
93
100
  `your own package's annex document, so it never names an owner`);
94
101
  const shape = f.shape;
@@ -98,13 +105,25 @@ export function annexFieldFindings(raw, at = 'annexFields') {
98
105
  out.push(`${where}: the shape holds a secret — the annex never keeps credentials or personal data ` +
99
106
  `(R61); keep a secret in plugin settings`);
100
107
  else
101
- for (const finding of checkSchema({ [String(f.key)]: shape }))
108
+ for (const finding of checkSchema({ [f.scope === 'user' ? 'value' : String(f.key)]: shape }))
102
109
  if (finding.severity === 'error')
103
110
  out.push(`${where}: ${finding.message} — ${finding.fix}`);
104
111
  const see = dataAudienceFindings(f.see);
105
112
  if (see)
106
113
  out.push(`${where}.see: ${see}`);
107
- if (f.act !== undefined) {
114
+ if (f.scope === 'user') {
115
+ if (f.act !== undefined)
116
+ out.push(`${where}.act: a user-scoped field has no 'act' — only the person and the package reach a user annex document, and no widget press sets one`);
117
+ if (f.see !== undefined && !(Array.isArray(f.see) && f.see.length === 0))
118
+ out.push(`${where}.see: a user-scoped field has no 'see' — only the person and the package reach a user annex document`);
119
+ if (f.genre !== undefined)
120
+ out.push(`${where}.genre: a user-scoped field is not bound to a genre — a person's documents follow them across sessions`);
121
+ if (f.nextChapter !== undefined)
122
+ out.push(`${where}.nextChapter: a user-scoped field is not part of a session, so nothing follows into a chapter`);
123
+ if (f.keepOnRetell !== undefined)
124
+ out.push(`${where}.keepOnRetell: a user-scoped field is not taken back with a turn, so there is nothing to keep — only a session-scope field can keep its value`);
125
+ }
126
+ if (f.act !== undefined && f.scope !== 'user') {
108
127
  if (!Array.isArray(f.act) || !f.act.length)
109
128
  out.push(`${where}.act: a non-empty list of participant references — who may set the value`);
110
129
  else
@@ -120,6 +139,15 @@ export function annexFieldFindings(raw, at = 'annexFields') {
120
139
  if (typeof g !== 'string' || !/^[a-z0-9.-]+:genre\/[a-z0-9.-]+/.test(g))
121
140
  out.push(`${where}.genre: a genre — the value genre() returned, or its id ('acme.dice:genre/table')`);
122
141
  }
142
+ if (f.scope !== undefined && f.scope !== 'session' && f.scope !== 'lorebook' && f.scope !== 'user')
143
+ out.push(`${where}.scope: 'session' (the session annex, the default), 'lorebook' (the lorebook annex) or 'user' (the user annex) — ` +
144
+ `'${String(f.scope)}' is neither`);
145
+ if (f.scope === 'lorebook' && f.keepOnRetell !== undefined)
146
+ out.push(`${where}.keepOnRetell: a session-scope field only — a lorebook-scope field's change is a lorebook write, and goes back with its turn as every lorebook write does`);
147
+ if (f.keepOnRetell !== undefined && f.keepOnRetell !== true)
148
+ out.push(`${where}.keepOnRetell: true or absent — the value stays when its turn is told again`);
149
+ if (f.nextChapter !== undefined && f.nextChapter !== true)
150
+ out.push(`${where}.nextChapter: true or absent — the value follows the player into the next chapter`);
123
151
  out.push(...i18nFindings(f.label, `${where}.label`));
124
152
  out.push(...i18nFindings(f.description, `${where}.description`));
125
153
  return out;
@@ -141,6 +169,9 @@ export function annexField(d) {
141
169
  see: Object.freeze([...(d.see ?? [])]),
142
170
  ...(d.act !== undefined ? { act: Object.freeze([...d.act]) } : {}),
143
171
  ...(d.genre !== undefined ? { genre: typeof d.genre === 'string' ? d.genre : d.genre.id } : {}),
172
+ ...(d.scope !== undefined ? { scope: d.scope } : {}),
173
+ ...(d.nextChapter !== undefined ? { nextChapter: d.nextChapter } : {}),
174
+ ...(d.keepOnRetell !== undefined ? { keepOnRetell: d.keepOnRetell } : {}),
144
175
  ...(d.label !== undefined ? { label: d.label } : {}),
145
176
  ...(d.description !== undefined ? { description: d.description } : {}),
146
177
  });
@@ -246,12 +277,30 @@ export const annexOwners = () => [...declarations.keys()];
246
277
  export const annexDeclarationOf = (owner) => declarations.get(owner);
247
278
  /**
248
279
  * The fields of a declaration in force for a session of `genre`: every
249
- * unscoped field and the ones scoped to that genre. With no genre — a
280
+ * unscoped field and the ones scoped to that genre (a `user`-scoped field
281
+ * never — it lives in no session). With no genre — a
250
282
  * document judged before it knows its session — every field, whatever genre
251
283
  * it is scoped to. Pure. @experimental
252
284
  */
253
285
  export function annexFieldsInGenre(fields, genre) {
254
- return fields.filter((f) => f.genre === undefined || genre === undefined || f.genre === genre);
286
+ return fields.filter((f) => f.scope !== 'user' && (f.genre === undefined || genre === undefined || f.genre === genre));
287
+ }
288
+ /**
289
+ * 🚧 (M2b) The declared field covering a user annex key: the exact key first,
290
+ * then the longest family (`saves/`) that prefixes it. Only `scope: 'user'`
291
+ * fields are considered. Pure. @experimental
292
+ */
293
+ export function userAnnexFieldFor(fields, key) {
294
+ const user = fields.filter((f) => f.scope === 'user');
295
+ const exact = user.find((f) => f.key === key);
296
+ if (exact)
297
+ return exact;
298
+ let best;
299
+ for (const f of user)
300
+ if (f.key.endsWith('/') && key.startsWith(f.key) && key.length > f.key.length)
301
+ if (!best || f.key.length > best.key.length)
302
+ best = f;
303
+ return best;
255
304
  }
256
305
  /** Whether a declared field may be set by a person, through its ready-made action. @experimental */
257
306
  export const isSettableAnnexField = (f) => !!f.act?.length;
@@ -74,6 +74,7 @@ export declare function specIdOf(v: unknown, where: string): string;
74
74
  import { type GenreDecl, type GenreProps } from './genres.js';
75
75
  import { type PresetRegistrationChanges, type RegistrationDecl } from './registrations.js';
76
76
  import type { SettingValue } from './exposure.js';
77
+ import type { VariableId } from './variables.js';
77
78
  import { type SessionEventDecl } from './events.js';
78
79
  import { type ValueToolkit } from './values.js';
79
80
  import type { ComponentDecl, Extension } from './extension.js';
@@ -310,18 +311,18 @@ export interface PresetDecl {
310
311
  */
311
312
  settings?: Readonly<Record<string, SettingValue>>;
312
313
  /**
313
- * Whether the instance should offer this preset the moment the package is
314
- * enabled. **Absent means no**, and that is the interesting half.
315
- *
316
- * A preset is what a non-admin picks from, so a package that installed one
317
- * straight into everybody's picker would be deciding, on the administrator's
318
- * behalf, what this instance offers. So the projection lands it disabled and
319
- * an administrator switches it on — the same shape as a declared permission,
320
- * which is also announced by the package and granted by the instance.
321
- *
322
- * Setting it is a request, not a grant: an instance is free to ignore it,
323
- * and an administrator who has already disabled a preset keeps that decision
324
- * across upgrades.
314
+ * 🚧 Variable id → layout reference (`{ 'core:var/characters@1': 'core/json@1' }`):
315
+ * this preset's sessions write that variable out with that layout instead of
316
+ * the pub's. A reference to a layout that isn't installed is accepted; the
317
+ * host skips it, renders the pub's layout and says so. ⚠ Not a genre's
318
+ * `layouts` (session layouts) and not `settings`.
319
+ */
320
+ variableLayouts?: Readonly<Record<VariableId, string>>;
321
+ /**
322
+ * @deprecated ⏳ Ignored. The instance offers a plugin's presets as soon as
323
+ * the plugin is enabled; an administrator may hide one afterwards, and that
324
+ * choice survives upgrades. Kept so existing packages still compile;
325
+ * removing it is the owner's call.
325
326
  */
326
327
  enabled?: boolean;
327
328
  }
@@ -437,7 +438,9 @@ export interface PresetInput {
437
438
  };
438
439
  /** 🚧 See `PresetDecl.settings` — each a value, or `{ value, lock?, askAtStart? }`. */
439
440
  settings?: Readonly<Record<string, SettingValue>>;
440
- /** Ask the instance to offer this preset immediately. See `PresetDecl.enabled`. */
441
+ /** 🚧 See `PresetDecl.variableLayouts`. */
442
+ variableLayouts?: Readonly<Record<VariableId, string>>;
443
+ /** @deprecated ⏳ Ignored — presets are offered once the plugin is enabled. See `PresetDecl.enabled`. */
441
444
  enabled?: boolean;
442
445
  }
443
446
  /**
@@ -492,6 +495,16 @@ export declare function requirementRanges(manifest: {
492
495
  id?: string;
493
496
  range: string;
494
497
  }>;
498
+ /**
499
+ * What is wrong with a preset's `variableLayouts`, as sentences — the one
500
+ * statement of the rule, for a preset that arrives as data (a manifest, a row)
501
+ * and for `preset()`. Empty when it is clean or absent.
502
+ * @experimental
503
+ */
504
+ export declare function presetVariableLayoutFindings(preset: {
505
+ slug?: string;
506
+ variableLayouts?: unknown;
507
+ } | null | undefined): string[];
495
508
  /**
496
509
  * The stored form of a preset. Every reference is read down to its id and
497
510
  * checked against what the value says: a binding's events against its spec's
package/dist/announce.js CHANGED
@@ -33,6 +33,7 @@ const actionKeysOf = (v) => {
33
33
  };
34
34
  import { genre as makeGenre, genreIdOf, sessionEvents } from './genres.js';
35
35
  import { registrationRange, } from './registrations.js';
36
+ import { parseVariableLayoutReference, variableIdParts } from './variableLayouts.js';
36
37
  import { eventById, isEventId, isSessionEventDecl } from './events.js';
37
38
  import { makeValueToolkit } from './values.js';
38
39
  import { SAVE_MESSAGE_SPEC_ID } from './descriptors.js';
@@ -218,6 +219,32 @@ export function requirementRanges(manifest) {
218
219
  return out;
219
220
  }
220
221
  const isBindingObject = (v) => !!v && typeof v === 'object' && 'spec' in v;
222
+ /**
223
+ * What is wrong with a preset's `variableLayouts`, as sentences — the one
224
+ * statement of the rule, for a preset that arrives as data (a manifest, a row)
225
+ * and for `preset()`. Empty when it is clean or absent.
226
+ * @experimental
227
+ */
228
+ export function presetVariableLayoutFindings(preset) {
229
+ const where = `preset '${preset?.slug ?? '?'}'`;
230
+ const map = preset?.variableLayouts;
231
+ if (map === undefined)
232
+ return [];
233
+ if (!map || typeof map !== 'object' || Array.isArray(map))
234
+ return [
235
+ `${where}.variableLayouts is a map from variable id to layout reference — ` +
236
+ `{ 'core:var/characters@1': 'core/json@1' }`,
237
+ ];
238
+ const findings = [];
239
+ for (const [key, value] of Object.entries(map)) {
240
+ if (!variableIdParts(key))
241
+ findings.push(`${where}.variableLayouts: '${key}' is not a variable id — it reads 'core:var/characters@1'`);
242
+ else if (!parseVariableLayoutReference(value))
243
+ findings.push(`${where}.variableLayouts: '${key}' is given '${String(value)}', which is not a layout reference — ` +
244
+ `it reads '<owner>/<slug>@<major>', such as 'core/json@1'`);
245
+ }
246
+ return findings;
247
+ }
221
248
  /**
222
249
  * The stored form of a preset. Every reference is read down to its id and
223
250
  * checked against what the value says: a binding's events against its spec's
@@ -228,6 +255,9 @@ const isBindingObject = (v) => !!v && typeof v === 'object' && 'spec' in v;
228
255
  export function preset(input) {
229
256
  const where = `preset '${input?.slug}'`;
230
257
  assertDisplayText(where, input);
258
+ const layoutFindings = presetVariableLayoutFindings(input);
259
+ if (layoutFindings.length)
260
+ throw new Error(layoutFindings[0]);
231
261
  if (typeof input.genre === 'string')
232
262
  throw new Error(`${where} names its genre as a string — pass the genre value (import it), or use('${input.genre}')`);
233
263
  const genre = isExternalRef(input.genre) ? input.genre.id : genreIdOf(input.genre);
@@ -360,6 +390,7 @@ export function preset(input) {
360
390
  ...(input.callsPerTurn !== undefined ? { callsPerTurn: assertCallsPerTurn(input.callsPerTurn, where) } : {}),
361
391
  ...(input.cast ? { cast: assertCastFloor(input.cast, where) } : {}),
362
392
  ...(input.settings && Object.keys(input.settings).length ? { settings: { ...input.settings } } : {}),
393
+ ...(input.variableLayouts && Object.keys(input.variableLayouts).length ? { variableLayouts: { ...input.variableLayouts } } : {}),
363
394
  };
364
395
  }
365
396
  const assertCallsPerTurn = (v, where) => {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 🚧 The one rule for a package's applet card (M2d), run by the packager
3
+ * (`serene-pub check`) and again by the instance's install over the stored
4
+ * manifest. Pure: the caller says which package files exist.
5
+ *
6
+ * Returns one finding per mistake, each with a `fix`: `E_APPLET_CARD_OUTSIDE_ASSETS`,
7
+ * `E_APPLET_CARD_MISSING`, `E_APPLET_CARD_BLURB_LONG`, `E_APPLET_CARD_WITHOUT_APPLET`.
8
+ * Empty when `appletCard` is undefined. Not a reader of files and not a layout
9
+ * check — no aspect ratio is tested.
10
+ * @experimental (M2d)
11
+ */
12
+ export declare function appletCardFindings(card: unknown, assetsDir: string | undefined, fileExists: (path: string) => boolean, hasAppletGenre: boolean): Array<{
13
+ code: string;
14
+ message: string;
15
+ fix: string;
16
+ }>;
17
+ //# sourceMappingURL=appletCard.d.ts.map
@@ -0,0 +1,60 @@
1
+ import { i18nText } from './i18n.js';
2
+ /**
3
+ * 🚧 The one rule for a package's applet card (M2d), run by the packager
4
+ * (`serene-pub check`) and again by the instance's install over the stored
5
+ * manifest. Pure: the caller says which package files exist.
6
+ *
7
+ * Returns one finding per mistake, each with a `fix`: `E_APPLET_CARD_OUTSIDE_ASSETS`,
8
+ * `E_APPLET_CARD_MISSING`, `E_APPLET_CARD_BLURB_LONG`, `E_APPLET_CARD_WITHOUT_APPLET`.
9
+ * Empty when `appletCard` is undefined. Not a reader of files and not a layout
10
+ * check — no aspect ratio is tested.
11
+ * @experimental (M2d)
12
+ */
13
+ export function appletCardFindings(card, assetsDir, fileExists, hasAppletGenre) {
14
+ if (card === undefined)
15
+ return [];
16
+ const out = [];
17
+ const c = (card && typeof card === 'object' ? card : {});
18
+ const dir = assetsDir?.replace(/\/+$/, '');
19
+ for (const key of ['poster', 'logo']) {
20
+ const raw = c[key];
21
+ if (raw === undefined)
22
+ continue;
23
+ const shown = String(raw);
24
+ const safe = typeof raw === 'string' &&
25
+ !raw.startsWith('/') &&
26
+ !raw.includes('\\') &&
27
+ !raw.split('/').some((x) => !x || x === '.' || x === '..');
28
+ if (!safe || !dir || !raw.startsWith(`${dir}/`)) {
29
+ out.push({
30
+ code: 'E_APPLET_CARD_OUTSIDE_ASSETS',
31
+ message: `appletCard.${key} is '${shown}', which is not a file under the package's assets folder${dir ? ` '${dir}'` : ' (the package declares none)'}`,
32
+ fix: `declare assets: { dir: 'assets' } and put the picture under it — 'assets/card/${key}.png'`,
33
+ });
34
+ continue;
35
+ }
36
+ if (!fileExists(raw))
37
+ out.push({
38
+ code: 'E_APPLET_CARD_MISSING',
39
+ message: `appletCard.${key} names '${shown}', and the package has no such file`,
40
+ fix: `add the picture at that path, or remove appletCard.${key}`,
41
+ });
42
+ }
43
+ if (c.blurb !== undefined) {
44
+ const text = i18nText(c.blurb) ?? '';
45
+ if (text.length > 160)
46
+ out.push({
47
+ code: 'E_APPLET_CARD_BLURB_LONG',
48
+ message: `appletCard.blurb is ${text.length} characters; the card shows at most 160`,
49
+ fix: 'shorten it to one line of at most 160 characters',
50
+ });
51
+ }
52
+ if (!hasAppletGenre)
53
+ out.push({
54
+ code: 'E_APPLET_CARD_WITHOUT_APPLET',
55
+ message: 'appletCard is declared, and no genre of this package presents as an applet',
56
+ fix: "add applet: true to a genre's shape, or remove appletCard",
57
+ });
58
+ return out;
59
+ }
60
+ //# sourceMappingURL=appletCard.js.map
@@ -161,6 +161,33 @@ export declare const derivations: Readonly<{
161
161
  requiresFrom: false;
162
162
  description: "A LiquidJS expression on the declaration, evaluated over the state pinned at run start.";
163
163
  }>;
164
+ /**
165
+ * The clock's part of the day, by the book's own calendar `periods` (default
166
+ * morning 5 · day 12 · dusk 18 · night 22). Absent when the clock has no hour.
167
+ */
168
+ readonly dayPeriod: Readonly<{
169
+ id: "core:derive/day-period@1";
170
+ requiresFrom: false;
171
+ description: "The part of the day the story clock is in, by the calendar's periods.";
172
+ }>;
173
+ /**
174
+ * The clock's season, by the book's own calendar `seasons`. Absent without
175
+ * seasons, months, or a clock with a month and day.
176
+ */
177
+ readonly season: Readonly<{
178
+ id: "core:derive/season@1";
179
+ requiresFrom: false;
180
+ description: "The season the story clock is in, by the calendar's seasons.";
181
+ }>;
182
+ /**
183
+ * The clock's part of the day over the default periods always (morning, day,
184
+ * dusk, night), whatever the calendar declares.
185
+ */
186
+ readonly timeOfDay: Readonly<{
187
+ id: "core:derive/time-of-day@1";
188
+ requiresFrom: false;
189
+ description: "The default part of the day (morning, day, dusk, night) the story clock is in.";
190
+ }>;
164
191
  }>;
165
192
  /** @experimental */
166
193
  export type DerivationId = (typeof derivations)[keyof typeof derivations]['id'];
@@ -216,7 +243,14 @@ export interface SlotConfig {
216
243
  * holds words and lore references only.
217
244
  */
218
245
  repertoire?: string;
219
- /** `derived`: which computation, and the slot it reads. */
246
+ /**
247
+ * `derived`: which computation, and the slot it reads.
248
+ *
249
+ * 🚧 On a slot that is NOT `derived` it names the slot's **derived default**:
250
+ * the reading a read uses when no layer holds a value, before the
251
+ * declaration's `default`. A hand write wins. Read order: layers, derived
252
+ * default, declaration default.
253
+ */
220
254
  derivation?: string;
221
255
  from?: SlotId;
222
256
  [key: string]: unknown;
@@ -481,6 +515,21 @@ export interface AttributeSlotProps {
481
515
  descriptor: string;
482
516
  /** Which owner kinds may carry it. */
483
517
  appliesTo: readonly SlotAppliesTo[];
518
+ /**
519
+ * 🚧 **What its values survive** (M0, SHAPES F1): `session` — they
520
+ * die with the session (its session layer: `session`, 🚧 `seated_member`, ⏳
521
+ * `session_cast`, `player_seat`, `session_location`); `world` — they live on the book,
522
+ * dated on its timeline (`lorebook`, `cast_member`, `location`). Absent:
523
+ * `session`. A ruleset attribute's `scope` lands here. The player's own
524
+ * (`owner: 'player'` on a ruleset attribute) is a `cast` slot read on the
525
+ * player's seat. Declared only until lane T3.
526
+ */
527
+ scope?: 'session' | 'world';
528
+ /**
529
+ * 🚧 This follows the player into the next chapter: a `next-chapter`
530
+ * session seeds its value from the session it follows (M0, F5).
531
+ */
532
+ nextChapter?: true;
484
533
  /** The base configuration every attachment starts from. */
485
534
  config?: SlotConfig;
486
535
  /** The value a read falls back to when no layer has one. */
@@ -928,7 +977,7 @@ export declare function applyListOp(current: readonly SlotListItem[] | null | un
928
977
  * Whether a slot may attach to this kind of owner.
929
978
  *
930
979
  * The owner *kinds* the host stores (`card`, `cast_member`, `lorebook`,
931
- * `session`, `session_cast`, `location`, `session_location`) collapse to the
980
+ * `session`, 🚧 `seated_member`, ⏳ `session_cast`, `location`, `session_location`) collapse to the
932
981
  * three a declaration talks about: a lorebook and a session are the **world**,
933
982
  * a location entry and its session layer are a **location**, everything that
934
983
  * is somebody is the **cast**. A declaration should not have to know the
@@ -169,6 +169,33 @@ export const derivations = Object.freeze({
169
169
  requiresFrom: false,
170
170
  description: 'A LiquidJS expression on the declaration, evaluated over the state pinned at run start.',
171
171
  }),
172
+ /**
173
+ * The clock's part of the day, by the book's own calendar `periods` (default
174
+ * morning 5 · day 12 · dusk 18 · night 22). Absent when the clock has no hour.
175
+ */
176
+ dayPeriod: Object.freeze({
177
+ id: 'core:derive/day-period@1',
178
+ requiresFrom: false,
179
+ description: "The part of the day the story clock is in, by the calendar's periods.",
180
+ }),
181
+ /**
182
+ * The clock's season, by the book's own calendar `seasons`. Absent without
183
+ * seasons, months, or a clock with a month and day.
184
+ */
185
+ season: Object.freeze({
186
+ id: 'core:derive/season@1',
187
+ requiresFrom: false,
188
+ description: "The season the story clock is in, by the calendar's seasons.",
189
+ }),
190
+ /**
191
+ * The clock's part of the day over the default periods always (morning, day,
192
+ * dusk, night), whatever the calendar declares.
193
+ */
194
+ timeOfDay: Object.freeze({
195
+ id: 'core:derive/time-of-day@1',
196
+ requiresFrom: false,
197
+ description: "The default part of the day (morning, day, dusk, night) the story clock is in.",
198
+ }),
172
199
  });
173
200
  /** @experimental */
174
201
  export const getDerivation = (id) => Object.values(derivations).find((d) => d.id === id);
@@ -841,6 +868,10 @@ function checkSlotDeclaration(id, props) {
841
868
  if (!props.appliesTo?.length)
842
869
  throw new Error(`${id} declares no appliesTo. Say whether it attaches to 'cast', to 'world', to ` +
843
870
  `'location', or to several — a slot nothing may carry can never hold a value.`);
871
+ if (props.scope !== undefined && props.scope !== 'session' && props.scope !== 'world')
872
+ throw new Error(`${id} declares scope '${String(props.scope)}'. Say 'session' — its values end with the session — or 'world' — they live on the book.`);
873
+ if (props.nextChapter !== undefined && props.nextChapter !== true)
874
+ throw new Error(`${id}: \`nextChapter\` is true or absent — the value follows the player into the next chapter.`);
844
875
  if (props.type === 'enum' && !(props.config?.of ?? fieldSlotConfig(slotField(props)).of)?.length)
845
876
  throw new Error(`${id} is an enum with no options. Declare config.of — the closed set is what ` +
846
877
  `makes it a chip rather than a text field.`);
@@ -1164,7 +1195,7 @@ export function applyListOp(current, op, items, config = {}) {
1164
1195
  * Whether a slot may attach to this kind of owner.
1165
1196
  *
1166
1197
  * The owner *kinds* the host stores (`card`, `cast_member`, `lorebook`,
1167
- * `session`, `session_cast`, `location`, `session_location`) collapse to the
1198
+ * `session`, 🚧 `seated_member`, ⏳ `session_cast`, `location`, `session_location`) collapse to the
1168
1199
  * three a declaration talks about: a lorebook and a session are the **world**,
1169
1200
  * a location entry and its session layer are a **location**, everything that
1170
1201
  * is somebody is the **cast**. A declaration should not have to know the