inspect

package
v0.38.0 Latest Latest
Warning

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

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

Documentation

Overview

Package inspect provides business logic for inspecting and explaining solutions. This package is the shared domain layer used by CLI, MCP, and future API consumers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendResolverHints added in v0.6.0

func AppendResolverHints(suggestions *[]string, cause error, resolverName string, sol *solution.Solution)

AppendResolverHints inspects an error cause and adds provider-specific hints to the suggestions slice. This is exported so callers can build custom diagnostic flows while reusing the hint logic.

func LoadSolution

func LoadSolution(ctx context.Context, path string) (*solution.Solution, error)

LoadSolution loads a solution from a path using the standard loader with catalog resolution. This function is reusable by CLI, MCP, and future API.

func LookupProvider

func LookupProvider(ctx context.Context, name string, reg *provider.Registry) (*provider.Descriptor, error)

LookupProvider looks up a provider by name and returns its descriptor. This is a standalone function reusable by CLI, MCP, and future API.

Types

type ActionInfo

type ActionInfo struct {
	Name        string              `json:"name" yaml:"name" doc:"Action name" maxLength:"256" example:"deploy"`
	Provider    string              `json:"provider" yaml:"provider" doc:"Provider used by this action" maxLength:"128" example:"shell"`
	DependsOn   []string            `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty" doc:"Action dependencies" maxItems:"100"`
	Conditional bool                `json:"conditional,omitempty" yaml:"conditional,omitempty" doc:"Whether action has a when condition"`
	HasRetry    bool                `json:"hasRetry,omitempty" yaml:"hasRetry,omitempty" doc:"Whether retry is configured"`
	HasForEach  bool                `json:"hasForEach,omitempty" yaml:"hasForEach,omitempty" doc:"Whether forEach is configured"`
	SourcePos   *sourcepos.Position `json:"sourcePos,omitempty" yaml:"sourcePos,omitempty" doc:"Source file location"`
}

ActionInfo holds structured information about an action.

type ActionUsage added in v0.34.0

type ActionUsage struct {
	Name        string `json:"name" yaml:"name" doc:"Action name" maxLength:"150"`
	Description string `json:"description,omitempty" yaml:"description,omitempty" doc:"What the action does" maxLength:"512"`
	Default     bool   `json:"default,omitempty" yaml:"default,omitempty" doc:"Runs on a bare invocation (not explicit, not gated by a when clause)"`
	Command     string `json:"command" yaml:"command" doc:"CLI command to run this action" maxLength:"2048"`
}

ActionUsage describes a runnable action and the command to invoke it.

type CatalogInfo

type CatalogInfo struct {
	Visibility string `json:"visibility,omitempty" yaml:"visibility,omitempty" doc:"Catalog visibility level" maxLength:"32" example:"public"`
	Beta       bool   `json:"beta,omitempty" yaml:"beta,omitempty" doc:"Whether the solution is in beta"`
	Disabled   bool   `json:"disabled,omitempty" yaml:"disabled,omitempty" doc:"Whether the solution is disabled"`
}

CatalogInfo holds catalog metadata.

type ExecutionDiagnostic added in v0.6.0

type ExecutionDiagnostic struct {
	// Details is the human-readable description of the error.
	Details string `json:"details" yaml:"details" doc:"Detailed error description" maxLength:"4096" example:"2 resolver(s) failed, 1 succeeded"`

	// Suggestions are actionable steps to fix the error.
	Suggestions []string `json:"suggestions" yaml:"suggestions" doc:"Actionable fix suggestions" maxItems:"20"`
}

ExecutionDiagnostic holds a structured diagnosis of a resolver execution error. This is the domain-level representation that can be used by CLI, MCP, and future API consumers to build user-facing error messages.

func DiagnoseExecutionError added in v0.6.0

func DiagnoseExecutionError(err error, sol *solution.Solution) *ExecutionDiagnostic

DiagnoseExecutionError converts a resolver execution error into a structured diagnostic with typed analysis and actionable suggestions. The solution is used to inspect resolver configurations for provider-specific hints.

