@codeyam/codeyam-cli 0.1.0-staging.6e699e5 → 0.1.0-staging.79ef713

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 (437) 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 +7 -7
  4. package/analyzer-template/packages/ai/index.ts +10 -2
  5. package/analyzer-template/packages/ai/package.json +2 -2
  6. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +86 -18
  7. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +67 -9
  8. package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +41 -17
  9. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  10. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +308 -50
  11. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +15 -6
  12. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +833 -243
  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 +54 -3
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +60 -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 +80 -5
  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 +393 -97
  23. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
  24. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +283 -1
  25. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +9 -5
  26. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +11 -3
  27. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
  28. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +297 -7
  29. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +1 -1
  30. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
  31. package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
  32. package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
  33. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +25 -13
  34. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +4 -3
  35. package/analyzer-template/packages/ai/src/lib/worker/analyzeScopeWorker.ts +114 -2
  36. package/analyzer-template/packages/analyze/index.ts +2 -0
  37. package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +65 -59
  38. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +113 -26
  39. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
  40. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
  41. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
  42. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
  43. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
  44. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
  45. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +71 -9
  46. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +19 -4
  47. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +6 -0
  48. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
  49. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +0 -3
  50. package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
  51. package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
  52. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
  53. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +61 -13
  54. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +37 -0
  55. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +229 -19
  56. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +117 -9
  57. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +459 -39
  58. package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
  59. package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
  60. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  61. package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
  62. package/analyzer-template/packages/aws/package.json +1 -1
  63. package/analyzer-template/packages/database/package.json +1 -1
  64. package/analyzer-template/packages/database/src/lib/kysely/db.ts +8 -1
  65. package/analyzer-template/packages/database/src/lib/kysely/tables/commitsTable.ts +6 -0
  66. package/analyzer-template/packages/database/src/lib/loadAnalyses.ts +58 -1
  67. package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +13 -0
  68. package/analyzer-template/packages/database/src/lib/loadBranch.ts +16 -1
  69. package/analyzer-template/packages/database/src/lib/loadCommit.ts +11 -0
  70. package/analyzer-template/packages/database/src/lib/loadCommits.ts +28 -0
  71. package/analyzer-template/packages/database/src/lib/loadEntities.ts +26 -3
  72. package/analyzer-template/packages/database/src/lib/loadEntityBranches.ts +12 -0
  73. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +7 -14
  74. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  75. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +8 -1
  76. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  77. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts +1 -0
  78. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts.map +1 -1
  79. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js +3 -0
  80. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  81. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts +2 -0
  82. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts.map +1 -1
  83. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js +45 -2
  84. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js.map +1 -1
  85. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
  86. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +8 -0
  87. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
  88. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js +11 -1
  89. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js.map +1 -1
  90. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.d.ts.map +1 -1
  91. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js +7 -0
  92. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js.map +1 -1
  93. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts +3 -1
  94. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  95. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +22 -1
  96. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  97. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts +3 -1
  98. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  99. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +23 -4
  100. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  101. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.d.ts.map +1 -1
  102. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js +9 -0
  103. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js.map +1 -1
  104. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts +2 -2
  105. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  106. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +5 -4
  107. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  108. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts +2 -0
  109. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts.map +1 -1
  110. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +3 -0
  111. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  112. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  113. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  114. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  115. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  116. package/analyzer-template/packages/github/package.json +1 -1
  117. package/analyzer-template/packages/types/src/types/Commit.ts +2 -0
  118. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +1 -0
  119. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +6 -5
  120. package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
  121. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts +2 -0
  122. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts.map +1 -1
  123. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +3 -0
  124. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  125. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  126. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  127. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  128. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  129. package/analyzer-template/playwright/capture.ts +20 -8
  130. package/analyzer-template/playwright/captureStatic.ts +1 -1
  131. package/analyzer-template/project/analyzeBaselineCommit.ts +5 -0
  132. package/analyzer-template/project/analyzeRegularCommit.ts +5 -0
  133. package/analyzer-template/project/captureLibraryFunctionDirect.ts +29 -26
  134. package/analyzer-template/project/constructMockCode.ts +90 -10
  135. package/analyzer-template/project/createEntitiesAndSortFiles.ts +83 -0
  136. package/analyzer-template/project/loadReadyToBeCaptured.ts +65 -41
  137. package/analyzer-template/project/orchestrateCapture/AwsCaptureTaskRunner.ts +12 -4
  138. package/analyzer-template/project/orchestrateCapture/SequentialCaptureTaskRunner.ts +11 -6
  139. package/analyzer-template/project/orchestrateCapture/taskRunner.ts +4 -2
  140. package/analyzer-template/project/orchestrateCapture.ts +45 -6
  141. package/analyzer-template/project/start.ts +35 -11
  142. package/analyzer-template/project/writeMockDataTsx.ts +181 -8
  143. package/analyzer-template/project/writeScenarioComponents.ts +103 -12
  144. package/analyzer-template/project/writeSimpleRoot.ts +21 -11
  145. package/analyzer-template/scripts/comboWorkerLoop.cjs +98 -50
  146. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js +5 -0
  147. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js.map +1 -1
  148. package/background/src/lib/virtualized/project/analyzeRegularCommit.js +5 -0
  149. package/background/src/lib/virtualized/project/analyzeRegularCommit.js.map +1 -1
  150. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js +3 -3
  151. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js.map +1 -1
  152. package/background/src/lib/virtualized/project/constructMockCode.js +75 -4
  153. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  154. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js +73 -1
  155. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js.map +1 -1
  156. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js +19 -8
  157. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js.map +1 -1
  158. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js +2 -2
  159. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js.map +1 -1
  160. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js +4 -4
  161. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js.map +1 -1
  162. package/background/src/lib/virtualized/project/orchestrateCapture.js +38 -6
  163. package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
  164. package/background/src/lib/virtualized/project/start.js +32 -11
  165. package/background/src/lib/virtualized/project/start.js.map +1 -1
  166. package/background/src/lib/virtualized/project/writeMockDataTsx.js +162 -4
  167. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  168. package/background/src/lib/virtualized/project/writeScenarioComponents.js +85 -15
  169. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  170. package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
  171. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  172. package/codeyam-cli/scripts/apply-setup.js +180 -0
  173. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  174. package/codeyam-cli/src/cli.js +2 -0
  175. package/codeyam-cli/src/cli.js.map +1 -1
  176. package/codeyam-cli/src/commands/debug.js +7 -5
  177. package/codeyam-cli/src/commands/debug.js.map +1 -1
  178. package/codeyam-cli/src/commands/memory.js +264 -0
  179. package/codeyam-cli/src/commands/memory.js.map +1 -0
  180. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +2 -2
  181. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  182. package/codeyam-cli/src/utils/analysisRunner.js +21 -2
  183. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  184. package/codeyam-cli/src/utils/backgroundServer.js +4 -0
  185. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  186. package/codeyam-cli/src/utils/install-skills.js +55 -10
  187. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  188. package/codeyam-cli/src/utils/queue/job.js +4 -0
  189. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  190. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  191. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  192. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +230 -0
  193. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  194. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  195. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  196. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  197. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  198. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  199. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  200. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  201. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  202. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +75 -0
  203. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  204. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +285 -0
  205. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  206. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +115 -0
  207. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  208. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  209. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  210. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  211. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  212. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
  213. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  214. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  215. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  216. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
  217. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  218. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  219. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  220. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  221. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  222. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  223. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  224. package/codeyam-cli/src/utils/rules/index.js +6 -0
  225. package/codeyam-cli/src/utils/rules/index.js.map +1 -0
  226. package/codeyam-cli/src/utils/rules/parser.js +78 -0
  227. package/codeyam-cli/src/utils/rules/parser.js.map +1 -0
  228. package/codeyam-cli/src/utils/rules/pathMatcher.js +18 -0
  229. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -0
  230. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  231. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  232. package/codeyam-cli/src/utils/rules/staleness.js +137 -0
  233. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -0
  234. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +1 -1
  235. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  236. package/codeyam-cli/src/webserver/app/lib/database.js +7 -3
  237. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  238. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CA3JxPb7.js +1 -0
  239. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-B86KKU7e.js +11 -0
  240. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-B5ctlSYt.js} +1 -1
  241. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-BqY8gDAW.js} +1 -1
  242. package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-C8lyxW9k.js → InlineSpinner-ClaLpuOo.js} +1 -1
  243. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-BDhPilK7.js} +2 -2
  244. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-VeqEBv9v.js} +1 -1
  245. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-Bs7Nn1Jr.js} +1 -1
  246. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-Bm3PmcCz.js} +1 -1
  247. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-D4TZhLuw.js → ReportIssueModal-C6PKeMYR.js} +3 -13
  248. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-Gq3Ocjo6.js} +1 -1
  249. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DEx02QDa.js → ScenarioViewer-BNLaXBHR.js} +3 -3
  250. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-CiwXDxLh.js} +1 -1
  251. package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-B3TDXxnk.js} +1 -1
  252. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-DoLIqZX2.js → activity.(_tab)-BtBFH820.js} +6 -16
  253. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-DfKzxuoe.js +11 -0
  254. package/codeyam-cli/src/webserver/build/client/assets/api.memory-profile-l0sNRNKZ.js +1 -0
  255. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  256. package/codeyam-cli/src/webserver/build/client/assets/book-open-PttOB2SF.js +6 -0
  257. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-TJp6ofnp.js} +1 -1
  258. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-JE9ZIoBl.js} +12 -12
  259. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-CXhHQYrI.js} +1 -1
  260. package/codeyam-cli/src/webserver/build/client/assets/copy-6y9ALfGT.js +11 -0
  261. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-Ca9fAY46.js} +1 -1
  262. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-C5lqplTC.js +1 -0
  263. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-C2N4Op8e.js → entity._sha._-n38keI1k.js} +10 -10
  264. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js → entity._sha.scenarios._scenarioId.fullscreen-CBoafmVs.js} +1 -1
  265. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-D1T4TGjf.js → entity._sha_.create-scenario-DGgZjdFg.js} +1 -1
  266. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-38yPijoD.js} +1 -1
  267. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-BSHEfydn.js} +1 -1
  268. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-DCPhhSMo.js} +1 -1
  269. package/codeyam-cli/src/webserver/build/client/assets/files-0N0YJQv7.js +1 -0
  270. package/codeyam-cli/src/webserver/build/client/assets/{git-B4RJRvYB.js → git-DXnyr8uP.js} +8 -8
  271. package/codeyam-cli/src/webserver/build/client/assets/globals-Bh6jH0cL.css +1 -0
  272. package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-CcsFv748.js} +1 -1
  273. package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-ChN9-fAY.js} +1 -1
  274. package/codeyam-cli/src/webserver/build/client/assets/labs-CdVUfvji.js +1 -0
  275. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-CTqLEAGU.js} +1 -1
  276. package/codeyam-cli/src/webserver/build/client/assets/manifest-87319d0f.js +1 -0
  277. package/codeyam-cli/src/webserver/build/client/assets/memory-CPIDnDEj.js +76 -0
  278. package/codeyam-cli/src/webserver/build/client/assets/pause-D6vreykR.js +11 -0
  279. package/codeyam-cli/src/webserver/build/client/assets/root-D6oziHts.js +62 -0
  280. package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-B8VUL8nl.js} +1 -1
  281. package/codeyam-cli/src/webserver/build/client/assets/{settings-CS5f3WzT.js → settings-eBI36Yv5.js} +1 -1
  282. package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-CPoAg7Zo.js} +1 -1
  283. package/codeyam-cli/src/webserver/build/client/assets/terminal-BrCP7uQo.js +11 -0
  284. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-BZz2NjYa.js} +1 -1
  285. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-DNwUduNu.js} +1 -1
  286. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-aSv48UbS.js → useLastLogLine-COky1GVF.js} +1 -1
  287. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-CpZgwliL.js} +1 -1
  288. package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-Bv9JFvUO.js} +1 -1
  289. package/codeyam-cli/src/webserver/build/server/assets/index-9ox9LcrG.js +1 -0
  290. package/codeyam-cli/src/webserver/build/server/assets/server-build-Cq5Vqcob.js +260 -0
  291. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  292. package/codeyam-cli/src/webserver/build-info.json +5 -5
  293. package/codeyam-cli/templates/{codeyam-power-rules-hook.sh → codeyam-memory-hook.sh} +12 -13
  294. package/codeyam-cli/templates/codeyam:diagnose.md +178 -25
  295. package/codeyam-cli/templates/codeyam:memory.md +404 -0
  296. package/codeyam-cli/templates/codeyam:new-rule.md +2 -2
  297. package/codeyam-cli/templates/rule-notification-hook.py +56 -0
  298. package/codeyam-cli/templates/rule-reflection-hook.py +590 -0
  299. package/codeyam-cli/templates/rules-instructions.md +123 -0
  300. package/package.json +8 -6
  301. package/packages/ai/index.js +3 -2
  302. package/packages/ai/index.js.map +1 -1
  303. package/packages/ai/src/lib/analyzeScope.js +68 -13
  304. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  305. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +54 -8
  306. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  307. package/packages/ai/src/lib/astScopes/methodSemantics.js +41 -17
  308. package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
  309. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  310. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  311. package/packages/ai/src/lib/astScopes/processExpression.js +239 -43
  312. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  313. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +650 -166
  314. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  315. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
  316. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  317. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
  318. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
  319. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
  320. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
  321. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +52 -3
  322. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  323. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +55 -11
  324. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  325. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  326. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  327. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +73 -5
  328. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  329. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
  330. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
  331. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
  332. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
  333. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +333 -86
  334. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  335. package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
  336. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  337. package/packages/ai/src/lib/generateEntityScenarioData.js +205 -1
  338. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  339. package/packages/ai/src/lib/generateEntityScenarios.js +7 -1
  340. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  341. package/packages/ai/src/lib/generateExecutionFlows.js +10 -2
  342. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  343. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +209 -3
  344. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  345. package/packages/ai/src/lib/isolateScopes.js +39 -3
  346. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  347. package/packages/ai/src/lib/mergeStatements.js +70 -51
  348. package/packages/ai/src/lib/mergeStatements.js.map +1 -1
  349. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +10 -4
  350. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
  351. package/packages/ai/src/lib/resolvePathToControllable.js +24 -14
  352. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
  353. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  354. package/packages/ai/src/lib/worker/analyzeScopeWorker.js +94 -1
  355. package/packages/ai/src/lib/worker/analyzeScopeWorker.js.map +1 -1
  356. package/packages/analyze/index.js +1 -0
  357. package/packages/analyze/index.js.map +1 -1
  358. package/packages/analyze/src/lib/FileAnalyzer.js +60 -36
  359. package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
  360. package/packages/analyze/src/lib/ProjectAnalyzer.js +96 -26
  361. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  362. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
  363. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
  364. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
  365. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
  366. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
  367. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
  368. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
  369. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
  370. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
  371. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
  372. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
  373. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
  374. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +54 -6
  375. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  376. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +17 -4
  377. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  378. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +5 -0
  379. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  380. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
  381. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  382. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +0 -3
  383. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  384. package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
  385. package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
  386. package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
  387. package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
  388. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
  389. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  390. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +56 -10
  391. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  392. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +33 -8
  393. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  394. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +150 -17
  395. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  396. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +56 -8
  397. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  398. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +399 -31
  399. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  400. package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
  401. package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
  402. package/packages/analyze/src/lib/index.js +1 -0
  403. package/packages/analyze/src/lib/index.js.map +1 -1
  404. package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
  405. package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
  406. package/packages/database/src/lib/kysely/db.js +8 -1
  407. package/packages/database/src/lib/kysely/db.js.map +1 -1
  408. package/packages/database/src/lib/kysely/tables/commitsTable.js +3 -0
  409. package/packages/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  410. package/packages/database/src/lib/loadAnalyses.js +45 -2
  411. package/packages/database/src/lib/loadAnalyses.js.map +1 -1
  412. package/packages/database/src/lib/loadAnalysis.js +8 -0
  413. package/packages/database/src/lib/loadAnalysis.js.map +1 -1
  414. package/packages/database/src/lib/loadBranch.js +11 -1
  415. package/packages/database/src/lib/loadBranch.js.map +1 -1
  416. package/packages/database/src/lib/loadCommit.js +7 -0
  417. package/packages/database/src/lib/loadCommit.js.map +1 -1
  418. package/packages/database/src/lib/loadCommits.js +22 -1
  419. package/packages/database/src/lib/loadCommits.js.map +1 -1
  420. package/packages/database/src/lib/loadEntities.js +23 -4
  421. package/packages/database/src/lib/loadEntities.js.map +1 -1
  422. package/packages/database/src/lib/loadEntityBranches.js +9 -0
  423. package/packages/database/src/lib/loadEntityBranches.js.map +1 -1
  424. package/packages/database/src/lib/updateCommitMetadata.js +5 -4
  425. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  426. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-BXhEawa3.js +0 -1
  427. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BRb-0kQl.js +0 -1
  428. package/codeyam-cli/src/webserver/build/client/assets/files-Cs4MdYtv.js +0 -1
  429. package/codeyam-cli/src/webserver/build/client/assets/git-commit-horizontal-CysbcZxi.js +0 -6
  430. package/codeyam-cli/src/webserver/build/client/assets/globals-DMUaGAqV.css +0 -1
  431. package/codeyam-cli/src/webserver/build/client/assets/manifest-f874c610.js +0 -1
  432. package/codeyam-cli/src/webserver/build/client/assets/root-Bz5TunQg.js +0 -57
  433. package/codeyam-cli/src/webserver/build/client/assets/rules-hEkvVw2-.js +0 -97
  434. package/codeyam-cli/src/webserver/build/server/assets/index-967OuJoF.js +0 -1
  435. package/codeyam-cli/src/webserver/build/server/assets/server-build-DRTmerg9.js +0 -257
  436. package/codeyam-cli/templates/codeyam:power-rules.md +0 -447
  437. /package/codeyam-cli/src/webserver/build/client/assets/{api.rules-l0sNRNKZ.js → api.agent-transcripts-l0sNRNKZ.js} +0 -0
