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

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 (62) hide show
  1. package/dist/announce.d.ts +36 -3
  2. package/dist/announce.js +59 -4
  3. package/dist/builder.d.ts +5 -7
  4. package/dist/cadences.d.ts +1 -3
  5. package/dist/componentWire.js +28 -0
  6. package/dist/conditions.d.ts +5 -1
  7. package/dist/conditions.js +7 -0
  8. package/dist/declarations.d.ts +63 -1
  9. package/dist/declarations.js +172 -7
  10. package/dist/descriptors.d.ts +86 -12
  11. package/dist/descriptors.js +83 -5
  12. package/dist/document.d.ts +1 -1
  13. package/dist/events.d.ts +68 -25
  14. package/dist/events.js +35 -2
  15. package/dist/executor.d.ts +27 -0
  16. package/dist/executor.js +6 -3
  17. package/dist/exposure.d.ts +35 -1
  18. package/dist/exposure.js +64 -2
  19. package/dist/extension.d.ts +13 -2
  20. package/dist/extension.js +3 -1
  21. package/dist/genres.d.ts +61 -3
  22. package/dist/genres.js +131 -10
  23. package/dist/hostElements.d.ts +3 -3
  24. package/dist/hostElements.js +12 -4
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/participants.d.ts +30 -0
  28. package/dist/provisos.d.ts +92 -0
  29. package/dist/provisos.js +273 -0
  30. package/dist/receiverRules.js +1 -1
  31. package/dist/registrations.d.ts +154 -14
  32. package/dist/registrations.js +293 -23
  33. package/dist/repertoires.d.ts +13 -1
  34. package/dist/repertoires.js +5 -1
  35. package/dist/rulesetDocument.d.ts +11 -0
  36. package/dist/rulesetDocument.js +17 -0
  37. package/dist/rulesetSections.d.ts +12 -0
  38. package/dist/rulesetSections.js +8 -0
  39. package/dist/rulesets.js +6 -0
  40. package/dist/sceneSettings.d.ts +3 -1
  41. package/dist/sceneSettings.js +3 -1
  42. package/dist/sessionDossier.d.ts +102 -2
  43. package/dist/sessionSettings.d.ts +18 -0
  44. package/dist/shapes.d.ts +9 -0
  45. package/dist/shapes.js +9 -0
  46. package/dist/speech.d.ts +14 -3
  47. package/dist/storyTime.d.ts +77 -1
  48. package/dist/storyTime.js +111 -4
  49. package/dist/surfaces.d.ts +38 -1
  50. package/dist/surfaces.js +3 -0
  51. package/dist/template.d.ts +13 -1
  52. package/dist/templateCheck.js +175 -12
  53. package/dist/templateFit.js +4 -1
  54. package/dist/validate.js +69 -0
  55. package/dist/variableLayouts.d.ts +19 -0
  56. package/dist/variableLayouts.js +19 -0
  57. package/dist/variables.d.ts +202 -13
  58. package/dist/variables.js +258 -32
  59. package/dist/widgets.d.ts +68 -9
  60. package/dist/widgets.js +10 -2
  61. package/host-elements.d.ts +4 -2
  62. package/package.json +1 -1
@@ -72,7 +72,7 @@ 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';
75
+ import { type PresetRegistrationChanges, type RegistrationDecl, type RoutineGroupDecl } from './registrations.js';
76
76
  import type { SettingValue } from './exposure.js';
77
77
  import type { VariableId } from './variables.js';
78
78
  import { type SessionEventDecl } from './events.js';
@@ -142,6 +142,22 @@ export interface PromptDecl {
142
142
  label: I18n;
143
143
  /** Field name → prose, exactly as that slot declares them. */
144
144
  fields: Record<string, string>;
145
+ /**
146
+ * The pipeline this prompt is filed under: the spec's `id`
147
+ * (`<owner>:spec/<name>`, versionless). Session owners are offered the prompt
148
+ * on that pipeline's steps, and every other pipeline stops offering it.
149
+ * Absent: administrators only.
150
+ *
151
+ * It may name another package's pipeline. That is accepted: on a pub where
152
+ * that pipeline is not installed it resolves to nothing, and the prompt is
153
+ * offered to administrators only.
154
+ *
155
+ * ⚠ Not `defaultForSpecs` — that says which pipelines' shipped configuration
156
+ * *starts* on a row, a different claim.
157
+ * @experimental
158
+ * @ruling PR3
159
+ */
160
+ forPipeline?: string;
145
161
  }
146
162
  /**
147
163
  * A named configuration: a typed delta over a spec's author defaults.
@@ -199,7 +215,8 @@ export interface PresetBinding {
199
215
  * recognises, type-checks each, and ignores the rest — so a preset written
200
216
  * against a newer genre than the instance has can still be started, and a
201
217
  * genre's own fields ride along in `genreFields` rather than growing this
202
- * shape a key at a time.
218
+ * shape a key at a time. The exception is `timeline`: a genre that requires a
219
+ * timeline (`GenreDecl.timeline`) refuses `timeline: false` at declaration.
203
220
  * @experimental
204
221
  * @ruling 23 §9
205
222
  */
@@ -230,6 +247,15 @@ export interface PresetDefaults {
230
247
  * @ruling R-18, U5g
231
248
  */
232
249
  envoys?: string[];
250
+ /**
251
+ * 🚧 A preset's timeline default: whether a new session's lorebook starts
252
+ * with a timeline when the session starts on its own notes. Left out = none,
253
+ * unless the genre requires one (`GenreDecl.timeline`). A genre
254
+ * that requires a timeline (`GenreDecl.timeline`) refuses `false` at
255
+ * declaration. Only a default for a new session's lorebook; the lorebook
256
+ * decides whether story time moves.
257
+ */
258
+ timeline?: boolean;
233
259
  }
