Skip to main content

Crate pi_codes

Crate pi_codes 

Source
Expand description

§pi-codes

Typed Rust SDK for the pi coding agent (@earendil-works/pi-coding-agent): serde models of the pi --mode json JSONL event stream and the pi --mode rpc stdin/stdout command protocol, plus an async (Tokio) RPC client.

use pi_codes::{PiRpcClient, RpcCommand};

let mut client = PiRpcClient::start().await?;
let state = client.request_ok(RpcCommand::GetState { id: None }).await?;
println!("session: {:?}", state.data);
client.shutdown().await?;

§Wire contract

  • RPC framing is strict JSONL: records split on \n only (\r tolerated); U+2028/U+2029 are legal inside strings and must not split records.
  • Unknown event types decode to io::PiEvent::Unknown with the payload preserved — ignore them rather than treating them as errors, so CLI upgrades degrade soft.
  • Unmodeled commands can be sent via rpc::RpcCommand::Raw.

The version convention matches the sibling crates: the crate version names the pi release the live suite last passed against (version::tested_cli_version).

Re-exports§

pub use cli::Mode;
pub use cli::PiCliBuilder;
pub use error::Error;
pub use error::Result;
pub use io::ContentBlock;
pub use io::Model;
pub use io::PiEvent;
pub use io::PiMessage;
pub use io::Usage;
pub use rpc::AgentState;
pub use rpc::BashResult;
pub use rpc::InputDisposition;
pub use rpc::RpcCommand;
pub use rpc::RpcResponse;
pub use rpc::StreamingBehavior;
pub use client_async::PiRpcClient;

Modules§

cli
Builder for pi invocations — assembles argv for --mode json one-shots and --mode rpc servers without hand-rolled string lists.
client_async
Async client for pi --mode rpc: spawns the CLI, writes one command per LF-terminated line, and demultiplexes stdout into command responses and streamed events.
error
Error type shared across the crate.
io
Typed models of pi’s wire vocabulary: the messages and events shared by --mode json (one-shot JSONL event stream) and --mode rpc (command protocol; see crate::rpc).
rpc
The pi --mode rpc command protocol: JSON objects on stdin (one per line, LF-delimited), {"type":"response",...} acknowledgements and streamed events on stdout.
version
Version pin this crate is tested against.