plugins

package
v0.68.2 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: AGPL-3.0 Imports: 17 Imported by: ? 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 plugins defines the shared plugin-facing contracts for Stella's unified plugin host.

Index

Constants

View Source
const (
	CapabilityChannel   = "channel"
	CapabilityRuntime   = "runtime"
	CapabilityLifecycle = "lifecycle"
	CapabilityConfig    = "config"
	CapabilityStatus    = "status"
	CapabilityTool      = "tool"
	CapabilityPrompt    = "prompt"
	CapabilityHook      = "hook"
)
View Source
const (
	StateScopeGlobal  = "global"
	StateScopeUser    = "user"
	StateScopeAgent   = "agent"
	StateScopeSession = "session"
)

Variables

This section is empty.

Functions

func Names

func Names() []string

Names returns all plugin IDs from the process-wide default catalog in sorted order.

func NewBotManagedRuntime

func NewBotManagedRuntime[T any](deps BotRuntimeDeps[T]) *botManagedRuntime[T]

func Register

func Register(id string, plugin Plugin)

Register stores a plugin in the process-wide default catalog.

func RegisterManagedChannelPlugin

func RegisterManagedChannelPlugin(host Host, reg ManagedChannelPluginRegistration)

func ResolveBinary

func ResolveBinary(binDir, name string) string

ResolveBinary returns the path to a named binary, checking binDir first, then $PATH. Returns empty string if not found. Plugins receive binDir via their context (e.g. HookContext.ToolsBinDir).

Types

type AdminContext

type AdminContext struct {
	Platform Platform
	State    PluginState
}

AdminContext is the narrow build context for plugin admin/status behavior.

type AdminSpec

type AdminSpec struct {
	PluginID      string
	DefaultConfig func() map[string]any
	Schema        map[string]any
	Validate      func(raw map[string]any) error
	Redact        func(raw map[string]any) map[string]any
	Status        func(ctx context.Context, build AdminContext) (any, error)
}

AdminSpec declares plugin-owned admin behavior: config defaults, schema, validation, redaction, and status.

func (AdminSpec) Defaults

func (r AdminSpec) Defaults() map[string]any

Defaults returns a defensive copy of the registered default config.

func (AdminSpec) Redacted

func (r AdminSpec) Redacted(raw map[string]any) map[string]any

Redacted returns a redacted copy of raw config, or a cloned copy when no redactor is set.

func (AdminSpec) SchemaDefinition

func (r AdminSpec) SchemaDefinition() map[string]any

SchemaDefinition returns a defensive deep copy of the registered config schema.

type AfterToolResult

type AfterToolResult struct {
	Result  *string `json:"result,omitempty"`
	IsError *bool   `json:"is_error,omitempty"`
}

AfterToolResult is the mutable post-execution output from tool lifecycle plugins.

type AfterToolResultContext

type AfterToolResultContext struct {
	Platform   Platform
	State      PluginState
	SessionID  string
	Channel    string
	UserID     string
	AgentID    string
	ToolName   string
	ToolCallID string
	Arguments  map[string]any
	Result     string
	IsError    bool
	Duration   time.Duration
}

AfterToolResultContext is the narrow post-tool lifecycle context exposed to plugins.

type AfterToolResultSpec

type AfterToolResultSpec struct {
	PluginID string
	Name     string
	Order    int
	Required bool
	Run      func(ctx context.Context, build AfterToolResultContext) (AfterToolResult, error)
}

AfterToolResultSpec declares a post-tool lifecycle hook owned by a plugin.

type Auth

type Auth interface {
	GetUser(ctx context.Context, userID string) (UserInfo, error)
	ListUserIdentities(ctx context.Context, userID string) ([]LinkedIdentity, error)
	GetIdentityByPlatform(ctx context.Context, platform, externalID string) (LinkedIdentity, error)
}

Auth exposes narrow user and identity lookups without leaking auth internals.

type BeforeRunContext

type BeforeRunContext struct {
	Platform     Platform
	State        PluginState
	SessionID    string
	Channel      string
	UserID       string
	AgentID      string
	Model        string
	MessageText  string
	SystemPrompt string
	History      []ai.Message
}

BeforeRunContext is the narrow per-run lifecycle context exposed to plugins.

type BeforeRunResult

type BeforeRunResult struct {
	SystemPrompt string `json:"system_prompt,omitempty"`
}

BeforeRunResult is the mutable per-run output from lifecycle plugins.

type BeforeRunSpec

