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 ¶
- func Discover(binaryDir string) (map[string]string, error)
- func Serve(m Module)
- type ApplyResult
- type CheckResult
- type Client
- func (c *Client) Apply(args map[string]any) (ApplyResult, error)
- func (c *Client) ApplyStreaming(args map[string]any, out OutputFunc) (ApplyResult, error)
- func (c *Client) Check(args map[string]any) (CheckResult, error)
- func (c *Client) CheckStreaming(args map[string]any, out OutputFunc) (CheckResult, error)
- func (c *Client) Close() error
- func (c *Client) Name() string
- func (c *Client) Version() string
- type DiscoveredPlugin
- type DiscoveryOptions
- type Module
- type OutputFunc
- type PluginStatus
- type StreamingModule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Discover ¶
Discover scans well-known directories for preflight plugins and returns a map of plugin name → absolute executable path.
Scan order (first match wins):
- binaryDir — directory alongside the preflight binary
- ~/.preflight/plugins/
- ./plugins/ — relative to the current working directory
On Windows, executables must have the ".exe" suffix. On all other platforms, executables have no required suffix.
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 ¶
NewClient starts the plugin at executablePath, sends an "initialize" request, and returns a ready-to-use Client.
func NewClientContext ¶
NewClientContext starts the plugin with a context, sends an "initialize" request, and returns a ready-to-use Client.
func NewClientFromCmd ¶
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.
type DiscoveredPlugin ¶
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.