kimi-wire 0.3.0

Typed Rust client for the Kimi Code CLI Wire protocol
Documentation

kimi-wire

CI crates.io docs.rs codecov

Typed Rust client for the Kimi Code CLI Wire protocol.

Overview

The Wire protocol is a JSON-RPC 2.0 based bidirectional communication protocol exposed by kimi --wire. This crate provides:

  • Strongly typed protocol structsEvent, Request, PromptResult, DisplayBlock, ContentPart, ...
  • A WireClient trait — high-level async methods (prompt, replay, steer, set_plan_mode, cancel).
  • A Transport abstraction — stdio via child process, in-memory channels, or custom backends.
  • Optional secret redaction — scrub secrets from JSON wire logs.

Quick start

Add to your Cargo.toml:

[dependencies]
kimi-wire = "0.1"

Mock client (testing)

use kimi_wire::{InMemoryWireClient, WireClient, protocol::*};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut client = InMemoryWireClient::new();

    // Inject a mock response.
    client.inject(RawWireMessage {
        jsonrpc: JsonRpcVersion,
        id: Some("req-1".to_string()),
        method: None,
        params: None,
        result: Some(serde_json::json!({"status": "finished"})),
        error: None,
    }).await;

    let result = client.prompt("Hello!").await?;
    assert_eq!(result.status, PromptStatus::Finished);

    Ok(())
}

Process transport

use kimi_wire::{transport::ChildProcessTransport, transport::TransportWireClient, WireClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let transport = ChildProcessTransport::spawn("kimi", None, None, None).await?;
    let mut client = TransportWireClient::new(transport);

    let result = client.prompt("Refactor this code").await?;
    println!("Turn finished with status: {:?}", result.status);

    Ok(())
}

Architecture

For protocol lifecycle, bidirectional request handling, object-safety notes, and design rationale, see docs/architecture.md.

Feature flags

Feature Default Description
process Enables ChildProcessTransport for spawning kimi --wire.
redact Enables redact_secrets for scrubbing secrets from JSON.

Protocol version

This crate targets Wire protocol version 1.10 as documented by Moonshot AI. It includes forward-compatible Option<T> fields for newer extensions.

MSRV

Rust 1.80 (required for std::sync::LazyLock).

License

MIT