universal-plugin-hub 1.0.45 → 1.0.50

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/client.js CHANGED
@@ -593,11 +593,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
593
593
  pointer-events: none !important;
594
594
  }
595
595
  .cpm-tab.is-shifting {
596
- transition: transform 0.22s cubic-bezier(0.2, 0, 0, 1), background .15s ease, color .15s ease !important;
596
+ transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1), background .15s ease, color .15s ease !important;
597
597
  will-change: transform;
598
598
  }
599
599
  .cpm-tab-drag-overlay {
600
600
  position: fixed !important;
601
+ left: 0;
602
+ top: 0;
601
603
  z-index: 9999999 !important;
602
604
  pointer-events: none !important;
603
605
  box-sizing: border-box !important;
@@ -618,7 +620,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
618
620
  box-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.32), 0 8px 16px -2px rgba(37, 99, 235, 0.25), 0 0 0 1px rgba(37, 99, 235, 0.4) !important;
619
621
  backdrop-filter: blur(8px);
620
622
  -webkit-backdrop-filter: blur(8px);
621
- will-change: left, top, transform, box-shadow;
623
+ will-change: transform;
622
624
  }
623
625
  .cpm-dark .cpm-tab-drag-overlay,
624
626
  .cpm-tab-drag-overlay.cpm-dark {
@@ -1051,7 +1053,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
1051
1053
  .cpm-detail {
1052
1054
  flex: 1;
1053
1055
  overflow-y: auto;
1054
- padding: 16px 24px 28px 24px;
1056
+ padding: 11px 24px 28px 24px;
1055
1057
  width: 100%;
1056
1058
  display: flex;
1057
1059
  flex-direction: column;
@@ -1088,6 +1090,9 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
1088
1090
  gap: 4px;
1089
1091
  }
1090
1092
  .cpm-back:hover { color: var(--cpm-text); }
1093
+ /* The top bar leaves 10px below its rule: 10 + 11 above Back matches
1094
+ the 21px below it, keeping Back centered without moving the title row. */
1095
+ .cpm-detail:not(.cpm-skill-detail) > .cpm-back { padding-bottom: 21px; }
1091
1096
  .cpm-title-row {
1092
1097
  display: flex;
1093
1098
  align-items: center;
@@ -1303,7 +1308,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
1303
1308
  .cpm-manage {
1304
1309
  flex: 1;
1305
1310
  overflow-y: auto;
1306
- padding: 16px 24px 28px 24px;
1311
+ padding: 11px 24px 28px 24px;
1307
1312
  width: 100%;
1308
1313
  background: var(--cpm-bg);
1309
1314
  display: flex;
@@ -1332,7 +1337,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
1332
1337
  display: flex;
1333
1338
  align-items: center;
1334
1339
  justify-content: space-between;
1335
- margin-bottom: 8px;
1340
+ margin-bottom: 21px;
1336
1341
  }
1337
1342
  .cpm-meta {
1338
1343
  display: flex;
@@ -1625,6 +1630,99 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
1625
1630
  margin-top: 12px;
1626
1631
  margin-bottom: 6px;
1627
1632
  }
1633
+ .cpm-agent-list {
1634
+ display: grid;
1635
+ gap: .625rem;
1636
+ list-style: none;
1637
+ margin: .25rem 0 0;
1638
+ padding: 0;
1639
+ }
1640
+ .cpm-agent-item {
1641
+ min-inline-size: 0;
1642
+ padding: .875rem 1rem;
1643
+ border: 1px solid var(--cpm-border);
1644
+ border-radius: .875rem;
1645
+ background: var(--cpm-card-bg);
1646
+ }
1647
+ .cpm-agent-header, .cpm-agent-meta {
1648
+ display: flex;
1649
+ align-items: center;
1650
+ flex-wrap: wrap;
1651
+ gap: .375rem .625rem;
1652
+ }
1653
+ .cpm-agent-name {
1654
+ min-inline-size: 0;
1655
+ margin: 0;
1656
+ font-size: .9375rem;
1657
+ font-weight: 600;
1658
+ line-height: 1.4;
1659
+ letter-spacing: -.015em;
1660
+ color: var(--cpm-text);
1661
+ overflow-wrap: anywhere;
1662
+ }
1663
+ .cpm-agent-meta {
1664
+ min-inline-size: 0;
1665
+ max-inline-size: 100%;
1666
+ margin-inline-start: auto;
1667
+ color: var(--cpm-muted);
1668
+ font-size: .6875rem;
1669
+ line-height: 1.5;
1670
+ font-variant-numeric: tabular-nums;
1671
+ }
1672
+ .cpm-agent-model {
1673
+ box-sizing: border-box;
1674
+ max-inline-size: 100%;
1675
+ padding: .125rem .4375rem;
1676
+ border-radius: .375rem;
1677
+ background: var(--cpm-pill-bg);
1678
+ color: var(--cpm-text-sub);
1679
+ overflow-wrap: anywhere;
1680
+ }
1681
+ .cpm-agent-description {
1682
+ margin-block: .4375rem 0;
1683
+ font-size: .8125rem;
1684
+ line-height: 1.55;
1685
+ color: var(--cpm-text-sub);
1686
+ overflow-wrap: anywhere;
1687
+ }
1688
+ .cpm-agent-description .cpm-smart-md { font-size: inherit; line-height: inherit; color: inherit; }
1689
+ .cpm-agent-tools { display: grid; gap: .375rem; margin-block-start: .625rem; }
1690
+ .cpm-agent-tool-group {
1691
+ display: flex;
1692
+ align-items: baseline;
1693
+ flex-wrap: wrap;
1694
+ gap: .375rem .75rem;
1695
+ }
1696
+ .cpm-agent-tool-source {
1697
+ flex: 0 1 13rem;
1698
+ min-inline-size: 0;
1699
+ font-size: .6875rem;
1700
+ line-height: 1.6;
1701
+ color: var(--cpm-muted);
1702
+ overflow-wrap: anywhere;
1703
+ }
1704
+ .cpm-agent-tool-list {
1705
+ display: flex;
1706
+ flex: 1 1 24rem;
1707
+ flex-wrap: wrap;
1708
+ flex-wrap: balance;
1709
+ gap: .25rem .375rem;
1710
+ min-inline-size: 0;
1711
+ list-style: none;
1712
+ margin: 0;
1713
+ padding: 0;
1714
+ }
1715
+ .cpm-agent-tool-list > li { min-inline-size: 0; max-inline-size: 100%; }
1716
+ .cpm-agent-tool {
1717
+ display: block;
1718
+ padding: .125rem .375rem;
1719
+ border-radius: .3125rem;
1720
+ background: var(--cpm-pill-bg);
1721
+ font: .6875rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
1722
+ color: var(--cpm-text-sub);
1723
+ white-space: normal;
1724
+ overflow-wrap: anywhere;
1725
+ }
1628
1726
  .cpm-skill-list { margin-top: 4px; }
1629
1727
  .cpm-skill-item {
1630
1728
  padding: 12px 2px;
@@ -2416,6 +2514,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
2416
2514
  }
2417
2515
  @media (prefers-reduced-motion: reduce) {
2418
2516
  .cpm-oauth-pending { animation: none; }
2517
+ .cpm-tab.is-shifting, .cpm-tab-drag-overlay { transition: none !important; }
2419
2518
  /* The spring is decoration; the state change is the message. A user who
2420
2519
  asked for less motion gets the knob in place immediately. */
2421
2520
  .cpm-toggle, .cpm-toggle::after {
@@ -3377,23 +3476,62 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
3377
3476
  font-family: var(--cpm-mono, monospace);
3378
3477
  }
3379
3478
 
3479
+ .cpm-mcp-discovery {
3480
+ display: inline-flex;
3481
+ align-items: center;
3482
+ flex-wrap: wrap;
3483
+ gap: 6px 8px;
3484
+ min-width: 0;
3485
+ max-width: 100%;
3486
+ color: var(--cpm-muted);
3487
+ font-size: 11.5px;
3488
+ line-height: 1.6;
3489
+ }
3490
+ .cpm-mcp-discovery.is-error { color: var(--cpm-text-secondary, var(--cpm-muted)); }
3491
+ .cpm-mcp-discovery-message { overflow-wrap: anywhere; }
3492
+ .cpm-mcp-retry {
3493
+ min-height: 24px;
3494
+ border: 1px solid var(--cpm-border);
3495
+ border-radius: 7px;
3496
+ background: var(--cpm-pill-bg);
3497
+ color: var(--cpm-text);
3498
+ padding: 2px 8px;
3499
+ font: inherit;
3500
+ font-weight: 500;
3501
+ cursor: pointer;
3502
+ transition: background 120ms ease, transform 100ms ease;
3503
+ }
3504
+ .cpm-mcp-retry:hover { background: var(--cpm-hover); }
3505
+ .cpm-mcp-retry:active { transform: scale(0.97); }
3506
+ .cpm-mcp-retry:focus-visible, .cpm-mcp-expand:focus-visible { outline: 2px solid #3b82f6; outline-offset: 3px; }
3507
+ @media (prefers-reduced-motion: reduce) {
3508
+ .cpm-toast { animation: none !important; }
3509
+ .cpm-mcp-discovery .cpm-spin-ring { animation: none; }
3510
+ .cpm-mcp-retry { transition: none; }
3511
+ .cpm-mcp-retry:active { transform: none; }
3512
+ }
3513
+ @media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
3514
+ .cpm-root .cpm-toast { background: var(--cpm-bg); backdrop-filter: none; -webkit-backdrop-filter: none; }
3515
+ }
3516
+
3380
3517
  .cpm-toast {
3381
- position: fixed;
3518
+ position: absolute;
3382
3519
  bottom: 28px;
3383
3520
  left: 50%;
3384
3521
  transform: translateX(-50%);
3385
- background: rgba(255, 255, 255, 0.95);
3522
+ background: rgba(255, 255, 255, 0.72);
3386
3523
  color: #09090b;
3387
3524
  border: 1px solid rgba(0, 0, 0, 0.08);
3388
3525
  border-radius: 12px;
3389
3526
  padding: 11px 16px;
3390
3527
  font-size: 13px;
3391
3528
  z-index: 100001;
3392
- max-width: min(92vw, 500px);
3529
+ max-width: min(calc(100% - 32px), 500px);
3530
+ box-sizing: border-box;
3393
3531
  width: max-content;
3394
- box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8) inset, 0 4px 12px -2px rgba(0, 0, 0, 0.06), 0 16px 36px -6px rgba(0, 0, 0, 0.12);
3395
- -webkit-backdrop-filter: blur(20px) saturate(190%);
3396
- backdrop-filter: blur(20px) saturate(190%);
3532
+ box-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.04);
3533
+ -webkit-backdrop-filter: blur(20px) saturate(180%);
3534
+ backdrop-filter: blur(20px) saturate(180%);
3397
3535
  display: flex;
3398
3536
  align-items: center;
3399
3537
  gap: 20px;
@@ -3402,10 +3540,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
3402
3540
  user-select: none;
3403
3541
  }
3404
3542
  .cpm-dark .cpm-toast {
3405
- background: rgba(24, 24, 27, 0.95);
3543
+ background: rgba(55, 55, 57, 0.75);
3406
3544
  color: #f4f4f5;
3407
- border: 1px solid rgba(255, 255, 255, 0.1);
3408
- box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.12) inset, 0 4px 12px -2px rgba(0, 0, 0, 0.4), 0 20px 48px -8px rgba(0, 0, 0, 0.7);
3545
+ backdrop-filter: blur(22px) saturate(180%);
3546
+ -webkit-backdrop-filter: blur(22px) saturate(180%);
3547
+ border: 1px solid var(--cpm-modal-border);
3548
+ box-shadow: var(--cpm-shadow);
3409
3549
  }
3410
3550
  @keyframes cpm-toast-in {
3411
3551
  from { opacity: 0; transform: translate(-50%, 14px) scale(0.97); }
@@ -3425,6 +3565,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
3425
3565
  to { transform: rotate(360deg); }
3426
3566
  }
3427
3567
  .cpm-toast-content {
3568
+ text-align: center;
3428
3569
  flex: 1;
3429
3570
  min-width: 0;
3430
3571
  display: flex;
@@ -3432,6 +3573,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
3432
3573
  justify-content: center;
3433
3574
  }
3434
3575
  .cpm-toast-title {
3576
+ justify-content: center;
3435
3577
  color: #09090b;
3436
3578
  font-size: 13px;
3437
3579
  font-weight: 600;
@@ -3448,9 +3590,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
3448
3590
  font-size: 12px;
3449
3591
  line-height: 1.4;
3450
3592
  margin-top: 2px;
3451
- white-space: nowrap;
3452
- overflow: hidden;
3453
- text-overflow: ellipsis;
3593
+ white-space: normal;
3594
+ overflow-wrap: anywhere;
3454
3595
  }
