From d2b9cadff62976b04cef3b73dcc1f77671df38c8 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:16:24 +0000 Subject: [PATCH 1/3] aitools: only auto-install without a terminal for coding agent calls ## Changes Automatic installation of Databricks AI tools now asks before a first install whenever the caller is not a coding agent, whether or not a terminal is attached. Before this change it asked only when stdin, stdout or stderr was a terminal. A run with no terminal at all installed without asking. - `autoInstallAsks` now depends only on whether a coding agent was detected. It no longer checks for a terminal. - A run that is not a coding agent's call and cannot show the question (`canAsk` is false) is skipped, the same way runs that have a terminal but cannot prompt are skipped today. It installs nothing, sends no telemetry and leaves the version unsettled, so a later run that can ask, or a coding agent's call, still installs. This skip happens before the lock and the gate lookup, so cron jobs and job pods don't wait on the lookup every time they run. - Coding agents still get the tools without a question, with or without a terminal. - The `interactive` field on the auto-install telemetry event is still true only when a terminal is attached and no coding agent is detected. It is now computed at the call site. ## Why Commands run over ssh without a terminal, under `nohup`, from cron or from an IDE extension have no terminal. Installing in those cases changed the user's agent configuration without asking a person who may have started the command. Asking is not possible there, so the run waits for one where it is. A coding agent's call is the case that is meant to install without a question, and it keeps doing so. ## Tests - Unit tests in `cmd/aitools/autoinstall_run_test.go`: - The "no terminal at all" case now expects a skip with the version left unsettled. - New cases check that a coding agent installs without asking, both with no terminal and in a terminal. - A new test checks that a run with no terminal and no coding agent skips before the gate lookup. - Existing tests that expect an install with no terminal now run as a coding agent's call. - New acceptance test `acceptance/cmd/aitools/auto-install/no-terminal`. A run with no terminal and no coding agent installs nothing and leaves the version unsettled. A later coding agent call then installs. - The shared `script.prepare` for the other auto-install acceptance cases sets `AGENT`. Those cases have no terminal, so they now run as a coding agent's call and their outputs stay the same. - Changelog fragment added under `.nextchanges/cli/`. Co-authored-by: Isaac --- .../cli/aitools-auto-install-no-terminal.md | 1 + .../auto-install/no-terminal/out.test.toml | 1 + .../auto-install/no-terminal/output.txt | 30 +++++++++ .../aitools/auto-install/no-terminal/script | 15 +++++ .../cmd/aitools/auto-install/script.prepare | 6 ++ cmd/aitools/autoinstall_run.go | 32 +++++----- cmd/aitools/autoinstall_run_test.go | 61 ++++++++++++++++++- 7 files changed, 129 insertions(+), 17 deletions(-) create mode 100644 .nextchanges/cli/aitools-auto-install-no-terminal.md create mode 100644 acceptance/cmd/aitools/auto-install/no-terminal/out.test.toml create mode 100644 acceptance/cmd/aitools/auto-install/no-terminal/output.txt create mode 100644 acceptance/cmd/aitools/auto-install/no-terminal/script diff --git a/.nextchanges/cli/aitools-auto-install-no-terminal.md b/.nextchanges/cli/aitools-auto-install-no-terminal.md new file mode 100644 index 00000000000..a61bee2bde9 --- /dev/null +++ b/.nextchanges/cli/aitools-auto-install-no-terminal.md @@ -0,0 +1 @@ +* Automatic installation of Databricks AI tools no longer installs without asking when the CLI runs with no terminal (ssh without a terminal, nohup, cron, an IDE extension); it waits for a run that can ask first. Coding agents still get the tools without a question. diff --git a/acceptance/cmd/aitools/auto-install/no-terminal/out.test.toml b/acceptance/cmd/aitools/auto-install/no-terminal/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/cmd/aitools/auto-install/no-terminal/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/cmd/aitools/auto-install/no-terminal/output.txt b/acceptance/cmd/aitools/auto-install/no-terminal/output.txt new file mode 100644 index 00000000000..095daafc365 --- /dev/null +++ b/acceptance/cmd/aitools/auto-install/no-terminal/output.txt @@ -0,0 +1,30 @@ + +=== no terminal and no coding agent: cannot ask, so nothing is installed or reported, and the version is not settled + +>>> [CLI] jobs list + +>>> print_telemetry + +>>> cursor_skills +(no skills) + +>>> auto_install_state +{"id": "treatment-machine"} + +=== the version is still due: a coding agent's call installs without asking + +>>> AGENT=test-agent [CLI] jobs list +Installed Databricks AI tools for Cursor. Disable: databricks aitools auto-install disable + +>>> print_telemetry +{"command":"jobs_list","exit_code":0,"aitools_install_event":{"agents":["CURSOR"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED","trigger":"AUTO_FIRST_RUN"}} +{"command":"jobs_list","exit_code":0,"aitools_auto_install_event":{"outcome":"INSTALLED","holdout_arm":"TREATMENT","interactive":false}} + +>>> cursor_skills +databricks-test + +>>> auto_install_state +{ + "last_version": "1.30.0", + "id": "treatment-machine" +} diff --git a/acceptance/cmd/aitools/auto-install/no-terminal/script b/acceptance/cmd/aitools/auto-install/no-terminal/script new file mode 100644 index 00000000000..ad88eec46e6 --- /dev/null +++ b/acceptance/cmd/aitools/auto-install/no-terminal/script @@ -0,0 +1,15 @@ +use_home home +gate true +unset AGENT + +title "no terminal and no coding agent: cannot ask, so nothing is installed or reported, and the version is not settled" +trace $CLI jobs list +trace print_telemetry +trace cursor_skills +trace auto_install_state + +title "the version is still due: a coding agent's call installs without asking" +trace AGENT=test-agent $CLI jobs list +trace print_telemetry +trace cursor_skills +trace auto_install_state diff --git a/acceptance/cmd/aitools/auto-install/script.prepare b/acceptance/cmd/aitools/auto-install/script.prepare index 8a130b71809..ad4bd0fd397 100644 --- a/acceptance/cmd/aitools/auto-install/script.prepare +++ b/acceptance/cmd/aitools/auto-install/script.prepare @@ -10,6 +10,12 @@ unset CI DATABRICKS_AITOOLS_AUTO_INSTALL GITHUB_ACTIONS GITLAB_CI JENKINS_URL TF # Telemetry is printed by print_telemetry. unset DATABRICKS_CLI_DISABLE_TELEMETRY DATABRICKS_CLI_TELEMETRY_TIMEOUT +# Without a terminal, only a coding agent's call installs: any other run cannot +# ask first, so it skips (see no-terminal). The cases have no terminal, so they +# run as a coding agent's call. AGENT is the generic marker; this name gets no +# agent hint. +export AGENT=test-agent + # Test binaries are development builds, which never auto-install. Each case # names the released version it simulates. export DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.30.0 diff --git a/cmd/aitools/autoinstall_run.go b/cmd/aitools/autoinstall_run.go index 8fe979938e9..bb886de1d85 100644 --- a/cmd/aitools/autoinstall_run.go +++ b/cmd/aitools/autoinstall_run.go @@ -148,7 +148,7 @@ func autoInstall(ctx context.Context, skippedCommand bool) { log.Debugf(ctx, "auto-install: skipped: %s", tools.skipWhy) return } - if err == nil && autoInstallAsks(ctx) && in.State.AcceptedVersion != version && !canAsk(ctx) && len(tools.newAgents()) > 0 { + if err == nil && autoInstallAsks() && in.State.AcceptedVersion != version && !canAsk(ctx) && len(tools.newAgents()) > 0 { skipUnaskable(ctx, in.State.ID) return } @@ -213,7 +213,7 @@ func autoInstall(ctx context.Context, skippedCommand bool) { version: version, id: id, arm: holdoutArm(in.Bucket), - interactive: autoInstallAsks(ctx), + interactive: cmdio.HasTerminal(ctx) && autoInstallAsks(), } if !reason.Due() { // Another process settled the version while this one waited. @@ -241,11 +241,11 @@ func (r autoInstallRun) attempt(ctx context.Context, prior autoinstall.State) { attempt := autoinstall.NextAttempt(prior, r.version) qctx := quietContext(ctx) tools, err := planTools(qctx, prior) - // A person at the terminal is asked before a first install, once per - // version: a "yes" covers that version's retries. A planning failure is - // a failed attempt, and its retry asks. + // A caller that is not a coding agent is asked before a first install, + // once per version: a "yes" covers that version's retries. A planning + // failure is a failed attempt, and its retry asks. asked := false - if err == nil && r.interactive && prior.AcceptedVersion != r.version && len(tools.newAgents()) > 0 { + if err == nil && autoInstallAsks() && prior.AcceptedVersion != r.version && len(tools.newAgents()) > 0 { // autoInstall skips this case before the lock; the state it decided // on may have changed since. if !canAsk(ctx) { @@ -306,15 +306,17 @@ func (r autoInstallRun) attempt(ctx context.Context, prior autoinstall.State) { } } -// autoInstallAsks reports whether a person may be at the terminal, so -// auto-install asks before installing: stdin, stdout or stderr is a terminal -// and no coding agent is detected (see installPromptsSupported). It asks only -// when the question can be seen and answered (cmdio.IsLinePromptSupported) -// and skips otherwise; the install without asking is left to runs with no -// terminal at all. The question is a plain-text line, so TERM=dumb and an -// MSYS2 pty pipe, which turn off the TUI prompts of install, do not skip it. -func autoInstallAsks(ctx context.Context) bool { - return cmdio.HasTerminal(ctx) && useragent.AgentProvider() == "" +// autoInstallAsks reports whether auto-install asks before installing: no +// coding agent is detected (see installPromptsSupported), so a person may have +// run the command. It asks only when the question can be seen and answered +// (canAsk) and skips otherwise, with or without a terminal: a run from ssh, +// nohup, cron or an IDE extension has none, and installing there would skip +// the consent of a person who cannot see the question. Coding agents get the +// tools without a question. The question is a plain-text line, so TERM=dumb +// and an MSYS2 pty pipe, which turn off the TUI prompts of install, do not +// skip it. +func autoInstallAsks() bool { + return useragent.AgentProvider() == "" } // canAsk reports whether the question can be seen and answered: see diff --git a/cmd/aitools/autoinstall_run_test.go b/cmd/aitools/autoinstall_run_test.go index 376fa91ebe4..5d45603959c 100644 --- a/cmd/aitools/autoinstall_run_test.go +++ b/cmd/aitools/autoinstall_run_test.go @@ -20,6 +20,7 @@ import ( "github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/telemetry" "github.com/databricks/cli/libs/telemetry/protos" + "github.com/databricks/databricks-sdk-go/useragent" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -49,6 +50,9 @@ func TestAutoInstallPrompt(t *testing.T) { installState string // env is set on top of a terminal with color. env map[string]string + // agent is a coding agent's env var, set to 1: the run is that + // agent's call. + agent string // stdinPiped, stdoutRedirected and stderrRedirected make that // stream not a terminal. stdinPiped bool @@ -154,7 +158,16 @@ func TestAutoInstallPrompt(t *testing.T) { wantState: autoinstall.State{ID: "treatment-machine"}, }, { - name: "no terminal at all installs without asking", + // ssh, nohup, cron or an IDE extension: nobody sees the question. + name: "no terminal at all skips without installing", + stdinPiped: true, + stdoutRedirected: true, + stderrRedirected: true, + wantState: autoinstall.State{ID: "treatment-machine"}, + }, + { + name: "a coding agent with no terminal installs without asking", + agent: "CLAUDECODE", stdinPiped: true, stdoutRedirected: true, stderrRedirected: true, @@ -163,6 +176,15 @@ func TestAutoInstallPrompt(t *testing.T) { wantState: autoinstall.State{LastVersion: "1.30.0", ID: "treatment-machine"}, wantOutcome: protos.AitoolsAutoInstallOutcomeInstalled, }, + { + name: "a coding agent in a terminal installs without asking", + agent: "CURSOR_AGENT", + input: "n\n", + wantStderr: []string{"Installed Databricks AI tools for Cursor."}, + wantSkills: true, + wantState: autoinstall.State{LastVersion: "1.30.0", ID: "treatment-machine"}, + wantOutcome: protos.AitoolsAutoInstallOutcomeInstalled, + }, { name: "a retry after yes is not asked again", state: `{"id": "treatment-machine", "last_version": "1.30.0", "attempts": 1, "accepted_version": "1.30.0"}`, @@ -217,6 +239,9 @@ func TestAutoInstallPrompt(t *testing.T) { for k, v := range tc.env { t.Setenv(k, v) } + if tc.agent != "" { + setCodingAgent(t, tc.agent) + } var stdout, stderr bytes.Buffer outW, errW := cmdio.FakeTTY(&stdout), cmdio.FakeTTY(&stderr) if tc.stdoutRedirected { @@ -250,7 +275,7 @@ func TestAutoInstallPrompt(t *testing.T) { for _, e := range telemetry.BufferedEvents(ctx) { if e := e.AitoolsAutoInstallEvent; e != nil { outcomes = append(outcomes, e.Outcome) - assert.Equal(t, !tc.stdinPiped || !tc.stdoutRedirected || !tc.stderrRedirected, e.Interactive) + assert.Equal(t, tc.agent == "" && (!tc.stdinPiped || !tc.stdoutRedirected || !tc.stderrRedirected), e.Interactive) assert.Equal(t, protos.AitoolsHoldoutArmTreatment, e.HoldoutArm) } } @@ -290,6 +315,7 @@ func TestAutoInstallKeepsTheIDWhenItCannotAsk(t *testing.T) { // after one command of a version, not after each of them. func TestAutoInstallLooksTheGateUpOncePerVersion(t *testing.T) { setupAutoInstallHome(t, "") + setCodingAgent(t, "CLAUDECODE") lookups := 0 t.Cleanup(func() { gateOn = autoinstall.GateOn }) gateOn = func(context.Context, string) (bool, error) { @@ -320,6 +346,7 @@ func TestAutoInstallLooksTheGateUpOncePerVersion(t *testing.T) { // the gate on. The run stops instead of installing. func TestAutoInstallStopsWhenTheGateLookupIsInterrupted(t *testing.T) { home := setupAutoInstallHome(t, "") + setCodingAgent(t, "CLAUDECODE") var interrupt context.CancelFunc t.Cleanup(func() { gateOn = autoinstall.GateOn @@ -350,6 +377,7 @@ func TestAutoInstallStopsWhenTheGateLookupIsInterrupted(t *testing.T) { // gate up. func TestAutoInstallSkipsTheGateLookupWithoutAgents(t *testing.T) { home := setupAutoInstallHome(t, "") + setCodingAgent(t, "CLAUDECODE") require.NoError(t, os.RemoveAll(filepath.Join(home, ".cursor"))) t.Cleanup(func() { gateOn = autoinstall.GateOn }) gateOn = func(context.Context, string) (bool, error) { @@ -391,6 +419,9 @@ func TestAutoInstallSkipsRootInAUserHome(t *testing.T) { // when rootInHome is set, and counts the gate lookups. func runRootInUserHome(t *testing.T, rootInHome bool) (ctx context.Context, home string, lookups *int) { home = setupAutoInstallHome(t, "") + // A coding agent's call installs without a question, so the user's run + // needs no terminal. + setCodingAgent(t, "CLAUDECODE") if rootInHome { // The state the setup seeds would hide a state file or lock file // the run creates. @@ -410,6 +441,25 @@ func runRootInUserHome(t *testing.T, rootInHome bool) (ctx context.Context, home return ctx, home, lookups } +// A run with no terminal and no coding agent cannot ask, so it skips before the +// gate lookup: a cron job or a job pod does not wait for it on every run. +func TestAutoInstallSkipsTheGateLookupWhenItCannotAsk(t *testing.T) { + home := setupAutoInstallHome(t, "") + t.Cleanup(func() { gateOn = autoinstall.GateOn }) + gateOn = func(context.Context, string) (bool, error) { + t.Error("the gate was looked up") + return true, nil + } + ctx := cmdio.MockDiscard(t.Context()) + ctx = telemetry.WithNewLogger(ctx) + runAutoInstallHook(ctx) + assert.Empty(t, telemetry.BufferedEvents(ctx)) + assert.NoDirExists(t, filepath.Join(home, ".cursor", "skills")) + state, err := autoinstall.Load(ctx) + require.NoError(t, err) + assert.Equal(t, autoinstall.State{ID: "treatment-machine"}, state, "the version is not settled") +} + func TestToolsPlanNewAgents(t *testing.T) { claude := &agents.Agent{DisplayName: "Claude Code"} cursor := &agents.Agent{DisplayName: "Cursor"} @@ -438,6 +488,13 @@ func runAutoInstallHook(ctx context.Context) { AutoInstall(list) } +// setCodingAgent makes the run the call of the coding agent whose env var is +// name. setupAutoInstallHome resets the SDK's cached agent after the test. +func setCodingAgent(t *testing.T, name string) { + t.Setenv(name, "1") + useragent.ClearCache() +} + // setupAutoInstallHome gives the run a clean environment with Cursor's config // dir, a skills server, the gate on and a released CLI version. state seeds // the auto-install state (a treatment-arm machine id by default). From 96994c501480da2eeda21417bdda8223b02a56e6 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Fri, 20 Nov 2026 01:21:30 +0000 Subject: [PATCH 2/3] Add PR link to changelog fragment Co-authored-by: Isaac --- .nextchanges/cli/aitools-auto-install-no-terminal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/cli/aitools-auto-install-no-terminal.md b/.nextchanges/cli/aitools-auto-install-no-terminal.md index a61bee2bde9..abf6a2683df 100644 --- a/.nextchanges/cli/aitools-auto-install-no-terminal.md +++ b/.nextchanges/cli/aitools-auto-install-no-terminal.md @@ -1 +1 @@ -* Automatic installation of Databricks AI tools no longer installs without asking when the CLI runs with no terminal (ssh without a terminal, nohup, cron, an IDE extension); it waits for a run that can ask first. Coding agents still get the tools without a question. +* Automatic installation of Databricks AI tools no longer installs without asking when the CLI runs with no terminal (ssh without a terminal, nohup, cron, an IDE extension); it waits for a run that can ask first. Coding agents still get the tools without a question. ([#7834](https://github.com/databricks/cli/pull/7834)) From 7806bfabf8ab5fb910e68a556268673d56cd9ba1 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:10:51 +0000 Subject: [PATCH 3/3] Address review: cover headless updates, clarify changelog, trim comment Co-authored-by: Isaac --- .nextchanges/cli/aitools-auto-install-no-terminal.md | 2 +- acceptance/cmd/aitools/auto-install/upgrade/script | 2 ++ cmd/aitools/autoinstall_run.go | 12 +++--------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/.nextchanges/cli/aitools-auto-install-no-terminal.md b/.nextchanges/cli/aitools-auto-install-no-terminal.md index abf6a2683df..e31543836d8 100644 --- a/.nextchanges/cli/aitools-auto-install-no-terminal.md +++ b/.nextchanges/cli/aitools-auto-install-no-terminal.md @@ -1 +1 @@ -* Automatic installation of Databricks AI tools no longer installs without asking when the CLI runs with no terminal (ssh without a terminal, nohup, cron, an IDE extension); it waits for a run that can ask first. Coding agents still get the tools without a question. ([#7834](https://github.com/databricks/cli/pull/7834)) +* Automatic installation of Databricks AI tools no longer installs for the first time without asking when the CLI runs with no terminal (ssh without a terminal, nohup, cron, an IDE extension); the first install waits for a run that can ask. Updates of an existing installation still run without a terminal, and coding agents still get the tools without a question. ([#7834](https://github.com/databricks/cli/pull/7834)) diff --git a/acceptance/cmd/aitools/auto-install/upgrade/script b/acceptance/cmd/aitools/auto-install/upgrade/script index 0be68b26379..98b3705fab5 100644 --- a/acceptance/cmd/aitools/auto-install/upgrade/script +++ b/acceptance/cmd/aitools/auto-install/upgrade/script @@ -16,6 +16,8 @@ trace cursor_skills echo "my notes" >> "$skills_dir/databricks-dropped/SKILL.md" echo "my notes" >> "$skills_dir/databricks-edited/SKILL.md" +# An update does not ask, so it runs with no terminal and no coding agent too. +unset AGENT title "upgrade to 1.31.0 with release 0.4.0: updates like aitools update, keeping the edited skills" trace DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION=1.31.0 DATABRICKS_CLI_GITHUB_API_URL=$DATABRICKS_HOST/newer $CLI jobs list trace print_telemetry diff --git a/cmd/aitools/autoinstall_run.go b/cmd/aitools/autoinstall_run.go index bb886de1d85..6802ef4d9f3 100644 --- a/cmd/aitools/autoinstall_run.go +++ b/cmd/aitools/autoinstall_run.go @@ -306,15 +306,9 @@ func (r autoInstallRun) attempt(ctx context.Context, prior autoinstall.State) { } } -// autoInstallAsks reports whether auto-install asks before installing: no -// coding agent is detected (see installPromptsSupported), so a person may have -// run the command. It asks only when the question can be seen and answered -// (canAsk) and skips otherwise, with or without a terminal: a run from ssh, -// nohup, cron or an IDE extension has none, and installing there would skip -// the consent of a person who cannot see the question. Coding agents get the -// tools without a question. The question is a plain-text line, so TERM=dumb -// and an MSYS2 pty pipe, which turn off the TUI prompts of install, do not -// skip it. +// autoInstallAsks reports whether auto-install asks before a first install: +// no coding agent is detected. A run that cannot ask (see canAsk) skips; +// coding agents install without a question. func autoInstallAsks() bool { return useragent.AgentProvider() == "" }