dsh-memu-memory 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +3 -1
- package/README.md +12 -4
- package/README.zh.md +13 -5
- package/docs/client-conventions.md +1 -0
- package/docs/contributing.md +7 -6
- package/docs/emotion-model-spec.md +2 -2
- package/docs/env-and-commands.md +20 -0
- package/docs/host-api.md +19 -0
- package/docs/memory-semantics.md +10 -1
- package/docs/troubleshooting.md +36 -3
- package/lib/activity-log.js +1 -1
- package/lib/binding-diagnostics.js +1 -1
- package/lib/client.js +152 -9
- package/lib/cycle.js +9 -1
- package/lib/freshness.js +97 -0
- package/lib/graph.js +244 -2
- package/lib/inject.js +119 -8
- package/lib/memory.js +83 -17
- package/lib/rpc.js +13 -2
- package/lib/salient-wake.js +402 -0
- package/lib/state.js +92 -1
- package/package.json +1 -1
- package/scripts/drive-session.mjs +853 -0
- package/scripts/mock-llm.mjs +903 -0
- package/tests/client-render.test.mjs +13 -1
- package/tests/entity-merge.test.mjs +261 -0
- package/tests/fixtures/mock-llm/reply.txt +1 -0
- package/tests/freshness.test.mjs +140 -0
- package/tests/help-page.test.mjs +4 -4
- package/tests/injection-chain.test.mjs +176 -0
- package/tests/mock-llm.test.mjs +225 -0
- package/tests/open-loop-date.test.mjs +406 -0
- package/tests/salient-wake.test.mjs +362 -0
- package/tests/settings-plumbing.test.mjs +76 -0
- package/tests/sidebar.test.mjs +5 -1
- package/tests/stubs/dsh-schedule.js +105 -0
- package/tests/webui-auth.test.mjs +4 -0
package/lib/client.js
CHANGED
|
@@ -132,6 +132,7 @@ window.__ModuleLoader__.load({
|
|
|
132
132
|
logKindError: '错误',
|
|
133
133
|
logKindSystem: '系统',
|
|
134
134
|
logKindCheck: '主动检查',
|
|
135
|
+
logKindWake: '日期唤醒',
|
|
135
136
|
logClear: '清空日志',
|
|
136
137
|
runLogTitle: '整理记录',
|
|
137
138
|
runLogEmpty: '还没有整理记录。',
|
|
@@ -172,6 +173,15 @@ window.__ModuleLoader__.load({
|
|
|
172
173
|
viewMemory: '查看此记忆',
|
|
173
174
|
entityDelete: '删除实体',
|
|
174
175
|
entityDeleteForceHint: '仍被记忆或关系引用;再点一次将连同引用一起删除',
|
|
176
|
+
entityMergeTitle: '合并候选',
|
|
177
|
+
entityMergeHint: '写法相近的实体只是建议,不会自动合并。合并后来源实体的记忆链接改指主节点,别名并入,来源实体消失;记忆本身不删除。',
|
|
178
|
+
entityMergeAction: '合并',
|
|
179
|
+
entityMergeConfirm: '确认合并',
|
|
180
|
+
entityMergeDone: '已把「{from}」并入「{to}」:{links} 条记忆链接改指,别名共 {aliases} 个',
|
|
181
|
+
entityMergeDropped: '({n} 个别名超出上限,未并入)',
|
|
182
|
+
entityMergeConflict: '({n} 条关系快照与主节点侧冲突,保留主节点侧)',
|
|
183
|
+
mergeReasonContainment: '名称包含',
|
|
184
|
+
mergeReasonDistance: '写法相近',
|
|
175
185
|
openMemu: '打开 MemU WebUI',
|
|
176
186
|
saved: '已保存',
|
|
177
187
|
copied: '已复制',
|
|
@@ -270,6 +280,16 @@ window.__ModuleLoader__.load({
|
|
|
270
280
|
globalEveryNTurns: '全局每 N 轮',
|
|
271
281
|
minUserChars: '最短用户消息',
|
|
272
282
|
randomCueChance: '随机侧事件概率',
|
|
283
|
+
openLoopRemindDays: '未了之事复提间隔(天)',
|
|
284
|
+
freshnessHint: '时效提示',
|
|
285
|
+
freshnessDays: '写够多久算过时(天)',
|
|
286
|
+
freshnessHintHint: '召回里有条目带时间敏感信号时,在块尾提示模型先核实再回答「现在怎样」。',
|
|
287
|
+
salientWake: '日期到点唤醒',
|
|
288
|
+
salientWakeOff: '关闭(只被动注入)',
|
|
289
|
+
salientWakeSchedule: '到点唤醒会话',
|
|
290
|
+
salientWakeHour: '唤醒时间(HH:mm)',
|
|
291
|
+
salientWakeTimeZone: '唤醒时区(留空跟随系统)',
|
|
292
|
+
salientWakeHint: '实验特性,默认关闭。唤醒走宿主定时任务投递,会替会话开一整轮;只有宿主进程活着才会触发,任务在宿主的定时任务界面可见、可手动删除。还没做过真机验收,建议先在测试库里试开。',
|
|
273
293
|
autoInstall: '自动安装引擎',
|
|
274
294
|
sleepConsolidation: '空闲后整理记忆',
|
|
275
295
|
sleepAfterIdleMinutes: '空闲多久后整理(分钟)',
|
|
@@ -312,6 +332,13 @@ window.__ModuleLoader__.load({
|
|
|
312
332
|
salientDateLabel: '日期(MM-DD 每年复现,YYYY-MM-DD 一次性)',
|
|
313
333
|
salientDatePlaceholder: '例如 10-29 或 2026-10-29,留空则不设日期',
|
|
314
334
|
moodTag: '情绪',
|
|
335
|
+
arousalLabel: '激活',
|
|
336
|
+
dominanceLabel: '掌控',
|
|
337
|
+
emotionSourceLabel: '来源',
|
|
338
|
+
emotionSourceModel: '模型标注',
|
|
339
|
+
emotionSourceSession: '会话心情',
|
|
340
|
+
emotionSourceContent: '正文识别',
|
|
341
|
+
emotionSourceUnknown: '未知',
|
|
315
342
|
reviews: '待复核',
|
|
316
343
|
reviewsEmpty: '没有等待复核的记忆。',
|
|
317
344
|
reviewScopePrivate: '私有库',
|
|
@@ -819,6 +846,8 @@ window.__ModuleLoader__.load({
|
|
|
819
846
|
helpFaq9A: '不会。会话被删除后,空闲整理扫描会把它标记为 sessionGone 并跳过,只记一条 check 级日志,不反复重试,也不影响其他会话的整理。',
|
|
820
847
|
helpFaq10: '本地向量模型未激活怎么办?',
|
|
821
848
|
helpFaq10A: '没有 active 向量代际时会回退词法检索,仍可用但语义更弱。「当前已入向量库 N 条」指 active 代际里的条数;切换模型或修复失败后要重建,旧代际在重建期间只读,失败不会动当前代际,可再点一次续建。',
|
|
849
|
+
helpFaq11: '对话里为什么会主动提「那个日子已经过了」或「这条可能过时了」?',
|
|
850
|
+
helpFaq11A: '三种情况都来自记忆本身,不是模型即兴:① 带 `YYYY-MM-DD` 的未了之事过期后,会按「未了之事复提间隔」(默认 7 天)重新提一次,同一天不重复,也没日期的承诺仍是提过一次就安静;② 召回里有时效信号的条目(日期已过、标题带「最新/价格/版本」这类词、或写得够久)会让注入块尾多一行提示,让模型在会话有搜索工具时先核实——它不声称工具一定存在;③「日期到点唤醒」是**实验特性**且默认关闭,打开后宿主会在日子当天用定时任务让会话开一轮,那种回合不跑常规召回,所以只带着那条日期说话。三者都只是提示:不自动写记忆、不自动关闭约定,也不自动删除任何东西。',
|
|
822
851
|
helpFeedback: '反馈',
|
|
823
852
|
helpOpenIssue: '提交 Issue',
|
|
824
853
|
helpCopyDiagnostics: '复制诊断信息',
|
|
@@ -851,6 +880,7 @@ window.__ModuleLoader__.load({
|
|
|
851
880
|
logKindError: 'Error',
|
|
852
881
|
logKindSystem: 'System',
|
|
853
882
|
logKindCheck: 'Check',
|
|
883
|
+
logKindWake: 'Date wake',
|
|
854
884
|
logClear: 'Clear log',
|
|
855
885
|
runLogTitle: 'Runs',
|
|
856
886
|
runLogEmpty: 'No runs recorded yet.',
|
|
@@ -891,6 +921,15 @@ window.__ModuleLoader__.load({
|
|
|
891
921
|
viewMemory: 'View',
|
|
892
922
|
entityDelete: 'Delete entity',
|
|
893
923
|
entityDeleteForceHint: 'Still referenced by memories or relations; click again to delete with its links',
|
|
924
|
+
entityMergeTitle: 'Merge candidates',
|
|
925
|
+
entityMergeHint: 'Similar spellings are only suggestions and are never merged automatically. Merging redirects the source entity memory links to the main node, folds its aliases in, and drops the source entity; memories themselves are never deleted.',
|
|
926
|
+
entityMergeAction: 'Merge',
|
|
927
|
+
entityMergeConfirm: 'Confirm merge',
|
|
928
|
+
entityMergeDone: 'Merged "{from}" into "{to}": {links} memory links redirected, {aliases} aliases in total',
|
|
929
|
+
entityMergeDropped: '({n} aliases over the cap were not folded in)',
|
|
930
|
+
entityMergeConflict: '({n} relationship snapshots clashed with the target side and were dropped)',
|
|
931
|
+
mergeReasonContainment: 'Name contained',
|
|
932
|
+
mergeReasonDistance: 'Similar spelling',
|
|
894
933
|
openMemu: 'Open MemU WebUI',
|
|
895
934
|
saved: 'Saved',
|
|
896
935
|
copied: 'Copied',
|
|
@@ -989,6 +1028,16 @@ window.__ModuleLoader__.load({
|
|
|
989
1028
|
globalEveryNTurns: 'Global every N turns',
|
|
990
1029
|
minUserChars: 'Min user chars',
|
|
991
1030
|
randomCueChance: 'Random cue chance',
|
|
1031
|
+
openLoopRemindDays: 'Re-remind open loops every N days',
|
|
1032
|
+
freshnessHint: 'Freshness hint',
|
|
1033
|
+
freshnessDays: 'Age treated as stale (days)',
|
|
1034
|
+
freshnessHintHint: 'When recalled entries carry time-sensitive signals, add one line telling the model to verify before answering about the present.',
|
|
1035
|
+
salientWake: 'Wake on salient dates',
|
|
1036
|
+
salientWakeOff: 'Off (passive injection only)',
|
|
1037
|
+
salientWakeSchedule: 'Wake the conversation',
|
|
1038
|
+
salientWakeHour: 'Wake time (HH:mm)',
|
|
1039
|
+
salientWakeTimeZone: 'Wake time zone (empty = system)',
|
|
1040
|
+
salientWakeHint: 'Experimental and off by default. Delivery goes through the host scheduler and opens a full turn for the conversation. It only fires while the host process is alive, and the tasks are visible (and deletable) in the host schedule UI. Not yet verified on a real install — try it on a test library first.',
|
|
992
1041
|
autoInstall: 'Auto-install engine',
|
|
993
1042
|
sleepConsolidation: 'Consolidate after idle',
|
|
994
1043
|
sleepAfterIdleMinutes: 'Idle minutes before consolidating',
|
|
@@ -1031,6 +1080,13 @@ window.__ModuleLoader__.load({
|
|
|
1031
1080
|
salientDateLabel: 'Date (MM-DD recurs yearly, YYYY-MM-DD is one-off)',
|
|
1032
1081
|
salientDatePlaceholder: 'e.g. 10-29 or 2026-10-29; empty for no date',
|
|
1033
1082
|
moodTag: 'mood',
|
|
1083
|
+
arousalLabel: 'arousal',
|
|
1084
|
+
dominanceLabel: 'dominance',
|
|
1085
|
+
emotionSourceLabel: 'source',
|
|
1086
|
+
emotionSourceModel: 'model',
|
|
1087
|
+
emotionSourceSession: 'session',
|
|
1088
|
+
emotionSourceContent: 'content',
|
|
1089
|
+
emotionSourceUnknown: 'unknown',
|
|
1034
1090
|
reviews: 'Awaiting review',
|
|
1035
1091
|
reviewsEmpty: 'No memories are waiting for review.',
|
|
1036
1092
|
reviewScopePrivate: 'private library',
|
|
@@ -1537,6 +1593,8 @@ window.__ModuleLoader__.load({
|
|
|
1537
1593
|
helpFaq9A: 'No. Once a conversation is deleted, the idle sweep marks it sessionGone and skips it, records a check-level log instead of an error, and does not retry forever or affect other conversations.',
|
|
1538
1594
|
helpFaq10: 'The vector model is inactive — what happens?',
|
|
1539
1595
|
helpFaq10A: 'Recall falls back to lexical search: still usable, weaker semantically. "Currently indexed N items" counts the active generation. Switching models or repairing a failure requires a rebuild; the old generation stays read-only during it, a failed rebuild leaves the active generation unchanged, and pressing again resumes.',
|
|
1596
|
+
helpFaq11: 'Why does the conversation bring up "that date already passed" or "this may be out of date"?',
|
|
1597
|
+
helpFaq11A: 'All three cases come from the memories themselves, not the model improvising: (1) an open loop whose `YYYY-MM-DD` has passed is raised again on the "re-remind every N days" cadence (default 7), never twice on one day, while undated promises stay quiet after their first mention; (2) recalled entries with time-sensitive signals (a past date, wording like "latest / price / version", or enough age) append one line to the recall block telling the model to verify first if the conversation has a search tool — it never claims the tool exists; (3) date wake-up is an experimental switch and off by default: with it enabled the host scheduler opens a turn on the day itself, and that turn runs no normal recall, so it only carries that date. All three are hints: nothing is written automatically, no commitment is closed automatically, nothing is deleted.',
|
|
1540
1598
|
helpFeedback: 'Feedback',
|
|
1541
1599
|
helpOpenIssue: 'Open an issue',
|
|
1542
1600
|
helpCopyDiagnostics: 'Copy diagnostics',
|
|
@@ -2214,6 +2272,27 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2214
2272
|
.join('/')
|
|
2215
2273
|
}
|
|
2216
2274
|
|
|
2275
|
+
const EMOTION_SOURCE_LABELS = {
|
|
2276
|
+
model: 'emotionSourceModel',
|
|
2277
|
+
session: 'emotionSourceSession',
|
|
2278
|
+
content: 'emotionSourceContent',
|
|
2279
|
+
unknown: 'emotionSourceUnknown',
|
|
2280
|
+
}
|
|
2281
|
+
// Read-only affect metadata. Old entries have no arousal/dominance at all; do
|
|
2282
|
+
// not infer them from valence, and do not show a lone source line.
|
|
2283
|
+
function emotionMetaText(entry, t) {
|
|
2284
|
+
const arousal = typeof entry?.arousal === 'number' && Number.isFinite(entry.arousal) ? entry.arousal : null
|
|
2285
|
+
const dominance = typeof entry?.dominance === 'number' && Number.isFinite(entry.dominance) ? entry.dominance : null
|
|
2286
|
+
if (arousal === null && dominance === null) return ''
|
|
2287
|
+
const parts = []
|
|
2288
|
+
if (arousal !== null) parts.push(`${t('arousalLabel')} ${arousal.toFixed(1)}`)
|
|
2289
|
+
if (dominance !== null) parts.push(`${t('dominanceLabel')} ${dominance > 0 ? '+' : ''}${dominance.toFixed(1)}`)
|
|
2290
|
+
if (entry?.emotionSource) {
|
|
2291
|
+
parts.push(`${t('emotionSourceLabel')} ${t(EMOTION_SOURCE_LABELS[entry.emotionSource] || 'emotionSourceUnknown')}`)
|
|
2292
|
+
}
|
|
2293
|
+
return parts.join(' · ')
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2217
2296
|
// Tags are labels, not decoration — except when the label is a warning. A memory
|
|
2218
2297
|
// marked "never say out loud" has to look different from one that can be said,
|
|
2219
2298
|
// otherwise the badge is just more grey text to skim past.
|
|
@@ -2222,9 +2301,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2222
2301
|
info: { color: V.accent, background: V.accentSoft },
|
|
2223
2302
|
}
|
|
2224
2303
|
|
|
2225
|
-
function Tag({ children, tone }) {
|
|
2304
|
+
function Tag({ children, tone, title }) {
|
|
2226
2305
|
const style = tone && TAG_TONES[tone] ? { ...S.tag, ...TAG_TONES[tone] } : S.tag
|
|
2227
|
-
return h('span', { style }, children)
|
|
2306
|
+
return h('span', { style, title }, children)
|
|
2228
2307
|
}
|
|
2229
2308
|
|
|
2230
2309
|
// The host lists untitled sessions (renamed title events are async), so fall
|
|
@@ -2499,6 +2578,10 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2499
2578
|
const [armed, setArmed] = React.useState('')
|
|
2500
2579
|
// deleteEntity 被后端拒绝(仍被引用)的实体 id:此时再点确认升级为 force。
|
|
2501
2580
|
const [deleteRefused, setDeleteRefused] = React.useState('')
|
|
2581
|
+
// 工单 F:实体合并候选。后端只出建议,合并必须由用户逐条确认;候选读失败不影响
|
|
2582
|
+
// 图谱其余部分,所以单独 catch 成空列表。
|
|
2583
|
+
const [merges, setMerges] = React.useState([])
|
|
2584
|
+
const [mergeNotice, setMergeNotice] = React.useState('')
|
|
2502
2585
|
const [error, setError] = React.useState('')
|
|
2503
2586
|
const requestId = React.useRef(0)
|
|
2504
2587
|
const mounted = React.useRef(true)
|
|
@@ -2508,12 +2591,13 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2508
2591
|
}, [])
|
|
2509
2592
|
const refresh = React.useCallback(async () => {
|
|
2510
2593
|
const id = ++requestId.current
|
|
2511
|
-
const [next, list] = await Promise.all([
|
|
2594
|
+
const [next, list, suggested] = await Promise.all([
|
|
2512
2595
|
call('getGraph', { libraryId, focusId: focus || null, depth: 2, limit: 200 }),
|
|
2513
2596
|
call('listEntities', { libraryId }),
|
|
2597
|
+
call('suggestEntityMerges', { libraryId }).catch(() => null),
|
|
2514
2598
|
])
|
|
2515
2599
|
if (mounted.current && id === requestId.current) {
|
|
2516
|
-
setGraph(next); setEntities(list.items || []); setError('')
|
|
2600
|
+
setGraph(next); setEntities(list.items || []); setMerges(suggested?.items || []); setError('')
|
|
2517
2601
|
}
|
|
2518
2602
|
}, [call, libraryId, focus])
|
|
2519
2603
|
React.useEffect(() => {
|
|
@@ -2531,6 +2615,12 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2531
2615
|
const timer = setTimeout(() => setError(''), 2600)
|
|
2532
2616
|
return () => clearTimeout(timer)
|
|
2533
2617
|
}, [error])
|
|
2618
|
+
// 合并影响面要说清"多少条链接改了指向",比普通错误停留更久。
|
|
2619
|
+
React.useEffect(() => {
|
|
2620
|
+
if (!mergeNotice) return undefined
|
|
2621
|
+
const timer = setTimeout(() => setMergeNotice(''), 9000)
|
|
2622
|
+
return () => clearTimeout(timer)
|
|
2623
|
+
}, [mergeNotice])
|
|
2534
2624
|
const act = async (method, payload) => {
|
|
2535
2625
|
try {
|
|
2536
2626
|
await call(method, { libraryId, ...payload })
|
|
@@ -2538,6 +2628,28 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2538
2628
|
if (mounted.current) await refresh()
|
|
2539
2629
|
} catch (error) { if (mounted.current) setError(String(error.message || error)) }
|
|
2540
2630
|
}
|
|
2631
|
+
const entityLabel = (id) => {
|
|
2632
|
+
const found = entities.find(item => item.id === id)
|
|
2633
|
+
return found ? (found.name || found.id) : id
|
|
2634
|
+
}
|
|
2635
|
+
const doMerge = async (item) => {
|
|
2636
|
+
try {
|
|
2637
|
+
const result = await call('mergeEntities', { libraryId, targetId: item.targetId, sourceIds: [item.sourceId] })
|
|
2638
|
+
let message = t('entityMergeDone')
|
|
2639
|
+
.replace('{from}', entityLabel(item.sourceId))
|
|
2640
|
+
.replace('{to}', entityLabel(item.targetId))
|
|
2641
|
+
.replace('{links}', String(result?.remappedLinks ?? 0))
|
|
2642
|
+
.replace('{aliases}', String((result?.aliases || []).length))
|
|
2643
|
+
const dropped = (result?.droppedAliases || []).length
|
|
2644
|
+
if (dropped) message += ' ' + t('entityMergeDropped').replace('{n}', String(dropped))
|
|
2645
|
+
const conflicts = (result?.relationships?.conflicts || []).length
|
|
2646
|
+
if (conflicts) message += ' ' + t('entityMergeConflict').replace('{n}', String(conflicts))
|
|
2647
|
+
setArmed('')
|
|
2648
|
+
setMergeNotice(message)
|
|
2649
|
+
notifyMemoryWrite('relation', libraryId)
|
|
2650
|
+
if (mounted.current) await refresh()
|
|
2651
|
+
} catch (failure) { if (mounted.current) setError(String(failure.message || failure)) }
|
|
2652
|
+
}
|
|
2541
2653
|
const titles = new Map(graph.nodes.map(node => [node.id, node.missing ? t('deletedNode') : node.title]))
|
|
2542
2654
|
const edges = graph.edges.filter(edge => !focus || edge.from === focus || edge.to === focus).sort((a, b) => b.confidence - a.confidence)
|
|
2543
2655
|
// 实体行:改名表单 + 删除按钮。删除是文字按钮(§6.4 包 D,原灰色 × 读不出
|
|
@@ -2614,6 +2726,23 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2614
2726
|
h('select', { value: entityKind, title: t('entityKind'), onChange: event => setEntityKind(event.target.value) }, ['person', 'place', 'thing', 'org'].map(value => h('option', { key: value, value }, value))),
|
|
2615
2727
|
h(Button, { disabled: !entityName.trim(), onClick: () => act('createEntity', { name: entityName, kind: entityKind }) }, t('entityNew'))),
|
|
2616
2728
|
h(RelationshipPanel, { call, libraryId, entities, files, t }),
|
|
2729
|
+
// 工单 F:合并候选只列出来,永不自动合并。两次点击确认沿用删除的 armed 模式,
|
|
2730
|
+
// 合并后的影响面(改指多少条链接、并入多少别名)用一行回执说清。
|
|
2731
|
+
mergeNotice ? h('div', { style: { ...S.muted, marginTop: 6, color: V.accent }, role: 'status' }, mergeNotice) : null,
|
|
2732
|
+
merges.length ? h('div', { style: { margin: '10px 0' } },
|
|
2733
|
+
h('div', { style: { fontSize: 12, fontWeight: 600 } }, t('entityMergeTitle')),
|
|
2734
|
+
h('div', { style: { ...S.muted, margin: '4px 0 6px', lineHeight: 1.5 } }, t('entityMergeHint')),
|
|
2735
|
+
merges.map(item => {
|
|
2736
|
+
const key = 'merge:' + item.sourceId + '>' + item.targetId
|
|
2737
|
+
return h('div', { key, className: 'dshm-graph-tools' },
|
|
2738
|
+
h('span', { style: { minWidth: 0, overflowWrap: 'anywhere' } }, entityLabel(item.sourceId) + ' → ' + entityLabel(item.targetId)),
|
|
2739
|
+
h(Tag, { tone: 'info' }, item.reason === 'containment' ? t('mergeReasonContainment') : t('mergeReasonDistance')),
|
|
2740
|
+
h(Button, {
|
|
2741
|
+
style: armed === key ? { ...S.btn, color: V.danger, borderColor: V.danger } : S.btn,
|
|
2742
|
+
title: t('entityMergeHint'),
|
|
2743
|
+
onClick: () => { if (armed !== key) { setArmed(key); return } void doMerge(item) },
|
|
2744
|
+
}, armed === key ? t('entityMergeConfirm') : t('entityMergeAction')))
|
|
2745
|
+
})) : null,
|
|
2617
2746
|
entities.length === 0 ? h(Empty, null, t('entityEmpty')) : null,
|
|
2618
2747
|
// 孤立分组(§6.4 包 D):listEntities 给出 linked 派生标记。被引用的实体照常
|
|
2619
2748
|
// 渲染;孤立实体(linked=false,没有任何记忆 link/关系快照指着)收进折叠区,
|
|
@@ -2917,7 +3046,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
2917
3046
|
t('openLoopTag'))),
|
|
2918
3047
|
h('div', { className: 'dshm-drawer-note' },
|
|
2919
3048
|
t('decay') + ' ' + Math.round((Number(shown.decay) || 0) * 100) + '% · ' +
|
|
2920
|
-
(shown.updatedAt ? String(shown.updatedAt).slice(0, 16).replace('T', ' ') : ''))
|
|
3049
|
+
(shown.updatedAt ? String(shown.updatedAt).slice(0, 16).replace('T', ' ') : '')),
|
|
3050
|
+
emotionMetaText(shown, t) ? h('div', { className: 'dshm-drawer-note' }, emotionMetaText(shown, t)) : null)
|
|
2921
3051
|
: detail && detail.file && detail.readonly
|
|
2922
3052
|
? (() => {
|
|
2923
3053
|
// 全局条目只读(spec §6.7 UI):详情抽屉里只读展示 links / absorbedFrom,
|
|
@@ -4969,6 +5099,17 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4969
5099
|
h(Field, { label: t('minUserChars') }, h('input', { type: 'number', style: S.input, value: settings.minUserChars ?? 6, onChange: (e) => setSetting('minUserChars', Number(e.target.value)) })),
|
|
4970
5100
|
h(Field, { label: t('relevanceThreshold') }, h('input', { type: 'number', step: '0.05', min: 0, max: 1, style: S.input, value: settings.relevanceThreshold ?? 0.4, onChange: (e) => setSetting('relevanceThreshold', Number(e.target.value)) })),
|
|
4971
5101
|
h(Field, { label: t('randomCueChance') }, h('input', { type: 'number', step: '0.01', min: 0, max: 1, style: S.input, value: settings.randomCueChance ?? 0.02, onChange: (e) => setSetting('randomCueChance', Number(e.target.value)) })),
|
|
5102
|
+
h(Field, { label: t('openLoopRemindDays') }, h('input', { type: 'number', min: 1, max: 365, style: S.input, value: settings.openLoopRemindDays ?? 7, onChange: (e) => setSetting('openLoopRemindDays', Number(e.target.value)) })),
|
|
5103
|
+
h(Field, { label: t('freshnessHint') }, h(Toggle, { checked: settings.freshnessHint !== false, label: t('freshnessHint'), onChange: value => setSetting('freshnessHint', value) })),
|
|
5104
|
+
h(Field, { label: t('freshnessDays') }, h('input', { type: 'number', min: 1, max: 3650, style: S.input, value: settings.freshnessDays ?? 30, onChange: (e) => setSetting('freshnessDays', Number(e.target.value)) })),
|
|
5105
|
+
h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('freshnessHintHint')),
|
|
5106
|
+
h(Field, { label: t('salientWake') },
|
|
5107
|
+
h('select', { style: S.input, value: settings.salientWake || 'off', onChange: (e) => setSetting('salientWake', e.target.value) },
|
|
5108
|
+
h('option', { value: 'off' }, t('salientWakeOff')),
|
|
5109
|
+
h('option', { value: 'schedule' }, t('salientWakeSchedule')))),
|
|
5110
|
+
h(Field, { label: t('salientWakeHour') }, h('input', { type: 'time', style: S.input, value: settings.salientWakeHour || '09:00', onChange: (e) => setSetting('salientWakeHour', e.target.value) })),
|
|
5111
|
+
h(Field, { label: t('salientWakeTimeZone') }, h('input', { type: 'text', style: S.input, placeholder: 'Asia/Shanghai', value: settings.salientWakeTimeZone || '', onChange: (e) => setSetting('salientWakeTimeZone', e.target.value) })),
|
|
5112
|
+
h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('salientWakeHint')),
|
|
4972
5113
|
h(Field, { label: t('autoInstall') }, h('input', { type: 'checkbox', checked: settings.autoInstallEngine !== false, onChange: (e) => setSetting('autoInstallEngine', e.target.checked) })),
|
|
4973
5114
|
h(Field, { label: t('newSessionPrompt') }, h('input', { type: 'checkbox', checked: settings.newSessionPromptDismissed !== true, onChange: (e) => setSetting('newSessionPromptDismissed', !e.target.checked) })),
|
|
4974
5115
|
h(Field, { label: t('habitsInjection') }, h('input', { type: 'checkbox', checked: settings.habitsInjection !== false, onChange: (e) => setSetting('habitsInjection', e.target.checked) })),
|
|
@@ -5303,7 +5444,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5303
5444
|
f.salientDate
|
|
5304
5445
|
? h(Tag, null, `${/^\d{4}-\d{2}-\d{2}$/.test(f.salientDate) ? t('dueDateTag') : t('anniversaryTag')} ${f.salientDate}`)
|
|
5305
5446
|
: null,
|
|
5306
|
-
moodText ? h(Tag,
|
|
5447
|
+
moodText ? h(Tag, { title: emotionMetaText(f, t) || undefined }, `${t('moodTag')} ${moodText}`) : null,
|
|
5307
5448
|
typeof f.accuracy === 'number' && typeof f.confidence === 'number' && f.accuracy <= 0.6 && f.accuracy < f.confidence - 0.1
|
|
5308
5449
|
? h(Tag, { tone: 'warn' }, `${t('accuracyTag')} ${f.accuracy}`) : null,
|
|
5309
5450
|
h(Tag, null, enumText(t, STATUS_LABELS, f.status || 'active'))),
|
|
@@ -5720,7 +5861,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5720
5861
|
},
|
|
5721
5862
|
})
|
|
5722
5863
|
|
|
5723
|
-
// 帮助页 v2(包 G4):快速开始 5 步 + 七个详解区 + FAQ
|
|
5864
|
+
// 帮助页 v2(包 G4):快速开始 5 步 + 七个详解区 + FAQ 11 条 + 反馈入口。
|
|
5724
5865
|
// 所有跳转都走既有 setPage(不新增路由/RPC/localStorage),诊断复制只序列化
|
|
5725
5866
|
// getSettingsState 已有快照(复用上方 copyText);正文全部走 i18n,段落/列表/
|
|
5726
5867
|
// 表格只由本地小助手拼装,样式复用 Section/Tag/Button 与 S 里的既有 token。
|
|
@@ -5813,7 +5954,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5813
5954
|
helpBullets(['helpSidebarAlerts', 'helpSidebarReview', 'helpSidebarRunLog',
|
|
5814
5955
|
'helpSidebarReviewMode', 'helpSidebarFirstRun', 'helpSidebarFallback', 'helpSidebarScope'])),
|
|
5815
5956
|
h(Section, { title: t('helpFaq'), icon: GlyphQuestion },
|
|
5816
|
-
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map(n => h('details', { key: 'helpFaq' + n, style: { margin: '0 0 8px' } },
|
|
5957
|
+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(n => h('details', { key: 'helpFaq' + n, style: { margin: '0 0 8px' } },
|
|
5817
5958
|
h('summary', { style: { cursor: 'pointer', fontSize: 12.5, fontWeight: 600, lineHeight: 1.5 } }, t('helpFaq' + n)),
|
|
5818
5959
|
h('div', { style: { ...S.muted, marginTop: 5, fontSize: 12, lineHeight: 1.7 } }, t('helpFaq' + n + 'A'))))),
|
|
5819
5960
|
h(Section, { title: t('helpFeedback'), icon: GlyphGlobe },
|
|
@@ -5833,6 +5974,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5833
5974
|
const LOG_KIND_LABELS = {
|
|
5834
5975
|
recall: t('logKindRecall'), write: t('logKindWrite'), consolidate: t('logKindConsolidate'),
|
|
5835
5976
|
curate: t('logKindCurate'), vector: t('logKindVector'), error: t('logKindError'), system: t('logKindSystem'), check: t('logKindCheck'),
|
|
5977
|
+
wake: t('logKindWake'),
|
|
5836
5978
|
}
|
|
5837
5979
|
const logsBlock = h(React.Fragment, null,
|
|
5838
5980
|
h(Section, {
|
|
@@ -5867,7 +6009,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
5867
6009
|
onChange: (event) => setLogKind(event.target.value),
|
|
5868
6010
|
},
|
|
5869
6011
|
h('option', { value: '' }, t('logAllKinds')),
|
|
5870
|
-
['recall', 'write', 'consolidate', 'curate', 'vector', 'error', 'check'].map(kind => h('option', { key: kind, value: kind }, LOG_KIND_LABELS[kind]))),
|
|
6012
|
+
['recall', 'write', 'consolidate', 'curate', 'vector', 'error', 'check', 'wake'].map(kind => h('option', { key: kind, value: kind }, LOG_KIND_LABELS[kind]))),
|
|
5871
6013
|
h('input', {
|
|
5872
6014
|
style: S.input,
|
|
5873
6015
|
value: logQueryInput,
|
|
@@ -6265,6 +6407,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6265
6407
|
const RUN_KIND_LABELS = {
|
|
6266
6408
|
recall: t('logKindRecall'), write: t('logKindWrite'), consolidate: t('logKindConsolidate'),
|
|
6267
6409
|
curate: t('logKindCurate'), vector: t('logKindVector'), error: t('logKindError'), system: t('logKindSystem'),
|
|
6410
|
+
check: t('logKindCheck'), wake: t('logKindWake'),
|
|
6268
6411
|
}
|
|
6269
6412
|
const renderRunRow = (row) => h('div', { key: row.id, style: S.item },
|
|
6270
6413
|
h('div', { style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap' } },
|
package/lib/cycle.js
CHANGED
|
@@ -7,6 +7,7 @@ import { expireShortTerm } from './memory.js'
|
|
|
7
7
|
import { requestPrivateConsolidation } from './private.js'
|
|
8
8
|
import { startGlobalCuration } from './curator.js'
|
|
9
9
|
import { runVisibilityMigrationPass } from './migrate.js'
|
|
10
|
+
import { runSalientWakePass } from './salient-wake.js'
|
|
10
11
|
import { record } from './activity-log.js'
|
|
11
12
|
import { ACTIVE_MEMORY_POLICY, suppressionReason } from './active-memory.js'
|
|
12
13
|
import { clearSessionState } from './consolidation-ledger.js'
|
|
@@ -256,7 +257,14 @@ export async function runCyclePasses(ctx, options = {}) {
|
|
|
256
257
|
// updated mid-flight. Reads are already normalized, so this only keeps the files in
|
|
257
258
|
// step with the code (see lib/migrate.js); it is cheap and idempotent.
|
|
258
259
|
const migrated = runVisibilityMigrationPass({ log: options.log })
|
|
259
|
-
|
|
260
|
+
// 工单 E:纪念日到点唤醒。放在最后:它是唯一会碰宿主 schedule 服务的 pass,宿主没
|
|
261
|
+
// 这个服务时只返回 `{skipped:'service'}`;即使它整体失败,上面的短期过期、睡眠整理、
|
|
262
|
+
// 自动提炼和库迁移已经跑完,下一次 sweep 照常重试。
|
|
263
|
+
const salientWake = await runSalientWakePass(ctx, { now: options.now ?? new Date(), log: options.log }).catch((error) => {
|
|
264
|
+
try { options.log?.(`salient wake pass failed: ${error?.message || error}`) } catch {}
|
|
265
|
+
return { created: 0, cleaned: 0, skipped: 0, errors: 1 }
|
|
266
|
+
})
|
|
267
|
+
return { shortTerm, sleep, curate, libraries, migrated, salientWake }
|
|
260
268
|
}
|
|
261
269
|
|
|
262
270
|
// DSH has no host scheduler a plugin can register a *global* job with
|
package/lib/freshness.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Freshness signals for a recalled memory (work order D).
|
|
2
|
+
//
|
|
3
|
+
// The hint that buildRecall appends is only as good as this classification, so the
|
|
4
|
+
// rules stay small and local:
|
|
5
|
+
// 1. a one-off salient date (YYYY-MM-DD) has already passed;
|
|
6
|
+
// 2. the title or body names something time-sensitive (最新 / 价格 / ...);
|
|
7
|
+
// 3. the entry itself is old enough (`updatedAt || createdAt` >= freshnessDays),
|
|
8
|
+
// except project facts, whose staleness is better judged against the code.
|
|
9
|
+
//
|
|
10
|
+
// An annual MM-DD date is a birthday, not an expiry: it never goes stale by itself.
|
|
11
|
+
// The word list is fixed on purpose — exposing it as a setting would create a second
|
|
12
|
+
// vocabulary system, and this is a nudge, not a filter.
|
|
13
|
+
|
|
14
|
+
const DAY_MS = 86_400_000
|
|
15
|
+
const DEFAULT_FRESHNESS_DAYS = 30
|
|
16
|
+
// Fixed first-version vocabulary (plan D.2). Keep it separate from the lexicon.
|
|
17
|
+
const FRESHNESS_TERMS = ['最新', '最近', '现在', '目前', '今年', '版本', '价格', '天气', '新闻', '比分', '汇率']
|
|
18
|
+
const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/
|
|
19
|
+
|
|
20
|
+
// `now` accepts a Date, epoch milliseconds or a parsable stamp. Anything invalid
|
|
21
|
+
// falls back to the wall clock so a caller mistake cannot crash a recall.
|
|
22
|
+
function baseTime(now) {
|
|
23
|
+
let date
|
|
24
|
+
if (now instanceof Date) date = now
|
|
25
|
+
else if (typeof now === 'number') date = new Date(now)
|
|
26
|
+
else date = new Date(now ?? Date.now())
|
|
27
|
+
const time = date instanceof Date ? date.getTime() : NaN
|
|
28
|
+
return Number.isFinite(time) ? time : Date.now()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Strict `YYYY-MM-DD` in local time. Returns null for MM-DD (annual), malformed
|
|
32
|
+
// strings and impossible dates such as 2026-02-30; those must never read as expired.
|
|
33
|
+
function datedValue(value) {
|
|
34
|
+
const text = String(value ?? '').trim()
|
|
35
|
+
const match = DATE_RE.exec(text)
|
|
36
|
+
if (!match) return null
|
|
37
|
+
const year = Number(match[1])
|
|
38
|
+
const month = Number(match[2])
|
|
39
|
+
const day = Number(match[3])
|
|
40
|
+
if (month < 1 || month > 12 || day < 1 || day > 31) return null
|
|
41
|
+
const date = new Date(0)
|
|
42
|
+
date.setFullYear(year, month - 1, day)
|
|
43
|
+
date.setHours(0, 0, 0, 0)
|
|
44
|
+
if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return null
|
|
45
|
+
return { text: `${match[1]}-${match[2]}-${match[3]}`, time: date.getTime() }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function timestampMs(value) {
|
|
49
|
+
if (value === undefined || value === null || value === '') return null
|
|
50
|
+
const at = typeof value === 'number' ? value : Date.parse(String(value))
|
|
51
|
+
return Number.isFinite(at) ? at : null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function thresholdDays(value) {
|
|
55
|
+
const days = Number(value)
|
|
56
|
+
return Number.isFinite(days) && days >= 0 ? days : DEFAULT_FRESHNESS_DAYS
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Classify one recalled entry.
|
|
61
|
+
*
|
|
62
|
+
* @param {object} entry memory entry; `title`/`content` are scanned for terms.
|
|
63
|
+
* @param {{now?: Date|number, freshnessDays?: number}} [options]
|
|
64
|
+
* @returns {{stale: boolean, reasons: string[]}}
|
|
65
|
+
*/
|
|
66
|
+
export function freshnessSignals(entry, { now = Date.now(), freshnessDays = DEFAULT_FRESHNESS_DAYS } = {}) {
|
|
67
|
+
const reasons = []
|
|
68
|
+
if (!entry || typeof entry !== 'object') return { stale: false, reasons }
|
|
69
|
+
const nowMs = baseTime(now)
|
|
70
|
+
const todayStart = new Date(nowMs)
|
|
71
|
+
todayStart.setHours(0, 0, 0, 0)
|
|
72
|
+
const todayMs = todayStart.getTime()
|
|
73
|
+
|
|
74
|
+
// (a) A one-off date strictly before local today. Today itself still counts as
|
|
75
|
+
// current; only tomorrow and later are future.
|
|
76
|
+
const dated = datedValue(entry.salientDate)
|
|
77
|
+
if (dated && dated.time < todayMs) reasons.push(`dated-past:${dated.text}`)
|
|
78
|
+
|
|
79
|
+
// (b) Time-sensitive wording in the title or body. Every matched term is kept so
|
|
80
|
+
// the reason list is auditable instead of a single opaque boolean.
|
|
81
|
+
const text = `${entry.title ?? ''}\n${entry.content ?? ''}`
|
|
82
|
+
for (const term of FRESHNESS_TERMS) if (text.includes(term)) reasons.push(`freshness-term:${term}`)
|
|
83
|
+
|
|
84
|
+
// (c) Age since the last edit. `updatedAt` wins over `createdAt`; missing or
|
|
85
|
+
// invalid stamps contribute nothing, and future stamps are not "old". Project
|
|
86
|
+
// facts are excluded on purpose — most coding memories would otherwise always
|
|
87
|
+
// trip this leg.
|
|
88
|
+
if (entry.owner !== 'about_project') {
|
|
89
|
+
const at = timestampMs(entry.updatedAt || entry.createdAt)
|
|
90
|
+
if (at !== null) {
|
|
91
|
+
const age = (nowMs - at) / DAY_MS
|
|
92
|
+
if (Number.isFinite(age) && age >= thresholdDays(freshnessDays)) reasons.push(`age-days:${Math.floor(age)}`)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { stale: reasons.length > 0, reasons }
|
|
97
|
+
}
|