@cero-base/tools

中文文档
2.12.0发布于 2026/11/09Apache-2.0TypeScriptES Module近 30 天下载 1807

Passive devtools for cero — observe data, events, and p2p/replication stats over a local out-of-band pipe.

原始使用文档
文档目录8 节
  1. Install
  2. Agent side — attach the tap
  3. Consumer side — connect
  4. CLI
  5. Redaction
  6. API
  7. Status
  8. License

@cero-base/tools

Passive devtools for cero — observe a running instance's data, its event log, and its p2p/replication stats from another process, without ever touching the swarm it measures.

A devtools() extension taps the instance over a local out-of-band pipe (never the app's hyperswarm), so connection counts, core lengths, and replication numbers stay exactly as they'd be with no devtools attached. Read-only by construction; identity secrets are structurally unreachable.

Install

npm install @cero-base/tools

Agent side — attach the tap

import { cero } from '@cero-base/cero'
import { devtools, loopback } from '@cero-base/tools'

const me = await cero('./data', spec, {
  extensions: [...spec.extensions, devtools({ transport: loopback({ port: 9111 }) })]
})
// ...then create your instance as usual; the tap follows it and every child handle.

devtools(opts):

optdefaultmeaning
transport—a { accept(handler) } source of consumer connections (use loopback({ port }))
bufferSize1000event ring buffer size (drop-oldest)
sampleInterval1000stats sampling interval (ms)
redact—a (ref, row) => row masker, or a config { fields, match, deny } (see Redaction)
tokenrandomauth token gating the tap — printed in the startup banner; false disables the gate

Zero footprint when not registered; all cleanup is bound to the root handle's close.

Any local process can dial the loopback port, so the tap requires a per-run token: the first frame of a connection must carry it or the connection is dropped. The banner prints the exact cero-tools <port> --token <token> command. Keep devtools out of production builds regardless — the tap is a development tool.

Consumer side — connect

import { connect, dial } from '@cero-base/tools'

const session = await connect(dial({ port: 9111 }))

await session.handles() // [{ id, type }, ...] — root + open children
await session.get('messages') // { data, total, size } — reuses cero's read operators
session.watch('messages') // Readable of live snapshots
session.events() // Readable of { op, name, row, writerKey, seq } — local AND remote
session.stats() // Readable of { network, bee, cores }
session.close()

CLI

cero-tools <port> --token <token> [refs...]
# prints the handle tree + state for each ref, then tails events + stats until Ctrl-C

Redaction

App rows can hold anything, so devtools({ redact }) masks matched fields in both snapshots and events — content hidden, shape kept (‹redacted:bytes(32)›):

devtools({ redact: {} }) // default denylist: seed/secret/token/private/...
devtools({ redact: { fields: ['profile.apiKey'] } })
devtools({ redact: { match: (key) => key.endsWith('Secret') } })

The default is a denylist by field name — a secret stored under an off-list name (otp, recoveryCode, …) transits unmasked. Add such fields via fields/match, or pass your own (ref, row) => row masker for allowlist semantics.

Identity credentials (the seed and keypairs) need no redaction: they're local builtins and the inspection surface only serves declared meta.refs, so they're never reachable.

API

devtools(opts) · serve(stream, me, opts) · connect(stream) · stats(handle) · redact(config) · loopback(opts) · dial(opts)

Status

MVP: local-pipe transport, get/watch + events + sampled stats, redaction, a CLI. Deferred to later phases: a whitelisted swarm transport, a read-only replication / time-travel plane, and an MCP/UI consumer.

License

Apache-2.0

版本与发布记录

@cero-base/tools 共发布 66 个版本,首次发布于 2026/06/01;过去 12 个月发布了 66 个版本。

版本发布日期距今
2.12.0latest2026/11/09今天
2.11.02026/11/09今天
2.10.02026/11/027 天前
2.9.02026/10/3010 天前
2.8.02026/10/3011 天前
2.7.02026/10/2713 天前

关于 @cero-base/tools 的常见问题

@cero-base/tools 是什么?

Passive devtools for cero — observe data, events, and p2p/replication stats over a local out-of-band pipe.

如何安装 @cero-base/tools?

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

@cero-base/tools 支持 TypeScript 吗?

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

@cero-base/tools 支持 ESM 还是 CommonJS?

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

@cero-base/tools 需要什么版本的 Node.js?

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

@cero-base/tools 可以商用吗?

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

@cero-base/tools 的下载量有多少?

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

@cero-base/tools 还在维护吗?

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