@godspeedai/cognate-kernel-cordis 0.1.1 → 0.1.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/README.md +99 -31
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,33 +1,101 @@
|
|
|
1
1
|
# @godspeedai/cognate-kernel-cordis
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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.
|
|
3
|
+
"version": "0.1.2",
|
|
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.
|
|
25
|
+
"@godspeedai/cognate-kernel-api": "^0.1.2",
|
|
26
26
|
"cordis": "4.0.0-rc.10"
|
|
27
27
|
}
|
|
28
28
|
}
|