Skip to content

Commit 691f773

Browse files
committed
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
1 parent a099feb commit 691f773

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

pkg/tui/commands/commands.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Item struct {
3232
Category string
3333
SlashCommand string
3434
Execute ExecuteFunc
35+
Hidden bool // Hidden commands work as slash commands but don't appear in the palette
3536
}
3637

3738
func builtInSessionCommands() []Item {
@@ -118,8 +119,9 @@ func builtInSessionCommands() []Item {
118119
},
119120
{
120121
ID: "session.q",
121-
Label: "Quit (short)",
122+
Label: "Quit",
122123
SlashCommand: "/q",
124+
Hidden: true,
123125
Description: "Quit the application (alias for /exit)",
124126
Category: "Session",
125127
Execute: func(string) tea.Cmd {
@@ -281,6 +283,17 @@ func builtInFeedbackCommands() []Item {
281283
}
282284
}
283285

286+
// visibleOnly returns items that are not hidden.
287+
func visibleOnly(items []Item) []Item {
288+
visible := make([]Item, 0, len(items))
289+
for _, item := range items {
290+
if !item.Hidden {
291+
visible = append(visible, item)
292+
}
293+
}
294+
return visible
295+
}
296+
284297
// sortByLabel returns items sorted alphabetically by label.
285298
func sortByLabel(items []Item) []Item {
286299
slices.SortFunc(items, func(a, b Item) int {
@@ -330,7 +343,7 @@ func BuildCommandCategories(ctx context.Context, application *app.App) []Categor
330343

331344
categories = append(categories, Category{
332345
Name: "Agent Commands",
333-
Commands: sortByLabel(commands),
346+
Commands: commands,
334347
})
335348
}
336349

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

403416
categories = append(categories, Category{
404417
Name: "MCP Prompts",
405-
Commands: sortByLabel(mcpCommands),
418+
Commands: mcpCommands,
406419
})
407420
}
408421

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

433446
categories = append(categories, Category{
434447
Name: "Skills",
435-
Commands: sortByLabel(skillCommands),
448+
Commands: skillCommands,
436449
})
437450
}
438451

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

464+
// Filter out hidden commands and sort by label in all categories.
465+
for i := range categories {
466+
categories[i].Commands = sortByLabel(visibleOnly(categories[i].Commands))
467+
}
468+
451469
return categories
452470
}
453471

pkg/tui/components/editor/completions/command.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package completions
22

33
import (
44
"context"
5+
"slices"
6+
"strings"
57

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

48+
return sortItemsByLabel(items)
49+
}
50+
51+
func sortItemsByLabel(items []completion.Item) []completion.Item {
52+
slices.SortFunc(items, func(a, b completion.Item) int {
53+
return strings.Compare(strings.ToLower(a.Label), strings.ToLower(b.Label))
54+
})
4655
return items
4756
}
4857

0 commit comments

Comments
 (0)