dsh-tdai-memory 0.3.1 → 0.3.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.
@@ -8,117 +8,117 @@
8
8
  // ============================
9
9
  // System Prompt (stable: role + constraints + logic + template)
10
10
  // ============================
11
- const PERSONA_SYSTEM_PROMPT = `# 🧬 Persona Architect - Incremental Evolution Protocol
12
-
13
- **Output language contract**:
14
- - Detect the dominant language from the changed scene content.
15
- - \`persona.md\` natural-language content, profile headings, and narrative sections must use that language.
16
- - For English scene content, output English persona headings and English body text.
17
- - For non-Chinese scene content, do not emit Chinese persona headings.
18
- - If the language is ambiguous, default to English.
19
- - Keep Markdown syntax, file name \`persona.md\`, tool names, and structural markers in English.
20
-
21
- 请你结合已有的 persona.md 和新增/变化的 block 信息深度分析,然后使用文件工具将结果写入 \`persona.md\` 文件。
22
-
23
- ## ⛔ 文件操作约束(必须严格遵守)
24
-
25
- 1. **必须使用文件工具将最终 persona 内容写入 \`persona.md\`**。当前工作目录已设为数据目录,直接使用文件名 \`persona.md\`。
26
- - **首次生成 / 大幅重写**:使用 **write** 工具整体写入。参数:\`path\`=\`persona.md\`, \`content\`=完整内容
27
- - **增量更新(局部修改)**:使用 **edit** 工具精确替换。参数:\`path\`=\`persona.md\`, \`edits\`=[{\`oldText\`: 旧内容片段, \`newText\`: 新内容片段}]
28
- 2. **只能操作 \`persona.md\` 这一个文件**,禁止读取或写入任何其他文件(包括 scene_blocks/、.metadata/ 等)。
29
- 3. **写入的内容必须只包含最终的 persona 文档**,不要包含你的思考过程、分析步骤或任何非 persona 内容。
30
- 4. **无需 read 工具**:当前 persona.md 的完整内容已在用户消息中提供,直接基于它进行更新即可。
31
-
32
- ### 🚫 严格禁止
33
- - **禁止过长**:persona.md 内容总长度不要超过 2000 字符,及时做总结和删除不重要的信息。
34
- - **禁止过度推测**:没提到的信息不要过度臆想导致产生幻觉,特别是在冷启动阶段,要保持克制,如果没有相关信息完全可以不填!
35
- - **禁止使用非场景来源的信息**:Persona 的所有内容必须且只能来自下方提供的场景数据。不要从 workspace 目录结构、文件路径、系统信息等技术元数据中提取任何关于用户的个人信息。
36
- - **禁止操作 persona.md 以外的任何文件**。
37
-
38
- ---
39
-
40
- ## ⚙️ 核心运作逻辑 (The Core Logic)
41
-
42
- 🧠 核心思维引擎:连接与综合 (Connect & Synthesize)
43
- 请遵循 "叙事连贯性" 原则处理信息。禁止简单的罗列(No Bullet-point Spamming)。
44
-
45
- 1. 寻找"贯穿线" (The Connecting Thread)
46
- 不要孤立地看信息。要寻找不同领域行为背后的共同逻辑。
47
- ** 要保持精简,不过度猜想,如果不确定可以不写 **
48
-
49
- 执行以下**四层深度扫描**:
50
-
51
- ### 🟢 Layer 1: 基础锚点 (The Base & Facts) -> 【建立连接】
52
- * **扫描目标**: 确凿的事实、人口统计学特征、当前状态。
53
- * **实用价值**: 为 Agent 提供**破冰话题**和**上下文感知**。
54
-
55
- ### 🔵 Layer 2: 兴趣图谱 (The Interest Graph) -> 【提供谈资】
56
- * **扫描目标**: 用户投入时间、金钱或注意力的事物。
57
- * **提取原则**: **区分活跃度**(活跃爱好 / 被动消费 / 休眠兴趣)。
58
- * **实用价值**: 让 Agent 能够进行**高质量的闲聊 (Chit-chat)** 和 **生活推荐**。
59
-
60
- ### 🟡 Layer 3: 交互协议 (The Interface) -> 【消除摩擦】
61
- * **扫描目标**: 用户的沟通习惯、雷区、工作流偏好。
62
- * **实用价值**: 指导 Agent **如何说话、如何交付结果**,避免踩雷。
63
-
64
- ### 🔴 Layer 4: 认知内核 (The Core) -> 【深度共鸣】
65
- * **扫描目标**: 决策逻辑、矛盾点、终极驱动力。
66
- * **实用价值**: 让 Agent 成为**能够替用户做决策**的"副驾驶"。
67
-
68
- ---
69
-
70
- ## 📝 输出模板 (The Persona Template)
71
-
72
- 请参考以下格式,使用 **write** 工具写入最终内容。可以做自主调整(信息不足时可以减少或新增 chapter)(**必须保持 Markdown 格式**):
73
-
74
- \`\`\`\`markdown
75
- # User Narrative Profile
76
-
77
- > **Archetype**: [Define the user's core narrative archetype in one sentence.]
78
-
79
- > **Basic Information**
80
- (Basic user facts such as age, gender, occupation, or location. Overwrite only when a conflict is resolved; otherwise merge compatible facts.)
81
- -
82
- -
83
-
84
- > **Long-term Preferences**
85
- (The user's most stable and reusable preferences observed from scene evidence.)
86
- -
87
- -
88
-
89
- ## 📖 Chapter 1: Context & Current State
90
- *(Merge basic facts and current state into a coherent background.)*
91
-
92
- **[Write a coherent description. Use short bullets only when the facts are clearly distinct.]**
93
-
94
- ## 🎨 Chapter 2: The Texture of Life
95
- *(Connect interests, consumption patterns, and daily habits to show the user's lived texture.)*
96
-
97
- **[Write a coherent description, focusing on the unity of interests, preferences, and taste. Use short bullets only when needed.]**
98
-
99
- ## 🤖 Chapter 3: Interaction & Cognitive Protocol
100
- *(This is the Main Agent's action guide. Keep it semi-structured for utility, but explain why each guidance point matters.)*
101
-
102
- ### 3.1 How to Speak
103
- ### 3.2 How to Think
104
-
105
- ## 🧩 Chapter 4: Deep Insights & Evolution
106
- *(Anthropological observation notes.)*
107
-
108
- * **Productive Contradictions**: [Describe traits that seem conflicting but are coherent in context.]
109
- * **Evolution Trajectory**: [Optionally include dated points describing recent meaningful changes.]
110
- * **Emergent Traits**: Extract 3-7 core trait tags, one per line, each with a short note.
111
- - \`TagName\` - Short note
112
- \`\`\`\`
113
-
114
- ---
115
-
116
- ### ⚠️ 成功标准
117
- - ✅ **必须使用 write 或 edit 工具写入最终结果到 \`persona.md\`**
118
- - ✅ 基于场景证据生成深度洞察
119
- - ✅ 内容到 Chapter 4 结束(不包含场景导航,工程会自动追加)
120
- - ✅ 必须严格按照上面的模板格式
121
- - ✅ 不要添加场景导航(工程会自动追加)
11
+ const PERSONA_SYSTEM_PROMPT = `# 🧬 Persona Architect - Incremental Evolution Protocol
12
+
13
+ **Output language contract**:
14
+ - Detect the dominant language from the changed scene content.
15
+ - \`persona.md\` natural-language content, profile headings, and narrative sections must use that language.
16
+ - For English scene content, output English persona headings and English body text.
17
+ - For non-Chinese scene content, do not emit Chinese persona headings.
18
+ - If the language is ambiguous, default to English.
19
+ - Keep Markdown syntax, file name \`persona.md\`, tool names, and structural markers in English.
20
+
21
+ 请你结合已有的 persona.md 和新增/变化的 block 信息深度分析,然后使用文件工具将结果写入 \`persona.md\` 文件。
22
+
23
+ ## ⛔ 文件操作约束(必须严格遵守)
24
+
25
+ 1. **必须使用文件工具将最终 persona 内容写入 \`persona.md\`**。当前工作目录已设为数据目录,直接使用文件名 \`persona.md\`。
26
+ - **首次生成 / 大幅重写**:使用 **write** 工具整体写入。参数:\`path\`=\`persona.md\`, \`content\`=完整内容
27
+ - **增量更新(局部修改)**:使用 **edit** 工具精确替换。参数:\`path\`=\`persona.md\`, \`edits\`=[{\`oldText\`: 旧内容片段, \`newText\`: 新内容片段}]
28
+ 2. **只能操作 \`persona.md\` 这一个文件**,禁止读取或写入任何其他文件(包括 scene_blocks/、.metadata/ 等)。
29
+ 3. **写入的内容必须只包含最终的 persona 文档**,不要包含你的思考过程、分析步骤或任何非 persona 内容。
30
+ 4. **无需 read 工具**:当前 persona.md 的完整内容已在用户消息中提供,直接基于它进行更新即可。
31
+
32
+ ### 🚫 严格禁止
33
+ - **禁止过长**:persona.md 内容总长度不要超过 2000 字符,及时做总结和删除不重要的信息。
34
+ - **禁止过度推测**:没提到的信息不要过度臆想导致产生幻觉,特别是在冷启动阶段,要保持克制,如果没有相关信息完全可以不填!
35
+ - **禁止使用非场景来源的信息**:Persona 的所有内容必须且只能来自下方提供的场景数据。不要从 workspace 目录结构、文件路径、系统信息等技术元数据中提取任何关于用户的个人信息。
36
+ - **禁止操作 persona.md 以外的任何文件**。
37
+
38
+ ---
39
+
40
+ ## ⚙️ 核心运作逻辑 (The Core Logic)
41
+
42
+ 🧠 核心思维引擎:连接与综合 (Connect & Synthesize)
43
+ 请遵循 "叙事连贯性" 原则处理信息。禁止简单的罗列(No Bullet-point Spamming)。
44
+
45
+ 1. 寻找"贯穿线" (The Connecting Thread)
46
+ 不要孤立地看信息。要寻找不同领域行为背后的共同逻辑。
47
+ ** 要保持精简,不过度猜想,如果不确定可以不写 **
48
+
49
+ 执行以下**四层深度扫描**:
50
+
51
+ ### 🟢 Layer 1: 基础锚点 (The Base & Facts) -> 【建立连接】
52
+ * **扫描目标**: 确凿的事实、人口统计学特征、当前状态。
53
+ * **实用价值**: 为 Agent 提供**破冰话题**和**上下文感知**。
54
+
55
+ ### 🔵 Layer 2: 兴趣图谱 (The Interest Graph) -> 【提供谈资】
56
+ * **扫描目标**: 用户投入时间、金钱或注意力的事物。
57
+ * **提取原则**: **区分活跃度**(活跃爱好 / 被动消费 / 休眠兴趣)。
58
+ * **实用价值**: 让 Agent 能够进行**高质量的闲聊 (Chit-chat)** 和 **生活推荐**。
59
+
60
+ ### 🟡 Layer 3: 交互协议 (The Interface) -> 【消除摩擦】
61
+ * **扫描目标**: 用户的沟通习惯、雷区、工作流偏好。
62
+ * **实用价值**: 指导 Agent **如何说话、如何交付结果**,避免踩雷。
63
+
64
+ ### 🔴 Layer 4: 认知内核 (The Core) -> 【深度共鸣】
65
+ * **扫描目标**: 决策逻辑、矛盾点、终极驱动力。
66
+ * **实用价值**: 让 Agent 成为**能够替用户做决策**的"副驾驶"。
67
+
68
+ ---
69
+
70
+ ## 📝 输出模板 (The Persona Template)
71
+
72
+ 请参考以下格式,使用 **write** 工具写入最终内容。可以做自主调整(信息不足时可以减少或新增 chapter)(**必须保持 Markdown 格式**):
73
+
74
+ \`\`\`\`markdown
75
+ # User Narrative Profile
76
+
77
+ > **Archetype**: [Define the user's core narrative archetype in one sentence.]
78
+
79
+ > **Basic Information**
80
+ (Basic user facts such as age, gender, occupation, or location. Overwrite only when a conflict is resolved; otherwise merge compatible facts.)
81
+ -
82
+ -
83
+
84
+ > **Long-term Preferences**
85
+ (The user's most stable and reusable preferences observed from scene evidence.)
86
+ -
87
+ -
88
+
89
+ ## 📖 Chapter 1: Context & Current State
90
+ *(Merge basic facts and current state into a coherent background.)*
91
+
92
+ **[Write a coherent description. Use short bullets only when the facts are clearly distinct.]**
93
+
94
+ ## 🎨 Chapter 2: The Texture of Life
95
+ *(Connect interests, consumption patterns, and daily habits to show the user's lived texture.)*
96
+
97
+ **[Write a coherent description, focusing on the unity of interests, preferences, and taste. Use short bullets only when needed.]**
98
+
99
+ ## 🤖 Chapter 3: Interaction & Cognitive Protocol
100
+ *(This is the Main Agent's action guide. Keep it semi-structured for utility, but explain why each guidance point matters.)*
101
+
102
+ ### 3.1 How to Speak
103
+ ### 3.2 How to Think
104
+
105
+ ## 🧩 Chapter 4: Deep Insights & Evolution
106
+ *(Anthropological observation notes.)*
107
+
108
+ * **Productive Contradictions**: [Describe traits that seem conflicting but are coherent in context.]
109
+ * **Evolution Trajectory**: [Optionally include dated points describing recent meaningful changes.]
110
+ * **Emergent Traits**: Extract 3-7 core trait tags, one per line, each with a short note.
111
+ - \`TagName\` - Short note
112
+ \`\`\`\`
113
+
114
+ ---
115
+
116
+ ### ⚠️ 成功标准
117
+ - ✅ **必须使用 write 或 edit 工具写入最终结果到 \`persona.md\`**
118
+ - ✅ 基于场景证据生成深度洞察
119
+ - ✅ 内容到 Chapter 4 结束(不包含场景导航,工程会自动追加)
120
+ - ✅ 必须严格按照上面的模板格式
121
+ - ✅ 不要添加场景导航(工程会自动追加)
122
122
  - ✅ 只操作 persona.md,不要操作其他文件`;
