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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (563) hide show
  1. package/analyzer-template/.build-info.json +7 -7
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/package.json +8 -8
  4. package/analyzer-template/packages/ai/index.ts +11 -2
  5. package/analyzer-template/packages/ai/package.json +2 -2
  6. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +100 -18
  7. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +67 -9
  8. package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +41 -17
  9. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  10. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +409 -50
  11. package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
  12. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +21 -6
  13. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +1007 -249
  14. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
  15. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +16 -3
  16. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +6 -4
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +54 -3
  18. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +60 -15
  19. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
  20. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +140 -14
  21. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +179 -0
  22. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.ts +40 -30
  23. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +393 -97
  24. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +33 -15
  25. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
  26. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +315 -6
  27. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +9 -5
  28. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +49 -5
  29. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
  30. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +649 -142
  31. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +1 -1
  32. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
  33. package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
  34. package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
  35. package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
  36. package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
  37. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
  38. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +25 -13
  39. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +4 -3
  40. package/analyzer-template/packages/ai/src/lib/worker/analyzeScopeWorker.ts +114 -2
  41. package/analyzer-template/packages/analyze/index.ts +2 -0
  42. package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +65 -59
  43. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +113 -26
  44. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
  45. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
  46. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
  47. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
  48. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
  49. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
  50. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +89 -9
  51. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +19 -4
  52. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +6 -0
  53. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
  54. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +0 -3
  55. package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
  56. package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
  57. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
  58. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +61 -13
  59. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +87 -25
  60. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +229 -19
  61. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +117 -9
  62. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +571 -74
  63. package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
  64. package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
  65. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  66. package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
  67. package/analyzer-template/packages/aws/package.json +1 -1
  68. package/analyzer-template/packages/database/package.json +1 -1
  69. package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
  70. package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
  71. package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
  72. package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
  73. package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
  74. package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
  75. package/analyzer-template/packages/database/src/lib/kysely/db.ts +14 -1
  76. package/analyzer-template/packages/database/src/lib/kysely/tables/commitsTable.ts +6 -0
  77. package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +1 -1
  78. package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
  79. package/analyzer-template/packages/database/src/lib/loadAnalyses.ts +58 -1
  80. package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +13 -0
  81. package/analyzer-template/packages/database/src/lib/loadBranch.ts +16 -1
  82. package/analyzer-template/packages/database/src/lib/loadCommit.ts +11 -0
  83. package/analyzer-template/packages/database/src/lib/loadCommits.ts +28 -0
  84. package/analyzer-template/packages/database/src/lib/loadEntities.ts +26 -3
  85. package/analyzer-template/packages/database/src/lib/loadEntityBranches.ts +12 -0
  86. package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
  87. package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
  88. package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
  89. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +7 -14
  90. package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
  91. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
  92. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
  93. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
  94. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
  95. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
  96. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
  97. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
  98. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
  99. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
  100. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
  101. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
  102. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
  103. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  104. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  105. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +11 -1
  106. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  107. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts +1 -0
  108. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts.map +1 -1
  109. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js +3 -0
  110. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  111. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +1 -1
  112. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
  113. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
  114. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  115. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  116. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts +2 -0
  117. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts.map +1 -1
  118. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js +45 -2
  119. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js.map +1 -1
  120. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
  121. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +8 -0
  122. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
  123. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js +11 -1
  124. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js.map +1 -1
  125. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.d.ts.map +1 -1
  126. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js +7 -0
  127. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js.map +1 -1
  128. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts +3 -1
  129. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  130. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +22 -1
  131. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  132. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts +3 -1
  133. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  134. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +23 -4
  135. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  136. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.d.ts.map +1 -1
  137. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js +9 -0
  138. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js.map +1 -1
  139. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
  140. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
  141. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
  142. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
  143. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
  144. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
  145. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts +2 -2
  146. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  147. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +5 -4
  148. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  149. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts +2 -0
  150. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts.map +1 -1
  151. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  152. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  153. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  154. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  155. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  156. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  157. package/analyzer-template/packages/github/package.json +1 -1
  158. package/analyzer-template/packages/types/src/types/Commit.ts +2 -0
  159. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +7 -0
  160. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +6 -5
  161. package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
  162. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts +2 -0
  163. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts.map +1 -1
  164. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  165. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  166. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  167. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  168. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  169. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  170. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
  171. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +93 -2
  172. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  173. package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +108 -2
  174. package/analyzer-template/playwright/capture.ts +20 -8
  175. package/analyzer-template/playwright/captureStatic.ts +1 -1
  176. package/analyzer-template/project/analyzeBaselineCommit.ts +5 -0
  177. package/analyzer-template/project/analyzeRegularCommit.ts +5 -0
  178. package/analyzer-template/project/captureLibraryFunctionDirect.ts +29 -26
  179. package/analyzer-template/project/constructMockCode.ts +92 -12
  180. package/analyzer-template/project/createEntitiesAndSortFiles.ts +83 -0
  181. package/analyzer-template/project/loadReadyToBeCaptured.ts +65 -41
  182. package/analyzer-template/project/orchestrateCapture/AwsCaptureTaskRunner.ts +12 -4
  183. package/analyzer-template/project/orchestrateCapture/SequentialCaptureTaskRunner.ts +11 -6
  184. package/analyzer-template/project/orchestrateCapture/taskRunner.ts +4 -2
  185. package/analyzer-template/project/orchestrateCapture.ts +45 -6
  186. package/analyzer-template/project/start.ts +35 -11
  187. package/analyzer-template/project/writeMockDataTsx.ts +181 -8
  188. package/analyzer-template/project/writeScenarioComponents.ts +103 -12
  189. package/analyzer-template/project/writeSimpleRoot.ts +21 -11
  190. package/analyzer-template/scripts/comboWorkerLoop.cjs +98 -50
  191. package/background/src/lib/local/createLocalAnalyzer.js +1 -1
  192. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  193. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js +5 -0
  194. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js.map +1 -1
  195. package/background/src/lib/virtualized/project/analyzeRegularCommit.js +5 -0
  196. package/background/src/lib/virtualized/project/analyzeRegularCommit.js.map +1 -1
  197. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js +3 -3
  198. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js.map +1 -1
  199. package/background/src/lib/virtualized/project/constructMockCode.js +77 -6
  200. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  201. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js +73 -1
  202. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js.map +1 -1
  203. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js +19 -8
  204. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js.map +1 -1
  205. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js +2 -2
  206. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js.map +1 -1
  207. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js +4 -4
  208. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js.map +1 -1
  209. package/background/src/lib/virtualized/project/orchestrateCapture.js +38 -6
  210. package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
  211. package/background/src/lib/virtualized/project/start.js +32 -11
  212. package/background/src/lib/virtualized/project/start.js.map +1 -1
  213. package/background/src/lib/virtualized/project/writeMockDataTsx.js +162 -4
  214. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  215. package/background/src/lib/virtualized/project/writeScenarioComponents.js +85 -15
  216. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  217. package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
  218. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  219. package/codeyam-cli/scripts/apply-setup.js +180 -0
  220. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  221. package/codeyam-cli/src/cli.js +4 -0
  222. package/codeyam-cli/src/cli.js.map +1 -1
  223. package/codeyam-cli/src/codeyam-cli.js +18 -2
  224. package/codeyam-cli/src/codeyam-cli.js.map +1 -1
  225. package/codeyam-cli/src/commands/analyze.js +4 -2
  226. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  227. package/codeyam-cli/src/commands/baseline.js +2 -0
  228. package/codeyam-cli/src/commands/baseline.js.map +1 -1
  229. package/codeyam-cli/src/commands/debug.js +9 -5
  230. package/codeyam-cli/src/commands/debug.js.map +1 -1
  231. package/codeyam-cli/src/commands/default.js +31 -20
  232. package/codeyam-cli/src/commands/default.js.map +1 -1
  233. package/codeyam-cli/src/commands/detect-universal-mocks.js +2 -0
  234. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +1 -1
  235. package/codeyam-cli/src/commands/init.js +49 -257
  236. package/codeyam-cli/src/commands/init.js.map +1 -1
  237. package/codeyam-cli/src/commands/memory.js +264 -0
  238. package/codeyam-cli/src/commands/memory.js.map +1 -0
  239. package/codeyam-cli/src/commands/recapture.js +2 -0
  240. package/codeyam-cli/src/commands/recapture.js.map +1 -1
  241. package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
  242. package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
  243. package/codeyam-cli/src/commands/setup-simulations.js +284 -0
  244. package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
  245. package/codeyam-cli/src/commands/test-startup.js +2 -0
  246. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  247. package/codeyam-cli/src/commands/verify.js +14 -2
  248. package/codeyam-cli/src/commands/verify.js.map +1 -1
  249. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +128 -86
  250. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  251. package/codeyam-cli/src/utils/analysisRunner.js +21 -2
  252. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  253. package/codeyam-cli/src/utils/analyzer.js +7 -0
  254. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  255. package/codeyam-cli/src/utils/backgroundServer.js +107 -19
  256. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  257. package/codeyam-cli/src/utils/generateReport.js +2 -2
  258. package/codeyam-cli/src/utils/install-skills.js +72 -47
  259. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  260. package/codeyam-cli/src/utils/labsAutoCheck.js +19 -0
  261. package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
  262. package/codeyam-cli/src/utils/progress.js +7 -0
  263. package/codeyam-cli/src/utils/progress.js.map +1 -1
  264. package/codeyam-cli/src/utils/queue/job.js +4 -0
  265. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  266. package/codeyam-cli/src/utils/requireSimulations.js +10 -0
  267. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
  268. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  269. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  270. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +230 -0
  271. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  272. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  273. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  274. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  275. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  276. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  277. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  278. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  279. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  280. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +75 -0
  281. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  282. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +378 -0
  283. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  284. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +115 -0
  285. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  286. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  287. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  288. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  289. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  290. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
  291. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  292. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  293. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  294. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
  295. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  296. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  297. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  298. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  299. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  300. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  301. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  302. package/codeyam-cli/src/utils/rules/index.js +6 -0
  303. package/codeyam-cli/src/utils/rules/index.js.map +1 -0
  304. package/codeyam-cli/src/utils/rules/parser.js +83 -0
  305. package/codeyam-cli/src/utils/rules/parser.js.map +1 -0
  306. package/codeyam-cli/src/utils/rules/pathMatcher.js +18 -0
  307. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -0
  308. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  309. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  310. package/codeyam-cli/src/utils/rules/staleness.js +137 -0
  311. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -0
  312. package/codeyam-cli/src/utils/serverState.js +37 -10
  313. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  314. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +21 -44
  315. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  316. package/codeyam-cli/src/webserver/app/lib/database.js +21 -6
  317. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  318. package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
  319. package/codeyam-cli/src/webserver/backgroundServer.js +50 -0
  320. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  321. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-D9i_zSlY.js +1 -0
  322. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-BLlhOa3C.js +11 -0
  323. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-De5b5pC7.js} +1 -1
  324. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-CzdG5I7z.js} +1 -1
  325. package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-C8lyxW9k.js → InlineSpinner-Bclf8Hka.js} +1 -1
  326. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-Ce-byqKl.js} +2 -2
  327. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-DEMHrl7v.js} +1 -1
  328. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-B1LNGboS.js} +1 -1
  329. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-B0Ll1DjK.js} +1 -1
  330. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-D4TZhLuw.js → ReportIssueModal-CVOvmCKb.js} +3 -13
  331. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-L0DWHa_L.js} +1 -1
  332. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DEx02QDa.js → ScenarioViewer-D54Mmpwi.js} +3 -3
  333. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-C7PFQfXy.js} +1 -1
  334. package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-CKTtYlBU.js} +1 -1
  335. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-DoLIqZX2.js → activity.(_tab)-CdziRIWU.js} +6 -16
  336. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-CPXtdaWm.js +17 -0
  337. package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
  338. package/codeyam-cli/src/webserver/build/client/assets/api.memory-profile-l0sNRNKZ.js +1 -0
  339. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  340. package/codeyam-cli/src/webserver/build/client/assets/book-open-Ch8b7GyQ.js +6 -0
  341. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-vJHJExlT.js} +1 -1
  342. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-BEyX4X6_.js} +12 -12
  343. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-rwynPZTW.js} +1 -1
  344. package/codeyam-cli/src/webserver/build/client/assets/copy-BBSpeBYf.js +11 -0
  345. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-DHVDauuc.js} +1 -1
  346. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-B9_ZqelV.js +1 -0
  347. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-BOPComvD.js +16 -0
  348. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js → entity._sha.scenarios._scenarioId.fullscreen-Cfw__yQa.js} +1 -1
  349. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-D1T4TGjf.js → entity._sha_.create-scenario-BIDUUrI3.js} +1 -1
  350. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-BEqewwtZ.js} +1 -1
  351. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-Dxqz8ygt.js} +1 -1
  352. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-CYnF5KWN.js} +1 -1
  353. package/codeyam-cli/src/webserver/build/client/assets/files-B_dAq2PQ.js +1 -0
  354. package/codeyam-cli/src/webserver/build/client/assets/{git-B4RJRvYB.js → git-BHPqH3Ch.js} +8 -8
  355. package/codeyam-cli/src/webserver/build/client/assets/globals-BJGhRykz.css +1 -0
  356. package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-DgAAopZk.js} +1 -1
  357. package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-viijWaN6.js} +1 -1
  358. package/codeyam-cli/src/webserver/build/client/assets/labs-ChoAe3xq.js +1 -0
  359. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-LGi2eKI5.js} +1 -1
  360. package/codeyam-cli/src/webserver/build/client/assets/manifest-87493a32.js +1 -0
  361. package/codeyam-cli/src/webserver/build/client/assets/memory-D9eA6kTo.js +78 -0
  362. package/codeyam-cli/src/webserver/build/client/assets/pause-DxJFmMsK.js +11 -0
  363. package/codeyam-cli/src/webserver/build/client/assets/root-C3r0p_7H.js +62 -0
  364. package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-Cu3QE9E5.js} +1 -1
  365. package/codeyam-cli/src/webserver/build/client/assets/settings-KH9TdArD.js +1 -0
  366. package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-D9Fkx0-d.js} +1 -1
  367. package/codeyam-cli/src/webserver/build/client/assets/terminal-dAhIBEcd.js +11 -0
  368. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-C4CYTEeP.js} +1 -1
  369. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-CLPnITMB.js} +1 -1
  370. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-aSv48UbS.js → useLastLogLine-DmGI38Et.js} +1 -1
  371. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-BK0S88PB.js} +1 -1
  372. package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-CJ-JqR0l.js} +1 -1
  373. package/codeyam-cli/src/webserver/build/server/assets/index-CkkmL6r5.js +1 -0
  374. package/codeyam-cli/src/webserver/build/server/assets/server-build-iBGjHYtO.js +259 -0
  375. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  376. package/codeyam-cli/src/webserver/build-info.json +5 -5
  377. package/codeyam-cli/templates/{codeyam:debug.md → codeyam-debug.md} +1 -1
  378. package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
  379. package/codeyam-cli/templates/{codeyam-power-rules-hook.sh → codeyam-memory-hook.sh} +22 -23
  380. package/codeyam-cli/templates/codeyam-memory.md +396 -0
  381. package/codeyam-cli/templates/codeyam-new-rule.md +13 -0
  382. package/codeyam-cli/templates/{codeyam:setup.md → codeyam-setup.md} +13 -1
  383. package/codeyam-cli/templates/{codeyam:sim.md → codeyam-sim.md} +1 -1
  384. package/codeyam-cli/templates/{codeyam:test.md → codeyam-test.md} +1 -1
  385. package/codeyam-cli/templates/{codeyam:verify.md → codeyam-verify.md} +1 -1
  386. package/codeyam-cli/templates/rule-notification-hook.py +56 -0
  387. package/codeyam-cli/templates/rule-reflection-hook.py +627 -0
  388. package/codeyam-cli/templates/rules-instructions.md +132 -0
  389. package/package.json +15 -13
  390. package/packages/ai/index.js +3 -2
  391. package/packages/ai/index.js.map +1 -1
  392. package/packages/ai/src/lib/analyzeScope.js +82 -13
  393. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  394. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +54 -8
  395. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  396. package/packages/ai/src/lib/astScopes/methodSemantics.js +41 -17
  397. package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
  398. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  399. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  400. package/packages/ai/src/lib/astScopes/processExpression.js +317 -44
  401. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  402. package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
  403. package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
  404. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +776 -171
  405. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  406. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
  407. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  408. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
  409. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
  410. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
  411. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
  412. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +52 -3
  413. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  414. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +55 -11
  415. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  416. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  417. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  418. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +122 -12
  419. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  420. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
  421. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
  422. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
  423. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
  424. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +333 -86
  425. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  426. package/packages/ai/src/lib/dataStructureChunking.js +26 -11
  427. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  428. package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
  429. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  430. package/packages/ai/src/lib/generateEntityScenarioData.js +227 -4
  431. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  432. package/packages/ai/src/lib/generateEntityScenarios.js +7 -1
  433. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  434. package/packages/ai/src/lib/generateExecutionFlows.js +26 -4
  435. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  436. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +447 -80
  437. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  438. package/packages/ai/src/lib/isolateScopes.js +39 -3
  439. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  440. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
  441. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
  442. package/packages/ai/src/lib/mergeStatements.js +70 -51
  443. package/packages/ai/src/lib/mergeStatements.js.map +1 -1
  444. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
  445. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
  446. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +10 -4
  447. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
  448. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
  449. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  450. package/packages/ai/src/lib/resolvePathToControllable.js +24 -14
  451. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
  452. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  453. package/packages/ai/src/lib/worker/analyzeScopeWorker.js +94 -1
  454. package/packages/ai/src/lib/worker/analyzeScopeWorker.js.map +1 -1
  455. package/packages/analyze/index.js +1 -0
  456. package/packages/analyze/index.js.map +1 -1
  457. package/packages/analyze/src/lib/FileAnalyzer.js +60 -36
  458. package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
  459. package/packages/analyze/src/lib/ProjectAnalyzer.js +96 -26
  460. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  461. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
  462. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
  463. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
  464. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
  465. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
  466. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
  467. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
  468. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
  469. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
  470. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
  471. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
  472. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
  473. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +65 -7
  474. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  475. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +17 -4
  476. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  477. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +5 -0
  478. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  479. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
  480. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  481. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +0 -3
  482. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  483. package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
  484. package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
  485. package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
  486. package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
  487. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
  488. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  489. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +56 -10
  490. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  491. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +75 -21
  492. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  493. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +150 -17
  494. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  495. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +56 -8
  496. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  497. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +478 -54
  498. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  499. package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
  500. package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
  501. package/packages/analyze/src/lib/index.js +1 -0
  502. package/packages/analyze/src/lib/index.js.map +1 -1
  503. package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
  504. package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
  505. package/packages/database/src/lib/analysisBranchToDb.js +1 -1
  506. package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
  507. package/packages/database/src/lib/analysisToDb.js +1 -1
  508. package/packages/database/src/lib/analysisToDb.js.map +1 -1
  509. package/packages/database/src/lib/branchToDb.js +1 -1
  510. package/packages/database/src/lib/branchToDb.js.map +1 -1
  511. package/packages/database/src/lib/commitBranchToDb.js +1 -1
  512. package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
  513. package/packages/database/src/lib/commitToDb.js +1 -1
  514. package/packages/database/src/lib/commitToDb.js.map +1 -1
  515. package/packages/database/src/lib/fileToDb.js +1 -1
  516. package/packages/database/src/lib/fileToDb.js.map +1 -1
  517. package/packages/database/src/lib/kysely/db.js +11 -1
  518. package/packages/database/src/lib/kysely/db.js.map +1 -1
  519. package/packages/database/src/lib/kysely/tables/commitsTable.js +3 -0
  520. package/packages/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  521. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  522. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  523. package/packages/database/src/lib/loadAnalyses.js +45 -2
  524. package/packages/database/src/lib/loadAnalyses.js.map +1 -1
  525. package/packages/database/src/lib/loadAnalysis.js +8 -0
  526. package/packages/database/src/lib/loadAnalysis.js.map +1 -1
  527. package/packages/database/src/lib/loadBranch.js +11 -1
  528. package/packages/database/src/lib/loadBranch.js.map +1 -1
  529. package/packages/database/src/lib/loadCommit.js +7 -0
  530. package/packages/database/src/lib/loadCommit.js.map +1 -1
  531. package/packages/database/src/lib/loadCommits.js +22 -1
  532. package/packages/database/src/lib/loadCommits.js.map +1 -1
  533. package/packages/database/src/lib/loadEntities.js +23 -4
  534. package/packages/database/src/lib/loadEntities.js.map +1 -1
  535. package/packages/database/src/lib/loadEntityBranches.js +9 -0
  536. package/packages/database/src/lib/loadEntityBranches.js.map +1 -1
  537. package/packages/database/src/lib/projectToDb.js +1 -1
  538. package/packages/database/src/lib/projectToDb.js.map +1 -1
  539. package/packages/database/src/lib/saveFiles.js +1 -1
  540. package/packages/database/src/lib/saveFiles.js.map +1 -1
  541. package/packages/database/src/lib/scenarioToDb.js +1 -1
  542. package/packages/database/src/lib/scenarioToDb.js.map +1 -1
  543. package/packages/database/src/lib/updateCommitMetadata.js +5 -4
  544. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  545. package/packages/utils/src/lib/fs/rsyncCopy.js +93 -2
  546. package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  547. package/scripts/finalize-analyzer.cjs +8 -76
  548. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-BXhEawa3.js +0 -1
  549. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BRb-0kQl.js +0 -1
  550. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-C2N4Op8e.js +0 -23
  551. package/codeyam-cli/src/webserver/build/client/assets/files-Cs4MdYtv.js +0 -1
  552. package/codeyam-cli/src/webserver/build/client/assets/git-commit-horizontal-CysbcZxi.js +0 -6
  553. package/codeyam-cli/src/webserver/build/client/assets/globals-DMUaGAqV.css +0 -1
  554. package/codeyam-cli/src/webserver/build/client/assets/manifest-f874c610.js +0 -1
  555. package/codeyam-cli/src/webserver/build/client/assets/root-Bz5TunQg.js +0 -57
  556. package/codeyam-cli/src/webserver/build/client/assets/rules-hEkvVw2-.js +0 -97
  557. package/codeyam-cli/src/webserver/build/client/assets/settings-CS5f3WzT.js +0 -1
  558. package/codeyam-cli/src/webserver/build/server/assets/index-967OuJoF.js +0 -1
  559. package/codeyam-cli/src/webserver/build/server/assets/server-build-DRTmerg9.js +0 -257
  560. package/codeyam-cli/templates/codeyam:diagnose.md +0 -650
  561. package/codeyam-cli/templates/codeyam:new-rule.md +0 -13
  562. package/codeyam-cli/templates/codeyam:power-rules.md +0 -447
  563. /package/codeyam-cli/src/webserver/build/client/assets/{api.rules-l0sNRNKZ.js → api.agent-transcripts-l0sNRNKZ.js} +0 -0
