Class: RubyCoded::Chat::CommandHandler
- Inherits:
-
Object
- Object
- RubyCoded::Chat::CommandHandler
- Includes:
- AgentCommands, HistoryCommands, ModelCommands, PlanCommands, TokenCommands, TokenFormatting
- Defined in:
- lib/ruby_coded/chat/command_handler.rb,
lib/ruby_coded/chat/command_handler/plan_commands.rb,
lib/ruby_coded/chat/command_handler/agent_commands.rb,
lib/ruby_coded/chat/command_handler/model_commands.rb,
lib/ruby_coded/chat/command_handler/token_commands.rb,
lib/ruby_coded/chat/command_handler/history_commands.rb,
lib/ruby_coded/chat/command_handler/token_formatting.rb
Overview
Handles slash commands entered in the chat input. Base commands are always available; plugins can contribute additional commands via the plugin registry.
Defined Under Namespace
Modules: AgentCommands, HistoryCommands, ModelCommands, PlanCommands, TokenCommands, TokenFormatting
Constant Summary collapse
- BASE_COMMANDS =
{ "/help" => :cmd_help, "/exit" => :cmd_exit, "/quit" => :cmd_exit, "/clear" => :cmd_clear, "/model" => :cmd_model, "/history" => :cmd_history, "/tokens" => :cmd_tokens, "/agent" => :cmd_agent, "/plan" => :cmd_plan }.freeze
- HELP_TEXT =
File.read(File.join(__dir__, "help.txt")).freeze
Instance Method Summary collapse
- #handle(raw_input) ⇒ Object
-
#initialize(state, llm_bridge:, user_config: nil, credentials_store: nil) ⇒ CommandHandler
constructor
A new instance of CommandHandler.
Constructor Details
#initialize(state, llm_bridge:, user_config: nil, credentials_store: nil) ⇒ CommandHandler
Returns a new instance of CommandHandler.
39 40 41 42 43 44 45 |
# File 'lib/ruby_coded/chat/command_handler.rb', line 39 def initialize(state, llm_bridge:, user_config: nil, credentials_store: nil) @state = state @llm_bridge = llm_bridge @user_config = user_config @credentials_store = credentials_store @commands = build_command_map end |
Instance Method Details
#handle(raw_input) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruby_coded/chat/command_handler.rb', line 47 def handle(raw_input) stripped = raw_input.strip return if stripped.empty? command, rest = stripped.split(" ", 2) method_name = @commands[command.downcase] if method_name send(method_name, rest) else @state.(:system, "Unknown command: #{command}. Type /help for available commands.") end end |