@codeyam/codeyam-cli 0.1.0-staging.323686 → 0.1.0-staging.4813bf3

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 (444) 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 +5 -5
  4. package/analyzer-template/packages/ai/index.ts +7 -1
  5. package/analyzer-template/packages/ai/package.json +2 -2
  6. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +62 -18
  7. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +67 -9
  8. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  9. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +409 -50
  10. package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
  11. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +21 -6
  12. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +992 -249
  13. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
  14. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +16 -3
  15. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +6 -4
  16. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +31 -3
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +37 -15
  18. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
  19. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +126 -11
  20. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +179 -0
  21. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.ts +40 -30
  22. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +367 -96
  23. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +33 -15
  24. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
  25. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +315 -6
  26. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +9 -5
  27. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +49 -5
  28. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
  29. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +649 -142
  30. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +1 -1
  31. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
  32. package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
  33. package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
  34. package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
  35. package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
  36. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
  37. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +25 -13
  38. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +4 -3
  39. package/analyzer-template/packages/analyze/index.ts +2 -0
  40. package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +65 -59
  41. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +113 -26
  42. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
  43. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
  44. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
  45. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
  46. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
  47. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
  48. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +89 -9
  49. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +19 -4
  50. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
  51. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +0 -3
  52. package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
  53. package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
  54. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
  55. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +61 -13
  56. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +37 -0
  57. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +229 -19
  58. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +117 -9
  59. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +459 -39
  60. package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
  61. package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
  62. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  63. package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
  64. package/analyzer-template/packages/aws/package.json +1 -1
  65. package/analyzer-template/packages/database/package.json +1 -1
  66. package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
  67. package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
  68. package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
  69. package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
  70. package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
  71. package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
  72. package/analyzer-template/packages/database/src/lib/kysely/db.ts +6 -0
  73. package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +1 -1
  74. package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
  75. package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
  76. package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
  77. package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
  78. package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
  79. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
  80. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
  81. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
  82. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
  83. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
  84. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
  85. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
  86. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
  87. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
  88. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
  89. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
  90. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
  91. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  92. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  93. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +3 -0
  94. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  95. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +1 -1
  96. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
  97. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
  98. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  99. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  100. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
  101. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
  102. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
  103. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
  104. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
  105. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
  106. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  107. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  108. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  109. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  110. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  111. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  112. package/analyzer-template/packages/github/package.json +1 -1
  113. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +7 -0
  114. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +6 -5
  115. package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
  116. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  117. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  118. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  119. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  120. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  121. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  122. package/analyzer-template/project/constructMockCode.ts +90 -10
  123. package/analyzer-template/project/writeMockDataTsx.ts +181 -8
  124. package/analyzer-template/project/writeScenarioComponents.ts +60 -12
  125. package/analyzer-template/project/writeSimpleRoot.ts +21 -11
  126. package/background/src/lib/local/createLocalAnalyzer.js +1 -1
  127. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  128. package/background/src/lib/virtualized/project/constructMockCode.js +75 -4
  129. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  130. package/background/src/lib/virtualized/project/writeMockDataTsx.js +162 -4
  131. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  132. package/background/src/lib/virtualized/project/writeScenarioComponents.js +60 -15
  133. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  134. package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
  135. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  136. package/codeyam-cli/scripts/apply-setup.js +180 -0
  137. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  138. package/codeyam-cli/src/cli.js +2 -0
  139. package/codeyam-cli/src/cli.js.map +1 -1
  140. package/codeyam-cli/src/codeyam-cli.js +18 -2
  141. package/codeyam-cli/src/codeyam-cli.js.map +1 -1
  142. package/codeyam-cli/src/commands/analyze.js +4 -2
  143. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  144. package/codeyam-cli/src/commands/baseline.js +2 -0
  145. package/codeyam-cli/src/commands/baseline.js.map +1 -1
  146. package/codeyam-cli/src/commands/debug.js +9 -5
  147. package/codeyam-cli/src/commands/debug.js.map +1 -1
  148. package/codeyam-cli/src/commands/default.js +31 -20
  149. package/codeyam-cli/src/commands/default.js.map +1 -1
  150. package/codeyam-cli/src/commands/detect-universal-mocks.js +2 -0
  151. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +1 -1
  152. package/codeyam-cli/src/commands/init.js +49 -257
  153. package/codeyam-cli/src/commands/init.js.map +1 -1
  154. package/codeyam-cli/src/commands/memory.js +17 -26
  155. package/codeyam-cli/src/commands/memory.js.map +1 -1
  156. package/codeyam-cli/src/commands/recapture.js +2 -0
  157. package/codeyam-cli/src/commands/recapture.js.map +1 -1
  158. package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
  159. package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
  160. package/codeyam-cli/src/commands/setup-simulations.js +284 -0
  161. package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
  162. package/codeyam-cli/src/commands/test-startup.js +2 -0
  163. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  164. package/codeyam-cli/src/commands/verify.js +14 -2
  165. package/codeyam-cli/src/commands/verify.js.map +1 -1
  166. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +128 -86
  167. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  168. package/codeyam-cli/src/utils/analyzer.js +7 -0
  169. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  170. package/codeyam-cli/src/utils/backgroundServer.js +5 -0
  171. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  172. package/codeyam-cli/src/utils/generateReport.js +2 -2
  173. package/codeyam-cli/src/utils/install-skills.js +70 -45
  174. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  175. package/codeyam-cli/src/utils/labsAutoCheck.js +19 -0
  176. package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
  177. package/codeyam-cli/src/utils/progress.js +7 -0
  178. package/codeyam-cli/src/utils/progress.js.map +1 -1
  179. package/codeyam-cli/src/utils/queue/job.js +4 -0
  180. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  181. package/codeyam-cli/src/utils/requireSimulations.js +10 -0
  182. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
  183. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  184. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  185. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +230 -0
  186. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  187. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  188. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  189. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  190. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  191. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  192. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  193. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  194. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  195. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +75 -0
  196. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  197. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +378 -0
  198. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  199. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +115 -0
  200. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  201. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  202. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  203. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  204. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  205. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
  206. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  207. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  208. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  209. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
  210. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  211. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  212. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  213. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  214. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  215. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  216. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  217. package/codeyam-cli/src/utils/rules/index.js +1 -0
  218. package/codeyam-cli/src/utils/rules/index.js.map +1 -1
  219. package/codeyam-cli/src/utils/rules/parser.js +2 -25
  220. package/codeyam-cli/src/utils/rules/parser.js.map +1 -1
  221. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  222. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  223. package/codeyam-cli/src/utils/rules/staleness.js +16 -11
  224. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -1
  225. package/codeyam-cli/src/utils/serverState.js +37 -10
  226. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  227. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +21 -44
  228. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  229. package/codeyam-cli/src/webserver/app/lib/database.js +15 -3
  230. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  231. package/codeyam-cli/src/webserver/backgroundServer.js +24 -0
  232. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  233. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CA3JxPb7.js +1 -0
  234. package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-DsN1wKrm.js → EntityItem-B86KKU7e.js} +1 -1
  235. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-B5ctlSYt.js} +1 -1
  236. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-BqY8gDAW.js} +1 -1
  237. package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-C8lyxW9k.js → InlineSpinner-ClaLpuOo.js} +1 -1
  238. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-BDhPilK7.js} +2 -2
  239. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-VeqEBv9v.js} +1 -1
  240. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-Bs7Nn1Jr.js} +1 -1
  241. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-Bm3PmcCz.js} +1 -1
  242. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-OApQuNyq.js → ReportIssueModal-CgMEzchJ.js} +3 -8
  243. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-Gq3Ocjo6.js} +1 -1
  244. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DzccYyI8.js → ScenarioViewer-CBui0id_.js} +2 -2
  245. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-CiwXDxLh.js} +1 -1
  246. package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-B3TDXxnk.js} +1 -1
  247. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BwavGCpm.js → activity.(_tab)-BtBFH820.js} +6 -11
  248. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-CN61MOMa.js +11 -0
  249. package/codeyam-cli/src/webserver/build/client/assets/api.agent-transcripts-l0sNRNKZ.js +1 -0
  250. package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
  251. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  252. package/codeyam-cli/src/webserver/build/client/assets/book-open-PttOB2SF.js +6 -0
  253. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-TJp6ofnp.js} +1 -1
  254. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-JE9ZIoBl.js} +12 -12
  255. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-CXhHQYrI.js} +1 -1
  256. package/codeyam-cli/src/webserver/build/client/assets/copy-6y9ALfGT.js +11 -0
  257. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-Ca9fAY46.js} +1 -1
  258. package/codeyam-cli/src/webserver/build/client/assets/{dev.empty-BBnGWYga.js → dev.empty-C0epRiVn.js} +1 -1
  259. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-BJUiQqZF.js → entity._sha._-BVnB8a9L.js} +10 -10
  260. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js → entity._sha.scenarios._scenarioId.fullscreen-CBoafmVs.js} +1 -1
  261. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-D1T4TGjf.js → entity._sha_.create-scenario-DGgZjdFg.js} +1 -1
  262. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-38yPijoD.js} +1 -1
  263. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-BSHEfydn.js} +1 -1
  264. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-DCPhhSMo.js} +1 -1
  265. package/codeyam-cli/src/webserver/build/client/assets/{files-CJ6lTdTA.js → files-0N0YJQv7.js} +1 -1
  266. package/codeyam-cli/src/webserver/build/client/assets/{git-CPTZZ-JZ.js → git-DXnyr8uP.js} +1 -1
  267. package/codeyam-cli/src/webserver/build/client/assets/globals-CKT08Djd.css +1 -0
  268. package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-CcsFv748.js} +1 -1
  269. package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-ChN9-fAY.js} +1 -1
  270. package/codeyam-cli/src/webserver/build/client/assets/labs-BLJ7HxOC.js +1 -0
  271. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-CTqLEAGU.js} +1 -1
  272. package/codeyam-cli/src/webserver/build/client/assets/manifest-b171b9d3.js +1 -0
  273. package/codeyam-cli/src/webserver/build/client/assets/memory-CCQd4aZA.js +78 -0
  274. package/codeyam-cli/src/webserver/build/client/assets/pause-D6vreykR.js +11 -0
  275. package/codeyam-cli/src/webserver/build/client/assets/root-CHhiHoo_.js +62 -0
  276. package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-B8VUL8nl.js} +1 -1
  277. package/codeyam-cli/src/webserver/build/client/assets/settings-BejnUJ6R.js +1 -0
  278. package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-CPoAg7Zo.js} +1 -1
  279. package/codeyam-cli/src/webserver/build/client/assets/terminal-BrCP7uQo.js +11 -0
  280. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-BZz2NjYa.js} +1 -1
  281. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-DNwUduNu.js} +1 -1
  282. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-aSv48UbS.js → useLastLogLine-COky1GVF.js} +1 -1
  283. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-CpZgwliL.js} +1 -1
  284. package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-Bv9JFvUO.js} +1 -1
  285. package/codeyam-cli/src/webserver/build/server/assets/{index-DVzYx8PN.js → index-8Fv-lH1-.js} +1 -1
  286. package/codeyam-cli/src/webserver/build/server/assets/server-build-Akn3iYFP.js +257 -0
  287. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  288. package/codeyam-cli/src/webserver/build-info.json +5 -5
  289. package/codeyam-cli/templates/{codeyam:debug.md → codeyam-debug.md} +1 -1
  290. package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
  291. package/codeyam-cli/templates/codeyam-memory-hook.sh +19 -20
  292. package/codeyam-cli/templates/codeyam-memory.md +392 -0
  293. package/codeyam-cli/templates/codeyam-new-rule.md +13 -0
  294. package/codeyam-cli/templates/{codeyam:setup.md → codeyam-setup.md} +13 -1
  295. package/codeyam-cli/templates/{codeyam:sim.md → codeyam-sim.md} +1 -1
  296. package/codeyam-cli/templates/{codeyam:test.md → codeyam-test.md} +1 -1
  297. package/codeyam-cli/templates/{codeyam:verify.md → codeyam-verify.md} +1 -1
  298. package/codeyam-cli/templates/rule-notification-hook.py +56 -0
  299. package/codeyam-cli/templates/rule-reflection-hook.py +627 -0
  300. package/codeyam-cli/templates/rules-instructions.md +132 -0
  301. package/package.json +2 -2
  302. package/packages/ai/index.js +3 -2
  303. package/packages/ai/index.js.map +1 -1
  304. package/packages/ai/src/lib/analyzeScope.js +50 -13
  305. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  306. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +54 -8
  307. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  308. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  309. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  310. package/packages/ai/src/lib/astScopes/processExpression.js +317 -44
  311. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  312. package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
  313. package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
  314. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +763 -171
  315. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  316. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
  317. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  318. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
  319. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
  320. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
  321. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
  322. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +33 -3
  323. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  324. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +36 -11
  325. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  326. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  327. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  328. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +113 -11
  329. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  330. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
  331. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
  332. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
  333. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
  334. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +309 -84
  335. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  336. package/packages/ai/src/lib/dataStructureChunking.js +26 -11
  337. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  338. package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
  339. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  340. package/packages/ai/src/lib/generateEntityScenarioData.js +227 -4
  341. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  342. package/packages/ai/src/lib/generateEntityScenarios.js +7 -1
  343. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  344. package/packages/ai/src/lib/generateExecutionFlows.js +26 -4
  345. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  346. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +447 -80
  347. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  348. package/packages/ai/src/lib/isolateScopes.js +39 -3
  349. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  350. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
  351. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
  352. package/packages/ai/src/lib/mergeStatements.js +70 -51
  353. package/packages/ai/src/lib/mergeStatements.js.map +1 -1
  354. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
  355. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
  356. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +10 -4
  357. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
  358. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
  359. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  360. package/packages/ai/src/lib/resolvePathToControllable.js +24 -14
  361. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
  362. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  363. package/packages/analyze/index.js +1 -0
  364. package/packages/analyze/index.js.map +1 -1
  365. package/packages/analyze/src/lib/FileAnalyzer.js +60 -36
  366. package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
  367. package/packages/analyze/src/lib/ProjectAnalyzer.js +96 -26
  368. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  369. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
  370. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
  371. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
  372. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
  373. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
  374. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
  375. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
  376. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
  377. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
  378. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
  379. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
  380. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
  381. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +65 -7
  382. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  383. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +17 -4
  384. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  385. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
  386. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  387. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +0 -3
  388. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  389. package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
  390. package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
  391. package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
  392. package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
  393. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
  394. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  395. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +56 -10
  396. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  397. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +33 -8
  398. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  399. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +150 -17
  400. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  401. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +56 -8
  402. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  403. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +399 -31
  404. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  405. package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
  406. package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
  407. package/packages/analyze/src/lib/index.js +1 -0
  408. package/packages/analyze/src/lib/index.js.map +1 -1
  409. package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
  410. package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
  411. package/packages/database/src/lib/analysisBranchToDb.js +1 -1
  412. package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
  413. package/packages/database/src/lib/analysisToDb.js +1 -1
  414. package/packages/database/src/lib/analysisToDb.js.map +1 -1
  415. package/packages/database/src/lib/branchToDb.js +1 -1
  416. package/packages/database/src/lib/branchToDb.js.map +1 -1
  417. package/packages/database/src/lib/commitBranchToDb.js +1 -1
  418. package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
  419. package/packages/database/src/lib/commitToDb.js +1 -1
  420. package/packages/database/src/lib/commitToDb.js.map +1 -1
  421. package/packages/database/src/lib/fileToDb.js +1 -1
  422. package/packages/database/src/lib/fileToDb.js.map +1 -1
  423. package/packages/database/src/lib/kysely/db.js +3 -0
  424. package/packages/database/src/lib/kysely/db.js.map +1 -1
  425. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  426. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  427. package/packages/database/src/lib/projectToDb.js +1 -1
  428. package/packages/database/src/lib/projectToDb.js.map +1 -1
  429. package/packages/database/src/lib/saveFiles.js +1 -1
  430. package/packages/database/src/lib/saveFiles.js.map +1 -1
  431. package/packages/database/src/lib/scenarioToDb.js +1 -1
  432. package/packages/database/src/lib/scenarioToDb.js.map +1 -1
  433. package/scripts/finalize-analyzer.cjs +8 -76
  434. package/codeyam-cli/src/webserver/build/client/assets/copy-Bb-80kDT.js +0 -6
  435. package/codeyam-cli/src/webserver/build/client/assets/file-code-Dhef1kWN.js +0 -6
  436. package/codeyam-cli/src/webserver/build/client/assets/globals-D3yhhV8x.css +0 -1
  437. package/codeyam-cli/src/webserver/build/client/assets/manifest-7522edd4.js +0 -1
  438. package/codeyam-cli/src/webserver/build/client/assets/memory-yxFcrxBX.js +0 -92
  439. package/codeyam-cli/src/webserver/build/client/assets/root-eVAaavTS.js +0 -62
  440. package/codeyam-cli/src/webserver/build/client/assets/settings-CS5f3WzT.js +0 -1
  441. package/codeyam-cli/src/webserver/build/server/assets/server-build-4Cr0uToj.js +0 -257
  442. package/codeyam-cli/templates/codeyam:diagnose.md +0 -803
  443. package/codeyam-cli/templates/codeyam:memory.md +0 -462
  444. package/codeyam-cli/templates/codeyam:new-rule.md +0 -13
@@ -181,6 +181,7 @@ const SILENTLY_IGNORED_EQUIVALENCY_REASONS = new Set([
181
181
  'transformed non-object function equivalency - implicit parent equivalency - rerouted via useCallback',
182
182
  'transformed non-object function equivalency - Array.from() equivalency',
183
183
  'Spread operator equivalency key update: Explicit array deconstruction equivalency value',
184
+ // 'transformed non-object function equivalency - Explicit array deconstruction equivalency value',
184
185
  ]);
185
186
  export class ScopeDataStructure {
186
187
  // Getter for backward compatibility - returns the tree structure
@@ -475,6 +476,10 @@ export class ScopeDataStructure {
475
476
  }
476
477
  return;
477
478
  }
479
+ // PERF: Early exit for paths with repeated function-call signature patterns
480
+ if (this.hasExcessivePatternRepetition(path)) {
481
+ return;
482
+ }
478
483
  // Update chain metadata for database tracking
479
484
  if (equivalencyValueChain.length > 0) {
480
485
  equivalencyValueChain[equivalencyValueChain.length - 1].addToSchemaId =
@@ -971,6 +976,12 @@ export class ScopeDataStructure {
971
976
  const value1 = scopeNode.schema[schemaPath];
972
977
  const value2 = equivalentScopeNode.schema[equivalentSchemaPath];
973
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
+ }
974
985
  scopeNode.schema[schemaPath] = bestValue;
975
986
  equivalentScopeNode.schema[equivalentSchemaPath] = bestValue;
976
987
  }
