rho-coding-agent 3.13.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! A user message the person did not write, as the transcript shows it:
//! one another session sent, or one rho wrote, by the origin the daemon
//! sends beside it ([`MessageOrigin`]).

use rho_protocol::{
    display::{
        NotificationCard, NotificationDelivery, NotificationPreview, NotificationTone,
        NotificationVisibility,
    },
    MessageOrigin, RhoNotice,
};

use super::{daemon_events::DaemonView, session_picker::short_session_id};
use crate::{app::RESUME_NOTICE, title::placeholder};

/// Who wrote a message the person did not, as its card names them.
struct Sender {
    /// Ahead of the message's first line in the card's title.
    name: String,
    /// The line the expanded card shows first.
    from: String,
}

/// The view of user message `text`, written by `origin`: the person's row
/// with no origin; the notice live clients see for rho's restart turn;
/// otherwise a card titled `<sender> · <first line>`, its first line alone
/// for a kind this rho does not know, which expands to who wrote it and the
/// whole text. A replay cannot tell a steer from a prompt, so neither does
/// the card.
pub(super) fn user_view(text: String, origin: Option<&MessageOrigin>) -> DaemonView {
    let sender = match origin {
        None => return DaemonView::User(text),
        Some(MessageOrigin::Rho {
            notice: RhoNotice::Restart,
            ..
        }) => return DaemonView::Notice(RESUME_NOTICE.to_owned()),
        Some(MessageOrigin::Session { id, title, .. }) => Some(Sender {
            name: title
                .as_deref()
                .and_then(placeholder)
                .unwrap_or_else(|| format!("session {}", short_session_id(id.as_str()))),
            from: format!("from session {id}"),
        }),
        // A notification, or a notice a newer daemon sends: rho's.
        Some(MessageOrigin::Rho { .. }) => Some(Sender {
            name: "rho".to_owned(),
            from: "from rho".to_owned(),
        }),
        // A kind a newer daemon sends: not the person's, naming no sender.
        Some(_) => None,
    };
    let first = placeholder(&text).unwrap_or_default();
    let (title, subtitle) = match sender {
        Some(Sender { name, from }) => (format!("{name} · {first}"), Some(from)),
        None => (first, None),
    };
    // The line card shows only the title, subtitle and body.
    DaemonView::Sent(Box::new(NotificationCard {
        title,
        sender: String::new(),
        recipient: String::new(),
        delivery: NotificationDelivery::Received,
        tone: NotificationTone::Neutral,
        preview: NotificationPreview::Full,
        visibility: NotificationVisibility::Conversation,
        reference: None,
        subtitle,
        body: text,
        output: None,
        details: Vec::new(),
    }))
}

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