/ go / internal / commands / registry.go
registry.go
  1  package commands
  2  
  3  import (
  4  	"strings"
  5  	"time"
  6  )
  7  
  8  // Message represents a chat message
  9  type Message struct {
 10  	Role      string
 11  	Content   string
 12  	Timestamp time.Time
 13  }
 14  
 15  // CommandHandler defines the interface for command handlers
 16  type CommandHandler interface {
 17  	Handle(args []string) (Message, error)
 18  	Usage() string
 19  	Description() string
 20  }
 21  
 22  // Registry manages all slash commands
 23  type Registry struct {
 24  	commands map[string]CommandHandler
 25  }
 26  
 27  // NewRegistry creates a new command registry
 28  func NewRegistry() *Registry {
 29  	r := &Registry{
 30  		commands: make(map[string]CommandHandler),
 31  	}
 32  	
 33  	// Register all command categories
 34  	r.registerFileCommands()
 35  	r.registerDevCommands()
 36  	r.registerSystemCommands()
 37  	
 38  	return r
 39  }
 40  
 41  // Execute processes a slash command
 42  func (r *Registry) Execute(input string) (Message, error) {
 43  	command := strings.TrimPrefix(input, "/")
 44  	parts := strings.Fields(command)
 45  	
 46  	if len(parts) == 0 {
 47  		return Message{}, nil
 48  	}
 49  	
 50  	cmd := parts[0]
 51  	args := parts[1:]
 52  	
 53  	if handler, exists := r.commands[cmd]; exists {
 54  		return handler.Handle(args)
 55  	}
 56  	
 57  	return Message{
 58  		Role:    "system",
 59  		Content: "❌ Unknown command: /" + cmd + ". Type /help for available commands.",
 60  		Timestamp: time.Now(),
 61  	}, nil
 62  }
 63  
 64  // GetHelp returns formatted help text
 65  func (r *Registry) GetHelp() string {
 66  	return `🔥 Available Commands:
 67  
 68  File Operations:
 69    /ls [path]    - List files in directory
 70    /cat <file>   - Show file contents
 71    /find <pattern> - Find files by pattern
 72    /mkdir <dir>  - Create directory
 73    /touch <file> - Create empty file
 74  
 75  Development Commands:
 76    /orchestrate <task> - Orchestrate complex tasks
 77    /verify <target>    - Verify system compliance
 78    /deploy <target>    - Deploy applications
 79    /test [type]        - Run tests
 80    /build [target]     - Build project
 81  
 82  System Commands:
 83    /help         - Show this help
 84    /clear        - Clear conversation history
 85    /pwd          - Show current directory`
 86  }
 87  
 88  func (r *Registry) registerFileCommands() {
 89  	r.commands["ls"] = &LsCommand{}
 90  	r.commands["cat"] = &CatCommand{}
 91  	r.commands["find"] = &FindCommand{}
 92  	r.commands["mkdir"] = &MkdirCommand{}
 93  	r.commands["touch"] = &TouchCommand{}
 94  }
 95  
 96  func (r *Registry) registerDevCommands() {
 97  	r.commands["orchestrate"] = &OrchestrateCommand{}
 98  	r.commands["verify"] = &VerifyCommand{}
 99  	r.commands["deploy"] = &DeployCommand{}
100  	r.commands["test"] = &TestCommand{}
101  	r.commands["build"] = &BuildCommand{}
102  }
103  
104  func (r *Registry) registerSystemCommands() {
105  	r.commands["help"] = &HelpCommand{registry: r}
106  	r.commands["clear"] = &ClearCommand{}
107  	r.commands["pwd"] = &PwdCommand{}
108  }