plugin

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package plugin provides the plugin system interface and base types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CellStyle

type CellStyle struct {
	Foreground string `json:"foreground"` // Color name or hex
	Background string `json:"background"` // Color name or hex
	Bold       bool   `json:"bold"`
	Italic     bool   `json:"italic"`
	Underline  bool   `json:"underline"`
}

CellStyle defines styling for a cell

type ColumnDefinition

type ColumnDefinition struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Width    int    `json:"width"`
	Priority int    `json:"priority"` // Column display priority
	Align    string `json:"align"`    // left, center, right
}

ColumnDefinition defines a column to be added by an overlay

type ColumnPosition

type ColumnPosition string

ColumnPosition defines where to place an overlay column

const (
	// ColumnPositionBefore places the column before the target column.
	ColumnPositionBefore ColumnPosition = "before"
	// ColumnPositionAfter places the column after the target column.
	ColumnPositionAfter ColumnPosition = "after"
	// ColumnPositionStart places the column at the start.
	ColumnPositionStart ColumnPosition = "start"
	// ColumnPositionEnd places the column at the end.
	ColumnPositionEnd ColumnPosition = "end"
)

type ConfigField

type ConfigField struct {
	Type        string      `json:"type"` // string, int, bool, float, array, object
	Description string      `json:"description"`
	Default     interface{} `json:"default"`
	Required    bool        `json:"required"`
	Validation  string      `json:"validation"` // Regex or validation rule
}

ConfigField describes a configuration field

type ConfigurablePlugin

type ConfigurablePlugin interface {
	Plugin

	// GetConfig returns the current configuration
	GetConfig() map[string]interface{}

	// SetConfig updates the configuration
	SetConfig(config map[string]interface{}) error

	// ValidateConfig validates a configuration without applying it
	ValidateConfig(config map[string]interface{}) error

	// GetConfigUI returns a UI for configuration (optional)
	GetConfigUI() tview.Primitive
}

ConfigurablePlugin represents a plugin that can be configured at runtime

type DataCallback

type DataCallback func(data interface{}, err error)

DataCallback is called when subscribed data updates

type DataPlugin

type DataPlugin interface {
	Plugin

	// GetDataProviders returns the data providers offered
	GetDataProviders() []DataProviderInfo

	// Subscribe allows other plugins to subscribe to data updates
	Subscribe(ctx context.Context, providerID string, callback DataCallback) (SubscriptionID, error)

	// Unsubscribe removes a data subscription
	Unsubscribe(ctx context.Context, subscriptionID SubscriptionID) error

	// Query performs a one-time data query
	Query(ctx context.Context, providerID string, params map[string]interface{}) (interface{}, error)
}

DataPlugin represents a plugin that provides data to other plugins

type DataProviderInfo

type DataProviderInfo struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Schema      map[string]interface{} `json:"schema"`       // Data schema
	QueryParams map[string]ConfigField `json:"query_params"` // Available query parameters
}

DataProviderInfo describes a data provider

type HealthStatus

type HealthStatus struct {
	Healthy bool                   `json:"healthy"`
	Status  string                 `json:"status"` // "healthy", "degraded", "unhealthy"
	Message string                 `json:"message"`
	Details map[string]interface{} `json:"details,omitempty"`
}

HealthStatus represents the health of a plugin

type HookCallback

type HookCallback func(ctx context.Context, params map[string]interface{}) error

HookCallback is called when a hook is triggered

type HookInfo

type HookInfo struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Parameters  map[string]ConfigField `json:"parameters"`
}

HookInfo describes a hook provided by a plugin

type HookablePlugin

type HookablePlugin interface {
	Plugin

	// GetHooks returns the hooks provided by this plugin
	GetHooks() []HookInfo

	// RegisterHook registers a callback for a hook
	RegisterHook(hookID string, callback HookCallback) error
}

HookablePlugin represents a plugin that provides hooks for events

type Info

type Info struct {
	Name         string                 `json:"name"`
	Version      string                 `json:"version"`
	Description  string                 `json:"description"`
	Author       string                 `json:"author"`
	License      string                 `json:"license"`
	Requires     []string               `json:"requires"` // Required plugins
	Provides     []string               `json:"provides"` // Capabilities provided
	ConfigSchema map[string]ConfigField `json:"config_schema"`
}

Info contains metadata about a plugin

type LifecycleAware

type LifecycleAware interface {
	// OnEnable is called when the plugin is enabled
	OnEnable(ctx context.Context) error

	// OnDisable is called when the plugin is disabled
	OnDisable(ctx context.Context) error

	// OnConfigChange is called when configuration changes
	OnConfigChange(ctx context.Context, oldConfig, newConfig map[string]interface{}) error
}

LifecycleAware represents a plugin that needs lifecycle events

type Manager

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

Manager manages the lifecycle of all plugins

