rho-coding-agent 3.12.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! The section of a system prompt that holds an agent definition's own
//! instructions (`PromptPolicy::Extend`), which a session's prompt renders
//! after Rho's, and reading them back out of a rendered prompt for a
//! session saved before its header kept them (see `app::agent_reopen`).

use super::host_prompt::HOST_HEADING;

const HEADING: &str = "\n\n# Agent instructions\n\n";

/// The section that renders `text`, an agent's instructions.
pub(crate) fn section(text: &str) -> String {
    format!("{HEADING}{text}")
}

/// The agent instructions `system`, a rendered system prompt, holds: what
/// follows the last section heading, up to the host's appended section and
/// any of `suffixes`, the texts a session's launch adds after them, if
/// present. `None` when `system` has no such section.
pub(crate) fn of<'a>(system: &'a str, suffixes: &[&str]) -> Option<&'a str> {
    let (_, rest) = system.rsplit_once(HEADING)?;
    let rest = rest
        .rsplit_once(HOST_HEADING)
        .map_or(rest, |(text, _)| text);
    Some(
        suffixes
            .iter()
            .find_map(|suffix| rest.strip_suffix(suffix)?.strip_suffix("\n\n"))
            .unwrap_or(rest),
    )
}

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