extension

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: MIT Imports: 16 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

View Source
var DefaultAllowedHosts = []string{hostGitHub}

Functions

func CheckPermission

func CheckPermission(ext *ExtensionInfo, perm Permission) bool

CheckPermission reports whether ext has been granted perm.

NOTE(#174): This function correctly checks the manifest declaration, but no runtime call-site currently enforces permissions before executing extension operations. MCP subprocess extensions run with full OS-level user privileges regardless of their declared permissions. See SECURITY.md for roadmap.

func ManifestHasPermission added in v0.2.0

func ManifestHasPermission(m *Manifest, perm Permission) bool

ManifestHasPermission reports whether m declares perm in its permissions list. This is the manifest-level equivalent of CheckPermission and is used by runtimes that hold a *Manifest rather than a full *ExtensionInfo.

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"`
	SourceURL   string    `toml:"source_url,omitempty"`
	CommitHash  string    `toml:"commit_hash,omitempty"`
}

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 uses DefaultAllowedHosts for registry validation. Call LoadAll explicitly to scan for installed extensions.

func NewManagerWithHosts added in v0.2.0

func NewManagerWithHosts(extDir string, allowedHosts []string) *Manager

NewManagerWithHosts creates a Manager with a custom registry allowlist. Pass nil or an empty slice to reject all remote installs.

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. Remote URLs are validated against the trusted registry allowlist. After a successful clone the commit hash is recorded for integrity verification. 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.

func (*Manager) VerifyIntegrity added in v0.2.0

func (m *Manager) VerifyIntegrity(ctx context.Context, name string) error

VerifyIntegrity checks that the current HEAD of an installed extension's git repo still matches the commit hash recorded at install time. Returns nil if the hashes match, an error describing the mismatch otherwise. Extensions installed from local paths (no recorded hash) always pass.

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 PermissionDeniedError added in v0.2.0

type PermissionDeniedError struct {
	Extension  string
	Permission Permission
	Operation  string
}

PermissionDeniedError is returned when an extension attempts an operation that requires a permission it has not declared.

func (*PermissionDeniedError) Error added in v0.2.0

func (e *PermissionDeniedError) Error() string

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