by 1653lin4
Load and hot-reload standalone local JavaScript drawer modules from your vault with lifecycle cleanup and secret storage support.
Module Host
A minimal, zero-dependency microkernel host for Obsidian (1.11.5+, desktop only) that loads and hot-reloads standalone local JavaScript drawer modules (*plugin.js / *plugin.mjs) directly from your vault—no build step required for local modules.
Security Notice
- Local-first host: The Module Host core makes zero network requests, includes zero telemetry, and never downloads external code.
- Automatic local execution: Modules inside your configured vault folder (
_Modules/pluginsby default) are dynamically imported via native ESimport()and automatically execute when the host loads or reloads. - Full plugin privileges (no sandbox): Modules are not sandboxed. They execute with the same privileges as a regular Obsidian plugin and can access Obsidian APIs and host-provided services, including
SecretStore. - Network & data access by modules: Although the host itself does not connect to the network, individual modules you load may make network requests, read or modify vault data, or use configured secrets depending on their code.
- Trusted code only: Only place modules that you wrote yourself or carefully audited into your modules folder.
Features
- Pure microkernel runtime (
Runtime): Service registry (register,get,has) with duplicate protection, single-module failure rollback, and LIFO (dispose) cleanup on hot reload or unload. - Single-layer hot reload (
PluginLoader): Scans the configured vault folder (default:_Modules/plugins) for*plugin.js/*plugin.mjsfiles, strictly loadsexport default, and busts ESM cache using timestamp queries. - Secret isolation (
SecretStore): Integrates exclusively with Obsidian's built-inSecretStorage(1.11.5+) andSecretComponent. Plaintext keys are never written todata.json, and missing secrets fail fast by returningnull. - Automatic bilingual UI: Automatically adapts settings, commands, and notices between English and Chinese via Obsidian's
getLanguage()API.
Core Services Registered by Default
Every module receives the runtime instance in setup(runtime) and dispose(runtime), and window.moduleHost also exposes the active runtime for console debugging or standalone scripts:
| Service key | Value |
|---|---|
"app" | Obsidian App instance |
"plugin" | ModuleHostPlugin instance |
"obsidian" | Full "obsidian" API namespace (Notice, Component, Modal, etc.) |
"secrets" | SecretStore wrapper (get(aliasOrId), list()) |
Quick Start: Minimal Drawer Module
- Create a folder in your vault (default:
_Modules/plugins). - Add a file whose name ends with
plugin.jsorplugin.mjs, such as_Modules/plugins/helloPlugin.js:
let scope = null;
export default {
name: "hello-drawer",
async setup(runtime) {
const app = runtime.get("app");
const hostPlugin = runtime.get("plugin");
const obsidian = runtime.get("obsidian");
// Manage listeners, timers, and UI cleanup via a standalone Component
scope = new obsidian.Component();
scope.load();
const statusEl = hostPlugin.addStatusBarItem();
statusEl.setText("Hello Drawer");
scope.register(() => statusEl.remove());
scope.registerEvent(
app.workspace.on("file-open", (file) => {
if (file) {
statusEl.setText(`Active: ${file.basename}`);
}
})
);
new obsidian.Notice("Hello drawer loaded.");
},
async dispose() {
// One-line cleanup for all listeners, timers, and registered callbacks
scope?.unload();
scope = null;
}
};
- Run the command Reload local modules (
热重载所有本地抽屉模块) from the Command Palette whenever you edit a module.
Note on commands and custom views:
obsidian.Componentautomatically detaches workspace events, DOM events, and intervals. If your drawer manually registers commands (hostPlugin.addCommand) or customItemViewtypes (hostPlugin.registerView), make sure to remove/unregister them insidedispose(runtime).
Using Secrets Safely
- Create your actual secret inside Obsidian Settings → Keychain / Secret Storage.
- In Settings → Module Host → Secret vault, add an uppercase alias (for example,
DEEPSEEK_API_KEY) and bind it to your secret storage entry—or callsecrets.get("my-secret-id")directly with the exact storage ID:
const secrets = runtime.get("secrets");
const apiKey = secrets.get("DEEPSEEK_API_KEY"); // returns string | null
if (!apiKey) {
throw new Error("Missing DEEPSEEK_API_KEY in Obsidian secret storage.");
}
Optional 4-Layer Folder Convention
While Module Host itself only scans your configured plugins folder (_Modules/plugins) and enforces no directory layout outside it, organizing your _Modules folder into four optional layers keeps AI-assisted local development clean:
_Modules/capabilities/— Reusable single-domain helper molecules (e.g., vault, text, JSON, canvas wrappers)_Modules/presets/— Higher-level engines or JSON configs shared across modules_Modules/plugins/— Resident drawer modules (*plugin.js/*plugin.mjs) scanned by Module Host_Modules/scripts/— One-off scripts triggered on demand via a launcher module
Installation
Manual Installation
- Download
main.jsandmanifest.jsonfrom the latest GitHub Release. - Copy both files into
<YourVault>/.obsidian/plugins/module-host/. - Enable Module Host in Obsidian Settings → Community plugins.
Build from Source
npm install
npm run build
Copy the generated main.js and manifest.json into <YourVault>/.obsidian/plugins/module-host/.
License
For plugin developers
Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.