mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 13:10:22 +08:00
release: 1.1.68
Co-authored-by: Cursor <cursoragent@cursor.com> #92 技能块标量 description;#93 红队更新路径与 GitHub 回落;#94 桌面 CLI unpacked 回退;#95 拆除 refusal-recover;#96 bash 等待迁回 60s。注入置顶,capability 改名,用户 prompt 一律 followup,默认关闭自动继续。
This commit is contained in:
1 parent
529fe3adb8
commit
4fc6db788e
26 files changed
+1730
-1371
No files matched your search
+155
-16
@@ -3769,7 +3769,7 @@ const NEW_TOOL_PATCHES = [
|
||||
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
|
||||
"\t\tconst dshPurgeSections = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\") && String(s.text || \"\").length > 0);\n" +
|
||||
"\t\tconst dshPurgeRest = (transformed.sections || []).filter((s) => !String(s && s.name || \"\").startsWith(\"dsh-purge\"));\n" +
|
||||
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return { ...transformed, sections: [...dshPurgeSections, ...dshPurgeRest] }; // [dsh-purge] every mode keeps system inject\n" +
|
||||
"\t\t if (completeSection === void 0 && !runtimeContextSuppressed) return { ...transformed, sections: [...dshPurgeSections, ...dshPurgeRest] }; // [dsh-purge] every mode keeps system inject\n" +
|
||||
"\t\treturn {\n" +
|
||||
"\t\t\t...transformed,\n" +
|
||||
"\t\t\tsections: completeSection === void 0 ? [...dshPurgeSections, ...dshPurgeRest] : (function (complete, purge) {\n" +
|
||||
@@ -3780,12 +3780,47 @@ const NEW_TOOL_PATCHES = [
|
||||
"\t\t};",
|
||||
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
|
||||
"\t\tconst dshPurgeSections = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\") && String(s.text || \"\").length > 0);\n" +
|
||||
"\t\tconst dshPurgeRest = (transformed.sections || []).filter((s) => !String(s && s.name || \"\").startsWith(\"dsh-purge\"));\n" +
|
||||
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return { ...transformed, sections: [...dshPurgeSections, ...dshPurgeRest] }; // [dsh-purge] every mode keeps system inject\n" +
|
||||
"\t\treturn {\n" +
|
||||
"\t\t\t...transformed,\n" +
|
||||
"\t\t\tsections: completeSection === void 0 ? [...dshPurgeSections, ...dshPurgeRest] : (function (complete, purge, rest) {\n" +
|
||||
"\t\t\t\tconst base = { ...complete };\n" +
|
||||
"\t\t\t\tconst tail = rest.filter((s) => String(s?.name || \"\") !== String(base.name || \"\"));\n" +
|
||||
"\t\t\t\treturn [...purge, ...tail, base]; // [dsh-purge] complete prompt keeps inject + agent-instructions\n" +
|
||||
"\t\t\t})(completeSection, dshPurgeSections, dshPurgeRest),\n" +
|
||||
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
|
||||
"\t\t};",
|
||||
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
|
||||
"\t\tconst dshPurgeSections = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\") && String(s.text || \"\").length > 0);\n" +
|
||||
"\t\tconst dshPurgeRest = (transformed.sections || []).filter((s) => !String(s && s.name || \"\").startsWith(\"dsh-purge\"));\n" +
|
||||
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return { ...transformed, sections: [...dshPurgeRest, ...dshPurgeSections] }; // [dsh-purge] inject last after closer\n" +
|
||||
"\t\treturn {\n" +
|
||||
"\t\t\t...transformed,\n" +
|
||||
"\t\t\tsections: completeSection === void 0 ? [...dshPurgeRest, ...dshPurgeSections] : (function (complete, purge, rest) {\n" +
|
||||
"\t\t\t\tconst base = { ...complete };\n" +
|
||||
"\t\t\t\tconst tail = rest.filter((s) => String(s?.name || \"\") !== String(base.name || \"\"));\n" +
|
||||
"\t\t\t\treturn [...tail, base, ...purge]; // [dsh-purge] inject last after closer\n" +
|
||||
"\t\t\t})(completeSection, dshPurgeSections, dshPurgeRest),\n" +
|
||||
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
|
||||
"\t\t};",
|
||||
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
|
||||
},
|
||||
],
|
||||
forbid: ["dsh-purge:committed"],
|
||||
markersAny: true,
|
||||
markers: [
|
||||
"complete prompt keeps waterfall inject",
|
||||
"complete prompt keeps inject + agent-instructions",
|
||||
"inject last after closer",
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -4446,10 +4481,10 @@ const NEW_TOOL_PATCHES = [
|
||||
replace:
|
||||
"\t\tlet system = renderPrompt(assembly);\n" +
|
||||
"\t\tconst dshPurgeHungFn = typeof globalThis.__dshPurgeHungPrompt === \"function\" ? globalThis.__dshPurgeHungPrompt : null;\n" +
|
||||
"\t\tconst dshPurgeHung = dshPurgeHungFn ? dshPurgeHungFn() : \"\";\n" +
|
||||
"\t\tconst dshPurgeNeedle = String(dshPurgeHung || \"\").trim().slice(0, 96);\n" +
|
||||
"\t\tif (dshPurgeNeedle && !String(system || \"\").includes(dshPurgeNeedle)) {\n" +
|
||||
"\t\t\tsystem = String(dshPurgeHung).trim() + (system ? \"\\n\\n\" + system : \"\"); // [dsh-purge] hang full prompt-inject every step\n" +
|
||||
"\t\tconst dshPurgeHung = dshPurgeHungFn ? String(dshPurgeHungFn() || \"\").trim() : \"\";\n" +
|
||||
"\t\tconst dshPurgeTail = dshPurgeHung.slice(-96);\n" +
|
||||
"\t\tif (dshPurgeHung && (!dshPurgeTail || !String(system || \"\").includes(dshPurgeTail))) {\n" +
|
||||
"\t\t\tsystem = dshPurgeHung + (system ? \"\\n\\n\" + system : \"\"); // [dsh-purge] hang full prompt-inject at head\n" +
|
||||
"\t\t}\n" +
|
||||
"\t\twhile (true) {\n" +
|
||||
"\t\t\tconst { request, preparedCall } = await this.buildRequest(turn, step, assembly.tools, system, this.session.deriveMessages(), signal);",
|
||||
@@ -4477,14 +4512,40 @@ const NEW_TOOL_PATCHES = [
|
||||
replace:
|
||||
"\t\tconst { assembly } = decision;\n" +
|
||||
"\t\tlet renderedPrompt = renderPrompt(assembly);\n" +
|
||||
"\t\tconst dshPurgeHung = typeof globalThis.__dshPurgeHungPrompt === \"function\" ? String(globalThis.__dshPurgeHungPrompt() || \"\").trim() : \"\";\n" +
|
||||
"\t\tconst dshPurgeTail = dshPurgeHung.slice(-96);\n" +
|
||||
"\t\tif (dshPurgeHung && (!dshPurgeTail || !String(renderedPrompt || \"\").includes(dshPurgeTail))) {\n" +
|
||||
"\t\t\trenderedPrompt = dshPurgeHung + (renderedPrompt ? \"\\n\\n\" + renderedPrompt : \"\"); // [dsh-purge] hang full prompt-inject at head\n" +
|
||||
"\t\t}",
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
"\t\tconst dshPurgeHung = typeof globalThis.__dshPurgeHungPrompt === \"function\" ? globalThis.__dshPurgeHungPrompt() : \"\";\n" +
|
||||
"\t\tconst dshPurgeNeedle = String(dshPurgeHung || \"\").trim().slice(0, 96);\n" +
|
||||
"\t\tif (dshPurgeNeedle && !String(renderedPrompt || \"\").includes(dshPurgeNeedle)) {\n" +
|
||||
"\t\t\trenderedPrompt = String(dshPurgeHung).trim() + (renderedPrompt ? \"\\n\\n\" + renderedPrompt : \"\"); // [dsh-purge] hang full prompt-inject every step\n" +
|
||||
"\t\t}",
|
||||
replace:
|
||||
"\t\tconst dshPurgeHung = typeof globalThis.__dshPurgeHungPrompt === \"function\" ? String(globalThis.__dshPurgeHungPrompt() || \"\").trim() : \"\";\n" +
|
||||
"\t\tconst dshPurgeTail = dshPurgeHung.slice(-96);\n" +
|
||||
"\t\tif (dshPurgeHung && (!dshPurgeTail || !String(renderedPrompt || \"\").includes(dshPurgeTail))) {\n" +
|
||||
"\t\t\trenderedPrompt = dshPurgeHung + (renderedPrompt ? \"\\n\\n\" + renderedPrompt : \"\"); // [dsh-purge] hang full prompt-inject at head\n" +
|
||||
"\t\t}",
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
"\t\t\trenderedPrompt = (renderedPrompt ? renderedPrompt + \"\\n\\n\" : \"\") + dshPurgeHung; // [dsh-purge] hang full prompt-inject after closer\n",
|
||||
replace:
|
||||
"\t\t\trenderedPrompt = dshPurgeHung + (renderedPrompt ? \"\\n\\n\" + renderedPrompt : \"\"); // [dsh-purge] hang full prompt-inject at head\n",
|
||||
},
|
||||
{
|
||||
pattern:
|
||||
"\t\t\tsystem = (system ? system + \"\\n\\n\" : \"\") + dshPurgeHung; // [dsh-purge] hang full prompt-inject after closer\n",
|
||||
replace:
|
||||
"\t\t\tsystem = dshPurgeHung + (system ? \"\\n\\n\" + system : \"\"); // [dsh-purge] hang full prompt-inject at head\n",
|
||||
},
|
||||
],
|
||||
markers: ["[dsh-purge] hang full prompt-inject every step"],
|
||||
markers: ["[dsh-purge] hang full prompt-inject at head"],
|
||||
},
|
||||
{
|
||||
id: 66,
|
||||
@@ -5430,6 +5491,26 @@ const NEW_TOOL_PATCHES = [
|
||||
],
|
||||
markers: ["[dsh-purge-82] 双击 exe 从 explorer 继承 env 时常缺 DSH_PROFILE"],
|
||||
},
|
||||
{
|
||||
id: 85,
|
||||
name: "SESSION_PROMPT_ALWAYS_FOLLOWUP",
|
||||
layer: "代码",
|
||||
layer_en: "Code",
|
||||
desc: "session-controller prompt() 一律 followup:UI 发消息永远新 turn,消 steer→next-step 竞态(二轮立刻发被拒根因)",
|
||||
file: "api-session-controller",
|
||||
optional: true,
|
||||
skipIfMarked: true,
|
||||
replacements: [
|
||||
{
|
||||
pattern:
|
||||
"\t\t\t\t\tif (request.mode === \"steer\") agent.steer(message);\n" +
|
||||
"\t\t\t\t\telse agent.followup(message);",
|
||||
replace:
|
||||
"\t\t\t\t\tagent.followup(message); // [dsh-purge-85] user prompt always next-turn (kill steer→next-step race)",
|
||||
},
|
||||
],
|
||||
markers: ["[dsh-purge-85] user prompt always next-turn"],
|
||||
},
|
||||
];
|
||||
|
||||
export const ALL_PATCHES = [...PATCHES, ...CODE_PATCHES, ...ENGINE_PATCHES, ...NEW_TOOL_PATCHES];
|
||||
@@ -5637,6 +5718,55 @@ export function restoreMissingOriginalsAllHosts() {
|
||||
return restored;
|
||||
}
|
||||
|
||||
const DSH_PURGE_MARKER_NEEDLE = "dsh-purge";
|
||||
|
||||
/**
|
||||
* DSH 自升级会把宿主文件整个换成官方新版,但旁边的 .dshpurge.bak 不会动
|
||||
* (backupAll 对已有 bak 走 wx 独占直接 continue)。老 bak 变过期后:
|
||||
* · revertAll 会把当前的新版文件写回成老版 → 新代码/旧代码混合直接崩
|
||||
* · patchesMatchInstall 的 hostCleanMarkersPresent 只看任一文件存在清洗 marker 就算对齐,
|
||||
* 结果 #74/#81 这类放到 agent-loop 的补丁从未被重打,hang-inject 全路径哑火。
|
||||
* 这里:current 里不含任何 dsh-purge marker 字串、且和 bak 字节不同 → 把 bak 刷到 current。
|
||||
* 本函数不动文件内容,只重做基线;后续 applyPatches 会把 marker 补回去。
|
||||
*/
|
||||
export function refreshStaleBaksForUpgrade(aiBase) {
|
||||
const refreshed = [];
|
||||
if (!aiBase || !isDir(aiBase)) return refreshed;
|
||||
const roots = [aiBase];
|
||||
const nested = path.join(aiBase, "dsh", "node_modules", "@deepseek-ai");
|
||||
if (isDir(nested)) roots.push(nested);
|
||||
const visit = (dir, depth) => {
|
||||
if (depth > 10) return;
|
||||
let ents = [];
|
||||
try { ents = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
|
||||
for (const ent of ents) {
|
||||
if (ent.name === "node_modules" || ent.name === ".git") continue;
|
||||
const fp = path.join(dir, ent.name);
|
||||
if (ent.isDirectory()) { visit(fp, depth + 1); continue; }
|
||||
if (!ent.isFile() || !ent.name.endsWith(BAK_SUFFIX)) continue;
|
||||
const original = fp.slice(0, -BAK_SUFFIX.length);
|
||||
if (isUserProfilePatchFile(original)) continue;
|
||||
let originalBuf;
|
||||
let bakBuf;
|
||||
try {
|
||||
originalBuf = fs.readFileSync(original);
|
||||
bakBuf = fs.readFileSync(fp);
|
||||
} catch { continue; }
|
||||
if (originalBuf.equals(bakBuf)) continue;
|
||||
// 原文件里只要还带 dsh-purge 标识就视为"我们打过的版本",不碰 bak。
|
||||
if (originalBuf.includes(DSH_PURGE_MARKER_NEEDLE)) continue;
|
||||
try {
|
||||
fs.writeFileSync(fp, originalBuf);
|
||||
refreshed.push(original);
|
||||
} catch {
|
||||
/* bak 被占用下次再试 */
|
||||
}
|
||||
}
|
||||
};
|
||||
for (const root of roots) visit(root, 0);
|
||||
return refreshed;
|
||||
}
|
||||
|
||||
export async function backupAll(aiBase) {
|
||||
const files = targetFiles(aiBase);
|
||||
const made = [];
|
||||
@@ -5951,6 +6081,10 @@ export function targetFiles(aiBase, dshHome = findDshHome()) {
|
||||
path.join(aiBase, "dsh-hooks-codex", "lib", "index.js"),
|
||||
...(root ? [path.join(root, "packages", "hooks", "hooks-codex", "lib", "index.js")] : []),
|
||||
]),
|
||||
"api-session-controller": firstExisting([
|
||||
path.join(aiBase, "dsh-api-session-controller", "lib", "index.js"),
|
||||
...(root ? [path.join(root, "packages", "api", "api-session-controller", "lib", "index.js")] : []),
|
||||
]),
|
||||
...nestedTargetFiles(aiBase),
|
||||
"pi-ai-completions": allExisting(listPiAiApiFiles(dshHome, aiBase, "openai-completions.js")),
|
||||
"pi-ai-responses-shared": allExisting(listPiAiApiFiles(dshHome, aiBase, "openai-responses-shared.js")),
|
||||
@@ -6549,6 +6683,7 @@ async function repairPluginCordisYaml() {
|
||||
|
||||
export async function applyPatches(aiBase, patches = ALL_PATCHES, options = {}) {
|
||||
restoreMissingOriginalsFromBak(aiBase);
|
||||
refreshStaleBaksForUpgrade(aiBase);
|
||||
const files = targetFiles(aiBase);
|
||||
const report = [];
|
||||
const preserveClientBundles = options.preserveClientBundles === true;
|
||||
@@ -7276,15 +7411,19 @@ export function syncPromptInjectOnDiskSync(dshHome) {
|
||||
const fp = findOverrideFile(home);
|
||||
const diskRaw = readPromptInjectFileSync(home);
|
||||
const diskNorm = normalizeOverride(diskRaw);
|
||||
// #92「磁盘为王」:磁盘非空 → 一律 keep,从不覆盖。
|
||||
// 旧逻辑 overrideTextIsOurs(state, disk) 把「磁盘 = 上次插件写的旧 slot」判成可覆盖,
|
||||
// 结果用户在 UI 里删掉某段 → 磁盘 hash 变 → 下一次 syncPrompt… 走到 atomicWrite 把
|
||||
// 编辑擦掉写回当前 slot。实测场景:YG 删 OUTPUT HEAD RULE 抑制段 → 点「应用」→
|
||||
// 磁盘被重写为 slot(无抑制)→ 模型下次回复带 `[Y]`。
|
||||
// 用户恢复默认走 installOverride(force=true),不走这条路径。
|
||||
if (diskNorm) {
|
||||
if (diskNorm === bundledNorm) return { action: "keep", reason: "current" };
|
||||
return { action: "keep", reason: "disk_wins" };
|
||||
const state = readOverrideStateSync(home);
|
||||
if (
|
||||
diskNorm
|
||||
&& hashOverride(diskNorm) !== defaultOverrideHash()
|
||||
&& !overrideTextIsOurs(state, diskRaw)
|
||||
) {
|
||||
return { action: "keep", reason: "user_custom" };
|
||||
}
|
||||
if (state.customized === true && diskNorm && hashOverride(diskNorm) !== defaultOverrideHash()) {
|
||||
return { action: "keep", reason: "user_flag" };
|
||||
}
|
||||
if (diskNorm === bundledNorm) {
|
||||
return { action: "keep", reason: "current" };
|
||||
}
|
||||
try {
|
||||
// H19:原子写 prompt-inject.md,半写坏的 inject 会让组装直接拿到残片。
|
||||
@@ -7298,7 +7437,7 @@ export function syncPromptInjectOnDiskSync(dshHome) {
|
||||
} catch (error) {
|
||||
return { action: "error", reason: String(error && error.message ? error.message : error) };
|
||||
}
|
||||
return { action: "wrote", reason: "seed_default" };
|
||||
return { action: "wrote", reason: diskNorm ? "refresh_default" : "seed_default" };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user