dsh-memu-memory 1.3.4 → 1.3.6

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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # 更新日志 / Changelog
2
2
 
3
+ ## [1.3.6] - 2026-11-15
4
+
5
+ > 修复 macOS 一键安装 MemU 引擎失败(issue #1):受管 Python(python-build-standalone)带 Developer ID 签名 + hardened runtime,macOS 库校验拒绝加载 PyPI wheel 里 ad-hoc 签名的 `pydantic_core` 二进制(dlopen 报 "different Team IDs"),所有候选解释器连环失败。
6
+
7
+ ### 引擎安装
8
+
9
+ - **macOS 签名校验自修复**:`installEngine` / `switchEngineVersion` / `ensureEngine` 的 verify 统一走 `verifyEngineRepaired`——错误文本命中签名校验形状时(`isMacOSLibraryValidationError`),对 venv 解释器的 realpath 执行 `codesign --force --sign -` ad-hoc 重签(去掉 hardened runtime 标志)并重试一次,仅 darwin 生效;已有安装下次 ensure 时同样自愈。
10
+ - **受管 Python 主动重签**:`ensureManagedPython` 装好自己的受管解释器后立即 ad-hoc 重签,在任何 venv 创建之前摘掉 hardened runtime。
11
+ - **可读的失败出口**:全部候选失败且错误呈签名形状时,错误末尾附用户侧旁路提示(`DSH_MEMU_PYTHON` 指向 Homebrew/官方 Python,或手动 codesign)。空目录说明:失败的 tmp venv 会被清理,属预期,不是数据丢失。
12
+
13
+ ### 文档与测试
14
+
15
+ - `docs/troubleshooting.md` 新增 §3.31(症状 / 落点 / 守卫)与症状速查入口。
16
+ - `tests/engine.test.mjs` 新增签名错误识别用例(issue #1 原文命中、普通 ImportError 不误触发重签)。
17
+
18
+ ## [1.3.5] - 2026-11-14
19
+
20
+ > 修复宿主对同一条用户消息给出两次 `agent/pre-step` 时的重复注入:第二次召回会把已投候选全去重、注入 0 条,还多推一格 memoryClock。现在按真实用户消息 id 幂等,一条消息只注入一次;回合回滚时清标记,真重试仍会重投。
21
+
22
+ ### 注入
23
+
24
+ - **一条用户消息只跑一次注入**:`registerInjection` 记录 `lastInjectedUserMessageId`;同一 session 收到同一条用户消息的第二次 enter 决策时只保留 guide 检查,不再召回。压缩后的 reinject(`reinjectPending`)不参与该幂等。
25
+ - **回滚清标记**:`rollbackInjectionForTurn` 撤回本轮账目时一并删除标记,宿主重试同一条消息仍会正常注入。
26
+
27
+ ### 文档与测试
28
+
29
+ - `docs/troubleshooting.md` 新增 §3.30(症状 / 根因 / 守卫)与症状速查入口。
30
+ - `tests/injection-rollback.test.mjs` 新增两条:两次 enter 决策只注入一次(memoryClock 不前进、去重账目不增加);回合回滚后重试重投。
31
+
3
32
  ## [1.3.4] - 2026-11-14
4
33
 
5
34
  > 整理执行器(实验功能)与增量回合日志:设置页可选 fork / 持久 worker(worker 按 200k 字符 / 16 窗换新,窗内批量写);整理快照增加持久日志交叉核对,修掉外部追加不可见导致的整理冻结;WebUI 空闲合成负载归零。产品文档移除 benchmark 记录与文档(测试资产不进产品文档)。
package/README.md CHANGED
@@ -30,7 +30,7 @@ It is **local-first by default**. The default `agent` backend stores full text i
30
30
  > [!WARNING]
31
31
  > **Early-stage software.** This plugin is still early and may contain unforeseen errors, bugs or breaking changes. Back up your data, and please [report an issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) or send a pull request — feedback helps the project improve.
32
32
 
33
- > **Status:** 1.3.4. The first public release was 1.0.0. The manual now lives in [`docs/`](docs/), with [`AGENTS.md`](AGENTS.md) as a short index. Back up `~/.dsh/dsh-memu-memory` before upgrades, and read [Compatibility & limits](#compatibility--limits) before storing data you cannot re-create.
33
+ > **Status:** 1.3.6. The first public release was 1.0.0. The manual now lives in [`docs/`](docs/), with [`AGENTS.md`](AGENTS.md) as a short index. Back up `~/.dsh/dsh-memu-memory` before upgrades, and read [Compatibility & limits](#compatibility--limits) before storing data you cannot re-create.
34
34
 
35
35
  ## Screenshots
36
36
 
package/README.zh.md CHANGED
@@ -30,7 +30,7 @@
30
30
  > [!WARNING]
31
31
  > **早期版本提示。** 本插件仍处于早期阶段,可能存在无法预见的错误、bug 或不兼容变更。请先备份数据;欢迎[提交 Issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) 或 PR 帮助改进。
32
32
 
33
- > **状态:** 1.3.4。首个公开发布版本为 1.0.0。细节文档已迁到 [`docs/`](docs/),[`AGENTS.md`](AGENTS.md) 只做索引。升级前请备份 `~/.dsh/dsh-memu-memory`;如果要存无法重建的数据,请先读[兼容性与边界](#兼容性与边界)。
33
+ > **状态:** 1.3.6。首个公开发布版本为 1.0.0。细节文档已迁到 [`docs/`](docs/),[`AGENTS.md`](AGENTS.md) 只做索引。升级前请备份 `~/.dsh/dsh-memu-memory`;如果要存无法重建的数据,请先读[兼容性与边界](#兼容性与边界)。
34
34
 
35
35
  ## 界面
36
36
 
@@ -38,6 +38,8 @@
38
38
  图谱改了没生效 / 缩到最小打架 / 导航被掰竖 → §3.27
39
39
  WebUI 开着 GPU 占用高 / 时钟钉高档 → §3.28
40
40
  长链跑批库不增长 / 考试大面积「不知道」→ §3.29
41
+ 同一条用户消息每轮注入两次 / 第二次召回 0 条 → §3.30
42
+ mac 一键安装引擎报 dlopen 签名错 / 事后引擎目录是空的 → §3.31
41
43
  ```
42
44
 
43
45
  ## 3. 出过的问题:症状 → 落点 → 守卫
@@ -391,6 +393,8 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
391
393
  | §3.26 | 整理超时(fork 预算) | `tests/consolidation-fork.test.mjs`:预算随事件数缩放(0/100/200/935/5000/非法值),显式 `maxWaitMs` 仍生效,超时不推进 `lastSleepSeq`。 |
392
394
  | §3.27 | 图谱改了没生效 / 缩到最小打架 / 导航被掰竖 | `npm run check` 的 `graph bundle`(源码与 bundle 逐字节比对);`tests/graph-view.test.mjs` 的 relayout 收敛、冷启动零帧、最小缩放命中迟滞;`tests/client-render.test.mjs` 的独立外壳归属。 |
393
395
  | §3.28 | WebUI 开着 GPU 占用高 / 时钟钉高档 | `tests/webui.test.mjs` 的 `the shell keeps no always-on compositor drivers`(无限动画只许 boot、ambient 静态、模糊只许小 chrome、缩略图不轮询);`scripts/check-idle-compositing.mjs` 真机数帧(空闲 fps > 2 即 FAIL)。 |
396
+ | §3.30 | 同一条用户消息每轮注入两次 | `tests/injection-rollback.test.mjs` 的 one-pass 幂等与回滚清标记两条(同一消息 id 只注入一次;回滚后重试重投)。 |
397
+ | §3.31 | mac 引擎装不上(dlopen 签名错) | `tests/engine.test.mjs` 断言 `isMacOSLibraryValidationError` 认得 issue #1 的原文错误、不误报普通 ImportError;真机验收:mac 上安装成功,install.log 出现 `re-signing interpreter ad-hoc`。 |
394
398
 
395
399
  ## 附录 A · 模块地图(原 §2.1)
396
400
 
@@ -574,3 +578,21 @@ section 的 `text(context)` 能拿到 `context.agent`,所以 system prompt **
574
578
  **根因(2026-11-14 复现实测)**:跑批脚本的 `seed-session.mjs` **直接重写** `session.v4.jsonl.zstd` 追加历史(不走网关 RPC)。宿主的 `observeSession`/`readSession` 都是 live-preferred:会话一旦是活对象,两者都读活视图、不再看持久日志,外部改写完全不可见。把种子会话钉成活对象的是 inherit 模式的 `inheritedAgentOptions` resume 回退;`host`/`custom` 模式本不需要父 route,旧代码却照样探测。于是追加 372 轮后活视图仍冻结在 6 事件 → 每窗恒等 → already-consolidated 洪水 → 游标不推进。**连带**:turn-log 录制器只收 `session/event`,直接改文件同样看不到。跑批侧 `consolidateAll` 又把 already-consolidated 当完成,不校验 `throughSeq`,把可检测故障变成静默腰斩。
575
579
 
576
580
  **守卫**:`captureSessionSnapshot` 在活视图落后于持久日志时,用 `sessionPersistence` + 宿主公开导出的 `readColdSessionLog` 冷读,取更长的一份(source `persisted-ahead`;60 秒 TTL 缓存,正常活会话不受影响)。`consolidationModelMode` 为 `host`/`custom` 时不探测父会话 route,避免无意义 resume。跑批的 `consolidateAll` 对 skipped 结果校验 `through >= targetSeq`,连续 3 次落后判定 `stale` 并终止本轮。
581
+
582
+ ### 3.30 同一条用户消息每轮注入两次(第二次召回 0 条)
583
+
584
+ **症状**:WebUI 时间线里每条用户消息后出现两条「上下文注入 · plugin:dsh-memu-memory」;召回记录成对出现(例如 13:41:41 注入 4 条 / 0 条,13:45:14 / 13:45:15),turn 号成对跳(221→222、223→224)。不报错,第二次只是纯空跑。
585
+
586
+ **根因**:宿主对同一条真实用户消息给出两次 `agent/pre-step` enter 决策;插件把每次 pre-step 都当成新的一轮,重新召回。第一次已把候选记入 `injectedIds`,第二次候选全被去重,注入 0 条,同时把 memoryClock 多推一格。
587
+
588
+ **现在**:`registerInjection` 按真实用户消息 id 幂等(`binding.lastInjectedUserMessageId`)——一条消息只跑一次注入;`turn/end` 失败且注入没进转录时,`rollbackInjectionForTurn` 清掉标记,真重试仍会重投;压缩后的 reinject(`reinjectPending`)不受影响。
589
+
590
+ **守卫**:`tests/injection-rollback.test.mjs` 的 `the same real user message gets one injection pass when the host emits two enter decisions`、`a rolled-back turn clears the one-pass marker so a real retry injects again`。
591
+
592
+ ### 3.31 macOS 一键安装引擎失败:dlopen 报「different Team IDs」(引擎安装 → macOS 签名校验)
593
+
594
+ **症状**:mac 上一键安装 MemU 引擎,安装日志里 `import memu` 在 `import pydantic_core` 处崩:`dlopen(..._pydantic_core.cpython-312-darwin.so): code signature ... not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs`,最终 `no Python candidate could install MemU`。事后按网上教程想去 `engine/0.11.0b3/` 手动 codesign,却发现目录是空的。
595
+
596
+ **落点,可能的原因**:uv 受管 Python 与 DSH 自带 runtime 都是 python-build-standalone 构建,macOS 上带 **Developer ID 签名 + hardened runtime**;macOS 库校验因此拒绝加载 PyPI wheel 里 ad-hoc 签名的 `.so`——pydantic_core 是纯二进制扩展,必撞。修复对象不是 `.so` 而是解释器本身:`codesign --force --sign -` 重签会同时去掉 hardened runtime 标志,之后所有 wheel 都能加载(Homebrew / python.org 官方安装器没有这个签名组合,所以多数 mac 用户遇不到)。**空目录是正常现象**:verify 失败后 `installEngine` 会清掉失败的 tmp venv(`cleanupDir`),所以“到那个目录里 codesign”无从下手,只能靠插件自己修。修法:`installEngine` / `switchEngineVersion` / `ensureEngine` 的 verify 统一走 `verifyEngineRepaired`——错误文本命中 `isMacOSLibraryValidationError` 时,对 venv 解释器的 realpath 做 ad-hoc 重签并重试一次;`ensureManagedPython` 对自己的受管解释器装完即主动重签(是插件下载的产物,随便签)。所有候选都失败时,错误末尾带用户侧旁路提示:`DSH_MEMU_PYTHON` 指向 Homebrew/官方 Python。
597
+
598
+ **守卫**:`tests/engine.test.mjs` 的 `the macOS library-validation dlopen error is recognized for the signing repair`(issue #1 原文错误命中、普通 ImportError 不误触发重签);真机验收项:mac + 受管 Python 安装成功,install.log 里出现 `re-signing interpreter ad-hoc` 一行。
@@ -56,7 +56,7 @@ export const RUNTIME_STATE = Object.freeze([
56
56
  { layer: 'temporary-map', file: 'lib/media.js:19', name: 'captures', keyedBy: 'sessionId', clearedBy: 'capture settle' },
57
57
  { layer: 'temporary-map', file: 'lib/private.js:982', 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
- { layer: 'cache', file: 'lib/state.js:1230', name: 'indexCache', keyedBy: 'libraryId', clearedBy: 'next load / external write' },
59
+ { layer: 'cache', file: 'lib/state.js:1233', 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' },
61
61
  ])
62
62
 
package/lib/engine.js CHANGED
@@ -150,6 +150,52 @@ function isWindows() {
150
150
  return process.platform === 'win32'
151
151
  }
152
152
 
153
+ function isMac() {
154
+ return process.platform === 'darwin'
155
+ }
156
+
157
+ // macOS library validation rejects the ad-hoc-signed `.so` files inside PyPI
158
+ // wheels when the running interpreter itself is Developer-ID signed with the
159
+ // hardened runtime (python-build-standalone: the uv-managed Python and the DSH
160
+ // bundled runtime). The dlopen error names "different Team IDs"; ad-hoc
161
+ // re-signing the interpreter drops the hardened runtime flag and lets every
162
+ // wheel load. Matched against verifyEngine's error text so the repair only
163
+ // fires on real signature failures, never on unrelated import errors.
164
+ export function isMacOSLibraryValidationError(text) {
165
+ return /code signature|different Team IDs|SignatureInvalid|library validation/i.test(String(text || ''))
166
+ }
167
+
168
+ // Best-effort: codesign always exists on macOS, but re-signing an interpreter
169
+ // we don't own (Homebrew, python.org) may fail on permissions; callers treat
170
+ // `false` as "repair unavailable" and let the normal error path report.
171
+ async function resignDarwinInterpreter(python, log) {
172
+ if (!isMac()) return false
173
+ let target = python
174
+ try { target = fs.realpathSync(python) } catch {}
175
+ logLine(`re-signing interpreter ad-hoc (macOS library validation): ${target}`, log)
176
+ const res = await run('/usr/bin/codesign', ['--force', '--sign', '-', target], { timeoutMs: 60_000 })
177
+ if (res.code !== 0) {
178
+ logLine(`codesign failed: ${(res.stderr || res.stdout || '').trim().slice(-200)}`, log)
179
+ return false
180
+ }
181
+ // Files written by other tools can carry a quarantine xattr that would break
182
+ // the next exec even with a valid signature; clearing it is harmless if absent.
183
+ await run('/usr/bin/xattr', ['-d', 'com.apple.quarantine', target], { timeoutMs: 15_000 })
184
+ return true
185
+ }
186
+
187
+ // verifyEngine plus the macOS signature repair: on a signature-shaped failure,
188
+ // re-sign the venv's base interpreter once and verify again before declaring
189
+ // the candidate broken. Every verify site goes through here so existing
190
+ // installs self-heal on the next ensure/install too.
191
+ async function verifyEngineRepaired(python, { log, expectedVersion = null } = {}) {
192
+ const verified = await verifyEngine(python, { log, expectedVersion })
193
+ if (verified.ok || !isMac() || !isMacOSLibraryValidationError(verified.error)) return verified
194
+ logLine(`verify failed with a macOS code-signature error; repairing and retrying`, log)
195
+ await resignDarwinInterpreter(python, log)
196
+ return verifyEngine(python, { log, expectedVersion })
197
+ }
198
+
153
199
  export function venvPython(venv) {
154
200
  return isWindows()
155
201
  ? path.join(venv, 'Scripts', 'python.exe')
@@ -525,7 +571,7 @@ export async function switchEngineVersion(version, { log = null, beforeSwitch =
525
571
 
526
572
  if (!acquireLock()) return { ok: false, status: 'installing', error: 'another install is already running' }
527
573
  try {
528
- const verified = await verifyEngine(target.python, { log, expectedVersion: version })
574
+ const verified = await verifyEngineRepaired(target.python, { log, expectedVersion: version })
529
575
  // Record what the probe saw, so the version list can say "usable" or "broken"
530
576
  // instead of guessing from the presence of a venv directory.
531
577
  recordProbe(version, verified)
@@ -864,7 +910,7 @@ export function readInstallLogTail(maxLines = 14, maxBytes = 24 * 1024) {
864
910
  export async function installEngine({ force = false, log = null, beforeSwitch = null } = {}) {
865
911
  const current = readCurrent()
866
912
  if (!force && current?.version === ENGINE_VERSION) {
867
- const verified = await verifyEngine(current.python, { log })
913
+ const verified = await verifyEngineRepaired(current.python, { log })
868
914
  if (verified.ok) return { ok: true, current, verified }
869
915
  }
870
916
 
@@ -918,7 +964,7 @@ export async function installEngine({ force = false, log = null, beforeSwitch =
918
964
 
919
965
  stateInstalling(`verifying:${base.source}`)
920
966
  const python = venvPython(tmpVenv)
921
- const verified = await verifyEngine(python, { log, expectedVersion: ENGINE_VERSION })
967
+ const verified = await verifyEngineRepaired(python, { log, expectedVersion: ENGINE_VERSION })
922
968
  if (!verified.ok) throw new Error(`verify failed: ${verified.error}`)
923
969
 
924
970
  if (typeof beforeSwitch === 'function') {
@@ -959,7 +1005,11 @@ export async function installEngine({ force = false, log = null, beforeSwitch =
959
1005
  }
960
1006
  }
961
1007
 
962
- throw new Error(`no Python candidate could install MemU:\n${errors.join('\n')}`)
1008
+ let message = `no Python candidate could install MemU:\n${errors.join('\n')}`
1009
+ if (isMac() && errors.some((e) => isMacOSLibraryValidationError(e))) {
1010
+ message += '\n(macOS 签名校验拒绝了依赖包的 .so;可对 Python 解释器执行 `codesign --force --sign - <python路径>` 后重试,或在设置里用 DSH_MEMU_PYTHON 指定 Homebrew/官方 Python)'
1011
+ }
1012
+ throw new Error(message)
963
1013
  } catch (error) {
964
1014
  stateError(error)
965
1015
  await cleanupDownloads()
@@ -973,7 +1023,7 @@ export async function installEngine({ force = false, log = null, beforeSwitch =
973
1023
  export async function ensureEngine({ force = false, log = null, beforeSwitch = null } = {}) {
974
1024
  const current = readCurrent()
975
1025
  if (!force && current?.version === ENGINE_VERSION) {
976
- const verified = await verifyEngine(current.python, { log })
1026
+ const verified = await verifyEngineRepaired(current.python, { log })
977
1027
  if (verified.ok) {
978
1028
  writeState({ status: 'ready', version: ENGINE_VERSION, step: 'ready', error: null })
979
1029
  return { ok: true, current, verified }
package/lib/inject.js CHANGED
@@ -1800,13 +1800,33 @@ export function registerInjection(ctx) {
1800
1800
 
1801
1801
  const offPre = ctx.on('agent/pre-step', async (payload, next) => {
1802
1802
  const decision = await next()
1803
+ // 宿主会在同一轮里对同一条真实用户消息给出两次 enter 决策(0.2.2-rc.1 实测:
1804
+ // turn 号成对跳 221→222、223→224)。第二次会重新走一遍召回,候选又全被去重,
1805
+ // 结果是 0 条注入的纯空跑,还会把 memoryClock 多推一格。按真实用户消息 id 幂等:
1806
+ // 一条消息只投一次;回合回滚时由 state.rollbackInjectionForTurn 清掉标记,真重试仍会重投。
1807
+ const stepSessionId = payload?.agent?.session?.header?.id || null
1808
+ const stepLastUser = decision?.kind === 'enter' && Array.isArray(decision.messages)
1809
+ ? lastRealUser(decision.messages)
1810
+ : null
1811
+ const stepBinding = stepSessionId
1812
+ ? (() => { try { return getSessionBinding(stepSessionId) } catch { return null } })()
1813
+ : null
1814
+ const duplicateStep = Boolean(
1815
+ stepSessionId && stepLastUser?.id && stepBinding?.reinjectPending !== true
1816
+ && stepBinding?.lastInjectedUserMessageId === stepLastUser.id,
1817
+ )
1803
1818
  try {
1804
- const injected = await injectForStep({
1805
- ...payload,
1806
- decision,
1807
- ctx,
1808
- log: (message) => { try { ctx.logger?.warn?.(`dsh-memu-memory: ${message}`) } catch {} },
1809
- })
1819
+ const injected = duplicateStep
1820
+ ? decision
1821
+ : await injectForStep({
1822
+ ...payload,
1823
+ decision,
1824
+ ctx,
1825
+ log: (message) => { try { ctx.logger?.warn?.(`dsh-memu-memory: ${message}`) } catch {} },
1826
+ })
1827
+ if (!duplicateStep && stepSessionId && stepLastUser?.id) {
1828
+ try { setSessionBinding(stepSessionId, { lastInjectedUserMessageId: stepLastUser.id }) } catch {}
1829
+ }
1810
1830
  return ensureUnifiedGuide(ctx, payload, injected)
1811
1831
  } catch (error) {
1812
1832
  try { setRecallError(payload?.agent?.session?.header?.id, `injection failed: ${error?.message || error}`) } catch {}
@@ -104,5 +104,15 @@ export async function ensureManagedPython({ run, log = () => {}, fetcher = fetch
104
104
  const found = await run(executable, ['python', 'find', '--no-python-downloads', MANAGED_PYTHON], { env, timeoutMs: 20_000 })
105
105
  const python = path.resolve(found.stdout.trim())
106
106
  if (found.code !== 0 || !python.startsWith(path.resolve(env.UV_PYTHON_INSTALL_DIR) + path.sep) || !fs.existsSync(python)) throw new Error('managed Python escaped its engine directory')
107
+ if (process.platform === 'darwin') {
108
+ // python-build-standalone interpreters ship Developer-ID-signed with the
109
+ // hardened runtime, so macOS library validation rejects the ad-hoc-signed
110
+ // .so files inside PyPI wheels ("different Team IDs" dlopen failure). Our
111
+ // own managed interpreter is safe to re-sign ad-hoc, which drops the
112
+ // hardened runtime flag before any venv is created from it.
113
+ const resign = await run('/usr/bin/codesign', ['--force', '--sign', '-', python], { env, timeoutMs: 60_000 })
114
+ if (resign.code !== 0) log(`ad-hoc re-sign of managed Python failed (continuing): ${(resign.stderr || resign.stdout || '').trim()}`)
115
+ else log('managed Python re-signed ad-hoc to avoid macOS library validation errors')
116
+ }
107
117
  return { kind: 'python', cmd: python, prefix: [], version: { major: 3, minor: 12, raw: MANAGED_PYTHON }, hasPip: false, uvPath: executable, uvEnv: env, source: 'managed-uv' }
108
118
  }
package/lib/state.js CHANGED
@@ -1177,6 +1177,9 @@ export function rollbackInjectionForTurn(sessionId, hostTurn) {
1177
1177
  }
1178
1178
  // 哨兵已不再进 injectedIds,必须单独撤掉它的"已投"标记,否则回滚后锚点不再重投。
1179
1179
  if (ids.has('__anchor__')) delete binding.anchorPushed
1180
+ // 这一轮注入没进转录,宿主重试时同一条用户消息会再送一次 pre-step:
1181
+ // 清掉「一消息一投」标记,让重试还能正常注入。
1182
+ delete binding.lastInjectedUserMessageId
1180
1183
  if (record.guideKey && binding.guideRulesKey === record.guideKey) {
1181
1184
  delete binding.guideRulesKey
1182
1185
  delete binding.guideMessageAt
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-memu-memory",
3
3
  "icon": "./assets/icon.png",
4
- "version": "1.3.4",
4
+ "version": "1.3.6",
5
5
  "description": "面向长篇 RP 与陪伴对话的 DeepSeek Harness 记忆插件:三层记忆、逐轮召回、来源标注、关系图、图片附件与独立 WebUI。",
6
6
  "keywords": [
7
7
  "deepseek-harness",
@@ -33,3 +33,16 @@ test('a release sorts above its pre-releases', () => {
33
33
  assert.ok(engine.compareVersions('0.11.0b3', '0.11.0b2') > 0)
34
34
  assert.ok(engine.compareVersions('0.11.0b1', '0.10.0') > 0)
35
35
  })
36
+
37
+ test('the macOS library-validation dlopen error is recognized for the signing repair', () => {
38
+ // Verbatim shape from GitHub issue #1 (macOS one-click install failure).
39
+ const issue = "ImportError: dlopen(/Users/best/.dsh/dsh-memu-memory/engine/0.11.0b3/venv.tmp-47668/lib/python3.12/site-packages/pydantic_core/_pydantic_core.cpython-312-darwin.so, 0x0002): code signature in <path> not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs"
40
+ assert.ok(engine.isMacOSLibraryValidationError(issue))
41
+ assert.ok(engine.isMacOSLibraryValidationError('list-files smoke failed: library validation failed to load _pydantic_core'))
42
+ assert.ok(engine.isMacOSLibraryValidationError('pip install failed: SignatureInvalid'))
43
+ // Unrelated failures must not trigger an interpreter re-sign.
44
+ assert.equal(engine.isMacOSLibraryValidationError('ImportError: No module named memu'), false)
45
+ assert.equal(engine.isMacOSLibraryValidationError('verify failed: memu-cli version mismatch'), false)
46
+ assert.equal(engine.isMacOSLibraryValidationError(''), false)
47
+ assert.equal(engine.isMacOSLibraryValidationError(null), false)
48
+ })
@@ -228,3 +228,37 @@ test('rollback also clears the day marks so dated blocks can return', async () =
228
228
  assert.equal(Object.keys(after.anniversariesShown || {}).length, 0, 'the day mark is withdrawn with the turn')
229
229
  assert.equal(Object.keys(after.openLoopRemindedAt || {}).length, 0, 'and so is the re-reminder clock')
230
230
  })
231
+
232
+ test('the same real user message gets one injection pass when the host emits two enter decisions', async () => {
233
+ const session = makeSession('dup-step')
234
+ const first = await step(session, 221, [user(1, '林眠的相机镜头维修到哪一步了?')])
235
+ const afterFirst = state.getSessionBinding(session.id)
236
+ assert.equal(afterFirst.lastInjectedUserMessageId, 'u-1', 'the first pass marks the message it handled')
237
+ const clockAfterFirst = afterFirst.inbound?.clock
238
+ const injectedAfterFirst = facts(session.id).injected
239
+ const pluginBlocks = (messages) => messages.filter((message) => message?.source?.kind === 'plugin:dsh-memu-memory').length
240
+ const blocksAfterFirst = pluginBlocks(first)
241
+ assert.ok(blocksAfterFirst > 0, 'the first pass actually injected something')
242
+
243
+ // 宿主把同一条用户消息又交给了一次 enter 决策(turn 号成对跳),第二次不应再召回。
244
+ const second = await step(session, 222, [...first])
245
+ assert.equal(pluginBlocks(second), blocksAfterFirst, 'the duplicate pass adds no second memory block')
246
+ const afterSecond = state.getSessionBinding(session.id)
247
+ assert.equal(afterSecond.lastInjectedUserMessageId, 'u-1', 'the marker stays on the handled message')
248
+ assert.equal(afterSecond.inbound?.clock, clockAfterFirst, 'the duplicate pass does not advance the memory clock')
249
+ assert.equal(facts(session.id).injected, injectedAfterFirst, 'nor does it write new dedupe accounting')
250
+ })
251
+
252
+ test('a rolled-back turn clears the one-pass marker so a real retry injects again', async () => {
253
+ const session = makeSession('dup-retry')
254
+ const first = await step(session, 1, [user(1, '林眠的相机镜头修好了吗')])
255
+ assert.equal(countWith(first, ANCHOR_RE), 1)
256
+ assert.equal(state.getSessionBinding(session.id).lastInjectedUserMessageId, 'u-1')
257
+
258
+ await failTurn(session, 1)
259
+ assert.equal(state.getSessionBinding(session.id).lastInjectedUserMessageId, undefined,
260
+ 'the rollback forgets the message so a real retry can inject again')
261
+
262
+ const retry = await step(session, 1, [user(1, '林眠的相机镜头修好了吗')])
263
+ assert.equal(countWith(retry, ANCHOR_RE), 1, 'the retry places the anchor again')
264
+ })