| 1 | import { processPromptOrRule } from "../args.js"; |
| 2 | |
| 3 | import { logger } from "./logger.js"; |
| 4 | |
| 5 | /** |
| 6 | * Process additional prompts from --prompt flags and combine with initial prompt |
| 7 | * @param additionalPrompts - Array of prompt specifications to process |
| 8 | * @param initialPrompt - Optional initial prompt to combine with |
| 9 | * @returns Combined prompt string or undefined if no prompts |
| 10 | */ |
| 11 | export async function processAndCombinePrompts( |
| 12 | additionalPrompts?: string[], |
| 13 | initialPrompt?: string, |
| 14 | ): Promise<string | undefined> { |
| 15 | if (!additionalPrompts || additionalPrompts.length === 0) { |
| 16 | return initialPrompt; |
| 17 | } |
| 18 | |
| 19 | const processedPrompts: string[] = []; |
| 20 | |
| 21 | for (const promptSpec of additionalPrompts) { |
| 22 | try { |
| 23 | const processed = await processPromptOrRule(promptSpec); |
| 24 | processedPrompts.push(processed); |
| 25 | } catch (error: any) { |
| 26 | logger.warn(`Failed to process prompt "${promptSpec}": ${error.message}`); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | if (processedPrompts.length === 0) { |
| 31 | return initialPrompt; |
| 32 | } |
| 33 | |
| 34 | const combinedPrompts = processedPrompts.join("\n\n"); |
| 35 | return initialPrompt |
| 36 | ? `${combinedPrompts}\n\n${initialPrompt}` |
| 37 | : combinedPrompts; |
| 38 | } |