@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.
loadSemanticProjectionreturns aLoadResult; parse failures are classified by message shape intosyntax,unresolved_reference,ambiguous_identity,binding_unavailable, orunknown. - 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 asambiguous_identityinstead of a silent merge. - Capability gating.
bindCapabilitiesthrows on an unknown semantic id and refuses to bindPolicyobjects — policies are referenced constraints, never capabilities. Unbound objects produce nothing: no implicit capabilities. - A mapping table.
mappingTablerecords, for every DomainForge kind, whether it is supported, its framework view, meaning, cardinality, and source accessor.Externalis 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/domainforge0.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
unknownwith its text rather than misclassified.
Related packages
@godspeedai/domainforge— the independent DomainForge parser this adapter wraps (kept at its own version, pinned here).@godspeedai/cognate-kernel-api—SemanticRefandCapabilityContracttypes the projection produces.@godspeedai/cognate-runtime-bun— the reference runtime that invokes bound capabilities.@godspeedai/cognate— the SDK umbrella.
License
Apache-2.0