@@ -3,7 +3,7 @@ import path from 'path';
33import fs from 'fs' ;
44import { minimatch } from 'minimatch' ;
55
6- const MAX_REVIEW_FILES = 10 ;
6+ const MAX_REVIEW_FILES = 15 ;
77const MAX_FILE_LINES = 5000 ;
88const MAX_FILE_SIZE_BYTES = 200 * 1024 ; // 200 KB
99
@@ -184,41 +184,20 @@ class ReviewApiHelper extends CommonApiHelper {
184184 return true ;
185185 } ) ;
186186
187- // Dedupe by filename, keeping all hunks, but limit unique files to MAX_REVIEW_FILES
187+ // Dedupe by filename, keeping all hunks (no cap yet — applied after size filtering)
188188 const fileOrder = [ ] ;
189189 const fileHunks = new Map ( ) ;
190- let capped = false ;
191190 for ( const d of reviewable ) {
192191 const f = d . filename_str ;
193192 if ( ! fileHunks . has ( f ) ) {
194- if ( fileOrder . length >= MAX_REVIEW_FILES ) {
195- capped = true ;
196- if ( ! seenSkipped . has ( f ) ) {
197- dedupedSkipped . push ( { file : f , reason : `exceeded ${ MAX_REVIEW_FILES } -file limit` } ) ;
198- seenSkipped . add ( f ) ;
199- }
200- continue ;
201- }
202193 fileOrder . push ( f ) ;
203194 fileHunks . set ( f , [ ] ) ;
204195 }
205196 fileHunks . get ( f ) . push ( d ) ;
206197 }
207198
208- // Reconstruct a combined diff string from the filtered hunks
209- const parts = [ ] ;
210- for ( const f of fileOrder ) {
211- const hunks = fileHunks . get ( f ) ;
212- // Build a file-level diff header + all hunk patches
213- const header = `diff --git a/${ f } b/${ f } \n--- a/${ f } \n+++ b/${ f } ` ;
214- const hunkPatches = hunks . map ( h => h . patch_str ) . filter ( Boolean ) ;
215- if ( hunkPatches . length > 0 ) {
216- parts . push ( header + '\n' + hunkPatches . join ( '\n' ) ) ;
217- }
218- }
219-
220199 // Use head_file_str from diffs so file content matches the diff version (avoids working tree mismatch for --last-commit etc.)
221- const fileContents = { } ;
200+ // Filter out files that exceed size or line limits before applying the cap
222201 const skippedLargeFiles = new Set ( ) ;
223202 for ( const f of fileOrder ) {
224203 const hunks = fileHunks . get ( f ) ;
@@ -234,21 +213,49 @@ class ReviewApiHelper extends CommonApiHelper {
234213 if ( lineCount > MAX_FILE_LINES ) {
235214 skippedLargeFiles . add ( f ) ;
236215 dedupedSkipped . push ( { file : f , reason : `too large (${ lineCount } lines, max ${ MAX_FILE_LINES } )` } ) ;
237- continue ;
238216 }
239- fileContents [ f ] = content ;
240217 }
241218 }
242219
243- // Remove diff sections for skipped files
244- const filteredParts = parts . filter ( ( _ , i ) => ! skippedLargeFiles . has ( fileOrder [ i ] ) ) ;
220+ // Apply MAX_REVIEW_FILES cap after all filtering (binary, deleted, pattern, size)
221+ let capped = false ;
222+ const cappedFileOrder = [ ] ;
223+ for ( const f of fileOrder ) {
224+ if ( skippedLargeFiles . has ( f ) ) continue ;
225+ if ( cappedFileOrder . length >= MAX_REVIEW_FILES ) {
226+ capped = true ;
227+ if ( ! seenSkipped . has ( f ) ) {
228+ dedupedSkipped . push ( { file : f , reason : `exceeded ${ MAX_REVIEW_FILES } -file limit` } ) ;
229+ seenSkipped . add ( f ) ;
230+ }
231+ continue ;
232+ }
233+ cappedFileOrder . push ( f ) ;
234+ }
235+
236+ // Build file contents for the capped set
237+ const fileContents = { } ;
238+ for ( const f of cappedFileOrder ) {
239+ const content = fileHunks . get ( f ) [ 0 ] ?. head_file_str || '' ;
240+ if ( content ) fileContents [ f ] = content ;
241+ }
242+
243+ // Reconstruct a combined diff string from the capped set
244+ const parts = [ ] ;
245+ for ( const f of cappedFileOrder ) {
246+ const hunks = fileHunks . get ( f ) ;
247+ const header = `diff --git a/${ f } b/${ f } \n--- a/${ f } \n+++ b/${ f } ` ;
248+ const hunkPatches = hunks . map ( h => h . patch_str ) . filter ( Boolean ) ;
249+ if ( hunkPatches . length > 0 ) {
250+ parts . push ( header + '\n' + hunkPatches . join ( '\n' ) ) ;
251+ }
252+ }
245253
246- const reviewedFiles = fileOrder . filter ( f => ! skippedLargeFiles . has ( f ) ) ;
247254 return {
248- diff_content : filteredParts . join ( '\n' ) ,
255+ diff_content : parts . join ( '\n' ) ,
249256 file_contents : fileContents ,
250257 _meta : {
251- reviewed_files : reviewedFiles ,
258+ reviewed_files : cappedFileOrder ,
252259 total_changed : allUniqueFiles . size ,
253260 skipped : dedupedSkipped ,
254261 capped,
0 commit comments