mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 13:10:22 +08:00
fix: 发布 1.1.57,应用后挂上提示词并让 Messages 使用当前系统提示
官方其余模式与标准一样清拦截。演练授权按本机目录保留,卸载成功后才清。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
54351cff82
commit
2c07aafead
12 files changed
+694
-271
No files matched your search
+48
-6
@@ -11,6 +11,7 @@ import {
|
||||
isMnemonPluginMessage,
|
||||
isRedteamSession,
|
||||
installAssembleGuard,
|
||||
modePromptText,
|
||||
rewritePromptAssembly,
|
||||
} from "./identity.js";
|
||||
import { capabilityProtocolText, CAPABILITY_SECTION } from "./capability-protocol.js";
|
||||
@@ -18,6 +19,7 @@ import { installSubagentRoleCapture, resolveSubagentRoleText } from "./redteam/r
|
||||
import * as rewind from "./rewind.js";
|
||||
import * as continueRetry from "./continue-retry.js";
|
||||
import * as uninstaller from "./uninstall.js";
|
||||
import { readDrillGrant, writeDrillGrant } from "./drill-grant.js";
|
||||
import { installRegionGate, readAllowText, writeAllowText } from "./net-scope.js";
|
||||
import * as refusalRecover from "./refusal-recover.js";
|
||||
import {
|
||||
@@ -174,6 +176,13 @@ function injectAllowedNow(config) {
|
||||
return config.enabled !== false;
|
||||
}
|
||||
|
||||
/** 有默认提示词用默认,没有才用当前规则集。两边都空则段上不挂正文。 */
|
||||
function refreshHungOperator(dshHome = core.findDshHome()) {
|
||||
const resolved = rules.resolveInjectText(dshHome);
|
||||
core.hangOperatorPrompt(resolved.text);
|
||||
return resolved;
|
||||
}
|
||||
|
||||
function injectSnapshot(dshHome = core.findDshHome()) {
|
||||
const resolved = rules.resolveInjectText(dshHome);
|
||||
return {
|
||||
@@ -255,7 +264,9 @@ export function registerPromptSections(ctx, config, _injectFile) {
|
||||
}
|
||||
|
||||
function readInjectFallback(context) {
|
||||
return rules.resolveModeInject(core.findDshHome(), isRedteamSession(context));
|
||||
const raw = core.hungOperatorPrompt();
|
||||
if (!String(raw || "").trim()) return "";
|
||||
return modePromptText(raw, isRedteamSession(context));
|
||||
}
|
||||
|
||||
function installMnemonMessageStrip(ctx, config = {}) {
|
||||
@@ -576,8 +587,10 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
case "a": {
|
||||
core.applyRuntimeEnv();
|
||||
core.clearDesktopLocateCache();
|
||||
const home = core.pinDshHome();
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
const state = await core.gatherState();
|
||||
if (home) state.dsh_home = home;
|
||||
let handoff = null;
|
||||
if (!state.ai_base) {
|
||||
const opened = await core.openSealedDesktopHost();
|
||||
@@ -723,6 +736,7 @@ async function handleRulesCommand(rawInput) {
|
||||
if (!id) return { kind: "error", text: "用法: /rules use <id>" };
|
||||
try {
|
||||
const meta = await rules.activateRule(dshHome, id);
|
||||
refreshHungOperator(dshHome);
|
||||
return {
|
||||
kind: "success",
|
||||
text: `✓ 已激活规则 ${meta.name}(${id})→ 写入 ${rules.targetPath(dshHome, meta.target)},并注入 systemPrompt。新会话生效。`,
|
||||
@@ -758,6 +772,7 @@ async function handleRulesCommand(rawInput) {
|
||||
if (!id) return { kind: "error", text: "用法: /rules delete <id>" };
|
||||
try {
|
||||
await rules.deleteRule(dshHome, id);
|
||||
refreshHungOperator(dshHome);
|
||||
return { kind: "success", text: `✓ 已删除规则 ${id}。` };
|
||||
} catch (e) {
|
||||
return { kind: "error", text: `删除失败: ${e.message}` };
|
||||
@@ -768,6 +783,7 @@ async function handleRulesCommand(rawInput) {
|
||||
case "还原": {
|
||||
try {
|
||||
const r = await rules.resetToOriginal(dshHome);
|
||||
refreshHungOperator(dshHome);
|
||||
const lines = [];
|
||||
if (r.removed.length > 0) lines.push(`✓ 已删除插件写入的目标文件: ${r.removed.join(", ")}`);
|
||||
if (r.skipped.length > 0) {
|
||||
@@ -912,6 +928,7 @@ export function apply(ctx, config) {
|
||||
console.warn("[dsh-purge] hide-console error:", String(e));
|
||||
}
|
||||
core.applyRuntimeEnv();
|
||||
try { refreshHungOperator(core.findDshHome()); } catch { /* 主目录还没有提示词时段上留空 */ }
|
||||
try {
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
if (scrubbed.length) log(cfg, "desktop runtime scrub on load:", JSON.stringify(scrubbed));
|
||||
@@ -1425,10 +1442,14 @@ function installWebServer(ctx, cfg) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const body = await readJsonBody(request);
|
||||
const incoming = typeof body?.content === "string" ? body.content : null;
|
||||
core.applyRuntimeEnv();
|
||||
core.clearDesktopLocateCache();
|
||||
const home = core.pinDshHome();
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
const state = await core.gatherState();
|
||||
if (home) state.dsh_home = home;
|
||||
let handoff = null;
|
||||
if (!state.ai_base) {
|
||||
const opened = await core.openSealedDesktopHost();
|
||||
@@ -1441,21 +1462,20 @@ function installWebServer(ctx, cfg) {
|
||||
} else {
|
||||
handoff = core.sealedAsarHandoff();
|
||||
}
|
||||
const body = await readJsonBody(request);
|
||||
const incoming = typeof body?.content === "string" ? body.content : "";
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home, incoming);
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home, incoming === null ? undefined : incoming);
|
||||
if (blocked) {
|
||||
const ui = await core.readOverrideForUi(state.dsh_home);
|
||||
sendJson(response, 400, {
|
||||
ok: false,
|
||||
needPrompt: true,
|
||||
override_content: incoming,
|
||||
override_content: incoming || "",
|
||||
defaultContent: ui.defaultContent,
|
||||
...blocked,
|
||||
});
|
||||
return;
|
||||
}
|
||||
await core.saveOverrideContent(state.dsh_home, incoming);
|
||||
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 override = await core.readOverrideForUi(state.dsh_home);
|
||||
@@ -1586,6 +1606,23 @@ function installWebServer(ctx, cfg) {
|
||||
}
|
||||
},
|
||||
}, "dsh-purge: uninstall");
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/drill-grant",
|
||||
handler: async (request, response) => {
|
||||
const home = core.findDshHome();
|
||||
if (request.method === "GET") {
|
||||
sendJson(response, 200, { ok: true, ...readDrillGrant(home) });
|
||||
return;
|
||||
}
|
||||
if (request.method === "POST") {
|
||||
sendJson(response, 200, { ok: true, ...writeDrillGrant(home) });
|
||||
return;
|
||||
}
|
||||
response.writeHead(405, { allow: "GET, POST" });
|
||||
response.end();
|
||||
},
|
||||
}, "dsh-purge: drill-grant");
|
||||
registerPluginRoute({
|
||||
kind: "exact",
|
||||
path: "/dsh-purge/override",
|
||||
@@ -1619,6 +1656,7 @@ function installWebServer(ctx, cfg) {
|
||||
return;
|
||||
}
|
||||
const saved = await core.saveOverrideContent(home, content);
|
||||
refreshHungOperator(home);
|
||||
sendJson(response, 200, { ok: true, ...saved, ...injectSnapshot(home) });
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
@@ -1743,11 +1781,13 @@ async function handleRulesOp(op, body, queryId) {
|
||||
name: typeof body?.name === "string" ? body.name : undefined,
|
||||
target: typeof body?.target === "string" ? body.target : undefined,
|
||||
});
|
||||
refreshHungOperator(dshHome);
|
||||
return { ok: true, id, ...injectSnapshot(dshHome) };
|
||||
}
|
||||
if (op === "activate") {
|
||||
if (!rules.validRuleId(id)) return { status: 400, ok: false, error: "invalid id" };
|
||||
const meta = await rules.activateRule(dshHome, id);
|
||||
refreshHungOperator(dshHome);
|
||||
return {
|
||||
ok: true,
|
||||
id,
|
||||
@@ -1761,10 +1801,12 @@ async function handleRulesOp(op, body, queryId) {
|
||||
if (op === "delete") {
|
||||
if (!rules.validRuleId(id)) return { status: 400, ok: false, error: "invalid id" };
|
||||
await rules.deleteRule(dshHome, id);
|
||||
refreshHungOperator(dshHome);
|
||||
return { ok: true, id };
|
||||
}
|
||||
if (op === "reset") {
|
||||
const r = await rules.resetToOriginal(dshHome);
|
||||
refreshHungOperator(dshHome);
|
||||
return { ok: true, ...r, note: "已还原出厂状态(无全局指令);规则库保留" };
|
||||
}
|
||||
return { status: 400, ok: false, error: `unknown op: ${op}` };
|
||||
|
||||
Reference in new issue
Block a user