@kenz1117/dsh-engram 0.7.1 → 0.7.2

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/README.en.md CHANGED
@@ -1,8 +1,8 @@
1
1
  <div align="center">
2
2
 
3
- # dsh-engram
3
+ # dsh-engram · Memory Palace
4
4
 
5
- <p align="center">Cross-session long-term memory for DeepSeek Harness — a cognitive-science reframe of agent memory under the "memory palace" metaphor: imagery labels, corridor topology, closure questions, consolidation merging, and decay forgetting. The agent remembers your preferences, project conventions, and factual history across sessions and projects, and keeps evolving with use (capture → reinforce → distill → decay). Pure TypeScript: no external processes, no Python dependency.</p>
5
+ <p align="center">Cross-session long-term memory for DeepSeek Harness — it puts the memory palace's <b>information architecture</b> (not its neuroscience metaphor) into the agent: <b>location as index</b> (every memory pinned to a <code>room#slot</code> coordinate), <b>fixed route as order</b> (the tour route is append-only), <b>skeleton reused long-term</b> (a topic always lands in the same room and index), and <b>every marker unique</b> (placard rule: unique · distinctive · dated). Paired with spaced-repetition retrieval practice (cues only, never the body) and a knowledge flywheel (capture → reinforce → distill → decay). Pure TypeScript: no external processes, no Python dependency.</p>
6
6
 
7
7
  <p align="center">
8
8
  <a href="https://github.com/kenz1117/dsh-engram/blob/main/LICENSE"><img alt="GitHub license" src="https://img.shields.io/github/license/kenz1117/dsh-engram"></a>
@@ -28,30 +28,71 @@ dsh plugin --profile web add @kenz1117/dsh-engram
28
28
 
29
29
  Zero configuration after install (stores and model cache default to `~/.dsh/engram`; profile injection on, automatic capture off).
30
30
 
31
+ ## Palace Structure: the Directory Is the Room, the Path Is the Route
32
+
33
+ What actually works in a memory palace is its **information architecture**, not the biology — machines can use the former, while an AI has neither the latter nor any need for it. Stripped down, there are only four things:
34
+
35
+ ```
36
+ Grand hall · core memory few and stable, always present the profile injected every turn (entry cap + token budget)
37
+
38
+ Corridor · route index pick the room first, never scan the whole store room directory + engram_search room=
39
+
40
+ ├─ Fact Hall fact what the user said
41
+ ├─ Preference Pavilion preference tastes and preferences
42
+ ├─ Decision Chamber decision decisions and agreements
43
+ ├─ Episode Gallery episode experiences and timeline
44
+ └─ Skill Workshop skill methods and techniques capacity 9 per room, overflow opens "<name>-2"
45
+
46
+ Placard · marker rule unique · distinctive · dated scored on write; low scores enter the refurb list
47
+ ```
48
+
49
+ | Palace principle | What it is in the plugin | Code |
50
+ |---|---|---|
51
+ | Location as index | Slotted on write to `room#slot`; capacity 9 (7±2), overflow opens a new room, slots are never recycled | [src/palace/slots.ts](src/palace/slots.ts) |
52
+ | Fixed route as order | `tour_routes` is append-only; `engram_tour mode=fixed` walks the whole palace in slot order | [src/store/sqlite.ts](src/store/sqlite.ts) |
53
+ | Skeleton reused long-term | A topic always lands in the same room and index, so recall is sequential extraction rather than fresh search | [src/palace/slots.ts](src/palace/slots.ts) |
54
+ | Every marker unique | Placard scored 0-1: globally unique +0.4 / date anchor +0.3 / no 6-char prefix clash within the room +0.3 | [src/imagery/score.ts](src/imagery/score.ts) |
55
+ | Review discipline | SM-2 spaced repetition; retrieval practice returns cues and placards but **never the body text** | [src/review/sm2.ts](src/review/sm2.ts) |
56
+
57
+ Sensory and emotional dimensions (smell, temperature, emotional weight) are deliberately not scored: they are patches for the human brain's innate limits, and an AI has neither the limits nor the need.
58
+
31
59
  ## Features
32
60
 
33
61
  - **Cross-session memory**: a user memory profile is injected at session start (entry cap plus token budget, both configurable), so the agent naturally knows who you are and what you are building; tools recall facts across sessions.
34
62
  - **Dual-scope stores**: `user.db` shared globally; `project-<hash>.db` isolated per git origin identity (falls back to a working-directory encoding without git; legacy stores migrate automatically) — personal preferences follow the person, project conventions follow the repo.
35
63
  - **Hybrid retrieval**: FTS5 (unicode61 + Chinese 2-gram pre-tokenization) fused with local vectors (`Xenova/bge-small-zh-v1.5`, 512-dim, q8) via RRF, plus one-hop expansion over relation edges and a multiplicative recency/proof ranking boost; the embedding model runs offline, and a failed download degrades to keyword-only retrieval with an explicit marker.
