@volter/world-core 2.0.37 → 3.0.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 (205) hide show
  1. package/README.md +4 -5
  2. package/app-route.cjs +12 -6
  3. package/app-route.d.cts +1 -1
  4. package/dist/app-route.cjs +12 -6
  5. package/dist/app-route.d.cts +1 -1
  6. package/dist/generated/pack-facts.json +1410 -3069
  7. package/dist/inject.cjs +64 -9
  8. package/dist/pack-facts.cjs +44 -0
  9. package/dist/src/actions.d.ts +3 -3
  10. package/dist/src/actions.js +22 -16
  11. package/dist/src/ancestry.d.ts +14 -2
  12. package/dist/src/ancestry.js +92 -2
  13. package/dist/src/anthropic-wire.d.ts +39 -0
  14. package/dist/src/anthropic-wire.js +136 -0
  15. package/dist/src/bytes.d.ts +7 -0
  16. package/dist/src/bytes.js +35 -0
  17. package/dist/src/changeset.d.ts +1 -1
  18. package/dist/src/changeset.js +0 -0
  19. package/dist/src/clickhouse/index.d.ts +3 -0
  20. package/dist/src/clickhouse/index.js +6 -0
  21. package/dist/src/clickhouse/sql.d.ts +233 -0
  22. package/dist/src/clickhouse/sql.js +4329 -0
  23. package/dist/src/clickhouse/types.d.ts +18 -0
  24. package/dist/src/clickhouse/types.js +47 -0
  25. package/dist/src/clickhouse/values.d.ts +146 -0
  26. package/dist/src/clickhouse/values.js +858 -0
  27. package/dist/src/client-bundle.js +2 -3
  28. package/dist/src/cors.d.ts +15 -0
  29. package/dist/src/cors.js +31 -0
  30. package/dist/src/derived-core.d.ts +487 -24
  31. package/dist/src/derived-core.js +788 -144
  32. package/dist/src/derived-real.d.ts +13 -0
  33. package/dist/src/derived-real.js +518 -0
  34. package/dist/src/derived.d.ts +35 -1
  35. package/dist/src/derived.js +61 -9
  36. package/dist/src/emit.js +1 -2
  37. package/dist/src/events.d.ts +206 -0
  38. package/dist/src/events.js +341 -0
  39. package/dist/src/executor.d.ts +3 -0
  40. package/dist/src/executor.js +19 -2
  41. package/dist/src/file-response.d.ts +6 -0
  42. package/dist/src/file-response.js +30 -0
  43. package/dist/src/fork.js +3 -2
  44. package/dist/src/git/history.d.ts +7 -0
  45. package/dist/src/git/history.js +24 -0
  46. package/dist/src/git/index.d.ts +1 -0
  47. package/dist/src/git/index.js +1 -0
  48. package/dist/src/git/lfs.d.ts +28 -0
  49. package/dist/src/git/lfs.js +66 -0
  50. package/dist/src/git/objects.js +3 -8
  51. package/dist/src/git/smart-http.d.ts +3 -1
  52. package/dist/src/git/smart-http.js +67 -6
  53. package/dist/src/graphql-wire.d.ts +29 -0
  54. package/dist/src/graphql-wire.js +101 -0
  55. package/dist/src/grpc-wire.d.ts +67 -0
  56. package/dist/src/grpc-wire.js +170 -0
  57. package/dist/src/h2.d.ts +40 -0
  58. package/dist/src/h2.js +656 -0
  59. package/dist/src/head.d.ts +32 -3
  60. package/dist/src/head.js +161 -40
  61. package/dist/src/history.d.ts +1 -1
  62. package/dist/src/history.js +6 -6
  63. package/dist/src/hpack.json +1 -0
  64. package/dist/src/index.d.ts +64 -75
  65. package/dist/src/index.js +58 -101
  66. package/dist/src/log.js +28 -19
  67. package/dist/src/machines.d.ts +50 -0
  68. package/dist/src/machines.js +151 -0
  69. package/dist/src/managed-database.d.ts +86 -0
  70. package/dist/src/managed-database.js +283 -0
  71. package/dist/src/multipart.d.ts +11 -0
  72. package/dist/src/multipart.js +51 -0
  73. package/dist/src/observe.d.ts +15 -5
  74. package/dist/src/observe.js +23 -9
  75. package/dist/src/openai-wire.d.ts +108 -0
  76. package/dist/src/openai-wire.js +337 -0
  77. package/dist/src/pack-assets.d.ts +3 -4
  78. package/dist/src/pack-assets.js +15 -10
  79. package/dist/src/pack-fetch.d.ts +77 -0
  80. package/dist/src/pack-fetch.js +449 -0
  81. package/dist/src/pack-paths.d.ts +12 -0
  82. package/dist/src/pack-paths.js +86 -0
  83. package/dist/src/packRegistry.d.ts +69 -162
  84. package/dist/src/packRegistry.js +55 -20
  85. package/dist/src/people.d.ts +13 -0
  86. package/dist/src/people.js +18 -0
  87. package/dist/src/placeholder-image.d.ts +5 -0
  88. package/dist/src/placeholder-image.js +114 -0
  89. package/dist/src/protobuf.d.ts +28 -0
  90. package/dist/src/protobuf.js +332 -0
  91. package/dist/src/redis/engine.js +1 -1
  92. package/dist/src/request-scope.d.ts +1 -1
  93. package/dist/src/request-scope.js +6 -4
  94. package/dist/src/resource-blob.d.ts +5 -0
  95. package/dist/src/resource-blob.js +11 -0
  96. package/dist/src/runtime.d.ts +85 -0
  97. package/dist/src/runtime.js +104 -0
  98. package/dist/src/s3/wire.d.ts +60 -0
  99. package/dist/src/s3/wire.js +157 -0
  100. package/dist/src/scenario.d.ts +3 -0
  101. package/dist/src/scenario.js +2 -0
  102. package/dist/src/schema-sample.d.ts +1 -0
  103. package/dist/src/schema-sample.js +21 -0
  104. package/dist/src/sealed-box.d.ts +14 -0
  105. package/dist/src/sealed-box.js +225 -0
  106. package/dist/src/serve-http.d.ts +14 -0
  107. package/dist/src/serve-http.js +27 -3
  108. package/dist/src/serve.d.ts +6 -0
  109. package/dist/src/serve.js +69 -14
  110. package/dist/src/signing.d.ts +135 -0
  111. package/dist/src/signing.js +222 -0
  112. package/dist/src/sigv4.d.ts +48 -0
  113. package/dist/src/sigv4.js +167 -0
  114. package/dist/src/smtp.d.ts +16 -0
  115. package/dist/src/smtp.js +72 -0
  116. package/dist/src/sockets.d.ts +51 -0
  117. package/dist/src/sockets.js +90 -0
  118. package/dist/src/state-system.d.ts +1 -0
  119. package/dist/src/state-system.js +1 -1
  120. package/dist/src/storage.d.ts +1 -1
  121. package/dist/src/storage.js +3 -3
  122. package/dist/src/trace-context.js +1 -1
  123. package/dist/src/twin-fetch.d.ts +0 -7
  124. package/dist/src/twin-fetch.js +0 -14
  125. package/dist/src/vendor-call.d.ts +6 -0
  126. package/dist/src/vendor-call.js +41 -0
  127. package/dist/src/world-store.js +1 -1
  128. package/dist/vendor-hosts.cjs +36 -125
  129. package/dist/vendor-hosts.d.cts +8 -0
  130. package/generated/pack-facts.json +1410 -3069
  131. package/inject.cjs +64 -9
  132. package/pack-facts.cjs +44 -0
  133. package/package.json +17 -3
  134. package/src/actions.ts +23 -16
  135. package/src/ancestry.ts +74 -2
  136. package/src/anthropic-wire.ts +137 -0
  137. package/src/bytes.ts +42 -0
  138. package/src/changeset.ts +5 -5
  139. package/src/clickhouse/index.ts +6 -0
  140. package/src/clickhouse/sql.ts +3059 -0
  141. package/src/clickhouse/types.ts +44 -0
  142. package/src/clickhouse/values.ts +697 -0
  143. package/src/client-bundle.ts +2 -3
  144. package/src/cors.ts +34 -0
  145. package/src/derived-core.ts +1013 -146
  146. package/src/derived-real.ts +434 -0
  147. package/src/derived.ts +73 -3
  148. package/src/emit.ts +1 -2
  149. package/src/events.ts +449 -0
  150. package/src/executor.ts +24 -2
  151. package/src/file-response.ts +27 -0
  152. package/src/fork.ts +3 -2
  153. package/src/git/history.ts +19 -0
  154. package/src/git/index.ts +1 -0
  155. package/src/git/lfs.ts +67 -0
  156. package/src/git/objects.ts +3 -5
  157. package/src/git/smart-http.ts +56 -6
  158. package/src/graphql-wire.ts +106 -0
  159. package/src/grpc-wire.ts +159 -0
  160. package/src/h2.ts +627 -0
  161. package/src/head.ts +132 -41
  162. package/src/history.ts +6 -6
  163. package/src/hpack.json +1 -0
  164. package/src/index.ts +82 -329
  165. package/src/log.ts +27 -18
  166. package/src/machines.ts +151 -0
  167. package/src/managed-database.ts +299 -0
  168. package/src/multipart.ts +51 -0
  169. package/src/observe.ts +31 -15
  170. package/src/openai-wire.ts +371 -0
  171. package/src/pack-assets.ts +15 -11
  172. package/src/pack-fetch.ts +458 -0
  173. package/src/pack-paths.ts +72 -0
  174. package/src/packRegistry.ts +79 -167
  175. package/src/people.ts +31 -0
  176. package/src/placeholder-image.ts +88 -0
  177. package/src/protobuf.ts +251 -0
  178. package/src/redis/engine.ts +1 -1
  179. package/src/request-scope.ts +8 -4
  180. package/src/resource-blob.ts +13 -0
  181. package/src/runtime.ts +344 -0
  182. package/src/s3/wire.ts +172 -0
  183. package/src/scenario.ts +4 -0
  184. package/src/schema-sample.ts +24 -0
  185. package/src/sealed-box.ts +182 -0
  186. package/src/serve-http.ts +31 -3
  187. package/src/serve.ts +58 -14
  188. package/src/signing.ts +231 -0
  189. package/src/sigv4.ts +158 -0
  190. package/src/smtp.ts +76 -0
  191. package/src/sockets.ts +140 -0
  192. package/src/state-system.ts +2 -2
  193. package/src/storage.ts +3 -3
  194. package/src/trace-context.ts +1 -1
  195. package/src/twin-fetch.ts +0 -20
  196. package/src/vendor-call.ts +41 -0
  197. package/src/world-store.ts +1 -1
  198. package/vendor-hosts.cjs +36 -125
  199. package/vendor-hosts.d.cts +8 -0
  200. package/dist/src/mirror-shell.d.ts +0 -2
  201. package/dist/src/mirror-shell.js +0 -13
  202. package/dist/src/v1-removed.d.ts +0 -159
  203. package/dist/src/v1-removed.js +0 -124
  204. package/src/mirror-shell.ts +0 -15
  205. package/src/v1-removed.ts +0 -172
