dsh-lite-memory 0.2.6 → 0.2.7
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 +2 -2
- package/TRIGGERS.md +9 -0
- package/index.js +1 -1
- package/package.json +1 -1
- package/store.js +37 -7
- package/test/store.test.mjs +15 -0
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Lightweight memory for the DeepSeek Harness. Nothing in the system prompt, nothi
|
|
|
19
19
|
| **L1** 它发现有跨会话价值的经验 | 一行灰字 `memory · keep? "X" — 要记的内容` + 一个 `keep` 按钮;标题加一句话,看得懂才点,不点就永远不写,48 小时内不重复 |
|
|
20
20
|
| **L2** 常识、一次性参数、凭据的值 | 永不写入 |
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
这些行只属于产生它的那一轮:重进会话就没了,历史里只留正文。同一件事再记一次会合并进原条目,不会长成两条。
|
|
23
23
|
|
|
24
24
|
触发词:`记住`、`记一下`、`上次`、`规范`、`约定`、`路径`、`凭据怎么取`。
|
|
25
25
|
|
|
@@ -29,7 +29,7 @@ Lightweight memory for the DeepSeek Harness. Nothing in the system prompt, nothi
|
|
|
29
29
|
| **L1** it spots something worth keeping | one muted line `memory · keep? "X" — what would be remembered` with a single `keep` button — readable before you click, nothing written unless you click, at most once per two days |
|
|
30
30
|
| **L2** common sense, one-off parameters, credential values | never written |
|
|
31
31
|
|
|
32
|
-
Those lines belong to the turn that made them: reopening the session drops them, leaving only the prose in history.
|
|
32
|
+
Those lines belong to the turn that made them: reopening the session drops them, leaving only the prose in history. Recording the same subject again merges into the existing entry instead of adding a second one.
|
|
33
33
|
|
|
34
34
|
## 点一下就存 / One click, no turn
|
|
35
35
|
|
package/TRIGGERS.md
CHANGED
|
@@ -34,6 +34,15 @@
|
|
|
34
34
|
|
|
35
35
|
这些行只属于产生它的那一轮:重进会话时不再显示,历史里只留正文。行出现在调用本身的位置——一轮正在跑时,那就是对话的最下面,不会悬浮在输入框上方。
|
|
36
36
|
|
|
37
|
+
## 什么时候合并,什么时候新建
|
|
38
|
+
|
|
39
|
+
一条约束只留一条。写入前先拿标题和摘要比一遍:够近就合并进原条目(`merges+1`),正文整篇替换;不够近才新建。
|
|
40
|
+
|
|
41
|
+
- 合并:同一件事换措辞、补细节、纠正旧值。标题相邻两字重合 ≥ 0.6,或摘要重合 ≥ 0.75。
|
|
42
|
+
- 新建:同一项目下的另一件事,哪怕标签一样。只共用项目名(「插件市场条目字段」对「插件市场踩坑清单」)不算合并。
|
|
43
|
+
- 合并前先 `memory_read` 旧正文:正文是替换,不是追加,漏读就丢细节。
|
|
44
|
+
- 判不准先 `memory_search`:命中就是同一件事,按命中那条的标题写;没命中再新建。
|
|
45
|
+
|
|
37
46
|
## 频率与退让
|
|
38
47
|
|
|
39
48
|
- 建议:同一项目 48 小时一条、一次对话最多一条;同一主题存过就不再建议。
|
package/index.js
CHANGED
|
@@ -156,7 +156,7 @@ export function apply(ctx) {
|
|
|
156
156
|
|
|
157
157
|
ctx.effect(() => tools.register({
|
|
158
158
|
name: 'memory_save',
|
|
159
|
-
description: `保存一条记忆。用户明确说「记住」时直接调用;用户自己的话已经是长期规则(「以后都这样」「别再 X」)时也直接调用,不要先问。用户点了「保留」或发「保留记忆「X
|
|
159
|
+
description: `保存一条记忆。用户明确说「记住」时直接调用;用户自己的话已经是长期规则(「以后都这样」「别再 X」)时也直接调用,不要先问。用户点了「保留」或发「保留记忆「X」」时,用那条建议的内容调用。更新已知主题时先 memory_read 旧正文再写:标题相同、或标题与摘要高度相近时,会合并进原来那条(merges+1),正文整篇替换,不新增条目。${NOTES}`,
|
|
160
160
|
parameters: SAVE_PARAMS,
|
|
161
161
|
output: {
|
|
162
162
|
schema: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-lite-memory",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "On-demand memory for the DeepSeek Harness: nothing in the system prompt, one muted line only when something is saved, hit or suggested.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/store.js
CHANGED
|
@@ -125,14 +125,44 @@ export function trimIndex(scope, index) {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/** 同一主题的判定线。跨过就合并成一条,跨不过就新建。 */
|
|
129
|
+
export const MERGE = { title: 0.6, summary: 0.75 };
|
|
130
|
+
|
|
131
|
+
/** 相邻两字为一组:中文没有空格,按词切分永远对不上,按字片才认得出改写的同一件事。 */
|
|
132
|
+
function bigrams(text) {
|
|
133
|
+
const plain = normalizeText(text, 400).toLowerCase().replace(/[^\p{L}\p{N}]+/gu, '');
|
|
134
|
+
if (!plain) return new Set();
|
|
135
|
+
if (plain.length < 2) return new Set([plain]);
|
|
136
|
+
const out = new Set();
|
|
137
|
+
for (let i = 0; i + 1 < plain.length; i += 1) out.add(plain.slice(i, i + 2));
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
|
|
128
141
|
function similarity(a, b) {
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
const right = words(b);
|
|
142
|
+
const left = bigrams(a);
|
|
143
|
+
const right = bigrams(b);
|
|
132
144
|
if (left.size === 0 || right.size === 0) return 0;
|
|
133
145
|
let shared = 0;
|
|
134
|
-
for (const
|
|
135
|
-
return shared /
|
|
146
|
+
for (const gram of left) if (right.has(gram)) shared += 1;
|
|
147
|
+
return shared / (left.size + right.size - shared);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** 同标题必合并;否则标题或摘要够像,也当作同一主题的又一次记录。 */
|
|
151
|
+
function mergeCandidate(entries, title, summary) {
|
|
152
|
+
let best = null;
|
|
153
|
+
let bestScore = 0;
|
|
154
|
+
for (const item of entries) {
|
|
155
|
+
if (item.title === title) return item;
|
|
156
|
+
const titleScore = similarity(item.title, title);
|
|
157
|
+
const summaryScore = similarity(item.summary, summary);
|
|
158
|
+
if (titleScore < MERGE.title && summaryScore < MERGE.summary) continue;
|
|
159
|
+
const score = Math.max(titleScore, summaryScore);
|
|
160
|
+
if (score > bestScore) {
|
|
161
|
+
best = item;
|
|
162
|
+
bestScore = score;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return best;
|
|
136
166
|
}
|
|
137
167
|
|
|
138
168
|
/**
|
|
@@ -151,7 +181,7 @@ export function upsert(scope, draft) {
|
|
|
151
181
|
|
|
152
182
|
const index = loadIndex(scope);
|
|
153
183
|
const now = new Date().toISOString();
|
|
154
|
-
const existing = index.entries
|
|
184
|
+
const existing = mergeCandidate(index.entries, title, summary.text);
|
|
155
185
|
const id = existing ? existing.id : `mem_${Date.now().toString(36)}${crypto.randomBytes(2).toString('hex')}`;
|
|
156
186
|
const record = {
|
|
157
187
|
id,
|
|
@@ -172,7 +202,7 @@ export function upsert(scope, draft) {
|
|
|
172
202
|
index.suggestions = (index.suggestions || []).filter((item) => item.title !== title).slice(-19);
|
|
173
203
|
trimIndex(scope, index);
|
|
174
204
|
saveIndex(scope, index);
|
|
175
|
-
return { record, merged: Boolean(existing) };
|
|
205
|
+
return { record, merged: Boolean(existing), mergedFrom: existing && existing.title !== title ? existing.title : null };
|
|
176
206
|
}
|
|
177
207
|
|
|
178
208
|
export function search(scope, query, limit = 4) {
|
package/test/store.test.mjs
CHANGED
|
@@ -63,3 +63,18 @@ assert.ok(trimmed.totalBytes <= store.LIMITS.totalBytes);
|
|
|
63
63
|
|
|
64
64
|
fs.rmSync(home, { recursive: true, force: true });
|
|
65
65
|
console.log('store: 16 checks passed');
|
|
66
|
+
|
|
67
|
+
// 同一主题换个说法:合并,不新增。
|
|
68
|
+
const mergeScope = store.scopeOf('/tmp/project-merge');
|
|
69
|
+
store.upsert(mergeScope, { title: '插件市场条目规范', summary: '市场上传指南的位置与要点', body: '见 UPLOAD-GUIDE.md' });
|
|
70
|
+
const paraphrase = store.upsert(mergeScope, { title: '插件市场条目规范(改写)', summary: '市场上传指南的位置与要点', body: '见 UPLOAD-GUIDE.md#第二节' });
|
|
71
|
+
assert.equal(paraphrase.merged, true);
|
|
72
|
+
assert.equal(paraphrase.mergedFrom, '插件市场条目规范');
|
|
73
|
+
assert.equal(store.loadIndex(mergeScope).entries.length, 1);
|
|
74
|
+
|
|
75
|
+
// 同一项目下的另一件事:不合并。
|
|
76
|
+
const sibling = store.upsert(mergeScope, { title: '插件市场踩坑清单', summary: '卡片不刷新与抓取失败的已知原因', body: 'y' });
|
|
77
|
+
assert.equal(sibling.merged, false);
|
|
78
|
+
assert.equal(store.loadIndex(mergeScope).entries.length, 2);
|
|
79
|
+
|
|
80
|
+
console.log('store: merge rules ok');
|