3455
3596
  .cpm-dark .cpm-toast-body {
3456
3597
  color: #a1a1aa;
@@ -4093,9 +4234,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4093
4234
  // visible only on the rows that actually hit the network, which read as
4094
4235
  // "these few icons reload every time".
4095
4236
  const LOADED_AVATARS = new Set();
4096
- // Only a successful load in this session may skip the placeholder. Restored
4097
- // history helps fetch and decode quickly, but must not expose an empty box.
4098
- const PAINTED_AVATARS = new Set();
4099
4237
  const FAILED_ICON_URLS = new Map();
4100
4238
  const LOADED_AVATARS_KEY = "cpm_loaded_icons_v1";
4101
4239
  // Deferred: touching localStorage while this module is still being evaluated
@@ -4123,7 +4261,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4123
4261
  }
4124
4262
  function trackLoadedAvatar(url) {
4125
4263
  if (!url || url.startsWith("data:")) return;
4126
- PAINTED_AVATARS.add(url);
4127
4264
  restoreLoadedAvatars();
4128
4265
  // Only a real change is worth a write: a restart re-reports every icon it
4129
4266
  // already knows, and rewriting an identical 2048-entry set on each boot is
@@ -4138,7 +4275,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4138
4275
  }
4139
4276
  function forgetLoadedAvatar(url) {
4140
4277
  restoreLoadedAvatars();
4141
- PAINTED_AVATARS.delete(url);
4142
4278
  if (!LOADED_AVATARS.delete(url)) return;
4143
4279
  loadedAvatarsDirty = true;
4144
4280
  defer(persistLoadedAvatars);
@@ -4146,8 +4282,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4146
4282
 
4147
4283
  function PluginIcon({ plugin, isDark, eager = false }) {
4148
4284
  const candidates = useMemo(() => getPluginIconCandidates(plugin, isDark), [plugin, isDark]);
4149
- const embedded = candidates.find((url) => url.startsWith("data:image/"));
4150
- const fallback = embedded ? h("img", { src: embedded, alt: "", width: 38, height: 38, style: { width: "100%", height: "100%", objectFit: "contain" } }) : h(PluginIconFallback, { plugin, isDark });
4285
+ const embedded = plugin?.icons?.previews?.[candidates[0]] || candidates.find((url) => url.startsWith("data:image/"));
4286
+ const fallback = embedded ? h("img", { src: embedded, alt: "", width: 38, height: 38, decoding: "sync", style: { width: "100%", height: "100%", objectFit: "contain" } }) : h(PluginIconFallback, { plugin, isDark });
4151
4287
  return candidates.length ? h(PluginIconImage, { key: candidates.join("|"), candidates, plugin, fallback, eager }) : fallback;
4152
4288
  }
4153
4289
 
@@ -4155,21 +4291,24 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4155
4291
  const [index, setIndex] = useState(0);
4156
4292
  const [loaded, setLoaded] = useState("");
4157
4293
  const avatarUrl = candidates.slice(index).find((url) => !(FAILED_ICON_URLS.get(url) > Date.now()));
4158
- // Once this session's onLoad has confirmed an icon, every later mount
4159
- // shows it immediately: re-mounting into a detail page used to reset
4160
- // `loaded` to "" and paint the placeholder until the same bytes were
4161
- // decoded again, which flashed on every click. A restored entry that
4162
- // has not yet loaded in this session still holds the placeholder, so
4163
- // a cold start never paints an empty container either.
4294
+ // History controls scheduling, not visibility: a new <img> can still be
4295
+ // fetching or decoding even if this URL loaded on an earlier mount.
4164
4296
  const known = !!avatarUrl && isKnownAvatar(avatarUrl);
4165
- const painted = !!avatarUrl && PAINTED_AVATARS.has(avatarUrl);
4166
- const imgLoaded = avatarUrl && (avatarUrl.startsWith("data:") || painted || loaded === avatarUrl);
4297
+ const imgLoaded = avatarUrl && (avatarUrl.startsWith("data:") || loaded === avatarUrl);
4167
4298
  return h("div", { className: "cpm-card-icon", style: { position: "relative", overflow: "hidden" } },
4168
4299
  h("div", { className: "cpm-icon-underlay", "aria-hidden": true, style: { position: "absolute", inset: 0, opacity: imgLoaded ? 0 : 1 } }, fallback),
4169
4300
  // A plugin-local icon is a same-origin disk read, so deferring it to
4170
4301
  // the viewport buys nothing and costs a visible placeholder on scroll.
4171
4302
  // Only remote avatars are worth deferring — and never above the fold.
4172
4303
  avatarUrl && h("img", { key: avatarUrl, src: avatarUrl, alt: plugin?.displayName || plugin?.name || "", width: 38, height: 38, decoding: known ? "sync" : "async", loading: (eager || known || avatarUrl.indexOf("/api/plugin-icon") >= 0) ? "eager" : "lazy",
4304
+ ref: (image) => {
4305
+ // A memory-cached image can be ready at commit, before onLoad.
4306
+ // Confirm this element before paint to avoid a fallback flash.
4307
+ if (image?.complete && image.naturalWidth > 0 && loaded !== avatarUrl) {
4308
+ trackLoadedAvatar(avatarUrl);
4309
+ setLoaded(avatarUrl);
4310
+ }
4311
+ },
4173
4312
  style: { position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "contain", borderRadius: "inherit", opacity: imgLoaded ? 1 : 0 },
4174
4313
  onLoad: () => { trackLoadedAvatar(avatarUrl); setLoaded(avatarUrl); },
4175
4314
  onError: () => {
@@ -4256,7 +4395,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4256
4395
  h("div", { className: "cpm-card-name" },
4257
4396
  h("span", { className: "cpm-card-name-text" }, plugin.displayName || plugin.name),
4258
4397
  ),
4259
- h("div", { className: "cpm-card-desc" }, plugin.description || (plugin.author ? `by ${plugin.author}` : "")),
4398
+ h("div", { className: "cpm-card-desc" }, plugin.shortDescription || plugin.description || (plugin.author ? `by ${plugin.author}` : "")),
4260
4399
  ),
4261
4400
  action || (installed
4262
4401
  ? h("button", {
@@ -4278,7 +4417,41 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4278
4417
  onClick: e => e.stopPropagation(), onChange: e => { setInteractive(true); onToggle(skill, e.currentTarget.checked); } });
4279
4418
  }
4280
4419
 
4281
- function useDetailScrollMask(identity, containerRef, content) {
4420
+ function useRememberedDetailScroll(identity, containerRef, page, updateMask, content) {
4421
+ useLayoutEffect(() => {
4422
+ const el = containerRef.current;
4423
+ if (!el) return;
4424
+ const positions = page ? (page.scrollPositions ||= {}) : {};
4425
+ let pending = positions[identity] || 0;
4426
+ const restore = () => {
4427
+ if (pending !== null) {
4428
+ el.scrollTop = pending;
4429
+ if (el.scrollTop === pending) pending = null;
4430
+ }
4431
+ updateMask();
4432
+ };
4433
+ const save = () => { if (pending === null) positions[identity] = el.scrollTop; };
4434
+ const interact = () => { pending = null; save(); };
4435
+ restore();
4436
+ el.addEventListener?.("scroll", save);
4437
+ el.addEventListener?.("wheel", interact, { passive: true });
4438
+ el.addEventListener?.("pointerdown", interact);
4439
+ el.addEventListener?.("keydown", interact);
4440
+ const observer = typeof ResizeObserver === "function" ? new ResizeObserver(restore) : null;
4441
+ observer?.observe(el);
4442
+ Array.from(el.children || []).forEach(child => observer?.observe(child));
4443
+ return () => {
4444
+ save();
4445
+ observer?.disconnect();
4446
+ el.removeEventListener?.("scroll", save);
4447
+ el.removeEventListener?.("wheel", interact);
4448
+ el.removeEventListener?.("pointerdown", interact);
4449
+ el.removeEventListener?.("keydown", interact);
4450
+ };
4451
+ }, [identity, containerRef, page, updateMask, content]);
4452
+ }
4453
+
4454
+ function useDetailScrollMask(identity, containerRef, content, scrollState) {
4282
4455
  const localRef = useRef(null);
4283
4456
  const detailRef = containerRef || localRef;
4284
4457
  const [maskClass, setMaskClass] = useState(" mask-bottom");
@@ -4287,10 +4460,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4287
4460
  if (!el) return;
4288
4461
  setMaskClass(el.scrollHeight - el.clientHeight > 4 && el.scrollTop < el.scrollHeight - el.clientHeight - 4 ? " mask-bottom" : "");
4289
4462
  }, [detailRef]);
4290
- useLayoutEffect(() => {
4291
- if (detailRef.current) detailRef.current.scrollTop = 0;
4292
- updateMask();
4293
- }, [identity, detailRef, updateMask]);
4463
+ useRememberedDetailScroll(identity, detailRef, scrollState, updateMask, content);
4294
4464
  useLayoutEffect(() => {
4295
4465
  updateMask();
4296
4466
  const el = detailRef.current;
@@ -4302,11 +4472,11 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4302
4472
  return { detailRef, maskClass, updateMask };
4303
4473
  }
4304
4474
 
4305
- function SkillDetail({ skill, onBack, onToggle, onRemove, busy, isDark, containerRef }) {
4475
+ function SkillDetail({ skill, onBack, onToggle, onRemove, busy, isDark, containerRef, scrollState }) {
4306
4476
  const [detail, setDetail] = useState(null);
4307
4477
  const [error, setError] = useState("");
4308
4478
  const [removing, setRemoving] = useState(false);
4309
- const { detailRef, maskClass, updateMask } = useDetailScrollMask(skill.id, containerRef, detail || error);
4479
+ const { detailRef, maskClass, updateMask } = useDetailScrollMask(skill.id, containerRef, detail || error, scrollState);
4310
4480
  useEffect(() => {
4311
4481
  let live = true;
4312
4482
  setDetail(null); setError("");
@@ -4522,23 +4692,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4522
4692
  h("polyline", { points: "15 18 9 12 15 6" }),
4523
4693
  );
4524
4694
 
4525
- const IconMore = ({ size = 14, color = "currentColor" }) =>
4526
- h("svg", {
4527
- width: size,
4528
- height: size,
4529
- viewBox: "0 0 24 24",
4530
- fill: "none",
4531
- stroke: color,
4532
- strokeWidth: 2,
4533
- strokeLinecap: "round",
4534
- strokeLinejoin: "round",
4535
- style: { flexShrink: 0 },
4536
- },
4537
- h("circle", { cx: 12, cy: 12, r: 1.3, fill: "currentColor" }),
4538
- h("circle", { cx: 12, cy: 5, r: 1.3, fill: "currentColor" }),
4539
- h("circle", { cx: 12, cy: 19, r: 1.3, fill: "currentColor" }),
4540
- );
4541
-
4542
4695
  const IconEye = ({ size = 14, color = "currentColor" }) =>
4543
4696
  h("svg", {
4544
4697
  width: size,
@@ -4829,8 +4982,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4829
4982
  const SESSION_STORE = {
4830
4983
  view: { type: "browse" },
4831
4984
  sourceViews: {},
4832
- manageFor: null,
4833
- prevView: null,
4985
+ browseSortSnapshots: Object.create(null),
4834
4986
  query: "",
4835
4987
  filter: "all",
4836
4988
  sortBy: "default",
@@ -4857,10 +5009,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4857
5009
 
4858
5010
  const [isDark, setIsDark] = useState(getEffectiveTheme);
4859
5011
  const [view, setViewRaw] = useState(() => SESSION_STORE.view);
4860
- const [manageFor, setManageForRaw] = useState(() => SESSION_STORE.manageFor);
4861
- const [manageTab, setManageTab] = useState(null);
4862
- const [manageConnector, setManageConnector] = useState(null);
4863
- const [prevView, setPrevViewRaw] = useState(() => SESSION_STORE.prevView);
4864
5012
 
4865
5013
  // Persistent browse state across views and sidebar tab switching
4866
5014
  const [query, setQueryRaw] = useState(() => SESSION_STORE.query);
@@ -4900,16 +5048,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
4900
5048
  setViewRaw(targetView);
4901
5049
  }, []);
4902
5050
 
4903
- const setManageFor = useCallback((m) => {
4904
- SESSION_STORE.manageFor = m;
4905
- setManageForRaw(m);
4906
- }, []);
4907
-
4908
- const setPrevView = useCallback((pv) => {
4909
- SESSION_STORE.prevView = pv;
4910
- setPrevViewRaw(pv);
4911
- }, []);
4912
-
4913
5051
  const setQuery = useCallback((q) => {
4914
5052
  SESSION_STORE.query = q;
4915
5053
  setQueryRaw(q);
@@ -5083,8 +5221,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
5083
5221
  // The plugin panel itself is being closed (MarketApp unmounts). Reset
5084
5222
  // the scroll memory so a fresh open of the panel starts at the top —
5085
5223
  // the user explicitly wants panel close/reopen to reset scroll. This
5086
- // does NOT run on the manage-page round trip (that only conditionally
5087
- // swaps BrowseView/ManagePage inside the same MarketApp), so returning
5224
+ // does NOT run when opening management inside BrowseView, so returning
5088
5225
  // from manage still restores the saved position.
5089
5226
  useEffect(() => {
5090
5227
  return () => {
@@ -5095,21 +5232,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
5095
5232
  };
5096
5233
  }, []);
5097
5234
 
5098
- const openManage = useCallback((record, fromView, tab, connector) => {
5099
- setManageFor(record ? record.name : null);
5100
- setManageTab(tab || null);
5101
- setManageConnector(connector || null);
5102
- setPrevView(fromView || view || { type: "browse" });
5103
- }, [view, setManageFor, setPrevView]);
5104
-
5105
- const closeManage = useCallback(() => {
5106
- setManageFor(null);
5107
- if (prevView && prevView.type === "detail") {
5108
- setView(prevView);
5109
- } else {
5110
- setView({ type: "browse", sourceId: activeSourceId });
5111
- }
5112
- }, [prevView, setManageFor, setView, activeSourceId]);
5235
+ const openManage = useCallback((record, fromView, tab, connector, returnToMcp = false) => {
5236
+ if (!record) return;
5237
+ setView({ type: "manage", sourceId: activeSourceId, pluginName: record.name,
5238
+ initialTab: tab || null, initialConnector: connector || null,
5239
+ returnView: returnToMcp || fromView?.type === "detail" ? fromView : undefined, returnToMcp });
5240
+ }, [activeSourceId, setView]);
5113
5241
 
5114
5242
  return h("div", {
5115
5243
  ref: rootRef,
@@ -5117,7 +5245,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
5117
5245
  onMouseOver: handleRootMouseOver,
5118
5246
  onMouseOut: handleRootMouseOut,
5119
5247
  },
5120
- !manageFor && h(BrowseView, {
5248
+ h(BrowseView, {
5121
5249
  view,
5122
5250
  setView,
5123
5251
  state,
@@ -5139,20 +5267,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
5139
5267
  setRows,
5140
5268
  scrollTopRef,
5141
5269
  }),
5142
- manageFor && h(ManagePage, {
5143
- record: state.plugins.find((p) => p.name === manageFor) || null,
5144
- state,
5145
- rows,
5146
- isDark,
5147
- refreshState,
5148
- showToast,
5149
- initialTab: manageTab,
5150
- initialConnector: manageConnector,
5151
- onBack: closeManage,
5152
- onClose: closeManage,
5153
- }),
5154
5270
  toast && h("div", {
5155
- className: "cpm-toast",
5271
+ className: "cpm-toast", role: "status", "aria-live": "polite", "aria-atomic": "true",
5156
5272
  },
5157
5273
  h("div", { className: "cpm-toast-content" },
5158
5274
  h("div", { className: "cpm-toast-title" },
@@ -5779,7 +5895,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
5779
5895
  setState,
5780
5896
  refreshState,
5781
5897
  showToast,
5782
- openManage,
5898
+ openManage: openManageView,
5783
5899
  onInstalled,
5784
5900
  isDark,
5785
5901
  query,
@@ -5817,6 +5933,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
5817
5933
  SESSION_STORE.mcpsOpen = v;
5818
5934
  setMcpsOpenRaw(v);
5819
5935
  }, []);
5936
+ const openManage = (record, fromView, tab, connector) => {
5937
+ setMcpsOpen(false);
5938
+ openManageView(record, mcpsOpen ? view : fromView, tab, connector, mcpsOpen);
5939
+ };
5820
5940
  const [editMcp, setEditMcp] = useState(null);
5821
5941
  // Plugin name when the editor was opened from a plugin-provided server;
5822
5942
  // null means the editor targets a user-added MCP.
@@ -5868,47 +5988,42 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
5868
5988
  ), [state.plugins]);
5869
5989
  const hasMcps = mcps.some((m) => m?.name) || pluginMcpRows.length > 0;
5870
5990
 
5871
- const loadGlobalTools = useCallback(async (owner, connectorName) => {
5991
+ const loadGlobalTools = useCallback(async (owner, connectorName, forceFresh = false) => {
5872
5992
  const key = `${owner}::${connectorName}`;
5873
5993
  const cached = GLOBAL_MCP_TOOLS_CACHE[key];
5874
- const hasCachedTools = Array.isArray(cached?.tools) && cached.tools.length > 0;
5875
- if (!hasCachedTools) {
5876
5994
  setGlobalToolData((prev) => ({ ...prev, [key]: { ...(prev[key] || {}), loading: true, error: null } }));
5877
- }
5878
5995
  try {
5879
5996
  const url = owner === "user-mcp"
5880
5997
  ? `/mcps/${encodeURIComponent(connectorName)}/tools`
5881
5998
  : `/plugins/${encodeURIComponent(owner)}/connectors/${encodeURIComponent(connectorName)}/tools`;
5882
- const res = await api(url);
5999
+ const res = await api(url + (forceFresh ? "?fresh=1" : ""));
5883
6000
  const tools = Array.isArray(res.tools) ? res.tools : [];
5884
6001
  const disabledTools = Array.isArray(res.disabledTools) ? res.disabledTools : [];
5885
- if (tools.length > 0) saveMcpToolsCache(key, { tools, disabledTools });
6002
+ if (res.ok) saveMcpToolsCache(key, { tools, disabledTools });
5886
6003
  setGlobalToolData((prev) => ({
5887
6004
  ...prev,
5888
6005
  [key]: {
5889
6006
  loading: false,
5890
6007
  error: res.ok ? null : (res.message || "获取能力列表失败"),
5891
- tools: tools.length > 0 ? tools : (prev[key]?.tools || []),
6008
+ tools: res.ok ? tools : (prev[key]?.tools || tools),
5892
6009
  disabledTools,
5893
6010
  },
5894
6011
  }));
5895
6012
  } catch (e) {
5896
- if (!hasCachedTools) {
5897
- setGlobalToolData((prev) => ({ ...prev, [key]: { loading: false, error: e.message, tools: [], disabledTools: [] } }));
5898
- }
6013
+ setGlobalToolData((prev) => ({ ...prev, [key]: { ...(prev[key] || cached), loading: false, error: e.message } }));
5899
6014
  }
5900
6015
  }, []);
5901
6016
 
5902
- const toggleGlobalExpand = useCallback((owner, connectorName) => {
6017
+ useAutoMcpTools([
6018
+ ...pluginMcpRows.map(row => ({ owner: row.owner, name: row.name, connected: row.connected, revision: JSON.stringify([row.record.installedAt, row.conn]) })),
6019
+ ...mcps.map(row => ({ owner: "user-mcp", name: row.name, connected: row.enabled === true, revision: JSON.stringify(row) })),
6020
+ ], loadGlobalTools);
6021
+
6022
+ const toggleGlobalExpand = useCallback((owner, connectorName) => {
5903
6023
  const key = `${owner}::${connectorName}`;
5904
6024
  const willExpand = !globalExpanded[key];
5905
6025
  setGlobalExpanded((prev) => ({ ...prev, [key]: willExpand }));
5906
- // Load outside the updater: React may replay updaters, and this one
5907
- // spawns a local MCP server.
5908
- if (willExpand && (!globalToolData[key] || !globalToolData[key].tools || globalToolData[key].tools.length === 0)) {
5909
- loadGlobalTools(owner, connectorName);
5910
- }
5911
- }, [globalExpanded, globalToolData, loadGlobalTools]);
6026
+ }, [globalExpanded]);
5912
6027
 
5913
6028
  const toggleGlobalTool = useCallback(async (owner, connectorName, toolName) => {
5914
6029
  const key = `${owner}::${connectorName}`;
@@ -5948,7 +6063,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
5948
6063
  const info = globalToolData[key];
5949
6064
  const toolsList = info?.tools || [];
5950
6065
  const disabledTools = info?.disabledTools || [];
5951
- const activeCount = toolsList.filter((t) => !disabledTools.includes(typeof t === "string" ? t : t.name)).length;
5952
6066
 
5953
6067
  const onToggleServer = async () => {
5954
6068
  try {
@@ -6018,18 +6132,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6018
6132
  // inline-flex so the pill's text baseline is the one that aligns,
6019
6133
  // instead of the padded box being pushed around as a block.
6020
6134
  h("span", { style: { display: "inline-flex", alignItems: "center", fontSize: 11, lineHeight: "16px", padding: "2px 8px", borderRadius: 6, background: "var(--cpm-pill-bg)", color: "var(--cpm-text)", fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", flexShrink: 0 } }, transport === "stdio" ? "stdio" : "http"),
6021
- // Must render before the tool list is fetched: this button is
6022
- // what triggers the fetch.
6023
- connected && h("button", {
6024
- type: "button",
6025
- className: "cpm-mcp-expand",
6026
- onClick: () => toggleGlobalExpand(owner, name),
6027
- },
6028
- h("span", null, toolsList.length > 0
6029
- ? `${activeCount} tools enabled${disabledTools.length > 0 ? ` (${disabledTools.length} disabled)` : ""}`
6030
- : "Tools"),
6031
- h("span", { className: "cpm-connector-collapse-btn" + (isExpanded ? " is-expanded" : "") }, h(IconArrow, { size: 10 })),
6032
- ),
6135
+ connected && h(McpDiscoveryStatus, { info, expanded: isExpanded,
6136
+ onExpand: () => toggleGlobalExpand(owner, name), onRetry: () => loadGlobalTools(owner, name, true) }),
6033
6137
  ),
6034
6138
  h("button", {
6035
6139
  type: "button",
@@ -6045,12 +6149,12 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6045
6149
  onClick: onToggleServer,
6046
6150
  }),
6047
6151
  ),
6048
- isExpanded && connected && h(McpToolsPanel, {
6152
+ isExpanded && connected && info && !info.loading && !info.error && h(McpToolsPanel, {
6049
6153
  loading: info?.loading,
6050
6154
  error: info?.error,
6051
6155
  tools: toolsList,
6052
6156
  disabledTools,
6053
- onRetry: () => loadGlobalTools(owner, name),
6157
+ onRetry: () => loadGlobalTools(owner, name, true),
6054
6158
  onHoverTool: (tool, rect, anchor, pointer, keyboard) => globalHover.enter({ owner, connectorName: name, tool, rect }, anchor, pointer, keyboard),
6055
6159
  onHoverEnd: (anchor) => globalHover.leave(anchor),
6056
6160
  onToggleTool: (toolName) => toggleGlobalTool(owner, name, toolName),
@@ -6375,6 +6479,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6375
6479
  const autoScrollRafRef = useRef(null);
6376
6480
  const isLongPressTriggeredRef = useRef(false);
6377
6481
  const snapTimerRef = useRef(null);
6482
+ const snapFinishRef = useRef(null);
6483
+ const dragOverlayRef = useRef(null);
6378
6484
 
6379
6485
  const stopAutoScroll = useCallback(() => {
6380
6486
  if (autoScrollRafRef.current) {
@@ -6397,45 +6503,27 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6397
6503
 
6398
6504
  // Visual center of dragged tab in container scroll content coordinate
6399
6505
  const contentCenter = (overlayX + (draggedWidth / 2)) - cRect.left + curScroll;
6400
- const numSlots = baseSlots.length;
6401
-
6402
6506
  let newIdx = fromIndex;
6403
-
6404
- if (numSlots >= 3) {
6405
- const firstMoveable = 1;
6406
- const lastMoveable = numSlots - 1;
6407
-
6408
- const firstCenter = baseSlots[firstMoveable].offsetLeft + (baseSlots[firstMoveable].width / 2);
6409
- // The last slot's center may be scrolled past the container's
6410
- // right edge, where the cursor can never reach it. Clamp the
6411
- // drop boundary to the right edge (in content coordinates) so
6412
- // dragging the tab to the visible end of the bar actually
6413
- // lands in the last slot instead of silently stopping at the
6414
- // second-to-last one.
6415
- const lastCenter = Math.min(
6416
- baseSlots[lastMoveable].offsetLeft + (baseSlots[lastMoveable].width / 2),
6417
- curScroll + cRect.width
6418
- );
6419
-
6420
- if (contentCenter <= firstCenter) {
6421
- newIdx = firstMoveable;
6422
- } else if (contentCenter >= lastCenter) {
6423
- newIdx = lastMoveable;
6424
- } else {
6425
- newIdx = firstMoveable;
6426
- for (let i = firstMoveable; i < lastMoveable; i++) {
6427
- const currentSlot = baseSlots[i];
6428
- const nextSlot = baseSlots[i + 1];
6429
- const midBoundary = (currentSlot.offsetLeft + (currentSlot.width / 2) + nextSlot.offsetLeft + (nextSlot.width / 2)) / 2;
6430
- if (contentCenter > midBoundary) {
6431
- newIdx = i + 1;
6432
- }
6433
- }
6507
+ let nearestDistance = Infinity;
6508
+ // Each candidate is where THIS tab's center would land after reordering,
6509
+ // not the original occupant's center. This keeps every insertion slot
6510
+ // reachable even when a short tab sits between two much wider tabs.
6511
+ // Frozen geometry also prevents animated neighbors feeding back on hit tests.
6512
+ for (const slot of baseSlots) {
6513
+ if (!slot || !slot.movable) continue;
6514
+ const left = slot.offsetLeft + (slot.index > fromIndex ? slot.width - draggedWidth : 0);
6515
+ const distance = Math.abs(contentCenter - (left + draggedWidth / 2));
6516
+ if (distance < nearestDistance) {
6517
+ nearestDistance = distance;
6518
+ newIdx = slot.index;
6434
6519
  }
6435
6520
  }
6436
-
6437
- newIdx = Math.max(1, Math.min(numSlots - 1, newIdx));
6438
-
6521
+ if (dragOverlayRef.current) {
6522
+ dragOverlayRef.current.style.transform = `translate3d(${overlayX}px, ${startOverlayY - 4}px, 0) scale(1.04)`;
6523
+ }
6524
+ // Pointer tracking stays off React's render path. Only crossing an
6525
+ // insertion boundary needs to render a new surrounding-tab preview.
6526
+ if (newIdx === dragLiveRef.current.toIndex) return;
6439
6527
  dragLiveRef.current.toIndex = newIdx;
6440
6528
  setDragState((prev) => prev ? {
6441
6529
  ...prev,
@@ -6470,13 +6558,22 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6470
6558
  longPressTimerRef.current = null;
6471
6559
  }
6472
6560
  stopAutoScroll();
6561
+ if (dragLiveRef.current.isSnapping && snapFinishRef.current) {
6562
+ snapFinishRef.current();
6563
+ return;
6564
+ }
6473
6565
  if (snapTimerRef.current) {
6474
6566
  clearTimeout(snapTimerRef.current);
6475
6567
  snapTimerRef.current = null;
6476
6568
  }
6569
+ snapFinishRef.current = null;
6477
6570
 
6478
- if (dragLiveRef.current.active) {
6479
- const { pointerId, fromIndex, toIndex } = dragLiveRef.current;
6571
+ const { pointerId } = dragLiveRef.current;
6572
+ const wasActive = dragLiveRef.current.active;
6573
+ dragLiveRef.current.active = false;
6574
+ dragLiveRef.current.isSnapping = false;
6575
+ dragLiveRef.current.pointerId = null;
6576
+ if (wasActive || pointerId !== null) {
6480
6577
  if (pointerId !== null) {
6481
6578
  try {
6482
6579
  const el = tabRefs.current[dragLiveRef.current.sourceId];
@@ -6486,36 +6583,16 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6486
6583
  } catch {}
6487
6584
  }
6488
6585
 
6489
- if (toIndex !== fromIndex && fromIndex >= 1 && toIndex >= 1) {
6490
- const scrollEl = tabsRef.current;
6491
- if (scrollEl) savedTabScrolls.set(activeSourceId, scrollEl.scrollLeft);
6492
- const newSources = [...state.sources];
6493
- const [moved] = newSources.splice(fromIndex, 1);
6494
- newSources.splice(toIndex, 0, moved);
6495
- setState((prev) => ({ ...prev, sources: newSources }));
6496
- SESSION_STORE.state = { ...(SESSION_STORE.state || {}), sources: newSources };
6497
- try {
6498
- localStorage.setItem(STORAGE_KEY_STATE, JSON.stringify(SESSION_STORE.state));
6499
- } catch {}
6500
- api("/sources/reorder", {
6501
- method: "POST",
6502
- body: JSON.stringify({ sourceIds: newSources.map((item) => item.id) }),
6503
- }).catch(() => {});
6504
- }
6505
-
6506
- dragLiveRef.current.active = false;
6507
- dragLiveRef.current.isSnapping = false;
6508
- dragLiveRef.current.pointerId = null;
6509
6586
  dragLiveRef.current.startX = 0;
6510
6587
  dragLiveRef.current.startY = 0;
6511
6588
  isLongPressTriggeredRef.current = false;
6512
6589
  setDragState(null);
6513
6590
  updateTabsMask();
6514
6591
  }
6515
- }, [state.sources, setState, stopAutoScroll, updateTabsMask]);
6592
+ }, [stopAutoScroll, updateTabsMask]);
6516
6593
 
6517
6594
  const handleTabPointerDown = useCallback((e, s, idx) => {
6518
- if (e.button !== 0) return;
6595
+ if (e.button !== 0 || e.isPrimary === false) return;
6519
6596
  if (e.target && e.target.closest && e.target.closest(".cpm-tab-del-zone")) return;
6520
6597
  if (dragLiveRef.current.active || dragState) {
6521
6598
  cancelOrResetDrag();
@@ -6539,33 +6616,40 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6539
6616
  dragLiveRef.current.startY = clientY;
6540
6617
  dragLiveRef.current.lastClientX = clientX;
6541
6618
  dragLiveRef.current.pointerId = pointerId;
6619
+ dragLiveRef.current.sourceId = s.id;
6542
6620
  dragLiveRef.current.active = false;
6543
6621
  dragLiveRef.current.isSnapping = false;
6544
-
6545
- const container = tabsRef.current;
6546
- const curScroll = container ? container.scrollLeft : 0;
6622
+ try { targetEl.setPointerCapture(pointerId); } catch {}
6547
6623
 
6548
6624
  if (longPressTimerRef.current) clearTimeout(longPressTimerRef.current);
6549
6625
  longPressTimerRef.current = setTimeout(() => {
6626
+ longPressTimerRef.current = null;
6627
+ const cont = tabsRef.current;
6628
+ if (!cont || !targetEl.isConnected) return;
6629
+ if (currentTabAnim) cancelAnimationFrame(currentTabAnim);
6630
+ currentTabAnim = null;
6631
+ currentTabTarget = null;
6550
6632
  isLongPressTriggeredRef.current = true;
6551
6633
  if (targetEl && typeof targetEl.setPointerCapture === "function") {
6552
6634
  try { targetEl.setPointerCapture(pointerId); } catch {}
6553
6635
  }
6554
- const cont = tabsRef.current;
6555
- if (!cont) return;
6556
6636
  const cRect = cont.getBoundingClientRect();
6557
6637
  const tRect = targetEl.getBoundingClientRect();
6638
+ const curScroll = cont.scrollLeft;
6558
6639
 
6559
- // Capture invariant base slots (offsetLeft / offsetWidth are immune to CSS transforms)
6640
+ // Use one scroll-content coordinate system; offsetLeft may refer to
6641
+ // an ancestor outside this scroller. Hidden sources have no slot.
6560
6642
  const baseSlots = state.sources.map((item, mIdx) => {
6561
6643
  const el = tabRefs.current[item.id];
6562
- if (!el) return { id: item.id, index: mIdx, offsetLeft: 0, width: 60, height: 30 };
6644
+ if (!el || !el.isConnected || !el.getClientRects().length) return null;
6645
+ const rect = el.getBoundingClientRect();
6563
6646
  return {
6564
6647
  id: item.id,
6565
6648
  index: mIdx,
6566
- offsetLeft: el.offsetLeft,
6567
- width: el.offsetWidth,
6568
- height: el.offsetHeight || 30,
6649
+ movable: mIdx !== 0 && !item.builtin && item.id?.toLowerCase() !== "anthropic",
6650
+ offsetLeft: rect.left - cRect.left + curScroll,
6651
+ width: rect.width,
6652
+ height: rect.height || 30,
6569
6653
  };
6570
6654
  });
6571
6655
 
@@ -6577,7 +6661,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6577
6661
  const pointerOffsetX = clientX - startOverlayX;
6578
6662
  const draggedWidth = draggedSlot.width;
6579
6663
  const draggedHeight = draggedSlot.height;
6580
- const slotSize = draggedWidth + 2;
6664
+ const slotSize = draggedWidth + (parseFloat(getComputedStyle(cont).columnGap) || 0);
6581
6665
 
6582
6666
  dragLiveRef.current = {
6583
6667
  active: true,
@@ -6622,6 +6706,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6622
6706
  }, [state.sources, cancelOrResetDrag, dragState]);
6623
6707
 
6624
6708
  const handleTabPointerMove = useCallback((e) => {
6709
+ if (e.pointerId !== dragLiveRef.current.pointerId) return;
6625
6710
  if (longPressTimerRef.current && !dragLiveRef.current.active) {
6626
6711
  if (Math.hypot(e.clientX - dragLiveRef.current.startX, e.clientY - dragLiveRef.current.startY) > 8) {
6627
6712
  clearTimeout(longPressTimerRef.current);
@@ -6652,6 +6737,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6652
6737
  }, [startAutoScroll, stopAutoScroll, updateDragPosition]);
6653
6738
 
6654
6739
  const handleTabPointerUp = useCallback((e, s, idx) => {
6740
+ if (dragLiveRef.current.isSnapping) return;
6741
+ if (dragLiveRef.current.pointerId !== null && e?.pointerId !== dragLiveRef.current.pointerId) return;
6655
6742
  if (longPressTimerRef.current) {
6656
6743
  clearTimeout(longPressTimerRef.current);
6657
6744
  longPressTimerRef.current = null;
@@ -6659,14 +6746,17 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6659
6746
  stopAutoScroll();
6660
6747
 
6661
6748
  const wasActive = dragLiveRef.current.active;
6749
+ if (wasActive && Number.isFinite(e?.clientX)) updateDragPosition(e.clientX);
6662
6750
  const { fromIndex, toIndex, pointerId, baseSlots, draggedWidth } = dragLiveRef.current;
6751
+ // Mark the handoff before releasing capture: lostpointercapture is a
6752
+ // cancellation only while tracking, never during the settle animation.
6753
+ if (wasActive) dragLiveRef.current.isSnapping = true;
6663
6754
 
6664
6755
  if (e && e.currentTarget && typeof e.currentTarget.releasePointerCapture === "function" && pointerId !== null) {
6665
6756
  try { e.currentTarget.releasePointerCapture(pointerId); } catch {}
6666
6757
  }
6667
6758
 
6668
- if (wasActive && !dragLiveRef.current.isSnapping) {
6669
- dragLiveRef.current.isSnapping = true;
6759
+ if (wasActive) {
6670
6760
  const container = tabsRef.current;
6671
6761
  const cRect = container ? container.getBoundingClientRect() : { left: 0, top: 0 };
6672
6762
  const curScroll = container ? container.scrollLeft : 0;
@@ -6690,7 +6780,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6690
6780
  snapTargetY: snapY,
6691
6781
  } : null);
6692
6782
 
6693
- snapTimerRef.current = setTimeout(() => {
6783
+ snapFinishRef.current = () => {
6784
+ if (!dragLiveRef.current.isSnapping) return;
6785
+ clearTimeout(snapTimerRef.current);
6786
+ snapFinishRef.current = null;
6694
6787
  if (toIndex !== fromIndex && fromIndex >= 1 && toIndex >= 1) {
6695
6788
  // Keep the tab bar where the user left it: the state.sources
6696
6789
  // change re-runs the tab-scroll restore layout effect, which
@@ -6722,7 +6815,11 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6722
6815
  setDragState(null);
6723
6816
  snapTimerRef.current = null;
6724
6817
  updateTabsMask();
6725
- }, 190);
6818
+ };
6819
+ // transitionend is the normal completion path; the timer handles
6820
+ // interrupted transitions and reduced-motion (which has no event).
6821
+ const reducedMotion = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
6822
+ snapTimerRef.current = setTimeout(() => snapFinishRef.current?.(), reducedMotion ? 0 : 320);
6726
6823
  return;
6727
6824
  }
6728
6825
 
@@ -6731,7 +6828,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6731
6828
  const isBrowseView = !view || view.type === "browse";
6732
6829
  const sInstalledCount = (state.plugins || []).filter((p) => (p.sourceId || "").toLowerCase() === s.id.toLowerCase() || (p.id && p.id.startsWith(s.id + "/"))).length;
6733
6830
  if (s.id !== activeSourceId) {
6734
- if (gridRef.current && isBrowseView) {
6831
+ if (gridRef.current && isBrowseView && !mcpsOpen) {
6735
6832
  if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
6736
6833
  SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
6737
6834
  }
@@ -6747,7 +6844,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6747
6844
  targetFilter = SESSION_STORE.sourceFilters[s.id] || SESSION_STORE.preferredFilter || (filter === "installed" ? "installed" : "all");
6748
6845
  }
6749
6846
  setActiveSourceId(s.id, targetFilter);
6750
- } else {
6847
+ } else if (!mcpsOpen) {
6751
6848
  // Clicking the current source's tab scrolls its list back to the top.
6752
6849
  scrollActiveTabIntoView(s.id, true);
6753
6850
  if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
@@ -6755,17 +6852,15 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6755
6852
  scrollContentToTop();
6756
6853
  }
6757
6854
  }
6758
- }, [state.sources, state.plugins, activeSourceId, view, filter, setActiveSourceId, scrollActiveTabIntoView, scrollContentToTop, setState, showToast, stopAutoScroll, updateTabsMask]);
6855
+ }, [state.sources, state.plugins, activeSourceId, view, filter, mcpsOpen, setActiveSourceId, scrollActiveTabIntoView, scrollContentToTop, setState, showToast, stopAutoScroll, updateTabsMask, updateDragPosition]);
6759
6856
 
6760
6857
  useEffect(() => {
6761
6858
  const handleWindowBlurOrCancel = () => {
6762
- if (dragLiveRef.current.active) {
6763
- cancelOrResetDrag();
6764
- }
6859
+ cancelOrResetDrag();
6765
6860
  };
6766
6861
 
6767
6862
  const handleGlobalPointerUp = (e) => {
6768
- if (dragLiveRef.current.active && !dragLiveRef.current.isSnapping) {
6863
+ if ((dragLiveRef.current.active || longPressTimerRef.current) && !dragLiveRef.current.isSnapping) {
6769
6864
  handleTabPointerUp(e, null, dragLiveRef.current.fromIndex);
6770
6865
  }
6771
6866
  };
@@ -6784,6 +6879,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6784
6879
  if (autoScrollRafRef.current) cancelAnimationFrame(autoScrollRafRef.current);
6785
6880
  };
6786
6881
  }, [cancelOrResetDrag, handleTabPointerUp]);
6882
+ useEffect(() => () => {
6883
+ clearTimeout(snapTimerRef.current);
6884
+ snapFinishRef.current = null;
6885
+ }, []);
6787
6886
 
6788
6887
  const cleanError = (err) => {
6789
6888
  if (!err) return "操作失败";
@@ -6792,7 +6891,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6792
6891
  return msg;
6793
6892
  };
6794
6893
 
6795
- const isBrowse = !view || view.type === "browse";
6894
+ // MCP is a separate surface; keep the source's list/detail view intact
6895
+ // underneath it so returning to that source resumes the same page.
6896
+ const isBrowse = mcpsOpen || !view || view.type === "browse";
6897
+ const isSourceBrowse = isBrowse && !mcpsOpen;
6796
6898
 
6797
6899
  // Per-source Scroll restoration and wheel scroll suppression
6798
6900
  const onGridWheel = useCallback(() => {
@@ -6849,15 +6951,15 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6849
6951
  // must NOT re-detect "filter changed". Only genuine user-driven
6850
6952
  // changes set a new pending intent.
6851
6953
  //
6852
- // Ref-based, so the apply-step's dependency array stays stable (only
6853
- // `isBrowse`, which flips once per mount). The restore therefore never
6954
+ // Ref-based, so the apply-step only tracks the visible source surface
6955
+ // and source identity. The restore therefore never
6854
6956
  // fires spuriously on unrelated re-renders and never gets clobbered by
6855
6957
  // onGridScroll overwriting the store with a stale value.
6856
6958
  const pendingScrollTopRef = useRef(null);
6857
6959
  const lastActiveSourceRef = useRef(activeSourceId);
6858
6960
  const lastFilterRef = useRef(filter);
6859
6961
  const lastSortByRef = useRef(sortBy);
6860
- const prevIsBrowseRef = useRef(isBrowse);
6962
+ const prevIsBrowseRef = useRef(isSourceBrowse);
6861
6963
  const firstBrowseRenderRef = useRef(true);
6862
6964
 
6863
6965
  if (lastActiveSourceRef.current !== activeSourceId) {
@@ -6881,18 +6983,15 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6881
6983
  pendingScrollTopRef.current = { type: "reset", filter, sortBy };
6882
6984
  }
6883
6985
  }
6884
- // Returning from the detail view unmounts the grid (isBrowse flips to
6885
- // false while the detail overlay shows). When coming back (false→true)
6886
- // the grid is freshly mounted at scrollTop 0 — restore the position
6887
- // that was saved right before the detail was opened.
6888
- if (isBrowse && prevIsBrowseRef.current === false && pendingScrollTopRef.current?.type !== "restore") {
6986
+ // Details and MCP both unmount the source grid. Returning to either the
6987
+ // same source or another source must restore that source's saved position.
6988
+ if (isSourceBrowse && prevIsBrowseRef.current === false && pendingScrollTopRef.current?.type !== "restore") {
6889
6989
  pendingScrollTopRef.current = { type: "restore" };
6890
6990
  }
6891
- prevIsBrowseRef.current = isBrowse;
6892
- // BrowseView itself is unmounted while the manage page is open. When
6893
- // it remounts (manage closed), there is no isBrowse flip — detect the
6894
- // fresh mount and restore the position saved before manage opened.
6895
- if (firstBrowseRenderRef.current && isBrowse && pendingScrollTopRef.current === null) {
6991
+ prevIsBrowseRef.current = isSourceBrowse;
6992
+ // A fresh panel mount can reuse a remembered source position. Management
6993
+ // round trips are handled by the source-surface transition above.
6994
+ if (firstBrowseRenderRef.current && isSourceBrowse && pendingScrollTopRef.current === null) {
6896
6995
  const saved = SESSION_STORE.scrollTops && SESSION_STORE.scrollTops[activeSourceId];
6897
6996
  if (typeof saved === "number") {
6898
6997
  pendingScrollTopRef.current = { type: "restore" };
@@ -6908,7 +7007,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6908
7007
  // yet, and the browser clamps scrollTop when it exceeds the current
6909
7008
  // scrollHeight. Re-applying on the next frame makes the restore stick.
6910
7009
  //
6911
- // NOTE: the apply layout effect deliberately depends on `isBrowse`
7010
+ // NOTE: the apply layout effect deliberately depends on `isSourceBrowse`
6912
7011
  // and `activeSourceId` — a tab switch changes activeSourceId, and
6913
7012
  // that MUST trigger the restore. The change-detection (last-* refs)
6914
7013
  // above runs during render and only sets pending for genuine changes,
@@ -6916,7 +7015,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6916
7015
  // fire this.
6917
7016
  const appliedScrollTopRef = useRef(null);
6918
7017
  useSafeLayoutEffect(() => {
6919
- if (!isBrowse || !gridRef.current) return;
7018
+ if (!isSourceBrowse || !gridRef.current) return;
6920
7019
  const pending = pendingScrollTopRef.current;
6921
7020
  if (!pending) return;
6922
7021
  if (pending.type === "reset" && (pending.filter !== filter || pending.sortBy !== sortBy)) return;
@@ -6937,10 +7036,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6937
7036
  gridRef.current.scrollTop = target;
6938
7037
  pendingScrollTopRef.current = null;
6939
7038
  updateGridMask();
6940
- }, [isBrowse, activeSourceId, updateGridMask]);
7039
+ }, [isSourceBrowse, activeSourceId, updateGridMask]);
6941
7040
 
6942
7041
  useEffect(() => {
6943
- if (!isBrowse) return;
7042
+ if (!isSourceBrowse) return;
6944
7043
  const applied = appliedScrollTopRef.current;
6945
7044
  if (applied === null) return;
6946
7045
  const { sourceId, target } = applied;
@@ -6960,7 +7059,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
6960
7059
  }
6961
7060
  });
6962
7061
  return () => cancelAnimationFrame(raf);
6963
- }, [isBrowse, activeSourceId, updateGridMask]);
7062
+ }, [isSourceBrowse, activeSourceId, updateGridMask]);
6964
7063
 
6965
7064
  useEffect(() => {
6966
7065
  const onDocClick = (e) => {
@@ -7006,6 +7105,32 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7006
7105
  }, [activeSourceId, setRows, showToast]);
7007
7106
 
7008
7107
  const currentSourceInstalledNames = useMemo(() => new Set((state.plugins || []).filter((p) => p.sourceId === activeSourceId).map((p) => p.name)), [state.plugins, activeSourceId]);
7108
+ // Each source retains its browsing order for this Hub session, including
7109
+ // tab navigation and panel remounts. Filtering or sorting takes a new
7110
+ // snapshot — derived here, committed below, so a render that React
7111
+ // discards leaves the session store untouched.
7112
+ const sortInstalledSnapshots = SESSION_STORE.browseSortSnapshots;
7113
+ const sortInstalledNames = useMemo(() => {
7114
+ const saved = sortInstalledSnapshots && sortInstalledSnapshots[activeSourceId];
7115
+ if (!saved || saved.filter !== filter || saved.query !== query || saved.sortBy !== sortBy) {
7116
+ return currentSourceInstalledNames;
7117
+ }
7118
+ // The captured order only ever loses names, never gains them: an
7119
+ // uninstall has to release the plugin's pinned slot at once (it drops
7120
+ // back into the current order like any other row), while an install
7121
+ // must still leave the list alone until the order is re-snapshotted.
7122
+ if (![...saved.names].some((n) => !currentSourceInstalledNames.has(n))) return saved.names;
7123
+ return new Set([...saved.names].filter((n) => currentSourceInstalledNames.has(n)));
7124
+ }, [sortInstalledSnapshots, activeSourceId, filter, query, sortBy, currentSourceInstalledNames]);
7125
+ // Only a new browsing order (or a tab switch) re-captures what is
7126
+ // installed. A plain install must leave the remembered order alone, so
7127
+ // the pruned set is never written back.
7128
+ useEffect(() => {
7129
+ if (!SESSION_STORE.browseSortSnapshots) SESSION_STORE.browseSortSnapshots = Object.create(null);
7130
+ const saved = SESSION_STORE.browseSortSnapshots[activeSourceId];
7131
+ if (saved && saved.filter === filter && saved.query === query && saved.sortBy === sortBy) return;
7132
+ SESSION_STORE.browseSortSnapshots[activeSourceId] = { filter, query, sortBy, names: currentSourceInstalledNames };
7133
+ }, [activeSourceId, filter, query, sortBy, currentSourceInstalledNames]);
7009
7134
  const installedNames = useMemo(() => new Set(state.plugins.map((p) => p.name)), [state.plugins]);
7010
7135
  const totalInstalledCount = state.plugins.length;
7011
7136
  const currentSourcePlugins = useMemo(() => (rows && rows[activeSourceId]) || [], [rows, activeSourceId]);
@@ -7158,17 +7283,17 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7158
7283
  } else if (sortBy === "name-desc") {
7159
7284
  list = [...list].sort((a, b) => (b.displayName || b.name).localeCompare(a.displayName || a.name));
7160
7285
  } else if (!query.trim()) {
7161
- // Use the same installed set for sorting and card actions on the first render.
7286
+ // Use the installed set captured when this browsing order was chosen.
7162
7287
  list = [...list].sort((a, b) => {
7163
- const instA = currentSourceInstalledNames.has(a.name) ? 1 : 0;
7164
- const instB = currentSourceInstalledNames.has(b.name) ? 1 : 0;
7288
+ const instA = sortInstalledNames.has(a.name) ? 1 : 0;
7289
+ const instB = sortInstalledNames.has(b.name) ? 1 : 0;
7165
7290
  if (instB !== instA) return instB - instA;
7166
7291
  return (a.displayName || a.name).localeCompare(b.displayName || b.name);
7167
7292
  });
7168
7293
  }
7169
7294
 
7170
7295
  return list;
7171
- }, [currentSourcePlugins, query, sortBy, currentSourceInstalledNames]);
7296
+ }, [currentSourcePlugins, query, sortBy, sortInstalledNames]);
7172
7297
 
7173
7298
  const refresh = async () => {
7174
7299
  setIsRefreshing(true);
@@ -7242,6 +7367,23 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7242
7367
  };
7243
7368
 
7244
7369
  const currentDetailPlugin = detail || (view && view.type === "detail" ? view.plugin : null);
7370
+ const manageRecord = view.type === "manage" ? state.plugins.find(r => r.name === view.pluginName) : null;
7371
+ const closeManage = () => {
7372
+ // A removal can finish after the user has switched to another tab.
7373
+ if (SESSION_STORE.view !== view) return;
7374
+ setView(view.returnView || { type: "browse", sourceId: activeSourceId });
7375
+ if (view.returnToMcp) setMcpsOpen(true);
7376
+ };
7377
+ const openPlugin = (plugin) => {
7378
+ closePluginHover();
7379
+ if (gridRef.current) {
7380
+ if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
7381
+ SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
7382
+ }
7383
+ const record = state.plugins.find(r => r.name === plugin.name);
7384
+ if (record) openManage(record);
7385
+ else setView({ type: "detail", sourceId: activeSourceId, plugin });
7386
+ };
7245
7387
 
7246
7388
  return h("div", { className: "cpm-main" },
7247
7389
  // Top bar matching Claude official: Row 1 (Full width search) & Row 2 (Tabs on Left + Filter & Sort on Right)
@@ -7269,7 +7411,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7269
7411
  hasMcps && h("button", {
7270
7412
  key: "__mcps",
7271
7413
  className: "cpm-tab" + (mcpsOpen ? " active" : ""),
7272
- onClick: () => { setMcpsOpen(true); refreshMcps(); setView({ type: "browse", sourceId: activeSourceId }); },
7414
+ onClick: () => {
7415
+ if (isSourceBrowse && gridRef.current) {
7416
+ if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
7417
+ SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
7418
+ }
7419
+ stopScrollTopAnim();
7420
+ setMcpsOpen(true); refreshMcps();
7421
+ },
7273
7422
  }, h("span", null, "MCP")),
7274
7423
  state.sources.map((s, idx) => {
7275
7424
  if (s.id === "local" && !hasLocalPlugins) return null;
@@ -7307,13 +7456,16 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7307
7456
 
7308
7457
  return h("button", {
7309
7458
  key: s.id,
7310
- ref: (el) => { if (el) tabRefs.current[s.id] = el; },
7459
+ ref: (el) => { tabRefs.current[s.id] = el; },
7311
7460
  className: "cpm-tab" + (s.id === activeSourceId && !mcpsOpen ? " active" : "") + tabClassExtra,
7312
7461
  style: tabTransform ? { transform: tabTransform } : undefined,
7313
7462
  onPointerDown: (e) => handleTabPointerDown(e, s, idx),
7314
7463
  onPointerMove: handleTabPointerMove,
7315
7464
  onPointerUp: (e) => handleTabPointerUp(e, s, idx),
7316
- onPointerCancel: (e) => handleTabPointerUp(e, s, idx),
7465
+ onPointerCancel: cancelOrResetDrag,
7466
+ onLostPointerCapture: (e) => {
7467
+ if (e.pointerId === dragLiveRef.current.pointerId && !dragLiveRef.current.isSnapping) cancelOrResetDrag();
7468
+ },
7317
7469
  onContextMenu: (e) => e.preventDefault(),
7318
7470
  onMouseDown: (e) => e.preventDefault(),
7319
7471
  onClick: () => setMcpsOpen(false),
@@ -7418,19 +7570,20 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7418
7570
  ),
7419
7571
  ),
7420
7572
 
7421
- view.type === "skill-detail" && (() => {
7573
+ !mcpsOpen && view.type === "skill-detail" && (() => {
7422
7574
  const selected = ((rows && rows["skills-local"]) || []).find(s => s.id === view.skill.id) || view.skill;
7423
- return h(SkillDetail, { skill: selected, isDark, containerRef: detailContainerRef, busy: skillBusy === selected.id, onToggle: toggleSkill, onRemove: removeUploadedSkill, onBack: () => setView({ type: "browse", sourceId: "skills-local" }) });
7575
+ return h(SkillDetail, { skill: selected, isDark, containerRef: detailContainerRef, scrollState: view, busy: skillBusy === selected.id, onToggle: toggleSkill, onRemove: removeUploadedSkill, onBack: () => setView({ type: "browse", sourceId: "skills-local" }) });
7424
7576
  })(),
7425
7577
 
7426
7578
  // Detail view — 0ms instant transition without intermediate loading screen
7427
- view.type === "detail" && currentDetailPlugin && h(DetailView, {
7579
+ !mcpsOpen && view.type === "detail" && currentDetailPlugin && h(DetailView, {
7428
7580
  plugin: {
7429
7581
  ...currentDetailPlugin,
7430
7582
  installed: installedNames.has(currentDetailPlugin.name),
7431
7583
  enabled: state.plugins.find((r) => r.name === currentDetailPlugin.name)?.enabled !== false,
7432
7584
  },
7433
7585
  pluginRecord: state.plugins.find((r) => r.name === currentDetailPlugin.name),
7586
+ scrollState: view,
7434
7587
  isDark,
7435
7588
  containerRef: detailContainerRef,
7436
7589
  onBack: () => setView({ type: "browse", sourceId: activeSourceId }),
@@ -7446,6 +7599,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7446
7599
  },
7447
7600
  showToast,
7448
7601
  }),
7602
+ !mcpsOpen && view.type === "manage" && h(ManagePage, {
7603
+ key: view.pluginName || manageRecord?.name,
7604
+ record: manageRecord || null, state, rows, isDark, refreshState, showToast,
7605
+ containerRef: detailContainerRef,
7606
+ initialTab: view.initialTab, initialConnector: view.initialConnector,
7607
+ scrollState: view,
7608
+ onBack: closeManage, onClose: closeManage,
7609
+ }),
7449
7610
 
7450
7611
  // Browse View — Mode A: Grouped Installed across all sources (Selected active tab source displayed first)
7451
7612
  isBrowse && activeSourceId !== "skills-local" && filter === "installed" && !mcpsOpen && h("div", {
@@ -7473,22 +7634,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7473
7634
  isDark,
7474
7635
  onMouseEnter: (e) => handleCardMouseEnter(p, e.currentTarget, { x: e.clientX, y: e.clientY, buttons: e.buttons }),
7475
7636
  onMouseLeave: () => handleCardMouseLeave(p),
7476
- onClick: () => {
7477
- closePluginHover();
7478
- if (gridRef.current) {
7479
- if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
7480
- SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
7481
- }
7482
- setView({ type: "detail", sourceId: p.sourceId || grp.source.id, plugin: p });
7483
- },
7637
+ onClick: () => openPlugin(p),
7484
7638
  onManage: (e) => {
7485
7639
  e.stopPropagation();
7486
- closePluginHover();
7487
- if (gridRef.current) {
7488
- if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
7489
- SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
7490
- }
7491
- openManage(state.plugins.find((r) => r.name === p.name), { type: "browse" });
7640
+ openPlugin(p);
7492
7641
  },
7493
7642
  onInstall: (e) => {
7494
7643
  e.stopPropagation();
@@ -7544,22 +7693,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7544
7693
  isDark,
7545
7694
  onMouseEnter: (e) => handleCardMouseEnter(p, e.currentTarget, { x: e.clientX, y: e.clientY, buttons: e.buttons }),
7546
7695
  onMouseLeave: () => handleCardMouseLeave(p),
7547
- onClick: () => {
7548
- closePluginHover();
7549
- if (gridRef.current) {
7550
- if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
7551
- SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
7552
- }
7553
- setView({ type: "detail", sourceId: activeSourceId, plugin: p });
7554
- },
7696
+ onClick: () => openPlugin(p),
7555
7697
  onManage: (e) => {
7556
7698
  e.stopPropagation();
7557
- closePluginHover();
7558
- if (gridRef.current) {
7559
- if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
7560
- SESSION_STORE.scrollTops[activeSourceId] = gridRef.current.scrollTop;
7561
- }
7562
- openManage(state.plugins.find((r) => r.name === p.name && (r.sourceId === activeSourceId || r.sourceId === p.sourceId)) || state.plugins.find((r) => r.name === p.name), { type: "browse" });
7699
+ openPlugin(p);
7563
7700
  },
7564
7701
  onInstall: (e) => {
7565
7702
  e.stopPropagation();
@@ -7653,7 +7790,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7653
7790
  showToast,
7654
7791
  }),
7655
7792
 
7656
- confirmRemoveSource && h("div", { className: "cpm-dialog", onClick: () => setConfirmRemoveSource(null) },
7793
+ confirmRemoveSource && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmRemoveSource(null)) },
7657
7794
  h("div", { className: "cpm-dialog-box", onClick: (e) => e.stopPropagation() },
7658
7795
  h("div", { className: "cpm-dialog-title" }, `删除插件源「${confirmRemoveSource.name}」`),
7659
7796
  h("div", { className: "cpm-field", style: { fontSize: 13, lineHeight: 1.6, color: "var(--cpm-muted)" } },
@@ -7700,14 +7837,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7700
7837
 
7701
7838
  // ────────────────────────────── Modern Floating Drag Overlay (Zero Container Clipping) ──────────────────────────────
7702
7839
  dragState?.active && h("div", {
7840
+ ref: dragOverlayRef,
7703
7841
  className: "cpm-tab-drag-overlay" + (isDark ? " cpm-dark" : ""),
7842
+ onTransitionEnd: (e) => {
7843
+ if (e.target === e.currentTarget && e.propertyName === "transform") snapFinishRef.current?.();
7844
+ },
7704
7845
  style: {
7705
- left: dragState.isSnapping ? dragState.snapTargetX : dragState.overlayX,
7706
- top: dragState.isSnapping ? dragState.snapTargetY : dragState.overlayY,
7707
7846
  width: dragState.width || "auto",
7708
7847
  height: dragState.height || 30,
7709
- transform: dragState.isSnapping ? "translate3d(0, 0, 0) scale(1)" : "translate3d(0, -4px, 0) scale(1.08)",
7710
- transition: dragState.isSnapping ? "left 0.18s cubic-bezier(0.2, 0, 0, 1), top 0.18s cubic-bezier(0.2, 0, 0, 1), transform 0.18s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.18s ease" : "none",
7848
+ transform: dragState.isSnapping
7849
+ ? `translate3d(${dragState.snapTargetX}px, ${dragState.snapTargetY}px, 0) scale(1)`
7850
+ : `translate3d(${dragLiveRef.current.currentOverlayX}px, ${dragLiveRef.current.startOverlayY - 4}px, 0) scale(1.04)`,
7851
+ transition: dragState.isSnapping ? "transform 260ms cubic-bezier(0.16, 1, 0.3, 1)" : "none",
7711
7852
  },
7712
7853
  },
7713
7854
  h("span", null, dragState.sourceName)
@@ -7715,10 +7856,23 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
7715
7856
  );
7716
7857
  }
7717
7858
 
7859
+ function backdropDismissProps(onDismiss) {
7860
+ let pressedBackdrop = false;
7861
+ return {
7862
+ onPointerDown: (event) => { pressedBackdrop = event.button === 0 && event.target === event.currentTarget; },
7863
+ onPointerCancel: () => { pressedBackdrop = false; },
7864
+ onClick: (event) => {
7865
+ const dismiss = pressedBackdrop && event.target === event.currentTarget;
7866
+ pressedBackdrop = false;
7867
+ if (dismiss) onDismiss();
7868
+ },
7869
+ };
7870
+ }
7871
+
7718
7872
  // ────────────────────────────── Modern Install Dialog ──────────────────────────────
7719
7873
  function InstallDialog({ plugin, isDark, onCancel, onConfirm }) {
7720
7874
  const [busy, setBusy] = useState(false);
7721
- return h("div", { className: "cpm-dialog", onClick: onCancel },
7875
+ return h("div", { className: "cpm-dialog", ...backdropDismissProps(onCancel) },
7722
7876
  h("div", { className: "cpm-dialog-box cpm-install-dialog", onClick: (e) => e.stopPropagation() },
7723
7877
  h("div", { className: "cpm-install-dialog-header" },
7724
7878
  h(PluginIcon, { plugin, isDark }),
@@ -8025,7 +8179,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
8025
8179
  }
8026
8180
  };
8027
8181
 
8028
- return h("div", { className: "cpm-dialog", onClick: onCancel },
8182
+ return h("div", { className: "cpm-dialog", ...backdropDismissProps(onCancel) },
8029
8183
  h("div", {
8030
8184
  role: "dialog",
8031
8185
  "aria-modal": "true",
@@ -8517,7 +8671,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
8517
8671
  }
8518
8672
  };
8519
8673
 
8520
- return h("div", { className: "cpm-dialog", onClick: onCancel },
8674
+ return h("div", { className: "cpm-dialog", ...backdropDismissProps(onCancel) },
8521
8675
  h("div", { className: "cpm-mcp-modal", onClick: (e) => e.stopPropagation() },
8522
8676
  h("button", { className: "cpm-mcp-close-top", onClick: onCancel }, h(IconClose, { size: 14 })),
8523
8677
  h("div", { className: "cpm-mcp-body" },
@@ -8755,7 +8909,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
8755
8909
  }, saving ? "保存中…" : "保存并启用"),
8756
8910
  ),
8757
8911
  ),
8758
- confirmDelete && h("div", { className: "cpm-dialog", onClick: () => setConfirmDelete(false) },
8912
+ confirmDelete && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmDelete(false)) },
8759
8913
  h("div", { className: "cpm-dialog-box", onClick: (e) => e.stopPropagation() },
8760
8914
  h("div", { className: "cpm-dialog-title" }, `删除 MCP「${initial.name}」`),
8761
8915
  h("div", { className: "cpm-field", style: { fontSize: 13, lineHeight: 1.6, color: "var(--cpm-muted)" } },
@@ -8896,11 +9050,11 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
8896
9050
  }
8897
9051
 
8898
9052
  // ────────────────────────────── Detail View ──────────────────────────────
8899
- function DetailView({ plugin, pluginRecord, isDark, onBack, onInstall, onRemove, onManage, onTogglePlugin, showToast, containerRef }) {
9053
+ function DetailView({ plugin, pluginRecord, isDark, onBack, onInstall, onRemove, onManage, onTogglePlugin, showToast, containerRef, scrollState }) {
8900
9054
  const [busy, setBusy] = useState(false);
8901
9055
  const [confirmRemove, setConfirmRemove] = useState(false);
8902
9056
  const [toggling, setToggling] = useState(false);
8903
- const { detailRef, maskClass: detailMaskClass, updateMask: updateDetailMask } = useDetailScrollMask(plugin?.name, containerRef, plugin);
9057
+ const { detailRef, maskClass: detailMaskClass, updateMask: updateDetailMask } = useDetailScrollMask(plugin?.name, containerRef, plugin, scrollState);
8904
9058
 
8905
9059
  if (!plugin) return null;
8906
9060
  const dark = typeof isDark === "boolean" ? isDark : (typeof isDarkMode === "function" ? isDarkMode() : false);
@@ -9105,7 +9259,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9105
9259
  }),
9106
9260
  ),
9107
9261
 
9108
- confirmRemove && h("div", { className: "cpm-dialog", onClick: () => setConfirmRemove(false) },
9262
+ confirmRemove && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmRemove(false)) },
9109
9263
  h("div", { className: "cpm-dialog-box", onClick: (e) => e.stopPropagation() },
9110
9264
  h("div", { className: "cpm-dialog-title" }, `卸载 ${plugin.displayName || plugin.name}?`),
9111
9265
  h("div", { className: "cpm-field", style: { color: "var(--cpm-muted)", fontSize: "13px", lineHeight: 1.5, marginBottom: "20px" } }, "将删除插件副本、技能与子代理注册及 MCP 配置。"),
@@ -9145,7 +9299,38 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9145
9299
  } catch {}
9146
9300
  }
9147
9301
 
9148
- // Shared tool grid for the MCP page and the plugin manage page: the
9302
+ function useAutoMcpTools(servers, loadTools) {
9303
+ const attempted = useRef(new Map());
9304
+ useEffect(() => {
9305
+ const active = new Set();
9306
+ for (const server of servers) {
9307
+ if (!server.connected || !server.name) continue;
9308
+ const key = `${server.owner}::${server.name}`;
9309
+ active.add(key);
9310
+ if (attempted.current.has(key) && attempted.current.get(key) === server.revision) continue;
9311
+ attempted.current.set(key, server.revision);
9312
+ void loadTools(server.owner, server.name);
9313
+ }
9314
+ for (const key of attempted.current.keys()) if (!active.has(key)) attempted.current.delete(key);
9315
+ }, [servers, loadTools]);
9316
+ }
9317
+
9318
+ function McpDiscoveryStatus({ info, expanded, onExpand, onRetry }) {
9319
+ if (!info || info.loading) return h("span", { className: "cpm-mcp-discovery", role: "status", "aria-live": "polite" },
9320
+ h("span", { className: "cpm-spin-ring", "aria-hidden": "true" }),
9321
+ h("span", null, "正在解析工具…"));
9322
+ if (info.error) return h("span", { className: "cpm-mcp-discovery is-error", role: "status", "aria-live": "polite" },
9323
+ h("span", { className: "cpm-mcp-discovery-message" }, `解析失败:${info.error}`),
9324
+ h("button", { type: "button", className: "cpm-mcp-retry", onClick: event => { event.stopPropagation(); onRetry(); } }, "重新解析"));
9325
+ const tools = info.tools || [], disabled = info.disabledTools || [];
9326
+ const active = tools.filter(tool => !disabled.includes(typeof tool === "string" ? tool : tool.name)).length;
9327
+ return h("button", { type: "button", className: "cpm-mcp-expand", "aria-expanded": !!expanded,
9328
+ onClick: event => { event.stopPropagation(); onExpand(); } },
9329
+ h("span", { className: "cpm-connector-collapse-btn" + (expanded ? " is-expanded" : ""), "aria-hidden": "true" }, h(IconArrow, { size: 10 })),
9330
+ h("span", null, `${active} tools enabled${disabled.length ? ` (${disabled.length} disabled)` : ""}`));
9331
+ }
9332
+
9333
+ // Shared tool grid for the MCP page and the plugin manage page: the
9149
9334
  // loading/error/empty branches and the hoverable pill grid are identical
9150
9335
  // there, and keeping one copy is what stops the two views drifting apart.
9151
9336
  function McpToolsPanel({ loading, error, tools, disabledTools, loadingText, onRetry, onHoverTool, onHoverEnd, onToggleTool }) {
@@ -9283,13 +9468,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9283
9468
  }
9284
9469
 
9285
9470
  // ────────────────────────────── Manage Page ──────────────────────────────
9286
- function ManagePage({ record, state, rows, isDark, refreshState, showToast, onBack, onClose, initialTab, initialConnector }) {
9471
+ function ManagePage(props) {
9472
+ useEffect(() => { if (!props.record) props.onClose(); }, [props.record, props.onClose]);
9473
+ return props.record ? h(ManagePageContent, props) : null;
9474
+ }
9475
+
9476
+ function ManagePageContent({ record, state, rows, isDark, refreshState, showToast, onBack, onClose, initialTab, initialConnector, containerRef, scrollState }) {
9287
9477
  const dark = typeof isDark === "boolean" ? isDark : (typeof isDarkMode === "function" ? isDarkMode() : false);
9288
- const [tab, setTab] = useState(initialTab || "skills");
9478
+ const [tab, setTabRaw] = useState(scrollState?.manageTab || initialTab || "skills");
9479
+ const setTab = (next) => { if (scrollState) scrollState.manageTab = next; setTabRaw(next); };
9289
9480
  const [searchOpen, setSearchOpen] = useState(false);
9290
9481
  const [tabQuery, setTabQuery] = useState("");
9291
9482
  const searchInputRef = useRef(null);
9292
- const [menuOpen, setMenuOpen] = useState(false);
9293
9483
  const [busy, setBusy] = useState(false);
9294
9484
  const [updating, setUpdating] = useState(false);
9295
9485
  const [toggling, setToggling] = useState(false);
@@ -9323,22 +9513,17 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9323
9513
  const loadConnectorTools = useCallback(async (connectorName, forceFresh = false) => {
9324
9514
  const key = `${record.name}::${connectorName}`;
9325
9515
  const cached = GLOBAL_MCP_TOOLS_CACHE[key];
9326
- const hasCachedTools = Array.isArray(cached?.tools) && cached.tools.length > 0;
9327
-
9328
- // If we already have cached tools, never show a spinner (0ms display)
9329
- if (!hasCachedTools) {
9330
- setConnectorToolsData((prev) => ({
9331
- ...prev,
9332
- [connectorName]: { ...(prev[connectorName] || {}), loading: true, error: null },
9333
- }));
9334
- }
9516
+ setConnectorToolsData((prev) => ({
9517
+ ...prev,
9518
+ [connectorName]: { ...(prev[connectorName] || {}), loading: true, error: null },
9519
+ }));
9335
9520
 
9336
9521
  try {
9337
9522
  const res = await api(`/plugins/${encodeURIComponent(record.name)}/connectors/${encodeURIComponent(connectorName)}/tools${forceFresh ? "?fresh=1" : ""}`);
9338
9523
  const tools = Array.isArray(res.tools) ? res.tools : [];
9339
9524
  const disabledTools = Array.isArray(res.disabledTools) ? res.disabledTools : [];
9340
9525
 
9341
- if (tools.length > 0) {
9526
+ if (res.ok) {
9342
9527
  saveMcpToolsCache(key, { tools, disabledTools });
9343
9528
  }
9344
9529
 
@@ -9347,22 +9532,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9347
9532
  [connectorName]: {
9348
9533
  loading: false,
9349
9534
  error: res.ok ? null : (res.message || "获取能力列表失败"),
9350
- tools: tools.length > 0 ? tools : (prev[connectorName]?.tools || []),
9535
+ tools: res.ok ? tools : (prev[connectorName]?.tools || tools),
9351
9536
  disabledTools,
9352
9537
  },
9353
9538
  }));
9354
9539
  } catch (e) {
9355
- if (!hasCachedTools) {
9356
- setConnectorToolsData((prev) => ({
9357
- ...prev,
9358
- [connectorName]: {
9359
- loading: false,
9360
- error: e.message,
9361
- tools: [],
9362
- disabledTools: [],
9363
- },
9364
- }));
9365
- }
9540
+ setConnectorToolsData((prev) => ({
9541
+ ...prev, [connectorName]: { ...(prev[connectorName] || cached), loading: false, error: e.message },
9542
+ }));
9366
9543
  }
9367
9544
  }, [record?.name]);
9368
9545
 
@@ -9463,28 +9640,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9463
9640
  await oauthFlow.start(payload);
9464
9641
  };
9465
9642
 
9466
- useEffect(() => {
9467
- if (record && Array.isArray(record.connectors)) {
9468
- record.connectors.forEach((c) => {
9469
- const cName = typeof c === "string" ? c : c.name;
9470
- const isConnected = typeof c === "object" ? (c.connected === true) : false;
9471
- if (isConnected) {
9472
- loadConnectorTools(cName);
9473
- }
9474
- });
9475
- }
9476
- }, [record?.name, record?.connectors, loadConnectorTools]);
9643
+ const autoLoadConnectorTools = useCallback((_owner, name) => loadConnectorTools(name), [loadConnectorTools]);
9644
+ useAutoMcpTools((record.connectors || []).map(connector => ({
9645
+ owner: record.name, name: connector.name, connected: connector.connected === true,
9646
+ revision: JSON.stringify([record.installedAt, connector]),
9647
+ })), autoLoadConnectorTools);
9477
9648
 
9478
9649
  const toggleExpandConnector = useCallback((connectorName) => {
9479
9650
  setExpandedConnectors((prev) => {
9480
9651
  const nextState = !prev[connectorName];
9481
- const curr = connectorToolsData[connectorName];
9482
- if (nextState && (!curr || !curr.tools || curr.tools.length === 0)) {
9483
- loadConnectorTools(connectorName);
9484
- }
9485
9652
  return { ...prev, [connectorName]: nextState };
9486
9653
  });
9487
- }, [loadConnectorTools, connectorToolsData]);
9654
+ }, []);
9488
9655
 
9489
9656
  const toggleTool = useCallback(async (connectorName, toolName, forcedEnabled) => {
9490
9657
  const key = `${record.name}::${connectorName}`;
@@ -9573,7 +9740,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9573
9740
  const latestVersion = (marketPlugin && (marketPlugin.version || (marketPlugin.detail && marketPlugin.detail.version))) || null;
9574
9741
  const hasUpdate = !!(latestVersion && compareSemver(latestVersion, installedVersion) > 0);
9575
9742
 
9576
- const manageRef = useRef(null);
9743
+ const localManageRef = useRef(null);
9744
+ const manageRef = containerRef || localManageRef;
9577
9745
  const [manageMaskClass, setManageMaskClass] = useState("");
9578
9746
 
9579
9747
  const updateManageMask = useCallback(() => {
@@ -9606,16 +9774,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9606
9774
 
9607
9775
  useLayoutEffect(() => {
9608
9776
  if (record) {
9609
- setTab("skills");
9777
+ setTab(scrollState?.manageTab || initialTab || "skills");
9610
9778
  setTabQuery("");
9611
9779
  setSearchOpen(false);
9612
- setMenuOpen(false);
9613
- if (manageRef.current) {
9614
- manageRef.current.scrollTop = 0;
9615
- }
9616
9780
  updateManageMask();
9617
9781
  }
9618
- }, [record?.name, updateManageMask]);
9782
+ }, [record?.name, initialTab, updateManageMask]);
9783
+ useRememberedDetailScroll(`${record?.name}:${tab}`, manageRef, scrollState, updateManageMask, record);
9619
9784
 
9620
9785
  useLayoutEffect(() => { updateManageMask(); });
9621
9786
  useEffect(() => {
@@ -9631,28 +9796,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9631
9796
  }
9632
9797
  }, [searchOpen]);
9633
9798
 
9634
- useEffect(() => {
9635
- if (!record) onClose();
9636
- }, [record, onClose]);
9637
-
9638
9799
  useEffect(() => {
9639
9800
  refreshState();
9640
9801
  }, []);
9641
9802
 
9642
- useEffect(() => {
9643
- const onDocClick = (e) => {
9644
- if (!e.target.closest(".cpm-menu")) {
9645
- setMenuOpen(false);
9646
- }
9647
- };
9648
- if (menuOpen) {
9649
- document.addEventListener("mousedown", onDocClick);
9650
- return () => document.removeEventListener("mousedown", onDocClick);
9651
- }
9652
- }, [menuOpen]);
9653
-
9654
- if (!record) return null;
9655
-
9656
9803
  const source = state.sources.find((s) => s.id === record.sourceId);
9657
9804
  const skills = (Array.isArray(record.skills) && record.skills.length > 0)
9658
9805
  ? record.skills
@@ -9899,7 +10046,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9899
10046
  h("button", { className: "cpm-back", style: { padding: 0 }, onClick: onBack }, h(IconChevronLeft), "Back"),
9900
10047
  ),
9901
10048
 
9902
- h("div", { className: "cpm-title-row", style: { marginTop: 8 } },
10049
+ h("div", { className: "cpm-title-row" },
9903
10050
  h("div", { className: "cpm-title-group" },
9904
10051
  h(PluginIcon, {
9905
10052
  plugin: marketPlugin ? {
@@ -9923,20 +10070,16 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
9923
10070
  "data-cpm-tip": updating ? "正在更新…" : (hasUpdate ? `可更新至 v${latestVersion}` : `当前已是最新版本 (v${installedVersion})`),
9924
10071
  onClick: hasUpdate && !updating ? update : undefined,
9925
10072
  }, updating ? "Updating…" : "Update"),
10073
+ h("button", {
10074
+ type: "button", className: "cpm-btn cpm-btn-danger",
10075
+ disabled: busy || updating || toggling,
10076
+ onClick: () => setConfirmRemove(true),
10077
+ }, "Remove"),
9926
10078
  h("button", {
9927
10079
  className: "cpm-toggle" + (record.enabled ? " on" : ""),
9928
10080
  onClick: toggling ? undefined : toggle,
9929
10081
  disabled: toggling || updating || busy,
9930
10082
  }),
9931
- h("div", { className: "cpm-menu" },
9932
- h("button", { className: "cpm-icon-btn", style: { width: 32, height: 32, padding: 0 }, onClick: () => setMenuOpen(!menuOpen) }, h(IconMore)),
9933
- menuOpen && h("div", { className: "cpm-menu-pop" },
9934
- h("div", {
9935
- className: "cpm-menu-item danger",
9936
- onClick: () => { setMenuOpen(false); setConfirmRemove(true); },
9937
- }, "卸载插件"),
9938
- ),
9939
- ),
9940
10083
  ),
9941
10084
 
9942
10085
  h("div", { className: "cpm-meta" },
@@ -10076,56 +10219,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
10076
10219
  }),
10077
10220
  ),
10078
10221
 
10079
- activeTab === "agents" && h("div", { className: "cpm-skill-list" },
10222
+ activeTab === "agents" && h("div", null,
10080
10223
  visibleAgents.length === 0 && h("div", { className: "cpm-empty" }, tabQuery ? "未找到匹配的 agents" : "没有可用 agents"),
10081
- visibleAgents.map((a) => {
10082
- const aFile = typeof a === "string" ? a : a.file || a.name || String(a);
10083
- const aDisplayName = typeof a === "object" && a.displayName ? a.displayName : (typeof a === "object" && a.name ? a.name : aFile.replace(/\.[^.]+$/, ""));
10084
- let aDesc = typeof a === "object" && a.description ? a.description : "Autonomous sub-agent workflow";
10085
- if (aDesc === ">" || aDesc === "|" || aDesc === ">-" || aDesc === "|-") aDesc = "Autonomous sub-agent workflow";
10086
- const tools = typeof a === "object" && a.tools ? a.tools : null;
10087
- const model = typeof a === "object" && a.model ? a.model : null;
10088
-
10089
- return h("div", { key: aFile, className: "cpm-skill-item" },
10090
- h("div", { style: { display: "flex", alignItems: "center", gap: 8, flexWrap: "wrap" } },
10091
- h("div", { className: "cpm-skill-name" }, aDisplayName),
10092
- h("span", {
10093
- style: {
10094
- fontSize: 10.5,
10095
- fontWeight: 600,
10096
- padding: "2px 6px",
10097
- borderRadius: 4,
10098
- background: "rgba(168, 85, 247, 0.12)",
10099
- color: "#a855f7",
10100
- letterSpacing: "0.5px",
10101
- },
10102
- }, "SUBAGENT"),
10103
- model && h("span", {
10104
- style: {
10105
- fontSize: 10.5,
10106
- padding: "1px 5px",
10107
- borderRadius: 3,
10108
- background: "rgba(161, 161, 170, 0.12)",
10109
- color: "var(--cpm-muted)",
10110
- },
10111
- }, model),
10112
- ),
10113
- aDesc ? h("div", { className: "cpm-skill-desc", style: { marginTop: 4 } }, h(SmartMarkdown, { text: aDesc })) : null,
10114
- tools && h("div", {
10115
- style: {
10116
- fontSize: 11.5,
10117
- color: "var(--cpm-muted)",
10118
- marginTop: 4,
10119
- display: "flex",
10120
- alignItems: "center",
10121
- gap: 4,
10122
- },
10123
- },
10124
- h("span", { style: { opacity: 0.7 } }, "Tools:"),
10125
- h("code", { style: { fontSize: 11, background: "rgba(128,128,128,0.1)", padding: "1px 4px", borderRadius: 3 } }, tools),
10126
- ),
10127
- );
10128
- }),
10224
+ visibleAgents.length > 0 && h("ul", { className: "cpm-agent-list", "aria-label": "Agents" },
10225
+ visibleAgents.map((agent, index) => h(AgentCard, { key: (typeof agent === "string" ? agent : agent?.file || agent?.name) || index, agent }))),
10129
10226
  ),
10130
10227
 
10131
10228
  activeTab === "hooks" && h("div", { className: "cpm-skill-list" },
@@ -10224,7 +10321,6 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
10224
10321
  const toolsInfo = connectorToolsData[cName];
10225
10322
  const toolsList = toolsInfo?.tools || [];
10226
10323
  const disabledTools = toolsInfo?.disabledTools || [];
10227
- const activeToolsCount = toolsList.filter((t) => !disabledTools.includes(typeof t === "string" ? t : t.name)).length;
10228
10324
 
10229
10325
  return h("div", {
10230
10326
  key: cName,
@@ -10256,33 +10352,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
10256
10352
  onClick: isPendingVerify ? () => openAuthDialog(cName, c) : undefined,
10257
10353
  }, isConnected ? "● 已连接" : (isPendingVerify ? "○ 待验证" : "○ 未连接")),
10258
10354
 
10259
- // Figure 2: Dropdown Chevron + Tool count badge (Clean minimal arrow, tight spacing, no tooltip)
10260
- isConnected && isAuthenticated && h("div", {
10261
- style: {
10262
- display: "inline-flex",
10263
- alignItems: "center",
10264
- gap: 4,
10265
- cursor: "pointer",
10266
- marginLeft: 2,
10267
- },
10268
- onClick: (e) => {
10269
- e.stopPropagation();
10270
- toggleExpandConnector(cName);
10271
- },
10272
- },
10273
- h("button", {
10274
- type: "button",
10275
- className: "cpm-connector-collapse-btn" + (isExpanded ? " is-expanded" : ""),
10276
- }, h(IconArrow, { size: 10 })),
10277
- toolsList.length > 0 && h("span", {
10278
- style: {
10279
- fontSize: 11.5,
10280
- fontWeight: 500,
10281
- color: "var(--cpm-muted)",
10282
- userSelect: "none",
10283
- },
10284
- }, `${activeToolsCount} tools enabled${disabledTools.length > 0 ? ` (${disabledTools.length} disabled)` : ""}`),
10285
- ),
10355
+ isConnected && isAuthenticated && h(McpDiscoveryStatus, {
10356
+ info: toolsInfo, expanded: isExpanded,
10357
+ onExpand: () => toggleExpandConnector(cName), onRetry: () => loadConnectorTools(cName, true),
10358
+ }),
10286
10359
  ),
10287
10360
  h("div", { className: "cpm-skill-desc", style: { marginTop: 4 } },
10288
10361
  endpoint ? `${transport.toUpperCase()} · ${endpoint}` : "Model Context Protocol (MCP) 服务连接器",
@@ -10310,13 +10383,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
10310
10383
  ),
10311
10384
 
10312
10385
  // Figure 1 & Figure 3: Expandable Capabilities Panel
10313
- isConnected && isAuthenticated && isExpanded && h(McpToolsPanel, {
10386
+ isConnected && isAuthenticated && isExpanded && toolsInfo && !toolsInfo.loading && !toolsInfo.error && h(McpToolsPanel, {
10314
10387
  loading: toolsInfo?.loading,
10315
10388
  error: toolsInfo?.error,
10316
10389
  tools: toolsList,
10317
10390
  disabledTools,
10318
10391
  loadingText: "正在启动本地 MCP 服务并解析工具列表(首次启动可能需要下载组件)…",
10319
- onRetry: () => loadConnectorTools(cName),
10392
+ onRetry: () => loadConnectorTools(cName, true),
10320
10393
  onHoverTool: (tool, rect, anchor, pointer, keyboard) => toolHover.enter({ connectorName: cName, tool, rect }, anchor, pointer, keyboard),
10321
10394
  onHoverEnd: (anchor) => toolHover.leave(anchor),
10322
10395
  onToggleTool: (toolName) => toggleTool(cName, toolName),
@@ -10326,7 +10399,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
10326
10399
  ),
10327
10400
  ),
10328
10401
 
10329
- authDialog && h("div", { className: "cpm-dialog", onClick: closeAuthDialog },
10402
+ authDialog && h("div", { className: "cpm-dialog", ...backdropDismissProps(closeAuthDialog) },
10330
10403
  h("div", { className: "cpm-mcp-modal", onClick: (e) => e.stopPropagation() },
10331
10404
  h("button", {
10332
10405
  className: "cpm-mcp-close-top",
@@ -10668,7 +10741,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
10668
10741
  ),
10669
10742
  ),
10670
10743
 
10671
- confirmRemove && h("div", { className: "cpm-dialog", onClick: () => setConfirmRemove(false) },
10744
+ confirmRemove && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmRemove(false)) },
10672
10745
  h("div", { className: "cpm-dialog-box", onClick: (e) => e.stopPropagation() },
10673
10746
  h("div", { className: "cpm-dialog-title" }, `卸载 ${record.displayName || record.name}?`),
10674
10747
  h("div", { className: "cpm-field", style: { color: "var(--cpm-muted)", fontSize: "13px", lineHeight: 1.5, marginBottom: "20px" } }, "将删除插件副本、技能与子代理注册及 MCP 配置。"),
@@ -10692,6 +10765,45 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
10692
10765
  );
10693
10766
  }
10694
10767
 
10768
+ function groupAgentTools(tools) {
10769
+ const names = (Array.isArray(tools) ? tools : [tools])
10770
+ .flatMap(value => typeof value === "string" ? value.split(/,(?![^()]*\))/) : [])
10771
+ .map(name => name.trim()).filter(Boolean);
10772
+ const groups = new Map();
10773
+ for (const fullName of names) {
10774
+ const separator = fullName.startsWith("mcp__") ? fullName.indexOf("__", 5) : -1;
10775
+ const qualified = separator > 5 && separator + 2 < fullName.length;
10776
+ const namespace = qualified ? fullName.slice(0, separator) : "";
10777
+ if (!groups.has(namespace)) groups.set(namespace, { namespace, tools: [] });
10778
+ groups.get(namespace).tools.push({ fullName, name: qualified ? fullName.slice(separator + 2) : fullName });
10779
+ }
10780
+ return [...groups.values()];
10781
+ }
10782
+
10783
+ function AgentCard({ agent }) {
10784
+ const info = agent && typeof agent === "object" ? agent : {};
10785
+ const file = typeof agent === "string" ? agent : info.file || info.name || "Agent";
10786
+ const name = info.displayName || info.name || file.replace(/\.[^.]+$/, "");
10787
+ const rawDescription = info.description || "Autonomous sub-agent workflow";
10788
+ const description = [">", "|", ">-", "|-"].includes(rawDescription) ? "Autonomous sub-agent workflow" : rawDescription;
10789
+ const groups = groupAgentTools(info.tools);
10790
+ const count = groups.reduce((total, group) => total + group.tools.length, 0);
10791
+ return h("li", { className: "cpm-agent-item" },
10792
+ h("div", { className: "cpm-agent-header" },
10793
+ h("h3", { className: "cpm-agent-name" }, name),
10794
+ h("div", { className: "cpm-agent-meta" },
10795
+ h("span", null, "Subagent"),
10796
+ info.model && h("span", { className: "cpm-agent-model" }, info.model),
10797
+ count > 0 && h("span", null, `${count} ${count === 1 ? "tool" : "tools"}`))),
10798
+ h("div", { className: "cpm-agent-description" }, h(SmartMarkdown, { text: description })),
10799
+ count > 0 && h("div", { className: "cpm-agent-tools" },
10800
+ groups.map(group => h("div", { key: group.namespace, className: "cpm-agent-tool-group" },
10801
+ h("span", { className: "cpm-agent-tool-source" }, group.namespace || "Tools"),
10802
+ h("ul", { className: "cpm-agent-tool-list", "aria-label": group.namespace || "Tools" },
10803
+ group.tools.map((tool, index) => h("li", { key: index },
10804
+ h("code", { className: "cpm-agent-tool", "aria-label": tool.fullName, "data-tool-name": tool.fullName }, tool.name))))))));
10805
+ }
10806
+
10695
10807
  class ErrorBoundary extends React.Component {
10696
10808
  constructor(props) {
10697
10809
  super(props);