@brud/kernel 0.0.1 → 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 +0 -0
  2. package/README.md +0 -0
  3. package/dist/index.d.ts +0 -0
  4. package/dist/index.js +0 -0
  5. package/dist/serviceModules/events.d.ts +0 -0
  6. package/dist/serviceModules/events.js +0 -0
  7. package/dist/serviceModules/exposedApiRegistry.d.ts +0 -0
  8. package/dist/serviceModules/exposedApiRegistry.js +0 -0
  9. package/dist/serviceModules/identityRegistry.d.ts +0 -0
  10. package/dist/serviceModules/identityRegistry.js +0 -0
  11. package/dist/serviceModules/interception.d.ts +0 -0
  12. package/dist/serviceModules/interception.js +0 -0
  13. package/dist/serviceModules/parser.d.ts +0 -0
  14. package/dist/serviceModules/parser.js +0 -0
  15. package/dist/serviceModules/router.d.ts +0 -0
  16. package/dist/serviceModules/router.js +0 -0
  17. package/dist/serviceModules/wasmCage.d.ts +0 -0
  18. package/dist/serviceModules/wasmCage.js +0 -0
  19. package/dist/services/Events/contracts/IEventsService.d.ts +0 -0
  20. package/dist/services/Events/contracts/IEventsService.js +0 -0
  21. package/dist/services/Events/contracts/errors.d.ts +0 -0
  22. package/dist/services/Events/contracts/errors.js +0 -0
  23. package/dist/services/Events/contracts/index.d.ts +0 -0
  24. package/dist/services/Events/contracts/index.js +0 -0
  25. package/dist/services/Events/contracts/tokens.d.ts +0 -0
  26. package/dist/services/Events/contracts/tokens.js +0 -0
  27. package/dist/services/Events/descriptor/EventsDescriptor.d.ts +0 -0
  28. package/dist/services/Events/descriptor/EventsDescriptor.js +0 -0
  29. package/dist/services/Events/descriptor/tokens.d.ts +0 -0
  30. package/dist/services/Events/descriptor/tokens.js +0 -0
  31. package/dist/services/Events/index.d.ts +0 -0
  32. package/dist/services/Events/index.js +0 -0
  33. package/dist/services/Events/orchestrator/EventsService.d.ts +0 -0
  34. package/dist/services/Events/orchestrator/EventsService.js +0 -0
  35. package/dist/services/Events/orchestrator/index.d.ts +0 -0
  36. package/dist/services/Events/orchestrator/index.js +0 -0
  37. package/dist/services/Events/orchestrator/limits.d.ts +0 -0
  38. package/dist/services/Events/orchestrator/limits.js +0 -0
  39. package/dist/services/Events/serviceModule.d.ts +0 -0
  40. package/dist/services/Events/serviceModule.js +0 -0
  41. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +13 -1
  42. package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +0 -0
  43. package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +0 -0
  44. package/dist/services/ExposedApiRegistry/contracts/errors.js +0 -0
  45. package/dist/services/ExposedApiRegistry/contracts/index.d.ts +1 -1
  46. package/dist/services/ExposedApiRegistry/contracts/index.js +0 -0
  47. package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +0 -0
  48. package/dist/services/ExposedApiRegistry/contracts/policy.js +0 -0
  49. package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +0 -0
  50. package/dist/services/ExposedApiRegistry/contracts/registrant.js +0 -0
  51. package/dist/services/ExposedApiRegistry/contracts/types.d.ts +21 -0
  52. package/dist/services/ExposedApiRegistry/contracts/types.js +0 -0
  53. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +2 -2
  54. package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +2 -2
  55. package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +0 -0
  56. package/dist/services/ExposedApiRegistry/descriptor/tokens.js +0 -0
  57. package/dist/services/ExposedApiRegistry/index.d.ts +0 -0
  58. package/dist/services/ExposedApiRegistry/index.js +0 -0
  59. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +9 -2
  60. package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +50 -5
  61. package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +0 -0
  62. package/dist/services/ExposedApiRegistry/orchestrator/index.js +0 -0
  63. package/dist/services/ExposedApiRegistry/serviceModule.d.ts +0 -0
  64. package/dist/services/ExposedApiRegistry/serviceModule.js +0 -0
  65. package/dist/services/ExposedApiRegistry/storage/protection.d.ts +0 -0
  66. package/dist/services/ExposedApiRegistry/storage/protection.js +0 -0
  67. package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +0 -0
  68. package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +0 -0
  69. package/dist/services/IdentityRegistry/contracts/errors.d.ts +0 -0
  70. package/dist/services/IdentityRegistry/contracts/errors.js +0 -0
  71. package/dist/services/IdentityRegistry/contracts/index.d.ts +0 -0
  72. package/dist/services/IdentityRegistry/contracts/index.js +0 -0
  73. package/dist/services/IdentityRegistry/contracts/types.d.ts +0 -0
  74. package/dist/services/IdentityRegistry/contracts/types.js +0 -0
  75. package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +0 -0
  76. package/dist/services/IdentityRegistry/descriptor/descriptor.js +0 -0
  77. package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +0 -0
  78. package/dist/services/IdentityRegistry/descriptor/tokens.js +0 -0
  79. package/dist/services/IdentityRegistry/index.d.ts +0 -0
  80. package/dist/services/IdentityRegistry/index.js +0 -0
  81. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +0 -0
  82. package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +0 -0
  83. package/dist/services/IdentityRegistry/serviceModule.d.ts +0 -0
  84. package/dist/services/IdentityRegistry/serviceModule.js +0 -0
  85. package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +0 -0
  86. package/dist/services/IdentityRegistry/storage/registryDocument.js +0 -0
  87. package/dist/services/Interception/contracts/IInterceptionService.d.ts +91 -1
  88. package/dist/services/Interception/contracts/IInterceptionService.js +12 -1
  89. package/dist/services/Interception/contracts/errors.d.ts +0 -0
  90. package/dist/services/Interception/contracts/errors.js +0 -0
  91. package/dist/services/Interception/contracts/index.d.ts +0 -0
  92. package/dist/services/Interception/contracts/index.js +0 -0
  93. package/dist/services/Interception/contracts/tokens.d.ts +0 -0
  94. package/dist/services/Interception/contracts/tokens.js +0 -0
  95. package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +1 -1
  96. package/dist/services/Interception/descriptor/InterceptionDescriptor.js +2 -1
  97. package/dist/services/Interception/descriptor/tokens.d.ts +0 -0
  98. package/dist/services/Interception/descriptor/tokens.js +0 -0
  99. package/dist/services/Interception/index.d.ts +0 -0
  100. package/dist/services/Interception/index.js +0 -0
  101. package/dist/services/Interception/orchestrator/InterceptionService.d.ts +9 -1
  102. package/dist/services/Interception/orchestrator/InterceptionService.js +167 -4
  103. package/dist/services/Interception/orchestrator/index.d.ts +0 -0
  104. package/dist/services/Interception/orchestrator/index.js +0 -0
  105. package/dist/services/Interception/serviceModule.d.ts +0 -0
  106. package/dist/services/Interception/serviceModule.js +0 -0
  107. package/dist/services/Parser/contracts/IParserService.d.ts +0 -0
  108. package/dist/services/Parser/contracts/IParserService.js +0 -0
  109. package/dist/services/Parser/contracts/errors.d.ts +0 -0
  110. package/dist/services/Parser/contracts/errors.js +0 -0
  111. package/dist/services/Parser/contracts/index.d.ts +0 -0
  112. package/dist/services/Parser/contracts/index.js +0 -0
  113. package/dist/services/Parser/contracts/types.d.ts +0 -0
  114. package/dist/services/Parser/contracts/types.js +0 -0
  115. package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +0 -0
  116. package/dist/services/Parser/descriptor/ParserDescriptor.js +0 -0
  117. package/dist/services/Parser/descriptor/tokens.d.ts +0 -0
  118. package/dist/services/Parser/descriptor/tokens.js +0 -0
  119. package/dist/services/Parser/index.d.ts +0 -0
  120. package/dist/services/Parser/index.js +0 -0
  121. package/dist/services/Parser/orchestrator/ParserService.d.ts +0 -0
  122. package/dist/services/Parser/orchestrator/ParserService.js +0 -0
  123. package/dist/services/Parser/orchestrator/index.d.ts +0 -0
  124. package/dist/services/Parser/orchestrator/index.js +0 -0
  125. package/dist/services/Parser/parser/indexSynthesis.d.ts +0 -0
  126. package/dist/services/Parser/parser/indexSynthesis.js +0 -0
  127. package/dist/services/Parser/parser/parameters.d.ts +0 -0
  128. package/dist/services/Parser/parser/parameters.js +0 -0
  129. package/dist/services/Parser/parser/scanner.d.ts +0 -0
  130. package/dist/services/Parser/parser/scanner.js +0 -0
  131. package/dist/services/Parser/parser/syntax.d.ts +0 -0
  132. package/dist/services/Parser/parser/syntax.js +0 -0
  133. package/dist/services/Parser/serviceModule.d.ts +0 -0
  134. package/dist/services/Parser/serviceModule.js +0 -0
  135. package/dist/services/Router/bootOptions.d.ts +0 -0
  136. package/dist/services/Router/bootOptions.js +0 -0
  137. package/dist/services/Router/contracts/IRouterService.d.ts +1 -1
  138. package/dist/services/Router/contracts/IRouterService.js +0 -0
  139. package/dist/services/Router/contracts/caller.d.ts +0 -0
  140. package/dist/services/Router/contracts/caller.js +0 -0
  141. package/dist/services/Router/contracts/errors.d.ts +12 -1
  142. package/dist/services/Router/contracts/errors.js +15 -0
  143. package/dist/services/Router/contracts/index.d.ts +2 -2
  144. package/dist/services/Router/contracts/index.js +1 -1
  145. package/dist/services/Router/contracts/kind.d.ts +0 -0
  146. package/dist/services/Router/contracts/kind.js +0 -0
  147. package/dist/services/Router/contracts/registrant.d.ts +0 -0
  148. package/dist/services/Router/contracts/registrant.js +0 -0
  149. package/dist/services/Router/contracts/types.d.ts +28 -8
  150. package/dist/services/Router/contracts/types.js +0 -0
  151. package/dist/services/Router/descriptor/RouterDescriptor.d.ts +0 -0
  152. package/dist/services/Router/descriptor/RouterDescriptor.js +1 -1
  153. package/dist/services/Router/descriptor/tokens.d.ts +0 -0
  154. package/dist/services/Router/descriptor/tokens.js +0 -0
  155. package/dist/services/Router/index.d.ts +0 -0
  156. package/dist/services/Router/index.js +0 -0
  157. package/dist/services/Router/orchestrator/RouterService.d.ts +22 -3
  158. package/dist/services/Router/orchestrator/RouterService.js +131 -6
  159. package/dist/services/Router/orchestrator/index.d.ts +0 -0
  160. package/dist/services/Router/orchestrator/index.js +0 -0
  161. package/dist/services/Router/serviceModule.d.ts +0 -0
  162. package/dist/services/Router/serviceModule.js +0 -0
  163. package/dist/services/WasmCage/index.d.ts +0 -0
  164. package/dist/services/WasmCage/index.js +0 -0
  165. package/dist/services/WasmCage/scripts/prepin.d.ts +0 -0
  166. package/dist/services/WasmCage/scripts/prepin.js +0 -0
  167. package/dist/services/WasmCage/serviceModule.d.ts +0 -0
  168. package/dist/services/WasmCage/serviceModule.js +0 -0
  169. package/dist/services/WasmCage/src/caged.d.ts +19 -2
  170. package/dist/services/WasmCage/src/caged.js +85 -6
  171. package/dist/services/WasmCage/src/descriptor.d.ts +0 -0
  172. package/dist/services/WasmCage/src/descriptor.js +0 -0
  173. package/dist/services/WasmCage/src/native.d.ts +0 -0
  174. package/dist/services/WasmCage/src/native.js +0 -0
  175. package/dist/services/WasmCage/src/nativeDigests.d.ts +0 -0
  176. package/dist/services/WasmCage/src/nativeDigests.js +5 -5
  177. package/dist/services/WasmCage/src/package.d.ts +0 -0
  178. package/dist/services/WasmCage/src/package.js +0 -0
  179. package/dist/services/shared/canonicalJson.d.ts +0 -0
  180. package/dist/services/shared/canonicalJson.js +0 -0
  181. package/dist/services/shared/documentStore.d.ts +0 -0
  182. package/dist/services/shared/documentStore.js +0 -0
  183. package/dist/src/bootstrap/bootKernelInternal.d.ts +4 -3
  184. package/dist/src/bootstrap/bootKernelInternal.js +284 -71
  185. package/dist/src/bootstrap/bootTypes.d.ts +25 -1
  186. package/dist/src/bootstrap/bootTypes.js +0 -0
  187. package/dist/src/bootstrap/config/index.d.ts +0 -0
  188. package/dist/src/bootstrap/config/index.js +0 -0
  189. package/dist/src/bootstrap/config/integrity.d.ts +11 -0
  190. package/dist/src/bootstrap/config/integrity.js +13 -0
  191. package/dist/src/bootstrap/config/parse.d.ts +0 -0
  192. package/dist/src/bootstrap/config/parse.js +0 -0
  193. package/dist/src/bootstrap/config/pathWriteGuard.d.ts +0 -0
  194. package/dist/src/bootstrap/config/pathWriteGuard.js +0 -0
  195. package/dist/src/bootstrap/config/types.d.ts +1 -1
  196. package/dist/src/bootstrap/config/types.js +0 -0
  197. package/dist/src/bootstrap/hardcore.d.ts +0 -0
  198. package/dist/src/bootstrap/hardcore.js +0 -0
  199. package/dist/src/bootstrap/hardcoreServices.d.ts +0 -0
  200. package/dist/src/bootstrap/hardcoreServices.js +14 -14
  201. package/dist/src/bootstrap/index.d.ts +6 -1
  202. package/dist/src/bootstrap/index.js +2 -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 +0 -0
  206. package/dist/src/bootstrap/packageRequirements.js +0 -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 +0 -0
  212. package/dist/src/contracts/accessBroker.js +0 -0
  213. package/dist/src/contracts/brudOperation.d.ts +0 -0
  214. package/dist/src/contracts/brudOperation.js +0 -0
  215. package/dist/src/contracts/callChain.d.ts +0 -0
  216. package/dist/src/contracts/callChain.js +0 -0
  217. package/dist/src/contracts/capability.d.ts +0 -0
  218. package/dist/src/contracts/capability.js +0 -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 +0 -0
  222. package/dist/src/contracts/container.js +0 -0
  223. package/dist/src/contracts/context.d.ts +0 -0
  224. package/dist/src/contracts/context.js +0 -0
  225. package/dist/src/contracts/contextContract.d.ts +11 -8
  226. package/dist/src/contracts/contextContract.js +21 -32
  227. package/dist/src/contracts/dispatchView.d.ts +3 -3
  228. package/dist/src/contracts/dispatchView.js +0 -0
  229. package/dist/src/contracts/handler.d.ts +0 -7
  230. package/dist/src/contracts/handler.js +0 -0
  231. package/dist/src/contracts/index.d.ts +2 -1
  232. package/dist/src/contracts/index.js +1 -0
  233. package/dist/src/contracts/kernel.d.ts +0 -0
  234. package/dist/src/contracts/kernel.js +0 -0
  235. package/dist/src/contracts/lifecycle.d.ts +0 -0
  236. package/dist/src/contracts/lifecycle.js +0 -0
  237. package/dist/src/contracts/manifest.d.ts +35 -0
  238. package/dist/src/contracts/manifest.js +62 -23
  239. package/dist/src/contracts/pipeline.d.ts +0 -0
  240. package/dist/src/contracts/pipeline.js +0 -0
  241. package/dist/src/contracts/policy.d.ts +0 -0
  242. package/dist/src/contracts/policy.js +0 -0
  243. package/dist/src/contracts/registry.d.ts +0 -0
  244. package/dist/src/contracts/registry.js +0 -0
  245. package/dist/src/contracts/serviceDescriptor.d.ts +0 -0
  246. package/dist/src/contracts/serviceDescriptor.js +0 -0
  247. package/dist/src/contracts/serviceToken.d.ts +0 -0
  248. package/dist/src/contracts/serviceToken.js +0 -0
  249. package/dist/src/engine/BrudKernel.d.ts +2 -0
  250. package/dist/src/engine/BrudKernel.js +35 -6
  251. package/dist/src/engine/ExecutionPipeline.d.ts +0 -0
  252. package/dist/src/engine/ExecutionPipeline.js +0 -0
  253. package/dist/src/engine/KernelAccessBroker.d.ts +0 -0
  254. package/dist/src/engine/KernelAccessBroker.js +0 -0
  255. package/dist/src/engine/KernelRegistry.d.ts +0 -0
  256. package/dist/src/engine/KernelRegistry.js +0 -0
  257. package/dist/src/engine/OperationRegistry.d.ts +0 -0
  258. package/dist/src/engine/OperationRegistry.js +0 -0
  259. package/dist/src/engine/ServiceContainer.d.ts +0 -0
  260. package/dist/src/engine/ServiceContainer.js +0 -0
  261. package/dist/src/engine/callChain.d.ts +0 -0
  262. package/dist/src/engine/callChain.js +5 -10
  263. package/dist/src/engine/dag.d.ts +0 -0
  264. package/dist/src/engine/dag.js +0 -0
  265. package/dist/src/engine/errors.d.ts +0 -0
  266. package/dist/src/engine/errors.js +0 -0
  267. package/dist/src/engine/index.d.ts +0 -0
  268. package/dist/src/engine/index.js +0 -0
  269. package/dist/src/engine/state.d.ts +0 -0
  270. package/dist/src/engine/state.js +0 -0
  271. package/dist/src/validation/jsonSchema/compile.d.ts +0 -0
  272. package/dist/src/validation/jsonSchema/compile.js +0 -0
  273. package/dist/src/validation/jsonSchema/index.d.ts +0 -0
  274. package/dist/src/validation/jsonSchema/index.js +0 -0
  275. package/dist/src/validation/jsonSchema/jsonValue.d.ts +0 -0
  276. package/dist/src/validation/jsonSchema/jsonValue.js +0 -0
  277. package/dist/src/validation/jsonSchema/pattern.d.ts +0 -0
  278. package/dist/src/validation/jsonSchema/pattern.js +0 -0
  279. package/dist/src/validation/jsonSchema/types.d.ts +0 -0
  280. package/dist/src/validation/jsonSchema/types.js +0 -0
  281. package/package.json +1 -1
  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
