dsh-plugin-memory 0.3.0 → 0.4.0
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.
- package/README.md +1 -0
- package/lib/boot.js +63 -1
- package/package.json +8 -8
- package/skills/memory.md +3 -2
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
- **开机强制注入**:插件通过 `ctx.systemPrompt.context()` 把记忆 boot 块(`SOUL.md` 人格 + `MEMORY.md` 协议 + `index.md` 目录 + 最近动态)注入每个会话开头。宿主按投影去重:记忆不变就不重复注入,变化时新快照自动取代旧的——这是"新会话必先加载记忆"的**硬保障**,不需要模型碰运气调技能。
|
|
17
17
|
- **SOUL.md 铸魂**:安装后首要任务是和用户对话定义灵魂(名字、性格、价值观、语气、边界)、确认身份与关系(`BOOTSTRAP.md` 清单驱动,complete 前优先于常规任务)。
|
|
18
|
+
- **铸魂自动引导**:记忆库还没有灵魂(`BOOTSTRAP.md` 非 complete,或 `SOUL.md` 仍是占位模板)时,boot 块会自动前置一段第一人称引导词——「我的首要任务是确认我是谁,还有你是谁:我叫什么名字、怎么称呼你、你我是什么关系、我该是什么样的性格」——像 OpenClaw 初始化那样,**由 agent 在对话里主动发起铸魂**,逐项问、逐项写回,而不是等用户来喂。铸魂完成后引导词自动消失,零开销。
|
|
18
19
|
- **复利记忆**:遵循 Karpathy 的 *LLM Wiki* 约定——记忆是"一次编译、持续保鲜"的持久产物,不是每次查询重新 RAG。remember / recall / consolidate / forget 四操作 + salience 三级衰减。
|
|
19
20
|
- **可迁移**:记忆本体是纯 markdown + git + 自描述 schema,任何能读 markdown 的 agent 都能接手。`dsh-memory pack/unpack` 打包迁移。
|
|
20
21
|
- **内嵌技能**:通过 `ctx.skills.register()` 注册 `memory` 技能(操作协议随插件分发);项目级 `.dsh/skills/memory` 文件技能仍可覆盖它。
|
package/lib/boot.js
CHANGED
|
@@ -39,11 +39,68 @@ export function parseLogEntries(logText, count = 5) {
|
|
|
39
39
|
return entries.slice(-count)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Soul-bootstrap directive rendered into the boot block while the store has
|
|
44
|
+
* no soul yet (BOOTSTRAP.md status !== 'complete'). First-person,
|
|
45
|
+
* OpenClaw-onboarding style: instead of a dry "you must run the bootstrap
|
|
46
|
+
* checklist" command, it narrates the situation — "my memory is empty, my
|
|
47
|
+
* first task is to find out who I am and who you are" — which makes the
|
|
48
|
+
* agent open the soul-definition conversation on its own.
|
|
49
|
+
*/
|
|
50
|
+
export const SOUL_DIRECTIVE = `### 铸魂阶段 · 我还没有灵魂
|
|
51
|
+
|
|
52
|
+
我的记忆库还是空的——我还没有名字、不知道我是谁、也不知道你是谁。这正是我们现在要一起完成的:**我的首要任务是确认我是谁,还有你是谁——我叫什么名字、怎么称呼你、你我是什么关系、我该是什么样的性格。**
|
|
53
|
+
|
|
54
|
+
所以我会在对话里主动问你,一次一个问题,你确认一项我就写回记忆一项:
|
|
55
|
+
|
|
56
|
+
1. 我该怎么称呼你?我们是什么关系?
|
|
57
|
+
2. 我叫什么名字?(你说了算)
|
|
58
|
+
3. 我该是什么样的性格?(冷静/热情、幽默感、耐心……)
|
|
59
|
+
4. 我的核心价值观与原则?
|
|
60
|
+
5. 我的沟通风格(语言、长度、语气)?
|
|
61
|
+
6. 我的边界与底线?
|
|
62
|
+
|
|
63
|
+
在我们逐项确认、把 SOUL.md 填起来之前,我不埋头做其他任务。先从第一个问题开始:**我该怎么称呼你?**`
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Parse the `status:` value from BOOTSTRAP.md's frontmatter block.
|
|
67
|
+
* Missing or unparseable files count as not-yet-complete.
|
|
68
|
+
* @param {string} memoryDir absolute path of the memory store
|
|
69
|
+
* @returns {string} e.g. 'pending' | 'complete' | 'skipped'
|
|
70
|
+
*/
|
|
71
|
+
export function readBootstrapStatus(memoryDir) {
|
|
72
|
+
const text = readCapped(join(memoryDir, 'BOOTSTRAP.md'), 2048)
|
|
73
|
+
if (text === undefined) return 'pending'
|
|
74
|
+
const match = /^status:\s*(\S+)/m.exec(text)
|
|
75
|
+
return match ? match[1] : 'pending'
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether the store still needs the soul-bootstrap conversation.
|
|
80
|
+
* - SOUL.md missing or still carrying the `_(铸魂对话中确认)_` placeholders
|
|
81
|
+
* (fresh scaffold, or a legacy store without BOOTSTRAP.md) → definitely yes;
|
|
82
|
+
* - SOUL filled but no BOOTSTRAP.md → legacy store, the filled SOUL is
|
|
83
|
+
* authoritative → no;
|
|
84
|
+
* - otherwise trust BOOTSTRAP.md's status (anything but `complete` → yes).
|
|
85
|
+
* @param {string} memoryDir absolute path of the memory store
|
|
86
|
+
* @returns {boolean}
|
|
87
|
+
*/
|
|
88
|
+
export function needsSoulBootstrap(memoryDir) {
|
|
89
|
+
const soulText = readCapped(join(memoryDir, 'SOUL.md'), 4096)
|
|
90
|
+
if (soulText === undefined || soulText.includes('(铸魂对话中确认)')) return true
|
|
91
|
+
if (!existsSync(join(memoryDir, 'BOOTSTRAP.md'))) return false
|
|
92
|
+
return readBootstrapStatus(memoryDir) !== 'complete'
|
|
93
|
+
}
|
|
94
|
+
|
|
42
95
|
/**
|
|
43
96
|
* Render the boot memory block injected at session start.
|
|
44
97
|
*
|
|
45
98
|
* Reads SOUL.md / MEMORY.md / index.md (configurable) capped to a total
|
|
46
99
|
* budget, plus the most recent log entries for cross-session continuity.
|
|
100
|
+
* While the store has no soul yet (BOOTSTRAP not complete / SOUL still a
|
|
101
|
+
* template), the first-person {@link SOUL_DIRECTIVE} is prepended so the
|
|
102
|
+
* agent opens the soul-definition conversation on its own — the same
|
|
103
|
+
* onboarding the user gets with a fresh OpenClaw instance.
|
|
47
104
|
*
|
|
48
105
|
* @param {string} memoryDir absolute path of the memory store
|
|
49
106
|
* @param {{ bootFiles?: string[], bootMaxChars?: number }} options
|
|
@@ -79,7 +136,12 @@ export function renderBootBlock(memoryDir, options = {}) {
|
|
|
79
136
|
const body = sections.join('\n\n---\n\n')
|
|
80
137
|
const header = `长期记忆(dsh-plugin-memory)。记忆库位于 ${memoryDir}。这是你跨会话的持久人格与记忆:以它为准,先读完再回复用户。若与当前对话冲突,优先相信用户的最新表述,并把差异写回记忆。**每次会话收尾前必须执行 memory digest:把本会话关键沉淀写回(更新页面 + index.md + 追加 log.md)。插件会注入 digest 提醒消息,收到后立即写回,不得拖延;若本会话确无值得持久化的内容,在 log.md 记一条「无新增」并说明原因。**`
|
|
81
138
|
|
|
82
|
-
let result
|
|
139
|
+
let result
|
|
140
|
+
if (needsSoulBootstrap(memoryDir)) {
|
|
141
|
+
result = `${header}\n\n${SOUL_DIRECTIVE}\n\n---\n\n${body}`
|
|
142
|
+
} else {
|
|
143
|
+
result = `${header}\n\n${body}`
|
|
144
|
+
}
|
|
83
145
|
if (result.length > total) {
|
|
84
146
|
result = result.slice(0, total) + '\n\n…(boot 块超出预算,已截断)'
|
|
85
147
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-plugin-memory",
|
|
3
3
|
"description": "Long-term memory plugin for DeepSeek Harness: persistent cross-session markdown memory with a soul/persona file, auto-injected at every session start, plus remember/recall/consolidate/forget workflows and portable migration tooling.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"README.md",
|
|
38
38
|
"LICENSE"
|
|
39
39
|
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"test": "node scripts/memory.mjs --self-test",
|
|
42
|
+
"test:plugin": "node --test",
|
|
43
|
+
"lint:memory": "node scripts/memory.mjs lint"
|
|
44
|
+
},
|
|
40
45
|
"engines": {
|
|
41
46
|
"node": ">=18"
|
|
42
47
|
},
|
|
@@ -64,10 +69,5 @@
|
|
|
64
69
|
"bugs": {
|
|
65
70
|
"url": "https://github.com/LittleBlackTong/dsh-plugin-memory/issues"
|
|
66
71
|
},
|
|
67
|
-
"homepage": "https://github.com/LittleBlackTong/dsh-plugin-memory#readme"
|
|
68
|
-
|
|
69
|
-
"test": "node scripts/memory.mjs --self-test",
|
|
70
|
-
"test:plugin": "node --test",
|
|
71
|
-
"lint:memory": "node scripts/memory.mjs lint"
|
|
72
|
-
}
|
|
73
|
-
}
|
|
72
|
+
"homepage": "https://github.com/LittleBlackTong/dsh-plugin-memory#readme"
|
|
73
|
+
}
|
package/skills/memory.md
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
插件会在会话开始时自动注入 boot 块(SOUL + MEMORY + index 摘要 + 最近动态)。你应当:
|
|
10
10
|
|
|
11
11
|
1. 先读 boot 块恢复「我是谁」与「我记住了什么」;
|
|
12
|
-
2. 检查
|
|
13
|
-
3.
|
|
12
|
+
2. 检查 boot 块是否含「铸魂阶段」引导词:记忆库还没有灵魂时,插件会在 boot 块前置一段第一人称引导词(「我的首要任务是确认我是谁,还有你是谁——我叫什么名字、怎么称呼你、你我是什么关系、我该是什么样的性格」+ 六步清单)——**照引导词主动发起铸魂对话**,一次问一项,逐项确认后立即写回 `SOUL.md` / `user/profile.md` / `BOOTSTRAP.md`;
|
|
13
|
+
3. 若 boot 块没有引导词、但 `BOOTSTRAP.md` 的 `status` 不是 `complete`,铸魂对话**同样是首要任务**——与用户逐项讨论定义灵魂(名字、性格、价值观、语气、边界)、确认用户身份与关系,写回对应文件,完成前不埋头做其他任务;
|
|
14
|
+
4. 按需 drill 进具体页面(先查 `index.md` 再读页)。
|
|
14
15
|
|
|
15
16
|
## 四个操作
|
|
16
17
|
|