pluginhost

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: GPL-3.0 Imports: 27 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 pluginhost supervises direct-child executable plugins.

Index

Constants

View Source
const (
	ErrorCodeStartFailed           = "start_failed"
	ErrorCodeReconcileFailed       = "reconcile_failed"
	ErrorCodeInvokeFailed          = "invoke_failed"
	ErrorCodeEndSessionFailed      = "end_session_failed"
	ErrorCodeSessionInputFailed    = "session_input_failed"
	ErrorCodeOperationFailed       = "operation_failed"
	ErrorCodeHealthTimeout         = "health_timeout"
	ErrorCodeHealthReported        = "health_reported_unhealthy"
	ErrorCodeUnexpectedExit        = "unexpected_exit"
	ErrorCodeStopFailed            = "stop_failed"
	ErrorCodeUnsupportedPlatform   = "unsupported_platform"
	ErrorCodeConfigurationRejected = "configuration_rejected"
)

Variables

View Source
var (
	ErrPluginNotConfigured = errors.New("plugin is not configured")
	ErrPluginUnavailable   = errors.New("plugin is temporarily unavailable")
	ErrManagerClosed       = errors.New("plugin manager is closed")
	ErrPermanentStart      = errors.New("plugin cannot start with the current executable and desired state")
)

Functions

func PermanentStart

func PermanentStart(err error) error

PermanentStart classifies a start failure that cannot recover until the executable or desired specification changes.

Types

type Callbacks

type Callbacks struct {
	Observe            func(observation.Source, protocol.Observation) error
	Withdraw           func(string, protocol.WithdrawRequest) error
	WithdrawGeneration func(string, uint64)
	WithdrawInstance   func(string, string, uint64)
	Checkpoint         func(string, protocol.CheckpointRequest) error
	CompleteSession    func(context.Context, string, protocol.CompleteSessionRequest) error
	BeginExecution     func(context.Context, string, protocol.SessionExecutionRequest) error
	SessionCompleted   func(string, protocol.CompleteSessionRequest)
	Metric             func(protocol.MetricNotification)
	Log                func(string, protocol.LogNotification)
	// SessionInvalidated is a short, non-blocking core hook for sessions that
	// can no longer receive input from this package.
	SessionInvalidated func(SessionInvalidation)
	// SessionCleanup is a short, non-blocking core hook for stable cleanup
	// lifecycle ownership outside the supervisor.
	SessionCleanup func(SessionCleanup)
	// Started is a non-blocking core hook called after a child handshake.
	Started func(pluginID string, runID uint64)
}

Callbacks receive validated plugin effects.

type CheckpointRestore

type CheckpointRestore struct {
	Generation uint64
	Data       json.RawMessage
}

CheckpointRestore is a generation-scoped checkpoint supplied during desired instance replacement.

type Clock

type Clock interface {
	Now() time.Time
	NewTimer(time.Duration) Timer
}

type EndSessionRequest

type EndSessionRequest struct {
	InstanceID   string
	Generation   uint64
	SessionToken string
}

EndSessionRequest identifies one exact active plugin session.

type Instance

type Instance struct {
	ID         string
	Generation uint64
	Config     json.RawMessage
	Secrets    map[string]string
	Policies   map[string]presentation.PolicyConfig
	Checkpoint *CheckpointRestore
}

Instance is one enabled desired plugin instance. Disabled configuration is excluded before it reaches the plugin host.

func (Instance) Ref

func (instance Instance) Ref() protocol.InstanceRef

func (Instance) Wire

func (instance Instance) Wire() protocol.Instance

type InvocationKind

type InvocationKind string
const (
	InvocationInteractive InvocationKind = "interactive"
)

type InvokeRequest

type InvokeRequest struct {
	InstanceID   string
	Generation   uint64
	Action       string
	Payload      json.RawMessage
	SessionToken string
	Trigger      *protocol.SessionTrigger
}

InvokeRequest is the host's pre-dispatch session command.

type JitterFunc

type JitterFunc func() float64

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(coreVersion string, start StartFunc, callbacks Callbacks, optionValues ...ManagerOption) *Manager

func (*Manager) Apply

func (m *Manager) Apply(ctx context.Context, specs []Spec) error

func (*Manager) Changes

func (m *Manager) Changes() <-chan struct{}

func (*Manager) Close

func (m *Manager) Close(ctx context.Context) error

func (*Manager) CompleteSession

func (m *Manager) CompleteSession(ctx context.Context, pluginID string, request protocol.CompleteSessionRequest) error

CompleteSession releases the exact child-completed interactive session without sending a redundant end-session request back to that child.

func (*Manager) EndSession

func (m *Manager) EndSession(ctx context.Context, pluginID string, target protocol.InstanceRef, token SessionToken) error

func (*Manager) Invoke

func (m *Manager) Invoke(ctx context.Context, pluginID string, request InvokeRequest, kind InvocationKind, token SessionToken) error

