extension

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package extension implements grut's plugin system. Extensions are small programs (Lua scripts, WASM modules, or MCP servers) installed from https:// git URLs or local directories. Each extension declares a manifest (extension.toml) that specifies its runtime, entry point, and required permissions. The Manager handles install, remove, enable/disable, and state persistence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPermission

func CheckPermission(ext *ExtensionInfo, perm Permission) bool

CheckPermission reports whether ext has been granted perm.

func Scaffold

func Scaffold(dir, name, templateName string) error

Scaffold creates a new extension project in dir/name using the named template.

func ValidPermission

func ValidPermission(p string) bool

ValidPermission reports whether p is a recognised permission name.

Types

type ExtensionInfo

type ExtensionInfo struct {
	InstalledAt time.Time `toml:"installed_at"`
	Manifest    Manifest  `toml:"manifest"`
	Dir         string    `toml:"-"`
	Enabled     bool      `toml:"enabled"`
}

ExtensionInfo holds runtime state for an installed extension.

type Manager

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

Manager handles extension installation, removal, and state tracking.

func NewManager

func NewManager(extDir string) *Manager

NewManager creates a Manager rooted at extDir, creating the directory if needed. It does NOT scan for installed extensions — call LoadAll explicitly.

func (*Manager) Disable

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

Disable marks the extension as disabled and persists state.

func (*Manager) Enable

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

Enable marks the extension as enabled and persists state.

func (*Manager) Get

func (m *Manager) Get(name string) (*ExtensionInfo, error)

Get returns a single extension by name.

func (*Manager) Install

func (m *Manager) Install(ctx context.Context, source string) error

Install adds an extension from a git URL (https:// only) or local path. The manifest inside the source is validated before the installation is considered successful.

func (*Manager) List

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

List returns all installed extensions. The returned slice is a snapshot; callers may iterate without holding a lock.

func (*Manager) LoadAll

func (m *Manager) LoadAll() error

LoadAll scans extDir for subdirectories containing extension.toml, loads each manifest, and restores persisted enabled/disabled state.

func (*Manager) Remove

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

Remove deletes the extension directory and removes it from state.

type Manifest

type Manifest struct {
	Name        string   `toml:"name"`
	Version     string   `toml:"version"`
	Description string   `toml:"description"`
	Author      string   `toml:"author"`
	License     string   `toml:"license"`
	Runtime     string   `toml:"runtime"`
	EntryPoint  string   `toml:"entry_point"`
	MinGrut     string   `toml:"min_grut"`
	Permissions []string `toml:"permissions"`
}

Manifest describes an extension's metadata, loaded from extension.toml.

func LoadManifest

func LoadManifest(dir string) (*Manifest, error)

LoadManifest reads extension.toml from dir and returns the parsed manifest.

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

ParseManifest decodes TOML bytes into a Manifest and validates it.

func (*Manifest) Validate

func (m *Manifest) Validate() error

Validate checks that all required fields are present and values are valid.

type Permission

type Permission string

Permission represents a capability an extension can request.

const (
	PermFileRead  Permission = "file_read"
	PermFileWrite Permission = "file_write"
	PermGitRead   Permission = "git_read"
	PermGitWrite  Permission = "git_write"
	PermNetwork   Permission = "network"
	PermProcess   Permission = "process"
	PermClipboard Permission = "clipboard"
	PermNotify    Permission = "notify"
)

Valid extension permissions.

func AllPermissions

func AllPermissions() []Permission

AllPermissions returns every valid permission value.

type Template

type Template struct {
	Files       map[string]string // relative path → content (may contain {{.Name}})
	Name        string
	Description string
	Runtime     string
}

Template describes a scaffold template for creating new extensions.

func ListTemplates

func ListTemplates() []Template

ListTemplates returns all available scaffold templates.

Directories

Path Synopsis
Package runtime provides sandboxed execution environments for grut extensions.
Package runtime provides sandboxed execution environments for grut extensions.

Jump to

Keyboard shortcuts

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