/** * SMI-1303: Result Aggregator * SMI-1337: Added metrics integration * * Aggregates parse results from multiple languages into unified context. * Collects imports, exports, and functions across all analyzed files. * * @see docs/internal/architecture/multi-language-analysis.md * @module analysis/aggregator */ import type { SupportedLanguage, ImportInfo, ExportInfo, FunctionInfo, ParseResult, CodebaseContext, FrameworkInfo, DependencyInfo } from './types.js'; import { type AnalysisMetrics } from './metrics.js'; /** * Input for adding a parse result to the aggregator */ export interface AggregatorInput { /** Path to the parsed file */ filePath: string; /** Language of the file */ language: SupportedLanguage; /** Parse result from the adapter */ result: ParseResult; } /** * Metadata for building the final context */ export interface AggregatorMetadata { /** Analysis duration in milliseconds */ durationMs: number; /** Analyzer version string */ version: string; /** Cache hit rate (0-1) */ cacheHitRate: number; } /** * Options for ResultAggregator */ export interface AggregatorOptions { /** Custom metrics instance (uses default if not provided) */ metrics?: AnalysisMetrics; } /** * Aggregates parse results from multiple languages into unified context * * Collects results from individual file parses and merges them * into a single CodebaseContext for skill recommendations. * * @example * ```typescript * const aggregator = new ResultAggregator() * * // Add results as files are parsed * aggregator.add({ * filePath: 'src/main.py', * language: 'python', * result: pythonAdapter.parseFile(content, 'src/main.py') * }) * * aggregator.add({ * filePath: 'src/index.ts', * language: 'typescript', * result: tsAdapter.parseFile(content, 'src/index.ts') * }) * * // Build final context * const context = aggregator.build('/path/to/project', dependencies, frameworks, metadata) * ``` */ export declare class ResultAggregator { private imports; private exports; private functions; private filesByExtension; private filesByLanguage; private totalLines; private languages; private fileCount; private readonly metrics; constructor(options?: AggregatorOptions); /** * Add parse result to aggregation * * Extracts imports, exports, and functions from the result * and annotates them with language information. * * SMI-1337: Updates aggregator metrics. * * @param input - File path, language, and parse result * * @example * ```typescript * aggregator.add({ * filePath: 'src/utils.py', * language: 'python', * result: adapter.parseFile(content, 'src/utils.py') * }) * ``` */ add(input: AggregatorInput): void; /** * Update aggregator metrics * SMI-1337: Helper to keep metrics in sync */ private updateMetrics; /** * Add line count for a file * * Call this separately from add() if line counting is done * during file reading rather than parsing. * * @param count - Number of lines in the file */ addLines(count: number): void; /** * Get current imports (read-only) */ getImports(): readonly ImportInfo[]; /** * Get current exports (read-only) */ getExports(): readonly ExportInfo[]; /** * Get current functions (read-only) */ getFunctions(): readonly FunctionInfo[]; /** * Get current file count */ getFileCount(): number; /** * Get detected languages */ getLanguages(): SupportedLanguage[]; /** * Build final CodebaseContext * * Combines all aggregated data with dependencies, frameworks, * and metadata into the final context structure. * * SMI-1337: Records final aggregation metrics. * * @param rootPath - Root path of the analyzed codebase * @param dependencies - Dependencies from all package managers * @param frameworks - Detected frameworks * @param metadata - Analysis metadata * @returns Complete codebase context * * @example * ```typescript * const context = aggregator.build( * '/path/to/project', * dependencies, * frameworks, * { durationMs: 1234, version: '2.0.0', cacheHitRate: 0.85 } * ) * ``` */ build(rootPath: string, dependencies: DependencyInfo[], frameworks: FrameworkInfo[], metadata: AggregatorMetadata): CodebaseContext; /** * Build language stats with all languages initialized to 0 */ private buildLanguageStats; /** * Reset aggregator for new analysis * * Clears all collected data. Call this before starting * a new analysis on a different codebase. * * SMI-1337: Resets aggregator metrics as well. */ reset(): void; /** * Merge another aggregator's results into this one * * Useful for parallel processing where each worker * has its own aggregator. * * @param other - Aggregator to merge from */ merge(other: ResultAggregator): void; /** * Get summary statistics */ getSummary(): { files: number; imports: number; exports: number; functions: number; lines: number; languages: SupportedLanguage[]; }; } //# sourceMappingURL=aggregator.d.ts.map