mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 11:30:22 +08:00
feat: 设置页可卸载,AI 安装说明只跑官方 add
This commit is contained in:
1 parent
bea3877f4d
commit
fbd17e277e
13 files changed
+810
-124
No files matched your search
+45
-2
@@ -15,6 +15,7 @@ import {
|
||||
shouldInjectPrompt,
|
||||
} from "./identity.js";
|
||||
import * as rewind from "./rewind.js";
|
||||
import * as uninstaller from "./uninstall.js";
|
||||
|
||||
export const name = "dsh-purge";
|
||||
|
||||
@@ -348,6 +349,23 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
lines.push("注: prompt-inject.md 保留(用户文件)/ prompt-inject.md kept (user file)");
|
||||
return { kind: "success", text: lines.join("\n") };
|
||||
}
|
||||
case "uninstall":
|
||||
case "remove": {
|
||||
const result = await uninstaller.uninstallPurge();
|
||||
const lines = [];
|
||||
if (result.applied) lines.push("已检测到补丁,已还原回原版。");
|
||||
else lines.push("未检测到已应用补丁,仍会清除插件文件。");
|
||||
if (result.patches) {
|
||||
lines.push(` 还原文件 ${result.patches.reverted?.length || 0} 个`);
|
||||
}
|
||||
if (result.override?.removed) lines.push(` 已删除 ${result.override.path}`);
|
||||
if (result.stripped?.length) lines.push(` 已从 profile 移除: ${result.stripped.join(", ")}`);
|
||||
if (result.errors?.length) {
|
||||
for (const e of result.errors) lines.push(` ⚠ ${e}`);
|
||||
}
|
||||
lines.push("", "请重启 dsh。重启后插件不再加载。");
|
||||
return { kind: result.ok ? "success" : "error", text: lines.join("\n") };
|
||||
}
|
||||
case "edit":
|
||||
case "e": {
|
||||
const state = await core.gatherState();
|
||||
@@ -374,6 +392,7 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
" /purge status 显示状态\n" +
|
||||
" /purge apply 应用全部清洗(提示词+代码+shim+override)\n" +
|
||||
" /purge revert 回滚还原\n" +
|
||||
" /purge uninstall 卸载插件(已应用则先还原)\n" +
|
||||
" /purge edit 编辑注入文件 prompt-inject.md\n" +
|
||||
" /purge help 显示帮助\n" +
|
||||
"规则集切换见 /rules(list | use <id> | create | delete | reset)",
|
||||
@@ -530,8 +549,8 @@ export function apply(ctx, config) {
|
||||
if (commands) {
|
||||
commands.register({
|
||||
name: "purge",
|
||||
description: "dsh 指令权威性清洗(status/apply/revert/edit/help)",
|
||||
input: { hint: "status | apply | revert | edit | help" },
|
||||
description: "dsh 指令权威性清洗(status/apply/revert/uninstall/edit/help)",
|
||||
input: { hint: "status | apply | revert | uninstall | edit | help" },
|
||||
handler: async (invocation) => handlePurgeCommand(invocation.rawInput ?? "", cfg),
|
||||
});
|
||||
commands.register({
|
||||
@@ -941,6 +960,30 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: revert");
|
||||
host.webServer.register({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/uninstall",
|
||||
handler: async (request, response) => {
|
||||
if (request.method !== "POST") {
|
||||
response.writeHead(405, { allow: "POST" });
|
||||
response.end();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const result = await uninstaller.uninstallPurge();
|
||||
sendJson(response, result.ok ? 200 : 500, result);
|
||||
if (result.ok) {
|
||||
uninstaller.scheduleCleanupRestart({
|
||||
request,
|
||||
restartArgv: restartArgv(),
|
||||
cleanup: result.cleanup,
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e && e.message ? e.message : e) });
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: uninstall");
|
||||
host.webServer.register({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/override",
|
||||
|
||||
Reference in new issue
Block a user