From c5ca2e0bf60abe31ab52ac9787b85fe2a62a3e99 Mon Sep 17 00:00:00 2001 From: kicer Date: Tue, 29 Sep 2026 17:31:28 +0800 Subject: [PATCH] =?UTF-8?q?refactor(recall):=20=E5=9B=9E=E6=89=A7=E5=8E=BB?= =?UTF-8?q?=E6=95=99=E5=AD=A6=E5=8C=96=E2=80=94=E2=80=94=E5=B0=BE=E9=83=A8?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=8C=87=E5=BC=95=E6=B8=85=E9=99=A4=EF=BC=8C?= =?UTF-8?q?=E7=A9=BA=E6=80=81=E4=B8=80=E5=8F=A5=E8=AF=9D=EF=BC=8C=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E5=A4=B4=E8=A1=8C=E7=98=A6=E8=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 与 schedule 回执同病同治(规范 §六:怎么做写在 schema description,运行时只给事实): - search 空态:'换个更宽泛的关键词再试,或 op=days…' → '日记中无「q」相关记录。'; 命中数尾巴 '要更多加大 count 或关键词收窄' 删; - days:'用 op=day 看某天;记得关键词就 op=search' 教学尾行删,头行简化 '【日记索引】共 N 天(新在前)';空态一句 '日记库为空(尚无收口碎片)。'; - day 空态 '没有日记(当天无交互或条目已裁剪;op=days 可看有哪些天)' → 'date 无日记。'; - files:'(按磁盘实况列出;取内容用 op=link)' 教学尾行删;措辞收紧为 '「标题」现存文件(顶层 N 个)' / 目录不存在、无文件各一句; - journalFor 注入头行:五连 op 枚举(search/days/day/files/link 用法)收为 '(最近N条,非全部——更早的可用 recall 检索)' 一句事实+指针,op 细节归 schema; - throw 类纠错错误保留(§五:错误是引导修正的合法位置)。 探针 6 项全过(search/days/day/files 零教学、空态一句话、注入头行瘦身)。 --- app/server/memory.js | 7 ++----- app/server/tools/executor.js | 18 ++++++++---------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/server/memory.js b/app/server/memory.js index 8fd17f0..8dbf3e5 100644 --- a/app/server/memory.js +++ b/app/server/memory.js @@ -76,9 +76,7 @@ function journalFor(db, cfg, user) { 'SELECT session_id, day, text FROM memory_fragments WHERE user = ?' + INJECT_ORDER + ' LIMIT ?' ).all(String(user || ''), cap); if (!rows.length) return ''; - const head = '【长期记忆·日记(最近' + rows.length + '条)】收工时的当日事件摘要,新在前、天内按发生顺序;' - + '每条【编号】是来源会话 id:更早的日记用 recall 工具 op=search 关键词检索、op=days 按日期翻页再 op=day 取整天;' - + '那次工作的成果文件用 op=files 查、op=link 取。'; + const head = '【长期记忆·日记(最近' + rows.length + '条,非全部——更早的可用 recall 检索)】新在前、天内按发生顺序;每条【编号】是来源会话 id。'; const groups = []; for (const r of rows) { const g = groups[groups.length - 1]; @@ -118,8 +116,7 @@ function searchFragments(db, user, query, count) { if (!hits.length) return ''; hits.sort((a, b) => b.score - a.score || a.i - b.i); const shown = hits.slice(0, lim); - const parts = ['【日记检索】「' + String(query).trim() + '」命中 ' + hits.length + ' 条,按相关度列前 ' + shown.length + ' 条' - + (hits.length > shown.length ? ';要更多加大 count 或关键词收窄' : '') + ':']; + const parts = ['【日记检索】「' + String(query).trim() + '」命中 ' + hits.length + ' 条,按相关度列前 ' + shown.length + ' 条:']; for (const h of shown) parts.push('--- ' + h.r.day + '(' + Math.round(h.score * 100) + '% 匹配)---\n' + renderFrag(h.r)); return parts.join('\n\n'); } diff --git a/app/server/tools/executor.js b/app/server/tools/executor.js index 564766e..6d562a8 100644 --- a/app/server/tools/executor.js +++ b/app/server/tools/executor.js @@ -1379,19 +1379,18 @@ function toolRecall(ctx, args) { const q = String(args.query || '').trim(); if (!q) throw new Error('op=search 需要 query(关键词;空格分隔多个词更好,如「身份证 水印」)'); const txt = memory.searchFragments(db, user, q, args.count); - return txt || '日记库里没有匹配「' + q + '」的条目。换个更宽泛的关键词再试,或 op=days 看哪天有什么;成果文件走 op=files。'; + return txt || '日记中无「' + q + '」相关记录。'; } case 'days': { const list = memory.daysIndex(db, user); - if (!list.length) return '日记库是空的:还没有任何收口条目(开场注入的日记也出自这里)。'; - return '【日记日期索引】共 ' + list.length + ' 天有记录(新在前):\n' + list.join('\n') - + '\n用 op=day {date} 看某天的完整日记;记得关键词就直接 op=search。'; + if (!list.length) return '日记库为空(尚无收口碎片)。'; + return '【日记索引】共 ' + list.length + ' 天(新在前):\n' + list.join('\n'); } case 'day': { const date = String(args.date || '').trim(); if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) throw new Error('op=day 需要 date(YYYY-MM-DD,先用 op=days 查有哪些天)'); const txt = memory.dayEntry(db, user, date); - return txt ? date + ' 的日记:\n' + txt : date + ' 没有日记(当天无交互或条目已裁剪;op=days 可看有哪些天)。'; + return txt ? date + ' 的日记:\n' + txt : date + ' 无日记。'; } case 'files': { const t = resolveSession(); @@ -1402,13 +1401,12 @@ function toolRecall(ctx, args) { .map(d => d.name) .sort(); } catch (_) { - return '会话「' + t.title + '」的任务目录不存在(已删或未产出),无成果文件。'; + return '「' + t.title + '」任务目录不存在,无成果文件。'; } - if (!names.length) return '会话「' + t.title + '」没有成果文件。'; + if (!names.length) return '「' + t.title + '」无成果文件。'; const shown = names.slice(0, 80); - return '会话「' + t.title + '」当前存在的文件(' + shown.length + (names.length > shown.length ? '/共 ' + names.length : '') + ' 个):\n' - + shown.map(n => '- ' + n).join('\n') - + '\n(按磁盘实况列出:存在即未被删;取内容用 op=link {id, path})'; + return '「' + t.title + '」现存文件(顶层 ' + shown.length + (names.length > shown.length ? '/共 ' + names.length : '') + ' 个):\n' + + shown.map(n => '- ' + n).join('\n'); } case 'link': { const t = resolveSession();