mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 17:30:21 +00:00
feat(memory-wiki): add prompt supplement integration
This commit is contained in:
@@ -62,6 +62,7 @@ function fakeApi(overrides: Partial<OpenClawPluginApi> = {}): OpenClawPluginApi
|
||||
registerCommand() {},
|
||||
registerContextEngine() {},
|
||||
registerMemoryPromptSection() {},
|
||||
registerMemoryPromptSupplement() {},
|
||||
registerMemoryFlushPlan() {},
|
||||
registerMemoryRuntime() {},
|
||||
registerMemoryEmbeddingProvider() {},
|
||||
|
||||
@@ -6,6 +6,7 @@ import plugin from "./index.js";
|
||||
function createApi() {
|
||||
const registerCli = vi.fn();
|
||||
const registerGatewayMethod = vi.fn();
|
||||
const registerMemoryPromptSupplement = vi.fn();
|
||||
const registerTool = vi.fn();
|
||||
const api = createTestPluginApi({
|
||||
id: "memory-wiki",
|
||||
@@ -15,17 +16,31 @@ function createApi() {
|
||||
runtime: {} as OpenClawPluginApi["runtime"],
|
||||
registerCli,
|
||||
registerGatewayMethod,
|
||||
registerMemoryPromptSupplement,
|
||||
registerTool,
|
||||
}) as OpenClawPluginApi;
|
||||
return { api, registerCli, registerGatewayMethod, registerTool };
|
||||
return {
|
||||
api,
|
||||
registerCli,
|
||||
registerGatewayMethod,
|
||||
registerMemoryPromptSupplement,
|
||||
registerTool,
|
||||
};
|
||||
}
|
||||
|
||||
describe("memory-wiki plugin", () => {
|
||||
it("registers gateway methods, tools, and wiki cli surface", async () => {
|
||||
const { api, registerCli, registerGatewayMethod, registerTool } = createApi();
|
||||
it("registers prompt supplement, gateway methods, tools, and wiki cli surface", async () => {
|
||||
const {
|
||||
api,
|
||||
registerCli,
|
||||
registerGatewayMethod,
|
||||
registerMemoryPromptSupplement,
|
||||
registerTool,
|
||||
} = createApi();
|
||||
|
||||
await plugin.register(api);
|
||||
|
||||
expect(registerMemoryPromptSupplement).toHaveBeenCalledTimes(1);
|
||||
expect(registerGatewayMethod.mock.calls.map((call) => call[0])).toEqual([
|
||||
"wiki.status",
|
||||
"wiki.init",
|
||||
|
||||
@@ -2,6 +2,7 @@ import { definePluginEntry } from "./api.js";
|
||||
import { registerWikiCli } from "./src/cli.js";
|
||||
import { memoryWikiConfigSchema, resolveMemoryWikiConfig } from "./src/config.js";
|
||||
import { registerMemoryWikiGatewayMethods } from "./src/gateway.js";
|
||||
import { buildWikiPromptSection } from "./src/prompt-section.js";
|
||||
import {
|
||||
createWikiApplyTool,
|
||||
createWikiGetTool,
|
||||
@@ -18,6 +19,7 @@ export default definePluginEntry({
|
||||
register(api) {
|
||||
const config = resolveMemoryWikiConfig(api.pluginConfig);
|
||||
|
||||
api.registerMemoryPromptSupplement(buildWikiPromptSection);
|
||||
registerMemoryWikiGatewayMethods({ api, config, appConfig: api.config });
|
||||
api.registerTool(createWikiStatusTool(config, api.config), { name: "wiki_status" });
|
||||
api.registerTool(createWikiLintTool(config, api.config), { name: "wiki_lint" });
|
||||
|
||||
42
extensions/memory-wiki/src/prompt-section.ts
Normal file
42
extensions/memory-wiki/src/prompt-section.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { MemoryPromptSectionBuilder } from "openclaw/plugin-sdk/memory-host-core";
|
||||
|
||||
export const buildWikiPromptSection: MemoryPromptSectionBuilder = ({ availableTools }) => {
|
||||
const hasWikiSearch = availableTools.has("wiki_search");
|
||||
const hasWikiGet = availableTools.has("wiki_get");
|
||||
const hasWikiApply = availableTools.has("wiki_apply");
|
||||
const hasWikiLint = availableTools.has("wiki_lint");
|
||||
|
||||
if (!hasWikiSearch && !hasWikiGet && !hasWikiApply && !hasWikiLint) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const lines = [
|
||||
"## Compiled Wiki",
|
||||
"Use the wiki when the answer depends on accumulated project knowledge, prior syntheses, entity pages, or source-backed notes that should survive beyond one conversation.",
|
||||
];
|
||||
|
||||
if (hasWikiSearch && hasWikiGet) {
|
||||
lines.push(
|
||||
"Workflow: `wiki_search` first, then `wiki_get` for the exact page or imported memory file you need. Shared search may return `corpus=memory` results when active-memory bridging is enabled.",
|
||||
);
|
||||
} else if (hasWikiSearch) {
|
||||
lines.push(
|
||||
"Use `wiki_search` before answering from stored knowledge. Shared search may return `corpus=memory` results when active-memory bridging is enabled.",
|
||||
);
|
||||
} else if (hasWikiGet) {
|
||||
lines.push(
|
||||
"Use `wiki_get` to inspect specific wiki pages or imported memory files by path/id.",
|
||||
);
|
||||
}
|
||||
|
||||
if (hasWikiApply) {
|
||||
lines.push(
|
||||
"Use `wiki_apply` for narrow synthesis filing and metadata repair instead of rewriting managed markdown blocks by hand.",
|
||||
);
|
||||
}
|
||||
if (hasWikiLint) {
|
||||
lines.push("After meaningful wiki updates, run `wiki_lint` before trusting the vault.");
|
||||
}
|
||||
lines.push("");
|
||||
return lines;
|
||||
};
|
||||
Reference in New Issue
Block a user