procyon 0.1.0

Terminal development harness for Stellar and Soroban smart contracts, driven by a language model
use crate::config::Provider;
use tokio::sync::mpsc;

/// Third-party persona pack (Justin, Nicole, Kaan, Tyler, Elliot, Bri) — not authored or hosted by
/// this project. Named here, rather than only where it's fetched, so the UI's confirmation prompt
/// and the agent task's download both show the same URL by construction.
pub const STELLAR_BUILD_INSTALL_URL: &str =
    "https://raw.githubusercontent.com/kaankacar/stellar-build/main/install.sh";

#[derive(Debug)]
pub enum UserCommand {
    SendPrompt(String),
    Quit,
    SetExplain(bool),
    // Sent once project switching is wired to a command (Sprint 2.1).
    #[allow(dead_code)]
    ChangeProject(String),
    SwitchModel {
        provider: Provider,
        model: String,
    },
    /// Runs the third-party Stellar Build installer after the user has explicitly confirmed it.
    /// Routed through the agent task rather than handled in the UI thread: it downloads a script
    /// and runs it, which can take a while and must not freeze rendering or key handling.
    InstallStellarBuild,
}

#[derive(Debug, Clone)]
pub struct McpServerStatus {
    pub name: String,
    pub connected: bool,
    pub detail: String,
}

#[derive(Debug, Clone)]
pub struct WorkspaceSnapshot {
    pub project_name: String,
    pub contract_name: Option<String>,
    pub network: String,
    pub account: String,
    pub mcp_servers: Vec<McpServerStatus>,
}

#[allow(dead_code)]
#[derive(Debug)]
pub enum AgentUpdate {
    ResponseChunk(String),
    ResponseEnd,
    Status(String),
    /// A plain notice addressed to the user, with none of `Status`'s side effects — it does not
    /// flip the app to Working or open an execution step. Boot-time announcements used `Status`
    /// and so made a freshly launched, idle session render as a running turn.
    Notice(String),
    Error(String),
    /// Which provider and model the agent actually holds, and whether a credential resolved for
    /// them. The UI used to keep its own optimistic copy, which drifted from the agent the moment
    /// a switch failed — or the moment the agent stopped existing.
    Ready {
        provider: String,
        model: String,
        credential: bool,
    },
    /// Structured workspace snapshot — lets the Context panel show Project/Contract/Network
    /// without parsing free-form Status strings.
    Workspace(WorkspaceSnapshot),
    McpStatus(Vec<McpServerStatus>),
}

pub struct Channels {
    pub user_tx: mpsc::UnboundedSender<UserCommand>,
    pub user_rx: mpsc::UnboundedReceiver<UserCommand>,
    pub agent_tx: mpsc::UnboundedSender<AgentUpdate>,
    pub agent_rx: mpsc::UnboundedReceiver<AgentUpdate>,
}

impl Channels {
    pub fn new() -> Self {
        let (user_tx, user_rx) = mpsc::unbounded_channel();
        let (agent_tx, agent_rx) = mpsc::unbounded_channel();
        Self {
            user_tx,
            user_rx,
            agent_tx,
            agent_rx,
        }
    }
}