@@ -79,6 +79,8 @@
79
79
  * - `helpers/README.md` - Overview of the helper module architecture
80
80
  */
81
81
  import fillInSchemaGapsAndUnknowns from "./helpers/fillInSchemaGapsAndUnknowns.js";
82
+ import { clearCleanKnownObjectFunctionsCache } from "./helpers/cleanKnownObjectFunctions.js";
83
+ import { clearCleanNonObjectFunctionsCache } from "./helpers/cleanNonObjectFunctions.js";
82
84
  /**
83
85
  * Patterns that indicate recursive type structures in schema paths.
84
86
  * Used by hasExcessivePatternRepetition() to detect exponential path blowup.
@@ -120,6 +122,17 @@ export function resetScopeDataStructureMetrics() {
120
122
  followEquivalenciesEarlyExitPhase1Count = 0;
121
123
  followEquivalenciesWithWorkCount = 0;
122
124
  addEquivalencyCallCount = 0;
125
+ // Clear module-level caches to prevent unbounded memory growth across entities
126
+ const knownObjectCache = clearCleanKnownObjectFunctionsCache();
127
+ const nonObjectCache = clearCleanNonObjectFunctionsCache();
128
+ if (knownObjectCache.count > 0 || nonObjectCache.count > 0) {
129
+ const totalBytes = knownObjectCache.estimatedBytes + nonObjectCache.estimatedBytes;
130
+ console.log('CodeYam: Cleared analysis caches', {
131
+ knownObjectCache: `${knownObjectCache.count} entries, ${(knownObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
132
+ nonObjectCache: `${nonObjectCache.count} entries, ${(nonObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
133
+ totalKB: `${(totalBytes / 1024).toFixed(1)}KB`,
134
+ });
135
+ }
123
136
  }
124
137
  // Performance: Pre-computed Sets for equivalency reason filtering (O(1) vs O(n))
125
138
  const ALLOWED_EQUIVALENCY_REASONS = new Set([
@@ -462,6 +475,10 @@ export class ScopeDataStructure {
462
475
  }
463
476
  return;
464
477
  }
478
+ // PERF: Early exit for paths with repeated function-call signature patterns
479
+ if (this.hasExcessivePatternRepetition(path)) {
480
+ return;
481
+ }
465
482
  // Update chain metadata for database tracking
466
483
  if (equivalencyValueChain.length > 0) {
467
484
  equivalencyValueChain[equivalencyValueChain.length - 1].addToSchemaId =
@@ -958,6 +975,12 @@ export class ScopeDataStructure {
958
975
  const value1 = scopeNode.schema[schemaPath];
959
976
  const value2 = equivalentScopeNode.schema[equivalentSchemaPath];
960
977
  const bestValue = selectBestValue(value1, value2);
978
+ // PERF: Skip paths with repeated function-call signature patterns
979
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
980
+ if (this.hasExcessivePatternRepetition(schemaPath) ||
981
+ this.hasExcessivePatternRepetition(equivalentSchemaPath)) {
982
+ continue;
983
+ }
961
984
  scopeNode.schema[schemaPath] = bestValue;
962
985
  equivalentScopeNode.schema[equivalentSchemaPath] = bestValue;
963
986
  }
@@ -969,6 +992,10 @@ export class ScopeDataStructure {
969
992
  equivalentPath,
970
993
  ...remainingSchemaPathParts,
971
994
  ]);
995
+ // PERF: Skip paths with repeated function-call signature patterns
996
+ if (this.hasExcessivePatternRepetition(newEquivalentPath)) {
997
+ continue;
998
+ }
972
999
  equivalentScopeNode.schema[newEquivalentPath] =
973
1000
  scopeNode.schema[schemaPath];
974
1001
  }
@@ -1050,6 +1077,23 @@ export class ScopeDataStructure {
1050
1077
  return true;
1051
1078
  }
1052
1079
  }
1080
+ // Check for repeated function calls that indicate recursive type expansion.
1081
+ // E.g., localeCompare(b[])...localeCompare(b[]) means string.localeCompare
1082
+ // returns a type that again has localeCompare, causing infinite expansion.
1083
+ // We extract all function call patterns like "funcName(args)" and check if
1084
+ // the same normalized call appears more than once.
1085
+ const funcCallPattern = /(?:^|\.)[^.([]+\([^)]*\)/g;
1086
+ const funcCallMatches = path.match(funcCallPattern);
1087
+ if (funcCallMatches && funcCallMatches.length > 1) {
1088
+ const seen = new Set();
1089
+ for (const match of funcCallMatches) {
1090
+ // Strip leading dot and normalize array indices
1091
+ const normalized = match.replace(/^\./, '').replace(/\[\d+\]/g, '[]');
1092
+ if (seen.has(normalized))
1093
+ return true;
1094
+ seen.add(normalized);
1095
+ }
1096
+ }
1053
1097
  // For longer paths, detect any repeated multi-part segments we haven't explicitly listed
1054
1098
  const pathParts = this.splitPath(path);
1055
1099
  if (pathParts.length <= 6) {
@@ -1075,21 +1119,36 @@ export class ScopeDataStructure {
1075
1119
  }
1076
1120
  setInstantiatedVariables(scopeNode) {
1077
1121
  let instantiatedVariables = scopeNode.analysis?.instantiatedVariables ?? [];
1078
- for (const [path, equivalentPath] of Object.entries(scopeNode.analysis.isolatedEquivalentVariables ?? {})) {
1079
- if (typeof equivalentPath !== 'string') {
1080
- continue;
1081
- }
1082
- if (equivalentPath.startsWith('signature[')) {
1083
- const equivalentPathParts = this.splitPath(equivalentPath);
1084
- instantiatedVariables.push(equivalentPathParts[0]);
1085
- instantiatedVariables.push(path);
1122
+ for (const [path, rawEquivalentPath] of Object.entries(scopeNode.analysis.isolatedEquivalentVariables ?? {})) {
1123
+ // Normalize to array for consistent handling (supports both string and string[])
1124
+ const equivalentPaths = Array.isArray(rawEquivalentPath)
1125
+ ? rawEquivalentPath
1126
+ : rawEquivalentPath
1127
+ ? [rawEquivalentPath]
1128
+ : [];
1129
+ for (const equivalentPath of equivalentPaths) {
1130
+ if (typeof equivalentPath !== 'string') {
1131
+ continue;
1132
+ }
1133
+ if (equivalentPath.startsWith('signature[')) {
1134
+ const equivalentPathParts = this.splitPath(equivalentPath);
1135
+ instantiatedVariables.push(equivalentPathParts[0]);
1136
+ instantiatedVariables.push(path);
1137
+ }
1086
1138
  }
1087
1139
  const duplicateInstantiated = instantiatedVariables.find((v) => path.split('::cyDuplicateKey')[0] === v.split('::cyDuplicateKey')[0]);
1088
1140
  if (duplicateInstantiated) {
1089
1141
  instantiatedVariables.push(path);
1090
1142
  }
1091
1143
  }
1092
- instantiatedVariables = instantiatedVariables.filter((varName, index, self) => self.indexOf(varName) === index);
1144
+ const instantiatedSeen = new Set();
1145
+ instantiatedVariables = instantiatedVariables.filter((varName) => {
1146
+ if (instantiatedSeen.has(varName)) {
1147
+ return false;
1148
+ }
1149
+ instantiatedSeen.add(varName);
1150
+ return true;
1151
+ });
1093
1152
  scopeNode.instantiatedVariables = instantiatedVariables;
1094
1153
  if (!scopeNode.tree || scopeNode.tree.length === 0) {
1095
1154
  return;
@@ -1101,9 +1160,16 @@ export class ScopeDataStructure {
1101
1160
  const parentInstantiatedVariables = [
1102
1161
  ...(parentScopeNode.parentInstantiatedVariables ?? []),
1103
1162
  ...parentScopeNode.instantiatedVariables.filter((v) => !v.startsWith('signature[') && !v.startsWith('returnValue')),
1104
- ].filter((varName, index, self) => !instantiatedVariables.includes(varName) &&
1105
- self.indexOf(varName) === index);
1106
- scopeNode.parentInstantiatedVariables = parentInstantiatedVariables;
1163
+ ].filter((varName) => !instantiatedSeen.has(varName));
1164
+ const parentInstantiatedSeen = new Set();
1165
+ const dedupedParentInstantiatedVariables = parentInstantiatedVariables.filter((varName) => {
1166
+ if (parentInstantiatedSeen.has(varName)) {
1167
+ return false;
1168
+ }
1169
+ parentInstantiatedSeen.add(varName);
1170
+ return true;
1171
+ });
1172
+ scopeNode.parentInstantiatedVariables = dedupedParentInstantiatedVariables;
1107
1173
  }
1108
1174
  trackFunctionCalls(scopeNode) {
1109
1175
  this.captureFunctionCalls(scopeNode);
@@ -1114,116 +1180,136 @@ export class ScopeDataStructure {
1114
1180
  return;
1115
1181
  }
1116
1182
  const { isolatedStructure, isolatedEquivalentVariables } = scopeNode.analysis;
1183
+ // Flatten isolatedEquivalentVariables values for allPaths (handles both string and string[])
1184
+ const flattenedEquivValues = Object.values(isolatedEquivalentVariables || {}).flatMap((v) => (Array.isArray(v) ? v : [v]));
1117
1185
  const allPaths = Array.from(new Set([
1118
1186
  ...Object.keys(isolatedStructure || {}),
1119
1187
  ...Object.keys(isolatedEquivalentVariables || {}),
1120
- ...Object.values(isolatedEquivalentVariables || {}),
1188
+ ...flattenedEquivValues,
1121
1189
  ]));
1122
1190
  for (let path in isolatedEquivalentVariables) {
1123
- let equivalentValue = isolatedEquivalentVariables?.[path];
1124
- if (equivalentValue && this.isValidPath(equivalentValue)) {
1125
- // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1126
- // These markers are critical for distinguishing variable reassignments.
1127
- // For example, with:
1128
- // let fetcher = useFetcher<ConfigData>();
1129
- // const configData = fetcher.data?.data;
1130
- // fetcher = useFetcher<SettingsData>();
1131
- // const settingsData = fetcher.data?.data;
1132
- //
1133
- // mergeStatements creates:
1134
- // fetcher useFetcher<ConfigData>()...
1135
- // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1136
- // configData fetcher.data.data
1137
- // settingsData → fetcher::cyDuplicateKey1::.data.data
1138
- //
1139
- // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1140
- // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1141
- path = cleanPath(path, allPaths);
1142
- equivalentValue = cleanPath(equivalentValue, allPaths);
1143
- this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
1144
- // Propagate equivalencies involving parent-scope variables to those parent scopes.
1145
- // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1146
- // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1147
- // visible when tracing from the parent scope.
1148
- const rootVariable = this.extractRootVariable(path);
1149
- const equivalentRootVariable = this.extractRootVariable(equivalentValue);
1150
- // Skip propagation for self-referential reassignment patterns like:
1151
- // x = x.method().functionCallReturnValue
1152
- // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1153
- // These create circular references since both sides reference the same variable.
1154
- //
1155
- // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1156
- // where the path has additional segments beyond the root variable.
1157
- const pathIsJustRootVariable = path === rootVariable;
1158
- const isSelfReferentialReassignment = pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1159
- if (rootVariable &&
1160
- !isSelfReferentialReassignment &&
1161
- scopeNode.parentInstantiatedVariables?.includes(rootVariable)) {
1162
- // Find the parent scope where this variable is defined
1163
- for (const parentScopeName of scopeNode.tree || []) {
1164
- const parentScope = this.scopeNodes[parentScopeName];
1165
- if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1166
- // Add the equivalency to the parent scope as well
1167
- this.addEquivalency(path, equivalentValue, scopeNode.name, // The equivalent path's scope remains the child scope
1168
- parentScope, // But store it in the parent scope's equivalencies
1169
- 'propagated parent-variable equivalency');
1170
- break;
1191
+ const rawEquivalentValue = isolatedEquivalentVariables?.[path];
1192
+ // Normalize to array for consistent handling
1193
+ const equivalentValues = Array.isArray(rawEquivalentValue)
1194
+ ? rawEquivalentValue
1195
+ : [rawEquivalentValue];
1196
+ for (let equivalentValue of equivalentValues) {
1197
+ if (equivalentValue && this.isValidPath(equivalentValue)) {
1198
+ // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1199
+ // These markers are critical for distinguishing variable reassignments.
1200
+ // For example, with:
1201
+ // let fetcher = useFetcher<ConfigData>();
1202
+ // const configData = fetcher.data?.data;
1203
+ // fetcher = useFetcher<SettingsData>();
1204
+ // const settingsData = fetcher.data?.data;
1205
+ //
1206
+ // mergeStatements creates:
1207
+ // fetcher useFetcher<ConfigData>()...
1208
+ // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1209
+ // configData fetcher.data.data
1210
+ // settingsData fetcher::cyDuplicateKey1::.data.data
1211
+ //
1212
+ // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1213
+ // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1214
+ path = cleanPath(path, allPaths);
1215
+ equivalentValue = cleanPath(equivalentValue, allPaths);
1216
+ this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
1217
+ // Propagate equivalencies involving parent-scope variables to those parent scopes.
1218
+ // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1219
+ // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1220
+ // visible when tracing from the parent scope.
1221
+ const rootVariable = this.extractRootVariable(path);
1222
+ const equivalentRootVariable = this.extractRootVariable(equivalentValue);
1223
+ // Skip propagation for self-referential reassignment patterns like:
1224
+ // x = x.method().functionCallReturnValue
1225
+ // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1226
+ // These create circular references since both sides reference the same variable.
1227
+ //
1228
+ // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1229
+ // where the path has additional segments beyond the root variable.
1230
+ const pathIsJustRootVariable = path === rootVariable;
1231
+ const isSelfReferentialReassignment = pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1232
+ if (rootVariable &&
1233
+ !isSelfReferentialReassignment &&
1234
+ scopeNode.parentInstantiatedVariables?.includes(rootVariable)) {
1235
+ // Find the parent scope where this variable is defined
1236
+ for (const parentScopeName of scopeNode.tree || []) {
1237
+ const parentScope = this.scopeNodes[parentScopeName];
1238
+ if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1239
+ // Add the equivalency to the parent scope as well
1240
+ this.addEquivalency(path, equivalentValue, scopeNode.name, // The equivalent path's scope remains the child scope
1241
+ parentScope, // But store it in the parent scope's equivalencies
1242
+ 'propagated parent-variable equivalency');
1243
+ break;
1244
+ }
1171
1245
  }
1172
1246
  }
1173
- }
1174
- // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1175
- // that has sub-properties defined in the isolatedEquivalentVariables.
1176
- // This handles cases like: dataItem={{ structure: completeDataStructure }}
1177
- // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1178
- // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1179
- const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
1180
- !equivalentValue.includes('functionCallReturnValue') &&
1181
- !equivalentValue.includes('.') &&
1182
- !equivalentValue.includes('[');
1183
- if (isSimpleVariable) {
1184
- // Look in current scope and all parent scopes for sub-properties
1185
- const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1186
- for (const scopeName of scopesToCheck) {
1187
- const checkScope = this.scopeNodes[scopeName];
1188
- if (!checkScope?.analysis?.isolatedEquivalentVariables)
1189
- continue;
1190
- for (const [subPath, subValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
1191
- // Check if this is a sub-property of the equivalentValue variable
1192
- // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1193
- const matchesDot = subPath.startsWith(equivalentValue + '.');
1194
- const matchesBracket = subPath.startsWith(equivalentValue + '[');
1195
- if (matchesDot || matchesBracket) {
1196
- const subPropertyPath = subPath.substring(equivalentValue.length);
1197
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1198
- const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1199
- if (newEquivalentValue &&
1200
- this.isValidPath(newEquivalentValue)) {
1201
- this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
1202
- scopeNode, 'propagated sub-property equivalency');
1247
+ // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1248
+ // that has sub-properties defined in the isolatedEquivalentVariables.
1249
+ // This handles cases like: dataItem={{ structure: completeDataStructure }}
1250
+ // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1251
+ // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1252
+ const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
1253
+ !equivalentValue.includes('functionCallReturnValue') &&
1254
+ !equivalentValue.includes('.') &&
1255
+ !equivalentValue.includes('[');
1256
+ if (isSimpleVariable) {
1257
+ // Look in current scope and all parent scopes for sub-properties
1258
+ const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1259
+ for (const scopeName of scopesToCheck) {
1260
+ const checkScope = this.scopeNodes[scopeName];
1261
+ if (!checkScope?.analysis?.isolatedEquivalentVariables)
1262
+ continue;
1263
+ for (const [subPath, rawSubValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
1264
+ // Normalize to array for consistent handling
1265
+ const subValues = Array.isArray(rawSubValue)
1266
+ ? rawSubValue
1267
+ : rawSubValue
1268
+ ? [rawSubValue]
1269
+ : [];
1270
+ // Check if this is a sub-property of the equivalentValue variable
1271
+ // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1272
+ const matchesDot = subPath.startsWith(equivalentValue + '.');
1273
+ const matchesBracket = subPath.startsWith(equivalentValue + '[');
1274
+ if (matchesDot || matchesBracket) {
1275
+ const subPropertyPath = subPath.substring(equivalentValue.length);
1276
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
1277
+ for (const subValue of subValues) {
1278
+ if (typeof subValue !== 'string')
1279
+ continue;
1280
+ const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1281
+ if (newEquivalentValue &&
1282
+ this.isValidPath(newEquivalentValue)) {
1283
+ this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
1284
+ scopeNode, 'propagated sub-property equivalency');
1285
+ }
1286
+ }
1287
+ }
1288
+ // Also check if equivalentValue itself maps to a functionCallReturnValue
1289
+ // e.g., result = useMemo(...).functionCallReturnValue
1290
+ for (const subValue of subValues) {
1291
+ if (subPath === equivalentValue &&
1292
+ typeof subValue === 'string' &&
1293
+ subValue.endsWith('.functionCallReturnValue')) {
1294
+ this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
1295
+ }
1203
1296
  }
1204
- }
1205
- // Also check if equivalentValue itself maps to a functionCallReturnValue
1206
- // e.g., result = useMemo(...).functionCallReturnValue
1207
- if (subPath === equivalentValue &&
1208
- typeof subValue === 'string' &&
1209
- subValue.endsWith('.functionCallReturnValue')) {
1210
- this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
1211
1297
  }
1212
1298
  }
1213
1299
  }
1214
- }
1215
- // Handle function call return values by propagating returnValue.* sub-properties
1216
- // from the callback scope to the usage path
1217
- if (equivalentValue.endsWith('.functionCallReturnValue')) {
1218
- this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
1219
- // Track which variable receives the return value of each function call
1220
- // This enables generating separate mock data for each call site
1221
- this.trackReceivingVariable(path, equivalentValue);
1222
- }
1223
- // Also track variables that receive destructured properties from function call return values
1224
- // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1225
- if (equivalentValue.includes('.functionCallReturnValue.')) {
1226
- this.trackReceivingVariable(path, equivalentValue);
1300
+ // Handle function call return values by propagating returnValue.* sub-properties
1301
+ // from the callback scope to the usage path
1302
+ if (equivalentValue.endsWith('.functionCallReturnValue')) {
1303
+ this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
1304
+ // Track which variable receives the return value of each function call
1305
+ // This enables generating separate mock data for each call site
1306
+ this.trackReceivingVariable(path, equivalentValue);
1307
+ }
1308
+ // Also track variables that receive destructured properties from function call return values
1309
+ // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1310
+ if (equivalentValue.includes('.functionCallReturnValue.')) {
1311
+ this.trackReceivingVariable(path, equivalentValue);
1312
+ }
1227
1313
  }
1228
1314
  }
1229
1315
  }
@@ -1367,8 +1453,15 @@ export class ScopeDataStructure {
1367
1453
  const checkScope = this.scopeNodes[scopeName];
1368
1454
  if (!checkScope?.analysis?.isolatedEquivalentVariables)
1369
1455
  continue;
1370
- const functionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
1371
- if (typeof functionRef === 'string' && functionRef.endsWith('F')) {
1456
+ const rawFunctionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
1457
+ // Normalize to array and find first string ending with 'F'
1458
+ const functionRefs = Array.isArray(rawFunctionRef)
1459
+ ? rawFunctionRef
1460
+ : rawFunctionRef
1461
+ ? [rawFunctionRef]
1462
+ : [];
1463
+ const functionRef = functionRefs.find((r) => typeof r === 'string' && r.endsWith('F'));
1464
+ if (typeof functionRef === 'string') {
1372
1465
  callbackScopeName = functionRef.slice(0, -1);
1373
1466
  break;
1374
1467
  }
@@ -1391,22 +1484,32 @@ export class ScopeDataStructure {
1391
1484
  if (!callbackScope.analysis?.isolatedEquivalentVariables)
1392
1485
  return;
1393
1486
  const isolatedVars = callbackScope.analysis.isolatedEquivalentVariables;
1487
+ // Get the first returnValue equivalency (normalize array to single value for these checks)
1488
+ const rawReturnValue = isolatedVars.returnValue;
1489
+ const firstReturnValue = Array.isArray(rawReturnValue)
1490
+ ? rawReturnValue[0]
1491
+ : rawReturnValue;
1394
1492
  // First, check if returnValue is an alias to another variable (e.g., returnValue = intermediate)
1395
1493
  // If so, we need to look for that variable's sub-properties too
1396
- const returnValueAlias = typeof isolatedVars.returnValue === 'string' &&
1397
- !isolatedVars.returnValue.includes('.')
1398
- ? isolatedVars.returnValue
1494
+ const returnValueAlias = typeof firstReturnValue === 'string' && !firstReturnValue.includes('.')
1495
+ ? firstReturnValue
1399
1496
  : undefined;
1400
1497
  // Pattern 3: Object.keys(X).reduce() - the reduce result has the same sub-properties as X
1401
1498
  // When returnValue = "Object.keys(source).reduce(...).functionCallReturnValue", look for source.* sub-properties
1402
1499
  let reduceSourceVar;
1403
- if (typeof isolatedVars.returnValue === 'string') {
1404
- const reduceMatch = isolatedVars.returnValue.match(/^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/);
1500
+ if (typeof firstReturnValue === 'string') {
1501
+ const reduceMatch = firstReturnValue.match(/^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/);
1405
1502
  if (reduceMatch) {
1406
1503
  reduceSourceVar = reduceMatch[1];
1407
1504
  }
1408
1505
  }
1409
- for (const [subPath, subValue] of Object.entries(isolatedVars)) {
1506
+ for (const [subPath, rawSubValue] of Object.entries(isolatedVars)) {
1507
+ // Normalize to array for consistent handling
1508
+ const subValues = Array.isArray(rawSubValue)
1509
+ ? rawSubValue
1510
+ : rawSubValue
1511
+ ? [rawSubValue]
1512
+ : [];
1410
1513
  // Check for direct returnValue.* sub-properties
1411
1514
  const isReturnValueSub = subPath.startsWith('returnValue.') ||
1412
1515
  subPath.startsWith('returnValue[');
@@ -1418,33 +1521,36 @@ export class ScopeDataStructure {
1418
1521
  const isReduceSourceSub = reduceSourceVar &&
1419
1522
  (subPath.startsWith(reduceSourceVar + '.') ||
1420
1523
  subPath.startsWith(reduceSourceVar + '['));
1421
- if (typeof subValue !== 'string' ||
1422
- (!isReturnValueSub && !isAliasSub && !isReduceSourceSub))
1524
+ if (!isReturnValueSub && !isAliasSub && !isReduceSourceSub)
1423
1525
  continue;
1424
- // Convert alias/reduceSource paths to returnValue paths
1425
- let effectiveSubPath = subPath;
1426
- if (isAliasSub && !isReturnValueSub) {
1427
- // Replace the alias prefix with returnValue
1428
- effectiveSubPath =
1429
- 'returnValue' + subPath.substring(returnValueAlias.length);
1430
- }
1431
- else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
1432
- // Replace the reduce source prefix with returnValue
1433
- effectiveSubPath =
1434
- 'returnValue' + subPath.substring(reduceSourceVar.length);
1435
- }
1436
- const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
1437
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1438
- let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1439
- // Resolve variable references through parent scope equivalencies
1440
- const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
1441
- newEquivalentValue = resolved.resolvedPath;
1442
- const equivalentScopeName = resolved.scopeName;
1443
- if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
1444
- continue;
1445
- this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
1446
- // Ensure the database entry has the usage path
1447
- this.addUsageToEquivalencyDatabaseEntry(newPath, newEquivalentValue, equivalentScopeName, scopeNode.name);
1526
+ for (const subValue of subValues) {
1527
+ if (typeof subValue !== 'string')
1528
+ continue;
1529
+ // Convert alias/reduceSource paths to returnValue paths
1530
+ let effectiveSubPath = subPath;
1531
+ if (isAliasSub && !isReturnValueSub) {
1532
+ // Replace the alias prefix with returnValue
1533
+ effectiveSubPath =
1534
+ 'returnValue' + subPath.substring(returnValueAlias.length);
1535
+ }
1536
+ else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
1537
+ // Replace the reduce source prefix with returnValue
1538
+ effectiveSubPath =
1539
+ 'returnValue' + subPath.substring(reduceSourceVar.length);
1540
+ }
1541
+ const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
1542
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
1543
+ let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1544
+ // Resolve variable references through parent scope equivalencies
1545
+ const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
1546
+ newEquivalentValue = resolved.resolvedPath;
1547
+ const equivalentScopeName = resolved.scopeName;
1548
+ if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
1549
+ continue;
1550
+ this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
1551
+ // Ensure the database entry has the usage path
1552
+ this.addUsageToEquivalencyDatabaseEntry(newPath, newEquivalentValue, equivalentScopeName, scopeNode.name);
1553
+ }
1448
1554
  }
1449
1555
  }
1450
1556
  /**
@@ -1476,7 +1582,14 @@ export class ScopeDataStructure {
1476
1582
  const parentScope = this.scopeNodes[parentScopeName];
1477
1583
  if (!parentScope?.analysis?.isolatedEquivalentVariables)
1478
1584
  continue;
1479
- const rootEquiv = parentScope.analysis.isolatedEquivalentVariables[rootVar];
1585
+ const rawRootEquiv = parentScope.analysis.isolatedEquivalentVariables[rootVar];
1586
+ // Normalize to array and use first string value
1587
+ const rootEquivs = Array.isArray(rawRootEquiv)
1588
+ ? rawRootEquiv
1589
+ : rawRootEquiv
1590
+ ? [rawRootEquiv]
1591
+ : [];
1592
+ const rootEquiv = rootEquivs.find((r) => typeof r === 'string');
1480
1593
  if (typeof rootEquiv === 'string') {
1481
1594
  return {
1482
1595
  resolvedPath: cleanPath(rootEquiv + restOfPath, allPaths),
@@ -1670,6 +1783,7 @@ export class ScopeDataStructure {
1670
1783
  const remainingPath = this.joinPathParts(remainingPathParts);
1671
1784
  if (relevantSubPathParts.every((part, i) => part === schemaPathParts[i]) &&
1672
1785
  equivalentValue.scopeNodeName === scopeNode.name) {
1786
+ // DEBUG
1673
1787
  continue;
1674
1788
  }
1675
1789
  const newEquivalentPath = this.joinPathParts([schemaPath, remainingPath]);
@@ -1955,9 +2069,70 @@ export class ScopeDataStructure {
1955
2069
  // Update inverted index
1956
2070
  this.intermediatesOrderIndex.set(pathId, databaseEntry);
1957
2071
  if (intermediateIndex === 0) {
1958
- const isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
2072
+ let isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
1959
2073
  pathInfo.schemaPath.includes('functionCallReturnValue');
1960
- if (isValidSourceCandidate) {
2074
+ // Check if path STARTS with a spread pattern like [...var]
2075
+ // This handles cases like [...files][][0] or [...files].sort(...).functionCallReturnValue[][0]
2076
+ // where the spread source variable needs to be resolved to a signature path.
2077
+ // We do this REGARDLESS of isValidSourceCandidate because even paths containing
2078
+ // functionCallReturnValue may need spread resolution to trace back to the signature.
2079
+ const spreadMatch = pathInfo.schemaPath.match(/^\[\.\.\.(\w+)\]/);
2080
+ if (spreadMatch) {
2081
+ const spreadVar = spreadMatch[1];
2082
+ const spreadPattern = spreadMatch[0]; // The full [...var] match
2083
+ const scopeNode = this.scopeNodes[pathInfo.scopeNodeName];
2084
+ if (scopeNode?.equivalencies) {
2085
+ // Follow the equivalency chain to find a signature path
2086
+ // e.g., files (cyScope1) → files (root) → signature[0].files
2087
+ const resolveToSignature = (varName, currentScopeName, visited) => {
2088
+ const visitKey = `${currentScopeName}::${varName}`;
2089
+ if (visited.has(visitKey))
2090
+ return null;
2091
+ visited.add(visitKey);
2092
+ const currentScope = this.scopeNodes[currentScopeName];
2093
+ if (!currentScope?.equivalencies)
2094
+ return null;
2095
+ const varEquivs = currentScope.equivalencies[varName];
2096
+ if (!varEquivs)
2097
+ return null;
2098
+ // First check if any equivalency directly points to a signature path
2099
+ const signatureEquiv = varEquivs.find((eq) => eq.schemaPath.startsWith('signature['));
2100
+ if (signatureEquiv) {
2101
+ return signatureEquiv;
2102
+ }
2103
+ // Otherwise, follow the chain to other scopes
2104
+ for (const equiv of varEquivs) {
2105
+ // If the equivalency points to the same variable in a different scope,
2106
+ // follow the chain
2107
+ if (equiv.schemaPath === varName &&
2108
+ equiv.scopeNodeName !== currentScopeName) {
2109
+ const result = resolveToSignature(varName, equiv.scopeNodeName, visited);
2110
+ if (result)
2111
+ return result;
2112
+ }
2113
+ }
2114
+ return null;
2115
+ };
2116
+ const signatureEquiv = resolveToSignature(spreadVar, pathInfo.scopeNodeName, new Set());
2117
+ if (signatureEquiv) {
2118
+ // Replace ONLY the [...var] part with the resolved signature path
2119
+ // This preserves any suffix like .sort(...).functionCallReturnValue[][0]
2120
+ const resolvedPath = pathInfo.schemaPath.replace(spreadPattern, signatureEquiv.schemaPath);
2121
+ // Add the resolved path as a source candidate
2122
+ if (!databaseEntry.sourceCandidates.some((sc) => sc.schemaPath === resolvedPath &&
2123
+ sc.scopeNodeName === pathInfo.scopeNodeName)) {
2124
+ databaseEntry.sourceCandidates.push({
2125
+ scopeNodeName: pathInfo.scopeNodeName,
2126
+ schemaPath: resolvedPath,
2127
+ });
2128
+ }
2129
+ isValidSourceCandidate = true;
2130
+ }
2131
+ }
2132
+ }
2133
+ if (isValidSourceCandidate &&
2134
+ !databaseEntry.sourceCandidates.some((sc) => sc.schemaPath === pathInfo.schemaPath &&
2135
+ sc.scopeNodeName === pathInfo.scopeNodeName)) {
1961
2136
  databaseEntry.sourceCandidates.push(pathInfo);
1962
2137
  }
1963
2138
  }
@@ -2103,6 +2278,13 @@ export class ScopeDataStructure {
2103
2278
  delete scopeNode.schema[key];
2104
2279
  }
2105
2280
  }
2281
+ // Ensure parameter-to-signature equivalencies are fully propagated.
2282
+ // When a parameter variable (e.g., `node`) is equivalenced to `signature[N]`,
2283
+ // all sub-paths of that variable should also appear under `signature[N]`.
2284
+ // This handles cases where the sub-path was added to the schema via a propagation
2285
+ // chain that already included the variable↔signature equivalency, causing the
2286
+ // cycle detection to prevent the reverse mapping.
2287
+ this.propagateParameterToSignaturePaths(scopeNode);
2106
2288
  fillInSchemaGapsAndUnknowns(scopeNode, fillInUnknowns);
2107
2289
  if (final) {
2108
2290
  for (const manager of this.equivalencyManagers) {
@@ -2114,6 +2296,40 @@ export class ScopeDataStructure {
2114
2296
  ensureSchemaConsistency(scopeNode.schema);
2115
2297
  }
2116
2298
  }
2299
+ /**
2300
+ * For each equivalency where a simple variable maps to signature[N],
2301
+ * ensure all sub-paths of that variable are reflected under signature[N].
2302
+ */
2303
+ propagateParameterToSignaturePaths(scopeNode) {
2304
+ // Find variable → signature[N] equivalencies
2305
+ for (const [varName, equivalencies] of Object.entries(scopeNode.equivalencies)) {
2306
+ // Only process simple variable names (no dots, brackets, or parens)
2307
+ if (varName.includes('.') ||
2308
+ varName.includes('[') ||
2309
+ varName.includes('(')) {
2310
+ continue;
2311
+ }
2312
+ for (const equiv of equivalencies) {
2313
+ if (equiv.scopeNodeName === scopeNode.name &&
2314
+ equiv.schemaPath.startsWith('signature[')) {
2315
+ const signaturePath = equiv.schemaPath;
2316
+ const varPrefix = varName + '.';
2317
+ const varBracketPrefix = varName + '[';
2318
+ // Find all schema keys starting with the variable
2319
+ for (const key in scopeNode.schema) {
2320
+ if (key.startsWith(varPrefix) || key.startsWith(varBracketPrefix)) {
2321
+ const suffix = key.slice(varName.length);
2322
+ const sigKey = signaturePath + suffix;
2323
+ // Only add if the signature path doesn't already exist
2324
+ if (!scopeNode.schema[sigKey]) {
2325
+ scopeNode.schema[sigKey] = scopeNode.schema[key];
2326
+ }
2327
+ }
2328
+ }
2329
+ }
2330
+ }
2331
+ }
2332
+ }
2117
2333
  filterAndConvertSchema({ filterPath, newPath, schema, }) {
2118
2334
  const filterPathParts = this.splitPath(filterPath);
2119
2335
  return Object.keys(schema).reduce((acc, key) => {
@@ -2173,6 +2389,10 @@ export class ScopeDataStructure {
2173
2389
  path,
2174
2390
  ...this.splitPath(key).slice(equivalentValueSchemaPathParts.length),
2175
2391
  ]);
2392
+ // PERF: Skip keys with repeated function-call signature patterns
2393
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
2394
+ if (this.hasExcessivePatternRepetition(newKey))
2395
+ continue;
2176
2396
  resolvedSchema[newKey] = value;
2177
2397
  }
2178
2398
  }
