@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
@@ -1,6 +1,6 @@
1
1
  import type { AdmittedManifest, KernelCallAuthority } from '../../../src/contracts/index.js';
2
2
  import type { ExposedApiCaller } from '../../ExposedApiRegistry/contracts/types.js';
3
- import type { IInterceptionService, InterceptionEvaluateOptions, InterceptionOutcome } from '../contracts/IInterceptionService.js';
3
+ import { type IInterceptionService, type InterceptionEvaluateOptions, type InterceptionOutcome, type InterceptionResultOutcome } from '../contracts/IInterceptionService.js';
4
4
  /** One participant of the composition, as the boot hook hands it over. */
5
5
  export interface InterceptionParticipant {
6
6
  readonly token: string;
@@ -29,4 +29,12 @@ export declare class InterceptionService implements IInterceptionService {
29
29
  * (fail closed).
30
30
  */
31
31
  evaluateAs(resolver: ExposedApiCaller | undefined, target: string, method: string, args: readonly unknown[], options?: InterceptionEvaluateOptions): InterceptionOutcome;
32
+ evaluateResult(target: string, method: string, args: readonly unknown[], result: unknown, options?: InterceptionEvaluateOptions): InterceptionResultOutcome;
33
+ /**
34
+ * Runs the output stage for `resolver`, which must be the point's owner. The
35
+ * interceptors that declared the stage run in the giver's admitted order,
36
+ * each as itself and each seeing only the original result; each may append
37
+ * one piece of content and nothing else. Any failure withholds the result.
38
+ */
39
+ evaluateResultAs(resolver: ExposedApiCaller | undefined, target: string, method: string, args: readonly unknown[], result: unknown, options?: InterceptionEvaluateOptions): InterceptionResultOutcome;
32
40
  }
@@ -1,6 +1,8 @@
1
+ import { createCapabilitySet } from '../../../src/contracts/capabilitySet.js';
1
2
  import { compileJsonSchema } from '../../../src/validation/jsonSchema/index.js';
2
- import { freezeJsonCopy } from '../../../src/validation/jsonSchema/jsonValue.js';
3
+ import { freezeJsonCopy, inspectJsonValue } from '../../../src/validation/jsonSchema/jsonValue.js';
3
4
  import { InterceptionDeclarationError } from '../contracts/errors.js';
5
+ import { INTERCEPTION_OUTPUT_CEILINGS, } from '../contracts/IInterceptionService.js';
4
6
  /** Source name the interception hardcore records observations under. */
5
7
  const OBSERVATION_SOURCE = 'brud.core.interception';
6
8
  /** Arguments must be a plain JSON array within the kernel validator's limits. */
@@ -23,6 +25,36 @@ function pointKey(name, version) {
23
25
  function isInterceptor(value) {
24
26
  return typeof value?.intercept === 'function';
25
27
  }
28
+ function isResultInterceptor(value) {
29
+ return typeof value?.interceptResult === 'function';
30
+ }
31
+ /** Largest value shape the output stage will carry: plain JSON of ordinary size. */
32
+ const OUTPUT_JSON_LIMITS = Object.freeze({ maxDepth: 64, maxNodes: 100_000 });
33
+ function jsonBytes(value) {
34
+ return Buffer.byteLength(JSON.stringify(value), 'utf8');
35
+ }
36
+ /**
37
+ * Reads a point's `outputLimits`: any of the three limits may be lowered,
38
+ * none may be raised above its kernel ceiling, and one addition may not be
39
+ * allowed to exceed all additions together.
40
+ */
41
+ function parseOutputLimits(owner, key, declared) {
42
+ const limits = { ...INTERCEPTION_OUTPUT_CEILINGS };
43
+ for (const [name, value] of Object.entries(declared ?? {})) {
44
+ if (!(name in INTERCEPTION_OUTPUT_CEILINGS)) {
45
+ throw new InterceptionDeclarationError(owner, `outputLimits of "${key}" has an unknown limit "${name}"`);
46
+ }
47
+ const ceiling = INTERCEPTION_OUTPUT_CEILINGS[name];
48
+ if (typeof value !== 'number' || !Number.isInteger(value) || value < 1 || value > ceiling) {
49
+ throw new InterceptionDeclarationError(owner, `outputLimits.${name} of "${key}" must be a whole number from 1 to ${String(ceiling)}`);
50
+ }
51
+ limits[name] = value;
52
+ }
53
+ if (limits.maxAdditionBytes > limits.maxTotalBytes) {
54
+ throw new InterceptionDeclarationError(owner, `outputLimits of "${key}" allow one addition to exceed all additions together`);
55
+ }
56
+ return Object.freeze(limits);
57
+ }
26
58
  function isValidArgs(value) {
27
59
  return Array.isArray(value) && ARGS_SCHEMA.validate(value).valid;
28
60
  }
@@ -82,9 +114,15 @@ export class InterceptionService {
82
114
  if (interceptor.identity === undefined) {
83
115
  throw new InterceptionDeclarationError(token, 'is admitted as an interceptor but has no kernel identity');
84
116
  }
85
- return Object.freeze({ token, identity: interceptor.identity });
117
+ const declared = interceptor.manifest.interceptions.find((entry) => pointKey(entry.target, entry.version) === key);
118
+ return Object.freeze({ token, identity: interceptor.identity, stages: Object.freeze([...(declared?.stages ?? ['output'])]) });
86
119
  });
87
- this.#points.set(key, Object.freeze({ key, owner, interceptors: Object.freeze(interceptors) }));
120
+ this.#points.set(key, Object.freeze({
121
+ key,
122
+ owner,
123
+ interceptors: Object.freeze(interceptors),
124
+ limits: parseOutputLimits(participant.token, key, point.outputLimits),
125
+ }));
88
126
  }
