Skip to content
Merged
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-marketplace-refresh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* `databricks aitools install` and `databricks aitools update` refresh only the marketplace the Databricks plugin is listed in, so another unreachable marketplace no longer blocks them. When that refresh fails, both commands warn, install or update the plugin from the local copy of the marketplace, and record the plugin version as unknown. ([#7473](https://github.com/databricks/cli/pull/7473))
8 changes: 5 additions & 3 deletions cmd/aitools/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,17 @@ func renderSkillTable(skills []skillEntry, bothScopes bool) string {
// are skipped: this line reports the plugin, and their versions would otherwise
// decide the status of an agent that also has a plugin in another scope.
func agentStatusLabel(a agentEntry, release string) string {
version, upToDate := "", true
// picked is separate from version because an empty version ("version
// unknown") is a real pick, not "nothing picked yet".
version, picked, upToDate := "", false, true
for _, scope := range []string{installer.ScopeProject, installer.ScopeGlobal} {
info, ok := a.Installed[scope]
if !ok || info.Delivery != deliveryPlugin.String() {
continue
}
stale := info.Version != release
if version == "" || (upToDate && stale) {
version = info.Version
if !picked || (upToDate && stale) {
version, picked = info.Version, true
}
if stale {
upToDate = false
Expand Down
11 changes: 11 additions & 0 deletions cmd/aitools/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ func TestBuildAgentEntriesRecordsPerScopeVersions(t *testing.T) {
assert.Equal(t, "databricks plugin · v0.2.5 · update available", agentStatusLabel(cc, "0.2.6"))
}

func TestAgentStatusLabelKeepsUnknownStaleScope(t *testing.T) {
// The project record has no version (its last install could not refresh the
// marketplace), the global one is current. The unknown scope is stale and
// must not be hidden behind the up-to-date version.
a := agentEntry{Installed: map[string]installInfo{
installer.ScopeProject: {Delivery: deliveryPlugin.String(), Version: ""},
installer.ScopeGlobal: {Delivery: deliveryPlugin.String(), Version: "0.2.7"},
}}
assert.Equal(t, "databricks plugin · version unknown · update available", agentStatusLabel(a, "0.2.7"))
}

func TestRenderListJSONScopeFiltersSummary(t *testing.T) {
out := listOutput{
Release: "0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion cmd/aitools/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func printPluginCheckResults(ctx context.Context, state *installer.InstallState,
rec := state.Plugins[name]
status := "up to date"
if rec.Version == "" {
status = "version unknown"
status = "update may be available"
} else if rec.Version != latest {
status = "update available"
}
Expand Down
22 changes: 20 additions & 2 deletions cmd/aitools/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ func TestUpdateCheckPrintsNoChanges(t *testing.T) {
}

func TestUpdateCheckPrintsPluginState(t *testing.T) {
for _, tc := range []struct {
name string
version string
want string
}{
{"current", "0.2.6", "Claude Code databricks plugin v0.2.6 (up to date)"},
{"older", "0.2.5", "Claude Code databricks plugin v0.2.5 (update available)"},
// A record without a version (the last install or update could not
// refresh the marketplace) may be behind, and `aitools update` would fix it.
{"unknown", "", "Claude Code databricks plugin version unknown (update may be available)"},
} {
t.Run(tc.name, func(t *testing.T) {
testUpdateCheckPrintsPluginState(t, tc.version, tc.want)
})
}
}

func testUpdateCheckPrintsPluginState(t *testing.T, version, want string) {
noTelemetryAuth(t)
setupTestAgents(t)
t.Setenv("DATABRICKS_SKILLS_REF", "v0.2.6")
Expand All @@ -85,7 +103,7 @@ func TestUpdateCheckPrintsPluginState(t *testing.T) {
SchemaVersion: 2,
Release: "v0.2.6",
Plugins: map[string]installer.PluginRecord{
agents.NameClaudeCode: {Marketplace: "claude-plugins-official", Plugin: "databricks", Version: "0.2.6"},
agents.NameClaudeCode: {Marketplace: "claude-plugins-official", Plugin: "databricks", Version: version},
},
}))

Expand All @@ -94,7 +112,7 @@ func TestUpdateCheckPrintsPluginState(t *testing.T) {
cmd.SetArgs([]string{"--scope", "global", "--check"})

require.NoError(t, cmd.Execute())
assert.Contains(t, stderr.String(), "Claude Code databricks plugin v0.2.6 (up to date)")
assert.Contains(t, stderr.String(), want)
}

func TestUpdateMigratesManagedRawSkillsToPlugins(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func renderUpdateCheck(ctx context.Context, result *versioncheck.Result, output
return err
}
if output == flags.OutputText {
agents.MaybeVersionCheckTip(ctx, installer.InstalledTools)
agents.MaybeVersionCheckTip(ctx, installer.InstalledPluginAgents)
}
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions libs/aitools/agents/recommend.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func PrintSkillsTip(ctx context.Context) {
// when a coding agent is detected without Databricks tooling. Claude Code
// callers are skipped because MaybeHint already covers them, with its
// per-session throttle. installedPlugins is a parameter because this package
// cannot import the installer; callers pass installer.InstalledTools. No
// telemetry is logged: `databricks version` never resolves auth, so the event
// would not be uploaded (see logHintShown).
// cannot import the installer; callers pass installer.InstalledPluginAgents,
// which counts a plugin recorded in the CLI install state with or without a
// known version. No telemetry is logged: `databricks version` never resolves
// auth, so the event would not be uploaded (see logHintShown).
func MaybeVersionCheckTip(ctx context.Context, installedPlugins func(context.Context) []string) {
if useragent.AgentProvider() == claudeAgentProvider {
return
Expand Down
34 changes: 30 additions & 4 deletions libs/aitools/installer/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import (
// agent's own plugin cache (ground truth, catches installs made directly through
// the agent), falling back to the version recorded in the CLI install state when
// the plugin is not found on disk. An agent with no resolvable version is
// omitted rather than reported without one.
// omitted rather than reported without one. That includes an agent without a
// plugin cache reader (Codex) whose record has no version because its last
// update ran from a marketplace copy that could not be refreshed; use
// InstalledPluginAgents to ask whether a plugin is installed at all.
func InstalledTools(ctx context.Context) []string {
recorded := recordedPluginVersions(ctx)

Expand All @@ -34,10 +37,33 @@ func InstalledTools(ctx context.Context) []string {
return tools
}

// InstalledPluginAgents returns the names of the coding tools that have the
// Databricks plugin installed, sorted: found in the agent's own plugin cache or
// recorded in the CLI install state, whether or not a version is known.
func InstalledPluginAgents(ctx context.Context) []string {
recorded := recordedPluginVersions(ctx)

var names []string
for _, a := range agents.Registry {
if a.Plugin == nil {
continue
}
_, inCache := a.DatabricksPluginVersion(ctx)
_, inState := recorded[a.Name]
if inCache || inState {
names = append(names, a.Name)
}
}
slices.Sort(names)
return names
}

// recordedPluginVersions maps agent name to the databricks plugin version
// recorded in the CLI install state, merged across global and project scope.
// When both scopes record a version, the project scope wins (it is the more
// specific, closer-to-the-invocation install).
// An agent whose record has no version maps to "". When both scopes record a
// version, the project scope wins (it is the more specific,
// closer-to-the-invocation install); a scope without a version never replaces
// one with a version.
func recordedPluginVersions(ctx context.Context) map[string]string {
versions := map[string]string{}
// Load global first, then project, so project overwrites on conflict.
Expand All @@ -55,7 +81,7 @@ func recordedPluginVersions(ctx context.Context) map[string]string {
continue
}
for name, rec := range state.Plugins {
if rec.Version != "" {
if _, seen := versions[name]; !seen || rec.Version != "" {
versions[name] = rec.Version
}
}
Expand Down
65 changes: 65 additions & 0 deletions libs/aitools/installer/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ func TestInstalledTools(t *testing.T) {
projectPlugins: map[string]string{"codex": "0.2.7"},
want: []string{"codex_0.2.7"},
},
{
// A record without a version (its last update ran from a marketplace
// copy that could not be refreshed) yields no token.
name: "state without version omitted",
globalPlugins: map[string]string{"codex": ""},
want: nil,
},
{
// A project record without a version does not hide the global one.
name: "project state without version keeps global",
globalPlugins: map[string]string{"codex": "0.2.7"},
projectPlugins: map[string]string{"codex": ""},
want: []string{"codex_0.2.7"},
},
{
// Manifest (claude) and state (codex) contribute; output is sorted.
name: "mixed sources sorted",
Expand Down Expand Up @@ -82,6 +96,57 @@ func TestInstalledTools(t *testing.T) {
}
}

// TestInstalledPluginAgents counts a plugin as installed whether or not its
// version is known, so `databricks version --check` does not suggest installing
// Databricks tooling to a user who has the plugin.
func TestInstalledPluginAgents(t *testing.T) {
tests := []struct {
name string
claudeManifestVersion string
globalPlugins map[string]string
projectPlugins map[string]string
want []string
}{
{
name: "none installed",
want: nil,
},
{
name: "state with version",
globalPlugins: map[string]string{"codex": "0.2.7"},
want: []string{"codex"},
},
{
name: "state without version",
projectPlugins: map[string]string{"codex": ""},
want: []string{"codex"},
},
{
name: "manifest and state sorted",
claudeManifestVersion: "0.2.9",
globalPlugins: map[string]string{"codex": ""},
want: []string{"claude-code", "codex"},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
tmp := t.TempDir()
t.Setenv("HOME", tmp)
t.Setenv("USERPROFILE", tmp)
t.Chdir(t.TempDir())

if tc.claudeManifestVersion != "" {
writeClaudeManifest(t, filepath.Join(tmp, ".claude"), tc.claudeManifestVersion)
}
savePluginState(t, GlobalSkillsDir, tc.globalPlugins)
savePluginState(t, ProjectSkillsDir, tc.projectPlugins)

assert.Equal(t, tc.want, InstalledPluginAgents(t.Context()))
})
}
}

// writeClaudeManifest writes a Claude installed_plugins.json recording the
// databricks plugin at the given version under configDir.
func writeClaudeManifest(t *testing.T, configDir, version string) {
Expand Down
Loading
Loading