mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-30 12:10:22 +08:00
fix: 发布 1.1.61,多宿主 Apply 与 #73/#74、极简 preset
- Apply/reapply 同时写 npm-global 与桌面宿主;#73 地区闸门误拦;#74 提示词落盘与 resolveInjectText - 极简 #80 官方 shell;agent-preset/selected 优先;adaptInjectForMinimalPreset;refusal-recover 扩展 - identity 注入去重与组装;默认提示词重加密 asset-table.js Closes #73. Closes #74. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8079d69bfb
commit
f51c1d6ddc
17 files changed
+957
-429
No files matched your search
+69
-37
@@ -179,7 +179,7 @@ function injectAllowedNow(config) {
|
||||
return config.enabled !== false;
|
||||
}
|
||||
|
||||
/** 挂插件加密默认。不读宿主磁盘上的提示词或规则集。 */
|
||||
/** 提示词框自改 > prompt-inject.md > 加密默认(见 rules.resolveInjectText)。 */
|
||||
function refreshHungOperator(dshHome = core.findDshHome()) {
|
||||
const home = dshHome || core.findDshHome();
|
||||
const resolved = rules.resolveInjectText(home);
|
||||
@@ -196,15 +196,15 @@ function injectSnapshot(dshHome = core.findDshHome()) {
|
||||
};
|
||||
}
|
||||
|
||||
/** 框里正在显示的字优先;框空则用插件加密默认。不读宿主磁盘。 */
|
||||
function injectSnapshotFromBox(_dshHome, boxText) {
|
||||
/** 框里正在显示的字优先;框空则 resolveInjectText(含 prompt-inject.md)。 */
|
||||
function injectSnapshotFromBox(dshHome, boxText) {
|
||||
if (typeof boxText === "string" && core.normalizeOverride(boxText)) {
|
||||
return { injectSource: "prompt", injectRuleId: null, needPrompt: false };
|
||||
}
|
||||
if (core.normalizeOverride(core.defaultOverrideText())) {
|
||||
return { injectSource: "default", injectRuleId: null, needPrompt: false };
|
||||
const resolved = rules.resolveInjectText(dshHome);
|
||||
if (resolved.text) {
|
||||
return { injectSource: resolved.source, injectRuleId: null, needPrompt: false };
|
||||
}
|
||||
if (typeof boxText !== "string") return injectSnapshot(_dshHome);
|
||||
return { injectSource: "none", injectRuleId: null, needPrompt: true };
|
||||
}
|
||||
|
||||
@@ -625,10 +625,10 @@ async function autoApply(config) {
|
||||
log(config, "auto-apply disabled");
|
||||
return "disabled";
|
||||
}
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
const autoMulti = await core.applyPatchesAllHosts(core.ALL_PATCHES, { preserveClientBundles: true });
|
||||
await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const report = autoMulti.report;
|
||||
const flash = core.silenceCmdFlash(autoMulti.hosts[0]?.aiBase || state.ai_base);
|
||||
const applied = report.filter((r) => r.status === "applied").length;
|
||||
log(config, `auto-apply done: ${applied} applied; cmd-flash=${flash.entry} ok=${flash.ok}`);
|
||||
return flash.ok ? `applied:${applied}` : `applied:${applied}:cmd_flash_incomplete`;
|
||||
@@ -677,22 +677,30 @@ async function handlePurgeCommand(rawInput, config) {
|
||||
if (home) state.dsh_home = home;
|
||||
let located;
|
||||
try {
|
||||
located = await core.resolveOfficialAiBase(state.ai_base);
|
||||
located = await core.resolveOfficialAiBase(state.ai_base, { forApply: true });
|
||||
} 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;
|
||||
if (located.extracted && located.handoff?.archive) {
|
||||
core.writeUnpackedAsarStamp(located.handoff.archive);
|
||||
}
|
||||
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: false });
|
||||
const applyMulti = await core.applyPatchesAllHosts(core.ALL_PATCHES, {
|
||||
preserveClientBundles: false,
|
||||
forApply: true,
|
||||
});
|
||||
const report = applyMulti.report;
|
||||
const shimResult = await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const lines = report.map((r) => {
|
||||
const flash = core.silenceCmdFlash(applyMulti.hosts[0]?.aiBase || state.ai_base);
|
||||
const lines = [];
|
||||
for (const h of applyMulti.hosts) lines.push(` 宿主 / host → ${h.aiBase}`);
|
||||
lines.push(...report.map((r) => {
|
||||
const m = r.status === "applied" ? "✓ 已清洗" : r.status === "already" ? "- 已是最新" : r.status === "missing_file" ? "⚠ 文件缺失" : `✗ ${r.status}`;
|
||||
return ` ${m} patch #${String(r.patch_id).padEnd(2)} ${r.name}`;
|
||||
});
|
||||
}));
|
||||
lines.push("", "shim:");
|
||||
for (const [dir, st] of Object.entries(shimResult)) {
|
||||
lines.push(` · ${dir} → ${typeof st === "object" ? JSON.stringify(st) : st}`);
|
||||
@@ -704,13 +712,14 @@ 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 hostWritten = core.allPatchHostsWritten(applyMulti.hosts) || core.hostCleanMarkersPresent(state.ai_base);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true && hostWritten;
|
||||
const promptReady = summary.failed.length > 0 && summary.failed.every((item) => item.status === "pattern_not_found");
|
||||
const shouldRestart = applyShouldRestart({
|
||||
complete,
|
||||
complete: complete || (promptReady && hostWritten),
|
||||
sealed: core.desktopAsarStillSealed(),
|
||||
appliedCount: summary.applied,
|
||||
promptReady,
|
||||
promptReady: promptReady && hostWritten,
|
||||
});
|
||||
if (shouldRestart) reapply.markSettleRestart();
|
||||
const planned = scheduleApplyRestart(shouldRestart);
|
||||
@@ -1086,6 +1095,10 @@ export function apply(ctx, config) {
|
||||
}
|
||||
|
||||
function applyHostHooks(ctx, cfg) {
|
||||
try {
|
||||
const home = core.pinDshHome() || core.findDshHome();
|
||||
rules.ensureOperatorBody(home);
|
||||
} catch { /* 主目录尚未就绪 */ }
|
||||
installIdentityOverride(ctx, cfg);
|
||||
installRegionGate(ctx);
|
||||
try {
|
||||
@@ -1215,10 +1228,13 @@ function applyHostHooks(ctx, cfg) {
|
||||
if (!state.ai_base) return { text: "ERROR: " + core.missingAiBaseMessage() };
|
||||
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: false });
|
||||
const toolMulti = await core.applyPatchesAllHosts(core.ALL_PATCHES, {
|
||||
preserveClientBundles: false,
|
||||
forApply: true,
|
||||
});
|
||||
await core.patchAllShims();
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const flash = core.silenceCmdFlash(toolMulti.hosts[0]?.aiBase || state.ai_base);
|
||||
const report = toolMulti.report;
|
||||
const applied = report.filter((r) => r.status === "applied").length;
|
||||
const already = report.filter((r) => r.status === "already").length;
|
||||
const scrubNote = scrubbed.length ? ` desktop_scrub=${scrubbed.length}` : "";
|
||||
@@ -1566,7 +1582,7 @@ function installWebServer(ctx, cfg) {
|
||||
if (home) state.dsh_home = home;
|
||||
let located;
|
||||
try {
|
||||
located = await core.resolveOfficialAiBase(state.ai_base);
|
||||
located = await core.resolveOfficialAiBase(state.ai_base, { forApply: true });
|
||||
} catch (e) {
|
||||
sendJson(response, 500, { ok: false, error: String(e && e.message ? e.message : e) });
|
||||
return;
|
||||
@@ -1576,6 +1592,10 @@ function installWebServer(ctx, cfg) {
|
||||
return;
|
||||
}
|
||||
state.ai_base = located.aiBase;
|
||||
if (located.extracted) {
|
||||
const arch = located.handoff?.archive;
|
||||
if (arch) core.writeUnpackedAsarStamp(arch);
|
||||
}
|
||||
const handoff = located.handoff && located.handoff.swapAsar ? located.handoff : null;
|
||||
const blocked = rejectIfNeedPrompt(state.dsh_home, incoming === null ? undefined : incoming);
|
||||
if (blocked) {
|
||||
@@ -1590,12 +1610,13 @@ function installWebServer(ctx, cfg) {
|
||||
return;
|
||||
}
|
||||
if (incoming !== null) {
|
||||
core.rememberCommittedOverride(state.dsh_home, core.normalizeOverride(incoming) ? incoming : "");
|
||||
await core.saveOverrideContent(state.dsh_home, incoming);
|
||||
}
|
||||
const hung = refreshHungOperator(state.dsh_home);
|
||||
await core.backupAll(state.ai_base);
|
||||
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: false });
|
||||
const override = await core.readOverrideForUi(state.dsh_home);
|
||||
const httpMulti = await core.applyPatchesAllHosts(core.ALL_PATCHES, {
|
||||
preserveClientBundles: false,
|
||||
forApply: true,
|
||||
});
|
||||
const report = httpMulti.report;
|
||||
const shim = await core.patchAllShims();
|
||||
let cliRepair = null;
|
||||
try {
|
||||
@@ -1603,25 +1624,32 @@ function installWebServer(ctx, cfg) {
|
||||
} catch (e) {
|
||||
cliRepair = { ok: false, error: String(e && e.message ? e.message : e) };
|
||||
}
|
||||
const flash = core.silenceCmdFlash(state.ai_base);
|
||||
const flash = core.silenceCmdFlash(httpMulti.hosts[0]?.aiBase || state.ai_base);
|
||||
const summary = core.summarizeApplyReport(report);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true;
|
||||
const written = core.hostCleanMarkersPresent(state.ai_base);
|
||||
const hostWritten =
|
||||
core.allPatchHostsWritten(httpMulti.hosts) || core.hostCleanMarkersPresent(state.ai_base);
|
||||
const complete = summary.failed.length === 0 && flash.ok === true && hostWritten;
|
||||
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) {
|
||||
if (flash.ok === true && (complete || promptReady) && hostWritten) {
|
||||
reapply.markPatchesApplied();
|
||||
}
|
||||
// 网页和桌面同一条:提示词已写入就重启。密封包只是重启前要换开 app.asar。
|
||||
// 全部洗完且标记进宿主才弹重启;密封包重启时换走 asar。
|
||||
const shouldRestart = applyShouldRestart({
|
||||
complete,
|
||||
complete: complete || (promptReady && hostWritten),
|
||||
sealed: sealedNow,
|
||||
appliedCount: summary.applied,
|
||||
promptReady,
|
||||
promptReady: promptReady && hostWritten,
|
||||
});
|
||||
if (shouldRestart && handoff && sealedNow) bootFullQuit = true;
|
||||
else bootFullQuit = false;
|
||||
if (shouldRestart) reapply.markSettleRestart();
|
||||
let promptInjectInstall = "skipped";
|
||||
if (hostWritten && flash.ok === true) {
|
||||
promptInjectInstall = await core.installOverride(state.dsh_home, false);
|
||||
}
|
||||
const hung = refreshHungOperator(state.dsh_home);
|
||||
const override = await core.readOverrideForUi(state.dsh_home);
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
complete,
|
||||
@@ -1644,7 +1672,7 @@ function installWebServer(ctx, cfg) {
|
||||
defaultContent: override.defaultContent,
|
||||
...injectSnapshot(state.dsh_home),
|
||||
override_path: override.path,
|
||||
override_installed: override.installed,
|
||||
override_installed: promptInjectInstall,
|
||||
shim,
|
||||
desktop_scrubbed: scrubbed,
|
||||
cli_repair: cliRepair,
|
||||
@@ -1757,12 +1785,16 @@ function installWebServer(ctx, cfg) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
core.rememberCommittedOverride(home, core.normalizeOverride(content) ? content : "");
|
||||
const saved = await core.saveOverrideContent(home, content);
|
||||
const hung = refreshHungOperator(home);
|
||||
const ui = await core.readOverrideForUi(home);
|
||||
sendJson(response, 200, {
|
||||
ok: true,
|
||||
content: hung.text,
|
||||
defaultContent: core.defaultOverrideText(),
|
||||
defaultContent: saved.defaultContent,
|
||||
customized: ui.customized,
|
||||
usingDefault: ui.usingDefault,
|
||||
path: ui.path,
|
||||
...injectSnapshot(home),
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
Reference in new issue
Block a user