From 4da6d2eaf4df0e3779fc9deb975254f4bd67d03f 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 14:19:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=91=E5=B8=83=201.1.54=EF=BC=8C?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E6=A1=8C=E9=9D=A2=E5=90=AF=E5=8A=A8=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=20INACTIVE=5FEFFECT=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/index.js | 82 ++++++++++++++++++++++++++++++---- lib/settle-policy.js | 43 ++++++++++++++++++ package.json | 2 +- release-notes.md | 16 +++++++ scripts/test-settle-policy.mjs | 50 +++++++++++++++++++++ 7 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 lib/settle-policy.js create mode 100644 scripts/test-settle-policy.mjs diff --git a/README.md b/README.md index 6e7cdec..9af6d38 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

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

-

Version 1.1.53

+

Version 1.1.54

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.53**. 1.1.45 is skipped; it has bugs. +The plugin version is **1.1.54**. 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.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 +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.54&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.53', + version: '1.1.54', 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.53` | Semver | +| version | `1.1.54` | 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 832f149..0b6034f 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,7 +4,7 @@

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

-

Version 1.1.53

+

Version 1.1.54

本机官方 DeepSeek Harness 网络安全红队评测插件。清洗宿主策略,并带内嵌演练台。不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐ @@ -118,7 +118,7 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审 | 官方 Harness 0.1.x | 不支持 | | 其它未列出版本 | 对不上的补丁会显示待应用或跳过,不要指望能用 | -插件版本是 **1.1.53**。1.1.45 有问题,略过。 +插件版本是 **1.1.54**。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.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 +dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.54&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.53', + version: '1.1.54', 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.53` | 语义化版本号 | +| version | `1.1.54` | 语义化版本号 | | repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 | | permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 | | downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 | diff --git a/lib/index.js b/lib/index.js index cdf9129..e36a64b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -19,6 +19,13 @@ import * as continueRetry from "./continue-retry.js"; import * as uninstaller from "./uninstall.js"; import { installRegionGate, readAllowText, writeAllowText } from "./net-scope.js"; import * as refusalRecover from "./refusal-recover.js"; +import { + isInactiveContextError, + settleDelayMs, + settleMayReapply, + settleMayRestart, + watchContextLife, +} from "./settle-policy.js"; export const name = "dsh-purge"; @@ -391,7 +398,14 @@ function shimNeedsPatch(state) { ); } -async function settleInstalledPatches(config, ctx) { +function currentSettleScope() { + let sealed = false; + try { sealed = core.desktopAsarStillSealed(); } catch { /* 非桌面或还没定位安装目录 */ } + return { surface: hostctl.currentSurface(), sealed }; +} + +async function settleInstalledPatches(config, ctx, life) { + if (life && !life.alive) return "skip:inactive"; try { core.rememberUnpackedArchive(); } catch { /* 没有官方安装目录时不必记归档 */ } try { reapply.ensureInstalledRevSeed(); @@ -404,17 +418,24 @@ async function settleInstalledPatches(config, ctx) { log(config, "heal applied stamp failed:", String(e && e.message ? e.message : e)); } + const scope = currentSettleScope(); if (!reapply.patchesMatchInstall()) { + if (!settleMayReapply(scope)) { + log(config, "sealed desktop: skip startup reapply (wait for Apply)"); + return "skip:sealed-wait-apply"; + } if (officialUpdate.upgradeMarkerExists(process.execPath)) { const upgraded = await reapply.reapplyInstalled({ scheduleSwap: false, upgrade: true }); + if (life && !life.alive) return "skip:inactive"; 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)"); + if (!settleMayRestart(currentSettleScope()) || reapply.shouldSkipSettleRestart()) { + if (upgraded.needsFullQuit) bootFullQuit = true; + log(config, "official upgrade reapplied; skip settle restart"); return "reapplied-no-restart"; } reapply.markSettleRestart(); @@ -428,7 +449,9 @@ async function settleInstalledPatches(config, ctx) { return "restarting"; } - const result = await reapply.reapplyInstalled(); + // 启动自愈只写盘,不 swap asar / 不杀进程,避免官方 Host Fiber._reload 撞 INACTIVE_EFFECT。 + const result = await reapply.reapplyInstalled({ scheduleSwap: false }); + if (life && !life.alive) return "skip:inactive"; if (!result.ok) { log(config, "reapply failed:", result.error || ""); return "reapply-failed"; @@ -440,6 +463,10 @@ async function settleInstalledPatches(config, ctx) { log(config, "reapply wrote patches; official host needs a full quit"); return "full-quit"; } + if (!settleMayRestart(currentSettleScope())) { + log(config, "reapply wrote patches; desktop settle does not restart"); + return "reapplied-no-restart"; + } if (reapply.shouldSkipSettleRestart()) { log(config, "reapply wrote patches; skip settle restart (cooldown)"); return "reapplied-no-restart"; @@ -467,7 +494,7 @@ async function settleInstalledPatches(config, ctx) { .then((r) => { log(config, "auto-update:", JSON.stringify(r)); if (r && r.needsFullQuit) bootFullQuit = true; - if (r && r.restartAfter) { + if (r && r.restartAfter && settleMayRestart(currentSettleScope())) { try { hostctl.scheduleRestart(null, ctx, { openBrowser: false }); } catch (e) { console.warn("[dsh-purge] auto-update restart failed:", e); } @@ -867,6 +894,11 @@ async function handleSkillsCommand(rawInput) { export function apply(ctx, config) { const cfg = { ...DEFAULTS, ...(config || {}) }; if (!cfg.enabled) return; + const life = watchContextLife(ctx); + if (!life.alive) { + console.warn("[dsh-purge] skip apply: inactive context"); + return; + } log(cfg, "plugin enabled"); try { @@ -883,14 +915,34 @@ export function apply(ctx, config) { console.warn("[dsh-purge] desktop runtime scrub error:", String(e)); } - setImmediate(() => { - settleInstalledPatches(cfg, ctx) + const settleTimer = setTimeout(() => { + if (!life.alive) { + log(cfg, "settle skipped: inactive context"); + return; + } + settleInstalledPatches(cfg, ctx, life) .then((r) => log(cfg, "settle:", r)) - .catch((e) => console.warn("[dsh-purge] settle error:", String(e))); + .catch((e) => { + if (isInactiveContextError(e)) { + log(cfg, "settle skipped: inactive context"); + return; + } + console.warn("[dsh-purge] settle error:", String(e)); + }); rules.ensureInitialState(core.findDshHome()) .then((r) => log(cfg, "rules init:", JSON.stringify(r))) .catch((e) => console.warn("[dsh-purge] rules init error:", String(e))); - }); + }, settleDelayMs(hostctl.currentSurface())); + try { + ctx.effect(() => () => clearTimeout(settleTimer)); + } catch (e) { + if (isInactiveContextError(e)) { + clearTimeout(settleTimer); + console.warn("[dsh-purge] skip apply: inactive context"); + return; + } + throw e; + } try { core.seedOverrideSync(core.findDshHome()); @@ -901,6 +953,18 @@ export function apply(ctx, config) { core.installOverride(core.findDshHome(), false).catch((e) => { console.warn("[dsh-purge] install override error:", String(e)); }); + try { + applyHostHooks(ctx, cfg); + } catch (e) { + if (isInactiveContextError(e)) { + console.warn("[dsh-purge] skip apply: inactive context"); + return; + } + throw e; + } +} + +function applyHostHooks(ctx, cfg) { installIdentityOverride(ctx, cfg); installRegionGate(ctx); try { diff --git a/lib/settle-policy.js b/lib/settle-policy.js new file mode 100644 index 0000000..7a09f82 --- /dev/null +++ b/lib/settle-policy.js @@ -0,0 +1,43 @@ +/** 官方桌面启动时 Fiber._reload 还在挂 desktop-office,settle 不得解包/杀进程。 */ + +export const DESKTOP_SETTLE_DELAY_MS = 4000; + +export function isInactiveContextError(error) { + if (!error) return false; + if (error.code === "INACTIVE_EFFECT") return true; + return /inactive context/i.test(String(error.message || error)); +} + +export function watchContextLife(ctx) { + const life = { alive: true }; + if (!ctx || typeof ctx.effect !== "function") return life; + try { + ctx.effect(() => () => { + life.alive = false; + }); + } catch (error) { + if (isInactiveContextError(error)) { + life.alive = false; + return life; + } + throw error; + } + return life; +} + +export function settleDelayMs(surface) { + return surface === "desktop" ? DESKTOP_SETTLE_DELAY_MS : 0; +} + +/** 桌面启动自愈不得 requestRestart / taskkill,否则 Cordis 会 INACTIVE_EFFECT。 */ +export function settleMayRestart({ surface, sealed = false } = {}) { + if (surface === "desktop") return false; + if (sealed) return false; + return true; +} + +/** 密封 asar 上就地 extract/swap 会和官方 Host 的 Fiber._reload 抢锁。 */ +export function settleMayReapply({ surface, sealed = false } = {}) { + if (surface === "desktop" && sealed) return false; + return true; +} diff --git a/package.json b/package.json index 558f976..5975e0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dsh-purge", - "version": "1.1.53", + "version": "1.1.54", "description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,内嵌演练台;不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐", "type": "module", "main": "lib/index.js", diff --git a/release-notes.md b/release-notes.md index 5a18ece..94d9abc 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,19 @@ +# 1.1.54 + +## 中文 + +- 版本升级到 1.1.54。 +- 官方桌面密封 asar 启动不再中途解包/杀进程:避开 Host Fiber._reload 的 INACTIVE_EFFECT / DesktopHostFatalError;补丁留给设置页「应用」。 +- 桌面 settle 延后并在 context 停用时退出;启动自愈只写盘、不 scheduleRestart(#59 / #60 / #61)。 +- 市场 tar 安装与空 sha / 缺 installed-rev 的无限重启修复仍在(#58–#61,1.1.53)。 + +## English + +- Version 1.1.54. +- Official desktop no longer unpacks or kills the host mid-boot on a sealed asar; that raced Fiber._reload and threw INACTIVE_EFFECT / DesktopHostFatalError. Patches wait for Settings Apply. +- Desktop settle is delayed and aborts on an inactive context; startup self-heal writes files only and does not scheduleRestart (#59 / #60 / #61). +- Marketplace tarball install and empty-sha / missing installed-rev restart loops remain fixed (#58–#61, 1.1.53). + # 1.1.53 ## 中文 diff --git a/scripts/test-settle-policy.mjs b/scripts/test-settle-policy.mjs new file mode 100644 index 0000000..7df8a05 --- /dev/null +++ b/scripts/test-settle-policy.mjs @@ -0,0 +1,50 @@ +import assert from "node:assert/strict"; +import { + DESKTOP_SETTLE_DELAY_MS, + isInactiveContextError, + settleDelayMs, + settleMayReapply, + settleMayRestart, + watchContextLife, +} from "../lib/settle-policy.js"; + +assert.equal(settleMayRestart({ surface: "desktop", sealed: false }), false); +assert.equal(settleMayRestart({ surface: "desktop", sealed: true }), false); +assert.equal(settleMayRestart({ surface: "web", sealed: true }), false); +assert.equal(settleMayRestart({ surface: "web", sealed: false }), true); + +assert.equal(settleMayReapply({ surface: "desktop", sealed: true }), false); +assert.equal(settleMayReapply({ surface: "desktop", sealed: false }), true); +assert.equal(settleMayReapply({ surface: "web", sealed: false }), true); + +assert.equal(settleDelayMs("desktop"), DESKTOP_SETTLE_DELAY_MS); +assert.equal(settleDelayMs("web"), 0); +assert.ok(DESKTOP_SETTLE_DELAY_MS >= 3000); + +assert.equal(isInactiveContextError({ code: "INACTIVE_EFFECT" }), true); +assert.equal(isInactiveContextError(new Error("cannot create effect on inactive context")), true); +assert.equal(isInactiveContextError(new Error("ENOENT")), false); + +const missing = watchContextLife(null); +assert.equal(missing.alive, true); + +let disposed = null; +const active = watchContextLife({ + effect(factory) { + disposed = factory(); + }, +}); +assert.equal(active.alive, true); +disposed(); +assert.equal(active.alive, false); + +const inactive = watchContextLife({ + effect() { + const err = new Error("cannot create effect on inactive context"); + err.code = "INACTIVE_EFFECT"; + throw err; + }, +}); +assert.equal(inactive.alive, false); + +console.log("ok: settle policy / inactive-context guards");