dsh-memu-memory 1.2.9 → 1.3.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 +45 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/docs/memory-semantics.md +4 -3
- package/lib/binding-diagnostics.js +3 -3
- package/lib/client.js +23 -1
- package/lib/consolidation-ledger.js +41 -1
- package/lib/consolidation-receipt.js +122 -21
- package/lib/consolidation-worker.js +81 -25
- package/lib/curator.js +91 -11
- package/lib/engine.js +13 -3
- package/lib/graph.js +57 -21
- package/lib/inject.js +35 -15
- package/lib/media.js +8 -1
- package/lib/memory.js +16 -1
- package/lib/memu.js +19 -6
- package/lib/private.js +374 -22
- package/lib/prompts/global-curator.md +6 -3
- package/lib/prompts/private-consolidation.md +2 -2
- package/lib/prompts/private-consolidation.rp.md +3 -2
- package/lib/prompts/system-guide.md +4 -5
- package/lib/prompts.js +27 -1
- package/lib/rpc.js +2 -2
- package/lib/state.js +17 -3
- package/lib/tools.js +257 -127
- package/package.json +1 -1
- package/tests/consolidation-credential.test.mjs +2 -2
- package/tests/consolidation-fork.test.mjs +92 -15
- package/tests/consolidation-ledger.test.mjs +95 -3
- package/tests/consolidation-snapshot.test.mjs +30 -13
- package/tests/curator-probe.test.mjs +32 -2
- package/tests/graph.test.mjs +21 -0
- package/tests/inject-conflict.test.mjs +1 -1
- package/tests/inject.test.mjs +1 -1
- package/tests/injection-chain.test.mjs +4 -4
- package/tests/injection-rollback.test.mjs +1 -1
- package/tests/memory-chain.test.mjs +28 -0
- package/tests/mock-llm.test.mjs +1 -1
- package/tests/prompt-semantics.test.mjs +1 -1
- package/tests/prompts.test.mjs +1 -1
- package/tests/tool-schema.test.mjs +2 -1
- package/tests/tools.test.mjs +25 -3
package/lib/private.js
CHANGED
|
@@ -8,6 +8,25 @@ import { condenseEvents, readSessionSnapshot } from './curator.js'
|
|
|
8
8
|
import { record } from './activity-log.js'
|
|
9
9
|
import { ACTIVE_MEMORY_POLICY, assessWake, collectEvidence } from './active-memory.js'
|
|
10
10
|
import { entryFingerprint } from './consolidation-receipt.js'
|
|
11
|
+
import { DEFAULT_TIME_ZONE } from './temporal.js'
|
|
12
|
+
|
|
13
|
+
// The consolidation worker only sees the transcript as text. Without a visible
|
|
14
|
+
// per-turn clock it falls back to the wall clock (or a single batch sceneTime),
|
|
15
|
+
// which is exactly how "前天" gets written months away from the scene. The seed
|
|
16
|
+
// event keeps the replayed logical time; surface it as a leading text block so
|
|
17
|
+
// the worker can pass that turn's observed_at to the write tools.
|
|
18
|
+
function eventTimeLabel(event) {
|
|
19
|
+
const explicit = event?.data?.sceneTime
|
|
20
|
+
const at = explicit ? new Date(explicit) : (Number.isFinite(event?.time) ? new Date(event.time) : null)
|
|
21
|
+
if (!at || !Number.isFinite(at.getTime())) return null
|
|
22
|
+
const parts = new Intl.DateTimeFormat('en-CA', {
|
|
23
|
+
timeZone: DEFAULT_TIME_ZONE,
|
|
24
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
25
|
+
hour: '2-digit', minute: '2-digit', hour12: false,
|
|
26
|
+
}).formatToParts(at)
|
|
27
|
+
const pick = (type) => parts.find((part) => part.type === type)?.value || ''
|
|
28
|
+
return `${pick('year')}-${pick('month')}-${pick('day')} ${pick('hour')}:${pick('minute')}`
|
|
29
|
+
}
|
|
11
30
|
|
|
12
31
|
// Short-term entries expire on a clock, so the idle pass is the last moment anyone
|
|
13
32
|
// can decide what they were worth. The list is generated in code rather than added
|
|
@@ -33,7 +52,7 @@ export function shortTermBrief(binding, { now = Date.now() } = {}) {
|
|
|
33
52
|
'[short_term · 快到期了]',
|
|
34
53
|
'下面这些是你近期记下的短期条目,到期会自己消失。逐条决定:',
|
|
35
54
|
'值得留下的升级 —— memu_private_update id=<id> layer=long_term(要补充的正文这次一并写上);',
|
|
36
|
-
'不重要的归档 ——
|
|
55
|
+
'不重要的归档 —— memu_private_update id=<id> status=archived;',
|
|
37
56
|
'还说不清的别动,它自己会过期。',
|
|
38
57
|
...rows.map((row) => `- [${row.id}] ${row.title} · 约 ${row.left} 小时后过期`),
|
|
39
58
|
].join('\n')
|
|
@@ -148,13 +167,19 @@ export function assessConsolidationValue(events) {
|
|
|
148
167
|
// tail, compact the noise, and leave the rest for the next window.
|
|
149
168
|
export const CONSOLIDATION_BACKLOG_EVENTS = 200
|
|
150
169
|
export const CONSOLIDATION_BACKLOG_TURNS = 10
|
|
151
|
-
|
|
170
|
+
// 小增量顺延:非手动整理时,少于 3 个真人回合的增量先不 fork。它不推进游标,
|
|
171
|
+
// 下一次触发会把顺延的事件一起带上;上限仍由上面的水位常量兜底,饥饿时放行。
|
|
172
|
+
export const CONSOLIDATION_MIN_HUMAN_TURNS = 3
|
|
173
|
+
// A checkpoint is measured in session events, and six of them are pure turn/step
|
|
174
|
+
// wrappers. 300 events therefore bought only ~50 turns of transcript. 500 keeps
|
|
175
|
+
// the same seed size in practice but cuts one fork for a 200-turn catch-up.
|
|
176
|
+
export const CONSOLIDATION_WINDOW_EVENTS = 500
|
|
152
177
|
export const CONSOLIDATION_PROBE_MINUTES = 15
|
|
153
178
|
export const CONSOLIDATION_SNAPSHOT_FAILURE_LIMIT = 2
|
|
154
|
-
const SEED_TOOL_RESULT_CHARS =
|
|
155
|
-
const SEED_TOOL_CALL_CHARS =
|
|
156
|
-
const SEED_TEXT_CHARS =
|
|
157
|
-
const SEED_CATALOG_ENTRIES =
|
|
179
|
+
const SEED_TOOL_RESULT_CHARS = 1_100
|
|
180
|
+
const SEED_TOOL_CALL_CHARS = 500
|
|
181
|
+
const SEED_TEXT_CHARS = 12_000
|
|
182
|
+
const SEED_CATALOG_ENTRIES = 18
|
|
158
183
|
|
|
159
184
|
// Types that carry conversation, plus the structural events a seeded Session
|
|
160
185
|
// replays. Everything else is host bookkeeping: request headers, permissions,
|
|
@@ -203,7 +228,11 @@ function cloneSeedBlocks(blocks, caps = {}, seenToolText = null) {
|
|
|
203
228
|
* Session's "contiguous from zero" rule holds. The optional catalog event takes
|
|
204
229
|
* seq 0 and is the only synthetic message.
|
|
205
230
|
*/
|
|
206
|
-
export function compactSeedEvents(events,
|
|
231
|
+
export function compactSeedEvents(events, prelude = null) {
|
|
232
|
+
const preludeEvents = (Array.isArray(prelude) ? prelude : (prelude ? [prelude] : []))
|
|
233
|
+
.filter((event) => event && typeof event === 'object')
|
|
234
|
+
.map((event, index) => ({ ...event, seq: index }))
|
|
235
|
+
const offset = preludeEvents.length
|
|
207
236
|
const kept = []
|
|
208
237
|
const seenToolText = new Set()
|
|
209
238
|
for (const event of Array.isArray(events) ? events : []) {
|
|
@@ -237,15 +266,17 @@ export function compactSeedEvents(events, catalogEvent = null) {
|
|
|
237
266
|
clone.data.arguments = capSeedText(event.data?.arguments, SEED_TOOL_CALL_CHARS)
|
|
238
267
|
} else if (event.type === 'user/message') {
|
|
239
268
|
clone.data.content = cloneSeedBlocks(event.data?.content, { text: SEED_TEXT_CHARS })
|
|
269
|
+
const timeLabel = eventTimeLabel(event)
|
|
270
|
+
if (timeLabel) clone.data.content.unshift({ type: 'text', text: `[事件时间 ${timeLabel}]` })
|
|
240
271
|
}
|
|
241
272
|
kept.push(clone)
|
|
242
273
|
}
|
|
243
274
|
|
|
244
275
|
const mapping = new Map()
|
|
245
|
-
kept.forEach((event, index) => mapping.set(Number(event.seq), index +
|
|
246
|
-
const out =
|
|
276
|
+
kept.forEach((event, index) => mapping.set(Number(event.seq), index + offset))
|
|
277
|
+
const out = [...preludeEvents]
|
|
247
278
|
kept.forEach((event, index) => {
|
|
248
|
-
const next = { ...event, seq: index +
|
|
279
|
+
const next = { ...event, seq: index + offset }
|
|
249
280
|
if (Array.isArray(next.sourceEventSeqs)) {
|
|
250
281
|
const mapped = [...new Set(next.sourceEventSeqs
|
|
251
282
|
.map(value => mapping.get(Number(value)))
|
|
@@ -263,6 +294,158 @@ export function compactSeedEvents(events, catalogEvent = null) {
|
|
|
263
294
|
return out
|
|
264
295
|
}
|
|
265
296
|
|
|
297
|
+
// P3: spend the worker's context on turns that can produce a durable memory.
|
|
298
|
+
// Zero-token local filter: strong signals (dates, promises, corrections,
|
|
299
|
+
// identities) count double; generic preference/social words count once. Whole
|
|
300
|
+
// turns are kept, plus the turn before/after for context. If nothing looks
|
|
301
|
+
// salient, keep everything rather than silently dropping the window.
|
|
302
|
+
const SALIENCE_STRONG = /今天|明天|昨天|前天|后天|大后天|下周|上周|这周|月底|月初|年初|年底|生日|纪念日|周年|星期[一二三四五六日天]|周[一二三四五六日天]|\d{1,2}\s*[月日号]|\d{4}\s*[-/年]|\d{1,2}\s*[点时]|答应|约定|说好|提醒|帮我|帮忙|欠|借|还|截止|到期|记得|别忘|改口|说错|更正|其实|矛盾|两版|之前说/g
|
|
303
|
+
const SALIENCE_WEAK = /喜欢|讨厌|不吃|不要|不能|不想|边界|秘密|别说|打算|计划|准备|要去|想去|叫|称呼|名字|岁|住|工作|职业|负责|接手|登记|换|孩子|父亲|母亲|老公|老婆|朋友|同事|邻居/g
|
|
304
|
+
|
|
305
|
+
function turnText(events) {
|
|
306
|
+
const parts = []
|
|
307
|
+
for (const event of events) {
|
|
308
|
+
if (event.type === 'user/message') {
|
|
309
|
+
for (const block of event.data?.content || []) if (block?.type === 'text' && typeof block.text === 'string') parts.push(block.text)
|
|
310
|
+
} else if (event.type === 'assistant/message') {
|
|
311
|
+
for (const block of event.data?.message?.content || []) if (block?.type === 'text' && typeof block.text === 'string') parts.push(block.text)
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return parts.join('\n')
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function salienceScore(text) {
|
|
318
|
+
const strong = (String(text).match(SALIENCE_STRONG) || []).length
|
|
319
|
+
const weak = (String(text).match(SALIENCE_WEAK) || []).length
|
|
320
|
+
return strong * 2 + weak
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Keep salient complete turns and one neighbour on each side. */
|
|
324
|
+
export function candidateSeedEvents(events, { maxTurns = 60 } = {}) {
|
|
325
|
+
const groups = []
|
|
326
|
+
let current = null
|
|
327
|
+
for (const event of Array.isArray(events) ? events : []) {
|
|
328
|
+
if (event?.type === 'turn/start' || current === null) {
|
|
329
|
+
current = []
|
|
330
|
+
groups.push(current)
|
|
331
|
+
}
|
|
332
|
+
current.push(event)
|
|
333
|
+
if (event?.type === 'turn/end') current = null
|
|
334
|
+
}
|
|
335
|
+
const kept = new Set()
|
|
336
|
+
groups.forEach((group, index) => {
|
|
337
|
+
if (salienceScore(turnText(group)) >= 2) kept.add(index)
|
|
338
|
+
})
|
|
339
|
+
if (kept.size === 0) return Array.isArray(events) ? [...events] : []
|
|
340
|
+
const expanded = new Set(kept)
|
|
341
|
+
for (const index of kept) {
|
|
342
|
+
if (index > 0) expanded.add(index - 1)
|
|
343
|
+
if (index + 1 < groups.length) expanded.add(index + 1)
|
|
344
|
+
}
|
|
345
|
+
const selected = [...expanded].sort((a, b) => a - b).slice(0, maxTurns)
|
|
346
|
+
const covered = selected.reduce((sum, index) => sum + groups[index].length, 0)
|
|
347
|
+
if (covered >= events.length * 0.8) return [...events]
|
|
348
|
+
return selected.flatMap((index) => groups[index])
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// P4:本地零 Token 抽「本窗必写候选」。worker 的任务选择常常只覆盖带日期/数字的
|
|
352
|
+
// 几条,新人物、换人接手、只有一句约定的轮次会被漏掉;这些轮次在 salience 里分数
|
|
353
|
+
// 不低,却在模型的 topic selection 里没有位置。给它就是一份带 seq 的短清单:要么
|
|
354
|
+
// 写,要么在回执里说明为什么不写,不能静默跳过。
|
|
355
|
+
const MUST_COVER_PERSON = /叫|自称|称呼|换|接手|改成|换成|新来|同事|师傅|阿姨|房东|店长|老板|邻居|朋友|家人/
|
|
356
|
+
export function mustCoverCandidates(events, { max = 8, minScore = 3 } = {}) {
|
|
357
|
+
const groups = []
|
|
358
|
+
let current = null
|
|
359
|
+
for (const event of Array.isArray(events) ? events : []) {
|
|
360
|
+
if (event?.type === 'turn/start' || current === null) {
|
|
361
|
+
current = []
|
|
362
|
+
groups.push(current)
|
|
363
|
+
}
|
|
364
|
+
current.push(event)
|
|
365
|
+
if (event?.type === 'turn/end') current = null
|
|
366
|
+
}
|
|
367
|
+
const rows = []
|
|
368
|
+
const seen = new Set()
|
|
369
|
+
groups.forEach((group) => {
|
|
370
|
+
const text = turnText(group)
|
|
371
|
+
const score = salienceScore(text)
|
|
372
|
+
if (score < minScore) return
|
|
373
|
+
const userText = group
|
|
374
|
+
.filter((event) => event?.type === 'user/message' && event.data?.source?.kind === 'user')
|
|
375
|
+
.flatMap((event) => (event.data?.content || []).filter((block) => block?.type === 'text').map((block) => String(block.text || '')))
|
|
376
|
+
.join(' ')
|
|
377
|
+
const source = (userText || text).replace(/\s+/g, ' ').trim().slice(0, 90)
|
|
378
|
+
if (!source || seen.has(source)) return
|
|
379
|
+
seen.add(source)
|
|
380
|
+
const observedAt = group
|
|
381
|
+
.filter((event) => event?.type === 'user/message' && event.data?.source?.kind === 'user')
|
|
382
|
+
.map((event) => event.data?.sceneTime)
|
|
383
|
+
.find((value) => typeof value === 'string' && value) || null
|
|
384
|
+
rows.push({
|
|
385
|
+
fromSeq: Number(group[0]?.seq),
|
|
386
|
+
throughSeq: Number(group[group.length - 1]?.seq),
|
|
387
|
+
score,
|
|
388
|
+
tag: MUST_COVER_PERSON.test(text) ? '人物/关系' : '事实',
|
|
389
|
+
text: source,
|
|
390
|
+
observedAt,
|
|
391
|
+
})
|
|
392
|
+
})
|
|
393
|
+
return rows
|
|
394
|
+
.sort((a, b) => b.score - a.score)
|
|
395
|
+
.slice(0, Math.max(1, Number(max) || 8))
|
|
396
|
+
.sort((a, b) => a.fromSeq - b.fromSeq)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** 顺延候选优先占位,但最多 4 条;其余名额留给本窗新候选。 */
|
|
400
|
+
export function mergeMustCover(carry, fresh, { max = 8, carryMax = 4 } = {}) {
|
|
401
|
+
const rows = []
|
|
402
|
+
const seen = new Set()
|
|
403
|
+
const add = (row) => {
|
|
404
|
+
if (!row || typeof row.text !== 'string') return
|
|
405
|
+
const key = row.text.replace(/\s+/g, '').slice(0, 60)
|
|
406
|
+
if (!key || seen.has(key)) return
|
|
407
|
+
seen.add(key)
|
|
408
|
+
rows.push(row)
|
|
409
|
+
}
|
|
410
|
+
for (const row of (Array.isArray(carry) ? carry : []).slice(0, Math.max(0, Number(carryMax) || 0))) {
|
|
411
|
+
add({ ...row, carried: true })
|
|
412
|
+
}
|
|
413
|
+
for (const row of Array.isArray(fresh) ? fresh : []) add(row)
|
|
414
|
+
return rows.slice(0, Math.max(1, Number(max) || 8))
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const COVER_DATE_RE = /\d{4}-\d{2}-\d{2}|\d{1,2}\s*[月日号]/
|
|
418
|
+
// 这些 bigram 到处出现,不能证明候选被写进库;命中两个以上才算覆盖。
|
|
419
|
+
const COVER_STOP = new Set([
|
|
420
|
+
'我们', '他们', '你们', '现在', '已经', '可以', '什么', '这个', '那个',
|
|
421
|
+
'时候', '今天', '明天', '昨天', '一下', '一个', '还是', '不是', '就是',
|
|
422
|
+
])
|
|
423
|
+
function coverTokens(text) {
|
|
424
|
+
return new Set(tokenize(String(text || ''))
|
|
425
|
+
.filter((token) => typeof token === 'string' && token.length >= 2 && !COVER_STOP.has(token)))
|
|
426
|
+
}
|
|
427
|
+
/** 本地零 Token 核验:候选里的关键事实是否真的出现在本窗新增/更新的条目里。 */
|
|
428
|
+
export function candidateCovered(candidate, writtenIds, index) {
|
|
429
|
+
const entries = index?.entries || {}
|
|
430
|
+
const text = String(candidate?.text || '')
|
|
431
|
+
if (!text) return true
|
|
432
|
+
const date = (text.match(COVER_DATE_RE) || [])[0] || null
|
|
433
|
+
const wanted = coverTokens(text)
|
|
434
|
+
if (wanted.size === 0 && !date) return true
|
|
435
|
+
for (const id of Array.isArray(writtenIds) ? writtenIds : []) {
|
|
436
|
+
const entry = entries[id]
|
|
437
|
+
if (!entry) continue
|
|
438
|
+
const body = String(entry.title || '') + ' ' + String(entry.content || '')
|
|
439
|
+
if (date && body.includes(date)) return true
|
|
440
|
+
const have = coverTokens(body)
|
|
441
|
+
let shared = 0
|
|
442
|
+
for (const token of wanted) {
|
|
443
|
+
if (have.has(token) && (shared += 1) >= 2) return true
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return false
|
|
447
|
+
}
|
|
448
|
+
|
|
266
449
|
/** Existing entries, compact, for dedupe/update instead of duplicate writes. */
|
|
267
450
|
export function memoryCatalogEvent(binding, now = Date.now()) {
|
|
268
451
|
if (!binding?.libraryId) return null
|
|
@@ -292,6 +475,62 @@ export function memoryCatalogEvent(binding, now = Date.now()) {
|
|
|
292
475
|
}
|
|
293
476
|
}
|
|
294
477
|
|
|
478
|
+
function recentUserText(events, limit = 6) {
|
|
479
|
+
const parts = []
|
|
480
|
+
for (const event of Array.isArray(events) ? events : []) {
|
|
481
|
+
if (event?.type !== 'user/message' || event.data?.source?.kind !== 'user') continue
|
|
482
|
+
for (const block of event.data?.content || []) {
|
|
483
|
+
if (block?.type === 'text' && typeof block.text === 'string' && block.text.trim()) parts.push(block.text.trim())
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return parts.slice(-limit).join('\n')
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* 1.3.1:本窗候选的本地召回命中。worker 不再获得 recall/list 工具,去重所需的
|
|
491
|
+
* 旧条目必须在种子里就给出;这里用插件现有的 BM25 词法腿做零 Token 预召回,
|
|
492
|
+
* 只给 id + 标题 + 一段正文,够 worker 判断 update 还是 remember。
|
|
493
|
+
*/
|
|
494
|
+
export function memoryRecallEvent({ binding = null, candidates = [], events = [], now = Date.now(), topK = 6 } = {}) {
|
|
495
|
+
if (!binding?.libraryId) return null
|
|
496
|
+
let rows = []
|
|
497
|
+
try {
|
|
498
|
+
rows = Object.entries(loadPrivateIndex(binding.libraryId).entries || {})
|
|
499
|
+
.filter(([, entry]) => entry && isMemoryEligible(entry, { automatic: true, now }))
|
|
500
|
+
.filter(([, entry]) => visibleToSession(entry, binding.sessionId))
|
|
501
|
+
.map(([id, entry]) => ({ ...entry, id }))
|
|
502
|
+
} catch { return null }
|
|
503
|
+
if (rows.length === 0) return null
|
|
504
|
+
const query = [
|
|
505
|
+
...(Array.isArray(candidates) ? candidates.map((item) => item?.text) : []),
|
|
506
|
+
recentUserText(events),
|
|
507
|
+
].filter(Boolean).join('\n')
|
|
508
|
+
const tokens = tokenize(query)
|
|
509
|
+
if (tokens.length === 0) return null
|
|
510
|
+
const corpus = buildCorpus(rows)
|
|
511
|
+
const scored = rows
|
|
512
|
+
.map((entry) => ({ entry, score: bm25(tokens, corpus.docs.get(entry.id), corpus) }))
|
|
513
|
+
.filter((item) => item.score > 0)
|
|
514
|
+
.sort((a, b) => b.score - a.score)
|
|
515
|
+
.slice(0, Math.max(1, Number(topK) || 6))
|
|
516
|
+
if (scored.length === 0) return null
|
|
517
|
+
const text = [
|
|
518
|
+
'[memory-recall · 本地召回命中(只读上下文,不是用户发言,也不属于本轮转录)]',
|
|
519
|
+
'下面是与本窗候选最相关的已有条目;只用于去重/合并,不是用户说过的话,也不是新证据。',
|
|
520
|
+
...scored.map(({ entry }) => `- [${entry.id}] ${capSeedText(entry.title || '(untitled)', 80)} — ${capSeedText(entry.content || '', 90)}`),
|
|
521
|
+
].join('\n')
|
|
522
|
+
return {
|
|
523
|
+
type: 'user/message',
|
|
524
|
+
seq: 0,
|
|
525
|
+
time: now,
|
|
526
|
+
data: createUserMessage({
|
|
527
|
+
content: [{ type: 'text', text }],
|
|
528
|
+
source: { kind: 'plugin:dsh-memu-memory', form: 'notice', summary: 'memory-recall' },
|
|
529
|
+
}),
|
|
530
|
+
surfaceOp: 'append',
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
295
534
|
/** First `limit` events, trimmed back to a complete turn so a fork never sees half a step. */
|
|
296
535
|
export function selectConsolidationWindow(events, limit = CONSOLIDATION_WINDOW_EVENTS) {
|
|
297
536
|
const list = (Array.isArray(events) ? events : []).filter(event => eventSeq(event) !== null)
|
|
@@ -520,6 +759,37 @@ async function attachWorkerTools(agents, childId, parentId) {
|
|
|
520
759
|
// workerToolsPartial true = 未证明 worker 拿到完整 wanted 集(子集、空集、或挂载
|
|
521
760
|
// 整体失败)。刻意把"一件都没挂上"也标 true:若失败标 false,
|
|
522
761
|
// false 会被一眼读成"全量挂载",元数据又不准了。
|
|
762
|
+
// A fork inherits the parent preset's plugin tools. `tools.restrict()` is scoped
|
|
763
|
+
// to the child agent, so this removes every plugin tool the worker never uses
|
|
764
|
+
// without touching the parent session. Restrict before followup: the host
|
|
765
|
+
// resolves the admitted set at step start.
|
|
766
|
+
async function restrictWorkerTools(agents, childId, parentId) {
|
|
767
|
+
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
768
|
+
let record = null
|
|
769
|
+
try { record = agents.get?.(childId) || null } catch { record = null }
|
|
770
|
+
const actx = record?.ctx || record?.agent?.ctx || null
|
|
771
|
+
if (actx && actx.tools && typeof actx.tools.restrict === 'function') {
|
|
772
|
+
try {
|
|
773
|
+
const dispose = actx.tools.restrict({ allow: WORKER_TOOL_ALLOW })
|
|
774
|
+
return { dispose, allowed: [...WORKER_TOOL_ALLOW] }
|
|
775
|
+
} catch (error) {
|
|
776
|
+
// A host missing one of the optional tools must not lose consolidation;
|
|
777
|
+
// retry with the write/read core and let the brief tell the truth.
|
|
778
|
+
const core = [...CORE_WRITE_TOOLS]
|
|
779
|
+
try {
|
|
780
|
+
return { dispose: actx.tools.restrict({ allow: core }), allowed: core }
|
|
781
|
+
} catch (inner) {
|
|
782
|
+
warn('consolidation worker tool restriction failed: ' + String(inner?.message || inner))
|
|
783
|
+
return null
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
if (record || !(agents.get?.(parentId))) return null
|
|
788
|
+
await new Promise(resolve => setTimeout(resolve, 100))
|
|
789
|
+
}
|
|
790
|
+
return null
|
|
791
|
+
}
|
|
792
|
+
|
|
523
793
|
function workerToolsMeta(workerTools) {
|
|
524
794
|
const wanted = [...WORKER_WRITE_TOOLS, ...WORKER_READ_TOOLS]
|
|
525
795
|
if (!workerTools) {
|
|
@@ -540,16 +810,18 @@ const inFlight = new Map()
|
|
|
540
810
|
const WORKER_STOP_GRACE_MS = 5_000
|
|
541
811
|
|
|
542
812
|
// 这里的 import 刻意写在语句之后:lib/binding-diagnostics.js 的 RUNTIME_STATE 把 `inFlight`
|
|
543
|
-
// 的 file:line 当成诊断契约(当前 lib/private.js:
|
|
813
|
+
// 的 file:line 当成诊断契约(当前 lib/private.js:805),修改位置时同步更新该诊断映射,
|
|
544
814
|
// 而那是别人的文件、本包不改。ESM 的 import 声明是提升的,写在语句之后合法。
|
|
545
815
|
import { warn } from './paths.js'
|
|
546
816
|
import { captureSessionSnapshot, eventSeq, safePrefix, snapshotHash } from './consolidation-snapshot.js'
|
|
547
817
|
import {
|
|
548
818
|
beginJob, completeJob, failJob, findOperation, noteEvidence, operationKey,
|
|
549
819
|
recoverStaleJobs, recordOperation, scopeGenerationOf, clearSessionState, skipRange,
|
|
820
|
+
readCarryCandidates, setCarryCandidates,
|
|
550
821
|
} from './consolidation-ledger.js'
|
|
551
822
|
import { decideCompletion, receiptContractText } from './consolidation-receipt.js'
|
|
552
|
-
import { buildWorkerBrief, probeToolSurface, WORKER_READ_TOOLS, WORKER_WRITE_TOOLS } from './consolidation-worker.js'
|
|
823
|
+
import { buildWorkerBrief, probeToolSurface, CORE_WRITE_TOOLS, WORKER_READ_TOOLS, WORKER_WRITE_TOOLS, WORKER_TOOL_ALLOW, WORKER_WRAPUP_ROUND, WORKER_HARD_STOP_ROUND, workerRoundGuidance } from './consolidation-worker.js'
|
|
824
|
+
import { tokenize, buildCorpus, bm25 } from './text-retrieval.js'
|
|
553
825
|
import { isGoneSessionError } from './cycle.js'
|
|
554
826
|
import { autoLinkPrivateMemories } from './private-links.js'
|
|
555
827
|
import { registerTools } from './tools.js'
|
|
@@ -620,6 +892,9 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
620
892
|
inFlight.set(sessionId, abort)
|
|
621
893
|
let handle = null
|
|
622
894
|
let offSession = null
|
|
895
|
+
// N3:worker 工具循环的软/硬上限。软上限追加收尾提示,硬上限停掉 fork;
|
|
896
|
+
// 已经写入库的条目不会因为硬停被撤销(游标不推进,下一窗重试剩余范围)。
|
|
897
|
+
let workerToolRounds = 0
|
|
623
898
|
let idle = null
|
|
624
899
|
// Stopped once, callable twice: the timeout path and `finally` both need it.
|
|
625
900
|
let stopped = false
|
|
@@ -652,6 +927,7 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
652
927
|
let jobId = null
|
|
653
928
|
let scopeChanged = null
|
|
654
929
|
let workerTools = null
|
|
930
|
+
let workerRestriction = null
|
|
655
931
|
const assistantTexts = []
|
|
656
932
|
let childId = null
|
|
657
933
|
// 每次整理都要在活动日志里留一条:谁触发(手动/空闲)、fork 有没有建、结果是完成、
|
|
@@ -786,6 +1062,17 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
786
1062
|
// 阈值与权重集中在 lib/active-memory.js,可根据回放标定。
|
|
787
1063
|
const idleMinutes = binding.lastTurnAt ? (Date.now() - (Date.parse(binding.lastTurnAt) || Date.now())) / 60_000 : Infinity
|
|
788
1064
|
const starved = idleMinutes >= Number(settings.activeMemoryStarvationMinutes ?? ACTIVE_MEMORY_POLICY.starvationMinutes)
|
|
1065
|
+
// 小增量顺延:不 fork、不推进游标;下一次触发把这段一起带上。
|
|
1066
|
+
// 首次整理(还没有成功游标)不受限,尽快建立记忆基线;饥饿(长时间空闲)
|
|
1067
|
+
// 仍然放行,保证收尾;force 手动路径不经过这里。
|
|
1068
|
+
const firstPass = !binding.lastSleepSeq
|
|
1069
|
+
if (!starved && !firstPass && Number(value.humanTurns) < CONSOLIDATION_MIN_HUMAN_TURNS) {
|
|
1070
|
+
return finish({
|
|
1071
|
+
ok: true, sessionId, skipped: 'below-min-turns', settled: false, deferred: true,
|
|
1072
|
+
reasonCode: 'below-min-turns', assessment: value, snapshot: snapshotMetaOf(fullSnapshot),
|
|
1073
|
+
trigger: options.trigger,
|
|
1074
|
+
})
|
|
1075
|
+
}
|
|
789
1076
|
const evidence = collectEvidence(candidateEvents)
|
|
790
1077
|
const wake = assessWake({
|
|
791
1078
|
evidence,
|
|
@@ -814,7 +1101,11 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
814
1101
|
}
|
|
815
1102
|
|
|
816
1103
|
// One bounded window per run: the next sweep continues from the new cursor.
|
|
817
|
-
|
|
1104
|
+
// 失败重试(sleepAttempts>0)时窗口减半:同一游标反复超时不该每次都付整窗成本,
|
|
1105
|
+
// 前半段先结算,剩余留给下一次。
|
|
1106
|
+
const sleepAttempt = Number(binding.sleepAttempts || 0)
|
|
1107
|
+
const windowLimit = sleepAttempt > 0 ? Math.floor(CONSOLIDATION_WINDOW_EVENTS / 2) : CONSOLIDATION_WINDOW_EVENTS
|
|
1108
|
+
const window = selectConsolidationWindow(candidateEvents, windowLimit)
|
|
818
1109
|
if (window.events.length === 0) {
|
|
819
1110
|
return finish({ ok: true, sessionId, skipped: 'empty-window', settled: true, snapshot: snapshotMetaOf(fullSnapshot) })
|
|
820
1111
|
}
|
|
@@ -829,7 +1120,13 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
829
1120
|
const snapshotMeta = snapshotMetaOf(windowSnapshot)
|
|
830
1121
|
// 范围大小决定等多久:显式给了就听调用方的,没给按这一窗的事件数推。
|
|
831
1122
|
const budgetMs = Number.isInteger(maxWaitMs) && maxWaitMs > 0 ? maxWaitMs : consolidationWaitBudget(window.events.length)
|
|
832
|
-
|
|
1123
|
+
// 1.3.1:目录与本地召回命中在种子开头一次给全,worker 不再开只读回合。
|
|
1124
|
+
const carry = safeLedger(() => readCarryCandidates(sessionId), [])
|
|
1125
|
+
const mustCover = mergeMustCover(carry, mustCoverCandidates(window.events))
|
|
1126
|
+
const seedEvents = compactSeedEvents(candidateSeedEvents(window.events), [
|
|
1127
|
+
memoryCatalogEvent({ ...binding, sessionId }),
|
|
1128
|
+
memoryRecallEvent({ binding: { ...binding, sessionId }, candidates: mustCover, events: window.events }),
|
|
1129
|
+
])
|
|
833
1130
|
if (seedEvents.length === 0) {
|
|
834
1131
|
return finish({ ok: true, sessionId, skipped: 'empty-seed', settled: true, snapshot: snapshotMeta })
|
|
835
1132
|
}
|
|
@@ -841,9 +1138,11 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
841
1138
|
if (previous && (previous.outcome === 'completed' || previous.outcome === 'skipped')) {
|
|
842
1139
|
return finish({ ok: true, sessionId, skipped: 'already-consolidated', settled: true, snapshot: snapshotMeta, credential: previous })
|
|
843
1140
|
}
|
|
844
|
-
//
|
|
845
|
-
//
|
|
846
|
-
|
|
1141
|
+
// 同一份快照连续失败到上限就不再「自动」重跑:窗口已经很小,重试成本可控,但
|
|
1142
|
+
// 没有新事件的同一段转录不值得无限重试。手动整理(force)是明确的一次再决定,
|
|
1143
|
+
// 不受上限约束——否则冻结回放/用户重试都会被永久卡在同一个窗口。新消息会改变
|
|
1144
|
+
// 快照哈希,自动路径也重新获得机会。
|
|
1145
|
+
if (!force && previous?.outcome === 'failed' && Number(previous.failures) >= CONSOLIDATION_SNAPSHOT_FAILURE_LIMIT) {
|
|
847
1146
|
return finish({
|
|
848
1147
|
ok: true, sessionId, skipped: 'snapshot-failed', settled: true, reasonCode: 'snapshot-failed-too-many',
|
|
849
1148
|
snapshot: snapshotMeta, failures: Number(previous.failures) || 0,
|
|
@@ -898,6 +1197,11 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
898
1197
|
const resolved = resolveConsolidationAgentOptions(settings, inherited)
|
|
899
1198
|
let agentOptions = resolved.options
|
|
900
1199
|
let modelMode = resolved.reason
|
|
1200
|
+
// 1.3.1:整理思考强度可独立于父会话;'inherit' 保持旧行为。
|
|
1201
|
+
const effort = settings.consolidationReasoningEffort
|
|
1202
|
+
if (agentOptions && effort && effort !== 'inherit') {
|
|
1203
|
+
agentOptions = { ...agentOptions, reasoningEffort: effort }
|
|
1204
|
+
}
|
|
901
1205
|
if (!agentOptions) {
|
|
902
1206
|
// no-inherited-route 与旧失败路径逐字节一致(inherit 模式语义不变);host/custom
|
|
903
1207
|
// 的坏配置各自带 reasonCode,整理提醒能直接说清是哪个配置面写错了。
|
|
@@ -951,6 +1255,7 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
951
1255
|
if (probe.hasWrite !== true) {
|
|
952
1256
|
workerTools = await attachWorkerTools(agents, childId, sessionId)
|
|
953
1257
|
}
|
|
1258
|
+
workerRestriction = await restrictWorkerTools(agents, childId, sessionId)
|
|
954
1259
|
|
|
955
1260
|
// 先记"已开始"再等结果:一个大会话的 fork 可能跑好几分钟,没有这条记录,
|
|
956
1261
|
// 侧边栏和日志页在等待期间只会显示上一次的结果,用户会以为按钮没生效。
|
|
@@ -1007,6 +1312,15 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
1007
1312
|
// 工具动作是写入的落点:每出现一次就重验一次父授权,变了立刻停掉这条 fork。
|
|
1008
1313
|
if (event?.type === 'tool/call' || event?.type === 'tool/result' || event?.type === 'tool/ptc-dispatch' || event?.type === 'tool/ptc-dispatch-start') {
|
|
1009
1314
|
revalidate('worker-write')
|
|
1315
|
+
workerToolRounds += 1
|
|
1316
|
+
if (workerToolRounds >= WORKER_HARD_STOP_ROUND) {
|
|
1317
|
+
try { abort.abort() } catch {}
|
|
1318
|
+
} else {
|
|
1319
|
+
const guidance = workerRoundGuidance(workerToolRounds)
|
|
1320
|
+
if (guidance && workerToolRounds === WORKER_WRAPUP_ROUND) {
|
|
1321
|
+
try { handle?.agent?.followup?.(noticeMessage(guidance.text, '整理收尾提示')) } catch {}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1010
1324
|
return
|
|
1011
1325
|
}
|
|
1012
1326
|
return
|
|
@@ -1026,6 +1340,10 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
1026
1340
|
// 不继承 mood。显式写 null 而不是留空:缺字段和「这一刻是中性」在写入时都走
|
|
1027
1341
|
// 同一条兜底,但只有 null 能把「后台 worker 没有当下心境」说清楚。
|
|
1028
1342
|
mood: null,
|
|
1343
|
+
// The fork writes memories on the same logical clock as its parent. Without
|
|
1344
|
+
// this the worker falls back to the wall clock at fork time; the per-turn
|
|
1345
|
+
// [事件时间] markers in the seed remain the authoritative override.
|
|
1346
|
+
sceneTime: binding.sceneTime || null,
|
|
1029
1347
|
parentSessionId: sessionId,
|
|
1030
1348
|
parentScopeGeneration: generationAtStart,
|
|
1031
1349
|
snapshotHash: snapshot.hash,
|
|
@@ -1053,7 +1371,17 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
1053
1371
|
})
|
|
1054
1372
|
}
|
|
1055
1373
|
|
|
1056
|
-
const brief = buildWorkerBrief({
|
|
1374
|
+
const brief = buildWorkerBrief({
|
|
1375
|
+
snapshot,
|
|
1376
|
+
probe,
|
|
1377
|
+
contract: receiptContractText({ jobId, snapshotHash: snapshot.hash, autoReceipt: true }),
|
|
1378
|
+
reason: force ? 'manual' : 'auto',
|
|
1379
|
+
jobId,
|
|
1380
|
+
mustCover,
|
|
1381
|
+
autoReceipt: true,
|
|
1382
|
+
// 上一轮 batch 参数 JSON 畸形:这一轮只让模型逐条 remember,降低再次整段失败的概率。
|
|
1383
|
+
singleOnly: Boolean(binding.consolidationSingleOnly),
|
|
1384
|
+
})
|
|
1057
1385
|
handle.agent.followup(noticeMessage([buildPrivateConsolidationPrompt(sessionId), '', brief].join('\n'), '整理这场对话的私有记忆'))
|
|
1058
1386
|
// followup only queues. whenIdle says the driver stopped; turn/end says
|
|
1059
1387
|
// whether that turn actually succeeded, so both are checked below.
|
|
@@ -1071,8 +1399,17 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
1071
1399
|
if (outcome === 'done') {
|
|
1072
1400
|
const failure = turnEndFailure(turnEnd)
|
|
1073
1401
|
if (failure) {
|
|
1074
|
-
|
|
1075
|
-
|
|
1402
|
+
// batch 参数的 JSON 畸形是模型生成问题,不是整理逻辑故障:标记下一次
|
|
1403
|
+
// 只用逐条 remember,并让重试路径接住(consolidateAll 已有 2 次重试)。
|
|
1404
|
+
const batchJsonInvalid = /memu_private_remember_batch/.test(String(failure))
|
|
1405
|
+
&& /JSON|Expected ','|after array element/.test(String(failure))
|
|
1406
|
+
const reasonCode = batchJsonInvalid ? 'batch-json-invalid' : 'fork-turn-failed'
|
|
1407
|
+
if (batchJsonInvalid) setSessionBinding(sessionId, { consolidationSingleOnly: true })
|
|
1408
|
+
safeLedger(() => failJob({ sessionId, jobId, reasonCode, retryable: batchJsonInvalid, error: failure }))
|
|
1409
|
+
return finish({
|
|
1410
|
+
ok: false, error: 'consolidation fork failed: ' + failure, sessionId, childId,
|
|
1411
|
+
settled: false, timedOut: false, retryable: batchJsonInvalid, reasonCode,
|
|
1412
|
+
})
|
|
1076
1413
|
}
|
|
1077
1414
|
// 父授权重验:写入可能已经落了一部分,但凭证只有在授权还成立时才算数。
|
|
1078
1415
|
const generationNow = scopeGenerationOf(getSessionBinding(sessionId))
|
|
@@ -1095,7 +1432,16 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
1095
1432
|
try { index = loadPrivateIndex(binding.libraryId) } catch { index = null }
|
|
1096
1433
|
// 完成不是"没报错":worker 的回执 + 库里的真实变化,两边对上才结算。
|
|
1097
1434
|
const workerText = assistantTexts.join('\n')
|
|
1098
|
-
decision = decideCompletion({
|
|
1435
|
+
decision = decideCompletion({
|
|
1436
|
+
text: workerText,
|
|
1437
|
+
wrote,
|
|
1438
|
+
index,
|
|
1439
|
+
beforeIds,
|
|
1440
|
+
beforeEntries,
|
|
1441
|
+
expectedJobId: jobId,
|
|
1442
|
+
expectedSnapshotHash: snapshot.hash,
|
|
1443
|
+
autoReceipt: { jobId, snapshotHash: snapshot.hash, checkedRange: { fromSeq: snapshot.fromSeq, throughSeq: snapshot.throughSeq } },
|
|
1444
|
+
})
|
|
1099
1445
|
|
|
1100
1446
|
if (!decision.advance) {
|
|
1101
1447
|
safeLedger(() => failJob({
|
|
@@ -1124,7 +1470,12 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
1124
1470
|
reasonCode: 'ledger-not-advanced', snapshot: snapshotMeta,
|
|
1125
1471
|
error: 'the consolidation ledger could not verify the covered snapshot range' })
|
|
1126
1472
|
}
|
|
1127
|
-
setSessionBinding(sessionId, { lastSleepSeq: snapshot.throughSeq })
|
|
1473
|
+
setSessionBinding(sessionId, { lastSleepSeq: snapshot.throughSeq, consolidationSingleOnly: false })
|
|
1474
|
+
// 候选跨窗顺延:本窗没写进库的候选留给下一窗的必写清单;最后一窗也在同一份
|
|
1475
|
+
// brief 里见到它们,不需要为了补写再开一次整窗 fork。核验纯本地,0 Token。
|
|
1476
|
+
const writtenIds = [...(decision.createdIds || []), ...(decision.updatedIds || []), ...(decision.heldIds || [])]
|
|
1477
|
+
const missed = mustCover.filter((candidate) => !candidateCovered(candidate, writtenIds, index))
|
|
1478
|
+
safeLedger(() => setCarryCandidates(sessionId, missed))
|
|
1128
1479
|
safeLedger(() => recordOperation({ sessionId, key: opKey, outcome: decision.status, ids: decision.createdIds || [] }))
|
|
1129
1480
|
// 私有自动关联(§5.6 兜底):只在整理真的对账并推进边界之后跑,纯算法,
|
|
1130
1481
|
// 0 token。worker 若已调用 memu_private_link_suggest,这一遍是幂等的(已有的
|
|
@@ -1195,6 +1546,7 @@ export async function requestHistoricalConsolidation(ctx, sessionId, options = {
|
|
|
1195
1546
|
inFlight.delete(sessionId)
|
|
1196
1547
|
try { await stopWorker() } catch {}
|
|
1197
1548
|
try { workerTools?.dispose?.() } catch {}
|
|
1549
|
+
try { workerRestriction?.dispose?.() } catch {}
|
|
1198
1550
|
try { if (childId) deleteSessionBinding(childId) } catch {}
|
|
1199
1551
|
}
|
|
1200
1552
|
}
|
|
@@ -63,7 +63,7 @@ identity、preferences、working_style、tooling、domain_profile、do_not_assum
|
|
|
63
63
|
|
|
64
64
|
第六步:写条目
|
|
65
65
|
中性第三人称,简洁,可执行。不要用角色口吻,不要写“我觉得”。
|
|
66
|
-
|
|
66
|
+
每条 content ≤300 字;每条带 evidence(session_id + 恰好 1 条 quote,quote ≤200 字)和 confidence(0-1)。
|
|
67
67
|
引用只能来自输入中确实存在的说话人与片段;摘要就写成摘要,不伪装逐字引语,不编造 session_id。群聊先核对是谁说的,不把其他成员或角色的喜好归给当前用户;凭据与私密信息不能出现在 evidence 里。
|
|
68
68
|
不要写“用户聊了很多项目的事”这种总结;
|
|
69
69
|
要写“用户在 coding 任务中偏好先给结论,再给细节”。
|
|
@@ -75,10 +75,13 @@ identity、preferences、working_style、tooling、domain_profile、do_not_assum
|
|
|
75
75
|
- 标题是给以后检索用的目录项,不是文采展示;拿不准就把结论写进标题。
|
|
76
76
|
|
|
77
77
|
上限(代码会截断,超出部分直接丢弃):
|
|
78
|
-
- memories ≤
|
|
78
|
+
- memories ≤24;
|
|
79
|
+
- 每条 content ≤300 字;
|
|
79
80
|
- link 与 absorb 合计 ≤20;其中 absorb ≤8;
|
|
80
81
|
- 每条 link note 8-500 字;
|
|
81
|
-
- 每条 evidence
|
|
82
|
+
- 每条 evidence 恰好 1 条 quote、quote ≤200 字,且必须来自输入会话原文;
|
|
83
|
+
- sessions 每条只写 id、domain 和 ≤20 字的 reason;
|
|
84
|
+
- domain_summary 每个域 ≤20 字。
|
|
82
85
|
|
|
83
86
|
输出 JSON:
|
|
84
87
|
{
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
- 一条只写一件事,并且自包含:以后看不到这段对话,要写清背景。
|
|
12
12
|
- 优先写具体的东西:一句原话、一个决定和它的理由、一次踩过的坑。
|
|
13
13
|
- 可以写有后续影响的关系、感受或限制,但要有具体事件与来源;一次礼貌或情绪不推导稳定人格,不按轮数增加亲密度。只有明确的叙事内容才用角色口吻。
|
|
14
|
-
-
|
|
14
|
+
- 只与实际提供或成功检索到的旧记忆去重:兼容可合并,矛盾保留来源、时间与条件供复核,不抹旧正文或自行宣布取代。**最多新增 8 条,按价值排序**:约定/承诺 > 日期/改口/冲突 > 身份/称呼/边界/第三方人物与变化 > 偏好/计划 > 其他明确事实;普通日常流水、打招呼、重复对话不写,没有值得留的就不写。
|
|
15
15
|
|
|
16
16
|
字段:
|
|
17
17
|
- title:8–40 字,写具体事实(人名、物名、事件、结论的关键词)。锚点与召回只显示标题、不显示正文,所以标题就是目录项;
|
|
18
18
|
不要「一些事」「那段对话」「关于……的记录」这类空标签,细节全部放进 content。合并/吸收后的标题要覆盖来源的关键词。
|
|
19
|
-
- content
|
|
19
|
+
- content:自包含的具体内容、对象/条件及后续意义,**50–170 字,尽量小但精准**;只保留人物、地点、时间、事情、原话/说话人,不复述整段对话,不写成行为日志。
|
|
20
20
|
- tags:可选,便于以后检索。
|
|
21
21
|
- salient_date:只在确有日期时填,且要落成绝对日期。每年复发的那一天(生日、周年)用 `MM-DD`;
|
|
22
22
|
一次性的约定或安排用 `YYYY-MM-DD`。说「明天」「后天」「下周」的约定必须按今天算出具体年月日——
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
- 同一件事有两种说法:各写一条,`conflicts_with` 互指;不要合并成一条,也不要自行裁决。
|
|
17
17
|
- 承诺/约定写 `commitment`(对谁/做什么/`due_at`/`status`);梦、假设、转述标 `source_kind`。
|
|
18
18
|
- 助手说过的承诺和计划同样要写;不要只收用户消息。
|
|
19
|
-
-
|
|
19
|
+
- 每窗最多新增 8 条。按价值排序:约定/承诺 = 新人物首次出现/换人接手/称呼变化 > 日期/改口/冲突 > 身份/边界/第三方人物 > 偏好/计划 > 其他明确事实。前两类必须写,不得因为已经写了几条就省略。明确说过的日常事实(颜色、物品、口味、作息、行程、称呼变更)也要各自成条;同一件事的两种说法各写一条,保留时间和来源,不要自行裁决。条数不能靠少写省掉;「少写」只指单条正文精准。
|
|
20
|
+
- 人物首次出现、换人接手或称呼变化必须单独成一条,写清先后(谁先、谁后来接手)与发生轮次;这类事实不并入生活流水,也不因为主体是第三方就不写。
|
|
20
21
|
|
|
21
22
|
写什么(活人感):
|
|
22
23
|
- 用角色的口吻、第一人称写,像在回想,不像在归档。
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
字段:
|
|
30
31
|
- title:8–40 字,写清这件事是什么——具体的人名、称谓、物件、事件或结论关键词。锚点/召回只显示标题、不显示正文,
|
|
31
32
|
所以标题就是目录项;不要「关于……的回忆」「一些对话」这类空标签,细节留在 content。合并/吸收后的标题要覆盖来源的关键词。
|
|
32
|
-
- content:一个瞬间 + 它对之后的影响,通常
|
|
33
|
+
- content:一个瞬间 + 它对之后的影响,通常 50–170 字,不硬凑长度;最多引一句有出处的原话。能让下次称呼、选择或分寸自然接续,比抒情更重要。
|
|
33
34
|
- tags:可选。
|
|
34
35
|
- salient_date:只在确有日期时填,且要落成绝对日期。每年复发的那一天(生日、周年)用 `MM-DD`;
|
|
35
36
|
一次性的约定或安排用 `YYYY-MM-DD`。说「明天」「后天」「下周」的约定必须按今天算出具体年月日——
|