From b6e70db34f1d6c6b262767848e952716569b9ca5 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:38:43 +0000 Subject: [PATCH 1/6] aitools: keep --skills-only agents on raw skills during update ## Changes `databricks aitools install --skills-only` now records which agents the user kept on raw skills, and `databricks aitools update` leaves those agents alone instead of moving them to the Databricks plugin. - `InstallState` has a new `skills_only_agents` field: a sorted list of agent names, left out of the file when it is empty. - `install --skills-only` sets the new `InstallOptions.SkillsOnly`. `InstallSkillsForAgents` then adds every target agent that supports a plugin and has its CLI on PATH to that list. - An agent whose CLI is missing is not added. `install` suggests `--skills-only` in that case too, so the user didn't turn the plugin down, and `update` should still migrate the agent once the CLI is installed. - `pluginMigrationCandidatesForScope` skips agents in the list, so `update` and `update --check` no longer migrate them or report that they would. Their raw skills still get refreshed as before. - `RecordPluginInstalls` takes an agent off the list once the plugin is installed for it. Running `install` again without `--skills-only` leaves the list as it is. ```diff pluginMigrationCandidatesForScope skip agents without a plugin skip agents already on the plugin + skip agents in state.SkillsOnlyAgents skip agents whose CLI is not on PATH skip agents without managed raw skills ``` ## Why For Claude Code, Codex and GitHub Copilot, `update` replaces CLI-managed raw skills with the plugin whenever the agent's CLI is on PATH. The state file couldn't tell skills installed with `--skills-only` apart from skills written by an older CLI or while the agent's CLI was missing. So the next `update` undid the user's `--skills-only` choice. Now that choice is saved, and only raw skills the user didn't choose get migrated. To move an agent to the plugin, run `databricks aitools install` without `--skills-only`. ## Tests New unit tests: - `TestInstallSkillsForAgentsRecordsSkillsOnlyAgents`: only agents with a plugin and their CLI on PATH are recorded, and a later install without `--skills-only` keeps the list. - `TestRecordPluginInstallsForgetsSkillsOnlyChoice`: installing the plugin for an agent takes only that agent off the list. - `TestPluginMigrationCandidatesSkipSkillsOnlyAgents`: agents in the list are not migration candidates, and other agents with raw skills still are. - `TestUpdateKeepsSkillsOnlyAgentsOnRawSkills`: `update --check` reports no migration, and `update` refreshes the raw skills without installing the plugin or cleaning up the skills. - The existing tests for `install --skills-only` and state round-tripping now also check the new option and field. `go test ./cmd/aitools/... ./libs/aitools/installer/...` passes. Adds the changelog fragment `.nextchanges/cli/aitools-update-keeps-skills-only.md`. Co-authored-by: Isaac --- .../cli/aitools-update-keeps-skills-only.md | 1 + cmd/aitools/install.go | 1 + cmd/aitools/install_test.go | 1 + cmd/aitools/update.go | 4 + cmd/aitools/update_test.go | 80 +++++++++++++++++++ libs/aitools/installer/installer.go | 14 ++++ libs/aitools/installer/installer_test.go | 44 ++++++++++ libs/aitools/installer/plugin.go | 5 ++ libs/aitools/installer/plugin_test.go | 22 +++++ libs/aitools/installer/state.go | 7 ++ libs/aitools/installer/state_test.go | 3 +- 11 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 .nextchanges/cli/aitools-update-keeps-skills-only.md diff --git a/.nextchanges/cli/aitools-update-keeps-skills-only.md b/.nextchanges/cli/aitools-update-keeps-skills-only.md new file mode 100644 index 00000000000..69ef338d766 --- /dev/null +++ b/.nextchanges/cli/aitools-update-keeps-skills-only.md @@ -0,0 +1 @@ +* `databricks aitools update` no longer replaces the skill files that `databricks aitools install --skills-only` gave Claude Code, Codex or GitHub Copilot with the Databricks plugin. Run `databricks aitools install` without `--skills-only` to switch such an agent to the plugin. diff --git a/cmd/aitools/install.go b/cmd/aitools/install.go index 821870f21da..c9db7557644 100644 --- a/cmd/aitools/install.go +++ b/cmd/aitools/install.go @@ -196,6 +196,7 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "), opts := installer.InstallOptions{ IncludeExperimental: includeExperimental, SpecificSkills: splitAndTrim(skillsFlag), + SkillsOnly: skillsOnly, } // --skills cherry-picks individual skill files, which only applies to diff --git a/cmd/aitools/install_test.go b/cmd/aitools/install_test.go index 02f3e3ce1f4..298a878419e 100644 --- a/cmd/aitools/install_test.go +++ b/cmd/aitools/install_test.go @@ -906,6 +906,7 @@ func TestInstallSkillsOnlyAllAgents(t *testing.T) { require.Len(t, *calls, 1) assert.Len(t, (*calls)[0].agents, 2) assert.Nil(t, (*calls)[0].opts.SpecificSkills) + assert.True(t, (*calls)[0].opts.SkillsOnly) } func TestInstallSkillsOnlySpecificSkills(t *testing.T) { diff --git a/cmd/aitools/update.go b/cmd/aitools/update.go index 8ab71a87e65..b4865afa570 100644 --- a/cmd/aitools/update.go +++ b/cmd/aitools/update.go @@ -299,6 +299,10 @@ func pluginMigrationCandidatesForScope(ctx context.Context, scope string, state if _, alreadyPlugin := state.Plugins[agent.Name]; alreadyPlugin { continue } + // The user chose raw skills over the plugin (install --skills-only). + if slices.Contains(state.SkillsOnlyAgents, agent.Name) { + continue + } } nativeScope, ok, _ := mapAgentScope(agent, scope) if !ok { diff --git a/cmd/aitools/update_test.go b/cmd/aitools/update_test.go index ad6ad104776..54a2e328887 100644 --- a/cmd/aitools/update_test.go +++ b/cmd/aitools/update_test.go @@ -356,6 +356,68 @@ func TestUpdateDoesNotMigratePluginAgentWithoutManagedRawSkills(t *testing.T) { assert.Equal(t, []string{agents.NameClaudeCode, agents.NameCursor}, rawUpdateAgents) } +// Raw skills the user chose with install --skills-only stay raw skills: update +// neither plans nor runs their migration to the plugin, and refreshes them. +func TestUpdateKeepsSkillsOnlyAgentsOnRawSkills(t *testing.T) { + noTelemetryAuth(t) + setupTestAgents(t) + fakeBinsOnPath(t, "claude") + t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6") + resetUpdatePluginSeams(t) + + var rawUpdateAgents []string + origUpdateSkills := updateSkillsFn + t.Cleanup(func() { updateSkillsFn = origUpdateSkills }) + updateSkillsFn = func(_ context.Context, _ installer.ManifestSource, targetAgents []*agents.Agent, opts installer.UpdateOptions) (*installer.UpdateResult, error) { + if !opts.Check { + for _, a := range targetAgents { + rawUpdateAgents = append(rawUpdateAgents, a.Name) + } + } + return &installer.UpdateResult{}, nil + } + updatePluginsFn = func(context.Context, string, string) ([]installer.PluginUpdate, error) { + return nil, nil + } + updateInstallPluginForAgentFn = func(context.Context, *agents.Agent, string, string) (installer.PluginRecord, error) { + require.Fail(t, "must not migrate an agent the user put on raw skills") + return installer.PluginRecord{}, nil + } + updateRecordPluginInstallsFn = func(context.Context, string, map[string]installer.PluginRecord, string) error { + require.Fail(t, "must not record plugin installs without migration") + return nil + } + updateCleanupLegacyFn = func(context.Context, *agents.Agent, string) error { + require.Fail(t, "must not clean up the raw skills the user chose") + return nil + } + hasManagedRawSkillsForAgentFn = func(_ context.Context, a *agents.Agent, _ string) (bool, error) { + return a.Plugin != nil, nil + } + + ctx, stderr := cmdio.NewTestContextWithStderr(t.Context()) + dir, err := installer.GlobalSkillsDir(ctx) + require.NoError(t, err) + require.NoError(t, installer.SaveState(dir, &installer.InstallState{ + SchemaVersion: 2, + Release: "v0.2.5", + Skills: map[string]string{"databricks": "0.2.5"}, + SkillsOnlyAgents: []string{agents.NameClaudeCode}, + })) + + check := NewUpdateCmd() + check.SetContext(ctx) + check.SetArgs([]string{"--scope", "global", "--check"}) + require.NoError(t, check.Execute()) + assert.NotContains(t, stderr.String(), "would migrate") + + update := NewUpdateCmd() + update.SetContext(ctx) + update.SetArgs([]string{"--scope", "global"}) + require.NoError(t, update.Execute()) + assert.Equal(t, []string{agents.NameClaudeCode, agents.NameCursor}, rawUpdateAgents) +} + func TestUpdateNoPruneFlag(t *testing.T) { noTelemetryAuth(t) setupTestAgents(t) @@ -490,6 +552,24 @@ func TestPluginMigrationCandidatesNeedTheCLI(t *testing.T) { assert.Equal(t, []string{agents.NameCodex}, names) } +// Only the agents the user put on raw skills with install --skills-only stay +// there; other raw skills (an older CLI, a missing agent CLI) still migrate. +func TestPluginMigrationCandidatesSkipSkillsOnlyAgents(t *testing.T) { + setupTestAgents(t) + fakeBinsOnPath(t, "claude", "codex", "copilot") + resetUpdatePluginSeams(t) + hasManagedRawSkillsForAgentFn = func(context.Context, *agents.Agent, string) (bool, error) { return true, nil } + + state := &installer.InstallState{SkillsOnlyAgents: []string{agents.NameClaudeCode, agents.NameCodex}} + candidates, err := pluginMigrationCandidatesForScope(t.Context(), installer.ScopeGlobal, state) + require.NoError(t, err) + var names []string + for _, c := range candidates { + names = append(names, c.agent.Name) + } + assert.Equal(t, []string{agents.NameCopilot}, names) +} + // Install keeps a plugin installed with Claude Code's own CLI without recording // it, so update must not write the raw skills back next to it. A project's // skill files are shared, so at project scope only a project-scope plugin of diff --git a/libs/aitools/installer/installer.go b/libs/aitools/installer/installer.go index f2603739964..ae6f67a7be3 100644 --- a/libs/aitools/installer/installer.go +++ b/libs/aitools/installer/installer.go @@ -226,6 +226,9 @@ type InstallOptions struct { IncludeExperimental bool SpecificSkills []string // empty = all skills Scope string // ScopeGlobal or ScopeProject (default: global) + // SkillsOnly records the target agents that could have had the plugin in + // InstallState.SkillsOnlyAgents: the user chose raw skills for them. + SkillsOnly bool } func fetchSkillFile(ctx context.Context, ref, repoDir, skillName, filePath string) ([]byte, error) { @@ -472,6 +475,17 @@ func InstallSkillsForAgents(ctx context.Context, src ManifestSource, targetAgent // enabled; this field does not retroactively remove them. state.IncludeExperimental = opts.IncludeExperimental state.Scope = scope + if opts.SkillsOnly { + for _, a := range targetAgents { + // Without its CLI on PATH the agent could not have had the plugin: + // install suggests --skills-only for that case too, and update + // should migrate the agent once the CLI is there. + if a.Plugin != nil && a.HasBinary(ctx) && !slices.Contains(state.SkillsOnlyAgents, a.Name) { + state.SkillsOnlyAgents = append(state.SkillsOnlyAgents, a.Name) + } + } + slices.Sort(state.SkillsOnlyAgents) + } for name, meta := range targetSkills { state.Skills[name] = meta.Version state.RepoDirs[name] = meta.RepoDir diff --git a/libs/aitools/installer/installer_test.go b/libs/aitools/installer/installer_test.go index 13013982a02..b400cf0e381 100644 --- a/libs/aitools/installer/installer_test.go +++ b/libs/aitools/installer/installer_test.go @@ -13,6 +13,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "runtime" "sync" "syscall" "testing" @@ -460,6 +461,49 @@ func TestInstallSkillsForAgentsWritesState(t *testing.T) { assert.Contains(t, stderr.String(), "Installed 2 skills in ") } +// --skills-only records the agents that could have had the plugin (their CLI +// is on PATH), so update keeps them on raw skills. An agent whose CLI is +// missing is not recorded: install suggests --skills-only for it, and update +// migrates it once the CLI is there. A later install without --skills-only +// keeps the record: it says nothing about the user's choice. +func TestInstallSkillsForAgentsRecordsSkillsOnlyAgents(t *testing.T) { + tmp := setupTestHome(t) + ctx := cmdio.MockDiscard(t.Context()) + setupFetchMock(t) + t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) + src := &mockManifestSource{manifest: testManifest()} + + binDir := t.TempDir() + binName := "plugin-agent-cli" + if runtime.GOOS == "windows" { + binName += ".exe" + } + require.NoError(t, os.WriteFile(filepath.Join(binDir, binName), []byte("#!/bin/sh\n"), 0o755)) + t.Setenv("PATH", binDir) + + plain := testAgent(tmp) + withPlugin := testAgent(tmp) + withPlugin.Name = "plugin-agent" + withPlugin.Binary = "plugin-agent-cli" + withPlugin.Plugin = &agents.PluginSpec{} + cliMissing := testAgent(tmp) + cliMissing.Name = "cli-missing-agent" + cliMissing.Binary = "cli-missing-agent-cli" + cliMissing.Plugin = &agents.PluginSpec{} + targets := []*agents.Agent{withPlugin, cliMissing, plain} + globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills") + + require.NoError(t, InstallSkillsForAgents(ctx, src, targets, InstallOptions{SkillsOnly: true})) + state, err := LoadState(globalDir) + require.NoError(t, err) + assert.Equal(t, []string{"plugin-agent"}, state.SkillsOnlyAgents) + + require.NoError(t, InstallSkillsForAgents(ctx, src, targets, InstallOptions{})) + state, err = LoadState(globalDir) + require.NoError(t, err) + assert.Equal(t, []string{"plugin-agent"}, state.SkillsOnlyAgents) +} + func setupSkillsFallback(t *testing.T, latestErr error) (ManifestSource, string) { t.Helper() setBuildVersion(t, "1.22.0") diff --git a/libs/aitools/installer/plugin.go b/libs/aitools/installer/plugin.go index af595e7153a..494d1709f99 100644 --- a/libs/aitools/installer/plugin.go +++ b/libs/aitools/installer/plugin.go @@ -7,6 +7,7 @@ import ( "maps" "path/filepath" "regexp" + "slices" "strings" "sync" "time" @@ -503,6 +504,10 @@ func RecordPluginInstalls(ctx context.Context, cliScope string, records map[stri state.Plugins = make(map[string]PluginRecord, len(records)) } maps.Copy(state.Plugins, records) + state.SkillsOnlyAgents = slices.DeleteFunc(state.SkillsOnlyAgents, func(name string) bool { + _, ok := records[name] + return ok + }) // An unresolved release keeps the one recorded by earlier installs. if ref != "" { state.Release = ref diff --git a/libs/aitools/installer/plugin_test.go b/libs/aitools/installer/plugin_test.go index fd0552cc99f..e8c776fa6f5 100644 --- a/libs/aitools/installer/plugin_test.go +++ b/libs/aitools/installer/plugin_test.go @@ -820,6 +820,28 @@ func TestRecordPluginInstallsUnresolvedRefKeepsRelease(t *testing.T) { assert.Contains(t, st.Plugins, agents.NameCodex) } +// Installing the plugin for an agent the user had put on raw skills ends that +// choice; the other agents keep theirs. +func TestRecordPluginInstallsForgetsSkillsOnlyChoice(t *testing.T) { + setupTestHome(t) + ctx := cmdio.MockDiscard(t.Context()) + dir, err := GlobalSkillsDir(ctx) + require.NoError(t, err) + require.NoError(t, SaveState(dir, &InstallState{ + SchemaVersion: CurrentSchemaVersion, + Skills: map[string]string{"databricks": "0.1.0"}, + SkillsOnlyAgents: []string{agents.NameClaudeCode, agents.NameCodex}, + })) + + require.NoError(t, RecordPluginInstalls(ctx, ScopeGlobal, map[string]PluginRecord{ + agents.NameCodex: {Marketplace: "databricks-agent-skills", Plugin: "databricks"}, + }, "v0.2.6")) + + st, err := LoadState(dir) + require.NoError(t, err) + assert.Equal(t, []string{agents.NameClaudeCode}, st.SkillsOnlyAgents) +} + func TestRecordPluginInstallsThenSkillsInstallNoPanic(t *testing.T) { tmp := setupTestHome(t) ctx := cmdio.MockDiscard(t.Context()) diff --git a/libs/aitools/installer/state.go b/libs/aitools/installer/state.go index f44c33921d4..5f236a22baa 100644 --- a/libs/aitools/installer/state.go +++ b/libs/aitools/installer/state.go @@ -59,6 +59,13 @@ type InstallState struct { // e.g. "databricks/SKILL.md"). Added in schema v2; used to prune only the // skills we wrote that the user hasn't modified. Files map[string]FileRecord `json:"files,omitempty"` + // SkillsOnlyAgents names, sorted, the agents with a plugin that + // `install --skills-only` gave raw skills while their CLI was on PATH, so + // the plugin was declined, not unavailable. Update keeps them on raw + // skills. Raw skills of other plugin agents were written by an older CLI or + // while the agent's CLI was missing, and update migrates those to the + // plugin. Recording a plugin install for an agent removes its name. + SkillsOnlyAgents []string `json:"skills_only_agents,omitempty"` // MCP records the Databricks MCP servers the `aitools mcp` commands wrote. // Added in schema v3; omitted when none are recorded. SaveState ignores this // field and keeps the section on disk; SaveMCPState is the only writer of it. diff --git a/libs/aitools/installer/state_test.go b/libs/aitools/installer/state_test.go index feeb59d81bd..e92ba66d85d 100644 --- a/libs/aitools/installer/state_test.go +++ b/libs/aitools/installer/state_test.go @@ -199,7 +199,8 @@ func TestSaveAndLoadStateWithOptionalFields(t *testing.T) { "databricks": stableSkillsRepoPath, "sql-tools": experimentalRepoPath, }, - Scope: "project", + Scope: "project", + SkillsOnlyAgents: []string{"claude-code", "codex"}, } err := SaveState(dir, original) From 201fc768686b8a0fd120fa28eb2758edc8643660 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:50:56 +0000 Subject: [PATCH 2/6] Add PR link to the aitools update changelog fragment Co-authored-by: Isaac --- .nextchanges/cli/aitools-update-keeps-skills-only.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/cli/aitools-update-keeps-skills-only.md b/.nextchanges/cli/aitools-update-keeps-skills-only.md index 69ef338d766..c75c66cf395 100644 --- a/.nextchanges/cli/aitools-update-keeps-skills-only.md +++ b/.nextchanges/cli/aitools-update-keeps-skills-only.md @@ -1 +1 @@ -* `databricks aitools update` no longer replaces the skill files that `databricks aitools install --skills-only` gave Claude Code, Codex or GitHub Copilot with the Databricks plugin. Run `databricks aitools install` without `--skills-only` to switch such an agent to the plugin. +* `databricks aitools update` no longer replaces the skill files that `databricks aitools install --skills-only` gave Claude Code, Codex or GitHub Copilot with the Databricks plugin. Run `databricks aitools install` without `--skills-only` to switch such an agent to the plugin. ([#7831](https://github.com/databricks/cli/pull/7831)) From 06c8e20e3e17ba65e9976c82b941afaae121ea48 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:06:46 +0000 Subject: [PATCH 3/6] aitools: a failed plugin install ends the --skills-only choice An install that tries the plugin for an agent the user had put on raw skills now drops that agent from the --skills-only record even when the plugin install fails, so update tries the plugin again. Also note on the field that an older CLI rewriting the state drops it. Co-authored-by: Isaac --- cmd/aitools/install.go | 10 ++++++++ cmd/aitools/install_test.go | 33 +++++++++++++++++++++++++++ libs/aitools/installer/plugin.go | 24 +++++++++++++++++++ libs/aitools/installer/plugin_test.go | 32 ++++++++++++++++++++++++++ libs/aitools/installer/state.go | 7 +++++- 5 files changed, 105 insertions(+), 1 deletion(-) diff --git a/cmd/aitools/install.go b/cmd/aitools/install.go index c9db7557644..dde06d6531c 100644 --- a/cmd/aitools/install.go +++ b/cmd/aitools/install.go @@ -957,6 +957,7 @@ func executePlan(ctx context.Context, src installer.ManifestSource, plan []agent ref = "" } records := map[string]installer.PluginRecord{} + var failed []string for _, it := range pluginItems { if !quiet { cmdio.LogString(ctx, fmt.Sprintf("Installing databricks plugin for %s...", it.agent.DisplayName)) @@ -979,6 +980,7 @@ func executePlan(ctx context.Context, src installer.ManifestSource, plan []agent if it.explicit { explicitErrs = append(explicitErrs, &displayError{msg: it.agent.DisplayName + ": " + reason, err: err}) } + failed = append(failed, it.agent.Name) continue } records[it.agent.Name] = rec @@ -993,6 +995,14 @@ func executePlan(ctx context.Context, src installer.ManifestSource, plan []agent cmdio.LogString(ctx, fmt.Sprintf(" %s databricks plugin %s", it.agent.DisplayName, versionToken(rec.Version))) } } + // Asking for the plugin ends an earlier --skills-only choice even when + // the install fails, so update tries the plugin again. A successful + // install ends it when the plugin is recorded. + if len(failed) > 0 { + if err := installer.ForgetSkillsOnlyChoice(ctx, opts.Scope, failed); err != nil { + log.Warnf(ctx, "Could not drop the --skills-only choice for %s: %v", strings.Join(failed, ", "), err) + } + } if len(records) > 0 && skillsErr != nil && installer.HasUntrackedSkills(ctx, opts.Scope) { // Skills with no state file are on disk (an install that predates // state tracking, or an interrupted first install). A state file diff --git a/cmd/aitools/install_test.go b/cmd/aitools/install_test.go index 298a878419e..a581d905dd0 100644 --- a/cmd/aitools/install_test.go +++ b/cmd/aitools/install_test.go @@ -373,6 +373,39 @@ func TestExecutePlanSkipBlockedPluginExit0(t *testing.T) { assert.NotErrorIs(t, err, errNoAgentSetUp) } +// An install that tries the plugin for an agent the user had put on raw skills +// ends that choice even when the plugin install fails, so update tries the +// plugin again. The choice of an agent not asked for the plugin stays. +func TestExecutePlanFailedPluginForgetsSkillsOnlyChoice(t *testing.T) { + setupTestAgents(t) + t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6") + fakeBinsOnPath(t, "claude") + orig := installPluginForAgentFn + t.Cleanup(func() { installPluginForAgentFn = orig }) + installPluginForAgentFn = func(_ context.Context, a *agents.Agent, _, _ string) (installer.PluginRecord, error) { + return installer.PluginRecord{}, &installer.BlockedError{Agent: a.Name, Reason: installer.ReasonInstallFailed} + } + + ctx := cmdio.MockDiscard(t.Context()) + dir, err := installer.GlobalSkillsDir(ctx) + require.NoError(t, err) + require.NoError(t, installer.SaveState(dir, &installer.InstallState{ + SchemaVersion: installer.CurrentSchemaVersion, + Release: "v0.2.5", + Skills: map[string]string{"databricks": "0.2.5"}, + SkillsOnlyAgents: []string{agents.NameClaudeCode, agents.NameCodex}, + })) + + claude := testPluginAgent(agents.NameClaudeCode, "Claude Code", "claude") + plan := buildPlan(t.Context(), []*agents.Agent{claude}, installer.ScopeGlobal, false, false) + _, err = executePlan(ctx, nil, plan, installer.InstallOptions{Scope: installer.ScopeGlobal}, installInvocation{scope: installer.ScopeGlobal}, true) + require.ErrorIs(t, err, errNoAgentSetUp) + + st, err := installer.LoadState(dir) + require.NoError(t, err) + assert.Equal(t, []string{agents.NameCodex}, st.SkillsOnlyAgents) +} + func TestExecutePlanNothingInstalledIsAnError(t *testing.T) { t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6") fakeBinsOnPath(t, "claude") diff --git a/libs/aitools/installer/plugin.go b/libs/aitools/installer/plugin.go index 494d1709f99..32b29956094 100644 --- a/libs/aitools/installer/plugin.go +++ b/libs/aitools/installer/plugin.go @@ -563,6 +563,30 @@ func ForgetPluginInstalls(ctx context.Context, cliScope string, agentNames []str return SaveState(dir, state) } +// ForgetSkillsOnlyChoice removes the named agents from the agents the user put +// on raw skills with `install --skills-only`, in the state file for the given +// CLI scope. Install calls it for agents whose plugin install it attempted and +// that failed, so update tries the plugin again. Agents not in the list, or a +// scope without state, are left as they are. +func ForgetSkillsOnlyChoice(ctx context.Context, cliScope string, agentNames []string) error { + dir, err := skillsDir(ctx, cliScope) + if err != nil { + return err + } + state, err := LoadState(dir) + if err != nil || state == nil { + return err + } + n := len(state.SkillsOnlyAgents) + state.SkillsOnlyAgents = slices.DeleteFunc(state.SkillsOnlyAgents, func(name string) bool { + return slices.Contains(agentNames, name) + }) + if len(state.SkillsOnlyAgents) == n { + return nil + } + return SaveState(dir, state) +} + // ManualPluginInstallCommands returns the commands, in order, that install the // databricks plugin through the agent's own CLI. When the headless install // fails, running them by hand shows the agent's full output. Returns nil for an diff --git a/libs/aitools/installer/plugin_test.go b/libs/aitools/installer/plugin_test.go index e8c776fa6f5..f1046dd16c4 100644 --- a/libs/aitools/installer/plugin_test.go +++ b/libs/aitools/installer/plugin_test.go @@ -842,6 +842,38 @@ func TestRecordPluginInstallsForgetsSkillsOnlyChoice(t *testing.T) { assert.Equal(t, []string{agents.NameClaudeCode}, st.SkillsOnlyAgents) } +// Forgetting the --skills-only choice of some agents keeps the choice of the +// others and the rest of the state. +func TestForgetSkillsOnlyChoice(t *testing.T) { + setupTestHome(t) + ctx := cmdio.MockDiscard(t.Context()) + dir, err := GlobalSkillsDir(ctx) + require.NoError(t, err) + require.NoError(t, SaveState(dir, &InstallState{ + SchemaVersion: CurrentSchemaVersion, + Skills: map[string]string{"databricks": "0.1.0"}, + SkillsOnlyAgents: []string{agents.NameClaudeCode, agents.NameCodex}, + })) + + require.NoError(t, ForgetSkillsOnlyChoice(ctx, ScopeGlobal, []string{agents.NameCodex, agents.NameCopilot})) + + st, err := LoadState(dir) + require.NoError(t, err) + assert.Equal(t, []string{agents.NameClaudeCode}, st.SkillsOnlyAgents) + assert.Equal(t, map[string]string{"databricks": "0.1.0"}, st.Skills) +} + +func TestForgetSkillsOnlyChoiceWithoutState(t *testing.T) { + setupTestHome(t) + ctx := cmdio.MockDiscard(t.Context()) + require.NoError(t, ForgetSkillsOnlyChoice(ctx, ScopeGlobal, []string{agents.NameCodex})) + dir, err := GlobalSkillsDir(ctx) + require.NoError(t, err) + st, err := LoadState(dir) + require.NoError(t, err) + assert.Nil(t, st) +} + func TestRecordPluginInstallsThenSkillsInstallNoPanic(t *testing.T) { tmp := setupTestHome(t) ctx := cmdio.MockDiscard(t.Context()) diff --git a/libs/aitools/installer/state.go b/libs/aitools/installer/state.go index 5f236a22baa..9c7e1cdf473 100644 --- a/libs/aitools/installer/state.go +++ b/libs/aitools/installer/state.go @@ -64,7 +64,12 @@ type InstallState struct { // the plugin was declined, not unavailable. Update keeps them on raw // skills. Raw skills of other plugin agents were written by an older CLI or // while the agent's CLI was missing, and update migrates those to the - // plugin. Recording a plugin install for an agent removes its name. + // plugin. Recording a plugin install for an agent removes its name, and so + // does an install that tried the plugin for it and failed. + // + // Unlike Plugins, nothing on disk shows this choice again: an older CLI + // that rewrites the state drops the field, and update then migrates these + // agents to the plugin like any other raw skills. SkillsOnlyAgents []string `json:"skills_only_agents,omitempty"` // MCP records the Databricks MCP servers the `aitools mcp` commands wrote. // Added in schema v3; omitted when none are recorded. SaveState ignores this From 245f98fc9483d2052d9dfa3cd9853084cfa132a9 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:08:04 +0000 Subject: [PATCH 4/6] aitools: address review of the --skills-only choice - The deprecated experimental skills install alias no longer records the choice: it adds --skills-only itself, so its users did not decline the plugin. - A targeted uninstall without --skills ends the choice of those agents. - Scope the changelog entry to installs made from this release on. - Keep the executePlan tests with a failing plugin off the real HOME, and stub agents.LookPath instead of writing a binary on PATH. - Cover install --skills-only then update with an agent CLI on PATH in the install-non-interactive acceptance test. Co-authored-by: Isaac --- .../cli/aitools-update-keeps-skills-only.md | 2 +- .../skills/install-non-interactive/output.txt | 13 +++++++ .../skills/install-non-interactive/script | 18 ++++++++++ cmd/aitools/install.go | 11 +++++- cmd/aitools/install_test.go | 6 ++++ cmd/aitools/legacy_skills.go | 3 +- cmd/aitools/legacy_skills_test.go | 3 ++ libs/aitools/installer/installer_test.go | 15 ++++---- libs/aitools/installer/state.go | 3 +- libs/aitools/installer/uninstall.go | 7 ++++ libs/aitools/installer/uninstall_test.go | 36 +++++++++++++++++++ 11 files changed, 106 insertions(+), 11 deletions(-) diff --git a/.nextchanges/cli/aitools-update-keeps-skills-only.md b/.nextchanges/cli/aitools-update-keeps-skills-only.md index c75c66cf395..0722928450f 100644 --- a/.nextchanges/cli/aitools-update-keeps-skills-only.md +++ b/.nextchanges/cli/aitools-update-keeps-skills-only.md @@ -1 +1 @@ -* `databricks aitools update` no longer replaces the skill files that `databricks aitools install --skills-only` gave Claude Code, Codex or GitHub Copilot with the Databricks plugin. Run `databricks aitools install` without `--skills-only` to switch such an agent to the plugin. ([#7831](https://github.com/databricks/cli/pull/7831)) +* `databricks aitools update` no longer replaces skill files with the Databricks plugin for Claude Code, Codex or GitHub Copilot when you installed them with `databricks aitools install --skills-only` from this release on while the agent's CLI was on PATH. For an earlier `--skills-only` install, run `databricks aitools install --skills-only` again to keep the skill files, and run `databricks aitools install` without `--skills-only` to switch to the plugin. ([#7831](https://github.com/databricks/cli/pull/7831)) diff --git a/acceptance/experimental/aitools/skills/install-non-interactive/output.txt b/acceptance/experimental/aitools/skills/install-non-interactive/output.txt index 0bb5d48e863..cd23f84b81f 100644 --- a/acceptance/experimental/aitools/skills/install-non-interactive/output.txt +++ b/acceptance/experimental/aitools/skills/install-non-interactive/output.txt @@ -40,6 +40,19 @@ Using skills version test-ref Fetching skills manifest... Installed 1 skill in [TEST_TMP_DIR]/home/.databricks/aitools/skills. +=== --skills-only with the agent's CLI on PATH: update keeps the skill files + +>>> [CLI] aitools install --agents=claude-code --skills-only +Installing Databricks skills for Claude Code... +Using skills version test-ref +Fetching skills manifest... +Installed 1 skill in [TEST_TMP_DIR]/home/.databricks/aitools/skills. + +>>> [CLI] aitools update --force + updated test-stable v1.0.0 -> v1.0.0 +Updated 1 skill. +Claude Code has skill files + === project scope: a personal plugin does not replace the project's skill files >>> [CLI] aitools install --scope=project diff --git a/acceptance/experimental/aitools/skills/install-non-interactive/script b/acceptance/experimental/aitools/skills/install-non-interactive/script index bb361d77522..688af5700a7 100644 --- a/acceptance/experimental/aitools/skills/install-non-interactive/script +++ b/acceptance/experimental/aitools/skills/install-non-interactive/script @@ -14,6 +14,14 @@ export APPDATA="${USERPROFILE:-$HOME}/AppData/Roaming" # the script runs first. Windows also finds a command under each PATHEXT # extension (e.g. claude.cmd), so check those names too. mkdir_bin=$(command -v mkdir) +# The harness's agent CLI stand-ins (acceptance/internal/fakeagent), for the +# runs below that need an agent CLI on PATH. They only accept the MCP commands, +# so a plugin install through one of them fails. +if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then + fake_agent_path=$(cygpath -u "$FAKE_AGENT_DIR") +else + fake_agent_path=$FAKE_AGENT_DIR +fi rm_bin=$(command -v rm) cp_bin=$(command -v cp) exts="" @@ -66,6 +74,16 @@ trace musterr $CLI aitools install --agents=claude-code title "the suggested recovery command works" trace $CLI aitools install --agents=claude-code --skills-only +title "--skills-only with the agent's CLI on PATH: update keeps the skill files" +# With Claude Code's CLI on PATH, --skills-only records that the user declined +# the plugin, so update refreshes the skill files and does not try the plugin. +path_without_agents=$PATH +export PATH="$fake_agent_path:$PATH" +trace $CLI aitools install --agents=claude-code --skills-only +trace $CLI aitools update --force +check_claude_skills +export PATH=$path_without_agents + title "project scope: a personal plugin does not replace the project's skill files" # Project skill files are shared through the repository, so a user-scope plugin # installed with Claude Code itself later must not stop the update from diff --git a/cmd/aitools/install.go b/cmd/aitools/install.go index dde06d6531c..223dad3db44 100644 --- a/cmd/aitools/install.go +++ b/cmd/aitools/install.go @@ -124,6 +124,15 @@ type agentChoice struct { } func NewInstallCmd() *cobra.Command { + return newInstallCmd(true) +} + +// newInstallCmd builds the install command. recordSkillsOnly says whether +// --skills-only records the user's choice of raw skills, so update keeps those +// agents off the plugin. The deprecated `experimental aitools skills install` +// alias passes false: it always adds --skills-only to keep its pre-plugin +// behavior, so its users did not decline the plugin. +func newInstallCmd(recordSkillsOnly bool) *cobra.Command { var skillsFlag, agentsFlag, scopeFlag, pathFlag string var includeExperimental, skillsOnly bool var projectFlag, globalFlag bool @@ -196,7 +205,7 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "), opts := installer.InstallOptions{ IncludeExperimental: includeExperimental, SpecificSkills: splitAndTrim(skillsFlag), - SkillsOnly: skillsOnly, + SkillsOnly: skillsOnly && recordSkillsOnly, } // --skills cherry-picks individual skill files, which only applies to diff --git a/cmd/aitools/install_test.go b/cmd/aitools/install_test.go index a581d905dd0..a89da97b96e 100644 --- a/cmd/aitools/install_test.go +++ b/cmd/aitools/install_test.go @@ -335,6 +335,8 @@ func TestMapAgentScope(t *testing.T) { } func TestExecutePlanSkipBlockedPluginExit0(t *testing.T) { + // A failed plugin install rewrites the install state; keep it off the real HOME. + setupTestAgents(t) t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6") fakeBinsOnPath(t, "claude", "codex") orig := installPluginForAgentFn @@ -407,6 +409,8 @@ func TestExecutePlanFailedPluginForgetsSkillsOnlyChoice(t *testing.T) { } func TestExecutePlanNothingInstalledIsAnError(t *testing.T) { + // A failed plugin install rewrites the install state; keep it off the real HOME. + setupTestAgents(t) t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6") fakeBinsOnPath(t, "claude") orig := installPluginForAgentFn @@ -539,6 +543,8 @@ func TestExecutePlanNoSkillsToInstall(t *testing.T) { } func TestExecutePlanNoSkillsToInstallWithPluginFailures(t *testing.T) { + // A failed plugin install rewrites the install state; keep it off the real HOME. + setupTestAgents(t) t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6") fakeBinsOnPath(t, "claude") setupPluginMock(t) diff --git a/cmd/aitools/legacy_skills.go b/cmd/aitools/legacy_skills.go index 43ba95dc274..f55f4cf1736 100644 --- a/cmd/aitools/legacy_skills.go +++ b/cmd/aitools/legacy_skills.go @@ -42,7 +42,8 @@ func newLegacySkillsInstallCmd() *cobra.Command { Deprecated: `use "databricks aitools install --skills " instead.`, Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - installCmd := NewInstallCmd() + // Its --skills-only is not the user's choice, so it is not recorded. + installCmd := newInstallCmd(false) installCmd.SetContext(cmd.Context()) // Root prints the returned error; the detached command must not print // it, or its usage, a second time. diff --git a/cmd/aitools/legacy_skills_test.go b/cmd/aitools/legacy_skills_test.go index 7f1a75b83fb..f7cf36b0cba 100644 --- a/cmd/aitools/legacy_skills_test.go +++ b/cmd/aitools/legacy_skills_test.go @@ -30,6 +30,9 @@ func TestLegacySkillsInstallDelegatesToInstall(t *testing.T) { require.Len(t, *calls, 1) assert.Len(t, (*calls)[0].agents, 2) + // The alias adds --skills-only itself, so its users did not decline the + // plugin: the choice is not recorded and update still migrates them. + assert.False(t, (*calls)[0].opts.SkillsOnly) } func TestLegacySkillsInstallForwardsSkillName(t *testing.T) { diff --git a/libs/aitools/installer/installer_test.go b/libs/aitools/installer/installer_test.go index b400cf0e381..c9bca4010d7 100644 --- a/libs/aitools/installer/installer_test.go +++ b/libs/aitools/installer/installer_test.go @@ -12,8 +12,8 @@ import ( "net/http" "net/http/httptest" "os" + "os/exec" "path/filepath" - "runtime" "sync" "syscall" "testing" @@ -473,13 +473,14 @@ func TestInstallSkillsForAgentsRecordsSkillsOnlyAgents(t *testing.T) { t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) src := &mockManifestSource{manifest: testManifest()} - binDir := t.TempDir() - binName := "plugin-agent-cli" - if runtime.GOOS == "windows" { - binName += ".exe" + origLookPath := agents.LookPath + t.Cleanup(func() { agents.LookPath = origLookPath }) + agents.LookPath = func(name string) (string, error) { + if name == "plugin-agent-cli" { + return filepath.Join("/usr/bin", name), nil + } + return "", exec.ErrNotFound } - require.NoError(t, os.WriteFile(filepath.Join(binDir, binName), []byte("#!/bin/sh\n"), 0o755)) - t.Setenv("PATH", binDir) plain := testAgent(tmp) withPlugin := testAgent(tmp) diff --git a/libs/aitools/installer/state.go b/libs/aitools/installer/state.go index 9c7e1cdf473..5a4941e4b4a 100644 --- a/libs/aitools/installer/state.go +++ b/libs/aitools/installer/state.go @@ -65,7 +65,8 @@ type InstallState struct { // skills. Raw skills of other plugin agents were written by an older CLI or // while the agent's CLI was missing, and update migrates those to the // plugin. Recording a plugin install for an agent removes its name, and so - // does an install that tried the plugin for it and failed. + // do an install that tried the plugin for it and failed, and an uninstall + // that names the agent with --agents and no --skills. // // Unlike Plugins, nothing on disk shows this choice again: an older CLI // that rewrites the state drops the field, and update then migrates these diff --git a/libs/aitools/installer/uninstall.go b/libs/aitools/installer/uninstall.go index ffa36c9b769..ff1852b8cf8 100644 --- a/libs/aitools/installer/uninstall.go +++ b/libs/aitools/installer/uninstall.go @@ -119,6 +119,13 @@ func UninstallSkillsWithResult(ctx context.Context, opts UninstallOptions) (*Uni cmdio.LogString(ctx, fmt.Sprintf(" %s removed databricks plugin%s", agent.DisplayName, note)) } } + // Uninstalling an agent ends its --skills-only choice, so raw skills it + // gets later another way are migrated to the plugin by update. + if fullUninstall && targetedAgents { + state.SkillsOnlyAgents = slices.DeleteFunc(state.SkillsOnlyAgents, func(name string) bool { + return agentFilter[name] + }) + } // Determine which skills to remove. var toRemove []string diff --git a/libs/aitools/installer/uninstall_test.go b/libs/aitools/installer/uninstall_test.go index 1413cde08c2..a466f72dc47 100644 --- a/libs/aitools/installer/uninstall_test.go +++ b/libs/aitools/installer/uninstall_test.go @@ -384,6 +384,42 @@ func TestUninstallTargetedAgentKeepsRemainingRawExposure(t *testing.T) { assert.Contains(t, state.Skills, "databricks-sql") } +// Uninstalling an agent ends its --skills-only choice, so raw skills it gets +// later another way are migrated by update. Removing only some of its skills +// keeps the choice, and so does uninstalling another agent. +func TestUninstallTargetedAgentForgetsSkillsOnlyChoice(t *testing.T) { + tmp := setupTestHome(t) + ctx := cmdio.MockDiscard(t.Context()) + setupFetchMock(t) + t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) + require.NoError(t, os.MkdirAll(filepath.Join(tmp, ".claude"), 0o755)) + require.NoError(t, os.MkdirAll(filepath.Join(tmp, ".cursor"), 0o755)) + + claudeAgent := agents.ByName(agents.NameClaudeCode) + cursorAgent := agents.ByName(agents.NameCursor) + src := &mockManifestSource{manifest: testManifest()} + require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{claudeAgent, cursorAgent}, InstallOptions{})) + + globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills") + state, err := LoadState(globalDir) + require.NoError(t, err) + state.SkillsOnlyAgents = []string{agents.NameClaudeCode, agents.NameCodex} + require.NoError(t, SaveState(globalDir, state)) + + _, err = UninstallSkillsWithResult(ctx, UninstallOptions{Agents: []string{agents.NameClaudeCode}, Skills: []string{"databricks-sql"}}) + require.NoError(t, err) + state, err = LoadState(globalDir) + require.NoError(t, err) + assert.Equal(t, []string{agents.NameClaudeCode, agents.NameCodex}, state.SkillsOnlyAgents) + + _, err = UninstallSkillsWithResult(ctx, UninstallOptions{Agents: []string{agents.NameClaudeCode}}) + require.NoError(t, err) + state, err = LoadState(globalDir) + require.NoError(t, err) + require.NotNil(t, state) + assert.Equal(t, []string{agents.NameCodex}, state.SkillsOnlyAgents) +} + func TestUninstallTargetedAgentRemovesCanonicalWhenNoExposureRemains(t *testing.T) { tmp := setupTestHome(t) ctx := cmdio.MockDiscard(t.Context()) From 5615699127669c8430bddc6ae2e33becb223165e Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:18:51 +0000 Subject: [PATCH 5/6] aitools: address review of the skills-only uninstall and tests A plain uninstall now ends every --skills-only choice, also when the state file stays for a plugin it could not remove. An uninstall that could not remove a skill keeps the choice, since the files are still there. The install-non-interactive acceptance test stops when the agent CLI stand-ins were not built, and sets FAKE_AGENT_LOG for them. Two uninstall tests no longer follow the host's agent config dir overrides. Reword the changelog fragment and fix a stale comment. Co-authored-by: Isaac --- .../cli/aitools-update-keeps-skills-only.md | 2 +- .../skills/install-non-interactive/script | 23 +++++-- .../skills/install-non-interactive/test.toml | 1 + cmd/aitools/install.go | 9 +-- libs/aitools/installer/state.go | 3 +- libs/aitools/installer/uninstall.go | 21 +++--- libs/aitools/installer/uninstall_test.go | 66 +++++++++++++++++++ 7 files changed, 104 insertions(+), 21 deletions(-) diff --git a/.nextchanges/cli/aitools-update-keeps-skills-only.md b/.nextchanges/cli/aitools-update-keeps-skills-only.md index 0722928450f..c93acc8dc2b 100644 --- a/.nextchanges/cli/aitools-update-keeps-skills-only.md +++ b/.nextchanges/cli/aitools-update-keeps-skills-only.md @@ -1 +1 @@ -* `databricks aitools update` no longer replaces skill files with the Databricks plugin for Claude Code, Codex or GitHub Copilot when you installed them with `databricks aitools install --skills-only` from this release on while the agent's CLI was on PATH. For an earlier `--skills-only` install, run `databricks aitools install --skills-only` again to keep the skill files, and run `databricks aitools install` without `--skills-only` to switch to the plugin. ([#7831](https://github.com/databricks/cli/pull/7831)) +* `databricks aitools update` no longer replaces skill files with the Databricks plugin for Claude Code, Codex or GitHub Copilot when you installed them with `databricks aitools install --skills-only` from this release on while the agent's CLI was on PATH. For an earlier `--skills-only` install, run `databricks aitools install --skills-only` again, with the agent's CLI on PATH, to keep the skill files, or run `databricks aitools install` without `--skills-only` to switch to the plugin. ([#7831](https://github.com/databricks/cli/pull/7831)) diff --git a/acceptance/experimental/aitools/skills/install-non-interactive/script b/acceptance/experimental/aitools/skills/install-non-interactive/script index 688af5700a7..8535a262014 100644 --- a/acceptance/experimental/aitools/skills/install-non-interactive/script +++ b/acceptance/experimental/aitools/skills/install-non-interactive/script @@ -8,20 +8,29 @@ unset CLAUDE_CONFIG_DIR PI_CODING_AGENT_DIR GEMINI_CLI_HOME GOOSE_PATH_ROOT export XDG_CONFIG_HOME="${USERPROFILE:-$HOME}/.config" export APPDATA="${USERPROFILE:-$HOME}/AppData/Roaming" -# Agents are also detected by their CLI binary on PATH, so drop every PATH entry -# that holds one; otherwise the developer's own agents would join the run. That -# can drop /usr/bin (and /bin on a merged-/usr system), so resolve the commands -# the script runs first. Windows also finds a command under each PATHEXT -# extension (e.g. claude.cmd), so check those names too. -mkdir_bin=$(command -v mkdir) # The harness's agent CLI stand-ins (acceptance/internal/fakeagent), for the # runs below that need an agent CLI on PATH. They only accept the MCP commands, -# so a plugin install through one of them fails. +# so a plugin install through one of them fails. Without them those runs would +# not test anything, so the test stops instead. Each stand-in appends its argv +# to FAKE_AGENT_LOG; Go opens it, so on msys it is in the mixed form. +if [[ -z "${FAKE_AGENT_DIR:-}" ]]; then + echo "FAKE_AGENT_DIR is empty: the agent CLI stand-ins were not built" >&2 + exit 1 +fi +export FAKE_AGENT_LOG="$PWD/agent-calls.log" if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then fake_agent_path=$(cygpath -u "$FAKE_AGENT_DIR") + export FAKE_AGENT_LOG="$(cygpath -m "$FAKE_AGENT_LOG")" else fake_agent_path=$FAKE_AGENT_DIR fi + +# Agents are also detected by their CLI binary on PATH, so drop every PATH entry +# that holds one; otherwise the developer's own agents would join the run. That +# can drop /usr/bin (and /bin on a merged-/usr system), so resolve the commands +# the script runs first. Windows also finds a command under each PATHEXT +# extension (e.g. claude.cmd), so check those names too. +mkdir_bin=$(command -v mkdir) rm_bin=$(command -v rm) cp_bin=$(command -v cp) exts="" diff --git a/acceptance/experimental/aitools/skills/install-non-interactive/test.toml b/acceptance/experimental/aitools/skills/install-non-interactive/test.toml index 7afa69b4552..8002262ced2 100644 --- a/acceptance/experimental/aitools/skills/install-non-interactive/test.toml +++ b/acceptance/experimental/aitools/skills/install-non-interactive/test.toml @@ -4,6 +4,7 @@ Env.DATABRICKS_SKILLS_REF = "test-ref" Ignore = [ "home", + "agent-calls.log", ] [[Server]] diff --git a/cmd/aitools/install.go b/cmd/aitools/install.go index 223dad3db44..a1f89a7a4e6 100644 --- a/cmd/aitools/install.go +++ b/cmd/aitools/install.go @@ -417,10 +417,11 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "), } // installOutputIsJSON reports whether --output json was requested. Unlike list, -// install can run detached from root: the legacy `skills install` alias builds a -// NewInstallCmd and executes it directly (see newLegacySkillsInstallCmd), so the -// root-supplied --output flag may be absent. Treat a missing flag as text rather -// than panicking the way root.OutputType would. +// install can run detached from root: the legacy `skills install` alias builds an +// install command with newInstallCmd and executes it directly (see +// newLegacySkillsInstallCmd), so the root-supplied --output flag may be absent. +// Treat a missing flag as text rather than panicking the way root.OutputType +// would. func installOutputIsJSON(cmd *cobra.Command) bool { f := cmd.Flag("output") if f == nil { diff --git a/libs/aitools/installer/state.go b/libs/aitools/installer/state.go index 5a4941e4b4a..b84bea5cc3d 100644 --- a/libs/aitools/installer/state.go +++ b/libs/aitools/installer/state.go @@ -66,7 +66,8 @@ type InstallState struct { // while the agent's CLI was missing, and update migrates those to the // plugin. Recording a plugin install for an agent removes its name, and so // do an install that tried the plugin for it and failed, and an uninstall - // that names the agent with --agents and no --skills. + // without --skills that removed all its skills: a plain uninstall clears + // every name, one with --agents only the named agents. // // Unlike Plugins, nothing on disk shows this choice again: an older CLI // that rewrites the state drops the field, and update then migrates these diff --git a/libs/aitools/installer/uninstall.go b/libs/aitools/installer/uninstall.go index ff1852b8cf8..92c5c361494 100644 --- a/libs/aitools/installer/uninstall.go +++ b/libs/aitools/installer/uninstall.go @@ -119,14 +119,6 @@ func UninstallSkillsWithResult(ctx context.Context, opts UninstallOptions) (*Uni cmdio.LogString(ctx, fmt.Sprintf(" %s removed databricks plugin%s", agent.DisplayName, note)) } } - // Uninstalling an agent ends its --skills-only choice, so raw skills it - // gets later another way are migrated to the plugin by update. - if fullUninstall && targetedAgents { - state.SkillsOnlyAgents = slices.DeleteFunc(state.SkillsOnlyAgents, func(name string) bool { - return agentFilter[name] - }) - } - // Determine which skills to remove. var toRemove []string if len(opts.Skills) > 0 { @@ -204,6 +196,19 @@ func UninstallSkillsWithResult(ctx context.Context, opts UninstallOptions) (*Uni } } + // Uninstalling an agent ends its --skills-only choice, so raw skills it + // gets later another way are migrated to the plugin by update. A skill that + // could not be removed keeps the choice, since its files are still there. + if fullUninstall && len(skillFailures) == 0 { + if targetedAgents { + state.SkillsOnlyAgents = slices.DeleteFunc(state.SkillsOnlyAgents, func(name string) bool { + return agentFilter[name] + }) + } else { + state.SkillsOnlyAgents = nil + } + } + // If nothing remains in this scope, clean up orphaned symlinks and delete the // state file; otherwise persist the trimmed state. if len(state.Skills) == 0 && len(state.Plugins) == 0 { diff --git a/libs/aitools/installer/uninstall_test.go b/libs/aitools/installer/uninstall_test.go index a466f72dc47..6e08f9f6762 100644 --- a/libs/aitools/installer/uninstall_test.go +++ b/libs/aitools/installer/uninstall_test.go @@ -354,6 +354,7 @@ func TestUninstallSelectiveAllRemovesStateFile(t *testing.T) { func TestUninstallTargetedAgentKeepsRemainingRawExposure(t *testing.T) { tmp := setupTestHome(t) + clearAgentDirOverrides(t) ctx := cmdio.MockDiscard(t.Context()) setupFetchMock(t) t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) @@ -389,6 +390,7 @@ func TestUninstallTargetedAgentKeepsRemainingRawExposure(t *testing.T) { // keeps the choice, and so does uninstalling another agent. func TestUninstallTargetedAgentForgetsSkillsOnlyChoice(t *testing.T) { tmp := setupTestHome(t) + clearAgentDirOverrides(t) ctx := cmdio.MockDiscard(t.Context()) setupFetchMock(t) t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) @@ -420,6 +422,70 @@ func TestUninstallTargetedAgentForgetsSkillsOnlyChoice(t *testing.T) { assert.Equal(t, []string{agents.NameCodex}, state.SkillsOnlyAgents) } +// A targeted uninstall that leaves one of the agent's skills in place keeps +// the agent's --skills-only choice, since it still has skill files. +func TestUninstallTargetedAgentFailureKeepsSkillsOnlyChoice(t *testing.T) { + tmp := setupTestHome(t) + clearAgentDirOverrides(t) + ctx := cmdio.MockDiscard(t.Context()) + setupFetchMock(t) + t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) + require.NoError(t, os.MkdirAll(filepath.Join(tmp, ".claude"), 0o755)) + require.NoError(t, os.MkdirAll(filepath.Join(tmp, ".cursor"), 0o755)) + + claudeAgent := agents.ByName(agents.NameClaudeCode) + cursorAgent := agents.ByName(agents.NameCursor) + src := &mockManifestSource{manifest: testManifest()} + require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{claudeAgent, cursorAgent}, InstallOptions{})) + + globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills") + state, err := LoadState(globalDir) + require.NoError(t, err) + state.SkillsOnlyAgents = []string{agents.NameClaudeCode} + require.NoError(t, SaveState(globalDir, state)) + + claudeSQL := filepath.Join(tmp, ".claude", "skills", "databricks-sql") + orig := removeAllFn + t.Cleanup(func() { removeAllFn = orig }) + removeAllFn = func(path string) error { + if path == claudeSQL { + return fs.ErrPermission + } + return orig(path) + } + + result, err := UninstallSkillsWithResult(ctx, UninstallOptions{Agents: []string{agents.NameClaudeCode}}) + require.NoError(t, err) + assert.NotEmpty(t, result.SkillFailures) + state, err = LoadState(globalDir) + require.NoError(t, err) + require.NotNil(t, state) + assert.Equal(t, []string{agents.NameClaudeCode}, state.SkillsOnlyAgents) +} + +// A plain uninstall removes every skill, so it ends every --skills-only +// choice, also when the state file stays for a plugin it could not remove. +func TestUninstallAllForgetsSkillsOnlyChoice(t *testing.T) { + tmp := setupTestHome(t) + globalDir := installTestSkills(t, tmp) + ctx := cmdio.MockDiscard(t.Context()) + + state, err := LoadState(globalDir) + require.NoError(t, err) + state.Plugins = map[string]PluginRecord{"unknown-agent": {Marketplace: "databricks-agent-skills", Plugin: "databricks"}} + state.SkillsOnlyAgents = []string{agents.NameClaudeCode, agents.NameCodex} + require.NoError(t, SaveState(globalDir, state)) + + _, err = UninstallSkillsWithResult(ctx, UninstallOptions{}) + require.NoError(t, err) + state, err = LoadState(globalDir) + require.NoError(t, err) + require.NotNil(t, state) + assert.Contains(t, state.Plugins, "unknown-agent") + assert.Empty(t, state.Skills) + assert.Empty(t, state.SkillsOnlyAgents) +} + func TestUninstallTargetedAgentRemovesCanonicalWhenNoExposureRemains(t *testing.T) { tmp := setupTestHome(t) ctx := cmdio.MockDiscard(t.Context()) From 98cd70b5229b5d0455cedd798b12f4ede12b0482 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Fri, 20 Nov 2026 15:16:51 +0000 Subject: [PATCH 6/6] aitools: clear --skills-only choice per agent on targeted uninstall With several --agents, a removal failure for one agent no longer keeps every named agent's choice; agents whose entries were all removed lose theirs. Trim the SkillsOnlyAgents doc comment to its contract and restore an unrelated blank line. Co-authored-by: Isaac --- libs/aitools/installer/plugin.go | 1 + libs/aitools/installer/state.go | 5 +-- libs/aitools/installer/uninstall.go | 29 +++++++++----- libs/aitools/installer/uninstall_test.go | 49 ++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 13 deletions(-) diff --git a/libs/aitools/installer/plugin.go b/libs/aitools/installer/plugin.go index 32b29956094..9c2a942c43a 100644 --- a/libs/aitools/installer/plugin.go +++ b/libs/aitools/installer/plugin.go @@ -504,6 +504,7 @@ func RecordPluginInstalls(ctx context.Context, cliScope string, records map[stri state.Plugins = make(map[string]PluginRecord, len(records)) } maps.Copy(state.Plugins, records) + // An agent with the plugin is no longer on raw skills by choice. state.SkillsOnlyAgents = slices.DeleteFunc(state.SkillsOnlyAgents, func(name string) bool { _, ok := records[name] return ok diff --git a/libs/aitools/installer/state.go b/libs/aitools/installer/state.go index b84bea5cc3d..599cacab00b 100644 --- a/libs/aitools/installer/state.go +++ b/libs/aitools/installer/state.go @@ -64,10 +64,7 @@ type InstallState struct { // the plugin was declined, not unavailable. Update keeps them on raw // skills. Raw skills of other plugin agents were written by an older CLI or // while the agent's CLI was missing, and update migrates those to the - // plugin. Recording a plugin install for an agent removes its name, and so - // do an install that tried the plugin for it and failed, and an uninstall - // without --skills that removed all its skills: a plain uninstall clears - // every name, one with --agents only the named agents. + // plugin. // // Unlike Plugins, nothing on disk shows this choice again: an older CLI // that rewrites the state drops the field, and update then migrates these diff --git a/libs/aitools/installer/uninstall.go b/libs/aitools/installer/uninstall.go index 92c5c361494..90ceb95d996 100644 --- a/libs/aitools/installer/uninstall.go +++ b/libs/aitools/installer/uninstall.go @@ -119,6 +119,7 @@ func UninstallSkillsWithResult(ctx context.Context, opts UninstallOptions) (*Uni cmdio.LogString(ctx, fmt.Sprintf(" %s removed databricks plugin%s", agent.DisplayName, note)) } } + // Determine which skills to remove. var toRemove []string if len(opts.Skills) > 0 { @@ -149,13 +150,20 @@ func UninstallSkillsWithResult(ctx context.Context, opts UninstallOptions) (*Uni // without a failure though no copy was left to remove, e.g. a stale entry. skillsChanged, skillsUninstalled := 0, 0 var skillFailures []error + // failedAgents names the targeted agents that keep an entry they could not + // remove. + failedAgents := map[string]bool{} for _, name := range toRemove { canonicalDir := filepath.Join(baseDir, name) removeCanonical := true changed := false var failures []error if targetedAgents { - changed, failures = removeSkillExposuresFromAgents(ctx, name, canonicalDir, scope, cwd, state, opts.Agents) + var failed []string + changed, failures, failed = removeSkillExposuresFromAgents(ctx, name, canonicalDir, scope, cwd, state, opts.Agents) + for _, agentName := range failed { + failedAgents[agentName] = true + } removeCanonical = !hasRemainingSkillExposure(ctx, name, canonicalDir, scope, cwd, opts.Agents) } else { changed = removeSymlinksFromAgents(ctx, name, canonicalDir, scope, cwd) @@ -197,14 +205,15 @@ func UninstallSkillsWithResult(ctx context.Context, opts UninstallOptions) (*Uni } // Uninstalling an agent ends its --skills-only choice, so raw skills it - // gets later another way are migrated to the plugin by update. A skill that - // could not be removed keeps the choice, since its files are still there. - if fullUninstall && len(skillFailures) == 0 { + // gets later another way are migrated to the plugin by update. An agent + // that keeps an entry it could not remove keeps the choice, since its files + // are still there; with --agents, the other named agents lose theirs. + if fullUninstall { if targetedAgents { state.SkillsOnlyAgents = slices.DeleteFunc(state.SkillsOnlyAgents, func(name string) bool { - return agentFilter[name] + return agentFilter[name] && !failedAgents[name] }) - } else { + } else if len(skillFailures) == 0 { state.SkillsOnlyAgents = nil } } @@ -252,10 +261,11 @@ func stringSet(items []string) map[string]bool { // removeSkillExposuresFromAgents removes the skill from the named agents' skills // dirs and reports whether it removed an existing entry for any of them, plus -// the errors from entries it failed to remove. -func removeSkillExposuresFromAgents(ctx context.Context, skillName, canonicalDir, scope, cwd string, state *InstallState, agentNames []string) (bool, []error) { +// the errors from entries it failed to remove and the agents they belong to. +func removeSkillExposuresFromAgents(ctx context.Context, skillName, canonicalDir, scope, cwd string, state *InstallState, agentNames []string) (bool, []error, []string) { removed := false var failures []error + var failedAgents []string for _, name := range agentNames { agent := agents.ByName(name) if agent == nil { @@ -280,11 +290,12 @@ func removeSkillExposuresFromAgents(ctx context.Context, skillName, canonicalDir if err := removeAllFn(entry); err != nil { log.Warnf(ctx, "Failed to remove %s: %v", entry, err) failures = append(failures, err) + failedAgents = append(failedAgents, name) continue } removed = true } - return removed, failures + return removed, failures, failedAgents } func hasRemainingSkillExposure(ctx context.Context, skillName, canonicalDir, scope, cwd string, removedAgents []string) bool { diff --git a/libs/aitools/installer/uninstall_test.go b/libs/aitools/installer/uninstall_test.go index 6e08f9f6762..e3bc55ea333 100644 --- a/libs/aitools/installer/uninstall_test.go +++ b/libs/aitools/installer/uninstall_test.go @@ -463,6 +463,55 @@ func TestUninstallTargetedAgentFailureKeepsSkillsOnlyChoice(t *testing.T) { assert.Equal(t, []string{agents.NameClaudeCode}, state.SkillsOnlyAgents) } +// With several --agents, a removal failure for one agent keeps only that +// agent's --skills-only choice; the agents whose entries were all removed +// lose theirs. +func TestUninstallTargetedAgentsFailureKeepsOnlyFailedAgentChoice(t *testing.T) { + tmp := setupTestHome(t) + clearAgentDirOverrides(t) + ctx := cmdio.MockDiscard(t.Context()) + setupFetchMock(t) + t.Setenv("DATABRICKS_SKILLS_REF", testSkillsRef) + require.NoError(t, os.MkdirAll(filepath.Join(tmp, ".claude"), 0o755)) + require.NoError(t, os.MkdirAll(filepath.Join(tmp, ".cursor"), 0o755)) + require.NoError(t, os.MkdirAll(filepath.Join(tmp, ".copilot"), 0o755)) + + // Copilot is not targeted and keeps the skills, so the state file stays. + claudeAgent := agents.ByName(agents.NameClaudeCode) + cursorAgent := agents.ByName(agents.NameCursor) + copilotAgent := agents.ByName(agents.NameCopilot) + src := &mockManifestSource{manifest: testManifest()} + require.NoError(t, InstallSkillsForAgents(ctx, src, []*agents.Agent{claudeAgent, cursorAgent, copilotAgent}, InstallOptions{})) + + globalDir := filepath.Join(tmp, ".databricks", "aitools", "skills") + state, err := LoadState(globalDir) + require.NoError(t, err) + state.SkillsOnlyAgents = []string{agents.NameClaudeCode, agents.NameCodex, agents.NameCursor} + require.NoError(t, SaveState(globalDir, state)) + + cursorSQL := filepath.Join(tmp, ".cursor", "skills", "databricks-sql") + _, err = os.Lstat(cursorSQL) + require.NoError(t, err) + orig := removeAllFn + t.Cleanup(func() { removeAllFn = orig }) + removeAllFn = func(path string) error { + if path == cursorSQL { + return fs.ErrPermission + } + return orig(path) + } + + result, err := UninstallSkillsWithResult(ctx, UninstallOptions{Agents: []string{agents.NameClaudeCode, agents.NameCursor}}) + require.NoError(t, err) + assert.NotEmpty(t, result.SkillFailures) + _, err = os.Lstat(filepath.Join(tmp, ".claude", "skills", "databricks-sql")) + assert.ErrorIs(t, err, fs.ErrNotExist) + state, err = LoadState(globalDir) + require.NoError(t, err) + require.NotNil(t, state) + assert.Equal(t, []string{agents.NameCodex, agents.NameCursor}, state.SkillsOnlyAgents) +} + // A plain uninstall removes every skill, so it ends every --skills-only // choice, also when the state file stays for a plugin it could not remove. func TestUninstallAllForgetsSkillsOnlyChoice(t *testing.T) {