234
260
  /**
235
261
  * A preset populates a genre's event slots: for each event the genre
@@ -410,7 +436,14 @@ export interface PresetInput {
410
436
  */
411
437
  change?: ReadonlyArray<{
412
438
  of: RegistrationDecl;
439
+ group?: RoutineGroupDecl;
413
440
  } & Partial<Pick<RegistrationDecl, 'values' | 'mode' | 'when' | 'allowStacking' | 'caps' | 'order' | 'label'>>>;
441
+ /** 🚧 Routine groups this preset declares — `routineGroup(cadence, { key })` values. */
442
+ groups?: readonly RoutineGroupDecl[];
443
+ /** 🚧 Changes to routine groups of the genre's defaults — `{ of: scenes, run: 'parallel' }`: the routine group object, and the fields that differ. */
444
+ changeGroups?: ReadonlyArray<{
445
+ of: RoutineGroupDecl;
446
+ } & Partial<Pick<RoutineGroupDecl, 'cadence' | 'label' | 'when' | 'allowStacking' | 'caps' | 'run'>>>;
414
447
  /** 🚧 Package requirements with version ranges — `acme.dice@^1.2` (A16). `use('…@range')` pipelines add their own. */
415
448
  requires?: readonly string[];
416
449
  /**
@@ -464,7 +497,7 @@ export declare function presetLevelFindings(preset: {
464
497
  slug?: string;
465
498
  genre?: unknown;
466
499
  registrations?: PresetRegistrationChanges;
467
- } | null | undefined, genreDefaults?: readonly RegistrationDecl[]): string[];
500
+ } | null | undefined, genreDefaults?: readonly RegistrationDecl[], genreGroups?: readonly RoutineGroupDecl[]): string[];
468
501
  /**
469
502
  * 🚧 One `requires` entry read (A16): a package with a version range
470
503
  * (`acme.dice@^1.2`), or a declared id (`acme:spec/x`, `core:event/x@1` — the
package/dist/announce.js CHANGED
@@ -142,7 +142,7 @@ const presetParentSentence = (where, k) => `${where} names '${k}' — a preset n
142
142
  * @experimental
143
143
  * @ruling R2, R3, R22
144
144
  */
145
- export function presetLevelFindings(preset, genreDefaults) {
145
+ export function presetLevelFindings(preset, genreDefaults, genreGroups) {
146
146
  if (!preset || typeof preset !== 'object')
147
147
  return ['a preset is an object — make it with preset({ … })'];
148
148
  const where = `preset '${preset.slug ?? '?'}'`;
@@ -162,8 +162,19 @@ export function presetLevelFindings(preset, genreDefaults) {
162
162
  if (!held.has(c.key))
163
163
  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)`);
164
164
  }
165
+ if (changes && genreGroups) {
166
+ const held = new Set([...genreGroups.map((g) => g.key), ...(changes.groups ?? []).map((g) => g.key)]);
167
+ for (const c of changes.changeGroups ?? [])
168
+ if (!held.has(c.key))
169
+ out.push(`${where} changes routine group '${c.key}', which its genre's defaults do not declare — a preset changes the genre's defaults, never another preset's changes (R2)`);
170
+ }
165
171
  return out;
166
172
  }
173
+ const isRoutineGroupShaped = (v) => !!v &&
174
+ typeof v === 'object' &&
175
+ typeof v.key === 'string' &&
176
+ !!v.cadence &&
177
+ typeof v.cadence.id === 'string';
167
178
  const isRegistrationShaped = (v) => !!v &&
168
179
  typeof v === 'object' &&
169
180
  typeof v.key === 'string' &&
@@ -171,7 +182,9 @@ const isRegistrationShaped = (v) => !!v &&
171
182
  typeof v.pipeline === 'string';
172
183
  const isPresetShaped = (v) => !!v && typeof v === 'object' && typeof v.slug === 'string' && ('bindings' in v || 'genre' in v);
173
184
  /** The fields a preset's `change` may state beside `of`. */
174
- const PRESET_CHANGE_KEYS = ['values', 'mode', 'when', 'allowStacking', 'caps', 'order', 'label'];
185
+ const PRESET_CHANGE_KEYS = ['values', 'mode', 'when', 'allowStacking', 'caps', 'order', 'label', 'group'];
186
+ /** The fields a preset's `changeGroups` may state beside `of`. */
187
+ const PRESET_GROUP_CHANGE_KEYS = ['cadence', 'label', 'when', 'allowStacking', 'caps', 'run'];
175
188
  /** `<package>@<range>` — a package requirement with a semver range (A16). */
176
189
  const PACKAGE_REQUIREMENT = /^([a-z0-9]+(?:[.-][a-z0-9]+)*)@([~^<>=]*\s*\d[\w.+\-<>=|^~* ]*)$/;
