plugins

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 22 Imported by: 0 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 plugins runs the hub's plugins and calls their tools. It implements hub.ToolHost.

Every plugin is a separate executable speaking MCP over stdio (docs/PLUGINS.md). The host starts each one with a minimal environment and its own data directory, keeps its stderr as the plugin log, lists its tools, restarts it with backoff when it crashes, and stops it with SIGTERM, then SIGKILL.

The tool snapshot keeps a plugin's last known tools while the plugin is restarting or failing, so a crash does not make tools vanish from assistants; calling them returns hub.ErrPluginDown until the plugin is back.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownPlugin = errors.New("unknown plugin")

ErrUnknownPlugin means no plugin with that id is in the host.

Functions

func WithProgress

func WithProgress(ctx context.Context, fn func(Progress)) context.Context

WithProgress returns a context that makes Host.Call ask the plugin for progress reports and hand each one to fn. fn runs on the plugin session's notification goroutine, one report at a time and in order: it must return quickly. It is never called after Call has returned, so reports that arrive with or after the result are dropped.

Types

type Host

type Host struct {
	// HubVersion goes to plugins as HOMIE_HUB_VERSION and as the MCP clientInfo version. Set it before Start.
	HubVersion string
	// contains filtered or unexported fields
}

Host runs plugins and implements hub.ToolHost.

func New

func New(specs []Spec, dataDir string, log *slog.Logger) (*Host, error)

New validates the specs and prepares the data directories. Plugins start with Start.

func (*Host) Add

func (h *Host) Add(s Spec) error

Add adds a plugin and, when the host has started, starts it. It fails for an invalid spec or an id in use.

func (*Host) Await

func (h *Host) Await(ctx context.Context, id string) error

Await waits until the plugin is up and returns nil. It returns an error as soon as a run since the plugin's last (re)start failed, when the plugin is not in the host (ErrUnknownPlugin), or when ctx ends. The installer uses it to tell whether a new version came up.

func (*Host) Call

func (h *Host) Call(ctx context.Context, caller hub.Caller, name string, args json.RawMessage) (hub.Result, error)

Call runs a tool. See hub.ToolHost. A context from WithProgress also receives the plugin's progress reports.

func (*Host) Changed

func (h *Host) Changed() <-chan struct{}

Changed returns a channel that is closed at the next change of the tool set or of the plugins' instructions.

func (*Host) Close

func (h *Host) Close()

Close stops every plugin (closing the session, then SIGTERM, then SIGKILL after 5 s) and waits for them.

func (*Host) Instructions

func (h *Host) Instructions() string

Instructions returns the instructions of every plugin that has any, in plugin id order, separated by blank lines. The gateway appends them to the hub preamble. A change fires Changed.

func (*Host) Logs

func (h *Host) Logs(id string) []string

Logs returns the last lines (at most 1000) a plugin wrote to stderr, oldest first, with the host's own events prefixed by "homie:". It returns nil for an unknown id.

func (*Host) PluginInstructions

func (h *Host) PluginInstructions(id string) string

PluginInstructions returns the instructions the plugin sent at initialize; "" for an unknown id. The admin shows them on the plugin's page.

func (*Host) Remove

func (h *Host) Remove(id string) error

Remove stops a plugin, waits until its process has exited and forgets it with its tools. Its data dir and log file stay. ErrUnknownPlugin when no such plugin is in the host.

func (*Host) Restart

func (h *Host) Restart(id string) error

Restart stops a plugin and starts it again. Its last known tools stay listed meanwhile, as after a crash. ErrUnknownPlugin when no such plugin is in the host.

func (*Host) Start

func (h *Host) Start(ctx context.Context)

Start launches every plugin. Plugins stop when ctx is done or Close is called. Start does nothing after the first call or after Close.

func (*Host) Status

func (h *Host) Status() []hub.PluginStatus

Status reports every plugin, sorted by id.

func (*Host) Sync

func (h *Host) Sync(specs []Spec) error

Sync makes the host's plugins match specs: plugins missing from specs are stopped and forgotten, new ones are added (and started once the host has), and those whose command changed are restarted with the new command. Plugins that did not change keep running. Invalid specs fail the whole call before anything changes.

func (*Host) Tools

func (h *Host) Tools(audience hub.Audience) []hub.Tool

Tools returns a snapshot of the tools visible to the audience, sorted by name.

type Progress

type Progress struct {
	Progress float64           // grows with every report
	Total    float64           // 0 when unknown
	Message  string            // short English text for a person; optional
	I18n     map[string]string // Message translated, by language ("ru"); optional
}

Progress is one progress report of a running tool call (MCP notifications/progress).

type Spec

type Spec struct {
	ID      string   // plugin id, ^[a-z][a-z0-9]{1,15}$
	Command []string // executable and arguments, e.g. ["/path/homie-tv", "serve"]
}

Spec says how to run one plugin.

Jump to

Keyboard shortcuts

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