From 43531da7abfbf583bd25ee68e50767508df87dd5 Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:04:52 +0000 Subject: [PATCH 1/3] aitools: Skip the apps init skills tip when Codex and Copilot have the plugin recorded ## Changes `databricks apps init` decides whether to recommend Databricks skills by calling `agents.HasDatabricksToolingInstalled`. With this change, that check also uses the plugins recorded in the CLI install state (`installer.InstalledPluginAgents`). It is used for agents that have no plugin manifest the CLI can read, which today means Codex and Copilot. ```diff for each detected agent: if agent has no plugin manifest reader (Codex, Copilot): - return false + if plugin not recorded in the CLI install state: + return false + continue if databricks plugin not active for the working directory: return false return true ``` - `HasDatabricksToolingInstalled` and `RecommendSkillsInstall` now take an `installedPlugins func(context.Context) []string` argument. The `agents` package can't import the installer, so this follows the pattern `MaybeVersionCheckTip` already uses. - `apps init` passes `installer.InstalledPluginAgents` in both paths: the flags-mode tip and the interactive install prompt. - `MaybeVersionCheckTip` passes its existing `installedPlugins` through. Its behavior doesn't change, because it already returned early when any plugin was recorded. - Claude Code is unchanged. It still needs the plugin in its own manifest, active for the working directory. A recorded Claude Code plugin without a manifest entry doesn't count. - Added a changelog fragment under `.nextchanges/cli/`. ## Why When Codex or Copilot was detected, `HasDatabricksToolingInstalled` returned false unless skills were in the shared skills directory. The CLI can't read a plugin manifest for those agents, so it never saw their plugin. As a result, users who had already run `databricks aitools install` to get the Databricks plugin for Codex or Copilot were still told to install skills by `apps init`, and the tip was logged in telemetry. The CLI install state is the only plugin source the CLI has for these agents. One gap remains: a plugin installed with the agent's own CLI, not with `databricks aitools install`, still isn't detected. ## Tests - `TestHasDatabricksToolingInstalledRecordedPlugins`, a new table test with these cases: - Codex and Copilot both recorded: no recommendation. - Only Codex recorded while Copilot is also detected: recommendation shown. - Nothing recorded: recommendation shown. - Codex recorded alongside Cursor, which has no tooling: recommendation shown. - A Claude Code record without its manifest: recommendation shown. - `TestRecommendSkillsInstallSkipsWhenPluginRecorded`: no prompt, no stderr output and no hint telemetry when Codex and Copilot plugins are recorded. - Updated the existing `HasDatabricksToolingInstalled` and `RecommendSkillsInstall` tests for the new argument. They pass a stub that records no plugin, so their expectations don't change. - Acceptance test `acceptance/cmd/aitools/telemetry/apps-init-tip`: a new case writes an install state that records Codex and Copilot plugins. It then checks that `apps init` prints no tip and logs no telemetry event. Co-authored-by: Isaac --- .../cli/apps-init-recorded-plugin-tip.md | 1 + .../telemetry/apps-init-tip/output.txt | 13 +++++ .../aitools/telemetry/apps-init-tip/script | 23 ++++++++ .../aitools/telemetry/apps-init-tip/test.toml | 4 ++ cmd/apps/init.go | 4 +- libs/aitools/agents/recommend.go | 8 +-- libs/aitools/agents/recommend_test.go | 27 ++++++++-- libs/aitools/agents/skills.go | 23 +++++--- libs/aitools/agents/skills_test.go | 53 +++++++++++++++---- 9 files changed, 129 insertions(+), 27 deletions(-) create mode 100644 .nextchanges/cli/apps-init-recorded-plugin-tip.md diff --git a/.nextchanges/cli/apps-init-recorded-plugin-tip.md b/.nextchanges/cli/apps-init-recorded-plugin-tip.md new file mode 100644 index 00000000000..ebed02987f7 --- /dev/null +++ b/.nextchanges/cli/apps-init-recorded-plugin-tip.md @@ -0,0 +1 @@ +* `apps init` no longer suggests installing skills to Codex and Copilot users who installed the Databricks plugin with `databricks aitools install`. diff --git a/acceptance/cmd/aitools/telemetry/apps-init-tip/output.txt b/acceptance/cmd/aitools/telemetry/apps-init-tip/output.txt index 335595f4d75..f8b34c89189 100644 --- a/acceptance/cmd/aitools/telemetry/apps-init-tip/output.txt +++ b/acceptance/cmd/aitools/telemetry/apps-init-tip/output.txt @@ -28,3 +28,16 @@ Tip: coding agents detected without Databricks skills. Run 'databricks aitools i >>> print_telemetry + +=== codex and copilot plugins recorded by aitools install: no tip, no event + +>>> [CLI] apps init --template ./template --skip-install --name app-recorded +✔ Creating project + +✔ Project created successfully! + + Location: [TEST_TMP_DIR]/app-recorded + Files: 3 + + +>>> print_telemetry diff --git a/acceptance/cmd/aitools/telemetry/apps-init-tip/script b/acceptance/cmd/aitools/telemetry/apps-init-tip/script index 5fa052bb0a4..b247386209c 100644 --- a/acceptance/cmd/aitools/telemetry/apps-init-tip/script +++ b/acceptance/cmd/aitools/telemetry/apps-init-tip/script @@ -16,3 +16,26 @@ sethome ./plugin-home trace $CLI apps init --template ./template --skip-install --name app-plugin > LOG.apps-init-plugin trace print_telemetry rm -rf app-plugin + +title "codex and copilot plugins recorded by aitools install: no tip, no event" +# Codex and Copilot have no plugin manifest the CLI can read, so the plugin +# record in the CLI install state is what counts for them. +sethome ./recorded-plugin-home +unset CLAUDECODE +mkdir -p "$HOME/.codex" "$HOME/.copilot" "${USERPROFILE:-$HOME}/.databricks/aitools/skills" +cat > "${USERPROFILE:-$HOME}/.databricks/aitools/skills/.state.json" <<'STATE' +{ + "schema_version": 2, + "release": "v0.2.32", + "last_updated": "2026-01-01T00:00:00Z", + "skills": {}, + "scope": "global", + "plugins": { + "codex": {"marketplace": "databricks-agent-skills", "plugin": "databricks", "scope": "user", "version": "0.2.32"}, + "copilot": {"marketplace": "databricks-agent-skills", "plugin": "databricks", "scope": "user", "version": "0.2.32"} + } +} +STATE +trace $CLI apps init --template ./template --skip-install --name app-recorded > LOG.apps-init-recorded +trace print_telemetry +rm -rf app-recorded recorded-plugin-home diff --git a/acceptance/cmd/aitools/telemetry/apps-init-tip/test.toml b/acceptance/cmd/aitools/telemetry/apps-init-tip/test.toml index def8da54843..e8a692bccbc 100644 --- a/acceptance/cmd/aitools/telemetry/apps-init-tip/test.toml +++ b/acceptance/cmd/aitools/telemetry/apps-init-tip/test.toml @@ -6,3 +6,7 @@ New = 'TEST_TMP_DIR]/app-tip' [[Repls]] Old = 'TEST_TMP_DIR]\\app-plugin' New = 'TEST_TMP_DIR]/app-plugin' + +[[Repls]] +Old = 'TEST_TMP_DIR]\\app-recorded' +New = 'TEST_TMP_DIR]/app-recorded' diff --git a/cmd/apps/init.go b/cmd/apps/init.go index 5e704e53e4c..05fd4952003 100644 --- a/cmd/apps/init.go +++ b/cmd/apps/init.go @@ -1914,10 +1914,10 @@ func runCreate(ctx context.Context, opts createOptions) (runErr error) { // Recommend skills installation if coding agents are detected without skills. // In flags mode, only print a hint — never prompt interactively. if flagsMode { - if !agents.HasDatabricksToolingInstalled(ctx) { + if !agents.HasDatabricksToolingInstalled(ctx, installer.InstalledPluginAgents) { agents.PrintSkillsTip(ctx) } - } else if err := agents.RecommendSkillsInstall(ctx, installer.InstallAllSkills); err != nil { + } else if err := agents.RecommendSkillsInstall(ctx, installer.InstalledPluginAgents, installer.InstallAllSkills); err != nil { log.Warnf(ctx, "Skills recommendation failed: %v", err) } diff --git a/libs/aitools/agents/recommend.go b/libs/aitools/agents/recommend.go index 31d3b94f064..f3631c1cd1b 100644 --- a/libs/aitools/agents/recommend.go +++ b/libs/aitools/agents/recommend.go @@ -38,7 +38,7 @@ func MaybeVersionCheckTip(ctx context.Context, installedPlugins func(context.Con if dbr.HasDetection(ctx) && dbr.RunsOnRuntime(ctx) { return } - if HasDatabricksToolingInstalled(ctx) || len(installedPlugins(ctx)) > 0 { + if HasDatabricksToolingInstalled(ctx, installedPlugins) || len(installedPlugins(ctx)) > 0 { return } // Recorded plugins are checked above, so DatabricksTooling only needs the @@ -53,11 +53,11 @@ func MaybeVersionCheckTip(ctx context.Context, installedPlugins func(context.Con } // RecommendSkillsInstall checks if coding agents are detected without Databricks tooling (skills -// or the databricks plugin) installed. +// or the databricks plugin) installed; installedPlugins is passed to HasDatabricksToolingInstalled. // In interactive mode, prompts the user to install now using installFn; a "no" also turns // auto-install off. In non-interactive mode, prints a hint. -func RecommendSkillsInstall(ctx context.Context, installFn func(context.Context) error) error { - if HasDatabricksToolingInstalled(ctx) { +func RecommendSkillsInstall(ctx context.Context, installedPlugins func(context.Context) []string, installFn func(context.Context) error) error { + if HasDatabricksToolingInstalled(ctx, installedPlugins) { return nil } diff --git a/libs/aitools/agents/recommend_test.go b/libs/aitools/agents/recommend_test.go index 5430b147c0b..da4d2fc637c 100644 --- a/libs/aitools/agents/recommend_test.go +++ b/libs/aitools/agents/recommend_test.go @@ -40,7 +40,7 @@ func TestRecommendSkillsInstallSkipsWhenSkillsExist(t *testing.T) { defer func() { Registry = origRegistry }() ctx := telemetry.WithNewLogger(cmdio.MockDiscard(t.Context())) - err := RecommendSkillsInstall(ctx, noopInstall) + err := RecommendSkillsInstall(ctx, noInstalledPlugins, noopInstall) assert.NoError(t, err) assert.Empty(t, hintKinds(t, ctx)) } @@ -57,7 +57,24 @@ func TestRecommendSkillsInstallSkipsWhenPluginInstalled(t *testing.T) { ctx, stderr := cmdio.NewTestContextWithStderr(t.Context()) ctx = telemetry.WithNewLogger(ctx) - err := RecommendSkillsInstall(ctx, noopInstall) + err := RecommendSkillsInstall(ctx, noInstalledPlugins, noopInstall) + assert.NoError(t, err) + assert.Empty(t, stderr.String()) + assert.Empty(t, hintKinds(t, ctx)) +} + +func TestRecommendSkillsInstallSkipsWhenPluginRecorded(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Chdir(t.TempDir()) + require.NoError(t, os.MkdirAll(filepath.Join(home, ".codex"), 0o755)) + require.NoError(t, os.MkdirAll(filepath.Join(home, ".copilot"), 0o755)) + recorded := func(context.Context) []string { return []string{NameCodex, NameCopilot} } + + ctx, stderr := cmdio.NewTestContextWithStderr(t.Context()) + ctx = telemetry.WithNewLogger(ctx) + err := RecommendSkillsInstall(ctx, recorded, noopInstall) assert.NoError(t, err) assert.Empty(t, stderr.String()) assert.Empty(t, hintKinds(t, ctx)) @@ -73,7 +90,7 @@ func TestRecommendSkillsInstallSkipsWhenNoAgents(t *testing.T) { defer func() { Registry = origRegistry }() ctx := cmdio.MockDiscard(t.Context()) - err := RecommendSkillsInstall(ctx, noopInstall) + err := RecommendSkillsInstall(ctx, noInstalledPlugins, noopInstall) assert.NoError(t, err) } @@ -94,7 +111,7 @@ func TestRecommendSkillsInstallNonInteractive(t *testing.T) { ctx, stderr := cmdio.NewTestContextWithStderr(t.Context()) ctx = telemetry.WithNewLogger(ctx) - err := RecommendSkillsInstall(ctx, noopInstall) + err := RecommendSkillsInstall(ctx, noInstalledPlugins, noopInstall) require.NoError(t, err) assert.Contains(t, stderr.String(), "databricks aitools install") assert.Equal(t, []protos.AitoolsHintKind{protos.AitoolsHintKindAppsInitTip}, hintKinds(t, ctx)) @@ -129,7 +146,7 @@ func TestRecommendSkillsInstallInteractiveDecline(t *testing.T) { errc := make(chan error, 1) go func() { - errc <- RecommendSkillsInstall(ctx, noopInstall) + errc <- RecommendSkillsInstall(ctx, noInstalledPlugins, noopInstall) }() _, err := testIO.Stdin.WriteString("n\n") diff --git a/libs/aitools/agents/skills.go b/libs/aitools/agents/skills.go index ac9acdafeb4..5bfc1866dd6 100644 --- a/libs/aitools/agents/skills.go +++ b/libs/aitools/agents/skills.go @@ -4,6 +4,7 @@ import ( "context" "os" "path/filepath" + "slices" "strings" "github.com/databricks/cli/libs/env" @@ -23,12 +24,16 @@ const ( // HasDatabricksToolingInstalled reports whether every detected agent already // has Databricks tooling, so `apps init` has nothing to recommend. Skills in // the shared canonical (or legacy) dir cover every agent. Otherwise each -// detected agent needs the databricks plugin in its own plugin manifest, -// installed for every project or for the working directory (see -// pluginInstall.appliesTo): a plugin installed for another project does not -// load for the app being created. It also reports true when no agent is -// detected. -func HasDatabricksToolingInstalled(ctx context.Context) bool { +// detected agent needs the databricks plugin. For an agent with a plugin +// manifest reader (Claude Code) that is its own plugin manifest, installed for +// every project or for the working directory (see pluginInstall.appliesTo): a +// plugin installed for another project does not load for the app being +// created. For Codex and Copilot the CLI install state is the only plugin +// source, so a plugin installed with the agent's own CLI is missed. +// installedPlugins is a parameter because this package cannot import the +// installer; callers pass installer.InstalledPluginAgents. It also reports +// true when no agent is detected. +func HasDatabricksToolingInstalled(ctx context.Context, installedPlugins func(context.Context) []string) bool { installed := DetectInstalled(ctx) if len(installed) == 0 || hasSharedSkills(ctx) { return true @@ -37,9 +42,13 @@ func HasDatabricksToolingInstalled(ctx context.Context) bool { if wd, err := os.Getwd(); err == nil { cwd = resolvePath(wd) } + recorded := installedPlugins(ctx) for _, a := range installed { if a.pluginInstalls == nil { - return false + if !slices.Contains(recorded, a.Name) { + return false + } + continue } // An unreadable manifest counts as no plugin, as before. if active, _ := a.DatabricksPluginActiveIn(ctx, cwd); !active { diff --git a/libs/aitools/agents/skills_test.go b/libs/aitools/agents/skills_test.go index 26ead3272c2..b9d474f42ee 100644 --- a/libs/aitools/agents/skills_test.go +++ b/libs/aitools/agents/skills_test.go @@ -11,12 +11,16 @@ import ( "github.com/stretchr/testify/require" ) +// noInstalledPlugins is the installedPlugins argument for a CLI install state +// that records no plugin. +func noInstalledPlugins(context.Context) []string { return nil } + func TestHasDatabricksToolingInstalledNoAgents(t *testing.T) { origRegistry := Registry Registry = []*Agent{} defer func() { Registry = origRegistry }() - assert.True(t, HasDatabricksToolingInstalled(t.Context())) + assert.True(t, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) } func TestHasDatabricksToolingInstalledCanonicalOnly(t *testing.T) { @@ -35,7 +39,7 @@ func TestHasDatabricksToolingInstalledCanonicalOnly(t *testing.T) { } defer func() { Registry = origRegistry }() - assert.True(t, HasDatabricksToolingInstalled(t.Context())) + assert.True(t, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) } func TestHasDatabricksToolingInstalledIgnoresAgentDir(t *testing.T) { @@ -56,7 +60,7 @@ func TestHasDatabricksToolingInstalledIgnoresAgentDir(t *testing.T) { } defer func() { Registry = origRegistry }() - assert.False(t, HasDatabricksToolingInstalled(t.Context())) + assert.False(t, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) } func TestHasDatabricksToolingInstalledWithOnlyNonDatabricksSkills(t *testing.T) { @@ -77,7 +81,7 @@ func TestHasDatabricksToolingInstalledWithOnlyNonDatabricksSkills(t *testing.T) } defer func() { Registry = origRegistry }() - assert.False(t, HasDatabricksToolingInstalled(t.Context())) + assert.False(t, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) } func TestHasDatabricksToolingInstalledNoSkillsDir(t *testing.T) { @@ -95,7 +99,7 @@ func TestHasDatabricksToolingInstalledNoSkillsDir(t *testing.T) { } defer func() { Registry = origRegistry }() - assert.False(t, HasDatabricksToolingInstalled(t.Context())) + assert.False(t, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) } func TestHasDatabricksToolingInstalledCustomSubdirNotChecked(t *testing.T) { @@ -116,7 +120,7 @@ func TestHasDatabricksToolingInstalledCustomSubdirNotChecked(t *testing.T) { } defer func() { Registry = origRegistry }() - assert.False(t, HasDatabricksToolingInstalled(t.Context())) + assert.False(t, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) } func TestHasDatabricksToolingInstalledDatabricksAppsCanonical(t *testing.T) { @@ -139,7 +143,7 @@ func TestHasDatabricksToolingInstalledDatabricksAppsCanonical(t *testing.T) { } defer func() { Registry = origRegistry }() - assert.True(t, HasDatabricksToolingInstalled(t.Context())) + assert.True(t, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) } func TestHasDatabricksSkillsInFollowsSymlinks(t *testing.T) { @@ -186,7 +190,7 @@ func TestHasDatabricksToolingInstalledLegacyPath(t *testing.T) { } defer func() { Registry = origRegistry }() - assert.True(t, HasDatabricksToolingInstalled(t.Context())) + assert.True(t, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) } func TestHasDatabricksToolingInstalled(t *testing.T) { @@ -228,7 +232,38 @@ func TestHasDatabricksToolingInstalled(t *testing.T) { Registry = registry t.Cleanup(func() { Registry = origRegistry }) - assert.Equal(t, tc.want, HasDatabricksToolingInstalled(t.Context())) + assert.Equal(t, tc.want, HasDatabricksToolingInstalled(t.Context(), noInstalledPlugins)) + }) + } +} + +// TestHasDatabricksToolingInstalledRecordedPlugins covers agents without a +// plugin manifest reader (Codex, Copilot): a plugin recorded in the CLI +// install state counts for them, and every detected agent still needs one. +func TestHasDatabricksToolingInstalledRecordedPlugins(t *testing.T) { + for _, tc := range []struct { + name string + agentDirs []string + recorded []string + want bool + }{ + {name: "codex and copilot plugins recorded", agentDirs: []string{".codex", ".copilot"}, recorded: []string{NameCodex, NameCopilot}, want: true}, + {name: "only the codex plugin recorded", agentDirs: []string{".codex", ".copilot"}, recorded: []string{NameCodex}, want: false}, + {name: "nothing recorded", agentDirs: []string{".codex", ".copilot"}, want: false}, + {name: "codex plugin recorded, cursor without tooling", agentDirs: []string{".codex", ".cursor"}, recorded: []string{NameCodex}, want: false}, + {name: "a claude code record without its manifest", agentDirs: []string{".claude"}, recorded: []string{NameClaudeCode}, want: false}, + } { + t.Run(tc.name, func(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Chdir(t.TempDir()) + for _, dir := range tc.agentDirs { + require.NoError(t, os.MkdirAll(filepath.Join(home, dir), 0o755)) + } + installedPlugins := func(context.Context) []string { return tc.recorded } + + assert.Equal(t, tc.want, HasDatabricksToolingInstalled(t.Context(), installedPlugins)) }) } } From abbcedec8f86382b85972c83351b28b83354fe8c Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 21:12:08 +0000 Subject: [PATCH 2/3] Add PR link to changelog fragment Co-authored-by: Isaac --- .nextchanges/cli/apps-init-recorded-plugin-tip.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.nextchanges/cli/apps-init-recorded-plugin-tip.md b/.nextchanges/cli/apps-init-recorded-plugin-tip.md index ebed02987f7..c007844db65 100644 --- a/.nextchanges/cli/apps-init-recorded-plugin-tip.md +++ b/.nextchanges/cli/apps-init-recorded-plugin-tip.md @@ -1 +1 @@ -* `apps init` no longer suggests installing skills to Codex and Copilot users who installed the Databricks plugin with `databricks aitools install`. +* `apps init` no longer suggests installing skills to Codex and Copilot users who installed the Databricks plugin with `databricks aitools install`. ([#7830](https://github.com/databricks/cli/pull/7830)) From 231f85e5a5d9b4a543c90bf135115111c3b03a6a Mon Sep 17 00:00:00 2001 From: Anton Nekipelov <226657+anton-107@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:08:07 +0000 Subject: [PATCH 3/3] Address review: isolate agent env in tests, commit recorded-plugin fixture, read install state once - Use testutil.SetAgentEnv in the new unit tests and unset the agent config-dir overrides in the acceptance script, so host agent dirs can't add a detected agent. - Commit the recorded-plugin home as a fixture instead of creating it in the script, and explain why CLAUDECODE is unset. - Read the CLI install state lazily in HasDatabricksToolingInstalled and once in MaybeVersionCheckTip. - Note that a plugin removed with the agent's own CLI still counts while its record remains. - Add a case with a Claude Code manifest plugin and a recorded Codex plugin, and make the recorded fixture in TestMaybeVersionCheckTip match what InstalledPluginAgents returns. Co-authored-by: Isaac --- .../recorded-plugin-home/.codex/.gitkeep | 0 .../recorded-plugin-home/.copilot/.gitkeep | 0 .../.databricks/aitools/skills/.state.json | 11 ++++++++ .../aitools/telemetry/apps-init-tip/script | 25 ++++++------------- libs/aitools/agents/recommend.go | 10 ++++++-- libs/aitools/agents/recommend_test.go | 5 ++-- libs/aitools/agents/skills.go | 13 ++++++---- libs/aitools/agents/skills_test.go | 21 ++++++++-------- 8 files changed, 48 insertions(+), 37 deletions(-) create mode 100644 acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.codex/.gitkeep create mode 100644 acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.copilot/.gitkeep create mode 100644 acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.databricks/aitools/skills/.state.json diff --git a/acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.codex/.gitkeep b/acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.codex/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.copilot/.gitkeep b/acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.copilot/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.databricks/aitools/skills/.state.json b/acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.databricks/aitools/skills/.state.json new file mode 100644 index 00000000000..398c2d0d610 --- /dev/null +++ b/acceptance/cmd/aitools/telemetry/apps-init-tip/recorded-plugin-home/.databricks/aitools/skills/.state.json @@ -0,0 +1,11 @@ +{ + "schema_version": 2, + "release": "v0.2.32", + "last_updated": "2026-01-01T00:00:00Z", + "skills": {}, + "scope": "global", + "plugins": { + "codex": {"marketplace": "databricks-agent-skills", "plugin": "databricks", "scope": "user", "version": "0.2.32"}, + "copilot": {"marketplace": "databricks-agent-skills", "plugin": "databricks", "scope": "user", "version": "0.2.32"} + } +} diff --git a/acceptance/cmd/aitools/telemetry/apps-init-tip/script b/acceptance/cmd/aitools/telemetry/apps-init-tip/script index b247386209c..b8ba57d90b8 100644 --- a/acceptance/cmd/aitools/telemetry/apps-init-tip/script +++ b/acceptance/cmd/aitools/telemetry/apps-init-tip/script @@ -4,7 +4,9 @@ sethome home export CLAUDECODE=1 unset CLAUDE_CODE_SESSION_ID -unset CLAUDE_CONFIG_DIR +# Agent detection reads these config-dir overrides besides HOME; unset them so +# the host's agent dirs can't add a detected agent. +unset CLAUDE_CONFIG_DIR XDG_CONFIG_HOME GEMINI_CLI_HOME PI_CODING_AGENT_DIR GOOSE_PATH_ROOT APPDATA title "apps init with flags prints the tip: one hint-shown event per hint printed" trace $CLI apps init --template ./template --skip-install --name app-tip > LOG.apps-init @@ -19,23 +21,12 @@ rm -rf app-plugin title "codex and copilot plugins recorded by aitools install: no tip, no event" # Codex and Copilot have no plugin manifest the CLI can read, so the plugin -# record in the CLI install state is what counts for them. +# record in the committed recorded-plugin-home/.databricks/aitools/skills/.state.json +# is what counts for them. sethome ./recorded-plugin-home +# CLAUDECODE from the first case would make the calling-agent install hint +# fire, since this home has no Claude Code plugin. unset CLAUDECODE -mkdir -p "$HOME/.codex" "$HOME/.copilot" "${USERPROFILE:-$HOME}/.databricks/aitools/skills" -cat > "${USERPROFILE:-$HOME}/.databricks/aitools/skills/.state.json" <<'STATE' -{ - "schema_version": 2, - "release": "v0.2.32", - "last_updated": "2026-01-01T00:00:00Z", - "skills": {}, - "scope": "global", - "plugins": { - "codex": {"marketplace": "databricks-agent-skills", "plugin": "databricks", "scope": "user", "version": "0.2.32"}, - "copilot": {"marketplace": "databricks-agent-skills", "plugin": "databricks", "scope": "user", "version": "0.2.32"} - } -} -STATE trace $CLI apps init --template ./template --skip-install --name app-recorded > LOG.apps-init-recorded trace print_telemetry -rm -rf app-recorded recorded-plugin-home +rm -rf app-recorded diff --git a/libs/aitools/agents/recommend.go b/libs/aitools/agents/recommend.go index f3631c1cd1b..963c382f990 100644 --- a/libs/aitools/agents/recommend.go +++ b/libs/aitools/agents/recommend.go @@ -38,7 +38,8 @@ func MaybeVersionCheckTip(ctx context.Context, installedPlugins func(context.Con if dbr.HasDetection(ctx) && dbr.RunsOnRuntime(ctx) { return } - if HasDatabricksToolingInstalled(ctx, installedPlugins) || len(installedPlugins(ctx)) > 0 { + // Any recorded plugin returns first, so the install state is read once. + if len(installedPlugins(ctx)) > 0 || HasDatabricksToolingInstalled(ctx, noInstalledPlugins) { return } // Recorded plugins are checked above, so DatabricksTooling only needs the @@ -52,8 +53,13 @@ func MaybeVersionCheckTip(ctx context.Context, installedPlugins func(context.Con cmdio.LogString(ctx, skillsTipText) } +// noInstalledPlugins is the installedPlugins argument to +// HasDatabricksToolingInstalled for a CLI install state that records no plugin. +func noInstalledPlugins(context.Context) []string { return nil } + // RecommendSkillsInstall checks if coding agents are detected without Databricks tooling (skills -// or the databricks plugin) installed; installedPlugins is passed to HasDatabricksToolingInstalled. +// or the databricks plugin) installed. Callers pass installer.InstalledPluginAgents as +// installedPlugins (see HasDatabricksToolingInstalled). // In interactive mode, prompts the user to install now using installFn; a "no" also turns // auto-install off. In non-interactive mode, prints a hint. func RecommendSkillsInstall(ctx context.Context, installedPlugins func(context.Context) []string, installFn func(context.Context) error) error { diff --git a/libs/aitools/agents/recommend_test.go b/libs/aitools/agents/recommend_test.go index da4d2fc637c..241878b52f3 100644 --- a/libs/aitools/agents/recommend_test.go +++ b/libs/aitools/agents/recommend_test.go @@ -65,8 +65,7 @@ func TestRecommendSkillsInstallSkipsWhenPluginInstalled(t *testing.T) { func TestRecommendSkillsInstallSkipsWhenPluginRecorded(t *testing.T) { home := t.TempDir() - t.Setenv("HOME", home) - t.Setenv("USERPROFILE", home) + testutil.SetAgentEnv(t, "HOME", home, "USERPROFILE", home) t.Chdir(t.TempDir()) require.NoError(t, os.MkdirAll(filepath.Join(home, ".codex"), 0o755)) require.NoError(t, os.MkdirAll(filepath.Join(home, ".copilot"), 0o755)) @@ -168,7 +167,7 @@ func TestRecommendSkillsInstallInteractiveDecline(t *testing.T) { func TestMaybeVersionCheckTip(t *testing.T) { noPlugins := func(context.Context) []string { return nil } - recordedCodexPlugin := func(context.Context) []string { return []string{"codex_0.2.6"} } + recordedCodexPlugin := func(context.Context) []string { return []string{NameCodex} } for _, tc := range []struct { name string diff --git a/libs/aitools/agents/skills.go b/libs/aitools/agents/skills.go index 5bfc1866dd6..306ff603795 100644 --- a/libs/aitools/agents/skills.go +++ b/libs/aitools/agents/skills.go @@ -6,6 +6,7 @@ import ( "path/filepath" "slices" "strings" + "sync" "github.com/databricks/cli/libs/env" ) @@ -29,10 +30,12 @@ const ( // every project or for the working directory (see pluginInstall.appliesTo): a // plugin installed for another project does not load for the app being // created. For Codex and Copilot the CLI install state is the only plugin -// source, so a plugin installed with the agent's own CLI is missed. +// source, so a plugin installed with the agent's own CLI is missed, and a +// plugin later removed with it still counts until the record is cleared. // installedPlugins is a parameter because this package cannot import the -// installer; callers pass installer.InstalledPluginAgents. It also reports -// true when no agent is detected. +// installer; callers pass installer.InstalledPluginAgents. It is called only +// once a detected agent has no plugin manifest reader. It also reports true +// when no agent is detected. func HasDatabricksToolingInstalled(ctx context.Context, installedPlugins func(context.Context) []string) bool { installed := DetectInstalled(ctx) if len(installed) == 0 || hasSharedSkills(ctx) { @@ -42,10 +45,10 @@ func HasDatabricksToolingInstalled(ctx context.Context, installedPlugins func(co if wd, err := os.Getwd(); err == nil { cwd = resolvePath(wd) } - recorded := installedPlugins(ctx) + recorded := sync.OnceValue(func() []string { return installedPlugins(ctx) }) for _, a := range installed { if a.pluginInstalls == nil { - if !slices.Contains(recorded, a.Name) { + if !slices.Contains(recorded(), a.Name) { return false } continue diff --git a/libs/aitools/agents/skills_test.go b/libs/aitools/agents/skills_test.go index b9d474f42ee..8c02aa74aa8 100644 --- a/libs/aitools/agents/skills_test.go +++ b/libs/aitools/agents/skills_test.go @@ -7,14 +7,11 @@ import ( "path/filepath" "testing" + "github.com/databricks/cli/internal/testutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -// noInstalledPlugins is the installedPlugins argument for a CLI install state -// that records no plugin. -func noInstalledPlugins(context.Context) []string { return nil } - func TestHasDatabricksToolingInstalledNoAgents(t *testing.T) { origRegistry := Registry Registry = []*Agent{} @@ -242,25 +239,29 @@ func TestHasDatabricksToolingInstalled(t *testing.T) { // install state counts for them, and every detected agent still needs one. func TestHasDatabricksToolingInstalledRecordedPlugins(t *testing.T) { for _, tc := range []struct { - name string - agentDirs []string - recorded []string - want bool + name string + agentDirs []string + claudePlugin bool + recorded []string + want bool }{ {name: "codex and copilot plugins recorded", agentDirs: []string{".codex", ".copilot"}, recorded: []string{NameCodex, NameCopilot}, want: true}, {name: "only the codex plugin recorded", agentDirs: []string{".codex", ".copilot"}, recorded: []string{NameCodex}, want: false}, {name: "nothing recorded", agentDirs: []string{".codex", ".copilot"}, want: false}, {name: "codex plugin recorded, cursor without tooling", agentDirs: []string{".codex", ".cursor"}, recorded: []string{NameCodex}, want: false}, {name: "a claude code record without its manifest", agentDirs: []string{".claude"}, recorded: []string{NameClaudeCode}, want: false}, + {name: "claude code plugin in its manifest, codex plugin recorded", agentDirs: []string{".claude", ".codex"}, claudePlugin: true, recorded: []string{NameCodex}, want: true}, } { t.Run(tc.name, func(t *testing.T) { home := t.TempDir() - t.Setenv("HOME", home) - t.Setenv("USERPROFILE", home) + testutil.SetAgentEnv(t, "HOME", home, "USERPROFILE", home) t.Chdir(t.TempDir()) for _, dir := range tc.agentDirs { require.NoError(t, os.MkdirAll(filepath.Join(home, dir), 0o755)) } + if tc.claudePlugin { + writePluginManifest(t, home, `{"plugins":{"databricks@claude-plugins-official":[{"scope":"user","version":"0.2.6"}]}}`) + } installedPlugins := func(context.Context) []string { return tc.recorded } assert.Equal(t, tc.want, HasDatabricksToolingInstalled(t.Context(), installedPlugins))