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
1 change: 1 addition & 0 deletions .nextchanges/cli/aitools-install-drop-proceed-confirm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `databricks aitools install` no longer asks "Proceed?" after the agent picker; the picker selection confirms the plan. The picker title now shows the install scope, its hint says Enter installs, `--skills-only` runs label plugin agents "skills" and pre-check every agent whose config dir exists, and the plan summary after it is reduced to the scope line. ([#7478](https://github.com/databricks/cli/pull/7478))
73 changes: 46 additions & 27 deletions cmd/aitools/funnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,32 +238,57 @@ func TestInstallFunnelSkillsFailureThroughJSON(t *testing.T) {
}, funnelShape(funnelEvents(ctx)))
}

func TestInstallFunnelInteractiveConfirm(t *testing.T) {
// Picking agents is the confirmation, so an interactive run goes straight from
// AGENTS_SELECTED to PLAN_CONFIRMED and the install.
func TestInstallFunnelInteractiveSuccess(t *testing.T) {
isolateAgents(t)
setupTestAgents(t)
setupScopeMock(t, installer.ScopeGlobal)
setupInstallMock(t)
origPicker := promptAgentSelection
t.Cleanup(func() { promptAgentSelection = origPicker })
// Cursor gets raw skills, which setupInstallMock stands in for.
promptAgentSelection = func(context.Context, string, []agentChoice) ([]*agents.Agent, error) {
return []*agents.Agent{agents.ByName(agents.NameCursor)}, nil
}

ioCtx, test := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true})
defer test.Done()
go drainReader(test.Stdout)
go drainReader(test.Stderr)

ctx := telemetry.WithNewLogger(ioCtx)
cmd := newTestInstallCmd()
cmd.SetContext(ctx)
require.NoError(t, cmd.RunE(cmd, nil))

events := funnelEvents(ctx)
require.Equal(t, []string{"STARTED", "FLAGS_VALIDATED", "SCOPE_RESOLVED", "AGENTS_SELECTED", "PLAN_CONFIRMED", "SKILLS_INSTALLED", "FINISHED:SUCCESS:"}, funnelShape(events))
assert.True(t, events[0].Interactive)
}

func TestInstallFunnelInteractiveCancel(t *testing.T) {
// The agent picker is the last prompt before the install, so it is where
// an interactive user cancels.
cases := []struct {
name string
proceed func() (bool, error)
wantErr bool
want []string
name string
err error
want string
}{
{name: "confirmed", proceed: func() (bool, error) { return true, nil }, want: []string{"PLAN_CONFIRMED", "SKILLS_INSTALLED", "FINISHED:SUCCESS:"}},
{name: "declined", proceed: func() (bool, error) { return false, nil }, want: []string{"FINISHED:CANCELLED:"}},
{name: "aborted", proceed: func() (bool, error) { return false, huh.ErrUserAborted }, wantErr: true, want: []string{"FINISHED:CANCELLED:USER_ABORTED"}},
// The real prompt tags its own failure (defaultPromptProceed).
{name: "prompt failed", proceed: func() (bool, error) { return false, promptError(assert.AnError) }, wantErr: true, want: []string{"FINISHED:FAILURE:PROMPT_FAILED"}},
{name: "aborted", err: huh.ErrUserAborted, want: "FINISHED:CANCELLED:USER_ABORTED"},
// The real picker tags its own failure (defaultPromptAgentSelection).
{name: "prompt failed", err: promptError(assert.AnError), want: "FINISHED:FAILURE:PROMPT_FAILED"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
isolateAgents(t)
setupTestAgents(t)
setupScopeMock(t, installer.ScopeGlobal)
setupInstallMock(t)
origPicker, origProceed := promptAgentSelection, promptProceed
t.Cleanup(func() { promptAgentSelection, promptProceed = origPicker, origProceed })
// Cursor gets raw skills, which setupInstallMock stands in for.
promptAgentSelection = func(context.Context, []agentChoice) ([]*agents.Agent, error) {
return []*agents.Agent{agents.ByName(agents.NameCursor)}, nil
origPicker := promptAgentSelection
t.Cleanup(func() { promptAgentSelection = origPicker })
promptAgentSelection = func(context.Context, string, []agentChoice) ([]*agents.Agent, error) {
return nil, tc.err
}
promptProceed = tc.proceed

ioCtx, test := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: true})
defer test.Done()
Expand All @@ -273,16 +298,10 @@ func TestInstallFunnelInteractiveConfirm(t *testing.T) {
ctx := telemetry.WithNewLogger(ioCtx)
cmd := newTestInstallCmd()
cmd.SetContext(ctx)
err := cmd.RunE(cmd, nil)
if tc.wantErr {
require.Error(t, err)
} else {
require.NoError(t, err)
}
require.Error(t, cmd.RunE(cmd, nil))

events := funnelEvents(ctx)
want := append([]string{"STARTED", "FLAGS_VALIDATED", "SCOPE_RESOLVED", "AGENTS_SELECTED"}, tc.want...)
require.Equal(t, want, funnelShape(events))
require.Equal(t, []string{"STARTED", "FLAGS_VALIDATED", "SCOPE_RESOLVED", tc.want}, funnelShape(events))
assert.True(t, events[0].Interactive)
})
}
Expand Down Expand Up @@ -338,14 +357,14 @@ func TestInstallFunnelAbortedScopePromptKeepsNamedAgents(t *testing.T) {
}

