slash commands (#2157)

Co-authored-by: adamdotdevin <2363879+adamdottv@users.noreply.github.com>
This commit is contained in:
Dax
2025-08-22 17:04:28 -04:00
committed by GitHub
parent 74c1085103
commit 133fe41cd5
32 changed files with 874 additions and 69 deletions

View File

@@ -31,6 +31,7 @@ type Command struct {
Description string
Keybindings []Keybinding
Trigger []string
Custom bool
}
func (c Command) Keys() []string {
@@ -96,6 +97,7 @@ func (r CommandRegistry) Sorted() []Command {
})
return commands
}
func (r CommandRegistry) Matches(msg tea.KeyPressMsg, leader bool) []Command {
var matched []Command
for _, command := range r.Sorted() {
@@ -182,7 +184,7 @@ func parseBindings(bindings ...string) []Keybinding {
return parsedBindings
}
func LoadFromConfig(config *opencode.Config) CommandRegistry {
func LoadFromConfig(config *opencode.Config, customCommands []opencode.Command) CommandRegistry {
defaults := []Command{
{
Name: AppHelpCommand,
@@ -400,6 +402,16 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry {
}
registry[command.Name] = command
}
for _, command := range customCommands {
registry[CommandName(command.Name)] = Command{
Name: CommandName(command.Name),
Description: command.Description,
Trigger: []string{command.Name},
Keybindings: []Keybinding{},
Custom: true,
}
}
slog.Info("Loaded commands", "commands", registry)
return registry
}