// Support prompts type PromptParams = Record const generateDiagnosticText = (diagnostics?: any[]) => { if (!diagnostics?.length) return "" return `\nCurrent problems detected:\n${diagnostics .map((d) => `- [${d.source || "Error"}] ${d.message}${d.code ? ` (${d.code})` : ""}`) .join("\n")}` } export const createPrompt = (template: string, params: PromptParams): string => { let result = template for (const [key, value] of Object.entries(params)) { if (key === "diagnostics") { result = result.replaceAll("${diagnosticText}", generateDiagnosticText(value as any[])) } else { result = result.replaceAll(`\${${key}}`, value as string) } } // Replace any remaining placeholders with empty strings result = result.replaceAll(/\${[^}]*}/g, "") return result } interface SupportPromptConfig { label: string description: string template: string } const supportPromptConfigs: Record = { ENHANCE: { label: "Enhance Prompt", description: "Use prompt enhancement to get tailored suggestions or improvements for your inputs. This ensures Roo understands your intent and provides the best possible responses. Available via the ✨ icon in chat.", template: `Generate an enhanced version of this prompt (reply with only the enhanced prompt - no conversation, explanations, lead-in, bullet points, placeholders, or surrounding quotes): \${userInput}`, }, EXPLAIN: { label: "Explain Code", description: "Get detailed explanations of code snippets, functions, or entire files. Useful for understanding complex code or learning new patterns. Available in code actions (lightbulb icon in the editor) and the editor context menu (right-click on selected code).", template: `Explain the following code from file path @/\${filePath}: \${userInput} \`\`\` \${selectedText} \`\`\` Please provide a clear and concise explanation of what this code does, including: 1. The purpose and functionality 2. Key components and their interactions 3. Important patterns or techniques used`, }, FIX: { label: "Fix Issues", description: "Get help identifying and resolving bugs, errors, or code quality issues. Provides step-by-step guidance for fixing problems. Available in code actions (lightbulb icon in the editor) and the editor context menu (right-click on selected code).", template: `Fix any issues in the following code from file path @/\${filePath} \${diagnosticText} \${userInput} \`\`\` \${selectedText} \`\`\` Please: 1. Address all detected problems listed above (if any) 2. Identify any other potential bugs or issues 3. Provide corrected code 4. Explain what was fixed and why`, }, IMPROVE: { label: "Improve Code", description: "Receive suggestions for code optimization, better practices, and architectural improvements while maintaining functionality. Available in code actions (lightbulb icon in the editor) and the editor context menu (right-click on selected code).", template: `Improve the following code from file path @/\${filePath}: \${userInput} \`\`\` \${selectedText} \`\`\` Please suggest improvements for: 1. Code readability and maintainability 2. Performance optimization 3. Best practices and patterns 4. Error handling and edge cases Provide the improved code along with explanations for each enhancement.`, }, ADD_TO_CONTEXT: { label: "Add to Context", description: "Add context to your current task or conversation. Useful for providing additional information or clarifications. Available in code actions (lightbulb icon in the editor). and the editor context menu (right-click on selected code).", template: `@/\${filePath}: \`\`\` \${selectedText} \`\`\``, }, } as const type SupportPromptType = keyof typeof supportPromptConfigs export const supportPrompt = { default: Object.fromEntries(Object.entries(supportPromptConfigs).map(([key, config]) => [key, config.template])), get: (customSupportPrompts: Record | undefined, type: SupportPromptType): string => { return customSupportPrompts?.[type] ?? supportPromptConfigs[type].template }, create: (type: SupportPromptType, params: PromptParams, customSupportPrompts?: Record): string => { const template = supportPrompt.get(customSupportPrompts, type) return createPrompt(template, params) }, } as const export type { SupportPromptType } // Expose labels and descriptions for UI export const supportPromptLabels = Object.fromEntries( Object.entries(supportPromptConfigs).map(([key, config]) => [key, config.label]), ) as Record export const supportPromptDescriptions = Object.fromEntries( Object.entries(supportPromptConfigs).map(([key, config]) => [key, config.description]), ) as Record export type CustomSupportPrompts = { [key: string]: string | undefined }