@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
@@ -20,7 +20,9 @@
20
20
  * lines or tokens, and a real-world `pause` of some hours between lines.
21
21
  * · `summary` — when a scene's summary runs: `onClose` (in the background
22
22
  * the moment it closes), `onRequest` (the person presses *Summarize*; the
23
- * default — the person decides when to pay), `never`.
23
+ * default — the person decides when to pay), `never`. A session running
24
+ * the *Summarize finished scenes* routine (`core:spec/scene-summaries`)
25
+ * reads `onRequest` whatever is declared or stored.
24
26
  *
25
27
  * Nothing here moves the story clock and nothing asks a model: a trigger is
26
28
  * read off stamps and rows a person or a fixed tick already wrote.
@@ -20,7 +20,9 @@
20
20
  * lines or tokens, and a real-world `pause` of some hours between lines.
21
21
  * · `summary` — when a scene's summary runs: `onClose` (in the background
22
22
  * the moment it closes), `onRequest` (the person presses *Summarize*; the
23
- * default — the person decides when to pay), `never`.
23
+ * default — the person decides when to pay), `never`. A session running
24
+ * the *Summarize finished scenes* routine (`core:spec/scene-summaries`)
25
+ * reads `onRequest` whatever is declared or stored.
24
26
  *
25
27
  * Nothing here moves the story clock and nothing asks a model: a trigger is
26
28
  * read off stamps and rows a person or a fixed tick already wrote.
@@ -261,7 +261,9 @@ export interface SessionDossierV1 {
261
261
  /**
262
262
  * 🚧 When this session's scenes are summarized (its scene settings):
263
263
  * under `never` no *Summarize* is offered — a scene divider's included.
264
- * Absent reads as `onRequest`.
264
+ * Absent reads as `onRequest`. A session running the *Summarize finished
265
+ * scenes* routine (`core:spec/scene-summaries`) reads `onRequest` whatever
266
+ * is declared or stored.
265
267
  * @ruling PROPOSAL-live-scenes §5 (2026-10-13)
266
268
  */
267
269
  sceneSummaryMode?: SceneSummaryMode;
@@ -293,11 +295,15 @@ export interface SessionDossierV1 {
293
295
  * 🚧 Whether this pub can speak a line at all (a speaking voice pair is
294
296
  * set up), read on the server as a boolean only; `reason` is the sentence
295
297
  * the speak verbs carry when it cannot. Absent reads as can speak.
298
+ * 🚧 `readAloud`: the session's Read aloud as it applies — the session's own value, else its preset's,
299
+ * else its genre's; `off` where the genre or a preset leaves out the read-aloud registration.
300
+ * Absent: read the session's stored field.
296
301
  * @experimental
297
302
  */
298
303
  speech?: {
299
304
  canSpeak: boolean;
300
305
  reason?: string;
306
+ readAloud?: 'off' | 'make' | 'play';
301
307
  };
302
308
  /**
303
309
  * 🚧 The run ids in flight for this session, off the `sessions:runStatus`
@@ -307,6 +313,34 @@ export interface SessionDossierV1 {
307
313
  * @experimental
308
314
  */
309
315
  liveRunIds?: string[];
316
+ /**
317
+ * 🚧 The names of this session's routines running now, one per run, as Routines names them —
318
+ * a run shows only once it has lasted past the host's short delay, and never while it is
319
+ * parked at a review gate. The turn line's left half says them when nothing else holds it.
320
+ * Names only, never a run id. Absent reads as none.
321
+ * @experimental
322
+ */
323
+ runningRoutineNames?: string[];
324
+ /**
325
+ * 🚧 The session's **background** runs in progress, as the turn line lists them: an action, a
326
+ * routine, a scene or session summary. A reply's run and a run bound to one line are never in
327
+ * it. Absent reads as none (an older host: `runningRoutineNames` and the scenes' summary state
328
+ * are read instead).
329
+ * @experimental
330
+ */
331
+ runsInProgress?: RunInProgressV1[];
332
+ /**
333
+ * 🚧 The sentence swipe, regenerate, delete, Back and Regenerate the last turn grey with while a
334
+ * run holds them (*Wait for ‹name› to finish, or stop it first.*). Absent when none does.
335
+ * @experimental
336
+ */
337
+ rerunWaitsFor?: string;
338
+ /**
339
+ * 🚧 The pub's step time limits are off (Admin › Diagnostics): a step may wait until someone stops it.
340
+ * Told to administrators only; the turn line shows a short marker while it is set. Absent reads as on.
341
+ * @experimental
342
+ */
343
+ stepTimeLimitsOff?: true;
310
344
  /** Admins with context debugging on may open a line's prompt. */
311
345
  debugPrompts: boolean;
312
346
  /**
@@ -357,6 +391,15 @@ export interface SessionDossierV1 {
357
391
  * for Maren Holt". Absent when nobody is waited for. @experimental
358
392
  */
359
393
  waitingFor?: string[];
394
+ /**
395
+ * 🚧 Why nothing starts by itself, told to the session's owner alone
396
+ * (the page passes it only when the server stated it for this viewer):
397
+ * `no-turn-order` — the genre registers no turn order option;
398
+ * `no-auto-advance` — the genre declares no Auto-advance;
399
+ * `no-extent` — Auto-advance is on and nothing says how far it runs.
400
+ * Absent when nothing needs saying. @experimental
401
+ */
402
+ standstill?: 'no-turn-order' | 'no-auto-advance' | 'no-extent';
360
403
  };
361
404
  /**
362
405
  * 🚧 **Back · Forward** (RF fix 5, owner ruling 2026-10-23): how many of
@@ -375,9 +418,19 @@ export interface SessionDossierV1 {
375
418
  * The page's answer (the session payload's `settledLine`, which already counts every applied
376
419
  * scene summary). Null: nothing is settled yet. Absent: a host that predates it (the same).
377
420
  * The conversation draws one quiet mark after the newest settled line it shows.
421
+ * It is `main`'s line (and that of every channel `settledThroughBy` leaves out).
378
422
  * @ruling pr-6 R-a, R-b; pass 13
379
423
  */
380
424
  settledThrough?: number | null;
425
+ /**
426
+ * 🚧 ★ Each further story channel's settle line, by channel slug (CP10, owner 2026-11-21: "a summary
427
+ * settles only its own channel's lines") — the session payload's `settledLineBy`. `settledThrough` is
428
+ * `main`'s, and the line of every channel this leaves out (a line on no story channel rides `main`).
429
+ * Absent: a genre with one story channel, or a host that predates it. The conversation draws each
430
+ * channel's mark from its own line.
431
+ * @ruling owner 2026-11-21 (CP10)
432
+ */
433
+ settledThroughBy?: Record<string, number | null>;
381
434
  /**
382
435
  * 🚧 The id of the newest loaded row the viewing user wrote; names only the viewer's own row.
383
436
  * Null: the viewer has written none of the loaded rows. Absent: a host that predates it.
@@ -403,13 +456,40 @@ export interface SessionDossierV1 {
403
456
  */
404
457
  appBackground: boolean;
405
458
  }