package/src/index.ts CHANGED
@@ -1,336 +1,89 @@
1
- // @volter/world-core — the shared state kernel and vendor-independent runtime libraries.
2
- // Protocol-2 packs read the checkpointed tree and write through the head's state system.
3
- // The kernel owns logs, branches, landing and receipts; each pack owns its vendor's wire
4
- // and resource semantics. See docs/concepts/the-model.md and docs/contributing/architecture.md.
5
- // Compatibility exports below are not a second state model. Refer to their implementations
6
- // before using older operator helpers; removed v1 entry points fail explicitly.
7
- // Conformance/validation tooling (capability + spec + recorded-diff + UI harnesses and
8
- // the spec derivers) is NOT part of the runtime kernel — it lives in @volter/world-tooling,
9
- // a dev dependency. A twin runs without it; only tests and the conformance scripts use it.
10
- // Pack registry — vendor twins self-describe (TwinPack) so tooling discovers them.
11
- export { clearRegistry, getPack, hasPack, listPacks, registerPack, pullPosture, assertContinuousPullAllowed, pullOnSchedule, resolvePullVendor, DEFAULT_PULL_POSTURE, DEFAULT_PULL_TRIGGER, PROTOCOL_VERSION, PROTOCOL_MAJOR, protocolStanding } from './packRegistry.ts';
12
- export type { PackTransport, PullPosture, PullTrigger, PullVendor, RoundTripWrite, TwinPack } from './packRegistry.ts';
13
- // The DELIVER verb (`emit`) — vendor-agnostic engine + CLI glue; packs declare a TwinEmitter
14
- // (their event catalog, endpoints-from-state, and signed synthesis) on `TwinPack.emitter`.
15
- export { parseScenarioDocument, scenarioFaultResult, ScenarioEngine, ScenarioError, statefulTwinManifest, twinManifest } from './scenario.ts';
16
- export { WORLD_CLOCK_ENV, worldNow } from './world-clock.ts';
17
- export { WORLD_ENV_NAMES_ENV, worldEnvValue } from './world-env.ts';
18
- export { createTwinFetchFromHandler, TWIN_PREFIX_HEADER, TWIN_REQUEST_SCOPES, twinPublicBase, withRequestScopes } from './twin-fetch.ts';
19
- export { isReadOnlyRequest, READ_ONLY_REQUEST_HEADER, ReadOnlyRequestError, runAsReadOnlyRequest, runAsVendorMove, writesRefused } from './request-scope.ts';
20
- export { compileSurface, createDerivedFetch, matchOperation } from './derived.ts';
21
- export { currentTraceparent, deliveryTraceHeaders, newTraceparent, parseTraceparent, runWithRequestTrace, runWithTraceparent, TRACEPARENT_HEADER, traceparentForDelivery, validTraceparent } from './trace-context.ts';
22
- export type { Traceparent } from './trace-context.ts';
23
- export type { DerivedCall, DerivedCoreOutcome, DerivedFetch, DerivedFetchOptions, DerivedHandler, DerivedOperation, DerivedOwner, DerivedSurface } from './derived.ts';
24
- export { bindSemantics, coreFor, crossCutting, derivedRequestScopes, observeTransitions, resourcesOfType as twinResourcesOfType, semanticsContext, stateOf, transitionFor, parseBracketForm, readParams, render as renderDerived, serveCore, sse, vendorError } from './derived-core.ts';
25
- export type { Actor, CoreScope, DerivedManifest, ErrorSpec, FieldRule, Handler, HandlerContext, ResourceDecl, WriteHookContext, ScreenDecl, Semantics, SemanticsContext, StateField, Transition, TransitionObserver } from './derived-core.ts';
26
- export type { RemoteExecute, RemoteExecuteRequest, RemoteExecuteResponse } from './remote-execute.ts';
27
- export type { TwinFetchAdapterConfig, TwinFetchHandlerRequest, TwinFetchHandlerResult, TwinStream, TwinStreamConnection, TwinStreamSink } from './twin-fetch.ts';
28
- export type { PackScenarioAdapter, ScenarioDecision, ScenarioDocument, ScenarioExtractorSpec, ScenarioFault, ScenarioFaultResult, ScenarioFeatures, ScenarioHandler, ScenarioMatcher, ScenarioMissRecord, ScenarioStatus } from './scenario.ts';
29
- export { emitTwinEvent, eventSubscriptionMatches, listEmittable, runEmitCli } from './emit.ts';
30
- export type { EmitDeliveryResult, EmitEndpoint, EmitReport, EmittableEvent, SynthesizedDelivery, TwinEmitter } from './emit.ts';
31
- // The vendor-agnostic CLIENT-SIDE RATE BUDGET — the fail-closed backstop a pack's guarded client
32
- // routes every live vendor call through. The MECHANISM is here; the per-vendor ceiling/window/
33
- // weights are DATA the pack declares (`TwinPack.rateBudget` / `declareRateBudget`). Exported so an
34
- // operator can inspect spend (`snapshot`) and a caller can catch `RateBudgetError` by type; there
35
- // is deliberately no export that disables the guard, and a vendor with no declaration falls back
36
- // to `DEFAULT_RATE_BUDGET` rather than to no limit at all.
37
- export {
38
- DEFAULT_RATE_BUDGET,
39
- MAX_RATE_BUDGET_CEILING,
40
- MAX_RATE_BUDGET_WINDOW_MS,
41
- MIN_RATE_BUDGET_WEIGHT,
42
- MIN_RATE_BUDGET_WINDOW_MS,
43
- RateBudget,
44
- RateBudgetError,
45
- declareRateBudget,
46
- hasRateBudgetDeclaration,
47
- listRateBudgets,
48
- priceCall,
49
- rateBudgetPath,
50
- rateBudgetPolicy,
51
- rateBudgetWeight,
52
- resetToSeconds,
53
- assertBudgetGuardIntact,
54
- } from './rateBudget.ts';
55
- export type {
56
- RateBudgetDeclaration,
57
- RateBudgetErrorKind,
58
- RateBudgetOptions,
59
- RateBudgetPolicy,
60
- RateBudgetReservation,
61
- RateBudgetSnapshot,
62
- RateBudgetWeightRule,
63
- } from './rateBudget.ts';
64
- export {
65
- GenericWorldStateSchema,
66
- WorldActorSchema,
67
- WorldExternalRefSchema,
68
- WorldServiceEventSchema,
69
- WorldSubjectSchema,
70
- } from './schemas.ts';
71
- // NOTE: source books (event→tracker-source mapping) moved OUT of the world — it was
72
- // the last tracker coupling. It now lives at `@volter/tracker/world-source-books`,
73
- // so `@volter/world-core` is a pure twin runtime.
74
- export {
75
- loadWorldConfig,
76
- } from './worldConfig.ts';
77
- export type {
78
- WorldConfig,
79
- WorldServiceConfig,
80
- } from './worldConfig.ts';
81
- export {
82
- DELTA_TYPE_SUFFIX,
83
- diffSubjectFields,
84
- hashFieldValue,
85
- subjectKey, deltaAfterFields } from './hash.ts';
86
- export type {
87
- FieldChange,
88
- SubjectFields,
89
- } from './hash.ts';
90
- export {
91
- appendDurable,
92
- appendEvent,
93
- createEvent,
94
- emptyGenericState,
95
- genericWorldReducer,
96
- listEvents,
97
- loadState,
98
- projectionLockPath,
99
- readJsonFile,
100
- rebuildGenericState,
101
- rebuildState,
102
- // Scrub: delete pulled data at rest (TWIN-45) — the honest, plain-`rm` counterpart to
103
- // sync pull's fold-into-the-log. See docs/concepts/data-and-keys.md for the full data-at-rest story.
104
- scrubService,
105
- scrubWorld,
106
- stateDirName,
107
- // Opt-in structured stderr logging (VOLTER_TWIN_LOG=1) for the audit trail. Public so a
108
- // CONNECTOR can say on the same stream when the vendor handed it a truncated page — a
109
- // silent shortfall is the one thing a pull must never pass off as the whole resource.
110
- twinLog,
111
- // The kernel's cross-process mutual-exclusion primitive (exclusive-create lockfile with
112
- // stale-holder reclaim). Public so world-runtime can guard concurrent `upWorld` claims of
113
- // one instance dir with the SAME lock semantics the event log uses (TWIN-36).
114
- withFileLock,
115
- worldPaths,
116
- worldStateRoot,
117
- // Where another pack's store is in a World (architecture A3), and the variable the runtime names its data directory in.
118
- ownerStoreRoots,
119
- WORLD_DATA_ENV,
120
- } from './storage.ts';
121
- export type {
122
- AppendEventResult,
123
- CommitQueuedEventsResult,
124
- GenericWorldState,
125
- EnqueueEventResult,
126
- QueuedWorldServiceEvent,
127
- WorldPaths,
128
- WorldReducer,
129
- WorldServiceEvent,
130
- } from './types.ts';
131
- export type { ScrubResult } from './storage.ts';
132
- // The pluggable persistence seam: the sync WorldStore interface, its fs (default) and
133
- // in-memory implementations, the active-store injection point, and the async
134
- // hydrate/flush boundary a serverless (Durable Object / KV / redis) entry uses.
135
- export {
136
- FsWorldStore,
137
- MemoryWorldStore,
138
- getActiveWorldStore,
139
- setActiveWorldStore,
140
- withWorldStore,
141
- hydrateInto,
142
- flushFrom,
143
- } from './world-store.ts';
144
- export type { WorldStore, WorldStat, HydrationSource, HydrationSink } from './world-store.ts';
145
- export type { CheckLoader } from './head.ts';
146
- export { SqlWorldStore } from './world-store-sql.ts';
147
- export type { SqlExec } from './world-store-sql.ts';
148
- // The blob seam (runtime contract R11): byte storage behind byte-carrying handlers, so a
149
- // serverless namespace puts bytes in object storage while local worlds keep today's layout.
150
- export {
151
- FsBlobStore,
152
- MemoryBlobStore,
153
- blobDigest,
154
- getActiveBlobStore,
155
- setActiveBlobStore,
156
- withBlobStore,
157
- readBlobRange,
158
- } from './blob-store.ts';
159
- export type { BlobStore } from './blob-store.ts';
160
- export {
161
- applyTwinWrite,
162
- applyTwinWriteAtomic,
163
- createTwinServer,
164
- CALLER_HEADER,
165
- journalTwinRequest,
166
- twinRequestJournalFailures,
167
- twinRequestCredentials,
168
- readTwinRequestJournal,
169
- resolveTwinRead,
170
- twinRequestJournalEnabled,
171
- twinRequestJournalPath,
172
- readTwinRequestJournalFrom,
173
- type TwinRequestJournalCursor,
174
- twinResources,
175
- } from './serve.ts';
176
- export type {
177
- AtomicTwinWriteDecision,
178
- TwinRequestJournalEntry,
179
- TwinResource,
180
- TwinWriteInput,
181
- TwinWriteResult,
182
- } from './serve.ts';
183
- export { createTwinProxy } from './proxy.ts';
184
- export type { TwinProxy, TwinProxyOptions, VendorRoute } from './proxy.ts';
185
- export {
186
- forkTwin,
187
- isFork,
188
- readForkMeta,
189
- } from './fork.ts';
190
- export type { ForkMeta } from './fork.ts';
191
- export {
192
- appendAction,
193
- appendTransactionCommit,
194
- checkPrecondition,
195
- confirmAction,
196
- listActions,
197
- listTransactionCommits,
198
- pendingActions,
199
- pushablePendingActions,
200
- isTwinBookkeeping,
201
- pendingTransactionCommits,
202
- projectResources,
203
- projectOwnerResources,
204
- OwnerStoreAmbiguousError,
205
- revertAction,
206
- TwinActionPreconditionError, subjectAliases, resolveSubjectId, runWithCorrelationId, currentCorrelationId } from './actions.ts';
207
- export type {
208
- ActionProjection,
209
- ProjectedDelivery,
210
- ProjectedResource,
211
- ProjectedResourcePatch,
212
- ProjectedResourceRef,
213
- TwinAction,
214
- TwinActionOp,
215
- TwinActionPrecondition,
216
- TwinActionPreconditionOp,
217
- TwinActionRevertSpec,
218
- TwinTransactionCommit,
219
- TwinTransactionCommitOp,
220
- TwinTransactionPrecondition,
221
- TwinTransactionRevertSpec,
222
- } from './actions.ts';
223
- // ── Operator control plane (R19/R20): remote refs, queue lifecycle, push ledger,
224
- // apply leases, plan, status. (the twins architecture notes)
225
- // The CHANGESET primitive + the ledger DIFF (docs/concepts/the-model.md v0) — "commit" and
226
- // "diff" for operational reality: a cross-service base marker, the ledger delta since it, and
227
- // the content-addressed, replayable changeset over that delta. State-level by construction
228
- // (it reads the same per-service action ledgers `actions.ts` writes); `volter-world` supplies
229
- // world discovery and thin verbs on top.
230
- export {
231
- approveChangeset,
232
- assertMarkerBelongsTo,
233
- assertSafeChangesetName,
234
- assertValidVerifiers,
235
- buildChangeset,
236
- captureMarker,
237
- changesetContentHash,
238
- changesetHashMatches,
239
- changesetReadiness,
240
- approverOf,
241
- CHANGESET_KIND,
242
- diffLedgers,
243
- formatApplication,
244
- formatChangeset,
245
- formatRebaseReport,
246
- narrateActions,
247
- narrationDrift,
248
- rebaseChangeset,
249
- formatChangesetStatus,
250
- formatLedgerDelta,
251
- formatReplayReport,
252
- formatVerification,
253
- MARKER_KIND,
254
- normalizeChangeset,
255
- parseVerifierExpression,
256
- replayChangeset,
257
- runChangesetVerifiers,
258
- summarizeByVendor,
259
- twinWriteShape,
260
- withApplication,
261
- withVerification,
262
- worldBootMarker,
263
- WORLD_BOOT_MARKER_ID,
264
- } from './changeset.ts';
265
- export type {
266
- ApplyReceipt,
267
- RebaseActionResult,
268
- RebaseReport,
269
- RebaseTarget,
270
- Changeset,
271
- ChangesetAction,
272
- ChangesetApplication,
273
- CompensationEntry,
274
- ChangesetApproval,
275
- ChangesetReadiness,
276
- ChangesetVerification,
277
- ChangesetVerifier,
278
- ChangesetVerifierResult,
279
- LedgerDelta,
280
- LedgerPosition,
281
- LedgerRef,
282
- ReplayActionResult,
283
- ReplayReport,
284
- ReplayTarget,
285
- VendorSummary,
286
- WorldMarker,
287
- } from './changeset.ts';
288
- export { getActivePackAssets, setActivePackAssets, packAsset, assetContentType, confinedAssetPath, LocalPackAssets, BindingPackAssets, type PackAssetStore } from './pack-assets.ts';
289
-
290
- // The git plane (contract "The git plane is a kernel library"): objects, packs, refs, smart HTTP.
291
- export * as git from './git/index.ts';
1
+ // @volter/world-core — the pack contract (docs/contributing/architecture.md, "The pack contract: the kernel's root").
2
+ // This root is everything a Protocol 3 pack may import from the kernel, and nothing else: the manifest's and the
3
+ // descriptor's types, the handler contract, the derived fetch and core a pack's fetch.ts builds, the serve factory's
4
+ // pieces, the kernel's deterministic helpers and the scenario grammar. The kernel itself (the log and the tree read
5
+ // and written directly, the head, the stores, the runtime's scopes) and the plugin contract's surfaces are
6
+ // `@volter/world-core/runtime`, which a pack never imports.
7
+ import { bindSemantics as bindAny, type CoreScope, type Handler } from './derived-core.ts';
8
+ import type { DerivedHandler, DerivedSurface } from './derived.ts';
9
+ import type { DerivedManifest } from './derived-core.ts';
10
+ import { packOf as packOfAny, registerPack as registerAny, type PackDescriptor } from './packRegistry.ts';
292
11
 