177
190
  /**
@@ -268,6 +281,13 @@ export function preset(input) {
268
281
  throw new Error(presetParentSentence(where, k));
269
282
  if (input.history !== undefined)
270
283
  throw new Error(`${where} sets history — when a session's history settles is its genre's to say (history.settle), never a preset's.`);
284
+ if (input.defaults?.timeline !== undefined && typeof input.defaults.timeline !== 'boolean')
285
+ throw new Error(`${where}.defaults.timeline: true or false, or leave it out`);
286
+ // 🚧 A genre named by `use(…)` is another package's and cannot be checked here; the host's resolver lets the mandate win.
287
+ if (input.defaults?.timeline === false &&
288
+ !isExternalRef(input.genre) &&
289
+ input.genre?.timeline === 'required')
290
+ throw new Error(`${where} sets defaults.timeline: false, but its genre '${genre}' requires a timeline — leave it out, or set it true`);
271
291
  const registrations = presetRegistrationsOf(input, where);
272
292
  if (input.default !== undefined && input.default !== true)
273
293
  throw new Error(`${where}.default: true, or leave it out`);
@@ -412,7 +432,11 @@ const assertCastFloor = (v, where) => {
412
432
  * in). Throws the first mistake, with the fix.
413
433
  */
414
434
  function presetRegistrationsOf(input, where) {
415
- if (input.register === undefined && input.drop === undefined && input.change === undefined)
435
+ if (input.register === undefined &&
436
+ input.drop === undefined &&
437
+ input.change === undefined &&
438
+ input.groups === undefined &&
439
+ input.changeGroups === undefined)
416
440
  return undefined;
417
441
  const one = (v, at) => {
418
442
  if (isPresetShaped(v) && !isRegistrationShaped(v))
@@ -439,15 +463,46 @@ function presetRegistrationsOf(input, where) {
439
463
  for (const k of Object.keys(c))
440
464
  if (k !== 'of' && !PRESET_CHANGE_KEYS.includes(k))
441
465
  throw new Error(`${at}: '${k}' is not something a preset changes — one of ${PRESET_CHANGE_KEYS.join(', ')}`);
466
+ if (c.group !== undefined && !isRoutineGroupShaped(c.group))
467
+ throw new Error(`${at}.group is not a routine group — pass routineGroup(…)`);
442
468
  return Object.freeze({
443
469
  key: of.key,
444
- ...Object.fromEntries(PRESET_CHANGE_KEYS.filter((k) => c[k] !== undefined).map((k) => [k, c[k]])),
470
+ ...Object.fromEntries(PRESET_CHANGE_KEYS.filter((k) => c[k] !== undefined).map((k) => [
471
+ k,
472
+ k === 'group' ? c.group.key : c[k],
473
+ ])),
474
+ });
475
+ });
476
+ if (input.groups !== undefined && !Array.isArray(input.groups))
477
+ throw new Error(`${where}.groups is a list of routine groups`);
478
+ const groups = (input.groups ?? []).map((g, i) => {
479
+ if (!isRoutineGroupShaped(g))
480
+ throw new Error(`${where}.groups[${i}] is not a routine group — make it with routineGroup(cadence, { key })`);
481
+ return g;
482
+ });
483
+ if (input.changeGroups !== undefined && !Array.isArray(input.changeGroups))
484
+ throw new Error(`${where}.changeGroups is a list of routine group changes`);
485
+ const changeGroups = (input.changeGroups ?? []).map((raw, i) => {
486
+ const at = `${where}.changeGroups[${i}]`;
487
+ if (!raw || typeof raw !== 'object')
488
+ throw new Error(`${at}: { of: routine group, …changes }`);
489
+ const c = raw;
490
+ if (!isRoutineGroupShaped(c.of))
491
+ throw new Error(`${at}.of is not a routine group — make it with routineGroup(cadence, { key })`);
492
+ for (const k of Object.keys(c))
493
+ if (k !== 'of' && !PRESET_GROUP_CHANGE_KEYS.includes(k))
494
+ throw new Error(`${at}: '${k}' is not something a preset changes — one of ${PRESET_GROUP_CHANGE_KEYS.join(', ')}`);
495
+ return Object.freeze({
496
+ key: c.of.key,
497
+ ...Object.fromEntries(PRESET_GROUP_CHANGE_KEYS.filter((k) => c[k] !== undefined).map((k) => [k, c[k]])),
445
498
  });
446
499
  });
447
500
  return Object.freeze({
448
501
  ...(register.length ? { register: Object.freeze(register) } : {}),
449
502
  ...(drop.length ? { drop: Object.freeze(drop) } : {}),
450
503
  ...(change.length ? { change: Object.freeze(change) } : {}),
504
+ ...(groups.length ? { groups: Object.freeze(groups) } : {}),
505
+ ...(changeGroups.length ? { changeGroups: Object.freeze(changeGroups) } : {}),
451
506
  });
452
507
  }
453
508
  const NS = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
package/dist/builder.d.ts CHANGED
@@ -229,7 +229,7 @@ export interface BuiltNode {
229
229
  status?: I18n;
230
230
  label?: I18n;
231
231
  purpose?: I18n;
232
- /** 🚧 R54: the owner chooses this step's prompt (among those not hidden) — see `NodeOpts.expose.promptReach`. */
232
+ /** ⏳ Transitional (R6): ignored by the host, which offers the owner every model call's prompt choice — see `NodeOpts.expose.promptReach`. */
233
233
  promptReach?: 'owner';
234
234
  };
235
235
  /** The placement's `prefers`, when stated — see `NodeOpts.prefers`. */
