rho-coding-agent 3.13.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! The line that tells the model which session sent a message, stamped into
//! the model's copy of it as the time is ([`UserInput::stamped`]).

use rho_protocol::MessageOrigin;
use rho_sdk::{model::ContentBlock, UserInput};

use crate::app::peer_sessions::detail_line;

/// The model's copy of `input`, which `origin` wrote: a message another
/// session sent leads with `[from session <id> (<title>)]` on a line of its
/// own, naming the session as session notifications do, so the model can
/// answer it with its `sessions` tool. Rho's own messages, and the person's,
/// say what they are and get none.
/// rho-providers' fixture providers read past this line; keep them in step.
pub(crate) fn stamp_origin(input: UserInput, origin: Option<&MessageOrigin>) -> UserInput {
    let Some(MessageOrigin::Session { id, title, .. }) = origin else {
        return input;
    };
    let stamp = match title.as_deref().map(detail_line) {
        Some(title) if !title.is_empty() => format!("[from session {id} ({title})]"),
        _ => format!("[from session {id}]"),
    };
    let mut content = input.blocks().to_vec();
    match content.iter_mut().find_map(|block| match block {
        ContentBlock::Text(text) => Some(text),
        _ => None,
    }) {
        Some(text) => *text = format!("{stamp}\n{text}"),
        None => content.insert(0, ContentBlock::Text(stamp)),
    }
    UserInput::content(content).unwrap_or(input)
}

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