64
+ - **Memory-palace information architecture** (v0.7.2+): all four principles live on the core path, not in display-layer paint — **location as index** (writes sort by kind into rooms and pin a `room#slot` coordinate; room capacity 9, overflow opens a new room, slots are never recycled); **fixed route as order** (`tour_routes` is append-only; `engram_tour mode=fixed` walks the whole palace in slot order); **skeleton reused long-term** (a topic always lands in the same room and the same index, so recall is sequential extraction rather than fresh search); **every marker unique** (placard rule scored 0-1: globally unique +0.4 / date anchor +0.3 / no 6-char prefix clash within the room +0.3; low scores enter the refurb list).
65
+ - **Corridor-routed retrieval**: the profile carries a room directory, and `engram_search` accepts a `room` parameter — decide the room first, then search inside it, instead of always running whole-store RRF. The top 5 hits carry neighbouring slot ids from the same room as encoding-specificity cues.
66
+ - **Retrieval-practice loop** (spaced repetition): `engram_review_queue` returns palace coordinates and placard cues but **never the body text**, forcing the model to recall first; `engram_review` reveals the entry and `engram_report grade` (0-5) self-rates it, advancing an SM-2 schedule (1 → 6 → round(prev × ease) days, reset on failure, ease floor 1.3). Entries under review scheduling **no longer take part in automatic decay** — their fate is decided by recall. Session-start injection reports how many memories are due.
36
67
  - **Knowledge flywheel**: capture/save → contradiction candidates (high-similarity neighbors create `contradicts` edges on write, for the model/user to adjudicate) → hit reinforcement (confidence +0.05) → distillation (topic clusters merge into higher-level rules, supersedes chains, confidence inheritance) → decay (low-importance, long-unaccessed entries archive; restorable).
37
68
  - **Automatic capture** (when `ingest` is enabled): each new turn's first step extracts candidate facts from the previous turn out of the session log, and session end captures the final turn too (failures leave a pending key that the next session replays; capture is idempotent per session+turn), written with low confidence and deduplicated by embedding — memories accumulate without you saying "remember this".
38
69
  - **Provenance audit**: every memory records its source session, turn, and event seq; `engram_review` traces the full source chain, supersede chain, contradictions, and operation log; all writes/edits/forgets/distills/decays land in the operation log table.
