@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,128 @@
1
+ /**
2
+ * Migration harness — converting an existing workflow into a pipeline without users
3
+ * losing what they customised (08 §5, U25).
4
+ *
5
+ * The failure this exists to prevent is specific and it is not "the migration crashed."
6
+ * A migration that runs cleanly and quietly changes what the model receives is far worse
7
+ * than one that fails, because nobody finds out for weeks and the symptom — "the bot
8
+ * feels different since the update" — is unfalsifiable.
9
+ *
10
+ * So the acceptance criterion is not "it ran." It is:
11
+ *
12
+ * **for every fixture in the corpus, the legacy engine's prompt and the migrated
13
+ * pipeline's preview payload are byte-identical.**
14
+ *
15
+ * That is checkable because a preview run already produces the exact payload that would
16
+ * be sent, from the same formatter and the same tokenizer as a real run (src/preview.ts).
17
+ * The parity test is the preview, not a second renderer written for the occasion.
18
+ */
19
+ import type { ScopeKind } from './config.js';
20
+ import type { Receipt } from './receipt.js';
21
+ import type { SpecDocument } from './document.js';
22
+ /**
23
+ * A migrated row's slug is derived from where it came from, not generated.
24
+ *
25
+ * This is what makes a migration **idempotent**: re-running after a bug fix matches the
26
+ * existing row by slug and replaces it, instead of creating a second copy beside it
27
+ * (12 §3b). A migration that cannot be safely re-run is a migration nobody dares fix.
28
+ * @experimental
29
+ */
30
+ export declare function migratedSlug(sourceTable: string, sourceId: string | number): string;
31
+ /** @experimental */
32
+ export type MigrationOutcome = 'migrated' | 'unmapped' | 'skipped';
33
+ /** @experimental */
34
+ export interface MigrationEntry {
35
+ source: {
36
+ table: string;
37
+ id: string | number;
38
+ label?: string;
39
+ };
40
+ outcome: MigrationOutcome;
41
+ /** Where the value landed: the scope it was written at, and what it became. */
42
+ target?: {
43
+ slug: string;
44
+ /** A `ScopeKind` (config.ts): `session · config · defaults · author` since R-10. */
45
+ scopeKind: ScopeKind;
46
+ nodeKey?: string;
47
+ slot?: string;
48
+ };
49
+ /** Required whenever the outcome is not `migrated` — never a silent drop. */
50
+ reason?: string;
51
+ }
52
+ /** @experimental */
53
+ export interface MigrationReport {
54
+ unit: string;
55
+ entries: MigrationEntry[];
56
+ /** Fixture-level parity results; empty means nobody checked, which is not the same as passing. */
57
+ parity: ParityResult[];
58
+ }
59
+ /** @experimental */
60
+ export declare function summarize(r: MigrationReport): {
61
+ migrated: number;
62
+ unmapped: number;
63
+ skipped: number;
64
+ parityChecked: number;
65
+ parityFailed: number;
66
+ };
67
+ /**
68
+ * Everything that did not migrate cleanly must say why, and must remain visible —
69
+ * `spec_diagnostics` in core, the same place an orphaned slot lands after a node swap
70
+ * (12 §5). Same principle as export (12 §7a): nothing is dropped silently.
71
+ * @experimental
72
+ */
73
+ export declare function unmappedEntries(r: MigrationReport): MigrationEntry[];
74
+ /** @experimental */
75
+ export declare class MigrationError extends Error {
76
+ }
77
+ /** A report with an entry that gives no reason is a bug in the migration, not in the data. @experimental */
78
+ export declare function assertReportComplete(r: MigrationReport): void;
79
+ /** @internal */
80
+ export interface ParityResult {
81
+ fixture: string;
82
+ identical: boolean;
83
+ /** First divergence, with context — a diff of two multi-kilobyte prompts is unreadable. */
84
+ firstDifferenceAt?: number;
85
+ legacyExcerpt?: string;
86
+ pipelineExcerpt?: string;
87
+ tokensLegacy?: number;
88
+ tokensPipeline?: number;
89
+ }
90
+ /** @internal */
91
+ export declare function checkParity(fixture: string, legacyPrompt: string, preview: Receipt, count?: (v: unknown) => number): ParityResult;
92
+ /**
93
+ * The gate on dropping an old code path (08 §5). Deliberately strict: an empty corpus
94
+ * passes nothing, because "no failures" and "nothing was checked" look identical in a
95
+ * summary and only one of them is safe.
96
+ * @internal
97
+ */
98
+ export declare function parityGate(results: ParityResult[], minimumCorpus?: number): {
99
+ pass: boolean;
100
+ reason?: string;
101
+ };
102
+ /** @internal */
103
+ export declare function renderParity(r: ParityResult): string;
104
+ /**
105
+ * Rewrite a legacy `commit-message@1` node into `create-message@1` or
106
+ * `update-message@1`.
107
+ *
108
+ * The old type decided new-vs-update at runtime from whether an id happened to be
109
+ * present. Migrating it means recovering that decision from the document — and the
110
+ * honest answer is that **it is recoverable in most specs and genuinely ambiguous in a
111
+ * few**. A migration that guesses in the ambiguous case converts a spec that used to
112
+ * update into one that creates, and the user finds out when their chat fills with
113
+ * duplicates.
114
+ *
115
+ * So the rule is: an id wired in (by edge or by config) means update; nothing wired
116
+ * means create; **anything else is reported unmapped rather than decided**. `unmapped`
117
+ * is already the shape 08 §5b uses for "a human has to look at this."
118
+ * @experimental
119
+ */
120
+ export declare const LEGACY_COMMIT_MESSAGE = "core:outlet/commit-message";
121
+ /** @experimental */
122
+ export interface SplitResult {
123
+ document: SpecDocument;
124
+ report: MigrationReport;
125
+ }
126
+ /** @experimental */
127
+ export declare function splitCommitMessage(doc: SpecDocument): SplitResult;
128
+ //# sourceMappingURL=migration.d.ts.map
@@ -0,0 +1,261 @@
1
+ /**
2
+ * Migration harness — converting an existing workflow into a pipeline without users
3
+ * losing what they customised (08 §5, U25).
4
+ *
5
+ * The failure this exists to prevent is specific and it is not "the migration crashed."
6
+ * A migration that runs cleanly and quietly changes what the model receives is far worse
7
+ * than one that fails, because nobody finds out for weeks and the symptom — "the bot
8
+ * feels different since the update" — is unfalsifiable.
9
+ *
10
+ * So the acceptance criterion is not "it ran." It is:
11
+ *
12
+ * **for every fixture in the corpus, the legacy engine's prompt and the migrated
13
+ * pipeline's preview payload are byte-identical.**
14
+ *
15
+ * That is checkable because a preview run already produces the exact payload that would
16
+ * be sent, from the same formatter and the same tokenizer as a real run (src/preview.ts).
17
+ * The parity test is the preview, not a second renderer written for the occasion.
18
+ */
19
+ // ── Deterministic identity, so a migration can be re-run ────────────────────
20
+ /**
21
+ * A migrated row's slug is derived from where it came from, not generated.
22
+ *
23
+ * This is what makes a migration **idempotent**: re-running after a bug fix matches the
24
+ * existing row by slug and replaces it, instead of creating a second copy beside it
25
+ * (12 §3b). A migration that cannot be safely re-run is a migration nobody dares fix.
26
+ * @experimental
27
+ */
28
+ export function migratedSlug(sourceTable, sourceId) {
29
+ const clean = String(sourceId)
30
+ .toLowerCase()
31
+ .replace(/[^a-z0-9]+/g, '-')
32
+ .replace(/^-+|-+$/g, '');
33
+ return `migrated-${sourceTable.replace(/_/g, '-')}-${clean}`;
34
+ }
35
+ /** @experimental */
36
+ export function summarize(r) {
37
+ const by = (o) => r.entries.filter((e) => e.outcome === o).length;
38
+ return {
39
+ migrated: by('migrated'),
40
+ unmapped: by('unmapped'),
41
+ skipped: by('skipped'),
42
+ parityChecked: r.parity.length,
43
+ parityFailed: r.parity.filter((p) => !p.identical).length,
44
+ };
45
+ }
46
+ /**
47
+ * Everything that did not migrate cleanly must say why, and must remain visible —
48
+ * `spec_diagnostics` in core, the same place an orphaned slot lands after a node swap
49
+ * (12 §5). Same principle as export (12 §7a): nothing is dropped silently.
50
+ * @experimental
51
+ */
52
+ export function unmappedEntries(r) {
53
+ return r.entries.filter((e) => e.outcome !== 'migrated');
54
+ }
55
+ /** @experimental */
56
+ export class MigrationError extends Error {
57
+ }
58
+ /** A report with an entry that gives no reason is a bug in the migration, not in the data. @experimental */
59
+ export function assertReportComplete(r) {
60
+ const silent = r.entries.filter((e) => e.outcome !== 'migrated' && !e.reason);
61
+ if (silent.length) {
62
+ throw new MigrationError(`${silent.length} entr${silent.length === 1 ? 'y' : 'ies'} did not migrate and gave no reason ` +
63
+ `(${silent.map((s) => `${s.source.table}#${s.source.id}`).join(', ')}). ` +
64
+ `Every non-migrated row states why, or the user finds out by noticing their config is gone.`);
65
+ }
66
+ }
67
+ const EXCERPT = 60;
68
+ /**
69
+ * Compare what the legacy engine produced against what the migrated pipeline *would*
70
+ * send. The second argument is a **preview receipt** — the run stopped at the pre-call
71
+ * substrate, so this compares the real payload rather than a reimplementation of it.
72
+ */
73
+ /**
74
+ * The text that would actually be sent, out of whatever the context port carried.
75
+ *
76
+ * Three shapes reach here. A Provider with a `wire` slot puts a formed payload on
77
+ * the port, and that may already be a string. Core's Assemble puts an **allocated
78
+ * context** there — blocks plus the rendered string, because the budget panel needs
79
+ * the blocks (16 §7) — so the prompt is one level in. A split-chat connection has
80
+ * `messages` instead of `rendered`, and its comparable form is the role-tagged text.
81
+ *
82
+ * Unwrapping matters more than it looks: the first version compared
83
+ * `JSON.stringify` of the whole allocation against the legacy prompt string. That
84
+ * "diverges at character 0" on every fixture forever — a harness that can never go
85
+ * green is indistinguishable from one whose subject is broken, and it costs a day
86
+ * to tell them apart.
87
+ */
88
+ function renderedText(value) {
89
+ if (typeof value === 'string')
90
+ return value;
91
+ const v = value;
92
+ if (v && typeof v.rendered === 'string')
93
+ return v.rendered;
94
+ if (v && Array.isArray(v.messages))
95
+ return v.messages
96
+ .map((m) => `${m.role ?? ''}: ${m.content ?? ''}`)
97
+ .join('\n');
98
+ if (v && typeof v.prompt === 'string')
99
+ return v.prompt;
100
+ return JSON.stringify(value);
101
+ }
102
+ /** @internal */
103
+ export function checkParity(fixture, legacyPrompt, preview, count) {
104
+ const p = preview.preview;
105
+ if (!p) {
106
+ throw new MigrationError(`parity for '${fixture}' was given a receipt with no preview. Run the migrated pipeline ` +
107
+ `with { preview: true } — comparing against anything else compares a reimplementation.`);
108
+ }
109
+ const pipelinePrompt = renderedText(p.context.rendered);
110
+ if (legacyPrompt === pipelinePrompt) {
111
+ return {
112
+ fixture,
113
+ identical: true,
114
+ tokensLegacy: count?.(legacyPrompt),
115
+ tokensPipeline: p.context.tokens,
116
+ };
117
+ }
118
+ let i = 0;
119
+ while (i < legacyPrompt.length &&
120
+ i < pipelinePrompt.length &&
121
+ legacyPrompt[i] === pipelinePrompt[i])
122
+ i++;
123
+ return {
124
+ fixture,
125
+ identical: false,
126
+ firstDifferenceAt: i,
127
+ legacyExcerpt: legacyPrompt.slice(Math.max(0, i - EXCERPT / 2), i + EXCERPT),
128
+ pipelineExcerpt: pipelinePrompt.slice(Math.max(0, i - EXCERPT / 2), i + EXCERPT),
129
+ tokensLegacy: count?.(legacyPrompt),
130
+ tokensPipeline: p.context.tokens,
131
+ };
132
+ }
133
+ /**
134
+ * The gate on dropping an old code path (08 §5). Deliberately strict: an empty corpus
135
+ * passes nothing, because "no failures" and "nothing was checked" look identical in a
136
+ * summary and only one of them is safe.
137
+ * @internal
138
+ */
139
+ export function parityGate(results, minimumCorpus = 1) {
140
+ if (results.length < minimumCorpus) {
141
+ return {
142
+ pass: false,
143
+ reason: `corpus has ${results.length} fixtures; ${minimumCorpus} required. An unchecked corpus is not a green one`,
144
+ };
145
+ }
146
+ const failed = results.filter((r) => !r.identical);
147
+ if (failed.length) {
148
+ return {
149
+ pass: false,
150
+ reason: `${failed.length}/${results.length} fixtures diverge, first at ${failed[0].fixture}`,
151
+ };
152
+ }
153
+ return { pass: true };
154
+ }
155
+ /** @internal */
156
+ export function renderParity(r) {
157
+ if (r.identical)
158
+ return `✓ ${r.fixture} identical (${r.tokensPipeline ?? '?'} tokens)`;
159
+ return [
160
+ `✗ ${r.fixture} diverges at character ${r.firstDifferenceAt}`,
161
+ ` legacy: …${r.legacyExcerpt}…`,
162
+ ` pipeline: …${r.pipelineExcerpt}…`,
163
+ ].join('\n');
164
+ }
165
+ // ── The commitMessage split (13 §10b) ───────────────────────────────────────
166
+ /**
167
+ * Rewrite a legacy `commit-message@1` node into `create-message@1` or
168
+ * `update-message@1`.
169
+ *
170
+ * The old type decided new-vs-update at runtime from whether an id happened to be
171
+ * present. Migrating it means recovering that decision from the document — and the
172
+ * honest answer is that **it is recoverable in most specs and genuinely ambiguous in a
173
+ * few**. A migration that guesses in the ambiguous case converts a spec that used to
174
+ * update into one that creates, and the user finds out when their chat fills with
175
+ * duplicates.
176
+ *
177
+ * So the rule is: an id wired in (by edge or by config) means update; nothing wired
178
+ * means create; **anything else is reported unmapped rather than decided**. `unmapped`
179
+ * is already the shape 08 §5b uses for "a human has to look at this."
180
+ * @experimental
181
+ */
182
+ export const LEGACY_COMMIT_MESSAGE = 'core:outlet/commit-message';
183
+ /** @experimental */
184
+ export function splitCommitMessage(doc) {
185
+ const entries = [];
186
+ const nodes = doc.nodes.map((n) => {
187
+ if (n.definitionId !== LEGACY_COMMIT_MESSAGE)
188
+ return n;
189
+ const wiredByEdge = doc.edges.filter((e) => e.to === n.key && ID_PORTS.has(e.toPort));
190
+ const wiredByConfig = ID_KEYS.filter((k) => n.config[k] !== undefined && n.config[k] !== null);
191
+ const wired = wiredByEdge.length + wiredByConfig.length;
192
+ if (wired === 0) {
193
+ entries.push({
194
+ source: { table: 'spec_nodes', id: n.key },
195
+ outcome: 'migrated',
196
+ target: {
197
+ slug: 'core:outlet/create-message@1',
198
+ scopeKind: 'config',
199
+ nodeKey: n.key,
200
+ },
201
+ reason: 'nothing supplies an id, so this node only ever created',
202
+ });
203
+ return {
204
+ ...n,
205
+ definitionId: 'core:outlet/create-message',
206
+ definitionVersion: 1,
207
+ };
208
+ }
209
+ // An id arriving from a write in the same run used to be reported rather
210
+ // than decided, because under async review that row might never have
211
+ // existed. That position is gone and a create → update pair on one row
212
+ // inside one run is one primary row (09-B B4, R-17) — so it is what it
213
+ // looks like: an update of the row an earlier node made.
214
+ if (wiredByEdge.length + wiredByConfig.length > 1) {
215
+ entries.push({
216
+ source: { table: 'spec_nodes', id: n.key },
217
+ outcome: 'unmapped',
218
+ reason: `two sources supply an id (${[...wiredByEdge.map((e) => e.toPort), ...wiredByConfig].join(', ')}) — which one won was a runtime detail`,
219
+ });
220
+ return n;
221
+ }
222
+ entries.push({
223
+ source: { table: 'spec_nodes', id: n.key },
224
+ outcome: 'migrated',
225
+ target: {
226
+ slug: 'core:outlet/update-message@1',
227
+ scopeKind: 'config',
228
+ nodeKey: n.key,
229
+ },
230
+ reason: 'an id is wired in, so this node updated',
231
+ });
232
+ const port = wiredByEdge[0]?.toPort;
233
+ return {
234
+ ...n,
235
+ definitionId: 'core:outlet/update-message',
236
+ definitionVersion: 1,
237
+ config: port ? n.config : renameIdKey(n.config),
238
+ };
239
+ });
240
+ const edges = doc.edges.map((e) => ID_PORTS.has(e.toPort) &&
241
+ nodes.find((n) => n.key === e.to)?.definitionId === 'core:outlet/update-message'
242
+ ? { ...e, toPort: 'target' }
243
+ : e);
244
+ return {
245
+ document: { ...doc, nodes, edges },
246
+ report: { unit: 'commit-message split (13 §10b)', entries, parity: [] },
247
+ };
248
+ }
249
+ /** The port and config names the legacy type accepted an id under. */
250
+ const ID_PORTS = new Set(['messageId', 'id', 'target']);
251
+ const ID_KEYS = ['messageId', 'id'];
252
+ const renameIdKey = (config) => {
253
+ const out = { ...config };
254
+ for (const k of ID_KEYS)
255
+ if (out[k] !== undefined) {
256
+ out.target = out[k];
257
+ delete out[k];
258
+ }
259
+ return out;
260
+ };
261
+ //# sourceMappingURL=migration.js.map
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Names, compared the one way every reader agrees on (lair pass R7, 2026-09-28).
3
+ *
4
+ * `core:task/undescribed-name@1` asks whether a room the planner named is
5
+ * already described: by a lorebook entry whose name or keys answer to it, or
6
+ * by a recent paragraph of prose that names it. Both questions are "is this
7
+ * the same name?", and a second copy of the rule elsewhere would not fail, it
8
+ * would quietly disagree (the knock says the room is new while the listing
9
+ * says it is known). So the rule lives here, once, for the core binding, a
10
+ * plugin's own check and the tests alike.
11
+ *
12
+ * ## The rule
13
+ *
14
+ * A name is reduced to its **words**:
15
+ *
16
+ * - NFKC, then lower case;
17
+ * - a possessive `'s` at the end of a word is dropped, then every other
18
+ * apostrophe (`'`, `’`, `ʼ`, `‘`, `` ` ``) — so "the Vault's door" names "the
19
+ * Vault", "Dragon's Den" is "dragon den" and "O'Brien" is "obrien";
20
+ * - every other character that is not a letter, a digit or a combining mark
21
+ * separates words. That removes surrounding quotes and punctuation
22
+ * (`"The Vault."`), and collapses whitespace, in one step.
23
+ *
24
+ * Then **one** leading article (`the`, `a`, `an`) is dropped, when a word is
25
+ * left after it. "The Vault" and "vault" are one name; "The" alone stays "the".
26
+ *
27
+ * Two names match on **whole equality** of what is left, never a substring:
28
+ * "the vault" is not "the sunken vault".
29
+ *
30
+ * ## Prose
31
+ *
32
+ * A text names a name when the name's words appear in it as a contiguous run
33
+ * of whole words ("the vault, dark" and "the vault's door" name "Vault";
34
+ * "the vaults" does not). The article is not stripped from the text, only
35
+ * from the name.
36
+ *
37
+ * ⚠ Hyphens separate words, so "well-lit" counts as two words toward
38
+ * `minWords`. That is consistent on both sides, which is what matters.
39
+ * @experimental
40
+ */
41
+ /** The articles one strip removes from the front of a name. @experimental */
42
+ export declare const LEADING_ARTICLES: readonly string[];
43
+ /**
44
+ * A text's words, as the name rule reads them: NFKC, lower case, a possessive
45
+ * `'s` and then every apostrophe dropped, split on everything that is not a
46
+ * letter, digit or mark. Anything but a string has no words.
47
+ * @experimental
48
+ */
49
+ export declare function nameWords(text: unknown): string[];
50
+ /**
51
+ * A name, normalized: its words (see the module note) with one leading
52
+ * article dropped, joined by single spaces. `''` for no name.
53
+ * @experimental
54
+ */
55
+ export declare function normalizeName(name: unknown): string;
56
+ /**
57
+ * Whether two names are the same name: whole equality after
58
+ * `normalizeName`, and never for an empty one.
59
+ * @experimental
60
+ */
61
+ export declare function sameName(a: unknown, b: unknown): boolean;
62
+ /**
63
+ * Whether `text` names `name`: the name's words (article dropped) appear in it
64
+ * as a contiguous run of whole words.
65
+ * @experimental
66
+ */
67
+ export declare function namesName(text: unknown, name: unknown): boolean;
68
+ /**
69
+ * The first paragraph of `text` that names `name` **and** holds at least
70
+ * `minWords` words besides it, trimmed; `null` when none does.
71
+ *
72
+ * A paragraph is what a blank line (whitespace-only lines included) separates.
73
+ * "Besides it" subtracts every occurrence of the name's words, so a paragraph
74
+ * that says the name three times is not longer for it.
75
+ * @experimental
76
+ */
77
+ export declare function passageNaming(text: unknown, name: unknown, minWords: number): string | null;
78
+ //# sourceMappingURL=names.d.ts.map
package/dist/names.js ADDED
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Names, compared the one way every reader agrees on (lair pass R7, 2026-09-28).
3
+ *
4
+ * `core:task/undescribed-name@1` asks whether a room the planner named is
5
+ * already described: by a lorebook entry whose name or keys answer to it, or
6
+ * by a recent paragraph of prose that names it. Both questions are "is this
7
+ * the same name?", and a second copy of the rule elsewhere would not fail, it
8
+ * would quietly disagree (the knock says the room is new while the listing
9
+ * says it is known). So the rule lives here, once, for the core binding, a
10
+ * plugin's own check and the tests alike.
11
+ *
12
+ * ## The rule
13
+ *
14
+ * A name is reduced to its **words**:
15
+ *
16
+ * - NFKC, then lower case;
17
+ * - a possessive `'s` at the end of a word is dropped, then every other
18
+ * apostrophe (`'`, `’`, `ʼ`, `‘`, `` ` ``) — so "the Vault's door" names "the
19
+ * Vault", "Dragon's Den" is "dragon den" and "O'Brien" is "obrien";
20
+ * - every other character that is not a letter, a digit or a combining mark
21
+ * separates words. That removes surrounding quotes and punctuation
22
+ * (`"The Vault."`), and collapses whitespace, in one step.
23
+ *
24
+ * Then **one** leading article (`the`, `a`, `an`) is dropped, when a word is
25
+ * left after it. "The Vault" and "vault" are one name; "The" alone stays "the".
26
+ *
27
+ * Two names match on **whole equality** of what is left, never a substring:
28
+ * "the vault" is not "the sunken vault".
29
+ *
30
+ * ## Prose
31
+ *
32
+ * A text names a name when the name's words appear in it as a contiguous run
33
+ * of whole words ("the vault, dark" and "the vault's door" name "Vault";
34
+ * "the vaults" does not). The article is not stripped from the text, only
35
+ * from the name.
36
+ *
37
+ * ⚠ Hyphens separate words, so "well-lit" counts as two words toward
38
+ * `minWords`. That is consistent on both sides, which is what matters.
39
+ * @experimental
40
+ */
41
+ /** The articles one strip removes from the front of a name. @experimental */
42
+ export const LEADING_ARTICLES = ['the', 'a', 'an'];
43
+ const POSSESSIVE = /['’ʼ]s(?![\p{L}\p{N}\p{M}])/gu;
44
+ const APOSTROPHES = /['’ʼ‘`]/gu;
45
+ const SEPARATORS = /[^\p{L}\p{N}\p{M}]+/u;
46
+ /**
47
+ * A text's words, as the name rule reads them: NFKC, lower case, a possessive
48
+ * `'s` and then every apostrophe dropped, split on everything that is not a
49
+ * letter, digit or mark. Anything but a string has no words.
50
+ * @experimental
51
+ */
52
+ export function nameWords(text) {
53
+ if (typeof text !== 'string')
54
+ return [];
55
+ return text
56
+ .normalize('NFKC')
57
+ .toLowerCase()
58
+ .replace(POSSESSIVE, '')
59
+ .replace(APOSTROPHES, '')
60
+ .split(SEPARATORS)
61
+ .filter(Boolean);
62
+ }
63
+ /** A name's words with one leading article dropped (when a word is left after it). */
64
+ function nameTerms(name) {
65
+ const words = nameWords(name);
66
+ return words.length > 1 && LEADING_ARTICLES.includes(words[0]) ? words.slice(1) : words;
67
+ }
68
+ /**
69
+ * A name, normalized: its words (see the module note) with one leading
70
+ * article dropped, joined by single spaces. `''` for no name.
71
+ * @experimental
72
+ */
73
+ export function normalizeName(name) {
74
+ return nameTerms(name).join(' ');
75
+ }
76
+ /**
77
+ * Whether two names are the same name: whole equality after
78
+ * `normalizeName`, and never for an empty one.
79
+ * @experimental
80
+ */
81
+ export function sameName(a, b) {
82
+ const x = normalizeName(a);
83
+ return x !== '' && x === normalizeName(b);
84
+ }
85
+ /** How many times `terms` occurs in `words` as a contiguous run, without overlap. */
86
+ function occurrences(words, terms) {
87
+ let count = 0;
88
+ for (let i = 0; i + terms.length <= words.length;) {
89
+ let hit = true;
90
+ for (let j = 0; j < terms.length; j++)
91
+ if (words[i + j] !== terms[j]) {
92
+ hit = false;
93
+ break;
94
+ }
95
+ if (hit) {
96
+ count++;
97
+ i += terms.length;
98
+ }
99
+ else
100
+ i++;
101
+ }
102
+ return count;
103
+ }
104
+ /**
105
+ * Whether `text` names `name`: the name's words (article dropped) appear in it
106
+ * as a contiguous run of whole words.
107
+ * @experimental
108
+ */
109
+ export function namesName(text, name) {
110
+ const terms = nameTerms(name);
111
+ return terms.length > 0 && occurrences(nameWords(text), terms) > 0;
112
+ }
113
+ /**
114
+ * The first paragraph of `text` that names `name` **and** holds at least
115
+ * `minWords` words besides it, trimmed; `null` when none does.
116
+ *
117
+ * A paragraph is what a blank line (whitespace-only lines included) separates.
118
+ * "Besides it" subtracts every occurrence of the name's words, so a paragraph
119
+ * that says the name three times is not longer for it.
120
+ * @experimental
121
+ */
122
+ export function passageNaming(text, name, minWords) {
123
+ if (typeof text !== 'string')
124
+ return null;
125
+ const terms = nameTerms(name);
126
+ if (terms.length === 0)
127
+ return null;
128
+ for (const paragraph of text.split(/\n[^\S\n]*\n/u)) {
129
+ const words = nameWords(paragraph);
130
+ const hits = occurrences(words, terms);
131
+ if (hits > 0 && words.length - hits * terms.length >= minWords)
132
+ return paragraph.trim();
133
+ }
134
+ return null;
135
+ }
136
+ //# sourceMappingURL=names.js.map