func NewManager

func NewManager() *Manager

NewManager creates a new plugin manager

func (*Manager) DisablePlugin

func (m *Manager) DisablePlugin(name string) error

DisablePlugin disables and stops a plugin

func (*Manager) EnablePlugin

func (m *Manager) EnablePlugin(name string, config map[string]interface{}) error

EnablePlugin enables and starts a plugin

func (*Manager) GetOverlayPlugins

func (m *Manager) GetOverlayPlugins() []OverlayPlugin

GetOverlayPlugins returns all plugins that provide overlays

func (*Manager) GetPlugin

func (m *Manager) GetPlugin(name string) (Plugin, error)

GetPlugin returns a plugin by name

func (*Manager) GetPluginState

func (m *Manager) GetPluginState(name string) (PluginState, error)

GetPluginState returns the state of a plugin

func (*Manager) GetViewPlugins

func (m *Manager) GetViewPlugins() []ViewPlugin

GetViewPlugins returns all plugins that provide views

func (*Manager) ListPlugins

func (m *Manager) ListPlugins() []PluginInfo

ListPlugins returns all registered plugins

func (*Manager) RegisterPlugin

func (m *Manager) RegisterPlugin(plugin Plugin) error

RegisterPlugin registers a plugin with the manager

func (*Manager) StartHealthChecks

func (m *Manager) StartHealthChecks()

StartHealthChecks starts periodic health checks for all plugins

func (*Manager) Stop

func (m *Manager) Stop() error

Stop stops all plugins and the manager

func (*Manager) UpdatePluginConfig

func (m *Manager) UpdatePluginConfig(name string, config map[string]interface{}) error

UpdatePluginConfig updates a plugin's configuration

type Metadata added in v0.3.0

type Metadata struct {
	RegistrationTime int64
	LoadOrder        int
	Source           string // "builtin", "external", "dynamic"
	Path             string // File path for external plugins
	Checksum         string // For verification
}

Metadata contains additional metadata about a plugin

type Overlay

type Overlay interface {
	// GetID returns the unique identifier
	GetID() string

	// GetColumns returns additional columns to add
	GetColumns() []ColumnDefinition

	// GetCellData returns data for a specific cell
	GetCellData(ctx context.Context, viewID string, rowID interface{}, columnID string) (string, error)

	// GetCellStyle returns styling for a specific cell
	GetCellStyle(ctx context.Context, viewID string, rowID interface{}, columnID string) CellStyle

	// ShouldRefresh indicates if the overlay needs refresh
	ShouldRefresh() bool
}

Overlay represents a data overlay for existing views

type OverlayCellData

type OverlayCellData struct {
	Value string      `json:"value"`
	Style CellStyle   `json:"style"`
	Raw   interface{} `json:"raw,omitempty"`
}

OverlayCellData represents data for an overlay cell

type OverlayColumn

type OverlayColumn = ColumnDefinition

OverlayColumn defines a column added by an overlay (alias for ColumnDefinition)

type OverlayEvent

type OverlayEvent struct {
	Type   string                 `json:"type"`
	Source string                 `json:"source"`
	Data   map[string]interface{} `json:"data"`
	RowID  string                 `json:"row_id,omitempty"`
}

OverlayEvent represents an event from an overlay

type OverlayInfo

type OverlayInfo struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	TargetViews []string `json:"target_views"` // Views this overlay applies to
	Priority    int      `json:"priority"`     // Higher priority overlays render last
}

OverlayInfo describes an overlay provided by a plugin

type OverlayPlugin

type OverlayPlugin interface {
	Plugin

	// GetOverlays returns the overlays provided by this plugin
	GetOverlays() []OverlayInfo

	// CreateOverlay creates a specific overlay instance
	CreateOverlay(ctx context.Context, overlayID string) (Overlay, error)
}

OverlayPlugin represents a plugin that overlays data on existing views

type OverlayRowEnhancement

type OverlayRowEnhancement struct {
	RowID           string                     `json:"row_id"`
	CellData        map[string]OverlayCellData `json:"cell_data"`
	RowStyle        CellStyle                  `json:"row_style,omitempty"`
	BackgroundColor tcell.Color                `json:"background_color,omitempty"`
	Bold            bool                       `json:"bold,omitempty"`
	Tooltip         string                     `json:"tooltip,omitempty"`
	Interactive     bool                       `json:"interactive,omitempty"`
}

OverlayRowEnhancement represents enhancements to a row

type Plugin

type Plugin interface {
	// GetInfo returns metadata about the plugin
	GetInfo() Info

	// Init initializes the plugin with configuration
	Init(ctx context.Context, config map[string]interface{}) error

	// Start starts the plugin's background processes
	Start(ctx context.Context) error

	// Stop gracefully stops the plugin
	Stop(ctx context.Context) error

	// Health returns the current health status of the plugin
	Health() HealthStatus
}

