From 6d88a78cca2329a8f63c23592782710c11895bf8 Mon Sep 17 00:00:00 2001 From: sean Date: Sun, 15 Jun 2025 16:09:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DRecallCommand.js=E4=B8=AD?= =?UTF-8?q?=E7=9A=84parseMemoryLine=E6=96=B9=E6=B3=95=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=E4=BB=A5?= =?UTF-8?q?=E9=80=82=E9=85=8D=E6=96=B0=E7=9A=84=E8=AE=B0=E5=BF=86=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=BC=BA=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=80=BB=E8=BE=91=E3=80=82=E6=94=B9=E5=8A=A8?= =?UTF-8?q?=E5=8C=85=E6=8B=AC=E6=94=AF=E6=8C=81--tags=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AE=B9=E5=88=86=E7=A6=BB=E5=92=8C=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E6=8F=90=E5=8F=96=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BA=86?= =?UTF-8?q?=E8=AE=B0=E5=BF=86=E8=A1=8C=E8=A7=A3=E6=9E=90=E7=9A=84=E7=81=B5?= =?UTF-8?q?=E6=B4=BB=E6=80=A7=E5=92=8C=E5=87=86=E7=A1=AE=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/core/pouch/commands/RecallCommand.js | 33 +++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/lib/core/pouch/commands/RecallCommand.js b/src/lib/core/pouch/commands/RecallCommand.js index eb68b13..04e9219 100644 --- a/src/lib/core/pouch/commands/RecallCommand.js +++ b/src/lib/core/pouch/commands/RecallCommand.js @@ -121,12 +121,37 @@ ${formattedMemories} * 解析记忆行(紧凑格式) */ parseMemoryLine (line) { - // 格式:- 2025/05/31 14:30 内容 #tag1 #tag2 #评分:8 #有效期:长期 - const match = line.match(/^- (\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}) (.*?) (#.*?)$/) + // 修复正则表达式,适配实际的记忆格式 + // 格式:- 2025/05/31 14:30 内容 --tags 标签 ##分类 #评分:8 #有效期:长期 + const match = line.match(/^- (\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}) (.+)$/) if (!match) return null - const [, timestamp, content, tagsStr] = match - const tags = tagsStr.split(' ').filter(t => t.startsWith('#')) + const [, timestamp, contentAndTags] = match + + // 分离内容和标签 + let content = contentAndTags + let tags = [] + + // 提取 --tags 后面的内容 + const tagsMatch = contentAndTags.match(/--tags\s+(.*)/) + if (tagsMatch) { + const beforeTags = contentAndTags.substring(0, contentAndTags.indexOf('--tags')).trim() + content = beforeTags + + // 解析标签部分,包括 --tags 后的内容和 # 开头的标签 + const tagsContent = tagsMatch[1] + const hashTags = tagsContent.match(/#[^\s]+/g) || [] + const regularTags = tagsContent.replace(/#[^\s]+/g, '').trim().split(/\s+/).filter(t => t) + + tags = [...regularTags, ...hashTags] + } else { + // 如果没有 --tags,检查是否有直接的 # 标签 + const hashTags = contentAndTags.match(/#[^\s]+/g) || [] + if (hashTags.length > 0) { + content = contentAndTags.replace(/#[^\s]+/g, '').trim() + tags = hashTags + } + } return { timestamp,