Documentation
¶
Overview ¶
Package plugin is the SDK every plugin binary and the host share: the handshake, the protocol versions, the lifecycle every kind answers (health, start, stop, notify), the logger and the process rules.
A plugin binary serves one or more kinds. Each kind has its own SDK package (pkg/plugin/source for sources) that adapts the plugin's Go interfaces to an Impl; the plugin's main calls Serve with them and never touches gRPC.
A plugin writes nothing to stdout: go-plugin reads the handshake from it. It logs through Logger, which writes to stderr, where the host reads it.
This package and every package under it import nothing under internal/.
Index ¶
- Constants
- Variables
- func Brand() string
- func ClientConfig(spec Spec, cmd *exec.Cmd) *goplugin.ClientConfig
- func Logger() hclog.Logger
- func Serve(impls map[Kind]Impl)
- func VersionedPlugins(impls map[Kind]Impl) map[int]goplugin.PluginSet
- type Client
- func (c *Client) Broker() *goplugin.GRPCBroker
- func (c *Client) Conn() *grpc.ClientConn
- func (c *Client) Health(ctx context.Context) (Health, error)
- func (c *Client) Kind() Kind
- func (c *Client) Notify(ctx context.Context, units []Unit, topics []Topic) error
- func (c *Client) Start(ctx context.Context, req StartRequest) error
- func (c *Client) Stop(ctx context.Context) error
- type Health
- type Impl
- type Kind
- type Launcher
- type Lifecycle
- type Process
- type Spec
- type StartRequest
- type Status
- type Topic
- type Unit
Constants ¶
const BrandEnv = "LOOP_PLUGIN_BRAND"
BrandEnv is the environment variable through which the host passes its brand name to a plugin process; a plugin cannot import the host's brand.
const ParentEnv = "LOOP_PLUGIN_PARENT_PID"
ParentEnv is the environment variable through which the host passes its pid, so a plugin whose host died before Serve ran still exits.
const Protocol = 1
Protocol is the plugin protocol version this SDK speaks. A breaking change to any kind's protocol is a new version, served beside the old one in VersionedPlugins until no supported host or plugin speaks the old one.
Variables ¶
var Handshake = goplugin.HandshakeConfig{ ProtocolVersion: Protocol, MagicCookieKey: "LOOP_PLUGIN_COOKIE", MagicCookieValue: "3f1c9a0e-units-and-tasks", }
Handshake is the go-plugin handshake the host and every plugin check. Its ProtocolVersion is unused: the version is negotiated from VersionedPlugins.
var Topics = []Topic{TopicRounds, TopicGates, TopicMarks, TopicTasks, TopicTurns, TopicSessions, TopicOverrides, TopicViewer, TopicConfig, TopicEvents, TopicWorkspaces, TopicAgents}
Topics are every Topic, which a manifest's notify list names from.
Functions ¶
func Brand ¶
func Brand() string
Brand is the host's brand name as the host passed it in BrandEnv; empty when the process was started by no host, as in CLI mode run by hand.
func ClientConfig ¶
func ClientConfig(spec Spec, cmd *exec.Cmd) *goplugin.ClientConfig
ClientConfig is the go-plugin client configuration that starts spec's binary through cmd: the handshake, the versioned plugin set of the kinds spec names, gRPC only, and the checksum when spec has one. The process's environment is cmd.Env (the host's when nil), then spec.Env, then ParentEnv set to the host's pid; a later key wins. The client is unmanaged: go-plugin would keep a managed one until CleanupClients, and the host kills each client itself.
func Logger ¶
Logger is the plugin's logger. It writes JSON lines to stderr, which the host relays to its own log at the host's level; a plugin never writes to stdout.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the host's handle on one kind a plugin serves. It answers the kind's Lifecycle; the kind's SDK package builds its own client on Conn and Broker.
func Dispense ¶
Dispense returns the host's handle on kind k of a connected plugin whose spec names kinds.
func (*Client) Broker ¶
func (c *Client) Broker() *goplugin.GRPCBroker
Broker is the connection's go-plugin broker, on which the host serves a kind's host services.
func (*Client) Conn ¶
func (c *Client) Conn() *grpc.ClientConn
Conn is the connection to the plugin, shared by every kind it serves.
type Health ¶
Health is a kind's health. Reason says why a kind is loading or degraded, and is empty while it serves.
type Impl ¶
Impl is one kind a plugin binary serves: its lifecycle, and the kind's own gRPC services, which Register adds to the plugin's server. A kind's SDK package builds the Impl; a plugin implements only that package's interfaces.
type Kind ¶
type Kind string
Kind names a capability a plugin serves, such as "source". It is the go-plugin plugin name, and the name of the kind's table in plugin.toml.
type Launcher ¶
Launcher starts plugin processes. The host's launcher starts a binary in the daemon's process group; plugintest's serves kinds in-process.
type Lifecycle ¶
type Lifecycle interface {
Health(ctx context.Context) (Health, error)
Start(ctx context.Context, req StartRequest) error
Stop(ctx context.Context) error
Notify(ctx context.Context, units []Unit, topics []Topic) error
}
Lifecycle is what every kind answers. The host calls Start once per process, before any call but Health; Stop before it kills the process; and Notify when host state the kind reads changed for some units, after which a kind that computes from that state reports those units again.
type Process ¶
Process is a started plugin. Kind returns the host's handle on one of the kinds it serves, and errors for a kind its Spec does not name. Protocol is the negotiated protocol version. Exited tells whether the process ended, by Kill or by crashing. Kill stops it, and is safe to call more than once.
type Spec ¶
type Spec struct {
// ID is the plugin's id, from its manifest.
ID string
// Path is the plugin's binary.
Path string
// Kinds are the kinds the manifest says the binary serves.
Kinds []Kind
// Env is added to the process's environment, [BrandEnv] among it.
Env []string
// Checksum is the SHA-256 the binary must have; nil when the binary is
// trusted by its path.
Checksum []byte
// Logger receives the plugin's log, which it writes to stderr.
Logger hclog.Logger
}
Spec is what the host knows of a plugin before it starts it.
type StartRequest ¶
type StartRequest struct {
// StateDir is the plugin's own state directory; the host never reads it.
StateDir string
// HostBroker is the go-plugin broker id on which the host serves the
// kind's host services, zero when it serves none. The kind's SDK package
// dials it; a plugin never sees it.
HostBroker uint32
}
StartRequest is what the host gives a kind when it starts it.
type Status ¶
type Status int32
Status is what a kind's health reports.
const ( // StatusUnknown is the zero Status; a kind never reports it. StatusUnknown Status = iota // StatusLoading: the kind has not yet imported its data or reported every unit. StatusLoading // StatusServing: the kind is up to date. StatusServing // StatusDegraded: the kind serves, but a source it reads is failing. StatusDegraded )
type Topic ¶
type Topic string
Topic names host state a kind may read, of which Notify says what changed. The names are the wire's, stable across plugins built apart from the host.
const ( TopicRounds Topic = "rounds" // round state, its marks, the pending rounds and the pause TopicGates Topic = "gates" // gates: drafts, plans, questions, proposals TopicMarks Topic = "marks" // unit marks TopicTasks Topic = "tasks" // tasks and their properties TopicTurns Topic = "turns" // turns and their records TopicSessions Topic = "sessions" // sessions and the workspaces they run in TopicOverrides Topic = "overrides" // per-unit overrides TopicViewer Topic = "viewer" // the viewer's login and teams TopicConfig Topic = "config" // the loaded profile and configuration TopicEvents Topic = "events" // events on units, the loop's and the plugins' TopicWorkspaces Topic = "workspaces" // the workspace managers' listing TopicAgents Topic = "agents" // the agents and their activity )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package manifest reads and validates a plugin's plugin.toml: its id, the kinds its binary serves, the protocol version it speaks and one table per kind, whose contents the kind's SDK package defines and decodes.
|
Package manifest reads and validates a plugin's plugin.toml: its id, the kinds its binary serves, the protocol version it speaks and one table per kind, whose contents the kind's SDK package defines and decodes. |
|
cmd/manifestdoc
command
Command manifestdoc writes plugin.toml's JSON schema and reference page from package manifest; make docs-ref runs it from the repository root.
|
Command manifestdoc writes plugin.toml's JSON schema and reference page from package manifest; make docs-ref runs it from the repository root. |
|
Package plugintest is the in-process fake of a plugin process, for tests on either side of the protocol.
|
Package plugintest is the in-process fake of a plugin process, for tests on either side of the protocol. |
|
Package source is the SDK of the source kind: a plugin that reports units of work from a service (pull requests, threads) and acts on them.
|
Package source is the SDK of the source kind: a plugin that reports units of work from a service (pull requests, threads) and acts on them. |
|
sourcetest
Package sourcetest runs source plugins in-process, for tests on either side of the source protocol: Stub is a source that reports a scripted snapshot, and Launch connects any source to a host over a real go-plugin connection inside the test binary.
|
Package sourcetest runs source plugins in-process, for tests on either side of the source protocol: Stub is a source that reports a scripted snapshot, and Launch connects any source to a host over a real go-plugin connection inside the test binary. |
|
Package store is a plugin's own SQLite database, in the state directory the host gives it at start: opened with the plugin's migrations, and filled once from the import.db the host's store migration exported for it.
|
Package store is a plugin's own SQLite database, in the state directory the host gives it at start: opened with the plugin's migrations, and filled once from the import.db the host's store migration exported for it. |