@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/pick.d.ts ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The pick hash and the rendezvous pick — one implementation, three callers.
3
+ *
4
+ * A genre that wants a fact *chosen* rather than authored — which suspect did
5
+ * it, which lorebook entry the answer is — needs a rule that is a pure
6
+ * function of the session and the candidates. Nothing may be written down:
7
+ * the only per-session store a spec can reach is the attribute-slot ledger,
8
+ * which a player's own state panel renders, so an answer stored there is an
9
+ * answer on screen. Derived, the create run and every later turn reach the
10
+ * same choice with nothing recorded anywhere.
11
+ *
12
+ * Two plugins and one core genre each wrote this function out before it lived
13
+ * here — Twenty Questions' `pickSecretEntry`, Whodunit's `pickCulprit`, and
14
+ * `core:task/pick-by-hash@1`'s binding in the app. Three copies of a hash is
15
+ * three chances for one of them to drift, and a drifted copy does not fail:
16
+ * it quietly picks a different suspect than the receipt of the same session
17
+ * from last week.
18
+ *
19
+ * ## Rendezvous, not modulo
20
+ *
21
+ * `ids[hash(key) % ids.length]` is the obvious version and it has the wrong
22
+ * failure: every id moves when the list length changes. Seating a fifth
23
+ * suspect halfway through a case would move the answer in four sessions out
24
+ * of five. Rendezvous hashing scores each candidate *on its own* —
25
+ * `hash(key + '#' + itemKey)` — and takes the maximum, so a new candidate
26
+ * displaces the pick exactly when its own score wins: probability 1/n, and
27
+ * the other n-1 sessions are undisturbed. Removing a candidate moves only the
28
+ * sessions that had picked it.
29
+ *
30
+ * ## ⚠ The finalizer is not optional, and leaving it off is a real bug
31
+ *
32
+ * The pick compares whole hashes, so what matters is how the **high** bits are
33
+ * distributed — and plain FNV-1a over strings differing only in their last
34
+ * character or two leaves those bits systematic. Measured over three ids
35
+ * differing in the last digit, plain FNV handed the first of them the answer
36
+ * in 49% of sessions instead of 33%, and a fourth added mid-game displaced it
37
+ * half the time rather than a quarter. The murmur3 `fmix32` tail below puts
38
+ * both back where the arithmetic says they should be. `sdk-tests/pick.test.ts`
39
+ * is what catches it coming back.
40
+ */
41
+ /**
42
+ * FNV-1a, 32 bits, with murmur3's `fmix32` avalanche on the end. Small,
43
+ * dependency-free, and identical on every machine — the same number in the
44
+ * app's binding, in a plugin's sandbox and in a test.
45
+ *
46
+ * Not `contentHash` from `hash.ts`, and the two must never be confused: that
47
+ * one answers *is this the same declaration?* over a canonical JSON form and
48
+ * is free to change whenever the registries agree to re-project. This one is
49
+ * a **stored answer** in everything but name — change it and every session in
50
+ * flight silently picks somebody else — so it is frozen by its tests.
51
+ * @experimental
52
+ */
53
+ export declare function pickHash32(text: string): number;
54
+ /** What the pick answers: the winning item, where it sat, and the key it won under. @public */
55
+ export interface RendezvousPick<T> {
56
+ item: T;
57
+ /** Its index in the list **as handed in**, not among the candidates. */
58
+ index: number;
59
+ /** The identity it was scored under — what a later comparison compares against. */
60
+ key: string;
61
+ }
62
+ /**
63
+ * The highest-scoring candidate for this key, or `null` when nothing
64
+ * identifiable was offered.
65
+ *
66
+ * Deterministic in both arguments and in **neither's order**: each candidate
67
+ * is scored on its own, and a tie is settled by the lower item key rather
68
+ * than by arrival, so a query that happened to return its rows the other way
69
+ * round reaches the same answer. (A tie needs two keys colliding in all 32
70
+ * bits; the rule exists so that the *answer* does not depend on row order
71
+ * even then.)
72
+ *
73
+ * `keyOf` answers `null` for an entry with no identity — a hole in the list,
74
+ * a row the caller cannot name — and those are skipped rather than scored
75
+ * under `'undefined'`, which would make every nameless entry the same
76
+ * candidate.
77
+ *
78
+ * ⚠ `key` is the session's own address (`session:41`) or something equally
79
+ * durable. It must **not** be a run's seed: that is a different string every
80
+ * turn, and a pick keyed on it would move between two questions.
81
+ * @public
82
+ */
83
+ export declare function rendezvousPick<T>(items: readonly T[], key: string, keyOf: (item: T, index: number) => string | null): RendezvousPick<T> | null;
84
+ //# sourceMappingURL=pick.d.ts.map
package/dist/pick.js ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * The pick hash and the rendezvous pick — one implementation, three callers.
3
+ *
4
+ * A genre that wants a fact *chosen* rather than authored — which suspect did
5
+ * it, which lorebook entry the answer is — needs a rule that is a pure
6
+ * function of the session and the candidates. Nothing may be written down:
7
+ * the only per-session store a spec can reach is the attribute-slot ledger,
8
+ * which a player's own state panel renders, so an answer stored there is an
9
+ * answer on screen. Derived, the create run and every later turn reach the
10
+ * same choice with nothing recorded anywhere.
11
+ *
12
+ * Two plugins and one core genre each wrote this function out before it lived
13
+ * here — Twenty Questions' `pickSecretEntry`, Whodunit's `pickCulprit`, and
14
+ * `core:task/pick-by-hash@1`'s binding in the app. Three copies of a hash is
15
+ * three chances for one of them to drift, and a drifted copy does not fail:
16
+ * it quietly picks a different suspect than the receipt of the same session
17
+ * from last week.
18
+ *
19
+ * ## Rendezvous, not modulo
20
+ *
21
+ * `ids[hash(key) % ids.length]` is the obvious version and it has the wrong
22
+ * failure: every id moves when the list length changes. Seating a fifth
23
+ * suspect halfway through a case would move the answer in four sessions out
24
+ * of five. Rendezvous hashing scores each candidate *on its own* —
25
+ * `hash(key + '#' + itemKey)` — and takes the maximum, so a new candidate
26
+ * displaces the pick exactly when its own score wins: probability 1/n, and
27
+ * the other n-1 sessions are undisturbed. Removing a candidate moves only the
28
+ * sessions that had picked it.
29
+ *
30
+ * ## ⚠ The finalizer is not optional, and leaving it off is a real bug
31
+ *
32
+ * The pick compares whole hashes, so what matters is how the **high** bits are
33
+ * distributed — and plain FNV-1a over strings differing only in their last
34
+ * character or two leaves those bits systematic. Measured over three ids
35
+ * differing in the last digit, plain FNV handed the first of them the answer
36
+ * in 49% of sessions instead of 33%, and a fourth added mid-game displaced it
37
+ * half the time rather than a quarter. The murmur3 `fmix32` tail below puts
38
+ * both back where the arithmetic says they should be. `sdk-tests/pick.test.ts`
39
+ * is what catches it coming back.
40
+ */
41
+ /**
42
+ * FNV-1a, 32 bits, with murmur3's `fmix32` avalanche on the end. Small,
43
+ * dependency-free, and identical on every machine — the same number in the
44
+ * app's binding, in a plugin's sandbox and in a test.
45
+ *
46
+ * Not `contentHash` from `hash.ts`, and the two must never be confused: that
47
+ * one answers *is this the same declaration?* over a canonical JSON form and
48
+ * is free to change whenever the registries agree to re-project. This one is
49
+ * a **stored answer** in everything but name — change it and every session in
50
+ * flight silently picks somebody else — so it is frozen by its tests.
51
+ * @experimental
52
+ */
53
+ export function pickHash32(text) {
54
+ let h = 0x811c9dc5;
55
+ for (let i = 0; i < text.length; i++) {
56
+ h ^= text.charCodeAt(i);
57
+ h = Math.imul(h, 0x01000193) >>> 0;
58
+ }
59
+ h ^= h >>> 16;
60
+ h = Math.imul(h, 0x85ebca6b) >>> 0;
61
+ h ^= h >>> 13;
62
+ h = Math.imul(h, 0xc2b2ae35) >>> 0;
63
+ h ^= h >>> 16;
64
+ return h >>> 0;
65
+ }
66
+ /**
67
+ * The highest-scoring candidate for this key, or `null` when nothing
68
+ * identifiable was offered.
69
+ *
70
+ * Deterministic in both arguments and in **neither's order**: each candidate
71
+ * is scored on its own, and a tie is settled by the lower item key rather
72
+ * than by arrival, so a query that happened to return its rows the other way
73
+ * round reaches the same answer. (A tie needs two keys colliding in all 32
74
+ * bits; the rule exists so that the *answer* does not depend on row order
75
+ * even then.)
76
+ *
77
+ * `keyOf` answers `null` for an entry with no identity — a hole in the list,
78
+ * a row the caller cannot name — and those are skipped rather than scored
79
+ * under `'undefined'`, which would make every nameless entry the same
80
+ * candidate.
81
+ *
82
+ * ⚠ `key` is the session's own address (`session:41`) or something equally
83
+ * durable. It must **not** be a run's seed: that is a different string every
84
+ * turn, and a pick keyed on it would move between two questions.
85
+ * @public
86
+ */
87
+ export function rendezvousPick(items, key, keyOf) {
88
+ let best = null;
89
+ let bestScore = -1;
90
+ for (let i = 0; i < items.length; i++) {
91
+ const item = items[i];
92
+ const itemKey = keyOf(item, i);
93
+ if (typeof itemKey !== 'string' || !itemKey)
94
+ continue;
95
+ const score = pickHash32(`${key}#${itemKey}`);
96
+ if (score > bestScore || (score === bestScore && best !== null && itemKey < best.key)) {
97
+ best = { item, index: i, key: itemKey };
98
+ bestScore = score;
99
+ }
100
+ }
101
+ return best;
102
+ }
103
+ //# sourceMappingURL=pick.js.map
@@ -0,0 +1,235 @@
1
+ /**
2
+ * The **plugin sandbox's context, in the author's harness** (plans 29 §14 D-3).
3
+ *
4
+ * The SDK's executor builds a node's context itself — `{ signal, progress,
5
+ * status, log, countTokens }`, plus `read` for a Query, `call` for an Oracle and
6
+ * `commit` for an Outlet. That is the context a **core** handler runs against,
7
+ * and it is *not* the one a **plugin's** handler ever sees. At install a
8
+ * plugin's node handlers do not go through that path at all: the app's
9
+ * `pipelines/runtime/pluginBindings.ts` calls `RuntimeManager.callHook`, which
10
+ * runs the hook inside the plugin's sandbox against a context the sandbox
11
+ * builds — `{ random, now, log, storage, fetch, signal }` — and commits its rows
12
+ * afterwards.
13
+ *
14
+ * Two packages paid for that gap before it was written down:
15
+ *
16
+ * - **Twenty Questions shipped a dead Query.** Its `ctx.read` worked in the
17
+ * harness, because the executor endows `read` for every Query whoever wrote
18
+ * it. No sandbox endows it, so the query would have read nothing at install.
19
+ * - **Battleship had to write its own fake store.** Nothing in the harness
20
+ * endows `ctx.storage`, so a package whose whole point is that one handler
21
+ * reads back what another wrote could not run its own handlers without
22
+ * hand-wrapping every binding.
23
+ *
24
+ * So this module endows the *sandbox's* surface, and endows **only** that: a
25
+ * plugin Query's `ctx.read` is `undefined` here exactly as it is at install, and
26
+ * a test written against it fails the way the install would. The executor's own
27
+ * conveniences — `progress`, `status`, `countTokens`, `iteration`, `scripts` —
28
+ * are absent for the same reason: no sandbox has ever defined them.
29
+ *
30
+ * ⚠ **Not the real sandbox.** No opaque origin, no worker, no QuickJS, no
31
+ * membrane; the handler runs in this process with ordinary references. What is
32
+ * reproduced is the *shape* — which members exist, which are withheld, what a
33
+ * refusal says, and where the randomness and the clock come from — because that
34
+ * is what a handler can be written against and get wrong.
35
+ */
36
+ import { type Bindings, type Result } from './executor.js';
37
+ import type { HookFetchInit, HookFetchResponse } from './hooks.js';
38
+ import type { ExtensionStorage } from './storage.js';
39
+ import { type HookCtxGrants, type HookCtxKind } from './hookGrants.js';
40
+ export { HOOK_CTX_KINDS, hookCtxGrants, hookCtxKeysFor, isHookCtxKind, type HookCtxGrants, type HookCtxKind } from './hookGrants.js';
41
+ /**
42
+ * The sandbox's RNG — xfnv1a over the seed label, then mulberry32.
43
+ *
44
+ * ⚠ **Not `seededRandom`.** The executor's RNG (executor.ts) is a different
45
+ * algorithm over a different seed, and the two produce different streams from
46
+ * the same word. That is a fact about the two codebases, not a design: a plugin
47
+ * handler's rolls come from the *sandbox's* stream, so a golden over a handler
48
+ * that rolls is only reproducible against this one. Kept byte-for-byte in step
49
+ * with `buildProgram` in the app's `QuickJsSandbox.ts` / `SesWorkerSandbox.ts`.
50
+ * @experimental
51
+ */
52
+ export declare function pluginSeededRandom(label: string): () => number;
53
+ /**
54
+ * djb2 over the serialized input — the app's per-call address, so the seed
55
+ * label a harness composes is the label an install composes (`pluginBindings.ts`).
56
+ * @experimental
57
+ */
58
+ export declare function inputDigest(v: unknown): string;
59
+ /**
60
+ * The seed label a plugin node handler's RNG is derived from, as the app
61
+ * composes it: the run seed, the pin, and a digest of the exact input — so
62
+ * replays roll the same and two same-typed nodes in one run (or one node under
63
+ * `each`) get distinct streams without depending on completion order.
64
+ * @experimental
65
+ */
66
+ export declare const nodeSeedLabel: (seed: string, pin: string, input: unknown) => string;
67
+ /** The prelude's `__fmtLog`: `[level] message detail…`, or `[log] …`. @experimental */
68
+ export declare function formatHookLog(args: unknown[]): string;
69
+ /**
70
+ * The row half of the grant, as a fraction of it — mirrors `rowQuotaFor` in the
71
+ * app's `storageHost.ts`, which is the arithmetic the sandbox actually applies.
72
+ * Rows live in the database and files on disk; one budget is what an author can
73
+ * reason about, and the sub-cap is what stops a plugin putting megabytes in the
74
+ * database.
75
+ * @experimental
76
+ */
77
+ export declare function rowQuotaFor(quotaBytes: number): number;
78
+ /** The grant a sandbox falls back to when the manifest declares none. @experimental */
79
+ export declare const DEFAULT_STORAGE_QUOTA_BYTES: number;
80
+ /**
81
+ * The clock this harness pins when a caller names none.
82
+ *
83
+ * Deliberately the same instant as `EXAMPLE_CLOCK` in `testing.ts`, so a
84
+ * handler run inside an executed example and the same handler run in a unit
85
+ * test report the same `ctx.now()` — a golden that moved between the two would
86
+ * be a golden nobody keeps. Defined here rather than imported because
87
+ * `testing.ts` re-exports this module, and a test pins that the two agree.
88
+ * @experimental
89
+ */
90
+ export declare const HARNESS_CLOCK = 1700000000000;
91
+ /** @experimental */
92
+ export interface MemoryStorageOptions {
93
+ /** The grant, in bytes. The sandbox's own fallback by default. */
94
+ quotaBytes?: number;
95
+ /** The sub-cap on the row half. Derived from `quotaBytes` by default. */
96
+ rowQuotaBytes?: number;
97
+ /** Rows to start with, for a test that wants a game already in progress. */
98
+ seed?: Record<string, unknown>;
99
+ /**
100
+ * The call's pinned clock, which is what stamps a row's `updatedAt`.
101
+ *
102
+ * Pinned, not ticking, because that is what install does: the sandbox stamps
103
+ * every row a call writes with the run's clock, so rows written in one call
104
+ * share a timestamp and `query({ order: 'newest' })` falls back to key order
105
+ * among them. A test that wants distinct stamps supplies a clock that moves.
106
+ */
107
+ now?: () => number;
108
+ }
109
+ /** @experimental */
110
+ export interface MemoryStorage extends ExtensionStorage {
111
+ /** Every key currently held with its value, key-sorted — for asserting on the shape of the store. */
112
+ snapshot(): Record<string, unknown>;
113
+ /** How many times `put` has been called. A cheap way to pin "this handler wrote once". */
114
+ readonly writes: number;
115
+ }
116
+ /**
117
+ * An in-memory `ExtensionStorage` — the half the SDK's harness cannot otherwise
118
+ * supply, with the refusals install actually makes.
119
+ *
120
+ * Faithful in the ways a handler can depend on: `get` answers `undefined` for a
121
+ * key nobody wrote; a row costs its key as well as its value; a write past the
122
+ * row budget or the whole grant comes back as `err` rather than throwing, and
123
+ * comes back **whole** so a handler that prunes and retries can; a key that is
124
+ * not a key, and a value JSON cannot carry, throw with the sandbox's sentence.
125
+ *
126
+ * ⚠ Not faithful about: transactions (install commits a call's rows together,
127
+ * this writes as it goes), the database, and the bytes a row costs on disk.
128
+ * What it does reproduce is the one property a package like Battleship exists
129
+ * to demonstrate — a row one handler writes is a row the next handler reads.
130
+ *
131
+ * **Isolation is structural.** One call is one namespace; two plugins get two
132
+ * calls and neither can name the other's keys, because there is no shared map
133
+ * to name them in.
134
+ * @experimental
135
+ */
136
+ export declare function memoryStorage(opts?: MemoryStorageOptions): MemoryStorage;
137
+ /** What `ctx.fetch` answers with once the allowlist has let a call through. @experimental */
138
+ export type HookFetchAnswer = (url: string, init?: HookFetchInit) => HookFetchResponse | Promise<HookFetchResponse>;
139
+ /**
140
+ * What a plugin's handler is handed — the sandbox's six, no more.
141
+ *
142
+ * `storage` and `fetch` are optional here for the reason they are absent there:
143
+ * a member a kind is not granted is **absent**, not a stub that refuses, so
144
+ * `Object.keys(ctx)` says exactly what the hook may reach.
145
+ * @experimental
146
+ */
147
+ export interface PluginHandlerContext {
148
+ /** Seeded from the run seed (`pluginSeededRandom`). Never `Math.random`. */
149
+ random(): number;
150
+ /** The run's clock, pinned. Two calls in one run return the same number. */
151
+ now(): number;
152
+ log(...args: unknown[]): void;
153
+ storage?: ExtensionStorage;
154
+ fetch?(url: string, init?: HookFetchInit): Promise<HookFetchResponse>;
155
+ signal: AbortSignal;
156
+ }
157
+ /** @experimental */
158
+ export interface PluginHandlerContextOptions {
159
+ /** The extension's address, for the sentences a refusal writes. */
160
+ pluginId: string;
161
+ /**
162
+ * The RNG's seed label. `pluginNodeBindings` composes the app's
163
+ * (`nodeSeedLabel`); a test calling this directly passes whatever it wants
164
+ * to be able to reproduce.
165
+ */
166
+ seed?: string;
167
+ /** The hook kind, which decides the grants (R-3). Omitted: both granted. */
168
+ kind?: HookCtxKind;
169
+ /** Override the kind's grants — for pinning what a handler does without one. */
170
+ grants?: Partial<HookCtxGrants>;
171
+ /** The extension's store. A fresh `memoryStorage()` when the grant holds and none is given. */
172
+ storage?: ExtensionStorage;
173
+ /** The pinned clock, in milliseconds. */
174
+ now?: number;
175
+ signal?: AbortSignal;
176
+ /** The hosts the manifest declares under `permissions.network.hosts`. */
177
+ network?: readonly string[];
178
+ /** What an allowed call answers with. Absent: an allowed call still refuses, and says so. */
179
+ fetch?: HookFetchAnswer;
180
+ /** Where `ctx.log` lines land, formatted as the sandbox prelude formats them. */
181
+ logs?: string[];
182
+ }
183
+ /**
184
+ * Build the context a plugin's handler runs against at install.
185
+ *
186
+ * The one-liner `examples/fixtures.ts` in a plugin repo should not have to
187
+ * write: pass it to a handler and the handler sees what the sandbox gives it,
188
+ * including the absences.
189
+ * @experimental
190
+ */
191
+ export declare function pluginHandlerContext(opts: PluginHandlerContextOptions): PluginHandlerContext;
192
+ /** A plugin's node handler: `(input, ctx)`, with the sandbox's ctx. @experimental */
193
+ export type PluginNodeHandler = (input: any, ctx: PluginHandlerContext) => Result | Promise<Result>;
194
+ /** @experimental */
195
+ export interface PluginNodeBindingOptions {
196
+ /** The extension's address — one store, one seed namespace, one set of grants. */
197
+ pluginId: string;
198
+ /** `definitionId@version` → the handler the manifest's `nodeDefinitions` names. */
199
+ handlers: Record<string, PluginNodeHandler>;
200
+ /**
201
+ * The extension's store, shared by every handler below — which is the whole
202
+ * point: one plugin is one namespace, so a row `place` writes is a row
203
+ * `fire` reads. A fresh `memoryStorage()` when none is given.
204
+ */
205
+ storage?: ExtensionStorage;
206
+ /** The run seed the RNG labels derive from. */
207
+ seed?: string;
208
+ /** The pinned clock. */
209
+ now?: number;
210
+ network?: readonly string[];
211
+ fetch?: HookFetchAnswer;
212
+ logs?: string[];
213
+ /**
214
+ * The hook ctx kind per pin, for a definition this process has not
215
+ * registered. A registered one is read off its descriptor, which is the
216
+ * answer install reads off the registry row.
217
+ */
218
+ kinds?: Record<string, HookCtxKind>;
219
+ }
220
+ /**
221
+ * Project a plugin's handlers into executor bindings that run them against the
222
+ * **sandbox's** context — the harness's counterpart of the app's
223
+ * `pluginNodeBindings` (`pipelines/runtime/pluginBindings.ts`), which does the
224
+ * same projection over a real sandbox.
225
+ *
226
+ * The executor's own context reaches the handler in exactly one respect: its
227
+ * `signal`, because at install the host fires the sandbox's abort from the same
228
+ * place. Everything else it built — `read`, `call`, `commit`, `progress`,
229
+ * `status`, `countTokens` — is dropped, because no sandbox has ever endowed it.
230
+ * A plugin Query reaching for `ctx.read` therefore fails here exactly as it
231
+ * fails at install, which is the whole reason this exists (G13).
232
+ * @experimental
233
+ */
234
+ export declare function pluginNodeBindings(opts: PluginNodeBindingOptions): Bindings;
235
+ //# sourceMappingURL=pluginHarness.d.ts.map