fix: 停用钉住上一条系统提示,避免梁神预设每步膨胀 (#29)

每轮只把注入折进 persona。钉最近全文会和每轮追加的 section 叠成线性增长,前缀缓存失效。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
叫我小杨同学andCursor committed 2026-09-22 00:04:26 +08:00
1 parent 1a47bcd969
commit 0fb12fc25e
5 files changed
+113 -24

No files matched your search

+4 -19
View File
@@ -191,9 +191,8 @@ export function lastInjectedSystemPrompt(context, injectText) {
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。
// 只做历史探测。assemble 不要据此钉上一条 system/message 全文(#29):
// 梁神等预设每轮还会追加 section,钉最近全文会变成「上一轮全文 + 本步新块」。
return !lastInjectedSystemPrompt(context, inject);
}
@@ -225,15 +224,6 @@ function normalizeRewriteOptions(fallbackInject, options) {
};
}
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 : "";
@@ -277,13 +267,8 @@ 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;
}
}
// #29: 不要把上一条 system/message 全文钉回 sections。
// 「历史里已有完整注入就不再折一份」由 foldInjectIntoPersona 的 includes 幂等满足。
const folded = foldInjectIntoPersona(rest, injectText);
const extras = opts.dropPurgeAfterFold
? purge.filter((section) => section.name !== "dsh-purge")