Documentation
¶
Overview ¶
Package plugin defines the plugin system interface and registry for registering, managing, and coordinating sidecar plugins with shared context.
Index ¶
- func FormatRemoteUnavailable(pluginName, hostID string) string
- func IsStale(ctx *Context, msg EpochMessage) bool
- type AttentionOrigin
- type AttentionOriginProvider
- type BindingRegistrar
- type Category
- type Class
- type Command
- type ContentLinkProvider
- type Context
- type CursorProvider
- type Descriptor
- type Diagnostic
- type DiagnosticProvider
- type EpochMessage
- type FocusCycler
- type FooterStatusProvider
- type GlobalKeyBlocker
- type HostBind
- type HostInventoryMsg
- type HostWorkspace
- type KeyRouter
- type MouseModeProvider
- type OpenFileMsg
- type PaneFocusProvider
- type PaneFocusRingHost
- type PaneFocusStop
- type PendingWorkspaceActionProvider
- type PendingWorkspaceSelection
- type PendingWorkspaceSelector
- type Placement
- 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) ReinitHost(newWorkDir, newProjectRoot string, bind HostBind) []tea.Cmd
- func (r *Registry) Replace(i int, p Plugin)
- func (r *Registry) SetHostIncarnation(n uint64)
- func (r *Registry) Start() []tea.Cmd
- func (r *Registry) Stop()
- func (r *Registry) Unavailable() map[string]string
- type ResizeDragReporter
- type Scope
- type SelfConstrainedView
- type TextInputConsumer
- type WheelBoundaryConsumer
- type WorkspaceSelectionKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatRemoteUnavailable ¶ added in v1.12.0
FormatRemoteUnavailable is the one-line reason Files/Git/td/Tasks show when bound to a host they cannot yet browse.
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 AttentionOrigin ¶ added in v1.11.0
type AttentionOrigin struct {
TmuxSession string
ProjectKey string
WorkDir string
// HostID names the registered remote host the visible workspace lives on,
// empty for one on this machine. Two machines legitimately share a session
// name and a checkout path, so without it a local selection would answer
// "is the user looking at that remote workspace" with yes.
HostID string
}
AttentionOrigin is the app-level identity shared by project and global workspace projections. It deliberately contains no notification or transport types.
type AttentionOriginProvider ¶ added in v1.11.0
type AttentionOriginProvider interface {
AttentionOrigin() (AttentionOrigin, bool)
}
AttentionOriginProvider projects the workspace/session actually visible in a presentation-only surface. The app owns focus and publishes this identity for host-wide background policy.
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 ContentLinkProvider ¶ added in v1.2.0
type ContentLinkProvider interface {
ContentLinkSurfaces() []contentlink.Surface
}
ContentLinkProvider is an optional capability for plugins that expose exact read-only rendered text rectangles for app-owned content-link decoration. Hosts read it after View so its geometry describes the frame just rendered.
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)
// HostID is empty for a local project. When set, this TUI is bound to a
// remote host project: WorkDir/ProjectRoot are not local paths, plugins
// that still assume a local tree must refuse, and Workspaces lists that
// host's inventory.
HostID string
HostIncarnation uint64
ProjectKey string // owning host's unscoped inventory key; empty when local
// HostWorktreeKey is the bound worktree's canonical path on the owning
// host, or empty for its main checkout. With ProjectKey it forms the
// durable workspace id (projectKey:worktree:key) a plugin reads that
// host's content and directory listings through.
HostWorktreeKey string
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
// HostWorkspaces returns the bound host project's in-memory workspaces.
// The app fills this from overview.HostCatalog; it is not reset by Reinit.
// The type is plugin-owned so this package does not import workspaceinventory
// (that import is a test cycle through agentintegration).
HostWorkspaces func() []HostWorkspace
// RemoteControlSpawner returns the control-mode proxy for the bound host,
// or nil when that host is not connected. Filled by the app from the
// Sessions spawner; not reset by Reinit.
RemoteControlSpawner func() tty.ControlSpawner
// RemoteRunner runs a sidecar command on a registered host (hosts.RunSidecar).
// The app fills it from the Sessions runner; the workspace plugin uses it
// for content reads and relayed uirequest acks. Not reset by Reinit.
RemoteRunner func(ctx context.Context, hostID string, args []string, out any) error
// HostVerbs is the bound host's advertised CLI verbs, or zero. Filled by
// the app from the Sessions hello; the workspace plugin builds RemoteSource
// from this plus RemoteRunner so this package does not import overview.
HostVerbs func() hostproto.VerbCapabilities
// HostShows reports that the bound host is connected enough to answer.
// It is separate from HostVerbs because a disconnected host advertises
// nothing, and "not connected" and "too old to do this" send a user
// looking in two different places.
HostShows func() bool
}
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 Descriptor ¶ added in v1.14.0
type Descriptor struct {
// ID is stable: the config key under plugins, the CLI name, and the
// persisted tab identity. It matches the constructed plugin's ID().
ID string
// Name is the header label. It is not required to match Plugin.Name(),
// which is what help and the palette document the surface by.
Name string
// Icon is the single-character header glyph.
Icon string
// Class decides who renders: an embedded plugin owns its own Bubble Tea
// frame, a protocol plugin is rendered by the host.
Class Class
// Scope decides lifecycle: a project plugin lives in the registry and is
// reinitialized on a project switch, a global plugin is built once and
// survives both project switches and scope toggles.
Scope Scope
// Placements are the surfaces this plugin's content can occupy.
Placements []Placement
// Detail is the one line the settings page prints under the name, saying
// what the surface is for.
Detail string
// Why is the sentence the install route leads with, for a plugin backed by
// a command the user has to have. Empty for one that ships in-repo.
Why string
// Beta marks a surface that carries the beta badge.
Beta bool
// Enabled answers whether Sidecar builds this plugin, reading
// plugins.<id>.enabled and any legacy switch the plugin migrated from so a
// config written before the unified key keeps working. A nil Enabled means
// the plugin has no switch at all — the workspace tab is exactly that.
Enabled func(*config.Config) bool
// Preference answers what the user chose, ignoring anything outside this
// plugin's own switch. It exists because the two questions differ: Notes
// needs the td panel, so a Notes preference of "on" with td off must still
// render as ON in settings rather than reading as a choice nobody made.
// Nil means the preference and the effective answer are the same question.
Preference func(*config.Config) bool
// SetEnabled writes the unified plugins.<id>.enabled key. It never touches
// a legacy feature flag: the flag is a read-only alias, so a user who once
// set it keeps it while the config key becomes the answer. Nil means the
// plugin has no switch.
SetEnabled func(*config.PluginsConfig, bool)
// New constructs the in-process plugin. Embedded class only; it is deferred
// so a caller that only wants the order (tests, the CLI, the settings page)
// never builds a plugin.
New func() Plugin
// Integration names the external command and formula the plugin needs, for
// the settings page's install route. The zero value means the plugin ships
// inside Sidecar and has nothing to install.
Integration version.Descriptor
// Instance is the configured entry a protocol descriptor was projected
// from, carrying the config section it was read from. Nil for the embedded
// class, which has a Go literal instead.
Instance *config.PluginInstance
}
Descriptor is everything Sidecar knows about a plugin before it runs.
It is data. The tab assembly, the settings page, the global tab list, the palette, and `sidecar plugin list` all read this one value rather than each keeping its own list of what exists — which is how "global plugin" stopped being a hardcoded special case for Tasks.
A descriptor never reaches for the application: it names a class, a scope, where its content can be placed, how to answer "is this enabled", and (for the embedded class) how to construct the plugin. Everything host-shaped is the host's business.
func ProtocolDescriptor ¶ added in v1.14.0
func ProtocolDescriptor(instance config.PluginInstance) Descriptor
ProtocolDescriptor projects one configured instance onto a descriptor.
Name is the instance ID until a describe result supplies the plugin's own display name. That is deliberate: the descriptor exists before anything has run, and inventing a prettier name here would mean the settings page and the CLI disagreed with the header the moment describe landed.
func ProtocolDescriptors ¶ added in v1.14.0
func ProtocolDescriptors(cfg *config.Config) []Descriptor
ProtocolDescriptors projects the configured external plugin instances onto descriptors, in configuration order.
A protocol plugin has no Go literal anywhere: its config entry is its manifest, and describe fills in the rest at run time. That is the whole of why there is no manifest file format — a config entry plus a describe answer is already every fact the host needs, and a manifest would be a third place for the same truth to live.
This is a pure function of configuration. It runs no plugin, resolves nothing on PATH, and reads nothing from disk, so it is safe anywhere config already is — including before the first frame.
func (Descriptor) HasPlacement ¶ added in v1.14.0
func (d Descriptor) HasPlacement(p Placement) bool
HasPlacement reports whether the plugin declares p.
func (Descriptor) HasSwitch ¶ added in v1.14.0
func (d Descriptor) HasSwitch() bool
HasSwitch reports whether the user can turn this plugin off at all.
func (Descriptor) IsEnabled ¶ added in v1.14.0
func (d Descriptor) IsEnabled(cfg *config.Config) bool
IsEnabled answers the descriptor's own switch against cfg. A descriptor with no Enabled func is always on: that is the honest answer for a plugin the user cannot turn off, and it keeps every caller free of nil checks.
func (Descriptor) IsPreferred ¶ added in v1.14.0
func (d Descriptor) IsPreferred(cfg *config.Config) bool
IsPreferred answers the user's own switch for this plugin, ignoring dependencies on other surfaces. The settings page renders this.
func (Descriptor) NeedsCommand ¶ added in v1.14.0
func (d Descriptor) NeedsCommand() bool
NeedsCommand reports whether enabling this plugin depends on a command outside Sidecar.
func (Descriptor) Source ¶ added in v1.14.0
func (d Descriptor) Source() string
Source reports the config section this descriptor was read from, or "" for an embedded plugin, whose descriptor is a Go literal.
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 FocusCycler ¶ added in v1.2.0
type FocusCycler interface {
// AtFocusCycleEnd reports that focus is on the last window of the surface's
// ring in the direction the cycle is about to move, so the next Tab would
// wrap. That is where a shell-owned stop belongs.
AtFocusCycleEnd(reverse bool) bool
// FocusCycleStart puts focus back on the window the cycle resumes at — the
// first going forward, the last going back — when the shell hands the
// keyboard back to the surface.
FocusCycleStart(reverse bool) tea.Cmd
}
FocusCycler is an optional capability for surfaces whose Tab cycle the shell may extend with a stop of its own. The notification centre is that stop: when it is open it joins the cycle between a surface's last window and its first, rather than running a second cycle beside it.
A surface that does not implement this keeps Tab exactly as it always had it; the shell then only offers Tab to the centre when nothing else has claimed the key in the focused context.
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 HostBind ¶ added in v1.12.0
type HostBind struct {
HostID string
Incarnation uint64
// ProjectKey is the owning host's inventory key: canonical(root) on that
// machine, a path-shaped string that is not a path here.
ProjectKey string
// WorktreeKey is the bound worktree's canonical path on that machine, or
// empty for the project's main checkout. It is the second half of the
// durable workspace id a plugin reads host content through.
WorktreeKey string
}
HostBind is the remote identity plugins are reinitialized against. The zero value is this machine, which is what Reinit passes.
type HostInventoryMsg ¶ added in v1.12.0
type HostInventoryMsg struct{}
HostInventoryMsg tells every bound plugin that the host catalog it reads from has changed. The app delivers it after overview.IsHostMessage so the sidebar refreshes on the same tick.
It is the only change signal that crosses a host boundary. internal/livewatch watches a filesystem and stays on the machine that owns the files, so a bound surface that wants to notice a change has this and an explicit refresh, and must not claim to be live beyond them.
type HostWorkspace ¶ added in v1.12.0
type HostWorkspace struct {
ID string
Kind string
Name string
Key string
Path string
TmuxName string
PaneID string
Provider string
Branch string
TaskID string
Live bool
IsMain bool
IsMissing bool
IsBare bool
IsDetached bool
IsLocked bool
IsPrunable bool
CreatedAt time.Time
}
HostWorkspace is one host-side shell or worktree as the bound workspace plugin lists it. Fields match workspaceinventory.Workspace enough to populate the sidebar and attach a live pane.
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 PaneFocusProvider ¶ added in v1.2.0
type PaneFocusProvider interface {
PaneFocusStops() []PaneFocusStop
PaneFocus() string
SetPaneFocus(id string) tea.Cmd
SetPaneFocusActive(active bool)
}
PaneFocusProvider is an optional capability for plugins whose own panes join an app-owned focus ring. Implementations project existing focus state rather than introducing a second focus model.
type PaneFocusRingHost ¶ added in v1.14.0
type PaneFocusRingHost interface {
PaneFocusProvider
// HostOwnsPaneFocusRing reports that the plugin binds no Tab of its own,
// so the app's ring is the whole of what the key does here.
HostOwnsPaneFocusRing() bool
}
PaneFocusRingHost is an optional capability for a plugin that hands Tab and Shift+Tab to the app even on a deck holding nothing but the plugin's own Primary leaf. The app cycles PaneFocusStops for it there, exactly as it does once a second leaf is open.
It is opt-in because Tab is not a spare key. Files, Git and Notes each route it themselves and do more with it than move focus — Notes saves the editor's buffer on the way out — so a host that took Tab from a Primary-only deck on the strength of two projected stops would quietly replace that. Nor can the keymap answer the question: several surfaces switch panes on a hard-coded tab that is registered nowhere, which internal/app already says out loud where the notification centre asks the same thing. So the plugin says so itself, and a plugin that says nothing keeps the key.
type PaneFocusStop ¶ added in v1.2.0
type PaneFocusStop struct {
ID string
}
PaneFocusStop names one directly focusable window inside a plugin. IDs are stable while visual order is expressed by the provider's returned slice.
type PendingWorkspaceActionProvider ¶ added in v1.0.0
type PendingWorkspaceSelection ¶ added in v0.94.0
type PendingWorkspaceSelection struct {
Kind WorkspaceSelectionKind
Key string
Path string
// Action asks the owning project surface to continue with one of its own
// established workflows after the exact identity is selected.
Action 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 Placement ¶ added in v1.14.0
type Placement string
Placement is where a plugin's content can show.
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. Local callers pass empty host identity; HostID/HostIncarnation/ProjectKey are cleared in the same lock so a remote bind cannot race Context() mutation.
func (*Registry) ReinitHost ¶ added in v1.12.0
ReinitHost is Reinit with host identity set in the same lock as WorkDir.
func (*Registry) Replace ¶ added in v1.0.3
Replace stores p at index i in the live registry. Plugins() returns a copy, so a caller that received a new value from Update must persist it here.
func (*Registry) SetHostIncarnation ¶ added in v1.12.0
SetHostIncarnation updates the bound host's serve identity without a Reinit. A bump while bound is a re-resolve, not a silent continuation.
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 ResizeDragReporter ¶ added in v1.2.0
type ResizeDragReporter interface {
// ResizeDragActive reports that a pane rail is currently being dragged.
ResizeDragActive() bool
}
ResizeDragReporter is implemented by a surface whose panes are resized by dragging a rail. While that drag is live the shell suppresses the floating tiers — toasts and status flashes — because every drag frame re-lays out the whole content region and a block composited on top of it both flickers and pays for a second full-screen composite on the frame that is already the expensive one (design 1g's "suppress while resizing", and the resize storm deferred from notifications Phase 1).
Nothing is lost by the suppression: the notification is already in the store, the centre and the header count, and it paints on the frame after the drop.
type SelfConstrainedView ¶ added in v1.12.0
type SelfConstrainedView interface {
ViewIsSelfConstrained() bool
}
SelfConstrainedView is an optional presentation capability for plugins whose View already returns the exact width and height requested by the app shell. Opting in lets the shell skip its defensive Lip Gloss clamp; View is still called on every frame so live content and pointer regions remain current.
Implementations must keep every rendered line within width, return no more than height lines, and preserve the padding that the shell's Width/Height wrapper would otherwise add. Plugins without this capability keep the defensive wrapper. The shell asks after View, so an implementation may use the dimensions it just rendered to decline the capability at a size where its normal layout floor exceeds the requested box.
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 WheelBoundaryConsumer ¶ added in v1.0.0
type WheelBoundaryConsumer interface {
WheelAtBoundary(tea.MouseWheelMsg) bool
}
WheelBoundaryConsumer is an optional fast-path for plugins with scrollable surfaces. Bubble Tea asks it before Update and View; returning true drops an inertia event that cannot move the surface under the pointer. Implementations must return false when they are not certain (for example, a terminal application that owns mouse reporting).
The message coordinates are local to the plugin content box, after Sidecar's header has been removed. Implementations may reset gesture-only coalescing state when they report a boundary, but must not change visible content.
type WorkspaceSelectionKind ¶ added in v0.94.0
type WorkspaceSelectionKind string
const ( WorkspaceSelectionWorktree WorkspaceSelectionKind = "worktree" WorkspaceSelectionShell WorkspaceSelectionKind = "shell" )