magi-code 0.61.0

Repository-aware CLI coding agent for terminal work
Documentation
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct PrimaryAgentEntry {
    pub(crate) id: String,
    pub(crate) name: String,
    pub(crate) description: String,
    pub(crate) prompt: String,
}

impl From<crate::primary_agents::PrimaryAgentProfile> for PrimaryAgentEntry {
    fn from(profile: crate::primary_agents::PrimaryAgentProfile) -> Self {
        Self {
            id: profile.id,
            name: profile.name,
            description: profile.description,
            prompt: profile.prompt,
        }
    }
}

impl From<PrimaryAgentEntry> for crate::primary_agents::PrimaryAgentProfile {
    fn from(entry: PrimaryAgentEntry) -> Self {
        Self {
            id: entry.id,
            name: entry.name,
            description: entry.description,
            path: std::path::PathBuf::new(),
            prompt: entry.prompt,
        }
    }
}

use super::MissionControlState;

impl MissionControlState {
    pub(crate) fn set_primary_agents(&mut self, entries: Vec<PrimaryAgentEntry>) {
        self.primary_agents = entries;
        self.selected_primary_agent = None;
    }

    pub(crate) fn set_selected_primary_agent_id(&mut self, id: Option<&str>) -> bool {
        self.selected_primary_agent = id.and_then(|id| {
            self.primary_agents
                .iter()
                .position(|entry| entry.id.as_str() == id)
        });
        id.is_none() || self.selected_primary_agent.is_some()
    }

    pub(crate) fn selected_primary_agent_id(&self) -> Option<&str> {
        self.selected_primary_agent
            .and_then(|index| self.primary_agents.get(index))
            .map(|entry| entry.id.as_str())
    }

    pub(crate) fn selected_primary_agent_name(&self) -> &str {
        self.selected_primary_agent
            .and_then(|index| self.primary_agents.get(index))
            .map(|entry| entry.name.as_str())
            .unwrap_or("None")
    }

    pub(crate) fn selected_primary_agent_profile(
        &self,
    ) -> Option<crate::primary_agents::PrimaryAgentProfile> {
        self.selected_primary_agent
            .and_then(|index| self.primary_agents.get(index).cloned())
            .map(Into::into)
    }

    pub(crate) fn cycle_primary_agent(&mut self) {
        self.selected_primary_agent =
            match (self.selected_primary_agent, self.primary_agents.is_empty()) {
                (_, true) => None,
                (None, false) => Some(0),
                (Some(index), false) if index + 1 < self.primary_agents.len() => Some(index + 1),
                (Some(_), false) => None,
            };
    }
}