293
- // The push arm: the kernel's transaction over a pack's one `perform<Name>Action` (contract section of that name).
12
+ // ── the descriptor ─────────────────────────────────────────────────────────────────────────────
13
+ export type { PackDescriptor, PackTransport } from './packRegistry.ts';
14
+ /** The descriptor a manifest declares, with its vendor ("The descriptor"); given the pack's generated surface (a vendor of
15
+ * lanes: each lane's manifest and surface), with the real-system adapters the kernel derives from them. */
16
+ export const packOf = (
17
+ manifest: { vendor: string; descriptor?: Omit<PackDescriptor, 'vendor'> },
18
+ surface?: DerivedSurface | Record<string, { manifest: DerivedManifest; surface: DerivedSurface }>,
19
+ ): PackDescriptor => packOfAny(manifest, surface);
20
+ /** The pack registered, so the World finds it. */
21
+ export const registerPack = (pack: PackDescriptor): PackDescriptor => registerAny(pack);
294
22
 
295
- // The placeholder remote (contract section of that name): the seed is a pull, never a pending write.
296
- export { PLACEHOLDER_REMOTE, beginPlaceholderPull, endPlaceholderPull, placeholderPullActive, placeholderPullMarkerPath, withPlaceholderPull, placeholderEventsFor } from './placeholder-remote.ts';
23
+ // ── the manifest ───────────────────────────────────────────────────────────────────────────────
24
+ export type { Actor, CoreScope, DerivedManifest, ErrorSpec, LaneRoute, LanesDecl, VendorManifest, FieldRule, ResourceDecl, ScreenDecl, SeedCall, StateField, Transition } from './derived-core.ts';
25
+ export type { ApplicationAnswer, EndpointsDecl, EventRender, EventScheme, EventsDecl, EventTransport, EventValues, EventWrite } from './events.ts';
26
+ export { verifyEvent } from './events.ts';
27
+ export { deriveStateSystem, deriveVendorStateSystem } from './derived-real.ts';
28
+ export type { IngestDecl } from './derived-core.ts';
29
+ export type { SocketDecl, SocketEngine, SocketSession } from './sockets.ts';
30
+ export { machinePool, type ExecSpec, type MachinePool, type MachineProcess, type MachineRun, type MachineSpec } from './machines.ts';
31
+ export type { CorsDecl } from './cors.ts';
297
32
 
