package cmd

import (
	"sync"

	"github.com/tidbcloud/AgentTeam/desktop/internal/operator"
)

var (
	cachedOp operator.Operator
	opOnce   sync.Once
	opErr    error
)

var getOperator = GetOperator

// GetOperator returns the singleton Operator, auto-detecting daemon mode (gRPC) when the daemon is running, or falling back to direct file-backed operations.
// The operator is created once per process invocation and reused.
func GetOperator() (operator.Operator, error) {
	opOnce.Do(func() {
		cachedOp, opErr = operator.New()
	})
	return cachedOp, opErr
}