@@ -2194,6 +2414,9 @@ export class ScopeDataStructure {
2194
2414
  if (!subSchema)
2195
2415
  continue;
2196
2416
  for (const resolvedKey in subSchema) {
2417
+ // PERF: Skip keys with repeated function-call signature patterns
2418
+ if (this.hasExcessivePatternRepetition(resolvedKey))
2419
+ continue;
2197
2420
  if (!resolvedSchema[resolvedKey] ||
2198
2421
  subSchema[resolvedKey] === 'unknown') {
2199
2422
  resolvedSchema[resolvedKey] = subSchema[resolvedKey];
@@ -2367,15 +2590,131 @@ export class ScopeDataStructure {
2367
2590
  if (!scopeNode) {
2368
2591
  return {};
2369
2592
  }
2370
- const entries = this.equivalencyDatabase.filter((entry) => entry.usages.some((usage) => usage.scopeNodeName === scopeNode.name));
2593
+ // Collect all descendant scope names (including the scope itself)
2594
+ // This ensures we include external calls from nested scopes like cyScope2
2595
+ const getAllDescendantScopeNames = (node) => {
2596
+ const names = new Set([node.name]);
2597
+ for (const child of node.children) {
2598
+ for (const name of getAllDescendantScopeNames(child)) {
2599
+ names.add(name);
2600
+ }
2601
+ }
2602
+ return names;
2603
+ };
2604
+ const treeNode = this.scopeTreeManager.findNode(scopeNode.name);
2605
+ const descendantScopeNames = treeNode
2606
+ ? getAllDescendantScopeNames(treeNode)
2607
+ : new Set([scopeNode.name]);
2608
+ // Get all external function calls made from this scope or any descendant scope
2609
+ // This allows us to include prop equivalencies from JSX components
2610
+ // that were rendered in nested scopes (e.g., FileTableRow called from cyScope2)
2611
+ const externalCallsFromScope = this.externalFunctionCalls.filter((efc) => descendantScopeNames.has(efc.callScope));
2612
+ const externalCallNames = new Set(externalCallsFromScope.map((efc) => efc.name));
2613
+ // Helper to check if a usage belongs to this scope (directly, via descendant, or via external call)
2614
+ const usageMatchesScope = (usage) => descendantScopeNames.has(usage.scopeNodeName) ||
2615
+ externalCallNames.has(usage.scopeNodeName);
2616
+ const entries = this.equivalencyDatabase.filter((entry) => entry.usages.some(usageMatchesScope));
2617
+ // Helper to resolve a source candidate through equivalency chains to find signature paths
2618
+ const resolveToSignature = (source, visited) => {
2619
+ const visitKey = `${source.scopeNodeName}::${source.schemaPath}`;
2620
+ if (visited.has(visitKey))
2621
+ return [];
2622
+ visited.add(visitKey);
2623
+ // If already a signature path, return as-is
2624
+ if (source.schemaPath.startsWith('signature[')) {
2625
+ return [source];
2626
+ }
2627
+ const currentScope = this.scopeNodes[source.scopeNodeName];
2628
+ if (!currentScope?.equivalencies)
2629
+ return [source];
2630
+ // Check for direct equivalencies FIRST (full path match)
2631
+ // This ensures paths like "useMemo(...).functionCallReturnValue" follow to "cyScope1::returnValue"
2632
+ // before prefix matching tries "useMemo(...)" which goes to the useMemo scope
2633
+ const directEquivs = currentScope.equivalencies[source.schemaPath];
2634
+ if (directEquivs?.length > 0) {
2635
+ const results = [];
2636
+ for (const equiv of directEquivs) {
2637
+ const resolved = resolveToSignature({
2638
+ scopeNodeName: equiv.scopeNodeName,
2639
+ schemaPath: equiv.schemaPath,
2640
+ }, visited);
2641
+ results.push(...resolved);
2642
+ }
2643
+ if (results.length > 0)
2644
+ return results;
2645
+ }
2646
+ // Handle spread patterns like [...items].sort().functionCallReturnValue
2647
+ // Extract the spread variable and resolve it through the equivalency chain
2648
+ const spreadMatch = source.schemaPath.match(/^\[\.\.\.(\w+)\]/);
2649
+ if (spreadMatch) {
2650
+ const spreadVar = spreadMatch[1];
2651
+ const spreadPattern = spreadMatch[0];
2652
+ const varEquivs = currentScope.equivalencies[spreadVar];
2653
+ if (varEquivs?.length > 0) {
2654
+ const results = [];
2655
+ for (const equiv of varEquivs) {
2656
+ // Follow the variable equivalency and then resolve from there
2657
+ const resolvedVar = resolveToSignature({
2658
+ scopeNodeName: equiv.scopeNodeName,
2659
+ schemaPath: equiv.schemaPath,
2660
+ }, visited);
2661
+ // For each resolved variable path, create the full path with array element suffix
2662
+ for (const rv of resolvedVar) {
2663
+ if (rv.schemaPath.startsWith('signature[')) {
2664
+ // Get the suffix after the spread pattern
2665
+ let suffix = source.schemaPath.slice(spreadPattern.length);
2666
+ // Clean the suffix: strip array method chains like .sort(...).functionCallReturnValue[]
2667
+ // These don't change the data identity, just transform it.
2668
+ // Keep only the final element access parts like [0], [1], etc.
2669
+ // Pattern: strip everything from a method call up through functionCallReturnValue[]
2670
+ suffix = suffix.replace(/\.\w+\([^)]*\)\.functionCallReturnValue\[\]/g, '');
2671
+ // Also handle simpler case without nested parens
2672
+ suffix = suffix.replace(/\.sort\(\w*\(\)\)\.functionCallReturnValue\[\]/g, '');
2673
+ // Add [] to indicate array element access from the spread
2674
+ const resolvedPath = rv.schemaPath + '[]' + suffix;
2675
+ results.push({
2676
+ scopeNodeName: rv.scopeNodeName,
2677
+ schemaPath: resolvedPath,
2678
+ });
2679
+ }
2680
+ }
2681
+ }
2682
+ if (results.length > 0)
2683
+ return results;
2684
+ }
2685
+ }
2686
+ // Try to find prefix equivalencies that can resolve this path
2687
+ // For path like "cyScope3().signature[0][0]", check "cyScope3().signature[0]", etc.
2688
+ const pathParts = this.splitPath(source.schemaPath);
2689
+ for (let i = pathParts.length - 1; i > 0; i--) {
2690
+ const prefix = this.joinPathParts(pathParts.slice(0, i));
2691
+ const suffix = this.joinPathParts(pathParts.slice(i));
2692
+ const prefixEquivs = currentScope.equivalencies[prefix];
2693
+ if (prefixEquivs?.length > 0) {
2694
+ const results = [];
2695
+ for (const equiv of prefixEquivs) {
2696
+ const newPath = this.joinPathParts([equiv.schemaPath, suffix]);
2697
+ const resolved = resolveToSignature({ scopeNodeName: equiv.scopeNodeName, schemaPath: newPath }, visited);
2698
+ results.push(...resolved);
2699
+ }
2700
+ if (results.length > 0)
2701
+ return results;
2702
+ }
2703
+ }
2704
+ return [source];
2705
+ };
2371
2706
  return entries.reduce((acc, entry) => {
2372
2707
  var _a;
2373
2708
  if (entry.sourceCandidates.length === 0)
2374
2709
  return acc;
2375
- const usages = entry.usages.filter((u) => u.scopeNodeName === scopeNode.name);
2710
+ const usages = entry.usages.filter(usageMatchesScope);
2376
2711
  for (const usage of usages) {
2377
2712
  acc[_a = usage.schemaPath] || (acc[_a] = []);
2378
- acc[usage.schemaPath].push(...entry.sourceCandidates);
2713
+ // Resolve each source candidate through the equivalency chain
2714
+ for (const source of entry.sourceCandidates) {
2715
+ const resolvedSources = resolveToSignature(source, new Set());
2716
+ acc[usage.schemaPath].push(...resolvedSources);
2717
+ }
2379
2718
  }
2380
2719
  return acc;
2381
2720
  }, {});
@@ -2443,6 +2782,49 @@ export class ScopeDataStructure {
2443
2782
  }
2444
2783
  }
2445
2784
  }
2785
+ // Enrich schema with deeply nested paths from internal function call scopes.
2786
+ // When a function call like traverse(tree) exists, and traverse's scope has
2787
+ // signature[0].children[path][entityName] (from propagateParameterToSignaturePaths),
2788
+ // we need to map those paths back to the argument variable (tree) in this scope.
2789
+ // This handles cases where cycle detection prevented the equivalency chain from
2790
+ // propagating deep paths during Phase 2 batch queue processing.
2791
+ for (const equivalenceKey in equivalencies ?? {}) {
2792
+ // Look for keys matching function call pattern: funcName(...).signature[N]
2793
+ const funcCallMatch = equivalenceKey.match(/^([^(]+)\(.*?\)\.(signature\[\d+\])$/);
2794
+ if (!funcCallMatch)
2795
+ continue;
2796
+ const calledFunctionName = funcCallMatch[1];
2797
+ const signatureParam = funcCallMatch[2]; // e.g., "signature[0]"
2798
+ for (const equivalenceValue of equivalencies[equivalenceKey]) {
2799
+ if (equivalenceValue.scopeNodeName !== scopeName)
2800
+ continue;
2801
+ const targetVariable = equivalenceValue.schemaPath;
2802
+ // Get the called function's schema (includes propagated parameter paths)
2803
+ const childSchema = this.getSchema({
2804
+ scopeName: calledFunctionName,
2805
+ });
2806
+ if (!childSchema)
2807
+ continue;
2808
+ // Map child function's signature paths to parent variable paths
2809
+ const sigPrefix = signatureParam + '.';
2810
+ const sigBracketPrefix = signatureParam + '[';
2811
+ for (const childKey in childSchema) {
2812
+ let suffix = null;
2813
+ if (childKey.startsWith(sigPrefix)) {
2814
+ suffix = childKey.slice(signatureParam.length);
2815
+ }
2816
+ else if (childKey.startsWith(sigBracketPrefix)) {
2817
+ suffix = childKey.slice(signatureParam.length);
2818
+ }
2819
+ if (suffix !== null) {
2820
+ const parentKey = targetVariable + suffix;
2821
+ if (!schema[parentKey]) {
2822
+ schema[parentKey] = childSchema[childKey];
2823
+ }
2824
+ }
2825
+ }
2826
+ }
2827
+ }
2446
2828
  // Propagate nested paths from variables to their signature equivalents
2447
2829
  // e.g., if workouts = signature[0].workouts, then workouts[].title becomes
2448
2830
  // signature[0].workouts[].title
@@ -2664,13 +3046,35 @@ export class ScopeDataStructure {
2664
3046
  getEquivalentSignatureVariables() {
2665
3047
  const scopeNode = this.scopeNodes[this.scopeTreeManager.getRootName()];
2666
3048
  const equivalentSignatureVariables = {};
3049
+ // Helper to add equivalencies - accumulates into array if multiple values for same key
3050
+ // This is critical for OR expressions like `x = a || b` where x should map to both a and b
3051
+ const addEquivalency = (key, value) => {
3052
+ const existing = equivalentSignatureVariables[key];
3053
+ if (existing === undefined) {
3054
+ // First value - store as string
3055
+ equivalentSignatureVariables[key] = value;
3056
+ }
3057
+ else if (typeof existing === 'string') {
3058
+ if (existing !== value) {
3059
+ // Second different value - convert to array
3060
+ equivalentSignatureVariables[key] = [existing, value];
3061
+ }
3062
+ // Same value - no change needed
3063
+ }
3064
+ else {
3065
+ // Already an array - add if not already present
3066
+ if (!existing.includes(value)) {
3067
+ existing.push(value);
3068
+ }
3069
+ }
3070
+ };
2667
3071
  for (const [path, equivalentValues] of Object.entries(scopeNode.equivalencies)) {
2668
3072
  for (const equivalentValue of equivalentValues) {
2669
3073
  // Case 1: Props/signature equivalencies (existing behavior)
2670
3074
  // Maps local variable names to their signature paths
2671
3075
  // e.g., "propValue" -> "signature[0].prop"
2672
3076
  if (path.startsWith('signature[')) {
2673
- equivalentSignatureVariables[equivalentValue.schemaPath] = path;
3077
+ addEquivalency(equivalentValue.schemaPath, path);
2674
3078
  }
2675
3079
  // Case 2: Hook variable equivalencies (new behavior)
2676
3080
  // The equivalencies are stored as: path = variable name, schemaPath = data source
@@ -2698,7 +3102,7 @@ export class ScopeDataStructure {
2698
3102
  hookCallPath = dbEntry.sourceCandidates[0].schemaPath;
2699
3103
  }
2700
3104
  }
2701
- equivalentSignatureVariables[path] = hookCallPath;
3105
+ addEquivalency(path, hookCallPath);
2702
3106
  }
2703
3107
  }
2704
3108
  // Case 3: Destructured variables from local variables
@@ -2710,10 +3114,8 @@ export class ScopeDataStructure {
2710
3114
  !equivalentValue.schemaPath.startsWith('signature[') && // not a signature path
2711
3115
  !equivalentValue.schemaPath.endsWith('.functionCallReturnValue') // not already handled above
2712
3116
  ) {
2713
- // Only add if we haven't already captured this variable in Case 1 or 2
2714
- if (!(path in equivalentSignatureVariables)) {
2715
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
2716
- }
3117
+ // Add equivalency (will accumulate if multiple values for OR expressions)
3118
+ addEquivalency(path, equivalentValue.schemaPath);
2717
3119
  }
2718
3120
  // Case 4: Child component prop mappings (Fix 22)
2719
3121
  // When parent renders <ChildComponent prop={value} />, we get equivalencies like:
@@ -2724,7 +3126,7 @@ export class ScopeDataStructure {
2724
3126
  if (path.includes('().signature[') &&
2725
3127
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable, not a function call
2726
3128
  ) {
2727
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3129
+ addEquivalency(path, equivalentValue.schemaPath);
2728
3130
  }
2729
3131
  // Case 5: Destructured function parameters (Fix 25)
2730
3132
  // When a function has destructured props: function Comp({ propA, propB }: Props)
@@ -2737,7 +3139,7 @@ export class ScopeDataStructure {
2737
3139
  if (!path.includes('.') && // path is a simple identifier (destructured prop name)
2738
3140
  equivalentValue.schemaPath.startsWith('signature[') // schemaPath IS a signature path
2739
3141
  ) {
2740
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3142
+ addEquivalency(path, equivalentValue.schemaPath);
2741
3143
  }
2742
3144
  // Case 7: Method calls on variables that result in .functionCallReturnValue (Fix 33)
2743
3145
  // When we have patterns like:
@@ -2749,8 +3151,7 @@ export class ScopeDataStructure {
2749
3151
  // segments -> useParams().functionCallReturnValue['*'].split('/').functionCallReturnValue
2750
3152
  if (!path.includes('.') && // path is a simple identifier
2751
3153
  equivalentValue.schemaPath.endsWith('.functionCallReturnValue') && // ends with function return
2752
- equivalentValue.schemaPath.includes('.') && // has property access (method call)
2753
- !(path in equivalentSignatureVariables) // not already captured
3154
+ equivalentValue.schemaPath.includes('.') // has property access (method call)
2754
3155
  ) {
2755
3156
  // Check if this looks like a method call on a variable (not a hook call)
2756
3157
  // Hook calls look like: hookName() or hookName<T>()
@@ -2761,7 +3162,7 @@ export class ScopeDataStructure {
2761
3162
  const parenPos = hookCallPath.indexOf('(');
2762
3163
  if (dotBeforeParen !== -1 && dotBeforeParen < parenPos) {
2763
3164
  // This is a method call like "splat.split('/')", not a hook call
2764
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3165
+ addEquivalency(path, equivalentValue.schemaPath);
2765
3166
  }
2766
3167
  }
2767
3168
  }
@@ -2788,8 +3189,9 @@ export class ScopeDataStructure {
2788
3189
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable
2789
3190
  ) {
2790
3191
  // Only add if not already present from the root scope
3192
+ // Root scope values take precedence over child scope values
2791
3193
  if (!(path in equivalentSignatureVariables)) {
2792
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
3194
+ addEquivalency(path, equivalentValue.schemaPath);
2793
3195
  }
2794
3196
  }
2795
3197
  }
@@ -2799,9 +3201,72 @@ export class ScopeDataStructure {
2799
3201
  // E.g., analysis → currentEntityAnalysis → useLoaderData().functionCallReturnValue.currentEntityAnalysis
2800
3202
  // We need multiple passes because resolutions can depend on each other
2801
3203
  const maxIterations = 5; // Prevent infinite loops
3204
+ // Helper function to resolve a single source path using equivalencies
3205
+ const resolveSourcePath = (sourcePath, equivMap) => {
3206
+ // Extract base variable from the path
3207
+ const dotIndex = sourcePath.indexOf('.');
3208
+ const bracketIndex = sourcePath.indexOf('[');
3209
+ let baseVar;
3210
+ let rest;
3211
+ if (dotIndex === -1 && bracketIndex === -1) {
3212
+ baseVar = sourcePath;
3213
+ rest = '';
3214
+ }
3215
+ else if (dotIndex === -1) {
3216
+ baseVar = sourcePath.slice(0, bracketIndex);
3217
+ rest = sourcePath.slice(bracketIndex);
3218
+ }
3219
+ else if (bracketIndex === -1) {
3220
+ baseVar = sourcePath.slice(0, dotIndex);
3221
+ rest = sourcePath.slice(dotIndex);
3222
+ }
3223
+ else {
3224
+ const firstIndex = Math.min(dotIndex, bracketIndex);
3225
+ baseVar = sourcePath.slice(0, firstIndex);
3226
+ rest = sourcePath.slice(firstIndex);
3227
+ }
3228
+ // Look up the base variable in equivalencies
3229
+ if (baseVar in equivMap && equivMap[baseVar] !== sourcePath) {
3230
+ const baseResolved = equivMap[baseVar];
3231
+ // Skip if baseResolved is an array (handle later)
3232
+ if (Array.isArray(baseResolved))
3233
+ return null;
3234
+ // If it resolves to a signature path, build the full resolved path
3235
+ if (baseResolved.startsWith('signature[') ||
3236
+ baseResolved.includes('()')) {
3237
+ if (baseResolved.endsWith('()')) {
3238
+ return baseResolved + '.functionCallReturnValue' + rest;
3239
+ }
3240
+ return baseResolved + rest;
3241
+ }
3242
+ }
3243
+ return null;
3244
+ };
2802
3245
  for (let iteration = 0; iteration < maxIterations; iteration++) {
2803
3246
  let changed = false;
2804
- for (const [varName, sourcePath] of Object.entries(equivalentSignatureVariables)) {
3247
+ for (const [varName, sourcePathOrArray] of Object.entries(equivalentSignatureVariables)) {
3248
+ // Handle arrays (OR expressions) by resolving each element
3249
+ if (Array.isArray(sourcePathOrArray)) {
3250
+ const resolvedArray = [];
3251
+ let arrayChanged = false;
3252
+ for (const sourcePath of sourcePathOrArray) {
3253
+ // Try to resolve this path using transitive resolution
3254
+ const resolved = resolveSourcePath(sourcePath, equivalentSignatureVariables);
3255
+ if (resolved && resolved !== sourcePath) {
3256
+ resolvedArray.push(resolved);
3257
+ arrayChanged = true;
3258
+ }
3259
+ else {
3260
+ resolvedArray.push(sourcePath);
3261
+ }
3262
+ }
3263
+ if (arrayChanged) {
3264
+ equivalentSignatureVariables[varName] = resolvedArray;
3265
+ changed = true;
3266
+ }
3267
+ continue;
3268
+ }
3269
+ const sourcePath = sourcePathOrArray;
2805
3270
  // Skip if already fully resolved (contains function call syntax)
2806
3271
  // BUT first check for computed value patterns that need resolution (Fix 28)
2807
3272
  // AND method call patterns that need base variable resolution (Fix 33)
@@ -2854,6 +3319,9 @@ export class ScopeDataStructure {
2854
3319
  if (baseVar in equivalentSignatureVariables &&
2855
3320
  baseVar !== varName) {
2856
3321
  const baseResolved = equivalentSignatureVariables[baseVar];
3322
+ // Skip if baseResolved is an array (OR expression)
3323
+ if (Array.isArray(baseResolved))
3324
+ continue;
2857
3325
  // Only resolve if the base resolved to something useful (contains () or .)
2858
3326
  if (baseResolved.includes('()') || baseResolved.includes('.')) {
2859
3327
  const newPath = baseResolved + rest;
@@ -2909,7 +3377,13 @@ export class ScopeDataStructure {
2909
3377
  rest = '';
2910
3378
  }
2911
3379
  if (baseVar in equivalentSignatureVariables && baseVar !== varName) {
2912
- const baseResolved = equivalentSignatureVariables[baseVar];
3380
+ // Handle array case (OR expressions) - use first element
3381
+ const rawBaseResolved = equivalentSignatureVariables[baseVar];
3382
+ const baseResolved = Array.isArray(rawBaseResolved)
3383
+ ? rawBaseResolved[0]
3384
+ : rawBaseResolved;
3385
+ if (!baseResolved)
3386
+ continue;
2913
3387
  // If the base resolves to a hook call, add .functionCallReturnValue
2914
3388
  if (baseResolved.endsWith('()')) {
2915
3389
  const newPath = baseResolved + '.functionCallReturnValue' + rest;
@@ -3467,11 +3941,21 @@ export class ScopeDataStructure {
3467
3941
  perVariableSchemas = undefined;
3468
3942
  }
3469
3943
  }
3944
+ // Enrich the schema with inferred types by applying fillInSchemaGapsAndUnknowns.
3945
+ // This ensures the serialized schema has the same type inference as getReturnValue().
3946
+ // Without this, evidence like "entities[].analyses: array" becomes "unknown".
3947
+ const enrichedSchema = { ...efc.schema };
3948
+ const tempScopeNode = {
3949
+ name: efc.name,
3950
+ schema: enrichedSchema,
3951
+ equivalencies: efc.equivalencies ?? {},
3952
+ };
3953
+ fillInSchemaGapsAndUnknowns(tempScopeNode, true);
3470
3954
  return {
3471
3955
  name: efc.name,
3472
3956
  callSignature: efc.callSignature,
3473
3957
  callScope: efc.callScope,
3474
- schema: efc.schema,
3958
+ schema: enrichedSchema,
3475
3959
  equivalencies: efc.equivalencies
3476
3960
  ? Object.entries(efc.equivalencies).reduce((acc, [key, vars]) => {
3477
3961
  // Clean cyScope from the key as well as variable properties