mr-memory 3.5.1 → 3.6.1
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 +46 -6
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -246,6 +246,15 @@ function isSystemNoise(text: string): boolean {
|
|
|
246
246
|
return SYSTEM_NOISE_PATTERNS.some(pattern => pattern.test(trimmed));
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/** Strip cron/system prefixes from prompts, keeping the actual task content.
|
|
250
|
+
* Used for prepare context building — we want the mission text, not the tag. */
|
|
251
|
+
function stripSystemPrefixes(text: string): string {
|
|
252
|
+
return text
|
|
253
|
+
.replace(/^\[cron:[^\]]+\]\s*/i, "")
|
|
254
|
+
.replace(/^A background task "[^"]*" just completed[^\n]*\n*/i, "")
|
|
255
|
+
.trim();
|
|
256
|
+
}
|
|
257
|
+
|
|
249
258
|
/**
|
|
250
259
|
* Detect OpenClaw compaction summary blobs — large user messages containing
|
|
251
260
|
* interleaved [USER] and [ASSISTANT] markers from conversation history dumps.
|
|
@@ -408,6 +417,25 @@ const memoryRouterPlugin = {
|
|
|
408
417
|
api.logger.info?.("memoryrouter: get your free API key at https://memoryrouter.ai");
|
|
409
418
|
}
|
|
410
419
|
|
|
420
|
+
// ==================================================================
|
|
421
|
+
// Onboarding: plugin installed but no key yet — prepend setup context
|
|
422
|
+
// ==================================================================
|
|
423
|
+
|
|
424
|
+
if (!hasAnyKey) {
|
|
425
|
+
const onboardedSessions = new Set<string>();
|
|
426
|
+
|
|
427
|
+
api.on("before_prompt_build", async (_event, ctx) => {
|
|
428
|
+
const sessionKey = ctx.sessionKey || "default";
|
|
429
|
+
if (onboardedSessions.has(sessionKey)) return;
|
|
430
|
+
onboardedSessions.add(sessionKey);
|
|
431
|
+
|
|
432
|
+
return {
|
|
433
|
+
prependContext:
|
|
434
|
+
"MemoryRouter is installed but not activated yet. If relevant, briefly and naturally tell the user they can enable persistent memory by getting a free API key at https://memoryrouter.ai and running `openclaw mr <key>`. Mention that once activated, OpenClaw will remember past conversations across sessions. Do not force this if the conversation is unrelated, but it's okay to mention it early after install.",
|
|
435
|
+
};
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
|
|
411
439
|
// ==================================================================
|
|
412
440
|
// Core: before_agent_start — search memories, inject context
|
|
413
441
|
// ==================================================================
|
|
@@ -464,8 +492,12 @@ const memoryRouterPlugin = {
|
|
|
464
492
|
}
|
|
465
493
|
}
|
|
466
494
|
const cleanedPrompt = sanitizeForIngest(prompt);
|
|
467
|
-
if (cleanedPrompt
|
|
468
|
-
|
|
495
|
+
if (cleanedPrompt) {
|
|
496
|
+
// Strip cron/system prefixes but keep the task content for memory search
|
|
497
|
+
const taskPrompt = stripSystemPrefixes(cleanedPrompt);
|
|
498
|
+
if (taskPrompt && !isSystemNoise(taskPrompt)) {
|
|
499
|
+
contextPayload.push({ role: "user", content: taskPrompt });
|
|
500
|
+
}
|
|
469
501
|
}
|
|
470
502
|
|
|
471
503
|
|
|
@@ -575,8 +607,12 @@ const memoryRouterPlugin = {
|
|
|
575
607
|
|
|
576
608
|
// Add current user prompt (sanitized)
|
|
577
609
|
const cleanedPrompt = sanitizeForIngest(prompt);
|
|
578
|
-
if (cleanedPrompt
|
|
579
|
-
|
|
610
|
+
if (cleanedPrompt) {
|
|
611
|
+
// Strip cron/system prefixes but keep the task content for memory search
|
|
612
|
+
const taskPrompt = stripSystemPrefixes(cleanedPrompt);
|
|
613
|
+
if (taskPrompt && !isSystemNoise(taskPrompt)) {
|
|
614
|
+
contextPayload.push({ role: "user", content: taskPrompt });
|
|
615
|
+
}
|
|
580
616
|
}
|
|
581
617
|
|
|
582
618
|
// 4. Call /v1/memory/prepare (no session_id — always search core vault)
|
|
@@ -671,8 +707,12 @@ const memoryRouterPlugin = {
|
|
|
671
707
|
if (userText) {
|
|
672
708
|
// Sanitize: strip memory injections, envelope metadata, and system noise
|
|
673
709
|
userText = sanitizeForIngest(stripMediaReferences(userText));
|
|
674
|
-
if (userText
|
|
675
|
-
|
|
710
|
+
if (userText) {
|
|
711
|
+
// Strip cron/system prefixes but keep the task content for storage
|
|
712
|
+
const taskText = stripSystemPrefixes(userText);
|
|
713
|
+
if (taskText && !isSystemNoise(taskText)) {
|
|
714
|
+
toStore.push({ role: "user", content: taskText });
|
|
715
|
+
}
|
|
676
716
|
}
|
|
677
717
|
}
|
|
678
718
|
}
|