type FileDependencyInfo added in v0.6.0

type FileDependencyInfo struct {
	Path   string `json:"path" yaml:"path" doc:"Relative file path" maxLength:"512" example:"templates/main.tf"`
	Source string `` /* 158-byte string literal not displayed */
}

FileDependencyInfo describes a file dependency discovered via static analysis.

type LinkInfo

type LinkInfo struct {
	Name string `json:"name" yaml:"name" doc:"Link display name" maxLength:"128" example:"Documentation"`
	URL  string `json:"url" yaml:"url" doc:"Link URL" maxLength:"1024" example:"https://example.com/docs"`
}

LinkInfo holds a named link.

type MaintainerInfo

type MaintainerInfo struct {
	Name  string `json:"name" yaml:"name" doc:"Maintainer name" maxLength:"128" example:"Jane Doe"`
	Email string `json:"email,omitempty" yaml:"email,omitempty" doc:"Maintainer email" maxLength:"256" example:"jane@example.com"`
}

MaintainerInfo holds maintainer contact info.

type ParamInfo added in v0.6.0

type ParamInfo struct {
	// Name is the CLI flag name used to supply this parameter (the parameter
	// provider's `inputs.key`, or the first of `inputs.keys`). This is what the
	// user passes via `-r <name>=value`. It may differ from the resolver's name.
	Name string `json:"name" yaml:"name" doc:"Parameter name (CLI flag key)" maxLength:"256" example:"projectName"`

	// ResolverName is the resolver's map-key name in spec.resolvers. CEL
	// when-clauses reference the resolver by this name (e.g. `_.<resolverName>`),
	// which is not necessarily the CLI key.
	ResolverName string `` /* 138-byte string literal not displayed */

	Type        string `json:"type,omitempty" yaml:"type,omitempty" doc:"Parameter type" maxLength:"64" example:"string"`
	Description string `` /* 141-byte string literal not displayed */
	Example     any    `json:"example,omitempty" yaml:"example,omitempty" doc:"Example value"`

	// Default is the literal default value declared on the parameter provider
	// (its "default" input), when present.
	Default any `json:"default,omitempty" yaml:"default,omitempty" doc:"Default value when the parameter is not supplied"`

	// Required is true when the parameter has no default value and must be
	// supplied by the user.
	Required bool `json:"required,omitempty" yaml:"required,omitempty" doc:"Whether the parameter must be supplied"`
}

ParamInfo describes a parameter-type resolver that requires a user-provided value.

type ParamUsage added in v0.34.0

type ParamUsage struct {
	Name          string `json:"name" yaml:"name" doc:"Parameter name" maxLength:"256"`
	Type          string `json:"type,omitempty" yaml:"type,omitempty" doc:"Parameter type" maxLength:"64"`
	Description   string `json:"description,omitempty" yaml:"description,omitempty" doc:"Parameter description" maxLength:"512"`
	Example       any    `json:"example,omitempty" yaml:"example,omitempty" doc:"Example value for the parameter"`
	Default       any    `json:"default,omitempty" yaml:"default,omitempty" doc:"Default value when omitted"`
	Required      bool   `json:"required,omitempty" yaml:"required,omitempty" doc:"Whether the parameter must be supplied"`
	AllowedValues []any  `json:"allowedValues,omitempty" yaml:"allowedValues,omitempty" doc:"Discovered allowed values (best-effort)" maxItems:"100"`
}

ParamUsage describes a single user-supplied parameter in the usage view.

type ResolverInfo

type ResolverInfo struct {
	Name        string              `json:"name" yaml:"name" doc:"Resolver name" maxLength:"256" example:"api-data"`
	Providers   []string            `json:"providers,omitempty" yaml:"providers,omitempty" doc:"Provider names used" maxItems:"20"`
	DependsOn   []string            `json:"dependsOn,omitempty" yaml:"dependsOn,omitempty" doc:"Resolver dependencies" maxItems:"100"`
	Conditional bool                `json:"conditional,omitempty" yaml:"conditional,omitempty" doc:"Whether resolver has a when condition"`
	Phases      []string            `json:"phases,omitempty" yaml:"phases,omitempty" doc:"Configured phases (resolve, transform, validate)" maxItems:"3"`
	SourcePos   *sourcepos.Position `json:"sourcePos,omitempty" yaml:"sourcePos,omitempty" doc:"Source file location"`
}

