feat: 0.6.0 - update check and one-command upgrade
Answers: when I ship a new version, how does the user find out, and what do they do about it. Three ways to learn: 1. moyun_ultimate_profile now returns an update block: current, latest, available, notes, howTo, page. 2. New tool moyun_check_update (force: true re-queries). 3. On startup the plugin checks the latest release in the background and logs a line when a newer version exists. One command to upgrade: powershell -ExecutionPolicy Bypass -File .\update.ps1 It queries the release, downloads the tgz, backs up the current directories as *.bak-update-<stamp>, extracts over them, and PRESERVES the user's mode choice (complement stays complement, it is not clobbered into full). Variants: -Check (report only), -Force (reinstall), -DryRun (dry run). Opt out with checkUpdate: false in the bundle patch. Version comparison is numeric per segment so 0.10.0 > 0.9.9. Network failure degrades quietly; startup is not blocked (8s timeout, background promise).
This commit is contained in:
parent
d18db479b7
commit
4b9eb3c1ff
119
index.js
119
index.js
@ -83,6 +83,83 @@ function readOwnVersion() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ── 更新检查:比对本地版本与仓库最新 Release ─────────────────────────
|
||||||
|
const UPDATE_API =
|
||||||
|
"https://git.lingdongjiansuo.cn/api/v1/repos/moyun/moyun-ultimate/releases/latest";
|
||||||
|
const UPDATE_PAGE = "https://git.lingdongjiansuo.cn/moyun/moyun-ultimate/releases";
|
||||||
|
|
||||||
|
let updateCache = { checked: false, latest: null, name: null, url: null, error: null };
|
||||||
|
|
||||||
|
function cmpVersion(a, b) {
|
||||||
|
const pa = String(a || "0").replace(/^v/i, "").split(".").map((x) => parseInt(x, 10) || 0);
|
||||||
|
const pb = String(b || "0").replace(/^v/i, "").split(".").map((x) => parseInt(x, 10) || 0);
|
||||||
|
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
||||||
|
const x = pa[i] || 0;
|
||||||
|
const y = pb[i] || 0;
|
||||||
|
if (x > y) return 1;
|
||||||
|
if (x < y) return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkUpdate(force = false) {
|
||||||
|
if (updateCache.checked && !force) return updateCache;
|
||||||
|
try {
|
||||||
|
const res = await fetch(UPDATE_API, {
|
||||||
|
headers: { "User-Agent": "moyun-ultimate/" + readOwnVersion() },
|
||||||
|
signal: AbortSignal.timeout(8000),
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error("HTTP " + res.status);
|
||||||
|
const j = await res.json();
|
||||||
|
updateCache = {
|
||||||
|
checked: true,
|
||||||
|
latest: j.tag_name || null,
|
||||||
|
name: j.name || null,
|
||||||
|
url: j.html_url || UPDATE_PAGE,
|
||||||
|
error: null,
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
updateCache = {
|
||||||
|
checked: true,
|
||||||
|
latest: null,
|
||||||
|
name: null,
|
||||||
|
url: UPDATE_PAGE,
|
||||||
|
error: String((e && e.message) || e),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return updateCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateStatus() {
|
||||||
|
const current = readOwnVersion();
|
||||||
|
if (!updateCache.checked) {
|
||||||
|
return { current, checked: false, latest: null, available: null, note: "尚未检查(后台检查中,或网络不可达)" };
|
||||||
|
}
|
||||||
|
if (updateCache.error) {
|
||||||
|
return {
|
||||||
|
current,
|
||||||
|
checked: true,
|
||||||
|
latest: null,
|
||||||
|
available: null,
|
||||||
|
error: updateCache.error,
|
||||||
|
note: "无法连接更新服务器;不影响使用,可手动看 " + UPDATE_PAGE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const avail = cmpVersion(updateCache.latest, current) > 0;
|
||||||
|
return {
|
||||||
|
current,
|
||||||
|
checked: true,
|
||||||
|
latest: updateCache.latest,
|
||||||
|
available: avail,
|
||||||
|
notes: avail
|
||||||
|
? "有新版本 " + updateCache.latest + "(当前 " + current + ")"
|
||||||
|
: "已是最新",
|
||||||
|
howTo: avail ? "powershell -ExecutionPolicy Bypass -File .\\update.ps1" : null,
|
||||||
|
page: updateCache.url,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// ── 环境诊断:找出当前 profile、检测配置覆盖与同类插件 ──────────────────
|
// ── 环境诊断:找出当前 profile、检测配置覆盖与同类插件 ──────────────────
|
||||||
const CONFLICT_IDS = ["sandbox-policy", "approval", "permission", "spill-policy", "tool-result-pruner"];
|
const CONFLICT_IDS = ["sandbox-policy", "approval", "permission", "spill-policy", "tool-result-pruner"];
|
||||||
// 只重叠 system-prompt 的算「轻微重叠」:都是改身份/人设前缀,谁后应用谁赢,效果差异很小。
|
// 只重叠 system-prompt 的算「轻微重叠」:都是改身份/人设前缀,谁后应用谁赢,效果差异很小。
|
||||||
@ -392,6 +469,7 @@ const profileTool = {
|
|||||||
effective: permissionEffective,
|
effective: permissionEffective,
|
||||||
verdict,
|
verdict,
|
||||||
},
|
},
|
||||||
|
update: updateStatus(),
|
||||||
environment: {
|
environment: {
|
||||||
profile: env.profile,
|
profile: env.profile,
|
||||||
userLayerOverrides: env.userOverrides,
|
userLayerOverrides: env.userOverrides,
|
||||||
@ -462,6 +540,27 @@ const skillsAuditTool = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ── 工具 4:检查更新 ───────────────────────────────────────────────────
|
||||||
|
const updateTool = {
|
||||||
|
name: "moyun_check_update",
|
||||||
|
description:
|
||||||
|
"检查仓库是否有更新版本。返回当前版本、最新版本、以及一条升级命令。" +
|
||||||
|
"网络不可达时如实报告,不影响插件使用。",
|
||||||
|
parameters: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
force: { type: "boolean", description: "强制重新查询(忽略缓存)" },
|
||||||
|
},
|
||||||
|
additionalProperties: false,
|
||||||
|
},
|
||||||
|
output: objectOutput,
|
||||||
|
async execute(args = {}) {
|
||||||
|
await checkUpdate(args.force !== false);
|
||||||
|
return updateStatus();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// ── 技能库自动同步(幂等:只补缺失,不覆盖用户改动)──────────────────
|
// ── 技能库自动同步(幂等:只补缺失,不覆盖用户改动)──────────────────
|
||||||
function syncSkills(dshHome) {
|
function syncSkills(dshHome) {
|
||||||
if (!dshHome) return { synced: 0, skipped: 0 };
|
if (!dshHome) return { synced: 0, skipped: 0 };
|
||||||
@ -586,6 +685,23 @@ export function apply(ctx, config = {}) {
|
|||||||
try { ctx.logger?.info?.(m); } catch {}
|
try { ctx.logger?.info?.(m); } catch {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 后台检查一次更新(不阻塞启动;config.checkUpdate === false 可关闭)
|
||||||
|
if (config.checkUpdate !== false) {
|
||||||
|
const logFn = (m) => {
|
||||||
|
try { ctx.logger?.info?.(m); } catch {}
|
||||||
|
};
|
||||||
|
checkUpdate()
|
||||||
|
.then((u) => {
|
||||||
|
if (u.latest && cmpVersion(u.latest, readOwnVersion()) > 0) {
|
||||||
|
logFn(
|
||||||
|
"moyun-ultimate: 有新版本 " + u.latest + "(当前 " + readOwnVersion() +
|
||||||
|
"),升级:powershell -ExecutionPolicy Bypass -File .\\update.ps1",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
// 分层注入
|
// 分层注入
|
||||||
for (const layer of LAYERS) {
|
for (const layer of LAYERS) {
|
||||||
if (config[layer.key] === false) continue;
|
if (config[layer.key] === false) continue;
|
||||||
@ -598,6 +714,7 @@ export function apply(ctx, config = {}) {
|
|||||||
ctx.effect(() => ctx.tools.register(frameTool));
|
ctx.effect(() => ctx.tools.register(frameTool));
|
||||||
ctx.effect(() => ctx.tools.register(profileTool));
|
ctx.effect(() => ctx.tools.register(profileTool));
|
||||||
ctx.effect(() => ctx.tools.register(skillsAuditTool));
|
ctx.effect(() => ctx.tools.register(skillsAuditTool));
|
||||||
|
ctx.effect(() => ctx.tools.register(updateTool));
|
||||||
|
|
||||||
// 判拒投影
|
// 判拒投影
|
||||||
// 环境诊断结果只算一次(apply 时),随 view 一并下发,供状态条显示真实状态。
|
// 环境诊断结果只算一次(apply 时),随 view 一并下发,供状态条显示真实状态。
|
||||||
@ -644,4 +761,4 @@ export function apply(ctx, config = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 供外部诊断脚本复用(doctor.ps1 的 JS 版、CI 等);不影响插件运行。
|
// 供外部诊断脚本复用(doctor.ps1 的 JS 版、CI 等);不影响插件运行。
|
||||||
export const __diagnostics = { detectConflicts, auditSkills, detectProvider, findProfileDir, readOwnVersion, profileTool, skillsAuditTool };
|
export const __diagnostics = { detectConflicts, auditSkills, detectProvider, findProfileDir, readOwnVersion, checkUpdate, updateStatus, cmpVersion, profileTool, skillsAuditTool, updateTool };
|
||||||
|
|||||||
206
update.ps1
Normal file
206
update.ps1
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
# moyun-ultimate updater (ASCII only - PS 5.1 reads BOM-less UTF-8 as ANSI)
|
||||||
|
#
|
||||||
|
# -Check only report whether a newer version exists
|
||||||
|
# -Force reinstall even if already up to date
|
||||||
|
# -DryRun show what would happen, download nothing
|
||||||
|
#
|
||||||
|
# Keeps your chosen mode: if the installed bundle patch was switched to
|
||||||
|
# COMPLEMENT (a cordis.patch.yml.full exists), the patch is preserved.
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[string]$Profile = 'desktop',
|
||||||
|
[string]$DshHome = '',
|
||||||
|
[switch]$Check,
|
||||||
|
[switch]$Force,
|
||||||
|
[switch]$DryRun
|
||||||
|
)
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
|
||||||
|
$PkgName = 'moyun-ultimate'
|
||||||
|
$Owner = 'moyun'
|
||||||
|
$Repo = 'moyun-ultimate'
|
||||||
|
$Base = 'https://git.lingdongjiansuo.cn'
|
||||||
|
$ApiUrl = "$Base/api/v1/repos/$Owner/$Repo/releases/latest"
|
||||||
|
$RelPage = "$Base/$Owner/$Repo/releases"
|
||||||
|
|
||||||
|
if (-not $DshHome) {
|
||||||
|
if ($env:DSH_HOME) { $DshHome = $env:DSH_HOME }
|
||||||
|
elseif (Test-Path 'G:\DeepSeek_dsh') { $DshHome = 'G:\DeepSeek_dsh' }
|
||||||
|
elseif (Test-Path (Join-Path $env:USERPROFILE '.dsh')) { $DshHome = Join-Path $env:USERPROFILE '.dsh' }
|
||||||
|
else { throw 'DSH_HOME not found. Pass -DshHome <path>.' }
|
||||||
|
}
|
||||||
|
$profileDir = Join-Path $DshHome "profiles\$Profile"
|
||||||
|
$plugDir = Join-Path $profileDir "plugins\$PkgName"
|
||||||
|
$runDir = Join-Path $profileDir "node_modules\$PkgName"
|
||||||
|
|
||||||
|
Write-Output ''
|
||||||
|
Write-Output 'moyun-ultimate updater'
|
||||||
|
Write-Output '======================'
|
||||||
|
|
||||||
|
# ---- current version ----
|
||||||
|
$current = $null
|
||||||
|
$localPkg = Join-Path $runDir 'package.json'
|
||||||
|
if (-not (Test-Path $localPkg)) { $localPkg = Join-Path $plugDir 'package.json' }
|
||||||
|
if (Test-Path $localPkg) {
|
||||||
|
try { $current = (Get-Content -LiteralPath $localPkg -Raw -Encoding UTF8 | ConvertFrom-Json).version } catch {}
|
||||||
|
}
|
||||||
|
if (-not $current) {
|
||||||
|
Write-Output " not installed under $profileDir"
|
||||||
|
Write-Output ' install first: powershell -ExecutionPolicy Bypass -File .\install.ps1'
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Write-Output (" current : " + $current)
|
||||||
|
Write-Output (" source : " + $localPkg)
|
||||||
|
|
||||||
|
# ---- latest release ----
|
||||||
|
try {
|
||||||
|
$rel = Invoke-RestMethod -Uri $ApiUrl -UseBasicParsing -TimeoutSec 25
|
||||||
|
} catch {
|
||||||
|
Write-Output (" cannot reach update server: " + $_.Exception.Message)
|
||||||
|
Write-Output (" check manually: " + $RelPage)
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$latest = ($rel.tag_name -replace '^[vV]', '')
|
||||||
|
Write-Output (" latest : " + $latest + " (" + $rel.name + ")")
|
||||||
|
|
||||||
|
function CmpVer([string]$a, [string]$b) {
|
||||||
|
$pa = ($a -replace '^[vV]', '') -split '\.'
|
||||||
|
$pb = ($b -replace '^[vV]', '') -split '\.'
|
||||||
|
$n = [Math]::Max($pa.Count, $pb.Count)
|
||||||
|
for ($i = 0; $i -lt $n; $i++) {
|
||||||
|
$x = 0; $y = 0
|
||||||
|
if ($i -lt $pa.Count) { [void][int]::TryParse($pa[$i], [ref]$x) }
|
||||||
|
if ($i -lt $pb.Count) { [void][int]::TryParse($pb[$i], [ref]$y) }
|
||||||
|
if ($x -gt $y) { return 1 }
|
||||||
|
if ($x -lt $y) { return -1 }
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
$cmp = CmpVer $latest $current
|
||||||
|
if ($cmp -le 0 -and -not $Force) {
|
||||||
|
Write-Output ''
|
||||||
|
Write-Output (' up to date (' + $current + ')')
|
||||||
|
Write-Output ''
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
if ($cmp -gt 0) { Write-Output (" update available: " + $current + " -> " + $latest) }
|
||||||
|
else { Write-Output (" same or older, reinstalling because -Force") }
|
||||||
|
|
||||||
|
if ($Check) {
|
||||||
|
Write-Output ''
|
||||||
|
Write-Output ' -Check only: nothing was downloaded.'
|
||||||
|
Write-Output (' to upgrade: powershell -ExecutionPolicy Bypass -File .\update.ps1')
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- asset ----
|
||||||
|
$asset = $rel.assets | Where-Object { $_.name -like '*.tgz' } | Select-Object -First 1
|
||||||
|
if (-not $asset) {
|
||||||
|
Write-Output ' no .tgz asset on that release; download manually:'
|
||||||
|
Write-Output (' ' + $rel.html_url)
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Write-Output (" asset : " + $asset.name + " " + $asset.size + " B")
|
||||||
|
if ($DryRun) {
|
||||||
|
Write-Output ''
|
||||||
|
Write-Output ' -DryRun: would download and install the above.'
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- download ----
|
||||||
|
$tmpDir = Join-Path ([IO.Path]::GetTempPath()) ("moyun-up-" + [guid]::NewGuid().ToString('N').Substring(0, 8))
|
||||||
|
New-Item -ItemType Directory -Force -Path $tmpDir | Out-Null
|
||||||
|
$tgz = Join-Path $tmpDir $asset.name
|
||||||
|
Write-Output ' downloading...'
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $tgz -UseBasicParsing -TimeoutSec 180
|
||||||
|
} catch {
|
||||||
|
Write-Output (" download failed: " + $_.Exception.Message)
|
||||||
|
Write-Output (" you can download manually: " + $asset.browser_download_url)
|
||||||
|
Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$got = (Get-Item $tgz).Length
|
||||||
|
Write-Output (" downloaded " + $got + " B")
|
||||||
|
|
||||||
|
# ---- extract ----
|
||||||
|
$ex = Join-Path $tmpDir 'x'
|
||||||
|
New-Item -ItemType Directory -Force -Path $ex | Out-Null
|
||||||
|
try {
|
||||||
|
& tar -xzf $tgz -C $ex 2>&1 | Out-Null
|
||||||
|
} catch {
|
||||||
|
Write-Output ' extract failed (tar missing?)'
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$src = Join-Path $ex 'package'
|
||||||
|
if (-not (Test-Path $src)) {
|
||||||
|
Write-Output ' archive layout unexpected (no package/ dir)'
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
$newVer = 'unknown'
|
||||||
|
try { $newVer = (Get-Content (Join-Path $src 'package.json') -Raw -Encoding UTF8 | ConvertFrom-Json).version } catch {}
|
||||||
|
Write-Output (" package version: " + $newVer)
|
||||||
|
|
||||||
|
# ---- remember current mode (complement keeps its patch) ----
|
||||||
|
$keepPatch = $false
|
||||||
|
$patchWasComplement = $false
|
||||||
|
$runPatch = Join-Path $runDir 'cordis.patch.yml'
|
||||||
|
if ((Test-Path (Join-Path $runDir 'cordis.patch.yml.full')) -or (Test-Path (Join-Path $plugDir 'cordis.patch.yml.full'))) {
|
||||||
|
$keepPatch = $true
|
||||||
|
$patchWasComplement = $true
|
||||||
|
}
|
||||||
|
if (Test-Path $runPatch) {
|
||||||
|
$pt = Get-Content $runPatch -Raw -Encoding UTF8
|
||||||
|
if ($pt -match 'COMPLEMENT MODE') { $keepPatch = $true; $patchWasComplement = $true }
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- backup + install ----
|
||||||
|
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
|
||||||
|
foreach ($d in @($plugDir, $runDir)) {
|
||||||
|
if (-not (Test-Path $d)) { continue }
|
||||||
|
$bak = "$d.bak-update-$stamp"
|
||||||
|
Copy-Item $d $bak -Recurse -Force
|
||||||
|
Write-Output (" backup: " + $bak)
|
||||||
|
|
||||||
|
# keep user's patch choice
|
||||||
|
$savedPatch = $null
|
||||||
|
if ($keepPatch) {
|
||||||
|
$p = Join-Path $d 'cordis.patch.yml'
|
||||||
|
if (Test-Path $p) { $savedPatch = Get-Content $p -Raw -Encoding UTF8 }
|
||||||
|
}
|
||||||
|
|
||||||
|
Remove-Item $d -Recurse -Force
|
||||||
|
New-Item -ItemType Directory -Force -Path $d | Out-Null
|
||||||
|
Copy-Item "$src\*" $d -Recurse -Force
|
||||||
|
|
||||||
|
if ($keepPatch -and $savedPatch) {
|
||||||
|
[IO.File]::WriteAllText((Join-Path $d 'cordis.patch.yml'), $savedPatch, (New-Object Text.UTF8Encoding($false)))
|
||||||
|
Write-Output (" kept existing patch (COMPLEMENT mode preserved)")
|
||||||
|
} elseif ($patchWasComplement) {
|
||||||
|
# restore the full copy marker so switch-mode still works
|
||||||
|
$fullSrc = Join-Path $src 'cordis.patch.yml'
|
||||||
|
if (Test-Path $fullSrc) {
|
||||||
|
Copy-Item $fullSrc (Join-Path $d 'cordis.patch.yml.full') -Force
|
||||||
|
}
|
||||||
|
Write-Output (" wrote new full patch as cordis.patch.yml.full")
|
||||||
|
}
|
||||||
|
Write-Output (" updated: " + $d)
|
||||||
|
}
|
||||||
|
|
||||||
|
# ---- package.json registration stays untouched ----
|
||||||
|
Write-Output ''
|
||||||
|
Write-Output (' updated to ' + $newVer + ' (was ' + $current + ')')
|
||||||
|
Write-Output ''
|
||||||
|
Write-Output 'Next:'
|
||||||
|
Write-Output ' 1. Fully quit DSH (including the tray icon), then reopen it.'
|
||||||
|
Write-Output ' 2. Verify: powershell -ExecutionPolicy Bypass -File .\doctor.ps1'
|
||||||
|
Write-Output ''
|
||||||
|
Write-Output 'Rollback this update:'
|
||||||
|
Write-Output (" the previous directories were saved as *" + ".bak-update-" + $stamp)
|
||||||
|
Write-Output ' or reinstall a specific version from the releases page:'
|
||||||
|
Write-Output (" " + $RelPage)
|
||||||
|
|
||||||
|
Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||||
|
exit 0
|
||||||
Loading…
Reference in New Issue
Block a user