type BeforeRunSpec struct {
	PluginID string
	Name     string
	Order    int
	Required bool
	Run      func(ctx context.Context, build BeforeRunContext) (BeforeRunResult, error)
}

BeforeRunSpec declares a dynamic per-run lifecycle hook owned by a plugin.

type BeforeToolCallContext

type BeforeToolCallContext struct {
	Platform   Platform
	State      PluginState
	SessionID  string
	Channel    string
	UserID     string
	AgentID    string
	ToolName   string
	ToolCallID string
	Arguments  map[string]any
}

BeforeToolCallContext is the narrow per-tool-call lifecycle context exposed to plugins.

type BeforeToolCallResult

type BeforeToolCallResult struct {
	Arguments    map[string]any `json:"arguments,omitempty"`
	Block        bool           `json:"block,omitempty"`
	BlockMessage string         `json:"block_message,omitempty"`
}

BeforeToolCallResult is the mutable pre-execution output from tool lifecycle plugins.

type BeforeToolCallSpec

type BeforeToolCallSpec struct {
	PluginID string
	Name     string
	Order    int
	Required bool
	Run      func(ctx context.Context, build BeforeToolCallContext) (BeforeToolCallResult, error)
}

BeforeToolCallSpec declares a pre-tool lifecycle hook owned by a plugin.

type BotRuntimeDeps

type BotRuntimeDeps[T any] struct {
	Parent          context.Context
	Handler         pkgchannel.Handler
	Notifier        ChannelRegistry
	Log             *slog.Logger
	Now             func() time.Time
	Platform        string
	DecodeConfig    func(map[string]any) (T, error)
	ConfigureConfig func(T, PluginState) T
	ValidateConfig  func(T) string
	NewChannel      func(T, pkgchannel.Handler) (pkgchannel.Channel, error)
	Snapshot        func(time.Time, RuntimeState, string, T) RuntimeStatus
	// WrapHandler, when set, wraps the handler passed to NewChannel so its
	// context-bearing agent-facing methods run on the runtime's operation context
	// (a child of Parent that outlives the poll context) rather than the poller's
	// Start context. This is what lets Quiesce stop polling without cancelling work
	// already accepted. When nil, the handler is passed through unchanged.
	WrapHandler func(pkgchannel.Handler, context.Context) pkgchannel.Handler
}

type BundledSkillSpec

type BundledSkillSpec struct {
	PluginID string
	Name     string
	Sync     func(ctx context.Context, build BundledSkillSyncContext) error
}

BundledSkillSpec declares a builtin system skill owned by a plugin and the build-time sync function that generates or updates it.

type BundledSkillSyncContext

type BundledSkillSyncContext struct {
	WorkDir string
	GOOS    string
	GOARCH  string
	Params  map[string]string
}

BundledSkillSyncContext is the build-time context for syncing a bundled skill into resources.

type Capability added in v0.60.0

type Capability string

Capability identifies a single host service exposed through the plugin-scoped Platform. A plugin must DECLARE the capabilities it needs in PluginInfo.RequiredCapabilities; the host grants only those, and a Platform accessor for an undeclared capability returns nil (fail-closed). This is a distinct, typed vocabulary from the derived trait strings above (which report what a plugin registered, not what host ports it may reach).

const (
	CapabilityLogger          Capability = "logger"
	CapabilityConfigStore     Capability = "config_store"
	CapabilityStateStore      Capability = "state_store"
	CapabilityNotifier        Capability = "notifier"
	CapabilityAuth            Capability = "auth"
	CapabilityRuntimeLookup   Capability = "runtime_lookup"
	CapabilityChannelPlatform Capability = "channel_platform"
)

type Catalog

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

Catalog stores plugins by plugin ID.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog creates an empty plugin catalog.

func (*Catalog) Get

func (c *Catalog) Get(id string) (Plugin, bool)

Get resolves a plugin by ID.

func (*Catalog) Names

func (c *Catalog) Names() []string

Names returns all registered plugin IDs in sorted order.

func (*Catalog) Register

func (c *Catalog) Register(id string, plugin Plugin)

Register stores a plugin by canonical plugin ID. It panics for invalid registrations because plugin init-time registration is a programmer error.

type ChannelContext

type ChannelContext struct {
	Platform Platform
	State    PluginState
	Handler  channel.Handler
}

ChannelContext is the narrow build context for channel capabilities.

type ChannelPlatform

type ChannelPlatform interface {
	ParentContext() context.Context
	Handler() pkgchannel.Handler
	Notifications() ChannelRegistry
}

ChannelPlatform exposes the narrow platform services needed by managed channel runtimes.