298
- export { ownFields, subjectHistory, rebaseBranch, cutCheckpoint, appendParentEntry, wholeLog, branchEntries, branchLogPath, branchMetaPath, CHECKPOINT_EVERY, dropCheckpoint, foldEntries, landedCopy, landedIds, parentEntries, parentLogPath, position, readBranchMeta, readTree, toEntry, toEvent, unpushedEntries, writeBranchMeta } from './log.ts';
299
- export type { BranchMeta, Entry, EntryOp, Receipt } from './log.ts';
300
- export { sealCredential, openSealedCredential, MemoryCredentialStorage, keySealer, transitSealer, type Rewrapped, type Sealer, type TransitSealerOptions, type SealedByVault, type SealedUnderKey } from './credential.ts';
301
- export type { CredentialPayload, CredentialStorage, SealedCredential } from './credential.ts';
302
- export { validateRemoteOrigin, buildRemoteExecute, type CredentialCustody } from './executor.ts';
303
- export type { TwinAuthStrategy } from './executor.ts';
304
- export { clearRoot, authStrategyFor, clearStateSystems, NO_SECRETS_CHECK, readRoot, registerAuthStrategy, registerStateSystem, rootPath, runChecks, stateSystemFor, writeRoot } from './state-system.ts';
305
- export type { Check, CheckVerdict, DeployPolicy, RootConfig, StateSystemAdapters } from './state-system.ts';
306
- export { observeAppends } from './actions.ts';
307
- export { appendActionIfAbsent, appendActionOccurrence } from './actions.ts';
33
+ // ── the handler contract ───────────────────────────────────────────────────────────────────────
34
+ export type { Handler, HandlerContext, WriteHookContext } from './derived-core.ts';
35
+ export type { MultipartPart } from './multipart.ts';
36
+ /** A pack's handlers, by operationId, bound to the manifest: each is answered over the contract's context. */
37
+ export const bindSemantics = (m: Parameters<typeof bindAny>[0], handlers: Record<string, Handler>, scope: CoreScope = {}): Record<string, DerivedHandler> => bindAny(m, handlers as never, scope);
308
38
 
