Skip to main content

atman_runtime/
meta_commands.rs

1pub struct MetaCommand {
2    pub name: &'static str,
3    pub desc: &'static str,
4    pub usage: &'static str,
5    pub aliases: &'static [&'static str],
6}
7
8pub const META_COMMANDS: &[MetaCommand] = &[
9    MetaCommand {
10        name: "help",
11        desc: "show this help",
12        usage: ":help",
13        aliases: &[],
14    },
15    MetaCommand {
16        name: "exit",
17        desc: "leave repl",
18        usage: ":exit | :quit",
19        aliases: &["quit"],
20    },
21    MetaCommand {
22        name: "session",
23        desc: "print current session id",
24        usage: ":session",
25        aliases: &[],
26    },
27    MetaCommand {
28        name: "cost",
29        desc: "cost summary hint",
30        usage: ":cost",
31        aliases: &[],
32    },
33    MetaCommand {
34        name: "mode",
35        desc: "switch trust mode (calm/steady/eager/reckless)",
36        usage: ":mode",
37        aliases: &[],
38    },
39    MetaCommand {
40        name: "mode-theme",
41        desc: "switch display theme (default/wuxia/animal/weather/drink)",
42        usage: ":mode-theme",
43        aliases: &[],
44    },
45    MetaCommand {
46        name: "outside",
47        desc: "cycle outside behavior in eager (deny/approve/allow)",
48        usage: ":outside",
49        aliases: &[],
50    },
51    MetaCommand {
52        name: "attach",
53        desc: "attach file / list / clear",
54        usage: ":attach <path> | :attach clear | :attach list",
55        aliases: &[],
56    },
57    MetaCommand {
58        name: "suggest",
59        desc: "meta-LLM flow suggestion",
60        usage: ":suggest",
61        aliases: &[],
62    },
63    MetaCommand {
64        name: "goal",
65        desc: "get / set / clear session goal",
66        usage: ":goal | :goal <text> | :goal clear",
67        aliases: &[],
68    },
69    MetaCommand {
70        name: "sessions",
71        desc: "list recent sessions",
72        usage: ":sessions",
73        aliases: &[],
74    },
75    MetaCommand {
76        name: "sidebar",
77        desc: "sidebar on / off / auto",
78        usage: ":sidebar on | off | auto",
79        aliases: &[],
80    },
81    MetaCommand {
82        name: "todo",
83        desc: "list / done <id> / cancel <id> / clear",
84        usage: ":todo list | :todo done <id> | :todo cancel <id> | :todo clear",
85        aliases: &[],
86    },
87    MetaCommand {
88        name: "rename",
89        desc: "set / clear session title",
90        usage: ":rename <text> | :rename clear",
91        aliases: &[],
92    },
93    MetaCommand {
94        name: "copy",
95        desc: "push to clipboard (OSC 52)",
96        usage: ":copy last-message | :copy last-tool",
97        aliases: &[],
98    },
99    MetaCommand {
100        name: "compact",
101        desc: "compact transcript now",
102        usage: ":compact",
103        aliases: &[],
104    },
105];
106
107pub fn builtin_list() -> Vec<(&'static str, &'static str)> {
108    META_COMMANDS.iter().map(|c| (c.name, c.desc)).collect()
109}
110
111pub fn help_lines() -> Vec<&'static str> {
112    let mut lines: Vec<&'static str> = META_COMMANDS.iter().map(|c| c.usage).collect();
113    lines.push("");
114    lines.push("resume a prior session: exit, then run `atman --continue <session_id>`");
115    lines.push("@./path or @/abs     — inline attach in bare input");
116    lines
117}
118
119pub fn match_command(input: &str) -> Option<&'static MetaCommand> {
120    let name = input.split_whitespace().next().unwrap_or(input);
121    META_COMMANDS
122        .iter()
123        .find(|c| c.name == name || c.aliases.contains(&name))
124}
125
126#[cfg(test)]
127mod tests {
128    use super::*;
129
130    #[test]
131    fn all_commands_have_nonempty_fields() {
132        for c in META_COMMANDS {
133            assert!(!c.name.is_empty());
134            assert!(!c.desc.is_empty());
135            assert!(!c.usage.is_empty());
136        }
137    }
138
139    #[test]
140    fn match_by_name() {
141        assert_eq!(match_command("help").unwrap().name, "help");
142        assert_eq!(match_command("mode").unwrap().name, "mode");
143        assert_eq!(match_command("mode eager").unwrap().name, "mode");
144    }
145
146    #[test]
147    fn match_by_alias() {
148        assert_eq!(match_command("quit").unwrap().name, "exit");
149    }
150
151    #[test]
152    fn unknown_returns_none() {
153        assert!(match_command("nonexistent").is_none());
154    }
155
156    #[test]
157    fn builtin_list_matches_commands() {
158        let list = builtin_list();
159        assert_eq!(list.len(), META_COMMANDS.len());
160        assert!(list.iter().any(|(n, _)| *n == "mode"));
161    }
162
163    #[test]
164    fn help_lines_not_empty() {
165        let lines = help_lines();
166        assert!(!lines.is_empty());
167        assert!(lines.iter().any(|l| l.contains("resume")));
168    }
169}