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

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 (123) hide show
  1. package/dist/actions.d.ts +29 -2
  2. package/dist/actions.js +20 -5
  3. package/dist/annexFields.d.ts +4 -1
  4. package/dist/annexFields.js +1 -0
  5. package/dist/announce.d.ts +142 -2
  6. package/dist/announce.js +198 -2
  7. package/dist/attributes.d.ts +281 -5
  8. package/dist/attributes.js +308 -27
  9. package/dist/bridges.d.ts +61 -0
  10. package/dist/bridges.js +112 -0
  11. package/dist/builder.d.ts +277 -50
  12. package/dist/builder.js +266 -29
  13. package/dist/cadences.d.ts +578 -0
  14. package/dist/cadences.js +1111 -0
  15. package/dist/capabilities.d.ts +93 -15
  16. package/dist/capabilities.js +57 -6
  17. package/dist/checkMethods.d.ts +240 -0
  18. package/dist/checkMethods.js +362 -0
  19. package/dist/component.d.ts +1 -1
  20. package/dist/composerStates.d.ts +96 -0
  21. package/dist/composerStates.js +190 -0
  22. package/dist/conditions.d.ts +424 -0
  23. package/dist/conditions.js +521 -0
  24. package/dist/config.d.ts +42 -6
  25. package/dist/config.js +48 -20
  26. package/dist/conversions.d.ts +41 -0
  27. package/dist/conversions.js +50 -0
  28. package/dist/declarations.d.ts +25 -2
  29. package/dist/declarations.js +149 -10
  30. package/dist/descriptors.d.ts +186 -4
  31. package/dist/descriptors.js +199 -18
  32. package/dist/document.d.ts +47 -2
  33. package/dist/document.js +46 -14
  34. package/dist/entities.d.ts +156 -0
  35. package/dist/entities.js +259 -0
  36. package/dist/events.d.ts +547 -1
  37. package/dist/events.js +345 -1
  38. package/dist/executor.d.ts +4 -3
  39. package/dist/executor.js +22 -8
  40. package/dist/exposure.d.ts +128 -0
  41. package/dist/exposure.js +168 -0
  42. package/dist/fit.d.ts +198 -0
  43. package/dist/fit.js +351 -0
  44. package/dist/functions.d.ts +554 -0
  45. package/dist/functions.js +712 -0
  46. package/dist/genres.d.ts +285 -89
  47. package/dist/genres.js +299 -100
  48. package/dist/hookGrants.d.ts +1 -1
  49. package/dist/hookGrants.js +1 -1
  50. package/dist/hooks.d.ts +21 -5
  51. package/dist/hooks.js +5 -2
  52. package/dist/hostElements.d.ts +7 -1
  53. package/dist/hostElements.js +14 -1
  54. package/dist/hostState.d.ts +110 -0
  55. package/dist/hostState.js +140 -0
  56. package/dist/identity.d.ts +1 -1
  57. package/dist/identity.js +1 -1
  58. package/dist/index.d.ts +21 -0
  59. package/dist/index.js +40 -0
  60. package/dist/jsonSchema.d.ts +178 -0
  61. package/dist/jsonSchema.js +558 -0
  62. package/dist/media.d.ts +127 -12
  63. package/dist/media.js +45 -1
  64. package/dist/messageBlocks.d.ts +179 -5
  65. package/dist/messageBlocks.js +208 -6
  66. package/dist/participants.d.ts +32 -9
  67. package/dist/participants.js +13 -2
  68. package/dist/pluginHarness.d.ts +14 -32
  69. package/dist/pluginHarness.js +14 -141
  70. package/dist/pluginPermissions.js +1 -1
  71. package/dist/preview.d.ts +45 -4
  72. package/dist/preview.js +52 -12
  73. package/dist/primers.d.ts +177 -0
  74. package/dist/primers.js +265 -0
  75. package/dist/receipt.d.ts +11 -0
  76. package/dist/refs.d.ts +9 -1
  77. package/dist/refs.js +12 -0
  78. package/dist/registrations.d.ts +384 -0
  79. package/dist/registrations.js +625 -0
  80. package/dist/repertoires.d.ts +502 -0
  81. package/dist/repertoires.js +666 -0
  82. package/dist/rulesetDocument.d.ts +95 -0
  83. package/dist/rulesetDocument.js +190 -0
  84. package/dist/rulesetSections.d.ts +597 -0
  85. package/dist/rulesetSections.js +1249 -0
  86. package/dist/rulesetTemplates.d.ts +161 -0
  87. package/dist/rulesetTemplates.js +242 -0
  88. package/dist/rulesets.d.ts +899 -0
  89. package/dist/rulesets.js +1378 -0
  90. package/dist/sceneSettings.d.ts +8 -0
  91. package/dist/sceneSettings.js +10 -2
  92. package/dist/scope.d.ts +44 -3
  93. package/dist/scope.js +18 -0
  94. package/dist/scripts.d.ts +31 -8
  95. package/dist/scripts.js +45 -8
  96. package/dist/sessionDossier.d.ts +124 -7
  97. package/dist/sessionLayout.d.ts +291 -138
  98. package/dist/sessionLayout.js +504 -211
  99. package/dist/sessionSettings.d.ts +24 -0
  100. package/dist/settings.d.ts +21 -0
  101. package/dist/shapes.d.ts +40 -1
  102. package/dist/shapes.js +52 -4
  103. package/dist/statShapes.d.ts +8 -1
  104. package/dist/statShapes.js +8 -1
  105. package/dist/status.d.ts +14 -0
  106. package/dist/status.js +12 -0
  107. package/dist/storage.d.ts +9 -66
  108. package/dist/storage.js +7 -12
  109. package/dist/templateScopeAt.d.ts +1 -1
  110. package/dist/templateScopeAt.js +11 -8
  111. package/dist/ties.d.ts +210 -0
  112. package/dist/ties.js +300 -0
  113. package/dist/turnOrder.d.ts +25 -14
  114. package/dist/turnOrder.js +21 -8
  115. package/dist/validate.js +114 -19
  116. package/dist/vocabularies.d.ts +192 -0
  117. package/dist/vocabularies.js +326 -0
  118. package/dist/widgetDecls.d.ts +12 -0
  119. package/dist/widgetDecls.js +2 -0
  120. package/dist/widgets.d.ts +597 -21
  121. package/dist/widgets.js +20 -0
  122. package/host-elements.d.ts +88 -0
  123. package/package.json +1 -1
