@grafema/core 0.1.0-alpha.5 → 0.1.1-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/README.md +0 -1
  2. package/dist/Orchestrator.d.ts +24 -2
  3. package/dist/Orchestrator.d.ts.map +1 -1
  4. package/dist/Orchestrator.js +197 -24
  5. package/dist/config/ConfigLoader.d.ts +72 -0
  6. package/dist/config/ConfigLoader.d.ts.map +1 -0
  7. package/dist/config/ConfigLoader.js +187 -0
  8. package/dist/config/index.d.ts +6 -0
  9. package/dist/config/index.d.ts.map +1 -0
  10. package/dist/config/index.js +4 -0
  11. package/dist/core/ASTWorker.d.ts +11 -36
  12. package/dist/core/ASTWorker.d.ts.map +1 -1
  13. package/dist/core/ASTWorker.js +93 -99
  14. package/dist/core/CoverageAnalyzer.d.ts +65 -0
  15. package/dist/core/CoverageAnalyzer.d.ts.map +1 -0
  16. package/dist/core/CoverageAnalyzer.js +198 -0
  17. package/dist/core/FileNodeManager.d.ts +40 -0
  18. package/dist/core/FileNodeManager.d.ts.map +1 -0
  19. package/dist/core/FileNodeManager.js +84 -0
  20. package/dist/core/GraphFreshnessChecker.d.ts +33 -0
  21. package/dist/core/GraphFreshnessChecker.d.ts.map +1 -0
  22. package/dist/core/GraphFreshnessChecker.js +101 -0
  23. package/dist/core/HashUtils.d.ts +24 -0
  24. package/dist/core/HashUtils.d.ts.map +1 -0
  25. package/dist/core/HashUtils.js +45 -0
  26. package/dist/core/IncrementalReanalyzer.d.ts +36 -0
  27. package/dist/core/IncrementalReanalyzer.d.ts.map +1 -0
  28. package/dist/core/IncrementalReanalyzer.js +132 -0
  29. package/dist/core/NodeFactory.d.ts +225 -17
  30. package/dist/core/NodeFactory.d.ts.map +1 -1
  31. package/dist/core/NodeFactory.js +208 -18
  32. package/dist/core/ScopeTracker.d.ts +84 -0
  33. package/dist/core/ScopeTracker.d.ts.map +1 -0
  34. package/dist/core/ScopeTracker.js +116 -0
  35. package/dist/core/SemanticId.d.ts +90 -0
  36. package/dist/core/SemanticId.d.ts.map +1 -0
  37. package/dist/core/SemanticId.js +115 -0
  38. package/dist/core/VersionManager.d.ts.map +1 -1
  39. package/dist/core/VersionManager.js +3 -2
  40. package/dist/core/nodes/ArgumentExpressionNode.d.ts +43 -0
  41. package/dist/core/nodes/ArgumentExpressionNode.d.ts.map +1 -0
  42. package/dist/core/nodes/ArgumentExpressionNode.js +60 -0
  43. package/dist/core/nodes/ArrayLiteralNode.d.ts +27 -0
  44. package/dist/core/nodes/ArrayLiteralNode.d.ts.map +1 -0
  45. package/dist/core/nodes/ArrayLiteralNode.js +41 -0
  46. package/dist/core/nodes/CallSiteNode.d.ts +28 -0
  47. package/dist/core/nodes/CallSiteNode.d.ts.map +1 -1
  48. package/dist/core/nodes/CallSiteNode.js +46 -0
  49. package/dist/core/nodes/ClassNode.d.ts +33 -1
  50. package/dist/core/nodes/ClassNode.d.ts.map +1 -1
  51. package/dist/core/nodes/ClassNode.js +46 -2
  52. package/dist/core/nodes/DecoratorNode.d.ts +42 -0
  53. package/dist/core/nodes/DecoratorNode.d.ts.map +1 -0
  54. package/dist/core/nodes/DecoratorNode.js +62 -0
  55. package/dist/core/nodes/EnumNode.d.ts +42 -0
  56. package/dist/core/nodes/EnumNode.d.ts.map +1 -0
  57. package/dist/core/nodes/EnumNode.js +54 -0
  58. package/dist/core/nodes/ExportNode.d.ts +37 -1
  59. package/dist/core/nodes/ExportNode.d.ts.map +1 -1
  60. package/dist/core/nodes/ExportNode.js +48 -2
  61. package/dist/core/nodes/ExpressionNode.d.ts +97 -0
  62. package/dist/core/nodes/ExpressionNode.d.ts.map +1 -0
  63. package/dist/core/nodes/ExpressionNode.js +178 -0
  64. package/dist/core/nodes/ExternalModuleNode.d.ts +28 -0
  65. package/dist/core/nodes/ExternalModuleNode.d.ts.map +1 -0
  66. package/dist/core/nodes/ExternalModuleNode.js +41 -0
  67. package/dist/core/nodes/ExternalStdioNode.d.ts +13 -6
  68. package/dist/core/nodes/ExternalStdioNode.d.ts.map +1 -1
  69. package/dist/core/nodes/ExternalStdioNode.js +15 -8
  70. package/dist/core/nodes/FunctionNode.d.ts +36 -0
  71. package/dist/core/nodes/FunctionNode.d.ts.map +1 -1
  72. package/dist/core/nodes/FunctionNode.js +80 -1
  73. package/dist/core/nodes/ImportNode.d.ts +19 -5
  74. package/dist/core/nodes/ImportNode.d.ts.map +1 -1
  75. package/dist/core/nodes/ImportNode.js +23 -5
  76. package/dist/core/nodes/InterfaceNode.d.ts +46 -0
  77. package/dist/core/nodes/InterfaceNode.d.ts.map +1 -0
  78. package/dist/core/nodes/InterfaceNode.js +55 -0
  79. package/dist/core/nodes/IssueNode.d.ts +73 -0
  80. package/dist/core/nodes/IssueNode.d.ts.map +1 -0
  81. package/dist/core/nodes/IssueNode.js +129 -0
  82. package/dist/core/nodes/MethodCallNode.d.ts +30 -0
  83. package/dist/core/nodes/MethodCallNode.d.ts.map +1 -1
  84. package/dist/core/nodes/MethodCallNode.js +49 -0
  85. package/dist/core/nodes/MethodNode.d.ts +32 -0
  86. package/dist/core/nodes/MethodNode.d.ts.map +1 -1
  87. package/dist/core/nodes/MethodNode.js +48 -0
  88. package/dist/core/nodes/ModuleNode.d.ts +31 -0
  89. package/dist/core/nodes/ModuleNode.d.ts.map +1 -1
  90. package/dist/core/nodes/ModuleNode.js +37 -0
  91. package/dist/core/nodes/NetworkRequestNode.d.ts +54 -0
  92. package/dist/core/nodes/NetworkRequestNode.d.ts.map +1 -0
  93. package/dist/core/nodes/NetworkRequestNode.js +65 -0
  94. package/dist/core/nodes/ObjectLiteralNode.d.ts +27 -0
  95. package/dist/core/nodes/ObjectLiteralNode.d.ts.map +1 -0
  96. package/dist/core/nodes/ObjectLiteralNode.js +41 -0
  97. package/dist/core/nodes/ScopeNode.d.ts +31 -0
  98. package/dist/core/nodes/ScopeNode.d.ts.map +1 -1
  99. package/dist/core/nodes/ScopeNode.js +49 -0
  100. package/dist/core/nodes/TypeNode.d.ts +36 -0
  101. package/dist/core/nodes/TypeNode.d.ts.map +1 -0
  102. package/dist/core/nodes/TypeNode.js +53 -0
  103. package/dist/core/nodes/VariableDeclarationNode.d.ts +27 -0
  104. package/dist/core/nodes/VariableDeclarationNode.d.ts.map +1 -1
  105. package/dist/core/nodes/VariableDeclarationNode.js +40 -0
  106. package/dist/core/nodes/index.d.ts +12 -1
  107. package/dist/core/nodes/index.d.ts.map +1 -1
  108. package/dist/core/nodes/index.js +14 -0
  109. package/dist/diagnostics/DiagnosticCollector.d.ts +98 -0
  110. package/dist/diagnostics/DiagnosticCollector.d.ts.map +1 -0
  111. package/dist/diagnostics/DiagnosticCollector.js +129 -0
  112. package/dist/diagnostics/DiagnosticReporter.d.ts +77 -0
  113. package/dist/diagnostics/DiagnosticReporter.d.ts.map +1 -0
  114. package/dist/diagnostics/DiagnosticReporter.js +159 -0
  115. package/dist/diagnostics/DiagnosticWriter.d.ts +31 -0
  116. package/dist/diagnostics/DiagnosticWriter.d.ts.map +1 -0
  117. package/dist/diagnostics/DiagnosticWriter.js +43 -0
  118. package/dist/diagnostics/index.d.ts +14 -0
  119. package/dist/diagnostics/index.d.ts.map +1 -0
  120. package/dist/diagnostics/index.js +11 -0
  121. package/dist/errors/GrafemaError.d.ts +118 -0
  122. package/dist/errors/GrafemaError.d.ts.map +1 -0
  123. package/dist/errors/GrafemaError.js +131 -0
  124. package/dist/index.d.ts +57 -1
  125. package/dist/index.d.ts.map +1 -1
  126. package/dist/index.js +54 -1
  127. package/dist/logging/Logger.d.ts +48 -0
  128. package/dist/logging/Logger.d.ts.map +1 -0
  129. package/dist/logging/Logger.js +134 -0
  130. package/dist/plugins/Plugin.d.ts +5 -1
  131. package/dist/plugins/Plugin.d.ts.map +1 -1
  132. package/dist/plugins/Plugin.js +33 -0
  133. package/dist/plugins/analysis/DatabaseAnalyzer.d.ts.map +1 -1
  134. package/dist/plugins/analysis/DatabaseAnalyzer.js +13 -6
  135. package/dist/plugins/analysis/ExpressAnalyzer.d.ts.map +1 -1
  136. package/dist/plugins/analysis/ExpressAnalyzer.js +27 -19
  137. package/dist/plugins/analysis/ExpressRouteAnalyzer.d.ts.map +1 -1
  138. package/dist/plugins/analysis/ExpressRouteAnalyzer.js +21 -14
  139. package/dist/plugins/analysis/FetchAnalyzer.d.ts +1 -0
  140. package/dist/plugins/analysis/FetchAnalyzer.d.ts.map +1 -1
  141. package/dist/plugins/analysis/FetchAnalyzer.js +34 -14
  142. package/dist/plugins/analysis/IncrementalAnalysisPlugin.d.ts +6 -3
  143. package/dist/plugins/analysis/IncrementalAnalysisPlugin.d.ts.map +1 -1
  144. package/dist/plugins/analysis/IncrementalAnalysisPlugin.js +76 -80
  145. package/dist/plugins/analysis/JSASTAnalyzer.d.ts +180 -17
  146. package/dist/plugins/analysis/JSASTAnalyzer.d.ts.map +1 -1
  147. package/dist/plugins/analysis/JSASTAnalyzer.js +1171 -471
  148. package/dist/plugins/analysis/ReactAnalyzer.d.ts.map +1 -1
  149. package/dist/plugins/analysis/ReactAnalyzer.js +56 -57
  150. package/dist/plugins/analysis/RustAnalyzer.d.ts.map +1 -1
  151. package/dist/plugins/analysis/RustAnalyzer.js +15 -10
  152. package/dist/plugins/analysis/SQLiteAnalyzer.d.ts.map +1 -1
  153. package/dist/plugins/analysis/SQLiteAnalyzer.js +9 -7
  154. package/dist/plugins/analysis/ServiceLayerAnalyzer.d.ts.map +1 -1
  155. package/dist/plugins/analysis/ServiceLayerAnalyzer.js +21 -9
  156. package/dist/plugins/analysis/SocketIOAnalyzer.d.ts.map +1 -1
  157. package/dist/plugins/analysis/SocketIOAnalyzer.js +27 -15
  158. package/dist/plugins/analysis/SystemDbAnalyzer.d.ts.map +1 -1
  159. package/dist/plugins/analysis/SystemDbAnalyzer.js +15 -5
  160. package/dist/plugins/analysis/ast/GraphBuilder.d.ts +34 -4
  161. package/dist/plugins/analysis/ast/GraphBuilder.d.ts.map +1 -1
  162. package/dist/plugins/analysis/ast/GraphBuilder.js +318 -298
  163. package/dist/plugins/analysis/ast/IdGenerator.d.ts +105 -0
  164. package/dist/plugins/analysis/ast/IdGenerator.d.ts.map +1 -0
  165. package/dist/plugins/analysis/ast/IdGenerator.js +116 -0
  166. package/dist/plugins/analysis/ast/types.d.ts +176 -5
  167. package/dist/plugins/analysis/ast/types.d.ts.map +1 -1
  168. package/dist/plugins/analysis/ast/utils/createParameterNodes.d.ts +33 -0
  169. package/dist/plugins/analysis/ast/utils/createParameterNodes.d.ts.map +1 -0
  170. package/dist/plugins/analysis/ast/utils/createParameterNodes.js +89 -0
  171. package/dist/plugins/analysis/ast/utils/index.d.ts +6 -0
  172. package/dist/plugins/analysis/ast/utils/index.d.ts.map +1 -0
  173. package/dist/plugins/analysis/ast/utils/index.js +5 -0
  174. package/dist/plugins/analysis/ast/utils/location.d.ts +87 -0
  175. package/dist/plugins/analysis/ast/utils/location.d.ts.map +1 -0
  176. package/dist/plugins/analysis/ast/utils/location.js +78 -0
  177. package/dist/plugins/analysis/ast/visitors/ASTVisitor.d.ts +9 -4
  178. package/dist/plugins/analysis/ast/visitors/ASTVisitor.d.ts.map +1 -1
  179. package/dist/plugins/analysis/ast/visitors/ASTVisitor.js +6 -5
  180. package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.d.ts +99 -9
  181. package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.d.ts.map +1 -1
  182. package/dist/plugins/analysis/ast/visitors/CallExpressionVisitor.js +663 -125
  183. package/dist/plugins/analysis/ast/visitors/ClassVisitor.d.ts +4 -1
  184. package/dist/plugins/analysis/ast/visitors/ClassVisitor.d.ts.map +1 -1
  185. package/dist/plugins/analysis/ast/visitors/ClassVisitor.js +72 -32
  186. package/dist/plugins/analysis/ast/visitors/FunctionVisitor.d.ts +4 -1
  187. package/dist/plugins/analysis/ast/visitors/FunctionVisitor.d.ts.map +1 -1
  188. package/dist/plugins/analysis/ast/visitors/FunctionVisitor.js +128 -63
  189. package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.d.ts.map +1 -1
  190. package/dist/plugins/analysis/ast/visitors/ImportExportVisitor.js +11 -8
  191. package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.d.ts +12 -1
  192. package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.d.ts.map +1 -1
  193. package/dist/plugins/analysis/ast/visitors/TypeScriptVisitor.js +36 -14
  194. package/dist/plugins/analysis/ast/visitors/VariableVisitor.d.ts +4 -1
  195. package/dist/plugins/analysis/ast/visitors/VariableVisitor.d.ts.map +1 -1
  196. package/dist/plugins/analysis/ast/visitors/VariableVisitor.js +17 -13
  197. package/dist/plugins/discovery/MonorepoServiceDiscovery.d.ts.map +1 -1
  198. package/dist/plugins/discovery/MonorepoServiceDiscovery.js +3 -2
  199. package/dist/plugins/discovery/SimpleProjectDiscovery.d.ts.map +1 -1
  200. package/dist/plugins/discovery/SimpleProjectDiscovery.js +5 -1
  201. package/dist/plugins/discovery/WorkspaceDiscovery.d.ts +22 -0
  202. package/dist/plugins/discovery/WorkspaceDiscovery.d.ts.map +1 -0
  203. package/dist/plugins/discovery/WorkspaceDiscovery.js +136 -0
  204. package/dist/plugins/discovery/resolveSourceEntrypoint.d.ts +46 -0
  205. package/dist/plugins/discovery/resolveSourceEntrypoint.d.ts.map +1 -0
  206. package/dist/plugins/discovery/resolveSourceEntrypoint.js +86 -0
  207. package/dist/plugins/discovery/workspaces/detector.d.ts +21 -0
  208. package/dist/plugins/discovery/workspaces/detector.d.ts.map +1 -0
  209. package/dist/plugins/discovery/workspaces/detector.js +49 -0
  210. package/dist/plugins/discovery/workspaces/globResolver.d.ts +35 -0
  211. package/dist/plugins/discovery/workspaces/globResolver.d.ts.map +1 -0
  212. package/dist/plugins/discovery/workspaces/globResolver.js +184 -0
  213. package/dist/plugins/discovery/workspaces/index.d.ts +9 -0
  214. package/dist/plugins/discovery/workspaces/index.d.ts.map +1 -0
  215. package/dist/plugins/discovery/workspaces/index.js +8 -0
  216. package/dist/plugins/discovery/workspaces/parsers.d.ts +38 -0
  217. package/dist/plugins/discovery/workspaces/parsers.d.ts.map +1 -0
  218. package/dist/plugins/discovery/workspaces/parsers.js +80 -0
  219. package/dist/plugins/enrichment/AliasTracker.d.ts.map +1 -1
  220. package/dist/plugins/enrichment/AliasTracker.js +14 -8
  221. package/dist/plugins/enrichment/HTTPConnectionEnricher.d.ts.map +1 -1
  222. package/dist/plugins/enrichment/HTTPConnectionEnricher.js +14 -7
  223. package/dist/plugins/enrichment/ImportExportLinker.d.ts.map +1 -1
  224. package/dist/plugins/enrichment/ImportExportLinker.js +23 -6
  225. package/dist/plugins/enrichment/MethodCallResolver.d.ts.map +1 -1
  226. package/dist/plugins/enrichment/MethodCallResolver.js +18 -12
  227. package/dist/plugins/enrichment/MountPointResolver.d.ts.map +1 -1
  228. package/dist/plugins/enrichment/MountPointResolver.js +8 -3
  229. package/dist/plugins/enrichment/PrefixEvaluator.d.ts.map +1 -1
  230. package/dist/plugins/enrichment/PrefixEvaluator.js +16 -7
  231. package/dist/plugins/enrichment/RustFFIEnricher.d.ts.map +1 -1
  232. package/dist/plugins/enrichment/RustFFIEnricher.js +6 -5
  233. package/dist/plugins/enrichment/ValueDomainAnalyzer.d.ts +17 -0
  234. package/dist/plugins/enrichment/ValueDomainAnalyzer.d.ts.map +1 -1
  235. package/dist/plugins/enrichment/ValueDomainAnalyzer.js +129 -10
  236. package/dist/plugins/indexing/IncrementalModuleIndexer.d.ts.map +1 -1
  237. package/dist/plugins/indexing/IncrementalModuleIndexer.js +23 -14
  238. package/dist/plugins/indexing/JSModuleIndexer.d.ts.map +1 -1
  239. package/dist/plugins/indexing/JSModuleIndexer.js +63 -31
  240. package/dist/plugins/indexing/RustModuleIndexer.d.ts.map +1 -1
  241. package/dist/plugins/indexing/RustModuleIndexer.js +5 -4
  242. package/dist/plugins/indexing/ServiceDetector.d.ts +10 -0
  243. package/dist/plugins/indexing/ServiceDetector.d.ts.map +1 -1
  244. package/dist/plugins/indexing/ServiceDetector.js +28 -15
  245. package/dist/plugins/validation/CallResolverValidator.d.ts.map +1 -1
  246. package/dist/plugins/validation/CallResolverValidator.js +8 -7
  247. package/dist/plugins/validation/DataFlowValidator.d.ts.map +1 -1
  248. package/dist/plugins/validation/DataFlowValidator.js +17 -12
  249. package/dist/plugins/validation/EvalBanValidator.d.ts.map +1 -1
  250. package/dist/plugins/validation/EvalBanValidator.js +17 -16
  251. package/dist/plugins/validation/GraphConnectivityValidator.d.ts.map +1 -1
  252. package/dist/plugins/validation/GraphConnectivityValidator.js +19 -23
  253. package/dist/plugins/validation/NodeCreationValidator.d.ts +85 -0
  254. package/dist/plugins/validation/NodeCreationValidator.d.ts.map +1 -0
  255. package/dist/plugins/validation/NodeCreationValidator.js +415 -0
  256. package/dist/plugins/validation/SQLInjectionValidator.d.ts.map +1 -1
  257. package/dist/plugins/validation/SQLInjectionValidator.js +59 -16
  258. package/dist/plugins/validation/ShadowingDetector.d.ts.map +1 -1
  259. package/dist/plugins/validation/ShadowingDetector.js +6 -5
  260. package/dist/plugins/validation/TypeScriptDeadCodeValidator.d.ts.map +1 -1
  261. package/dist/plugins/validation/TypeScriptDeadCodeValidator.js +12 -11
  262. package/dist/plugins/vcs/GitPlugin.d.ts.map +1 -1
  263. package/dist/plugins/vcs/GitPlugin.js +10 -12
  264. package/dist/plugins/vcs/VCSPlugin.d.ts +3 -2
  265. package/dist/plugins/vcs/VCSPlugin.d.ts.map +1 -1
  266. package/dist/plugins/vcs/VCSPlugin.js +5 -5
  267. package/dist/storage/backends/RFDBServerBackend.d.ts +10 -17
  268. package/dist/storage/backends/RFDBServerBackend.d.ts.map +1 -1
  269. package/dist/storage/backends/RFDBServerBackend.js +31 -10
  270. package/dist/validation/PathValidator.d.ts +1 -2
  271. package/dist/validation/PathValidator.d.ts.map +1 -1
  272. package/package.json +3 -3
  273. package/src/Orchestrator.ts +237 -24
  274. package/src/config/ConfigLoader.ts +263 -0
  275. package/src/config/index.ts +5 -0
  276. package/src/core/ASTWorker.ts +143 -139
  277. package/src/core/CoverageAnalyzer.ts +243 -0
  278. package/src/core/FileNodeManager.ts +100 -0
  279. package/src/core/GraphFreshnessChecker.ts +143 -0
  280. package/src/core/HashUtils.ts +48 -0
  281. package/src/core/IncrementalReanalyzer.ts +192 -0
  282. package/src/core/NodeFactory.ts +401 -18
  283. package/src/core/ScopeTracker.ts +154 -0
  284. package/src/core/SemanticId.ts +192 -0
  285. package/src/core/VersionManager.ts +3 -2
  286. package/src/core/nodes/ArgumentExpressionNode.ts +89 -0
  287. package/src/core/nodes/ArrayLiteralNode.ts +65 -0
  288. package/src/core/nodes/CallSiteNode.ts +58 -0
  289. package/src/core/nodes/ClassNode.ts +63 -2
  290. package/src/core/nodes/DecoratorNode.ts +91 -0
  291. package/src/core/nodes/EnumNode.ts +86 -0
  292. package/src/core/nodes/ExportNode.ts +70 -2
  293. package/src/core/nodes/ExpressionNode.ts +231 -0
  294. package/src/core/nodes/ExternalModuleNode.ts +56 -0
  295. package/src/core/nodes/ExternalStdioNode.ts +17 -9
  296. package/src/core/nodes/FunctionNode.ts +101 -1
  297. package/src/core/nodes/ImportNode.ts +32 -10
  298. package/src/core/nodes/InterfaceNode.ts +91 -0
  299. package/src/core/nodes/IssueNode.ts +177 -0
  300. package/src/core/nodes/MethodCallNode.ts +64 -0
  301. package/src/core/nodes/MethodNode.ts +63 -0
  302. package/src/core/nodes/ModuleNode.ts +50 -0
  303. package/src/core/nodes/NetworkRequestNode.ts +77 -0
  304. package/src/core/nodes/ObjectLiteralNode.ts +65 -0
  305. package/src/core/nodes/ScopeNode.ts +65 -0
  306. package/src/core/nodes/TypeNode.ts +78 -0
  307. package/src/core/nodes/VariableDeclarationNode.ts +52 -0
  308. package/src/core/nodes/index.ts +18 -1
  309. package/src/diagnostics/DiagnosticCollector.ts +163 -0
  310. package/src/diagnostics/DiagnosticReporter.ts +204 -0
  311. package/src/diagnostics/DiagnosticWriter.ts +50 -0
  312. package/src/diagnostics/index.ts +16 -0
  313. package/src/errors/GrafemaError.ts +174 -0
  314. package/src/index.ts +148 -1
  315. package/src/logging/Logger.ts +152 -0
  316. package/src/plugins/Plugin.ts +42 -0
  317. package/src/plugins/analysis/DatabaseAnalyzer.ts +14 -8
  318. package/src/plugins/analysis/ExpressAnalyzer.ts +29 -19
  319. package/src/plugins/analysis/ExpressRouteAnalyzer.ts +22 -21
  320. package/src/plugins/analysis/FetchAnalyzer.ts +39 -16
  321. package/src/plugins/analysis/IncrementalAnalysisPlugin.ts +84 -101
  322. package/src/plugins/analysis/JSASTAnalyzer.ts +1483 -503
  323. package/src/plugins/analysis/ReactAnalyzer.ts +57 -57
  324. package/src/plugins/analysis/RustAnalyzer.ts +15 -10
  325. package/src/plugins/analysis/SQLiteAnalyzer.ts +10 -7
  326. package/src/plugins/analysis/ServiceLayerAnalyzer.ts +22 -16
  327. package/src/plugins/analysis/SocketIOAnalyzer.ts +31 -22
  328. package/src/plugins/analysis/SystemDbAnalyzer.ts +16 -11
  329. package/src/plugins/analysis/ast/GraphBuilder.ts +439 -327
  330. package/src/plugins/analysis/ast/IdGenerator.ts +177 -0
  331. package/src/plugins/analysis/ast/types.ts +209 -6
  332. package/src/plugins/analysis/ast/utils/createParameterNodes.ts +104 -0
  333. package/src/plugins/analysis/ast/utils/index.ts +12 -0
  334. package/src/plugins/analysis/ast/utils/location.ts +103 -0
  335. package/src/plugins/analysis/ast/visitors/ASTVisitor.ts +11 -8
  336. package/src/plugins/analysis/ast/visitors/CallExpressionVisitor.ts +909 -83
  337. package/src/plugins/analysis/ast/visitors/ClassVisitor.ts +97 -44
  338. package/src/plugins/analysis/ast/visitors/FunctionVisitor.ts +159 -93
  339. package/src/plugins/analysis/ast/visitors/ImportExportVisitor.ts +12 -8
  340. package/src/plugins/analysis/ast/visitors/TypeScriptVisitor.ts +41 -14
  341. package/src/plugins/analysis/ast/visitors/VariableVisitor.ts +37 -17
  342. package/src/plugins/discovery/MonorepoServiceDiscovery.ts +3 -2
  343. package/src/plugins/discovery/SimpleProjectDiscovery.ts +6 -1
  344. package/src/plugins/discovery/WorkspaceDiscovery.ts +177 -0
  345. package/src/plugins/discovery/resolveSourceEntrypoint.ts +103 -0
  346. package/src/plugins/discovery/workspaces/detector.ts +63 -0
  347. package/src/plugins/discovery/workspaces/globResolver.ts +229 -0
  348. package/src/plugins/discovery/workspaces/index.ts +23 -0
  349. package/src/plugins/discovery/workspaces/parsers.ts +99 -0
  350. package/src/plugins/enrichment/AliasTracker.ts +14 -8
  351. package/src/plugins/enrichment/HTTPConnectionEnricher.ts +14 -7
  352. package/src/plugins/enrichment/ImportExportLinker.ts +24 -6
  353. package/src/plugins/enrichment/MethodCallResolver.ts +18 -12
  354. package/src/plugins/enrichment/MountPointResolver.ts +8 -3
  355. package/src/plugins/enrichment/PrefixEvaluator.ts +16 -7
  356. package/src/plugins/enrichment/RustFFIEnricher.ts +6 -5
  357. package/src/plugins/enrichment/ValueDomainAnalyzer.ts +149 -12
  358. package/src/plugins/indexing/IncrementalModuleIndexer.ts +23 -14
  359. package/src/plugins/indexing/JSModuleIndexer.ts +74 -34
  360. package/src/plugins/indexing/RustModuleIndexer.ts +5 -4
  361. package/src/plugins/validation/CallResolverValidator.ts +8 -7
  362. package/src/plugins/validation/DataFlowValidator.ts +16 -12
  363. package/src/plugins/validation/EvalBanValidator.ts +17 -16
  364. package/src/plugins/validation/GraphConnectivityValidator.ts +19 -23
  365. package/src/plugins/validation/NodeCreationValidator.ts +554 -0
  366. package/src/plugins/validation/SQLInjectionValidator.ts +61 -15
  367. package/src/plugins/validation/ShadowingDetector.ts +6 -5
  368. package/src/plugins/validation/TypeScriptDeadCodeValidator.ts +12 -11
  369. package/src/plugins/vcs/GitPlugin.ts +40 -12
  370. package/src/plugins/vcs/VCSPlugin.ts +7 -5
  371. package/src/storage/backends/RFDBServerBackend.ts +43 -29
  372. package/src/validation/PathValidator.ts +1 -1
  373. package/dist/core/AnalysisWorker.d.ts +0 -14
  374. package/dist/core/AnalysisWorker.d.ts.map +0 -1
  375. package/dist/core/AnalysisWorker.js +0 -307
  376. package/dist/core/ParallelAnalyzer.d.ts +0 -120
  377. package/dist/core/ParallelAnalyzer.d.ts.map +0 -1
  378. package/dist/core/ParallelAnalyzer.js +0 -331
  379. package/dist/core/QueueWorker.d.ts +0 -12
  380. package/dist/core/QueueWorker.d.ts.map +0 -1
  381. package/dist/core/QueueWorker.js +0 -567
  382. package/dist/core/RFDBClient.d.ts +0 -179
  383. package/dist/core/RFDBClient.d.ts.map +0 -1
  384. package/dist/core/RFDBClient.js +0 -429
  385. package/dist/plugins/discovery/ZonServiceDiscovery.d.ts +0 -19
  386. package/dist/plugins/discovery/ZonServiceDiscovery.d.ts.map +0 -1
  387. package/dist/plugins/discovery/ZonServiceDiscovery.js +0 -204
  388. package/src/core/AnalysisWorker.ts +0 -410
  389. package/src/core/ParallelAnalyzer.ts +0 -476
  390. package/src/core/QueueWorker.ts +0 -780
  391. package/src/plugins/indexing/ServiceDetector.ts +0 -230