@@ -82,6 +82,8 @@
82
82
  import { ScopeAnalysis } from '~codeyam/types';
83
83
  import { EquivalencyManager } from './equivalencyManagers/EquivalencyManager';
84
84
  import fillInSchemaGapsAndUnknowns from './helpers/fillInSchemaGapsAndUnknowns';
85
+ import { clearCleanKnownObjectFunctionsCache } from './helpers/cleanKnownObjectFunctions';
86
+ import { clearCleanNonObjectFunctionsCache } from './helpers/cleanNonObjectFunctions';
85
87
 
86
88
  /**
87
89
  * Patterns that indicate recursive type structures in schema paths.
@@ -150,7 +152,7 @@ export interface ScopeInfo {
150
152
  [childComponentName: string]: Array<{
151
153
  path: string;
152
154
  conditionType: 'truthiness' | 'comparison';
153
- location: 'if' | 'ternary' | 'logical-and' | 'switch';
155
+ location: 'if' | 'ternary' | 'logical-and' | 'switch' | 'unconditional';
154
156
  isNegated?: boolean;
155
157
  }>;
156
158
  };
@@ -332,6 +334,19 @@ export function resetScopeDataStructureMetrics() {
332
334
  followEquivalenciesEarlyExitPhase1Count = 0;
333
335
  followEquivalenciesWithWorkCount = 0;
334
336
  addEquivalencyCallCount = 0;
337
+
338
+ // Clear module-level caches to prevent unbounded memory growth across entities
339
+ const knownObjectCache = clearCleanKnownObjectFunctionsCache();
340
+ const nonObjectCache = clearCleanNonObjectFunctionsCache();
341
+ if (knownObjectCache.count > 0 || nonObjectCache.count > 0) {
342
+ const totalBytes =
343
+ knownObjectCache.estimatedBytes + nonObjectCache.estimatedBytes;
344
+ console.log('CodeYam: Cleared analysis caches', {
345
+ knownObjectCache: `${knownObjectCache.count} entries, ${(knownObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
346
+ nonObjectCache: `${nonObjectCache.count} entries, ${(nonObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
347
+ totalKB: `${(totalBytes / 1024).toFixed(1)}KB`,
348
+ });
349
+ }
335
350
  }
336
351
 
337
352
  // Performance: Pre-computed Sets for equivalency reason filtering (O(1) vs O(n))
@@ -382,6 +397,7 @@ const SILENTLY_IGNORED_EQUIVALENCY_REASONS = new Set([
382
397
  'transformed non-object function equivalency - implicit parent equivalency - rerouted via useCallback',
383
398
  'transformed non-object function equivalency - Array.from() equivalency',
384
399
  'Spread operator equivalency key update: Explicit array deconstruction equivalency value',
400
+ // 'transformed non-object function equivalency - Explicit array deconstruction equivalency value',
385
401
  ]);
386
402
 
387
403
  export class ScopeDataStructure {
@@ -409,7 +425,7 @@ export class ScopeDataStructure {
409
425
  path: string;
410
426
  conditionType: 'truthiness' | 'comparison' | 'switch';
411
427
  comparedValues?: string[];
412
- location: 'if' | 'ternary' | 'logical-and' | 'switch';
428
+ location: 'if' | 'ternary' | 'logical-and' | 'switch' | 'unconditional';
413
429
  }>
414
430
  > = {};
415
431
 
@@ -784,6 +800,11 @@ export class ScopeDataStructure {
784
800
  return;
785
801
  }
786
802
 
803
+ // PERF: Early exit for paths with repeated function-call signature patterns
804
+ if (this.hasExcessivePatternRepetition(path)) {
805
+ return;
806
+ }
807
+
787
808
  // Update chain metadata for database tracking
788
809
  if (equivalencyValueChain.length > 0) {
789
810
  equivalencyValueChain[equivalencyValueChain.length - 1].addToSchemaId =
@@ -1471,6 +1492,15 @@ export class ScopeDataStructure {
1471
1492
 
1472
1493
  const bestValue = selectBestValue(value1, value2);
1473
1494
 
1495
+ // PERF: Skip paths with repeated function-call signature patterns
1496
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
1497
+ if (
1498
+ this.hasExcessivePatternRepetition(schemaPath) ||
1499
+ this.hasExcessivePatternRepetition(equivalentSchemaPath)
1500
+ ) {
1501
+ continue;
1502
+ }
1503
+
1474
1504
  scopeNode.schema[schemaPath] = bestValue;
1475
1505
  equivalentScopeNode.schema[equivalentSchemaPath] = bestValue;
1476
1506
  } else if (
@@ -1484,6 +1514,11 @@ export class ScopeDataStructure {
1484
1514
  ...remainingSchemaPathParts,
1485
1515
  ]);
1486
1516
 
1517
+ // PERF: Skip paths with repeated function-call signature patterns
1518
+ if (this.hasExcessivePatternRepetition(newEquivalentPath)) {
1519
+ continue;
1520
+ }
1521
+
1487
1522
  equivalentScopeNode.schema[newEquivalentPath] =
1488
1523
  scopeNode.schema[schemaPath];
1489
1524
  }
@@ -1603,6 +1638,23 @@ export class ScopeDataStructure {
1603
1638
  }
1604
1639
  }
1605
1640
 
1641
+ // Check for repeated function calls that indicate recursive type expansion.
1642
+ // E.g., localeCompare(b[])...localeCompare(b[]) means string.localeCompare
1643
+ // returns a type that again has localeCompare, causing infinite expansion.
1644
+ // We extract all function call patterns like "funcName(args)" and check if
1645
+ // the same normalized call appears more than once.
1646
+ const funcCallPattern = /(?:^|\.)[^.([]+\([^)]*\)/g;
1647
+ const funcCallMatches = path.match(funcCallPattern);
1648
+ if (funcCallMatches && funcCallMatches.length > 1) {
1649
+ const seen = new Set<string>();
1650
+ for (const match of funcCallMatches) {
1651
+ // Strip leading dot and normalize array indices
1652
+ const normalized = match.replace(/^\./, '').replace(/\[\d+\]/g, '[]');
1653
+ if (seen.has(normalized)) return true;
1654
+ seen.add(normalized);
1655
+ }
1656
+ }
1657
+
1606
1658
  // For longer paths, detect any repeated multi-part segments we haven't explicitly listed
1607
1659
  const pathParts = this.splitPath(path);
1608
1660
  if (pathParts.length <= 6) {
@@ -1635,17 +1687,26 @@ export class ScopeDataStructure {
1635
1687
  private setInstantiatedVariables(scopeNode: ScopeNode) {
1636
1688
  let instantiatedVariables = scopeNode.analysis?.instantiatedVariables ?? [];
1637
1689
 
1638
- for (const [path, equivalentPath] of Object.entries(
1690
+ for (const [path, rawEquivalentPath] of Object.entries(
1639
1691
  scopeNode.analysis.isolatedEquivalentVariables ?? {},
1640
1692
  )) {
1641
- if (typeof equivalentPath !== 'string') {
1642
- continue;
1643
- }
1693
+ // Normalize to array for consistent handling (supports both string and string[])
1694
+ const equivalentPaths = Array.isArray(rawEquivalentPath)
1695
+ ? rawEquivalentPath
1696
+ : rawEquivalentPath
1697
+ ? [rawEquivalentPath]
1698
+ : [];
1699
+
1700
+ for (const equivalentPath of equivalentPaths) {
1701
+ if (typeof equivalentPath !== 'string') {
1702
+ continue;
1703
+ }
1644
1704
 
1645
- if (equivalentPath.startsWith('signature[')) {
1646
- const equivalentPathParts = this.splitPath(equivalentPath);
1647
- instantiatedVariables.push(equivalentPathParts[0]);
1648
- instantiatedVariables.push(path);
1705
+ if (equivalentPath.startsWith('signature[')) {
1706
+ const equivalentPathParts = this.splitPath(equivalentPath);
1707
+ instantiatedVariables.push(equivalentPathParts[0]);
1708
+ instantiatedVariables.push(path);
1709
+ }
1649
1710
  }
1650
1711
 
1651
1712
  const duplicateInstantiated = instantiatedVariables.find(
@@ -1658,9 +1719,14 @@ export class ScopeDataStructure {
1658
1719
  }
1659
1720
  }
1660
1721
 
1661
- instantiatedVariables = instantiatedVariables.filter(
1662
- (varName, index, self) => self.indexOf(varName) === index,
1663
- );
1722
+ const instantiatedSeen = new Set<string>();
1723
+ instantiatedVariables = instantiatedVariables.filter((varName) => {
1724
+ if (instantiatedSeen.has(varName)) {
1725
+ return false;
1726
+ }
1727
+ instantiatedSeen.add(varName);
1728
+ return true;
1729
+ });
1664
1730
 
1665
1731
  scopeNode.instantiatedVariables = instantiatedVariables;
1666
1732
 
@@ -1681,13 +1747,19 @@ export class ScopeDataStructure {
1681
1747
  ...parentScopeNode.instantiatedVariables.filter(
1682
1748
  (v) => !v.startsWith('signature[') && !v.startsWith('returnValue'),
1683
1749
  ),
1684
- ].filter(
1685
- (varName, index, self) =>
1686
- !instantiatedVariables.includes(varName) &&
1687
- self.indexOf(varName) === index,
1688
- );
1750
+ ].filter((varName) => !instantiatedSeen.has(varName));
1689
1751
 
1690
- scopeNode.parentInstantiatedVariables = parentInstantiatedVariables;
1752
+ const parentInstantiatedSeen = new Set<string>();
1753
+ const dedupedParentInstantiatedVariables =
1754
+ parentInstantiatedVariables.filter((varName) => {
1755
+ if (parentInstantiatedSeen.has(varName)) {
1756
+ return false;
1757
+ }
1758
+ parentInstantiatedSeen.add(varName);
1759
+ return true;
1760
+ });
1761
+
1762
+ scopeNode.parentInstantiatedVariables = dedupedParentInstantiatedVariables;
1691
1763
  }
1692
1764
 
1693
1765
  private trackFunctionCalls(scopeNode: ScopeNode) {
@@ -1703,172 +1775,198 @@ export class ScopeDataStructure {
1703
1775
  const { isolatedStructure, isolatedEquivalentVariables } =
1704
1776
  scopeNode.analysis;
1705
1777
 
1778
+ // Flatten isolatedEquivalentVariables values for allPaths (handles both string and string[])
1779
+ const flattenedEquivValues = Object.values(
1780
+ isolatedEquivalentVariables || {},
1781
+ ).flatMap((v) => (Array.isArray(v) ? v : [v]));
1782
+
1706
1783
  const allPaths = Array.from(
1707
1784
  new Set([
1708
1785
  ...Object.keys(isolatedStructure || {}),
1709
1786
  ...Object.keys(isolatedEquivalentVariables || {}),
1710
- ...Object.values(isolatedEquivalentVariables || {}),
1787
+ ...flattenedEquivValues,
1711
1788
  ]),
1712
1789
  );
1713
1790
 
1714
1791
  for (let path in isolatedEquivalentVariables) {
1715
- let equivalentValue = isolatedEquivalentVariables?.[path];
1716
-
1717
- if (equivalentValue && this.isValidPath(equivalentValue)) {
1718
- // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1719
- // These markers are critical for distinguishing variable reassignments.
1720
- // For example, with:
1721
- // let fetcher = useFetcher<ConfigData>();
1722
- // const configData = fetcher.data?.data;
1723
- // fetcher = useFetcher<SettingsData>();
1724
- // const settingsData = fetcher.data?.data;
1725
- //
1726
- // mergeStatements creates:
1727
- // fetcher useFetcher<ConfigData>()...
1728
- // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1729
- // configData fetcher.data.data
1730
- // settingsData → fetcher::cyDuplicateKey1::.data.data
1731
- //
1732
- // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1733
- // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1734
- path = cleanPath(path, allPaths);
1735
- equivalentValue = cleanPath(equivalentValue, allPaths);
1736
-
1737
- this.addEquivalency(
1738
- path,
1739
- equivalentValue,
1740
- scopeNode.name,
1741
- scopeNode,
1742
- 'original equivalency',
1743
- );
1792
+ const rawEquivalentValue = isolatedEquivalentVariables?.[path];
1793
+ // Normalize to array for consistent handling
1794
+ const equivalentValues = Array.isArray(rawEquivalentValue)
1795
+ ? rawEquivalentValue
1796
+ : [rawEquivalentValue];
1797
+
1798
+ for (let equivalentValue of equivalentValues) {
1799
+ if (equivalentValue && this.isValidPath(equivalentValue)) {
1800
+ // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1801
+ // These markers are critical for distinguishing variable reassignments.
1802
+ // For example, with:
1803
+ // let fetcher = useFetcher<ConfigData>();
1804
+ // const configData = fetcher.data?.data;
1805
+ // fetcher = useFetcher<SettingsData>();
1806
+ // const settingsData = fetcher.data?.data;
1807
+ //
1808
+ // mergeStatements creates:
1809
+ // fetcher useFetcher<ConfigData>()...
1810
+ // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1811
+ // configData fetcher.data.data
1812
+ // settingsData fetcher::cyDuplicateKey1::.data.data
1813
+ //
1814
+ // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1815
+ // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1816
+ path = cleanPath(path, allPaths);
1817
+ equivalentValue = cleanPath(equivalentValue, allPaths);
1818
+
1819
+ this.addEquivalency(
1820
+ path,
1821
+ equivalentValue,
1822
+ scopeNode.name,
1823
+ scopeNode,
1824
+ 'original equivalency',
1825
+ );
1744
1826
 
1745
- // Propagate equivalencies involving parent-scope variables to those parent scopes.
1746
- // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1747
- // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1748
- // visible when tracing from the parent scope.
1749
- const rootVariable = this.extractRootVariable(path);
1750
- const equivalentRootVariable =
1751
- this.extractRootVariable(equivalentValue);
1752
-
1753
- // Skip propagation for self-referential reassignment patterns like:
1754
- // x = x.method().functionCallReturnValue
1755
- // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1756
- // These create circular references since both sides reference the same variable.
1757
- //
1758
- // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1759
- // where the path has additional segments beyond the root variable.
1760
- const pathIsJustRootVariable = path === rootVariable;
1761
- const isSelfReferentialReassignment =
1762
- pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1827
+ // Propagate equivalencies involving parent-scope variables to those parent scopes.
1828
+ // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1829
+ // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1830
+ // visible when tracing from the parent scope.
1831
+ const rootVariable = this.extractRootVariable(path);
1832
+ const equivalentRootVariable =
1833
+ this.extractRootVariable(equivalentValue);
1834
+
1835
+ // Skip propagation for self-referential reassignment patterns like:
1836
+ // x = x.method().functionCallReturnValue
1837
+ // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1838
+ // These create circular references since both sides reference the same variable.
1839
+ //
1840
+ // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1841
+ // where the path has additional segments beyond the root variable.
1842
+ const pathIsJustRootVariable = path === rootVariable;
1843
+ const isSelfReferentialReassignment =
1844
+ pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1763
1845
 
1764
- if (
1765
- rootVariable &&
1766
- !isSelfReferentialReassignment &&
1767
- scopeNode.parentInstantiatedVariables?.includes(rootVariable)
1768
- ) {
1769
- // Find the parent scope where this variable is defined
1770
- for (const parentScopeName of scopeNode.tree || []) {
1771
- const parentScope = this.scopeNodes[parentScopeName];
1772
- if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1773
- // Add the equivalency to the parent scope as well
1774
- this.addEquivalency(
1775
- path,
1776
- equivalentValue,
1777
- scopeNode.name, // The equivalent path's scope remains the child scope
1778
- parentScope, // But store it in the parent scope's equivalencies
1779
- 'propagated parent-variable equivalency',
1780
- );
1781
- break;
1846
+ if (
1847
+ rootVariable &&
1848
+ !isSelfReferentialReassignment &&
1849
+ scopeNode.parentInstantiatedVariables?.includes(rootVariable)
1850
+ ) {
1851
+ // Find the parent scope where this variable is defined
1852
+ for (const parentScopeName of scopeNode.tree || []) {
1853
+ const parentScope = this.scopeNodes[parentScopeName];
1854
+ if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1855
+ // Add the equivalency to the parent scope as well
1856
+ this.addEquivalency(
1857
+ path,
1858
+ equivalentValue,
1859
+ scopeNode.name, // The equivalent path's scope remains the child scope
1860
+ parentScope, // But store it in the parent scope's equivalencies
1861
+ 'propagated parent-variable equivalency',
1862
+ );
1863
+ break;
1864
+ }
1782
1865
  }
1783
1866
  }
1784
- }
1785
1867
 
1786
- // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1787
- // that has sub-properties defined in the isolatedEquivalentVariables.
1788
- // This handles cases like: dataItem={{ structure: completeDataStructure }}
1789
- // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1790
- // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1791
- const isSimpleVariable =
1792
- !equivalentValue.startsWith('signature[') &&
1793
- !equivalentValue.includes('functionCallReturnValue') &&
1794
- !equivalentValue.includes('.') &&
1795
- !equivalentValue.includes('[');
1796
-
1797
- if (isSimpleVariable) {
1798
- // Look in current scope and all parent scopes for sub-properties
1799
- const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1800
- for (const scopeName of scopesToCheck) {
1801
- const checkScope = this.scopeNodes[scopeName];
1802
- if (!checkScope?.analysis?.isolatedEquivalentVariables) continue;
1803
-
1804
- for (const [subPath, subValue] of Object.entries(
1805
- checkScope.analysis.isolatedEquivalentVariables,
1806
- )) {
1807
- // Check if this is a sub-property of the equivalentValue variable
1808
- // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1809
- const matchesDot = subPath.startsWith(equivalentValue + '.');
1810
- const matchesBracket = subPath.startsWith(equivalentValue + '[');
1811
- if (matchesDot || matchesBracket) {
1812
- const subPropertyPath = subPath.substring(
1813
- equivalentValue.length,
1868
+ // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1869
+ // that has sub-properties defined in the isolatedEquivalentVariables.
1870
+ // This handles cases like: dataItem={{ structure: completeDataStructure }}
1871
+ // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1872
+ // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1873
+ const isSimpleVariable =
1874
+ !equivalentValue.startsWith('signature[') &&
1875
+ !equivalentValue.includes('functionCallReturnValue') &&
1876
+ !equivalentValue.includes('.') &&
1877
+ !equivalentValue.includes('[');
1878
+
1879
+ if (isSimpleVariable) {
1880
+ // Look in current scope and all parent scopes for sub-properties
1881
+ const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1882
+ for (const scopeName of scopesToCheck) {
1883
+ const checkScope = this.scopeNodes[scopeName];
1884
+ if (!checkScope?.analysis?.isolatedEquivalentVariables) continue;
1885
+
1886
+ for (const [subPath, rawSubValue] of Object.entries(
1887
+ checkScope.analysis.isolatedEquivalentVariables,
1888
+ )) {
1889
+ // Normalize to array for consistent handling
1890
+ const subValues = Array.isArray(rawSubValue)
1891
+ ? rawSubValue
1892
+ : rawSubValue
1893
+ ? [rawSubValue]
1894
+ : [];
1895
+
1896
+ // Check if this is a sub-property of the equivalentValue variable
1897
+ // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1898
+ const matchesDot = subPath.startsWith(equivalentValue + '.');
1899
+ const matchesBracket = subPath.startsWith(
1900
+ equivalentValue + '[',
1814
1901
  );
1815
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1816
- const newEquivalentValue = cleanPath(
1817
- (subValue as string).replace(/::cyDuplicateKey\d+::/g, ''),
1818
- allPaths,
1819
- );
1820
-
1821
- if (
1822
- newEquivalentValue &&
1823
- this.isValidPath(newEquivalentValue)
1824
- ) {
1825
- this.addEquivalency(
1826
- newPath,
1827
- newEquivalentValue,
1828
- checkScope.name, // Use the scope where the sub-property was found
1829
- scopeNode,
1830
- 'propagated sub-property equivalency',
1902
+ if (matchesDot || matchesBracket) {
1903
+ const subPropertyPath = subPath.substring(
1904
+ equivalentValue.length,
1831
1905
  );
1906
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
1907
+
1908
+ for (const subValue of subValues) {
1909
+ if (typeof subValue !== 'string') continue;
1910
+ const newEquivalentValue = cleanPath(
1911
+ subValue.replace(/::cyDuplicateKey\d+::/g, ''),
1912
+ allPaths,
1913
+ );
1914
+
1915
+ if (
1916
+ newEquivalentValue &&
1917
+ this.isValidPath(newEquivalentValue)
1918
+ ) {
1919
+ this.addEquivalency(
1920
+ newPath,
1921
+ newEquivalentValue,
1922
+ checkScope.name, // Use the scope where the sub-property was found
1923
+ scopeNode,
1924
+ 'propagated sub-property equivalency',
1925
+ );
1926
+ }
1927
+ }
1832
1928
  }
1833
- }
1834
1929
 
1835
- // Also check if equivalentValue itself maps to a functionCallReturnValue
1836
- // e.g., result = useMemo(...).functionCallReturnValue
1837
- if (
1838
- subPath === equivalentValue &&
1839
- typeof subValue === 'string' &&
1840
- subValue.endsWith('.functionCallReturnValue')
1841
- ) {
1842
- this.propagateFunctionCallReturnSubProperties(
1843
- path,
1844
- subValue,
1845
- scopeNode,
1846
- allPaths,
1847
- );
1930
+ // Also check if equivalentValue itself maps to a functionCallReturnValue
1931
+ // e.g., result = useMemo(...).functionCallReturnValue
1932
+ for (const subValue of subValues) {
1933
+ if (
1934
+ subPath === equivalentValue &&
1935
+ typeof subValue === 'string' &&
1936
+ subValue.endsWith('.functionCallReturnValue')
1937
+ ) {
1938
+ this.propagateFunctionCallReturnSubProperties(
1939
+ path,
1940
+ subValue,
1941
+ scopeNode,
1942
+ allPaths,
1943
+ );
1944
+ }
1945
+ }
1848
1946
  }
1849
1947
  }
1850
1948
  }
1851
- }
1852
1949
 
1853
- // Handle function call return values by propagating returnValue.* sub-properties
1854
- // from the callback scope to the usage path
1855
- if (equivalentValue.endsWith('.functionCallReturnValue')) {
1856
- this.propagateFunctionCallReturnSubProperties(
1857
- path,
1858
- equivalentValue,
1859
- scopeNode,
1860
- allPaths,
1861
- );
1950
+ // Handle function call return values by propagating returnValue.* sub-properties
1951
+ // from the callback scope to the usage path
1952
+ if (equivalentValue.endsWith('.functionCallReturnValue')) {
1953
+ this.propagateFunctionCallReturnSubProperties(
1954
+ path,
1955
+ equivalentValue,
1956
+ scopeNode,
1957
+ allPaths,
1958
+ );
1862
1959
 
1863
- // Track which variable receives the return value of each function call
1864
- // This enables generating separate mock data for each call site
1865
- this.trackReceivingVariable(path, equivalentValue);
1866
- }
1960
+ // Track which variable receives the return value of each function call
1961
+ // This enables generating separate mock data for each call site
1962
+ this.trackReceivingVariable(path, equivalentValue);
1963
+ }
1867
1964
 
1868
- // Also track variables that receive destructured properties from function call return values
1869
- // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1870
- if (equivalentValue.includes('.functionCallReturnValue.')) {
1871
- this.trackReceivingVariable(path, equivalentValue);
1965
+ // Also track variables that receive destructured properties from function call return values
1966
+ // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1967
+ if (equivalentValue.includes('.functionCallReturnValue.')) {
1968
+ this.trackReceivingVariable(path, equivalentValue);
1969
+ }
1872
1970
  }
1873
1971
  }
1874
1972
  }
@@ -2049,9 +2147,18 @@ export class ScopeDataStructure {
2049
2147
  const checkScope = this.scopeNodes[scopeName];
2050
2148
  if (!checkScope?.analysis?.isolatedEquivalentVariables) continue;
2051
2149
 
2052
- const functionRef =
2150
+ const rawFunctionRef =
2053
2151
  checkScope.analysis.isolatedEquivalentVariables[functionName];
2054
- if (typeof functionRef === 'string' && functionRef.endsWith('F')) {
2152
+ // Normalize to array and find first string ending with 'F'
2153
+ const functionRefs = Array.isArray(rawFunctionRef)
2154
+ ? rawFunctionRef
2155
+ : rawFunctionRef
2156
+ ? [rawFunctionRef]
2157
+ : [];
2158
+ const functionRef = functionRefs.find(
2159
+ (r) => typeof r === 'string' && r.endsWith('F'),
2160
+ );
2161
+ if (typeof functionRef === 'string') {
2055
2162
  callbackScopeName = functionRef.slice(0, -1);
2056
2163
  break;
2057
2164
  }
@@ -2079,19 +2186,24 @@ export class ScopeDataStructure {
2079
2186
 
2080
2187
  const isolatedVars = callbackScope.analysis.isolatedEquivalentVariables;
2081
2188
 
2189
+ // Get the first returnValue equivalency (normalize array to single value for these checks)
2190
+ const rawReturnValue = isolatedVars.returnValue;
2191
+ const firstReturnValue = Array.isArray(rawReturnValue)
2192
+ ? rawReturnValue[0]
2193
+ : rawReturnValue;
2194
+
2082
2195
  // First, check if returnValue is an alias to another variable (e.g., returnValue = intermediate)
2083
2196
  // If so, we need to look for that variable's sub-properties too
2084
2197
  const returnValueAlias =
2085
- typeof isolatedVars.returnValue === 'string' &&
2086
- !isolatedVars.returnValue.includes('.')
2087
- ? isolatedVars.returnValue
2198
+ typeof firstReturnValue === 'string' && !firstReturnValue.includes('.')
2199
+ ? firstReturnValue
2088
2200
  : undefined;
2089
2201
 
2090
2202
  // Pattern 3: Object.keys(X).reduce() - the reduce result has the same sub-properties as X
2091
2203
  // When returnValue = "Object.keys(source).reduce(...).functionCallReturnValue", look for source.* sub-properties
2092
2204
  let reduceSourceVar: string | undefined;
2093
- if (typeof isolatedVars.returnValue === 'string') {
2094
- const reduceMatch = isolatedVars.returnValue.match(
2205
+ if (typeof firstReturnValue === 'string') {
2206
+ const reduceMatch = firstReturnValue.match(
2095
2207
  /^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/,
2096
2208
  );
2097
2209
  if (reduceMatch) {
@@ -2099,7 +2211,14 @@ export class ScopeDataStructure {
2099
2211
  }
2100
2212
  }
2101
2213
 
2102
- for (const [subPath, subValue] of Object.entries(isolatedVars)) {
2214
+ for (const [subPath, rawSubValue] of Object.entries(isolatedVars)) {
2215
+ // Normalize to array for consistent handling
2216
+ const subValues = Array.isArray(rawSubValue)
2217
+ ? rawSubValue
2218
+ : rawSubValue
2219
+ ? [rawSubValue]
2220
+ : [];
2221
+
2103
2222
  // Check for direct returnValue.* sub-properties
2104
2223
  const isReturnValueSub =
2105
2224
  subPath.startsWith('returnValue.') ||
@@ -2117,57 +2236,59 @@ export class ScopeDataStructure {
2117
2236
  (subPath.startsWith(reduceSourceVar + '.') ||
2118
2237
  subPath.startsWith(reduceSourceVar + '['));
2119
2238
 
2120
- if (
2121
- typeof subValue !== 'string' ||
2122
- (!isReturnValueSub && !isAliasSub && !isReduceSourceSub)
2123
- )
2124
- continue;
2125
-
2126
- // Convert alias/reduceSource paths to returnValue paths
2127
- let effectiveSubPath = subPath;
2128
- if (isAliasSub && !isReturnValueSub) {
2129
- // Replace the alias prefix with returnValue
2130
- effectiveSubPath =
2131
- 'returnValue' + subPath.substring(returnValueAlias!.length);
2132
- } else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
2133
- // Replace the reduce source prefix with returnValue
2134
- effectiveSubPath =
2135
- 'returnValue' + subPath.substring(reduceSourceVar!.length);
2136
- }
2137
- const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
2138
- const newPath = cleanPath(path + subPropertyPath, allPaths);
2139
- let newEquivalentValue = cleanPath(
2140
- subValue.replace(/::cyDuplicateKey\d+::/g, ''),
2141
- allPaths,
2142
- );
2239
+ if (!isReturnValueSub && !isAliasSub && !isReduceSourceSub) continue;
2240
+
2241
+ for (const subValue of subValues) {
2242
+ if (typeof subValue !== 'string') continue;
2243
+
2244
+ // Convert alias/reduceSource paths to returnValue paths
2245
+ let effectiveSubPath = subPath;
2246
+ if (isAliasSub && !isReturnValueSub) {
2247
+ // Replace the alias prefix with returnValue
2248
+ effectiveSubPath =
2249
+ 'returnValue' + subPath.substring(returnValueAlias!.length);
2250
+ } else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
2251
+ // Replace the reduce source prefix with returnValue
2252
+ effectiveSubPath =
2253
+ 'returnValue' + subPath.substring(reduceSourceVar!.length);
2254
+ }
2255
+ const subPropertyPath = effectiveSubPath.substring(
2256
+ 'returnValue'.length,
2257
+ );
2258
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
2259
+ let newEquivalentValue = cleanPath(
2260
+ subValue.replace(/::cyDuplicateKey\d+::/g, ''),
2261
+ allPaths,
2262
+ );
2143
2263
 
2144
- // Resolve variable references through parent scope equivalencies
2145
- const resolved = this.resolveVariableThroughParentScopes(
2146
- newEquivalentValue,
2147
- callbackScope,
2148
- allPaths,
2149
- );
2150
- newEquivalentValue = resolved.resolvedPath;
2151
- const equivalentScopeName = resolved.scopeName;
2264
+ // Resolve variable references through parent scope equivalencies
2265
+ const resolved = this.resolveVariableThroughParentScopes(
2266
+ newEquivalentValue,
2267
+ callbackScope,
2268
+ allPaths,
2269
+ );
2270
+ newEquivalentValue = resolved.resolvedPath;
2271
+ const equivalentScopeName = resolved.scopeName;
2152
2272
 
2153
- if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
2154
- continue;
2273
+ if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
2274
+ continue;
2155
2275
 
2156
- this.addEquivalency(
2157
- newPath,
2158
- newEquivalentValue,
2159
- equivalentScopeName,
2160
- scopeNode,
2161
- 'propagated function call return sub-property equivalency',
2162
- );
2276
+ this.addEquivalency(
2277
+ newPath,
2278
+ newEquivalentValue,
2279
+ equivalentScopeName,
2280
+ scopeNode,
2281
+ 'propagated function call return sub-property equivalency',
2282
+ );
2163
2283
 
2164
- // Ensure the database entry has the usage path
2165
- this.addUsageToEquivalencyDatabaseEntry(
2166
- newPath,
2167
- newEquivalentValue,
2168
- equivalentScopeName,
2169
- scopeNode.name,
2170
- );
2284
+ // Ensure the database entry has the usage path
2285
+ this.addUsageToEquivalencyDatabaseEntry(
2286
+ newPath,
2287
+ newEquivalentValue,
2288
+ equivalentScopeName,
2289
+ scopeNode.name,
2290
+ );
2291
+ }
2171
2292
  }
2172
2293
  }
2173
2294
 
@@ -2207,8 +2328,15 @@ export class ScopeDataStructure {
2207
2328
  const parentScope = this.scopeNodes[parentScopeName];
2208
2329
  if (!parentScope?.analysis?.isolatedEquivalentVariables) continue;
2209
2330
 
2210
- const rootEquiv =
2331
+ const rawRootEquiv =
2211
2332
  parentScope.analysis.isolatedEquivalentVariables[rootVar];
2333
+ // Normalize to array and use first string value
2334
+ const rootEquivs = Array.isArray(rawRootEquiv)
2335
+ ? rawRootEquiv
2336
+ : rawRootEquiv
2337
+ ? [rawRootEquiv]
2338
+ : [];
2339
+ const rootEquiv = rootEquivs.find((r) => typeof r === 'string');
2212
2340
  if (typeof rootEquiv === 'string') {
2213
2341
  return {
2214
2342
  resolvedPath: cleanPath(rootEquiv + restOfPath, allPaths),
@@ -2483,6 +2611,7 @@ export class ScopeDataStructure {
2483
2611
  relevantSubPathParts.every((part, i) => part === schemaPathParts[i]) &&
2484
2612
  equivalentValue.scopeNodeName === scopeNode.name
2485
2613
  ) {
2614
+ // DEBUG
2486
2615
  continue;
2487
2616
  }
2488
2617
 
@@ -2669,6 +2798,8 @@ export class ScopeDataStructure {
2669
2798
  usageEquivalency.scopeNodeName,
2670
2799
  ) as ScopeNode;
2671
2800
 
2801
+ if (!usageScopeNode) continue;
2802
+
2672
2803
  // Guard against infinite recursion by tracking which paths we've already
2673
2804
  // added from addComplexSourcePathVariables
2674
2805
  if (
@@ -2748,6 +2879,8 @@ export class ScopeDataStructure {
2748
2879
  usageEquivalency.scopeNodeName,
2749
2880
  ) as ScopeNode;
2750
2881
 
2882
+ if (!usageScopeNode) continue;
2883
+
2751
2884
  // This is put in place to avoid propagating array functions like 'filter' through complex equivalencies
2752
2885
  // but may cause problems if the funtion call is not on a known object (e.g. string or array)
2753
2886
  if (
@@ -2874,10 +3007,105 @@ export class ScopeDataStructure {
2874
3007
  this.intermediatesOrderIndex.set(pathId, databaseEntry);
2875
3008
 
2876
3009
  if (intermediateIndex === 0) {
2877
- const isValidSourceCandidate =
3010
+ let isValidSourceCandidate =
2878
3011
  pathInfo.schemaPath.startsWith('signature[') ||
2879
3012
  pathInfo.schemaPath.includes('functionCallReturnValue');
2880
- if (isValidSourceCandidate) {
3013
+
3014
+ // Check if path STARTS with a spread pattern like [...var]
3015
+ // This handles cases like [...files][][0] or [...files].sort(...).functionCallReturnValue[][0]
3016
+ // where the spread source variable needs to be resolved to a signature path.
3017
+ // We do this REGARDLESS of isValidSourceCandidate because even paths containing
3018
+ // functionCallReturnValue may need spread resolution to trace back to the signature.
3019
+ const spreadMatch = pathInfo.schemaPath.match(/^\[\.\.\.(\w+)\]/);
3020
+ if (spreadMatch) {
3021
+ const spreadVar = spreadMatch[1];
3022
+ const spreadPattern = spreadMatch[0]; // The full [...var] match
3023
+ const scopeNode = this.scopeNodes[pathInfo.scopeNodeName];
3024
+
3025
+ if (scopeNode?.equivalencies) {
3026
+ // Follow the equivalency chain to find a signature path
3027
+ // e.g., files (cyScope1) → files (root) → signature[0].files
3028
+ const resolveToSignature = (
3029
+ varName: string,
3030
+ currentScopeName: string,
3031
+ visited: Set<string>,
3032
+ ): { schemaPath: string; scopeNodeName: string } | null => {
3033
+ const visitKey = `${currentScopeName}::${varName}`;
3034
+ if (visited.has(visitKey)) return null;
3035
+ visited.add(visitKey);
3036
+
3037
+ const currentScope = this.scopeNodes[currentScopeName];
3038
+ if (!currentScope?.equivalencies) return null;
3039
+
3040
+ const varEquivs = currentScope.equivalencies[varName];
3041
+ if (!varEquivs) return null;
3042
+
3043
+ // First check if any equivalency directly points to a signature path
3044
+ const signatureEquiv = varEquivs.find((eq) =>
3045
+ eq.schemaPath.startsWith('signature['),
3046
+ );
3047
+ if (signatureEquiv) {
3048
+ return signatureEquiv;
3049
+ }
3050
+
3051
+ // Otherwise, follow the chain to other scopes
3052
+ for (const equiv of varEquivs) {
3053
+ // If the equivalency points to the same variable in a different scope,
3054
+ // follow the chain
3055
+ if (
3056
+ equiv.schemaPath === varName &&
3057
+ equiv.scopeNodeName !== currentScopeName
3058
+ ) {
3059
+ const result = resolveToSignature(
3060
+ varName,
3061
+ equiv.scopeNodeName,
3062
+ visited,
3063
+ );
3064
+ if (result) return result;
3065
+ }
3066
+ }
3067
+
3068
+ return null;
3069
+ };
3070
+
3071
+ const signatureEquiv = resolveToSignature(
3072
+ spreadVar,
3073
+ pathInfo.scopeNodeName,
3074
+ new Set(),
3075
+ );
3076
+ if (signatureEquiv) {
3077
+ // Replace ONLY the [...var] part with the resolved signature path
3078
+ // This preserves any suffix like .sort(...).functionCallReturnValue[][0]
3079
+ const resolvedPath = pathInfo.schemaPath.replace(
3080
+ spreadPattern,
3081
+ signatureEquiv.schemaPath,
3082
+ );
3083
+ // Add the resolved path as a source candidate
3084
+ if (
3085
+ !databaseEntry.sourceCandidates.some(
3086
+ (sc) =>
3087
+ sc.schemaPath === resolvedPath &&
3088
+ sc.scopeNodeName === pathInfo.scopeNodeName,
3089
+ )
3090
+ ) {
3091
+ databaseEntry.sourceCandidates.push({
3092
+ scopeNodeName: pathInfo.scopeNodeName,
3093
+ schemaPath: resolvedPath,
3094
+ });
3095
+ }
3096
+ isValidSourceCandidate = true;
3097
+ }
3098
+ }
3099
+ }
3100
+
3101
+ if (
3102
+ isValidSourceCandidate &&
3103
+ !databaseEntry.sourceCandidates.some(
3104
+ (sc) =>
3105
+ sc.schemaPath === pathInfo.schemaPath &&
3106
+ sc.scopeNodeName === pathInfo.scopeNodeName,
3107
+ )
3108
+ ) {
2881
3109
  databaseEntry.sourceCandidates.push(pathInfo);
2882
3110
  }
2883
3111
  } else {
@@ -3105,6 +3333,14 @@ export class ScopeDataStructure {
3105
3333
  }
3106
3334
  }
3107
3335
 
3336
+ // Ensure parameter-to-signature equivalencies are fully propagated.
3337
+ // When a parameter variable (e.g., `node`) is equivalenced to `signature[N]`,
3338
+ // all sub-paths of that variable should also appear under `signature[N]`.
3339
+ // This handles cases where the sub-path was added to the schema via a propagation
3340
+ // chain that already included the variable↔signature equivalency, causing the
3341
+ // cycle detection to prevent the reverse mapping.
3342
+ this.propagateParameterToSignaturePaths(scopeNode);
3343
+
3108
3344
  fillInSchemaGapsAndUnknowns(scopeNode, fillInUnknowns);
3109
3345
 
3110
3346
  if (final) {
@@ -3119,6 +3355,50 @@ export class ScopeDataStructure {
3119
3355
  }
3120
3356
  }
3121
3357
 
3358
+ /**
3359
+ * For each equivalency where a simple variable maps to signature[N],
3360
+ * ensure all sub-paths of that variable are reflected under signature[N].
3361
+ */
3362
+ private propagateParameterToSignaturePaths(scopeNode: ScopeNode) {
3363
+ // Find variable → signature[N] equivalencies
3364
+ for (const [varName, equivalencies] of Object.entries(
3365
+ scopeNode.equivalencies,
3366
+ )) {
3367
+ // Only process simple variable names (no dots, brackets, or parens)
3368
+ if (
3369
+ varName.includes('.') ||
3370
+ varName.includes('[') ||
3371
+ varName.includes('(')
3372
+ ) {
3373
+ continue;
3374
+ }
3375
+
3376
+ for (const equiv of equivalencies) {
3377
+ if (
3378
+ equiv.scopeNodeName === scopeNode.name &&
3379
+ equiv.schemaPath.startsWith('signature[')
3380
+ ) {
3381
+ const signaturePath = equiv.schemaPath;
3382
+ const varPrefix = varName + '.';
3383
+ const varBracketPrefix = varName + '[';
3384
+
3385
+ // Find all schema keys starting with the variable
3386
+ for (const key in scopeNode.schema) {
3387
+ if (key.startsWith(varPrefix) || key.startsWith(varBracketPrefix)) {
3388
+ const suffix = key.slice(varName.length);
3389
+ const sigKey = signaturePath + suffix;
3390
+
3391
+ // Only add if the signature path doesn't already exist
3392
+ if (!scopeNode.schema[sigKey]) {
3393
+ scopeNode.schema[sigKey] = scopeNode.schema[key];
3394
+ }
3395
+ }
3396
+ }
3397
+ }
3398
+ }
3399
+ }
3400
+ }
3401
+
3122
3402
  private filterAndConvertSchema({
3123
3403
  filterPath,
3124
3404
  newPath,
@@ -3205,6 +3485,9 @@ export class ScopeDataStructure {
3205
3485
  equivalentValueSchemaPathParts.length,
3206
3486
  ),
3207
3487
  ]);