func (*Manager) Operation

func (m *Manager) Operation(ctx context.Context, pluginID string, request protocol.OperationRequest) (protocol.OperationResult, error)

func (*Manager) Restart

func (m *Manager) Restart(ctx context.Context, pluginID string) error

func (*Manager) SessionInputResult

func (m *Manager) SessionInputResult(ctx context.Context, pluginID string, request protocol.SessionInputRequest) (protocol.SessionInputResult, error)

func (*Manager) Status

func (m *Manager) Status() []PluginStatus

type ManagerOption

type ManagerOption func(*managerOptions)

func WithClock

func WithClock(clock Clock) ManagerOption

func WithHealthInterval

func WithHealthInterval(interval time.Duration) ManagerOption

func WithJitter

func WithJitter(jitter JitterFunc) ManagerOption

type Phase

type Phase string
const (
	PhaseStopped     Phase = "stopped"
	PhaseStarting    Phase = "starting"
	PhaseRunning     Phase = "running"
	PhaseUnhealthy   Phase = "unhealthy"
	PhaseBackoff     Phase = "backoff"
	PhaseQuarantined Phase = "quarantined"
	PhaseStopping    Phase = "stopping"
)

type PluginStatus

type PluginStatus struct {
	ID                        string    `json:"id"`
	Desired                   bool      `json:"desired"`
	Phase                     Phase     `json:"phase"`
	Running                   bool      `json:"running"`
	Healthy                   bool      `json:"healthy"`
	HealthMisses              int       `json:"health_misses"`
	ExitCount                 int       `json:"exit_count"`
	RetryAt                   time.Time `json:"retry_at,omitempty"`
	LastErrorCode             string    `json:"last_error_code,omitempty"`
	LastErrorAt               time.Time `json:"last_error_at,omitempty"`
	SessionLifecycleErrorCode string    `json:"session_lifecycle_error_code,omitempty"`
	SessionLifecycleErrorAt   time.Time `json:"session_lifecycle_error_at,omitempty"`
}

type Process

type Process struct {
	// contains filtered or unexported fields
}

Process owns one direct child, its process group, RPC connection, and Wait call.

func Start

func Start(ctx context.Context, coreVersion string, spec Spec, callbacks Callbacks) (*Process, error)

Start verifies and starts a direct child, then completes the identity handshake.

func (*Process) Done

func (p *Process) Done() <-chan error

Done closes after the child has been reaped.

func (*Process) EndSession

func (p *Process) EndSession(ctx context.Context, request EndSessionRequest) error

EndSession tells the plugin that one interactive instance session has ended.

func (*Process) Invoke

func (p *Process) Invoke(ctx context.Context, request InvokeRequest) error

func (*Process) Operation

func (*Process) Ping

Ping checks plugin responsiveness.

func (*Process) ReplaceInstances

func (p *Process) ReplaceInstances(ctx context.Context, instances []Instance) error

ReplaceInstances atomically supplies the plugin's complete desired state.

func (*Process) SessionInput

SessionInput delivers one exact interactive input and returns the plugin's strict consumed/not-consumed disposition.

func (*Process) Stop

func (p *Process) Stop(ctx context.Context) error

Stop performs bounded graceful shutdown followed by process-group signals.

type SessionCleanup

type SessionCleanup struct {
	PluginID     string
	Sequence     uint64
	At           time.Time
	PendingCount int
	ErrorCode    string
}

SessionCleanup reports supervisor-owned session cleanup lifecycle state. PluginID is assigned by the authenticated supervisor, never by a child.

type SessionInvalidation

type SessionInvalidation struct {
	PluginID   string
	InstanceID string
	Generation uint64
	Token      SessionToken
	Reason     SessionInvalidationReason
}

type SessionInvalidationReason

type SessionInvalidationReason string
const (
	SessionInvalidatedExit       SessionInvalidationReason = "child_exit"
	SessionInvalidatedHealth     SessionInvalidationReason = "health_failure"
	SessionInvalidatedDisabled   SessionInvalidationReason = "disabled"
	SessionInvalidatedGeneration SessionInvalidationReason = "generation_changed"
	SessionInvalidatedReplaced   SessionInvalidationReason = "child_replaced"
	SessionInvalidatedInput      SessionInvalidationReason = "session_input_failed"
)

type SessionToken

type SessionToken string

type Spec

type Spec struct {
	ID              string
	Version         string
	Executable      string
	Args            []string
	SHA256          string
	ProtocolVersion string
	ExecutionModes  []protocol.ExecutionMode
	Channels        []protocol.Channel
	Operations      []protocol.OperationDescriptor
	Instances       []Instance
}

Spec is one verified plugin executable and its current enabled instances.

type StartFunc

type StartFunc func(context.Context, string, Spec, Callbacks) (Child, error)

type Timer

type Timer interface {
	C() <-chan time.Time
	Stop() bool
}

Jump to

Keyboard shortcuts

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