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
3 changes: 2 additions & 1 deletion cmd/aitools/autoinstall_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"strings"
"time"

"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/aitools/agents"
"github.com/databricks/cli/libs/aitools/autoinstall"
"github.com/databricks/cli/libs/aitools/installer"
Expand Down Expand Up @@ -680,7 +681,7 @@ func (t toolsPlan) install(ctx context.Context) (installResult, error) {
func updateTools(ctx context.Context, globalDir string, before *installer.InstallState) (installResult, error) {
uctx := telemetry.WithNewLogger(ctx)
uctx = context.WithValue(uctx, funnelKey{}, &commandFunnel{command: protos.AitoolsCommandUpdate})
uctx = context.WithValue(uctx, telemetryAuthKey{}, &TelemetryAuth{})
uctx = context.WithValue(uctx, telemetryAuthKey{}, &root.TelemetryAuth{})
updateErr := runUpdate(uctx, updateFlags{scope: installer.ScopeGlobal, keepModified: true})
// The update refuses the raw skills after it updated the plugins, so a
// refusal still reports the plugins it changed.
Expand Down
4 changes: 2 additions & 2 deletions cmd/aitools/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func newInstallCmd(recordSkillsOnly bool) *cobra.Command {
var skillsFlag, agentsFlag, scopeFlag, pathFlag string
var includeExperimental, skillsOnly bool
var projectFlag, globalFlag bool
var auth *TelemetryAuth
var auth *root.TelemetryAuth

cmd := &cobra.Command{
Use: "install",
Expand Down Expand Up @@ -449,7 +449,7 @@ Supported agents: ` + strings.Join(agents.SupportedNames(), ", "),
cmd.Flags().BoolVar(&globalFlag, "global", false, "Install globally (default)")
markScopeBoolsDeprecated(cmd)
// Resolve auth best-effort and time-bounded so telemetry can upload.
auth = WithTelemetryAuth(cmd)
auth = root.WithTelemetryAuth(cmd)
return cmd
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/aitools/mcp_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Supported agents: ` + strings.Join(mcpAgentNames(), ", "),
}
runErr := runMcpAdd(ctx, cmd, f, jsonMode, out)
logMcpEvent(ctx, protos.AitoolsMcpEvent{
CallingAgent: callingAgentType(),
CallingAgent: root.CallingAgentType(),
Operation: protos.AitoolsMcpOperationAdd,
Servers: addServerResults(out.Servers),
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/aitools/mcp_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func signInEvent(operation protos.AitoolsMcpOperation, out *mcpSignInOutput, err
return signInEventOf(out.Service, out.State, out.alreadySignedIn, err)
}
return protos.AitoolsMcpEvent{
CallingAgent: callingAgentType(),
CallingAgent: root.CallingAgentType(),
Operation: operation,
Servers: []protos.AitoolsMcpServerResult{signOutServerResult(out.Service, out.State, err)},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/aitools/mcp_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func writeRemoveJSON(cmd *cobra.Command, out *removeOutput, runErr error) error
// output is written. A run that logged no event touched no server, so it has nothing to upload and sets no config.
func logRemoveEvent(ctx context.Context, out *removeOutput) {
if !logMcpEvent(ctx, protos.AitoolsMcpEvent{
CallingAgent: callingAgentType(),
CallingAgent: root.CallingAgentType(),
Operation: protos.AitoolsMcpOperationRemove,
Servers: out.results,
}) {
Expand Down
29 changes: 7 additions & 22 deletions cmd/aitools/mcp_telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"strings"

"github.com/databricks/cli/libs/aitools/agents"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/aitools/mcp"
"github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/log"
Expand All @@ -30,7 +30,7 @@ func setUploadConfig(ctx context.Context, profileName, configFile string, bound
return
}
}
cfg, err := mcp.BoundUploadConfig(ctx, profileName, configFile, telemetryAuthBudget)
cfg, err := mcp.BoundUploadConfig(ctx, profileName, configFile, root.TelemetryAuthBudget)
if err != nil {
log.Debugf(ctx, "telemetry: cannot resolve profile %s to upload with: %s", profileName, err)
telemetry.SkipUpload(ctx)
Expand Down Expand Up @@ -109,28 +109,13 @@ func mcpServiceType(fullName string) protos.AitoolsMcpService {
return protos.AitoolsMcpServiceOtherSystem
}

// CallingAgentType returns the agent that drives the CLI, Unspecified when none is detected. The skills commands
// report it as their calling agent too.
func CallingAgentType() protos.AitoolsAgentType {
return callingAgentType()
}

// callingAgentType returns the agent that drives the CLI, Unspecified when none is detected.
func callingAgentType() protos.AitoolsAgentType {
a := agents.CallingAgent()
if a == nil {
return protos.AitoolsAgentTypeUnspecified
}
return agentType(a.Name)
}

// proxyAgentType returns the agent that started the proxy: the --agent flag when given, else the
// detected agent.
func proxyAgentType(flag string) protos.AitoolsAgentType {
if flag == "" {
return callingAgentType()
return root.CallingAgentType()
}
return agentType(flag)
return root.AgentType(flag)
}

// logMcpEvent buffers an MCP event for the next upload and reports whether it did. An event without server
Expand Down Expand Up @@ -184,7 +169,7 @@ func addServerResults(servers []addServerOutput) []protos.AitoolsMcpServerResult
for _, a := range s.Agents {
r := protos.AitoolsMcpServerResult{
Service: mcpServiceType(s.Service),
Agent: agentType(a.Name),
Agent: root.AgentType(a.Name),
SignInState: addSignInState(s),
}
switch a.Status {
Expand All @@ -205,7 +190,7 @@ func addServerResults(servers []addServerOutput) []protos.AitoolsMcpServerResult
// removeServerResult returns the result of removing one server from one agent config. An entry that was deleted, or
// pruned (its record dropped), is CHANGED. An entry that was changed outside this CLI is SKIPPED: it is left in place.
func removeServerResult(service, agent string, outcome removeOutcome, err error) protos.AitoolsMcpServerResult {
r := protos.AitoolsMcpServerResult{Service: mcpServiceType(service), Agent: agentType(agent)}
r := protos.AitoolsMcpServerResult{Service: mcpServiceType(service), Agent: root.AgentType(agent)}
switch {
case err != nil:
r.Outcome = protos.AitoolsTargetOutcomeFailed
Expand Down Expand Up @@ -252,7 +237,7 @@ func signInServerResult(service, state string, alreadySignedIn bool, err error)
// already signed in is UNCHANGED.
func signInEventOf(service, state string, alreadySignedIn bool, err error) protos.AitoolsMcpEvent {
return protos.AitoolsMcpEvent{
CallingAgent: callingAgentType(),
CallingAgent: root.CallingAgentType(),
Operation: protos.AitoolsMcpOperationSignIn,
Servers: []protos.AitoolsMcpServerResult{signInServerResult(service, state, alreadySignedIn, err)},
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/aitools/mcp_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"slices"
"testing"

"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/aitools/agents"
"github.com/databricks/cli/libs/aitools/mcp"
"github.com/databricks/cli/libs/env"
Expand Down Expand Up @@ -335,7 +336,7 @@ func TestBoundProfileCount(t *testing.T) {
func TestSignInEventOf(t *testing.T) {
// An ACTIVE credential that the add found signed in is UNCHANGED, as add --login reports it.
assert.Equal(t, protos.AitoolsMcpEvent{
CallingAgent: callingAgentType(),
CallingAgent: root.CallingAgentType(),
Operation: protos.AitoolsMcpOperationSignIn,
Servers: []protos.AitoolsMcpServerResult{{
Service: protos.AitoolsMcpServiceGitHub,
Expand Down
Loading
Loading