309
- // PROTOCOL 2 — the head and the fold (company contract "The head", "Refresh is the kernel's fold")
310
- export { answerVendorErrors, performEntries, performAtHead, deployableEntries, headOf, boundRoot, loadChecks, loadCheck, openRootCredential, resealRootCredential, destinationOf, openSealedRecord, sealsThroughVault, rootCustody, sealingKey, setCheckLoader, setSealingKeySource, setSealer, currentSealer, openSealedAt, userKek, userKekPath, vendorOf, worldRootOf, RefusedWriteError, VendorWriteError, HeadError } from './head.ts';
311
- export type { BoundRoot, DeployReport, Head, PerformAction, PerformContext, PushOutcome } from './head.ts';
312
- export { observeResource, observeResources, collectObservations, foldObservations } from './observe.ts';
313
- export type { ObservedResource, ObserveReport, Observation } from './observe.ts';
314
- export { readTreeMap, readParentTreeMap, treeStamp, treeChangesSince, originEntries, appendOriginEntry, originLogPath, isUrlParent, parentPosition, positionAt, splitsBatch, assertBatchBoundary } from './log.ts';
39
+ // ── the derived fetch ──────────────────────────────────────────────────────────────────────────
40
+ export { createPackFetch, createVendorFetch, type LanePart, type PackFetchOptions, type PackParts, type PackScenario } from './pack-fetch.ts';
41
+ export { createDerivedFetch } from './derived.ts';
42
+ export type { DerivedCall, DerivedFetch, DerivedFetchOptions, DerivedHandler, DerivedOperation, DerivedSurface } from './derived.ts';
43
+ export { coreFor, crossCutting, derivedRequestScopes, vendorError } from './derived-core.ts';
44
+ export { answerVendorErrors, RefusedWriteError } from './head.ts';
45
+ // a GraphQL API's resolvers (`semantics/graphql.ts`), and the error one answers with the vendor's type
46
+ export { GraphqlError, type GraphqlPart, type GraphqlResolver } from './graphql-wire.ts';
47
+ // what `ctx.vendorFetch` throws when the other vendor cannot be reached (a vendor's call to another as its own behaviour)
48
+ export { VendorUnreachableError } from './vendor-call.ts';
49
+ export { isReadOnlyRequest, READ_ONLY_REQUEST_HEADER } from './request-scope.ts';
315
50
 
