@equationalapplications/core-okf

中文文档
8.4.0发布于 2026/11/13MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 8939

Zero-dependency Open Knowledge Format (OKF) v0.1 + v0.2 primitives: frontmatter serialization (with flow mappings / sequences), concept documents, index.md and log.md builders, trust-tier and staleness helpers.

原始使用文档
文档目录11 节
  1. Overview
  2. Installation
  3. API Reference
  4. serializeFrontmatter / parseFrontmatter
  5. buildConceptDocument / parseConcept
  6. buildIndexMd / buildRootIndexMd
  7. buildLogMd / parseLogMd
  8. deriveEventId
  9. extractMarkdownLinks
  10. Monorepo Ecosystem
  11. OKF v0.2 conformance

@equationalapplications/core-okf

npm version npm downloads

Overview

A zero-dependency library for parsing and producing Open Knowledge Format (OKF) v0.1 and v0.2 bundles. This package provides the raw primitives to work with OKF frontmatter, concept documents, and index/log files, completely decoupled from any specific database or data model.

For a ready-made MemoryDump ⇄ OKF bundle adapter, see the OKF guide for @equationalapplications/core-llm-wiki.

For the llm-wiki interoperability profiles (llm-wiki/1 and llm-wiki/2), see docs/okf-profile.md. Conformance fixtures live in fixtures/.

GraphRAG compatibility: core-okf is database-agnostic. The adapter that can populate llm_wiki_edges for traverseGraph() lives in @equationalapplications/core-llm-wiki. See GraphRAG guide.

Installation

npm install @equationalapplications/core-okf

API Reference

serializeFrontmatter / parseFrontmatter

Produces and parses YAML frontmatter for OKF concept documents.

const yaml = serializeFrontmatter({ type: 'fact', id: 'fact_123' });
const { frontmatter, rest } = parseFrontmatter(fileContent);

buildConceptDocument / parseConcept

Combines frontmatter and markdown body into a single string, or splits an existing OKF file into its component parts.

const markdown = buildConceptDocument({ type: 'task', id: 'task_1' }, '# Buy groceries');
const { frontmatter, body } = parseConcept(markdown);

buildIndexMd / buildRootIndexMd

Generates directory index lists or root OKF catalog manifests.

const sections = [{ heading: 'Facts', entries: [{ path: 'facts/fact_123.md', title: 'Fact 123' }] }];
const dirIndex = buildIndexMd(sections);
const rootIndex = buildRootIndexMd('0.1', sections);

buildLogMd / parseLogMd

Serializes chronological append-only events or parses them back into discrete entries.

const log = buildLogMd([{ date: '2026-06-23', text: 'Observation made' }]);
const events = parseLogMd(logContent);

deriveEventId

Computes the deterministic id an OKF consumer gives a log.md line that has no <!-- id: … --> comment (profile §7). The same line in the same entity always gets the same id, so importing the log again skips it while the earlier copy is stored.

const id = deriveEventId({
  entityId: 'demo',
  date: '2026-07-05',        // the heading text
  eventType: 'observation',
  summary: 'Linked to alpha',
  occurrence: 0,             // earlier id-less lines with the same date, type and summary
});
// 'evt_okf1_02dd42bf329719f258ab93b373f44506'

createEventIdDeriver({ entityId, date, eventType, summary }) returns (occurrence) => id with the same results, hashing the summary only once. Use it when you need many occurrences of one line.

Parses relative markdown cross-links to map knowledge graph edges.

const links = extractMarkdownLinks('See [preferences](facts/fact_abc.md) for more.');
// links: [{ text: 'preferences', path: 'facts/fact_abc.md' }]

Monorepo Ecosystem

PackagePurpose
@equationalapplications/core-llm-wikiPersistent episodic memory
@equationalapplications/expo-llm-wikiPersistent episodic memory for Expo/React Native
@equationalapplications/react-llm-wikiPersistent episodic memory for Web
@equationalapplications/prisma-outboxSync SQLite outbox events to Prisma
@equationalapplications/core-llm-toolsGemini tool schemas and capability injector
@equationalapplications/core-okfZero-dependency Open Knowledge Format (OKF) v0.1 + v0.2 primitives — parse and produce interoperable knowledge bundles.
@equationalapplications/schema-org-llm-wikiCurated schema.org warm-agent ontology manifest
@equationalapplications/schema-software-orgSoftware-organization executive ontology manifest — 17 node types, 40 edges, warm-agent superset, data-only
@equationalapplications/mcp-serverMCP server exposing SynapseTree memory tools to coding agents

OKF v0.2 conformance

This package conforms to OKF v0.2. New helpers for v0.2:

  • deriveTrustTier(verified) — derive 'unverified' | 'machine-confirmed' | 'human-reviewed'.
  • isStaleAfter(staleAfter, now) — staleness check against an absolute YYYY-MM-DD cutoff.
  • parseVerifiedFlexible(value) — accept either an array or a bare { by, at } mapping.
  • extractFootnotes(body) / serializeFootnotes(footnotes) — preserve footnote attribution verbatim.
  • parseFlowMapping(text) / parseFlowSequence(text) — flow parsing with at most one level of mapping-value nesting (no anchors/aliases outside quoted strings).

The serializeFrontmatter function emits plain objects as flow mappings and actor strings (containing / or :) via serializeActorString. Anchor/alias expansion is rejected; only unquoted & or * characters are treated as opaque (quoted spans are excluded from the scan, so URL query strings like "https://x/a?p=1&q=2" remain valid).

版本与发布记录

@equationalapplications/core-okf 共发布 84 个版本,首次发布于 2026/06/19;过去 12 个月发布了 84 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.4.0latest2026/11/131 天前
8.3.02026/11/131 天前
8.2.02026/11/122 天前
8.1.02026/11/122 天前
8.0.52026/11/112 天前
8.0.42026/11/112 天前

关于 @equationalapplications/core-okf 的常见问题

@equationalapplications/core-okf 是什么?

Zero-dependency Open Knowledge Format (OKF) v0.1 + v0.2 primitives: frontmatter serialization (with flow mappings / sequences), concept documents, index.md and log.md builders, trust-tier and staleness helpers.

如何安装 @equationalapplications/core-okf?

在项目目录运行 npm install @equationalapplications/core-okf,或使用 pnpm add / yarn add / bun add。

@equationalapplications/core-okf 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@equationalapplications/core-okf 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@equationalapplications/core-okf 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@equationalapplications/core-okf 可以商用吗?

@equationalapplications/core-okf 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@equationalapplications/core-okf 的下载量有多少?

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

@equationalapplications/core-okf 还在维护吗?

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