@brud/kernel 0.0.0-stage → 0.0.2

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 (286) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +63 -2
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.js +13 -0
  5. package/dist/serviceModules/events.d.ts +1 -0
  6. package/dist/serviceModules/events.js +1 -0
  7. package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
  8. package/dist/serviceModules/exposedApiRegistry.js +1 -0
  9. package/dist/serviceModules/identityRegistry.d.ts +1 -0
  10. package/dist/serviceModules/identityRegistry.js +1 -0
  11. package/dist/serviceModules/interception.d.ts +1 -0
  12. package/dist/serviceModules/interception.js +1 -0
  13. package/dist/serviceModules/parser.d.ts +1 -0
  14. package/dist/serviceModules/parser.js +1 -0
  15. package/dist/serviceModules/router.d.ts +1 -0
  16. package/dist/serviceModules/router.js +1 -0
  17. package/dist/serviceModules/wasmCage.d.ts +1 -0
  18. package/dist/serviceModules/wasmCage.js +1 -0
  19. package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
  20. package/dist/services/Events/contracts/IEventsService.js +1 -0
  21. package/dist/services/Events/contracts/errors.d.ts +31 -0
  22. package/dist/services/Events/contracts/errors.js +40 -0
  23. package/dist/services/Events/contracts/index.d.ts +3 -0
  24. package/dist/services/Events/contracts/index.js +3 -0
  25. package/dist/services/Events/contracts/tokens.d.ts +2 -0
  26. package/dist/services/Events/contracts/tokens.js +2 -0
  27. package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
  28. package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
  29. package/dist/services/Events/descriptor/tokens.d.ts +1 -0
  30. package/dist/services/Events/descriptor/tokens.js +1 -0
  31. package/dist/services/Events/index.d.ts +4 -0
  32. package/dist/services/Events/index.js +4 -0
  33. package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
  34. package/dist/services/Events/orchestrator/EventsService.js +339 -0
  35. package/dist/services/Events/orchestrator/index.d.ts +2 -0
  36. package/dist/services/Events/orchestrator/index.js +2 -0
  37. package/dist/services/Events/orchestrator/limits.d.ts +22 -0
  38. package/dist/services/Events/orchestrator/limits.js +33 -0
  39. package/dist/services/Events/serviceModule.d.ts +2 -0
  40. package/dist/services/Events/serviceModule.js +5 -0
  41. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +56 -0
  42. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
  43. package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
  44. package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
  45. package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
  46. package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
  47. package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
  48. package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
  49. package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
  50. package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
  51. package/dist/services/ExposedApiRegistry/contracts/types.d.ts +133 -0
  52. package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
  53. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
  54. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
  55. package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
  56. package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
  57. package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
  58. package/dist/services/ExposedApiRegistry/index.js +5 -0
  59. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +68 -0
  60. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +452 -0
  61. package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
  62. package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
  63. package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
  64. package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
  65. package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
  66. package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
  67. package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
  68. package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
  69. package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
  70. package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
  71. package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
  72. package/dist/services/IdentityRegistry/contracts/index.js +3 -0
  73. package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
  74. package/dist/services/IdentityRegistry/contracts/types.js +18 -0
  75. package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
  76. package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
  77. package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
  78. package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
  79. package/dist/services/IdentityRegistry/index.d.ts +11 -0
  80. package/dist/services/IdentityRegistry/index.js +6 -0
  81. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
  82. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
  83. package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
  84. package/dist/services/IdentityRegistry/serviceModule.js +24 -0
  85. package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
  86. package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
  87. package/dist/services/Interception/contracts/IInterceptionService.d.ts +155 -0
  88. package/dist/services/Interception/contracts/IInterceptionService.js +12 -0
  89. package/dist/services/Interception/contracts/errors.d.ts +26 -0
  90. package/dist/services/Interception/contracts/errors.js +35 -0
  91. package/dist/services/Interception/contracts/index.d.ts +3 -0
  92. package/dist/services/Interception/contracts/index.js +3 -0
  93. package/dist/services/Interception/contracts/tokens.d.ts +2 -0
  94. package/dist/services/Interception/contracts/tokens.js +2 -0
  95. package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
  96. package/dist/services/Interception/descriptor/InterceptionDescriptor.js +50 -0
  97. package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
  98. package/dist/services/Interception/descriptor/tokens.js +1 -0
  99. package/dist/services/Interception/index.d.ts +4 -0
  100. package/dist/services/Interception/index.js +4 -0
  101. package/dist/services/Interception/orchestrator/InterceptionService.d.ts +40 -0
  102. package/dist/services/Interception/orchestrator/InterceptionService.js +343 -0
  103. package/dist/services/Interception/orchestrator/index.d.ts +1 -0
  104. package/dist/services/Interception/orchestrator/index.js +1 -0
  105. package/dist/services/Interception/serviceModule.d.ts +2 -0
  106. package/dist/services/Interception/serviceModule.js +5 -0
  107. package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
  108. package/dist/services/Parser/contracts/IParserService.js +1 -0
  109. package/dist/services/Parser/contracts/errors.d.ts +25 -0
  110. package/dist/services/Parser/contracts/errors.js +33 -0
  111. package/dist/services/Parser/contracts/index.d.ts +4 -0
  112. package/dist/services/Parser/contracts/index.js +1 -0
  113. package/dist/services/Parser/contracts/types.d.ts +42 -0
  114. package/dist/services/Parser/contracts/types.js +1 -0
  115. package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
  116. package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
  117. package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
  118. package/dist/services/Parser/descriptor/tokens.js +8 -0
  119. package/dist/services/Parser/index.d.ts +8 -0
  120. package/dist/services/Parser/index.js +8 -0
  121. package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
  122. package/dist/services/Parser/orchestrator/ParserService.js +105 -0
  123. package/dist/services/Parser/orchestrator/index.d.ts +1 -0
  124. package/dist/services/Parser/orchestrator/index.js +1 -0
  125. package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
  126. package/dist/services/Parser/parser/indexSynthesis.js +13 -0
  127. package/dist/services/Parser/parser/parameters.d.ts +14 -0
  128. package/dist/services/Parser/parser/parameters.js +89 -0
  129. package/dist/services/Parser/parser/scanner.d.ts +48 -0
  130. package/dist/services/Parser/parser/scanner.js +156 -0
  131. package/dist/services/Parser/parser/syntax.d.ts +30 -0
  132. package/dist/services/Parser/parser/syntax.js +34 -0
  133. package/dist/services/Parser/serviceModule.d.ts +2 -0
  134. package/dist/services/Parser/serviceModule.js +5 -0
  135. package/dist/services/Router/bootOptions.d.ts +2 -0
  136. package/dist/services/Router/bootOptions.js +2 -0
  137. package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
  138. package/dist/services/Router/contracts/IRouterService.js +1 -0
  139. package/dist/services/Router/contracts/caller.d.ts +6 -0
  140. package/dist/services/Router/contracts/caller.js +6 -0
  141. package/dist/services/Router/contracts/errors.d.ts +67 -0
  142. package/dist/services/Router/contracts/errors.js +90 -0
  143. package/dist/services/Router/contracts/index.d.ts +8 -0
  144. package/dist/services/Router/contracts/index.js +4 -0
  145. package/dist/services/Router/contracts/kind.d.ts +7 -0
  146. package/dist/services/Router/contracts/kind.js +10 -0
  147. package/dist/services/Router/contracts/registrant.d.ts +23 -0
  148. package/dist/services/Router/contracts/registrant.js +13 -0
  149. package/dist/services/Router/contracts/types.d.ts +110 -0
  150. package/dist/services/Router/contracts/types.js +1 -0
  151. package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
  152. package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
  153. package/dist/services/Router/descriptor/tokens.d.ts +9 -0
  154. package/dist/services/Router/descriptor/tokens.js +9 -0
  155. package/dist/services/Router/index.d.ts +4 -0
  156. package/dist/services/Router/index.js +4 -0
  157. package/dist/services/Router/orchestrator/RouterService.d.ts +93 -0
  158. package/dist/services/Router/orchestrator/RouterService.js +457 -0
  159. package/dist/services/Router/orchestrator/index.d.ts +2 -0
  160. package/dist/services/Router/orchestrator/index.js +1 -0
  161. package/dist/services/Router/serviceModule.d.ts +4 -0
  162. package/dist/services/Router/serviceModule.js +22 -0
  163. package/dist/services/WasmCage/index.d.ts +7 -0
  164. package/dist/services/WasmCage/index.js +4 -0
  165. package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
  166. package/dist/services/WasmCage/scripts/prepin.js +38 -0
  167. package/dist/services/WasmCage/serviceModule.d.ts +12 -0
  168. package/dist/services/WasmCage/serviceModule.js +18 -0
  169. package/dist/services/WasmCage/src/caged.d.ts +121 -0
  170. package/dist/services/WasmCage/src/caged.js +460 -0
  171. package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
  172. package/dist/services/WasmCage/src/descriptor.js +56 -0
  173. package/dist/services/WasmCage/src/native.d.ts +29 -0
  174. package/dist/services/WasmCage/src/native.js +66 -0
  175. package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
  176. package/dist/services/WasmCage/src/nativeDigests.js +15 -0
  177. package/dist/services/WasmCage/src/package.d.ts +36 -0
  178. package/dist/services/WasmCage/src/package.js +122 -0
  179. package/dist/services/shared/canonicalJson.d.ts +29 -0
  180. package/dist/services/shared/canonicalJson.js +93 -0
  181. package/dist/services/shared/documentStore.d.ts +16 -0
  182. package/dist/services/shared/documentStore.js +98 -0
  183. package/dist/src/bootstrap/bootKernelInternal.d.ts +19 -0
  184. package/dist/src/bootstrap/bootKernelInternal.js +633 -0
  185. package/dist/src/bootstrap/bootTypes.d.ts +113 -0
  186. package/dist/src/bootstrap/bootTypes.js +1 -0
  187. package/dist/src/bootstrap/config/index.d.ts +3 -0
  188. package/dist/src/bootstrap/config/index.js +2 -0
  189. package/dist/src/bootstrap/config/integrity.d.ts +45 -0
  190. package/dist/src/bootstrap/config/integrity.js +92 -0
  191. package/dist/src/bootstrap/config/parse.d.ts +15 -0
  192. package/dist/src/bootstrap/config/parse.js +81 -0
  193. package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
  194. package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
  195. package/dist/src/bootstrap/config/types.d.ts +41 -0
  196. package/dist/src/bootstrap/config/types.js +15 -0
  197. package/dist/src/bootstrap/hardcore.d.ts +212 -0
  198. package/dist/src/bootstrap/hardcore.js +312 -0
  199. package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
  200. package/dist/src/bootstrap/hardcoreServices.js +258 -0
  201. package/dist/src/bootstrap/index.d.ts +13 -0
  202. package/dist/src/bootstrap/index.js +7 -0
  203. package/dist/src/bootstrap/loaded.d.ts +30 -0
  204. package/dist/src/bootstrap/loaded.js +45 -0
  205. package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
  206. package/dist/src/bootstrap/packageRequirements.js +52 -0
  207. package/dist/src/bootstrap/reload.d.ts +44 -0
  208. package/dist/src/bootstrap/reload.js +45 -0
  209. package/dist/src/bootstrap/seal.d.ts +32 -0
  210. package/dist/src/bootstrap/seal.js +101 -0
  211. package/dist/src/contracts/accessBroker.d.ts +53 -0
  212. package/dist/src/contracts/accessBroker.js +1 -0
  213. package/dist/src/contracts/brudOperation.d.ts +20 -0
  214. package/dist/src/contracts/brudOperation.js +20 -0
  215. package/dist/src/contracts/callChain.d.ts +161 -0
  216. package/dist/src/contracts/callChain.js +19 -0
  217. package/dist/src/contracts/capability.d.ts +26 -0
  218. package/dist/src/contracts/capability.js +26 -0
  219. package/dist/src/contracts/capabilitySet.d.ts +23 -0
  220. package/dist/src/contracts/capabilitySet.js +72 -0
  221. package/dist/src/contracts/container.d.ts +17 -0
  222. package/dist/src/contracts/container.js +8 -0
  223. package/dist/src/contracts/context.d.ts +19 -0
  224. package/dist/src/contracts/context.js +1 -0
  225. package/dist/src/contracts/contextContract.d.ts +132 -0
  226. package/dist/src/contracts/contextContract.js +274 -0
  227. package/dist/src/contracts/dispatchView.d.ts +21 -0
  228. package/dist/src/contracts/dispatchView.js +1 -0
  229. package/dist/src/contracts/handler.d.ts +21 -0
  230. package/dist/src/contracts/handler.js +1 -0
  231. package/dist/src/contracts/index.d.ts +26 -0
  232. package/dist/src/contracts/index.js +9 -0
  233. package/dist/src/contracts/kernel.d.ts +60 -0
  234. package/dist/src/contracts/kernel.js +1 -0
  235. package/dist/src/contracts/lifecycle.d.ts +59 -0
  236. package/dist/src/contracts/lifecycle.js +1 -0
  237. package/dist/src/contracts/manifest.d.ts +180 -0
  238. package/dist/src/contracts/manifest.js +334 -0
  239. package/dist/src/contracts/pipeline.d.ts +8 -0
  240. package/dist/src/contracts/pipeline.js +1 -0
  241. package/dist/src/contracts/policy.d.ts +75 -0
  242. package/dist/src/contracts/policy.js +77 -0
  243. package/dist/src/contracts/registry.d.ts +7 -0
  244. package/dist/src/contracts/registry.js +1 -0
  245. package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
  246. package/dist/src/contracts/serviceDescriptor.js +1 -0
  247. package/dist/src/contracts/serviceToken.d.ts +36 -0
  248. package/dist/src/contracts/serviceToken.js +16 -0
  249. package/dist/src/engine/BrudKernel.d.ts +120 -0
  250. package/dist/src/engine/BrudKernel.js +395 -0
  251. package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
  252. package/dist/src/engine/ExecutionPipeline.js +62 -0
  253. package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
  254. package/dist/src/engine/KernelAccessBroker.js +107 -0
  255. package/dist/src/engine/KernelRegistry.d.ts +14 -0
  256. package/dist/src/engine/KernelRegistry.js +33 -0
  257. package/dist/src/engine/OperationRegistry.d.ts +9 -0
  258. package/dist/src/engine/OperationRegistry.js +18 -0
  259. package/dist/src/engine/ServiceContainer.d.ts +13 -0
  260. package/dist/src/engine/ServiceContainer.js +53 -0
  261. package/dist/src/engine/callChain.d.ts +68 -0
  262. package/dist/src/engine/callChain.js +175 -0
  263. package/dist/src/engine/dag.d.ts +2 -0
  264. package/dist/src/engine/dag.js +34 -0
  265. package/dist/src/engine/errors.d.ts +26 -0
  266. package/dist/src/engine/errors.js +52 -0
  267. package/dist/src/engine/index.d.ts +11 -0
  268. package/dist/src/engine/index.js +8 -0
  269. package/dist/src/engine/state.d.ts +1 -0
  270. package/dist/src/engine/state.js +1 -0
  271. package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
  272. package/dist/src/validation/jsonSchema/compile.js +386 -0
  273. package/dist/src/validation/jsonSchema/index.d.ts +3 -0
  274. package/dist/src/validation/jsonSchema/index.js +2 -0
  275. package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
  276. package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
  277. package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
  278. package/dist/src/validation/jsonSchema/pattern.js +155 -0
  279. package/dist/src/validation/jsonSchema/types.d.ts +71 -0
  280. package/dist/src/validation/jsonSchema/types.js +15 -0
  281. package/package.json +59 -4
  282. package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
  283. package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
  284. package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
  285. package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
  286. package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