@@ -60,6 +60,15 @@ export interface InterceptionDeclaration {
60
60
  readonly target: string;
61
61
  /** Major version of the target; defaults to 1. */
62
62
  readonly version?: number | string;
63
+ /**
64
+ * The stages this interceptor takes part in: `'input'` (it sees a call's
65
+ * arguments before the giver runs, and may modify or block them) and
66
+ * `'output'` (it may append content to the giver's result). Defaults to
67
+ * `['output']`: seeing or changing arguments must be asked for explicitly.
68
+ * A declared stage must be implemented. An output interceptor that is not is
69
+ * skipped; an input interceptor that is not blocks the call.
70
+ */
71
+ readonly stages?: readonly ('input' | 'output')[];
63
72
  }
64
73
  /**
65
74
  * One interception point a giver declares on one of its own exposures, naming
@@ -79,6 +88,12 @@ export interface InterceptionPointDeclaration {
79
88
  readonly operations?: Readonly<Record<string, KindOperationDescription>>;
80
89
  /** Service tokens of the admitted interceptors, in run order. */
81
90
  readonly admit: readonly string[];
91
+ /**
92
+ * Lowers the kernel's output-stage limits for this point, in bytes of
93
+ * canonical JSON. The Interception primitive validates the values; a value
94
+ * can lower a kernel ceiling and never raise it.
95
+ */
96
+ readonly outputLimits?: Readonly<Record<string, number>>;
82
97
  }
