diff --git a/.nextchanges/cli/aitools-auto-install-hint-contradiction.md b/.nextchanges/cli/aitools-auto-install-hint-contradiction.md new file mode 100644 index 00000000000..80150c43ad6 --- /dev/null +++ b/.nextchanges/cli/aitools-auto-install-hint-contradiction.md @@ -0,0 +1 @@ +* A coding agent no longer gets the "Databricks skills are not installed" hint on a command after which the automatic installation of Databricks AI tools installs them for that agent, so its output no longer tells it to install what the same command installs. When that installation does not happen, for example because the command failed, the hint appears once the command ends. ([#7890](https://github.com/databricks/cli/pull/7890)) diff --git a/acceptance/cmd/aitools/auto-install/agent-hint/out.test.toml b/acceptance/cmd/aitools/auto-install/agent-hint/out.test.toml new file mode 100644 index 00000000000..18b1a88417e --- /dev/null +++ b/acceptance/cmd/aitools/auto-install/agent-hint/out.test.toml @@ -0,0 +1 @@ +Cloud = false diff --git a/acceptance/cmd/aitools/auto-install/agent-hint/output.txt b/acceptance/cmd/aitools/auto-install/agent-hint/output.txt new file mode 100644 index 00000000000..62ec35240df --- /dev/null +++ b/acceptance/cmd/aitools/auto-install/agent-hint/output.txt @@ -0,0 +1,51 @@ + +=== a failing command: no install, the hint once the command ends + +>>> CLAUDECODE=1 [CLI] jobs get abc +Error: invalid JOB_ID: abc +Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install + +Exit code: 1 + +>>> print_telemetry +{"command":"jobs_get","exit_code":1,"aitools_hint_event":{"hint_kind":"INSTALL_TEXT"}} + +=== first run of a new version: the install notice, no install hint + +>>> CLAUDECODE=1 [CLI] jobs list +Installed Databricks AI tools for Claude Code, Cursor. Disable: databricks aitools auto-install disable + +>>> print_telemetry +{"command":"jobs_list","exit_code":0,"aitools_install_event":{"agents":["CLAUDE_CODE","CURSOR"],"scope":"GLOBAL","error_category":"TYPE_UNSPECIFIED","agent_results":[{"agent":"CLAUDE_CODE","error_category":"CLI_NOT_ON_PATH"}],"trigger":"AUTO_FIRST_RUN"}} +{"command":"jobs_list","exit_code":0,"aitools_auto_install_event":{"outcome":"INSTALLED","holdout_arm":"TREATMENT","interactive":false}} + +=== second run: the tools are installed, nothing + +>>> CLAUDECODE=1 [CLI] jobs list + +>>> print_telemetry + +=== gate off: no install, the hint once the command ends, and on the next + +>>> CLAUDECODE=1 [CLI] jobs list +Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install + +>>> print_telemetry +{"command":"jobs_list","exit_code":0,"aitools_hint_event":{"hint_kind":"INSTALL_TEXT"}} + +>>> CLAUDECODE=1 [CLI] jobs list +Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install + +>>> print_telemetry +{"command":"jobs_list","exit_code":0,"aitools_hint_event":{"hint_kind":"INSTALL_TEXT"}} + +=== an agent the install skips is still hinted: Claude Code has no config dir + +>>> CLAUDECODE=1 [CLI] jobs list +Databricks skills are not installed. To work with Databricks reliably, first run: databricks aitools install +Installed Databricks AI tools for Cursor. Disable: databricks aitools auto-install disable + +>>> print_telemetry +{"command":"jobs_list","exit_code":0,"aitools_hint_event":{"hint_kind":"INSTALL_TEXT"}} +{"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}} diff --git a/acceptance/cmd/aitools/auto-install/agent-hint/script b/acceptance/cmd/aitools/auto-install/agent-hint/script new file mode 100644 index 00000000000..080d464f2aa --- /dev/null +++ b/acceptance/cmd/aitools/auto-install/agent-hint/script @@ -0,0 +1,34 @@ +# Claude Code calls the CLI: its config dir exists and its CLI is not on PATH, +# so auto-install gives it skill files. The install hint must not tell it to +# install what the same run installs. +unset AGENT CLAUDE_CODE_SESSION_ID CLAUDE_CODE_CHILD_SESSION +use_home home +"$mkdir_bin" -p "${USERPROFILE:-$HOME}/.claude" +gate true + +title "a failing command: no install, the hint once the command ends" +errcode trace CLAUDECODE=1 $CLI jobs get abc +trace print_telemetry + +title "first run of a new version: the install notice, no install hint" +trace CLAUDECODE=1 $CLI jobs list +trace print_telemetry + +title "second run: the tools are installed, nothing" +trace CLAUDECODE=1 $CLI jobs list +trace print_telemetry + +title "gate off: no install, the hint once the command ends, and on the next" +use_home no-agents-home +"$mkdir_bin" -p "${USERPROFILE:-$HOME}/.claude" +gate false +trace CLAUDECODE=1 $CLI jobs list +trace print_telemetry +trace CLAUDECODE=1 $CLI jobs list +trace print_telemetry + +title "an agent the install skips is still hinted: Claude Code has no config dir" +use_home holdout-home +gate true +trace CLAUDECODE=1 $CLI jobs list +trace print_telemetry diff --git a/cmd/aitools/autoinstall_hint.go b/cmd/aitools/autoinstall_hint.go new file mode 100644 index 00000000000..8c67da9ebc2 --- /dev/null +++ b/cmd/aitools/autoinstall_hint.go @@ -0,0 +1,49 @@ +package aitools + +import ( + "slices" + + "github.com/databricks/cli/libs/aitools/agents" + "github.com/databricks/cli/libs/aitools/autoinstall" + "github.com/spf13/cobra" +) + +// AutoInstallsFor reports whether the auto-install after cmd may give the +// agent agentName tools (see autoinstall.InstallsFor). It decides as +// autoInstall does up to the gate lookup, which it skips: a run that would +// look the gate up counts as installing, so on a version whose gate is off the +// install hint moves to the end of the command. A machine whose stored ID puts +// it in the holdout never installs. A first install gives tools to the agents +// its plan names; an update gives skills to every agent with a config +// directory when a skill changed, which is only known after the manifest is +// fetched, so it counts as installing for each of them. +func AutoInstallsFor(cmd *cobra.Command, agentName string) bool { + ctx := cmd.Context() + in := autoInstallInputs(ctx, skipsAutoInstall(cmd)) + if slices.Contains(stateFreeSkips, autoinstall.Decide(in)) { + return false + } + var err error + in.State, err = autoinstall.Load(ctx) + if err != nil || autoinstall.Decide(in) != autoinstall.ReasonGateOff { + return false + } + if in.State.ID != "" && autoinstall.InHoldout(autoinstall.Bucket(in.State.ID)) { + return false + } + tools, err := planTools(quietContext(ctx), in.State) + if err != nil || tools.skip != "" { + return false + } + if tools.existing != nil { + return slices.ContainsFunc(agents.DetectInstalled(ctx), func(a *agents.Agent) bool { + return a.Name == agentName + }) + } + for _, it := range tools.plan { + if it.agent.Name == agentName { + return slices.Contains(tools.newAgents(), it.agent.DisplayName) + } + } + return false +} diff --git a/cmd/aitools/autoinstall_hint_test.go b/cmd/aitools/autoinstall_hint_test.go new file mode 100644 index 00000000000..369d633415a --- /dev/null +++ b/cmd/aitools/autoinstall_hint_test.go @@ -0,0 +1,94 @@ +package aitools + +import ( + "context" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/databricks/cli/libs/aitools/agents" + "github.com/databricks/cli/libs/aitools/autoinstall" + "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/dbr" + "github.com/spf13/cobra" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// globalInstallState is a global install state file of an earlier install. +const globalInstallState = `{"schema_version": 2, "release": "v0.1.0", "skills": {"databricks-test": "0.1.0"}}` + +func TestAutoInstallsFor(t *testing.T) { + tests := []struct { + name string + state string + // env is set on top of setupAutoInstallHome's environment. + env map[string]string + // installState replaces the global install state file. + installState string + agent string + command string + want bool + }{ + {name: "first run of a version installs for a detected agent", want: true}, + {name: "a retry installs too", state: `{"id": "treatment-machine", "last_version": "1.30.0", "attempts": 2}`, want: true}, + {name: "a fresh machine with no state installs", state: "{}", want: true}, + {name: "an agent without a config dir is not installed for", agent: agents.NameClaudeCode}, + {name: "a settled version installs nothing", state: `{"id": "treatment-machine", "last_version": "1.30.0"}`}, + {name: "a version whose retries ran out installs nothing", state: `{"id": "treatment-machine", "last_version": "1.30.0", "attempts": 10}`}, + {name: "an opt-out installs nothing", state: `{"id": "treatment-machine", "opted_out": true}`}, + {name: "the env opt-out installs nothing", env: map[string]string{"DATABRICKS_AITOOLS_AUTO_INSTALL": "false"}}, + {name: "CI installs nothing", env: map[string]string{"CI": "true"}}, + {name: "a development build installs nothing", env: map[string]string{"DATABRICKS_AITOOLS_AUTO_INSTALL_CLI_VERSION": ""}}, + {name: "a command that skips auto-install installs nothing", command: "aitools list"}, + {name: "a failed plan installs nothing", installState: "not json"}, + {name: "a holdout machine installs nothing", state: `{"id": "holdout-machine"}`}, + {name: "an update may install for an agent with a config dir", installState: globalInstallState, want: true}, + {name: "an update installs nothing for an agent without a config dir", installState: globalInstallState, agent: agents.NameClaudeCode}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + home := setupAutoInstallHome(t, tc.state, "CLAUDECODE", "1") + for k, v := range tc.env { + t.Setenv(k, v) + } + if tc.installState != "" { + dir := filepath.Join(home, ".databricks", "aitools", "skills") + require.NoError(t, os.MkdirAll(dir, 0o755)) + require.NoError(t, os.WriteFile(filepath.Join(dir, ".state.json"), []byte(tc.installState), 0o600)) + } + t.Cleanup(func() { gateOn = autoinstall.GateOn }) + gateOn = func(context.Context, string) (bool, error) { + t.Error("the gate was looked up") + return true, nil + } + agent, command := tc.agent, tc.command + if agent == "" { + agent = agents.NameCursor + } + if command == "" { + command = "jobs list" + } + ctx := dbr.MockRuntime(cmdio.MockDiscard(t.Context()), dbr.Environment{}) + stateBefore, _ := os.ReadFile(filepath.Join(home, ".databricks", "aitools", "auto-install.json")) + assert.Equal(t, tc.want, AutoInstallsFor(hintTestCommand(ctx, command), agent)) + stateAfter, _ := os.ReadFile(filepath.Join(home, ".databricks", "aitools", "auto-install.json")) + assert.Equal(t, string(stateBefore), string(stateAfter), "the state is only read") + assert.NoDirExists(t, filepath.Join(home, ".cursor", "skills")) + }) + } +} + +// hintTestCommand returns the cobra command at path (two words) under a +// databricks root, with ctx set. +func hintTestCommand(ctx context.Context, path string) *cobra.Command { + group, name, _ := strings.Cut(path, " ") + root := &cobra.Command{Use: "databricks"} + parent := &cobra.Command{Use: group} + cmd := &cobra.Command{Use: name} + root.AddCommand(parent) + parent.AddCommand(cmd) + cmd.SetContext(ctx) + return cmd +} diff --git a/cmd/aitools/autoinstall_run.go b/cmd/aitools/autoinstall_run.go index 8138881157e..27e37d22168 100644 --- a/cmd/aitools/autoinstall_run.go +++ b/cmd/aitools/autoinstall_run.go @@ -135,18 +135,24 @@ func skipsAutoInstall(cmd *cobra.Command) bool { return false } -func autoInstall(ctx context.Context, skippedCommand bool) os.Signal { - version := autoinstall.Version(ctx) - in := autoinstall.Inputs{ +// autoInstallInputs returns the decision inputs that need neither the state +// nor the gate. +func autoInstallInputs(ctx context.Context, skippedCommand bool) autoinstall.Inputs { + return autoinstall.Inputs{ SkippedCommand: skippedCommand, OnRuntime: dbr.RunsOnRuntime(ctx), CacheDisabled: autoinstall.CacheDisabled(ctx), - Version: version, + Version: autoinstall.Version(ctx), RootInUserHome: rootInUserHome(ctx), CI: agents.InCI(ctx), // A "no" earlier in this process counts even if storing it failed. EnvOptOut: autoinstall.EnvOptedOut(ctx) || autoinstall.Declined(), } +} + +func autoInstall(ctx context.Context, skippedCommand bool) os.Signal { + in := autoInstallInputs(ctx, skippedCommand) + version := in.Version // What never auto-installs skips before the state is read, and without a // log line: these are most runs. Root in a user's home is rare, and a user // who always runs the CLI under sudo needs a way to see why nothing diff --git a/cmd/root/root.go b/cmd/root/root.go index 9f8886dd25b..56c199f2d25 100644 --- a/cmd/root/root.go +++ b/cmd/root/root.go @@ -99,9 +99,14 @@ func newRootCommand(ctx context.Context) *cobra.Command { // when it drives the CLI without the tooling installed (best-effort: a // stderr line and a telemetry event that is uploaded at exit). Only the // global install state is read, as for the calling-agent User-Agent. - agents.MaybeHint(ctx, cmd, func(ctx context.Context, agentName string) bool { + deferred := agents.MaybeHint(ctx, cmd, func(ctx context.Context, agentName string) bool { return installer.PluginRecorded(ctx, installer.ScopeGlobal, agentName) }) + // A hint withheld for auto-install prints once the command has ended. + // Commands run without execute have no slot, and then it is dropped. + if slot, ok := ctx.Value(deferredHintKey{}).(*func()); ok { + *slot = deferred + } return nil } @@ -131,6 +136,11 @@ func newRootCommand(ctx context.Context) *cobra.Command { // the context. It holds the signal that stopped auto-install, if one did. type caughtSignalKey struct{} +// deferredHintKey is the context key of the *func() that execute puts in the +// context. It holds the agent hint withheld for auto-install, if one was (see +// agents.MaybeHint). +type deferredHintKey struct{} + // raise is process.Raise; tests replace it. var raise = process.Raise @@ -194,6 +204,8 @@ Stack Trace: ctx = context.WithValue(ctx, logFileKey{}, &logFile) var caught os.Signal ctx = context.WithValue(ctx, caughtSignalKey{}, &caught) + var deferredHint func() + ctx = context.WithValue(ctx, deferredHintKey{}, &deferredHint) // slog.SetDefault also redirects the standard log package, so both are restored. prevLogger := slog.Default() prevLogWriter, prevLogFlags := stdlog.Writer(), stdlog.Flags() @@ -228,6 +240,12 @@ Stack Trace: fmt.Fprintf(cmd.ErrOrStderr(), "Error: %s\n", err.Error()) } + // After auto-install, which runs only when the command succeeded, and + // before the telemetry upload, which sends its hint-shown event. + if deferredHint != nil { + deferredHint() + } + exitCode := ExitStatus(err) // Log exit status and error diff --git a/libs/aitools/agents/hint.go b/libs/aitools/agents/hint.go index f3c49839721..66dda383a97 100644 --- a/libs/aitools/agents/hint.go +++ b/libs/aitools/agents/hint.go @@ -5,6 +5,7 @@ import ( "strings" "time" + "github.com/databricks/cli/libs/aitools/autoinstall" "github.com/databricks/cli/libs/cache" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/env" @@ -109,6 +110,9 @@ var ( // agentHint describes how one calling agent is nudged to install the // Databricks AI tooling. type agentHint struct { + // agentName is the registry name of the hinted agent. + agentName string + // installed reports whether the agent already has the tooling; when it // does, nothing is printed. installed func(ctx context.Context) bool @@ -159,6 +163,7 @@ func hintForAgent(provider string, pluginRecorded PluginRecordedFunc) *agentHint switch provider { case claudeAgentProvider: return &agentHint{ + agentName: NameClaudeCode, installed: claudeToolingInstalled, text: hintText, textKind: protos.AitoolsHintKindInstallText, @@ -205,22 +210,28 @@ func (h *agentHint) nativeLine(ctx context.Context) string { // Best-effort: it never fails the command. Besides the stderr lines, it logs a // telemetry event for each hint line shown, which makes a command that resolved // auth upload telemetry at exit. -func MaybeHint(ctx context.Context, cmd *cobra.Command, pluginRecorded PluginRecordedFunc) { +// +// When the auto-install after cmd may give the agent its tools (see +// autoinstall.InstallsFor), the hint is withheld: MaybeHint returns a function +// to call once the command has ended, which prints the hint unless the tooling +// is installed by then. A failed command, a gate that turns out off or a +// failed install then still gets the hint. Otherwise it returns nil. +func MaybeHint(ctx context.Context, cmd *cobra.Command, pluginRecorded PluginRecordedFunc) (deferred func()) { hint := hintForAgent(useragent.AgentProvider(), pluginRecorded) if hint == nil { - return + return nil } if isHintExemptCommand(cmd) { - return + return nil } if IsCredentialHelperCommand(cmd) { - return + return nil } if IsSelfExec(ctx) { - return + return nil } if !cmdio.HasIO(ctx) { - return + return nil } // Check the throttles before the filesystem probe, so a throttled session // skips the plugin/skills detection. A marker is written only once its @@ -233,14 +244,32 @@ func MaybeHint(ctx context.Context, cmd *cobra.Command, pluginRecorded PluginRec } textDue := !textHintThrottle.seen(ctx, key) if native == "" && !textDue { - return + return nil } if hint.installed(ctx) { - return + return nil + } + // The auto-install after this command prints its own notice; neither line + // may tell the agent to install what it installs. No marker is written + // until the hint prints. + if autoinstall.InstallsFor != nil && autoinstall.InstallsFor(cmd, hint.agentName) { + return func() { + if hint.installed(ctx) { + return + } + hint.show(ctx, key, native, textDue) + } } + hint.show(ctx, key, native, textDue) + return nil +} + +// show prints the lines MaybeHint found due, records their throttle markers +// and logs their hint-shown events. +func (h *agentHint) show(ctx context.Context, key, native string, textDue bool) { // Only agents without a native line have a durable throttle, so a failed // claim leaves nothing to print. - if textDue && !hint.claim(ctx, key) { + if textDue && !h.claim(ctx, key) { return } if native != "" { @@ -249,15 +278,15 @@ func MaybeHint(ctx context.Context, cmd *cobra.Command, pluginRecorded PluginRec // A text print starts a new text window, in which this is the first // native print. if textDue || !nativeEventThrottle.seen(ctx, key) { - logHintShown(ctx, hint.nativeKind) + logHintShown(ctx, h.nativeKind) nativeEventThrottle.set(ctx, key, true) } - } else if textDue && hint.native != nil { + } else if textDue && h.native != nil { nativeEventThrottle.set(ctx, key, false) } if textDue { - cmdio.LogString(ctx, hint.text) - logHintShown(ctx, hint.textKind) + cmdio.LogString(ctx, h.text) + logHintShown(ctx, h.textKind) } } diff --git a/libs/aitools/agents/hint_agents.go b/libs/aitools/agents/hint_agents.go index 68a3935b8af..9552ea62af0 100644 --- a/libs/aitools/agents/hint_agents.go +++ b/libs/aitools/agents/hint_agents.go @@ -35,6 +35,7 @@ type PluginRecordedFunc func(ctx context.Context, agentName string) bool // hinted; the throttle bounds that to once per session or per TTL. func agentInstallHint(a *Agent, pluginRecorded PluginRecordedFunc) *agentHint { return &agentHint{ + agentName: a.Name, installed: func(ctx context.Context) bool { recorded := func() bool { return pluginRecorded(ctx, a.Name) } return a.DatabricksTooling(ctx, recorded) != ToolingNone diff --git a/libs/aitools/agents/hint_test.go b/libs/aitools/agents/hint_test.go index c3f092e1eae..1884d296150 100644 --- a/libs/aitools/agents/hint_test.go +++ b/libs/aitools/agents/hint_test.go @@ -13,6 +13,7 @@ import ( "time" "github.com/databricks/cli/internal/testutil" + "github.com/databricks/cli/libs/aitools/autoinstall" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/env" "github.com/databricks/cli/libs/flags" @@ -806,3 +807,87 @@ func TestMaybeHint_ProjectSkillsInstalledSilent(t *testing.T) { }) } } + +// setInstallsFor replaces autoinstall.InstallsFor for the test and returns the +// agent names it was asked about. +func setInstallsFor(t *testing.T, installs bool) *[]string { + var asked []string + prev := autoinstall.InstallsFor + autoinstall.InstallsFor = func(_ *cobra.Command, agentName string) bool { + asked = append(asked, agentName) + return installs + } + t.Cleanup(func() { autoinstall.InstallsFor = prev }) + return &asked +} + +func TestMaybeHint_WithheldWhileAutoInstallInstallsForTheAgent(t *testing.T) { + setClaudeAgent(t) + home, cacheDir := t.TempDir(), t.TempDir() + asked := setInstallsFor(t, true) + + // The run installs: both lines are withheld, and no event or throttle + // marker is written. + ctx1, stderr1 := sessionCtx(t, home, cacheDir, true) + deferred := MaybeHint(ctx1, regularCmd(), noPluginRecorded) + require.NotNil(t, deferred) + assert.Equal(t, []string{NameClaudeCode}, *asked) + writeClaudeSkill(t, home, "databricks-core") + deferred() + assert.Empty(t, stderr1.String()) + assert.Empty(t, hintKinds(t, ctx1)) +} + +func TestMaybeHint_WithheldHintPrintsWhenTheRunDidNotInstall(t *testing.T) { + setClaudeAgent(t) + home, cacheDir := t.TempDir(), t.TempDir() + setInstallsFor(t, true) + + // Nothing prints before the command; once it ended without the tools + // (it failed, the gate was off or the install failed), both lines do. + ctx1, stderr1 := sessionCtx(t, home, cacheDir, true) + deferred := MaybeHint(ctx1, regularCmd(), noPluginRecorded) + require.NotNil(t, deferred) + assert.Empty(t, stderr1.String()) + deferred() + assert.Contains(t, stderr1.String(), wantNativeHint) + assert.Contains(t, stderr1.String(), hintText) + assert.Equal(t, []protos.AitoolsHintKind{protos.AitoolsHintKindClaudeCodeNative, protos.AitoolsHintKindInstallText}, hintKinds(t, ctx1)) + + // The markers were written then: the session's next command is throttled. + ctx2, stderr2 := sessionCtx(t, home, cacheDir, true) + assert.Nil(t, MaybeHint(ctx2, regularCmd(), noPluginRecorded)) + assert.Empty(t, stderr2.String()) +} + +func TestMaybeHint_NotWithheldWithoutAutoInstall(t *testing.T) { + setClaudeAgent(t) + setInstallsFor(t, false) + ctx, stderr := sessionCtx(t, t.TempDir(), t.TempDir(), true) + assert.Nil(t, MaybeHint(ctx, regularCmd(), noPluginRecorded)) + assert.Contains(t, stderr.String(), hintText) +} + +func TestMaybeHint_RegistryAgentAskedByItsName(t *testing.T) { + testutil.SetAgentEnv(t, "CURSOR_AGENT", "1") + cwd := t.TempDir() + require.NoError(t, os.Mkdir(filepath.Join(cwd, ".git"), 0o755)) + t.Chdir(cwd) + asked := setInstallsFor(t, true) + ctx, stderr := claudeCtx(t, t.TempDir()) + ctx = telemetry.WithNewLogger(ctx) + assert.NotNil(t, MaybeHint(ctx, regularCmd(), noPluginRecorded)) + assert.Empty(t, stderr.String()) + assert.Empty(t, hintKinds(t, ctx)) + assert.Equal(t, []string{NameCursor}, *asked) +} + +func TestMaybeHint_InstalledToolingSkipsTheAutoInstallCheck(t *testing.T) { + setClaudeAgent(t) + home := t.TempDir() + writeClaudeSkill(t, home, "databricks-core") + asked := setInstallsFor(t, true) + ctx, _ := claudeCtx(t, home) + assert.Nil(t, MaybeHint(ctx, regularCmd(), noPluginRecorded)) + assert.Empty(t, *asked) +} diff --git a/libs/aitools/autoinstall/hook.go b/libs/aitools/autoinstall/hook.go index e22746c2caf..8883d24d035 100644 --- a/libs/aitools/autoinstall/hook.go +++ b/libs/aitools/autoinstall/hook.go @@ -16,3 +16,12 @@ import ( // command ends the CLI by it once it uploaded the telemetry and closed the log // file. var Run func(cmd *cobra.Command) os.Signal + +// InstallsFor, when set, reports whether the Run after cmd may give the agent +// with this registry name Databricks AI tools. The install hint, printed before +// the command runs, is withheld then so the agent is not told to install what +// the same run installs. It reads only local state: the gate is looked up +// after the command, Run is skipped when the command fails, and an install can +// fail, so the withheld hint prints when the command ends unless the agent has +// the tools by then. main.go sets it with Run. +var InstallsFor func(cmd *cobra.Command, agentName string) bool diff --git a/main.go b/main.go index a08ab8c2ec9..e562ee8a16c 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ func main() { // which imports it. It is wired here, not in a package init, for the same // reason as DATABRICKS_CLI_PATH above. autoinstall.Run = aitools.AutoInstall + autoinstall.InstallsFor = aitools.AutoInstallsFor ctx := context.Background() err := cmd.New(ctx).Execute(ctx, os.Args[1:])