dsh-lite-memory 0.2.1 → 0.2.3

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 CHANGED
@@ -16,7 +16,7 @@ Lightweight memory for the DeepSeek Harness. Nothing in the system prompt, nothi
16
16
  | 场景 | 行为 |
17
17
  | --- | --- |
18
18
  | **L0** 你明确要求「记住这个」 | 立即写盘,一条确认行 |
19
- | **L1** 它发现有跨会话价值的经验 | 一行灰字 `可记「X」` + 一个 `保留` 按钮;不点就永远不写 |
19
+ | **L1** 它发现有跨会话价值的经验 | 一行灰字 `可记「X」` + 一个 `保留` 按钮;不写问句、不用你打字,不点就永远不写,48 小时内不重复 |
20
20
  | **L2** 常识、一次性参数、凭据的值 | 永不写入 |
21
21
 
22
22
  触发词:`记住`、`记一下`、`上次`、`规范`、`约定`、`路径`、`凭据怎么取`。
@@ -24,7 +24,7 @@ Lightweight memory for the DeepSeek Harness. Nothing in the system prompt, nothi
24
24
  | Case | Behaviour |
25
25
  | --- | --- |
26
26
  | **L0** you ask it to remember | written immediately, one confirmation line |
27
- | **L1** it spots something worth keeping | one muted line `可记「X」` with a single `保留` button — nothing is written unless you click |
27
+ | **L1** it spots something worth keeping | one muted line `可记「X」` with a single `保留` button — never a question, no typing, nothing written unless you click, at most once per two days |
28
28
  | **L2** common sense, one-off parameters, credential values | never written |
29
29
 
30
30
  ## 点一下就存 / One click, no turn
package/TRIGGERS.md CHANGED
@@ -13,8 +13,8 @@
13
13
  模型不会常驻读记忆。触发全靠工具描述里的触发词,命中才调。
14
14
 
15
15
  - 查:用户说「上次 / 之前 / 记住过 / 规范 / 约定 / 路径 / 凭据怎么取」,或要做的事像是在这个项目里做过。
16
- - 写:用户明确要求;或用户对某条建议点了「保留」。
17
- - 建议:一条经验能跨会话复用、又只存在于用户嘴里(偏好、惯例、踩过的坑),且同一项目 24 小时内没建议过。
16
+ - 写:用户明确要求;用户自己的话已经是长期规则(「以后都这样 / 别再 X」)时直接存,不先问;或用户对某条建议点了「保留」。
17
+ - 建议:一条经验能跨会话复用、又只存在于用户嘴里(偏好、惯例、踩过的坑),且同一项目 48 小时内没建议过。只出按钮,不写「要不要记」这种问句——问句要用户打字,按钮不要。
18
18
  - 不写:`1+1=2` 这种常识、一次性任务参数、能从仓库直接读到的正文;凭据只记位置与调用方式。
19
19
 
20
20
  ## 触发后长什么样
@@ -34,7 +34,7 @@
34
34
 
35
35
  ## 频率与退让
36
36
 
37
- - 建议:同一项目 24 小时一条;同一主题存过就不再建议。
37
+ - 建议:同一项目 48 小时一条、一次对话最多一条;同一主题存过就不再建议。
38
38
  - 结果:搜索最多 4 条、400 字;全文只在 `memory_read` 里出现。
39
39
  - 用户说「别记」→ `memory_forget` 归档,不删文件。
40
40
  - 拒绝三次后仍反复建议,说明触发词太宽:收窄 `memory_suggest` 的描述,而不是加状态。
