multicast-workflows 2.0.0

Durable Code Mode workflows attached to multicast CLIs as first-party commands
Documentation
//! A CLI with no workflows of its own, served through [`ServeWorkflows`].
//!
//! ```text
//! plain_math sum --left 2 --right 3
//! plain_math workflows list
//! plain_math --codemode           # Code Mode MCP server on stdio
//! ```

use multicast::cli::Cli;
use multicast::command::{CommandContext, CommandDef, CommandHandler};
use multicast::output::CommandResult;
use multicast_workflows::ServeWorkflows as _;
use serde::Deserialize;
use serde_json::json;

#[derive(multicast::Options, Deserialize)]
#[allow(dead_code)]
struct SumOptions {
    /// Left operand.
    left: i64,
    /// Right operand.
    right: i64,
}

struct Sum;

#[async_trait::async_trait]
impl CommandHandler for Sum {
    async fn run(&self, context: CommandContext) -> CommandResult {
        let number = |key: &str| context.options[key].as_i64().unwrap_or(0);
        CommandResult::Ok {
            data: json!({"sum": number("left") + number("right")}),
            cta: None,
            exit_code: None,
        }
    }
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    Cli::create("plain_math")
        .command(
            "sum",
            CommandDef::build("sum", Sum)
                .description("Add two integers")
                .options::<SumOptions>()
                .done(),
        )
        .serve_workflows()
        .await
}