mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 10:50:22 +08:00
fix: 发布 1.1.60,极简/PTC 清洗、回退轮次与桌面补丁
- 反转 run_code/沙箱/plan 拦截(#60/#61/#63);minimal 补 agent-instructions(#26) - 回退按当前轮定位(rewind + #74/#75);Apply 写入 client 包避免取消重启 - 默认提示词重新加密;#66/#67/#69/#71/#70 与 README #68 安装说明 Closes #66, #67, #69, #70, #71. Docs for #68. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7ad39ad832
commit
f50ebbc032
25 files changed
+1461
-792
No files matched your search
+58
-57
@@ -160,6 +160,9 @@ function renderStatus(state) {
|
||||
out.push(line("备份 / backup", state.has_backup ? "有 / yes" : "无 / no", state.has_backup));
|
||||
out.push(line("注入文件 / inject", state.override_path));
|
||||
out.push(line("注入状态 / override", state.override_status));
|
||||
if (state.asar_still_sealed) {
|
||||
out.push(line("app.asar", "还在。补丁写在解开目录,当前进程读不到", false));
|
||||
}
|
||||
out.push("");
|
||||
out.push(`补丁 / patches: ${state.patches_applied}/${state.patches_total || 0} applied, ${state.patches_pending} pending`);
|
||||
for (const p of core.ALL_PATCHES) {
|
||||
@@ -176,12 +179,9 @@ function injectAllowedNow(config) {
|
||||
return config.enabled !== false;
|
||||
}
|
||||
|
||||
/** 有磁盘提示词用磁盘,没有才用规则集,再没有就用内置默认。打开就能挂上。 */
|
||||
/** 挂插件加密默认。不读宿主磁盘上的提示词或规则集。 */
|
||||
function refreshHungOperator(dshHome = core.findDshHome()) {
|
||||
const home = dshHome || core.findDshHome();
|
||||
if (home) {
|
||||
try { core.seedOverrideSync(home); } catch { /* 默认写不进去时,组装仍会用内存里的内置正文 */ }
|
||||
}
|
||||
const resolved = rules.resolveInjectText(home);
|
||||
core.hangOperatorPrompt(resolved.text);
|
||||
return resolved;
|
||||
@@ -196,20 +196,16 @@ function injectSnapshot(dshHome = core.findDshHome()) {
|
||||
};
|
||||
}
|
||||
|
||||
/** 框里有字用框;空框才看规则集;都没有就用内置默认,不要求先点保存。 */
|
||||
function injectSnapshotFromBox(dshHome, boxText) {
|
||||
const ruleId = rules.activeRuleId(dshHome);
|
||||
/** 框里正在显示的字优先;框空则用插件加密默认。不读宿主磁盘。 */
|
||||
function injectSnapshotFromBox(_dshHome, boxText) {
|
||||
if (typeof boxText === "string" && core.normalizeOverride(boxText)) {
|
||||
return { injectSource: "prompt", injectRuleId: null, needPrompt: false };
|
||||
}
|
||||
if (core.normalizeOverride(rules.activeRuleText(dshHome))) {
|
||||
return { injectSource: "rule", injectRuleId: ruleId, needPrompt: false };
|
||||
}
|
||||
if (core.normalizeOverride(core.defaultOverrideText())) {
|
||||
return { injectSource: "default", injectRuleId: null, needPrompt: false };
|
||||
}
|
||||
if (typeof boxText !== "string") return injectSnapshot(dshHome);
|
||||
return { injectSource: "none", injectRuleId: ruleId, needPrompt: true };
|
||||
if (typeof boxText !== "string") return injectSnapshot(_dshHome);
|
||||
return { injectSource: "none", injectRuleId: null, needPrompt: true };
|
||||
}
|
||||
|
||||
const NEED_PROMPT_ERROR = "提示词和规则集都是空的,必须先添加提示词";
|
||||
@@ -221,13 +217,7 @@ function rejectIfNeedPrompt(dshHome, boxText) {
|
||||
}
|
||||
|
||||
async function ensureRestartReady() {
|
||||
const clean = await core.ensureHostClean();
|
||||
if (clean.ok) return clean;
|
||||
// 密封 asar 读的是旧包,清洗写在解包目录;允许换包重启,注入靠 assemble 包装。
|
||||
try {
|
||||
if (core.desktopAsarStillSealed()) return { ok: true, pending: clean.pending || [] };
|
||||
} catch { /* 非桌面 */ }
|
||||
return clean;
|
||||
return core.ensureHostClean();
|
||||
}
|
||||
|
||||
/** 提示词服务自己的 ctx 多半没有 scope,段会进全局层。插件若挂在某个 scope 上,预设代理的父链看不到那一层。 */
|
||||
@@ -685,15 +675,18 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
const state = await core.gatherState();
|
||||
if (home) state.dsh_home = home;
|
||||
if (!state.ai_base) {
|
||||
const opened = await core.openSealedDesktopHost();
|
||||
if (!opened.aiBase) return { kind: "error", text: core.missingAiBaseMessage() };
|
||||
state.ai_base = opened.aiBase;
|
||||
let located;
|
||||
try {
|
||||
located = await core.resolveOfficialAiBase(state.ai_base);
|
||||
} catch (e) {
|
||||
return { kind: "error", text: String(e && e.message ? e.message : e) };
|
||||
}
|
||||
if (!located.aiBase) return { kind: "error", text: core.missingAiBaseMessage() };
|
||||
state.ai_base = located.aiBase;
|
||||
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, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: false });
|
||||
const shimResult = await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const lines = report.map((r) => {
|
||||
@@ -712,10 +705,12 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
lines.push("Desktop: host-commands 密封目录只清理不注入;bak 禁止写进 bin(issue #9)。");
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true;
|
||||
const promptReady = summary.failed.length > 0 && summary.failed.every((item) => item.status === "pattern_not_found");
|
||||
const shouldRestart = applyShouldRestart({
|
||||
complete,
|
||||
sealed: core.desktopAsarStillSealed(),
|
||||
appliedCount: summary.applied,
|
||||
promptReady,
|
||||
});
|
||||
if (shouldRestart) reapply.markSettleRestart();
|
||||
const planned = scheduleApplyRestart(shouldRestart);
|
||||
@@ -1042,7 +1037,7 @@ export function apply(ctx, config) {
|
||||
try {
|
||||
const home = core.pinDshHome() || core.findDshHome();
|
||||
refreshHungOperator(home);
|
||||
} catch { /* 主目录还没有提示词时,组装会再挂内置默认 */ }
|
||||
} catch { /* 主目录还没有时,组装会再挂内置默认 */ }
|
||||
try {
|
||||
const scrubbed = core.sanitizeDesktopCommandRuntimes();
|
||||
if (scrubbed.length) log(cfg, "desktop runtime scrub on load:", JSON.stringify(scrubbed));
|
||||
@@ -1221,7 +1216,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, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: false });
|
||||
await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const applied = report.filter((r) => r.status === "applied").length;
|
||||
@@ -1569,18 +1564,19 @@ function installWebServer(ctx, cfg) {
|
||||
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();
|
||||
if (!opened.aiBase) {
|
||||
sendJson(response, 500, { ok: false, error: core.missingAiBaseMessage() });
|
||||
return;
|
||||
}
|
||||
state.ai_base = opened.aiBase;
|
||||
if (opened.swapAsar) handoff = opened;
|
||||
} else {
|
||||
handoff = core.sealedAsarHandoff();
|
||||
let located;
|
||||
try {
|
||||
located = await core.resolveOfficialAiBase(state.ai_base);
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e && e.message ? e.message : e) });
|
||||
return;
|
||||
}
|
||||
if (!located.aiBase) {
|
||||
sendJson(response, 500, { ok: false, error: core.missingAiBaseMessage() });
|
||||
return;
|
||||
}
|
||||
state.ai_base = located.aiBase;
|
||||
const handoff = located.handoff && located.handoff.swapAsar ? located.handoff : null;
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home, incoming === null ? undefined : incoming);
|
||||
if (blocked) {
|
||||
const ui = await core.readOverrideForUi(state.dsh_home);
|
||||
@@ -1593,12 +1589,12 @@ function installWebServer(ctx, cfg) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (incoming !== null && core.normalizeOverride(incoming)) {
|
||||
await core.saveOverrideContent(state.dsh_home, incoming);
|
||||
if (incoming !== null) {
|
||||
core.rememberCommittedOverride(state.dsh_home, core.normalizeOverride(incoming) ? incoming : "");
|
||||
}
|
||||
refreshHungOperator(state.dsh_home);
|
||||
const hung = refreshHungOperator(state.dsh_home);
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: false });
|
||||
const override = await core.readOverrideForUi(state.dsh_home);
|
||||
const shim = await core.patchAllShims();
|
||||
let cliRepair = null;
|
||||
@@ -1610,31 +1606,29 @@ function installWebServer(ctx, cfg) {
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true;
|
||||
let pendingQuit = false;
|
||||
if (handoff && core.desktopAsarStillSealed()) {
|
||||
// 仍在读 app.asar:等这次响应发出后由重启接口退出再打开,不要先挂 idle-rename。
|
||||
pendingQuit = true;
|
||||
}
|
||||
const leaveTray = pendingQuit;
|
||||
const onlyUnmatched = summary.failed.every((item) => item.status === "pattern_not_found");
|
||||
if (flash.ok === true && onlyUnmatched && core.hostCleanMarkersPresent(state.ai_base)) {
|
||||
const written = core.hostCleanMarkersPresent(state.ai_base);
|
||||
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) && written) {
|
||||
reapply.markPatchesApplied();
|
||||
}
|
||||
if (leaveTray) bootFullQuit = true;
|
||||
const sealedNow = core.desktopAsarStillSealed();
|
||||
// 网页和桌面同一条:提示词已写入就重启。密封包只是重启前要换开 app.asar。
|
||||
const shouldRestart = applyShouldRestart({
|
||||
complete,
|
||||
sealed: sealedNow,
|
||||
appliedCount: summary.applied,
|
||||
promptReady,
|
||||
});
|
||||
if (shouldRestart && handoff && sealedNow) bootFullQuit = true;
|
||||
else bootFullQuit = false;
|
||||
if (shouldRestart) reapply.markSettleRestart();
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
complete,
|
||||
restarting: shouldRestart,
|
||||
restart_after_apply: shouldRestart,
|
||||
unpacked_asar: leaveTray,
|
||||
needs_full_quit: leaveTray,
|
||||
unpacked_asar: shouldRestart,
|
||||
needs_full_quit: shouldRestart,
|
||||
asar_still_sealed: sealedNow,
|
||||
asar_swap_started: Boolean(shouldRestart && handoff && sealedNow),
|
||||
applied: summary.applied,
|
||||
@@ -1646,7 +1640,7 @@ function installWebServer(ctx, cfg) {
|
||||
status: r.status,
|
||||
})),
|
||||
report: report.map((r) => ({ id: r.patch_id, name: r.name, status: r.status })),
|
||||
override_content: override.content,
|
||||
override_content: hung.text || override.content,
|
||||
defaultContent: override.defaultContent,
|
||||
...injectSnapshot(state.dsh_home),
|
||||
override_path: override.path,
|
||||
@@ -1763,9 +1757,14 @@ function installWebServer(ctx, cfg) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const saved = await core.saveOverrideContent(home, content);
|
||||
refreshHungOperator(home);
|
||||
sendJson(response, 200, { ok: true, ...saved, ...injectSnapshot(home) });
|
||||
core.rememberCommittedOverride(home, core.normalizeOverride(content) ? content : "");
|
||||
const hung = refreshHungOperator(home);
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
content: hung.text,
|
||||
defaultContent: core.defaultOverrideText(),
|
||||
...injectSnapshot(home),
|
||||
});
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e) });
|
||||
}
|
||||
@@ -1817,6 +1816,7 @@ function installWebServer(ctx, cfg) {
|
||||
try {
|
||||
const ready = await ensureRestartReady();
|
||||
if (!ready.ok) {
|
||||
bootFullQuit = false;
|
||||
sendJson(response, 200, {
|
||||
ok: false,
|
||||
error: ready.error || "清洗没有完成,已取消重启",
|
||||
@@ -1833,6 +1833,7 @@ function installWebServer(ctx, cfg) {
|
||||
planned = hostctl.scheduleRestart(request, ctx);
|
||||
}
|
||||
if (planned && planned.clean === false) {
|
||||
bootFullQuit = false;
|
||||
sendJson(response, 200, {
|
||||
ok: false,
|
||||
error: "清洗没有写进当前宿主,已取消重启",
|
||||
|
||||
Reference in new issue
Block a user