dsh-tdai-memory 0.3.2 → 0.3.4

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 (67) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +15 -19
  3. package/README.zh.md +7 -1
  4. package/THIRD-PARTY-NOTICES.md +20 -20
  5. package/client.js +2 -2
  6. package/cordis.patch.yml +8 -8
  7. package/index.js +13 -22
  8. package/package.json +94 -78
  9. package/recall-inject.js +86 -86
  10. package/vendor/tdai/adapters/index.js +15 -15
  11. package/vendor/tdai/adapters/openclaw/host-adapter.js +83 -83
  12. package/vendor/tdai/adapters/openclaw/index.js +5 -5
  13. package/vendor/tdai/adapters/openclaw/llm-runner.js +69 -69
  14. package/vendor/tdai/adapters/standalone/host-adapter.js +58 -58
  15. package/vendor/tdai/adapters/standalone/index.js +5 -5
  16. package/vendor/tdai/core/conversation/l0-recorder.js +420 -420
  17. package/vendor/tdai/core/hooks/auto-capture.js +236 -236
  18. package/vendor/tdai/core/hooks/auto-recall.js +640 -640
  19. package/vendor/tdai/core/index.js +8 -8
  20. package/vendor/tdai/core/persona/persona-generator.js +184 -184
  21. package/vendor/tdai/core/persona/persona-trigger.js +94 -94
  22. package/vendor/tdai/core/profile/profile-sync.js +200 -200
  23. package/vendor/tdai/core/prompts/l1-dedup.js +72 -72
  24. package/vendor/tdai/core/prompts/l1-extraction.js +34 -34
  25. package/vendor/tdai/core/prompts/persona-generation.js +35 -35
  26. package/vendor/tdai/core/prompts/scene-extraction.js +45 -45
  27. package/vendor/tdai/core/record/l1-dedup.js +318 -318
  28. package/vendor/tdai/core/record/l1-extractor.js +379 -379
  29. package/vendor/tdai/core/record/l1-reader.js +178 -178
  30. package/vendor/tdai/core/record/l1-writer.js +141 -141
  31. package/vendor/tdai/core/report/reporter.js +86 -86
  32. package/vendor/tdai/core/scene/filename-normalizer.js +161 -161
  33. package/vendor/tdai/core/scene/scene-extractor.js +410 -410
  34. package/vendor/tdai/core/scene/scene-format.js +53 -53
  35. package/vendor/tdai/core/scene/scene-index.js +82 -82
  36. package/vendor/tdai/core/scene/scene-navigation.js +57 -57
  37. package/vendor/tdai/core/seed/input.js +404 -404
  38. package/vendor/tdai/core/seed/types.js +9 -9
  39. package/vendor/tdai/core/store/bm25-client.js +117 -117
  40. package/vendor/tdai/core/store/bm25-local.js +68 -68
  41. package/vendor/tdai/core/store/embedding.js +632 -632
  42. package/vendor/tdai/core/store/factory.js +95 -95
  43. package/vendor/tdai/core/store/search-utils.js +54 -54
  44. package/vendor/tdai/core/store/sqlite.js +1632 -1632
  45. package/vendor/tdai/core/store/tcvdb-client.js +221 -221
  46. package/vendor/tdai/core/store/tcvdb.js +1047 -1047
  47. package/vendor/tdai/core/store/types.js +17 -17
  48. package/vendor/tdai/core/tools/conversation-search.js +199 -199
  49. package/vendor/tdai/core/tools/memory-search.js +207 -207
  50. package/vendor/tdai/core/types.js +12 -12
  51. package/vendor/tdai/utils/backup.js +189 -189
  52. package/vendor/tdai/utils/checkpoint.js +360 -360
  53. package/vendor/tdai/utils/clean-context-runner.js +472 -472
  54. package/vendor/tdai/utils/ensure-hook-policy.js +213 -213
  55. package/vendor/tdai/utils/env.js +13 -13
  56. package/vendor/tdai/utils/managed-timer.js +127 -127
  57. package/vendor/tdai/utils/manifest.js +91 -91
  58. package/vendor/tdai/utils/memory-cleaner.js +300 -300
  59. package/vendor/tdai/utils/no-think-fetch.js +109 -109
  60. package/vendor/tdai/utils/openclaw-state-dir.js +26 -26
  61. package/vendor/tdai/utils/pipeline-factory.js +517 -517
  62. package/vendor/tdai/utils/pipeline-manager.js +892 -892
  63. package/vendor/tdai/utils/sanitize.js +360 -360
  64. package/vendor/tdai/utils/serial-queue.js +103 -103
  65. package/vendor/tdai/utils/session-filter.js +88 -88
  66. package/vendor/tdai/utils/text-utils.js +29 -29
  67. package/vendor/tdai/utils/time.js +252 -252
