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/quiet-aitools-hint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Suppress the AI tooling installation hint in non-interactive sessions and when Claude Code does not provide a session ID.
8 changes: 8 additions & 0 deletions libs/aitools/agents/hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
47 changes: 44 additions & 3 deletions libs/aitools/agents/hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package agents
import (
"bytes"
"context"
"io"
"log/slog"
"os"
"path/filepath"
"testing"

"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"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
})
}
}
Loading