IPC Protocol

Wire format, message types, and communication flows between client and daemon.

Wire Format

All IPC messages use a simple length-prefixed binary format:

┌──────────────┬──────────────────────────┐
│ 4 bytes (BE) │ bincode payload          │
│ length       │ (serde-serialized)       │
└──────────────┴──────────────────────────┘
  • Length — 4-byte big-endian unsigned integer indicating the payload size in bytes
  • Payload — bincode-serialized Rust struct

This keeps parsing simple and avoids delimiter-based framing issues with binary data.

Message Types

MessageDirectionPurpose
EnvSnapshotClient to DaemonSends current environment variables, working directory, terminal size
HeartbeatBidirectionalKeep-alive ping/pong
AgentRequestClient to DaemonUser query with session context
AgentStreamChunkDaemon to ClientStreaming token from LLM response
AgentCompleteDaemon to ClientAgent finished processing
ConfirmationRequestDaemon to ClientAsk user to approve a risky command
ConfirmationResponseClient to DaemonUser’s approval or denial
CommandResultDaemon to ClientResult of a tool execution
ExecuteCommandDaemon to ClientRoute AI bash command through client’s co-process
CommandExecutionResultClient to DaemonRelay result with output, exit code, and updated cwd

Agent Task Flow

A typical AI query follows this sequence:

sequenceDiagram
    participant C as Client
    participant D as Daemon
    C->>D: AgentRequest
    Note right of D: LLM call
    D-->>C: AgentStreamChunk (reasoning text)
    D-->>C: AgentStreamChunk
    Note right of D: Tool call (e.g., grep)
    D-->>C: AgentStreamChunk (tool result summary)
    Note right of D: LLM call (with tool result)
    D-->>C: AgentStreamChunk (final response)
    D->>C: AgentComplete

Safety Confirmation Flow

When the agent wants to run a command classified as risky:

sequenceDiagram
    participant C as Client
    participant D as Daemon
    Note right of D: Agent wants to run\n"rm -rf target/"
    D->>C: ConfirmationRequest (command, risk level, explanation)
    Note left of C: User sees prompt in TUI
    C->>D: ConfirmationResponse (allow / deny / always-allow)
    Note right of D: Executes or skips based on response
    D-->>C: AgentStreamChunk (continues)

Command Relay Flow

When the orchestrator agent runs a bash command, it is relayed through the client’s co-process so that shell state is shared with the user:

sequenceDiagram
    participant A as Agent (Daemon)
    participant D as Daemon IPC
    participant C as Client IPC
    participant S as Bash Co-Process

    A->>D: bash tool call
    D->>C: ExecuteCommand (command, cwd)
    C->>S: Write command to co-process
    S-->>C: Output + exit code
    C->>D: CommandExecutionResult (output, exit_code, new_cwd)
    D->>A: Tool result

Independent agents (engineer, reviewer) bypass this relay and execute commands in their own daemon-side DaemonShell processes.

Versioning

The IPC protocol is versioned implicitly through the shared codiv-common crate. Since both client and daemon are built from the same workspace, they always use matching message definitions. The EnvSnapshot message includes a protocol version field for future compatibility when independent versioning is needed.