mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 09:20:22 +08:00
feat: 发布 1.1.7,Web / 桌面端分开安装并跟随当前桌面目录清洗
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
2529db6088
commit
e84671d20a
14 files changed
+1370
-345
No files matched your search
+23
-85
@@ -1,10 +1,8 @@
|
||||
import fs from "node:fs";
|
||||
import { promises as fsp } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import * as core from "./core.js";
|
||||
import * as hostctl from "./host.js";
|
||||
import * as rules from "./rules.js";
|
||||
import * as updater from "./update.js";
|
||||
import {
|
||||
@@ -77,7 +75,9 @@ function line(title, value, ok = null) {
|
||||
function renderStatus(state) {
|
||||
const out = [];
|
||||
out.push("dsh-purge 状态 / Status");
|
||||
out.push(line("宿主 / surface", state.surface || hostctl.currentSurface()));
|
||||
out.push(line("DSH_HOME", state.dsh_home));
|
||||
if (state.desktop_install) out.push(line("桌面安装 / desktop", state.desktop_install));
|
||||
if (state.ai_base) {
|
||||
out.push(line("插件根 / plugin root", state.ai_base));
|
||||
for (const [key, fp] of Object.entries(state.files)) {
|
||||
@@ -224,23 +224,12 @@ function installIdentityOverride(ctx, config = {}) {
|
||||
ctx.on("system-prompt/assemble", hook, { global: true, prepend: true });
|
||||
}
|
||||
|
||||
const LAUNCHER_SHIM_NAMES = ["dsh.cmd", "dsh.ps1", "dsh"];
|
||||
|
||||
function desktopShimNeedsPatch(dirs) {
|
||||
for (const dir of dirs || []) {
|
||||
for (const name of LAUNCHER_SHIM_NAMES) {
|
||||
if (core.shimFileStatus(path.join(dir, name)) === "original") return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function shimNeedsPatch(state) {
|
||||
if (hostctl.currentSurface() === "desktop") return false;
|
||||
return (
|
||||
state.shim_cmd === "original" ||
|
||||
state.shim_ps1 === "original" ||
|
||||
state.shim_bin === "original" ||
|
||||
desktopShimNeedsPatch(state.desktop_runtimes)
|
||||
state.shim_bin === "original"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -673,71 +662,6 @@ export function apply(ctx, config) {
|
||||
installWebServer(ctx, cfg);
|
||||
}
|
||||
|
||||
function portFromRequest(request) {
|
||||
const hostHeader = String(request.headers?.host || "");
|
||||
const match = hostHeader.match(/:(\d+)$/);
|
||||
if (match) return Number(match[1]);
|
||||
return 3080;
|
||||
}
|
||||
|
||||
function hostFromRequest(request) {
|
||||
const hostHeader = String(request.headers?.host || "127.0.0.1");
|
||||
return hostHeader.replace(/:\d+$/, "") || "127.0.0.1";
|
||||
}
|
||||
|
||||
function restartArgv() {
|
||||
const root = core.findDshBinRoot();
|
||||
const binJs = root ? path.join(root, "lib", "bin.js") : null;
|
||||
if (binJs && fs.existsSync(binJs)) {
|
||||
const args = [binJs];
|
||||
// 复用当前 argv 的 profile/子命令,入口改走 node + bin.js。
|
||||
const rest = process.argv.slice(2).filter((arg) => arg !== "--no-open");
|
||||
if (!rest.includes("web") && !rest.includes("desktop")) {
|
||||
const port = Number(process.env.PORT) || 3080;
|
||||
rest.unshift("web", "--port", String(port));
|
||||
}
|
||||
rest.push("--no-open");
|
||||
return [...args, ...rest];
|
||||
}
|
||||
const argv = process.argv.slice(1).filter((arg) => arg !== "--no-open");
|
||||
if (argv[0] && /\.(cmd|bat)$/i.test(argv[0])) {
|
||||
const dir = path.dirname(argv[0]);
|
||||
const candidates = [
|
||||
path.resolve(dir, "node_modules", "@deepseek-ai", "dsh", "lib", "bin.js"),
|
||||
path.resolve(dir, "..", "node_modules", "@deepseek-ai", "dsh", "lib", "bin.js"),
|
||||
];
|
||||
const hit = candidates.find((p) => fs.existsSync(p));
|
||||
if (hit) argv[0] = hit;
|
||||
}
|
||||
argv.push("--no-open");
|
||||
return argv;
|
||||
}
|
||||
|
||||
function scheduleWebRestart(request) {
|
||||
try {
|
||||
core.silenceCmdFlash();
|
||||
} catch {}
|
||||
const helper = fileURLToPath(new URL("./restart-web.js", import.meta.url));
|
||||
const child = spawn(process.execPath, [helper], {
|
||||
detached: true,
|
||||
stdio: "ignore",
|
||||
windowsHide: true,
|
||||
shell: false,
|
||||
env: {
|
||||
...core.envForDetachedSpawn(),
|
||||
DSH_PURGE_RESTART: JSON.stringify({
|
||||
execPath: process.execPath,
|
||||
argv: restartArgv(),
|
||||
cwd: process.cwd(),
|
||||
host: hostFromRequest(request),
|
||||
port: portFromRequest(request),
|
||||
}),
|
||||
},
|
||||
});
|
||||
child.unref();
|
||||
setTimeout(() => process.exit(0), 250);
|
||||
}
|
||||
|
||||
function installWebServer(ctx, cfg) {
|
||||
watchWebTreeReady(ctx);
|
||||
ctx.inject(["webServer"], (host) => {
|
||||
@@ -762,7 +686,10 @@ function installWebServer(ctx, cfg) {
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
ready: true,
|
||||
surface: state.surface || hostctl.currentSurface(),
|
||||
ai_base: state.ai_base,
|
||||
desktop_install: state.desktop_install || "",
|
||||
missing_ai_base: state.ai_base ? "" : core.missingAiBaseMessage(),
|
||||
patches_applied: state.patches_applied,
|
||||
patches_pending: state.patches_pending,
|
||||
patches_skipped: state.patches_skipped || 0,
|
||||
@@ -971,12 +898,17 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
try {
|
||||
const result = await uninstaller.uninstallPurge();
|
||||
sendJson(response, result.ok ? 200 : 500, result);
|
||||
sendJson(response, result.ok ? 200 : 500, {
|
||||
...result,
|
||||
surface: hostctl.currentSurface(),
|
||||
fullApp: hostctl.currentSurface() === "desktop",
|
||||
note: result.ok ? hostctl.restartNote() : undefined,
|
||||
});
|
||||
if (result.ok) {
|
||||
uninstaller.scheduleCleanupRestart({
|
||||
request,
|
||||
restartArgv: restartArgv(),
|
||||
cleanup: result.cleanup,
|
||||
ctx,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -1033,8 +965,14 @@ function installWebServer(ctx, cfg) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
scheduleWebRestart(request);
|
||||
sendJson(response, 200, { ok: true, note: "正在重启 dsh web…" });
|
||||
const surface = hostctl.currentSurface();
|
||||
hostctl.scheduleRestart(request, ctx);
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
surface,
|
||||
fullApp: surface === "desktop",
|
||||
note: hostctl.restartNote(),
|
||||
});
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user