@mnemoai/core 1.1.0 → 1.1.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.
Files changed (220) hide show
  1. package/dist/cli.d.ts +2 -0
  2. package/dist/cli.d.ts.map +1 -0
  3. package/dist/cli.js +7 -0
  4. package/dist/cli.js.map +7 -0
  5. package/dist/index.d.ts +136 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/{index.ts → dist/index.js} +537 -1333
  8. package/dist/index.js.map +7 -0
  9. package/dist/src/access-tracker.d.ts +97 -0
  10. package/dist/src/access-tracker.d.ts.map +1 -0
  11. package/dist/src/access-tracker.js +184 -0
  12. package/dist/src/access-tracker.js.map +7 -0
  13. package/dist/src/adapters/chroma.d.ts +31 -0
  14. package/dist/src/adapters/chroma.d.ts.map +1 -0
  15. package/{src/adapters/chroma.ts → dist/src/adapters/chroma.js} +45 -107
  16. package/dist/src/adapters/chroma.js.map +7 -0
  17. package/dist/src/adapters/lancedb.d.ts +29 -0
  18. package/dist/src/adapters/lancedb.d.ts.map +1 -0
  19. package/{src/adapters/lancedb.ts → dist/src/adapters/lancedb.js} +41 -109
  20. package/dist/src/adapters/lancedb.js.map +7 -0
  21. package/dist/src/adapters/pgvector.d.ts +33 -0
  22. package/dist/src/adapters/pgvector.d.ts.map +1 -0
  23. package/{src/adapters/pgvector.ts → dist/src/adapters/pgvector.js} +42 -104
  24. package/dist/src/adapters/pgvector.js.map +7 -0
  25. package/dist/src/adapters/qdrant.d.ts +34 -0
  26. package/dist/src/adapters/qdrant.d.ts.map +1 -0
  27. package/dist/src/adapters/qdrant.js +132 -0
  28. package/dist/src/adapters/qdrant.js.map +7 -0
  29. package/dist/src/adaptive-retrieval.d.ts +14 -0
  30. package/dist/src/adaptive-retrieval.d.ts.map +1 -0
  31. package/dist/src/adaptive-retrieval.js +52 -0
  32. package/dist/src/adaptive-retrieval.js.map +7 -0
  33. package/dist/src/audit-log.d.ts +56 -0
  34. package/dist/src/audit-log.d.ts.map +1 -0
  35. package/dist/src/audit-log.js +139 -0
  36. package/dist/src/audit-log.js.map +7 -0
  37. package/dist/src/chunker.d.ts +45 -0
  38. package/dist/src/chunker.d.ts.map +1 -0
  39. package/dist/src/chunker.js +157 -0
  40. package/dist/src/chunker.js.map +7 -0
  41. package/dist/src/config.d.ts +70 -0
  42. package/dist/src/config.d.ts.map +1 -0
  43. package/dist/src/config.js +142 -0
  44. package/dist/src/config.js.map +7 -0
  45. package/dist/src/decay-engine.d.ts +73 -0
  46. package/dist/src/decay-engine.d.ts.map +1 -0
  47. package/dist/src/decay-engine.js +119 -0
  48. package/dist/src/decay-engine.js.map +7 -0
  49. package/dist/src/embedder.d.ts +94 -0
  50. package/dist/src/embedder.d.ts.map +1 -0
  51. package/{src/embedder.ts → dist/src/embedder.js} +119 -317
  52. package/dist/src/embedder.js.map +7 -0
  53. package/dist/src/extraction-prompts.d.ts +12 -0
  54. package/dist/src/extraction-prompts.d.ts.map +1 -0
  55. package/dist/src/extraction-prompts.js +311 -0
  56. package/dist/src/extraction-prompts.js.map +7 -0
  57. package/dist/src/license.d.ts +29 -0
  58. package/dist/src/license.d.ts.map +1 -0
  59. package/{src/license.ts → dist/src/license.js} +42 -113
  60. package/dist/src/license.js.map +7 -0
  61. package/dist/src/llm-client.d.ts +23 -0
  62. package/dist/src/llm-client.d.ts.map +1 -0
  63. package/{src/llm-client.ts → dist/src/llm-client.js} +22 -55
  64. package/dist/src/llm-client.js.map +7 -0
  65. package/dist/src/logger.d.ts +33 -0
  66. package/dist/src/logger.d.ts.map +1 -0
  67. package/dist/src/logger.js +35 -0
  68. package/dist/src/logger.js.map +7 -0
  69. package/dist/src/mcp-server.d.ts +16 -0
  70. package/dist/src/mcp-server.d.ts.map +1 -0
  71. package/{src/mcp-server.ts → dist/src/mcp-server.js} +81 -181
  72. package/dist/src/mcp-server.js.map +7 -0
  73. package/dist/src/memory-categories.d.ts +40 -0
  74. package/dist/src/memory-categories.d.ts.map +1 -0
  75. package/dist/src/memory-categories.js +33 -0
  76. package/dist/src/memory-categories.js.map +7 -0
  77. package/dist/src/memory-upgrader.d.ts +71 -0
  78. package/dist/src/memory-upgrader.d.ts.map +1 -0
  79. package/dist/src/memory-upgrader.js +238 -0
  80. package/dist/src/memory-upgrader.js.map +7 -0
  81. package/dist/src/migrate.d.ts +47 -0
  82. package/dist/src/migrate.d.ts.map +1 -0
  83. package/{src/migrate.ts → dist/src/migrate.js} +57 -165
  84. package/dist/src/migrate.js.map +7 -0
  85. package/dist/src/mnemo.d.ts +67 -0
  86. package/dist/src/mnemo.d.ts.map +1 -0
  87. package/dist/src/mnemo.js +66 -0
  88. package/dist/src/mnemo.js.map +7 -0
  89. package/dist/src/noise-filter.d.ts +23 -0
  90. package/dist/src/noise-filter.d.ts.map +1 -0
  91. package/dist/src/noise-filter.js +62 -0
  92. package/dist/src/noise-filter.js.map +7 -0
  93. package/dist/src/noise-prototypes.d.ts +40 -0
  94. package/dist/src/noise-prototypes.d.ts.map +1 -0
  95. package/dist/src/noise-prototypes.js +116 -0
  96. package/dist/src/noise-prototypes.js.map +7 -0
  97. package/dist/src/observability.d.ts +16 -0
  98. package/dist/src/observability.d.ts.map +1 -0
  99. package/dist/src/observability.js +53 -0
  100. package/dist/src/observability.js.map +7 -0
  101. package/dist/src/query-tracker.d.ts +27 -0
  102. package/dist/src/query-tracker.d.ts.map +1 -0
  103. package/dist/src/query-tracker.js +32 -0
  104. package/dist/src/query-tracker.js.map +7 -0
  105. package/dist/src/reflection-event-store.d.ts +44 -0
  106. package/dist/src/reflection-event-store.d.ts.map +1 -0
  107. package/dist/src/reflection-event-store.js +50 -0
  108. package/dist/src/reflection-event-store.js.map +7 -0
  109. package/dist/src/reflection-item-store.d.ts +58 -0
  110. package/dist/src/reflection-item-store.d.ts.map +1 -0
  111. package/dist/src/reflection-item-store.js +69 -0
  112. package/dist/src/reflection-item-store.js.map +7 -0
  113. package/dist/src/reflection-mapped-metadata.d.ts +47 -0
  114. package/dist/src/reflection-mapped-metadata.d.ts.map +1 -0
  115. package/dist/src/reflection-mapped-metadata.js +40 -0
  116. package/dist/src/reflection-mapped-metadata.js.map +7 -0
  117. package/dist/src/reflection-metadata.d.ts +11 -0
  118. package/dist/src/reflection-metadata.d.ts.map +1 -0
  119. package/dist/src/reflection-metadata.js +24 -0
  120. package/dist/src/reflection-metadata.js.map +7 -0
  121. package/dist/src/reflection-ranking.d.ts +13 -0
  122. package/dist/src/reflection-ranking.d.ts.map +1 -0
  123. package/{src/reflection-ranking.ts → dist/src/reflection-ranking.js} +12 -21
  124. package/dist/src/reflection-ranking.js.map +7 -0
  125. package/dist/src/reflection-retry.d.ts +30 -0
  126. package/dist/src/reflection-retry.d.ts.map +1 -0
  127. package/{src/reflection-retry.ts → dist/src/reflection-retry.js} +24 -64
  128. package/dist/src/reflection-retry.js.map +7 -0
  129. package/dist/src/reflection-slices.d.ts +42 -0
  130. package/dist/src/reflection-slices.d.ts.map +1 -0
  131. package/{src/reflection-slices.ts → dist/src/reflection-slices.js} +60 -136
  132. package/dist/src/reflection-slices.js.map +7 -0
  133. package/dist/src/reflection-store.d.ts +85 -0
  134. package/dist/src/reflection-store.d.ts.map +1 -0
  135. package/dist/src/reflection-store.js +407 -0
  136. package/dist/src/reflection-store.js.map +7 -0
  137. package/dist/src/resonance-state.d.ts +19 -0
  138. package/dist/src/resonance-state.d.ts.map +1 -0
  139. package/{src/resonance-state.ts → dist/src/resonance-state.js} +13 -42
  140. package/dist/src/resonance-state.js.map +7 -0
  141. package/dist/src/retriever.d.ts +228 -0
  142. package/dist/src/retriever.d.ts.map +1 -0
  143. package/dist/src/retriever.js +1006 -0
  144. package/dist/src/retriever.js.map +7 -0
  145. package/dist/src/scopes.d.ts +58 -0
  146. package/dist/src/scopes.d.ts.map +1 -0
  147. package/dist/src/scopes.js +252 -0
  148. package/dist/src/scopes.js.map +7 -0
  149. package/dist/src/self-improvement-files.d.ts +20 -0
  150. package/dist/src/self-improvement-files.d.ts.map +1 -0
  151. package/{src/self-improvement-files.ts → dist/src/self-improvement-files.js} +24 -49
  152. package/dist/src/self-improvement-files.js.map +7 -0
  153. package/dist/src/semantic-gate.d.ts +24 -0
  154. package/dist/src/semantic-gate.d.ts.map +1 -0
  155. package/dist/src/semantic-gate.js +86 -0
  156. package/dist/src/semantic-gate.js.map +7 -0
  157. package/dist/src/session-recovery.d.ts +9 -0
  158. package/dist/src/session-recovery.d.ts.map +1 -0
  159. package/{src/session-recovery.ts → dist/src/session-recovery.js} +40 -57
  160. package/dist/src/session-recovery.js.map +7 -0
  161. package/dist/src/smart-extractor.d.ts +107 -0
  162. package/dist/src/smart-extractor.d.ts.map +1 -0
  163. package/{src/smart-extractor.ts → dist/src/smart-extractor.js} +130 -383
  164. package/dist/src/smart-extractor.js.map +7 -0
  165. package/dist/src/smart-metadata.d.ts +103 -0
  166. package/dist/src/smart-metadata.d.ts.map +1 -0
  167. package/dist/src/smart-metadata.js +361 -0
  168. package/dist/src/smart-metadata.js.map +7 -0
  169. package/dist/src/storage-adapter.d.ts +102 -0
  170. package/dist/src/storage-adapter.d.ts.map +1 -0
  171. package/dist/src/storage-adapter.js +22 -0
  172. package/dist/src/storage-adapter.js.map +7 -0
  173. package/dist/src/store.d.ts +108 -0
  174. package/dist/src/store.d.ts.map +1 -0
  175. package/dist/src/store.js +939 -0
  176. package/dist/src/store.js.map +7 -0
  177. package/dist/src/tier-manager.d.ts +57 -0
  178. package/dist/src/tier-manager.d.ts.map +1 -0
  179. package/dist/src/tier-manager.js +80 -0
  180. package/dist/src/tier-manager.js.map +7 -0
  181. package/dist/src/tools.d.ts +43 -0
  182. package/dist/src/tools.d.ts.map +1 -0
  183. package/dist/src/tools.js +1075 -0
  184. package/dist/src/tools.js.map +7 -0
  185. package/dist/src/wal-recovery.d.ts +30 -0
  186. package/dist/src/wal-recovery.d.ts.map +1 -0
  187. package/{src/wal-recovery.ts → dist/src/wal-recovery.js} +26 -79
  188. package/dist/src/wal-recovery.js.map +7 -0
  189. package/package.json +21 -2
  190. package/openclaw.plugin.json +0 -815
  191. package/src/access-tracker.ts +0 -341
  192. package/src/adapters/README.md +0 -78
  193. package/src/adapters/qdrant.ts +0 -191
  194. package/src/adaptive-retrieval.ts +0 -90
  195. package/src/audit-log.ts +0 -238
  196. package/src/chunker.ts +0 -254
  197. package/src/config.ts +0 -271
  198. package/src/decay-engine.ts +0 -238
  199. package/src/extraction-prompts.ts +0 -339
  200. package/src/memory-categories.ts +0 -71
  201. package/src/memory-upgrader.ts +0 -388
  202. package/src/mnemo.ts +0 -142
  203. package/src/noise-filter.ts +0 -97
  204. package/src/noise-prototypes.ts +0 -164
  205. package/src/observability.ts +0 -81
  206. package/src/query-tracker.ts +0 -57
  207. package/src/reflection-event-store.ts +0 -98
  208. package/src/reflection-item-store.ts +0 -112
  209. package/src/reflection-mapped-metadata.ts +0 -84
  210. package/src/reflection-metadata.ts +0 -23
  211. package/src/reflection-store.ts +0 -602
  212. package/src/retriever.ts +0 -1510
  213. package/src/scopes.ts +0 -375
  214. package/src/semantic-gate.ts +0 -121
  215. package/src/smart-metadata.ts +0 -561
  216. package/src/storage-adapter.ts +0 -153
  217. package/src/store.ts +0 -1330
  218. package/src/tier-manager.ts +0 -189
  219. package/src/tools.ts +0 -1292
  220. package/test/core.test.mjs +0 -301
