openclaw-cortex-memory 0.1.0-Alpha.3 → 0.1.0-Alpha.31

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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +296 -203
  3. package/SIGNATURE.md +7 -0
  4. package/SKILL.md +92 -268
  5. package/dist/index.d.ts +100 -22
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1249 -1252
  8. package/dist/index.js.map +1 -1
  9. package/dist/openclaw.plugin.json +501 -16
  10. package/dist/src/dedup/three_stage_deduplicator.d.ts +25 -0
  11. package/dist/src/dedup/three_stage_deduplicator.d.ts.map +1 -0
  12. package/dist/src/dedup/three_stage_deduplicator.js +224 -0
  13. package/dist/src/dedup/three_stage_deduplicator.js.map +1 -0
  14. package/dist/src/engine/memory_engine.d.ts +6 -1
  15. package/dist/src/engine/memory_engine.d.ts.map +1 -1
  16. package/dist/src/engine/ts_engine.d.ts +242 -0
  17. package/dist/src/engine/ts_engine.d.ts.map +1 -1
  18. package/dist/src/engine/ts_engine.js +1468 -52
  19. package/dist/src/engine/ts_engine.js.map +1 -1
  20. package/dist/src/engine/types.d.ts +29 -0
  21. package/dist/src/engine/types.d.ts.map +1 -1
  22. package/dist/src/graph/ontology.d.ts +125 -0
  23. package/dist/src/graph/ontology.d.ts.map +1 -0
  24. package/dist/src/graph/ontology.js +1237 -0
  25. package/dist/src/graph/ontology.js.map +1 -0
  26. package/dist/src/net/http_post.d.ts +17 -0
  27. package/dist/src/net/http_post.d.ts.map +1 -0
  28. package/dist/src/net/http_post.js +56 -0
  29. package/dist/src/net/http_post.js.map +1 -0
  30. package/dist/src/quality/llm_output_validator.d.ts +66 -0
  31. package/dist/src/quality/llm_output_validator.d.ts.map +1 -0
  32. package/dist/src/quality/llm_output_validator.js +659 -0
  33. package/dist/src/quality/llm_output_validator.js.map +1 -0
  34. package/dist/src/reflect/reflector.d.ts +7 -0
  35. package/dist/src/reflect/reflector.d.ts.map +1 -1
  36. package/dist/src/reflect/reflector.js +352 -8
  37. package/dist/src/reflect/reflector.js.map +1 -1
  38. package/dist/src/rules/rule_store.d.ts.map +1 -1
  39. package/dist/src/rules/rule_store.js +75 -16
  40. package/dist/src/rules/rule_store.js.map +1 -1
  41. package/dist/src/session/session_end.d.ts +33 -0
  42. package/dist/src/session/session_end.d.ts.map +1 -1
  43. package/dist/src/session/session_end.js +67 -64
  44. package/dist/src/session/session_end.js.map +1 -1
  45. package/dist/src/store/archive_store.d.ts +136 -0
  46. package/dist/src/store/archive_store.d.ts.map +1 -0
  47. package/dist/src/store/archive_store.js +635 -0
  48. package/dist/src/store/archive_store.js.map +1 -0
  49. package/dist/src/store/embedding_utils.d.ts +32 -0
  50. package/dist/src/store/embedding_utils.d.ts.map +1 -0
  51. package/dist/src/store/embedding_utils.js +173 -0
  52. package/dist/src/store/embedding_utils.js.map +1 -0
  53. package/dist/src/store/graph_memory_store.d.ts +114 -0
  54. package/dist/src/store/graph_memory_store.d.ts.map +1 -0
  55. package/dist/src/store/graph_memory_store.js +841 -0
  56. package/dist/src/store/graph_memory_store.js.map +1 -0
  57. package/dist/src/store/read_store.d.ts +89 -0
  58. package/dist/src/store/read_store.d.ts.map +1 -1
  59. package/dist/src/store/read_store.js +2459 -28
  60. package/dist/src/store/read_store.js.map +1 -1
  61. package/dist/src/store/vector_store.d.ts +45 -0
  62. package/dist/src/store/vector_store.d.ts.map +1 -0
  63. package/dist/src/store/vector_store.js +202 -0
  64. package/dist/src/store/vector_store.js.map +1 -0
  65. package/dist/src/store/write_store.d.ts +54 -0
  66. package/dist/src/store/write_store.d.ts.map +1 -1
  67. package/dist/src/store/write_store.js +284 -6
  68. package/dist/src/store/write_store.js.map +1 -1
  69. package/dist/src/sync/session_sync.d.ts +119 -2
  70. package/dist/src/sync/session_sync.d.ts.map +1 -1
  71. package/dist/src/sync/session_sync.js +2377 -31
  72. package/dist/src/sync/session_sync.js.map +1 -1
  73. package/dist/src/utils/runtime_env.d.ts +4 -0
  74. package/dist/src/utils/runtime_env.d.ts.map +1 -0
  75. package/dist/src/utils/runtime_env.js +51 -0
  76. package/dist/src/utils/runtime_env.js.map +1 -0
  77. package/dist/src/wiki/wiki_linter.d.ts +25 -0
  78. package/dist/src/wiki/wiki_linter.d.ts.map +1 -0
  79. package/dist/src/wiki/wiki_linter.js +268 -0
  80. package/dist/src/wiki/wiki_linter.js.map +1 -0
  81. package/dist/src/wiki/wiki_logger.d.ts +10 -0
  82. package/dist/src/wiki/wiki_logger.d.ts.map +1 -0
  83. package/dist/src/wiki/wiki_logger.js +78 -0
  84. package/dist/src/wiki/wiki_logger.js.map +1 -0
  85. package/dist/src/wiki/wiki_maintainer.d.ts +36 -0
  86. package/dist/src/wiki/wiki_maintainer.d.ts.map +1 -0
  87. package/dist/src/wiki/wiki_maintainer.js +38 -0
  88. package/dist/src/wiki/wiki_maintainer.js.map +1 -0
  89. package/dist/src/wiki/wiki_projector.d.ts +33 -0
  90. package/dist/src/wiki/wiki_projector.d.ts.map +1 -0
  91. package/dist/src/wiki/wiki_projector.js +633 -0
  92. package/dist/src/wiki/wiki_projector.js.map +1 -0
  93. package/dist/src/wiki/wiki_queue.d.ts +29 -0
  94. package/dist/src/wiki/wiki_queue.d.ts.map +1 -0
  95. package/dist/src/wiki/wiki_queue.js +137 -0
  96. package/dist/src/wiki/wiki_queue.js.map +1 -0
  97. package/openclaw.plugin.json +501 -16
  98. package/package.json +58 -7
  99. package/schema/graph.schema.yaml +330 -0
  100. package/scripts/cli.js +19 -14
  101. package/scripts/repair-memory.js +321 -0
  102. package/scripts/uninstall.js +22 -5
  103. package/skills/cortex-memory/SKILL.md +49 -0
  104. package/skills/cortex-memory/references/agent-manual.md +115 -0
  105. package/skills/cortex-memory/references/configuration.md +92 -0
  106. package/skills/cortex-memory/references/publish-checklist.md +46 -0
  107. package/skills/cortex-memory/references/system-prompt-template.md +27 -0
  108. package/skills/cortex-memory/references/tools.md +181 -0
  109. package/skills/cortex-memory/scripts/smoke-check.ps1 +56 -0
  110. package/index.ts +0 -2142
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 deki18
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,204 +1,297 @@
1
- # OpenClaw Cortex Memory
2
-
3
- OpenClaw 长期记忆插件,提供跨会话检索、事件存储、规则反思、增量同步与运行诊断能力。
4
- 可作为 OpenClaw 的 memory slot 直接接入,支持从历史会话持续沉淀可复用记忆。
5
-
6
- ## 功能特性
7
-
8
- | 特性 | 说明 |
9
- |------|------|
10
- | 语义检索 | `search_memory` 支持 query + top_k |
11
- | 事件存储 | `store_event` 将摘要写入归档 |
12
- | 上下文注入 | `get_hot_context` / `get_auto_context` |
13
- | 增量同步 | `sync_memory` 按状态文件增量导入 |
14
- | 规则演进 | `reflect_memory` 更新 `CORTEX_RULES.md` |
15
- | 运行诊断 | `diagnostics` 检查本地存储状态 |
16
-
17
- ## 安装
18
-
19
- ### 前置要求
20
-
21
- - Node.js 22+
22
- - OpenAI API Key(或其他兼容 API)
23
-
24
- ### 安装步骤
25
-
26
- 快速安装(推荐,npm 发布版):
27
-
28
- ```bash
29
- cd ~/openclaw
30
- pnpm openclaw plugins install openclaw-cortex-memory@alpha
31
- pnpm openclaw plugins enable openclaw-cortex-memory
32
- pnpm openclaw gateway restart
33
- ```
34
-
35
- 后续更新:
36
-
37
- ```bash
38
- cd ~/openclaw
39
- pnpm openclaw plugins install openclaw-cortex-memory@alpha
40
- pnpm openclaw gateway restart
41
- ```
42
-
43
- 安装前如果 `openclaw.json` 已经提前写了 `allow/slots/entries` 指向本插件,先临时移除,安装后再加回,避免安装前校验报 `plugin not found`。
44
-
45
- ### 本地打包安装(源码模式)
46
-
47
- ```bash
48
- git clone https://github.com/deki18/openclaw-cortex-memory.git ~/openclaw-cortex-memory-src
49
- cd ~/openclaw-cortex-memory-src
50
- npm install && npm run build && npm pack
51
- cd ~/openclaw
52
- pnpm openclaw plugins install ~/openclaw-cortex-memory-src/openclaw-cortex-memory-0.1.0-Alpha.1.tgz
53
- pnpm openclaw gateway restart
54
- ```
55
-
56
- ### 本地开发模式(无安装记录)
57
-
58
- ```bash
59
- cd ~/.openclaw/extensions
60
- git clone https://github.com/deki18/openclaw-cortex-memory.git
61
- cd openclaw-cortex-memory
62
- npm install
63
- ```
64
-
65
- `npm install` 会自动执行 TypeScript 构建并生成 `dist/`,但这种方式默认不写 OpenClaw 安装记录。
66
-
67
- ## 配置
68
-
69
- `openclaw.json` 中添加:
70
-
71
- ```json
72
- {
73
- "plugins": {
74
- "slots": { "memory": "openclaw-cortex-memory" },
75
- "entries": {
76
- "openclaw-cortex-memory": {
77
- "enabled": true,
78
- "config": {
79
- "engineMode": "ts",
80
- "dbPath": "<optional-memory-dir>",
81
- "autoSync": true,
82
- "autoReflect": true,
83
- "embedding": {
84
- "provider": "api",
85
- "model": "text-embedding-3-large",
86
- "apiKey": "${EMBEDDING_API_KEY}",
87
- "baseURL": "https://your-embedding-endpoint/v1",
88
- "dimensions": 3072
89
- },
90
- "llm": {
91
- "provider": "api",
92
- "model": "gpt-4",
93
- "apiKey": "${LLM_API_KEY}",
94
- "baseURL": "https://your-llm-endpoint/v1"
95
- },
96
- "reranker": {
97
- "provider": "api",
98
- "model": "BAAI/bge-reranker-v2-m3",
99
- "apiKey": "${RERANKER_API_KEY}",
100
- "baseURL": "https://your-reranker-endpoint/v1/rerank"
101
- }
102
- }
103
- }
104
- }
105
- }
106
- }
107
- ```
108
-
109
- ### 配置项说明
110
-
111
- | 配置项 | 必填 | 说明 |
112
- |--------|------|------|
113
- | `embedding.provider` | 是 | 建议使用 `api`(统一第三方接口模式) |
114
- | `embedding.model` | 是 | 嵌入模型名称 |
115
- | `embedding.dimensions` | 否 | 向量维度,需与模型匹配 |
116
- | `embedding.apiKey` | 是 | Embedding API Key(建议 `${EMBEDDING_API_KEY}`) |
117
- | `embedding.baseURL` | 是 | Embedding API 端点 |
118
- | `llm.provider` | 是 | 建议使用 `api` |
119
- | `llm.model` | 是 | LLM 模型名称 |
120
- | `llm.apiKey` | 是 | LLM API Key(建议 `${LLM_API_KEY}`) |
121
- | `llm.baseURL` | 是 | LLM API 端点 |
122
- | `reranker.provider` | 否 | 建议使用 `api` |
123
- | `reranker.model` | 是 | Reranker 模型名称 |
124
- | `reranker.apiKey` | 是 | Reranker API Key(建议 `${RERANKER_API_KEY}`) |
125
- | `reranker.baseURL` | | Reranker API 端点 |
126
- | `engineMode` | 否 | 固定 `ts` |
127
- | `dbPath` | 否 | 数据目录,默认 `<plugin-dir>/data/memory` |
128
- | `autoSync` | 否 | 会话结束时自动同步历史记录,默认 `true` |
129
- | `autoReflect` | 否 | 自动触发记忆反思,默认 `false` |
130
-
131
- ### 启动
132
-
133
- ```bash
134
- pnpm openclaw config validate
135
- pnpm openclaw gateway restart
136
- ```
137
-
138
- ### 主 Agent 注入说明
139
-
140
- 首次接入后,建议把下面这段发给主 Agent,确保其按记忆工作流执行:
141
-
142
- ```text
143
- 你已接入 Cortex Memory。请遵循以下规则:
144
- 1) 当用户询问历史对话、偏好、项目上下文时,先调用 search_memory 再回答。
145
- 2) 需要当前会话热上下文时调用 get_hot_context。
146
- 3) 需要自动召回相关记忆时调用 get_auto_context。
147
- 4) 在一件重要事情结束并形成明确结果后,再调用 store_event 记录(不要在过程进行中频繁记录)。
148
- 5) 需要实体关联关系时调用 query_graph。
149
- 6) 当任务经历“失败→调整→最终成功”时,优先用 store_event 记录失败原因与成功方案,再调用 reflect_memory 沉淀可复用规则。
150
- 7) 需要导入历史会话时调用 sync_memory。
151
- 8) 出现配置校验失败、记忆读写异常、检索结果异常或数据目录问题时,优先调用 diagnostics。
152
- 9) 同一任务内不要反复调用 store_event 或 reflect_memory;仅在关键节点或任务收尾时触发一次。
153
- 10) 不要臆造历史事实;无法确认时必须先检索。
154
- ```
155
-
156
- ## 可用工具
157
-
158
- | 工具 | 说明 |
159
- |------|------|
160
- | `search_memory` | 语义搜索记忆库,支持 top_k 参数 |
161
- | `store_event` | 存储事件,可包含实体和关系 |
162
- | `query_graph` | 查询实体关系图谱 |
163
- | `get_hot_context` | 获取热上下文(CORTEX_RULES.md + 近期会话) |
164
- | `get_auto_context` | 自动检索相关记忆 + 热上下文 |
165
- | `reflect_memory` | 触发记忆反思,将事件转化为规则 |
166
- | `sync_memory` | 同步 OpenClaw 历史会话(增量) |
167
- | `delete_memory` | 删除指定记忆 |
168
- | `diagnostics` | 系统诊断 |
169
-
170
- ## CLI 命令
171
-
172
- CLI 命令需在插件目录运行:
173
-
174
- ```bash
175
- npx cortex-memory status # 查看插件状态
176
- npx cortex-memory enable # 启用插件
177
- npx cortex-memory disable # 禁用插件(回退到内置记忆)
178
- npx cortex-memory uninstall # 卸载插件
179
- npx cortex-memory uninstall --keep-data # 卸载但保留数据
180
- npx cortex-memory help # 查看命令帮助
181
- ```
182
-
183
- ## 数据存储
184
-
185
- | 路径 | 说明 |
186
- |------|------|
187
- | `<dbPath>/MEMORY.md` | 记忆说明 |
188
- | `<dbPath>/CORTEX_RULES.md` | 规则文件 |
189
- | `<dbPath>/sessions/active/sessions.jsonl` | 活跃会话 |
190
- | `<dbPath>/sessions/archive/sessions.jsonl` | 归档事件 |
191
- | `<dbPath>/.sync_state.json` | 同步增量状态 |
192
- | `<dbPath>/.session_end_state.json` | session_end 幂等状态 |
193
- | `<dbPath>/.rule_store_state.json` | 规则去重状态 |
194
-
195
- ## 注意事项
196
-
197
- 1. **API Key 安全**:使用环境变量 `${OPENAI_API_KEY}` 而非硬编码
198
- 2. **向量维度**:必须与嵌入模型匹配,如 `text-embedding-3-large` 为 3072
199
- 3. **重排序**:可选配置 `reranker` 以提升检索精度
200
- 4. **单栈运行**:当前版本为纯 TS,无 Python 运行时依赖
201
-
202
- ## 许可证
203
-
1
+ # OpenClaw Cortex Memory
2
+
3
+ OpenClaw 长期记忆插件 - 专为 OpenClaw AI 助手设计的智能记忆系统
4
+
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
6
+ [![Node.js: 22+](https://img.shields.io/badge/Node.js-22+-green.svg)](https://nodejs.org/)
7
+ [![OpenClaw: Plugin](https://img.shields.io/badge/OpenClaw-Plugin-orange.svg)](https://github.com/openclaw)
8
+
9
+ 面向 OpenClaw 的长期记忆插件,集成多路检索、事件归档、图谱关系、向量化与反衰减排序,支持历史增量导入、规则反思和可观测诊断,帮助 Agent 在跨会话中持续积累并稳定调用高价值记忆。
10
+
11
+ ---
12
+
13
+ ## 核心能力
14
+
15
+ ### 1) 语义检索
16
+ - 多路召回:`keyword / BM25 / vector / graph` 混合检索
17
+ - 排序融合:加权打分 + RRF + 可选 reranker
18
+ - 结果融合:可选 `readFusion`,支持权威融合返回
19
+ - 时序建模:`memoryDecay` + 命中反衰减(anti-decay)
20
+
21
+ ### 2) 事件存储
22
+ - 分层写入:`active`(会话)与 `archive`(结构化事件)
23
+ - 摘要优先:归档记录保留 `summary` 与 `source_text`
24
+ - 向量分块:支持 summary/evidence 双通道向量记录
25
+ - 增量同步:按状态文件增量导入历史会话
26
+
27
+ ### 3) 图谱关系
28
+ - 图谱独立层:`graph/memory.jsonl` 独立于 archive 文本层
29
+ - 关系追溯:每条关系可追溯 `source_event_id`
30
+ - 关系查询:`query_graph` 支持方向、关系类型、路径搜索
31
+ - 冲突治理:单值事实冲突进入队列,支持人工 `accept/reject` 闭环
32
+ - 可视化导出:`export_graph_view` 输出状态化图谱快照(含来源证据)
33
+ - 质量门禁:`graphQualityMode` 支持 `off/warn/strict`
34
+
35
+ ### 4) 规则演进
36
+ - 反思沉淀:`reflect_memory` 将事件抽象为规则
37
+ - 去重治理:规则与事件均有去重控制,避免污染
38
+ - 规则复用:规则写入 `CORTEX_RULES.md` 供后续任务复用
39
+
40
+ ### 5) 运维诊断
41
+ - `diagnostics`:模型连通、层级状态、字段对齐检查
42
+ - `backfill_embeddings`:支持 `incremental / vector_only / full`
43
+ - `lint_memory_wiki`:Wiki/图谱一致性巡检与修复建议
44
+ - 完整状态文件:便于快速定位同步、回填、质量问题
45
+
46
+ ---
47
+
48
+ ## 已注册工具(与当前代码一致)
49
+
50
+ - `search_memory`
51
+ - `store_event`
52
+ - `query_graph`
53
+ - `export_graph_view`
54
+ - `lint_memory_wiki`
55
+ - `list_graph_conflicts`
56
+ - `resolve_graph_conflict`
57
+ - `get_hot_context`
58
+ - `get_auto_context`
59
+ - `reflect_memory`
60
+ - `sync_memory`
61
+ - `backfill_embeddings`
62
+ - `delete_memory`
63
+ - `diagnostics`
64
+
65
+ ### 工具参数速览
66
+
67
+ | 工具 | 关键参数 |
68
+ |------|------|
69
+ | `search_memory` | `query`, `top_k` |
70
+ | `store_event` | `summary`, `entities`, `entity_types`, `outcome`, `relations` |
71
+ | `query_graph` | `entity`, `rel`, `dir`, `path_to`, `max_depth` |
72
+ | `export_graph_view` | `write_snapshot` |
73
+ | `lint_memory_wiki` | 无 |
74
+ | `list_graph_conflicts` | `status`, `limit` |
75
+ | `resolve_graph_conflict` | `conflict_id`, `action`, `note` |
76
+ | `get_hot_context` | `limit` |
77
+ | `get_auto_context` | `include_hot` |
78
+ | `reflect_memory` | 无 |
79
+ | `sync_memory` | 无 |
80
+ | `backfill_embeddings` | `layer`, `batch_size`, `max_retries`, `retry_failed_only`, `rebuild_mode` |
81
+ | `diagnostics` | 无 |
82
+ | `delete_memory` | `memory_id` |
83
+
84
+ ---
85
+
86
+ ## Agent 使用手册(系统提示词)
87
+
88
+ > 可直接粘贴到 Agent 的系统提示词中使用
89
+
90
+ **Cortex Memory 记忆插件使用规则(核心规则,不允许删除)**
91
+
92
+ 你已接入 Cortex Memory。必须遵循以下规则:
93
+
94
+ 1. 禁止臆造历史事实;凡涉及历史对话、用户偏好、项目既有决策,先检索再回答。
95
+ 2. 单个任务内避免重复写入:`store_event` / `reflect_memory` 仅在关键节点或收尾触发一次。
96
+ 3. 用户询问历史信息、偏好、项目上下文时:先调用 `search_memory`,再回答。
97
+ 4. 需要当前会话热上下文时:调用 `get_hot_context`。
98
+ 5. 需要自动召回相关记忆时:调用 `get_auto_context`。
99
+ 6. 需要实体关系、依赖链路或路径关系时:调用 `query_graph`。
100
+ 7. 仅在“重要事项已结束且结论明确”后调用 `store_event` 记录结果(过程进行中不频繁记录)。
101
+ 8. 当任务经历“失败 -> 调整 -> 成功”时:先用 `store_event` 记录失败原因与成功方案,再调用 `reflect_memory` 沉淀可复用规则。
102
+ 9. 需要导入历史会话时:调用 `sync_memory`。
103
+ 10. 当 `diagnostics` 显示 active/archive 有未向量化记录,或迁移后需重建向量层时:调用 `backfill_embeddings`(按需选择 `incremental` / `vector_only` / `full`)。
104
+ 11. 出现配置校验失败、记忆读写异常、检索结果异常或数据目录问题时:优先调用 `diagnostics`。
105
+ 12. 仅在用户明确要求删除记忆,且已确认 `memory_id` 时,才调用 `delete_memory`;禁止在未确认情况下自动删除。
106
+ 13. 任一工具调用失败时,先重试一次;仍失败则明确告知用户,并基于当前可得上下文继续完成任务。
107
+ 14. 调用任意 Cortex Memory 工具前,先确认当前运行环境可见该工具;若工具不可见,必须立即报告“当前 lane 不可用”,不得虚构执行结果。
108
+ 15. `sync_memory` 属于关键路径任务:执行前后应避免并发重复触发;若已有同任务进行中,复用当前结果或等待完成。
109
+ 16. 当用户明确请求 Cortex Memory 任务(如 `sync_memory` / `search_memory` / `store_event`)时,禁止切换到无关流程(如心跳巡检、日报、闲聊任务);若被系统任务打断,先完成用户请求再处理后台任务。
110
+ 17. 当 `query_graph` 返回 `conflict_hint` 时,不得静默覆盖冲突事实;应先调用 `list_graph_conflicts`,并与用户确认后再 `resolve_graph_conflict`。
111
+ 18. 需要解释图谱状态分布或排查投影异常时,优先调用 `export_graph_view` `lint_memory_wiki`。
112
+
113
+ ---
114
+
115
+ ## 快速开始
116
+
117
+ ### 安装
118
+
119
+ ```bash
120
+ cd ~/openclaw
121
+ openclaw plugins install clawhub:openclaw-cortex-memory
122
+ openclaw plugins enable openclaw-cortex-memory
123
+ ```
124
+
125
+ 如果 `clawhub:` 安装出现 `fetch failed`,可改用 npm 包本地安装(推荐兜底):
126
+
127
+ ```bash
128
+ npm pack openclaw-cortex-memory@0.1.0-Alpha.30
129
+ openclaw plugins install ./openclaw-cortex-memory-0.1.0-Alpha.30.tgz
130
+ openclaw plugins enable openclaw-cortex-memory
131
+ rm ./openclaw-cortex-memory-0.1.0-Alpha.30.tgz
132
+ ```
133
+
134
+ 完成安装后,请先按下方“最小配置”示例配置 `openclaw.json`,确认配置无误后再启动 gateway。
135
+
136
+ ### 更新
137
+
138
+ ```bash
139
+ rm -r ~/.openclaw/extensions/openclaw-cortex-memory
140
+ npm pack openclaw-cortex-memory@0.1.0-Alpha.30
141
+ openclaw plugins install ./openclaw-cortex-memory-0.1.0-Alpha.30.tgz
142
+ openclaw plugins enable openclaw-cortex-memory
143
+ rm ./openclaw-cortex-memory-0.1.0-Alpha.30.tgz
144
+ openclaw plugins list --enabled
145
+ openclaw gateway restart
146
+ ```
147
+
148
+ ### 卸载
149
+
150
+ ```bash
151
+ cd ~/openclaw
152
+ openclaw plugins disable openclaw-cortex-memory
153
+ openclaw plugins uninstall openclaw-cortex-memory
154
+ ```
155
+
156
+ 如需卸载插件但保留记忆数据:
157
+
158
+ ```bash
159
+ cd ~/openclaw
160
+ openclaw plugins disable openclaw-cortex-memory
161
+ openclaw plugins uninstall openclaw-cortex-memory --keep-data
162
+ ```
163
+
164
+ ### 最小配置(推荐先跑起来)
165
+
166
+ ```json
167
+ {
168
+ "plugins": {
169
+ "allow": ["openclaw-cortex-memory"],
170
+ "slots": { "memory": "none" },
171
+ "entries": {
172
+ "openclaw-cortex-memory": {
173
+ "enabled": true,
174
+ "config": {
175
+ "autoSync": true,
176
+ "autoReflect": false,
177
+ "graphQualityMode": "warn",
178
+ "wikiProjection": {
179
+ "enabled": true,
180
+ "mode": "incremental",
181
+ "maxBatch": 100
182
+ },
183
+ "embedding": {
184
+ "provider": "api",
185
+ "model": "text-embedding-3-large",
186
+ "apiKey": "${EMBEDDING_API_KEY}",
187
+ "baseURL": "https://your-embedding-endpoint/v1",
188
+ "dimensions": 3072
189
+ },
190
+ "llm": {
191
+ "provider": "api",
192
+ "model": "gpt-4",
193
+ "apiKey": "${LLM_API_KEY}",
194
+ "baseURL": "https://your-llm-endpoint/v1"
195
+ },
196
+ "reranker": {
197
+ "provider": "api",
198
+ "model": "BAAI/bge-reranker-v2-m3",
199
+ "apiKey": "${RERANKER_API_KEY}",
200
+ "baseURL": "https://your-reranker-endpoint/v1/rerank"
201
+ }
202
+ }
203
+ }
204
+ }
205
+ }
206
+ }
207
+ ```
208
+
209
+ ## 外部端点与凭证声明(审查说明)
210
+
211
+ 本插件是本地长期记忆系统,但以下能力依赖用户自配置的外部模型端点:
212
+
213
+ - `embedding`:向量化(`/embeddings`)
214
+ - `llm`:写入门控、规则反思、读融合(`/chat/completions`)
215
+ - `reranker`:候选重排序(`/rerank`)
216
+
217
+ 对应凭证要求:
218
+
219
+ - 环境变量(可选):`EMBEDDING_API_KEY`、`LLM_API_KEY`、`RERANKER_API_KEY`
220
+ - 插件配置(常用):`embedding.apiKey`、`llm.apiKey`、`reranker.apiKey`
221
+ - 端点配置:`embedding.baseURL`、`llm.baseURL`、`reranker.baseURL`
222
+
223
+ ### 网络发送的数据边界
224
+
225
+ - 会发送:用于模型推理的文本片段(如 query、候选摘要、转写片段、待向量化文本)
226
+ - 不会主动发送:本地配置文件原文、系统环境变量全集、插件状态文件全集
227
+ - 凭证使用方式:仅作为 `Authorization: Bearer` 请求头调用你配置的端点
228
+
229
+ ### 风险与建议
230
+
231
+ - 你应只配置可信模型网关,密钥权限最小化(建议专用 key)
232
+ - 生产环境建议启用网关审计与请求日志脱敏
233
+ - 如不希望联网推理,不要配置外部端点/密钥(相关能力将降级或跳过)
234
+
235
+ <details>
236
+ <summary>高级配置(默认已内置,不懂可以不改)</summary>
237
+
238
+ - `readFusion`:融合候选数、通道权重、通道 TopK、最小 lexical/semantic 命中、长度归一
239
+ - `memoryDecay`:最小衰减地板、默认半衰期、事件类型半衰期、anti-decay 参数
240
+ - `vectorChunking`:分块大小、重叠、evidence 最大分块数
241
+ - `writePolicy`:archive/active 质量阈值与文本长度限制
242
+ - `readTuning`:打分权重、RRF 参数、recency 分桶、auto-context 轻量检索
243
+
244
+ </details>
245
+
246
+ ---
247
+
248
+ ## 数据目录
249
+
250
+ 默认情况下(未配置 `dbPath`),数据目录为 OpenClaw workspace 下:
251
+
252
+ - Linux/macOS: `~/.openclaw/workspace/memory/openclaw-cortex-memory`
253
+ - Windows: `%USERPROFILE%\\.openclaw\\workspace\\memory\\openclaw-cortex-memory`
254
+
255
+ 如果当前进程无法识别 OpenClaw 基础目录(例如离线脚本直接运行且无相关环境变量),会回退到项目目录:
256
+
257
+ - `<projectRoot>/data/memory`
258
+
259
+ 如果在插件配置里设置了 `dbPath`,则以下文件都会写到你指定的 `dbPath` 下:
260
+
261
+ - `<memoryRoot>/MEMORY.md`
262
+ - `<memoryRoot>/CORTEX_RULES.md`
263
+ - `<memoryRoot>/sessions/active/sessions.jsonl`
264
+ - `<memoryRoot>/sessions/archive/sessions.jsonl`
265
+ - `<memoryRoot>/graph/memory.jsonl`
266
+ - `<memoryRoot>/graph/mutation_log.jsonl`
267
+ - `<memoryRoot>/graph/conflict_queue.jsonl`
268
+ - `<memoryRoot>/graph/superseded_relations.jsonl`
269
+ - `<memoryRoot>/wiki/index.md`
270
+ - `<memoryRoot>/wiki/log.md`
271
+ - `<memoryRoot>/wiki/entities/*.md`
272
+ - `<memoryRoot>/wiki/topics/*.md`
273
+ - `<memoryRoot>/wiki/graph/view.json`
274
+ - `<memoryRoot>/wiki/graph/timeline.jsonl`
275
+ - `<memoryRoot>/wiki/.projection_index.json`
276
+ - `<memoryRoot>/wiki/.rebuild_queue.jsonl`
277
+ - `<memoryRoot>/vector/lancedb`
278
+ - `<memoryRoot>/vector/lancedb_events.jsonl`
279
+ - `<memoryRoot>/.sync_state.json`
280
+ - `<memoryRoot>/.session_end_state.json`
281
+ - `<memoryRoot>/.rule_store_state.json`
282
+ - `<memoryRoot>/.dedup_index.json`
283
+ - `<memoryRoot>/.read_hit_stats.json`
284
+
285
+ ---
286
+
287
+ ## 常用命令
288
+
289
+ ```bash
290
+ npm run typecheck
291
+ npm run test:graph-quality
292
+ npm run test:graph-quality-zh
293
+ ```
294
+
295
+ ---
296
+
204
297
  MIT License
package/SIGNATURE.md ADDED
@@ -0,0 +1,7 @@
1
+ # Publisher Signature
2
+
3
+ - Maintainer: deki18
4
+ - Repository: https://github.com/deki18/openclaw-cortex-memory
5
+ - npm Package: https://www.npmjs.com/package/openclaw-cortex-memory
6
+ - ClawHub ID: openclaw-cortex-memory
7
+ - Signature Intent: This repository and published artifacts are maintained and released by deki18.