@brud/kernel 0.0.0-stage → 0.0.1
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 +44 -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 +112 -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 +61 -0
- package/dist/services/ExposedApiRegistry/orchestrator/ExposedApiRegistryService.js +407 -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 +65 -0
- package/dist/services/Interception/contracts/IInterceptionService.js +1 -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 +49 -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 +32 -0
- package/dist/services/Interception/orchestrator/InterceptionService.js +180 -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 +56 -0
- package/dist/services/Router/contracts/errors.js +75 -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 +90 -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 +74 -0
- package/dist/services/Router/orchestrator/RouterService.js +332 -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 +104 -0
- package/dist/services/WasmCage/src/caged.js +381 -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 +18 -0
- package/dist/src/bootstrap/bootKernelInternal.js +420 -0
- package/dist/src/bootstrap/bootTypes.d.ts +89 -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 +34 -0
- package/dist/src/bootstrap/config/integrity.js +79 -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 +8 -0
- package/dist/src/bootstrap/index.js +5 -0
- package/dist/src/bootstrap/packageRequirements.d.ts +26 -0
- package/dist/src/bootstrap/packageRequirements.js +52 -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/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 +129 -0
- package/dist/src/contracts/contextContract.js +285 -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 +28 -0
- package/dist/src/contracts/handler.js +1 -0
- package/dist/src/contracts/index.d.ts +25 -0
- package/dist/src/contracts/index.js +8 -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 +145 -0
- package/dist/src/contracts/manifest.js +295 -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 +118 -0
- package/dist/src/engine/BrudKernel.js +366 -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 +180 -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,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
|
+
/**
|
|
13
|
+
* Shape accepted for capability tokens.
|
|
14
|
+
*
|
|
15
|
+
* Lowercase-only keeps diagnostics and manifest comparisons deterministic.
|
|
16
|
+
*/
|
|
17
|
+
export const CAPABILITY_TOKEN_PATTERN = /^[a-z][a-z0-9_-]*(?::[a-z][a-z0-9_-]*)*$/;
|
|
18
|
+
/**
|
|
19
|
+
* Validates a declarable capability token.
|
|
20
|
+
*
|
|
21
|
+
* @param value - Untrusted capability.
|
|
22
|
+
* @returns `true` when the value has the accepted capability shape.
|
|
23
|
+
*/
|
|
24
|
+
export function isCapabilityToken(value) {
|
|
25
|
+
return typeof value === 'string' && CAPABILITY_TOKEN_PATTERN.test(value);
|
|
26
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type Token<T> = symbol & {
|
|
2
|
+
__brand: T;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Planned: the token-keyed container is a universal kernel primitive. It is
|
|
6
|
+
* constructed and consulted by the dispatch pipeline; no production module
|
|
7
|
+
* registers into it yet.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createToken<T>(description: string): Token<T>;
|
|
10
|
+
export interface IServiceContainer {
|
|
11
|
+
register<T>(token: Token<T>, provider: T | (() => T)): void;
|
|
12
|
+
resolve<T>(token: Token<T>): T;
|
|
13
|
+
has<T>(token: Token<T>): boolean;
|
|
14
|
+
createChildScope(): IServiceContainer;
|
|
15
|
+
freeze(): void;
|
|
16
|
+
readonly isFrozen: boolean;
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planned: the token-keyed container is a universal kernel primitive. It is
|
|
3
|
+
* constructed and consulted by the dispatch pipeline; no production module
|
|
4
|
+
* registers into it yet.
|
|
5
|
+
*/
|
|
6
|
+
export function createToken(description) {
|
|
7
|
+
return Symbol(description);
|
|
8
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Token } from './container.js';
|
|
2
|
+
import type { OperationResult } from './handler.js';
|
|
3
|
+
export interface ExecutionContext {
|
|
4
|
+
readonly sessionId: string;
|
|
5
|
+
/**
|
|
6
|
+
* Opaque host-supplied options bag.
|
|
7
|
+
*
|
|
8
|
+
* The kernel stores the bag at boot and attaches it unchanged to every
|
|
9
|
+
* execution context. The core never inspects a key; operations read the
|
|
10
|
+
* options their own domain owns.
|
|
11
|
+
*/
|
|
12
|
+
readonly options: Readonly<Record<string, unknown>>;
|
|
13
|
+
readonly signal?: AbortSignal;
|
|
14
|
+
readonly callDepth: number;
|
|
15
|
+
readonly metadata?: Record<string, unknown>;
|
|
16
|
+
resolve<T>(token: Token<T>): T;
|
|
17
|
+
invoke<TInput, TOutput>(kind: string, input: TInput): Promise<OperationResult<TOutput>>;
|
|
18
|
+
createChildContext(overrides?: Partial<ExecutionContext>): ExecutionContext;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic context contract.
|
|
3
|
+
*
|
|
4
|
+
* Services declare the fields they need from the host-supplied options bag.
|
|
5
|
+
* The core builds one schema from those declarations, enforces it at the boot
|
|
6
|
+
* and runtime boundaries, and never names a concrete field itself.
|
|
7
|
+
*
|
|
8
|
+
* Each participant declares only its own fields under its own namespace and
|
|
9
|
+
* reads only its own fields. The bag is owner-namespaced and opaque to the
|
|
10
|
+
* kernel core, and no kernel code synthesizes a context field. Secrets never
|
|
11
|
+
* travel in the bag: every participant constructed by the kernel receives it.
|
|
12
|
+
*/
|
|
13
|
+
/** Primitive types the contract understands. */
|
|
14
|
+
export declare const CONTEXT_FIELD_TYPES: readonly ["string", "number", "boolean", "object"];
|
|
15
|
+
/** A supported context field type. */
|
|
16
|
+
export type ContextFieldType = (typeof CONTEXT_FIELD_TYPES)[number];
|
|
17
|
+
/** One field a service requires or accepts from the options bag. */
|
|
18
|
+
export interface ContextFieldDeclaration {
|
|
19
|
+
/** Dotted field name inside the declaring service's namespace. */
|
|
20
|
+
readonly name: string;
|
|
21
|
+
/** Primitive type the value must have. */
|
|
22
|
+
readonly type: ContextFieldType;
|
|
23
|
+
/** Whether the field must be present when a context is created. */
|
|
24
|
+
readonly required: boolean;
|
|
25
|
+
/** Short explanation of what the field is for. */
|
|
26
|
+
readonly description: string;
|
|
27
|
+
}
|
|
28
|
+
/** One service's set of declarations for a single namespace. */
|
|
29
|
+
export interface ContextScopeDeclaration {
|
|
30
|
+
/** Namespace owned by the declaring service. */
|
|
31
|
+
readonly scope: string;
|
|
32
|
+
/** Fields declared inside that namespace. */
|
|
33
|
+
readonly fields: readonly ContextFieldDeclaration[];
|
|
34
|
+
}
|
|
35
|
+
/** A field after the kernel has accepted a declaration. */
|
|
36
|
+
export interface ContextFieldSchema extends ContextFieldDeclaration {
|
|
37
|
+
/** Service that owns the namespace and declared the field. */
|
|
38
|
+
readonly service: string;
|
|
39
|
+
}
|
|
40
|
+
/** The complete, introspectable contract for one kernel. */
|
|
41
|
+
export interface ContextSchema {
|
|
42
|
+
/** Whether further declarations are rejected. */
|
|
43
|
+
readonly locked: boolean;
|
|
44
|
+
/** Accepted fields in declaration order. */
|
|
45
|
+
readonly fields: readonly ContextFieldSchema[];
|
|
46
|
+
}
|
|
47
|
+
/** Stable failure code for every contract violation. */
|
|
48
|
+
export type ContextContractErrorCode = 'CONTEXT_CONTRACT_VIOLATION';
|
|
49
|
+
/** Raised when a declaration, a field name, or a value violates the contract. */
|
|
50
|
+
export declare class ContextContractError extends Error {
|
|
51
|
+
readonly code: ContextContractErrorCode;
|
|
52
|
+
/** Field involved in the violation, when one exists. */
|
|
53
|
+
readonly field: string | undefined;
|
|
54
|
+
/** Namespace/service involved in the violation, when one exists. */
|
|
55
|
+
readonly service: string | undefined;
|
|
56
|
+
/** Expected primitive type, when the violation is a type mismatch. */
|
|
57
|
+
readonly expectedType: ContextFieldType | undefined;
|
|
58
|
+
/** Actual value type observed, when the violation is a type mismatch. */
|
|
59
|
+
readonly actualType: string | undefined;
|
|
60
|
+
constructor(message: string, details?: {
|
|
61
|
+
readonly field?: string;
|
|
62
|
+
readonly service?: string;
|
|
63
|
+
readonly expectedType?: ContextFieldType;
|
|
64
|
+
readonly actualType?: string;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Reads a required non-empty string field from an options bag.
|
|
69
|
+
*
|
|
70
|
+
* The field name is supplied by the service; the core does not know any
|
|
71
|
+
* concrete field. This is the descriptor-level read used after contract
|
|
72
|
+
* validation, and it also protects standalone descriptor construction.
|
|
73
|
+
*
|
|
74
|
+
* @param options - Opaque options bag.
|
|
75
|
+
* @param field - Dotted field name owned by the calling service.
|
|
76
|
+
* @param service - Service id used in the error.
|
|
77
|
+
* @returns The string value.
|
|
78
|
+
* @throws {ContextContractError} When the value is absent or not a non-empty
|
|
79
|
+
* string.
|
|
80
|
+
*/
|
|
81
|
+
export declare function requireContextString(options: Readonly<Record<string, unknown>>, field: string, service: string): string;
|
|
82
|
+
/**
|
|
83
|
+
* Per-kernel declaration store and validator.
|
|
84
|
+
*
|
|
85
|
+
* The class is generic: it understands dotted namespaces, primitive types, and
|
|
86
|
+
* ownership, but no concrete field name.
|
|
87
|
+
*/
|
|
88
|
+
export declare class ContextContract {
|
|
89
|
+
private readonly fields;
|
|
90
|
+
private readonly owners;
|
|
91
|
+
private locked;
|
|
92
|
+
/** `true` once the kernel has reached `RUNNING`. */
|
|
93
|
+
get isLocked(): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Records one service's declarations.
|
|
96
|
+
*
|
|
97
|
+
* @param ownerId - Stable identity of the declaring module.
|
|
98
|
+
* @param scopeOrDeclaration - Namespace string or a complete scope declaration.
|
|
99
|
+
* @param fields - Fields to declare when the second argument is a scope string.
|
|
100
|
+
*/
|
|
101
|
+
declare(ownerId: string, scopeOrDeclaration: string | ContextScopeDeclaration, fields?: readonly ContextFieldDeclaration[]): void;
|
|
102
|
+
/**
|
|
103
|
+
* Validates an options bag against every accepted declaration.
|
|
104
|
+
*
|
|
105
|
+
* @param options - Host-supplied values carried through unchanged.
|
|
106
|
+
* @throws {ContextContractError} When a required field is missing or a value
|
|
107
|
+
* has the wrong type.
|
|
108
|
+
*/
|
|
109
|
+
validate(options: Readonly<Record<string, unknown>>): void;
|
|
110
|
+
/**
|
|
111
|
+
* Lists, per declaring owner, the required fields the bag does not carry.
|
|
112
|
+
*
|
|
113
|
+
* @param options - Host-supplied values.
|
|
114
|
+
* @returns Owner id mapped to its missing required field names.
|
|
115
|
+
*/
|
|
116
|
+
missingRequiredByOwner(options: Readonly<Record<string, unknown>>): ReadonlyMap<string, readonly string[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Withdraws every declaration one owner made.
|
|
119
|
+
*
|
|
120
|
+
* Used when admission prunes an optional participant before boot.
|
|
121
|
+
*
|
|
122
|
+
* @param ownerId - Stable identity of the declaring module.
|
|
123
|
+
*/
|
|
124
|
+
withdraw(ownerId: string): void;
|
|
125
|
+
/** Prevents any further declaration. */
|
|
126
|
+
lock(): void;
|
|
127
|
+
/** Returns an immutable snapshot of the current schema. */
|
|
128
|
+
schema(): ContextSchema;
|
|
129
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic context contract.
|
|
3
|
+
*
|
|
4
|
+
* Services declare the fields they need from the host-supplied options bag.
|
|
5
|
+
* The core builds one schema from those declarations, enforces it at the boot
|
|
6
|
+
* and runtime boundaries, and never names a concrete field itself.
|
|
7
|
+
*
|
|
8
|
+
* Each participant declares only its own fields under its own namespace and
|
|
9
|
+
* reads only its own fields. The bag is owner-namespaced and opaque to the
|
|
10
|
+
* kernel core, and no kernel code synthesizes a context field. Secrets never
|
|
11
|
+
* travel in the bag: every participant constructed by the kernel receives it.
|
|
12
|
+
*/
|
|
13
|
+
/** Primitive types the contract understands. */
|
|
14
|
+
export const CONTEXT_FIELD_TYPES = ['string', 'number', 'boolean', 'object'];
|
|
15
|
+
/** Raised when a declaration, a field name, or a value violates the contract. */
|
|
16
|
+
export class ContextContractError extends Error {
|
|
17
|
+
code = 'CONTEXT_CONTRACT_VIOLATION';
|
|
18
|
+
/** Field involved in the violation, when one exists. */
|
|
19
|
+
field;
|
|
20
|
+
/** Namespace/service involved in the violation, when one exists. */
|
|
21
|
+
service;
|
|
22
|
+
/** Expected primitive type, when the violation is a type mismatch. */
|
|
23
|
+
expectedType;
|
|
24
|
+
/** Actual value type observed, when the violation is a type mismatch. */
|
|
25
|
+
actualType;
|
|
26
|
+
constructor(message, details = {}) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = 'ContextContractError';
|
|
29
|
+
this.field = details.field;
|
|
30
|
+
this.service = details.service;
|
|
31
|
+
this.expectedType = details.expectedType;
|
|
32
|
+
this.actualType = details.actualType;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const SCOPE_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*$/u;
|
|
36
|
+
const SEGMENT_PATTERN = /^[A-Za-z0-9_-]+$/u;
|
|
37
|
+
function isRecord(value) {
|
|
38
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
39
|
+
}
|
|
40
|
+
function isContextFieldType(value) {
|
|
41
|
+
return typeof value === 'string'
|
|
42
|
+
&& CONTEXT_FIELD_TYPES.includes(value);
|
|
43
|
+
}
|
|
44
|
+
function describeValueType(value) {
|
|
45
|
+
if (value === null) {
|
|
46
|
+
return 'null';
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
return 'array';
|
|
50
|
+
}
|
|
51
|
+
return typeof value;
|
|
52
|
+
}
|
|
53
|
+
function matchesType(value, type) {
|
|
54
|
+
switch (type) {
|
|
55
|
+
case 'string':
|
|
56
|
+
return typeof value === 'string';
|
|
57
|
+
case 'number':
|
|
58
|
+
return typeof value === 'number' && !Number.isNaN(value);
|
|
59
|
+
case 'boolean':
|
|
60
|
+
return typeof value === 'boolean';
|
|
61
|
+
case 'object':
|
|
62
|
+
return isRecord(value);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reads a required non-empty string field from an options bag.
|
|
67
|
+
*
|
|
68
|
+
* The field name is supplied by the service; the core does not know any
|
|
69
|
+
* concrete field. This is the descriptor-level read used after contract
|
|
70
|
+
* validation, and it also protects standalone descriptor construction.
|
|
71
|
+
*
|
|
72
|
+
* @param options - Opaque options bag.
|
|
73
|
+
* @param field - Dotted field name owned by the calling service.
|
|
74
|
+
* @param service - Service id used in the error.
|
|
75
|
+
* @returns The string value.
|
|
76
|
+
* @throws {ContextContractError} When the value is absent or not a non-empty
|
|
77
|
+
* string.
|
|
78
|
+
*/
|
|
79
|
+
export function requireContextString(options, field, service) {
|
|
80
|
+
const value = options[field];
|
|
81
|
+
if (typeof value !== 'string' || value.length === 0) {
|
|
82
|
+
throw new ContextContractError(`${service} requires the non-empty string context field "${field}" (options['${field}']).`, {
|
|
83
|
+
field,
|
|
84
|
+
service,
|
|
85
|
+
expectedType: 'string',
|
|
86
|
+
actualType: value === undefined ? 'missing' : describeValueType(value),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
function assertScope(scope) {
|
|
92
|
+
if (typeof scope !== 'string' || !SCOPE_PATTERN.test(scope)) {
|
|
93
|
+
throw new ContextContractError(`Invalid context namespace "${String(scope)}". A namespace must start with a letter and contain only letters, digits, "_" or "-".`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function assertFieldName(scope, name) {
|
|
97
|
+
if (typeof name !== 'string') {
|
|
98
|
+
throw new ContextContractError(`A context field declared by namespace "${scope}" must have a string name.`, { service: scope });
|
|
99
|
+
}
|
|
100
|
+
const segments = name.split('.');
|
|
101
|
+
if (segments.length < 2 || segments.some((segment) => !SEGMENT_PATTERN.test(segment))) {
|
|
102
|
+
throw new ContextContractError(`Field "${name}" declared by namespace "${scope}" must be a dotted path such as "${scope}.name".`, { field: name, service: scope });
|
|
103
|
+
}
|
|
104
|
+
if (segments[0] !== scope) {
|
|
105
|
+
throw new ContextContractError(`Namespace "${scope}" cannot declare field "${name}"; declarations must stay inside the "${scope}." namespace.`, { field: name, service: scope });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function assertDeclaration(scope, declaration) {
|
|
109
|
+
if (!isRecord(declaration)) {
|
|
110
|
+
throw new ContextContractError(`Namespace "${scope}" supplied a context field declaration that is not an object.`, { service: scope });
|
|
111
|
+
}
|
|
112
|
+
assertFieldName(scope, declaration.name);
|
|
113
|
+
if (!isContextFieldType(declaration.type)) {
|
|
114
|
+
throw new ContextContractError(`Field "${declaration.name}" declared by namespace "${scope}" has unsupported type "${String(declaration.type)}". Expected one of: ${CONTEXT_FIELD_TYPES.join(', ')}.`, { field: declaration.name, service: scope });
|
|
115
|
+
}
|
|
116
|
+
if (typeof declaration.required !== 'boolean') {
|
|
117
|
+
throw new ContextContractError(`Field "${declaration.name}" declared by namespace "${scope}" must set "required" to a boolean.`, { field: declaration.name, service: scope });
|
|
118
|
+
}
|
|
119
|
+
if (typeof declaration.description !== 'string' || declaration.description.length === 0) {
|
|
120
|
+
throw new ContextContractError(`Field "${declaration.name}" declared by namespace "${scope}" must include a non-empty description.`, { field: declaration.name, service: scope });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function normalizeDeclaration(scopeOrDeclaration, fields) {
|
|
124
|
+
if (typeof scopeOrDeclaration === 'string') {
|
|
125
|
+
return { scope: scopeOrDeclaration, fields: fields ?? [] };
|
|
126
|
+
}
|
|
127
|
+
if (!isRecord(scopeOrDeclaration)
|
|
128
|
+
|| typeof scopeOrDeclaration.scope !== 'string'
|
|
129
|
+
|| !Array.isArray(scopeOrDeclaration.fields)) {
|
|
130
|
+
throw new ContextContractError('A context contract declaration requires a scope string and a fields array.');
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
scope: scopeOrDeclaration.scope,
|
|
134
|
+
fields: scopeOrDeclaration.fields,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Per-kernel declaration store and validator.
|
|
139
|
+
*
|
|
140
|
+
* The class is generic: it understands dotted namespaces, primitive types, and
|
|
141
|
+
* ownership, but no concrete field name.
|
|
142
|
+
*/
|
|
143
|
+
export class ContextContract {
|
|
144
|
+
fields = new Map();
|
|
145
|
+
owners = new Map();
|
|
146
|
+
locked = false;
|
|
147
|
+
/** `true` once the kernel has reached `RUNNING`. */
|
|
148
|
+
get isLocked() {
|
|
149
|
+
return this.locked;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Records one service's declarations.
|
|
153
|
+
*
|
|
154
|
+
* @param ownerId - Stable identity of the declaring module.
|
|
155
|
+
* @param scopeOrDeclaration - Namespace string or a complete scope declaration.
|
|
156
|
+
* @param fields - Fields to declare when the second argument is a scope string.
|
|
157
|
+
*/
|
|
158
|
+
declare(ownerId, scopeOrDeclaration, fields) {
|
|
159
|
+
const { scope, fields: declarations } = normalizeDeclaration(scopeOrDeclaration, fields);
|
|
160
|
+
assertScope(scope);
|
|
161
|
+
if (this.locked) {
|
|
162
|
+
throw new ContextContractError(`Context contract is locked; namespace "${scope}" cannot declare new fields after the kernel reached RUNNING.`, { service: scope });
|
|
163
|
+
}
|
|
164
|
+
const owner = this.owners.get(scope);
|
|
165
|
+
if (owner !== undefined && owner !== ownerId) {
|
|
166
|
+
throw new ContextContractError(`Context namespace "${scope}" is already owned by another service; a namespace can only be declared by its owning service.`, { service: scope });
|
|
167
|
+
}
|
|
168
|
+
if (owner === undefined) {
|
|
169
|
+
this.owners.set(scope, ownerId);
|
|
170
|
+
}
|
|
171
|
+
for (const declaration of declarations) {
|
|
172
|
+
assertDeclaration(scope, declaration);
|
|
173
|
+
const existing = this.fields.get(declaration.name);
|
|
174
|
+
if (existing !== undefined) {
|
|
175
|
+
throw new ContextContractError(`Field "${declaration.name}" is already declared by namespace "${existing.service}".`, { field: declaration.name, service: scope });
|
|
176
|
+
}
|
|
177
|
+
this.fields.set(declaration.name, {
|
|
178
|
+
name: declaration.name,
|
|
179
|
+
type: declaration.type,
|
|
180
|
+
required: declaration.required,
|
|
181
|
+
description: declaration.description,
|
|
182
|
+
service: scope,
|
|
183
|
+
ownerId,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Validates an options bag against every accepted declaration.
|
|
189
|
+
*
|
|
190
|
+
* @param options - Host-supplied values carried through unchanged.
|
|
191
|
+
* @throws {ContextContractError} When a required field is missing or a value
|
|
192
|
+
* has the wrong type.
|
|
193
|
+
*/
|
|
194
|
+
validate(options) {
|
|
195
|
+
for (const [key, value] of Object.entries(options)) {
|
|
196
|
+
if (this.fields.has(key)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
// String-valued options are contract fields. Every one must be a dotted
|
|
200
|
+
// namespace path; flat aliases have no service owner and cannot be read.
|
|
201
|
+
if (typeof value === 'string' && !key.includes('.')) {
|
|
202
|
+
throw new ContextContractError(`Un-namespaced string context option "${key}" is forbidden; use a dotted service namespace.`, { field: key, actualType: 'string' });
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (const field of this.fields.values()) {
|
|
206
|
+
const value = options[field.name];
|
|
207
|
+
if (value === undefined) {
|
|
208
|
+
if (field.required) {
|
|
209
|
+
throw new ContextContractError(`Required context field "${field.name}" declared by service "${field.service}" is missing. Expected ${field.type}.`, {
|
|
210
|
+
field: field.name,
|
|
211
|
+
service: field.service,
|
|
212
|
+
expectedType: field.type,
|
|
213
|
+
actualType: 'missing',
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (!matchesType(value, field.type)) {
|
|
219
|
+
throw new ContextContractError(`Context field "${field.name}" declared by service "${field.service}" must be of type ${field.type}; received ${describeValueType(value)}.`, {
|
|
220
|
+
field: field.name,
|
|
221
|
+
service: field.service,
|
|
222
|
+
expectedType: field.type,
|
|
223
|
+
actualType: describeValueType(value),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Lists, per declaring owner, the required fields the bag does not carry.
|
|
230
|
+
*
|
|
231
|
+
* @param options - Host-supplied values.
|
|
232
|
+
* @returns Owner id mapped to its missing required field names.
|
|
233
|
+
*/
|
|
234
|
+
missingRequiredByOwner(options) {
|
|
235
|
+
const missing = new Map();
|
|
236
|
+
for (const field of this.fields.values()) {
|
|
237
|
+
if (field.required && options[field.name] === undefined) {
|
|
238
|
+
const names = missing.get(field.ownerId) ?? [];
|
|
239
|
+
names.push(field.name);
|
|
240
|
+
missing.set(field.ownerId, names);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return missing;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Withdraws every declaration one owner made.
|
|
247
|
+
*
|
|
248
|
+
* Used when admission prunes an optional participant before boot.
|
|
249
|
+
*
|
|
250
|
+
* @param ownerId - Stable identity of the declaring module.
|
|
251
|
+
*/
|
|
252
|
+
withdraw(ownerId) {
|
|
253
|
+
if (this.locked) {
|
|
254
|
+
throw new ContextContractError('Context contract is locked; declarations cannot be withdrawn after the kernel reached RUNNING.');
|
|
255
|
+
}
|
|
256
|
+
for (const [name, field] of [...this.fields]) {
|
|
257
|
+
if (field.ownerId === ownerId) {
|
|
258
|
+
this.fields.delete(name);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
for (const [scope, owner] of [...this.owners]) {
|
|
262
|
+
if (owner === ownerId) {
|
|
263
|
+
this.owners.delete(scope);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/** Prevents any further declaration. */
|
|
268
|
+
lock() {
|
|
269
|
+
this.locked = true;
|
|
270
|
+
}
|
|
271
|
+
/** Returns an immutable snapshot of the current schema. */
|
|
272
|
+
schema() {
|
|
273
|
+
const fields = [...this.fields.values()].map((field) => Object.freeze({
|
|
274
|
+
name: field.name,
|
|
275
|
+
type: field.type,
|
|
276
|
+
required: field.required,
|
|
277
|
+
description: field.description,
|
|
278
|
+
service: field.service,
|
|
279
|
+
}));
|
|
280
|
+
return Object.freeze({
|
|
281
|
+
locked: this.locked,
|
|
282
|
+
fields: Object.freeze(fields),
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The caller of a routed operation, as recorded on the kernel call chain.
|
|
3
|
+
* It is never taken from the request. `capabilities` is a sorted array here,
|
|
4
|
+
* unlike the `ReadonlySet` of the kernel's own caller.
|
|
5
|
+
*/
|
|
6
|
+
export interface DispatchCallerView {
|
|
7
|
+
readonly identity: string | null;
|
|
8
|
+
readonly callerClass: string;
|
|
9
|
+
readonly official: boolean;
|
|
10
|
+
readonly capabilities: readonly string[];
|
|
11
|
+
readonly origin: string;
|
|
12
|
+
}
|
|
13
|
+
/** What a kind's dispatch exposure receives for one operation. */
|
|
14
|
+
export interface DispatchContextView {
|
|
15
|
+
/** Kernel-derived caller of the route request. */
|
|
16
|
+
readonly caller: DispatchCallerView;
|
|
17
|
+
/** Cancellation signal, when the transport supplied one. */
|
|
18
|
+
readonly signal?: AbortSignal;
|
|
19
|
+
/** Validate only; do not execute. */
|
|
20
|
+
readonly dryRun?: boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Token } from './container.js';
|
|
2
|
+
import type { ExecutionContext } from './context.js';
|
|
3
|
+
export interface PluginMetadata {
|
|
4
|
+
readonly isOfficial?: boolean;
|
|
5
|
+
readonly version?: string;
|
|
6
|
+
readonly author?: string;
|
|
7
|
+
readonly permissions?: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export interface OperationResult<TData = unknown> {
|
|
10
|
+
status: "success" | "failed" | "aborted" | "skipped";
|
|
11
|
+
data?: TData;
|
|
12
|
+
message?: string;
|
|
13
|
+
error?: Error | string;
|
|
14
|
+
durationMs?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface PromptDescriptor {
|
|
17
|
+
readonly description: string;
|
|
18
|
+
readonly syntaxGuide?: string;
|
|
19
|
+
readonly systemPromptFragment?: string;
|
|
20
|
+
readonly examples?: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
export interface OperationHandler<TInput = unknown, TOutput = unknown> {
|
|
23
|
+
readonly kind: string;
|
|
24
|
+
readonly requiredCapabilities?: readonly Token<unknown>[];
|
|
25
|
+
readonly promptDescriptor?: PromptDescriptor;
|
|
26
|
+
readonly metadata?: PluginMetadata;
|
|
27
|
+
execute(context: ExecutionContext, input: TInput): Promise<OperationResult<TOutput>>;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type { ServiceToken, InferService } from './serviceToken.js';
|
|
2
|
+
export { createServiceToken } from './serviceToken.js';
|
|
3
|
+
export type { ServiceAccessPolicy } from './policy.js';
|
|
4
|
+
export { AccessDeniedError, BlacklistedAccessViolationError, AllowlistViolationError, CallerIdentityMismatchError, } from './policy.js';
|
|
5
|
+
export type { ServiceTier, ServiceContext, IServiceLifecycle, KernelLogger, } from './lifecycle.js';
|
|
6
|
+
export type { ServiceInfo, IKernelAccessBroker } from './accessBroker.js';
|
|
7
|
+
export type { ServiceDescriptor, ServiceContractDeclaration, } from './serviceDescriptor.js';
|
|
8
|
+
export type { KernelBootOptions, IBrudKernel } from './kernel.js';
|
|
9
|
+
export type { CallOrigin, CallerClass, KernelCallAuthority, KernelCallContext, KernelCallLimits, KernelCaller, KernelHostSession, KernelObservation, } from './callChain.js';
|
|
10
|
+
export { CALLER_CLASSES, CALL_ORIGINS, DEFAULT_KERNEL_CALL_LIMITS, } from './callChain.js';
|
|
11
|
+
export type { AdmittedManifest, EventDeclaration, InterceptionDeclaration, InterceptionPointDeclaration, KindDeclaration, ExposureDeclaration, ParticipantManifest, ParticipantRequests, } from './manifest.js';
|
|
12
|
+
export { ParticipantManifestError, admitParticipantManifest, } from './manifest.js';
|
|
13
|
+
export type { Token } from './container.js';
|
|
14
|
+
export { createToken } from './container.js';
|
|
15
|
+
export type { IServiceContainer } from './container.js';
|
|
16
|
+
export type { ExecutionContext } from './context.js';
|
|
17
|
+
export type { ContextContractErrorCode, ContextFieldDeclaration, ContextFieldSchema, ContextFieldType, ContextSchema, ContextScopeDeclaration, } from './contextContract.js';
|
|
18
|
+
export { CONTEXT_FIELD_TYPES, ContextContract, ContextContractError, requireContextString, } from './contextContract.js';
|
|
19
|
+
export type { OperationResult, OperationHandler, PromptDescriptor, PluginMetadata } from './handler.js';
|
|
20
|
+
export type { CapabilityToken } from './capability.js';
|
|
21
|
+
export { CAPABILITY_TOKEN_PATTERN, isCapabilityToken, } from './capability.js';
|
|
22
|
+
export type { BrudOperationKind } from './brudOperation.js';
|
|
23
|
+
export { BRUD_KIND_PATTERN, isValidBrudKind, } from './brudOperation.js';
|
|
24
|
+
export type { MiddlewareNext, Middleware, IExecutionPipeline } from './pipeline.js';
|
|
25
|
+
export type { IOperationRegistry } from './registry.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createServiceToken } from './serviceToken.js';
|
|
2
|
+
export { AccessDeniedError, BlacklistedAccessViolationError, AllowlistViolationError, CallerIdentityMismatchError, } from './policy.js';
|
|
3
|
+
export { CALLER_CLASSES, CALL_ORIGINS, DEFAULT_KERNEL_CALL_LIMITS, } from './callChain.js';
|
|
4
|
+
export { ParticipantManifestError, admitParticipantManifest, } from './manifest.js';
|
|
5
|
+
export { createToken } from './container.js';
|
|
6
|
+
export { CONTEXT_FIELD_TYPES, ContextContract, ContextContractError, requireContextString, } from './contextContract.js';
|
|
7
|
+
export { CAPABILITY_TOKEN_PATTERN, isCapabilityToken, } from './capability.js';
|
|
8
|
+
export { BRUD_KIND_PATTERN, isValidBrudKind, } from './brudOperation.js';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { IKernelAccessBroker } from './accessBroker.js';
|
|
2
|
+
import type { KernelHostSession, KernelObservation } from './callChain.js';
|
|
3
|
+
import type { ContextSchema } from './contextContract.js';
|
|
4
|
+
import type { KernelLogger } from './lifecycle.js';
|
|
5
|
+
import type { ServiceDescriptor } from './serviceDescriptor.js';
|
|
6
|
+
/**
|
|
7
|
+
* Options controlling a kernel boot sequence.
|
|
8
|
+
*/
|
|
9
|
+
export interface KernelBootOptions {
|
|
10
|
+
/** Open options bag supplied by the host and forwarded to services. */
|
|
11
|
+
readonly options?: Readonly<Record<string, unknown>>;
|
|
12
|
+
/** Optional diagnostic sink forwarded to every service context. */
|
|
13
|
+
readonly logger?: KernelLogger;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Root microkernel contract governing service registration and lifecycle.
|
|
17
|
+
*/
|
|
18
|
+
export interface IBrudKernel extends IKernelAccessBroker {
|
|
19
|
+
/**
|
|
20
|
+
* Registers a service descriptor. Must be called before {@link boot}.
|
|
21
|
+
*
|
|
22
|
+
* @typeParam TService - The public interface exposed by the service.
|
|
23
|
+
* @param descriptor - Self-describing registration record.
|
|
24
|
+
*/
|
|
25
|
+
register<TService>(descriptor: ServiceDescriptor<TService>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Initializes every registered service in dependency order.
|
|
28
|
+
*
|
|
29
|
+
* @param options - Boot configuration.
|
|
30
|
+
*/
|
|
31
|
+
boot(options: KernelBootOptions): Promise<void>;
|
|
32
|
+
/** Disposes every initialized service in reverse dependency order. */
|
|
33
|
+
shutdown(): Promise<void>;
|
|
34
|
+
/** Returns the dynamically built context schema. */
|
|
35
|
+
getContextSchema(): ContextSchema;
|
|
36
|
+
/**
|
|
37
|
+
* Validates an options bag against the locked context schema.
|
|
38
|
+
*
|
|
39
|
+
* Used by hosts that build a fresh context after boot.
|
|
40
|
+
*/
|
|
41
|
+
validateContextOptions(options: Readonly<Record<string, unknown>>): void;
|
|
42
|
+
/**
|
|
43
|
+
* Runs an operation inside a host-origin call chain.
|
|
44
|
+
*
|
|
45
|
+
* This is the only way a chain gets the `host` origin. It is a method of the
|
|
46
|
+
* kernel object, which only the host holds; a participant receives the access
|
|
47
|
+
* broker, never the kernel. The host calls it from its authenticated session.
|
|
48
|
+
*
|
|
49
|
+
* @param session - The host session's declaration.
|
|
50
|
+
* @param operation - Work performed inside the host-origin chain.
|
|
51
|
+
*/
|
|
52
|
+
runHostCall<T>(session: KernelHostSession, operation: () => T): T;
|
|
53
|
+
/**
|
|
54
|
+
* Reads the kernel's observation stream.
|
|
55
|
+
*
|
|
56
|
+
* Detailed denial reasons are recorded here, never returned to the refused
|
|
57
|
+
* caller. Only the holder of the kernel object can read the stream.
|
|
58
|
+
*/
|
|
59
|
+
readObservations(): readonly KernelObservation[];
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|