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

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 (186) hide show
  1. package/README.md +23 -19
  2. package/dist/actions.d.ts +149 -67
  3. package/dist/actions.js +89 -35
  4. package/dist/annexFields.d.ts +8 -4
  5. package/dist/annexFields.js +5 -2
  6. package/dist/announce.d.ts +78 -28
  7. package/dist/announce.js +14 -5
  8. package/dist/attributes.d.ts +9 -6
  9. package/dist/attributes.js +9 -5
  10. package/dist/bands.d.ts +41 -6
  11. package/dist/bands.js +83 -33
  12. package/dist/builder.d.ts +161 -58
  13. package/dist/builder.js +128 -22
  14. package/dist/candidates.d.ts +5 -3
  15. package/dist/candidates.js +3 -2
  16. package/dist/clauses.d.ts +2 -1
  17. package/dist/clauses.js +2 -1
  18. package/dist/component.d.ts +24 -7
  19. package/dist/component.js +16 -6
  20. package/dist/componentBuild.d.ts +16 -5
  21. package/dist/componentBuild.js +14 -5
  22. package/dist/componentClient.d.ts +61 -30
  23. package/dist/componentClient.js +11 -1
  24. package/dist/componentImports.d.ts +8 -5
  25. package/dist/componentImports.js +23 -4
  26. package/dist/componentModule.js +2 -1
  27. package/dist/componentWire.d.ts +2 -1
  28. package/dist/componentWire.js +34 -2
  29. package/dist/config.d.ts +28 -14
  30. package/dist/config.js +20 -10
  31. package/dist/connections.d.ts +9 -4
  32. package/dist/connections.js +7 -4
  33. package/dist/declarations.d.ts +46 -17
  34. package/dist/declarations.js +46 -15
  35. package/dist/descriptors.d.ts +242 -97
  36. package/dist/descriptors.js +145 -41
  37. package/dist/dev.d.ts +6 -5
  38. package/dist/dev.js +6 -5
  39. package/dist/document.d.ts +74 -25
  40. package/dist/document.js +32 -11
  41. package/dist/dowry.d.ts +241 -0
  42. package/dist/dowry.js +315 -0
  43. package/dist/engines.d.ts +16 -7
  44. package/dist/engines.js +6 -4
  45. package/dist/eventMapLaws.d.ts +19 -8
  46. package/dist/eventMapLaws.js +9 -6
  47. package/dist/events.d.ts +101 -39
  48. package/dist/events.js +106 -33
  49. package/dist/executor.d.ts +122 -41
  50. package/dist/executor.js +188 -95
  51. package/dist/extension.d.ts +99 -35
  52. package/dist/extension.js +43 -9
  53. package/dist/facets.d.ts +2 -1
  54. package/dist/facets.js +4 -2
  55. package/dist/foldedSections.d.ts +4 -2
  56. package/dist/foldedSections.js +2 -1
  57. package/dist/genres.d.ts +123 -41
  58. package/dist/genres.js +127 -22
  59. package/dist/guardedConnection.d.ts +4 -3
  60. package/dist/guardedConnection.js +4 -3
  61. package/dist/handlebarsReach.d.ts +1 -1
  62. package/dist/handlebarsReach.js +1 -1
  63. package/dist/hash.d.ts +16 -5
  64. package/dist/hash.js +14 -4
  65. package/dist/hookGrants.d.ts +3 -2
  66. package/dist/hookGrants.js +6 -4
  67. package/dist/hooks.d.ts +21 -16
  68. package/dist/hooks.js +12 -10
  69. package/dist/hostElements.d.ts +41 -17
  70. package/dist/hostElements.js +49 -17
  71. package/dist/i18n.d.ts +5 -3
  72. package/dist/i18n.js +5 -3
  73. package/dist/identity.d.ts +4 -3
  74. package/dist/identity.js +4 -3
  75. package/dist/index.d.ts +5 -0
  76. package/dist/index.js +15 -0
  77. package/dist/layout.d.ts +36 -15
  78. package/dist/layout.js +2 -2
  79. package/dist/loadouts.d.ts +97 -0
  80. package/dist/loadouts.js +81 -0
  81. package/dist/media.d.ts +26 -4
  82. package/dist/media.js +2 -1
  83. package/dist/messageBlocks.d.ts +44 -32
  84. package/dist/messageBlocks.js +23 -18
  85. package/dist/migration.d.ts +16 -8
  86. package/dist/migration.js +14 -8
  87. package/dist/names.d.ts +2 -1
  88. package/dist/names.js +2 -1
  89. package/dist/nodeInput.d.ts +2 -1
  90. package/dist/nodeInput.js +2 -1
  91. package/dist/participants.d.ts +22 -15
  92. package/dist/participants.js +14 -12
  93. package/dist/personGate.d.ts +2 -1
  94. package/dist/personGate.js +2 -1
  95. package/dist/pluginHarness.d.ts +8 -3
  96. package/dist/pluginHarness.js +4 -2
  97. package/dist/pluginPermissions.d.ts +2 -1
  98. package/dist/pluginPermissions.js +12 -1
  99. package/dist/pluginRuleRef.d.ts +2 -2
  100. package/dist/pluginRuleRef.js +1 -1
  101. package/dist/predicates.d.ts +16 -11
  102. package/dist/predicates.js +7 -6
  103. package/dist/preview.d.ts +8 -3
  104. package/dist/preview.js +2 -1
  105. package/dist/promptBlocks.d.ts +5 -3
  106. package/dist/promptBlocks.js +5 -3
  107. package/dist/rankingDecisions.d.ts +2 -1
  108. package/dist/rankingDecisions.js +2 -1
  109. package/dist/receipt.d.ts +65 -29
  110. package/dist/receipt.js +9 -4
  111. package/dist/receiverRules.js +3 -2
  112. package/dist/refs.d.ts +34 -9
  113. package/dist/refs.js +33 -13
  114. package/dist/registry.d.ts +42 -23
  115. package/dist/registry.js +7 -5
  116. package/dist/review.d.ts +16 -5
  117. package/dist/review.js +11 -4
  118. package/dist/sampling.d.ts +54 -0
  119. package/dist/sampling.js +95 -3
  120. package/dist/sceneSettings.d.ts +312 -0
  121. package/dist/sceneSettings.js +425 -0
  122. package/dist/scope.d.ts +6 -4
  123. package/dist/scope.js +4 -3
  124. package/dist/scripts.d.ts +81 -14
  125. package/dist/scripts.js +90 -11
  126. package/dist/sessionDossier.d.ts +521 -0
  127. package/dist/sessionDossier.js +33 -0
  128. package/dist/sessionLayout.d.ts +303 -19
  129. package/dist/sessionLayout.js +354 -40
  130. package/dist/sessionSettings.d.ts +8 -5
  131. package/dist/settings.d.ts +45 -20
  132. package/dist/settings.js +19 -12
  133. package/dist/settingsSlot.d.ts +11 -8
  134. package/dist/settingsSlot.js +11 -8
  135. package/dist/shapes.d.ts +99 -36
  136. package/dist/shapes.js +101 -35
  137. package/dist/sheets.d.ts +4 -2
  138. package/dist/sheets.js +6 -3
  139. package/dist/statShapes.d.ts +2 -1
  140. package/dist/statShapes.js +2 -1
  141. package/dist/status.d.ts +13 -9
  142. package/dist/status.js +8 -6
  143. package/dist/storage.d.ts +2 -1
  144. package/dist/storage.js +2 -1
  145. package/dist/storyTime.d.ts +13 -7
  146. package/dist/storyTime.js +11 -6
  147. package/dist/strokes.d.ts +176 -0
  148. package/dist/strokes.js +281 -0
  149. package/dist/surfaces.d.ts +54 -25
  150. package/dist/surfaces.js +3 -3
  151. package/dist/template.d.ts +9 -5
  152. package/dist/template.js +5 -3
  153. package/dist/templateCheck.d.ts +2 -2
  154. package/dist/templateCheck.js +2 -2
  155. package/dist/templateFit.d.ts +37 -8
  156. package/dist/templateFit.js +92 -8
  157. package/dist/templateIds.d.ts +3 -3
  158. package/dist/templateIds.js +3 -3
  159. package/dist/templateScopeAt.d.ts +21 -11
  160. package/dist/templateScopeAt.js +21 -11
  161. package/dist/testing.d.ts +11 -4
  162. package/dist/testing.js +13 -5
  163. package/dist/tokenizers.d.ts +2 -2
  164. package/dist/tokenizers.js +2 -2
  165. package/dist/turnLock.d.ts +4 -2
  166. package/dist/turnLock.js +2 -1
  167. package/dist/turnOrder.d.ts +17 -11
  168. package/dist/turnOrder.js +9 -5
  169. package/dist/validate.d.ts +11 -8
  170. package/dist/validate.js +81 -10
  171. package/dist/values.d.ts +17 -8
  172. package/dist/values.js +11 -6
  173. package/dist/variables.d.ts +46 -7
  174. package/dist/variables.js +87 -6
  175. package/dist/verdicts.d.ts +20 -13
  176. package/dist/verdicts.js +17 -11
  177. package/dist/widgetDecls.d.ts +8 -4
  178. package/dist/widgetDecls.js +4 -2
  179. package/dist/widgets.d.ts +987 -94
  180. package/dist/widgets.js +93 -18
  181. package/dist/wire.d.ts +13 -6
  182. package/dist/wire.js +3 -3
  183. package/dist/worldinfo.d.ts +11 -6
  184. package/dist/worldinfo.js +8 -4
  185. package/host-elements.d.ts +13 -0
  186. package/package.json +1 -1
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * Parts, validated beyond shape only against a book's **declared calendar**
17
17
  * (`StoryCalendar`, below) when it has one; with none the book is