package/dist/actions.d.ts CHANGED
@@ -363,6 +363,22 @@ export interface ActionDecl {
363
363
  recipients?: CollectedRecipients;
364
364
  clockStep?: CollectedClockStep;
365
365
  };
366
+ /**
367
+ * 🚧 A question asked before the action fires (2026-10-18, the 100-turn
368
+ * walk: _Reveal the planning notes_ cannot be taken back, and fired on
369
+ * one press). Every press — a chip, the palette, a widget's invoke —
370
+ * opens the host's confirmation (an `alertdialog`) with `question` as
371
+ * its title, `description` under it saying what goes and what stays,
372
+ * and a confirm button reading `confirmLabel` (absent: the action's
373
+ * `label`); Cancel fires nothing. A press that answers a form (a block)
374
+ * is not asked again: the form was the question. Display text, all of it.
375
+ * @experimental
376
+ */
377
+ confirm?: {
378
+ question: I18n;
379
+ description?: I18n;
380
+ confirmLabel?: I18n;
381
+ };
366
382
  }
367
383
  /** A declaration after normalisation: venues and predicates always lists, no alias spellings, no `function`. @experimental */
368
384
  export interface NormalizedAction extends ActionDecl {
@@ -420,7 +436,7 @@ export declare function placeActions<A extends {
420
436
  venue: ReadonlyArray<Venue>;
421
437
  quick?: boolean;
422
438
  }>(actions: ReadonlyArray<A>, channel?: string): VenueListings<A>;
423
- /** The namespace of a spec id — `core:spec/chat-narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
439
+ /** The namespace of a spec id — `core:spec/story-narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
424
440
  export declare function specNamespace(specId: string): string;
425
441
  /** Is this namespace core's — the one whose actions take bare slash names? @experimental */
426
442
  export declare const isCoreNamespace: (ns: string) => boolean;
@@ -508,7 +524,14 @@ export declare function collectsFindings(raw: unknown, where: string): string[];
508
524
  */
509
525
  export declare function actionFindings(raw: unknown, specId: string, at?: string): string[];
510
526
  /** `actionFindings`, each sentence with the law it comes from (`ActionFinding`). @experimental */
511
- export declare function actionFindingsByLaw(raw: unknown, specId: string, at?: string): ActionFinding[];
527
+ export declare function actionFindingsByLaw(raw: unknown, specId: string, at?: string, opts?: {
528
+ /**
529
+ * 🚧 The spec is mounted by registrations, not locked (PLAN-layering
530
+ * D3): its actions carry no genre — a registration that includes one
531
+ * offers it to that genre.
532
+ */
533
+ unlocked?: boolean;
534
+ }): ActionFinding[];
512
535
  /** The slash-name grammar, applied to one name for one spec. @experimental */
513
536
  export declare function slashFindings(slash: string, specId: string, where?: string): string[];
514
537
  /**
@@ -566,6 +589,8 @@ export declare function slashCollisions(actions: ReadonlyArray<NormalizedAction
566
589
  export declare function actionDocumentFindings(doc: {
567
590
  id: string;
568
591
  contributes?: unknown;
592
+ input?: unknown;
593
+ suits?: unknown;
569
594
  }): string[];
570
595
  /**
571
596
  * `actionDocumentFindings` with the law each sentence comes from — what
@@ -575,6 +600,8 @@ export declare function actionDocumentFindings(doc: {
575
600
  export declare function actionDocumentFindingsByLaw(doc: {
576
601
  id: string;
577
602
  contributes?: unknown;
603
+ input?: unknown;
604
+ suits?: unknown;
578
605
  }): ActionFinding[];
579
606
  /**
580
607
  * Who core's message verbs are for and where they live — the same shape a
package/dist/actions.js CHANGED
@@ -203,7 +203,7 @@ export function placeActions(actions, channel = DEFAULT_CHANNEL) {
203
203
  }
204
204
  return listings;
205
205
  }
206
- /** The namespace of a spec id — `core:spec/chat-narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
206
+ /** The namespace of a spec id — `core:spec/story-narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
207
207
  export function specNamespace(specId) {
208
208
  const i = specId.indexOf(':');
209
209
  return i === -1 ? '' : specId.slice(0, i);
@@ -372,7 +372,7 @@ export function actionFindings(raw, specId, at = 'contributes.actions') {
372
372
  return actionFindingsByLaw(raw, specId, at).map((f) => f.message);
373
373
  }
374
374
  /** `actionFindings`, each sentence with the law it comes from (`ActionFinding`). @experimental */
375
- export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
375
+ export function actionFindingsByLaw(raw, specId, at = 'contributes.actions', opts = {}) {
376
376
  const out = [];
377
377
  /** A fault in the declaration's shape (R-15). */
378
378
  const shape = (...messages) => {
@@ -390,7 +390,7 @@ export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
390
390
  const where = `${at}[${typeof a.key === 'string' ? a.key : '?'}]`;
391
391
  if (typeof a.key !== 'string' || !KEY.test(a.key))
392
392
  shape(`${where}: 'key' is required — a lowercase kebab token (${KEY.source})`);
393
- if (typeof a.genre !== 'string' || !a.genre)
393
+ if (opts.unlocked ? a.genre !== undefined && (typeof a.genre !== 'string' || !a.genre) : typeof a.genre !== 'string' || !a.genre)
394
394
  shape(`${where}: 'genre' is required — the genre id this action is offered to (24 §3), ` +
395
395
  `such as core:genre/chat`);
396
396
  const venues = Array.isArray(a.venue) ? a.venue : a.venue === undefined ? [] : [a.venue];
@@ -423,7 +423,7 @@ export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
423
423
  if (!isParticipantRef(r))
424
424
  shape(`${where}: audience.${half} names '${String(r)}', which is not a participant ` +
425
425
  `reference — one of ${PARTICIPANT_ROLES.join(', ')}, or user:<id>, ` +
426
- `character:<id>, envoy:<slug>`);
426
+ `character:<id>, player-seat:<id>, envoy:<slug>`);
427
427
  }
428
428
  }
