plugins

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 27 Imported by: 0 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 installs plugins, keeps the consent that pins each one, and hands their contributions to the places Lectern already has: the agent catalog, project workflows, agent MCP config, lifecycle hooks and the UI. The package format itself is internal/pluginpkg; docs/plugins.md is the user-facing description.

The rule everything here serves: nothing from a plugin is used unless a person consented to exactly the content that is on disk. Content lives in <Dir>/store/<sha256>/, is re-hashed on every load and before every hook run, and a mismatch stops the plugin until someone trusts it again.

Index

Constants

View Source
const (
	StatusActive       = "active"        // consented, verified, enabled
	StatusDisabled     = "disabled"      // consented and verified, switched off
	StatusModified     = "modified"      // files on disk differ from the consented hash
	StatusNeedsConsent = "needs_consent" // content changed through an update not yet consented
	StatusMissing      = "missing"       // the content store lost its files
)

Status values of an installed plugin.

View Source
const ClaudeMarketplace = ".claude-plugin/marketplace.json"

ClaudeMarketplace is Claude Code's marketplace file, read as a source too.

View Source
const IndexFile = "lectern-plugins.yaml"

IndexFile is the marketplace file at a source repository's root.

Variables

View Source
var AllowLoopbackHTTP = false

AllowLoopbackHTTP admits http:// git URLs to this machine. Only tests set it (they serve repositories with git-http-backend); nothing in the binary or its configuration can.

View Source
var ErrUnknownPreview = errors.New("that preview has expired; preview the plugin again")

ErrUnknownPreview means the preview expired or never existed.

Functions

func CheckGitURL

func CheckGitURL(raw string) error

CheckGitURL admits https, ssh and scp-like git URLs and file:// paths. git's ext:: and fd:: transports run programs, and a plain-http fetch could be changed in flight.

func Summary

func Summary(man *pluginpkg.Manifest) map[string]int

Summary counts contributions by kind, for list views.

Types

type AgentPreset

type AgentPreset struct {
	sessions.CatalogPreset
	Plugin string `json:"plugin"`
}

AgentPreset is a catalog entry and the plugin it came from.

type ConsentError

type ConsentError struct{ Msg string }

ConsentError is a consent that does not match what the preview showed.

func (*ConsentError) Error

func (e *ConsentError) Error() string

type Event

type Event struct {
	Event     string  `json:"event"`
	Plugin    string  `json:"plugin"`
	Time      float64 `json:"time"`
	ProjectID int64   `json:"project_id,omitempty"`
	Data      any     `json:"data"`
}

Event is what a hook reads on stdin.

type HookResult

type HookResult struct {
	OK      bool   `json:"ok"`
	Message string `json:"message,omitempty"`
	Notify  string `json:"notify,omitempty"`
}

HookResult is what a hook prints: one JSON object. Output that is not JSON becomes Message (its first line), with OK from the exit status.

type Hooks

type Hooks struct {
	M      *Manager
	Bus    *bus.Bus
	Reg    *executor.Registry
	Notify func(title, body, url string)
	// RunHost is the host command runner; tests replace it with a stand-in.
	RunHost func(ctx context.Context, dir string, argv, env []string, stdin []byte) (stdout []byte, err error)
	// contains filtered or unexported fields
}

Hooks turns Lectern's own events into plugin hook runs. It reads the board bus — task, session, approval and CI changes already flow through it as typed values — and polls for new usage-limit holds, which have no bus event of their own. It never blocks a publisher: the bus drops for a full subscriber, and each plugin's hooks run one at a time on its own queue.

func (*Hooks) Observe

func (h *Hooks) Observe(kind string, data any)

Observe maps one bus message to lifecycle events. Exposed so tests can drive it without a bus.

func (*Hooks) Start

func (h *Hooks) Start(ctx context.Context)

Start subscribes to the bus and begins watching for limit holds.

func (*Hooks) Wait

func (h *Hooks) Wait()

Wait blocks until every queued hook has run (tests).

type Index

type Index struct {
	Name    string       `json:"name" yaml:"name"`
	Plugins []IndexEntry `json:"plugins" yaml:"plugins"`
	// Commit is the marketplace commit the list was read at.
	Commit string `json:"commit" yaml:"-"`
}

Index is a marketplace's list of plugins.

type IndexEntry

type IndexEntry struct {
	ID          string `json:"id" yaml:"id"`
	Name        string `json:"name,omitempty" yaml:"name,omitempty"`
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	Version     string `json:"version,omitempty" yaml:"version,omitempty"`
	Source      string `json:"source" yaml:"source"`
	Commit      string `json:"commit" yaml:"commit"`
	Path        string `json:"path,omitempty" yaml:"path,omitempty"`
}

IndexEntry is one listed plugin, pinned to an exact commit.

type Listing