@@ -982,6 +993,10 @@ export class ScopeDataStructure {
982
993
  equivalentPath,
983
994
  ...remainingSchemaPathParts,
984
995
  ]);
996
+ // PERF: Skip paths with repeated function-call signature patterns
997
+ if (this.hasExcessivePatternRepetition(newEquivalentPath)) {
998
+ continue;
999
+ }
985
1000
  equivalentScopeNode.schema[newEquivalentPath] =
986
1001
  scopeNode.schema[schemaPath];
987
1002
  }
@@ -1063,6 +1078,23 @@ export class ScopeDataStructure {
1063
1078
  return true;
1064
1079
  }
1065
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
+ }
1066
1098
  // For longer paths, detect any repeated multi-part segments we haven't explicitly listed
1067
1099
  const pathParts = this.splitPath(path);
1068
1100
  if (pathParts.length <= 6) {
@@ -1088,21 +1120,36 @@ export class ScopeDataStructure {
1088
1120
  }
1089
1121
  setInstantiatedVariables(scopeNode) {
1090
1122
  let instantiatedVariables = scopeNode.analysis?.instantiatedVariables ?? [];
1091
- for (const [path, equivalentPath] of Object.entries(scopeNode.analysis.isolatedEquivalentVariables ?? {})) {
1092
- if (typeof equivalentPath !== 'string') {
1093
- continue;
1094
- }
1095
- if (equivalentPath.startsWith('signature[')) {
1096
- const equivalentPathParts = this.splitPath(equivalentPath);
1097
- instantiatedVariables.push(equivalentPathParts[0]);
1098
- 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
+ }
1099
1139
  }
1100
1140
  const duplicateInstantiated = instantiatedVariables.find((v) => path.split('::cyDuplicateKey')[0] === v.split('::cyDuplicateKey')[0]);
1101
1141
  if (duplicateInstantiated) {
1102
1142
  instantiatedVariables.push(path);
1103
1143
  }
1104
1144
  }
1105
- 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
+ });
1106
1153
  scopeNode.instantiatedVariables = instantiatedVariables;
1107
1154
  if (!scopeNode.tree || scopeNode.tree.length === 0) {
1108
1155
  return;
@@ -1114,9 +1161,16 @@ export class ScopeDataStructure {
1114
1161
  const parentInstantiatedVariables = [
1115
1162
  ...(parentScopeNode.parentInstantiatedVariables ?? []),
1116
1163
  ...parentScopeNode.instantiatedVariables.filter((v) => !v.startsWith('signature[') && !v.startsWith('returnValue')),
1117
- ].filter((varName, index, self) => !instantiatedVariables.includes(varName) &&
1118
- self.indexOf(varName) === index);
1119
- 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;
1120
1174
  }
1121
1175
  trackFunctionCalls(scopeNode) {
1122
1176
  this.captureFunctionCalls(scopeNode);
@@ -1127,116 +1181,136 @@ export class ScopeDataStructure {
1127
1181
  return;
1128
1182
  }
1129
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]));
1130
1186
  const allPaths = Array.from(new Set([
1131
1187
  ...Object.keys(isolatedStructure || {}),
1132
1188
  ...Object.keys(isolatedEquivalentVariables || {}),
1133
- ...Object.values(isolatedEquivalentVariables || {}),
1189
+ ...flattenedEquivValues,
1134
1190
  ]));
1135
1191
  for (let path in isolatedEquivalentVariables) {
1136
- let equivalentValue = isolatedEquivalentVariables?.[path];
1137
- if (equivalentValue && this.isValidPath(equivalentValue)) {
1138
- // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1139
- // These markers are critical for distinguishing variable reassignments.
1140
- // For example, with:
1141
- // let fetcher = useFetcher<ConfigData>();
1142
- // const configData = fetcher.data?.data;
1143
- // fetcher = useFetcher<SettingsData>();
1144
- // const settingsData = fetcher.data?.data;
1145
- //
1146
- // mergeStatements creates:
1147
- // fetcher useFetcher<ConfigData>()...
1148
- // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1149
- // configData fetcher.data.data
1150
- // settingsData → fetcher::cyDuplicateKey1::.data.data
1151
- //
1152
- // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1153
- // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1154
- path = cleanPath(path, allPaths);
1155
- equivalentValue = cleanPath(equivalentValue, allPaths);
1156
- this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
1157
- // Propagate equivalencies involving parent-scope variables to those parent scopes.
1158
- // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1159
- // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1160
- // visible when tracing from the parent scope.
1161
- const rootVariable = this.extractRootVariable(path);
1162
- const equivalentRootVariable = this.extractRootVariable(equivalentValue);
1163
- // Skip propagation for self-referential reassignment patterns like:
1164
- // x = x.method().functionCallReturnValue
1165
- // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1166
- // These create circular references since both sides reference the same variable.
1167
- //
1168
- // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1169
- // where the path has additional segments beyond the root variable.
1170
- const pathIsJustRootVariable = path === rootVariable;
1171
- const isSelfReferentialReassignment = pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1172
- if (rootVariable &&
1173
- !isSelfReferentialReassignment &&
1174
- scopeNode.parentInstantiatedVariables?.includes(rootVariable)) {
1175
- // Find the parent scope where this variable is defined
1176
- for (const parentScopeName of scopeNode.tree || []) {
1177
- const parentScope = this.scopeNodes[parentScopeName];
1178
- if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1179
- // Add the equivalency to the parent scope as well
1180
- this.addEquivalency(path, equivalentValue, scopeNode.name, // The equivalent path's scope remains the child scope
1181
- parentScope, // But store it in the parent scope's equivalencies
1182
- 'propagated parent-variable equivalency');
1183
- 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
+ }
1184
1246
  }
1185
1247
  }
1186
- }
1187
- // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1188
- // that has sub-properties defined in the isolatedEquivalentVariables.
1189
- // This handles cases like: dataItem={{ structure: completeDataStructure }}
1190
- // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1191
- // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1192
- const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
1193
- !equivalentValue.includes('functionCallReturnValue') &&
1194
- !equivalentValue.includes('.') &&
1195
- !equivalentValue.includes('[');
1196
- if (isSimpleVariable) {
1197
- // Look in current scope and all parent scopes for sub-properties
1198
- const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1199
- for (const scopeName of scopesToCheck) {
1200
- const checkScope = this.scopeNodes[scopeName];
1201
- if (!checkScope?.analysis?.isolatedEquivalentVariables)
1202
- continue;
1203
- for (const [subPath, subValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
1204
- // Check if this is a sub-property of the equivalentValue variable
1205
- // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1206
- const matchesDot = subPath.startsWith(equivalentValue + '.');
1207
- const matchesBracket = subPath.startsWith(equivalentValue + '[');
1208
- if (matchesDot || matchesBracket) {
1209
- const subPropertyPath = subPath.substring(equivalentValue.length);
1210
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1211
- const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1212
- if (newEquivalentValue &&
1213
- this.isValidPath(newEquivalentValue)) {
1214
- this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
1215
- 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
+ }
1216
1297
  }
1217
- }
1218
- // Also check if equivalentValue itself maps to a functionCallReturnValue
1219
- // e.g., result = useMemo(...).functionCallReturnValue
1220
- if (subPath === equivalentValue &&
1221
- typeof subValue === 'string' &&
1222
- subValue.endsWith('.functionCallReturnValue')) {
1223
- this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
1224
1298
  }
1225
1299
  }
1226
1300
  }
1227
- }
1228
- // Handle function call return values by propagating returnValue.* sub-properties
1229
- // from the callback scope to the usage path
1230
- if (equivalentValue.endsWith('.functionCallReturnValue')) {
1231
- this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
1232
- // Track which variable receives the return value of each function call
1233
- // This enables generating separate mock data for each call site
1234
- this.trackReceivingVariable(path, equivalentValue);
1235
- }
1236
- // Also track variables that receive destructured properties from function call return values
1237
- // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1238
- if (equivalentValue.includes('.functionCallReturnValue.')) {
1239
- 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
+ }
1240
1314
  }
1241
1315
  }
1242
1316
  }
@@ -1380,8 +1454,15 @@ export class ScopeDataStructure {
1380
1454
  const checkScope = this.scopeNodes[scopeName];
1381
1455
  if (!checkScope?.analysis?.isolatedEquivalentVariables)
1382
1456
  continue;
1383
- const functionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
1384
- 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') {
1385
1466
  callbackScopeName = functionRef.slice(0, -1);
1386
1467
  break;
1387
1468
  }
@@ -1404,22 +1485,32 @@ export class ScopeDataStructure {
1404
1485
  if (!callbackScope.analysis?.isolatedEquivalentVariables)
1405
1486
  return;
1406
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;
1407
1493
  // First, check if returnValue is an alias to another variable (e.g., returnValue = intermediate)
1408
1494
  // If so, we need to look for that variable's sub-properties too
1409
- const returnValueAlias = typeof isolatedVars.returnValue === 'string' &&
1410
- !isolatedVars.returnValue.includes('.')
1411
- ? isolatedVars.returnValue
1495
+ const returnValueAlias = typeof firstReturnValue === 'string' && !firstReturnValue.includes('.')
1496
+ ? firstReturnValue
1412
1497
  : undefined;
1413
1498
  // Pattern 3: Object.keys(X).reduce() - the reduce result has the same sub-properties as X
1414
1499
  // When returnValue = "Object.keys(source).reduce(...).functionCallReturnValue", look for source.* sub-properties
1415
1500
  let reduceSourceVar;
1416
- if (typeof isolatedVars.returnValue === 'string') {
1417
- 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$/);
1418
1503
  if (reduceMatch) {
1419
1504
  reduceSourceVar = reduceMatch[1];
1420
1505
  }
1421
1506
  }
1422
- 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
+ : [];
1423
1514
  // Check for direct returnValue.* sub-properties
1424
1515
  const isReturnValueSub = subPath.startsWith('returnValue.') ||
1425
1516
  subPath.startsWith('returnValue[');
@@ -1431,33 +1522,36 @@ export class ScopeDataStructure {
1431
1522
  const isReduceSourceSub = reduceSourceVar &&
1432
1523
  (subPath.startsWith(reduceSourceVar + '.') ||
1433
1524
  subPath.startsWith(reduceSourceVar + '['));
1434
- if (typeof subValue !== 'string' ||
1435
- (!isReturnValueSub && !isAliasSub && !isReduceSourceSub))
1525
+ if (!isReturnValueSub && !isAliasSub && !isReduceSourceSub)
1436
1526
  continue;
1437
- // Convert alias/reduceSource paths to returnValue paths
1438
- let effectiveSubPath = subPath;
1439
- if (isAliasSub && !isReturnValueSub) {
1440
- // Replace the alias prefix with returnValue
1441
- effectiveSubPath =
1442
- 'returnValue' + subPath.substring(returnValueAlias.length);
1443
- }
1444
- else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
1445
- // Replace the reduce source prefix with returnValue
1446
- effectiveSubPath =
1447
- 'returnValue' + subPath.substring(reduceSourceVar.length);
1448
- }
1449
- const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
1450
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1451
- let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1452
- // Resolve variable references through parent scope equivalencies
1453
- const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
1454
- newEquivalentValue = resolved.resolvedPath;
1455
- const equivalentScopeName = resolved.scopeName;
1456
- if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
1457
- continue;
1458
- this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
1459
- // Ensure the database entry has the usage path
1460
- 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
+ }
1461
1555
  }
1462
1556
  }
1463
1557
  /**
@@ -1489,7 +1583,14 @@ export class ScopeDataStructure {
1489
1583
  const parentScope = this.scopeNodes[parentScopeName];
1490
1584
  if (!parentScope?.analysis?.isolatedEquivalentVariables)
1491
1585
  continue;
1492
- 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');
1493
1594
  if (typeof rootEquiv === 'string') {
1494
1595
  return {
1495
1596
  resolvedPath: cleanPath(rootEquiv + restOfPath, allPaths),
@@ -1683,6 +1784,7 @@ export class ScopeDataStructure {
1683
1784
  const remainingPath = this.joinPathParts(remainingPathParts);
1684
1785
  if (relevantSubPathParts.every((part, i) => part === schemaPathParts[i]) &&
1685
1786
  equivalentValue.scopeNodeName === scopeNode.name) {
1787
+ // DEBUG
1686
1788
  continue;
1687
1789
  }
1688
1790
  const newEquivalentPath = this.joinPathParts([schemaPath, remainingPath]);
@@ -1824,6 +1926,8 @@ export class ScopeDataStructure {
1824
1926
  return;
1825
1927
  }
1826
1928
  const usageScopeNode = this.getScopeOrFunctionCallInfo(usageEquivalency.scopeNodeName);
1929
+ if (!usageScopeNode)
1930
+ continue;
1827
1931
  // Guard against infinite recursion by tracking which paths we've already
1828
1932
  // added from addComplexSourcePathVariables
1829
1933
  if (this.visitedTracker.checkAndMarkComplexSourceVisited(usageScopeNode.name, newUsageEquivalentPath)) {
@@ -1872,6 +1976,8 @@ export class ScopeDataStructure {
1872
1976
  continue;
1873
1977
  }
1874
1978
  const usageScopeNode = this.getScopeOrFunctionCallInfo(usageEquivalency.scopeNodeName);
1979
+ if (!usageScopeNode)
1980
+ continue;
1875
1981
  // This is put in place to avoid propagating array functions like 'filter' through complex equivalencies
1876
1982
  // but may cause problems if the funtion call is not on a known object (e.g. string or array)
1877
1983
  if (newUsageEquivalentPath.endsWith(')') ||
@@ -1968,9 +2074,70 @@ export class ScopeDataStructure {
1968
2074
  // Update inverted index
1969
2075
  this.intermediatesOrderIndex.set(pathId, databaseEntry);
1970
2076
  if (intermediateIndex === 0) {
1971
- const isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
2077
+ let isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
1972
2078
  pathInfo.schemaPath.includes('functionCallReturnValue');
1973
- 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)) {
1974
2141
  databaseEntry.sourceCandidates.push(pathInfo);
1975
2142
  }
1976
2143
  }
@@ -2116,6 +2283,13 @@ export class ScopeDataStructure {
2116
2283
  delete scopeNode.schema[key];
2117
2284
  }
2118
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);
2119
2293
  fillInSchemaGapsAndUnknowns(scopeNode, fillInUnknowns);
2120
2294
  if (final) {
2121
2295
  for (const manager of this.equivalencyManagers) {
@@ -2127,6 +2301,40 @@ export class ScopeDataStructure {
2127
2301
  ensureSchemaConsistency(scopeNode.schema);
2128
2302
  }
2129
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
+ }
2130
2338
  filterAndConvertSchema({ filterPath, newPath, schema, }) {
2131
2339
  const filterPathParts = this.splitPath(filterPath);
2132
2340
  return Object.keys(schema).reduce((acc, key) => {
@@ -2186,6 +2394,10 @@ export class ScopeDataStructure {
2186
2394
  path,
2187
2395
  ...this.splitPath(key).slice(equivalentValueSchemaPathParts.length),
2188
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;
2189
2401
  resolvedSchema[newKey] = value;
2190
2402
  }
2191
2403
  }
@@ -2207,6 +2419,9 @@ export class ScopeDataStructure {
2207
2419
  if (!subSchema)
2208
2420
  continue;
2209
2421
  for (const resolvedKey in subSchema) {
2422
+ // PERF: Skip keys with repeated function-call signature patterns
2423
+ if (this.hasExcessivePatternRepetition(resolvedKey))
2424
+ continue;
2210
2425
  if (!resolvedSchema[resolvedKey] ||
2211
2426
  subSchema[resolvedKey] === 'unknown') {
2212
2427
  resolvedSchema[resolvedKey] = subSchema[resolvedKey];
@@ -2380,18 +2595,204 @@ export class ScopeDataStructure {
2380
2595
  if (!scopeNode) {
2381
2596
  return {};
2382
2597
  }
2383
- const entries = this.equivalencyDatabase.filter((entry) => entry.usages.some((usage) => usage.scopeNodeName === scopeNode.name));
2384
- 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) => {
2385
2712
  var _a;
2386
2713
  if (entry.sourceCandidates.length === 0)
2387
- return acc;
2388
- const usages = entry.usages.filter((u) => u.scopeNodeName === scopeNode.name);
2714
+ return result;
2715
+ const usages = entry.usages.filter(usageMatchesScope);
2389
2716
  for (const usage of usages) {
2390
- acc[_a = usage.schemaPath] || (acc[_a] = []);
2391
- 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
+ }
2392
2723
  }
2393
- return acc;
2724
+ return result;
2394
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
+ }
2395
2796
  }
2396
2797
  getUsageEquivalencies(functionName) {
2397
2798
  const scopeNode = this.getScopeOrFunctionCallInfo(functionName);
@@ -2456,6 +2857,49 @@ export class ScopeDataStructure {
2456
2857
  }
2457
2858
  }
2458
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
+ }
2459
2903
  // Propagate nested paths from variables to their signature equivalents
2460
2904
  // e.g., if workouts = signature[0].workouts, then workouts[].title becomes
2461
2905
  // signature[0].workouts[].title
@@ -2677,13 +3121,35 @@ export class ScopeDataStructure {
2677
3121
  getEquivalentSignatureVariables() {
2678
3122
  const scopeNode = this.scopeNodes[this.scopeTreeManager.getRootName()];
2679
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
+ };
2680
3146
  for (const [path, equivalentValues] of Object.entries(scopeNode.equivalencies)) {
2681
3147
  for (const equivalentValue of equivalentValues) {
2682
3148
  // Case 1: Props/signature equivalencies (existing behavior)
2683
3149
  // Maps local variable names to their signature paths
2684
3150
  // e.g., "propValue" -> "signature[0].prop"
2685
3151
  if (path.startsWith('signature[')) {
2686
- equivalentSignatureVariables[equivalentValue.schemaPath] = path;
3152
+ addEquivalency(equivalentValue.schemaPath, path);
2687
3153
  }
2688
3154
  // Case 2: Hook variable equivalencies (new behavior)
2689
3155
  // The equivalencies are stored as: path = variable name, schemaPath = data source
@@ -2711,7 +3177,7 @@ export class ScopeDataStructure {
2711
3177
  hookCallPath = dbEntry.sourceCandidates[0].schemaPath;
2712
3178
  }
2713
3179
  }
2714
- equivalentSignatureVariables[path] = hookCallPath;
3180
+ addEquivalency(path, hookCallPath);
2715
3181
  }
2716
3182
  }
2717
3183
  // Case 3: Destructured variables from local variables
@@ -2723,10 +3189,15 @@ export class ScopeDataStructure {
2723
3189
  !equivalentValue.schemaPath.startsWith('signature[') && // not a signature path
2724
3190
  !equivalentValue.schemaPath.endsWith('.functionCallReturnValue') // not already handled above
2725
3191
  ) {
2726
- // Only add if we haven't already captured this variable in Case 1 or 2
2727
- if (!(path in equivalentSignatureVariables)) {
2728
- 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;
2729
3198
  }
3199
+ // Add equivalency (will accumulate if multiple values for OR expressions)
3200
+ addEquivalency(path, equivalentValue.schemaPath);
2730
3201
  }
2731
3202
  // Case 4: Child component prop mappings (Fix 22)
2732
3203
  // When parent renders <ChildComponent prop={value} />, we get equivalencies like:
@@ -2737,7 +3208,7 @@ export class ScopeDataStructure {
2737
3208
  if (path.includes('().signature[') &&
2738
3209
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable, not a function call
2739
3210
  ) {
2740
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3211
+ addEquivalency(path, equivalentValue.schemaPath);
2741
3212
  }
2742
3213
  // Case 5: Destructured function parameters (Fix 25)
2743
3214
  // When a function has destructured props: function Comp({ propA, propB }: Props)
@@ -2750,7 +3221,7 @@ export class ScopeDataStructure {
2750
3221
  if (!path.includes('.') && // path is a simple identifier (destructured prop name)
2751
3222
  equivalentValue.schemaPath.startsWith('signature[') // schemaPath IS a signature path
2752
3223
  ) {
2753
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3224
+ addEquivalency(path, equivalentValue.schemaPath);
2754
3225
  }
2755
3226
  // Case 7: Method calls on variables that result in .functionCallReturnValue (Fix 33)
2756
3227
  // When we have patterns like:
@@ -2762,8 +3233,7 @@ export class ScopeDataStructure {
2762
3233
  // segments -> useParams().functionCallReturnValue['*'].split('/').functionCallReturnValue
2763
3234
  if (!path.includes('.') && // path is a simple identifier
2764
3235
  equivalentValue.schemaPath.endsWith('.functionCallReturnValue') && // ends with function return
2765
- equivalentValue.schemaPath.includes('.') && // has property access (method call)
2766
- !(path in equivalentSignatureVariables) // not already captured
3236
+ equivalentValue.schemaPath.includes('.') // has property access (method call)
2767
3237
  ) {
2768
3238
  // Check if this looks like a method call on a variable (not a hook call)
2769
3239
  // Hook calls look like: hookName() or hookName<T>()
@@ -2774,7 +3244,7 @@ export class ScopeDataStructure {
2774
3244
  const parenPos = hookCallPath.indexOf('(');
2775
3245
  if (dotBeforeParen !== -1 && dotBeforeParen < parenPos) {
2776
3246
  // This is a method call like "splat.split('/')", not a hook call
2777
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3247
+ addEquivalency(path, equivalentValue.schemaPath);
2778
3248
  }
2779
3249
  }
2780
3250
  }
@@ -2801,8 +3271,9 @@ export class ScopeDataStructure {
2801
3271
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable
2802
3272
  ) {
2803
3273
  // Only add if not already present from the root scope
3274
+ // Root scope values take precedence over child scope values
2804
3275
  if (!(path in equivalentSignatureVariables)) {
2805
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3276
+ addEquivalency(path, equivalentValue.schemaPath);
2806
3277
  }
2807
3278
  }
2808
3279
  }
@@ -2812,9 +3283,72 @@ export class ScopeDataStructure {
2812
3283
  // E.g., analysis → currentEntityAnalysis → useLoaderData().functionCallReturnValue.currentEntityAnalysis
2813
3284
  // We need multiple passes because resolutions can depend on each other
2814
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
+ };
2815
3327
  for (let iteration = 0; iteration < maxIterations; iteration++) {
2816
3328
  let changed = false;
2817
- 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;
2818
3352
  // Skip if already fully resolved (contains function call syntax)
2819
3353
  // BUT first check for computed value patterns that need resolution (Fix 28)
2820
3354
  // AND method call patterns that need base variable resolution (Fix 33)
@@ -2867,6 +3401,9 @@ export class ScopeDataStructure {
2867
3401
  if (baseVar in equivalentSignatureVariables &&
2868
3402
  baseVar !== varName) {
2869
3403
  const baseResolved = equivalentSignatureVariables[baseVar];
3404
+ // Skip if baseResolved is an array (OR expression)
3405
+ if (Array.isArray(baseResolved))
3406
+ continue;
2870
3407
  // Only resolve if the base resolved to something useful (contains () or .)
2871
3408
  if (baseResolved.includes('()') || baseResolved.includes('.')) {
2872
3409
  const newPath = baseResolved + rest;
@@ -2922,7 +3459,13 @@ export class ScopeDataStructure {
2922
3459
  rest = '';
2923
3460
  }
2924
3461
  if (baseVar in equivalentSignatureVariables && baseVar !== varName) {
2925
- 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;
2926
3469
  // If the base resolves to a hook call, add .functionCallReturnValue
2927
3470
  if (baseResolved.endsWith('()')) {
2928
3471
  const newPath = baseResolved + '.functionCallReturnValue' + rest;
@@ -3212,6 +3755,7 @@ export class ScopeDataStructure {
3212
3755
  */
3213
3756
  getEnrichedConditionalUsages() {
3214
3757
  const enriched = {};
3758
+ console.log(`[getEnrichedConditionalUsages] Processing ${Object.keys(this.rawConditionalUsages).length} conditional paths: [${Object.keys(this.rawConditionalUsages).join(', ')}]`);
3215
3759
  for (const [path, usages] of Object.entries(this.rawConditionalUsages)) {
3216
3760
  // Try to trace this path back to a data source
3217
3761
  // First, try the root scope
@@ -3219,9 +3763,47 @@ export class ScopeDataStructure {
3219
3763
  const explanation = this.explainPath(rootScopeName, path);
3220
3764
  let sourceDataPath;
3221
3765
  if (explanation.source) {
3222
- // Build the full data path: scopeName.path
3223
- 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`);
3224
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
+ }
3805
+ }
3806
+ console.log(`[getEnrichedConditionalUsages] "${path}" FINAL sourceDataPath="${sourceDataPath ?? '(none)'}" (${usages.length} usages)`);
3225
3807
  enriched[path] = usages.map((usage) => ({
3226
3808
  ...usage,
3227
3809
  sourceDataPath,
@@ -3480,11 +4062,21 @@ export class ScopeDataStructure {
3480
4062
  perVariableSchemas = undefined;
3481
4063
  }
3482
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);
3483
4075
  return {
3484
4076
  name: efc.name,
3485
4077
  callSignature: efc.callSignature,
3486
4078
  callScope: efc.callScope,
3487
- schema: efc.schema,
4079
+ schema: enrichedSchema,
3488
4080
  equivalencies: efc.equivalencies
3489
4081
  ? Object.entries(efc.equivalencies).reduce((acc, [key, vars]) => {
3490
4082
  // Clean cyScope from the key as well as variable properties