type ChannelRegistry

type ChannelRegistry interface {
	Register(pkgchannel.Channel)
	Unregister(name string)
}

ChannelRegistry exposes channel registration needed by managed channel runtimes.

type ChannelSpec

type ChannelSpec struct {
	PluginID   string
	Name       string
	Configured func(raw map[string]any) bool
	Build      func(ctx ChannelContext) (channel.Channel, error)
}

ChannelSpec declares a channel capability owned by a plugin.

type ConfigStore

type ConfigStore interface {
	Get(ctx context.Context) (PluginState, error)
	Set(ctx context.Context, config map[string]any) error
}

ConfigStore exposes plugin-owned config persistence through a narrow interface.

type HookContext

type HookContext struct {
	Platform    Platform
	State       PluginState
	ToolsBinDir string
}

HookContext is the narrow build context for hook capabilities.

type HookSpec

type HookSpec struct {
	PluginID string
	Name     string
	Build    func(ctx HookContext) (hooks.HookPlugin, error)
}

HookSpec declares a hook capability owned by a plugin.

type Host

type Host interface {
	SetInfo(PluginInfo)
	AddAdmin(AdminSpec)
	AddTool(ToolSpec)
	AddChannel(ChannelSpec)
	AddHook(HookSpec)
	AddRuntime(RuntimeSpec)
	AddPromptInventory(PromptInventorySpec)
	AddSystemPrompt(SystemPromptSpec)
	AddBeforeRun(BeforeRunSpec)
	AddBeforeToolCall(BeforeToolCallSpec)
	AddAfterToolResult(AfterToolResultSpec)
	AddSessionEnv(SessionEnvSpec)
	AddBundledSkill(BundledSkillSpec)
}

Host is the flat registration surface exposed to plugins. Platform services are provided only through capability-specific contexts.

type KnowledgeEntry

