| 1 | //! `/advisor` command — toggle the background advisor watcher. |
| 2 | //! |
| 3 | //! Usage: |
| 4 | //! `/advisor on` — enable the advisor watcher for this session |
| 5 | //! `/advisor off` — disable it |
| 6 | //! `/advisor status` — show whether it is currently enabled |
| 7 | //! `/advisor` — same as `status` |
| 8 | //! |
| 9 | //! The advisor runs as a fire-and-forget background task after each turn that |
| 10 | //! contains tool calls. It reads a bounded slice of recent tool calls, makes a |
| 11 | //! concise LLM advisory call, and emits a note into the status area. |
| 12 | //! Failures do not affect the parent turn. Off by default. |
| 13 | |
| 14 | use crate::commands::traits::{CommandInfo, RegisterCommand}; |
| 15 | use crate::localization::MessageId; |
| 16 | use crate::tui::app::{App, AppAction}; |
| 17 | |
| 18 | use super::CommandResult; |
| 19 | |
| 20 | pub(in crate::commands) const COMMAND_INFO: CommandInfo = CommandInfo { |
| 21 | name: "advisor", |
| 22 | aliases: &["watchers", "watch"], |
| 23 | usage: "/advisor [on|off|status]", |
| 24 | description_id: MessageId::CmdAdvisorDescription, |
| 25 | }; |
| 26 | |
| 27 | pub(in crate::commands) struct AdvisorCmd; |
| 28 | |
| 29 | impl RegisterCommand for AdvisorCmd { |
| 30 | fn info() -> &'static CommandInfo { |
| 31 | &COMMAND_INFO |
| 32 | } |
| 33 | |
| 34 | fn execute(_app: &mut App, arg: Option<&str>) -> CommandResult { |
| 35 | match arg.map(str::trim).filter(|s| !s.is_empty()) { |
| 36 | Some("on") | Some("enable") | Some("yes") | Some("1") | Some("true") => { |
| 37 | CommandResult::action(AppAction::SetAdvisorEnabled { enabled: true }) |
| 38 | } |
| 39 | Some("off") | Some("disable") | Some("no") | Some("0") | Some("false") => { |
| 40 | CommandResult::action(AppAction::SetAdvisorEnabled { enabled: false }) |
| 41 | } |
| 42 | Some("status") | None => { |
| 43 | // The engine owns the authoritative state; report from config. |
| 44 | CommandResult::message( |
| 45 | "Advisor status: use `/advisor on` or `/advisor off` to toggle. \ |
| 46 | Check `[advisor] enabled` in config.toml for the session default.", |
| 47 | ) |
| 48 | } |
| 49 | Some(unknown) => CommandResult::error(format!( |
| 50 | "Unknown advisor argument: {unknown:?}. Use `on`, `off`, or `status`." |
| 51 | )), |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 |