@almadar/shell-runtime 0.0.0-stage → 0.1.0

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 (180) hide show
  1. package/dist/chunk-2JU7Y4KU.js +21 -0
  2. package/dist/chunk-46RWK2B5.js +28 -0
  3. package/dist/chunk-4J2QEIUV.js +78 -0
  4. package/dist/chunk-4SEK5ER2.js +8 -0
  5. package/dist/chunk-4ZICQ5PM.js +192 -0
  6. package/dist/chunk-53IPZXDP.js +76 -0
  7. package/dist/chunk-5D63EMO5.js +16 -0
  8. package/dist/chunk-64IH2SMY.js +22 -0
  9. package/dist/chunk-7SDV3QWR.js +67 -0
  10. package/dist/chunk-CPSQXEJ6.js +55 -0
  11. package/dist/chunk-CQP5XAX6.js +173 -0
  12. package/dist/chunk-CROS2GEX.js +49 -0
  13. package/dist/chunk-D4XJTBLB.js +217 -0
  14. package/dist/chunk-D5USD2EX.js +232 -0
  15. package/dist/chunk-DYOJGLIX.js +25 -0
  16. package/dist/chunk-ELBLT2HZ.js +1 -0
  17. package/dist/chunk-EV56K4GB.js +63 -0
  18. package/dist/chunk-EZZYLTWY.js +1 -0
  19. package/dist/chunk-FQ6IZMIU.js +10 -0
  20. package/dist/chunk-FWA5K7Q2.js +48 -0
  21. package/dist/chunk-HC6ERSAH.js +55 -0
  22. package/dist/chunk-HLOUDLPI.js +48 -0
  23. package/dist/chunk-HMK6YMQS.js +135 -0
  24. package/dist/chunk-HNOAZWFH.js +19 -0
  25. package/dist/chunk-IHQLE5M7.js +62 -0
  26. package/dist/chunk-IOPUS6Q5.js +15 -0
  27. package/dist/chunk-JFWFDUTR.js +35 -0
  28. package/dist/chunk-LZIOTBFX.js +1 -0
  29. package/dist/chunk-MHYSHSRG.js +54 -0
  30. package/dist/chunk-MLKGABMK.js +7 -0
  31. package/dist/chunk-MZKIL5IN.js +74 -0
  32. package/dist/chunk-NAECVIAR.js +322 -0
  33. package/dist/chunk-NATGCIVM.js +583 -0
  34. package/dist/chunk-O57GKTYU.js +30 -0
  35. package/dist/chunk-ODJCZ27I.js +50 -0
  36. package/dist/chunk-P53CKOME.js +1 -0
  37. package/dist/chunk-Q2H75UYT.js +92 -0
  38. package/dist/chunk-Q7JK4KY7.js +9 -0
  39. package/dist/chunk-QELZ6TEJ.js +208 -0
  40. package/dist/chunk-QQRDUMB2.js +40 -0
  41. package/dist/chunk-RBUMDYFS.js +681 -0
  42. package/dist/chunk-REPX5QPI.js +57 -0
  43. package/dist/chunk-SAS5KKCR.js +43 -0
  44. package/dist/chunk-SKLMWHQD.js +109 -0
  45. package/dist/chunk-SOQDEPME.js +131 -0
  46. package/dist/chunk-SWPDU752.js +28 -0
  47. package/dist/chunk-T775TUCD.js +18 -0
  48. package/dist/chunk-UBN5JJKZ.js +26 -0
  49. package/dist/chunk-UJHOUZAL.js +36 -0
  50. package/dist/chunk-UP6GGGAN.js +34 -0
  51. package/dist/chunk-VMOBW7RK.js +21 -0
  52. package/dist/chunk-VNMG7NKY.js +69 -0
  53. package/dist/chunk-WNPNNYXY.js +22 -0
  54. package/dist/chunk-XB5GYODW.js +28 -0
  55. package/dist/chunk-XXWNMJI6.js +15 -0
  56. package/dist/chunk-YL2SO5TP.js +334 -0
  57. package/dist/chunk-YO4LWS3I.js +606 -0
  58. package/dist/chunk-ZAQSS47X.js +157 -0
  59. package/dist/chunk-ZCQUUJIF.js +129 -0
  60. package/dist/client/EventTransport.d.ts +131 -0
  61. package/dist/client/EventTransport.js +2 -0
  62. package/dist/client/ServerBridge.d.ts +126 -0
  63. package/dist/client/ServerBridge.js +3 -0
  64. package/dist/client/awaiting.d.ts +28 -0
  65. package/dist/client/awaiting.js +2 -0
  66. package/dist/client/channel-transport.d.ts +69 -0
  67. package/dist/client/channel-transport.js +2 -0
  68. package/dist/client/circuit-store.d.ts +76 -0
  69. package/dist/client/circuit-store.js +4 -0
  70. package/dist/client/client-kernel.d.ts +113 -0
  71. package/dist/client/client-kernel.js +1 -0
  72. package/dist/client/declared-input-dispatch.d.ts +5 -0
  73. package/dist/client/declared-input-dispatch.js +2 -0
  74. package/dist/client/inbound-dispatch.d.ts +5 -0
  75. package/dist/client/inbound-dispatch.js +2 -0
  76. package/dist/client/local-fold.d.ts +26 -0
  77. package/dist/client/local-fold.js +2 -0
  78. package/dist/client/render-sigils.d.ts +24 -0
  79. package/dist/client/render-sigils.js +2 -0
  80. package/dist/client/state-book.d.ts +37 -0
  81. package/dist/client/state-book.js +2 -0
  82. package/dist/client/trait-mount-error.d.ts +9 -0
  83. package/dist/client/trait-mount-error.js +2 -0
  84. package/dist/client/trait-types.d.ts +67 -0
  85. package/dist/client/trait-types.js +1 -0
  86. package/dist/credentials/env-vars.d.ts +14 -0
  87. package/dist/credentials/env-vars.js +3 -0
  88. package/dist/credentials/scope.d.ts +50 -0
  89. package/dist/credentials/scope.js +2 -0
  90. package/dist/credentials/seed.d.ts +21 -0
  91. package/dist/credentials/seed.js +2 -0
  92. package/dist/credentials/store.d.ts +110 -0
  93. package/dist/credentials/store.js +2 -0
  94. package/dist/effects/in-flight-calls.d.ts +36 -0
  95. package/dist/effects/in-flight-calls.js +2 -0
  96. package/dist/effects/on-device-model.d.ts +22 -0
  97. package/dist/effects/on-device-model.js +2 -0
  98. package/dist/events/EventBus.d.ts +90 -0
  99. package/dist/events/EventBus.js +2 -0
  100. package/dist/events/emit-stamp.d.ts +47 -0
  101. package/dist/events/emit-stamp.js +2 -0
  102. package/dist/index-hT1xCdTq.d.ts +46 -0
  103. package/dist/index.d.ts +60 -0
  104. package/dist/index.js +59 -0
  105. package/dist/kernel/beacon.d.ts +32 -0
  106. package/dist/kernel/beacon.js +2 -0
  107. package/dist/kernel/decode.d.ts +15 -0
  108. package/dist/kernel/decode.js +2 -0
  109. package/dist/kernel/engine.d.ts +94 -0
  110. package/dist/kernel/engine.js +11 -0
  111. package/dist/kernel/frame-applier.d.ts +43 -0
  112. package/dist/kernel/frame-applier.js +2 -0
  113. package/dist/kernel/host.d.ts +95 -0
  114. package/dist/kernel/host.js +9 -0
  115. package/dist/kernel/http.d.ts +302 -0
  116. package/dist/kernel/http.js +6 -0
  117. package/dist/kernel/lane.d.ts +28 -0
  118. package/dist/kernel/lane.js +2 -0
  119. package/dist/kernel/oauth-effects.d.ts +25 -0
  120. package/dist/kernel/oauth-effects.js +7 -0
  121. package/dist/kernel/oauth-port.d.ts +31 -0
  122. package/dist/kernel/oauth-port.js +2 -0
  123. package/dist/kernel/os-port.d.ts +133 -0
  124. package/dist/kernel/os-port.js +2 -0
  125. package/dist/kernel/program-effects.d.ts +65 -0
  126. package/dist/kernel/program-effects.js +2 -0
  127. package/dist/kernel/wire.d.ts +66 -0
  128. package/dist/kernel/wire.js +1 -0
  129. package/dist/loader/http-loader.d.ts +111 -0
  130. package/dist/loader/http-loader.js +2 -0
  131. package/dist/loader/lazy-page.d.ts +12 -0
  132. package/dist/loader/lazy-page.js +2 -0
  133. package/dist/loader/schema-loader.d.ts +160 -0
  134. package/dist/loader/schema-loader.js +1 -0
  135. package/dist/persistence/native-memory.d.ts +28 -0
  136. package/dist/persistence/native-memory.js +2 -0
  137. package/dist/runtime/effects/composition/compose-behaviors.d.ts +58 -0
  138. package/dist/runtime/effects/composition/compose-behaviors.js +4 -0
  139. package/dist/runtime/effects/composition/event-wiring.d.ts +38 -0
  140. package/dist/runtime/effects/composition/event-wiring.js +2 -0
  141. package/dist/runtime/effects/composition/index.d.ts +5 -0
  142. package/dist/runtime/effects/composition/index.js +6 -0
  143. package/dist/runtime/effects/composition/layout-strategy.d.ts +35 -0
  144. package/dist/runtime/effects/composition/layout-strategy.js +2 -0
  145. package/dist/runtime/effects/composition/pipe.d.ts +25 -0
  146. package/dist/runtime/effects/composition/pipe.js +2 -0
  147. package/dist/runtime/entities/mockStoreSeed.d.ts +56 -0
  148. package/dist/runtime/entities/mockStoreSeed.js +3 -0
  149. package/dist/runtime/entities/seedBrowserStore.d.ts +28 -0
  150. package/dist/runtime/entities/seedBrowserStore.js +2 -0
  151. package/dist/runtime/entities/std-mock-seed.d.ts +87 -0
  152. package/dist/runtime/entities/std-mock-seed.js +2 -0
  153. package/dist/runtime/evaluation/local-store-transport.d.ts +68 -0
  154. package/dist/runtime/evaluation/local-store-transport.js +18 -0
  155. package/dist/runtime/evaluation/residence-transport.d.ts +15 -0
  156. package/dist/runtime/evaluation/residence-transport.js +2 -0
  157. package/dist/runtime/evaluation/routed-persistence.d.ts +9 -0
  158. package/dist/runtime/evaluation/routed-persistence.js +2 -0
  159. package/dist/runtime/events/identity/routing.d.ts +84 -0
  160. package/dist/runtime/events/identity/routing.js +2 -0
  161. package/dist/runtime/time/TickScheduler.d.ts +77 -0
  162. package/dist/runtime/time/TickScheduler.js +3 -0
  163. package/dist/runtime/time/cron.d.ts +25 -0
  164. package/dist/runtime/time/cron.js +2 -0
  165. package/dist/runtime/time/duration.d.ts +20 -0
  166. package/dist/runtime/time/duration.js +2 -0
  167. package/dist/runtime/traits/OrbitalTraitParsing.d.ts +34 -0
  168. package/dist/runtime/traits/OrbitalTraitParsing.js +2 -0
  169. package/dist/runtime/traits/listen-targets.d.ts +16 -0
  170. package/dist/runtime/traits/listen-targets.js +3 -0
  171. package/dist/runtime/traits/trait-index.d.ts +35 -0
  172. package/dist/runtime/traits/trait-index.js +3 -0
  173. package/dist/runtime/types.d.ts +574 -0
  174. package/dist/runtime/types.js +2 -0
  175. package/dist/service/default-call-service.d.ts +23 -0
  176. package/dist/service/default-call-service.js +3 -0
  177. package/dist/service/service-provider.d.ts +37 -0
  178. package/dist/service/service-provider.js +2 -0
  179. package/package.json +46 -3
  180. package/README.md +0 -3
