Files
moltbot/src/plugins/memory-runtime.ts
Neerav Makwana b6cbd9225c fix(cli): load memory plugin for doctor/status when registry is cold (#76393)
Summary:
- The PR adds a scoped standalone memory-slot plugin load for doctor/status memory resolution, updates memory-runtime regression tests, and adds a changelog fix entry.
- Reproducibility: yes. source-reproducible: current main's doctor/status path reads getMemoryRuntime after on ...  registers that runtime only during plugin activation. I did not run a live macOS LaunchAgent reproduction.

Automerge notes:
- PR branch already contained follow-up commit before automerge: fix(cli): load memory plugin for doctor/status when registry is cold

Validation:
- ClawSweeper review passed for head a6a1967316.
- Required merge gates passed before the squash merge.

Prepared head SHA: a6a1967316
Review: https://github.com/openclaw/openclaw/pull/76393#issuecomment-4365255585

Co-authored-by: Neerav Makwana <261249544+neeravmakwana@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: clawsweeper <274271284+clawsweeper[bot]@users.noreply.github.com>
2026-05-03 07:38:55 +00:00

77 lines
2.6 KiB
TypeScript

import { resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../agents/agent-scope.js";
import type { OpenClawConfig } from "../config/types.openclaw.js";
import { resolveUserPath } from "../utils.js";
import { getLoadedRuntimePluginRegistry } from "./active-runtime-registry.js";
import { normalizePluginsConfig } from "./config-state.js";
import { getMemoryRuntime } from "./memory-state.js";
import { ensureStandaloneRuntimePluginRegistryLoaded } from "./runtime/standalone-runtime-registry-loader.js";
function resolveMemoryRuntimePluginIds(config: OpenClawConfig): string[] {
const plugins = normalizePluginsConfig(config.plugins);
const memorySlot = plugins.slots.memory;
if (!plugins.enabled || typeof memorySlot !== "string" || memorySlot.trim().length === 0) {
return [];
}
const pluginId = memorySlot.trim();
if (plugins.deny.includes(pluginId) || plugins.entries[pluginId]?.enabled === false) {
return [];
}
return [pluginId];
}
function resolveMemoryRuntimeWorkspaceDir(cfg: OpenClawConfig): string | undefined {
const agentId = resolveDefaultAgentId(cfg);
const dir = resolveAgentWorkspaceDir(cfg, agentId);
if (typeof dir !== "string" || !dir.trim()) {
return undefined;
}
return resolveUserPath(dir);
}
function ensureMemoryRuntime(cfg?: OpenClawConfig) {
const current = getMemoryRuntime();
if (current || !cfg) {
return current;
}
const onlyPluginIds = resolveMemoryRuntimePluginIds(cfg);
if (onlyPluginIds.length === 0) {
return getMemoryRuntime();
}
getLoadedRuntimePluginRegistry({ requiredPluginIds: onlyPluginIds });
if (getMemoryRuntime()) {
return getMemoryRuntime();
}
const workspaceDir = resolveMemoryRuntimeWorkspaceDir(cfg);
ensureStandaloneRuntimePluginRegistryLoaded({
requiredPluginIds: onlyPluginIds,
loadOptions: {
config: cfg,
onlyPluginIds,
workspaceDir,
},
});
return getMemoryRuntime();
}
export async function getActiveMemorySearchManager(params: {
cfg: OpenClawConfig;
agentId: string;
purpose?: "default" | "status" | "cli";
}) {
const runtime = ensureMemoryRuntime(params.cfg);
if (!runtime) {
return { manager: null, error: "memory plugin unavailable" };
}
return await runtime.getMemorySearchManager(params);
}
export function resolveActiveMemoryBackendConfig(params: { cfg: OpenClawConfig; agentId: string }) {
return ensureMemoryRuntime(params.cfg)?.resolveMemoryBackendConfig(params) ?? null;
}
export async function closeActiveMemorySearchManagers(cfg?: OpenClawConfig): Promise<void> {
void cfg;
const runtime = getMemoryRuntime();
await runtime?.closeAllMemorySearchManagers?.();
}