rho-coding-agent 3.3.0

A fast Rust agent harness with a small footprint and opinionated defaults
//! How advisor mode reads on every surface that shows it.
//!
//! Advisor mode has three states, not two: a hand-edited config can leave the
//! mode on with no advisor model, and nothing reviews the session in that case.
//! Each surface renders the same three states so none of them claims the
//! advisor is working when it is not.

use crate::{agent::ADVISOR_AGENT_ID, config::InternalAgentModelConfig};

use super::{model_names::ModelNames, RuntimeModelView};

#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) enum AdvisorStatus {
    Off,
    /// Advisor mode is on and this model reviews the session.
    Reviewing {
        model: String,
    },
    /// Advisor mode is on with no advisor model, so the tool is not offered.
    MissingModel,
}

impl AdvisorStatus {
    pub(super) fn new(
        advisor_mode: bool,
        model: Option<&InternalAgentModelConfig>,
        names: ModelNames<'_>,
    ) -> Self {
        Self::of(advisor_mode, model.map(|model| names.internal_agent(model)))
    }

    /// The status of `advisor_mode` with the advisor model `model`, as its
    /// name reads.
    pub(super) fn of(advisor_mode: bool, model: Option<String>) -> Self {
        match (advisor_mode, model) {
            (false, _) => Self::Off,
            (true, Some(model)) => Self::Reviewing { model },
            (true, None) => Self::MissingModel,
        }
    }

    pub(super) fn from_runtime(info: &RuntimeModelView, names: ModelNames<'_>) -> Self {
        Self::new(
            info.advisor_mode,
            info.internal_agents.get(ADVISOR_AGENT_ID),
            names,
        )
    }

    /// Longest-first composer-divider labels. Empty while the mode is off.
    pub(super) fn divider_labels(&self) -> Vec<String> {
        match self {
            Self::Off => Vec::new(),
            Self::Reviewing { model } => vec![format!("advisor: {model}"), "advisor".into()],
            Self::MissingModel => vec!["advisor: no model".into(), "advisor".into()],
        }
    }

    /// `/info` value for the advisor field.
    pub(super) fn detail(&self) -> String {
        match self {
            Self::Off => "off".into(),
            Self::Reviewing { model } => format!("on, {model} reviews the session"),
            Self::MissingModel => "on, but no advisor model is selected".into(),
        }
    }

    /// Whether the mode is on but cannot run for want of a model.
    pub(super) fn needs_model(&self) -> bool {
        matches!(self, Self::MissingModel)
    }
}

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