@@ -0,0 +1,187 @@
1
+ import { readFileSync, existsSync, statSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { parse as parseYAML } from 'yaml';
4
+ /**
5
+ * Default plugin configuration.
6
+ * Matches current DEFAULT_PLUGINS in analyze.ts and config.ts (MCP).
7
+ */
8
+ export const DEFAULT_CONFIG = {
9
+ plugins: {
10
+ discovery: [],
11
+ indexing: ['JSModuleIndexer'],
12
+ analysis: [
13
+ 'JSASTAnalyzer',
14
+ 'ExpressRouteAnalyzer',
15
+ 'SocketIOAnalyzer',
16
+ 'DatabaseAnalyzer',
17
+ 'FetchAnalyzer',
18
+ 'ServiceLayerAnalyzer',
19
+ ],
20
+ enrichment: [
21
+ 'MethodCallResolver',
22
+ 'AliasTracker',
23
+ 'ValueDomainAnalyzer',
24
+ 'MountPointResolver',
25
+ 'PrefixEvaluator',
26
+ 'ImportExportLinker',
27
+ 'HTTPConnectionEnricher',
28
+ ],
29
+ validation: [
30
+ 'CallResolverValidator',
31
+ 'EvalBanValidator',
32
+ 'SQLInjectionValidator',
33
+ 'ShadowingDetector',
34
+ 'GraphConnectivityValidator',
35
+ 'DataFlowValidator',
36
+ 'TypeScriptDeadCodeValidator',
37
+ ],
38
+ },
39
+ services: [], // Empty by default (uses auto-discovery)
40
+ };
41
+ /**
42
+ * Load Grafema config from project directory.
43
+ *
44
+ * Priority:
45
+ * 1. config.yaml (preferred)
46
+ * 2. config.json (deprecated, fallback)
47
+ * 3. DEFAULT_CONFIG (if neither exists)
48
+ *
49
+ * Warnings:
50
+ * - Logs deprecation warning if config.json is used
51
+ * - Logs parse errors but doesn't throw (returns defaults)
52
+ *
53
+ * @param projectPath - Absolute path to project root
54
+ * @param logger - Optional logger for warnings (defaults to console.warn)
55
+ * @returns Parsed config or defaults
56
+ */
57
+ export function loadConfig(projectPath, logger = console) {
58
+ const grafemaDir = join(projectPath, '.grafema');
59
+ const yamlPath = join(grafemaDir, 'config.yaml');
60
+ const jsonPath = join(grafemaDir, 'config.json');
61
+ // 1. Try YAML first (preferred)
62
+ if (existsSync(yamlPath)) {
63
+ let parsed;
64
+ try {
65
+ const content = readFileSync(yamlPath, 'utf-8');
66
+ parsed = parseYAML(content);
67
+ // Validate structure - ensure plugins sections are arrays if they exist
68
+ if (parsed.plugins) {
69
+ for (const phase of ['discovery', 'indexing', 'analysis', 'enrichment', 'validation']) {
70
+ const value = parsed.plugins[phase];
71
+ if (value !== undefined && value !== null && !Array.isArray(value)) {
72
+ throw new Error(`plugins.${phase} must be an array, got ${typeof value}`);
73
+ }
74
+ }
75
+ }
76
+ }
77
+ catch (err) {
78
+ const error = err instanceof Error ? err : new Error(String(err));
79
+ logger.warn(`Failed to parse config.yaml: ${error.message}`);
80
+ logger.warn('Using default configuration');
81
+ return DEFAULT_CONFIG;
82
+ }
83
+ // Validate services array if present (THROWS on error per Linus review)
84
+ // This is OUTSIDE try-catch - config errors MUST throw
85
+ validateServices(parsed.services, projectPath);
86
+ // Merge with defaults (user config may be partial)
87
+ return mergeConfig(DEFAULT_CONFIG, parsed);
88
+ }
89
+ // 2. Fallback to JSON (migration path)
90
+ if (existsSync(jsonPath)) {
91
+ logger.warn('⚠ config.json is deprecated. Run "grafema init --force" to migrate to config.yaml');
92
+ let parsed;
93
+ try {
94
+ const content = readFileSync(jsonPath, 'utf-8');
95
+ parsed = JSON.parse(content);
96
+ }
97
+ catch (err) {
98
+ const error = err instanceof Error ? err : new Error(String(err));
99
+ logger.warn(`Failed to parse config.json: ${error.message}`);
100
+ logger.warn('Using default configuration');
101
+ return DEFAULT_CONFIG;
102
+ }
103
+ // Validate services array if present (THROWS on error)
104
+ // This is OUTSIDE try-catch - config errors MUST throw
105
+ validateServices(parsed.services, projectPath);
106
+ return mergeConfig(DEFAULT_CONFIG, parsed);
107
+ }
108
+ // 3. No config file - return defaults
109
+ return DEFAULT_CONFIG;
110
+ }
111
+ /**
112
+ * Validate services array structure.
113
+ * THROWS on error (fail loudly per Linus review).
114
+ *
115
+ * @param services - Parsed services array (may be undefined)
116
+ * @param projectPath - Project root for path validation
117
+ */
118
+ function validateServices(services, projectPath) {
119
+ // undefined/null is valid (means use defaults)
120
+ if (services === undefined || services === null) {
121
+ return;
122
+ }
123
+ // Must be an array
124
+ if (!Array.isArray(services)) {
125
+ throw new Error(`Config error: services must be an array, got ${typeof services}`);
126
+ }
127
+ // Validate each service
128
+ for (let i = 0; i < services.length; i++) {
129
+ const svc = services[i];
130
+ // Must be an object
131
+ if (typeof svc !== 'object' || svc === null) {
132
+ throw new Error(`Config error: services[${i}] must be an object`);
133
+ }
134
+ // Name validation - required, non-empty string
135
+ if (typeof svc.name !== 'string') {
136
+ throw new Error(`Config error: services[${i}].name must be a string, got ${typeof svc.name}`);
137
+ }
138
+ if (!svc.name.trim()) {
139
+ throw new Error(`Config error: services[${i}].name cannot be empty or whitespace-only`);
140
+ }
141
+ // Path validation - required, non-empty string
142
+ if (typeof svc.path !== 'string') {
143
+ throw new Error(`Config error: services[${i}].path must be a string, got ${typeof svc.path}`);
144
+ }
145
+ if (!svc.path.trim()) {
146
+ throw new Error(`Config error: services[${i}].path cannot be empty or whitespace-only`);
147
+ }
148
+ // Path validation - must be relative (reject absolute paths per Linus review)
149
+ if (svc.path.startsWith('/') || svc.path.startsWith('~')) {
150
+ throw new Error(`Config error: services[${i}].path must be relative to project root, got "${svc.path}"`);
151
+ }
152
+ // Path validation - must exist
153
+ const absolutePath = join(projectPath, svc.path);
154
+ if (!existsSync(absolutePath)) {
155
+ throw new Error(`Config error: services[${i}].path "${svc.path}" does not exist`);
156
+ }
157
+ // Path validation - must be directory
158
+ if (!statSync(absolutePath).isDirectory()) {
159
+ throw new Error(`Config error: services[${i}].path "${svc.path}" must be a directory`);
160
+ }
161
+ // entryPoint validation (optional field) - must be non-empty string if provided
162
+ if (svc.entryPoint !== undefined) {
163
+ if (typeof svc.entryPoint !== 'string') {
164
+ throw new Error(`Config error: services[${i}].entryPoint must be a string, got ${typeof svc.entryPoint}`);
165
+ }
166
+ if (!svc.entryPoint.trim()) {
167
+ throw new Error(`Config error: services[${i}].entryPoint cannot be empty or whitespace-only`);
168
+ }
169
+ }
170
+ }
171
+ }
172
+ /**
173
+ * Merge user config with defaults.
174
+ * User config takes precedence, but missing sections use defaults.
175
+ */
176
+ function mergeConfig(defaults, user) {
177
+ return {
178
+ plugins: {
179
+ discovery: user.plugins?.discovery ?? defaults.plugins.discovery,
180
+ indexing: user.plugins?.indexing ?? defaults.plugins.indexing,
181
+ analysis: user.plugins?.analysis ?? defaults.plugins.analysis,
182
+ enrichment: user.plugins?.enrichment ?? defaults.plugins.enrichment,
183
+ validation: user.plugins?.validation ?? defaults.plugins.validation,
184
+ },
185
+ services: user.services ?? defaults.services,
186
+ };
187
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Configuration loading utilities
3
+ */
4
+ export { loadConfig, DEFAULT_CONFIG } from './ConfigLoader.js';
5
+ export type { GrafemaConfig } from './ConfigLoader.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/D,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Configuration loading utilities
3
+ */
4
+ export { loadConfig, DEFAULT_CONFIG } from './ConfigLoader.js';
@@ -3,32 +3,13 @@
3
3
  *
4
4
  * Receives: { filePath, moduleId, moduleName }
5
5
  * Returns: { collections } - extracted AST data for GraphBuilder
6
+ *
7
+ * Uses ScopeTracker for semantic ID generation (REG-133).
8
+ * IDs are stable and don't change when unrelated code is added/removed.
6
9
  */
7
- /**
8
- * Import node structure
9
- */
10
- interface ImportNode {
11
- id: string;
12
- type: 'IMPORT';
13
- name: string;
14
- importedName: string;
15
- source: string;
16
- file: string;
17
- line: number;
18
- }
19
- /**
20
- * Export node structure
21
- */
22
- interface ExportNode {
23
- id: string;
24
- type: 'EXPORT';
25
- name: string;
26
- exportType?: string;
27
- localName?: string;
28
- isDefault?: boolean;
29
- file: string;
30
- line: number;
31
- }
10
+ import { type ClassNodeRecord } from './nodes/ClassNode.js';
11
+ import { type ImportNodeRecord } from './nodes/ImportNode.js';
12
+ import { type ExportNodeRecord } from './nodes/ExportNode.js';
32
13
  /**
33
14
  * Variable declaration node
34
15
  */
@@ -56,7 +37,6 @@ interface ClassInstantiationInfo {
56
37
  */
57
38
  interface FunctionNode {
58
39
  id: string;
59
- stableId: string;
60
40
  type: 'FUNCTION' | 'METHOD';
61
41
  name: string;
62
42
  file: string;
@@ -84,15 +64,10 @@ interface ParameterNode {
84
64
  line: number;
85
65
  }
86
66
  /**
87
- * Class declaration node
67
+ * Class declaration node (matches ClassNodeRecord from ClassNode factory)
68
+ * Workers use legacy line-based IDs
88
69
  */
89
- interface ClassDeclarationNode {
90
- id: string;
91
- type: 'CLASS';
92
- name: string;
93
- file: string;
94
- line: number;
95
- superClass: string | null;
70
+ interface ClassDeclarationNode extends ClassNodeRecord {
96
71
  }
97
72
  /**
98
73
  * Call site node
@@ -123,8 +98,8 @@ export interface ASTCollections {
123
98
  classDeclarations: ClassDeclarationNode[];
124
99
  methodCallbacks: unknown[];
125
100
  callArguments: unknown[];
126
- imports: ImportNode[];
127
- exports: ExportNode[];
101
+ imports: ImportNodeRecord[];
102
+ exports: ExportNodeRecord[];
128
103
  httpRequests: unknown[];
129
104
  literals: unknown[];
130
105
  variableAssignments: unknown[];
@@ -1 +1 @@
1
- {"version":3,"file":"ASTWorker.d.ts","sourceRoot":"","sources":["../../src/core/ASTWorker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH;;GAEG;AACH,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,UAAU,uBAAuB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,EAAE,MAAM,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e;CAErD;AAED;;GAEG;AACH,UAAU,YAAY;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,UAAU,EAAE,aAAa,EAAE,CAAC;IAC5B,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,oBAAoB,EAAE,uBAAuB,EAAE,CAAC;IAChD,SAAS,EAAE,YAAY,EAAE,CAAC;IAC1B,WAAW,EAAE,YAAY,EAAE,CAAC;IAC5B,cAAc,EAAE,OAAO,EAAE,CAAC;IAC1B,mBAAmB,EAAE,sBAAsB,EAAE,CAAC;IAC9C,iBAAiB,EAAE,oBAAoB,EAAE,CAAC;IAC1C,eAAe,EAAE,OAAO,EAAE,CAAC;IAC3B,aAAa,EAAE,OAAO,EAAE,CAAC;IACzB,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,YAAY,EAAE,OAAO,EAAE,CAAC;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,mBAAmB,EAAE,OAAO,EAAE,CAAC;CAChC"}
@@ -3,17 +3,30 @@
3
3
  *
4
4
  * Receives: { filePath, moduleId, moduleName }
5
5
  * Returns: { collections } - extracted AST data for GraphBuilder
6
+ *
7
+ * Uses ScopeTracker for semantic ID generation (REG-133).
8
+ * IDs are stable and don't change when unrelated code is added/removed.
6
9
  */
7
10
  import { parentPort } from 'worker_threads';
8
11
  import { readFileSync } from 'fs';
12
+ import { basename } from 'path';
9
13
  import { parse } from '@babel/parser';
10
14
  import traverseModule from '@babel/traverse';
15
+ import { ClassNode } from './nodes/ClassNode.js';
16
+ import { ImportNode } from './nodes/ImportNode.js';
17
+ import { ExportNode } from './nodes/ExportNode.js';
18
+ import { ScopeTracker } from './ScopeTracker.js';
19
+ import { computeSemanticId } from './SemanticId.js';
20
+ import { getLine, getColumn } from '../plugins/analysis/ast/utils/location.js';
11
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
22
  const traverse = traverseModule.default || traverseModule;
13
23
  // Simplified visitors for extraction (no graph access needed)
14
24
  import { ExpressionEvaluator } from '../plugins/analysis/ast/ExpressionEvaluator.js';
15
25
  /**
16
26
  * Parse a single module and extract all collections
27
+ *
28
+ * Uses ScopeTracker for semantic ID generation - IDs are stable
29
+ * and don't change when unrelated code is added/removed.
17
30
  */
18
31
  function parseModule(filePath, moduleId, moduleName) {
19
32
  const code = readFileSync(filePath, 'utf-8');
@@ -21,6 +34,9 @@ function parseModule(filePath, moduleId, moduleName) {
21
34
  sourceType: 'module',
22
35
  plugins: ['jsx', 'typescript']
23
36
  });
37
+ // Create ScopeTracker for semantic ID generation
38
+ // Use basename for shorter, more readable IDs
39
+ const scopeTracker = new ScopeTracker(basename(filePath));
24
40
  // Collections to extract
25
41
  const collections = {
26
42
  functions: [],
@@ -40,17 +56,7 @@ function parseModule(filePath, moduleId, moduleName) {
40
56
  literals: [],
41
57
  variableAssignments: []
42
58
  };
43
- // Counters for unique IDs
44
- const counters = {
45
- ifScope: 0,
46
- scope: 0,
47
- varDecl: 0,
48
- callSite: 0,
49
- function: 0,
50
- httpRequest: 0,
51
- literal: 0
52
- };
53
- // Processed nodes tracking
59
+ // Processed nodes tracking (still needed for deduplication)
54
60
  const processed = {
55
61
  callSites: new Set(),
56
62
  methodCalls: new Set(),
@@ -78,54 +84,35 @@ function parseModule(filePath, moduleId, moduleName) {
78
84
  importedName = spec.imported?.name || spec.local.name;
79
85
  localName = spec.local.name;
80
86
  }
81
- collections.imports.push({
82
- id: `IMPORT#${localName}#${filePath}#${node.loc.start.line}`,
83
- type: 'IMPORT',
84
- name: localName,
85
- importedName,
86
- source,
87
- file: filePath,
88
- line: node.loc.start.line
89
- });
87
+ // Babel AST guarantees node.loc exists with locations: true option
88
+ const importNode = ImportNode.create(localName, // name
89
+ filePath, // file
90
+ getLine(node), // line (non-null - Babel guarantees location)
91
+ 0, // column (not available in this worker)
92
+ source, // source
93
+ { imported: importedName, local: localName });
94
+ collections.imports.push(importNode);
90
95
  });
91
96
  }
92
97
  });
93
- // Extract exports
98
+ // Extract exports using semantic IDs (via createWithContext)
94
99
  traverse(ast, {
95
100
  ExportNamedDeclaration(path) {
96
101
  const node = path.node;
97
102
  if (node.declaration) {
98
103
  if (node.declaration.type === 'FunctionDeclaration' && node.declaration.id) {
99
- collections.exports.push({
100
- id: `EXPORT#${node.declaration.id.name}#${filePath}#${node.loc.start.line}`,
101
- type: 'EXPORT',
102
- name: node.declaration.id.name,
103
- exportType: 'function',
104
- file: filePath,
105
- line: node.loc.start.line
106
- });
104
+ const exportNode = ExportNode.createWithContext(node.declaration.id.name, scopeTracker.getContext(), { line: getLine(node), column: 0 }, { exportType: 'named' });
105
+ collections.exports.push(exportNode);
107
106
  }
108
107
  else if (node.declaration.type === 'ClassDeclaration' && node.declaration.id) {
109
- collections.exports.push({
110
- id: `EXPORT#${node.declaration.id.name}#${filePath}#${node.loc.start.line}`,
111
- type: 'EXPORT',
112
- name: node.declaration.id.name,
113
- exportType: 'class',
114
- file: filePath,
115
- line: node.loc.start.line
116
- });
108
+ const exportNode = ExportNode.createWithContext(node.declaration.id.name, scopeTracker.getContext(), { line: getLine(node), column: 0 }, { exportType: 'named' });
109
+ collections.exports.push(exportNode);
117
110
  }
118
111
  else if (node.declaration.type === 'VariableDeclaration') {
119
112
  node.declaration.declarations.forEach(decl => {
120
113
  if (decl.id.type === 'Identifier') {
121
- collections.exports.push({
122
- id: `EXPORT#${decl.id.name}#${filePath}#${node.loc.start.line}`,
123
- type: 'EXPORT',
124
- name: decl.id.name,
125
- exportType: 'variable',
126
- file: filePath,
127
- line: node.loc.start.line
128
- });
114
+ const exportNode = ExportNode.createWithContext(decl.id.name, scopeTracker.getContext(), { line: getLine(node), column: 0 }, { exportType: 'named' });
115
+ collections.exports.push(exportNode);
129
116
  }
130
117
  });
131
118
  }
@@ -135,38 +122,32 @@ function parseModule(filePath, moduleId, moduleName) {
135
122
  if (spec.type !== 'ExportSpecifier')
136
123
  return;
137
124
  const exportedName = spec.exported.type === 'Identifier' ? spec.exported.name : spec.exported.value;
138
- collections.exports.push({
139
- id: `EXPORT#${exportedName}#${filePath}#${node.loc.start.line}`,
140
- type: 'EXPORT',
141
- name: exportedName,
142
- localName: spec.local.name,
143
- file: filePath,
144
- line: node.loc.start.line
125
+ const exportNode = ExportNode.createWithContext(exportedName, scopeTracker.getContext(), { line: getLine(node), column: 0 }, {
126
+ local: spec.local.name,
127
+ exportType: 'named'
145
128
  });
129
+ collections.exports.push(exportNode);
146
130
  });
147
131
  }
148
132
  },
149
133
  ExportDefaultDeclaration(path) {
150
134
  const node = path.node;
151
- let name = 'default';
135
+ let localName = 'default';
152
136
  if (node.declaration.type === 'Identifier') {
153
- name = node.declaration.name;
137
+ localName = node.declaration.name;
154
138
  }
155
139
  else if ('id' in node.declaration && node.declaration.id) {
156
- name = node.declaration.id.name;
140
+ localName = node.declaration.id.name;
157
141
  }
158
- collections.exports.push({
159
- id: `EXPORT#default#${filePath}#${node.loc.start.line}`,
160
- type: 'EXPORT',
161
- name: 'default',
162
- localName: name,
163
- isDefault: true,
164
- file: filePath,
165
- line: node.loc.start.line
142
+ const exportNode = ExportNode.createWithContext('default', scopeTracker.getContext(), { line: getLine(node), column: 0 }, {
143
+ local: localName,
144
+ default: true,
145
+ exportType: 'default'
166
146
  });
147
+ collections.exports.push(exportNode);
167
148
  }
168
149
  });
169
- // Extract top-level variables
150
+ // Extract top-level variables using semantic IDs
170
151
  traverse(ast, {
171
152
  VariableDeclaration(path) {
172
153
  if (path.getFunctionParent())
@@ -176,15 +157,14 @@ function parseModule(filePath, moduleId, moduleName) {
176
157
  node.declarations.forEach(decl => {
177
158
  if (decl.id.type === 'Identifier') {
178
159
  const varName = decl.id.name;
179
- const line = decl.id.loc.start.line;
180
- const column = decl.id.loc.start.column;
160
+ const line = getLine(decl.id);
181
161
  const literalValue = ExpressionEvaluator.extractLiteralValue(decl.init);
182
162
  const isLiteral = literalValue !== null;
183
163
  const isNewExpr = decl.init?.type === 'NewExpression';
184
164
  const shouldBeConstant = isConst && (isLiteral || isNewExpr);
185
- const varId = shouldBeConstant
186
- ? `CONSTANT#${varName}#${filePath}#${line}:${column}:${counters.varDecl++}`
187
- : `VARIABLE#${varName}#${filePath}#${line}:${column}:${counters.varDecl++}`;
165
+ // Generate semantic ID using ScopeTracker
166
+ const nodeType = shouldBeConstant ? 'CONSTANT' : 'VARIABLE';
167
+ const varId = computeSemanticId(nodeType, varName, scopeTracker.getContext());
188
168
  collections.variableDeclarations.push({
189
169
  id: varId,
190
170
  type: shouldBeConstant ? 'CONSTANT' : 'VARIABLE',
@@ -207,7 +187,7 @@ function parseModule(filePath, moduleId, moduleName) {
207
187
  });
208
188
  }
209
189
  });
210
- // Extract functions and classes
190
+ // Extract functions and classes using semantic IDs
211
191
  traverse(ast, {
212
192
  FunctionDeclaration(path) {
213
193
  if (path.getFunctionParent())
@@ -216,33 +196,38 @@ function parseModule(filePath, moduleId, moduleName) {
216
196
  if (!node.id)
217
197
  return;
218
198
  const funcName = node.id.name;
219
- const functionId = `FUNCTION#${funcName}#${filePath}#${node.loc.start.line}:${node.loc.start.column}`;
199
+ // Generate semantic ID using ScopeTracker
200
+ const functionId = computeSemanticId('FUNCTION', funcName, scopeTracker.getContext());
220
201
  collections.functions.push({
221
202
  id: functionId,
222
- stableId: functionId,
223
203
  type: 'FUNCTION',
224
204
  name: funcName,
225
205
  file: filePath,
226
- line: node.loc.start.line,
227
- column: node.loc.start.column,
206
+ line: getLine(node),
207
+ column: getColumn(node),
228
208
  async: node.async || false,
229
209
  generator: node.generator || false,
230
210
  exported: path.parent?.type === 'ExportNamedDeclaration' || path.parent?.type === 'ExportDefaultDeclaration'
231
211
  });
232
- // Extract parameters
212
+ // Enter function scope for parameter extraction
213
+ scopeTracker.enterScope(funcName, 'FUNCTION');
214
+ // Extract parameters with semantic IDs
233
215
  node.params.forEach((param, index) => {
234
216
  if (param.type === 'Identifier') {
217
+ const paramId = computeSemanticId('PARAMETER', param.name, scopeTracker.getContext(), { discriminator: index });
235
218
  collections.parameters.push({
236
- id: `PARAMETER#${param.name}#${functionId}#${index}`,
219
+ id: paramId,
237
220
  type: 'PARAMETER',
238
221
  name: param.name,
239
222
  index,
240
223
  functionId,
241
224
  file: filePath,
242
- line: param.loc.start.line
225
+ line: getLine(param)
243
226
  });
244
227
  }
245
228
  });
229
+ // Exit function scope
230
+ scopeTracker.exitScope();
246
231
  },
247
232
  ClassDeclaration(path) {
248
233
  if (path.getFunctionParent())
@@ -251,30 +236,30 @@ function parseModule(filePath, moduleId, moduleName) {
251
236
  if (!node.id)
252
237
  return;
253
238
  const className = node.id.name;
254
- const classId = `CLASS#${className}#${filePath}#${node.loc.start.line}`;
255
- collections.classDeclarations.push({
256
- id: classId,
257
- type: 'CLASS',
258
- name: className,
259
- file: filePath,
260
- line: node.loc.start.line,
261
- superClass: node.superClass?.name || null
262
- });
263
- // Extract methods
239
+ // Extract superClass name
240
+ const superClassName = node.superClass && node.superClass.type === 'Identifier'
241
+ ? node.superClass.name
242
+ : null;
243
+ // Create CLASS node using ClassNode.createWithContext() for semantic IDs
244
+ const classRecord = ClassNode.createWithContext(className, scopeTracker.getContext(), { line: getLine(node), column: getColumn(node) }, { superClass: superClassName || undefined });
245
+ collections.classDeclarations.push(classRecord);
246
+ // Enter class scope for method extraction
247
+ scopeTracker.enterScope(className, 'CLASS');
248
+ // Extract methods with semantic IDs (including class scope)
264
249
  node.body.body.forEach(member => {
265
250
  if (member.type === 'ClassMethod' && member.key.type === 'Identifier') {
266
251
  const methodName = member.key.name;
267
- const methodId = `METHOD#${className}.${methodName}#${filePath}#${member.loc.start.line}`;
252
+ // Method ID includes class scope: file->ClassName->FUNCTION->methodName
253
+ const methodId = computeSemanticId('FUNCTION', methodName, scopeTracker.getContext());
268
254
  collections.functions.push({
269
255
  id: methodId,
270
- stableId: methodId,
271
256
  type: 'METHOD',
272
257
  name: methodName,
273
258
  className,
274
- classId,
259
+ classId: classRecord.id,
275
260
  file: filePath,
276
- line: member.loc.start.line,
277
- column: member.loc.start.column,
261
+ line: getLine(member),
262
+ column: getColumn(member),
278
263
  async: member.async || false,
279
264
  isClassMethod: true,
280
265
  isConstructor: member.kind === 'constructor',
@@ -282,9 +267,11 @@ function parseModule(filePath, moduleId, moduleName) {
282
267
  });
283
268
  }
284
269
  });
270
+ // Exit class scope
271
+ scopeTracker.exitScope();
285
272
  }
286
273
  });
287
- // Extract call expressions at module level
274
+ // Extract call expressions at module level using semantic IDs with discriminators
288
275
  traverse(ast, {
289
276
  CallExpression(path) {
290
277
  if (path.getFunctionParent())
@@ -295,14 +282,18 @@ function parseModule(filePath, moduleId, moduleName) {
295
282
  if (processed.callSites.has(nodeKey))
296
283
  return;
297
284
  processed.callSites.add(nodeKey);
285
+ // Get discriminator for same-named calls in current scope
286
+ const calleeName = node.callee.name;
287
+ const discriminator = scopeTracker.getItemCounter(`CALL:${calleeName}`);
288
+ const callId = computeSemanticId('CALL', calleeName, scopeTracker.getContext(), { discriminator });
298
289
  collections.callSites.push({
299
- id: `CALL#${node.callee.name}#${filePath}#${node.loc.start.line}:${node.loc.start.column}:${counters.callSite++}`,
290
+ id: callId,
300
291
  type: 'CALL',
301
- name: node.callee.name,
292
+ name: calleeName,
302
293
  file: filePath,
303
- line: node.loc.start.line,
294
+ line: getLine(node),
304
295
  parentScopeId: moduleId,
305
- targetFunctionName: node.callee.name
296
+ targetFunctionName: calleeName
306
297
  });
307
298
  }
308
299
  else if (node.callee.type === 'MemberExpression') {
@@ -315,14 +306,17 @@ function parseModule(filePath, moduleId, moduleName) {
315
306
  const objectName = obj.type === 'Identifier' ? obj.name : 'this';
316
307
  const methodName = prop.name;
317
308
  const fullName = `${objectName}.${methodName}`;
309
+ // Get discriminator for same-named method calls
310
+ const discriminator = scopeTracker.getItemCounter(`CALL:${fullName}`);
311
+ const callId = computeSemanticId('CALL', fullName, scopeTracker.getContext(), { discriminator });
318
312
  collections.methodCalls.push({
319
- id: `CALL#${fullName}#${filePath}#${node.loc.start.line}:${node.loc.start.column}:${counters.callSite++}`,
313
+ id: callId,
320
314
  type: 'CALL',
321
315
  name: fullName,
322
316
  object: objectName,
323
317
  method: methodName,
324
318
  file: filePath,
325
- line: node.loc.start.line,
319
+ line: getLine(node),
326
320
  parentScopeId: moduleId
327
321
  });
328
322
  }