fix: 发布 1.1.57,应用后挂上提示词并让 Messages 使用当前系统提示

官方其余模式与标准一样清拦截。演练授权按本机目录保留,卸载成功后才清。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-04 13:06:19 +08:00
1 parent 54351cff82
commit 2c07aafead
12 files changed
+694 -271

No files matched your search

+247 -17
View File
@@ -1,3 +1,4 @@
import nodeFs from "node:fs";
import os from "node:os";
import path from "node:path";
import { createHash } from "node:crypto";
@@ -330,9 +331,10 @@ export function silenceCmdFlash(aiBase = findAiBase()) {
const subprocess = silenceSubprocessLocalFlash();
const customBash = silenceLiangshenCustomBashFlash();
const phase1 = silenceLiangshenPhase1Strip();
const liangshenPrompt = keepLiangshenOperatorPrompt();
const mnemon = silenceMnemonGitFlash();
// bin.js 写失败(missing_bin / ACL)不阻断 Apply。源码 cli 跳过注入也算成功(#41)。
const ok =
const hideOk =
process.platform !== "win32" ||
hide.entry === "injected" ||
hide.entry === "already_injected" ||
@@ -341,6 +343,7 @@ export function silenceCmdFlash(aiBase = findAiBase()) {
hide.entry === "missing_bin" ||
hide.entry === "sealed_asar" ||
(typeof hide.entry === "string" && hide.entry.startsWith("error:"));
const liangshenOk = liangshenPrompt === "missing" || liangshenPrompt === "already" || liangshenPrompt === "patched";
return {
...hide,
doctor,
@@ -349,8 +352,9 @@ export function silenceCmdFlash(aiBase = findAiBase()) {
subprocess,
customBash,
phase1,
liangshenPrompt,
mnemon,
ok,
ok: hideOk && liangshenOk,
};
}
@@ -762,6 +766,70 @@ export function silenceLiangshenPhase1Strip(dshHome = findDshHome()) {
return hit;
}
const LIANGSHEN_KEEP_OPERATOR = "const sections = assembled.sections.filter(section => keep.has(section?.name) || String(section?.name || \"\").startsWith(\"dsh-purge\")) // [dsh-purge] liangshen keep operator";
/** 梁神新版 minimal-prompt 只留人设段。操作者段要留下。红队文件不在这里。 */
export function liangshenPromptFilterText(text) {
const src = asLf(text);
const needle = "const sections = assembled.sections.filter(section => keep.has(section?.name))";
if (!src.includes(needle)) return src;
if (src.includes("[dsh-purge] liangshen keep operator")) return src;
return src.replace(needle, LIANGSHEN_KEEP_OPERATOR);
}
function listLiangshenMinimalPromptFiles(dshHome) {
const out = [];
const push = (fp) => {
if (keepSurfaceFile(fp) && !out.includes(fp)) out.push(fp);
};
const profilesRoot = path.join(dshHome, "profiles");
for (const name of ["web", "desktop"]) {
push(path.join(profilesRoot, name, "node_modules", "@linxin666", "dsh-liangshen", "presets", "liangshen", "minimal-prompt.mjs"));
push(path.join(profilesRoot, name, ".dsh-module-fallback", "node_modules", "@linxin666", "dsh-liangshen", "presets", "liangshen", "minimal-prompt.mjs"));
push(path.join(profilesRoot, name, "node_modules", "@linxin666", "dsh-web-all", "node_modules", "@linxin666", "dsh-liangshen", "presets", "liangshen", "minimal-prompt.mjs"));
}
push(path.join(dshHome, ".agent-presets", "liangshen", "minimal-prompt.mjs"));
return out;
}
function worseLiangshenHit(current, next) {
const rank = (hit) => {
if (String(hit).startsWith("error:")) return 0;
if (hit === "pattern_miss") return 1;
if (hit === "missing") return 2;
if (hit === "patched") return 3;
if (hit === "already") return 4;
return 2;
};
return rank(next) < rank(current) ? next : current;
}
export function keepLiangshenOperatorPrompt(dshHome = findDshHome()) {
const files = listLiangshenMinimalPromptFiles(dshHome);
if (files.length === 0) return "missing";
let hit = "missing";
for (const fp of files) {
let text;
try {
text = fs.readFileSync(fp, "utf8");
} catch {
continue;
}
const next = liangshenPromptFilterText(text);
if (next === asLf(text)) {
hit = worseLiangshenHit(hit, text.includes("[dsh-purge] liangshen keep operator") ? "already" : "pattern_miss");
continue;
}
try {
fs.writeFileSync(fp, text.includes("\r\n") ? next.replace(/\n/g, "\r\n") : next, "utf8");
hit = worseLiangshenHit(hit, "patched");
} catch (e) {
hit = worseLiangshenHit(hit, `error:${e}`);
}
}
return hit;
}
function realNorm(fp) {
if (!fp) return "";
try {
@@ -1918,6 +1986,42 @@ export function findOverrideFile(dshHome) {
return path.join(dshHome, "prompt-inject.md");
}
let committedOverride = null;
/** 本次进程里刚写入的提示词。重启后为空,改读磁盘。 */
export function rememberCommittedOverride(dshHome, text) {
const home = path.normalize(String(dshHome || ""));
if (!home) return;
committedOverride = { home, text: typeof text === "string" ? text : "" };
}
export function peekCommittedOverride(dshHome) {
if (!committedOverride) return null;
const home = path.normalize(String(dshHome || ""));
if (home !== committedOverride.home) return null;
return committedOverride.text;
}
let hungOperatorPromptText = "";
/** 本进程挂在系统提示词段上的操作者正文。有默认用默认,否则是规则集,都没有则是空串。 */
export function hangOperatorPrompt(text) {
hungOperatorPromptText = typeof text === "string" ? text : "";
}
export function hungOperatorPrompt() {
return hungOperatorPromptText;
}
/** 把本次解析到的主目录钉进环境变量,重启后的进程继续读这一份提示词。已有且不同的 DSH_HOME 不改。 */
export function pinDshHome() {
const home = path.normalize(findDshHome() || "");
if (!home) return "";
const current = String(process.env.DSH_HOME || "").trim();
if (!current) process.env.DSH_HOME = home;
return path.normalize(findDshHome() || home);
}
const STRONG_INTRO_CORE =
"The following instructions are ACTIVE and MANDATORY for this session. " +
"They are part of your operating configuration, not optional guidance. " +
@@ -1954,6 +2058,49 @@ function quotedConst(name, body) {
return `const ${name} = "${body}"`;
}
const COMPLETE_PROMPT_WATERFALL_INJECT =
"\t\tconst transformed = await this.ctx.waterfall(scopeTarget(this, scope), \"system-prompt/assemble\", assembly, context, () => Promise.resolve(assembly));\n" +
"\t\tconst dshPurgeInject = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\")).map((s) => String(s.text || \"\")).filter((t) => t.length > 0).join(\"\\n\\n\");\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 : (function (complete, inject) {\n" +
"\t\t\t\tconst base = { ...complete };\n" +
"\t\t\t\tif (!inject) return [base];\n" +
"\t\t\t\tif (String(base.text || \"\").includes(inject)) return [base];\n" +
"\t\t\t\treturn [{ ...base, text: inject + \"\\n\\n\" + base.text }]; // [dsh-purge] complete prompt keeps waterfall inject\n" +
"\t\t\t})(completeSection, dshPurgeInject),\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};";
function clearShellNetworkBan(pattern) {
return pattern
.replace(/\n[ \t]+\* You don't have access to the internet via this tool\./, "")
.replace("- id: persistent-pwsh\n", "- id: persistent-pwsh # [dsh-purge] preset shell network\n");
}
const SHELL_NETWORK_WEB =
" - id: persistent-pwsh\n" +
" name: '@deepseek-ai/dsh-tool-pwsh-persistent'\n" +
" disabled: !!js process.platform !== 'win32'\n" +
" config:\n" +
" timeoutMs: 300000\n" +
" description: |-\n" +
" Run commands in a PowerShell shell\n" +
" * When invoking this tool, the contents of the \"command\" parameter does NOT need to be XML-escaped.\n" +
" * You don't have access to the internet via this tool.";
const SHELL_NETWORK_SDK =
" - id: persistent-pwsh\n" +
" name: '@deepseek-ai/dsh-tool-pwsh-persistent'\n" +
" disabled: !!js process.platform !== 'win32'\n" +
" config:\n" +
" timeoutMs: 300000\n" +
" description: |-\n" +
" Run commands in a PowerShell shell\n" +
" * When invoking this tool, the contents of the \"command\" parameter does NOT need to be XML-escaped.\n" +
" * You don't have access to the internet via this tool.";
function replacementPrecedenceRewrites(name) {
const official = quotedConst(name, REPLACEMENT_BASELINE_PREFIX + OFFICIAL_REPLACEMENT_BODY);
// 长句在前。V1/V2 是完整强句的前缀,先换短句会把后半截留在引号里。
@@ -2085,7 +2232,8 @@ const PATCHES = [
{
id: 43, name: "WEB_PRESET_IDENTITY_STRIP", layer: "提示词", layer_en: "Prompt",
desc: "Web 四个内置预设只去掉身份句 / strip web preset identity only",
file: ["preset-standard", "preset-ptc", "preset-cordis", "preset-minimal"],
file: ["preset-standard", "preset-unrestricted", "preset-ptc", "preset-cordis", "preset-minimal"],
strictFiles: true,
replacements: [
{
pattern: " prefix: You are a coding agent powered by the {{model}} model.",
@@ -2104,6 +2252,45 @@ const PATCHES = [
],
markers: [' prefix: ""'],
},
{
id: 70,
name: "PRESET_SHELL_NETWORK",
layer: "提示词",
layer_en: "Prompt",
desc: "极简模式终端不再写没有网络 / minimal shell drops no-network ban",
file: ["preset-minimal", "preset-sdk-minimal"],
strictFiles: true,
skipIfMarked: true,
replacements: [
{ pattern: SHELL_NETWORK_WEB, replace: clearShellNetworkBan(SHELL_NETWORK_WEB) },
{ pattern: SHELL_NETWORK_SDK, replace: clearShellNetworkBan(SHELL_NETWORK_SDK) },
],
markers: ["[dsh-purge] preset shell network"],
},
{
id: 71,
name: "LIANGSHEN_IDENTITY_LINE",
layer: "提示词",
layer_en: "Prompt",
desc: "梁神去掉官方身份句,留下本模式的工作纪律 / strip liangshen stock identity line",
file: ["preset-liangshen", "preset-liangshen-pkg"],
strictFiles: true,
skipIfMarked: true,
replacements: [
{
pattern:
" prefix: |-\n" +
" You are a helpful software engineer assistant.\n" +
"\n" +
" - Thinking Disruption:",
replace:
" # [dsh-purge] liangshen identity line removed\n" +
" prefix: |-\n" +
" - Thinking Disruption:",
},
],
markers: ["[dsh-purge] liangshen identity line removed"],
},
{
id: 5, name: "APPROVAL_NEVER_SENTENCE", layer: "提示词", layer_en: "Prompt",
desc: "审批提示句限制 / approval sentence",
@@ -3055,14 +3242,13 @@ const NEW_TOOL_PATCHES = [
markers: ["[dsh-purge] mnemon summary off-notice"],
},
{
// 0.1.5 assemble 在 waterfall 之后若有 complete:true,会丢掉全部 section,提示词写了也进不去。
// complete:true 会在 waterfall 之后只留完整段。操作者段是 waterfall 里加上的,
// 必须从 waterfall 的结果里抄,不能从 waterfall 之前的段落里抄。
id: 40, name: "COMPLETE_PROMPT_KEEP_INJECT", layer: "0.1.5 兼容", layer_en: "0.1.5",
desc: "complete 预设仍保留 dsh-purge 注入 / keep inject after complete prompt",
file: ["system-prompt", "system-prompt-nested"],
replacements: [
{
// 注入文本在 waterfall 之前抄下来。换插件版本时,旧钩子会在 waterfall 里删掉 dsh-purge 段,
// 若等 waterfall 结束再找这段,complete:true 的返回值里就没有注入。
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" +
@@ -3071,7 +3257,10 @@ const NEW_TOOL_PATCHES = [
"\t\t\tsections: completeSection === void 0 ? transformed.sections : [completeSection],\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};",
replace:
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
},
{
pattern:
"\t\tconst dshPurgeInject = (assembly.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\")).map((s) => String(s.text || \"\")).filter((t) => t.length > 0).join(\"\\n\\n\");\n" +
"\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" +
@@ -3085,12 +3274,11 @@ const NEW_TOOL_PATCHES = [
"\t\t\t})(completeSection, dshPurgeInject),\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};",
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
},
],
// 已打过旧补丁的宿主里还有这行时,不能当成完成,要点一次应用删掉。
// 只认 waterfall 之前抄下的 dshPurgeInject。旧补丁在 waterfall 之后才读段,换版本会被删掉。
forbid: ["dsh-purge:committed"],
markers: ["dshPurgeInject"],
markers: ["complete prompt keeps waterfall inject"],
},
{
id: 42, name: "SETTINGS_LEGACY_API", layer: "代码", layer_en: "Code",
@@ -3894,6 +4082,34 @@ const NEW_TOOL_PATCHES = [
],
markers: ["[dsh-purge] deepseek-flash keeps in-history"],
},
{
id: 72,
name: "MESSAGES_SYSTEM_CURRENT",
layer: "代码",
layer_en: "Code",
desc: "Messages 的 system 字段用当前系统提示,不再把后出现的系统提示降成中途消息 / messages system field keeps the current prompt",
file: ["llm-deepseek"],
optional: true,
skipIfMarked: true,
replacements: [
{
pattern:
"\t\t\tif (inHistory && messages.length > 0) {\n" +
"\t\t\t\tif (text.length === 0) return unsupported(\"empty in-history system update\");\n" +
"\t\t\t\tsystemUpdates.push({\n" +
"\t\t\t\t\trole: \"system\",\n" +
"\t\t\t\t\tcontent: [{\n" +
"\t\t\t\t\t\ttype: \"text\",\n" +
"\t\t\t\t\t\ttext\n" +
"\t\t\t\t\t}]\n" +
"\t\t\t\t});\n" +
"\t\t\t} else historySystem = text;",
replace:
"\t\t\tif (text.length > 0) historySystem = text; // [dsh-purge] messages system field keeps the current prompt",
},
],
markers: ["[dsh-purge] messages system field keeps the current prompt"],
},
{
id: 56,
name: "REWIND_HIDE_CUT_ONLY",
@@ -5117,7 +5333,9 @@ export function applyReplacementsToText(text, patch, fp = "") {
return { text: out, changed: changed || preChanged };
}
function rollupPatchStatus({ applied, already, missing, notFound, lastError, keyCount, layoutSoft }) {
function rollupPatchStatus({ applied, already, missing, notFound, lastError, keyCount, layoutSoft, strictFiles }) {
if (strictFiles && lastError) return lastError;
if (strictFiles && notFound > 0) return "pattern_not_found";
if (applied > 0) return "applied";
if (already > 0 && (notFound === 0 || layoutSoft)) return "already";
if (missing === keyCount) return "missing_file";
@@ -5141,6 +5359,7 @@ export function isPatchResultSoftOk(row, patch = null) {
if (!row) return false;
if (ALWAYS_SOFT_STATUSES.has(row.status)) return true;
const p = patch || ALL_PATCHES.find((x) => x.id === row.patch_id || x.id === row.id);
if (p?.strictFiles && row.status === "pattern_not_found") return false;
if (p?.optional && row.status === "pattern_not_found") return true;
if (isLayoutSoftPatch(p) && row.status === "pattern_not_found") return true;
return false;
@@ -5239,7 +5458,7 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
}
if (filePatchSettled(text, p, fp)) {
already += 1;
} else if (patchHasRemainingWork(text, p, fp)) {
} else if (patchHasRemainingWork(text, p, fp) || p.strictFiles) {
notFound += 1;
}
}
@@ -5247,6 +5466,7 @@ export async function applyPatches(aiBase, patches = ALL_PATCHES) {
const status = rollupPatchStatus({
applied, already, missing, notFound, lastError, keyCount: keys.length,
layoutSoft: isLayoutSoftPatch(p),
strictFiles: !!p.strictFiles,
});
report.push({
patch_id: p.id,
@@ -5290,7 +5510,7 @@ export async function patchStatus(aiBase, patches = ALL_PATCHES) {
}
const outcome = filePatchOutcome(text, p, fp);
if (outcome === "applied") applied += 1;
else if (outcome === "pending") pending += 1;
else if (outcome === "pending" || (p.strictFiles && outcome === "skipped")) pending += 1;
else skipped += 1;
}
}
@@ -5890,10 +6110,19 @@ export async function saveOverrideContent(dshHome, content) {
const incoming = typeof content === "string" ? content : "";
const customized = Boolean(normalizeOverride(incoming))
&& normalizeOverride(incoming) !== normalizeOverride(bundled);
const fp = findOverrideFile(dshHome);
await fsp.mkdir(dshHome, { recursive: true });
await fsp.writeFile(fp, incoming, "utf8");
await markOverrideCustomized(dshHome, customized, incoming);
const home = path.normalize(dshHome);
const fp = findOverrideFile(home);
await fsp.mkdir(home, { recursive: true });
const handle = await nodeFs.promises.open(fp, "w");
try {
await handle.writeFile(incoming, "utf8");
await handle.sync();
} finally {
await handle.close();
}
rememberCommittedOverride(home, incoming);
if (!String(process.env.DSH_HOME || "").trim()) process.env.DSH_HOME = home;
await markOverrideCustomized(home, customized, incoming);
return { path: fp, customized, content: incoming, defaultContent: bundled };
}
@@ -5923,6 +6152,7 @@ export function patchStatusReady(status, patch = null) {
if (status === "applied" || status === "already") return true;
if (status === "skipped" || status === "missing_file") return true;
if (status === "na") return false;
if (status === "pattern_not_found" && patch?.strictFiles) return false;
if (status === "pattern_not_found" && patch?.optional) return true;
return false;
}