Documentation
¶
Overview ¶
Package plugin implements Fern's Lua plugin system.
Index ¶
- Constants
- func DownloadPlugin(r Registry, name, destDir string) error
- func InstalledNames(dir string) ([]string, error)
- func InstalledVersion(dir, name string) string
- func NormalizeName(name string) string
- func RemovePlugin(name, destDir string) error
- func SaveRegistryCacheTo(r Registry, path string) error
- type CallCtx
- type Effect
- type EffectKind
- type KVStore
- type Manager
- func (m *Manager) ApproveAndLoad(name, dir string) []Effect
- func (m *Manager) BlockRenderers() map[string]*lua.LFunction
- func (m *Manager) CallBlockRenderer(fence, content string) ([]string, bool)
- func (m *Manager) CallCommand(name string, ctx *CallCtx) bool
- func (m *Manager) CallKeyMap(mode, key string, ctx *CallCtx) bool
- func (m *Manager) CancelPicker()
- func (m *Manager) Close()
- func (m *Manager) Enabled() bool
- func (m *Manager) FireDueTimers(ctx *CallCtx) time.Duration
- func (m *Manager) FireEvent(event string, ctx *CallCtx)
- func (m *Manager) HasTimers() bool
- func (m *Manager) LuaCommandNames() map[string]struct{}
- func (m *Manager) PendingApproval() []string
- func (m *Manager) ResolvePicker(selected string) []Effect
- func (m *Manager) RevokePlugin(name string)
- func (m *Manager) TakeEffects() []Effect
- type Registry
- type RegistryEntry
- type VaultQuerier
Constants ¶
const (
// RegistryURL is the canonical URL for the fern-terranium plugin registry.
RegistryURL = "https://codeberg.org/InodeLabs/fern-terranium/raw/branch/main/registry.json"
)
Variables ¶
This section is empty.
Functions ¶
func DownloadPlugin ¶
DownloadPlugin downloads the named plugin tarball from the registry and extracts it into destDir/name/.
func InstalledNames ¶
InstalledNames returns the names of plugin directories inside dir that contain a main.lua file, sorted lexicographically.
func InstalledVersion ¶
InstalledVersion reads the version string written by DownloadPlugin for the named plugin. Returns "" if no version file exists.
func NormalizeName ¶
NormalizeName converts an "author/repo" style name to "author-repo". Plain names (no slash) are returned unchanged.
func RemovePlugin ¶
RemovePlugin deletes the destDir/name/ directory and all its contents.
func SaveRegistryCacheTo ¶
SaveRegistryCacheTo writes r as JSON to path, creating the file if needed.
Types ¶
type CallCtx ¶
type CallCtx struct {
Content string
FilePath string
NoteStems []string
JournalStems []string
TemplateStems []string
NotesDir string
JournalsDir string
TemplatesDir string
Vault string
}
CallCtx holds a snapshot of app state provided to Lua during a call.
type Effect ¶
type Effect struct {
Kind EffectKind
Payload string
}
Effect is a single side-effect produced by a Lua call.
type EffectKind ¶
type EffectKind int
EffectKind identifies what kind of side-effect a Lua call produced.
const ( EffectNotify EffectKind = iota // show success message in cmdbar EffectNotifyErr // show error message in cmdbar EffectSetContent // replace active file content EffectOpen // open file by stem/kind; Payload: stem+"\x1f"+kind EffectOpenPicker // request picker UI; Payload: JSON array of {label,value} )
type KVStore ¶
type KVStore interface {
// PluginKVGet retrieves the value for plugin+key.
// Returns ("", false, nil) when the key is not present.
PluginKVGet(plugin, key string) (string, bool, error)
// PluginKVSet writes value for plugin+key, overwriting any prior value.
PluginKVSet(plugin, key, value string) error
}
KVStore is the interface the plugin manager uses for persistent key-value storage. The implementation lives in vfiles.Index and writes to the vault's fern.db.
type Manager ¶
Manager owns the shared LState and all plugin registrations. All methods must be called from the BubbleTea main goroutine.
func New ¶
func New(cfg *config.Config, kv KVStore, querier VaultQuerier, approved []string, builtinCmds []string) *Manager
New creates a Manager. If plugins are not enabled or the directory is missing/unreadable, returns a disabled manager that is safe to call but does nothing. querier may be nil; vault query API functions return empty results when no querier is available. approved is the list of plugin names allowed to load; unapproved plugins are blocked and recorded in PendingApproval.
func (*Manager) ApproveAndLoad ¶
ApproveAndLoad executes dir/name/main.lua into the live LState, removes name from pendingApproval, and returns the resulting effects. Returns nil when the manager is disabled or name/main.lua does not exist.
func (*Manager) BlockRenderers ¶
BlockRenderers returns the registered fence-name -> Lua function map.
func (*Manager) CallBlockRenderer ¶
CallBlockRenderer calls the Lua renderer registered for fence with the given block content. Returns (display lines, true) on success or (nil, false) when no renderer is registered for that fence or the Lua call fails. The caller must be on the BubbleTea main goroutine.
func (*Manager) CallCommand ¶
CallCommand calls the named Lua command with the provided context. Returns false if no such command is registered.
func (*Manager) CallKeyMap ¶
CallKeyMap checks whether key+mode matches a registered binding and calls it. Returns true if a binding was found.
func (*Manager) CancelPicker ¶
func (m *Manager) CancelPicker()
CancelPicker clears the pending picker callback without calling it.
func (*Manager) FireDueTimers ¶
FireDueTimers fires timers whose nextFireAt is past, updates nextFireAt, and returns the duration until the nearest next fire time (0 = no timers).
func (*Manager) LuaCommandNames ¶
LuaCommandNames returns the set of registered Lua command names.
func (*Manager) PendingApproval ¶
PendingApproval returns a copy of the list of plugin names blocked at load time because they were not in the approved set.
func (*Manager) ResolvePicker ¶
ResolvePicker calls the stored picker callback with the selected value, clears it, and returns the resulting effects.
func (*Manager) RevokePlugin ¶
RevokePlugin moves name into pendingApproval so it shows as unapproved in the UI. Because the Lua state does not support unloading individual scripts the plugin remains functional for the current session; it will not load on the next restart once the caller also removes it from the persisted approved list. If name is already in pendingApproval this is a no-op.
func (*Manager) TakeEffects ¶
TakeEffects returns all accumulated effects and clears the internal list.
type Registry ¶
type Registry struct {
BaseURL string `json:"base_url"`
Plugins []RegistryEntry `json:"plugins"`
}
Registry is the parsed registry.json from fern-terranium.
func FetchRegistry ¶
FetchRegistry downloads and parses the fern-terranium registry.json.
func LoadRegistryCacheFrom ¶
LoadRegistryCacheFrom reads a cached Registry from path. Returns an empty Registry if the file does not exist or cannot be parsed.
type RegistryEntry ¶
type RegistryEntry struct {
Name string `json:"name"`
Main string `json:"main"`
Description string `json:"description"`
Version string `json:"version,omitempty"`
URL string `json:"url,omitempty"`
Maintainer string `json:"maintainer,omitempty"`
Repo string `json:"repo,omitempty"`
Permissions []string `json:"permissions,omitempty"`
}
RegistryEntry describes a single plugin in the registry.
func LoadManifest ¶
func LoadManifest(dir, name string) (RegistryEntry, bool)
LoadManifest reads {dir}/{name}/manifest.json and parses it as a RegistryEntry. Returns the entry and ok=true on success; zero entry and ok=false on missing file or parse error.
type VaultQuerier ¶
type VaultQuerier interface {
// ListStemsForTag returns the stems of all notes/journals carrying tag.
ListStemsForTag(tag string) ([]string, error)
// FrontmatterForStem returns the scalar frontmatter fields for stem.
// kind should be "note", "journal", or "template".
FrontmatterForStem(stem, kind string) (map[string]string, error)
// SearchVault runs a full-text search against the vault. Each hit is a
// map with keys "stem", "kind", and "snippet".
SearchVault(query string) ([]map[string]string, error)
}
VaultQuerier provides read-only vault queries available to Lua plugins. The implementation lives in vfiles.Index. A nil VaultQuerier is valid; all methods check for nil and return empty results rather than panicking.