dsh-tdai-memory 0.2.10 → 0.2.11

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.
Files changed (72) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +130 -130
  3. package/README.zh.md +72 -72
  4. package/THIRD-PARTY-NOTICES.md +20 -20
  5. package/client.js +349 -349
  6. package/cordis.patch.yml +8 -8
  7. package/index.js +421 -421
  8. package/package.json +5 -2
  9. package/recall-inject.js +86 -86
  10. package/vendor/dsh-settings-expose.js +75 -75
  11. package/vendor/tdai/adapters/index.js +15 -15
  12. package/vendor/tdai/adapters/openclaw/host-adapter.js +83 -83
  13. package/vendor/tdai/adapters/openclaw/index.js +5 -5
  14. package/vendor/tdai/adapters/openclaw/llm-runner.js +69 -69
  15. package/vendor/tdai/adapters/standalone/host-adapter.js +58 -58
  16. package/vendor/tdai/adapters/standalone/index.js +5 -5
  17. package/vendor/tdai/adapters/standalone/llm-runner.js +246 -246
  18. package/vendor/tdai/config.js +363 -363
  19. package/vendor/tdai/core/conversation/l0-recorder.js +420 -420
  20. package/vendor/tdai/core/hooks/auto-capture.js +236 -236
  21. package/vendor/tdai/core/hooks/auto-recall.js +640 -640
  22. package/vendor/tdai/core/index.js +8 -8
  23. package/vendor/tdai/core/persona/persona-generator.js +184 -184
  24. package/vendor/tdai/core/persona/persona-trigger.js +94 -94
  25. package/vendor/tdai/core/profile/profile-sync.js +200 -200
  26. package/vendor/tdai/core/prompts/l1-dedup.js +72 -72
  27. package/vendor/tdai/core/prompts/l1-extraction.js +34 -34
  28. package/vendor/tdai/core/prompts/persona-generation.js +35 -35
  29. package/vendor/tdai/core/prompts/scene-extraction.js +45 -45
  30. package/vendor/tdai/core/record/l1-dedup.js +318 -318
  31. package/vendor/tdai/core/record/l1-extractor.js +379 -379
  32. package/vendor/tdai/core/record/l1-reader.js +178 -178
  33. package/vendor/tdai/core/record/l1-writer.js +141 -141
  34. package/vendor/tdai/core/report/reporter.js +86 -86
  35. package/vendor/tdai/core/scene/filename-normalizer.js +161 -161
  36. package/vendor/tdai/core/scene/scene-extractor.js +410 -410
  37. package/vendor/tdai/core/scene/scene-format.js +53 -53
  38. package/vendor/tdai/core/scene/scene-index.js +82 -82
  39. package/vendor/tdai/core/scene/scene-navigation.js +57 -57
  40. package/vendor/tdai/core/seed/input.js +404 -404
  41. package/vendor/tdai/core/seed/seed-runtime.js +314 -314
  42. package/vendor/tdai/core/seed/types.js +9 -9
  43. package/vendor/tdai/core/store/bm25-client.js +117 -117
  44. package/vendor/tdai/core/store/bm25-local.js +68 -68
  45. package/vendor/tdai/core/store/embedding.js +632 -632
  46. package/vendor/tdai/core/store/factory.js +95 -95
  47. package/vendor/tdai/core/store/search-utils.js +54 -54
  48. package/vendor/tdai/core/store/sqlite.js +1632 -1632
  49. package/vendor/tdai/core/store/tcvdb-client.js +221 -221
  50. package/vendor/tdai/core/store/tcvdb.js +1047 -1047
  51. package/vendor/tdai/core/store/types.js +17 -17
  52. package/vendor/tdai/core/tdai-core.js +446 -446
  53. package/vendor/tdai/core/tools/conversation-search.js +199 -199
  54. package/vendor/tdai/core/tools/memory-search.js +207 -207
  55. package/vendor/tdai/core/types.js +12 -12
  56. package/vendor/tdai/utils/backup.js +189 -189
  57. package/vendor/tdai/utils/checkpoint.js +360 -360
  58. package/vendor/tdai/utils/clean-context-runner.js +472 -472
  59. package/vendor/tdai/utils/ensure-hook-policy.js +213 -213
  60. package/vendor/tdai/utils/env.js +13 -13
  61. package/vendor/tdai/utils/managed-timer.js +127 -127
  62. package/vendor/tdai/utils/manifest.js +91 -91
  63. package/vendor/tdai/utils/memory-cleaner.js +300 -300
  64. package/vendor/tdai/utils/no-think-fetch.js +109 -109
  65. package/vendor/tdai/utils/openclaw-state-dir.js +26 -26
  66. package/vendor/tdai/utils/pipeline-factory.js +517 -517
  67. package/vendor/tdai/utils/pipeline-manager.js +892 -892
  68. package/vendor/tdai/utils/sanitize.js +360 -360
  69. package/vendor/tdai/utils/serial-queue.js +103 -103
  70. package/vendor/tdai/utils/session-filter.js +88 -88
  71. package/vendor/tdai/utils/text-utils.js +29 -29
  72. package/vendor/tdai/utils/time.js +252 -252
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Scorp1o117
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Scorp1o117
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,130 +1,130 @@
1
- # dsh-tdai-memory
2
-
3
- [![中文文档](https://img.shields.io/badge/%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A3-blue)](README.zh.md)
4
-
5
- **GitHub**: [Scorp1o117/dsh-tdai-memory](https://github.com/Scorp1o117/dsh-tdai-memory) · **npm**: [dsh-tdai-memory](https://www.npmjs.com/package/dsh-tdai-memory)
6
-
7
- [![Enhancement Suite](https://img.shields.io/badge/part%20of-Enhancement%20Suite-3964fe)](https://github.com/Scorp1o117/dsh-enhancement-suite) [![npm](https://img.shields.io/npm/v/dsh-enhancement-suite)](https://www.npmjs.com/package/dsh-enhancement-suite)
8
-
9
- Part of the [DeepSeek Harness Enhancement Suite](https://github.com/Scorp1o117/dsh-enhancement-suite) — Vision · Soul/Persona · Long-term Memory · Plugin Marketplace.
10
-
11
- A port of **TencentDB Agent Memory** (Tencent Cloud's open-source four-layer
12
- memory system, originally an OpenClaw plugin) into DeepSeek Harness.
13
-
14
- ## Features
15
-
16
- - **L0 conversation capture**: every turn (turn end, request boundary) is
17
- written to raw conversation storage (JSONL + SQLite + FTS + vectors)
18
- - **L1 structured memory**: a background pipeline uses an LLM to extract
19
- facts / preferences / events (persona / episodic / instruction) from
20
- conversations, stored in `records/` + SQLite + FTS + vectors
21
- - **L2 scenes / L3 persona**: scene blocks and user profile generation
22
- (pipeline-scheduled)
23
- - **Automatic recall injection**: on every prompt assembly, relevant memories
24
- and the user profile are retrieved by the current user message and injected
25
- as dynamic context (the model "just remembers")
26
- - **Tools**: `tdai_memory_search` (L1 structured search),
27
- `tdai_conversation_search` (L0 raw-text search)
28
-
29
- The data directory reuses the existing `~/.memory-tencentdb/memory-tdai`, so
30
- **previously accumulated memories carry over seamlessly**.
31
-
32
- ## Architecture (porting approach)
33
-
34
- | Layer | Content |
35
- |---|---|
36
- | Core | The host-neutral core of `tdai-memory-openclaw-plugin` (`src/core`, `src/utils`), tsc-compiled to ESM (`dist-dsh/`), zero changes |
37
- | Host adapter | `StandaloneHostAdapter` (official standalone mode, direct OpenAI-compatible calls) |
38
- | dsh shell | `index.js`: config mapping, `session/event` + `session/flush` capture, `system-prompt/assemble` recall injection on `agent.ctx`, tool registration, lifecycle |
39
- | Fallback | `recall-inject.js`: preset-row recall injection (used when mounted inside an agent preset) |
40
-
41
- Hard-won wiring details:
42
-
43
- - **Capture**: `session/flush` listener (await semantics; must complete before
44
- headless exits); `turn/start` timestamps as the L0 cursor floor; turn-id dedup
45
- - **Headless one-shot runs**: wait for `core.handleSessionEnd()` inside flush
46
- (L1 extraction finishes before exit; otherwise the 5s shutdown timeout kills it)
47
- - **Recall injection**: must be registered on **`agent.ctx`** (assembly runs in
48
- the agent scope; root listeners never see it); attach one tick after
49
- `session/created` by resolving the agent from the `agents` service
50
-
51
- ## Configuration (profile patch + settings)
52
-
53
- Configuration is **settings-namespace driven**: the profile patch is the base
54
- layer, and the `tdai-memory:` section of `$DSH_HOME/settings.yaml` overrides it
55
- (LLM/embedding keys live in settings.yaml). The **Web UI Settings → 记忆**
56
- section edits every field (v0.2.0, write-only keys); TdaiCore is built at
57
- startup, so changes apply **after a restart**.
58
-
59
- ```yaml
60
- # $DSH_HOME/settings.yaml
61
- tdai-memory:
62
- llm:
63
- apiKey: 'sk-...'
64
- embedding:
65
- apiKey: 'local-no-key'
66
- ```
67
-
68
- ```yaml
69
- # profile patch (base layer)
70
- - id: tdai-memory
71
- name: 'dsh-tdai-memory'
72
- config:
73
- extraction:
74
- enabled: true
75
- enableDedup: false # dedup LLM output parsing is flaky; off by default
76
- llm: # L1/L2/L3 extraction model (OpenAI-compatible)
77
- baseUrl: 'https://opencode.ai/zen/go/v1'
78
- model: 'mimo-v2.5' # deepseek-v4-flash produces invalid extraction JSON
79
- embedding: # vectors (OpenAI-compatible /v1/embeddings)
80
- baseUrl: 'http://127.0.0.1:8088/v1'
81
- model: 'Qwen3-Embedding-0.6B'
82
- dimensions: 1024
83
- sendDimensions: false
84
- ```
85
-
86
- ## Install
87
-
88
- ```bash
89
- dsh plugin --profile web add dsh-tdai-memory
90
- ```
91
-
92
- then mount it in `$DSH_HOME/profiles/web/cordis.patch.yml`:
93
-
94
- ```yaml
95
- - insert:
96
- - id: tdai-memory
97
- name: 'dsh-tdai-memory'
98
- config: {} # keys can live in settings.yaml instead
99
- ```
100
-
101
- and restart `dsh web`. LLM/embedding API keys can be set in the Web UI
102
- settings page (记忆 / Memory) or directly in `settings.yaml` under
103
- `tdai-memory:`.
104
-
105
- > **Note for users**
106
- > - This plugin is a standard **profile bundle** (`dsh.bundle.patch`):
107
- > `dsh plugin --profile web add dsh-tdai-memory` installs and mounts it in
108
- > one step — no manual `cordis.patch.yml` edits needed.
109
- > - The settings section needs the `dsh-host-apiproxy` namespace allowlist;
110
- > the plugin patches it automatically on first start — **restart `dsh web`
111
- > once more** and the section appears. A dsh update overwrites the patch;
112
- > the next plugin start re-applies it.
113
- > - Settings changes apply **after a restart** (TdaiCore is built at startup).
114
- > - Tested against DSH `0.1.0-rc.6`.
115
-
116
- ## Known trade-offs
117
-
118
- - **Extraction model**: `mimo-v2.5` extracts correctly but takes 20-30s per
119
- call (background execution, does not block the conversation);
120
- `deepseek-v4-flash` is fast but its JSON output is non-compliant (extracts 0)
121
- - **dedup**: LLM conflict-detection output parsing is unstable (once caused
122
- stored=0); off by default; enable only with a more reliable model
123
- - **L1 memory vectors**: written with storage (8088 embedding is fast); L0
124
- vectors run as a background task, drained by `destroy()` on headless exit
125
- - **Upgrades**: after pulling new upstream code, rerun
126
- `npx tsc -p dsh-tsconfig.json` in the tdai project dir (output in `dist-dsh/`)
127
-
128
- ## License
129
-
130
- MIT
1
+ # dsh-tdai-memory
2
+
3
+ [![中文文档](https://img.shields.io/badge/%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A3-blue)](README.zh.md)
4
+
5
+ **GitHub**: [Scorp1o117/dsh-tdai-memory](https://github.com/Scorp1o117/dsh-tdai-memory) · **npm**: [dsh-tdai-memory](https://www.npmjs.com/package/dsh-tdai-memory)
6
+
7
+ [![Enhancement Suite](https://img.shields.io/badge/part%20of-Enhancement%20Suite-3964fe)](https://github.com/Scorp1o117/dsh-enhancement-suite) [![npm](https://img.shields.io/npm/v/dsh-enhancement-suite)](https://www.npmjs.com/package/dsh-enhancement-suite)
8
+
9
+ Part of the [DeepSeek Harness Enhancement Suite](https://github.com/Scorp1o117/dsh-enhancement-suite) — Vision · Soul/Persona · Long-term Memory · Plugin Marketplace.
10
+
11
+ A port of **TencentDB Agent Memory** (Tencent Cloud's open-source four-layer
12
+ memory system, originally an OpenClaw plugin) into DeepSeek Harness.
13
+
14
+ ## Features
15
+
16
+ - **L0 conversation capture**: every turn (turn end, request boundary) is
17
+ written to raw conversation storage (JSONL + SQLite + FTS + vectors)
18
+ - **L1 structured memory**: a background pipeline uses an LLM to extract
19
+ facts / preferences / events (persona / episodic / instruction) from
20
+ conversations, stored in `records/` + SQLite + FTS + vectors
21
+ - **L2 scenes / L3 persona**: scene blocks and user profile generation
22
+ (pipeline-scheduled)
23
+ - **Automatic recall injection**: on every prompt assembly, relevant memories
24
+ and the user profile are retrieved by the current user message and injected
25
+ as dynamic context (the model "just remembers")
26
+ - **Tools**: `tdai_memory_search` (L1 structured search),
27
+ `tdai_conversation_search` (L0 raw-text search)
28
+
29
+ The data directory reuses the existing `~/.memory-tencentdb/memory-tdai`, so
30
+ **previously accumulated memories carry over seamlessly**.
31
+
32
+ ## Architecture (porting approach)
33
+
34
+ | Layer | Content |
35
+ |---|---|
36
+ | Core | The host-neutral core of `tdai-memory-openclaw-plugin` (`src/core`, `src/utils`), tsc-compiled to ESM (`dist-dsh/`), zero changes |
37
+ | Host adapter | `StandaloneHostAdapter` (official standalone mode, direct OpenAI-compatible calls) |
38
+ | dsh shell | `index.js`: config mapping, `session/event` + `session/flush` capture, `system-prompt/assemble` recall injection on `agent.ctx`, tool registration, lifecycle |
39
+ | Fallback | `recall-inject.js`: preset-row recall injection (used when mounted inside an agent preset) |
40
+
41
+ Hard-won wiring details:
42
+
43
+ - **Capture**: `session/flush` listener (await semantics; must complete before
44
+ headless exits); `turn/start` timestamps as the L0 cursor floor; turn-id dedup
45
+ - **Headless one-shot runs**: wait for `core.handleSessionEnd()` inside flush
46
+ (L1 extraction finishes before exit; otherwise the 5s shutdown timeout kills it)
47
+ - **Recall injection**: must be registered on **`agent.ctx`** (assembly runs in
48
+ the agent scope; root listeners never see it); attach one tick after
49
+ `session/created` by resolving the agent from the `agents` service
50
+
51
+ ## Configuration (profile patch + settings)
52
+
53
+ Configuration is **settings-namespace driven**: the profile patch is the base
54
+ layer, and the `tdai-memory:` section of `$DSH_HOME/settings.yaml` overrides it
55
+ (LLM/embedding keys live in settings.yaml). The **Web UI Settings → 记忆**
56
+ section edits every field (v0.2.0, write-only keys); TdaiCore is built at
57
+ startup, so changes apply **after a restart**.
58
+
59
+ ```yaml
60
+ # $DSH_HOME/settings.yaml
61
+ tdai-memory:
62
+ llm:
63
+ apiKey: 'sk-...'
64
+ embedding:
65
+ apiKey: 'local-no-key'
66
+ ```
67
+
68
+ ```yaml
69
+ # profile patch (base layer)
70
+ - id: tdai-memory
71
+ name: 'dsh-tdai-memory'
72
+ config:
73
+ extraction:
74
+ enabled: true
75
+ enableDedup: false # dedup LLM output parsing is flaky; off by default
76
+ llm: # L1/L2/L3 extraction model (OpenAI-compatible)
77
+ baseUrl: 'https://opencode.ai/zen/go/v1'
78
+ model: 'mimo-v2.5' # deepseek-v4-flash produces invalid extraction JSON
79
+ embedding: # vectors (OpenAI-compatible /v1/embeddings)
80
+ baseUrl: 'http://127.0.0.1:8088/v1'
81
+ model: 'Qwen3-Embedding-0.6B'
82
+ dimensions: 1024
83
+ sendDimensions: false
84
+ ```
85
+
86
+ ## Install
87
+
88
+ ```bash
89
+ dsh plugin --profile web add dsh-tdai-memory
90
+ ```
91
+
92
+ then mount it in `$DSH_HOME/profiles/web/cordis.patch.yml`:
93
+
94
+ ```yaml
95
+ - insert:
96
+ - id: tdai-memory
97
+ name: 'dsh-tdai-memory'
98
+ config: {} # keys can live in settings.yaml instead
99
+ ```
100
+
101
+ and restart `dsh web`. LLM/embedding API keys can be set in the Web UI
102
+ settings page (记忆 / Memory) or directly in `settings.yaml` under
103
+ `tdai-memory:`.
104
+
105
+ > **Note for users**
106
+ > - This plugin is a standard **profile bundle** (`dsh.bundle.patch`):
107
+ > `dsh plugin --profile web add dsh-tdai-memory` installs and mounts it in
108
+ > one step — no manual `cordis.patch.yml` edits needed.
109
+ > - The settings section needs the `dsh-host-apiproxy` namespace allowlist;
110
+ > the plugin patches it automatically on first start — **restart `dsh web`
111
+ > once more** and the section appears. A dsh update overwrites the patch;
112
+ > the next plugin start re-applies it.
113
+ > - Settings changes apply **after a restart** (TdaiCore is built at startup).
114
+ > - Tested against DSH `0.1.0-rc.6`, `0.1.0-rc.7`, and `0.1.0-rc.8`.
115
+
116
+ ## Known trade-offs
117
+
118
+ - **Extraction model**: `mimo-v2.5` extracts correctly but takes 20-30s per
119
+ call (background execution, does not block the conversation);
120
+ `deepseek-v4-flash` is fast but its JSON output is non-compliant (extracts 0)
121
+ - **dedup**: LLM conflict-detection output parsing is unstable (once caused
122
+ stored=0); off by default; enable only with a more reliable model
123
+ - **L1 memory vectors**: written with storage (8088 embedding is fast); L0
124
+ vectors run as a background task, drained by `destroy()` on headless exit
125
+ - **Upgrades**: after pulling new upstream code, rerun
126
+ `npx tsc -p dsh-tsconfig.json` in the tdai project dir (output in `dist-dsh/`)
127
+
128
+ ## License
129
+
130
+ MIT
package/README.zh.md CHANGED
@@ -1,72 +1,72 @@
1
- # dsh-tdai-memory
2
-
3
- **GitHub**: [Scorp1o117/dsh-tdai-memory](https://github.com/Scorp1o117/dsh-tdai-memory) · **npm**: [dsh-tdai-memory](https://www.npmjs.com/package/dsh-tdai-memory) · [English](README.md)
4
-
5
- [![Enhancement Suite](https://img.shields.io/badge/part%20of-Enhancement%20Suite-3964fe)](https://github.com/Scorp1o117/dsh-enhancement-suite) [![npm](https://img.shields.io/npm/v/dsh-enhancement-suite)](https://www.npmjs.com/package/dsh-enhancement-suite)
6
-
7
- 属于 [DeepSeek Harness Enhancement Suite](https://github.com/Scorp1o117/dsh-enhancement-suite) —— Vision · Soul/Persona · 长期记忆 · 插件市场。
8
-
9
- 把 **TencentDB Agent Memory**(腾讯云开源的四层记忆系统,原为 OpenClaw 插件)移植进 DeepSeek Harness。
10
-
11
- ## 能力
12
-
13
- - **L0 对话捕获**:每轮对话(turn 结束、请求边界)自动写入原始对话(JSONL + SQLite + FTS + 向量)
14
- - **L1 结构化记忆**:后台管线用 LLM 从对话中提取事实/偏好/事件(persona / episodic / instruction),写入 `records/` + SQLite + FTS + 向量
15
- - **L2 场景 / L3 画像**:场景块与用户画像生成(管线自动调度)
16
- - **自动召回注入**:每次组装提示词时,按当前用户消息检索相关记忆 + 画像,作为动态上下文注入(模型"凭空想起")
17
- - **工具**:`tdai_memory_search`(L1 结构化检索)、`tdai_conversation_search`(L0 原文检索)
18
-
19
- 数据目录复用现有 `~/.memory-tencentdb/memory-tdai`,**旧记忆无缝继承**。
20
-
21
- ## 架构(移植方式)
22
-
23
- | 层 | 内容 |
24
- |---|---|
25
- | 核心 | `tdai-memory-openclaw-plugin` 的 host-neutral 核心(`src/core`、`src/utils`),tsc 编译为 ESM(`dist-dsh/`),零改动 |
26
- | 宿主适配 | `StandaloneHostAdapter`(官方 standalone 模式,OpenAI 兼容直调) |
27
- | dsh 壳 | `index.js`:配置映射、`session/event`+`session/flush` 捕获、`agent.ctx` 上的 `system-prompt/assemble` waterfall 召回注入、工具注册、生命周期 |
28
- | 备用 | `recall-inject.js`:preset 行形态的召回注入(挂在 agent preset 内时用) |
29
-
30
- 关键接线(都是踩坑换来的):
31
-
32
- - **捕获**:`session/flush` 监听器(await 语义,headless 退出前必完成);`turn/start` 时间戳做 L0 cursor 下限;turn id 去重
33
- - **headless 一次性任务**:flush 内再等 `core.handleSessionEnd()`(L1 提取跑完才退出;否则 5s 关闭超时会杀掉提取)
34
- - **召回注入**:必须注册在 **`agent.ctx`** 上(组装在 agent 作用域进行,root 监听器收不到);`session/created` 后延迟一 tick 从 `agents` 服务拿 agent
35
-
36
- ## 配置(profile patch + settings)
37
-
38
- 配置以 **settings 命名空间**驱动:profile patch 作为 base 层,`$DSH_HOME/settings.yaml` 的 `tdai-memory:` 节覆盖(LLM/embedding 密钥已迁到 settings.yaml)。Web UI 设置 → 记忆 可编辑全部字段(v0.2.0,含写-only 密钥);TdaiCore 启动时构建,改动**重启后生效**。
39
-
40
- ```yaml
41
- # $DSH_HOME/settings.yaml
42
- tdai-memory:
43
- llm:
44
- apiKey: 'sk-...'
45
- embedding:
46
- apiKey: 'local-no-key'
47
- ```
48
-
49
- ```yaml
50
- # profile patch(base 层)
51
- - id: tdai-memory
52
- name: 'dsh-tdai-memory'
53
- config:
54
- extraction:
55
- enabled: true
56
- enableDedup: false # dedup 的 LLM 输出解析不稳,先关
57
- llm: # L1/L2/L3 提取模型(OpenAI 兼容)
58
- baseUrl: 'https://opencode.ai/zen/go/v1'
59
- model: 'mimo-v2.5' # deepseek-v4-flash 对提取 JSON 输出不合格
60
- embedding: # 向量(OpenAI 兼容 /v1/embeddings)
61
- baseUrl: 'http://127.0.0.1:8088/v1'
62
- model: 'Qwen3-Embedding-0.6B'
63
- dimensions: 1024
64
- sendDimensions: false
65
- ```
66
-
67
- ## 已知取舍
68
-
69
- - **提取模型**:`mimo-v2.5` 提取正确但单次 20-30s(后台执行,不阻塞对话);`deepseek-v4-flash` 快但 JSON 输出不合规(提取 0 条)
70
- - **dedup**:LLM 冲突检测输出解析不稳(曾导致 stored=0),默认关闭;开启需换更稳的模型
71
- - **L1 记忆向量**:随存储写入(8088 embedding 快);L0 向量走后台任务,headless 退出时由 `destroy()` drain
72
- - **升级**:上游拉新代码后,在 tdai 项目目录重跑 `npx tsc -p dsh-tsconfig.json`(产物在 `dist-dsh/`)
1
+ # dsh-tdai-memory
2
+
3
+ **GitHub**: [Scorp1o117/dsh-tdai-memory](https://github.com/Scorp1o117/dsh-tdai-memory) · **npm**: [dsh-tdai-memory](https://www.npmjs.com/package/dsh-tdai-memory) · [English](README.md)
4
+
5
+ [![Enhancement Suite](https://img.shields.io/badge/part%20of-Enhancement%20Suite-3964fe)](https://github.com/Scorp1o117/dsh-enhancement-suite) [![npm](https://img.shields.io/npm/v/dsh-enhancement-suite)](https://www.npmjs.com/package/dsh-enhancement-suite)
6
+
7
+ 属于 [DeepSeek Harness Enhancement Suite](https://github.com/Scorp1o117/dsh-enhancement-suite) —— Vision · Soul/Persona · 长期记忆 · 插件市场。
8
+
9
+ 把 **TencentDB Agent Memory**(腾讯云开源的四层记忆系统,原为 OpenClaw 插件)移植进 DeepSeek Harness。
10
+
11
+ ## 能力
12
+
13
+ - **L0 对话捕获**:每轮对话(turn 结束、请求边界)自动写入原始对话(JSONL + SQLite + FTS + 向量)
14
+ - **L1 结构化记忆**:后台管线用 LLM 从对话中提取事实/偏好/事件(persona / episodic / instruction),写入 `records/` + SQLite + FTS + 向量
15
+ - **L2 场景 / L3 画像**:场景块与用户画像生成(管线自动调度)
16
+ - **自动召回注入**:每次组装提示词时,按当前用户消息检索相关记忆 + 画像,作为动态上下文注入(模型"凭空想起")
17
+ - **工具**:`tdai_memory_search`(L1 结构化检索)、`tdai_conversation_search`(L0 原文检索)
18
+
19
+ 数据目录复用现有 `~/.memory-tencentdb/memory-tdai`,**旧记忆无缝继承**。
20
+
21
+ ## 架构(移植方式)
22
+
23
+ | 层 | 内容 |
24
+ |---|---|
25
+ | 核心 | `tdai-memory-openclaw-plugin` 的 host-neutral 核心(`src/core`、`src/utils`),tsc 编译为 ESM(`dist-dsh/`),零改动 |
26
+ | 宿主适配 | `StandaloneHostAdapter`(官方 standalone 模式,OpenAI 兼容直调) |
27
+ | dsh 壳 | `index.js`:配置映射、`session/event`+`session/flush` 捕获、`agent.ctx` 上的 `system-prompt/assemble` waterfall 召回注入、工具注册、生命周期 |
28
+ | 备用 | `recall-inject.js`:preset 行形态的召回注入(挂在 agent preset 内时用) |
29
+
30
+ 关键接线(都是踩坑换来的):
31
+
32
+ - **捕获**:`session/flush` 监听器(await 语义,headless 退出前必完成);`turn/start` 时间戳做 L0 cursor 下限;turn id 去重
33
+ - **headless 一次性任务**:flush 内再等 `core.handleSessionEnd()`(L1 提取跑完才退出;否则 5s 关闭超时会杀掉提取)
34
+ - **召回注入**:必须注册在 **`agent.ctx`** 上(组装在 agent 作用域进行,root 监听器收不到);`session/created` 后延迟一 tick 从 `agents` 服务拿 agent
35
+
36
+ ## 配置(profile patch + settings)
37
+
38
+ 配置以 **settings 命名空间**驱动:profile patch 作为 base 层,`$DSH_HOME/settings.yaml` 的 `tdai-memory:` 节覆盖(LLM/embedding 密钥已迁到 settings.yaml)。Web UI 设置 → 记忆 可编辑全部字段(v0.2.0,含写-only 密钥);TdaiCore 启动时构建,改动**重启后生效**。
39
+
40
+ ```yaml
41
+ # $DSH_HOME/settings.yaml
42
+ tdai-memory:
43
+ llm:
44
+ apiKey: 'sk-...'
45
+ embedding:
46
+ apiKey: 'local-no-key'
47
+ ```
48
+
49
+ ```yaml
50
+ # profile patch(base 层)
51
+ - id: tdai-memory
52
+ name: 'dsh-tdai-memory'
53
+ config:
54
+ extraction:
55
+ enabled: true
56
+ enableDedup: false # dedup 的 LLM 输出解析不稳,先关
57
+ llm: # L1/L2/L3 提取模型(OpenAI 兼容)
58
+ baseUrl: 'https://opencode.ai/zen/go/v1'
59
+ model: 'mimo-v2.5' # deepseek-v4-flash 对提取 JSON 输出不合格
60
+ embedding: # 向量(OpenAI 兼容 /v1/embeddings)
61
+ baseUrl: 'http://127.0.0.1:8088/v1'
62
+ model: 'Qwen3-Embedding-0.6B'
63
+ dimensions: 1024
64
+ sendDimensions: false
65
+ ```
66
+
67
+ ## 已知取舍
68
+
69
+ - **提取模型**:`mimo-v2.5` 提取正确但单次 20-30s(后台执行,不阻塞对话);`deepseek-v4-flash` 快但 JSON 输出不合规(提取 0 条)
70
+ - **dedup**:LLM 冲突检测输出解析不稳(曾导致 stored=0),默认关闭;开启需换更稳的模型
71
+ - **L1 记忆向量**:随存储写入(8088 embedding 快);L0 向量走后台任务,headless 退出时由 `destroy()` drain
72
+ - **升级**:上游拉新代码后,在 tdai 项目目录重跑 `npx tsc -p dsh-tsconfig.json`(产物在 `dist-dsh/`)
@@ -1,20 +1,20 @@
1
- # Third-party notices
2
-
3
- ## TencentDB Agent Memory core (vendored in `vendor/tdai`)
4
-
5
- `vendor/tdai` is a TypeScript-compiled copy of the host-neutral core of
6
- [TencentCloud/TencentDB-Agent-Memory](https://github.com/TencentCloud/TencentDB-Agent-Memory)
7
- (`tdai-memory-openclaw-plugin`, npm: `@tencentdb-agent-memory/memory-tencentdb`),
8
- compiled with `tsc -p dsh-tsconfig.json` (see the upstream repo for source).
9
- Its runtime dependencies are declared in this package's `dependencies`.
10
-
11
- MIT License — Copyright (c) 2026 TencentCloud
12
-
13
- ## Runtime dependencies
14
-
15
- - `ai` / `@ai-sdk/openai` — Vercel AI SDK (Apache-2.0)
16
- - `@node-rs/jieba` — Rust jieba bindings (MIT)
17
- - `sqlite-vec` — vector search extension for SQLite (Apache-2.0 / MIT)
18
- - `json5` — JSON5 parser (MIT)
19
- - `undici` — HTTP client (MIT)
20
- - `@tencentdb-agent-memory/tcvdb-text` — TencentDB text utilities (MIT)
1
+ # Third-party notices
2
+
3
+ ## TencentDB Agent Memory core (vendored in `vendor/tdai`)
4
+
5
+ `vendor/tdai` is a TypeScript-compiled copy of the host-neutral core of
6
+ [TencentCloud/TencentDB-Agent-Memory](https://github.com/TencentCloud/TencentDB-Agent-Memory)
7
+ (`tdai-memory-openclaw-plugin`, npm: `@tencentdb-agent-memory/memory-tencentdb`),
8
+ compiled with `tsc -p dsh-tsconfig.json` (see the upstream repo for source).
9
+ Its runtime dependencies are declared in this package's `dependencies`.
10
+
11
+ MIT License — Copyright (c) 2026 TencentCloud
12
+
13
+ ## Runtime dependencies
14
+
15
+ - `ai` / `@ai-sdk/openai` — Vercel AI SDK (Apache-2.0)
16
+ - `@node-rs/jieba` — Rust jieba bindings (MIT)
17
+ - `sqlite-vec` — vector search extension for SQLite (Apache-2.0 / MIT)
18
+ - `json5` — JSON5 parser (MIT)
19
+ - `undici` — HTTP client (MIT)
20
+ - `@tencentdb-agent-memory/tcvdb-text` — TencentDB text utilities (MIT)