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
- Variables
- func CheckGitURL(raw string) error
- func Summary(man *pluginpkg.Manifest) map[string]int
- type AgentPreset
- type ConsentError
- type Event
- type HookResult
- type Hooks
- type Index
- type IndexEntry
- type Listing
- type Manager
- func (m *Manager) ActiveFor(projectID int64) []*Plugin
- func (m *Manager) AddSource(ctx context.Context, name, url, ref string) (*Index, error)
- func (m *Manager) AgentPresets() []AgentPreset
- func (m *Manager) AllWorkflows() []workflows.Source
- func (m *Manager) BundledCatalogActive() bool
- func (m *Manager) Consent(hash string, accept []string, by string, projectIDs []int64) (*Plugin, error)
- func (m *Manager) Get(id string) (*Plugin, bool)
- func (m *Manager) List() []*Plugin
- func (m *Manager) MCPServerNames(projectID int64) []string
- func (m *Manager) MCPServers(ctx context.Context, ex executor.Executor, targetID, projectID int64, ...) (map[string]any, error)
- func (m *Manager) Mods(surface string) []UIMod
- func (m *Manager) Preview(ctx context.Context, src Source) (*Preview, error)
- func (m *Manager) Prune()
- func (m *Manager) Reload()
- func (m *Manager) Remove(id string) error
- func (m *Manager) RemoveSource(name string) error
- func (m *Manager) SandboxProviderFile(ref string) ([]byte, error)
- func (m *Manager) Search(ctx context.Context, query string, refresh bool) ([]Listing, []string, error)
- func (m *Manager) SetEnabled(id string, enabled *bool, scope []int64) (*Plugin, error)
- func (m *Manager) SetSecrets(id string, values map[string]string) error
- func (m *Manager) Sources() ([]map[string]any, error)
- func (m *Manager) StageOnTarget(ctx context.Context, ex executor.Executor, targetID int64, p *Plugin) (string, error)
- func (m *Manager) TrustPreview(id string) (*Preview, error)
- func (m *Manager) UI() UIContributions
- func (m *Manager) UpdatePreview(ctx context.Context, id, ref string) (*Preview, error)
- func (m *Manager) Verify(p *Plugin) bool
- func (m *Manager) Workflows(projectID int64) []workflows.Source
- type Plugin
- type Preview
- type Source
- type UIContributions
- type UIMod
- type UIPaletteCommand
- type UIQuickCommand
- type UITheme
Constants ¶
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.
const ClaudeMarketplace = ".claude-plugin/marketplace.json"
ClaudeMarketplace is Claude Code's marketplace file, read as a source too.
const IndexFile = "lectern-plugins.yaml"
IndexFile is the marketplace file at a source repository's root.
Variables ¶
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.
var ErrUnknownPreview = errors.New("that preview has expired; preview the plugin again")
ErrUnknownPreview means the preview expired or never existed.
Functions ¶
func CheckGitURL ¶
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.
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 ¶
Observe maps one bus message to lifecycle events. Exposed so tests can drive it without a bus.
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 ¶
New builds a manager over dir (normally lectern-plugins beside the database) and loads what is installed.
func (*Manager) ActiveFor ¶
ActiveFor lists the active plugins that apply to a project (0 = global).
func (*Manager) AddSource ¶
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 ¶
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 ¶
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) MCPServerNames ¶
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) Mods ¶ added in v2.8.0
Mods lists the mods of every active plugin that run on surface ("web" or "cli"). A plugin whose files no longer match its consent contributes an error instead of code: nothing it ships runs until someone trusts it again.
func (*Manager) Preview ¶
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 ¶
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 ¶
RemoveSource forgets a marketplace. Plugins installed from it stay.
func (*Manager) SandboxProviderFile ¶
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 ¶
SetEnabled switches a plugin on or off; scope, when non-nil, sets the projects it applies to (empty = everywhere).
func (*Manager) SetSecrets ¶
SetSecrets stores values for the plugin's declared secrets. An empty value removes one. Undeclared names are refused.
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 ¶
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 ¶
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.
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) InScope ¶
InScope reports whether p applies to a project. Project 0 asks about contributions that are global by nature (agents, themes, palette).
func (*Plugin) SecretNames ¶
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 UIMod ¶ added in v2.8.0
type UIMod struct {
Plugin string `json:"plugin"`
ID string `json:"id"`
Name string `json:"name"`
API string `json:"api,omitempty"`
Hash string `json:"hash"`
Script string `json:"script,omitempty"`
Error string `json:"error,omitempty"`
}
UIMod is one mod a surface loads (docs/mods.md). Script is the module already turned into the classic script both runtimes evaluate, from the consented, re-verified files; Hash pins it, so a runtime can tell that a mod changed and reload it.