Documentation
¶
Overview ¶
Package plugin defines the plugin system interface and registry for registering, managing, and coordinating sidecar plugins with shared context.
Index ¶
- func IsStale(ctx *Context, msg EpochMessage) bool
- type BindingRegistrar
- type Category
- type Command
- type Context
- type CursorProvider
- type Diagnostic
- type DiagnosticProvider
- type EpochMessage
- type FooterStatusProvider
- type GlobalKeyBlocker
- type KeyRouter
- type MouseModeProvider
- type OpenFileMsg
- type PendingWorkspaceSelection
- type PendingWorkspaceSelector
- type Plugin
- type PluginFocusedMsg
- type Registry
- func (r *Registry) Context() *Context
- func (r *Registry) Get(id string) Plugin
- func (r *Registry) Plugins() []Plugin
- func (r *Registry) Register(p Plugin) error
- func (r *Registry) Reinit(newWorkDir, newProjectRoot string) []tea.Cmd
- func (r *Registry) Start() []tea.Cmd
- func (r *Registry) Stop()
- func (r *Registry) Unavailable() map[string]string
- type TextInputConsumer
- type WorkspaceSelectionKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsStale ¶
func IsStale(ctx *Context, msg EpochMessage) bool
IsStale returns true if the message's epoch doesn't match the current context epoch. Use this in Update() handlers to discard messages from previous projects:
if plugin.IsStale(p.ctx, msg) { return p, nil }
Types ¶
type BindingRegistrar ¶
type BindingRegistrar interface {
RegisterPluginBinding(key, command, context string)
}
BindingRegistrar allows plugins to register key bindings dynamically. This is implemented by keymap.Registry.
type Category ¶
type Category string
Category represents a logical grouping of commands for the command palette.
type Command ¶
type Command struct {
ID string // Unique identifier (e.g., "stage-file")
Name string // Short name for footer (e.g., "Stage")
Description string // Full description for palette
Category Category // Logical grouping for palette display
Handler func() tea.Cmd // Action to execute (optional)
Context string // Activation context
Priority int // Footer display priority: 1=highest, 0=default (treated as 99)
}
Command represents a keybinding command exposed by a plugin.
type Context ¶
type Context struct {
WorkDir string // Actual working directory (worktree path for linked worktrees)
ProjectRoot string // Main repo root for shared state (same as WorkDir for non-worktrees)
ConfigDir string
Config *config.Config
Adapters map[string]adapter.Adapter
EventBus *event.Dispatcher
Logger *slog.Logger
Keymap BindingRegistrar // For plugins to register dynamic bindings
Epoch uint64 // Incremented on project switch to invalidate stale async messages
}
Context provides shared resources to plugins during initialization.
type CursorProvider ¶ added in v0.88.0
CursorProvider is an optional capability for plugins that own the terminal cursor. Coordinates are local to the plugin content area; the app applies its header offset and suppresses the cursor while blurred or covered by a modal.
type Diagnostic ¶
Diagnostic represents a health/status check result.
type DiagnosticProvider ¶
type DiagnosticProvider interface {
Diagnostics() []Diagnostic
}
DiagnosticProvider is implemented by plugins that expose diagnostics.
type EpochMessage ¶
type EpochMessage interface {
GetEpoch() uint64
}
EpochMessage is implemented by async messages that need staleness detection. Messages from async operations should embed an Epoch field and implement this interface.
type FooterStatusProvider ¶ added in v0.95.0
type FooterStatusProvider interface {
// An empty string means "nothing to say".
FooterStatus() (string, bool)
}
FooterStatusProvider is an optional capability for plugins with a condition that must stay visible even though the host owns the footer. A plugin that suppresses its own status line has no other always-on surface.
type GlobalKeyBlocker ¶ added in v0.96.0
type GlobalKeyBlocker interface {
BlocksGlobalKeys() bool
}
GlobalKeyBlocker is an optional capability for plugins with overlays that own the keyboard. While it reports true, Sidecar forwards every key except its interrupt instead of running host-level shortcuts.
type KeyRouter ¶ added in v0.95.0
type KeyRouter interface {
GlobalKeyBlocker
// BlocksGlobalKeys reports that the plugin is showing an overlay that owns
// the keyboard. Every key except the host's interrupt is forwarded.
// ClaimsKey reports that the plugin has a live contextual binding for a
// key. It is asked only for keys sidecar would otherwise handle globally,
// and only when no overlay is blocking.
ClaimsKey(key string) bool
// QuitKeyExits reports whether `q` in the plugin's current context should
// reach sidecar's quit flow. It replaces the host's isRootContext guess for
// plugins that can answer for themselves.
QuitKeyExits() bool
}
KeyRouter is an optional capability for plugins that own keys the host also binds globally. It makes sidecar's key precedence explicit instead of implicit in the order of a switch statement:
- an open sidecar application modal;
- the active plugin's text-input or blocking-overlay context (TextInputConsumer, or BlocksGlobalKeys here);
- an active plugin contextual binding (ClaimsKey here);
- sidecar global bindings;
- unbound input forwarded to the plugin.
Only plugins that implement it participate in levels 2 (overlay) and 3; every other plugin keeps the level-4-then-5 behaviour it has always had.
type MouseModeProvider ¶ added in v0.88.0
MouseModeProvider is an optional capability for plugins that need a more specific mouse reporting mode in their current view. Sidecar defaults to all-motion for hover-driven UI and lets embedded terminal contexts request cell-motion so only clicks, drags, releases, and wheels are reported.
type OpenFileMsg ¶
type OpenFileMsg struct {
Editor string // Editor command (e.g., "vim", "code")
Path string // File path to open
LineNo int // Line number to open at (0 = start of file)
}
OpenFileMsg requests opening a file in an external editor. Sent by plugins, handled by app to exec the editor process.
type PendingWorkspaceSelection ¶ added in v0.94.0
type PendingWorkspaceSelection struct {
Kind WorkspaceSelectionKind
Key string
Path string
}
PendingWorkspaceSelection is delivered synchronously after registry.Reinit, before the returned async Start commands run.
type PendingWorkspaceSelector ¶ added in v0.94.0
type PendingWorkspaceSelector interface {
SetPendingWorkspaceSelection(PendingWorkspaceSelection)
}
type Plugin ¶
type Plugin interface {
ID() string
Name() string
Icon() string
Init(ctx *Context) error
Start() tea.Cmd
Stop()
Update(msg tea.Msg) (Plugin, tea.Cmd)
View(width, height int) string
IsFocused() bool
SetFocused(bool)
Commands() []Command
FocusContext() string
}
Plugin defines the interface for all sidecar plugins.
type PluginFocusedMsg ¶
type PluginFocusedMsg struct{}
PluginFocusedMsg is sent to a plugin when it becomes the active plugin. Plugins can use this to refresh data or update their state on focus.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages plugin registration and lifecycle.
func NewRegistry ¶
NewRegistry creates a new plugin registry with the given context.
func (*Registry) Context ¶
Context returns the shared plugin context, or nil when the registry was built without one. App-owned surfaces that are not registry plugins (the global Tasks host) read it to inherit config, logger, and adapters without taking part in the registry's per-project lifecycle.
func (*Registry) Register ¶
Register adds a plugin to the registry. If Init fails, the plugin is marked unavailable (silent degradation).
func (*Registry) Reinit ¶
Reinit stops all plugins, updates the context with a new WorkDir and ProjectRoot, and reinitializes all plugins. Returns the start commands for all plugins.
func (*Registry) Stop ¶
func (r *Registry) Stop()
Stop stops all registered plugins in reverse order.
func (*Registry) Unavailable ¶
Unavailable returns a map of plugin IDs to their failure reasons.
type TextInputConsumer ¶
type TextInputConsumer interface {
ConsumesTextInput() bool
}
TextInputConsumer is an optional capability for plugins that need alphanumeric key input to be forwarded as typed text instead of being intercepted by app-level shortcuts.
type WorkspaceSelectionKind ¶ added in v0.94.0
type WorkspaceSelectionKind string
const ( WorkspaceSelectionWorktree WorkspaceSelectionKind = "worktree" WorkspaceSelectionShell WorkspaceSelectionKind = "shell" )