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 ¶
- Variables
- func WithProgress(ctx context.Context, fn func(Progress)) context.Context
- type Host
- func (h *Host) Add(s Spec) error
- func (h *Host) Await(ctx context.Context, id string) error
- func (h *Host) Call(ctx context.Context, caller hub.Caller, name string, args json.RawMessage) (hub.Result, error)
- func (h *Host) Changed() <-chan struct{}
- func (h *Host) Close()
- func (h *Host) Instructions() string
- func (h *Host) Logs(id string) []string
- func (h *Host) PluginInstructions(id string) string
- func (h *Host) Remove(id string) error
- func (h *Host) Restart(id string) error
- func (h *Host) Start(ctx context.Context)
- func (h *Host) Status() []hub.PluginStatus
- func (h *Host) Sync(specs []Spec) error
- func (h *Host) Tools(audience hub.Audience) []hub.Tool
- type Progress
- type Spec
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownPlugin = errors.New("unknown plugin")
ErrUnknownPlugin means no plugin with that id is in the host.
Functions ¶
func WithProgress ¶
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 (*Host) Add ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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).