fix: 面板不再盖住官方对话,重打补丁不再回写前端包

浮层收成右侧窄条,底边停在输入框上方;演练台嵌在面板里时不再给官方窗口加右侧内边距。重打补丁时若前端 client.js 内容没变就不写,避免页面按旧 rev 404。桌面启动自检不再杀掉自己,清洗标记同时认新旧两句。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-04 21:24:20 +08:00
1 parent 354f9a1960
commit 813fbe4d54
8 files changed
+458 -188

No files matched your search

+144 -29
View File
@@ -1604,12 +1604,31 @@ export function listShimDirsForPatch() {
.filter((dir) => !isDesktopCommandRuntimeDir(dir));
}
function pathIsUnder(child, root) {
const c = path.normalize(String(child || "")).replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
const r = path.normalize(String(root || "")).replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
if (!c || !r || /^[a-z]:$/.test(r)) return false;
return c === r || c.startsWith(`${r}/`);
}
function findAiBaseDesktop() {
const env = process.env.DSH_BASE;
if (env && env.trim()) {
const p = path.normalize(env.trim());
if (isAiBase(p) && desktop.isInsideDesktopInstall(p)) return p;
const exe = desktop.findDesktopAppExecutable();
const owned = exe
? desktop.resolveDesktopAiBase({
execPath: exe,
resourcesPath: path.join(path.dirname(exe), "resources"),
argv: [],
env: {},
})
: "";
const envBase = String(process.env.DSH_BASE || "").trim();
if (envBase) {
const p = path.normalize(envBase);
const underOwned = Boolean(owned && exe && pathIsUnder(p, path.dirname(exe)));
if (isAiBase(p) && underOwned) return p;
if (isAiBase(p) && !owned && desktop.isInsideDesktopInstall(p)) return p;
}
if (owned) return owned;
const resolved = desktop.resolveDesktopAiBase();
if (resolved) return resolved;
const starts = [];
@@ -1842,18 +1861,22 @@ export function scheduleSealedDesktopRestart(handoff) {
return { renamed: false, pending: true, ...pending };
}
const HOST_CLEAN_MARKERS = ["[dsh-purge] identity stripped", "[dsh-purge] complete prompt keeps inject"];
/** waterfall 那句中间多了 waterfall,不包含旧句,两句都要认。 */
export function hostPromptKeepsInject(text) {
const body = String(text || "");
if (!body.includes("[dsh-purge] identity stripped")) return false;
return body.includes("[dsh-purge] complete prompt keeps waterfall inject")
|| body.includes("[dsh-purge] complete prompt keeps inject");
}
export function hostCleanMarkersPresent(aiBase) {
if (!aiBase) return false;
const fp = path.join(aiBase, "dsh-system-prompt", "lib", "index.js");
let text = "";
try {
text = fs.readFileSync(fp, "utf8");
return hostPromptKeepsInject(fs.readFileSync(fp, "utf8"));
} catch {
return false;
}
return HOST_CLEAN_MARKERS.every((mark) => text.includes(mark));
}
/** 重启前把清洗写进当前宿主。没写完就返回失败,调用方不得打开进程。 */
@@ -1879,17 +1902,18 @@ export async function ensureHostClean() {
let flash = silenceCmdFlash(aiBase);
if (pending.length || flash.ok !== true) {
await backupAll(aiBase);
const report = await applyPatches(aiBase);
const report = await applyPatches(aiBase, ALL_PATCHES, { preserveClientBundles: true });
await patchAllShims();
flash = silenceCmdFlash(aiBase);
const summary = summarizeApplyReport(report);
pending = await pendingIds();
if (pending.length || summary.failed.length || flash.ok !== true) {
const blocking = summary.failed.filter((row) => row.status !== "pattern_not_found");
if (pending.length || blocking.length || flash.ok !== true) {
return {
ok: false,
error: "清洗没有完成,已取消重启",
pending,
failed: summary.failed.length,
failed: blocking.length,
aiBase,
};
}
@@ -2060,16 +2084,14 @@ function quotedConst(name, body) {
const COMPLETE_PROMPT_WATERFALL_INJECT =
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
"\t\tconst dshPurgeInject = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\")).map((s) => String(s.text || \"\")).filter((t) => t.length > 0).join(\"\\n\\n\");\n" +
"\t\tconst dshPurgeSections = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\") && String(s.text || \"\").length > 0);\n" +
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return transformed;\n" +
"\t\treturn {\n" +
"\t\t\t...transformed,\n" +
"\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, inject) {\n" +
"\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, purge) {\n" +
"\t\t\t\tconst base = { ...complete };\n" +
"\t\t\t\tif (!inject) return [base];\n" +
"\t\t\t\tif (String(base.text || \"\").includes(inject)) return [base];\n" +
"\t\t\t\treturn [{ ...base, text: inject + \"\\n\\n\" + base.text }]; // [dsh-purge] complete prompt keeps waterfall inject\n" +
"\t\t\t})(completeSection, dshPurgeInject),\n" +
"\t\t\t\treturn [...purge, base]; // [dsh-purge] complete prompt keeps waterfall inject\n" +
"\t\t\t})(completeSection, dshPurgeSections),\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};";
@@ -2859,6 +2881,14 @@ const NEW_TOOL_PATCHES = [
replace:
"personaPrefix: !!js process.env.DSH_SYSTEM_PROMPT ?? ''",
},
{
pattern:
" prefix: \"\"\n" +
" complete: true",
replace:
" prefix: \"\"\n" +
" complete: false # [dsh-purge] minimal keeps operator once",
},
],
markers: [
"personaPrefix: !!js process.env.DSH_SYSTEM_PROMPT ?? ''",
@@ -4118,6 +4148,8 @@ const NEW_TOOL_PATCHES = [
desc: "回退只藏被撤掉的那一轮 / rewind hides only the cut range",
file: ["conversation-client"],
optional: true,
// 锚点还在时也别再 replaceAll。这个文件是前端模块,重复写会改 mtime。
skipIfMarked: true,
replacements: [
{
pattern:
@@ -4614,6 +4646,21 @@ function flattenTargetPaths(files) {
return out;
}
/**
* client-hmr 按 mtime/ctime/size 轮询 exports["./client"](官方 UI 包是 lib/client.js)。
* 页面已经按旧 rev 要脚本时,再写这个文件会让缓存里的地址 404,输入框整串掉光(#63)。
*/
export function isWatchedClientBundle(fp) {
const norm = String(fp || "").replace(/\\/g, "/");
return /\/node_modules\/@[^/]+\/[^/]+\/lib\/client\.js$/.test(norm);
}
export function clientBundlePackageName(fp) {
const norm = String(fp || "").replace(/\\/g, "/");
const matched = norm.match(/\/node_modules\/(@[^/]+\/[^/]+)\/lib\/client\.js$/);
return matched ? matched[1] : "";
}
/** 用户配置层:官方允许在 profiles/<name>/cordis.patch.yml 手写 insert,绝不能进 bak/回滚(#43)。 */
export function isUserProfilePatchFile(fp) {
const n = String(fp || "").replace(/\\/g, "/").toLowerCase();
@@ -4671,14 +4718,29 @@ export async function backupAll(aiBase) {
return { made, errors, skippedUser, dropped };
}
export async function revertAll(aiBase) {
async function sameFileBytes(left, right) {
try {
const [a, b] = await Promise.all([fsp.readFile(left), fsp.readFile(right)]);
return a.equals(b);
} catch {
return false;
}
}
export async function revertAll(aiBase, options = {}) {
const files = targetFiles(aiBase);
const reverted = [];
const skipped = [];
const preservedUser = [];
const errors = [];
const preserveClientBundles = options.preserveClientBundles === true;
for (const fp of flattenTargetPaths(files)) {
const bak = fp + ".dshpurge.bak";
// 启动自愈不能把前端 client.js 盖回去:copyFile 即使字节相同也会改 mtime(#63)。
if (preserveClientBundles && isWatchedClientBundle(fp)) {
skipped.push(fp);
continue;
}
// 用户 patch 层:有 bak 也只丢掉 bak,绝不 copy 回去(#43)。
if (isUserProfilePatchFile(fp)) {
if (fs.existsSync(bak)) {
@@ -4693,6 +4755,10 @@ export async function revertAll(aiBase) {
}
if (fs.existsSync(bak)) {
try {
if (fs.existsSync(fp) && await sameFileBytes(fp, bak)) {
skipped.push(fp);
continue;
}
await fsp.copyFile(bak, fp);
await fsp.unlink(bak);
reverted.push(fp);
@@ -5387,7 +5453,15 @@ async function loadText(p) {
}
async function saveText(p, text) {
await fsp.writeFile(p, text, "utf8");
const next = Buffer.from(text, "utf8");
try {
const current = await fsp.readFile(p);
if (current.equals(next)) return false;
} catch (e) {
if (!e || e.code !== "ENOENT") throw e;
}
await fsp.writeFile(p, next);
return true;
}
async function repairPluginCordisYaml() {
@@ -5398,9 +5472,10 @@ async function repairPluginCordisYaml() {
if (cleaned !== text) await saveText(fp, cleaned);
}
export async function applyPatches(aiBase, patches = ALL_PATCHES) {
export async function applyPatches(aiBase, patches = ALL_PATCHES, options = {}) {
const files = targetFiles(aiBase);
const report = [];
const preserveClientBundles = options.preserveClientBundles === true;
await repairPluginCordisYaml();
for (const p of patches) {
if (!patchAppliesHere(p)) {
@@ -5437,6 +5512,11 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
lastError = "read_error";
continue;
}
if (preserveClientBundles && isWatchedClientBundle(fp)) {
if (filePatchSettled(text, p, fp)) already += 1;
else if (patchHasRemainingWork(text, p, fp) || p.strictFiles) notFound += 1;
continue;
}
const appliedText = applyReplacementsToText(text, p, fp);
let textOut = appliedText.text;
let changed = appliedText.changed;
@@ -5449,8 +5529,9 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
}
if (changed) {
try {
await saveText(fp, textOut);
applied += 1;
const wrote = await saveText(fp, textOut);
if (wrote) applied += 1;
else already += 1;
} catch (e) {
lastError = `write_error:${e}`;
}
@@ -5481,6 +5562,37 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
return report;
}
/**
* 页面加载前同步写入前端 client.js。只在字节真的变化时写盘。
* 启动 4 秒后的 settle 不得再写这些文件,否则 client-hmr 会把旧 rev 从缓存里拿掉(#63)。
* @returns 实际写过的包名
*/
export function patchWatchedClientBundlesSync(aiBase = findAiBase()) {
if (!aiBase) return [];
const files = targetFiles(aiBase);
const written = [];
for (const p of ALL_PATCHES) {
if (!patchAppliesHere(p)) continue;
for (const key of fileKeysOf(p)) {
for (const fp of pathsOf(files, key)) {
if (!isWatchedClientBundle(fp)) continue;
const text = fs.readFileSync(fp, "utf8");
const appliedText = applyReplacementsToText(text, p, fp);
if (!appliedText.changed) continue;
const next = Buffer.from(appliedText.text, "utf8");
const current = fs.readFileSync(fp);
if (current.equals(next)) continue;
const bak = `${fp}.dshpurge.bak`;
if (!fs.existsSync(bak)) fs.copyFileSync(fp, bak);
fs.writeFileSync(fp, next);
const packageName = clientBundlePackageName(fp);
if (packageName && !written.includes(packageName)) written.push(packageName);
}
}
}
return written;
}
export async function patchStatus(aiBase, patches = ALL_PATCHES) {
const files = targetFiles(aiBase);
const status = {};
@@ -5493,6 +5605,7 @@ export async function patchStatus(aiBase, patches = ALL_PATCHES) {
let applied = 0;
let pending = 0;
let skipped = 0;
let unmatched = 0;
let missing = 0;
for (const key of keys) {
const fps = pathsOf(files, key);
@@ -5510,12 +5623,14 @@ export async function patchStatus(aiBase, patches = ALL_PATCHES) {
}
const outcome = filePatchOutcome(text, p, fp);
if (outcome === "applied") applied += 1;
else if (outcome === "pending" || (p.strictFiles && outcome === "skipped")) pending += 1;
else if (outcome === "pending") pending += 1;
else if (p.strictFiles) unmatched += 1;
else skipped += 1;
}
}
if (pending > 0) status[p.id] = "pending";
else if (applied > 0) status[p.id] = "applied";
else if (unmatched > 0) status[p.id] = "unmatched";
else if (skipped > 0) status[p.id] = "skipped";
else status[p.id] = p.optional ? "na" : "missing_file";
}
@@ -6190,15 +6305,15 @@ export async function gatherState() {
let shim_cmd = "missing";
let shim_ps1 = "missing";
let shim_bin = "missing";
if (shimDir) {
shim_cmd = shimFileStatus(path.join(shimDir, "dsh.cmd"));
shim_ps1 = shimFileStatus(path.join(shimDir, "dsh.ps1"));
shim_bin = shimFileStatus(path.join(shimDir, "dsh"));
} else if (adapterFor(detectSurface()) === "desktop") {
// 桌面宿主不 patch CLI shim;缺目录不是失败。
if (adapterFor(detectSurface()) === "desktop") {
// 桌面宿主不改 CLI shim。PATH 上就算有网页端的 dsh,也不算进这一页。
shim_cmd = "n/a";
shim_ps1 = "n/a";
shim_bin = "n/a";
} else if (shimDir) {
shim_cmd = shimFileStatus(path.join(shimDir, "dsh.cmd"));
shim_ps1 = shimFileStatus(path.join(shimDir, "dsh.ps1"));
shim_bin = shimFileStatus(path.join(shimDir, "dsh"));
}
return {
surface: detectSurface(),
+19 -4
View File
@@ -1045,7 +1045,9 @@ function dshHomeForRelaunch() {
return current;
}
export function scheduleRestart(request, ctx, _options = {}) {
export function scheduleRestart(request, ctx, options = {}) {
// 启动自检会带 openBrowser:false。桌面进程不再因此杀掉自己。
if (options.openBrowser === false) return { restarting: false, skipped: true };
const exe =
officialExeFromProcess() ||
findDesktopAppExecutable() ||
@@ -1094,7 +1096,7 @@ function officialRestartScript(exe, asar, dshHome) {
"log('begin');",
"var promptFile = asar.replace(/app\\.asar$/i, 'app') + '\\\\dsh\\\\node_modules\\\\@deepseek-ai\\\\dsh-system-prompt\\\\lib\\\\index.js';",
"var clean = false;",
"if (fso.FileExists(promptFile)) { var tf = fso.OpenTextFile(promptFile, 1); var body = tf.ReadAll(); tf.Close(); clean = body.indexOf('[dsh-purge] identity stripped') >= 0 && body.indexOf('[dsh-purge] complete prompt keeps inject') >= 0; }",
"if (fso.FileExists(promptFile)) { var tf = fso.OpenTextFile(promptFile, 1); var body = tf.ReadAll(); tf.Close(); var ident = body.indexOf('[dsh-purge] identity stripped') >= 0; var kept = body.indexOf('[dsh-purge] complete prompt keeps waterfall inject') >= 0 || body.indexOf('[dsh-purge] complete prompt keeps inject') >= 0; clean = ident && kept; }",
"if (!clean) log('clean markers missing; not starting');",
"if (clean) {",
"log('clean markers ok');",
@@ -1118,11 +1120,14 @@ function officialRestartScript(exe, asar, dshHome) {
"if (!renamed) { log('rename failed; not starting'); }",
"if (renamed) {",
"try { sh.Environment('PROCESS').Remove('ELECTRON_RUN_AS_NODE'); } catch (ignore) {}",
"try { sh.Environment('PROCESS').Remove('DSH_BASE'); } catch (ignoreBase) {}",
"if (home) { try { sh.Environment('PROCESS').Item('DSH_HOME') = home; } catch (ignore2) {} }",
"sh.Run('\"' + exe + '\"', 1, false);",
"log('started');",
"}",
"}",
"WScript.Sleep(180000);",
"try { if (fso.FileExists(" + jsString(path.join(os.tmpdir(), "dsh-purge-official-restarting")) + ")) fso.DeleteFile(" + jsString(path.join(os.tmpdir(), "dsh-purge-official-restarting")) + ", true); } catch (ignoreFlag) {}",
"",
].join("\r\n");
}
@@ -1133,8 +1138,9 @@ function unpackedHostIsClean(exe) {
const fp = path.join(appDir, "dsh", "node_modules", "@deepseek-ai", "dsh-system-prompt", "lib", "index.js");
try {
const text = fs.readFileSync(fp, "utf8");
return text.includes("[dsh-purge] identity stripped")
&& text.includes("[dsh-purge] complete prompt keeps inject");
const kept = text.includes("[dsh-purge] complete prompt keeps waterfall inject")
|| text.includes("[dsh-purge] complete prompt keeps inject");
return text.includes("[dsh-purge] identity stripped") && kept;
} catch {
return false;
}
@@ -1167,6 +1173,15 @@ export function restartOfficialHarness(options = {}) {
if (options.requireClean !== false && !unpackedHostIsClean(exe)) {
return { restarting: false, clean: false };
}
const inflight = path.join(os.tmpdir(), "dsh-purge-official-restarting");
try {
const age = Date.now() - fs.statSync(inflight).mtimeMs;
// 同一次换进程里不再开第二轮,避免杀掉刚拉起来的客户端。
if (age >= 0 && age < 180000) return { restarting: true, already: true };
} catch {
// 没有进行中的重启。
}
try { fs.writeFileSync(inflight, `${Date.now()}\n`, "utf8"); } catch { /* 标记写失败仍继续这一次 */ }
const asar = options.asar || appAsarPath(exe);
const asarPresent = Boolean(asar && asarArchiveIsFile(asar));
const swapLock = asar ? `${asar}.swap-lock` : "";
+42 -14
View File
@@ -307,6 +307,21 @@ function rewriteLiveAssembly(config, assembled, context) {
});
}
/** 注册表若已经按旧文件算过 rev,立刻 rebuilt,让页面拿到的地址和缓存一致(#63)。 */
function publishClientBundleRevs(ctx, packageNames) {
if (!Array.isArray(packageNames) || packageNames.length === 0) return;
let mods = null;
try {
mods = ctx?.get?.("clientModules", false);
} catch {
mods = null;
}
if (!mods || typeof mods.rebuilt !== "function") return;
for (const id of packageNames) {
try { mods.rebuilt(id); } catch { /* 这一包还没进注册表,下次快照会读到新文件 */ }
}
}
/** Cordis 的 ctx 是 Proxy:未声明 inject 时点属性会抛 "cannot get property ... without inject",所以两段都要包 try。 */
function permissionPresetsOf(ctx) {
try {
@@ -446,6 +461,11 @@ async function settleInstalledPatches(config, ctx, life) {
log(config, "sealed desktop: skip startup reapply (wait for Apply)");
return "skip:sealed-wait-apply";
}
if (await reapply.hostCleanEnoughToKeep()) {
reapply.markPatchesApplied();
log(config, "host already clean; kept patches and refreshed stamp");
return "already-clean";
}
if (officialUpdate.upgradeMarkerExists(process.execPath)) {
const upgraded = await reapply.reapplyInstalled({ scheduleSwap: false, upgrade: true });
if (life && !life.alive) return "skip:inactive";
@@ -561,7 +581,7 @@ async function autoApply(config) {
return "disabled";
}
await core.backupAll(state.ai_base);
const report = await core.applyPatches(state.ai_base);
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
await core.patchAllShims();
const flash = core.silenceCmdFlash(state.ai_base);
const applied = report.filter((r) => r.status === "applied").length;
@@ -603,7 +623,7 @@ async function handlePurgeCommand(rawInput, config) {
const blocked = rejectIfNeedPrompt(state.dsh_home);
if (blocked) return { kind: "error", text: blocked.error };
await core.backupAll(state.ai_base);
const report = await core.applyPatches(state.ai_base);
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
const shimResult = await core.patchAllShims();
const flash = core.silenceCmdFlash(state.ai_base);
const lines = report.map((r) => {
@@ -928,6 +948,14 @@ export function apply(ctx, config) {
console.warn("[dsh-purge] hide-console error:", String(e));
}
core.applyRuntimeEnv();
// 页面打开前写前端 client.js。settle 在数秒之后,那时再写会让已发出的 rev 404(#63)。
try {
const written = core.patchWatchedClientBundlesSync();
publishClientBundleRevs(ctx, written);
if (written.length) log(cfg, "client bundles patched before page:", written.join(","));
} catch (e) {
console.warn("[dsh-purge] client bundle boot patch:", String(e && e.message ? e.message : e));
}
try { refreshHungOperator(core.findDshHome()); } catch { /* 主目录还没有提示词时段上留空 */ }
try {
const scrubbed = core.sanitizeDesktopCommandRuntimes();
@@ -1107,7 +1135,7 @@ function applyHostHooks(ctx, cfg) {
const blocked = rejectIfNeedPrompt(state.dsh_home);
if (blocked) return { text: "ERROR: " + blocked.error };
await core.backupAll(state.ai_base);
const report = await core.applyPatches(state.ai_base);
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
await core.patchAllShims();
const flash = core.silenceCmdFlash(state.ai_base);
const applied = report.filter((r) => r.status === "applied").length;
@@ -1238,6 +1266,11 @@ function installWebServer(ctx, cfg) {
patches_total: state.ai_base ? (state.patches_total || 0) : 0,
patches_lost: reapply.patchesLostAfterHostReset(),
patch_status: state.patch_status,
patches: core.ALL_PATCHES.map((p) => ({
id: p.id,
layer: p.layer || "",
status: state.patch_status[p.id] || (state.ai_base ? "missing_file" : "unlocated"),
})).filter((p) => p.status !== "na"),
patch_names,
shim_cmd: state.shim_cmd,
shim_ps1: state.shim_ps1,
@@ -1477,7 +1510,7 @@ function installWebServer(ctx, cfg) {
if (incoming !== null) await core.saveOverrideContent(state.dsh_home, incoming);
refreshHungOperator(state.dsh_home);
await core.backupAll(state.ai_base);
const report = await core.applyPatches(state.ai_base);
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
const override = await core.readOverrideForUi(state.dsh_home);
const shim = await core.patchAllShims();
let cliRepair = null;
@@ -1502,7 +1535,10 @@ function installWebServer(ctx, cfg) {
}
}
const leaveTray = renamed || pendingQuit;
if (complete) reapply.markPatchesApplied();
const onlyUnmatched = summary.failed.every((item) => item.status === "pattern_not_found");
if (flash.ok === true && onlyUnmatched && core.hostCleanMarkersPresent(state.ai_base)) {
reapply.markPatchesApplied();
}
if (leaveTray) bootFullQuit = true;
const sealedNow = core.desktopAsarStillSealed();
const shouldRestart = applyShouldRestart({
@@ -1539,15 +1575,6 @@ function installWebServer(ctx, cfg) {
cli_repair: cliRepair,
cmd_flash: flash,
});
if (shouldRestart && handoff && sealedNow) {
setImmediate(() => {
try {
core.restartSealedDesktopIfNeeded();
} catch (e) {
console.warn("[dsh-purge] asar swap after apply failed:", e);
}
});
}
} catch (e) {
sendJson(response, 500, { ok: false, error: String(e) });
}
@@ -1739,6 +1766,7 @@ function installWebServer(ctx, cfg) {
surface,
fullApp: surface === "desktop",
restarting: Boolean(planned && (planned.restarting || planned.asarSwap)),
already: Boolean(planned && planned.already),
needsFullQuit: Boolean(planned && planned.asarSwap),
asar_still_sealed: core.desktopAsarStillSealed(),
note: "正在重启。",
+19 -2
View File
@@ -128,6 +128,22 @@ export function patchesMatchInstall() {
return hostStillHasAppliedPatches();
}
/**
* 宿主上的清洗还在,只是版本戳旧了。启动时不能因此 revertAll,
* 否则用户点应用并重启后,页面会回到「要重新清洗」。
*/
export async function hostCleanEnoughToKeep() {
let aiBase = "";
try {
aiBase = core.findAiBase() || "";
} catch {
return false;
}
if (!aiBase || !core.hostCleanMarkersPresent(aiBase)) return false;
const status = await core.patchStatus(aiBase);
return !Object.values(status).some((row) => row === "pending");
}
/** 有 applied 戳但宿主已回到密封 asar / 清洗标记没了:面板提示「补丁已丢失」(#57)。找不到根不算丢失。 */
export function patchesLostAfterHostReset() {
const stamp = readAppliedStamp();
@@ -251,10 +267,11 @@ export async function reapplyInstalled(options = {}) {
}
if (!aiBase) return { ok: false, error: core.missingAiBaseMessage() };
// 刚解开的是官方原件。已经在用的目录仍先还原再按这一版重打。
const reverted = freshExtract ? { reverted: [] } : await core.revertAll(aiBase);
const preserveClientBundles = options.preserveClientBundles !== false;
const reverted = freshExtract ? { reverted: [] } : await core.revertAll(aiBase, { preserveClientBundles });
if (!freshExtract) await core.revertAllShims();
await core.backupAll(aiBase);
const report = await core.applyPatches(aiBase);
const report = await core.applyPatches(aiBase, core.ALL_PATCHES, { preserveClientBundles });
await core.patchAllShims();
const flash = core.silenceCmdFlash(aiBase);
const summary = core.summarizeApplyReport(report);
+2 -2
View File
@@ -28,7 +28,7 @@ window.__ModuleLoader__.load({
这里放占位符,由 bundle 的 build.mjs 在生成 lib/client.js 时替换成正文。 */
const CSS = `
:root{--rt-dock-w:620px}
/* 右侧栏收起时给 frame 加内边距,中栏主动收窄。属性名跨 DSH 版本兼容:\n 旧版 details 栏 data-details-collapsed,新版 rightbar 栏 data-rightbar-collapsed。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-details-collapsed],\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-rightbar-collapsed]{padding-right:var(--rt-dock-w)}
/* 右侧栏收起时给 frame 加内边距,中栏主动收窄。属性名跨 DSH 版本兼容:\n 旧版 details 栏 data-details-collapsed,新版 rightbar 栏 data-rightbar-collapsed。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-details-collapsed],\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-rightbar-collapsed]{padding-right:var(--rt-dock-w)}
.rt-dock{position:absolute;top:0;right:0;bottom:0;z-index:20;display:flex;flex-direction:column;
background:color-mix(in srgb,var(--dsw-alias-bg-layer-1,#1c1c1c) 52%,transparent);
backdrop-filter:blur(20px) saturate(1.3);-webkit-backdrop-filter:blur(20px) saturate(1.3);
@@ -36,7 +36,7 @@ window.__ModuleLoader__.load({
box-shadow:-12px 0 32px color-mix(in srgb,#000 22%,transparent);pointer-events:auto;color:var(--dsw-alias-label-primary);
font-size:13px;line-height:1.5;transition:transform .18s ease,opacity .18s ease}
.rt-dock.rt-embedded{position:relative;background:transparent!important;border:0;box-shadow:none;backdrop-filter:none;-webkit-backdrop-filter:none}
/* 右侧栏打开(或新版全屏)时让位:滑出隐藏。必须同时否定两个属性名——\n 旧写法只用 :not([data-details-collapsed]),在新 shell 里该属性不存在会导致条件恒真、面板永远打不开。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]):not([data-details-collapsed]):not([data-rightbar-collapsed]) .rt-dock,\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"])[data-rightbar-fullscreen] .rt-dock{
/* 右侧栏打开(或新版全屏)时让位:滑出隐藏。必须同时否定两个属性名——\n 旧写法只用 :not([data-details-collapsed]),在新 shell 里该属性不存在会导致条件恒真、面板永远打不开。 */\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded)):not([data-details-collapsed]):not([data-rightbar-collapsed]) .rt-dock,\ndiv:has(> [data-shell-overlay] .rt-dock[data-open="1"]:not(.rt-embedded))[data-rightbar-fullscreen] .rt-dock{
transform:translateX(100%);opacity:0;pointer-events:none}
.rt-grip{position:absolute;left:-3px;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:2}
.rt-head{display:flex;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--dsw-alias-border-l1)}
+20 -28
View File
@@ -633,34 +633,26 @@ export function markCurrent(versions, state, localVer, localSha) {
const pin = String(state?.pin || "");
const rows = versions || [];
const ver = String(localVer || "").replace(/^v/i, "");
const shaMatched = rows.some((item) => localSha && item.sha && sameRev(localSha, item.sha));
const versionOnLatest = rows.some((item) => (
item.latest
&& item.channel === state?.channel
&& String(item.version || "").replace(/^v/i, "") === ver
));
const versionFallback = versionOnLatest ? null : rows.find((item) => (
item.channel === state?.channel
&& String(item.version || "").replace(/^v/i, "") === ver
));
return rows.map((item) => {
const shaHit = Boolean(!pin && localSha && item.sha && sameRev(localSha, item.sha));
const pinHit = Boolean(pin && item.ref === pin);
// 提交号对不上时,只把本通道里和本机版本号相同的那一条标成当前。
const headHit = Boolean(
!pin
&& !shaMatched
&& ver
&& (versionOnLatest
? item.latest && item.channel === state?.channel && String(item.version || "").replace(/^v/i, "") === ver
: versionFallback && item === versionFallback)
);
return {
...item,
shaShort: item.shaShort || (item.sha ? String(item.sha).slice(0, 7) : ""),
current: pinHit || shaHit || headHit,
};
});
const channel = state?.channel || "stable";
const sameVersion = (item) => ver && String(item?.version || "").replace(/^v/i, "") === ver && item.channel === channel;
const sameSha = (item) => Boolean(localSha && item?.sha && sameRev(localSha, item.sha));
let chosen = null;
if (pin) {
chosen = rows.find((item) => item.ref === pin) || null;
} else {
const pool = rows.filter(sameVersion);
// 安装记录里的旧提交号不能把较低版本标成当前。只认和正在跑的 package.json 相同的版本。
chosen = pool.find((item) => sameSha(item) && (item.latest || item.ref === "master" || item.kind === "head"))
|| pool.find((item) => item.latest || item.ref === "master" || item.kind === "head")
|| pool.find((item) => sameSha(item))
|| pool[0]
|| null;
}
return rows.map((item) => ({
...item,
shaShort: item.shaShort || (item.sha ? String(item.sha).slice(0, 7) : ""),
current: Boolean(chosen && item === chosen),
}));
}
async function listGithubTags() {