3488
+ // PERF: Skip keys with repeated function-call signature patterns
3489
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
3490
+ if (this.hasExcessivePatternRepetition(newKey)) continue;
3208
3491
  resolvedSchema[newKey] = value;
3209
3492
  }
3210
3493
  }
@@ -3227,6 +3510,8 @@ export class ScopeDataStructure {
3227
3510
  if (!subSchema) continue;
3228
3511
 
3229
3512
  for (const resolvedKey in subSchema) {
3513
+ // PERF: Skip keys with repeated function-call signature patterns
3514
+ if (this.hasExcessivePatternRepetition(resolvedKey)) continue;
3230
3515
  if (
3231
3516
  !resolvedSchema[resolvedKey] ||
3232
3517
  subSchema[resolvedKey] === 'unknown'
@@ -3464,26 +3749,270 @@ export class ScopeDataStructure {
3464
3749
  return {};
3465
3750
  }
3466
3751
 
3752
+ // Collect all descendant scope names (including the scope itself)
3753
+ // This ensures we include external calls from nested scopes like cyScope2
3754
+ const getAllDescendantScopeNames = (
3755
+ node: import('./helpers/ScopeTreeManager').ScopeTreeNode,
3756
+ ): Set<string> => {
3757
+ const names = new Set<string>([node.name]);
3758
+ for (const child of node.children) {
3759
+ for (const name of getAllDescendantScopeNames(child)) {
3760
+ names.add(name);
3761
+ }
3762
+ }
3763
+ return names;
3764
+ };
3765
+
3766
+ const treeNode = this.scopeTreeManager.findNode(scopeNode.name);
3767
+ const descendantScopeNames = treeNode
3768
+ ? getAllDescendantScopeNames(treeNode)
3769
+ : new Set<string>([scopeNode.name]);
3770
+
3771
+ // Get all external function calls made from this scope or any descendant scope
3772
+ // This allows us to include prop equivalencies from JSX components
3773
+ // that were rendered in nested scopes (e.g., FileTableRow called from cyScope2)
3774
+ const externalCallsFromScope = this.externalFunctionCalls.filter((efc) =>
3775
+ descendantScopeNames.has(efc.callScope),
3776
+ );
3777
+ const externalCallNames = new Set(
3778
+ externalCallsFromScope.map((efc) => efc.name),
3779
+ );
3780
+
3781
+ // Helper to check if a usage belongs to this scope (directly, via descendant, or via external call)
3782
+ const usageMatchesScope = (usage: { scopeNodeName: string }) =>
3783
+ descendantScopeNames.has(usage.scopeNodeName) ||
3784
+ externalCallNames.has(usage.scopeNodeName);
3785
+
3467
3786
  const entries = this.equivalencyDatabase.filter((entry) =>
3468
- entry.usages.some((usage) => usage.scopeNodeName === scopeNode.name),
3787
+ entry.usages.some(usageMatchesScope),
3469
3788
  );
3470
- return entries.reduce(
3471
- (acc, entry) => {
3472
- if (entry.sourceCandidates.length === 0) return acc;
3473
- const usages = entry.usages.filter(
3474
- (u) => u.scopeNodeName === scopeNode.name,
3475
- );
3789
+
3790
+ // Helper to resolve a source candidate through equivalency chains to find signature paths
3791
+ const resolveToSignature = (
3792
+ source: Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>,
3793
+ visited: Set<string>,
3794
+ ): Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[] => {
3795
+ const visitKey = `${source.scopeNodeName}::${source.schemaPath}`;
3796
+ if (visited.has(visitKey)) return [];
3797
+ visited.add(visitKey);
3798
+
3799
+ // If already a signature path, return as-is
3800
+ if (source.schemaPath.startsWith('signature[')) {
3801
+ return [source];
3802
+ }
3803
+
3804
+ const currentScope = this.scopeNodes[source.scopeNodeName];
3805
+ if (!currentScope?.equivalencies) return [source];
3806
+
3807
+ // Check for direct equivalencies FIRST (full path match)
3808
+ // This ensures paths like "useMemo(...).functionCallReturnValue" follow to "cyScope1::returnValue"
3809
+ // before prefix matching tries "useMemo(...)" which goes to the useMemo scope
3810
+ const directEquivs = currentScope.equivalencies[source.schemaPath];
3811
+ if (directEquivs?.length > 0) {
3812
+ const results: Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[] =
3813
+ [];
3814
+ for (const equiv of directEquivs) {
3815
+ const resolved = resolveToSignature(
3816
+ {
3817
+ scopeNodeName: equiv.scopeNodeName,
3818
+ schemaPath: equiv.schemaPath,
3819
+ },
3820
+ visited,
3821
+ );
3822
+ results.push(...resolved);
3823
+ }
3824
+ if (results.length > 0) return results;
3825
+ }
3826
+
3827
+ // Handle spread patterns like [...items].sort().functionCallReturnValue
3828
+ // Extract the spread variable and resolve it through the equivalency chain
3829
+ const spreadMatch = source.schemaPath.match(/^\[\.\.\.(\w+)\]/);
3830
+ if (spreadMatch) {
3831
+ const spreadVar = spreadMatch[1];
3832
+ const spreadPattern = spreadMatch[0];
3833
+ const varEquivs = currentScope.equivalencies[spreadVar];
3834
+
3835
+ if (varEquivs?.length > 0) {
3836
+ const results: Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[] =
3837
+ [];
3838
+ for (const equiv of varEquivs) {
3839
+ // Follow the variable equivalency and then resolve from there
3840
+ const resolvedVar = resolveToSignature(
3841
+ {
3842
+ scopeNodeName: equiv.scopeNodeName,
3843
+ schemaPath: equiv.schemaPath,
3844
+ },
3845
+ visited,
3846
+ );
3847
+ // For each resolved variable path, create the full path with array element suffix
3848
+ for (const rv of resolvedVar) {
3849
+ if (rv.schemaPath.startsWith('signature[')) {
3850
+ // Get the suffix after the spread pattern
3851
+ let suffix = source.schemaPath.slice(spreadPattern.length);
3852
+
3853
+ // Clean the suffix: strip array method chains like .sort(...).functionCallReturnValue[]
3854
+ // These don't change the data identity, just transform it.
3855
+ // Keep only the final element access parts like [0], [1], etc.
3856
+ // Pattern: strip everything from a method call up through functionCallReturnValue[]
3857
+ suffix = suffix.replace(
3858
+ /\.\w+\([^)]*\)\.functionCallReturnValue\[\]/g,
3859
+ '',
3860
+ );
3861
+ // Also handle simpler case without nested parens
3862
+ suffix = suffix.replace(
3863
+ /\.sort\(\w*\(\)\)\.functionCallReturnValue\[\]/g,
3864
+ '',
3865
+ );
3866
+
3867
+ // Add [] to indicate array element access from the spread
3868
+ const resolvedPath = rv.schemaPath + '[]' + suffix;
3869
+ results.push({
3870
+ scopeNodeName: rv.scopeNodeName,
3871
+ schemaPath: resolvedPath,
3872
+ });
3873
+ }
3874
+ }
3875
+ }
3876
+ if (results.length > 0) return results;
3877
+ }
3878
+ }
3879
+
3880
+ // Try to find prefix equivalencies that can resolve this path
3881
+ // For path like "cyScope3().signature[0][0]", check "cyScope3().signature[0]", etc.
3882
+ const pathParts = this.splitPath(source.schemaPath);
3883
+ for (let i = pathParts.length - 1; i > 0; i--) {
3884
+ const prefix = this.joinPathParts(pathParts.slice(0, i));
3885
+ const suffix = this.joinPathParts(pathParts.slice(i));
3886
+ const prefixEquivs = currentScope.equivalencies[prefix];
3887
+
3888
+ if (prefixEquivs?.length > 0) {
3889
+ const results: Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[] =
3890
+ [];
3891
+ for (const equiv of prefixEquivs) {
3892
+ const newPath = this.joinPathParts([equiv.schemaPath, suffix]);
3893
+ const resolved = resolveToSignature(
3894
+ { scopeNodeName: equiv.scopeNodeName, schemaPath: newPath },
3895
+ visited,
3896
+ );
3897
+ results.push(...resolved);
3898
+ }
3899
+ if (results.length > 0) return results;
3900
+ }
3901
+ }
3902
+
3903
+ return [source];
3904
+ };
3905
+
3906
+ const acc = entries.reduce(
3907
+ (result, entry) => {
3908
+ if (entry.sourceCandidates.length === 0) return result;
3909
+ const usages = entry.usages.filter(usageMatchesScope);
3476
3910
  for (const usage of usages) {
3477
- acc[usage.schemaPath] ||= [];
3478
- acc[usage.schemaPath].push(...entry.sourceCandidates);
3911
+ result[usage.schemaPath] ||= [];
3912
+ // Resolve each source candidate through the equivalency chain
3913
+ for (const source of entry.sourceCandidates) {
3914
+ const resolvedSources = resolveToSignature(source, new Set());
3915
+ result[usage.schemaPath].push(...resolvedSources);
3916
+ }
3479
3917
  }
3480
- return acc;
3918
+ return result;
3481
3919
  },
3482
3920
  {} as Record<
3483
3921
  string,
3484
3922
  Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[]
3485
3923
  >,
3486
3924
  );
3925
+
3926
+ // Post-processing: enrich useState-backed sources with co-located external
3927
+ // function calls. When a useState value resolves to a setter variable that
3928
+ // lives in the same scope as a fetch/API call, that fetch is a data source.
3929
+ this.enrichUseStateSourcesWithCoLocatedCalls(acc);
3930
+
3931
+ return acc;
3932
+ }
3933
+
3934
+ /**
3935
+ * For each source that ends at a useState path, check if the setter was called
3936
+ * from a scope that also contains external function calls (like fetch).
3937
+ * If so, add those external calls as additional source candidates.
3938
+ */
3939
+ private enrichUseStateSourcesWithCoLocatedCalls(
3940
+ acc: Record<string, Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[]>,
3941
+ ) {
3942
+ const rootScopeName = this.scopeTreeManager.getRootName();
3943
+ const rootScope = this.scopeNodes[rootScopeName];
3944
+ if (!rootScope) return;
3945
+
3946
+ // Collect all descendants for each scope node
3947
+ const getAllDescendants = (
3948
+ node: import('./helpers/ScopeTreeManager').ScopeTreeNode,
3949
+ ): Set<string> => {
3950
+ const names = new Set<string>([node.name]);
3951
+ for (const child of node.children) {
3952
+ for (const name of getAllDescendants(child)) {
3953
+ names.add(name);
3954
+ }
3955
+ }
3956
+ return names;
3957
+ };
3958
+
3959
+ for (const [usagePath, sources] of Object.entries(acc)) {
3960
+ const additionalSources: Pick<
3961
+ ScopeVariable,
3962
+ 'scopeNodeName' | 'schemaPath'
3963
+ >[] = [];
3964
+
3965
+ for (const source of sources) {
3966
+ // Check if this source is a useState-related terminal path
3967
+ // (e.g., useState(X).functionCallReturnValue[1] or useState(X).signature[0])
3968
+ if (!source.schemaPath.match(/^useState\([^)]*\)\./)) continue;
3969
+
3970
+ // Find the useState call from the source path
3971
+ const useStateCallMatch = source.schemaPath.match(
3972
+ /^(useState\([^)]*\))\./,
3973
+ );
3974
+ if (!useStateCallMatch) continue;
3975
+ const useStateCall = useStateCallMatch[1];
3976
+
3977
+ // Look in the root scope for the useState value equivalency
3978
+ // which tells us where the setter was called from
3979
+ const valuePath = `${useStateCall}.functionCallReturnValue[0]`;
3980
+ const valueEquivs = rootScope.equivalencies[valuePath];
3981
+ if (!valueEquivs) continue;
3982
+
3983
+ for (const equiv of valueEquivs) {
3984
+ // Find the scope where the setter was called
3985
+ const setterScopeName = equiv.scopeNodeName;
3986
+ const setterScopeTree =
3987
+ this.scopeTreeManager.findNode(setterScopeName);
3988
+ if (!setterScopeTree) continue;
3989
+
3990
+ // Get all descendant scope names from the setter scope
3991
+ const relatedScopes = getAllDescendants(setterScopeTree);
3992
+
3993
+ // Find external function calls in those scopes whose return values
3994
+ // are actually consumed (assigned to a variable). This excludes
3995
+ // fire-and-forget calls like analytics.track() or console.log().
3996
+ const coLocatedCalls = this.externalFunctionCalls.filter(
3997
+ (efc) =>
3998
+ relatedScopes.has(efc.callScope) &&
3999
+ efc.receivingVariableNames &&
4000
+ efc.receivingVariableNames.length > 0,
4001
+ );
4002
+
4003
+ for (const call of coLocatedCalls) {
4004
+ additionalSources.push({
4005
+ scopeNodeName: call.callScope,
4006
+ schemaPath: `${call.callSignature}.functionCallReturnValue`,
4007
+ });
4008
+ }
4009
+ }
4010
+ }
4011
+
4012
+ if (additionalSources.length > 0) {
4013
+ acc[usagePath].push(...additionalSources);
4014
+ }
4015
+ }
3487
4016
  }
3488
4017
 
3489
4018
  getUsageEquivalencies(functionName?: string) {
@@ -3588,6 +4117,54 @@ export class ScopeDataStructure {
3588
4117
  }
3589
4118
  }
3590
4119
 
4120
+ // Enrich schema with deeply nested paths from internal function call scopes.
4121
+ // When a function call like traverse(tree) exists, and traverse's scope has
4122
+ // signature[0].children[path][entityName] (from propagateParameterToSignaturePaths),
4123
+ // we need to map those paths back to the argument variable (tree) in this scope.
4124
+ // This handles cases where cycle detection prevented the equivalency chain from
4125
+ // propagating deep paths during Phase 2 batch queue processing.
4126
+ for (const equivalenceKey in equivalencies ?? {}) {
4127
+ // Look for keys matching function call pattern: funcName(...).signature[N]
4128
+ const funcCallMatch = equivalenceKey.match(
4129
+ /^([^(]+)\(.*?\)\.(signature\[\d+\])$/,
4130
+ );
4131
+ if (!funcCallMatch) continue;
4132
+
4133
+ const calledFunctionName = funcCallMatch[1];
4134
+ const signatureParam = funcCallMatch[2]; // e.g., "signature[0]"
4135
+
4136
+ for (const equivalenceValue of equivalencies[equivalenceKey]) {
4137
+ if (equivalenceValue.scopeNodeName !== scopeName) continue;
4138
+
4139
+ const targetVariable = equivalenceValue.schemaPath;
4140
+
4141
+ // Get the called function's schema (includes propagated parameter paths)
4142
+ const childSchema = this.getSchema({
4143
+ scopeName: calledFunctionName,
4144
+ });
4145
+ if (!childSchema) continue;
4146
+
4147
+ // Map child function's signature paths to parent variable paths
4148
+ const sigPrefix = signatureParam + '.';
4149
+ const sigBracketPrefix = signatureParam + '[';
4150
+ for (const childKey in childSchema) {
4151
+ let suffix: string | null = null;
4152
+ if (childKey.startsWith(sigPrefix)) {
4153
+ suffix = childKey.slice(signatureParam.length);
4154
+ } else if (childKey.startsWith(sigBracketPrefix)) {
4155
+ suffix = childKey.slice(signatureParam.length);
4156
+ }
4157
+
4158
+ if (suffix !== null) {
4159
+ const parentKey = targetVariable + suffix;
4160
+ if (!schema[parentKey]) {
4161
+ schema[parentKey] = childSchema[childKey];
4162
+ }
4163
+ }
4164
+ }
4165
+ }
4166
+ }
4167
+
3591
4168
  // Propagate nested paths from variables to their signature equivalents
3592
4169
  // e.g., if workouts = signature[0].workouts, then workouts[].title becomes
3593
4170
  // signature[0].workouts[].title
@@ -3860,10 +4437,32 @@ export class ScopeDataStructure {
3860
4437
  return scopeText;
3861
4438
  }
3862
4439
 
3863
- getEquivalentSignatureVariables() {
4440
+ getEquivalentSignatureVariables(): Record<string, string | string[]> {
3864
4441
  const scopeNode = this.scopeNodes[this.scopeTreeManager.getRootName()];
3865
4442
 
3866
- const equivalentSignatureVariables: Record<string, string> = {};
4443
+ const equivalentSignatureVariables: Record<string, string | string[]> = {};
4444
+
4445
+ // Helper to add equivalencies - accumulates into array if multiple values for same key
4446
+ // This is critical for OR expressions like `x = a || b` where x should map to both a and b
4447
+ const addEquivalency = (key: string, value: string) => {
4448
+ const existing = equivalentSignatureVariables[key];
4449
+ if (existing === undefined) {
4450
+ // First value - store as string
4451
+ equivalentSignatureVariables[key] = value;
4452
+ } else if (typeof existing === 'string') {
4453
+ if (existing !== value) {
4454
+ // Second different value - convert to array
4455
+ equivalentSignatureVariables[key] = [existing, value];
4456
+ }
4457
+ // Same value - no change needed
4458
+ } else {
4459
+ // Already an array - add if not already present
4460
+ if (!existing.includes(value)) {
4461
+ existing.push(value);
4462
+ }
4463
+ }
4464
+ };
4465
+
3867
4466
  for (const [path, equivalentValues] of Object.entries(
3868
4467
  scopeNode.equivalencies,
3869
4468
  )) {
@@ -3872,7 +4471,7 @@ export class ScopeDataStructure {
3872
4471
  // Maps local variable names to their signature paths
3873
4472
  // e.g., "propValue" -> "signature[0].prop"
3874
4473
  if (path.startsWith('signature[')) {
3875
- equivalentSignatureVariables[equivalentValue.schemaPath] = path;
4474
+ addEquivalency(equivalentValue.schemaPath, path);
3876
4475
  }
3877
4476
 
3878
4477
  // Case 2: Hook variable equivalencies (new behavior)
@@ -3906,7 +4505,7 @@ export class ScopeDataStructure {
3906
4505
  hookCallPath = dbEntry.sourceCandidates[0].schemaPath;
3907
4506
  }
3908
4507
  }
3909
- equivalentSignatureVariables[path] = hookCallPath;
4508
+ addEquivalency(path, hookCallPath);
3910
4509
  }
3911
4510
  }
3912
4511
 
@@ -3920,10 +4519,17 @@ export class ScopeDataStructure {
3920
4519
  !equivalentValue.schemaPath.startsWith('signature[') && // not a signature path
3921
4520
  !equivalentValue.schemaPath.endsWith('.functionCallReturnValue') // not already handled above
3922
4521
  ) {
3923
- // Only add if we haven't already captured this variable in Case 1 or 2
3924
- if (!(path in equivalentSignatureVariables)) {
3925
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4522
+ // Skip bare "returnValue" from child scopes this is the child's return value,
4523
+ // not a meaningful data source path in the parent scope
4524
+ if (
4525
+ equivalentValue.schemaPath === 'returnValue' &&
4526
+ equivalentValue.scopeNodeName !==
4527
+ this.scopeTreeManager.getRootName()
4528
+ ) {
4529
+ continue;
3926
4530
  }
4531
+ // Add equivalency (will accumulate if multiple values for OR expressions)
4532
+ addEquivalency(path, equivalentValue.schemaPath);
3927
4533
  }
3928
4534
 
3929
4535
  // Case 4: Child component prop mappings (Fix 22)
@@ -3936,7 +4542,7 @@ export class ScopeDataStructure {
3936
4542
  path.includes('().signature[') &&
3937
4543
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable, not a function call
3938
4544
  ) {
3939
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4545
+ addEquivalency(path, equivalentValue.schemaPath);
3940
4546
  }
3941
4547
 
3942
4548
  // Case 5: Destructured function parameters (Fix 25)
@@ -3951,7 +4557,7 @@ export class ScopeDataStructure {
3951
4557
  !path.includes('.') && // path is a simple identifier (destructured prop name)
3952
4558
  equivalentValue.schemaPath.startsWith('signature[') // schemaPath IS a signature path
3953
4559
  ) {
3954
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4560
+ addEquivalency(path, equivalentValue.schemaPath);
3955
4561
  }
3956
4562
 
3957
4563
  // Case 7: Method calls on variables that result in .functionCallReturnValue (Fix 33)
@@ -3965,8 +4571,7 @@ export class ScopeDataStructure {
3965
4571
  if (
3966
4572
  !path.includes('.') && // path is a simple identifier
3967
4573
  equivalentValue.schemaPath.endsWith('.functionCallReturnValue') && // ends with function return
3968
- equivalentValue.schemaPath.includes('.') && // has property access (method call)
3969
- !(path in equivalentSignatureVariables) // not already captured
4574
+ equivalentValue.schemaPath.includes('.') // has property access (method call)
3970
4575
  ) {
3971
4576
  // Check if this looks like a method call on a variable (not a hook call)
3972
4577
  // Hook calls look like: hookName() or hookName<T>()
@@ -3980,7 +4585,7 @@ export class ScopeDataStructure {
3980
4585
  const parenPos = hookCallPath.indexOf('(');
3981
4586
  if (dotBeforeParen !== -1 && dotBeforeParen < parenPos) {
3982
4587
  // This is a method call like "splat.split('/')", not a hook call
3983
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4588
+ addEquivalency(path, equivalentValue.schemaPath);
3984
4589
  }
3985
4590
  }
3986
4591
  }
@@ -4011,8 +4616,9 @@ export class ScopeDataStructure {
4011
4616
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable
4012
4617
  ) {
4013
4618
  // Only add if not already present from the root scope
4619
+ // Root scope values take precedence over child scope values
4014
4620
  if (!(path in equivalentSignatureVariables)) {
4015
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4621
+ addEquivalency(path, equivalentValue.schemaPath);
4016
4622
  }
4017
4623
  }
4018
4624
  }
@@ -4024,12 +4630,83 @@ export class ScopeDataStructure {
4024
4630
  // We need multiple passes because resolutions can depend on each other
4025
4631
  const maxIterations = 5; // Prevent infinite loops
4026
4632
 
4633
+ // Helper function to resolve a single source path using equivalencies
4634
+ const resolveSourcePath = (
4635
+ sourcePath: string,
4636
+ equivMap: Record<string, string | string[]>,
4637
+ ): string | null => {
4638
+ // Extract base variable from the path
4639
+ const dotIndex = sourcePath.indexOf('.');
4640
+ const bracketIndex = sourcePath.indexOf('[');
4641
+
4642
+ let baseVar: string;
4643
+ let rest: string;
4644
+
4645
+ if (dotIndex === -1 && bracketIndex === -1) {
4646
+ baseVar = sourcePath;
4647
+ rest = '';
4648
+ } else if (dotIndex === -1) {
4649
+ baseVar = sourcePath.slice(0, bracketIndex);
4650
+ rest = sourcePath.slice(bracketIndex);
4651
+ } else if (bracketIndex === -1) {
4652
+ baseVar = sourcePath.slice(0, dotIndex);
4653
+ rest = sourcePath.slice(dotIndex);
4654
+ } else {
4655
+ const firstIndex = Math.min(dotIndex, bracketIndex);
4656
+ baseVar = sourcePath.slice(0, firstIndex);
4657
+ rest = sourcePath.slice(firstIndex);
4658
+ }
4659
+
4660
+ // Look up the base variable in equivalencies
4661
+ if (baseVar in equivMap && equivMap[baseVar] !== sourcePath) {
4662
+ const baseResolved = equivMap[baseVar];
4663
+ // Skip if baseResolved is an array (handle later)
4664
+ if (Array.isArray(baseResolved)) return null;
4665
+ // If it resolves to a signature path, build the full resolved path
4666
+ if (
4667
+ baseResolved.startsWith('signature[') ||
4668
+ baseResolved.includes('()')
4669
+ ) {
4670
+ if (baseResolved.endsWith('()')) {
4671
+ return baseResolved + '.functionCallReturnValue' + rest;
4672
+ }
4673
+ return baseResolved + rest;
4674
+ }
4675
+ }
4676
+ return null;
4677
+ };
4678
+
4027
4679
  for (let iteration = 0; iteration < maxIterations; iteration++) {
4028
4680
  let changed = false;
4029
4681
 
4030
- for (const [varName, sourcePath] of Object.entries(
4682
+ for (const [varName, sourcePathOrArray] of Object.entries(
4031
4683
  equivalentSignatureVariables,
4032
4684
  )) {
4685
+ // Handle arrays (OR expressions) by resolving each element
4686
+ if (Array.isArray(sourcePathOrArray)) {
4687
+ const resolvedArray: string[] = [];
4688
+ let arrayChanged = false;
4689
+ for (const sourcePath of sourcePathOrArray) {
4690
+ // Try to resolve this path using transitive resolution
4691
+ const resolved = resolveSourcePath(
4692
+ sourcePath,
4693
+ equivalentSignatureVariables,
4694
+ );
4695
+ if (resolved && resolved !== sourcePath) {
4696
+ resolvedArray.push(resolved);
4697
+ arrayChanged = true;
4698
+ } else {
4699
+ resolvedArray.push(sourcePath);
4700
+ }
4701
+ }
4702
+ if (arrayChanged) {
4703
+ equivalentSignatureVariables[varName] = resolvedArray;
4704
+ changed = true;
4705
+ }
4706
+ continue;
4707
+ }
4708
+ const sourcePath = sourcePathOrArray;
4709
+
4033
4710
  // Skip if already fully resolved (contains function call syntax)
4034
4711
  // BUT first check for computed value patterns that need resolution (Fix 28)
4035
4712
  // AND method call patterns that need base variable resolution (Fix 33)
@@ -4091,6 +4768,8 @@ export class ScopeDataStructure {
4091
4768
  baseVar !== varName
4092
4769
  ) {
4093
4770
  const baseResolved = equivalentSignatureVariables[baseVar];
4771
+ // Skip if baseResolved is an array (OR expression)
4772
+ if (Array.isArray(baseResolved)) continue;
4094
4773
  // Only resolve if the base resolved to something useful (contains () or .)
4095
4774
  if (baseResolved.includes('()') || baseResolved.includes('.')) {
4096
4775
  const newPath = baseResolved + rest;
@@ -4155,7 +4834,12 @@ export class ScopeDataStructure {
4155
4834
  }
4156
4835
 
4157
4836
  if (baseVar in equivalentSignatureVariables && baseVar !== varName) {
4158
- const baseResolved = equivalentSignatureVariables[baseVar];
4837
+ // Handle array case (OR expressions) - use first element
4838
+ const rawBaseResolved = equivalentSignatureVariables[baseVar];
4839
+ const baseResolved = Array.isArray(rawBaseResolved)
4840
+ ? rawBaseResolved[0]
4841
+ : rawBaseResolved;
4842
+ if (!baseResolved) continue;
4159
4843
  // If the base resolves to a hook call, add .functionCallReturnValue
4160
4844
  if (baseResolved.endsWith('()')) {
4161
4845
  const newPath = baseResolved + '.functionCallReturnValue' + rest;
@@ -4375,7 +5059,7 @@ export class ScopeDataStructure {
4375
5059
  path: string;
4376
5060
  conditionType: 'truthiness' | 'comparison' | 'switch';
4377
5061
  comparedValues?: string[];
4378
- location: 'if' | 'ternary' | 'logical-and' | 'switch';
5062
+ location: 'if' | 'ternary' | 'logical-and' | 'switch' | 'unconditional';
4379
5063
  }>
4380
5064
  >,
4381
5065
  ): void {
@@ -4540,6 +5224,10 @@ export class ScopeDataStructure {
4540
5224
  getEnrichedConditionalUsages(): Record<string, EnrichedConditionalUsage[]> {
4541
5225
  const enriched: Record<string, EnrichedConditionalUsage[]> = {};
4542
5226
 
5227
+ console.log(
5228
+ `[getEnrichedConditionalUsages] Processing ${Object.keys(this.rawConditionalUsages).length} conditional paths: [${Object.keys(this.rawConditionalUsages).join(', ')}]`,
5229
+ );
5230
+
4543
5231
  for (const [path, usages] of Object.entries(this.rawConditionalUsages)) {
4544
5232
  // Try to trace this path back to a data source
4545
5233
  // First, try the root scope
@@ -4548,10 +5236,69 @@ export class ScopeDataStructure {
4548
5236
 
4549
5237
  let sourceDataPath: string | undefined;
4550
5238
  if (explanation.source) {
4551
- // Build the full data path: scopeName.path
4552
- sourceDataPath = `${explanation.source.scope}.${explanation.source.path}`;
5239
+ const { scope, path: sourcePath } = explanation.source;
5240
+
5241
+ // Build initial path — avoid redundant prefix when path already contains the scope call
5242
+ let fullPath: string;
5243
+ if (sourcePath.startsWith(`${scope}(`)) {
5244
+ fullPath = sourcePath;
5245
+ } else {
5246
+ fullPath = `${scope}.${sourcePath}`;
5247
+ }
5248
+
5249
+ sourceDataPath = fullPath;
5250
+ console.log(
5251
+ `[getEnrichedConditionalUsages] "${path}" explainPath → scope="${scope}", sourcePath="${sourcePath}" → sourceDataPath="${sourceDataPath}"`,
5252
+ );
5253
+ } else {
5254
+ console.log(
5255
+ `[getEnrichedConditionalUsages] "${path}" explainPath → no source found`,
5256
+ );
4553
5257
  }
4554
5258
 
5259
+ // If explainPath didn't find a useful external source (e.g., it traced to
5260
+ // useState or just to the component scope itself), check sourceEquivalencies
5261
+ // for an external function call source like a fetch call
5262
+ const hasExternalSource = sourceDataPath?.includes(
5263
+ '.functionCallReturnValue',
5264
+ );
5265
+ if (!hasExternalSource) {
5266
+ console.log(
5267
+ `[getEnrichedConditionalUsages] "${path}" no external source (sourceDataPath="${sourceDataPath}"), checking sourceEquivalencies fallback...`,
5268
+ );
5269
+ const sourceEquiv = this.getSourceEquivalencies();
5270
+ const returnValueKey = `returnValue.${path}`;
5271
+ const sources = sourceEquiv[returnValueKey];
5272
+ if (sources) {
5273
+ console.log(
5274
+ `[getEnrichedConditionalUsages] "${path}" sourceEquivalencies["${returnValueKey}"] has ${sources.length} sources: [${sources.map((s: { schemaPath: string }) => s.schemaPath).join(', ')}]`,
5275
+ );
5276
+ const externalSource = sources.find(
5277
+ (s: { schemaPath: string }) =>
5278
+ s.schemaPath.includes('.functionCallReturnValue') &&
5279
+ !s.schemaPath.startsWith('useState('),
5280
+ );
5281
+ if (externalSource) {
5282
+ console.log(
5283
+ `[getEnrichedConditionalUsages] "${path}" sourceEquivalencies fallback found external source: "${externalSource.schemaPath}"`,
5284
+ );
5285
+ sourceDataPath = externalSource.schemaPath;
5286
+ } else {
5287
+ console.log(
5288
+ `[getEnrichedConditionalUsages] "${path}" sourceEquivalencies fallback found no external function call source`,
5289
+ );
5290
+ }
5291
+ } else {
5292
+ console.log(
5293
+ `[getEnrichedConditionalUsages] "${path}" sourceEquivalencies["${returnValueKey}"] not found`,
5294
+ );
5295
+ }
5296
+ }
5297
+
5298
+ console.log(
5299
+ `[getEnrichedConditionalUsages] "${path}" FINAL sourceDataPath="${sourceDataPath ?? '(none)'}" (${usages.length} usages)`,
5300
+ );
5301
+
4555
5302
  enriched[path] = usages.map((usage) => ({
4556
5303
  ...usage,
4557
5304
  sourceDataPath,
@@ -4899,11 +5646,22 @@ export class ScopeDataStructure {
4899
5646
  }
4900
5647
  }
4901
5648
 
5649
+ // Enrich the schema with inferred types by applying fillInSchemaGapsAndUnknowns.
5650
+ // This ensures the serialized schema has the same type inference as getReturnValue().
5651
+ // Without this, evidence like "entities[].analyses: array" becomes "unknown".
5652
+ const enrichedSchema = { ...efc.schema };
5653
+ const tempScopeNode = {
5654
+ name: efc.name,
5655
+ schema: enrichedSchema,
5656
+ equivalencies: efc.equivalencies ?? {},
5657
+ };
5658
+ fillInSchemaGapsAndUnknowns(tempScopeNode, true);
5659
+
4902
5660
  return {
4903
5661
  name: efc.name,
4904
5662
  callSignature: efc.callSignature,
4905
5663
  callScope: efc.callScope,
4906
- schema: efc.schema,
5664
+ schema: enrichedSchema,
4907
5665
  equivalencies: efc.equivalencies
4908
5666
  ? Object.entries(efc.equivalencies).reduce(
4909
5667
  (acc, [key, vars]) => {