fix: use HTML comment format for dcp-id tags to prevent model echo

XML-style <dcp-id>m001</dcp-id> tags get echoed by models because they
look like semantic content. HTML comments <!-- dcp-id: m001 --> are
invisible in rendered markdown and models are trained to skip them.
This commit is contained in:
wassname
2026-04-16 15:39:24 +08:00
parent b18c536b11
commit b83b3f8c53
2 changed files with 7 additions and 7 deletions
+3 -3
View File
@@ -13,7 +13,7 @@ You operate in a context-constrained environment. Manage context continuously to
The ONLY tool you have for context management is \`compress\`. It replaces older conversation content with technical summaries you produce.
\`<dcp-id>\` and \`<dcp-system-reminder>\` tags are environment-injected metadata. Do not output them.
\`<!-- dcp-id: ... -->\` and \`<dcp-system-reminder>\` tags are environment-injected metadata. Do not output them.
THE PHILOSOPHY OF COMPRESS
\`compress\` transforms conversation content into dense, high-fidelity summaries. This is not cleanup — it is crystallization. Your summary becomes the authoritative record of what transpired.
@@ -114,7 +114,7 @@ You specify boundaries by ID using the injected IDs visible in the conversation:
- \`mNNN\` IDs identify raw messages (3 digits, zero-padded, e.g. \`m001\`, \`m042\`)
- \`bN\` IDs identify previously compressed blocks
Each message has an ID inside XML metadata tags like \`<dcp-id>...</dcp-id>\`.
Each message has an ID inside an HTML comment like \`<!-- dcp-id: m001 -->\`.
The ID tag appears at the end of the message it belongs to — it identifies the message above it, not the one below it.
Treat these tags as boundary metadata only, not as tool result content.
@@ -215,7 +215,7 @@ Prefer multiple short, closed ranges over one large range when several independe
export const MANUAL_MODE_SYSTEM_PROMPT = `
You are operating in DCP manual mode for context management.
\`<dcp-id>\` and \`<dcp-system-reminder>\` tags are environment-injected metadata. Do not output them.
\`<!-- dcp-id: ... -->\` and \`<dcp-system-reminder>\` tags are environment-injected metadata. Do not output them.
In manual mode you do NOT proactively compress conversation content. Compression is a deliberate, user-directed action.
+4 -4
View File
@@ -151,9 +151,9 @@ function applyCompressionBlocks(messages: any[], state: DcpState): any[] {
block.topic +
"]\n\n" +
block.summary +
"\n\n<dcp-block-id>b" +
"\n\n<!-- dcp-block-id: b" +
block.id +
"</dcp-block-id>",
" -->",
},
],
// anchorTimestamp is always finite (resolveAnchorTimestamp returns
@@ -356,11 +356,11 @@ function injectMessageIds(messages: any[], state: DcpState): void {
const id = "m" + String(counter).padStart(3, "0");
counter++;
const idTag = `\n<dcp-id>${id}</dcp-id>`;
const idTag = `\n<!-- dcp-id: ${id} -->`;
if (role === "user") {
if (typeof msg.content === "string") {
msg.content = msg.content + `\n\n<dcp-id>${id}</dcp-id>`;
msg.content = msg.content + `\n\n<!-- dcp-id: ${id} -->`;
} else if (Array.isArray(msg.content)) {
msg.content = [...msg.content, { type: "text", text: idTag }];
}