mermaid-cli 0.8.1

Open-source AI pair programmer with agentic capabilities. Local-first with Ollama, native tool calling, and beautiful TUI.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
//! Single source of truth for slash commands. Used by:
//! - The palette widget (rendering + filtering)
//! - The dispatcher in `command_handler.rs` (validating known commands)
//! - The `/help` handler (rendering the command list)
//!
//! Adding a new command means adding one entry to `COMMAND_REGISTRY`
//! plus wiring its handler into the `match` in `handle_command`.
//! The palette + help text update automatically.

/// Metadata for one slash command. Names exclude the leading `/`.
#[derive(Debug, Clone, Copy)]
pub struct SlashCommand {
    /// Canonical command name without the leading `/`. Lowercase.
    pub name: &'static str,
    /// Alternative names that route to the same handler. Used by the
    /// dispatcher AND prefix filter — typing `/q` matches `/quit`.
    pub aliases: &'static [&'static str],
    /// One-line user-visible description shown in palette and `/help`.
    pub description: &'static str,
    /// Optional argument hint shown after the command name in the
    /// palette, e.g. `Some("[name]")` for `/model [name]`.
    pub arg_hint: Option<&'static str>,
    /// UX grouping used by `/help`; the palette still preserves registry order.
    pub group: SlashCommandGroup,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SlashCommandGroup {
    Everyday,
    ModelContext,
    SafetyRecovery,
    Integrations,
    AdvancedRuntime,
}

impl SlashCommandGroup {
    pub fn title(self) -> &'static str {
        match self {
            SlashCommandGroup::Everyday => "Everyday",
            SlashCommandGroup::ModelContext => "Model and context",
            SlashCommandGroup::SafetyRecovery => "Safety and recovery",
            SlashCommandGroup::Integrations => "Integrations",
            SlashCommandGroup::AdvancedRuntime => "Advanced runtime",
        }
    }
}

pub const COMMAND_GROUPS: &[SlashCommandGroup] = &[
    SlashCommandGroup::Everyday,
    SlashCommandGroup::ModelContext,
    SlashCommandGroup::SafetyRecovery,
    SlashCommandGroup::Integrations,
    SlashCommandGroup::AdvancedRuntime,
];

/// Authoritative registry of all slash commands. Order here is the
/// order shown in the palette and `/help`.
pub const COMMAND_REGISTRY: &[SlashCommand] = &[
    SlashCommand {
        name: "model",
        aliases: &[],
        description: "Switch model (auto-pulls if needed) or show current",
        arg_hint: Some("[name]"),
        group: SlashCommandGroup::ModelContext,
    },
    SlashCommand {
        name: "reasoning",
        aliases: &[],
        description: "Set reasoning depth (none, minimal, low, medium, high, max, xhigh)",
        arg_hint: Some("[level]"),
        group: SlashCommandGroup::ModelContext,
    },
    SlashCommand {
        name: "visible-reasoning",
        aliases: &["visiblereasoning"],
        description: "Show, hide, or toggle reasoning blocks in the transcript",
        arg_hint: Some("[on|off|toggle]"),
        group: SlashCommandGroup::ModelContext,
    },
    SlashCommand {
        name: "clear",
        aliases: &[],
        description: "Clear chat history",
        arg_hint: None,
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "save",
        aliases: &[],
        description: "Save current conversation",
        arg_hint: Some("[name]"),
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "load",
        aliases: &[],
        description: "Load a conversation",
        arg_hint: Some("[name]"),
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "list",
        aliases: &[],
        description: "List saved conversations",
        arg_hint: None,
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "usage",
        aliases: &[],
        description: "Show provider token usage and session totals",
        arg_hint: None,
        group: SlashCommandGroup::ModelContext,
    },
    SlashCommand {
        name: "context",
        aliases: &[],
        description: "Show current context-window estimate and prompt budget",
        arg_hint: None,
        group: SlashCommandGroup::ModelContext,
    },
    SlashCommand {
        name: "compact",
        aliases: &["compress", "summarize"],
        description: "Compact conversation context with optional focus instructions",
        arg_hint: Some("[instructions]"),
        group: SlashCommandGroup::ModelContext,
    },
    SlashCommand {
        name: "doctor",
        aliases: &[],
        description: "Show in-session readiness, model, safety, and instruction status",
        arg_hint: None,
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "tasks",
        aliases: &[],
        description: "List durable runtime tasks",
        arg_hint: None,
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "task",
        aliases: &[],
        description: "Show a durable runtime task",
        arg_hint: Some("<id>"),
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "pause",
        aliases: &[],
        description: "Pause a durable task by marking it blocked",
        arg_hint: Some("<task-id>"),
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "resume",
        aliases: &[],
        description: "Resume a durable task by marking it running",
        arg_hint: Some("<task-id>"),
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "cancel",
        aliases: &[],
        description: "Cancel the active turn or a durable task",
        arg_hint: Some("[task-id]"),
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "handoff",
        aliases: &[],
        description: "Write a handoff report for the current or named task",
        arg_hint: Some("[task-id]"),
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "report",
        aliases: &[],
        description: "Show current context report or task report",
        arg_hint: Some("[task-id]"),
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "processes",
        aliases: &["procs"],
        description: "List durable runtime processes",
        arg_hint: None,
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "logs",
        aliases: &[],
        description: "Show a durable runtime process log",
        arg_hint: Some("<process-id>"),
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "stop",
        aliases: &[],
        description: "Stop a durable runtime process",
        arg_hint: Some("<process-id>"),
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "restart",
        aliases: &[],
        description: "Restart a durable runtime process",
        arg_hint: Some("<process-id>"),
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "open",
        aliases: &[],
        description: "Open a URL, file, or process target",
        arg_hint: Some("<url|path|process-id>"),
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "ports",
        aliases: &[],
        description: "Show listening TCP ports",
        arg_hint: None,
        group: SlashCommandGroup::AdvancedRuntime,
    },
    SlashCommand {
        name: "approvals",
        aliases: &[],
        description: "List pending approvals",
        arg_hint: None,
        group: SlashCommandGroup::SafetyRecovery,
    },
    SlashCommand {
        name: "approve",
        aliases: &[],
        description: "Approve a pending action",
        arg_hint: Some("<approval-id>"),
        group: SlashCommandGroup::SafetyRecovery,
    },
    SlashCommand {
        name: "deny",
        aliases: &[],
        description: "Deny a pending action",
        arg_hint: Some("<approval-id>"),
        group: SlashCommandGroup::SafetyRecovery,
    },
    SlashCommand {
        name: "checkpoint",
        aliases: &[],
        description: "Create a restore checkpoint for one or more paths",
        arg_hint: Some("<path...>"),
        group: SlashCommandGroup::SafetyRecovery,
    },
    SlashCommand {
        name: "checkpoints",
        aliases: &[],
        description: "List restore checkpoints",
        arg_hint: None,
        group: SlashCommandGroup::SafetyRecovery,
    },
    SlashCommand {
        name: "restore",
        aliases: &[],
        description: "Restore a checkpoint",
        arg_hint: Some("<id>"),
        group: SlashCommandGroup::SafetyRecovery,
    },
    SlashCommand {
        name: "memory",
        aliases: &[],
        description: "List project memory",
        arg_hint: Some("[edit <id> <value>]"),
        group: SlashCommandGroup::Integrations,
    },
    SlashCommand {
        name: "remember",
        aliases: &[],
        description: "Write project memory",
        arg_hint: Some("<key> <value>"),
        group: SlashCommandGroup::Integrations,
    },
    SlashCommand {
        name: "forget",
        aliases: &[],
        description: "Forget a memory entry",
        arg_hint: Some("<id>"),
        group: SlashCommandGroup::Integrations,
    },
    SlashCommand {
        name: "plugins",
        aliases: &[],
        description: "List installed plugins",
        arg_hint: None,
        group: SlashCommandGroup::Integrations,
    },
    SlashCommand {
        name: "model-info",
        aliases: &[],
        description: "Show provider/model capability information",
        arg_hint: Some("<model>"),
        group: SlashCommandGroup::ModelContext,
    },
    SlashCommand {
        name: "cloud-setup",
        aliases: &[],
        description: "Configure Ollama Cloud API key",
        arg_hint: None,
        group: SlashCommandGroup::Integrations,
    },
    SlashCommand {
        name: "help",
        aliases: &["h"],
        description: "Show command help",
        arg_hint: None,
        group: SlashCommandGroup::Everyday,
    },
    SlashCommand {
        name: "quit",
        aliases: &["q"],
        description: "Quit the application",
        arg_hint: None,
        group: SlashCommandGroup::Everyday,
    },
];

