2026-07-12 11:28:39 +07:00
|
|
|
//! Maps parsed `/` slash commands into one or more `Action` variants
|
|
|
|
|
//! that `apply_action` can process.
|
2026-07-11 18:23:01 +07:00
|
|
|
use crate::controller::command::Command;
|
|
|
|
|
use crate::app::runtime::actions::Action;
|
|
|
|
|
use crate::app::state::types::Overlay;
|
|
|
|
|
|
2026-07-12 11:28:39 +07:00
|
|
|
/// 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<Action>` (always non-empty) to be applied sequentially
|
|
|
|
|
/// by `apply_action`.
|
2026-07-11 18:23:01 +07:00
|
|
|
pub fn apply_command(command: Command) -> Vec<Action> {
|
|
|
|
|
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)]
|
|
|
|
|
}
|
2026-07-11 21:06:22 +07:00
|
|
|
Command::LessonAccept(name) => {
|
|
|
|
|
vec![Action::LessonAccept { name }]
|
|
|
|
|
}
|
|
|
|
|
Command::LessonReject(name) => {
|
|
|
|
|
vec![Action::LessonReject { name }]
|
|
|
|
|
}
|
2026-07-11 18:23:01 +07:00
|
|
|
Command::Mode(mode) => {
|
|
|
|
|
vec![Action::SwitchMode(mode)]
|
|
|
|
|
}
|
2026-07-12 02:06:46 +07:00
|
|
|
Command::ClearConfirm => {
|
|
|
|
|
vec![Action::OpenOverlay(Overlay::ClearConfirm)]
|
|
|
|
|
}
|
2026-07-11 18:23:01 +07:00
|
|
|
Command::Clear => {
|
|
|
|
|
vec![Action::SystemNote {
|
|
|
|
|
kind: "clear".to_string(),
|
|
|
|
|
message: "transcript cleared".to_string(),
|
|
|
|
|
}]
|
|
|
|
|
}
|
2026-07-12 03:14:52 +07:00
|
|
|
Command::Login { provider } if provider.is_empty() => {
|
|
|
|
|
vec![Action::SystemNote {
|
|
|
|
|
kind: "error".to_string(),
|
|
|
|
|
message: "Usage: /login <provider>".to_string(),
|
|
|
|
|
}]
|
|
|
|
|
}
|
2026-07-11 20:21:59 +07:00
|
|
|
Command::Login { provider } => {
|
2026-07-11 23:45:13 +07:00
|
|
|
vec![Action::StartOAuth { provider }]
|
2026-07-11 18:23:01 +07:00
|
|
|
}
|
2026-07-12 02:06:46 +07:00
|
|
|
Command::Edit(path) if path == "." || path.is_empty() => {
|
|
|
|
|
vec![Action::SystemNote {
|
|
|
|
|
kind: "info".to_string(),
|
|
|
|
|
message: "Usage: /edit <path>\nOpens a file for inline editing.\nExample: /edit src/main.rs".to_string(),
|
|
|
|
|
}]
|
|
|
|
|
}
|
2026-07-12 01:25:52 +07:00
|
|
|
Command::Edit(path) => {
|
|
|
|
|
vec![Action::OpenEditor { path }]
|
|
|
|
|
}
|
|
|
|
|
Command::McpAdd { name, command } => {
|
|
|
|
|
vec![Action::McpAdd { name, command }]
|
|
|
|
|
}
|
2026-07-12 02:06:46 +07:00
|
|
|
Command::ModelList => {
|
|
|
|
|
vec![Action::ModelList]
|
|
|
|
|
}
|
2026-07-12 13:40:58 +07:00
|
|
|
Command::Compact => {
|
|
|
|
|
vec![Action::Compact]
|
|
|
|
|
}
|
2026-07-12 17:49:34 +07:00
|
|
|
Command::WorkflowOpen => {
|
|
|
|
|
vec![Action::OpenOverlay(Overlay::Workflow)]
|
|
|
|
|
}
|
|
|
|
|
Command::WorkflowRun { script } => {
|
|
|
|
|
vec![Action::RunWorkflow { script }]
|
|
|
|
|
}
|
2026-07-11 18:23:01 +07:00
|
|
|
Command::Unknown(cmd) => {
|
|
|
|
|
vec![Action::SystemNote {
|
|
|
|
|
kind: "error".to_string(),
|
|
|
|
|
message: format!("unknown command: {}", cmd),
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|