diff --git a/pkg/telemetry/telemetry_test.go b/pkg/telemetry/telemetry_test.go index 80d8da46c..b3f9e0100 100644 --- a/pkg/telemetry/telemetry_test.go +++ b/pkg/telemetry/telemetry_test.go @@ -12,7 +12,6 @@ import ( "testing" "time" - "github.com/spf13/cobra" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -539,67 +538,6 @@ func TestTrackServerStart(t *testing.T) { assert.True(t, executed) } -// TestBuildCommandInfo tests the BuildCommandInfo function with all commands -func TestBuildCommandInfo(t *testing.T) { - testCases := []struct { - name string - command string - args []string - expected CommandInfo - }{ - { - name: "run command with config", - command: "run", - args: []string{"config.yaml", "--debug"}, - expected: CommandInfo{ - Action: "run", - Args: []string{"config.yaml"}, - Flags: []string{}, - }, - }, - { - name: "pull command with image", - command: "pull", - args: []string{"user/agent:latest"}, - expected: CommandInfo{ - Action: "pull", - Args: []string{"user/agent:latest"}, - Flags: []string{}, - }, - }, - { - name: "catalog command", - command: "catalog", - args: []string{}, - expected: CommandInfo{ - Action: "catalog", - Args: []string{}, - Flags: []string{}, - }, - }, - { - name: "version command", - command: "version", - args: []string{}, - expected: CommandInfo{ - Action: "version", - Args: []string{}, - Flags: []string{}, - }, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - cmd := &cobra.Command{Use: tc.command} - result := BuildCommandInfo(cmd, tc.args, tc.command) - - assert.Equal(t, tc.expected.Action, result.Action) - assert.Equal(t, tc.expected.Args, result.Args) - }) - } -} - // TestGlobalTelemetryFunctions tests the global telemetry convenience functions func TestGlobalTelemetryFunctions(t *testing.T) { // Save original global state diff --git a/pkg/telemetry/utils.go b/pkg/telemetry/utils.go index cb5162d36..72bfd219b 100644 --- a/pkg/telemetry/utils.go +++ b/pkg/telemetry/utils.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/google/uuid" - "github.com/spf13/cobra" "github.com/docker/cagent/pkg/paths" ) @@ -100,54 +99,3 @@ type CommandInfo struct { Args []string Flags []string } - -// BuildCommandInfo extracts detailed command information for telemetry -func BuildCommandInfo(cmd *cobra.Command, args []string, baseName string) CommandInfo { - info := CommandInfo{ - Action: baseName, - Args: []string{}, - Flags: []string{}, - } - - // Only capture arguments for specific commands where they provide valuable context - shouldCaptureArgs := baseName == "run" || baseName == "pull" || baseName == "catalog" - - if shouldCaptureArgs { - // Add subcommands from args (first non-flag arguments) - for _, arg := range args { - if !strings.HasPrefix(arg, "-") { - info.Args = append(info.Args, arg) - } else { - // Stop at first flag - break - } - } - } - - // Add important flags that provide context - if cmd.Flags() != nil { - // Check for help flag - if help, _ := cmd.Flags().GetBool("help"); help { - info.Flags = append(info.Flags, "--help") - } - - // Check for version flag (if it exists) - if cmd.Flags().Lookup("version") != nil { - if version, _ := cmd.Flags().GetBool("version"); version { - info.Flags = append(info.Flags, "--version") - } - } - - // Check for other commonly used flags (more relevant for run/pull commands) - if shouldCaptureArgs { - flagsToCheck := []string{"config", "agent", "model", "output", "format", "yolo"} - for _, flagName := range flagsToCheck { - if flag := cmd.Flags().Lookup(flagName); flag != nil && flag.Changed { - info.Flags = append(info.Flags, "--"+flagName) - } - } - } - } - - return info -}