Documentation
¶
Overview ¶
Package pluginapi defines the experimental external plugin bundle contract. It has no dependency on the desktop UI or mtools' internal packages. The runtime protocol is experimental; the surface schema is not frozen yet.
Index ¶
- Constants
- Variables
- func CompareVersions(a, b string) (int, error)
- func DecodePayload(data []byte, dst any) error
- func Serve(ctx context.Context, input io.ReadCloser, output io.Writer, ...) error
- func ValidBundlePath(name string) bool
- func ValidJobID(id string) bool
- func ValidPluginID(id PluginID) bool
- func WriteMessage(w io.Writer, m Message) error
- type CancelParams
- type Capability
- type Entry
- type FileInfo
- type HelperStatus
- type InitializeParams
- type InitializeResult
- type InputError
- type InspectFieldUpdate
- type InspectParams
- type InspectResult
- type Inspector
- type InspectorFunc
- type Manifest
- type Message
- type PluginID
- type Progress
- type Publisher
- type RPCError
- type RunParams
- type RunResult
- type Runner
- type RunnerFunc
- type SurfaceAction
- type SurfaceDocument
- type SurfaceField
- type SurfaceFieldAction
- type SurfaceHelper
- type SurfaceMode
- type SurfaceOption
- type Tool
- type ToolID
- type ToolSurface
Constants ¶
const ( SchemaVersion = 1 Protocol = "jsonrpc-stdio-v1" MaxManifestBytes = 256 << 10 MaxFiles = 2048 MaxFileBytes = 128 << 20 MaxExpandedBytes = 512 << 20 MaxArchiveBytes = 256 << 20 )
const ( MaxMessageBytes = 1 << 20 // includes the terminating LF MethodInitialize = "initialize" MethodInspect = "inspect" MethodRun = "run" MethodProgress = "progress" MethodCancel = "cancel" )
const ( SurfaceFile = "surfaces.json" MaxSurfaceBytes = 64 << 10 )
Variables ¶
var ( ErrManifest = errors.New("invalid plugin manifest") ErrCompatibility = errors.New("incompatible plugin") )
var ErrProtocol = errors.New("invalid plugin protocol")
var ErrSurface = errors.New("invalid plugin surface")
Functions ¶
func CompareVersions ¶
CompareVersions compares release versions. Prerelease/build suffixes are not supported in schema 1, so version order has no channel-dependent ambiguity.
func DecodePayload ¶
DecodePayload applies the same strict JSON rules to a typed wire payload. Callers must then validate semantic bounds and job/manifest identity.
func Serve ¶
func Serve(ctx context.Context, input io.ReadCloser, output io.Writer, identity InitializeResult, runner Runner) error
Serve is the optional Go sidecar SDK, independent of the desktop host. It owns and closes input so cancellation can interrupt a blocked read. output must be protocol-only and must not block forever (the host closes it on termination). Any diagnostics belong on stderr, never output.
func ValidBundlePath ¶
ValidBundlePath accepts only portable, slash-separated regular file paths. Reject aliases on case-insensitive/Windows filesystems before extraction.
func ValidJobID ¶
func ValidPluginID ¶
Types ¶
type CancelParams ¶
type CancelParams struct {
JobID string `json:"job_id"`
}
type Capability ¶
type Capability string
const ( FilesRead Capability = "files.read" FilesWrite Capability = "files.write" Network Capability = "network" Process Capability = "process" Clipboard Capability = "clipboard" )
type HelperStatus ¶
type InitializeParams ¶
type InitializeParams struct {
Protocol string `json:"protocol"`
PluginID PluginID `json:"plugin_id"`
Version string `json:"version"`
}
func (InitializeParams) Validate ¶
func (p InitializeParams) Validate() error
type InitializeResult ¶
type InitializeResult = InitializeParams
type InputError ¶
type InputError struct{ Field string }
InputError identifies a field without retaining or exposing its value.
func (*InputError) Error ¶
func (e *InputError) Error() string
type InspectFieldUpdate ¶
type InspectFieldUpdate struct {
Options []SurfaceOption `json:"options,omitempty"`
Value string `json:"value,omitempty"`
Info string `json:"info,omitempty"`
}
type InspectParams ¶
type InspectParams struct {
Tool ToolID `json:"tool"`
Action string `json:"action,omitempty"`
Inputs map[string][]string `json:"inputs"`
Settings map[string]string `json:"settings,omitempty"`
}
func (InspectParams) Validate ¶
func (p InspectParams) Validate() error
type InspectResult ¶
type InspectResult struct {
Fields map[string]InspectFieldUpdate `json:"fields,omitempty"`
Metadata map[string]string `json:"metadata,omitempty"`
CommandPreview string `json:"command_preview,omitempty"`
HelperStatus map[string]HelperStatus `json:"helper_status,omitempty"`
}
func (InspectResult) Validate ¶
func (r InspectResult) Validate() error
type Inspector ¶
type Inspector interface {
Inspect(context.Context, InspectParams) (InspectResult, error)
}
Inspector is an optional interface a Runner may implement to support dynamic schema inspection, previews, and helper binary checks.
type InspectorFunc ¶
type InspectorFunc func(context.Context, InspectParams) (InspectResult, error)
func (InspectorFunc) Inspect ¶
func (f InspectorFunc) Inspect(ctx context.Context, p InspectParams) (InspectResult, error)
type Manifest ¶
type Manifest struct {
Schema int `json:"schema"`
ID PluginID `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Platform string `json:"platform"`
Publisher Publisher `json:"publisher"`
Capabilities []Capability `json:"capabilities"`
Entry Entry `json:"entry"`
Tools []Tool `json:"tools"`
Files map[string]FileInfo `json:"files"`
}
Manifest is signed as exact UTF-8 JSON bytes, not re-encoded JSON. Files inventories every ZIP payload except manifest.json and SIGNATURE.
func DecodeManifest ¶
DecodeManifest rejects unknown and duplicate members, trailing JSON, excessive nesting, invalid UTF-8, and metadata beyond the schema's bounds.
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID uint64 `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
Message is a deliberately small JSON-RPC 2.0 subset. IDs are positive integers; notifications omit ID. Batches, reverse requests and arbitrary error data are not supported. Stdout carries only LF-terminated messages.
func DecodeMessage ¶
type Progress ¶
type Publisher ¶
type Publisher struct {
Name string `json:"name"`
PublicKey string `json:"public_key"` // standard padded base64, Ed25519
}
func (Publisher) Fingerprint ¶
Fingerprint identifies a key, not a verified real-world publisher identity.
type RunParams ¶
type RunResult ¶
type Runner ¶
Runner handles one action at a time. It must honor ctx and finish before returning. emit is safe from multiple goroutines, but must not be retained.
type RunnerFunc ¶
type SurfaceAction ¶
type SurfaceDocument ¶
type SurfaceDocument struct {
Schema int `json:"schema"`
Tools []ToolSurface `json:"tools"`
}
SurfaceDocument is a signed, static description, not executable UI code.
func DecodeSurfaces ¶
func DecodeSurfaces(data []byte, manifest Manifest) (SurfaceDocument, error)
func (SurfaceDocument) Validate ¶
func (d SurfaceDocument) Validate(m Manifest) error
type SurfaceField ¶
type SurfaceField struct {
ID string `json:"id"`
Kind string `json:"kind"` // text, choice, select, toggle, files, directory; settings also allow file
Label string `json:"label"`
Required bool `json:"required"`
Default string `json:"default"`
Options []SurfaceOption `json:"options,omitempty"`
Dynamic bool `json:"dynamic,omitempty"`
// Description, Placeholder and Action are only meaningful for settings.
Description string `json:"description,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
Action *SurfaceFieldAction `json:"action,omitempty"`
}
type SurfaceFieldAction ¶
type SurfaceFieldAction struct {
ID string `json:"id"`
Label string `json:"label"`
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
}
SurfaceFieldAction attaches one button to a setting. It either opens an https URL through the host, or runs a declared tool action whose first output becomes the setting's value. It never carries executable UI code.
type SurfaceHelper ¶
type SurfaceMode ¶
type SurfaceOption ¶
type ToolSurface ¶
type ToolSurface struct {
ID ToolID `json:"id"`
Modes []SurfaceMode `json:"modes,omitempty"`
Fields []SurfaceField `json:"fields"`
Actions []SurfaceAction `json:"actions"`
Helpers []SurfaceHelper `json:"helpers,omitempty"`
Settings []SurfaceField `json:"settings,omitempty"`
}