({
mainThreadAgentDefinition,
toolUseContext,
customSystemPrompt,
defaultSystemPrompt,
appendSystemPrompt,
overrideSystemPrompt,
}: {
mainThreadAgentDefinition: AgentDefinition | undefined
toolUseContext: Pick<ToolUseContext, 'options'>
customSystemPrompt: string | undefined
defaultSystemPrompt: string[]
appendSystemPrompt: string | undefined
overrideSystemPrompt?: string | null
})
| 40 | * Plus appendSystemPrompt is always added at the end if specified (except when override is set). |
| 41 | */ |
| 42 | export function buildEffectiveSystemPrompt({ |
| 43 | mainThreadAgentDefinition, |
| 44 | toolUseContext, |
| 45 | customSystemPrompt, |
| 46 | defaultSystemPrompt, |
| 47 | appendSystemPrompt, |
| 48 | overrideSystemPrompt, |
| 49 | }: { |
| 50 | mainThreadAgentDefinition: AgentDefinition | undefined |
| 51 | toolUseContext: Pick<ToolUseContext, 'options'> |
| 52 | customSystemPrompt: string | undefined |
| 53 | defaultSystemPrompt: string[] |
| 54 | appendSystemPrompt: string | undefined |
| 55 | overrideSystemPrompt?: string | null |
| 56 | }): SystemPrompt { |
| 57 | if (overrideSystemPrompt) { |
| 58 | return asSystemPrompt([overrideSystemPrompt]) |
| 59 | } |
| 60 | // Coordinator mode: use coordinator prompt instead of default |
| 61 | // Use inline env check instead of coordinatorModule to avoid circular |
| 62 | // dependency issues during test module loading. |
| 63 | if ( |
| 64 | feature('COORDINATOR_MODE') && |
| 65 | isEnvTruthy(process.env.CLAUDE_CODE_COORDINATOR_MODE) && |
| 66 | !mainThreadAgentDefinition |
| 67 | ) { |
| 68 | // Lazy require to avoid circular dependency at module load time |
| 69 | const { getCoordinatorSystemPrompt } = |
| 70 | // eslint-disable-next-line @typescript-eslint/no-require-imports |
| 71 | require('../coordinator/coordinatorMode.js') as typeof import('../coordinator/coordinatorMode.js') |
| 72 | return asSystemPrompt([ |
| 73 | getCoordinatorSystemPrompt(), |
| 74 | ...(appendSystemPrompt ? [appendSystemPrompt] : []), |
| 75 | ]) |
| 76 | } |
| 77 | |
| 78 | const agentSystemPrompt = mainThreadAgentDefinition |
| 79 | ? isBuiltInAgent(mainThreadAgentDefinition) |
| 80 | ? mainThreadAgentDefinition.getSystemPrompt({ |
| 81 | toolUseContext: { options: toolUseContext.options }, |
| 82 | }) |
| 83 | : mainThreadAgentDefinition.getSystemPrompt() |
| 84 | : undefined |
| 85 | |
| 86 | // Log agent memory loaded event for main loop agents |
| 87 | if (mainThreadAgentDefinition?.memory) { |
| 88 | logEvent('ncode_agent_memory_loaded', { |
| 89 | ...(isInternalBuild() && { |
| 90 | agent_type: |
| 91 | mainThreadAgentDefinition.agentType as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 92 | }), |
| 93 | scope: |
| 94 | mainThreadAgentDefinition.memory as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 95 | source: |
| 96 | 'main-thread' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS, |
| 97 | }) |
| 98 | } |
| 99 |
no test coverage detected