@adlc/behavior-diff

中文文档
1.12.0发布于 2026/10/10MITES Module构建来源已验证近 30 天下载 8227

Behavior-space diff for the P6 human gate — review what changed in behavior, not 5,000-line diffs.

原始使用文档
文档目录8 节
  1. ADLC phase
  2. Verbs
  3. capture
  4. compare
  5. Typical workflow
  6. Snapshot format
  7. Future work (noted in spec)
  8. Core gaps

behavior-diff — ADLC C14

Behavior-space diff for the P6 human gate. Review what changed in behavior, not 5,000-line diffs. Captures observable HTTP surface (status, content-type, body structure) before and after a change, then diffs in behavior-space: "3 endpoints changed shape, 1 removed, everything else identical."

The code diff is 5,000 lines; the behavior diff is six items. The human reviews intent vs behavior — the one judgment machines cannot make — while the manifest (C11) proves the machines already did the rest.


ADLC phase

P6 — Human Gate. Consumed directly by the human reviewer during the gate step. Pairs with gate-manifest (C11): manifest proves machine checks passed; behavior-diff proves observable behavior is within expected bounds.


Verbs

capture

Hit each route in a config file and record the observable HTTP behavior to a JSON snapshot.

behavior-diff capture --config behavior.json --out before.json

Flags:

FlagRequiredDescription
--config <path>yesPath to the behavior config JSON file
--out <path>yesOutput path for the snapshot JSON
--jsonnoPrint machine-readable result summary to stdout

Config format (behavior.json):

{
  "baseUrl": "http://localhost:3000",
  "routes": [
    { "method": "GET", "path": "/health" },
    { "method": "GET", "path": "/api/users" },
    { "method": "POST", "path": "/api/items", "body": { "name": "test" } },
    { "method": "GET", "path": "/api/data", "headers": { "Accept": "application/json" } }
  ]
}

Each route: { method, path, body?, headers? }. body is serialized as JSON with Content-Type: application/json automatically added.

Per-route errors are recorded (as { method, path, error }) without aborting the run. The snapshot always contains an entry for every route in the config.

Exit codes for capture:

CodeMeaning
0All routes attempted and at least one reachable; snapshot written (some routes may have errored)
1Operational error: config file unreadable, invalid config, cannot write output

compare

Compare two snapshots and produce a human-readable behavior report.

behavior-diff compare before.json after.json [--json]

Flags:

FlagRequiredDescription
--jsonnoPrint machine-readable diff result to stdout

Output (human-readable):

2 routes identical, 2 changed, 0 errored

  + GET /metrics: route added (absent in before, present in after)
  ~ GET /health:
      body (json): 2 changes:
        ~ version: "1.0.0" → "2.0.0"
        + newField: "added"
  ~ GET /users:
      status: 200 → 503
      body (json): 2 changes:
        - users: [...]
        + error: "Service Unavailable"

Diff rules:

  • Routes matched by METHOD path.
  • Status change: reported directly.
  • Content-type change: reported (parameters like ; charset=utf-8 stripped for comparison).
  • JSON bodies: structural recursive diff. Paths use dot notation (body.items[3].price). Arrays: length change reported + first divergent index drilled. Capped at 50 paths.
  • Text/binary bodies: compared by SHA-256 hash.
  • Route only in before → "removed". Route only in after → "added".

Exit codes for compare:

CodeMeaning
0Gate passes — all routes identical
1Operational error: snapshot file unreadable or invalid JSON
2Gate fails — one or more routes changed, removed, or added

Typical workflow

# Before the change: capture baseline
behavior-diff capture --config behavior.json --out before.json

# Make your code change, restart the service, then:
behavior-diff capture --config behavior.json --out after.json

# Review behavior diff (exits 0 if clean, 2 if changes found)
behavior-diff compare before.json after.json

Snapshot format

{
  "baseUrl": "http://localhost:3000",
  "capturedAt": "2024-01-15T10:30:00.000Z",
  "routes": [
    {
      "method": "GET",
      "path": "/health",
      "status": 200,
      "contentType": "application/json",
      "body": { "status": "ok" }
    },
    {
      "method": "GET",
      "path": "/large-html",
      "status": 200,
      "contentType": "text/html",
      "body": { "textHash": "sha256hex...", "bytes": 4096 }
    },
    {
      "method": "GET",
      "path": "/broken",
      "error": "timeout after 10000ms"
    }
  ]
}
  • JSON responses: body is parsed and stored as a JSON value.
  • Non-JSON responses: body stored as { textHash, bytes }.
  • Errors: route stored as { method, path, error } (no status/body).

Future work (noted in spec)

Browser/headless mode — render routes via headless browser and diff rendered DOM or screenshots. Documented as future work; not yet implemented. HTTP fixture mode (this tool) is the current supported mode.


Core gaps

None. This tool is self-contained and uses only parseArgs, pass, gateFail, opError, and printJson from @adlc/core. Hashing is done locally via node:crypto rather than the core sha256 helper to avoid coupling the capture serialization format to a shared library.

版本与发布记录

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

版本发布日期距今
1.12.0latest2026/10/1027 天前
1.11.12026/09/091 个月前
1.11.02026/08/252 个月前
1.10.02026/08/112 个月前
1.9.02026/08/092 个月前
1.8.02026/08/082 个月前

关于 @adlc/behavior-diff 的常见问题

@adlc/behavior-diff 是什么?

Behavior-space diff for the P6 human gate — review what changed in behavior, not 5,000-line diffs.

如何安装 @adlc/behavior-diff?

在项目目录运行 npm install @adlc/behavior-diff,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 behavior-diff,可以用 npx behavior-diff 直接运行。

@adlc/behavior-diff 支持 TypeScript 吗?

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

@adlc/behavior-diff 支持 ESM 还是 CommonJS?

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

@adlc/behavior-diff 需要什么版本的 Node.js?

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

@adlc/behavior-diff 可以商用吗?

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

@adlc/behavior-diff 的下载量有多少?

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

@adlc/behavior-diff 还在维护吗?

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