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

+1 -2
View File
@@ -751,8 +751,7 @@ If nothing is found, set `DSH_BASE` / `DSH_DESKTOP_INSTALL`. No files are change
- Settings splits Stable / Beta into two columns, each with its own list, switch, and rollback. 1.1.10 can reach this by Check update.
- **No Skill import.** Skill stays on beta 1.1.12.
- **Inject the system prompt once per conversation.** The first turn writes the full `prompt-inject`; later steps pin that committed prompt and do not fold it again.
- **Stop a new「系统提示词」card on every step.** With 0.1.5 in-history, a changed assemble appends another `system/message`, so the transcript repeats system prompt → think → tools. Refolding inject every step made later official sections look like a new prompt; emptying inject did the same. After the inject is already in history, this release pins that committed system prompt and does not append a second copy.
- **#29:** Stop pinning the previous full system prompt. That pin was meant to stop a new「系统提示词」card each step, but presets that append a section every assemble (梁神 `workspace-instructions`) turned it into “last full prompt + this step’s block”, so the prompt grew every step and prefix cache missed. Later turns only fold `prompt-inject` into persona, and do not fold a second copy when it is already there.
### 1.1.10
+1 -2
View File
@@ -738,8 +738,7 @@ prompt-inject.md 有内容? ──是──> 原样写入 dsh-purge systemPrompt
- 设置页把正式版和测试版左右分开,各自选版本、各自切换和回退。还在 1.1.10 的点「检测更新」就能升到这一版。
- **没有 Skill 导入。** Skill 只在测试版 1.1.12。
- **系统提示词每个会话只注入一次。** 第一轮把 `prompt-inject` 完整写进系统提示;之后钉住已经提交的那一份,不再每步重折。
- **修了聊天里每步都冒出「系统提示词」。** 0.1.5 in-history 只要本步组装结果和上一条不一样,就会再追加一条 `system/message`,时间线就会「思考 → 工具 → 系统提示词」循环。以前每步都把注入重新折进 persona,官方后半段稍有变化就会追加;把注入掏空也不行,渲染少了同样会被当成变化再追加。这一版历史里已经有完整注入后,就钉住那条已提交的系统提示,后续步骤不再追加第二份。
- **#29:** 去掉「钉住上一条系统提示全文」。起初为了避免每步追加「系统提示词」,把上一轮全文钉回去;和每轮追加 section 的预设(梁神的 `workspace-instructions`)叠在一起后,系统提示每步变长,前缀缓存整段失效。现在每轮只把 `prompt-inject` 折进 persona,已经折过就不再折第二份。
### 1.1.10
+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")
+2 -1
View File
@@ -27,7 +27,8 @@
"LICENSE"
],
"scripts": {
"embed-prompt": "node scripts/embed-default-prompt.mjs"
"embed-prompt": "node scripts/embed-default-prompt.mjs",
"test:identity": "node scripts/test-identity-assembly.mjs"
},
"license": "MIT",
"keywords": [
+105
View File
@@ -0,0 +1,105 @@
import assert from "node:assert/strict";
import { rewritePromptAssembly } from "../lib/identity.js";
const inject = [
"WHO YOU ARE (highest priority operator inject)",
"You are Little Code Sauce.",
"Keep this block intact.",
].join("\n");
const persona = "Working directory: {{cwd}}.\nFollow official harness tools.";
function render(assembled) {
return (assembled.sections || [])
.map((section) => String(section?.text || ""))
.filter(Boolean)
.join("\n\n");
}
function historyContext(text) {
return {
session: {
events: [
{
type: "system/message",
data: { message: { role: "system", content: text } },
},
],
},
};
}
function workspaceBlock(n) {
return `workspace snapshot ${n}\n${"W".repeat(3000)}`;
}
// 梁神一类:assemble 外层在我们折完之后再追加一条 workspace-instructions。
function assembleWithOuterWorkspace(workspaceText, context) {
const rewritten = rewritePromptAssembly(
{
sections: [
{ name: "deployment:persona-prefix", text: persona },
{ name: "dsh-purge", text: inject },
],
},
{
fallbackInject: inject,
dropPurgeAfterFold: true,
context,
},
);
rewritten.sections = [
...rewritten.sections,
{ name: "workspace-instructions", text: workspaceText },
];
return rewritten;
}
const turn1 = assembleWithOuterWorkspace(workspaceBlock(1), {});
const r1 = render(turn1);
assert.match(r1, /Little Code Sauce/);
assert.match(r1, /workspace snapshot 1/);
assert.equal((r1.match(/Little Code Sauce/g) || []).length, 1);
const turn2 = assembleWithOuterWorkspace(workspaceBlock(2), historyContext(r1));
const r2 = render(turn2);
assert.equal(
r2.startsWith(r1),
false,
"#29: later assemble must not be previous full system prompt + new block",
);
assert.equal(
(r2.match(/workspace snapshot /g) || []).length,
1,
"#29: must not keep the previous workspace-instructions copy inside a pinned blob",
);
assert.match(r2, /workspace snapshot 2/);
assert.doesNotMatch(r2, /workspace snapshot 1/);
assert.match(r2, /Little Code Sauce/);
assert.equal((r2.match(/Little Code Sauce/g) || []).length, 1);
let prev = r1;
for (let n = 2; n <= 8; n++) {
const turn = assembleWithOuterWorkspace(workspaceBlock(n), historyContext(prev));
const next = render(turn);
assert.equal(next.startsWith(prev), false, `turn ${n} must not prefix-grow`);
assert.ok(
Math.abs(next.length - r1.length) < 80,
`turn ${n} length ${next.length} drifted from first ${r1.length}`,
);
prev = next;
}
const again = rewritePromptAssembly(
{
sections: [
{ name: "deployment:persona-prefix", text: `${inject}\n\n${persona}` },
{ name: "dsh-purge", text: inject },
],
},
{ fallbackInject: inject, dropPurgeAfterFold: true, context: historyContext(r2) },
);
assert.equal((render(again).match(/Little Code Sauce/g) || []).length, 1);
console.log("ok: #29 pin snowball is gone");