89
127
  }
90
128
  for (const [key, tokens] of requests) {
@@ -134,12 +172,16 @@ export class InterceptionService {
134
172
  identity: caller.identity,
135
173
  callerClass: caller.callerClass,
136
174
  official: caller.official,
137
- capabilities: Object.freeze(Array.from(caller.capabilities ?? []).sort()),
175
+ // The giver names the caller it is intercepting for; whatever it passes, the interceptor sees the one read-only shape.
176
+ capabilities: createCapabilitySet(caller.capabilities ?? []),
138
177
  origin: caller.origin,
139
178
  }),
140
179
  });
141
180
  const modifiedBy = [];
142
181
  for (const interceptor of point.interceptors) {
182
+ if (!interceptor.stages.includes('input')) {
183
+ continue;
184
+ }
143
185
  let verdict;
144
186
  try {
145
187
  const instance = authority.instanceOf(interceptor.identity);
@@ -169,6 +211,127 @@ export class InterceptionService {
169
211
  }
170
212
  return Object.freeze({ allowed: true, args: call.args, modifiedBy: Object.freeze(modifiedBy) });
171
213
  }
214
+ evaluateResult(target, method, args, result, options) {
215
+ const context = this.authority?.current();
216
+ const caller = context === undefined ? undefined : { ...context.caller, origin: context.origin };
217
+ return this.evaluateResultAs(caller, target, method, args, result, options);
218
+ }
219
+ /**
220
+ * Runs the output stage for `resolver`, which must be the point's owner. The
221
+ * interceptors that declared the stage run in the giver's admitted order,
222
+ * each as itself and each seeing only the original result; each may append
223
+ * one piece of content and nothing else. Any failure withholds the result.
224
+ */
225
+ evaluateResultAs(resolver, target, method, args, result, options) {
226
+ const key = target.includes('@') ? target : `${target}@1`;
227
+ const point = this.#points.get(key);
228
+ const authority = this.authority;
229
+ if (authority === undefined) {
230
+ return this.#refuseResult(key, 'interception is not bound');
231
+ }
232
+ if (point === undefined) {
233
+ return this.#refuseResult(key, 'unknown interception point');
234
+ }
235
+ if (resolver?.identity === null || resolver?.identity === undefined || resolver.identity !== point.owner) {
236
+ return this.#refuseResult(key, 'only the interception point owner may evaluate it');
237
+ }
238
+ const taking = point.interceptors.filter((interceptor) => interceptor.stages.includes('output'));
239
+ if (taking.length === 0) {
240
+ return Object.freeze({ applied: false });
241
+ }
242
+ if (typeof method !== 'string' || method.length === 0 || !isValidArgs(args)) {
243
+ return this.#refuseResult(key, 'method must be a non-empty string and args a plain JSON array');
244
+ }
245
+ // A result the output stage cannot carry is the giver's own data, never an
246
+ // interceptor's doing. The stage is skipped and the giver ships its result.
247
+ if (inspectJsonValue(result, OUTPUT_JSON_LIMITS) !== null) {
248
+ return this.#skipStage(key, 'the result must be plain JSON to take part in the output stage');
249
+ }
250
+ const resultBytes = result === undefined ? 0 : jsonBytes(result);
251
+ if (resultBytes > point.limits.maxResultBytes) {
252
+ return this.#skipStage(key, `the result is ${String(resultBytes)} bytes; the limit is ${String(point.limits.maxResultBytes)}`);
253
+ }
254
+ const caller = options?.caller ?? resolver;
255
+ const frozenResult = freezeJsonCopy(result);
256
+ const call = Object.freeze({
257
+ target: key,
258
+ method,
259
+ args: freezeJsonCopy(args),
260
+ caller: Object.freeze({
261
+ identity: caller.identity,
262
+ callerClass: caller.callerClass,
263
+ official: caller.official,
264
+ capabilities: createCapabilitySet(caller.capabilities ?? []),
265
+ origin: caller.origin,
266
+ }),
267
+ result: frozenResult,
268
+ });
269
+ const additions = [];
270
+ const ran = [];
271
+ const skipped = [];
272
+ let total = 0;
273
+ // The output stage can only append, so an interceptor that misbehaves is
274
+ // skipped and the result is delivered without its contribution. It must
275
+ // never be able to withhold the giver's result by failing.
276
+ for (const interceptor of taking) {
277
+ const skip = (reason) => {
278
+ skipped.push(Object.freeze({ interceptor: interceptor.token, reason }));
279
+ authority.observe(OBSERVATION_SOURCE, 'interception.result.skipped', { target: key, method, interceptor: interceptor.token, reason });
280
+ };
281
+ let verdict;
282
+ try {
283
+ const instance = authority.instanceOf(interceptor.identity);
284
+ if (!isResultInterceptor(instance)) {
285
+ throw new Error('the interceptor does not implement interceptResult (an interceptor that means to see arguments must declare the input stage)');
286
+ }
287
+ verdict = authority.runAs(interceptor.identity, () => instance.interceptResult(call));
288
+ }
289
+ catch (error) {
290
+ skip(error instanceof Error ? error.message : 'interceptor threw');
291
+ continue;
292
+ }
293
+ if (verdict?.verdict === 'none') {
294
+ ran.push(interceptor.token);
295
+ authority.observe(OBSERVATION_SOURCE, 'interception.result.unchanged', { target: key, method, interceptor: interceptor.token });
296
+ continue;
297
+ }
298
+ if (verdict?.verdict !== 'append' || inspectJsonValue(verdict.content, OUTPUT_JSON_LIMITS) !== null || verdict.content === undefined) {
299
+ skip('invalid output verdict: the output stage can only append');
300
+ continue;
301
+ }
302
+ const bytes = jsonBytes(verdict.content);
303
+ if (bytes > point.limits.maxAdditionBytes) {
304
+ skip(`the addition is ${String(bytes)} bytes; the limit is ${String(point.limits.maxAdditionBytes)}`);
305
+ continue;
306
+ }
307
+ if (total + bytes > point.limits.maxTotalBytes) {
308
+ skip(`the additions together would exceed ${String(point.limits.maxTotalBytes)} bytes`);
309
+ continue;
310
+ }
311
+ total += bytes;
312
+ ran.push(interceptor.token);
313
+ additions.push(Object.freeze({ interceptor: interceptor.token, content: freezeJsonCopy(verdict.content) }));
314
+ authority.observe(OBSERVATION_SOURCE, 'interception.result.appended', { target: key, method, interceptor: interceptor.token, bytes });
315
+ }
316
+ return Object.freeze({
317
+ applied: true,
318
+ allowed: true,
319
+ envelope: Object.freeze({
320
+ result: frozenResult,
321
+ additions: Object.freeze(additions),
322
+ interceptedBy: Object.freeze(ran),
323
+ skipped: Object.freeze(skipped),
324
+ }),
325
+ });
326
+ }
327
+ #refuseResult(key, reason) {
328
+ this.authority?.observe(OBSERVATION_SOURCE, 'interception.result.refused', { target: key, reason });
329
+ return Object.freeze({ applied: true, allowed: false, reason });
330
+ }
331
+ #skipStage(key, reason) {
332
+ this.authority?.observe(OBSERVATION_SOURCE, 'interception.result.stage-skipped', { target: key, reason });
333
+ return Object.freeze({ applied: false });
334
+ }
172
335
  #refuse(key, reason) {
