InternalsDaemon

One For All Protocol

One For All Protocol

Pure IPC protocol types for the Unbound daemon - no I/O, no async. This crate defines the shared language between the IPC client (macOS app) and server (daemon). Only data types and serialization, nothing else.

Architecture

┌──────────────────┐                    ┌──────────────────┐
│    macOS App      │                    │      Daemon       │
│                   │    Request         │                   │
│  Request::new()  ─┼──► JSON ────────►─┼─► Method match    │
│                   │                    │       │           │
│  Response::      ◄┼── JSON ◄─────────┼── Response::      │
│    from_json()    │    Response        │    success()      │
│                   │                    │                   │
│  Event::         ◄┼── JSON ◄─────────┼── Event::new()    │
│    from_json()    │    Stream          │                   │
└──────────────────┘                    └──────────────────┘

Protocol Overview

JSON-RPC-like protocol over Unix domain sockets (NDJSON - one JSON object per line).

Request

use one_for_all_protocol::{Request, Method};

// Auto-generates UUID v4 request ID
let req = Request::new(Method::SessionList);

// With parameters
let req = Request::with_params(
    Method::SessionCreate,
    serde_json::json!({ "title": "My Session", "repository_id": "repo-1" }),
);

// Serializes to:
// {"id":"550e8400-...","method":"session.create","params":{"title":"My Session",...}}

Response

use one_for_all_protocol::{Response, error_codes};

// Success
let resp = Response::success(&req.id, serde_json::json!({ "id": "sess-1" }));

// Error
let resp = Response::error(&req.id, error_codes::NOT_FOUND, "Session not found");

// Check
resp.is_success(); // true or false

Event (Streaming)

use one_for_all_protocol::{Event, EventType};

let event = Event::new(
    EventType::Message,
    "session-123".to_string(),
    serde_json::json!({ "content": "Hello" }),
    42, // sequence number
);

Methods (41 total)

Health & Lifecycle

MethodWire Name
Healthhealth
Shutdownshutdown

Authentication

MethodWire Name
AuthStatusauth.status
AuthLoginauth.login
AuthLogoutauth.logout

Sessions

MethodWire Name
SessionListsession.list
SessionCreatesession.create
SessionGetsession.get
SessionDeletesession.delete
SessionSubscribesession.subscribe
SessionUnsubscribesession.unsubscribe

Messages

MethodWire Name
MessageListmessage.list
MessageSendmessage.send

Outbox

MethodWire Name
OutboxStatusoutbox.status

Repositories

MethodWire Name
RepositoryListrepository.list
RepositoryAddrepository.add
RepositoryRemoverepository.remove
RepositoryListFilesrepository.list_files
RepositoryReadFilerepository.read_file
RepositoryReadFileSlicerepository.read_file_slice
RepositoryWriteFilerepository.write_file
RepositoryReplaceFileRangerepository.replace_file_range

Claude CLI

MethodWire Name
ClaudeSendclaude.send
ClaudeStatusclaude.status
ClaudeStopclaude.stop

Git

MethodWire Name
GitStatusgit.status
GitDiffFilegit.diff_file
GitLoggit.log
GitBranchesgit.branches
GitStagegit.stage
GitUnstagegit.unstage
GitDiscardgit.discard

GitHub CLI

MethodWire Name
GhAuthStatusgh.auth_status
GhPrCreategh.pr_create
GhPrViewgh.pr_view
GhPrListgh.pr_list
GhPrChecksgh.pr_checks
GhPrMergegh.pr_merge

Terminal

MethodWire Name
TerminalRunterminal.run
TerminalStatusterminal.status
TerminalStopterminal.stop

Event Types

EventTypeDescription
MessageNew message added to session
StreamingChunkReal-time Claude response chunk
StatusChangeSession status changed
InitialStateState dump on subscribe
PingKeepalive
TerminalOutputTerminal stdout/stderr
TerminalFinishedTerminal process exited
ClaudeEventRaw Claude NDJSON event
AuthStateChangedLogin/logout state change
SessionCreatedNew session created
SessionDeletedSession removed

Error Codes

Standard JSON-RPC codes plus custom extensions:

pub mod error_codes {
    // Standard JSON-RPC
    pub const PARSE_ERROR: i32 = -32700;
    pub const INVALID_REQUEST: i32 = -32600;
    pub const METHOD_NOT_FOUND: i32 = -32601;
    pub const INVALID_PARAMS: i32 = -32602;
    pub const INTERNAL_ERROR: i32 = -32603;

    // Custom
    pub const NOT_AUTHENTICATED: i32 = -32001;
    pub const NOT_FOUND: i32 = -32002;
    pub const CONFLICT: i32 = -32003;
}

Design Principles

  • Zero dependencies on I/O or async - Pure data types and serde
  • UUID v4 correlation - Every request auto-generates an ID for response matching
  • Exclusive result/error - Responses carry either result or error, never both
  • Sequence numbers - Events are ordered for resumption after reconnect
  • Wire-format stability - Method names use serde(rename) for stable JSON keys

Testing

cargo test -p one-for-all-protocol

50+ tests covering serialization round-trips, method name mapping, error construction, event formatting, and edge cases.

One For All Protocol