plugins

package
v0.32.0 Latest Latest
Warning

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

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

Documentation

Overview

Package plugins provides a plugin system for extending Hive with additional commands and status providers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	PluginName string
	SessionID  string
	Session    *session.Session
}

Job represents a single status fetch request for a plugin and session.

type Manager

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

Manager manages plugin registration, lifecycle, and status fetching.

func NewManager

func NewManager(cfg config.PluginsConfig) *Manager

NewManager creates a new plugin manager with a shared worker pool.

func (*Manager) CloseAll

func (m *Manager) CloseAll()

CloseAll closes all registered plugins and stops background workers.

func (*Manager) Collector

func (m *Manager) Collector() *StatusCollector

Collector returns the status collector for reading cached statuses.

func (*Manager) EnabledPlugins

func (m *Manager) EnabledPlugins() []Plugin

EnabledPlugins returns all registered (available) plugins.

func (*Manager) Get

func (m *Manager) Get(name string) Plugin

Get returns a plugin by name, or nil if not found.

func (*Manager) InitAll

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

InitAll initializes all registered plugins. Errors are logged but do not stop initialization of other plugins.

func (*Manager) MergedCommands

func (m *Manager) MergedCommands(systemCmds, userCmds map[string]config.UserCommand) map[string]config.UserCommand

MergedCommands merges system, plugin, and user commands. Priority order: system (lowest) → plugins → user (highest).

func (*Manager) Pool

func (m *Manager) Pool() *WorkerPool

Pool returns the shared worker pool for plugins to use.

func (*Manager) RefreshAllStatus deprecated

func (m *Manager) RefreshAllStatus(ctx context.Context, sessions []*session.Session) map[string]map[string]Status

RefreshAllStatus fetches status from all plugins for the given sessions. Returns a map of plugin name -> session ID -> status.

Deprecated: Use StartBackgroundWorker for non-blocking status fetching.

func (*Manager) Register

func (m *Manager) Register(p Plugin)

Register adds a plugin if it is available. Plugins that are not available (missing dependencies) are silently skipped.

func (*Manager) StartBackgroundWorker

func (m *Manager) StartBackgroundWorker(ctx context.Context, pollInterval time.Duration) <-chan Result

StartBackgroundWorker starts background workers that fetch plugin statuses. Returns a channel that receives results as they complete. Call Stop() to shut down the workers.

func (*Manager) Stop

func (m *Manager) Stop()

Stop shuts down background workers and waits for them to finish.

func (*Manager) UpdateSessions

func (m *Manager) UpdateSessions(sessions []*session.Session)

UpdateSessions updates the session list. A plugin refresh is only triggered when sessions are added or removed to avoid unnecessary API calls (e.g. GitHub).

type Plugin

type Plugin interface {
	// Name returns the plugin name (e.g., "github", "beads").
	Name() string

	// Available returns true if the plugin's dependencies are met
	// (e.g., gh CLI is installed). Called once at startup.
	Available() bool

	// Init initializes the plugin. Called once after registration
	// if the plugin is available.
	Init(ctx context.Context) error

	// Close releases plugin resources.
	Close() error

	// Commands returns commands to register in the command palette.
	// Uses Plugin<Cmd> naming convention (e.g., GithubOpenPR).
	Commands() map[string]config.UserCommand

	// StatusProvider returns the status provider for UI integration.
	// May return nil if the plugin doesn't provide status.
	StatusProvider() StatusProvider
}

Plugin defines the interface for Hive plugins.

type Result

type Result struct {
	PluginName string
	SessionID  string
	Status     Status
	Err        error
}

Result represents the outcome of a status fetch job.

type Status

type Status struct {
	Label string         // e.g., "0/3", "PR#42", "main +2/-1"
	Icon  string         // e.g., "●", "◆", "!"
	Style lipgloss.Style // color/formatting
}

Status represents plugin status to display in the UI.

type StatusCollector

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

StatusCollector provides thread-safe caching for plugin statuses. It stores statuses indexed by plugin name and session ID.

func NewStatusCollector

func NewStatusCollector() *StatusCollector

NewStatusCollector creates a new status collector.

func (*StatusCollector) Clear

func (c *StatusCollector) Clear()

Clear removes all cached statuses.

func (*StatusCollector) Get

func (c *StatusCollector) Get(pluginName, sessionID string) (Status, bool)

Get retrieves a status for the given plugin and session.

func (*StatusCollector) GetAll

func (c *StatusCollector) GetAll(pluginName string) map[string]Status

GetAll returns all statuses for a given plugin.

func (*StatusCollector) Set

func (c *StatusCollector) Set(pluginName, sessionID string, status Status)

Set stores a status for the given plugin and session.

type StatusProvider

type StatusProvider interface {
	// RefreshStatus fetches fresh status data for a batch of sessions.
	// Uses the shared worker pool for subprocess calls.
	// Returns a map of session ID -> Status.
	RefreshStatus(ctx context.Context, sessions []*session.Session, pool *WorkerPool) (map[string]Status, error)

	// StatusCacheDuration returns how long status can be cached.
	StatusCacheDuration() time.Duration
}

StatusProvider defines the interface for plugins that provide status information to display in the UI (tree view, preview header).

type WorkerPool

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

WorkerPool limits concurrent subprocess execution across all plugins.

func NewWorkerPool

func NewWorkerPool(size int) *WorkerPool

NewWorkerPool creates a new worker pool with the given size.

func (*WorkerPool) Acquire

func (p *WorkerPool) Acquire()

Acquire blocks until a worker slot is available.

func (*WorkerPool) Release

func (p *WorkerPool) Release()

Release returns a worker slot to the pool.

func (*WorkerPool) Run

func (p *WorkerPool) Run(fn func())

Run executes fn with pool semaphore held.

func (*WorkerPool) RunContext

func (p *WorkerPool) RunContext(ctx context.Context, fn func()) error

RunContext executes fn with pool semaphore held, respecting context cancellation. Returns ctx.Err() if context is cancelled while waiting to acquire.

Directories

Path Synopsis
Package beads provides a Beads issue tracker plugin for Hive.
Package beads provides a Beads issue tracker plugin for Hive.
Package claude provides Claude Code integration for Hive.
Package claude provides Claude Code integration for Hive.
Package contextdir provides commands for opening context directories.
Package contextdir provides commands for opening context directories.
Package github provides a GitHub plugin for Hive.
Package github provides a GitHub plugin for Hive.
Package lazygit provides a lazygit plugin for Hive.
Package lazygit provides a lazygit plugin for Hive.
Package neovim provides a Neovim plugin for Hive.
Package neovim provides a Neovim plugin for Hive.
Package tmux provides a tmux plugin for Hive with default session management commands.
Package tmux provides a tmux plugin for Hive with default session management commands.

Jump to

Keyboard shortcuts

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