From b638cb9fef686ee1414770158188059b81bb9aec Mon Sep 17 00:00:00 2001 From: ethan ma Date: Thu, 12 Nov 2026 21:23:20 +0000 Subject: [PATCH] Suppress repeated AI tooling hints in non-interactive sessions --- .nextchanges/cli/quiet-aitools-hint.md | 1 + libs/aitools/agents/hint.go | 8 +++++ libs/aitools/agents/hint_test.go | 47 ++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 .nextchanges/cli/quiet-aitools-hint.md diff --git a/.nextchanges/cli/quiet-aitools-hint.md b/.nextchanges/cli/quiet-aitools-hint.md new file mode 100644 index 00000000000..eabeb72046d --- /dev/null +++ b/.nextchanges/cli/quiet-aitools-hint.md @@ -0,0 +1 @@ +Suppress the AI tooling installation hint in non-interactive sessions and when Claude Code does not provide a session ID. diff --git a/libs/aitools/agents/hint.go b/libs/aitools/agents/hint.go index 802c04bbc90..f49b5c48a92 100644 --- a/libs/aitools/agents/hint.go +++ b/libs/aitools/agents/hint.go @@ -61,6 +61,14 @@ func MaybeHint(ctx context.Context, cmd *cobra.Command) { if !cmdio.HasIO(ctx) { return } + if cmdio.GetInteractiveMode(ctx) != cmdio.InteractiveModeFull { + return + } + // Without a session ID we cannot throttle the hint reliably across CLI + // invocations, so stay quiet instead of printing it on every command. + if env.Get(ctx, claudeSessionEnv) == "" { + return + } // Check the session throttle before the filesystem probe: once a session has // been hinted, later commands short-circuit here and skip the plugin/skills // detection. The throttle token is written only after a hint prints (below), diff --git a/libs/aitools/agents/hint_test.go b/libs/aitools/agents/hint_test.go index e82cfcd32d8..bafc3947a7a 100644 --- a/libs/aitools/agents/hint_test.go +++ b/libs/aitools/agents/hint_test.go @@ -3,6 +3,7 @@ package agents import ( "bytes" "context" + "io" "log/slog" "os" "path/filepath" @@ -10,6 +11,7 @@ import ( "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/env" + "github.com/databricks/cli/libs/flags" "github.com/databricks/cli/libs/log" "github.com/databricks/databricks-sdk-go/useragent" "github.com/spf13/cobra" @@ -54,9 +56,11 @@ func setClaudeAgent(t *testing.T) { // HOME + cache dir, so detection and the session throttle read only the test's // temp state. home is returned so the test can drop fixtures under it. func claudeCtx(t *testing.T, home string) (context.Context, *bytes.Buffer) { - ctx, stderr := cmdio.NewTestContextWithStderr(t.Context()) + stderr := &bytes.Buffer{} + ctx := cmdio.InContext(t.Context(), cmdio.NewTestIO(nil, io.Discard, stderr)) ctx = env.WithUserHomeDir(ctx, home) ctx = env.Set(ctx, "DATABRICKS_CACHE_DIR", t.TempDir()) + ctx = env.Set(ctx, claudeSessionEnv, "session-test") return ctx, stderr } @@ -177,8 +181,7 @@ func TestMaybeHint_ThrottledPerSession(t *testing.T) { home := t.TempDir() cacheDir := t.TempDir() newCtx := func() (context.Context, *bytes.Buffer) { - ctx, stderr := cmdio.NewTestContextWithStderr(t.Context()) - ctx = env.WithUserHomeDir(ctx, home) + ctx, stderr := claudeCtx(t, home) ctx = env.Set(ctx, "DATABRICKS_CACHE_DIR", cacheDir) ctx = env.Set(ctx, claudeSessionEnv, "session-abc") return ctx, stderr @@ -193,3 +196,41 @@ func TestMaybeHint_ThrottledPerSession(t *testing.T) { MaybeHint(ctx2, regularCmd()) assert.Empty(t, stderr2.String()) } + +func TestMaybeHint_MissingSessionSilent(t *testing.T) { + setClaudeAgent(t) + ctx, stderr := claudeCtx(t, t.TempDir()) + ctx = env.Set(ctx, claudeSessionEnv, "") + for range 2 { + MaybeHint(ctx, regularCmd()) + } + assert.Empty(t, stderr.String()) +} + +func TestMaybeHint_NonInteractiveSilent(t *testing.T) { + setClaudeAgent(t) + for _, tt := range []struct { + name string + stderrTTY bool + }{ + {name: "pipes"}, + {name: "redirected stdin", stderrTTY: true}, + } { + t.Run(tt.name, func(t *testing.T) { + ctx, _ := claudeCtx(t, t.TempDir()) + stderr := &bytes.Buffer{} + var errWriter io.Writer = stderr + if tt.stderrTTY { + errWriter = cmdio.FakeTTY(stderr) + } + ctx = cmdio.InContext(ctx, cmdio.NewIO(ctx, flags.OutputText, &bytes.Buffer{}, io.Discard, errWriter, "", "")) + MaybeHint(ctx, regularCmd()) + assert.Empty(t, stderr.String()) + + // A suppressed invocation must not consume the session's hint. + ctx = cmdio.InContext(ctx, cmdio.NewTestIO(nil, io.Discard, stderr)) + MaybeHint(ctx, regularCmd()) + assert.Contains(t, stderr.String(), hintText) + }) + } +}