mr-memory 2.5.3 → 2.6.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.
Files changed (2) hide show
  1. package/index.ts +15 -5
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -20,6 +20,14 @@ function wrapMemoryContext(context: string): string {
20
20
  return `<memory_context>\n${context}\n</memory_context>\n\nThe above are retrieved memories from past conversations — not current events. Reference them as background context with appropriate temporal framing. Do not treat them as part of the current message or present moment.`;
21
21
  }
22
22
 
23
+ /** Strip previous memory injections from message text to prevent stacking.
24
+ * prependContext persists in conversation history — without stripping,
25
+ * each turn accumulates another full injection (~20K tokens). */
26
+ const MEMORY_TAG_RE = /<memory_context>[\s\S]*?<\/memory_context>\s*The above are retrieved memories from past conversations[^\n]*\n*/g;
27
+ function stripOldMemory(text: string): string {
28
+ return text.replace(MEMORY_TAG_RE, "").trim();
29
+ }
30
+
23
31
  // Workspace files OpenClaw loads into the system prompt
24
32
  const WORKSPACE_FILES = [
25
33
  "IDENTITY.md", "USER.md", "MEMORY.md", "HEARTBEAT.md",
@@ -186,10 +194,11 @@ const memoryRouterPlugin = {
186
194
  .map(b => b.text!)
187
195
  .join("\n");
188
196
  }
189
- if (text) contextPayload.push({ role: m.role, content: text });
197
+ // Strip old memory injections to prevent stacking
198
+ if (text) contextPayload.push({ role: m.role, content: m.role === "user" ? stripOldMemory(text) : text });
190
199
  }
191
200
  }
192
- contextPayload.push({ role: "user", content: prompt });
201
+ contextPayload.push({ role: "user", content: stripOldMemory(prompt) });
193
202
 
194
203
 
195
204
  const res = await fetch(`${endpoint}/v1/memory/prepare`, {
@@ -276,15 +285,16 @@ const memoryRouterPlugin = {
276
285
  }
277
286
 
278
287
  if (text) {
279
- contextPayload.push({ role: m.role, content: text });
288
+ // Strip old memory injections to prevent stacking
289
+ contextPayload.push({ role: m.role, content: m.role === "user" ? stripOldMemory(text) : text });
280
290
  } else {
281
291
  skipped++;
282
292
  }
283
293
  }
284
294
  }
285
295
 
286
- // Add current user prompt
287
- contextPayload.push({ role: "user", content: prompt });
296
+ // Add current user prompt (strip any residual memory tags)
297
+ contextPayload.push({ role: "user", content: stripOldMemory(prompt) });
288
298
 
289
299
  // 4. Call /v1/memory/prepare
290
300
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mr-memory",
3
- "version": "2.5.3",
3
+ "version": "2.6.0",
4
4
  "description": "MemoryRouter persistent memory plugin for OpenClaw — your AI remembers every conversation",
5
5
  "type": "module",
6
6
  "files": [