Repository navigation
aitools: don't hint an install that auto-install is about to make #7890
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
base: main
Are you sure you want to change the base?
Changes from all commits
24b61a7
b117245
c876dc0
cb5377d
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 @@ | ||
| * 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)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Cloud = false |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
Comment on lines
+22
to
+31
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] |
||
| gate true | ||
| trace CLAUDECODE=1 $CLI jobs list | ||
| trace print_telemetry | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
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. [nice to have] 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. [nice to have]
anton-107 marked this conversation as resolved.
Resolved
|
||
| 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 | ||
| }) | ||
|
Comment on lines
+38
to
+41
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] For an existing global install, this returns true for every agent with a config dir. But |
||
| } | ||
| for _, it := range tools.plan { | ||
|
Contributor
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. [non-blocking] An update plan has no items, so this returns false when the global install predates the calling agent. With tools installed for Cursor only and |
||
| if it.agent.Name == agentName { | ||
| return slices.Contains(tools.newAgents(), it.agent.DisplayName) | ||
| } | ||
| } | ||
| return false | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
| } | ||
|
Comment on lines
+243
to
+247
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. [nice to have] The withheld hint prints only when
These runs never reach auto-install either, so the version stays pending and each such run withholds the hint again. While the gate is off, this happens on every machine for the first commands of each version. Options: print the withheld hint before |
||
|
|
||
| exitCode := ExitStatus(err) | ||
|
|
||
| // Log exit status and error | ||
|
|
||
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] This case expects
jobs get abcto fail..agents/rules/testing.mdsays to assert an expected failure withmusterr CMDand keeperrcodefor tolerated non-zero exits. Usemusterr trace CLAUDECODE=1 $CLI jobs get abc.