429
429
  if (a.quick !== undefined && typeof a.quick !== 'boolean')
@@ -461,6 +461,18 @@ export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
461
461
  `({ en: 'Roll the dice and post the result.' })`);
462
462
  else
463
463
  shape(...i18nFindings(a.description, `${where}.description`));
464
+ if (a.confirm !== undefined) {
465
+ const c = a.confirm;
466
+ if (!c || typeof c !== 'object' || Array.isArray(c))
467
+ shape(`${where}.confirm is { question, description?, confirmLabel? } — the question asked before the action fires`);
468
+ else {
469
+ shape(...i18nFindings(c.question, `${where}.confirm.question`, { required: true }));
470
+ if (c.description !== undefined)
471
+ shape(...i18nFindings(c.description, `${where}.confirm.description`));
472
+ if (c.confirmLabel !== undefined)
473
+ shape(...i18nFindings(c.confirmLabel, `${where}.confirm.confirmLabel`));
474
+ }
475
+ }
464
476
  if (a.iconAlt !== undefined) {
465
477
  shape(...i18nFindings(a.iconAlt, `${where}.iconAlt`));
466
478
  if (a.icon === undefined)
@@ -660,9 +672,12 @@ export function actionDocumentFindingsByLaw(doc) {
660
672
  if (!c)
661
673
  return [];
662
674
  const out = [];
675
+ // 🚧 D3: a spec declared with `{ suits }` and no lock offers its actions
676
+ // where registrations include them — no genre on the declaration.
677
+ const unlocked = Array.isArray(doc.suits) && !doc.input;
663
678
  for (const entry of c.actions ?? []) {
664
679
  const a = normalizeAction(entry);
665
- out.push(...actionFindingsByLaw(a, doc.id));
680
+ out.push(...actionFindingsByLaw(a, doc.id, 'contributes.actions', { unlocked }));
666
681
  }
667
682
  if (out.length)
668
683
  return out;
@@ -112,7 +112,10 @@ export declare function annexFieldFindings(raw: unknown, at?: string): string[];
112
112
  * them while writing, never at a press.
113
113
  * @experimental
114
114
  */
115
- export declare function annexField(d: AnnexFieldInput): AnnexFieldDecl;
115
+ export declare function annexField<const D extends AnnexFieldInput>(d: D): AnnexFieldDecl & {
116
+ readonly key: D['key'];
117
+ readonly __declared?: D;
118
+ };
116
119
  /** Faults in a list of fields: each one's, and a key declared twice. @experimental */
117
120
  export declare function annexFieldListFindings(raw: unknown, at?: string): string[];
118
121
  /**
@@ -133,6 +133,7 @@ export function annexField(d) {
133
133
  const problems = annexFieldFindings(d, 'annexField');
134
134
  if (problems.length)
135
135
  throw new Error(problems.join('\n'));
136
+ // `__declared` is a phantom (never set): the field as written, for `sessionOf`'s annex typing.
136
137
  return Object.freeze({
137
138
  __decl: 'annex-field',
138
139
  key: d.key,
@@ -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
package/dist/announce.js CHANGED
@@ -32,8 +32,10 @@ const actionKeysOf = (v) => {
32
32
  return actionsOf({ id: v.id, contributes }).map((a) => a.key);
33
33
  };
34
34
  import { genre as makeGenre, genreIdOf, sessionEvents } from './genres.js';
35
+ import { registrationRange, } from './registrations.js';
35
36
  import { eventById, isEventId, isSessionEventDecl } from './events.js';
36
37
  import { makeValueToolkit } from './values.js';
38
+ import { SAVE_MESSAGE_SPEC_ID } from './descriptors.js';
37
39
  import { ACTION_IDENTITY, actionsOf } from './actions.js';
38
40
  import { i18nFindings } from './i18n.js';
39
41
  import { declarationFindings, labelFindings, storedSwap, subjectsOf, swapInputFindings, } from './declarations.js';
@@ -119,6 +121,102 @@ export function storedEventDeclaration(d) {
119
121
  recordedBy,
120
122
  };
121
123
  }
124
+ /**
125
+ * Keys that would make a preset build on another preset — refused (R2).
126
+ * @experimental
127
+ * @ruling R2
128
+ */
129
+ export const PRESET_PARENT_KEYS = Object.freeze(['extends', 'base', 'parent', 'from', 'preset', 'inherits']);
130
+ /** The one sentence for a preset that names a parent — the builder's refusal and C37's. */
131
+ const presetParentSentence = (where, k) => `${where} names '${k}' — a preset never builds on another preset (R2): it is one set of changes on ` +
132
+ `the genre's defaults. To start from another preset, copy its register / drop / change / settings`;
133
+ /**
134
+ * 🚧 **One level**, judged on a STORED preset (R2, R3) — the verdict the
135
+ * builder's refusal gives at `preset()`, for a preset that arrives as data (an
136
+ * announcement, a manifest, a row): it names a parent (`extends`, `base`, …),
137
+ * it belongs to no genre, or it drops or changes a registration that neither
138
+ * its genre's defaults nor its own `register` list holds (a change on a
139
+ * change). As sentences; empty when it is one set of changes on one genre's
140
+ * defaults. Conformance C37 reads it; a host's install may too.
141
+ * @experimental
142
+ * @ruling R2, R3, R22
143
+ */
144
+ export function presetLevelFindings(preset, genreDefaults) {
145
+ if (!preset || typeof preset !== 'object')
146
+ return ['a preset is an object — make it with preset({ … })'];
147
+ const where = `preset '${preset.slug ?? '?'}'`;
148
+ const out = [];
149
+ for (const k of PRESET_PARENT_KEYS)
150
+ if (preset[k] !== undefined)
151
+ out.push(presetParentSentence(where, k));
152
+ if (typeof preset.genre !== 'string' || !preset.genre)
153
+ out.push(`${where} names no genre — a preset belongs to one genre (R3) and changes that genre's defaults`);
154
+ const changes = preset.registrations;
155
+ if (changes && genreDefaults) {
156
+ const held = new Set([...genreDefaults.map((r) => r.key), ...(changes.register ?? []).map((r) => r.key)]);
157
+ for (const key of changes.drop ?? [])
158
+ if (!held.has(key))
159
+ out.push(`${where} drops '${key}', which its genre's defaults do not register — a preset changes the genre's defaults, never another preset's changes (R2)`);
160
+ for (const c of changes.change ?? [])
161
+ if (!held.has(c.key))
162
+ out.push(`${where} changes '${c.key}', which its genre's defaults do not register — a preset changes the genre's defaults, never another preset's changes (R2)`);
163
+ }
164
+ return out;
165
+ }
166
+ const isRegistrationShaped = (v) => !!v &&
167
+ typeof v === 'object' &&
168
+ typeof v.key === 'string' &&
169
+ !!v.trigger &&
170
+ typeof v.pipeline === 'string';
171
+ const isPresetShaped = (v) => !!v && typeof v === 'object' && typeof v.slug === 'string' && ('bindings' in v || 'genre' in v);
172
+ /** The fields a preset's `change` may state beside `of`. */
173
+ const PRESET_CHANGE_KEYS = ['values', 'mode', 'when', 'allowStacking', 'caps', 'order', 'label'];
174
+ /** `<package>@<range>` — a package requirement with a semver range (A16). */
175
+ const PACKAGE_REQUIREMENT = /^([a-z0-9]+(?:[.-][a-z0-9]+)*)@([~^<>=]*\s*\d[\w.+\-<>=|^~* ]*)$/;
176
+ /**
177
+ * 🚧 One `requires` entry read (A16): a package with a version range
178
+ * (`acme.dice@^1.2`), or a declared id (`acme:spec/x`, `core:event/x@1` — the
179
+ * `@1` of an event is its version, part of the id) with an optional range
180
+ * written after it (`acme:spec/x@^2`). `undefined` when it is neither.
181
+ * @experimental
182
+ * @ruling A16
183
+ */
184
+ export function parseRequirement(entry) {
185
+ if (typeof entry !== 'string' || !entry)
186
+ return undefined;
187
+ if (!entry.includes(':')) {
188
+ const m = PACKAGE_REQUIREMENT.exec(entry);
189
+ if (m)
190
+ return { requirement: entry, package: m[1], range: m[2].trim() };
191
+ return /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/.test(entry) ? { requirement: entry, package: entry } : undefined;
192
+ }
193
+ const pkg = entry.slice(0, entry.indexOf(':'));
194
+ const at = entry.lastIndexOf('@');
195
+ if (at > entry.indexOf(':')) {
196
+ const tail = entry.slice(at + 1);
197
+ // A whole number is a declared id's version (`core:event/x@1`), not a range.
198
+ if (!/^\d+$/.test(tail))
199
+ return { requirement: entry, package: pkg, id: entry.slice(0, at), range: tail };
200
+ }
201
+ return { requirement: entry, package: pkg, id: entry };
202
+ }
203
+ /**
204
+ * 🚧 The version ranges a manifest's (or an announcement's) `requires`
205
+ * names (A16) — one per entry that carries a range. The host enforces them
206
+ * at install (lane 5b); a preset whose requirement is missing or disabled is
207
+ * withdrawn, and nothing is deleted.
208
+ * @experimental
209
+ * @ruling A16
210
+ */
211
+ export function requirementRanges(manifest) {
212
+ const out = [];
213
+ for (const entry of manifest?.requires ?? []) {
214
+ const r = parseRequirement(entry);
215
+ if (r?.range)
216
+ out.push({ requirement: r.requirement, package: r.package, ...(r.id ? { id: r.id } : {}), range: r.range });
217
+ }
218
+ return out;
219
+ }
122
220
  const isBindingObject = (v) => !!v && typeof v === 'object' && 'spec' in v;
123
221
  /**
124
222
  * The stored form of a preset. Every reference is read down to its id and
@@ -133,11 +231,35 @@ export function preset(input) {
133
231
  if (typeof input.genre === 'string')
134
232
  throw new Error(`${where} names its genre as a string — pass the genre value (import it), or use('${input.genre}')`);
135
233
  const genre = isExternalRef(input.genre) ? input.genre.id : genreIdOf(input.genre);
234
+ // One level (R2): a preset is one set of changes on the genre's
235
+ // defaults, never on another preset. Cloning copies the changes.
236
+ for (const k of PRESET_PARENT_KEYS)
237
+ if (input[k] !== undefined)
238
+ throw new Error(presetParentSentence(where, k));
239
+ if (input.history !== undefined)
240
+ throw new Error(`${where} sets history — when a session's history settles is its genre's to say (history.settle), never a preset's.`);
241
+ const registrations = presetRegistrationsOf(input, where);
242
+ if (input.default !== undefined && input.default !== true)
243
+ throw new Error(`${where}.default: true, or leave it out`);
244
+ const requires = new Set();
245
+ for (const r of input.requires ?? []) {
246
+ if (!parseRequirement(r))
247
+ throw new Error(`${where}.requires: '${r}' is not a requirement — '<package>@<range>', such as 'acme.dice@^1.2'`);
248
+ requires.add(r);
249
+ }
250
+ for (const d of [...(input.register ?? []), ...(input.change ?? []).map((c) => c.of)]) {
251
+ const range = d ? registrationRange(d) : undefined;
252
+ if (range)
253
+ requires.add(`${d.pipeline.slice(0, d.pipeline.indexOf(':'))}@${range}`);
254
+ }
136
255
  const bindings = {};
137
- if (!Array.isArray(input.bindings))
256
+ // ⏳ The bindings alias (D4): kept exactly as it was, so a preset still
257
+ // declared with it stores — and hashes — as it always did.
258
+ const aliased = input.bindings !== undefined;
259
+ if (aliased && !Array.isArray(input.bindings))
138
260
  throw new Error(`${where}: bindings is a list of specs — [createSession, { spec: respond, config: tuned }]; ` +
139
261
  `each is bound on the events its inlet lock answers`);
140
- for (const [i, raw] of input.bindings.entries()) {
262
+ for (const [i, raw] of (input.bindings ?? []).entries()) {
141
263
  const entry = isBindingObject(raw) ? raw : { spec: raw };
142
264
  const at = `${where} binding ${i + 1}`;
143
265
  const id = specIdOf(entry.spec, at);
@@ -173,6 +295,16 @@ export function preset(input) {
173
295
  bindings[event] = { spec: id, ...(configSlug !== undefined ? { config: configSlug } : {}) };
174
296
  }
175
297
  }
298
+ /**
299
+ * 🚧 A person's message is always saved through a pipeline (owner ruling
300
+ * 2026-10-15). A preset that binds nothing on `message-offered` binds
301
+ * core's default save, `core:spec/save-message` — written into the
302
+ * stored preset here, so the preset shows what saves a message rather
303
+ * than a host deciding it out of sight. A preset that binds its own spec
304
+ * there (a genre that refuses, rewrites or routes a message) keeps it.
305
+ */
306
+ if (aliased && !bindings[sessionEvents.messageOffered])
307
+ bindings[sessionEvents.messageOffered] = { spec: SAVE_MESSAGE_SPEC_ID };
176
308
  const include = (pick, n) => {
177
309
  const at = `${where} action ${n + 1}`;
178
310
  if (typeof pick === 'string')
@@ -208,6 +340,10 @@ export function preset(input) {
208
340
  label: input.label,
209
341
  description: input.description,
210
342
  bindings,
343
+ // 🚧 D4: present only when declared, so a preset on the aliases hashes as it did.
344
+ ...(registrations ? { registrations } : {}),
345
+ ...(input.default ? { default: true } : {}),
346
+ ...(requires.size ? { requires: [...requires].sort() } : {}),
211
347
  ...(input.actions ? { actions: { include: input.actions.include.flatMap(include) } } : {}),
212
348
  ...(input.defaults
213
349
  ? {
@@ -221,7 +357,67 @@ export function preset(input) {
221
357
  // nothing hashes as it always did — the announcement is content-hashed
222
358
  // like every other declaration here.
223
359
  ...(input.enabled === undefined ? {} : { enabled: input.enabled }),
360
+ ...(input.callsPerTurn !== undefined ? { callsPerTurn: assertCallsPerTurn(input.callsPerTurn, where) } : {}),
361
+ ...(input.cast ? { cast: assertCastFloor(input.cast, where) } : {}),
362
+ ...(input.settings && Object.keys(input.settings).length ? { settings: { ...input.settings } } : {}),
363
+ };
364
+ }
365
+ const assertCallsPerTurn = (v, where) => {
366
+ if (typeof v !== 'number' || !Number.isInteger(v) || v < 0)
367
+ throw new Error(`${where}.callsPerTurn is a whole number of model calls (0 or more)`);
368
+ return v;
369
+ };
370
+ const assertCastFloor = (v, where) => {
371
+ for (const k of ['characters', 'personas']) {
372
+ const n = v[k];
373
+ if (n !== undefined && (typeof n !== 'number' || !Number.isInteger(n) || n < 0))
374
+ throw new Error(`${where}.cast.${k} is a whole number (0 or more)`);
375
+ }
376
+ return { ...(v.characters !== undefined ? { characters: v.characters } : {}), ...(v.personas !== undefined ? { personas: v.personas } : {}) };
377
+ };
378
+ /**
379
+ * A preset's `register` / `drop` / `change`, read down to the stored changes
380
+ * (keys for the dropped and changed, derived from the registrations handed
381
+ * in). Throws the first mistake, with the fix.
382
+ */
383
+ function presetRegistrationsOf(input, where) {
384
+ if (input.register === undefined && input.drop === undefined && input.change === undefined)
385
+ return undefined;
386
+ const one = (v, at) => {
387
+ if (isPresetShaped(v) && !isRegistrationShaped(v))
388
+ throw new Error(`${at} names a preset — a preset never builds on another preset (R2); name registrations`);
389
+ if (!isRegistrationShaped(v))
390
+ throw new Error(`${at} is not a registration — make it with register(trigger, pipeline, { … })`);
391
+ return v;
224
392
  };
393
+ const list = (v, name) => {
394
+ if (v === undefined)
395
+ return [];
396
+ if (!Array.isArray(v))
397
+ throw new Error(`${where}.${name} is a list of registrations`);
398
+ return v;
399
+ };
400
+ const register = list(input.register, 'register').map((r, i) => one(r, `${where}.register[${i}]`));
401
+ const drop = list(input.drop, 'drop').map((r, i) => one(r, `${where}.drop[${i}]`).key);
402
+ const change = list(input.change, 'change').map((raw, i) => {
403
+ const at = `${where}.change[${i}]`;
404
+ if (!raw || typeof raw !== 'object')
405
+ throw new Error(`${at}: { of: registration, …changes }`);
406
+ const c = raw;
407
+ const of = one(c.of, `${at}.of`);
408
+ for (const k of Object.keys(c))
409
+ if (k !== 'of' && !PRESET_CHANGE_KEYS.includes(k))
410
+ throw new Error(`${at}: '${k}' is not something a preset changes — one of ${PRESET_CHANGE_KEYS.join(', ')}`);
411
+ return Object.freeze({
412
+ key: of.key,
413
+ ...Object.fromEntries(PRESET_CHANGE_KEYS.filter((k) => c[k] !== undefined).map((k) => [k, c[k]])),
414
+ });
415
+ });
416
+ return Object.freeze({
417
+ ...(register.length ? { register: Object.freeze(register) } : {}),
418
+ ...(drop.length ? { drop: Object.freeze(drop) } : {}),
419
+ ...(change.length ? { change: Object.freeze(change) } : {}),
420
+ });
225
421
  }
226
422
  const NS = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
227
423
  /** @internal The builder behind `announcementOf()`; author a package with `defineExtension()`. */