import { CODEX_ENABLE_FLEET_ENV } from '../config/defaults.js'; import { getQuestionGuidance } from '../config/question-guidance.js'; const TRUTHY_VALUES = new Set(['1', 'true', 'yes', 'on']); export const FLEET_DEVELOPER_INSTRUCTIONS_SUFFIX = [ '', '[codex-worker-fleet]', 'This thread is running under mcp-codex-worker fleet mode.', ].join('\n'); export function isFleetModeEnabled(value = process.env[CODEX_ENABLE_FLEET_ENV]): boolean { return value !== undefined && TRUTHY_VALUES.has(value.trim().toLowerCase()); } export function appendFleetDeveloperInstructions( developerInstructions: string | null | undefined, ): string | undefined { if (!isFleetModeEnabled()) { return developerInstructions ?? undefined; } const base = developerInstructions?.trim(); if (!base) { return FLEET_DEVELOPER_INSTRUCTIONS_SUFFIX.trim(); } return `${base}\n${FLEET_DEVELOPER_INSTRUCTIONS_SUFFIX}`; } /** * Build the full developerInstructions string for a thread/start call. * Composes: user instructions → question guidance → fleet sentinel. */ export function buildDeveloperInstructions( userInstructions: string | undefined, provider: string, ): string | undefined { let base = userInstructions?.trim() ?? ''; // Append provider-specific question guidance const questionGuidance = getQuestionGuidance(provider); base = base ? `${base}\n${questionGuidance}` : questionGuidance.trim(); // Append fleet sentinel if enabled if (isFleetModeEnabled()) { base = `${base}\n${FLEET_DEVELOPER_INSTRUCTIONS_SUFFIX}`; } return base || undefined; }