From 27e8fa194ee331eccc3aa77d63ae636691a1e8fe Mon Sep 17 00:00:00 2001 From: "nekomimi.pet" Date: Tue, 3 Nov 2026 18:17:42 -0500 Subject: [PATCH] tui: the slash menu completes a command's declared argument choices --- cli/internal/tui/commands.go | 41 +++++++++++++++++++++- cli/internal/tui/commands_test.go | 55 ++++++++++++++++++++++++++++++ cli/internal/tui/shot_chat_test.go | 19 +++++++++++ robot-docs/tui.md | 2 ++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 cli/internal/tui/commands_test.go diff --git a/cli/internal/tui/commands.go b/cli/internal/tui/commands.go index bd8609677..bf674079f 100644 --- a/cli/internal/tui/commands.go +++ b/cli/internal/tui/commands.go @@ -31,7 +31,7 @@ var AppCommands = []ChatCommand{ {Name: "/reload", Description: "apply selected configuration and refresh models"}, {Name: "/compact-at", Description: "show or set this session's compaction window"}, {Name: "/compact", Description: "compact durable context"}, - {Name: "/kernel", Description: "upgrade the session kernel"}, + {Name: "/kernel", Description: "upgrade or restart the session kernel"}, {Name: "/model", Description: "choose a model"}, {Name: "/context", Description: "inspect prepared context"}, {Name: "/login", Description: "add or select a model provider"}, @@ -65,6 +65,45 @@ func (m CommandMenuModel) Matches(input string) []ChatCommand { return nil } + if name, rest, ok := strings.Cut(input, " "); ok { + words := strings.Fields(rest) + argumentIndex := len(words) + partial := "" + if rest != "" && !strings.HasSuffix(rest, " ") { + argumentIndex-- + partial = words[argumentIndex] + } + prefix := name + " " + if partial != "" { + prefix += strings.TrimSuffix(rest, partial) + } + seen := make(map[string]bool) + var direct, others []ChatCommand + for _, command := range m.Catalog { + if command.Name != name || argumentIndex >= len(command.Arguments) { + continue + } + argument := command.Arguments[argumentIndex] + description := argument.Description + if description == "" { + description = argument.Name + } + for _, choice := range argument.Choices { + if seen[choice] || !strings.HasPrefix(choice, partial) { + continue + } + seen[choice] = true + match := ChatCommand{Name: prefix + choice, Description: description} + if match.Name == input { + direct = append(direct, match) + } else { + others = append(others, match) + } + } + } + return append(direct, others...) + } + all := slices.Clone(AppCommands) for _, cmd := range m.Catalog { all = append(all, ChatCommand{ diff --git a/cli/internal/tui/commands_test.go b/cli/internal/tui/commands_test.go new file mode 100644 index 000000000..833ddeda4 --- /dev/null +++ b/cli/internal/tui/commands_test.go @@ -0,0 +1,55 @@ +package tui + +import ( + "testing" + + "albedo/cli/internal/daemon" +) + +func TestCommandMenuMatchesArgumentChoices(t *testing.T) { + menu := CommandMenuModel{Catalog: []daemon.SessionCommand{ + {Name: "/reload", Arguments: []daemon.CommandArgument{{Name: "target", Description: "reload target", Choices: []string{"session", "models", "both"}}}}, + {Name: "/reload", Arguments: []daemon.CommandArgument{{Name: "target", Choices: []string{"models", "other"}}}}, + {Name: "/research", Arguments: []daemon.CommandArgument{{Name: "prompt"}}}, + }} + tests := []struct { + input string + want []string + }{ + {input: "/reload ", want: []string{"/reload session", "/reload models", "/reload both", "/reload other"}}, + {input: "/reload m", want: []string{"/reload models"}}, + {input: "/reload both", want: []string{"/reload both"}}, + {input: "/research some words"}, + {input: "/unknown "}, + {input: "/reload\n", want: nil}, + } + for _, test := range tests { + t.Run(test.input, func(t *testing.T) { + matches := menu.Matches(test.input) + if len(matches) != len(test.want) { + t.Fatalf("got %v, want %v", commandNames(matches), test.want) + } + for index, match := range matches { + if match.Name != test.want[index] { + t.Fatalf("got %v, want %v", commandNames(matches), test.want) + } + } + }) + } +} + +func commandNames(matches []ChatCommand) []string { + result := make([]string, len(matches)) + for index, match := range matches { + result[index] = match.Name + } + return result +} + +func TestCommandMenuMatchesNames(t *testing.T) { + menu := CommandMenuModel{} + matches := menu.Matches("/rel") + if len(matches) == 0 || matches[0].Name != "/reload" { + t.Fatalf("got %v, want /reload name completion", commandNames(matches)) + } +} diff --git a/cli/internal/tui/shot_chat_test.go b/cli/internal/tui/shot_chat_test.go index af86785d9..70bf5471a 100644 --- a/cli/internal/tui/shot_chat_test.go +++ b/cli/internal/tui/shot_chat_test.go @@ -58,6 +58,12 @@ func init() { shotState{name: "fast-off", view: func(w, h int) string { return renderFastChatShot(false, w, h) }}, shotState{name: "fast-on", view: func(w, h int) string { return renderFastChatShot(true, w, h) }}, shotState{name: "direnv-blocked", view: renderDirenvChatShot}, + shotState{name: "command-argument-choices", view: func(w, h int) string { + return renderCommandMenuChatShot("/reload ", w, h) + }}, + shotState{name: "command-argument-filtered", view: func(w, h int) string { + return renderCommandMenuChatShot("/reload m", w, h) + }}, shotState{name: "shell-running", view: func(w, h int) string { return renderShellChatShot(daemon.ShellCommand{ID: "shell-1", Command: "printf output", Status: "running", Output: "first\nsecond\nthird\nfourth\nfifth\nsixth\n", OutputBytes: 38}, false, w, h) }}, @@ -171,6 +177,19 @@ func renderShellChatShot(command daemon.ShellCommand, expanded bool, width, heig return m.View() } +func renderCommandMenuChatShot(input string, width, height int) string { + conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) + session := &daemon.Session{ID: "s", Workspace: "/Users/dawn/proj/albedo", Model: "claude-opus-5-5", Provider: "claude"} + m := NewChatModel(session, daemon.NewChatClient(conn, session.ID)) + m.CommandMenu.Catalog = []daemon.SessionCommand{{ + Name: "/reload", + Arguments: []daemon.CommandArgument{{Name: "target", Description: "reload target", Choices: []string{"session", "models", "both"}}}, + }} + m.TextArea.SetValue(input) + m.SetSize(width, height) + return m.View() +} + // renderDirenvChatShot is a fresh chat whose folder's .envrc direnv blocks. func renderDirenvChatShot(width, height int) string { conn := daemon.NewConnection(daemon.ConnectionSnapshot{Port: 1}, nil) diff --git a/robot-docs/tui.md b/robot-docs/tui.md index 3bfac4a67..de2cb6861 100644 --- a/robot-docs/tui.md +++ b/robot-docs/tui.md @@ -90,6 +90,8 @@ A human composer input beginning with `!` is submitted to the daemon shell resou The Go client sends slash-prefixed `/sessions/.../shell-commands/...` paths through the shared HTTP transport. `cli/test/e2e/tui_shell_test.go` drives the actual composer, output-expansion and cancel shortcuts against a real daemon, covering URL construction as well as execution. +The slash menu completes command names, and after a name and a space it completes that command's declared argument choices from the session's catalog (`CommandMenuModel.Matches`): `/reload ` offers `session`, `models` and `both`, `/kernel ` offers `upgrade` and `restart`, and a typed prefix narrows them. A command whose argument takes free text, like a skill's, shows nothing, so prose after its name stays prose. Gallery states: `chat/command-argument-choices`, `chat/command-argument-filtered`. + The daemon owns execution. A shell command uses the workspace's default/login shell with no TTY, interactive stdin, or persistent cwd/environment. Only one user shell command may run at a time; it may run while an agent is active. Remote workspaces are rejected rather than executed locally. The stream and reset snapshot restore command status, and committed `shell_command` history entries deduplicate with their live event by command ID/history sequence. Shell cards appear even when verbose tool display is off. Execution status and model delivery are separate: a finished command waiting at the safe point says `queued for agent`, and after acknowledgement says `sent to agent`; running commands remain running, and legacy/unknown or detached delivery has no badge. The collapsed card shows at most five output rows; click its expand row or use `ctrl+shift+o` to fetch the retained output pages, and `ctrl+shift+x` or the visible cancel action stops the newest running command. Output is bounded at 16 MiB; the card says when the cap was reached. The preview and expanded capture are plain terminal text: ANSI/control sequences are stripped or neutralized before rendering, never replayed as terminal escapes or markdown. -- knotmirror 0.0.1