From 50110aeae55a8df301daad7fccfe1b36cf090f7a Mon Sep 17 00:00:00 2001 From: kicer Date: Tue, 29 Sep 2026 15:06:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(memory):=20inject=5Fmax=20=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=2010=E2=86=923=20+=20=E8=B0=83=E8=AF=95=E9=A1=B5?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=E7=AA=97=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 开场注入只带最近 3 条碎片(近几片足以接上旧话,多了是噪音);example 同步。 线上 config.yml 无 memory 段,吃默认值直接生效。 - memory.html:条目卡按 journalFor 同序标出「已注入」徽章——哪几片会被新会话 开场带走一眼可见,注入窗调整时不用数注入预览文本。 --- app/config.example.yml | 2 +- app/server/config.js | 4 ++-- app/server/public/memory.html | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/config.example.yml b/app/config.example.yml index be6e5ee..cbd684d 100644 --- a/app/config.example.yml +++ b/app/config.example.yml @@ -54,7 +54,7 @@ agent: # 长期记忆(日记,memory.js):收口时一条几十字第一人称碎片入当日条目;存储默认永久,旧记忆靠回忆下钻 memory: - inject_max: 10 # 新会话开场注入最近几条碎片;0=只记录不注入 + inject_max: 3 # 新会话开场注入最近几条碎片;0=只记录不注入 retain_days: 0 # 存储裁剪窗;0=永不删,正数=超窗硬删 wrap_idle_ms: 14400000 # 空闲超此时长自动收口(碎片+归档+微信解绑);0=关 diff --git a/app/server/config.js b/app/server/config.js index 7ffe264..5478ecf 100644 --- a/app/server/config.js +++ b/app/server/config.js @@ -89,11 +89,11 @@ const DEFAULTS = { skills: { skills_root: '', timeout_ms: 120000 }, // 长期记忆(日记,memory.js):会话收口(下班)时一条几十字的第一人称碎片,按【收口当日】入条目。 // 记忆分层:存储默认永久(虚拟人的过去不能到点就抹);注入只取最近几条当「嘴边的工记」; - // inject_max = 新会话开场注入上限(默认 10,硬帽 50);0 = 只记录不自动注入。 + // inject_max = 新会话开场注入上限(嘴边的工记:近几片足以接上旧话,多了是噪音;0 = 只记录不自动注入)。 // retain_days = 存储裁剪窗:0 = 默认永不删;正数 = 超窗硬删(自动清理/隐私抹除场景才用)。 // wrap_idle_ms = 空闲收口阈值:held/completed 且超过此时长无更新 → 后台 LLM 摘要收口、 // 归档、微信通道解绑退位(下次消息自然新工作台);0 = 关。设定定时任务是显式收口,不受此开关影响。 - memory: { inject_max: 10, retain_days: 0, wrap_idle_ms: 14400000 }, + memory: { inject_max: 3, retain_days: 0, wrap_idle_ms: 14400000 }, // 【已废弃】旧版模型保持租约(held 到期自动释放)。调度已改为「key 共享并发 + 优先级选择」(见 engine.chooseKey), // 不再有任何到期逻辑;字段保留仅为旧 config.yml 兼容(解析不报错),运行期无人读取。 model_hold: { idle_release_ms: 180000, active_max_ms: 1800000, sweep_ms: 10000 }, diff --git a/app/server/public/memory.html b/app/server/public/memory.html index e2f24d0..e30bf9e 100644 --- a/app/server/public/memory.html +++ b/app/server/public/memory.html @@ -24,6 +24,7 @@ .day .t { color: #9aa4b2; font-weight: 400; font-size: 12px; margin-left: 8px; } .frag { margin-top: 8px; padding: 8px 10px; background: #f8fafc; border: 1px solid #eef1f6; border-radius: 8px; white-space: pre-wrap; word-break: break-all; } .frag .sid a { color: #4c6ef5; text-decoration: none; font-size: 12px; } + .inj-tag { display: block; width: fit-content; margin: 0 0 6px; } pre.inj { background: #fff; border: 1px solid #e3e8f0; border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; word-break: break-all; margin: 0; font: 13px/1.7 ui-monospace, Menlo, monospace; } table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e3e8f0; border-radius: 10px; overflow: hidden; } @@ -80,12 +81,22 @@ function render(d) { document.getElementById('injection').textContent = d.injection || '(无注入文本:无记忆或功能关闭)'; var eHtml = ''; - (d.entries || []).forEach(function (e) { + // 镜像 journalFor 取序(天降序、天内从最新一片往回取)算出注入窗,条目卡上直接标出哪几片会被新会话开场带走。 + var injected = {}; + if (d.inject_max) { + var left = d.inject_max; + (d.entries || []).forEach(function (e, ei) { + if (left <= 0) return; + var frs = String(e.content || '').split(/\n\n+/).filter(Boolean); + for (var i = frs.length - 1; i >= 0 && left > 0; i--, left--) injected[ei + ':' + i] = 1; + }); + } + (d.entries || []).forEach(function (e, ei) { var frags = String(e.content || '').split(/\n\n+/).filter(Boolean); eHtml += '
' + esc(e.day) + (e.in_window ? '' : '窗外(待裁)') + '更新 ' + fmtTime(e.updated_at) + ' · ' + frags.length + ' 个碎片
' - + frags.map(function (f) { return '
' + linkSids(esc(f)) + '
'; }).join('') + + frags.map(function (f, fi) { return '
' + (injected[ei + ':' + fi] ? '已注入' : '') + linkSids(esc(f)) + '
'; }).join('') + '
'; }); document.getElementById('entries').innerHTML = eHtml || '
暂无条目——等一次收口,或先在微信/网页聊几句。
';