//! Maps parsed `/` slash commands into one or more `Action` variants //! that `apply_action` can process. use crate::controller::command::Command; use crate::app::runtime::actions::Action; use crate::app::state::types::Overlay; /// Convert a parsed `Command` into the corresponding sequence of `Action`s. /// /// Flow: match each `Command` variant to its handler — most produce a /// single `Action` (open an overlay, dispatch an OAuth flow, open the /// editor, etc.); some produce an `Action::SystemNote` for errors or /// informational responses. /// /// Return: a `Vec` (always non-empty) to be applied sequentially /// by `apply_action`. pub fn apply_command(command: Command) -> Vec { match command { Command::Help => { vec![Action::OpenOverlay(Overlay::Help)] } Command::Quit => { vec![Action::QuitConfirm] } Command::LessonCreate(text) => { vec![Action::SystemNote { kind: "lesson".to_string(), message: format!("/lesson {}", text), }] } Command::LessonExport(path) => { vec![Action::LessonExport { path }] } Command::LessonImport(path) => { vec![Action::LessonImport { path }] } Command::LessonList => { vec![Action::OpenOverlay(Overlay::Learning)] } Command::LessonAccept(name) => { vec![Action::LessonAccept { name }] } Command::LessonReject(name) => { vec![Action::LessonReject { name }] } Command::Mode(mode) => { vec![Action::SwitchMode(mode)] } Command::ClearConfirm => { vec![Action::OpenOverlay(Overlay::ClearConfirm)] } Command::Clear => { vec![Action::SystemNote { kind: "clear".to_string(), message: "transcript cleared".to_string(), }] } Command::Login { provider } if provider.is_empty() => { vec![Action::SystemNote { kind: "error".to_string(), message: "Usage: /login ".to_string(), }] } Command::Login { provider } => { vec![Action::StartOAuth { provider }] } Command::Edit(path) if path == "." || path.is_empty() => { vec![Action::SystemNote { kind: "info".to_string(), message: "Usage: /edit \nOpens a file for inline editing.\nExample: /edit src/main.rs".to_string(), }] } Command::Edit(path) => { vec![Action::OpenEditor { path }] } Command::McpAdd { name, command } => { vec![Action::McpAdd { name, command }] } Command::ModelList => { vec![Action::ModelList] } Command::Compact => { vec![Action::Compact] } Command::WorkflowOpen => { vec![Action::OpenOverlay(Overlay::Workflow)] } Command::WorkflowRun { script } => { vec![Action::RunWorkflow { script }] } Command::Unknown(cmd) => { vec![Action::SystemNote { kind: "error".to_string(), message: format!("unknown command: {}", cmd), }] } } }