universal-plugin-hub 1.5.1 → 1.5.5
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/assets/icon.svg +20 -0
- package/client/client.js +236 -36
- package/package.json +4 -1
- package/src/install.js +171 -60
- package/src/market.js +66 -9
- package/src/parser.js +79 -7
- package/src/store.js +50 -24
package/assets/icon.svg
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36" fill="none">
|
|
2
|
+
<title>Universal Plugin Hub</title>
|
|
3
|
+
<defs>
|
|
4
|
+
<linearGradient id="uph-bg" x1="18" y1="2.2" x2="18" y2="34" gradientUnits="userSpaceOnUse">
|
|
5
|
+
<stop offset="0" stop-color="#3BBCE8"/>
|
|
6
|
+
<stop offset="0.26" stop-color="#4D88FE"/>
|
|
7
|
+
<stop offset="0.56" stop-color="#4D6BFE"/>
|
|
8
|
+
<stop offset="1" stop-color="#3B54E0"/>
|
|
9
|
+
</linearGradient>
|
|
10
|
+
<linearGradient id="uph-handle" x1="18" y1="5.2" x2="18" y2="13.2" gradientUnits="userSpaceOnUse">
|
|
11
|
+
<stop offset="0" stop-color="#FFFFFF"/>
|
|
12
|
+
<stop offset="1" stop-color="#EFF5FF"/>
|
|
13
|
+
</linearGradient>
|
|
14
|
+
</defs>
|
|
15
|
+
<path d="M34.000 18.000C34.000 22.002 34.000 23.948 33.887 25.574C33.709 28.145 33.220 30.303 31.762 31.762C30.303 33.220 28.145 33.709 25.574 33.887C23.948 34.000 22.002 34.000 18.000 34.000C13.998 34.000 12.052 34.000 10.426 33.887C7.855 33.709 5.697 33.220 4.238 31.762C2.780 30.303 2.291 28.145 2.113 25.574C2.000 23.948 2.000 22.002 2.000 18.000C2.000 13.998 2.000 12.052 2.113 10.426C2.291 7.855 2.780 5.697 4.238 4.238C5.697 2.780 7.855 2.291 10.426 2.113C12.052 2.000 13.998 2.000 18.000 2.000C22.002 2.000 23.948 2.000 25.574 2.113C28.145 2.291 30.303 2.780 31.762 4.238C33.220 5.697 33.709 7.855 33.887 10.426C34.000 12.052 34.000 13.998 34.000 18.000Z" fill="url(#uph-bg)"/>
|
|
16
|
+
<path d="M10.000 6.301A8.000 6.848 0 0 0 26.000 6.301A0.973 0.973 0 0 0 25.027 5.328L23.933 5.328A0.973 0.973 0 0 0 22.960 6.301A4.960 3.808 0 0 1 13.040 6.301A0.973 0.973 0 0 0 12.067 5.328L10.973 5.328A0.973 0.973 0 0 0 10.000 6.301Z" transform="translate(0 0.6)" fill="#18308C" fill-opacity="0.22"/>
|
|
17
|
+
<path d="M10.000 6.301A8.000 6.848 0 0 0 26.000 6.301A0.973 0.973 0 0 0 25.027 5.328L23.933 5.328A0.973 0.973 0 0 0 22.960 6.301A4.960 3.808 0 0 1 13.040 6.301A0.973 0.973 0 0 0 12.067 5.328L10.973 5.328A0.973 0.973 0 0 0 10.000 6.301Z" fill="url(#uph-handle)"/>
|
|
18
|
+
<path d="M8.61 22.98L8.61 24.90L7.86 24.90L7.86 19.70L9.37 19.70Q10.24 19.70 10.72 20.11Q11.19 20.52 11.19 21.27Q11.19 22.02 10.68 22.50Q10.17 22.98 9.30 22.98L8.61 22.98ZM8.61 20.34L8.61 22.34L9.20 22.34Q9.79 22.34 10.10 22.07Q10.41 21.80 10.41 21.31Q10.41 20.34 9.27 20.34L8.61 20.34ZM12.85 24.90L12.12 24.90L12.12 19.40L12.85 19.40L12.85 24.90ZM17.22 24.90L16.49 24.90L16.49 24.31L16.47 24.31Q16.11 24.99 15.33 24.99Q14.01 24.99 14.01 23.41L14.01 21.19L14.74 21.19L14.74 23.32Q14.74 24.39 15.57 24.39Q15.97 24.39 16.23 24.10Q16.49 23.80 16.49 23.32L16.49 21.19L17.22 21.19L17.22 24.90ZM21.73 24.60Q21.73 26.65 19.72 26.65Q19.01 26.65 18.49 26.40L18.49 25.71Q19.10 26.05 19.66 26.05Q21.00 26.05 21.00 24.68L21.00 24.28L20.99 24.28Q20.57 24.99 19.73 24.99Q19.04 24.99 18.62 24.49Q18.20 24.00 18.20 23.16Q18.20 22.22 18.65 21.66Q19.10 21.10 19.89 21.10Q20.63 21.10 20.99 21.70L21.00 21.70L21.00 21.19L21.73 21.19L21.73 24.60ZM21.01 23.21L21.01 22.70Q21.01 22.28 20.73 21.99Q20.45 21.69 20.04 21.69Q19.53 21.69 19.24 22.07Q18.95 22.44 18.95 23.12Q18.95 23.70 19.23 24.05Q19.51 24.39 19.96 24.39Q20.43 24.39 20.72 24.06Q21.01 23.73 21.01 23.21ZM23.34 20.33Q23.15 20.33 23.02 20.21Q22.89 20.09 22.89 19.90Q22.89 19.71 23.02 19.59Q23.15 19.46 23.34 19.46Q23.53 19.46 23.66 19.59Q23.80 19.71 23.80 19.90Q23.80 20.08 23.66 20.21Q23.53 20.33 23.34 20.33ZM23.70 24.90L22.97 24.90L22.97 21.19L23.70 21.19L23.70 24.90ZM28.14 24.90L27.41 24.90L27.41 22.80Q27.41 21.69 26.62 21.69Q26.20 21.69 25.93 22.00Q25.67 22.31 25.67 22.78L25.67 24.90L24.93 24.90L24.93 21.19L25.67 21.19L25.67 21.80L25.68 21.80Q26.10 21.10 26.89 21.10Q27.50 21.10 27.82 21.49Q28.14 21.89 28.14 22.63L28.14 24.90Z" transform="translate(0 0.4)" fill="#18308C" fill-opacity="0.20"/>
|
|
19
|
+
<path id="uph-wordmark" d="M8.61 22.98L8.61 24.90L7.86 24.90L7.86 19.70L9.37 19.70Q10.24 19.70 10.72 20.11Q11.19 20.52 11.19 21.27Q11.19 22.02 10.68 22.50Q10.17 22.98 9.30 22.98L8.61 22.98ZM8.61 20.34L8.61 22.34L9.20 22.34Q9.79 22.34 10.10 22.07Q10.41 21.80 10.41 21.31Q10.41 20.34 9.27 20.34L8.61 20.34ZM12.85 24.90L12.12 24.90L12.12 19.40L12.85 19.40L12.85 24.90ZM17.22 24.90L16.49 24.90L16.49 24.31L16.47 24.31Q16.11 24.99 15.33 24.99Q14.01 24.99 14.01 23.41L14.01 21.19L14.74 21.19L14.74 23.32Q14.74 24.39 15.57 24.39Q15.97 24.39 16.23 24.10Q16.49 23.80 16.49 23.32L16.49 21.19L17.22 21.19L17.22 24.90ZM21.73 24.60Q21.73 26.65 19.72 26.65Q19.01 26.65 18.49 26.40L18.49 25.71Q19.10 26.05 19.66 26.05Q21.00 26.05 21.00 24.68L21.00 24.28L20.99 24.28Q20.57 24.99 19.73 24.99Q19.04 24.99 18.62 24.49Q18.20 24.00 18.20 23.16Q18.20 22.22 18.65 21.66Q19.10 21.10 19.89 21.10Q20.63 21.10 20.99 21.70L21.00 21.70L21.00 21.19L21.73 21.19L21.73 24.60ZM21.01 23.21L21.01 22.70Q21.01 22.28 20.73 21.99Q20.45 21.69 20.04 21.69Q19.53 21.69 19.24 22.07Q18.95 22.44 18.95 23.12Q18.95 23.70 19.23 24.05Q19.51 24.39 19.96 24.39Q20.43 24.39 20.72 24.06Q21.01 23.73 21.01 23.21ZM23.34 20.33Q23.15 20.33 23.02 20.21Q22.89 20.09 22.89 19.90Q22.89 19.71 23.02 19.59Q23.15 19.46 23.34 19.46Q23.53 19.46 23.66 19.59Q23.80 19.71 23.80 19.90Q23.80 20.08 23.66 20.21Q23.53 20.33 23.34 20.33ZM23.70 24.90L22.97 24.90L22.97 21.19L23.70 21.19L23.70 24.90ZM28.14 24.90L27.41 24.90L27.41 22.80Q27.41 21.69 26.62 21.69Q26.20 21.69 25.93 22.00Q25.67 22.31 25.67 22.78L25.67 24.90L24.93 24.90L24.93 21.19L25.67 21.19L25.67 21.80L25.68 21.80Q26.10 21.10 26.89 21.10Q27.50 21.10 27.82 21.49Q28.14 21.89 28.14 22.63L28.14 24.90Z" fill="#FFFFFF"/>
|
|
20
|
+
</svg>
|
package/client/client.js
CHANGED
|
@@ -5383,7 +5383,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5383
5383
|
}
|
|
5384
5384
|
|
|
5385
5385
|
function AnthropicIcon({ isDark }) {
|
|
5386
|
-
return h("
|
|
5386
|
+
return h("span", {
|
|
5387
5387
|
className: "cpm-card-icon",
|
|
5388
5388
|
style: {
|
|
5389
5389
|
background: isDark ? "#18181b" : "#f4f1ea",
|
|
@@ -5403,7 +5403,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5403
5403
|
}
|
|
5404
5404
|
|
|
5405
5405
|
function Context7Icon({ isDark }) {
|
|
5406
|
-
return h("
|
|
5406
|
+
return h("span", {
|
|
5407
5407
|
className: "cpm-card-icon",
|
|
5408
5408
|
style: {
|
|
5409
5409
|
background: isDark ? "#09090b" : "#000000",
|
|
@@ -5605,8 +5605,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5605
5605
|
const renderedFallback = (!inline && typeof React !== "undefined" && typeof PluginIconFallback === "function" && React.isValidElement?.(fallback) && fallback.type === PluginIconFallback)
|
|
5606
5606
|
? React.cloneElement(fallback, { underlay: !!avatarUrl })
|
|
5607
5607
|
: fallback;
|
|
5608
|
-
return h("
|
|
5609
|
-
h("
|
|
5608
|
+
return h("span", { className: "cpm-card-icon", style: { position: "relative", overflow: "hidden" } },
|
|
5609
|
+
h("span", { className: "cpm-icon-underlay", "aria-hidden": true, style: { position: "absolute", inset: 0, opacity: imgLoaded ? 0 : 1 } }, inline ? null : renderedFallback),
|
|
5610
5610
|
// A plugin-local icon is a same-origin disk read, so deferring it to
|
|
5611
5611
|
// the viewport buys nothing and costs a visible placeholder on scroll.
|
|
5612
5612
|
// Only remote avatars are worth deferring — and never above the fold.
|
|
@@ -5668,7 +5668,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5668
5668
|
}
|
|
5669
5669
|
|
|
5670
5670
|
// Use the upstream 3D PNG unchanged; declared logos retain priority.
|
|
5671
|
-
return h("
|
|
5671
|
+
return h("span", {
|
|
5672
5672
|
className: "cpm-card-icon cpm-fallback-icon",
|
|
5673
5673
|
"aria-hidden": true,
|
|
5674
5674
|
style: {
|
|
@@ -5685,6 +5685,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5685
5685
|
plugin,
|
|
5686
5686
|
iconPlugin = plugin,
|
|
5687
5687
|
installed,
|
|
5688
|
+
installing = false,
|
|
5688
5689
|
eagerIcon = false,
|
|
5689
5690
|
isDark,
|
|
5690
5691
|
onMouseEnter,
|
|
@@ -5715,8 +5716,9 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
5715
5716
|
}, "管理")
|
|
5716
5717
|
: h("button", {
|
|
5717
5718
|
className: "cpm-card-pill",
|
|
5718
|
-
|
|
5719
|
-
|
|
5719
|
+
disabled: installing,
|
|
5720
|
+
onClick: installing ? (e) => e.stopPropagation() : onInstall,
|
|
5721
|
+
}, installing ? "安装中…" : "安装")),
|
|
5720
5722
|
);
|
|
5721
5723
|
}
|
|
5722
5724
|
|
|
@@ -8178,6 +8180,13 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
8178
8180
|
|
|
8179
8181
|
const [confirmRemoveSource, setConfirmRemoveSource] = useState(null);
|
|
8180
8182
|
const [installFor, setInstallFor] = useState(null);
|
|
8183
|
+
const installDialogBusyRef = useRef(false);
|
|
8184
|
+
useEffect(() => {
|
|
8185
|
+
if (!installFor) installDialogBusyRef.current = false;
|
|
8186
|
+
}, [installFor]);
|
|
8187
|
+
const installingNamesRef = useRef(new Set());
|
|
8188
|
+
const [installingNames, setInstallingNames] = useState(() => new Set());
|
|
8189
|
+
const isPluginInstalling = (name) => installingNames.has(String(name || "").toLowerCase());
|
|
8181
8190
|
const [hoveredPreview, closePluginHover, pluginHover] = useHoverPreview(240);
|
|
8182
8191
|
const installedByName = useMemo(() => new Map(state.plugins.map(plugin => [plugin.name, plugin])), [state.plugins]);
|
|
8183
8192
|
const resolveMarketplaceIcon = useMemo(() => createMarketplaceIconResolver(installedByName, state.sources), [installedByName, state.sources]);
|
|
@@ -9198,6 +9207,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9198
9207
|
SESSION_STORE.browseSortSnapshots[activeSourceId] = { filter, query, sortBy, names: currentSourceInstalledNames };
|
|
9199
9208
|
}, [activeSourceId, filter, query, sortBy, currentSourceInstalledNames]);
|
|
9200
9209
|
const installedNames = useMemo(() => new Set(state.plugins.map((p) => p.name)), [state.plugins]);
|
|
9210
|
+
const totalInstalledCount = Array.isArray(state?.plugins) ? state.plugins.length : 0;
|
|
9201
9211
|
const currentSourcePlugins = useMemo(() => (rows && rows[activeSourceId]) || [], [rows, activeSourceId]);
|
|
9202
9212
|
const totalSourcePluginsCount = currentSourcePlugins.length;
|
|
9203
9213
|
|
|
@@ -9308,9 +9318,9 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9308
9318
|
}, [view]);
|
|
9309
9319
|
|
|
9310
9320
|
useDialogEscape(!!(installFor || addDialog || confirmRemoveSource || mcpDialog), () => {
|
|
9311
|
-
if (installFor) setInstallFor(null);
|
|
9321
|
+
if (installFor && !installDialogBusyRef.current) setInstallFor(null);
|
|
9312
9322
|
if (addDialog && !addDialogBusyRef.current) setAddDialog(false);
|
|
9313
|
-
if (confirmRemoveSource) setConfirmRemoveSource(null);
|
|
9323
|
+
if (confirmRemoveSource && !busy) setConfirmRemoveSource(null);
|
|
9314
9324
|
if (mcpDialog) {
|
|
9315
9325
|
setMcpDialog(false);
|
|
9316
9326
|
setEditMcp(null);
|
|
@@ -9433,12 +9443,18 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9433
9443
|
};
|
|
9434
9444
|
|
|
9435
9445
|
const doInstall = async () => {
|
|
9446
|
+
const target = installFor;
|
|
9447
|
+
if (!target) return;
|
|
9448
|
+
const key = String(target.name || "").toLowerCase();
|
|
9449
|
+
if (installingNamesRef.current.has(key)) return;
|
|
9450
|
+
installingNamesRef.current.add(key);
|
|
9451
|
+
setInstallingNames((prev) => { const next = new Set(prev); next.add(key); return next; });
|
|
9436
9452
|
try {
|
|
9437
9453
|
const result = await api("/plugins/install", {
|
|
9438
9454
|
method: "POST",
|
|
9439
9455
|
body: JSON.stringify({
|
|
9440
|
-
sourceId:
|
|
9441
|
-
pluginName:
|
|
9456
|
+
sourceId: target.sourceId,
|
|
9457
|
+
pluginName: target.name,
|
|
9442
9458
|
}),
|
|
9443
9459
|
});
|
|
9444
9460
|
const parts = [];
|
|
@@ -9448,11 +9464,14 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9448
9464
|
if (result.connectors && result.connectors.length) parts.push(`${result.connectors.length} 个 MCP 服务`);
|
|
9449
9465
|
const summary = parts.length ? `${parts.join("、")}已就绪。` : "插件已安装就绪。";
|
|
9450
9466
|
void showApplicationToast(showToast, result, "安装完成", summary);
|
|
9451
|
-
setInstallFor(null);
|
|
9467
|
+
setInstallFor((cur) => (cur && cur.name === target.name && cur.sourceId === target.sourceId ? null : cur));
|
|
9452
9468
|
await refreshState();
|
|
9453
9469
|
onInstalled();
|
|
9454
9470
|
} catch (e) {
|
|
9455
9471
|
showToast("安装失败", e.message, { restart: false });
|
|
9472
|
+
} finally {
|
|
9473
|
+
installingNamesRef.current.delete(key);
|
|
9474
|
+
setInstallingNames((prev) => { if (!prev.has(key)) return prev; const next = new Set(prev); next.delete(key); return next; });
|
|
9456
9475
|
}
|
|
9457
9476
|
};
|
|
9458
9477
|
|
|
@@ -9609,7 +9628,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9609
9628
|
if (!SESSION_STORE.scrollTops) SESSION_STORE.scrollTops = {};
|
|
9610
9629
|
SESSION_STORE.scrollTops[activeSourceId] = 0;
|
|
9611
9630
|
scrollContentToTop();
|
|
9612
|
-
} },
|
|
9631
|
+
} }, `已安装 (${totalInstalledCount})`),
|
|
9613
9632
|
),
|
|
9614
9633
|
),
|
|
9615
9634
|
h("div", { style: { position: "relative" } },
|
|
@@ -9686,9 +9705,10 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9686
9705
|
pluginRecord: state.plugins.find((r) => r.name === currentDetailPlugin.name),
|
|
9687
9706
|
scrollState: view,
|
|
9688
9707
|
isDark,
|
|
9708
|
+
installing: Boolean(currentDetailPlugin && isPluginInstalling(currentDetailPlugin.name)),
|
|
9689
9709
|
containerRef: detailContainerRef,
|
|
9690
9710
|
onBack: () => setView({ type: "browse", sourceId: activeSourceId }),
|
|
9691
|
-
onInstall: () => setInstallFor(currentDetailPlugin),
|
|
9711
|
+
onInstall: () => { if (!installDialogBusyRef.current && !installingNamesRef.current.has(String(currentDetailPlugin.name || "").toLowerCase())) setInstallFor(currentDetailPlugin); },
|
|
9692
9712
|
onRemove: () => removePlugin(currentDetailPlugin.name),
|
|
9693
9713
|
onManage: () => openManage(state.plugins.find((r) => r.name === currentDetailPlugin.name), { type: "detail", sourceId: activeSourceId, plugin: currentDetailPlugin }),
|
|
9694
9714
|
onTogglePlugin: async (enabled) => {
|
|
@@ -9798,6 +9818,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9798
9818
|
iconPlugin: resolveMarketplaceIcon(p),
|
|
9799
9819
|
eagerIcon: index < 12,
|
|
9800
9820
|
installed,
|
|
9821
|
+
installing: isPluginInstalling(p.name),
|
|
9801
9822
|
isDark,
|
|
9802
9823
|
onMouseEnter: (e) => handleCardMouseEnter(p, e.currentTarget, { x: e.clientX, y: e.clientY, buttons: e.buttons }),
|
|
9803
9824
|
onMouseLeave: () => handleCardMouseLeave(p),
|
|
@@ -9809,7 +9830,9 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9809
9830
|
onInstall: (e) => {
|
|
9810
9831
|
e.stopPropagation();
|
|
9811
9832
|
closePluginHover();
|
|
9812
|
-
|
|
9833
|
+
if (!installDialogBusyRef.current && !installingNamesRef.current.has(String(p.name || "").toLowerCase())) {
|
|
9834
|
+
setInstallFor(p);
|
|
9835
|
+
}
|
|
9813
9836
|
},
|
|
9814
9837
|
});
|
|
9815
9838
|
}),
|
|
@@ -9868,7 +9891,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9868
9891
|
installFor && h(InstallDialog, {
|
|
9869
9892
|
plugin: installFor,
|
|
9870
9893
|
isDark,
|
|
9871
|
-
|
|
9894
|
+
onBusyChange: (v) => { installDialogBusyRef.current = !!v; },
|
|
9895
|
+
onCancel: () => { if (!installDialogBusyRef.current) setInstallFor(null); },
|
|
9872
9896
|
onConfirm: doInstall,
|
|
9873
9897
|
}),
|
|
9874
9898
|
|
|
@@ -9935,7 +9959,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
9935
9959
|
showToast,
|
|
9936
9960
|
}),
|
|
9937
9961
|
|
|
9938
|
-
confirmRemoveSource && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => setConfirmRemoveSource(null)) },
|
|
9962
|
+
confirmRemoveSource && h("div", { className: "cpm-dialog", ...backdropDismissProps(() => { if (!busy) setConfirmRemoveSource(null); }) },
|
|
9939
9963
|
h(ConfirmDialogBox, {
|
|
9940
9964
|
titleId: "cpm-confirm-remove-source-title",
|
|
9941
9965
|
title: `删除插件源「${confirmRemoveSource.name}」`,
|
|
@@ -10089,10 +10113,34 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10089
10113
|
}
|
|
10090
10114
|
|
|
10091
10115
|
// ────────────────────────────── Modern Install Dialog ──────────────────────────────
|
|
10092
|
-
function InstallDialog({ plugin, isDark, onCancel, onConfirm }) {
|
|
10093
|
-
const [busy,
|
|
10116
|
+
function InstallDialog({ plugin, isDark, onCancel, onConfirm, onBusyChange }) {
|
|
10117
|
+
const [busy, setBusyState] = useState(false);
|
|
10118
|
+
const busyRef = useRef(false);
|
|
10119
|
+
const unmountedRef = useRef(false);
|
|
10120
|
+
useEffect(() => () => { unmountedRef.current = true; }, []);
|
|
10121
|
+
const setBusy = (next) => {
|
|
10122
|
+
const val = !!next;
|
|
10123
|
+
busyRef.current = val;
|
|
10124
|
+
if (!unmountedRef.current) {
|
|
10125
|
+
setBusyState(val);
|
|
10126
|
+
if (typeof onBusyChange === "function") onBusyChange(val);
|
|
10127
|
+
}
|
|
10128
|
+
};
|
|
10129
|
+
const handleCancel = () => {
|
|
10130
|
+
if (busyRef.current) return;
|
|
10131
|
+
onCancel();
|
|
10132
|
+
};
|
|
10133
|
+
const handleConfirm = async () => {
|
|
10134
|
+
if (busyRef.current) return;
|
|
10135
|
+
setBusy(true);
|
|
10136
|
+
try {
|
|
10137
|
+
await onConfirm();
|
|
10138
|
+
} finally {
|
|
10139
|
+
setBusy(false);
|
|
10140
|
+
}
|
|
10141
|
+
};
|
|
10094
10142
|
const titleId = "cpm-install-dialog-title";
|
|
10095
|
-
return h("div", { className: "cpm-dialog", ...backdropDismissProps(
|
|
10143
|
+
return h("div", { className: "cpm-dialog", ...backdropDismissProps(handleCancel) },
|
|
10096
10144
|
h("div", {
|
|
10097
10145
|
className: "cpm-dialog-box cpm-install-dialog",
|
|
10098
10146
|
role: "dialog",
|
|
@@ -10109,11 +10157,11 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
10109
10157
|
),
|
|
10110
10158
|
plugin.description && h("div", { className: "cpm-install-desc" }, plugin.description),
|
|
10111
10159
|
h("div", { className: "cpm-dialog-actions", style: { marginTop: 18 } },
|
|
10112
|
-
h("button", { className: "cpm-btn cpm-btn-secondary", onClick:
|
|
10160
|
+
h("button", { className: "cpm-btn cpm-btn-secondary", onClick: handleCancel, disabled: busy }, "取消"),
|
|
10113
10161
|
h("button", {
|
|
10114
10162
|
className: "cpm-btn cpm-btn-primary",
|
|
10115
10163
|
disabled: busy,
|
|
10116
|
-
onClick:
|
|
10164
|
+
onClick: handleConfirm,
|
|
10117
10165
|
}, busy ? "正在安装…" : "确认安装"),
|
|
10118
10166
|
),
|
|
10119
10167
|
),
|
|
@@ -11797,7 +11845,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11797
11845
|
}
|
|
11798
11846
|
|
|
11799
11847
|
// ────────────────────────────── Detail View ──────────────────────────────
|
|
11800
|
-
function DetailView({ plugin, pluginRecord, isDark, onBack, onInstall, onRemove, onManage, onTogglePlugin, showToast, containerRef, scrollState }) {
|
|
11848
|
+
function DetailView({ plugin, pluginRecord, isDark, installing = false, onBack, onInstall, onRemove, onManage, onTogglePlugin, showToast, containerRef, scrollState }) {
|
|
11801
11849
|
const [busy, setBusy] = useState(false);
|
|
11802
11850
|
const [confirmRemove, setConfirmRemove] = useState(false);
|
|
11803
11851
|
const [toggling, setToggling] = useState(false);
|
|
@@ -11911,9 +11959,9 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
11911
11959
|
!installed &&
|
|
11912
11960
|
h("button", {
|
|
11913
11961
|
className: "cpm-btn cpm-btn-primary",
|
|
11914
|
-
disabled: busy,
|
|
11915
|
-
onClick: async () => { setBusy(true); try { await onInstall(); } finally { setBusy(false); } },
|
|
11916
|
-
}, busy ? "安装中…" : "Install"),
|
|
11962
|
+
disabled: busy || installing,
|
|
11963
|
+
onClick: async () => { if (busy || installing) return; setBusy(true); try { await onInstall(); } finally { setBusy(false); } },
|
|
11964
|
+
}, (busy || installing) ? "安装中…" : "Install"),
|
|
11917
11965
|
installed && [
|
|
11918
11966
|
h("button", {
|
|
11919
11967
|
key: "r",
|
|
@@ -13997,6 +14045,8 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
13997
14045
|
const AT_PLUGIN_RAW_TOKEN_RE = /@([^\s\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul},。;:、!?()【】《》“”‘’」』]+)/uy;
|
|
13998
14046
|
const AT_PLUGIN_LEFT_ALLOWED_RE = /[\s(\[{"'“‘(【《,。;:、!?\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u;
|
|
13999
14047
|
const AT_PLUGIN_TRAILING_PUNCT_RE = /[.,;:!?,。;:!?)"'\]”’)】》]+$/u;
|
|
14048
|
+
const EASY_REWRITE_BUBBLE = '[data-dsh-easyrewrite="user"] .dsh-easyrewrite-bubble';
|
|
14049
|
+
const AT_PLUGIN_CLIPBOARD = "data-uph-plugin-clipboard";
|
|
14000
14050
|
const AT_PLUGINS_CSS = `
|
|
14001
14051
|
[role="listbox"] button[id^="dsh-slash-option-plugins-"] {
|
|
14002
14052
|
gap: 8px;
|
|
@@ -14060,8 +14110,7 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
14060
14110
|
object-fit: contain !important;
|
|
14061
14111
|
display: block;
|
|
14062
14112
|
}
|
|
14063
|
-
[data-composer-chip="plugins"]
|
|
14064
|
-
.cpm-at-plugin-chip {
|
|
14113
|
+
[data-composer-chip="plugins"] {
|
|
14065
14114
|
display: inline-flex;
|
|
14066
14115
|
align-items: baseline;
|
|
14067
14116
|
gap: 4px;
|
|
@@ -14077,6 +14126,27 @@ window.__ModuleLoader__.load({ id: "universal-plugin-hub", factory: (require) =>
|
|
|
14077
14126
|
cursor: default;
|
|
14078
14127
|
transition: background-color 120ms ease;
|
|
14079
14128
|
}
|
|
14129
|
+
.cpm-at-plugin-chip {
|
|
14130
|
+
display: inline;
|
|
14131
|
+
margin: 0 2px;
|
|
14132
|
+
border-radius: var(--dsw-radius-sm, 4px);
|
|
14133
|
+
color: var(--dsw-alias-label-primary, #18181b);
|
|
14134
|
+
font-weight: 600;
|
|
14135
|
+
overflow-wrap: anywhere;
|
|
14136
|
+
user-select: all;
|
|
14137
|
+
}
|
|
14138
|
+
.cpm-at-plugin-chip > .cpm-at-plugin-chip-icon-wrap {
|
|
14139
|
+
display: inline-block;
|
|
14140
|
+
margin-inline-end: 4px;
|
|
14141
|
+
vertical-align: -0.125em;
|
|
14142
|
+
top: auto;
|
|
14143
|
+
pointer-events: none;
|
|
14144
|
+
}
|
|
14145
|
+
.cpm-at-plugin-chip .cpm-at-plugin-chip-icon,
|
|
14146
|
+
.cpm-at-plugin-chip .cpm-card-icon {
|
|
14147
|
+
display: inline-block;
|
|
14148
|
+
vertical-align: top;
|
|
14149
|
+
}
|
|
14080
14150
|
body[data-ds-dark-theme] [data-composer-chip="plugins"],
|
|
14081
14151
|
body[data-ds-dark-theme] .cpm-at-plugin-chip {
|
|
14082
14152
|
color: var(--dsw-alias-label-primary, #f4f4f5);
|
|
@@ -14133,11 +14203,6 @@ body[data-ds-dark-theme] .cpm-at-plugin-chip {
|
|
|
14133
14203
|
position: relative;
|
|
14134
14204
|
top: 0.05em;
|
|
14135
14205
|
}
|
|
14136
|
-
.cpm-at-plugin-chip-label {
|
|
14137
|
-
overflow: hidden;
|
|
14138
|
-
text-overflow: ellipsis;
|
|
14139
|
-
white-space: nowrap;
|
|
14140
|
-
}
|
|
14141
14206
|
.cpm-at-plugin-popover {
|
|
14142
14207
|
position: fixed;
|
|
14143
14208
|
inset: auto;
|
|
@@ -14348,6 +14413,106 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
14348
14413
|
return { source: "plugins", ref: mention, label, clipboardText: mention };
|
|
14349
14414
|
}
|
|
14350
14415
|
|
|
14416
|
+
function copyAtPluginReferences(event) {
|
|
14417
|
+
if (event.defaultPrevented || !event.clipboardData || event.target?.isContentEditable ||
|
|
14418
|
+
event.target?.closest?.("input, textarea")) return;
|
|
14419
|
+
const selection = document.getSelection?.();
|
|
14420
|
+
if (selection?.rangeCount !== 1 || selection.isCollapsed) return;
|
|
14421
|
+
const range = selection.getRangeAt(0);
|
|
14422
|
+
const common = range.commonAncestorContainer;
|
|
14423
|
+
const element = common.nodeType === 1 ? common : common.parentElement;
|
|
14424
|
+
const bubble = element?.closest('[data-message-bubble], ' + EASY_REWRITE_BUBBLE);
|
|
14425
|
+
const chipSelector = '[' + AT_PLUGIN_CLIPBOARD + ']';
|
|
14426
|
+
if (!bubble?.querySelector(chipSelector)) return;
|
|
14427
|
+
|
|
14428
|
+
const fragment = range.cloneContents();
|
|
14429
|
+
// User text is inline. Leave structured content such as a host JSON block
|
|
14430
|
+
// to the browser so its formatting and rich clipboard formats are kept.
|
|
14431
|
+
if (fragment.querySelector("div, p, pre, table, ul, ol, blockquote")) return;
|
|
14432
|
+
const enclosingChip = element.closest(chipSelector);
|
|
14433
|
+
let text;
|
|
14434
|
+
if (enclosingChip && fragment.textContent === enclosingChip.textContent) {
|
|
14435
|
+
text = enclosingChip.getAttribute(AT_PLUGIN_CLIPBOARD);
|
|
14436
|
+
} else {
|
|
14437
|
+
let replaced = false;
|
|
14438
|
+
for (const chip of fragment.querySelectorAll(chipSelector)) {
|
|
14439
|
+
// A clipped label is ordinary selected text. A whole chip carries the original reference.
|
|
14440
|
+
if (chip.querySelector(".cpm-at-plugin-chip-label")?.textContent !== chip.getAttribute("data-uph-plugin-label")) continue;
|
|
14441
|
+
chip.replaceWith(chip.getAttribute(AT_PLUGIN_CLIPBOARD));
|
|
14442
|
+
replaced = true;
|
|
14443
|
+
}
|
|
14444
|
+
if (!replaced) return;
|
|
14445
|
+
for (const br of fragment.querySelectorAll("br")) br.replaceWith("\n");
|
|
14446
|
+
text = fragment.textContent;
|
|
14447
|
+
}
|
|
14448
|
+
event.clipboardData.setData("text/plain", text);
|
|
14449
|
+
event.preventDefault();
|
|
14450
|
+
}
|
|
14451
|
+
|
|
14452
|
+
function restoreEasyRewriteBubble({ bubble, mount, original }) {
|
|
14453
|
+
if (mount.parentElement === bubble) mount.replaceWith(original);
|
|
14454
|
+
}
|
|
14455
|
+
|
|
14456
|
+
function watchEasyRewriteBubbles(publish) {
|
|
14457
|
+
const entries = new Map();
|
|
14458
|
+
let nextId = 0;
|
|
14459
|
+
|
|
14460
|
+
function collect(root, bubbles) {
|
|
14461
|
+
if (root.nodeType !== 1) return;
|
|
14462
|
+
if (root.matches(EASY_REWRITE_BUBBLE)) bubbles.add(root);
|
|
14463
|
+
for (const bubble of root.querySelectorAll(EASY_REWRITE_BUBBLE)) bubbles.add(bubble);
|
|
14464
|
+
}
|
|
14465
|
+
|
|
14466
|
+
function update(bubbles) {
|
|
14467
|
+
let changed = false;
|
|
14468
|
+
for (const bubble of bubbles) {
|
|
14469
|
+
const previous = entries.get(bubble);
|
|
14470
|
+
const original = bubble.firstChild;
|
|
14471
|
+
if (bubble.isConnected && original && !original.nextSibling &&
|
|
14472
|
+
(previous?.mount === original || (previous?.original === original && previous.text === original.data))) continue;
|
|
14473
|
+
if (entries.delete(bubble)) changed = true;
|
|
14474
|
+
// EasyRewrite renders the resting bubble as one text node. Leave its editor,
|
|
14475
|
+
// attachments, buttons and any future renderer using structured children alone.
|
|
14476
|
+
if (!bubble.isConnected || original?.nodeType !== 3 || original.nextSibling) continue;
|
|
14477
|
+
const text = original.data;
|
|
14478
|
+
const first = matchAtPluginMention(text, 0, null, true);
|
|
14479
|
+
if (!first) continue;
|
|
14480
|
+
const mount = document.createElement("span");
|
|
14481
|
+
mount.style.display = "contents";
|
|
14482
|
+
entries.set(bubble, { id: nextId++, bubble, original, text, first, mount });
|
|
14483
|
+
changed = true;
|
|
14484
|
+
}
|
|
14485
|
+
if (changed) publish([...entries.values()]);
|
|
14486
|
+
}
|
|
14487
|
+
|
|
14488
|
+
const observer = new MutationObserver((mutations) => {
|
|
14489
|
+
const bubbles = new Set();
|
|
14490
|
+
let removed = false;
|
|
14491
|
+
for (const mutation of mutations) {
|
|
14492
|
+
const target = mutation.type === "characterData" ? mutation.target.parentElement : mutation.target;
|
|
14493
|
+
if (target?.matches?.(EASY_REWRITE_BUBBLE)) bubbles.add(target);
|
|
14494
|
+
for (const node of mutation.addedNodes) collect(node, bubbles);
|
|
14495
|
+
if (!removed && entries.size > 0 && mutation.removedNodes.length > 0) {
|
|
14496
|
+
removed = Array.from(mutation.removedNodes).some((node) => node.nodeType === 1);
|
|
14497
|
+
}
|
|
14498
|
+
}
|
|
14499
|
+
if (removed) {
|
|
14500
|
+
for (const bubble of entries.keys()) {
|
|
14501
|
+
if (!bubble.isConnected) bubbles.add(bubble);
|
|
14502
|
+
}
|
|
14503
|
+
}
|
|
14504
|
+
update(bubbles);
|
|
14505
|
+
});
|
|
14506
|
+
observer.observe(document.body, { subtree: true, childList: true, characterData: true });
|
|
14507
|
+
update(document.querySelectorAll(EASY_REWRITE_BUBBLE));
|
|
14508
|
+
return () => {
|
|
14509
|
+
observer.disconnect();
|
|
14510
|
+
// Restore text before another client instance scans the bubbles.
|
|
14511
|
+
for (const entry of entries.values()) restoreEasyRewriteBubble(entry);
|
|
14512
|
+
entries.clear();
|
|
14513
|
+
};
|
|
14514
|
+
}
|
|
14515
|
+
|
|
14351
14516
|
function pasteAtPluginReferences(event, byLowerName) {
|
|
14352
14517
|
const clipboard = event.clipboardData;
|
|
14353
14518
|
if (event.defaultPrevented || !clipboard || clipboard.files?.length ||
|
|
@@ -14782,12 +14947,13 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
14782
14947
|
const ReactDOM = (() => { try { return require("react-dom") || null; } catch { return null; } })();
|
|
14783
14948
|
const ReactDOMClient = (() => { try { return require("react-dom/client") || null; } catch { return null; } })();
|
|
14784
14949
|
|
|
14785
|
-
function PluginMentionChip({ node }) {
|
|
14950
|
+
function PluginMentionChip({ node, raw }) {
|
|
14786
14951
|
const [revision, setRevision] = useState(0);
|
|
14787
14952
|
useEffect(() => {
|
|
14788
14953
|
const bump = () => setRevision((r) => r + 1);
|
|
14789
14954
|
const offStore = store.subscribe(bump);
|
|
14790
14955
|
const offTheme = store.subscribeTheme(bump);
|
|
14956
|
+
store.warm();
|
|
14791
14957
|
return () => {
|
|
14792
14958
|
offStore();
|
|
14793
14959
|
offTheme();
|
|
@@ -14801,6 +14967,7 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
14801
14967
|
"data-uph-plugin-chip": "true",
|
|
14802
14968
|
"data-uph-plugin-name": live?.name || node?.data?.name || "",
|
|
14803
14969
|
"data-uph-plugin-label": label,
|
|
14970
|
+
[AT_PLUGIN_CLIPBOARD]: raw,
|
|
14804
14971
|
},
|
|
14805
14972
|
live
|
|
14806
14973
|
? h("span", { className: "cpm-at-plugin-chip-icon-wrap", "aria-hidden": "true" },
|
|
@@ -14813,6 +14980,27 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
14813
14980
|
);
|
|
14814
14981
|
}
|
|
14815
14982
|
|
|
14983
|
+
function EasyRewritePluginText({ entry }) {
|
|
14984
|
+
const { bubble, original, text, first, mount } = entry;
|
|
14985
|
+
useSafeLayoutEffect(() => {
|
|
14986
|
+
// Stage the portal off-DOM, then swap only the same plain text once
|
|
14987
|
+
// the chips have rendered. EasyRewrite still owns the bubble and its events.
|
|
14988
|
+
if (!bubble.isConnected || bubble.firstChild !== original || original.nextSibling || original.data !== text) return;
|
|
14989
|
+
original.replaceWith(mount);
|
|
14990
|
+
return () => restoreEasyRewriteBubble(entry);
|
|
14991
|
+
}, [entry]);
|
|
14992
|
+
const children = [];
|
|
14993
|
+
let cursor = 0;
|
|
14994
|
+
for (let node = first; node; node = matchAtPluginMention(text, cursor, null, true)) {
|
|
14995
|
+
children.push(text.slice(cursor, node.start), h(PluginMentionChip, {
|
|
14996
|
+
key: node.start, node, raw: text.slice(node.start, node.end),
|
|
14997
|
+
}));
|
|
14998
|
+
cursor = node.end;
|
|
14999
|
+
}
|
|
15000
|
+
children.push(text.slice(cursor));
|
|
15001
|
+
return children;
|
|
15002
|
+
}
|
|
15003
|
+
|
|
14816
15004
|
function PluginChipHoverPopover({ hovered, isDark, session }) {
|
|
14817
15005
|
const popRef = useRef(null);
|
|
14818
15006
|
const [position, setPosition] = useState(null);
|
|
@@ -14905,7 +15093,7 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
14905
15093
|
let knownComposerEl = null;
|
|
14906
15094
|
let syncQueued = false;
|
|
14907
15095
|
let blockDisposed = false;
|
|
14908
|
-
let activeOverlayState = { chips: [], hovered: null, isDark: store.isDark() };
|
|
15096
|
+
let activeOverlayState = { chips: [], rewriteBubbles: [], hovered: null, isDark: store.isDark() };
|
|
14909
15097
|
let setOverlayState = null;
|
|
14910
15098
|
let hoverSession = null;
|
|
14911
15099
|
|
|
@@ -15190,11 +15378,13 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
15190
15378
|
|
|
15191
15379
|
if (typeof document.addEventListener === "function") {
|
|
15192
15380
|
const onPaste = (event) => pasteAtPluginReferences(event, store.getByLowerName());
|
|
15381
|
+
document.addEventListener("copy", copyAtPluginReferences);
|
|
15193
15382
|
document.addEventListener("paste", onPaste, true);
|
|
15194
15383
|
document.addEventListener("pointerover", onPointerOver, true);
|
|
15195
15384
|
document.addEventListener("focusin", onFocusIn, true);
|
|
15196
15385
|
document.addEventListener("keydown", onComposerKeyDown, true);
|
|
15197
15386
|
disposers.push(() => {
|
|
15387
|
+
document.removeEventListener("copy", copyAtPluginReferences);
|
|
15198
15388
|
document.removeEventListener("paste", onPaste, true);
|
|
15199
15389
|
document.removeEventListener("pointerover", onPointerOver, true);
|
|
15200
15390
|
document.removeEventListener("focusin", onFocusIn, true);
|
|
@@ -15246,6 +15436,9 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
15246
15436
|
setLocalState(activeOverlayState);
|
|
15247
15437
|
return () => { if (setOverlayState === setLocalState) setOverlayState = null; };
|
|
15248
15438
|
}, []);
|
|
15439
|
+
const rewritePortals = useMemo(() => overlayState.rewriteBubbles.map((entry) => ReactDOM.createPortal(
|
|
15440
|
+
h(EasyRewritePluginText, { entry }), entry.mount, "easyrewrite-" + entry.id,
|
|
15441
|
+
)), [overlayState.rewriteBubbles]);
|
|
15249
15442
|
return h(React.Fragment, null,
|
|
15250
15443
|
overlayState.chips.map((entry) => (
|
|
15251
15444
|
entry.iconSlot?.isConnected
|
|
@@ -15258,6 +15451,7 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
15258
15451
|
)
|
|
15259
15452
|
: null
|
|
15260
15453
|
)),
|
|
15454
|
+
rewritePortals,
|
|
15261
15455
|
h(PluginChipHoverPopover, {
|
|
15262
15456
|
hovered: overlayState.hovered,
|
|
15263
15457
|
isDark: overlayState.isDark,
|
|
@@ -15270,11 +15464,17 @@ body[data-ds-dark-theme] .cpm-at-plugin-popover,
|
|
|
15270
15464
|
overlayRoot.render(h(AtPluginsOverlay));
|
|
15271
15465
|
disposers.push(() => {
|
|
15272
15466
|
setOverlayState = null;
|
|
15273
|
-
activeOverlayState = { chips: [], hovered: null, isDark: false };
|
|
15467
|
+
activeOverlayState = { chips: [], rewriteBubbles: [], hovered: null, isDark: false };
|
|
15274
15468
|
cleanupStaleAtPluginDom();
|
|
15275
15469
|
try { overlayRoot.unmount(); } catch {}
|
|
15276
15470
|
try { overlayHost.remove(); } catch {}
|
|
15277
15471
|
});
|
|
15472
|
+
if (typeof MutationObserver === "function") {
|
|
15473
|
+
disposers.push(watchEasyRewriteBubbles((rewriteBubbles) => {
|
|
15474
|
+
activeOverlayState = { ...activeOverlayState, rewriteBubbles };
|
|
15475
|
+
setOverlayState?.(activeOverlayState);
|
|
15476
|
+
}));
|
|
15477
|
+
}
|
|
15278
15478
|
} else {
|
|
15279
15479
|
disposers.push(() => cleanupStaleAtPluginDom());
|
|
15280
15480
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
"title": "Universal Plugin Hub",
|
|
4
4
|
"displayName": "Universal Plugin Hub",
|
|
5
5
|
"description": "在 DSH 中使用 Claude Code、Codex 等软件生态的插件,一站式管理插件、Skills 与 MCP。支持添加 Git 插件源和 marketplace、上传插件和 Skills、添加 MCP 服务器,自动扫描并开关本地 Skills,接入插件提供的子代理、MCP、Hooks 与 LSP。",
|
|
6
|
-
"version": "1.5.
|
|
6
|
+
"version": "1.5.5",
|
|
7
|
+
"icon": "./assets/icon.svg",
|
|
7
8
|
"engines": {
|
|
8
9
|
"dsh": ">=0.1.5-rc.1"
|
|
9
10
|
},
|
|
@@ -64,6 +65,7 @@
|
|
|
64
65
|
},
|
|
65
66
|
"./client": "./client/client.js",
|
|
66
67
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
68
|
+
"./icon": "./assets/icon.svg",
|
|
67
69
|
"./package.json": "./package.json"
|
|
68
70
|
},
|
|
69
71
|
"files": [
|
|
@@ -72,6 +74,7 @@
|
|
|
72
74
|
"scripts/postinstall.js",
|
|
73
75
|
"cordis.patch.yml",
|
|
74
76
|
"screenshots.json",
|
|
77
|
+
"assets/icon.svg",
|
|
75
78
|
"assets/Plugins-official.png",
|
|
76
79
|
"assets/Skills.png",
|
|
77
80
|
"assets/MCP.png",
|
package/src/install.js
CHANGED
|
@@ -21,8 +21,8 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/
|
|
|
21
21
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
22
22
|
import { ErrorCode } from '@modelcontextprotocol/sdk/types.js'
|
|
23
23
|
import { installedDir, pluginDataDir, compiledHooksPath, readState, writeState, slugify, dshHome, dshSkillsDir, safeRmDir, removeManagedDir, sourceCacheDir, trashRoot, isSameOrInsidePath } from './store.js'
|
|
24
|
-
import { materializePlugin, pullSource } from './market.js'
|
|
25
|
-
import { copyDir, listSkills, listAgents, listPrompts, listConnectors, listHooks, listLspServers, readPluginManifest, readPluginShortDescription, formatDisplayName, invalidateParserCaches, invalidateMarketplaceCache, readMarketplace, connectorTransport, isRemoteTransportName, PLUGIN_RUNTIME_ENV_KEYS, hasUnresolvedVarPlaceholder, isDotRelativePath, expandPluginVars, resolvePluginCommand, resolvePluginCwd, resolvePluginSpecPath, resolveConnectorDisplay, resolvePluginCommandEntries, compileResolvedHooks, mergeManifestWithRow, MARKETPLACE_COMPONENT_KEYS } from './parser.js'
|
|
24
|
+
import { materializePlugin, pullSource, sourceRepositoryDir, normalizeRemotePluginSource, remoteCheckoutDir, pluginPath } from './market.js'
|
|
25
|
+
import { copyDir, copyDirAsync, normalizeVersion, listSkills, listAgents, listPrompts, listConnectors, listHooks, listLspServers, readPluginManifest, readPluginShortDescription, formatDisplayName, invalidateParserCaches, invalidateMarketplaceCache, readMarketplace, connectorTransport, isRemoteTransportName, PLUGIN_RUNTIME_ENV_KEYS, hasUnresolvedVarPlaceholder, isDotRelativePath, expandPluginVars, resolvePluginCommand, resolvePluginCwd, resolvePluginSpecPath, resolveConnectorDisplay, resolvePluginCommandEntries, compileResolvedHooks, mergeManifestWithRow, MARKETPLACE_COMPONENT_KEYS } from './parser.js'
|
|
26
26
|
import { parseAgentDefinition, compileSubagentsHubSkill, cleanupLegacyPresets } from './agents-map.js'
|
|
27
27
|
import { isUploadedSkillTarget } from './skill-uploads.js'
|
|
28
28
|
import { buildPluginIcons } from './icons.js'
|
|
@@ -2277,7 +2277,7 @@ export async function syncPluginSkillsToDsh(pluginName, shouldSync = () => true,
|
|
|
2277
2277
|
}
|
|
2278
2278
|
|
|
2279
2279
|
const settled = await Promise.allSettled(candidates.map(async (item) => {
|
|
2280
|
-
if (await
|
|
2280
|
+
if (await replaceManagedDirAsync(item.srcSkillDir, item.destSkillDir, keepExisting, false, { allowTrash: true, deferCleanup: true })) {
|
|
2281
2281
|
synced.push(item.name)
|
|
2282
2282
|
}
|
|
2283
2283
|
}))
|
|
@@ -2311,13 +2311,18 @@ const PLUGIN_LOCKS = new Map()
|
|
|
2311
2311
|
const SOURCE_LOCKS = new Map()
|
|
2312
2312
|
const PLUGIN_EPOCHS = new Map()
|
|
2313
2313
|
|
|
2314
|
+
function pluginLockKey(pluginName) {
|
|
2315
|
+
return pluginName == null ? '' : String(pluginName).toLowerCase()
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2314
2318
|
function currentPluginEpoch(pluginName) {
|
|
2315
|
-
return PLUGIN_EPOCHS.get(pluginName) || 0
|
|
2319
|
+
return PLUGIN_EPOCHS.get(pluginLockKey(pluginName)) || 0
|
|
2316
2320
|
}
|
|
2317
2321
|
|
|
2318
2322
|
function bumpPluginEpoch(pluginName) {
|
|
2319
|
-
const
|
|
2320
|
-
PLUGIN_EPOCHS.
|
|
2323
|
+
const key = pluginLockKey(pluginName)
|
|
2324
|
+
const next = (PLUGIN_EPOCHS.get(key) || 0) + 1
|
|
2325
|
+
PLUGIN_EPOCHS.set(key, next)
|
|
2321
2326
|
return next
|
|
2322
2327
|
}
|
|
2323
2328
|
|
|
@@ -2341,7 +2346,7 @@ async function acquireKeyedLock(locks, key, fn) {
|
|
|
2341
2346
|
* when the lock is idle so startup repair reaches its first fs attempt synchronously.
|
|
2342
2347
|
*/
|
|
2343
2348
|
export function withPluginLock(pluginName, fn) {
|
|
2344
|
-
return acquireKeyedLock(PLUGIN_LOCKS, pluginName, fn)
|
|
2349
|
+
return acquireKeyedLock(PLUGIN_LOCKS, pluginLockKey(pluginName), fn)
|
|
2345
2350
|
}
|
|
2346
2351
|
|
|
2347
2352
|
/**
|
|
@@ -2355,7 +2360,7 @@ export function withSourceLock(sourceId, fn) {
|
|
|
2355
2360
|
async function retryManagedDirOperation(operation, destination) {
|
|
2356
2361
|
for (let attempt = 0; ; attempt++) {
|
|
2357
2362
|
try {
|
|
2358
|
-
return operation()
|
|
2363
|
+
return await operation()
|
|
2359
2364
|
} catch (err) {
|
|
2360
2365
|
// Windows can keep a deleted directory name reserved until the last
|
|
2361
2366
|
// handle closes. Keep retries scoped to directory cleanup and creation.
|
|
@@ -2382,6 +2387,16 @@ function replaceManagedDir(from, to, keepExisting, repairOnly = false, { allowTr
|
|
|
2382
2387
|
}, to)
|
|
2383
2388
|
}
|
|
2384
2389
|
|
|
2390
|
+
function replaceManagedDirAsync(from, to, keepExisting, repairOnly = false, { allowTrash = false, deferCleanup = false, excludeNames = null } = {}) {
|
|
2391
|
+
return retryManagedDirOperation(async () => {
|
|
2392
|
+
if (keepExisting?.(to)) return false
|
|
2393
|
+
if (repairOnly && hasMatchingSkillCopy(from, to)) return true
|
|
2394
|
+
removeManagedDir(to, { allowTrash, deferCleanup })
|
|
2395
|
+
await copyDirAsync(from, to, { excludeNames })
|
|
2396
|
+
return true
|
|
2397
|
+
}, to)
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2385
2400
|
/**
|
|
2386
2401
|
* Remove a plugin's skills from $DSH_HOME/skills upon uninstall or disabling.
|
|
2387
2402
|
*/
|
|
@@ -2405,7 +2420,7 @@ function skillOwnedByOtherEnabledPlugin(pluginName, skillName, plugins = readSta
|
|
|
2405
2420
|
return false
|
|
2406
2421
|
}
|
|
2407
2422
|
|
|
2408
|
-
export async function removePluginSkillsFromDsh(pluginName, { allowQuarantine = true, preserveOtherEnabled = true } = {}) {
|
|
2423
|
+
export async function removePluginSkillsFromDsh(pluginName, { allowQuarantine = true, preserveOtherEnabled = true, deferCleanup = false } = {}) {
|
|
2409
2424
|
const target = installedDir(pluginName)
|
|
2410
2425
|
const pluginSkillsDir = join(target, 'skills')
|
|
2411
2426
|
const dshSkills = dshSkillsDir()
|
|
@@ -2435,7 +2450,7 @@ export async function removePluginSkillsFromDsh(pluginName, { allowQuarantine =
|
|
|
2435
2450
|
const settled = await Promise.allSettled(targets.map(async ({ name, dest }) => {
|
|
2436
2451
|
const didRemove = await retryManagedDirOperation(() => {
|
|
2437
2452
|
if (isUploadedSkillTarget(dest)) return false
|
|
2438
|
-
removeManagedDir(dest, { allowTrash: allowQuarantine })
|
|
2453
|
+
removeManagedDir(dest, { allowTrash: allowQuarantine, deferCleanup })
|
|
2439
2454
|
return true
|
|
2440
2455
|
}, dest)
|
|
2441
2456
|
if (didRemove) removed.push(name)
|
|
@@ -2475,17 +2490,24 @@ export async function syncAllInstalledSkillsToDsh() {
|
|
|
2475
2490
|
* Returns a result summary for the UI.
|
|
2476
2491
|
*/
|
|
2477
2492
|
const marketplaceInstalls = new Set()
|
|
2493
|
+
const activePluginUpdates = new Set()
|
|
2478
2494
|
|
|
2479
2495
|
export async function installPlugin(options) {
|
|
2480
2496
|
const { pluginName } = options
|
|
2481
|
-
|
|
2482
|
-
marketplaceInstalls.
|
|
2497
|
+
const lockKey = pluginLockKey(pluginName)
|
|
2498
|
+
if (marketplaceInstalls.has(lockKey)) {
|
|
2499
|
+
throw Object.assign(new Error(`插件 ${pluginName} 正在安装`), { status: 409 })
|
|
2500
|
+
}
|
|
2501
|
+
if (activePluginUpdates.has(lockKey)) {
|
|
2502
|
+
throw Object.assign(new Error(`插件 ${pluginName} 正在更新`), { status: 409 })
|
|
2503
|
+
}
|
|
2504
|
+
marketplaceInstalls.add(lockKey)
|
|
2483
2505
|
bumpPluginEpoch(pluginName)
|
|
2484
2506
|
cancelActivePluginProbes(pluginName)
|
|
2485
2507
|
try {
|
|
2486
2508
|
return await withPluginLock(pluginName, () => installMarketplacePluginUnlocked(options))
|
|
2487
2509
|
} finally {
|
|
2488
|
-
marketplaceInstalls.delete(
|
|
2510
|
+
marketplaceInstalls.delete(lockKey)
|
|
2489
2511
|
}
|
|
2490
2512
|
}
|
|
2491
2513
|
|
|
@@ -2535,7 +2557,7 @@ async function rollbackFreshInstall(pluginName, target) {
|
|
|
2535
2557
|
await removeManagedDirAsync(target, { allowTrash: true }).catch(() => {})
|
|
2536
2558
|
}
|
|
2537
2559
|
|
|
2538
|
-
async function installMarketplacePluginFromSourceLocked({ sourceId, pluginName, refresh = false, initialEnabled = true }) {
|
|
2560
|
+
async function installMarketplacePluginFromSourceLocked({ sourceId, pluginName, refresh = false, sourcePulled = false, initialEnabled = true }) {
|
|
2539
2561
|
const state = readState()
|
|
2540
2562
|
const source = state.sources.find((s) => s.id === sourceId)
|
|
2541
2563
|
if (!source) throw new Error(`unknown source: ${sourceId}`)
|
|
@@ -2548,7 +2570,38 @@ async function installMarketplacePluginFromSourceLocked({ sourceId, pluginName,
|
|
|
2548
2570
|
const row = await findMarketRow(sourceId, pluginName)
|
|
2549
2571
|
if (!row) throw new Error(`plugin not found in marketplace: ${pluginName}`)
|
|
2550
2572
|
|
|
2551
|
-
|
|
2573
|
+
let effectiveRefresh = refresh
|
|
2574
|
+
let allowStaleFallback = false
|
|
2575
|
+
if (!effectiveRefresh && row.source && typeof row.source === 'object' && row.version) {
|
|
2576
|
+
const normalizedSource = normalizeRemotePluginSource(row.source)
|
|
2577
|
+
if (
|
|
2578
|
+
normalizedSource &&
|
|
2579
|
+
['url', 'git-subdir', 'github'].includes(normalizedSource.source) &&
|
|
2580
|
+
typeof normalizedSource.url === 'string' &&
|
|
2581
|
+
/^https?:\/\//.test(normalizedSource.url) &&
|
|
2582
|
+
!normalizedSource.sha &&
|
|
2583
|
+
!sourceRepositoryDir(sourceCacheDir(sourceId), normalizedSource)
|
|
2584
|
+
) {
|
|
2585
|
+
const checkout = remoteCheckoutDir(normalizedSource.url, normalizedSource.ref)
|
|
2586
|
+
if (existsSync(join(checkout, '.git'))) {
|
|
2587
|
+
try {
|
|
2588
|
+
const cachedPluginDir = normalizedSource.path ? pluginPath(checkout, normalizedSource.path) : checkout
|
|
2589
|
+
const cachedVersion = normalizeVersion(readPluginManifest(cachedPluginDir, false)?.version)
|
|
2590
|
+
const rowVersion = normalizeVersion(row.version)
|
|
2591
|
+
if (rowVersion && cachedVersion && semverGt(rowVersion, cachedVersion)) {
|
|
2592
|
+
effectiveRefresh = true
|
|
2593
|
+
allowStaleFallback = true
|
|
2594
|
+
}
|
|
2595
|
+
} catch {}
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
const { dir } = await materializePlugin(sourceId, pluginName, row.source, {
|
|
2601
|
+
refresh: effectiveRefresh,
|
|
2602
|
+
sourcePulled,
|
|
2603
|
+
allowStaleFallback,
|
|
2604
|
+
})
|
|
2552
2605
|
const target = installedDir(pluginName)
|
|
2553
2606
|
|
|
2554
2607
|
// Reinstalling must not inherit the previous copy's registrations: skills it
|
|
@@ -2567,11 +2620,53 @@ async function installMarketplacePluginFromSourceLocked({ sourceId, pluginName,
|
|
|
2567
2620
|
}
|
|
2568
2621
|
}
|
|
2569
2622
|
|
|
2623
|
+
function isPureSkillPackage(target, manifest) {
|
|
2624
|
+
return (
|
|
2625
|
+
listPrompts(target, manifest).length === 0 &&
|
|
2626
|
+
listConnectors(target, manifest).length === 0 &&
|
|
2627
|
+
listHooks(target, manifest).length === 0 &&
|
|
2628
|
+
listLspServers(target, manifest).length === 0 &&
|
|
2629
|
+
listAgents(target, manifest).length === 0 &&
|
|
2630
|
+
resolvePluginCommandEntries(target, manifest).entries.length === 0
|
|
2631
|
+
)
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2634
|
+
function canMoveTopLevelSkillDir(target, skillDir, manifestOrPure) {
|
|
2635
|
+
const isPure = typeof manifestOrPure === 'boolean'
|
|
2636
|
+
? manifestOrPure
|
|
2637
|
+
: isPureSkillPackage(target, manifestOrPure)
|
|
2638
|
+
if (!isPure) return false
|
|
2639
|
+
if (resolve(dirname(skillDir)) !== resolve(target)) return false
|
|
2640
|
+
for (const name of ['SKILL.md', 'skill.md']) {
|
|
2641
|
+
const skillMdPath = join(skillDir, name)
|
|
2642
|
+
if (!existsSync(skillMdPath)) continue
|
|
2643
|
+
try {
|
|
2644
|
+
return !/\$\{(?:CLAUDE_PLUGIN_ROOT|PLUGIN_ROOT)\}|\$(?:CLAUDE_PLUGIN_ROOT|PLUGIN_ROOT)\b/.test(readFileSync(skillMdPath, 'utf8'))
|
|
2645
|
+
} catch {
|
|
2646
|
+
return false
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
return false
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
async function mirrorSkillDir(target, skillDir, dest, pureSkill) {
|
|
2653
|
+
if (resolve(dest) === resolve(skillDir)) return
|
|
2654
|
+
if (!existsSync(dest) && canMoveTopLevelSkillDir(target, skillDir, pureSkill)) {
|
|
2655
|
+
try {
|
|
2656
|
+
renameSync(skillDir, dest)
|
|
2657
|
+
return
|
|
2658
|
+
} catch {}
|
|
2659
|
+
}
|
|
2660
|
+
await copyDirAsync(skillDir, dest)
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2570
2663
|
async function materializeAndRegisterPlugin({ sourceId, pluginName, row, dir, target, installed, prevConnectors, initialEnabled }) {
|
|
2571
|
-
if (existsSync(target))
|
|
2664
|
+
if (existsSync(target)) {
|
|
2665
|
+
await removePluginSkillsFromDsh(pluginName, { allowQuarantine: true, preserveOtherEnabled: true, deferCleanup: true })
|
|
2666
|
+
}
|
|
2572
2667
|
|
|
2573
2668
|
// Idempotent reinstall: clear the previous copy first.
|
|
2574
|
-
await
|
|
2669
|
+
await replaceManagedDirAsync(dir, target, undefined, false, { deferCleanup: true, excludeNames: new Set(['.git']) })
|
|
2575
2670
|
|
|
2576
2671
|
// Persist marketplace-declared components into the installed copy's manifest
|
|
2577
2672
|
// when `strict: false` or when absent on disk, preserving any existing
|
|
@@ -2606,7 +2701,10 @@ async function materializeAndRegisterPlugin({ sourceId, pluginName, row, dir, ta
|
|
|
2606
2701
|
'skills', 'commands', 'agents', '.agents', '.claude-plugin', '.codex-plugin', '.well-known',
|
|
2607
2702
|
'hooks', 'prompts', 'mcp', 'lsp', 'scripts', 'server', 'node_modules', '.git', 'assets', 'docs',
|
|
2608
2703
|
])
|
|
2609
|
-
const
|
|
2704
|
+
const installedManifest = readPluginManifest(target)
|
|
2705
|
+
const rootSkillMd = ['SKILL.md', 'skill.md'].map((f) => join(target, f)).find(existsSync)
|
|
2706
|
+
const pureSkill = !rootSkillMd && isPureSkillPackage(target, installedManifest)
|
|
2707
|
+
const declaredSkills = installedManifest?.skills
|
|
2610
2708
|
const skillPaths = typeof declaredSkills === 'string'
|
|
2611
2709
|
? (isDotRelativePath(declaredSkills) ? [declaredSkills] : [])
|
|
2612
2710
|
: (Array.isArray(declaredSkills) ? declaredSkills.filter((p) => typeof p === 'string' && isDotRelativePath(p)) : [])
|
|
@@ -2619,7 +2717,7 @@ async function materializeAndRegisterPlugin({ sourceId, pluginName, row, dir, ta
|
|
|
2619
2717
|
const parent = dirname(root)
|
|
2620
2718
|
if (resolve(parent) !== resolve(target)) {
|
|
2621
2719
|
const dest = join(skillsDir, basename(parent))
|
|
2622
|
-
|
|
2720
|
+
await mirrorSkillDir(target, parent, dest, pureSkill)
|
|
2623
2721
|
}
|
|
2624
2722
|
} else if (/\.md$/i.test(base) && !['README.md', 'CONTRIBUTING.md', 'LICENSE.md', 'CHANGELOG.md'].includes(base)) {
|
|
2625
2723
|
const skillName = base.replace(/\.md$/i, '')
|
|
@@ -2641,19 +2739,19 @@ async function materializeAndRegisterPlugin({ sourceId, pluginName, row, dir, ta
|
|
|
2641
2739
|
if (resolve(dir) === resolve(target)) continue // handled as a root skill below
|
|
2642
2740
|
if (!existsSync(join(dir, 'SKILL.md')) && !existsSync(join(dir, 'skill.md'))) continue
|
|
2643
2741
|
const dest = join(skillsDir, basename(dir))
|
|
2644
|
-
|
|
2742
|
+
await mirrorSkillDir(target, dir, dest, pureSkill)
|
|
2645
2743
|
}
|
|
2646
2744
|
}
|
|
2647
2745
|
|
|
2648
2746
|
// 1. Mirror commands/ (nested subdirs, manifest string/array/object paths & inline commands) into skills/
|
|
2649
|
-
const { entries: commandEntries } = resolvePluginCommandEntries(target,
|
|
2747
|
+
const { entries: commandEntries } = resolvePluginCommandEntries(target, installedManifest)
|
|
2650
2748
|
for (const cmd of commandEntries) {
|
|
2651
2749
|
const cmdSkillDir = join(skillsDir, cmd.name)
|
|
2652
2750
|
if (existsSync(cmdSkillDir)) continue
|
|
2653
2751
|
if (cmd.filePath) {
|
|
2654
2752
|
if (/^skill\.md$/i.test(basename(cmd.filePath))) {
|
|
2655
2753
|
mkdirSync(cmdSkillDir, { recursive: true })
|
|
2656
|
-
|
|
2754
|
+
await copyDirAsync(dirname(cmd.filePath), cmdSkillDir)
|
|
2657
2755
|
} else {
|
|
2658
2756
|
mkdirSync(cmdSkillDir, { recursive: true })
|
|
2659
2757
|
const rawContent = readFileSync(cmd.filePath, 'utf8')
|
|
@@ -2668,14 +2766,13 @@ async function materializeAndRegisterPlugin({ sourceId, pluginName, row, dir, ta
|
|
|
2668
2766
|
}
|
|
2669
2767
|
|
|
2670
2768
|
// 2. If the plugin has a root SKILL.md, mirror it into skills/<pluginName>/SKILL.md
|
|
2671
|
-
const rootSkillMd = ['SKILL.md', 'skill.md'].map((f) => join(target, f)).find(existsSync)
|
|
2672
2769
|
if (rootSkillMd) {
|
|
2673
2770
|
const rootSkillDir = join(skillsDir, pluginName)
|
|
2674
2771
|
if (!existsSync(rootSkillDir)) {
|
|
2675
2772
|
mkdirSync(rootSkillDir, { recursive: true })
|
|
2676
2773
|
// Keep relative scripts/references/assets usable when DSH copies the skill.
|
|
2677
2774
|
for (const entry of readdirSync(target, { withFileTypes: true })) {
|
|
2678
|
-
if (entry.isDirectory() && !['skills', '.git', 'node_modules'].includes(entry.name))
|
|
2775
|
+
if (entry.isDirectory() && !['skills', '.git', 'node_modules'].includes(entry.name)) await copyDirAsync(join(target, entry.name), join(rootSkillDir, entry.name))
|
|
2679
2776
|
else if (entry.isFile()) copyFileSync(join(target, entry.name), join(rootSkillDir, entry.name))
|
|
2680
2777
|
}
|
|
2681
2778
|
const rawContent = readFileSync(rootSkillMd, 'utf8')
|
|
@@ -2700,8 +2797,7 @@ async function materializeAndRegisterPlugin({ sourceId, pluginName, row, dir, ta
|
|
|
2700
2797
|
const sMd = join(target, entry.name, 'SKILL.md')
|
|
2701
2798
|
if (existsSync(sMd) && !existsSync(join(skillsDir, entry.name))) {
|
|
2702
2799
|
const subDir = join(skillsDir, entry.name)
|
|
2703
|
-
|
|
2704
|
-
copyDir(join(target, entry.name), subDir)
|
|
2800
|
+
await mirrorSkillDir(target, join(target, entry.name), subDir, pureSkill)
|
|
2705
2801
|
}
|
|
2706
2802
|
}
|
|
2707
2803
|
}
|
|
@@ -3117,46 +3213,61 @@ async function togglePluginUnlocked(pluginName, enabled, epoch, options = {}) {
|
|
|
3117
3213
|
* reinstall the plugin copy and re-run conversions.
|
|
3118
3214
|
*/
|
|
3119
3215
|
export async function updatePlugin(pluginName) {
|
|
3216
|
+
const lockKey = pluginLockKey(pluginName)
|
|
3217
|
+
if (activePluginUpdates.has(lockKey)) {
|
|
3218
|
+
throw Object.assign(new Error(`插件 ${pluginName} 正在更新`), { status: 409 })
|
|
3219
|
+
}
|
|
3220
|
+
if (marketplaceInstalls.has(lockKey)) {
|
|
3221
|
+
throw Object.assign(new Error(`插件 ${pluginName} 正在安装`), { status: 409 })
|
|
3222
|
+
}
|
|
3223
|
+
activePluginUpdates.add(lockKey)
|
|
3120
3224
|
bumpPluginEpoch(pluginName)
|
|
3121
3225
|
cancelActivePluginProbes(pluginName)
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
if (
|
|
3136
|
-
|
|
3226
|
+
try {
|
|
3227
|
+
return await withPluginLock(pluginName, async () => {
|
|
3228
|
+
const initialRec = readState().plugins.find((p) => p.name === pluginName)
|
|
3229
|
+
if (!initialRec) throw new Error(`plugin not installed: ${pluginName}`)
|
|
3230
|
+
return withSourceLock(initialRec.sourceId, async () => {
|
|
3231
|
+
const state = readState()
|
|
3232
|
+
const rec = state.plugins.find((p) => p.name === pluginName)
|
|
3233
|
+
if (!rec) throw new Error(`plugin not installed: ${pluginName}`)
|
|
3234
|
+
if (rec.sourceId === 'local' && !readMarketplace('local').some(row => row.name === pluginName)) {
|
|
3235
|
+
throw new Error('本地插件的原始来源不可用,请重新导入后再更新')
|
|
3236
|
+
}
|
|
3237
|
+
const source = state.sources.find((s) => s.id === rec.sourceId)
|
|
3238
|
+
let sourcePulled = false
|
|
3239
|
+
if (source && typeof source.url === 'string') {
|
|
3240
|
+
const cacheDir = sourceCacheDir(rec.sourceId)
|
|
3241
|
+
if (existsSync(join(cacheDir, '.git'))) {
|
|
3242
|
+
await pullSource(rec.sourceId)
|
|
3243
|
+
sourcePulled = true
|
|
3244
|
+
}
|
|
3137
3245
|
}
|
|
3138
|
-
}
|
|
3139
3246
|
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3247
|
+
// Clear memory cache so fresh MCP tool lists can be queried
|
|
3248
|
+
for (const k of Array.from(MEMORY_TOOLS_CACHE.keys())) {
|
|
3249
|
+
if (k.startsWith(`${pluginName}::`)) {
|
|
3250
|
+
MEMORY_TOOLS_CACHE.delete(k)
|
|
3251
|
+
}
|
|
3144
3252
|
}
|
|
3145
|
-
}
|
|
3146
3253
|
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3254
|
+
// The marketplace rows are cached for 30s; without this the install below
|
|
3255
|
+
// re-reads the pre-pull catalog and installs the old revision.
|
|
3256
|
+
invalidateMarketplaceCache(rec.sourceId)
|
|
3150
3257
|
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3258
|
+
// Freshly materialized install (re-copies, re-registers, re-converts).
|
|
3259
|
+
return installMarketplacePluginFromSourceLocked({
|
|
3260
|
+
sourceId: rec.sourceId,
|
|
3261
|
+
pluginName,
|
|
3262
|
+
refresh: true,
|
|
3263
|
+
sourcePulled,
|
|
3264
|
+
initialEnabled: rec.enabled !== false,
|
|
3265
|
+
})
|
|
3157
3266
|
})
|
|
3158
3267
|
})
|
|
3159
|
-
}
|
|
3268
|
+
} finally {
|
|
3269
|
+
activePluginUpdates.delete(lockKey)
|
|
3270
|
+
}
|
|
3160
3271
|
}
|
|
3161
3272
|
|
|
3162
3273
|
/**
|
|
@@ -3341,7 +3452,7 @@ function buildInstalledPluginDetail(rec, shared = {}) {
|
|
|
3341
3452
|
|
|
3342
3453
|
const target = installedDir(rec.name)
|
|
3343
3454
|
const installed = existsSync(target)
|
|
3344
|
-
if (installed && !PLUGIN_LOCKS.has(rec.name)) {
|
|
3455
|
+
if (installed && !PLUGIN_LOCKS.has(pluginLockKey(rec.name))) {
|
|
3345
3456
|
const skillsDir = join(target, 'skills')
|
|
3346
3457
|
try {
|
|
3347
3458
|
for (const entry of readdirSync(target, { withFileTypes: true })) {
|
|
@@ -3490,8 +3601,8 @@ function buildInstalledPluginDetail(rec, shared = {}) {
|
|
|
3490
3601
|
connectors,
|
|
3491
3602
|
hooks: listHooks(target, targetManifest),
|
|
3492
3603
|
lspServers,
|
|
3493
|
-
version: targetManifest?.version ?? null,
|
|
3494
|
-
} : { skills: [], agents: [], prompts: [], connectors: [], hooks: [], lspServers: [], version: null }
|
|
3604
|
+
version: targetManifest?.version ?? rec.version ?? null,
|
|
3605
|
+
} : { skills: [], agents: [], prompts: [], connectors: [], hooks: [], lspServers: [], version: rec.version ?? null }
|
|
3495
3606
|
const shortDescription = rec.shortDescription || (installed ? readPluginShortDescription(target) : '') || marketRow?.shortDescription || ''
|
|
3496
3607
|
return {
|
|
3497
3608
|
...rec,
|
package/src/market.js
CHANGED
|
@@ -135,7 +135,14 @@ function hasSourceCheckout(dir) {
|
|
|
135
135
|
return existsSync(join(git, 'uph-clone-complete')) || existsSync(join(git, 'index'))
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
function safeSparsePath(root, pathValue) {
|
|
139
|
+
if (typeof pathValue !== 'string' || !pathValue) return ''
|
|
140
|
+
const resolved = pluginPath(root, pathValue)
|
|
141
|
+
const rel = relative(resolve(root), resolved).replace(/\\/g, '/').replace(/^\/+|\/+$/g, '')
|
|
142
|
+
return rel === '.' ? '' : rel
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function cloneRepoToCache(dir, url, { branch, timeoutMs, sparsePath } = {}) {
|
|
139
146
|
const hadCheckout = hasSourceCheckout(dir)
|
|
140
147
|
if (hadCheckout && readCheckoutOrigin(dir) === url) return false
|
|
141
148
|
|
|
@@ -144,10 +151,29 @@ async function cloneRepoToCache(dir, url, { branch, timeoutMs } = {}) {
|
|
|
144
151
|
mkdirSync(parent, { recursive: true })
|
|
145
152
|
const staging = mkdtempSync(join(parent, '.clone-'))
|
|
146
153
|
try {
|
|
147
|
-
const
|
|
154
|
+
const normalizedSparse = safeSparsePath(staging, sparsePath)
|
|
155
|
+
const args = ['clone', '--depth', '1', '--single-branch']
|
|
148
156
|
if (branch) args.push('--branch', String(branch))
|
|
149
157
|
args.push(url, staging)
|
|
150
|
-
|
|
158
|
+
|
|
159
|
+
let cloned = false
|
|
160
|
+
if (normalizedSparse && /^https?:\/\//i.test(String(url))) {
|
|
161
|
+
try {
|
|
162
|
+
const sparseArgs = ['clone', '--depth', '1', '--single-branch', '--filter=blob:none', '--no-checkout']
|
|
163
|
+
if (branch) sparseArgs.push('--branch', String(branch))
|
|
164
|
+
sparseArgs.push(url, staging)
|
|
165
|
+
await runGit(sparseArgs, undefined, timeoutMs)
|
|
166
|
+
await runGit(['sparse-checkout', 'set', '--cone', '--', normalizedSparse], staging, timeoutMs)
|
|
167
|
+
await runGit(['checkout'], staging, timeoutMs)
|
|
168
|
+
cloned = true
|
|
169
|
+
} catch {
|
|
170
|
+
safeRmDir(staging)
|
|
171
|
+
mkdirSync(staging, { recursive: true })
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (!cloned) {
|
|
175
|
+
await runGit(args, undefined, timeoutMs)
|
|
176
|
+
}
|
|
151
177
|
// Empty repositories can be cloned successfully without an index.
|
|
152
178
|
writeFileSync(join(staging, '.git', 'uph-clone-complete'), '')
|
|
153
179
|
// The slug can collide with an abandoned preview from another repository.
|
|
@@ -212,7 +238,7 @@ export async function pullSource(sourceId) {
|
|
|
212
238
|
* Returns { dir } of a materialized checkout for the plugin, or throws with
|
|
213
239
|
* a user-facing message.
|
|
214
240
|
*/
|
|
215
|
-
export async function materializePlugin(sourceId, pluginName, source, { refresh = false } = {}) {
|
|
241
|
+
export async function materializePlugin(sourceId, pluginName, source, { refresh = false, sourcePulled = false, allowStaleFallback = false } = {}) {
|
|
216
242
|
safeSegment(sourceId, 'source id')
|
|
217
243
|
safeSegment(pluginName, 'plugin name')
|
|
218
244
|
|
|
@@ -236,17 +262,37 @@ export async function materializePlugin(sourceId, pluginName, source, { refresh
|
|
|
236
262
|
if (typeof normalized.url !== 'string' || !/^https?:\/\//.test(normalized.url)) {
|
|
237
263
|
throw new Error(`plugin ${pluginName}: unsupported remote url`)
|
|
238
264
|
}
|
|
265
|
+
const sourceCache = sourceCacheDir(sourceId)
|
|
266
|
+
const ownDir = sourceRepositoryDir(sourceCache, normalized)
|
|
267
|
+
if (ownDir) {
|
|
268
|
+
if (refresh && !sourcePulled && existsSync(join(sourceCache, '.git'))) {
|
|
269
|
+
try {
|
|
270
|
+
await pullSource(sourceId)
|
|
271
|
+
} catch (err) {
|
|
272
|
+
if (!allowStaleFallback) throw err
|
|
273
|
+
}
|
|
274
|
+
const refreshedDir = sourceRepositoryDir(sourceCache, normalized)
|
|
275
|
+
if (refreshedDir) return { dir: refreshedDir }
|
|
276
|
+
} else {
|
|
277
|
+
return { dir: ownDir }
|
|
278
|
+
}
|
|
279
|
+
}
|
|
239
280
|
const remoteKey = remoteCheckoutKey(normalized.url, normalized.ref)
|
|
240
281
|
const checkout = join(sourceCacheDir('remote'), remoteKey)
|
|
241
282
|
await withGitLock(`remote:${remoteKey}`, async () => {
|
|
242
|
-
const
|
|
283
|
+
const sparsePath = normalized.source === 'git-subdir' ? normalized.path : undefined
|
|
284
|
+
const cloned = await cloneRepoToCache(checkout, normalized.url, { branch: normalized.ref, sparsePath })
|
|
243
285
|
if (!cloned && refresh) {
|
|
244
286
|
// The cached checkout is otherwise reused forever, so updates would
|
|
245
287
|
// reinstall the first clone's commit. Re-fetch the tracked ref.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
288
|
+
try {
|
|
289
|
+
const args = ['fetch', '--depth', '1', 'origin']
|
|
290
|
+
if (normalized.ref) args.push(String(normalized.ref))
|
|
291
|
+
await runGit(args, checkout)
|
|
292
|
+
await runGit(['reset', '--hard', 'FETCH_HEAD'], checkout)
|
|
293
|
+
} catch (err) {
|
|
294
|
+
if (!allowStaleFallback) throw err
|
|
295
|
+
}
|
|
250
296
|
}
|
|
251
297
|
if (normalized.sha && /^[0-9a-f]{7,64}$/i.test(String(normalized.sha))) {
|
|
252
298
|
try {
|
|
@@ -257,6 +303,17 @@ export async function materializePlugin(sourceId, pluginName, source, { refresh
|
|
|
257
303
|
}
|
|
258
304
|
} catch {}
|
|
259
305
|
}
|
|
306
|
+
if (!cloned && existsSync(join(checkout, '.git', 'info', 'sparse-checkout'))) {
|
|
307
|
+
const posixPath = safeSparsePath(checkout, normalized.path)
|
|
308
|
+
if (posixPath) {
|
|
309
|
+
const targetPath = pluginPath(checkout, posixPath)
|
|
310
|
+
if (!existsSync(targetPath)) {
|
|
311
|
+
await runGit(['sparse-checkout', 'add', '--', posixPath], checkout)
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
await runGit(['sparse-checkout', 'disable'], checkout)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
260
317
|
})
|
|
261
318
|
const dir = normalized.path ? pluginPath(checkout, normalized.path) : checkout
|
|
262
319
|
if (!existsSync(dir)) throw new Error(`plugin ${pluginName}: path ${normalized.path} not found in remote repo`)
|
package/src/parser.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* 4. Multi-plugin Monorepos (plugins/*, skills/*, packages/*, tools/*, extensions/*)
|
|
9
9
|
* 5. Single-plugin Standalone Repositories (root SKILL.md, plugin.json, skills/, commands/, agents/, .cursorrules)
|
|
10
10
|
*/
|
|
11
|
-
import { existsSync, readFileSync, readdirSync, statSync, mkdirSync, copyFileSync } from 'node:fs'
|
|
11
|
+
import { existsSync, readFileSync, readdirSync, statSync, realpathSync, mkdirSync, copyFileSync } from 'node:fs'
|
|
12
|
+
import { readdir, mkdir, copyFile, stat, realpath } from 'node:fs/promises'
|
|
12
13
|
import { join, basename, dirname, isAbsolute, relative, resolve } from 'node:path'
|
|
13
14
|
import { load as parseYaml } from 'js-yaml'
|
|
14
15
|
import { sourceCacheDir, installedDir, pluginDataDir } from './store.js'
|
|
@@ -1887,15 +1888,86 @@ export function pluginDetail(sourceId, pluginName, source, rowFallback) {
|
|
|
1887
1888
|
}
|
|
1888
1889
|
|
|
1889
1890
|
/** Recursively copy a directory (plain JS; avoids shell dependency). */
|
|
1890
|
-
export function copyDir(from, to) {
|
|
1891
|
+
export function copyDir(from, to, visited = null) {
|
|
1892
|
+
const seen = visited || new Set()
|
|
1893
|
+
if (!visited) {
|
|
1894
|
+
try { seen.add(realpathSync(from)) } catch {}
|
|
1895
|
+
}
|
|
1891
1896
|
mkdirSync(to, { recursive: true })
|
|
1892
|
-
for (const entry of readdirSync(from)) {
|
|
1893
|
-
const src = join(from, entry)
|
|
1894
|
-
const dest = join(to, entry)
|
|
1895
|
-
if (
|
|
1896
|
-
copyDir(src, dest)
|
|
1897
|
+
for (const entry of readdirSync(from, { withFileTypes: true })) {
|
|
1898
|
+
const src = join(from, entry.name)
|
|
1899
|
+
const dest = join(to, entry.name)
|
|
1900
|
+
if (entry.isDirectory()) {
|
|
1901
|
+
copyDir(src, dest, seen)
|
|
1902
|
+
} else if (entry.isSymbolicLink()) {
|
|
1903
|
+
let st
|
|
1904
|
+
try { st = statSync(src) } catch { continue }
|
|
1905
|
+
if (st.isDirectory()) {
|
|
1906
|
+
let realDir
|
|
1907
|
+
try { realDir = realpathSync(src) } catch { continue }
|
|
1908
|
+
if (seen.has(realDir)) continue
|
|
1909
|
+
seen.add(realDir)
|
|
1910
|
+
copyDir(src, dest, seen)
|
|
1911
|
+
} else if (st.isFile()) {
|
|
1912
|
+
copyFileSync(src, dest)
|
|
1913
|
+
}
|
|
1897
1914
|
} else {
|
|
1898
1915
|
copyFileSync(src, dest)
|
|
1899
1916
|
}
|
|
1900
1917
|
}
|
|
1901
1918
|
}
|
|
1919
|
+
|
|
1920
|
+
/** Recursively copy a directory asynchronously using a bounded concurrent worker pool. */
|
|
1921
|
+
export async function copyDirAsync(from, to, { concurrency = 32, excludeNames = null } = {}) {
|
|
1922
|
+
const seen = new Set()
|
|
1923
|
+
try { seen.add(await realpath(from)) } catch {}
|
|
1924
|
+
const dirs = [to]
|
|
1925
|
+
const files = []
|
|
1926
|
+
async function scan(curFrom, curTo) {
|
|
1927
|
+
const entries = await readdir(curFrom, { withFileTypes: true })
|
|
1928
|
+
for (const entry of entries) {
|
|
1929
|
+
if (excludeNames?.has(entry.name)) continue
|
|
1930
|
+
const src = join(curFrom, entry.name)
|
|
1931
|
+
const dest = join(curTo, entry.name)
|
|
1932
|
+
if (entry.isDirectory()) {
|
|
1933
|
+
dirs.push(dest)
|
|
1934
|
+
await scan(src, dest)
|
|
1935
|
+
} else if (entry.isFile()) {
|
|
1936
|
+
files.push([src, dest])
|
|
1937
|
+
} else if (entry.isSymbolicLink()) {
|
|
1938
|
+
let st
|
|
1939
|
+
try { st = await stat(src) } catch { continue }
|
|
1940
|
+
if (st.isDirectory()) {
|
|
1941
|
+
let realDir
|
|
1942
|
+
try { realDir = await realpath(src) } catch { continue }
|
|
1943
|
+
if (seen.has(realDir)) continue
|
|
1944
|
+
seen.add(realDir)
|
|
1945
|
+
dirs.push(dest)
|
|
1946
|
+
await scan(src, dest)
|
|
1947
|
+
} else if (st.isFile()) {
|
|
1948
|
+
files.push([src, dest])
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
}
|
|
1953
|
+
await scan(from, to)
|
|
1954
|
+
for (const dir of dirs) {
|
|
1955
|
+
await mkdir(dir, { recursive: true })
|
|
1956
|
+
}
|
|
1957
|
+
if (files.length === 0) return
|
|
1958
|
+
let firstErr = null
|
|
1959
|
+
let idx = 0
|
|
1960
|
+
const workerCount = Math.max(1, Math.min(concurrency, files.length))
|
|
1961
|
+
async function worker() {
|
|
1962
|
+
while (!firstErr && idx < files.length) {
|
|
1963
|
+
const [src, dest] = files[idx++]
|
|
1964
|
+
try {
|
|
1965
|
+
await copyFile(src, dest)
|
|
1966
|
+
} catch (err) {
|
|
1967
|
+
if (!firstErr) firstErr = err
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
await Promise.all(Array.from({ length: workerCount }, worker))
|
|
1972
|
+
if (firstErr) throw firstErr
|
|
1973
|
+
}
|
package/src/store.js
CHANGED
|
@@ -66,6 +66,16 @@ function unlinkReparsePointsSync(dir) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
function unlinkSymlinkPath(dir) {
|
|
70
|
+
try {
|
|
71
|
+
unlinkSync(dir)
|
|
72
|
+
} catch {
|
|
73
|
+
try { rmdirSync(dir) } catch {
|
|
74
|
+
try { rmSync(dir, { recursive: true, force: true }) } catch {}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
/** Robust directory deletion handling Windows readonly/locked files. */
|
|
70
80
|
export function safeRmDir(dir, { allowTrash = true, quarantineRoot = trashRoot() } = {}) {
|
|
71
81
|
if (!dir) return
|
|
@@ -75,13 +85,7 @@ export function safeRmDir(dir, { allowTrash = true, quarantineRoot = trashRoot()
|
|
|
75
85
|
let lstatErr = null
|
|
76
86
|
try { entry = lstatSync(dir, { throwIfNoEntry: false }) } catch (err) { lstatErr = err }
|
|
77
87
|
if (entry?.isSymbolicLink()) {
|
|
78
|
-
|
|
79
|
-
unlinkSync(dir)
|
|
80
|
-
} catch {
|
|
81
|
-
try { rmdirSync(dir) } catch {
|
|
82
|
-
try { rmSync(dir, { recursive: true, force: true }) } catch {}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
88
|
+
unlinkSymlinkPath(dir)
|
|
85
89
|
return
|
|
86
90
|
}
|
|
87
91
|
if (!entry && !lstatErr && !existsSync(dir)) return
|
|
@@ -130,23 +134,45 @@ export function safeRmDir(dir, { allowTrash = true, quarantineRoot = trashRoot()
|
|
|
130
134
|
/** Remove managed files before forgetting the record needed to retry cleanup. */
|
|
131
135
|
export function removeManagedDir(dir, { allowTrash = false, deferCleanup = false } = {}) {
|
|
132
136
|
if (deferCleanup) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
137
|
+
let entry
|
|
138
|
+
let lstatErr = null
|
|
139
|
+
try { entry = lstatSync(dir, { throwIfNoEntry: false }) } catch (err) { lstatErr = err }
|
|
140
|
+
if (!entry && !lstatErr) return
|
|
141
|
+
if (entry?.isSymbolicLink()) {
|
|
142
|
+
unlinkSymlinkPath(dir)
|
|
143
|
+
try {
|
|
144
|
+
if (!lstatSync(dir, { throwIfNoEntry: false })) return
|
|
145
|
+
} catch {}
|
|
146
|
+
}
|
|
147
|
+
const quarantineRoot = trashRoot()
|
|
148
|
+
if (
|
|
149
|
+
!lstatErr &&
|
|
150
|
+
entry?.isDirectory() &&
|
|
151
|
+
!isSameOrInsidePath(dir, quarantineRoot) &&
|
|
152
|
+
!isSameOrInsidePath(quarantineRoot, dir)
|
|
153
|
+
) {
|
|
154
|
+
try {
|
|
155
|
+
// Detach the checkout as a unit. An open Windows handle can block the
|
|
156
|
+
// move, in which case the caller retries while the checkout stays intact.
|
|
157
|
+
const trashed = moveToTrash(dir, quarantineRoot)
|
|
158
|
+
PENDING_TRASH_PATHS.add(trashed)
|
|
159
|
+
void rm(trashed, { recursive: true, force: true }).then(
|
|
160
|
+
() => {
|
|
161
|
+
PENDING_TRASH_PATHS.delete(trashed)
|
|
162
|
+
try { rmdirSync(quarantineRoot) } catch {}
|
|
163
|
+
},
|
|
164
|
+
() => scheduleTrashSweep(trashed),
|
|
165
|
+
)
|
|
166
|
+
return
|
|
167
|
+
} catch (cause) {
|
|
168
|
+
if (cause?.code !== 'EXDEV') {
|
|
169
|
+
throw Object.assign(new Error(`无法清理目录:${dir}`, { cause }), {
|
|
170
|
+
code: cause.code,
|
|
171
|
+
syscall: cause.syscall,
|
|
172
|
+
path: dir,
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
}
|
|
150
176
|
}
|
|
151
177
|
}
|
|
152
178
|
safeRmDir(dir, { allowTrash })
|