Plugin represents the base interface that all plugins must implement

type PluginInfo

type PluginInfo struct {
	Info    Info
	State   State
	Enabled bool
	Running bool
}

PluginInfo combines plugin info with runtime state

type PluginMetadata

type PluginMetadata = Metadata

type PluginState

type PluginState = State

type Prioritizable

type Prioritizable interface {
	// GetPriority returns the plugin priority (higher = later initialization)
	GetPriority() int
}

Prioritizable represents a plugin that has priority ordering

type Registry

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

Registry manages plugin registration and metadata

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new plugin registry

func (*Registry) Get

func (r *Registry) Get(name string) (Plugin, error)

Get retrieves a plugin by name

func (*Registry) GetByCapability

func (r *Registry) GetByCapability(capability string) []Plugin

GetByCapability returns all plugins that provide a specific capability

func (*Registry) GetCapabilities

func (r *Registry) GetCapabilities() []string

GetCapabilities returns all available capabilities

func (*Registry) GetDependencyOrder

func (r *Registry) GetDependencyOrder() ([]string, error)

GetDependencyOrder returns plugins in dependency order

func (*Registry) GetMetadata

func (r *Registry) GetMetadata(name string) (PluginMetadata, error)

GetMetadata returns metadata for a plugin

func (*Registry) List

func (r *Registry) List() []Plugin

List returns all registered plugins

func (*Registry) Register

func (r *Registry) Register(plugin Plugin) error

Register registers a plugin in the registry

func (*Registry) SetMetadata

func (r *Registry) SetMetadata(name string, metadata PluginMetadata) error

SetMetadata updates metadata for a plugin

func (*Registry) Unregister

func (r *Registry) Unregister(name string) error

Unregister removes a plugin from the registry

func (*Registry) ValidateDependencies

func (r *Registry) ValidateDependencies() error

ValidateDependencies checks if all plugin dependencies are satisfied

type ResourceLimits

type ResourceLimits struct {
	MaxMemoryBytes int64   `json:"max_memory_bytes"`
	MaxCPUPercent  float64 `json:"max_cpu_percent"`
	MaxGoroutines  int     `json:"max_goroutines"`
	MaxConnections int     `json:"max_connections"`
	MaxCacheSize   int64   `json:"max_cache_size"`
}

ResourceLimits represents resource limits

type ResourceManager

type ResourceManager interface {
	// GetResourceUsage returns current resource usage
	GetResourceUsage() ResourceUsage

	// GetResourceLimits returns resource limits
	GetResourceLimits() ResourceLimits

	// SetResourceLimits sets resource limits
	SetResourceLimits(limits ResourceLimits) error
}

ResourceManager represents a plugin that manages resources

type ResourceUsage

type ResourceUsage struct {
	MemoryBytes int64   `json:"memory_bytes"`
	CPUPercent  float64 `json:"cpu_percent"`
	Goroutines  int     `json:"goroutines"`
	Connections int     `json:"connections"`
	CacheSize   int64   `json:"cache_size"`
}

ResourceUsage represents current resource usage

type State added in v0.3.0

type State struct {
	Enabled      bool
	Running      bool
	Health       HealthStatus
	LastError    error
	StartTime    time.Time
	RestartCount int
}

State represents the current state of a plugin

type SubscriptionID

type SubscriptionID string

SubscriptionID represents a data subscription

type View

type View interface {
	// GetName returns the display name
	GetName() string

	// GetID returns the unique identifier
	GetID() string

	// GetPrimitive returns the tview primitive for rendering
	GetPrimitive() tview.Primitive

	// Update refreshes the view data
	Update(ctx context.Context) error

	// HandleKey processes keyboard input
	HandleKey(event *tcell.EventKey) bool

	// SetFocus sets focus to this view
	SetFocus(app *tview.Application)

	// GetHelp returns help text for this view
	GetHelp() string
}

View represents a custom view interface

type ViewEvent

type ViewEvent struct {
	Type   string                 `json:"type"`
	Source string                 `json:"source"`
	Data   map[string]interface{} `json:"data"`
}

ViewEvent represents an event from a view

type ViewInfo

type ViewInfo struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Icon        string `json:"icon"`     // Icon character or emoji
	Shortcut    string `json:"shortcut"` // Keyboard shortcut
	Category    string `json:"category"` // View category (monitoring, management, etc.)
}

ViewInfo describes a view provided by a plugin

type ViewPlugin

type ViewPlugin interface {
	Plugin

	// GetViews returns the views provided by this plugin
	GetViews() []ViewInfo

	// CreateView creates a specific view instance
	CreateView(ctx context.Context, viewID string) (View, error)
}

ViewPlugin represents a plugin that provides custom views

Jump to

Keyboard shortcuts

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