UNPKG

@bobmatnyc/ai-code-review

Version:

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

191 lines (190 loc) 5.41 kB
/** * @fileoverview Intelligent chunk generator for semantic code analysis * * This module generates optimal code chunks based on semantic analysis results, * implementing AI-guided chunking strategies that understand code structure * and relationships for more effective code review. */ import { SemanticAnalysis, ChunkingRecommendation } from './types'; /** * Configuration for chunk generation */ export interface ChunkGeneratorConfig { /** Maximum lines per chunk */ maxChunkSize: number; /** Minimum lines per chunk */ minChunkSize: number; /** Whether to include context declarations */ includeContext: boolean; /** Maximum context declarations per chunk */ maxContextDeclarations: number; /** Token estimation factor (tokens per line) */ tokensPerLine: number; /** Complexity threshold for high priority */ highComplexityThreshold: number; /** Complexity threshold for medium priority */ mediumComplexityThreshold: number; } /** * Intelligent chunk generator for semantic code analysis */ export declare class ChunkGenerator { private config; constructor(config?: Partial<ChunkGeneratorConfig>); /** * Generate intelligent code chunks from semantic analysis */ generateChunks(analysis: SemanticAnalysis, fileContent: string, reviewType?: string): ChunkingRecommendation; /** * Generate individual chunks (each declaration separately) */ private generateIndividualChunks; /** * Generate grouped chunks (related declarations together) */ private generateGroupedChunks; /** * Generate hierarchical chunks (classes with methods) */ private generateHierarchicalChunks; /** * Generate functional chunks (by shared dependencies) */ private generateFunctionalChunks; /** * Generate contextual chunks (by shared context) */ private generateContextualChunks; /** * Generate fallback chunks when semantic analysis fails */ private generateFallbackChunks; /** * Create a chunk from a single declaration */ private createChunkFromDeclaration; /** * Create a chunk from multiple declarations */ private createChunkFromDeclarations; /** * Create class hierarchy chunks */ private createClassHierarchyChunks; /** * Create class header chunk (class declaration without methods) */ private createClassHeaderChunk; /** * Create import chunk for significant import statements */ private createImportChunk; /** * Group related declarations based on naming and dependencies */ private groupRelatedDeclarations; /** * Check if two declarations are related */ private areDeclarationsRelated; /** * Group declarations by shared dependencies */ private groupByDependencies; /** * Group declarations by broader context */ private groupByContext; /** * Group class methods intelligently */ private groupClassMethods; /** * Split large groups into smaller chunks */ private splitLargeGroup; /** * Find context declarations for a given declaration */ private findContextDeclarations; /** * Generate cross-references between chunks */ private generateCrossReferences; /** * Analyze relationship between two chunks */ private analyzeChunkRelationship; /** * Map declaration type to review unit */ private mapDeclarationToReviewUnit; /** * Determine review unit for a group of declarations */ private determineGroupReviewUnit; /** * Calculate priority for a declaration */ private calculatePriority; /** * Calculate priority for a group of declarations */ private calculateGroupPriority; /** * Get review focus for a declaration */ private getReviewFocusForDeclaration; /** * Get review focus for multiple declarations */ private getReviewFocusForDeclarations; /** * Get review focus based on review type */ private getReviewFocusForType; /** * Estimate token count for a line range */ private estimateTokens; /** * Check if declaration is important (shouldn't be skipped even if small) */ private isImportantDeclaration; /** * Check if declaration is security critical */ private isSecurityCritical; /** * Check if two names are similar */ private haveSimilarNames; /** * Get common prefix of two strings */ private getCommonPrefix; /** * Generate reasoning explanation for chunking decisions */ private generateReasoningExplanation; /** * Generate fallback recommendation when chunking fails */ private generateFallbackRecommendation; /** * Update configuration */ updateConfig(config: Partial<ChunkGeneratorConfig>): void; /** * Get current configuration */ getConfig(): ChunkGeneratorConfig; } /** * Default chunk generator instance */ export declare const chunkGenerator: ChunkGenerator; /** * Convenience function for generating chunks */ export declare function generateSemanticChunks(analysis: SemanticAnalysis, fileContent: string, reviewType?: string): ChunkingRecommendation;