ResolverInfo holds structured information about a resolver.

type RunCommandInfo added in v0.6.0

type RunCommandInfo struct {
	// Command is the full CLI command string with all flags.
	Command string `` /* 156-byte string literal not displayed */

	// Subcommand is the base command (e.g., "scafctl run solution").
	Subcommand string `json:"subcommand" yaml:"subcommand" doc:"Base CLI subcommand" maxLength:"128" example:"scafctl run solution"`

	// BaseCommand is the subcommand plus the resolved solution source
	// (e.g. "scafctl run solution -f ./my-solution.yaml"), without any example
	// parameter flags. Append parameter flags to this to build a runnable command
	// that targets the correct solution rather than relying on cwd auto-discovery.
	BaseCommand string `` /* 183-byte string literal not displayed */

	// Explanation describes why this command variant was chosen.
	Explanation string `` /* 142-byte string literal not displayed */

	// Parameters lists the parameter-type resolvers that need values.
	Parameters []ParamInfo `json:"parameters" yaml:"parameters" doc:"Parameter-type resolvers requiring values" maxItems:"100"`

	// HasWorkflow indicates whether the solution has a workflow.
	HasWorkflow bool `json:"hasWorkflow" yaml:"hasWorkflow" doc:"Whether the solution has a workflow"`

	// HasResolvers indicates whether the solution has resolvers.
	HasResolvers bool `json:"hasResolvers" yaml:"hasResolvers" doc:"Whether the solution has resolvers"`
}

RunCommandInfo holds the structured result of analyzing a solution to determine how to run it. This is the domain representation used by CLI, MCP, and future API consumers.

func BuildRunCommand added in v0.6.0

func BuildRunCommand(sol *solution.Solution, path, binaryName string) (*RunCommandInfo, error)

BuildRunCommand analyzes a solution and returns the exact CLI command to run it, including any parameter-type resolvers that need values passed via -r flags. The binaryName parameter is used in the generated command (e.g., "scafctl" or a custom name when scafctl is embedded as a library). Returns nil and an error message if the solution has nothing to run.

type SolutionExplanation

type SolutionExplanation struct {
	Name        string `json:"name" yaml:"name" doc:"Solution name" maxLength:"256" example:"my-solution"`
	DisplayName string `` /* 129-byte string literal not displayed */
	Version     string `json:"version" yaml:"version" doc:"Solution version" maxLength:"64" example:"1.0.0"`
	Description string `` /* 134-byte string literal not displayed */
	Category    string `json:"category,omitempty" yaml:"category,omitempty" doc:"Solution category" maxLength:"128" example:"infrastructure"`
	Path        string `json:"path,omitempty" yaml:"path,omitempty" doc:"Source file path" maxLength:"512" example:"./solution.yaml"`

	Catalog *CatalogInfo `json:"catalog,omitempty" yaml:"catalog,omitempty" doc:"Catalog visibility info"`

	Resolvers []ResolverInfo `json:"resolvers,omitempty" yaml:"resolvers,omitempty" doc:"Resolver configurations" maxItems:"1000"`
	Actions   []ActionInfo   `json:"actions,omitempty" yaml:"actions,omitempty" doc:"Action configurations" maxItems:"1000"`
	Finally   []ActionInfo   `json:"finally,omitempty" yaml:"finally,omitempty" doc:"Finally/cleanup actions" maxItems:"100"`

	Source      string            `json:"source,omitempty" yaml:"source,omitempty" doc:"Source repository URL" maxLength:"500"`
	Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty" doc:"Free-form key-value annotations"`

	State *StateInfo `json:"state,omitempty" yaml:"state,omitempty" doc:"State persistence configuration"`

	Tags        []string         `json:"tags,omitempty" yaml:"tags,omitempty" doc:"Solution tags" maxItems:"50"`
	Links       []LinkInfo       `json:"links,omitempty" yaml:"links,omitempty" doc:"Related links" maxItems:"50"`
	Maintainers []MaintainerInfo `json:"maintainers,omitempty" yaml:"maintainers,omitempty" doc:"Solution maintainers" maxItems:"20"`

	// FileDependencies lists files discovered through static analysis of provider inputs.
	FileDependencies []FileDependencyInfo `` /* 137-byte string literal not displayed */
}

