dsh-memu-memory 1.3.6 → 1.3.8
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 -1
- package/CHANGELOG.md +87 -0
- package/README.md +7 -7
- package/README.zh.md +7 -7
- package/docs/client-conventions.md +4 -0
- package/docs/contributing.md +2 -2
- package/docs/memory-semantics.md +10 -7
- package/docs/troubleshooting.md +132 -7
- package/lib/binding-diagnostics.js +2 -2
- package/lib/client.js +296 -122
- package/lib/consolidation-ledger.js +6 -2
- package/lib/consolidation-worker.js +7 -0
- package/lib/inbound.js +24 -9
- package/lib/inject.js +379 -215
- package/lib/lexicon.js +5 -0
- package/lib/local-embedding-manager.js +4 -0
- package/lib/local-vector-service.js +65 -1
- package/lib/memory.js +711 -175
- package/lib/paths.js +24 -0
- package/lib/private.js +284 -127
- package/lib/rpc.js +144 -45
- package/lib/snippet.js +49 -28
- package/lib/state.js +185 -26
- package/lib/tools.js +150 -31
- package/lib/webui/standalone.css +28 -1
- package/lib/webui.js +25 -1
- package/lib/worker-pool.js +260 -26
- package/package.json +1 -1
- package/scripts/check-i18n.mjs +19 -0
- package/scripts/recall-bench.mjs +4 -4
- package/scripts/simulate-injection.mjs +3 -0
- package/tests/activity-wiring.test.mjs +52 -0
- package/tests/client-render.test.mjs +207 -0
- package/tests/consolidation-feed.test.mjs +26 -0
- package/tests/consolidation-fork.test.mjs +618 -33
- package/tests/consolidation-snapshot.test.mjs +2 -1
- package/tests/cross-library-recall.test.mjs +156 -0
- package/tests/cue.test.mjs +15 -2
- package/tests/hybrid-recall.test.mjs +488 -0
- package/tests/inbound.test.mjs +49 -4
- package/tests/inject-conflict.test.mjs +70 -9
- package/tests/inject-guide.test.mjs +13 -1
- package/tests/inject.test.mjs +10 -0
- package/tests/injection-budget.test.mjs +101 -0
- package/tests/injection-chain.test.mjs +37 -0
- package/tests/injection-rollback.test.mjs +172 -9
- package/tests/issue2-chain.test.mjs +169 -0
- package/tests/lexicon-inject.test.mjs +33 -5
- package/tests/lexicon-ui.test.mjs +99 -2
- package/tests/managed-memory.test.mjs +625 -1
- package/tests/media.test.mjs +1 -1
- package/tests/new-session-gate.test.mjs +280 -25
- package/tests/open-loop-date.test.mjs +11 -1
- package/tests/recall-intent.test.mjs +52 -3
- package/tests/simulate-injection.test.mjs +4 -4
- package/tests/snippet.test.mjs +33 -1
- package/tests/state.test.mjs +8 -3
- package/tests/tool-schema.test.mjs +52 -0
- package/tests/tools.test.mjs +394 -0
- package/tests/webui.test.mjs +16 -2
- package/tests/worker-lifecycle.test.mjs +419 -36
|
@@ -258,7 +258,7 @@ export function completeJob({
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
/** 失败:清掉 inflight、把范围退回 pending、按尝试次数退避。 */
|
|
261
|
-
export function failJob({ sessionId, jobId, reasonCode = 'failed', retryable = true, error = null, now = Date.now() }) {
|
|
261
|
+
export function failJob({ sessionId, jobId, reasonCode = 'failed', retryable = true, error = null, executionKey = null, executionSettingsKey = null, executionDefaultsComparable = true, now = Date.now() }) {
|
|
262
262
|
return mutateLedger((ledger) => {
|
|
263
263
|
const entry = ensureEntry(ledger, sessionId)
|
|
264
264
|
const job = entry.inflight && entry.inflight.jobId === jobId ? entry.inflight : null
|
|
@@ -282,12 +282,16 @@ export function failJob({ sessionId, jobId, reasonCode = 'failed', retryable = t
|
|
|
282
282
|
if (job.snapshot?.hash) {
|
|
283
283
|
const key = operationKey({ sessionId, libraryId: job.libraryId, snapshotHash: job.snapshot.hash, scopeGeneration: job.scopeGeneration })
|
|
284
284
|
const prior = entry.operations[key]
|
|
285
|
+
const effectiveExecutionKey = executionKey && !executionDefaultsComparable && executionSettingsKey === prior?.executionSettingsKey
|
|
286
|
+
? prior?.executionKey || executionKey : executionKey
|
|
285
287
|
entry.operations[key] = {
|
|
286
288
|
outcome: 'failed',
|
|
287
289
|
ids: Array.isArray(prior?.ids) ? prior.ids : [],
|
|
288
290
|
at: stamp(),
|
|
289
|
-
failures: (Number(prior?.failures) || 0) + 1,
|
|
291
|
+
failures: (effectiveExecutionKey && prior?.executionKey && effectiveExecutionKey !== prior.executionKey ? 0 : Number(prior?.failures) || 0) + 1,
|
|
290
292
|
firstFailedAt: prior?.firstFailedAt || stamp(),
|
|
293
|
+
...(effectiveExecutionKey ? { executionKey: effectiveExecutionKey, executionSettingsKey } : {}),
|
|
294
|
+
reasonCode,
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
297
|
pushHistory(entry, { jobId, status: 'failed', reasonCode, at: stamp() })
|
|
@@ -16,10 +16,15 @@
|
|
|
16
16
|
// Lexicon extraction, relationship snapshots, global recall, archive/unpin and
|
|
17
17
|
// working_directory were never used by the consolidation pass; removing them
|
|
18
18
|
// also removes their schema from every request.
|
|
19
|
+
// 2026-11-15:link 两件重新挂回——它们不属于上面被裁掉的无用面:auto-link 的
|
|
20
|
+
// 不确定候选本来就是留给整理回合裁决的,此前 worker 没有这两件工具,
|
|
21
|
+
// 「模型不做 link 节点维护(含整理)」是结构性缺口,不是模型不听话。
|
|
19
22
|
export const WORKER_WRITE_TOOLS = Object.freeze([
|
|
20
23
|
'memu_private_remember',
|
|
21
24
|
'memu_private_remember_batch',
|
|
22
25
|
'memu_private_update',
|
|
26
|
+
'memu_private_link',
|
|
27
|
+
'memu_private_link_suggest',
|
|
23
28
|
])
|
|
24
29
|
// 1.3.1:已有记忆目录与本地召回命中都由插件在种子开头注入(零模型调用),
|
|
25
30
|
// worker 不再需要 list / recall / status 任何一个只读回合。
|
|
@@ -190,6 +195,8 @@ export function buildWorkerBrief({ snapshot, probe = null, contract = '', reason
|
|
|
190
195
|
'写库字段:speaker_id、source_kind、observed_at、absolute_date 必填;冲突用 conflicts_with,明确取代用 supersedes;助手说过的话用 source_kind=assistant_said;承诺写 commitment。',
|
|
191
196
|
'按价值排序:约定/承诺 = 新人物首次出现/换人接手/称呼变化 > 日期/改口/冲突 > 身份/边界/第三方人物 > 偏好/计划 > 其他明确事实。前两类必须写;每窗最多新增 8 条,普通事实最多 3 条,必写候选不受限,总数仍不超过 8 条。',
|
|
192
197
|
'同一件事有两种说法时各写一条,用 conflicts_with 互指;只有明确取代才用 supersedes,旧正文保留。承诺/约定写 commitment。',
|
|
198
|
+
// 2026-11-15:link 裁决步骤写进任务书——触发时机明示,模型不再靠读工具参数说明猜。
|
|
199
|
+
'写完条目后用本轮创建/更新的 id 调一次 memu_private_link_suggest,返回的候选【逐条】裁决:有具体证据的用 memu_private_link 连(note 引用转录原句作依据),没有证据的明确放弃,不许全部留着不裁决。触发时机:同一事实的新版本→连到旧条(取代关系);同一个人的多条记忆→挂到命名实体 entity {name, kind};承诺/约定→commitment;两条互斥→conflict。相似≠相连,宁缺毋滥。',
|
|
193
200
|
'content 写 50–150 字,只保留人物、地点、时间、事情、原话/说话人;emotion 只在叙事确实有情绪瞬间时填写,普通事实省略;不要复述整段对话,不要写成行为日志。',
|
|
194
201
|
...(Array.isArray(mustCover) && mustCover.length > 0
|
|
195
202
|
? [
|
package/lib/inbound.js
CHANGED
|
@@ -71,7 +71,7 @@ export function nativeInboundMessage(message) {
|
|
|
71
71
|
let images = 0
|
|
72
72
|
const content = (message?.content || []).filter(block => block?.type === 'text' || block?.type === 'image')
|
|
73
73
|
.filter(block => block.type !== 'image' || ++images <= 8).slice(0, 16)
|
|
74
|
-
.map(block => block.type === 'text' ? { type: 'text', text: String(block.text || '').slice(0, MAX_TEXT) } : block)
|
|
74
|
+
.map(block => block.type === 'text' ? { type: 'text', text: redactSecrets(String(block.text || '').slice(0, MAX_TEXT)) } : block)
|
|
75
75
|
return content.some(block => block.type === 'image' || block.text.trim()) ? { id: message.id, role: 'user', content } : null
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -136,18 +136,23 @@ export function ingestInboundBatch({ sessionId, batch, session, ctx, now = Date.
|
|
|
136
136
|
return { accepted: accepted.length, duplicate: normalized.messages.length - accepted.length, pending: pending.length }
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
export function noteNativeUserMessages(sessionId, messages, { now = Date.now() } = {}) {
|
|
139
|
+
export function noteNativeUserMessages(sessionId, messages, { now = Date.now(), admitted = false } = {}) {
|
|
140
|
+
if (!admitted) return
|
|
140
141
|
const binding = getSessionBinding(sessionId)
|
|
141
142
|
if (!binding) return
|
|
142
143
|
const before = journal(binding)
|
|
143
|
-
const
|
|
144
|
-
|
|
144
|
+
const native = messages.filter(message => message?.source?.kind === 'user' && message.role === 'user' && typeof message.id === 'string')
|
|
145
|
+
const keys = native.map(message => messageKey({ id: message.id, context: binding.memoryContext }))
|
|
145
146
|
const seen = [...new Set([...before.seen, ...keys])].slice(-MAX_SEEN)
|
|
146
147
|
setSessionBinding(sessionId, {
|
|
147
|
-
inbound: { ...before, seen, pending: before.pending.
|
|
148
|
+
inbound: { ...before, seen, pending: before.pending.map(item => native.some(message => item.producer === 'host.user'
|
|
149
|
+
&& item.id === message.id && JSON.stringify(item.content) === JSON.stringify(nativeInboundMessage(message)?.content))
|
|
150
|
+
? { ...item, nativeAdmitted: true } : item) },
|
|
148
151
|
lastTurnAt: new Date(now).toISOString(),
|
|
149
152
|
sessionGone: false, sessionGoneAt: null,
|
|
150
153
|
})
|
|
154
|
+
const outcome = getSessionBinding(sessionId)?.lastInboundOutcome
|
|
155
|
+
if (outcome?.keys?.length) finishInbound(sessionId, outcome.keys, outcome.clock, outcome)
|
|
151
156
|
}
|
|
152
157
|
|
|
153
158
|
export function hasPendingInbound(sessionId) {
|
|
@@ -188,10 +193,19 @@ export function finishInbound(sessionId, keys, clock, outcome) {
|
|
|
188
193
|
if (!binding) return
|
|
189
194
|
const before = journal(binding)
|
|
190
195
|
const done = new Set(keys)
|
|
191
|
-
const
|
|
196
|
+
const matched = before.pending.filter(item => done.has(item.key))
|
|
197
|
+
if (!matched.length) return
|
|
198
|
+
const ready = matched.filter(item => item.producer === 'host.user' ? item.nativeAdmitted === true : outcome?.admitted === true)
|
|
199
|
+
if (ready.length !== matched.length) {
|
|
200
|
+
setSessionBinding(sessionId, { lastInboundOutcome: { ...structuredClone(outcome), status: 'proposed',
|
|
201
|
+
keys: [...keys], clock, at: new Date().toISOString(), count: matched.length } })
|
|
202
|
+
}
|
|
203
|
+
if (!ready.length) return
|
|
204
|
+
const readyKeys = new Set(ready.map(item => item.key))
|
|
205
|
+
const claims = ready.map(item => deliveryClaim({ producer: item.producer, batchId: item.batchId }))
|
|
192
206
|
setSessionBinding(sessionId, {
|
|
193
|
-
inbound: { ...before, seen: [...new Set([...before.seen, ...
|
|
194
|
-
lastInboundOutcome: { ...outcome, at: new Date().toISOString(), count:
|
|
207
|
+
inbound: { ...before, seen: [...new Set([...before.seen, ...readyKeys])].slice(-MAX_SEEN), claimed: [...new Set([...before.claimed, ...claims])].slice(-MAX_SEEN), pending: before.pending.filter(item => !readyKeys.has(item.key)), clock: Math.max(Number(before.clock || 0), Number(clock) || 0), retryAt: null },
|
|
208
|
+
lastInboundOutcome: { ...structuredClone(outcome), keys: [...keys], clock, at: new Date().toISOString(), count: ready.length },
|
|
195
209
|
})
|
|
196
210
|
flushState()
|
|
197
211
|
}
|
|
@@ -249,11 +263,12 @@ export function observeInboundEvent(ctx, session, event) {
|
|
|
249
263
|
const binding = getSessionBinding(id)
|
|
250
264
|
if (!binding || !event.data.id) return
|
|
251
265
|
const message = nativeInboundMessage(event.data)
|
|
252
|
-
if (!message) { noteNativeUserMessages(id, [event.data]); return }
|
|
266
|
+
if (!message) { noteNativeUserMessages(id, [event.data], { admitted: true }); return }
|
|
253
267
|
ingestInboundBatch({ sessionId: id, session, ctx, batch: {
|
|
254
268
|
type: INBOUND_TYPE, version: 1, producer: 'host.user', batchId: `user:${event.data.id}`,
|
|
255
269
|
messages: [message],
|
|
256
270
|
}, mediaEventKey: event.seq !== undefined ? `seq:${event.seq}` : `id:${event.data.id}` })
|
|
271
|
+
noteNativeUserMessages(id, [event.data], { admitted: true })
|
|
257
272
|
} else if (event?.type === 'turn/end') {
|
|
258
273
|
calls.delete(id)
|
|
259
274
|
}
|