Skip to content

Commit 230fdc5

Browse files
authored
Fix/memory v2 (#1452)
1 parent 283dce7 commit 230fdc5

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

examples/openclaw-plugin/text-utils.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const FENCED_JSON_BLOCK_RE = /```json\s*([\s\S]*?)```/gi;
2020
const METADATA_JSON_KEY_RE =
2121
/"(session|sessionid|sessionkey|conversationid|channel|sender|userid|agentid|timestamp|timezone)"\s*:/gi;
2222
const LEADING_TIMESTAMP_PREFIX_RE = /^\s*(?!\[\[)\[(?:(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)[a-z]*\s+)?(?:\d{4}[-/]\d{2}[-/]\d{2}|\d{2}[-/]\d{2}[-/]\d{2,4})(?:\s+\d{1,2}:\d{2}(?::\d{2})?(?:\s*[A-Z]{1,5}(?:[+-]\d{1,2})?)?)?\s*\]\s*/i;
23-
const COMPACTED_SYSTEM_MSG_RE = /^System:\s*\[.*?\]\s*Compacted/i;
23+
const COMPACTED_SYSTEM_MSG_RE = /^System:\s*\[.*?\]\s*Compacted\s*(.+)$/i;
2424
const COMMAND_TEXT_RE = /^\/[a-z0-9_-]{1,64}\b/i;
2525
const NON_CONTENT_TEXT_RE = /^[\p{P}\p{S}\s]+$/u;
2626
const SUBAGENT_CONTEXT_RE = /^\s*\[Subagent Context\]/i;
@@ -57,11 +57,9 @@ export function sanitizeUserTextForCapture(text: string): string {
5757
// 处理 Compactor 系统消息,提取实际用户输入
5858
// 格式: "System: [时间] Compacted ... Context ... [时间] 实际内容"
5959
if (COMPACTED_SYSTEM_MSG_RE.test(text)) {
60-
// 提取最后一个 ] 之后的内容(即实际用户输入)
61-
const lastBracketIndex = text.lastIndexOf("]");
62-
if (lastBracketIndex !== -1) {
63-
const content = text.slice(lastBracketIndex + 1);
64-
return content.replace(/\s+/g, " ").trim();
60+
const match = text.match(COMPACTED_SYSTEM_MSG_RE);
61+
if (match) {
62+
return match[1].replace(/\s+/g, " ").trim();
6563
}
6664
return "";
6765
}

0 commit comments

Comments
 (0)