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

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 (144) hide show
  1. package/dist/actions.d.ts +52 -2
  2. package/dist/actions.js +56 -6
  3. package/dist/annexFields.d.ts +32 -2
  4. package/dist/annexFields.js +48 -5
  5. package/dist/announce.d.ts +142 -2
  6. package/dist/announce.js +198 -2
  7. package/dist/attributes.d.ts +331 -6
  8. package/dist/attributes.js +339 -27
  9. package/dist/bridges.d.ts +61 -0
  10. package/dist/bridges.js +112 -0
  11. package/dist/builder.d.ts +278 -51
  12. package/dist/builder.js +267 -30
  13. package/dist/cadences.d.ts +585 -0
  14. package/dist/cadences.js +1118 -0
  15. package/dist/capabilities.d.ts +106 -17
  16. package/dist/capabilities.js +85 -7
  17. package/dist/checkMethods.d.ts +240 -0
  18. package/dist/checkMethods.js +362 -0
  19. package/dist/component.d.ts +6 -1
  20. package/dist/componentClient.d.ts +42 -6
  21. package/dist/componentWire.js +22 -4
  22. package/dist/composerStates.d.ts +96 -0
  23. package/dist/composerStates.js +190 -0
  24. package/dist/conditions.d.ts +424 -0
  25. package/dist/conditions.js +521 -0
  26. package/dist/config.d.ts +42 -6
  27. package/dist/config.js +48 -20
  28. package/dist/conversions.d.ts +41 -0
  29. package/dist/conversions.js +50 -0
  30. package/dist/declarations.d.ts +40 -2
  31. package/dist/declarations.js +178 -10
  32. package/dist/descriptors.d.ts +287 -4
  33. package/dist/descriptors.js +281 -18
  34. package/dist/document.d.ts +47 -2
  35. package/dist/document.js +46 -14
  36. package/dist/entities.d.ts +156 -0
  37. package/dist/entities.js +259 -0
  38. package/dist/events.d.ts +711 -1
  39. package/dist/events.js +412 -1
  40. package/dist/executor.d.ts +4 -3
  41. package/dist/executor.js +22 -8
  42. package/dist/exposure.d.ts +128 -0
  43. package/dist/exposure.js +168 -0
  44. package/dist/extension.d.ts +127 -3
  45. package/dist/extension.js +43 -0
  46. package/dist/fit.d.ts +198 -0
  47. package/dist/fit.js +351 -0
  48. package/dist/functions.d.ts +554 -0
  49. package/dist/functions.js +712 -0
  50. package/dist/genres.d.ts +303 -89
  51. package/dist/genres.js +335 -100
  52. package/dist/hookGrants.d.ts +15 -1
  53. package/dist/hookGrants.js +11 -10
  54. package/dist/hooks.d.ts +34 -5
  55. package/dist/hooks.js +5 -2
  56. package/dist/hostElements.d.ts +7 -1
  57. package/dist/hostElements.js +20 -1
  58. package/dist/hostState.d.ts +110 -0
  59. package/dist/hostState.js +140 -0
  60. package/dist/identity.d.ts +1 -1
  61. package/dist/identity.js +1 -1
  62. package/dist/index.d.ts +25 -0
  63. package/dist/index.js +48 -0
  64. package/dist/jsonSchema.d.ts +178 -0
  65. package/dist/jsonSchema.js +570 -0
  66. package/dist/libraryDraft.d.ts +27 -0
  67. package/dist/libraryDraft.js +25 -0
  68. package/dist/lorebookFile.d.ts +44 -0
  69. package/dist/lorebookFile.js +202 -0
  70. package/dist/media.d.ts +127 -12
  71. package/dist/media.js +45 -1
  72. package/dist/messageBlocks.d.ts +179 -5
  73. package/dist/messageBlocks.js +208 -6
  74. package/dist/participants.d.ts +32 -9
  75. package/dist/participants.js +13 -2
  76. package/dist/pluginHarness.d.ts +63 -33
  77. package/dist/pluginHarness.js +78 -144
  78. package/dist/pluginPermissions.d.ts +15 -1
  79. package/dist/pluginPermissions.js +29 -2
  80. package/dist/preview.d.ts +45 -4
  81. package/dist/preview.js +52 -12
  82. package/dist/primers.d.ts +177 -0
  83. package/dist/primers.js +265 -0
  84. package/dist/receipt.d.ts +11 -0
  85. package/dist/receiverRules.js +9 -0
  86. package/dist/refs.d.ts +9 -1
  87. package/dist/refs.js +12 -0
  88. package/dist/registrations.d.ts +384 -0
  89. package/dist/registrations.js +625 -0
  90. package/dist/repertoires.d.ts +502 -0
  91. package/dist/repertoires.js +666 -0
  92. package/dist/rulesetDocument.d.ts +116 -0
  93. package/dist/rulesetDocument.js +252 -0
  94. package/dist/rulesetSections.d.ts +631 -0
  95. package/dist/rulesetSections.js +1288 -0
  96. package/dist/rulesetTemplates.d.ts +161 -0
  97. package/dist/rulesetTemplates.js +242 -0
  98. package/dist/rulesets.d.ts +899 -0
  99. package/dist/rulesets.js +1378 -0
  100. package/dist/sceneSettings.d.ts +8 -0
  101. package/dist/sceneSettings.js +10 -2
  102. package/dist/scope.d.ts +44 -3
  103. package/dist/scope.js +18 -0
  104. package/dist/scripts.d.ts +31 -8
  105. package/dist/scripts.js +45 -8
  106. package/dist/sessionDossier.d.ts +157 -7
  107. package/dist/sessionLayout.d.ts +291 -138
  108. package/dist/sessionLayout.js +504 -211
  109. package/dist/sessionSettings.d.ts +24 -0
  110. package/dist/settings.d.ts +95 -4
  111. package/dist/settings.js +293 -4
  112. package/dist/shapes.d.ts +80 -1
  113. package/dist/shapes.js +100 -5
  114. package/dist/speech.d.ts +333 -0
  115. package/dist/speech.js +199 -0
  116. package/dist/statShapes.d.ts +8 -1
  117. package/dist/statShapes.js +8 -1
  118. package/dist/status.d.ts +14 -0
  119. package/dist/status.js +12 -0
  120. package/dist/storage.d.ts +53 -66
  121. package/dist/storage.js +7 -12
  122. package/dist/storyTime.d.ts +25 -1
  123. package/dist/storyTime.js +42 -2
  124. package/dist/surfaces.d.ts +15 -2
  125. package/dist/template.d.ts +19 -1
  126. package/dist/template.js +25 -11
  127. package/dist/templateScopeAt.d.ts +1 -1
  128. package/dist/templateScopeAt.js +11 -8
  129. package/dist/ties.d.ts +211 -0
  130. package/dist/ties.js +301 -0
  131. package/dist/turnOrder.d.ts +25 -14
  132. package/dist/turnOrder.js +21 -8
  133. package/dist/userAnnex.d.ts +126 -0
  134. package/dist/userAnnex.js +214 -0
  135. package/dist/validate.js +114 -19
  136. package/dist/values.js +6 -0
  137. package/dist/vocabularies.d.ts +192 -0
  138. package/dist/vocabularies.js +326 -0
  139. package/dist/widgetDecls.d.ts +12 -0
  140. package/dist/widgetDecls.js +2 -0
  141. package/dist/widgets.d.ts +1062 -29
  142. package/dist/widgets.js +218 -3
  143. package/host-elements.d.ts +90 -0
  144. 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.
