Skip to main content

oxicode/rpc_mode/
mod.rs

1//! RPC mode for headless operation
2//!
3//! Implements a JSONL-over-stdio protocol for embedding oxicode in other applications.
4//! Commands are received as JSON lines on stdin, responses and events are emitted
5//! as JSON lines on stdout.
6//!
7//! # Protocol
8//!
9//! - **Commands**: JSON objects with a `type` field and optional `id` for correlation
10//! - **Responses**: JSON objects with `type: "response"`, `command`, `success`, and optional `data`/`error`
11//! - **Events**: `AgentEvent` objects streamed as they occur
12//! - **Extension UI**: Extension UI requests emitted to client; client responds with `extension_ui_response`
13//! - **JSON-RPC 2.0**: Alternatively supports JSON-RPC 2.0 framing (detected by `jsonrpc` field)
14//!
15//! # Framing
16//!
17//! Strict JSONL (JSON Lines): each record is a single JSON object terminated by `\n` (LF).
18//! Carriage returns inside payloads are preserved; records are split on `\n` only.
19#![allow(dead_code, unused_imports)]
20
21pub mod handlers;
22pub mod protocol;
23#[cfg(test)]
24mod tests;
25pub mod utils;
26
27// ── Re-exports ──────────────────────────────────────────────────
28
29// Public API: main entry point
30pub use handlers::run_rpc_mode;
31
32// Protocol types
33pub use protocol::{
34    CommandInfo, CompactionResult, ImageData, JSONRPC_INTERNAL_ERROR, JSONRPC_INVALID_PARAMS,
35    JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_PARSE_ERROR, JsonRpcError,
36    JsonRpcErrorResponse, JsonRpcRequest, JsonRpcSuccessResponse, JsonlLineReader, ModelInfo,
37    PendingExtensionRequest, RpcCommand, RpcEvent, RpcExtensionUiRequest, RpcExtensionUiResponse,
38    RpcImageSource, RpcOutput, RpcResponse, SessionHandoff, SessionState, SessionStats, SourceInfo,
39    jsonrpc_to_command, parse_json_line, rpc_response_to_jsonrpc, serialize_json_line,
40    serialize_json_line_obj,
41};
42
43// Utility types
44pub use utils::{BoxedEventListener, PasteHandler, PasteState, RpcClient, RpcClientConfig};