cli

package
v1.0.51 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CatalogFixtureEnv    = "DWS_CATALOG_FIXTURE"
	CacheDirEnv          = "DWS_CACHE_DIR"
	PluginColdTimeoutEnv = "DWS_PLUGIN_COLD_TIMEOUT"
)

Variables

This section is empty.

Functions

func NewMCPCommand

NewMCPCommand returns a stub command since the canonical discovery surface has been removed. The command tree is now built from plugins and static endpoint registration only.

func NewSchemaCommand

func NewSchemaCommand(_ CatalogLoader, helperTools HelperToolFetcher) *cobra.Command

NewSchemaCommand returns a stub schema command since the canonical catalog discovery has been removed.

func OverridePriority

func OverridePriority(cmd *cobra.Command) int

OverridePriority delegates to cobracmd.OverridePriority.

func ReadFileArg

func ReadFileArg(value string) (string, bool, error)

ReadFileArg reads the contents of a file referenced by the @filename syntax. Returns the original value unchanged if it does not start with "@" or is otherwise not a file-path-shaped value (e.g. "@所有人" is treated as plain text, not a path). Returns an error if the file cannot be read or exceeds the size limit.

Note: @- (stdin) is NOT handled here; use ResolveInputSource instead.

func ReadStdin

func ReadStdin() (string, error)

ReadStdin reads all data from stdin unconditionally (up to maxStdinSize). Use this when the caller has explicitly requested stdin via @-.

func ReadStdinIfPiped

func ReadStdinIfPiped() (string, error)

ReadStdinIfPiped reads all data from stdin if it is a pipe (not a terminal). Returns empty string if stdin is a terminal or has no data.

func ResolveInputSource

func ResolveInputSource(value string, flagName string, guard *StdinGuard) (string, error)

ResolveInputSource resolves a flag value that may reference an external input source. It supports three forms:

  • "@-" reads from stdin (requires StdinGuard claim)
  • "@<path>" reads from the named file
  • anything else returned unchanged

The flagName parameter is used only for error messages and StdinGuard tracking.

func SetOverridePriority

func SetOverridePriority(cmd *cobra.Command, priority int)

SetOverridePriority delegates to cobracmd.SetOverridePriority.

func StdinIsPipe

func StdinIsPipe() bool

StdinIsPipe reports whether stdin is a pipe (not a terminal). This is a non-consuming check — it only inspects file mode via stat.

func ValidateInputSchema

func ValidateInputSchema(params map[string]any, schema map[string]any) error

ValidateInputSchema performs strict local validation for MCP tool inputs. It enforces required/type/enum checks and rejects unknown properties by default.

Types

type CLIFlagHint added in v1.0.48

type CLIFlagHint struct {
	Shorthand string `json:"shorthand,omitempty"`
	Alias     string `json:"alias,omitempty"`
}

CLIFlagHint holds CLI flag alias/shorthand metadata for a tool parameter.

type CanonicalProduct added in v1.0.48

type CanonicalProduct struct {
	ID          string           `json:"id"`
	DisplayName string           `json:"display_name"`
	Description string           `json:"description,omitempty"`
	ServerKey   string           `json:"server_key"`
	Endpoint    string           `json:"endpoint"`
	Source      string           `json:"source,omitempty"`
	Tools       []ToolDescriptor `json:"tools"`
}

CanonicalProduct represents a single MCP product in the catalog.

func (CanonicalProduct) FindTool added in v1.0.48

func (p CanonicalProduct) FindTool(name string) (ToolDescriptor, bool)

FindTool returns the tool with the given RPC name.

type Catalog added in v1.0.48

type Catalog struct {
	Products []CanonicalProduct `json:"products"`
}

Catalog holds the discovered MCP product surface.

func (Catalog) FindProduct added in v1.0.48

func (c Catalog) FindProduct(id string) (CanonicalProduct, bool)

FindProduct returns the product with the given ID.

type CatalogDegraded added in v1.0.9

type CatalogDegraded struct {
	Reason      CatalogDegradedReason
	Hint        string
	ServerCount int
}

CatalogDegraded is returned by EnvironmentLoader.Load when discovery fails for a diagnosable reason. Callers that need graceful degradation (e.g. the runtime runner) can check errors.As and fall back to an empty catalog; callers like the schema command can surface the hint.