@@ -363,6 +386,22 @@ export interface ActionDecl {
363
386
  recipients?: CollectedRecipients;
364
387
  clockStep?: CollectedClockStep;
365
388
  };
389
+ /**
390
+ * 🚧 A question asked before the action fires (2026-10-18, the 100-turn
391
+ * walk: _Reveal the planning notes_ cannot be taken back, and fired on
392
+ * one press). Every press — a chip, the palette, a widget's invoke —
393
+ * opens the host's confirmation (an `alertdialog`) with `question` as
394
+ * its title, `description` under it saying what goes and what stays,
395
+ * and a confirm button reading `confirmLabel` (absent: the action's
396
+ * `label`); Cancel fires nothing. A press that answers a form (a block)
397
+ * is not asked again: the form was the question. Display text, all of it.
398
+ * @experimental
399
+ */
400
+ confirm?: {
401
+ question: I18n;
402
+ description?: I18n;
403
+ confirmLabel?: I18n;
404
+ };
366
405
  }
367
406
  /** A declaration after normalisation: venues and predicates always lists, no alias spellings, no `function`. @experimental */
368
407
  export interface NormalizedAction extends ActionDecl {
@@ -420,7 +459,7 @@ export declare function placeActions<A extends {
420
459
  venue: ReadonlyArray<Venue>;
421
460
  quick?: boolean;
422
461
  }>(actions: ReadonlyArray<A>, channel?: string): VenueListings<A>;
423
- /** The namespace of a spec id — `core:spec/chat-narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
462
+ /** The namespace of a spec id — `core:spec/story-narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
424
463
  export declare function specNamespace(specId: string): string;
425
464
  /** Is this namespace core's — the one whose actions take bare slash names? @experimental */
426
465
  export declare const isCoreNamespace: (ns: string) => boolean;
@@ -508,7 +547,14 @@ export declare function collectsFindings(raw: unknown, where: string): string[];
508
547
  */
509
548
  export declare function actionFindings(raw: unknown, specId: string, at?: string): string[];
510
549
  /** `actionFindings`, each sentence with the law it comes from (`ActionFinding`). @experimental */
511
- export declare function actionFindingsByLaw(raw: unknown, specId: string, at?: string): ActionFinding[];
550
+ export declare function actionFindingsByLaw(raw: unknown, specId: string, at?: string, opts?: {
551
+ /**
552
+ * 🚧 The spec is mounted by registrations, not locked (PLAN-layering
553
+ * D3): its actions carry no genre — a registration that includes one
554
+ * offers it to that genre.
555
+ */
556
+ unlocked?: boolean;
557
+ }): ActionFinding[];
512
558
  /** The slash-name grammar, applied to one name for one spec. @experimental */
513
559
  export declare function slashFindings(slash: string, specId: string, where?: string): string[];
514
560
  /**
@@ -566,6 +612,8 @@ export declare function slashCollisions(actions: ReadonlyArray<NormalizedAction
566
612
  export declare function actionDocumentFindings(doc: {
567
613
  id: string;
568
614
  contributes?: unknown;
615
+ input?: unknown;
616
+ suits?: unknown;
569
617
  }): string[];
570
618
  /**
571
619
  * `actionDocumentFindings` with the law each sentence comes from — what
@@ -575,6 +623,8 @@ export declare function actionDocumentFindings(doc: {
575
623
  export declare function actionDocumentFindingsByLaw(doc: {
576
624
  id: string;
577
625
  contributes?: unknown;
626
+ input?: unknown;
627
+ suits?: unknown;
578
628
  }): ActionFinding[];
579
629
  /**
580
630
  * Who core's message verbs are for and where they live — the same shape a
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
@@ -203,7 +215,7 @@ export function placeActions(actions, channel = DEFAULT_CHANNEL) {
203
215
  }
204
216
  return listings;
205
217
  }
206
- /** The namespace of a spec id — `core:spec/chat-narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
218
+ /** The namespace of a spec id — `core:spec/story-narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
207
219
  export function specNamespace(specId) {
208
220
  const i = specId.indexOf(':');
209
221
  return i === -1 ? '' : specId.slice(0, i);
@@ -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) {
@@ -372,7 +407,7 @@ export function actionFindings(raw, specId, at = 'contributes.actions') {
372
407
  return actionFindingsByLaw(raw, specId, at).map((f) => f.message);
373
408
  }
374
409
  /** `actionFindings`, each sentence with the law it comes from (`ActionFinding`). @experimental */
375
- export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
410
+ export function actionFindingsByLaw(raw, specId, at = 'contributes.actions', opts = {}) {
376
411
  const out = [];
377
412
  /** A fault in the declaration's shape (R-15). */
378
413
  const shape = (...messages) => {
@@ -390,7 +425,7 @@ export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
390
425
  const where = `${at}[${typeof a.key === 'string' ? a.key : '?'}]`;
391
426
  if (typeof a.key !== 'string' || !KEY.test(a.key))
392
427
  shape(`${where}: 'key' is required — a lowercase kebab token (${KEY.source})`);
393
- if (typeof a.genre !== 'string' || !a.genre)
428
+ if (opts.unlocked ? a.genre !== undefined && (typeof a.genre !== 'string' || !a.genre) : typeof a.genre !== 'string' || !a.genre)
394
429
  shape(`${where}: 'genre' is required — the genre id this action is offered to (24 §3), ` +
395
430
  `such as core:genre/chat`);
396
431
  const venues = Array.isArray(a.venue) ? a.venue : a.venue === undefined ? [] : [a.venue];
@@ -423,7 +458,7 @@ export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
423
458
  if (!isParticipantRef(r))
424
459
  shape(`${where}: audience.${half} names '${String(r)}', which is not a participant ` +
425
460
  `reference — one of ${PARTICIPANT_ROLES.join(', ')}, or user:<id>, ` +
426
- `character:<id>, envoy:<slug>`);
461
+ `character:<id>, player-seat:<id>, envoy:<slug>`);
427
462
  }
428
463
  }