SolutionExplanation holds structured explanation data for a solution. This can be serialized to JSON/YAML or formatted for terminal output.

func BuildSolutionExplanation

func BuildSolutionExplanation(sol *solution.Solution) *SolutionExplanation

BuildSolutionExplanation builds a structured explanation from a loaded solution. This returns data that can be serialized (JSON/YAML) or formatted for display.

type StateInfo added in v0.18.0

type StateInfo struct {
	Enabled      bool     `json:"enabled" yaml:"enabled" doc:"Whether state persistence is configured"`
	Provider     string   `json:"provider" yaml:"provider" doc:"Backend provider name" maxLength:"253" example:"file"`
	InputKeys    []string `json:"inputKeys,omitempty" yaml:"inputKeys,omitempty" doc:"Configured backend input keys" maxItems:"50"`
	OverrideKeys []string `json:"overrideKeys,omitempty" yaml:"overrideKeys,omitempty" doc:"Configured saveOverrides keys" maxItems:"50"`
}

StateInfo holds structured information about state persistence configuration.

type UsageInfo added in v0.34.0

type UsageInfo struct {
	Name        string              `json:"name" yaml:"name" doc:"Solution name" maxLength:"256"`
	DisplayName string              `json:"displayName,omitempty" yaml:"displayName,omitempty" doc:"Human-readable display name" maxLength:"256"`
	Version     string              `json:"version,omitempty" yaml:"version,omitempty" doc:"Solution version" maxLength:"64"`
	Synopsis    string              `json:"synopsis,omitempty" yaml:"synopsis,omitempty" doc:"How to consume this solution" maxLength:"5000"`
	Details     string              `` /* 140-byte string literal not displayed */
	Source      string              `json:"source,omitempty" yaml:"source,omitempty" doc:"Resolved solution path" maxLength:"1024"`
	Run         string              `json:"run,omitempty" yaml:"run,omitempty" doc:"Base command to run the solution" maxLength:"2048"`
	Tags        []string            `json:"tags,omitempty" yaml:"tags,omitempty" doc:"Searchable tags" maxItems:"100"`
	Links       []LinkInfo          `json:"links,omitempty" yaml:"links,omitempty" doc:"Related documentation and resources" maxItems:"10"`
	Params      []ParamUsage        `json:"parameters,omitempty" yaml:"parameters,omitempty" doc:"User-supplied parameters" maxItems:"100"`
	Actions     []ActionUsage       `json:"actions,omitempty" yaml:"actions,omitempty" doc:"Runnable actions with commands" maxItems:"200"`
	Examples    []spec.UsageExample `json:"examples,omitempty" yaml:"examples,omitempty" doc:"Curated usage examples" maxItems:"50"`
}

UsageInfo is the user-facing "how do I consume this solution" view. It is a projection over a solution's metadata, parameters, and actions, rendered via the kvx pipeline (table/json/yaml/tui).

func BuildUsage added in v0.34.0

func BuildUsage(ctx context.Context, sol *solution.Solution, path, binaryName string) (*UsageInfo, error)

BuildUsage assembles the user-facing usage view for a solution. It never fails on best-effort discovery (allowed-value inference); it returns an error only when the solution cannot be run at all (no resolvers and no workflow).

binaryName is used to generate embedder-safe commands; it falls back to the default CLI binary name when empty.

Jump to

Keyboard shortcuts

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