sage-mem 0.4.0 → 0.4.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.
- package/LICENSE +202 -202
- package/NOTICE +5 -5
- package/README.md +138 -115
- package/cordis.patch.yml +4 -4
- package/lib/client.js +432 -432
- package/lib/index.js +212 -212
- package/lib/typert.host.js +90 -90
- package/package.json +68 -52
package/README.md
CHANGED
|
@@ -1,115 +1,138 @@
|
|
|
1
|
-
# sage-mem · DSH 的文件式记忆插件
|
|
2
|
-
|
|
3
|
-
给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)装上**跨会话记忆**——agent 今天记住的事,明天的新会话自动想起来。
|
|
4
|
-
|
|
5
|
-
记忆存在**本地 markdown 文件**里(frontmatter + 正文),不是数据库。透明、可检查、防膨胀。
|
|
6
|
-
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
1
|
+
# sage-mem · DSH 的文件式记忆插件
|
|
2
|
+
|
|
3
|
+
给 [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)(DSH)装上**跨会话记忆**——agent 今天记住的事,明天的新会话自动想起来。
|
|
4
|
+
|
|
5
|
+
记忆存在**本地 markdown 文件**里(frontmatter + 正文),不是数据库。透明、可检查、防膨胀。
|
|
6
|
+
|
|
7
|
+
## 从 Claude Code 无损迁移
|
|
8
|
+
|
|
9
|
+
你已经在 Claude Code(CC)里养了一个 agent,舍不得它的记忆和人格?sage-mem 是「CC → DSH」迁移方案的一部分,**记忆与人格都能无损搬过来**:
|
|
10
|
+
|
|
11
|
+
- **人格**:CC 的 `CLAUDE.md` → DSH 的 `AGENTS.md`,DSH 原生加载,纯文本一字不改就能用。
|
|
12
|
+
- **记忆**:CC 沉淀的跨会话记忆 → sage-mem 的 `memory/` 目录(markdown + frontmatter,四类)。
|
|
13
|
+
|
|
14
|
+
没有数据库、没有私有格式——全都是 markdown 文本,**直接拷文件就完成迁移**。agent 换了身体,但依然记得你是谁、记得你们聊过什么、记得进行中的项目。
|
|
15
|
+
|
|
16
|
+
## 为什么用文件
|
|
17
|
+
|
|
18
|
+
DSH 原生没有记忆系统,每个会话都是白纸。市面上的记忆方案大多走 SQLite + 常驻 worker:
|
|
19
|
+
|
|
20
|
+
- 记忆写进数据库,**不透明**——想检查存了什么得查表,想清理要连数据库
|
|
21
|
+
- 事件自动捕获会**膨胀**——"用户打了个招呼"这种无实质内容也被存进去
|
|
22
|
+
- 需要一个**常驻 worker 进程** + 端口,多一份运维负担
|
|
23
|
+
|
|
24
|
+
sage-mem 换成文件式:每条记忆一个 markdown 文件,直接用编辑器打开就能看、能改、能删。存不存由 agent 按规则判断,不是事件全捕获。没有 worker、没有 SQLite、没有端口。
|
|
25
|
+
|
|
26
|
+
## 功能
|
|
27
|
+
|
|
28
|
+
- **按问题检索注入**:每次提问,插件扫记忆目录,按相关性把记忆注入 system prompt,agent 第一轮就「想起来」
|
|
29
|
+
- **四类记忆**:`user`(用户是谁)/ `feedback`(工作方式指导)/ `project`(项目状态)/ `reference`(外部信息指针)
|
|
30
|
+
- **文件透明**:记忆就是 `*.md` 文件,frontmatter 存元数据,正文存内容
|
|
31
|
+
- **防膨胀**:写入靠规则引导 agent 判断「存不存」,无实质内容、能靠代码/git 推导的不存
|
|
32
|
+
- **Web 文件管理器**(v0.4):DSH 设置页「记忆管理」,浏览/查看/编辑/删除记忆文件,添加新记忆
|
|
33
|
+
|
|
34
|
+
## 架构
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
DSH(Cordis 插件)
|
|
38
|
+
└─ sage-mem 插件(按问题检索 + 注入)← 本仓库
|
|
39
|
+
│ Node fs 直读
|
|
40
|
+
▼
|
|
41
|
+
memory/ 目录(markdown 文件,4 类)
|
|
42
|
+
├── user_*.md
|
|
43
|
+
├── feedback_*.md
|
|
44
|
+
├── project_*.md
|
|
45
|
+
├── reference_*.md
|
|
46
|
+
└── MEMORY.md ← 索引
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
没有 worker、没有 SQLite、没有 HTTP 端口、没有常驻进程。
|
|
50
|
+
|
|
51
|
+
## 安装
|
|
52
|
+
|
|
53
|
+
在你的 DSH profile 的 `package.json` 里加:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"sage-mem": "github:gezi-wen/sage-mem"
|
|
59
|
+
},
|
|
60
|
+
"dsh": {
|
|
61
|
+
"profile": {
|
|
62
|
+
"bundles": ["sage-mem"]
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
或 clone 后本地 link:
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"dependencies": {
|
|
73
|
+
"sage-mem": "link:../sage-mem"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
然后 `pnpm install` 重启 DSH。
|
|
79
|
+
|
|
80
|
+
## DSH 兼容性
|
|
81
|
+
|
|
82
|
+
sage-mem 是纯 DSH 插件,在 `package.json` 的 `dsh.compatibility.dshReleases` 里逐版本声明兼容状态:
|
|
83
|
+
|
|
84
|
+
| DSH 版本 | 状态 |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| 0.1.2-rc.1 | compatible |
|
|
87
|
+
| 0.1.3-alpha.1 | compatible |
|
|
88
|
+
| 0.1.3-alpha.2 | compatible |
|
|
89
|
+
|
|
90
|
+
Node.js 要求 `>= 18`(见 `engines.node`)。
|
|
91
|
+
|
|
92
|
+
## 卸载
|
|
93
|
+
|
|
94
|
+
在 profile 的 `package.json` 里删掉 `sage-mem` 依赖,并从 `dsh.profile.bundles` 移除 `"sage-mem"`;
|
|
95
|
+
`pnpm install` 后重启 DSH 即可。记忆 markdown 文件留在原目录,不受影响。
|
|
96
|
+
|
|
97
|
+
## 配置
|
|
98
|
+
|
|
99
|
+
用环境变量 `SAGE_MEM_DIR` 指定记忆目录,默认 `~/.sage-mem/memory`:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
SAGE_MEM_DIR=/path/to/your/memory
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
记忆文件格式:
|
|
106
|
+
|
|
107
|
+
```markdown
|
|
108
|
+
---
|
|
109
|
+
name: 可选的短名
|
|
110
|
+
description: 一句话说清这条记忆是什么(检索与列表都靠它)
|
|
111
|
+
metadata:
|
|
112
|
+
type: user # user / feedback / project / reference
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
记忆正文。
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`feedback` 类建议带 `**Why:**`(原因)和 `**How to apply:**`(何时生效)两行,方便判断边界。
|
|
119
|
+
|
|
120
|
+
## 验证
|
|
121
|
+
|
|
122
|
+
跨会话记忆链路(实测):
|
|
123
|
+
|
|
124
|
+
1. 会话 A 说「记住:我的猫叫芝麻,它喜欢晒太阳」——agent 按规则写进 `memory/`
|
|
125
|
+
2. 开新会话 B 问「我的猫叫什么」
|
|
126
|
+
3. agent 第一轮直接答出「芝麻」——记忆自动注入,无需 agent 自己找
|
|
127
|
+
|
|
128
|
+
## 相关项目
|
|
129
|
+
|
|
130
|
+
- [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) — DSH 本体,一切皆插件
|
|
131
|
+
|
|
132
|
+
## 旧版
|
|
133
|
+
|
|
134
|
+
本仓库早期是 SQLite + worker 架构,已归档到 [`sqlite-worker`](../../tree/sqlite-worker) 分支。文件式是继任实现。
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
Apache-2.0
|
package/cordis.patch.yml
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# sage-mem bundle patch — injects the memory bridge plugin into the profile tree.
|
|
2
|
-
- insert:
|
|
3
|
-
- id: sage-mem
|
|
4
|
-
name: 'sage-mem'
|
|
1
|
+
# sage-mem bundle patch — injects the memory bridge plugin into the profile tree.
|
|
2
|
+
- insert:
|
|
3
|
+
- id: sage-mem
|
|
4
|
+
name: 'sage-mem'
|