type KnowledgeEntry struct {
	ID            string
	Name          string
	Description   string
	Content       string
	KnowledgeType KnowledgeType
	Status        string // draft | active | deprecated
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

KnowledgeEntry is a subject=world fact projected into the Knowledge prompt section. It is not a callable skill and is not stored in the skills table.

type KnowledgeType

type KnowledgeType string

KnowledgeType classifies a facts-backed knowledge entry rendered in prompts.

const (
	KnowledgeTypeFact    KnowledgeType = "fact"    // durable project/domain fact
	KnowledgeTypeContext KnowledgeType = "context" // time-bound background info
)

type LinkedIdentity

type LinkedIdentity struct {
	ID         string
	UserID     string
	Platform   string
	ExternalID string
	Name       string
	LinkedAt   time.Time
}

LinkedIdentity is the host-owned linked identity record exposed to plugins.

type ManagedChannelPluginRegistration

type ManagedChannelPluginRegistration struct {
	PluginID       string
	RuntimeName    string
	Meta           PluginInfo
	Info           PluginInfo
	DefaultConfig  func() map[string]any
	Schema         map[string]any
	Validate       func(raw map[string]any) error
	Redact         func(raw map[string]any) map[string]any
	Configured     func(raw map[string]any) bool
	RuntimeFactory func(rc RuntimeContext) (Runtime, error)
}

type Notifier

type Notifier interface {
	Notify(ctx context.Context, n pkgchannel.Notification) error
	NotifyUser(ctx context.Context, userID string, n pkgchannel.Notification) error
}

Notifier exposes user-visible notification delivery through the host.

type Platform

type Platform interface {
	Logger() *slog.Logger
	ConfigStore() ConfigStore
	StateStore() StateStore
	Notifier() Notifier
	Auth() Auth
	RuntimeLookup() RuntimeLookup
	ChannelPlatform() ChannelPlatform
}

Platform is the plugin-scoped service surface available during build/runtime work. It is capability-gated: each accessor returns its scoped service only if the plugin declared the matching Capability in PluginInfo.RequiredCapabilities. An accessor for an undeclared capability returns nil (fail-closed) — there is no ambient, all-capabilities Platform.

type Plugin

type Plugin interface {
	Register(host Host)
}

Plugin is the ownership unit in the unified plugin host. A plugin may register multiple capabilities against the provided host.

func Get

func Get(id string) (Plugin, bool)

Get resolves a plugin from the process-wide default catalog.

type PluginFunc

type PluginFunc func(host Host)

PluginFunc adapts a function to the Plugin interface.

func (PluginFunc) Register

func (f PluginFunc) Register(host Host)

Register implements Plugin.

type PluginInfo

type PluginInfo struct {
	ID           string   `json:"id"`
	Kind         string   `json:"kind,omitempty"`
	Name         string   `json:"name,omitempty"`
	DisplayName  string   `json:"display_name,omitempty"`
	Description  string   `json:"description,omitempty"`
	Managed      bool     `json:"managed,omitempty"`
	AdminVisible bool     `json:"admin_visible,omitempty"`
	HasConfig    bool     `json:"has_config,omitempty"`
	HasStatus    bool     `json:"has_status,omitempty"`
	Capabilities []string `json:"capabilities,omitempty"`
	// RequiredCapabilities is the set of host Platform ports this plugin needs.
	// The host grants only these; the plugin-scoped Platform fails closed (nil)
	// on any undeclared capability. Distinct from the derived Capabilities trait.
	RequiredCapabilities []Capability `json:"required_capabilities,omitempty"`
}

PluginInfo is the host discovery metadata registered by a plugin. Capability traits are derived from actual registrations rather than declared here.

func (PluginInfo) Clone

func (m PluginInfo) Clone() PluginInfo

Clone returns a shallow copy.

func (PluginInfo) RequiresCapability added in v0.60.0

func (m PluginInfo) RequiresCapability(c Capability) bool

RequiresCapability reports whether the plugin declared the given capability.

type PluginState

type PluginState struct {
	ID      string         `json:"id"`
	Enabled bool           `json:"enabled"`
	Config  map[string]any `json:"config,omitempty"`
}

PluginState is the canonical plugin-level desired state.

func (PluginState) Clone

func (s PluginState) Clone() PluginState

Clone returns a shallow copy with an independent config map.

type PromptInventoryContext

type PromptInventoryContext struct {
	Platform Platform
	State    PluginState
}

PromptInventoryContext is the narrow build context for prompt inventory contributions.

type PromptInventorySpec

type PromptInventorySpec struct {
	PluginID string
	Name     string
	GetTools func(ctx context.Context, build PromptInventoryContext) ([]PromptToolInfo, error)
}

PromptInventorySpec declares structured tool inventory contribution.

type PromptToolInfo

type PromptToolInfo struct {
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
}

PromptToolInfo is a structured tool inventory item contributed to prompt building.

func (PromptToolInfo) Clone

func (i PromptToolInfo) Clone() PromptToolInfo

Clone returns a shallow copy with independent metadata.

type RegisteredPlugin

type RegisteredPlugin struct {
	Info         PluginInfo
	Kind         string
	Name         string
	HasConfig    bool
	HasStatus    bool
	Capabilities []string
	State        PluginState
	Persisted    bool
	PersistedID  string
}

RegisteredPlugin is the merged discovery view of registered metadata and persisted state.

func (RegisteredPlugin) Clone

Clone returns a shallow copy with independent nested maps/slices.

func (RegisteredPlugin) SortedCapabilities

func (p RegisteredPlugin) SortedCapabilities() []string

SortedCapabilities returns a normalized, sorted copy of the capability list.

type Runtime

type Runtime interface {
	Apply(ctx context.Context, desired PluginState) error
	Start(ctx context.Context, desired PluginState) error
	Reconcile(ctx context.Context, desired PluginState) error
	Stop(ctx context.Context) error
	Snapshot(ctx context.Context) (RuntimeStatus, error)
	Status(ctx context.Context) (RuntimeStatus, error)
}

Runtime is implemented by plugin-owned long-lived runtime services.

type RuntimeContext

type RuntimeContext struct {
	Platform Platform
	State    PluginState
}

RuntimeContext is the narrow construction context for runtime capabilities.

type RuntimeHandle

type RuntimeHandle interface {
	Snapshot(ctx context.Context) (RuntimeStatus, error)
	Status(ctx context.Context) (RuntimeStatus, error)
}

RuntimeHandle exposes status access to a running runtime.

type RuntimeLookup

type RuntimeLookup interface {
	Get(ctx context.Context, runtimeID string, runtimeName string) (RuntimeHandle, bool)
	Lookup(ctx context.Context, runtimeID string, runtimeName string) (RuntimeHandle, bool)
}

RuntimeLookup resolves running runtime handles by plugin and runtime capability ID.

type RuntimeSpec

type RuntimeSpec struct {
	PluginID string
	Name     string
	Build    func(ctx RuntimeContext) (Runtime, error)
}

RuntimeSpec declares a managed runtime capability owned by a plugin.

type RuntimeState

type RuntimeState string

RuntimeState is the shared high-level runtime state used by host orchestration.

const (
	RuntimeStateUnknown RuntimeState = "unknown"
	RuntimeStateStopped RuntimeState = "stopped"
	RuntimeStateRunning RuntimeState = "running"
	RuntimeStateError   RuntimeState = "error"
)

type RuntimeStatus

type RuntimeStatus struct {
	State     RuntimeState   `json:"state"`
	Message   string         `json:"message,omitempty"`
	UpdatedAt time.Time      `json:"updated_at"`
	Metadata  map[string]any `json:"metadata,omitempty"`
}

RuntimeStatus is the minimal shared runtime status envelope.

func (RuntimeStatus) Clone

func (s RuntimeStatus) Clone() RuntimeStatus

Clone returns a shallow copy with independent metadata.

type SessionEnvSource

type SessionEnvSource string

SessionEnvSource identifies how a session env var is produced.

const (
	SessionEnvSourceStatic SessionEnvSource = "static"
)

type SessionEnvSpec

type SessionEnvSpec struct {
	PluginID        string
	EnvVar          string
	Source          SessionEnvSource
	Value           string // used only when Source == SessionEnvSourceStatic
	Required        bool   // if true, session creation fails when this env cannot be resolved
	OAuthProviderID string // set when source is oauth.*; identifies which provider bundle to load
}

SessionEnvSpec declares one env var contributed to sandbox sessions. Sources are metadata-driven so plugins can declare what they need without depending on runner-owned services such as TokenManager.

type SessionPluginView

type SessionPluginView struct {
	RegisteredPluginIDs []string
	EnabledPluginIDs    []string
	SessionEnvSpecs     []SessionEnvSpec
}

SessionPluginView is the runner-facing view of enabled plugin-owned session setup plus the plugin visibility state prompt builders may need.

type StateScope

type StateScope struct {
	Kind string
	ID   string
}

StateScope identifies the owner of a stored plugin state entry.

func (StateScope) Normalize

func (s StateScope) Normalize() StateScope

Normalize returns the canonical scope shape used by the host store.

type StateStore

type StateStore interface {
	Get(ctx context.Context, scope StateScope, key string) (map[string]any, bool, error)
	Set(ctx context.Context, scope StateScope, key string, value map[string]any) error
	Delete(ctx context.Context, scope StateScope, key string) error
}

StateStore exposes host-owned plugin persistence without leaking DB packages.

type SystemPromptContext

type SystemPromptContext struct {
	Platform Platform
	State    PluginState
	UserID   string
	AgentID  string
	// RegisteredPluginIDs and EnabledPluginIDs describe plugin visibility for
	// prompt builders that need plugin-state-aware output such as skill catalogs.
	RegisteredPluginIDs []string
	EnabledPluginIDs    []string
	// DisabledSkillRefs is copied from the Agent runner snapshot. Prompt and
	// Skills-tool reads receive the same value for the life of that runner.
	DisabledSkillRefs []string
}

SystemPromptContext is the shared build context for prompt contributions. It carries logical identity and immutable plugin/policy state only; filesystem access belongs to the active Session or to an explicitly captured snapshot.

type SystemPromptSection

type SystemPromptSection struct {
	Title   string `json:"title"`
	Content string `json:"content"`
	Inline  bool   `json:"inline,omitempty"`
}

SystemPromptSection is a structured prompt contribution from a plugin. Inline sections render as bullet items; non-inline sections render as full heading blocks in the system prompt.

type SystemPromptSpec

type SystemPromptSpec struct {
	PluginID string
	Name     string
	Required bool
	Build    func(ctx context.Context, build SystemPromptContext) (SystemPromptSection, error)
}

SystemPromptSpec declares prompt contribution owned by a plugin.

type ToolBuildContext added in v0.33.0

type ToolBuildContext struct {
	Runtime sandbox.Session
}

ToolBuildContext carries the active runtime for per-session tool construction.

type ToolContext

type ToolContext struct {
	Platform Platform
	Runtime  sandbox.Session
}

ToolContext is the narrow build context for tool capabilities.

type ToolSpec

type ToolSpec struct {
	PluginID    string
	Name        string
	Description string
	Required    bool
	Build       func(ctx ToolContext) (tools.Tool, error)
}

ToolSpec declares a tool capability owned by a plugin.

type UserInfo

type UserInfo struct {
	ID               string
	Username         string
	Role             string
	IsActive         bool
	DefaultAgentID   string
	NotifyIdentityID *string
	CreatedAt        time.Time
	UpdatedAt        time.Time
}

UserInfo is the host-owned user record exposed to plugins.

Jump to

Keyboard shortcuts

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