diff --git a/src/services/api/claude.ts b/src/services/api/claude.ts index aba74a0f9..9b82f428e 100644 --- a/src/services/api/claude.ts +++ b/src/services/api/claude.ts @@ -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抢占 (CLAUDE.md) at the front. messagesForAPI = [ + ...messagesForAPI, createUserMessage({ - content: `\n${deferredToolList}\n\nTo invoke any tool listed above, use ExecuteExtraTool with {"tool_name": "", "params": {...}}. This is the ONLY way to call deferred tools — do not read source code or analyze implementation, just call ExecuteExtraTool directly.`, + content: `\n\n${deferredToolList}\n\nTo invoke any tool listed above, use ExecuteExtraTool with {"tool_name": "", "params": {...}}. This is the ONLY way to call deferred tools — do not read source code or analyze implementation, just call ExecuteExtraTool directly.\n`, isMeta: true, }), - ...messagesForAPI, ] } } diff --git a/src/utils/api.ts b/src/utils/api.ts index 5ee820c8a..12c11ecdf 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -452,19 +452,36 @@ export function prependUserContext( return messages } - return [ - createUserMessage({ - content: `\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 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: `\n${claudeMd}\n\n`, + isMeta: true, + }), + ) + } + + const restEntries = Object.entries(rest) + if (restEntries.length > 0) { + result.push( + createUserMessage({ + content: `\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\n`, - isMeta: true, - }), - ...messages, - ] + isMeta: true, + }), + ) + } + + return [...result, ...messages] } /**