@@ -32,10 +32,11 @@ export function CodebaseIntelligence({ repo, apiKey, onTabChange }: CodebaseInte
3232
3333 // Derive intelligence from raw data
3434 const intelligence = useMemo ( ( ) => {
35- if ( ! deps ?. metrics ) return null
36-
37- const nodes = deps . nodes || [ ]
38- const edges = deps . edges || [ ]
35+ const nodes = deps ?. nodes || [ ]
36+ const edges = deps ?. edges || [ ]
37+
38+ // Gate on deps existence or having graph data
39+ if ( ! deps && nodes . length === 0 ) return null
3940
4041 // Calculate in-degree and out-degree from edges
4142 const inDegree : Record < string , number > = { }
@@ -90,15 +91,21 @@ export function CodebaseIntelligence({ repo, apiKey, onTabChange }: CodebaseInte
9091 } )
9192
9293 // Find "start here" file - the most critical file that's also an entry point
93- const startHere = criticalFiles [ 0 ] ?. file || entryPoints [ 0 ] ?. file || null
94+ const criticalEntryPoint = criticalFiles . find ( cf =>
95+ entryPoints . some ( ep => ep . file === cf . file )
96+ )
97+ const startHere = criticalEntryPoint ?. file || entryPoints [ 0 ] ?. file || null
9498
9599 // Generate smart summary
96- const totalFiles = deps . total_files || nodes . length
97- const totalFunctions = style ?. summary ?. total_functions || repo . file_count || 0
100+ const totalFiles = deps ? .total_files || nodes . length
101+ const totalFunctions : number | null = style ?. summary ?. total_functions ?? null
98102
99- let sizeDesc = 'compact'
100- if ( totalFunctions > 1000 ) sizeDesc = 'large'
101- else if ( totalFunctions > 200 ) sizeDesc = 'medium-sized'
103+ let sizeDesc : string | null = null
104+ if ( typeof totalFunctions === 'number' ) {
105+ if ( totalFunctions > 1000 ) sizeDesc = 'large'
106+ else if ( totalFunctions > 200 ) sizeDesc = 'medium-sized'
107+ else sizeDesc = 'compact'
108+ }
102109
103110 // Detect patterns
104111 const hasMiddleware = nodes . some ( ( n : any ) =>
@@ -168,9 +175,11 @@ export function CodebaseIntelligence({ repo, apiKey, onTabChange }: CodebaseInte
168175 </ h3 >
169176
170177 < p className = "text-foreground leading-relaxed mb-4" >
171- < strong > { repo . name } </ strong > is a { intelligence . summary . size } { intelligence . summary . language } codebase
172- with < span className = "text-primary font-semibold" > { intelligence . summary . totalFunctions . toLocaleString ( ) } </ span > functions
173- across { intelligence . summary . totalFiles } files.
178+ < strong > { repo . name } </ strong > is a { intelligence . summary . size ? `${ intelligence . summary . size } ` : '' } { intelligence . summary . language } codebase
179+ { intelligence . summary . totalFunctions != null ? (
180+ < > with < span className = "text-primary font-semibold" > { intelligence . summary . totalFunctions . toLocaleString ( ) } </ span > functions</ >
181+ ) : null }
182+ { ' ' } across { intelligence . summary . totalFiles } files.
174183 { intelligence . summary . pattern && (
175184 < > Uses { intelligence . summary . pattern } .</ >
176185 ) }
@@ -367,8 +376,8 @@ export function CodebaseIntelligence({ repo, apiKey, onTabChange }: CodebaseInte
367376 )
368377}
369378
370- function HealthIndicator ( { label, value, threshold } : { label : string , value : string | null , threshold : number } ) {
371- if ( ! value ) {
379+ function HealthIndicator ( { label, value, threshold } : { label : string , value : string | number | null , threshold : number } ) {
380+ if ( value == null ) {
372381 return (
373382 < div className = "p-3 bg-muted/50 rounded-lg" >
374383 < p className = "text-[10px] text-muted-foreground uppercase tracking-wide mb-1" > { label } </ p >
@@ -377,15 +386,16 @@ function HealthIndicator({ label, value, threshold }: { label: string, value: st
377386 )
378387 }
379388
380- const numValue = parseFloat ( value )
381- const isGood = numValue >= threshold
389+ const numValue = typeof value === 'number' ? value : parseFloat ( value )
390+ const isGood = ! isNaN ( numValue ) && numValue >= threshold
391+ const displayValue = typeof value === 'number' ? `${ value } %` : value
382392
383393 return (
384394 < div className = "p-3 bg-muted/50 rounded-lg" >
385395 < p className = "text-[10px] text-muted-foreground uppercase tracking-wide mb-1" > { label } </ p >
386396 < p className = { `text-sm font-semibold flex items-center gap-1 ${ isGood ? 'text-green-600 dark:text-green-400' : 'text-foreground' } ` } >
387397 { isGood && < CheckCircle2 className = "w-3.5 h-3.5" /> }
388- { value }
398+ { displayValue }
389399 </ p >
390400 </ div >
391401 )
0 commit comments