173
336
  this.authority?.observe(OBSERVATION_SOURCE, 'interception.refused', { target: key, reason });
174
337
  return Object.freeze({ allowed: false, reason });
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
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
@@ -6,7 +6,7 @@ import type { BrudKindInfo, BrudDispatchCaller, BrudRouteOptions, BrudRouteRegis
6
6
  *
7
7
  * Accepts boot-time kind registrations from kernel services, resolves the
8
8
  * owning service through the kernel access broker with its `ServiceToken`, and
9
- * dispatches parsed operations. It never routes to a plugin directly.
9
+ * dispatches parsed operations. It routes only to the service that owns a kind.
10
10
  */
11
11
  export interface IRouterService {
12
12
  /**
File without changes
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  /** Stable, machine-readable codes for Router failures. */
2
- export type RouterErrorCode = 'ROUTER_REGISTRATION_CLOSED' | 'ROUTER_KIND_COLLISION' | 'ROUTER_INVALID_KIND' | 'ROUTER_UNKNOWN_SERVICE' | 'ROUTER_DISPOSED';
2
+ export type RouterErrorCode = 'ROUTER_REGISTRATION_CLOSED' | 'ROUTER_KIND_COLLISION' | 'ROUTER_INVALID_KIND' | 'ROUTER_INVALID_DECLARATION' | 'ROUTER_UNKNOWN_SERVICE' | 'ROUTER_DISPOSED';
3
3
  /** Base class for every Router domain failure. */
4
4
  export declare abstract class RouterError extends Error {
5
5
  /** Stable, machine-readable error code. */
@@ -16,6 +16,17 @@ export declare class RouterRegistrationClosedError extends RouterError {
16
16
  */
17
17
  constructor(kind: string);
18
18
  }
19
+ /** Raised when a kind's operations or permissions are missing or invalid. Refuses boot. */
20
+ export declare class RouterInvalidDeclarationError extends RouterError {
21
+ readonly code: "ROUTER_INVALID_DECLARATION";
22
+ /** Kind whose declaration was refused. */
23
+ readonly kind: string;
24
+ /**
25
+ * @param kind - Kind whose declaration was refused.
26
+ * @param reason - What is wrong with it.
27
+ */
28
+ constructor(kind: string, reason: string);
29
+ }
19
30
  /** Raised when two services claim the same kind. */
20
31
  export declare class RouterKindCollisionError extends RouterError {
21
32
  readonly code: "ROUTER_KIND_COLLISION";
@@ -19,6 +19,21 @@ export class RouterRegistrationClosedError extends RouterError {
19
19
  this.kind = kind;
20
20
  }
21
21
  }
22
+ /** Raised when a kind's operations or permissions are missing or invalid. Refuses boot. */
23
+ export class RouterInvalidDeclarationError extends RouterError {
24
+ code = 'ROUTER_INVALID_DECLARATION';
25
+ /** Kind whose declaration was refused. */
26
+ kind;
27
+ /**
28
+ * @param kind - Kind whose declaration was refused.
29
+ * @param reason - What is wrong with it.
30
+ */
31
+ constructor(kind, reason) {
32
+ super(`Kind "${kind}" declaration refused: ${reason}`);
33
+ this.name = 'RouterInvalidDeclarationError';
34
+ this.kind = kind;
35
+ }
36
+ }
22
37
  /** Raised when two services claim the same kind. */
23
38
  export class RouterKindCollisionError extends RouterError {
24
39
  code = 'ROUTER_KIND_COLLISION';
@@ -3,6 +3,6 @@ export { isValidRouterKind } from './kind.js';
3
3
  export type { IRouterService } from './IRouterService.js';
4
4
  export type { IRouterRegistrant } from './registrant.js';
5
5
  export { isRouterRegistrant } from './registrant.js';
6
- export type { BrudDispatchContext, BrudRouteOptions, BrudRouteRegistration, BrudRouteResult, RouteStatus, RoutedOperationOutcome, RoutedOperationStatus, } from './types.js';
6
+ export type { BrudDispatchContext, BrudKindOperation, BrudPublicKindOperation, BrudRouteOptions, BrudRouteRegistration, BrudRouteResult, RouteStatus, RoutedOperationOutcome, RoutedOperationStatus, } from './types.js';
7
7
  export type { RouterErrorCode } from './errors.js';
8
- export { RouterDisposedError, RouterError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, RouterUnknownServiceError, } from './errors.js';
8
+ export { RouterDisposedError, RouterError, RouterInvalidDeclarationError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, RouterUnknownServiceError, } from './errors.js';
@@ -1,4 +1,4 @@
1
1
  export { ROUTER_CALLER_ID } from './caller.js';
2
2
  export { isValidRouterKind } from './kind.js';
3
3
  export { isRouterRegistrant } from './registrant.js';
4
- export { RouterDisposedError, RouterError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, RouterUnknownServiceError, } from './errors.js';
4
+ export { RouterDisposedError, RouterError, RouterInvalidDeclarationError, RouterInvalidKindError, RouterKindCollisionError, RouterRegistrationClosedError, RouterUnknownServiceError, } from './errors.js';
File without changes
File without changes
File without changes
File without changes
@@ -2,7 +2,7 @@ import type { BrudOperationKind } from '../../../src/contracts/brudOperation.js'
2
2
  import type { OperationResult } from '../../../src/contracts/handler.js';
3
3
  import type { BrudOperation, BrudParseFailure } from '../../Parser/contracts/index.js';
4
4
  /** Terminal status of one routed operation. */
5
- export type RoutedOperationStatus = 'success' | 'failed' | 'skipped' | 'aborted' | 'kind_not_registered';
5
+ export type RoutedOperationStatus = 'success' | 'failed' | 'skipped' | 'aborted' | 'kind_not_registered' | 'operation_not_declared' | 'permission_denied';
6
6
  /**
7
7
  * The real caller of a routed operation, captured by the Router from the
8
8
  * kernel call chain (delegation by the owner). Never supplied by the caller.
@@ -11,7 +11,7 @@ export interface BrudDispatchCaller {
11
11
  readonly identity: string | null;
12
12
  readonly callerClass: string;
13
13
  readonly official: boolean;
14
- readonly capabilities: readonly string[];
14
+ readonly capabilities: ReadonlySet<string>;
15
15
  readonly origin: string;
16
16
  }
17
17
  /** Context handed to a kind owner's dispatch exposure for one operation. */
@@ -72,17 +72,37 @@ export interface BrudRouteRegistration {
72
72
  readonly version?: number;
73
73
  /** Public description declared with the kind. */
74
74
  readonly description?: string;
75
- /** Public operations declared with the kind. */
76
- readonly operations?: Readonly<Record<string, {
77
- readonly description?: string;
78
- readonly input?: Readonly<Record<string, unknown>>;
79
- }>>;
75
+ /**
76
+ * Every operation the kind serves. Required: an operation not listed here is
77
+ * refused before the owner is reached.
78
+ */
79
+ readonly operations: Readonly<Record<string, BrudKindOperation>> | 'open';
80
+ /**
81
+ * Default permission for operations that declare none (a Layer 1 policy
82
+ * object). Required when `operations` is `'open'`: the owner defines the
83
+ * names, and this permission is enforced on every call.
84
+ */
85
+ readonly permission?: Readonly<Record<string, unknown>>;
86
+ }
87
+ /** One declared operation of a kind. */
88
+ export interface BrudKindOperation {
89
+ readonly description?: string;
90
+ readonly input?: Readonly<Record<string, unknown>>;
91
+ /** Who may call it (a Layer 1 policy object). Falls back to the kind's. */
92
+ readonly permission?: Readonly<Record<string, unknown>>;
93
+ }
94
+ /** One operation as remote clients see it. The permission is not public. */
95
+ export interface BrudPublicKindOperation {
96
+ readonly description?: string;
97
+ readonly input?: Readonly<Record<string, unknown>>;
80
98
  }
81
99
  /** One kind as remote clients see it: the public vocabulary of Brud syntax. */
82
100
  export interface BrudKindInfo {
83
101
  readonly kind: BrudOperationKind;
84
102
  readonly description?: string;
85
- readonly operations?: BrudRouteRegistration['operations'];
103
+ readonly operations?: Readonly<Record<string, BrudPublicKindOperation>>;
104
+ /** True when the owner defines the operation names itself, so none are listed. */
105
+ readonly open?: true;
86
106
  }
87
107
  /** The surface a kind owner's dispatch exposure must provide. */
88
108
  export interface BrudKindDispatcher {
File without changes
@@ -75,7 +75,7 @@ export function createRouterDescriptor(options) {
75
75
  identity: caller.identity,
76
76
  callerClass: caller.callerClass,
77
77
  official: caller.official,
78
- capabilities: Object.freeze([...caller.capabilities].sort()),
78
+ capabilities: caller.capabilities,
79
79
  origin: caller.origin,
80
80
  });
81
81
  return Object.freeze({
File without changes
File without changes
File without changes
File without changes
@@ -18,11 +18,15 @@ export interface RouterDependencies {
18
18
  * guard for alternate compositions.
19
19
  *
20
20
  * Dispatch resolves every target through the access broker with the token the
21
- * owning service supplied, so access policies still apply and a plugin can
22
- * never be a routing target.
21
+ * owning service supplied, so access policies still apply and only the
22
+ * owning service can be a routing target.
23
23
  */
24
24
  export declare class RouterService implements IRouterService, IServiceLifecycle {
25
25
  private readonly registrations;
26
+ /** The parsed permission of every declared operation, by kind then operation. Frozen at registration. */
27
+ private readonly permissions;
28
+ /** The one permission of every kind whose owner defines its operation names. */
29
+ private readonly openKinds;
26
30
  private authority;
27
31
  private readonly dependencies;
28
32
  private parser;
@@ -54,9 +58,16 @@ export declare class RouterService implements IRouterService, IServiceLifecycle
54
58
  readonly exposure: string;
55
59
  readonly version?: number | string;
56
60
  readonly description?: string;
57
- readonly operations?: BrudRouteRegistration['operations'];
61
+ readonly operations: BrudRouteRegistration['operations'];
62
+ readonly permission?: BrudRouteRegistration['permission'];
58
63
  }): void;
59
64
  register(registration: BrudRouteRegistration, owner?: string): void;
65
+ /**
66
+ * Builds the operation registry for one kind: every operation must be
67
+ * declared and carry a valid permission, its own or the kind's. Refuses the
68
+ * declaration, and so the boot, otherwise.
69
+ */
70
+ private compilePermissions;
60
71
  closeRegistration(): void;
61
72
  isRegistrationOpen(): boolean;
62
73
  registeredKinds(): readonly string[];
@@ -68,6 +79,14 @@ export declare class RouterService implements IRouterService, IServiceLifecycle
68
79
  kinds(): readonly BrudKindInfo[];
69
80
  route(rawInput: string, options?: BrudRouteOptions, caller?: BrudDispatchCaller): Promise<BrudRouteResult>;
70
81
  dispatch(operations: readonly BrudOperation[], options?: BrudRouteOptions, caller?: BrudDispatchCaller): Promise<BrudRouteResult>;
82
+ /**
83
+ * The operation registry check, run before the owner is resolved: the
84
+ * operation must be declared for its kind, and the caller must hold the
85
+ * operation's permission. The reason a permission is denied goes to the
86
+ * observation stream, never to the caller.
87
+ */
88
+ private refuseBeforeOwner;
89
+ private observeRefusal;
71
90
  private resolveParser;
72
91
  private buildDispatchContext;
73
92
  private failureResult;