fix: 发布 1.1.59,应用后不再误报没写进宿主

重启校验同时认两条安装路径。原文里已经没有官方身份句和丢掉注入的写法时,不再因为旧标记对不上就取消重启。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-05 01:36:46 +08:00
1 parent c032942e5f
commit 7ad39ad832
7 files changed
+75 -42

No files matched your search

+4 -15
View File
@@ -25,6 +25,7 @@ import {
restoreExtractedDir,
} from "./extract-asar.js";
import { adapterFor, detectSurface } from "./surface.js";
import { hostPromptKeepsInject } from "./host-clean.js";
import { openSlot } from "./table-read.js";
// 无归档时用 node:fs;app.asar 还在时改写真实的 resources/app,避免新建文件 ENOENT。
@@ -1874,13 +1875,7 @@ export function scheduleSealedDesktopRestart(handoff) {
return { renamed: false, pending: true, ...pending };
}
/** waterfall 那句中间多了 waterfall,不包含旧句,两句都要认。 */
export function hostPromptKeepsInject(text) {
const body = String(text || "");
if (!body.includes("[dsh-purge] identity stripped")) return false;
return body.includes("[dsh-purge] complete prompt keeps waterfall inject")
|| body.includes("[dsh-purge] complete prompt keeps inject");
}
export { hostPromptKeepsInject };
export function hostCleanMarkersPresent(aiBase) {
if (!aiBase) return false;
@@ -3308,14 +3303,8 @@ const NEW_TOOL_PATCHES = [
file: ["system-prompt", "system-prompt-nested"],
replacements: [
{
pattern:
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return transformed;\n" +
"\t\treturn {\n" +
"\t\t\t...transformed,\n" +
"\t\t\tsections: completeSection === void 0 ? transformed.sections : [completeSection],\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};",
// 缩进不固定。0.2 有的构建用 tab,有的用空格;只认 tab 时匹配为 0,重启校验会说没写进宿主。
pattern: /[ \t]*const transformed = await this\.ctx\.waterfall\(scopeTarget\(this, scope\), "system-prompt\/assemble", assembly, context, \(\) => Promise\.resolve\(assembly\)\);\n[ \t]*if \(completeSection === void 0 && !runtimeContextSuppressed\) return transformed;\n[ \t]*return \{\n[ \t]*\.\.\.transformed,\n[ \t]*sections: completeSection === void 0 \? transformed\.sections : \[completeSection\],\n[ \t]*contexts: runtimeContextSuppressed \? \[\] : transformed\.contexts\n[ \t]*\};/,
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
},
{
+27 -12
View File
@@ -4,6 +4,7 @@ import { execFileSync, spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
import { isWshAscii, wshLiteral } from "./official-update.js";
import { asarArchiveIsFile, hostFs } from "./extract-asar.js";
import { hostPromptKeepsInject } from "./host-clean.js";
// 无归档时用 node:fs。app.asar 还在时不能把映射出来的 resources/app 当成已经解开。
const fs = hostFs;
@@ -1147,8 +1148,13 @@ function officialRestartScript(exe, asar, dshHome) {
"function pids() { var out = []; var root = String(installRoot() || '').replace(/\\//g, '\\\\').toLowerCase(); var e = new Enumerator(wmi.ExecQuery(\"SELECT ProcessId, ExecutablePath FROM Win32_Process WHERE Name = 'DeepSeek Harness.exe'\")); for (; !e.atEnd(); e.moveNext()) { var p = e.item(); var ep = String(p.ExecutablePath || '').replace(/\\//g, '\\\\').toLowerCase(); if (samePath(p.ExecutablePath, exe) || (root && ep.indexOf(root) === 0)) out.push(p.ProcessId); } return out; }",
"log('begin');",
"var promptFile = asar.replace(/app\\.asar$/i, 'app') + '\\\\dsh\\\\node_modules\\\\@deepseek-ai\\\\dsh-system-prompt\\\\lib\\\\index.js';",
"var altFile = asar.replace(/app\\.asar$/i, 'app') + '\\\\node_modules\\\\@deepseek-ai\\\\dsh-system-prompt\\\\lib\\\\index.js';",
"function readBody(file) { if (!fso.FileExists(file)) return ''; var tf = fso.OpenTextFile(file, 1); var body = tf.ReadAll(); tf.Close(); return body; }",
"function hostClean(body) { if (!body) return null; var ident = body.indexOf('[dsh-purge] identity stripped') >= 0; var kept = body.indexOf('[dsh-purge] complete prompt keeps waterfall inject') >= 0 || body.indexOf('[dsh-purge] complete prompt keeps inject') >= 0; if (ident && kept) return true; if (body.indexOf('system-prompt/assemble') < 0) return false; var identityLeft = body.indexOf('You are an AI agent powered by DeepSeek Harness.') >= 0; var drops = body.indexOf('transformed.sections : [completeSection]') >= 0; return !identityLeft && !drops; }",
"var clean = false;",
"if (fso.FileExists(promptFile)) { var tf = fso.OpenTextFile(promptFile, 1); var body = tf.ReadAll(); tf.Close(); var ident = body.indexOf('[dsh-purge] identity stripped') >= 0; var kept = body.indexOf('[dsh-purge] complete prompt keeps waterfall inject') >= 0 || body.indexOf('[dsh-purge] complete prompt keeps inject') >= 0; clean = ident && kept; }",
"var primary = hostClean(readBody(promptFile));",
"var alt = hostClean(readBody(altFile));",
"clean = (primary == true || alt == true) && primary != false && alt != false;",
"if (!clean) log('clean markers missing; not starting');",
"if (clean) {",
"log('clean markers ok');",
@@ -1184,18 +1190,27 @@ function officialRestartScript(exe, asar, dshHome) {
].join("\r\n");
}
function unpackedHostIsClean(exe) {
function systemPromptFiles(exe) {
const appDir = appDirForExecutable(exe);
if (!appDir) return false;
const fp = path.join(appDir, "dsh", "node_modules", "@deepseek-ai", "dsh-system-prompt", "lib", "index.js");
try {
const text = fs.readFileSync(fp, "utf8");
const kept = text.includes("[dsh-purge] complete prompt keeps waterfall inject")
|| text.includes("[dsh-purge] complete prompt keeps inject");
return text.includes("[dsh-purge] identity stripped") && kept;
} catch {
return false;
}
if (!appDir) return [];
return [
path.join(appDir, "dsh", "node_modules", "@deepseek-ai", "dsh-system-prompt", "lib", "index.js"),
path.join(appDir, "node_modules", "@deepseek-ai", "dsh-system-prompt", "lib", "index.js"),
].filter((fp) => {
try { return fs.existsSync(fp); } catch { return false; }
});
}
function unpackedHostIsClean(exe) {
const files = systemPromptFiles(exe);
if (files.length === 0) return false;
return files.every((fp) => {
try {
return hostPromptKeepsInject(fs.readFileSync(fp, "utf8"));
} catch {
return false;
}
});
}
/** 点「重启」后结束当前官方客户端,挪开被占用的 app.asar,再自己打开。 */
+13
View File
@@ -0,0 +1,13 @@
/** 重启前看系统提示词文件:标记写上了,或者当前原文里已经没有那两处旧拦截。 */
export function hostPromptKeepsInject(text) {
const body = String(text || "");
const identityMarked = body.includes("[dsh-purge] identity stripped");
const injectMarked = body.includes("[dsh-purge] complete prompt keeps waterfall inject")
|| body.includes("[dsh-purge] complete prompt keeps inject");
if (identityMarked && injectMarked) return true;
// 空文件或不是这份模块,不能当成已经洗过。
if (!body.includes("system-prompt/assemble")) return false;
const identityLeft = body.includes("You are an AI agent powered by DeepSeek Harness.");
const dropsInject = body.includes("transformed.sections : [completeSection]");
return !identityLeft && !dropsInject;
}