mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 07:11:06 +00:00
* memory-core: add dreaming promotion flow with weighted thresholds * docs(memory): mark dreaming as experimental * memory-core: address dreaming promotion review feedback * memory-core: harden short-term promotion concurrency * acpx: make abort-process test timer-independent * memory-core: simplify dreaming config with mode presets * memory-core: add /dreaming command and tighten recall tracking * ui: add Dreams tab with sleeping lobster animation Adds a new Dreams tab to the gateway UI under the Agent group. The tab is gated behind the memory-core dreaming config — it only appears in the sidebar when dreaming.mode is not 'off'. Features: - Sleeping vector lobster with breathing animation - Floating Z's, twinkling starfield, moon glow - Rotating dream phrase bubble (17 whimsical phrases) - Memory stats bar (short-term, long-term, promoted) - Active/idle visual states - 14 unit tests * plugins: fix --json stdout pollution from hook runner log The hook runner initialization message was using log.info() which writes to stdout via console.log, breaking JSON.parse() in the Docker smoke test for 'openclaw plugins list --json'. Downgrade to log.debug() so it only appears when debugging is enabled. * ui: keep Dreams tab visible when dreaming is off * tests: fix contracts and stabilize extension shards * memory-core: harden dreaming recall persistence and locking * fix: stabilize dreaming PR gates (#60569) (thanks @vignesh07) * test: fix rebase drift in telegram and plugin guards
139 lines
4.3 KiB
TypeScript
139 lines
4.3 KiB
TypeScript
import type { MemorySearchResult } from "openclaw/plugin-sdk/memory-core-host-runtime-files";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
resetMemoryToolMockState,
|
|
setMemoryBackend,
|
|
setMemorySearchImpl,
|
|
} from "../../../test/helpers/memory-tool-manager-mock.js";
|
|
import type { OpenClawConfig } from "../api.js";
|
|
import { createMemorySearchTool } from "./tools.js";
|
|
|
|
type RecordShortTermRecallsFn = (params: {
|
|
workspaceDir?: string;
|
|
query: string;
|
|
results: MemorySearchResult[];
|
|
nowMs?: number;
|
|
}) => Promise<void>;
|
|
|
|
const recallTrackingMock = vi.hoisted(() => ({
|
|
recordShortTermRecalls: vi.fn<RecordShortTermRecallsFn>(async () => {}),
|
|
}));
|
|
|
|
vi.mock("./short-term-promotion.js", () => ({
|
|
recordShortTermRecalls: recallTrackingMock.recordShortTermRecalls,
|
|
}));
|
|
|
|
function asOpenClawConfig(config: Partial<OpenClawConfig>): OpenClawConfig {
|
|
return config as OpenClawConfig;
|
|
}
|
|
|
|
function createSearchTool(config: OpenClawConfig) {
|
|
const tool = createMemorySearchTool({ config });
|
|
if (!tool) {
|
|
throw new Error("memory_search tool missing");
|
|
}
|
|
return tool;
|
|
}
|
|
|
|
describe("memory_search recall tracking", () => {
|
|
beforeEach(() => {
|
|
resetMemoryToolMockState();
|
|
recallTrackingMock.recordShortTermRecalls.mockReset();
|
|
recallTrackingMock.recordShortTermRecalls.mockResolvedValue(undefined);
|
|
});
|
|
|
|
it("records only surfaced results after qmd clamp", async () => {
|
|
setMemoryBackend("qmd");
|
|
setMemorySearchImpl(async () => [
|
|
{
|
|
path: "memory/2026-04-03.md",
|
|
startLine: 1,
|
|
endLine: 2,
|
|
score: 0.95,
|
|
snippet: "A".repeat(80),
|
|
source: "memory" as const,
|
|
},
|
|
{
|
|
path: "memory/2026-04-02.md",
|
|
startLine: 1,
|
|
endLine: 2,
|
|
score: 0.92,
|
|
snippet: "B".repeat(80),
|
|
source: "memory" as const,
|
|
},
|
|
]);
|
|
|
|
const tool = createSearchTool(
|
|
asOpenClawConfig({
|
|
agents: { list: [{ id: "main", default: true }] },
|
|
memory: {
|
|
backend: "qmd",
|
|
citations: "on",
|
|
qmd: { limits: { maxInjectedChars: 100 } },
|
|
},
|
|
}),
|
|
);
|
|
|
|
const result = await tool.execute("call_recall_clamp", { query: "backup glacier" });
|
|
const details = result.details as { results: Array<{ path: string }> };
|
|
expect(details.results).toHaveLength(1);
|
|
expect(details.results[0]?.path).toBe("memory/2026-04-03.md");
|
|
|
|
expect(recallTrackingMock.recordShortTermRecalls).toHaveBeenCalledTimes(1);
|
|
const [firstCall] = recallTrackingMock.recordShortTermRecalls.mock.calls;
|
|
expect(firstCall).toBeDefined();
|
|
const recallParams = firstCall[0];
|
|
expect(recallParams.results).toHaveLength(1);
|
|
expect(recallParams.results[0]?.path).toBe("memory/2026-04-03.md");
|
|
expect(recallParams.results[0]?.snippet).not.toContain("Source:");
|
|
});
|
|
|
|
it("does not block tool results on slow best-effort recall writes", async () => {
|
|
let resolveRecall: (() => void) | undefined;
|
|
recallTrackingMock.recordShortTermRecalls.mockImplementationOnce(
|
|
async () =>
|
|
await new Promise<void>((resolve) => {
|
|
resolveRecall = resolve;
|
|
}),
|
|
);
|
|
|
|
const tool = createSearchTool(
|
|
asOpenClawConfig({
|
|
agents: { list: [{ id: "main", default: true }] },
|
|
}),
|
|
);
|
|
setMemorySearchImpl(async () => [
|
|
{
|
|
path: "memory/2026-04-03.md",
|
|
startLine: 1,
|
|
endLine: 2,
|
|
score: 0.95,
|
|
snippet: "Move backups to S3 Glacier.",
|
|
source: "memory" as const,
|
|
},
|
|
]);
|
|
|
|
let timeout: NodeJS.Timeout | undefined;
|
|
try {
|
|
const result = (await Promise.race([
|
|
tool.execute("call_recall_non_blocking", { query: "glacier" }),
|
|
new Promise<never>((_, reject) => {
|
|
timeout = setTimeout(() => {
|
|
reject(new Error("memory_search waited on recall persistence"));
|
|
}, 200);
|
|
}),
|
|
])) as Awaited<ReturnType<typeof tool.execute>>;
|
|
|
|
const details = result.details as { results: Array<{ path: string }> };
|
|
expect(details.results).toHaveLength(1);
|
|
expect(details.results[0]?.path).toBe("memory/2026-04-03.md");
|
|
expect(recallTrackingMock.recordShortTermRecalls).toHaveBeenCalledTimes(1);
|
|
} finally {
|
|
if (timeout) {
|
|
clearTimeout(timeout);
|
|
}
|
|
resolveRecall?.();
|
|
}
|
|
});
|
|
});
|