mr-memory 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +11 -6
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -16,16 +16,19 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
|
16
16
|
const DEFAULT_ENDPOINT = "https://api.memoryrouter.ai";
|
|
17
17
|
|
|
18
18
|
/** Wrap raw memory context in XML tags with a strong instruction */
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/** Wrap API response in extraction markers so we can strip it next turn. */
|
|
20
|
+
function wrapForInjection(context: string): string {
|
|
21
|
+
return `<mr-memory>\n${context}\n</mr-memory>`;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/** Strip previous memory injections from message text to prevent stacking.
|
|
24
25
|
* prependContext persists in conversation history — without stripping,
|
|
25
26
|
* each turn accumulates another full injection (~20K tokens). */
|
|
26
|
-
const MEMORY_TAG_RE = /<
|
|
27
|
+
const MEMORY_TAG_RE = /<mr-memory>[\s\S]*?<\/mr-memory>\s*/g;
|
|
28
|
+
/** Legacy tag pattern for backward compat (pre-2.7.0 injections still in history) */
|
|
29
|
+
const LEGACY_TAG_RE = /<memory_context>[\s\S]*?<\/memory_context>\s*(?:The above are retrieved memories|IMPORTANT: The above block contains retrieved memories)[^\n]*\n*/g;
|
|
27
30
|
function stripOldMemory(text: string): string {
|
|
28
|
-
return text.replace(MEMORY_TAG_RE, "").trim();
|
|
31
|
+
return text.replace(MEMORY_TAG_RE, "").replace(LEGACY_TAG_RE, "").trim();
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
// Workspace files OpenClaw loads into the system prompt
|
|
@@ -168,6 +171,7 @@ const memoryRouterPlugin = {
|
|
|
168
171
|
// When PR #24122 merges, OpenClaw will use the returned prependContext.
|
|
169
172
|
// This gives forward compatibility — no plugin update needed.
|
|
170
173
|
api.on("llm_input", async (event, ctx) => {
|
|
174
|
+
api.logger.warn?.(`memoryrouter: llm_input fired (sessionKey=${ctx.sessionKey}, promptBuildFired=${promptBuildFiredThisRun})`);
|
|
171
175
|
// Skip the first call — before_prompt_build already handled it
|
|
172
176
|
// (before_prompt_build includes workspace+tools+skills for accurate billing)
|
|
173
177
|
if (promptBuildFiredThisRun) {
|
|
@@ -227,7 +231,7 @@ const memoryRouterPlugin = {
|
|
|
227
231
|
api.logger.info?.(
|
|
228
232
|
`memoryrouter: injected ${data.memories_found || 0} memories on tool iteration (${data.tokens_billed || 0} tokens billed)`,
|
|
229
233
|
);
|
|
230
|
-
return { prependContext:
|
|
234
|
+
return { prependContext: wrapForInjection(data.context) };
|
|
231
235
|
}
|
|
232
236
|
} catch {
|
|
233
237
|
// Silent fail on tool iterations — don't block the agent
|
|
@@ -237,6 +241,7 @@ const memoryRouterPlugin = {
|
|
|
237
241
|
// ── before_prompt_build: fires once per run (primary, includes full billing context)
|
|
238
242
|
api.on("before_prompt_build", async (event, ctx) => {
|
|
239
243
|
promptBuildFiredThisRun = true;
|
|
244
|
+
api.logger.warn?.(`memoryrouter: before_prompt_build fired (sessionKey=${ctx.sessionKey}, promptLen=${event.prompt?.length})`);
|
|
240
245
|
try {
|
|
241
246
|
const prompt = event.prompt;
|
|
242
247
|
|
|
@@ -327,7 +332,7 @@ const memoryRouterPlugin = {
|
|
|
327
332
|
api.logger.info?.(
|
|
328
333
|
`memoryrouter: injected ${data.memories_found || 0} memories (${data.tokens_billed || 0} tokens billed)`,
|
|
329
334
|
);
|
|
330
|
-
return { prependContext:
|
|
335
|
+
return { prependContext: wrapForInjection(data.context) };
|
|
331
336
|
}
|
|
332
337
|
} catch (err) {
|
|
333
338
|
api.logger.warn?.(
|