11import { globby } from 'globby' ;
2- import type { Document , Scanner , ScanOptions , ScanResult } from './types' ;
2+ import type { Document , Scanner , ScanOptions , ScanProgress , ScanResult } from './types' ;
33
44/**
55 * Scanner registry manages multiple language scanners
@@ -60,6 +60,24 @@ export class ScannerRegistry {
6060 async scanRepository ( options : ScanOptions ) : Promise < ScanResult > {
6161 const startTime = Date . now ( ) ;
6262 const errors : Array < { file : string ; error : string } > = [ ] ;
63+ const logger = options . logger ?. child ( { component : 'scanner' } ) ;
64+ const onProgress = options . onProgress ;
65+
66+ // Helper to emit progress
67+ const emitProgress = ( progress : Partial < ScanProgress > ) => {
68+ onProgress ?.( {
69+ phase : 'discovery' ,
70+ filesTotal : 0 ,
71+ filesScanned : 0 ,
72+ documentsExtracted : 0 ,
73+ errors : errors . length ,
74+ ...progress ,
75+ } ) ;
76+ } ;
77+
78+ // Phase 1: Discovery
79+ logger ?. info ( { repoRoot : options . repoRoot } , 'Starting repository scan' ) ;
80+ emitProgress ( { phase : 'discovery' } ) ;
6381
6482 // Build glob patterns
6583 const patterns = this . buildGlobPatterns ( options ) ;
@@ -71,6 +89,8 @@ export class ScannerRegistry {
7189 absolute : false ,
7290 } ) ;
7391
92+ logger ?. info ( { totalFiles : files . length } , 'File discovery complete' ) ;
93+
7494 // Group files by scanner
7595 const filesByScanner = new Map < Scanner , string [ ] > ( ) ;
7696
@@ -83,23 +103,85 @@ export class ScannerRegistry {
83103 }
84104 }
85105
86- // Scan files with appropriate scanners
106+ // Log per-language breakdown
107+ const languageBreakdown : Record < string , number > = { } ;
108+ for ( const [ scanner , scannerFiles ] of filesByScanner ) {
109+ languageBreakdown [ scanner . language ] = scannerFiles . length ;
110+ logger ?. info (
111+ { language : scanner . language , files : scannerFiles . length } ,
112+ `Found ${ scannerFiles . length } ${ scanner . language } files`
113+ ) ;
114+ }
115+
116+ // Phase 2: Scanning
87117 const allDocuments : Document [ ] = [ ] ;
118+ let totalFilesScanned = 0 ;
88119
89120 for ( const [ scanner , scannerFiles ] of filesByScanner . entries ( ) ) {
121+ logger ?. debug (
122+ { language : scanner . language , fileCount : scannerFiles . length } ,
123+ `Scanning ${ scanner . language } ...`
124+ ) ;
125+
126+ emitProgress ( {
127+ phase : 'scanning' ,
128+ language : scanner . language ,
129+ filesTotal : files . length ,
130+ filesScanned : totalFilesScanned ,
131+ documentsExtracted : allDocuments . length ,
132+ } ) ;
133+
90134 try {
91135 const documents = await scanner . scan ( scannerFiles , options . repoRoot ) ;
92136 allDocuments . push ( ...documents ) ;
137+ totalFilesScanned += scannerFiles . length ;
138+
139+ logger ?. info (
140+ { language : scanner . language , files : scannerFiles . length , documents : documents . length } ,
141+ `${ scanner . language } scan complete`
142+ ) ;
143+
144+ emitProgress ( {
145+ phase : 'scanning' ,
146+ language : scanner . language ,
147+ filesTotal : files . length ,
148+ filesScanned : totalFilesScanned ,
149+ documentsExtracted : allDocuments . length ,
150+ } ) ;
93151 } catch ( error ) {
152+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
94153 errors . push ( {
95154 file : `[${ scanner . language } ]` ,
96- error : error instanceof Error ? error . message : String ( error ) ,
155+ error : errorMessage ,
97156 } ) ;
157+ logger ?. error (
158+ { language : scanner . language , error : errorMessage } ,
159+ `${ scanner . language } scan failed`
160+ ) ;
98161 }
99162 }
100163
164+ // Phase 3: Complete
101165 const duration = Date . now ( ) - startTime ;
102166
167+ logger ?. info (
168+ {
169+ totalFiles : files . length ,
170+ totalDocuments : allDocuments . length ,
171+ duration : `${ duration } ms` ,
172+ byLanguage : languageBreakdown ,
173+ errors : errors . length ,
174+ } ,
175+ 'Repository scan complete'
176+ ) ;
177+
178+ emitProgress ( {
179+ phase : 'complete' ,
180+ filesTotal : files . length ,
181+ filesScanned : totalFilesScanned ,
182+ documentsExtracted : allDocuments . length ,
183+ } ) ;
184+
103185 return {
104186 documents : allDocuments ,
105187 stats : {
@@ -152,6 +234,15 @@ export class ScannerRegistry {
152234 '**/.turbo/**' ,
153235 '**/.nuxt/**' ,
154236
237+ // Go generated files
238+ '**/*.pb.go' , // Protobuf
239+ '**/*.gen.go' , // Code generators
240+ '**/*_gen.go' , // Alternative generator pattern
241+ '**/*.pb.gw.go' , // gRPC gateway
242+ '**/mock_*.go' , // Mockgen files
243+ '**/mocks/**' , // Mock directories
244+ '**/testdata/**' , // Test fixtures
245+
155246 // Version control
156247 '**/.git/**' ,
157248 '**/.svn/**' ,
0 commit comments