func (*CatalogDegraded) Error added in v1.0.9

func (e *CatalogDegraded) Error() string

type CatalogDegradedReason added in v1.0.9

type CatalogDegradedReason string

CatalogDegradedReason identifies why catalog discovery returned empty.

const (
	DegradedUnauthenticated   CatalogDegradedReason = "unauthenticated"
	DegradedMarketUnreachable CatalogDegradedReason = "market_unreachable"
	DegradedRuntimeAllFailed  CatalogDegradedReason = "runtime_all_failed"
)

type CatalogLoader

type CatalogLoader interface {
	Load(context.Context) (Catalog, error)
}

CatalogLoader loads the canonical catalog.

func CatalogLoaderFrom

func CatalogLoaderFrom(catalog Catalog, err error) CatalogLoader

CatalogLoaderFrom creates a CatalogLoader that returns a pre-loaded catalog and error.

type EnvironmentLoader

type EnvironmentLoader struct {
	LookupEnv              func(string) (string, bool)
	CatalogBaseURLOverride string
	AuthTokenFunc          func(context.Context) string
	LoggerFunc             func() *slog.Logger
}

EnvironmentLoader provides catalog loading. In the post-discovery architecture this always returns an empty catalog; endpoint resolution is handled by the direct runtime path.

func NewEnvironmentLoader

func NewEnvironmentLoader() EnvironmentLoader

NewEnvironmentLoader creates an EnvironmentLoader with default settings.

func (EnvironmentLoader) Load

Load returns an empty catalog. All endpoint resolution now uses the direct runtime path (dynamic server registry).

type FlagKind

type FlagKind string

type FlagSpec

type FlagSpec struct {
	PropertyName string
	FlagName     string
	Alias        string
	Shorthand    string
	Kind         FlagKind
	Description  string
}

func BuildFlagSpecs

func BuildFlagSpecs(schema map[string]any, hints map[string]CLIFlagHint) []FlagSpec

type HelperToolFetcher added in v1.0.42

type HelperToolFetcher func(ctx context.Context, source string) (map[string]HelperToolSchema, error)

HelperToolFetcher loads a helper MCP server's tools/list LIVE and returns toolName→schema for the given source (e.g. "op-app" for dev app commands, "devdoc" for dev doc commands). The schema command injects this so dev_schema.go can resolve a command's MCP tool and render its real schema without the cli package importing app/transport. Implementations should cache per-source per-process so repeated `dws schema dev.*` only hit the network once per source.

type HelperToolSchema added in v1.0.42

type HelperToolSchema struct {
	Name        string
	Description string
	Properties  map[string]any // MCP param name → property object {type,description,default?,...}
	Required    []string       // MCP param names that are required
}

HelperToolSchema is the live op-app tool schema the renderer needs: the raw MCP description plus the inputSchema's properties/required, exactly as the server returned them (no local transformation of CONTENT).

type StaticLoader

type StaticLoader struct {
	Catalog Catalog
}

StaticLoader returns a pre-built catalog.

func (StaticLoader) Load

func (l StaticLoader) Load(_ context.Context) (Catalog, error)

type StdinGuard

type StdinGuard struct {
	// contains filtered or unexported fields
}

StdinGuard ensures stdin is consumed at most once per command invocation. Multiple flags using @- or implicit stdin fallback would race on the same reader; StdinGuard detects and rejects the second claim with a clear error.

func NewStdinGuard

func NewStdinGuard() *StdinGuard

NewStdinGuard creates a fresh guard for one command invocation.

func (*StdinGuard) Claim

func (g *StdinGuard) Claim(source string) error

Claim marks stdin as consumed by the named source (e.g. "--text @-"). Returns an error if stdin was already claimed.

func (*StdinGuard) Claimed

func (g *StdinGuard) Claimed() bool

Claimed reports whether stdin has been consumed.

type ToolDescriptor added in v1.0.48

type ToolDescriptor struct {
	RPCName       string `json:"rpc_name"`
	CanonicalPath string `json:"canonical_path"`
}

ToolDescriptor represents a single tool in a canonical product.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL