@codeyam/codeyam-cli 0.1.0-staging.6e699e5 → 0.1.0-staging.73a4bf4

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 (563) hide show
  1. package/analyzer-template/.build-info.json +7 -7
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/package.json +8 -8
  4. package/analyzer-template/packages/ai/index.ts +11 -2
  5. package/analyzer-template/packages/ai/package.json +2 -2
  6. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +100 -18
  7. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +67 -9
  8. package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +41 -17
  9. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  10. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +409 -50
  11. package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
  12. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +21 -6
  13. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +1007 -249
  14. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
  15. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +16 -3
  16. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +6 -4
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +54 -3
  18. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +60 -15
  19. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
  20. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +140 -14
  21. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +179 -0
  22. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.ts +40 -30
  23. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +393 -97
  24. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +33 -15
  25. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
  26. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +315 -6
  27. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +9 -5
  28. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +49 -5
  29. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
  30. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +649 -142
  31. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +1 -1
  32. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
  33. package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
  34. package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
  35. package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
  36. package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
  37. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
  38. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +25 -13
  39. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +4 -3
  40. package/analyzer-template/packages/ai/src/lib/worker/analyzeScopeWorker.ts +114 -2
  41. package/analyzer-template/packages/analyze/index.ts +2 -0
  42. package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +65 -59
  43. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +113 -26
  44. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
  45. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
  46. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
  47. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
  48. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
  49. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
  50. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +89 -9
  51. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +19 -4
  52. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +6 -0
  53. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
  54. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +0 -3
  55. package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
  56. package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
  57. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
  58. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +61 -13
  59. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +87 -25
  60. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +229 -19
  61. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +117 -9
  62. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +571 -74
  63. package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
  64. package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
  65. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  66. package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
  67. package/analyzer-template/packages/aws/package.json +1 -1
  68. package/analyzer-template/packages/database/package.json +1 -1
  69. package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
  70. package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
  71. package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
  72. package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
  73. package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
  74. package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
  75. package/analyzer-template/packages/database/src/lib/kysely/db.ts +14 -1
  76. package/analyzer-template/packages/database/src/lib/kysely/tables/commitsTable.ts +6 -0
  77. package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +1 -1
  78. package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
  79. package/analyzer-template/packages/database/src/lib/loadAnalyses.ts +58 -1
  80. package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +13 -0
  81. package/analyzer-template/packages/database/src/lib/loadBranch.ts +16 -1
  82. package/analyzer-template/packages/database/src/lib/loadCommit.ts +11 -0
  83. package/analyzer-template/packages/database/src/lib/loadCommits.ts +28 -0
  84. package/analyzer-template/packages/database/src/lib/loadEntities.ts +26 -3
  85. package/analyzer-template/packages/database/src/lib/loadEntityBranches.ts +12 -0
  86. package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
  87. package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
  88. package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
  89. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +7 -14
  90. package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
  91. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
  92. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
  93. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
  94. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
  95. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
  96. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
  97. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
  98. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
  99. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
  100. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
  101. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
  102. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
  103. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  104. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  105. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +11 -1
  106. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  107. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts +1 -0
  108. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts.map +1 -1
  109. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js +3 -0
  110. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  111. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +1 -1
  112. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
  113. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
  114. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  115. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  116. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts +2 -0
  117. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts.map +1 -1
  118. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js +45 -2
  119. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js.map +1 -1
  120. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
  121. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +8 -0
  122. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
  123. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js +11 -1
  124. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js.map +1 -1
  125. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.d.ts.map +1 -1
  126. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js +7 -0
  127. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js.map +1 -1
  128. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts +3 -1
  129. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  130. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +22 -1
  131. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  132. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts +3 -1
  133. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  134. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +23 -4
  135. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  136. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.d.ts.map +1 -1
  137. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js +9 -0
  138. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js.map +1 -1
  139. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
  140. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
  141. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
  142. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
  143. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
  144. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
  145. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts +2 -2
  146. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  147. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +5 -4
  148. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  149. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts +2 -0
  150. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts.map +1 -1
  151. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  152. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  153. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  154. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  155. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  156. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  157. package/analyzer-template/packages/github/package.json +1 -1
  158. package/analyzer-template/packages/types/src/types/Commit.ts +2 -0
  159. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +7 -0
  160. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +6 -5
  161. package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
  162. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts +2 -0
  163. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts.map +1 -1
  164. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  165. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  166. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  167. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  168. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  169. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  170. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
  171. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +93 -2
  172. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  173. package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +108 -2
  174. package/analyzer-template/playwright/capture.ts +20 -8
  175. package/analyzer-template/playwright/captureStatic.ts +1 -1
  176. package/analyzer-template/project/analyzeBaselineCommit.ts +5 -0
  177. package/analyzer-template/project/analyzeRegularCommit.ts +5 -0
  178. package/analyzer-template/project/captureLibraryFunctionDirect.ts +29 -26
  179. package/analyzer-template/project/constructMockCode.ts +92 -12
  180. package/analyzer-template/project/createEntitiesAndSortFiles.ts +83 -0
  181. package/analyzer-template/project/loadReadyToBeCaptured.ts +65 -41
  182. package/analyzer-template/project/orchestrateCapture/AwsCaptureTaskRunner.ts +12 -4
  183. package/analyzer-template/project/orchestrateCapture/SequentialCaptureTaskRunner.ts +11 -6
  184. package/analyzer-template/project/orchestrateCapture/taskRunner.ts +4 -2
  185. package/analyzer-template/project/orchestrateCapture.ts +45 -6
  186. package/analyzer-template/project/start.ts +35 -11
  187. package/analyzer-template/project/writeMockDataTsx.ts +181 -8
  188. package/analyzer-template/project/writeScenarioComponents.ts +103 -12
  189. package/analyzer-template/project/writeSimpleRoot.ts +21 -11
  190. package/analyzer-template/scripts/comboWorkerLoop.cjs +98 -50
  191. package/background/src/lib/local/createLocalAnalyzer.js +1 -1
  192. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  193. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js +5 -0
  194. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js.map +1 -1
  195. package/background/src/lib/virtualized/project/analyzeRegularCommit.js +5 -0
  196. package/background/src/lib/virtualized/project/analyzeRegularCommit.js.map +1 -1
  197. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js +3 -3
  198. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js.map +1 -1
  199. package/background/src/lib/virtualized/project/constructMockCode.js +77 -6
  200. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  201. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js +73 -1
  202. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js.map +1 -1
  203. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js +19 -8
  204. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js.map +1 -1
  205. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js +2 -2
  206. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js.map +1 -1
  207. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js +4 -4
  208. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js.map +1 -1
  209. package/background/src/lib/virtualized/project/orchestrateCapture.js +38 -6
  210. package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
  211. package/background/src/lib/virtualized/project/start.js +32 -11
  212. package/background/src/lib/virtualized/project/start.js.map +1 -1
  213. package/background/src/lib/virtualized/project/writeMockDataTsx.js +162 -4
  214. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  215. package/background/src/lib/virtualized/project/writeScenarioComponents.js +85 -15
  216. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  217. package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
  218. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  219. package/codeyam-cli/scripts/apply-setup.js +180 -0
  220. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  221. package/codeyam-cli/src/cli.js +4 -0
  222. package/codeyam-cli/src/cli.js.map +1 -1
  223. package/codeyam-cli/src/codeyam-cli.js +18 -2
  224. package/codeyam-cli/src/codeyam-cli.js.map +1 -1
  225. package/codeyam-cli/src/commands/analyze.js +4 -2
  226. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  227. package/codeyam-cli/src/commands/baseline.js +2 -0
  228. package/codeyam-cli/src/commands/baseline.js.map +1 -1
  229. package/codeyam-cli/src/commands/debug.js +9 -5
  230. package/codeyam-cli/src/commands/debug.js.map +1 -1
  231. package/codeyam-cli/src/commands/default.js +31 -20
  232. package/codeyam-cli/src/commands/default.js.map +1 -1
  233. package/codeyam-cli/src/commands/detect-universal-mocks.js +2 -0
  234. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +1 -1
  235. package/codeyam-cli/src/commands/init.js +49 -257
  236. package/codeyam-cli/src/commands/init.js.map +1 -1
  237. package/codeyam-cli/src/commands/memory.js +264 -0
  238. package/codeyam-cli/src/commands/memory.js.map +1 -0
  239. package/codeyam-cli/src/commands/recapture.js +2 -0
  240. package/codeyam-cli/src/commands/recapture.js.map +1 -1
  241. package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
  242. package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
  243. package/codeyam-cli/src/commands/setup-simulations.js +284 -0
  244. package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
  245. package/codeyam-cli/src/commands/test-startup.js +2 -0
  246. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  247. package/codeyam-cli/src/commands/verify.js +14 -2
  248. package/codeyam-cli/src/commands/verify.js.map +1 -1
  249. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +128 -86
  250. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  251. package/codeyam-cli/src/utils/analysisRunner.js +21 -2
  252. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  253. package/codeyam-cli/src/utils/analyzer.js +7 -0
  254. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  255. package/codeyam-cli/src/utils/backgroundServer.js +107 -19
  256. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  257. package/codeyam-cli/src/utils/generateReport.js +2 -2
  258. package/codeyam-cli/src/utils/install-skills.js +72 -47
  259. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  260. package/codeyam-cli/src/utils/labsAutoCheck.js +19 -0
  261. package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
  262. package/codeyam-cli/src/utils/progress.js +7 -0
  263. package/codeyam-cli/src/utils/progress.js.map +1 -1
  264. package/codeyam-cli/src/utils/queue/job.js +4 -0
  265. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  266. package/codeyam-cli/src/utils/requireSimulations.js +10 -0
  267. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
  268. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  269. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  270. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +230 -0
  271. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  272. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  273. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  274. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  275. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  276. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  277. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  278. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  279. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  280. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +75 -0
  281. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  282. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +378 -0
  283. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  284. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +115 -0
  285. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  286. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  287. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  288. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  289. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  290. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
  291. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  292. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  293. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  294. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
  295. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  296. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  297. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  298. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  299. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  300. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  301. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  302. package/codeyam-cli/src/utils/rules/index.js +6 -0
  303. package/codeyam-cli/src/utils/rules/index.js.map +1 -0
  304. package/codeyam-cli/src/utils/rules/parser.js +83 -0
  305. package/codeyam-cli/src/utils/rules/parser.js.map +1 -0
  306. package/codeyam-cli/src/utils/rules/pathMatcher.js +18 -0
  307. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -0
  308. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  309. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  310. package/codeyam-cli/src/utils/rules/staleness.js +137 -0
  311. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -0
  312. package/codeyam-cli/src/utils/serverState.js +37 -10
  313. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  314. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +21 -44
  315. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  316. package/codeyam-cli/src/webserver/app/lib/database.js +21 -6
  317. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  318. package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
  319. package/codeyam-cli/src/webserver/backgroundServer.js +50 -0
  320. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  321. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-D9i_zSlY.js +1 -0
  322. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-BLlhOa3C.js +11 -0
  323. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-De5b5pC7.js} +1 -1
  324. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-CzdG5I7z.js} +1 -1
  325. package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-C8lyxW9k.js → InlineSpinner-Bclf8Hka.js} +1 -1
  326. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-Ce-byqKl.js} +2 -2
  327. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-DEMHrl7v.js} +1 -1
  328. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-B1LNGboS.js} +1 -1
  329. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-B0Ll1DjK.js} +1 -1
  330. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-D4TZhLuw.js → ReportIssueModal-CVOvmCKb.js} +3 -13
  331. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-L0DWHa_L.js} +1 -1
  332. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DEx02QDa.js → ScenarioViewer-D54Mmpwi.js} +3 -3
  333. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-C7PFQfXy.js} +1 -1
  334. package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-CKTtYlBU.js} +1 -1
  335. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-DoLIqZX2.js → activity.(_tab)-CdziRIWU.js} +6 -16
  336. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-CPXtdaWm.js +17 -0
  337. package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
  338. package/codeyam-cli/src/webserver/build/client/assets/api.memory-profile-l0sNRNKZ.js +1 -0
  339. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  340. package/codeyam-cli/src/webserver/build/client/assets/book-open-Ch8b7GyQ.js +6 -0
  341. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-vJHJExlT.js} +1 -1
  342. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-BEyX4X6_.js} +12 -12
  343. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-rwynPZTW.js} +1 -1
  344. package/codeyam-cli/src/webserver/build/client/assets/copy-BBSpeBYf.js +11 -0
  345. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-DHVDauuc.js} +1 -1
  346. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-B9_ZqelV.js +1 -0
  347. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-BOPComvD.js +16 -0
  348. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js → entity._sha.scenarios._scenarioId.fullscreen-Cfw__yQa.js} +1 -1
  349. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-D1T4TGjf.js → entity._sha_.create-scenario-BIDUUrI3.js} +1 -1
  350. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-BEqewwtZ.js} +1 -1
  351. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-Dxqz8ygt.js} +1 -1
  352. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-CYnF5KWN.js} +1 -1
  353. package/codeyam-cli/src/webserver/build/client/assets/files-B_dAq2PQ.js +1 -0
  354. package/codeyam-cli/src/webserver/build/client/assets/{git-B4RJRvYB.js → git-BHPqH3Ch.js} +8 -8
  355. package/codeyam-cli/src/webserver/build/client/assets/globals-BJGhRykz.css +1 -0
  356. package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-DgAAopZk.js} +1 -1
  357. package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-viijWaN6.js} +1 -1
  358. package/codeyam-cli/src/webserver/build/client/assets/labs-ChoAe3xq.js +1 -0
  359. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-LGi2eKI5.js} +1 -1
  360. package/codeyam-cli/src/webserver/build/client/assets/manifest-87493a32.js +1 -0
  361. package/codeyam-cli/src/webserver/build/client/assets/memory-D9eA6kTo.js +78 -0
  362. package/codeyam-cli/src/webserver/build/client/assets/pause-DxJFmMsK.js +11 -0
  363. package/codeyam-cli/src/webserver/build/client/assets/root-C3r0p_7H.js +62 -0
  364. package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-Cu3QE9E5.js} +1 -1
  365. package/codeyam-cli/src/webserver/build/client/assets/settings-KH9TdArD.js +1 -0
  366. package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-D9Fkx0-d.js} +1 -1
  367. package/codeyam-cli/src/webserver/build/client/assets/terminal-dAhIBEcd.js +11 -0
  368. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-C4CYTEeP.js} +1 -1
  369. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-CLPnITMB.js} +1 -1
  370. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-aSv48UbS.js → useLastLogLine-DmGI38Et.js} +1 -1
  371. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-BK0S88PB.js} +1 -1
  372. package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-CJ-JqR0l.js} +1 -1
  373. package/codeyam-cli/src/webserver/build/server/assets/index-CkkmL6r5.js +1 -0
  374. package/codeyam-cli/src/webserver/build/server/assets/server-build-iBGjHYtO.js +259 -0
  375. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  376. package/codeyam-cli/src/webserver/build-info.json +5 -5
  377. package/codeyam-cli/templates/{codeyam:debug.md → codeyam-debug.md} +1 -1
  378. package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
  379. package/codeyam-cli/templates/{codeyam-power-rules-hook.sh → codeyam-memory-hook.sh} +22 -23
  380. package/codeyam-cli/templates/codeyam-memory.md +396 -0
  381. package/codeyam-cli/templates/codeyam-new-rule.md +13 -0
  382. package/codeyam-cli/templates/{codeyam:setup.md → codeyam-setup.md} +13 -1
  383. package/codeyam-cli/templates/{codeyam:sim.md → codeyam-sim.md} +1 -1
  384. package/codeyam-cli/templates/{codeyam:test.md → codeyam-test.md} +1 -1
  385. package/codeyam-cli/templates/{codeyam:verify.md → codeyam-verify.md} +1 -1
  386. package/codeyam-cli/templates/rule-notification-hook.py +56 -0
  387. package/codeyam-cli/templates/rule-reflection-hook.py +627 -0
  388. package/codeyam-cli/templates/rules-instructions.md +132 -0
  389. package/package.json +15 -13
  390. package/packages/ai/index.js +3 -2
  391. package/packages/ai/index.js.map +1 -1
  392. package/packages/ai/src/lib/analyzeScope.js +82 -13
  393. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  394. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +54 -8
  395. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  396. package/packages/ai/src/lib/astScopes/methodSemantics.js +41 -17
  397. package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
  398. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  399. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  400. package/packages/ai/src/lib/astScopes/processExpression.js +317 -44
  401. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  402. package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
  403. package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
  404. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +776 -171
  405. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  406. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
  407. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  408. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
  409. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
  410. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
  411. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
  412. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +52 -3
  413. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  414. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +55 -11
  415. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  416. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  417. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  418. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +122 -12
  419. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  420. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
  421. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
  422. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
  423. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
  424. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +333 -86
  425. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  426. package/packages/ai/src/lib/dataStructureChunking.js +26 -11
  427. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  428. package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
  429. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  430. package/packages/ai/src/lib/generateEntityScenarioData.js +227 -4
  431. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  432. package/packages/ai/src/lib/generateEntityScenarios.js +7 -1
  433. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  434. package/packages/ai/src/lib/generateExecutionFlows.js +26 -4
  435. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  436. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +447 -80
  437. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  438. package/packages/ai/src/lib/isolateScopes.js +39 -3
  439. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  440. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
  441. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
  442. package/packages/ai/src/lib/mergeStatements.js +70 -51
  443. package/packages/ai/src/lib/mergeStatements.js.map +1 -1
  444. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
  445. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
  446. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +10 -4
  447. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
  448. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
  449. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  450. package/packages/ai/src/lib/resolvePathToControllable.js +24 -14
  451. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
  452. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  453. package/packages/ai/src/lib/worker/analyzeScopeWorker.js +94 -1
  454. package/packages/ai/src/lib/worker/analyzeScopeWorker.js.map +1 -1
  455. package/packages/analyze/index.js +1 -0
  456. package/packages/analyze/index.js.map +1 -1
  457. package/packages/analyze/src/lib/FileAnalyzer.js +60 -36
  458. package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
  459. package/packages/analyze/src/lib/ProjectAnalyzer.js +96 -26
  460. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  461. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
  462. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
  463. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
  464. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
  465. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
  466. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
  467. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
  468. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
  469. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
  470. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
  471. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
  472. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
  473. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +65 -7
  474. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  475. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +17 -4
  476. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  477. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +5 -0
  478. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  479. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
  480. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  481. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +0 -3
  482. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  483. package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
  484. package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
  485. package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
  486. package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
  487. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
  488. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  489. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +56 -10
  490. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  491. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +75 -21
  492. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  493. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +150 -17
  494. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  495. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +56 -8
  496. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  497. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +478 -54
  498. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  499. package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
  500. package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
  501. package/packages/analyze/src/lib/index.js +1 -0
  502. package/packages/analyze/src/lib/index.js.map +1 -1
  503. package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
  504. package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
  505. package/packages/database/src/lib/analysisBranchToDb.js +1 -1
  506. package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
  507. package/packages/database/src/lib/analysisToDb.js +1 -1
  508. package/packages/database/src/lib/analysisToDb.js.map +1 -1
  509. package/packages/database/src/lib/branchToDb.js +1 -1
  510. package/packages/database/src/lib/branchToDb.js.map +1 -1
  511. package/packages/database/src/lib/commitBranchToDb.js +1 -1
  512. package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
  513. package/packages/database/src/lib/commitToDb.js +1 -1
  514. package/packages/database/src/lib/commitToDb.js.map +1 -1
  515. package/packages/database/src/lib/fileToDb.js +1 -1
  516. package/packages/database/src/lib/fileToDb.js.map +1 -1
  517. package/packages/database/src/lib/kysely/db.js +11 -1
  518. package/packages/database/src/lib/kysely/db.js.map +1 -1
  519. package/packages/database/src/lib/kysely/tables/commitsTable.js +3 -0
  520. package/packages/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  521. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  522. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  523. package/packages/database/src/lib/loadAnalyses.js +45 -2
  524. package/packages/database/src/lib/loadAnalyses.js.map +1 -1
  525. package/packages/database/src/lib/loadAnalysis.js +8 -0
  526. package/packages/database/src/lib/loadAnalysis.js.map +1 -1
  527. package/packages/database/src/lib/loadBranch.js +11 -1
  528. package/packages/database/src/lib/loadBranch.js.map +1 -1
  529. package/packages/database/src/lib/loadCommit.js +7 -0
  530. package/packages/database/src/lib/loadCommit.js.map +1 -1
  531. package/packages/database/src/lib/loadCommits.js +22 -1
  532. package/packages/database/src/lib/loadCommits.js.map +1 -1
  533. package/packages/database/src/lib/loadEntities.js +23 -4
  534. package/packages/database/src/lib/loadEntities.js.map +1 -1
  535. package/packages/database/src/lib/loadEntityBranches.js +9 -0
  536. package/packages/database/src/lib/loadEntityBranches.js.map +1 -1
  537. package/packages/database/src/lib/projectToDb.js +1 -1
  538. package/packages/database/src/lib/projectToDb.js.map +1 -1
  539. package/packages/database/src/lib/saveFiles.js +1 -1
  540. package/packages/database/src/lib/saveFiles.js.map +1 -1
  541. package/packages/database/src/lib/scenarioToDb.js +1 -1
  542. package/packages/database/src/lib/scenarioToDb.js.map +1 -1
  543. package/packages/database/src/lib/updateCommitMetadata.js +5 -4
  544. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  545. package/packages/utils/src/lib/fs/rsyncCopy.js +93 -2
  546. package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  547. package/scripts/finalize-analyzer.cjs +8 -76
  548. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-BXhEawa3.js +0 -1
  549. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BRb-0kQl.js +0 -1
  550. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-C2N4Op8e.js +0 -23
  551. package/codeyam-cli/src/webserver/build/client/assets/files-Cs4MdYtv.js +0 -1
  552. package/codeyam-cli/src/webserver/build/client/assets/git-commit-horizontal-CysbcZxi.js +0 -6
  553. package/codeyam-cli/src/webserver/build/client/assets/globals-DMUaGAqV.css +0 -1
  554. package/codeyam-cli/src/webserver/build/client/assets/manifest-f874c610.js +0 -1
  555. package/codeyam-cli/src/webserver/build/client/assets/root-Bz5TunQg.js +0 -57
  556. package/codeyam-cli/src/webserver/build/client/assets/rules-hEkvVw2-.js +0 -97
  557. package/codeyam-cli/src/webserver/build/client/assets/settings-CS5f3WzT.js +0 -1
  558. package/codeyam-cli/src/webserver/build/server/assets/index-967OuJoF.js +0 -1
  559. package/codeyam-cli/src/webserver/build/server/assets/server-build-DRTmerg9.js +0 -257
  560. package/codeyam-cli/templates/codeyam:diagnose.md +0 -650
  561. package/codeyam-cli/templates/codeyam:new-rule.md +0 -13
  562. package/codeyam-cli/templates/codeyam:power-rules.md +0 -447
  563. /package/codeyam-cli/src/webserver/build/client/assets/{api.rules-l0sNRNKZ.js → api.agent-transcripts-l0sNRNKZ.js} +0 -0