316
- // v1 left the kernel (contract "Just like Neon", 5): the names a protocol 1 pack still imports throw on
317
- // their first call, so the catalog stays importable and a pack out of date fails loudly.
318
- export * from './v1-removed.ts';
319
- export { referenceField, registerReferences, packReferences, resolveReferences, type ReferenceDeclaration } from './references.ts';
320
- // the HTTP server seam: the one place the serve path meets the runtime (Bun or Node)
321
- export { serveHttp, nodeBuiltin, WORLD_BOOT_PATH, type HttpServer, type ServeHttpOptions, type HttpHandler } from './serve-http.ts';
322
- // two runtime-neutral helpers for a pack's serve path: a file as a Response, a mirror's client bundle
323
- export { fileResponse, contentTypeOf } from './file-response.ts';
324
- export { bundleClient, filePathOf } from './client-bundle.ts';
325
- // the brand's tokens and faces for a Volter page (the console, the site, the UI kit), fetched at build
326
- export { brandTokensResponse } from './brand-tokens.ts';
51
+ // ── the serve factory ──────────────────────────────────────────────────────────────────────────
52
+ export { serveHttp, serveStream, type HttpHandler, type HttpServer, type ServeHttpOptions } from './serve-http.ts';
53
+ export type { TwinStream, TwinStreamConnection, TwinStreamSink } from './twin-fetch.ts';
54
+ export { statefulTwinManifest, twinManifest } from './scenario.ts';
55
+ export { assetContentType, packAsset } from './pack-assets.ts';
56
+ export { bytesResponse, contentTypeOf, fileResponse } from './file-response.ts';
327
57
 
328
- export { readResourceBlob, readResourceBlobRange, resourceBlobSize, resourceChain } from './resource-blob.ts';
329
- export { mirrorShellUnder } from './mirror-shell.ts';
330
-
331
- export { assertStateRemovable, checkParent, stateGeneration, withAncestryLock, withStateRemoval } from './ancestry.ts';
58
+ // ── the kernel's deterministic helpers ─────────────────────────────────────────────────────────
59
+ export { certificateOf, digest, digestBytes, equalSecrets, oauth1BaseString, oauth1Encode, oauth1Header, oauth1Signature, hmac, jwks, jwtDecode, jwtSign, jwtVerify, keyId, lettersFrom, md5, publicKeyOf, sha256, signWith, SIGNING_ALGORITHMS, uuidFrom, verifyWith } from './signing.ts';
60
+ export type { HandlerCrypto, Jwk, Jwks, JwtVerdict, SigningKey } from './signing.ts';
61
+ export { blobDigest } from './blob-store.ts';
62
+ // compressed bytes a wire carries (a SARIF upload), over web streams
63
+ export { gunzip, gzip } from './bytes.ts';
64
+ // a row's own fields, where the tree's reserved ones (id, type, updatedAt) shadow the vendor's of the same name
65
+ export { ownFields } from './log.ts';
66
+ export type { TwinResource } from './serve.ts';
67
+ // the people a vendor's pages sign in (a `_person` row with its password's hash)
68
+ export { passwordHash, personOf, personWith, recordPerson, type Person } from './people.ts';
69
+ // the World's managed Postgres a handler reaches as `ctx.engine` (managed-database.ts), and a mail's route (`ctx.mail`)
70
+ export { EngineDatabaseError, EngineUnavailableError, quoteIdent, worldClockSql } from './managed-database.ts';
71
+ export type { Batch as EngineBatch, ManagedDatabase, Statement as EngineStatement, StatementResult as EngineStatementResult } from './managed-database.ts';
72
+ export type { Mail, SmtpRoute } from './smtp.ts';
73
+ // S3's wire (contract "S3's wire is a kernel library too") and the git plane (contract "The git plane is a kernel library")
74
+ export * as s3 from './s3/wire.ts';
75
+ export * as clickhouse from './clickhouse/index.ts';
76
+ export { sampleFromSchema } from './schema-sample.ts';
77
+ export * as openaiWire from './openai-wire.ts';
78
+ export * as anthropicWire from './anthropic-wire.ts';
79
+ export * as protobuf from './protobuf.ts';
80
+ export * as grpc from './grpc-wire.ts';
81
+ export { acceptH2Connection, type H2Handler, type Http1Handler } from './h2.ts';
82
+ export { placeholderPng } from './placeholder-image.ts';
83
+ export { presignSigV4, signSigV4, verifySigV4, type SigV4Verdict } from './sigv4.ts';
84
+ export * as redis from './redis/index.ts';
85
+ export * as git from './git/index.ts';
332
86
 