// Confirming the picker with nothing checked is the user opting out, so it
// finishes CANCELLED like a declined confirm, though the command still errors.
// finishes CANCELLED, though the command still errors.
func TestInstallFunnelEmptyPickerSelectionIsCancelled(t *testing.T) {
isolateAgents(t)
setupTestAgents(t)
setupScopeMock(t, installer.ScopeGlobal)
origPicker := promptAgentSelection
t.Cleanup(func() { promptAgentSelection = origPicker })
promptAgentSelection = func(context.Context, []agentChoice) ([]*agents.Agent, error) {
promptAgentSelection = func(context.Context, string, []agentChoice) ([]*agents.Agent, error) {
return nil, errNoAgentsSelected
}

Expand Down
85 changes: 34 additions & 51 deletions cmd/aitools/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
// install_test.go.
var (
promptAgentSelection = defaultPromptAgentSelection
promptProceed = defaultPromptProceed
installSkillsForAgentsFn = installer.InstallSkillsForAgents
installPluginForAgentFn = installer.InstallPluginForAgent
recordPluginInstallsFn = installer.RecordPluginInstalls
Expand Down Expand Up @@ -202,7 +201,7 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "),
}

// JSON output must be fully non-interactive: every choice has to come
// from flags so no scope prompt, agent picker, or confirm is shown.
// from flags so no scope prompt or agent picker is shown.
// Require the flags those prompts would otherwise resolve, and fail
// fast naming them.
if jsonMode {
Expand Down Expand Up @@ -280,21 +279,12 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "),
plan := buildPlan(targetAgents, scope, skillsOnly, explicit)
funnel.setAgents(plan)
funnel.step(ctx, protos.AitoolsCommandStepAgentsSelected)

// In the interactive picker path, show a plan summary and confirm.
// The picker selection confirms the plan; runs without the picker
// confirm it implicitly.
funnel.step(ctx, protos.AitoolsCommandStepPlanConfirmed)
if !explicit && interactive {
printPlanSummary(ctx, plan, scope)
proceed, err := promptProceed()
if err != nil {
return err
}
if !proceed {
cmdio.LogString(ctx, "Cancelled.")
funnel.finishWith(ctx, protos.AitoolsCommandOutcomeCancelled, protos.AitoolsErrorCategoryUnspecified)
return nil
}
printInstallScope(ctx, scope)
}
funnel.step(ctx, protos.AitoolsCommandStepPlanConfirmed)
// Only a run past this point waits for the telemetry auth. A run that
// ended earlier (a flag error, a cancelled prompt, no agent detected,
// a --path dump) uploads its events only if auth had already resolved,
Expand Down Expand Up @@ -399,7 +389,7 @@ func selectAgents(ctx context.Context, scope string, skillsOnly, interactive boo
// caller prints the no-agents message rather than showing an empty picker.
return nil, nil
}
return promptAgentSelection(ctx, choices)
return promptAgentSelection(ctx, scope, choices)
}

var selected []*agents.Agent
Expand All @@ -426,24 +416,32 @@ func agentChoices(ctx context.Context, scope string, skillsOnly bool) []agentCho
var choices []agentChoice
for _, a := range agents.Registry {
item := planItemFor(a, scope, skillsOnly, false)
label := agentChoiceLabel(ctx, a, item)
label := agentChoiceLabel(ctx, a, item, skillsOnly)
cmdio.LogString(ctx, fmt.Sprintf(" %-16s %s", a.DisplayName, label))
if item.delivery == deliverySkip {
continue
}
choices = append(choices, agentChoice{
agent: a,
label: a.DisplayName + " " + label,
preselect: a.IsPreselected(ctx),
agent: a,
label: a.DisplayName + " " + label,
// Under --skills-only, an agent whose config dir exists also starts
// checked, so a plugin agent whose CLI is not on PATH is included
// as in the non-interactive run. The usual pre-checks still apply.
preselect: a.IsPreselected(ctx) || (skillsOnly && a.Detected(ctx)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The comment says that --skills-only pre-checks agents "as the non-interactive run does". But IsPreselected is also true for a plugin agent whose CLI is on PATH and that has no config dir (StateAvailable). The non-interactive --skills-only run selects by config dir only (a.Detected), so it does not pick that agent. Under --skills-only, use preselect = a.Detected(ctx) only, and add a test case for a CLI on PATH with no config dir.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right: the comment overstated it. Under --skills-only the picker pre-checks the union of IsPreselected and Detected, so a plugin agent with its CLI on PATH and no config dir starts checked, while the non-interactive --skills-only run, which selects by config dir only, leaves it out. In c635c52 I reworded the comment to describe what the code does: a config dir also pre-checks the agent under --skills-only, and the usual pre-checks still apply.

The behavior itself is approved on this PR, so I left it as is. Switching to preselect = a.Detected(ctx) under --skills-only, with a test for a CLI on PATH and no config dir, can be a follow-up.

})
}
return choices
}

// agentChoiceLabel is the picker label: the detection state, plus the skip
// reason when the agent can't be acted on in the chosen scope.
func agentChoiceLabel(ctx context.Context, a *agents.Agent, item agentPlanItem) string {
label := agentStateLabel(a.DisplayState(ctx))
// reason when the agent can't be acted on in the chosen scope. Under
// --skills-only every found agent gets raw skills, so it is labeled "skills".
func agentChoiceLabel(ctx context.Context, a *agents.Agent, item agentPlanItem, skillsOnly bool) string {
state := a.DisplayState(ctx)
label := agentStateLabel(state)
if skillsOnly && state != agents.StateNotFound {
label = deliverySkills.String()
}
if item.delivery == deliverySkip {
return label + " · " + item.reason
Comment on lines 445 to 446

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] The --skills-only relabel only covers rows that get skills delivery, so skipped plugin agents still say plugin. With codex on PATH, databricks aitools install --skills-only --scope project prints Codex CLI plugin · does not support project-scoped skills (GitHub Copilot too). The user asked for skills only, the row names the plugin, and the reason talks about skills. Suggest passing skillsOnly into agentChoiceLabel and, when it is set, labeling every found agent with deliverySkills.String(). For plugin agents, StateAvailable || StateInstalledCLIMissing is the same as state != agents.StateNotFound. That also replaces the new "skills" literal, which .agents/rules/style-guide-go.md asks to avoid when the package already has the value. A ScopeProject case in TestAgentChoicesSkillsOnlyLabelsPluginAgentsSkills would pin it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in da4d9e2. agentChoiceLabel now takes skillsOnly and, when it is set, labels every found agent (state != agents.StateNotFound) with deliverySkills.String(). That covers skipped rows and replaces the "skills" literal. TestAgentChoicesSkillsOnlyLabelsSkippedPluginAgentSkills checks that Codex CLI under project scope reads skills · does not support project-scoped skills. The label test also has a ScopeProject case now.

}
Expand All @@ -464,19 +462,7 @@ func agentStateLabel(s agents.DisplayState) string {
}
}

func defaultPromptProceed() (bool, error) {
proceed := true
err := huh.NewConfirm().
Title("Proceed?").
Value(&proceed).
Run()
if err != nil {
return false, promptError(err)
}
return proceed, nil
}

func defaultPromptAgentSelection(_ context.Context, choices []agentChoice) ([]*agents.Agent, error) {
func defaultPromptAgentSelection(_ context.Context, scope string, choices []agentChoice) ([]*agents.Agent, error) {
options := make([]huh.Option[string], 0, len(choices))
byName := make(map[string]*agents.Agent, len(choices))
for _, c := range choices {
Expand All @@ -486,8 +472,8 @@ func defaultPromptAgentSelection(_ context.Context, choices []agentChoice) ([]*a

var selected []string
err := huh.NewMultiSelect[string]().
Title("Select agents to set up").
Description("space to toggle, enter to confirm").
Title(agentPickerTitle(scope)).
Description("space to toggle, enter to install").
Options(options...).
Value(&selected).
Run()
Expand Down Expand Up @@ -547,20 +533,17 @@ func planItemFor(a *agents.Agent, scope string, skillsOnly, explicit bool) agent
return item
}

// printPlanSummary renders the interactive plan summary before the confirm.
func printPlanSummary(ctx context.Context, plan []agentPlanItem, scope string) {
// agentPickerTitle names the install scope, so it is visible before anything
// is installed.
func agentPickerTitle(scope string) string {
return "Select agents to set up (" + scope + " scope)"
}

// printInstallScope prints the install scope after the agent picker, above the
// per-agent install lines.
func printInstallScope(ctx context.Context, scope string) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nice to have] With --skills-only, the picker rows for Claude Code, Codex and Copilot still say "plugin": agentChoiceLabel (line 411) builds the label from DisplayState, which ignores skillsOnly, while planItemFor gives every agent raw skills. Before this PR, the plan summary ("Claude Code install skills") showed the real delivery before anything ran. Now nothing does until the install starts. This affects databricks aitools install --skills-only and every interactive run of the deprecated databricks skills install alias, which always passes --skills-only (legacy_skills.go:50). So the per-agent lines did not just repeat the picker in this mode. Could the label come from the plan item instead, for example showing "skills" when item.delivery == deliverySkills for an agent that has a plugin? An agentChoices(ctx, scope, true) test would pin it; the existing test (install_test.go:180) only passes false.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 24a70e8. agentChoiceLabel now shows "skills" for a plugin agent (state "plugin" or "plugin · CLI not found") when its plan item delivers skills, which only happens under --skills-only, so the databricks skills install alias is covered too. Agents that aren't found keep "not found". The new test TestAgentChoicesSkillsOnlyLabelsPluginAgentsSkills calls agentChoices with skillsOnly false and true, and checks that Claude Code is labeled "plugin" and then "skills". It fails without the change.

cmdio.LogString(ctx, "")
cmdio.LogString(ctx, "Plan ("+scope+" scope):")
for _, it := range plan {
switch it.delivery {
case deliveryPlugin:
cmdio.LogString(ctx, " "+it.agent.DisplayName+" install the databricks plugin")
case deliverySkills:
cmdio.LogString(ctx, " "+it.agent.DisplayName+" install skills")
case deliverySkip:
cmdio.LogString(ctx, " "+it.agent.DisplayName+" skip ("+it.reason+")")
}
}
cmdio.LogString(ctx, "Install scope: "+scope)
cmdio.LogString(ctx, "")
}

Expand Down
Loading
Loading