@godspeedai/cognate-domainforge

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

Version-pinned adapter from DomainForge Graph output to Cognate SemanticRefs and read-only semantic projections (spec §7.1, §19).

原始使用文档
文档目录7 节
  1. Installation
  2. Quick start
  3. What the adapter adds over the parser
  4. Composed-world integration
  5. Limitations
  6. Related packages
  7. License

@godspeedai/cognate-domainforge

Turn DomainForge domain models into Cognate semantic objects and capabilities. This package is a version-pinned adapter around the external @godspeedai/domainforge npm package (pinned to 0.22.2), which parses the .sea domain language into a graph of entities, resources, flows, relations, policies, and metrics. The adapter converts that graph into Cognate SemanticRefs and a read-only SemanticProjection, and is the only supported path from a domain model to Cognate capability contracts.

When to use this package: you model your domain in .sea and want your Cognate application's capabilities to carry verifiable provenance — every semantic object traceable to a digest of the exact source it came from, with renames never silently re-resolved.

Installation

bun add @godspeedai/cognate-domainforge

Requires Bun >= 1.4.0. The external parser @godspeedai/domainforge at 0.22.2 is installed automatically as a pinned regular dependency; it performs the actual .sea parsing (including its native binding). The SDK ships Bun-native TypeScript source, so add @types/bun and @types/node as dev dependencies when typechecking your project.

Quick start

import {
  bindCapabilities,
  loadSemanticProjection,
  SemanticRegistry,
  serializeProjection,
} from "@godspeedai/cognate-domainforge";

const source = `
Entity "Warehouse" in logistics
Entity "Factory" in manufacturing
Resource "Cameras" units in equipment
Flow "Cameras" from "Warehouse" to "Factory" quantity 10
`;

const result = loadSemanticProjection(source, { uri: "file:///domain/logistics.sea" });
if (!result.ok) {
  // Never throws: failures come back typed as one of
  // "syntax" | "unresolved_reference" | "ambiguous_identity" | "binding_unavailable" | "unknown"
  console.error(result.error.kind, result.error);
} else {
  const projection = result.projection;
  projection.objects.map((o) => o.ref.id);
  // ["logistics::Warehouse", "manufacturing::Factory", "equipment::Cameras",
  //  "equipment::flow(equipment::Cameras|logistics::Warehouse|manufacturing::Factory)"]
  console.log(projection.source.digest); // sha256 of the exact source text

  // Canonical, deterministic serialization (stable key order) for storage or diffing:
  const canonical = serializeProjection(projection);

  // Resolve historical refs against exactly the projection they came from:
  const registry = new SemanticRegistry();
  registry.register(projection);
  const resolution = registry.resolve(projection.objects[0]!.ref);
  // { kind: "resolved", object, projection } — or { kind: "unresolved", ref, reason }
  // A rename does not resolve to the same-named object unless you record an explicit,
  // reviewed alias: registry.alias(oldRef, newRef, { reviewedBy: "...", meaningCheck: "..." });

  // The only path from a semantic object to a capability contract:
  const contracts = bindCapabilities(projection, [
    { semanticId: "logistics::Warehouse", capability: { id: "logistics.warehouse", version: "1.0.0", attributes: {} } },
  ]);
  contracts[0]!.semanticRef; // the provenance attached to the capability
}

What the adapter adds over the parser

  • Typed, never-throwing loads. loadSemanticProjection returns a LoadResult; parse failures are classified by message shape into syntax, unresolved_reference, ambiguous_identity, binding_unavailable, or unknown.
  • Stable identity. Objects are identified as namespace::name. Flows get a deterministic derived id (namespace::flow(resource|from|to)) because the underlying parser assigns flows a fresh random id on every parse; a computed-id collision surfaces as ambiguous_identity instead of a silent merge.
  • Capability gating. bindCapabilities throws on an unknown semantic id and refuses to bind Policy objects — policies are referenced constraints, never capabilities. Unbound objects produce nothing: no implicit capabilities.
  • A mapping table. mappingTable records, for every DomainForge kind, whether it is supported, its framework view, meaning, cardinality, and source accessor. External is the one unmappable kind (it has no graph declaration).

Composed-world integration

With DomainForge 0.22.2, loadSemanticWorld({ entry, sources, worldName }) resolves the complete canonical import closure through Graph.parseSourceMap, returns the verified root worldRef and DomainModelIdentity, and creates refs pinned to the resolved world. Use this API rather than parsing individual imported files. See docs/how-to/load-a-composed-semantic-world.md.

Limitations

  • Pinned to @godspeedai/domainforge 0.22.2. The projection records which binding produced it; newer parser versions require a deliberate adapter upgrade, not an accidental drift.
  • Projections are read-only data. Nothing here executes models, enforces policies, or grants permissions — it makes semantics referenceable.
  • Error classification matches the parser's human-readable messages; an unrecognized failure is reported as unknown with its text rather than misclassified.

License

Apache-2.0

版本与发布记录

@godspeedai/cognate-domainforge 共发布 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-domainforge 的常见问题

@godspeedai/cognate-domainforge 是什么?

Version-pinned adapter from DomainForge Graph output to Cognate SemanticRefs and read-only semantic projections (spec §7.1, §19).

如何安装 @godspeedai/cognate-domainforge?

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

@godspeedai/cognate-domainforge 支持 TypeScript 吗?

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

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

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

@godspeedai/cognate-domainforge 可以商用吗?

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

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

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

@godspeedai/cognate-domainforge 还在维护吗?

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