/** * Scanner Service - Enterprise-grade pattern detection with Worker Threads * * Uses the real detectors from driftdetect-detectors to find * high-value architectural patterns and violations. * * Now uses Piscina worker threads for parallel CPU-bound processing. */ import { ManifestStore, type Manifest } from 'driftdetect-core'; /** * Project-wide context for detection */ export interface ProjectContext { rootDir: string; files: string[]; config: Record; } /** * Scanner service configuration */ export interface ScannerServiceConfig { rootDir: string; verbose?: boolean; categories?: string[]; /** Only run critical/high-value detectors */ criticalOnly?: boolean; /** Enable manifest generation */ generateManifest?: boolean; /** Only scan changed files (incremental) */ incremental?: boolean; /** Use worker threads for parallel processing */ useWorkerThreads?: boolean; /** Number of worker threads (default: CPU cores - 1) */ workerThreads?: number; } /** * Aggregated pattern match across files * * Enhanced to preserve all metadata from detectors including: * - Full location range (endLine/endColumn) * - Outlier information per location * - Matched text for context */ export interface AggregatedPattern { patternId: string; detectorId: string; category: string; subcategory: string; name: string; description: string; locations: Array<{ file: string; line: number; column: number; /** End line for full range highlighting */ endLine?: number; /** End column for full range highlighting */ endColumn?: number; /** Whether this specific location is an outlier */ isOutlier?: boolean; /** Reason for outlier classification */ outlierReason?: string; /** The actual text that was matched */ matchedText?: string; /** Per-location confidence score */ confidence?: number; }>; confidence: number; occurrences: number; /** Total number of outliers across all locations */ outlierCount: number; /** Custom metadata from detectors */ metadata?: Record; } /** * Aggregated violation across files */ export interface AggregatedViolation { patternId: string; detectorId: string; category: string; severity: 'error' | 'warning' | 'info' | 'hint'; file: string; line: number; column: number; message: string; explanation?: string | undefined; suggestedFix?: string | undefined; } /** * Scan result for a single file */ export interface FileScanResult { file: string; patterns: Array<{ patternId: string; detectorId: string; confidence: number; location: { file: string; line: number; column: number; endLine?: number; endColumn?: number; }; isOutlier?: boolean; outlierReason?: string; matchedText?: string; metadata?: Record; }>; violations: AggregatedViolation[]; duration: number; error?: string | undefined; } /** * Overall scan results */ export interface ScanResults { files: FileScanResult[]; patterns: AggregatedPattern[]; violations: AggregatedViolation[]; totalPatterns: number; totalViolations: number; totalFiles: number; duration: number; errors: string[]; detectorStats: { total: number; ran: number; skipped: number; }; /** Manifest with semantic locations (if generateManifest is true) */ manifest?: Manifest | undefined; /** Worker thread stats (if useWorkerThreads is true) */ workerStats?: { threadsUsed: number; tasksCompleted: number; } | undefined; } /** * Scanner Service * * Orchestrates pattern detection across files using real detectors. * Supports both single-threaded and multi-threaded (Piscina) modes. */ export declare class ScannerService { private config; private detectors; private initialized; private manifestStore; private pool; private PiscinaClass; constructor(config: ScannerServiceConfig); /** * Initialize the scanner service */ initialize(): Promise; /** * Warm up all worker threads by preloading detectors * This runs warmup tasks in parallel so all workers load detectors simultaneously */ private warmupWorkers; /** * Get detector count */ getDetectorCount(): number; /** * Get detector counts by category */ getDetectorCounts(): { api: number; auth: number; security: number; errors: number; structural: number; components: number; styling: number; logging: number; testing: number; dataAccess: number; config: number; types: number; accessibility: number; documentation: number; performance: number; total: number; }; /** * Check if worker threads are enabled and initialized */ isUsingWorkerThreads(): boolean; /** * Get worker thread count */ getWorkerThreadCount(): number; /** * Scan files for patterns */ scanFiles(files: string[], projectContext: ProjectContext): Promise; /** * Scan files using worker threads (parallel) */ private scanFilesWithWorkers; /** * Aggregate results from worker threads */ private aggregateWorkerResults; /** * Add pattern match to manifest */ private addToManifest; /** * Scan files single-threaded (fallback) */ private scanFilesSingleThreaded; /** * Create a semantic location from a basic location */ private createSemanticLocation; /** * Extract semantic information from a line of code */ private extractSemanticInfo; /** * Get the manifest store */ getManifestStore(): ManifestStore | null; /** * Destroy the worker pool */ destroy(): Promise; } /** * Create a scanner service */ export declare function createScannerService(config: ScannerServiceConfig): ScannerService; //# sourceMappingURL=scanner-service.d.ts.map