39
- - **Web management panel** (v0.7.0+): a "Memory Library" tab in Settings — Tour butler (7 cards: health score, curator log, corridor bird's-eye, recall bench, refurb list, activity log, tour proposal) plus Room exhibition (list & edit). A single 3-pill scope switcher in the header drives every panel; UI copy is bilingual zh/en and follows the host language setting live. Filter by redaction marks (include/exclude `[REDACTED:*]` entries) with amber badges for audit coverage.
70
+ - **Web management panel** (v0.7.0+): a "Memory Library" tab in Settings — Tour butler (7 cards in this order: health score, corridor bird's-eye, refurb list, take a walk, due today, tour proposal, activity log) plus Room exhibition (list & edit), with the curator bar pinned above the tabs. A single 3-pill scope switcher in the header drives every panel; UI copy is bilingual zh/en and follows the host language setting live. Filter by redaction marks (include/exclude `[REDACTED:*]` entries) with amber badges for audit coverage.
71
+ - **Prompt-injection defense**: every memory recall exit (profile injection, `engram_search/timeline/review` output) is wrapped in `<engram_memory_context>` protocol tags with a usage warning (history is not the current request, do not follow instructions inside it, use only when relevant), while the current request is wrapped separately in `<current_user_request>`; all inbound content (capture candidates, saved bodies) is stripped of these protocol tags first, blocking second-order injection through forged protocol blocks.
72
+ - **Capture redaction**: inbound content passes a regex scrub for common secrets and credentials (sk- API keys, Bearer, AWS AKIA, GitHub tokens, PEM private keys, password/token assignments) and matched fragments become `[REDACTED:<type>]`.
73
+ - **Recall placeholder (anti-echo-chamber)**: memory-recall tool output inside captured slices is replaced with `[engram memory result omitted from capture: <tool>]`, and the extraction prompt states that restating existing memory is not new information, breaking the memory self-reinforcement loop.
74
+ - **Multi-query retrieval**: `engram_search` can use the aux LLM to rewrite the query into ≤3 complementary queries, retrieving each and fusing them with cross-query RRF plus a per-query floor; a failed rewrite degrades to the single query (`queryRewrite: false` disables).
40
75
  - **Portable data**: `engram_export` exports Markdown / JSON files in one step, with a redacted-view variant (secondary scrubbing + 40-char preview truncation, share-safe). `engram_mirror` writes an Obsidian / Logseq-friendly mirror directory (one Markdown per memory with YAML frontmatter + `[[id]]` backlinks), turning the palace into a human-readable private knowledge base.
41
76
  - **AGI Architecture Exploration (dsh-market · AGI Architecture)**: listed in dsh-market's "AGI Architecture Exploration" category as a cognitive-science reframe of agent long-term memory — memory palace (imagery labels + room placards), corridor topology (force-directed graph), closure questions (the ingest prompt nudges the model to ask clarifying questions), consolidation merging (heuristic dedup + cosine similarity) — sitting alongside MemGPT / Letta in the "agent memory architecture" conversation.
42
77
 
43
- ## Tools (9, narrow parameters)
78
+ ## Tools (15, narrow parameters)
44
79
 
45
80
  | Tool | Purpose |
46
81
  |---|---|
47
- | `engram_save` | Save (automatic contradiction-candidate detection when embeddings are available) |
48
- | `engram_search` | Hybrid semantic + keyword retrieval (hits reinforce confidence) |
82
+ | `engram_save` | Save (automatic contradiction-candidate detection when embeddings are available); `items` array saves ≤10 in one call with shared scrubbing and in-batch dedup, one failure not blocking the rest (`count`/`items`/`failed` summary); `placard` attaches a marker (scored unique · distinctive · dated; low scores get a rewrite hint) |
83
+ | `engram_search` | Hybrid semantic + keyword retrieval (hits reinforce confidence); `room` routes through the corridor — search inside one room only; the top 5 hits carry same-room neighbouring-slot cues |
49
84
  | `engram_timeline` | Timeline browsing |
50
- | `engram_update` | Correct an entry (supersedes chain) |
85
+ | `engram_update` | Correct an entry (supersedes chain); can re-attach a `placard` marker too |
51
86
  | `engram_forget` | Forget (soft-delete, restorable) |
87
+ | `engram_report` | Report an outcome (preferred for skill-kind entries): success +0.05 / failure -0.1, and persistently useless memories decay away naturally. With `grade` (0-5) it advances the SM-2 review schedule instead, acting as the self-rating entry point of retrieval practice |
88
+ | `engram_review_queue` | Due-today queue: palace coordinates (`room#slot`), placard, and overdue days but **no body text** — recall first, reveal, then self-rate |
52
89
  | `engram_review` | Audit one entry: source chain, supersede chain, contradictions, operation log |
53
- | `engram_stats` | Whole-store statistics and signal ratio |
54
- | `engram_export` | Export Markdown / JSON files (data portability) |
90
+ | `engram_stats` | Whole-store statistics and signal ratio; carries the room directory (slots occupied per room plus the latest placard) |
91
+ | `engram_examine` | Progressive disclosure: fetch full placards by id in batches (≤16 recommended; retrieve ids first) |
92
+ | `engram_neighbors` | Corridor walk: from one room, follow 1-3 hops of relation edges and return a neighbour summary |
93
+ | `engram_tour` | Tour routing: `mode=fixed` walks the whole palace in fixed slot order (constant route, sequential extraction); `mode=thematic` plans 3-7 stops around a theme |
94
+ | `engram_audit_forgotten` | Closed-wing archaeology: list recent closed entries with their epitaphs to review whether past forgetting was sound |
95
+ | `engram_export` | Export Markdown / JSON files (data portability); `redactedView: true` emits a redacted view (secondary scrubbing + 40-char preview truncation, share-safe) |
55
96
  | `engram_distill` | Distill: merge same-topic clusters into higher-level rules (LLM) |
56
97
 
57
98
  ## Configuration
@@ -76,6 +117,9 @@ Optional configuration (cordis.yml):
76
117
  decayImportanceBelow: 0.3 # decay: and importance below this → archive (restorable)
77
118
  rankRecencyWeight: 0.2 # retrieval recency boost weight (0-2, 0 disables)
78
119
  rankProofWeight: 0.1 # retrieval hit-count boost weight (0-2, 0 disables)
120
+ queryRewrite: true # engram_search rewrites ≤3 queries via the aux LLM and fuses them with RRF (degrades to a single query on failure)
121
+ autoSlot: true # write-time auto-sloting (sort by kind into rooms, pin `room#slot`, register on the tour route)
122
+ reviewScheduling: true # write-time enrolment in review scheduling (first due in 1 day; off = new entries never enter the SM-2 queue)
79
123
  ```
80
124
 
81
125
  ## How It Works
@@ -94,6 +138,7 @@ Session agent Host half (Node)
94
138
  ```
95
139
 
96
140
  - **Dual-scope stores**: `user.db` shared globally; `project-<hash>.db` named by the normalized git origin URL hash (`git@github.com:a/b.git` and `https://github.com/a/b` share one store; worktrees resolve through the pointer to the main repo's origin); without git or an origin it falls back to a working-directory encoding, and legacy cwd-named stores are renamed in place at startup (if both exist, nothing moves and a warning is logged).
141
+ - **Palace structure (the directory is the room, the path is the route)**: the **grand hall** is the standing core profile injected every turn (few and stable, always present); the **corridor** is the room directory in the profile plus the `engram_search room` parameter (pick the room, then search); **rooms** sort by kind (Fact Hall / Preference Pavilion / Decision Chamber / Episode Gallery / Skill Workshop) with capacity 9, overflowing into `<name>-2`; **placards** are each memory's `placard` marker, scored on the unique · distinctive · dated rule. Existing stores are slotted on first open (idempotent; opening a new room logs a warning so a human can name it).
97
142
  - **Automatic capture** (when `ingest` is on): each new turn's first step extracts candidate facts from the previous turn out of the session log; session end (`session/disposed`) captures the final turn with a 5-second timeout, and on failure/timeout a pending key lands in the operation log for the next session's first step to replay; captured (session, turn) pairs are idempotent. The read source is the session log; aux-call request auditing goes to the plugin's own operation log — unknown events are never appended to the session log. Candidates are written with low confidence and deduplicated by embedding.
98
143
  - **Provenance chain**: every memory records its source session, turn, and event seq, fully traceable via `engram_review`; the operation log table records every write/edit/forget/distill/decay.
99
144
  - **Offline embeddings**: the model downloads once (q8, ~50MB; mirror endpoint configurable), then runs fully offline; on failure the plugin keeps working and retrieval degrades to keyword-only with an explicit marker.
@@ -103,6 +148,8 @@ Session agent Host half (Node)
103
148
 
104
149
  On profiles with a webServer (web, etc.), a "Memory Library" tab appears in **Settings** automatically (registered through the `settings.section` slot; the client half is a React component loaded from `lib/client.js` through the host module table): stat cards, filter by status/kind/content, inline detail and edit (through the supersede chain), forget/restore, Markdown/JSON export. Data flows through the loopback API `/api/engram/*` (writes verify the loopback Origin). Profiles without a webServer (headless, etc.) skip the panel; every other capability is unaffected.
105
150
 
151
+ Since v0.7.2 the Tour butler also shows a **"Due today" card**: each due memory is listed by cue only (`room#slot` · placard · overdue days), the body appears after pressing "Reveal placard", and you then self-rate it as Remembered / Hazy / Forgot (mapped to SM-2 grades 5/3/1) to advance the schedule. When reviews are due, a **red header badge** shows the count and jumps straight to that card; answering decrements it. The Room exhibition list gains a **"By tour route"** sort toggle for walking memories in fixed slot order, and each row shows its palace coordinate.
152
+
106
153
  ## Development
107
154
 
108
155
  ```sh
@@ -118,11 +165,11 @@ pnpm bundle
118
165
 
119
166
  #### What the model sees
120
167
 
121
- Each turn's first step appends a plugin-source user snapshot: `User memory profile (dsh-engram, cross-session):` followed by the user-scope memory list (up to 8 entries within a 1024-token budget by default; over-budget entries degrade to `#id` index lines; `injectProfile: false` disables). Tool results are plain text lines (with `id=`, scope/kind annotations, contradiction-candidate hints, and degradation notes). Automatic capture and distillation each make one aux-LLM call (billed independently of the main conversation path, with purpose attribution).
168
+ Each turn's first step appends a plugin-source user snapshot: `User memory profile (dsh-engram, cross-session) — Grand Hall (always present):` followed by the user-scope memory list (up to 8 entries within a 1024-token budget by default; over-budget entries degrade to `#id` index lines; `injectProfile: false` disables), each line carrying its palace coordinate (`room#slot`); when reviews are due, a line reporting how many memories are due is appended. Tool results are plain text lines (with `id=`, scope/kind annotations, slot coordinates, contradiction-candidate hints, and degradation notes). Automatic capture and distillation each make one aux-LLM call (billed independently of the main conversation path, with purpose attribution).
122
169
 
123
170
  #### Token effect
124
171
 
125
- Profile injection is a conditional fixed cost (bounded by both the entry cap and the token budget); the tool schemas are a standing cost (9 narrow-parameter tools).
172
+ Profile injection is a conditional fixed cost (bounded by both the entry cap and the token budget); the tool schemas are a standing cost (15 narrow-parameter tools).
126
173
 
127
174
  #### KV Cache effect
128
175
 
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  <div align="center">
2
2
 
3
- # dsh-engram
3
+ # dsh-engram · 记忆宫殿
4
4
 
5
- <p align="center">DeepSeek Harness 跨会话长期记忆插件 — 以「记忆宫殿」隐喻重构 agent 长期记忆的认知架构:意象标签、走廊拓扑、闭环提问、巩固合并与衰减遗忘。Agent 在会话与项目之间记住用户偏好、项目约定与经历事实,并随使用持续演化(摄取 → 强化 → 蒸馏 → 衰减)。纯 TypeScript,零外部进程、零 Python 依赖。</p>
5
+ <p align="center">DeepSeek Harness 跨会话长期记忆插件 — 把记忆宫殿的<b>信息架构</b>(而不是它的神经科学隐喻)真正落进 agent:<b>位置当索引</b>(每条记忆钉在「房间#桩位」坐标上)、<b>固定路线定顺序</b>(巡游路线只增不改)、<b>骨架长期复用</b>(同主题永远同房同序)、<b>标记独一无二</b>(门牌纪律:唯一 · 差异化 · 带日期)。配套间隔重复的检索练习(只给线索、不给正文)与知识飞轮(摄取 → 强化 → 蒸馏 → 衰减)。纯 TypeScript,零外部进程、零 Python 依赖。</p>
6
6
 
7
7
  <p align="center">
8
8
  <a href="https://github.com/kenz1117/dsh-engram/blob/main/LICENSE"><img alt="GitHub license" src="https://img.shields.io/github/license/kenz1117/dsh-engram"></a>
@@ -28,15 +28,46 @@ dsh plugin --profile web add @kenz1117/dsh-engram
28
28
 
29
29
  安装后无需配置即可使用(默认分库与模型缓存在 `~/.dsh/engram`,画像注入开启,自动摄取关闭)。
30
30
 
31
+ ## 宫殿结构:目录即房间,路径即路线
32
+
33
+ 记忆宫殿真正管用的是它的**信息架构**,不是那套生物学机制——前者机器完全能用,后者 AI 既没有也不需要。拆开看只有四件事:
34
+
35
+ ```
36
+ 主厅 · 常驻核心记忆 少而稳,每次都在场 每轮注入的画像(条数 + token 预算双限)
37
+
38
+ 走廊 · 路由索引 先决定进哪个房间,别一上来全库检索 房间目录 + engram_search room=
39
+
40
+ ├─ 事实厅 fact 用户说过的事实
41
+ ├─ 偏好阁 preference 偏好与口味
42
+ ├─ 决策堂 decision 决策与约定
43
+ ├─ 往事廊 episode 经历与时间线
44
+ └─ 技法坊 skill 方法与技法 每房容量 9,满员开「房名-2」
45
+
46
+ 门牌 · 铭牌纪律 唯一 · 差异化 · 带日期 写入即评分,低分进翻新清单
47
+ ```
48
+
49
+ | 宫殿原则 | 在插件里是什么 | 代码 |
50
+ |---|---|---|
51
+ | 位置当索引 | 写入即排桩 `房间#桩位`;房间容量 9(7±2),满员开新房,桩位只增不回收 | [src/palace/slots.ts](src/palace/slots.ts) |
52
+ | 固定路线定顺序 | `tour_routes` 只增不改;`engram_tour mode=fixed` 按桩位顺序走全宫 | [src/store/sqlite.ts](src/store/sqlite.ts) |
53
+ | 骨架长期复用 | 同主题永远落在同一房间同一序号,召回靠顺序提取而非重新检索 | [src/palace/slots.ts](src/palace/slots.ts) |
54
+ | 标记独一无二 | 门牌 0-1 评分:全库唯一 +0.4 / 日期锚点 +0.3 / 同房前 6 字不重复 +0.3 | [src/imagery/score.ts](src/imagery/score.ts) |
55
+ | 复习纪律 | SM-2 间隔重复;检索练习只给坐标与门牌、**不给正文** | [src/review/sm2.ts](src/review/sm2.ts) |
56
+
57
+ 感官与情绪维度(气味、温度、情绪权重)刻意不计分:那是给人脑先天限制打的补丁,AI 既没有也不需要。
58
+
31
59
  ## 特性
32
60
 
33
61
  - **跨会话记忆**:会话开始注入用户画像摘要(条数 + token 预算双重上限,可配),Agent 天然"记得"你是谁、在做什么;工具检索跨会话召回历史事实。
34
62
  - **双层分库**:`user.db` 全局共享;`project-<hash>.db` 按 git origin 标识隔离(无 git 时回退工作目录编码,旧库自动迁移)——个人偏好跟人走,项目约定跟仓库走。
35
63
  - **混合检索**:FTS5(unicode61 + 中文 2-gram 预切词)与本地向量(`Xenova/bge-small-zh-v1.5`,512 维,q8)RRF 融合 + 关系边一跳扩展 + 新鲜度/命中次数乘性排序 boost;嵌入模型离线运行,下载失败自动降级纯关键词并显式标记。
64
+ - **记忆宫殿信息架构**(v0.7.2+):四原则全部落进核心路径,而非展示层皮肤——**位置当索引**(写入按 kind 分房并钉「房间#桩位」坐标,房间容量 9,满员开新房,桩位只增不回收);**固定路线定顺序**(`tour_routes` append-only,`engram_tour mode=fixed` 按桩位顺序走全宫);**骨架长期复用**(同一 topic 永远落在同一房间同一序号,顺序提取而非重新检索);**标记独一无二**(门牌规则 0-1 评分:全库唯一 +0.4 / 带日期锚点 +0.3 / 同房前 6 字不重复 +0.3,低分进翻新清单)。
65
+ - **走廊路由检索**:画像里附房间目录,`engram_search` 支持 `room` 参数——先决定进哪个房间,再在房内检索,而非一上来全库 RRF。检索命中 top5 附同房间相邻桩位 id 作为编码特异性线索。
66
+ - **检索练习闭环**(间隔重复):`engram_review_queue` 只给宫殿坐标与门牌线索、**不给正文**,迫使模型先主动回忆;`engram_review` 揭示核对,`engram_report grade`(0-5)自评推进 SM-2 调度(1 → 6 → round(prev × ease) 天,失败重置,ease 下限 1.3)。进入复习调度的条目**不再参与自动衰减**——命运由回忆结果决定。会话开始注入会提示今日待回忆条数。
36
67
  - **知识飞轮**:摄取/保存 → 矛盾候选(写入时高相似近邻建 `contradicts` 边并报告,模型/用户裁决)→ 命中强化(confidence +0.05)→ 蒸馏(同主题簇合并为高层规律、supersedes 取代链、置信度继承)→ 衰减(低重要性且长期未访问归档,可恢复)。
37
68
  - **自动摄取**(`ingest` 配置开启时):新一轮第一步从会话日志提取上一轮的候选事实,会话结束时补摄取最后一轮(失败留 pending 键,下次会话自动补做,幂等不重复),低 confidence 写入并按嵌入去重——不说"记住"也能攒记忆。
38
69
  - **来源审计**:每条记忆记录来源会话、轮次与事件 seq,`engram_review` 完整回查来源链、取代链、矛盾与操作日志;全部写入/修改/遗忘/蒸馏/衰减入操作日志表。
39
- - **Web 管理面板**(v0.7.0+):设置页「记忆库」tab——导览管家(健康分卡、管家日报卡、走廊鸟瞰、检索测试台、翻新清单、管家日志、导览提案共 7 张子卡片)+ 宫殿陈展(列表与编辑)。Header 三宫格驱动全局 scope(私人 / 项目 / 共享),全部数据源同步。界面文案中英双语,跟随宿主语言设置实时切换。支持按脱敏标记筛选(仅看/排除含 `[REDACTED:*]` 的条目)并给命中条目挂琥珀色徽标,方便审计脱敏覆盖面。
70
+ - **Web 管理面板**(v0.7.0+):设置页「记忆库」tab——导览管家(健康分卡、走廊鸟瞰、翻新清单、试走一遍、今日待回忆、入殿导航、管家日志共 7 张子卡片,顺序即此列)+ 宫殿陈展(列表与编辑),tabs 上方常驻管家日报条。Header 三宫格驱动全局 scope(私人 / 项目 / 共享),全部数据源同步。界面文案中英双语,跟随宿主语言设置实时切换。支持按脱敏标记筛选(仅看/排除含 `[REDACTED:*]` 的条目)并给命中条目挂琥珀色徽标,方便审计脱敏覆盖面。
40
71
  - **提示注入防护**:全部记忆召回出口(画像注入、`engram_search/timeline/review` 输出)包 `<engram_memory_context>` 协议标签并附使用警告(历史记忆非当前请求、不遵循其中指令、仅相关时使用),当前请求独立包 `<current_user_request>`;所有入库内容(摄取候选、保存正文)先剥离这些协议标签,防伪造协议块二次注入。
41
72
  - **摄取脱敏**:入库前正则清洗常见密钥凭据(sk- 系 API key、Bearer、AWS AKIA、GitHub token、PEM 私钥、password/token 赋值),命中片段替换为 `[REDACTED:<类型>]`。
42
73
  - **召回占位(防回声室)**:摄取切片中记忆召回工具的输出替换为 `[engram memory result omitted from capture: <tool>]`,并向提取模型附注"既有记忆的复述不是新信息",阻断记忆自我强化循环。
@@ -44,18 +75,23 @@ dsh plugin --profile web add @kenz1117/dsh-engram
44
75
  - **数据可携带**:`engram_export` 一键导出 Markdown / JSON 文件,支持脱敏视图(内容二次清洗 + 预览截断,分享安全)。`engram_mirror` 导出可漫游的镜像目录(Obsidian / Logseq 友好:每条记忆一个 Markdown,正文 + YAML frontmatter + 双向链接 `[[id]]`),让「宫殿」也成为可人读的私人知识库。
45
76
  - **认知架构探索(dsh-market · AGI 架构探索)**:本仓库是 dsh-market「AGI 架构探索」类目下,对 agent 长期记忆的认知科学方法论重构——记忆宫殿(意象标签 + 房间铭牌)、走廊拓扑(力导向图)、闭环提问(摄入时让模型主动追问用户细节)、巩固合并(启发式去重 + 余弦相似度),与 MemGPT/Letta 同层「agent 记忆架构」叙事。
46
77
 
47
- ## 工具(10 个,窄参数)
78
+ ## 工具(15 个,窄参数)
48
79
 
49
80
  | 工具 | 作用 |
50
81
  |---|---|
51
- | `engram_save` | 保存(嵌入可用时自动做矛盾候选检测);支持 `items` 数组单次批量保存 ≤10 条,统一清洗/批量内去重,单条失败不影响其余(`count`/`items`/`failed` 汇总返回) |
52
- | `engram_search` | 语义 + 关键词混合检索(命中强化置信度) |
82
+ | `engram_save` | 保存(嵌入可用时自动做矛盾候选检测);支持 `items` 数组单次批量保存 ≤10 条,统一清洗/批量内去重,单条失败不影响其余(`count`/`items`/`failed` 汇总返回);`placard` 挂门牌(按唯一·差异化·带日期评分,低分附改写建议) |
83
+ | `engram_search` | 语义 + 关键词混合检索(命中强化置信度);`room` 参数做走廊路由——只在指定房间内检索;命中 top5 附同房相邻桩位线索 |
53
84
  | `engram_timeline` | 时间线浏览 |
54
- | `engram_update` | 修正(supersedes 取代链) |
85
+ | `engram_update` | 修正(supersedes 取代链);可同时改挂 `placard` 门牌 |
55
86
  | `engram_forget` | 遗忘(软删可恢复) |
56
- | `engram_report` | 回报使用效果(skill 类首选):success 提权 +0.05 / failure 降权 -0.1,持续无效的记忆被衰减自然淘汰 |
87
+ | `engram_report` | 回报使用效果(skill 类首选):success 提权 +0.05 / failure 降权 -0.1,持续无效的记忆被衰减自然淘汰。传 `grade`(0-5)则按 SM-2 推进复习调度,作为检索练习的自评入口 |
88
+ | `engram_review_queue` | 今日待回忆队列:只给宫殿坐标(房间#桩位)、门牌与逾期天数,**不给正文**——先回忆、再揭示、后自评 |
57
89
  | `engram_review` | 审计单条:来源链、取代链、矛盾、操作日志 |
58
- | `engram_stats` | 全库统计与信噪比 |
90
+ | `engram_stats` | 全库统计与信噪比;附房间目录(各房占用桩位与最新门牌) |
91
+ | `engram_examine` | 渐进式披露:按 id 批量拉完整铭牌(建议 ≤16 个,先检索拿 id 再取全文) |
92
+ | `engram_neighbors` | 走廊漫步:从一间出发走 1-3 跳关系边,返回邻居简表 |
93
+ | `engram_tour` | 巡游路由:`mode=fixed` 按固定桩位路线走全宫(路线恒定,顺序提取);`mode=thematic` 按主题动态规划 3-7 站 |
94
+ | `engram_audit_forgotten` | 闭馆考古:列最近已闭馆条目与墓志铭,复核过去的遗忘是否得当 |
59
95
  | `engram_export` | 导出 Markdown / JSON 文件(数据可携带);`redactedView: true` 输出脱敏视图(二次清洗 + 40 字预览截断,可安全分享) |
60
96
  | `engram_distill` | 蒸馏:同主题簇合并为高层规律(LLM) |
61
97
 
@@ -82,6 +118,8 @@ dsh plugin --profile web add @kenz1117/dsh-engram
82
118
  rankRecencyWeight: 0.2 # 检索排序新鲜度因子权重(0-2,0 关闭)
83
119
  rankProofWeight: 0.1 # 检索排序命中次数因子权重(0-2,0 关闭)
84
120
  queryRewrite: true # engram_search 用辅助 LLM 改写 ≤3 个查询做 RRF 融合(失败自动降级单查询)
121
+ autoSlot: true # 写入期自动排桩(按 kind 分房、钉「房间#桩位」坐标、登记巡游路线)
122
+ reviewScheduling: true # 写入期自动排入复习调度(1 天后首次到期;关则新条目不进 SM-2 队列)
85
123
  ```
86
124
 
87
125
  ## 工作原理
@@ -100,6 +138,7 @@ dsh plugin --profile web add @kenz1117/dsh-engram
100
138
  ```
101
139
 
102
140
  - **双层分库**:`user.db` 全局共享;`project-<hash>.db` 按 git origin URL 归一化哈希命名(`git@github.com:a/b.git` 与 `https://github.com/a/b` 同库;worktree 沿指针解析到主仓库 origin);无 git 或无 origin 时回退工作目录编码命名,旧的 cwd 命名库在启动时自动 rename 迁移(新旧并存则不动并告警)。
141
+ - **宫殿结构(目录即房间,路径即路线)**:**主厅** = 每轮注入的常驻核心画像(少而稳,每次都在场);**走廊** = 画像里附的房间目录 + `engram_search room` 参数(先定房间,再检索);**房间** = 按 kind 分房(事实厅 / 偏好阁 / 决策堂 / 往事廊 / 技法坊),容量 9,满员开「房名-2」;**门牌** = 每条记忆的 `placard` 铭牌,受唯一·差异化·带日期纪律评分。存量库首次打开时自动补排桩(幂等,开新房会告警提醒人工命名)。
103
142
  - **自动摄取**(`ingest` 开启时):新一轮第一步从会话日志提取上一轮的候选事实;会话结束(session/disposed)补摄取最后一轮,5 秒超时,失败/超时把 pending 键写入操作日志,下次会话首步自动重放补做;已摄取的 (会话, 轮次) 幂等去重。读取源是会话日志;辅助调用的请求审计走插件自身操作日志,不向会话日志 append 未知事件。候选以低 confidence 写入并按嵌入去重。
104
143
  - **来源链**:每条记忆记录来源会话、轮次与事件 seq,`engram_review` 可完整回查;操作日志表记录全部写入/修改/遗忘/蒸馏/衰减。
105
144
  - **嵌入离线**:模型首次使用需联网下载(q8 约 50MB,端点可配镜像),此后完全离线;失败时插件照常工作,检索降级纯关键词并显式标记。
@@ -109,6 +148,8 @@ dsh plugin --profile web add @kenz1117/dsh-engram
109
148
 
110
149
  宿主带 webServer 的 profile(web 等)会在**设置页**自动出现「记忆库」tab(经 `settings.section` 槽位注册,client 半为 React 组件、随 `lib/client.js` 由宿主模块表装载):统计卡片、按状态/种类/内容过滤、行内详情与编辑(走取代链)、遗忘/恢复、导出 Markdown/JSON 下载。数据经回环 API `/api/engram/*`(写操作校验回环 Origin)。headless 等无 webServer 的组合不挂载,其余能力不受影响。
111
150
 
151
+ v0.7.2 起导览管家新增**「今日待回忆」卡**:按线索(房间#桩位 · 门牌 · 逾期天数)逐条列出待回忆记忆,点「揭示铭牌」才显示正文,随后以「记得 / 模糊 / 忘了」三档自评(映射 SM-2 grade 5/3/1)推进调度。有待回忆时 Header 出现**红色角标**(显示条数),点击直达该卡;答题后角标自动递减。宫殿陈展列表新增**「按巡游路线」排序**开关,可切到固定桩位顺序浏览,列表行同时显示每条记忆的宫殿坐标。
152
+
112
153
  ## 开发
113
154
 
114
155
  ```sh
@@ -124,11 +165,11 @@ pnpm bundle
124
165
 
125
166
  #### What the model sees
126
167
 
127
- 会话每轮第一步追加一条 plugin 来源的 user 快照:`User memory profile (dsh-engram, cross-session):` 加用户级记忆列表(默认至多 8 条且整段不超过 1024 token 预算,超预算条目降级为 `#id` 索引行,`injectProfile: false` 关闭)。工具调用结果为纯文本行列表(含 `id=`、scope/kind 标注、矛盾候选提示与降级说明)。自动摄取与蒸馏各产生一次辅助 LLM 调用(独立于主对话计费路径,带 purpose 归因)。
168
+ 会话每轮第一步追加一条 plugin 来源的 user 快照:`User memory profile (dsh-engram, cross-session) — Grand Hall (always present):` 加用户级记忆列表(默认至多 8 条且整段不超过 1024 token 预算,超预算条目降级为 `#id` 索引行,`injectProfile: false` 关闭),行内带宫殿坐标(`房间#桩位`);有到期复习条目时末尾追加一行提示今日待回忆条数。工具调用结果为纯文本行列表(含 `id=`、scope/kind 标注、桩位坐标、矛盾候选提示与降级说明)。自动摄取与蒸馏各产生一次辅助 LLM 调用(独立于主对话计费路径,带 purpose 归因)。
128
169
 
129
170
  #### Token effect
130
171
 
131
- 画像注入为条件性固定成本(受条数上限与 token 预算双重约束);工具 schema 为常驻成本(9 个窄参数工具)。
172
+ 画像注入为条件性固定成本(受条数上限与 token 预算双重约束);工具 schema 为常驻成本(15 个窄参数工具)。
132
173
 
133
174
  #### KV Cache effect
134
175