Repository: GoogleCloudPlatform/kubectl-ai
File: main.go (Go)

Code before:
	"github.com/GoogleCloudPlatform/kubectl-ai/pkg/journal"
	"github.com/GoogleCloudPlatform/kubectl-ai/pkg/tools"
	"github.com/GoogleCloudPlatform/kubectl-ai/pkg/ui"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"

	"k8s.io/klog/v2"
	"sigs.k8s.io/yaml"
)

// Using the defaults from goreleaser as per https://goreleaser.com/cookbooks/using-main.version/
var (
	version = "dev"
	commit  = "none"
	date    = "unknown"
)

var (
	// CLI related
	opt                    = Options{}
	maxIterations          int
	kubeconfigPath         string
	promptTemplateFilePath string
	tracePath              string
	removeWorkDir          bool
	geminiModels           = []string{
		"gemini-2.5-pro-preview-03-25",
		"gemini-2.0-flash",
	}

	rootCmd = &cobra.Command{
		Use:   "kubectl-ai",
		Short: "Run the kubectl-ai agent",
		RunE:  runCmd,
	}
)

type Options struct {
	ProviderID string `json:"llmProvider,omitempty"`
	ModelID    string `json:"model,omitempty"`
	// SkipPermissions is a flag to skip asking for confirmation before executing kubectl commands
	// that modifies resources in the cluster.
	SkipPermissions bool `json:"skipPermissions,omitempty"`
	// EnableToolUseShim is a flag to enable tool use shim.
	// TODO(droot): figure out a better way to discover if the model supports tool use
	// and set this automatically.
	EnableToolUseShim bool `json:"enableToolUseShim,omitempty"`
	// Quiet flag indicates if the agent should run in non-interactive mode.
	// It requires a query to be provided as a positional argument.
	Quiet     bool `json:"quiet,omitempty"`
	MCPServer bool

Review comment (suggestion):
same, would just declare the type and set default values elsewhere, surely the init() at that point.

Code after:
	"github.com/GoogleCloudPlatform/kubectl-ai/pkg/journal"
	"github.com/GoogleCloudPlatform/kubectl-ai/pkg/tools"
	"github.com/GoogleCloudPlatform/kubectl-ai/pkg/ui"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"

	"k8s.io/klog/v2"
	"sigs.k8s.io/yaml"
)

// Using the defaults from goreleaser as per https://goreleaser.com/cookbooks/using-main.version/
var (
	version = "dev"
	commit  = "none"
	date    = "unknown"
)

const viperEnvPrefix = "KUBECTL_AI"

var rootCmd = &cobra.Command{
	Use:   "kubectl-ai",
	Short: "A CLI tool to interact with Kubernetes using natural language",
	Long:  "kubectl-ai is a command-line tool that allows you to interact with your Kubernetes cluster using natural language queries. It leverages large language models to understand your intent and translate it into kubectl",
	Args:  cobra.MaximumNArgs(1), // Only one positional arg is allowed.
	RunE:  runCmd,
}

type Options struct {
	ProviderID string `json:"llmProvider,omitempty"`
	ModelID    string `json:"model,omitempty"`
	// SkipPermissions is a flag to skip asking for confirmation before executing kubectl commands
	// that modifies resources in the cluster.
	SkipPermissions bool `json:"skipPermissions,omitempty"`
	// EnableToolUseShim is a flag to enable tool use shim.
	// TODO(droot): figure out a better way to discover if the model supports tool use
	// and set this automatically.
	EnableToolUseShim bool `json:"enableToolUseShim,omitempty"`
	// Quiet flag indicates if the agent should run in non-interactive mode.
	// It requires a query to be provided as a positional argument.
	Quiet                  bool   `json:"quiet,omitempty"`
	MCPServer              bool   `json:"mcpServer,omitempty"`
	MaxIterations          int    `json:"maxIterations,omitempty"`
	KubeConfigPath         string `json:"kubeConfigPath,omitempty"`
	PromptTemplateFilePath string `json:"promptTemplateFilePath,omitempty"`
	TracePath              string `json:"tracePath,omitempty"`
	RemoveWorkDir          bool   `json:"removeWorkDir,omitempty"`
}

func (o *Options) InitDefaults() {
	o.ProviderID = "gemini"
	o.ModelID = "gemini-2.5-pro-preview-03-25"