mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-27 18:50:22 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
148d6218d8 | ||
|
|
94a7cf814e |
No files matched your search
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness cybersecurity red-team tool (dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.48</strong></p>
|
||||
<p align="center"><strong>Version 1.1.50</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>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 ⭐</em>
|
||||
@@ -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.50**. 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.
|
||||
|
||||
<a id="web"></a>
|
||||
|
||||
### Web
|
||||
@@ -218,13 +220,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv
|
||||
<p align="center">
|
||||
<a href="https://deepseek.stream/plugins/dsh-purge"><strong>🌐 Open Hub page</strong></a>
|
||||
·
|
||||
<a href="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"><strong>🚀 Install in desktop client</strong></a>
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.50&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"><strong>🚀 Install in desktop client</strong></a>
|
||||
</p>
|
||||
|
||||
🔗 **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.50&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
|
||||
```
|
||||
|
||||
<details>
|
||||
@@ -240,7 +242,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.48',
|
||||
version: '1.1.50',
|
||||
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
|
||||
<a href="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">
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.50&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">
|
||||
🚀 Install in desktop client
|
||||
</a>
|
||||
```
|
||||
@@ -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.50` | 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 |
|
||||
|
||||
+9
-7
@@ -4,7 +4,7 @@
|
||||
|
||||
<h1 align="center">⚔️ DeepSeek Harness 网络安全红队工具(dsh-purge)</h1>
|
||||
|
||||
<p align="center"><strong>Version 1.1.48</strong></p>
|
||||
<p align="center"><strong>Version 1.1.50</strong></p>
|
||||
|
||||
<p align="center">
|
||||
<em>本机官方 DeepSeek Harness 网络安全红队评测插件。清洗宿主策略,并带内嵌演练台。不同模型可换不同提示词。默认提示词面向国模「小码酱」。求 Star 收藏 ⭐</em>
|
||||
@@ -118,7 +118,7 @@ Harness 不只是把问题交给模型。它还会在运行时改提示词、审
|
||||
| 官方 Harness 0.1.x | 不支持 |
|
||||
| 其它未列出版本 | 对不上的补丁会显示待应用或跳过,不要指望能用 |
|
||||
|
||||
插件版本是 **1.1.48**。1.1.45 有问题,略过。
|
||||
插件版本是 **1.1.50**。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 里点桌面端的应用,也不要反过来。
|
||||
|
||||
<a id="web"></a>
|
||||
@@ -218,13 +220,13 @@ dsh plugin --profile default add https://github.com/YuJunZhiXue/dsh-purge/archiv
|
||||
<p align="center">
|
||||
<a href="https://deepseek.stream/plugins/dsh-purge"><strong>🌐 打开插件市场页</strong></a>
|
||||
·
|
||||
<a href="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"><strong>🚀 唤起客户端一键安装</strong></a>
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.50&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"><strong>🚀 唤起客户端一键安装</strong></a>
|
||||
</p>
|
||||
|
||||
🔗 **原生协议链接:**
|
||||
|
||||
```
|
||||
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.50&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
|
||||
```
|
||||
|
||||
<details>
|
||||
@@ -240,7 +242,7 @@ export function installDshPurgeToDesktop() {
|
||||
const params = new URLSearchParams({
|
||||
id: 'dsh-purge',
|
||||
name: 'dsh-purge',
|
||||
version: '1.1.48',
|
||||
version: '1.1.50',
|
||||
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
|
||||
<a href="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">
|
||||
<a href="dsh://plugin/install?id=dsh-purge&name=dsh-purge&version=1.1.50&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">
|
||||
🚀 唤起客户端一键安装
|
||||
</a>
|
||||
```
|
||||
@@ -270,7 +272,7 @@ export function installDshPurgeToDesktop() {
|
||||
|---|---|---|
|
||||
| id | `dsh-purge` | 插件唯一标识符 |
|
||||
| name | `dsh-purge` | 插件展示名称 |
|
||||
| version | `1.1.48` | 语义化版本号 |
|
||||
| version | `1.1.50` | 语义化版本号 |
|
||||
| repo | `YuJunZhiXue/dsh-purge` | GitHub 仓库 |
|
||||
| permissions | `系统提示词注入, 本机补丁, 设置页` | 申请权限 |
|
||||
| downloadUrl | `https://github.com/YuJunZhiXue/dsh-purge/archive/refs/heads/master.tar.gz` | GitHub 源码包地址 |
|
||||
|
||||
@@ -94,8 +94,9 @@ window.__ModuleLoader__.load({ id: "dsh-purge", factory: (require) => {
|
||||
return Boolean(active && active.size > 0);
|
||||
}
|
||||
|
||||
async function bothInjectEmpty(overrideText) {
|
||||
async function bothInjectEmpty(overrideText, defaultText) {
|
||||
if (!promptBoxEmpty(overrideText)) return false;
|
||||
if (!promptBoxEmpty(defaultText)) return false;
|
||||
try {
|
||||
return !activeRuleHasBody(await rulesApi("status"));
|
||||
} catch {
|
||||
@@ -1498,7 +1499,7 @@ body .dshp-dock[data-theme="white"] .dshp-dock-body .rt-card,body .dshp-dock[dat
|
||||
run();
|
||||
return;
|
||||
}
|
||||
bothInjectEmpty(overrideRef.current).then((empty) => {
|
||||
bothInjectEmpty(overrideRef.current, defaultOverrideRef.current).then((empty) => {
|
||||
if (ticket !== actionTicket.current) return;
|
||||
if (empty) {
|
||||
rejectNeedPrompt(tr);
|
||||
@@ -1538,7 +1539,7 @@ body .dshp-dock[data-theme="white"] .dshp-dock-body .rt-card,body .dshp-dock[dat
|
||||
if (ticket === actionTicket.current) setPatchBusy(false);
|
||||
});
|
||||
};
|
||||
bothInjectEmpty(overrideRef.current).then((empty) => {
|
||||
bothInjectEmpty(overrideRef.current, defaultOverrideRef.current).then((empty) => {
|
||||
if (ticket !== actionTicket.current) return;
|
||||
if (empty) {
|
||||
rejectNeedPrompt(tr);
|
||||
@@ -2462,7 +2463,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;
|
||||
}
|
||||
|
||||
+71
-13
@@ -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);
|
||||
@@ -5749,7 +5762,10 @@ export async function readOverrideForUi(dshHome) {
|
||||
}
|
||||
}
|
||||
const customized = await isUserCustomizedOverride(dshHome);
|
||||
const show = normalizeOverride(disk) ? disk : defaultContent;
|
||||
// 未改过:界面始终显示内置默认(1.1.30 前行为)。已改过:显示磁盘正文,空则回退默认。
|
||||
const show = customized
|
||||
? (normalizeOverride(disk) ? disk : defaultContent)
|
||||
: defaultContent;
|
||||
return {
|
||||
path: fp,
|
||||
exists,
|
||||
@@ -5775,42 +5791,84 @@ export function seedOverrideSync(dshHome) {
|
||||
const bundled = defaultOverrideText();
|
||||
if (!normalizeOverride(bundled)) return fs.existsSync(fp) ? "empty" : "missing";
|
||||
fs.writeFileSync(fp, bundled, "utf8");
|
||||
try {
|
||||
const state = readOverrideStateSync(dshHome);
|
||||
if (state.customized !== true) {
|
||||
fs.mkdirSync(path.dirname(overrideStatePath(dshHome)), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
overrideStatePath(dshHome),
|
||||
`${JSON.stringify({
|
||||
customized: false,
|
||||
hash: hashOverride(bundled),
|
||||
seedHash: defaultOverrideHash(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
}, null, 2)}\n`,
|
||||
"utf8",
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// 状态写失败不挡注入文件
|
||||
}
|
||||
return "wrote";
|
||||
}
|
||||
|
||||
/**
|
||||
* 未自行改过时始终把内置默认写回磁盘(与 1.1.30 前一致)。
|
||||
* 只点「应用」不点「保存」也要有可注入正文;空文件或仍是旧默认种子时都补齐。
|
||||
*/
|
||||
export async function installOverride(dshHome, force = false) {
|
||||
const fp = findOverrideFile(dshHome);
|
||||
await fsp.mkdir(dshHome, { recursive: true });
|
||||
if (!force && await isUserCustomizedOverride(dshHome)) return "exists";
|
||||
const bundled = defaultOverrideText();
|
||||
if (!normalizeOverride(bundled)) return fs.existsSync(fp) ? "empty" : "missing";
|
||||
let disk = "";
|
||||
if (!force && fs.existsSync(fp)) {
|
||||
let disk = "";
|
||||
try {
|
||||
disk = await loadText(fp);
|
||||
} catch {
|
||||
disk = "";
|
||||
}
|
||||
const bundled = defaultOverrideText();
|
||||
if (normalizeOverride(disk) && normalizeOverride(disk) !== normalizeOverride(bundled)) {
|
||||
await markOverrideCustomized(dshHome, true, disk);
|
||||
return "exists";
|
||||
}
|
||||
}
|
||||
const bundled = defaultOverrideText();
|
||||
if (!normalizeOverride(bundled)) return fs.existsSync(fp) ? "empty" : "missing";
|
||||
// 磁盘已是同一份默认则只刷新标记,避免无意义重写。
|
||||
if (!force && normalizeOverride(disk) && normalizeOverride(disk) === normalizeOverride(bundled)) {
|
||||
await markOverrideCustomized(dshHome, false, bundled);
|
||||
return "exists";
|
||||
}
|
||||
await fsp.writeFile(fp, bundled, "utf8");
|
||||
await markOverrideCustomized(dshHome, false, bundled);
|
||||
return "wrote";
|
||||
}
|
||||
|
||||
/** 应用/启动时解析最终要落盘并注入的正文:框里有就用框,否则内置默认。 */
|
||||
export function resolveApplyOverrideText(dshHome, incoming) {
|
||||
const bundled = defaultOverrideText();
|
||||
if (normalizeOverride(incoming)) return String(incoming);
|
||||
const disk = overrideFileTextSafe(dshHome);
|
||||
if (normalizeOverride(disk)) return disk;
|
||||
return bundled;
|
||||
}
|
||||
|
||||
function overrideFileTextSafe(dshHome) {
|
||||
const fp = findOverrideFile(dshHome);
|
||||
try {
|
||||
if (!fp || !fs.existsSync(fp)) return "";
|
||||
return fs.readFileSync(fp, "utf8");
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveOverrideContent(dshHome, content) {
|
||||
const bundled = defaultOverrideText();
|
||||
const incoming = typeof content === "string" ? content : "";
|
||||
const customized = normalizeOverride(incoming) !== normalizeOverride(bundled);
|
||||
const resolved = normalizeOverride(incoming) ? incoming : bundled;
|
||||
const customized = normalizeOverride(resolved) !== normalizeOverride(bundled);
|
||||
const fp = findOverrideFile(dshHome);
|
||||
await fsp.mkdir(dshHome, { recursive: true });
|
||||
await fsp.writeFile(fp, incoming, "utf8");
|
||||
await markOverrideCustomized(dshHome, customized, incoming);
|
||||
return { path: fp, customized, content: incoming, defaultContent: bundled };
|
||||
await fsp.writeFile(fp, resolved, "utf8");
|
||||
await markOverrideCustomized(dshHome, customized, resolved);
|
||||
return { path: fp, customized, content: resolved, defaultContent: bundled };
|
||||
}
|
||||
|
||||
export async function ensureOverrideContent(dshHome, force = false) {
|
||||
|
||||
+142
-3
@@ -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;
|
||||
}
|
||||
+56
-18
@@ -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));
|
||||
@@ -354,14 +364,22 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
// 0.1.5 起 complete:true 在 waterfall 之后用调用前的快照盖掉 sections。
|
||||
// 换宿主版本时文件补丁还没写上,或换插件版本时旧钩子把 dsh-purge 段删掉,注入都会丢。
|
||||
// 包住 assemble 的返回值,按 prompt-inject.md 再补回。
|
||||
const prompt = ctx.systemPrompt;
|
||||
if (!prompt || typeof prompt.assemble !== "function" || prompt.__dshPurgeAssembleWrapped) return;
|
||||
const orig = prompt.assemble;
|
||||
prompt.assemble = async function (...args) {
|
||||
const assembled = await orig.apply(this, args);
|
||||
return rewriteLiveAssembly(config, assembled, args[0]);
|
||||
const wrapAssemble = () => {
|
||||
const prompt = ctx.systemPrompt;
|
||||
if (!prompt || typeof prompt.assemble !== "function" || prompt.__dshPurgeAssembleWrapped) return false;
|
||||
const orig = prompt.assemble;
|
||||
prompt.assemble = async function (...args) {
|
||||
const assembled = await orig.apply(this, args);
|
||||
return rewriteLiveAssembly(config, assembled, args[0]);
|
||||
};
|
||||
prompt.__dshPurgeAssembleWrapped = true;
|
||||
return true;
|
||||
};
|
||||
prompt.__dshPurgeAssembleWrapped = true;
|
||||
if (!wrapAssemble()) {
|
||||
queueMicrotask(wrapAssemble);
|
||||
setTimeout(wrapAssemble, 500);
|
||||
setTimeout(wrapAssemble, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
function shimNeedsPatch(state) {
|
||||
@@ -505,6 +523,10 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
await core.ensureOverrideContent(state.dsh_home, false);
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||
if (blocked) return { kind: "error", text: blocked.error };
|
||||
await core.saveOverrideContent(
|
||||
state.dsh_home,
|
||||
core.resolveApplyOverrideText(state.dsh_home, ""),
|
||||
);
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
const shimResult = await core.patchAllShims();
|
||||
@@ -844,6 +866,10 @@ export function apply(ctx, config) {
|
||||
} catch (e) {
|
||||
console.warn("[dsh-purge] seed override error:", String(e));
|
||||
}
|
||||
// 与 1.1.30 前一致:启动就落盘默认提示词,不依赖用户先点保存。
|
||||
core.installOverride(core.findDshHome(), false).catch((e) => {
|
||||
console.warn("[dsh-purge] install override error:", String(e));
|
||||
});
|
||||
installIdentityOverride(ctx, cfg);
|
||||
installRegionGate(ctx);
|
||||
try {
|
||||
@@ -975,6 +1001,10 @@ export function apply(ctx, config) {
|
||||
await core.ensureOverrideContent(state.dsh_home, false);
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home);
|
||||
if (blocked) return { text: "ERROR: " + blocked.error };
|
||||
await core.saveOverrideContent(
|
||||
state.dsh_home,
|
||||
core.resolveApplyOverrideText(state.dsh_home, ""),
|
||||
);
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base);
|
||||
await core.patchAllShims();
|
||||
@@ -1331,9 +1361,11 @@ function installWebServer(ctx, cfg) {
|
||||
await core.ensureOverrideContent(state.dsh_home, false);
|
||||
const ui = await core.readOverrideForUi(state.dsh_home);
|
||||
const incoming = typeof body?.content === "string" ? body.content : "";
|
||||
const boxText = core.normalizeOverride(incoming)
|
||||
? incoming
|
||||
: (ui.content || ui.defaultContent || "");
|
||||
// 框空时用内置默认,与 1.1.30 前「应用即带默认注入」一致,不必先点保存。
|
||||
const boxText = core.resolveApplyOverrideText(state.dsh_home, incoming)
|
||||
|| ui.content
|
||||
|| ui.defaultContent
|
||||
|| "";
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home, boxText);
|
||||
if (blocked) {
|
||||
sendJson(response, 400, {
|
||||
@@ -1345,13 +1377,17 @@ function installWebServer(ctx, cfg) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (core.normalizeOverride(boxText)) {
|
||||
await core.saveOverrideContent(state.dsh_home, boxText);
|
||||
}
|
||||
await core.saveOverrideContent(state.dsh_home, boxText);
|
||||
await core.backupAll(state.ai_base);
|
||||
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 +1432,7 @@ function installWebServer(ctx, cfg) {
|
||||
override_installed: override.installed,
|
||||
shim,
|
||||
desktop_scrubbed: scrubbed,
|
||||
cli_repair: cliRepair,
|
||||
cmd_flash: flash,
|
||||
});
|
||||
if (shouldRestart && handoff && core.desktopAsarStillSealed()) {
|
||||
@@ -1488,16 +1525,17 @@ function installWebServer(ctx, cfg) {
|
||||
return;
|
||||
}
|
||||
const home = core.findDshHome();
|
||||
const blocked = rejectIfNeedPrompt(home, content);
|
||||
const resolved = core.resolveApplyOverrideText(home, content);
|
||||
const blocked = rejectIfNeedPrompt(home, resolved);
|
||||
if (blocked) {
|
||||
sendJson(response, 400, {
|
||||
ok: false,
|
||||
content,
|
||||
content: resolved,
|
||||
...blocked,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const saved = await core.saveOverrideContent(home, content);
|
||||
const saved = await core.saveOverrideContent(home, resolved);
|
||||
sendJson(response, 200, { ok: true, ...saved, ...injectSnapshot(home) });
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
|
||||
+214
-23
@@ -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);
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "dsh-purge",
|
||||
"version": "1.1.48",
|
||||
"version": "1.1.50",
|
||||
"description": "DeepSeek Harness 网络安全红队工具:本机官方 Harness 受控评测与清洗,内嵌演练台;不同模型可换不同提示词;默认提示词面向国模「小码酱」。求 Star ⭐",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
|
||||
@@ -1,3 +1,35 @@
|
||||
# 1.1.50
|
||||
|
||||
## 中文
|
||||
|
||||
- 版本升级到 1.1.50。
|
||||
- 修复 macOS 官方桌面:点「应用」假失败「失败: 正在重启。」、解包后 `dsh` CLI 失效、status 误标 ✗(#53)。
|
||||
- 修复点「应用」重启后默认提示词不注入:未改过时自动落盘内置默认,不必先点保存。
|
||||
|
||||
## English
|
||||
|
||||
- Version 1.1.50.
|
||||
- Fix macOS official desktop: Apply false "Failed: Restarting.", broken `dsh` CLI after asar unpack, and status ✗ false negatives (#53).
|
||||
- Fix default prompt not injecting after Apply + restart; bundled default is written without requiring Save first.
|
||||
|
||||
# 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
|
||||
|
||||
## 中文
|
||||
|
||||
Reference in new issue
Block a user