rho-coding-agent 3.13.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! Who wrote the user messages a session shows, when the person did not:
//! the origin saved with a row, or, for a row saved before origins were,
//! what rho's own messages are.

use rho_protocol::{MessageOrigin, RhoNotice};
use rho_sdk::model::{ContentBlock, SemanticMessage};

/// What the model reads as the turn that continues an interrupted one
/// begins, as an approved plan's implementation turn begins with the
/// host's message. The session saves it as the turn's user message, rho's
/// ([`RhoNotice::Restart`]); live, clients see [`RESUME_NOTICE`] instead.
pub(crate) const RESUME_NOTE: &str =
    "The rho daemon restarted and interrupted your previous turn. Continue where you left off. \
     A tool call the restart interrupted may have partly run; check its effects before \
     repeating it.";

/// What clients following the session are told as the continuing turn
/// begins.
pub(crate) const RESUME_NOTICE: &str =
    "rho daemon restarted mid-turn; continuing the interrupted turn";

/// Who wrote `message`, a saved user row, when the person did not: the
/// origin `saved` with it, else, for a row saved before origins were, rho
/// for a background input, which only rho writes, and for the restart
/// note, matched exactly. Any other row is the person's, even one an agent
/// labelled by hand.
pub(super) fn replayed_origin(
    message: &SemanticMessage<'_>,
    saved: Option<&MessageOrigin>,
) -> Option<MessageOrigin> {
    if let Some(saved) = saved {
        return Some(saved.clone());
    }
    match message {
        SemanticMessage::BoundaryInput(_) => Some(MessageOrigin::rho(RhoNotice::Notification)),
        SemanticMessage::User([ContentBlock::Text(text)]) if text == RESUME_NOTE => {
            Some(MessageOrigin::rho(RhoNotice::Restart))
        }
        _ => None,
    }
}