返回 CodeWhale
advisor.rs
根目录 / crates / tui / src / commands / groups / core / advisor.rs
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 codewhale_command_contract::handler::CommandHandler;
15 use codewhale_command_contract::metadata::{CommandInfo, RegisterCommand};
16 use codewhale_command_contract::outcome::{CommandResult, CoreAction};
17
18 const COMMAND_INFO: CommandInfo = CommandInfo {
19 name: "advisor",
20 aliases: &["watchers", "watch"],
21 usage: "/advisor [on|off|status]",
22 description_key: "cmd_advisor_description",
23 };
24
25 pub(super) struct AdvisorCmd;
26
27 impl<A: From<CoreAction>> RegisterCommand<CommandResult<A>> for AdvisorCmd {
28 fn info() -> &'static CommandInfo {
29 &COMMAND_INFO
30 }
31
32 fn handler() -> CommandHandler<CommandResult<A>> {
33 CommandHandler::Pure(|arg| match arg.map(str::trim).filter(|s| !s.is_empty()) {
34 Some("on") | Some("enable") | Some("yes") | Some("1") | Some("true") => {
35 CommandResult::action(CoreAction::SetAdvisorEnabled { enabled: true }.into())
36 }
37 Some("off") | Some("disable") | Some("no") | Some("0") | Some("false") => {
38 CommandResult::action(CoreAction::SetAdvisorEnabled { enabled: false }.into())
39 }
40 Some("status") | None => {
41 // The engine owns the authoritative state; report from config.
42 CommandResult::message(
43 "Advisor status: use `/advisor on` or `/advisor off` to toggle. \
44 Check `[advisor] enabled` in config.toml for the session default.",
45 )
46 }
47 Some(unknown) => CommandResult::error(format!(
48 "Unknown advisor argument: {unknown:?}. Use `on`, `off`, or `status`."
49 )),
50 })
51 }
52 }
53
53 lines RUST