dsh-agentone 0.5.7 → 0.5.9
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/lib/index.js +7 -4
- package/lib/proc.js +34 -0
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -32,7 +32,7 @@ import { applyPlatformModel, removePlatformModel } from './model.js';
|
|
|
32
32
|
import { installPlatformSkill, listPlatformSkills, removePlatformSkill } from './skill.js';
|
|
33
33
|
import { platformFetch } from './http.js';
|
|
34
34
|
import { donePageHtml, statusPageHtml } from './page.js';
|
|
35
|
-
import { dshPluginCli, probeCliDetail, pnpmViewLatest, upgradeCliTool } from './proc.js';
|
|
35
|
+
import { compareSemver, dshPluginCli, probeCliDetail, pnpmViewLatest, upgradeCliTool } from './proc.js';
|
|
36
36
|
|
|
37
37
|
import { clearCredentials, loadCredentials, resolveDshHome, saveCredentials, updateCredentials } from './store.js';
|
|
38
38
|
|
|
@@ -373,8 +373,9 @@ async function upgradeProfilePlugin(config, name) {
|
|
|
373
373
|
if (!latest) {
|
|
374
374
|
throw new Error('查询插件最新版本失败,请稍后重试');
|
|
375
375
|
}
|
|
376
|
-
|
|
377
|
-
|
|
376
|
+
// latest dist-tag 可能指向旧版(作者误指/回退),不比已装高就没必要升
|
|
377
|
+
if (latest === current || (current && compareSemver(latest, current) <= 0)) {
|
|
378
|
+
throw new Error(`已是最新版本(v${current ?? latest})`);
|
|
378
379
|
}
|
|
379
380
|
await runPluginCli(['add', `${name}@${latest}`, ...(BUILTIN_PLUGIN_ALLOW_BUILD[name] || [])]);
|
|
380
381
|
const after = await installedVersion(dir, name);
|
|
@@ -851,7 +852,9 @@ export function apply(ctx, config) {
|
|
|
851
852
|
state.plugins
|
|
852
853
|
.filter((item) => item.version !== null && item.source === 'npm')
|
|
853
854
|
.map(async (item) => {
|
|
854
|
-
|
|
855
|
+
const latest = await pnpmViewLatest(item.name, dir).catch(() => null);
|
|
856
|
+
// latest 不高于已装版本时不展示(dist-tag 指旧版 → 不出降级按钮)
|
|
857
|
+
item.latest = latest && compareSemver(latest, item.version) > 0 ? latest : null;
|
|
855
858
|
}),
|
|
856
859
|
);
|
|
857
860
|
sendJson(response, 200, state);
|
package/lib/proc.js
CHANGED
|
@@ -67,6 +67,40 @@ export function parseLatestVersionLine(stdout) {
|
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/** 简版 semver 比较(足够比较 x.y.z[-pre] 形态):
|
|
71
|
+
* 数字段逐位比;预发布 < 正式版;预发布段数字比数字、其余词典序。
|
|
72
|
+
* 用途:包作者把 latest dist-tag 指向旧版时(实测 @deepseek-ai/dsh-mcp-client
|
|
73
|
+
* 的 latest=0.0.1-rc.1 < 已装 0.1.2-alpha.4),避免展示「降级按钮」。 */
|
|
74
|
+
export function compareSemver(a, b) {
|
|
75
|
+
const parse = (v) => {
|
|
76
|
+
const [core, pre] = String(v).split('+')[0].split('-');
|
|
77
|
+
const raw = core.split('.').map((n) => parseInt(n, 10) || 0);
|
|
78
|
+
while (raw.length < 3) raw.push(0); // 「1.2」补齐为「1.2.0」再比
|
|
79
|
+
return { nums: raw, pre: pre === undefined ? null : pre.split('.') };
|
|
80
|
+
};
|
|
81
|
+
const pa = parse(a);
|
|
82
|
+
const pb = parse(b);
|
|
83
|
+
for (let i = 0; i < 3; i += 1) {
|
|
84
|
+
if (pa.nums[i] !== pb.nums[i]) return (pa.nums[i] > pb.nums[i] ? 1 : -1);
|
|
85
|
+
}
|
|
86
|
+
if (pa.pre === pb.pre) return 0;
|
|
87
|
+
if (pa.pre === null) return 1; // 无预发布 > 有预发布
|
|
88
|
+
if (pb.pre === null) return -1;
|
|
89
|
+
for (let i = 0; i < Math.max(pa.pre.length, pb.pre.length); i += 1) {
|
|
90
|
+
const x = pa.pre[i];
|
|
91
|
+
const y = pb.pre[i];
|
|
92
|
+
if (x === y) continue;
|
|
93
|
+
if (x === undefined) return -1;
|
|
94
|
+
if (y === undefined) return 1;
|
|
95
|
+
const xn = /^\d+$/.test(x);
|
|
96
|
+
const yn = /^\d+$/.test(y);
|
|
97
|
+
if (xn && yn) return parseInt(x, 10) > parseInt(y, 10) ? 1 : -1;
|
|
98
|
+
if (xn !== yn) return xn ? -1 : 1; // 数字段 < 字母段
|
|
99
|
+
return x > y ? 1 : -1;
|
|
100
|
+
}
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
70
104
|
/**
|
|
71
105
|
* 查询包在 registry 的最新版本(`pnpm view <name>@latest version`)。
|
|
72
106
|
* 为什么不用 `pnpm outdated` / `update -L` / `add pkg@latest`:实测 pnpm 11
|
package/package.json
CHANGED