18
- * **free-form** — no month lengths, no rollover, no origin. The story-time design (DESIGN-story-time) stores a signed
18
+ * **free-form** — no month lengths, no rollover, no origin. The story-time design stores a signed
19
19
  * **instant** once a book has a real calendar; when that rung is built the
20
20
  * shape moves to `@2` rather than reinterpreting what `@1` stored.
21
21
  *
@@ -27,6 +27,7 @@
27
27
  * number to sort on: a radix packing collides once a part passes its radix,
28
28
  * which is the bug the host's `compareDates` was rewritten to fix. The host's
29
29
  * lorebook dates delegate here, so one calendar has one comparator.
30
+ * @ruling DESIGN-story-time
30
31
  */
31
32
  /** A position on the story calendar. An absent part is one the author did not give. @experimental */
32
33
  export interface StoryTime {
@@ -46,7 +47,7 @@ export interface StoryTime {
46
47
  * leap day — `storyTimeProblem`); nothing widens it. `parseStoryTime`,
47
48
  * `storyTimeProblem` and core's history entry type all read these, and the
48
49
  * entry type's declared range is projected into the database's CHECK — so a
49
- * date a book's calendar allows is a date the database holds (A15, 2026-09-30:
50
+ * date a book's calendar allows is a date the database holds (2026-09-30:
50
51
  * a copied 1–12 / 1–31 once refused month 13 of a thirteen-month calendar and
51
52
  * the day after a free-form day 31).
