dsh-memu-memory 1.3.1 → 1.3.2

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +3 -3
  3. package/README.zh.md +3 -1
  4. package/docs/contributing.md +2 -2
  5. package/docs/env-and-commands.md +12 -1
  6. package/docs/memory-semantics.md +8 -2
  7. package/docs/troubleshooting.md +9 -6
  8. package/lib/auto-link/apply.js +249 -0
  9. package/lib/auto-link/candidates.js +155 -0
  10. package/lib/auto-link/decide.js +304 -0
  11. package/lib/auto-link/normalize.js +99 -0
  12. package/lib/auto-link/policy.js +42 -0
  13. package/lib/auto-link/suppression.js +101 -0
  14. package/lib/auto-link/terminology.js +265 -0
  15. package/lib/binding-diagnostics.js +2 -2
  16. package/lib/client.js +1412 -69
  17. package/lib/graph.js +269 -18
  18. package/lib/memory.js +11 -0
  19. package/lib/memu.js +7 -6
  20. package/lib/private-links.js +105 -137
  21. package/lib/private.js +138 -38
  22. package/lib/rpc.js +67 -7
  23. package/lib/state.js +7 -2
  24. package/lib/tools.js +4 -2
  25. package/lib/webui/graph-LICENSE.txt +1 -62
  26. package/lib/webui/graph-view.bundle.js +1 -1
  27. package/lib/webui/graph-view.js +891 -124
  28. package/lib/webui/standalone.js +3 -3
  29. package/package.json +1 -2
  30. package/scripts/build-graph.mjs +3 -3
  31. package/scripts/check-graph-browser.mjs +106 -23
  32. package/scripts/rebuild-auto-links.mjs +252 -0
  33. package/tests/audit-regression.test.mjs +11 -8
  34. package/tests/auto-link-candidates.test.mjs +161 -0
  35. package/tests/auto-link-decide.test.mjs +512 -0
  36. package/tests/auto-link-migration.test.mjs +133 -0
  37. package/tests/client-render.test.mjs +7 -6
  38. package/tests/consolidation-fork.test.mjs +148 -0
  39. package/tests/cycle.test.mjs +1 -1
  40. package/tests/graph-view.test.mjs +163 -21
  41. package/tests/graph.test.mjs +5 -0
  42. package/tests/help-page.test.mjs +3 -3
  43. package/tests/memu-resident-route.test.mjs +130 -0
  44. package/tests/private-links.test.mjs +81 -45
  45. package/tests/stubs/child-process-spy.mjs +14 -0
  46. package/tests/tools.test.mjs +24 -18
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', 'logs', 'lexicon', 'help']
11
+ const SETTINGS_PAGES = ['engine', 'connection', 'settings', 'folders', 'libraries', 'browser', 'global', 'prompts', 'stats', 'memories', 'graph', 'logs', 'lexicon', 'help']
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'
@@ -117,6 +117,86 @@ window.__ModuleLoader__.load({
117
117
  reviewConditions: '说明不同适用条件(至少 8 字)',
118
118
  pageMemories: 'MemU 记忆',
119
119
  descMemories: '跨库记忆、来源与状态',
120
+ pageGraph: '关系图谱',
121
+ descGraph: '力导向节点图:拖动即固定、弹簧链跟随',
122
+ graphCenter: '向心力',
123
+ graphPinned: '已固定',
124
+ graphUnpinAll: '解除全部固定',
125
+ graphRelayout: '重新布局',
126
+ graphPinHint: '左键拖动节点 · 右键锁定 / 解除 · Shift 拖整簇',
127
+ graphScopeHint: '拖动只影响所连的簇,其他簇保持不动',
128
+ gsManage: '管理',
129
+ gsSearch: '搜索节点 / 证据…',
130
+ gsRules: '规则筛选',
131
+ gsExport: '导出 PNG',
132
+ gsLegend: '图例',
133
+ gsForce: '力导向参数',
134
+ gsReset: '恢复默认',
135
+ gsCollapse: '折叠 / 展开检视面板',
136
+ gsGrid: '显示网格',
137
+ gsMinimap: '显示缩略图',
138
+ gsHelp: '快捷键',
139
+ gsFocusNode: '聚焦选中节点',
140
+ gsInspector: '检视面板',
141
+ gsInspectorHint: '面板独立滚动 · 不把整页撑成长列表',
142
+ gsNodes: '节点',
143
+ gsEdges: '边',
144
+ gsVisible: '可见',
145
+ gsAutoEdges: '自动边',
146
+ gsPending: '待确认',
147
+ gsRender: '渲染',
148
+ gsEmpty: '当前筛选下没有可显示的边',
149
+ gsAllLibraries: '全部记忆库',
150
+ gsGlobalEmpty: '全部记忆库还没有关联;先在 MemU 记忆里建立关系',
151
+ gsLocate: '图中定位',
152
+ gsNoSelection: '未选中节点',
153
+ gsLocalData: '插件数据',
154
+ gsThemeHint: '跟随宿主主题',
155
+ gsTitle: '标题',
156
+ gsKind: '类型',
157
+ gsStatus: '状态',
158
+ gsLayer: '层级',
159
+ gsConfirmed: '已确认',
160
+ gsNoRules: '当前没有带规则(evidence.rule)的边',
161
+ gsRuleAuto: '旧版自动',
162
+ gsRuleMention: '提及',
163
+ gsRuleConflict: '冲突',
164
+ gsRuleSupersede: '取代',
165
+ gsRuleFactKey: '同键',
166
+ gsRuleWorkerQuote: '引文',
167
+ gsAddNode: '新增节点',
168
+ gsEditNode: '编辑节点',
169
+ gsNodeMemory: '记忆',
170
+ gsNodeEntity: '实体',
171
+ gsRemoveNode: '删除节点',
172
+ gsRemoveNodeHint: '永久删除选中节点:记忆先归档再删除,实体连同其关联边一起删除',
173
+ gsNodeCreated: '已创建「{name}」',
174
+ gsNodeDeleted: '节点已删除',
175
+ gsAddLibrary: '目标记忆库',
176
+ gsDegree: '关联',
177
+ gsStrength: '强度',
178
+ gsAction: '操作',
179
+ gsAllKinds: '全部类型',
180
+ gsAllStatus: '全部状态',
181
+ gsSort: '排序方式',
182
+ gsNoMatch: '没有匹配的节点',
183
+ gsShortcuts: '+/− 缩放 · F 适应 · / 搜索 · 左键拖动 · 右键锁定/解除 · Shift 整簇 · 双击聚焦',
184
+ gsLegendMemory: '长期记忆',
185
+ gsLegendMust: '永久记忆',
186
+ gsLegendEntity: '已确认实体',
187
+ gsLegendPending: '待确认实体',
188
+ gsLegendGlobal: '全局记忆',
189
+ gsLegendMissing: '已删除',
190
+ gsLegendAuto: '自动边 · 实线',
191
+ gsLegendManual: '手动边 · 虚线',
192
+ gsHideNav: '收起左侧导航',
193
+ gsShowNav: '显示左侧导航',
194
+ gsBranch: '连接分支',
195
+ gsBranchHint: '查看所选节点的邻域、边类型与图中定位',
196
+ gsResize: '拖动调整面板宽度',
197
+ gsTier1: '一级邻域',
198
+ gsTier2: '二级邻域',
199
+ gsViewBranch: '查看分支',
120
200
  pageLogs: '日志',
121
201
  descLogs: '召回、写入、整理与向量的活动记录,可筛选、复制、下载',
122
202
  logSearch: '搜索 id / 标题 / 错误',
@@ -253,6 +333,15 @@ window.__ModuleLoader__.load({
253
333
  entityKind: '实体类型',
254
334
  graphEmpty: '还没有关联',
255
335
  graphAutoLink: '自动',
336
+ edgeFilterAll: '全部来源',
337
+ edgeFilterAuto: '仅自动',
338
+ edgeFilterManual: '仅手动',
339
+ purgeAutoLinks: '删除全部自动边',
340
+ purgeAutoConfirm: '确认删除自动边',
341
+ purgeAutoDone: '已删除 {n} 条自动边',
342
+ clearSuppression: '解除删除标记',
343
+ clearSuppressionConfirm: '确认解除删除标记',
344
+ clearSuppressionDone: '已解除 {n} 条删除标记',
256
345
  deletedNode: '[已删除]',
257
346
  graphLimited: '仅显示最多 200 个节点',
258
347
  graphFit: '适应全图',
@@ -820,6 +909,29 @@ window.__ModuleLoader__.load({
820
909
  orphanEntities: '未关联实体 ({n})',
821
910
  orphanPruneHint: '这些实体没有被任何记忆或关系引用,插件下次启动时会自动清理。',
822
911
  entityEmpty: '这个词库还没有实体。',
912
+ // —— 自动关联:待确认实体(DESIGN §9.2/§10)——
913
+ anchorReviewTitle: '待确认实体',
914
+ anchorReviewHint: '统计只用来排候选,不会自动写边。只有你确认过的名字,才会把已有记忆里的提及连到它。',
915
+ anchorTier1: '有证据的候选',
916
+ anchorTier2: '仅统计特征(需复核)',
917
+ anchorConfirm: '确认',
918
+ anchorConfirmSelected: '确认选中({n})',
919
+ anchorPendingEntity: '待确认',
920
+ anchorExistingEntity: '已有实体',
921
+ anchorArchivedEntity: '已归档',
922
+ anchorNoCandidates: '没有新的候选。',
923
+ anchorCreateHint: '确认后会建成实体,并立即给已有记忆补挂提及边。',
924
+ anchorKindHint: '类型随确认一起定下,之后不能修改。',
925
+ anchorConfirmedDone: '已确认 {n} 个实体,提及边已补挂。',
926
+ anchorSignalQuote: '引号',
927
+ anchorSignalIntro: '引导语',
928
+ anchorSignalMixed: '标识符',
929
+ anchorStats: 'df {df} · 凝聚 {cohesion} · 边界 {freedom}',
930
+ autoLinkMode: '自动关联',
931
+ autoLinkSuggest: '只出候选(推荐)',
932
+ autoLinkDeterministic: '确定性写边',
933
+ autoLinkOff: '关闭',
934
+ autoLinkHint: '“只出候选”不会写任何边;“确定性写边”只写两类边:已确认实体的提及,以及 conflicts_with / supersedes / 同 fact_key 的字段证据。词面相似度与向量永远不建边。',
823
935
  firstRunTitle: '先建一个记忆库',
824
936
  firstRunDesc: '还没有任何记忆库。新建一个私有库后,会话里的记忆才有地方落。',
825
937
  firstRunGoLibraries: '去新建库',
@@ -934,6 +1046,86 @@ window.__ModuleLoader__.load({
934
1046
  reviewConditions: 'Explain distinct conditions (at least 8 characters)',
935
1047
  pageMemories: 'MemU Memory',
936
1048
  descMemories: 'Memories, provenance and status across libraries',
1049
+ pageGraph: 'Relationship graph',
1050
+ descGraph: 'Force graph: drag to pin, spring-chain follow',
1051
+ graphCenter: 'Center force',
1052
+ graphPinned: 'Pinned',
1053
+ graphUnpinAll: 'Unpin all',
1054
+ graphRelayout: 'Re-layout',
1055
+ graphPinHint: 'Left-drag a node · right-click locks / unlocks · Shift drags the cluster',
1056
+ graphScopeHint: 'Dragging only moves the connected cluster',
1057
+ gsManage: 'Manage',
1058
+ gsSearch: 'Search nodes / evidence…',
1059
+ gsRules: 'Rule filter',
1060
+ gsExport: 'Export PNG',
1061
+ gsLegend: 'Legend',
1062
+ gsForce: 'Force parameters',
1063
+ gsReset: 'Reset',
1064
+ gsCollapse: 'Toggle inspector',
1065
+ gsGrid: 'Show grid',
1066
+ gsMinimap: 'Show minimap',
1067
+ gsHelp: 'Shortcuts',
1068
+ gsFocusNode: 'Focus selected',
1069
+ gsInspector: 'Inspector',
1070
+ gsInspectorHint: 'Scrolls on its own · the page never becomes one long list',
1071
+ gsNodes: 'Nodes',
1072
+ gsEdges: 'Edges',
1073
+ gsVisible: 'Visible',
1074
+ gsAutoEdges: 'Auto edges',
1075
+ gsPending: 'Pending',
1076
+ gsRender: 'Render',
1077
+ gsEmpty: 'No edges match the current filter',
1078
+ gsAllLibraries: 'All libraries',
1079
+ gsGlobalEmpty: 'No links across all libraries yet; create relations in MemU memory first',
1080
+ gsLocate: 'Locate',
1081
+ gsNoSelection: 'No node selected',
1082
+ gsLocalData: 'Plugin data',
1083
+ gsThemeHint: 'Follows host theme',
1084
+ gsTitle: 'Title',
1085
+ gsKind: 'Kind',
1086
+ gsStatus: 'Status',
1087
+ gsLayer: 'Layer',
1088
+ gsConfirmed: 'Confirmed',
1089
+ gsNoRules: 'No edges carry evidence.rule yet',
1090
+ gsRuleAuto: 'Legacy auto',
1091
+ gsRuleMention: 'Mention',
1092
+ gsRuleConflict: 'Conflict',
1093
+ gsRuleSupersede: 'Superseded',
1094
+ gsRuleFactKey: 'Fact key',
1095
+ gsRuleWorkerQuote: 'Worker quote',
1096
+ gsAddNode: 'Add node',
1097
+ gsEditNode: 'Edit node',
1098
+ gsNodeMemory: 'Memory',
1099
+ gsNodeEntity: 'Entity',
1100
+ gsRemoveNode: 'Delete node',
1101
+ gsRemoveNodeHint: 'Permanently delete the selected node: memories are archived then deleted, entities are removed with their links',
1102
+ gsNodeCreated: 'Created "{name}"',
1103
+ gsNodeDeleted: 'Node deleted',
1104
+ gsAddLibrary: 'Target library',
1105
+ gsDegree: 'Links',
1106
+ gsStrength: 'Strength',
1107
+ gsAction: 'Action',
1108
+ gsAllKinds: 'All kinds',
1109
+ gsAllStatus: 'All statuses',
1110
+ gsSort: 'Sort by',
1111
+ gsNoMatch: 'No matching nodes',
1112
+ gsShortcuts: '+/- zoom · F fit · / search · left-drag moves · right-click locks/unlocks · Shift cluster · double-click focus',
1113
+ gsLegendMemory: 'Long-term memory',
1114
+ gsLegendMust: 'Must remember',
1115
+ gsLegendEntity: 'Confirmed entity',
1116
+ gsLegendPending: 'Provisional entity',
1117
+ gsLegendGlobal: 'Global memory',
1118
+ gsLegendMissing: 'Deleted',
1119
+ gsLegendAuto: 'Auto edge · solid',
1120
+ gsLegendManual: 'Manual edge · dashed',
1121
+ gsHideNav: 'Hide left nav',
1122
+ gsShowNav: 'Show left nav',
1123
+ gsBranch: 'Connected branch',
1124
+ gsBranchHint: 'Inspect neighbourhood, edge kinds and locate on canvas',
1125
+ gsResize: 'Drag to resize the panel',
1126
+ gsTier1: 'Direct neighbours',
1127
+ gsTier2: 'Second-degree neighbours',
1128
+ gsViewBranch: 'View branch',
937
1129
  pageLogs: 'Logs',
938
1130
  descLogs: 'Recall, writes, consolidation and vector activity; filter, copy or download',
939
1131
  logSearch: 'Search id / title / error',
@@ -1070,6 +1262,15 @@ window.__ModuleLoader__.load({
1070
1262
  entityKind: 'Entity kind',
1071
1263
  graphEmpty: 'No connections yet',
1072
1264
  graphAutoLink: 'Auto',
1265
+ edgeFilterAll: 'All sources',
1266
+ edgeFilterAuto: 'Auto only',
1267
+ edgeFilterManual: 'Manual only',
1268
+ purgeAutoLinks: 'Remove all auto edges',
1269
+ purgeAutoConfirm: 'Confirm removing auto edges',
1270
+ purgeAutoDone: 'Removed {n} auto edge(s)',
1271
+ clearSuppression: 'Clear deletion markers',
1272
+ clearSuppressionConfirm: 'Confirm clearing deletion markers',
1273
+ clearSuppressionDone: 'Cleared {n} deletion marker(s)',
1073
1274
  deletedNode: '[deleted]',
1074
1275
  graphLimited: 'Showing at most 200 nodes',
1075
1276
  graphFit: 'Fit graph',
@@ -1636,6 +1837,29 @@ window.__ModuleLoader__.load({
1636
1837
  orphanEntities: 'Unlinked entities ({n})',
1637
1838
  orphanPruneHint: 'No memory or relationship references these entities; the plugin cleans them up automatically at the next startup.',
1638
1839
  entityEmpty: 'No entities in this library yet.',
1840
+ // —— Auto-link: entities awaiting confirmation (DESIGN §9.2/§10) ——
1841
+ anchorReviewTitle: 'Entities to confirm',
1842
+ anchorReviewHint: 'Statistics only rank the queue and never write edges. Only a name you confirm gets its existing memories connected.',
1843
+ anchorTier1: 'Evidenced candidates',
1844
+ anchorTier2: 'Statistical only (needs review)',
1845
+ anchorConfirm: 'Confirm',
1846
+ anchorConfirmSelected: 'Confirm selected ({n})',
1847
+ anchorPendingEntity: 'Pending',
1848
+ anchorExistingEntity: 'Existing entity',
1849
+ anchorArchivedEntity: 'Archived',
1850
+ anchorNoCandidates: 'No new candidates.',
1851
+ anchorCreateHint: 'Confirming creates the entity and immediately attaches mention edges to existing memories.',
1852
+ anchorKindHint: 'The kind is fixed at confirmation time and cannot be changed later.',
1853
+ anchorConfirmedDone: 'Confirmed {n} entit(ies); mention edges are attached.',
1854
+ anchorSignalQuote: 'Quoted',
1855
+ anchorSignalIntro: 'Name intro',
1856
+ anchorSignalMixed: 'Identifier',
1857
+ anchorStats: 'df {df} · cohesion {cohesion} · boundary {freedom}',
1858
+ autoLinkMode: 'Auto-linking',
1859
+ autoLinkSuggest: 'Candidates only (recommended)',
1860
+ autoLinkDeterministic: 'Deterministic edges',
1861
+ autoLinkOff: 'Off',
1862
+ autoLinkHint: '"Candidates only" writes no edges. "Deterministic edges" writes exactly two kinds: mentions of confirmed entities, and field evidence from conflicts_with / supersedes / the same fact_key. Lexical similarity and vectors never create an edge.',
1639
1863
  firstRunTitle: 'Create a memory library first',
1640
1864
  firstRunDesc: 'There are no libraries yet. Memories from your conversations need one to land in.',
1641
1865
  firstRunGoLibraries: 'Create a library',
@@ -1872,6 +2096,251 @@ window.__ModuleLoader__.load({
1872
2096
  .dshm-graph-unlink.is-armed{width:auto;padding:0 8px;font-size:11.5px;color:var(--dsw-alias-state-error-primary,#b43e45);background:color-mix(in srgb,var(--dsw-alias-state-error-primary,#b43e45) 12%,transparent)}
1873
2097
  @media (max-width:1100px){.dshm-graph-stage{grid-template-columns:minmax(0,1fr)}}
1874
2098
  .dshm-graph-missing{opacity:.5}
2099
+ /* Graph Studio 工作台:按 graph-studio/index.html 的界面逐块复刻,尺寸按 WebUI 收敛,
2100
+ 颜色全部走 --dsw-alias-* token,自动跟随宿主明暗。画布本身仍由 graph-view.js 绘制。 */
2101
+ .dshm-gs{--gs-panel:var(--dsw-alias-bg-layer-1,#fff);--gs-panel-2:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.07));--gs-border:var(--dsw-alias-border-l1,rgba(127,127,127,.20));--gs-border-soft:var(--dsw-alias-border-l2,rgba(127,127,127,.10));--gs-text:var(--dsw-alias-label-primary,#1a1e2b);--gs-dim:var(--dsw-alias-label-secondary,rgba(127,127,127,.9));--gs-faint:var(--dsw-alias-label-secondary,rgba(127,127,127,.65));--gs-accent:var(--dsw-alias-brand-primary,#3b5bdb);--gs-on-accent:var(--dsw-alias-brand-text,#fff);--gs-accent-soft:color-mix(in srgb,var(--gs-accent) 12%,transparent);--gs-radius:12px;--gs-radius-sm:8px;--gs-shadow:0 12px 32px rgba(20,30,60,.16);--gs-shadow-sm:0 3px 12px rgba(20,30,60,.12);
2102
+ display:grid;grid-template-columns:46px minmax(0,1fr) 344px;grid-template-rows:50px minmax(0,1fr) 28px;
2103
+ height:clamp(520px,calc(100vh - 210px),860px);min-height:420px;position:relative;overflow:hidden;
2104
+ border:1px solid var(--gs-border);border-radius:var(--gs-radius);background:var(--dsw-alias-bg-base,transparent);
2105
+ color:var(--gs-text);font-size:12px;line-height:1.5}
2106
+ .dshm-gs *{box-sizing:border-box;min-width:0}
2107
+ .dshm-gs button,.dshm-gs input,.dshm-gs select{font:inherit;color:inherit}
2108
+ .dshm-gs button{cursor:pointer}
2109
+ .dshm-gs.is-collapsed{grid-template-columns:46px minmax(0,1fr) 0}
2110
+ .dshm-gs.is-collapsed .dshm-gs-inspector{display:none}
2111
+ .dshm-gs.is-manage{grid-template-columns:0 minmax(0,1fr) 0}
2112
+ .dshm-gs.is-manage .dshm-gs-rail,.dshm-gs.is-manage .dshm-gs-stage,.dshm-gs.is-manage .dshm-gs-inspector,.dshm-gs.is-manage .dshm-gs-popwrap,.dshm-gs.is-manage .dshm-gs-themechip,.dshm-gs.is-manage .dshm-gs-icon{display:none!important}
2113
+ .dshm-gs.is-manage .dshm-gs-manager{display:flex}
2114
+ .dshm-gs-c-memory{background:#618fcd}.dshm-gs-c-must{background:#d97768}.dshm-gs-c-short{background:#8a93a6}
2115
+ .dshm-gs-c-entity{background:#36a582}.dshm-gs-c-provisional{background:#b9963f}.dshm-gs-c-global{background:#8b7bd8}.dshm-gs-c-missing{background:#92959c}
2116
+ /* topbar */
2117
+ .dshm-gs-topbar{grid-column:1/-1;grid-row:1;display:flex;align-items:center;gap:9px;padding:0 12px;border-bottom:1px solid var(--gs-border);background:var(--gs-panel);z-index:20;min-width:0}
2118
+ .dshm-gs-brand{display:flex;align-items:center;gap:9px;flex-shrink:0}
2119
+ .dshm-gs-mark{width:28px;height:28px;border-radius:8px;display:grid;place-items:center;background:linear-gradient(140deg,var(--gs-accent),color-mix(in srgb,var(--gs-accent) 55%,#8b7bd8));color:var(--gs-on-accent);font-weight:750;font-size:14px;box-shadow:var(--gs-shadow-sm)}
2120
+ .dshm-gs-brand-txt strong{display:block;font-size:12.5px;font-weight:680;line-height:1.15;white-space:nowrap}
2121
+ .dshm-gs-brand-txt small{display:block;color:var(--gs-faint);font-size:9.5px;letter-spacing:.1em;text-transform:uppercase}
2122
+ .dshm-gs-divider{width:1px;height:20px;background:var(--gs-border);flex-shrink:0}
2123
+ .dshm-gs-seg{display:inline-flex;padding:2px;gap:2px;border:1px solid var(--gs-border);border-radius:999px;background:var(--gs-panel-2);flex-shrink:0}
2124
+ .dshm-gs-seg button{border:0;background:transparent;color:var(--gs-dim);font-size:11px;padding:3px 10px;border-radius:999px;white-space:nowrap;transition:.18s}
2125
+ .dshm-gs-seg button[aria-pressed=true]{background:var(--gs-accent);color:var(--gs-on-accent);font-weight:600}
2126
+ .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%}
2127
+ .dshm-gs-field:focus{border-color:var(--gs-accent);box-shadow:0 0 0 3px var(--gs-accent-soft)}
2128
+ .dshm-gs-search{position:relative;flex:1 1 160px;max-width:260px;min-width:90px}
2129
+ /* standalone.css 会给外壳输入框统一 padding/height;工作台的紧凑控件必须用更高
2130
+ 特异性拉回自己的尺寸,否则搜索图标会压住文字、顶栏控件高度也不齐。 */
2131
+ .dshm-gs-search .dshm-gs-field{width:100%;padding-left:28px!important}
2132
+ .dshm-gs-search-icon{position:absolute;left:9px;top:0;bottom:0;display:flex;align-items:center;font-size:14px;line-height:1;color:var(--gs-faint);pointer-events:none}
2133
+ html[data-standalone] .dshm-root .dshm-gs .dshm-gs-topbar input.dshm-gs-field,
2134
+ html[data-standalone] .dshm-root .dshm-gs .dshm-gs-topbar select.dshm-gs-field,
2135
+ html[data-standalone] .dshm-root .dshm-gs .dshm-gs-mgr-head select.dshm-gs-field{height:29px!important;padding:0 9px!important;border-radius:var(--gs-radius-sm)!important;font-size:11.5px!important;background:var(--gs-panel-2)!important;border-color:var(--gs-border)!important}
2136
+ html[data-standalone] .dshm-root .dshm-gs .dshm-gs-search input.dshm-gs-field{padding:0 9px 0 28px!important}
2137
+ html[data-standalone] .dshm-root .dshm-gs .dshm-gs-forcepop input[type=range]{height:auto!important;padding:0!important;border:0!important;background:transparent!important}
2138
+ .dshm-gs-spacer{flex:1 1 auto}
2139
+ .dshm-gs-btn{height:29px;padding:0 11px;border:1px solid var(--gs-border);border-radius:var(--gs-radius-sm);background:var(--gs-panel-2);font-size:11.5px;white-space:nowrap;display:inline-flex;align-items:center;gap:6px;transition:.18s}
2140
+ .dshm-gs-btn:hover{border-color:var(--gs-accent);color:var(--gs-accent)}
2141
+ .dshm-gs-btn.primary{background:var(--gs-accent);border-color:transparent;color:var(--gs-on-accent);font-weight:600}
2142
+ .dshm-gs-btn.icon{width:29px;padding:0;justify-content:center;font-size:14px}
2143
+ .dshm-gs-btn:disabled{opacity:.45;cursor:not-allowed}
2144
+ .dshm-gs-count{font-size:10px;color:var(--gs-dim);font-variant-numeric:tabular-nums}
2145
+ .dshm-gs-popwrap,.dshm-gs-legendwrap{position:relative;flex-shrink:0}
2146
+ .dshm-gs-pop,.dshm-gs-legendpop{position:absolute;top:38px;right:0;width:230px;padding:11px;border:1px solid var(--gs-border);border-radius:var(--gs-radius);background:var(--gs-panel);box-shadow:var(--gs-shadow);z-index:60}
2147
+ .dshm-gs-pop h4,.dshm-gs-legendpop h4{margin:0 0 8px;font-size:10.5px;letter-spacing:.07em;text-transform:uppercase;color:var(--gs-faint);font-weight:650}
2148
+ .dshm-gs-pop label{display:flex;align-items:center;gap:8px;padding:4px 2px;font-size:11.5px;color:var(--gs-dim);cursor:pointer}
2149
+ .dshm-gs-pop input{accent-color:var(--gs-accent)}
2150
+ .dshm-gs-themechip{display:inline-flex;align-items:center;gap:6px;height:27px;padding:0 10px;border:1px solid var(--gs-border);border-radius:999px;background:var(--gs-panel-2);font-size:11px;color:var(--gs-dim);white-space:nowrap}
2151
+ .dshm-gs-dot{width:8px;height:8px;border-radius:50%;background:var(--gs-accent)}
2152
+ /* rail */
2153
+ .dshm-gs-rail{grid-column:1;grid-row:2;display:flex;flex-direction:column;align-items:center;gap:6px;padding:10px 0;border-right:1px solid var(--gs-border);background:var(--gs-panel-2);z-index:10}
2154
+ .dshm-gs-rail button{width:30px;height:30px;border:1px solid transparent;border-radius:var(--gs-radius-sm);background:transparent;color:var(--gs-dim);display:grid;place-items:center;font-size:14px;transition:.18s}
2155
+ .dshm-gs-rail button:hover{background:var(--gs-accent-soft);color:var(--gs-accent);border-color:var(--gs-border)}
2156
+ .dshm-gs-rail button[aria-pressed=true]{background:var(--gs-accent-soft);color:var(--gs-accent);border-color:var(--gs-accent)}
2157
+ .dshm-gs-rail-sep{width:20px;height:1px;background:var(--gs-border);margin:2px 0}
2158
+ .dshm-gs-rail-grow{flex:1}
2159
+ /* stage */
2160
+ .dshm-gs-stage{grid-column:2;grid-row:2;position:relative;min-width:0;min-height:0;overflow:hidden;background:var(--gs-panel)}
2161
+ .dshm-gs-stage .dshm-graph-viewport{position:absolute;inset:0;border:0;border-radius:0;background:transparent}
2162
+ .dshm-gs-stage .dshm-graph-canvas{width:100%;height:100%;max-height:none;min-height:0}
2163
+ .dshm-gs-canvas-tools{position:absolute;left:12px;bottom:12px;display:flex;align-items:flex-end;gap:8px;z-index:8}
2164
+ .dshm-gs-zoombar{display:flex;align-items:center;gap:2px;padding:3px;border:1px solid var(--gs-border);background:var(--gs-panel);border-radius:10px;box-shadow:var(--gs-shadow-sm);opacity:.72}
2165
+ .dshm-gs-canvas-tools:hover .dshm-gs-zoombar,.dshm-gs-zoombar:focus-within{opacity:1}
2166
+ .dshm-gs-zoombar button{width:24px;height:24px;border:0;background:transparent;color:var(--gs-dim);border-radius:7px;font-size:13px;display:grid;place-items:center}
2167
+ .dshm-gs-zoombar button:hover{background:var(--gs-accent-soft);color:var(--gs-accent)}
2168
+ .dshm-gs-zoomval{min-width:40px;text-align:center;font-size:10.5px;color:var(--gs-dim);font-variant-numeric:tabular-nums}
2169
+ .dshm-gs-legendbtn{border:1px solid var(--gs-border);background:var(--gs-panel);color:var(--gs-dim);font-size:11px;padding:5px 9px;border-radius:9px;box-shadow:var(--gs-shadow-sm);opacity:.72}
2170
+ .dshm-gs-legendbtn:hover,.dshm-gs-canvas-tools:hover .dshm-gs-legendbtn{opacity:1;color:var(--gs-accent)}
2171
+ .dshm-gs-legendpop{bottom:calc(100% + 8px);left:0;top:auto;right:auto;width:210px;padding:10px 12px}
2172
+ .dshm-gs-legend-row{display:flex;align-items:center;gap:8px;font-size:11px;color:var(--gs-dim);padding:2px 0}
2173
+ .dshm-gs-swatch{width:9px;height:9px;border-radius:50%;flex-shrink:0;display:inline-block}
2174
+ .dshm-gs-line{width:16px;height:0;border-top:2px solid var(--gs-accent);flex-shrink:0}
2175
+ .dshm-gs-line.dashed{border-top-style:dashed;border-color:var(--gs-faint)}
2176
+ .dshm-gs-minimap{position:absolute;right:12px;bottom:12px;padding:7px;border:1px solid var(--gs-border);background:var(--gs-panel);border-radius:var(--gs-radius);box-shadow:var(--gs-shadow-sm);z-index:6}
2177
+ .dshm-gs-minimap h4{margin:0 0 5px;font-size:9.5px;letter-spacing:.08em;text-transform:uppercase;color:var(--gs-faint)}
2178
+ .dshm-gs-minimap canvas{display:block;width:158px;height:104px;border-radius:6px}
2179
+ .dshm-gs-rail-slot{position:relative;display:flex;flex:none}
2180
+ .dshm-gs-forcepop{position:absolute;left:calc(100% + 8px);top:-6px;width:226px;padding:11px;border:1px solid var(--gs-border);border-radius:var(--gs-radius);background:var(--gs-panel);box-shadow:var(--gs-shadow);z-index:40}
2181
+ .dshm-gs-forcepop h4{margin:0 0 6px;font-size:11px;font-weight:650}
2182
+ .dshm-gs-forcepop label{display:grid;grid-template-columns:56px 1fr 36px;align-items:center;gap:7px;padding:5px 0;font-size:11px;color:var(--gs-dim)}
2183
+ .dshm-gs-forcepop input[type=range]{width:100%;accent-color:var(--gs-accent);margin:0}
2184
+ .dshm-gs-forcepop output{font-size:10px;text-align:right;color:var(--gs-dim);font-variant-numeric:tabular-nums}
2185
+ .dshm-gs-forcepop-toggles{display:flex;flex-wrap:wrap;gap:6px 14px;margin-top:6px;padding-top:8px;border-top:1px solid var(--gs-border-soft)}
2186
+ .dshm-gs-mini{height:26px;padding:0 10px;font-size:11.5px;border-radius:7px;border:1px solid var(--gs-border);background:var(--gs-panel);white-space:nowrap;margin-top:8px}
2187
+ .dshm-gs-mini:hover{border-color:var(--gs-accent);color:var(--gs-accent)}
2188
+ .dshm-gs-forcepop .dshm-gs-mini{margin-top:9px}
2189
+ .dshm-gs-toast{position:absolute;left:50%;bottom:22px;transform:translate(-50%,10px);z-index:40;padding:8px 14px;border-radius:999px;background:var(--gs-text);color:var(--gs-panel);font-size:11.5px;box-shadow:var(--gs-shadow);opacity:0;transition:.25s;pointer-events:none;max-width:80%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
2190
+ .dshm-gs-toast.show{opacity:1;transform:translate(-50%,0)}
2191
+ .dshm-gs-empty{position:absolute;inset:0;display:grid;place-items:center;color:var(--gs-dim);font-size:12px;pointer-events:none}
2192
+ /* inspector */
2193
+ .dshm-gs-inspector{grid-column:3;grid-row:2;display:flex;flex-direction:column;min-height:0;border-left:1px solid var(--gs-border);background:var(--gs-panel);z-index:10}
2194
+ .dshm-gs-ins-head{flex-shrink:0;padding:12px 14px 9px;border-bottom:1px solid var(--gs-border-soft)}
2195
+ .dshm-gs-ins-title{display:flex;align-items:center;justify-content:space-between;gap:8px}
2196
+ .dshm-gs-ins-title h2{margin:0;font-size:12.5px;font-weight:680}
2197
+ .dshm-gs-ins-head p{margin:3px 0 0;font-size:10.5px;color:var(--gs-dim)}
2198
+ .dshm-gs-ins-body{flex:1;min-height:0;overflow-y:auto;padding:12px 14px 20px;display:flex;flex-direction:column;gap:12px}
2199
+ .dshm-gs-sec{border:1px solid var(--gs-border-soft);border-radius:var(--gs-radius);padding:11px;background:var(--gs-panel-2)}
2200
+ .dshm-gs-sec-head{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:9px}
2201
+ .dshm-gs-sec-head h3{margin:0;font-size:10.5px;letter-spacing:.06em;text-transform:uppercase;color:var(--gs-faint);font-weight:680}
2202
+ .dshm-gs-hero{display:flex;gap:10px;align-items:flex-start}
2203
+ .dshm-gs-glyph{width:34px;height:34px;border-radius:10px;display:grid;place-items:center;color:#fff;font-size:15px;flex-shrink:0;font-weight:700}
2204
+ .dshm-gs-hero-t h3{margin:1px 0 5px;font-size:13px;font-weight:670;line-height:1.35;overflow-wrap:anywhere}
2205
+ .dshm-gs-tags{display:flex;flex-wrap:wrap;gap:5px}
2206
+ .dshm-gs-tag{display:inline-flex;align-items:center;font-size:10px;padding:2px 8px;border-radius:999px;background:var(--gs-accent-soft);color:var(--gs-accent);white-space:nowrap;font-weight:600}
2207
+ .dshm-gs-tag.neutral{background:var(--gs-panel);border:1px solid var(--gs-border);color:var(--gs-dim);font-weight:500}
2208
+ .dshm-gs-tag.auto{background:var(--gs-accent-soft);color:var(--gs-accent)}
2209
+ .dshm-gs-tag.manual{background:transparent;border:1px dashed var(--gs-border);color:var(--gs-dim)}
2210
+ .dshm-gs-tag.warn{background:color-mix(in srgb,#b9963f 16%,transparent);color:#b9963f}
2211
+ .dshm-gs-kv{display:grid;grid-template-columns:auto 1fr;gap:5px 12px;margin:11px 0 0;font-size:11px}
2212
+ .dshm-gs-kv dt{color:var(--gs-dim)}
2213
+ .dshm-gs-kv dd{margin:0;text-align:right;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
2214
+ .dshm-gs-edge-list{display:flex;flex-direction:column;gap:7px}
2215
+ .dshm-gs-edge{border:1px solid var(--gs-border-soft);border-radius:var(--gs-radius-sm);padding:8px 9px;background:var(--gs-panel);cursor:pointer;transition:.18s}
2216
+ .dshm-gs-edge:hover{border-color:var(--gs-accent);transform:translateY(-1px)}
2217
+ .dshm-gs-edge-top{display:flex;align-items:center;justify-content:space-between;gap:6px}
2218
+ .dshm-gs-edge-arrow{font-size:11.5px;font-weight:600;overflow-wrap:anywhere;line-height:1.45}
2219
+ .dshm-gs-conf{font-size:10px;color:var(--gs-dim);font-variant-numeric:tabular-nums}
2220
+ .dshm-gs-why{margin:5px 0 0;font-size:10.5px;color:var(--gs-dim);line-height:1.5}
2221
+ .dshm-gs-meta{display:flex;flex-wrap:wrap;gap:5px;margin-top:7px;align-items:center}
2222
+ .dshm-gs-stats{display:grid;grid-template-columns:repeat(2,1fr);gap:8px}
2223
+ .dshm-gs-stat{border:1px solid var(--gs-border-soft);border-radius:var(--gs-radius-sm);padding:9px 10px;background:var(--gs-panel)}
2224
+ .dshm-gs-stat b{display:block;font-size:17px;font-weight:680;line-height:1.2;font-variant-numeric:tabular-nums}
2225
+ .dshm-gs-stat span{font-size:10.5px;color:var(--gs-dim)}
2226
+ .dshm-gs-hintbox{font-size:11px;color:var(--gs-dim);line-height:1.65;padding:10px;border:1px dashed var(--gs-border);border-radius:var(--gs-radius-sm);background:var(--gs-panel-2)}
2227
+ .dshm-gs-fold>summary{cursor:pointer;font-size:11px;color:var(--gs-dim);list-style:none}
2228
+ .dshm-gs-fold>summary::-webkit-details-marker{display:none}
2229
+ .dshm-gs-fold>summary::before{content:'▸';font-size:10px;margin-right:6px}
2230
+ .dshm-gs-fold[open]>summary::before{content:'▾'}
2231
+ /* manager */
2232
+ .dshm-gs-manager{grid-column:2/-1;grid-row:2;display:none;flex-direction:column;min-width:0;min-height:0;background:var(--gs-panel);z-index:12}
2233
+ .dshm-gs-mgr-head{flex-shrink:0;display:flex;align-items:center;gap:8px;padding:9px 12px;border-bottom:1px solid var(--gs-border);background:var(--gs-panel-2);flex-wrap:wrap}
2234
+ .dshm-gs-mgr-add{display:grid;grid-template-columns:170px auto minmax(220px,1fr) 150px max-content;gap:8px;padding:10px 12px;border-bottom:1px solid var(--gs-border);background:var(--gs-panel-2);align-items:center}
2235
+ .dshm-gs-mgr-add .dshm-gs-field,.dshm-gs-mgr-add .dshm-gs-btn{height:32px;min-width:0}
2236
+ .dshm-gs-mgr-add .dshm-gs-seg{height:32px;align-items:center}
2237
+ .dshm-gs-mgr-add .dshm-gs-seg button{height:26px}
2238
+ .dshm-gs-mgr-add textarea.dshm-gs-field{grid-column:3 / 5;height:66px;padding:7px 9px;line-height:1.45;font-family:inherit;resize:vertical}
2239
+ .dshm-gs-add-actions{display:flex;gap:8px;align-items:center;justify-content:flex-end}
2240
+ .dshm-gs-mgr-add .dshm-gs-seg button:disabled{opacity:1;cursor:default}
2241
+ .dshm-gs-mgr-add .dshm-gs-field:disabled{opacity:.75;cursor:default}
2242
+ .dshm-gs-btn:disabled{opacity:.5;cursor:not-allowed}
2243
+ .dshm-gs-btn.is-danger{color:var(--dsw-alias-state-error-primary,#c0392b);border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary,#c0392b) 55%,transparent)}
2244
+ .dshm-gs-mgr-scroll{flex:1;min-height:0;overflow:auto}
2245
+ .dshm-gs-mgr-thead,.dshm-gs-mgr-row{display:grid;grid-template-columns:26px 92px minmax(140px,1fr) 88px 88px 92px 58px 70px 156px;align-items:center;gap:8px;padding:0 14px;min-width:900px}
2246
+ .dshm-gs-mgr-ops{display:flex;gap:4px;flex-wrap:nowrap}
2247
+ .dshm-gs-mgr-thead{position:sticky;top:0;z-index:2;height:36px;background:var(--gs-panel-2);border-bottom:1px solid var(--gs-border);font-size:11px;letter-spacing:.05em;text-transform:uppercase;color:var(--gs-faint);font-weight:650}
2248
+ /* 表头必须与数据行同一种列内对齐,否则看起来整列错位 */
2249
+ .dshm-gs-mgr-thead>span{text-align:left}
2250
+ .dshm-gs-mgr-thead>span.num{text-align:right}
2251
+ .dshm-gs-mgr-row>span{text-align:left}
2252
+ .dshm-gs-mgr-row{height:42px;border-bottom:1px solid var(--gs-border-soft);font-size:12.5px;cursor:pointer}
2253
+ .dshm-gs-mgr-row:hover{background:var(--gs-accent-soft)}
2254
+ .dshm-gs-mgr-row.sel{background:var(--gs-accent-soft);box-shadow:inset 2px 0 0 var(--gs-accent)}
2255
+ .dshm-gs-mgr-id{font-family:ui-monospace,monospace;font-size:11px;color:var(--gs-dim);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
2256
+ .dshm-gs-mgr-title{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
2257
+ .dshm-gs-mgr-row .num{text-align:right;font-variant-numeric:tabular-nums;color:var(--gs-dim)}
2258
+ .dshm-gs-mgr-row .dshm-gs-mini{margin:0}
2259
+ .dshm-gs-mgr-empty{padding:28px 16px;text-align:center;color:var(--gs-dim)}
2260
+ .dshm-gs-mgr-foot{flex-shrink:0;display:flex;align-items:center;gap:8px;padding:8px 12px;border-top:1px solid var(--gs-border);background:var(--gs-panel-2);font-size:11px;color:var(--gs-dim)}
2261
+ /* status */
2262
+ .dshm-gs-status{grid-column:1/-1;grid-row:3;display:flex;align-items:center;gap:12px;padding:0 12px;border-top:1px solid var(--gs-border);background:var(--gs-panel);font-size:10px;color:var(--gs-dim);font-variant-numeric:tabular-nums;white-space:nowrap;overflow:hidden}
2263
+ .dshm-gs-status b{color:var(--gs-text);font-weight:650}
2264
+ .dshm-gs-status-sep{width:1px;height:11px;background:var(--gs-border)}
2265
+ .dshm-gs-status-right{margin-left:auto;overflow:hidden;text-overflow:ellipsis}
2266
+ .dshm-gs-live{display:inline-flex;align-items:center;gap:5px}
2267
+ .dshm-gs-live i{width:6px;height:6px;border-radius:50%;background:#36a582;box-shadow:0 0 0 3px color-mix(in srgb,#36a582 20%,transparent)}
2268
+ @media (max-width:1100px){
2269
+ .dshm-gs{grid-template-columns:46px minmax(0,1fr) 0}
2270
+ .dshm-gs-inspector{position:absolute;top:50px;right:0;bottom:28px;width:340px;box-shadow:var(--gs-shadow);z-index:25}
2271
+ .dshm-gs.is-collapsed .dshm-gs-inspector{display:none}
2272
+ .dshm-gs-search{max-width:160px}
2273
+ .dshm-gs-brand-txt small,.dshm-gs-themechip{display:none}
2274
+ }
2275
+ @media (max-width:760px){
2276
+ .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}
2277
+ .dshm-gs-topbar{grid-column:1;grid-row:1}
2278
+ .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)}
2279
+ .dshm-gs-rail-sep{width:1px;height:20px;margin:0 2px}
2280
+ .dshm-gs-rail-grow{display:none}
2281
+ .dshm-gs-stage,.dshm-gs-manager{grid-column:1;grid-row:3}
2282
+ .dshm-gs-status{grid-column:1;grid-row:4}
2283
+ .dshm-gs-inspector{top:88px;width:min(300px,92vw)}
2284
+ .dshm-gs-search,.dshm-gs-divider,.dshm-gs-popwrap{display:none}
2285
+ .dshm-gs-mgr-thead,.dshm-gs-mgr-row{grid-template-columns:20px 58px minmax(90px,1fr) 70px 64px 130px;min-width:500px}
2286
+ .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}
2287
+ }
2288
+ /* 管理视图的可调「连接分支」侧栏 */
2289
+ .dshm-gs-mgr-body{flex:1;min-height:0;display:flex;position:relative}
2290
+ .dshm-gs-mgr-body .dshm-gs-mgr-scroll{flex:1;min-width:0}
2291
+ .dshm-gs-br-resizer{width:5px;flex:0 0 5px;cursor:col-resize;background:var(--gs-border);border:0;padding:0}
2292
+ .dshm-gs-br-resizer:hover{background:var(--gs-accent)}
2293
+ .dshm-gs-branch{width:var(--gs-br-w,360px);flex:0 0 var(--gs-br-w,360px);background:var(--gs-panel);overflow:hidden;display:flex;flex-direction:column;border-left:1px solid var(--gs-border)}
2294
+ .dshm-gs-br-head{flex-shrink:0;padding:11px 13px 9px;border-bottom:1px solid var(--gs-border-soft)}
2295
+ .dshm-gs-br-head h3{margin:0 0 2px;font-size:12px;font-weight:680}
2296
+ .dshm-gs-br-head p{margin:0;font-size:10.5px;color:var(--gs-faint);line-height:1.5}
2297
+ .dshm-gs-br-body{flex:1;min-height:0;overflow-y:auto}
2298
+ .dshm-gs-br-hero{display:flex;gap:9px;align-items:flex-start;padding:11px 13px;border-bottom:1px solid var(--gs-border-soft)}
2299
+ .dshm-gs-br-hero .dshm-gs-glyph{width:28px;height:28px;font-size:13px;flex-shrink:0}
2300
+ .dshm-gs-br-hero .dshm-gs-hero-t{min-width:0;flex:1}
2301
+ .dshm-gs-br-hero .dshm-gs-hero-t b{display:block;font-size:12px;line-height:1.4;overflow-wrap:anywhere}
2302
+ .dshm-gs-br-hero .dshm-gs-hero-t span{display:block;margin-top:3px;font-size:10px;color:var(--gs-dim)}
2303
+ .dshm-gs-br-sec{padding:9px 13px}
2304
+ .dshm-gs-br-sec h4{margin:0 0 7px;font-size:10px;letter-spacing:.06em;text-transform:uppercase;color:var(--gs-faint)}
2305
+ .dshm-gs-br-item{display:flex;align-items:flex-start;gap:8px;padding:6px 0;border-bottom:1px solid var(--gs-border-soft)}
2306
+ .dshm-gs-br-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0;margin-top:4px}
2307
+ .dshm-gs-br-col{min-width:0;flex:1}
2308
+ .dshm-gs-br-nm{font-size:11.5px;line-height:1.45;overflow-wrap:anywhere;cursor:pointer}
2309
+ .dshm-gs-br-nm:hover{color:var(--gs-accent);text-decoration:underline}
2310
+ .dshm-gs-br-meta{font-size:10px;color:var(--gs-faint);line-height:1.45;overflow-wrap:anywhere}
2311
+ .dshm-gs-br-item .dshm-gs-mini{flex-shrink:0;margin-top:0}
2312
+ .dshm-gs-br-empty{padding:26px 16px;text-align:center;color:var(--gs-dim);font-size:11.5px}
2313
+ @media (max-width:760px){.dshm-gs-branch,.dshm-gs-br-resizer{display:none}}
2314
+ /* 关系图谱是沉浸式页面:解除 980px/1180px 宽度锁,可一键收起 WebUI 左导航腾满宽度 */
2315
+ .dshm-root.is-graph-wide{padding:0}
2316
+ .dshm-root.is-graph-wide .dshm-head{display:none}
2317
+ .dshm-root.is-graph-wide .dshm-page{gap:0;min-height:0}
2318
+ .dshm-root.is-graph-wide .dshm-gs{border:1px solid var(--gs-border);border-radius:var(--gs-radius);height:calc(100dvh - 96px);min-height:560px;box-shadow:var(--gs-shadow-sm)}
2319
+ /* 贴在左导航右边缘的收起小块;收起后导航缩成 20px 窄条,把手本身始终可见 */
2320
+ .dshm-root.is-graph-wide .dshm-nav-handle{position:absolute;right:0;top:50%;transform:translateY(-50%);width:20px;height:56px;display:grid;place-items:center;border:1px solid var(--gs-border);border-right:0;border-radius:8px 0 0 8px;background:var(--gs-panel);color:var(--gs-dim);font-size:15px;z-index:30;box-shadow:var(--gs-shadow-sm)}
2321
+ .dshm-root.is-graph-wide .dshm-nav-handle:hover{color:var(--gs-accent);border-color:var(--gs-accent)}
2322
+ /* 收起/展开要有过渡;窄条状态下隐藏外壳的“记忆工作室”竖排小字 */
2323
+ .dshm-root.is-graph-wide .dshm-nav{transition:width .22s ease,min-width .22s ease,padding .22s ease}
2324
+ .dshm-root.is-graph-wide .dshm-shell{transition:grid-template-columns .22s ease}
2325
+ html[data-standalone] .stage{transition:padding-left .22s ease,padding-right .22s ease}
2326
+ /* 关系图谱独占一屏:内容区只留 8px 呼吸,隐藏外壳 footer,工作台整体上移并加高 */
2327
+ html[data-standalone]:has(.dshm-root.is-graph-wide) .stage{padding-top:8px;padding-bottom:8px}
2328
+ html[data-standalone]:has(.dshm-root.is-graph-wide) .foot{display:none}
2329
+ .dshm-root.is-graph-navless .dshm-nav::before{display:none}
2330
+ /* 宿主内嵌:左导航是 grid 的一列,收起后只剩窄条 */
2331
+ .dshm-root.is-graph-wide .dshm-shell{display:grid;max-width:none;gap:0;grid-template-columns:158px minmax(0,1fr);align-items:stretch;width:100%}
2332
+ .dshm-root.is-graph-navless .dshm-shell{grid-template-columns:20px minmax(0,1fr)}
2333
+ .dshm-root.is-graph-navless .dshm-nav{display:flex;width:20px;min-width:20px;padding:0;overflow:visible}
2334
+ .dshm-root.is-graph-navless .dshm-nav>*:not(.dshm-nav-handle){display:none}
2335
+ .dshm-root.is-graph-navless .dshm-nav-handle{border-right:1px solid var(--gs-border);border-radius:0}
2336
+ /* 独立 WebUI:外壳本来是 block + 固定左栏,只需解除内容列上限 */
2337
+ html[data-standalone] .dshm-root.is-graph-wide .dshm-shell{display:block;max-width:none}
2338
+ html[data-standalone] .dshm-root.is-graph-wide .dshm-page{max-width:none;margin:0}
2339
+ html[data-standalone] .dshm-root.is-graph-navless .dshm-nav{width:20px;min-width:20px;padding:0;overflow:visible}
2340
+ html[data-standalone]:has(.dshm-root.is-graph-navless) .stage{padding-left:28px;padding-right:16px}
2341
+ .dshm-root.is-graph-wide[data-dshm-surface="sidebar"] .dshm-shell{display:flex;flex-direction:column;height:100%;min-height:0;max-width:none}
2342
+ .dshm-root.is-graph-wide[data-dshm-surface="sidebar"] .dshm-page{flex:1;min-height:0;overflow:hidden}
2343
+ .dshm-root.is-graph-wide[data-dshm-surface="sidebar"] .dshm-gs{height:100%;min-height:0}
1875
2344
  /* The sidebar's context-scope form: a collapsed card instead of four bare
1876
2345
  inputs and a browser-default button. */
1877
2346
  .dshm-scope{width:100%;margin:0 0 10px;border:1px solid var(--dsw-alias-border-l1,#ddd);border-radius:12px;background:var(--dsw-alias-bg-layer-2,rgba(127,127,127,.05));overflow:hidden;flex-shrink:0}
@@ -2624,17 +3093,23 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2624
3093
  return graphModulePromise
2625
3094
  }
2626
3095
 
2627
- function GraphCanvas({ graph, focus, onFocus, t }) {
3096
+ // chrome=false 时外壳(rail / 参数弹层 / 状态栏)由 Graph Studio 工作台自己画,
3097
+ // 画布与引擎保持同一份实现:拖动、pin、弹簧链、簇作用域都不变。
3098
+ function GraphCanvas({ graph, focus, onFocus, t, chrome = true, options: controlledOptions = null,
3099
+ apiRef = null, onZoom = null }) {
2628
3100
  const ref = React.useRef(null)
2629
3101
  const tooltipRef = React.useRef(null)
2630
3102
  const viewRef = React.useRef(null)
2631
3103
  const latest = React.useRef({ graph, focus, onFocus, t })
2632
3104
  latest.current = { graph, focus, onFocus, t }
3105
+ const zoomNotify = React.useRef(onZoom)
3106
+ zoomNotify.current = onZoom
2633
3107
  const [zoom, setZoom] = React.useState(1)
2634
3108
  const [settingsOpen, setSettingsOpen] = React.useState(false)
2635
- const [options, setOptions] = React.useState({ repulsion: 120, distance: 100, labels: true, motion: true })
2636
- const optionsRef = React.useRef(options)
2637
- optionsRef.current = options
3109
+ const [options, setOptions] = React.useState({ repulsion: 120, distance: 100, center: 0, labels: true, motion: true })
3110
+ const effectiveOptions = controlledOptions || options
3111
+ const optionsRef = React.useRef(effectiveOptions)
3112
+ optionsRef.current = effectiveOptions
2638
3113
  const [loadError, setLoadError] = React.useState(false)
2639
3114
  const [attempt, setAttempt] = React.useState(0)
2640
3115
  React.useEffect(() => {
@@ -2646,41 +3121,62 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2646
3121
  if (disposed) return
2647
3122
  const view = module.createGraphView(canvas, {
2648
3123
  onFocus: id => latest.current.onFocus(id),
2649
- onZoom: setZoom,
3124
+ onZoom: value => { setZoom(value); zoomNotify.current?.(value) },
2650
3125
  tooltip: tooltipRef.current,
2651
3126
  reducedMotion: window.matchMedia?.('(prefers-reduced-motion: reduce)').matches,
2652
3127
  emptyLabel: latest.current.t('graphEmpty'),
2653
3128
  })
2654
3129
  viewRef.current = view
3130
+ // 只读句柄:浏览器验收与状态栏需要问「现在有几个节点被右键锁定」。
3131
+ canvas.__dshmGraphView = view
2655
3132
  view.configure(optionsRef.current)
2656
3133
  view.update(latest.current.graph, latest.current.focus)
2657
3134
  }).catch(() => { if (!disposed) setLoadError(true) })
2658
3135
  return () => {
2659
3136
  disposed = true
2660
3137
  viewRef.current?.dispose(); viewRef.current = null
3138
+ try { delete canvas.__dshmGraphView } catch {}
2661
3139
  }
2662
3140
  }, [attempt])
2663
3141
  React.useEffect(() => { viewRef.current?.update(graph, focus) }, [graph, focus])
2664
- React.useEffect(() => { viewRef.current?.configure(options) }, [options])
3142
+ React.useEffect(() => { viewRef.current?.configure(effectiveOptions) }, [effectiveOptions])
3143
+ React.useEffect(() => {
3144
+ if (!apiRef) return undefined
3145
+ apiRef.current = {
3146
+ zoom: factor => viewRef.current?.zoom(factor),
3147
+ fit: () => viewRef.current?.fit(),
3148
+ unpinAll: () => viewRef.current?.unpinAll?.(),
3149
+ relayout: () => viewRef.current?.relayout?.(),
3150
+ exportPng: () => ref.current?.toDataURL?.('image/png') || '',
3151
+ }
3152
+ return () => { apiRef.current = null }
3153
+ }, [apiRef])
2665
3154
  const icon = (label, text, action, extra = {}) => h('button', {
2666
3155
  type: 'button', className: 'dshm-graph-icon', title: t(label), 'aria-label': t(label), onClick: action, ...extra,
2667
3156
  }, text)
2668
3157
  return h('div', { className: 'dshm-graph-viewport' },
2669
- h('div', { className: 'dshm-graph-toolbar' },
3158
+ chrome ? h('div', { className: 'dshm-graph-toolbar' },
2670
3159
  icon('graphZoomOut', '-', () => viewRef.current?.zoom(.8)),
2671
3160
  h('output', { className: 'dshm-graph-scale', 'aria-label': t('graphView') }, Math.round(zoom * 100) + '%'),
2672
3161
  icon('graphZoomIn', '+', () => viewRef.current?.zoom(1.25)),
2673
3162
  icon('graphFit', '⛶', () => viewRef.current?.fit()),
2674
- icon('graphOptions', h(GlyphSliders), () => setSettingsOpen(value => !value), { 'aria-expanded': settingsOpen })),
2675
- settingsOpen ? h('div', { className: 'dshm-graph-options' },
2676
- [['repulsion', 'graphRepulsion', 30, 350], ['distance', 'graphDistance', 40, 220]].map(([key, label, min, max]) =>
2677
- h('label', { key }, t(label), h('input', { type: 'range', min, max, step: 5, value: options[key],
3163
+ icon('graphUnpinAll', '⊙', () => viewRef.current?.unpinAll?.()),
3164
+ icon('graphRelayout', '↻', () => viewRef.current?.relayout?.()),
3165
+ icon('graphOptions', h(GlyphSliders), () => setSettingsOpen(value => !value), { 'aria-expanded': settingsOpen })) : null,
3166
+ chrome && settingsOpen ? h('div', { className: 'dshm-graph-options' },
3167
+ [['repulsion', 'graphRepulsion', 30, 350, 5], ['distance', 'graphDistance', 40, 220, 5],
3168
+ ['center', 'graphCenter', 0, 3, .05]].map(([key, label, min, max, step]) =>
3169
+ h('label', { key }, t(label), h('input', { type: 'range', min, max, step, value: options[key],
3170
+ 'aria-label': t(label), title: t(label),
2678
3171
  onChange: event => setOptions(value => ({ ...value, [key]: Number(event.target.value) })) }))),
2679
3172
  [['labels', 'graphLabels'], ['motion', 'graphMotion']].map(([key, label]) =>
2680
3173
  h('div', { key, style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 10 } },
2681
3174
  h('span', null, t(label)),
2682
3175
  h(Toggle, { checked: options[key] === true, label: t(label),
2683
- onChange: value => setOptions(current => ({ ...current, [key]: value })) })))) : null,
3176
+ onChange: value => setOptions(current => ({ ...current, [key]: value })) }))),
3177
+ h('div', { className: 'dshm-graph-actions' },
3178
+ h(Button, { title: t('graphUnpinAll'), onClick: () => viewRef.current?.unpinAll?.() }, t('graphUnpinAll')),
3179
+ h(Button, { title: t('graphRelayout'), onClick: () => viewRef.current?.relayout?.() }, t('graphRelayout')))) : null,
2684
3180
  h('canvas', { ref, className: 'dshm-graph-canvas', role: 'img', tabIndex: 0, 'aria-label': t('graphView') }),
2685
3181
  h('div', { ref: tooltipRef, className: 'dshm-graph-tooltip', hidden: true, 'aria-hidden': true }),
2686
3182
  loadError ? h('div', { className: 'dshm-graph-error', role: 'alert' },
@@ -2738,6 +3234,689 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2738
3234
  // 关系图的库选择器里,全局记忆不是一个私有库;用一个不可能与库 id 冲突的
2739
3235
  // 占位值走同一套选择控件,避免再加一排 scope 按钮。
2740
3236
  const GLOBAL_GRAPH_ID = '__global__'
3237
+ // Graph Studio 工作台:界面按 graph-studio/index.html 逐块复刻(顶栏 / 竖排工具 /
3238
+ // 画布浮动控件 / 检视面板 / 管理表格 / 状态栏),尺寸按 WebUI 收敛、颜色走 DSH
3239
+ // token 跟随宿主明暗。数据仍走插件 getGraph/listEntities,画布仍是 GraphCanvas +
3240
+ // 自研引擎,所以节点连接、拖动即固定、弹簧链、簇作用域这些手感一个都没改。
3241
+ const GS_NODE_COLORS = Object.freeze({
3242
+ memory: '#618fcd', must: '#d97768', short: '#8a93a6', entity: '#36a582',
3243
+ provisional: '#b9963f', global: '#8b7bd8', missing: '#92959c',
3244
+ })
3245
+ const gsKind = node => node.missing ? 'missing'
3246
+ : node.kind === 'global' ? 'global'
3247
+ : node.kind !== 'memory' ? (node.status === 'provisional' ? 'provisional' : 'entity') : 'memory'
3248
+ const gsColor = node => GS_NODE_COLORS[gsKind(node)]
3249
+
3250
+ function GraphStudioMinimap({ active, t }) {
3251
+ const ref = React.useRef(null)
3252
+ React.useEffect(() => {
3253
+ if (!active || typeof document === 'undefined') return undefined
3254
+ const paint = () => {
3255
+ const target = ref.current
3256
+ if (!target?.getContext) return
3257
+ const source = document.querySelector('.dshm-gs-stage canvas.dshm-graph-canvas')
3258
+ const context = target.getContext('2d')
3259
+ if (!source || !context) return
3260
+ context.clearRect(0, 0, target.width, target.height)
3261
+ try { context.drawImage(source, 0, 0, target.width, target.height) } catch {}
3262
+ }
3263
+ paint()
3264
+ const timer = setInterval(paint, 600)
3265
+ return () => clearInterval(timer)
3266
+ }, [active])
3267
+ return h('div', { className: 'dshm-gs-minimap' },
3268
+ h('h4', null, t('gsMinimap')),
3269
+ h('canvas', { ref, width: 158, height: 104, 'aria-label': t('gsMinimap') }))
3270
+ }
3271
+
3272
+ // 规则筛选读显示层 rule。老版本插件的自动边没有 evidence.rule(handoff: 旧
3273
+ // suppression 键就是 'auto'),这里按 source==='auto' 兜底成 'auto' 桶——
3274
+ // 这样新客户端配旧后端/旧数据也不会出现「一条规则都没有」;新写入带真实规则。
3275
+ const GS_RULE_LABEL_KEYS = Object.freeze({
3276
+ 'entity-mention': 'gsRuleMention', conflict: 'gsRuleConflict', supersede: 'gsRuleSupersede',
3277
+ 'fact-key': 'gsRuleFactKey', 'worker-quote': 'gsRuleWorkerQuote', auto: 'gsRuleAuto',
3278
+ })
3279
+ const graphRuleOf = edge => edge.rule || (edge.source === 'auto' ? 'auto' : null)
3280
+ const graphRuleText = (rule, t) => GS_RULE_LABEL_KEYS[rule] ? t(GS_RULE_LABEL_KEYS[rule]) : String(rule)
3281
+
3282
+ function GraphStudioPanel({ call, libraries, revision, stamp, t, navHidden = false, onToggleNav = null }) {
3283
+ const [graphLib, setGraphLib] = React.useState('')
3284
+ // 默认落在有数据的私有库:全局图常常是空的,一进页面就空白会让人以为图坏了。
3285
+ const firstPrivate = libraries[0]?.id || ''
3286
+ const graphLibrary = graphLib === GLOBAL_GRAPH_ID ? GLOBAL_GRAPH_ID
3287
+ : (graphLib && libraries.some(lib => lib.id === graphLib) ? graphLib : (firstPrivate || GLOBAL_GRAPH_ID))
3288
+ const showGlobal = graphLibrary === GLOBAL_GRAPH_ID
3289
+ const [graph, setGraph] = React.useState({ nodes: [], edges: [] })
3290
+ const [entities, setEntities] = React.useState([])
3291
+ const [focus, setFocus] = React.useState('')
3292
+ const [error, setError] = React.useState('')
3293
+ const [view, setView] = React.useState('graph')
3294
+ const [query, setQuery] = React.useState('')
3295
+ const [source, setSource] = React.useState('all')
3296
+ const [rulesOff, setRulesOff] = React.useState(() => new Set())
3297
+ const [ruleOpen, setRuleOpen] = React.useState(false)
3298
+ const [legendOpen, setLegendOpen] = React.useState(false)
3299
+ const [forceOpen, setForceOpen] = React.useState(false)
3300
+ const [minimap, setMinimap] = React.useState(false)
3301
+ const [grid, setGrid] = React.useState(true)
3302
+ const [labels, setLabels] = React.useState(true)
3303
+ const [motion, setMotion] = React.useState(true)
3304
+ const [forces, setForces] = React.useState({ repulsion: 120, distance: 100, center: 0 })
3305
+ // 窄屏下检视面板是覆盖层,会挡住画布;默认收起,画布优先。
3306
+ const [inspectorOpen, setInspectorOpen] = React.useState(() =>
3307
+ typeof window === 'undefined' || typeof window.matchMedia !== 'function'
3308
+ ? true : !window.matchMedia('(max-width: 1100px)').matches)
3309
+ const [zoom, setZoom] = React.useState(1)
3310
+ const [toast, setToast] = React.useState('')
3311
+ const [mgrKind, setMgrKind] = React.useState('')
3312
+ const [mgrStatus, setMgrStatus] = React.useState('')
3313
+ const [mgrSort, setMgrSort] = React.useState('degree')
3314
+ const [mgrSelected, setMgrSelected] = React.useState('')
3315
+ const [branchWidth, setBranchWidth] = React.useState(360)
3316
+ // 管理视图的增删节点:新增走 addMemory / createEntity,删除两段确认。
3317
+ const [mgrBusy, setMgrBusy] = React.useState(false)
3318
+ const [mgrArmed, setMgrArmed] = React.useState('')
3319
+ const [mgrDeleteRefused, setMgrDeleteRefused] = React.useState('')
3320
+ const [reloadKey, setReloadKey] = React.useState(0)
3321
+ const [addOpen, setAddOpen] = React.useState(false)
3322
+ const [addLib, setAddLib] = React.useState('')
3323
+ const [draft, setDraft] = React.useState({ type: 'memory', title: '', content: '', layer: 'long_term', name: '', kind: 'person' })
3324
+ // 编辑已有节点:记忆读 getMemory 取完整正文,实体读 listEntities 取别名;
3325
+ // 两者都与新增表单互斥,共用同一套网格样式。
3326
+ const [editBusy, setEditBusy] = React.useState(false)
3327
+ const [editOpen, setEditOpen] = React.useState(false)
3328
+ const [editDraft, setEditDraft] = React.useState(null)
3329
+ // 「全部记忆库」合并的是各私有库,新增必须选目标库;没有私有库时落到全局索引,只读。
3330
+ const mergedScope = showGlobal && libraries.length > 0
3331
+ const writable = !showGlobal || mergedScope
3332
+ const addTargetLib = mergedScope ? (addLib || libraries[0]?.id || '') : (showGlobal ? '' : graphLibrary)
3333
+ const apiRef = React.useRef(null)
3334
+ const searchRef = React.useRef(null)
3335
+ const beat = `${revision ?? ''}:${stamp ?? ''}`
3336
+ const notify = message => setToast(message)
3337
+
3338
+ // 一切轮询仍走 SettingsPage 的心跳:revision/stamp 变动才重新取数。
3339
+ React.useEffect(() => {
3340
+ let alive = true
3341
+ const load = async () => {
3342
+ try {
3343
+ if (showGlobal && libraries.length) {
3344
+ // 「全部记忆库」= 合并每个私有库的图,和 MemU 记忆页的「全部记忆库」口径一致。
3345
+ const results = await Promise.all(libraries.map(lib =>
3346
+ call('getGraph', { libraryId: lib.id, focusId: null, depth: 2, limit: 200 }).catch(() => null)))
3347
+ const nodes = new Map(), edges = new Map()
3348
+ for (let i = 0; i < results.length; i++) {
3349
+ const value = results[i], lib = libraries[i]
3350
+ // 合并视图下节点要记住来源库:管理视图的删除必须有 libraryId。
3351
+ for (const node of value?.nodes || []) if (!nodes.has(node.id)) nodes.set(node.id, { ...node, libraryId: lib.id })
3352
+ for (const edge of value?.edges || []) edges.set(`${edge.from}|${edge.to}|${edge.kind || ''}`, edge)
3353
+ }
3354
+ if (!alive) return
3355
+ setGraph({ nodes: [...nodes.values()], edges: [...edges.values()] })
3356
+ } else {
3357
+ const payload = showGlobal
3358
+ ? { scope: 'global', focusId: focus || null, depth: 2, limit: 200 }
3359
+ : { libraryId: graphLibrary, focusId: focus || null, depth: 2, limit: 200 }
3360
+ const value = await call('getGraph', payload)
3361
+ if (!alive) return
3362
+ setGraph(value && Array.isArray(value.nodes)
3363
+ ? { nodes: value.nodes, edges: value.edges || [] } : { nodes: [], edges: [] })
3364
+ }
3365
+ setError('')
3366
+ } catch (failure) { if (alive) setError(String(failure?.message || failure)) }
3367
+ }
3368
+ void load()
3369
+ return () => { alive = false }
3370
+ }, [call, graphLibrary, showGlobal, focus, beat, reloadKey, libraries.length, libraries.map(lib => lib.id).join(',')])
3371
+ React.useEffect(() => {
3372
+ if (showGlobal) { setEntities([]); return undefined }
3373
+ let alive = true
3374
+ void call('listEntities', { libraryId: graphLibrary })
3375
+ .then(value => { if (alive) setEntities(value?.items || []) })
3376
+ .catch(() => { if (alive) setEntities([]) })
3377
+ return () => { alive = false }
3378
+ }, [call, graphLibrary, showGlobal, beat, reloadKey])
3379
+ React.useEffect(() => {
3380
+ if (!toast) return undefined
3381
+ const timer = setTimeout(() => setToast(''), 2200)
3382
+ return () => clearTimeout(timer)
3383
+ }, [toast])
3384
+ // 破坏性操作 = 二次点击,2.5s 未确认自动复原(§7.3)。
3385
+ React.useEffect(() => {
3386
+ if (!mgrArmed) return undefined
3387
+ const timer = setTimeout(() => { setMgrArmed(''); setMgrDeleteRefused('') }, 2500)
3388
+ return () => clearTimeout(timer)
3389
+ }, [mgrArmed])
3390
+ React.useEffect(() => {
3391
+ if (typeof document === 'undefined' || !document.addEventListener) return undefined
3392
+ const onKey = event => {
3393
+ const tag = event.target?.tagName
3394
+ if (tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA') return
3395
+ if (event.key === '/') { event.preventDefault(); searchRef.current?.focus?.() }
3396
+ else if (event.key === 'f' || event.key === 'F') apiRef.current?.fit?.()
3397
+ }
3398
+ document.addEventListener('keydown', onKey)
3399
+ return () => document.removeEventListener('keydown', onKey)
3400
+ }, [])
3401
+
3402
+ const nodes = graph.nodes || [], edges = graph.edges || []
3403
+ const nodeIds = React.useMemo(() => new Set(nodes.map(node => node.id)), [graph])
3404
+ const degree = React.useMemo(() => {
3405
+ const map = new Map()
3406
+ for (const edge of edges) {
3407
+ map.set(edge.from, (map.get(edge.from) || 0) + 1)
3408
+ map.set(edge.to, (map.get(edge.to) || 0) + 1)
3409
+ }
3410
+ return map
3411
+ }, [graph])
3412
+ const rules = React.useMemo(() => [...new Set(edges.map(graphRuleOf).filter(Boolean))].sort(), [graph])
3413
+ const q = query.trim().toLowerCase()
3414
+ const visibleEdges = React.useMemo(() => {
3415
+ const matched = new Set(q ? nodes.filter(node => String(node.title || node.id).toLowerCase().includes(q))
3416
+ .map(node => node.id) : [])
3417
+ return edges.filter(edge => {
3418
+ if (edge.from === edge.to || !nodeIds.has(edge.from) || !nodeIds.has(edge.to)) return false
3419
+ if (source === 'auto' && edge.source !== 'auto') return false
3420
+ if (source === 'manual' && edge.source === 'auto') return false
3421
+ const rule = graphRuleOf(edge)
3422
+ if (rule && rulesOff.has(rule)) return false
3423
+ if (q && !matched.has(edge.from) && !matched.has(edge.to)) return false
3424
+ return true
3425
+ })
3426
+ }, [graph, q, source, rulesOff, nodeIds])
3427
+ const canvasGraph = React.useMemo(() => ({ nodes, edges: visibleEdges }), [graph, visibleEdges])
3428
+ // 搜索词透传给画布:匹配节点会被高亮,边筛选仍在工作台侧完成。
3429
+ const canvasOptions = React.useMemo(() => ({ ...forces, labels, motion, grid, query: q }),
3430
+ [forces, labels, motion, grid, q])
3431
+ const titles = React.useMemo(() => new Map(nodes.map(node => [node.id, node.title || node.id])), [graph])
3432
+ const panelFiles = React.useMemo(() => nodes.map(node => ({ id: node.id, title: node.title || node.id })), [graph])
3433
+ const selected = nodes.find(node => node.id === focus) || null
3434
+ const focusEdges = edges.filter(edge => edge.from === focus || edge.to === focus)
3435
+ const autoCount = edges.filter(edge => edge.source === 'auto').length
3436
+ const pendingCount = nodes.filter(node => node.status === 'provisional').length
3437
+ const manageRows = React.useMemo(() => nodes.filter(node => {
3438
+ if (q && !String(node.title || node.id).toLowerCase().includes(q)) return false
3439
+ if (mgrKind && node.kind !== mgrKind) return false
3440
+ if (mgrStatus && (node.status || 'confirmed') !== mgrStatus) return false
3441
+ return true
3442
+ }).sort((a, b) => mgrSort === 'degree' ? (degree.get(b.id) || 0) - (degree.get(a.id) || 0)
3443
+ : mgrSort === 'strength' ? (Number(b.strength) || 0) - (Number(a.strength) || 0)
3444
+ : String(mgrSort === 'id' ? a.id : a.title || a.id).localeCompare(String(mgrSort === 'id' ? b.id : b.title || b.id))),
3445
+ [graph, q, mgrKind, mgrStatus, mgrSort, degree])
3446
+
3447
+ const railBtn = (label, text, action, pressed) => h('button', {
3448
+ type: 'button', title: t(label), 'aria-label': t(label),
3449
+ 'aria-pressed': pressed === undefined ? undefined : String(pressed), onClick: action,
3450
+ }, text)
3451
+ const segBtn = (label, value, current, action) => h('button', {
3452
+ type: 'button', 'aria-pressed': String(current === value), onClick: () => action(value),
3453
+ }, t(label))
3454
+ const toggleRule = rule => setRulesOff(current => {
3455
+ const next = new Set(current)
3456
+ if (next.has(rule)) next.delete(rule); else next.add(rule)
3457
+ return next
3458
+ })
3459
+ const exportPng = () => {
3460
+ const url = apiRef.current?.exportPng?.()
3461
+ if (!url || typeof document === 'undefined') return
3462
+ const link = document.createElement('a')
3463
+ link.href = url; link.download = 'relationship-graph.png'
3464
+ document.body?.appendChild?.(link); link.click?.(); link.remove?.()
3465
+ notify(t('gsExport'))
3466
+ }
3467
+ const fit = () => apiRef.current?.fit?.()
3468
+ const zoomBy = factor => apiRef.current?.zoom?.(factor)
3469
+ // 增删节点:记忆走 addMemory(事实级去重会返回 deduped),实体走 createEntity
3470
+ // (RPC 层强制 confirmed 并补提及边)。写入后立即重取图,不等心跳。
3471
+ const removeKey = mgrSelected ? 'remove:' + mgrSelected : ''
3472
+ const canAdd = writable && Boolean(addTargetLib) && !mgrBusy
3473
+ && (draft.type === 'memory' ? Boolean(draft.content.trim()) : Boolean(draft.name.trim()))
3474
+ const canSave = Boolean(editDraft) && !editBusy
3475
+ && (editDraft.kind === 'memory' ? Boolean(editDraft.content.trim()) : Boolean(editDraft.name.trim()))
3476
+ // updateMemory 只支持 short_term→long_term 升级与 must_remember 降级;
3477
+ // 提升到 must_remember 必须走带 pin 理由的写入口,这里不提供。
3478
+ const editLayers = !editDraft || editDraft.kind !== 'memory' ? []
3479
+ : editDraft.layer === 'must_remember' ? ['must_remember', 'long_term']
3480
+ : editDraft.layer === 'short_term' ? ['short_term', 'long_term'] : ['long_term']
3481
+ const addNode = async () => {
3482
+ if (!canAdd) return
3483
+ setMgrBusy(true)
3484
+ try {
3485
+ if (draft.type === 'entity') {
3486
+ const name = draft.name.trim()
3487
+ const entity = await call('createEntity', { libraryId: addTargetLib, name, kind: draft.kind })
3488
+ notifyMemoryWrite('relation', addTargetLib)
3489
+ setMgrSelected(entity?.id || '')
3490
+ setDraft(value => ({ ...value, name: '' }))
3491
+ notify(t('gsNodeCreated').replace('{name}', name))
3492
+ } else {
3493
+ const payload = { libraryId: addTargetLib, content: draft.content.trim(), title: draft.title.trim() || undefined, layer: draft.layer }
3494
+ if (draft.layer === 'must_remember') { payload.pinReason = 'user_explicit_note'; payload.pinSource = 'user_explicit' }
3495
+ const created = await call('addMemory', payload)
3496
+ if (created?.deduped === true) {
3497
+ notify(t('dedupedNotice').replace('{id}', created.existingId || '?'))
3498
+ return
3499
+ }
3500
+ notifyMemoryWrite('memory', addTargetLib)
3501
+ setMgrSelected(created?.id || '')
3502
+ setDraft(value => ({ ...value, title: '', content: '' }))
3503
+ notify(t('memorySaved'))
3504
+ }
3505
+ setReloadKey(value => value + 1)
3506
+ } catch (failure) { notify(String(failure?.message || failure)) } finally { setMgrBusy(false) }
3507
+ }
3508
+ const removeSelected = async () => {
3509
+ const node = mgrSelected ? nodes.find(item => item.id === mgrSelected) : null
3510
+ const libraryId = node?.libraryId || (showGlobal ? '' : graphLibrary)
3511
+ if (!node || !libraryId || !writable || mgrBusy) return
3512
+ if (mgrArmed !== removeKey) { setMgrArmed(removeKey); return }
3513
+ setMgrBusy(true)
3514
+ try {
3515
+ if (node.kind === 'memory') {
3516
+ // 永久删除只接受已归档条目:先归档再删;两段确认已由按钮承担。
3517
+ await call('archiveMemory', { libraryId, id: node.id })
3518
+ await call('deleteMemory', { libraryId, id: node.id, confirmed: true })
3519
+ notifyMemoryWrite('memory', libraryId)
3520
+ notify(t('memoryDeleted'))
3521
+ } else {
3522
+ await call('deleteEntity', { libraryId, entityId: node.id, force: mgrDeleteRefused === node.id })
3523
+ notifyMemoryWrite('relation', libraryId)
3524
+ notify(t('gsNodeDeleted'))
3525
+ }
3526
+ setMgrArmed(''); setMgrDeleteRefused(''); setMgrSelected('')
3527
+ setEditOpen(false); setEditDraft(null)
3528
+ if (focus === node.id) setFocus('')
3529
+ setReloadKey(value => value + 1)
3530
+ } catch (failure) {
3531
+ const message = String(failure?.message || failure)
3532
+ // 实体仍被引用:保留 armed,再点一次升级为 force(连同引用一起删)。
3533
+ if (/referenced|引用/.test(message)) setMgrDeleteRefused(node.id)
3534
+ notify(message)
3535
+ } finally { setMgrBusy(false) }
3536
+ }
3537
+ // 编辑已有节点:先读完整数据再开表单,避免拿节点摘要当正文保存。
3538
+ const editNode = async () => {
3539
+ const node = mgrSelected ? nodes.find(item => item.id === mgrSelected) : null
3540
+ const libraryId = node?.libraryId || (showGlobal ? '' : graphLibrary)
3541
+ if (!node || !libraryId || !writable || editBusy) return
3542
+ setEditBusy(true)
3543
+ try {
3544
+ if (node.kind === 'memory') {
3545
+ const loaded = await call('getMemory', { libraryId, id: node.id })
3546
+ const entry = loaded?.entry || {}
3547
+ setEditDraft({ id: node.id, kind: 'memory', libraryId,
3548
+ title: entry.title || '', content: entry.content || '', layer: entry.layer || 'long_term' })
3549
+ } else {
3550
+ const list = await call('listEntities', { libraryId })
3551
+ const found = (list?.items || []).find(item => item.id === node.id) || {}
3552
+ setEditDraft({ id: node.id, kind: 'entity', libraryId,
3553
+ name: found.name || node.title || '', aliases: (found.aliases || []).join(', ') })
3554
+ }
3555
+ setAddOpen(false)
3556
+ setEditOpen(true)
3557
+ } catch (failure) { notify(String(failure?.message || failure)) } finally { setEditBusy(false) }
3558
+ }
3559
+ const saveEdit = async () => {
3560
+ if (!canSave) return
3561
+ setEditBusy(true)
3562
+ try {
3563
+ if (editDraft.kind === 'memory') {
3564
+ const patch = { content: editDraft.content.trim(), layer: editDraft.layer }
3565
+ const title = editDraft.title.trim()
3566
+ if (title) patch.title = title
3567
+ await call('updateMemory', { libraryId: editDraft.libraryId, id: editDraft.id, patch })
3568
+ notifyMemoryWrite('memory', editDraft.libraryId)
3569
+ } else {
3570
+ // renameEntity 的 aliases 是整体替换:必须带上当前列表,否则会被清空。
3571
+ const aliases = String(editDraft.aliases || '').split(',').map(value => value.trim()).filter(Boolean)
3572
+ await call('renameEntity', { libraryId: editDraft.libraryId, entityId: editDraft.id,
3573
+ name: editDraft.name.trim(), aliases })
3574
+ notifyMemoryWrite('relation', editDraft.libraryId)
3575
+ }
3576
+ notify(t('saved'))
3577
+ setEditOpen(false); setEditDraft(null)
3578
+ setReloadKey(value => value + 1)
3579
+ } catch (failure) { notify(String(failure?.message || failure)) } finally { setEditBusy(false) }
3580
+ }
3581
+
3582
+ const topbar = h('header', { className: 'dshm-gs-topbar' },
3583
+ h('div', { className: 'dshm-gs-brand' },
3584
+ h('div', { className: 'dshm-gs-mark', 'aria-hidden': 'true' }, 'M'),
3585
+ h('div', { className: 'dshm-gs-brand-txt' },
3586
+ h('strong', null, t('pageGraph')), h('small', null, 'GRAPH STUDIO'))),
3587
+ h('div', { className: 'dshm-gs-divider' }),
3588
+ h('div', { className: 'dshm-gs-seg', role: 'group', 'aria-label': t('pageGraph') },
3589
+ segBtn('graphView', 'graph', view, setView), segBtn('gsManage', 'manage', view, setView)),
3590
+ h('select', {
3591
+ className: 'dshm-gs-field', value: graphLibrary,
3592
+ title: showGlobal ? t('gsAllLibraries') : (libraries.find(lib => lib.id === graphLibrary)?.scopeKey || t('currentLibrary')),
3593
+ 'aria-label': t('currentLibrary'), onChange: event => setGraphLib(event.target.value),
3594
+ },
3595
+ h('option', { value: GLOBAL_GRAPH_ID }, t('gsAllLibraries')),
3596
+ libraries.map(lib => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries)))),
3597
+ h('label', { className: 'dshm-gs-search' },
3598
+ h('span', { className: 'dshm-gs-search-icon', 'aria-hidden': 'true' }, '⌕'),
3599
+ h('input', { ref: searchRef, className: 'dshm-gs-field', type: 'search', value: query,
3600
+ placeholder: t('gsSearch'), 'aria-label': t('gsSearch'),
3601
+ onChange: event => setQuery(event.target.value) })),
3602
+ h('div', { className: 'dshm-gs-seg', role: 'group', 'aria-label': t('gsRules') },
3603
+ segBtn('edgeFilterAll', 'all', source, setSource),
3604
+ segBtn('edgeFilterAuto', 'auto', source, setSource),
3605
+ segBtn('edgeFilterManual', 'manual', source, setSource)),
3606
+ h('div', { className: 'dshm-gs-popwrap' },
3607
+ h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsRules'), 'aria-label': t('gsRules'),
3608
+ 'aria-expanded': String(ruleOpen), onClick: () => setRuleOpen(value => !value) },
3609
+ t('gsRules'), h('span', { className: 'dshm-gs-count' }, `${rules.length - rulesOff.size}/${rules.length}`)),
3610
+ ruleOpen ? h('div', { className: 'dshm-gs-pop is-open' }, h('h4', null, t('gsRules')),
3611
+ rules.length ? rules.map(rule => h('label', { key: rule },
3612
+ h('input', { type: 'checkbox', checked: !rulesOff.has(rule), onChange: () => toggleRule(rule) }), graphRuleText(rule, t)))
3613
+ : h('p', { className: 'dshm-gs-pop-empty' }, t('gsNoRules'))) : null),
3614
+ h('div', { className: 'dshm-gs-spacer' }),
3615
+ h('span', { className: 'dshm-gs-themechip', 'aria-pressed': 'true' },
3616
+ h('i', { className: 'dshm-gs-dot' }), t('gsLocalData')),
3617
+ h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsExport'), onClick: exportPng }, t('gsExport')),
3618
+ h('button', { type: 'button', className: 'dshm-gs-btn dshm-gs-icon', title: t('gsCollapse'),
3619
+ 'aria-label': t('gsCollapse'), onClick: () => setInspectorOpen(value => !value) }, '⇥'))
3620
+
3621
+ // 力参数弹层贴在 rail 的「图谱设置」按钮正右边,而不是画布右下角。
3622
+ const forcePop = h('div', { className: 'dshm-gs-forcepop is-open' },
3623
+ h('h4', null, t('gsForce')),
3624
+ [['repulsion', 'graphRepulsion', 30, 350, 5], ['distance', 'graphDistance', 40, 220, 5],
3625
+ ['center', 'graphCenter', 0, 3, .05]].map(([key, label, min, max, step]) =>
3626
+ h('label', { key }, t(label),
3627
+ h('input', { type: 'range', min, max, step, value: forces[key], title: t(label), 'aria-label': t(label),
3628
+ onChange: event => setForces(value => ({ ...value, [key]: Number(event.target.value) })) }),
3629
+ h('output', null, Number(forces[key]).toFixed(2)))),
3630
+ h('div', { className: 'dshm-gs-forcepop-toggles' },
3631
+ h(Toggle, { checked: labels, label: t('graphLabels'), onChange: setLabels }),
3632
+ h(Toggle, { checked: motion, label: t('graphMotion'), onChange: setMotion })),
3633
+ h('button', { type: 'button', className: 'dshm-gs-mini', title: t('gsReset'),
3634
+ onClick: () => { setForces({ repulsion: 120, distance: 100, center: 0 }); notify(t('gsReset')) } }, t('gsReset')))
3635
+
3636
+ const rail = h('nav', { className: 'dshm-gs-rail', 'aria-label': t('graphView') },
3637
+ railBtn('graphZoomIn', '+', () => zoomBy(1.25)),
3638
+ railBtn('graphZoomOut', '−', () => zoomBy(.8)),
3639
+ railBtn('graphFit', '⛶', fit),
3640
+ h('div', { className: 'dshm-gs-rail-sep' }),
3641
+ railBtn('graphLabels', 'Aa', () => setLabels(value => !value), labels),
3642
+ railBtn('gsGrid', '#', () => setGrid(value => !value), grid),
3643
+ railBtn('gsMinimap', '▭', () => setMinimap(value => !value), minimap),
3644
+ railBtn('graphRelayout', '↻', () => { apiRef.current?.relayout?.(); notify(t('graphRelayout')) }),
3645
+ h('div', { className: 'dshm-gs-rail-slot' },
3646
+ railBtn('graphOptions', '⚙', () => setForceOpen(value => !value), forceOpen),
3647
+ forceOpen ? forcePop : null),
3648
+ railBtn('graphUnpinAll', '⊘', () => { apiRef.current?.unpinAll?.(); notify(t('graphUnpinAll')) }),
3649
+ h('div', { className: 'dshm-gs-rail-sep' }),
3650
+ railBtn('gsFocusNode', '◎', () => { if (focus) notify(t('gsFocusNode')); else fit() }),
3651
+ h('div', { className: 'dshm-gs-rail-grow' }),
3652
+ railBtn('gsHelp', '?', () => notify(t('gsShortcuts'))))
3653
+
3654
+ const legendItems = [
3655
+ ['memory', t('gsLegendMemory')], ['must', t('gsLegendMust')],
3656
+ ['entity', t('gsLegendEntity')], ['provisional', t('gsLegendPending')],
3657
+ ['global', t('gsLegendGlobal')], ['missing', t('gsLegendMissing')],
3658
+ ]
3659
+ const canvasTools = h('div', { className: 'dshm-gs-canvas-tools' },
3660
+ h('div', { className: 'dshm-gs-zoombar' },
3661
+ h('button', { type: 'button', title: t('graphZoomOut'), 'aria-label': t('graphZoomOut'), onClick: () => zoomBy(.8) }, '−'),
3662
+ h('output', { className: 'dshm-gs-zoomval' }, `${Math.round(zoom * 100)}%`),
3663
+ h('button', { type: 'button', title: t('graphZoomIn'), 'aria-label': t('graphZoomIn'), onClick: () => zoomBy(1.25) }, '+'),
3664
+ h('button', { type: 'button', title: t('graphFit'), 'aria-label': t('graphFit'), onClick: fit }, '⛶')),
3665
+ h('div', { className: 'dshm-gs-legendwrap' },
3666
+ h('button', { type: 'button', className: 'dshm-gs-legendbtn', title: t('gsLegend'),
3667
+ 'aria-expanded': String(legendOpen), onClick: () => setLegendOpen(value => !value) }, t('gsLegend')),
3668
+ legendOpen ? h('div', { className: 'dshm-gs-legendpop is-open' },
3669
+ h('h4', null, t('gsNodes')),
3670
+ legendItems.map(([kind, label]) => h('div', { key: kind, className: 'dshm-gs-legend-row' },
3671
+ h('i', { className: `dshm-gs-swatch dshm-gs-c-${kind}` }), label)),
3672
+ h('h4', null, t('gsEdges')),
3673
+ h('div', { className: 'dshm-gs-legend-row' }, h('i', { className: 'dshm-gs-line' }), t('gsLegendAuto')),
3674
+ h('div', { className: 'dshm-gs-legend-row' }, h('i', { className: 'dshm-gs-line dashed' }), t('gsLegendManual'))) : null))
3675
+
3676
+ const stage = h('main', { className: 'dshm-gs-stage' },
3677
+ h(GraphCanvas, { graph: canvasGraph, focus, onFocus: setFocus, t, chrome: false,
3678
+ options: canvasOptions, apiRef, onZoom: setZoom }),
3679
+ canvasTools,
3680
+ minimap ? h(GraphStudioMinimap, { active: true, t }) : null,
3681
+ h('div', { className: `dshm-gs-toast${toast ? ' show' : ''}`, role: 'status' }, toast),
3682
+ error ? h('div', { className: 'dshm-gs-toast show', role: 'alert' }, error) : null,
3683
+ !visibleEdges.length && nodes.length
3684
+ ? h('div', { className: 'dshm-gs-empty' }, showGlobal ? t('gsGlobalEmpty') : t('gsEmpty')) : null)
3685
+
3686
+ const inspectorBody = selected
3687
+ ? h(React.Fragment, null,
3688
+ h('div', { className: 'dshm-gs-sec' },
3689
+ h('div', { className: 'dshm-gs-hero' },
3690
+ h('div', { className: `dshm-gs-glyph dshm-gs-c-${gsKind(selected)}`, 'aria-hidden': 'true' },
3691
+ selected.kind === 'memory' ? '●' : '◆'),
3692
+ h('div', { className: 'dshm-gs-hero-t' },
3693
+ h('h3', null, String(selected.title || selected.id)),
3694
+ h('div', { className: 'dshm-gs-tags' },
3695
+ h('span', { className: 'dshm-gs-tag' }, String(selected.kind || 'memory')),
3696
+ selected.layer ? h('span', { className: 'dshm-gs-tag neutral' }, String(selected.layer)) : null,
3697
+ selected.status === 'provisional' ? h('span', { className: 'dshm-gs-tag warn' }, t('gsPending')) : null))),
3698
+ h('dl', { className: 'dshm-gs-kv' },
3699
+ h('dt', null, 'ID'), h('dd', null, String(selected.id)),
3700
+ h('dt', null, t('gsDegree')), h('dd', null, String(degree.get(selected.id) || 0)),
3701
+ h('dt', null, t('gsStrength')), h('dd', null, Number(selected.strength || 0).toFixed(2)))),
3702
+ h('div', { className: 'dshm-gs-sec' },
3703
+ h('div', { className: 'dshm-gs-sec-head' }, h('h3', null, t('relations')),
3704
+ h('span', { className: 'dshm-gs-count' }, String(focusEdges.length))),
3705
+ h('div', { className: 'dshm-gs-edge-list' }, focusEdges.slice(0, 20).map(edge => {
3706
+ const other = edge.from === focus ? edge.to : edge.from
3707
+ return h('div', { key: `${edge.from}:${edge.to}:${edge.kind || ''}`, className: 'dshm-gs-edge',
3708
+ onClick: () => setFocus(other) },
3709
+ h('div', { className: 'dshm-gs-edge-top' },
3710
+ h('span', { className: 'dshm-gs-edge-arrow' },
3711
+ `${titles.get(edge.from) || edge.from} → ${titles.get(edge.to) || edge.to}`),
3712
+ h('span', { className: 'dshm-gs-conf' }, Number(edge.confidence || 0).toFixed(2))),
3713
+ edge.note ? h('p', { className: 'dshm-gs-why' }, String(edge.note)) : null,
3714
+ h('div', { className: 'dshm-gs-meta' },
3715
+ h('span', { className: `dshm-gs-tag ${edge.source === 'auto' ? 'auto' : 'manual'}` },
3716
+ edge.source === 'auto' ? t('graphAutoLink') : t('edgeFilterManual')),
3717
+ edge.rule ? h('span', { className: 'dshm-gs-tag neutral' }, graphRuleText(edge.rule, t)) : null))
3718
+ }))),
3719
+ showGlobal ? null : h('details', { className: 'dshm-gs-fold' },
3720
+ h('summary', null, t('relations')),
3721
+ h(RelationshipPanel, { call, libraryId: graphLibrary, entities, files: panelFiles, t })))
3722
+ : h(React.Fragment, null,
3723
+ h('div', { className: 'dshm-gs-stats' },
3724
+ [[t('gsNodes'), nodes.length], [t('gsEdges'), edges.length],
3725
+ [t('gsVisible'), visibleEdges.length], [t('gsAutoEdges'), autoCount],
3726
+ [t('gsPending'), pendingCount]].map(([label, value]) =>
3727
+ h('div', { key: label, className: 'dshm-gs-stat' }, h('b', null, String(value)), h('span', null, label)))),
3728
+ h('div', { className: 'dshm-gs-hintbox' }, t('gsShortcuts')),
3729
+ h('div', { className: 'dshm-gs-hintbox' }, t('graphPinHint'), ' · ', t('graphScopeHint')))
3730
+ const inspector = h('aside', { className: 'dshm-gs-inspector' },
3731
+ h('div', { className: 'dshm-gs-ins-head' },
3732
+ h('div', { className: 'dshm-gs-ins-title' },
3733
+ h('h2', null, t('gsInspector')),
3734
+ h('span', { className: 'dshm-gs-count' }, selected ? String(selected.title || selected.id) : t('gsNoSelection'))),
3735
+ h('p', null, t('gsInspectorHint'))),
3736
+ h('div', { className: 'dshm-gs-ins-body' }, inspectorBody))
3737
+
3738
+ // 管理视图的「连接分支」侧栏:可拖动分隔条调宽度,复刻 HTML 的 br-resizer。
3739
+ const startBranchResize = event => {
3740
+ event.preventDefault?.()
3741
+ const startX = event.clientX || 0, startWidth = branchWidth
3742
+ const onMove = moveEvent => setBranchWidth(Math.max(240, Math.min(620, startWidth + startX - (moveEvent.clientX || 0))))
3743
+ const onUp = () => {
3744
+ window.removeEventListener?.('pointermove', onMove)
3745
+ window.removeEventListener?.('pointerup', onUp)
3746
+ }
3747
+ window.addEventListener?.('pointermove', onMove)
3748
+ window.addEventListener?.('pointerup', onUp)
3749
+ }
3750
+ const branchId = mgrSelected || focus
3751
+ const branchNode = nodes.find(node => node.id === branchId) || null
3752
+ const tier1 = branchId ? edges.filter(edge => edge.from === branchId || edge.to === branchId)
3753
+ .map(edge => ({ id: edge.from === branchId ? edge.to : edge.from, edge })) : []
3754
+ const tier1Ids = new Set(tier1.map(item => item.id))
3755
+ const tier2 = branchId ? edges.filter(edge => tier1Ids.has(edge.from) || tier1Ids.has(edge.to))
3756
+ .map(edge => ({ id: tier1Ids.has(edge.from) ? edge.to : edge.from, edge }))
3757
+ .filter(item => item.id !== branchId && !tier1Ids.has(item.id)) : []
3758
+ const branchRow = item => {
3759
+ const other = nodes.find(node => node.id === item.id) || { kind: 'memory' }
3760
+ return h('div', { key: `${item.id}:${item.edge.from}:${item.edge.to}`, className: 'dshm-gs-br-item' },
3761
+ h('i', { className: `dshm-gs-br-dot dshm-gs-c-${gsKind(other)}` }),
3762
+ h('div', { className: 'dshm-gs-br-col' },
3763
+ h('div', { className: 'dshm-gs-br-nm', onClick: () => { setFocus(item.id); setView('graph') } },
3764
+ titles.get(item.id) || item.id),
3765
+ h('div', { className: 'dshm-gs-br-meta' },
3766
+ `${item.edge.kind || 'link'} · ${item.edge.source === 'auto' ? t('graphAutoLink') : t('edgeFilterManual')}`)),
3767
+ h('button', { type: 'button', className: 'dshm-gs-mini', title: t('gsLocate'),
3768
+ onClick: () => { setFocus(item.id); setView('graph'); setInspectorOpen(true) } }, t('gsLocate')))
3769
+ }
3770
+ const branchPanel = h('aside', { className: 'dshm-gs-branch' },
3771
+ h('div', { className: 'dshm-gs-br-head' },
3772
+ h('h3', null, t('gsBranch')), h('p', null, t('gsBranchHint'))),
3773
+ h('div', { className: 'dshm-gs-br-body' },
3774
+ branchNode ? h(React.Fragment, null,
3775
+ h('div', { className: 'dshm-gs-br-hero' },
3776
+ h('div', { className: `dshm-gs-glyph dshm-gs-c-${gsKind(branchNode)}` }, '◆'),
3777
+ h('div', { className: 'dshm-gs-hero-t' },
3778
+ h('b', null, String(branchNode.title || branchNode.id)),
3779
+ h('span', null, `${t('gsDegree')} ${degree.get(branchId) || 0}`))),
3780
+ h('div', { className: 'dshm-gs-br-sec' },
3781
+ h('h4', null, `${t('gsTier1')} (${tier1.length})`),
3782
+ tier1.slice(0, 30).map(branchRow)),
3783
+ tier2.length ? h('details', { className: 'dshm-gs-fold' },
3784
+ h('summary', null, `${t('gsTier2')} (${tier2.length})`),
3785
+ tier2.slice(0, 30).map(branchRow)) : null)
3786
+ : h('div', { className: 'dshm-gs-br-empty' }, t('gsNoSelection'))))
3787
+
3788
+ const manager = h('section', { className: 'dshm-gs-manager' },
3789
+ h('div', { className: 'dshm-gs-mgr-head' },
3790
+ h('span', { className: 'dshm-gs-count' }, `${manageRows.length} · ${t('gsNodes')}`),
3791
+ h('select', { className: 'dshm-gs-field', value: mgrKind, 'aria-label': t('gsAllKinds'),
3792
+ onChange: event => setMgrKind(event.target.value) },
3793
+ h('option', { value: '' }, t('gsAllKinds')),
3794
+ ['memory', 'person', 'place', 'thing', 'global'].map(kind =>
3795
+ h('option', { key: kind, value: kind }, kind))),
3796
+ h('select', { className: 'dshm-gs-field', value: mgrStatus, 'aria-label': t('gsAllStatus'),
3797
+ onChange: event => setMgrStatus(event.target.value) },
3798
+ h('option', { value: '' }, t('gsAllStatus')),
3799
+ [['confirmed', 'entityConfirmed'], ['provisional', 'gsPending']].map(([value, label]) =>
3800
+ h('option', { key: value, value }, t(label)))),
3801
+ h('select', { className: 'dshm-gs-field', value: mgrSort, 'aria-label': t('gsSort'),
3802
+ onChange: event => setMgrSort(event.target.value) },
3803
+ [['degree', 'gsDegree'], ['strength', 'gsStrength'], ['title', 'gsTitle'], ['id', 'gsNodes']].map(([value, label]) =>
3804
+ h('option', { key: value, value }, t(label)))),
3805
+ writable ? h('button', { type: 'button', className: `dshm-gs-btn${mgrArmed === removeKey ? ' is-danger' : ''}`,
3806
+ title: t('gsRemoveNodeHint'), 'aria-label': t('gsRemoveNode'), disabled: !mgrSelected || mgrBusy,
3807
+ onClick: () => { void removeSelected() } },
3808
+ mgrArmed === removeKey ? (mgrDeleteRefused === mgrSelected ? t('relationConfirm') + '!' : t('confirmDelete')) : t('gsRemoveNode')) : null,
3809
+ writable ? h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsEditNode'),
3810
+ 'aria-label': t('gsEditNode'), disabled: !mgrSelected || mgrBusy || editBusy,
3811
+ onClick: () => { void editNode() } }, t('gsEditNode')) : null,
3812
+ writable ? h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsAddNode'),
3813
+ 'aria-expanded': String(addOpen), onClick: () => { setEditOpen(false); setEditDraft(null); setAddOpen(value => !value) } }, t('gsAddNode')) : null,
3814
+ h('button', { type: 'button', className: 'dshm-gs-btn', title: t('gsExport'), onClick: exportPng }, t('gsExport'))),
3815
+ addOpen && writable ? h('div', { className: 'dshm-gs-mgr-add' },
3816
+ h('select', { className: 'dshm-gs-field', value: addTargetLib, title: t('gsAddLibrary'), 'aria-label': t('gsAddLibrary'),
3817
+ onChange: event => setAddLib(event.target.value) },
3818
+ (mergedScope ? libraries : libraries.filter(lib => lib.id === addTargetLib))
3819
+ .map(lib => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries)))),
3820
+ h('div', { className: 'dshm-gs-seg', role: 'group', 'aria-label': t('gsAddNode') },
3821
+ h('button', { type: 'button', 'aria-pressed': String(draft.type === 'memory'),
3822
+ onClick: () => setDraft(value => ({ ...value, type: 'memory' })) }, t('gsNodeMemory')),
3823
+ h('button', { type: 'button', 'aria-pressed': String(draft.type === 'entity'),
3824
+ onClick: () => setDraft(value => ({ ...value, type: 'entity' })) }, t('gsNodeEntity'))),
3825
+ draft.type === 'memory'
3826
+ ? h('input', { className: 'dshm-gs-field', value: draft.title, placeholder: t('memoryTitle'), 'aria-label': t('memoryTitle'),
3827
+ onChange: event => setDraft(value => ({ ...value, title: event.target.value })) })
3828
+ : h('input', { className: 'dshm-gs-field', value: draft.name, placeholder: t('entityName'), 'aria-label': t('entityName'),
3829
+ onChange: event => setDraft(value => ({ ...value, name: event.target.value })) }),
3830
+ draft.type === 'memory'
3831
+ ? h('select', { className: 'dshm-gs-field', value: draft.layer, 'aria-label': t('gsLayer'),
3832
+ onChange: event => setDraft(value => ({ ...value, layer: event.target.value })) },
3833
+ ['long_term', 'short_term', 'must_remember'].map(layer => h('option', { key: layer, value: layer }, enumText(t, LAYER_LABELS, layer))))
3834
+ : h('select', { className: 'dshm-gs-field', value: draft.kind, 'aria-label': t('gsKind'),
3835
+ onChange: event => setDraft(value => ({ ...value, kind: event.target.value })) },
3836
+ ['person', 'place', 'thing', 'org'].map(kind => h('option', { key: kind, value: kind }, kind))),
3837
+ h('div', { className: 'dshm-gs-add-actions' },
3838
+ h('button', { type: 'button', className: 'dshm-gs-btn', disabled: !canAdd, onClick: () => { void addNode() } }, t('add')),
3839
+ h('button', { type: 'button', className: 'dshm-gs-btn', onClick: () => setAddOpen(false) }, t('cancelDelete'))),
3840
+ draft.type === 'memory'
3841
+ ? h('textarea', { className: 'dshm-gs-field', value: draft.content, placeholder: t('memoryContent'), 'aria-label': t('memoryContent'),
3842
+ onChange: event => setDraft(value => ({ ...value, content: event.target.value })) })
3843
+ : null) : null,
3844
+ editOpen && editDraft ? h('div', { className: 'dshm-gs-mgr-add' },
3845
+ h('select', { className: 'dshm-gs-field', value: editDraft.libraryId, disabled: true, title: t('gsAddLibrary'), 'aria-label': t('gsAddLibrary') },
3846
+ h('option', { value: editDraft.libraryId },
3847
+ libraryOptionLabel(libraries.find(lib => lib.id === editDraft.libraryId) || { id: editDraft.libraryId }, libraries))),
3848
+ h('div', { className: 'dshm-gs-seg', role: 'group', 'aria-label': t('gsEditNode') },
3849
+ h('button', { type: 'button', 'aria-pressed': 'true', disabled: true },
3850
+ editDraft.kind === 'memory' ? t('gsNodeMemory') : t('gsNodeEntity'))),
3851
+ editDraft.kind === 'memory'
3852
+ ? h('input', { className: 'dshm-gs-field', value: editDraft.title, placeholder: t('memoryTitle'), 'aria-label': t('memoryTitle'),
3853
+ onChange: event => setEditDraft(value => ({ ...value, title: event.target.value })) })
3854
+ : h('input', { className: 'dshm-gs-field', value: editDraft.name, placeholder: t('entityName'), 'aria-label': t('entityName'),
3855
+ onChange: event => setEditDraft(value => ({ ...value, name: event.target.value })) }),
3856
+ editDraft.kind === 'memory'
3857
+ ? h('select', { className: 'dshm-gs-field', value: editDraft.layer, 'aria-label': t('gsLayer'),
3858
+ onChange: event => setEditDraft(value => ({ ...value, layer: event.target.value })) },
3859
+ editLayers.map(layer => h('option', { key: layer, value: layer }, enumText(t, LAYER_LABELS, layer))))
3860
+ : h('input', { className: 'dshm-gs-field', value: editDraft.aliases, placeholder: t('entityAliases'), 'aria-label': t('entityAliases'),
3861
+ onChange: event => setEditDraft(value => ({ ...value, aliases: event.target.value })) }),
3862
+ h('div', { className: 'dshm-gs-add-actions' },
3863
+ h('button', { type: 'button', className: 'dshm-gs-btn', disabled: !canSave, onClick: () => { void saveEdit() } }, t('save')),
3864
+ h('button', { type: 'button', className: 'dshm-gs-btn', onClick: () => { setEditOpen(false); setEditDraft(null) } }, t('cancelDelete'))),
3865
+ editDraft.kind === 'memory'
3866
+ ? h('textarea', { className: 'dshm-gs-field', value: editDraft.content, placeholder: t('memoryContent'), 'aria-label': t('memoryContent'),
3867
+ onChange: event => setEditDraft(value => ({ ...value, content: event.target.value })) })
3868
+ : null) : null,
3869
+ h('div', { className: 'dshm-gs-mgr-body', style: { '--gs-br-w': `${branchWidth}px` } },
3870
+ h('div', { className: 'dshm-gs-mgr-scroll' },
3871
+ h('div', { className: 'dshm-gs-mgr-thead' },
3872
+ h('span', null, ''), h('span', null, 'ID'), h('span', null, t('gsTitle')),
3873
+ h('span', null, t('gsKind')), h('span', null, t('gsStatus')), h('span', null, t('gsLayer')),
3874
+ h('span', { className: 'num' }, t('gsDegree')), h('span', { className: 'num' }, t('gsStrength')),
3875
+ h('span', null, t('gsAction'))),
3876
+ manageRows.length ? manageRows.slice(0, 300).map(node => h('div', {
3877
+ key: node.id, className: `dshm-gs-mgr-row${mgrSelected === node.id ? ' sel' : ''}`,
3878
+ onClick: () => { setMgrSelected(node.id); setEditOpen(false); setEditDraft(null) },
3879
+ },
3880
+ h('span', { className: 'dshm-gs-mgr-dot' }, h('i', { className: `dshm-gs-swatch dshm-gs-c-${gsKind(node)}` })),
3881
+ h('span', { className: 'dshm-gs-mgr-id' }, String(node.id).slice(0, 8)),
3882
+ h('span', { className: 'dshm-gs-mgr-title' }, String(node.title || node.id)),
3883
+ h('span', null, String(node.kind || 'memory')),
3884
+ // 记忆条目写入即生效,没有「待确认」概念;只有实体才会是 provisional。
3885
+ h('span', null, node.status === 'provisional' ? t('gsPending')
3886
+ : node.kind === 'memory' || node.status === 'confirmed' ? t('gsConfirmed') : '—'),
3887
+ h('span', null, node.layer ? enumText(t, LAYER_LABELS, node.layer) : '—'),
3888
+ h('span', { className: 'num' }, String(degree.get(node.id) || 0)),
3889
+ h('span', { className: 'num' }, Number(node.strength || 0).toFixed(2)),
3890
+ h('span', { className: 'dshm-gs-mgr-ops' },
3891
+ h('button', { type: 'button', className: 'dshm-gs-mini', title: t('gsViewBranch'),
3892
+ onClick: event => { event.stopPropagation(); setMgrSelected(node.id); setView('manage') } }, t('gsViewBranch')),
3893
+ h('button', { type: 'button', className: 'dshm-gs-mini', title: t('gsLocate'),
3894
+ onClick: event => { event.stopPropagation(); setFocus(node.id); setView('graph'); setInspectorOpen(true) } }, t('gsLocate')))))
3895
+ : h('div', { className: 'dshm-gs-mgr-empty' }, t('gsNoMatch'))),
3896
+ h('button', { type: 'button', className: 'dshm-gs-br-resizer', title: t('gsResize'),
3897
+ 'aria-label': t('gsResize'), onPointerDown: startBranchResize }),
3898
+ branchPanel),
3899
+ h('div', { className: 'dshm-gs-mgr-foot' },
3900
+ h('span', null, mgrSelected || '—'),
3901
+ h('div', { className: 'dshm-gs-spacer' }),
3902
+ h('button', { type: 'button', className: 'dshm-gs-btn', disabled: !mgrSelected,
3903
+ onClick: () => { setFocus(mgrSelected); setView('graph'); setInspectorOpen(true) } }, t('gsLocate')),
3904
+ h('button', { type: 'button', className: 'dshm-gs-btn primary', onClick: () => setView('graph') }, t('graphView'))))
3905
+
3906
+ const status = h('footer', { className: 'dshm-gs-status' },
3907
+ h('span', { className: 'dshm-gs-live' }, h('i'), t('gsLocalData')),
3908
+ h('span', { className: 'dshm-gs-status-sep' }),
3909
+ h('span', null, t('gsNodes'), ' ', h('b', null, String(nodes.length))),
3910
+ h('span', null, t('gsEdges'), ' ', h('b', null, String(edges.length))),
3911
+ h('span', null, t('gsVisible'), ' ', h('b', null, String(visibleEdges.length))),
3912
+ h('span', null, t('gsAutoEdges'), ' ', h('b', null, String(autoCount))),
3913
+ h('span', null, t('gsPending'), ' ', h('b', null, String(pendingCount))),
3914
+ h('span', { className: 'dshm-gs-status-right' }, t('gsRender'), ' ', h('b', null, '—'),
3915
+ ' · ', t('graphPinHint')))
3916
+
3917
+ return h('div', { className: `dshm-gs${inspectorOpen ? '' : ' is-collapsed'}${view === 'manage' ? ' is-manage' : ''}${minimap ? ' show-minimap' : ''}` },
3918
+ topbar, rail, stage, inspector, manager, status)
3919
+ }
2741
3920
  function GraphPanel({ call, libraryId, files, t, global = false }) {
2742
3921
  const [graph, setGraph] = React.useState({ nodes: [], edges: [] })
2743
3922
  const [entities, setEntities] = React.useState([])
@@ -2754,6 +3933,15 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2754
3933
  // 图谱其余部分,所以单独 catch 成空列表。
2755
3934
  const [merges, setMerges] = React.useState([])
2756
3935
  const [mergeNotice, setMergeNotice] = React.useState('')
3936
+ // 待确认实体(DESIGN §9.2):候选只排队列;确认动作才会补挂提及边。
3937
+ const [anchor, setAnchor] = React.useState(null)
3938
+ const [anchorKinds, setAnchorKinds] = React.useState({})
3939
+ const [anchorPicked, setAnchorPicked] = React.useState(() => new Set())
3940
+ const [anchorBusy, setAnchorBusy] = React.useState(false)
3941
+ // 边来源筛选 + “删除全部自动边”的二次确认(§10)。
3942
+ const [edgeFilter, setEdgeFilter] = React.useState('all')
3943
+ const [purgeArmed, setPurgeArmed] = React.useState(false)
3944
+ const [clearArmed, setClearArmed] = React.useState(false)
2757
3945
  const [error, setError] = React.useState('')
2758
3946
  const requestId = React.useRef(0)
2759
3947
  const mounted = React.useRef(true)
@@ -2776,13 +3964,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2776
3964
  }
2777
3965
  return
2778
3966
  }
2779
- const [next, list, suggested] = await Promise.all([
3967
+ const [next, list, suggested, queue] = await Promise.all([
2780
3968
  call('getGraph', { libraryId, focusId: focus || null, depth: 2, limit: 200 }),
2781
3969
  call('listEntities', { libraryId }),
2782
3970
  call('suggestEntityMerges', { libraryId }).catch(() => null),
3971
+ call('getAnchorCandidates', { libraryId }).catch(() => null),
2783
3972
  ])
2784
3973
  if (mounted.current && id === requestId.current) {
2785
- setGraph(next); setEntities(list.items || []); setMerges(suggested?.items || []); setError('')
3974
+ setGraph(next); setEntities(list.items || []); setMerges(suggested?.items || []); setAnchor(queue || null); setError('')
2786
3975
  }
2787
3976
  }, [call, libraryId, focus, global])
2788
3977
  React.useEffect(() => {
@@ -2790,6 +3979,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2790
3979
  if (libraryId || global) refresh().catch(error => { if (active) setError(String(error.message || error)) })
2791
3980
  return () => { active = false; requestId.current++ }
2792
3981
  }, [refresh, files, global])
3982
+ // Switching libraries must not keep a selection that belongs to another one.
3983
+ React.useEffect(() => { setAnchorPicked(new Set()) }, [libraryId])
2793
3984
  React.useEffect(() => {
2794
3985
  if (!armed) return undefined
2795
3986
  const timer = setTimeout(() => setArmed(''), 2500)
@@ -2806,6 +3997,16 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2806
3997
  const timer = setTimeout(() => setMergeNotice(''), 9000)
2807
3998
  return () => clearTimeout(timer)
2808
3999
  }, [mergeNotice])
4000
+ React.useEffect(() => {
4001
+ if (!purgeArmed) return undefined
4002
+ const timer = setTimeout(() => setPurgeArmed(false), 2500)
4003
+ return () => clearTimeout(timer)
4004
+ }, [purgeArmed])
4005
+ React.useEffect(() => {
4006
+ if (!clearArmed) return undefined
4007
+ const timer = setTimeout(() => setClearArmed(false), 2500)
4008
+ return () => clearTimeout(timer)
4009
+ }, [clearArmed])
2809
4010
  const act = async (method, payload) => {
2810
4011
  try {
2811
4012
  await call(method, { libraryId, ...payload })
@@ -2835,8 +4036,74 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2835
4036
  if (mounted.current) await refresh()
2836
4037
  } catch (failure) { if (mounted.current) setError(String(failure.message || failure)) }
2837
4038
  }
4039
+ // Confirm is the only action that changes an entity's status. It also runs
4040
+ // the incremental mention pass on the server, so the graph below updates
4041
+ // with the new edges in the same round trip.
4042
+ const confirmEntityIds = async (ids) => {
4043
+ const wanted = (Array.isArray(ids) ? ids : []).filter(Boolean)
4044
+ if (!wanted.length || anchorBusy) return
4045
+ setAnchorBusy(true)
4046
+ try {
4047
+ const result = await call('confirmEntities', { libraryId, entityIds: wanted })
4048
+ notifyMemoryWrite('relation', libraryId)
4049
+ setAnchorPicked(new Set())
4050
+ if (mounted.current) {
4051
+ await refresh()
4052
+ if (result?.confirmed?.length) setMergeNotice(t('anchorConfirmedDone').replace('{n}', String(result.confirmed.length)))
4053
+ }
4054
+ } catch (failure) {
4055
+ if (mounted.current) setError(String(failure?.message || failure))
4056
+ } finally {
4057
+ if (mounted.current) setAnchorBusy(false)
4058
+ }
4059
+ }
4060
+ const confirmCandidate = async (row) => {
4061
+ if (!row || anchorBusy) return
4062
+ if (row.entityId) { if (row.entityStatus === 'provisional') await confirmEntityIds([row.entityId]); return }
4063
+ setAnchorBusy(true)
4064
+ try {
4065
+ await call('createEntity', { libraryId, name: row.term, kind: anchorKinds[row.term] || 'person' })
4066
+ notifyMemoryWrite('relation', libraryId)
4067
+ if (mounted.current) { await refresh(); setMergeNotice(t('anchorConfirmedDone').replace('{n}', '1')) }
4068
+ } catch (failure) {
4069
+ if (mounted.current) setError(String(failure?.message || failure))
4070
+ } finally {
4071
+ if (mounted.current) setAnchorBusy(false)
4072
+ }
4073
+ }
4074
+ const purgeAuto = async () => {
4075
+ if (!purgeArmed) { setPurgeArmed(true); return }
4076
+ setPurgeArmed(false)
4077
+ try {
4078
+ const result = await call('purgeAutoLinks', { libraryId })
4079
+ notifyMemoryWrite('relation', libraryId)
4080
+ if (mounted.current) {
4081
+ await refresh()
4082
+ setMergeNotice(t('purgeAutoDone').replace('{n}', String(result?.removed ?? 0)))
4083
+ }
4084
+ } catch (failure) {
4085
+ if (mounted.current) setError(String(failure?.message || failure))
4086
+ }
4087
+ }
4088
+ const clearSuppressionNow = async () => {
4089
+ if (!clearArmed) { setClearArmed(true); return }
4090
+ setClearArmed(false)
4091
+ try {
4092
+ const result = await call('clearLinkSuppression', { libraryId })
4093
+ notifyMemoryWrite('relation', libraryId)
4094
+ if (mounted.current) {
4095
+ await refresh()
4096
+ setMergeNotice(t('clearSuppressionDone').replace('{n}', String(result?.cleared ?? 0)))
4097
+ }
4098
+ } catch (failure) {
4099
+ if (mounted.current) setError(String(failure?.message || failure))
4100
+ }
4101
+ }
2838
4102
  const titles = new Map(graph.nodes.map(node => [node.id, node.missing ? t('deletedNode') : node.title]))
2839
- const edges = graph.edges.filter(edge => !focus || edge.from === focus || edge.to === focus).sort((a, b) => b.confidence - a.confidence)
4103
+ const focusEdges = graph.edges.filter(edge => !focus || edge.from === focus || edge.to === focus).sort((a, b) => b.confidence - a.confidence)
4104
+ const edges = focusEdges.filter(edge => edgeFilter === 'all'
4105
+ || (edgeFilter === 'auto' ? edge.source === 'auto' : edge.source !== 'auto'))
4106
+ const canvasGraph = { ...graph, edges }
2840
4107
  if (global) {
2841
4108
  return h('div', null,
2842
4109
  error ? h('div', { className: 'dshm-toast', role: 'status' }, error) : null,
@@ -2846,7 +4113,7 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2846
4113
  files.map(file => h('option', { key: file.id, value: file.id }, file.title || file.id)))),
2847
4114
  graph.truncated ? h('p', null, t('graphLimited')) : null,
2848
4115
  h('div', { className: 'dshm-graph-stage' },
2849
- h(GraphCanvas, { key: 'global', graph, focus, onFocus: setFocus, t }),
4116
+ h(GraphCanvas, { key: 'global', graph: canvasGraph, focus, onFocus: setFocus, t }),
2850
4117
  h('div', { className: 'dshm-graph-list' }, edges.length ? edges.map(edge => h('div', { key: edge.from + edge.to + edge.kind, className: 'dshm-graph-edge' },
2851
4118
  h('div', null,
2852
4119
  h('button', { type: 'button', className: 'dshm-graph-node', onClick: () => setFocus(edge.from) }, titles.get(edge.from) || edge.from),
@@ -2894,19 +4161,39 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2894
4161
  h('select', { value: focus, title: t('focusMemory'), onChange: event => setFocus(event.target.value) },
2895
4162
  h('option', { value: '' }, t('focusMemory')),
2896
4163
  [...files, ...entities.map(entity => ({ id: entity.id, title: entity.name }))].map(file =>
2897
- h('option', { key: file.id, value: file.id }, file.title || file.id)))),
4164
+ h('option', { key: file.id, value: file.id }, file.title || file.id))),
4165
+ h('select', { value: edgeFilter, title: t('edgeFilterAll'), onChange: event => setEdgeFilter(event.target.value) },
4166
+ h('option', { value: 'all' }, t('edgeFilterAll')),
4167
+ h('option', { value: 'auto' }, t('edgeFilterAuto')),
4168
+ h('option', { value: 'manual' }, t('edgeFilterManual'))),
4169
+ h(Button, {
4170
+ disabled: anchorBusy || !graph.edges.some(edge => edge.source === 'auto'),
4171
+ style: purgeArmed ? { ...S.btn, color: V.danger, borderColor: V.danger } : S.ghost,
4172
+ onClick: () => void purgeAuto(),
4173
+ }, purgeArmed ? t('purgeAutoConfirm') : t('purgeAutoLinks')),
4174
+ h(Button, {
4175
+ disabled: anchorBusy,
4176
+ style: clearArmed ? { ...S.btn, color: V.danger, borderColor: V.danger } : S.ghost,
4177
+ onClick: () => void clearSuppressionNow(),
4178
+ }, clearArmed ? t('clearSuppressionConfirm') : t('clearSuppression'))),
2898
4179
  graph.truncated ? h('p', null, t('graphLimited')) : null,
2899
4180
  // The canvas and the adjacency list are one view: the picture shows the
2900
4181
  // shape, the list keeps the reasons readable and clickable. Neither is an
2901
4182
  // alternate mode, so there is no toggle to forget.
2902
4183
  h('div', { className: 'dshm-graph-stage' },
2903
- h(GraphCanvas, { key: libraryId, graph, focus, onFocus: setFocus, t }),
4184
+ h(GraphCanvas, { key: libraryId, graph: canvasGraph, focus, onFocus: setFocus, t }),
2904
4185
  h('div', { className: 'dshm-graph-list' }, edges.length ? edges.map(edge => h('div', { key: edge.from + edge.to + edge.kind, className: 'dshm-graph-edge' },
2905
4186
  h('div', null, h('button', { type: 'button', className: 'dshm-graph-node', onClick: () => setFocus(edge.from) }, titles.get(edge.from) || edge.from),
2906
4187
  ' → ', h('button', { type: 'button', className: 'dshm-graph-node', onClick: () => setFocus(edge.to) }, titles.get(edge.to) || edge.to),
2907
4188
  // 私有自动关联(§5.7):source:'auto' 的边来自算法/实体枢纽,不是用户手连。
2908
4189
  // 只多一个可点读的小 Tag;kind/confidence/note 与移除按钮保持原样。
2909
4190
  edge.source === 'auto' ? h('span', { style: { margin: '0 5px', verticalAlign: 'middle' } }, h(Tag, { tone: 'info' }, t('graphAutoLink'))) : null,
4191
+ // §10:自动边要能说清“为什么”——规则 + 命中的表面/字段。
4192
+ // 老自动边没有 evidence.rule,用 edge.rule 的 'auto' 兜底标签。
4193
+ edge.rule ? h('span', { style: { margin: '0 5px', verticalAlign: 'middle' } }, h(Tag, null, graphRuleText(edge.rule, t))) : null,
4194
+ edge.evidence?.surface ? h('span', { style: { ...S.muted, fontSize: 11, marginRight: 5 } },
4195
+ `「${edge.evidence.surface}」${edge.evidence.field || ''}${Number.isInteger(edge.evidence.offset) ? ' @' + edge.evidence.offset : ''}`) : null,
4196
+ edge.evidence?.field && !edge.evidence?.surface ? h('span', { style: { ...S.muted, fontSize: 11, marginRight: 5 } }, edge.evidence.field) : null,
2910
4197
  h('small', null, edge.kind + ' · ' + Math.round(edge.confidence * 100) + '% · ' + edge.note)),
2911
4198
  h('button', {
2912
4199
  type: 'button',
@@ -2947,6 +4234,77 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2947
4234
  onClick: () => { if (armed !== key) { setArmed(key); return } void doMerge(item) },
2948
4235
  }, armed === key ? t('entityMergeConfirm') : t('entityMergeAction')))
2949
4236
  })) : null,
4237
+ // 待确认实体(DESIGN §9.2):候选只排队列、不改状态;确认后才补挂提及边。
4238
+ (() => {
4239
+ const provisional = entities.filter(entity => entity.status === 'provisional')
4240
+ const tiers = anchor?.tiers || { tier1: [], tier2: [] }
4241
+ const visible = (list) => (Array.isArray(list) ? list : []).filter(row => row.entityStatus !== 'confirmed')
4242
+ const tier1 = visible(tiers.tier1)
4243
+ const tier2 = visible(tiers.tier2)
4244
+ if (!provisional.length && !tier1.length && !tier2.length) {
4245
+ return h('div', { style: { margin: '10px 0' } },
4246
+ h('div', { style: { fontSize: 12, fontWeight: 600 } }, t('anchorReviewTitle')),
4247
+ h('div', { style: { ...S.muted, margin: '4px 0 0' } }, t('anchorNoCandidates')))
4248
+ }
4249
+ const kindOptions = ['person', 'place', 'thing', 'org']
4250
+ const candidateRow = (row) => {
4251
+ const archived = row.entityStatus === 'archived'
4252
+ return h('div', { key: 'cand:' + row.term, className: 'dshm-graph-tools', style: { alignItems: 'center', flexWrap: 'wrap' } },
4253
+ h('span', { style: { minWidth: 0, overflowWrap: 'anywhere', fontWeight: 600 } }, row.term),
4254
+ row.quoted ? h(Tag, { tone: 'info' }, t('anchorSignalQuote')) : null,
4255
+ row.intro ? h(Tag, { tone: 'info' }, t('anchorSignalIntro')) : null,
4256
+ row.mixed ? h(Tag, { tone: 'info' }, t('anchorSignalMixed')) : null,
4257
+ archived ? h(Tag, { tone: 'warn' }, t('anchorArchivedEntity')) : null,
4258
+ row.entityId && !archived ? h(Tag, null, t('anchorExistingEntity')) : null,
4259
+ h('span', { style: { ...S.muted, fontSize: 11, whiteSpace: 'nowrap' } },
4260
+ t('anchorStats').replace('{df}', String(row.df)).replace('{cohesion}', String(row.cohesion)).replace('{freedom}', String(row.freedom))),
4261
+ archived ? null : (row.entityId
4262
+ ? (row.entityStatus === 'provisional'
4263
+ ? h(Button, { disabled: anchorBusy, onClick: () => void confirmEntityIds([row.entityId]) }, t('anchorConfirm'))
4264
+ : null)
4265
+ : h(React.Fragment, null,
4266
+ h('select', {
4267
+ value: anchorKinds[row.term] || 'person', title: t('entityKind'),
4268
+ onChange: event => setAnchorKinds(prev => ({ ...prev, [row.term]: event.target.value })),
4269
+ style: { ...S.input, width: 'auto' },
4270
+ }, kindOptions.map(kind => h('option', { key: kind, value: kind }, kind))),
4271
+ h(Button, { disabled: anchorBusy, onClick: () => void confirmCandidate(row) }, t('anchorConfirm')))))
4272
+ }
4273
+ return h('div', { style: { margin: '10px 0' } },
4274
+ h('div', { style: { fontSize: 12, fontWeight: 600 } }, t('anchorReviewTitle') + (provisional.length ? ` (${provisional.length})` : '')),
4275
+ h('div', { style: { ...S.muted, margin: '4px 0 6px', lineHeight: 1.5 } }, t('anchorReviewHint')),
4276
+ provisional.length
4277
+ ? h('div', null,
4278
+ provisional.map(entity => {
4279
+ const picked = anchorPicked.has(entity.id)
4280
+ return h('label', { key: 'pending:' + entity.id, className: 'dshm-graph-tools', style: { alignItems: 'center', cursor: 'pointer' } },
4281
+ h('input', {
4282
+ type: 'checkbox', checked: picked,
4283
+ // .dshm-graph-tools input stretches text fields; a checkbox must not.
4284
+ style: { flex: 'none', width: 16, height: 16, margin: 0, padding: 0 },
4285
+ onChange: () => setAnchorPicked(prev => {
4286
+ const next = new Set(prev)
4287
+ if (picked) next.delete(entity.id); else next.add(entity.id)
4288
+ return next
4289
+ }),
4290
+ }),
4291
+ h('span', { style: { minWidth: 0, overflowWrap: 'anywhere' } }, entity.name),
4292
+ h(Tag, null, entity.kind || 'person'),
4293
+ h(Tag, { tone: 'info' }, t('anchorPendingEntity')))
4294
+ }),
4295
+ h(Button, {
4296
+ disabled: anchorBusy || anchorPicked.size === 0,
4297
+ onClick: () => void confirmEntityIds([...anchorPicked]),
4298
+ }, t('anchorConfirmSelected').replace('{n}', String(anchorPicked.size))))
4299
+ : null,
4300
+ tier1.length ? h('div', { style: { marginTop: 8 } },
4301
+ h('div', { style: { ...S.muted, fontSize: 11 } }, t('anchorTier1')),
4302
+ tier1.map(candidateRow)) : null,
4303
+ tier2.length ? h('details', { style: { marginTop: 6 } },
4304
+ h('summary', { style: { cursor: 'pointer', fontSize: 12, color: V.textDim } }, t('anchorTier2') + ` (${tier2.length})`),
4305
+ tier2.map(candidateRow)) : null,
4306
+ h('div', { style: { ...S.muted, marginTop: 6, lineHeight: 1.5, fontSize: 11 } }, t('anchorCreateHint') + ' ' + t('anchorKindHint')))
4307
+ })(),
2950
4308
  entities.length === 0 ? h(Empty, null, t('entityEmpty')) : null,
2951
4309
  // 孤立分组(§6.4 包 D):listEntities 给出 linked 派生标记。被引用的实体照常
2952
4310
  // 渲染;孤立实体(linked=false,没有任何记忆 link/关系快照指着)收进折叠区,
@@ -2996,8 +4354,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
2996
4354
  const [data, setData] = React.useState({ items: [], total: 0, errors: [] })
2997
4355
  const [libraryId, setLibraryId] = React.useState(initialLibraryId || '')
2998
4356
  const [multiBlocked, setMultiBlocked] = React.useState(false)
2999
- const [view, setView] = React.useState('memories')
3000
- const [graphLib, setGraphLib] = React.useState('')
3001
4357
  const [pool, setPool] = React.useState('active')
3002
4358
  const [layer, setLayer] = React.useState('all')
3003
4359
  const [query, setQuery] = React.useState('')
@@ -3073,13 +4429,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3073
4429
  void load()
3074
4430
  return () => { alive = false }
3075
4431
  }, [call, libraryId, revision, stamp, version, firstLibraryId])
3076
- React.useEffect(() => {
3077
- if (graphLib && libraries.some((lib) => lib.id === graphLib)) return
3078
- const selected = libraryId && libraries.some((lib) => lib.id === libraryId) ? libraryId : ''
3079
- const first = selected || libraries[0]?.id || ''
3080
- if (first) setGraphLib(first)
3081
- else if (graphLib) setGraphLib('')
3082
- }, [graphLib, libraryId, libraries])
3083
4432
  React.useEffect(() => {
3084
4433
  if (!detail) return undefined
3085
4434
  const onKey = (event) => { if (event.key === 'Escape') setDetail(null) }
@@ -3372,35 +4721,6 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3372
4721
  h(Button, { style: S.ghost, onClick: () => setDetail(null) }, t('close')))))
3373
4722
  : null
3374
4723
 
3375
- const validLib = (id) => id && libraries.some((lib) => lib.id === id) ? id : ''
3376
- // No private library is still a meaningful graph state: global edges do not
3377
- // belong to any library, so the selector defaults to them instead of an
3378
- // empty "no libraries" card.
3379
- const graphLibrary = graphLib === GLOBAL_GRAPH_ID || libraries.length === 0
3380
- ? GLOBAL_GRAPH_ID
3381
- : (validLib(graphLib) || validLib(libraryId) || libraries[0].id)
3382
- const showGlobalGraph = graphLibrary === GLOBAL_GRAPH_ID
3383
- const graphFiles = React.useMemo(() => items
3384
- .filter(item => showGlobalGraph ? item.libraryId === null : item.libraryId === graphLibrary)
3385
- .map(item => ({ id: item.id, title: item.title })), [items, graphLibrary, showGlobalGraph])
3386
- const graphView = h('div', { className: 'dshm-card dshm-wall-graph' },
3387
- h(React.Fragment, null,
3388
- h('div', { className: 'dshm-graph-tools' },
3389
- h('select', {
3390
- value: graphLibrary,
3391
- title: showGlobalGraph ? t('graphGlobalScope') : (libraries.find((lib) => lib.id === graphLibrary)?.scopeKey || t('currentLibrary')),
3392
- // One selection drives both views, otherwise the graph's focus list can
3393
- // be empty when the wall is filtered to a different library.
3394
- onChange: (event) => {
3395
- const value = event.target.value
3396
- setGraphLib(value)
3397
- if (value !== GLOBAL_GRAPH_ID) setLibraryId(value)
3398
- },
3399
- },
3400
- h('option', { key: GLOBAL_GRAPH_ID, value: GLOBAL_GRAPH_ID }, t('graphGlobalScope')),
3401
- libraries.map(lib => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries))))),
3402
- h(GraphPanel, { key: graphLibrary, call, libraryId: showGlobalGraph ? null : graphLibrary, files: graphFiles, t, global: showGlobalGraph })))
3403
-
3404
4724
  // Category filters used to reuse the compact nav pills (2px gap, 30px high) and
3405
4725
  // stacked directly on top of each other. Give every group its own segmented
3406
4726
  // control, a label and breathing room so the state/layer filters are distinct.
@@ -3484,12 +4804,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3484
4804
  })() : null
3485
4805
 
3486
4806
  return h('div', { className: 'dshm-wall' },
3487
- wallTabGroup([['memories', t('viewMemories')], ['relations', t('viewRelations')]], view, setView, { className: 'dshm-wall-views' }),
3488
4807
  error || data.errors?.length ? h('p', { className: 'dshm-error', role: 'alert' }, error || t('wallReadError')) : null,
3489
- view === 'relations'
3490
- ? graphView
3491
- : h(React.Fragment, null,
3492
- // 组分类:私有 / 全局(默认私有、私有靠前)。计数按各自的块算,切换即重置多选。
4808
+ h(React.Fragment, null,
4809
+ // 组分类:私有 / 全局(默认私有、私有靠前)。计数按各自的块算,切换即重置多选。
3493
4810
  // The library selector belongs to the scope row, not the search row: it
3494
4811
  // narrows the same private block the two tabs switch between.
3495
4812
  wallTabGroup(scopeItems, scope, (value) => { setScope(value); exitMulti() }, { label: t('wallFilterScope'), marginTop: 10, extra: librarySelect }),
@@ -3985,11 +5302,12 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
3985
5302
  prompts: 7,
3986
5303
  stats: 8,
3987
5304
  memories: 9,
3988
- // logs:10 之前缺失:SETTINGS_PAGES 里有 'logs' 但 PAGE 没有对应索引,
3989
- // 任何"跳到日志页"的入口都会错位到词典。补上,help 才能落在正确的 12。
3990
- logs: 10,
3991
- lexicon: 11,
3992
- help: 12,
5305
+ // graph:10 插在 memories 之后;后续页顺延,三处清单(SETTINGS_PAGES /
5306
+ // PAGE_NAMES / PAGE)必须同序,否则导航会整片错位。
5307
+ graph: 10,
5308
+ logs: 11,
5309
+ lexicon: 12,
5310
+ help: 13,
3993
5311
  }
3994
5312
  const call = useRpc(ctx)
3995
5313
  const sessionId = useCurrentSession(ctx)
@@ -4014,6 +5332,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
4014
5332
  const progressSpeedRef = React.useRef(new Map())
4015
5333
  // 全局记忆页"查看此记忆"的接力棒:带着 id 切到 MemU 记忆页,墙直接开对应抽屉。
4016
5334
  const [wallFocus, setWallFocus] = React.useState(null)
5335
+ // 关系图谱是沉浸式页面:默认解除 980px 宽度锁,用户还能收起左导航腾满宽度。
5336
+ const [graphNavHidden, setGraphNavHidden] = React.useState(false)
4017
5337
  // Success messages need their own slot: reusing `error` would paint a good
4018
5338
  // outcome in red and make the next real failure easy to miss.
4019
5339
  const [notice, setNotice] = React.useState('')
@@ -5668,6 +6988,12 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
5668
6988
  h(Field, { label: t('sleepAfterIdleMinutes') }, h('input', { type: 'number', min: 1, style: S.input, value: settings.sleepAfterIdleMinutes ?? 2, onChange: (e) => setSetting('sleepAfterIdleMinutes', Number(e.target.value)) })),
5669
6989
  h(Field, { label: t('autoCurateEveryHours') }, h('input', { type: 'number', min: 0, style: S.input, value: settings.autoCurateEveryHours ?? 0, onChange: (e) => setSetting('autoCurateEveryHours', Number(e.target.value)) })),
5670
6990
  h(Field, { label: t('autoCurateSessionLimit') }, h('input', { type: 'number', min: 1, max: 10, style: S.input, value: settings.autoCurateSessionLimit ?? 8, onChange: (e) => setSetting('autoCurateSessionLimit', Number(e.target.value)) })),
6991
+ h(Field, { label: t('autoLinkMode') },
6992
+ h('select', { style: S.input, value: settings.autoLinkMode || 'suggest', onChange: (e) => setSetting('autoLinkMode', e.target.value) },
6993
+ h('option', { value: 'suggest' }, t('autoLinkSuggest')),
6994
+ h('option', { value: 'deterministic' }, t('autoLinkDeterministic')),
6995
+ h('option', { value: 'off' }, t('autoLinkOff')))),
6996
+ h('div', { className: 'dshm-settings-note', style: { ...S.muted, marginTop: 6, lineHeight: 1.55 } }, t('autoLinkHint')),
5671
6997
  h(Field, { label: t('consolidationModelMode') },
5672
6998
  h('select', { style: S.input, value: consolidationMode, onChange: (e) => setSetting('consolidationModelMode', e.target.value) },
5673
6999
  h('option', { value: 'inherit' }, t('consolidationModeInherit')),
@@ -6406,6 +7732,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
6406
7732
  { label: t('pageStats'), overline: 'STATS', desc: t('descStats'), icon: GlyphChart },
6407
7733
  ]
6408
7734
  pageDefs.push({ label: t('pageMemories'), overline: 'MEMU', desc: t('descMemories'), icon: GlyphLayers })
7735
+ // 关系图谱是独立页,放在「MemU 记忆」下面一页;复用现有 glyph,不新增资产。
7736
+ pageDefs.push({ label: t('pageGraph'), overline: 'GRAPH', desc: t('descGraph'), icon: GlyphChart })
6409
7737
  pageDefs.push({ label: t('pageLogs'), overline: 'ACTIVITY', desc: t('descLogs'), icon: GlyphText })
6410
7738
  pageDefs.push({ label: t('pageLexicon'), overline: 'LEXICON', desc: t('descLexicon'), icon: GlyphStack })
6411
7739
  pageDefs.push({ label: t('pageHelp'), overline: 'GUIDE', desc: t('descHelp'), icon: GlyphQuestion })
@@ -6428,6 +7756,12 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
6428
7756
  if (item.libraryId) { setBrowseLibId(item.libraryId); setPage(PAGE.browser); void openBrowser(item.libraryId) }
6429
7757
  else setPage(PAGE.global)
6430
7758
  } }))
7759
+ // 关系图谱独立成页:库/全局选择器由 GraphStudioPanel 自持,刷新随 SettingsPage
7760
+ // 已有的心跳(revision/stamp)走 beat,页内不再开第二套轮询。
7761
+ const graphBlock = h(GraphStudioPanel, {
7762
+ call, libraries: state.libraries || [], revision: state.revision, stamp: state.stamp, t,
7763
+ navHidden: graphNavHidden, onToggleNav: () => setGraphNavHidden(value => !value),
7764
+ })
6431
7765
  // 词典页:sourceMemoryId →「来源记忆 ↗」复用全局记忆页的 wallFocus 接力棒,
6432
7766
  // 跳到 MemU 记忆页并直接打开对应条目的抽屉。
6433
7767
  const lexiconBlock = h(LexiconPanel, {
@@ -6640,19 +7974,28 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
6640
7974
  row.detail
6641
7975
  ? h('pre', { style: { ...S.muted, margin: '6px 0 0', fontSize: 11, whiteSpace: 'pre-wrap', wordBreak: 'break-all' } }, JSON.stringify(row.detail).slice(0, 600))
6642
7976
  : null)))))
6643
- const pageBlocks = [engineBlock, connectionBlock, settingsBlock, foldersBlock, librariesBlock, browserBlock, globalBlock, promptsBlock, statsBlock, memoriesBlock, logsBlock, lexiconBlock, helpBlock]
7977
+ const pageBlocks = [engineBlock, connectionBlock, settingsBlock, foldersBlock, librariesBlock, browserBlock, globalBlock, promptsBlock, statsBlock, memoriesBlock, graphBlock, logsBlock, lexiconBlock, helpBlock]
6644
7978
 
6645
7979
  // Settings uses a left nav with a sliding indicator (the sidebar keeps its
6646
7980
  // top segments). The indicator is one absolutely-positioned element moved by
6647
7981
  // a transform, so the active item animates without per-item flicker.
6648
7982
  const active = pageDefs[page] || pageDefs[0]
7983
+ const graphWide = page === PAGE.graph
6649
7984
  return h('div', {
6650
- className: 'dshm-root',
7985
+ className: `dshm-root${graphWide ? ' is-graph-wide' : ''}${graphWide && graphNavHidden ? ' is-graph-navless' : ''}`,
6651
7986
  'data-dshm-surface': embedded ? 'sidebar' : 'dialog',
6652
7987
  style: { '--dshm-nav-h': `${NAV_ITEM_H}px`, '--dshm-nav-gap': `${NAV_GAP}px` },
6653
7988
  },
6654
7989
  h('div', { className: 'dshm-shell' },
6655
7990
  h('nav', { className: 'dshm-nav', role: 'tablist', 'aria-orientation': 'vertical' },
7991
+ // 贴在左导航右边缘的收起小块:收起后本身仍留一条窄边,可随时展开。
7992
+ graphWide ? h('button', {
7993
+ type: 'button', className: 'dshm-nav-handle',
7994
+ title: graphNavHidden ? t('gsShowNav') : t('gsHideNav'),
7995
+ 'aria-label': graphNavHidden ? t('gsShowNav') : t('gsHideNav'),
7996
+ 'aria-expanded': String(!graphNavHidden),
7997
+ onClick: () => setGraphNavHidden(value => !value),
7998
+ }, graphNavHidden ? '›' : '‹') : null,
6656
7999
  h('div', { className: 'dshm-brand' },
6657
8000
  h('div', { className: 'dshm-brand-tile' }, h('img', { src: '/dsh-memu-memory/ui-assets/icon.png', alt: '', width: 32, height: 32 })),
6658
8001
  h('div', { style: { minWidth: 0 } },