@@ -0,0 +1,113 @@
1
+ import type { ContextFieldDeclaration, ContextSchema, ContextScopeDeclaration } from '../contracts/contextContract.js';
2
+ import type { IServiceLifecycle, KernelLogger } from '../contracts/lifecycle.js';
3
+ /**
4
+ * The build seal: what a composition's builder shipped, fixed once per build.
5
+ *
6
+ * It lists every official participant in the order the build declared them,
7
+ * each with a content hash. The builder generates it at release time and the
8
+ * built product hands the kernel the seal file and its digest at boot, so the
9
+ * kernel can tell what the build shipped from anything added afterwards.
10
+ */
11
+ export interface SealReference {
12
+ /** Path of the seal file. */
13
+ readonly path: string;
14
+ /** SHA-256 hex digest of the seal file, held by the built product, not next to the file. */
15
+ readonly digest: string;
16
+ }
17
+ /**
18
+ * Generic options accepted by {@link bootKernel}.
19
+ *
20
+ * The core names three fields: an open options bag, a logger, and the build seal the host's product carries. Every
21
+ * service-specific option lives inside {@link BootKernelOptions.options} and
22
+ * is interpreted by the service module that owns it. The core never sees those
23
+ * names or types.
24
+ */
25
+ export interface BootKernelOptions {
26
+ /** Open options bag built by the host before boot. */
27
+ readonly options?: Readonly<Record<string, unknown>>;
28
+ /** Kernel diagnostic sink. Defaults to a console-backed sink. */
29
+ readonly logger?: KernelLogger;
30
+ /**
31
+ * The build seal: the file the builder generated at release time and its
32
+ * digest, which the built product holds. When given, the official
33
+ * participants must be exactly those the seal lists, and an entry that
34
+ * declares itself official without being sealed is left out. When absent,
35
+ * the config's own `official` flags stand, which suits development.
36
+ */
37
+ readonly seal?: SealReference;
38
+ }
39
+ /** Options accepted by {@link createDeferredKernel}. */
40
+ export interface ComposeKernelOptions {
41
+ /** Open options bag built by the host before boot. */
42
+ readonly options?: Readonly<Record<string, unknown>>;
43
+ /** Kernel diagnostic sink. Defaults to a console-backed sink. */
44
+ readonly logger?: KernelLogger;
45
+ /** The build seal, as for {@link BootKernelOptions.seal}. */
46
+ readonly seal?: SealReference;
47
+ }
48
+ /**
49
+ * Context handed to a config-selected service module.
50
+ *
51
+ * The module owns its descriptor; the loader owns ordering and official flags.
52
+ * The context deliberately contains no concrete service instances and no
53
+ * service option types: services read their own keys from the generic options
54
+ * bag and coordinate through owner-namespaced entries in the shared bag.
55
+ */
56
+ export interface KernelServiceModuleContext {
57
+ /** Generic options bag from the host. */
58
+ readonly options: Record<string, unknown>;
59
+ /** Kernel diagnostic sink. */
60
+ readonly logger?: KernelLogger;
61
+ /**
62
+ * Per-kernel owner-namespaced coordination bag.
63
+ *
64
+ * A module may publish an instance under a key inside its own namespace; the
65
+ * core treats the bag as opaque and never reads named slots. A service that
66
+ * needs another participant's API resolves it through the broker or the
67
+ * exposed-API registry, never through another owner's slot.
68
+ */
69
+ readonly shared: Record<string, unknown>;
70
+ /**
71
+ * Declares the context fields this service requires from the options bag.
72
+ *
73
+ * A service may only declare fields inside its own dot-separated namespace.
74
+ * Declarations are accepted during `createService` and `pinBootPolicies`, and
75
+ * are rejected once the kernel reaches `RUNNING`.
76
+ *
77
+ * @param scope - Namespace owned by the declaring service.
78
+ * @param fields - Fields to require or accept inside that namespace.
79
+ */
80
+ declareContextFields(scope: string, fields: readonly ContextFieldDeclaration[]): void;
81
+ /** Declares fields through a single scope-declaration record. */
82
+ declareContextFields(declaration: ContextScopeDeclaration): void;
83
+ /** Returns the schema collected so far, including fields from other services. */
84
+ getContextSchema(): ContextSchema;
85
+ }
86
+ /**
87
+ * Shape a config-selected service module exports.
88
+ *
89
+ * `createService` returns one descriptor, or an ordered list of descriptors
90
+ * when the module exposes more than one API. Each descriptor is registered as
91
+ * its own service; the descriptor shape itself does not change. The return is
92
+ * typed as `unknown` at this boundary because descriptors are invariant in
93
+ * their service type; the loader validates the runtime shape and narrows it.
94
+ *
95
+ * A module that must resolve host values before it can declare its descriptor
96
+ * may return a promise; the loader awaits every module before registration.
97
+ *
98
+ * The optional hooks are generic coordination points available to every
99
+ * participant. The loader invokes them without knowing which service
100
+ * implements them:
101
+ * - `pinBootPolicies` ingests a boot snapshot while the broker gate is open.
102
+ * - `registerBootRegistrants` makes boot-time claims before `RUNNING`.
103
+ * Exposures are not among them: they are declared in each participant's
104
+ * manifest and admitted by the kernel.
105
+ */
106
+ export interface ServiceModule {
107
+ /** Builds and returns this service's descriptor or descriptors. */
108
+ createService(context: KernelServiceModuleContext): unknown | Promise<unknown>;
109
+ /** Ingests frozen boot policy after construction. */
110
+ pinBootPolicies?(context: KernelServiceModuleContext, instances: readonly IServiceLifecycle[]): void | Promise<void>;
111
+ /** Registers boot-time claims against this service's instance. */
112
+ registerBootRegistrants?(context: KernelServiceModuleContext, instances: readonly IServiceLifecycle[]): void;
113
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export type { BrudConfig, BrudConfigEntry, BrudConfigErrorCode, } from './types.js';
2
+ export { BrudConfigError } from './types.js';
3
+ export { parseBrudConfig } from './parse.js';
@@ -0,0 +1,2 @@
1
+ export { BrudConfigError } from './types.js';
2
+ export { parseBrudConfig } from './parse.js';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Records the digest of the raw config document and returns it.
3
+ *
4
+ * A second read at the same path must hash identically. This is what makes a
5
+ * modified config refuse a reboot even if it changed outside the guarded APIs.
6
+ *
7
+ * @param configPath - Path the document was read from.
8
+ * @param raw - Exact file contents.
9
+ */
10
+ export declare function recordConfigRead(configPath: string, raw: string): void;
11
+ /**
12
+ * Forgets the recorded digest of a config path, so the next read is recorded
13
+ * as the new baseline.
14
+ *
15
+ * Only a reload the host asked for calls this: it is the host's explicit
16
+ * decision to run a changed composition. An ordinary boot never does, so a
17
+ * config that changed outside a reload is still refused.
18
+ *
19
+ * @param configPath - Path whose digest is forgotten.
20
+ */
21
+ export declare function acceptConfigChange(configPath: string): void;
22
+ /**
23
+ * Marks the root config read-only for the lifetime of one kernel.
24
+ *
25
+ * Both the declared path and its real path are protected so an alias cannot
26
+ * bypass the guard.
27
+ *
28
+ * @param configPath - Path the kernel read.
29
+ */
30
+ export declare function protectConfigFile(configPath: string): void;
31
+ /**
32
+ * Releases one kernel's claim on the config path.
33
+ *
34
+ * The digest record is intentionally retained for the process lifetime, so a
35
+ * later boot of the same path is still compared against the first read.
36
+ *
37
+ * @param configPath - Path the kernel read.
38
+ */
39
+ export declare function releaseConfigProtection(configPath: string): void;
40
+ /**
41
+ * Re-reads the config and compares it with the digest recorded at boot.
42
+ *
43
+ * @param configPath - Path the kernel read.
44
+ */
45
+ export declare function verifyConfigIntegrity(configPath: string): Promise<void>;
@@ -0,0 +1,92 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { resolve as resolvePath } from 'node:path';
4
+ import { BrudConfigError } from './types.js';
5
+ import { protectPath, releasePath } from './pathWriteGuard.js';
6
+ /**
7
+ * Runtime integrity for the root config document.
8
+ *
9
+ * The root config is read exactly once per boot. Its digest is recorded then,
10
+ * and every later read of that path is checked against the record. While a
11
+ * kernel is alive the path is also made read-only and mutating `node:fs`
12
+ * operations against it are refused before they reach the host.
13
+ */
14
+ const CONFIG_DIGESTS = new Map();
15
+ function digestOf(raw) {
16
+ return createHash('sha256').update(raw, 'utf8').digest('hex');
17
+ }
18
+ function configPathError(configPath, operation) {
19
+ return new BrudConfigError('CONFIG_INTEGRITY', `The root config file is protected and cannot be ${operation}: ${configPath}`, configPath);
20
+ }
21
+ /**
22
+ * Records the digest of the raw config document and returns it.
23
+ *
24
+ * A second read at the same path must hash identically. This is what makes a
25
+ * modified config refuse a reboot even if it changed outside the guarded APIs.
26
+ *
27
+ * @param configPath - Path the document was read from.
28
+ * @param raw - Exact file contents.
29
+ */
30
+ export function recordConfigRead(configPath, raw) {
31
+ const key = resolvePath(configPath);
32
+ const digest = digestOf(raw);
33
+ const recorded = CONFIG_DIGESTS.get(key);
34
+ if (recorded !== undefined && recorded !== digest) {
35
+ throw new BrudConfigError('CONFIG_INTEGRITY', `Config integrity check failed: "${key}" changed since it was first read`, configPath);
36
+ }
37
+ CONFIG_DIGESTS.set(key, digest);
38
+ }
39
+ /**
40
+ * Forgets the recorded digest of a config path, so the next read is recorded
41
+ * as the new baseline.
42
+ *
43
+ * Only a reload the host asked for calls this: it is the host's explicit
44
+ * decision to run a changed composition. An ordinary boot never does, so a
45
+ * config that changed outside a reload is still refused.
46
+ *
47
+ * @param configPath - Path whose digest is forgotten.
48
+ */
49
+ export function acceptConfigChange(configPath) {
50
+ CONFIG_DIGESTS.delete(resolvePath(configPath));
51
+ }
52
+ /**
53
+ * Marks the root config read-only for the lifetime of one kernel.
54
+ *
55
+ * Both the declared path and its real path are protected so an alias cannot
56
+ * bypass the guard.
57
+ *
58
+ * @param configPath - Path the kernel read.
59
+ */
60
+ export function protectConfigFile(configPath) {
61
+ protectPath(configPath, (key, operation) => configPathError(key, operation));
62
+ }
63
+ /**
64
+ * Releases one kernel's claim on the config path.
65
+ *
66
+ * The digest record is intentionally retained for the process lifetime, so a
67
+ * later boot of the same path is still compared against the first read.
68
+ *
69
+ * @param configPath - Path the kernel read.
70
+ */
71
+ export function releaseConfigProtection(configPath) {
72
+ releasePath(configPath);
73
+ }
74
+ /**
75
+ * Re-reads the config and compares it with the digest recorded at boot.
76
+ *
77
+ * @param configPath - Path the kernel read.
78
+ */
79
+ export async function verifyConfigIntegrity(configPath) {
80
+ const key = resolvePath(configPath);
81
+ const recorded = CONFIG_DIGESTS.get(key);
82
+ let raw;
83
+ try {
84
+ raw = await readFile(configPath, 'utf8');
85
+ }
86
+ catch (error) {
87
+ throw new BrudConfigError('CONFIG_INTEGRITY', `Config integrity check failed: cannot re-read "${key}": ${error instanceof Error ? error.message : String(error)}`, configPath);
88
+ }
89
+ if (recorded === undefined || recorded !== digestOf(raw)) {
90
+ throw new BrudConfigError('CONFIG_INTEGRITY', `Config integrity check failed: "${key}" no longer matches its boot-time digest`, configPath);
91
+ }
92
+ }
@@ -0,0 +1,15 @@
1
+ import { type BrudConfig } from './types.js';
2
+ /**
3
+ * Parses and validates the kernel-owned sections of a `brud.config.json`
4
+ * document.
5
+ *
6
+ * The kernel owns `services` and `exposureOwners`. Other top-level sections
7
+ * belong to the participants that own them; the kernel carries them untouched
8
+ * and never interprets them.
9
+ *
10
+ * @param raw - File contents.
11
+ * @param configPath - Config path used in diagnostics.
12
+ */
13
+ export declare function parseBrudConfig(raw: string, configPath: string): BrudConfig;
14
+ /** Finds the first source line containing a token. */
15
+ export declare function lineOf(raw: string, token: string): number | undefined;
@@ -0,0 +1,81 @@
1
+ import { BrudConfigError, } from './types.js';
2
+ const ENTRY_KEYS = new Set(['path', 'official']);
3
+ /**
4
+ * Parses and validates the kernel-owned sections of a `brud.config.json`
5
+ * document.
6
+ *
7
+ * The kernel owns `services` and `exposureOwners`. Other top-level sections
8
+ * belong to the participants that own them; the kernel carries them untouched
9
+ * and never interprets them.
10
+ *
11
+ * @param raw - File contents.
12
+ * @param configPath - Config path used in diagnostics.
13
+ */
14
+ export function parseBrudConfig(raw, configPath) {
15
+ let document;
16
+ try {
17
+ document = JSON.parse(raw);
18
+ }
19
+ catch (error) {
20
+ throw new BrudConfigError('CONFIG_PARSE', `Config is not valid JSON: ${error instanceof Error ? error.message : String(error)}`, configPath);
21
+ }
22
+ if (!isRecord(document)) {
23
+ throw new BrudConfigError('CONFIG_SCHEMA', 'Config root must be an object', configPath);
24
+ }
25
+ const services = parseEntries(document.services, 'services', raw, configPath);
26
+ const exposureOwners = parseExposureOwners(document.exposureOwners, raw, configPath);
27
+ return Object.freeze(exposureOwners === undefined
28
+ ? { services }
29
+ : { services, exposureOwners });
30
+ }
31
+ /** Parses the composition's exposure-owner pins, failing closed. */
32
+ function parseExposureOwners(value, raw, configPath) {
33
+ if (value === undefined) {
34
+ return undefined;
35
+ }
36
+ if (!isRecord(value)) {
37
+ throw new BrudConfigError('CONFIG_SCHEMA', 'Config "exposureOwners" must be an object mapping exposure names to owner identities', configPath, lineOf(raw, 'exposureOwners'));
38
+ }
39
+ const pins = {};
40
+ for (const [name, owner] of Object.entries(value)) {
41
+ if (name.length === 0 || typeof owner !== 'string' || owner.length === 0) {
42
+ throw new BrudConfigError('CONFIG_SCHEMA', `Config exposureOwners["${name}"] must map a non-empty name to a non-empty owner identity`, configPath, lineOf(raw, name));
43
+ }
44
+ pins[name] = owner;
45
+ }
46
+ return Object.freeze(pins);
47
+ }
48
+ function parseEntries(value, key, raw, configPath) {
49
+ if (!Array.isArray(value)) {
50
+ throw new BrudConfigError('CONFIG_SCHEMA', `Config "${key}" must be an array`, configPath, lineOf(raw, key));
51
+ }
52
+ return value.map((entry, index) => {
53
+ if (!isRecord(entry)) {
54
+ throw new BrudConfigError('CONFIG_SCHEMA', `Config ${key}[${String(index)}] must be an object`, configPath, lineOf(raw, key));
55
+ }
56
+ for (const entryKey of Object.keys(entry)) {
57
+ if (!ENTRY_KEYS.has(entryKey)) {
58
+ throw new BrudConfigError('CONFIG_SCHEMA', `Config ${key}[${String(index)}] contains unknown key "${entryKey}"`, configPath, lineOf(raw, entryKey));
59
+ }
60
+ }
61
+ const path = entry.path;
62
+ if (typeof path !== 'string' || path.trim() === '') {
63
+ throw new BrudConfigError('CONFIG_SCHEMA', `Config ${key}[${String(index)}].path must be a non-empty string`, configPath, lineOf(raw, key));
64
+ }
65
+ const official = entry.official;
66
+ if (official !== undefined && typeof official !== 'boolean') {
67
+ throw new BrudConfigError('CONFIG_SCHEMA', `Config ${key}[${String(index)}].official must be a boolean`, configPath, lineOf(raw, path));
68
+ }
69
+ return official === undefined ? { path } : { path, official };
70
+ });
71
+ }
72
+ /** Finds the first source line containing a token. */
73
+ export function lineOf(raw, token) {
74
+ const lines = raw.split('\n');
75
+ const needle = JSON.stringify(token);
76
+ const index = lines.findIndex((line) => line.includes(needle) || line.includes(`"${token}"`));
77
+ return index < 0 ? undefined : index + 1;
78
+ }
79
+ function isRecord(value) {
80
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
81
+ }
@@ -0,0 +1,20 @@
1
+ /** Builds the failure raised when an operation targets a protected path. */
2
+ export type ProtectedPathErrorFactory = (storagePath: string, operation: string) => Error;
3
+ /**
4
+ * Marks a path read-only for the lifetime of one claim.
5
+ *
6
+ * Both the declared path and its real path are protected so an alias cannot
7
+ * bypass the guard. Repeated claims are reference-counted.
8
+ *
9
+ * @param storagePath - Absolute or resolvable path to protect.
10
+ * @param error - Failure factory for operations that target the path.
11
+ */
12
+ export declare function protectPath(storagePath: string, error: ProtectedPathErrorFactory): void;
13
+ /**
14
+ * Releases one claim on a protected path.
15
+ *
16
+ * @param storagePath - Path whose claim is released.
17
+ */
18
+ export declare function releasePath(storagePath: string): void;
19
+ /** Reports whether a path is currently protected by this process. */
20
+ export declare function isPathProtected(storagePath: string): boolean;