@adlc/build-gate

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

Machine-checkable fitness-to-build gate — denies starting a high-risk P4 build in a degraded (context-rot) session unless an audited override is recorded (C13).

原始使用文档
文档目录9 节
  1. ADLC Phase
  2. Usage
  3. Flags
  4. Exit codes
  5. Risk tier
  6. Context-fitness signal
  7. Audited override
  8. Toolkit modules (Path A — reusable by any harness)
  9. Claude Code integration (Path B — self-enforcing)

build-gate

Machine-checkable fitness-to-build gate (ADLC C13 — issue #48).

Nothing else in ADLC deterministically prevents starting a high-blast-radius ticket's build (P4) when the executing session's context is degraded ("context rot"). build-gate closes that gap: it derives a ticket's risk tier, checks a machine-checkable context-fitness signal, and denies the build unless an audited override is recorded.

ADLC Phase

P3 → P4 entry gate. Sits between rail-freeze (P3) and supervised build execution (P4). Guards one invariant: a high-risk ticket must not begin its build in a degraded session.

Usage

build-gate <ticket-id> [--depth <n>] [--session-bytes <n>] [--transcript <path>]
           [--depth-threshold <n>] [--bytes-threshold <n>] [--tickets <path>]
           [--reason <text>] [--json]

Flags

FlagDefaultDescription
<ticket-id>—Ticket to gate (required)
--depth <n>—Precomputed tool-call-count depth signal
--session-bytes <n>—Precomputed transcript byte-size signal
--transcript <path>—Derive depth/session-bytes from this transcript file
--depth-threshold <n>40Tool-call count past which a session is "degraded"
--bytes-threshold <n>8388608 (8 MiB)Transcript bytes past which a session is "degraded"
--tickets <path>.adlc/tickets.jsonPath to tickets file
--reason <text>—Free-text reason recorded with an override
--jsonoffEmit machine-readable JSON result
--help—Print this help and exit 0

The library export DEFAULT_BYTES_THRESHOLD (lib/depth-signal.mjs) remains HARD_BYTES (256 KiB) by design, so the two numbers are not expected to agree: this binary's flag default is the recalibrated operating threshold.

A CLI process can't observe its own caller's context state — the caller (a hook, CI wrapper, or any harness) must supply the signal via --depth/ --session-bytes, or point --transcript at a transcript file to derive it from. Supplying neither defaults the signal to "not degraded" — a gate given no signal cannot deny.

Exit codes

0  allow (gate passes)
1  operational error (bad ticket id, missing tickets file, bad thresholds)
2  deny (gate fails)

Risk tier

A ticket is high risk if it declares "risk": "high", OR any of these derived signals fire from fields already on the ticket:

  • external: true — writes back to / creates / deletes in an external system
  • mutatesIdentity: true — mutates identity
  • scope/rails glob-matches .adlc/manifest.jsonl — mutates the gate-evidence ledger
  • scope/rails glob-matches .adlc/tickets.json or .adlc/current-ticket.json — touches the trust root
  • category is contract or architecture

A declared "risk": "normal" can never downgrade a derived-high signal — that would be a silent, undetectable way to defeat the gate.

Context-fitness signal

A proxy for "this session is deep," mirroring @adlc/flail-detector's existing transcript-size / tool-call-count scanning approach: a tool-call-count (--depth) and a transcript byte count (--session-bytes), each compared to a threshold. Either signal past its threshold means the session is degraded.

Audited override

Set ADLC_BUILD_GATE_BYPASS=1 to deliberately override a deny (mirrors the ADLC_RAILS_BYPASS pattern used by rails-guard). The override is only honored if it can be durably recorded to .adlc/manifest.jsonl as a build-gate-bypass entry — an override that cannot be recorded is refused, never silently allowed.

Toolkit modules (Path A — reusable by any harness)

  • lib/risk.mjs — computeRiskTier(ticket) / deriveRiskSignals(ticket)
  • lib/depth-signal.mjs — computeDepthSignal({ text, bytes }) / isDegraded({...}) (absolute hard band via @adlc/context-handoff isHardDegraded; inclusive >= at HARD_DEPTH / HARD_BYTES)
  • lib/decide.mjs — decideBuildGate({ riskTier, degraded, bypass, recordBypass })
  • lib/override.mjs — recordOverride({...})
  • lib/active-ticket.mjs — resolveActiveTicketId({ dir, env }), the shared ADLC_TICKET env var / .adlc/current-ticket.json convention already used by every other harness integration (codex, opencode, cursor, antigravity)

Claude Code integration (Path B — self-enforcing)

plugins/adlc-claude-code/hooks/adlc-hook.mjs's buildgate PreToolUse mode supplies the in-session context signal (the same transcript-window staging the flail mode already does) and computes the risk tier, context-fitness signal, and allow/deny decision entirely locally — verbatim ports of this package's lib/risk.mjs / lib/depth-signal.mjs / lib/decide.mjs logic, marked "KEEP IN SYNC" in the hook source. It does not shell out to adlc build-gate for the decision; adlc (via gate-manifest) is invoked only to durably record an audited override, mirroring how rails never needs adlc for its own core decision either. See docs/specs/build-gate-fitness.md, including its Known limitations section (unreadable-transcript fail-closed behavior, and the unprotected .adlc/current-ticket.json pointer as a Bash-reachable, CI-unbackstopped escape hatch).

版本与发布记录

@adlc/build-gate 共发布 15 个版本,首次发布于 2026/07/11;过去 12 个月发布了 15 个版本。最新版本附带 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/build-gate 的常见问题

@adlc/build-gate 是什么?

Machine-checkable fitness-to-build gate — denies starting a high-risk P4 build in a degraded (context-rot) session unless an audited override is recorded (C13).

如何安装 @adlc/build-gate?

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

@adlc/build-gate 支持 TypeScript 吗?

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

@adlc/build-gate 支持 ESM 还是 CommonJS?

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

@adlc/build-gate 需要什么版本的 Node.js?

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

@adlc/build-gate 可以商用吗?

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

@adlc/build-gate 的下载量有多少?

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

@adlc/build-gate 还在维护吗?

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