type Listing struct {
	IndexEntry
	Index     string `json:"index"`
	Installed string `json:"installed,omitempty"` // installed status, if it is
}

Listing is one plugin available from a source.

type Manager

type Manager struct {
	DB  *store.DB
	Dir string
	Log *slog.Logger
	// Version is this Lectern's version, checked against min_lectern.
	Version string
	// contains filtered or unexported fields
}

Manager owns installed plugins.

func New

func New(db *store.DB, dir, version string, log *slog.Logger) *Manager

New builds a manager over dir (normally lectern-plugins beside the database) and loads what is installed.

func (*Manager) ActiveFor

func (m *Manager) ActiveFor(projectID int64) []*Plugin

ActiveFor lists the active plugins that apply to a project (0 = global).

func (*Manager) AddSource

func (m *Manager) AddSource(ctx context.Context, name, url, ref string) (*Index, error)

AddSource registers a marketplace after reading its index once, so a broken URL is refused rather than saved.

func (*Manager) AgentPresets

func (m *Manager) AgentPresets() []AgentPreset

AgentPresets lists catalog entries from active installed plugins. The bundled catalog is sessions.Catalog(); a disabled bundled catalog plugin hides it (Catalog reports whether it is active).

func (*Manager) AllWorkflows

func (m *Manager) AllWorkflows() []workflows.Source

AllWorkflows lists every plugin's workflows whatever its state, so an attachment made while a plugin was on can still be found and turned off.

func (*Manager) BundledCatalogActive

func (m *Manager) BundledCatalogActive() bool

BundledCatalogActive reports whether the bundled agent catalog plugin is on.

func (*Manager) Consent

func (m *Manager) Consent(hash string, accept []string, by string, projectIDs []int64) (*Plugin, error)

Consent installs, updates or re-trusts the previewed plugin. accept must be exactly the capability list the preview showed: a client cannot consent to one set and install another. by names the person.

func (*Manager) Get

func (m *Manager) Get(id string) (*Plugin, bool)

Get returns one plugin.

func (*Manager) List

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

List returns every plugin, bundled first, then by id.

func (*Manager) MCPServerNames

func (m *Manager) MCPServerNames(projectID int64) []string

MCPServerNames lists the servers active plugins would add to a project, without staging anything — for the launch preview.

func (*Manager) MCPServers

func (m *Manager) MCPServers(ctx context.Context, ex executor.Executor, targetID, projectID int64, taken map[string]bool) (map[string]any, error)

MCPServers returns the MCP servers active plugins add to a launch on a project's target (0: no project), keyed by server name. A server that refers to ${LECTERN_PLUGIN_ROOT} gets the plugin copied onto the target first. taken holds names the project already uses: the project's own server wins, and between two plugins the first by id does.

func (*Manager) Preview

func (m *Manager) Preview(ctx context.Context, src Source) (*Preview, error)

Preview fetches a plugin and validates it without installing anything. The files go into the content store (they are addressed by their hash, so nothing refers to them until a consent does).

func (*Manager) Prune

func (m *Manager) Prune()

Prune deletes content-store directories no installed plugin refers to.

func (*Manager) Reload

func (m *Manager) Reload()

Reload re-reads every plugin from the database and its content store, re-hashing each one.

func (*Manager) Remove

func (m *Manager) Remove(id string) error

Remove uninstalls a plugin and forgets its consent and secrets. Its files stay in the content store until Prune, since another install may share them.

func (*Manager) RemoveSource

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

RemoveSource forgets a marketplace. Plugins installed from it stay.

func (*Manager) SandboxProviderFile

func (m *Manager) SandboxProviderFile(ref string) ([]byte, error)

SandboxProviderFile returns a plugin sandbox provider's hooks file, for a machine whose script provider names "plugin:<id>/<provider>". The bytes are the consented ones, so no separate trust is needed.

func (*Manager) Search

func (m *Manager) Search(ctx context.Context, query string, refresh bool) ([]Listing, []string, error)

Search lists plugins from every source whose id, name or description contains query. refresh re-reads each index.

func (*Manager) SetEnabled

func (m *Manager) SetEnabled(id string, enabled *bool, scope []int64) (*Plugin, error)

SetEnabled switches a plugin on or off; scope, when non-nil, sets the projects it applies to (empty = everywhere).

func (*Manager) SetSecrets

func (m *Manager) SetSecrets(id string, values map[string]string) error

SetSecrets stores values for the plugin's declared secrets. An empty value removes one. Undeclared names are refused.

func (*Manager) Sources

func (m *Manager) Sources() ([]map[string]any, error)

Sources lists marketplaces with when their index was read.

func (*Manager) StageOnTarget

func (m *Manager) StageOnTarget(ctx context.Context, ex executor.Executor, targetID int64, p *Plugin) (string, error)

StageOnTarget copies an active plugin onto a target, into ~/.lectern/plugins/<id>/<hash>, and returns that path. The copy is verified file by file against the consented content, never replaced.

