Plugin lifecycle and layout
Lifecycle and layout
The loader scans the bundled plugin root first and the writable instance plugin root second (src/daemon/brainCore.ts:188). A name is loaded from the first root whose copy loads successfully: a copy that fails in an earlier root is logged and does not block a later root (src/plugins/loader.ts:336, 479). Only names in the enabled-plugin configuration are loaded. Within each root, plugin folders are processed in ascending name order, so registration order does not depend on the filesystem (src/plugins/loader.ts:333-334).
Each plugin is loaded into a staging registry. The loader parses and validates the manifest, verifies that the entry remains inside the plugin directory by a lexical path check that does not resolve symlinks (src/plugins/manifest.ts:55-57), imports the ESM entry, runs the migrate() that a plugin declaring reads: ['db'] must export (pluginMigrator), and calls register(ctx). A failing migration skips the plugin like any other load failure, so register never sees a database its own migrations have not prepared. Contributions are merged only after registration completes. In this lazy entry-loading phase, a malformed manifest, failed import, failed migration, or throwing registration skips that plugin without leaving partial tools or routes in the live registry. Authoritative construction first awaits strict declaration preparation in the same loader; an unreadable root, malformed declaration or persistence failure rejects construction rather than taking this per-plugin skip path. The internal allToolOwners callback reads the merged registry's canonical owner index at call time. Both ctx.toolNames() and runner local RPC attribution use that live view, so an earlier Sandbox context can attribute Terminal's later registration without exposing failed staged contributions. Direct contextFor callers read their own registry's owner index. See the runner bridge.
Every daemon start builds the registry generation from disk, and a plugin change is applied by restarting, never by swapping the plugin in place (requestReload). The one exception is a plugin's skill set: requestReload({ mode: 'reload', skills }) replaces it in the running daemon, because skills are data that every reader resolves per turn. Do not cache a control, configuration object, or other live registry value; resolve sibling controls at the time of use.
A minimal plugin has this shape:
my-plugin/
├── elowen-plugin.json
├── index.mjs
├── icon.svg
├── i18n/
│ └── cs.json
├── prompt/
├── web-src/
└── web/
The icon, translation files, prompt fragments, browser sources, and browser bundle are optional. The entry path is relative to the plugin directory.
Server-side plugin code should use the stable plugin API package and the published packages it declares. Do not import Elowen application internals. Browser bundles must never import from Elowen's web/ application. They use the browser runtime described in browser bundle and runtime.
A user-root plugin also has to be in the licence set. The loader refuses a user-root plugin outside that set with not included in this licence before its entry is imported, and the failure takes the normal skip path. The bundled root is never gated (src/plugins/loader.ts:356). The set is built as loadablePlugins in src/daemon/brainCore.ts:306.
Each import URL carries the manifest version and the entry file's modification time. The loader's own comment gives the reason: Node caches a module by URL for the life of the process, so a later load must not reuse a stale module after an in-place update (src/plugins/loader.ts:357-361).
Invalid or incompatible installed manifests are omitted from authoritative declaration ingestion, not allowed to abort the daemon. The existing lazy loader reports enabled failures after reporting is wired, and install receipts keep rejected plugins visible as degraded for Marketplace repair. Filesystem scan failures and durable declaration write failures still abort construction; previously recorded lifecycle ownership is retained.
A skipped plugin is logged as plugin skipped: <name>: <reason> with code plugin.load_failed, and the load alert is synced (src/plugins/loader.ts:479). A folder without elowen-plugin.json is not a plugin and is skipped without a message (src/plugins/loader.ts:345). An enabled name that no root provides is reported once at the end as plugin.enabled_missing (src/plugins/loader.ts:490).
Owning code and minimal use
The loader is preparePluginLoad in src/plugins/loader.ts, which returns the lazy entry-loading implementation that stages, validates and merges each plugin. The internal loadPlugins fixture facade composes both phases for core and registry-plugin tests without daemon construction. The authoritative daemon awaits preparation before exposing brain consumers, then keeps entry loading lazy until bootstrap has installed reporting and host transports; runners skip declaration writes. See daemon construction. discoverPlugins in the same file lists folders by parsing manifests without importing any code, so a request handler may call it. The manifest checks are parseManifest and validateManifestFolder in src/plugins/manifest.ts. The roots and the licence set are wired in src/daemon/brainCore.ts. The public surface is PluginContext and PluginChange in src/plugins/api.ts.
The one live way to change a skill set without a restart is requestReload with the complete new set:
await ctx.requestReload({ mode: 'reload', skills: nextSkills });
Any other change uses the restart form, which carries a reason:
await ctx.requestReload({ mode: 'restart', reason: 'settings changed' });
The method takes the plugin from its context, so a plugin can only replace its own skills. When it rejects, the plugin's write already happened, so the plugin should report the change as saved but not applied rather than as a success (src/plugins/api.ts:2582). The real consumer is the skills plugin in the registry, which calls requestReload({ mode: 'reload', skills: collectSkills() }) after it changes its skill files.
Discovery is cheap and safe to repeat, because it parses manifests only (src/plugins/loader.ts:114). A plugin change of any kind other than a skill set costs one daemon restart, which pauses running turns first.
The registry LSP provider registers its existing conversation shutdown owner once as registerSessionLifecycle({ releaseSession: shutdownSession }). Release fences acquisition synchronously, joins an existing release and awaits actual process-close acknowledgement before allowing a successor. Unconfirmed termination rejects; a later explicit release may retry through the same provider state. Its named lsp control remains diagnostics-status-only, not a cleanup route. Process/service-stop cleanup is separate and must retain its own confirmed termination ownership.
registerSessionLifecycle({ retainedSessionIds?, releaseSession? }) contributes to the existing retention and release owners, not a second scheduler. At least one callback is required. Published records hold only the owner and callbacks; dispatcher failures retain owner attribution without storing an unused logger. Retention validates and unions every provider result before deletion; a failure aborts instead of using a partial set. With no provider there are no extra retained ids or release calls. Registration adds neither tool authority nor prompt/model cost. Retention calls each applicable provider once per sweep/account and unions the returned strings; protection neither authorizes access nor prevents explicit user/admin erasure. Release calls every provider's synchronous fence before yielding, then awaits all acknowledgements and aggregates failures; one rejection does not skip another provider's cleanup. The dispatcher creates no timer, durable classification or background work.
provides.sessionLifecycle.runPlatforms declares synthetic platforms actually owned by the plugin. Canonical ingestion persists ownership and normalizes historical interruption sidecars before consumers run. Target listing, ordinary deletion and recovery read that durable set, including classifications retained after a plugin is disabled or removed. This metadata is not server-automation authority. Historical owners missing from disk require explicit matching manifests through the offline importer before consumer activation; names, session prefixes and a successful discovery listing are not substitutes.
Process-lifetime registry
The daemon's PluginRegistryProvider shares one lazy in-flight or successful get() promise. An initial failure propagates and clears the memo for a later retry; peek() performs no load and is undefined before success. Plugin-code and enablement changes create a fresh provider on daemon restart. Skill-only reloads replace skills in the loaded registry. Brain sessions and platform adapters use this owner without polling or a second registry.