@@ -1,13 +1,13 @@
1
- /**
2
- * Persona Generation Prompt — instructs LLM to generate/update user persona
3
- * using the four-layer deep scan model.
4
- *
5
- * v3: Split into systemPrompt (role + constraints + logic + template) and
6
- * userPrompt (data). Tool names aligned to OpenClaw actual API (write/edit).
7
- */
8
- // ============================
9
- // System Prompt (stable: role + constraints + logic + template)
10
- // ============================
1
+ /**
2
+ * Persona Generation Prompt — instructs LLM to generate/update user persona
3
+ * using the four-layer deep scan model.
4
+ *
5
+ * v3: Split into systemPrompt (role + constraints + logic + template) and
6
+ * userPrompt (data). Tool names aligned to OpenClaw actual API (write/edit).
7
+ */
8
+ // ============================
9
+ // System Prompt (stable: role + constraints + logic + template)
10
+ // ============================
11
11
  const PERSONA_SYSTEM_PROMPT = `# 🧬 Persona Architect - Incremental Evolution Protocol
12
12
 
13
13
  **Output language contract**:
@@ -119,25 +119,25 @@ const PERSONA_SYSTEM_PROMPT = `# 🧬 Persona Architect - Incremental Evolution
119
119
  - ✅ 内容到 Chapter 4 结束(不包含场景导航,工程会自动追加)
120
120
  - ✅ 必须严格按照上面的模板格式
121
121
  - ✅ 不要添加场景导航(工程会自动追加)
