mr-memory 2.12.0 → 2.13.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/package.json +1 -1
  2. package/upload.ts +30 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mr-memory",
3
- "version": "2.12.0",
3
+ "version": "2.13.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
@@ -35,6 +35,12 @@ function stripMediaReferences(text: string): string {
35
35
  .replace(/\n{3,}/g, "\n\n");
36
36
  }
37
37
 
38
+ // Embedded noise substrings — strip from within larger messages
39
+ const POST_COMPACTION_AUDIT_RE = /System: \[[^\]]*\] ⚠️ Post-Compaction Audit:[\s\S]*?(?:after memory compaction\.\s*|before continuing\.\s*)/g;
40
+ const READ_TOOL_INSTRUCTION_RE = /Please read them now using the Read tool before continuing\.[\s\S]*?after memory compaction\.\s*/g;
41
+ const TELEGRAM_ENVELOPE_RE = /\[Telegram [^\]]+\]\s*/g;
42
+ const MESSAGE_ID_TAG_RE = /\[message_id: \d+\]\s*/g;
43
+
38
44
  function sanitizeForUpload(text: string): string {
39
45
  let cleaned = stripOldMemory(text);
40
46
  cleaned = stripMediaReferences(cleaned);
@@ -43,15 +49,20 @@ function sanitizeForUpload(text: string): string {
43
49
  .replace(SENDER_METADATA_RE, "")
44
50
  .replace(REPLY_CONTEXT_RE, "")
45
51
  .replace(MEMORY_INSTRUCTION_RE, "")
46
- .replace(IMPORTANT_MEMORY_RE, "");
52
+ .replace(IMPORTANT_MEMORY_RE, "")
53
+ .replace(POST_COMPACTION_AUDIT_RE, "")
54
+ .replace(READ_TOOL_INSTRUCTION_RE, "")
55
+ .replace(TELEGRAM_ENVELOPE_RE, "")
56
+ .replace(MESSAGE_ID_TAG_RE, "");
47
57
  cleaned = cleaned.replace(/\n{3,}/g, "\n\n").trim();
48
58
  return cleaned;
49
59
  }
50
60
 
51
61
  const SYSTEM_NOISE_PATTERNS = [
52
62
  /^Read HEARTBEAT\.md if it exists/,
53
- /^HEARTBEAT_OK\s*$/,
54
- /^Pre-compaction memory flush\./,
63
+ /^Read HEARTBEAT\.md/,
64
+ /HEARTBEAT_OK\s*$/,
65
+ /^Pre-compaction memory flush/,
55
66
  /⚠️ Post-Compaction Audit:/,
56
67
  /^NO_REPLY\s*$/,
57
68
  /^Note: The previous agent run was aborted/,
@@ -62,6 +73,9 @@ const SYSTEM_NOISE_PATTERNS = [
62
73
  /^Store durable memories now/,
63
74
  /^Current time: .+\(America\//,
64
75
  /^A new session was started via \/new or \/reset/,
76
+ /^Please read them now using the Read tool/,
77
+ /^GatewayRestart:\s*\{/,
78
+ /^This ensures your operating protocols are restored/,
65
79
  ];
66
80
 
67
81
  function isSystemNoise(text: string): boolean {
@@ -70,6 +84,18 @@ function isSystemNoise(text: string): boolean {
70
84
  return SYSTEM_NOISE_PATTERNS.some(pattern => pattern.test(trimmed));
71
85
  }
72
86
 
87
+ /**
88
+ * Detect OpenClaw compaction summary blobs — large user messages containing
89
+ * interleaved [USER] and [ASSISTANT] markers from conversation history dumps.
90
+ * These are 100% redundant since individual messages are already uploaded.
91
+ */
92
+ function isCompactionSummary(text: string, role: string): boolean {
93
+ if (role !== "user") return false;
94
+ if (text.length < 2000) return false;
95
+ const markers = (text.match(/\[(?:USER|ASSISTANT)[\] ]/g) || []).length;
96
+ return markers >= 3;
97
+ }
98
+
73
99
  type MemoryLine = {
74
100
  content: string;
75
101
  role: "user" | "assistant";
@@ -183,6 +209,7 @@ async function sessionToJsonl(filePath: string): Promise<MemoryLine[]> {
183
209
  text = sanitizeForUpload(text);
184
210
  if (!text || text.trim().length < 20) continue;
185
211
  if (isSystemNoise(text)) continue;
212
+ if (isCompactionSummary(text, msg.role)) continue;
186
213
 
187
214
  let timestamp: number;
188
215
  if (typeof parsed.timestamp === "string") {