@earendil-works/pi-client

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

Transport-neutral client for remote pi sessions over framed CBOR bytes

原始使用文档

@earendil-works/pi-client

Transport-neutral client for the experimental Pi service protocol.

import { Client, type ByteTransportFactory } from "@earendil-works/pi-client";

const transportFactory: ByteTransportFactory = async (handlers) => {
  // Connect using WebSocket, Unix socket, or another ordered byte transport.
  return {
    async send(chunk) {
      // Deliver bytes in invocation order and honor backpressure.
    },
    close() {},
  };
};

const client = await Client.connect({
  serverId: "01234567-89ab-4def-8123-456789abcdef",
  transportFactory,
});
const result = await client.request(
  { serverId: client.hello.serverId },
  { serviceId: "example.service", member: "read", args: [] },
);

The client verifies that the physical endpoint reports the expected logical serverId. Server-wide requests carry that ID, and every Session request carries the full live target { serverId, sessionId, attachmentId }. The combined durable address prevents cross-server or cross-session misrouting; the server-generated attachment ID rejects delayed frames after switching or reattaching.

Typed server and Session APIs are provided by Chord service bindings owned by the application. createClientServiceTransport() adapts a lazily resolved server or Session route to a Chord transport; request() and subscribeService() remain its low-level primitives. The client uses Chord's service-control parsers and per-subscription state decoder; pi-protocol only validates the routed envelope and strict-JSON boundary. A service subscription returns a complete provider snapshot; the binding installs it and then calls start() to release updates buffered during hydration. Client applies ordered out-of-band attachment changes but deliberately does not construct typed service proxies or interpret application contracts.

Application observation APIs such as the coding agent's Transcript are ordinary Chord services. The client does not interpret their snapshots or updates.

On disconnect or disposal, pending requests reject locally, but accepted work may still complete remotely before the attachment is released. The client clears its live attachment route. It never reconnects or replays requests automatically. After disconnection, call reconnect(), attach through the application's management service again, and explicitly repeat only operations known to be safe.

The experimental local coordinator only provides a stable endpoint and relays traffic. Replaceable server processes own Session and worker lifecycle outside the public client protocol.

Call transport handlers as follows:

  • handlers.onData(chunk) for inbound bytes;
  • handlers.onClose() for an orderly terminal close;
  • handlers.onError(error) for transport failures.

A transport factory creates a fresh authenticated connection for each attempt. Requests are correlated by ID, and server failures are exposed as ServerError.

Unix-domain sockets

Node.js and Bun consumers can use the separate Unix transport:

import { Client } from "@earendil-works/pi-client";
import { createUnixTransportFactory } from "@earendil-works/pi-client/unix";

const client = new Client({
  serverId: "01234567-89ab-4def-8123-456789abcdef",
  transportFactory: createUnixTransportFactory({ path: "/tmp/pi.sock" }),
});
await client.connect();

Unix discovery scans an explicit physical-route directory, derives each expected server ID from its filename, and verifies it through the existing handshake:

import { discoverUnixServers } from "@earendil-works/pi-client/unix";

const routes = await discoverUnixServers({ directory: "/run/user/1000/pi" });
// [{ serverId: "...", path: "/run/user/1000/pi/<serverId>.sock" }]

Malformed entries, non-sockets, stale or unresponsive endpoints, and server-ID mismatches are ignored. Discovery is read-only and probes at most 16 sockets concurrently. Unexpected filesystem and socket errors reject discovery. Pass timeoutMs to override the default probe timeout.

ClientOptions.maxFrameLength bounds protocol payloads. maxPendingBytes bounds queued Unix transport output. Configure matching limits on both peers.

版本与发布记录

@earendil-works/pi-client 共发布 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-client 的常见问题

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

Transport-neutral client for remote pi sessions over framed CBOR bytes

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

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

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

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

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

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

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

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

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

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

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

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

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

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