From 691f7735730f88abdfb9700fbd57ab019f7d3c95 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 20 Mar 2026 19:02:57 +0100 Subject: [PATCH] Hide /q from dialogs and sort all commands by label - Add Hidden field to commands.Item for slash-only aliases - Mark /q as hidden so only /exit and /quit appear in UI - Filter hidden commands centrally in BuildCommandCategories - Sort all command categories by label uniformly - Sort completion items across categories into a single flat list Fixes #2194 Assisted-By: docker-agent --- pkg/tui/commands/commands.go | 26 ++++++++++++++++--- .../components/editor/completions/command.go | 9 +++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/pkg/tui/commands/commands.go b/pkg/tui/commands/commands.go index 77d0d9d73..3bea679c9 100644 --- a/pkg/tui/commands/commands.go +++ b/pkg/tui/commands/commands.go @@ -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 { @@ -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 { @@ -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 { @@ -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, }) } @@ -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, }) } @@ -432,7 +445,7 @@ func BuildCommandCategories(ctx context.Context, application *app.App) []Categor categories = append(categories, Category{ Name: "Skills", - Commands: sortByLabel(skillCommands), + Commands: skillCommands, }) } @@ -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 } diff --git a/pkg/tui/components/editor/completions/command.go b/pkg/tui/components/editor/completions/command.go index 8a5505d0f..fe628d3a3 100644 --- a/pkg/tui/components/editor/completions/command.go +++ b/pkg/tui/components/editor/completions/command.go @@ -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" @@ -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 }