333
- export { captureHistory, captureParentHistory, historyChanges, historyAtInstant, historyDigest, historyEntries, historyLength, historyPrefix, inheritedHistory, originHead, publishOriginHistory, readHistoryView } from './history.ts';
334
- export type { HistoryView, HistoryLayout, HistoryReference, HistoryOrigin } from './history.ts';
335
- export { foldHistory } from './log.ts';
336
- export { volterHome } from './volter-home.ts';
87
+ // ── the scenario grammar (architecture, "Behaviour") ───────────────────────────────────────────
88
+ export { parseScenarioDocument, scenarioFaultResult, ScenarioEngine, ScenarioError } from './scenario.ts';
89
+ export type { PackScenarioAdapter, ScenarioDecision, ScenarioDocument, ScenarioExtractorSpec, ScenarioFault, ScenarioFaultResult, ScenarioFeatures, ScenarioHandler, ScenarioMatcher, ScenarioMissRecord, ScenarioStatus } from './scenario.ts';
package/src/log.ts CHANGED
@@ -20,11 +20,11 @@
20
20
  // and the fold skips a branch entry whose id the parent already holds. Nothing is suppressed,
21
21
  // rebound or quarantined by a bookkeeping row; `unpushed` is the branch log minus what the parent
22
22
  // holds. The parent log accepts the v1 observed-event rows too (`toEntry` reads a delta event as
23
- // an entry; a non-delta observation folds nothing and is kept for `listEvents`), so a protocol 1
24
- // pack's own fold of the logs keeps working while it is deprecated.
23
+ // an entry; a non-delta observation folds nothing and is kept for `listEvents`), so a World whose
24
+ // log was written in that form still reads.
25
25
  import { captureHistory, historyChanges, historyEntryTime, historyEntries, historyLength, historyPrefix, inheritedHistory, inheritedHistoryKey, originHead, readHistoryView, replaceHistoryOrigin, saveHistoryView, validateHistoryOrigin, type HistoryLayout } from './history.ts';
26
26
  import { dirname, join } from 'node:path';
27
- import { canonicalStatePath, checkParent, commitParentPin, pinParent, withAncestryLock } from './ancestry.ts';
27
+ import { canonicalStatePath, checkParent, commitParentPin, pinParent, withAncestryLock, withHistoryLock } from './ancestry.ts';
28
28
  import { resolveReferences } from './references.ts';
29
29
  import { hashFieldValue } from './hash.ts';
30
30
  import type { SubjectFields } from './hash.ts';
@@ -180,7 +180,9 @@ export function readBranchMeta(service: string, root?: string): BranchMeta | nul
180
180
  }
181
181
 