@@ -79,6 +79,8 @@
79
79
  * - `helpers/README.md` - Overview of the helper module architecture
80
80
  */
81
81
  import fillInSchemaGapsAndUnknowns from "./helpers/fillInSchemaGapsAndUnknowns.js";
82
+ import { clearCleanKnownObjectFunctionsCache } from "./helpers/cleanKnownObjectFunctions.js";
83
+ import { clearCleanNonObjectFunctionsCache } from "./helpers/cleanNonObjectFunctions.js";
82
84
  /**
83
85
  * Patterns that indicate recursive type structures in schema paths.
84
86
  * Used by hasExcessivePatternRepetition() to detect exponential path blowup.
@@ -120,6 +122,17 @@ export function resetScopeDataStructureMetrics() {
120
122
  followEquivalenciesEarlyExitPhase1Count = 0;
121
123
  followEquivalenciesWithWorkCount = 0;
122
124
  addEquivalencyCallCount = 0;
125
+ // Clear module-level caches to prevent unbounded memory growth across entities
126
+ const knownObjectCache = clearCleanKnownObjectFunctionsCache();
127
+ const nonObjectCache = clearCleanNonObjectFunctionsCache();
128
+ if (knownObjectCache.count > 0 || nonObjectCache.count > 0) {
129
+ const totalBytes = knownObjectCache.estimatedBytes + nonObjectCache.estimatedBytes;
130
+ console.log('CodeYam: Cleared analysis caches', {
131
+ knownObjectCache: `${knownObjectCache.count} entries, ${(knownObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
132
+ nonObjectCache: `${nonObjectCache.count} entries, ${(nonObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
133
+ totalKB: `${(totalBytes / 1024).toFixed(1)}KB`,
134
+ });
135
+ }
123
136
  }
124
137
  // Performance: Pre-computed Sets for equivalency reason filtering (O(1) vs O(n))
125
138
  const ALLOWED_EQUIVALENCY_REASONS = new Set([
@@ -168,6 +181,7 @@ const SILENTLY_IGNORED_EQUIVALENCY_REASONS = new Set([
168
181
  'transformed non-object function equivalency - implicit parent equivalency - rerouted via useCallback',
169
182
  'transformed non-object function equivalency - Array.from() equivalency',
170
183
  'Spread operator equivalency key update: Explicit array deconstruction equivalency value',
184
+ // 'transformed non-object function equivalency - Explicit array deconstruction equivalency value',
171
185
  ]);
172
186
  export class ScopeDataStructure {
173
187
  // Getter for backward compatibility - returns the tree structure
@@ -462,6 +476,10 @@ export class ScopeDataStructure {
462
476
  }
463
477
  return;
464
478
  }
479
+ // PERF: Early exit for paths with repeated function-call signature patterns
480
+ if (this.hasExcessivePatternRepetition(path)) {
481
+ return;
482
+ }
465
483
  // Update chain metadata for database tracking
466
484
  if (equivalencyValueChain.length > 0) {
467
485
  equivalencyValueChain[equivalencyValueChain.length - 1].addToSchemaId =
@@ -958,6 +976,12 @@ export class ScopeDataStructure {
958
976
  const value1 = scopeNode.schema[schemaPath];
959
977
  const value2 = equivalentScopeNode.schema[equivalentSchemaPath];
960
978
  const bestValue = selectBestValue(value1, value2);
979
+ // PERF: Skip paths with repeated function-call signature patterns
980
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
981
+ if (this.hasExcessivePatternRepetition(schemaPath) ||
982
+ this.hasExcessivePatternRepetition(equivalentSchemaPath)) {
983
+ continue;
984
+ }
961
985
  scopeNode.schema[schemaPath] = bestValue;
962
986
  equivalentScopeNode.schema[equivalentSchemaPath] = bestValue;
963
987
  }
@@ -969,6 +993,10 @@ export class ScopeDataStructure {
969
993
  equivalentPath,
970
994
  ...remainingSchemaPathParts,
971
995
  ]);
996
+ // PERF: Skip paths with repeated function-call signature patterns
997
+ if (this.hasExcessivePatternRepetition(newEquivalentPath)) {
998
+ continue;
999
+ }
972
1000
  equivalentScopeNode.schema[newEquivalentPath] =
973
1001
  scopeNode.schema[schemaPath];
974
1002
  }
@@ -1050,6 +1078,23 @@ export class ScopeDataStructure {
1050
1078
  return true;
1051
1079
  }
1052
1080
  }
1081
+ // Check for repeated function calls that indicate recursive type expansion.
1082
+ // E.g., localeCompare(b[])...localeCompare(b[]) means string.localeCompare
1083
+ // returns a type that again has localeCompare, causing infinite expansion.
1084
+ // We extract all function call patterns like "funcName(args)" and check if
1085
+ // the same normalized call appears more than once.
1086
+ const funcCallPattern = /(?:^|\.)[^.([]+\([^)]*\)/g;
1087
+ const funcCallMatches = path.match(funcCallPattern);
1088
+ if (funcCallMatches && funcCallMatches.length > 1) {
1089
+ const seen = new Set();
1090
+ for (const match of funcCallMatches) {
1091
+ // Strip leading dot and normalize array indices
1092
+ const normalized = match.replace(/^\./, '').replace(/\[\d+\]/g, '[]');
1093
+ if (seen.has(normalized))
1094
+ return true;
1095
+ seen.add(normalized);
1096
+ }
1097
+ }
1053
1098
  // For longer paths, detect any repeated multi-part segments we haven't explicitly listed
1054
1099
  const pathParts = this.splitPath(path);
1055
1100
  if (pathParts.length <= 6) {
@@ -1075,21 +1120,36 @@ export class ScopeDataStructure {
1075
1120
  }
1076
1121
  setInstantiatedVariables(scopeNode) {
1077
1122
  let instantiatedVariables = scopeNode.analysis?.instantiatedVariables ?? [];
1078
- for (const [path, equivalentPath] of Object.entries(scopeNode.analysis.isolatedEquivalentVariables ?? {})) {
1079
- if (typeof equivalentPath !== 'string') {
1080
- continue;
1081
- }
1082
- if (equivalentPath.startsWith('signature[')) {
1083
- const equivalentPathParts = this.splitPath(equivalentPath);
1084
- instantiatedVariables.push(equivalentPathParts[0]);
1085
- instantiatedVariables.push(path);
1123
+ for (const [path, rawEquivalentPath] of Object.entries(scopeNode.analysis.isolatedEquivalentVariables ?? {})) {
1124
+ // Normalize to array for consistent handling (supports both string and string[])
1125
+ const equivalentPaths = Array.isArray(rawEquivalentPath)
1126
+ ? rawEquivalentPath
1127
+ : rawEquivalentPath
1128
+ ? [rawEquivalentPath]
1129
+ : [];
1130
+ for (const equivalentPath of equivalentPaths) {
1131
+ if (typeof equivalentPath !== 'string') {
1132
+ continue;
1133
+ }
1134
+ if (equivalentPath.startsWith('signature[')) {
1135
+ const equivalentPathParts = this.splitPath(equivalentPath);
1136
+ instantiatedVariables.push(equivalentPathParts[0]);
1137
+ instantiatedVariables.push(path);
1138
+ }
1086
1139
  }
1087
1140
  const duplicateInstantiated = instantiatedVariables.find((v) => path.split('::cyDuplicateKey')[0] === v.split('::cyDuplicateKey')[0]);
1088
1141
  if (duplicateInstantiated) {
1089
1142
  instantiatedVariables.push(path);
1090
1143
  }
1091
1144
  }
1092
- instantiatedVariables = instantiatedVariables.filter((varName, index, self) => self.indexOf(varName) === index);
1145
+ const instantiatedSeen = new Set();
1146
+ instantiatedVariables = instantiatedVariables.filter((varName) => {
1147
+ if (instantiatedSeen.has(varName)) {
1148
+ return false;
1149
+ }
1150
+ instantiatedSeen.add(varName);
1151
+ return true;
1152
+ });
1093
1153
  scopeNode.instantiatedVariables = instantiatedVariables;
1094
1154
  if (!scopeNode.tree || scopeNode.tree.length === 0) {
1095
1155
  return;
@@ -1101,9 +1161,16 @@ export class ScopeDataStructure {
1101
1161
  const parentInstantiatedVariables = [
1102
1162
  ...(parentScopeNode.parentInstantiatedVariables ?? []),
1103
1163
  ...parentScopeNode.instantiatedVariables.filter((v) => !v.startsWith('signature[') && !v.startsWith('returnValue')),
1104
- ].filter((varName, index, self) => !instantiatedVariables.includes(varName) &&
1105
- self.indexOf(varName) === index);
1106
- scopeNode.parentInstantiatedVariables = parentInstantiatedVariables;
1164
+ ].filter((varName) => !instantiatedSeen.has(varName));
1165
+ const parentInstantiatedSeen = new Set();
1166
+ const dedupedParentInstantiatedVariables = parentInstantiatedVariables.filter((varName) => {
1167
+ if (parentInstantiatedSeen.has(varName)) {
1168
+ return false;
1169
+ }
1170
+ parentInstantiatedSeen.add(varName);
1171
+ return true;
1172
+ });
1173
+ scopeNode.parentInstantiatedVariables = dedupedParentInstantiatedVariables;
1107
1174
  }
1108
1175
  trackFunctionCalls(scopeNode) {
1109
1176
  this.captureFunctionCalls(scopeNode);
@@ -1114,116 +1181,136 @@ export class ScopeDataStructure {
1114
1181
  return;
1115
1182
  }
1116
1183
  const { isolatedStructure, isolatedEquivalentVariables } = scopeNode.analysis;
1184
+ // Flatten isolatedEquivalentVariables values for allPaths (handles both string and string[])
1185
+ const flattenedEquivValues = Object.values(isolatedEquivalentVariables || {}).flatMap((v) => (Array.isArray(v) ? v : [v]));
1117
1186
  const allPaths = Array.from(new Set([
1118
1187
  ...Object.keys(isolatedStructure || {}),
1119
1188
  ...Object.keys(isolatedEquivalentVariables || {}),
1120
- ...Object.values(isolatedEquivalentVariables || {}),
1189
+ ...flattenedEquivValues,
1121
1190
  ]));
1122
1191
  for (let path in isolatedEquivalentVariables) {
1123
- let equivalentValue = isolatedEquivalentVariables?.[path];
1124
- if (equivalentValue && this.isValidPath(equivalentValue)) {
1125
- // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1126
- // These markers are critical for distinguishing variable reassignments.
1127
- // For example, with:
1128
- // let fetcher = useFetcher<ConfigData>();
1129
- // const configData = fetcher.data?.data;
1130
- // fetcher = useFetcher<SettingsData>();
1131
- // const settingsData = fetcher.data?.data;
1132
- //
1133
- // mergeStatements creates:
1134
- // fetcher useFetcher<ConfigData>()...
1135
- // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1136
- // configData fetcher.data.data
1137
- // settingsData → fetcher::cyDuplicateKey1::.data.data
1138
- //
1139
- // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1140
- // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1141
- path = cleanPath(path, allPaths);
1142
- equivalentValue = cleanPath(equivalentValue, allPaths);
1143
- this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
1144
- // Propagate equivalencies involving parent-scope variables to those parent scopes.
1145
- // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1146
- // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1147
- // visible when tracing from the parent scope.
1148
- const rootVariable = this.extractRootVariable(path);
1149
- const equivalentRootVariable = this.extractRootVariable(equivalentValue);
1150
- // Skip propagation for self-referential reassignment patterns like:
1151
- // x = x.method().functionCallReturnValue
1152
- // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1153
- // These create circular references since both sides reference the same variable.
1154
- //
1155
- // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1156
- // where the path has additional segments beyond the root variable.
1157
- const pathIsJustRootVariable = path === rootVariable;
1158
- const isSelfReferentialReassignment = pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1159
- if (rootVariable &&
1160
- !isSelfReferentialReassignment &&
1161
- scopeNode.parentInstantiatedVariables?.includes(rootVariable)) {
1162
- // Find the parent scope where this variable is defined
1163
- for (const parentScopeName of scopeNode.tree || []) {
1164
- const parentScope = this.scopeNodes[parentScopeName];
1165
- if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1166
- // Add the equivalency to the parent scope as well
1167
- this.addEquivalency(path, equivalentValue, scopeNode.name, // The equivalent path's scope remains the child scope
1168
- parentScope, // But store it in the parent scope's equivalencies
1169
- 'propagated parent-variable equivalency');
1170
- break;
1192
+ const rawEquivalentValue = isolatedEquivalentVariables?.[path];
1193
+ // Normalize to array for consistent handling
1194
+ const equivalentValues = Array.isArray(rawEquivalentValue)
1195
+ ? rawEquivalentValue
1196
+ : [rawEquivalentValue];
1197
+ for (let equivalentValue of equivalentValues) {
1198
+ if (equivalentValue && this.isValidPath(equivalentValue)) {
1199
+ // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1200
+ // These markers are critical for distinguishing variable reassignments.
1201
+ // For example, with:
1202
+ // let fetcher = useFetcher<ConfigData>();
1203
+ // const configData = fetcher.data?.data;
1204
+ // fetcher = useFetcher<SettingsData>();
1205
+ // const settingsData = fetcher.data?.data;
1206
+ //
1207
+ // mergeStatements creates:
1208
+ // fetcher useFetcher<ConfigData>()...
1209
+ // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1210
+ // configData fetcher.data.data
1211
+ // settingsData fetcher::cyDuplicateKey1::.data.data
1212
+ //
1213
+ // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1214
+ // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1215
+ path = cleanPath(path, allPaths);
1216
+ equivalentValue = cleanPath(equivalentValue, allPaths);
1217
+ this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
1218
+ // Propagate equivalencies involving parent-scope variables to those parent scopes.
1219
+ // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1220
+ // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1221
+ // visible when tracing from the parent scope.
1222
+ const rootVariable = this.extractRootVariable(path);
1223
+ const equivalentRootVariable = this.extractRootVariable(equivalentValue);
1224
+ // Skip propagation for self-referential reassignment patterns like:
1225
+ // x = x.method().functionCallReturnValue
1226
+ // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1227
+ // These create circular references since both sides reference the same variable.
1228
+ //
1229
+ // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1230
+ // where the path has additional segments beyond the root variable.
1231
+ const pathIsJustRootVariable = path === rootVariable;
1232
+ const isSelfReferentialReassignment = pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1233
+ if (rootVariable &&
1234
+ !isSelfReferentialReassignment &&
1235
+ scopeNode.parentInstantiatedVariables?.includes(rootVariable)) {
1236
+ // Find the parent scope where this variable is defined
1237
+ for (const parentScopeName of scopeNode.tree || []) {
1238
+ const parentScope = this.scopeNodes[parentScopeName];
1239
+ if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1240
+ // Add the equivalency to the parent scope as well
1241
+ this.addEquivalency(path, equivalentValue, scopeNode.name, // The equivalent path's scope remains the child scope
1242
+ parentScope, // But store it in the parent scope's equivalencies
1243
+ 'propagated parent-variable equivalency');
1244
+ break;
1245
+ }
1171
1246
  }
1172
1247
  }
1173
- }
1174
- // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1175
- // that has sub-properties defined in the isolatedEquivalentVariables.
1176
- // This handles cases like: dataItem={{ structure: completeDataStructure }}
1177
- // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1178
- // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1179
- const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
1180
- !equivalentValue.includes('functionCallReturnValue') &&
1181
- !equivalentValue.includes('.') &&
1182
- !equivalentValue.includes('[');
1183
- if (isSimpleVariable) {
1184
- // Look in current scope and all parent scopes for sub-properties
1185
- const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1186
- for (const scopeName of scopesToCheck) {
1187
- const checkScope = this.scopeNodes[scopeName];
1188
- if (!checkScope?.analysis?.isolatedEquivalentVariables)
1189
- continue;
1190
- for (const [subPath, subValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
1191
- // Check if this is a sub-property of the equivalentValue variable
1192
- // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1193
- const matchesDot = subPath.startsWith(equivalentValue + '.');
1194
- const matchesBracket = subPath.startsWith(equivalentValue + '[');
1195
- if (matchesDot || matchesBracket) {
1196
- const subPropertyPath = subPath.substring(equivalentValue.length);
1197
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1198
- const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1199
- if (newEquivalentValue &&
1200
- this.isValidPath(newEquivalentValue)) {
1201
- this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
1202
- scopeNode, 'propagated sub-property equivalency');
1248
+ // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1249
+ // that has sub-properties defined in the isolatedEquivalentVariables.
1250
+ // This handles cases like: dataItem={{ structure: completeDataStructure }}
1251
+ // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1252
+ // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1253
+ const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
1254
+ !equivalentValue.includes('functionCallReturnValue') &&
1255
+ !equivalentValue.includes('.') &&
1256
+ !equivalentValue.includes('[');
1257
+ if (isSimpleVariable) {
1258
+ // Look in current scope and all parent scopes for sub-properties
1259
+ const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1260
+ for (const scopeName of scopesToCheck) {
1261
+ const checkScope = this.scopeNodes[scopeName];
1262
+ if (!checkScope?.analysis?.isolatedEquivalentVariables)
1263
+ continue;
1264
+ for (const [subPath, rawSubValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
1265
+ // Normalize to array for consistent handling
1266
+ const subValues = Array.isArray(rawSubValue)
1267
+ ? rawSubValue
1268
+ : rawSubValue
1269
+ ? [rawSubValue]
1270
+ : [];
1271
+ // Check if this is a sub-property of the equivalentValue variable
1272
+ // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1273
+ const matchesDot = subPath.startsWith(equivalentValue + '.');
1274
+ const matchesBracket = subPath.startsWith(equivalentValue + '[');
1275
+ if (matchesDot || matchesBracket) {
1276
+ const subPropertyPath = subPath.substring(equivalentValue.length);
1277
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
1278
+ for (const subValue of subValues) {
1279
+ if (typeof subValue !== 'string')
1280
+ continue;
1281
+ const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1282
+ if (newEquivalentValue &&
1283
+ this.isValidPath(newEquivalentValue)) {
1284
+ this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
1285
+ scopeNode, 'propagated sub-property equivalency');
1286
+ }
1287
+ }
1288
+ }
1289
+ // Also check if equivalentValue itself maps to a functionCallReturnValue
1290
+ // e.g., result = useMemo(...).functionCallReturnValue
1291
+ for (const subValue of subValues) {
1292
+ if (subPath === equivalentValue &&
1293
+ typeof subValue === 'string' &&
1294
+ subValue.endsWith('.functionCallReturnValue')) {
1295
+ this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
1296
+ }
1203
1297
  }
1204
- }
1205
- // Also check if equivalentValue itself maps to a functionCallReturnValue
1206
- // e.g., result = useMemo(...).functionCallReturnValue
1207
- if (subPath === equivalentValue &&
1208
- typeof subValue === 'string' &&
1209
- subValue.endsWith('.functionCallReturnValue')) {
1210
- this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
1211
1298
  }
1212
1299
  }
1213
1300
  }
1214
- }
1215
- // Handle function call return values by propagating returnValue.* sub-properties
1216
- // from the callback scope to the usage path
1217
- if (equivalentValue.endsWith('.functionCallReturnValue')) {
1218
- this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
1219
- // Track which variable receives the return value of each function call
1220
- // This enables generating separate mock data for each call site
1221
- this.trackReceivingVariable(path, equivalentValue);
1222
- }
1223
- // Also track variables that receive destructured properties from function call return values
1224
- // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1225
- if (equivalentValue.includes('.functionCallReturnValue.')) {
1226
- this.trackReceivingVariable(path, equivalentValue);
1301
+ // Handle function call return values by propagating returnValue.* sub-properties
1302
+ // from the callback scope to the usage path
1303
+ if (equivalentValue.endsWith('.functionCallReturnValue')) {
1304
+ this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
1305
+ // Track which variable receives the return value of each function call
1306
+ // This enables generating separate mock data for each call site
1307
+ this.trackReceivingVariable(path, equivalentValue);
1308
+ }
1309
+ // Also track variables that receive destructured properties from function call return values
1310
+ // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1311
+ if (equivalentValue.includes('.functionCallReturnValue.')) {
1312
+ this.trackReceivingVariable(path, equivalentValue);
1313
+ }
1227
1314
  }
1228
1315
  }
1229
1316
  }
@@ -1367,8 +1454,15 @@ export class ScopeDataStructure {
1367
1454
  const checkScope = this.scopeNodes[scopeName];
1368
1455
  if (!checkScope?.analysis?.isolatedEquivalentVariables)
1369
1456
  continue;
1370
- const functionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
1371
- if (typeof functionRef === 'string' && functionRef.endsWith('F')) {
1457
+ const rawFunctionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
1458
+ // Normalize to array and find first string ending with 'F'
1459
+ const functionRefs = Array.isArray(rawFunctionRef)
1460
+ ? rawFunctionRef
1461
+ : rawFunctionRef
1462
+ ? [rawFunctionRef]
1463
+ : [];
1464
+ const functionRef = functionRefs.find((r) => typeof r === 'string' && r.endsWith('F'));
1465
+ if (typeof functionRef === 'string') {
1372
1466
  callbackScopeName = functionRef.slice(0, -1);
1373
1467
  break;
1374
1468
  }
@@ -1391,22 +1485,32 @@ export class ScopeDataStructure {
1391
1485
  if (!callbackScope.analysis?.isolatedEquivalentVariables)
1392
1486
  return;
1393
1487
  const isolatedVars = callbackScope.analysis.isolatedEquivalentVariables;
1488
+ // Get the first returnValue equivalency (normalize array to single value for these checks)
1489
+ const rawReturnValue = isolatedVars.returnValue;
1490
+ const firstReturnValue = Array.isArray(rawReturnValue)
1491
+ ? rawReturnValue[0]
1492
+ : rawReturnValue;
1394
1493
  // First, check if returnValue is an alias to another variable (e.g., returnValue = intermediate)
1395
1494
  // If so, we need to look for that variable's sub-properties too
1396
- const returnValueAlias = typeof isolatedVars.returnValue === 'string' &&
1397
- !isolatedVars.returnValue.includes('.')
1398
- ? isolatedVars.returnValue
1495
+ const returnValueAlias = typeof firstReturnValue === 'string' && !firstReturnValue.includes('.')
1496
+ ? firstReturnValue
1399
1497
  : undefined;
1400
1498
  // Pattern 3: Object.keys(X).reduce() - the reduce result has the same sub-properties as X
1401
1499
  // When returnValue = "Object.keys(source).reduce(...).functionCallReturnValue", look for source.* sub-properties
1402
1500
  let reduceSourceVar;
1403
- if (typeof isolatedVars.returnValue === 'string') {
1404
- const reduceMatch = isolatedVars.returnValue.match(/^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/);
1501
+ if (typeof firstReturnValue === 'string') {
1502
+ const reduceMatch = firstReturnValue.match(/^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/);
1405
1503
  if (reduceMatch) {
1406
1504
  reduceSourceVar = reduceMatch[1];
1407
1505
  }
1408
1506
  }
1409
- for (const [subPath, subValue] of Object.entries(isolatedVars)) {
1507
+ for (const [subPath, rawSubValue] of Object.entries(isolatedVars)) {
1508
+ // Normalize to array for consistent handling
1509
+ const subValues = Array.isArray(rawSubValue)
1510
+ ? rawSubValue
1511
+ : rawSubValue
1512
+ ? [rawSubValue]
1513
+ : [];
1410
1514
  // Check for direct returnValue.* sub-properties
1411
1515
  const isReturnValueSub = subPath.startsWith('returnValue.') ||
1412
1516
  subPath.startsWith('returnValue[');
@@ -1418,33 +1522,36 @@ export class ScopeDataStructure {
1418
1522
  const isReduceSourceSub = reduceSourceVar &&
1419
1523
  (subPath.startsWith(reduceSourceVar + '.') ||
1420
1524
  subPath.startsWith(reduceSourceVar + '['));
1421
- if (typeof subValue !== 'string' ||
1422
- (!isReturnValueSub && !isAliasSub && !isReduceSourceSub))
1423
- continue;
1424
- // Convert alias/reduceSource paths to returnValue paths
1425
- let effectiveSubPath = subPath;
1426
- if (isAliasSub && !isReturnValueSub) {
1427
- // Replace the alias prefix with returnValue
1428
- effectiveSubPath =
1429
- 'returnValue' + subPath.substring(returnValueAlias.length);
1430
- }
1431
- else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
1432
- // Replace the reduce source prefix with returnValue
1433
- effectiveSubPath =
1434
- 'returnValue' + subPath.substring(reduceSourceVar.length);
1435
- }
1436
- const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
1437
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1438
- let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1439
- // Resolve variable references through parent scope equivalencies
1440
- const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
1441
- newEquivalentValue = resolved.resolvedPath;
1442
- const equivalentScopeName = resolved.scopeName;
1443
- if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
1525
+ if (!isReturnValueSub && !isAliasSub && !isReduceSourceSub)
1444
1526
  continue;
1445
- this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
1446
- // Ensure the database entry has the usage path
1447
- this.addUsageToEquivalencyDatabaseEntry(newPath, newEquivalentValue, equivalentScopeName, scopeNode.name);
1527
+ for (const subValue of subValues) {
1528
+ if (typeof subValue !== 'string')
1529
+ continue;
1530
+ // Convert alias/reduceSource paths to returnValue paths
1531
+ let effectiveSubPath = subPath;
1532
+ if (isAliasSub && !isReturnValueSub) {
1533
+ // Replace the alias prefix with returnValue
1534
+ effectiveSubPath =
1535
+ 'returnValue' + subPath.substring(returnValueAlias.length);
1536
+ }
1537
+ else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
1538
+ // Replace the reduce source prefix with returnValue
1539
+ effectiveSubPath =
1540
+ 'returnValue' + subPath.substring(reduceSourceVar.length);
1541
+ }
1542
+ const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
1543
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
1544
+ let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1545
+ // Resolve variable references through parent scope equivalencies
1546
+ const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
1547
+ newEquivalentValue = resolved.resolvedPath;
1548
+ const equivalentScopeName = resolved.scopeName;
1549
+ if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
1550
+ continue;
1551
+ this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
1552
+ // Ensure the database entry has the usage path
1553
+ this.addUsageToEquivalencyDatabaseEntry(newPath, newEquivalentValue, equivalentScopeName, scopeNode.name);
1554
+ }
1448
1555
  }
1449
1556
  }
1450
1557
  /**
@@ -1476,7 +1583,14 @@ export class ScopeDataStructure {
1476
1583
  const parentScope = this.scopeNodes[parentScopeName];
1477
1584
  if (!parentScope?.analysis?.isolatedEquivalentVariables)
1478
1585
  continue;
1479
- const rootEquiv = parentScope.analysis.isolatedEquivalentVariables[rootVar];
1586
+ const rawRootEquiv = parentScope.analysis.isolatedEquivalentVariables[rootVar];
1587
+ // Normalize to array and use first string value
1588
+ const rootEquivs = Array.isArray(rawRootEquiv)
1589
+ ? rawRootEquiv
1590
+ : rawRootEquiv
1591
+ ? [rawRootEquiv]
1592
+ : [];
1593
+ const rootEquiv = rootEquivs.find((r) => typeof r === 'string');
1480
1594
  if (typeof rootEquiv === 'string') {
1481
1595
  return {
1482
1596
  resolvedPath: cleanPath(rootEquiv + restOfPath, allPaths),
@@ -1670,6 +1784,7 @@ export class ScopeDataStructure {
1670
1784
  const remainingPath = this.joinPathParts(remainingPathParts);
1671
1785
  if (relevantSubPathParts.every((part, i) => part === schemaPathParts[i]) &&
1672
1786
  equivalentValue.scopeNodeName === scopeNode.name) {
1787
+ // DEBUG
1673
1788
  continue;
1674
1789
  }
1675
1790
  const newEquivalentPath = this.joinPathParts([schemaPath, remainingPath]);
@@ -1811,6 +1926,8 @@ export class ScopeDataStructure {
1811
1926
  return;
1812
1927
  }
1813
1928
  const usageScopeNode = this.getScopeOrFunctionCallInfo(usageEquivalency.scopeNodeName);
1929
+ if (!usageScopeNode)
1930
+ continue;
1814
1931
  // Guard against infinite recursion by tracking which paths we've already
1815
1932
  // added from addComplexSourcePathVariables
1816
1933
  if (this.visitedTracker.checkAndMarkComplexSourceVisited(usageScopeNode.name, newUsageEquivalentPath)) {
@@ -1859,6 +1976,8 @@ export class ScopeDataStructure {
1859
1976
  continue;
1860
1977
  }
1861
1978
  const usageScopeNode = this.getScopeOrFunctionCallInfo(usageEquivalency.scopeNodeName);
1979
+ if (!usageScopeNode)
1980
+ continue;
1862
1981
  // This is put in place to avoid propagating array functions like 'filter' through complex equivalencies
1863
1982
  // but may cause problems if the funtion call is not on a known object (e.g. string or array)
1864
1983
  if (newUsageEquivalentPath.endsWith(')') ||
@@ -1955,9 +2074,70 @@ export class ScopeDataStructure {
1955
2074
  // Update inverted index
1956
2075
  this.intermediatesOrderIndex.set(pathId, databaseEntry);
1957
2076
  if (intermediateIndex === 0) {
1958
- const isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
2077
+ let isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
1959
2078
  pathInfo.schemaPath.includes('functionCallReturnValue');
1960
- if (isValidSourceCandidate) {
2079
+ // Check if path STARTS with a spread pattern like [...var]
2080
+ // This handles cases like [...files][][0] or [...files].sort(...).functionCallReturnValue[][0]
2081
+ // where the spread source variable needs to be resolved to a signature path.
2082
+ // We do this REGARDLESS of isValidSourceCandidate because even paths containing
2083
+ // functionCallReturnValue may need spread resolution to trace back to the signature.
2084
+ const spreadMatch = pathInfo.schemaPath.match(/^\[\.\.\.(\w+)\]/);
2085
+ if (spreadMatch) {
2086
+ const spreadVar = spreadMatch[1];
2087
+ const spreadPattern = spreadMatch[0]; // The full [...var] match
2088
+ const scopeNode = this.scopeNodes[pathInfo.scopeNodeName];
2089
+ if (scopeNode?.equivalencies) {
2090
+ // Follow the equivalency chain to find a signature path
2091
+ // e.g., files (cyScope1) → files (root) → signature[0].files
2092
+ const resolveToSignature = (varName, currentScopeName, visited) => {
2093
+ const visitKey = `${currentScopeName}::${varName}`;
2094
+ if (visited.has(visitKey))
2095
+ return null;
2096
+ visited.add(visitKey);
2097
+ const currentScope = this.scopeNodes[currentScopeName];
2098
+ if (!currentScope?.equivalencies)
2099
+ return null;
2100
+ const varEquivs = currentScope.equivalencies[varName];
2101
+ if (!varEquivs)
2102
+ return null;
2103
+ // First check if any equivalency directly points to a signature path
2104
+ const signatureEquiv = varEquivs.find((eq) => eq.schemaPath.startsWith('signature['));
2105
+ if (signatureEquiv) {
2106
+ return signatureEquiv;
2107
+ }
2108
+ // Otherwise, follow the chain to other scopes
2109
+ for (const equiv of varEquivs) {
2110
+ // If the equivalency points to the same variable in a different scope,
2111
+ // follow the chain
2112
+ if (equiv.schemaPath === varName &&
2113
+ equiv.scopeNodeName !== currentScopeName) {
2114
+ const result = resolveToSignature(varName, equiv.scopeNodeName, visited);
2115
+ if (result)
2116
+ return result;
2117
+ }
2118
+ }
2119
+ return null;
2120
+ };
2121
+ const signatureEquiv = resolveToSignature(spreadVar, pathInfo.scopeNodeName, new Set());
2122
+ if (signatureEquiv) {
2123
+ // Replace ONLY the [...var] part with the resolved signature path
2124
+ // This preserves any suffix like .sort(...).functionCallReturnValue[][0]
2125
+ const resolvedPath = pathInfo.schemaPath.replace(spreadPattern, signatureEquiv.schemaPath);
2126
+ // Add the resolved path as a source candidate
2127
+ if (!databaseEntry.sourceCandidates.some((sc) => sc.schemaPath === resolvedPath &&
2128
+ sc.scopeNodeName === pathInfo.scopeNodeName)) {
2129
+ databaseEntry.sourceCandidates.push({
2130
+ scopeNodeName: pathInfo.scopeNodeName,
2131
+ schemaPath: resolvedPath,
2132
+ });
2133
+ }
2134
+ isValidSourceCandidate = true;
2135
+ }
2136
+ }
2137
+ }
2138
+ if (isValidSourceCandidate &&
2139
+ !databaseEntry.sourceCandidates.some((sc) => sc.schemaPath === pathInfo.schemaPath &&
2140
+ sc.scopeNodeName === pathInfo.scopeNodeName)) {
1961
2141
  databaseEntry.sourceCandidates.push(pathInfo);
1962
2142
  }
1963
2143
  }
@@ -2103,6 +2283,13 @@ export class ScopeDataStructure {
2103
2283
  delete scopeNode.schema[key];
2104
2284
  }
2105
2285
  }
2286
+ // Ensure parameter-to-signature equivalencies are fully propagated.
2287
+ // When a parameter variable (e.g., `node`) is equivalenced to `signature[N]`,
2288
+ // all sub-paths of that variable should also appear under `signature[N]`.
2289
+ // This handles cases where the sub-path was added to the schema via a propagation
2290
+ // chain that already included the variable↔signature equivalency, causing the
2291
+ // cycle detection to prevent the reverse mapping.
2292
+ this.propagateParameterToSignaturePaths(scopeNode);
2106
2293
  fillInSchemaGapsAndUnknowns(scopeNode, fillInUnknowns);
2107
2294
  if (final) {
2108
2295
  for (const manager of this.equivalencyManagers) {
@@ -2114,6 +2301,40 @@ export class ScopeDataStructure {
2114
2301
  ensureSchemaConsistency(scopeNode.schema);
2115
2302
  }
2116
2303
  }
2304
+ /**
2305
+ * For each equivalency where a simple variable maps to signature[N],
2306
+ * ensure all sub-paths of that variable are reflected under signature[N].
2307
+ */
2308
+ propagateParameterToSignaturePaths(scopeNode) {
2309
+ // Find variable → signature[N] equivalencies
2310
+ for (const [varName, equivalencies] of Object.entries(scopeNode.equivalencies)) {
2311
+ // Only process simple variable names (no dots, brackets, or parens)
2312
+ if (varName.includes('.') ||
2313
+ varName.includes('[') ||
2314
+ varName.includes('(')) {
2315
+ continue;
2316
+ }
2317
+ for (const equiv of equivalencies) {
2318
+ if (equiv.scopeNodeName === scopeNode.name &&
2319
+ equiv.schemaPath.startsWith('signature[')) {
2320
+ const signaturePath = equiv.schemaPath;
2321
+ const varPrefix = varName + '.';
2322
+ const varBracketPrefix = varName + '[';
2323
+ // Find all schema keys starting with the variable
2324
+ for (const key in scopeNode.schema) {
2325
+ if (key.startsWith(varPrefix) || key.startsWith(varBracketPrefix)) {
2326
+ const suffix = key.slice(varName.length);
2327
+ const sigKey = signaturePath + suffix;
2328
+ // Only add if the signature path doesn't already exist
2329
+ if (!scopeNode.schema[sigKey]) {
2330
+ scopeNode.schema[sigKey] = scopeNode.schema[key];
2331
+ }
2332
+ }
2333
+ }
2334
+ }
2335
+ }
2336
+ }
2337
+ }
2117
2338
  filterAndConvertSchema({ filterPath, newPath, schema, }) {
2118
2339
  const filterPathParts = this.splitPath(filterPath);
2119
2340
  return Object.keys(schema).reduce((acc, key) => {
@@ -2173,6 +2394,10 @@ export class ScopeDataStructure {
2173
2394
  path,
2174
2395
  ...this.splitPath(key).slice(equivalentValueSchemaPathParts.length),
2175
2396
  ]);
2397
+ // PERF: Skip keys with repeated function-call signature patterns
2398
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
2399
+ if (this.hasExcessivePatternRepetition(newKey))
2400
+ continue;
2176
2401
  resolvedSchema[newKey] = value;
2177
2402
  }
2178
2403
  }
