fix: 提升 CLAUDE.md 指令权重 — 独立 project-instructions + deferred tools 位置调整

- prependUserContext: 将 claudeMd 从通用 <system-reminder> 提取为独立的
  <project-instructions> 用户消息,不带免责声明,置于消息列表最前面
- queryModel: deferred tools 消息从 prepend 改为 append,避免抢占
  project-instructions 的最高权重位置;标签规范化为 <system-reminder>

Co-Authored-By: glm-5-turbo <zai-org@claude-code-best.win>
This commit is contained in:
claude-code-best
2026-05-09 17:50:15 +08:00
parent 2f86485d9c
commit 84f12f34bd
2 changed files with 32 additions and 13 deletions

View File

@@ -1407,12 +1407,14 @@ async function* queryModel(
.sort()
.join('\n')
if (deferredToolList) {
// Append to the end of the messages array (not prepend) so it
// never抢占 <project-instructions> (CLAUDE.md) at the front.
messagesForAPI = [
...messagesForAPI,
createUserMessage({
content: `<available-deferred-tools>\n${deferredToolList}\n</available-deferred-tools>\nTo invoke any tool listed above, use ExecuteExtraTool with {"tool_name": "<name>", "params": {...}}. This is the ONLY way to call deferred tools — do not read source code or analyze implementation, just call ExecuteExtraTool directly.`,
content: `<system-reminder>\n<available-deferred-tools>\n${deferredToolList}\n</available-deferred-tools>\nTo invoke any tool listed above, use ExecuteExtraTool with {"tool_name": "<name>", "params": {...}}. This is the ONLY way to call deferred tools — do not read source code or analyze implementation, just call ExecuteExtraTool directly.\n</system-reminder>`,
isMeta: true,
}),
...messagesForAPI,
]
}
}

View File

@@ -452,19 +452,36 @@ export function prependUserContext(
return messages
}
return [
createUserMessage({
content: `<system-reminder>\nAs you answer the user's questions, you can use the following context:\n${Object.entries(
context,
)
.map(([key, value]) => `# ${key}\n${value}`)
.join('\n')}
// Extract claudeMd as a dedicated high-weight user message so it isn't
// buried inside the generic <system-reminder> with the "may or may not be
// relevant" disclaimer, which would degrade its instructional weight.
const { claudeMd, ...rest } = context
const result: Message[] = []
if (claudeMd) {
result.push(
createUserMessage({
content: `<project-instructions>\n${claudeMd}\n</project-instructions>\n`,
isMeta: true,
}),
)
}
const restEntries = Object.entries(rest)
if (restEntries.length > 0) {
result.push(
createUserMessage({
content: `<system-reminder>\nAs you answer the user's questions, you can use the following context:\n${restEntries
.map(([key, value]) => `# ${key}\n${value}`)
.join('\n')}
IMPORTANT: this context may or may not be relevant to your tasks. You should not respond to this context unless it is highly relevant to your task.\n</system-reminder>\n`,
isMeta: true,
}),
...messages,
]
isMeta: true,
}),
)
}
return [...result, ...messages]
}
/**