fix: ignorePatterns tests message text not object, add warn for bad regex

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-31 14:27:22 +10:00
co-authored by Claude Sonnet 4.6
parent 8db3154cff
commit e4ac7acaed
+7 -5
View File
@@ -340,8 +340,9 @@ const plugin = {
} }
// Count real user messages (exclude system, metadata-only, short commands) // Count real user messages (exclude system, metadata-only, short commands)
const realUserMsgs = messages.filter(m => { // Returns cleaned text strings so ignore-pattern regex can test against actual content.
if (m?.role !== "user") return false; const realUserMsgs = messages.reduce((acc, m) => {
if (m?.role !== "user") return acc;
const text = typeof m?.content === "string" ? m.content const text = typeof m?.content === "string" ? m.content
: Array.isArray(m?.content) ? m.content.filter(b => b?.type === "text").map(b => b.text).join("\n") : Array.isArray(m?.content) ? m.content.filter(b => b?.type === "text").map(b => b.text).join("\n")
: ""; : "";
@@ -350,12 +351,13 @@ const plugin = {
.replace(/^Sender \(untrusted metadata\):[\s\S]*?\n\n/m, "") .replace(/^Sender \(untrusted metadata\):[\s\S]*?\n\n/m, "")
.trim(); .trim();
// Skip very short messages like "/new", "/status", single-word queries // Skip very short messages like "/new", "/status", single-word queries
return cleaned.length > 10; if (cleaned.length > 10) acc.push(cleaned);
}); return acc;
}, []);
// Check ignore patterns — skip sessions matching cron/subagent noise // Check ignore patterns — skip sessions matching cron/subagent noise
const ignorePatterns = (config.ignorePatterns || []) const ignorePatterns = (config.ignorePatterns || [])
.map(p => { try { return new RegExp(p, "i"); } catch { return null; } }) .map(p => { try { return new RegExp(p, "i"); } catch { log.warn?.("[memory-continuity] ignorePatterns: invalid regex, skipping: " + p); return null; } })
.filter(Boolean); .filter(Boolean);
if (ignorePatterns.length > 0 && realUserMsgs.length > 0) { if (ignorePatterns.length > 0 && realUserMsgs.length > 0) {