dsh-memu-memory 1.4.0 → 1.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/AGENTS.md +2 -0
- package/CHANGELOG.md +36 -0
- package/README.md +4 -1
- package/README.zh.md +4 -1
- package/docs/client-conventions.md +3 -0
- package/docs/mcp-porting.md +146 -0
- package/docs/memory-semantics.md +4 -2
- package/docs/troubleshooting.md +40 -0
- package/lib/binding-diagnostics.js +1 -1
- package/lib/client.js +223 -120
- package/lib/consolidation-worker.js +11 -3
- package/lib/curator.js +16 -4
- package/lib/cycle.js +75 -4
- package/lib/engine.js +68 -0
- package/lib/index.js +4 -2
- package/lib/inject.js +142 -8
- package/lib/memory.js +123 -21
- package/lib/port-surface.js +82 -0
- package/lib/private.js +49 -13
- package/lib/prompts/private-consolidation.coding.md +3 -1
- package/lib/prompts/private-consolidation.md +2 -0
- package/lib/prompts/private-consolidation.mixed.md +2 -0
- package/lib/prompts/private-consolidation.rp.md +2 -0
- package/lib/prompts/system-guide.coding.md +8 -2
- package/lib/prompts/system-guide.md +6 -0
- package/lib/prompts/system-guide.mixed.md +11 -0
- package/lib/prompts/system-guide.rp.md +6 -0
- package/lib/rpc.js +19 -5
- package/lib/tools.js +25 -0
- package/lib/turn-log.js +34 -11
- package/lib/worker-pool.js +11 -7
- package/package.json +2 -1
- package/tests/browser.test.mjs +21 -0
- package/tests/client-export.test.mjs +1 -0
- package/tests/client-render.test.mjs +1 -0
- package/tests/consolidation-fork.test.mjs +20 -1
- package/tests/curator-probe.test.mjs +19 -1
- package/tests/engine.test.mjs +60 -0
- package/tests/help-page.test.mjs +1 -0
- package/tests/inject-guide.test.mjs +108 -1
- package/tests/new-session-gate.test.mjs +1 -0
- package/tests/port-surface.test.mjs +138 -0
- package/tests/prompts.test.mjs +30 -0
- package/tests/react-snapshot.test.mjs +1 -0
- package/tests/salience-domain.test.mjs +34 -0
- package/tests/settings-beat.test.mjs +1 -0
- package/tests/sidebar-beat.test.mjs +1 -0
- package/tests/stale-maintenance.test.mjs +131 -0
- package/tests/turn-log.test.mjs +13 -0
- package/tests/webui.test.mjs +8 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// 移植入口(lib/port-surface.js)的契约测试。
|
|
2
|
+
//
|
|
3
|
+
// 这里模拟的是「没有宿主」的调用方(MCP server / CLI):没有 ctx、没有会话、没有
|
|
4
|
+
// 注入钩子,只有 libraryId 和工具规格。任何一条挂掉都意味着移植方会踩坑,而这些
|
|
5
|
+
// 坑在宿主内是测不到的。
|
|
6
|
+
import test from 'node:test'
|
|
7
|
+
import assert from 'node:assert/strict'
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
import os from 'node:os'
|
|
10
|
+
import path from 'node:path'
|
|
11
|
+
|
|
12
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-memory-port-'))
|
|
13
|
+
process.env.DSH_MEMU_HOME = home
|
|
14
|
+
|
|
15
|
+
// 只从公开入口取能力:适配器就该这么用,测试顺带证明入口自洽。
|
|
16
|
+
const port = await import('../lib/port-surface.js')
|
|
17
|
+
const { createLibrary, ensureSession, loadPrivateIndex, savePrivateIndex, setWorkspacePolicy } = await import('../lib/state.js')
|
|
18
|
+
|
|
19
|
+
test.after(() => {
|
|
20
|
+
try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
function seed(libraryId, id, entry) {
|
|
24
|
+
const index = loadPrivateIndex(libraryId)
|
|
25
|
+
index.entries[id] = {
|
|
26
|
+
layer: 'long_term', title: id, content: `body of ${id}`, status: 'active',
|
|
27
|
+
createdAt: '2026-11-01T00:00:00.000Z', ...entry,
|
|
28
|
+
}
|
|
29
|
+
savePrivateIndex(libraryId, index)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
test('collectToolSpecs hands out every hosted tool as plain data', () => {
|
|
33
|
+
const specs = port.collectToolSpecs()
|
|
34
|
+
// 宿主实际挂的就是这 14 个(私有读写 + 词典 + 全局 + status);这个数字变了
|
|
35
|
+
// 说明工具面本身变了,移植方需要重新核对,所以守住它。
|
|
36
|
+
assert.ok(specs.length >= 14, `expected the full tool set, got ${specs.length}`)
|
|
37
|
+
const names = new Set(specs.map((spec) => spec.name))
|
|
38
|
+
for (const required of ['memu_private_recall', 'memu_private_remember', 'memu_private_list', 'memu_status']) {
|
|
39
|
+
assert.ok(names.has(required), `${required} must be part of the surface`)
|
|
40
|
+
}
|
|
41
|
+
for (const spec of specs) {
|
|
42
|
+
assert.equal(typeof spec.name, 'string')
|
|
43
|
+
assert.ok(spec.name.startsWith('memu_'), `unexpected tool name ${spec.name}`)
|
|
44
|
+
assert.equal(typeof spec.description, 'string')
|
|
45
|
+
assert.ok(spec.description.length > 0, `${spec.name} must carry a description`)
|
|
46
|
+
assert.equal(typeof spec.parameters, 'object')
|
|
47
|
+
assert.equal(typeof spec.execute, 'function')
|
|
48
|
+
}
|
|
49
|
+
// 幂等:再问一次不该多也不该少(内部会重跑一遍 registerTools)。
|
|
50
|
+
assert.equal(port.collectToolSpecs().length, specs.length, 'asking twice must not change the set')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('toInputSchema lifts host required flags into a JSON Schema array', () => {
|
|
54
|
+
const specs = port.collectToolSpecs()
|
|
55
|
+
const recall = specs.find((spec) => spec.name === 'memu_private_recall')
|
|
56
|
+
assert.ok(recall, 'memu_private_recall must be part of the surface')
|
|
57
|
+
const schema = port.toInputSchema(recall.parameters)
|
|
58
|
+
assert.equal(schema.type, 'object')
|
|
59
|
+
assert.ok(Array.isArray(schema.required), 'required must be an array')
|
|
60
|
+
assert.ok(schema.required.includes('query'), 'query is a required parameter in the host DSL')
|
|
61
|
+
assert.equal(schema.properties.query.type, 'string')
|
|
62
|
+
// 宿主方言的 required 是属性上的布尔,不能漏进 JSON Schema。
|
|
63
|
+
assert.equal(schema.properties.query.required, undefined, 'per-property required must not survive')
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('privateRecall serves an explicit library with no session at all', async () => {
|
|
67
|
+
const lib = createLibrary({ name: 'port-recall', cwd: path.join(home, 'port-recall') })
|
|
68
|
+
seed(lib.id, 'mem-port-1', { title: '主题偏好', content: '用户偏好深色主题,讨厌弹窗。' })
|
|
69
|
+
const result = await port.privateRecall({ libraryId: lib.id, query: '深色主题' })
|
|
70
|
+
assert.ok(result && Array.isArray(result.files), 'recall must return a files array')
|
|
71
|
+
assert.ok(result.files.some((file) => file.name === 'mem-port-1'), 'the seeded memory must be recalled')
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('privateRecall without a session and without a library still refuses', async () => {
|
|
75
|
+
await assert.rejects(() => port.privateRecall({ query: 'x' }), /no bound session/)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
test('an unknown libraryId is rejected instead of silently returning nothing', async () => {
|
|
79
|
+
// loadPrivateIndex 对未知库给的是空索引,不校验就会变成「静默零命中」——
|
|
80
|
+
// 对一个拼错的 libraryId 来说,安静的空结果比报错更难查。
|
|
81
|
+
await assert.rejects(
|
|
82
|
+
() => port.privateRecall({ libraryId: 'lib-does-not-exist', query: 'x' }),
|
|
83
|
+
/unknown library/,
|
|
84
|
+
)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('an explicit library never pulls in a sibling library', async () => {
|
|
88
|
+
const a = createLibrary({ name: 'port-own-a', cwd: path.join(home, 'port-own-a') })
|
|
89
|
+
const b = createLibrary({ name: 'port-own-b', cwd: path.join(home, 'port-own-b') })
|
|
90
|
+
seed(a.id, 'mem-own', { content: '只在 A 库里的锚点词 蓝色钥匙' })
|
|
91
|
+
seed(b.id, 'mem-foreign', { content: '只在 B 库里的锚点词 蓝色钥匙' })
|
|
92
|
+
const result = await port.privateRecall({ libraryId: a.id, query: '蓝色钥匙' })
|
|
93
|
+
assert.ok(result.files.length > 0, 'the owning library must still answer')
|
|
94
|
+
assert.ok(
|
|
95
|
+
result.files.every((file) => (file.libraryId || a.id) === a.id),
|
|
96
|
+
'no cross-library rows without a session',
|
|
97
|
+
)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
test('a bound session keeps behaving as before', async () => {
|
|
101
|
+
const cwd = path.join(home, 'port-bound')
|
|
102
|
+
const lib = createLibrary({ name: 'port-bound', cwd })
|
|
103
|
+
seed(lib.id, 'mem-bound', { content: '会话里的锚点词 红色雨伞' })
|
|
104
|
+
ensureSession('port-session-1', { cwd, libraryId: lib.id })
|
|
105
|
+
const exec = { agent: { session: { header: { id: 'port-session-1', cwd } } } }
|
|
106
|
+
const result = await port.privateRecall({ exec, query: '红色雨伞' })
|
|
107
|
+
assert.ok(result.files.some((file) => file.name === 'mem-bound'), 'the bound session path must be unchanged')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('privateRemember writes with only a libraryId', async () => {
|
|
111
|
+
const lib = createLibrary({ name: 'port-write', cwd: path.join(home, 'port-write') })
|
|
112
|
+
await port.privateRemember({ libraryId: lib.id, content: '无会话也能写,但必须显式给库。', title: '无会话写入' })
|
|
113
|
+
const listed = await port.privateList({ libraryId: lib.id })
|
|
114
|
+
// privateList 返回的是原始行(标题在 entry 里);privateListView 才做顶层投影。
|
|
115
|
+
assert.ok(
|
|
116
|
+
(listed.files || []).some((file) => (file.entry?.title || file.title) === '无会话写入'),
|
|
117
|
+
'the written memory must be listed from the same library',
|
|
118
|
+
)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test('a folder that turned private memory off stays off for session-less callers', async () => {
|
|
122
|
+
const lib = createLibrary({ name: 'port-disabled', cwd: path.join(home, 'port-disabled') })
|
|
123
|
+
setWorkspacePolicy(lib.scopeKey, { useLibrary: false })
|
|
124
|
+
try {
|
|
125
|
+
await assert.rejects(
|
|
126
|
+
() => port.privateRemember({ libraryId: lib.id, content: 'x', title: 'x' }),
|
|
127
|
+
/disabled for this folder/,
|
|
128
|
+
'a disabled folder must not accept writes just because the caller has no session',
|
|
129
|
+
)
|
|
130
|
+
await assert.rejects(
|
|
131
|
+
() => port.privateRecall({ libraryId: lib.id, query: 'x' }),
|
|
132
|
+
/disabled for this folder/,
|
|
133
|
+
'a disabled folder must not serve reads either',
|
|
134
|
+
)
|
|
135
|
+
} finally {
|
|
136
|
+
setWorkspacePolicy(lib.scopeKey, { useLibrary: true })
|
|
137
|
+
}
|
|
138
|
+
})
|
package/tests/prompts.test.mjs
CHANGED
|
@@ -283,3 +283,33 @@ test('local consolidation adds actual tools while the shared domain body stays b
|
|
|
283
283
|
assert.equal(text.includes('你没有记忆工具'), false)
|
|
284
284
|
}
|
|
285
285
|
})
|
|
286
|
+
|
|
287
|
+
test('every memory guide ships the tool timing map, in all four domains', () => {
|
|
288
|
+
const vars = { mustRememberCap: 12, unpinBudget: 2, shortTermTtlHours: 72, anchorTokens: 800, turnTokens: 800 }
|
|
289
|
+
for (const domain of ['general', 'coding', 'rp', 'mixed']) {
|
|
290
|
+
const text = prompts.loadPromptForDomain('system-guide', vars, domain).text
|
|
291
|
+
for (const tool of ['memu_private_recall', 'memu_global_recall', 'memu_private_remember',
|
|
292
|
+
'memu_private_update', 'memu_private_list', 'memu_status', 'memu_private_archive', 'memu_private_unpin']) {
|
|
293
|
+
assert.ok(text.includes(tool), `${domain}: the first-step guide must say when to use ${tool}`)
|
|
294
|
+
}
|
|
295
|
+
assert.match(text, /link|lexicon/, `${domain}: consolidation-only tools are fenced off`)
|
|
296
|
+
assert.match(text, /remember_batch/, `${domain}: several facts in one call are pointed at the batch tool`)
|
|
297
|
+
}
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
test('the consolidation brief switches to the engineering value order for coding', async () => {
|
|
301
|
+
const { buildWorkerBrief } = await import('../lib/consolidation-worker.js')
|
|
302
|
+
const snapshot = { fromSeq: 1, throughSeq: 2, eventCount: 2, hash: 'coding-brief' }
|
|
303
|
+
const coding = buildWorkerBrief({ snapshot, probe: null, contract: '', domain: 'coding' })
|
|
304
|
+
assert.match(coding, /根因与修复理由/)
|
|
305
|
+
assert.match(coding, /不受「普通事实最多 3 条」限制/)
|
|
306
|
+
assert.match(coding, /每窗最多新增 8 条/)
|
|
307
|
+
assert.match(coding, /150–350 字/)
|
|
308
|
+
assert.match(coding, /路径 \+ 符号/)
|
|
309
|
+
assert.doesNotMatch(coding, /只保留人物、地点、时间、事情、原话/)
|
|
310
|
+
for (const domain of ['rp', 'general', 'mixed']) {
|
|
311
|
+
const brief = buildWorkerBrief({ snapshot, probe: null, contract: '', domain })
|
|
312
|
+
assert.match(brief, /约定\/承诺 = 新人物首次出现/, `${domain}: the people-first order stays for non-coding domains`)
|
|
313
|
+
assert.match(brief, /content 写 50–150 字/, `${domain}: non-coding content length is unchanged`)
|
|
314
|
+
}
|
|
315
|
+
})
|
|
@@ -6,6 +6,7 @@ const React = {
|
|
|
6
6
|
createElement: (type, props, ...children) => typeof type === 'function' ? type({ ...props, children }) : { type, props, children },
|
|
7
7
|
Fragment: Symbol('fragment'),
|
|
8
8
|
useState: value => [typeof value === 'function' ? value() : value, () => {}],
|
|
9
|
+
memo: (component) => component,
|
|
9
10
|
useMemo: fn => fn(), useCallback: fn => fn, useEffect: () => {}, useRef: value => ({ current: value }),
|
|
10
11
|
useSyncExternalStore: (_subscribe, snapshot) => {
|
|
11
12
|
const first = snapshot()
|
|
@@ -137,3 +137,37 @@ test('candidateSeedEvents honours domain without changing defaults', () => {
|
|
|
137
137
|
const coding = candidateSeedEvents(events, { domain: 'coding' })
|
|
138
138
|
assert.deepEqual(coding.map((event) => event.seq), [0, 1, 2, 3, 4, 5, 6, 7, 8], 'coding keeps the English turn and its neighbours')
|
|
139
139
|
})
|
|
140
|
+
|
|
141
|
+
test('coding seed selection keeps tool turns and weak signals; general keeps neither', () => {
|
|
142
|
+
const group = (base, text, withTool) => {
|
|
143
|
+
const events = [
|
|
144
|
+
{ type: 'turn/start', seq: base, data: { turn: base } },
|
|
145
|
+
{ type: 'user/message', seq: base + 1, data: { source: { kind: 'user' }, content: [{ type: 'text', text }] } },
|
|
146
|
+
]
|
|
147
|
+
if (withTool) events.push({ type: 'tool/call', seq: base + 2, data: { callId: 'c' + base, name: 'edit', arguments: '{}' } })
|
|
148
|
+
events.push({ type: 'turn/end', seq: base + 3, data: { turn: base, reason: { kind: 'completed' } } })
|
|
149
|
+
return events
|
|
150
|
+
}
|
|
151
|
+
const events = [
|
|
152
|
+
...group(0, '改一下那个函数', true),
|
|
153
|
+
...group(10, '闲聊而已', false),
|
|
154
|
+
...group(20, '我答应月底之前把伞还给你', false),
|
|
155
|
+
...group(30, '第 0 段普通的记录', false),
|
|
156
|
+
...group(40, '第 1 段普通的记录', false),
|
|
157
|
+
...group(50, '第 2 段普通的记录', false),
|
|
158
|
+
...group(60, '重构一下这段', false),
|
|
159
|
+
...group(70, '第 3 段普通的记录', false),
|
|
160
|
+
...group(80, '第 4 段普通的记录', false),
|
|
161
|
+
...group(90, '第 5 段普通的记录', false),
|
|
162
|
+
...group(100, '第 6 段普通的记录', false),
|
|
163
|
+
]
|
|
164
|
+
const seqs = (list) => new Set(list.map((event) => event.seq))
|
|
165
|
+
const coding = seqs(candidateSeedEvents(events, { domain: 'coding' }))
|
|
166
|
+
const general = seqs(candidateSeedEvents(events, { domain: 'general' }))
|
|
167
|
+
assert.ok(coding.has(1), 'coding keeps a turn whose only evidence is a tool call')
|
|
168
|
+
assert.ok(coding.has(61), 'coding keeps a single weak signal (one point)')
|
|
169
|
+
assert.ok(coding.has(11), 'the neighbour of a kept turn stays')
|
|
170
|
+
assert.equal(general.has(1), false, 'general still drops the tool-only turn')
|
|
171
|
+
assert.equal(general.has(61), false, 'general still needs two points')
|
|
172
|
+
assert.ok(general.has(21), 'a strong signal keeps the turn for general too')
|
|
173
|
+
})
|
|
@@ -25,6 +25,7 @@ const React = {
|
|
|
25
25
|
if (hooks[index] === undefined) hooks[index] = typeof initial === "function" ? initial() : initial
|
|
26
26
|
return [hooks[index], (next) => { hooks[index] = typeof next === "function" ? next(hooks[index]) : next }]
|
|
27
27
|
},
|
|
28
|
+
memo: (component) => component,
|
|
28
29
|
useCallback: (fn) => fn,
|
|
29
30
|
useMemo: (fn) => fn(),
|
|
30
31
|
useEffect(fn, deps) { effects.push({ fn, deps }) },
|
|
@@ -25,6 +25,7 @@ const React = {
|
|
|
25
25
|
if (hooks[index] === undefined) hooks[index] = typeof initial === "function" ? initial() : initial
|
|
26
26
|
return [hooks[index], (next) => { hooks[index] = typeof next === "function" ? next(hooks[index]) : next }]
|
|
27
27
|
},
|
|
28
|
+
memo: (component) => component,
|
|
28
29
|
useCallback: (fn) => fn,
|
|
29
30
|
useMemo: (fn) => fn(),
|
|
30
31
|
useEffect(fn, deps) { effects.push({ fn, deps }) },
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
|
|
7
|
+
// 逾期与过时的收尾:过期草稿的保留期归档、逾期承诺的周期提示,
|
|
8
|
+
// 以及整理任务书里的欠账清单。三者都只做"标出来",不替人裁决事实。
|
|
9
|
+
|
|
10
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-memory-stale-'))
|
|
11
|
+
process.env.DSH_MEMU_HOME = home
|
|
12
|
+
|
|
13
|
+
const state = await import('../lib/state.js')
|
|
14
|
+
const memory = await import('../lib/memory.js')
|
|
15
|
+
const cycle = await import('../lib/cycle.js')
|
|
16
|
+
const activity = await import('../lib/activity-log.js')
|
|
17
|
+
const privateMod = await import('../lib/private.js')
|
|
18
|
+
|
|
19
|
+
test.after(() => {
|
|
20
|
+
try { fs.rmSync(home, { recursive: true, force: true }) } catch {}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
function dayKey(offsetDays) {
|
|
24
|
+
const date = new Date()
|
|
25
|
+
date.setDate(date.getDate() + offsetDays)
|
|
26
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isoDaysAgo(days) {
|
|
30
|
+
return new Date(Date.now() - days * 86_400_000).toISOString()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function bindingFor(sessionId, folder) {
|
|
34
|
+
return state.ensureSession(sessionId, { cwd: path.join(home, folder), agentPreset: 'coding' })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function putEntry(binding, id, patch = {}) {
|
|
38
|
+
const index = state.loadPrivateIndex(binding.libraryId)
|
|
39
|
+
index.entries[id] = {
|
|
40
|
+
track: 'memory',
|
|
41
|
+
layer: 'long_term',
|
|
42
|
+
title: id,
|
|
43
|
+
content: 'body of ' + id,
|
|
44
|
+
status: 'active',
|
|
45
|
+
createdAt: isoDaysAgo(20),
|
|
46
|
+
updatedAt: isoDaysAgo(20),
|
|
47
|
+
...patch,
|
|
48
|
+
}
|
|
49
|
+
state.savePrivateIndex(binding.libraryId, index)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function entryOf(binding, id) {
|
|
53
|
+
return state.loadPrivateIndex(binding.libraryId).entries[id]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
test('expired drafts are archived after the retention window, never deleted', () => {
|
|
57
|
+
const binding = bindingFor('stale-archive', 'proj-archive')
|
|
58
|
+
putEntry(binding, 'draft-old', { layer: 'short_term', status: 'expired', expiredAt: isoDaysAgo(40), expiresAt: isoDaysAgo(40) })
|
|
59
|
+
putEntry(binding, 'draft-legacy', { layer: 'short_term', status: 'expired', expiresAt: isoDaysAgo(45) })
|
|
60
|
+
putEntry(binding, 'draft-fresh', { layer: 'short_term', status: 'expired', expiredAt: isoDaysAgo(5), expiresAt: isoDaysAgo(5) })
|
|
61
|
+
putEntry(binding, 'still-active', { layer: 'short_term', expiresAt: isoDaysAgo(1) })
|
|
62
|
+
|
|
63
|
+
const sweep = memory.archiveExpiredDrafts()
|
|
64
|
+
const archived = new Set(sweep.archived.map((row) => row.id))
|
|
65
|
+
assert.ok(archived.has('draft-old'), 'past the retention window → archived')
|
|
66
|
+
assert.ok(archived.has('draft-legacy'), 'legacy expired rows fall back to expiresAt')
|
|
67
|
+
assert.equal(archived.has('draft-fresh'), false, 'inside the retention window → left for promotion')
|
|
68
|
+
assert.equal(archived.has('still-active'), false, 'a live draft is not touched')
|
|
69
|
+
|
|
70
|
+
const old = entryOf(binding, 'draft-old')
|
|
71
|
+
assert.equal(old.status, 'archived')
|
|
72
|
+
assert.ok(old.archivedAt)
|
|
73
|
+
assert.ok(old.content.includes('body of draft-old'), 'archiving keeps the text')
|
|
74
|
+
assert.equal(entryOf(binding, 'draft-fresh').status, 'expired', 'status is unchanged while inside the window')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('overdueOpenCommitments only returns open commitments past due by the threshold', () => {
|
|
78
|
+
const binding = bindingFor('stale-overdue', 'proj-overdue')
|
|
79
|
+
putEntry(binding, 'owes-10d', { commitment: { action: '陪复习', counterparty: '主人', due_at: dayKey(-10), status: 'open' } })
|
|
80
|
+
putEntry(binding, 'owes-2d', { commitment: { action: '买猫粮', due_at: dayKey(-2), status: 'open' } })
|
|
81
|
+
putEntry(binding, 'due-tomorrow', { commitment: { action: '交周报', due_at: dayKey(1), status: 'open' } })
|
|
82
|
+
putEntry(binding, 'already-done', { commitment: { action: '回消息', due_at: dayKey(-9), status: 'done' } })
|
|
83
|
+
putEntry(binding, 'marginal', { marginalized: true, commitment: { action: '旧账', due_at: dayKey(-9), status: 'open' } })
|
|
84
|
+
|
|
85
|
+
const rows = memory.overdueOpenCommitments({ libraryId: binding.libraryId, minOverdueDays: 7 })
|
|
86
|
+
const ids = rows.map((row) => row.id)
|
|
87
|
+
assert.deepEqual(ids, ['owes-10d'])
|
|
88
|
+
assert.equal(rows[0].daysOverdue, 10)
|
|
89
|
+
|
|
90
|
+
const loose = memory.overdueOpenCommitments({ libraryId: binding.libraryId, minOverdueDays: 0 }).map((row) => row.id)
|
|
91
|
+
assert.ok(loose.includes('owes-2d'), 'minOverdueDays=0 lists every overdue promise')
|
|
92
|
+
assert.equal(loose.includes('due-tomorrow'), false)
|
|
93
|
+
assert.equal(loose.includes('already-done'), false)
|
|
94
|
+
assert.equal(loose.includes('marginal'), false)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test('the cycle notes overdue promises once per week and never closes them itself', () => {
|
|
98
|
+
const binding = bindingFor('stale-pass', 'proj-pass')
|
|
99
|
+
putEntry(binding, 'promise-1', { title: '陪主人复习', commitment: { action: '陪复习', counterparty: '主人', due_at: dayKey(-12), status: 'open' } })
|
|
100
|
+
putEntry(binding, 'promise-2', { title: '寄相册', commitment: { action: '寄相册', due_at: dayKey(-8), status: 'open' } })
|
|
101
|
+
|
|
102
|
+
const first = cycle.runOverdueReviewPass(null, { now: Date.now() })
|
|
103
|
+
assert.ok(first.noted >= 2, 'both promises are past the threshold')
|
|
104
|
+
const entry = activity.listEvents({ kind: 'check', limit: 50 }).find((row) => String(row.message).includes('欠账待结案'))
|
|
105
|
+
assert.ok(entry, 'a check entry is written to the activity log')
|
|
106
|
+
assert.ok(entry.detail.ids.includes('promise-1'))
|
|
107
|
+
|
|
108
|
+
const second = cycle.runOverdueReviewPass(null, { now: Date.now() })
|
|
109
|
+
assert.equal(second.noted, 0, 'the same week must not repeat the note')
|
|
110
|
+
|
|
111
|
+
const later = cycle.runOverdueReviewPass(null, { now: Date.now() + 8 * 86_400_000 })
|
|
112
|
+
assert.ok(later.noted >= 2, 'after the repeat window it comes back')
|
|
113
|
+
|
|
114
|
+
assert.equal(entryOf(binding, 'promise-1').commitment.status, 'open', 'status is evidence-driven, never auto-closed')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('the consolidation catalog lists overdue promises so the worker can close them with evidence', () => {
|
|
118
|
+
const binding = bindingFor('stale-catalog', 'proj-catalog')
|
|
119
|
+
putEntry(binding, 'catalog-owe', {
|
|
120
|
+
title: '答应陪主人复习',
|
|
121
|
+
commitment: { action: '陪复习', counterparty: '主人', due_at: dayKey(-5), status: 'open' },
|
|
122
|
+
})
|
|
123
|
+
const event = privateMod.memoryCatalogEvent({ ...binding, sessionId: 'stale-catalog' })
|
|
124
|
+
assert.ok(event, 'the catalog event is produced')
|
|
125
|
+
const text = String(event.data?.content?.[0]?.text || '')
|
|
126
|
+
assert.ok(text.includes('欠账'), 'the catalog carries an overdue section')
|
|
127
|
+
assert.ok(text.includes('[catalog-owe]'))
|
|
128
|
+
assert.ok(text.includes('已逾期 5 天'))
|
|
129
|
+
assert.ok(text.includes('对 主人:陪复习'))
|
|
130
|
+
assert.ok(text.includes('done'), 'the instruction names the closing statuses')
|
|
131
|
+
})
|
package/tests/turn-log.test.mjs
CHANGED
|
@@ -472,3 +472,16 @@ test('a deleted session (sessionGone) loses its log on session/disposed', () =>
|
|
|
472
472
|
assert.ok(fs.existsSync(turnLog.turnLogPath('rec-alive')))
|
|
473
473
|
dispose()
|
|
474
474
|
})
|
|
475
|
+
|
|
476
|
+
test('coding tool lines keep 600 chars of arguments and error text instead of 160', () => {
|
|
477
|
+
const args = '{"cmd":"npm test -- --grep memory","pad":"' + 'a'.repeat(400) + '"}'
|
|
478
|
+
const tools = [['c1', 'bash', args, 'E'.repeat(800), true]]
|
|
479
|
+
const plain = turnLog.buildTurnRecords(oneTurn({ user: '跑测试', tools }), { tools: 'summary' })[0].tools[0]
|
|
480
|
+
const coding = turnLog.buildTurnRecords(oneTurn({ user: '跑测试', tools }), { tools: 'summary', ...turnLog.turnLogLimits('coding') })[0].tools[0]
|
|
481
|
+
assert.ok(plain.length <= turnLog.TURNLOG_TOOL_LINE_CHARS + 1)
|
|
482
|
+
assert.ok(coding.length > turnLog.TURNLOG_TOOL_LINE_CHARS, 'the coding cap is wider than the default')
|
|
483
|
+
assert.ok(coding.length <= turnLog.TURNLOG_TOOL_LINE_CHARS_CODING + 1)
|
|
484
|
+
assert.ok(coding.includes('npm test'), 'the command survives in coding mode')
|
|
485
|
+
assert.ok(coding.includes('E'.repeat(20)), 'the error output tail survives in coding mode')
|
|
486
|
+
assert.equal(turnLog.turnLogLimits('rp').toolLineChars, turnLog.TURNLOG_TOOL_LINE_CHARS)
|
|
487
|
+
})
|
package/tests/webui.test.mjs
CHANGED
|
@@ -200,6 +200,12 @@ test('single-library browseWall still carries global rows and F1/F2 metadata', a
|
|
|
200
200
|
|
|
201
201
|
const wall = await dispatch({}, 'browseWall', { libraryId: library.id })
|
|
202
202
|
assert.ok(wall.items.some((item) => item.id === 'mem-private-merge'), 'the authorized private row is present')
|
|
203
|
+
// 记忆墙按 offset 逐批读完整库:分页不得改变 total,也不得重排(新到旧)。
|
|
204
|
+
const wallPage = await dispatch({}, 'browseWall', { libraryId: library.id, limit: 1, offset: 1 })
|
|
205
|
+
assert.equal(wallPage.offset, 1)
|
|
206
|
+
assert.equal(wallPage.total, wall.total, 'paging must not change the total')
|
|
207
|
+
assert.equal(wallPage.items.length, 1)
|
|
208
|
+
assert.equal(wallPage.items[0].id, wall.items[1].id, 'offset continues the same sorted list')
|
|
203
209
|
const globalRow = wall.items.find((item) => item.id === 'gmem-linked')
|
|
204
210
|
assert.ok(globalRow, 'a single-library wall must keep the shared global scope')
|
|
205
211
|
assert.equal(globalRow.libraryId, null)
|
|
@@ -214,7 +220,8 @@ test('single-library browseWall still carries global rows and F1/F2 metadata', a
|
|
|
214
220
|
|
|
215
221
|
const source = fs.readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
|
|
216
222
|
assert.match(source, /wallAllBlocked/, 'the single-library fallback explains itself')
|
|
217
|
-
assert.match(source, /
|
|
223
|
+
assert.match(source, /const stream = async \(targetLibraryId\)/, 'the wall reads the library in batches')
|
|
224
|
+
assert.match(source, /await stream\(firstLibraryId\)/, 'the wall retries the first library after an all-libraries 403')
|
|
218
225
|
assert.match(source, /setMultiBlocked\(true\)/, 'the fallback disables the all-libraries option')
|
|
219
226
|
})
|
|
220
227
|
test('the settings button preserves the host SPA and links to individual pages', () => {
|