Files
mistral-vibe/vibe/cli/commands.py
Mathias Gesbert eb580209d4 v2.6.0 (#524)
Co-authored-by: Clément Drouin <clement.drouin@mistral.ai>
Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai>
Co-authored-by: Gauthier Guinet <43207538+Gguinet@users.noreply.github.com>
Co-authored-by: Kim-Adeline Miguel <kimadeline.miguel@mistral.ai>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Quentin <torroba.q@gmail.com>
Co-authored-by: Simon <80467011+sorgfresser@users.noreply.github.com>
Co-authored-by: Simon Van de Kerckhove <simon.vandekerckhove@mistral.ai>
Co-authored-by: Vincent G <10739306+VinceOPS@users.noreply.github.com>
Co-authored-by: angelapopopo <angele.lenglemetz@mistral.ai>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
2026-03-23 18:45:21 +01:00

142 lines
5.0 KiB
Python

from __future__ import annotations
from dataclasses import dataclass
@dataclass
class Command:
aliases: frozenset[str]
description: str
handler: str
exits: bool = False
class CommandRegistry:
def __init__(self, excluded_commands: list[str] | None = None) -> None:
if excluded_commands is None:
excluded_commands = []
self.commands = {
"help": Command(
aliases=frozenset(["/help"]),
description="Show help message",
handler="_show_help",
),
"config": Command(
aliases=frozenset(["/config"]),
description="Edit config settings",
handler="_show_config",
),
"model": Command(
aliases=frozenset(["/model"]),
description="Select active model",
handler="_show_model",
),
"reload": Command(
aliases=frozenset(["/reload"]),
description="Reload configuration from disk",
handler="_reload_config",
),
"clear": Command(
aliases=frozenset(["/clear"]),
description="Clear conversation history",
handler="_clear_history",
),
"log": Command(
aliases=frozenset(["/log"]),
description="Show path to current interaction log file",
handler="_show_log_path",
),
"compact": Command(
aliases=frozenset(["/compact"]),
description="Compact conversation history by summarizing",
handler="_compact_history",
),
"exit": Command(
aliases=frozenset(["/exit"]),
description="Exit the application",
handler="_exit_app",
exits=True,
),
"terminal-setup": Command(
aliases=frozenset(["/terminal-setup"]),
description="Configure Shift+Enter for newlines",
handler="_setup_terminal",
),
"status": Command(
aliases=frozenset(["/status"]),
description="Display agent statistics",
handler="_show_status",
),
"teleport": Command(
aliases=frozenset(["/teleport"]),
description="Teleport session to Vibe Nuage",
handler="_teleport_command",
),
"proxy-setup": Command(
aliases=frozenset(["/proxy-setup"]),
description="Configure proxy and SSL certificate settings",
handler="_show_proxy_setup",
),
"resume": Command(
aliases=frozenset(["/resume", "/continue"]),
description="Browse and resume past sessions",
handler="_show_session_picker",
),
"voice": Command(
aliases=frozenset(["/voice"]),
description="Configure voice settings",
handler="_show_voice_settings",
),
"leanstall": Command(
aliases=frozenset(["/leanstall"]),
description="Install the Lean 4 agent (leanstral)",
handler="_install_lean",
),
"unleanstall": Command(
aliases=frozenset(["/unleanstall"]),
description="Uninstall the Lean 4 agent",
handler="_uninstall_lean",
),
}
for command in excluded_commands:
self.commands.pop(command, None)
self._alias_map = {}
for cmd_name, cmd in self.commands.items():
for alias in cmd.aliases:
self._alias_map[alias] = cmd_name
def find_command(self, user_input: str) -> Command | None:
cmd_name = self.get_command_name(user_input)
return self.commands.get(cmd_name) if cmd_name else None
def get_command_name(self, user_input: str) -> str | None:
return self._alias_map.get(user_input.lower().strip())
def get_help_text(self) -> str:
lines: list[str] = [
"### Keyboard Shortcuts",
"",
"- `Enter` Submit message",
"- `Ctrl+J` / `Shift+Enter` Insert newline",
"- `Escape` Interrupt agent or close dialogs",
"- `Ctrl+C` Quit (or clear input if text present)",
"- `Ctrl+G` Edit input in external editor",
"- `Ctrl+O` Toggle tool output view",
"- `Shift+Tab` Toggle auto-approve mode",
"",
"### Special Features",
"",
"- `!<command>` Execute bash command directly",
"- `@path/to/file/` Autocompletes file paths",
"",
"### Commands",
"",
]
for cmd in self.commands.values():
aliases = ", ".join(f"`{alias}`" for alias in sorted(cmd.aliases))
lines.append(f"- {aliases}: {cmd.description}")
return "\n".join(lines)