Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/cli/aitools-update-keeps-skills-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +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, 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))
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ 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"

# 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. 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
Comment thread
anton-107 marked this conversation as resolved.
Resolved

# 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
Expand Down Expand Up @@ -66,6 +83,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Env.DATABRICKS_SKILLS_REF = "test-ref"

Ignore = [
"home",
"agent-calls.log",
]

[[Server]]
Expand Down
29 changes: 25 additions & 4 deletions cmd/aitools/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -196,6 +205,7 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "),
opts := installer.InstallOptions{
IncludeExperimental: includeExperimental,
SpecificSkills: splitAndTrim(skillsFlag),
SkillsOnly: skillsOnly && recordSkillsOnly,
}

// --skills cherry-picks individual skill files, which only applies to
Expand Down Expand Up @@ -407,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 {
Expand Down Expand Up @@ -956,6 +967,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))
Expand All @@ -978,6 +990,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
Expand All @@ -992,6 +1005,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 {
Comment thread
anton-107 marked this conversation as resolved.
Resolved
log.Warnf(ctx, "Could not drop the --skills-only choice for %s: %v", strings.Join(failed, ", "), err)
}
}
Comment thread
anton-107 marked this conversation as resolved.
Resolved
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
Expand Down
40 changes: 40 additions & 0 deletions cmd/aitools/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -373,7 +375,42 @@ 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) {
// 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
Expand Down Expand Up @@ -506,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)
Expand Down Expand Up @@ -906,6 +945,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) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/aitools/legacy_skills.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func newLegacySkillsInstallCmd() *cobra.Command {
Deprecated: `use "databricks aitools install --skills <name>" 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.
Expand Down
3 changes: 3 additions & 0 deletions cmd/aitools/legacy_skills_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions cmd/aitools/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
80 changes: 80 additions & 0 deletions cmd/aitools/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Comment thread
anton-107 marked this conversation as resolved.
Resolved
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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions libs/aitools/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Comment thread
anton-107 marked this conversation as resolved.
Resolved
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
Expand Down
Loading
Loading