@serene-pub/sdk 0.6.0-pr-1

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 (187) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +17 -0
  3. package/README.md +368 -0
  4. package/dist/actions.d.ts +572 -0
  5. package/dist/actions.js +829 -0
  6. package/dist/annexFields.d.ts +234 -0
  7. package/dist/annexFields.js +413 -0
  8. package/dist/announce.d.ts +464 -0
  9. package/dist/announce.js +426 -0
  10. package/dist/attributes.d.ts +670 -0
  11. package/dist/attributes.js +904 -0
  12. package/dist/bands.d.ts +125 -0
  13. package/dist/bands.js +256 -0
  14. package/dist/builder.d.ts +683 -0
  15. package/dist/builder.js +677 -0
  16. package/dist/candidates.d.ts +109 -0
  17. package/dist/candidates.js +118 -0
  18. package/dist/capabilities.d.ts +744 -0
  19. package/dist/capabilities.js +679 -0
  20. package/dist/channels.d.ts +106 -0
  21. package/dist/channels.js +129 -0
  22. package/dist/clauses.d.ts +40 -0
  23. package/dist/clauses.js +43 -0
  24. package/dist/component.d.ts +33 -0
  25. package/dist/component.js +27 -0
  26. package/dist/componentBuild.d.ts +48 -0
  27. package/dist/componentBuild.js +84 -0
  28. package/dist/componentClient.d.ts +100 -0
  29. package/dist/componentClient.js +13 -0
  30. package/dist/componentImports.d.ts +51 -0
  31. package/dist/componentImports.js +106 -0
  32. package/dist/componentModule.d.ts +8 -0
  33. package/dist/componentModule.js +270 -0
  34. package/dist/componentWire.d.ts +130 -0
  35. package/dist/componentWire.js +280 -0
  36. package/dist/config.d.ts +295 -0
  37. package/dist/config.js +231 -0
  38. package/dist/connections.d.ts +89 -0
  39. package/dist/connections.js +131 -0
  40. package/dist/declarations.d.ts +290 -0
  41. package/dist/declarations.js +794 -0
  42. package/dist/descriptors.d.ts +1774 -0
  43. package/dist/descriptors.js +1329 -0
  44. package/dist/dev.d.ts +136 -0
  45. package/dist/dev.js +161 -0
  46. package/dist/document.d.ts +202 -0
  47. package/dist/document.js +312 -0
  48. package/dist/engines.d.ts +117 -0
  49. package/dist/engines.js +203 -0
  50. package/dist/eventMapLaws.d.ts +63 -0
  51. package/dist/eventMapLaws.js +128 -0
  52. package/dist/events.d.ts +554 -0
  53. package/dist/events.js +633 -0
  54. package/dist/executor.d.ts +771 -0
  55. package/dist/executor.js +1829 -0
  56. package/dist/extension.d.ts +448 -0
  57. package/dist/extension.js +315 -0
  58. package/dist/facets.d.ts +53 -0
  59. package/dist/facets.js +60 -0
  60. package/dist/foldedSections.d.ts +74 -0
  61. package/dist/foldedSections.js +161 -0
  62. package/dist/genres.d.ts +507 -0
  63. package/dist/genres.js +633 -0
  64. package/dist/guardedConnection.d.ts +138 -0
  65. package/dist/guardedConnection.js +341 -0
  66. package/dist/handlebarsReach.d.ts +122 -0
  67. package/dist/handlebarsReach.js +222 -0
  68. package/dist/hash.d.ts +146 -0
  69. package/dist/hash.js +166 -0
  70. package/dist/hookGrants.d.ts +47 -0
  71. package/dist/hookGrants.js +68 -0
  72. package/dist/hooks.d.ts +290 -0
  73. package/dist/hooks.js +113 -0
  74. package/dist/hostElements.d.ts +447 -0
  75. package/dist/hostElements.js +702 -0
  76. package/dist/i18n.d.ts +94 -0
  77. package/dist/i18n.js +123 -0
  78. package/dist/identity.d.ts +93 -0
  79. package/dist/identity.js +135 -0
  80. package/dist/index.d.ts +85 -0
  81. package/dist/index.js +176 -0
  82. package/dist/layout.d.ts +194 -0
  83. package/dist/layout.js +40 -0
  84. package/dist/media.d.ts +202 -0
  85. package/dist/media.js +70 -0
  86. package/dist/messageBlocks.d.ts +487 -0
  87. package/dist/messageBlocks.js +683 -0
  88. package/dist/migration.d.ts +128 -0
  89. package/dist/migration.js +261 -0
  90. package/dist/names.d.ts +78 -0
  91. package/dist/names.js +136 -0
  92. package/dist/nodeInput.d.ts +399 -0
  93. package/dist/nodeInput.js +178 -0
  94. package/dist/participants.d.ts +291 -0
  95. package/dist/participants.js +252 -0
  96. package/dist/personGate.d.ts +62 -0
  97. package/dist/personGate.js +77 -0
  98. package/dist/pick.d.ts +84 -0
  99. package/dist/pick.js +103 -0
  100. package/dist/pluginHarness.d.ts +235 -0
  101. package/dist/pluginHarness.js +558 -0
  102. package/dist/pluginPermissions.d.ts +25 -0
  103. package/dist/pluginPermissions.js +97 -0
  104. package/dist/pluginRuleRef.d.ts +13 -0
  105. package/dist/pluginRuleRef.js +10 -0
  106. package/dist/predicates.d.ts +182 -0
  107. package/dist/predicates.js +249 -0
  108. package/dist/preview.d.ts +120 -0
  109. package/dist/preview.js +82 -0
  110. package/dist/promptBlocks.d.ts +130 -0
  111. package/dist/promptBlocks.js +197 -0
  112. package/dist/rankingDecisions.d.ts +60 -0
  113. package/dist/rankingDecisions.js +48 -0
  114. package/dist/receipt.d.ts +313 -0
  115. package/dist/receipt.js +60 -0
  116. package/dist/receiverRules.d.ts +24 -0
  117. package/dist/receiverRules.js +94 -0
  118. package/dist/refs.d.ts +117 -0
  119. package/dist/refs.js +137 -0
  120. package/dist/registry.d.ts +230 -0
  121. package/dist/registry.js +273 -0
  122. package/dist/review.d.ts +108 -0
  123. package/dist/review.js +97 -0
  124. package/dist/sampling.d.ts +152 -0
  125. package/dist/sampling.js +712 -0
  126. package/dist/scope.d.ts +65 -0
  127. package/dist/scope.js +128 -0
  128. package/dist/scripts.d.ts +243 -0
  129. package/dist/scripts.js +326 -0
  130. package/dist/sessionLayout.d.ts +339 -0
  131. package/dist/sessionLayout.js +503 -0
  132. package/dist/sessionSettings.d.ts +70 -0
  133. package/dist/sessionSettings.js +2 -0
  134. package/dist/settings.d.ts +501 -0
  135. package/dist/settings.js +604 -0
  136. package/dist/settingsSlot.d.ts +108 -0
  137. package/dist/settingsSlot.js +166 -0
  138. package/dist/shapes.d.ts +373 -0
  139. package/dist/shapes.js +408 -0
  140. package/dist/sheets.d.ts +165 -0
  141. package/dist/sheets.js +251 -0
  142. package/dist/statShapes.d.ts +96 -0
  143. package/dist/statShapes.js +112 -0
  144. package/dist/status.d.ts +103 -0
  145. package/dist/status.js +125 -0
  146. package/dist/storage.d.ts +145 -0
  147. package/dist/storage.js +33 -0
  148. package/dist/storyTime.d.ts +308 -0
  149. package/dist/storyTime.js +560 -0
  150. package/dist/surfaces.d.ts +501 -0
  151. package/dist/surfaces.js +292 -0
  152. package/dist/template.d.ts +312 -0
  153. package/dist/template.js +554 -0
  154. package/dist/templateCheck.d.ts +60 -0
  155. package/dist/templateCheck.js +516 -0
  156. package/dist/templateFit.d.ts +157 -0
  157. package/dist/templateFit.js +349 -0
  158. package/dist/templateIds.d.ts +138 -0
  159. package/dist/templateIds.js +144 -0
  160. package/dist/templateScopeAt.d.ts +131 -0
  161. package/dist/templateScopeAt.js +354 -0
  162. package/dist/testing.d.ts +177 -0
  163. package/dist/testing.js +383 -0
  164. package/dist/tokenizers.d.ts +113 -0
  165. package/dist/tokenizers.js +184 -0
  166. package/dist/turnLock.d.ts +96 -0
  167. package/dist/turnLock.js +79 -0
  168. package/dist/turnOrder.d.ts +143 -0
  169. package/dist/turnOrder.js +128 -0
  170. package/dist/validate.d.ts +74 -0
  171. package/dist/validate.js +1399 -0
  172. package/dist/values.d.ts +212 -0
  173. package/dist/values.js +390 -0
  174. package/dist/variables.d.ts +493 -0
  175. package/dist/variables.js +662 -0
  176. package/dist/verdicts.d.ts +275 -0
  177. package/dist/verdicts.js +348 -0
  178. package/dist/widgetDecls.d.ts +88 -0
  179. package/dist/widgetDecls.js +119 -0
  180. package/dist/widgets.d.ts +1527 -0
  181. package/dist/widgets.js +208 -0
  182. package/dist/wire.d.ts +126 -0
  183. package/dist/wire.js +140 -0
  184. package/dist/worldinfo.d.ts +150 -0
  185. package/dist/worldinfo.js +212 -0
  186. package/host-elements.d.ts +914 -0
  187. package/package.json +67 -0
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The turn lock — whether the numbers written for one speaker are still open
3
+ * to be changed.
4
+ *
5
+ * A change to a character's state anchors to **that character's latest
6
+ * message** and stays open until that character speaks again, whatever anybody
7
+ * else says in between. Two characters trading lines therefore each keep their
8
+ * own reply editable: the older one is not sealed by the newer speaker, because
9
+ * it was not that speaker's turn that produced it. The world's numbers follow
10
+ * the same rule against the newest message in the session, whoever wrote it —
11
+ * the world moves on every turn, which is exactly the difference between the
12
+ * two owners.
13
+ *
14
+ * Before a character's first reply there is nothing to anchor to: the open
15
+ * anchor is `null`, and `null` is open. That is the case a cast member who has
16
+ * just joined is in, and it has to be writable or their opening state could
17
+ * never be set at all. Personas are characters, so the player's own turns lock
18
+ * on exactly these terms too.
19
+ *
20
+ * ## Why this lives in the SDK
21
+ *
22
+ * Three parties ask this question and they must not answer it differently: the
23
+ * host's write gate, which refuses a write to a sealed anchor; a plugin
24
+ * proposing a change, which has to know whether the proposal can land; and the
25
+ * client, which draws each ledger line as editable or sealed. Two of the three
26
+ * are outside core, so the rule cannot live in core's write path — a client
27
+ * that drew an editable ledger the gate then refused would be a bug neither
28
+ * side could see alone, and a plugin that guessed would be a bug nobody could
29
+ * see at all. It is a pure function over facts all three already hold, so there
30
+ * is nothing to share here but the rule itself.
31
+ *
32
+ * ⚠ Only session-layer writes are turn-locked. A lorebook-layer edit is
33
+ * authoring rather than play, and a capture stays exactly as it was written.
34
+ */
35
+ /**
36
+ * One message, reduced to the two facts the lock reads.
37
+ *
38
+ * `speakerId` is whoever spoke — the character id, or the persona id, which is
39
+ * the same table. `null` is a message with no speaker at all.
40
+ * @experimental
41
+ */
42
+ export interface TurnMessage {
43
+ id: number;
44
+ speakerId: number | null;
45
+ /**
46
+ * The **turn** the message belongs to — the run that created it — when
47
+ * the asker knows (lair pass R8, 2026-09-28). Optional: absent, the
48
+ * world's rule is the newest message alone, exactly as before. Present,
49
+ * every row of the newest turn is open for the world (see
50
+ * `isAnchorOpen`). A person's own line belongs to no run, so it carries
51
+ * none.
52
+ */
53
+ turn?: string | number | null;
54
+ }
55
+ /**
56
+ * Whose ledger is being asked about: one cast member, or the world.
57
+ *
58
+ * `session` carries an id this file never reads — the session's own. It is
59
+ * here because it is the shape the host already stores an owner as, and a
60
+ * second, world-only shape would be one more place the two could disagree
61
+ * about what a row belongs to.
62
+ * @experimental
63
+ */
64
+ export interface TurnOwner {
65
+ kind: 'session' | 'session_cast';
66
+ id: number;
67
+ }
68
+ /**
69
+ * The anchor still open for this owner, or `null` when there is none.
70
+ *
71
+ * ⚠ `messages` is in **session order** — oldest first, as a query ordered by id
72
+ * returns them. The newest is the last element, and the caller owns that
73
+ * guarantee: this reads positions rather than comparing ids, so a reversed list
74
+ * answers confidently and wrongly.
75
+ * @experimental
76
+ */
77
+ export declare function openAnchorFor(messages: readonly TurnMessage[], owner: TurnOwner): number | null;
78
+ /**
79
+ * Whether a change filed at `anchorId` may still be changed.
80
+ *
81
+ * `null === null` is deliberate, and it is the whole first-reply case: a
82
+ * character who has not spoken has no anchor, and a change filed against no
83
+ * anchor is open until they do.
84
+ *
85
+ * **The world's newest turn, whole** (lair pass R8, 2026-09-28): a turn may
86
+ * write several rows — the Lair's Castellan posts its beats in the Sanctum
87
+ * and then the party speak — and the world's changes are anchored to the
88
+ * row that planned them, not to whichever delver happened to speak last. So
89
+ * for the world, an anchor is open when it is the newest message OR it
90
+ * belongs to the same turn (`TurnMessage.turn`) as the newest message.
91
+ * Nothing written after that turn by anybody else is sealed any later than
92
+ * before; a caller that supplies no `turn` gets the newest-message rule.
93
+ * @experimental
94
+ */
95
+ export declare function isAnchorOpen(messages: readonly TurnMessage[], owner: TurnOwner, anchorId: number | null): boolean;
96
+ //# sourceMappingURL=turnLock.d.ts.map
@@ -0,0 +1,79 @@
1
+ /**
2
+ * The turn lock — whether the numbers written for one speaker are still open
3
+ * to be changed.
4
+ *
5
+ * A change to a character's state anchors to **that character's latest
6
+ * message** and stays open until that character speaks again, whatever anybody
7
+ * else says in between. Two characters trading lines therefore each keep their
8
+ * own reply editable: the older one is not sealed by the newer speaker, because
9
+ * it was not that speaker's turn that produced it. The world's numbers follow
10
+ * the same rule against the newest message in the session, whoever wrote it —
11
+ * the world moves on every turn, which is exactly the difference between the
12
+ * two owners.
13
+ *
14
+ * Before a character's first reply there is nothing to anchor to: the open
15
+ * anchor is `null`, and `null` is open. That is the case a cast member who has
16
+ * just joined is in, and it has to be writable or their opening state could
17
+ * never be set at all. Personas are characters, so the player's own turns lock
18
+ * on exactly these terms too.
19
+ *
20
+ * ## Why this lives in the SDK
21
+ *
22
+ * Three parties ask this question and they must not answer it differently: the
23
+ * host's write gate, which refuses a write to a sealed anchor; a plugin
24
+ * proposing a change, which has to know whether the proposal can land; and the
25
+ * client, which draws each ledger line as editable or sealed. Two of the three
26
+ * are outside core, so the rule cannot live in core's write path — a client
27
+ * that drew an editable ledger the gate then refused would be a bug neither
28
+ * side could see alone, and a plugin that guessed would be a bug nobody could
29
+ * see at all. It is a pure function over facts all three already hold, so there
30
+ * is nothing to share here but the rule itself.
31
+ *
32
+ * ⚠ Only session-layer writes are turn-locked. A lorebook-layer edit is
33
+ * authoring rather than play, and a capture stays exactly as it was written.
34
+ */
35
+ /**
36
+ * The anchor still open for this owner, or `null` when there is none.
37
+ *
38
+ * ⚠ `messages` is in **session order** — oldest first, as a query ordered by id
39
+ * returns them. The newest is the last element, and the caller owns that
40
+ * guarantee: this reads positions rather than comparing ids, so a reversed list
41
+ * answers confidently and wrongly.
42
+ * @experimental
43
+ */
44
+ export function openAnchorFor(messages, owner) {
45
+ if (owner.kind === 'session')
46
+ return messages.length ? messages[messages.length - 1].id : null;
47
+ for (let i = messages.length - 1; i >= 0; i--)
48
+ if (messages[i].speakerId === owner.id)
49
+ return messages[i].id;
50
+ return null;
51
+ }
52
+ /**
53
+ * Whether a change filed at `anchorId` may still be changed.
54
+ *
55
+ * `null === null` is deliberate, and it is the whole first-reply case: a
56
+ * character who has not spoken has no anchor, and a change filed against no
57
+ * anchor is open until they do.
58
+ *
59
+ * **The world's newest turn, whole** (lair pass R8, 2026-09-28): a turn may
60
+ * write several rows — the Lair's Castellan posts its beats in the Sanctum
61
+ * and then the party speak — and the world's changes are anchored to the
62
+ * row that planned them, not to whichever delver happened to speak last. So
63
+ * for the world, an anchor is open when it is the newest message OR it
64
+ * belongs to the same turn (`TurnMessage.turn`) as the newest message.
65
+ * Nothing written after that turn by anybody else is sealed any later than
66
+ * before; a caller that supplies no `turn` gets the newest-message rule.
67
+ * @experimental
68
+ */
69
+ export function isAnchorOpen(messages, owner, anchorId) {
70
+ if (anchorId === openAnchorFor(messages, owner))
71
+ return true;
72
+ if (owner.kind !== 'session' || anchorId === null || !messages.length)
73
+ return false;
74
+ const newest = messages[messages.length - 1].turn;
75
+ if (newest === undefined || newest === null)
76
+ return false;
77
+ return messages.some((m) => m.id === anchorId && m.turn === newest);
78
+ }
79
+ //# sourceMappingURL=turnLock.js.map
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Turn order as state (PLAN-turn-order §4.2, ruled 2026-09-21).
3
+ *
4
+ * The session's ordered list of prepared turns is a **document**, not a
5
+ * decision a run makes on the way to a reply. It lives at
6
+ * `sessions.metadata.turnOrder`, is written by `core:outlet/set-turn-order@1`
7
+ * and nothing else, and survives refresh and reboot (R5). A page renders it;
8
+ * a socket fires an entry from it; the recompute is a pipeline
9
+ * (`core:spec/<genre>-turn-order`, one per genre) that answers a session event and reads only.
10
+ *
11
+ * Three shapes, each open at the end so an orderer or a plugin may carry more:
12
+ *
13
+ * · a **candidate** — a participant the pool admitted this run;
14
+ * · an **entry** — one prepared turn: who, where, what to fire, how decided;
15
+ * · the **order** — the entries, the candidates they were chosen from, and
16
+ * what the recompute answered.
17
+ *
18
+ * ⚠ `TurnCandidateV1.ref` is a `ParticipantRef`, whose grammar today admits
19
+ * `character:` · `envoy:` · `user:` and the roles — not `persona:`. A
20
+ * persona is a character row flagged `is_persona` (NOMENCLATURE §23), so its
21
+ * reference is `character:<id>` and `kind: 'persona'` is what says which;
22
+ * whether the grammar grows a `persona:` form is an open question the plan
23
+ * records (§8), not one this file answers.
24
+ */
25
+ import type { ParticipantRef } from './participants.js';
26
+ /** @experimental */
27
+ export interface TurnCandidateV1 {
28
+ /** character:11 | persona:7 | envoy:mascot — see the file note on `persona:`. */
29
+ ref: ParticipantRef;
30
+ kind: 'character' | 'persona' | 'envoy' | (string & {});
31
+ name: string;
32
+ nickname?: string;
33
+ position: number;
34
+ /** Characters and personas: whose library row this is. */
35
+ ownerUserId?: number;
36
+ /** Open: orderers and plugins may add keys; core passes them through. */
37
+ [k: string]: unknown;
38
+ }
39
+ /** @experimental */
40
+ export interface TurnEntryV1 {
41
+ /** Who speaks. null = the pipeline's own voice (a narrator turn). */
42
+ ref: ParticipantRef | null;
43
+ /** Where: canonical channel string (`main`, `phone:3`). Absent = the pipeline's default. */
44
+ channel?: string;
45
+ /** What to fire: an event id or an action id. Absent = core:event/message-respond@1. */
46
+ subject?: string;
47
+ /**
48
+ * How decided. Open string; core: strategy | script | voice, pick on an
49
+ * entry a person fires, and 🚧 `plan` — a turn a standing turn plan named
50
+ * (a Lair character turn): the rest of a turn already taken, which
51
+ * auto-advance fires on any run's cause but a stopped one.
52
+ */
53
+ via: string;
54
+ [k: string]: unknown;
55
+ }
56
+ /** @experimental */
57
+ export interface TurnOrderV1 {
58
+ v: 1;
59
+ order: TurnEntryV1[];
60
+ candidates: TurnCandidateV1[];
61
+ /** Epoch ms of the event this order answers. The write rule keeps the newer. */
62
+ basedOnAt: number;
63
+ computedAt: number;
64
+ runId: string | null;
65
+ /** The event id that caused the recompute. */
66
+ event: string | null;
67
+ /** The strategy definition id that produced `order`. */
68
+ strategy: string | null;
69
+ }
70
+ /**
71
+ * The order a session has before its first recompute — and what a reader
72
+ * answers for a document it cannot read. Frozen: a caller that wants to
73
+ * build on it copies it.
74
+ * @experimental
75
+ */
76
+ export declare const EMPTY_TURN_ORDER: TurnOrderV1;
77
+ /**
78
+ * The turn order a session's `metadata` holds — `EMPTY_TURN_ORDER` when the
79
+ * key is missing or the value is not a `TurnOrderV1`. Never throws: a
80
+ * session that predates this build, or one whose metadata a hand edit
81
+ * broke, has an empty order until its next event recomputes it (§4.1,
82
+ * "no backfill"). The document is returned as stored, extra keys included;
83
+ * only its shape is judged.
84
+ * @experimental
85
+ */
86
+ export declare function readTurnOrder(metadata: unknown): TurnOrderV1;
87
+ /**
88
+ * The fields of a history row the round-robin rule reads — the shape
89
+ * `core:shape/messages@1` carries (the host's `session-history` projection),
90
+ * reduced to what the rule needs. Rows may carry more; the rule ignores it.
91
+ *
92
+ * @experimental 🚧 provisional with the turn-order vocabulary (PLAN-turn-order §4.4).
93
+ */
94
+ export interface TurnHistoryMessage {
95
+ role: string;
96
+ characterId?: number | null;
97
+ personaId?: number | null;
98
+ isHidden?: boolean | null;
99
+ isNarratorResponse?: boolean | null;
100
+ /**
101
+ * The row's participant reference (`envoy:<slug>`), as `session-history`
102
+ * publishes it. A raw row keeps it in `metadata.speaker` instead; both are read.
103
+ */
104
+ speaker?: string | null;
105
+ metadata?: unknown;
106
+ }
107
+ /**
108
+ * The rows that count as turns: not hidden, not narration. Hidden rows and
109
+ * narrator responses are outside the rotation entirely. A missing row (`null`
110
+ * or `undefined` — a sparse or partially loaded history) is skipped, never a
111
+ * throw: every reader of turn order goes through here, so it tolerates them once.
112
+ *
113
+ * @experimental 🚧 provisional with the turn-order vocabulary (PLAN-turn-order §4.4).
114
+ */
115
+ export declare function countedTurns<M extends TurnHistoryMessage>(messages: readonly (M | null | undefined)[]): M[];
116
+ /**
117
+ * Which participants have already spoken since the person last did, as
118
+ * references (`character:<id>`, `envoy:<slug>`).
119
+ *
120
+ * Three readings, one per kind, each the fact that kind leaves in the
121
+ * history: a character's id on a reply row, an envoy's reference on a reply
122
+ * row (`speaker`, else `metadata.speaker`), a persona's id on the user row
123
+ * that opened the window — the person's own send is their turn, consumed. An
124
+ * envoy's reply marks no character. Before any user row the whole history is
125
+ * one round, so a greeting counts as its character's turn.
126
+ *
127
+ * @experimental 🚧 provisional with the turn-order vocabulary (PLAN-turn-order §4.4).
128
+ */
129
+ export declare function spokenRefsSince(messages: readonly (TurnHistoryMessage | null | undefined)[]): Set<string>;
130
+ /**
131
+ * Round robin — once per turn of the person's: every candidate that has not
132
+ * spoken since the person last did, in candidate order, each entry
133
+ * `via: 'strategy'`. Everyone having spoken is an empty order (the person's
134
+ * turn), never a halt; the next user row opens a fresh round, and a manual
135
+ * out-of-turn trigger counts as that candidate's turn for the round.
136
+ *
137
+ * This is the rule `core:task/turn-round-robin@1` runs, and the fallback a
138
+ * plugin's own strategy should use rather than carry a copy of it.
139
+ *
140
+ * @experimental 🚧 provisional with the turn-order vocabulary (PLAN-turn-order §4.4).
141
+ */
142
+ export declare function roundRobinOrder(candidates: readonly TurnCandidateV1[], messages: readonly (TurnHistoryMessage | null | undefined)[]): TurnEntryV1[];
143
+ //# sourceMappingURL=turnOrder.d.ts.map
@@ -0,0 +1,128 @@
1
+ /**
2
+ * The order a session has before its first recompute — and what a reader
3
+ * answers for a document it cannot read. Frozen: a caller that wants to
4
+ * build on it copies it.
5
+ * @experimental
6
+ */
7
+ export const EMPTY_TURN_ORDER = Object.freeze({
8
+ v: 1,
9
+ order: Object.freeze([]),
10
+ candidates: Object.freeze([]),
11
+ basedOnAt: 0,
12
+ computedAt: 0,
13
+ runId: null,
14
+ event: null,
15
+ strategy: null,
16
+ });
17
+ const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
18
+ const isEntry = (v) => isRecord(v) &&
19
+ (v.ref === null || typeof v.ref === 'string') &&
20
+ typeof v.via === 'string' &&
21
+ (v.channel === undefined || typeof v.channel === 'string') &&
22
+ (v.subject === undefined || typeof v.subject === 'string');
23
+ const isCandidate = (v) => isRecord(v) &&
24
+ typeof v.ref === 'string' &&
25
+ typeof v.kind === 'string' &&
26
+ typeof v.name === 'string' &&
27
+ typeof v.position === 'number';
28
+ /**
29
+ * The turn order a session's `metadata` holds — `EMPTY_TURN_ORDER` when the
30
+ * key is missing or the value is not a `TurnOrderV1`. Never throws: a
31
+ * session that predates this build, or one whose metadata a hand edit
32
+ * broke, has an empty order until its next event recomputes it (§4.1,
33
+ * "no backfill"). The document is returned as stored, extra keys included;
34
+ * only its shape is judged.
35
+ * @experimental
36
+ */
37
+ export function readTurnOrder(metadata) {
38
+ if (!isRecord(metadata))
39
+ return EMPTY_TURN_ORDER;
40
+ const t = metadata.turnOrder;
41
+ if (!isRecord(t))
42
+ return EMPTY_TURN_ORDER;
43
+ if (t.v !== 1)
44
+ return EMPTY_TURN_ORDER;
45
+ if (!Array.isArray(t.order) || !t.order.every(isEntry))
46
+ return EMPTY_TURN_ORDER;
47
+ if (!Array.isArray(t.candidates) || !t.candidates.every(isCandidate))
48
+ return EMPTY_TURN_ORDER;
49
+ if (typeof t.basedOnAt !== 'number' || typeof t.computedAt !== 'number')
50
+ return EMPTY_TURN_ORDER;
51
+ if (t.runId !== null && typeof t.runId !== 'string')
52
+ return EMPTY_TURN_ORDER;
53
+ if (t.event !== null && typeof t.event !== 'string')
54
+ return EMPTY_TURN_ORDER;
55
+ if (t.strategy !== null && typeof t.strategy !== 'string')
56
+ return EMPTY_TURN_ORDER;
57
+ return t;
58
+ }
59
+ /** Who voiced a row, by reference: the projected `speaker`, else the raw `metadata.speaker`. */
60
+ const speakerRefOf = (m) => m.speaker ?? m.metadata?.speaker;
61
+ /**
62
+ * The rows that count as turns: not hidden, not narration. Hidden rows and
63
+ * narrator responses are outside the rotation entirely. A missing row (`null`
64
+ * or `undefined` — a sparse or partially loaded history) is skipped, never a
65
+ * throw: every reader of turn order goes through here, so it tolerates them once.
66
+ *
67
+ * @experimental 🚧 provisional with the turn-order vocabulary (PLAN-turn-order §4.4).
68
+ */
69
+ export function countedTurns(messages) {
70
+ return messages.filter((m) => !!m && !m.isHidden && !m.isNarratorResponse);
71
+ }
72
+ const lastUserIndex = (turns) => {
73
+ for (let i = turns.length - 1; i >= 0; i--)
74
+ if (turns[i].role === 'user')
75
+ return i;
76
+ return -1;
77
+ };
78
+ /**
79
+ * Which participants have already spoken since the person last did, as
80
+ * references (`character:<id>`, `envoy:<slug>`).
81
+ *
82
+ * Three readings, one per kind, each the fact that kind leaves in the
83
+ * history: a character's id on a reply row, an envoy's reference on a reply
84
+ * row (`speaker`, else `metadata.speaker`), a persona's id on the user row
85
+ * that opened the window — the person's own send is their turn, consumed. An
86
+ * envoy's reply marks no character. Before any user row the whole history is
87
+ * one round, so a greeting counts as its character's turn.
88
+ *
89
+ * @experimental 🚧 provisional with the turn-order vocabulary (PLAN-turn-order §4.4).
90
+ */
91
+ export function spokenRefsSince(messages) {
92
+ const turns = countedTurns(messages);
93
+ const at = lastUserIndex(turns);
94
+ const out = new Set();
95
+ for (let i = at + 1; i < turns.length; i++) {
96
+ const m = turns[i];
97
+ if (m.role !== 'assistant')
98
+ continue;
99
+ if (m.characterId != null)
100
+ out.add(`character:${m.characterId}`);
101
+ const ref = speakerRefOf(m);
102
+ if (typeof ref === 'string' && ref.startsWith('envoy:'))
103
+ out.add(ref);
104
+ }
105
+ if (at >= 0) {
106
+ const sender = turns[at].personaId;
107
+ if (sender != null)
108
+ out.add(`character:${sender}`);
109
+ }
110
+ return out;
111
+ }
112
+ /**
113
+ * Round robin — once per turn of the person's: every candidate that has not
114
+ * spoken since the person last did, in candidate order, each entry
115
+ * `via: 'strategy'`. Everyone having spoken is an empty order (the person's
116
+ * turn), never a halt; the next user row opens a fresh round, and a manual
117
+ * out-of-turn trigger counts as that candidate's turn for the round.
118
+ *
119
+ * This is the rule `core:task/turn-round-robin@1` runs, and the fallback a
120
+ * plugin's own strategy should use rather than carry a copy of it.
121
+ *
122
+ * @experimental 🚧 provisional with the turn-order vocabulary (PLAN-turn-order §4.4).
123
+ */
124
+ export function roundRobinOrder(candidates, messages) {
125
+ const spoken = spokenRefsSince(messages);
126
+ return candidates.filter((c) => !spoken.has(c.ref)).map((c) => ({ ref: c.ref, via: 'strategy' }));
127
+ }
128
+ //# sourceMappingURL=turnOrder.js.map
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Validation — the Fixed Ledger laws that can be checked statically.
3
+ *
4
+ * Every finding names what to do instead (15 §1.3). A prohibition without a stated
5
+ * alternative is a bug, and there is a test asserting exactly that.
6
+ */
7
+ import { type SpecDocument } from './document.js';
8
+ import { type TemplateChecking } from './templateFit.js';
9
+ /** @experimental */
10
+ export interface Finding {
11
+ law: string;
12
+ severity: 'error' | 'warning';
13
+ nodeKey?: string;
14
+ message: string;
15
+ /** What to do instead — required for every error. */
16
+ fix: string;
17
+ }
18
+ /**
19
+ * What `validate()` is handed beyond the document. @experimental
20
+ */
21
+ export interface ValidateOptions {
22
+ /**
23
+ * The template checker, for law T1's name check (typed templates P5):
24
+ * `{ check: checkTemplateSourceReport }` from `@serene-pub/sdk/template-check`,
25
+ * plus the host's vocabulary. A value rather than an import because the
26
+ * checker carries the engines and this module is on the dependency-free
27
+ * barrel. Absent, T1 still refuses scope collisions, forbidden kinds and a
28
+ * band with no variable; it does not read template sources.
29
+ */
30
+ templates?: TemplateChecking;
31
+ }
32
+ /** @experimental */
33
+ export declare function validate(doc: SpecDocument, options?: ValidateOptions): Finding[];
34
+ /**
35
+ * The streaming step and the step status, as declared on `expose` (lair
36
+ * pass B3/B18; owner D6 and D5, 2026-09-27).
37
+ *
38
+ * Which oracle streams into the reply is **declared**, never inferred: the
39
+ * inference it replaced skipped every oracle inside a clause and streamed the
40
+ * Lair's planner JSON into the row. What a declaration can still get wrong is
41
+ * refused here, each with the fix:
42
+ *
43
+ * · **a JSON step never streams** — a step whose `main` out-port is not a
44
+ * streaming shape (`generate-json`, whose `main` is `core:shape/json@1`)
45
+ * would write its document into the row a person is reading;
46
+ * · **one per execution path** — a run has one live row, and two streams
47
+ * interleave or concatenate into it. Two steps that can never run in the
48
+ * same execution may each stream (W2, 2026-09-27): they sit in different
49
+ * branches of one junction whose predicates are mutually exclusive — one
50
+ * is the `otherwise`, or both are `equals` on the same path with different
51
+ * literals. The runtime streams whichever one runs. Anything weaker (a
52
+ * `truthy`, an `equalsPath`, two different paths) could fire both, so it
53
+ * is refused, and so is a step on the spine beside one in a branch;
54
+ * · **never in an each or a loop** — the step would stream once per pass
55
+ * into the same row;
56
+ * · **an oracle** — only an oracle has a model's tokens to stream.
57
+ *
58
+ * A step status, step label and step purpose are display text (R-20), and a
59
+ * step purpose sits only on a model call — an oracle whose definition declares
60
+ * a `connection` slot (`isModelCall`; law `step purpose`, 2026-09-30).
61
+ * @internal
62
+ */
63
+ export declare function streamingStepFindings(doc: SpecDocument): Finding[];
64
+ /** @experimental */
65
+ export declare function assertValid(doc: SpecDocument, options?: ValidateOptions): void;
66
+ /**
67
+ * The R-20 findings over one stored document: presets, and the genre
68
+ * declaration a create pipeline carries. Read as `unknown` throughout — a
69
+ * document may have come from anywhere — so a wrong shape is a sentence,
70
+ * never a throw.
71
+ * @experimental
72
+ */
73
+ export declare function documentDisplayTextFindings(doc: SpecDocument): string[];
74
+ //# sourceMappingURL=validate.d.ts.map