@@ -498,12 +498,10 @@ export interface NodeOpts {
498
498
  /** The step purpose: what this step is for, under its settings heading — see `BuiltNode.expose` for where it is allowed. */
499
499
  purpose?: I18n;
500
500
  /**
501
- * 🚧 **The prompt choice's reach** (R54, 2026-10-21): `'owner'` offers
502
- * the session's owner a choice of this step's prompt — among the
503
- * prompts of its slot's pool an administrator has not hidden — as a
504
- * setting of the pipeline. Never the prompt's text: members never edit
505
- * a prompt. Only on a step whose definition declares a `prompts` slot.
506
- * Absent: an administrator's choice alone.
501
+ * ⏳ **Transitional** (R6): the host offers a session's owner the
502
+ * prompt choice of every model call that offers one, whatever this
503
+ * says — the choice, never the prompt's text. Kept so existing specs
504
+ * build; its only value is `'owner'`.
507
505
  */
508
506
  promptReach?: 'owner';
509
507
  };
@@ -48,7 +48,7 @@ import type { EntityKind } from './entities.js';
48
48
  import { type FieldDecl } from './settings.js';
49
49
  import { type I18n } from './i18n.js';
50
50
  import { type ConditionDecl } from './conditions.js';
51
- import { type EventDef, type SessionEventDecl, type TurnSeatChange } from './events.js';
51
+ import { type EventDef, type SessionEventDecl } from './events.js';
52
52
  import { type StoryCalendar, type StoryTime, type StoryTimeUnit } from './storyTime.js';
53
53
  /** 🚧 `core:event/turn-ended@1` — a turn ended (R51). @experimental */
54
54
  export declare const TURN_ENDED_EVENT: 'core:event/turn-ended@1';
