fix: 回退只撤最后一轮,提示词只保留一份。

解包改到旁边的目录,失败时放回上一份。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-01 13:10:15 +08:00
1 parent 3cede10253
commit 10a597d6ff
8 files changed
+354 -45

No files matched your search

+154 -6
View File
@@ -11,7 +11,16 @@ import {
revertHideConsoleFromBin,
} from "./hide-console.js";
import * as desktop from "./desktop.js";
import { asarArchiveIsFile, extractAsar, hostFs, overlayAsarUnpacked, renameAsarAside } from "./extract-asar.js";
import {
asarArchiveIsFile,
commitExtractedDir,
extractAsarToSide,
hostFs,
newestPreservedDir,
overlayAsarUnpacked,
renameAsarAside,
restoreExtractedDir,
} from "./extract-asar.js";
import { adapterFor, detectSurface } from "./surface.js";
import { openSlot } from "./table-read.js";
@@ -1626,22 +1635,39 @@ export function sealedAsarHandoff(input = {}) {
return { exe, asar, swapAsar: true };
}
/** 官方 app.asar 解开到 resources/app。点「应用」时调用,不要求用户先跑脚本。 */
/** 官方 app.asar 解开到 resources/app。已有解开目录时直接用,不重新解包。 */
export async function openSealedDesktopHost(options = {}) {
const handoff = sealedAsarHandoff();
if (!handoff) return { aiBase: null, swapAsar: false };
if (!handoff) return { aiBase: null, swapAsar: false, extracted: false, prev: "", appDir: "" };
const appDir = desktop.appDirForExecutable(handoff.exe);
let aiBase = options.forceExtract ? null : aiBaseUnderAppDir(appDir);
let extracted = false;
let prev = "";
if (!aiBase) {
await extractAsar(handoff.asar, appDir);
const side = extractAsarToSide(handoff.asar, appDir);
overlayAsarUnpacked(handoff.asar, side.next);
if (!aiBaseUnderAppDir(side.next)) {
try { hostFs.rmSync(side.next, { recursive: true, force: true }); } catch { /* 半成品留在旁边,不覆盖正在用的目录 */ }
throw new Error(`已解开 ${handoff.asar},但里面没有 @deepseek-ai`);
}
const committed = commitExtractedDir(appDir, side.next);
prev = committed.prev || "";
extracted = true;
aiBase = aiBaseUnderAppDir(appDir);
} else {
overlayAsarUnpacked(handoff.asar, appDir);
}
overlayAsarUnpacked(handoff.asar, appDir);
if (!aiBase) {
if (prev) restoreExtractedDir(appDir, prev);
throw new Error(`已解开 ${handoff.asar},但 ${appDir} 下没有 @deepseek-ai`);
}
resetPathMemo();
return { aiBase, swapAsar: true, exe: handoff.exe, asar: handoff.asar };
return { aiBase, swapAsar: true, exe: handoff.exe, asar: handoff.asar, extracted, prev, appDir };
}
export function restoreSealedExtract(appDir, prev) {
const saved = prev || newestPreservedDir(appDir);
return restoreExtractedDir(appDir, saved);
}
export function scheduleSealedDesktopRestart(handoff) {
@@ -3592,6 +3618,122 @@ const NEW_TOOL_PATCHES = [
],
markers: ["[dsh-purge] deliverable prohibition removed"],
},
{
id: 55,
name: "SYSTEM_PROMPT_REPLACE_HEAD",
layer: "代码",
layer_en: "Code",
desc: "每一步用当前整段系统提示替换第一条,避免旧提示被钉住 / replace the first system prompt every step",
file: ["agent-loop"],
replacements: [
{
pattern: 'inHistory: preparedCall?.systemPromptUpdate === "in-history",',
replace: "inHistory: false, // [dsh-purge] system prompt replaces the first node",
},
],
markers: ["[dsh-purge] system prompt replaces the first node"],
},
{
id: 56,
name: "REWIND_HIDE_CUT_ONLY",
layer: "代码",
layer_en: "Code",
desc: "回退只藏被撤掉的那一轮 / rewind hides only the cut range",
file: ["conversation-client"],
optional: true,
replacements: [
{
pattern:
"\t\tfunction rewindVisibleEntries(entries) {\n" +
"\t\t\tconst list = Array.isArray(entries) ? entries : [...entries];\n" +
"\t\t\tlet latest = null;\n" +
"\t\t\tfor (const entry of list) {\n" +
"\t\t\t\tconst event = entry && entry.event;\n" +
"\t\t\t\tif (!isRewindMarker(event)) continue;\n" +
"\t\t\t\tif (latest === null || event.seq > latest.seq) latest = event;\n" +
"\t\t\t}\n" +
"\t\t\tif (latest === null) return list;\n" +
"\t\t\tconst hidden = /* @__PURE__ */ new Set();\n" +
"\t\t\tif (Array.isArray(latest.sourceEventSeqs)) {\n" +
"\t\t\t\tfor (const seq of latest.sourceEventSeqs) hidden.add(seq);\n" +
"\t\t\t}\n" +
"\t\t\thidden.add(latest.seq);\n" +
"\t\t\treturn list.filter((entry) => {\n" +
"\t\t\t\tconst event = entry && entry.event;\n" +
"\t\t\t\tif (!event || hidden.has(event.seq)) return false;\n" +
"\t\t\t\tif (event.seq > latest.seq) return true;\n" +
"\t\t\t\treturn event.type === \"system/message\";\n" +
"\t\t\t});\n" +
"\t\t}",
replace:
"\t\tfunction rewindVisibleEntries(entries) {\n" +
"\t\t\tconst list = Array.isArray(entries) ? entries : [...entries];\n" +
"\t\t\tconst hidden = /* @__PURE__ */ new Set();\n" +
"\t\t\tfor (const entry of list) {\n" +
"\t\t\t\tconst event = entry && entry.event;\n" +
"\t\t\t\tif (!isRewindMarker(event)) continue;\n" +
"\t\t\t\thidden.add(event.seq);\n" +
"\t\t\t\tif (Array.isArray(event.sourceEventSeqs)) {\n" +
"\t\t\t\t\tfor (const seq of event.sourceEventSeqs) hidden.add(seq);\n" +
"\t\t\t\t}\n" +
"\t\t\t}\n" +
"\t\t\tif (hidden.size === 0) return list;\n" +
"\t\t\treturn list.filter((entry) => {\n" +
"\t\t\t\tconst event = entry && entry.event;\n" +
"\t\t\t\treturn !!event && !hidden.has(event.seq);\n" +
"\t\t\t});\n" +
"\t\t} // [dsh-purge] rewind hides only the cut range",
},
{
pattern:
"\t\t/**\n" +
"\t\t* Session-owned incremental engine that assembles business Contexts from a\n" +
"\t\t* contiguous Event window and materializes registered view snapshots.\n" +
"\t\t*/\n" +
"\t\tvar ConversationNodeAssembler = class {",
replace:
"\t\t/**\n" +
"\t\t* Session-owned incremental engine that assembles business Contexts from a\n" +
"\t\t* contiguous Event window and materializes registered view snapshots.\n" +
"\t\t*/\n" +
"\t\tfunction isRewindMarker(event) {\n" +
"\t\t\tif (!event || event.type !== \"user/message\") return false;\n" +
"\t\t\tconst id = event.data && event.data.id;\n" +
"\t\t\tif (typeof id !== \"string\" || id.indexOf(\"rewind-\") !== 0) return false;\n" +
"\t\t\tconst op = event.surfaceOp;\n" +
"\t\t\treturn !!op && op !== \"append\" && op.op === \"replace\";\n" +
"\t\t}\n" +
"\t\tfunction rewindVisibleEntries(entries) {\n" +
"\t\t\tconst list = Array.isArray(entries) ? entries : [...entries];\n" +
"\t\t\tconst hidden = /* @__PURE__ */ new Set();\n" +
"\t\t\tfor (const entry of list) {\n" +
"\t\t\t\tconst event = entry && entry.event;\n" +
"\t\t\t\tif (!isRewindMarker(event)) continue;\n" +
"\t\t\t\thidden.add(event.seq);\n" +
"\t\t\t\tif (Array.isArray(event.sourceEventSeqs)) {\n" +
"\t\t\t\t\tfor (const seq of event.sourceEventSeqs) hidden.add(seq);\n" +
"\t\t\t\t}\n" +
"\t\t\t}\n" +
"\t\t\tif (hidden.size === 0) return list;\n" +
"\t\t\treturn list.filter((entry) => {\n" +
"\t\t\t\tconst event = entry && entry.event;\n" +
"\t\t\t\treturn !!event && !hidden.has(event.seq);\n" +
"\t\t\t});\n" +
"\t\t} // [dsh-purge] rewind hides only the cut range\n" +
"\t\tvar ConversationNodeAssembler = class {",
},
{
pattern:
"\t\t\treplaceWindow(entries, hasMore) {\n" +
"\t\t\t\tthis.contexts.clear();",
replace:
"\t\t\treplaceWindow(entries, hasMore) {\n" +
"\t\t\t\tentries = rewindVisibleEntries(entries);\n" +
"\t\t\t\tthis.contexts.clear();",
},
],
markers: ["[dsh-purge] rewind hides only the cut range"],
},
];
export const ALL_PATCHES = [...PATCHES, ...CODE_PATCHES, ...ENGINE_PATCHES, ...NEW_TOOL_PATCHES];
@@ -4000,6 +4142,12 @@ export function targetFiles(aiBase, dshHome = findDshHome()) {
"deliverables-prompt": allExisting([
...nestedPkg(aiBase, "dsh-client-ui-deliverables", "lib", "index.js"),
]),
"agent-loop": allExisting([
...nestedPkg(aiBase, "dsh-agent-loop", "lib", "index.js"),
]),
"conversation-client": allExisting([
...nestedPkg(aiBase, "dsh-client-ui-conversation", "lib", "client.js"),
]),
};
return filterTargetFiles(files);
}