dsh-memu-memory 1.4.0 → 1.4.1
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/CHANGELOG.md +16 -0
- package/README.md +4 -1
- package/README.zh.md +4 -1
- package/docs/memory-semantics.md +4 -2
- package/docs/troubleshooting.md +26 -0
- package/lib/binding-diagnostics.js +1 -1
- package/lib/consolidation-worker.js +11 -3
- package/lib/curator.js +16 -4
- package/lib/cycle.js +75 -4
- package/lib/index.js +4 -2
- package/lib/inject.js +142 -8
- package/lib/memory.js +72 -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/turn-log.js +34 -11
- package/lib/worker-pool.js +11 -7
- package/package.json +1 -1
- package/tests/consolidation-fork.test.mjs +20 -1
- package/tests/curator-probe.test.mjs +19 -1
- package/tests/inject-guide.test.mjs +108 -1
- package/tests/prompts.test.mjs +30 -0
- package/tests/salience-domain.test.mjs +34 -0
- package/tests/stale-maintenance.test.mjs +131 -0
- package/tests/turn-log.test.mjs +13 -0
|
@@ -74,6 +74,7 @@ function makeTurn(sessionId, options = {}) {
|
|
|
74
74
|
turn = 1,
|
|
75
75
|
text = 'please continue with the earlier context of this task',
|
|
76
76
|
history = [],
|
|
77
|
+
sessionCreatedAt = null,
|
|
77
78
|
} = options
|
|
78
79
|
const user = {
|
|
79
80
|
id: sessionId + '-user-' + turn,
|
|
@@ -82,7 +83,9 @@ function makeTurn(sessionId, options = {}) {
|
|
|
82
83
|
content: [{ type: 'text', text }],
|
|
83
84
|
}
|
|
84
85
|
const decision = { kind: 'enter', messages: [...history, user] }
|
|
85
|
-
const
|
|
86
|
+
const session = { header: { id: sessionId, cwd, agentPreset, origin } }
|
|
87
|
+
if (sessionCreatedAt !== null) session.createdAt = sessionCreatedAt
|
|
88
|
+
const agent = { session }
|
|
86
89
|
const payload = { agent, turn, step, signal: { aborted: false } }
|
|
87
90
|
return { user, decision, payload }
|
|
88
91
|
}
|
|
@@ -186,6 +189,78 @@ function textOf(messages) {
|
|
|
186
189
|
return (messages || []).map((message) => String(message?.content?.[0]?.text || '')).join('\n')
|
|
187
190
|
}
|
|
188
191
|
|
|
192
|
+
test('a recreated session object with the same id re-delivers the guide and the anchor', async () => {
|
|
193
|
+
const sessionId = 'guide-incarnation'
|
|
194
|
+
const cwd = path.join(home, 'project-guide-incarnation')
|
|
195
|
+
const binding = state.ensureSession(sessionId, { cwd, agentPreset: 'coding' })
|
|
196
|
+
seedPinned(binding, 'mem-guide-incarnation', '重启后的锚点')
|
|
197
|
+
const mounted = mountGuide()
|
|
198
|
+
|
|
199
|
+
const first = makeTurn(sessionId, { cwd, sessionCreatedAt: 1_700_000_000_000 })
|
|
200
|
+
const firstOut = await mounted.run(first.payload, first.decision)
|
|
201
|
+
assert.equal(guideMessages(firstOut.messages).length, 1)
|
|
202
|
+
assert.equal(state.getSessionBinding(sessionId).sessionStamp, 'created:1700000000000')
|
|
203
|
+
|
|
204
|
+
const next = makeTurn(sessionId, { cwd, turn: 2, sessionCreatedAt: 1_700_000_000_000 })
|
|
205
|
+
const nextOut = await mounted.run(next.payload, next.decision)
|
|
206
|
+
assert.equal(guideMessages(nextOut.messages).length, 0, '同一会话对象不重发')
|
|
207
|
+
|
|
208
|
+
// 通道用确定性 id 重建同名会话:binding 还是旧的,转录从头开始。
|
|
209
|
+
const revived = makeTurn(sessionId, { cwd, turn: 1, sessionCreatedAt: 1_700_000_100_000 })
|
|
210
|
+
const revivedOut = await mounted.run(revived.payload, revived.decision)
|
|
211
|
+
const revivedGuides = guideMessages(revivedOut.messages)
|
|
212
|
+
assert.equal(revivedGuides.length, 1, '新会话对象必须重新拿到规则')
|
|
213
|
+
assert.ok(textOf(revivedOut.messages).includes('[mem-guide-incarnation]'), '锚点也重新投放')
|
|
214
|
+
const stamped = state.getSessionBinding(sessionId)
|
|
215
|
+
assert.equal(stamped.sessionStamp, 'created:1700000100000')
|
|
216
|
+
assert.equal(stamped.guideRulesKey, guideKey(revivedGuides[0]))
|
|
217
|
+
assert.equal(stamped.guideLost, false)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('without a host createdAt, a first turn on a reused id resets one-shots exactly once', async () => {
|
|
221
|
+
const sessionId = 'guide-turn-reset'
|
|
222
|
+
const cwd = path.join(home, 'project-guide-turn-reset')
|
|
223
|
+
state.ensureSession(sessionId, { cwd, agentPreset: 'coding' })
|
|
224
|
+
const mounted = mountGuide()
|
|
225
|
+
|
|
226
|
+
const first = makeTurn(sessionId, { cwd })
|
|
227
|
+
const firstOut = await mounted.run(first.payload, first.decision)
|
|
228
|
+
assert.equal(guideMessages(firstOut.messages).length, 1)
|
|
229
|
+
assert.equal(state.getSessionBinding(sessionId).sessionStamp, `turn1:${first.user.id}`)
|
|
230
|
+
|
|
231
|
+
const later = makeTurn(sessionId, { cwd, turn: 4 })
|
|
232
|
+
const laterOut = await mounted.run(later.payload, later.decision)
|
|
233
|
+
assert.equal(guideMessages(laterOut.messages).length, 0)
|
|
234
|
+
|
|
235
|
+
const revived = makeTurn(sessionId, { cwd, turn: 1, text: 'a brand new conversation' })
|
|
236
|
+
revived.user.id = 'guide-turn-reset-new-user'
|
|
237
|
+
revived.decision.messages = [revived.user]
|
|
238
|
+
const revivedOut = await mounted.run(revived.payload, revived.decision)
|
|
239
|
+
assert.equal(guideMessages(revivedOut.messages).length, 1, '回合号回到 1 → 重新投放')
|
|
240
|
+
|
|
241
|
+
// 宿主对同一首步重入:这一代的戳一致,不再重置、不再追加副本。
|
|
242
|
+
const reentry = makeTurn(sessionId, { cwd, turn: 1, text: 'a brand new conversation' })
|
|
243
|
+
reentry.user.id = 'guide-turn-reset-new-user'
|
|
244
|
+
reentry.decision.messages = [reentry.user]
|
|
245
|
+
const reentryOut = await mounted.run(reentry.payload, reentry.decision)
|
|
246
|
+
assert.equal(guideMessages(reentryOut.messages).length, 0)
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
test('a recall failure cannot swallow the rules message', async () => {
|
|
250
|
+
const sessionId = 'guide-failopen'
|
|
251
|
+
const cwd = path.join(home, 'project-guide-failopen')
|
|
252
|
+
state.ensureSession(sessionId, { cwd, agentPreset: 'coding' })
|
|
253
|
+
const mounted = mountGuide()
|
|
254
|
+
const turn = makeTurn(sessionId, { cwd })
|
|
255
|
+
Object.defineProperty(turn.payload.agent.session.header, 'agentPreset', {
|
|
256
|
+
get() { throw new Error('inject boom') },
|
|
257
|
+
})
|
|
258
|
+
const out = await mounted.run(turn.payload, turn.decision)
|
|
259
|
+
assert.equal(guideMessages(out.messages).length, 1, 'guide 与召回解耦,召回故障时仍然投放')
|
|
260
|
+
assert.ok(mounted.logger.warnings.some((message) => message.includes('pre-step injection failed')))
|
|
261
|
+
assert.match(String(state.getSessionBinding(sessionId).lastRecallError || ''), /inject boom/)
|
|
262
|
+
})
|
|
263
|
+
|
|
189
264
|
test('a domain change replaces the old guide with exactly one current version', async () => {
|
|
190
265
|
const sessionId = 'guide-domain'
|
|
191
266
|
const cwd = path.join(home, 'project-guide-domain')
|
|
@@ -209,6 +284,38 @@ test('a domain change replaces the old guide with exactly one current version',
|
|
|
209
284
|
assert.equal(out.messages.includes(old), false, 'the old version is projected out of the model view')
|
|
210
285
|
})
|
|
211
286
|
|
|
287
|
+
test('switching the memory domain re-delivers the guide and the domain-scoped one-shots', async () => {
|
|
288
|
+
const sessionId = 'guide-domain-switch'
|
|
289
|
+
const cwd = path.join(home, 'project-guide-domain-switch')
|
|
290
|
+
const binding = state.ensureSession(sessionId, { cwd, agentPreset: 'coding' })
|
|
291
|
+
const mounted = mountGuide()
|
|
292
|
+
|
|
293
|
+
const first = makeTurn(sessionId, { cwd })
|
|
294
|
+
const firstOut = await mounted.run(first.payload, first.decision)
|
|
295
|
+
const oldKey = guideKey(guideMessages(firstOut.messages)[0])
|
|
296
|
+
assert.equal(state.getSessionBinding(sessionId).injectedDomain, 'coding')
|
|
297
|
+
|
|
298
|
+
// 这条记忆是上一轮之后才写下的:切域后锚点重投时必须重新出现。
|
|
299
|
+
seedPinned(binding, 'mem-domain-switch', '切域之后写下的记忆')
|
|
300
|
+
state.setSessionBinding(sessionId, {
|
|
301
|
+
anniversariesShown: { 'mem-anniv': '2026-11-26' },
|
|
302
|
+
openLoopRemindedAt: { 'mem-loop': new Date().toISOString() },
|
|
303
|
+
})
|
|
304
|
+
state.setSessionBinding(sessionId, { domainOverride: 'rp' })
|
|
305
|
+
|
|
306
|
+
const next = makeTurn(sessionId, { cwd, turn: 2 })
|
|
307
|
+
const out = await mounted.run(next.payload, next.decision)
|
|
308
|
+
const guides = guideMessages(out.messages)
|
|
309
|
+
assert.equal(guides.length, 1)
|
|
310
|
+
assert.match(String(guides[0].content[0].text), /关于记忆(角色扮演)/)
|
|
311
|
+
assert.notEqual(guideKey(guides[0]), oldKey)
|
|
312
|
+
assert.ok(textOf(out.messages).includes('[mem-domain-switch]'), '锚点随切域重投')
|
|
313
|
+
const after = state.getSessionBinding(sessionId)
|
|
314
|
+
assert.equal(after.injectedDomain, 'rp')
|
|
315
|
+
assert.deepEqual(after.anniversariesShown, {})
|
|
316
|
+
assert.deepEqual(after.openLoopRemindedAt, {})
|
|
317
|
+
})
|
|
318
|
+
|
|
212
319
|
test('a prompt override changes the rendered body and the rules key', async () => {
|
|
213
320
|
const sessionId = 'guide-override'
|
|
214
321
|
const cwd = path.join(home, 'project-guide-override')
|
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
|
+
})
|
|
@@ -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
|
+
})
|
|
@@ -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
|
+
})
|