Channels
Channels are the transport layer in cmd-ipc. They abstract the underlying communication mechanism so the same command API works over Web Workers, HTTP, MCP, in-memory pipes, or anything you implement yourself.
What is a channel?
Section titled “What is a channel?”A channel is a bidirectional communication pipe that:
- Has a unique ID used by the registry as a routing key
- Sends and receives messages (the protocol’s seven
Messagevariants — see Protocol) - Signals connection close so the registry can clean up
- Can operate in client or server mode, depending on the channel type
Each language implementation defines its own channel interface (ICommandChannel in TypeScript, CommandChannel trait in Rust) and ships a set of built-in channel implementations. The wire format is byte-identical across languages, so a TypeScript peer and a Rust peer can exchange messages over any transport both support.
Channel lifecycle
Section titled “Channel lifecycle”- You construct a channel and pass it to
registry.registerChannel(channel)(TS) orregistry.register_channel(channel)(Rust). - The registry calls the channel’s
start()to perform any handshake. - For client-mode channels, the registry probes the peer for its commands and caches them as “remote” for routing.
- The registry pumps messages in both directions — your handlers run locally, remote calls route over the channel.
- When the channel closes (peer disconnect, explicit
close(), transport error), the registry drops any commands owned by that channel and stops routing to it.
Language-specific interfaces and built-in channels
Section titled “Language-specific interfaces and built-in channels”The channel interface shape and the available built-ins differ between the two implementations. Pick your language:
TypeScript channels ICommandChannel interface; MessagePortChannel, HTTPChannel, and MCPChannel built-ins.
Rust channels CommandChannel trait; InMemoryChannel and MCPChannel built-ins.