fusabi-plugin-runtime
Plugin loader, hot-reload, and runtime for Fusabi plugins (fsx & fzb) with manifest validation and capability enforcement.
Features
- Plugin Loading - Load plugins from source (.fsx) or bytecode (.fzb)
- Manifest Validation - Validate plugin manifests and enforce requirements
- Capability Enforcement - Ensure plugins only use declared capabilities
- Hot Reload - Automatically reload plugins when files change
- Lifecycle Management - Initialize, run, and cleanup plugins
- Plugin Registry - Manage multiple plugins with concurrent access
Quick Start
use ;
Feature Flags
| Feature | Description |
|---|---|
serde (default) |
Enable manifest parsing and serialization |
watch |
Enable filesystem watching for hot reload |
metrics-prometheus |
Prometheus metrics integration |
Plugin Manifest
Plugins are defined by a TOML manifest:
= "my-plugin"
= "1.0.0"
= "Example plugin"
= { = 0, = 18, = 0 }
# Required capabilities
= ["fs:read", "net:request"]
# Dependencies
[[]]
= "json"
= "^1.0"
# Entry point
= "main.fsx"
# Exported functions
= ["init", "process", "cleanup"]
# Tags for categorization
= ["processing", "example"]
Loading Plugins
use ;
let loader = new?;
// From manifest
let plugin = loader.load_from_manifest?;
// From source directly
let plugin = loader.load_source?;
// From bytecode
let plugin = loader.load_bytecode_file?;
Plugin Registry
use ;
let registry = new;
// Register plugins
registry.register?;
// Get by name
let plugin = registry.get?;
// Get all running plugins
let running = registry.running;
// Reload a plugin
registry.reload?;
Hot Reload
use ;
let mut watcher = new?;
// Add change handler
watcher.on_change;
// Watch plugin directories
watcher.watch?;
watcher.start?;
Lifecycle Hooks
use ;
let runtime = new?;
// Add lifecycle event handler
runtime.on_event;
Capability Enforcement
Plugins must declare required capabilities in their manifest. The runtime validates that:
- All declared capabilities are valid
- The host grants the required capabilities
- Plugins don't access undeclared capabilities
use ;
let config = new
.with_engine_config;
// Plugin requesting fs:write without it being granted will fail
let loader = new?;
API Version Compatibility
Plugins declare a required API version. The runtime checks compatibility:
use ;
let config = new
.with_host_api_version;
// Plugin requiring 0.19.0 will fail to load
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.