dsh-skill-browser 2.0.14 → 2.2.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/CHANGELOG.md +86 -0
- package/README-zh.md +13 -0
- package/README.md +12 -0
- package/docs/images/shot-09.png +0 -0
- package/docs/images/shot-10.png +0 -0
- package/docs/images/shot-11.png +0 -0
- package/lib/client.js +535 -25
- package/lib/index.js +93 -1
- package/lib/market.js +9 -3
- package/lib/selfupdate.js +300 -0
- package/package.json +1 -1
- package/screenshots.json +4 -6
package/lib/index.js
CHANGED
|
@@ -23,6 +23,7 @@ var lsMod = await import("./ledger-stats.js" + RELOAD_V);
|
|
|
23
23
|
var zhMod = await import("./zh.js" + RELOAD_V);
|
|
24
24
|
var grMod = await import("./groups.js" + RELOAD_V);
|
|
25
25
|
var kwMod = await import("./keyword-groups.js" + RELOAD_V);
|
|
26
|
+
var suMod = await import("./selfupdate.js" + RELOAD_V);
|
|
26
27
|
|
|
27
28
|
var scanSkills = scanMod.scanSkills, categoriesMeta = scanMod.categoriesMeta,
|
|
28
29
|
readSkillBody = scanMod.readSkillBody, parseLedgerTable = scanMod.parseLedgerTable,
|
|
@@ -58,10 +59,29 @@ var marketMod = await import("./market.js" + RELOAD_V);
|
|
|
58
59
|
var buildMarket = marketMod.buildMarket, MARKET_CATS = marketMod.MARKET_CATS, fetchRegistry = marketMod.fetchRegistry; // v2.0.6: MCP 市场
|
|
59
60
|
|
|
60
61
|
var PREFIX = "/dsh-skill-browser";
|
|
61
|
-
export var VERSION = "2.
|
|
62
|
+
export var VERSION = "2.2.5";
|
|
62
63
|
var CACHE_TTL_MS = 30 * 1000;
|
|
63
64
|
var DIAG_FILE = join(homedir(), ".dsh", "data", "dsh-skill-browser", "diag.log");
|
|
64
65
|
var CONFIG_FILE = join(homedir(), ".dsh", "data", "dsh-skill-browser", "config.json");
|
|
66
|
+
// v2.1.0: 卡片列表磁盘缓存。启动首开面板直接读它,避免为了渲染卡片同步扫全库;
|
|
67
|
+
// 之后由后台轻量重建(3s 后)刷新。详情仍按需加载,不进缓存。
|
|
68
|
+
var CARDS_CACHE_FILE = join(homedir(), ".dsh", "data", "dsh-skill-browser", "cards-cache.json");
|
|
69
|
+
function readCardsCache() {
|
|
70
|
+
try {
|
|
71
|
+
var o = JSON.parse(readFileSync(CARDS_CACHE_FILE, "utf8"));
|
|
72
|
+
if (o && o._v === 1 && Array.isArray(o.skills) && o.skills.length) return o;
|
|
73
|
+
} catch (e) {}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
function writeCardsCache(p) {
|
|
77
|
+
try {
|
|
78
|
+
mkdirSync(join(homedir(), ".dsh", "data", "dsh-skill-browser"), { recursive: true });
|
|
79
|
+
writeFileSync(CARDS_CACHE_FILE, JSON.stringify({
|
|
80
|
+
_v: 1, savedAt: Date.now(), generatedAt: p.generatedAt, total: p.total,
|
|
81
|
+
categories: p.categories, skills: p.skills, ui: p.ui
|
|
82
|
+
}), "utf8");
|
|
83
|
+
} catch (e) {}
|
|
84
|
+
}
|
|
65
85
|
// v1.7.2: hard cap on one batch call (skill libraries are ~hundreds, this is
|
|
66
86
|
// only an abuse guard - the panel never sends more than the full library).
|
|
67
87
|
var BATCH_MAX = 2000;
|
|
@@ -222,6 +242,30 @@ async function selfReload(ctx, config) {
|
|
|
222
242
|
return { version: fresh.VERSION || VERSION, gen: LIVE.gen };
|
|
223
243
|
}
|
|
224
244
|
|
|
245
|
+
|
|
246
|
+
/** 作者插件包的 npm 累计下载量(宿主侧抓,10 分钟内存缓存;客户端只读取用)。 */
|
|
247
|
+
var AUTHOR_STATS_PKGS = ["dsh-loyalchiiina-plugin-pack","dsh-font-enhancer","dsh-skill-browser","dsh-todo-float-ball","dsh-model-fold","dsh-voice-alert","dsh-archive-favorites-forge","dsh-chat-image-lightbox","dsh-lit-fetch","dsh-schedule-calendar","dsh-console-sentinel","dsh-browser-hub"];
|
|
248
|
+
var _authorStats = { total: { ts: 0, data: null }, month: { ts: 0, data: null } };
|
|
249
|
+
function getAuthorStats(range) {
|
|
250
|
+
var rng = (range === "month") ? "month" : "total";
|
|
251
|
+
var cache = _authorStats[rng];
|
|
252
|
+
var now = Date.now();
|
|
253
|
+
if (cache.data && now - cache.ts < 10 * 60 * 1000) return Promise.resolve(cache.data);
|
|
254
|
+
var asOf = new Date().toISOString().slice(0, 10);
|
|
255
|
+
var out = { ok: true, range: rng, asOf: asOf, stats: {} };
|
|
256
|
+
var jobs = AUTHOR_STATS_PKGS.map(function (pkg) {
|
|
257
|
+
var url = (rng === "month")
|
|
258
|
+
? "https://api.npmjs.org/downloads/point/last-month/" + pkg
|
|
259
|
+
: "https://api.npmjs.org/downloads/point/2015-01-01:" + asOf + "/" + pkg;
|
|
260
|
+
var ctl = (typeof AbortController === "function") ? new AbortController() : null;
|
|
261
|
+
var timer = ctl ? setTimeout(function () { try { ctl.abort(); } catch (e) {} }, 8000) : null;
|
|
262
|
+
return fetch(url, ctl ? { signal: ctl.signal } : {}).then(function (r) { return r.json(); }).then(function (j) {
|
|
263
|
+
out.stats[pkg] = { total: (j && typeof j.downloads === "number") ? j.downloads : null };
|
|
264
|
+
}).catch(function () { out.stats[pkg] = { total: null }; }).then(function () { if (timer) clearTimeout(timer); });
|
|
265
|
+
});
|
|
266
|
+
return Promise.all(jobs).then(function () { _authorStats[rng] = { ts: Date.now(), data: out }; return out; });
|
|
267
|
+
}
|
|
268
|
+
|
|
225
269
|
export function apply(ctx, config) {
|
|
226
270
|
ctx.effect(function () {
|
|
227
271
|
var api = createApi(ctx, config);
|
|
@@ -346,9 +390,21 @@ export function createApi(ctx, config) {
|
|
|
346
390
|
};
|
|
347
391
|
}
|
|
348
392
|
|
|
393
|
+
var diskTried = false;
|
|
349
394
|
function getPayload(force) {
|
|
350
395
|
var now = Date.now();
|
|
351
396
|
if (!force && cache.payload && now - cache.ts < CACHE_TTL_MS) return cache.payload;
|
|
397
|
+
// v2.1.0: 首次请求先回磁盘缓存(陈旧但立即可用),并安排后台重建。
|
|
398
|
+
if (!force && !cache.payload && !diskTried) {
|
|
399
|
+
diskTried = true;
|
|
400
|
+
var disk = readCardsCache();
|
|
401
|
+
if (disk) {
|
|
402
|
+
cache.payload = disk;
|
|
403
|
+
cache.ts = now - CACHE_TTL_MS + 5000; // 5s 后过期,触发重建
|
|
404
|
+
setTimeout(function () { try { getPayload(true); } catch (e) {} }, 3000).unref?.();
|
|
405
|
+
return disk;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
352
408
|
if (!root) {
|
|
353
409
|
var re = detectRoot(config, runtime);
|
|
354
410
|
root = re.root;
|
|
@@ -358,6 +414,7 @@ export function createApi(ctx, config) {
|
|
|
358
414
|
if (root) resolveLedger(force); // 首扫/强刷时:搜索台账,无则创建(幂等)
|
|
359
415
|
cache.payload = buildPayload();
|
|
360
416
|
cache.ts = now;
|
|
417
|
+
writeCardsCache(cache.payload);
|
|
361
418
|
return cache.payload;
|
|
362
419
|
}
|
|
363
420
|
|
|
@@ -1083,6 +1140,41 @@ function getLedgerPayload(force) {
|
|
|
1083
1140
|
return;
|
|
1084
1141
|
}
|
|
1085
1142
|
|
|
1143
|
+
if (path === PREFIX + "/author-stats" && req.method === "GET") {
|
|
1144
|
+
var _q = String(req.url || "").split("?")[1] || "";
|
|
1145
|
+
var _rng = (_q.indexOf("range=month") >= 0) ? "month" : "total";
|
|
1146
|
+
getAuthorStats(_rng).then(function (r) { sendJson(res, 200, r); })
|
|
1147
|
+
.catch(function (e) { sendJson(res, 200, { ok: false, stats: {}, error: String((e && e.message) || e) }); });
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// ── v2.1.6: 插件自更新(所有带 UI 插件共用这一套后端)──────────────
|
|
1152
|
+
// GET ?pkg=<name> 检查是否落后于 npm 最新版
|
|
1153
|
+
// POST ?pkg=<name> 真安装到 profile(仅 registry 安装;link/file 拒绝)
|
|
1154
|
+
// GET 最近一次安装日志(页面刷新后还能看)
|
|
1155
|
+
if (path === PREFIX + "/plugin-update" && req.method === "GET") {
|
|
1156
|
+
var _um = /(?:^|&)pkg=([^&]+)/.exec(query || "");
|
|
1157
|
+
var _upkg = _um ? decodeURIComponent(_um[1]) : "";
|
|
1158
|
+
if (!_upkg) { sendJson(res, 400, { ok: false, error: "missing pkg" }); return; }
|
|
1159
|
+
suMod.checkUpdate(_upkg).then(function (r) { sendJson(res, 200, r); })
|
|
1160
|
+
.catch(function (e) { sendJson(res, 500, { ok: false, error: String((e && e.message) || e) }); });
|
|
1161
|
+
return;
|
|
1162
|
+
}
|
|
1163
|
+
if (path === PREFIX + "/plugin-update-apply" && req.method === "POST") {
|
|
1164
|
+
var _am = /(?:^|&)pkg=([^&]+)/.exec(query || "");
|
|
1165
|
+
var _apkg = _am ? decodeURIComponent(_am[1]) : "";
|
|
1166
|
+
if (!_apkg) { sendJson(res, 400, { ok: false, error: "missing pkg" }); return; }
|
|
1167
|
+
suMod.applyUpdate(_apkg).then(function (r) {
|
|
1168
|
+
if (r && r.ok) ctx.logger.info("dsh-skill-browser: updated " + _apkg + " -> " + (r.latest || "?") + " via " + (r.packageManager || "?"));
|
|
1169
|
+
sendJson(res, 200, r);
|
|
1170
|
+
}).catch(function (e) { sendJson(res, 500, { ok: false, error: String((e && e.message) || e) }); });
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
if (path === PREFIX + "/plugin-update-log" && req.method === "GET") {
|
|
1174
|
+
sendJson(res, 200, { ok: true, log: suMod.lastLog() });
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1086
1178
|
sendJson(res, 404, { ok: false, error: "unknown path" });
|
|
1087
1179
|
};
|
|
1088
1180
|
|
package/lib/market.js
CHANGED
|
@@ -31,9 +31,15 @@ var MAX_PAGES = 30;
|
|
|
31
31
|
var FETCH_TIMEOUT_MS = 20000;
|
|
32
32
|
var CACHE_TTL_MS = 24 * 3600 * 1000;
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
// 通用性铁律:不写死开发者本机路径。
|
|
35
|
+
// node 用当前宿主进程可执行文件;npx-cli 从 node 同目录推导;
|
|
36
|
+
// uvx 按 uv 官方默认安装位置(%USERPROFILE%\.local\bin)与 LOCALAPPDATA 探测,最后退化为 PATH 上的 uvx。
|
|
37
|
+
var DEFAULT_NODE_EXE = process.execPath || "";
|
|
38
|
+
var DEFAULT_NPX_CLI = "";
|
|
39
|
+
var DEFAULT_UVX = (function () {
|
|
40
|
+
var home = process.env.USERPROFILE || process.env.HOME || "";
|
|
41
|
+
return home ? join(home, ".local", "bin", "uvx.exe") : "";
|
|
42
|
+
})();
|
|
37
43
|
|
|
38
44
|
// ─────────────────────────── 19 大类定义(契约严格指定 id/label/icon) ───────────────────────────
|
|
39
45
|
// 每条挂一组分类关键词(中英都覆盖);打分 = 命中词长,长词优先,
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// selfupdate.js - shared "is there a newer version / install it" service.
|
|
2
|
+
//
|
|
3
|
+
// WHY ONE CENTRAL SERVICE INSTEAD OF 13 COPIES
|
|
4
|
+
// Every UI plugin in this family ships its own host half, but they all run in the
|
|
5
|
+
// same host process and are served from the same origin. Implementing the check
|
|
6
|
+
// 13 times would mean 13 code paths to keep in sync and 13 chances to get the
|
|
7
|
+
// npm/pnpm invocation wrong. So the logic lives here once, and dsh-skill-browser
|
|
8
|
+
// (the plugin that owns the settings "悬浮球导航" section and is always installed
|
|
9
|
+
// alongside the rest) exposes it as:
|
|
10
|
+
//
|
|
11
|
+
// GET /dsh-skill-browser/plugin-update?pkg=<name>
|
|
12
|
+
// POST /dsh-skill-browser/plugin-update-apply?pkg=<name>
|
|
13
|
+
// GET /dsh-skill-browser/plugin-update-log
|
|
14
|
+
//
|
|
15
|
+
// Each plugin's own panel then shows one line: "当前 vX · 检查更新", calling the
|
|
16
|
+
// root-relative URL above. The user sees a button per plugin; the code is shared.
|
|
17
|
+
//
|
|
18
|
+
// HARD RULES (each one is a bug we refuse to ship)
|
|
19
|
+
// 1. npm registry first (npmmirror, then npmjs). Users install from npm, so npm is
|
|
20
|
+
// the version that actually exists for them.
|
|
21
|
+
// 2. link:/file: installs are refused: those are local development copies and an
|
|
22
|
+
// npm install would overwrite the working tree.
|
|
23
|
+
// 3. profile package.json is backed up before any write; installs run with
|
|
24
|
+
// windowsHide (this family must never show a console window).
|
|
25
|
+
// 4. Never restart DSH: host code only reloads on a full app restart, so every
|
|
26
|
+
// response carries needRestart and the UI states it in plain words.
|
|
27
|
+
// 5. Registry answers are cached 10 minutes; repeated panel opens must not hammer npm.
|
|
28
|
+
|
|
29
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, copyFileSync, readdirSync } from "node:fs";
|
|
30
|
+
import { join, dirname } from "node:path";
|
|
31
|
+
import { homedir } from "node:os";
|
|
32
|
+
import { execFile } from "node:child_process";
|
|
33
|
+
import { get as httpsGet } from "node:https";
|
|
34
|
+
|
|
35
|
+
var CACHE_TTL_MS = 10 * 60 * 1000;
|
|
36
|
+
var CACHE = {}; // pkg -> { at, latest, registry }
|
|
37
|
+
var LAST_LOG = "";
|
|
38
|
+
var APPLYING = {};
|
|
39
|
+
|
|
40
|
+
function readJsonFile(file, dflt) {
|
|
41
|
+
try {
|
|
42
|
+
var raw = readFileSync(file, "utf8");
|
|
43
|
+
if (raw.charCodeAt(0) === 0xfeff) raw = raw.slice(1);
|
|
44
|
+
return JSON.parse(raw);
|
|
45
|
+
} catch (e) { return dflt; }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getJson(url, timeoutMs) {
|
|
49
|
+
return new Promise(function (resolve) {
|
|
50
|
+
var req = httpsGet(url, { headers: { accept: "application/json", "user-agent": "dsh-plugin-selfupdate" } }, function (res) {
|
|
51
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
52
|
+
res.resume();
|
|
53
|
+
return resolve(getJson(res.headers.location, timeoutMs));
|
|
54
|
+
}
|
|
55
|
+
var chunks = [];
|
|
56
|
+
res.on("data", function (c) { chunks.push(c); });
|
|
57
|
+
res.on("end", function () {
|
|
58
|
+
if (res.statusCode !== 200) return resolve({ ok: false, error: "HTTP " + res.statusCode });
|
|
59
|
+
try { resolve({ ok: true, body: JSON.parse(Buffer.concat(chunks).toString("utf8")) }); }
|
|
60
|
+
catch (e) { resolve({ ok: false, error: "bad json" }); }
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
req.on("error", function (e) { resolve({ ok: false, error: String(e && e.message || e) }); });
|
|
64
|
+
req.setTimeout(timeoutMs || 8000, function () { try { req.destroy(); } catch (e) {} resolve({ ok: false, error: "timeout" }); });
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function compareVer(a, b) {
|
|
69
|
+
var norm = function (v) {
|
|
70
|
+
return String(v || "").replace(/^v/i, "").split(/[.+-]/).map(function (x) { return parseInt(x, 10) || 0; });
|
|
71
|
+
};
|
|
72
|
+
var pa = norm(a), pb = norm(b);
|
|
73
|
+
for (var i = 0; i < Math.max(pa.length, pb.length, 3); i++) {
|
|
74
|
+
var d = (pa[i] || 0) - (pb[i] || 0);
|
|
75
|
+
if (d) return d > 0 ? 1 : -1;
|
|
76
|
+
}
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Candidate install roots, most specific first. The aggregate suite copy wins over
|
|
81
|
+
// npm's hoisted copy because that is what the running process actually loaded.
|
|
82
|
+
function pkgRootCandidates(pkgName) {
|
|
83
|
+
var out = [];
|
|
84
|
+
var home = homedir();
|
|
85
|
+
var profiles = ["desktop", "xiufu", "web"];
|
|
86
|
+
profiles.forEach(function (pf) {
|
|
87
|
+
out.push(join(home, ".dsh", "profiles", pf, "node_modules", pkgName));
|
|
88
|
+
out.push(join(home, ".dsh", "profiles", pf, "node_modules", "dsh-loyalchiiina-plugin-pack", "node_modules", pkgName));
|
|
89
|
+
});
|
|
90
|
+
out.push(join(home, ".dsh", "local-plugins", "dsh-loyalchiiina-suite", "node_modules", pkgName));
|
|
91
|
+
out.push(join(home, ".dsh", "local-plugins", pkgName));
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function resolvePkgRoot(pkgName) {
|
|
96
|
+
var cands = pkgRootCandidates(pkgName);
|
|
97
|
+
for (var i = 0; i < cands.length; i++) {
|
|
98
|
+
if (existsSync(join(cands[i], "package.json"))) return cands[i];
|
|
99
|
+
}
|
|
100
|
+
return "";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function localVersion(pkgRoot, fallback) {
|
|
104
|
+
var pj = pkgRoot ? readJsonFile(join(pkgRoot, "package.json"), null) : null;
|
|
105
|
+
return (pj && pj.version) ? String(pj.version) : String(fallback || "0.0.0");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Is this package a real npm dependency of a profile, or a local link/file copy?
|
|
109
|
+
// The profile package.json is the only reliable witness; node_modules alone looks
|
|
110
|
+
// identical in both cases.
|
|
111
|
+
export function detectInstall(pkgName) {
|
|
112
|
+
var cands = [];
|
|
113
|
+
try {
|
|
114
|
+
var home = homedir();
|
|
115
|
+
["desktop", "xiufu", "web"].forEach(function (pf) {
|
|
116
|
+
cands.push(join(home, ".dsh", "profiles", pf, "package.json"));
|
|
117
|
+
});
|
|
118
|
+
} catch (e) { /* ignore */ }
|
|
119
|
+
for (var j = 0; j < cands.length; j++) {
|
|
120
|
+
var pj = readJsonFile(cands[j], null);
|
|
121
|
+
if (pj && pj.dependencies && Object.prototype.hasOwnProperty.call(pj.dependencies, pkgName)) {
|
|
122
|
+
var spec = String(pj.dependencies[pkgName] || "");
|
|
123
|
+
var isLocal = spec.indexOf("link:") === 0 || spec.indexOf("file:") === 0 || spec.indexOf(".") === 0 || spec.indexOf("/") === 0 || spec.indexOf("local-plugins") >= 0;
|
|
124
|
+
return { installType: isLocal ? "local" : "registry", depSpec: spec, profileFile: cands[j], profileDir: dirname(cands[j]) };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Sub-plugins of the aggregate pack are not direct profile dependencies: the
|
|
128
|
+
// profile depends on dsh-loyalchiiina-plugin-pack, whose own dependencies carry
|
|
129
|
+
// the sub-plugin versions. Without this branch every bundled plugin reports
|
|
130
|
+
// "unknown", which is exactly the confusing answer we want to avoid.
|
|
131
|
+
var PACK = "dsh-loyalchiiina-plugin-pack";
|
|
132
|
+
for (var k = 0; k < cands.length; k++) {
|
|
133
|
+
var pjp = readJsonFile(cands[k], null);
|
|
134
|
+
if (pjp && pjp.dependencies && Object.prototype.hasOwnProperty.call(pjp.dependencies, PACK)) {
|
|
135
|
+
var packSpec = String(pjp.dependencies[PACK] || "");
|
|
136
|
+
var packDir = join(dirname(cands[k]), "node_modules", PACK);
|
|
137
|
+
var packPj = readJsonFile(join(packDir, "package.json"), null);
|
|
138
|
+
if (packPj && packPj.dependencies && Object.prototype.hasOwnProperty.call(packPj.dependencies, pkgName)) {
|
|
139
|
+
var subSpec = String(packPj.dependencies[pkgName] || "");
|
|
140
|
+
var packLocal = packSpec.indexOf("link:") === 0 || packSpec.indexOf("file:") === 0 || packSpec.indexOf(".") === 0 || packSpec.indexOf("/") === 0 || packSpec.indexOf("local-plugins") >= 0;
|
|
141
|
+
return {
|
|
142
|
+
installType: packLocal ? "bundle-local" : "bundle",
|
|
143
|
+
depSpec: subSpec, packSpec: packSpec, packDir: packDir,
|
|
144
|
+
profileFile: cands[k], profileDir: dirname(cands[k])
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return { installType: "unknown", depSpec: "", profileFile: "", profileDir: "" };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function fetchLatest(pkgName) {
|
|
153
|
+
var cached = CACHE[pkgName];
|
|
154
|
+
if (cached && Date.now() - cached.at < CACHE_TTL_MS) return { ok: true, latest: cached.latest, registry: cached.registry };
|
|
155
|
+
var registries = ["https://registry.npmmirror.com", "https://registry.npmjs.org"];
|
|
156
|
+
var lastErr = null;
|
|
157
|
+
for (var i = 0; i < registries.length; i++) {
|
|
158
|
+
var url = registries[i] + "/" + pkgName.replace("/", "%2f") + "/latest";
|
|
159
|
+
var r = await getJson(url, 8000);
|
|
160
|
+
if (r.ok && r.body && r.body.version) {
|
|
161
|
+
var latest = String(r.body.version);
|
|
162
|
+
CACHE[pkgName] = { at: Date.now(), latest: latest, registry: registries[i] };
|
|
163
|
+
return { ok: true, latest: latest, registry: registries[i] };
|
|
164
|
+
}
|
|
165
|
+
lastErr = r.error || "no version";
|
|
166
|
+
}
|
|
167
|
+
return { ok: false, error: lastErr || "registry unreachable" };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function backupProfile(profileFile) {
|
|
171
|
+
try {
|
|
172
|
+
if (!profileFile || !existsSync(profileFile)) return "";
|
|
173
|
+
var dir = join(homedir(), ".dsh", "backups");
|
|
174
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
175
|
+
var stamp = new Date().toISOString().replace(/[-:T]/g, "").slice(0, 15);
|
|
176
|
+
var dst = join(dir, "selfupdate-" + stamp + "-" + profileFile.split(/[\\/]/).pop());
|
|
177
|
+
copyFileSync(profileFile, dst);
|
|
178
|
+
return dst;
|
|
179
|
+
} catch (e) { return ""; }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function checkUpdate(pkgName) {
|
|
183
|
+
var root = resolvePkgRoot(pkgName);
|
|
184
|
+
if (!root) return { ok: false, error: "找不到该插件的安装目录:" + pkgName };
|
|
185
|
+
var current = localVersion(root, "0.0.0");
|
|
186
|
+
var install = detectInstall(pkgName);
|
|
187
|
+
var r = await fetchLatest(pkgName);
|
|
188
|
+
if (!r.ok) return { ok: false, error: r.error, name: pkgName, current: current, installType: install.installType };
|
|
189
|
+
return {
|
|
190
|
+
ok: true, name: pkgName, current: current, latest: r.latest,
|
|
191
|
+
hasUpdate: compareVer(r.latest, current) > 0,
|
|
192
|
+
installType: install.installType, depSpec: install.depSpec,
|
|
193
|
+
source: r.registry, needRestart: true,
|
|
194
|
+
note: install.installType === "local"
|
|
195
|
+
? "本地开发版(" + (install.depSpec || "link") + "),npm 安装会覆盖本地改动,按钮只提示不覆盖"
|
|
196
|
+
: install.installType === "bundle-local"
|
|
197
|
+
? "随套件安装的本地开发版(套件 " + (install.packSpec || "link") + "),更新请改源码后重新发布"
|
|
198
|
+
: install.installType === "bundle"
|
|
199
|
+
? "随套件安装(" + (install.depSpec || "") + "),点更新会升级套件里这个插件的版本"
|
|
200
|
+
: (install.installType === "registry" ? "npm 安装,可一键更新" : "未在 profile 依赖中找到,可能随聚合包统一管理")
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export async function applyUpdate(pkgName) {
|
|
205
|
+
if (APPLYING[pkgName]) return { ok: false, error: "该插件已有一个更新在跑,请稍候" };
|
|
206
|
+
var install = detectInstall(pkgName);
|
|
207
|
+
if (install.installType === "local" || install.installType === "bundle-local") {
|
|
208
|
+
return {
|
|
209
|
+
ok: false, refused: install.installType,
|
|
210
|
+
error: "本地开发版(" + (install.depSpec || "link") + "),不做 npm 覆盖安装。",
|
|
211
|
+
hint: "发布新版到 npm 后,把 profile 依赖改成 registry 版本,这个按钮就能真装。"
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
if (install.installType === "unknown") return { ok: false, error: "未在 profile 依赖中找到该插件,无法确定安装位置" };
|
|
215
|
+
var r = await fetchLatest(pkgName);
|
|
216
|
+
if (!r.ok) return { ok: false, error: "查询最新版失败:" + r.error };
|
|
217
|
+
var current = localVersion(resolvePkgRoot(pkgName), "0.0.0");
|
|
218
|
+
if (compareVer(r.latest, current) <= 0) return { ok: true, upToDate: true, current: current, latest: r.latest };
|
|
219
|
+
var backup = backupProfile(install.profileFile);
|
|
220
|
+
APPLYING[pkgName] = true;
|
|
221
|
+
if (install.installType === "bundle") {
|
|
222
|
+
// The sub-plugin is not a profile dependency; the pack pins it. Bump the pin
|
|
223
|
+
// inside the pack's own package.json, then let pnpm reconcile node_modules.
|
|
224
|
+
var bump = bumpPackDependency(install.packDir, pkgName, r.latest);
|
|
225
|
+
if (!bump.ok) { APPLYING[pkgName] = false; return { ok: false, error: bump.error, backup: backup }; }
|
|
226
|
+
var rb = await runPm("pnpm", ["install"], install.packDir);
|
|
227
|
+
APPLYING[pkgName] = false;
|
|
228
|
+
LAST_LOG = rb.log || "";
|
|
229
|
+
return {
|
|
230
|
+
ok: rb.ok, from: current, latest: r.latest, packageManager: "pnpm",
|
|
231
|
+
via: "bundle", packBackup: bump.backup, needRestart: true, backup: backup,
|
|
232
|
+
log: LAST_LOG.slice(-4000),
|
|
233
|
+
error: rb.ok ? undefined : "套件安装失败,见日志"
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
var spec = pkgName + "@" + r.latest;
|
|
237
|
+
var dir = install.profileDir;
|
|
238
|
+
var r1 = await runPm("pnpm", ["add", spec], dir);
|
|
239
|
+
var used = "pnpm", log = r1.log;
|
|
240
|
+
if (!r1.ok) {
|
|
241
|
+
var r2 = await runPm("npm", ["install", spec, "--no-audit", "--no-fund"], dir);
|
|
242
|
+
used = "npm"; log = r2.log;
|
|
243
|
+
if (!r2.ok) {
|
|
244
|
+
APPLYING[pkgName] = false;
|
|
245
|
+
LAST_LOG = String(r1.log || "") + "\n----\n" + String(r2.log || "");
|
|
246
|
+
return { ok: false, error: "安装失败,见日志", log: LAST_LOG.slice(-4000), backup: backup };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
APPLYING[pkgName] = false;
|
|
250
|
+
LAST_LOG = log || "";
|
|
251
|
+
return {
|
|
252
|
+
ok: true, from: current, latest: r.latest, packageManager: used,
|
|
253
|
+
installedOnDisk: guessDiskVersion(dir, pkgName) || r.latest,
|
|
254
|
+
needRestart: true, backup: backup, log: LAST_LOG.slice(-4000)
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Rewrite only the one dependency line inside the pack's package.json, keeping the
|
|
259
|
+
// rest of the file byte-identical (indent, key order). Returns a backup path.
|
|
260
|
+
function bumpPackDependency(packDir, pkgName, latest) {
|
|
261
|
+
try {
|
|
262
|
+
var file = join(packDir, "package.json");
|
|
263
|
+
var raw = readFileSync(file, "utf8");
|
|
264
|
+
var re = new RegExp('("' + pkgName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + '"\\s*:\\s*")([^"]*)(")');
|
|
265
|
+
if (!re.test(raw)) return { ok: false, error: "套件 package.json 里没有该插件依赖" };
|
|
266
|
+
var dir = join(homedir(), ".dsh", "backups");
|
|
267
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
268
|
+
var stamp = new Date().toISOString().replace(/[-:T]/g, "").slice(0, 15);
|
|
269
|
+
var bak = join(dir, "selfupdate-pack-" + stamp + "-package.json");
|
|
270
|
+
copyFileSync(file, bak);
|
|
271
|
+
var next = raw.replace(re, function (m, a, v, c) { return a + "^" + latest + c; });
|
|
272
|
+
writeFileSync(file, next, "utf8");
|
|
273
|
+
return { ok: true, backup: bak };
|
|
274
|
+
} catch (e) {
|
|
275
|
+
return { ok: false, error: String(e && e.message || e) };
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function lastLog() { return LAST_LOG || "(暂无日志)"; }
|
|
280
|
+
|
|
281
|
+
function guessDiskVersion(profileDir, pkgName) {
|
|
282
|
+
try {
|
|
283
|
+
var pj = readJsonFile(join(profileDir, "node_modules", pkgName, "package.json"), null);
|
|
284
|
+
return pj && pj.version ? String(pj.version) : "";
|
|
285
|
+
} catch (e) { return ""; }
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function runPm(cmd, args, cwd) {
|
|
289
|
+
return new Promise(function (resolve) {
|
|
290
|
+
execFile(cmd, args, {
|
|
291
|
+
cwd: cwd || undefined,
|
|
292
|
+
windowsHide: true,
|
|
293
|
+
timeout: 180000,
|
|
294
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
295
|
+
shell: process.platform === "win32"
|
|
296
|
+
}, function (err, stdout, stderr) {
|
|
297
|
+
resolve({ ok: !err, log: String(stdout || "") + String(stderr || "") });
|
|
298
|
+
});
|
|
299
|
+
});
|
|
300
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-skill-browser",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.5",
|
|
4
4
|
"description": "技能浏览器:悬浮球打开面板,把本机技能库变成可浏览、可检索、可治理的资产——五个 Tab(技能浏览/调用台账/MCP 管理/市场/快速上手)、树状/平铺双视图、手动+关键词+AI 三种分组(分组只改视图不动技能文件)、调用台账看板(调用次数/成功率/趋势图/技能调用排行)、130 款三球同步皮肤(6 列宽屏菜单)、9 步快速上手、MCP 管理(读取运行时 MCP 配置、真实连接状态、工具清单与自动功能概括、调用统计落盘、启停即时跟随/重连/卸载/导出标准 mcpServers JSON、重绘不跳顶且面板记忆上次滚动位置、卡片每行列数技能 3~6 / MCP 3~5)、DSH 设置页悬浮球导航分区;一键热重载,技能库位置可配置,悬浮球可拖拽可复位、市场(MCP 市场:官方 Registry + 29 条精选免费目录、19 大类平铺分类带每类数量、网格/列表双模式、卡片逐字复刻技能卡、每条 MCP 用其自身真实图标并自动降级、一键安装写入 cordis.patch.yml 并自动备份、一键卸载、仅免费筛选、24 小时磁盘缓存、与 MCP 页双向即时同步)。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
package/screenshots.json
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
[
|
|
2
|
-
"docs/images/shot-01.png",
|
|
3
|
-
"docs/images/shot-09.png",
|
|
4
|
-
"docs/images/shot-06.png",
|
|
5
|
-
"docs/images/shot-05.png",
|
|
6
|
-
"docs/images/shot-10.png",
|
|
7
2
|
"docs/images/shot-11.png",
|
|
3
|
+
"docs/images/shot-06.png",
|
|
8
4
|
"docs/images/shot-12.png",
|
|
9
|
-
"docs/images/shot-13.png"
|
|
5
|
+
"docs/images/shot-13.png",
|
|
6
|
+
"docs/images/shot-05.png",
|
|
7
|
+
"docs/images/shot-01.png"
|
|
10
8
|
]
|