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

Code before:

	"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
}

func (o *Options) InitDefaults() {
	o.ProviderID = "gemini"
	o.ModelID = geminiModels[0]

Review comment (suggestion):
for sake of clarity and to prepare future enhancement, i would define `var rootCmd` on its own before line 50.

Code after:

	"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"
	// by default, confirm before executing kubectl commands that modify resources in the cluster.
	o.SkipPermissions = false
	o.MCPServer = false
	// We now default to our strongest model (gemini-2.5-pro-exp-03-25) which supports tool use natively.
	// so we don't need shim.