capnweb RPC Patterns
Applies capnweb stub lifecycle and disposal rules across RPC boundaries.
Install
npx skills add cloudflare/computer --skill capnweb -g -a claude-code -y- Repository
- cloudflare/computer9.8k
- Category
- Engineering
- Updated
- 6d ago
- License
- MIT
- Context cost
- Mediumabout 2,531 tokens
- Runs scripts
- No, instructions only
What it does
capnweb RPC patterns for this repo, with a heavy focus on stub lifecycle and disposal. Load when touching anything that crosses the Durable Object ↔ computerd boundary: packages/rpc, packages/computer, the computerd client, or the Durable Object server. Triggers include "capnweb", "RpcTarget", "stub", "RPC wire", "promise pipelining", "stub disposal", "RpcPromise".
capnweb in this repo
capnweb is the RPC framing
between the Durable Object and computerd. It's an object-capability RPC
system with promise pipelining, structured-clone-style transfer of
stubs, and bidirectional calls. The wire format used here is text
JSON over a long-lived WebSocket. That is the only carrier: capnweb's
HTTP batch transport cannot deliver a stream returned from a call,
which is what every read on this interface is.
Where things live
packages/rpc/src/interface.ts, typed wire surface.WorkspaceRPCis the root stub and composesSyncRPCandShellRPC. Add new methods here first.packages/rpc/src/server.ts,Database-backed implementation. Imported by the Durable Object and the in-container computerd.packages/rpc/src/client.ts, typed stubs over a WebSocket carrier. The Durable Object uses a deferred transport so the stub can be created before the upgrade completes.packages/rpc/src/sync-driver.ts,pullOnce,pushOnce,tick. These wrap streaming methods and handle disposal internally.packages/rpc/src/debug.ts,enableStubTracking,stubSnapshotfor leak hunting.docs/08_capnweb_interface.md, design intent for the wire.docs/11_lifecycle.md, the repo's stub disposal contract.
