dsh-memu-memory 1.2.6 → 1.2.8
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/AGENTS.md +1 -1
- package/README.md +10 -15
- package/README.zh.md +10 -15
- package/docs/contributing.md +1 -1
- package/docs/host-adaptation.md +1 -1
- package/docs/memory-semantics.md +26 -4
- package/docs/troubleshooting.md +3 -1
- package/lib/backup.js +1 -1
- package/lib/binding-diagnostics.js +2 -2
- package/lib/budget.js +31 -0
- package/lib/client.js +276 -28
- package/lib/commitment.js +138 -0
- package/lib/consolidation-receipt.js +2 -0
- package/lib/consolidation-worker.js +3 -0
- package/lib/curator-policy.js +98 -0
- package/lib/fork-model.js +312 -0
- package/lib/freshness.js +24 -0
- package/lib/inject.js +117 -10
- package/lib/lexicon.js +1 -1
- package/lib/local-vector-service.js +4 -1
- package/lib/memory.js +600 -43
- package/lib/memu.js +4 -0
- package/lib/private.js +49 -8
- package/lib/prompts/private-consolidation.mixed.md +3 -2
- package/lib/prompts/private-consolidation.rp.md +7 -1
- package/lib/prompts/private-policy.mixed.md +1 -0
- package/lib/prompts/private-policy.rp.md +5 -1
- package/lib/prompts/system-guide.rp.md +3 -0
- package/lib/recall-cache.js +212 -0
- package/lib/rpc.js +44 -6
- package/lib/snippet.js +25 -0
- package/lib/state.js +43 -1
- package/lib/temporal.js +329 -0
- package/lib/text-retrieval.js +292 -28
- package/lib/tokenizer-v2.js +295 -0
- package/lib/tools.js +81 -4
- package/lib/webui/standalone.css +17 -1
- package/package.json +1 -1
- package/scripts/bench-recall.mjs +142 -0
- package/scripts/check-seed-compat.mjs +118 -0
- package/tests/backup.test.mjs +2 -2
- package/tests/commitment.test.mjs +144 -0
- package/tests/consolidation-fork.test.mjs +122 -5
- package/tests/curator-clusters.test.mjs +7 -1
- package/tests/curator-pairing.test.mjs +52 -8
- package/tests/disclosure.test.mjs +34 -17
- package/tests/dynamic-rrf.test.mjs +179 -0
- package/tests/fact-version.test.mjs +128 -0
- package/tests/fork-model.test.mjs +345 -0
- package/tests/help-page.test.mjs +1 -1
- package/tests/inject-conflict.test.mjs +94 -0
- package/tests/inject-guide.test.mjs +5 -3
- package/tests/inject.test.mjs +2 -2
- package/tests/injection-intent-budget.test.mjs +92 -0
- package/tests/lexicon-frequency.test.mjs +1 -1
- package/tests/loader.mjs +3 -0
- package/tests/memory-chain.test.mjs +140 -0
- package/tests/memory-fields.test.mjs +134 -0
- package/tests/memu-resident.test.mjs +33 -0
- package/tests/negation-polarity.test.mjs +135 -0
- package/tests/prompt-semantics.test.mjs +51 -0
- package/tests/query-decompose.test.mjs +62 -0
- package/tests/recall-cache.test.mjs +292 -0
- package/tests/recall-intent.test.mjs +100 -0
- package/tests/speaker-provenance.test.mjs +120 -0
- package/tests/stubs/dsh-llm-pi-ai.js +13 -0
- package/tests/temporal.test.mjs +124 -0
- package/tests/tokenizer-v2.test.mjs +142 -0
package/AGENTS.md
CHANGED
|
@@ -65,7 +65,7 @@ node scripts/acceptance-local.mjs # 50/50
|
|
|
65
65
|
npm run check # node --check + i18n + package.json + 文档预算
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
**结果口径**:以 `node --test` 输出的 `ℹ tests / pass / fail / skipped` 为准。用例数变了先问「是不是我加的」,失败先问「是不是并发写了同一个库」——这仓库真会多个会话同时改它。测试数字只作**带日期快照**引用(2026-11-
|
|
68
|
+
**结果口径**:以 `node --test` 输出的 `ℹ tests / pass / fail / skipped` 为准。用例数变了先问「是不是我加的」,失败先问「是不是并发写了同一个库」——这仓库真会多个会话同时改它。测试数字只作**带日期快照**引用(2026-11-06 实测 1473 tests / 1471 pass / 0 fail / 2 skipped;两条真实引擎用例按设计跳过,历史 1293/1291/1287/1280/1277/1273/1210/505/493/463/409/392 等不再代表当前),不当成当前保证。提交前逐条对 `docs/contributing.md` §10。
|
|
69
69
|
|
|
70
70
|
---
|
|
71
71
|
|
package/README.md
CHANGED
|
@@ -23,14 +23,18 @@
|
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
`dsh-memu-memory` is built for long-form RP and companion chats. It gives a DSH conversation a memory that behaves like memory instead of a log: three retention layers that fade, a first-turn anchor plus at most one per-turn recall, provenance that cannot be quietly upgraded from "I inferred it" to "they said it", contradictions that wait for a decision instead of
|
|
26
|
+
`dsh-memu-memory` is built for long-form RP and companion chats. It gives a DSH conversation a memory that behaves like memory instead of a log: three retention layers that fade, a first-turn anchor plus at most one per-turn recall, provenance that cannot be quietly upgraded from "I inferred it" to "they said it", contradictions that either wait for a decision or — when explicitly versioned — stay side by side with a conflict card instead of being silently merged, near-identical facts collapse to one entry and one recall seat, and an optional relationship graph with evidence. Speakers, characters, worlds and story branches form hard boundaries, and what a character is allowed to know stays separate from what actually happened.
|
|
27
27
|
|
|
28
28
|
It is **local-first by default**. The default `agent` backend stores full text in JSON indexes and recalls lexically — no Python, no embedding service, no API key. The `api` backend switches recall to the optional, pinned MemU engine (vector search). MemU is a plugin for people who want it, not a requirement for the plugin to start.
|
|
29
29
|
|
|
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.2.
|
|
33
|
+
> **Status:** 1.2.8. 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
|
+
|
|
35
|
+
## Benchmark
|
|
36
|
+
|
|
37
|
+
The public [chat-memory-benchmark](https://github.com/Ornn8/chat-memory-benchmark) full 714-question run (2026-11-06, `dys-router / deepseek-v4.1-flash`, high reasoning) passed **653 / 714 (91.46%)**. The run's actual measured memory cost was **¥16.05**; the full run, including non-memory overhead, cost **¥24.45** (75,517,851 tokens total, at the provider's off-peak rate) — measured end to end, not extrapolated from a single session.
|
|
34
38
|
|
|
35
39
|
## Screenshots
|
|
36
40
|
|
|
@@ -60,10 +64,10 @@ All screenshots are the real WebUI on isolated example data, not anyone's memori
|
|
|
60
64
|
- **Recall is a moment, not a dump.** The first turn after a session starts (or after compaction) gets an anchor block with budgets for pinned, core and global memory. After that, each user turn gets at most one recall. Deduplication and a token budget are enforced in code, not left to the prompt. Anchor and recall entries are **title cards**: title, id and semantic tags only. The body stays in the drawer and behind `memu_private_recall` / `memu_global_recall`, so the same budget exposes far more memories without pasting text the model never asked for.
|
|
61
65
|
- **A private lexicon writes itself.** The consolidation worker extracts stable, evidenced slang, memes and project terms with one term per entry. Ordinary entries become active immediately (no human review queue), while sensitive triggers and sensitive edits stay user-only. The lexicon page is a card flow with active/archived tabs, edit, archive/restore and two-step permanent delete. A **global lexicon** sits beside the per-library ones: every conversation reads it, only you write it. With same-domain cross-library recall on, the anchor, this-turn match and `memu_lexicon_search` merge those libraries too — the page still browses one book at a time.
|
|
62
66
|
- **Private links are algorithm-first.** After consolidation, a zero-token pass connects memories that share a rare name or alias in the same context/track and creates/reuses an entity hub (for example `yuike`). Uncertain pairs are handed to the consolidation worker for an evidence-based decision. Links are metadata (`source: 'auto'`), shown with an “Auto” badge in the graph and removable; they never rewrite a body, write a vector or delete anything.
|
|
63
|
-
- **A date is either an anniversary or one day.** `MM-DD` recurs every year (a birthday); `YYYY-MM-DD` fires the day before and the day itself, then is spent.
|
|
67
|
+
- **A date is either an anniversary or one day.** `MM-DD` recurs every year (a birthday); `YYYY-MM-DD` fires the day before and the day itself, then is spent. Relative wording (今天 / 明天 / 下周X / 月底) is resolved against the turn's scene time and stored as an absolute date; a memory that says "tomorrow" is stored as the dated form, so an appointment does not come back every year.
|
|
64
68
|
- **Memory fades unevenly.** Recency, access count, peak and end effects, primacy, habituation and flashbulb accuracy feed one strength score. Mood is described by four components (joy / anger / sorrow / fear, summing to 1) plus arousal (intensity) and dominance (sense of control); a compound mood such as jealousy is a named mix of the four, not a new axis. Mood only reorders recall: it never enters the injected text and never rewrites a memory body. Gating is the OR of three independent conditions — the dominant share is >= 0.35, |arousal - 0.35| >= 0.1, or |dominance| >= 0.25; when none holds, both multipliers are exactly 1. Older entries carry no emotion and keep the old valence path; the four axes are never inferred back from valence. A vivid memory can be more confident than it is accurate, and the UI says so.
|
|
65
|
-
- **Provenance is a fact, not a style.** Every entry carries `source` (`user_said` / `
|
|
66
|
-
- **Contradictions
|
|
69
|
+
- **Provenance is a fact, not a style.** Every entry carries `source` / `source_kind` (`user_said` / `assistant_said` / `told` / `imagined` / `inferred` / `tool`), `speaker_id`, `confidence`, `accuracy`, and disclosure rules. A vague recollection cannot impersonate a quote, and the assistant's own promises or plans cannot be filed as something the user said.
|
|
70
|
+
- **Contradictions do not get silently merged.** An ordinary contradiction still lands as `pending_review`: it is not injected, not recalled, and appears in a review queue until someone accepts or rejects it. When the writer explicitly marks two statements as versions of one fact (`conflicts_with`), both stay active, are recalled together and surface as a conflict card; an explicit `supersedes` retires the old row without deleting its text.
|
|
67
71
|
- **Secrets stay excluded.** `secret` visibility, group-chat channels, characters, worlds, branches and `knownBy` all constrain reads and edits. Automatic recall never injects a `secret` memory, and a `secret` is still readable by an explicit recall from the same folder — it hides a memory from the prompt, it is not a lock. What actually separates two conversations in one folder is the `context` scope (`channelId` / `characterId` / `worldId` / `branchId`); a blank scope on both sides means one shared scope, which is the point of a folder. The old `visibility: 'session'` level is gone — reading turns it into `shared` with its `context` untouched, and `node scripts/migrate-visibility.mjs` rewrites libraries that still store it (`--apply`, backs up first).
|
|
68
72
|
- **People and stories are structured.** Group chat uses stable `speakerId` / `channelId`, not display names. RP uses `characterId` / `worldId` / `branchId`. Relationships are edges with a note and confidence, entities can be renamed without rewriting memory bodies, and the current relationship state (familiarity, trust, warmth, boundaries, promises) is a snapshot that keeps its history and evidence.
|
|
69
73
|
- **Images are pointers and captions, not pretend vision.** Attachments are deduplicated by SHA-256, quota-limited and tiered; an image without a description is remembered as "received an image", never as a scene the model did not see.
|
|
@@ -86,16 +90,7 @@ Four real long sessions from this machine were replayed read-only (no new chat)
|
|
|
86
90
|
|
|
87
91
|
Below-threshold turns on the two small sessions can still wake through starvation; on the 2,000+ event sessions they do not. None of the four had new human input after its real cursor, so none would fork again immediately.
|
|
88
92
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
| Consolidations/day | Monthly input | Monthly output |
|
|
92
|
-
|---|---:|---:|
|
|
93
|
-
| 2 | ~5.6M | ~0.11M |
|
|
94
|
-
| 4 | ~11M | ~0.23M |
|
|
95
|
-
| 6 | ~17M | ~0.34M |
|
|
96
|
-
| 6 (worst measured fork each) | ~39M | ~0.7M |
|
|
97
|
-
|
|
98
|
-
For scale, the whole 4-hour session tree measured here consumed 132M input and 1.28M output in one day, so active-memory forks are about **0.2%–1%** of the total. These are token counts, not money; cache reads are usually billed at a lower rate. The exact figure depends on turn count, memory-tool steps and how often the session actually goes idle.
|
|
93
|
+
End-to-end accuracy and the measured cost of the 714-question run are in [Benchmark](#benchmark).
|
|
99
94
|
|
|
100
95
|
## One WebUI
|
|
101
96
|
|
package/README.zh.md
CHANGED
|
@@ -23,14 +23,18 @@
|
|
|
23
23
|
|
|
24
24
|
---
|
|
25
25
|
|
|
26
|
-
`dsh-memu-memory` 面向长篇 RP 与陪伴对话,给 DSH
|
|
26
|
+
`dsh-memu-memory` 面向长篇 RP 与陪伴对话,给 DSH 一份「像记忆」的记忆,而不是一本日志:三种留存层会淡;首轮有锚点,之后每个用户回合最多召回一次;来源不能被悄悄从「我推断」升级成「对方说过」;互相矛盾的记忆会挂起等待裁决,明确标成同一事实的两个版本则并排保留并给出冲突卡,而不是被悄悄合并;几乎相同的事实只入一条、召回时同簇只占一席;关系可以是一条带证据的边。说话人、角色、世界线与剧情分支构成硬边界,角色「知道什么」与实际发生过什么分开保存。
|
|
27
27
|
|
|
28
28
|
默认**本地优先**。`agent` 后端把完整正文放在 JSON 索引里、用词法检索——不需要 Python、embedding 服务或 API key。`api` 后端才把检索交给可选的、锁定版本的 MemU 引擎(向量)。MemU 是「想要就用」的后端,不是插件能否启动的前提。
|
|
29
29
|
|
|
30
30
|
> [!WARNING]
|
|
31
31
|
> **早期版本提示。** 本插件仍处于早期阶段,可能存在无法预见的错误、bug 或不兼容变更。请先备份数据;欢迎[提交 Issue](https://github.com/Tkingxiao/dsh-memu-memory/issues) 或 PR 帮助改进。
|
|
32
32
|
|
|
33
|
-
> **状态:** 1.2.
|
|
33
|
+
> **状态:** 1.2.8。首个公开发布版本为 1.0.0。细节文档已迁到 [`docs/`](docs/),[`AGENTS.md`](AGENTS.md) 只做索引。升级前请备份 `~/.dsh/dsh-memu-memory`;如果要存无法重建的数据,请先读[兼容性与边界](#兼容性与边界)。
|
|
34
|
+
|
|
35
|
+
## 基准测试
|
|
36
|
+
|
|
37
|
+
公开的 [chat-memory-benchmark](https://github.com/Ornn8/chat-memory-benchmark) 714 题完整卷(2026-11-06,`dys-router / deepseek-v4.1-flash`,high 思考强度)通过 **653 / 714(91.46%)**。同一轮**实测记忆成本为 ¥16.05**;包含非记忆开销的总成本为 **¥24.45**(总 token 75,517,851,谷价),均为端到端实测,不是按单次会话外推。
|
|
34
38
|
|
|
35
39
|
## 界面
|
|
36
40
|
|
|
@@ -58,10 +62,10 @@
|
|
|
58
62
|
|
|
59
63
|
- **三层,一条时间线。** `short_term` 草稿默认 72 小时到期;`long_term` 是记忆主体;`must_remember` 需要理由与来源,按 365 天半衰并带 0.35 强度地板,可以**边缘化**,但不会为腾名额被自动删除。
|
|
60
64
|
- **召回是一个瞬间,不是一次倾倒。** 新会话或压缩后的第一个回合得到锚点块(pin / core / global 分段预算);之后每个用户回合最多一次召回。去重与 token 预算由代码执行,不交给提示词自觉。
|
|
61
|
-
- **日期要么是纪念日,要么是一天。** `MM-DD` 每年复发(生日);`YYYY-MM-DD`
|
|
65
|
+
- **日期要么是纪念日,要么是一天。** `MM-DD` 每年复发(生日);`YYYY-MM-DD` 在前一天和当天各响一次,之后就算用过了。说「今天 / 明天 / 下周X / 月底」的相对日期会按这一轮的场景时间换算成绝对日期再存;说「明天」的记忆存成带年份的日期,不会变成每年都冒出来的周年。
|
|
62
66
|
- **记忆会不均匀地淡。** 新近、访问次数、峰终、首因、习惯化、闪光灯记忆的准确度共同参与强度。情绪用四项构成(joy / anger / sorrow / fear,和为 1)加唤醒度 `arousal`(强度)与掌控感 `dominance` 描述;「嫉妒」这类复合情绪是四项的具名混合比例,不是新维度。情绪只影响召回排序:不进注入文本,也不改记忆正文。门控是三条独立条件的 OR——主导项占比 ≥ 0.35、`|arousal − 0.35| ≥ 0.1`、`|dominance| ≥ 0.25`;三条都不满足时两项乘数恒为 1。旧条目没有 emotion 时继续走原来的 valence 路径,不从旧 valence 反推四轴。一条生动但可能记错的记忆会显示「细节未必准」,而不是假装确定。
|
|
63
|
-
- **来源是事实,不是文风。** 每条记忆带 `source`(`user_said` / `
|
|
64
|
-
-
|
|
67
|
+
- **来源是事实,不是文风。** 每条记忆带 `source` / `source_kind`(`user_said` / `assistant_said` / `told` / `imagined` / `inferred` / `tool`)、`speaker_id`、`confidence`、`accuracy` 与说出口径。模糊的推断不能冒充原话,助手自己的承诺和计划也不能记成用户说的。
|
|
68
|
+
- **矛盾不会被悄悄合并。** 普通矛盾仍进入 `pending_review`:不注入、不召回,只出现在复核队列,等人或整理作业裁决。写入方明确把两种说法标成同一事实的版本(`conflicts_with`)时,两条都保持 active、一起召回并注入一张冲突卡;显式 `supersedes` 才退休旧条,正文不删。
|
|
65
69
|
- **秘密不进自动召回。** `secret`、群聊频道、角色、世界线、剧情分支与 `knownBy` 共同约束读写;`secret` 永远不会被自动注入,但同文件夹里**主动检索仍然读得到**——它挡的是「自己冒出来」,不是保险箱。真正把同一文件夹里的两段对话隔开的是 `context` 作用域(`channelId` / `characterId` / `worldId` / `branchId`);两边都没填就是同一个作用域,这正是「文件夹」的含义。旧的 `visibility: 'session'` 级别已删除:读到就按 `shared` 处理、`context` 原样保留,仍存着该级别的库用 `node scripts/migrate-visibility.mjs` 重写(`--apply` 才写,先备份)。
|
|
66
70
|
- **人与故事是有结构的。** 群聊用稳定的 `speakerId` / `channelId`,不拿显示名当身份;RP 用 `characterId` / `worldId` / `branchId` 隔离知识。关系边有理由和置信度,实体改名不动记忆正文,关系当前状态(熟悉、信任、温度、边界、承诺)是带证据和历史快照。
|
|
67
71
|
- **图片是指针加描述,不是假装能看图。** 附件按 SHA-256 去重、有配额、分三级留存;没有描述时只记「收到一张图片」,绝不编造画面。
|
|
@@ -84,16 +88,7 @@
|
|
|
84
88
|
|
|
85
89
|
两条小会话的未达分数回合仍可能因饥饿唤醒;2000 条事件以上的大会话不会。四个会话在真实游标之后都没有新的真人输入,因此不会立即再 fork。
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
| 每天整理次数 | 每月 input | 每月 output |
|
|
90
|
-
|---|---:|---:|
|
|
91
|
-
| 2 次 | ~5.6M | ~0.11M |
|
|
92
|
-
| 4 次 | ~11M | ~0.23M |
|
|
93
|
-
| 6 次 | ~17M | ~0.34M |
|
|
94
|
-
| 6 次(都按实测最贵的单次) | ~39M | ~0.7M |
|
|
95
|
-
|
|
96
|
-
作为参照,今天这棵 4 小时会话树实测 132M input + 1.28M output/日,主动记忆整理约占 **0.2%~1%**。以上是 token 量,不是金额;缓存读通常按更低单价计费。实际取决于回合数、记忆工具步数和会话真正空闲的次数。
|
|
91
|
+
714 题完整卷的通过率与实测成本见[基准测试](#基准测试)。
|
|
97
92
|
|
|
98
93
|
## 一个 WebUI
|
|
99
94
|
|
package/docs/contributing.md
CHANGED
|
@@ -75,7 +75,7 @@ npm run check # node --check + i18n 键对齐 + package.j
|
|
|
75
75
|
|
|
76
76
|
### 5.3 新增一个 RPC 方法
|
|
77
77
|
|
|
78
|
-
<!-- rpc-method-count:
|
|
78
|
+
<!-- rpc-method-count: 97 -->
|
|
79
79
|
|
|
80
80
|
1. `lib/rpc.js` 的 `switch` 加 case(共 95 个方法,按功能分组,别乱插)。
|
|
81
81
|
2. 返回**形状稳定**:客户端 `call()` 直接解构,列表类给 `{items, total}` 而不是裸数组。
|
package/docs/host-adaptation.md
CHANGED
|
@@ -253,7 +253,7 @@ headless 会禁用 `deepseek-account`;没有配假模型时会以 `MISSING_CRE
|
|
|
253
253
|
### 5.4 没测的
|
|
254
254
|
|
|
255
255
|
- 桌面壳(Windows 标题栏、原生按钮区)——本插件不写 DOM app-region,但仍未在 0.2.2 桌面上跑过。
|
|
256
|
-
-
|
|
256
|
+
- ~~全局整理(`subagents.startActivation`)与历史会话 fork(`agents.create` + `followup`)只核对了类型/源码,没有在 0.2.2 真机上跑完一整次作业。~~ **1.2.7 实证补记**:这条漏测面被内部真机评测击中——rc.1 的种子校验(`assertAssistantSettlementShape`)要求 `assistant/message.data.stream` 是数组,而插件种子清噪曾直接删除该字段,**0.2.2-rc.1 上每个整理 fork 种子必被拒**(1.2.6 已发布版中招)。已修:种子携带**空 stream 数组**(`lib/private.js` compactSeedEvents),并用 `node scripts/check-seed-compat.mjs --session-pkg <宿主 dsh-session 的 lib/index.js>` 固化为**每个新宿主版本适配检查表的必跑项**(PASS 后再跑完整整理作业)。全局整理(startActivation)仍属源码核对面。
|
|
257
257
|
- 日期唤醒的**真实投递**没有等 5 分钟周期;只核对了 `ctx.schedule` 的 rc.1 类型与单测。
|
|
258
258
|
- 从 0.2.1 升级上来的旧库/旧 state.json:未在 0.2.2 上做迁移回归(数据格式未变,但不宣称已测)。
|
|
259
259
|
|
package/docs/memory-semantics.md
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
- 移出永久记忆 = **边缘化**:`marginalized=true`、`strength × 0.2`、召回排序里 `marginalized` 乘以 0.35(`recallPenalty` 字段仅作历史记录,当前不参与排序),**不删除**;条目仍在库里,`marginalReason` 在侧边栏可见(替代人类闸门的**事后**监督)。
|
|
21
21
|
- **unpin 由模型自己判断,侧边栏没有标记按钮、用户不参与。** 三重护栏:① `reason` 必填、第一人称、去空白后 ≥ 20 字符;② 每会话配额 `unpinBudgetPerSession`(默认 2);③ 冷却 `unpinCooldownMinutes`(默认 3)。放行后记 `unpinnedBy: model`、`unpinnedAt`、`originalPinSource`(保留原 pinSource 以便复 pin)。
|
|
22
22
|
- 正当的 unpin 只有两种:想起它本身正在伤人;它已经不再是我的一部分。不正当的:inconvenient、不想面对、用户这轮没提、永久记忆快满了。**这个区别要写进提示词。**
|
|
23
|
-
- 矛盾检测:同库同题改写或说法相反 → 新条挂 `pending_review` + `reviewReason` + `conflictingWith`,**不进注入不进召回**,等 `listReviews` / `resolveReview` 裁决(§3.9
|
|
23
|
+
- 矛盾检测:同库同题改写或说法相反 → 新条挂 `pending_review` + `reviewReason` + `conflictingWith`,**不进注入不进召回**,等 `listReviews` / `resolveReview` 裁决(§3.9)。写入方显式用 `conflicts_with`(或同一显式 `fact_key` 再次写入)声明“同一事实的两个版本”时是例外:两条都保持 active、互指并成对召回,注入为冲突卡(§8.17);明确取代用 `supersedes`。
|
|
24
24
|
|
|
25
25
|
### 8.3 全局记忆
|
|
26
26
|
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
|
|
41
41
|
- 静态 guide 与动态记忆都走 plugin 消息;当前版本不再注册本插件的 system prompt 段。所有会话(含 `persona` `complete: true`)统一由 `lib/inject.js` 的 `ensureUnifiedGuide` 在**回合首步**投放一条 `<memory-guide rules="…">` 插件消息;`rulesKey` 由协议版本、domain 和实际渲染正文计算,domain/覆盖/默认稿变化或压缩丢失(`guideLost`)时在下一个合法首步替换,同一规则不逐回合重复。旧 binding 只有 `guideMessageAt`、没有 `guideRulesKey` 时视为旧版,补投一次;失败 fail-open,不写新版本。
|
|
42
42
|
- 首轮锚点 + 每用户回合最多一次;长工具回合仅有新的真实人类消息批次时追加一次,普通工具步骤不触发。私有优先、全局补充;冲突时私有胜。
|
|
43
|
-
- **锚点和本回合召回只放标题卡**(1.2.2):`formatPrivateTitle` / `formatGlobalTitle` 输出 `[id]`、标题、`source`、owner、layer、日期/年龄、marginalized/open_loop、accuracy/uncertainty/disclosure 与附件计数,**不输出正文与附件 caption**。工具返回、记忆抽屉与浏览器仍是全文;要正文就按标题关键词或方括号里的 id 调 `memu_private_recall` / `memu_global_recall`。标题为空时回退正文前 40 字;`imagined
|
|
43
|
+
- **锚点和本回合召回只放标题卡**(1.2.2):`formatPrivateTitle` / `formatGlobalTitle` 输出 `[id]`、标题、`source`、owner、layer、日期/年龄、marginalized/open_loop、accuracy/uncertainty/disclosure 与附件计数,**不输出正文与附件 caption**。工具返回、记忆抽屉与浏览器仍是全文;要正文就按标题关键词或方括号里的 id 调 `memu_private_recall` / `memu_global_recall`。标题为空时回退正文前 40 字;`imagined` 等语义标签不能因为标题化而丢失。`never_say` 不进入自动注入面,`only_if_asked` 只在 boundary 查询里自动放行(§8.17);显式召回仍可读两者。跨库召回开启时(§8.15),private 标题卡可能来自其它同领域库;id 仍全局唯一,按 id 取正文仍走 `memu_private_recall`,写入仍只落在当前库。
|
|
44
44
|
- **条件式时效提示(工单 D)**:本回合召回块已经生成后,若其中至少一条真正进入文本的条目带时间敏感信号——`salientDate` 是已过去的 `YYYY-MM-DD`(年度 `MM-DD` 不算)、标题/正文命中固定词表 `最新|最近|现在|目前|今年|版本|价格|天气|新闻|比分|汇率`、或 `updatedAt||createdAt` 距现在 ≥ `freshnessDays`(`owner=about_project` 的工程事实不算年龄)——且 `freshnessHint !== false`、用户文本长度 ≥ `minUserChars`,就在最后一个 `</memory-context>` 之后追加**一个** `<memory-freshness>` 块,N 为去重后的 stale 条数。提示与召回共用 `turnTokens` 预算:放不下就丢弃提示,召回本身仍成功(fail-open,计算异常只 `warn`)。它只说「若你的会话里有可用的搜索工具就先核实」,**不声称** `web_search` 一定存在(工具面不确定性见 `docs/host-api.md` §6.8),也不改 `<memory-guide>`/`rulesKey`。`freshnessDays` 默认 30,范围 `[1,3650]`;`freshnessHint` 默认开。
|
|
45
45
|
- **rule 是前言,不是页脚**:`buildAnchor` 先输出锚点头与 `[rule]`,再输出 private/global/short_term 各段;inbound 路径的锚点之后直接衔接 `<memory-context>`,中间不再隔一条规则。
|
|
46
46
|
- **`injectedIds` 只能记真正进入文本的条目**,否则从未展示的记忆被白白压制 8 轮。
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
- **只有三个 key 分域**:`system-guide`、`private-policy`、`private-consolidation`;`global-curator` 不分域。
|
|
62
62
|
- **远程与本地共用一份 `private-consolidation`**:正文讲「记什么、字段怎么填」,差异只有输出协议(`CONSOLIDATION_CONTRACTS.local` 调工具 / `.remote` 返回 JSON,代码追加)。不要拆第二份。
|
|
63
63
|
- **1.2.2 起整理稿负责标题质量**:title 按「只看标题就知道具体事实」写(8–40 字、具体关键词、集合稿覆盖全部来源),`global-curator` 同一口径。词典/关联的工具调用属于**本地工作流**:领域整理稿与远程 JSON 路径共用,因此不写 `memu_*` 工具名;领域稿只保留「可抽什么词」的差异,稳定复用的黑话/梗/术语先 `memu_lexicon_search` 再 `memu_lexicon_propose`、写完用 `memu_private_link_suggest` 裁决候选的工具流程只出现在 local worker brief。远程契约明确「没有工具」,title 长度同样是 8–40 字。
|
|
64
|
-
- RP 与 coding 是**内容**差异:coding 记事实(决定、约束、踩过的坑、工程偏好),召回当「可能过期的事实」,与代码冲突时以代码为准;rp 记经验(具体瞬间、半句原话、身体感觉、没说出口的话),允许模糊记错,不确定就标低 `confidence`。
|
|
64
|
+
- RP 与 coding 是**内容**差异:coding 记事实(决定、约束、踩过的坑、工程偏好),召回当「可能过期的事实」,与代码冲突时以代码为准;rp 记经验(具体瞬间、半句原话、身体感觉、没说出口的话),允许模糊记错,不确定就标低 `confidence`。rp/mixed 同时收对方主动给出的**现实生活事实**(作息、行程、口味、健康、家人朋友、在忙的事):`about_user` 平实短条(30–80 字),不需要「瞬间+影响」模板,剧情与现实条分开写、不互相合并;单次提及低 confidence 或 `short_term`,重复出现才升 `long_term`(`寒暄不留`的口径只拦寒暄本身,不拦寒暄里夹带的事实)。
|
|
65
65
|
- **KV cache**:section 文本随 domain 变,但同一会话内恒定,缓存不受影响;中途改 domain 会让该会话失效一次缓存。别在文档里写「文本恒定」。
|
|
66
66
|
|
|
67
67
|
### 8.6 可见范围只剩两档,它决定「自动浮现」而不是「谁能读」
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
| 附件像素 | ✅ | ❌(`hidden: true`;`never_say` 的 caption 也不回显) |
|
|
80
80
|
|
|
81
81
|
- 所以 `secret` 的实际边界是「**不被自动注入、不当回响源、附件不出像素**」;同一文件夹里另一个会话**主动检索时照样能拿到**。它挡的是「自己冒出来」,不是「别人查到」。要「跨会话绝不外泄」,靠 §8.7 的上下文边界,不是 `secret`。
|
|
82
|
-
- 「只有我知道」= `disclosure: never_say
|
|
82
|
+
- 「只有我知道」= `disclosure: never_say`(不进入任何自动注入面,显式召回仍可读)+ `secret`(不自动浮现、附件不出像素)两个字段的组合,不是加密。侧边栏和记忆墙始终能看到正文——这是**事后监督**的设计,不是疏漏。
|
|
83
83
|
- 全局 curator 读的是会话日志与全局库,不读私有库条目(`compactGlobalIndex`),所以 `secret` 不会被复制进「每会话都注入」的全局记忆;跨文件夹(不同库)之间的私有召回**默认隔离**,只有显式打开 `crossLibraryRecall` 才会合并同领域库,且只读——见 §8.15。
|
|
84
84
|
|
|
85
85
|
### 8.7 上下文作用域:`channelId / characterId / worldId / branchId` + `knownBy`
|
|
@@ -146,6 +146,8 @@
|
|
|
146
146
|
|
|
147
147
|
服务不可用时仅回退词法并保留可见错误信号;不暗切远端、不调用 LLM。真实 embedding 质量、延迟和跨模型收益仍需单独评测;W8(助手重复提示)已决定不做,结论与理由见 `AGENTS.md`。
|
|
148
148
|
|
|
149
|
+
**语义召回缓存(1.2.7)**:`managedRecall` 的成功语义召回段被 `lib/recall-cache.js` 的进程内 LRU 缓存(max=256、TTL 120s)包住,命中直接复用融合结果,词面 localRecall 仍每轮计算。只缓存成功路径:`byId` 直达、local-fallback、带 `errors` 的降级结果一律不缓存(fail-open 信号不能被缓存吞掉)。缓存键含 `memoryRevision()`(state.js 的每次索引/状态落盘自增,自动覆盖 remember/update/整理提交/graph/迁移全部写路径)+ 向量代数 token + query/topK/libraryId/domain/sessionId/context/automatic,写记忆后下一轮键即变化、无 stale;跨进程写入靠 TTL 兜底(revision 是进程内的)。缓存自身故障按未命中处理并 `warn` 留痕(`stats()` 暴露 hits/misses/errors)。显式召回(`memu_private_recall`)命中率为 ~0 是正确行为:其 `touchAccess` 写会推进 revision 使键失效,accessCount 参与 decay 加成不能被缓存短路。
|
|
150
|
+
|
|
149
151
|
模型下载、进度与 profile 切换/迁移已有实现,但真实模型/runtime 下载、原生推理及切换全链路在本轮仍未验证。candidate / `pending` artifact 不是可用制品,必须通过制品、校验与迁移门槛后才可进入可用/激活状态。
|
|
150
152
|
|
|
151
153
|
回归与管线测试:`tests/hybrid-recall.test.mjs` 仅保留 RRF、去重、稳定排序、资格过滤与候选上限等通用融合 helper 覆盖;managed vector 行为由 `tests/managed-memory.test.mjs` 覆盖。
|
|
@@ -199,3 +201,23 @@
|
|
|
199
201
|
|
|
200
202
|
---
|
|
201
203
|
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
### 8.17 1.2.8:时间、版本、来源、承诺与召回意图
|
|
208
|
+
|
|
209
|
+
这一节只描述新增字段与策略,不改原有三层、可见范围与注入纪律。所有字段对旧数据都是**可选**:缺字段按空处理,不强制迁移,写入时补齐。
|
|
210
|
+
|
|
211
|
+
**时间**:写入时按这一轮的逻辑时间解析相对日期,落在 `event_time` / `observed_at`(ISO)、`absolute_date`(YYYY-MM-DD)、`date_precision`(`day|month|year|unknown`)、`date_source`(`explicit|relative`)。逻辑时间优先 `context.occurredAt`,其次会话 `sceneTime`,最后才是墙上时钟;解析失败不猜,只有确实出现相对时间词时才标 `date_precision=unknown`。原文保留在 `content`,不改写用户原话。`valid_from` / `valid_to` 是可选的有效窗口(`valid_from <= 今天 <= valid_to`),缺字段的旧条目照常召回;旧复核路径写的 `validFrom/validTo` 也会被识别。召回查询里的“明天/下周三/月底”同样先解析成绝对日期再检索,时间题注入按 `absolute_date` 最近优先排序。
|
|
212
|
+
|
|
213
|
+
**版本与冲突**:每条新记忆都有 `fact_key`(显式传入或由 `owner + 标题` 归一化)与 `version`。显式 `conflicts_with` 或“同一显式 fact_key 的再次写入”会让新旧两条都保持 `active`、互指 `conflicts_with`,召回命中一侧时另一侧成对带回,注入成一张 200 字内的冲突卡(“未确认哪版为准”)。显式 `supersedes` 才是取代:旧条 `status=superseded`、`valid_to` 落日期、正文与标题不删不改。兼容补充仍走 `memu_private_update`,保留原 id,不增加版本。旧的无关系字段的冲突仍按原路径进入 `pending_review`,行为不变。
|
|
214
|
+
|
|
215
|
+
**来源**:新增 `speaker_id`、`source_kind`(`user_said|assistant_said|told|imagined|inferred|tool`)、`quote_span`(`{seq, turn, textHash}`)、`storyline_id`、`branch_id`、`known_by`。`speaker_id` 显式 > `context.speakerId` > 按 `source_kind` 的 `user/assistant/tool/unknown`;不猜。助手自己的承诺、计划、事实用 `assistant_said`,不能记成用户说的。查询“我说过/你说过/他说的”时按说话人过滤:只排除明确属于别人的条目,缺 speaker 的旧条目保留。注入标题卡会显示非默认的 `speaker=`。
|
|
216
|
+
|
|
217
|
+
**承诺**:`commitment = {counterparty, action, due_at, status, closed_by, evidence_seq}`,`status` 是 `open|done|cancelled|expired`,也是权威;`open_loop` 只做兼容并随 `status` 同步。`open_loop=true` 的旧写法会派生一条 `open` 承诺,`due_at` 取本轮已解析日期。到期/临期(逾期、今天、明天)的未完成承诺最多 3 条、按 `due_at` 升序进一张 `[commitment]` 小卡;远期承诺不占每回合预算。`dueOpenLoops` 也优先看 `commitment.status` 与 `due_at`。
|
|
218
|
+
|
|
219
|
+
**召回意图**:`lib/text-retrieval.js` 的 `detectQueryIntent` / `decomposeQuery` 把查询分成 `date|entity|conflict|commitment|boundary|general`;日期与引号/`@`/已知实体名会被拆成可检索词。各意图的候选上限见 `lib/budget.js` 的 `RECALL_INTENT_TOPK`(general 5、date/entity 8、conflict 6、commitment/boundary 5),调用方显式给的更大 topK 不被压低,封顶 20。命中条目沿 `links` 扩展一跳(最多 2 条,实体题 3 条),只沿显式关系走。`disclosure` 现在是“何时能自动出现”的门:`never_say` 不进任何自动注入面(锚点、自动召回、提醒),`only_if_asked` 只在 `boundary` 意图的查询里自动放行;显式 `memu_private_recall` 仍可读两者。
|
|
220
|
+
|
|
221
|
+
**可观测性**:`getState` 增加 `recallCache` 段(`hits/misses/evictions/errors/staleSkipped/generations/...`);`staleSkipped` 统计 TTL 过期、代数清理与按 query 失效时被丢弃的缓存条目。
|
|
222
|
+
|
|
223
|
+
守卫:`tests/temporal.test.mjs`、`tests/memory-fields.test.mjs`、`tests/fact-version.test.mjs`、`tests/inject-conflict.test.mjs`、`tests/speaker-provenance.test.mjs`、`tests/commitment.test.mjs`、`tests/query-decompose.test.mjs`、`tests/recall-intent.test.mjs`、`tests/injection-intent-budget.test.mjs`、`tests/memory-chain.test.mjs`。
|
package/docs/troubleshooting.md
CHANGED
|
@@ -91,6 +91,8 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
|
|
|
91
91
|
|
|
92
92
|
**守卫**:同库连续两次写后条目数对不上即可确认;并发用例见 `tests/storage.test.mjs`。
|
|
93
93
|
|
|
94
|
+
**召回缓存(1.2.7)不是本症状的成因**:写路径(remember/update/整理提交)都会推进 `memoryRevision()`,缓存键随之变化,同进程写后立即召回不会命中旧键。唯一残留窗口是**跨进程写**(第二窗口/独立进程改库):revision 是进程内的,另一进程最多多看 120s(TTL)旧召回,之后自动刷新;`bumpGeneration()` 可手动清。
|
|
95
|
+
|
|
94
96
|
### 3.5 面板不自动刷新(S8 心跳)
|
|
95
97
|
|
|
96
98
|
**症状**:侧边栏 / 设置页要手点刷新才更新,心跳却一直在跑。
|
|
@@ -360,7 +362,7 @@ S8 展示回写 client.js 面板 + useMemoryBeat 心跳 + rpc.js allowed + tool
|
|
|
360
362
|
|
|
361
363
|
### 2.1 模块地图
|
|
362
364
|
|
|
363
|
-
<!-- rpc-method-count:
|
|
365
|
+
<!-- rpc-method-count: 97 -->
|
|
364
366
|
|
|
365
367
|
| 文件 | 职责 / 什么时候碰它 |
|
|
366
368
|
|---|---|
|
package/lib/backup.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from './paths.js'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Local-vector backup policy - safe latest-three backup retention.
|
|
12
12
|
*
|
|
13
13
|
* One rule, one place. Every managed backup of the current data root is created
|
|
14
14
|
* by createBackup(), published atomically, and only then may the oldest
|
|
@@ -54,9 +54,9 @@ 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:535', name: 'inFlight', keyedBy: 'sessionId', clearedBy: 'consolidation settle' },
|
|
58
58
|
{ layer: 'temporary-map', file: 'lib/curator.js:50', name: 'jobs', keyedBy: 'job id', clearedBy: 'curation settle' },
|
|
59
|
-
{ layer: 'cache', file: 'lib/state.js:
|
|
59
|
+
{ layer: 'cache', file: 'lib/state.js:1186', 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/budget.js
CHANGED
|
@@ -94,3 +94,34 @@ export function packToBudget(items, maxTokens, render) {
|
|
|
94
94
|
}
|
|
95
95
|
return { lines, ids, used, omitted: Math.max(0, items.length - ids.length) }
|
|
96
96
|
}
|
|
97
|
+
|
|
98
|
+
// S6 意图预算:不同问题需要的候选数不同。时间/实体题需要更大的时间线或实体卡
|
|
99
|
+
// 面(8),冲突题 6 条成对,承诺/边界 5 条。用户显式设置的更大值不会被压低,
|
|
100
|
+
// 但也不会超过 20 条。
|
|
101
|
+
export const RECALL_INTENT_TOPK = Object.freeze({
|
|
102
|
+
general: 5,
|
|
103
|
+
date: 8,
|
|
104
|
+
entity: 8,
|
|
105
|
+
conflict: 6,
|
|
106
|
+
commitment: 5,
|
|
107
|
+
boundary: 5,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
export function intentTopK(intent, requested) {
|
|
111
|
+
const preset = RECALL_INTENT_TOPK[intent] ?? RECALL_INTENT_TOPK.general
|
|
112
|
+
const asked = Number(requested)
|
|
113
|
+
const hasAsked = Number.isFinite(asked) && asked > 0
|
|
114
|
+
// general 尊重调用方显式设置的更小值;专项意图(时间/实体/冲突…)需要更多证据,
|
|
115
|
+
// 只升不降,但同样封顶 20。
|
|
116
|
+
const wanted = !RECALL_INTENT_TOPK[intent] || intent === 'general'
|
|
117
|
+
? (hasAsked ? asked : preset)
|
|
118
|
+
: Math.max(hasAsked ? asked : 0, preset)
|
|
119
|
+
return Math.max(1, Math.min(20, wanted))
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function recallIntentBudget(intent, settings = {}) {
|
|
123
|
+
return {
|
|
124
|
+
intent: RECALL_INTENT_TOPK[intent] ? intent : 'general',
|
|
125
|
+
topK: intentTopK(intent, settings.privateTopK),
|
|
126
|
+
}
|
|
127
|
+
}
|