@@ -2194,6 +2419,9 @@ export class ScopeDataStructure {
2194
2419
  if (!subSchema)
2195
2420
  continue;
2196
2421
  for (const resolvedKey in subSchema) {
2422
+ // PERF: Skip keys with repeated function-call signature patterns
2423
+ if (this.hasExcessivePatternRepetition(resolvedKey))
2424
+ continue;
2197
2425
  if (!resolvedSchema[resolvedKey] ||
2198
2426
  subSchema[resolvedKey] === 'unknown') {
2199
2427
  resolvedSchema[resolvedKey] = subSchema[resolvedKey];
@@ -2367,18 +2595,204 @@ export class ScopeDataStructure {
2367
2595
  if (!scopeNode) {
2368
2596
  return {};
2369
2597
  }
2370
- const entries = this.equivalencyDatabase.filter((entry) => entry.usages.some((usage) => usage.scopeNodeName === scopeNode.name));
2371
- return entries.reduce((acc, entry) => {
2598
+ // Collect all descendant scope names (including the scope itself)
2599
+ // This ensures we include external calls from nested scopes like cyScope2
2600
+ const getAllDescendantScopeNames = (node) => {
2601
+ const names = new Set([node.name]);
2602
+ for (const child of node.children) {
2603
+ for (const name of getAllDescendantScopeNames(child)) {
2604
+ names.add(name);
2605
+ }
2606
+ }
2607
+ return names;
2608
+ };
2609
+ const treeNode = this.scopeTreeManager.findNode(scopeNode.name);
2610
+ const descendantScopeNames = treeNode
2611
+ ? getAllDescendantScopeNames(treeNode)
2612
+ : new Set([scopeNode.name]);
2613
+ // Get all external function calls made from this scope or any descendant scope
2614
+ // This allows us to include prop equivalencies from JSX components
2615
+ // that were rendered in nested scopes (e.g., FileTableRow called from cyScope2)
2616
+ const externalCallsFromScope = this.externalFunctionCalls.filter((efc) => descendantScopeNames.has(efc.callScope));
2617
+ const externalCallNames = new Set(externalCallsFromScope.map((efc) => efc.name));
2618
+ // Helper to check if a usage belongs to this scope (directly, via descendant, or via external call)
2619
+ const usageMatchesScope = (usage) => descendantScopeNames.has(usage.scopeNodeName) ||
2620
+ externalCallNames.has(usage.scopeNodeName);
2621
+ const entries = this.equivalencyDatabase.filter((entry) => entry.usages.some(usageMatchesScope));
2622
+ // Helper to resolve a source candidate through equivalency chains to find signature paths
2623
+ const resolveToSignature = (source, visited) => {
2624
+ const visitKey = `${source.scopeNodeName}::${source.schemaPath}`;
2625
+ if (visited.has(visitKey))
2626
+ return [];
2627
+ visited.add(visitKey);
2628
+ // If already a signature path, return as-is
2629
+ if (source.schemaPath.startsWith('signature[')) {
2630
+ return [source];
2631
+ }
2632
+ const currentScope = this.scopeNodes[source.scopeNodeName];
2633
+ if (!currentScope?.equivalencies)
2634
+ return [source];
2635
+ // Check for direct equivalencies FIRST (full path match)
2636
+ // This ensures paths like "useMemo(...).functionCallReturnValue" follow to "cyScope1::returnValue"
2637
+ // before prefix matching tries "useMemo(...)" which goes to the useMemo scope
2638
+ const directEquivs = currentScope.equivalencies[source.schemaPath];
2639
+ if (directEquivs?.length > 0) {
2640
+ const results = [];
2641
+ for (const equiv of directEquivs) {
2642
+ const resolved = resolveToSignature({
2643
+ scopeNodeName: equiv.scopeNodeName,
2644
+ schemaPath: equiv.schemaPath,
2645
+ }, visited);
2646
+ results.push(...resolved);
2647
+ }
2648
+ if (results.length > 0)
2649
+ return results;
2650
+ }
2651
+ // Handle spread patterns like [...items].sort().functionCallReturnValue
2652
+ // Extract the spread variable and resolve it through the equivalency chain
2653
+ const spreadMatch = source.schemaPath.match(/^\[\.\.\.(\w+)\]/);
2654
+ if (spreadMatch) {
2655
+ const spreadVar = spreadMatch[1];
2656
+ const spreadPattern = spreadMatch[0];
2657
+ const varEquivs = currentScope.equivalencies[spreadVar];
2658
+ if (varEquivs?.length > 0) {
2659
+ const results = [];
2660
+ for (const equiv of varEquivs) {
2661
+ // Follow the variable equivalency and then resolve from there
2662
+ const resolvedVar = resolveToSignature({
2663
+ scopeNodeName: equiv.scopeNodeName,
2664
+ schemaPath: equiv.schemaPath,
2665
+ }, visited);
2666
+ // For each resolved variable path, create the full path with array element suffix
2667
+ for (const rv of resolvedVar) {
2668
+ if (rv.schemaPath.startsWith('signature[')) {
2669
+ // Get the suffix after the spread pattern
2670
+ let suffix = source.schemaPath.slice(spreadPattern.length);
2671
+ // Clean the suffix: strip array method chains like .sort(...).functionCallReturnValue[]
2672
+ // These don't change the data identity, just transform it.
2673
+ // Keep only the final element access parts like [0], [1], etc.
2674
+ // Pattern: strip everything from a method call up through functionCallReturnValue[]
2675
+ suffix = suffix.replace(/\.\w+\([^)]*\)\.functionCallReturnValue\[\]/g, '');
2676
+ // Also handle simpler case without nested parens
2677
+ suffix = suffix.replace(/\.sort\(\w*\(\)\)\.functionCallReturnValue\[\]/g, '');
2678
+ // Add [] to indicate array element access from the spread
2679
+ const resolvedPath = rv.schemaPath + '[]' + suffix;
2680
+ results.push({
2681
+ scopeNodeName: rv.scopeNodeName,
2682
+ schemaPath: resolvedPath,
2683
+ });
2684
+ }
2685
+ }
2686
+ }
2687
+ if (results.length > 0)
2688
+ return results;
2689
+ }
2690
+ }
2691
+ // Try to find prefix equivalencies that can resolve this path
2692
+ // For path like "cyScope3().signature[0][0]", check "cyScope3().signature[0]", etc.
2693
+ const pathParts = this.splitPath(source.schemaPath);
2694
+ for (let i = pathParts.length - 1; i > 0; i--) {
2695
+ const prefix = this.joinPathParts(pathParts.slice(0, i));
2696
+ const suffix = this.joinPathParts(pathParts.slice(i));
2697
+ const prefixEquivs = currentScope.equivalencies[prefix];
2698
+ if (prefixEquivs?.length > 0) {
2699
+ const results = [];
2700
+ for (const equiv of prefixEquivs) {
2701
+ const newPath = this.joinPathParts([equiv.schemaPath, suffix]);
2702
+ const resolved = resolveToSignature({ scopeNodeName: equiv.scopeNodeName, schemaPath: newPath }, visited);
2703
+ results.push(...resolved);
2704
+ }
2705
+ if (results.length > 0)
2706
+ return results;
2707
+ }
2708
+ }
2709
+ return [source];
2710
+ };
2711
+ const acc = entries.reduce((result, entry) => {
2372
2712
  var _a;
2373
2713
  if (entry.sourceCandidates.length === 0)
2374
- return acc;
2375
- const usages = entry.usages.filter((u) => u.scopeNodeName === scopeNode.name);
2714
+ return result;
2715
+ const usages = entry.usages.filter(usageMatchesScope);
2376
2716
  for (const usage of usages) {
2377
- acc[_a = usage.schemaPath] || (acc[_a] = []);
2378
- acc[usage.schemaPath].push(...entry.sourceCandidates);
2717
+ result[_a = usage.schemaPath] || (result[_a] = []);
2718
+ // Resolve each source candidate through the equivalency chain
2719
+ for (const source of entry.sourceCandidates) {
2720
+ const resolvedSources = resolveToSignature(source, new Set());
2721
+ result[usage.schemaPath].push(...resolvedSources);
2722
+ }
2379
2723
  }
2380
- return acc;
2724
+ return result;
2381
2725
  }, {});
2726
+ // Post-processing: enrich useState-backed sources with co-located external
2727
+ // function calls. When a useState value resolves to a setter variable that
2728
+ // lives in the same scope as a fetch/API call, that fetch is a data source.
2729
+ this.enrichUseStateSourcesWithCoLocatedCalls(acc);
2730
+ return acc;
2731
+ }
2732
+ /**
2733
+ * For each source that ends at a useState path, check if the setter was called
2734
+ * from a scope that also contains external function calls (like fetch).
2735
+ * If so, add those external calls as additional source candidates.
2736
+ */
2737
+ enrichUseStateSourcesWithCoLocatedCalls(acc) {
2738
+ const rootScopeName = this.scopeTreeManager.getRootName();
2739
+ const rootScope = this.scopeNodes[rootScopeName];
2740
+ if (!rootScope)
2741
+ return;
2742
+ // Collect all descendants for each scope node
2743
+ const getAllDescendants = (node) => {
2744
+ const names = new Set([node.name]);
2745
+ for (const child of node.children) {
2746
+ for (const name of getAllDescendants(child)) {
2747
+ names.add(name);
2748
+ }
2749
+ }
2750
+ return names;
2751
+ };
2752
+ for (const [usagePath, sources] of Object.entries(acc)) {
2753
+ const additionalSources = [];
2754
+ for (const source of sources) {
2755
+ // Check if this source is a useState-related terminal path
2756
+ // (e.g., useState(X).functionCallReturnValue[1] or useState(X).signature[0])
2757
+ if (!source.schemaPath.match(/^useState\([^)]*\)\./))
2758
+ continue;
2759
+ // Find the useState call from the source path
2760
+ const useStateCallMatch = source.schemaPath.match(/^(useState\([^)]*\))\./);
2761
+ if (!useStateCallMatch)
2762
+ continue;
2763
+ const useStateCall = useStateCallMatch[1];
2764
+ // Look in the root scope for the useState value equivalency
2765
+ // which tells us where the setter was called from
2766
+ const valuePath = `${useStateCall}.functionCallReturnValue[0]`;
2767
+ const valueEquivs = rootScope.equivalencies[valuePath];
2768
+ if (!valueEquivs)
2769
+ continue;
2770
+ for (const equiv of valueEquivs) {
2771
+ // Find the scope where the setter was called
2772
+ const setterScopeName = equiv.scopeNodeName;
2773
+ const setterScopeTree = this.scopeTreeManager.findNode(setterScopeName);
2774
+ if (!setterScopeTree)
2775
+ continue;
2776
+ // Get all descendant scope names from the setter scope
2777
+ const relatedScopes = getAllDescendants(setterScopeTree);
2778
+ // Find external function calls in those scopes whose return values
2779
+ // are actually consumed (assigned to a variable). This excludes
2780
+ // fire-and-forget calls like analytics.track() or console.log().
2781
+ const coLocatedCalls = this.externalFunctionCalls.filter((efc) => relatedScopes.has(efc.callScope) &&
2782
+ efc.receivingVariableNames &&
2783
+ efc.receivingVariableNames.length > 0);
2784
+ for (const call of coLocatedCalls) {
2785
+ additionalSources.push({
2786
+ scopeNodeName: call.callScope,
2787
+ schemaPath: `${call.callSignature}.functionCallReturnValue`,
2788
+ });
2789
+ }
2790
+ }
2791
+ }
2792
+ if (additionalSources.length > 0) {
2793
+ acc[usagePath].push(...additionalSources);
2794
+ }
2795
+ }
2382
2796
  }
2383
2797
  getUsageEquivalencies(functionName) {
2384
2798
  const scopeNode = this.getScopeOrFunctionCallInfo(functionName);
@@ -2443,6 +2857,49 @@ export class ScopeDataStructure {
2443
2857
  }
2444
2858
  }
2445
2859
  }
2860
+ // Enrich schema with deeply nested paths from internal function call scopes.
2861
+ // When a function call like traverse(tree) exists, and traverse's scope has
2862
+ // signature[0].children[path][entityName] (from propagateParameterToSignaturePaths),
2863
+ // we need to map those paths back to the argument variable (tree) in this scope.
2864
+ // This handles cases where cycle detection prevented the equivalency chain from
2865
+ // propagating deep paths during Phase 2 batch queue processing.
2866
+ for (const equivalenceKey in equivalencies ?? {}) {
2867
+ // Look for keys matching function call pattern: funcName(...).signature[N]
2868
+ const funcCallMatch = equivalenceKey.match(/^([^(]+)\(.*?\)\.(signature\[\d+\])$/);
2869
+ if (!funcCallMatch)
2870
+ continue;
2871
+ const calledFunctionName = funcCallMatch[1];
2872
+ const signatureParam = funcCallMatch[2]; // e.g., "signature[0]"
2873
+ for (const equivalenceValue of equivalencies[equivalenceKey]) {
2874
+ if (equivalenceValue.scopeNodeName !== scopeName)
2875
+ continue;
2876
+ const targetVariable = equivalenceValue.schemaPath;
2877
+ // Get the called function's schema (includes propagated parameter paths)
2878
+ const childSchema = this.getSchema({
2879
+ scopeName: calledFunctionName,
2880
+ });
2881
+ if (!childSchema)
2882
+ continue;
2883
+ // Map child function's signature paths to parent variable paths
2884
+ const sigPrefix = signatureParam + '.';
2885
+ const sigBracketPrefix = signatureParam + '[';
2886
+ for (const childKey in childSchema) {
2887
+ let suffix = null;
2888
+ if (childKey.startsWith(sigPrefix)) {
2889
+ suffix = childKey.slice(signatureParam.length);
2890
+ }
2891
+ else if (childKey.startsWith(sigBracketPrefix)) {
2892
+ suffix = childKey.slice(signatureParam.length);
2893
+ }
2894
+ if (suffix !== null) {
2895
+ const parentKey = targetVariable + suffix;
2896
+ if (!schema[parentKey]) {
2897
+ schema[parentKey] = childSchema[childKey];
2898
+ }
2899
+ }
2900
+ }
2901
+ }
2902
+ }
2446
2903
  // Propagate nested paths from variables to their signature equivalents
2447
2904
  // e.g., if workouts = signature[0].workouts, then workouts[].title becomes
2448
2905
  // signature[0].workouts[].title
@@ -2664,13 +3121,35 @@ export class ScopeDataStructure {
2664
3121
  getEquivalentSignatureVariables() {
2665
3122
  const scopeNode = this.scopeNodes[this.scopeTreeManager.getRootName()];
2666
3123
  const equivalentSignatureVariables = {};
3124
+ // Helper to add equivalencies - accumulates into array if multiple values for same key
3125
+ // This is critical for OR expressions like `x = a || b` where x should map to both a and b
3126
+ const addEquivalency = (key, value) => {
3127
+ const existing = equivalentSignatureVariables[key];
3128
+ if (existing === undefined) {
3129
+ // First value - store as string
3130
+ equivalentSignatureVariables[key] = value;
3131
+ }
3132
+ else if (typeof existing === 'string') {
3133
+ if (existing !== value) {
3134
+ // Second different value - convert to array
3135
+ equivalentSignatureVariables[key] = [existing, value];
3136
+ }
3137
+ // Same value - no change needed
3138
+ }
3139
+ else {
3140
+ // Already an array - add if not already present
3141
+ if (!existing.includes(value)) {
3142
+ existing.push(value);
3143
+ }
3144
+ }
3145
+ };
2667
3146
  for (const [path, equivalentValues] of Object.entries(scopeNode.equivalencies)) {
2668
3147
  for (const equivalentValue of equivalentValues) {
2669
3148
  // Case 1: Props/signature equivalencies (existing behavior)
2670
3149
  // Maps local variable names to their signature paths
2671
3150
  // e.g., "propValue" -> "signature[0].prop"
2672
3151
  if (path.startsWith('signature[')) {
2673
- equivalentSignatureVariables[equivalentValue.schemaPath] = path;
3152
+ addEquivalency(equivalentValue.schemaPath, path);
2674
3153
  }
2675
3154
  // Case 2: Hook variable equivalencies (new behavior)
2676
3155
  // The equivalencies are stored as: path = variable name, schemaPath = data source
@@ -2698,7 +3177,7 @@ export class ScopeDataStructure {
2698
3177
  hookCallPath = dbEntry.sourceCandidates[0].schemaPath;
2699
3178
  }
2700
3179
  }
2701
- equivalentSignatureVariables[path] = hookCallPath;
3180
+ addEquivalency(path, hookCallPath);
2702
3181
  }
2703
3182
  }
2704
3183
  // Case 3: Destructured variables from local variables
@@ -2710,10 +3189,15 @@ export class ScopeDataStructure {
2710
3189
  !equivalentValue.schemaPath.startsWith('signature[') && // not a signature path
2711
3190
  !equivalentValue.schemaPath.endsWith('.functionCallReturnValue') // not already handled above
2712
3191
  ) {
2713
- // Only add if we haven't already captured this variable in Case 1 or 2
2714
- if (!(path in equivalentSignatureVariables)) {
2715
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3192
+ // Skip bare "returnValue" from child scopes this is the child's return value,
3193
+ // not a meaningful data source path in the parent scope
3194
+ if (equivalentValue.schemaPath === 'returnValue' &&
3195
+ equivalentValue.scopeNodeName !==
3196
+ this.scopeTreeManager.getRootName()) {
3197
+ continue;
2716
3198
  }
3199
+ // Add equivalency (will accumulate if multiple values for OR expressions)
3200
+ addEquivalency(path, equivalentValue.schemaPath);
2717
3201
  }
2718
3202
  // Case 4: Child component prop mappings (Fix 22)
2719
3203
  // When parent renders <ChildComponent prop={value} />, we get equivalencies like:
@@ -2724,7 +3208,7 @@ export class ScopeDataStructure {
2724
3208
  if (path.includes('().signature[') &&
2725
3209
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable, not a function call
2726
3210
  ) {
2727
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3211
+ addEquivalency(path, equivalentValue.schemaPath);
2728
3212
  }
2729
3213
  // Case 5: Destructured function parameters (Fix 25)
2730
3214
  // When a function has destructured props: function Comp({ propA, propB }: Props)
@@ -2737,7 +3221,7 @@ export class ScopeDataStructure {
2737
3221
  if (!path.includes('.') && // path is a simple identifier (destructured prop name)
2738
3222
  equivalentValue.schemaPath.startsWith('signature[') // schemaPath IS a signature path
2739
3223
  ) {
2740
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3224
+ addEquivalency(path, equivalentValue.schemaPath);
2741
3225
  }
2742
3226
  // Case 7: Method calls on variables that result in .functionCallReturnValue (Fix 33)
2743
3227
  // When we have patterns like:
@@ -2749,8 +3233,7 @@ export class ScopeDataStructure {
2749
3233
  // segments -> useParams().functionCallReturnValue['*'].split('/').functionCallReturnValue
2750
3234
  if (!path.includes('.') && // path is a simple identifier
2751
3235
  equivalentValue.schemaPath.endsWith('.functionCallReturnValue') && // ends with function return
2752
- equivalentValue.schemaPath.includes('.') && // has property access (method call)
2753
- !(path in equivalentSignatureVariables) // not already captured
3236
+ equivalentValue.schemaPath.includes('.') // has property access (method call)
2754
3237
  ) {
2755
3238
  // Check if this looks like a method call on a variable (not a hook call)
2756
3239
  // Hook calls look like: hookName() or hookName<T>()
@@ -2761,7 +3244,7 @@ export class ScopeDataStructure {
2761
3244
  const parenPos = hookCallPath.indexOf('(');
2762
3245
  if (dotBeforeParen !== -1 && dotBeforeParen < parenPos) {
2763
3246
  // This is a method call like "splat.split('/')", not a hook call
2764
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3247
+ addEquivalency(path, equivalentValue.schemaPath);
2765
3248
  }
2766
3249
  }
2767
3250
  }
@@ -2788,8 +3271,9 @@ export class ScopeDataStructure {
2788
3271
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable
2789
3272
  ) {
2790
3273
  // Only add if not already present from the root scope
3274
+ // Root scope values take precedence over child scope values
2791
3275
  if (!(path in equivalentSignatureVariables)) {
2792
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3276
+ addEquivalency(path, equivalentValue.schemaPath);
2793
3277
  }
2794
3278
  }
2795
3279
  }
@@ -2799,9 +3283,72 @@ export class ScopeDataStructure {
2799
3283
  // E.g., analysis → currentEntityAnalysis → useLoaderData().functionCallReturnValue.currentEntityAnalysis
2800
3284
  // We need multiple passes because resolutions can depend on each other
2801
3285
  const maxIterations = 5; // Prevent infinite loops
3286
+ // Helper function to resolve a single source path using equivalencies
3287
+ const resolveSourcePath = (sourcePath, equivMap) => {
3288
+ // Extract base variable from the path
3289
+ const dotIndex = sourcePath.indexOf('.');
3290
+ const bracketIndex = sourcePath.indexOf('[');
3291
+ let baseVar;
3292
+ let rest;
3293
+ if (dotIndex === -1 && bracketIndex === -1) {
3294
+ baseVar = sourcePath;
3295
+ rest = '';
3296
+ }
3297
+ else if (dotIndex === -1) {
3298
+ baseVar = sourcePath.slice(0, bracketIndex);
3299
+ rest = sourcePath.slice(bracketIndex);
3300
+ }
3301
+ else if (bracketIndex === -1) {
3302
+ baseVar = sourcePath.slice(0, dotIndex);
3303
+ rest = sourcePath.slice(dotIndex);
3304
+ }
3305
+ else {
3306
+ const firstIndex = Math.min(dotIndex, bracketIndex);
3307
+ baseVar = sourcePath.slice(0, firstIndex);
3308
+ rest = sourcePath.slice(firstIndex);
3309
+ }
3310
+ // Look up the base variable in equivalencies
3311
+ if (baseVar in equivMap && equivMap[baseVar] !== sourcePath) {
3312
+ const baseResolved = equivMap[baseVar];
3313
+ // Skip if baseResolved is an array (handle later)
3314
+ if (Array.isArray(baseResolved))
3315
+ return null;
3316
+ // If it resolves to a signature path, build the full resolved path
3317
+ if (baseResolved.startsWith('signature[') ||
3318
+ baseResolved.includes('()')) {
3319
+ if (baseResolved.endsWith('()')) {
3320
+ return baseResolved + '.functionCallReturnValue' + rest;
3321
+ }
3322
+ return baseResolved + rest;
3323
+ }
3324
+ }
3325
+ return null;
3326
+ };
2802
3327
  for (let iteration = 0; iteration < maxIterations; iteration++) {
2803
3328
  let changed = false;
2804
- for (const [varName, sourcePath] of Object.entries(equivalentSignatureVariables)) {
3329
+ for (const [varName, sourcePathOrArray] of Object.entries(equivalentSignatureVariables)) {
3330
+ // Handle arrays (OR expressions) by resolving each element
3331
+ if (Array.isArray(sourcePathOrArray)) {
3332
+ const resolvedArray = [];
3333
+ let arrayChanged = false;
3334
+ for (const sourcePath of sourcePathOrArray) {
3335
+ // Try to resolve this path using transitive resolution
3336
+ const resolved = resolveSourcePath(sourcePath, equivalentSignatureVariables);
3337
+ if (resolved && resolved !== sourcePath) {
3338
+ resolvedArray.push(resolved);
3339
+ arrayChanged = true;
3340
+ }
3341
+ else {
3342
+ resolvedArray.push(sourcePath);
3343
+ }
3344
+ }
3345
+ if (arrayChanged) {
3346
+ equivalentSignatureVariables[varName] = resolvedArray;
3347
+ changed = true;
3348
+ }
3349
+ continue;
3350
+ }
3351
+ const sourcePath = sourcePathOrArray;
2805
3352
  // Skip if already fully resolved (contains function call syntax)
2806
3353
  // BUT first check for computed value patterns that need resolution (Fix 28)
2807
3354
  // AND method call patterns that need base variable resolution (Fix 33)
@@ -2854,6 +3401,9 @@ export class ScopeDataStructure {
2854
3401
  if (baseVar in equivalentSignatureVariables &&
2855
3402
  baseVar !== varName) {
2856
3403
  const baseResolved = equivalentSignatureVariables[baseVar];
3404
+ // Skip if baseResolved is an array (OR expression)
3405
+ if (Array.isArray(baseResolved))
3406
+ continue;
2857
3407
  // Only resolve if the base resolved to something useful (contains () or .)
2858
3408
  if (baseResolved.includes('()') || baseResolved.includes('.')) {
2859
3409
  const newPath = baseResolved + rest;
@@ -2909,7 +3459,13 @@ export class ScopeDataStructure {
2909
3459
  rest = '';
2910
3460
  }
2911
3461
  if (baseVar in equivalentSignatureVariables && baseVar !== varName) {
2912
- const baseResolved = equivalentSignatureVariables[baseVar];
3462
+ // Handle array case (OR expressions) - use first element
3463
+ const rawBaseResolved = equivalentSignatureVariables[baseVar];
3464
+ const baseResolved = Array.isArray(rawBaseResolved)
3465
+ ? rawBaseResolved[0]
3466
+ : rawBaseResolved;
3467
+ if (!baseResolved)
3468
+ continue;
2913
3469
  // If the base resolves to a hook call, add .functionCallReturnValue
2914
3470
  if (baseResolved.endsWith('()')) {
2915
3471
  const newPath = baseResolved + '.functionCallReturnValue' + rest;
@@ -3199,6 +3755,7 @@ export class ScopeDataStructure {
3199
3755
  */
3200
3756
  getEnrichedConditionalUsages() {
3201
3757
  const enriched = {};
3758
+ console.log(`[getEnrichedConditionalUsages] Processing ${Object.keys(this.rawConditionalUsages).length} conditional paths: [${Object.keys(this.rawConditionalUsages).join(', ')}]`);
3202
3759
  for (const [path, usages] of Object.entries(this.rawConditionalUsages)) {
3203
3760
  // Try to trace this path back to a data source
3204
3761
  // First, try the root scope
@@ -3206,9 +3763,47 @@ export class ScopeDataStructure {
3206
3763
  const explanation = this.explainPath(rootScopeName, path);
3207
3764
  let sourceDataPath;
3208
3765
  if (explanation.source) {
3209
- // Build the full data path: scopeName.path
3210
- sourceDataPath = `${explanation.source.scope}.${explanation.source.path}`;
3766
+ const { scope, path: sourcePath } = explanation.source;
3767
+ // Build initial path — avoid redundant prefix when path already contains the scope call
3768
+ let fullPath;
3769
+ if (sourcePath.startsWith(`${scope}(`)) {
3770
+ fullPath = sourcePath;
3771
+ }
3772
+ else {
3773
+ fullPath = `${scope}.${sourcePath}`;
3774
+ }
3775
+ sourceDataPath = fullPath;
3776
+ console.log(`[getEnrichedConditionalUsages] "${path}" explainPath → scope="${scope}", sourcePath="${sourcePath}" → sourceDataPath="${sourceDataPath}"`);
3777
+ }
3778
+ else {
3779
+ console.log(`[getEnrichedConditionalUsages] "${path}" explainPath → no source found`);
3780
+ }
3781
+ // If explainPath didn't find a useful external source (e.g., it traced to
3782
+ // useState or just to the component scope itself), check sourceEquivalencies
3783
+ // for an external function call source like a fetch call
3784
+ const hasExternalSource = sourceDataPath?.includes('.functionCallReturnValue');
3785
+ if (!hasExternalSource) {
3786
+ console.log(`[getEnrichedConditionalUsages] "${path}" no external source (sourceDataPath="${sourceDataPath}"), checking sourceEquivalencies fallback...`);
3787
+ const sourceEquiv = this.getSourceEquivalencies();
3788
+ const returnValueKey = `returnValue.${path}`;
3789
+ const sources = sourceEquiv[returnValueKey];
3790
+ if (sources) {
3791
+ console.log(`[getEnrichedConditionalUsages] "${path}" sourceEquivalencies["${returnValueKey}"] has ${sources.length} sources: [${sources.map((s) => s.schemaPath).join(', ')}]`);
3792
+ const externalSource = sources.find((s) => s.schemaPath.includes('.functionCallReturnValue') &&
3793
+ !s.schemaPath.startsWith('useState('));
3794
+ if (externalSource) {
3795
+ console.log(`[getEnrichedConditionalUsages] "${path}" sourceEquivalencies fallback found external source: "${externalSource.schemaPath}"`);
3796
+ sourceDataPath = externalSource.schemaPath;
3797
+ }
3798
+ else {
3799
+ console.log(`[getEnrichedConditionalUsages] "${path}" sourceEquivalencies fallback found no external function call source`);
3800
+ }
3801
+ }
3802
+ else {
3803
+ console.log(`[getEnrichedConditionalUsages] "${path}" sourceEquivalencies["${returnValueKey}"] not found`);
3804
+ }
3211
3805
  }
3806
+ console.log(`[getEnrichedConditionalUsages] "${path}" FINAL sourceDataPath="${sourceDataPath ?? '(none)'}" (${usages.length} usages)`);
3212
3807
  enriched[path] = usages.map((usage) => ({
3213
3808
  ...usage,
3214
3809
  sourceDataPath,
@@ -3467,11 +4062,21 @@ export class ScopeDataStructure {
3467
4062
  perVariableSchemas = undefined;
3468
4063
  }
3469
4064
  }
4065
+ // Enrich the schema with inferred types by applying fillInSchemaGapsAndUnknowns.
4066
+ // This ensures the serialized schema has the same type inference as getReturnValue().
4067
+ // Without this, evidence like "entities[].analyses: array" becomes "unknown".
4068
+ const enrichedSchema = { ...efc.schema };
4069
+ const tempScopeNode = {
4070
+ name: efc.name,
4071
+ schema: enrichedSchema,
4072
+ equivalencies: efc.equivalencies ?? {},
4073
+ };
4074
+ fillInSchemaGapsAndUnknowns(tempScopeNode, true);
3470
4075
  return {
3471
4076
  name: efc.name,
3472
4077
  callSignature: efc.callSignature,
3473
4078
  callScope: efc.callScope,
3474
- schema: efc.schema,
4079
+ schema: enrichedSchema,
3475
4080
  equivalencies: efc.equivalencies
3476
4081
  ? Object.entries(efc.equivalencies).reduce((acc, [key, vars]) => {
3477
4082
  // Clean cyScope from the key as well as variable properties