Commands#
Registering and running slash commands. See Commands for the built-in commands.
Commands module for gptme.
This module provides the command system for gptme, including:
Command registry and decorator
Built-in commands (session, llm, export, meta)
Plugin command registration
- class gptme.commands.CommandContext#
Context object containing all command handler parameters.
- gptme.commands.command(name: str, aliases: list[str] | None = None, completer: Callable[[str, list[str]], list[tuple[str, str]]] | None = None, auto_undo: bool = True)#
Decorator to register command handlers.
- Parameters:
name – Command name (without leading /)
aliases – Optional list of command aliases
completer – Optional function for argument completion. Takes (partial_arg, previous_args) and returns list of (completion, description) tuples.
auto_undo – If True (default), automatically undo the command message before execution. Set to False for commands that should be visible to the assistant or that handle undo themselves.
- gptme.commands.execute_cmd(msg: Message, log: LogManager) bool#
Executes any user-command, returns True if command was executed.
- gptme.commands.get_command_completer(name: str) Callable[[str, list[str]], list[tuple[str, str]]] | None#
Get the completer function for a command.
- Parameters:
name – Command name (without leading /)
- Returns:
Completer function or None if no completer registered, or if the command’s owning tool is not loaded in this session.
- gptme.commands.get_commands_with_descriptions() list[tuple[str, str]]#
Get all registered commands with their descriptions.
Returns a sorted list of (name, description) tuples for all registered commands. Uses action_descriptions for built-in commands, falls back to handler docstrings for dynamically registered commands.
- gptme.commands.get_user_commands() list[str]#
Returns user commands enabled in this session.
Includes built-ins and tool-registered commands whose owning tool is loaded. Process-global registrations of disabled tools are omitted.
- gptme.commands.handle_cmd(cmd: str, manager: LogManager) Generator[Message, None, None]#
Handles a command.
- gptme.commands.register_command(name: str, handler: Callable[[CommandContext], Generator[Message, None, None]], aliases: list[str] | None = None, completer: Callable[[str, list[str]], list[tuple[str, str]]] | None = None, owner_tool: str | None = None) None#
Register a command handler dynamically (for tools).
- Parameters:
name – Command name (without leading /)
handler – Function that takes CommandContext and yields Messages
aliases – Optional list of command aliases
completer – Optional function for argument completion. Takes (partial_arg, previous_args) and returns list of (completion, description) tuples.
owner_tool – Tool that owns this command. When set, dispatch and listing require that tool to be loaded in the current session.