feat: 发布 1.1.19,支持官方桌面 EXE

官方客户端可以应用并自己重启;修掉重启弹窗、残留 PowerShell,以及更新时要手动还原再应用的问题。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-25 02:47:29 +08:00
1 parent 00ccf4a1f1
commit fd8d47c00f
16 files changed
+973 -72

No files matched your search

+91 -12
View File
@@ -5,6 +5,7 @@ import * as hostctl from "./host.js";
import * as rules from "./rules.js";
import * as skills from "./skills.js";
import * as updater from "./update.js";
import * as reapply from "./reapply.js";
import {
GLOBAL_PROMPT_ORDER,
isMnemonPluginMessage,
@@ -18,6 +19,8 @@ export const name = "dsh-purge";
export const inject = ["systemPrompt", "tools"];
let bootFullQuit = false;
const DEFAULTS = {
enabled: true,
autoApplyOnStart: true,
@@ -268,6 +271,44 @@ function shimNeedsPatch(state) {
);
}
async function settleInstalledPatches(config, ctx) {
if (!reapply.patchesMatchInstall()) {
const result = await reapply.reapplyInstalled();
if (!result.ok) {
log(config, "reapply failed:", result.error || "");
return "reapply-failed";
}
if (result.needsFullQuit) {
bootFullQuit = true;
log(config, "reapply wrote patches; official host needs a full quit");
return "full-quit";
}
log(config, "reapply wrote patches; restarting");
try {
hostctl.scheduleRestart(null, ctx);
} 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 !== false) {
updater.autoUpdateIfNeeded()
.then((r) => {
log(config, "auto-update:", JSON.stringify(r));
if (r && r.needsFullQuit) bootFullQuit = true;
if (r && r.restartAfter) {
try { hostctl.scheduleRestart(null, ctx); } catch (e) {
console.warn("[dsh-purge] auto-update restart failed:", e);
}
}
})
.catch((e) => console.warn("[dsh-purge] auto-update error:", String(e)));
}
return applied;
}
async function autoApply(config) {
try {
core.applyRuntimeEnv();
@@ -330,8 +371,14 @@ async function handlePurgeCommand(rawInput, config) {
core.applyRuntimeEnv();
const scrubbed = core.sanitizeDesktopCommandRuntimes();
const state = await core.gatherState();
let handoff = null;
if (!state.ai_base) {
return { kind: "error", text: core.missingAiBaseMessage() };
const opened = await core.openSealedDesktopHost();
if (!opened.aiBase) return { kind: "error", text: core.missingAiBaseMessage() };
state.ai_base = opened.aiBase;
if (opened.swapAsar) handoff = opened;
} else {
handoff = core.sealedAsarHandoff();
}
const blocked = rejectIfNeedPrompt(state.dsh_home);
if (blocked) return { kind: "error", text: blocked.error };
@@ -354,6 +401,12 @@ async function handlePurgeCommand(rawInput, config) {
}
lines.push("", "全部完成 / All done。重启 dsh 生效 / Restart dsh to take effect.");
lines.push("Desktop: host-commands 密封目录只清理不注入;bak 禁止写进 bin(issue #9)。");
if (handoff) {
const swapped = core.scheduleSealedDesktopRestart(handoff);
if (swapped?.renamed || swapped?.pending) {
lines.push("", "补丁已写入。请在设置页点「重启」,客户端会自己重新打开。");
}
}
return { kind: "success", text: lines.join("\n") };
}
case "revert":
@@ -655,15 +708,12 @@ export function apply(ctx, config) {
}
setImmediate(() => {
autoApply(cfg).then((r) => log(cfg, "auto-apply:", r));
settleInstalledPatches(cfg, ctx)
.then((r) => log(cfg, "settle:", r))
.catch((e) => 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)));
if (cfg.autoUpdateOnStart !== false) {
updater.autoUpdateIfNeeded()
.then((r) => log(cfg, "auto-update:", JSON.stringify(r)))
.catch((e) => console.warn("[dsh-purge] auto-update error:", String(e)));
}
});
try {
@@ -923,6 +973,7 @@ function installWebServer(ctx, cfg) {
override_path: state.override_path,
dsh_home: state.dsh_home,
plugin_version: updater.localVersion(),
boot_full_quit: bootFullQuit,
update: updater.lastUpdateResult(),
...updater.channelPublic(),
...(await skills.skillsStatus(core.findDshHome()).catch(() => ({ skills: [] }))),
@@ -1090,7 +1141,14 @@ function installWebServer(ctx, cfg) {
if (request.method === "POST") {
try {
const body = await readJsonBody(request);
sendJson(response, 200, await updater.handleUpdateOp(body || {}));
const result = await updater.handleUpdateOp(body || {});
if (result && result.needsFullQuit) bootFullQuit = true;
sendJson(response, 200, result);
if (result && result.restartAfter) {
try { hostctl.scheduleRestart(request, ctx); } catch (e) {
console.warn("[dsh-purge] update restart failed:", e);
}
}
} catch (e) {
sendJson(response, 500, { ok: false, error: String(e) });
}
@@ -1113,9 +1171,17 @@ function installWebServer(ctx, cfg) {
core.applyRuntimeEnv();
const scrubbed = core.sanitizeDesktopCommandRuntimes();
const state = await core.gatherState();
let handoff = null;
if (!state.ai_base) {
sendJson(response, 500, { ok: false, error: core.missingAiBaseMessage() });
return;
const opened = await core.openSealedDesktopHost();
if (!opened.aiBase) {
sendJson(response, 500, { ok: false, error: core.missingAiBaseMessage() });
return;
}
state.ai_base = opened.aiBase;
if (opened.swapAsar) handoff = opened;
} else {
handoff = core.sealedAsarHandoff();
}
const body = await readJsonBody(request);
const ui = await core.readOverrideForUi(state.dsh_home);
@@ -1141,9 +1207,20 @@ function installWebServer(ctx, cfg) {
const flash = core.silenceCmdFlash(state.ai_base);
const summary = core.summarizeApplyReport(report);
const complete = summary.failed.length === 0 && flash.ok === true;
let renamed = false;
let pendingQuit = false;
if (handoff) {
const swapped = core.scheduleSealedDesktopRestart(handoff);
renamed = Boolean(swapped?.renamed);
pendingQuit = Boolean(swapped?.pending);
}
const leaveTray = renamed || pendingQuit;
sendJson(response, 200, {
ok: true,
complete,
restarting: false,
unpacked_asar: leaveTray,
needs_full_quit: leaveTray,
applied: summary.applied,
already: summary.already,
failed: summary.failed.length,
@@ -1276,12 +1353,14 @@ function installWebServer(ctx, cfg) {
}
try {
const surface = hostctl.currentSurface();
hostctl.scheduleRestart(request, ctx);
const planned = hostctl.scheduleRestart(request, ctx);
sendJson(response, 200, {
ok: true,
surface,
fullApp: surface === "desktop",
note: hostctl.restartNote(),
restarting: Boolean(planned && planned.restarting),
needsFullQuit: false,
note: "正在重启。",
});
} catch (e) {
sendJson(response, 500, { ok: false, error: String(e) });