mr-memory 2.13.0 → 2.14.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 +34 -3
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -53,9 +53,10 @@ function stripOldMemory(text: string): string {
53
53
  const SYSTEM_NOISE_PATTERNS = [
54
54
  // Heartbeat prompts and responses
55
55
  /^Read HEARTBEAT\.md if it exists/,
56
- /^HEARTBEAT_OK\s*$/,
56
+ /^Read HEARTBEAT\.md/,
57
+ /HEARTBEAT_OK\s*$/,
57
58
  // Pre-compaction flush prompts
58
- /^Pre-compaction memory flush\./,
59
+ /^Pre-compaction memory flush/,
59
60
  // Post-compaction audit warnings
60
61
  /⚠️ Post-Compaction Audit:/,
61
62
  // Silent reply ack
@@ -73,6 +74,12 @@ const SYSTEM_NOISE_PATTERNS = [
73
74
  /^Store durable memories now/,
74
75
  // Current time system lines (injected by OpenClaw into system events)
75
76
  /^Current time: .+\(America\//,
77
+ // New session notice
78
+ /^A new session was started via \/new or \/reset/,
79
+ // Post-compaction recovery instructions
80
+ /^Please read them now using the Read tool/,
81
+ /^GatewayRestart:\s*\{/,
82
+ /^This ensures your operating protocols are restored/,
76
83
  ];
77
84
 
78
85
  /** Strip OpenClaw envelope metadata from user messages */
@@ -82,6 +89,12 @@ const REPLY_CONTEXT_RE = /Replied message \(untrusted, for context\):\s*```json\
82
89
  const MEMORY_INSTRUCTION_RE = /The above are retrieved memories from past conversations[^\n]*\n*/g;
83
90
  const IMPORTANT_MEMORY_RE = /IMPORTANT: The above (?:are retrieved memories|block contains retrieved memories)[^\n]*\n*/g;
84
91
 
92
+ // Embedded noise substrings — strip from within larger messages
93
+ const POST_COMPACTION_AUDIT_RE = /System: \[[^\]]*\] ⚠️ Post-Compaction Audit:[\s\S]*?(?:after memory compaction\.\s*|before continuing\.\s*)/g;
94
+ const READ_TOOL_INSTRUCTION_RE = /Please read them now using the Read tool before continuing\.[\s\S]*?after memory compaction\.\s*/g;
95
+ const TELEGRAM_ENVELOPE_RE = /\[Telegram [^\]]+\]\s*/g;
96
+ const MESSAGE_ID_TAG_RE = /\[message_id: \d+\]\s*/g;
97
+
85
98
  /** Sanitize text before storing in memory — removes system noise and envelope metadata */
86
99
  function sanitizeForIngest(text: string): string {
87
100
  // 1. Strip our own memory injection wrapper (already exists as stripOldMemory)
@@ -92,7 +105,11 @@ function sanitizeForIngest(text: string): string {
92
105
  .replace(SENDER_METADATA_RE, "")
93
106
  .replace(REPLY_CONTEXT_RE, "")
94
107
  .replace(MEMORY_INSTRUCTION_RE, "")
95
- .replace(IMPORTANT_MEMORY_RE, "");
108
+ .replace(IMPORTANT_MEMORY_RE, "")
109
+ .replace(POST_COMPACTION_AUDIT_RE, "")
110
+ .replace(READ_TOOL_INSTRUCTION_RE, "")
111
+ .replace(TELEGRAM_ENVELOPE_RE, "")
112
+ .replace(MESSAGE_ID_TAG_RE, "");
96
113
  // 3. Collapse excessive whitespace from removals
97
114
  cleaned = cleaned.replace(/\n{3,}/g, "\n\n").trim();
98
115
  return cleaned;
@@ -105,6 +122,18 @@ function isSystemNoise(text: string): boolean {
105
122
  return SYSTEM_NOISE_PATTERNS.some(pattern => pattern.test(trimmed));
106
123
  }
107
124
 
125
+ /**
126
+ * Detect OpenClaw compaction summary blobs — large user messages containing
127
+ * interleaved [USER] and [ASSISTANT] markers from conversation history dumps.
128
+ * These are 100% redundant since individual messages are already uploaded.
129
+ */
130
+ function isCompactionSummary(text: string, role: string): boolean {
131
+ if (role !== "user") return false;
132
+ if (text.length < 2000) return false;
133
+ const markers = (text.match(/\[(?:USER|ASSISTANT)[\] ]/g) || []).length;
134
+ return markers >= 3;
135
+ }
136
+
108
137
  // Workspace files OpenClaw loads into the system prompt
109
138
  const WORKSPACE_FILES = [
110
139
  "IDENTITY.md", "USER.md", "MEMORY.md", "HEARTBEAT.md",
@@ -280,6 +309,7 @@ const memoryRouterPlugin = {
280
309
  // Sanitize ALL roles: strip memory injections, envelope metadata, system noise
281
310
  const cleaned = sanitizeForIngest(text);
282
311
  if (!cleaned || isSystemNoise(cleaned)) continue;
312
+ if (isCompactionSummary(cleaned, m.role || "")) continue;
283
313
  contextPayload.push({ role: m.role, content: cleaned });
284
314
  }
285
315
  }
@@ -386,6 +416,7 @@ const memoryRouterPlugin = {
386
416
  // Sanitize ALL roles: strip memory injections, envelope metadata, system noise
387
417
  const cleaned = sanitizeForIngest(text);
388
418
  if (!cleaned || isSystemNoise(cleaned)) continue;
419
+ if (isCompactionSummary(cleaned, m.role || "")) continue;
389
420
  contextPayload.push({ role: m.role, content: cleaned });
390
421
  }
391
422
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mr-memory",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "description": "MemoryRouter persistent memory plugin for OpenClaw — your AI remembers every conversation",
5
5
  "type": "module",
6
6
  "files": [