dsh-memu-memory 1.3.12 → 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: '复制全部',
@@ -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',
@@ -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。
@@ -5518,6 +5624,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5518
5624
  logs: 11,
5519
5625
  lexicon: 12,
5520
5626
  help: 13,
5627
+ // 诊断页固定排最后(14):它是排查入口,不该挤在功能页中间;三处清单
5628
+ // (SETTINGS_PAGES / pageDefs / PAGE)必须同序,否则导航会整片错位。
5629
+ diagnostics: 14,
5521
5630
  }
5522
5631
  const call = useRpc(ctx)
5523
5632
  const sessionId = useCurrentSession(ctx)
@@ -5579,6 +5688,63 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5579
5688
  } catch (error) { setLogNotice(String(error?.message || error)) } finally { setLogBusy(false) }
5580
5689
  }, [call, logKind, logQuery])
5581
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
+ }
5582
5748
  const settingsTimer = React.useRef(null)
5583
5749
  const saveChain = React.useRef(Promise.resolve())
5584
5750
  const [resetArmed, setResetArmed] = React.useState(false)
@@ -8060,6 +8226,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
8060
8226
  pageDefs.push({ label: t('pageLogs'), overline: 'ACTIVITY', desc: t('descLogs'), icon: GlyphText })
8061
8227
  pageDefs.push({ label: t('pageLexicon'), overline: 'LEXICON', desc: t('descLexicon'), icon: GlyphStack })
8062
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 })
8063
8231
  // 首次安装引导(§6.5 包 E):只在还没有任何库时出现——有了库,用户已经过了
8064
8232
  // 这一步,卡片只会碍事。不落 localStorage:关不掉是刻意的,等第一个库建好
8065
8233
  // 它自然消失;以后要记关闭状态必须走 settings,不许加本地存储。
@@ -8304,11 +8472,139 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
8304
8472
  row.detail
8305
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))
8306
8474
  : null)))))
8307
- 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]
8308
8587
 
8309
8588
  // Settings uses a left nav with a sliding indicator (the sidebar keeps its
8310
8589
  // top segments). The indicator is one absolutely-positioned element moved by
8311
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
8312
8608
  const active = pageDefs[page] || pageDefs[0]
8313
8609
  // 沉浸式只给独立 WebUI 的完整工作室用。宿主设置页里这一页现在只是一个按钮,
8314
8610
  // 不能再套 is-graph-wide:那会把本来横排的导航强制成 158px 竖排。
@@ -8375,6 +8671,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
8375
8671
  void flushSettings()
8376
8672
  } }, t('settingsRetry')),
8377
8673
  h(Button, { style: S.ghost, onClick: () => setFailedPatch(null) }, t('settingsDiscard'))) : null,
8674
+ // 启动提醒只挂在主页(概览)最上面:设置页里弹一个"你插件坏了"的卡会打断
8675
+ // 用户正在做的事,而主页本来就是"看一眼状态"的地方。
8676
+ page === PAGE.overview ? startupAlertCard : null,
8378
8677
  pageBlocks[page] || null)))
8379
8678
  }
8380
8679
 
@@ -9300,4 +9599,4 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
9300
9599
 
9301
9600
  return module.exports
9302
9601
  },
9303
- })
9602
+ })