pluginapi

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 22 Imported by: 4 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	SchemaVersion    = 1
	Protocol         = "jsonrpc-stdio-v1"
	MaxManifestBytes = 256 << 10
	MaxFiles         = 2048
	MaxFileBytes     = 128 << 20
	MaxExpandedBytes = 512 << 20
	MaxArchiveBytes  = 256 << 20
)
View Source
const (
	MaxMessageBytes  = 1 << 20 // includes the terminating LF
	MethodInitialize = "initialize"
	MethodInspect    = "inspect"
	MethodRun        = "run"
	MethodProgress   = "progress"
	MethodCancel     = "cancel"
)
View Source
const (
	SurfaceFile     = "surfaces.json"
	MaxSurfaceBytes = 64 << 10
)

Variables

View Source
var (
	ErrManifest      = errors.New("invalid plugin manifest")
	ErrCompatibility = errors.New("incompatible plugin")
)
View Source
var ErrProtocol = errors.New("invalid plugin protocol")
View Source
var ErrSurface = errors.New("invalid plugin surface")

Functions

func CompareVersions

func CompareVersions(a, b string) (int, error)

CompareVersions compares release versions. Prerelease/build suffixes are not supported in schema 1, so version order has no channel-dependent ambiguity.

func DecodePayload

func DecodePayload(data []byte, dst any) error

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

func ValidBundlePath(name string) bool

ValidBundlePath accepts only portable, slash-separated regular file paths. Reject aliases on case-insensitive/Windows filesystems before extraction.

func ValidJobID

func ValidJobID(id string) bool

func ValidPluginID

func ValidPluginID(id PluginID) bool

func WriteMessage

func WriteMessage(w io.Writer, m Message) error

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 Entry

type Entry struct {
	Kind     string `json:"kind"`
	Path     string `json:"path"`
	Protocol string `json:"protocol"`
}

type FileInfo

type FileInfo struct {
	SHA256     string `json:"sha256"` // lowercase hex
	Size       int64  `json:"size"`
	Executable bool   `json:"executable"`
}

type HelperStatus

type HelperStatus struct {
	Found   bool   `json:"found"`
	Needed  bool   `json:"needed,omitempty"`
	Path    string `json:"path,omitempty"`
	Version string `json:"version,omitempty"`
	Message string `json:"message,omitempty"`
}

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 InspectPreview added in v0.1.2

type InspectPreview struct {
	Title        string   `json:"title"`
	Subtitle     string   `json:"subtitle,omitempty"`
	Meta         []string `json:"meta,omitempty"`
	ThumbnailURL string   `json:"thumbnail_url,omitempty"`
	Dismissible  bool     `json:"dismissible,omitempty"`
}

type InspectResult

