@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.
- package/LICENSE +201 -0
- package/README.md +63 -2
- package/dist/index.d.ts +15 -0
- package/dist/index.js +13 -0
- package/dist/serviceModules/events.d.ts +1 -0
- package/dist/serviceModules/events.js +1 -0
- package/dist/serviceModules/exposedApiRegistry.d.ts +1 -0
- package/dist/serviceModules/exposedApiRegistry.js +1 -0
- package/dist/serviceModules/identityRegistry.d.ts +1 -0
- package/dist/serviceModules/identityRegistry.js +1 -0
- package/dist/serviceModules/interception.d.ts +1 -0
- package/dist/serviceModules/interception.js +1 -0
- package/dist/serviceModules/parser.d.ts +1 -0
- package/dist/serviceModules/parser.js +1 -0
- package/dist/serviceModules/router.d.ts +1 -0
- package/dist/serviceModules/router.js +1 -0
- package/dist/serviceModules/wasmCage.d.ts +1 -0
- package/dist/serviceModules/wasmCage.js +1 -0
- package/dist/services/Events/contracts/IEventsService.d.ts +64 -0
- package/dist/services/Events/contracts/IEventsService.js +1 -0
- package/dist/services/Events/contracts/errors.d.ts +31 -0
- package/dist/services/Events/contracts/errors.js +40 -0
- package/dist/services/Events/contracts/index.d.ts +3 -0
- package/dist/services/Events/contracts/index.js +3 -0
- package/dist/services/Events/contracts/tokens.d.ts +2 -0
- package/dist/services/Events/contracts/tokens.js +2 -0
- package/dist/services/Events/descriptor/EventsDescriptor.d.ts +9 -0
- package/dist/services/Events/descriptor/EventsDescriptor.js +56 -0
- package/dist/services/Events/descriptor/tokens.d.ts +1 -0
- package/dist/services/Events/descriptor/tokens.js +1 -0
- package/dist/services/Events/index.d.ts +4 -0
- package/dist/services/Events/index.js +4 -0
- package/dist/services/Events/orchestrator/EventsService.d.ts +51 -0
- package/dist/services/Events/orchestrator/EventsService.js +339 -0
- package/dist/services/Events/orchestrator/index.d.ts +2 -0
- package/dist/services/Events/orchestrator/index.js +2 -0
- package/dist/services/Events/orchestrator/limits.d.ts +22 -0
- package/dist/services/Events/orchestrator/limits.js +33 -0
- package/dist/services/Events/serviceModule.d.ts +2 -0
- package/dist/services/Events/serviceModule.js +5 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.d.ts +56 -0
- package/dist/services/ExposedApiRegistry/contracts/IExposedApiRegistry.js +1 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.d.ts +132 -0
- package/dist/services/ExposedApiRegistry/contracts/errors.js +195 -0
- package/dist/services/ExposedApiRegistry/contracts/index.d.ts +9 -0
- package/dist/services/ExposedApiRegistry/contracts/index.js +4 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.d.ts +90 -0
- package/dist/services/ExposedApiRegistry/contracts/policy.js +169 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.d.ts +37 -0
- package/dist/services/ExposedApiRegistry/contracts/registrant.js +36 -0
- package/dist/services/ExposedApiRegistry/contracts/types.d.ts +133 -0
- package/dist/services/ExposedApiRegistry/contracts/types.js +73 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.d.ts +44 -0
- package/dist/services/ExposedApiRegistry/descriptor/ExposedApiRegistryDescriptor.js +58 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/ExposedApiRegistry/descriptor/tokens.js +8 -0
- package/dist/services/ExposedApiRegistry/index.d.ts +6 -0
- package/dist/services/ExposedApiRegistry/index.js +5 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.d.ts +68 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +452 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.d.ts +2 -0
- package/dist/services/ExposedApiRegistry/orchestrator/index.js +1 -0
- package/dist/services/ExposedApiRegistry/serviceModule.d.ts +10 -0
- package/dist/services/ExposedApiRegistry/serviceModule.js +20 -0
- package/dist/services/ExposedApiRegistry/storage/protection.d.ts +21 -0
- package/dist/services/ExposedApiRegistry/storage/protection.js +35 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.d.ts +45 -0
- package/dist/services/ExposedApiRegistry/storage/scopeRecord.js +178 -0
- package/dist/services/IdentityRegistry/contracts/errors.d.ts +88 -0
- package/dist/services/IdentityRegistry/contracts/errors.js +128 -0
- package/dist/services/IdentityRegistry/contracts/index.d.ts +5 -0
- package/dist/services/IdentityRegistry/contracts/index.js +3 -0
- package/dist/services/IdentityRegistry/contracts/types.d.ts +77 -0
- package/dist/services/IdentityRegistry/contracts/types.js +18 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.d.ts +36 -0
- package/dist/services/IdentityRegistry/descriptor/descriptor.js +44 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.d.ts +8 -0
- package/dist/services/IdentityRegistry/descriptor/tokens.js +8 -0
- package/dist/services/IdentityRegistry/index.d.ts +11 -0
- package/dist/services/IdentityRegistry/index.js +6 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.d.ts +47 -0
- package/dist/services/IdentityRegistry/orchestrator/IdentityRegistryService.js +240 -0
- package/dist/services/IdentityRegistry/serviceModule.d.ts +10 -0
- package/dist/services/IdentityRegistry/serviceModule.js +24 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.d.ts +55 -0
- package/dist/services/IdentityRegistry/storage/registryDocument.js +235 -0
- package/dist/services/Interception/contracts/IInterceptionService.d.ts +155 -0
- package/dist/services/Interception/contracts/IInterceptionService.js +12 -0
- package/dist/services/Interception/contracts/errors.d.ts +26 -0
- package/dist/services/Interception/contracts/errors.js +35 -0
- package/dist/services/Interception/contracts/index.d.ts +3 -0
- package/dist/services/Interception/contracts/index.js +3 -0
- package/dist/services/Interception/contracts/tokens.d.ts +2 -0
- package/dist/services/Interception/contracts/tokens.js +2 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.d.ts +9 -0
- package/dist/services/Interception/descriptor/InterceptionDescriptor.js +50 -0
- package/dist/services/Interception/descriptor/tokens.d.ts +1 -0
- package/dist/services/Interception/descriptor/tokens.js +1 -0
- package/dist/services/Interception/index.d.ts +4 -0
- package/dist/services/Interception/index.js +4 -0
- package/dist/services/Interception/orchestrator/InterceptionService.d.ts +40 -0
- package/dist/services/Interception/orchestrator/InterceptionService.js +343 -0
- package/dist/services/Interception/orchestrator/index.d.ts +1 -0
- package/dist/services/Interception/orchestrator/index.js +1 -0
- package/dist/services/Interception/serviceModule.d.ts +2 -0
- package/dist/services/Interception/serviceModule.js +5 -0
- package/dist/services/Parser/contracts/IParserService.d.ts +21 -0
- package/dist/services/Parser/contracts/IParserService.js +1 -0
- package/dist/services/Parser/contracts/errors.d.ts +25 -0
- package/dist/services/Parser/contracts/errors.js +33 -0
- package/dist/services/Parser/contracts/index.d.ts +4 -0
- package/dist/services/Parser/contracts/index.js +1 -0
- package/dist/services/Parser/contracts/types.d.ts +42 -0
- package/dist/services/Parser/contracts/types.js +1 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.d.ts +23 -0
- package/dist/services/Parser/descriptor/ParserDescriptor.js +50 -0
- package/dist/services/Parser/descriptor/tokens.d.ts +8 -0
- package/dist/services/Parser/descriptor/tokens.js +8 -0
- package/dist/services/Parser/index.d.ts +8 -0
- package/dist/services/Parser/index.js +8 -0
- package/dist/services/Parser/orchestrator/ParserService.d.ts +20 -0
- package/dist/services/Parser/orchestrator/ParserService.js +105 -0
- package/dist/services/Parser/orchestrator/index.d.ts +1 -0
- package/dist/services/Parser/orchestrator/index.js +1 -0
- package/dist/services/Parser/parser/indexSynthesis.d.ts +11 -0
- package/dist/services/Parser/parser/indexSynthesis.js +13 -0
- package/dist/services/Parser/parser/parameters.d.ts +14 -0
- package/dist/services/Parser/parser/parameters.js +89 -0
- package/dist/services/Parser/parser/scanner.d.ts +48 -0
- package/dist/services/Parser/parser/scanner.js +156 -0
- package/dist/services/Parser/parser/syntax.d.ts +30 -0
- package/dist/services/Parser/parser/syntax.js +34 -0
- package/dist/services/Parser/serviceModule.d.ts +2 -0
- package/dist/services/Parser/serviceModule.js +5 -0
- package/dist/services/Router/bootOptions.d.ts +2 -0
- package/dist/services/Router/bootOptions.js +2 -0
- package/dist/services/Router/contracts/IRouterService.d.ts +43 -0
- package/dist/services/Router/contracts/IRouterService.js +1 -0
- package/dist/services/Router/contracts/caller.d.ts +6 -0
- package/dist/services/Router/contracts/caller.js +6 -0
- package/dist/services/Router/contracts/errors.d.ts +67 -0
- package/dist/services/Router/contracts/errors.js +90 -0
- package/dist/services/Router/contracts/index.d.ts +8 -0
- package/dist/services/Router/contracts/index.js +4 -0
- package/dist/services/Router/contracts/kind.d.ts +7 -0
- package/dist/services/Router/contracts/kind.js +10 -0
- package/dist/services/Router/contracts/registrant.d.ts +23 -0
- package/dist/services/Router/contracts/registrant.js +13 -0
- package/dist/services/Router/contracts/types.d.ts +110 -0
- package/dist/services/Router/contracts/types.js +1 -0
- package/dist/services/Router/descriptor/RouterDescriptor.d.ts +32 -0
- package/dist/services/Router/descriptor/RouterDescriptor.js +92 -0
- package/dist/services/Router/descriptor/tokens.d.ts +9 -0
- package/dist/services/Router/descriptor/tokens.js +9 -0
- package/dist/services/Router/index.d.ts +4 -0
- package/dist/services/Router/index.js +4 -0
- package/dist/services/Router/orchestrator/RouterService.d.ts +93 -0
- package/dist/services/Router/orchestrator/RouterService.js +457 -0
- package/dist/services/Router/orchestrator/index.d.ts +2 -0
- package/dist/services/Router/orchestrator/index.js +1 -0
- package/dist/services/Router/serviceModule.d.ts +4 -0
- package/dist/services/Router/serviceModule.js +22 -0
- package/dist/services/WasmCage/index.d.ts +7 -0
- package/dist/services/WasmCage/index.js +4 -0
- package/dist/services/WasmCage/scripts/prepin.d.ts +1 -0
- package/dist/services/WasmCage/scripts/prepin.js +38 -0
- package/dist/services/WasmCage/serviceModule.d.ts +12 -0
- package/dist/services/WasmCage/serviceModule.js +18 -0
- package/dist/services/WasmCage/src/caged.d.ts +121 -0
- package/dist/services/WasmCage/src/caged.js +460 -0
- package/dist/services/WasmCage/src/descriptor.d.ts +47 -0
- package/dist/services/WasmCage/src/descriptor.js +56 -0
- package/dist/services/WasmCage/src/native.d.ts +29 -0
- package/dist/services/WasmCage/src/native.js +66 -0
- package/dist/services/WasmCage/src/nativeDigests.d.ts +9 -0
- package/dist/services/WasmCage/src/nativeDigests.js +15 -0
- package/dist/services/WasmCage/src/package.d.ts +36 -0
- package/dist/services/WasmCage/src/package.js +122 -0
- package/dist/services/shared/canonicalJson.d.ts +29 -0
- package/dist/services/shared/canonicalJson.js +93 -0
- package/dist/services/shared/documentStore.d.ts +16 -0
- package/dist/services/shared/documentStore.js +98 -0
- package/dist/src/bootstrap/bootKernelInternal.d.ts +19 -0
- package/dist/src/bootstrap/bootKernelInternal.js +633 -0
- package/dist/src/bootstrap/bootTypes.d.ts +113 -0
- package/dist/src/bootstrap/bootTypes.js +1 -0
- package/dist/src/bootstrap/config/index.d.ts +3 -0
- package/dist/src/bootstrap/config/index.js +2 -0
- package/dist/src/bootstrap/config/integrity.d.ts +45 -0
- package/dist/src/bootstrap/config/integrity.js +92 -0
- package/dist/src/bootstrap/config/parse.d.ts +15 -0
- package/dist/src/bootstrap/config/parse.js +81 -0
- package/dist/src/bootstrap/config/pathWriteGuard.d.ts +20 -0
- package/dist/src/bootstrap/config/pathWriteGuard.js +349 -0
- package/dist/src/bootstrap/config/types.d.ts +41 -0
- package/dist/src/bootstrap/config/types.js +15 -0
- package/dist/src/bootstrap/hardcore.d.ts +212 -0
- package/dist/src/bootstrap/hardcore.js +312 -0
- package/dist/src/bootstrap/hardcoreServices.d.ts +10 -0
- package/dist/src/bootstrap/hardcoreServices.js +258 -0
- package/dist/src/bootstrap/index.d.ts +13 -0
- package/dist/src/bootstrap/index.js +7 -0
- package/dist/src/bootstrap/loaded.d.ts +30 -0
- package/dist/src/bootstrap/loaded.js +45 -0
- package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
- package/dist/src/bootstrap/packageRequirements.js +52 -0
- package/dist/src/bootstrap/reload.d.ts +44 -0
- package/dist/src/bootstrap/reload.js +45 -0
- package/dist/src/bootstrap/seal.d.ts +32 -0
- package/dist/src/bootstrap/seal.js +101 -0
- package/dist/src/contracts/accessBroker.d.ts +53 -0
- package/dist/src/contracts/accessBroker.js +1 -0
- package/dist/src/contracts/brudOperation.d.ts +20 -0
- package/dist/src/contracts/brudOperation.js +20 -0
- package/dist/src/contracts/callChain.d.ts +161 -0
- package/dist/src/contracts/callChain.js +19 -0
- package/dist/src/contracts/capability.d.ts +26 -0
- package/dist/src/contracts/capability.js +26 -0
- package/dist/src/contracts/capabilitySet.d.ts +23 -0
- package/dist/src/contracts/capabilitySet.js +72 -0
- package/dist/src/contracts/container.d.ts +17 -0
- package/dist/src/contracts/container.js +8 -0
- package/dist/src/contracts/context.d.ts +19 -0
- package/dist/src/contracts/context.js +1 -0
- package/dist/src/contracts/contextContract.d.ts +132 -0
- package/dist/src/contracts/contextContract.js +274 -0
- package/dist/src/contracts/dispatchView.d.ts +21 -0
- package/dist/src/contracts/dispatchView.js +1 -0
- package/dist/src/contracts/handler.d.ts +21 -0
- package/dist/src/contracts/handler.js +1 -0
- package/dist/src/contracts/index.d.ts +26 -0
- package/dist/src/contracts/index.js +9 -0
- package/dist/src/contracts/kernel.d.ts +60 -0
- package/dist/src/contracts/kernel.js +1 -0
- package/dist/src/contracts/lifecycle.d.ts +59 -0
- package/dist/src/contracts/lifecycle.js +1 -0
- package/dist/src/contracts/manifest.d.ts +180 -0
- package/dist/src/contracts/manifest.js +334 -0
- package/dist/src/contracts/pipeline.d.ts +8 -0
- package/dist/src/contracts/pipeline.js +1 -0
- package/dist/src/contracts/policy.d.ts +75 -0
- package/dist/src/contracts/policy.js +77 -0
- package/dist/src/contracts/registry.d.ts +7 -0
- package/dist/src/contracts/registry.js +1 -0
- package/dist/src/contracts/serviceDescriptor.d.ts +67 -0
- package/dist/src/contracts/serviceDescriptor.js +1 -0
- package/dist/src/contracts/serviceToken.d.ts +36 -0
- package/dist/src/contracts/serviceToken.js +16 -0
- package/dist/src/engine/BrudKernel.d.ts +120 -0
- package/dist/src/engine/BrudKernel.js +395 -0
- package/dist/src/engine/ExecutionPipeline.d.ts +13 -0
- package/dist/src/engine/ExecutionPipeline.js +62 -0
- package/dist/src/engine/KernelAccessBroker.d.ts +47 -0
- package/dist/src/engine/KernelAccessBroker.js +107 -0
- package/dist/src/engine/KernelRegistry.d.ts +14 -0
- package/dist/src/engine/KernelRegistry.js +33 -0
- package/dist/src/engine/OperationRegistry.d.ts +9 -0
- package/dist/src/engine/OperationRegistry.js +18 -0
- package/dist/src/engine/ServiceContainer.d.ts +13 -0
- package/dist/src/engine/ServiceContainer.js +53 -0
- package/dist/src/engine/callChain.d.ts +68 -0
- package/dist/src/engine/callChain.js +175 -0
- package/dist/src/engine/dag.d.ts +2 -0
- package/dist/src/engine/dag.js +34 -0
- package/dist/src/engine/errors.d.ts +26 -0
- package/dist/src/engine/errors.js +52 -0
- package/dist/src/engine/index.d.ts +11 -0
- package/dist/src/engine/index.js +8 -0
- package/dist/src/engine/state.d.ts +1 -0
- package/dist/src/engine/state.js +1 -0
- package/dist/src/validation/jsonSchema/compile.d.ts +8 -0
- package/dist/src/validation/jsonSchema/compile.js +386 -0
- package/dist/src/validation/jsonSchema/index.d.ts +3 -0
- package/dist/src/validation/jsonSchema/index.js +2 -0
- package/dist/src/validation/jsonSchema/jsonValue.d.ts +29 -0
- package/dist/src/validation/jsonSchema/jsonValue.js +190 -0
- package/dist/src/validation/jsonSchema/pattern.d.ts +28 -0
- package/dist/src/validation/jsonSchema/pattern.js +155 -0
- package/dist/src/validation/jsonSchema/types.d.ts +71 -0
- package/dist/src/validation/jsonSchema/types.js +15 -0
- package/package.json +59 -4
- package/services/WasmCage/native/brud-wasm-cage.darwin-arm64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.darwin-x64.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-arm64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.linux-x64-gnu.node +0 -0
- package/services/WasmCage/native/brud-wasm-cage.win32-x64-msvc.node +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { failingServiceOf } from '../engine/BrudKernel.js';
|
|
2
|
+
/**
|
|
3
|
+
* One or more loaded participants cannot be part of this boot.
|
|
4
|
+
*
|
|
5
|
+
* The boot driver catches it, leaves them out, and tries again. It is thrown
|
|
6
|
+
* only for loaded participants: a failure in a hardcore or composed
|
|
7
|
+
* participant is never wrapped in it.
|
|
8
|
+
*/
|
|
9
|
+
export class LoadedParticipantFailure extends Error {
|
|
10
|
+
participants;
|
|
11
|
+
constructor(participants) {
|
|
12
|
+
super(`Loaded participant(s) cannot start: ${participants.map((entry) => `${entry.path} (${entry.reason})`).join('; ')}`);
|
|
13
|
+
this.name = 'LoadedParticipantFailure';
|
|
14
|
+
this.participants = participants;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Describes a failure as an abandoned loaded participant. */
|
|
18
|
+
export function abandonment(path, error, participant) {
|
|
19
|
+
const code = error !== null && typeof error === 'object' ? error.code : undefined;
|
|
20
|
+
return {
|
|
21
|
+
path,
|
|
22
|
+
...(participant === undefined ? {} : { participant }),
|
|
23
|
+
...(typeof code === 'string' ? { code } : {}),
|
|
24
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The service token an error blames: the participant the error itself names
|
|
29
|
+
* (a check one participant's declaration failed), else the service whose
|
|
30
|
+
* lifecycle code threw it. Looks through `cause`.
|
|
31
|
+
*/
|
|
32
|
+
export function culpritOf(error) {
|
|
33
|
+
for (let current = error, depth = 0; current !== null && typeof current === 'object' && depth < 5; depth += 1) {
|
|
34
|
+
const named = current.participant;
|
|
35
|
+
if (typeof named === 'string') {
|
|
36
|
+
return named;
|
|
37
|
+
}
|
|
38
|
+
const failing = failingServiceOf(current);
|
|
39
|
+
if (failing !== undefined) {
|
|
40
|
+
return failing;
|
|
41
|
+
}
|
|
42
|
+
current = current.cause;
|
|
43
|
+
}
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The powers a participant package may say it needs. A fixed vocabulary, so the
|
|
3
|
+
* refusal message is never free text from the package.
|
|
4
|
+
*/
|
|
5
|
+
export declare const PACKAGE_POWERS: readonly ["environment", "filesystem", "network", "process"];
|
|
6
|
+
/** What a participant package requires of the composition that loads it. */
|
|
7
|
+
export interface PackageRequirements {
|
|
8
|
+
/** The package refuses to load unless the composition declares its entry official. */
|
|
9
|
+
readonly official: boolean;
|
|
10
|
+
/** The powers it will use, shown to the owner next to the refusal. */
|
|
11
|
+
readonly powers: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
/** A `requires` section that is malformed. */
|
|
14
|
+
export declare class PackageRequirementsError extends Error {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reads the optional `requires` section of a participant package's data file.
|
|
19
|
+
* A requirement can only refuse a load; it never grants officialness, which
|
|
20
|
+
* stays the composition owner's decision.
|
|
21
|
+
*
|
|
22
|
+
* @param manifestPath - Absolute path of `brud.participant.json`.
|
|
23
|
+
* @returns The requirements; none when the section is absent.
|
|
24
|
+
* @throws {PackageRequirementsError} When the file is unreadable or the section is malformed.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readPackageRequirements(manifestPath: string): PackageRequirements;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
/**
|
|
3
|
+
* The powers a participant package may say it needs. A fixed vocabulary, so the
|
|
4
|
+
* refusal message is never free text from the package.
|
|
5
|
+
*/
|
|
6
|
+
export const PACKAGE_POWERS = ['environment', 'filesystem', 'network', 'process'];
|
|
7
|
+
/** A `requires` section that is malformed. */
|
|
8
|
+
export class PackageRequirementsError extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'PackageRequirementsError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const NONE = Object.freeze({ official: false, powers: Object.freeze([]) });
|
|
15
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
16
|
+
/**
|
|
17
|
+
* Reads the optional `requires` section of a participant package's data file.
|
|
18
|
+
* A requirement can only refuse a load; it never grants officialness, which
|
|
19
|
+
* stays the composition owner's decision.
|
|
20
|
+
*
|
|
21
|
+
* @param manifestPath - Absolute path of `brud.participant.json`.
|
|
22
|
+
* @returns The requirements; none when the section is absent.
|
|
23
|
+
* @throws {PackageRequirementsError} When the file is unreadable or the section is malformed.
|
|
24
|
+
*/
|
|
25
|
+
export function readPackageRequirements(manifestPath) {
|
|
26
|
+
let pkg;
|
|
27
|
+
try {
|
|
28
|
+
pkg = JSON.parse(readFileSync(manifestPath, 'utf8'));
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new PackageRequirementsError(`unreadable (${error instanceof Error ? error.message : String(error)})`);
|
|
32
|
+
}
|
|
33
|
+
const requires = isRecord(pkg) ? pkg.requires : undefined;
|
|
34
|
+
if (requires === undefined) {
|
|
35
|
+
return NONE;
|
|
36
|
+
}
|
|
37
|
+
if (!isRecord(requires)) {
|
|
38
|
+
throw new PackageRequirementsError('requires must be an object');
|
|
39
|
+
}
|
|
40
|
+
const unknownKeys = Object.keys(requires).filter((key) => key !== 'official' && key !== 'powers');
|
|
41
|
+
if (unknownKeys.length > 0) {
|
|
42
|
+
throw new PackageRequirementsError(`unknown requires key(s) ${unknownKeys.join(', ')}`);
|
|
43
|
+
}
|
|
44
|
+
if (requires.official !== true) {
|
|
45
|
+
throw new PackageRequirementsError('requires.official must be true when requires is present');
|
|
46
|
+
}
|
|
47
|
+
const powers = requires.powers ?? [];
|
|
48
|
+
if (!Array.isArray(powers) || powers.some((power) => !PACKAGE_POWERS.includes(power))) {
|
|
49
|
+
throw new PackageRequirementsError(`requires.powers must list only: ${PACKAGE_POWERS.join(', ')}`);
|
|
50
|
+
}
|
|
51
|
+
return Object.freeze({ official: true, powers: Object.freeze([...new Set(powers)].sort()) });
|
|
52
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { BrudKernel } from '../engine/BrudKernel.js';
|
|
2
|
+
import { type BrudConfig } from './config/types.js';
|
|
3
|
+
import type { AbandonedParticipant } from './loaded.js';
|
|
4
|
+
/** Options for {@link ReloadableKernel.reload}. */
|
|
5
|
+
export interface ReloadOptions {
|
|
6
|
+
/** Config to load. Defaults to the path the running kernel booted from. */
|
|
7
|
+
readonly configPath?: string;
|
|
8
|
+
}
|
|
9
|
+
/** A kernel the host can reload. Only the host holds it; no participant receives it. */
|
|
10
|
+
export type ReloadableKernel = BrudKernel & {
|
|
11
|
+
/** The loaded participants this kernel left out when it booted, each with the reason. Empty when none. */
|
|
12
|
+
readonly abandoned: readonly AbandonedParticipant[];
|
|
13
|
+
/**
|
|
14
|
+
* Replaces the running composition with the one in a config file: it
|
|
15
|
+
* checks the new config against the frozen part, composes it, shuts this
|
|
16
|
+
* kernel down, and boots the new one with the same options.
|
|
17
|
+
*
|
|
18
|
+
* Everything outside the frozen part may change: which loaded participants
|
|
19
|
+
* exist, their packages and their options. The frozen part is every official
|
|
20
|
+
* entry in order, and the exposure owners; changing it needs a rebuild. A
|
|
21
|
+
* loaded participant that cannot start is left out and named in
|
|
22
|
+
* `abandoned` of the returned kernel; it never stops the reload.
|
|
23
|
+
*
|
|
24
|
+
* @returns The new running kernel. This one is disposed.
|
|
25
|
+
* @throws {BrudConfigError} `CONFIG_RELOAD_FROZEN` when the frozen part
|
|
26
|
+
* differs, or any config error the new composition raises. Nothing has
|
|
27
|
+
* been stopped in either case.
|
|
28
|
+
* @throws {KernelReloadError} When the new kernel failed to boot for a reason
|
|
29
|
+
* in the build, not in a loaded participant, after this one was stopped.
|
|
30
|
+
* @throws {LifecycleStateError} When this kernel is not running.
|
|
31
|
+
*/
|
|
32
|
+
reload(options?: ReloadOptions): Promise<ReloadableKernel>;
|
|
33
|
+
};
|
|
34
|
+
/** The new composition failed to boot after the running kernel was stopped. */
|
|
35
|
+
export declare class KernelReloadError extends Error {
|
|
36
|
+
readonly code: "KERNEL_RELOAD_FAILED";
|
|
37
|
+
constructor(configPath: string, cause: unknown);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Refuses a config whose frozen part differs from the booted one.
|
|
41
|
+
*
|
|
42
|
+
* @throws {BrudConfigError} `CONFIG_RELOAD_FROZEN`, naming every difference.
|
|
43
|
+
*/
|
|
44
|
+
export declare function refuseFrozenChange(booted: BrudConfig, next: BrudConfig, configPath: string, sealed?: ReadonlySet<string>): void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BrudConfigError } from './config/types.js';
|
|
2
|
+
/** The new composition failed to boot after the running kernel was stopped. */
|
|
3
|
+
export class KernelReloadError extends Error {
|
|
4
|
+
code = 'KERNEL_RELOAD_FAILED';
|
|
5
|
+
constructor(configPath, cause) {
|
|
6
|
+
super(`Reload failed: the previous kernel was stopped and the composition in "${configPath}" did not boot: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
7
|
+
this.name = 'KernelReloadError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** What a reload may not change: official entries in order, and exposure owners. */
|
|
11
|
+
function frozenPart(config, sealed) {
|
|
12
|
+
return {
|
|
13
|
+
official: config.services.filter((entry) => entry.official === true && (sealed === undefined || sealed.has(entry.path))).map((entry) => entry.path),
|
|
14
|
+
owners: Object.fromEntries(Object.entries(config.exposureOwners ?? {}).sort(([a], [b]) => a.localeCompare(b))),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Refuses a config whose frozen part differs from the booted one.
|
|
19
|
+
*
|
|
20
|
+
* @throws {BrudConfigError} `CONFIG_RELOAD_FROZEN`, naming every difference.
|
|
21
|
+
*/
|
|
22
|
+
export function refuseFrozenChange(booted, next, configPath, sealed) {
|
|
23
|
+
const before = frozenPart(booted, sealed);
|
|
24
|
+
const after = frozenPart(next, sealed);
|
|
25
|
+
const problems = [];
|
|
26
|
+
for (const path of before.official) {
|
|
27
|
+
if (!after.official.includes(path)) {
|
|
28
|
+
problems.push(`official participant "${path}" was removed or is no longer official`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const path of after.official) {
|
|
32
|
+
if (!before.official.includes(path)) {
|
|
33
|
+
problems.push(`"${path}" is declared official but was not official at boot`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (problems.length === 0 && before.official.join('\n') !== after.official.join('\n')) {
|
|
37
|
+
problems.push('the order of the official participants changed');
|
|
38
|
+
}
|
|
39
|
+
if (JSON.stringify(before.owners) !== JSON.stringify(after.owners)) {
|
|
40
|
+
problems.push('the exposure owners changed');
|
|
41
|
+
}
|
|
42
|
+
if (problems.length > 0) {
|
|
43
|
+
throw new BrudConfigError('CONFIG_RELOAD_FROZEN', `A reload cannot change what the build froze (${problems.join('; ')}). Rebuild to change official participants or exposure owners.`, configPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SealReference } from './bootTypes.js';
|
|
2
|
+
import { type BrudConfig } from './config/types.js';
|
|
3
|
+
/** A generated seal and its digest. */
|
|
4
|
+
export interface CreatedSeal {
|
|
5
|
+
/** The text to write to the seal file. */
|
|
6
|
+
readonly text: string;
|
|
7
|
+
/** SHA-256 hex digest of `text`: the value the built product passes at boot. */
|
|
8
|
+
readonly digest: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Generates the seal for the official participants a config declares.
|
|
12
|
+
*
|
|
13
|
+
* A builder runs this once per release, after the build is final.
|
|
14
|
+
*
|
|
15
|
+
* @param configPath - The composition's config.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSeal(configPath: string): CreatedSeal;
|
|
18
|
+
/** What a seal says about a config. */
|
|
19
|
+
export interface SealCheck {
|
|
20
|
+
/** Official entries the build did not seal. They are not part of the build and are left out. */
|
|
21
|
+
readonly unsealed: ReadonlySet<string>;
|
|
22
|
+
/** Paths the build sealed. */
|
|
23
|
+
readonly sealed: ReadonlySet<string>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks a config against the build seal.
|
|
27
|
+
*
|
|
28
|
+
* @throws {BrudConfigError} `SEAL_MISMATCH` when the seal file is not the one
|
|
29
|
+
* the built product holds the digest of; `SEAL_VIOLATION` when a sealed
|
|
30
|
+
* participant is missing, out of order, or its content changed.
|
|
31
|
+
*/
|
|
32
|
+
export declare function checkSeal(seal: SealReference, config: BrudConfig, configPath: string): SealCheck;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { dirname, join, parse as parsePath } from 'node:path';
|
|
5
|
+
import { resolveModuleId } from './bootKernelInternal.js';
|
|
6
|
+
import { computePackageContentHash, hashPackageFile } from './hardcore.js';
|
|
7
|
+
import { parseBrudConfig } from './config/parse.js';
|
|
8
|
+
import { BrudConfigError } from './config/types.js';
|
|
9
|
+
const digestOf = (text) => createHash('sha256').update(text, 'utf8').digest('hex');
|
|
10
|
+
/** Finds the file a bare package specifier names, looking through `node_modules` folders above the config. */
|
|
11
|
+
function resolveSpecifier(specifier, configPath) {
|
|
12
|
+
try {
|
|
13
|
+
return createRequire(configPath).resolve(specifier);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
for (let dir = dirname(configPath);; dir = dirname(dir)) {
|
|
17
|
+
const candidate = join(dir, 'node_modules', specifier);
|
|
18
|
+
if (existsSync(candidate) && parsePath(candidate).ext !== '') {
|
|
19
|
+
return candidate;
|
|
20
|
+
}
|
|
21
|
+
if (dirname(dir) === dir) {
|
|
22
|
+
throw new BrudConfigError('MODULE_RESOLVE', `Cannot seal "${specifier}": it does not resolve to a file. Declare the file path.`, configPath);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** The content hash a seal records for one participant. */
|
|
28
|
+
function sealHash(declared, configPath) {
|
|
29
|
+
const resolved = declared.startsWith('.') || declared.startsWith('/') || declared.startsWith('file:') || declared.startsWith('kernel:')
|
|
30
|
+
? resolveModuleId(declared, configPath)
|
|
31
|
+
: resolveSpecifier(declared, configPath);
|
|
32
|
+
if (!resolved.endsWith('.json')) {
|
|
33
|
+
return computePackageContentHash(resolved);
|
|
34
|
+
}
|
|
35
|
+
// A participant package: the package file, its module, and the native build it may ship.
|
|
36
|
+
const dir = dirname(resolved);
|
|
37
|
+
const manifest = JSON.parse(readFileSync(resolved, 'utf8'));
|
|
38
|
+
const parts = [hashPackageFile(resolved)];
|
|
39
|
+
if (typeof manifest.cage?.module === 'string') {
|
|
40
|
+
parts.push(hashPackageFile(join(dir, manifest.cage.module)));
|
|
41
|
+
}
|
|
42
|
+
if (typeof manifest.native === 'string') {
|
|
43
|
+
parts.push(computePackageContentHash(join(dir, manifest.native)));
|
|
44
|
+
}
|
|
45
|
+
return digestOf(parts.join('\n'));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generates the seal for the official participants a config declares.
|
|
49
|
+
*
|
|
50
|
+
* A builder runs this once per release, after the build is final.
|
|
51
|
+
*
|
|
52
|
+
* @param configPath - The composition's config.
|
|
53
|
+
*/
|
|
54
|
+
export function createSeal(configPath) {
|
|
55
|
+
const config = parseBrudConfig(readFileSync(configPath, 'utf8'), configPath);
|
|
56
|
+
const participants = config.services
|
|
57
|
+
.filter((entry) => entry.official === true)
|
|
58
|
+
.map((entry) => (entry.path.startsWith('kernel:') ? { path: entry.path } : { path: entry.path, sha256: sealHash(entry.path, configPath) }));
|
|
59
|
+
const text = `${JSON.stringify({ format: 1, participants }, null, 2)}\n`;
|
|
60
|
+
return { text, digest: digestOf(text) };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Checks a config against the build seal.
|
|
64
|
+
*
|
|
65
|
+
* @throws {BrudConfigError} `SEAL_MISMATCH` when the seal file is not the one
|
|
66
|
+
* the built product holds the digest of; `SEAL_VIOLATION` when a sealed
|
|
67
|
+
* participant is missing, out of order, or its content changed.
|
|
68
|
+
*/
|
|
69
|
+
export function checkSeal(seal, config, configPath) {
|
|
70
|
+
let text;
|
|
71
|
+
try {
|
|
72
|
+
text = readFileSync(seal.path, 'utf8');
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
throw new BrudConfigError('SEAL_MISMATCH', `Cannot read the build seal "${seal.path}": ${error instanceof Error ? error.message : String(error)}`, configPath);
|
|
76
|
+
}
|
|
77
|
+
if (digestOf(text) !== seal.digest) {
|
|
78
|
+
throw new BrudConfigError('SEAL_MISMATCH', `The build seal "${seal.path}" is not the one this build was sealed with. Rebuild to change what the build ships.`, configPath);
|
|
79
|
+
}
|
|
80
|
+
const document = JSON.parse(text);
|
|
81
|
+
const sealed = new Set(document.participants.map((entry) => entry.path));
|
|
82
|
+
const official = config.services.filter((entry) => entry.official === true && sealed.has(entry.path));
|
|
83
|
+
const problems = [];
|
|
84
|
+
if (official.map((entry) => entry.path).join('\n') !== document.participants.map((entry) => entry.path).join('\n')) {
|
|
85
|
+
problems.push('the sealed participants are missing, repeated or out of order in the config');
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
for (const entry of document.participants) {
|
|
89
|
+
if (entry.sha256 !== undefined && sealHash(entry.path, configPath) !== entry.sha256) {
|
|
90
|
+
problems.push(`"${entry.path}" no longer matches the content the build sealed`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (problems.length > 0) {
|
|
95
|
+
throw new BrudConfigError('SEAL_VIOLATION', `The composition does not match its build seal: ${problems.join('; ')}.`, configPath);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
sealed,
|
|
99
|
+
unsealed: new Set(config.services.filter((entry) => entry.official === true && !sealed.has(entry.path)).map((entry) => entry.path)),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ServiceContext, ServiceTier } from './lifecycle.js';
|
|
2
|
+
import type { ServiceToken } from './serviceToken.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read-only metadata describing a registered service.
|
|
5
|
+
*/
|
|
6
|
+
export interface ServiceInfo {
|
|
7
|
+
/** Stable identifier of the service. */
|
|
8
|
+
readonly id: string;
|
|
9
|
+
/** Short explanation of what the service provides. */
|
|
10
|
+
readonly description: string;
|
|
11
|
+
/** Privilege tier the service belongs to. */
|
|
12
|
+
readonly tier: ServiceTier;
|
|
13
|
+
/** Whether the service has completed initialization. */
|
|
14
|
+
readonly initialized: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Mediated entry point for resolving services across the microkernel boundary.
|
|
18
|
+
*
|
|
19
|
+
* Every resolution is subject to the target service's access policy and the
|
|
20
|
+
* caller's {@link ServiceContext}.
|
|
21
|
+
*/
|
|
22
|
+
export interface IKernelAccessBroker {
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a service for the given caller.
|
|
25
|
+
*
|
|
26
|
+
* @typeParam TService - The public interface carried by `token`.
|
|
27
|
+
* @param caller - Context identifying the requesting caller.
|
|
28
|
+
* @param token - Token identifying the requested service.
|
|
29
|
+
* @returns The caller-facing view of the service.
|
|
30
|
+
*/
|
|
31
|
+
requestAccess<TService>(caller: ServiceContext, token: ServiceToken<TService>): TService;
|
|
32
|
+
/**
|
|
33
|
+
* Reports whether a service is registered.
|
|
34
|
+
*
|
|
35
|
+
* @param token - Token identifying the service.
|
|
36
|
+
*/
|
|
37
|
+
hasService(token: ServiceToken<unknown>): boolean;
|
|
38
|
+
/** Lists metadata for every registered service. */
|
|
39
|
+
listServices(): readonly ServiceInfo[];
|
|
40
|
+
/**
|
|
41
|
+
* Suspends the lifecycle gate for a bounded boot-window operation.
|
|
42
|
+
*
|
|
43
|
+
* This is a general rule available to every participant on the same terms,
|
|
44
|
+
* not a service-specific exception. It removes only the "broker is idle"
|
|
45
|
+
* state check while the operation runs; every access policy, denial list,
|
|
46
|
+
* and allowlist still applies, so a suspended gate never widens authority.
|
|
47
|
+
* The kernel uses it around the boot pinner, where any module's
|
|
48
|
+
* `pinBootPolicies` hook may ingest its boot snapshot before `RUNNING`.
|
|
49
|
+
*
|
|
50
|
+
* @param operation - Work performed while the gate is suspended.
|
|
51
|
+
*/
|
|
52
|
+
withLifecycleGateSuspended?<T>(operation: () => Promise<T>): Promise<T>;
|
|
53
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation-kind mechanism.
|
|
3
|
+
*
|
|
4
|
+
* An operation kind is an open, shape-validated token. Any participant may
|
|
5
|
+
* claim a kind and any participant may emit one. The kernel defines only the
|
|
6
|
+
* token's shape; it does not define which kinds exist, which kind is assumed
|
|
7
|
+
* when none is written, or which participant serves a kind. Concrete kind
|
|
8
|
+
* values belong to the participants that claim them.
|
|
9
|
+
*/
|
|
10
|
+
/** Open operation-kind identity. */
|
|
11
|
+
export type BrudOperationKind = string;
|
|
12
|
+
/** Safe kind token: starts with a letter, then letters, digits, `_` or `-`. */
|
|
13
|
+
export declare const BRUD_KIND_PATTERN: RegExp;
|
|
14
|
+
/**
|
|
15
|
+
* Validates an untrusted kind token.
|
|
16
|
+
*
|
|
17
|
+
* @param value - Candidate kind.
|
|
18
|
+
* @returns `true` when the token is safe to register and route.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isValidBrudKind(value: string): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operation-kind mechanism.
|
|
3
|
+
*
|
|
4
|
+
* An operation kind is an open, shape-validated token. Any participant may
|
|
5
|
+
* claim a kind and any participant may emit one. The kernel defines only the
|
|
6
|
+
* token's shape; it does not define which kinds exist, which kind is assumed
|
|
7
|
+
* when none is written, or which participant serves a kind. Concrete kind
|
|
8
|
+
* values belong to the participants that claim them.
|
|
9
|
+
*/
|
|
10
|
+
/** Safe kind token: starts with a letter, then letters, digits, `_` or `-`. */
|
|
11
|
+
export const BRUD_KIND_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
12
|
+
/**
|
|
13
|
+
* Validates an untrusted kind token.
|
|
14
|
+
*
|
|
15
|
+
* @param value - Candidate kind.
|
|
16
|
+
* @returns `true` when the token is safe to register and route.
|
|
17
|
+
*/
|
|
18
|
+
export function isValidBrudKind(value) {
|
|
19
|
+
return BRUD_KIND_PATTERN.test(value);
|
|
20
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel call chain.
|
|
3
|
+
*
|
|
4
|
+
* Every call the kernel mediates runs inside a call chain the kernel starts.
|
|
5
|
+
* The kernel fixes the chain's root origin when the chain starts and never
|
|
6
|
+
* changes it while the chain runs. The kernel also records who the current
|
|
7
|
+
* caller is. Neither value is a string a caller supplies: both are read only
|
|
8
|
+
* from the execution context the kernel provides.
|
|
9
|
+
*/
|
|
10
|
+
/** Root origins a call chain can carry. */
|
|
11
|
+
export declare const CALL_ORIGINS: readonly ["kernel", "runtime", "host"];
|
|
12
|
+
/**
|
|
13
|
+
* Root origin of a call chain.
|
|
14
|
+
*
|
|
15
|
+
* `kernel` is a chain the kernel itself starts for its own work. `runtime` is a
|
|
16
|
+
* chain the kernel starts when it runs a participant inside the runtime.
|
|
17
|
+
* `host` is a chain the host starts from its authenticated session through the
|
|
18
|
+
* kernel's host entry point.
|
|
19
|
+
*/
|
|
20
|
+
export type CallOrigin = (typeof CALL_ORIGINS)[number];
|
|
21
|
+
/** Identity classes a caller can belong to. */
|
|
22
|
+
export declare const CALLER_CLASSES: readonly ["kernel", "participant", "host"];
|
|
23
|
+
/**
|
|
24
|
+
* Identity class of a caller.
|
|
25
|
+
*
|
|
26
|
+
* `kernel` is the kernel itself, `participant` is a participant admitted to
|
|
27
|
+
* the composition, and `host` is a host session.
|
|
28
|
+
*/
|
|
29
|
+
export type CallerClass = (typeof CALLER_CLASSES)[number];
|
|
30
|
+
/**
|
|
31
|
+
* A caller as the kernel knows it.
|
|
32
|
+
*
|
|
33
|
+
* Every field is assigned by the kernel. A participant cannot set any of them.
|
|
34
|
+
*/
|
|
35
|
+
export interface KernelCaller {
|
|
36
|
+
/** Identity class of the caller. */
|
|
37
|
+
readonly callerClass: CallerClass;
|
|
38
|
+
/**
|
|
39
|
+
* Kernel-issued identity token of the caller.
|
|
40
|
+
*
|
|
41
|
+
* Present for an admitted participant. `null` for the kernel itself and for
|
|
42
|
+
* a host session, which are identified by their class.
|
|
43
|
+
*/
|
|
44
|
+
readonly identity: string | null;
|
|
45
|
+
/**
|
|
46
|
+
* The caller's official status in this composition.
|
|
47
|
+
*
|
|
48
|
+
* Read from the kernel's identity-to-official mapping, which the kernel
|
|
49
|
+
* builds at boot from the composition's frozen config. Never supplied by the
|
|
50
|
+
* caller.
|
|
51
|
+
*/
|
|
52
|
+
readonly official: boolean;
|
|
53
|
+
/** Capabilities the caller declared it wants. A request, not a grant. */
|
|
54
|
+
readonly capabilities: ReadonlySet<string>;
|
|
55
|
+
/**
|
|
56
|
+
* The parent's kernel-issued identity token, when the caller is a caged child.
|
|
57
|
+
*
|
|
58
|
+
* Optional. A top-level participant has no parent and omits the field. A caged
|
|
59
|
+
* child carries the identity token of the participant that loaded it, or the
|
|
60
|
+
* cage's own identity token, as the kernel issued it at admission. The value
|
|
61
|
+
* is the parent's identity, never the parent's name, token id, or descriptor
|
|
62
|
+
* label. The child's own identity is separate and unchanged.
|
|
63
|
+
*/
|
|
64
|
+
readonly parentIdentity?: string;
|
|
65
|
+
}
|
|
66
|
+
/** The kernel-provided execution context of the current call. */
|
|
67
|
+
export interface KernelCallContext {
|
|
68
|
+
/** Root origin fixed when the chain started; propagated unchanged. */
|
|
69
|
+
readonly origin: CallOrigin;
|
|
70
|
+
/** The caller currently executing inside the chain. */
|
|
71
|
+
readonly caller: KernelCaller;
|
|
72
|
+
}
|
|
73
|
+
/** One record on the kernel's observation stream. */
|
|
74
|
+
export interface KernelObservation {
|
|
75
|
+
/** Milliseconds since the epoch at which the record was made. */
|
|
76
|
+
readonly at: number;
|
|
77
|
+
/** Kernel component or root primitive that made the record. */
|
|
78
|
+
readonly source: string;
|
|
79
|
+
/** Stable event name. */
|
|
80
|
+
readonly event: string;
|
|
81
|
+
/** Detailed, structured reason. Never returned to the refused caller. */
|
|
82
|
+
readonly detail: Readonly<Record<string, unknown>>;
|
|
83
|
+
}
|
|
84
|
+
/** Per-identity limits applied to every call the kernel mediates. */
|
|
85
|
+
export interface KernelCallLimits {
|
|
86
|
+
/** Calls one caller may make inside one window. */
|
|
87
|
+
readonly maxCallsPerWindow: number;
|
|
88
|
+
/** Window length in milliseconds. */
|
|
89
|
+
readonly windowMs: number;
|
|
90
|
+
/** Largest accepted request size, in bytes, for one mediated call. */
|
|
91
|
+
readonly maxRequestBytes: number;
|
|
92
|
+
}
|
|
93
|
+
/** Limits used when the host does not supply its own. */
|
|
94
|
+
export declare const DEFAULT_KERNEL_CALL_LIMITS: KernelCallLimits;
|
|
95
|
+
/**
|
|
96
|
+
* Kernel authority over the call chain.
|
|
97
|
+
*
|
|
98
|
+
* The kernel hands this only to root primitives, through the hardcore boot
|
|
99
|
+
* context. It is never reachable through the access broker.
|
|
100
|
+
*/
|
|
101
|
+
export interface KernelCallAuthority {
|
|
102
|
+
/** The current call's kernel-provided context, or `undefined` outside a chain. */
|
|
103
|
+
current(): KernelCallContext | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* Runs an operation as an admitted participant, keeping the root origin.
|
|
106
|
+
*
|
|
107
|
+
* Used when the kernel mediates a call into a participant's code. The chain's
|
|
108
|
+
* root origin does not change.
|
|
109
|
+
*
|
|
110
|
+
* @param identity - Kernel-issued identity token of the participant.
|
|
111
|
+
* @param operation - Work performed as that participant.
|
|
112
|
+
* @throws {Error} When no chain is active or the identity is not live.
|
|
113
|
+
*/
|
|
114
|
+
runAs<T>(identity: string, operation: () => T): T;
|
|
115
|
+
/** Whether an identity is live in the composition. */
|
|
116
|
+
isLive(identity: string): boolean;
|
|
117
|
+
/** The initialized instance of a live participant, or `undefined`. */
|
|
118
|
+
instanceOf(identity: string): unknown;
|
|
119
|
+
/**
|
|
120
|
+
* Starts a chain with the given origin and a participant's recorded caller.
|
|
121
|
+
*
|
|
122
|
+
* The caller is the participant the kernel admitted under `identity`; it is
|
|
123
|
+
* resolved from the same admission record {@link callerForIdentity} reads, so
|
|
124
|
+
* the frame carries the participant's kernel-issued identity and its parent
|
|
125
|
+
* relation exactly as the kernel recorded them. Unlike {@link runAs}, this
|
|
126
|
+
* member sets the chain's root origin and does not require an active chain.
|
|
127
|
+
* It composes what the kernel's own root-start and run-as paths do, without
|
|
128
|
+
* exposing either.
|
|
129
|
+
*
|
|
130
|
+
* @param origin - Root origin the new chain starts with.
|
|
131
|
+
* @param identity - Kernel-issued identity token of the participant.
|
|
132
|
+
* @param operation - Work performed inside the chain as that participant.
|
|
133
|
+
* @throws {Error} When the identity is not live in this composition.
|
|
134
|
+
*/
|
|
135
|
+
runAsOrigin<T>(origin: CallOrigin, identity: string, operation: () => T): T;
|
|
136
|
+
/**
|
|
137
|
+
* The kernel caller recorded for an identity token, or `undefined`.
|
|
138
|
+
*
|
|
139
|
+
* Reads the same admission record `isLive` and `instanceOf` read. Used to
|
|
140
|
+
* resolve the caller's class for a caller that is named by another caller's
|
|
141
|
+
* frame — the parent of a caged child — without the caller supplying it.
|
|
142
|
+
*
|
|
143
|
+
* @param identity - Kernel-issued identity token.
|
|
144
|
+
*/
|
|
145
|
+
callerForIdentity(identity: string): KernelCaller | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Applies the per-identity call and size limits to one mediated call.
|
|
148
|
+
*
|
|
149
|
+
* @param caller - The caller making the call.
|
|
150
|
+
* @param requestBytes - Size of the call's request.
|
|
151
|
+
* @returns `true` when the call is within the limits.
|
|
152
|
+
*/
|
|
153
|
+
admitCall(caller: KernelCaller, requestBytes: number): boolean;
|
|
154
|
+
/** Appends one record to the kernel's observation stream. */
|
|
155
|
+
observe(source: string, event: string, detail: Readonly<Record<string, unknown>>): void;
|
|
156
|
+
}
|
|
157
|
+
/** A host session's declaration when it enters a host-origin chain. */
|
|
158
|
+
export interface KernelHostSession {
|
|
159
|
+
/** Capabilities the host session declares it wants. */
|
|
160
|
+
readonly capabilities?: Iterable<string>;
|
|
161
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kernel call chain.
|
|
3
|
+
*
|
|
4
|
+
* Every call the kernel mediates runs inside a call chain the kernel starts.
|
|
5
|
+
* The kernel fixes the chain's root origin when the chain starts and never
|
|
6
|
+
* changes it while the chain runs. The kernel also records who the current
|
|
7
|
+
* caller is. Neither value is a string a caller supplies: both are read only
|
|
8
|
+
* from the execution context the kernel provides.
|
|
9
|
+
*/
|
|
10
|
+
/** Root origins a call chain can carry. */
|
|
11
|
+
export const CALL_ORIGINS = ['kernel', 'runtime', 'host'];
|
|
12
|
+
/** Identity classes a caller can belong to. */
|
|
13
|
+
export const CALLER_CLASSES = ['kernel', 'participant', 'host'];
|
|
14
|
+
/** Limits used when the host does not supply its own. */
|
|
15
|
+
export const DEFAULT_KERNEL_CALL_LIMITS = Object.freeze({
|
|
16
|
+
maxCallsPerWindow: 10_000,
|
|
17
|
+
windowMs: 1_000,
|
|
18
|
+
maxRequestBytes: 65_536,
|
|
19
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extensible capability token vocabulary.
|
|
3
|
+
*
|
|
4
|
+
* Capabilities are declared by the service that exposes an API and claimed by
|
|
5
|
+
* callers. They are open strings: the kernel validates their shape, not
|
|
6
|
+
* membership in a closed list. A token is one or more lowercase segments
|
|
7
|
+
* separated by `:`, for example `fs:read` or `photoshop:access`.
|
|
8
|
+
*
|
|
9
|
+
* The kernel provides this mechanism only. A giver that wants a public preset
|
|
10
|
+
* declares it in its own contract; the kernel ships none.
|
|
11
|
+
*/
|
|
12
|
+
/** Open capability token. */
|
|
13
|
+
export type CapabilityToken = string;
|
|
14
|
+
/**
|
|
15
|
+
* Shape accepted for capability tokens.
|
|
16
|
+
*
|
|
17
|
+
* Lowercase-only keeps diagnostics and manifest comparisons deterministic.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CAPABILITY_TOKEN_PATTERN: RegExp;
|
|
20
|
+
/**
|
|
21
|
+
* Validates a declarable capability token.
|
|
22
|
+
*
|
|
23
|
+
* @param value - Untrusted capability.
|
|
24
|
+
* @returns `true` when the value has the accepted capability shape.
|
|
25
|
+
*/
|
|
26
|
+
export declare function isCapabilityToken(value: unknown): value is CapabilityToken;
|