mr-memory 2.12.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.
- package/index.ts +34 -3
- package/package.json +1 -1
- package/upload.ts +30 -3
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
|
-
/^
|
|
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
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
|
-
/^
|
|
54
|
-
|
|
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") {
|