# @earendil-works/pi-protocol

> Transport-neutral CBOR protocol for remote pi sessions

Latest version **0.85.1** (published 2026-09-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @earendil-works/pi-protocol
pnpm add @earendil-works/pi-protocol
yarn add @earendil-works/pi-protocol
bun add @earendil-works/pi-protocol
```

## Health

**Score 85/100 (A)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score; popular repo; extremely popular.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.85.1 |
| Published | 2026-09-05 |
| First published | 2026-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.19.0 |
| Dependencies | 2 |
| Unpacked size | 138.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 104394 |
| Author | Earendil Works |
| Maintainers | mitsuhiko, badlogic, rwachtler |
| Keywords | pi, protocol, cbor, binary, framing |

## Links

- npm: https://www.npmjs.com/package/@earendil-works/pi-protocol
- Repository: https://github.com/earendil-works/pi
- Homepage: https://github.com/earendil-works/pi#readme
- Issues: https://github.com/earendil-works/pi/issues
- npm.io page: https://npm.io/package/@earendil-works/pi-protocol

## Dependencies (2)

- [typebox](https://npm.io/package/typebox.md) 1.3.7
- [@earendil-works/chord](https://npm.io/package/@earendil-works/chord.md) ^0.85.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.85.1 (latest) — 2026-09-05
- 0.85.0 — 2026-09-04
- 0.84.4 — 2026-08-28
- 0.84.3 — 2026-08-24
- 0.84.2 — 2026-08-14
- 0.84.1 — 2026-08-07
- 0.84.0 — 2026-08-06

## README

# @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 real `Session` and `AgentHarness` remain process-local. 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.

```ts
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.

---
_Source: https://npm.io/package/@earendil-works/pi-protocol · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