429
464
  if (a.quick !== undefined && typeof a.quick !== 'boolean')
@@ -461,6 +496,18 @@ export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
461
496
  `({ en: 'Roll the dice and post the result.' })`);
462
497
  else
463
498
  shape(...i18nFindings(a.description, `${where}.description`));
499
+ if (a.confirm !== undefined) {
500
+ const c = a.confirm;
501
+ if (!c || typeof c !== 'object' || Array.isArray(c))
502
+ shape(`${where}.confirm is { question, description?, confirmLabel? } — the question asked before the action fires`);
503
+ else {
504
+ shape(...i18nFindings(c.question, `${where}.confirm.question`, { required: true }));
505
+ if (c.description !== undefined)
506
+ shape(...i18nFindings(c.description, `${where}.confirm.description`));
507
+ if (c.confirmLabel !== undefined)
508
+ shape(...i18nFindings(c.confirmLabel, `${where}.confirm.confirmLabel`));
509
+ }
510
+ }
464
511
  if (a.iconAlt !== undefined) {
465
512
  shape(...i18nFindings(a.iconAlt, `${where}.iconAlt`));
466
513
  if (a.icon === undefined)
@@ -660,9 +707,12 @@ export function actionDocumentFindingsByLaw(doc) {
660
707
  if (!c)
661
708
  return [];
662
709
  const out = [];
710
+ // 🚧 D3: a spec declared with `{ suits }` and no lock offers its actions
711
+ // where registrations include them — no genre on the declaration.
712
+ const unlocked = Array.isArray(doc.suits) && !doc.input;
663
713
  for (const entry of c.actions ?? []) {
664
714
  const a = normalizeAction(entry);
665
- out.push(...actionFindingsByLaw(a, doc.id));
715
+ out.push(...actionFindingsByLaw(a, doc.id, 'contributes.actions', { unlocked }));
666
716
  }
667
717
  if (out.length)
668
718
  return out;
@@ -84,6 +84,22 @@ 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;
87
103
  /** What a listing calls the action. Default: the key. */
88
104
  readonly label?: I18n;
89
105
  readonly description?: I18n;
@@ -98,6 +114,10 @@ export type AnnexFieldInput = {
98
114
  genre?: {
99
115
  readonly id: string;
100
116
  } | string;
117
+ /** 🚧 `session` (the default) or `lorebook` — {@link AnnexFieldDecl.scope}. */
118
+ scope?: 'session' | 'lorebook' | 'user';
119
+ /** 🚧 The value follows the player into the next chapter — {@link AnnexFieldDecl.nextChapter}. */
120
+ nextChapter?: true;
101
121
  label?: I18n;
102
122
  description?: I18n;
103
123
  };
@@ -112,7 +132,10 @@ export declare function annexFieldFindings(raw: unknown, at?: string): string[];
112
132
  * them while writing, never at a press.
113
133
  * @experimental
114
134
  */
115
- export declare function annexField(d: AnnexFieldInput): AnnexFieldDecl;
135
+ export declare function annexField<const D extends AnnexFieldInput>(d: D): AnnexFieldDecl & {
136
+ readonly key: D['key'];
137
+ readonly __declared?: D;
138
+ };
116
139
  /** Faults in a list of fields: each one's, and a key declared twice. @experimental */
117
140
  export declare function annexFieldListFindings(raw: unknown, at?: string): string[];
118
141
  /**
@@ -156,11 +179,18 @@ export declare const annexOwners: () => string[];
156
179
  export declare const annexDeclarationOf: (owner: string) => readonly AnnexFieldDecl[] | undefined;
157
180
  /**
158
181
  * The fields of a declaration in force for a session of `genre`: every
159
- * unscoped field and the ones scoped to that genre. With no genre — a
182
+ * unscoped field and the ones scoped to that genre (a `user`-scoped field
183
+ * never — it lives in no session). With no genre — a
160
184
  * document judged before it knows its session — every field, whatever genre
161
185
  * it is scoped to. Pure. @experimental
162
186
  */
163
187
  export declare function annexFieldsInGenre(fields: readonly AnnexFieldDecl[], genre?: string): AnnexFieldDecl[];
188
+ /**
189
+ * 🚧 (M2b) The declared field covering a user annex key: the exact key first,
190
+ * then the longest family (`saves/`) that prefixes it. Only `scope: 'user'`
191
+ * fields are considered. Pure. @experimental
192
+ */
193
+ export declare function userAnnexFieldFor(fields: readonly AnnexFieldDecl[], key: string): AnnexFieldDecl | undefined;
164
194
  /** Whether a declared field may be set by a person, through its ready-made action. @experimental */
165
195
  export declare const isSettableAnnexField: (f: Pick<AnnexFieldDecl, 'act'>) => boolean;
166
196
  /**
@@ -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,23 @@ 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
+ }
124
+ if (f.act !== undefined && f.scope !== 'user') {
108
125
  if (!Array.isArray(f.act) || !f.act.length)
109
126
  out.push(`${where}.act: a non-empty list of participant references — who may set the value`);
110
127
  else
@@ -120,6 +137,11 @@ export function annexFieldFindings(raw, at = 'annexFields') {
120
137
  if (typeof g !== 'string' || !/^[a-z0-9.-]+:genre\/[a-z0-9.-]+/.test(g))
121
138
  out.push(`${where}.genre: a genre — the value genre() returned, or its id ('acme.dice:genre/table')`);
122
139
  }
140
+ if (f.scope !== undefined && f.scope !== 'session' && f.scope !== 'lorebook' && f.scope !== 'user')
141
+ out.push(`${where}.scope: 'session' (the session annex, the default), 'lorebook' (the lorebook annex) or 'user' (the user annex) — ` +
142
+ `'${String(f.scope)}' is neither`);
143
+ if (f.nextChapter !== undefined && f.nextChapter !== true)
144
+ out.push(`${where}.nextChapter: true or absent — the value follows the player into the next chapter`);
123
145
  out.push(...i18nFindings(f.label, `${where}.label`));
124
146
  out.push(...i18nFindings(f.description, `${where}.description`));
125
147
  return out;
@@ -133,6 +155,7 @@ export function annexField(d) {
133
155
  const problems = annexFieldFindings(d, 'annexField');
134
156
  if (problems.length)
135
157
  throw new Error(problems.join('\n'));
158
+ // `__declared` is a phantom (never set): the field as written, for `sessionOf`'s annex typing.
136
159
  return Object.freeze({
137
160
  __decl: 'annex-field',
138
161
  key: d.key,
@@ -140,6 +163,8 @@ export function annexField(d) {
140
163
  see: Object.freeze([...(d.see ?? [])]),
141
164
  ...(d.act !== undefined ? { act: Object.freeze([...d.act]) } : {}),
142
165
  ...(d.genre !== undefined ? { genre: typeof d.genre === 'string' ? d.genre : d.genre.id } : {}),
166
+ ...(d.scope !== undefined ? { scope: d.scope } : {}),
167
+ ...(d.nextChapter !== undefined ? { nextChapter: d.nextChapter } : {}),
143
168
  ...(d.label !== undefined ? { label: d.label } : {}),
144
169
  ...(d.description !== undefined ? { description: d.description } : {}),
145
170
  });
@@ -245,12 +270,30 @@ export const annexOwners = () => [...declarations.keys()];
245
270
  export const annexDeclarationOf = (owner) => declarations.get(owner);
246
271
  /**
247
272
  * The fields of a declaration in force for a session of `genre`: every
248
- * unscoped field and the ones scoped to that genre. With no genre — a
273
+ * unscoped field and the ones scoped to that genre (a `user`-scoped field
274
+ * never — it lives in no session). With no genre — a
249
275
  * document judged before it knows its session — every field, whatever genre
250
276
  * it is scoped to. Pure. @experimental
251
277
  */
252
278
  export function annexFieldsInGenre(fields, genre) {
253
- return fields.filter((f) => f.genre === undefined || genre === undefined || f.genre === genre);
279
+ return fields.filter((f) => f.scope !== 'user' && (f.genre === undefined || genre === undefined || f.genre === genre));
280
+ }
281
+ /**
282
+ * 🚧 (M2b) The declared field covering a user annex key: the exact key first,
283
+ * then the longest family (`saves/`) that prefixes it. Only `scope: 'user'`
284
+ * fields are considered. Pure. @experimental
285
+ */
286
+ export function userAnnexFieldFor(fields, key) {
287
+ const user = fields.filter((f) => f.scope === 'user');
288
+ const exact = user.find((f) => f.key === key);
289
+ if (exact)
290
+ return exact;
291
+ let best;
292
+ for (const f of user)
293
+ if (f.key.endsWith('/') && key.startsWith(f.key) && key.length > f.key.length)
294
+ if (!best || f.key.length > best.key.length)
295
+ best = f;
296
+ return best;
254
297
  }
255
298
  /** Whether a declared field may be set by a person, through its ready-made action. @experimental */
256
299
  export const isSettableAnnexField = (f) => !!f.act?.length;
@@ -72,6 +72,8 @@ export type SpecRef = AnnouncedSpec | ExternalRef;
72
72
  /** The id a `SpecRef` names; a bare string is refused with the fix. @experimental */
73
73
  export declare function specIdOf(v: unknown, where: string): string;
74
74
  import { type GenreDecl, type GenreProps } from './genres.js';
75
+ import { type PresetRegistrationChanges, type RegistrationDecl } from './registrations.js';
76
+ import type { SettingValue } from './exposure.js';
75
77
  import { type SessionEventDecl } from './events.js';
76
78
  import { type ValueToolkit } from './values.js';
77
79
  import type { ComponentDecl, Extension } from './extension.js';
@@ -243,7 +245,35 @@ export interface PresetDecl {
243
245
  */
244
246
  label: I18n;
245
247
  description?: I18n;
248
+ /**
249
+ * ⏳ Which spec answers each event, keyed by event id.
250
+ * @deprecated An alias to 0.7 (PLAN-layering D4): a preset is **changes
251
+ * on the genre's defaults** — `registrations`. `presetChangesOf(decl)`
252
+ * reads these as registrations. A preset declared with `register` /
253
+ * `drop` / `change` stores `{}` here.
254
+ */
246
255
  bindings: Record<string, PresetBinding>;
256
+ /**
257
+ * 🚧 This preset's **changes on the genre's defaults** (R2, PLAN-layering
258
+ * D4): registrations it adds, the keys it drops, and changes to the rest.
259
+ * Present only when declared with `register` / `drop` / `change`; a
260
+ * preset still on `bindings` is read through `presetChangesOf`.
261
+ * @ruling R2, R3, R22
262
+ */
263
+ registrations?: PresetRegistrationChanges;
264
+ /**
265
+ * 🚧 The genre's **default preset** (R22, A18): marked here, by the
266
+ * preset itself, never by a slug on the genre. Absent: not the default.
267
+ */
268
+ default?: true;
269
+ /**
270
+ * 🚧 What this preset builds on beyond its own package (A16, R6): package
271
+ * requirements with version ranges — `acme.dice@^1.2`. Collected from
272
+ * `use('…@range')` pipelines and stated ones; the host withdraws the preset
273
+ * when one is disabled or missing, and deletes nothing. Absent when none.
274
+ * @ruling A16
275
+ */
276
+ requires?: string[];
247
277
  /**
248
278
  * For the open `session-action` slot: which actions come along, each by
249
279
  * its **identity** — `<spec slug>#<key>`. A preset
@@ -251,6 +281,10 @@ export interface PresetDecl {
251
281
  * function are two entries, and including one says nothing about the
252
282
  * other. Absent means the host's companion rule (every action from the
253
283
  * genre owner's own namespace).
284
+ * @deprecated ⏳ An alias to 0.7 (PLAN-layering D4): an action is offered
285
+ * by an action registration — `register(spec.actions.<key>, spec)` in the
286
+ * genre's defaults or a preset's `register`. `presetChangesOf` reads the
287
+ * include list as action registrations.
254
288
  * @ruling U5c review, W-A
255
289
  */
256
290
  actions?: {
@@ -258,6 +292,23 @@ export interface PresetDecl {
258
292
  };
259
293
  /** What starting from this preset pre-fills the creation form with. */
260
294
  defaults?: PresetDefaults;
295
+ /**
296
+ * 🚧 Model calls one turn costs on this preset, as the card prints it (PLAN-genre-restructure §3, 2026-10-19); the host's parity test measures a real turn against it. Absent means "as the genre".
297
+ * @deprecated ⏳ Accepted and kept as stated until calls per turn are derived from what is registered (PLAN-layering D4).
298
+ */
299
+ callsPerTurn?: number;
300
+ /** 🚧 The cast floor this preset lowers (never raises) the shape's to — `{ characters: 0 }` lets a Minimal story start with nobody in it. */
301
+ cast?: {
302
+ characters?: number;
303
+ personas?: number;
304
+ };
305
+ /**
306
+ * 🚧 Values this preset sets, keyed by setting key — the preset layer of
307
+ * the cascade: `session > preset > genre > core`. Each a plain value, or
308
+ * `{ value, lock?, askAtStart? }` (`SettingValue`, A10): lock it for the
309
+ * layers below, or place it on the start form. Never stored per session.
310
+ */
311
+ settings?: Readonly<Record<string, SettingValue>>;
261
312
  /**
262
313
  * Whether the instance should offer this preset the moment the package is
263
314
  * enabled. **Absent means no**, and that is the interesting half.
@@ -343,15 +394,104 @@ export interface PresetInput {
343
394
  */
344
395
  label: I18n;
345
396
  description?: I18n;
346
- bindings: BindingEntry[];
347
- /** Absent means the host's companion rule — see `PresetDecl.actions`. */
397
+ /**
398
+ * 🚧 This is the genre's **default preset** (R22) — marked here, never by
399
+ * a slug on the genre (A18).
400
+ */
401
+ default?: true;
402
+ /** 🚧 Registrations this preset adds to the genre's defaults — `register(…)` values (R2). */
403
+ register?: readonly RegistrationDecl[];
404
+ /** 🚧 Registrations of the genre's defaults this preset drops — the registration objects, never keys. */
405
+ drop?: readonly RegistrationDecl[];
406
+ /**
407
+ * 🚧 Changes to registrations of the genre's defaults — `{ of: reckoning, mode: 'review' }`:
408
+ * the registration object, and the fields that differ.
409
+ */
410
+ change?: ReadonlyArray<{
411
+ of: RegistrationDecl;
412
+ } & Partial<Pick<RegistrationDecl, 'values' | 'mode' | 'when' | 'allowStacking' | 'caps' | 'order' | 'label'>>>;
413
+ /** 🚧 Package requirements with version ranges — `acme.dice@^1.2` (A16). `use('…@range')` pipelines add their own. */
414
+ requires?: readonly string[];
415
+ /**
416
+ * ⏳ Which spec answers which event.
417
+ * @deprecated An alias to 0.7 — state `register` / `drop` / `change` on the genre's defaults.
418
+ */
419
+ bindings?: BindingEntry[];
420
+ /**
421
+ * ⏳ Which actions come along. Absent means the host's companion rule — see `PresetDecl.actions`.
422
+ * @deprecated An alias to 0.7 — register each action: `register(spec.actions.<key>, spec)`.
423
+ */
348
424
  actions?: {
349
425
  include: ActionPick[];
350
426
  };
351
427
  defaults?: PresetDefaultsInput;
428
+ /**
429
+ * 🚧 See `PresetDecl.callsPerTurn`.
430
+ * @deprecated ⏳ Accepted; derived from what is registered later (PLAN-layering D4).
431
+ */
432
+ callsPerTurn?: number;
433
+ /** 🚧 See `PresetDecl.cast`. */
434
+ cast?: {
435
+ characters?: number;
436
+ personas?: number;
437
+ };
438
+ /** 🚧 See `PresetDecl.settings` — each a value, or `{ value, lock?, askAtStart? }`. */
439
+ settings?: Readonly<Record<string, SettingValue>>;
352
440
  /** Ask the instance to offer this preset immediately. See `PresetDecl.enabled`. */
353
441
  enabled?: boolean;
354
442
  }
443
+ /**
444
+ * Keys that would make a preset build on another preset — refused (R2).
445
+ * @experimental
446
+ * @ruling R2
447
+ */
448
+ export declare const PRESET_PARENT_KEYS: readonly string[];
449
+ /**
450
+ * 🚧 **One level**, judged on a STORED preset (R2, R3) — the verdict the
451
+ * builder's refusal gives at `preset()`, for a preset that arrives as data (an
452
+ * announcement, a manifest, a row): it names a parent (`extends`, `base`, …),
453
+ * it belongs to no genre, or it drops or changes a registration that neither
454
+ * its genre's defaults nor its own `register` list holds (a change on a
455
+ * change). As sentences; empty when it is one set of changes on one genre's
456
+ * defaults. Conformance C37 reads it; a host's install may too.
457
+ * @experimental
458
+ * @ruling R2, R3, R22
459
+ */
460
+ export declare function presetLevelFindings(preset: {
461
+ slug?: string;
462
+ genre?: unknown;
463
+ registrations?: PresetRegistrationChanges;
464
+ } | null | undefined, genreDefaults?: readonly RegistrationDecl[]): string[];
465
+ /**
466
+ * 🚧 One `requires` entry read (A16): a package with a version range
467
+ * (`acme.dice@^1.2`), or a declared id (`acme:spec/x`, `core:event/x@1` — the
468
+ * `@1` of an event is its version, part of the id) with an optional range
469
+ * written after it (`acme:spec/x@^2`). `undefined` when it is neither.
470
+ * @experimental
471
+ * @ruling A16
472
+ */
473
+ export declare function parseRequirement(entry: string): {
474
+ requirement: string;
475
+ package: string;
476
+ id?: string;
477
+ range?: string;
478
+ } | undefined;
479
+ /**
480
+ * 🚧 The version ranges a manifest's (or an announcement's) `requires`
481
+ * names (A16) — one per entry that carries a range. The host enforces them
482
+ * at install (lane 5b); a preset whose requirement is missing or disabled is
483
+ * withdrawn, and nothing is deleted.
484
+ * @experimental
485
+ * @ruling A16
486
+ */
487
+ export declare function requirementRanges(manifest: {
488
+ requires?: readonly string[];
489
+ } | null | undefined): Array<{
490
+ requirement: string;
491
+ package: string;
492
+ id?: string;
493
+ range: string;
494
+ }>;
355
495
  /**
356
496
  * The stored form of a preset. Every reference is read down to its id and
357
497
  * checked against what the value says: a binding's events against its spec's