@adrkit/core

中文文档
0.20.0发布于 2026/10/11Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 1.1万

Pure ADR parsing, validation, migration, and affects resolution for adrkit.

原始使用文档
文档目录5 节
  1. Building and rendering the decision graph
  2. Resolving decisions in both directions
  3. Marker scanning contract
  4. Filesystem boundaries
  5. Batch scans

@adrkit/core

Pure, deterministic building blocks for working with adrkit architecture decision records: parsing, schema validation, corpus invariants, MADR migration, graph construction, queue projection, and affects resolution.

npm install @adrkit/core      # or: bun add @adrkit/core
import { lintCorpus } from '@adrkit/core';

const findings = lintCorpus(records);

Building and rendering the decision graph

Graph construction, filtering, and serialization are pure and deterministic. The CLI owns TTY detection; core callers always select a concrete renderer.

import {
  buildAdrGraph,
  filterAdrGraph,
  renderDotGraph,
  renderJsonGraph,
  renderMermaidGraph,
} from '@adrkit/core';

const graph = buildAdrGraph(records);
const supersession = filterAdrGraph(graph, {
  focus: '0014',
  kinds: ['supersedes'],
});

const dot = renderDotGraph(supersession);
const mermaid = renderMermaidGraph(supersession);
const json = renderJsonGraph(supersession);

filterAdrGraph keeps the focus record, matching incident edges, and their endpoints. A kind-only filter drops unrelated isolated nodes. The JSON envelope remains { nodes, edges }; DOT and Mermaid add presentation without changing the graph model.

Resolving decisions in both directions

resolveAffects is the outbound edge: a record declares patterns, and paths are matched against them. resolveSourceMarkers is the inbound edge: a source file declares the decision it lives under with an @adr <id> marker in a comment.

import {
  mergeSourceDeclarations,
  readSourceMarkers,
  readSourceMarkersBatch,
  resolveAffects,
  resolveSourceMarkers,
  scanSourceMarkers,
  toGoverningDecisions,
} from '@adrkit/core';

const scan = await readSourceMarkers('src/services/sync/retry.ts');
const byMarker = resolveSourceMarkers({ records, markers: scan.markers });
const byPattern = resolveAffects({ records, changedFiles: ['src/services/sync/retry.ts'] });

const governedBy = mergeSourceDeclarations(
  toGoverningDecisions(records, byPattern.matches),
  records,
  byMarker.matches,
);

firedMatchers records what the ADR matched. declaredBy records what the file declared. Keeping them separate lets consumers distinguish "this record matched the path" from "this file opted into the record."

Marker scanning contract

scanSourceMarkers(source, path) is the pure half: text in, markers out, no filesystem. It scans only the first MARKER_HEADER_WINDOW_BYTES (8192) of the source, stops at the last complete line inside that window, and retains the first MARKER_DECLARATION_FILE_CAP (64) valid declarations in physical/source order. omittedMarkers reports the exact number beyond that cap without allocating a marker object for each one.

Markers must be the first content on a dedicated comment line. That keeps prose, string literals, and trailing inline comments from becoming declarations. Lines inside ``` or ~~~ fences are ignored. For markdown extensions (.md, .mdx, .markdown), the only accepted comment introducers are <!-- and {/*.

readSourceMarkers(path) adds a bounded filesystem read and reports state as scanned, absent, unreadable, or out-of-tree, so "found no markers" is never confused with "could not look." A scanned result includes scannedBytes and fileBytes for the observed scan extent.

If a file changes while it is being read, treat those byte counts as observations rather than strict arithmetic.

Filesystem boundaries

readSourceMarkers takes a repo-relative path from cwd.

  • Absolute paths are rejected as out-of-tree.
  • Paths that climb out of the working tree are out-of-tree.
  • Symlinks are refused as unreadable without opening their targets.
  • Non-regular files are also unreadable, so FIFOs and similar special files cannot block the read.

Batch scans

readSourceMarkersBatch(paths, cwd) is the impure boundary used by checkChanges. It normalizes, deduplicates, and sorts the input paths; scans the first 3,000 normalized paths with at most 16 reads in flight; and returns every skipped path. After the concurrent reads finish, it retains the first MARKER_DECLARATION_BATCH_CAP (10,000) declarations in code-unit path then physical/source order. The batch's declarations report gives exact total, retained, omitted, perFileOmitted, and batchOmitted counts.

Pass that SourceMarkerBatchScan through markerScans to get marker-aware decisions and a deterministic markerScan report without adding filesystem access to checkChanges. Declaration overflow produces one advisory marker-declarations-capped finding and never changes CheckOutcome.ok.

The published ESM artifacts run on Node.js 22 or newer. Development in the adrkit repository uses Bun.

See also @adrkit/mcp, a local read-only Model Context Protocol server that exposes the same corpus to coding agents.

Documentation: https://adrkit.dev

License: Apache-2.0

版本与发布记录

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

版本发布日期距今
0.20.0latest2026/10/1127 天前
0.19.02026/10/1127 天前
0.18.02026/10/1028 天前
0.17.02026/10/031 个月前
0.16.02026/10/011 个月前
0.15.02026/09/281 个月前

关于 @adrkit/core 的常见问题

@adrkit/core 是什么?

Pure ADR parsing, validation, migration, and affects resolution for adrkit.

如何安装 @adrkit/core?

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

@adrkit/core 支持 TypeScript 吗?

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

@adrkit/core 支持 ESM 还是 CommonJS?

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

@adrkit/core 需要什么版本的 Node.js?

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

@adrkit/core 可以商用吗?

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

@adrkit/core 的下载量有多少?

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

@adrkit/core 还在维护吗?

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