dsh-memu-memory 1.3.11 → 1.3.13

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/lib/client.js CHANGED
@@ -8,7 +8,7 @@ window.__ModuleLoader__.load({
8
8
  const exports = module.exports
9
9
 
10
10
  const NS = 'dsh-memu-memory'
11
- const SETTINGS_PAGES = ['engine', 'connection', 'settings', 'folders', 'libraries', 'browser', 'global', 'prompts', 'stats', 'memories', 'graph', 'logs', 'lexicon', 'help']
11
+ const SETTINGS_PAGES = ['engine', 'connection', 'settings', 'folders', 'libraries', 'browser', 'global', 'prompts', 'stats', 'memories', 'graph', 'logs', 'lexicon', 'help', 'diagnostics']
12
12
  const EMPTY_SESSIONS = Object.freeze({ byId: Object.freeze({}), ids: Object.freeze([]) })
13
13
  const TAB_ID = `${NS}:memory`
14
14
  const TAB_KIND = 'dsh-memu-memory'
@@ -147,6 +147,10 @@ window.__ModuleLoader__.load({
147
147
  gsRender: '渲染',
148
148
  gsEmpty: '当前筛选下没有可显示的边',
149
149
  gsAllLibraries: '全部记忆库',
150
+ gsDomain: '按域筛选',
151
+ gsDomainHint: '输入完整域名;留空显示全部域',
152
+ gsDomainAll: '全部域(可输入)',
153
+ gsLoadPartial: '部分记忆库加载失败:',
150
154
  gsGlobalEmpty: '全部记忆库还没有关联;先在 MemU 记忆里建立关系',
151
155
  gsLocate: '图中定位',
152
156
  gsNoSelection: '未选中节点',
@@ -199,6 +203,34 @@ window.__ModuleLoader__.load({
199
203
  gsViewBranch: '查看分支',
200
204
  pageLogs: '日志',
201
205
  descLogs: '召回、写入、整理与向量的活动记录,可筛选、复制、下载',
206
+ pageDiagnostics: '诊断',
207
+ descDiagnostics: '插件内部的故障与修复记录(含 stderr、目录、修复动作),与活动日志分开存放',
208
+ diagEnvTitle: '环境自检',
209
+ diagEnvDesc: '启动时与打开本页时各检查一次:数据目录、遗留锁、引擎、向量档案、运行时、模型文件',
210
+ diagEventsTitle: '诊断记录',
211
+ diagEventsDesc: '只放插件自己出错的信息,不进 WebUI 常规日志;同一条重复出现只累加次数',
212
+ diagRefresh: '重新检查',
213
+ diagRepair: '修复',
214
+ diagRepairAll: '并做安全修复',
215
+ diagCopyAll: '复制全部',
216
+ diagClear: '清空诊断',
217
+ diagSearch: '搜索 code / message',
218
+ diagAllLevels: '全部等级',
219
+ diagLevelError: '错误',
220
+ diagLevelWarn: '告警',
221
+ diagLevelInfo: '信息',
222
+ diagEmpty: '没有诊断记录。',
223
+ diagNoCheck: '还没有自检结果,点「重新检查」。',
224
+ diagCheckRunning: '检查中…',
225
+ diagRepairDone: '修复已完成,已重新检查。',
226
+ diagRepairFailedMsg: '修复失败',
227
+ diagManual: '需手动确认',
228
+ diagAction: '修复动作',
229
+ diagHint: '怎么处理',
230
+ diagAlertTitle: '插件自身有故障',
231
+ diagAlertDesc: '这些问题来自 dsh-memu-memory 内部(不是你的记忆内容),修好后不再提示',
232
+ diagAlertOpen: '去诊断',
233
+ diagAlertLater: '稍后',
202
234
  logSearch: '搜索 id / 标题 / 错误',
203
235
  logRefresh: '刷新',
204
236
  logCopyAll: '复制全部',
@@ -318,7 +350,7 @@ window.__ModuleLoader__.load({
318
350
  viewRelations: '节点图',
319
351
  close: '关闭',
320
352
  openInBrowser: '在记忆浏览中打开',
321
- globalReadOnly: '全局记忆在这里只读;需要修改请去全局记忆页。',
353
+ globalReadOnly: '全局记忆的内容由整理器书写,这里只读;归档、恢复与删除用下方按钮,与私有记忆同权。',
322
354
  confidenceLabel: '置信度',
323
355
  tagsLabel: '标签',
324
356
  memoryMissing: '这条记忆已经不在了。',
@@ -1096,6 +1128,10 @@ window.__ModuleLoader__.load({
1096
1128
  gsRender: 'Render',
1097
1129
  gsEmpty: 'No edges match the current filter',
1098
1130
  gsAllLibraries: 'All libraries',
1131
+ gsDomain: 'Filter by domain',
1132
+ gsDomainHint: 'Enter an exact domain; leave blank for all domains',
1133
+ gsDomainAll: 'All domains (type to filter)',
1134
+ gsLoadPartial: 'Some libraries could not be loaded: ',
1099
1135
  gsGlobalEmpty: 'No links across all libraries yet; create relations in MemU memory first',
1100
1136
  gsLocate: 'Locate',
1101
1137
  gsNoSelection: 'No node selected',
@@ -1148,6 +1184,34 @@ window.__ModuleLoader__.load({
1148
1184
  gsViewBranch: 'View branch',
1149
1185
  pageLogs: 'Logs',
1150
1186
  descLogs: 'Recall, writes, consolidation and vector activity; filter, copy or download',
1187
+ pageDiagnostics: 'Diagnostics',
1188
+ descDiagnostics: 'Internal faults and repairs (stderr, paths, repair actions), kept apart from the activity log',
1189
+ diagEnvTitle: 'Environment check',
1190
+ diagEnvDesc: 'Runs at startup and when this page opens: data dir, stale locks, engine, vector profile, runtime, model files',
1191
+ diagEventsTitle: 'Diagnostic records',
1192
+ diagEventsDesc: 'Plugin-internal errors only, never in the regular WebUI log; repeats bump a counter instead of adding rows',
1193
+ diagRefresh: 'Re-check',
1194
+ diagRepair: 'Repair',
1195
+ diagRepairAll: 'Run safe repairs',
1196
+ diagCopyAll: 'Copy all',
1197
+ diagClear: 'Clear diagnostics',
1198
+ diagSearch: 'Search code / message',
1199
+ diagAllLevels: 'All levels',
1200
+ diagLevelError: 'Error',
1201
+ diagLevelWarn: 'Warning',
1202
+ diagLevelInfo: 'Info',
1203
+ diagEmpty: 'No diagnostic records.',
1204
+ diagNoCheck: 'No check yet — press "Re-check".',
1205
+ diagCheckRunning: 'Checking…',
1206
+ diagRepairDone: 'Repair finished, re-checked.',
1207
+ diagRepairFailedMsg: 'Repair failed',
1208
+ diagManual: 'Needs confirmation',
1209
+ diagAction: 'Repair action',
1210
+ diagHint: 'What to do',
1211
+ diagAlertTitle: 'The plugin itself has a fault',
1212
+ diagAlertDesc: 'These come from inside dsh-memu-memory (not from your memories); the prompt stops once fixed',
1213
+ diagAlertOpen: 'Open diagnostics',
1214
+ diagAlertLater: 'Later',
1151
1215
  logSearch: 'Search id / title / error',
1152
1216
  logRefresh: 'Refresh',
1153
1217
  logCopyAll: 'Copy all',
@@ -1267,7 +1331,7 @@ window.__ModuleLoader__.load({
1267
1331
  viewRelations: 'Node graph',
1268
1332
  close: 'Close',
1269
1333
  openInBrowser: 'Open in the browser',
1270
- globalReadOnly: 'Global memories are read-only here; edit them on the global page.',
1334
+ globalReadOnly: 'Global memory content is curator-written and read-only here; archive, restore and delete below carry the same rights as private memories.',
1271
1335
  confidenceLabel: 'Confidence',
1272
1336
  tagsLabel: 'Tags',
1273
1337
  memoryMissing: 'This memory no longer exists.',
@@ -2176,7 +2240,9 @@ window.__ModuleLoader__.load({
2176
2240
  .dshm-gs-seg button[aria-pressed=true]{background:var(--gs-accent);color:var(--gs-on-accent);font-weight:600}
2177
2241
  .dshm-gs-field{height:29px;padding:0 9px;border:1px solid var(--gs-border);background:var(--gs-panel-2);border-radius:var(--gs-radius-sm);outline:none;font-size:11.5px;max-width:100%}
2178
2242
  .dshm-gs-field:focus{border-color:var(--gs-accent);box-shadow:0 0 0 3px var(--gs-accent-soft)}
2179
- .dshm-gs-search{position:relative;flex:1 1 160px;max-width:260px;min-width:90px}
2243
+ .dshm-gs-domain{flex:0 1 160px;min-width:100px}
2244
+ .dshm-gs-domain .dshm-gs-field{width:100%}
2245
+ .dshm-gs-search{position:relative;flex:1 1 140px;max-width:220px;min-width:90px}
2180
2246
  /* standalone.css 会给外壳输入框统一 padding/height;工作台的紧凑控件必须用更高
2181
2247
  特异性拉回自己的尺寸,否则搜索图标会压住文字、顶栏控件高度也不齐。 */
2182
2248
  .dshm-gs-search .dshm-gs-field{width:100%;padding-left:28px!important}
@@ -2324,14 +2390,15 @@ html[data-standalone] .dshm-root .dshm-gs .dshm-gs-forcepop input[type=range]{he
2324
2390
  .dshm-gs-brand-txt small,.dshm-gs-themechip{display:none}
2325
2391
  }
2326
2392
  @media (max-width:760px){
2327
- .dshm-gs,.dshm-gs.is-collapsed,.dshm-gs.is-manage{grid-template-columns:minmax(0,1fr);grid-template-rows:50px 38px minmax(0,1fr) 28px}
2328
- .dshm-gs-topbar{grid-column:1;grid-row:1}
2393
+ .dshm-gs,.dshm-gs.is-collapsed,.dshm-gs.is-manage{grid-template-columns:minmax(0,1fr);grid-template-rows:112px 38px minmax(0,1fr) 28px}
2394
+ .dshm-gs-topbar{grid-column:1;grid-row:1;flex-wrap:wrap;align-content:center;gap:6px}
2395
+ .dshm-gs-domain{order:20;flex:1 0 100%;min-width:0}
2329
2396
  .dshm-gs-rail{grid-column:1;grid-row:2;flex-direction:row;justify-content:flex-start;padding:4px 8px;gap:4px;overflow-x:auto;border-right:0;border-bottom:1px solid var(--gs-border)}
2330
2397
  .dshm-gs-rail-sep{width:1px;height:20px;margin:0 2px}
2331
2398
  .dshm-gs-rail-grow{display:none}
2332
2399
  .dshm-gs-stage,.dshm-gs-manager{grid-column:1;grid-row:3}
2333
2400
  .dshm-gs-status{grid-column:1;grid-row:4}
2334
- .dshm-gs-inspector{top:88px;width:min(300px,92vw)}
2401
+ .dshm-gs-inspector{top:150px;width:min(300px,92vw)}
2335
2402
  .dshm-gs-search,.dshm-gs-divider,.dshm-gs-popwrap{display:none}
2336
2403
  .dshm-gs-mgr-thead,.dshm-gs-mgr-row{grid-template-columns:20px 58px minmax(90px,1fr) 70px 64px 130px;min-width:500px}
2337
2404
  .dshm-gs-mgr-thead span:nth-child(6),.dshm-gs-mgr-row>span:nth-child(6),.dshm-gs-mgr-thead span:nth-child(7),.dshm-gs-mgr-row>span:nth-child(7),.dshm-gs-mgr-thead span:nth-child(8),.dshm-gs-mgr-row>span:nth-child(8){display:none}
@@ -3367,6 +3434,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3367
3434
  const [error, setError] = React.useState('')
3368
3435
  const [view, setView] = React.useState('graph')
3369
3436
  const [query, setQuery] = React.useState('')
3437
+ const [domain, setDomain] = React.useState('')
3438
+ const graphDomain = domain.normalize('NFKC').trim().toLowerCase()
3370
3439
  const [source, setSource] = React.useState('all')
3371
3440
  const [rulesOff, setRulesOff] = React.useState(() => new Set())
3372
3441
  const [ruleOpen, setRuleOpen] = React.useState(false)
@@ -3417,34 +3486,56 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3417
3486
  let alive = true
3418
3487
  const load = async () => {
3419
3488
  try {
3489
+ // Each response stays bounded; browsing follows all pages, including trailing entities.
3490
+ const readLibrary = async libraryId => {
3491
+ const nodes = new Map(), edges = new Map(), domains = new Set()
3492
+ let offset = 0
3493
+ while (alive) {
3494
+ const value = await call('getGraph', { libraryId, domain: graphDomain || undefined,
3495
+ focusId: showGlobal ? null : (focus || null), depth: 2, limit: 200,
3496
+ ...(!focus || showGlobal ? { offset } : {}) })
3497
+ for (const node of value?.nodes || []) nodes.set(node.id, node)
3498
+ for (const edge of value?.edges || []) edges.set(JSON.stringify([edge.from, edge.to, edge.kind]), edge)
3499
+ for (const valueDomain of value?.domains || []) domains.add(valueDomain)
3500
+ if (!Number.isInteger(value?.nextOffset)) break
3501
+ if (value.nextOffset <= offset) throw new Error('Invalid graph page offset')
3502
+ offset = value.nextOffset
3503
+ }
3504
+ return { nodes: [...nodes.values()], edges: [...edges.values()], domains: [...domains] }
3505
+ }
3420
3506
  if (showGlobal && libraries.length) {
3421
- // 「全部记忆库」= 合并每个私有库的图,和 MemU 记忆页的「全部记忆库」口径一致。
3422
- const results = await Promise.all(libraries.map(lib =>
3423
- call('getGraph', { libraryId: lib.id, focusId: null, depth: 2, limit: 200 }).catch(() => null)))
3424
- const nodes = new Map(), edges = new Map()
3507
+ const results = await Promise.allSettled(libraries.map(lib => readLibrary(lib.id)))
3508
+ const nodes = new Map(), edges = new Map(), domains = new Set(), failures = []
3425
3509
  for (let i = 0; i < results.length; i++) {
3426
- const value = results[i], lib = libraries[i]
3427
- // 合并视图下节点要记住来源库:管理视图的删除必须有 libraryId。
3428
- for (const node of value?.nodes || []) if (!nodes.has(node.id)) nodes.set(node.id, { ...node, libraryId: lib.id })
3429
- for (const edge of value?.edges || []) edges.set(`${edge.from}|${edge.to}|${edge.kind || ''}`, edge)
3510
+ const result = results[i], lib = libraries[i]
3511
+ if (result.status === 'rejected') { failures.push(lib.name || lib.id); continue }
3512
+ const key = id => JSON.stringify([lib.id, id])
3513
+ for (const node of result.value.nodes) nodes.set(key(node.id), {
3514
+ ...node, id: key(node.id), rawId: node.id, libraryId: lib.id,
3515
+ })
3516
+ for (const edge of result.value.edges) {
3517
+ const from = key(edge.from), to = key(edge.to)
3518
+ edges.set(JSON.stringify([from, to, edge.kind]), { ...edge, from, to, libraryId: lib.id })
3519
+ }
3520
+ for (const valueDomain of result.value.domains) domains.add(valueDomain)
3430
3521
  }
3431
3522
  if (!alive) return
3432
- setGraph({ nodes: [...nodes.values()], edges: [...edges.values()] })
3523
+ setGraph({ nodes: [...nodes.values()], edges: [...edges.values()], domains: [...domains].sort() })
3524
+ setError(failures.length ? t('gsLoadPartial') + failures.join(', ') : '')
3433
3525
  } else {
3434
- const payload = showGlobal
3435
- ? { scope: 'global', focusId: focus || null, depth: 2, limit: 200 }
3436
- : { libraryId: graphLibrary, focusId: focus || null, depth: 2, limit: 200 }
3437
- const value = await call('getGraph', payload)
3526
+ const value = showGlobal
3527
+ ? await call('getGraph', { scope: 'global', focusId: focus || null, depth: 2, limit: 200 })
3528
+ : await readLibrary(graphLibrary)
3438
3529
  if (!alive) return
3439
3530
  setGraph(value && Array.isArray(value.nodes)
3440
- ? { nodes: value.nodes, edges: value.edges || [] } : { nodes: [], edges: [] })
3531
+ ? { nodes: value.nodes, edges: value.edges || [], domains: value.domains || [] } : { nodes: [], edges: [] })
3532
+ setError('')
3441
3533
  }
3442
- setError('')
3443
- } catch (failure) { if (alive) setError(String(failure?.message || failure)) }
3534
+ } catch (failure) { if (alive) { setGraph({ nodes: [], edges: [] }); setError(String(failure?.message || failure)) } }
3444
3535
  }
3445
3536
  void load()
3446
3537
  return () => { alive = false }
3447
- }, [call, graphLibrary, showGlobal, focus, beat, reloadKey, libraries.length, libraries.map(lib => lib.id).join(',')])
3538
+ }, [call, graphLibrary, showGlobal, focus, beat, reloadKey, libraries.length, libraries.map(lib => lib.id).join(','), graphDomain])
3448
3539
  React.useEffect(() => {
3449
3540
  if (showGlobal) { setEntities([]); return undefined }
3450
3541
  let alive = true
@@ -3563,7 +3654,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3563
3654
  const name = draft.name.trim()
3564
3655
  const entity = await call('createEntity', { libraryId: addTargetLib, name, kind: draft.kind })
3565
3656
  notifyMemoryWrite('relation', addTargetLib)
3566
- setMgrSelected(entity?.id || '')
3657
+ setMgrSelected(entity?.id ? (showGlobal ? JSON.stringify([addTargetLib, entity.id]) : entity.id) : '')
3567
3658
  setDraft(value => ({ ...value, name: '' }))
3568
3659
  notify(t('gsNodeCreated').replace('{name}', name))
3569
3660
  } else {
@@ -3575,7 +3666,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3575
3666
  return
3576
3667
  }
3577
3668
  notifyMemoryWrite('memory', addTargetLib)
3578
- setMgrSelected(created?.id || '')
3669
+ setMgrSelected(created?.id ? (showGlobal ? JSON.stringify([addTargetLib, created.id]) : created.id) : '')
3579
3670
  setDraft(value => ({ ...value, title: '', content: '' }))
3580
3671
  notify(t('memorySaved'))
3581
3672
  }
@@ -3591,12 +3682,12 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3591
3682
  try {
3592
3683
  if (node.kind === 'memory') {
3593
3684
  // 永久删除只接受已归档条目:先归档再删;两段确认已由按钮承担。
3594
- await call('archiveMemory', { libraryId, id: node.id })
3595
- await call('deleteMemory', { libraryId, id: node.id, confirmed: true })
3685
+ await call('archiveMemory', { libraryId, id: node.rawId || node.id })
3686
+ await call('deleteMemory', { libraryId, id: node.rawId || node.id, confirmed: true })
3596
3687
  notifyMemoryWrite('memory', libraryId)
3597
3688
  notify(t('memoryDeleted'))
3598
3689
  } else {
3599
- await call('deleteEntity', { libraryId, entityId: node.id, force: mgrDeleteRefused === node.id })
3690
+ await call('deleteEntity', { libraryId, entityId: node.rawId || node.id, force: mgrDeleteRefused === node.id })
3600
3691
  notifyMemoryWrite('relation', libraryId)
3601
3692
  notify(t('gsNodeDeleted'))
3602
3693
  }
@@ -3619,14 +3710,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3619
3710
  setEditBusy(true)
3620
3711
  try {
3621
3712
  if (node.kind === 'memory') {
3622
- const loaded = await call('getMemory', { libraryId, id: node.id })
3713
+ const loaded = await call('getMemory', { libraryId, id: node.rawId || node.id })
3623
3714
  const entry = loaded?.entry || {}
3624
- setEditDraft({ id: node.id, kind: 'memory', libraryId,
3715
+ setEditDraft({ id: node.rawId || node.id, kind: 'memory', libraryId,
3625
3716
  title: entry.title || '', content: entry.content || '', layer: entry.layer || 'long_term' })
3626
3717
  } else {
3627
3718
  const list = await call('listEntities', { libraryId })
3628
- const found = (list?.items || []).find(item => item.id === node.id) || {}
3629
- setEditDraft({ id: node.id, kind: 'entity', libraryId,
3719
+ const found = (list?.items || []).find(item => item.id === (node.rawId || node.id)) || {}
3720
+ setEditDraft({ id: node.rawId || node.id, kind: 'entity', libraryId,
3630
3721
  name: found.name || node.title || '', aliases: (found.aliases || []).join(', ') })
3631
3722
  }
3632
3723
  setAddOpen(false)
@@ -3667,10 +3758,25 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3667
3758
  h('select', {
3668
3759
  className: 'dshm-gs-field', value: graphLibrary,
3669
3760
  title: showGlobal ? t('gsAllLibraries') : (libraries.find(lib => lib.id === graphLibrary)?.scopeKey || t('currentLibrary')),
3670
- 'aria-label': t('currentLibrary'), onChange: event => setGraphLib(event.target.value),
3761
+ 'aria-label': t('currentLibrary'), onChange: event => {
3762
+ setGraphLib(event.target.value); setFocus(''); setMgrSelected(''); setGraph({ nodes: [], edges: [] })
3763
+ },
3671
3764
  },
3672
3765
  h('option', { value: GLOBAL_GRAPH_ID }, t('gsAllLibraries')),
3673
3766
  libraries.map(lib => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries)))),
3767
+ h('label', { className: 'dshm-gs-domain', title: t('gsDomainHint') },
3768
+ h('input', { className: 'dshm-gs-field', type: 'search', value: domain, list: 'dshm-graph-domains',
3769
+ placeholder: t('gsDomainAll'), 'aria-label': t('gsDomain'),
3770
+ onChange: event => {
3771
+ const next = event.target.value
3772
+ setDomain(next)
3773
+ if (next.normalize('NFKC').trim().toLowerCase() !== graphDomain) {
3774
+ setFocus(''); setMgrSelected(''); setGraph({ nodes: [], edges: [] })
3775
+ }
3776
+ } }),
3777
+ h('datalist', { id: 'dshm-graph-domains' },
3778
+ [...new Set(['rp', 'coding', 'general', 'mixed', ...(graph.domains || [])])].sort()
3779
+ .map(value => h('option', { key: value, value })))),
3674
3780
  h('label', { className: 'dshm-gs-search' },
3675
3781
  h('span', { className: 'dshm-gs-search-icon', 'aria-hidden': 'true' }, '⌕'),
3676
3782
  h('input', { ref: searchRef, className: 'dshm-gs-field', type: 'search', value: query,
@@ -3773,7 +3879,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3773
3879
  selected.layer ? h('span', { className: 'dshm-gs-tag neutral' }, String(selected.layer)) : null,
3774
3880
  selected.status === 'provisional' ? h('span', { className: 'dshm-gs-tag warn' }, t('gsPending')) : null))),
3775
3881
  h('dl', { className: 'dshm-gs-kv' },
3776
- h('dt', null, 'ID'), h('dd', null, String(selected.id)),
3882
+ h('dt', null, 'ID'), h('dd', null, String(selected.rawId || selected.id)),
3777
3883
  h('dt', null, t('gsDegree')), h('dd', null, String(degree.get(selected.id) || 0)),
3778
3884
  h('dt', null, t('gsStrength')), h('dd', null, Number(selected.strength || 0).toFixed(2)))),
3779
3885
  h('div', { className: 'dshm-gs-sec' },
@@ -3955,7 +4061,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3955
4061
  onClick: () => { setMgrSelected(node.id); setEditOpen(false); setEditDraft(null) },
3956
4062
  },
3957
4063
  h('span', { className: 'dshm-gs-mgr-dot' }, h('i', { className: `dshm-gs-swatch dshm-gs-c-${gsKind(node)}` })),
3958
- h('span', { className: 'dshm-gs-mgr-id' }, String(node.id).slice(0, 8)),
4064
+ h('span', { className: 'dshm-gs-mgr-id' }, String(node.rawId || node.id).slice(0, 8)),
3959
4065
  h('span', { className: 'dshm-gs-mgr-title' }, String(node.title || node.id)),
3960
4066
  h('span', null, String(node.kind || 'memory')),
3961
4067
  // 记忆条目写入即生效,没有「待确认」概念;只有实体才会是 provisional。
@@ -4436,7 +4542,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4436
4542
  const [query, setQuery] = React.useState('')
4437
4543
  const [error, setError] = React.useState('')
4438
4544
  const [version, setVersion] = React.useState(0)
4439
- // 组分类:私有 / 全局两块,默认私有、私有靠前。全局条目只读,所以多选只在私有块。
4545
+ // 组分类:私有 / 全局两块,默认私有、私有靠前。全局条目内容只读(curator 写),
4546
+ // 但生命周期(归档/恢复/删除)与私有同权,多选两块都生效。
4440
4547
  const [scope, setScope] = React.useState('private')
4441
4548
  const [multi, setMulti] = React.useState(false)
4442
4549
  const [selectedIds, setSelectedIds] = React.useState(() => new Set())
@@ -4567,6 +4674,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4567
4674
  setDetail({ ...current, file, draft: draftOf(file), busy: false, error: '' })
4568
4675
  reload()
4569
4676
  }
4677
+ // 全局条目没有 getMemory 路由:刷新重拉 listGlobal(管理面不过滤状态,
4678
+ // 归档后仍读得到),内容保持只读。
4679
+ const refreshGlobalDetail = async (current) => {
4680
+ const res = await call('listGlobal', {})
4681
+ const file = (res.files || []).find(entry => entry.id === current.item.id) || null
4682
+ setDetail({ ...current, file, draft: null, busy: false, error: file ? '' : t('memoryMissing'), readonly: true })
4683
+ reload()
4684
+ }
4570
4685
  const saveDetail = async () => {
4571
4686
  const current = detail
4572
4687
  if (!current?.file || current.readonly || !current.draft) return
@@ -4593,11 +4708,17 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4593
4708
  }
4594
4709
  const setDetailStatus = async (status) => {
4595
4710
  const current = detail
4596
- if (!current?.file || current.readonly) return
4711
+ if (!current?.file) return
4597
4712
  setDetail({ ...current, busy: true, error: '' })
4598
4713
  try {
4599
- await call('updateMemory', { libraryId: current.item.libraryId, id: current.item.id, patch: { status } })
4600
- await refreshDetail(current)
4714
+ if (current.item.libraryId) {
4715
+ await call('updateMemory', { libraryId: current.item.libraryId, id: current.item.id, patch: { status } })
4716
+ await refreshDetail(current)
4717
+ } else {
4718
+ if (status === 'archived') await call('archiveMemory', { scope: 'global', id: current.item.id })
4719
+ else await call('updateMemory', { scope: 'global', id: current.item.id, patch: { status: 'active' } })
4720
+ await refreshGlobalDetail(current)
4721
+ }
4601
4722
  // 归档/恢复/保存是三个不同结果,同一条通知通道但各说各话。
4602
4723
  notice(status === 'archived' ? t('memoryArchived') : status === 'active' ? t('memoryRestored') : t('memorySaved'))
4603
4724
  } catch (failure) {
@@ -4606,13 +4727,16 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4606
4727
  }
4607
4728
  const deleteDetail = async () => {
4608
4729
  const current = detail
4609
- if (!current?.file || current.readonly || current.file.status !== 'archived') return
4730
+ if (!current?.file || current.file.status !== 'archived') return
4610
4731
  setDetail({ ...current, busy: true, error: '' })
4611
4732
  try {
4612
- await call('deleteMemory', { libraryId: current.item.libraryId, id: current.item.id, confirmed: true })
4733
+ await call('deleteMemory', {
4734
+ ...(current.item.libraryId ? { libraryId: current.item.libraryId } : { scope: 'global' }),
4735
+ id: current.item.id, confirmed: true,
4736
+ })
4613
4737
  setDetail(null)
4614
4738
  setDeleteArmed(false)
4615
- notifyMemoryWrite('memory', current.item.libraryId)
4739
+ notifyMemoryWrite('memory', current.item.libraryId || null)
4616
4740
  notice(t('memoryDeleted'))
4617
4741
  reload()
4618
4742
  } catch (failure) {
@@ -4639,9 +4763,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4639
4763
  }
4640
4764
  }
4641
4765
 
4642
- // —— 多选批量操作(只对私有块生效;全局只读)——
4643
- // 逐条走既有 RPC(updateMemory patch.status / deleteMemory),循环里失败的条目
4644
- // 记下来一次性报错:部分成功不能说成全部成功,也不该让一条失败吞掉其余的成果。
4766
+ // —— 多选批量操作(私有与全局同权;全局走显式 scope:'global' 管理面路由)——
4767
+ // 逐条走既有 RPC(updateMemory patch.status / archiveMemory / deleteMemory),
4768
+ // 循环里失败的条目记下来一次性报错:部分成功不能说成全部成功,也不该让一条失败吞掉其余的成果。
4645
4769
  const exitMulti = () => { setMulti(false); setSelectedIds(new Set()); setDeleteArmedMulti(false) }
4646
4770
  const bulkApply = async (action) => {
4647
4771
  const targets = selectedRows(visible).filter(item => action === 'archive'
@@ -4653,15 +4777,18 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4653
4777
  const failures = []
4654
4778
  for (const item of targets) {
4655
4779
  try {
4656
- if (action === 'delete') await call('deleteMemory', { libraryId: item.libraryId, id: item.id, confirmed: true })
4657
- else await call('updateMemory', { libraryId: item.libraryId, id: item.id, patch: { status: action === 'archive' ? 'archived' : 'active' } })
4780
+ const global = !item.libraryId
4781
+ const target = global ? { scope: 'global' } : { libraryId: item.libraryId }
4782
+ if (action === 'delete') await call('deleteMemory', { ...target, id: item.id, confirmed: true })
4783
+ else if (global && action === 'archive') await call('archiveMemory', { ...target, id: item.id })
4784
+ else await call('updateMemory', { ...target, id: item.id, patch: { status: action === 'archive' ? 'archived' : 'active' } })
4658
4785
  done += 1
4659
4786
  } catch (failure) { failures.push(`${item.title || item.id}: ${String(failure?.message || failure)}`) }
4660
4787
  }
4661
4788
  setWallBusy(false)
4662
4789
  setDeleteArmedMulti(false)
4663
4790
  setSelectedIds(new Set())
4664
- if (done > 0) { notifyMemoryWrite('memory', libraryId || null); reload() }
4791
+ if (done > 0) { notifyMemoryWrite('memory', scope === 'global' ? null : (libraryId || null)); reload() }
4665
4792
  // 部分成功不说成全部成功:有失败只走 error(带 done/total 前缀),全成功才报 notice。
4666
4793
  if (failures.length > 0) setError(`${done}/${targets.length} · ` + failures.slice(0, 3).join(';'))
4667
4794
  else if (done > 0) notice(t('bulkDone').replace('{n}', String(done)))
@@ -4721,8 +4848,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4721
4848
  affectText ? h('div', { className: 'dshm-drawer-note' }, affectText) : null)
4722
4849
  : detail && detail.file && detail.readonly
4723
4850
  ? (() => {
4724
- // 全局条目只读(spec §6.7 UI):详情抽屉里只读展示 links / absorbedFrom,
4725
- // 不提供编辑、不提供手动全局关联。links 移除按钮在全局页(F1 接入)。
4851
+ // 全局条目内容只读(spec §6.7 UI):详情抽屉里只读展示 links / absorbedFrom,
4852
+ // 不提供编辑、不提供手动全局关联;生命周期按钮(归档/恢复/删除)与私有同权。
4853
+ // links 移除按钮在全局页(F1 接入)。
4726
4854
  const absorbed = Array.isArray(detail.file.absorbedFrom) ? detail.file.absorbedFrom : []
4727
4855
  const links = Array.isArray(detail.file.links) ? detail.file.links : []
4728
4856
  return h(React.Fragment, null,
@@ -4793,14 +4921,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4793
4921
  !detail.readonly
4794
4922
  ? h(Button, { primary: true, disabled: detail.busy, onClick: () => { void saveDetail() } }, t('save'))
4795
4923
  : null,
4796
- !detail.readonly && detail.file
4924
+ detail.file && !(detail.readonly && detail.file.status === 'pending_review')
4797
4925
  ? h(Button, {
4798
4926
  style: S.ghost,
4799
4927
  disabled: detail.busy,
4800
4928
  onClick: () => { void setDetailStatus(detail.file.status === 'archived' ? 'active' : 'archived') },
4801
4929
  }, detail.file.status === 'archived' ? t('restore') : t('archive'))
4802
4930
  : null,
4803
- !detail.readonly && detail.file?.status === 'archived'
4931
+ detail.file?.status === 'archived'
4804
4932
  ? deleteArmed
4805
4933
  ? h(React.Fragment, null,
4806
4934
  h(Button, {
@@ -4879,15 +5007,13 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4879
5007
  h('option', { value: '', disabled: multiBlocked }, t('allLibraries')),
4880
5008
  libraries.map((lib) => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries))))
4881
5009
  : null
4882
- const hasOptionControls = scope === 'private' || multiBlocked || data?.total > items.length
4883
- const multiToggle = scope === 'private'
4884
- ? h(Button, {
4885
- 'aria-pressed': multi,
4886
- style: multi ? { ...S.ghost, color: V.accent, borderColor: V.accent } : S.ghost,
4887
- onClick: () => { if (multi) exitMulti(); else setMulti(true) },
4888
- }, multi ? t('wallMultiExit') : t('multiSelect'))
4889
- : null
4890
- const multiActions = multi && scope === 'private' ? (() => {
5010
+ const hasOptionControls = true
5011
+ const multiToggle = h(Button, {
5012
+ 'aria-pressed': multi,
5013
+ style: multi ? { ...S.ghost, color: V.accent, borderColor: V.accent } : S.ghost,
5014
+ onClick: () => { if (multi) exitMulti(); else setMulti(true) },
5015
+ }, multi ? t('wallMultiExit') : t('multiSelect'))
5016
+ const multiActions = multi ? (() => {
4891
5017
  const chosen = selectedRows(visible)
4892
5018
  const archiveN = chosen.filter(item => ['active', 'inactive'].includes(poolOf(item))).length
4893
5019
  const restoreN = chosen.filter(item => item.status === 'archived').length
@@ -4925,10 +5051,10 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4925
5051
  'aria-label': multi ? t('multiSelect') : undefined,
4926
5052
  style: { marginTop: 8, marginBottom: 0 },
4927
5053
  },
4928
- // 多选只对私有块:全局条目只读,批量操作没有意义。
5054
+ // 多选对私有与全局同权:全局走 scope:'global' 管理面路由。
4929
5055
  multiToggle,
4930
5056
  multiActions,
4931
- multiBlocked ? h('span', { style: S.muted, role: 'status' }, t('wallAllBlocked')) : null,
5057
+ multiBlocked && scope === 'private' ? h('span', { style: S.muted, role: 'status' }, t('wallAllBlocked')) : null,
4932
5058
  data?.total > items.length ? h('span', { style: S.muted }, t('wallLimit') + ` (${items.length}/${data.total})`) : null) : null,
4933
5059
  wallTabGroup(poolItems, pool, setPool, { label: t('wallFilterStatus'), marginTop: 12 }),
4934
5060
  wallTabGroup(layerItems, layer, setLayer, { label: t('wallFilterLayer'), marginTop: 10 }),
@@ -4938,14 +5064,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4938
5064
  style: multi && selectedIds.has(keyOf(item)) ? { outline: '2px solid ' + V.accent, outlineOffset: -2 } : undefined,
4939
5065
  onClick: () => {
4940
5066
  // 多选模式下点卡片 = 勾选/取消勾选;正常模式打开抽屉。
4941
- if (multi && scope === 'private') {
5067
+ if (multi) {
4942
5068
  setSelectedIds(prev => { const next = new Set(prev); if (next.has(keyOf(item))) next.delete(keyOf(item)); else next.add(keyOf(item)); return next })
4943
5069
  return
4944
5070
  }
4945
5071
  void openDetail(item)
4946
5072
  },
4947
5073
  },
4948
- multi && scope === 'private' ? h(Tag, { tone: selectedIds.has(keyOf(item)) ? 'info' : null }, selectedIds.has(keyOf(item)) ? '✓' : '□') : null,
5074
+ multi ? h(Tag, { tone: selectedIds.has(keyOf(item)) ? 'info' : null }, selectedIds.has(keyOf(item)) ? '✓' : '□') : null,
4949
5075
  h(WallCover, { item }),
4950
5076
  h('div', { className: 'dshm-wall-meta' }, h('span', null, item.libraryId ? item.libraryName : t('globalMemory')), h('span', null, enumText(t, LAYER_LABELS, item.layer))),
4951
5077
  h('strong', null, item.title || item.id),
@@ -5498,6 +5624,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5498
5624
  logs: 11,
5499
5625
  lexicon: 12,
5500
5626
  help: 13,
5627
+ // 诊断页固定排最后(14):它是排查入口,不该挤在功能页中间;三处清单
5628
+ // (SETTINGS_PAGES / pageDefs / PAGE)必须同序,否则导航会整片错位。
5629
+ diagnostics: 14,
5501
5630
  }
5502
5631
  const call = useRpc(ctx)
5503
5632
  const sessionId = useCurrentSession(ctx)
@@ -5559,6 +5688,63 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5559
5688
  } catch (error) { setLogNotice(String(error?.message || error)) } finally { setLogBusy(false) }
5560
5689
  }, [call, logKind, logQuery])
5561
5690
  React.useEffect(() => { void loadLogs() }, [loadLogs])
5691
+ // ------------------------------------------------ 诊断(2026-11-21)
5692
+ // 与活动日志完全分开的一套状态:活动日志讲"记忆发生了什么",诊断讲"插件自己哪里
5693
+ // 坏了"。故障取证需要 stderr 尾巴、目录和修复动作,塞进日志只会把日志淹掉。
5694
+ const [diagRows, setDiagRows] = React.useState([])
5695
+ const [diagStats, setDiagStats] = React.useState(null)
5696
+ const [diagEnv, setDiagEnv] = React.useState(null)
5697
+ const [diagBusy, setDiagBusy] = React.useState(false)
5698
+ const [diagNotice, setDiagNotice] = React.useState('')
5699
+ const [diagLevel, setDiagLevel] = React.useState('')
5700
+ const [diagQueryInput, setDiagQueryInput] = React.useState('')
5701
+ const [diagQuery, setDiagQuery] = React.useState('')
5702
+ // 启动提醒:只在主页弹一次;确认后写进服务端的 acknowledged.json,之后的"新"按
5703
+ // 累积次数判断,所以同一问题不会每次开机都弹。
5704
+ const [startupAlerts, setStartupAlerts] = React.useState([])
5705
+ const loadDiagnostics = React.useCallback(async (withCheck = false) => {
5706
+ setDiagBusy(true)
5707
+ try {
5708
+ const data = await call('getDiagnostics', { limit: 300, level: diagLevel || undefined, q: diagQuery || undefined })
5709
+ setDiagRows(Array.isArray(data?.items) ? data.items : [])
5710
+ setDiagStats(data?.stats || null)
5711
+ setDiagNotice('')
5712
+ } catch (error) { setDiagNotice(String(error?.message || error)) } finally { setDiagBusy(false) }
5713
+ // 环境自检单独一次调用:它会碰磁盘和引擎状态,慢的时候不该拖住诊断记录列表。
5714
+ if (withCheck || !diagEnv) {
5715
+ try { setDiagEnv(await call('runEnvironmentCheck', {})) } catch (error) { setDiagNotice(String(error?.message || error)) }
5716
+ }
5717
+ }, [call, diagLevel, diagQuery, diagEnv])
5718
+ React.useEffect(() => { void loadDiagnostics() }, [loadDiagnostics])
5719
+ const runRepair = React.useCallback(async (actions) => {
5720
+ if (!Array.isArray(actions) || !actions.length) return
5721
+ setDiagBusy(true)
5722
+ try {
5723
+ const outcome = await call('repairEnvironment', { actions, confirmed: true })
5724
+ const failed = (outcome?.results || []).filter(result => !result.ok)
5725
+ setDiagNotice(failed.length
5726
+ ? `${t('diagRepairFailedMsg')}: ${failed.map(result => `${result.action} ${result.detail}`).join('; ')}`
5727
+ : t('diagRepairDone'))
5728
+ setDiagEnv(outcome?.after || null)
5729
+ await loadDiagnostics()
5730
+ } catch (error) { setDiagNotice(String(error?.message || error)) } finally { setDiagBusy(false) }
5731
+ }, [call, loadDiagnostics, t])
5732
+ React.useEffect(() => {
5733
+ let alive = true
5734
+ void (async () => {
5735
+ try {
5736
+ const data = await call('getDiagnosticAlerts', {})
5737
+ if (alive) setStartupAlerts(Array.isArray(data?.alerts) ? data.alerts : [])
5738
+ } catch {}
5739
+ })()
5740
+ return () => { alive = false }
5741
+ }, [call])
5742
+ const dismissAlerts = async (openDiagnostics) => {
5743
+ const keys = startupAlerts.map(alert => alert.key).filter(Boolean)
5744
+ setStartupAlerts([])
5745
+ try { await call('acknowledgeDiagnostics', { keys }) } catch {}
5746
+ if (openDiagnostics) setPage(PAGE.diagnostics)
5747
+ }
5562
5748
  const settingsTimer = React.useRef(null)
5563
5749
  const saveChain = React.useRef(Promise.resolve())
5564
5750
  const [resetArmed, setResetArmed] = React.useState(false)
@@ -6353,6 +6539,34 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
6353
6539
  await loadReviews()
6354
6540
  } catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
6355
6541
  }
6542
+ // 全局生命周期(归档/恢复/永久删除):与 undo-absorb 同一管理面凭据口径
6543
+ // (embedded 带活会话 sessionId,standalone 走 capability)。归档/恢复可逆,
6544
+ // 单击即行;永久删除两段确认,服务端删除前整库备份。
6545
+ const refreshGlobalList = async () => {
6546
+ const res = await call('listGlobal', {})
6547
+ setGlobalFiles(res.files || [])
6548
+ setGlobalLoaded(true)
6549
+ }
6550
+ const setGlobalStatus = async (id, status) => {
6551
+ setBusy(true)
6552
+ try {
6553
+ if (status === 'archived') await call('archiveMemory', { scope: 'global', id, sessionId: sessionId || undefined })
6554
+ else await call('updateMemory', { scope: 'global', id, patch: { status: 'active' }, sessionId: sessionId || undefined })
6555
+ setNotice(status === 'archived' ? t('memoryArchived') : t('memoryRestored'))
6556
+ notifyMemoryWrite('memory', null)
6557
+ await refreshGlobalList()
6558
+ } catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
6559
+ }
6560
+ const deleteGlobalEntry = async (id) => {
6561
+ if (!confirmAction('global-delete:' + id)) return
6562
+ setBusy(true)
6563
+ try {
6564
+ await call('deleteMemory', { scope: 'global', id, confirmed: true, sessionId: sessionId || undefined })
6565
+ setNotice(t('memoryDeleted'))
6566
+ notifyMemoryWrite('memory', null)
6567
+ await refreshGlobalList()
6568
+ } catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
6569
+ }
6356
6570
  // 导出契约(spec §6.2):显式对象参数——libraryId 缺省取当前浏览库,但调用点可以
6357
6571
  // 传入别的 id(契约保证 payload、回退文件名、成功提示都用**传入**的 id)。
6358
6572
  const exportLibraryNow = async ({ libraryId = browseLibId, includeAttachments = false } = {}) => {
@@ -7314,15 +7528,17 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7314
7528
  // 集合记忆(spec §6.7 UI):absorbedFrom → 「集合记忆 · N 条来源」Tag +
7315
7529
  // 「撤销合并」两段确认按钮(resolveReview action:'undo-absorb')。links
7316
7530
  // 只读展示 + 「移除」(resolveReview action:'unlink'),不提供手动全局关联。
7531
+ // 生命周期与私有同权:归档/恢复单击,永久删除两段确认(仅已归档条目)。
7317
7532
  const absorbed = Array.isArray(f.absorbedFrom) ? f.absorbedFrom : []
7318
7533
  const links = Array.isArray(f.links) ? f.links : []
7319
7534
  const titleOf = (id) => (globalFiles.find((item) => item.id === id)?.title) || id
7320
7535
  return h('div', { key: f.id, style: S.item },
7321
7536
  h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8 } },
7322
7537
  h('strong', null, f.title || f.id),
7323
- h('div', { style: { display: 'flex', gap: 6, flexShrink: 0 } },
7538
+ h('div', { style: { display: 'flex', gap: 6, flexShrink: 0, flexWrap: 'wrap', justifyContent: 'flex-end' } },
7324
7539
  h(Tag, null, domainText(t, f.domain)),
7325
7540
  h(Tag, null, `conf ${f.confidence ?? '?'}`),
7541
+ f.status && f.status !== 'active' ? h(Tag, { tone: 'warn' }, enumText(t, STATUS_LABELS, f.status)) : null,
7326
7542
  links.length ? h(Tag, { tone: 'info' }, t('linkCountTag').replace('{n}', String(links.length))) : null,
7327
7543
  absorbed.length ? h(Tag, { tone: 'info' }, t('absorbSourcesTag').replace('{n}', String(absorbed.length))) : null,
7328
7544
  // 撤销合并:两段确认(点一次变为「确认此操作?」,再点才发请求)。
@@ -7334,6 +7550,19 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7334
7550
  onClick: () => { void undoAbsorb(f.id) },
7335
7551
  }, actionLabel('undo-absorb:' + f.id, t('absorbUndo')))
7336
7552
  : null,
7553
+ f.status === 'archived'
7554
+ ? h(Button, { style: S.ghost, disabled: busy, onClick: () => { void setGlobalStatus(f.id, 'active') } }, t('restore'))
7555
+ : f.status !== 'pending_review'
7556
+ ? h(Button, { style: S.ghost, disabled: busy, onClick: () => { void setGlobalStatus(f.id, 'archived') } }, t('archive'))
7557
+ : null,
7558
+ f.status === 'archived'
7559
+ ? h(Button, {
7560
+ style: { ...S.ghost, color: V.danger },
7561
+ disabled: busy,
7562
+ title: t('browseArchivedHint'),
7563
+ onClick: () => { void deleteGlobalEntry(f.id) },
7564
+ }, actionLabel('global-delete:' + f.id, t('deleteForever')))
7565
+ : null,
7337
7566
  // 查看此记忆:切到 MemU 记忆页的全局块并直接打开对应条目的抽屉。
7338
7567
  h(Button, {
7339
7568
  style: S.ghost,
@@ -7997,6 +8226,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
7997
8226
  pageDefs.push({ label: t('pageLogs'), overline: 'ACTIVITY', desc: t('descLogs'), icon: GlyphText })
7998
8227
  pageDefs.push({ label: t('pageLexicon'), overline: 'LEXICON', desc: t('descLexicon'), icon: GlyphStack })
7999
8228
  pageDefs.push({ label: t('pageHelp'), overline: 'GUIDE', desc: t('descHelp'), icon: GlyphQuestion })
8229
+ // 诊断页(2026-11-21):插件内部故障的取证与修复入口,排在帮助之后。
8230
+ pageDefs.push({ label: t('pageDiagnostics'), overline: 'DIAGNOSTICS', desc: t('descDiagnostics'), icon: GlyphGauge })
8000
8231
  // 首次安装引导(§6.5 包 E):只在还没有任何库时出现——有了库,用户已经过了
8001
8232
  // 这一步,卡片只会碍事。不落 localStorage:关不掉是刻意的,等第一个库建好
8002
8233
  // 它自然消失;以后要记关闭状态必须走 settings,不许加本地存储。
@@ -8241,11 +8472,139 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
8241
8472
  row.detail
8242
8473
  ? h('pre', { style: { ...S.muted, margin: '6px 0 0', fontSize: 11, whiteSpace: 'pre-wrap', wordBreak: 'break-all' } }, JSON.stringify(row.detail).slice(0, 600))
8243
8474
  : null)))))
8244
- const pageBlocks = [engineBlock, connectionBlock, settingsBlock, foldersBlock, librariesBlock, browserBlock, globalBlock, promptsBlock, statsBlock, memoriesBlock, graphBlock, logsBlock, lexiconBlock, helpBlock]
8475
+ // 诊断页。三块拼起来:环境自检(前提项,逐项带修复按钮)、启动提醒(主页也复用
8476
+ // 同一份数据)、诊断记录(插件内部错误,不进 WebUI 常规日志)。
8477
+ // 这里的 JSX 一律拆成独立变量再组装——嵌套 h() 写到七八层时括号没法数,之前就
8478
+ // 在这里写崩过一次语法。
8479
+ const diagLevelLabel = (level) => (level === 'error' ? t('diagLevelError')
8480
+ : level === 'warn' ? t('diagLevelWarn')
8481
+ : level === 'info' ? t('diagLevelInfo') : String(level || ''))
8482
+ const diagTone = (level) => (level === 'error' ? 'danger' : level === 'warn' ? 'warn' : undefined)
8483
+ const diagMuted = { ...S.muted, marginTop: 4, whiteSpace: 'pre-wrap', wordBreak: 'break-all' }
8484
+ const diagButtons = h('div', { style: { display: 'flex', gap: 6, flexWrap: 'wrap' } },
8485
+ h(Button, { onClick: () => { void loadDiagnostics(true) }, disabled: diagBusy }, t('diagRefresh')),
8486
+ (diagEnv?.autoRepairs || []).length > 0
8487
+ ? h(Button, {
8488
+ style: S.ghost,
8489
+ disabled: diagBusy,
8490
+ onClick: () => { void runRepair(diagEnv.autoRepairs) },
8491
+ }, t('diagRepairAll'))
8492
+ : null,
8493
+ h(Button, {
8494
+ style: S.ghost,
8495
+ onClick: async () => {
8496
+ const ok = await copyText(JSON.stringify({ environment: diagEnv, diagnostics: diagRows }, null, 2))
8497
+ setDiagNotice(ok ? t('copied') : t('copyFailed'))
8498
+ },
8499
+ }, t('diagCopyAll')),
8500
+ h(Button, {
8501
+ style: S.ghost,
8502
+ onClick: async () => {
8503
+ try {
8504
+ await call('clearDiagnostics', { confirmed: true })
8505
+ await loadDiagnostics(true)
8506
+ } catch (error) { setDiagNotice(String(error?.message || error)) }
8507
+ },
8508
+ }, t('diagClear')))
8509
+ const diagEnvRow = (entry) => h('div', { key: entry.id, style: S.item },
8510
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8, alignItems: 'center' } },
8511
+ h('div', { style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap', minWidth: 0 } },
8512
+ h(Tag, { tone: diagTone(entry.level) }, diagLevelLabel(entry.level)),
8513
+ h('span', null, entry.title),
8514
+ entry.manual && entry.repair ? h(Tag, null, t('diagManual')) : null),
8515
+ entry.repair
8516
+ ? h(Button, { style: S.ghost, disabled: diagBusy, onClick: () => { void runRepair([entry.repair]) } }, t('diagRepair'))
8517
+ : null),
8518
+ entry.detail ? h('div', { style: diagMuted }, entry.detail) : null,
8519
+ entry.repair ? h('div', { style: diagMuted }, `${t('diagAction')}: ${entry.repair}`) : null,
8520
+ entry.hint ? h('div', { style: diagMuted }, `${t('diagHint')}: ${entry.hint}`) : null)
8521
+ const diagEnvList = (diagEnv?.items || []).length
8522
+ ? h('div', { style: S.list }, (diagEnv?.items || []).map(diagEnvRow))
8523
+ : h(Empty, null, diagBusy ? t('diagCheckRunning') : t('diagNoCheck'))
8524
+ const diagEnvSection = h(Section, {
8525
+ title: t('diagEnvTitle'),
8526
+ desc: t('diagEnvDesc'),
8527
+ right: diagButtons,
8528
+ },
8529
+ diagNotice ? h('div', { style: { ...S.muted, marginBottom: 8, color: V.accent } }, diagNotice) : null,
8530
+ diagEnvList)
8531
+ const diagEventRow = (entry) => h('div', { key: entry.id, style: S.item },
8532
+ h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8, alignItems: 'center' } },
8533
+ h('div', { style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap', minWidth: 0 } },
8534
+ h(Tag, { tone: diagTone(entry.level) }, diagLevelLabel(entry.level)),
8535
+ h(Tag, null, entry.scope),
8536
+ h('span', { style: { fontFamily: 'monospace', fontSize: 12 } }, entry.code),
8537
+ Number(entry.count) > 1 ? h('span', { style: S.muted }, `x${entry.count}`) : null,
8538
+ h('span', { style: S.muted }, new Date(entry.lastAt || entry.at).toLocaleString())),
8539
+ h(Button, {
8540
+ style: S.ghost,
8541
+ onClick: async () => {
8542
+ const ok = await copyText(JSON.stringify(entry, null, 2))
8543
+ setDiagNotice(ok ? t('copied') : t('copyFailed'))
8544
+ },
8545
+ }, t('logCopyOne'))),
8546
+ h('div', { style: { marginTop: 4, whiteSpace: 'pre-wrap' } }, entry.message),
8547
+ entry.hint ? h('div', { style: diagMuted }, `${t('diagHint')}: ${entry.hint}`) : null,
8548
+ entry.repair
8549
+ ? h('div', { style: { marginTop: 6 } },
8550
+ h(Button, { style: S.ghost, disabled: diagBusy, onClick: () => { void runRepair([entry.repair]) } }, `${t('diagRepair')}: ${entry.repair}`))
8551
+ : null,
8552
+ entry.detail
8553
+ ? h('pre', {
8554
+ style: { ...S.muted, margin: '6px 0 0', fontSize: 11, whiteSpace: 'pre-wrap', wordBreak: 'break-all' },
8555
+ }, JSON.stringify(entry.detail).slice(0, 1200))
8556
+ : null)
8557
+ const diagFilters = h('div', { style: { display: 'flex', gap: 8, flexWrap: 'wrap', marginBottom: 10 } },
8558
+ h('select', {
8559
+ style: S.input,
8560
+ 'aria-label': t('diagEventsTitle'),
8561
+ value: diagLevel,
8562
+ onChange: (event) => setDiagLevel(event.target.value),
8563
+ },
8564
+ h('option', { value: '' }, t('diagAllLevels')),
8565
+ h('option', { value: 'error' }, t('diagLevelError')),
8566
+ h('option', { value: 'warn' }, t('diagLevelWarn')),
8567
+ h('option', { value: 'info' }, t('diagLevelInfo'))),
8568
+ h('input', {
8569
+ style: S.input,
8570
+ value: diagQueryInput,
8571
+ placeholder: t('diagSearch'),
8572
+ 'aria-label': t('diagSearch'),
8573
+ onChange: (event) => setDiagQueryInput(event.target.value),
8574
+ onKeyDown: (event) => { if (event.key === 'Enter') setDiagQuery(diagQueryInput) },
8575
+ }),
8576
+ h(Button, { onClick: () => { setDiagQuery(diagQueryInput); void loadDiagnostics() }, disabled: diagBusy }, t('diagRefresh')),
8577
+ diagStats
8578
+ ? h('div', { style: S.muted }, `${diagStats.total} · error ${diagStats.counts?.error || 0} / warn ${diagStats.counts?.warn || 0}`)
8579
+ : null)
8580
+ const diagEventsSection = h(Section, { title: t('diagEventsTitle'), desc: t('diagEventsDesc') },
8581
+ diagFilters,
8582
+ diagRows.length === 0
8583
+ ? h(Empty, null, t('diagEmpty'))
8584
+ : h('div', { style: S.list }, diagRows.map(diagEventRow)))
8585
+ const diagnosticsBlock = h(React.Fragment, null, diagEnvSection, diagEventsSection)
8586
+ const pageBlocks = [engineBlock, connectionBlock, settingsBlock, foldersBlock, librariesBlock, browserBlock, globalBlock, promptsBlock, statsBlock, memoriesBlock, graphBlock, logsBlock, lexiconBlock, helpBlock, diagnosticsBlock]
8245
8587
 
8246
8588
  // Settings uses a left nav with a sliding indicator (the sidebar keeps its
8247
8589
  // top segments). The indicator is one absolutely-positioned element moved by
8248
8590
  // a transform, so the active item animates without per-item flicker.
8591
+ // 启动提醒卡:DSH 启动后主页主动弹出的"插件内部有问题"。只显示 error 级且
8592
+ // 未确认过的条目(服务端按累积出现次数判断),点「去诊断」会一起确认,所以同一
8593
+ // 问题不会每次开机都重弹;点「稍后」只关这一次。
8594
+ const startupAlertCard = startupAlerts.length
8595
+ ? h(Section, {
8596
+ title: t('diagAlertTitle'),
8597
+ desc: t('diagAlertDesc'),
8598
+ right: h('div', { style: { display: 'flex', gap: 6, flexWrap: 'wrap' } },
8599
+ h(Button, { onClick: () => { void dismissAlerts(true) } }, t('diagAlertOpen')),
8600
+ h(Button, { style: S.ghost, onClick: () => { void dismissAlerts(false) } }, t('diagAlertLater'))),
8601
+ }, h('div', { style: S.list }, startupAlerts.slice(0, 4).map(alert => h('div', { key: alert.key || alert.code, style: S.item },
8602
+ h('div', { style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap' } },
8603
+ h(Tag, { tone: 'danger' }, alert.level || 'error'),
8604
+ h('span', { style: { fontFamily: 'monospace', fontSize: 12 } }, alert.code),
8605
+ Number(alert.count) > 1 ? h('span', { style: S.muted }, `x${alert.count}`) : null),
8606
+ h('div', { style: { marginTop: 4 } }, alert.message)))))
8607
+ : null
8249
8608
  const active = pageDefs[page] || pageDefs[0]
8250
8609
  // 沉浸式只给独立 WebUI 的完整工作室用。宿主设置页里这一页现在只是一个按钮,
8251
8610
  // 不能再套 is-graph-wide:那会把本来横排的导航强制成 158px 竖排。
@@ -8312,6 +8671,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
8312
8671
  void flushSettings()
8313
8672
  } }, t('settingsRetry')),
8314
8673
  h(Button, { style: S.ghost, onClick: () => setFailedPatch(null) }, t('settingsDiscard'))) : null,
8674
+ // 启动提醒只挂在主页(概览)最上面:设置页里弹一个"你插件坏了"的卡会打断
8675
+ // 用户正在做的事,而主页本来就是"看一眼状态"的地方。
8676
+ page === PAGE.overview ? startupAlertCard : null,
8315
8677
  pageBlocks[page] || null)))
8316
8678
  }
8317
8679
 
@@ -9237,4 +9599,4 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
9237
9599
 
9238
9600
  return module.exports
9239
9601
  },
9240
- })
9602
+ })