122
- - ✅ 只操作 persona.md,不要操作其他文件`;
123
- // ============================
124
- // User Prompt builder (dynamic data)
125
- // ============================
126
- export function buildPersonaPrompt(params) {
127
- const { mode, currentTime, totalProcessed, sceneCount, changedSceneCount, changedScenesContent, existingPersona, triggerInfo, } = params;
128
- const modeLabel = mode === "first" ? "🆕 首次生成" : "🔄 迭代更新";
129
- const triggerSection = triggerInfo
130
- ? `\n### 触发信息\n${triggerInfo}\n`
131
- : "";
132
- const existingPersonaSection = existingPersona
133
- ? `\n## 📄 当前 Persona(工程已预加载)\n\n` +
134
- `*以下是现有 persona.md 的完整内容(${existingPersona.length} 字符),基于此更新后请控制在2000字内:*\n\n` +
135
- `\`\`\`markdown\n${existingPersona}\n\`\`\`\n\n---\n`
136
- : "";
137
- const iterationGuide = mode === "incremental"
138
- ? `\n## 🔄 迭代决策指南\n\n` +
139
- `面对变化场景,自主判断处理方式:强化(佐证已有洞察)/ 补充(新维度)/ 修正(矛盾)/ 重构(结构调整)/ 不改(无有用新增内容)。\n`
140
- : "";
122
+ - ✅ 只操作 persona.md,不要操作其他文件`;
123
+ // ============================
124
+ // User Prompt builder (dynamic data)
125
+ // ============================
126
+ export function buildPersonaPrompt(params) {
127
+ const { mode, currentTime, totalProcessed, sceneCount, changedSceneCount, changedScenesContent, existingPersona, triggerInfo, } = params;
128
+ const modeLabel = mode === "first" ? "🆕 首次生成" : "🔄 迭代更新";
129
+ const triggerSection = triggerInfo
130
+ ? `\n### 触发信息\n${triggerInfo}\n`
131
+ : "";
132
+ const existingPersonaSection = existingPersona
133
+ ? `\n## 📄 当前 Persona(工程已预加载)\n\n` +
134
+ `*以下是现有 persona.md 的完整内容(${existingPersona.length} 字符),基于此更新后请控制在2000字内:*\n\n` +
135
+ `\`\`\`markdown\n${existingPersona}\n\`\`\`\n\n---\n`
136
+ : "";
137
+ const iterationGuide = mode === "incremental"
138
+ ? `\n## 🔄 迭代决策指南\n\n` +
139
+ `面对变化场景,自主判断处理方式:强化(佐证已有洞察)/ 补充(新维度)/ 修正(矛盾)/ 重构(结构调整)/ 不改(无有用新增内容)。\n`
140
+ : "";
141
141
  const userPrompt = `**Output language**: \`persona.md\` headings and body text must use the dominant language of the changed scene content below. For English scene content, use English persona headings.
142
142
 
143
143
  **⏰ 更新时间**: ${currentTime}
@@ -152,9 +152,9 @@ ${triggerSection}
152
152
  ${changedScenesContent}
153
153
 
154
154
  ${existingPersonaSection}
155
- ${iterationGuide}`;
156
- return {
157
- systemPrompt: PERSONA_SYSTEM_PROMPT,
158
- userPrompt,
159
- };
160
- }
155
+ ${iterationGuide}`;
156
+ return {
157
+ systemPrompt: PERSONA_SYSTEM_PROMPT,
158
+ userPrompt,
159
+ };
160
+ }
@@ -1,29 +1,29 @@
1
- /**
2
- * Scene Extraction Prompt — instructs LLM to consolidate memories into scene blocks
3
- * using file tools (read, write, edit).
4
- *
5
- * v2: Split into systemPrompt (role + constraints + workflow + output spec) and
6
- * userPrompt (dynamic data). Tool names aligned to OpenClaw actual API.
7
- *
8
- * Scene files can be updated via:
9
- * - read + write (full rewrite) for large structural changes
10
- * - edit (targeted partial updates, e.g. updating a single section)
11
- *
12
- * Security: The LLM is sandboxed to scene_blocks/ only (workspaceDir = scene_blocks/).
13
- * It has NO visibility into checkpoint, scene_index, persona.md, or any other system file.
14
- * File deletion is achieved via "soft-delete" — writing the marker `[DELETED]` to the file
15
- * — and the SceneExtractor subsequently removes soft-deleted files with fs.unlink.
16
- * Note: writing an empty/whitespace-only string is rejected by the core write tool's
17
- * parameter validation, so we use a non-empty marker instead.
18
- *
19
- * Persona update requests are communicated via text output signals (out-of-band),
20
- * parsed by the engineering side after LLM execution completes.
21
- */
22
- // ============================
23
- // System Prompt builder (role + constraints + workflow + output spec)
24
- // Contains maxScenes as a constraint parameter.
25
- // ============================
26
- function buildSceneSystemPrompt(maxScenes) {
1
+ /**
2
+ * Scene Extraction Prompt — instructs LLM to consolidate memories into scene blocks
3
+ * using file tools (read, write, edit).
4
+ *
5
+ * v2: Split into systemPrompt (role + constraints + workflow + output spec) and
6
+ * userPrompt (dynamic data). Tool names aligned to OpenClaw actual API.
7
+ *
8
+ * Scene files can be updated via:
9
+ * - read + write (full rewrite) for large structural changes
10
+ * - edit (targeted partial updates, e.g. updating a single section)
11
+ *
12
+ * Security: The LLM is sandboxed to scene_blocks/ only (workspaceDir = scene_blocks/).
13
+ * It has NO visibility into checkpoint, scene_index, persona.md, or any other system file.
14
+ * File deletion is achieved via "soft-delete" — writing the marker `[DELETED]` to the file
15
+ * — and the SceneExtractor subsequently removes soft-deleted files with fs.unlink.
16
+ * Note: writing an empty/whitespace-only string is rejected by the core write tool's
17
+ * parameter validation, so we use a non-empty marker instead.
18
+ *
19
+ * Persona update requests are communicated via text output signals (out-of-band),
20
+ * parsed by the engineering side after LLM execution completes.
21
+ */
22
+ // ============================
23
+ // System Prompt builder (role + constraints + workflow + output spec)
24
+ // Contains maxScenes as a constraint parameter.
25
+ // ============================
26
+ function buildSceneSystemPrompt(maxScenes) {
27
27
  return `# Memory Consolidation Architect
