sdk

package
v1.0.0-beta.6 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: ISC Imports: 12 Imported by: 0

Documentation

Overview

Package sdk provides the plugin author interface and helpers for implementing preflight plugins as standalone executables speaking JSON-RPC over stdin/stdout.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Serve

func Serve(m Module)

Serve runs the JSON-RPC loop for the given module. Call this from your plugin's main().

Types

type ApplyResult

type ApplyResult struct {
	Message string         `json:"message,omitempty"`
	State   map[string]any `json:"state,omitempty"`
	Error   string         `json:"error,omitempty"`
}

ApplyResult is returned by a module's Apply method.

type CheckResult

type CheckResult struct {
	// NeedsChange must be true if the system is NOT yet in the desired state
	// (i.e., Apply should be called). Return false when the system is already
	// in the desired state and no action is required.
	NeedsChange bool           `json:"needs_change"`
	Message     string         `json:"message,omitempty"`
	State       map[string]any `json:"state,omitempty"`
	Error       string         `json:"error,omitempty"`
}

CheckResult is returned by a module's Check method.

type Client

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

Client is the runner-side handle for a running plugin process.

func NewClient

func NewClient(executablePath string) (*Client, error)

NewClient starts the plugin at executablePath, sends an "initialize" request, and returns a ready-to-use Client.

func NewClientContext

func NewClientContext(ctx context.Context, executablePath string) (*Client, error)

NewClientContext starts the plugin with a context, sends an "initialize" request, and returns a ready-to-use Client.

func NewClientFromCmd

func NewClientFromCmd(cmd *exec.Cmd) (*Client, error)

NewClientFromCmd starts the given command and connects a Client to its stdin/stdout for JSON-RPC communication. The command must not have been started yet. The caller must call Close() when done.

func (*Client) Apply

func (c *Client) Apply(args map[string]any) (ApplyResult, error)

Apply calls the plugin's apply method.

func (*Client) ApplyStreaming

func (c *Client) ApplyStreaming(args map[string]any, out OutputFunc) (ApplyResult, error)

ApplyStreaming calls the plugin's apply method and dispatches output lines to out.

func (*Client) Check

func (c *Client) Check(args map[string]any) (CheckResult, error)

Check calls the plugin's check method.

func (*Client) CheckStreaming

func (c *Client) CheckStreaming(args map[string]any, out OutputFunc) (CheckResult, error)

CheckStreaming calls the plugin's check method and dispatches output lines to out.

func (*Client) Close

func (c *Client) Close() error

Close terminates the plugin process.

func (*Client) Name

func (c *Client) Name() string

Name returns the plugin's self-reported name.

func (*Client) Version

func (c *Client) Version() string

Version returns the plugin's self-reported version.

type DiscoveredPlugin

type DiscoveredPlugin struct {
	Name   string
	Path   string
	Source string
}

DiscoveredPlugin is one plugin executable found during scanning.

func Scan

func Scan(opts DiscoveryOptions) ([]DiscoveredPlugin, error)

Scan returns every matching plugin executable in scan order. PreferredDirs are searched before the default binary/home/cwd directories.

type DiscoveryOptions

type DiscoveryOptions struct {
	BinaryDir           string
	WorkingDir          string
	PreferredDirs       []string
	DisableFallbackDirs bool
}

DiscoveryOptions controls plugin scan order.

type Module

type Module interface {
	// Name returns the module's canonical name (e.g. "my-module").
	Name() string
	// Version returns the module's semantic version.
	Version() string
	// Check reports whether the system is already in the desired state.
	// NeedsChange must be true if the system is NOT yet in the desired state
	// (i.e., Apply should be called). Return false when no change is required.
	Check(args map[string]any) (CheckResult, error)
	// Apply brings the system into the desired state.
	Apply(args map[string]any) (ApplyResult, error)
}

Module is the interface plugin authors implement.

type OutputFunc

type OutputFunc func(line string)

OutputFunc is called for each line of streaming output emitted during Check or Apply.

type PluginStatus

type PluginStatus struct {
	Name         string
	Path         string
	Source       string
	Version      string
	Initialized  bool
	ErrorMessage string
}

PluginStatus describes a discovered plugin plus initialization status.

func Inspect

func Inspect(opts DiscoveryOptions) ([]PluginStatus, error)

Inspect initializes each discovered plugin and returns its reported version or the initialization failure.

func InspectPlugin

func InspectPlugin(path, source string) PluginStatus

InspectPlugin initializes a single plugin executable and returns its status.

type StreamingModule

type StreamingModule interface {
	Module
	CheckStreaming(args map[string]any, out OutputFunc) (CheckResult, error)
	ApplyStreaming(args map[string]any, out OutputFunc) (ApplyResult, error)
}

StreamingModule is an optional upgrade for plugins that can emit output during Check or Apply. The host detects support via interface assertion.

Jump to

Keyboard shortcuts

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