MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / prependUserContext

Function prependUserContext

source code/utils/api.ts:451–476  ·  view source on GitHub ↗
(
  messages: Message[],
  context: { [k: string]: string },
)

Source from the content-addressed store, hash-verified

449}
450
451export function prependUserContext(
452 messages: Message[],
453 context: { [k: string]: string },
454): Message[] {
455 if (process.env.NODE_ENV === 'test') {
456 return messages
457 }
458
459 if (Object.entries(context).length === 0) {
460 return messages
461 }
462
463 return [
464 createUserMessage({
465 content: `<system-reminder>\nAs you answer the user's questions, you can use the following context:\n${Object.entries(
466 context,
467 )
468 .map(([key, value]) => `# ${key}\n${value}`)
469 .join('\n')}
470
471 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`,
472 isMeta: true,
473 }),
474 ...messages,
475 ]
476}
477
478/**
479 * Log metrics about context and system prompt size

Callers 2

queryLoopFunction · 0.85
generateAgentFunction · 0.85

Calls 2

createUserMessageFunction · 0.85
entriesMethod · 0.80

Tested by

no test coverage detected