fix: 发布 1.1.66,Hooks 开关与会话来源

清洗页可关掉 hooks deny 旁路。继续/拒答续跑改用官方允许的来源 kind,限流和传输失败不再自动续一轮。

Closes #80. Closes #81.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-09 01:32:17 +08:00
1 parent 76e64d65e0
commit 09bac57f2c
13 files changed
+789 -59

No files matched your search

+83 -10
View File
@@ -58,6 +58,7 @@ const DEFAULTS = {
refusalRecoverText: "",
// Codex 风格:教模型主动发现 skill / MCP;不改官方注册与工具面。
capabilityProtocol: true,
hooksDenyBypass: true,
};
const log = (config, ...args) => {
@@ -162,11 +163,26 @@ function injectAllowedNow(config) {
/** 提示词框自改 > prompt-inject.md > 加密默认(见 rules.resolveInjectText)。 */
function refreshHungOperator(dshHome = core.findDshHome()) {
const home = dshHome || core.findDshHome();
const home = core.pinDshHome() || dshHome || core.findDshHome();
try { core.syncPromptInjectOnDiskSync(home); } catch { /* 同步失败仍按 resolve 走 */ }
const resolved = rules.resolveInjectText(home);
core.hangOperatorPrompt(resolved.text);
return resolved;
const text = resolved.text || core.normalizeOverride(core.defaultOverrideText()) || "";
if (text) {
core.hangOperatorPrompt(text);
// 与点「保存」同一钉钉:不点保存,组装也要读到这一份全文。
core.rememberCommittedOverride(home, text);
}
return { ...resolved, text: text || resolved.text };
}
function installHungPromptGlobal() {
globalThis.__dshPurgeHungPrompt = () => {
try {
return refreshHungOperator(core.findDshHome()).text || "";
} catch {
return core.hungOperatorPrompt() || "";
}
};
}
function injectSnapshot(dshHome = core.findDshHome()) {
@@ -269,7 +285,7 @@ export function registerPromptSections(ctx, config, _injectFile) {
function readInjectFallback(context) {
let home = "";
try { home = core.findDshHome(); } catch { home = ""; }
const raw = rules.ensureOperatorBody(home);
const raw = refreshHungOperator(home).text || rules.ensureOperatorBody(home);
if (!raw) return "";
let redteam = false;
try { redteam = isRedteamSession(context); } catch { redteam = false; }
@@ -418,7 +434,7 @@ function installIdentityOverride(ctx, config = {}) {
// 切换预设会换掉 assemble。pre-step 瀑布在 assemble 之后才跑,第一次发送包不上。
// 宿主在 assemble 之前调用这个函数,用的就是当前模式自己的 systemPrompt。
const prepareAssemble = (loopCtx) => {
try { rules.ensureOperatorBody(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
try { refreshHungOperator(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
const prompt = loopCtx && loopCtx.systemPrompt;
if (prompt) {
try {
@@ -428,8 +444,10 @@ function installIdentityOverride(ctx, config = {}) {
} catch { /* 这一层代理包不上时,下面再包插件自己的 */ }
}
wrapAssemble();
return prompt || null;
};
globalThis.__dshPurgePrepareAssemble = prepareAssemble;
installHungPromptGlobal();
// complete:true 会在 waterfall 之后盖掉 sections;包住 assemble 返回值,每轮都补回注入。
wrapAssemble();
const started = Date.now();
@@ -442,7 +460,7 @@ function installIdentityOverride(ctx, config = {}) {
try { ctx.on("session/created", wrapAssemble); } catch { /* ignore */ }
try {
ctx.on("agent-preset/selected", () => {
try { rules.ensureOperatorBody(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
try { refreshHungOperator(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
wrapAssemble();
}, { global: true });
} catch { /* ignore */ }
@@ -581,6 +599,14 @@ async function autoApply(config) {
const sanitized = core.sanitizeDesktopCommandRuntimes();
if (sanitized.length) log(config, "desktop runtime sanitized:", JSON.stringify(sanitized));
core.refreshHooksDenySettings();
if (core.getHooksDenySettings().hooksDenyBypass === false) {
const restored = await core.restoreHookDenyForBases(core.enumeratePatchAiBases());
if (restored.failed.length) {
log(config, "hooks-deny restore leftover:", restored.failed.join(","));
}
}
const state = await core.gatherState();
if (!state.ai_base) {
log(config, "skip auto-apply: plugin root not found");
@@ -696,7 +722,8 @@ async function handlePurgeCommand(rawInput, config) {
lines.push("Desktop: host-commands 密封目录只清理不注入;bak 禁止写进 bin(issue #9)。");
const summary = core.summarizeApplyReport(report);
const hostWritten = core.allPatchHostsWritten(applyMulti.hosts) || core.hostCleanMarkersPresent(state.ai_base);
const complete = summary.failed.length === 0 && flash.ok === true && hostWritten;
const hookDenyRestoreFailed = (applyMulti.hookDenyRestoreFailed || []).length > 0;
const complete = summary.failed.length === 0 && flash.ok === true && hostWritten && !hookDenyRestoreFailed;
const promptReady = summary.failed.length > 0 && summary.failed.every((item) => item.status === "pattern_not_found");
const shouldRestart = applyShouldRestart({
complete: complete || (promptReady && hostWritten),
@@ -1004,6 +1031,19 @@ async function handleSkillsCommand(rawInput) {
export function apply(ctx, config) {
const cfg = { ...DEFAULTS, ...(config || {}) };
if (!cfg.enabled) return;
core.setHooksDenyConfigValue(cfg.hooksDenyBypass);
core.refreshHooksDenySettings();
try {
const home = core.pinDshHome() || core.findDshHome();
installHungPromptGlobal();
refreshHungOperator(home);
} catch { /* 主目录还没有时,组装会再挂内置默认 */ }
try {
const restored = core.restoreMissingOriginalsAllHosts();
if (restored.length) log(cfg, "restored missing overlay from bak:", restored.join(","));
} catch (e) {
console.warn("[dsh-purge] restore bak:", String(e && e.message ? e.message : e));
}
const life = watchContextLife(ctx);
if (!life.alive) {
console.warn("[dsh-purge] skip apply: inactive context");
@@ -1080,7 +1120,7 @@ export function apply(ctx, config) {
function applyHostHooks(ctx, cfg) {
try {
const home = core.pinDshHome() || core.findDshHome();
rules.ensureOperatorBody(home);
refreshHungOperator(home);
} catch { /* 主目录尚未就绪 */ }
installIdentityOverride(ctx, cfg);
installRegionGate(ctx);
@@ -1349,6 +1389,7 @@ function installWebServer(ctx, cfg) {
boot_full_quit: bootFullQuit,
update: updater.lastUpdateResult(),
...updater.channelPublic(),
hooks_deny_bypass: core.getHooksDenySettings().hooksDenyBypass,
...(await skills.skillsStatus(core.findDshHome()).catch(() => ({ skills: [] }))),
});
} catch (e) {
@@ -1356,6 +1397,37 @@ function installWebServer(ctx, cfg) {
}
},
}, "dsh-purge: status");
registerPluginRoute({
kind: "exact",
path: "/dsh-purge/hooks-deny",
handler: async (request, response) => {
if (request.method === "GET") {
try {
const settings = core.refreshHooksDenySettings();
sendJson(response, 200, { ok: true, hooksDenyBypass: settings.hooksDenyBypass });
} catch (e) {
sendJson(response, 500, { ok: false, error: String(e) });
}
return;
}
if (request.method === "POST") {
try {
const body = await readJsonBody(request);
if (typeof body?.hooksDenyBypass !== "boolean") {
sendJson(response, 400, { ok: false, error: "hooksDenyBypass must be boolean" });
return;
}
const saved = core.setHooksDenySettings({ hooksDenyBypass: body.hooksDenyBypass });
sendJson(response, 200, { ok: true, hooksDenyBypass: saved.hooksDenyBypass });
} catch (e) {
sendJson(response, 500, { ok: false, error: String(e) });
}
return;
}
response.writeHead(405, { allow: "GET, POST" });
response.end();
},
}, "dsh-purge: hooks-deny");
registerPluginRoute({
kind: "exact",
path: "/dsh-purge/last-user",
@@ -1511,7 +1583,7 @@ function installWebServer(ctx, cfg) {
});
return;
}
if (incoming !== null) {
if (typeof incoming === "string" && core.normalizeOverride(incoming)) {
await core.saveOverrideContent(state.dsh_home, incoming);
}
const httpMulti = await core.applyPatchesAllHosts(core.ALL_PATCHES, {
@@ -1530,7 +1602,8 @@ function installWebServer(ctx, cfg) {
const summary = core.summarizeApplyReport(report);
const hostWritten =
core.allPatchHostsWritten(httpMulti.hosts) || core.hostCleanMarkersPresent(state.ai_base);
const complete = summary.failed.length === 0 && flash.ok === true && hostWritten;
const hookDenyRestoreFailed = (httpMulti.hookDenyRestoreFailed || []).length > 0;
const complete = summary.failed.length === 0 && flash.ok === true && hostWritten && !hookDenyRestoreFailed;
const sealedNow = core.desktopAsarStillSealed();
const promptReady = summary.failed.length > 0 && summary.failed.every((item) => item.status === "pattern_not_found");
if (flash.ok === true && (complete || promptReady) && hostWritten) {