52
53
  *
@@ -64,6 +65,7 @@ export interface StoryTime {
64
65
  * `storyTimeProblem`'s, which reads these for every part and is the check
65
66
  * every dated writer answers with.
66
67
  * @experimental
68
+ * @ruling A15 (2026-09-30)
67
69
  */
68
70
  export declare const STORY_TIME_PART_RANGES: {
69
71
  readonly month: {
@@ -221,8 +223,9 @@ export declare function storyTimeProblem(time: StoryTime, calendar: StoryCalenda
221
223
  * without a full date or for one that does not land.
222
224
  *
223
225
  * ⚠ A POSITION FOR ARITHMETIC (weekdays), not a stored key and not an
224
- * ordering: the design's `day_index` column is P2 and not built.
226
+ * ordering: the design's `day_index` column is a later step and not built.
225
227
  * @experimental
228
+ * @ruling P2
226
229
  */
227
230
  export declare function storyDayIndex(time: StoryTime, calendar: StoryCalendar): number | null;
228
231
  /**
@@ -257,8 +260,9 @@ export declare function storyTimeOfDayIndex(index: number, calendar: StoryCalend
257
260
  day: number;
258
261
  };
259
262
  /**
260
- * What a story clock advances by (DESIGN-story-time §5, `advance(n, unit)`).
263
+ * What a story clock advances by (`advance(n, unit)`).
261
264
  * @experimental
265
+ * @ruling DESIGN-story-time §5
262
266
  */
263
267
  export type StoryTimeUnit = 'minutes' | 'hours' | 'days' | 'months' | 'years';
264
268
  /** @experimental */
@@ -275,8 +279,8 @@ export type StoryTimeAdvance = {
275
279
  problem: string;
276
280
  };
277
281
  /**
278
- * Move a story time by `by` of `unit` — what a clock's `advance(n, unit)` is
279
- * (DESIGN-story-time P3). Negative `by` goes back.
282
+ * Move a story time by `by` of `unit` — what a clock's `advance(n, unit)` is.
283
+ * Negative `by` goes back.
280
284
  *
281
285
  * **By a declared calendar** the step carries: minutes into hours into days
282
286
  * (a 24-hour day), days through month lengths and the leap day, months into
@@ -293,12 +297,14 @@ export type StoryTimeAdvance = {
293
297
  * A missing time of day reads as the start of the day when stepping by hours
294
298
  * or minutes, and stays missing otherwise.
295
299
  * @experimental
300
+ * @ruling DESIGN-story-time P3
296
301
  */
297
302
  export declare function advanceStoryTime(from: StoryTime, by: number, unit: StoryTimeUnit, calendar?: StoryCalendar | null): StoryTimeAdvance;
298
303
  /**
299
- * The presets the calendar editor starts from (DESIGN-story-time P5). Each is
304
+ * The presets the calendar editor starts from. Each is
300
305
  * an ordinary declared calendar — a starting point, never a live link.
301
306
  * @experimental
307
+ * @ruling DESIGN-story-time P5
302
308
  */
303
309
  export declare const STORY_CALENDAR_PRESETS: ReadonlyArray<{
304
310
  id: string;
package/dist/storyTime.js CHANGED
@@ -15,7 +15,7 @@
15
15
  *
16
16
  * Parts, validated beyond shape only against a book's **declared calendar**
17
17
  * (`StoryCalendar`, below) when it has one; with none the book is
18
- * **free-form** — no month lengths, no rollover, no origin. The story-time design (DESIGN-story-time) stores a signed
18
+ * **free-form** — no month lengths, no rollover, no origin. The story-time design stores a signed
19
19
  * **instant** once a book has a real calendar; when that rung is built the
20
20
  * shape moves to `@2` rather than reinterpreting what `@1` stored.
21
21
  *
@@ -27,6 +27,7 @@
27
27
  * number to sort on: a radix packing collides once a part passes its radix,
28
28
  * which is the bug the host's `compareDates` was rewritten to fix. The host's
29
29
  * lorebook dates delegate here, so one calendar has one comparator.
30
+ * @ruling DESIGN-story-time
30
31
  */
31
32
  /**
32
33
  * The range each part of a story time takes on EVERY rung of the calendar —
@@ -36,7 +37,7 @@
36
37
  * leap day — `storyTimeProblem`); nothing widens it. `parseStoryTime`,
37
38
  * `storyTimeProblem` and core's history entry type all read these, and the
38
39
  * entry type's declared range is projected into the database's CHECK — so a
39
- * date a book's calendar allows is a date the database holds (A15, 2026-09-30:
40
+ * date a book's calendar allows is a date the database holds (2026-09-30:
40
41
  * a copied 1–12 / 1–31 once refused month 13 of a thirteen-month calendar and
41
42
  * the day after a free-form day 31).
42
43
  *
@@ -54,6 +55,7 @@
54
55
  * `storyTimeProblem`'s, which reads these for every part and is the check
55
56
  * every dated writer answers with.
56
57
  * @experimental
58
+ * @ruling A15 (2026-09-30)
57
59
  */
58
60
  export const STORY_TIME_PART_RANGES = {
59
61
  month: { min: 1 },
@@ -322,8 +324,9 @@ export function storyTimeProblem(time, calendar) {
322
324
  * without a full date or for one that does not land.
323
325
  *
324
326
  * ⚠ A POSITION FOR ARITHMETIC (weekdays), not a stored key and not an
325
- * ordering: the design's `day_index` column is P2 and not built.
327
+ * ordering: the design's `day_index` column is a later step and not built.
326
328
  * @experimental
329
+ * @ruling P2
327
330
  */
328
331
  export function storyDayIndex(time, calendar) {
329
332
  if (!has(time.month) || !has(time.day) || storyTimeProblem(time, calendar))
@@ -437,8 +440,8 @@ function partsOf(t) {
437
440
  return out;
438
441
  }
439
442
  /**
440
- * Move a story time by `by` of `unit` — what a clock's `advance(n, unit)` is
441
- * (DESIGN-story-time P3). Negative `by` goes back.
443
+ * Move a story time by `by` of `unit` — what a clock's `advance(n, unit)` is.
444
+ * Negative `by` goes back.
442
445
  *
443
446
  * **By a declared calendar** the step carries: minutes into hours into days
444
447
  * (a 24-hour day), days through month lengths and the leap day, months into
@@ -455,6 +458,7 @@ function partsOf(t) {
455
458
  * A missing time of day reads as the start of the day when stepping by hours
456
459
  * or minutes, and stays missing otherwise.
457
460
  * @experimental
461
+ * @ruling DESIGN-story-time P3
458
462
  */
459
463
  export function advanceStoryTime(from, by, unit, calendar) {
460
464
  if (!isInt(by) || by === 0)
@@ -519,9 +523,10 @@ export function advanceStoryTime(from, by, unit, calendar) {
519
523
  }
520
524
  const WEEK = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
521
525
  /**
522
- * The presets the calendar editor starts from (DESIGN-story-time P5). Each is
526
+ * The presets the calendar editor starts from. Each is
523
527
  * an ordinary declared calendar — a starting point, never a live link.
524
528
  * @experimental
529
+ * @ruling DESIGN-story-time P5
525
530
  */
526
531
  export const STORY_CALENDAR_PRESETS = [
527
532
  {
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Card strokes — a character's description and personality as an ordered list
3
+ * of small pieces of prose ("a card is painted in strokes").
4
+ *
5
+ * ⏸ Paused 2026-10-11 (owner): no core spec places this step and the app hides strokes behind `STROKES_ENABLED`; kept so stored documents and the registry hash stay stable.
6
+ *
7
+ * ## What a stroke is
8
+ *
9
+ * One piece of a card's prose: which field it belongs to (`kind`), an optional
10
+ * `label` a person reads ("Eyes"), an optional `slug` a template addresses it
11
+ * by (`character.strokes.eyes`), the `text`, and **one** condition — `when`.
12
+ * Array order is position. A card with no strokes is the legacy shape and its
13
+ * prose columns are the truth; a card with strokes has its `description` and
14
+ * `personality` compiled from them (`compileStrokes`), so every existing
15
+ * template, embedding and export keeps reading four plain fields.
16
+ *
17
+ * ## What a stroke is NOT
18
+ *
19
+ * · **Not a lorebook entry.** A stroke lives on the card and leaves with it; it
20
+ * has no priority, no weight, no budget, no ranker. A keyword stroke is
21
+ * marked `fired` or not against the recent transcript (`resolveStrokes`, run
22
+ * by `core:task/card-strokes@1`) and that is the whole of its life — it never
23
+ * competes with lore for room, and nothing here ranks one stroke over another.
24
+ * · **Not a matcher.** The SDK never matches keywords. The host owns the one
25
+ * keyword matcher (match modes, the regex time limit, the refused-pattern
26
+ * check) and hands it to `resolveStrokes`; the shape here is what it is
27
+ * asked about.
28
+ * · **Not an import transform.** Nothing explodes a card's prose into strokes
29
+ * behind a person's back: `splitIntoStrokes` is the explicit "Split into
30
+ * strokes" action, previewed before anything is saved.
31
+ *
32
+ * `when` is the only condition language. A fourth mode (a predicate over
33
+ * state) is planned under `when`; the shape does not block it.
34
+ */
35
+ /** Which card field a stroke paints. Closed for now. @experimental */
36
+ export type StrokeKind = 'description' | 'personality';
37
+ /** @experimental */
38
+ export declare const STROKE_KINDS: readonly StrokeKind[];
39
+ /** How a keyword stroke's keys are compared — the lore matcher's three modes. @experimental */
40
+ export type StrokeMatchMode = 'substring' | 'word' | 'regex';
41
+ /** @experimental */
42
+ export declare const STROKE_MATCH_MODES: readonly StrokeMatchMode[];
43
+ /**
44
+ * A keyword stroke's condition: in the prompt only when one of `keys` appears
45
+ * in the recent transcript. `matchMode` and `caseSensitive` mean what they mean
46
+ * on a lorebook entry, because the host answers both with the same matcher.
47
+ * @experimental
48
+ */
49
+ export interface StrokeKeywordsWhen {
50
+ mode: 'keywords';
51
+ keys: string[];
52
+ matchMode?: StrokeMatchMode;
53
+ caseSensitive?: boolean;
54
+ }
55
+ /**
56
+ * When a stroke is in the prompt.
57
+ *
58
+ * - `always` — every turn.
59
+ * - `off` — never; kept on the card, compiled nowhere.
60
+ * - `keywords` — when a key appears in the recent transcript. Before any
61
+ * step resolved it, it is IN (the fallback loses nothing, only budget).
62
+ * @experimental
63
+ */
64
+ export type StrokeWhen = {
65
+ mode: 'always';
66
+ } | {
67
+ mode: 'off';
68
+ } | StrokeKeywordsWhen;
69
+ /** @experimental */
70
+ export interface Stroke {
71
+ kind: StrokeKind;
72
+ /**
73
+ * The data key a template addresses the stroke by. Author-owned, unique per
74
+ * card, `^[a-z0-9][a-z0-9-]{0,63}$`. The slug is the key; `label` is what a
75
+ * person reads.
76
+ */
77
+ slug?: string;
78
+ /** "Eyes" — compiles as `Eyes: green`. Absent, the bare text. */
79
+ label?: string;
80
+ text: string;
81
+ when: StrokeWhen;
82
+ }
83
+ /**
84
+ * A stroke after `core:task/card-strokes@1` ran: `fired` stamped. `always` is
85
+ * fired, `off` never is, a keyword stroke is whatever the matcher said.
86
+ * @experimental
87
+ */
88
+ export type ResolvedStroke = Stroke & {
89
+ fired: boolean;
90
+ };
91
+ /** The caps a card's strokes are held to, at save and at import. @experimental */
92
+ export declare const STROKE_LIMITS: Readonly<{
93
+ readonly maxStrokes: 200;
94
+ readonly maxTextChars: 4000;
95
+ readonly maxKeys: 32;
96
+ readonly maxKeyChars: 120;
97
+ readonly maxLabelChars: 80;
98
+ }>;
99
+ /** A stroke slug — the attributes rule: lower-case, digits and dashes, 64 at most. @experimental */
100
+ export declare const STROKE_SLUG: RegExp;
101
+ /** @experimental */
102
+ export interface CompileStrokesOptions {
103
+ /**
104
+ * Keyword strokes compile only when `fired` is true — the shape after
105
+ * `core:task/card-strokes@1` ran. Absent, every enabled stroke compiles,
106
+ * keyword ones included: the cached column and the no-step fallback.
107
+ */
108
+ firedOnly?: boolean;
109
+ }
110
+ /**
111
+ * One card field compiled from its strokes — the ONE join rule.
112
+ *
113
+ * A labelled stroke is `Label: text`, an unlabelled one its bare text.
114
+ * Description strokes are joined by a blank line. Personality strokes are
115
+ * joined by `; ` when any compiled one has a label (PList-shaped), else by a
116
+ * newline. `off` strokes never compile. `null` when nothing does — the card
117
+ * then has no such field, which is what `compileCharacter` already does with
118
+ * an empty one.
119
+ * @experimental
120
+ */
121
+ export declare function compileStrokes(strokes: readonly (Stroke | ResolvedStroke)[] | null | undefined, kind: StrokeKind, opts?: CompileStrokesOptions): string | null;
122
+ /**
123
+ * Asked once per keyword stroke: does this condition hold against the recent
124
+ * transcript? Supplied by the host, which owns the one keyword matcher and its
125
+ * regex time limit. The SDK never matches.
126
+ * @experimental
127
+ */
128
+ export type StrokeMatcher = (when: StrokeKeywordsWhen) => boolean;
129
+ /**
130
+ * Stamp `fired` on every stroke — what `core:task/card-strokes@1` does to each
131
+ * card in the cast. Order is kept, nothing is dropped, nothing is ranked:
132
+ * `always` → true, `off` → false, `keywords` → the matcher's answer. A matcher
133
+ * that throws leaves that stroke unfired rather than failing the turn.
134
+ * @experimental
135
+ */
136
+ export declare function resolveStrokes(strokes: readonly Stroke[] | null | undefined, matcher: StrokeMatcher): ResolvedStroke[];
137
+ /** One thing wrong with a card's strokes. @experimental */
138
+ export interface StrokeFinding {
139
+ /** e.g. `strokes[3].when.keys[0]` */
140
+ path: string;
141
+ message: string;
142
+ }
143
+ /**
144
+ * A card's strokes against the shape and `STROKE_LIMITS`. Empty means fine.
145
+ *
146
+ * ⚠ A `regex` key is not compiled here: whether a pattern is refused is the
147
+ * host matcher's call (the same check a lorebook entry's key gets at save).
148
+ * @experimental
149
+ */
150
+ export declare function validateStrokes(strokes: unknown): StrokeFinding[];
151
+ /**
152
+ * A slug from a label: lower-cased, accents dropped, everything else a dash,
153
+ * 64 at most. `'stroke'` when nothing survives — a label of punctuation still
154
+ * needs a key.
155
+ * @experimental
156
+ */
157
+ export declare function strokeSlugFor(label: string): string;
158
+ /** How "Split into strokes" cuts a field. @experimental */
159
+ export type StrokeSplitBy = 'paragraph' | 'sentence' | 'plist';
160
+ /**
161
+ * Cut one field's prose into strokes — the explicit "Split into strokes"
162
+ * action. Every stroke comes back `always`, in order.
163
+ *
164
+ * - `paragraph` — on blank lines.
165
+ * - `sentence` — on sentence ends and line breaks.
166
+ * - `plist` — `[Key: value; Key2: value]` and `Key: value;` segments, split
167
+ * on `;`, line breaks and brackets. A segment with a key becomes a labelled
168
+ * stroke with a slug from the label (deduplicated `-2`, `-3`…); one
169
+ * without stays a bare stroke.
170
+ *
171
+ * Pure: the form previews the result and nothing is saved until a person
172
+ * saves it.
173
+ * @experimental
174
+ */
175
+ export declare function splitIntoStrokes(text: string, kind: StrokeKind, by: StrokeSplitBy): Stroke[];
176
+ //# sourceMappingURL=strokes.d.ts.map
@@ -0,0 +1,281 @@
1
+ /**
2
+ * Card strokes — a character's description and personality as an ordered list
3
+ * of small pieces of prose ("a card is painted in strokes").
4
+ *
5
+ * ⏸ Paused 2026-10-11 (owner): no core spec places this step and the app hides strokes behind `STROKES_ENABLED`; kept so stored documents and the registry hash stay stable.
6
+ *
7
+ * ## What a stroke is
8
+ *
9
+ * One piece of a card's prose: which field it belongs to (`kind`), an optional
10
+ * `label` a person reads ("Eyes"), an optional `slug` a template addresses it
11
+ * by (`character.strokes.eyes`), the `text`, and **one** condition — `when`.
12
+ * Array order is position. A card with no strokes is the legacy shape and its
13
+ * prose columns are the truth; a card with strokes has its `description` and
14
+ * `personality` compiled from them (`compileStrokes`), so every existing
15
+ * template, embedding and export keeps reading four plain fields.
16
+ *
17
+ * ## What a stroke is NOT
18
+ *
19
+ * · **Not a lorebook entry.** A stroke lives on the card and leaves with it; it
20
+ * has no priority, no weight, no budget, no ranker. A keyword stroke is
21
+ * marked `fired` or not against the recent transcript (`resolveStrokes`, run
22
+ * by `core:task/card-strokes@1`) and that is the whole of its life — it never
23
+ * competes with lore for room, and nothing here ranks one stroke over another.
24
+ * · **Not a matcher.** The SDK never matches keywords. The host owns the one
25
+ * keyword matcher (match modes, the regex time limit, the refused-pattern
26
+ * check) and hands it to `resolveStrokes`; the shape here is what it is
27
+ * asked about.
28
+ * · **Not an import transform.** Nothing explodes a card's prose into strokes
29
+ * behind a person's back: `splitIntoStrokes` is the explicit "Split into
30
+ * strokes" action, previewed before anything is saved.
31
+ *
32
+ * `when` is the only condition language. A fourth mode (a predicate over
33
+ * state) is planned under `when`; the shape does not block it.
34
+ */
35
+ /** @experimental */
36
+ export const STROKE_KINDS = Object.freeze(['description', 'personality']);
37
+ /** @experimental */
38
+ export const STROKE_MATCH_MODES = Object.freeze([
39
+ 'substring',
40
+ 'word',
41
+ 'regex',
42
+ ]);
43
+ /** The caps a card's strokes are held to, at save and at import. @experimental */
44
+ export const STROKE_LIMITS = Object.freeze({
45
+ maxStrokes: 200,
46
+ maxTextChars: 4000,
47
+ maxKeys: 32,
48
+ maxKeyChars: 120,
49
+ maxLabelChars: 80,
50
+ });
51
+ /** A stroke slug — the attributes rule: lower-case, digits and dashes, 64 at most. @experimental */
52
+ export const STROKE_SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
53
+ // ── Compile ─────────────────────────────────────────────────────────────────
54
+ /** `Label: text`, or the bare text. Empty after trimming is nothing. */
55
+ const pieceOf = (s) => {
56
+ const text = typeof s.text === 'string' ? s.text.trim() : '';
57
+ if (!text)
58
+ return null;
59
+ const label = typeof s.label === 'string' ? s.label.trim() : '';
60
+ return label ? { text: `${label}: ${text}`, labelled: true } : { text, labelled: false };
61
+ };
62
+ /**
63
+ * One card field compiled from its strokes — the ONE join rule.
64
+ *
65
+ * A labelled stroke is `Label: text`, an unlabelled one its bare text.
66
+ * Description strokes are joined by a blank line. Personality strokes are
67
+ * joined by `; ` when any compiled one has a label (PList-shaped), else by a
68
+ * newline. `off` strokes never compile. `null` when nothing does — the card
69
+ * then has no such field, which is what `compileCharacter` already does with
70
+ * an empty one.
71
+ * @experimental
72
+ */
73
+ export function compileStrokes(strokes, kind, opts = {}) {
74
+ if (!Array.isArray(strokes))
75
+ return null;
76
+ const pieces = [];
77
+ for (const s of strokes) {
78
+ if (!s || s.kind !== kind)
79
+ continue;
80
+ const mode = s.when?.mode;
81
+ if (mode === 'off')
82
+ continue;
83
+ if (mode === 'keywords' && opts.firedOnly && s.fired !== true)
84
+ continue;
85
+ const piece = pieceOf(s);
86
+ if (piece)
87
+ pieces.push(piece);
88
+ }
89
+ if (!pieces.length)
90
+ return null;
91
+ const sep = kind === 'description' ? '\n\n' : pieces.some((p) => p.labelled) ? '; ' : '\n';
92
+ return pieces.map((p) => p.text).join(sep);
93
+ }
94
+ /**
95
+ * Stamp `fired` on every stroke — what `core:task/card-strokes@1` does to each
96
+ * card in the cast. Order is kept, nothing is dropped, nothing is ranked:
97
+ * `always` → true, `off` → false, `keywords` → the matcher's answer. A matcher
98
+ * that throws leaves that stroke unfired rather than failing the turn.
99
+ * @experimental
100
+ */
101
+ export function resolveStrokes(strokes, matcher) {
102
+ if (!Array.isArray(strokes))
103
+ return [];
104
+ return strokes.map((s) => {
105
+ const when = s.when;
106
+ let fired;
107
+ if (when?.mode === 'always')
108
+ fired = true;
109
+ else if (when?.mode === 'keywords') {
110
+ try {
111
+ fired = when.keys.length > 0 && matcher(when) === true;
112
+ }
113
+ catch {
114
+ fired = false;
115
+ }
116
+ }
117
+ else
118
+ fired = false;
119
+ return { ...s, fired };
120
+ });
121
+ }
122
+ const isObj = (v) => !!v && typeof v === 'object' && !Array.isArray(v);
123
+ /**
124
+ * A card's strokes against the shape and `STROKE_LIMITS`. Empty means fine.
125
+ *
126
+ * ⚠ A `regex` key is not compiled here: whether a pattern is refused is the
127
+ * host matcher's call (the same check a lorebook entry's key gets at save).
128
+ * @experimental
129
+ */
130
+ export function validateStrokes(strokes) {
131
+ const out = [];
132
+ if (!Array.isArray(strokes))
133
+ return [{ path: 'strokes', message: 'strokes are a list' }];
134
+ const L = STROKE_LIMITS;
135
+ if (strokes.length > L.maxStrokes)
136
+ out.push({
137
+ path: 'strokes',
138
+ message: `a card holds at most ${L.maxStrokes} strokes; this one has ${strokes.length}`,
139
+ });
140
+ const slugs = new Map();
141
+ strokes.forEach((s, i) => {
142
+ const at = `strokes[${i}]`;
143
+ if (!isObj(s)) {
144
+ out.push({ path: at, message: 'a stroke is an object' });
145
+ return;
146
+ }
147
+ if (!STROKE_KINDS.includes(s.kind))
148
+ out.push({ path: `${at}.kind`, message: `kind is one of ${STROKE_KINDS.join(', ')}` });
149
+ if (s.slug !== undefined) {
150
+ if (typeof s.slug !== 'string' || !STROKE_SLUG.test(s.slug))
151
+ out.push({
152
+ path: `${at}.slug`,
153
+ message: 'a slug is lower-case letters, digits and dashes, starting with a letter or digit, 64 at most',
154
+ });
155
+ else if (slugs.has(s.slug))
156
+ out.push({
157
+ path: `${at}.slug`,
158
+ message: `slug '${s.slug}' is already used by strokes[${slugs.get(s.slug)}] — a slug is unique per card`,
159
+ });
160
+ else
161
+ slugs.set(s.slug, i);
162
+ }
163
+ if (s.label !== undefined) {
164
+ if (typeof s.label !== 'string')
165
+ out.push({ path: `${at}.label`, message: 'a label is text' });
166
+ else if (s.label.length > L.maxLabelChars)
167
+ out.push({ path: `${at}.label`, message: `a label is at most ${L.maxLabelChars} characters` });
168
+ }
169
+ if (typeof s.text !== 'string' || !s.text.trim())
170
+ out.push({ path: `${at}.text`, message: 'a stroke needs text' });
171
+ else if (s.text.length > L.maxTextChars)
172
+ out.push({
173
+ path: `${at}.text`,
174
+ message: `a stroke is at most ${L.maxTextChars} characters; this one has ${s.text.length}`,
175
+ });
176
+ const when = s.when;
177
+ if (!isObj(when)) {
178
+ out.push({ path: `${at}.when`, message: "when is { mode: 'always' | 'off' | 'keywords' }" });
179
+ return;
180
+ }
181
+ if (when.mode === 'always' || when.mode === 'off')
182
+ return;
183
+ if (when.mode !== 'keywords') {
184
+ out.push({ path: `${at}.when.mode`, message: "mode is 'always', 'off' or 'keywords'" });
185
+ return;
186
+ }
187
+ if (!Array.isArray(when.keys) || when.keys.length === 0)
188
+ out.push({ path: `${at}.when.keys`, message: 'a keyword stroke needs at least one key' });
189
+ else {
190
+ if (when.keys.length > L.maxKeys)
191
+ out.push({ path: `${at}.when.keys`, message: `a stroke has at most ${L.maxKeys} keys` });
192
+ when.keys.forEach((k, j) => {
193
+ if (typeof k !== 'string' || !k.trim())
194
+ out.push({ path: `${at}.when.keys[${j}]`, message: 'a key is non-empty text' });
195
+ else if (k.length > L.maxKeyChars)
196
+ out.push({ path: `${at}.when.keys[${j}]`, message: `a key is at most ${L.maxKeyChars} characters` });
197
+ });
198
+ }
199
+ if (when.matchMode !== undefined && !STROKE_MATCH_MODES.includes(when.matchMode))
200
+ out.push({ path: `${at}.when.matchMode`, message: `matchMode is one of ${STROKE_MATCH_MODES.join(', ')}` });
201
+ if (when.caseSensitive !== undefined && typeof when.caseSensitive !== 'boolean')
202
+ out.push({ path: `${at}.when.caseSensitive`, message: 'caseSensitive is true or false' });
203
+ });
204
+ return out;
205
+ }
206
+ // ── Split ───────────────────────────────────────────────────────────────────
207
+ /**
208
+ * A slug from a label: lower-cased, accents dropped, everything else a dash,
209
+ * 64 at most. `'stroke'` when nothing survives — a label of punctuation still
210
+ * needs a key.
211
+ * @experimental
212
+ */
213
+ export function strokeSlugFor(label) {
214
+ const s = String(label ?? '')
215
+ .normalize('NFKD')
216
+ .replace(/[̀-ͯ]/g, '')
217
+ .toLowerCase()
218
+ .replace(/[^a-z0-9]+/g, '-')
219
+ .replace(/^-+|-+$/g, '')
220
+ .slice(0, 64)
221
+ .replace(/-+$/g, '');
222
+ return s || 'stroke';
223
+ }
224
+ const paragraphsOf = (text) => text
225
+ .split(/\r?\n[ \t]*\r?\n/)
226
+ .map((p) => p.trim())
227
+ .filter(Boolean);
228
+ /** Sentences end at `.`, `!`, `?` or `…` (closing quotes and brackets kept), or at a line break. */
229
+ const sentencesOf = (text) => text
230
+ .split(/\r?\n/)
231
+ .flatMap((line) => line.match(/[^.!?…]+(?:[.!?…]+["'”’)\]]*|$)|[.!?…]+/g) ?? [])
232
+ .map((s) => s.trim())
233
+ .filter(Boolean);
234
+ /** `Key: value` — a label is a short run with no sentence punctuation before the first colon. */
235
+ const PLIST_PAIR = /^([^:.!?\n]{1,80}?)\s*:\s*([\s\S]+)$/;
236
+ /**
237
+ * Cut one field's prose into strokes — the explicit "Split into strokes"
238
+ * action. Every stroke comes back `always`, in order.
239
+ *
240
+ * - `paragraph` — on blank lines.
241
+ * - `sentence` — on sentence ends and line breaks.
242
+ * - `plist` — `[Key: value; Key2: value]` and `Key: value;` segments, split
243
+ * on `;`, line breaks and brackets. A segment with a key becomes a labelled
244
+ * stroke with a slug from the label (deduplicated `-2`, `-3`…); one
245
+ * without stays a bare stroke.
246
+ *
247
+ * Pure: the form previews the result and nothing is saved until a person
248
+ * saves it.
249
+ * @experimental
250
+ */
251
+ export function splitIntoStrokes(text, kind, by) {
252
+ const src = typeof text === 'string' ? text : '';
253
+ if (by === 'paragraph')
254
+ return paragraphsOf(src).map((t) => ({ kind, text: t, when: { mode: 'always' } }));
255
+ if (by === 'sentence')
256
+ return sentencesOf(src).map((t) => ({ kind, text: t, when: { mode: 'always' } }));
257
+ const used = new Set();
258
+ const out = [];
259
+ for (const raw of src.split(/[;\n[\]]/)) {
260
+ const seg = raw.trim();
261
+ if (!seg)
262
+ continue;
263
+ const m = PLIST_PAIR.exec(seg);
264
+ const label = m?.[1]?.trim();
265
+ const value = m?.[2]?.trim();
266
+ if (!label || !value) {
267
+ out.push({ kind, text: seg, when: { mode: 'always' } });
268
+ continue;
269
+ }
270
+ const base = strokeSlugFor(label);
271
+ let slug = base;
272
+ for (let n = 2; used.has(slug); n++) {
273
+ const suffix = `-${n}`;
274
+ slug = `${base.slice(0, 64 - suffix.length).replace(/-+$/, '')}${suffix}`;
275
+ }
276
+ used.add(slug);
277
+ out.push({ kind, slug, label, text: value, when: { mode: 'always' } });
278
+ }
279
+ return out;
280
+ }
281
+ //# sourceMappingURL=strokes.js.map