@@ -575,8 +575,6 @@ export interface RoutineCause {
575
575
  turnsBy?: Readonly<Record<string, number>>;
576
576
  /** 🚧 `round-ended`: who spoke in the round, in order of first turn (R52). */
577
577
  speakers?: readonly string[];
578
- /** 🚧 `turn-ended`, when the genre declares `shape.turnSeatChanges: true`: the seats that changed since the previous turn (`TurnSeatChange`). */
579
- turnSeatChanges?: readonly TurnSeatChange[];
580
578
  actor?: string;
581
579
  castMember?: string;
582
580
  subject?: string;
@@ -102,6 +102,34 @@ export function createComponentContext(port) {
102
102
  case 'messages':
103
103
  data.messages = m.messages;
104
104
  return notify('messages');
105
+ case 'message': {
106
+ // Replaces one held row by id. A host sends it only to a peer it
107
+ // knows receives it; the full `messages`/`channel` posts still
108
+ // carry every add and remove. Arrays are copied, never mutated:
109
+ // a component may still hold the old one.
110
+ const row = m.message;
111
+ const id = row?.id;
112
+ if (!row || typeof row !== 'object' || typeof id !== 'number')
113
+ return;
114
+ const at = data.messages?.findIndex((r) => r.id === id) ?? -1;
115
+ if (data.messages && at >= 0) {
116
+ data.messages = data.messages.map((r, k) => (k === at ? row : r));
117
+ notify('messages');
118
+ }
119
+ let channels;
120
+ for (const [ch, list] of Object.entries(data.channels)) {
121
+ const k = list.findIndex((r) => r.id === id);
122
+ if (k < 0)
123
+ continue;
124
+ channels ??= { ...data.channels };
125
+ channels[ch] = list.map((r, j) => (j === k ? row : r));
126
+ }
127
+ if (channels) {
128
+ data.channels = channels;
129
+ notify('channels');
130
+ }
131
+ return;
132
+ }
105
133
  case 'channel':
106
134
  data.channels = { ...data.channels, [String(m.channel)]: m.messages };
107
135
  return notify('channels');
@@ -281,7 +281,7 @@ type AnnexOf<O> = O extends {
281
281
  } : {};
282
282
  /**
283
283
  * 🚧 The host's fixed facts a condition may test (A5): whether the session is
284
- * generating, its turn, round and last speaker (R51, R52), the open form's action, the backdrop, each cast member's current
284
+ * generating, its turn, round and last speaker (R51, R52), the round of a story channel by name, the open form's action, the backdrop, each cast member's current
285
285
  * sprite, which invokable functions the session's rules use (S3), and — on an action that carries one — the message (`item.*` in the
286
286
  * published values; absent elsewhere, so a condition on it reads false).
287
287
  * @experimental
@@ -294,6 +294,10 @@ export interface SessionHostFacts {
294
294
  readonly turn: ConditionProp<number, 'number'>;
295
295
  /** 🚧 `session.round` — the round in progress on the story's lane, counted from 1 (R52). */
296
296
  readonly round: ConditionProp<number, 'number'>;
297
+ /**
298
+ * 🚧 `session.rounds.<channel>` — the round in progress on one of the genre's story channels, counted from 1 (CP1). `main`'s equals `session.round`; a channel that is not a story channel reads as absent, so a condition on it is false.
299
+ */
300
+ readonly rounds: (channel: string) => ConditionProp<number, 'number'>;
297
301
  /** 🚧 `session.lastSpeaker` — who took the last turn on the story's lane: a participant reference, or `narrator` (R51). */
298
302
  readonly lastSpeaker: ConditionProp<string, 'string'>;
299
303
  /** `session.openForm.action` — the action that answers the open form, when one is open. */
@@ -48,6 +48,7 @@
48
48
  * @ruling R31, A5, A19
49
49
  */
50
50
  import { readPath, truthy as isTruthy } from './predicates.js';
51
+ import { formatChannel, parseChannel } from './channels.js';
51
52
  import { getAttributeSlot, slotSlug } from './attributes.js';
52
53
  import { getStatShape } from './statShapes.js';
53
54
  import { hostStateFor } from './hostState.js';
@@ -369,6 +370,12 @@ function hostFacts() {
369
370
  generating: prop('session.generating', 'boolean'),
370
371
  turn: prop('session.turn', 'number'),
371
372
  round: prop('session.round', 'number'),
373
+ rounds: (channel) => {
374
+ const slug = typeof channel === 'string' && channel ? formatChannel(parseChannel(channel)) : '';
375
+ if (!slug || slug.includes('.') || slug.includes('*'))
376
+ throw new Error("s.rounds(channel): name a channel by its slug — 'main', or one the genre declares with lore: 'story'");
377
+ return prop(`session.rounds.${slug}`, 'number');
378
+ },
372
379
  lastSpeaker: prop('session.lastSpeaker', 'string'),
373
380
  openForm: Object.freeze({ action: prop('session.openForm.action', 'string') }),
374
381
  backdrop: Object.freeze({ set: prop('backdrop.set', 'boolean'), mediaId: prop('backdrop.mediaId', 'number') }),
@@ -24,6 +24,7 @@ import type { WidgetDecl } from './layout.js';
24
24
  import type { AnnouncedSpec, ExternalRef, StoredEventDeclaration, ConfigDecl, CoverageReport, PresetDecl, PromptDecl } from './announce.js';
25
25
  import { type ComponentDecl } from './extension.js';
26
26
  import { type GenreDecl } from './genres.js';
27
+ import { type RegistrationDecl } from './registrations.js';
27
28
  import { type SurfacesDecl } from './surfaces.js';
28
29
  import { type AnnexFieldDecl } from './annexFields.js';
29
30
  /**
@@ -52,6 +53,11 @@ export interface DeclaredPackage {
52
53
  * @ruling R29
53
54
  */
54
55
  swaps?: readonly (SwapContribution | StoredSwapContribution)[];
56
+ /**
57
+ * Turn order options this package adds to genres it names.
58
+ * @ruling TQ1, TQ2, TQ4 (owner 2026-11-19)
59
+ */
60
+ turnOrderOptions?: readonly (TurnOrderOptionDecl | StoredTurnOrderOption)[];
55
61
  /** Events this package declares, with who may record them. */
56
62
  events?: readonly StoredEventDeclaration[];
57
63
  /**
@@ -90,6 +96,55 @@ export interface StoredSwapContribution {
90
96
  }
91
97
  /** The stored form of a contribution — the spec and the pin read down to their ids. @experimental */
92
98
  export declare const storedSwap: (c: SwapContribution | StoredSwapContribution) => StoredSwapContribution;
99
+ /**
100
+ * One turn order option a plugin adds to a genre it names — `{ genre: storyGenre,
101
+ * option: register(coreEvents.turnOrderAsked, natural, { label: 'Natural hand-off' }) }`.
102
+ * The option never marks `default`: a plugin never changes a genre's default.
103
+ * @experimental
104
+ * @ruling TQ1, TQ2, TQ4 (owner 2026-11-19)
105
+ */
106
+ export interface TurnOrderOptionDecl {
107
+ /** The genre it is offered in — the genre value, or its id for one you cannot import. Never this package's own genre. */
108
+ genre: GenreDecl | string;
109
+ /** A registration on Turn order asked, made by `register()`. */
110
+ option: RegistrationDecl;
111
+ }
112
+ /** As stored in the manifest: the genre read down to its id. @experimental */
113
+ export interface StoredTurnOrderOption {
114
+ genre: string;
115
+ option: RegistrationDecl;
116
+ }
117
+ /**
118
+ * The stored form of an option — the genre read down to its id; the option is
119
+ * the same object, so the registration door still recognises `register()`'s.
120
+ * @experimental
121
+ */
122
+ export declare const storedTurnOrderOption: (o: TurnOrderOptionDecl | StoredTurnOrderOption) => StoredTurnOrderOption;
123
+ /**
124
+ * Turn order options a package adds to genres it names. Each is a registration
125
+ * on Turn order asked, labelled, marking no default, running a pipeline the
126
+ * package ships (a model is asked only through core's turn advise, R53), in a
127
+ * genre that is not this package's own. A genre that is neither core's nor the
128
+ * package's is accepted and not required: the instance offers the option once
129
+ * that genre arrives. Reads both the authored and the stored form.
130
+ * @experimental
131
+ * @ruling TQ1, TQ2, TQ4 (owner 2026-11-19)
132
+ */
133
+ export declare function turnOrderOptionFindings(options: readonly (TurnOrderOptionDecl | StoredTurnOrderOption)[], ctx: {
134
+ /** The package's namespace; optional (a catalogue judged without one). */
135
+ ns?: string;
136
+ /** The package's own pipelines, by spec id. */
137
+ pipelines: ReadonlyMap<string, AnnouncedSpec>;
138
+ /** The package's own genre ids. */
139
+ genres?: ReadonlySet<string>;
140
+ /** Whether a `core:` genre id is one core ships. Absent: the genre registry, when it holds core's genres; otherwise not judged. */
141
+ knownGenre?: (id: string) => boolean;
142
+ /** Filled with the core events the options register on (a requirement on the host's version). */
143
+ requires?: Set<string>;
144
+ }): {
145
+ errors: string[];
146
+ warnings: string[];
147
+ };
93
148
  /**
94
149
  * Swaps as authored: the spec is a value and the definition a pin. A
95
150
  * string is refused here, at the entry — the shared pass below also reads the
@@ -230,9 +285,16 @@ export declare function actionGenres(genres: readonly GenreDecl[], presets: read
230
285
  * would make every install fail permanently on a requirement nothing can ever
231
286
  * satisfy, where the real failure mode is mild and self-announcing: the row
232
287
  * seeds into a pool no installed pipeline offers, and is simply never shown.
288
+ *
289
+ * `forPipeline` is held to the same shape as a spec id with an owner and no
290
+ * version pin. When `ns` is given, one in this package's own namespace must be
291
+ * a pipeline in `declaredSpecs`. That refusal is this function's own rule, not
292
+ * a copy of `configFindings`, which records another package's spec as a
293
+ * requirement: a prompt's pipeline never is one, so another package's id is
294
+ * accepted and not added to `requires`.
233
295
  * @experimental
234
296
  */
235
- export declare function promptFindings(prompts: readonly PromptDecl[]): string[];
297
+ export declare function promptFindings(prompts: readonly PromptDecl[], ns?: string, declaredSpecs?: ReadonlyMap<string, AnnouncedSpec>): string[];
236
298
  /** Configs: node keys verified for declared specs; slugs unique per spec. @experimental */
237
299
  export declare function configFindings(configs: readonly ConfigDecl[], declaredSpecs: ReadonlyMap<string, AnnouncedSpec>, requires: Set<string>): string[];
238
300
  /**
@@ -20,15 +20,18 @@
20
20
  * announcement has.
21
21
  * @ruling D-1
22
22
  */
23
+ import { assertSpecId, parseSpecId } from './identity.js';
23
24
  import { coreWidgetIds, widgetReadsFindings } from './widgetDecls.js';
24
25
  import { presetVariableLayoutFindings } from './announce.js';
25
26
  import { COMPONENT_FRAMEWORKS } from './extension.js';
26
- import { CONVERSATION_WIDGET_ID, TURN_ORDER_CHANGED_IS_INTERNAL, sessionEvents } from './genres.js';
27
+ import { CONVERSATION_WIDGET_ID, TURN_ORDER_CHANGED_IS_INTERNAL, genreWarnings, sessionEvents } from './genres.js';
27
28
  import { drawnWidgetIds, validateSessionLayout, widgetOfInstance } from './sessionLayout.js';
28
29
  import { SAVE_MESSAGE_SPEC_ID, eventsLockFindings, getDefinition, swapFitFinding } from './descriptors.js';
29
- import { eventById, isEventId, notADeclaredEvent } from './events.js';
30
+ import { CORE_EVENTS, eventById, eventIdOf, isEventId, notADeclaredEvent } from './events.js';
30
31
  import { effectiveRegistrations, presetChangesOf, registrationFindings, } from './registrations.js';
31
- import { genreDefaultsOf } from './genres.js';
32
+ import { presetProvisoWarnings } from './provisos.js';
33
+ import { assertGenreId, genreDefaultsOf, genres as registeredGenres, getGenre } from './genres.js';
34
+ import { pluginRuleRef } from './pluginRuleRef.js';
32
35
  import { actionDocumentFindings, actionsOf, slashCollisions } from './actions.js';
33
36
  import { isTodo } from './values.js';
34
37
  import { isServableEntry } from './surfaces.js';
@@ -42,6 +45,99 @@ export const storedSwap = (c) => ({
42
45
  node: c?.node,
43
46
  definition: typeof c?.definition === 'string' ? c.definition : (c?.definition?.id ?? ''),
44
47
  });
48
+ /**
49
+ * The stored form of an option — the genre read down to its id; the option is
50
+ * the same object, so the registration door still recognises `register()`'s.
51
+ * @experimental
52
+ */
53
+ export const storedTurnOrderOption = (o) => ({
54
+ genre: typeof o?.genre === 'string' ? o.genre : (o?.genre?.id ?? ''),
55
+ option: o?.option,
56
+ });
57
+ /**
58
+ * Turn order options a package adds to genres it names. Each is a registration
59
+ * on Turn order asked, labelled, marking no default, running a pipeline the
60
+ * package ships (a model is asked only through core's turn advise, R53), in a
61
+ * genre that is not this package's own. A genre that is neither core's nor the
62
+ * package's is accepted and not required: the instance offers the option once
63
+ * that genre arrives. Reads both the authored and the stored form.
64
+ * @experimental
65
+ * @ruling TQ1, TQ2, TQ4 (owner 2026-11-19)
66
+ */
67
+ export function turnOrderOptionFindings(options, ctx) {
68
+ const errors = [];
69
+ const warnings = [];
70
+ const asked = eventIdOf(CORE_EVENTS.turnOrderAsked);
71
+ const seen = new Set();
72
+ for (const [i, raw] of options.entries()) {
73
+ const { genre, option } = storedTurnOrderOption(raw);
74
+ const at = `turnOrderOptions[${i}] ('${genre}')`;
75
+ if (!option || typeof option !== 'object' || !option.trigger || typeof option.pipeline !== 'string') {
76
+ errors.push(`${at}.option is not a registration — make it with register(coreEvents.turnOrderAsked, pipeline, { label })`);
77
+ continue;
78
+ }
79
+ let idProblem = false;
80
+ try {
81
+ assertGenreId(genre);
82
+ }
83
+ catch {
84
+ idProblem = true;
85
+ errors.push(`${at}: '${genre}' is not a genre id — name a genre by its value or its id ('core:genre/story', 'acme.rp:genre/mystery')`);
86
+ }
87
+ const own = ctx.genres?.has(genre) || (ctx.ns !== undefined && genre.startsWith(`${ctx.ns}:`));
88
+ if (!idProblem && own)
89
+ errors.push(`${at}: this package's own genre has its options in its defaults — register them with withGenreDefaults, marking one default: true`);
90
+ if (!idProblem && !own && genre.startsWith('core:')) {
91
+ const known = ctx.knownGenre
92
+ ? ctx.knownGenre(genre)
93
+ : registeredGenres().some((g) => g.id.startsWith('core:'))
94
+ ? getGenre(genre) !== undefined
95
+ : true;
96
+ if (!known)
97
+ errors.push(`${at}: core ships no genre '${genre}' — name one core ships, by value from @serene-pub/core-catalog`);
98
+ }
99
+ if (option.trigger.family !== 'event' || option.trigger.event !== asked)
100
+ errors.push(`${at}: a turn order option registers on Turn order asked ('${asked}') — register(coreEvents.turnOrderAsked, …)`);
101
+ if (option.default !== undefined)
102
+ errors.push(`${at}: a plugin never changes a genre's default — the genre's own default stays its default; drop default`);
103
+ errors.push(...i18nFindings(option.label, `${at}.option.label`, { required: true }));
104
+ const spec = ctx.pipelines.get(option.pipeline);
105
+ if (!spec)
106
+ errors.push(`${at}: runs '${option.pipeline}', which this package does not ship — add it to pipelines`);
107
+ else {
108
+ const lock = spec.input?.genre;
109
+ if (lock !== undefined && lock !== genre)
110
+ errors.push(`${at}: runs '${option.pipeline}', which is locked to genre '${lock}' — build the option for the genre it names`);
111
+ for (const n of spec.nodes) {
112
+ const def = getDefinition(`${n.definitionId}@${n.definitionVersion}`);
113
+ if (!def)
114
+ continue;
115
+ const slots = Object.values(def.slots ?? {});
116
+ const usesConnection = slots.some((s) => s?.kind === 'connection');
117
+ const refused = (usesConnection && !def.id.startsWith('core:')) ||
118
+ (def.kind === 'oracle' && usesConnection && def.id.replace(/@\d+$/, '') !== 'core:oracle/turn-advise');
119
+ if (refused)
120
+ errors.push(`${at}: the step '${n.key}' uses a connection (${def.id}) — a plugin's turn order option asks a model only through core's turn advise (core:oracle/turn-advise, the strategy modelTurnOrder pins); a plugin's code never touches connection data or calls a model (R53)` +
121
+ pluginRuleRef('connections'));
122
+ }
123
+ }
124
+ const dup = `${genre} ${option.key}`;
125
+ if (seen.has(dup))
126
+ errors.push(`${at}: the option '${option.key}' is already added to this genre — add each option once`);
127
+ seen.add(dup);
128
+ for (const f of registrationFindings([option], {
129
+ pipeline: (id) => ctx.pipelines.get(id),
130
+ external: (id) => !ctx.pipelines.has(id),
131
+ layer: at,
132
+ }))
133
+ // A default is the genre's own: an option marks none, and rule 6 refuses one that does.
134
+ if (f.law !== 'registration default')
135
+ (f.severity === 'error' ? errors : warnings).push(`${f.message} — ${f.fix}`);
136
+ if (option.trigger.family === 'event' && option.trigger.event.startsWith('core:event/'))
137
+ ctx.requires?.add(option.trigger.event);
138
+ }
139
+ return { errors, warnings };
140
+ }
45
141
  /**
46
142
  * Swaps as authored: the spec is a value and the definition a pin. A
47
143
  * string is refused here, at the entry — the shared pass below also reads the
@@ -359,6 +455,20 @@ export function actionGenres(genres, presets) {
359
455
  add(r.trigger.action, p.genre);
360
456
  return out;
361
457
  }
458
+ /** A versionless spec id with an owner: `owner:slug`, no `@`. */
459
+ function isPipelineId(id) {
460
+ if (typeof id !== 'string' || id.includes('@'))
461
+ return false;
462
+ if (parseSpecId(id).owner === undefined)
463
+ return false;
464
+ try {
465
+ assertSpecId(id);
466
+ return true;
467
+ }
468
+ catch {
469
+ return false;
470
+ }
471
+ }
362
472
  /**
363
473
  * Prompts: slugs unique per POOL, which is `(node type, slot)`.
364
474
  *
@@ -373,12 +483,26 @@ export function actionGenres(genres, presets) {
373
483
  * would make every install fail permanently on a requirement nothing can ever
374
484
  * satisfy, where the real failure mode is mild and self-announcing: the row
375
485
  * seeds into a pool no installed pipeline offers, and is simply never shown.
486
+ *
487
+ * `forPipeline` is held to the same shape as a spec id with an owner and no
488
+ * version pin. When `ns` is given, one in this package's own namespace must be
489
+ * a pipeline in `declaredSpecs`. That refusal is this function's own rule, not
490
+ * a copy of `configFindings`, which records another package's spec as a
491
+ * requirement: a prompt's pipeline never is one, so another package's id is
492
+ * accepted and not added to `requires`.
376
493
  * @experimental
377
494
  */
378
- export function promptFindings(prompts) {
495
+ export function promptFindings(prompts, ns, declaredSpecs) {
379
496
  const out = [];
380
497
  const seen = new Set();
381
498
  for (const pr of prompts) {
499
+ const fp = pr.forPipeline;
500
+ if (fp !== undefined) {
501
+ if (!isPipelineId(fp))
502
+ out.push(`prompt '${pr.slug}'.forPipeline is a pipeline id — '<owner>:spec/<name>'`);
503
+ else if (ns !== undefined && fp.startsWith(`${ns}:`) && !declaredSpecs?.has(fp))
504
+ out.push(`prompt '${pr.slug}' is filed under '${fp}', which this package does not declare — declare that pipeline, or name one that exists`);
505
+ }
382
506
  out.push(...i18nFindings(pr.label, `prompt '${pr.slug}'.label`, { required: true }));
383
507
  const pool = `${pr.nodeType}#${pr.slot}`;
384
508
  const key = `${pool}#${pr.slug}`;
@@ -826,6 +950,34 @@ export function todoHoles(configs) {
826
950
  });
827
951
  return out;
828
952
  }
953
+ /**
954
+ * 🚧 A genre with a field `showDice` whose registered pipeline reads the
955
+ * session history (`core:query/session-history`) without wiring its
956
+ * `outcomeNumbers`: that read is kept free of outcome numbers by the field's
957
+ * spelling, which core reads until 0.7. A read inside a junction branch is a
958
+ * node like any other. One line per genre and pipeline.
959
+ * @internal
960
+ */
961
+ function outcomeNumbersWarnings(genres, pipelines) {
962
+ const out = [];
963
+ const byId = new Map(pipelines.map((s) => [s.id, s]));
964
+ for (const g of genres) {
965
+ const fields = (g.shape?.fields ?? {});
966
+ if (!Object.prototype.hasOwnProperty.call(fields, 'showDice'))
967
+ continue;
968
+ const registered = [...new Set((genreDefaultsOf(g)?.registrations ?? []).map((r) => r.pipeline))];
969
+ for (const id of registered) {
970
+ const spec = byId.get(id);
971
+ if (!spec)
972
+ continue;
973
+ const unwired = spec.nodes.some((n) => n.definitionId === 'core:query/session-history' &&
974
+ !Object.prototype.hasOwnProperty.call(n.config ?? {}, 'outcomeNumbers'));
975
+ if (unwired)
976
+ out.push(`genre '${g.id}': pipeline '${id}' reads the session history without wiring outcomeNumbers, so core keeps outcome numbers out of that read's prompt by the field's spelling 'showDice' until 0.7. Wire session-history's outcomeNumbers from the field.`);
977
+ }
978
+ }
979
+ return out;
980
+ }
829
981
  /**
830
982
  * Every check above, over one package's declarations — what both authoring
831
983
  * surfaces run so that one mistake gets one sentence wherever it was written.
@@ -846,7 +998,7 @@ export function declarationFindings(p) {
846
998
  ...contributedActionFindings(pipelines, actionGenres(genres, p.presets ?? [])),
847
999
  ...exposeSwapFindings(pipelines),
848
1000
  ...swapContributionFindings(p.swaps ?? [], p.ns, declaredSpecs),
849
- ...promptFindings(p.prompts ?? []),
1001
+ ...promptFindings(p.prompts ?? [], p.ns, declaredSpecs),
850
1002
  ...configFindings(configs, declaredSpecs, requires),
851
1003
  ...eventDeclarationFindings(p.events ?? [], p.ns, pipelines, declaredGenres, requires, p.presets ?? []),
852
1004
  ...annexDeclarationFindings(p.ns, pipelines, p.annexFields),
@@ -860,12 +1012,25 @@ export function declarationFindings(p) {
860
1012
  }));
861
1013
  const presets = presetFindings(p.presets ?? [], withEvents, declaredSpecs, configs, requires);
862
1014
  const registrations = registrationDeclarationFindings(p.ns, genres, p.presets ?? [], declaredSpecs, requires);
863
- errors.push(...presets.errors, ...registrations.errors, ...surfaceFindings(p.surfaces), ...componentFindings(p.components ?? []), ...widgetComponentFindings(genres, p.components ?? []), ...packageWidgetFindings(p.widgets ?? [], p.components ?? []));
1015
+ const options = turnOrderOptionFindings(p.turnOrderOptions ?? [], {
1016
+ ns: p.ns,
1017
+ pipelines: declaredSpecs,
1018
+ genres: new Set(declaredGenres.keys()),
1019
+ requires,
1020
+ });
1021
+ errors.push(...presets.errors, ...registrations.errors, ...options.errors, ...surfaceFindings(p.surfaces), ...componentFindings(p.components ?? []), ...widgetComponentFindings(genres, p.components ?? []), ...packageWidgetFindings(p.widgets ?? [], p.components ?? []));
864
1022
  const layouts = genreLayoutFindings(genres, p.widgets, p.ns);
865
1023
  errors.push(...layouts.errors);
866
1024
  return {
867
1025
  errors,
868
- warnings: [...layouts.warnings, ...registrations.warnings],
1026
+ warnings: [
1027
+ ...layouts.warnings,
1028
+ ...registrations.warnings,
1029
+ ...options.warnings,
1030
+ ...genres.flatMap(genreWarnings),
1031
+ ...(p.presets ?? []).flatMap((preset) => presetProvisoWarnings(preset, declaredGenres.get(preset.genre) ?? getGenre(preset.genre))),
1032
+ ...outcomeNumbersWarnings(genres, pipelines),
1033
+ ],
869
1034
  coverage: { presets: presets.coverage, todos: todoHoles(configs) },
870
1035
  // Never the package's own ids: core locks on its own events and
871
1036
  // requires nothing of itself.