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
\nonly (\rtolerated); U+2028/U+2029 are legal inside strings and must not split records. - Unknown event types decode to
io::PiEvent::Unknownwith 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
piinvocations — assembles argv for--mode jsonone-shots and--mode rpcservers 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; seecrate::rpc). - rpc
- The
pi --mode rpccommand 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.