mr-memory 2.13.0 → 2.15.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 (3) hide show
  1. package/index.ts +56 -3
  2. package/package.json +1 -1
  3. package/upload.ts +23 -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,22 @@ 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/,
83
+ // Cron job prompts — automated system instructions, not human conversation
84
+ /^\[cron:[^\]]+\]/,
85
+ // Sub-agent completion announcements (system-generated)
86
+ /^A background task "[^"]*" just completed/,
87
+ // Sub-agent stats lines
88
+ /^Stats: runtime \d+/,
89
+ // Summarize instruction for sub-agent completions
90
+ /^Summarize this naturally for the user/,
91
+ // Session reset greet prompts
92
+ /^Greet the user in your configured persona/,
76
93
  ];
77
94
 
78
95
  /** Strip OpenClaw envelope metadata from user messages */
@@ -82,6 +99,12 @@ const REPLY_CONTEXT_RE = /Replied message \(untrusted, for context\):\s*```json\
82
99
  const MEMORY_INSTRUCTION_RE = /The above are retrieved memories from past conversations[^\n]*\n*/g;
83
100
  const IMPORTANT_MEMORY_RE = /IMPORTANT: The above (?:are retrieved memories|block contains retrieved memories)[^\n]*\n*/g;
84
101
 
102
+ // Embedded noise substrings — strip from within larger messages
103
+ const POST_COMPACTION_AUDIT_RE = /System: \[[^\]]*\] ⚠️ Post-Compaction Audit:[\s\S]*?(?:after memory compaction\.\s*|before continuing\.\s*)/g;
104
+ const READ_TOOL_INSTRUCTION_RE = /Please read them now using the Read tool before continuing\.[\s\S]*?after memory compaction\.\s*/g;
105
+ const TELEGRAM_ENVELOPE_RE = /\[Telegram [^\]]+\]\s*/g;
106
+ const MESSAGE_ID_TAG_RE = /\[message_id: \d+\]\s*/g;
107
+
85
108
  /** Sanitize text before storing in memory — removes system noise and envelope metadata */
86
109
  function sanitizeForIngest(text: string): string {
87
110
  // 1. Strip our own memory injection wrapper (already exists as stripOldMemory)
@@ -92,7 +115,23 @@ function sanitizeForIngest(text: string): string {
92
115
  .replace(SENDER_METADATA_RE, "")
93
116
  .replace(REPLY_CONTEXT_RE, "")
94
117
  .replace(MEMORY_INSTRUCTION_RE, "")
95
- .replace(IMPORTANT_MEMORY_RE, "");
118
+ .replace(IMPORTANT_MEMORY_RE, "")
119
+ .replace(POST_COMPACTION_AUDIT_RE, "")
120
+ .replace(READ_TOOL_INSTRUCTION_RE, "")
121
+ .replace(TELEGRAM_ENVELOPE_RE, "")
122
+ .replace(MESSAGE_ID_TAG_RE, "")
123
+ // Embedded noise substrings — v2.15.0
124
+ .replace(/Pre-compaction memory flush\.?\s*(?:Store durable memories now[^\n]*\n?)*(?:IMPORTANT:[^\n]*\n?)?(?:Current time:[^\n]*\n?)?/g, "")
125
+ .replace(/`?HEARTBEAT_OK`?\s*/g, "")
126
+ .replace(/Read HEARTBEAT\.md[^\n]*(?:\n(?:Follow it strictly|Do not infer|If nothing needs)[^\n]*)*/g, "")
127
+ .replace(/\n*\s*NO_REPLY\s*$/g, "")
128
+ .replace(/You can respond with NO_REPLY[^\n]*\n*/g, "")
129
+ .replace(/If nothing to store,? reply (?:with )?NO_REPLY[^\n]*\n*/g, "")
130
+ .replace(/Store durable memories now[^\n]*\n*/g, "")
131
+ .replace(/This ensures your operating protocols are restored[^\n]*\n*/g, "")
132
+ .replace(/Current time:[^\n]*\n*/g, "")
133
+ .replace(/\bset:\s*\n\s*-\s*WORKFLOW_AUTO\.md[^\n]*\n(?:\s*-\s*memory[^\n]*\n)*/g, "")
134
+ .replace(/Do not mention technical details[^\n]*\n*/g, "");
96
135
  // 3. Collapse excessive whitespace from removals
97
136
  cleaned = cleaned.replace(/\n{3,}/g, "\n\n").trim();
98
137
  return cleaned;
@@ -105,6 +144,18 @@ function isSystemNoise(text: string): boolean {
105
144
  return SYSTEM_NOISE_PATTERNS.some(pattern => pattern.test(trimmed));
106
145
  }
107
146
 
147
+ /**
148
+ * Detect OpenClaw compaction summary blobs — large user messages containing
149
+ * interleaved [USER] and [ASSISTANT] markers from conversation history dumps.
150
+ * These are 100% redundant since individual messages are already uploaded.
151
+ */
152
+ function isCompactionSummary(text: string, role: string): boolean {
153
+ if (role !== "user") return false;
154
+ if (text.length < 2000) return false;
155
+ const markers = (text.match(/\[(?:USER|ASSISTANT)[\] ]/g) || []).length;
156
+ return markers >= 3;
157
+ }
158
+
108
159
  // Workspace files OpenClaw loads into the system prompt
109
160
  const WORKSPACE_FILES = [
110
161
  "IDENTITY.md", "USER.md", "MEMORY.md", "HEARTBEAT.md",
@@ -280,6 +331,7 @@ const memoryRouterPlugin = {
280
331
  // Sanitize ALL roles: strip memory injections, envelope metadata, system noise
281
332
  const cleaned = sanitizeForIngest(text);
282
333
  if (!cleaned || isSystemNoise(cleaned)) continue;
334
+ if (isCompactionSummary(cleaned, m.role || "")) continue;
283
335
  contextPayload.push({ role: m.role, content: cleaned });
284
336
  }
285
337
  }
@@ -386,6 +438,7 @@ const memoryRouterPlugin = {
386
438
  // Sanitize ALL roles: strip memory injections, envelope metadata, system noise
387
439
  const cleaned = sanitizeForIngest(text);
388
440
  if (!cleaned || isSystemNoise(cleaned)) continue;
441
+ if (isCompactionSummary(cleaned, m.role || "")) continue;
389
442
  contextPayload.push({ role: m.role, content: cleaned });
390
443
  }
391
444
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mr-memory",
3
- "version": "2.13.0",
3
+ "version": "2.15.0",
4
4
  "description": "MemoryRouter persistent memory plugin for OpenClaw — your AI remembers every conversation",
5
5
  "type": "module",
6
6
  "files": [
package/upload.ts CHANGED
@@ -53,7 +53,19 @@ function sanitizeForUpload(text: string): string {
53
53
  .replace(POST_COMPACTION_AUDIT_RE, "")
54
54
  .replace(READ_TOOL_INSTRUCTION_RE, "")
55
55
  .replace(TELEGRAM_ENVELOPE_RE, "")
56
- .replace(MESSAGE_ID_TAG_RE, "");
56
+ .replace(MESSAGE_ID_TAG_RE, "")
57
+ // Embedded noise substrings — v2.15.0
58
+ .replace(/Pre-compaction memory flush\.?\s*(?:Store durable memories now[^\n]*\n?)*(?:IMPORTANT:[^\n]*\n?)?(?:Current time:[^\n]*\n?)?/g, "")
59
+ .replace(/`?HEARTBEAT_OK`?\s*/g, "")
60
+ .replace(/Read HEARTBEAT\.md[^\n]*(?:\n(?:Follow it strictly|Do not infer|If nothing needs)[^\n]*)*/g, "")
61
+ .replace(/\n*\s*NO_REPLY\s*$/g, "")
62
+ .replace(/You can respond with NO_REPLY[^\n]*\n*/g, "")
63
+ .replace(/If nothing to store,? reply (?:with )?NO_REPLY[^\n]*\n*/g, "")
64
+ .replace(/Store durable memories now[^\n]*\n*/g, "")
65
+ .replace(/This ensures your operating protocols are restored[^\n]*\n*/g, "")
66
+ .replace(/Current time:[^\n]*\n*/g, "")
67
+ .replace(/\bset:\s*\n\s*-\s*WORKFLOW_AUTO\.md[^\n]*\n(?:\s*-\s*memory[^\n]*\n)*/g, "")
68
+ .replace(/Do not mention technical details[^\n]*\n*/g, "");
57
69
  cleaned = cleaned.replace(/\n{3,}/g, "\n\n").trim();
58
70
  return cleaned;
59
71
  }
@@ -76,6 +88,16 @@ const SYSTEM_NOISE_PATTERNS = [
76
88
  /^Please read them now using the Read tool/,
77
89
  /^GatewayRestart:\s*\{/,
78
90
  /^This ensures your operating protocols are restored/,
91
+ // Cron job prompts — automated system instructions, not human conversation
92
+ /^\[cron:[^\]]+\]/,
93
+ // Sub-agent completion announcements (system-generated)
94
+ /^A background task "[^"]*" just completed/,
95
+ // Sub-agent stats lines
96
+ /^Stats: runtime \d+/,
97
+ // Summarize instruction for sub-agent completions
98
+ /^Summarize this naturally for the user/,
99
+ // Session reset greet prompts
100
+ /^Greet the user in your configured persona/,
79
101
  ];
80
102
 
81
103
  function isSystemNoise(text: string): boolean {