Skip to content

Plugins

ConsensusOS uses a plugin architecture where every module — from health monitoring to chain adapters — is a plugin that communicates through the shared event bus.

FactoryPurpose
createHealthSentinel()Node health monitoring via heartbeats
createReleaseVerifier()Software release hash verification
createConfigGuardian()Configuration schema validation and migration
createSandboxPlugin()Isolated simulation, replay, and amendment engine
createGovernorPlugin()Token-based execution, policy enforcement, build queue

Extend BasePlugin and use ManifestBuilder to declare your plugin’s identity and capabilities:

import { BasePlugin, ManifestBuilder } from "@mcptoolshop/consensus-os/plugin";
class MyMonitor extends BasePlugin {
readonly manifest = ManifestBuilder.create("my-monitor")
.name("My Monitor")
.version("1.0.0")
.capability("sentinel")
.build();
protected async onStart() {
this.on("health.check.completed", (event) => {
this.log.info("Health check result", event.data);
});
this.emit("my-monitor.ready", { status: "online" });
}
}
  1. Registrationloader.register(plugin) adds the plugin to the loader
  2. Dependency resolution — The loader topologically sorts plugins using Kahn’s algorithm; circular dependencies cause a hard fail
  3. InitializationonInit(ctx) is called in dependency order, receiving the PluginContext with access to the event bus, invariant engine, config, and logger
  4. StartuponStart() is called after all plugins are initialized
  5. ShutdownonStop() is called in reverse boot order
  6. DestroyonDestroy() is called after stop for final resource cleanup

When extending BasePlugin, these helpers are available in any lifecycle hook:

MethodDescription
this.emit(topic, data)Publish an event through the event bus
this.on(topic, handler)Subscribe to an event topic (supports wildcards)
this.registerInvariant(name, description, check)Register a fail-closed invariant
this.logStructured logger scoped to this plugin
this.eventsDirect access to the event bus
this.invariantsDirect access to the invariant engine
this.configPlugin-specific configuration
ExportDescription
BasePluginAbstract base class with lifecycle defaults and convenience methods
ManifestBuilderFluent builder for type-safe plugin manifests
validatePlugin()Pre-registration validation with errors and warnings
AttestationPipelineRelease attestation and build provenance

Call validatePlugin() before registration to catch issues early:

const result = validatePlugin(myPlugin);
if (result.errors.length > 0) {
console.error("Plugin validation failed:", result.errors);
}