182
182
  export function writeBranchMeta(service: string, meta: BranchMeta, root?: string): void {
183
- withAncestryLock(() => {
183
+ // Under the branch's own history lock (a capture of its parent's nests inside it, child before ancestor); only the
184
+ // pin and the pointer's publication take the coordinator.
185
+ withHistoryLock(worldPaths(service, root).dir, () => {
184
186
  if (meta.parent && (!Number.isInteger(meta.parent.position) || meta.parent.position < 0)) throw new Error('Invalid branch position');
185
187
  const path = branchMetaPath(service, root);
186
188
  const old = readBranchMeta(service, root);
@@ -195,6 +197,7 @@ export function writeBranchMeta(service: string, meta: BranchMeta, root?: string
195
197
  const previousParents = [...(old?.previousParents ?? [])];
196
198
  if (old?.parent?.directory && old.parent.generation) previousParents.push({ directory: old.parent.directory, generation: old.parent.generation });
197
199
  if (previousParents.length) meta = { ...meta, previousParents: [...new Map(previousParents.map(p => [p.directory, p])).values()] };
200
+ let local: { directory: string; view: string; generation?: string } | undefined;
198
201
  if (meta.parent && !isUrlParent(meta.parent.at)) {
199
202
  const directory = canonicalStatePath(worldPaths(service, meta.parent.at).dir);
200
203
  const view = meta.parent.view ?? captureHistory(service, meta.parent.at).view;
@@ -202,9 +205,8 @@ export function writeBranchMeta(service: string, meta: BranchMeta, root?: string
202
205
  if (meta.parent.viewDirectory && canonicalStatePath(viewDirectory) !== canonicalStatePath(worldPaths(service, root).dir)) throw new Error('Composed history view must belong to this branch');
203
206
  const descriptor = readHistoryView(viewDirectory, view);
204
207
  historyPrefix(descriptor, meta.parent.position);
205
- const parent = meta.parent;
206
- const generation = pinParent(directory, path, parent.generation);
207
- meta = { ...meta, parent: { ...parent, view, at: canonicalStatePath(parent.at), directory, generation } };
208
+ // the parent the view was captured from: a parent removed or re-created since is refused at the pin
209
+ local = { directory, view, generation: meta.parent.generation ?? (viewDirectory === directory ? descriptor.owner.generation : undefined) };
208
210
  }
209
211
  if (meta.parent && isUrlParent(meta.parent.at) && !meta.parent.view) {
210
212
  const head = originHead(service, root);
@@ -214,9 +216,16 @@ export function writeBranchMeta(service: string, meta: BranchMeta, root?: string
214
216
  meta = { ...meta, parent: { ...meta.parent, view: empty.view } };
215
217
  } else throw new Error('Origin has no completed immutable history view');
216
218
  }
217
- getActiveWorldStore().mkdir(dirname(path));
218
- getActiveWorldStore().writeAtomic(path, `${JSON.stringify(meta, null, 2)}\n`);
219
- if (meta.parent?.directory && !isUrlParent(meta.parent.at)) commitParentPin(meta.parent.directory, path);
219
+ withAncestryLock(() => {
220
+ if (local && meta.parent) {
221
+ const parent = meta.parent;
222
+ const generation = pinParent(local.directory, path, local.generation);
223
+ meta = { ...meta, parent: { ...parent, view: local.view, at: canonicalStatePath(parent.at), directory: local.directory, generation } };
224
+ }
225
+ getActiveWorldStore().mkdir(dirname(path));
226
+ getActiveWorldStore().writeAtomic(path, `${JSON.stringify(meta, null, 2)}\n`);
227
+ if (meta.parent?.directory && !isUrlParent(meta.parent.at)) commitParentPin(meta.parent.directory, path);
228
+ });
220
229
  });
221
230
  }
222
231
 
@@ -288,7 +297,7 @@ export function appendOriginEntry(entry: Entry, root?: string): { appended: bool
288
297
  const path = originLogPath(entry.service, root);
289
298
  const store = getActiveWorldStore();
290
299
  store.mkdir(dirname(path));
291
- return withAncestryLock(() => store.withLock(`${path}.lock`, () => {
300
+ return withHistoryLock(worldPaths(entry.service, root).dir, () => store.withLock(`${path}.lock`, () => {
292
301
  if (readRows<{ id?: string }>(path).some((r) => r.id === entry.id)) return { appended: false };
293
302
  store.append(path, `${JSON.stringify(entry)}\n`);
294
303
  return { appended: true };
@@ -433,7 +442,7 @@ export function readTree(service: string, root?: string, opts: { until?: string;
433
442
  /** The upstream view for observation diffing, without this root's local overlay. Inherited
434
443
  * history keeps its own layout: an ancestor's local writes are part of our pinned base. */
435
444
  export function readParentTreeMap(service: string, root?: string): Tree {
436
- return withAncestryLock(() => {
445
+ return withHistoryLock(worldPaths(service, root).dir, () => {
437
446
  const inherited = inheritedHistory(service, root);
438
447
  const own = ownParentEntries(service, root);
439
448
  return foldHistory([...(inherited ? historyEntries(inherited) : []), ...own], {
@@ -505,11 +514,11 @@ function currentTree(service: string, root?: string): { tree: Tree; memo?: TreeM
505
514
  let memos = treeMemos.get(store);
506
515
  if (!memos) { memos = new Map(); treeMemos.set(store, memos); }
507
516
  const slot = `${service}\u0000${root ?? ''}`;
508
- // A hit needs no coordinator: a memo is only ever stored from a fold made under it, and while the
517
+ // A hit needs no lock: a memo is only ever stored from a fold made under the history lock, and while the
509
518
  // facts still match that fold, nothing was written since. A writer mid-batch has moved them.
510
519
  const unlocked = memos.get(slot);
511
520
  if (unlocked && unlocked.parentKey === parentKeyOf(service, root) && unlocked.branchKey === statKey(branchLogPath(service, root))) return { tree: unlocked.tree, memo: unlocked };
512
- return withAncestryLock(() => {
521
+ return withHistoryLock(worldPaths(service, root).dir, () => {
513
522
  const parentKey = parentKeyOf(service, root); const branchKey = statKey(branchLogPath(service, root));
514
523
  const held = memos.get(slot);
515
524
  if (held && held.parentKey === parentKey && held.branchKey === branchKey) return { tree: held.tree, memo: held };
@@ -571,7 +580,7 @@ export function treeChangesSince(service: string, root: string | undefined, sinc
571
580
  }
572
581
 
573
582
  function readTreeMapFull(service: string, root?: string, opts: { until?: string; at?: number; view?: string } = {}): Tree {
574
- return withAncestryLock(() => {
583
+ return withHistoryLock(worldPaths(service, root).dir, () => {
575
584
  if (opts.at !== undefined || opts.view !== undefined) {
576
585
  const view = opts.view ? readHistoryView(worldPaths(service, root).dir, opts.view) : captureHistory(service, root).descriptor;
577
586
  const at = opts.at ?? historyLength(view.layout);
@@ -616,7 +625,7 @@ function readTreeMapFull(service: string, root?: string, opts: { until?: string;
616
625
  });
617
626
  }
618
627
  export function cutCheckpoint(service: string, root?: string): void {
619
- return withAncestryLock(() => {
628
+ return withHistoryLock(worldPaths(service, root).dir, () => {
620
629
  dropCheckpoint(service, root);
621
630
  const subjects = [...readTreeMap(service, root).values()];
622
631
  const inherited = inheritedHistory(service, root); const own = ownParentEntries(service, root);
@@ -695,7 +704,7 @@ export function appendParentEntry(entry: Entry, root?: string): { appended: bool
695
704
  const path = parentLogPath(entry.service, root);
696
705
  const store = getActiveWorldStore();
697
706
  store.mkdir(dirname(path));
698
- return withAncestryLock(() => store.withLock(`${path}.lock`, () => {
707
+ return withHistoryLock(worldPaths(entry.service, root).dir, () => store.withLock(`${path}.lock`, () => {
699
708
  let indexes = parentIdIndex.get(store);
700
709
  if (!indexes) { indexes = new Map(); parentIdIndex.set(store, indexes); }
701
710
  let index = indexes.get(path);
@@ -726,7 +735,7 @@ export function wholeLog(service: string, root?: string): Entry[] {
726
735
  * result, never a stop. An unbranched world (no pointer) has nothing to rebase.
727
736
  */
728
737
  export function rebaseBranch(service: string, root?: string, opts: { origin?: boolean } = {}): { moved: boolean; from: number; to: number; conflicts: Array<{ entryId: string; subject: { type: string; id: string }; field: string; op: string; expected?: unknown; actual?: unknown }> } {
729
- return withAncestryLock(() => {
738
+ return withHistoryLock(worldPaths(service, root).dir, () => {
730
739
  const meta = readBranchMeta(service, root);
731
740
  if (!meta?.parent) return { moved: false, from: 0, to: 0, conflicts: [] };
732
741
  if (opts.origin && !meta.origin) throw new Error('This local fork has no tracked origin; clone the origin before branching');