@@ -0,0 +1,76 @@
1
+ import { AwaitingRegistry } from './awaiting.js';
2
+ import { StateBook } from './state-book.js';
3
+ import { EntityRow, EventPayload, TraitDefinition } from '@almadar/core';
4
+ import { RollbackCause, TransitionObserver } from './trait-types.js';
5
+ import '@almadar/core/kernel-wire';
6
+
7
+ /**
8
+ * CircuitStore — P2, `docs/Almadar_Runtime_Stateless_Stateful_PLAN.md` §4.2.
9
+ *
10
+ * The browser client's circuit state: each trait's state and entity frame as the kernel last reported them.
11
+ *
12
+ * `snapshot`/`restore` are the JS twin of orbital-core's
13
+ * `RuntimeKernel::snapshot_trait`/`restore_trait` (`runtime/kernel.rs`) — the
14
+ * `runtimeOptimistic` rollback point. `subscribe`/`getVersion` let a later
15
+ * React adapter drive `useSyncExternalStore` off this store without the
16
+ * store knowing anything about React.
17
+ *
18
+ * @packageDocumentation
19
+ */
20
+
21
+ /**
22
+ * A trait instance's state + entity frame at a point in time — the twin of
23
+ * orbital-core's `TraitSnapshot { state, entity }`. `frame` is `undefined`
24
+ * when the trait had no frame row yet (mirrors Rust's `Value::Null` case:
25
+ * restoring must leave the row absent, not invent one).
26
+ */
27
+ interface TraitSnapshot {
28
+ state: string;
29
+ frame: EntityRow | undefined;
30
+ }
31
+ interface CircuitStore {
32
+ /** Each trait's state as the kernel last reported it. */
33
+ readonly states: StateBook;
34
+ /** The entity-frame map (`(set @entity.X)` writes), keyed by
35
+ * `IndexedTrait.frameKey`. */
36
+ readonly frames: Map<string, EntityRow>;
37
+ /** Embedded child → the payload its composer last composed it with (sticky `@callsitePayload`). */
38
+ readonly callsitePayloads: Map<string, EventPayload>;
39
+ /** Traits awaiting a server round trip (per-trait subscriptions; see `AwaitingRegistry`). */
40
+ readonly awaiting: AwaitingRegistry;
41
+ /**
42
+ * Capture `trait`'s current state + its frame row, for a
43
+ * `runtimeOptimistic` dispatch's pre-commit rollback point. `frameKey`
44
+ * defaults to `trait` (the non-`[shared]`-entity case); a caller holding
45
+ * the trait's `IndexedTrait.frameKey` (the `[shared]` case) passes it
46
+ * explicitly so the snapshot reads the SAME row the dispatch will write.
47
+ */
48
+ snapshot(trait: string, entityId?: string, frameKey?: string): TraitSnapshot;
49
+ /**
50
+ * Roll `trait` back to a prior snapshot: state via a reconcile write (no
51
+ * guard evaluation — `rollbackState`, which reports the hop to the observer), frame via REPLACE (never merge — an
52
+ * optimistic commit may have added fields since the snapshot that a merge
53
+ * would keep, the same reasoning as `RuntimeKernel::restore_trait`).
54
+ */
55
+ restore(trait: string, entityId: string | undefined, snapshot: TraitSnapshot, frameKey: string | undefined, cause: RollbackCause): void;
56
+ /**
57
+ * Notify subscribers that circuit state changed. Callers (the client
58
+ * role, `client-role.ts`) call this ONCE after a dispatch/fold finishes
59
+ * writing state — the store never fires this on its own.
60
+ */
61
+ notify(): void;
62
+ /** `useSyncExternalStore`-shaped subscription. Returns the unsubscribe fn. */
63
+ subscribe(listener: () => void): () => void;
64
+ /** Monotonic version, bumped by every `notify()` call. */
65
+ getVersion(): number;
66
+ }
67
+ /**
68
+ * The one in-memory `CircuitStore` implementation. Per-request (stateless
69
+ * server) or long-lived (stateful server, browser client) is only a
70
+ * question of how long the caller HOLDS the returned store — the
71
+ * implementation itself carries no lifetime opinion.
72
+ */
73
+ declare function createMemoryCircuitStore(traits?: readonly TraitDefinition[], observer?: TransitionObserver): CircuitStore;
74
+
75
+ export { createMemoryCircuitStore };
76
+ export type { CircuitStore, TraitSnapshot };
@@ -0,0 +1,4 @@
1
+ export { createMemoryCircuitStore } from '../chunk-ODJCZ27I.js';
2
+ import '../chunk-Q2H75UYT.js';
3
+ import '../chunk-HC6ERSAH.js';
4
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,113 @@
1
+ import { OrbitalEventResponse, OrbitalEventRequest, DispatchMode, MountSeed, TransitionRejection } from '@almadar/core';
2
+ import { CircuitStore } from './circuit-store.js';
3
+ import './awaiting.js';
4
+ import './state-book.js';
5
+ import './trait-types.js';
6
+ import '@almadar/core/kernel-wire';
7
+
8
+ /**
9
+ * The contract of a client kernel: what a view dispatches into and what it gets back. `@almadar/ui`'s kernel client
10
+ * (over `@almadar/kernel/client`) implements it.
11
+ */
12
+
13
+ /** One `ClientKernel.dispatch()` call's settled outcome. */
14
+ interface ClientKernelOutcome {
15
+ response: OrbitalEventResponse;
16
+ mode: DispatchMode;
17
+ /**
18
+ * True when `onLocal` already received the local arm's response (the leg
19
+ * was posted). `serverEffects` then holds only what the server's fold
20
+ * added — the local ones were painted before the round trip.
21
+ */
22
+ localPainted?: boolean;
23
+ serverEffects?: Pick<OrbitalEventResponse, 'clientEffects' | 'clientEffectsByTrait'>;
24
+ /**
25
+ * A tick-lane dispatch: what its post's fold added on top of the local run,
26
+ * once the post settles (undefined when a newer firing superseded it). The
27
+ * drain never waits on it; the caller paints it when it lands.
28
+ */
29
+ tickSettled?: Promise<Pick<OrbitalEventResponse, 'clientEffects' | 'clientEffectsByTrait'> | undefined>;
30
+ }
31
+ /** Per-dispatch hooks: `onLocal` sees the locally-evaluated response before its server leg is sent. */
32
+ interface ClientDispatchHooks {
33
+ onLocal?: (local: OrbitalEventResponse) => void;
34
+ }
35
+ /** Mount hooks: `onLocal` sees each seed's local response before the mount leg is sent. */
36
+ interface ClientMountHooks {
37
+ onLocal?: (trait: string, local: OrbitalEventResponse) => void;
38
+ }
39
+ /** One `ClientKernel.dispatchMount()` call's settled outcome. */
40
+ interface ClientMountOutcome {
41
+ /** Each seed's local run, in seed order (already painted through `onLocal`). */
42
+ seeds: Array<{
43
+ trait: string;
44
+ event: string;
45
+ mode: DispatchMode;
46
+ local: OrbitalEventResponse;
47
+ }>;
48
+ /** Whether any mount leg was posted. */
49
+ posted: boolean;
50
+ success: boolean;
51
+ error?: string;
52
+ /** Per-trait effect failures the posted legs reported (`effect-failed`). */
53
+ rejections: TransitionRejection[];
54
+ /** What the posted legs added: the server's effects and the emits the client had not run. */
55
+ serverEffects: Pick<OrbitalEventResponse, 'clientEffects' | 'clientEffectsByTrait'>;
56
+ emittedEvents: OrbitalEventResponse['emittedEvents'];
57
+ }
58
+ interface ClientKernel {
59
+ /**
60
+ * Enqueue one event. FIFO per kernel: this entry's local dispatch → post
61
+ * (per the posting rule) → fold → `store.notify()` all complete before the
62
+ * next queued entry's local dispatch begins — the twin of orbital-client's
63
+ * `ClientKernel::dispatch` being called serially off one queue, ported to
64
+ * JS's single-threaded-but-concurrent-microtask model where two `dispatch`
65
+ * calls made back to back would otherwise interleave.
66
+ *
67
+ * A `request.tick`-stamped entry coalesces onto a pending entry with the
68
+ * SAME `(event, targetTrait)` that is itself tick-stamped — same contract
69
+ * as `@almadar/ui`'s `lib/event-queue-coalesce.ts` `enqueueEvent` (see
70
+ * that file's tests, mirrored in `client-kernel.test.ts`): only the
71
+ * pending entry's `payload` is replaced (its FIFO slot and every other
72
+ * field are kept), a sourceless/non-tick entry is never coalesced, and an
73
+ * entry already shifted off the queue (in flight) is never a coalesce
74
+ * target. Every caller coalesced onto the same pending entry resolves to
75
+ * that ONE entry's eventual outcome.
76
+ *
77
+ * A tick-stamped entry resolves after its LOCAL dispatch; its post goes
78
+ * out on a per-(event, trait) newest-wins lane outside the FIFO, with no
79
+ * rollback, so a tick round trip never delays a command.
80
+ */
81
+ dispatch(request: OrbitalEventRequest, hooks?: ClientDispatchHooks): Promise<ClientKernelOutcome>;
82
+ /**
83
+ * Dispatch a server-pushed live message of THIS client's own running
84
+ * request (`PushTarget` `origin`). Outside the FIFO, because the request
85
+ * producing it is the entry the FIFO is waiting on; progress dispatches run
86
+ * one at a time, in push order, and never mark traits awaiting.
87
+ */
88
+ dispatchProgress(request: OrbitalEventRequest): Promise<ClientKernelOutcome>;
89
+ /**
90
+ * Show the result of a dispatch the host ran on its own (`EventTransport.subscribeHostDispatches`):
91
+ * the host's states, rows and render land in this view. Nothing runs here and nothing is posted,
92
+ * so the dispatch's effects happen once, on the host. Host dispatches fold one at a time, in order.
93
+ */
94
+ foldHostDispatch(request: OrbitalEventRequest, response: OrbitalEventResponse): Promise<ClientKernelOutcome>;
95
+ /**
96
+ * Mount several traits in ONE FIFO entry: every seed's local arm runs and
97
+ * paints, then one `mount` leg per owning orbital is posted and folded.
98
+ */
99
+ dispatchMount(seeds: readonly MountSeed[], hooks?: ClientMountHooks, base?: Pick<OrbitalEventRequest, 'payload' | 'entityId' | 'clientId' | 'locale'>): Promise<ClientMountOutcome>;
100
+ readonly store: CircuitStore;
101
+ }
102
+ /**
103
+ * Show the result of a dispatch THIS kernel already ran (a tick frame's aggregate response or one of its
104
+ * cascade dispatches): the response's states, rows and paint land in the view's store. Nothing runs and
105
+ * nothing is posted: the in-process kernel owns the state, so (unlike `foldHostDispatch`) the server fold
106
+ * (`applyServerResponse`) is never called. `traceHops` reports the response's executed hops to the transition
107
+ * observer; a frame's aggregate response carries tick hops the kernel's tick observer already reported. `notify` wakes the store's subscribers after the fold; a frame folds several responses and notifies on the last only.
108
+ */
109
+ interface LocalFoldKernel {
110
+ foldLocalResponse(response: OrbitalEventResponse, traceHops: boolean, notify: boolean): Promise<void>;
111
+ }
112
+
113
+ export type { ClientDispatchHooks, ClientKernel, ClientKernelOutcome, ClientMountHooks, ClientMountOutcome, LocalFoldKernel };
@@ -0,0 +1 @@
1
+ import '../chunk-LZIOTBFX.js';
@@ -0,0 +1,5 @@
1
+ import { OrbitalSchema, ExternalInputRequest, OrbitalEventRequest, OrbitalEventResponse } from '@almadar/core';
2
+
3
+ declare function dispatchDeclaredInput(schema: OrbitalSchema | null | undefined, orbitalName: string, request: ExternalInputRequest, send: (orbitalName: string, request: OrbitalEventRequest) => Promise<OrbitalEventResponse>): Promise<OrbitalEventResponse>;
4
+
5
+ export { dispatchDeclaredInput };
@@ -0,0 +1,2 @@
1
+ export { dispatchDeclaredInput } from '../chunk-DYOJGLIX.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,5 @@
1
+ import { OrbitalSchema, InboundDelivery, OrbitalEventRequest, OrbitalEventResponse, InboundAnswer } from '@almadar/core';
2
+
3
+ declare function dispatchInbound(schema: OrbitalSchema | null | undefined, name: string, delivery: InboundDelivery, send: (orbitalName: string, request: OrbitalEventRequest) => Promise<OrbitalEventResponse>, credential: (name: string) => Promise<string | null | undefined>): Promise<InboundAnswer>;
4
+
5
+ export { dispatchInbound };
@@ -0,0 +1,2 @@
1
+ export { dispatchInbound } from '../chunk-2JU7Y4KU.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,26 @@
1
+ import { OrbitalEventResponse } from '@almadar/core';
2
+ import { LocalFoldKernel } from './client-kernel.js';
3
+ import { CircuitStore } from './circuit-store.js';
4
+ import { TransitionObserver } from './trait-types.js';
5
+ import './awaiting.js';
6
+ import './state-book.js';
7
+ import '@almadar/core/kernel-wire';
8
+
9
+ /**
10
+ * The view's side of a dispatch the in-process kernel already ran: report its executed hops to the observer,
11
+ * mirror its states, rows and sticky callsite payloads into the `CircuitStore`, then notify subscribers.
12
+ * One implementation for every response the kernel produces (a dispatch, a mount seed, a posted leg's fold,
13
+ * a tick frame).
14
+ */
15
+
16
+ declare function mirrorResponse(store: CircuitStore, frameKeyOf: (trait: string) => string | undefined, response: OrbitalEventResponse): void;
17
+ declare function traceResponse(observer: TransitionObserver | undefined, response: OrbitalEventResponse): void;
18
+ interface LocalFoldOptions {
19
+ store: CircuitStore;
20
+ frameKeyOf(trait: string): string | undefined;
21
+ observer?: TransitionObserver;
22
+ }
23
+ declare function createLocalFold(opts: LocalFoldOptions): LocalFoldKernel;
24
+
25
+ export { createLocalFold, mirrorResponse, traceResponse };
26
+ export type { LocalFoldOptions };
@@ -0,0 +1,2 @@
1
+ export { createLocalFold, mirrorResponse, traceResponse } from '../chunk-QQRDUMB2.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,24 @@
1
+ import { OrbitalDefinition, NavItem, PageRef } from '@almadar/core';
2
+
3
+ /**
4
+ * The render sigils `@pages` and `@currentTheme`, assembled one way for every effect
5
+ * stage (the server's and the index runner's). Mirrors the compiler's resolver.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+
10
+ /** The baseline theme `@currentTheme` falls back to when no orbital or app theme is declared. Mirrors the compiler's `DEFAULT_THEME_KEY`. */
11
+ declare const DEFAULT_THEME_KEY = "minimalist-light";
12
+ /**
13
+ * Map an orbital's inline pages to the `NavItem[]` the `@pages` sigil yields: one
14
+ * entry per root page that declares `@label` (`href = page.path`, its `@icon` and
15
+ * `@roles`). References (resolved before any stage runs) and `:param` pages are
16
+ * skipped — the Rust resolver's filter.
17
+ */
18
+ declare function inlineNavItems(pages: readonly PageRef[]): NavItem[];
19
+ /** `@pages` is app-wide: the root pages of every orbital, deduped by path, in orbital order. */
20
+ declare function appNavItems(orbitals: Iterable<Pick<OrbitalDefinition, 'pages'>>): NavItem[];
21
+ /** `@currentTheme`: the orbital's declared theme, else the app's theme key, else the baseline. */
22
+ declare function sigilThemeKey(orbitalTheme: OrbitalDefinition['theme'], appThemeKey?: string): string;
23
+
24
+ export { DEFAULT_THEME_KEY, appNavItems, inlineNavItems, sigilThemeKey };
@@ -0,0 +1,2 @@
1
+ export { DEFAULT_THEME_KEY, appNavItems, inlineNavItems, sigilThemeKey } from '../chunk-UP6GGGAN.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,37 @@
1
+ import { TraitDefinition, EventId } from '@almadar/core';
2
+ import { TransitionObserver, TraitState, RollbackCause } from './trait-types.js';
3
+ import '@almadar/core/kernel-wire';
4
+
5
+ /** The state a trait starts in: the one marked initial, else the first declared. */
6
+ declare function findInitialState(trait: TraitDefinition): string;
7
+ declare function createInitialTraitState(trait: TraitDefinition): TraitState;
8
+ /**
9
+ * Every transition out of `currentState` on the event, in declaration order. An event id is compared with a
10
+ * transition's own id when both carry one, so an arm still matches after its event was renamed.
11
+ */
12
+ declare function findMatchingTransitions(trait: TraitDefinition, currentState: string, eventKey: string, eventId?: EventId): TraitDefinition['transitions'];
13
+ /** The first transition out of `currentState` on the event, ignoring guards. */
14
+ declare function findTransition(trait: TraitDefinition, currentState: string, eventKey: string, eventId?: EventId): TraitDefinition['transitions'][0] | undefined;
15
+ declare class StateBook {
16
+ private readonly observer?;
17
+ private readonly traits;
18
+ private readonly states;
19
+ constructor(traits?: readonly TraitDefinition[], observer?: TransitionObserver | undefined);
20
+ /** The trait's state, its initial state until the kernel reports one; `undefined` for a trait not on the page. */
21
+ getState(traitName: string, entityId?: string): TraitState | undefined;
22
+ /** Each trait's singleton-scope state. */
23
+ getAllStates(): Map<string, TraitState>;
24
+ /** Whether the trait has an arm on the event from its current state. */
25
+ canHandleEvent(traitName: string, eventKey: string, entityId?: string, eventId?: EventId): boolean;
26
+ /**
27
+ * The lifecycle event an embedded child can be repainted with: the one it handles from its current state,
28
+ * provided every matching arm stays in that state and only renders.
29
+ */
30
+ repaintLifecycleEvent(traitName: string, entityId?: string): string | undefined;
31
+ /** Record the state the kernel reports. No-op for a trait not on the page. */
32
+ seedState(traitName: string, currentState: string, entityId?: string): void;
33
+ /** Undo an optimistic commit, reporting the hop back to the observer. */
34
+ rollbackState(traitName: string, toState: string, entityId: string | undefined, cause: RollbackCause): void;
35
+ }
36
+
37
+ export { StateBook, createInitialTraitState, findInitialState, findMatchingTransitions, findTransition };
@@ -0,0 +1,2 @@
1
+ export { StateBook, createInitialTraitState, findInitialState, findMatchingTransitions, findTransition } from '../chunk-Q2H75UYT.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,9 @@
1
+ /** A mount seed's lifecycle dispatch threw: names that trait and event, the original error's message kept. */
2
+ declare class TraitMountError extends Error {
3
+ readonly trait: string;
4
+ readonly event: string;
5
+ readonly original: Error;
6
+ constructor(trait: string, event: string, original: Error);
7
+ }
8
+
9
+ export { TraitMountError };
@@ -0,0 +1,2 @@
1
+ export { TraitMountError } from '../chunk-IOPUS6Q5.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,67 @@
1
+ import { SExpr, TraitConfig } from '@almadar/core';
2
+ import { HopObservation } from '@almadar/core/kernel-wire';
3
+
4
+ /**
5
+ * The client host's view of a trait: its running state, its flat definition, and the observer a
6
+ * verifier hangs on committed hops. Client-host types, not language contract.
7
+ */
8
+
9
+ /**
10
+ * State of a single trait's state machine
11
+ */
12
+ interface TraitState {
13
+ /** Trait name */
14
+ traitName: string;
15
+ /** Current state name */
16
+ currentState: string;
17
+ /** Previous state (null if initial) */
18
+ previousState: string | null;
19
+ /** Last event that caused a transition */
20
+ lastEvent: string | null;
21
+ /** Custom context data */
22
+ context: TraitConfig;
23
+ }
24
+ /**
25
+ * Observer interface for recording transition and effect traces.
26
+ * Implement this to wire in the verificationRegistry or other monitoring tools.
27
+ *
28
+ * The runtime calls these hooks automatically when transitions execute and
29
+ * effects complete, enabling runtime verification without tight coupling.
30
+ */
31
+ interface TransitionObserver {
32
+ /**
33
+ * Called after a transition is processed (whether or not it executed).
34
+ */
35
+ onTransition(trace: {
36
+ traitName: string;
37
+ from: string;
38
+ to: string;
39
+ event: string;
40
+ /** The arm that fired, by its position among the state's arms for the event. */
41
+ firedArm?: number;
42
+ guardResult?: boolean;
43
+ effects: Array<{
44
+ type: string;
45
+ args: SExpr[];
46
+ status: "executed" | "failed" | "skipped";
47
+ error?: string;
48
+ durationMs?: number;
49
+ }>;
50
+ /** Recorded for a verifier only (`setRecordEntityAfter`): the payload and `@entity` before and after. */
51
+ observed?: HopObservation;
52
+ }): void;
53
+ /**
54
+ * Called when an optimistic dispatch is undone: the state moved back from
55
+ * `from` to `to` because the server rejected the leg or never answered.
56
+ */
57
+ onRollback?(trace: {
58
+ traitName: string;
59
+ from: string;
60
+ to: string;
61
+ cause: RollbackCause;
62
+ }): void;
63
+ }
64
+ /** Why an optimistic dispatch was rolled back. */
65
+ type RollbackCause = 'transport-error' | 'server-rejected';
66
+
67
+ export type { RollbackCause, TraitState, TransitionObserver };
@@ -0,0 +1 @@
1
+ import '../chunk-P53CKOME.js';
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Bootstrap secrets that must NEVER enter store custody: the master key(s)
3
+ * decrypt the store itself, so seeding them as rows (encrypted under
4
+ * themselves) or stripping them from the env would be circular.
5
+ */
6
+ declare const STORE_BOOTSTRAP_ENV_VARS: ReadonlySet<string>;
7
+ /**
8
+ * Every env var a forked verify/harness process must not inherit so it can never see, and therefore
9
+ * never spend, a real credential: the store's bootstrap keys. A program's own credentials are declared
10
+ * in the program (`program_credentials` in the kernel) and held in the store, never in the fork's env.
11
+ */
12
+ declare function allCredentialEnvVars(): Set<string>;
13
+
14
+ export { STORE_BOOTSTRAP_ENV_VARS, allCredentialEnvVars };
@@ -0,0 +1,3 @@
1
+ export { STORE_BOOTSTRAP_ENV_VARS, allCredentialEnvVars } from '../chunk-Q7JK4KY7.js';
2
+ import '../chunk-NAECVIAR.js';
3
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,50 @@
1
+ import { CredentialStore } from './store.js';
2
+ import '@almadar/core';
3
+
4
+ /** Whether integrations answer with mock data or call their real backends. */
5
+ type CredentialMode = 'mock' | 'real';
6
+ /** The mode an env asks for: `ALMADAR_INTEGRATIONS_MODE=mock` or `USE_MOCK_DATA=true` mean mock. */
7
+ declare function credentialModeFromEnv(env: Record<string, string | undefined>): CredentialMode;
8
+ /** The host's live mode switch, reachable from the kernel's `credential-mode` asks. */
9
+ interface CredentialModeControl {
10
+ readonly mode: CredentialMode;
11
+ setMode(mode: CredentialMode): void;
12
+ }
13
+ /** The per-tenant credential scope: a Node host installs AsyncLocalStorage (`@almadar/shell-node`); a browser has none. */
14
+ interface CredentialScopeStorage {
15
+ run<T>(store: CredentialStore, fn: () => T): T;
16
+ getStore(): CredentialStore | undefined;
17
+ }
18
+ declare function installCredentialScopeStorage(storage: CredentialScopeStorage): void;
19
+ /**
20
+ * Run `fn` as one tenant of a multi-tenant host: every credential reference resolved inside it
21
+ * (across awaits) comes from `store` alone, never from the host's env or installed store.
22
+ */
23
+ declare function runWithCredentialScope<T>(store: CredentialStore, fn: () => T): T;
24
+ /** The host's mode switch, installed beside its credential store. */
25
+ declare function installModeControl(control: CredentialModeControl): void;
26
+ declare function getModeControl(): CredentialModeControl | null;
27
+ /**
28
+ * Install the host's credential store as the process-wide resolution source.
29
+ * Called once at boot (playground / generated server) after the store is
30
+ * constructed over the host's persistence adapter.
31
+ */
32
+ declare function installCredentialStore(store: CredentialStore): void;
33
+ /** The installed store, for the credentials admin service. */
34
+ declare function getInstalledCredentialStore(): CredentialStore | null;
35
+ declare function getEffectiveCredentialStore(): CredentialStore | null;
36
+ /** Testing/reset hook. */
37
+ declare function uninstallCredentialStore(): void;
38
+ /** The env var selecting store-only resolution (the kernel rule `credential_admin::SOURCE_VAR`). */
39
+ declare const CREDENTIALS_SOURCE_ENV = "ALMADAR_CREDENTIALS_SOURCE";
40
+ /** Whether `env` selects store-only resolution: exactly `ALMADAR_CREDENTIALS_SOURCE=store`. */
41
+ declare function credentialsFromStoreOnly(env: Record<string, string | undefined>): boolean;
42
+ /**
43
+ * The one credential-reference resolver: store, then env, then undefined; inside a tenant's
44
+ * credential scope, that tenant's store only. With `ALMADAR_CREDENTIALS_SOURCE=store` every
45
+ * name but a host setting answers from the store alone, never from the env. `ref` is an env-var name.
46
+ */
47
+ declare function resolveCredentialRef(ref: string, env?: Record<string, string | undefined>, principal?: string): string | undefined;
48
+
49
+ export { CREDENTIALS_SOURCE_ENV, credentialModeFromEnv, credentialsFromStoreOnly, getEffectiveCredentialStore, getInstalledCredentialStore, getModeControl, installCredentialScopeStorage, installCredentialStore, installModeControl, resolveCredentialRef, runWithCredentialScope, uninstallCredentialStore };
50
+ export type { CredentialMode, CredentialModeControl, CredentialScopeStorage };
@@ -0,0 +1,2 @@
1
+ export { CREDENTIALS_SOURCE_ENV, credentialModeFromEnv, credentialsFromStoreOnly, getEffectiveCredentialStore, getInstalledCredentialStore, getModeControl, installCredentialScopeStorage, installCredentialStore, installModeControl, resolveCredentialRef, runWithCredentialScope, uninstallCredentialStore } from '../chunk-HLOUDLPI.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,21 @@
1
+ import { CredentialStore } from './store.js';
2
+ import '@almadar/core';
3
+
4
+ /** One credential the app declares: the service group it belongs to and the env var / credential name. */
5
+ interface DeclaredCredential {
6
+ readonly service: string;
7
+ readonly envVar: string;
8
+ }
9
+ /** The kernel export that decides a seed (`credential_admin::seed_plan`): the rows to copy, never a value. */
10
+ interface CredentialSeedKernel {
11
+ credentialSeedPlan(declaredJson: string, heldJson: string, presentJson: string): string;
12
+ }
13
+ /**
14
+ * The boot of `ALMADAR_CREDENTIALS_SOURCE=store`: the kernel plans which declared credentials the store lacks and the env
15
+ * holds, and this copies each into the store, so the env stays the way to hand a deployment its first keys. A name
16
+ * declared twice seeds once, a held row is never overwritten. Returns the count.
17
+ */
18
+ declare function seedCredentialStore(store: CredentialStore, declared: readonly DeclaredCredential[], env: Record<string, string | undefined>, kernel: CredentialSeedKernel): Promise<number>;
19
+
20
+ export { seedCredentialStore };
21
+ export type { CredentialSeedKernel, DeclaredCredential };
@@ -0,0 +1,2 @@
1
+ export { seedCredentialStore } from '../chunk-SWPDU752.js';
2
+ import '../chunk-MLKGABMK.js';
@@ -0,0 +1,110 @@
1
+ import { PersistenceAdapter, CredentialIdentity } from '@almadar/core';
2
+
3
+ /** Entity type the credential rows persist under (never a `.lolo`-declared entity). */
4
+ declare const CREDENTIAL_ENTITY_TYPE = "AlmadarIntegrationCredential";
5
+ /** Env var holding the 64-char-hex AES-256 master key (Secret Manager in production). */
6
+ declare const CREDENTIAL_MASTER_KEY_ENV = "ALMADAR_CREDENTIAL_MASTER_KEY";
7
+ /**
8
+ * Env var holding the PREVIOUS master key during a rotation window (I-28):
9
+ * decryption tries the row's stamped key, `rotate()` re-encrypts every row
10
+ * under the current key, then the previous key is retired from the env.
11
+ */
12
+ declare const CREDENTIAL_PREVIOUS_MASTER_KEY_ENV = "ALMADAR_CREDENTIAL_MASTER_KEY_PREVIOUS";
13
+ /** The slice of the persistence contract the credential store uses. */
14
+ type CredentialPersistence = Pick<PersistenceAdapter, 'create' | 'update' | 'delete' | 'list'>;
15
+ /** Entity type the shared one-use values (a pending OAuth grant) persist under. */
16
+ declare const DERIVED_ENTITY_TYPE = "AlmadarKernelDerivedSecret";
17
+ /** What an adapter also offers when it can share one-use values across instances: a read by id, and a conditional delete where the store has one. */
18
+ type DerivedPersistence = Pick<PersistenceAdapter, 'getById'> & Partial<Pick<PersistenceAdapter, 'writeWhere' | 'writeCapabilities'>>;
19
+ /** Masked view of one stored credential — safe to return to a settings page. */
20
+ interface CredentialEntry {
21
+ service: string;
22
+ envVar: string;
23
+ last4: string;
24
+ updatedAt: number;
25
+ principal?: CredentialIdentity['principal'];
26
+ }
27
+ /**
28
+ * Tenant-scoped (app-wide) credential store: one AES-256-GCM-encrypted row
29
+ * per (service, envVar) through the host's persistence adapter, master key
30
+ * `ALMADAR_CREDENTIAL_MASTER_KEY` held alone in the platform secret store.
31
+ *
32
+ * Resolution contract: credential keys ARE env-var names (the same names
33
+ * `serviceCredentials` declares and `connectionRef` carries), so a stored
34
+ * value transparently shadows its env counterpart — store → env →
35
+ * unconfigured, everywhere.
36
+ *
37
+ * `warm()` decrypts all rows into memory so resolution stays synchronous;
38
+ * every write re-warms the affected entry and notifies subscribers (the
39
+ * `RuntimeIntegrationManager` re-configures on that signal, so new keys go
40
+ * live without a restart).
41
+ */
42
+ declare class CredentialStore {
43
+ private readonly adapter;
44
+ private readonly masterKeyHex;
45
+ private readonly previousKeyHex;
46
+ private readonly byIdentity;
47
+ private readonly listeners;
48
+ private warmed;
49
+ constructor(adapter: CredentialPersistence, masterKey?: string, previousMasterKey?: string);
50
+ /** True when a valid master key is present (writes and decryption enabled). */
51
+ get enabled(): boolean;
52
+ /** Subscribe to credential changes; returns an unsubscribe function. */
53
+ subscribe(listener: (principal?: string) => void): () => void;
54
+ private notify;
55
+ private encrypt;
56
+ private decryptWithKey;
57
+ /**
58
+ * Decrypt one row, selecting the key by the row's stamped `keyId` (I-28):
59
+ * current key first, then the rotation-window previous key. Legacy rows
60
+ * (no `keyId`) try current then previous. Returns null when no held key
61
+ * decrypts the row — the row is unreadable, never silently wrong (GCM
62
+ * auth tags make a wrong-key success impossible).
63
+ */
64
+ private decryptRow;
65
+ /**
66
+ * Load and decrypt every stored row into memory. Returns the number of
67
+ * resolvable credentials. Without a master key nothing decrypts (rows are
68
+ * left in place, resolution falls through to env).
69
+ */
70
+ warm(): Promise<number>;
71
+ /** Resolve one credential by env-var name (warmed values only). */
72
+ resolve(envVar: string, principal?: string): string | undefined;
73
+ /** The non-secret account label stored in the clear beside a credential's ciphertext; undefined when its row carries none. */
74
+ label(envVar: string, principal?: string): string | undefined;
75
+ /** All warmed values as an env-shaped map, for merging over the process env. */
76
+ snapshotEnv(): Record<string, string>;
77
+ /** Masked entries for display — never includes plaintext. */
78
+ entries(principal?: string): CredentialEntry[];
79
+ /**
80
+ * Upsert one credential (encrypts, persists, re-warms the entry, notifies). `label` is a non-secret account name kept
81
+ * in the clear in the row beside the ciphertext; left out, the row's label stays as it is.
82
+ */
83
+ set(service: string, envVar: string, value: string, principal?: string, label?: string): Promise<CredentialEntry>;
84
+ /**
85
+ * Re-encrypt every readable row under the CURRENT master key (I-28).
86
+ * Rotation window: deploy the new key as `ALMADAR_CREDENTIAL_MASTER_KEY`
87
+ * with the old one as `..._PREVIOUS`, call `rotate()`, then retire the
88
+ * previous key. Rows no held key can read are counted, never dropped.
89
+ */
90
+ rotate(): Promise<{
91
+ rotated: number;
92
+ alreadyCurrent: number;
93
+ unreadable: number;
94
+ }>;
95
+ /** Whether one-use values are shared through the adapter: a master key and an adapter that reads a row by id. */
96
+ get sharesDerived(): boolean;
97
+ /** Keep `value` encrypted in the adapter until `expiresAt` (epoch ms) so any instance on the same store can take it once. */
98
+ holdDerived(name: string, value: string, expiresAt: number, principal?: string): Promise<void>;
99
+ /**
100
+ * Remove and return a held value. Where the adapter has a conditional delete only the instance whose delete
101
+ * lands gets the value; elsewhere the delete is unconditional, so two instances racing for one state can both
102
+ * read it. An expired value is consumed and not returned.
103
+ */
104
+ takeDerived(name: string, principal: string | undefined, now: number): Promise<string | undefined>;
105
+ /** Delete one credential row; resolution falls back to env afterwards. */
106
+ remove(envVar: string, principal?: string): Promise<boolean>;
107
+ }
108
+
109
+ export { CREDENTIAL_ENTITY_TYPE, CREDENTIAL_MASTER_KEY_ENV, CREDENTIAL_PREVIOUS_MASTER_KEY_ENV, CredentialStore, DERIVED_ENTITY_TYPE };
110
+ export type { CredentialEntry, CredentialPersistence, DerivedPersistence };
@@ -0,0 +1,2 @@
1
+ export { CREDENTIAL_ENTITY_TYPE, CREDENTIAL_MASTER_KEY_ENV, CREDENTIAL_PREVIOUS_MASTER_KEY_ENV, CredentialStore, DERIVED_ENTITY_TYPE } from '../chunk-NAECVIAR.js';
2
+ import '../chunk-MLKGABMK.js';