type InspectResult struct {
	Fields         map[string]InspectFieldUpdate `json:"fields,omitempty"`
	Metadata       map[string]string             `json:"metadata,omitempty"`
	Preview        *InspectPreview               `json:"preview,omitempty"`
	IsPlaylist     bool                          `json:"is_playlist,omitempty"`
	CommandPreview string                        `json:"command_preview,omitempty"`
	HelperStatus   map[string]HelperStatus       `json:"helper_status,omitempty"`
	Logs           []string                      `json:"logs,omitempty"`
	Error          string                        `json:"error,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

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

func DecodeManifest(data []byte) (Manifest, error)

DecodeManifest rejects unknown and duplicate members, trailing JSON, excessive nesting, invalid UTF-8, and metadata beyond the schema's bounds.

func (Manifest) Validate

func (m Manifest) Validate() error

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

func DecodeMessage(data []byte) (Message, error)

func ReadMessage

func ReadMessage(r *bufio.Reader) (Message, error)

ReadMessage requires the LF delimiter even at EOF, and bounds allocation before decoding. The caller owns the reader and its cancellation mechanism.

type PluginID

type PluginID string

type Progress

type Progress struct {
	JobID   string  `json:"job_id"`
	Done    float64 `json:"done"`
	Total   float64 `json:"total"`
	Unit    string  `json:"unit"`
	Message string  `json:"message"`
	LogLine string  `json:"log_line,omitempty"`
}

func (Progress) Validate

func (p Progress) Validate(jobID string) error

type Publisher

type Publisher struct {
	Name      string `json:"name"`
	PublicKey string `json:"public_key"` // standard padded base64, Ed25519
}

func (Publisher) Fingerprint

func (p Publisher) Fingerprint() (string, error)

Fingerprint identifies a key, not a verified real-world publisher identity.

func (Publisher) Key

func (p Publisher) Key() (ed25519.PublicKey, error)

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func (*RPCError) Error

func (e *RPCError) Error() string

Error deliberately omits plugin-supplied text: it may contain private inputs.

type RunParams

type RunParams struct {
	JobID    string              `json:"job_id"`
	Tool     ToolID              `json:"tool"`
	Action   string              `json:"action"`
	Inputs   map[string][]string `json:"inputs"`
	Settings map[string]string   `json:"settings"`
}

func (RunParams) Validate

func (p RunParams) Validate() error

type RunResult

type RunResult struct {
	JobID   string   `json:"job_id"`
	Outputs []string `json:"outputs"`
	Summary string   `json:"summary"`
}

func (RunResult) Validate

func (r RunResult) Validate(jobID string) error

type Runner

type Runner interface {
	Run(context.Context, RunParams, func(Progress) error) (RunResult, error)
}

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 RunnerFunc func(context.Context, RunParams, func(Progress) error) (RunResult, error)

func (RunnerFunc) Run

func (f RunnerFunc) Run(ctx context.Context, p RunParams, emit func(Progress) error) (RunResult, error)

type SurfaceAction

type SurfaceAction struct {
	ID     string   `json:"id"`
	Label  string   `json:"label"`
	Kind   string   `json:"kind,omitempty"` // "" or "run" (default), or "inspect"
	Inputs []string `json:"inputs"`
}

type SurfaceCondition added in v0.1.2

type SurfaceCondition struct {
	Field     string `json:"field"`
	Equals    string `json:"equals,omitempty"`
	NotEquals string `json:"not_equals,omitempty"`
}

SurfaceCondition declares when a field should be visible based on another field's value.

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, file, files, directory, checklist, chips
	Label       string            `json:"label"`
	Hint        string            `json:"hint,omitempty"`
	HideLabel   bool              `json:"hide_label,omitempty"`
	Required    bool              `json:"required"`
	Default     string            `json:"default"`
	Options     []SurfaceOption   `json:"options,omitempty"`
	Dynamic     bool              `json:"dynamic,omitempty"`
	Grow        bool              `json:"grow,omitempty"`
	Flex        int               `json:"flex,omitempty"`
	Style       string            `json:"style,omitempty"` // "" or "chip"
	VisibleWhen *SurfaceCondition `json:"visible_when,omitempty"`
	// Description, Placeholder and Action are only meaningful for settings (or text/file placeholders).
	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 SurfaceHelper struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	InstallURL  string `json:"install_url,omitempty"`
	Required    bool   `json:"required,omitempty"`
}

type SurfaceHistory added in v0.1.2

type SurfaceHistory struct {
	Disabled      bool                   `json:"disabled,omitempty"`
	Title         string                 `json:"title,omitempty"`
	EmptyTitle    string                 `json:"empty_title,omitempty"`
	EmptySubtitle string                 `json:"empty_subtitle,omitempty"`
	ShowHide      bool                   `json:"show_hide,omitempty"`
	HideClearAll  bool                   `json:"hide_clear_all,omitempty"`
	DefaultWidth  int                    `json:"default_width,omitempty"`
	Buttons       []SurfaceHistoryButton `json:"buttons,omitempty"`
}

SurfaceHistory configures the declarative history sidebar for a tool workspace.

type SurfaceHistoryButton added in v0.1.2

type SurfaceHistoryButton struct {
	ID     string `json:"id"`
	Label  string `json:"label"`
	Action string `json:"action,omitempty"`
	URL    string `json:"url,omitempty"`
}

SurfaceHistoryButton attaches a custom action button to the history sidebar header. It can trigger a declared tool action, reveal the output folder ("open_output_dir"), or open an https URL.

type SurfaceMode

type SurfaceMode struct {
	ID     string   `json:"id"`
	Label  string   `json:"label"`
	Fields []string `json:"fields"`
	Action string   `json:"action"`
}

type SurfaceOption

type SurfaceOption struct {
	Label string `json:"label"`
	Value string `json:"value"`
	Meta  string `json:"meta,omitempty"`
}

type SurfaceSection added in v0.1.2

type SurfaceSection struct {
	ID          string           `json:"id"`
	Label       string           `json:"label,omitempty"`
	Layout      string           `json:"layout"` // vertical, horizontal, wrap, grid, primary, tabs, collapsible, card, input_row
	Columns     int              `json:"columns,omitempty"`
	DefaultOpen bool             `json:"default_open,omitempty"`
	Fields      []string         `json:"fields,omitempty"`
	Actions     []string         `json:"actions,omitempty"`
	Groups      []SurfaceSection `json:"groups,omitempty"`
}

SurfaceSection groups fields and actions into a declarative layout.

type Tool

type Tool struct {
	ID          ToolID `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Category    string `json:"category"`
}

type ToolID

type ToolID string

type ToolSurface

type ToolSurface struct {
	ID       ToolID           `json:"id"`
	Modes    []SurfaceMode    `json:"modes,omitempty"`
	Sections []SurfaceSection `json:"sections,omitempty"`
	Fields   []SurfaceField   `json:"fields"`
	Actions  []SurfaceAction  `json:"actions"`
	Helpers  []SurfaceHelper  `json:"helpers,omitempty"`
	Settings []SurfaceField   `json:"settings,omitempty"`
	History  *SurfaceHistory  `json:"history,omitempty"`
}

func (ToolSurface) Inputs

func (t ToolSurface) Inputs(action string, values map[string][]string) (map[string][]string, error)

Inputs validates only the selected action's fields and copies their values. File existence/access is a worker boundary; this checks the portable wire shape.

Jump to

Keyboard shortcuts

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