@godspeedai/cognate-kernel-cordis 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +99 -31
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,33 +1,101 @@
1
1
  # @godspeedai/cognate-kernel-cordis
2
2
 
3
- Cordis-backed implementation of `@godspeedai/cognate-kernel-api`. Only this package imports `cordis`; no
4
- Cordis type crosses an exported signature (spec §3.4). See `docs/decisions/ADR-0001-kernel-engine-cordis.md`.
5
-
6
- ## Mapping
7
-
8
- | Cognate concept | Cordis concept |
9
- | --- | --- |
10
- | `Scope` | A Cordis `Context` obtained via `ctx.isolate(id)` (`scope.ts`) |
11
- | Mounted component occurrence | One `ctx.plugin()` call = one Cordis fiber, per attempt (`fiber.ts`) |
12
- | `effects.register()` | Entries in an adapter-owned stack unwound by a single `ctx.effect()` wrapper |
13
- | `provide()` / capability publish-withdraw | Committed into `CapabilityRegistry` only after activation succeeds, torn down by the same wrapper effect |
14
- | `CapabilityLease` | Adapter object bound to one `Publication`, revalidated per invoke (Cordis has no lease type) |
15
- | `kernel.resolve()` / dependency matching | `CapabilityRegistry.find()` using `isCompatible` over scope-ancestor chain |
16
-
17
- ## Adapter-owned behaviours (Cordis has none of these; ADR-0001 mitigations)
18
-
19
- - **Aggregated cleanup errors** — Cordis reports each disposer error to its own logger and never
20
- aggregates them; the single wrapper effect aggregates into `CleanupError` itself.
21
- - **Reverse-order disposal** — Cordis's own `Promise.all`-based unload is only reverse-of-completion
22
- for synchronous disposers; the adapter runs its own effect stack sequentially in reverse.
23
- - **Cancellation signal** — Cordis never cancels an in-flight `apply()`; the adapter derives its own
24
- `AbortSignal` per attempt and per active occurrence.
25
- - **Retry/backoff and permanent failure** — fully adapter-owned state machine (`fiber.ts`).
26
- - **Activation timeout** — raced against the Cordis fiber promise; a timed-out fiber is abandoned,
27
- not force-disposed (Cordis's `dispose()` blocks forever on a hung `apply()`).
28
- - **FAILED/DEACTIVATING vocabulary and fiber-state translation** — Cordis uses
29
- PENDING/LOADING/ACTIVE/FAILED/DISPOSED/UNLOADING; never exposed.
30
- - **Dependency eligibility (`isCompatible`, version/attributes)** and **scope visibility**
31
- (descendant-visible, sibling-invisible) — Cordis's `ctx.provide`/`ctx.get`/`isolate` are
32
- single-slot-per-name with no version matching and no dynamic per-id isolation; both are
33
- implemented in `registry.ts`/`scope.ts`.
3
+ A complete implementation of the [`@godspeedai/cognate-kernel-api`](https://www.npmjs.com/package/@godspeedai/cognate-kernel-api)
4
+ kernel contract — scopes, components, capabilities, fibers, effects, policy — built on the Cordis
5
+ plugin system. This is the only Cognate package that imports `cordis`, and no Cordis type appears in
6
+ its public surface: consumers program entirely against the kernel contract.
7
+
8
+ **When to use this package:** you want a standalone capability kernel without the rest of the
9
+ runtime. Most applications meet it indirectly through
10
+ [`@godspeedai/cognate-runtime-bun`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-bun),
11
+ which embeds this kernel.
12
+
13
+ ## Installation
14
+
15
+ ```sh
16
+ bun add @godspeedai/cognate-kernel-cordis
17
+ ```
18
+
19
+ Requires [Bun](https://bun.sh) >= 1.4.0 (`cordis` is installed automatically as a dependency).
20
+
21
+ ## Quick start
22
+
23
+ ```ts
24
+ import { allowCapabilities, isUnavailable } from "@godspeedai/cognate-kernel-api";
25
+ import { createCordisKernel } from "@godspeedai/cognate-kernel-cordis";
26
+
27
+ const kernel = await createCordisKernel({
28
+ tenant: "tenant-a",
29
+ principal: { id: "system", kind: "system" },
30
+ policy: allowCapabilities("allow-greetings", ["greet"]),
31
+ });
32
+
33
+ // Mount a component; its activation runs, and its capability is published on success.
34
+ const handle = await kernel.mount({
35
+ id: "greeter",
36
+ provides: [{ id: "greet", version: "1.0.0" }],
37
+ activate(fiber) {
38
+ fiber.effects.register(() => console.log("greeter cleaned up"));
39
+ fiber.provide({ id: "greet", version: "1.0.0" }, async (name: string) => ({ hello: name }));
40
+ },
41
+ });
42
+ await handle.waitFor("ACTIVE");
43
+
44
+ // Resolution matches deterministically and never consults policy;
45
+ // the invocation is what the policy authorizes.
46
+ const resolved = kernel.resolve({ capability: "greet" });
47
+ if (!isUnavailable(resolved)) {
48
+ const result = await resolved.invoke("Ada", {
49
+ actor: { id: "alice", kind: "user" },
50
+ correlationId: "corr-1",
51
+ });
52
+ console.log(result); // { ok: true, value: { hello: "Ada" } }
53
+ }
54
+
55
+ // Disposes every fiber and effect, children first.
56
+ await kernel.shutdown("done");
57
+ ```
58
+
59
+ `createCordisKernel` is a `KernelFactory`: it returns a `Kernel` whose `mount`, `resolve`,
60
+ `observe`, and `shutdown` follow the shared contract. A failed resolution is not an exception — it
61
+ returns `{ unavailable: true, requirement, reason }`, which `isUnavailable` distinguishes from a
62
+ lease.
63
+
64
+ ## What the engine guarantees
65
+
66
+ - **All-or-nothing activation.** A failed activation disposes that attempt's effects in reverse
67
+ order and publishes nothing. A component whose requirements are missing stays `WAITING` with no
68
+ fiber and activates automatically when a compatible provider appears.
69
+ - **Orderly teardown.** `handle.dispose`, `scope.close`, and `kernel.shutdown` run every disposer in
70
+ reverse order and are idempotent; failures aggregate into a single `CleanupError` rejection.
71
+ Closing a scope closes its children first.
72
+ - **Cancellation.** Every activation and invocation carries an `AbortSignal`, aborted on caller
73
+ cancellation, deadline expiry, or provider teardown.
74
+ - **Retries with backoff.** Transient activation failures retry per the component's `retry` policy.
75
+ Throwing `PermanentActivationError` skips retries until `handle.reset()`. Activation that exceeds
76
+ `activationTimeoutMs` (default 30 seconds) fails transiently instead of hanging.
77
+ - **Scoped visibility.** A provided capability is visible in its scope and its descendants only;
78
+ sibling scopes never see it. Child scopes may narrow the principal and never gain authority by
79
+ inheritance.
80
+ - **Audit.** `kernel.observe` streams fiber-state transitions, capability publication and
81
+ withdrawal, cleanup failures, and every policy decision.
82
+
83
+ ## Limitations
84
+
85
+ - In-process and single-tenant: one kernel serves one tenant, and there is no network surface. The
86
+ runtime layers caller tenancy and services on top.
87
+ - Mounting into a closed scope throws `ScopeClosedError`.
88
+ - The kernel resolves and invokes capabilities but knows nothing about durability, runs, events, or
89
+ persistence — that is the runtime's job.
90
+
91
+ ## Related packages
92
+
93
+ - [`@godspeedai/cognate-kernel-api`](https://www.npmjs.com/package/@godspeedai/cognate-kernel-api) —
94
+ the contract this package implements, including the conformance suites it passes.
95
+ - [`@godspeedai/cognate-runtime-bun`](https://www.npmjs.com/package/@godspeedai/cognate-runtime-bun) —
96
+ the reference runtime that embeds this kernel.
97
+ - [`@godspeedai/cognate`](https://www.npmjs.com/package/@godspeedai/cognate) — the SDK umbrella.
98
+
99
+ ## License
100
+
101
+ Apache-2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godspeedai/cognate-kernel-cordis",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Cordis-backed implementation of @godspeedai/cognate-kernel-api. The only package allowed to import cordis.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -22,7 +22,7 @@
22
22
  ".": "./src/index.ts"
23
23
  },
24
24
  "dependencies": {
25
- "@godspeedai/cognate-kernel-api": "^0.1.1",
25
+ "@godspeedai/cognate-kernel-api": "^0.2.0",
26
26
  "cordis": "4.0.0-rc.10"
27
27
  }
28
28
  }