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