fix: 测试版同步系统提示词只注入一次,并写清 1.1.11 变更

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-21 10:35:26 +08:00
1 parent a9fc371898
commit d2578b79c3
5 files changed
+60 -7

No files matched your search

+2
View File
@@ -3015,6 +3015,8 @@ const NEW_TOOL_PATCHES = [
"\t\t\t...transformed,\n" +
"\t\t\tsections: completeSection === void 0 ? transformed.sections : (function (complete, assembled) {\n" +
"\t\t\t\tconst sections = assembled.sections || [];\n" +
"\t\t\t\tconst committed = sections.find((s) => s && s.name === \"dsh-purge:committed\");\n" +
"\t\t\t\tif (committed && String(committed.text || \"\").trim()) return [{ ...complete, name: complete.name, text: committed.text }];\n" +
"\t\t\t\tconst inject = 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\t\t\tconst folded = sections.find((s) => s && s.name === complete.name);\n" +
"\t\t\t\tconst base = folded && typeof folded.text === \"string\" ? { ...complete, text: folded.text } : { ...complete };\n" +
+38 -4
View File
@@ -175,10 +175,26 @@ export function promptAlreadyInjected(existing, injectText) {
return String(existing || "").includes(inject);
}
export function shouldInjectPrompt(_context, _injectOnce = true, _injectText = "") {
// 0.1.5 in-history:渲染少了注入就会再追加一条 system/message。
// 用「最后一条是否含注入」决定本步掏空注入,会 A/B 死循环。每步都必须留下完整注入。
return true;
export function lastInjectedSystemPrompt(context, injectText) {
const inject = String(injectText || "").trim();
if (!inject) return "";
const events = eventList(context?.agent?.session || context?.session);
let last = "";
for (const event of events) {
if (event?.type !== "system/message") continue;
const text = messageText(event.data?.message || event.data).trim();
if (text && promptAlreadyInjected(text, inject)) last = text;
}
return last;
}
export function shouldInjectPrompt(context, _injectOnce = true, injectText = "") {
const inject = String(injectText || "").trim();
if (!inject) return false;
// 历史里已经有完整注入就不要再折一份。0.1.5 in-history 只要渲染结果和上一条
// system/message 不同就会再追加,聊天里就会每步都冒出「系统提示词」。
// 掏空注入也不行:渲染少了注入同样会被当成变化再追加,形成 A/B。
return !lastInjectedSystemPrompt(context, inject);
}
export function isMnemonPluginMessage(message) {
@@ -198,15 +214,26 @@ function normalizeRewriteOptions(fallbackInject, options) {
fallbackInject: typeof fallbackInject.fallbackInject === "string" ? fallbackInject.fallbackInject : "",
dropMnemon: fallbackInject.dropMnemon !== false,
dropPurgeAfterFold: fallbackInject.dropPurgeAfterFold !== false,
context: fallbackInject.context,
};
}
return {
fallbackInject: typeof fallbackInject === "string" ? fallbackInject : "",
dropMnemon: options?.dropMnemon !== false,
dropPurgeAfterFold: options?.dropPurgeAfterFold !== false,
context: options?.context,
};
}
function pinCommittedSystemPrompt(sections, committed) {
const names = sections.map((section) => String(section?.name || ""));
const hasPrefix = names.some((name) => PERSONA_PREFIX_NAMES.has(name));
const target = hasPrefix
? names.find((name) => PERSONA_PREFIX_NAMES.has(name))
: names.find((name) => PERSONA_LEGACY_NAMES.has(name));
return [{ name: target || "dsh-purge:committed", text: committed }];
}
// 0.1.5 优先写入 persona-prefix;无 prefix 时写入 legacy persona。
function foldInjectIntoPersona(sections, injectText) {
const inject = typeof injectText === "string" ? injectText : "";
@@ -250,6 +277,13 @@ export function rewritePromptAssembly(assembled, fallbackInject = "", options =
}
const injectText = collectInjectText(purge, opts.fallbackInject);
if (!shouldInjectPrompt(opts.context, true, injectText)) {
const committed = lastInjectedSystemPrompt(opts.context, injectText);
if (committed) {
assembled.sections = pinCommittedSystemPrompt([...rest, ...purge], committed);
return assembled;
}
}
const folded = foldInjectIntoPersona(rest, injectText);
const extras = opts.dropPurgeAfterFold
? purge.filter((section) => section.name !== "dsh-purge")
+2 -1
View File
@@ -223,7 +223,7 @@ function installIdentityOverride(ctx, config = {}) {
if (typeof ctx.on !== "function") return;
if (ctx.__dshPurgeAssembleHook) return;
ctx.__dshPurgeAssembleHook = true;
const hook = async (_assembly, _context, next) => {
const hook = async (_assembly, context, next) => {
const assembled = typeof next === "function" ? await next() : _assembly;
const enabled = config.enabled !== false;
const inject = enabled ? readInjectFallback() : "";
@@ -231,6 +231,7 @@ function installIdentityOverride(ctx, config = {}) {
fallbackInject: inject,
dropMnemon: config.stripMnemon !== false,
dropPurgeAfterFold: true,
context,
});
};
// 只挂一次:挂多次会让同一轮 assemble 折两遍,UI 也会显示两次注入。