@earendil-works/pi-protocol

中文文档
1.1.0发布于 2026/10/08MITTypeScriptES Module构建来源已验证近 30 天下载 255.9万

Transport-neutral CBOR protocol for remote pi sessions

原始使用文档

@earendil-works/pi-protocol

Runtime-neutral routed envelopes, CBOR encoding, and byte-stream framing for the experimental Pi protocol.

Protocol version 8 defines:

  • a version handshake that identifies the logical serverId;
  • explicit server and Session request targets;
  • correlated requests and responses with opaque strict-JSON payloads;
  • request cancellation, opaque subscription updates, and out-of-band attachment changes;
  • non-empty opaque error codes and bounded transport messages.

A server target contains { serverId }; a Session target contains { serverId, sessionId, attachmentId }. The combined route fences calls to one logical server, durable Session, and live presentation attachment. Management attach() and detach() return no routing identifiers; the server publishes the selected live route in an out-of-band attachment message. Disconnecting releases only that presentation's attachment after admitted calls settle.

Chord owns the payload semantics carried inside these envelopes: { serviceId, instance?, member, args } calls, the $chord.service control vocabulary, service catalogues, subscription snapshots and updates, service error codes, and the independent Delta path codecs for replicated states. pi-protocol validates that each opaque payload is strict JSON but does not validate or export its Chord grammar. Clients and servers parse those values through @earendil-works/chord at the service adapter boundary.

Session-directory state, management results, transcripts, models, plugins, and all other application values remain opaque service data. The durable Session and its Harness remain local to the Session worker process. Server and Session calls route opaquely to their owning providers, where Chord and the application validate and invoke them.

Server and worker lifecycle is intentionally outside this public protocol. The experimental local coordinator is only an opaque message router; each replaceable server process owns the private lifecycle protocol.

Each wire frame consists of a four-byte unsigned big-endian payload length followed by one definite-length CBOR item. encodeClientMessage() and encodeServerMessage() validate and encode complete frames. ClientMessageDecoder and ServerMessageDecoder accept arbitrary stream fragmentation and coalescing.

import {
  PROTOCOL_VERSION,
  encodeClientMessage,
  ServerMessageDecoder,
  type ClientHello,
} from "@earendil-works/pi-protocol";

const hello: ClientHello = { type: "hello", version: PROTOCOL_VERSION };
transport.send(encodeClientMessage(hello));

const decoder = new ServerMessageDecoder({ maxFrameLength: 1024 * 1024 });
for (const message of decoder.push(incomingChunk)) handleServerMessage(message);
decoder.end();

All envelope schemas reject unknown object properties, and codecs recursively reject non-JSON opaque payloads, including non-finite numbers, byte arrays, undefined, prototypes, and cycles. Envelope violations, malformed CBOR, and invalid framing throw ProtocolValidationError. Payload-specific adapters must perform their own semantic validation after decoding. Transports must preserve byte order. Peer authentication and authenticated service contexts are not implemented by the experimental transport.

Default limits are 16 MiB per CBOR payload/frame, 1,000,000 array elements or map entries, and 64 nested item levels. The protocol is experimental and has no compatibility guarantees.

版本与发布记录

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

版本发布日期距今
1.1.0latest2026/10/081 个月前
1.0.42026/10/061 个月前
1.0.32026/10/051 个月前
1.0.22026/10/041 个月前
1.0.12026/10/031 个月前
1.0.02026/10/021 个月前

关于 @earendil-works/pi-protocol 的常见问题

@earendil-works/pi-protocol 是什么?

Transport-neutral CBOR protocol for remote pi sessions

如何安装 @earendil-works/pi-protocol?

在项目目录运行 npm install @earendil-works/pi-protocol,或使用 pnpm add / yarn add / bun add。

@earendil-works/pi-protocol 支持 TypeScript 吗?

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

@earendil-works/pi-protocol 支持 ESM 还是 CommonJS?

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

@earendil-works/pi-protocol 需要什么版本的 Node.js?

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

@earendil-works/pi-protocol 可以商用吗?

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

@earendil-works/pi-protocol 的下载量有多少?

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

@earendil-works/pi-protocol 还在维护吗?

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