diff --git a/extensions/memory-core/index.test.ts b/extensions/memory-core/index.test.ts new file mode 100644 index 00000000000..8c81f52fc05 --- /dev/null +++ b/extensions/memory-core/index.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from "vitest"; +import { buildPromptSection } from "./index.js"; + +describe("buildPromptSection", () => { + it("returns empty when no memory tools are available", () => { + expect(buildPromptSection({ availableTools: new Set() })).toEqual([]); + }); + + it("returns Memory Recall section when memory_search is available", () => { + const result = buildPromptSection({ availableTools: new Set(["memory_search"]) }); + expect(result[0]).toBe("## Memory Recall"); + expect(result).toContain( + "Citations: include Source: when it helps the user verify memory snippets.", + ); + expect(result.at(-1)).toBe(""); + }); + + it("returns Memory Recall section when memory_get is available", () => { + const result = buildPromptSection({ availableTools: new Set(["memory_get"]) }); + expect(result[0]).toBe("## Memory Recall"); + }); + + it("includes citations-off instruction when citationsMode is off", () => { + const result = buildPromptSection({ + availableTools: new Set(["memory_search"]), + citationsMode: "off", + }); + expect(result).toContain( + "Citations are disabled: do not mention file paths or line numbers in replies unless the user explicitly asks.", + ); + }); +}); diff --git a/extensions/memory-core/index.ts b/extensions/memory-core/index.ts index e176ea619fe..c163f34e1a1 100644 --- a/extensions/memory-core/index.ts +++ b/extensions/memory-core/index.ts @@ -1,7 +1,10 @@ import { definePluginEntry } from "openclaw/plugin-sdk/core"; import type { MemoryPromptSectionBuilder } from "openclaw/plugin-sdk/memory-core"; -const buildPromptSection: MemoryPromptSectionBuilder = ({ availableTools, citationsMode }) => { +export const buildPromptSection: MemoryPromptSectionBuilder = ({ + availableTools, + citationsMode, +}) => { if (!availableTools.has("memory_search") && !availableTools.has("memory_get")) { return []; }