83
98
  /**
84
99
  * One Brud Syntax kind a participant claims, served by one of its own
@@ -89,6 +104,12 @@ export interface KindOperationDescription {
89
104
  readonly description?: string;
90
105
  /** JSON Schema of the operation's input (plain JSON). */
91
106
  readonly input?: Readonly<Record<string, unknown>>;
107
+ /**
108
+ * Who may call this operation: a Layer 1 policy object, in the same
109
+ * language as an exposure's `policy`. Falls back to the kind's `permission`.
110
+ * The Router validates and evaluates it; admission checks only its shape.
111
+ */
112
+ readonly permission?: Readonly<Record<string, unknown>>;
92
113
  }
93
114
  export interface KindDeclaration {
94
115
  /** The kind word written after `[CALL`, e.g. `tool`. */
@@ -97,6 +118,20 @@ export interface KindDeclaration {
97
118
  readonly exposure: string;
98
119
  /** Major version of the exposure; defaults to 1. */
99
120
  readonly version?: number | string;
121
+ /** Public description of the kind. */
122
+ readonly description?: string;
123
+ /**
124
+ * Every operation the kind serves, by name. Required: the kernel refuses an
125
+ * operation that is not listed, before the owner is reached.
126
+ *
127
+ * `'open'` declares that the owner defines the operation names itself (for
128
+ * example from a registry filled at runtime), so the kernel cannot list them.
129
+ * It must be written out, and the kind's `permission` is then required and is
130
+ * enforced on every call; the owner decides which names exist.
131
+ */
132
+ readonly operations: Readonly<Record<string, KindOperationDescription>> | 'open';
133
+ /** Default permission for operations that declare none; required when `operations` is `'open'`. */
134
+ readonly permission?: Readonly<Record<string, unknown>>;
100
135
  }
101
136
  /** A participant's manifest. */
102
137
  export interface ParticipantManifest {
@@ -19,14 +19,15 @@ export class ParticipantManifestError extends Error {
19
19
  }
20
20
  }
21
21
  const MANIFEST_KEYS = new Set(['requests', 'exposures', 'events', 'interceptions', 'interceptionPoints', 'kinds']);
22
- const KIND_KEYS = new Set(['kind', 'exposure', 'version', 'description', 'operations']);
23
- const KIND_OPERATION_KEYS = new Set(['description', 'input']);
22
+ const KIND_KEYS = new Set(['kind', 'exposure', 'version', 'description', 'operations', 'permission']);
23
+ const KIND_OPERATION_KEYS = new Set(['description', 'input', 'permission']);
24
+ const KIND_OPERATION_PATTERN = /^[A-Za-z][A-Za-z0-9_.-]*$/u;
24
25
  const KIND_PATTERN = /^[a-z][a-z0-9_-]*$/u;
25
26
  const REQUEST_KEYS = new Set(['capabilities']);
26
27
  const EXPOSURE_KEYS = new Set(['name', 'version', 'scope', 'policy']);
27
28
  const EVENT_KEYS = new Set(['name', 'version', 'scope', 'policy', 'payloadSchema']);
28
- const INTERCEPTION_KEYS = new Set(['target', 'version']);
29
- const INTERCEPTION_POINT_KEYS = new Set(['exposure', 'version', 'admit']);
29
+ const INTERCEPTION_KEYS = new Set(['target', 'version', 'stages']);
30
+ const INTERCEPTION_POINT_KEYS = new Set(['exposure', 'version', 'admit', 'outputLimits']);
30
31
  function isPlainObject(value) {
31
32
  if (value === null || typeof value !== 'object' || Array.isArray(value)) {
32
33
  return false;
@@ -206,12 +207,25 @@ function admitInterceptions(value, participant) {
206
207
  throw new ParticipantManifestError(participant, `${path}.target must be a non-empty string`);
207
208
  }
208
209
  assertVersion(entry.version, path, participant);
209
- return Object.freeze(entry);
210
+ const stages = entry.stages;
211
+ if (stages !== undefined
212
+ && (!Array.isArray(stages)
213
+ || stages.length === 0
214
+ || new Set(stages).size !== stages.length
215
+ || stages.some((stage) => stage !== 'input' && stage !== 'output'))) {
216
+ throw new ParticipantManifestError(participant, `${path}.stages must be a non-empty list of unique "input" or "output"`);
217
+ }
218
+ return Object.freeze({
219
+ ...entry,
220
+ ...(stages === undefined ? {} : { stages: Object.freeze([...stages]) }),
221
+ });
210
222
  }));
