dsh-memu-memory 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +4 -1
- package/README.zh.md +4 -1
- package/docs/memory-semantics.md +4 -2
- package/docs/troubleshooting.md +26 -0
- package/lib/binding-diagnostics.js +1 -1
- package/lib/consolidation-worker.js +11 -3
- package/lib/curator.js +16 -4
- package/lib/cycle.js +75 -4
- package/lib/index.js +4 -2
- package/lib/inject.js +142 -8
- package/lib/memory.js +72 -0
- package/lib/private.js +49 -13
- package/lib/prompts/private-consolidation.coding.md +3 -1
- package/lib/prompts/private-consolidation.md +2 -0
- package/lib/prompts/private-consolidation.mixed.md +2 -0
- package/lib/prompts/private-consolidation.rp.md +2 -0
- package/lib/prompts/system-guide.coding.md +8 -2
- package/lib/prompts/system-guide.md +6 -0
- package/lib/prompts/system-guide.mixed.md +11 -0
- package/lib/prompts/system-guide.rp.md +6 -0
- package/lib/turn-log.js +34 -11
- package/lib/worker-pool.js +11 -7
- package/package.json +1 -1
- package/tests/consolidation-fork.test.mjs +20 -1
- package/tests/curator-probe.test.mjs +19 -1
- package/tests/inject-guide.test.mjs +108 -1
- package/tests/prompts.test.mjs +30 -0
- package/tests/salience-domain.test.mjs +34 -0
- package/tests/stale-maintenance.test.mjs +131 -0
- package/tests/turn-log.test.mjs +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# 更新日志 / Changelog
|
|
2
2
|
|
|
3
|
+
## [1.4.1] - 2026-11-26
|
|
4
|
+
|
|
5
|
+
> 两件事:通道复用会话 id 时规则消息会整段缺席(真机 24 回合没有 `<memory-guide>`);
|
|
6
|
+
> 按域变体只有"怎么查"没有"什么时候写",于是私聊里从不下笔。
|
|
7
|
+
|
|
8
|
+
- **同名新会话重新投放规则与锚点**:dsh-channel 用确定性会话 id(`qq-dm-<uid>`)跨重启复用,宿主重建同名空转录后 binding 仍是上一代的,`guideRulesKey`/`anchorPushed` 让 `guideAdmission`/`ensureUnifiedGuide` 的稳态判据把 guide 与锚点永久跳过——实测 `qq-dm-1299772830` 新会话 16:22 建立、第 1 回合就有记忆块,规则消息直到第 25 回合 20:50 才出现。现在 `lib/inject.js:syncSessionIncarnation` 每次 pre-step 比对宿主会话身份(`session.createdAt`;宿主不暴露时退回「回合号回到 1 + 首条消息 id」兜底,同一代内稳定),换代就清 `guideRulesKey`/`guideMessageAt`/`anchorPushed`/`lastInjectedUserMessageId`、置 `reinjectPending`,活动日志记「同名新会话:一次性投放已重置」。
|
|
9
|
+
- **切换记忆领域重新投放**:`injectedDomain` 记录在 binding 上,与 `domainOf(binding)` 不一致时清 `guideRulesKey`/`guideMessageAt`/`anchorPushed`/`anniversariesShown`/`openLoopRemindedAt`/`textureKey` 并置 `reinjectPending`(`lib/inject.js:syncDomainDelivery`,活动日志「记忆领域切换:一次性投放已重置」)。此前切域只靠 `rulesKey` 换 guide,锚点与按域过滤的纪念日/未了之事仍按"一会话一次"被旧领域的记账压着;两个领域落到同一份基础稿时 guide 也不会重投。
|
|
10
|
+
- **逾期与过时的整理收尾**:此前两类"只提醒不结案"——逾期承诺在注入里天天提示但 `commitment.status` 永远是 `open`(整理提示词只教"写承诺");`expired` 短期草稿退出召回后永久占索引,没有保留期。现在:①`[memory-catalog]` 后附**欠账单列**(`lib/memory.js:overdueOpenCommitments`,最多 8 条,含 due、已逾期天数、对谁/做什么),整理页四稿与 worker 任务书都要求"先清欠账再查过时"——按本窗证据写 `done`/`cancelled`/`expired`,没证据就保留并写明仍欠着;`valid_to` 已过或已被明确取代的旧条目改 `status=archived` 或补正窗口,旧正文保留。②`lib/cycle.js:runOverdueReviewPass` 对逾期 ≥7 天的 open 承诺写一条 `check` 活动日志(同一条 7 天不重复,节流表 `state.cycle.overdueReviewAt`),只提示、不改状态——承诺是否兑现不能被清理策略替人裁决。③`lib/memory.js:archiveExpiredDrafts`:`expired` 草稿在保留期(30 天)后改标 `archived`,不删除,正文仍可升回 `long_term`。
|
|
11
|
+
- **编码域种子放宽**:fork 种子以前对 coding 也用 2 分 salience 过滤,"改这个函数"这类只有工具调用的改动会被整回合丢掉;工具结果截 1100 字、调用参数截 500 字,diff 与错误签名常只剩开头,worker 路径的 turn-log 工具行更是只留 160 字。现在 coding:`candidateSeedEvents` 弱词阈值 1、带 `tool/call` 的回合一律保留、回合上限 120(默认 60);`compactSeedEvents` 工具结果 2200 字 / 调用参数 1000 字;turn-log 工具行 600 字 / 参数 400 字(`turnLogLimits('coding')`,记录器、worker 增量与缺口重建同口径);turn-log 关闭/重建失败时的兜底压缩与远端整理转录也按域(`condenseLimitsFor('coding')`:结果 1400 / 参数 700,默认 400/300)。整窗仍有 ≤500 事件、单条 12k 文本、turn-log 4000 字/条的总闸。
|
|
12
|
+
- **编程整理频率与"修改重点"**:fork/worker 的任务书以前是 RP 口径——价值排序把工程结论排进「其他明确事实」并受「普通事实最多 3 条」限制,`content` 要求 50–150 字「人物、地点、原话」;与编码整理稿自己的 150–350 字结构要求冲突,编码域于是写得少、也只剩"修复了某问题"这种摘要。现在 `buildWorkerBrief({domain})` 对 `coding` 使用工程排序(根因与修复理由 = 接口/不变量变化 = 环境与版本约束 = 被否决方案 > 验证结论与测试范围 > 需求/验收变化 > 偏好 > 其余),`content` 150–350 字按「结论 / 作用范围与定位(路径 + 符号)/ 条件与原因 / 验证状态」、标题写结论本身;编码整理稿的「最多 3 条、宁可少写一条」改为「每窗最多 8 条、前两类必须写」,与 RP 同口径。`rp/general/mixed` 的原口径不变。守卫:`tests/prompts.test.mjs` 按域断言任务书排序、长度与标题要求。
|
|
13
|
+
- **规则消息补工具分工表**:首步 `<memory-guide>` 以前只在零星句子里提到 recall/remember,`rp`/`mixed` 连写入工具名都没有,模型没有"哪个工具什么时候用"的统一入口。四个领域稿(`general` 基础稿 + `rp`/`coding`/`mixed` 变体)现在都带同一张表:`memu_private_recall` / `memu_global_recall`、`memu_private_remember`(+`_batch`) / `memu_private_update`、`memu_private_list` / `memu_status` 的时机,以及 `memu_private_archive`/`memu_private_unpin` 只在用户明确要求时、`memu_private_link*`/`memu_lexicon_*` 不在对话里主动调。`project:*` 等无变体领域回退基础稿。渲染后 full message:coding 963 / mixed 1015 / rp 1327 / general 1685 token,都在 `injectionTotalTokens` 默认 2000 内;规则正文变化会换 `rulesKey`,存量会话下一步首步自动重投一次。
|
|
14
|
+
- **guide 与召回解耦**:`ensureUnifiedGuide` 以前在 `injectForStep` 的 try 内,召回抛错(真机:`inbound queue is full`)会把规则消息一起吞掉。现在 catch 分支仍尝试投放 rules,故障只落 `lastRecallError` + warn。
|
|
15
|
+
- **按域 guide 补写入条款**:`system-guide.rp.md` / `.coding.md` / `.mixed.md` 各补一段「什么时候写」——值得记的三类、用 `memu_private_remember`/`memu_private_update` 的口径、不每回合写、其余交给闲时整理。此前只有通用稿讲写入(`domainLayered` 是整篇替换),实测 27 回合的 RP 私聊 `memu_*` 工具调用 0 次。coding 稿加完渲染约 907 token,仍在 `injectionTotalTokens` 默认 2000 之内。
|
|
16
|
+
- 守卫:`tests/inject-guide.test.mjs` 新增四条——同名新会话重投规则与锚点、无 `createdAt` 时回合号复位只重置一次且重入不重复、召回抛错仍投 guide、切域重投规则/锚点并清掉纪念日与未了之事的记账;`tests/stale-maintenance.test.mjs` 新增四条——保留期归档、逾期门槛、周期提示只写一次且不改状态、目录欠账单列;`tests/prompts.test.mjs` 新增两条——逐域断言工具分工表(八个工具 + batch 指引 + 整理侧工具边界)、按域断言整理任务书的排序/长度/标题口径;`tests/turn-log.test.mjs`、`tests/salience-domain.test.mjs`、`tests/consolidation-fork.test.mjs`、`tests/curator-probe.test.mjs` 各加一条编码域额度用例(工具行 600/参数 400、工具回合与弱词保留、种子 2200/1000、兜底 1400/700)。全量 2022 tests / 2020 pass / 0 fail / 2 skipped。
|
|
17
|
+
- 文档:`docs/troubleshooting.md` §3.47 与症状速查表、`docs/memory-semantics.md` §8.4、中英 README 的兼容性段。
|
|
18
|
+
|
|
3
19
|
## [1.4.0] - 2026-11-26
|
|
4
20
|
|
|
5
21
|
> 三件事一起收:按域终于看得见筛得动;中文人名被 n-gram 滑窗切成两个节点的成因在提名侧堵住;
|
package/README.md
CHANGED
|
@@ -327,7 +327,10 @@ the idle window starts from real message activity or the agent's return to idle.
|
|
|
327
327
|
- **No cloud sync, no accounts, no cross-device sync.** This is a local plugin with no server-side identity.
|
|
328
328
|
- **Images without vision:** without an optional caption/vision endpoint, an image memory is a pointer plus what a person wrote about it. The plugin does not claim to see pixels.
|
|
329
329
|
- **Poisoned v4 sessions:** historical `format v4 message requires a producer-owned source kind` rows can be diagnosed but not rewritten; the plugin never edits private session files.
|
|
330
|
-
- **Agent presets:** a conversation whose preset (`i-am-yuike`, `yuike-standard`, …) carries its own `cordis.yml` composes its model-facing plugins from that list alone, and its scope never delivers `agent/pre-step` to this plugin. At runtime `lib/preset-scope.js` attaches an injection listener to that agent's own context, so **anchor and recall delivery works**. All conversations now receive the memory rules as one `<memory-guide rules="…">` plugin message on the first step of a turn; the plugin no longer registers a system-prompt section, and the message is replaced after a domain/prompt change or a compaction (`rulesKey` / `guideLost`). The **final tool list** is a third, separate question: it follows the preset's own plugin list and the host scope, and it cannot be inferred from whether this plugin is listed — observations in this repo record both "no `memu_*` tools" and `memu_private_*` present in some presets' tool chains. **Per-preset tool availability still needs a real-host check (W3)**; until then do not read this as "presets have no tools", nor as "listing the plugin is enough". The plugin never edits anyone's preset files.
|
|
330
|
+
- **Agent presets:** a conversation whose preset (`i-am-yuike`, `yuike-standard`, …) carries its own `cordis.yml` composes its model-facing plugins from that list alone, and its scope never delivers `agent/pre-step` to this plugin. At runtime `lib/preset-scope.js` attaches an injection listener to that agent's own context, so **anchor and recall delivery works**. All conversations now receive the memory rules as one `<memory-guide rules="…">` plugin message on the first step of a turn; the plugin no longer registers a system-prompt section, and the message is replaced after a domain/prompt change or a compaction (`rulesKey` / `guideLost`). The rules message carries a **tool timing map** (recall/global_recall, remember(+batch)/update, list/status, and archive/unpin only on an explicit user request) in all four domains: `general`, `rp`, `coding` and `mixed`. The **final tool list** is a third, separate question: it follows the preset's own plugin list and the host scope, and it cannot be inferred from whether this plugin is listed — observations in this repo record both "no `memu_*` tools" and `memu_private_*` present in some presets' tool chains. **Per-preset tool availability still needs a real-host check (W3)**; until then do not read this as "presets have no tools", nor as "listing the plugin is enough". The plugin never edits anyone's preset files.
|
|
331
|
+
- **Reused session ids in IM channels, and domain switches:** `dsh-channel` and similar surfaces reuse a deterministic id (`qq-dm-<uid>`) across restarts, and the host can re-create a same-id session with an empty transcript. The plugin compares the host session identity (`session.createdAt`; when the host does not expose it, a turn number back at 1 plus the first message id) against the stamp kept on the binding, and on a new incarnation it clears the previous incarnation's `guideRulesKey` / `anchorPushed` so the rules and the anchor are delivered again (1.4.1+). Before this, such a conversation could run its whole life without a `<memory-guide>` message. **Switching the memory domain** re-delivers too: the rules message, the anchor, today's anniversaries, open loops and the time-of-day line are all domain-filtered, so a domain change resets them and they are delivered again for the new domain. Guide delivery is also decoupled from recall: a recall exception no longer swallows the rules message.
|
|
332
|
+
- **Overdue and stale cleanup:** a short-term draft leaves recall at its deadline and is archived 30 days later (never deleted; the body can still be promoted back to `long_term`). Overdue promises surface at most three per turn, dated open loops once a day, and the consolidation brief ships an "overdue" section so the worker can close them from transcript evidence (`done`/`cancelled`/`expired`); the periodic sweep only writes a hint and never changes a status. Entries whose `valid_to` has passed leave recall and are archived or re-windowed during consolidation. Whether a promise was kept is a factual question — the plugin does not answer it for you.
|
|
333
|
+
- **Coding consolidation detail:** the fork seed keeps every coding turn that touched a tool (up to 120 turns, default 60), 2,200 chars of a tool result and 1,000 chars of call arguments; the worker path's turn-log keeps 600-char tool lines and 400-char arguments (default 160/120), and the turn-log-off fallback compaction keeps 1,400/700 (default 400/300). RP/general keep their original caps, and the 500-event window, 12k per-message text and 4,000-char per-record limits still bound everything.
|
|
331
334
|
- **Consolidation worker (C 包, 2026-10-30).** An idle or manual pass now works from a *fixed snapshot*: it takes the public `sessionQuery.observeSession()` lease (falling back to `readSession()` when the host offers no lease), cuts at the last complete `turn/end`, and drops unpaired tool calls and half steps — a live transcript whose last turn is still open is **deferred**, never consolidated. A job is settled only by a structured completion receipt that is cross-checked against the library index (an id the library does not contain is not a success, and a rewrite of an existing id counts as an update, not a new memory). Checked / pending / in-flight ranges and a lease are persisted separately in `consolidation.json`, so a crash, a timeout or a failed turn leaves the range pending instead of looking consolidated. **Limits:** the worker still runs inside the parent preset's own system prompt — it receives an explicit "you are a background consolidation worker, not this character" brief, which reduces but does not remove persona carry-over, because the host has no public API to replace that prompt; and when the conversation's tool surface carries no `memu_private_remember` / `memu_private_update` (or exposes memory only through PTC), consolidation reports `unavailable` (`worker-tools-missing` / `worker-tools-ptc-only`) rather than forking a worker that could not write. The parent's library, scope, domain and memory context are re-checked before dispatch, on every worker tool call, and again before any result is credited.
|
|
332
335
|
- **Consolidation coverage is conservative lexical evidence.** A matching date or a couple of shared terms does not prove a candidate was written. The local check also requires text coverage, retained characters/words and values, and matching clause polarity; uncertain candidates stay in carry. It can retain a paraphrase that was already saved, and it does not claim semantic equivalence.
|
|
333
336
|
- **"Tomorrow" is resolved at write time.** A relative day (今天 / 明天 / 后天 / today / tomorrow) together with a month-day settles into one dated memory; a memory that only says "sometime next month" keeps no date rather than inventing one. A date that was already written as `MM-DD` is not rewritten — the fix applies to new writes.
|
package/README.zh.md
CHANGED
|
@@ -316,7 +316,10 @@ return { content: originalContent, meta: { ...originalMeta, memoryInbound: batch
|
|
|
316
316
|
- **没有云同步、账号或跨设备同步。** 这是本地插件,没有服务端身份。
|
|
317
317
|
- **没有视觉时:** 图片记忆只是「指针 + 人写的描述」。插件不会声称看过像素。
|
|
318
318
|
- **v4 污染会话:** 历史 `format v4 message requires a producer-owned source kind` 行只能诊断,不能改写;插件不会编辑私有会话文件。
|
|
319
|
-
- **人格预设(agent preset):** 预设(`i-am-yuike`、`yuike-standard` 等)自带 `cordis.yml`,会话的模型可见插件集只由那份清单决定,它的 scope 也不会把 `agent/pre-step` 送到本插件。运行时 `lib/preset-scope.js` 会把注入监听挂到该 agent 自己的 ctx 上,所以**锚点与召回的送达是能用的**。所有会话现在都通过回合首步的一条 `<memory-guide rules="…">` 插件消息接收记忆规则;插件不再注册 system prompt 段,规则在切域、改稿或压缩后由 `rulesKey`/`guideLost`
|
|
319
|
+
- **人格预设(agent preset):** 预设(`i-am-yuike`、`yuike-standard` 等)自带 `cordis.yml`,会话的模型可见插件集只由那份清单决定,它的 scope 也不会把 `agent/pre-step` 送到本插件。运行时 `lib/preset-scope.js` 会把注入监听挂到该 agent 自己的 ctx 上,所以**锚点与召回的送达是能用的**。所有会话现在都通过回合首步的一条 `<memory-guide rules="…">` 插件消息接收记忆规则;插件不再注册 system prompt 段,规则在切域、改稿或压缩后由 `rulesKey`/`guideLost` 替换。规则消息里带**工具分工表**(recall/global_recall、remember(+batch)/update、list/status 的时机,以及归档与取消置顶只在用户明确要求时调用),`general`/`rp`/`coding`/`mixed` 四个领域都有。**最终工具面**是第三件事,由该预设自己的清单与宿主 scope 决定——不能从「有没有列上本插件」推断,仓库里的观察既有「没有 `memu_*` 工具」,也有某些预设的工具链里存在 `memu_private_*`。**逐预设的真实工具名单仍需真机核实(W3)**;在那之前,别读成「预设都没有工具」,也别读成「列上插件就一定可用」。插件不会改任何人的预设文件。
|
|
320
|
+
- **通道复用会话 id + 切域重投:** IM 通道(`dsh-channel` 等)用确定性会话 id(`qq-dm-<uid>`)跨重启复用,宿主重建同名新会话时转录是空的。插件按宿主会话身份(`session.createdAt`;宿主不暴露时看回合号是否回到 1 加首条消息 id)比对绑定上的会话戳,换代就清掉上一代的 `guideRulesKey`/`anchorPushed` 并重新投放规则与锚点(1.4.1 起);在此之前,这类会话可能整段都收不到 `<memory-guide>`。**切换记忆领域**同样重投:规则消息、锚点、当日纪念日、未了之事与时段氛围都按领域过滤,切域后全部按新领域重新投一次。规则消息的投放也与召回解耦:召回抛错不再连带吞掉它。
|
|
321
|
+
- **逾期与过时的收尾:** 短期草稿到期即退出召回,再保留 30 天后自动归档(不删除,正文仍可升回 `long_term`);逾期承诺每回合最多提示 3 条、带日期的未了之事每天最多提一次,整理任务书会带上"欠账单列"要求按转录证据结案(`done`/`cancelled`/`expired`),周期扫描只写提示、永不改状态;`valid_to` 已过的条目不进召回,整理时归档或补正窗口。承诺是否兑现是事实问题,插件不替你裁决。
|
|
322
|
+
- **编码域的整理精度:** 种子保留对编码域更宽——带工具调用的回合一律保留(上限 120,默认 60),工具结果保留 2200 字、调用参数 1000 字;worker 路径的 turn-log 工具行 600 字、参数 400 字(默认 160/120),turn-log 关闭时的兜底压缩 1400/700(默认 400/300)。RP/通用域保持原额度;整窗仍受 500 事件、12k 文本/条、4000 字/条记录的总闸。
|
|
320
323
|
- **相对日期在写入时结算:** 「今天 / 明天 / 后天 / today / tomorrow」加上一个月日落成带年份的日期;只说「下个月某天」的记忆不产生日期,也不替它编一个。已经按 `MM-DD` 写进去的旧条目不会被改写——这条只对新写入生效。
|
|
321
324
|
- **不在范围:** 云端 MemU 联调、旧条目的 source 回填、已写坏 v4 消息的自动修复。
|
|
322
325
|
|
package/docs/memory-semantics.md
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
### 8.4 注入
|
|
42
42
|
|
|
43
|
-
- 静态 guide 与动态记忆都走 plugin 消息;当前版本不再注册本插件的 system prompt 段。所有会话(含 `persona` `complete: true`)统一由 `lib/inject.js` 的 `ensureUnifiedGuide` 在**回合首步**投放一条 `<memory-guide rules="…">` 插件消息;`rulesKey` 由协议版本、domain 和实际渲染正文计算,domain/覆盖/默认稿变化或压缩丢失(`guideLost`)时在下一个合法首步替换,同一规则不逐回合重复。旧 binding 只有 `guideMessageAt`、没有 `guideRulesKey` 时视为旧版,补投一次;失败 fail-open
|
|
43
|
+
- 静态 guide 与动态记忆都走 plugin 消息;当前版本不再注册本插件的 system prompt 段。所有会话(含 `persona` `complete: true`)统一由 `lib/inject.js` 的 `ensureUnifiedGuide` 在**回合首步**投放一条 `<memory-guide rules="…">` 插件消息;`rulesKey` 由协议版本、domain 和实际渲染正文计算,domain/覆盖/默认稿变化或压缩丢失(`guideLost`)时在下一个合法首步替换,同一规则不逐回合重复。旧 binding 只有 `guideMessageAt`、没有 `guideRulesKey` 时视为旧版,补投一次;失败 fail-open,不写新版本。**规则消息本身带工具分工**:查(`memu_private_recall` / `memu_global_recall`)、写(`memu_private_remember`,多条走 `memu_private_remember_batch`)、补(`memu_private_update`:合并/纠正/补窗口/给承诺结案)、看(`memu_private_list` / `memu_status`)各在什么时机用,以及归档/取消置顶(`memu_private_archive` / `memu_private_unpin`)只在用户明确要求时、`memu_private_link*` 与 `memu_lexicon_*` 不在对话里主动调。四个领域变体(`general` 用基础稿,`rp` / `coding` / `mixed` 用变体,其余无变体的 `project:*` 领域回退基础稿)都覆盖这张表,`tests/prompts.test.mjs` 逐域钉住。**同名新会话**:通道(如 dsh-channel 的 `qq-dm-<uid>`)重启后会用同一个 id 重建空转录,binding 却还是上一代的,稳态判据会把 guide 与锚点永久跳过(真机 24 回合无规则消息)。`syncSessionIncarnation` 因此记录宿主会话身份(`session.createdAt`;宿主不暴露时用「回合号回到 1 + 首条消息 id」兜底),身份变化时清掉 `guideRulesKey`/`anchorPushed`/`lastInjectedUserMessageId` 并置 `reinjectPending`;guide 的投放也不再位于召回异常之内,召回故障不连带吞掉规则消息。**切域同理**:绑定上记 `injectedDomain`,与 `domainOf(binding)` 不一致时清 `guideRulesKey`/`guideMessageAt`/`anchorPushed`/`anniversariesShown`/`openLoopRemindedAt`/`textureKey` 并置 `reinjectPending`——这些一次性提醒都按领域过滤,切到新领域后必须重新投,guide 即使两个领域回退到同一份基础稿也照样重投。
|
|
44
44
|
- 首轮锚点 + 每用户回合最多一次;记忆块**紧跟在人类消息之后**(`index + 1`),不再前插到用户消息之前——通道驱动(`channel-*`)的回合也走同一落点。此前它们退到 inbound 路径被追加到批次末尾,于是锚点落在工具调用之后,读起来就像"回复完才拿到上下文"。长工具回合仅有新的真实人类消息批次时追加一次,普通工具步骤不触发。**短句也召回**:召回门槛下限是 2 字(`minUserChars` 仍可调高),否则 QQ 里常见的「摸摸」「现在有点饿」会让首步一条记忆都没有——这正是"锚点总在下一条模型消息之后"的成因。人类消息按来源判定:`channel-*` 算;插件消息、`runtime-context` / `skill-catalog` / `time-context` / `progress-rules` / `agent-instructions` / `user-approval` 与 `tool*` 不算。
|
|
45
45
|
- **回合中途补充召回(受控)**:位置不变式在工具步不成立(那一步的批次里没有人类消息),所以它单独成一类:带 `[回合中途补充 · 这不是用户新说的话]` 标记、追加在批次末尾、独立预算 `midTurnTokens`(默认 400)、每回合最多 `midTurnMaxPerTurn`(默认 2)次、冷却 `midTurnCooldownMs`(默认 60s)。触发用**增量**证据并复用 `active-memory` 计分口径(去重后的工具单元 + 单条封顶字符 + 步数):默认 `midTurnMinSteps=4` 且(`midTurnMinUnits=3` 或 `midTurnMinChars=6000`);刚过线只投一行提示卡(让模型自己调 `memu_private_recall`),明显过线(`midTurnFullUnits=6` 且 `midTurnFullChars=15000`)才投正文召回;连续两次空召回停止本回合。`midTurnRecall: false` 关闭。
|
|
46
46
|
- **待接纳提案有落盘凭据**:`injectionAdmissions` 是进程内 Map,宿主重启或「同一 home 由另一个进程观察」时提案会凭空消失,接纳永远不发生(qq-dm 实测:333 个回合里 `acceptedMemoryMessages` 一次都没出现,同库 qq-group 正常)。现在提案同时写一份最小凭据到 binding 的 `pendingInjections`(按消息内容 digest 匹配,最多 8 条),观察端换进程也能补完接纳;迟到的接纳会把时钟抬到 `max(当时时钟, lastInjectedTurn, inbound.clock)`,否则 `markInjectedRefs` 会按「时钟必须前进」拒掉全部 effects。回合一收立即作废这份凭据(`finishInjectionTurn`),避免迟到的同内容消息复活已丢弃的提案。接纳失败一律落一条 warn 记录(`注入消息未被接纳 · <reason>`,同会话同原因 60 秒合并),原因取 `proposal-missing` / `proposal-<status>` / `digest-mismatch` / `snapshot-stale`——硬规则 10 的观测信号。
|
|
@@ -109,7 +109,8 @@
|
|
|
109
109
|
- 触发:`settings.sleepConsolidation` 开着时,每 5 分钟扫一遍(`lib/cycle.js` 的 `runSleepPass`)。候选有三条腿:① 空闲 ≥ `sleepAfterIdleMinutes`(**默认 2 分钟**,`lib/state.js` 的 `DEFAULT_SETTINGS`);② **水位**——账本里 pending 积压 ≥ 200 事件,不依赖空闲;③ 新活动但水位不足时的**探针**(最多每 15 分钟一次,读转录并评估,不 fork)。排序是 backlog → idle → probe,扫描每次最多处理 **2 个**会话。
|
|
110
110
|
- 应用启动后 8 秒补跑一次(`STARTUP_SWEEP_MS`),因为定时器只在应用开着时存在:一段对话如果是在应用关着的时候结束的,它永远等不到那个「空闲窗口」——用户一回来发消息,`lastTurnAt` 就被顶新了。
|
|
111
111
|
- **有新回合 ≠ 该写记忆。** 进 fork 之前先做两道本地评估(只看 `lastSleepSeq` 之后的转录):① `assessConsolidationValue` 的硬门槛——没有任何人类消息(只有插件通知、工具结果、心跳)→ 跳过;只有一条**纯应答**(「谢谢」「好的」「ok」「收到」,且没有任何工具调用)→ 跳过。**这里刻意不按字数判断**:字数少的偏好句(「我不吃香菜」)比一千字的闲聊更该留,长度是坏代理。② 水位优先级高于 `assessWake` 加权分:pending ≥ 200 事件或 ≥10 个真人回合直接整理;水位以下才走 `score = 0.35*min(H/3,2) + 0.45*min(C/4000,2) + 0.20*min(U/20,2)`(`H` 真人回合、`C` 真人文字 + 助手正文 + 去重工具结果、`U` 去重有效工具单元),默认 `activeMemoryMinScore = 0.8`、`activeMemoryStarvationMinutes = 15`。
|
|
112
|
-
- **每次只种一窗。** `requestPrivateConsolidation` 只把 `lastSleepSeq` 之后的增量切成一个 ≤500 事件、尾部对齐完整回合的窗口(`selectConsolidationWindow`);种子经 `compactSeedEvents` 清噪:只留真人消息 / 助手正文 / 工具调用与结果,删 reasoning、`source.replayState`、`data.stream`、插件召回、`runtime-context`、`request/header` 等后台事件;工具结果截 1200 字、重复输出只留一份。窗口开头插一条 `[memory-catalog]` 已有记忆目录(最多 18 条:id + 标题 + layer + status),worker
|
|
112
|
+
- **每次只种一窗。** `requestPrivateConsolidation` 只把 `lastSleepSeq` 之后的增量切成一个 ≤500 事件、尾部对齐完整回合的窗口(`selectConsolidationWindow`);种子经 `compactSeedEvents` 清噪:只留真人消息 / 助手正文 / 工具调用与结果,删 reasoning、`source.replayState`、`data.stream`、插件召回、`runtime-context`、`request/header` 等后台事件;工具结果截 1200 字、重复输出只留一份。窗口开头插一条 `[memory-catalog]` 已有记忆目录(最多 18 条:id + 标题 + layer + status),worker 用它合并/去重,不再为旧库重读历史。目录后面另有**欠账单列**(`overdueOpenCommitments`,最多 8 条:id + 标题 + due + 已逾期天数 + 对谁/做什么),因为按更新时间截断的目录很可能漏掉旧承诺,而整理必须看见它们;整理页与 worker 任务书都要求"先清欠账再查过时"——open 且已过 due_at 的承诺按本窗证据结案(`done`/`cancelled`/`expired`),没有证据就保留并写明仍欠着;`valid_to` 已过或已被明确取代的旧条目改 `status=archived` 或补正窗口,旧正文保留。周期兜底只提示不裁决:`runOverdueReviewPass` 对逾期 ≥7 天的 open 承诺写一条 `check` 活动日志(同一条 7 天内不重复,标记存 `state.cycle.overdueReviewAt`);过期草稿在 `shortTermTtlHours` 之后再留 30 天(`EXPIRED_DRAFT_RETENTION_DAYS`),超期由 `archiveExpiredDrafts` 改标 `archived` —— 不删除,正文仍可在归档视图里升回 `long_term`。剩余事件留到下一次扫描,`lastSleepSeq` 只随对账回执前进。
|
|
113
|
+
- **种子按域保留(1.4.1)**:fork 种子以前对 coding 也用 2 分 salience 过滤,"改这个函数"这类只带工具调用的改动会被整回合丢掉;工具结果截 1100 字、调用参数截 500 字,diff 与错误签名常常只剩开头。现在 coding:`candidateSeedEvents` 弱词阈值 1、带 `tool/call` 的回合一律保留、回合上限 120(默认 60);`compactSeedEvents` 工具结果 2200 字 / 调用参数 1000 字。worker 路径的 turn-log 同口径按域给额度:编码域工具行 600 字 / 参数 400 字(默认 160/120,`turnLogLimits`,记录器与缺口重建同源),整条记录仍 4000 字封顶,整窗仍有 ≤500 事件与单条 12k 文本的总闸。turn-log 关闭或缺口重建失败时的兜底压缩(`condenseEvents`)与远端整理转录也按域:coding 工具结果 1400 字 / 参数 700 字(默认 400/300,`condenseLimitsFor`)。
|
|
113
114
|
- **近期触发过记忆就不 fork。** `runSleepPass` 先看 `suppressionReason`:距上次整理不足 `activeMemoryCooldownMinutes`(默认 0)或距上次**注入过记忆**不足 `activeMemoryRecallCooldownMinutes`(默认 15 分钟)→ 跳过并发 `check` 日志。探针/水位可绕过「刚注入过」这一条(它们先评估、不直接 fork);被抑制或低分跳过的回合返回 `settled: false`,不推进 `lastSleepSeq`/`lastSleepAt`。
|
|
114
115
|
- **寒暄与无新事件是终态。** `small-talk` / `no-human-turn` / `no-new-events` 返回 `settled: true` 并写入 `lastSleepAt`,下一次真人消息到达前不再重扫同一段;政策跳过不计入 `ran`(没有 worker 回执)。
|
|
115
116
|
- **同一快照失败有上限(仅自动触发)。** `failJob` 按窗口 `snapshotHash` 记 `failures`;连续 2 次失败后下一次**自动**请求返回 `skipped: 'snapshot-failed'`(`settled: true`),不再重复付同一段的 fork 成本。手动整理(`force: true`)是明确的一次再决定,不受该上限约束;新事件也会改变哈希,让自动路径重新获得机会。
|
|
@@ -117,6 +118,7 @@
|
|
|
117
118
|
- 会话被删:host 对 `readSession` 报 `session "…" not found`,这是**不变量**而不是瞬时故障。`runSleepPass` 一旦看到就把 binding 标 `sessionGone: true` 并清掉重试计数,此后直接跳过(以前会按 2 的幂退避、封顶 1 小时,永远重试);同名会话后来真的收到新消息时(`lib/inbound.js`)会清掉这个标记。**"读不出来"不是"被删了"**:转录读失败(例如 `ENOENT`)由快照层显式标成可重试(`lib/consolidation-snapshot.js` 的 `failed()` → `retryable: true`),`runSleepPass` 只按退避重试、不打 `sessionGone`——`isGoneSessionError` 只认宿主那句 `session "…" not found` / `no such session`。
|
|
118
119
|
- 手动「整理这场对话」(RPC `generatePrivate`)带 `force: true`,跳过上面两道评估与抑制:用户已经决定了。若游标已经到末尾,手动整理只重查最后 ≤300 个事件,不再重放整段历史。
|
|
119
120
|
- **必写候选跨窗顺延。** 每窗本地抽 salience ≥3 的轮次(最多 8 条)作为必写清单;本窗没写进库的候选记入账本 `carry`,下一窗优先带 4 条、其余名额留给新候选。核验是纯本地保守证据比对,不额外调模型:日期从文本重合证据中剔除;至少 2 个有效 token,重合数须达 min(3, 候选 token 数) 且覆盖率 ≥55%,候选里的汉字 / Latin 词必须在同一条新增或更新记忆中出现,数值集合须包含候选值,共享 token 的子句否定极性须一致。日期相同、少量重词、不同动作或数值、相反极性不再单独算覆盖;不足以证明时保留在 carry。它仍是词法近似,不能证明任意改写的语义等价,因此可能保守保留已写入的改写候选;最后一窗也会在同一份任务书里看到顺延候选,不需要为补写再开一次整窗 fork。
|
|
121
|
+
- **任务书按域分叉(1.4.1)**:`buildWorkerBrief({ domain })` 以前是 RP 口径——价值排序把工程结论排进「其他明确事实」并受「普通事实最多 3 条」限制,`content` 要求 50–150 字「人物、地点、原话」,与编码整理稿自己的 150–350 字结构要求直接冲突。现在 `coding` 用工程排序(根因与修复理由 = 接口/不变量变化 = 环境与版本约束 = 被否决方案 > 验证结论与测试范围 > 需求/验收变化 > 偏好 > 其余),`content` 150–350 字按「结论 / 作用范围与定位(路径 + 符号)/ 条件与原因 / 验证状态」排、标题写结论;编码整理稿的「最多 3 条、宁可少写」也改为「每窗最多 8 条、前两类必须写」。rp/general/mixed 保持原口径。
|
|
120
122
|
|
|
121
123
|
---
|
|
122
124
|
|
package/docs/troubleshooting.md
CHANGED
|
@@ -52,6 +52,8 @@ WebUI 开着 GPU 占用高 / 时钟钉高档 → §3.28
|
|
|
52
52
|
mac 一键安装引擎报 dlopen 签名错 / 事后引擎目录是空的 → §3.31
|
|
53
53
|
插件内部报错要取证与一键修复 / 启动弹窗 → §3.45
|
|
54
54
|
库从列表消失但仍在写入 / 召回正常 → §3.46
|
|
55
|
+
同名新会话整段没有规则消息 / 锚点迟到很久 → §3.47
|
|
56
|
+
欠账一直提醒却不结案 / 过期草稿越积越多 → §3.48
|
|
55
57
|
```
|
|
56
58
|
|
|
57
59
|
## 3. 出过的问题:症状 → 落点 → 守卫
|
|
@@ -812,3 +814,27 @@ grep tests 里的硬编码清单。守卫:全量 `npm test` 1676/1674 pass / 0
|
|
|
812
814
|
**怎么确认**:`state.json` 里看 `archived` / `archivedBy` / `lastUsedAt` 三者是否自相矛盾;宿主日志搜 `archived library` 与 `kept library`。修好后旧数据在下一轮 sweep(启动后 8 秒或每 5 分钟)或下一条消息时自动复活。
|
|
813
815
|
|
|
814
816
|
**守卫**:`tests/cycle.test.mjs` —— 在用库跨三轮 sweep 不归档且仍在列表、无人用的库照常归档并记 `archivedBy='sweep'`、误归档在用库被复活、用户归档不被复活、purge 不把在用库列入候选、删除在用库被拒(解绑后放行)、快路径复活。
|
|
817
|
+
|
|
818
|
+
### 3.47 同名新会话整段没有规则消息 / 锚点迟到很久(通道复用会话 id)
|
|
819
|
+
|
|
820
|
+
**症状**:IM 通道(dsh-channel 等)的私聊/群聊里,回合首步有 `[open loop]` 与逐轮召回,却始终没有 `<memory-guide>`,`===== memory anchor =====` 也很久以后才偶然出现一次。`state.json` 里该会话的 `guideRulesKey` 有值、`guideMessageAt` 比宿主会话对象的 `createdAt` 还早,`lastInjectedTurn` 远大于当前转录的回合数。真机(2026-11-26,`qq-dm-1299772830`):新会话对象 16:22 建立,第 1 回合就有记忆块,规则消息直到第 25 回合 20:50 才出现。
|
|
821
|
+
|
|
822
|
+
**落点**:通道用确定性会话 id(`bridge.ts` 的 `qq-dm-<uid>`)跨重启复用,宿主重建同名新会话后转录是空的,而 memu 的 binding 按 id 持久,`guideRulesKey` / `anchorPushed` 还是上一代的。`guideAdmission` / `ensureUnifiedGuide` 的稳态判据只看 binding(`steady && guides.length === 0 → skip`),而 `agent/pre-step` 只给本步批次、看不见历史,于是新转录的首回合被当成「规则早就在」而永久跳过;只有压缩置 `guideLost`、规则/领域变了或回合失败回滚删 key 才会补投。同链缺陷:`ensureUnifiedGuide` 原先在 `injectForStep` 的 try 内,召回抛错(如 `inbound queue is full`)会把规则消息一起吞掉,那一回合记忆块与规则双双缺席。
|
|
823
|
+
|
|
824
|
+
**现在(1.4.1 起)**:`lib/inject.js:syncSessionIncarnation` 每次 pre-step 用宿主会话身份(`session.createdAt`,宿主不暴露时退回「回合号回到 1 + 首条消息 id」)比对 binding 上的 `sessionStamp`;换代就清掉 `guideRulesKey` / `guideMessageAt` / `anchorPushed` / `lastInjectedUserMessageId` 并置 `reinjectPending`,活动日志记一行「同名新会话:一次性投放已重置」。兜底戳只在同一代内稳定,宿主对同一首步重入不会重复重置。guide 的投放移出召回 try,召回故障只写 `lastRecallError` 与 warn,不再带走规则消息。同一入口的 `syncDomainDelivery` 处理**切域**:`injectedDomain` 与当前 `domainOf(binding)` 不一致时清 `guideRulesKey` / `guideMessageAt` / `anchorPushed` / `anniversariesShown` / `openLoopRemindedAt` / `textureKey` 并置 `reinjectPending`——纪念日与未了之事都按领域过滤,切到新领域后必须重投;guide 即使两个领域落到同一份基础稿也照样重投。
|
|
825
|
+
|
|
826
|
+
**怎么确认**:`state.json` 里看 `sessionStamp` 与当前转录是否同代(有 `createdAt` 时以它为准)、`injectedDomain` 与 `domainOf(binding)` 是否一致;活动日志搜「同名新会话」与「记忆领域切换」。规则/锚点恢复后,`guideMessageAt` 会被下一次接纳刷新。
|
|
827
|
+
|
|
828
|
+
**守卫**:`tests/inject-guide.test.mjs` —— 同名新会话重投规则与锚点、无 `createdAt` 时回合号复位只重置一次且重入不重复、召回抛错仍投 guide、切域重投规则/锚点并清掉纪念日与未了之事的记账。
|
|
829
|
+
|
|
830
|
+
### 3.48 欠账一直提醒却不结案 / 过期草稿越积越多
|
|
831
|
+
|
|
832
|
+
**症状**:`[commitment]` 卡每天还在提示"已逾期 N 天",但库里那条 `commitment.status` 一直是 `open`;或者归档视图里的 `expired` 草稿越积越多,召回又永远看不到它们。
|
|
833
|
+
|
|
834
|
+
**落点**:这是两条"只提醒不结案"的链。承诺逾期只有注入提醒(`dueCommitments` 与 overdue 兜底腿),整理提示词只教"写 `commitment`",没教"按证据结案",于是欠账永远 open。短期草稿过期只改 `status=expired` 退出召回(`isMemoryEligible` 的即时拦截 + `expireShortTerm` 清扫),注释里的"保留供升级"没有期限——`expired` 草稿会永久占索引,只能人工删。
|
|
835
|
+
|
|
836
|
+
**现在(1.4.1 起)**:`[memory-catalog]` 后带**欠账单列**(`overdueOpenCommitments`,最多 8 条),整理页与 worker 任务书要求"先清欠账再查过时"——open 且已过 `due_at` 的承诺按本窗证据写 `done`/`cancelled`/`expired`,没有证据就保留并写明仍欠着;`valid_to` 已过或已被明确取代的旧条目改 `status=archived` 或补正窗口。周期兜底只提示:`runOverdueReviewPass` 对逾期 ≥7 天的 open 承诺写一条 `check` 活动日志(同一条 7 天内不重复,节流表在 `state.cycle.overdueReviewAt`),**不改 status**;过期草稿在 TTL 之后再留 30 天,由 `archiveExpiredDrafts` 改标 `archived`(不删除,正文仍可升回 `long_term`)。口径见 `docs/memory-semantics.md` §8.9。
|
|
837
|
+
|
|
838
|
+
**怎么确认**:活动日志搜「欠账待结案」「过期草稿归档」;`state.json` 的 `cycle.overdueReviewAt` 是节流表;承诺是否结案只看 `commitment.status`(应被整理改成 `done`/`cancelled`/`expired`,周期任务永远不动它)。想让某条提前结案,直接让 agent 调 `memu_private_update` 或整理一次。
|
|
839
|
+
|
|
840
|
+
**守卫**:`tests/stale-maintenance.test.mjs` —— 保留期归档(旧的归档、窗口内不动、legacy 回退 `expiresAt`、活草稿不碰)、逾期判定门槛(open/逾期天数/marginalized/done)、周期提示只写一次且不改状态、目录欠账单列包含 id/due/天数/对象。
|
|
@@ -54,7 +54,7 @@ export const RUNTIME_STATE = Object.freeze([
|
|
|
54
54
|
{ layer: 'temporary-map', file: 'lib/inbound.js:13', name: 'calls', keyedBy: 'sessionId', clearedBy: 'tool/result or turn/end' },
|
|
55
55
|
{ layer: 'temporary-map', file: 'lib/inbound.js:14', name: 'sessions', keyedBy: 'sessionId', clearedBy: 'session/disposed (releaseInboundSession)' },
|
|
56
56
|
{ layer: 'temporary-map', file: 'lib/media.js:19', name: 'captures', keyedBy: 'sessionId', clearedBy: 'capture settle' },
|
|
57
|
-
{ layer: 'temporary-map', file: 'lib/private.js:
|
|
57
|
+
{ layer: 'temporary-map', file: 'lib/private.js:1075', name: 'inFlight', keyedBy: 'sessionId', clearedBy: 'consolidation settle' },
|
|
58
58
|
{ layer: 'temporary-map', file: 'lib/curator.js:56', name: 'jobs', keyedBy: 'job id', clearedBy: 'curation settle' },
|
|
59
59
|
{ layer: 'cache', file: 'lib/state.js:1538', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
|
|
60
60
|
{ layer: 'cache', file: 'lib/paths.js:52', name: 'readFailures', keyedBy: 'absolute file', clearedBy: 'a later successful read' },
|
|
@@ -170,7 +170,8 @@ function rangeLine(snapshot) {
|
|
|
170
170
|
* worker 的任务书:身份、范围、可用工具、回执契约。
|
|
171
171
|
* 这不是「人格」,是职责——所以它不描述风格,只描述能做什么、不能做什么、怎么交差。
|
|
172
172
|
*/
|
|
173
|
-
export function buildWorkerBrief({ snapshot, probe = null, contract = '', reason = 'auto', jobId = null, mustCover = [], autoReceipt = false, singleOnly = false } = {}) {
|
|
173
|
+
export function buildWorkerBrief({ snapshot, probe = null, contract = '', reason = 'auto', jobId = null, mustCover = [], autoReceipt = false, singleOnly = false, domain = 'general' } = {}) {
|
|
174
|
+
const coding = String(domain) === 'coding'
|
|
174
175
|
const ptc = probe?.ptcObserved === true
|
|
175
176
|
const sdkShape = singleOnly
|
|
176
177
|
? 'await tools.memu_private_remember({...}) / await tools.memu_private_update({...})'
|
|
@@ -193,11 +194,18 @@ export function buildWorkerBrief({ snapshot, probe = null, contract = '', reason
|
|
|
193
194
|
: '直接写,不要再检索:目录和召回命中已经给出。真正新增的条目合并成一次 memu_private_remember_batch({items:[...]}) 提交:每个窗口只发一次 batch,不要逐条 remember;只有本窗只写 1 条时才用 memu_private_remember。目录里已有的同一事实用 memu_private_update(用目录里的 id)合并,能合并的更新也放在同一轮里,不要一条一轮来回。',
|
|
194
195
|
'时间锚点:每条用户消息前的 [事件时间 YYYY-MM-DD HH:mm] 是那一轮的发生时间;observed_at 填这个时间,今天/明天/下周X/月底按它算绝对日期;不要用整理时的入库时间,也不要用真实时钟。',
|
|
195
196
|
'写库字段:speaker_id、source_kind、observed_at、absolute_date 必填;冲突用 conflicts_with,明确取代用 supersedes;助手说过的话用 source_kind=assistant_said;承诺写 commitment。',
|
|
196
|
-
|
|
197
|
+
coding
|
|
198
|
+
// 工程记忆的价值排序与写入形状和 RP 完全不同:中文工程结论落在 RP 排序的
|
|
199
|
+
// "其他明确事实"里会被"普通事实最多 3 条"挤掉,所以任务书按域分叉。
|
|
200
|
+
? '按价值排序:根因与修复理由 = 接口/不变量变化 = 环境与版本约束 = 被否决方案及其失败条件 > 验证结论与测试范围 > 需求/验收变化 > 工作偏好 > 其余明确事实。前两类必须写,每窗最多新增 8 条;工程结论不受「普通事实最多 3 条」限制,必写候选不受限,总数仍不超过 8 条。'
|
|
201
|
+
: '按价值排序:约定/承诺 = 新人物首次出现/换人接手/称呼变化 > 日期/改口/冲突 > 身份/边界/第三方人物 > 偏好/计划 > 其他明确事实。前两类必须写;每窗最多新增 8 条,普通事实最多 3 条,必写候选不受限,总数仍不超过 8 条。',
|
|
197
202
|
'同一件事有两种说法时各写一条,用 conflicts_with 互指;只有明确取代才用 supersedes,旧正文保留。承诺/约定写 commitment。',
|
|
203
|
+
'先清欠账再查过时:目录「欠账」里 open 且已过 due_at 的承诺,按本窗证据结案(done/cancelled/expired),没有证据就保留 open 并写明仍欠着谁;valid_to 已过或已被明确取代的旧条目用 memu_private_update 归档或补正窗口,旧正文保留。',
|
|
198
204
|
// 2026-11-15:link 裁决步骤写进任务书——触发时机明示,模型不再靠读工具参数说明猜。
|
|
199
205
|
'写完条目后用本轮创建/更新的 id 调一次 memu_private_link_suggest,返回的候选【逐条】裁决:有具体证据的用 memu_private_link 连(note 引用转录原句作依据),没有证据的明确放弃,不许全部留着不裁决。触发时机:同一事实的新版本→连到旧条(取代关系);同一个人的多条记忆→挂到命名实体 entity {name, kind};承诺/约定→commitment;两条互斥→conflict。相似≠相连,宁缺毋滥。',
|
|
200
|
-
|
|
206
|
+
coding
|
|
207
|
+
? 'content 写 150–350 字,按「结论 / 作用范围与定位(路径 + 符号,行号只作辅助)/ 条件与原因 / 验证状态」排;标题写结论本身(模块、符号、错误签名或命令),不要「修复了异步问题」这类空话;不写人物地点与原文模板,不复述整段对话。emotion 与 dominance 只属于人物侧条目,工程事实省略。'
|
|
208
|
+
: 'content 写 50–150 字,只保留人物、地点、时间、事情、原话/说话人;emotion 只在叙事确实有情绪瞬间时填写,普通事实省略;不要复述整段对话,不要写成行为日志。',
|
|
201
209
|
...(Array.isArray(mustCover) && mustCover.length > 0
|
|
202
210
|
? [
|
|
203
211
|
'本窗必写候选(先写这些,再写其他;每条都必须落库,或在失败说明里写明为什么不写,不得静默跳过):',
|
package/lib/curator.js
CHANGED
|
@@ -121,8 +121,20 @@ function eventCallId(event) {
|
|
|
121
121
|
* 次调用的双写,以 tool/call 事件为准——块只在没有对应事件时保留(先按 callId
|
|
122
122
|
* 配对;两侧都没有 id 时按 name+arguments 计数配对,支持重复调用)。字符预算
|
|
123
123
|
* 保留原行为,另加可选 token 预算(累计 estTokens 超预算即停)。
|
|
124
|
+
* 工具行额度可按域覆盖:编码域的修改重点在命令/错误签名/参数里,300/400 只够开头。
|
|
124
125
|
*/
|
|
125
|
-
export
|
|
126
|
+
export const CONDENSE_TOOL_RESULT_CHARS = 400
|
|
127
|
+
export const CONDENSE_TOOL_CALL_CHARS = 300
|
|
128
|
+
const CONDENSE_TOOL_RESULT_CHARS_CODING = 1_400
|
|
129
|
+
const CONDENSE_TOOL_CALL_CHARS_CODING = 700
|
|
130
|
+
|
|
131
|
+
export function condenseLimitsFor(domain) {
|
|
132
|
+
return String(domain) === 'coding'
|
|
133
|
+
? { toolResultChars: CONDENSE_TOOL_RESULT_CHARS_CODING, toolCallChars: CONDENSE_TOOL_CALL_CHARS_CODING }
|
|
134
|
+
: { toolResultChars: CONDENSE_TOOL_RESULT_CHARS, toolCallChars: CONDENSE_TOOL_CALL_CHARS }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function condenseEvents(events, maxChars = MAX_SESSION_CHARS, { maxTokens = Infinity, toolResultChars = CONDENSE_TOOL_RESULT_CHARS, toolCallChars = CONDENSE_TOOL_CALL_CHARS } = {}) {
|
|
126
138
|
// 事件侧先收一遍:callId 集合 + (name, arguments) 计数,供块侧配对。
|
|
127
139
|
const eventCallIds = new Set()
|
|
128
140
|
const eventSignatures = new Map()
|
|
@@ -159,17 +171,17 @@ export function condenseEvents(events, maxChars = MAX_SESSION_CHARS, { maxTokens
|
|
|
159
171
|
claimedSignatures.set(key, (claimedSignatures.get(key) || 0) + 1)
|
|
160
172
|
continue
|
|
161
173
|
}
|
|
162
|
-
lines.push(`Tool call: ${b.name}${b.arguments ? ` ${truncate(argsText(b.arguments),
|
|
174
|
+
lines.push(`Tool call: ${b.name}${b.arguments ? ` ${truncate(argsText(b.arguments), toolCallChars)}` : ''}`)
|
|
163
175
|
}
|
|
164
176
|
continue
|
|
165
177
|
}
|
|
166
178
|
if (type === 'tool/result') {
|
|
167
179
|
const text = textOf(event.data?.message?.content)
|
|
168
|
-
if (text) lines.push(`Tool result${event.data?.message?.isError ? ' (error)' : ''}: ${truncate(text,
|
|
180
|
+
if (text) lines.push(`Tool result${event.data?.message?.isError ? ' (error)' : ''}: ${truncate(text, toolResultChars)}`)
|
|
169
181
|
continue
|
|
170
182
|
}
|
|
171
183
|
if (type === 'tool/call') {
|
|
172
|
-
lines.push(`Tool call: ${event.data?.name || '?'} ${truncate(argsText(event.data?.arguments),
|
|
184
|
+
lines.push(`Tool call: ${event.data?.name || '?'} ${truncate(argsText(event.data?.arguments), toolCallChars)}`)
|
|
173
185
|
}
|
|
174
186
|
} catch {}
|
|
175
187
|
}
|
package/lib/cycle.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
getCycleState, setCycleState, listLibrariesAll, archiveLibrary, setSessionBinding,
|
|
4
4
|
deleteLibrary, restoreLibrary, normalizeCwd, inUseLibraryIds, archivedWhileInUse,
|
|
5
5
|
} from './state.js'
|
|
6
|
-
import { expireShortTerm } from './memory.js'
|
|
6
|
+
import { expireShortTerm, archiveExpiredDrafts, overdueOpenCommitments, EXPIRED_DRAFT_RETENTION_DAYS } from './memory.js'
|
|
7
7
|
import { requestPrivateConsolidation, archivedSessionIdsOf, CONSOLIDATION_BACKLOG_EVENTS, CONSOLIDATION_PROBE_MINUTES } from './private.js'
|
|
8
8
|
import { gcTurnLogs } from './turn-log.js'
|
|
9
9
|
import { startGlobalCuration } from './curator.js'
|
|
@@ -42,16 +42,86 @@ function older(a, b) {
|
|
|
42
42
|
// Short-term expiry. Runs before the sleep pass on purpose: a draft that is already
|
|
43
43
|
// past its deadline must not be offered to consolidation as something worth keeping,
|
|
44
44
|
// and promoting a dead entry would resurrect text nobody asked for again.
|
|
45
|
+
// 过期之后的保留期也在同一趟里结算:超期草稿改标 archived(不删除),
|
|
46
|
+
// 免得"第二机会"变成永久占位。
|
|
45
47
|
export function runShortTermPass(_ctx, { now = Date.now(), log = () => {} } = {}) {
|
|
46
48
|
try {
|
|
47
49
|
const result = expireShortTerm({ now })
|
|
48
50
|
if (result.expired.length > 0) {
|
|
49
51
|
log(`expired ${result.expired.length} short-term memor${result.expired.length === 1 ? 'y' : 'ies'} in ${result.libraries.length} library(ies)`)
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
let archived = { archived: [], libraries: [], skipped: 0 }
|
|
54
|
+
try {
|
|
55
|
+
archived = archiveExpiredDrafts({ now })
|
|
56
|
+
if (archived.archived.length > 0) {
|
|
57
|
+
log(`archived ${archived.archived.length} expired draft(s) past the retention window`)
|
|
58
|
+
record({
|
|
59
|
+
kind: 'check',
|
|
60
|
+
scope: 'private',
|
|
61
|
+
ok: true,
|
|
62
|
+
message: `过期草稿归档 · ${archived.archived.length} 条(保留期 ${EXPIRED_DRAFT_RETENTION_DAYS} 天,不删除正文)`,
|
|
63
|
+
detail: { ids: archived.archived.map((row) => row.id), libraries: archived.libraries },
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
log(`expired draft archiving failed: ${error?.message || error}`)
|
|
68
|
+
}
|
|
69
|
+
return { ...result, archived }
|
|
52
70
|
} catch (error) {
|
|
53
71
|
log(`short-term expiry failed: ${error?.message || error}`)
|
|
54
|
-
return { expired: [], libraries: [], error: String(error?.message || error) }
|
|
72
|
+
return { expired: [], libraries: [], skipped: 0, archived: { archived: [], libraries: [], skipped: 0 }, error: String(error?.message || error) }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 逾期承诺的周期提醒:只写一条活动日志提示"该结案了",绝不改 status。
|
|
77
|
+
// 承诺有没有兑现要靠转录证据(由整理任务书交给 worker),清理策略不替人裁决。
|
|
78
|
+
// 同一条承诺 7 天内只提示一次,避免每天刷屏。
|
|
79
|
+
const OVERDUE_REVIEW_DAYS = 7
|
|
80
|
+
const OVERDUE_REVIEW_REPEAT_MS = 7 * 86_400_000
|
|
81
|
+
const OVERDUE_REVIEW_KEYS = 500
|
|
82
|
+
|
|
83
|
+
export function runOverdueReviewPass(_ctx, { now = Date.now(), log = () => {} } = {}) {
|
|
84
|
+
try {
|
|
85
|
+
const seen = { ...(getCycleState().overdueReviewAt || {}) }
|
|
86
|
+
const noted = []
|
|
87
|
+
const liveKeys = new Set()
|
|
88
|
+
for (const lib of listLibrariesAll()) {
|
|
89
|
+
if (lib.archived === true) continue
|
|
90
|
+
const rows = overdueOpenCommitments({ libraryId: lib.id, now, minOverdueDays: OVERDUE_REVIEW_DAYS })
|
|
91
|
+
for (const row of rows) liveKeys.add(`${lib.id}:${row.id}`)
|
|
92
|
+
const due = rows.filter((row) => {
|
|
93
|
+
const last = Date.parse(seen[`${lib.id}:${row.id}`] || '') || 0
|
|
94
|
+
return !last || now - last >= OVERDUE_REVIEW_REPEAT_MS
|
|
95
|
+
})
|
|
96
|
+
if (due.length === 0) continue
|
|
97
|
+
const at = new Date(now).toISOString()
|
|
98
|
+
for (const row of due) {
|
|
99
|
+
seen[`${lib.id}:${row.id}`] = at
|
|
100
|
+
noted.push({ libraryId: lib.id, id: row.id, daysOverdue: row.daysOverdue })
|
|
101
|
+
}
|
|
102
|
+
record({
|
|
103
|
+
kind: 'check',
|
|
104
|
+
scope: 'private',
|
|
105
|
+
libraryId: lib.id,
|
|
106
|
+
ok: true,
|
|
107
|
+
message: `欠账待结案 · ${due.length} 条承诺逾期 ≥${OVERDUE_REVIEW_DAYS} 天(整理时按证据结案)`,
|
|
108
|
+
detail: { ids: due.map((row) => row.id), daysOverdue: due.map((row) => row.daysOverdue) },
|
|
109
|
+
})
|
|
110
|
+
log(`overdue commitments in ${lib.id}: ${due.length} past ${OVERDUE_REVIEW_DAYS} days`)
|
|
111
|
+
}
|
|
112
|
+
// 标记表只留还欠着的 + 60 天内的记录,上限 500,避免无限长。
|
|
113
|
+
const cutoff = now - 60 * 86_400_000
|
|
114
|
+
const kept = Object.entries(seen)
|
|
115
|
+
.filter(([key, at]) => liveKeys.has(key) || (Date.parse(at) || 0) >= cutoff)
|
|
116
|
+
.sort((a, b) => (Date.parse(b[1]) || 0) - (Date.parse(a[1]) || 0))
|
|
117
|
+
.slice(0, OVERDUE_REVIEW_KEYS)
|
|
118
|
+
if (noted.length > 0 || kept.length !== Object.keys(seen).length) {
|
|
119
|
+
setCycleState({ overdueReviewAt: Object.fromEntries(kept) })
|
|
120
|
+
}
|
|
121
|
+
return { noted: noted.length, rows: noted }
|
|
122
|
+
} catch (error) {
|
|
123
|
+
log(`overdue commitment review failed: ${error?.message || error}`)
|
|
124
|
+
return { noted: 0, rows: [], error: String(error?.message || error) }
|
|
55
125
|
}
|
|
56
126
|
}
|
|
57
127
|
|
|
@@ -378,6 +448,7 @@ export function runLibraryHousekeeping(ctx, { now = Date.now(), log = () => {} }
|
|
|
378
448
|
|
|
379
449
|
export async function runCyclePasses(ctx, options = {}) {
|
|
380
450
|
const shortTerm = runShortTermPass(ctx, options)
|
|
451
|
+
const overdue = runOverdueReviewPass(ctx, options)
|
|
381
452
|
// turn-log GC 挂在 sweep 顺带跑(§3.4),只做 stat/绑定表级别的便宜检查。
|
|
382
453
|
const turnLogs = runTurnLogGcPass(ctx, options)
|
|
383
454
|
const sleep = await runSleepPass(ctx, options)
|
|
@@ -394,7 +465,7 @@ export async function runCyclePasses(ctx, options = {}) {
|
|
|
394
465
|
try { options.log?.(`salient wake pass failed: ${error?.message || error}`) } catch {}
|
|
395
466
|
return { created: 0, cleaned: 0, skipped: 0, errors: 1 }
|
|
396
467
|
})
|
|
397
|
-
return { shortTerm, turnLogs, sleep, curate, libraries, migrated, salientWake }
|
|
468
|
+
return { shortTerm, overdue, turnLogs, sleep, curate, libraries, migrated, salientWake }
|
|
398
469
|
}
|
|
399
470
|
|
|
400
471
|
// DSH has no host scheduler a plugin can register a *global* job with
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { registerCycle } from './cycle.js'
|
|
|
6
6
|
import { syncPromptDefaults } from './prompts.js'
|
|
7
7
|
import { ensureEngine, engineStatus, ENGINE_VERSION } from './engine.js'
|
|
8
8
|
import { getSettings, getMemoryBackend, backupDatabases, flushState, listLibraries, getSessionBinding, getCycleState, setCycleState, loadPrivateIndex } from './state.js'
|
|
9
|
-
import { buildTurnRecords, recordTurn, deleteTurnLog } from './turn-log.js'
|
|
9
|
+
import { buildTurnRecords, recordTurn, deleteTurnLog, turnLogLimits } from './turn-log.js'
|
|
10
10
|
import { pruneOrphanEntitiesAll } from './graph.js'
|
|
11
11
|
import { pruneDeletedStores } from './memory.js'
|
|
12
12
|
import { closeEmbeddingWorkers, setEmbeddingFailureSink } from './local-embedding-manager.js'
|
|
@@ -296,7 +296,9 @@ export function registerTurnLogRecorder(ctx) {
|
|
|
296
296
|
buffers.delete(sessionId)
|
|
297
297
|
if (!buffer || !turnLogAdmitted(session)) return
|
|
298
298
|
buffer.push(event)
|
|
299
|
-
|
|
299
|
+
const binding = getSessionBinding(sessionId)
|
|
300
|
+
const limits = turnLogLimits(binding?.domainOverride || binding?.domain || 'general')
|
|
301
|
+
for (const record of buildTurnRecords(buffer, limits)) recordTurn(sessionId, record)
|
|
300
302
|
return
|
|
301
303
|
}
|
|
302
304
|
const buffer = buffers.get(sessionId)
|
package/lib/inject.js
CHANGED
|
@@ -1634,6 +1634,132 @@ function guideAdmission(binding, messages, guideKey) {
|
|
|
1634
1634
|
return 'replace'
|
|
1635
1635
|
}
|
|
1636
1636
|
|
|
1637
|
+
// 通道会话(dsh-channel 等)用确定性 id(`qq-dm-<uid>`)。宿主重建同名新会话后,
|
|
1638
|
+
// 转录里没有旧的一次性投放,binding 上却还留着 guideRulesKey / anchorPushed,
|
|
1639
|
+
// 稳态判据于是把 guide 与锚点永久跳过(实测 qq-dm 会话首 24 回合没有规则消息)。
|
|
1640
|
+
// 会话身份优先用宿主暴露的 createdAt;拿不到时退回「回合号回到 1」,
|
|
1641
|
+
// 并用首条消息 id 做这一代的戳,避免同一代被重复重置。
|
|
1642
|
+
function sessionStampOf(payload) {
|
|
1643
|
+
const session = payload?.agent?.session
|
|
1644
|
+
const raw = session?.createdAt ?? session?.header?.createdAt
|
|
1645
|
+
if (raw === undefined || raw === null || raw === '') return null
|
|
1646
|
+
const time = typeof raw === 'number' ? raw : Date.parse(raw)
|
|
1647
|
+
return 'created:' + (Number.isFinite(time) ? String(time) : String(raw))
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
function firstTurnStamp(decision) {
|
|
1651
|
+
const messages = Array.isArray(decision?.messages) ? decision.messages : []
|
|
1652
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
1653
|
+
const message = messages[i]
|
|
1654
|
+
if (message?.role === 'user' && message?.id) return `turn1:${message.id}`
|
|
1655
|
+
}
|
|
1656
|
+
return null
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
function resetSessionOneShots(sessionId, stamp, reason) {
|
|
1660
|
+
const binding = getSessionBinding(sessionId)
|
|
1661
|
+
if (!binding) return
|
|
1662
|
+
setSessionBinding(sessionId, {
|
|
1663
|
+
sessionStamp: stamp,
|
|
1664
|
+
reinjectPending: true,
|
|
1665
|
+
guideRulesKey: undefined,
|
|
1666
|
+
guideMessageAt: undefined,
|
|
1667
|
+
guideLost: false,
|
|
1668
|
+
anchorPushed: undefined,
|
|
1669
|
+
lastInjectedUserMessageId: undefined,
|
|
1670
|
+
})
|
|
1671
|
+
clearInjectionSeen(sessionId)
|
|
1672
|
+
record({
|
|
1673
|
+
kind: 'system',
|
|
1674
|
+
scope: 'private',
|
|
1675
|
+
sessionId,
|
|
1676
|
+
libraryId: binding.libraryId || null,
|
|
1677
|
+
ok: true,
|
|
1678
|
+
message: '同名新会话:一次性投放已重置(规则/锚点/首条去重)',
|
|
1679
|
+
detail: { reason, previousStamp: binding.sessionStamp || null },
|
|
1680
|
+
})
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
function syncSessionIncarnation(payload, decision) {
|
|
1684
|
+
try {
|
|
1685
|
+
const sessionId = payload?.agent?.session?.header?.id
|
|
1686
|
+
if (!sessionId) return
|
|
1687
|
+
const binding = getSessionBinding(sessionId)
|
|
1688
|
+
if (!binding) return
|
|
1689
|
+
const created = sessionStampOf(payload)
|
|
1690
|
+
if (created) {
|
|
1691
|
+
if (!binding.sessionStamp) {
|
|
1692
|
+
setSessionBinding(sessionId, { sessionStamp: created })
|
|
1693
|
+
return
|
|
1694
|
+
}
|
|
1695
|
+
if (binding.sessionStamp === created) return
|
|
1696
|
+
if (binding.sessionStamp.startsWith('created:')) {
|
|
1697
|
+
resetSessionOneShots(sessionId, created, 'session-stamp-changed')
|
|
1698
|
+
return
|
|
1699
|
+
}
|
|
1700
|
+
// 兜底戳不拿来和 createdAt 比:宿主开始暴露 createdAt 时只升级记录。
|
|
1701
|
+
if (Number(payload?.turn) === 1) {
|
|
1702
|
+
const current = firstTurnStamp(decision)
|
|
1703
|
+
if (current && current !== binding.sessionStamp) {
|
|
1704
|
+
resetSessionOneShots(sessionId, created, 'session-stamp-changed')
|
|
1705
|
+
return
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
setSessionBinding(sessionId, { sessionStamp: created })
|
|
1709
|
+
return
|
|
1710
|
+
}
|
|
1711
|
+
if (Number(payload?.turn) !== 1) return
|
|
1712
|
+
const fallback = firstTurnStamp(decision)
|
|
1713
|
+
if (!fallback) return
|
|
1714
|
+
if (binding.sessionStamp?.startsWith('turn1:')) {
|
|
1715
|
+
if (binding.sessionStamp !== fallback) resetSessionOneShots(sessionId, fallback, 'turn-restarted')
|
|
1716
|
+
return
|
|
1717
|
+
}
|
|
1718
|
+
if (binding.sessionStamp) return
|
|
1719
|
+
// 旧版 binding 没有会话戳:回合号回到 1 且已有过往注入,说明转录换代了。
|
|
1720
|
+
if (Number(binding.lastInjectedTurn || 0) > 1) resetSessionOneShots(sessionId, fallback, 'turn-restarted')
|
|
1721
|
+
else setSessionBinding(sessionId, { sessionStamp: fallback })
|
|
1722
|
+
} catch {}
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
// 切域改变参与召回的记忆集合,也让 guide 变体不同。guide 原本靠 rulesKey 替换,
|
|
1726
|
+
// 但锚点与按域过滤的一次性提醒(纪念日/未了之事/时段氛围)都是「一会话一次」,
|
|
1727
|
+
// 记账还在旧领域上——所以切域要显式清一遍,让新一代重新投。
|
|
1728
|
+
function syncDomainDelivery(sessionId) {
|
|
1729
|
+
try {
|
|
1730
|
+
if (!sessionId) return
|
|
1731
|
+
const binding = getSessionBinding(sessionId)
|
|
1732
|
+
if (!binding) return
|
|
1733
|
+
const domain = domainOf(binding)
|
|
1734
|
+
if (!binding.injectedDomain) {
|
|
1735
|
+
setSessionBinding(sessionId, { injectedDomain: domain })
|
|
1736
|
+
return
|
|
1737
|
+
}
|
|
1738
|
+
if (binding.injectedDomain === domain) return
|
|
1739
|
+
setSessionBinding(sessionId, {
|
|
1740
|
+
injectedDomain: domain,
|
|
1741
|
+
guideRulesKey: undefined,
|
|
1742
|
+
guideMessageAt: undefined,
|
|
1743
|
+
guideLost: false,
|
|
1744
|
+
anchorPushed: undefined,
|
|
1745
|
+
anniversariesShown: {},
|
|
1746
|
+
openLoopRemindedAt: {},
|
|
1747
|
+
textureKey: undefined,
|
|
1748
|
+
})
|
|
1749
|
+
markReinjectPending(sessionId)
|
|
1750
|
+
clearInjectionSeen(sessionId)
|
|
1751
|
+
record({
|
|
1752
|
+
kind: 'system',
|
|
1753
|
+
scope: 'private',
|
|
1754
|
+
sessionId,
|
|
1755
|
+
libraryId: binding.libraryId || null,
|
|
1756
|
+
ok: true,
|
|
1757
|
+
message: '记忆领域切换:一次性投放已重置(规则/锚点/纪念日/未了之事)',
|
|
1758
|
+
detail: { from: binding.injectedDomain, to: domain },
|
|
1759
|
+
})
|
|
1760
|
+
} catch {}
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1637
1763
|
function ensureUnifiedGuide(ctx, payload, decision) {
|
|
1638
1764
|
try {
|
|
1639
1765
|
const header = payload?.agent?.session?.header
|
|
@@ -2350,6 +2476,10 @@ export function registerInjection(ctx) {
|
|
|
2350
2476
|
const offPre = ctx.on('agent/pre-step', async (payload, next) => {
|
|
2351
2477
|
const closure = turnClosure(payload?.agent?.session?.header?.id, payload?.turn)
|
|
2352
2478
|
const decision = await next()
|
|
2479
|
+
// 同名新会话(通道重建 transcript)必须先清掉旧代的一次性记账,再让下面的
|
|
2480
|
+
// 注入与 guide 按新一代重新投放;切域同样要重投(锚点与按域过滤的提醒)。
|
|
2481
|
+
syncSessionIncarnation(payload, decision)
|
|
2482
|
+
syncDomainDelivery(payload?.agent?.session?.header?.id)
|
|
2353
2483
|
// 宿主会在同一轮里对同一条真实用户消息给出两次 enter 决策(0.2.2-rc.1 实测:
|
|
2354
2484
|
// turn 号成对跳 221→222、223→224)。第二次会重新走一遍召回,候选又全被去重,
|
|
2355
2485
|
// 结果是 0 条注入的纯空跑,还会把 memoryClock 多推一格。按真实用户消息 id 幂等:
|
|
@@ -2365,8 +2495,9 @@ export function registerInjection(ctx) {
|
|
|
2365
2495
|
stepSessionId && stepLastUser?.id && stepBinding?.reinjectPending !== true
|
|
2366
2496
|
&& stepBinding?.lastInjectedUserMessageId === stepLastUser.id && !hasPendingInbound(stepSessionId),
|
|
2367
2497
|
)
|
|
2498
|
+
let injected = decision
|
|
2368
2499
|
try {
|
|
2369
|
-
|
|
2500
|
+
injected = duplicateStep
|
|
2370
2501
|
? decision
|
|
2371
2502
|
: await injectForStep({
|
|
2372
2503
|
...payload,
|
|
@@ -2374,18 +2505,21 @@ export function registerInjection(ctx) {
|
|
|
2374
2505
|
ctx,
|
|
2375
2506
|
log: (message) => { try { ctx.logger?.warn?.(`dsh-memu-memory: ${message}`) } catch {} },
|
|
2376
2507
|
})
|
|
2377
|
-
if (turnClosure(stepSessionId, payload?.turn) !== closure) {
|
|
2378
|
-
for (const [id, proposal] of injectionAdmissions.get(stepSessionId) || []) {
|
|
2379
|
-
if (proposal.turn === Number(payload?.turn) && proposal.status === 'proposed') injectionAdmissions.get(stepSessionId).delete(id)
|
|
2380
|
-
}
|
|
2381
|
-
return decision
|
|
2382
|
-
}
|
|
2383
|
-
return ensureUnifiedGuide(ctx, payload, injected)
|
|
2384
2508
|
} catch (error) {
|
|
2385
2509
|
try { setRecallError(payload?.agent?.session?.header?.id, `injection failed: ${error?.message || error}`) } catch {}
|
|
2386
2510
|
try { ctx.logger?.warn?.(`dsh-memu-memory: pre-step injection failed (fail-open): ${error?.stack || error}`) } catch {}
|
|
2511
|
+
// 召回/入站故障不该把规则消息一起带走:guide 是独立 plugin 消息,照常尝试。
|
|
2512
|
+
// 但回合已被关闭/替换时不能给旧回合提新提案,闭包判据与成功路径一致。
|
|
2513
|
+
if (turnClosure(stepSessionId, payload?.turn) !== closure) return decision
|
|
2514
|
+
return ensureUnifiedGuide(ctx, payload, decision)
|
|
2515
|
+
}
|
|
2516
|
+
if (turnClosure(stepSessionId, payload?.turn) !== closure) {
|
|
2517
|
+
for (const [id, proposal] of injectionAdmissions.get(stepSessionId) || []) {
|
|
2518
|
+
if (proposal.turn === Number(payload?.turn) && proposal.status === 'proposed') injectionAdmissions.get(stepSessionId).delete(id)
|
|
2519
|
+
}
|
|
2387
2520
|
return decision
|
|
2388
2521
|
}
|
|
2522
|
+
return ensureUnifiedGuide(ctx, payload, injected)
|
|
2389
2523
|
}, { prepend: true })
|
|
2390
2524
|
disposers.push(offPre)
|
|
2391
2525
|
|