func (*Manager) TrustPreview

func (m *Manager) TrustPreview(id string) (*Preview, error)

TrustPreview reads what is on disk now for a modified plugin and previews it, so a person can see what changed before trusting it.

func (*Manager) UI

func (m *Manager) UI() UIContributions

UI collects the browser-side contributions of every active plugin. Ids are "<plugin>/<id>", so two plugins cannot collide.

func (*Manager) UpdatePreview

func (m *Manager) UpdatePreview(ctx context.Context, id, ref string) (*Preview, error)

UpdatePreview fetches the installed plugin's source again: the same path, the same git ref's current commit, or the commit its index lists now.

func (*Manager) Verify

func (m *Manager) Verify(p *Plugin) bool

Verify re-hashes an active plugin's files. Hooks call it before every run, so a file changed after load is caught before it executes.

func (*Manager) Workflows

func (m *Manager) Workflows(projectID int64) []workflows.Source

Workflows lists the workflows and skills active plugins offer a project.

type Plugin

type Plugin struct {
	ID         string             `json:"id"`
	Bundled    bool               `json:"bundled"`
	Status     string             `json:"status"`
	Problem    string             `json:"problem,omitempty"`
	ProjectIDs []int64            `json:"project_ids"`
	Row        *store.Plugin      `json:"install,omitempty"`
	Pkg        *pluginpkg.Package `json:"-"`
	// Manifest is the consented manifest, or nil when none can be read.
	Manifest *pluginpkg.Manifest `json:"manifest,omitempty"`
}

Plugin is an installed plugin as the rest of Lectern sees it.

func (*Plugin) Active

func (p *Plugin) Active() bool

Active reports whether contributions from p may be used at all.

func (*Plugin) InScope

func (p *Plugin) InScope(projectID int64) bool

InScope reports whether p applies to a project. Project 0 asks about contributions that are global by nature (agents, themes, palette).

func (*Plugin) SecretNames

func (p *Plugin) SecretNames() []string

SecretNames lists which declared secrets have a value.

type Preview

type Preview struct {
	Hash          string                 `json:"hash"`
	Source        Source                 `json:"source"`
	Commit        string                 `json:"commit,omitempty"`
	Tree          string                 `json:"tree,omitempty"`
	Format        string                 `json:"format"`
	Skipped       []string               `json:"skipped,omitempty"`
	Manifest      *pluginpkg.Manifest    `json:"manifest"`
	Capabilities  []pluginpkg.Capability `json:"capabilities"`
	Accept        []string               `json:"accept"`
	Contributions map[string]int         `json:"contributions"`
	// Update fields: the installed version and what the new one adds.
	Installed   *store.Plugin `json:"installed,omitempty"`
	FromVersion string        `json:"from_version,omitempty"`
	Grown       []string      `json:"grown,omitempty"`
	Unchanged   bool          `json:"unchanged,omitempty"`
	// contains filtered or unexported fields
}

Preview is what a person reviews before consenting: the package, what it may do, and for an update what changed. Nothing of it runs.

type Source

type Source struct {
	Kind   string `json:"kind"` // path | git | index
	Path   string `json:"path,omitempty"`
	URL    string `json:"url,omitempty"`
	Ref    string `json:"ref,omitempty"`
	Commit string `json:"commit,omitempty"`
	Subdir string `json:"subdir,omitempty"`
	Index  string `json:"index,omitempty"`
	ID     string `json:"id,omitempty"`
}

Source says where a plugin comes from. Exactly one of Path or URL is set; Index names the marketplace an id was found in.

type UIContributions

type UIContributions struct {
	QuickCommands   []UIQuickCommand   `json:"quick_commands"`
	Themes          []UITheme          `json:"themes"`
	PaletteCommands []UIPaletteCommand `json:"palette_commands"`
}

UIContributions are what the browser shows: quick commands (with the projects they apply to), themes and palette commands.

type UIPaletteCommand

type UIPaletteCommand struct {
	ID     string `json:"id"`
	Plugin string `json:"plugin"`
	Title  string `json:"title"`
	Href   string `json:"href"`
}

type UIQuickCommand

type UIQuickCommand struct {
	ID         string  `json:"id"`
	Plugin     string  `json:"plugin"`
	Label      string  `json:"label"`
	Text       string  `json:"text"`
	Enter      bool    `json:"enter"`
	ProjectIDs []int64 `json:"project_ids"`
}

type UITheme

type UITheme struct {
	ID     string            `json:"id"`
	Plugin string            `json:"plugin"`
	Name   string            `json:"name"`
	Accent string            `json:"accent,omitempty"`
	Dark   map[string]string `json:"dark,omitempty"`
	Light  map[string]string `json:"light,omitempty"`
}

Jump to

Keyboard shortcuts

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