211
223
  }
212
224
  /**
213
225
  * Admits `manifest.kinds`. Each kind names one of the participant's own
214
- * declared exposures; a kind may be claimed once per manifest.
226
+ * declared exposures, lists every operation it serves, and gives each
227
+ * operation a permission (its own, or the kind's); a kind may be claimed once
228
+ * per manifest. The Router validates and evaluates the permissions.
215
229
  */
216
230
  function admitKinds(value, exposures, participant) {
217
231
  if (value === undefined) {
@@ -245,22 +259,38 @@ function admitKinds(value, exposures, participant) {
245
259
  if (entry.description !== undefined && typeof entry.description !== 'string') {
246
260
  throw new ParticipantManifestError(participant, `${path}.description must be a string`);
247
261
  }
248
- if (entry.operations !== undefined) {
249
- if (!isPlainObject(entry.operations)) {
250
- throw new ParticipantManifestError(participant, `${path}.operations must be an object`);
262
+ if (entry.permission !== undefined && !isPlainObject(entry.permission)) {
263
+ throw new ParticipantManifestError(participant, `${path}.permission must be a policy object`);
264
+ }
265
+ if (entry.operations === 'open') {
266
+ if (entry.permission === undefined) {
267
+ throw new ParticipantManifestError(participant, `${path}.permission is required when operations is "open"; write { "policyVersion": 2 } to allow every routing caller`);
251
268
  }
252
- for (const [name, operation] of Object.entries(entry.operations)) {
253
- const at = `${path}.operations.${name}`;
254
- if (!isPlainObject(operation)) {
255
- throw new ParticipantManifestError(participant, `${at} must be an object`);
256
- }
257
- assertKnownKeys(operation, KIND_OPERATION_KEYS, at, participant);
258
- if (operation.description !== undefined && typeof operation.description !== 'string') {
259
- throw new ParticipantManifestError(participant, `${at}.description must be a string`);
260
- }
261
- if (operation.input !== undefined && !isPlainObject(operation.input)) {
262
- throw new ParticipantManifestError(participant, `${at}.input must be a JSON Schema object`);
263
- }
269
+ return Object.freeze(JSON.parse(JSON.stringify(entry)));
270
+ }
271
+ if (!isPlainObject(entry.operations) || Object.keys(entry.operations).length === 0) {
272
+ throw new ParticipantManifestError(participant, `${path}.operations is required: declare every operation the kind serves, or write "open" if its owner defines the names at runtime`);
273
+ }
274
+ for (const [name, operation] of Object.entries(entry.operations)) {
275
+ const at = `${path}.operations.${name}`;
276
+ if (!KIND_OPERATION_PATTERN.test(name)) {
277
+ throw new ParticipantManifestError(participant, `${at}: operation names start with a letter and use letters, digits, "_", "-" and "."`);
278
+ }
279
+ if (!isPlainObject(operation)) {
280
+ throw new ParticipantManifestError(participant, `${at} must be an object`);
281
+ }
282
+ assertKnownKeys(operation, KIND_OPERATION_KEYS, at, participant);
283
+ if (operation.description !== undefined && typeof operation.description !== 'string') {
284
+ throw new ParticipantManifestError(participant, `${at}.description must be a string`);
285
+ }
286
+ if (operation.input !== undefined && !isPlainObject(operation.input)) {
287
+ throw new ParticipantManifestError(participant, `${at}.input must be a JSON Schema object`);
288
+ }
289
+ if (operation.permission !== undefined && !isPlainObject(operation.permission)) {
290
+ throw new ParticipantManifestError(participant, `${at}.permission must be a policy object`);
291
+ }
292
+ if (operation.permission === undefined && entry.permission === undefined) {
293
+ throw new ParticipantManifestError(participant, `${at}.permission is required, or declare a kind-level permission; write { "policyVersion": 2 } to allow every routing caller`);
264
294
  }
265
295
  }
266
296
  // Deep copy so the admitted declaration is plain, frozen data.
@@ -288,8 +318,17 @@ function admitInterceptionPoints(value, participant) {
288
318
  if (!Array.isArray(admit)
289
319
  || admit.some((token) => typeof token !== 'string' || token.length === 0)
290
320
  || new Set(admit).size !== admit.length) {
291
- throw new ParticipantManifestError(participant, `${path}.admit must be an array of unique non-empty service tokens`);
321
+ const object = Array.isArray(admit) ? admit.find((token) => isPlainObject(token) && typeof token.id === 'string') : undefined;
322
+ const hint = object === undefined ? '' : ` A token object was given; pass its id string ("${object.id}") instead`;
323
+ throw new ParticipantManifestError(participant, `${path}.admit must be an array of unique non-empty service token id strings.${hint}`);
324
+ }
325
+ if (entry.outputLimits !== undefined && !isPlainObject(entry.outputLimits)) {
326
+ throw new ParticipantManifestError(participant, `${path}.outputLimits must be an object`);
292
327
  }
293
- return Object.freeze({ ...entry, admit: Object.freeze([...admit]) });
328
+ return Object.freeze({
329
+ ...entry,
330
+ admit: Object.freeze([...admit]),
331
+ ...(entry.outputLimits === undefined ? {} : { outputLimits: Object.freeze({ ...entry.outputLimits }) }),
332
+ });
294
333
  }));
295
334
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -116,3 +116,5 @@ export declare class BrudKernel implements IBrudKernel {
116
116
  private createExecutionContext;
117
117
  generatePromptManifest(): PromptManifest;
118
118
  }
119
+ /** The token of the service whose lifecycle code threw `error`, when the kernel recorded it. */
120
+ export declare function failingServiceOf(error: unknown): string | undefined;
@@ -154,12 +154,18 @@ export class BrudKernel {
154
154
  options: this.bootOptions,
155
155
  ...(options.logger === undefined ? {} : { logger: options.logger }),
156
156
  };
157
- const instance = descriptor.factory(context, this.accessBroker);
158
- this.registry.setInstance(descriptor.token.id, instance);
159
- if (typeof instance.initialize === 'function') {
160
- await instance.initialize(this.accessBroker);
157
+ try {
158
+ const instance = descriptor.factory(context, this.accessBroker);
159
+ this.registry.setInstance(descriptor.token.id, instance);
160
+ if (typeof instance.initialize === 'function') {
161
+ await instance.initialize(this.accessBroker);
162
+ }
163
+ this.initializedServices.push({ tokenId: descriptor.token.id, instance });
164
+ }
165
+ catch (error) {
166
+ tagFailingService(error, descriptor.token.id);
167
+ throw error;
161
168
  }
162
- this.initializedServices.push({ tokenId: descriptor.token.id, instance });
163
169
  });
164
170
  };
165
171
  for (const descriptor of hardcoreOrder) {
@@ -217,7 +223,13 @@ export class BrudKernel {
217
223
  try {
218
224
  for (const { tokenId, instance } of this.initializedServices) {
219
225
  if (typeof instance.onRunning === 'function') {
220
- await this.runFor(tokenId, () => instance.onRunning?.(this.accessBroker));
226
+ try {
227
+ await this.runFor(tokenId, () => instance.onRunning?.(this.accessBroker));
228
+ }
229
+ catch (error) {
230
+ tagFailingService(error, tokenId);
231
+ throw error;
232
+ }
221
233
  }
222
234
  }
223
235
  }
@@ -364,3 +376,20 @@ export class BrudKernel {
364
376
  return { operations };
365
377
  }
366
378
  }
379
+ /**
380
+ * Records, on an error thrown by a service's own lifecycle code, which service
381
+ * threw it. The mark is not enumerable and never replaces an earlier one, so
382
+ * the error keeps its type and message. A caller that must decide what to do
383
+ * about a failed boot reads it with `failingServiceOf`.
384
+ */
385
+ function tagFailingService(error, tokenId) {
386
+ if (error !== null && typeof error === 'object' && !(FAILING_SERVICE in error)) {
387
+ Object.defineProperty(error, FAILING_SERVICE, { value: tokenId, enumerable: false });
388
+ }
389
+ }
390
+ const FAILING_SERVICE = Symbol.for('brud.kernel.failingService');
391
+ /** The token of the service whose lifecycle code threw `error`, when the kernel recorded it. */
392
+ export function failingServiceOf(error) {
393
+ const value = error !== null && typeof error === 'object' ? error[FAILING_SERVICE] : undefined;
394
+ return typeof value === 'string' ? value : undefined;
395
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,3 +1,4 @@
1
+ import { NO_CAPABILITIES, createCapabilitySet } from '../contracts/capabilitySet.js';
1
2
  import { AsyncLocalStorage } from 'node:async_hooks';
2
3
  import { DEFAULT_KERNEL_CALL_LIMITS, } from '../contracts/callChain.js';
3
4
  /**
@@ -9,20 +10,19 @@ import { DEFAULT_KERNEL_CALL_LIMITS, } from '../contracts/callChain.js';
9
10
  const frames = new AsyncLocalStorage();
10
11
  /** Largest number of records the observation stream retains. */
11
12
  const OBSERVATION_CAPACITY = 1_000;
12
- const EMPTY_CAPABILITIES = Object.freeze(new Set());
13
13
  /** The kernel itself as a caller. */
14
14
  export const KERNEL_CALLER = Object.freeze({
15
15
  callerClass: 'kernel',
16
16
  identity: null,
17
17
  official: true,
18
- capabilities: EMPTY_CAPABILITIES,
18
+ capabilities: NO_CAPABILITIES,
19
19
  });
20
20
  /** A participant the kernel has not assigned an identity to. */
21
21
  export const UNIDENTIFIED_PARTICIPANT = Object.freeze({
22
22
  callerClass: 'participant',
23
23
  identity: null,
24
24
  official: false,
25
- capabilities: EMPTY_CAPABILITIES,
25
+ capabilities: NO_CAPABILITIES,
26
26
  });
27
27
  /**
28
28
  * One kernel's call chain.
@@ -88,17 +88,12 @@ export class KernelCallChain {
88
88
  * @param operation - Work performed inside the chain.
89
89
  */
90
90
  runHost(session, operation) {
91
- const capabilities = new Set();
92
- for (const capability of session.capabilities ?? []) {
93
- if (typeof capability === 'string' && capability.length > 0) {
94
- capabilities.add(capability);
95
- }
96
- }
91
+ const capabilities = createCapabilitySet([...(session.capabilities ?? [])].filter((capability) => typeof capability === 'string' && capability.length > 0));
97
92
  const caller = Object.freeze({
98
93
  callerClass: 'host',
99
94
  identity: null,
100
95
  official: false,
101
- capabilities: Object.freeze(capabilities),
96
+ capabilities,
102
97
  });
103
98
  return this.runRoot('host', caller, operation);
104
99
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brud/kernel",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",