/// Filter the registry by a typed prefix (after stripping the leading
/// `/`). An empty prefix returns the full registry. Matches against the
/// canonical name AND any aliases — typing `/q` finds `quit` because
/// `q` is a `quit` alias. Result preserves registry order (stable).
pub fn filter_by_prefix(typed: &str) -> Vec<&'static SlashCommand> {
    let needle = typed.to_lowercase();
    if needle.is_empty() {
        return COMMAND_REGISTRY.iter().collect();
    }
    COMMAND_REGISTRY
        .iter()
        .filter(|cmd| {
            let name_matches = cmd.name == needle
                || (!cmd.name.contains('-') || needle.contains('-'))
                    && cmd.name.starts_with(&needle);
            name_matches || cmd.aliases.iter().any(|a| a.starts_with(&needle))
        })
        .collect()
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn filter_by_prefix_empty_returns_all() {
        let result = filter_by_prefix("");
        assert_eq!(result.len(), COMMAND_REGISTRY.len());
        // Order preserved.
        assert_eq!(result[0].name, COMMAND_REGISTRY[0].name);
    }

    #[test]
    fn filter_by_prefix_exact_match() {
        let result = filter_by_prefix("model");
        assert_eq!(result.len(), 1);
        assert_eq!(result[0].name, "model");
    }

    #[test]
    fn filter_by_prefix_partial_prefix_matches_one() {
        let result = filter_by_prefix("mod");
        assert_eq!(result.len(), 1);
        assert_eq!(result[0].name, "model");
    }

    #[test]
    fn filter_by_prefix_no_match_returns_empty() {
        let result = filter_by_prefix("zzzzz");
        assert!(result.is_empty());
    }

    #[test]
    fn filter_by_prefix_matches_aliases() {
        // `/q` should find `quit` via its alias.
        let result = filter_by_prefix("q");
        assert!(
            result.iter().any(|c| c.name == "quit"),
            "expected quit in: {:?}",
            result.iter().map(|c| c.name).collect::<Vec<_>>()
        );
    }

    #[test]
    fn filter_by_prefix_is_case_insensitive() {
        // User shouldn't have to type lowercase /Q or /MODEL.
        let upper = filter_by_prefix("MODEL");
        assert_eq!(upper.len(), 1);
        assert_eq!(upper[0].name, "model");
    }

    #[test]
    fn registry_has_no_duplicate_names() {
        // Defensive: catches accidental duplicate entries during
        // registry maintenance. Duplicate names would route ambiguously
        // in the dispatcher.
        let mut names: Vec<&str> = COMMAND_REGISTRY.iter().map(|c| c.name).collect();
        names.sort_unstable();
        let len_before = names.len();
        names.dedup();
        assert_eq!(
            names.len(),
            len_before,
            "duplicate command name detected in COMMAND_REGISTRY"
        );
    }
}