Files
openclaw/src/cli/plugin-registry.ts
2026-02-12 17:15:43 +00:00

40 lines
1.3 KiB
TypeScript

import type { PluginLogger } from "../plugins/types.js";
import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
import { loadConfig } from "../config/config.js";
import { createSubsystemLogger } from "../logging.js";
import { loadOpenClawPlugins } from "../plugins/loader.js";
import { getActivePluginRegistry } from "../plugins/runtime.js";
const log = createSubsystemLogger("plugins");
let pluginRegistryLoaded = false;
export function ensurePluginRegistryLoaded(): void {
if (pluginRegistryLoaded) {
return;
}
const active = getActivePluginRegistry();
// Tests (and callers) can pre-seed a registry (e.g. `test/setup.ts`); avoid
// doing an expensive load when we already have plugins/channels/tools.
if (
active &&
(active.plugins.length > 0 || active.channels.length > 0 || active.tools.length > 0)
) {
pluginRegistryLoaded = true;
return;
}
const config = loadConfig();
const workspaceDir = resolveAgentWorkspaceDir(config, resolveDefaultAgentId(config));
const logger: PluginLogger = {
info: (msg) => log.info(msg),
warn: (msg) => log.warn(msg),
error: (msg) => log.error(msg),
debug: (msg) => log.debug(msg),
};
loadOpenClawPlugins({
config,
workspaceDir,
logger,
});
pluginRegistryLoaded = true;
}