@godspeedai/cognate-kernel-api

中文文档
0.10.0发布于 2026/11/16Apache-2.0ES Module零依赖构建来源已验证近 30 天下载 7115

Framework-owned kernel contract: contexts, scopes, capabilities, components, fibers, effects. No engine types.

原始使用文档
文档目录8 节
  1. Installation
  2. What's in the box
  3. Quick start
  4. Semantics the contract pins down
  5. Conformance kit for engine implementers
  6. Limitations
  7. Related packages
  8. License

@godspeedai/cognate-kernel-api

The framework-owned kernel contract for Cognate: components, scopes, capabilities, fibers, effects, and policy — as TypeScript types plus a few deterministic helpers. No engine code ships here.

When to use this package: you are authoring capability components or writing code that must type against the kernel, or you are implementing a kernel engine. Applications normally get it transitively through @godspeedai/cognate-runtime-bun or the @godspeedai/cognate umbrella.

Installation

bun add @godspeedai/cognate-kernel-api

Requires Bun >= 1.4.0.

What's in the box

  • Types — Kernel, Scope, Component, FiberContext, CapabilityLease, Effects, Policy, InvocationResult, and the rest of the kernel vocabulary.
  • isCompatible(requirement, contract) — deterministic capability eligibility: same capability id, same major version with minor/patch >= required, and every required attribute equal. No engine required.
  • Policies — denyAll (nothing is authorized unless you say so), rulePolicy(policyId, rules) (first matching rule decides, no match denies), and allowCapabilities(policyId, ids) for explicit allow-lists.
  • isUnavailable(value) — type guard distinguishing a failed resolution from a lease.
  • Typed errors — CleanupError, PermanentActivationError, ActivationTimeoutError, UndeclaredCapabilityError, ScopeClosedError.

Quick start

Declare a component that provides a capability, and pick a policy for its invocations:

import { allowCapabilities, isCompatible } from "@godspeedai/cognate-kernel-api";
import type { Component } from "@godspeedai/cognate-kernel-api";

const greeter: Component = {
  id: "greeter",
  provides: [{ id: "greet", version: "1.0.0" }],
  activate(fiber) {
    // Reversible effects, torn down in reverse order on disposal.
    fiber.effects.register(() => console.log("greeter cleaned up"));
    // Publish the capability; visible only after activation succeeds.
    fiber.provide({ id: "greet", version: "1.0.0" }, async (name: string) => ({
      hello: name,
    }));
  },
};

// Deterministic eligibility — computed locally, no engine involved:
isCompatible({ capability: "greet", version: "1.0.0" }, greeter.provides![0]!); // true

// Every invocation passes through a policy; anything not allowed is denied.
const policy = allowCapabilities("allow-greetings", ["greet"]);

Mounting components, resolving leases, and invoking capabilities need an engine: use @godspeedai/cognate-kernel-cordis or the runtime, which embed one.

Semantics the contract pins down

  • Resolution never consults policy; every invocation does, and the default is deny. Each decision is emitted as an invocation audit event through kernel.observe.
  • Invocation never throws: it returns an InvocationResult with a typed failure — unavailable, denied, deadline_exceeded, cancelled, or failed.
  • Activation is all-or-nothing: a failed activation disposes that attempt's effects in reverse order and publishes nothing.
  • Disposal is idempotent, runs every disposer in reverse order, and rejects once with CleanupError if any disposer failed.
  • A provided capability is visible in its scope and its descendants only; a child scope may narrow its principal but never gains authority by inheritance.

Conformance kit for engine implementers

If you implement KernelFactory, run the executable contract unchanged in your own test suite:

import { contractSuite } from "@godspeedai/cognate-kernel-api/conformance";
import { createCordisKernel } from "@godspeedai/cognate-kernel-cordis";

contractSuite("my-kernel", createCordisKernel);

The subpath exports six suites (contractSuite, lifecycleSuite, effectsSuite, dependenciesSuite, scopesSuite, authoritySuite) plus a fixtures namespace with ready-made principals, providers, and consumers for your own kernel tests.

Limitations

  • This package enforces nothing at runtime beyond the small helpers it exports: it does not mount components, match providers, or authorize calls. Pair it with an engine implementation.
  • The types are compile-time only; nothing validates your components against the contract until TypeScript checks them.

License

Apache-2.0

版本与发布记录

@godspeedai/cognate-kernel-api 共发布 20 个版本,首次发布于 2026/10/09;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/16今天
0.9.22026/11/152 天前
0.9.12026/11/143 天前
0.9.02026/11/0610 天前
0.8.02026/10/2720 天前
0.7.12026/10/2523 天前

关于 @godspeedai/cognate-kernel-api 的常见问题

@godspeedai/cognate-kernel-api 是什么?

Framework-owned kernel contract: contexts, scopes, capabilities, components, fibers, effects. No engine types.

如何安装 @godspeedai/cognate-kernel-api?

在项目目录运行 npm install @godspeedai/cognate-kernel-api,或使用 pnpm add / yarn add / bun add。

@godspeedai/cognate-kernel-api 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/godspeedai__cognate-kernel-api 是否存在。

@godspeedai/cognate-kernel-api 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@godspeedai/cognate-kernel-api 可以商用吗?

@godspeedai/cognate-kernel-api 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@godspeedai/cognate-kernel-api 的下载量有多少?

根据 npm 官方下载统计,@godspeedai/cognate-kernel-api 在 2026/10/17 – 2026/11/15 这 30 天内被下载 7,115 次,日均约 237 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@godspeedai/cognate-kernel-api 还在维护吗?

最新版本 0.10.0 发布于 2026/11/16(今天);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/10/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。