dsh-mcp-skills-controller 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -57,6 +57,7 @@ window.__ModuleLoader__.load({
57
57
  'mcp.disconnected': '未连接',
58
58
  'mcp.connected': '已连接',
59
59
  'mcp.tools': '个工具',
60
+ 'mcp.toolGroup': '工具',
60
61
  'skills.empty': '没有可见的 skills',
61
62
  'skills.incomplete': '清单可能不完整',
62
63
  'settings.title': 'MCP & Skills 全局默认',
@@ -64,6 +65,12 @@ window.__ModuleLoader__.load({
64
65
  'section.mcp': 'MCP 服务器',
65
66
  'section.skills': 'Skills',
66
67
  'action.refresh': '刷新',
68
+ 'action.orphans': '清理孤立覆盖',
69
+ 'action.orphansClean': '确认清理',
70
+ 'action.cancel': '取消',
71
+ 'orphans.confirm': '将清理孤立会话覆盖:',
72
+ 'orphans.none': '没有孤立会话覆盖',
73
+ 'orphans.cleaned': '已清理孤立会话覆盖',
67
74
  'action.expand': '展开详情',
68
75
  'action.collapse': '收起详情',
69
76
  'action.reveal': '所在目录',
@@ -106,6 +113,7 @@ window.__ModuleLoader__.load({
106
113
  'mcp.disconnected': 'not connected',
107
114
  'mcp.connected': 'Connected',
108
115
  'mcp.tools': 'tools',
116
+ 'mcp.toolGroup': 'Tools',
109
117
  'skills.empty': 'No skills are visible',
110
118
  'skills.incomplete': 'The skill list may be incomplete',
111
119
  'settings.title': 'MCP & Skills defaults',
@@ -113,6 +121,12 @@ window.__ModuleLoader__.load({
113
121
  'section.mcp': 'MCP servers',
114
122
  'section.skills': 'Skills',
115
123
  'action.refresh': 'Refresh',
124
+ 'action.orphans': 'Clean orphan overrides',
125
+ 'action.orphansClean': 'Clean',
126
+ 'action.cancel': 'Cancel',
127
+ 'orphans.confirm': 'Overrides to remove:',
128
+ 'orphans.none': 'No orphaned session overrides',
129
+ 'orphans.cleaned': 'Orphaned overrides removed',
116
130
  'action.expand': 'Show details',
117
131
  'action.collapse': 'Hide details',
118
132
  'action.reveal': 'Folder',
@@ -298,8 +312,8 @@ window.__ModuleLoader__.load({
298
312
  return React.createElement(SpriteIcon, { name: 'skill-outline', size })
299
313
  }
300
314
 
301
- /** 小箭头:官方 chevron-down-outline,展开时由外层旋转。 */
302
- function Caret({ size = 12, className }) {
315
+ /** 小箭头:官方 chevron-down-outline;14px / caption 色,不随菜单旋转,对齐 agent preset seat。 */
316
+ function Caret({ size = 14, className }) {
303
317
  return React.createElement(SpriteIcon, { name: 'chevron-down-outline', size, className })
304
318
  }
305
319
 
@@ -311,11 +325,12 @@ window.__ModuleLoader__.load({
311
325
  // #endregion
312
326
 
313
327
  // 会话级按钮与浮层:逐值照抄官方基准 ——
314
- // · trigger 取 primitives Button size sm(28px 高、radius-sm 8px、12px/18px、
315
- // padding 0 10px、gap 4px)+ ghost 交互填充(hover interactive-bg-hover、
316
- // active interactive-bg-active、disabled 0.4),caret 旋转 120ms ease
317
- // (switcherTrigger 的 caret 动画基准);状态词「全开/n/m」是普通次级
318
- // 文字,不加徽标底 —— 对齐「2 个子智能体」的纯文字排布。
328
+ // · trigger 对齐 ui-agent-preset 的 seat(28px 高、radius-sm 8px、
329
+ // 13px/20px、padding 0 8px、gap 4px)+ ghost 交互填充(hover 与
330
+ // 打开态都用 interactive-bg-hover,无 :active 高亮、disabled 0.4);
331
+ // caret 取官方 14px chevron-down-outline、label-caption 色,不随菜单旋转;
332
+ // 状态词「全开/n/m」是普通次级文字,不加徽标底 —— 对齐「2 个子智能体」
333
+ // 的纯文字排布。
319
334
  // · 浮层容器取 MenuSurface + SubagentCatalog.menu:radius-lg 16px、
320
335
  // menu-surface-fill 半透明底 + blur(40px) saturate(150%) 毛玻璃、
321
336
  // elevation-prominent 描边阴影(0.5px 发丝描边画在 box-shadow 里)、
@@ -330,18 +345,17 @@ window.__ModuleLoader__.load({
330
345
  .msc-wrap { position: relative; display: inline-flex; flex: none; align-self: center; }
331
346
  .msc-trigger {
332
347
  box-sizing: border-box; display: inline-flex; align-items: center; gap: 4px;
333
- min-height: 28px; padding: 0 10px; max-width: 240px;
348
+ min-height: 28px; padding: 0 8px; max-width: 240px;
334
349
  border: none; border-radius: var(--dsw-radius-sm); outline: none;
335
350
  background: transparent; color: var(--dsw-alias-label-primary);
336
- font-family: var(--dsw-font-family); font-size: 12px; line-height: 18px; font-weight: 500;
351
+ font-family: var(--dsw-font-family); font-size: 13px; line-height: 20px; font-weight: 500;
337
352
  white-space: nowrap; cursor: pointer;
338
353
  }
339
354
  @media (hover: hover) {
340
355
  .msc-trigger:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover); }
341
356
  }
342
- .msc-trigger:active:not(:disabled) { background: var(--dsw-alias-interactive-bg-active); }
343
357
  .msc-trigger[data-open="true"] {
344
- background: var(--dsw-alias-interactive-bg-active);
358
+ background: var(--dsw-alias-interactive-bg-hover);
345
359
  color: var(--dsw-alias-label-primary);
346
360
  }
347
361
  .msc-trigger:focus-visible { box-shadow: 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary)); }
@@ -352,15 +366,14 @@ window.__ModuleLoader__.load({
352
366
  .msc-trigger[data-none="true"] .msc-state { color: var(--dsw-alias-label-caption); }
353
367
  .msc-caret {
354
368
  flex: none; display: inline-flex; align-items: center;
355
- color: var(--dsw-alias-label-secondary);
356
- transition: transform 120ms ease;
369
+ color: var(--dsw-alias-label-caption);
357
370
  }
358
- .msc-trigger[data-open="true"] .msc-caret { transform: rotate(180deg); }
359
371
  /* 浮层:MenuSurface 材质(毛玻璃 + prominent 阴影)+ subagent 菜单几何。 */
360
372
  .msc-menu {
361
373
  position: absolute; top: calc(100% + 5px); right: 0; z-index: 100;
362
374
  box-sizing: border-box;
363
375
  width: 360px; max-height: min(560px, calc(100dvh - 140px)); overflow-y: auto;
376
+ overscroll-behavior: contain;
364
377
  padding: 6px;
365
378
  border-radius: var(--dsw-radius-lg);
366
379
  background: var(--dsw-menu-surface-fill, var(--dsw-alias-bg-overlay));
@@ -369,6 +382,15 @@ window.__ModuleLoader__.load({
369
382
  font-size: 12px; line-height: 17px;
370
383
  color: var(--dsw-alias-label-primary);
371
384
  }
385
+ /* 浮层内部滚动但不显示滚动条:360px 的窄面板里滚动条会挤压内容,也破坏
386
+ 毛玻璃边缘;滚轮 / 触控板 / 键盘(PageUp/PageDown)仍可正常滚动。 */
387
+ .msc-menu {
388
+ scrollbar-width: none;
389
+ -ms-overflow-style: none;
390
+ }
391
+ .msc-menu::-webkit-scrollbar { width: 0; height: 0; display: none; }
392
+ /* hero 在视口底部附近时向上开,max-height 由 measureMenu 实时写入 inline style。 */
393
+ .msc-menu[data-side="top"] { top: auto; bottom: calc(100% + 5px); }
372
394
  .msc-head {
373
395
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
374
396
  flex-wrap: wrap;
@@ -416,6 +438,16 @@ window.__ModuleLoader__.load({
416
438
  .msc-item:hover { background: var(--dsw-alias-interactive-bg-hover); }
417
439
  }
418
440
  .msc-item[data-busy="true"] { opacity: .4; }
441
+ /* 会话行外层:主行 + 可选展开的工具组,两者纵向排列。 */
442
+ .msc-itemWrap { display: flex; flex-direction: column; min-width: 0; }
443
+ .msc-itemActions { display: inline-flex; align-items: center; gap: 4px; flex: none; align-self: center; }
444
+ /* 行内开关容器:只做事件隔离,不改变布局。 */
445
+ .msc-itemSwitch { display: inline-flex; align-items: center; }
446
+ /* 可展开的会话行:整行可点(三角、连接点、标题都算),开关区除外。 */
447
+ .msc-item[data-expandable="true"] { cursor: pointer; }
448
+ /* 会话行展开的工具组:缩进到服务器名下方,与主行留出一点间距。 */
449
+ .msc-itemTools { display: flex; flex-direction: column; padding: 0 6px 6px 30px; min-width: 0; }
450
+ .msc-itemTools .msc-toolRow { padding: 2px 0; }
419
451
  .msc-itemSlot {
420
452
  display: inline-flex; flex: none;
421
453
  align-items: center; justify-content: center;
@@ -498,6 +530,12 @@ window.__ModuleLoader__.load({
498
530
  .msc-page { box-sizing: border-box; display: flex; flex-direction: column; gap: 24px; max-width: 720px; color: var(--dsw-alias-label-primary); }
499
531
  .msc-pageHead { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
500
532
  .msc-pageHeaderText { display: flex; flex-direction: column; gap: 4px; }
533
+ .msc-pageActions { display: flex; flex: none; align-items: center; gap: 8px; }
534
+ .msc-orphanBar {
535
+ display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
536
+ margin-top: 8px; font-size: 13px; line-height: 20px;
537
+ color: var(--dsw-alias-label-secondary);
538
+ }
501
539
  .msc-pageTitle { margin: 0; font-size: 16px; line-height: 24px; font-weight: 500; color: var(--dsw-alias-label-primary); }
502
540
  .msc-intro { margin: 0; font-size: 14px; line-height: 22px; color: var(--dsw-alias-label-tertiary); }
503
541
  .msc-section { display: flex; flex-direction: column; }
@@ -563,7 +601,8 @@ window.__ModuleLoader__.load({
563
601
  color: var(--dsw-alias-label-secondary); font-size: 12px; line-height: 18px;
564
602
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
565
603
  }
566
- .msc-tag, .msc-tool {
604
+ /* 未连接徽标(服务器行)。工具组样式见下方 .msc-tool*。 */
605
+ .msc-tag {
567
606
  flex: none; display: inline-flex; align-items: center;
568
607
  padding: 1px 6px;
569
608
  border: 0.5px solid var(--dsw-alias-border-l3); border-radius: var(--dsw-radius-xs, 4px);
@@ -580,6 +619,8 @@ window.__ModuleLoader__.load({
580
619
  }
581
620
  .msc-detailsChevron { transition: transform 160ms ease; }
582
621
  .msc-row[data-open="true"] .msc-detailsChevron { transform: rotate(180deg); }
622
+ /* 会话行的展开三角走同一个类名,但外层是 .msc-item。 */
623
+ .msc-item[data-open="true"] .msc-detailsChevron { transform: rotate(180deg); }
583
624
  /* 展开详情:与主行同宽;描述允许换行,路径允许任意位置折行。 */
584
625
  .msc-rowDetail { display: flex; flex-direction: column; gap: 6px; padding: 0 0 12px; }
585
626
  .msc-detailDesc {
@@ -588,7 +629,24 @@ window.__ModuleLoader__.load({
588
629
  }
589
630
  .msc-detailMeta { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }
590
631
  .msc-detailEmpty { color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; }
591
- .msc-toolList { display: flex; flex-wrap: wrap; gap: 6px; }
632
+ /* 工具组:设置页展开区与会话浮层共用。组头一行(小标题 + 恢复跟随 + 三态开关),
633
+ 下面是逐工具行:裸名 + 单行描述 + 三态控件(设置页右侧同款开关)。 */
634
+ .msc-toolHead { display: flex; align-items: center; gap: 8px; padding: 2px 0 6px; }
635
+ .msc-toolHeadTitle {
636
+ font-size: 11px; line-height: 16px; font-weight: 500;
637
+ color: var(--dsw-alias-label-tertiary);
638
+ }
639
+ .msc-toolRows { display: flex; flex-direction: column; gap: 2px; }
640
+ .msc-toolRow { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 3px 0; }
641
+ .msc-toolBody { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
642
+ .msc-toolName {
643
+ font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-primary);
644
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
645
+ }
646
+ .msc-toolDesc {
647
+ font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary);
648
+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
649
+ }
592
650
  .msc-pathRow { display: flex; align-items: flex-start; gap: 10px; margin-top: 2px; }
593
651
  /* 长路径会折行;动作按钮不参与收缩,避免「所在目录」被压成两行。 */
594
652
  .msc-pathRow .msc-actionButton { flex: none; white-space: nowrap; }
@@ -701,6 +759,49 @@ window.__ModuleLoader__.load({
701
759
  }, React.createElement(RestoreGlyph)))
702
760
  }
703
761
 
762
+ /** 工具行:裸名 + 单行描述 + 三态控件。设置页与会话浮层共用。
763
+ * valueKey:全局视图传 'enabled',会话视图传 'effective'——两者都是「当前
764
+ * 实际状态」,控件显示它;显式覆盖时另出现 ↺ 恢复跟随。 */
765
+ function ToolRow({ tool, valueKey, busy, onSet, t }) {
766
+ const name = tool.rawName ?? tool.name
767
+ return React.createElement('div', { className: 'msc-toolRow', 'data-busy': String(busy) },
768
+ React.createElement('div', { className: 'msc-toolBody' },
769
+ React.createElement('div', { className: 'msc-toolName', title: tool.name }, name),
770
+ tool.description
771
+ ? React.createElement('div', { className: 'msc-toolDesc', title: tool.description }, tool.description)
772
+ : null),
773
+ React.createElement(ModeControl, {
774
+ checked: tool[valueKey] === true,
775
+ name,
776
+ busy: busy === true,
777
+ followable: tool.mode !== 'follow',
778
+ onFollow: () => { onSet(tool, 'follow') },
779
+ onChange: (mode) => { onSet(tool, mode) },
780
+ t,
781
+ }))
782
+ }
783
+
784
+ /** 工具组头:只显示「工具 on/total」。整组开关由服务器开关承担(点击会清掉
785
+ * 该服务器的工具级例外),这里不再放第二个「全开」开关,避免语义重叠。 */
786
+ function ToolGroupSummary({ tools, valueKey, t }) {
787
+ const on = tools.filter((tool) => tool[valueKey] === true).length
788
+ return React.createElement('div', { className: 'msc-toolHead' },
789
+ React.createElement('span', { className: 'msc-toolHeadTitle' },
790
+ `${t('mcp.toolGroup')} ${on}/${tools.length}`))
791
+ }
792
+
793
+ /**
794
+ * 服务器行的显示状态:以工具聚合为准。没有工具时退回服务器层;
795
+ * 全开 true / 全关 false / 部分开启 'mixed'(= 存在工具级例外)。
796
+ */
797
+ function serverStateOf(row, valueKey) {
798
+ const stats = row?.toolStats
799
+ if (stats === undefined || stats.total === 0) return row?.[valueKey] === true
800
+ if (stats.on === stats.total) return true
801
+ if (stats.on === 0) return false
802
+ return 'mixed'
803
+ }
804
+
704
805
  /** skills 行共用的悬停摘要:来源、provider 与调用面只进 title,不占版面。 */
705
806
  function skillTip(item) {
706
807
  const inv = item.invocation
@@ -750,10 +851,38 @@ window.__ModuleLoader__.load({
750
851
  const { sessionId, kind, t, glyph, title, renderRow, renderEmpty, foot } = props
751
852
 
752
853
  const [open, setOpen] = React.useState(false)
854
+ // 展开到工具行的服务器名集合:纯 UI 状态,不写 RPC、不落盘,刷新不重置。
855
+ const [toolsOpen, setToolsOpen] = React.useState(() => new Set())
856
+ // 浮层相对触发器的放置:hero 靠近视口底部时向上开,并按可用高度实时限高,
857
+ // 避免绝对定位的菜单把整页撑出滚动条。
858
+ const [menu, setMenu] = React.useState({ side: 'bottom', maxHeight: 560 })
753
859
  // 正在写入的项:'all' 或 '<kind>:<name>';只有该行(或全部)置灰,不锁整组。
754
860
  const [busyKey, setBusyKey] = React.useState()
755
861
  const rootRef = React.useRef(null)
756
862
 
863
+ /**
864
+ * 按触发器在视口中的位置选上下方向,并把菜单限高到可用空间。
865
+ * 可用空间不足时,内容在菜单内部滚动,而不是把整个页面撑出滚动条。
866
+ */
867
+ const measureMenu = React.useCallback(() => {
868
+ const root = rootRef.current
869
+ const trigger = root?.firstElementChild
870
+ if (!(trigger instanceof Element)) return
871
+ const rect = trigger.getBoundingClientRect()
872
+ const viewport = window.innerHeight
873
+ const gap = 5
874
+ const margin = 12
875
+ const below = viewport - rect.bottom - gap - margin
876
+ const above = rect.top - gap - margin
877
+ const side = below >= above ? 'bottom' : 'top'
878
+ const available = Math.max(0, side === 'bottom' ? below : above)
879
+ // 至少保留一个可用高度;正常情况下选中的一侧有半个视口以上。
880
+ const maxHeight = Math.max(120, Math.min(560, available))
881
+ setMenu((current) => (current.side === side && current.maxHeight === maxHeight
882
+ ? current
883
+ : { side, maxHeight }))
884
+ }, [])
885
+
757
886
  // 覆盖按会话 id 保存;槽还没给出会话时没有可写的键。
758
887
  const scoped = sessionId !== undefined && sessionId !== null && String(sessionId) !== ''
759
888
  const sessionKey = scoped ? String(sessionId) : ''
@@ -798,6 +927,22 @@ window.__ModuleLoader__.load({
798
927
  const items = kind === 'mcp' ? group?.servers ?? [] : group?.skills ?? []
799
928
  const effectiveCount = items.reduce((sum, item) => sum + (item.effective === true ? 1 : 0), 0)
800
929
 
930
+ // 打开时、清单长度变化、展开工具组或窗口缩放/滚动时重新量一次。
931
+ React.useLayoutEffect(() => {
932
+ if (open) measureMenu()
933
+ }, [open, measureMenu, items.length, toolsOpen.size])
934
+
935
+ React.useEffect(() => {
936
+ if (!open) return undefined
937
+ const update = () => measureMenu()
938
+ window.addEventListener('resize', update)
939
+ window.addEventListener('scroll', update, true)
940
+ return () => {
941
+ window.removeEventListener('resize', update)
942
+ window.removeEventListener('scroll', update, true)
943
+ }
944
+ }, [open, measureMenu])
945
+
801
946
  // 徽标只放短状态:全开 / 全关 / n/m;无条目或会话未知用 '—',
802
947
  // 读取中用 '…'。完整说明留在浮层里,长句会把 220px 触发器撑破。
803
948
  const label = !scoped
@@ -856,6 +1001,16 @@ window.__ModuleLoader__.load({
856
1001
  })
857
1002
  }
858
1003
 
1004
+ /** 展开 / 收起某个服务器的工具组(纯 UI 状态)。 */
1005
+ const toggleTools = (name) => {
1006
+ setToolsOpen((current) => {
1007
+ const next = new Set(current)
1008
+ if (next.has(name)) next.delete(name)
1009
+ else next.add(name)
1010
+ return next
1011
+ })
1012
+ }
1013
+
859
1014
  return React.createElement('div', { className: 'msc-wrap', ref: rootRef },
860
1015
  React.createElement('button', {
861
1016
  type: 'button',
@@ -878,6 +1033,8 @@ window.__ModuleLoader__.load({
878
1033
  className: 'msc-menu',
879
1034
  role: 'dialog',
880
1035
  'aria-label': title,
1036
+ 'data-side': menu.side,
1037
+ style: { maxHeight: `${menu.maxHeight}px` },
881
1038
  },
882
1039
  React.createElement('div', { className: 'msc-head' },
883
1040
  React.createElement('span', null, scoped ? t('scope.session') : t('scope.default')),
@@ -917,8 +1074,12 @@ window.__ModuleLoader__.load({
917
1074
  items.map((item) => renderRow({
918
1075
  item,
919
1076
  busy: busyKey === 'all' || busyKey === `${kind}:${item.name}`,
1077
+ busyKey,
920
1078
  setMode,
921
1079
  t,
1080
+ // 只有 MCP 行用到:展开工具组的纯 UI 状态与切换回调。
1081
+ toolsOpen: toolsOpen.has(item.name),
1082
+ onToggleTools: () => { toggleTools(item.name) },
922
1083
  })),
923
1084
 
924
1085
  error !== undefined && React.createElement('div', { className: 'msc-err', role: 'alert' }, error),
@@ -927,17 +1088,24 @@ window.__ModuleLoader__.load({
927
1088
  foot?.(group)))
928
1089
  }
929
1090
 
930
- /** MCP 会话行:CatalogTree 行基准 —— 连接状态点 + 标题/副行 + 右侧三态控件。 */
931
- function renderMcpRow({ item, busy, setMode, t }) {
1091
+ /** MCP 会话行:CatalogTree 行基准 —— 连接点 + 标题/副行 + 展开三角 + 三态控件。
1092
+ * 服务器控件以工具聚合为准:全开 / 全关 / 部分(有工具级例外)。 */
1093
+ function renderMcpRow({ item, busy, busyKey, setMode, t, toolsOpen, onToggleTools }) {
932
1094
  // 副标题只放能一眼比较的短信息;完整 target 塞进 title(长命令被截断反而难辨认)。
933
1095
  const toolsPart = typeof item.tools === 'number' ? `${item.tools} ${t('mcp.tools')}` : ''
934
1096
  const meta = [toolsPart, item.transport]
935
1097
  .filter((part) => part !== undefined && part !== null && part !== '')
936
1098
  .join(' · ')
937
- return React.createElement('div', {
938
- key: item.name,
1099
+ const toolRows = Array.isArray(item.toolRows) ? item.toolRows : []
1100
+ const serverState = serverStateOf(item, 'effective')
1101
+ return React.createElement('div', { key: item.name, className: 'msc-itemWrap' },
1102
+ React.createElement('div', {
939
1103
  className: 'msc-item',
940
1104
  'data-busy': String(busy),
1105
+ 'data-open': String(toolsOpen),
1106
+ 'data-expandable': 'true',
1107
+ // 整行(连接点、标题、三角)都是展开目标;只有开关区阻止冒泡。
1108
+ onClick: onToggleTools,
941
1109
  title: item.target ? `${item.name} — ${item.target}` : item.name,
942
1110
  },
943
1111
  // StateDot 语义:连接=success 绿点、未连接=error 红点(对照子代理行的运行/停止)。
@@ -948,24 +1116,58 @@ window.__ModuleLoader__.load({
948
1116
  role: 'img',
949
1117
  'aria-label': item.connected === true ? t('mcp.connected') : t('mcp.disconnected'),
950
1118
  })),
951
- React.createElement('div', { className: 'msc-itemBody' },
1119
+ React.createElement('div', {
1120
+ className: 'msc-itemBody',
1121
+ role: 'button',
1122
+ tabIndex: 0,
1123
+ 'aria-expanded': String(toolsOpen),
1124
+ onKeyDown: (event) => {
1125
+ if (event.key !== 'Enter' && event.key !== ' ') return
1126
+ event.preventDefault()
1127
+ onToggleTools()
1128
+ },
1129
+ },
952
1130
  React.createElement('div', { className: 'msc-itemLabel' },
953
1131
  React.createElement('span', { className: 'msc-itemName' }, item.name)),
954
1132
  React.createElement('div', { className: 'msc-itemSecondary' },
955
1133
  React.createElement('span', { className: 'msc-itemSecondaryMain' }, meta),
956
1134
  React.createElement('span', { className: 'msc-itemSecondaryGlob' },
957
1135
  item.global === true ? t('global.on') : t('global.off')))),
1136
+ React.createElement('div', { className: 'msc-itemActions' },
1137
+ React.createElement(ExpandIndicator, { open: toolsOpen, t }),
1138
+ React.createElement('span', {
1139
+ className: 'msc-itemSwitch',
1140
+ // 开关与 ↺ 是行内独立动作:不让它们触发整行的展开/收起。
1141
+ onClick: (event) => { event.stopPropagation() },
1142
+ },
958
1143
  React.createElement(ModeControl, {
959
- // 控件显示「当前实际生效值」:无覆盖时即全局状态;有覆盖时是显式值,
960
- // 此时出现 ↺ 单项恢复跟随。
961
- checked: item.effective === true,
1144
+ // 服务器控件显示工具聚合值:部分开启 = 有工具级例外;点击即整组重置
1145
+ // (宿主会清掉该服务器的工具例外),所以这里不另设工具组开关。
1146
+ checked: serverState,
962
1147
  name: item.name,
963
1148
  busy,
964
1149
  followable: item.mode !== 'follow',
965
1150
  onFollow: () => { void setMode(item, 'follow') },
966
1151
  onChange: (mode) => { void setMode(item, mode) },
967
1152
  t,
968
- }))
1153
+ })))),
1154
+ toolsOpen && React.createElement('div', { className: 'msc-itemTools' },
1155
+ toolRows.length === 0
1156
+ ? React.createElement('div', { className: 'msc-foot' }, t('mcp.noTools'))
1157
+ : React.createElement('div', { className: 'msc-toolRows' },
1158
+ React.createElement(ToolGroupSummary, {
1159
+ tools: toolRows,
1160
+ valueKey: 'effective',
1161
+ t,
1162
+ }),
1163
+ toolRows.map((tool) => React.createElement(ToolRow, {
1164
+ key: tool.name,
1165
+ tool,
1166
+ valueKey: 'effective',
1167
+ busy: busyKey === 'all' || busyKey === `mcp:${tool.name}`,
1168
+ onSet: (entry, mode) => { setMode({ name: entry.name }, mode) },
1169
+ t,
1170
+ })))))
969
1171
  }
970
1172
 
971
1173
  /** Skills 会话行:标题=skill 名(项目级带「项目」标签),副行=描述单行省略。 */
@@ -1048,6 +1250,9 @@ window.__ModuleLoader__.load({
1048
1250
  const [expanded, setExpanded] = React.useState(() => new Set())
1049
1251
  // 正在打开目录的技能名;只禁用对应按钮,不阻塞开关。
1050
1252
  const [revealing, setRevealing] = React.useState()
1253
+ // 孤立会话覆盖:undefined 表示没有待确认清单;数组为只读预览结果。
1254
+ const [orphans, setOrphans] = React.useState()
1255
+ const [orphanBusy, setOrphanBusy] = React.useState(false)
1051
1256
 
1052
1257
  // 全局默认快照:挂载与每次手动刷新都读。
1053
1258
  const snapshot = useSnapshot(
@@ -1107,9 +1312,71 @@ window.__ModuleLoader__.load({
1107
1312
  })
1108
1313
  }
1109
1314
 
1315
+ /** 写工具层全局三态(/global/set + mode;_follow_ 删除工具记录)。 */
1316
+ const setGlobalTool = (tool, mode) => {
1317
+ if (busyKey !== undefined) return
1318
+ void runMutation({
1319
+ requestRef,
1320
+ setBusyKey,
1321
+ setError,
1322
+ setNotice,
1323
+ busy: `mcp:${tool.name}`,
1324
+ run: () => api('/global/set', {
1325
+ method: 'POST',
1326
+ payload: { kind: 'mcp', item: tool.name, mode },
1327
+ }),
1328
+ onSuccess: (payload) => {
1329
+ setState({ phase: 'ready', data: payload })
1330
+ if (payload.persisted === false) setNotice(t('state.unsaved'))
1331
+ },
1332
+ })
1333
+ }
1334
+
1335
+ /** 只读预览孤立会话覆盖;有结果时进入确认条,不直接删除。 */
1336
+ const checkOrphans = async () => {
1337
+ if (orphanBusy) return
1338
+ setOrphanBusy(true)
1339
+ setError(undefined)
1340
+ setNotice(undefined)
1341
+ try {
1342
+ const payload = await api('/maintenance/orphans', {})
1343
+ const rows = Array.isArray(payload.orphans) ? payload.orphans : []
1344
+ if (rows.length === 0) {
1345
+ setOrphans(undefined)
1346
+ setNotice(t('orphans.none'))
1347
+ } else {
1348
+ setOrphans(rows)
1349
+ }
1350
+ } catch (reason) {
1351
+ setError(reason instanceof Error ? reason.message : String(reason))
1352
+ } finally {
1353
+ setOrphanBusy(false)
1354
+ }
1355
+ }
1356
+
1357
+ /** 确认后清理;宿主重新校验会话存在性,返回最新全局快照。 */
1358
+ const cleanOrphans = async () => {
1359
+ if (orphanBusy || orphans === undefined) return
1360
+ setOrphanBusy(true)
1361
+ setError(undefined)
1362
+ setNotice(undefined)
1363
+ try {
1364
+ const payload = await api('/maintenance/orphans/clean', { method: 'POST' })
1365
+ setState({ phase: 'ready', data: payload })
1366
+ setOrphans(undefined)
1367
+ const count = Array.isArray(payload.removed) ? payload.removed.length : 0
1368
+ setNotice(payload.persisted === false
1369
+ ? t('state.unsaved')
1370
+ : `${t('orphans.cleaned')} ${count}`)
1371
+ } catch (reason) {
1372
+ setError(reason instanceof Error ? reason.message : String(reason))
1373
+ } finally {
1374
+ setOrphanBusy(false)
1375
+ }
1376
+ }
1377
+
1110
1378
  /** 展开 / 收起某一行;刷新数据不会重置展开状态。 */
1111
- const toggleExpanded = (kind, name) => {
1112
- setExpanded((current) => {
1379
+ const toggleExpanded = (kind, name) => { setExpanded((current) => {
1113
1380
  const next = new Set(current)
1114
1381
  const key = `${kind}:${name}`
1115
1382
  if (next.has(key)) next.delete(key)
@@ -1166,14 +1433,16 @@ window.__ModuleLoader__.load({
1166
1433
  }))
1167
1434
  }
1168
1435
 
1169
- /** 全局 MCP 行:主行(题 + 说明 + 展开/开关)+ 展开后的工具列表。 */
1436
+ /** 全局 MCP 行:主行(题 + 说明 + 展开/开关)+ 展开后的工具行。
1437
+ * 服务器开关以工具聚合为准,点击整组重置(宿主清掉工具例外)。 */
1170
1438
  const renderMcpRow = (server) => {
1171
1439
  const open = isExpanded('mcp', server.name)
1172
1440
  const toolsPart = typeof server.tools === 'number' ? `${server.tools} ${t('mcp.tools')}` : ''
1173
1441
  const meta = [toolsPart, server.transport]
1174
1442
  .filter((part) => part !== undefined && part !== null && part !== '')
1175
1443
  .join(' · ')
1176
- const toolNames = Array.isArray(server.toolNames) ? server.toolNames : []
1444
+ const toolRows = Array.isArray(server.toolRows) ? server.toolRows : []
1445
+ const serverState = serverStateOf(server, 'enabled')
1177
1446
  return React.createElement('div', {
1178
1447
  key: server.name,
1179
1448
  className: 'msc-row',
@@ -1201,25 +1470,33 @@ window.__ModuleLoader__.load({
1201
1470
  React.createElement('div', { className: 'msc-rowActions' },
1202
1471
  React.createElement(ExpandIndicator, { open, t }),
1203
1472
  React.createElement(SwitchButton, {
1204
- checked: server.enabled === true,
1473
+ checked: serverState,
1205
1474
  label: server.name,
1206
1475
  disabled: busyKey !== undefined,
1207
1476
  onClick: (event) => {
1208
1477
  // 开关是行内独立动作:阻止冒泡,避免点开关时同时展开/收起详情。
1209
1478
  event.stopPropagation()
1210
- void setGlobal('mcp', server.name, server.enabled !== true)
1479
+ // 部分开启(有工具例外)视作「未全开」,点一下整组打开。
1480
+ void setGlobal('mcp', server.name, serverState !== true)
1211
1481
  },
1212
1482
  }))),
1213
1483
  open && React.createElement('div', { className: 'msc-rowDetail' },
1214
- toolNames.length === 0
1484
+ toolRows.length === 0
1215
1485
  ? React.createElement('div', { className: 'msc-detailEmpty' }, t('mcp.noTools'))
1216
- : React.createElement('div', { className: 'msc-toolList' },
1217
- toolNames.map((toolName) => React.createElement('span', {
1218
- key: toolName,
1219
- className: 'msc-tool',
1220
- // 展开区显示裸工具名;完整公开名留作 hover,便于核对或复制。
1221
- title: `mcp__${server.name}__${toolName}`,
1222
- }, toolName)))))
1486
+ : React.createElement('div', { className: 'msc-toolRows' },
1487
+ React.createElement(ToolGroupSummary, {
1488
+ tools: toolRows,
1489
+ valueKey: 'enabled',
1490
+ t,
1491
+ }),
1492
+ toolRows.map((tool) => React.createElement(ToolRow, {
1493
+ key: tool.name,
1494
+ tool,
1495
+ valueKey: 'enabled',
1496
+ busy: busyKey === `mcp:${tool.name}`,
1497
+ onSet: (entry, mode) => { setGlobalTool(entry, mode) },
1498
+ t,
1499
+ })))))
1223
1500
  }
1224
1501
 
1225
1502
  /** 全局 Skills 行:主行(描述单行省略 + 展开/开关)+ 展开后的完整描述与位置。 */
@@ -1301,12 +1578,35 @@ window.__ModuleLoader__.load({
1301
1578
  React.createElement('div', { className: 'msc-pageHeaderText' },
1302
1579
  React.createElement('h2', { className: 'msc-pageTitle' }, t('settings.title')),
1303
1580
  React.createElement('p', { className: 'msc-intro' }, t('settings.note'))),
1581
+ React.createElement('div', { className: 'msc-pageActions' },
1582
+ React.createElement('button', {
1583
+ type: 'button',
1584
+ className: 'msc-actionButton',
1585
+ disabled: orphanBusy,
1586
+ onClick: () => { void checkOrphans() },
1587
+ }, t('action.orphans')),
1304
1588
  React.createElement('button', {
1305
1589
  type: 'button',
1306
1590
  className: 'msc-actionButton',
1307
1591
  disabled: busyKey !== undefined,
1308
1592
  onClick: retry,
1309
- }, t('action.refresh'))),
1593
+ }, t('action.refresh')))),
1594
+
1595
+ orphans !== undefined && React.createElement('div', { className: 'msc-orphanBar', role: 'status' },
1596
+ React.createElement('span', null, t('orphans.confirm'), ' ',
1597
+ React.createElement('strong', null, orphans.length)),
1598
+ React.createElement('button', {
1599
+ type: 'button',
1600
+ className: 'msc-actionButton',
1601
+ disabled: orphanBusy,
1602
+ onClick: () => { void cleanOrphans() },
1603
+ }, t('action.orphansClean')),
1604
+ React.createElement('button', {
1605
+ type: 'button',
1606
+ className: 'msc-actionButton',
1607
+ disabled: orphanBusy,
1608
+ onClick: () => setOrphans(undefined),
1609
+ }, t('action.cancel'))),
1310
1610
 
1311
1611
  state.phase === 'loading' && React.createElement('p', { className: 'msc-statusText', role: 'status' }, t('state.loading')),
1312
1612
  state.phase === 'failed' && React.createElement('div', { className: 'msc-pageHead' },