fix: 发布 1.1.58,打开即挂上默认提示词

重启或重新打开后不用再点保存。磁盘正文优先,其次规则集,再没有就用内置默认。应用成功仍先询问是否重启。前端模块只在页面发出前改写,避免输入框消失。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-10-05 01:06:55 +08:00
1 parent 75637c48b9
commit 131ef12ecb
8 files changed
+158 -37

No files matched your search

+86 -5
View File
@@ -2098,10 +2098,11 @@ function quotedConst(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 dshPurgeSections = (transformed.sections || []).filter((s) => String(s && s.name || \"\").startsWith(\"dsh-purge\") && String(s.text || \"\").length > 0);\n" +
"\t\tif (completeSection === void 0 && !runtimeContextSuppressed) return transformed;\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 ? transformed.sections : (function (complete, purge) {\n" +
"\t\t\tsections: completeSection === void 0 ? [...dshPurgeSections, ...dshPurgeRest] : (function (complete, purge) {\n" +
"\t\t\t\tconst base = { ...complete };\n" +
"\t\t\t\treturn [...purge, base]; // [dsh-purge] complete prompt keeps waterfall inject\n" +
"\t\t\t})(completeSection, dshPurgeSections),\n" +
@@ -3334,6 +3335,21 @@ 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\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, purge) {\n" +
"\t\t\t\tconst base = { ...complete };\n" +
"\t\t\t\treturn [...purge, base]; // [dsh-purge] complete prompt keeps waterfall inject\n" +
"\t\t\t})(completeSection, dshPurgeSections),\n" +
"\t\t\tcontexts: runtimeContextSuppressed ? [] : transformed.contexts\n" +
"\t\t};",
replace: COMPLETE_PROMPT_WATERFALL_INJECT,
},
],
forbid: ["dsh-purge:committed"],
markers: ["complete prompt keeps waterfall inject"],
@@ -3911,6 +3927,30 @@ const NEW_TOOL_PATCHES = [
],
markers: ["[dsh-purge] system prompt replaces the first node"],
},
{
id: 74,
name: "ASSEMBLE_BEFORE_PRESTEP",
layer: "代码",
layer_en: "Code",
desc: "每个模式的第一次发送前先挂上默认提示词 / hang the default prompt before the first assemble",
file: ["agent-loop"],
skipIfMarked: true,
replacements: [
{
pattern:
"\t\tconst claimed = this.inbox.claim(target, position.turn);\n" +
"\t\tconst assembly = await this.loopCtx.systemPrompt.assemble(assembleContextFor(this, signal));",
replace:
"\t\tconst claimed = this.inbox.claim(target, position.turn);\n" +
"\t\tconst dshPurgePrepare = globalThis.__dshPurgePrepareAssemble;\n" +
"\t\tif (typeof dshPurgePrepare === \"function\") {\n" +
"\t\t\ttry { dshPurgePrepare(this.loopCtx); } catch { /* [dsh-purge] prepare assemble before this step */ }\n" +
"\t\t}\n" +
"\t\tconst assembly = await this.loopCtx.systemPrompt.assemble(assembleContextFor(this, signal));",
},
],
markers: ["[dsh-purge] prepare assemble before this step"],
},
{
id: 66,
name: "SYSTEM_PROMPT_RENDER_GUARD",
@@ -4179,6 +4219,47 @@ const NEW_TOOL_PATCHES = [
// 锚点还在时也别再 replaceAll。这个文件是前端模块,重复写会改 mtime。
skipIfMarked: true,
replacements: [
{
// 上一版只藏 surface 序号。界面气泡和「用时」挂在回合事件上,序号对不上就还留在聊天里。
pattern:
"\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",
replace:
"\t\t\t\thidden.add(event.seq); // [dsh-purge] rewind hides the cut turn\n" +
"\t\t\t\tconst op = event.surfaceOp;\n" +
"\t\t\t\tif (op && typeof op.startSeq === \"number\" && typeof op.endSeq === \"number\" && op.endSeq >= op.startSeq && op.endSeq - op.startSeq < 100000) {\n" +
"\t\t\t\t\tfor (let seq = op.startSeq; seq <= op.endSeq; seq += 1) hidden.add(seq);\n" +
"\t\t\t\t}\n" +
"\t\t\t\tconst raw = event.sourceEventSeqs;\n" +
"\t\t\t\tif (Array.isArray(raw)) {\n" +
"\t\t\t\t\tfor (const row of raw) {\n" +
"\t\t\t\t\t\tif (typeof row === \"number\") hidden.add(row);\n" +
"\t\t\t\t\t\telse if (Array.isArray(row) && row.length === 2 && typeof row[0] === \"number\" && typeof row[1] === \"number\" && row[1] >= row[0] && row[1] - row[0] < 100000) {\n" +
"\t\t\t\t\t\t\tfor (let seq = row[0]; seq <= row[1]; seq += 1) hidden.add(seq);\n" +
"\t\t\t\t\t\t}\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t}\n" +
"\t\t\t\tconst cutEnd = op && typeof op.endSeq === \"number\" ? op.endSeq : event.seq;\n" +
"\t\t\t\tlet turnStart = null;\n" +
"\t\t\t\tlet turnEnd = null;\n" +
"\t\t\t\tfor (const row of list) {\n" +
"\t\t\t\t\tconst ev = row && row.event;\n" +
"\t\t\t\t\tif (!ev || ev.seq >= event.seq) continue;\n" +
"\t\t\t\t\tif (ev.type === \"turn/start\") turnStart = ev.seq;\n" +
"\t\t\t\t\tif (ev.type === \"turn/end\" && ev.seq >= cutEnd && turnEnd === null) turnEnd = ev.seq;\n" +
"\t\t\t\t}\n" +
"\t\t\t\tif (turnStart !== null) {\n" +
"\t\t\t\t\tconst last = turnEnd === null ? event.seq : turnEnd;\n" +
"\t\t\t\t\tfor (const row of list) {\n" +
"\t\t\t\t\t\tconst ev = row && row.event;\n" +
"\t\t\t\t\t\tif (!ev || ev.seq < turnStart || ev.seq > last) continue;\n" +
"\t\t\t\t\t\tif (ev.type === \"system/message\") continue;\n" +
"\t\t\t\t\t\thidden.add(ev.seq);\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t}\n",
},
{
pattern:
"\t\tfunction rewindVisibleEntries(entries) {\n" +
@@ -4247,7 +4328,7 @@ const NEW_TOOL_PATCHES = [
"\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",
"\t\t} // [dsh-purge] rewind hides the cut turn",
},
{
pattern:
@@ -4312,7 +4393,7 @@ const NEW_TOOL_PATCHES = [
"\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\t} // [dsh-purge] rewind hides the cut turn\n" +
"\t\tvar ConversationNodeAssembler = class {",
},
{
@@ -4325,7 +4406,7 @@ const NEW_TOOL_PATCHES = [
"\t\t\t\tthis.contexts.clear();",
},
],
markers: ["[dsh-purge] rewind hides only the cut range"],
markers: ["[dsh-purge] rewind hides the cut turn"],
},
{
id: 57,
+32 -5
View File
@@ -176,9 +176,13 @@ function injectAllowedNow(config) {
return config.enabled !== false;
}
/** 有默认提示词用默认,没有才用当前规则集。两边都空则段上不挂正文。 */
/** 有磁盘提示词用磁盘,没有才用规则集,再没有就用内置默认。打开就能挂上。 */
function refreshHungOperator(dshHome = core.findDshHome()) {
const resolved = rules.resolveInjectText(dshHome);
const home = dshHome || core.findDshHome();
if (home) {
try { core.seedOverrideSync(home); } catch { /* 默认写不进去时,组装仍会用内存里的内置正文 */ }
}
const resolved = rules.resolveInjectText(home);
core.hangOperatorPrompt(resolved.text);
return resolved;
}
@@ -192,7 +196,7 @@ function injectSnapshot(dshHome = core.findDshHome()) {
};
}
/** 框里有字用框;空框才看规则集;都没有则要求先写提示词。不看内置默认。 */
/** 框里有字用框;空框才看规则集;都没有就用内置默认,不要求先点保存。 */
function injectSnapshotFromBox(dshHome, boxText) {
const ruleId = rules.activeRuleId(dshHome);
if (typeof boxText === "string" && core.normalizeOverride(boxText)) {
@@ -201,6 +205,9 @@ function injectSnapshotFromBox(dshHome, boxText) {
if (core.normalizeOverride(rules.activeRuleText(dshHome))) {
return { injectSource: "rule", injectRuleId: ruleId, needPrompt: false };
}
if (core.normalizeOverride(core.defaultOverrideText())) {
return { injectSource: "default", injectRuleId: null, needPrompt: false };
}
if (typeof boxText !== "string") return injectSnapshot(dshHome);
return { injectSource: "none", injectRuleId: ruleId, needPrompt: true };
}
@@ -435,6 +442,21 @@ function installIdentityOverride(ctx, config = {}) {
return rewriteLiveAssembly(config, assembled, context);
}, { global: true, prepend: true });
}
// 切换预设会换掉 assemble。pre-step 瀑布在 assemble 之后才跑,第一次发送包不上。
// 宿主在 assemble 之前调用这个函数,用的就是当前模式自己的 systemPrompt。
const prepareAssemble = (loopCtx) => {
try { rules.ensureOperatorBody(core.findDshHome()); } catch { /* 主目录还没有提示词 */ }
const prompt = loopCtx && loopCtx.systemPrompt;
if (prompt) {
try {
installAssembleGuard(prompt, (assembled, context) => (
rewriteLiveAssembly(config, assembled, context)
));
} catch { /* 这一层代理包不上时,下面再包插件自己的 */ }
}
wrapAssemble();
};
globalThis.__dshPurgePrepareAssemble = prepareAssemble;
// complete:true 会在 waterfall 之后盖掉 sections;包住 assemble 返回值,每轮都补回注入。
wrapAssemble();
const started = Date.now();
@@ -1017,7 +1039,10 @@ export function apply(ctx, config) {
} catch (e) {
console.warn("[dsh-purge] client bundle boot patch:", String(e && e.message ? e.message : e));
}
try { refreshHungOperator(core.findDshHome()); } catch { /* 主目录还没有提示词时段上留空 */ }
try {
const home = core.pinDshHome() || core.findDshHome();
refreshHungOperator(home);
} catch { /* 主目录还没有提示词时,组装会再挂内置默认 */ }
try {
const scrubbed = core.sanitizeDesktopCommandRuntimes();
if (scrubbed.length) log(cfg, "desktop runtime scrub on load:", JSON.stringify(scrubbed));
@@ -1568,7 +1593,9 @@ function installWebServer(ctx, cfg) {
});
return;
}
if (incoming !== null) await core.saveOverrideContent(state.dsh_home, incoming);
if (incoming !== null && core.normalizeOverride(incoming)) {
await core.saveOverrideContent(state.dsh_home, incoming);
}
refreshHungOperator(state.dsh_home);
await core.backupAll(state.ai_base);
const report = await core.applyPatches(state.ai_base, core.ALL_PATCHES, { preserveClientBundles: true });
+7 -7
View File
@@ -4,6 +4,7 @@ import path from "node:path";
import {
findDshHome,
findOverrideFile,
defaultOverrideText,
hangOperatorPrompt,
hungOperatorPrompt,
normalizeOverride,
@@ -195,27 +196,26 @@ function diskPrompt(dshHome) {
return normalizeOverride(overrideFileText(dshHome));
}
/** 磁盘上的提示词优先;没有则用当前规则集;两边都没有则不注入。不回落内置默认。 */
/** 磁盘上的提示词优先;没有则用当前规则集;两边都没有就用内置默认。不需要先点保存。 */
export function resolveInjectText(dshHome) {
const prompt = diskPrompt(dshHome);
if (prompt) return { text: prompt, source: "prompt", ruleId: null };
const ruleId = activeRuleId(dshHome);
const rule = normalizeOverride(activeRuleText(dshHome));
if (rule) return { text: rule, source: "rule", ruleId };
const bundled = normalizeOverride(defaultOverrideText());
if (bundled) return { text: bundled, source: "default", ruleId: null };
return { text: "", source: "none", ruleId };
}
/**
* 组装时用。内存里已经挂过就用那一份;还没挂(没点保存、也没在本次启动里挂上)
* 就从磁盘提示词或当前规则集补上。空内存不能挡住磁盘上已有的正文。
* 磁盘和规则集都没有时保持空,不回落内置默认。
* 每次组装都按当前主目录重读。重启后的空内存不能挡住磁盘或内置默认。
* 磁盘和规则集都没有时挂内置默认,打开、应用、重启都不用再点保存。
*/
export function ensureOperatorBody(dshHome) {
const hung = normalizeOverride(hungOperatorPrompt());
if (hung) return hung;
const resolved = resolveInjectText(dshHome);
if (resolved.text) hangOperatorPrompt(resolved.text);
return resolved.text || "";
return resolved.text || normalizeOverride(hungOperatorPrompt()) || "";
}
/** 官方和红队同一顺序。红队再去掉 CTF。没有正文时不注入操作者段。 */