From add526b62cff3cb72dd7056ce0e3b77dcee3716f Mon Sep 17 00:00:00 2001 From: Simon Faltum Date: Tue, 17 Nov 2026 09:47:12 +0000 Subject: [PATCH 1/4] aitools install: cancel the agent picker on Esc Esc did nothing in the agent picker, so only Ctrl+C left it. Esc now cancels the picker as Ctrl+C does, and the run ends with the same "user aborted" error. While the picker searches, the first Esc only leaves the search. The help line now says how to cancel. Enter installs the selected agents, since install runs the plan straight after the picker. Co-authored-by: Isaac --- .../cli/aitools-install-esc-cancels.md | 1 + cmd/aitools/install.go | 71 +++++++++++++++++-- cmd/aitools/install_test.go | 66 +++++++++++++++++ 3 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 .nextchanges/cli/aitools-install-esc-cancels.md diff --git a/.nextchanges/cli/aitools-install-esc-cancels.md b/.nextchanges/cli/aitools-install-esc-cancels.md new file mode 100644 index 00000000000..944dd2d296b --- /dev/null +++ b/.nextchanges/cli/aitools-install-esc-cancels.md @@ -0,0 +1 @@ +* `databricks aitools install` now cancels the agent picker when you press Esc, as Ctrl+C does, and exits with the same "user aborted" error. Its help line now says how to cancel. diff --git a/cmd/aitools/install.go b/cmd/aitools/install.go index 62e6f43e2b8..4a72be87241 100644 --- a/cmd/aitools/install.go +++ b/cmd/aitools/install.go @@ -8,6 +8,7 @@ import ( "runtime" "strings" + tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/huh" "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/aitools/agents" @@ -518,13 +519,9 @@ func defaultPromptAgentSelection(_ context.Context, scope string, choices []agen } var selected []string - err := huh.NewMultiSelect[string](). - Title(agentPickerTitle(scope)). - Description("space to toggle, enter to install"). - Options(options...). - Value(&selected). - Run() - if err != nil { + field := agentPickerField(scope, options, &selected) + form := huh.NewForm(huh.NewGroup(field)).WithShowHelp(false) + if err := runPicker(form, field.GetFiltering); err != nil { return nil, promptError(err) } if len(selected) == 0 { @@ -538,6 +535,66 @@ func defaultPromptAgentSelection(_ context.Context, scope string, choices []agen return result, nil } +// agentPickerHelp is the help line of the agent picker. Enter installs the +// selected agents: install runs the plan straight after the picker. +const agentPickerHelp = "space to toggle, enter to install, esc to cancel" + +func agentPickerField(scope string, options []huh.Option[string], selected *[]string) *huh.MultiSelect[string] { + return huh.NewMultiSelect[string](). + Title(agentPickerTitle(scope)). + Description(agentPickerHelp). + Options(options...). + Value(selected) +} + +// pickerModel runs a form as huh's Run does, except that Esc cancels it too. +type pickerModel struct { + form *huh.Form + // searching reports whether a multi-select in the form is searching. Esc + // then belongs to the form, which leaves the search. + searching func() bool + cancelled bool +} + +func (p *pickerModel) Init() tea.Cmd { return p.form.Init() } + +func (p *pickerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { + if key, ok := msg.(tea.KeyMsg); ok && key.Type == tea.KeyEsc && !p.searching() { + p.cancelled = true + return p, tea.Quit + } + next, cmd := p.form.Update(msg) + p.form = next.(*huh.Form) + return p, cmd +} + +func (p *pickerModel) View() string { return p.form.View() } + +// newPicker returns the program of form. Run sets the commands that submit and +// cancel a form, and newPicker sets them too, since it runs the form without Run. +func newPicker(form *huh.Form, searching func() bool) *pickerModel { + form.SubmitCmd = tea.Quit + form.CancelCmd = tea.Interrupt + return &pickerModel{form: form, searching: searching} +} + +// runPicker runs form and returns huh.ErrUserAborted when the user cancels it, +// with Esc or Ctrl+C. +func runPicker(form *huh.Form, searching func() bool) error { + p := newPicker(form, searching) + _, err := tea.NewProgram(p).Run() + return pickerError(p.cancelled, err) +} + +// pickerError is the result of a picker's program: a cancel, by Esc or Ctrl+C, +// is huh.ErrUserAborted, as huh's Run returns it. +func pickerError(cancelled bool, err error) error { + if cancelled || errors.Is(err, tea.ErrInterrupted) { + return huh.ErrUserAborted + } + return err +} + // buildPlan resolves the per-agent delivery and scope. Plugin-first: an agent // with a headless plugin install gets the plugin; --skills-only forces skills // everywhere; agents with no plugin always get skills. diff --git a/cmd/aitools/install_test.go b/cmd/aitools/install_test.go index c24b8cc9b3c..eff181e28c4 100644 --- a/cmd/aitools/install_test.go +++ b/cmd/aitools/install_test.go @@ -16,6 +16,7 @@ import ( "runtime" "testing" + tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/huh" "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/aitools/agents" @@ -1820,3 +1821,68 @@ func TestNoAgentsMessageMatchesTheDetection(t *testing.T) { printNoAgentsMessage(ctx, installInvocation{scope: installer.ScopeGlobal}) assert.Contains(t, stderr.String(), "No supported coding agents found on PATH.") } + +// Esc cancels the agent picker as Ctrl+C does, and both end the run with +// huh.ErrUserAborted. +func TestAgentPickerEscCancelsLikeCtrlC(t *testing.T) { + options := []huh.Option[string]{huh.NewOption("Cursor", "cursor")} + + var selected []string + field := agentPickerField(installer.ScopeGlobal, options, &selected) + p := newPicker(huh.NewForm(huh.NewGroup(field)).WithShowHelp(false), field.GetFiltering) + p.Init() + p.Update(tea.WindowSizeMsg{Width: 80, Height: 24}) + assert.Contains(t, p.View(), agentPickerHelp) + + _, cmd := p.Update(tea.KeyMsg{Type: tea.KeyEsc}) + assert.True(t, p.cancelled) + assert.Equal(t, tea.QuitMsg{}, cmd()) + assert.ErrorIs(t, pickerError(p.cancelled, nil), huh.ErrUserAborted) + + field = agentPickerField(installer.ScopeGlobal, options, &selected) + p = newPicker(huh.NewForm(huh.NewGroup(field)).WithShowHelp(false), field.GetFiltering) + p.Init() + _, cmd = p.Update(tea.KeyMsg{Type: tea.KeyCtrlC}) + assert.Equal(t, tea.InterruptMsg{}, cmd()) + assert.ErrorIs(t, pickerError(false, tea.ErrInterrupted), huh.ErrUserAborted) +} + +// While the agent picker searches, the first Esc only leaves the search. +func TestAgentPickerEscLeavesSearchBeforeCancelling(t *testing.T) { + options := []huh.Option[string]{huh.NewOption("Cursor", "cursor"), huh.NewOption("Claude Code", "claude")} + + var selected []string + field := agentPickerField(installer.ScopeGlobal, options, &selected) + p := newPicker(huh.NewForm(huh.NewGroup(field)).WithShowHelp(false), field.GetFiltering) + p.Init() + p.Update(tea.WindowSizeMsg{Width: 80, Height: 24}) + p.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune("/")}) + require.True(t, field.GetFiltering()) + + p.Update(tea.KeyMsg{Type: tea.KeyEsc}) + assert.False(t, p.cancelled, "the first Esc leaves the search") + assert.False(t, field.GetFiltering()) + + p.Update(tea.KeyMsg{Type: tea.KeyEsc}) + assert.True(t, p.cancelled, "Esc outside the search cancels the picker") +} + +func TestPickerError(t *testing.T) { + boom := errors.New("boom") + tests := []struct { + name string + cancelled bool + err error + want error + }{ + {"completed", false, nil, nil}, + {"esc", true, nil, huh.ErrUserAborted}, + {"ctrl c", false, tea.ErrInterrupted, huh.ErrUserAborted}, + {"program error", false, boom, boom}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + assert.Equal(t, tc.want, pickerError(tc.cancelled, tc.err)) + }) + } +} From 5c38d9e8f1b468a39187d31d62eee6ea0817149c Mon Sep 17 00:00:00 2001 From: Simon Faltum Date: Tue, 17 Nov 2026 11:43:45 +0000 Subject: [PATCH 2/4] Link the changelog fragment to its PR Co-authored-by: Isaac --- .nextchanges/cli/aitools-install-esc-cancels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/cli/aitools-install-esc-cancels.md b/.nextchanges/cli/aitools-install-esc-cancels.md index 944dd2d296b..f15e136b1e1 100644 --- a/.nextchanges/cli/aitools-install-esc-cancels.md +++ b/.nextchanges/cli/aitools-install-esc-cancels.md @@ -1 +1 @@ -* `databricks aitools install` now cancels the agent picker when you press Esc, as Ctrl+C does, and exits with the same "user aborted" error. Its help line now says how to cancel. +* `databricks aitools install` now cancels the agent picker when you press Esc, as Ctrl+C does, and exits with the same "user aborted" error. Its help line now says how to cancel. ([#7721](https://github.com/databricks/cli/pull/7721)) From b137472b63ad97b76e992a53825b18a83d5738e0 Mon Sep 17 00:00:00 2001 From: Simon Faltum Date: Thu, 19 Nov 2026 08:44:43 +0000 Subject: [PATCH 3/4] aitools install: draw the agent picker on stderr, and clear it on Esc Co-authored-by: Isaac --- cmd/aitools/install.go | 14 +++++++++++--- cmd/aitools/install_test.go | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/aitools/install.go b/cmd/aitools/install.go index 4a72be87241..36338365dcd 100644 --- a/cmd/aitools/install.go +++ b/cmd/aitools/install.go @@ -568,7 +568,14 @@ func (p *pickerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return p, cmd } -func (p *pickerModel) View() string { return p.form.View() } +// View draws nothing once Esc cancelled the picker, as huh's form does after Ctrl+C, so both keys leave the same +// screen. +func (p *pickerModel) View() string { + if p.cancelled { + return "" + } + return p.form.View() +} // newPicker returns the program of form. Run sets the commands that submit and // cancel a form, and newPicker sets them too, since it runs the form without Run. @@ -579,10 +586,11 @@ func newPicker(form *huh.Form, searching func() bool) *pickerModel { } // runPicker runs form and returns huh.ErrUserAborted when the user cancels it, -// with Esc or Ctrl+C. +// with Esc or Ctrl+C. It takes the program options huh's Run sets: the picker +// draws on stderr, so a redirected stdout gets none of it, and reports focus. func runPicker(form *huh.Form, searching func() bool) error { p := newPicker(form, searching) - _, err := tea.NewProgram(p).Run() + _, err := tea.NewProgram(p, tea.WithOutput(os.Stderr), tea.WithReportFocus()).Run() return pickerError(p.cancelled, err) } diff --git a/cmd/aitools/install_test.go b/cmd/aitools/install_test.go index eff181e28c4..ac180c5f67e 100644 --- a/cmd/aitools/install_test.go +++ b/cmd/aitools/install_test.go @@ -1837,6 +1837,7 @@ func TestAgentPickerEscCancelsLikeCtrlC(t *testing.T) { _, cmd := p.Update(tea.KeyMsg{Type: tea.KeyEsc}) assert.True(t, p.cancelled) assert.Equal(t, tea.QuitMsg{}, cmd()) + assert.Empty(t, p.View(), "a cancelled picker leaves nothing on screen") assert.ErrorIs(t, pickerError(p.cancelled, nil), huh.ErrUserAborted) field = agentPickerField(installer.ScopeGlobal, options, &selected) From 6958a6d9dc0cd91ce0eb7db20019873b079b745d Mon Sep 17 00:00:00 2001 From: Simon Faltum Date: Thu, 19 Nov 2026 09:19:20 +0000 Subject: [PATCH 4/4] Say what Esc and Ctrl+C leave on screen in the picker's View comment Co-authored-by: Isaac --- cmd/aitools/install.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/aitools/install.go b/cmd/aitools/install.go index 36338365dcd..22cfda71bf4 100644 --- a/cmd/aitools/install.go +++ b/cmd/aitools/install.go @@ -568,8 +568,8 @@ func (p *pickerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return p, cmd } -// View draws nothing once Esc cancelled the picker, as huh's form does after Ctrl+C, so both keys leave the same -// screen. +// View draws nothing once Esc cancelled the picker, so Esc leaves no picker on screen. Ctrl+C interrupts the program, +// which keeps the last frame, as huh's Run does. func (p *pickerModel) View() string { if p.cancelled { return ""