feat: 设置页可卸载,AI 安装说明只跑官方 add

This commit is contained in:
叫我小杨同学 committed 2026-09-18 15:10:15 +08:00
1 parent bea3877f4d
commit fbd17e277e
13 files changed
+810 -124

No files matched your search

+135
View File
@@ -10,6 +10,7 @@ import {
installHideConsole,
installHideConsoleIntoBin,
resolveDshBinRoot,
revertHideConsoleFromBin,
} from "./hide-console.js";
const isWindows = process.platform === "win32";
@@ -334,6 +335,140 @@ export function silenceCmdFlash(aiBase = findAiBase()) {
};
}
function rewriteFiles(files, rewrite) {
let hit = "missing";
for (const fp of files) {
let text;
try {
text = fs.readFileSync(fp, "utf8");
} catch {
continue;
}
const next = rewrite(text);
if (next == null || next === text) {
if (hit === "missing") hit = "absent";
continue;
}
try {
fs.writeFileSync(fp, next, "utf8");
hit = "reverted";
} catch (e) {
hit = `error:${e}`;
}
}
return hit;
}
export function revertCmdFlash(aiBase = findAiBase(), dshHome = findDshHome()) {
const hide = revertHideConsoleFromBin(aiBase);
const subprocess = rewriteFiles(listSubprocessLocalFiles(dshHome), (text) => {
const marker = "[dsh-purge] subprocess-local windowsHide";
if (!text.includes(marker)) return text;
return text
.replace(/\n\t\t\/\/ \[dsh-purge\] subprocess-local windowsHide\n\t\twindowsHide: true/, "")
.replace(",\n\t\t// [dsh-purge] subprocess-local windowsHide\n\t\twindowsHide: true", "");
});
const customBash = rewriteFiles(listLiangshenCustomBashFiles(dshHome), (text) => {
const marker = "[dsh-purge] never fall back to WSL System32 bash";
if (!text.includes(marker)) return text;
const needle =
" try {\n" +
" return await ctx.subprocess.resolveExecutable('bash', undefined, signal)\n" +
" } catch (error) {\n";
const replacement =
" // " +
marker +
"\n" +
" try {\n" +
" const resolved = await ctx.subprocess.resolveExecutable('bash', undefined, signal)\n" +
" if (/[\\\\/](System32|SysWOW64|WindowsApps)[\\\\/]bash\\.exe$/i.test(resolved)) {\n" +
" throw new Error('WSL bash launcher is not Git Bash')\n" +
" }\n" +
" return resolved\n" +
" } catch (error) {\n";
return text.includes(replacement) ? text.replace(replacement, needle) : text;
});
const phase1 = rewriteFiles(listLiangshenBootstrapFiles(dshHome), (text) => {
if (!text.includes("[dsh-purge]") && !text.includes("dsh-purge:")) return text;
let next = text.replace(/\r\n/g, "\n");
const origSet = "const PERSONA_SECTION_NAMES = new Set(['deployment:persona', 'persona'])";
next = next.replace(
/const PERSONA_SECTION_NAMES = new Set\(\[[^\]]*dsh-purge[^\]]*\]\)/,
origSet,
);
const officialFilter =
" const sections = Array.isArray(assembled.sections)\n" +
" ? assembled.sections.filter(section => PERSONA_SECTION_NAMES.has(section?.name))\n" +
" : undefined";
const wideFilter =
" const sections = Array.isArray(assembled.sections)\n" +
' ? assembled.sections.filter(section => PERSONA_SECTION_NAMES.has(section?.name) || String(section?.name || "").startsWith("dsh-purge"))\n' +
" : undefined";
next = next.replace(wideFilter, officialFilter);
next = next.replace(/\n \/\/ \[dsh-purge\] phase-1 keep persona\+inject sections/g, "");
next = next.replace(/\n \/\/ \[dsh-purge\] phase-1 keep full system-prompt sections/g, "");
return next;
});
const doctorSpawn = rewriteFiles(listDoctorCliFiles(dshHome), (text) => {
if (!text.includes("[dsh-purge]")) return text;
let next = text;
const spawnNeedle = 'import { spawn } from "node:child_process";';
next = next.replace(
/import \{ spawn as __dshPurgeSpawnOrig \} from "node:child_process";\n\/\/ \[dsh-purge\] doctor spawn windowsHide\nfunction spawn\(file, args, options\) \{[\s\S]*?\n\}\n/,
spawnNeedle + "\n",
);
const specNeedle =
'function dshSpawnSpec(binary, args, platform = process.platform) {\n' +
'\tif (platform === "win32") {\n' +
'\t\tif (binary.toLowerCase().endsWith(".cmd") || binary.toLowerCase().endsWith(".bat")) return {\n' +
'\t\t\tcommand: "cmd.exe",\n' +
'\t\t\targs: windowsCmdShimArgs(binary, args),\n' +
'\t\t\twindowsVerbatimArguments: true\n' +
'\t\t};';
if (next.includes("[dsh-purge] dsh.cmd → node bin.js (no cmd.exe)")) {
next = next.replace(
/function dshSpawnSpec\(binary, args, platform = process\.platform\) \{\n\tif \(platform === "win32"\) \{\n\t\tif \(binary\.toLowerCase\(\)\.endsWith\("\.cmd"\) \|\| binary\.toLowerCase\(\)\.endsWith\("\.bat"\)\) \{[\s\S]*?\t\t\}/,
specNeedle,
);
}
const stdioNeedle =
'const child = spawnDsh(realDsh, options.argv, {\n' +
'\t\tstdio: [\n' +
'\t\t\t"inherit",\n' +
'\t\t\t"inherit",\n' +
'\t\t\t"pipe"\n' +
'\t\t],';
if (next.includes("[dsh-purge] doctor launch stdio no-inherit")) {
next = next.replace(
/const child = spawnDsh\(realDsh, options\.argv, \{\n\t\t\/\/ \[dsh-purge\] doctor launch stdio no-inherit\n\t\tstdio: \[\n\t\t\t"ignore",\n\t\t\t"ignore",\n\t\t\t"pipe"\n\t\t\],\n\t\twindowsHide: true,/,
stdioNeedle,
);
}
return next;
});
const market = rewriteFiles(listDshmarketRestartFiles(dshHome), (text) => {
const marker = "[dsh-purge] market restart → node bin.js (no powershell/dsh.cmd)";
if (!text.includes(marker)) return text;
const needle =
"export function respawnInvocation(launch, platform = process.platform) {\n" +
" if (platform !== 'win32') {\n" +
" return { file: launch.file, args: launch.args, viaShell: launch.viaShell, detached: true };\n" +
" }\n";
let next = text.replace(
/export function respawnInvocation\(launch, platform = process\.platform\) \{\n if \(platform !== 'win32'\) \{\n return \{ file: launch\.file, args: launch\.args, viaShell: launch\.viaShell, detached: true \};\n \}\n \/\/ \[dsh-purge\] market restart[^\n]*\n \{[\s\S]*?\n \}\n/,
needle,
);
const importNeedle = "import { tmpdir } from 'node:os';\nimport { join } from 'node:path';";
const importReplacement =
"import { existsSync } from 'node:fs';\n" +
"import { tmpdir } from 'node:os';\n" +
"import { dirname, join } from 'node:path';";
if (next.includes(importReplacement)) next = next.replace(importReplacement, importNeedle);
return next;
});
return { hide, subprocess, customBash, phase1, doctorSpawn, market };
}
export function silenceSubprocessLocalFlash(dshHome = findDshHome()) {
if (process.platform !== "win32") return "skipped_not_win32";
const marker = "[dsh-purge] subprocess-local windowsHide";