plugin

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 16 Imported by: 1 module, 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 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

View Source
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.

View Source
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.

View Source
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

View Source
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.

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

func Logger() hclog.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.

func Serve

func Serve(impls map[Kind]Impl)

Serve serves impls, one per kind, and returns when the host ends the plugin. It exits the process when the parent that started it dies, after giving every kind's Stop up to five seconds: there is no reattach.

func VersionedPlugins

func VersionedPlugins(impls map[Kind]Impl) map[int]goplugin.PluginSet

VersionedPlugins is the go-plugin plugin set of each protocol version, one plugin per kind of impls. The plugin side passes its impls; the host passes the kinds it expects, each with a nil Impl.

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

func Dispense(proto goplugin.ClientProtocol, kinds []Kind, k Kind) (*Client, error)

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.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (Health, error)

func (*Client) Kind

func (c *Client) Kind() Kind

Kind is the kind this client reaches.

func (*Client) Notify

func (c *Client) Notify(ctx context.Context, units []Unit, topics []Topic) error

func (*Client) Start

func (c *Client) Start(ctx context.Context, req StartRequest) error

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

type Health

type Health struct {
	Status Status
	Reason string
}

Health is a kind's health. Reason says why a kind is loading or degraded, and is empty while it serves.

type Impl

type Impl interface {
	Lifecycle
	Register(s *grpc.Server, broker *goplugin.GRPCBroker) error
}

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

type Launcher interface {
	Launch(ctx context.Context, spec Spec) (Process, error)
}

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

type Process interface {
	Kind(k Kind) (*Client, error)
	Protocol() int
	Exited() bool
	Kill()
}

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.

func Exec

func Exec(spec Spec, cmd *exec.Cmd) (Process, error)

Exec starts spec's binary through cmd and completes the handshake. The caller sets cmd's process attributes.

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
)

type Unit

type Unit struct {
	Provider string `json:"provider,omitempty"`
	Key      string `json:"key,omitempty"`
}

Unit names a unit of work by its provider and the provider's key, as the host's unit does.

Directories

Path Synopsis
Package evalout guards where an eval command writes what real calls returned.
Package evalout guards where an eval command writes what real calls returned.
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.
pb
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.

Jump to

Keyboard shortcuts

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