@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
package/dist/status.js ADDED
@@ -0,0 +1,125 @@
1
+ /**
2
+ * Statuses (plans/29 R-19, R-21; 09-B B11) — what a node says it is doing,
3
+ * from inside its execution.
4
+ *
5
+ * `ctx.status({ i18n, vars })` is callable at any point, by any kind: a query
6
+ * says *{speaker} is thinking*, the oracle five nodes later says *{speaker} is
7
+ * typing*. It is **ephemeral** — never a parameter, never declared on a
8
+ * definition, never a node row on the receipt (F34) — and it persists until
9
+ * the next status or the run's end. The one exception R-21 took: the **last**
10
+ * status is recorded on the receipt when a run ends `halt`, `err` or
11
+ * `cancelled`, because "what was it doing when it died" is a question the
12
+ * receipt should answer.
13
+ *
14
+ * Text is display text with variables — a string, or a locale map (R-20);
15
+ * the CLIENT resolves the locale, so a handler never sees a language. `{speaker}` is the one variable the HOST
16
+ * fills — see `HOST_FILLED_STATUS_VARS` — because a handler is blind to who
17
+ * is speaking and must stay so.
18
+ *
19
+ * ⚠ Not HTTP's `statusText` (a reason phrase beside a code) and not a run's
20
+ * *outcome* (`ok · halt · err · cancelled`): a status is prose about progress,
21
+ * and it decides nothing.
22
+ */
23
+ import { i18nText, isI18n, localeMapOf } from './i18n.js';
24
+ /**
25
+ * The variables a host fills, by name, when a status's text mentions them and
26
+ * the handler did not supply a value. One entry: `speaker` — the display name
27
+ * of the run's speaker (a character's or an envoy's), which the handler cannot
28
+ * know and the host always can. A text naming `{speaker}` on a run with no
29
+ * speaker keeps the variable unset; see `renderStatusText` for what a reader
30
+ * sees then.
31
+ * @experimental
32
+ */
33
+ export const HOST_FILLED_STATUS_VARS = ['speaker'];
34
+ /** `{name}` — one variable placeholder, as every locale of a status spells it. */
35
+ const VAR_PATTERN = /\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
36
+ /**
37
+ * Is this a status a run can carry? `i18n` is display text a publish accepts
38
+ * (R-20): a non-blank string, or a locale map whose `en` is non-blank. The
39
+ * executor drops a status that is not, with a note on the receipt — a status
40
+ * is advisory and never halts a run.
41
+ * @internal
42
+ */
43
+ export function isStatusText(value) {
44
+ if (!value || typeof value !== 'object')
45
+ return false;
46
+ return isI18n(value.i18n);
47
+ }
48
+ /** The variable names a status's text mentions, across every locale it carries. @internal */
49
+ export function statusVarsMentioned(text) {
50
+ const names = new Set();
51
+ for (const template of Object.values(localeMapOf(text.i18n))) {
52
+ if (typeof template !== 'string')
53
+ continue;
54
+ for (const m of template.matchAll(VAR_PATTERN))
55
+ names.add(m[1]);
56
+ }
57
+ return [...names];
58
+ }
59
+ /**
60
+ * A status with the given variables filled in — for every name the text
61
+ * mentions that its own `vars` does not already set. The text's own values
62
+ * win: a handler that supplied a value said what it meant.
63
+ *
64
+ * Returns the same object when nothing changes, so a caller can dedupe by
65
+ * identity as well as by content.
66
+ * @internal
67
+ */
68
+ export function fillStatusVars(text, values) {
69
+ const mentioned = statusVarsMentioned(text);
70
+ const added = {};
71
+ for (const name of mentioned) {
72
+ if (text.vars && name in text.vars)
73
+ continue;
74
+ const v = values[name];
75
+ if (v === undefined)
76
+ continue;
77
+ added[name] = v;
78
+ }
79
+ if (Object.keys(added).length === 0)
80
+ return text;
81
+ return { ...text, vars: { ...(text.vars ?? {}), ...added } };
82
+ }
83
+ /**
84
+ * The status as a person reads it: the requested locale, else `en`, with
85
+ * every `{var}` the text sets substituted. A variable the text mentions and
86
+ * nobody filled stays as written — a visible `{speaker}` mid-sentence is a
87
+ * defect a reader can report — EXCEPT a leading `{speaker} `, which is
88
+ * dropped rather than shown literally: a run with nobody to name (a
89
+ * summarize, a graph build) leaves `speaker` unset by design, and "is
90
+ * thinking" reads fine with nobody named. An empty gap elsewhere is one
91
+ * nobody would notice.
92
+ * @internal
93
+ */
94
+ export function renderStatusText(text, language = 'en') {
95
+ const template = i18nText(text.i18n, language) ?? '';
96
+ const vars = text.vars ?? {};
97
+ const withoutUnfilledSpeaker = !('speaker' in vars) && template.startsWith('{speaker} ')
98
+ ? template.slice('{speaker} '.length)
99
+ : template;
100
+ return withoutUnfilledSpeaker.replace(VAR_PATTERN, (whole, name) => name in vars ? String(vars[name]) : whole);
101
+ }
102
+ /** Two statuses that would render identically in every locale. @internal */
103
+ export function sameStatus(a, b) {
104
+ if (a === b)
105
+ return true;
106
+ if (!a || !b)
107
+ return false;
108
+ return sameLocaleMap(localeMapOf(a.i18n), localeMapOf(b.i18n)) && sameVars(a.vars, b.vars);
109
+ }
110
+ /** Same locale map — order-independent, like `sameVars` (a rebuilt object must still match). */
111
+ function sameLocaleMap(a, b) {
112
+ const ka = Object.keys(a).sort();
113
+ const kb = Object.keys(b).sort();
114
+ if (ka.length !== kb.length)
115
+ return false;
116
+ return ka.every((k, i) => k === kb[i] && a[k] === b[k]);
117
+ }
118
+ function sameVars(a, b) {
119
+ const ka = Object.keys(a ?? {}).sort();
120
+ const kb = Object.keys(b ?? {}).sort();
121
+ if (ka.length !== kb.length)
122
+ return false;
123
+ return ka.every((k, i) => k === kb[i] && a[k] === b[k]);
124
+ }
125
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1,145 @@
1
+ /**
2
+ * What an extension may do with its own data (13 §7c).
3
+ *
4
+ * The surface this replaces was `readOwnRows` / `writeOwnRows` and nothing
5
+ * else, which composed into a one-way door: a quota was declared in the
6
+ * manifest (`storage.quotaBytes`), writes returned `void` so exceeding it was
7
+ * either an undocumented throw or a silent drop, and there was **no delete at
8
+ * all**. An extension that filled its quota could neither find out nor recover.
9
+ *
10
+ * Three things fix that, and they are the three the API now has: usage is
11
+ * *askable*, writes *report*, and everything that can be created can be
12
+ * removed.
13
+ *
14
+ * ## Rows and files are separate on purpose
15
+ *
16
+ * Rows are small, queryable and live in the database with the rest of the
17
+ * instance's state — they back up with it and restore with it. Files are bytes
18
+ * on disk, jailed to the extension's own directory, for the things a row is the
19
+ * wrong home for (a downloaded model index, a cache, a generated artifact).
20
+ * Merging them would mean either putting megabytes in the database or putting
21
+ * queryable state outside the backup.
22
+ *
23
+ * **Both count against one quota.** A single number is what an author can
24
+ * reason about and what a consent screen can state; two budgets that can each
25
+ * be under while the disk fills is the failure this avoids.
26
+ */
27
+ import type { Result } from './executor.js';
28
+ /** @experimental */
29
+ export interface StorageUsage {
30
+ /** The ceiling, from the manifest's `storage.quotaBytes`. */
31
+ quotaBytes: number;
32
+ /** Rows plus files, as currently stored. */
33
+ usedBytes: number;
34
+ /** `quotaBytes - usedBytes`, floored at zero — precomputed because every
35
+ * caller wants it and a subtraction is where an off-by-one lives. */
36
+ availableBytes: number;
37
+ /** The split, for an extension that wants to know which half to prune. */
38
+ rowBytes: number;
39
+ fileBytes: number;
40
+ }
41
+ /**
42
+ * What a write reports back.
43
+ *
44
+ * A write that would exceed the quota returns `err` — it does not throw, and it
45
+ * does not partially apply. The usage figures come back either way so a caller
46
+ * can prune and retry without a second round trip.
47
+ * @experimental
48
+ */
49
+ export interface WriteReceipt {
50
+ /** Bytes this write added (negative when it replaced something larger). */
51
+ deltaBytes: number;
52
+ usage: StorageUsage;
53
+ }
54
+ /**
55
+ * A row query, deliberately small.
56
+ *
57
+ * This is key-prefix and time filtering with a cursor, not a query language.
58
+ * An extension needing joins or secondary indexes wants its own tables, which
59
+ * is a different (and much bigger) conversation than "let a plugin keep some
60
+ * state" — and a query language here would become a compatibility surface no
61
+ * one can change.
62
+ * @experimental
63
+ */
64
+ export interface RowQuery {
65
+ /** Keys starting with this. Absent means every key. */
66
+ prefix?: string;
67
+ /** Written at or after this ISO timestamp. */
68
+ since?: string;
69
+ /** Written before this ISO timestamp. */
70
+ until?: string;
71
+ /** Page size. The host clamps it; ask for what you want. */
72
+ limit?: number;
73
+ /** From a previous page's `nextCursor`. */
74
+ cursor?: string;
75
+ /** Newest first by default — the order a log or a cache wants. */
76
+ order?: 'newest' | 'oldest' | 'key';
77
+ }
78
+ /** @experimental */
79
+ export interface RowEntry<T = unknown> {
80
+ key: string;
81
+ value: T;
82
+ bytes: number;
83
+ /** ISO. */
84
+ updatedAt: string;
85
+ }
86
+ /** @experimental */
87
+ export interface RowPage<T = unknown> {
88
+ rows: RowEntry<T>[];
89
+ /** Absent when this was the last page. */
90
+ nextCursor?: string;
91
+ }
92
+ /** @experimental */
93
+ export interface FileEntry {
94
+ /** Relative to the extension's own directory. Never absolute, never
95
+ * escaping it — the host rejects `..` rather than normalising it. */
96
+ path: string;
97
+ bytes: number;
98
+ /** ISO. */
99
+ updatedAt: string;
100
+ }
101
+ /**
102
+ * The extension's own directory on disk.
103
+ *
104
+ * Jailed the same way plugin storage and media already are: paths are relative,
105
+ * containment is asserted by the host, and nothing an extension supplies
106
+ * reaches a filesystem call unchecked.
107
+ * @experimental
108
+ */
109
+ export interface ExtensionFiles {
110
+ list(prefix?: string): Promise<FileEntry[]>;
111
+ stat(path: string): Promise<FileEntry | null>;
112
+ read(path: string): Promise<Result<Uint8Array>>;
113
+ write(path: string, bytes: Uint8Array): Promise<Result<WriteReceipt>>;
114
+ delete(path: string): Promise<Result<WriteReceipt>>;
115
+ /** Everything under a prefix. Returns how many were removed. */
116
+ deleteAll(prefix?: string): Promise<Result<{
117
+ removed: number;
118
+ usage: StorageUsage;
119
+ }>>;
120
+ }
121
+ /** @experimental */
122
+ export interface ExtensionStorage {
123
+ /** Ask, at any time. Cheap enough to call before a large write. */
124
+ usage(): Promise<StorageUsage>;
125
+ get<T = unknown>(key: string): Promise<T | undefined>;
126
+ /** Keys only — for an extension that wants to enumerate before reading. */
127
+ keys(prefix?: string): Promise<string[]>;
128
+ query<T = unknown>(q?: RowQuery): Promise<RowPage<T>>;
129
+ put(key: string, value: unknown): Promise<Result<WriteReceipt>>;
130
+ delete(key: string): Promise<Result<WriteReceipt>>;
131
+ /** Everything under a prefix — the "get back under quota" and the
132
+ * "clean up after myself on uninstall" operation. */
133
+ deleteAll(prefix?: string): Promise<Result<{
134
+ removed: number;
135
+ usage: StorageUsage;
136
+ }>>;
137
+ files: ExtensionFiles;
138
+ }
139
+ /** Nothing here reaches outside the extension's own namespace, so there is no
140
+ * capability to grant and nothing to put on a consent screen: an extension
141
+ * managing its own rows is not a permission, it is housekeeping.
142
+ * @experimental
143
+ */
144
+ export declare const STORAGE_IS_UNPRIVILEGED: true;
145
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1,33 @@
1
+ /**
2
+ * What an extension may do with its own data (13 §7c).
3
+ *
4
+ * The surface this replaces was `readOwnRows` / `writeOwnRows` and nothing
5
+ * else, which composed into a one-way door: a quota was declared in the
6
+ * manifest (`storage.quotaBytes`), writes returned `void` so exceeding it was
7
+ * either an undocumented throw or a silent drop, and there was **no delete at
8
+ * all**. An extension that filled its quota could neither find out nor recover.
9
+ *
10
+ * Three things fix that, and they are the three the API now has: usage is
11
+ * *askable*, writes *report*, and everything that can be created can be
12
+ * removed.
13
+ *
14
+ * ## Rows and files are separate on purpose
15
+ *
16
+ * Rows are small, queryable and live in the database with the rest of the
17
+ * instance's state — they back up with it and restore with it. Files are bytes
18
+ * on disk, jailed to the extension's own directory, for the things a row is the
19
+ * wrong home for (a downloaded model index, a cache, a generated artifact).
20
+ * Merging them would mean either putting megabytes in the database or putting
21
+ * queryable state outside the backup.
22
+ *
23
+ * **Both count against one quota.** A single number is what an author can
24
+ * reason about and what a consent screen can state; two budgets that can each
25
+ * be under while the disk fills is the failure this avoids.
26
+ */
27
+ /** Nothing here reaches outside the extension's own namespace, so there is no
28
+ * capability to grant and nothing to put on a consent screen: an extension
29
+ * managing its own rows is not a permission, it is housekeeping.
30
+ * @experimental
31
+ */
32
+ export const STORAGE_IS_UNPRIVILEGED = true;
33
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1,308 @@
1
+ /**
2
+ * Story time as a stored value — the free-form rung of the story calendar.
3
+ *
4
+ * A **story time** is a position on a book's own calendar: a year, and
5
+ * optionally a month, a day and a time of day. It is what a clock/date stat
6
+ * (`core:stat-shape/story-time@1`) holds, and what a birthdate slot is read
7
+ * as when age is derived.
8
+ *
9
+ * ## Why text, and why this one spelling
10
+ *
11
+ * A stored attribute value is a scalar (`SlotScalar`), so a story time is
12
+ * stored as one canonical line — `412-03-05 22:30` — and parsed back into its
13
+ * parts wherever it is read. The spelling is the one the host already read
14
+ * birthdates in (`412`, `412-03`, `412-03-05`), with a time of day added.
15
+ *
16
+ * Parts, validated beyond shape only against a book's **declared calendar**
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
19
+ * **instant** once a book has a real calendar; when that rung is built the
20
+ * shape moves to `@2` rather than reinterpreting what `@1` stored.
21
+ *
22
+ * ## One comparator
23
+ *
24
+ * `compareStoryTimes` is THE ordering of story times — element-wise, so it is
25
+ * correct for any magnitude (a book numbering "day 250 of year 3" is ordinary
26
+ * free-form practice) and for negative years. Never pack the parts into one
27
+ * number to sort on: a radix packing collides once a part passes its radix,
28
+ * which is the bug the host's `compareDates` was rewritten to fix. The host's
29
+ * lorebook dates delegate here, so one calendar has one comparator.
30
+ */
31
+ /** A position on the story calendar. An absent part is one the author did not give. @experimental */
32
+ export interface StoryTime {
33
+ year: number;
34
+ month?: number | null;
35
+ day?: number | null;
36
+ /** 0–23. */
37
+ hour?: number | null;
38
+ /** 0–59; read only beside an hour. */
39
+ minute?: number | null;
40
+ }
41
+ /**
42
+ * The range each part of a story time takes on EVERY rung of the calendar —
43
+ * the free-form rule, and the one validity definition for a stored date.
44
+ *
45
+ * A declared calendar only ever narrows it (month count, month lengths, the
46
+ * leap day — `storyTimeProblem`); nothing widens it. `parseStoryTime`,
47
+ * `storyTimeProblem` and core's history entry type all read these, and the
48
+ * 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
+ * a copied 1–12 / 1–31 once refused month 13 of a thirteen-month calendar and
51
+ * the day after a free-form day 31).
52
+ *
53
+ * ⚠ **Month and day have a floor and no ceiling, on purpose.** A free-form
54
+ * book numbers days of the year ("Year 3, day 250") and may count as many
55
+ * months as it likes; a declared calendar may have any number of months of up
56
+ * to 1000 days each. Those are facts about ONE book, checked against its
57
+ * calendar at entry — never a bound on every book. Zero is refused because it
58
+ * is what an absent part packs to. The year has no range at all: it is one
59
+ * signed count, negative before year 1.
60
+ *
61
+ * Not the calendar's own limits (`storyCalendarProblems`: a month's LENGTH is
62
+ * 1–1000 days) — those bound a calendar's shape, not a date. And ranges only:
63
+ * the narrowing rule (a day needs a month, a minute needs an hour) is
64
+ * `storyTimeProblem`'s, which reads these for every part and is the check
65
+ * every dated writer answers with.
66
+ * @experimental
67
+ */
68
+ export declare const STORY_TIME_PART_RANGES: {
69
+ readonly month: {
70
+ readonly min: 1;
71
+ };
72
+ readonly day: {
73
+ readonly min: 1;
74
+ };
75
+ readonly hour: {
76
+ readonly min: 0;
77
+ readonly max: 23;
78
+ };
79
+ readonly minute: {
80
+ readonly min: 0;
81
+ readonly max: 59;
82
+ };
83
+ };
84
+ /**
85
+ * The story time a stored value spells, or `null` when it spells none.
86
+ *
87
+ * A number is a bare year (the oldest spelling a birthdate was ever typed
88
+ * in); a string is the canonical line, trimmed. Anything else — and a month,
89
+ * day, hour or minute out of its range — is not a story time.
90
+ * @experimental
91
+ */
92
+ export declare function parseStoryTime(value: unknown): StoryTime | null;
93
+ /**
94
+ * The canonical line a story time is stored as — `412-03-05 22:30`.
95
+ *
96
+ * A day is only spelled beside a month (`412--05` is not a line anybody could
97
+ * read back), and a minute only beside an hour.
98
+ * @experimental
99
+ */
100
+ export declare function storyTimeText(time: StoryTime): string;
101
+ /**
102
+ * Which of two story times comes first — **the ordering key; sort with this.**
103
+ *
104
+ * Element-wise. An absent month or day is 0 and an absent hour or minute is
105
+ * -1, so each sorts BEFORE a present one: "Year 2" is the whole year and
106
+ * comes before "Year 2, Mo. 5" inside it, and a date with no time comes
107
+ * before midnight on it.
108
+ * @experimental
109
+ */
110
+ export declare function compareStoryTimes(a: StoryTime, b: StoryTime): number;
111
+ /**
112
+ * A story time as a person reads it.
113
+ *
114
+ * With no calendar — **free-form**, the bottom rung and every book's default —
115
+ * `Year 412, Mo. 3, Day 5, 22:30`, exactly today's spelling (the story-time
116
+ * design's open decision #4, non-negotiable). With a declared calendar the same
117
+ * parts are spelled through it: `Moonday, 5 Thaw, Year 412 AR, 22:30`.
118
+ *
119
+ * ⚠ A date the calendar cannot place (month 13 of twelve) is spelled
120
+ * free-form rather than guessed at. Dates are validated at entry once a book
121
+ * declares a calendar, so this is the fallback for a row that predates it,
122
+ * never an ordinary path.
123
+ * @experimental
124
+ */
125
+ export declare function formatStoryTime(time: StoryTime, calendar?: StoryCalendar | null): string;
126
+ /**
127
+ * One month of a declared story calendar, in order.
128
+ * @experimental
129
+ */
130
+ export interface StoryMonth {
131
+ name: string;
132
+ /** Its length in an ordinary year. */
133
+ days: number;
134
+ }
135
+ /**
136
+ * How a year is spelled from a point on: `AR` from year 1, `BR` before it.
137
+ *
138
+ * ⚠ **An era is a spelling, never an ordering.** The stored year is one
139
+ * continuous count (year 0 is the year before year 1, -299 three hundred
140
+ * before that); an era only decides how that count is written. So changing
141
+ * an era re-labels every date and moves none.
142
+ * @experimental
143
+ */
144
+ export interface StoryEra {
145
+ name: string;
146
+ /** The first stored year it spells. `null` only for the first era: every year before the next one. */
147
+ start: number | null;
148
+ /**
149
+ * Counts DOWN towards the next era's start — `300 BR, 299 BR, … 1 BR`, then
150
+ * the next era. Needs a next era, so the last one can never count down.
151
+ */
152
+ backwards?: boolean;
153
+ }
154
+ /**
155
+ * One extra day in one month, every `every` years (a year divisible by it).
156
+ * @experimental
157
+ */
158
+ export interface StoryLeapRule {
159
+ every: number;
160
+ /** 1-based. */
161
+ month: number;
162
+ }
163
+ /**
164
+ * A book's declared calendar — the rung above free-form.
165
+ *
166
+ * Data, not code: it is stored on the lorebook, exported with it, and edited in
167
+ * the book's settings. `null` wherever a calendar is taken means free-form.
168
+ *
169
+ * ⚠ **A calendar spells and steps; it never orders.** `compareStoryTimes` takes
170
+ * no calendar: with parts validated at entry against month lengths, the
171
+ * element-wise order IS the order of days, so there is still one comparator.
172
+ * @experimental
173
+ */
174
+ export interface StoryCalendar {
175
+ months: StoryMonth[];
176
+ /** Weekday names in order; absent or empty = no week. */
177
+ weekdays?: string[];
178
+ /** Which weekday (0-based) Year 1, month 1, day 1 falls on. Default 0. */
179
+ firstWeekday?: number;
180
+ /** The word before a year number — `Year` when absent; `''` spells the bare number. */
181
+ yearLabel?: string;
182
+ leap?: StoryLeapRule | null;
183
+ /** In order of `start`; absent or empty = the bare year. */
184
+ eras?: StoryEra[];
185
+ }
186
+ /**
187
+ * What is wrong with a calendar, one sentence per fault; empty when nothing is.
188
+ *
189
+ * Refuses rather than repairs: a calendar that silently dropped a nameless
190
+ * month would renumber every month after it.
191
+ * @experimental
192
+ */
193
+ export declare function storyCalendarProblems(calendar: unknown): string[];
194
+ /**
195
+ * A stored calendar value, checked: `null` for free-form, the calendar for a
196
+ * well-formed one, and a thrown error naming every fault otherwise. The copy
197
+ * carries only the declared keys.
198
+ * @experimental
199
+ */
200
+ export declare function parseStoryCalendar(value: unknown): StoryCalendar | null;
201
+ /**
202
+ * How many days a month has in a given year — its length, plus the leap day
203
+ * when the leap rule names it and the year is a leap year.
204
+ * @experimental
205
+ */
206
+ export declare function storyDaysInMonth(year: number, month: number, calendar: StoryCalendar): number;
207
+ /**
208
+ * Why a date does not land in a calendar, or `null` when it does.
209
+ *
210
+ * **Every rung** holds a story time to `STORY_TIME_PART_RANGES` and to the
211
+ * narrowing rule — a day needs a month, a minute needs an hour — so free-form
212
+ * (`null` calendar) takes any whole parts in range and no more. A declared
213
+ * calendar then narrows further: its month count, its month lengths, the leap
214
+ * day. This is the one check every dated writer answers with (history,
215
+ * amendments, fork dates, placements, clocks): one rule, one sentence.
216
+ * @experimental
217
+ */
218
+ export declare function storyTimeProblem(time: StoryTime, calendar: StoryCalendar | null | undefined): string | null;
219
+ /**
220
+ * Days from Year 1, month 1, day 1 to this date — negative before it; `null`
221
+ * without a full date or for one that does not land.
222
+ *
223
+ * ⚠ 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.
225
+ * @experimental
226
+ */
227
+ export declare function storyDayIndex(time: StoryTime, calendar: StoryCalendar): number | null;
228
+ /**
229
+ * The date one step after `from` — what "the next date in sequence" is.
230
+ *
231
+ * The step is one more of the FINEST part given, and precision is kept: a
232
+ * year-and-month date steps a month, a year alone steps a year.
233
+ *
234
+ * - **Free-form** (no calendar): nothing rolls over. Day 31 of month 1 is
235
+ * followed by day 32 of month 1 — a book numbering days of the year is
236
+ * ordinary free-form practice.
237
+ * - **A declared calendar**: a day past its month's length (leap day
238
+ * included) rolls into day 1 of the next month, and a month past the last
239
+ * rolls into month 1 of the next year.
240
+ *
241
+ * Always sorts after `from` under `compareStoryTimes`.
242
+ * @experimental
243
+ */
244
+ export declare function nextStoryTime(from: StoryTime, calendar?: StoryCalendar | null): {
245
+ year: number;
246
+ month: number | null;
247
+ day: number | null;
248
+ };
249
+ /**
250
+ * The date a day index names — the inverse of `storyDayIndex` (Year 1,
251
+ * month 1, day 1 is 0; negative before it).
252
+ * @experimental
253
+ */
254
+ export declare function storyTimeOfDayIndex(index: number, calendar: StoryCalendar): {
255
+ year: number;
256
+ month: number;
257
+ day: number;
258
+ };
259
+ /**
260
+ * What a story clock advances by (DESIGN-story-time §5, `advance(n, unit)`).
261
+ * @experimental
262
+ */
263
+ export type StoryTimeUnit = 'minutes' | 'hours' | 'days' | 'months' | 'years';
264
+ /** @experimental */
265
+ export declare const STORY_TIME_UNITS: readonly StoryTimeUnit[];
266
+ /**
267
+ * An advance's result: the time it lands on, or the sentence refusing it.
268
+ * @experimental
269
+ */
270
+ export type StoryTimeAdvance = {
271
+ time: StoryTime;
272
+ problem?: undefined;
273
+ } | {
274
+ time?: undefined;
275
+ problem: string;
276
+ };
277
+ /**
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.
280
+ *
281
+ * **By a declared calendar** the step carries: minutes into hours into days
282
+ * (a 24-hour day), days through month lengths and the leap day, months into
283
+ * years. **Free-form** has no unit lengths, so a step changes only the part
284
+ * it names — the **smallest-part rule**: forty days on day 31 is day 71 of
285
+ * the same month, and nothing rolls into a month or a year. A time of day
286
+ * carries into the day in both, since a day is always 24 hours.
287
+ *
288
+ * Refused — with a sentence, never clamped — when `by` is not a whole number
289
+ * other than zero (a step of nothing is a silent no-op), when the time has
290
+ * no part for the unit to count (days on a year-only clock; a carry past
291
+ * midnight with no day to carry into), and when the result does not land
292
+ * (Bloom 31 plus a month is Ember 31; before day or month 1 in free-form).
293
+ * A missing time of day reads as the start of the day when stepping by hours
294
+ * or minutes, and stays missing otherwise.
295
+ * @experimental
296
+ */
297
+ export declare function advanceStoryTime(from: StoryTime, by: number, unit: StoryTimeUnit, calendar?: StoryCalendar | null): StoryTimeAdvance;
298
+ /**
299
+ * The presets the calendar editor starts from (DESIGN-story-time P5). Each is
300
+ * an ordinary declared calendar — a starting point, never a live link.
301
+ * @experimental
302
+ */
303
+ export declare const STORY_CALENDAR_PRESETS: ReadonlyArray<{
304
+ id: string;
305
+ name: string;
306
+ calendar: StoryCalendar;
307
+ }>;
308
+ //# sourceMappingURL=storyTime.d.ts.map