From c67b012bd71c20e53da5552a1c26dc3fbb3dc92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AB=E6=88=91=E5=B0=8F=E6=9D=A8=E5=90=8C=E5=AD=A6?= Date: Sat, 3 Oct 2026 13:54:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=91=E5=B8=83=201.1.53=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=BA=94=E7=94=A8=E5=90=8E=E6=97=A0=E9=99=90=E9=87=8D?= =?UTF-8?q?=E5=90=AF=E4=B8=8E=E5=B8=82=E5=9C=BA=20git=20=E5=AE=89=E8=A3=85?= =?UTF-8?q?=EF=BC=88#58=E2=80=93#61=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- README.md | 14 +-- README.zh-CN.md | 14 +-- lib/desktop.js | 2 +- lib/host.js | 4 +- lib/index.js | 67 +++++++++---- lib/reapply.js | 165 +++++++++++++++++++++++++++++---- lib/restart-web.js | 13 ++- lib/web.js | 11 ++- package.json | 11 ++- release-notes.md | 18 ++++ scripts/test-reapply-stamp.mjs | 65 +++++++++++++ 11 files changed, 325 insertions(+), 59 deletions(-) create mode 100644 scripts/test-reapply-stamp.mjs diff --git a/README.md b/README.md index 649c200..6e7cdec 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)

-

Version 1.1.52

+

Version 1.1.53

