rho-coding-agent 3.13.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! What `rho daemon start --json` prints (#1997): the daemon it reached, or
//! the refusal of one that speaks another protocol version. A client that
//! starts a daemon on another machine before it connects, as rho-ui's setup
//! script does over ssh, reads the refusal here, where its own handshake
//! never gets to, to offer the restart the refusal describes.

use rho_protocol::VersionMismatch;
use serde::Serialize;

use super::daemon_cli::Unreachable;
use crate::daemon::Connection;

/// The one JSON object `rho daemon start --json` prints. Clients such as
/// rho-ui parse it, so keep its field names stable.
#[derive(Debug, Serialize)]
#[serde(tag = "outcome", rename_all = "snake_case")]
pub(super) enum StartReport {
    /// A daemon runs and answered: one that already did, or one this
    /// started.
    Running { pid: u32, version: String },
    /// The daemon's protocol version and this rho's are incompatible, and
    /// the daemon was left running: one newer than this rho, or an older
    /// one someone uses. `mismatch` is the refusal's data as this rho read
    /// it from `rho/hello`: a field a newer daemon added is left out.
    Refused { mismatch: VersionMismatch },
}

impl StartReport {
    /// The report of what `rho daemon start` reached, or `None` when it
    /// failed some other way, which only its error says.
    pub(super) fn of(connected: &Result<Connection, Unreachable>) -> Option<Self> {
        match connected {
            Ok(connection) => Some(Self::Running {
                pid: connection.hello.daemon.pid,
                version: connection.hello.daemon.version.clone(),
            }),
            Err(unreachable) => unreachable
                .mismatch()
                .map(|mismatch| Self::Refused { mismatch }),
        }
    }
}

#[cfg(test)]
#[path = "daemon_start_report_tests.rs"]
mod tests;