mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 02:10:22 +08:00
silenceCmdFlash():应用/启动/重启前统一收尾(hide + Doctor stub + mnemon) 应用完成条件:complete 必须含 CMD 无感成功 重启只走 node + bin.js,不走 dsh.cmd 发消息闪 CMD silenceMnemonGitFlash():把 mnemon 每轮 git branch 改成读 .git/HEAD(点应用会自动钉到现场 node_modules) 提示词注入 identity.js:把 prompt-inject.md 折进 deployment:persona,梁神 phase-1 也能吃到 梁神白名单保留 dsh-purge*(现场 patch + core #29) 空 prompt-inject 不再自动灌默认 RP;有内容才注入
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
// Spawned by /dsh-purge/restart: wait until the old web port is free, then relaunch.
|
|
import net from "node:net";
|
|
import { spawn } from "node:child_process";
|
|
import { envForDetachedSpawn } from "./core.js";
|
|
|
|
const encoded = process.env.DSH_PURGE_RESTART;
|
|
if (!encoded) process.exit(1);
|
|
|
|
let info;
|
|
try {
|
|
info = JSON.parse(encoded);
|
|
} catch {
|
|
process.exit(1);
|
|
}
|
|
|
|
const port = Number(info.port) || 3080;
|
|
const host = typeof info.host === "string" && info.host ? info.host : "127.0.0.1";
|
|
|
|
function portFree() {
|
|
return new Promise((resolve) => {
|
|
const socket = net.createConnection({ host, port }, () => {
|
|
socket.destroy();
|
|
resolve(false);
|
|
});
|
|
socket.on("error", () => resolve(true));
|
|
});
|
|
}
|
|
|
|
async function waitFree() {
|
|
for (let i = 0; i < 80; i++) {
|
|
if (await portFree()) return true;
|
|
await new Promise((r) => setTimeout(r, 120));
|
|
}
|
|
return false;
|
|
}
|
|
|
|
const ok = await waitFree();
|
|
if (!ok) process.exit(1);
|
|
|
|
const child = spawn(info.execPath, info.argv, {
|
|
detached: true,
|
|
stdio: "ignore",
|
|
cwd: info.cwd || process.cwd(),
|
|
env: envForDetachedSpawn(),
|
|
windowsHide: true,
|
|
shell: false,
|
|
});
|
|
child.unref();
|
|
process.exit(0);
|