Local official DeepSeek Harness cybersecurity red-team plugin. Clean host policy, and ship a built-in drill console. Swap prompts per model. Default prompt for Chinese models — 小码酱. Please star ⭐ @@ -118,7 +118,7 @@ This release supports **DeepSeek Harness 0.2** only (official desktop **0.2.0-rc | Official Harness 0.1.x | Not supported | | Any other version | Unmatched patches stay pending or skipped; do not expect them to work | -The plugin version is **1.1.52**. 1.1.45 is skipped; it has bugs. +The plugin version is **1.1.53**. 1.1.45 is skipped; it has bugs. --- @@ -220,13 +220,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv

🌐 Open Hub page  ·  - 🚀 Install in desktop client + 🚀 Install in desktop client

🔗 **Raw protocol URL:** ``` -dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.52&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.53&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz ```
@@ -242,7 +242,7 @@ export function installDshPurgeToDesktop() { const params = new URLSearchParams({ id: 'dsh-purge', name: 'dsh-purge', - version: '1.1.52', + version: '1.1.53', repo: 'YuJunZhiXue/dsh-purge', permissions: '系统提示词注入, 本机补丁, 设置页', downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz', @@ -261,7 +261,7 @@ export function installDshPurgeToDesktop() { **HTML link:** ```html - + 🚀 Install in desktop client ``` @@ -272,7 +272,7 @@ export function installDshPurgeToDesktop() { |---|---|---| | id | `dsh-purge` | Plugin id | | name | `dsh-purge` | Display name | -| version | `1.1.52` | Semver | +| version | `1.1.53` | Semver | | repo | `YuJunZhiXue/dsh-purge` | GitHub repo | | permissions | `系统提示词注入, 本机补丁, 设置页` | Requested permissions | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub source archive | diff --git a/README.zh-CN.md b/README.zh-CN.md index 6ea42be..832f149 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@

⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)

-

Version 1.1.52

+

Version 1.1.53

本机官方 DeepSeek Harness 网络安全红队评测插件。清洗宿主策略,并带内嵌演练台。不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐ @@ -118,7 +118,7 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审 | 官方 Harness 0.1.x | 不支持 | | 其它未列出版本 | 对不上的补丁会显示待应用或跳过,不要指望能用 | -插件版本是 **1.1.52**。1.1.45 有问题,略过。 +插件版本是 **1.1.53**。1.1.45 有问题,略过。 --- @@ -220,13 +220,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv

🌐 打开插件市场页  ·  - 🚀 唤起客户端一键安装 + 🚀 唤起客户端一键安装

🔗 **原生协议链接:** ``` -dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.52&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.53&repo=YuJunZhiXue%2Fdsh-purge&permissions=%E7%B3%BB%E7%BB%9F%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%B3%A8%E5%85%A5%2C%E6%9C%AC%E6%9C%BA%E8%A1%A5%E4%B8%81%2C%E8%AE%BE%E7%BD%AE%E9%A1%B5&downloadUrl=https%3A%2F%2Fgithub.com%2FYuJunZhiXue%2Fdsh-purge%2Farchive%2Frefs%2Fheads%2Fmaster.tar.gz ```
@@ -242,7 +242,7 @@ export function installDshPurgeToDesktop() { const params = new URLSearchParams({ id: 'dsh-purge', name: 'dsh-purge', - version: '1.1.52', + version: '1.1.53', repo: 'YuJunZhiXue/dsh-purge', permissions: '系统提示词注入, 本机补丁, 设置页', downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz', @@ -261,7 +261,7 @@ export function installDshPurgeToDesktop() { **HTML 静态链接方式:** ```html - + 🚀 唤起客户端一键安装 ``` @@ -272,7 +272,7 @@ export function installDshPurgeToDesktop() { |---|---|---| | id | `dsh-purge` | 插件唯一标识符 | | name | `dsh-purge` | 插件展示名称 | -| version | `1.1.52` | 语义化版本号 | +| version | `1.1.53` | 语义化版本号 | | repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 | | permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 | diff --git a/lib/desktop.js b/lib/desktop.js index 62396c8..a424ad0 100644 --- a/lib/desktop.js +++ b/lib/desktop.js @@ -1045,7 +1045,7 @@ function dshHomeForRelaunch() { return current; } -export function scheduleRestart(request, ctx) { +export function scheduleRestart(request, ctx, _options = {}) { const exe = officialExeFromProcess() || findDesktopAppExecutable() || diff --git a/lib/host.js b/lib/host.js index 302f7db..c9eec96 100644 --- a/lib/host.js +++ b/lib/host.js @@ -15,8 +15,8 @@ export function hostAdapter(kind = detectSurface()) { return ADAPTERS[adapterFor(kind)] || web; } -export function scheduleRestart(request, ctx) { - return hostAdapter().scheduleRestart(request, ctx); +export function scheduleRestart(request, ctx, options = {}) { + return hostAdapter().scheduleRestart(request, ctx, options); } export function scheduleCleanupRestart(opts) { diff --git a/lib/index.js b/lib/index.js index 8ca61a8..cdf9129 100644 --- a/lib/index.js +++ b/lib/index.js @@ -393,43 +393,74 @@ function shimNeedsPatch(state) { async function settleInstalledPatches(config, ctx) { try { core.rememberUnpackedArchive(); } catch { /* 没有官方安装目录时不必记归档 */ } - if (officialUpdate.upgradeMarkerExists(process.execPath)) { - const upgraded = await reapply.reapplyInstalled({ scheduleSwap: false, upgrade: true }); - if (!upgraded.ok) { - log(config, "official upgrade reapply failed:", upgraded.error || ""); - return "reapply-failed"; - } - officialUpdate.clearUpgradeMarker(process.execPath); - officialUpdate.clearStaleExtractedApps(process.execPath); - log(config, "official upgrade reapplied; restarting onto the new build"); - try { - hostctl.scheduleRestart(null, ctx); - } catch (e) { - log(config, "restart after official upgrade failed:", String(e && e.message ? e.message : e)); - return "restart-failed"; - } - return "restarting"; + try { + reapply.ensureInstalledRevSeed(); + } catch (e) { + log(config, "seed installed-rev failed:", String(e && e.message ? e.message : e)); } + try { + if (reapply.healEmptyAppliedStamp()) log(config, "healed empty applied stamp"); + } catch (e) { + log(config, "heal applied stamp failed:", String(e && e.message ? e.message : e)); + } + if (!reapply.patchesMatchInstall()) { + if (officialUpdate.upgradeMarkerExists(process.execPath)) { + const upgraded = await reapply.reapplyInstalled({ scheduleSwap: false, upgrade: true }); + if (!upgraded.ok) { + log(config, "official upgrade reapply failed:", upgraded.error || ""); + return "reapply-failed"; + } + officialUpdate.clearUpgradeMarker(process.execPath); + officialUpdate.clearStaleExtractedApps(process.execPath); + if (reapply.shouldSkipSettleRestart()) { + log(config, "official upgrade reapplied; skip settle restart (cooldown)"); + return "reapplied-no-restart"; + } + reapply.markSettleRestart(); + log(config, "official upgrade reapplied; restarting onto the new build"); + try { + hostctl.scheduleRestart(null, ctx, { openBrowser: false }); + } catch (e) { + log(config, "restart after official upgrade failed:", String(e && e.message ? e.message : e)); + return "restart-failed"; + } + return "restarting"; + } + const result = await reapply.reapplyInstalled(); if (!result.ok) { log(config, "reapply failed:", result.error || ""); return "reapply-failed"; } + // reapply 成功后强制保证非空戳,避免 clean 路径漏写又空转(#59/#60)。 + try { reapply.markPatchesApplied(); } catch { /* ignore */ } if (result.needsFullQuit) { bootFullQuit = true; log(config, "reapply wrote patches; official host needs a full quit"); return "full-quit"; } + if (reapply.shouldSkipSettleRestart()) { + log(config, "reapply wrote patches; skip settle restart (cooldown)"); + return "reapplied-no-restart"; + } + // 已对齐则不必再重启;只在 stamp/宿主仍不一致时重启一次。 + if (reapply.patchesMatchInstall()) { + log(config, "reapply wrote patches; already aligned, no restart"); + return "reapplied"; + } + reapply.markSettleRestart(); log(config, "reapply wrote patches; restarting"); try { - hostctl.scheduleRestart(null, ctx); + // web:自愈重启不弹浏览器,关窗后不应再被反复拉起新窗口(#59/#61)。 + hostctl.scheduleRestart(null, ctx, { openBrowser: false }); } catch (e) { log(config, "restart after reapply failed:", String(e && e.message ? e.message : e)); return "restart-failed"; } return "restarting"; } + const applied = await autoApply(config); if (config.autoUpdateOnStart === true) { updater.autoUpdateIfNeeded() @@ -437,7 +468,7 @@ async function settleInstalledPatches(config, ctx) { log(config, "auto-update:", JSON.stringify(r)); if (r && r.needsFullQuit) bootFullQuit = true; if (r && r.restartAfter) { - try { hostctl.scheduleRestart(null, ctx); } catch (e) { + try { hostctl.scheduleRestart(null, ctx, { openBrowser: false }); } catch (e) { console.warn("[dsh-purge] auto-update restart failed:", e); } } diff --git a/lib/reapply.js b/lib/reapply.js index 4518b3d..204e2d9 100644 --- a/lib/reapply.js +++ b/lib/reapply.js @@ -14,9 +14,13 @@ function pluginVersion() { } } +function installedRevPath() { + return path.join(core.findDshHome(), "dsh-purge", "installed-rev"); +} + function installedRev() { try { - return fs.readFileSync(path.join(core.findDshHome(), "dsh-purge", "installed-rev"), "utf8").trim(); + return fs.readFileSync(installedRevPath(), "utf8").trim(); } catch { return ""; } @@ -26,6 +30,10 @@ function appliedStampPath() { return path.join(core.findDshHome(), "dsh-purge", "applied.json"); } +function settleGuardPath() { + return path.join(core.findDshHome(), "dsh-purge", "settle-restart.guard"); +} + export function readAppliedStamp() { try { const raw = JSON.parse(fs.readFileSync(appliedStampPath(), "utf8")); @@ -43,16 +51,56 @@ function sameRev(a, b) { return a === b || a.startsWith(b) || b.startsWith(a); } +function isApplyPlaceholder(sha) { + const text = String(sha || ""); + return text.startsWith("apply:") || text === "applied"; +} + +/** 手动应用未必写过 installed-rev;空 sha 会让 settle 永远判未对齐并无限重启。 */ +export function resolveApplySha(explicit) { + const wanted = String(explicit == null ? "" : explicit).trim(); + if (wanted) return wanted; + const rev = installedRev(); + if (rev) return rev; + const ver = pluginVersion(); + return ver ? `apply:${ver}` : "applied"; +} + +function writeInstalledRev(sha) { + const value = String(sha || "").trim(); + if (!value) return; + const fp = installedRevPath(); + fs.mkdirSync(path.dirname(fp), { recursive: true }); + fs.writeFileSync(fp, `${value}\n`, "utf8"); +} + +function writeAppliedStamp(sha) { + const fp = appliedStampPath(); + fs.mkdirSync(path.dirname(fp), { recursive: true }); + fs.writeFileSync(fp, `${JSON.stringify({ + version: pluginVersion(), + sha: String(sha || "").trim(), + at: new Date().toISOString(), + }, null, 2)}\n`, "utf8"); +} + /** 当前插件版本和已写入补丁的版本一致时,启动不必再还原重打。 */ export function stampMatches(stamp, version, rev) { if (!stamp || !stamp.version || stamp.version !== version) return false; // sha 为空表示 stamp 不完整(曾误写空串),不能当作已对齐(#56)。 if (!stamp.sha) return false; - if (rev && !sameRev(rev, stamp.sha)) return false; + const current = String(rev || "").trim(); + if (!current) return true; + // 手动应用占位戳与后续 git rev 并存时,只认 version,避免再空转重启。 + if (isApplyPlaceholder(stamp.sha) || isApplyPlaceholder(current)) return true; + if (!sameRev(current, stamp.sha)) return false; return true; } -/** stamp 对上了,但宿主被官方更新打回 sealed / 找不到插件根时仍算未对齐(#57)。 */ +/** + * stamp 对上了,但宿主被官方更新打回 sealed / 清洗标记没了时仍算未对齐(#57)。 + * 找不到插件根(web 启动早期、纯 CLI)不等于补丁丢失,否则会无限重打+重启(#59)。 + */ export function hostStillHasAppliedPatches() { try { if (core.desktopAsarStillSealed()) return false; @@ -60,10 +108,18 @@ export function hostStillHasAppliedPatches() { /* 非桌面面 */ } try { - if (!core.findAiBase()) return false; + const aiBase = core.findAiBase(); + if (!aiBase) return true; + return core.hostCleanMarkersPresent(aiBase); } catch { - return false; + return true; } +} + +/** 空 sha 只有在「不是密封、也不是明确缺标记」时才允许就地补戳。 */ +export function canHealEmptyStamp({ sealed = false, hasAiBase = false, markersPresent = false } = {}) { + if (sealed) return false; + if (hasAiBase && !markersPresent) return false; return true; } @@ -72,26 +128,97 @@ export function patchesMatchInstall() { return hostStillHasAppliedPatches(); } -/** 有 applied 戳但宿主已密封/丢根:面板提示「补丁已丢失」。 */ +/** 有 applied 戳但宿主已回到密封 asar / 清洗标记没了:面板提示「补丁已丢失」(#57)。找不到根不算丢失。 */ export function patchesLostAfterHostReset() { const stamp = readAppliedStamp(); if (!stamp?.version || !stamp?.sha) return false; - return !hostStillHasAppliedPatches(); -} - -function writeAppliedStamp(sha) { - const fp = appliedStampPath(); - fs.mkdirSync(path.dirname(fp), { recursive: true }); - fs.writeFileSync(fp, `${JSON.stringify({ - version: pluginVersion(), - sha: sha || "", - at: new Date().toISOString(), - }, null, 2)}\n`, "utf8"); + try { + if (core.desktopAsarStillSealed()) return true; + } catch { + /* 非桌面面 */ + } + try { + const aiBase = core.findAiBase(); + if (aiBase && !core.hostCleanMarkersPresent(aiBase)) return true; + } catch { + /* ignore */ + } + return false; } /** 手动「应用」成功后也要打戳,否则重启后 settle 会以为补丁未对齐再要求重启。 */ export function markPatchesApplied(sha) { - writeAppliedStamp(sha == null ? installedRev() : sha); + const resolved = resolveApplySha(sha); + const current = installedRev(); + // 已有更新通道写入的 git rev 时沿用;否则用 resolve 结果(含 apply:version 占位)。 + const finalSha = current && !isApplyPlaceholder(current) ? current : resolved; + writeInstalledRev(finalSha); + writeAppliedStamp(finalSha); + return finalSha; +} + +/** + * #59/#60:空 sha 或缺失 installed-rev 会让 settle 每次启动都 reapply+restart。 + * 版本已对齐时先补非空戳 / 种子 rev,打断自重启;真正缺补丁再由后续逻辑重打。 + */ +export function healEmptyAppliedStamp() { + const stamp = readAppliedStamp(); + const version = pluginVersion(); + if (!stamp || stamp.version !== version) return false; + if (stamp.sha) { + if (!installedRev()) writeInstalledRev(stamp.sha); + return false; + } + let sealed = false; + try { sealed = core.desktopAsarStillSealed(); } catch { /* ignore */ } + let hasAiBase = false; + let markersPresent = false; + try { + const aiBase = core.findAiBase(); + hasAiBase = Boolean(aiBase); + markersPresent = Boolean(aiBase && core.hostCleanMarkersPresent(aiBase)); + } catch { + /* 根还没定位 */ + } + // 密封或明确没打上清洗标记:不能补戳装成已对齐,否则 #57 不再自愈。 + if (!canHealEmptyStamp({ sealed, hasAiBase, markersPresent })) return false; + markPatchesApplied(); + return true; +} + +/** 安装后还没有 installed-rev 时先落盘占位(tarball / 手动应用常见)。 */ +export function ensureInstalledRevSeed() { + const current = installedRev(); + if (current) return current; + const stamp = readAppliedStamp(); + if (stamp?.sha) { + writeInstalledRev(stamp.sha); + return stamp.sha; + } + const sha = resolveApplySha(); + writeInstalledRev(sha); + return sha; +} + +/** settle 刚重启过则冷却,防止「重打→重启→再重打」打成死循环。 */ +export function shouldSkipSettleRestart(windowMs = 180000) { + try { + const raw = JSON.parse(fs.readFileSync(settleGuardPath(), "utf8")); + if (String(raw.version || "") !== pluginVersion()) return false; + const at = Date.parse(String(raw.at || "")) || 0; + return at > 0 && Date.now() - at < windowMs; + } catch { + return false; + } +} + +export function markSettleRestart() { + const fp = settleGuardPath(); + fs.mkdirSync(path.dirname(fp), { recursive: true }); + fs.writeFileSync(fp, `${JSON.stringify({ + version: pluginVersion(), + at: new Date().toISOString(), + }, null, 2)}\n`, "utf8"); } /** @@ -148,7 +275,7 @@ export async function reapplyInstalled(options = {}) { }; } if (clean) { - writeAppliedStamp(installedRev()); + markPatchesApplied(installedRev() || undefined); if (freshExtract?.archive) core.writeUnpackedAsarStamp(freshExtract.archive); } let renamed = false; diff --git a/lib/restart-web.js b/lib/restart-web.js index ec5d669..d2c7398 100644 --- a/lib/restart-web.js +++ b/lib/restart-web.js @@ -77,20 +77,27 @@ const child = spawn(info.execPath, info.argv, { shell: false, }); child.on("error", () => process.exit(1)); +const wantBrowser = info.openBrowser !== false; const takeUrl = (chunk) => { const text = String(chunk || ""); if (opened) return; const match = text.match(/dsh web:\s+(https?:\/\/\S+)/); if (!match) return; opened = true; + if (!wantBrowser) return; const url = match[1].replace(/[),.;]+$/, ""); openBrowser(url); }; child.stdout?.on("data", takeUrl); child.stderr?.on("data", takeUrl); child.unref(); -const started = Date.now(); -while (!opened && Date.now() - started < 20000) { - await new Promise((r) => setTimeout(r, 200)); +if (wantBrowser) { + const started = Date.now(); + while (!opened && Date.now() - started < 20000) { + await new Promise((r) => setTimeout(r, 200)); + } +} else { + // 等子进程真正起来再退出,避免端口未监听时父链误判失败又拉一把。 + await new Promise((r) => setTimeout(r, 1500)); } process.exit(0); diff --git a/lib/web.js b/lib/web.js index c8726c6..290d77a 100644 --- a/lib/web.js +++ b/lib/web.js @@ -68,7 +68,14 @@ function spawnRestartHelper(helper, payload, exitAfter = 250) { setTimeout(() => process.exit(0), exitAfter); } -export function scheduleRestart(request) { +/** + * @param {object} [request] + * @param {unknown} [_ctx] + * @param {{ openBrowser?: boolean }} [options] + * settle / 自愈重启传 request=null → 默认不弹浏览器,避免关窗后仍被反复拉起新窗口(#59/#61)。 + */ +export function scheduleRestart(request, _ctx, options = {}) { + const openBrowser = options.openBrowser ?? (request != null); const helper = fileURLToPath(new URL("./restart-web.js", import.meta.url)); spawnRestartHelper(helper, { kind: "web", @@ -78,6 +85,7 @@ export function scheduleRestart(request) { host: hostFromRequest(request), port: portFromRequest(request), pid: process.pid, + openBrowser: openBrowser !== false, }); } @@ -94,5 +102,6 @@ export function scheduleCleanupRestart({ request, restartArgv: argv, cleanup = [ port: portFromRequest(request), cleanup, helper: dest, + openBrowser: request != null, }, 400); } diff --git a/package.json b/package.json index 8140cef..558f976 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-purge", - "version": "1.1.52", + "version": "1.1.53", "description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,内嵌演练台;不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐", "type": "module", "main": "lib/index.js", @@ -74,8 +74,17 @@ "@deepseek-ai/dsh-client-ui-slots", "@deepseek-ai/dsh-client-ui-settings" ] + }, + "install": { + "preferred": "tarball", + "tarball": "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz", + "zip": "https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.zip", + "git": "https://github.com/YuJunZhiXue/dsh-purge.git" } }, + "publishConfig": { + "access": "public" + }, "peerDependencies": { "@deepseek-ai/cordis": "^4.0.1" }, diff --git a/release-notes.md b/release-notes.md index be7e67e..5a18ece 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,21 @@ +# 1.1.53 + +## 中文 + +- 版本升级到 1.1.53。 +- 修复点「应用」后无限重启(#59 / #60 / #61):tarball 安装没有 `installed-rev`、或 `applied.json` 空 sha 时,启动不再反复 reapply+restart;对齐后不再空转重启,并加冷却。 +- web 自愈重启不再自动弹浏览器,关窗后不会再被反复拉起新窗口(#59 / #61)。 +- 空 sha 只在非密封、且清洗标记还在(或找不到插件根)时补戳,避免冲掉密封宿主自愈(#56 / #57)。 +- 市场安装:`package.json` 标明优先 tar.gz/zip,避免 Hub 退回 `git ls-remote` 失败(#58)。 + +## English + +- Version 1.1.53. +- Stop Apply/startup infinite restart (#59 / #60 / #61): missing `installed-rev` after tarball install or empty `applied.json` sha no longer reapply+restart every boot; skip restart once aligned, with a cooldown. +- Web self-heal restart does not open a browser, so closing the window no longer respawns tabs (#59 / #61). +- Empty-sha heal only runs when the host is not sealed and markers are present (or the plugin root is missing), so sealed-host self-heal still works (#56 / #57). +- Marketplace install prefers tar.gz/zip in `package.json` so Hub does not fall back to a failing `git ls-remote` (#58). + # 1.1.52 ## 中文 diff --git a/scripts/test-reapply-stamp.mjs b/scripts/test-reapply-stamp.mjs new file mode 100644 index 0000000..4cffd04 --- /dev/null +++ b/scripts/test-reapply-stamp.mjs @@ -0,0 +1,65 @@ +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "dsh-purge-stamp-")); +process.env.DSH_HOME = tmp; + +const { + stampMatches, + resolveApplySha, + markPatchesApplied, + readAppliedStamp, + healEmptyAppliedStamp, + ensureInstalledRevSeed, + shouldSkipSettleRestart, + markSettleRestart, + canHealEmptyStamp, +} = await import("../lib/reapply.js"); + +assert.equal(stampMatches({ version: "1.1.52", sha: "" }, "1.1.52", "abc"), false); +assert.equal(stampMatches({ version: "1.1.52", sha: "abc" }, "1.1.52", "abc"), true); +assert.equal(stampMatches({ version: "1.1.52", sha: "abc" }, "1.1.52", ""), true); +assert.equal(stampMatches({ version: "1.1.52", sha: "apply:1.1.52" }, "1.1.52", "deadbeef"), true); +assert.equal(stampMatches({ version: "1.1.52", sha: "abc" }, "1.1.52", "def"), false); +assert.equal(stampMatches({ version: "1.1.51", sha: "abc" }, "1.1.52", "abc"), false); + +// #56:空 sha 仍不能当对齐;#57:密封/缺标记不能就地补戳。 +assert.equal(canHealEmptyStamp({ sealed: true, hasAiBase: true, markersPresent: true }), false); +assert.equal(canHealEmptyStamp({ sealed: false, hasAiBase: true, markersPresent: false }), false); +assert.equal(canHealEmptyStamp({ sealed: false, hasAiBase: true, markersPresent: true }), true); +assert.equal(canHealEmptyStamp({ sealed: false, hasAiBase: false, markersPresent: false }), true); + +assert.equal(resolveApplySha("deadbeef"), "deadbeef"); +assert.match(resolveApplySha(""), /^(apply:|applied)/); + +const sha = markPatchesApplied(); +assert.ok(sha); +assert.ok(sha.length > 0); +const stamp = readAppliedStamp(); +assert.equal(stamp.sha, sha); +assert.ok(stamp.sha); +const revFile = path.join(tmp, "dsh-purge", "installed-rev"); +assert.equal(fs.readFileSync(revFile, "utf8").trim(), sha); +assert.equal(stampMatches(stamp, stamp.version, sha), true); + +fs.writeFileSync(path.join(tmp, "dsh-purge", "applied.json"), `${JSON.stringify({ + version: stamp.version, + sha: "", + at: new Date().toISOString(), +}, null, 2)}\n`); +assert.equal(healEmptyAppliedStamp(), true); +assert.ok(readAppliedStamp().sha); + +// #60:缺 installed-rev 时种子 +fs.rmSync(path.join(tmp, "dsh-purge", "installed-rev"), { force: true }); +const seeded = ensureInstalledRevSeed(); +assert.ok(seeded); +assert.equal(fs.readFileSync(path.join(tmp, "dsh-purge", "installed-rev"), "utf8").trim(), seeded); + +assert.equal(shouldSkipSettleRestart(), false); +markSettleRestart(); +assert.equal(shouldSkipSettleRestart(), true); + +console.log("ok: reapply stamp / infinite-restart guards");