@@ -1,339 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- /**
3
- * Prompt templates for intelligent memory extraction.
4
- * Three mandatory prompts:
5
- * - buildExtractionPrompt: 6-category L0/L1/L2 extraction with few-shot
6
- * - buildDedupPrompt: CREATE/MERGE/SKIP dedup decision
7
- * - buildMergePrompt: Memory merge with three-level structure
8
- */
9
-
10
- export function buildExtractionPrompt(
11
- conversationText: string,
12
- user: string,
13
- ): string {
14
- return `Analyze the following session context and extract memories worth long-term preservation.
15
-
16
- User: ${user}
17
-
18
- Target Output Language: auto (detect from recent messages)
19
-
20
- ## Recent Conversation
21
- ${conversationText}
22
-
23
- # Memory Extraction Criteria
24
-
25
- ## What is worth remembering?
26
- - Personalized information: Information specific to this user, not general domain knowledge
27
- - Long-term validity: Information that will still be useful in future sessions
28
- - Specific and clear: Has concrete details, not vague generalizations
29
-
30
- ## What is NOT worth remembering?
31
- - General knowledge that anyone would know
32
- - Temporary information: One-time questions or conversations
33
- - Vague information: "User has questions about a feature" (no specific details)
34
- - Tool output, error logs, or boilerplate
35
- - Recall queries / meta-questions: "Do you remember X?", "你还记得X吗?", "你知道我喜欢什么吗" — these are retrieval requests, NOT new information to store
36
- - Degraded or incomplete references: If the user mentions something vaguely ("that thing I said"), do NOT invent details or create a hollow memory
37
-
38
- # Memory Classification
39
-
40
- ## Core Decision Logic
41
-
42
- | Question | Answer | Category |
43
- |----------|--------|----------|
44
- | Who is the user? | Identity, attributes | profile |
45
- | What does the user prefer? | Preferences, habits | preferences |
46
- | What is this thing? | Person, project, organization | entities |
47
- | What happened? | Decision, milestone | events |
48
- | How was it solved? | Problem + solution | cases |
49
- | What is the process? | Reusable steps | patterns |
50
-
51
- ## Precise Definition
52
-
53
- **profile** - User identity (static attributes). Test: "User is..."
54
- **preferences** - User preferences (tendencies). Test: "User prefers/likes..."
55
- **entities** - Continuously existing nouns. Test: "XXX's state is..."
56
- **events** - Things that happened. Test: "XXX did/completed..."
57
- **cases** - Problem + solution pairs. Test: Contains "problem -> solution"
58
- **patterns** - Reusable processes. Test: Can be used in "similar situations"
59
-
60
- ## Common Confusion
61
- - "Plan to do X" -> events (action, not entity)
62
- - "Project X status: Y" -> entities (describes entity)
63
- - "User prefers X" -> preferences (not profile)
64
- - "Encountered problem A, used solution B" -> cases (not events)
65
- - "General process for handling certain problems" -> patterns (not cases)
66
-
67
- # Three-Level Structure
68
-
69
- Each memory contains three levels:
70
-
71
- **abstract (L0)**: One-liner index
72
- - Merge types (preferences/entities/profile/patterns): \`[Merge key]: [Description]\`
73
- - Independent types (events/cases): Specific description
74
-
75
- **overview (L1)**: Structured Markdown summary with category-specific headings
76
-
77
- **content (L2)**: Full narrative with background and details
78
-
79
- # Few-shot Examples
80
-
81
- ## profile
82
- \`\`\`json
83
- {
84
- "category": "profile",
85
- "abstract": "User basic info: AI development engineer, 3 years LLM experience",
86
- "overview": "## Background\\n- Occupation: AI development engineer\\n- Experience: 3 years LLM development\\n- Tech stack: Python, LangChain",
87
- "content": "User is an AI development engineer with 3 years of LLM application development experience."
88
- }
89
- \`\`\`
90
-
91
- ## preferences
92
- \`\`\`json
93
- {
94
- "category": "preferences",
95
- "abstract": "Python code style: No type hints, concise and direct",
96
- "overview": "## Preference Domain\\n- Language: Python\\n- Topic: Code style\\n\\n## Details\\n- No type hints\\n- Concise function comments\\n- Direct implementation",
97
- "content": "User prefers Python code without type hints, with concise function comments."
98
- }
99
- \`\`\`
100
-
101
- ## cases
102
- \`\`\`json
103
- {
104
- "category": "cases",
105
- "abstract": "LanceDB BigInt error -> Use Number() coercion before arithmetic",
106
- "overview": "## Problem\\nLanceDB 0.26+ returns BigInt for numeric columns\\n\\n## Solution\\nCoerce values with Number(...) before arithmetic",
107
- "content": "When LanceDB returns BigInt values, wrap them with Number() before doing arithmetic operations."
108
- }
109
- \`\`\`
110
-
111
- # Output Format
112
-
113
- Return JSON:
114
- {
115
- "memories": [
116
- {
117
- "category": "profile|preferences|entities|events|cases|patterns",
118
- "abstract": "One-line index",
119
- "overview": "Structured Markdown summary",
120
- "content": "Full narrative"
121
- }
122
- ]
123
- }
124
-
125
- Notes:
126
- - Output language should match the dominant language in the conversation
127
- - Only extract truly valuable personalized information
128
- - If nothing worth recording, return {"memories": []}
129
- - Maximum 5 memories per extraction
130
- - Preferences should be aggregated by topic`;
131
- }
132
-
133
- // ============================================================================
134
- // Chinese Extraction Prompt
135
- // ============================================================================
136
-
137
- export function buildChineseExtractionPrompt(
138
- conversationText: string,
139
- user: string,
140
- ): string {
141
- return `分析以下会话上下文,提取值得长期保存的记忆。
142
-
143
- 用户: ${user}
144
-
145
- ## 最近对话
146
- ${conversationText}
147
-
148
- # 记忆提取标准
149
-
150
- ## 什么值得记住?
151
- - 个性化信息:专属于该用户的信息,而非通用领域知识
152
- - 长期有效性:在未来会话中仍然有用的信息
153
- - 具体明确:有具体细节,而非模糊的概括
154
-
155
- ## 什么不值得记住?
156
- - 任何人都知道的常识
157
- - 临时信息:一次性的提问或对话
158
- - 模糊信息:"用户对某功能有疑问"(没有具体细节)
159
- - 工具输出、错误日志或模板文字
160
- - 回忆查询/元问题:"你还记得X吗?"、"好的"、"收到"、"嗯嗯"——这些是检索请求或应答碎片,不是新信息
161
- - 降级或不完整引用:如果用户模糊提及某事("之前说的那个"),不要编造细节或创建空洞记忆
162
-
163
- # 记忆分类
164
-
165
- ## 核心判断逻辑
166
-
167
- | 问题 | 答案 | 分类 |
168
- |------|------|------|
169
- | 用户是谁? | 身份、属性 | profile |
170
- | 用户偏好什么? | 偏好、习惯 | preferences |
171
- | 这个东西是什么? | 人物、项目、组织 | entities |
172
- | 发生了什么? | 决策、里程碑 | events |
173
- | 怎么解决的? | 问题+方案 | cases |
174
- | 流程是什么? | 可复用步骤 | patterns |
175
-
176
- ## 精确定义
177
-
178
- **profile** - 用户身份(静态属性)。判断标准:"用户是..."
179
- **preferences** - 用户偏好(倾向性)。判断标准:"用户偏好/喜欢..."
180
- **entities** - 持续存在的名词实体。判断标准:"XXX的状态是..."
181
- **events** - 发生过的事件。判断标准:"XXX做了/完成了..."
182
- **cases** - 问题+解决方案对。判断标准:包含"问题->方案"
183
- **patterns** - 可复用流程。判断标准:可用于"类似场景"
184
-
185
- ## 常见混淆
186
- - "计划做X" -> events(行动,非实体)
187
- - "项目X的状态:Y" -> entities(描述实体)
188
- - "用户偏好X" -> preferences(不是 profile)
189
- - "遇到问题A,用了方案B" -> cases(不是 events)
190
- - "处理某类问题的通用流程" -> patterns(不是 cases)
191
-
192
- # 三级结构
193
-
194
- 每条记忆包含三个层级:
195
-
196
- **abstract (L0)**:一行索引
197
- - 合并类型(preferences/entities/profile/patterns):\`[合并键]: [描述]\`
198
- - 独立类型(events/cases):具体描述
199
-
200
- **overview (L1)**:结构化 Markdown 摘要,使用分类特定标题
201
-
202
- **content (L2)**:包含背景和细节的完整叙述
203
-
204
- # 少样本示例
205
-
206
- ## profile
207
- \`\`\`json
208
- {
209
- "category": "profile",
210
- "abstract": "用户基本信息:AI开发工程师,3年LLM经验",
211
- "overview": "## 背景\\n- 职业:AI开发工程师\\n- 经验:3年LLM应用开发\\n- 技术栈:Python, LangChain",
212
- "content": "用户是一名AI开发工程师,有3年LLM应用开发经验。"
213
- }
214
- \`\`\`
215
-
216
- ## preferences
217
- \`\`\`json
218
- {
219
- "category": "preferences",
220
- "abstract": "Python代码风格:不加类型注解,简洁直接",
221
- "overview": "## 偏好领域\\n- 语言:Python\\n- 主题:代码风格\\n\\n## 详情\\n- 不加类型注解\\n- 简洁的函数注释\\n- 直接实现",
222
- "content": "用户偏好不带类型注解的Python代码,函数注释要简洁。"
223
- }
224
- \`\`\`
225
-
226
- ## cases
227
- \`\`\`json
228
- {
229
- "category": "cases",
230
- "abstract": "LanceDB BigInt错误 -> 在运算前使用Number()转换",
231
- "overview": "## 问题\\nLanceDB 0.26+对数值列返回BigInt\\n\\n## 方案\\n在运算前用Number(...)转换",
232
- "content": "当LanceDB返回BigInt值时,在做算术运算前用Number()包裹。"
233
- }
234
- \`\`\`
235
-
236
- # 输出格式
237
-
238
- 返回 JSON:
239
- {
240
- "memories": [
241
- {
242
- "category": "profile|preferences|entities|events|cases|patterns",
243
- "abstract": "一行索引",
244
- "overview": "结构化Markdown摘要",
245
- "content": "完整叙述"
246
- }
247
- ]
248
- }
249
-
250
- 注意:
251
- - 输出语言应与对话中的主要语言一致
252
- - 只提取真正有价值的个性化信息
253
- - 如果没有值得记录的内容,返回 {"memories": []}
254
- - 每次提取最多5条记忆
255
- - 偏好应按主题聚合`;
256
- }
257
-
258
- export function buildDedupPrompt(
259
- candidateAbstract: string,
260
- candidateOverview: string,
261
- candidateContent: string,
262
- existingMemories: string,
263
- ): string {
264
- return `Determine how to handle this candidate memory.
265
-
266
- **Candidate Memory**:
267
- Abstract: ${candidateAbstract}
268
- Overview: ${candidateOverview}
269
- Content: ${candidateContent}
270
-
271
- **Existing Similar Memories**:
272
- ${existingMemories}
273
-
274
- Please decide:
275
- - SKIP: Candidate memory duplicates existing memories, no need to save. Also SKIP if the candidate contains LESS information than an existing memory on the same topic (information degradation — e.g., candidate says "programming language preference" but existing memory already says "programming language preference: Python, TypeScript")
276
- - CREATE: This is completely new information not covered by any existing memory, should be created
277
- - MERGE: Candidate memory adds genuinely NEW details to an existing memory and should be merged
278
- - SUPPORT: Candidate reinforces/confirms an existing memory in a specific context (e.g. "still prefers tea in the evening")
279
- - CONTEXTUALIZE: Candidate adds a situational nuance to an existing memory (e.g. existing: "likes coffee", candidate: "prefers tea at night" — different context, same topic)
280
- - CONTRADICT: Candidate directly contradicts an existing memory in a specific context (e.g. existing: "runs on weekends", candidate: "stopped running on weekends")
281
-
282
- IMPORTANT:
283
- - "events" and "cases" categories are independent records — they do NOT support MERGE/SUPPORT/CONTEXTUALIZE/CONTRADICT. For these categories, only use SKIP or CREATE.
284
- - If the candidate appears to be derived from a recall question (e.g., "Do you remember X?" / "你记得X吗?") and an existing memory already covers topic X with equal or more detail, you MUST choose SKIP.
285
- - A candidate with less information than an existing memory on the same topic should NEVER be CREATED or MERGED — always SKIP.
286
- - For SUPPORT/CONTEXTUALIZE/CONTRADICT, you MUST provide a context_label from this vocabulary: general, morning, evening, night, weekday, weekend, work, leisure, summer, winter, travel.
287
-
288
- Return JSON format:
289
- {
290
- "decision": "skip|create|merge|support|contextualize|contradict",
291
- "match_index": 1,
292
- "reason": "Decision reason",
293
- "context_label": "evening"
294
- }
295
-
296
- - If decision is "merge"/"support"/"contextualize"/"contradict", set "match_index" to the number of the existing memory (1-based).
297
- - Only include "context_label" for support/contextualize/contradict decisions.`;
298
- }
299
-
300
- export function buildMergePrompt(
301
- existingAbstract: string,
302
- existingOverview: string,
303
- existingContent: string,
304
- newAbstract: string,
305
- newOverview: string,
306
- newContent: string,
307
- category: string,
308
- ): string {
309
- return `Merge the following memory into a single coherent record with all three levels.
310
-
311
- ** Category **: ${category}
312
-
313
- ** Existing Memory:**
314
- Abstract: ${existingAbstract}
315
- Overview:
316
- ${existingOverview}
317
- Content:
318
- ${existingContent}
319
-
320
- ** New Information:**
321
- Abstract: ${newAbstract}
322
- Overview:
323
- ${newOverview}
324
- Content:
325
- ${newContent}
326
-
327
- Requirements:
328
- - Remove duplicate information
329
- - Keep the most up - to - date details
330
- - Maintain a coherent narrative
331
- - Keep code identifiers / URIs / model names unchanged when they are proper nouns
332
-
333
- Return JSON:
334
- {
335
- "abstract": "Merged one-line abstract",
336
- "overview": "Merged structured Markdown overview",
337
- "content": "Merged full content"
338
- } `;
339
- }
@@ -1,71 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- /**
3
- * Memory Categories — 6-category classification system
4
- *
5
- * UserMemory: profile, preferences, entities, events
6
- * AgentMemory: cases, patterns
7
- */
8
-
9
- export const MEMORY_CATEGORIES = [
10
- "profile",
11
- "preferences",
12
- "entities",
13
- "events",
14
- "cases",
15
- "patterns",
16
- ] as const;
17
-
18
- export type MemoryCategory = (typeof MEMORY_CATEGORIES)[number];
19
-
20
- /** Categories that always merge (skip dedup entirely). */
21
- export const ALWAYS_MERGE_CATEGORIES = new Set<MemoryCategory>(["profile"]);
22
-
23
- /** Categories that support MERGE decision from LLM dedup. */
24
- export const MERGE_SUPPORTED_CATEGORIES = new Set<MemoryCategory>([
25
- "preferences",
26
- "entities",
27
- "patterns",
28
- ]);
29
-
30
- /** Categories that are append-only (CREATE or SKIP only, no MERGE). */
31
- export const APPEND_ONLY_CATEGORIES = new Set<MemoryCategory>([
32
- "events",
33
- "cases",
34
- ]);
35
-
36
- /** Memory tier levels for lifecycle management. */
37
- export type MemoryTier = "core" | "working" | "peripheral";
38
-
39
- /** A candidate memory extracted from conversation by LLM. */
40
- export type CandidateMemory = {
41
- category: MemoryCategory;
42
- abstract: string; // L0: one-sentence index
43
- overview: string; // L1: structured markdown summary
44
- content: string; // L2: full narrative
45
- };
46
-
47
- /** Dedup decision from LLM. */
48
- export type DedupDecision = "create" | "merge" | "skip" | "support" | "contextualize" | "contradict";
49
-
50
- export type DedupResult = {
51
- decision: DedupDecision;
52
- reason: string;
53
- matchId?: string; // ID of existing memory to merge with
54
- contextLabel?: string; // Optional context label for support/contextualize/contradict
55
- };
56
-
57
- export type ExtractionStats = {
58
- created: number;
59
- merged: number;
60
- skipped: number;
61
- supported?: number; // context-aware support count
62
- };
63
-
64
- /** Validate and normalize a category string. */
65
- export function normalizeCategory(raw: string): MemoryCategory | null {
66
- const lower = raw.toLowerCase().trim();
67
- if ((MEMORY_CATEGORIES as readonly string[]).includes(lower)) {
68
- return lower as MemoryCategory;
69
- }
70
- return null;
71
- }