Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions pkg/tui/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Item struct {
Category string
SlashCommand string
Execute ExecuteFunc
Hidden bool // Hidden commands work as slash commands but don't appear in the palette
}

func builtInSessionCommands() []Item {
Expand Down Expand Up @@ -118,8 +119,9 @@ func builtInSessionCommands() []Item {
},
{
ID: "session.q",
Label: "Quit (short)",
Label: "Quit",
SlashCommand: "/q",
Hidden: true,
Description: "Quit the application (alias for /exit)",
Category: "Session",
Execute: func(string) tea.Cmd {
Expand Down Expand Up @@ -281,6 +283,17 @@ func builtInFeedbackCommands() []Item {
}
}

// visibleOnly returns items that are not hidden.
func visibleOnly(items []Item) []Item {
visible := make([]Item, 0, len(items))
for _, item := range items {
if !item.Hidden {
visible = append(visible, item)
}
}
return visible
}

// sortByLabel returns items sorted alphabetically by label.
func sortByLabel(items []Item) []Item {
slices.SortFunc(items, func(a, b Item) int {
Expand Down Expand Up @@ -330,7 +343,7 @@ func BuildCommandCategories(ctx context.Context, application *app.App) []Categor

categories = append(categories, Category{
Name: "Agent Commands",
Commands: sortByLabel(commands),
Commands: commands,
})
}

Expand Down Expand Up @@ -402,7 +415,7 @@ func BuildCommandCategories(ctx context.Context, application *app.App) []Categor

categories = append(categories, Category{
Name: "MCP Prompts",
Commands: sortByLabel(mcpCommands),
Commands: mcpCommands,
})
}

Expand Down Expand Up @@ -432,7 +445,7 @@ func BuildCommandCategories(ctx context.Context, application *app.App) []Categor

categories = append(categories, Category{
Name: "Skills",
Commands: sortByLabel(skillCommands),
Commands: skillCommands,
})
}

Expand All @@ -448,6 +461,11 @@ func BuildCommandCategories(ctx context.Context, application *app.App) []Categor
},
)

// Filter out hidden commands and sort by label in all categories.
for i := range categories {
categories[i].Commands = sortByLabel(visibleOnly(categories[i].Commands))
}

return categories
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/tui/components/editor/completions/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package completions

import (
"context"
"slices"
"strings"

"github.com/docker/docker-agent/pkg/app"
"github.com/docker/docker-agent/pkg/tui/commands"
Expand Down Expand Up @@ -43,6 +45,13 @@ func (c *commandCompletion) Items() []completion.Item {
}
}

return sortItemsByLabel(items)
}

func sortItemsByLabel(items []completion.Item) []completion.Item {
slices.SortFunc(items, func(a, b completion.Item) int {
return strings.Compare(strings.ToLower(a.Label), strings.ToLower(b.Label))
})
return items
}

Expand Down
Loading