@@ -29,6 +29,7 @@ def stack_name(self) -> str:
2929 def __init__ (self , project_dir : Path ):
3030 super ().__init__ (project_dir )
3131 self ._detected_stack = "nodejs" # Default, may change to "express" or "nestjs"
32+ self ._detection_confidence : float | None = None # Store confidence from can_analyze()
3233
3334 def can_analyze (self ) -> tuple [bool , float ]:
3435 """Detect if this is a Node.js/Express/NestJS project."""
@@ -48,6 +49,7 @@ def can_analyze(self) -> tuple[bool, float]:
4849 if "@nestjs/core" in deps :
4950 self ._detected_stack = "nestjs"
5051 confidence = 0.95
52+ self ._detection_confidence = confidence
5153 return True , confidence
5254
5355 # Check for Express
@@ -60,24 +62,28 @@ def can_analyze(self) -> tuple[bool, float]:
6062 (self .project_dir / "src" / "routes" ).exists ():
6163 confidence = 0.9
6264
65+ self ._detection_confidence = confidence
6366 return True , confidence
6467
6568 # Check for Fastify
6669 if "fastify" in deps :
6770 self ._detected_stack = "fastify"
6871 confidence = 0.85
72+ self ._detection_confidence = confidence
6973 return True , confidence
7074
7175 # Check for Koa
7276 if "koa" in deps :
7377 self ._detected_stack = "koa"
7478 confidence = 0.85
79+ self ._detection_confidence = confidence
7580 return True , confidence
7681
7782 # Generic Node.js (has node-specific files but no specific framework)
7883 if "type" in data and data ["type" ] == "module" :
7984 self ._detected_stack = "nodejs"
8085 confidence = 0.5
86+ self ._detection_confidence = confidence
8187 return True , confidence
8288
8389 except (json .JSONDecodeError , OSError ):
@@ -88,7 +94,9 @@ def can_analyze(self) -> tuple[bool, float]:
8894 for file in common_files :
8995 if (self .project_dir / file ).exists ():
9096 self ._detected_stack = "nodejs"
91- return True , 0.5
97+ confidence = 0.5
98+ self ._detection_confidence = confidence
99+ return True , confidence
92100
93101 return False , 0.0
94102
@@ -158,9 +166,13 @@ def analyze(self) -> AnalysisResult:
158166 # Routes is the same as endpoints for Node.js analyzers
159167 routes = endpoints
160168
169+ # Use stored detection confidence with fallback to 0.85, clamped to [0.0, 1.0]
170+ confidence = float (self ._detection_confidence ) if self ._detection_confidence is not None else 0.85
171+ confidence = max (0.0 , min (1.0 , confidence ))
172+
161173 return {
162174 "stack_name" : self ._detected_stack ,
163- "confidence" : 0.85 ,
175+ "confidence" : confidence ,
164176 "routes" : routes ,
165177 "components" : components ,
166178 "endpoints" : endpoints ,
0 commit comments