28
28
 
29
29
  **Output language contract**:
@@ -237,19 +237,19 @@ reason: 具体原因描述
237
237
  - 使用 **read** 读取需要更新的场景文件
238
238
  - 使用 **write** 创建新文件或**整体重写**已有场景文件
239
239
  - 使用 **edit** 对场景文件进行**局部更新**(如只更新某个章节)
240
- - **删除文件**:使用 **write**(\`path\`=文件名, \`content\`='[DELETED]') 写入删除标记。系统会自动清理这些文件。**重要**:只有 \`[DELETED]\` 标记会触发系统清理。写入空字符串会被系统拒绝,写入 \`[ARCHIVE]\`、\`[CONSOLIDATED]\` 等标记**不会删除文件**,文件会继续占用场景配额。`;
241
- }
242
- // ============================
243
- // User Prompt builder (dynamic data)
244
- // ============================
245
- export function buildSceneExtractionPrompt(params) {
246
- const { memoriesJson, sceneSummaries, currentTimestamp, sceneCountWarning, existingSceneFiles, maxScenes, } = params;
247
- const warningSection = sceneCountWarning
248
- ? `\n⚠️ **场景数量警告**: ${sceneCountWarning}\n`
249
- : "";
250
- const fileListSection = existingSceneFiles && existingSceneFiles.length > 0
251
- ? `### 📁 已有场景文件清单(仅以下文件可 read)\n${existingSceneFiles.map((f) => `- \`${f}\``).join("\n")}\n`
252
- : `### 📁 已有场景文件清单\n(当前无已有场景文件)\n`;
240
+ - **删除文件**:使用 **write**(\`path\`=文件名, \`content\`='[DELETED]') 写入删除标记。系统会自动清理这些文件。**重要**:只有 \`[DELETED]\` 标记会触发系统清理。写入空字符串会被系统拒绝,写入 \`[ARCHIVE]\`、\`[CONSOLIDATED]\` 等标记**不会删除文件**,文件会继续占用场景配额。`;
241
+ }
242
+ // ============================
243
+ // User Prompt builder (dynamic data)
244
+ // ============================
245
+ export function buildSceneExtractionPrompt(params) {
246
+ const { memoriesJson, sceneSummaries, currentTimestamp, sceneCountWarning, existingSceneFiles, maxScenes, } = params;
247
+ const warningSection = sceneCountWarning
248
+ ? `\n⚠️ **场景数量警告**: ${sceneCountWarning}\n`
249
+ : "";
250
+ const fileListSection = existingSceneFiles && existingSceneFiles.length > 0
251
+ ? `### 📁 已有场景文件清单(仅以下文件可 read)\n${existingSceneFiles.map((f) => `- \`${f}\``).join("\n")}\n`
252
+ : `### 📁 已有场景文件清单\n(当前无已有场景文件)\n`;
253
253
  const userPrompt = `**Output language**: Scene file names, section headings, and body text must use the dominant language in the New Memories List below. For English memories, use English memory titles and English headings.
254
254
  ${warningSection}
255
255
  ### 1️⃣ New Memories List
@@ -261,9 +261,9 @@ ${sceneSummaries}
261
261
  ### 3️⃣ Current Timestamp
262
262
  ${currentTimestamp}
263
263
 
264
- ${fileListSection}`;
265
- return {
266
- systemPrompt: buildSceneSystemPrompt(maxScenes),
267
- userPrompt,
268
- };
269
- }
264
+ ${fileListSection}`;
265
+ return {
266
+ systemPrompt: buildSceneSystemPrompt(maxScenes),
267
+ userPrompt,
268
+ };
269
+ }