Documentation
¶
Overview ¶
This file bridges the agent's event stream to subscribed plugins (US-017, #133). The agent loop emits agentcore.AgentEvent values; a plugin declares which event types it wants in its manifest. EventNotifier maps each observed event to a small, wire-safe payload and hands it to the Manager for fire-and-forget delivery — the same "never secrets, only observable fields" discipline the stream-json envelope uses.
This file implements plugin discovery and lifecycle management (US-016, #132): finding plugin executables under a config directory, loading each, and aggregating their tools. Loading is fault-tolerant — one plugin that fails to start or handshake is logged and skipped so the rest still load.
Package plugin implements golder's external plugin system (US-016, #132): an executable written in any language registers custom tools (and, later, slash commands) with golder without touching golder's source. golder launches each plugin as a child process and speaks line-delimited JSON-RPC 2.0 over its stdio, reusing internal/jsonrpc as the transport.
Protocol (client = golder, server = plugin):
- initialize → Manifest {name, version, tools[], commands[]} The handshake. The plugin declares everything it offers up front.
- tools/call {name, arguments} → CallResult {content, isError} golder forwards a tool invocation; the plugin runs it and returns the text.
- event {type, data} (notification) golder pushes a subscribed agent lifecycle event (US-017, #133). One-way, fire-and-forget: the plugin never replies and a slow plugin is isolated.
- shutdown (notification) Sent on Close so a well-behaved plugin can exit before stdin EOF.
A plugin that crashes or misbehaves is isolated: its Start failure is logged and skipped (other plugins still load), and a tool call against a dead plugin returns an error result rather than propagating up.
This file defines the wire types exchanged during the handshake and tool call.
This file implements the plugin client (US-016, #132): it launches a plugin executable, performs the initialize handshake, and exposes the plugin's declared tools as agentcore.AgentTool values that forward invocations over JSON-RPC. Crash isolation lives here — a call against a plugin whose process has died returns an error result, never a panic.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallParams ¶
type CallParams struct {
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments"`
}
CallParams is the parameter object for a tools/call request.
type CallResult ¶
CallResult is the reply to a tools/call request. Content is the tool output as text; IsError marks a tool-level failure (distinct from a transport error).
type CommandCallParams ¶
type CommandCallParams struct {
Name string `json:"name"`
Args json.RawMessage `json:"arguments"`
}
CommandCallParams is the parameter object for a commands/call request. It mirrors CallParams' naming (name/arguments) so a plugin can decode tool and command invocations with the same conventions. Name is the command's name; Args carries its free-form arguments (e.g. the text following the slash command) as raw JSON, passed through verbatim to the plugin.
type CommandCallResult ¶
type CommandCallResult struct {
Prompt string `json:"prompt,omitempty"`
Notifications []CommandNotification `json:"notifications,omitempty"`
}
CommandCallResult is the reply to a commands/call request. Prompt is the text injected as the next agent turn (matching the declarative-command convention); it may be empty if the command produces no prompt. Notifications are messages the plugin asks golder to surface to the user out of band from the prompt.
type CommandNotification ¶
type CommandNotification struct {
Message string `json:"message"`
Type string `json:"type,omitempty"`
}
CommandNotification is a single message a command asks golder to surface to the user. Message is the human-readable text; Type is an optional severity or category hint (e.g. "info", "warning", "error") that golder may use to style the message.
type CommandSpec ¶
type CommandSpec struct {
Name string `json:"name"`
Description string `json:"description"`
Prompt string `json:"prompt,omitempty"`
}
CommandSpec declares one slash command a plugin exposes. Prompt is the text injected as the next user prompt when the command is invoked (matching the declarative-command convention); it may be empty if the plugin handles the command by other means.
type EventNotifier ¶
type EventNotifier struct {
// contains filtered or unexported fields
}
EventNotifier forwards agent lifecycle events to the plugins that subscribed to them. It is created once per run and its Handle method is wired as the event-stream OnEvent callback. A nil *Manager (no plugins) makes NewNotifier return nil, and calling Handle on a nil notifier is a safe no-op — callers can wire it unconditionally.
func NewEventNotifier ¶
func NewEventNotifier(mgr *Manager, warnLog io.Writer) *EventNotifier
NewEventNotifier returns a notifier over mgr, or nil when mgr is nil or has no plugins — so the caller can skip the OnEvent wiring entirely in the common no-plugin case. warnLog (when non-nil) receives per-plugin delivery failures.
func (*EventNotifier) Handle ¶
func (n *EventNotifier) Handle(ev agentcore.AgentEvent)
Handle maps ev to a wire payload and dispatches it to subscribed plugins. It is a no-op on a nil notifier and when no plugin subscribes to ev's type, so it builds a payload only when someone is listening. Delivery is bounded and isolated by the Manager, so Handle never blocks the loop beyond the per-plugin event timeout.
type EventParams ¶
type EventParams struct {
Type string `json:"type"`
Data json.RawMessage `json:"data,omitempty"`
}
EventParams is the parameter object for an `event` notification. Type is the event discriminant (an agentcore.Event* value); Data carries a small, wire-safe payload for that event (never secrets — see plugin.EventData).
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns a set of loaded plugins and their aggregated tools. It is not safe for concurrent modification; load once at startup, then read.
func Discover ¶
Discover finds and loads every plugin under dir. A plugin is any executable regular file directly inside dir (non-executable files and subdirectories are ignored). Each plugin is launched and handshaked; a failure is written to warnLog (when non-nil) and that plugin is skipped. A missing dir is not an error — it yields an empty Manager. pluginStderr, when non-nil, receives every plugin's stderr.
func (*Manager) Close ¶
Close shuts down every loaded plugin, returning the first error encountered (all plugins are attempted regardless).
func (*Manager) Commands ¶
func (m *Manager) Commands() []PluginCommand
Commands returns the aggregated slash commands of every loaded plugin, in load order (and, within a plugin, in manifest order). Each carries the owning plugin so the caller can dispatch it via Plugin.CallCommand.
func (*Manager) DispatchEvent ¶
func (m *Manager) DispatchEvent(params EventParams, warnLog io.Writer)
DispatchEvent delivers one lifecycle event to every plugin subscribed to its type (US-017, #133). Delivery is best-effort and isolated: each plugin's send is bounded by eventTimeout, and a delivery failure to one plugin (timeout, dead process) is written to warnLog when non-nil and does not stop delivery to the others. It never blocks the agent loop beyond the per-plugin timeout.
func (*Manager) Plugins ¶
Plugins returns the loaded plugins (for command aggregation and diagnostics).
func (*Manager) Subscribers ¶
Subscribers reports whether any loaded plugin subscribes to the given event type. It lets a caller skip building an event payload when nobody is listening (US-017, #133).
type Manifest ¶
type Manifest struct {
// Name identifies the plugin; used to namespace its tools and in diagnostics.
Name string `json:"name"`
// Version is an optional free-form version string for diagnostics.
Version string `json:"version,omitempty"`
// Tools are the tools this plugin registers with the agent.
Tools []ToolSpec `json:"tools,omitempty"`
// Commands are the slash commands this plugin registers.
Commands []CommandSpec `json:"commands,omitempty"`
// Events lists the agent lifecycle event types this plugin subscribes to
// (US-017, #133). golder delivers only these via one-way `event` notifications;
// an empty list means the plugin observes no events. Valid values are the
// agentcore.Event* discriminants (e.g. "agent_start", "tool_execution_end").
Events []string `json:"events,omitempty"`
}
Manifest is the plugin's self-description, returned from the initialize call.
type Plugin ¶
type Plugin struct {
Manifest Manifest
// contains filtered or unexported fields
}
Plugin is a running plugin: its JSON-RPC client plus the manifest it declared during initialize.
func Load ¶
Load starts the plugin executable at path (with optional args) and performs the initialize handshake. stderr, when non-nil, receives the plugin's stderr for logging. The caller must Close the returned Plugin.
func (*Plugin) CallCommand ¶
func (p *Plugin) CallCommand(ctx context.Context, name string, args json.RawMessage) (CommandCallResult, error)
CallCommand forwards a slash-command invocation to the plugin over JSON-RPC (commands/call) and returns the plugin's result. args carries the command's free-form arguments (passed through verbatim). A transport error (e.g. the plugin crashed) or a malformed reply is surfaced as a returned error rather than a panic — mirroring how pluginTool.Execute isolates a dead plugin, but leaving the caller to decide how to present the failure.
func (*Plugin) Close ¶
Close shuts the plugin down: it sends a best-effort shutdown notification then closes the transport (which closes stdin and, if needed, kills the child). The shutdown notify is bounded by eventTimeout so a plugin that has stopped reading its stdin (whose write pipe is full) cannot make Close block on the transport write mutex — Close falls through to client.Close, which kills the child.
func (*Plugin) SendEvent ¶
func (p *Plugin) SendEvent(params EventParams) error
SendEvent delivers one lifecycle event to the plugin as a one-way `event` notification (US-017, #133). Delivery is fire-and-forget and bounded by eventTimeout: the underlying write runs on its own goroutine so a plugin that has stopped reading its stdin (a hung or slow plugin) cannot block the agent loop — the send is abandoned when the timeout elapses and its error returned. The dropped write goroutine ends on its own when the plugin dies or Close tears the pipe down.
func (*Plugin) Subscribes ¶
Subscribes reports whether the plugin asked to receive the given event type in its manifest (US-017, #133). golder only delivers subscribed events.
type PluginCommand ¶
type PluginCommand struct {
// Plugin is the plugin that declared and handles this command.
Plugin *Plugin
// Spec is the command's declaration from the owning plugin's manifest.
Spec CommandSpec
}
PluginCommand pairs a plugin-declared slash command with the plugin that owns it, so a caller can dispatch the command back to its plugin via Plugin.CallCommand.