459
+ /**
460
+ * 🚧 One background run in progress, as the turn line lists it.
461
+ * @experimental
462
+ */
463
+ export interface RunInProgressV1 {
464
+ /** Names the run to `stop-run`; never shown. */
465
+ id: string;
466
+ kind: 'action' | 'routine' | 'summary';
467
+ /** What the person knows it by. */
468
+ name: string;
469
+ /** Status words in the viewer's language. */
470
+ status?: string;
471
+ /** Epoch ms the run began. */
472
+ since?: number;
473
+ /** The speaker whose reply caused the run. */
474
+ readsReplyOf?: string;
475
+ /** Parked at review: waiting, nothing to stop. */
476
+ parked?: true;
477
+ /** The viewer may stop it. */
478
+ mayStop: boolean;
479
+ }
406
480
  /**
407
481
  * 🚧 The Back · Forward strip's state (`SessionDossierV1.rewind`). @experimental
408
482
  * @ruling owner 2026-10-23
409
483
  */
410
484
  export interface ConversationRewindV1 {
411
- /** How many turns are rewound — "2 turns ahead". */
485
+ /** How many presses of Back are rewound — "2 turns ahead", "2 messages ahead". */
412
486
  ahead: number;
487
+ /**
488
+ * 🚧 What one press of Back takes in this session's genre (`GenreDecl.history.back`): the
489
+ * newest message, or the whole turn. The words follow it. Absent reads as `turn`.
490
+ * @experimental
491
+ */
492
+ step?: 'message' | 'turn';
413
493
  /** Why Back is refused now, or null when it may be pressed. */
414
494
  back: string | null;
415
495
  /** Why Forward is refused now, or null when it may be pressed. */
@@ -515,6 +595,19 @@ export interface ConversationComposerV1 {
515
595
  name: string;
516
596
  }>;
517
597
  personaId: number | null;
598
+ /**
599
+ * 🚧 Every seat the viewer writes as here — each player seat of theirs in
600
+ * play, with a card or card-less — by its participant reference (`seatRef`,
601
+ * the seat's `SessionCastV1.sessionPersonas[].ref`, `player-seat:<id>`) and
602
+ * the name it is shown by. When present the composer lists these, not
603
+ * `personas`. @experimental
604
+ */
605
+ seats?: Array<{
606
+ seatRef: string;
607
+ name: string;
608
+ }>;
609
+ /** 🚧 The seat of `seats` the viewer writes as; null when none. @experimental */
610
+ seatRef?: string | null;
518
611
  /**
519
612
  * 🚧 Whom the viewer writes as with no persona, phrased as the composer
520
613
  * writes it after "Write as": the viewer's own card-less player seat by
@@ -547,6 +640,13 @@ export interface ConversationComposerV1 {
547
640
  channel: string;
548
641
  label: string;
549
642
  };
643
+ /**
644
+ * 🚧 Told only to a Turn line: whether a Composer following the same
645
+ * Messages copy has **Show the Send button** on (absent: shown). At the
646
+ * compact width Send shows whatever this says (`composerSendShown`).
647
+ * @experimental
648
+ */
649
+ sendShown?: boolean;
550
650
  /**
551
651
  * 🚧 A guest who plays, in a genre of player seats (one with a player
552
652
  * label: the Lair), with no seat yet: the story's composer offers a
@@ -54,6 +54,24 @@ export interface SessionSettingsV1 {
54
54
  playerLabel?: string;
55
55
  scenario: string | null;
56
56
  lorebookId: number | null;
57
+ /**
58
+ * 🚧 Whether the lorebook that governs this session keeps a **timeline**
59
+ * (its Timeline switch): the attached lorebook's, else the session's own
60
+ * notes'. Resolved once per run, like the rest of the document.
61
+ *
62
+ * It holds for the session's life (a session keeps the lorebook it
63
+ * started with) except when that lorebook's owner flips the switch; the
64
+ * next run reads the new value.
65
+ *
66
+ * `false`: the session's story time does not move and a pipeline writes
67
+ * nothing dated to the lorebook (each outlet refuses or writes undated, as
68
+ * its contract says).
69
+ * `true`: the lorebook keeps time — but the story's present (and so
70
+ * `core:var/current-date@1`) may still be absent: a lorebook line with no
71
+ * story clock and no dated history entry has none, and a session on it
72
+ * writes its optionally dated rows undated.
73
+ */
74
+ timeline: boolean;
57
75
  tags: string[];
58
76
  channels: string[];
59
77
  /** What core:query/session-cast@1 publishes, envoys included. Not candidates: nothing here has been pooled. */
package/dist/shapes.d.ts CHANGED
@@ -331,6 +331,15 @@ export declare const S: {
331
331
  * @ruling §4.1
332
332
  */
333
333
  readonly turnOrderChanged: string;
334
+ /**
335
+ * 🚧 A **turn order asked**: the payload of
336
+ * `core:event/turn-order-asked@1` — `{ sessionId, at, asked, cause }`
337
+ * (`TurnOrderAskedPayload`, events.ts). `asked` is the id of the event
338
+ * that raised the ask, `cause` that event's cause. Its own id for the
339
+ * reason `session-change@1` has.
340
+ * @ruling programme 2.3, TC2 (owner 2026-11-18)
341
+ */
342
+ readonly turnOrderAsked: string;
334
343
  /**
335
344
  * The session's **turn order** as state: `TurnOrderV1` —
336
345
  * `{ v, order, candidates, basedOnAt, computedAt, runId, event,
package/dist/shapes.js CHANGED
@@ -367,6 +367,15 @@ export const S = {
367
367
  * @ruling §4.1
368
368
  */
369
369
  turnOrderChanged: defineShape({ id: 'core:shape/turn-order-changed@1' }),
370
+ /**
371
+ * 🚧 A **turn order asked**: the payload of
372
+ * `core:event/turn-order-asked@1` — `{ sessionId, at, asked, cause }`
373
+ * (`TurnOrderAskedPayload`, events.ts). `asked` is the id of the event
374
+ * that raised the ask, `cause` that event's cause. Its own id for the
375
+ * reason `session-change@1` has.
376
+ * @ruling programme 2.3, TC2 (owner 2026-11-18)
377
+ */
378
+ turnOrderAsked: defineShape({ id: 'core:shape/turn-order-asked@1' }),
370
379
  /**
371
380
  * The session's **turn order** as state: `TurnOrderV1` —
372
381
  * `{ v, order, candidates, basedOnAt, computedAt, runId, event,
package/dist/speech.d.ts CHANGED
@@ -111,16 +111,21 @@ export type AsteriskReading = (typeof ASTERISK_READINGS)[number];
111
111
  * @experimental
112
112
  */
113
113
  export declare const DEFAULT_QUOTE_STYLES: readonly string[];
114
- /** 🚧 One cue's place in the spoken audio. `cue` indexes the `Cue[]` spoken. @experimental */
114
+ /** 🚧 One cue's place in the spoken audio (one file of the line). `cue` indexes the `Cue[]` spoken. @experimental */
115
115
  export interface CueSpan {
116
116
  readonly cue: number;
117
117
  readonly startMs: number;
118
118
  readonly endMs: number;
119
119
  /** The cue's words, kept so the spoken line can caption the cue that is playing (additive; older records lack it). */
120
120
  readonly text?: string;
121
+ /**
122
+ * 🚧 Which entry of `SpokenMeta.assetIds` the span is in; `startMs`/`endMs` are inside that file.
123
+ * Absent: the first.
124
+ */
125
+ readonly assetIndex?: number;
121
126
  }
122
127
  /**
123
- * 🚧 **The cue map** — where each cue sits in the audio, for highlighting as it
128
+ * 🚧 **The cue map** — where each cue sits in the line's audio files, for highlighting as it
124
129
  * plays. `concatenated`: the host joined per-group audio and knows the group
125
130
  * edges; `service`: the service returned timings; `none`: nothing is known
126
131
  * (`spans` empty).
@@ -158,7 +163,7 @@ export interface SpokenAs {
158
163
  }
159
164
  /**
160
165
  * 🚧 **Spoken metadata** — the record a spoken line keeps per swipe beside its
161
- * audio part (seam S6: `metadata.spoken`). What `core:oracle/speak@1` publishes
166
+ * audio parts (seam S6: `metadata.spoken`). What `core:oracle/speak@1` publishes
162
167
  * on `meta` and `core:outlet/attach-audio@1` records.
163
168
  * @experimental
164
169
  */
@@ -171,6 +176,12 @@ export interface SpokenMeta {
171
176
  readonly template: string | null;
172
177
  /** ISO 8601, when it was spoken. */
173
178
  readonly at: string;
179
+ /**
180
+ * 🚧 The line's spoken files in play order — `files.id`, as each `core:audio` part's `data.assetId`.
181
+ * Written by `attach-audio@1` at commit. Absent (a record written before the list existed): the newest
182
+ * `core:audio` part is the line's audio. A person's voice note is never in it.
183
+ */
184
+ readonly assetIds?: readonly number[];
174
185
  }
175
186
  /**
176
187
  * 🚧 The Jinja filters a speech template may use. Their bodies are the host's
@@ -40,6 +40,58 @@ export interface StoryTime {
40
40
  /** 0–59; read only beside an hour. */
41
41
  minute?: number | null;
42
42
  }
43
+ /**
44
+ * 🚧 One part of a date value: its number, and the calendar's name for it when
45
+ * the calendar names one.
46
+ * @experimental
47
+ */
48
+ export interface StoryDatePart {
49
+ number: number;
50
+ name?: string;
51
+ }
52
+ /**
53
+ * 🚧 A story date as a layout reads it (owner 2026-11-15). The same value on
54
+ * every dated row and on the current date, so a layout prints all of them one
55
+ * way. `name` comes only from the lorebook's calendar and is absent where it
56
+ * names nothing (free-form: no names). The value carries everything needed to
57
+ * print it; a layout has no calendar.
58
+ * @experimental
59
+ */
60
+ export interface StoryDateValue {
61
+ /**
62
+ * `name`: the era-spelled year (`Year 412 AR`), only under a declared calendar.
63
+ * For a date that calendar cannot place it is the fallback spelling `Year 412`
64
+ * and the month and day carry no name: the date prints as `formatStoryTime`'s
65
+ * free-form text.
66
+ */
67
+ year: StoryDatePart;
68
+ /** `name`: the month's name. */
69
+ month: StoryDatePart | null;
70
+ /** `name`: the weekday. */
71
+ day: StoryDatePart | null;
72
+ time: {
73
+ hour: number;
74
+ minute: number;
75
+ } | null;
76
+ }
77
+ /**
78
+ * 🚧 How far a row's date is from the session's current date: row minus now.
79
+ * Magnitudes carry no names (a month name labels a position, not a length). A
80
+ * part is `null` where it was not compared or could not be known, never 0 for
81
+ * "unknown".
82
+ * @experimental
83
+ */
84
+ export interface StoryDateDelta {
85
+ sign: -1 | 0 | 1;
86
+ /** Non-negative. */
87
+ year: number;
88
+ month: number | null;
89
+ day: number | null;
90
+ time: {
91
+ hour: number;
92
+ minute: number;
93
+ } | null;
94
+ }
43
95
  /**
44
96
  * The range each part of a story time takes on EVERY rung of the calendar —
45
97
  * the free-form rule, and the one validity definition for a stored date.
@@ -155,14 +207,38 @@ export interface StoryEra {
155
207
  backwards?: boolean;
156
208
  }
157
209
  /**
158
- * One extra day in one month, every `every` years (a year divisible by it).
210
+ * One extra day in one month, every `every` years (a year divisible by it) —
211
+ * except every `skipEvery` years, except every `keepEvery` years. The real
212
+ * (Gregorian) rule is `{ every: 4, month: 2, skipEvery: 100, keepEvery: 400 }`;
213
+ * a rule with neither is every `every` years, as ever. The rule is a chain of
214
+ * levels (`storyLeapLevels`), at most `STORY_LEAP_MAX_LEVELS`: the last level
215
+ * that divides a year decides — an odd-numbered level adds the day, an
216
+ * even-numbered one takes it away.
159
217
  * @experimental
160
218
  */
161
219
  export interface StoryLeapRule {
162
220
  every: number;
163
221
  /** 1-based. */
164
222
  month: number;
223
+ /** 🚧 A whole multiple of `every`: years divisible by it are not leap years … */
224
+ skipEvery?: number;
225
+ /** 🚧 … unless also divisible by this, a whole multiple of `skipEvery` (needs it). */
226
+ keepEvery?: number;
227
+ /** 🚧 The levels after `keepEvery`, each a whole multiple of the one before (needs `keepEvery`). */
228
+ more?: number[];
165
229
  }
230
+ /**
231
+ * 🚧 The most levels a leap rule may chain (`every`, `skipEvery`, `keepEvery`
232
+ * and `more` together).
233
+ * @experimental
234
+ */
235
+ export declare const STORY_LEAP_MAX_LEVELS = 8;
236
+ /**
237
+ * 🚧 A leap rule's levels in order — `[every, skipEvery?, keepEvery?, ...more]`,
238
+ * stopping at the first absent (falsy) level.
239
+ * @experimental
240
+ */
241
+ export declare function storyLeapLevels(rule: StoryLeapRule): number[];
166
242
  /**
167
243
  * A book's declared calendar — the rung above free-form.
168
244
  *
package/dist/storyTime.js CHANGED
@@ -177,6 +177,34 @@ export function formatStoryTime(time, calendar) {
177
177
  out += `, Day ${time.day}`;
178
178
  return out + clock;
179
179
  }
180
+ /**
181
+ * 🚧 The most levels a leap rule may chain (`every`, `skipEvery`, `keepEvery`
182
+ * and `more` together).
183
+ * @experimental
184
+ */
185
+ export const STORY_LEAP_MAX_LEVELS = 8;
186
+ /**
187
+ * 🚧 A leap rule's levels in order — `[every, skipEvery?, keepEvery?, ...more]`,
188
+ * stopping at the first absent (falsy) level.
189
+ * @experimental
190
+ */
191
+ export function storyLeapLevels(rule) {
192
+ const out = [rule.every];
193
+ if (!rule.skipEvery)
194
+ return out;
195
+ out.push(rule.skipEvery);
196
+ if (!rule.keepEvery)
197
+ return out;
198
+ out.push(rule.keepEvery);
199
+ if (Array.isArray(rule.more)) {
200
+ for (const n of rule.more) {
201
+ if (!n)
202
+ break;
203
+ out.push(n);
204
+ }
205
+ }
206
+ return out;
207
+ }
180
208
  const isInt = (n) => typeof n === 'number' && Number.isInteger(n);
181
209
  const floorDiv = (a, b) => Math.floor(a / b);
182
210
  const mod = (a, b) => ((a % b) + b) % b;
@@ -223,6 +251,38 @@ export function storyCalendarProblems(calendar, opts) {
223
251
  out.push('A leap rule needs a whole number of years, 1 or more.');
224
252
  if (!isInt(c.leap.month) || c.leap.month < 1 || c.leap.month > months)
225
253
  out.push('A leap rule must name one of the months.');
254
+ const { every, skipEvery, keepEvery } = c.leap;
255
+ if (skipEvery !== undefined && (!isInt(skipEvery) || skipEvery < 1 || (isInt(every) && every >= 1 && skipEvery % every !== 0)))
256
+ out.push('A leap rule’s skipped years must be a whole number, a multiple of its leap years.');
257
+ if (keepEvery !== undefined) {
258
+ if (skipEvery === undefined)
259
+ out.push('A leap rule can keep years only when it skips some.');
260
+ else if (!isInt(keepEvery) || keepEvery < 1 || (isInt(skipEvery) && skipEvery >= 1 && keepEvery % skipEvery !== 0))
261
+ out.push('A leap rule’s kept years must be a whole number, a multiple of its skipped years.');
262
+ }
263
+ const more = c.leap.more;
264
+ if (more !== undefined) {
265
+ const further = 'Each further level of a leap rule must be a whole number, a multiple of the level before.';
266
+ if (!Array.isArray(more))
267
+ out.push(further);
268
+ else {
269
+ if (keepEvery === undefined)
270
+ out.push('A leap rule can add more levels only after its kept years.');
271
+ else {
272
+ let before = keepEvery;
273
+ let bad = false;
274
+ for (const n of more) {
275
+ if (!isInt(n) || n < 1 || !isInt(before) || before < 1 || n % before !== 0)
276
+ bad = true;
277
+ before = n;
278
+ }
279
+ if (bad)
280
+ out.push(further);
281
+ }
282
+ if (3 + more.length > STORY_LEAP_MAX_LEVELS)
283
+ out.push(`A leap rule has at most ${STORY_LEAP_MAX_LEVELS} levels.`);
284
+ }
285
+ }
226
286
  }
227
287
  if (c.eras !== undefined) {
228
288
  if (!Array.isArray(c.eras))
@@ -301,7 +361,13 @@ export function parseStoryCalendar(value) {
301
361
  if (c.yearLabel !== undefined)
302
362
  out.yearLabel = c.yearLabel;
303
363
  if (c.leap != null)
304
- out.leap = { every: c.leap.every, month: c.leap.month };
364
+ out.leap = {
365
+ every: c.leap.every,
366
+ month: c.leap.month,
367
+ ...(c.leap.skipEvery !== undefined ? { skipEvery: c.leap.skipEvery } : {}),
368
+ ...(c.leap.keepEvery !== undefined ? { keepEvery: c.leap.keepEvery } : {}),
369
+ ...(c.leap.more !== undefined && c.leap.more.length > 0 ? { more: [...c.leap.more] } : {}),
370
+ };
305
371
  if (c.eras !== undefined)
306
372
  out.eras = c.eras.map((e) => ({ name: e.name.trim(), start: e.start, ...(e.backwards ? { backwards: true } : {}) }));
307
373
  if (c.periods !== undefined)
@@ -310,7 +376,22 @@ export function parseStoryCalendar(value) {
310
376
  out.seasons = { days: c.seasons.days, labels: [...c.seasons.labels] };
311
377
  return out;
312
378
  }
313
- const isLeapYear = (year, calendar) => !!calendar.leap && mod(year, calendar.leap.every) === 0;
379
+ const isLeapYear = (year, calendar) => {
380
+ const leap = calendar.leap;
381
+ if (!leap)
382
+ return false;
383
+ let count = 0;
384
+ for (const level of storyLeapLevels(leap)) {
385
+ if (mod(year, level) !== 0)
386
+ break;
387
+ count++;
388
+ }
389
+ return count % 2 === 1;
390
+ };
391
+ /** Leap days in the years before `year + 1` (years `…, year - 1, year`), counted from year 0. */
392
+ const leapDaysThrough = (year, leap) => leap
393
+ ? storyLeapLevels(leap).reduce((n, level, i) => n + (i % 2 === 0 ? 1 : -1) * floorDiv(year, level), 0)
394
+ : 0;
314
395
  /**
315
396
  * How many days a month has in a given year — its length, plus the leap day
316
397
  * when the leap rule names it and the year is a leap year.
@@ -373,7 +454,7 @@ export function storyDayIndex(time, calendar) {
373
454
  return null;
374
455
  const yearDays = calendar.months.reduce((n, m) => n + m.days, 0);
375
456
  const y = time.year - 1;
376
- let days = y * yearDays + (calendar.leap ? floorDiv(y, calendar.leap.every) : 0);
457
+ let days = y * yearDays + leapDaysThrough(y, calendar.leap);
377
458
  for (let m = 1; m < time.month; m++)
378
459
  days += storyDaysInMonth(time.year, m, calendar);
379
460
  return days + time.day - 1;
@@ -448,7 +529,9 @@ export function nextStoryTime(from, calendar) {
448
529
  */
449
530
  export function storyTimeOfDayIndex(index, calendar) {
450
531
  const yearDays = calendar.months.reduce((n, m) => n + m.days, 0);
451
- const average = yearDays + (calendar.leap ? 1 / calendar.leap.every : 0);
532
+ const leap = calendar.leap;
533
+ const average = yearDays +
534
+ (leap ? storyLeapLevels(leap).reduce((n, level, i) => n + (i % 2 === 0 ? 1 : -1) / level, 0) : 0);
452
535
  const startOf = (year) => storyDayIndex({ year, month: 1, day: 1 }, calendar);
453
536
  // An estimate by the average year, then corrected: at most a step or two.
454
537
  let year = Math.floor(index / average) + 1;
@@ -595,6 +678,30 @@ export const STORY_CALENDAR_PRESETS = [
595
678
  leap: { every: 4, month: 2 },
596
679
  },
597
680
  },
681
+ {
682
+ id: 'real-calendar',
683
+ name: 'The real calendar',
684
+ calendar: {
685
+ months: [
686
+ { name: 'January', days: 31 },
687
+ { name: 'February', days: 28 },
688
+ { name: 'March', days: 31 },
689
+ { name: 'April', days: 30 },
690
+ { name: 'May', days: 31 },
691
+ { name: 'June', days: 30 },
692
+ { name: 'July', days: 31 },
693
+ { name: 'August', days: 31 },
694
+ { name: 'September', days: 30 },
695
+ { name: 'October', days: 31 },
696
+ { name: 'November', days: 30 },
697
+ { name: 'December', days: 31 },
698
+ ],
699
+ weekdays: WEEK,
700
+ firstWeekday: 0,
701
+ yearLabel: '',
702
+ leap: { every: 4, month: 2, skipEvery: 100, keepEvery: 400 },
703
+ },
704
+ },
598
705
  {
599
706
  id: 'thirty-day-months',
600
707
  name: 'Twelve months of thirty days',
@@ -172,7 +172,20 @@ export type HostFrameMessage = {
172
172
  } | {
173
173
  t: 'messages';
174
174
  messages: MessageV1[];
175
- } | {
175
+ }
176
+ /**
177
+ * Replace the held row with this `id` — in `messages` and in any `channel`
178
+ * list holding it; an id not held is ignored. Adds and removes still arrive
179
+ * as full `messages` / `channel` lists. A host sends it only to a peer that
180
+ * takes it: a component's wire (core's `WidgetWireOptions.peerTakesOneMessage`),
181
+ * or a frame that declared `takes: ['message']` on its `ready`. It comes when
182
+ * exactly one held row changed, that row is still generating, and ids, order
183
+ * and lanes are unchanged. Everything else arrives as full `messages` /
184
+ * `channel` lists: the row's first appearance (a row joining the log is an
185
+ * add), every add / remove / reorder / lane move, and the settled row (no
186
+ * longer generating). It only ever replaces a row the receiver already holds.
187
+ */
188
+ | {
176
189
  t: 'message';
177
190
  message: MessageV1;
178
191
  } | {
@@ -367,6 +380,27 @@ export type HostFrameMessage = {
367
380
  */
368
381
  export type FrameHostMessage = {
369
382
  t: 'ready';
383
+ /**
384
+ * 🚧 The host messages this frame takes beyond the ones every frame
385
+ * gets. One entry today, `'message'`: declared, a streamed update to a
386
+ * row the frame already holds arrives as `{ t: 'message' }` (that one
387
+ * row, to replace by id) instead of the whole list again.
388
+ *
389
+ * Not a grant: it asks for nothing the frame is not already sent — the
390
+ * row is the same row the lists carry, under the same lane scoping. Not
391
+ * a read: it says nothing about which sections the frame wants.
392
+ *
393
+ * Absent, empty, or without `'message'`: full lists, always, as before.
394
+ * Read on every `ready`: a replayed `ready` without it turns it off, and
395
+ * a new port starts without it. A frame may ignore `message` only by not
396
+ * declaring it. A host that predates this field ignores it and keeps
397
+ * posting full lists, so a declaring frame still handles `messages` and
398
+ * `channel`.
399
+ *
400
+ * @experimental
401
+ * @ruling ★P14 (2026-11-13), ★M-1 (2026-11-14)
402
+ */
403
+ takes?: 'message'[];
370
404
  }
371
405
  /**
372
406
  * ⏳ Fire a function by name.
@@ -485,6 +519,9 @@ export type FrameHostMessage = {
485
519
  * that needs an answer must therefore tolerate not getting one, just as it
486
520
  * ignores a host message it has never heard of.
487
521
  *
522
+ * `ready`'s optional `takes` is part of 2; it needs no new version, because a
523
+ * host that does not read it keeps the old behaviour (full lists).
524
+ *
488
525
  * A v1 frame keeps working unchanged: it never sends the frame → host
489
526
  * additions, and it must already ignore host messages it does not recognise. A
490
527
  * v2 host must still accept `init` from a v1 frame — the version says what the
package/dist/surfaces.js CHANGED
@@ -125,6 +125,9 @@ export function parsePluginWidgetId(id) {
125
125
  * that needs an answer must therefore tolerate not getting one, just as it
126
126
  * ignores a host message it has never heard of.
127
127
  *
128
+ * `ready`'s optional `takes` is part of 2; it needs no new version, because a
129
+ * host that does not read it keeps the old behaviour (full lists).
130
+ *
128
131
  * A v1 frame keeps working unchanged: it never sends the frame → host
129
132
  * additions, and it must already ignore host messages it does not recognise. A
130
133
  * v2 host must still accept `init` from a v1 frame — the version says what the
@@ -178,9 +178,13 @@ export interface TemplateFinding {
178
178
  * and a quoted layout reference (`{{{layout characters "core/json@1"}}}`).
179
179
  * - 🚧 `unknown-layout` — a layout reference that is malformed, or that the
180
180
  * key's variable does not offer.
181
+ * - 🚧 `shape-mismatch` — a template that treats a typed value as a shape it
182
+ * is not (an object printed bare, `each` over a non-list, `@key` over a
183
+ * list, `formatDate` of a non-date) in a variable layout. Always a warning,
184
+ * never refused.
181
185
  * @experimental
182
186
  */
183
- export type TemplateFindingKind = 'syntax' | 'unknown-name' | 'unknown-path' | 'unknown-helper' | 'layout-argument' | 'unknown-layout';
187
+ export type TemplateFindingKind = 'syntax' | 'unknown-name' | 'unknown-path' | 'unknown-helper' | 'layout-argument' | 'unknown-layout' | 'shape-mismatch';
184
188
  /**
185
189
  * What a host's engines register, as names — the checker's input
186
190
  * (`@serene-pub/sdk/template-check`). Declared here, on the barrel, so a
@@ -217,6 +221,14 @@ export interface TemplateCheckOptions {
217
221
  * chooses per variable).
218
222
  */
219
223
  variableLayoutOffers?: Readonly<Record<string, readonly VariableLayoutOffer[]>>;
224
+ /**
225
+ * 🚧 The source is a variable layout, checked against its variable's own
226
+ * scope; only then are `shape-mismatch` findings reported (a context
227
+ * template receives laid-out keys as text, so the declared shapes do not
228
+ * describe what it prints).
229
+ * @experimental
230
+ */
231
+ variableLayout?: boolean;
220
232
  }
221
233
  /** @experimental */
222
234
  export interface TemplateSourceCheck {