package/index.js CHANGED
@@ -145,7 +145,7 @@ export function apply(ctx) {
145
145
 
146
146
  ctx.effect(() => tools.register({
147
147
  name: 'memory_save',
148
- description: `保存一条记忆。仅在用户明确要求记住,或用户确认保留时才调用。用户发「保留记忆「X」」时,用当时那条建议的内容调用本工具。${NOTES}`,
148
+ description: `保存一条记忆。用户明确说「记住」时直接调用;用户自己的话已经是长期规则(「以后都这样」「别再 X」)时也直接调用,不要先问。用户点了「保留」或发「保留记忆「X」」时,用那条建议的内容调用。${NOTES}`,
149
149
  parameters: SAVE_PARAMS,
150
150
  output: {
151
151
  schema: {
@@ -172,7 +172,7 @@ export function apply(ctx) {
172
172
 
173
173
  ctx.effect(() => tools.register({
174
174
  name: 'memory_suggest',
175
- description: `对一条值得长期保留、但用户没有明说的经验提出保存建议。用户点「保留」才保存,不点就不保存。每次会话最多用一次;同一项目 24 小时内不会重复建议。${NOTES}`,
175
+ description: `对一条用户没说、但跨会话还有用的经验提出保存建议。调用后对话里出现一个「保留」按钮,用户点了才保存。不要用问句征询「要不要记」,那要用户打字;按钮不打扰对话。一次对话最多建议一条,问自己「下次会话还得靠它吗」,不确定就别建议。${NOTES}`,
176
176
  parameters: SUGGEST_PARAMS,
177
177
  output: {
178
178
  schema: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lite-memory",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
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",
@@ -26,7 +26,8 @@
26
26
  "icon.svg",
27
27
  "README.md",
28
28
  "TRIGGERS.md",
29
- "LICENSE"
29
+ "LICENSE",
30
+ "test"
30
31
  ],
31
32
  "dsh": {
32
33
  "bundle": {
package/store.js CHANGED
@@ -13,7 +13,7 @@ export const LIMITS = {
13
13
  totalBytes: 512 * 1024,
14
14
  titleChars: 40,
15
15
  summaryChars: 60,
16
- suggestionWindowMs: 24 * 60 * 60 * 1000,
16
+ suggestionWindowMs: 48 * 60 * 60 * 1000,
17
17
  };
18
18
 
19
19
  /** Strings that mean "this is a credential", never a memory. */
@@ -220,14 +220,14 @@ export function forget(scope, id) {
220
220
  return record;
221
221
  }
222
222
 
223
- /** Why a suggestion is refused: one per day per project, and never for a saved topic. */
223
+ /** Why a suggestion is refused: one per two days per project, and never for a saved topic. */
224
224
  export function suggestionGate(scope, title) {
225
225
  const index = loadIndex(scope);
226
226
  const text = normalizeText(title, LIMITS.titleChars);
227
227
  if (index.entries.some((item) => item.title === text)) return { ok: false, reason: '这条已经存过' };
228
228
  const now = Date.now();
229
229
  const recent = index.suggestions.find((item) => now - Date.parse(item.at) < LIMITS.suggestionWindowMs);
230
- if (recent) return { ok: false, reason: `今天已经建议过「${recent.title}」` };
230
+ if (recent) return { ok: false, reason: `48 小时内已建议过「${recent.title}」` };
231
231
  return { ok: true };
232
232
  }
233
233
 
@@ -0,0 +1,65 @@
1
+ import assert from 'node:assert/strict';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import * as store from '../store.js';
6
+
7
+ const home = fs.mkdtempSync(path.join(os.tmpdir(), 'lite-memory-'));
8
+ process.env.DSH_HOME = home;
9
+
10
+ const scope = store.scopeOf('/tmp/project-a');
11
+ const other = store.scopeOf('/tmp/project-b');
12
+ const draft = { title: '插件市场条目规范', summary: '市场上传指南的位置与要点', body: '见 UPLOAD-GUIDE.md', kind: 'pointer', tags: ['marketplace'] };
13
+
14
+ const first = store.upsert(scope, draft);
15
+ assert.equal(first.merged, false);
16
+ assert.equal(store.loadIndex(scope).entries.length, 1);
17
+
18
+ const second = store.upsert(scope, { ...draft, summary: '市场上传指南的位置与要点(更新)' });
19
+ assert.equal(second.merged, true);
20
+ assert.equal(second.record.id, first.record.id);
21
+ assert.equal(store.loadIndex(scope).entries.length, 1);
22
+ assert.equal(store.loadIndex(scope).entries[0].merges, 1);
23
+
24
+ assert.deepEqual(store.search(scope, '插件市场').map((item) => item.id), [first.record.id]);
25
+ assert.deepEqual(store.search(scope, '量子力学'), []);
26
+ assert.deepEqual(store.loadIndex(other).entries, []);
27
+
28
+ assert.throws(() => store.upsert(scope, { title: 'x', summary: '你要记得用 tab 缩进' }), /名词短语/);
29
+ assert.throws(() => store.upsert(scope, { title: 'y', summary: '凭据位置', body: 'ghp_abcdefghijklmnopqrstuvwxyz0123456789' }), /凭据/);
30
+
31
+ const read = store.readEntry(scope, first.record.id);
32
+ assert.match(read.body, /UPLOAD-GUIDE/);
33
+ assert.ok(store.loadIndex(scope).entries[0].hits >= 2);
34
+
35
+ assert.equal(store.suggestionGate(scope, '插件市场条目规范').ok, false);
36
+ store.noteSuggestion(scope, '提交前先跑 lint');
37
+ assert.equal(store.suggestionGate(scope, '另一条').ok, false);
38
+ store.upsert(scope, { title: '提交前先跑 lint', summary: '交付前的文案检查步骤' });
39
+ assert.equal(store.suggestionGate(scope, '新的建议').ok, true);
40
+
41
+ const old = store.upsert(scope, { title: '很久没用到的条目', summary: '三个月没命中', body: 'x' });
42
+ const index = store.loadIndex(scope);
43
+ index.entries = index.entries.map((item) =>
44
+ item.id === old.record.id ? { ...item, lastUsed: new Date(Date.now() - 400 * 86400000).toISOString() } : item,
45
+ );
46
+ store.saveIndex(scope, index);
47
+ const stale = store.loadIndex(scope).entries.find((item) => item.id === old.record.id);
48
+ const rendered = store.renderIndex([stale]);
49
+ assert.equal(rendered.text.includes('|'), false);
50
+ assert.ok(rendered.text.includes(old.record.title));
51
+
52
+ const forgotten = store.forget(scope, first.record.id);
53
+ assert.equal(forgotten.title, draft.title);
54
+ assert.equal(store.loadIndex(scope).entries.some((item) => item.id === first.record.id), false);
55
+ assert.ok(fs.existsSync(path.join(scope.dir, 'archive', `${first.record.id}.md`)));
56
+
57
+ for (let i = 0; i < 240; i += 1) {
58
+ store.upsert(scope, { title: `条目 ${i}`, summary: `第 ${i} 条`, body: 'x' });
59
+ }
60
+ const trimmed = store.loadIndex(scope);
61
+ assert.ok(trimmed.entries.length <= store.LIMITS.entries);
62
+ assert.ok(trimmed.totalBytes <= store.LIMITS.totalBytes);
63
+
64
+ fs.rmSync(home, { recursive: true, force: true });
65
+ console.log('store: 16 checks passed');