Coverage for src / lilbee / cli / tui / command_registry.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-05-15 20:55 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-05-15 20:55 +0000
1"""Single source of truth for TUI slash commands.
3Every slash command is defined once here. All other modules (chat dispatch,
4suggester, help modal, autocomplete) read from this registry.
5"""
7from __future__ import annotations
9from dataclasses import dataclass
12@dataclass(frozen=True)
13class SlashCommand:
14 """Definition of a single slash command."""
16 name: str
17 handler: str
18 aliases: tuple[str, ...] = ()
19 args_hint: str = ""
20 help_text: str = ""
21 has_arg_completion: bool = False
24COMMANDS: tuple[SlashCommand, ...] = (
25 SlashCommand(
26 "/model",
27 "_cmd_model",
28 aliases=(),
29 args_hint="[name]",
30 help_text="Switch chat model (no arg opens the catalog)",
31 has_arg_completion=True,
32 ),
33 SlashCommand(
34 "/add",
35 "_cmd_add",
36 aliases=(),
37 args_hint="<path>",
38 help_text="Add file or folder to the knowledge base",
39 has_arg_completion=True,
40 ),
41 SlashCommand(
42 "/crawl",
43 "_cmd_crawl",
44 aliases=(),
45 args_hint="[url]",
46 help_text="Crawl a URL (no arg opens the dialog)",
47 ),
48 SlashCommand(
49 "/delete",
50 "_cmd_delete",
51 aliases=(),
52 args_hint="<name>",
53 help_text="Remove a document from the index",
54 has_arg_completion=True,
55 ),
56 SlashCommand(
57 "/set",
58 "_cmd_set",
59 aliases=(),
60 args_hint="<key> <value>",
61 help_text="Change a setting",
62 has_arg_completion=True,
63 ),
64 SlashCommand(
65 "/theme",
66 "_cmd_theme",
67 aliases=(),
68 args_hint="[name]",
69 help_text="Switch theme (no arg lists themes)",
70 has_arg_completion=True,
71 ),
72 SlashCommand(
73 "/reset",
74 "_cmd_reset",
75 args_hint="confirm",
76 help_text="Factory reset (deletes all data)",
77 ),
78 SlashCommand("/status", "_cmd_status", help_text="Show knowledge-base status"),
79 SlashCommand("/settings", "_cmd_settings", help_text="Open settings"),
80 SlashCommand(
81 "/models",
82 "_cmd_catalog",
83 aliases=("/m", "/catalog"),
84 help_text="Browse the model catalog",
85 ),
86 SlashCommand("/setup", "_cmd_setup", help_text="Run the first-run setup wizard"),
87 SlashCommand(
88 "/wiki",
89 "_cmd_wiki",
90 help_text="Open the wiki view",
91 ),
92 SlashCommand(
93 "/remove",
94 "_cmd_remove",
95 aliases=(),
96 args_hint="<name>",
97 help_text="Uninstall a downloaded model",
98 has_arg_completion=True,
99 ),
100 SlashCommand(
101 "/login",
102 "_cmd_login",
103 args_hint="[token]",
104 help_text="Log in to Hugging Face (no arg opens the token page)",
105 ),
106 SlashCommand("/help", "_cmd_help", aliases=("/h",), help_text="Show the slash-command catalog"),
107 SlashCommand("/version", "_cmd_version", help_text="Show the lilbee version"),
108 SlashCommand("/cancel", "_cmd_cancel", help_text="Cancel any in-flight operations"),
109 SlashCommand("/clear", "_cmd_clear", help_text="Clear the conversation"),
110 SlashCommand("/quit", "_cmd_quit", aliases=("/q", "/exit"), help_text="Exit lilbee"),
111)
114def build_dispatch_dict() -> dict[str, str]:
115 """Build a mapping from command name (and aliases) to handler method name."""
116 dispatch: dict[str, str] = {}
117 for cmd in COMMANDS:
118 dispatch[cmd.name] = cmd.handler
119 for alias in cmd.aliases:
120 dispatch[alias] = cmd.handler
121 return dispatch
124def completion_names() -> tuple[str, ...]:
125 """All command names including aliases, for tab completion."""
126 names: list[str] = []
127 for cmd in COMMANDS:
128 names.append(cmd.name)
129 names.extend(cmd.aliases)
130 return tuple(names)