Repository navigation
aitools: never prompt a coding agent caller in install #7477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * `databricks aitools install` no longer prompts when a coding agent runs it, even in a pseudo-terminal; it uses the non-interactive defaults instead and prints a note saying so. ([#7477](https://github.com/databricks/cli/pull/7477)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import ( | |
| "github.com/databricks/cli/libs/flags" | ||
| "github.com/databricks/cli/libs/log" | ||
| "github.com/databricks/cli/libs/telemetry/protos" | ||
| "github.com/databricks/databricks-sdk-go/useragent" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
|
|
@@ -32,6 +33,33 @@ var ( | |
| // checked. The funnel reports it as CANCELLED: the user chose to act on nothing. | ||
| var errNoAgentsSelected = errors.New("at least one agent must be selected") | ||
|
|
||
| // installPromptsSupported reports whether install may show its prompts. Agents | ||
| // often run commands in a pseudo-terminal (Cursor, Copilot in the VS Code | ||
| // terminal) where stdin looks like a TTY but nobody can answer a TUI prompt. | ||
| // Agent detection is the SDK's list of agent environment variables: | ||
| // https://github.com/databricks/databricks-sdk-go/blob/main/useragent/agent.go | ||
| // An agent caller always gets the documented non-interactive defaults. | ||
| func installPromptsSupported(ctx context.Context) bool { | ||
| return cmdio.IsPromptSupported(ctx) && useragent.AgentProvider() == "" | ||
| } | ||
|
|
||
| // agentCallerNote is printed when install skips its prompts on a terminal | ||
| // because the caller is a coding agent. It names the detected agent by its | ||
| // --agents value when it has one, and the flags of `databricks aitools install` | ||
| // that would have replaced the skipped prompts. The command is named because | ||
| // the deprecated `experimental aitools skills install` alias does not accept | ||
| // these flags. | ||
| func agentCallerNote(missingFlags []string) string { | ||
| provider := useragent.AgentProvider() | ||
| detected := "a coding agent was" | ||
| if provider == "multiple" { | ||
| detected = "more than one coding agent was" | ||
| } else if agent := agents.AgentForProvider(provider); agent != nil { | ||
| detected = fmt.Sprintf("a coding agent (%s) was", agent.Name) | ||
| } | ||
| return fmt.Sprintf("No prompts shown because %s detected. Pass %s to databricks aitools install to choose what to install.", detected, strings.Join(missingFlags, " and ")) | ||
| } | ||
|
|
||
| // delivery is how the databricks tools are delivered to one agent. | ||
| type delivery int | ||
|
|
||
|
|
@@ -102,6 +130,10 @@ Agent selection: | |
| (unset, interactive) A picker over all known agents, detected ones pre-checked. | ||
| (unset, non-interactive) Act on every detected agent. | ||
|
|
||
| Non-interactive runs (no terminal, or called by a coding agent) never prompt: | ||
| scope defaults to global and agents to every detected one. On a terminal, a | ||
| coding agent caller gets a note saying so. | ||
|
|
||
| Output: | ||
| --output json Emit a structured result instead of text. Requires --scope | ||
| and --agents so the command runs without interactive prompts. | ||
|
|
@@ -118,7 +150,8 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "), | |
| ctx = cmdio.WithQuiet(ctx) | ||
| } | ||
|
|
||
| funnel := startFunnel(ctx, protos.AitoolsCommandInstall, installModeType(skillsOnly, pathFlag)) | ||
| interactive := installPromptsSupported(ctx) | ||
| funnel := startFunnel(ctx, protos.AitoolsCommandInstall, installModeType(skillsOnly, pathFlag), interactive) | ||
| defer func() { funnel.finish(ctx, err) }() | ||
|
|
||
| if skillsOnly && pathFlag != "" { | ||
|
|
@@ -206,8 +239,24 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "), | |
| } | ||
| funnel.step(ctx, protos.AitoolsCommandStepFlagsValidated) | ||
|
|
||
| // A person may be at this terminal with an agent env var inherited | ||
| // from an agent session, so say why the prompts they would expect | ||
| // were skipped. | ||
| if !interactive && cmdio.IsPromptSupported(ctx) { | ||
| var missing []string | ||
| if scope == "" { | ||
| missing = append(missing, "--scope") | ||
| } | ||
| if !explicit { | ||
| missing = append(missing, "--agents") | ||
| } | ||
| if len(missing) > 0 { | ||
| cmdio.LogString(ctx, agentCallerNote(missing)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] The deprecated
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in d6c9440. The note now names the command: "Pass --scope and --agents to databricks aitools install to choose what to install." That advice is correct from both |
||
| } | ||
| } | ||
|
|
||
| if scope == "" { | ||
| scope, err = resolveScopeWithPrompt(ctx) | ||
| scope, err = resolveScopeWithPrompt(ctx, interactive) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -217,7 +266,7 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "), | |
| funnel.step(ctx, protos.AitoolsCommandStepScopeResolved) | ||
|
|
||
| if !explicit { | ||
| targetAgents, err = selectAgents(ctx, scope, skillsOnly) | ||
| targetAgents, err = selectAgents(ctx, scope, skillsOnly, interactive) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -233,7 +282,7 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "), | |
| funnel.step(ctx, protos.AitoolsCommandStepAgentsSelected) | ||
|
|
||
| // In the interactive picker path, show a plan summary and confirm. | ||
| if !explicit && cmdio.IsPromptSupported(ctx) { | ||
| if !explicit && interactive { | ||
| printPlanSummary(ctx, plan, scope) | ||
| proceed, err := promptProceed() | ||
| if err != nil { | ||
|
|
@@ -340,10 +389,10 @@ func installOutputIsJSON(cmd *cobra.Command) bool { | |
| // needs a config dir, so in --skills-only mode an agent is "detected" by its | ||
| // config dir (PATH-independent); plugin delivery additionally detects agents by | ||
| // their CLI binary on PATH, which fixes the Codex/Copilot config-dir miss. | ||
| func selectAgents(ctx context.Context, scope string, skillsOnly bool) ([]*agents.Agent, error) { | ||
| func selectAgents(ctx context.Context, scope string, skillsOnly, interactive bool) ([]*agents.Agent, error) { | ||
| // Interactive: the picker decides; a prompt error or empty selection is a real | ||
| // error, not a "nothing detected" no-op. | ||
| if cmdio.IsPromptSupported(ctx) { | ||
| if interactive { | ||
| choices := agentChoices(ctx, scope, skillsOnly) | ||
| if len(choices) == 0 { | ||
| // Agents were detected but none can be acted on in this scope; the | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "io" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "os" | ||
|
|
@@ -387,6 +388,7 @@ func TestInstallPluginFirstDefault(t *testing.T) { | |
| } | ||
|
|
||
| func TestInstallInteractivePickerAndConfirm(t *testing.T) { | ||
| isolateAgents(t) | ||
| setupTestAgents(t) | ||
| fakeBinsOnPath(t, "claude") | ||
| t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6") | ||
|
|
@@ -657,6 +659,7 @@ func TestInstallSkillsRequiresSkillsOnlyOrPath(t *testing.T) { | |
| } | ||
|
|
||
| func TestInstallInteractivePickerErrorPropagates(t *testing.T) { | ||
| isolateAgents(t) | ||
| setupTestAgents(t) | ||
| setupScopeMock(t, installer.ScopeGlobal) | ||
|
|
||
|
|
@@ -908,3 +911,125 @@ func TestResolveScopeValidation(t *testing.T) { | |
| }) | ||
| } | ||
| } | ||
|
|
||
| // setupAgentCallerInstall sets up an install run by the agent caller that | ||
| // agentEnv names (key/value pairs), with Claude Code and Cursor detected. Every | ||
| // prompt fails the test if shown. isolateAgents clears the environment, so it | ||
| // runs first and the HOME, PATH and skills ref set below survive. | ||
| func setupAgentCallerInstall(t *testing.T, agentEnv ...string) (plugins *[]pluginCall, skills *[]installCall, scopePrompted *bool) { | ||
| t.Helper() | ||
| isolateAgents(t, agentEnv...) | ||
| setupTestAgents(t) // ~/.claude and ~/.cursor | ||
| fakeBinsOnPath(t, "claude") | ||
| t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6") | ||
| plugins = setupPluginMock(t) | ||
| skills = setupInstallMock(t) | ||
| scopePrompted = setupScopeMock(t, installer.ScopeProject) | ||
| origPrompt := promptAgentSelection | ||
| t.Cleanup(func() { promptAgentSelection = origPrompt }) | ||
| promptAgentSelection = func(context.Context, []agentChoice) ([]*agents.Agent, error) { | ||
| t.Fatal("agent picker shown to an agent caller") | ||
| return nil, nil | ||
|
Comment on lines
+928
to
+932
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] The test fails fast if the scope prompt or the agent picker runs, but
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in d0c5cc6. The test now stubs |
||
| } | ||
| origProceed := promptProceed | ||
| t.Cleanup(func() { promptProceed = origProceed }) | ||
| promptProceed = func() (bool, error) { | ||
| t.Fatal("plan confirm shown to an agent caller") | ||
| return false, nil | ||
| } | ||
| return plugins, skills, scopePrompted | ||
| } | ||
|
|
||
| // runInstallWithStderr runs install with args and returns the telemetry | ||
| // context and everything written to stderr. | ||
| func runInstallWithStderr(t *testing.T, promptSupported bool, args ...string) (context.Context, string) { | ||
| t.Helper() | ||
| ctx, test := cmdio.SetupTest(t.Context(), cmdio.TestOptions{PromptSupported: promptSupported}) | ||
| go drainReader(test.Stdout) | ||
| // Buffered so the reader never blocks if the test stops before receiving. | ||
| stderr := make(chan []byte, 1) | ||
| go func() { | ||
| b, _ := io.ReadAll(test.Stderr) | ||
| stderr <- b | ||
| }() | ||
| ctx = telemetry.WithNewLogger(ctx) | ||
| cmd := newTestInstallCmd() | ||
| cmd.SetContext(ctx) | ||
| cmd.SetArgs(args) | ||
|
|
||
| err := cmd.Execute() | ||
| test.Done() | ||
| out := string(<-stderr) | ||
| require.NoError(t, err, "stderr:\n%s", out) | ||
| return ctx, out | ||
| } | ||
|
|
||
| func TestInstallAgentCallerInPTYNeverPrompts(t *testing.T) { | ||
| // Cursor and Copilot run agent commands in a pseudo-terminal, so stdin is a | ||
| // TTY, but no human answers the prompts. The run must use the | ||
| // non-interactive defaults instead of blocking on the scope select. | ||
| plugins, skills, scopePrompted := setupAgentCallerInstall(t, "CURSOR_AGENT", "1") | ||
|
|
||
| ctx, stderr := runInstallWithStderr(t, true) | ||
| assert.Contains(t, stderr, "No prompts shown because a coding agent (cursor) was detected. Pass --scope and --agents to databricks aitools install to choose what to install.") | ||
| events := funnelEvents(ctx) | ||
| require.NotEmpty(t, events) | ||
| assert.False(t, events[0].Interactive) | ||
| assert.False(t, *scopePrompted) | ||
| require.Len(t, *plugins, 1) | ||
| assert.Equal(t, agents.NameClaudeCode, (*plugins)[0].agent) | ||
| require.Len(t, *skills, 1) | ||
| assert.Equal(t, installer.ScopeGlobal, (*skills)[0].opts.Scope) | ||
| } | ||
|
|
||
| func TestInstallAgentCallerNoteNamesOnlyMissingFlags(t *testing.T) { | ||
| setupAgentCallerInstall(t, "CURSOR_AGENT", "1") | ||
|
|
||
| _, stderr := runInstallWithStderr(t, true, "--scope", "global") | ||
| assert.Contains(t, stderr, "No prompts shown because a coding agent (cursor) was detected. Pass --agents to databricks aitools install to choose what to install.") | ||
| } | ||
|
|
||
| func TestInstallAgentCallerNoteNamesAgent(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| env []string | ||
| want string | ||
| }{ | ||
| // The SDK reports copilot-cli; the note shows the --agents value. | ||
| {name: "registry alias", env: []string{"COPILOT_CLI", "1"}, want: "because a coding agent (copilot) was detected."}, | ||
| // vscode-agent has no registry entry, so no name is shown. | ||
| {name: "no registry entry", env: []string{"VSCODE_AGENT", "1"}, want: "because a coding agent was detected."}, | ||
| {name: "nested agents", env: []string{"CURSOR_AGENT", "1", "CLAUDECODE", "1"}, want: "because more than one coding agent was detected."}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| plugins, _, _ := setupAgentCallerInstall(t, tc.env...) | ||
|
|
||
| _, stderr := runInstallWithStderr(t, true) | ||
| assert.Contains(t, stderr, tc.want) | ||
| require.Len(t, *plugins, 1) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestInstallAgentCallerNoteSilent(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| promptSupported bool | ||
| args []string | ||
| }{ | ||
| // Both flags given: no prompt would have run, so there is nothing to explain. | ||
| {name: "scope and agents passed", promptSupported: true, args: []string{"--scope", "global", "--agents", "claude-code"}}, | ||
| // No terminal: prompts are skipped for every caller, as before. | ||
| {name: "no terminal", promptSupported: false}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| plugins, _, _ := setupAgentCallerInstall(t, "CURSOR_AGENT", "1") | ||
|
|
||
| _, stderr := runInstallWithStderr(t, tc.promptSupported, tc.args...) | ||
| assert.NotContains(t, stderr, "No prompts shown") | ||
| require.Len(t, *plugins, 1) | ||
| }) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit]
.agents/rules/comments.mdasks for Go doc comments that end with a period. This one ends with the SDK URL. Moving the "Agent detection is the SDK's list…" lines above the last sentence keeps the link and fixes it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in a475e72. I moved the SDK link lines above the last sentence, so the doc comment now ends with a period.