@agenticprimitives/audit

中文文档
1.0.0-alpha.46发布于 2026/10/26MITTypeScriptES Module零依赖近 30 天下载 6896

Append-only audit event schema + sink interface. Transport-agnostic; consumers wire concrete sinks (console / D1 / Cloud Logging / etc.).

原始使用文档
文档目录6 节
  1. Quick start
  2. How it's different
  3. Boundaries
  4. Invariants
  5. Status
  6. Build

@agenticprimitives/audit

Part of Agentic Primitives — the open-source trust substrate for agentic applications: identity that can sign, authority checked at act time, evidence the owner carries. Developer kit · All packages

The append-only audit-event primitive for the agentic primitives stack — because in the agent economy, "who authorized what, under which limits, provable to whom?" is a question your logs have to answer, not your incident retro.

Most teams bolt logging onto agent infrastructure after the fact: a console transport here, a SIEM shipper there, each component naming actors its own way. The result is telemetry, not evidence. This package inverts that: one canonical AuditEvent schema that every package in the substrate emits — delegation mints, custody changes, key operations, tool calls — so the trail speaks the same identity language as the system it observes. The actor in an audit event is the same canonical Smart Agent address that signed the delegation; the evidence chain and the authority chain are one chain.

It closes system-audit finding C3 (forensic trail) from docs/architecture/product-readiness-audit.md, and it sits at the base of the dependency graph alongside types — everything imports it, it imports (almost) nothing.

Part of agenticprimitives — the trust substrate for the agent economy: one canonical Smart Agent identity with custody, delegation, naming, credentials, and audit evidence designed as one system.

See spec.md → specs/206-audit.md.

Quick start

import {
  buildEvent,
  createConsoleAuditSink,
  composeSinks,
  type AuditSink,
} from '@agenticprimitives/audit';

const sink: AuditSink = composeSinks(
  createConsoleAuditSink({ prefix: '[AUDIT]' }),
  // ...add a persistent sink from your app layer (D1, Postgres, etc.)
);

await sink.write(
  buildEvent({
    action: 'delegation.verify.accept',
    outcome: 'success',
    actor:   { type: 'agent', id: 'demo-a2a' },
    subject: { type: 'jti', id: claims.jti },
    audience: claims.aud,
    correlationId,
  }),
);

Beyond the basics: a canonical action registry (AUDIT_ACTION_REGISTRY), a createPiiGuardrailSink wrapper that scrubs secrets defense-in-depth, lightweight MetricsSink counters, and two composition contracts picked per event class — composeFailSoftSinks absorbs transient failures for telemetry-grade events, while composeFailHardSinks throws on first failure so security-critical flows (delegation mint/revoke, custody changes, key operations) refuse to commit if the evidence didn't persist.

How it's different

  • vs. OpenZeppelin Defender / Tenderly: those monitor contracts — transactions and on-chain state. This trail captures the off-chain authority decisions that precede them (delegation verified, scope checked, quorum reached, tool invoked), bound to the same canonical identity and delegation chain the contracts enforce. You get the why behind the transaction, not just the transaction.
  • vs. custom logging: ad-hoc logs have no shared schema, no append-only contract, and no fail-hard option — an attacker (or a bug) that suppresses the log still gets the action committed. Here the sink interface has write and nothing else, and security-critical emitters can make persistence a precondition.
  • The substrate effect: because every package emits the same schema, one query correlates a sign-in, the delegation it minted, the MCP tool call it authorized, and the spend it produced — across packages, by correlationId and canonical address. Stitched stacks cannot produce that join.

Boundaries

  • Ships in-band sinks only (console + memory + compositions + PII guardrail). Concrete persistent sinks (D1, Postgres, Cloud Logging, SIEM) live in consumer apps behind the single AuditSink interface.
  • Sits at the base of the dep graph alongside @agenticprimitives/types. Forbidden from importing connect-auth / agent-account / delegation / key-custody / tool-policy / mcp-runtime — those import us. Events carry IDs and strings, never domain objects.

Invariants

  • No secret material in events. Emitters hash sessionIds, omit raw keys / tokens. createPiiGuardrailSink is defense-in-depth, not the primary control.
  • Append-only by interface. AuditSink has write only — no delete / update. Persistent sinks must enforce immutability at the schema level.
  • Fail-soft for telemetry, fail-hard for security. Routine emit failures never throw to the caller; security-critical events use composeFailHardSinks so the trail persists or the flow refuses to commit.

Status

Alpha track — testnet-only. Schema versioned (schemaVersion: 1); bumps are major. Do not deploy to production until the gates listed in the root README.md Status section are cleared. Every security finding is tracked live in docs/audits/findings.yaml.

Build

pnpm --filter @agenticprimitives/audit typecheck
pnpm --filter @agenticprimitives/audit test
pnpm --filter @agenticprimitives/audit build

版本与发布记录

@agenticprimitives/audit 共发布 45 个版本,首次发布于 2026/06/01;过去 12 个月发布了 45 个版本。

版本发布日期距今
1.0.0-alpha.46latest2026/10/2610 天前
1.0.0-alpha.452026/10/2610 天前
1.0.0-alpha.442026/10/1720 天前
1.0.0-alpha.432026/10/1720 天前
1.0.0-alpha.422026/10/1620 天前
1.0.0-alpha.412026/10/1620 天前

其他发布通道:alpha → 0.1.0-alpha.2。

关于 @agenticprimitives/audit 的常见问题

@agenticprimitives/audit 是什么?

Append-only audit event schema + sink interface. Transport-agnostic; consumers wire concrete sinks (console / D1 / Cloud Logging / etc.).

如何安装 @agenticprimitives/audit?

在项目目录运行 npm install @agenticprimitives/audit,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@agenticprimitives/types(^1.0.0-alpha.46)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@agenticprimitives/audit 支持 TypeScript 吗?

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

@agenticprimitives/audit 支持 ESM 还是 CommonJS?

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

@agenticprimitives/audit 可以商用吗?

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

@agenticprimitives/audit 的下载量有多少?

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

@agenticprimitives/audit 还在维护吗?

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