UNPKG

@bobmatnyc/ai-code-review

Version:

A TypeScript-based tool for automated code reviews using AI models from Google Gemini, Anthropic Claude, and OpenRouter

171 lines (170 loc) 5.48 kB
/** * @fileoverview Prompt manager for loading and managing prompt templates. * * IMPORTANT: This module provides a singleton manager for prompt templates. * All core prompts are bundled with the package in bundledPrompts.ts. * The system prioritizes bundled prompts and only falls back to file system * prompts if a bundled prompt is not found. * * Custom prompts can still be provided via the promptFile option or by * registering custom templates programmatically. */ import { ReviewType, ReviewOptions } from '../types/review'; /** * Interface for prompt template metadata */ export interface PromptTemplateMetadata { /** * Name of the template */ name: string; /** * Description of the template */ description: string; /** * Version of the template */ version: string; /** * Author of the template */ author: string; /** * Language the template is designed for */ language?: string; /** * Framework the template is designed for */ framework?: string; /** * Review type the template is designed for */ reviewType: ReviewType; /** * Tags associated with the template */ tags?: string[]; } /** * Interface for a prompt template */ export interface PromptTemplate { /** * Content of the template */ content: string; /** * Metadata for the template */ metadata: PromptTemplateMetadata; /** * Path to the template file */ path: string; } /** * Singleton manager for prompt templates */ export declare class PromptManager { private static instance; private templates; private customTemplates; private promptCache; private promptBuilder; /** * Private constructor to enforce singleton pattern */ private constructor(); /** * Get the singleton instance * @returns The prompt manager instance */ static getInstance(): PromptManager; /** * Register a custom prompt template * @param template Prompt template to register */ registerCustomTemplate(template: PromptTemplate): void; /** * Get a template key based on review type, language, and framework * @param reviewType Type of review * @param language Programming language * @param framework Framework (optional) * @returns Template key */ private getTemplateKey; /** * Load custom prompt templates from a directory * @param templatesDir Directory containing templates * * IMPORTANT: This method is only for loading CUSTOM templates. * Core prompts are bundled with the package in bundledPrompts.ts. * This method should only be used for loading user-provided templates * that extend or override the bundled ones. */ loadTemplates(templatesDir: string): Promise<void>; /** * Extract metadata from a prompt template * @param content Template content * @param fileName Name of the template file * @returns Prompt template metadata */ private extractMetadata; /** * Get review type from a file name * @param fileName Name of the template file * @returns Review type */ private getReviewTypeFromFileName; /** * Get a prompt template * @param reviewType Type of review * @param options Review options * @returns Promise resolving to the prompt template content * * IMPORTANT: This method prioritizes prompts in the following order: * 1. Custom prompt file specified in options * 2. Custom templates registered programmatically * 3. Bundled prompts (PRIMARY SOURCE) * 4. Custom templates loaded from the file system (FALLBACK ONLY) * * Core functionality should ALWAYS use bundled prompts to ensure * the system works correctly regardless of installation environment. */ getPromptTemplate(reviewType: ReviewType, options?: ReviewOptions): Promise<string>; /** * IMPORTANT: The loadPromptTemplateFromFileSystem method has been removed. * We now use bundled prompts as the PRIMARY AND ONLY SOURCE for prompts. * * All prompts are defined in the bundledPrompts.ts file and accessed through * the getBundledPrompt function. The system does NOT load prompts from the * file system anymore. * * If you need to add or modify prompts, you must update the bundledPrompts.ts file. */ private loadPromptTemplateFromFileSystem; /** * Process a prompt template by replacing placeholders * @param promptTemplate The raw prompt template * @param options Review options * @returns The processed prompt template */ private processPromptTemplate; /** * List all available prompt templates * @returns Array of prompt template metadata */ listTemplates(): PromptTemplateMetadata[]; /** * Provide feedback on a prompt * @param reviewType Type of review * @param promptContent Content of the prompt * @param rating Rating of the prompt (1-5) * @param comments Comments on the prompt quality * @param positiveAspects Positive aspects of the prompt * @param negativeAspects Negative aspects of the prompt */ provideFeedback(reviewType: ReviewType, promptContent: string, rating: number, _comments?: string, _positiveAspects?: string[], _negativeAspects?: string[]): Promise<void>; }