diff --git a/README.md b/README.md
index 90270b3..9d42366 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)
-Version 1.1.48
+Version 1.1.49-beta.1
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.48**. 1.1.45 is skipped; it has bugs.
+The plugin version is **1.1.49-beta.1**. 1.1.45 is skipped; it has bugs.
---
@@ -144,6 +144,8 @@ Adding the plugin to a profile does **not** patch `@deepseek-ai` by itself.
Web **Apply / Restart / Uninstall** affect Web only. Desktop controls affect the desktop app only and do not launch `dsh web`. Do not Apply one host from the other.
+> **macOS official desktop:** Apply unpacks `app.asar`. This plugin patches the official `dsh` CLI entry (asar / `app/` fallback) and adds an `app/runtime` link. If you still see `MODULE_NOT_FOUND ... app.asar/.../cli.js`, Apply once more or reinstall Harness.
+
### Web
@@ -218,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.48&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.49-beta.1&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
```
@@ -240,7 +242,7 @@ export function installDshPurgeToDesktop() {
const params = new URLSearchParams({
id: 'dsh-purge',
name: 'dsh-purge',
- version: '1.1.48',
+ version: '1.1.49-beta.1',
repo: 'YuJunZhiXue/dsh-purge',
permissions: '系统提示词注入, 本机补丁, 设置页',
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
@@ -259,7 +261,7 @@ export function installDshPurgeToDesktop() {
**HTML link:**
```html
-
+
🚀 Install in desktop client
```
@@ -270,7 +272,7 @@ export function installDshPurgeToDesktop() {
|---|---|---|
| id | `dsh-purge` | Plugin id |
| name | `dsh-purge` | Display name |
-| version | `1.1.48` | Semver |
+| version | `1.1.49-beta.1` | 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 2f9bd20..cfa825e 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -4,7 +4,7 @@
⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)
-Version 1.1.48
+Version 1.1.49-beta.1
本机官方 DeepSeek Harness 网络安全红队评测插件。清洗宿主策略,并带内嵌演练台。不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐
@@ -118,7 +118,7 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审
| 官方 Harness 0.1.x | 不支持 |
| 其它未列出版本 | 对不上的补丁会显示待应用或跳过,不要指望能用 |
-插件版本是 **1.1.48**。1.1.45 有问题,略过。
+插件版本是 **1.1.49-beta.1**。1.1.45 有问题,略过。
---
@@ -142,6 +142,8 @@ Web、社区桌面端、官方桌面 EXE **分开装、分开应用**。只装
2. 点会话标题旁的 **dsh-purge**,在右侧栏的 **清洗** 里点 **「应用」**。宿主的设置页里没有这个条目。
3. 按提示 **再重启一次**。补丁这时才进入当前进程。点「重启」才会重启,不会装完自动重启。
+> **macOS 官方桌面**:点「应用」会解开 `app.asar`。本插件会自动修补官方 `dsh` CLI 入口(asar / `app/` 双向兼容)并补上 `app/runtime` 链接;若你仍看到 `MODULE_NOT_FOUND ... app.asar/.../cli.js`,再点一次「应用」,或重装 Harness。
+
Web 的「应用 / 重启 / 卸载」只动 Web。桌面端的只动桌面应用,不会去拉 `dsh web`。不要在 Web 里点桌面端的应用,也不要反过来。
@@ -218,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.48&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.49-beta.1&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
```
@@ -240,7 +242,7 @@ export function installDshPurgeToDesktop() {
const params = new URLSearchParams({
id: 'dsh-purge',
name: 'dsh-purge',
- version: '1.1.48',
+ version: '1.1.49-beta.1',
repo: 'YuJunZhiXue/dsh-purge',
permissions: '系统提示词注入, 本机补丁, 设置页',
downloadUrl: 'https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz',
@@ -259,7 +261,7 @@ export function installDshPurgeToDesktop() {
**HTML 静态链接方式:**
```html
-
+
🚀 唤起客户端一键安装
```
@@ -270,7 +272,7 @@ export function installDshPurgeToDesktop() {
|---|---|---|
| id | `dsh-purge` | 插件唯一标识符 |
| name | `dsh-purge` | 插件展示名称 |
-| version | `1.1.48` | 语义化版本号 |
+| version | `1.1.49-beta.1` | 语义化版本号 |
| repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 |
| permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 |
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 |
diff --git a/client.js b/client.js
index 7d9894a..4f99cb6 100644
--- a/client.js
+++ b/client.js
@@ -2462,7 +2462,7 @@ body .dshp-dock[data-theme="white"] .dshp-dock-body .rt-card,body .dshp-dock[dat
if (!d.ok) throw new Error(d.error || "restart failed");
const next = (d && d.surface) || surf;
if ((next === "desktop" || d.fullApp) && d.restarting === false) {
- setNotice({ kind: "error", text: t("restart.fail", { error: d.note || "not started" }) });
+ setNotice({ kind: "error", text: t("restart.fail", { error: d.error || "not started" }) });
setBusy(false);
return;
}
diff --git a/lib/core.js b/lib/core.js
index 0b5a0fe..026f82b 100644
--- a/lib/core.js
+++ b/lib/core.js
@@ -1744,10 +1744,23 @@ export async function openSealedDesktopHost(options = {}) {
restoreUnusableExtract(appDir, prev);
throw new Error(`已解开 ${handoff.asar},但 ${appDir} 下没有 @deepseek-ai`);
}
+ try {
+ desktop.repairOfficialCliAfterUnpack(handoff.exe);
+ } catch (e) {
+ console.warn("[dsh-purge] repair official CLI after unpack failed:", e);
+ }
resetPathMemo();
return { aiBase, swapAsar: true, exe: handoff.exe, asar: handoff.asar, extracted, prev, appDir, archive: extracted ? archive : null };
}
+export function repairOfficialCliAfterUnpack(exe) {
+ try {
+ return desktop.repairOfficialCliAfterUnpack(exe);
+ } catch (e) {
+ return { ok: false, error: String(e && e.message ? e.message : e) };
+ }
+}
+
export function restoreSealedExtract(appDir, prev) {
const saved = prev || newestPreservedDir(appDir);
return restoreExtractedDir(appDir, saved);
diff --git a/lib/desktop.js b/lib/desktop.js
index 1a88f36..b407c61 100644
--- a/lib/desktop.js
+++ b/lib/desktop.js
@@ -910,6 +910,7 @@ const ASAR_RENAME_WHEN_IDLE_SH = [
"lock=$3",
"deadline=$(($(date +%s) + 1800))",
"relaunch() {",
+ " unset ELECTRON_RUN_AS_NODE",
" case \"$(uname -s)\" in",
" Darwin)",
" case \"$exe\" in",
@@ -921,7 +922,6 @@ const ASAR_RENAME_WHEN_IDLE_SH = [
" esac",
" ;;",
" esac",
- " unset ELECTRON_RUN_AS_NODE",
" nohup \"$exe\" >/dev/null 2>&1 &",
"}",
"while [ \"$(date +%s)\" -lt \"$deadline\" ]; do",
@@ -991,6 +991,12 @@ export function scheduleAsarRenameWhenIdle({ exe, asar } = {}) {
/** 等当前桌面进程退出后把 app.asar 挪走,再启动 exe。解开后的 resources\\app 才会被加载。 */
export function scheduleAsarSwapRestart({ exe, asar, waitPid = process.pid, exit = false } = {}) {
if (!exe || !asar) throw new Error("缺少桌面 exe 或 app.asar,无法重启");
+ if (process.platform === "darwin") {
+ const helper = fileURLToPath(new URL("./restart-desktop.js", import.meta.url));
+ spawnHelper(helper, { respawn: true, killApp: true, asar, waitPid }, { exit: false });
+ if (exit !== false) setTimeout(() => process.exit(0), 800);
+ return { scheduled: true };
+ }
if (process.platform !== "win32") return scheduleAsarRenameWhenIdle({ exe, asar });
const script = path.join(os.tmpdir(), `dsh-purge-asar-swap-${process.pid}.ps1`);
fs.writeFileSync(script, ASAR_SWAP_PS1, "utf8");
@@ -1058,10 +1064,11 @@ export function scheduleRestart(request, ctx) {
Promise.resolve(runtime.requestRestart()).catch((err) => {
console.warn("[dsh-purge] desktop requestRestart failed:", err);
});
- return;
+ return { restarting: true };
}
const helper = fileURLToPath(new URL("./restart-desktop.js", import.meta.url));
spawnHelper(helper, { respawn: true, killApp: true }, { exit: false });
+ return { restarting: true };
}
function jsString(value) {
@@ -1198,7 +1205,139 @@ export function scheduleCleanupRestart({ cleanup = [], ctx } = {}) {
Promise.resolve(runtime.requestRestart()).catch((err) => {
console.warn("[dsh-purge] desktop uninstall restart failed:", err);
});
- return;
+ return { restarting: true };
}
spawnHelper(dest, { cleanup, helper: dest, respawn: true, killApp: true }, { exit: false });
+ return { restarting: true };
+}
+
+const CLI_ENTRY_BEGIN = "# dsh-purge cli entry begin";
+const CLI_ENTRY_END = "# dsh-purge cli entry end";
+const CLI_ASAR_ENTRY = "app.asar/dsh/node_modules/@deepseek-ai/dsh-desktop-host/lib/cli.js";
+const CLI_DIR_ENTRY = "app/dsh/node_modules/@deepseek-ai/dsh-desktop-host/lib/cli.js";
+
+function ensureAppRuntimeSymlink(resources) {
+ const appDir = path.join(resources, "app");
+ const runtime = path.join(resources, "runtime");
+ const link = path.join(appDir, "runtime");
+ if (!isDir(appDir) || !isDir(runtime)) return { ok: false, reason: "missing" };
+ try {
+ if (fs.existsSync(link)) {
+ const st = fs.lstatSync(link);
+ if (st.isSymbolicLink() || st.isDirectory()) return { ok: true, already: true };
+ }
+ } catch {
+ // create below
+ }
+ try {
+ try {
+ fs.rmSync(link, { recursive: true, force: true });
+ } catch {
+ // ignore
+ }
+ if (process.platform === "win32") {
+ fs.symlinkSync("..\\runtime", link, "junction");
+ return { ok: true, created: true, type: "junction" };
+ }
+ fs.symlinkSync("../runtime", link, "dir");
+ return { ok: true, created: true, type: "dir" };
+ } catch (e) {
+ return { ok: false, error: String(e && e.message ? e.message : e) };
+ }
+}
+
+function patchOfficialCliShimText(text) {
+ if (!text || !text.includes(CLI_ASAR_ENTRY)) return { changed: false, text };
+ if (text.includes(CLI_ENTRY_BEGIN) && text.includes('"$entry"')) {
+ return { changed: false, text, already: true };
+ }
+ const block = [
+ CLI_ENTRY_BEGIN,
+ `entry="$resources/${CLI_ASAR_ENTRY}"`,
+ 'if [ ! -f "$entry" ]; then',
+ ` entry="$resources/${CLI_DIR_ENTRY}"`,
+ "fi",
+ CLI_ENTRY_END,
+ "",
+ ].join("\n");
+ let next = text;
+ if (!next.includes(CLI_ENTRY_BEGIN)) {
+ const insertAt = next.search(/ELECTRON_RUN_AS_NODE=1/);
+ if (insertAt >= 0) next = `${next.slice(0, insertAt)}${block}${next.slice(insertAt)}`;
+ else next = `${block}${next}`;
+ }
+ next = next.replace(
+ /"\$resources\/app\.asar\/dsh\/node_modules\/@deepseek-ai\/dsh-desktop-host\/lib\/cli\.js"/g,
+ '"$entry"',
+ );
+ next = next.replace(
+ /\$resources\/app\.asar\/dsh\/node_modules\/@deepseek-ai\/dsh-desktop-host\/lib\/cli\.js/g,
+ '"$entry"',
+ );
+ return { changed: next !== text, text: next };
+}
+
+function patchOfficialCliCmdText(text) {
+ if (!text) return { changed: false, text };
+ const hasAsar =
+ text.toLowerCase().includes("app.asar\\dsh\\node_modules\\@deepseek-ai\\dsh-desktop-host\\lib\\cli.js") ||
+ text.includes(CLI_ASAR_ENTRY);
+ if (!hasAsar) return { changed: false, text };
+ if (text.includes("dsh-purge cli entry begin")) return { changed: false, text, already: true };
+ const asarWin = "%resources%\\app.asar\\dsh\\node_modules\\@deepseek-ai\\dsh-desktop-host\\lib\\cli.js";
+ const dirWin = "%resources%\\app\\dsh\\node_modules\\@deepseek-ai\\dsh-desktop-host\\lib\\cli.js";
+ let next = text;
+ const block = [
+ "REM dsh-purge cli entry begin",
+ `set "entry=${asarWin}"`,
+ `if not exist "%entry%" set "entry=${dirWin}"`,
+ "REM dsh-purge cli entry end",
+ "",
+ ].join("\r\n");
+ if (!next.includes("dsh-purge cli entry begin")) next = block + next;
+ next = next.replace(
+ /%resources%\\app\.asar\\dsh\\node_modules\\@deepseek-ai\\dsh-desktop-host\\lib\\cli\.js/gi,
+ "%entry%",
+ );
+ return { changed: next !== text, text: next };
+}
+
+/** 解包 app.asar 后修补官方 CLI:入口回退到 app/,并补 app/runtime → ../runtime。 */
+export function repairOfficialCliAfterUnpack(exe = findDesktopAppExecutable()) {
+ if (!exe || !isOfficialHarnessExecutable(exe)) return { ok: false, reason: "not_official" };
+ const resources = resourcesDirForExecutable(exe);
+ if (!resources || !isDir(resources)) return { ok: false, reason: "no_resources" };
+ const report = { ok: true, resources, symlink: null, shims: [] };
+ report.symlink = ensureAppRuntimeSymlink(resources);
+ const shimPaths = [
+ path.join(resources, "runtime", "cli", "bin", "dsh"),
+ path.join(resources, "runtime", "cli", "bin", "dsh.cmd"),
+ ];
+ for (const fp of shimPaths) {
+ if (!isFile(fp)) {
+ report.shims.push({ path: fp, status: "missing" });
+ continue;
+ }
+ let text = "";
+ try {
+ text = fs.readFileSync(fp, "utf8");
+ } catch (e) {
+ report.shims.push({ path: fp, status: "read_error", error: String(e && e.message ? e.message : e) });
+ continue;
+ }
+ const patched = fp.toLowerCase().endsWith(".cmd")
+ ? patchOfficialCliCmdText(text)
+ : patchOfficialCliShimText(text);
+ if (!patched.changed) {
+ report.shims.push({ path: fp, status: patched.already ? "already" : "skipped" });
+ continue;
+ }
+ try {
+ fs.writeFileSync(fp, patched.text, "utf8");
+ report.shims.push({ path: fp, status: "patched" });
+ } catch (e) {
+ report.shims.push({ path: fp, status: "write_error", error: String(e && e.message ? e.message : e) });
+ }
+ }
+ return report;
}
diff --git a/lib/index.js b/lib/index.js
index 3992246..efafca9 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -109,7 +109,15 @@ function watchWebTreeReady(ctx) {
}
function fsExists(fp) {
- return fsFor(fp).existsSync(fp);
+ const list = Array.isArray(fp) ? fp : [fp];
+ return list.some((p) => {
+ if (!p || typeof p !== "string") return false;
+ try {
+ return fsFor(p).existsSync(p);
+ } catch {
+ return false;
+ }
+ });
}
function line(title, value, ok = null) {
@@ -126,7 +134,9 @@ function renderStatus(state) {
if (state.ai_base) {
out.push(line("插件根 / plugin root", state.ai_base));
for (const [key, fp] of Object.entries(state.files)) {
- out.push(` ${fsExists(fp) ? "✓" : "✗"} ${key.padEnd(22)} ${fp}`);
+ const list = Array.isArray(fp) ? fp : [fp];
+ const shown = list.length <= 1 ? String(list[0] || "") : `${list[0]} (+${list.length - 1})`;
+ out.push(` ${fsExists(fp) ? "✓" : "✗"} ${key.padEnd(22)} ${shown}`);
}
} else {
out.push(line("插件根 / plugin root", core.missingAiBaseMessage(), false));
@@ -1352,6 +1362,12 @@ function installWebServer(ctx, cfg) {
const report = await core.applyPatches(state.ai_base);
const override = await core.readOverrideForUi(state.dsh_home);
const shim = await core.patchAllShims();
+ let cliRepair = null;
+ try {
+ cliRepair = core.repairOfficialCliAfterUnpack();
+ } catch (e) {
+ cliRepair = { ok: false, error: String(e && e.message ? e.message : e) };
+ }
const flash = core.silenceCmdFlash(state.ai_base);
const summary = core.summarizeApplyReport(report);
const complete = summary.failed.length === 0 && flash.ok === true;
@@ -1396,6 +1412,7 @@ function installWebServer(ctx, cfg) {
override_installed: override.installed,
shim,
desktop_scrubbed: scrubbed,
+ cli_repair: cliRepair,
cmd_flash: flash,
});
if (shouldRestart && handoff && core.desktopAsarStillSealed()) {
diff --git a/lib/restart-desktop.js b/lib/restart-desktop.js
index 0e5c5f2..bf80960 100644
--- a/lib/restart-desktop.js
+++ b/lib/restart-desktop.js
@@ -1,4 +1,5 @@
import fs from "node:fs";
+import path from "node:path";
import { execFileSync, spawn } from "node:child_process";
const encoded = process.env.DSH_PURGE_RESTART;
@@ -12,6 +13,18 @@ try {
}
const cleanup = Array.isArray(info.cleanup) ? info.cleanup : [];
+const logPath = path.join(
+ process.env.TEMP || process.env.TMPDIR || "/tmp",
+ "dsh-purge-restart-desktop.log",
+);
+
+function log(msg) {
+ try {
+ fs.appendFileSync(logPath, `${new Date().toISOString()} ${msg}\n`);
+ } catch {
+ // ignore
+ }
+}
function spawnEnv() {
const env = { ...process.env };
@@ -23,6 +36,10 @@ function spawnEnv() {
return env;
}
+function sleep(ms) {
+ return new Promise((r) => setTimeout(r, ms));
+}
+
function pidAlive(pid) {
const n = Number(pid);
if (!n) return false;
@@ -36,12 +53,12 @@ function pidAlive(pid) {
async function waitPidGone(pid) {
if (!pid) {
- await new Promise((r) => setTimeout(r, 400));
+ await sleep(400);
return true;
}
for (let i = 0; i < 80; i++) {
if (!pidAlive(pid)) return true;
- await new Promise((r) => setTimeout(r, 120));
+ await sleep(120);
}
return !pidAlive(pid);
}
@@ -70,7 +87,66 @@ function pidsForImage(image) {
return pids;
}
-function listDesktopPids() {
+function darwinBundleOf(exe) {
+ const n = String(exe || "").replace(/\\/g, "/");
+ const m = n.match(/^(.*\.app)\/Contents\/MacOS\//i);
+ return m ? m[1] : "";
+}
+
+function darwinBundleName(bundle) {
+ if (!bundle) return "";
+ const infoPlist = path.join(bundle, "Contents", "Info.plist");
+ try {
+ return execFileSync("defaults", ["read", path.join(bundle, "Contents", "Info"), "CFBundleName"], {
+ encoding: "utf8",
+ timeout: 5000,
+ }).trim();
+ } catch {
+ // fall through
+ }
+ try {
+ return execFileSync("plutil", ["-extract", "CFBundleName", "raw", infoPlist], {
+ encoding: "utf8",
+ timeout: 5000,
+ }).trim();
+ } catch {
+ return path.basename(bundle, ".app");
+ }
+}
+
+function listDarwinPids(exe) {
+ const bundle = darwinBundleOf(exe);
+ if (!exe || !bundle) return [];
+ let out = "";
+ try {
+ out = execFileSync("ps", ["-Ao", "pid=,command="], {
+ encoding: "utf8",
+ timeout: 8000,
+ });
+ } catch {
+ return [];
+ }
+ const frameworks = `${bundle}/Contents/Frameworks/`;
+ const pids = [];
+ for (const line of String(out || "").split(/\n/)) {
+ const trimmed = line.trim();
+ if (!trimmed) continue;
+ const sp = trimmed.search(/\s/);
+ if (sp < 0) continue;
+ const pid = Number(trimmed.slice(0, sp).trim());
+ const cmd = trimmed.slice(sp + 1).trim();
+ if (!pid) continue;
+ // CLI 独立宿主(dsh web / plugin 等),不占桌面单实例锁,不能一起杀。
+ if (cmd.includes("/dsh-desktop-host/lib/cli.js")) continue;
+ if (cmd === exe || cmd.startsWith(`${exe} `) || cmd.startsWith(frameworks)) {
+ pids.push(pid);
+ }
+ }
+ return [...new Set(pids)];
+}
+
+function listDesktopPids(exe = info.execPath) {
+ if (process.platform === "darwin") return listDarwinPids(exe);
if (process.platform !== "win32") return [];
const images = ["DeepSeek Harness.exe", "DSH Desktop.exe"];
const pids = [];
@@ -84,32 +160,156 @@ function listDesktopPids() {
return pids;
}
-function killOtherDesktopProcesses(keepPid) {
- for (const pid of listDesktopPids()) {
- if (pid === keepPid || pid === process.pid) continue;
+function signalPids(pids, signal) {
+ for (const pid of pids) {
+ if (pid === process.pid) continue;
try {
- process.kill(pid);
+ process.kill(pid, signal);
} catch {
// 已经退了
}
}
}
+async function waitDesktopGone(exe, timeoutMs = 8000) {
+ const deadline = Date.now() + timeoutMs;
+ while (Date.now() < deadline) {
+ const left = listDesktopPids(exe).filter((pid) => pid !== process.pid);
+ if (left.length === 0) return true;
+ await sleep(200);
+ }
+ return listDesktopPids(exe).filter((pid) => pid !== process.pid).length === 0;
+}
+
+async function quitDarwinDesktop(exe) {
+ const bundle = darwinBundleOf(exe);
+ const name = darwinBundleName(bundle);
+ if (name) {
+ try {
+ execFileSync(
+ "osascript",
+ ["-e", `if application "${name}" is running then tell application "${name}" to quit`],
+ { timeout: 15000 },
+ );
+ log("osascript quit sent");
+ } catch (e) {
+ log(`osascript quit failed: ${e && e.message ? e.message : e}`);
+ }
+ if (await waitDesktopGone(exe, 8000)) {
+ log("quit by apple event");
+ return "apple-event";
+ }
+ }
+ signalPids(listDesktopPids(exe), "SIGTERM");
+ if (await waitDesktopGone(exe, 5000)) {
+ log("quit by SIGTERM");
+ return "SIGTERM";
+ }
+ signalPids(listDesktopPids(exe), "SIGKILL");
+ await waitDesktopGone(exe, 2000);
+ log("quit by SIGKILL");
+ return "SIGKILL";
+}
+
+function killOtherDesktopProcesses(keepPid, exe = info.execPath) {
+ for (const pid of listDesktopPids(exe)) {
+ if (pid === keepPid || pid === process.pid) continue;
+ try {
+ process.kill(pid, process.platform === "darwin" ? "SIGTERM" : undefined);
+ } catch {
+ // 已经退了
+ }
+ }
+}
+
+async function moveAsarAsideAsync(asar) {
+ if (!asar) return false;
+ try {
+ if (!fs.existsSync(asar) || !fs.statSync(asar).isFile()) return true;
+ } catch {
+ return true;
+ }
+ const bak = `${asar}.bak`;
+ try {
+ if (fs.existsSync(bak)) fs.rmSync(bak, { force: true });
+ } catch {
+ // keep going
+ }
+ for (let i = 0; i < 40; i++) {
+ try {
+ fs.renameSync(asar, bak);
+ log(`asar moved to ${bak}`);
+ return true;
+ } catch {
+ await sleep(200);
+ }
+ }
+ log("asar move failed after retries");
+ return false;
+}
+
+function relaunchDesktop() {
+ if (!info.execPath) {
+ process.exit(1);
+ }
+ const env = spawnEnv();
+ if (process.platform === "darwin") {
+ const bundle = darwinBundleOf(info.execPath);
+ if (bundle) {
+ const child = spawn("open", [bundle], {
+ detached: true,
+ stdio: "ignore",
+ env,
+ shell: false,
+ });
+ child.on("error", () => process.exit(1));
+ child.unref();
+ log("relaunched via open");
+ return;
+ }
+ }
+ const child = spawn(info.execPath, Array.isArray(info.argv) ? info.argv : [], {
+ detached: true,
+ stdio: "ignore",
+ cwd: info.cwd || process.cwd(),
+ env,
+ windowsHide: true,
+ shell: false,
+ });
+ child.on("error", () => process.exit(1));
+ child.unref();
+ log("relaunched via execPath");
+}
+
if (info.killApp) {
- await new Promise((r) => setTimeout(r, 400));
+ await sleep(400);
for (const dir of cleanup) rmTree(dir);
if (info.helper) {
- try { fs.unlinkSync(info.helper); } catch { /* ignore */ }
+ try {
+ fs.unlinkSync(info.helper);
+ } catch {
+ /* ignore */
+ }
}
- killOtherDesktopProcesses(process.pid);
- await new Promise((r) => setTimeout(r, 500));
+ if (process.platform === "darwin") {
+ await quitDarwinDesktop(info.execPath);
+ } else {
+ killOtherDesktopProcesses(process.pid);
+ await sleep(500);
+ }
+ if (info.asar) await moveAsarAsideAsync(info.asar);
} else {
const gone = await waitPidGone(info.pid);
if (!gone) process.exit(1);
for (const dir of cleanup) rmTree(dir);
if (info.helper) {
- try { fs.unlinkSync(info.helper); } catch { /* ignore */ }
+ try {
+ fs.unlinkSync(info.helper);
+ } catch {
+ /* ignore */
+ }
}
+ if (info.asar) await moveAsarAsideAsync(info.asar);
}
if (info.respawn === false) {
@@ -118,15 +318,6 @@ if (info.respawn === false) {
if (!info.execPath) process.exit(1);
-const child = spawn(info.execPath, Array.isArray(info.argv) ? info.argv : [], {
- detached: true,
- stdio: "ignore",
- cwd: info.cwd || process.cwd(),
- env: spawnEnv(),
- windowsHide: true,
- shell: false,
-});
-child.on("error", () => process.exit(1));
-child.unref();
-await new Promise((r) => setTimeout(r, 400));
+relaunchDesktop();
+await sleep(400);
process.exit(0);
diff --git a/package.json b/package.json
index 590df0c..2af6fb2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "dsh-purge",
- "version": "1.1.48",
+ "version": "1.1.49-beta.1",
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,内嵌演练台;不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
"type": "module",
"main": "lib/index.js",
diff --git a/release-notes.md b/release-notes.md
index d69cee7..45d60a5 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -1,3 +1,21 @@
+# 1.1.49-beta.1
+
+## 中文
+
+- 版本升级到 1.1.49-beta.1(#53 测试版)。
+- 修复 macOS 官方桌面点「应用」后假失败「失败: 正在重启。」:`scheduleRestart` helper/runtime 分支补回 `restarting: true`;Darwin 重启改为 osascript 优雅退出 + SIGTERM/SIGKILL,排除 CLI 进程后再 `open` 重开(剥掉 ELECTRON_RUN_AS_NODE)。
+- 解包 app.asar 后自动修补官方 `dsh` CLI 入口(asar/`app/` 回退)并补 `app/runtime -> ../runtime`,避免 `dsh web` 等全部 MODULE_NOT_FOUND。
+- `/purge status` 对多路径文件清单按数组逐项判断,不再把已打补丁文件标成 ✗。
+- 前端重启失败文案不再把成功分支的 note 当成 error。
+
+## English
+
+- Version 1.1.49-beta.1 (prerelease for #53).
+- Fix macOS official desktop Apply false failure "Failed: Restarting.": helper/runtime branches of scheduleRestart return restarting:true; Darwin restart uses osascript quit then SIGTERM/SIGKILL, skips CLI processes, relaunches via open without ELECTRON_RUN_AS_NODE.
+- After unpacking app.asar, auto-patch the official dsh CLI entry (asar/app fallback) and add app/runtime -> ../runtime so dsh web and other subcommands keep working.
+- /purge status treats multi-path file lists correctly instead of marking patched files as missing.
+- Restart failure UI no longer uses the success note as the error detail.
+
# 1.1.48
## 中文