rho-coding-agent 3.11.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
//! Shared checklist facts for native and external runtime cards.

use rho_protocol::{
    display::{ToolCard, ToolCardStatus, ToolFact, ToolFamily, ToolHeader},
    PlanEntry, PlanStatus,
};

#[derive(Clone, Copy, Debug)]
pub(crate) enum ChecklistStatus {
    Pending,
    InProgress,
    Completed,
}

/// Keep every item available for expansion; the generic card renderer owns
/// the collapsed terminal-row budget.
pub(crate) fn push_checklist_facts<'a>(
    card: &mut ToolCard,
    items: impl Iterator<Item = (&'a str, ChecklistStatus)>,
) {
    for (text, status) in items {
        if text.is_empty() {
            continue;
        }
        let marker = match status {
            ChecklistStatus::Completed => "✓",
            ChecklistStatus::InProgress => "▸",
            ChecklistStatus::Pending => "○",
        };
        card.push_fact(ToolFact::Text {
            text: format!("{marker} {text}"),
        });
    }
}

/// The key an external agent's plan card goes by among its run's calls, in
/// journals from before plans were recorded as such too, so both show one
/// card.
pub(crate) const EXTERNAL_PLAN_KEY: &str = "acp-plan";

/// The running card that shows an external agent's plan, `entries`, as
/// Rho's own todo card shows its checklist.
pub(crate) fn plan_card(entries: &[PlanEntry]) -> ToolCard {
    let mut card = ToolCard::new(
        ToolCardStatus::Running,
        ToolFamily::Form,
        ToolHeader::call("Plan", /*primary*/ None),
    );
    push_checklist_facts(
        &mut card,
        entries.iter().map(|entry| {
            let status = match entry.status {
                PlanStatus::InProgress => ChecklistStatus::InProgress,
                PlanStatus::Completed => ChecklistStatus::Completed,
                // `Unknown`, or a status a newer journal holds: the step
                // still shows, as not started.
                _ => ChecklistStatus::Pending,
            };
            (entry.content.as_str(), status)
        }),
    );
    card
}