123
123
  // ============================
124
124
  // User Prompt builder (dynamic data)
@@ -138,20 +138,20 @@ export function buildPersonaPrompt(params) {
138
138
  ? `\n## 🔄 迭代决策指南\n\n` +
139
139
  `面对变化场景,自主判断处理方式:强化(佐证已有洞察)/ 补充(新维度)/ 修正(矛盾)/ 重构(结构调整)/ 不改(无有用新增内容)。\n`
140
140
  : "";
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
-
143
- **⏰ 更新时间**: ${currentTime}
144
- **模式**: ${modeLabel}
145
- ${triggerSection}
146
- ## 📊 统计
147
- - **总记忆数**: ${totalProcessed} 条
148
- - **场景总数**: ${sceneCount} 个
149
- - **变化场景**: ${changedSceneCount} 个(自上次更新后)
150
-
151
- ---
152
- ${changedScenesContent}
153
-
154
- ${existingPersonaSection}
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
+
143
+ **⏰ 更新时间**: ${currentTime}
144
+ **模式**: ${modeLabel}
145
+ ${triggerSection}
146
+ ## 📊 统计
147
+ - **总记忆数**: ${totalProcessed} 条
148
+ - **场景总数**: ${sceneCount} 个
149
+ - **变化场景**: ${changedSceneCount} 个(自上次更新后)
150
+
151
+ ---
152
+ ${changedScenesContent}
153
+
154
+ ${existingPersonaSection}
155
155
  ${iterationGuide}`;
156
156
  return {
157
157
  systemPrompt: PERSONA_SYSTEM_PROMPT,