@codeyam/codeyam-cli 0.1.0-staging.596f0eb → 0.1.0-staging.62d4615

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 (914) hide show
  1. package/analyzer-template/.build-info.json +8 -8
  2. package/analyzer-template/common/execAsync.ts +1 -1
  3. package/analyzer-template/log.txt +3 -3
  4. package/analyzer-template/package.json +16 -12
  5. package/analyzer-template/packages/ai/index.ts +20 -5
  6. package/analyzer-template/packages/ai/package.json +3 -3
  7. package/analyzer-template/packages/ai/src/lib/__mocks__/completionCall.ts +122 -0
  8. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +214 -24
  9. package/analyzer-template/packages/ai/src/lib/astScopes/arrayDerivationDetector.ts +199 -0
  10. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +205 -10
  11. package/analyzer-template/packages/ai/src/lib/astScopes/conditionalEffectsExtractor.ts +644 -0
  12. package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +181 -23
  13. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  14. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/ifStatementHandler.ts +18 -0
  15. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/switchStatementHandler.ts +38 -1
  16. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.ts +181 -1
  17. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +1518 -125
  18. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +318 -5
  19. package/analyzer-template/packages/ai/src/lib/checkAllAttributes.ts +29 -10
  20. package/analyzer-template/packages/ai/src/lib/completionCall.ts +216 -36
  21. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +2301 -348
  22. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +7 -2
  23. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.ts +976 -0
  24. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.ts +243 -77
  25. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +16 -3
  26. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +6 -4
  27. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +71 -2
  28. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +161 -19
  29. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
  30. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +93 -1
  31. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertNullToUndefinedBySchema.ts +98 -0
  32. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +179 -0
  33. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.ts +40 -30
  34. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +422 -86
  35. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.ts +129 -0
  36. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +156 -0
  37. package/analyzer-template/packages/ai/src/lib/deepEqual.ts +30 -0
  38. package/analyzer-template/packages/ai/src/lib/e2eDataTracking.ts +334 -0
  39. package/analyzer-template/packages/ai/src/lib/extractCriticalDataKeys.ts +120 -0
  40. package/analyzer-template/packages/ai/src/lib/generateChangesEntityScenarioData.ts +74 -7
  41. package/analyzer-template/packages/ai/src/lib/generateChangesEntityScenarios.ts +89 -112
  42. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +63 -2
  43. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +1394 -92
  44. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +216 -109
  45. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +578 -0
  46. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +528 -0
  47. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +2267 -0
  48. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +239 -0
  49. package/analyzer-template/packages/ai/src/lib/getConditionalUsagesFromCode.ts +143 -31
  50. package/analyzer-template/packages/ai/src/lib/guessScenarioDataFromDescription.ts +8 -2
  51. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +328 -7
  52. package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +111 -87
  53. package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +17 -7
  54. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateChangesEntityScenarioDataGenerator.ts +1 -1
  55. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateChangesEntityScenariosGenerator.ts +32 -102
  56. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateChunkPrompt.ts +82 -0
  57. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateCriticalKeysPrompt.ts +103 -0
  58. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +90 -6
  59. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenariosGenerator.ts +14 -53
  60. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateMissingKeysPrompt.ts +58 -0
  61. package/analyzer-template/packages/ai/src/lib/promptGenerators/guessNewScenarioDataFromDescriptionGenerator.ts +28 -2
  62. package/analyzer-template/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.ts +391 -0
  63. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +824 -0
  64. package/analyzer-template/packages/ai/src/lib/splitOutsideParentheses.ts +5 -1
  65. package/analyzer-template/packages/ai/src/lib/validateExecutionFlowPaths.ts +531 -0
  66. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +127 -3
  67. package/analyzer-template/packages/ai/src/lib/worker/analyzeScopeWorker.ts +121 -2
  68. package/analyzer-template/packages/analyze/index.ts +2 -0
  69. package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +79 -59
  70. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +113 -26
  71. package/analyzer-template/packages/analyze/src/lib/analysisContext.ts +44 -4
  72. package/analyzer-template/packages/analyze/src/lib/asts/nodes/index.ts +1 -0
  73. package/analyzer-template/packages/analyze/src/lib/asts/nodes/isAsyncFunction.ts +67 -0
  74. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
  75. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
  76. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
  77. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
  78. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
  79. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
  80. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +522 -272
  81. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +34 -1
  82. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +6 -0
  83. package/analyzer-template/packages/analyze/src/lib/files/analyze/findOrCreateEntity.ts +3 -0
  84. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
  85. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +33 -10
  86. package/analyzer-template/packages/analyze/src/lib/files/analyzeChange.ts +31 -15
  87. package/analyzer-template/packages/analyze/src/lib/files/analyzeEntity.ts +11 -7
  88. package/analyzer-template/packages/analyze/src/lib/files/analyzeInitial.ts +11 -12
  89. package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
  90. package/analyzer-template/packages/analyze/src/lib/files/enums/steps.ts +1 -1
  91. package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
  92. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
  93. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +313 -0
  94. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichUnknownTypesFromSourceEquivalencies.ts +102 -0
  95. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +625 -52
  96. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateChangesScenarioData.ts +1 -1
  97. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateChangesScenarios.ts +28 -62
  98. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +550 -137
  99. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +264 -0
  100. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateScenarioData.ts +78 -83
  101. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateScenarios.ts +4 -8
  102. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +917 -130
  103. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.ts +56 -11
  104. package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
  105. package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
  106. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  107. package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
  108. package/analyzer-template/packages/aws/codebuild/index.ts +1 -0
  109. package/analyzer-template/packages/aws/dist/src/lib/codebuild/waitForBuild.d.ts +11 -1
  110. package/analyzer-template/packages/aws/dist/src/lib/codebuild/waitForBuild.d.ts.map +1 -1
  111. package/analyzer-template/packages/aws/dist/src/lib/codebuild/waitForBuild.js +29 -18
  112. package/analyzer-template/packages/aws/dist/src/lib/codebuild/waitForBuild.js.map +1 -1
  113. package/analyzer-template/packages/aws/dist/src/lib/ecs/ecsDefineContainer.d.ts +2 -2
  114. package/analyzer-template/packages/aws/dist/src/lib/ecs/ecsDefineContainer.d.ts.map +1 -1
  115. package/analyzer-template/packages/aws/dist/src/lib/ecs/ecsDefineContainer.js +2 -2
  116. package/analyzer-template/packages/aws/dist/src/lib/ecs/ecsDefineContainer.js.map +1 -1
  117. package/analyzer-template/packages/aws/dist/src/lib/ecs/ecsTaskFactory.d.ts +8 -18
  118. package/analyzer-template/packages/aws/dist/src/lib/ecs/ecsTaskFactory.d.ts.map +1 -1
  119. package/analyzer-template/packages/aws/dist/src/lib/ecs/ecsTaskFactory.js +17 -61
  120. package/analyzer-template/packages/aws/dist/src/lib/ecs/ecsTaskFactory.js.map +1 -1
  121. package/analyzer-template/packages/aws/dist/src/lib/s3/checkS3ObjectExists.d.ts +15 -0
  122. package/analyzer-template/packages/aws/dist/src/lib/s3/checkS3ObjectExists.d.ts.map +1 -0
  123. package/analyzer-template/packages/aws/dist/src/lib/s3/checkS3ObjectExists.js +31 -0
  124. package/analyzer-template/packages/aws/dist/src/lib/s3/checkS3ObjectExists.js.map +1 -0
  125. package/analyzer-template/packages/aws/dist/src/lib/s3/uploadFileToS3.d.ts.map +1 -1
  126. package/analyzer-template/packages/aws/dist/src/lib/s3/uploadFileToS3.js +8 -1
  127. package/analyzer-template/packages/aws/dist/src/lib/s3/uploadFileToS3.js.map +1 -1
  128. package/analyzer-template/packages/aws/package.json +3 -3
  129. package/analyzer-template/packages/aws/s3/index.ts +1 -0
  130. package/analyzer-template/packages/aws/src/lib/codebuild/waitForBuild.ts +43 -19
  131. package/analyzer-template/packages/aws/src/lib/ecs/ecsDefineContainer.ts +3 -3
  132. package/analyzer-template/packages/aws/src/lib/ecs/ecsTaskFactory.ts +17 -69
  133. package/analyzer-template/packages/aws/src/lib/s3/checkS3ObjectExists.ts +47 -0
  134. package/analyzer-template/packages/aws/src/lib/s3/uploadFileToS3.ts +8 -1
  135. package/analyzer-template/packages/database/package.json +1 -1
  136. package/analyzer-template/packages/database/src/lib/kysely/db.ts +12 -5
  137. package/analyzer-template/packages/database/src/lib/kysely/tableRelations.ts +2 -2
  138. package/analyzer-template/packages/database/src/lib/kysely/tables/commitsTable.ts +6 -0
  139. package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +36 -9
  140. package/analyzer-template/packages/database/src/lib/loadAnalyses.ts +58 -1
  141. package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +13 -0
  142. package/analyzer-template/packages/database/src/lib/loadBranch.ts +16 -1
  143. package/analyzer-template/packages/database/src/lib/loadCommit.ts +11 -0
  144. package/analyzer-template/packages/database/src/lib/loadCommits.ts +28 -0
  145. package/analyzer-template/packages/database/src/lib/loadEntities.ts +26 -3
  146. package/analyzer-template/packages/database/src/lib/loadEntityBranches.ts +12 -0
  147. package/analyzer-template/packages/database/src/lib/loadReadyToBeCapturedAnalyses.ts +7 -3
  148. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +7 -14
  149. package/analyzer-template/packages/generate/index.ts +3 -0
  150. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/componentScenarioPageNext.ts +17 -1
  151. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.ts +193 -0
  152. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/generateScenarioServerComponent.ts +73 -0
  153. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.ts +9 -4
  154. package/analyzer-template/packages/generate/src/lib/deepMerge.ts +26 -1
  155. package/analyzer-template/packages/generate/src/lib/scenarioComponentForServer.ts +114 -0
  156. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -2
  157. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  158. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +10 -3
  159. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  160. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tableRelations.d.ts +2 -2
  161. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/analysesTable.d.ts +1 -11
  162. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/analysesTable.d.ts.map +1 -1
  163. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts +1 -0
  164. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts.map +1 -1
  165. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js +3 -0
  166. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  167. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +30 -7
  168. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts.map +1 -1
  169. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.js +9 -3
  170. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.js.map +1 -1
  171. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/entitiesTable.d.ts +1 -0
  172. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/entitiesTable.d.ts.map +1 -1
  173. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts +2 -6
  174. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts.map +1 -1
  175. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts +2 -0
  176. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts.map +1 -1
  177. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js +45 -2
  178. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js.map +1 -1
  179. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
  180. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +8 -0
  181. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
  182. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js +11 -1
  183. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js.map +1 -1
  184. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.d.ts.map +1 -1
  185. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js +7 -0
  186. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js.map +1 -1
  187. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts +3 -1
  188. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  189. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +22 -1
  190. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  191. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts +3 -1
  192. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  193. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +23 -4
  194. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  195. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.d.ts.map +1 -1
  196. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js +9 -0
  197. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js.map +1 -1
  198. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.d.ts.map +1 -1
  199. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js +7 -4
  200. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  201. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts +2 -2
  202. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  203. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +5 -4
  204. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  205. package/analyzer-template/packages/github/dist/generate/index.d.ts +3 -0
  206. package/analyzer-template/packages/github/dist/generate/index.d.ts.map +1 -1
  207. package/analyzer-template/packages/github/dist/generate/index.js +3 -0
  208. package/analyzer-template/packages/github/dist/generate/index.js.map +1 -1
  209. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageNext.d.ts.map +1 -1
  210. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageNext.js +16 -1
  211. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/componentScenarioPageNext.js.map +1 -1
  212. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.d.ts +9 -0
  213. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.d.ts.map +1 -0
  214. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +189 -0
  215. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -0
  216. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioServerComponent.d.ts +20 -0
  217. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioServerComponent.d.ts.map +1 -0
  218. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioServerComponent.js +53 -0
  219. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioServerComponent.js.map +1 -0
  220. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.d.ts.map +1 -1
  221. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +8 -4
  222. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  223. package/analyzer-template/packages/github/dist/generate/src/lib/deepMerge.d.ts.map +1 -1
  224. package/analyzer-template/packages/github/dist/generate/src/lib/deepMerge.js +27 -1
  225. package/analyzer-template/packages/github/dist/generate/src/lib/deepMerge.js.map +1 -1
  226. package/analyzer-template/packages/github/dist/generate/src/lib/scenarioComponentForServer.d.ts +8 -0
  227. package/analyzer-template/packages/github/dist/generate/src/lib/scenarioComponentForServer.d.ts.map +1 -0
  228. package/analyzer-template/packages/github/dist/generate/src/lib/scenarioComponentForServer.js +89 -0
  229. package/analyzer-template/packages/github/dist/generate/src/lib/scenarioComponentForServer.js.map +1 -0
  230. package/analyzer-template/packages/github/dist/github/src/lib/loadOrCreateCommit.d.ts.map +1 -1
  231. package/analyzer-template/packages/github/dist/github/src/lib/loadOrCreateCommit.js +10 -0
  232. package/analyzer-template/packages/github/dist/github/src/lib/loadOrCreateCommit.js.map +1 -1
  233. package/analyzer-template/packages/github/dist/github/src/lib/syncPrimaryBranch.d.ts.map +1 -1
  234. package/analyzer-template/packages/github/dist/github/src/lib/syncPrimaryBranch.js +3 -0
  235. package/analyzer-template/packages/github/dist/github/src/lib/syncPrimaryBranch.js.map +1 -1
  236. package/analyzer-template/packages/github/dist/types/index.d.ts +2 -2
  237. package/analyzer-template/packages/github/dist/types/index.d.ts.map +1 -1
  238. package/analyzer-template/packages/github/dist/types/index.js.map +1 -1
  239. package/analyzer-template/packages/github/dist/types/src/types/Analysis.d.ts +87 -13
  240. package/analyzer-template/packages/github/dist/types/src/types/Analysis.d.ts.map +1 -1
  241. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts +2 -0
  242. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts.map +1 -1
  243. package/analyzer-template/packages/github/dist/types/src/types/Entity.d.ts +2 -0
  244. package/analyzer-template/packages/github/dist/types/src/types/Entity.d.ts.map +1 -1
  245. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +3 -0
  246. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  247. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts +11 -6
  248. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts.map +1 -1
  249. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +199 -3
  250. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  251. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  252. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  253. package/analyzer-template/packages/github/dist/types/src/types/StatementInfo.d.ts +2 -0
  254. package/analyzer-template/packages/github/dist/types/src/types/StatementInfo.d.ts.map +1 -1
  255. package/analyzer-template/packages/github/dist/utils/src/lib/lightweightEntityExtractor.d.ts.map +1 -1
  256. package/analyzer-template/packages/github/dist/utils/src/lib/lightweightEntityExtractor.js +25 -0
  257. package/analyzer-template/packages/github/dist/utils/src/lib/lightweightEntityExtractor.js.map +1 -1
  258. package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.d.ts +9 -1
  259. package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.d.ts.map +1 -1
  260. package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.js +29 -3
  261. package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.js.map +1 -1
  262. package/analyzer-template/packages/github/package.json +1 -1
  263. package/analyzer-template/packages/github/src/lib/loadOrCreateCommit.ts +14 -0
  264. package/analyzer-template/packages/github/src/lib/syncPrimaryBranch.ts +2 -0
  265. package/analyzer-template/packages/process/index.ts +2 -0
  266. package/analyzer-template/packages/process/package.json +12 -0
  267. package/analyzer-template/packages/process/tsconfig.json +8 -0
  268. package/analyzer-template/packages/types/index.ts +5 -0
  269. package/analyzer-template/packages/types/src/types/Analysis.ts +104 -13
  270. package/analyzer-template/packages/types/src/types/Commit.ts +2 -0
  271. package/analyzer-template/packages/types/src/types/Entity.ts +2 -0
  272. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +1 -0
  273. package/analyzer-template/packages/types/src/types/Scenario.ts +11 -10
  274. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +228 -3
  275. package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
  276. package/analyzer-template/packages/types/src/types/StatementInfo.ts +2 -0
  277. package/analyzer-template/packages/ui-components/src/components/ScenarioDetailInteractiveView.tsx +23 -7
  278. package/analyzer-template/packages/utils/dist/types/index.d.ts +2 -2
  279. package/analyzer-template/packages/utils/dist/types/index.d.ts.map +1 -1
  280. package/analyzer-template/packages/utils/dist/types/index.js.map +1 -1
  281. package/analyzer-template/packages/utils/dist/types/src/types/Analysis.d.ts +87 -13
  282. package/analyzer-template/packages/utils/dist/types/src/types/Analysis.d.ts.map +1 -1
  283. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts +2 -0
  284. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts.map +1 -1
  285. package/analyzer-template/packages/utils/dist/types/src/types/Entity.d.ts +2 -0
  286. package/analyzer-template/packages/utils/dist/types/src/types/Entity.d.ts.map +1 -1
  287. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +3 -0
  288. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  289. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts +11 -6
  290. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts.map +1 -1
  291. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +199 -3
  292. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  293. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  294. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  295. package/analyzer-template/packages/utils/dist/types/src/types/StatementInfo.d.ts +2 -0
  296. package/analyzer-template/packages/utils/dist/types/src/types/StatementInfo.d.ts.map +1 -1
  297. package/analyzer-template/packages/utils/dist/utils/src/lib/lightweightEntityExtractor.d.ts.map +1 -1
  298. package/analyzer-template/packages/utils/dist/utils/src/lib/lightweightEntityExtractor.js +25 -0
  299. package/analyzer-template/packages/utils/dist/utils/src/lib/lightweightEntityExtractor.js.map +1 -1
  300. package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.d.ts +9 -1
  301. package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.d.ts.map +1 -1
  302. package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.js +29 -3
  303. package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.js.map +1 -1
  304. package/analyzer-template/packages/utils/src/lib/lightweightEntityExtractor.ts +27 -0
  305. package/analyzer-template/packages/utils/src/lib/safeFileName.ts +48 -3
  306. package/analyzer-template/playwright/capture.ts +57 -26
  307. package/analyzer-template/playwright/captureStatic.ts +1 -1
  308. package/analyzer-template/playwright/getCodeYamInfo.ts +12 -7
  309. package/analyzer-template/playwright/takeElementScreenshot.ts +26 -11
  310. package/analyzer-template/playwright/takeScreenshot.ts +9 -7
  311. package/analyzer-template/playwright/waitForServer.ts +21 -6
  312. package/analyzer-template/project/analyzeBaselineCommit.ts +9 -0
  313. package/analyzer-template/project/analyzeBranchCommit.ts +4 -0
  314. package/analyzer-template/project/analyzeFileEntities.ts +4 -0
  315. package/analyzer-template/project/analyzeRegularCommit.ts +9 -0
  316. package/analyzer-template/project/captureLibraryFunctionDirect.ts +29 -26
  317. package/analyzer-template/project/constructMockCode.ts +1268 -167
  318. package/analyzer-template/project/controller/startController.ts +16 -1
  319. package/analyzer-template/project/createEntitiesAndSortFiles.ts +83 -0
  320. package/analyzer-template/project/executeLibraryFunctionDirect.ts +7 -3
  321. package/analyzer-template/project/loadReadyToBeCaptured.ts +65 -41
  322. package/analyzer-template/project/mocks/analyzeFileMock.ts +8 -7
  323. package/analyzer-template/project/orchestrateCapture/AwsCaptureTaskRunner.ts +12 -4
  324. package/analyzer-template/project/orchestrateCapture/KyselyAnalysisLoader.ts +3 -6
  325. package/analyzer-template/project/orchestrateCapture/SequentialCaptureTaskRunner.ts +93 -42
  326. package/analyzer-template/project/orchestrateCapture/taskRunner.ts +4 -2
  327. package/analyzer-template/project/orchestrateCapture.ts +81 -9
  328. package/analyzer-template/project/reconcileMockDataKeys.ts +245 -2
  329. package/analyzer-template/project/runAnalysis.ts +11 -0
  330. package/analyzer-template/project/runMultiScenarioServer.ts +11 -10
  331. package/analyzer-template/project/serverOnlyModules.ts +194 -21
  332. package/analyzer-template/project/start.ts +61 -15
  333. package/analyzer-template/project/startScenarioCapture.ts +79 -41
  334. package/analyzer-template/project/writeMockDataTsx.ts +405 -65
  335. package/analyzer-template/project/writeScenarioClientWrapper.ts +21 -0
  336. package/analyzer-template/project/writeScenarioComponents.ts +862 -183
  337. package/analyzer-template/project/writeScenarioFiles.ts +26 -0
  338. package/analyzer-template/project/writeSimpleRoot.ts +31 -23
  339. package/analyzer-template/scripts/comboWorkerLoop.cjs +99 -50
  340. package/analyzer-template/scripts/defaultCmd.sh +9 -0
  341. package/analyzer-template/tsconfig.json +2 -1
  342. package/background/src/lib/local/createLocalAnalyzer.js +1 -29
  343. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  344. package/background/src/lib/local/execAsync.js +1 -1
  345. package/background/src/lib/local/execAsync.js.map +1 -1
  346. package/background/src/lib/virtualized/common/execAsync.js +1 -1
  347. package/background/src/lib/virtualized/common/execAsync.js.map +1 -1
  348. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js +7 -1
  349. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js.map +1 -1
  350. package/background/src/lib/virtualized/project/analyzeBranchCommit.js +2 -1
  351. package/background/src/lib/virtualized/project/analyzeBranchCommit.js.map +1 -1
  352. package/background/src/lib/virtualized/project/analyzeFileEntities.js +2 -1
  353. package/background/src/lib/virtualized/project/analyzeFileEntities.js.map +1 -1
  354. package/background/src/lib/virtualized/project/analyzeRegularCommit.js +7 -1
  355. package/background/src/lib/virtualized/project/analyzeRegularCommit.js.map +1 -1
  356. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js +3 -3
  357. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js.map +1 -1
  358. package/background/src/lib/virtualized/project/constructMockCode.js +1126 -126
  359. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  360. package/background/src/lib/virtualized/project/controller/startController.js +11 -1
  361. package/background/src/lib/virtualized/project/controller/startController.js.map +1 -1
  362. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js +73 -1
  363. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js.map +1 -1
  364. package/background/src/lib/virtualized/project/executeLibraryFunctionDirect.js +6 -3
  365. package/background/src/lib/virtualized/project/executeLibraryFunctionDirect.js.map +1 -1
  366. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js +19 -8
  367. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js.map +1 -1
  368. package/background/src/lib/virtualized/project/mocks/analyzeFileMock.js +7 -7
  369. package/background/src/lib/virtualized/project/mocks/analyzeFileMock.js.map +1 -1
  370. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js +2 -2
  371. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js.map +1 -1
  372. package/background/src/lib/virtualized/project/orchestrateCapture/KyselyAnalysisLoader.js +3 -2
  373. package/background/src/lib/virtualized/project/orchestrateCapture/KyselyAnalysisLoader.js.map +1 -1
  374. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js +73 -36
  375. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js.map +1 -1
  376. package/background/src/lib/virtualized/project/orchestrateCapture.js +65 -10
  377. package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
  378. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +204 -2
  379. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
  380. package/background/src/lib/virtualized/project/runAnalysis.js +9 -0
  381. package/background/src/lib/virtualized/project/runAnalysis.js.map +1 -1
  382. package/background/src/lib/virtualized/project/runMultiScenarioServer.js +11 -9
  383. package/background/src/lib/virtualized/project/runMultiScenarioServer.js.map +1 -1
  384. package/background/src/lib/virtualized/project/serverOnlyModules.js +163 -23
  385. package/background/src/lib/virtualized/project/serverOnlyModules.js.map +1 -1
  386. package/background/src/lib/virtualized/project/start.js +53 -15
  387. package/background/src/lib/virtualized/project/start.js.map +1 -1
  388. package/background/src/lib/virtualized/project/startScenarioCapture.js +61 -31
  389. package/background/src/lib/virtualized/project/startScenarioCapture.js.map +1 -1
  390. package/background/src/lib/virtualized/project/writeMockDataTsx.js +354 -54
  391. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  392. package/background/src/lib/virtualized/project/writeScenarioClientWrapper.js +15 -0
  393. package/background/src/lib/virtualized/project/writeScenarioClientWrapper.js.map +1 -0
  394. package/background/src/lib/virtualized/project/writeScenarioComponents.js +624 -127
  395. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  396. package/background/src/lib/virtualized/project/writeScenarioFiles.js +19 -0
  397. package/background/src/lib/virtualized/project/writeScenarioFiles.js.map +1 -1
  398. package/background/src/lib/virtualized/project/writeSimpleRoot.js +31 -21
  399. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  400. package/codeyam-cli/scripts/apply-setup.js +180 -0
  401. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  402. package/codeyam-cli/src/cli.js +9 -1
  403. package/codeyam-cli/src/cli.js.map +1 -1
  404. package/codeyam-cli/src/commands/analyze.js +1 -1
  405. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  406. package/codeyam-cli/src/commands/baseline.js +174 -0
  407. package/codeyam-cli/src/commands/baseline.js.map +1 -0
  408. package/codeyam-cli/src/commands/debug.js +42 -18
  409. package/codeyam-cli/src/commands/debug.js.map +1 -1
  410. package/codeyam-cli/src/commands/default.js +0 -15
  411. package/codeyam-cli/src/commands/default.js.map +1 -1
  412. package/codeyam-cli/src/commands/memory.js +264 -0
  413. package/codeyam-cli/src/commands/memory.js.map +1 -0
  414. package/codeyam-cli/src/commands/recapture.js +226 -0
  415. package/codeyam-cli/src/commands/recapture.js.map +1 -0
  416. package/codeyam-cli/src/commands/report.js +72 -24
  417. package/codeyam-cli/src/commands/report.js.map +1 -1
  418. package/codeyam-cli/src/commands/start.js +8 -12
  419. package/codeyam-cli/src/commands/start.js.map +1 -1
  420. package/codeyam-cli/src/commands/status.js +23 -1
  421. package/codeyam-cli/src/commands/status.js.map +1 -1
  422. package/codeyam-cli/src/commands/test-startup.js +1 -1
  423. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  424. package/codeyam-cli/src/commands/wipe.js +108 -0
  425. package/codeyam-cli/src/commands/wipe.js.map +1 -0
  426. package/codeyam-cli/src/utils/__tests__/serverVersionStaleness.test.js +81 -0
  427. package/codeyam-cli/src/utils/__tests__/serverVersionStaleness.test.js.map +1 -0
  428. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +31 -27
  429. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  430. package/codeyam-cli/src/utils/analysisRunner.js +29 -15
  431. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  432. package/codeyam-cli/src/utils/backgroundServer.js +18 -4
  433. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  434. package/codeyam-cli/src/utils/database.js +91 -5
  435. package/codeyam-cli/src/utils/database.js.map +1 -1
  436. package/codeyam-cli/src/utils/generateReport.js +253 -106
  437. package/codeyam-cli/src/utils/generateReport.js.map +1 -1
  438. package/codeyam-cli/src/utils/git.js +79 -0
  439. package/codeyam-cli/src/utils/git.js.map +1 -0
  440. package/codeyam-cli/src/utils/install-skills.js +76 -17
  441. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  442. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js +38 -0
  443. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js.map +1 -1
  444. package/codeyam-cli/src/utils/queue/job.js +249 -16
  445. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  446. package/codeyam-cli/src/utils/queue/manager.js +25 -7
  447. package/codeyam-cli/src/utils/queue/manager.js.map +1 -1
  448. package/codeyam-cli/src/utils/queue/persistence.js.map +1 -1
  449. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  450. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  451. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +128 -0
  452. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  453. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  454. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  455. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  456. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  457. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  458. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  459. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  460. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  461. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +75 -0
  462. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  463. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +285 -0
  464. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  465. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +83 -0
  466. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  467. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  468. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  469. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  470. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  471. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +96 -0
  472. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  473. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  474. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  475. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +33 -0
  476. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  477. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  478. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  479. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  480. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  481. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  482. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  483. package/codeyam-cli/src/utils/rules/index.js +6 -0
  484. package/codeyam-cli/src/utils/rules/index.js.map +1 -0
  485. package/codeyam-cli/src/utils/rules/parser.js +78 -0
  486. package/codeyam-cli/src/utils/rules/parser.js.map +1 -0
  487. package/codeyam-cli/src/utils/rules/pathMatcher.js +18 -0
  488. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -0
  489. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  490. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  491. package/codeyam-cli/src/utils/rules/staleness.js +137 -0
  492. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -0
  493. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  494. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +7 -5
  495. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  496. package/codeyam-cli/src/utils/versionInfo.js +25 -19
  497. package/codeyam-cli/src/utils/versionInfo.js.map +1 -1
  498. package/codeyam-cli/src/utils/wipe.js +128 -0
  499. package/codeyam-cli/src/utils/wipe.js.map +1 -0
  500. package/codeyam-cli/src/webserver/app/lib/database.js +104 -3
  501. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  502. package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
  503. package/codeyam-cli/src/webserver/backgroundServer.js +5 -10
  504. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  505. package/codeyam-cli/src/webserver/bootstrap.js +49 -0
  506. package/codeyam-cli/src/webserver/bootstrap.js.map +1 -0
  507. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CA3JxPb7.js +1 -0
  508. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-B86KKU7e.js +11 -0
  509. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-efWKDYMr.js → EntityTypeBadge-B5ctlSYt.js} +1 -1
  510. package/codeyam-cli/src/webserver/build/client/assets/EntityTypeIcon-BqY8gDAW.js +41 -0
  511. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-ClaLpuOo.js +34 -0
  512. package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-BDhPilK7.js +25 -0
  513. package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-VeqEBv9v.js +3 -0
  514. package/codeyam-cli/src/webserver/build/client/assets/LoadingDots-Bs7Nn1Jr.js +6 -0
  515. package/codeyam-cli/src/webserver/build/client/assets/LogViewer-Bm3PmcCz.js +3 -0
  516. package/codeyam-cli/src/webserver/build/client/assets/ReportIssueModal-C6PKeMYR.js +11 -0
  517. package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-Gq3Ocjo6.js +1 -0
  518. package/codeyam-cli/src/webserver/build/client/assets/ScenarioViewer-BNLaXBHR.js +10 -0
  519. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-COPstp9J.js → TruncatedFilePath-CiwXDxLh.js} +1 -1
  520. package/codeyam-cli/src/webserver/build/client/assets/_index-B3TDXxnk.js +11 -0
  521. package/codeyam-cli/src/webserver/build/client/assets/activity.(_tab)-DD1r_QU0.js +27 -0
  522. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-DfKzxuoe.js +11 -0
  523. package/codeyam-cli/src/webserver/build/client/assets/api.agent-transcripts-l0sNRNKZ.js +1 -0
  524. package/codeyam-cli/src/webserver/build/client/assets/api.health-l0sNRNKZ.js +1 -0
  525. package/codeyam-cli/src/webserver/build/client/assets/api.memory-profile-l0sNRNKZ.js +1 -0
  526. package/codeyam-cli/src/webserver/build/client/assets/api.restart-server-l0sNRNKZ.js +1 -0
  527. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  528. package/codeyam-cli/src/webserver/build/client/assets/book-open-PttOB2SF.js +6 -0
  529. package/codeyam-cli/src/webserver/build/client/assets/chevron-down-TJp6ofnp.js +6 -0
  530. package/codeyam-cli/src/webserver/build/client/assets/chunk-JZWAC4HX-JE9ZIoBl.js +51 -0
  531. package/codeyam-cli/src/webserver/build/client/assets/circle-check-CXhHQYrI.js +6 -0
  532. package/codeyam-cli/src/webserver/build/client/assets/copy-6y9ALfGT.js +11 -0
  533. package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-Ca9fAY46.js +21 -0
  534. package/codeyam-cli/src/webserver/build/client/assets/{cy-logo-cli-C1gnJVOL.svg → cy-logo-cli-CCKUIm0S.svg} +2 -2
  535. package/codeyam-cli/src/webserver/build/client/assets/cy-logo-cli-DcX-ZS3p.js +1 -0
  536. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-C5lqplTC.js +1 -0
  537. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-n38keI1k.js +23 -0
  538. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-CBoafmVs.js +6 -0
  539. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-DGgZjdFg.js +6 -0
  540. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.edit._scenarioId-38yPijoD.js +5 -0
  541. package/codeyam-cli/src/webserver/build/client/assets/entry.client-BSHEfydn.js +29 -0
  542. package/codeyam-cli/src/webserver/build/client/assets/executionFlowCoverage-BWhdfn70.js +1 -0
  543. package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-DCPhhSMo.js +1 -0
  544. package/codeyam-cli/src/webserver/build/client/assets/files-Dk8wkAS7.js +1 -0
  545. package/codeyam-cli/src/webserver/build/client/assets/git-DXnyr8uP.js +15 -0
  546. package/codeyam-cli/src/webserver/build/client/assets/globals-Bh6jH0cL.css +1 -0
  547. package/codeyam-cli/src/webserver/build/client/assets/html2canvas-pro.esm-fmIEn3Bc.js +9 -0
  548. package/codeyam-cli/src/webserver/build/client/assets/index-CcsFv748.js +3 -0
  549. package/codeyam-cli/src/webserver/build/client/assets/index-ChN9-fAY.js +9 -0
  550. package/codeyam-cli/src/webserver/build/client/assets/labs-BUvfJMNR.js +1 -0
  551. package/codeyam-cli/src/webserver/build/client/assets/loader-circle-CTqLEAGU.js +6 -0
  552. package/codeyam-cli/src/webserver/build/client/assets/manifest-d4e77269.js +1 -0
  553. package/codeyam-cli/src/webserver/build/client/assets/memory-DCHBwHou.js +76 -0
  554. package/codeyam-cli/src/webserver/build/client/assets/pause-D6vreykR.js +11 -0
  555. package/codeyam-cli/src/webserver/build/client/assets/preload-helper-ckwbz45p.js +1 -0
  556. package/codeyam-cli/src/webserver/build/client/assets/root-D6oziHts.js +62 -0
  557. package/codeyam-cli/src/webserver/build/client/assets/scenarioStatus-B_8jpV3e.js +1 -0
  558. package/codeyam-cli/src/webserver/build/client/assets/search-B8VUL8nl.js +6 -0
  559. package/codeyam-cli/src/webserver/build/client/assets/settings-B2X7lJgQ.js +1 -0
  560. package/codeyam-cli/src/webserver/build/client/assets/simulations-CPoAg7Zo.js +1 -0
  561. package/codeyam-cli/src/webserver/build/client/assets/terminal-BrCP7uQo.js +11 -0
  562. package/codeyam-cli/src/webserver/build/client/assets/triangle-alert-BZz2NjYa.js +6 -0
  563. package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-DNwUduNu.js +1 -0
  564. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-3pmpUQB-.js → useLastLogLine-COky1GVF.js} +1 -1
  565. package/codeyam-cli/src/webserver/build/client/assets/useReportContext-CpZgwliL.js +1 -0
  566. package/codeyam-cli/src/webserver/build/client/assets/{useToast-DEyawJ8r.js → useToast-Bv9JFvUO.js} +1 -1
  567. package/codeyam-cli/src/webserver/build/server/assets/index-C0KrUQp-.js +1 -0
  568. package/codeyam-cli/src/webserver/build/server/assets/server-build-C2h1v1XD.js +260 -0
  569. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  570. package/codeyam-cli/src/webserver/build-info.json +5 -5
  571. package/codeyam-cli/src/webserver/devServer.js +1 -3
  572. package/codeyam-cli/src/webserver/devServer.js.map +1 -1
  573. package/codeyam-cli/src/webserver/server.js +35 -25
  574. package/codeyam-cli/src/webserver/server.js.map +1 -1
  575. package/codeyam-cli/templates/codeyam-memory-hook.sh +199 -0
  576. package/codeyam-cli/templates/{codeyam-debug-skill.md → codeyam:debug.md} +48 -4
  577. package/codeyam-cli/templates/codeyam:diagnose.md +803 -0
  578. package/codeyam-cli/templates/codeyam:memory.md +404 -0
  579. package/codeyam-cli/templates/codeyam:new-rule.md +13 -0
  580. package/codeyam-cli/templates/{codeyam-setup-skill.md → codeyam:setup.md} +139 -4
  581. package/codeyam-cli/templates/{codeyam-sim-skill.md → codeyam:sim.md} +1 -1
  582. package/codeyam-cli/templates/{codeyam-test-skill.md → codeyam:test.md} +1 -1
  583. package/codeyam-cli/templates/{codeyam-verify-skill.md → codeyam:verify.md} +1 -1
  584. package/codeyam-cli/templates/rule-notification-hook.py +54 -0
  585. package/codeyam-cli/templates/rule-reflection-hook.py +428 -0
  586. package/codeyam-cli/templates/rules-instructions.md +123 -0
  587. package/package.json +22 -19
  588. package/packages/ai/index.js +8 -6
  589. package/packages/ai/index.js.map +1 -1
  590. package/packages/ai/src/lib/analyzeScope.js +167 -13
  591. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  592. package/packages/ai/src/lib/astScopes/arrayDerivationDetector.js +150 -0
  593. package/packages/ai/src/lib/astScopes/arrayDerivationDetector.js.map +1 -0
  594. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +154 -9
  595. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  596. package/packages/ai/src/lib/astScopes/conditionalEffectsExtractor.js +435 -0
  597. package/packages/ai/src/lib/astScopes/conditionalEffectsExtractor.js.map +1 -0
  598. package/packages/ai/src/lib/astScopes/methodSemantics.js +138 -23
  599. package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
  600. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  601. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  602. package/packages/ai/src/lib/astScopes/patterns/ifStatementHandler.js +8 -0
  603. package/packages/ai/src/lib/astScopes/patterns/ifStatementHandler.js.map +1 -1
  604. package/packages/ai/src/lib/astScopes/patterns/switchStatementHandler.js +23 -0
  605. package/packages/ai/src/lib/astScopes/patterns/switchStatementHandler.js.map +1 -1
  606. package/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.js +138 -1
  607. package/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.js.map +1 -1
  608. package/packages/ai/src/lib/astScopes/processExpression.js +1157 -103
  609. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  610. package/packages/ai/src/lib/checkAllAttributes.js +24 -9
  611. package/packages/ai/src/lib/checkAllAttributes.js.map +1 -1
  612. package/packages/ai/src/lib/completionCall.js +178 -31
  613. package/packages/ai/src/lib/completionCall.js.map +1 -1
  614. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +1816 -216
  615. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  616. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +7 -2
  617. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  618. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.js +661 -0
  619. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.js.map +1 -0
  620. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.js +180 -56
  621. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.js.map +1 -1
  622. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
  623. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
  624. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
  625. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
  626. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +66 -2
  627. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  628. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +139 -13
  629. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  630. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  631. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  632. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +83 -1
  633. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  634. package/packages/ai/src/lib/dataStructure/helpers/convertNullToUndefinedBySchema.js +86 -0
  635. package/packages/ai/src/lib/dataStructure/helpers/convertNullToUndefinedBySchema.js.map +1 -0
  636. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
  637. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
  638. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
  639. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
  640. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +355 -77
  641. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  642. package/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.js +107 -0
  643. package/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.js.map +1 -0
  644. package/packages/ai/src/lib/dataStructureChunking.js +111 -0
  645. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -0
  646. package/packages/ai/src/lib/deepEqual.js +32 -0
  647. package/packages/ai/src/lib/deepEqual.js.map +1 -0
  648. package/packages/ai/src/lib/e2eDataTracking.js +241 -0
  649. package/packages/ai/src/lib/e2eDataTracking.js.map +1 -0
  650. package/packages/ai/src/lib/extractCriticalDataKeys.js +96 -0
  651. package/packages/ai/src/lib/extractCriticalDataKeys.js.map +1 -0
  652. package/packages/ai/src/lib/generateChangesEntityScenarioData.js +62 -5
  653. package/packages/ai/src/lib/generateChangesEntityScenarioData.js.map +1 -1
  654. package/packages/ai/src/lib/generateChangesEntityScenarios.js +81 -90
  655. package/packages/ai/src/lib/generateChangesEntityScenarios.js.map +1 -1
  656. package/packages/ai/src/lib/generateEntityDataStructure.js +50 -1
  657. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  658. package/packages/ai/src/lib/generateEntityScenarioData.js +1109 -85
  659. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  660. package/packages/ai/src/lib/generateEntityScenarios.js +193 -83
  661. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  662. package/packages/ai/src/lib/generateExecutionFlows.js +400 -0
  663. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -0
  664. package/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.js +380 -0
  665. package/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.js.map +1 -0
  666. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +1646 -0
  667. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -0
  668. package/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.js +194 -0
  669. package/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.js.map +1 -0
  670. package/packages/ai/src/lib/getConditionalUsagesFromCode.js +84 -14
  671. package/packages/ai/src/lib/getConditionalUsagesFromCode.js.map +1 -1
  672. package/packages/ai/src/lib/guessScenarioDataFromDescription.js +2 -1
  673. package/packages/ai/src/lib/guessScenarioDataFromDescription.js.map +1 -1
  674. package/packages/ai/src/lib/isolateScopes.js +270 -7
  675. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  676. package/packages/ai/src/lib/mergeStatements.js +88 -46
  677. package/packages/ai/src/lib/mergeStatements.js.map +1 -1
  678. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +16 -4
  679. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
  680. package/packages/ai/src/lib/promptGenerators/generateChangesEntityScenarioDataGenerator.js +1 -1
  681. package/packages/ai/src/lib/promptGenerators/generateChangesEntityScenarioDataGenerator.js.map +1 -1
  682. package/packages/ai/src/lib/promptGenerators/generateChangesEntityScenariosGenerator.js +21 -64
  683. package/packages/ai/src/lib/promptGenerators/generateChangesEntityScenariosGenerator.js.map +1 -1
  684. package/packages/ai/src/lib/promptGenerators/generateChunkPrompt.js +54 -0
  685. package/packages/ai/src/lib/promptGenerators/generateChunkPrompt.js.map +1 -0
  686. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +68 -6
  687. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  688. package/packages/ai/src/lib/promptGenerators/generateEntityScenariosGenerator.js +10 -34
  689. package/packages/ai/src/lib/promptGenerators/generateEntityScenariosGenerator.js.map +1 -1
  690. package/packages/ai/src/lib/promptGenerators/generateMissingKeysPrompt.js +45 -0
  691. package/packages/ai/src/lib/promptGenerators/generateMissingKeysPrompt.js.map +1 -0
  692. package/packages/ai/src/lib/promptGenerators/guessNewScenarioDataFromDescriptionGenerator.js +16 -3
  693. package/packages/ai/src/lib/promptGenerators/guessNewScenarioDataFromDescriptionGenerator.js.map +1 -1
  694. package/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.js +335 -0
  695. package/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.js.map +1 -0
  696. package/packages/ai/src/lib/resolvePathToControllable.js +677 -0
  697. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -0
  698. package/packages/ai/src/lib/splitOutsideParentheses.js +3 -1
  699. package/packages/ai/src/lib/splitOutsideParentheses.js.map +1 -1
  700. package/packages/ai/src/lib/worker/SerializableDataStructure.js +29 -0
  701. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  702. package/packages/ai/src/lib/worker/analyzeScopeWorker.js +98 -1
  703. package/packages/ai/src/lib/worker/analyzeScopeWorker.js.map +1 -1
  704. package/packages/analyze/index.js +1 -0
  705. package/packages/analyze/index.js.map +1 -1
  706. package/packages/analyze/src/lib/FileAnalyzer.js +75 -36
  707. package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
  708. package/packages/analyze/src/lib/ProjectAnalyzer.js +96 -26
  709. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  710. package/packages/analyze/src/lib/analysisContext.js +30 -5
  711. package/packages/analyze/src/lib/analysisContext.js.map +1 -1
  712. package/packages/analyze/src/lib/asts/nodes/index.js +1 -0
  713. package/packages/analyze/src/lib/asts/nodes/index.js.map +1 -1
  714. package/packages/analyze/src/lib/asts/nodes/isAsyncFunction.js +52 -0
  715. package/packages/analyze/src/lib/asts/nodes/isAsyncFunction.js.map +1 -0
  716. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
  717. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
  718. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
  719. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
  720. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
  721. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
  722. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
  723. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
  724. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
  725. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
  726. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
  727. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
  728. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +268 -52
  729. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  730. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +24 -1
  731. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  732. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +5 -0
  733. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  734. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js +2 -0
  735. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js.map +1 -1
  736. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
  737. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  738. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +31 -10
  739. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  740. package/packages/analyze/src/lib/files/analyzeChange.js +21 -11
  741. package/packages/analyze/src/lib/files/analyzeChange.js.map +1 -1
  742. package/packages/analyze/src/lib/files/analyzeEntity.js +9 -8
  743. package/packages/analyze/src/lib/files/analyzeEntity.js.map +1 -1
  744. package/packages/analyze/src/lib/files/analyzeInitial.js +9 -10
  745. package/packages/analyze/src/lib/files/analyzeInitial.js.map +1 -1
  746. package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
  747. package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
  748. package/packages/analyze/src/lib/files/enums/steps.js +1 -1
  749. package/packages/analyze/src/lib/files/enums/steps.js.map +1 -1
  750. package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
  751. package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
  752. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
  753. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  754. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +255 -0
  755. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -0
  756. package/packages/analyze/src/lib/files/scenarios/enrichUnknownTypesFromSourceEquivalencies.js +85 -0
  757. package/packages/analyze/src/lib/files/scenarios/enrichUnknownTypesFromSourceEquivalencies.js.map +1 -0
  758. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +483 -48
  759. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  760. package/packages/analyze/src/lib/files/scenarios/generateChangesScenarioData.js +1 -1
  761. package/packages/analyze/src/lib/files/scenarios/generateChangesScenarioData.js.map +1 -1
  762. package/packages/analyze/src/lib/files/scenarios/generateChangesScenarios.js +29 -34
  763. package/packages/analyze/src/lib/files/scenarios/generateChangesScenarios.js.map +1 -1
  764. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +404 -85
  765. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  766. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +144 -0
  767. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -0
  768. package/packages/analyze/src/lib/files/scenarios/generateScenarioData.js +56 -69
  769. package/packages/analyze/src/lib/files/scenarios/generateScenarioData.js.map +1 -1
  770. package/packages/analyze/src/lib/files/scenarios/generateScenarios.js +4 -8
  771. package/packages/analyze/src/lib/files/scenarios/generateScenarios.js.map +1 -1
  772. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +768 -117
  773. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  774. package/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.js +46 -9
  775. package/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.js.map +1 -1
  776. package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
  777. package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
  778. package/packages/analyze/src/lib/index.js +1 -0
  779. package/packages/analyze/src/lib/index.js.map +1 -1
  780. package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
  781. package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
  782. package/packages/aws/src/lib/ecs/ecsDefineContainer.js +2 -2
  783. package/packages/aws/src/lib/ecs/ecsDefineContainer.js.map +1 -1
  784. package/packages/aws/src/lib/ecs/ecsTaskFactory.js +17 -61
  785. package/packages/aws/src/lib/ecs/ecsTaskFactory.js.map +1 -1
  786. package/packages/database/src/lib/kysely/db.js +10 -3
  787. package/packages/database/src/lib/kysely/db.js.map +1 -1
  788. package/packages/database/src/lib/kysely/tables/commitsTable.js +3 -0
  789. package/packages/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  790. package/packages/database/src/lib/kysely/tables/debugReportsTable.js +9 -3
  791. package/packages/database/src/lib/kysely/tables/debugReportsTable.js.map +1 -1
  792. package/packages/database/src/lib/loadAnalyses.js +45 -2
  793. package/packages/database/src/lib/loadAnalyses.js.map +1 -1
  794. package/packages/database/src/lib/loadAnalysis.js +8 -0
  795. package/packages/database/src/lib/loadAnalysis.js.map +1 -1
  796. package/packages/database/src/lib/loadBranch.js +11 -1
  797. package/packages/database/src/lib/loadBranch.js.map +1 -1
  798. package/packages/database/src/lib/loadCommit.js +7 -0
  799. package/packages/database/src/lib/loadCommit.js.map +1 -1
  800. package/packages/database/src/lib/loadCommits.js +22 -1
  801. package/packages/database/src/lib/loadCommits.js.map +1 -1
  802. package/packages/database/src/lib/loadEntities.js +23 -4
  803. package/packages/database/src/lib/loadEntities.js.map +1 -1
  804. package/packages/database/src/lib/loadEntityBranches.js +9 -0
  805. package/packages/database/src/lib/loadEntityBranches.js.map +1 -1
  806. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js +7 -4
  807. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  808. package/packages/database/src/lib/updateCommitMetadata.js +5 -4
  809. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  810. package/packages/generate/index.js +3 -0
  811. package/packages/generate/index.js.map +1 -1
  812. package/packages/generate/src/lib/componentScenarioPage/componentScenarioPageNext.js +16 -1
  813. package/packages/generate/src/lib/componentScenarioPage/componentScenarioPageNext.js.map +1 -1
  814. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +189 -0
  815. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -0
  816. package/packages/generate/src/lib/componentScenarioPage/generateScenarioServerComponent.js +53 -0
  817. package/packages/generate/src/lib/componentScenarioPage/generateScenarioServerComponent.js.map +1 -0
  818. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +8 -4
  819. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  820. package/packages/generate/src/lib/deepMerge.js +27 -1
  821. package/packages/generate/src/lib/deepMerge.js.map +1 -1
  822. package/packages/generate/src/lib/scenarioComponentForServer.js +89 -0
  823. package/packages/generate/src/lib/scenarioComponentForServer.js.map +1 -0
  824. package/packages/github/src/lib/loadOrCreateCommit.js +10 -0
  825. package/packages/github/src/lib/loadOrCreateCommit.js.map +1 -1
  826. package/packages/github/src/lib/syncPrimaryBranch.js +3 -0
  827. package/packages/github/src/lib/syncPrimaryBranch.js.map +1 -1
  828. package/packages/process/index.js +3 -0
  829. package/packages/process/index.js.map +1 -0
  830. package/packages/process/src/GlobalProcessManager.js.map +1 -0
  831. package/{background/src/lib/process → packages/process/src}/ProcessManager.js +1 -1
  832. package/packages/process/src/ProcessManager.js.map +1 -0
  833. package/packages/process/src/index.js.map +1 -0
  834. package/packages/process/src/managedExecAsync.js.map +1 -0
  835. package/packages/types/index.js.map +1 -1
  836. package/packages/utils/src/lib/lightweightEntityExtractor.js +25 -0
  837. package/packages/utils/src/lib/lightweightEntityExtractor.js.map +1 -1
  838. package/packages/utils/src/lib/safeFileName.js +29 -3
  839. package/packages/utils/src/lib/safeFileName.js.map +1 -1
  840. package/scripts/finalize-analyzer.cjs +6 -4
  841. package/analyzer-template/packages/ai/src/lib/findMatchingAttribute.ts +0 -102
  842. package/analyzer-template/packages/ai/src/lib/gatherRelevantDependentKeyAttributes.ts +0 -197
  843. package/analyzer-template/packages/ai/src/lib/generateChangesEntityKeyAttributes.ts +0 -271
  844. package/analyzer-template/packages/ai/src/lib/generateEntityKeyAttributes.ts +0 -294
  845. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityKeyAttributesGenerator.ts +0 -67
  846. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateKeyAttributes.ts +0 -115
  847. package/analyzer-template/process/INTEGRATION_COMPLETE.md +0 -333
  848. package/analyzer-template/process/INTEGRATION_EXAMPLE.md +0 -525
  849. package/analyzer-template/process/README.md +0 -507
  850. package/background/src/lib/process/GlobalProcessManager.js.map +0 -1
  851. package/background/src/lib/process/ProcessManager.js.map +0 -1
  852. package/background/src/lib/process/index.js.map +0 -1
  853. package/background/src/lib/process/managedExecAsync.js.map +0 -1
  854. package/codeyam-cli/scripts/fixtures/cal.com/universal-mocks/packages/prisma/index.js +0 -238
  855. package/codeyam-cli/scripts/fixtures/cal.com/universal-mocks/packages/prisma/index.js.map +0 -1
  856. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-CVbSvOjo.js +0 -1
  857. package/codeyam-cli/src/webserver/build/client/assets/EntityTypeIcon-DcwcHyl5.js +0 -1
  858. package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-WgwC1GfJ.js +0 -26
  859. package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-IEKom9O2.js +0 -3
  860. package/codeyam-cli/src/webserver/build/client/assets/LogViewer-BYnfxbUG.js +0 -3
  861. package/codeyam-cli/src/webserver/build/client/assets/ReportIssueModal-_lBPJCzG.js +0 -1
  862. package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-lHVhvsu_.js +0 -1
  863. package/codeyam-cli/src/webserver/build/client/assets/ScenarioViewer-d_TBk4GQ.js +0 -5
  864. package/codeyam-cli/src/webserver/build/client/assets/_index-kGT7VUqj.js +0 -1
  865. package/codeyam-cli/src/webserver/build/client/assets/activity.(_tab)-DDGmhu7P.js +0 -7
  866. package/codeyam-cli/src/webserver/build/client/assets/chevron-down-n_HPRfM_.js +0 -1
  867. package/codeyam-cli/src/webserver/build/client/assets/chunk-WWGJGFF6-CbVoyx1U.js +0 -26
  868. package/codeyam-cli/src/webserver/build/client/assets/circle-check-D1VOYveA.js +0 -1
  869. package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-YR8jjAlu.js +0 -1
  870. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-B8vP3V_s.js +0 -1
  871. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-CN6aLCT1.js +0 -16
  872. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-DA5Jeu2P.js +0 -1
  873. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.edit._scenarioId-BTeitalf.js +0 -5
  874. package/codeyam-cli/src/webserver/build/client/assets/entry.client-du6UEYD-.js +0 -13
  875. package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-BpjkhMoi.js +0 -1
  876. package/codeyam-cli/src/webserver/build/client/assets/files-BQGvk4lJ.js +0 -1
  877. package/codeyam-cli/src/webserver/build/client/assets/git-DVdYRT-I.js +0 -12
  878. package/codeyam-cli/src/webserver/build/client/assets/globals-CO-U8Bpo.css +0 -1
  879. package/codeyam-cli/src/webserver/build/client/assets/html2canvas-pro.esm-XQCGvadH.js +0 -5
  880. package/codeyam-cli/src/webserver/build/client/assets/index-DCG-vks0.js +0 -1
  881. package/codeyam-cli/src/webserver/build/client/assets/loader-circle-GazdNeLl.js +0 -1
  882. package/codeyam-cli/src/webserver/build/client/assets/manifest-0b694d28.js +0 -1
  883. package/codeyam-cli/src/webserver/build/client/assets/root-D3tQP7hx.js +0 -16
  884. package/codeyam-cli/src/webserver/build/client/assets/search-CIY6XmtE.js +0 -1
  885. package/codeyam-cli/src/webserver/build/client/assets/server-build-CMKNK2uU.css +0 -1
  886. package/codeyam-cli/src/webserver/build/client/assets/settings-CoMDgElu.js +0 -1
  887. package/codeyam-cli/src/webserver/build/client/assets/simulations-agkniXp2.js +0 -1
  888. package/codeyam-cli/src/webserver/build/client/assets/triangle-alert-B2VUcygF.js +0 -1
  889. package/codeyam-cli/src/webserver/build/client/assets/useReportContext-EvdK-zXP.js +0 -1
  890. package/codeyam-cli/src/webserver/build/server/assets/index-DGVHQEXD.js +0 -1
  891. package/codeyam-cli/src/webserver/build/server/assets/server-build-CghkTkIL.js +0 -166
  892. package/codeyam-cli/templates/debug-command.md +0 -303
  893. package/packages/ai/src/lib/findMatchingAttribute.js +0 -77
  894. package/packages/ai/src/lib/findMatchingAttribute.js.map +0 -1
  895. package/packages/ai/src/lib/gatherRelevantDependentKeyAttributes.js +0 -136
  896. package/packages/ai/src/lib/gatherRelevantDependentKeyAttributes.js.map +0 -1
  897. package/packages/ai/src/lib/generateChangesEntityKeyAttributes.js +0 -220
  898. package/packages/ai/src/lib/generateChangesEntityKeyAttributes.js.map +0 -1
  899. package/packages/ai/src/lib/generateEntityKeyAttributes.js +0 -241
  900. package/packages/ai/src/lib/generateEntityKeyAttributes.js.map +0 -1
  901. package/packages/ai/src/lib/isFrontend.js +0 -5
  902. package/packages/ai/src/lib/isFrontend.js.map +0 -1
  903. package/packages/ai/src/lib/promptGenerators/generateEntityKeyAttributesGenerator.js +0 -40
  904. package/packages/ai/src/lib/promptGenerators/generateEntityKeyAttributesGenerator.js.map +0 -1
  905. package/packages/analyze/src/lib/files/scenarios/generateKeyAttributes.js +0 -72
  906. package/packages/analyze/src/lib/files/scenarios/generateKeyAttributes.js.map +0 -1
  907. /package/analyzer-template/{process → packages/process/src}/GlobalProcessManager.ts +0 -0
  908. /package/analyzer-template/{process → packages/process/src}/ProcessManager.ts +0 -0
  909. /package/analyzer-template/{process → packages/process/src}/index.ts +0 -0
  910. /package/analyzer-template/{process → packages/process/src}/managedExecAsync.ts +0 -0
  911. /package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-CMKNK2uU.css → styles-CMKNK2uU.css} +0 -0
  912. /package/{background/src/lib/process → packages/process/src}/GlobalProcessManager.js +0 -0
  913. /package/{background/src/lib/process → packages/process/src}/index.js +0 -0
  914. /package/{background/src/lib/process → packages/process/src}/managedExecAsync.js +0 -0
@@ -79,15 +79,29 @@
79
79
  * - `helpers/README.md` - Overview of the helper module architecture
80
80
  */
81
81
  import fillInSchemaGapsAndUnknowns from "./helpers/fillInSchemaGapsAndUnknowns.js";
82
+ import { clearCleanKnownObjectFunctionsCache } from "./helpers/cleanKnownObjectFunctions.js";
83
+ import { clearCleanNonObjectFunctionsCache } from "./helpers/cleanNonObjectFunctions.js";
84
+ /**
85
+ * Patterns that indicate recursive type structures in schema paths.
86
+ * Used by hasExcessivePatternRepetition() to detect exponential path blowup.
87
+ */
88
+ const RECURSIVE_PATH_PATTERNS = [
89
+ /\.attributes\.properties\[\]/g, // TypeScript AST JSX nodes
90
+ /\.children\[\]/g, // Tree structures
91
+ /\.elements\[\]/g, // Array-like structures
92
+ /\.members\[\]/g, // Class/interface members
93
+ /\.properties\[\]/g, // Object properties
94
+ /\.items\[\]/g, // Generic items arrays
95
+ ];
82
96
  import ensureSchemaConsistency from "./helpers/ensureSchemaConsistency.js";
83
97
  import cleanPath from "./helpers/cleanPath.js";
84
98
  import { PathManager } from "./helpers/PathManager.js";
85
- import { uniqueId, uniqueScopeVariables, uniqueScopeAndPaths, } from "./helpers/uniqueIdUtils.js";
99
+ import { uniqueId, uniqueScopeAndPaths, uniqueScopeVariables, } from "./helpers/uniqueIdUtils.js";
86
100
  import selectBestValue from "./helpers/selectBestValue.js";
87
101
  import { VisitedTracker } from "./helpers/VisitedTracker.js";
88
102
  import { DebugTracer } from "./helpers/DebugTracer.js";
89
103
  import { BatchSchemaProcessor } from "./helpers/BatchSchemaProcessor.js";
90
- import { ScopeTreeManager, ROOT_SCOPE_NAME, } from "./helpers/ScopeTreeManager.js";
104
+ import { ROOT_SCOPE_NAME, ScopeTreeManager, } from "./helpers/ScopeTreeManager.js";
91
105
  import cleanScopeNodeName from "./helpers/cleanScopeNodeName.js";
92
106
  import getFunctionCallRoot from "./helpers/getFunctionCallRoot.js";
93
107
  import cleanPathOfNonTransformingFunctions from "./helpers/cleanPathOfNonTransformingFunctions.js";
@@ -108,6 +122,17 @@ export function resetScopeDataStructureMetrics() {
108
122
  followEquivalenciesEarlyExitPhase1Count = 0;
109
123
  followEquivalenciesWithWorkCount = 0;
110
124
  addEquivalencyCallCount = 0;
125
+ // Clear module-level caches to prevent unbounded memory growth across entities
126
+ const knownObjectCache = clearCleanKnownObjectFunctionsCache();
127
+ const nonObjectCache = clearCleanNonObjectFunctionsCache();
128
+ if (knownObjectCache.count > 0 || nonObjectCache.count > 0) {
129
+ const totalBytes = knownObjectCache.estimatedBytes + nonObjectCache.estimatedBytes;
130
+ console.log('CodeYam: Cleared analysis caches', {
131
+ knownObjectCache: `${knownObjectCache.count} entries, ${(knownObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
132
+ nonObjectCache: `${nonObjectCache.count} entries, ${(nonObjectCache.estimatedBytes / 1024).toFixed(1)}KB`,
133
+ totalKB: `${(totalBytes / 1024).toFixed(1)}KB`,
134
+ });
135
+ }
111
136
  }
112
137
  // Performance: Pre-computed Sets for equivalency reason filtering (O(1) vs O(n))
113
138
  const ALLOWED_EQUIVALENCY_REASONS = new Set([
@@ -140,6 +165,10 @@ const ALLOWED_EQUIVALENCY_REASONS = new Set([
140
165
  'propagated function call return sub-property equivalency',
141
166
  'propagated parent-variable equivalency', // Added: propagate child scope equivalencies to parent scope when variable is defined in parent
142
167
  'where was this function called from', // Added: tracks which scope called an external function
168
+ 'MUI DataGrid renderCell params.row equivalency', // Added: links DataGrid renderCell params.row to rows array elements
169
+ 'MUI Autocomplete getOptionLabel option equivalency', // Added: links Autocomplete getOptionLabel callback param to options array
170
+ 'MUI Autocomplete renderOption option equivalency', // Added: links Autocomplete renderOption callback param to options array
171
+ 'MUI Autocomplete option property equivalency', // Added: propagates property accesses from Autocomplete callbacks
143
172
  ]);
144
173
  const SILENTLY_IGNORED_EQUIVALENCY_REASONS = new Set([
145
174
  'signature of functionCall',
@@ -172,6 +201,26 @@ export class ScopeDataStructure {
172
201
  * Maps local variable path to array of usages.
173
202
  */
174
203
  this.rawConditionalUsages = {};
204
+ /**
205
+ * Conditional effects collected during AST analysis.
206
+ * Tracks what setter calls happen inside conditionals (if, switch, ternary).
207
+ */
208
+ this.rawConditionalEffects = [];
209
+ /**
210
+ * Compound conditionals collected during AST analysis.
211
+ * Groups conditions that must all be true together (e.g., a && b && c).
212
+ */
213
+ this.rawCompoundConditionals = [];
214
+ /**
215
+ * Gating conditions for child component boundaries.
216
+ * Maps child component name to the conditions that must be true for it to render.
217
+ */
218
+ this.rawChildBoundaryGatingConditions = {};
219
+ /**
220
+ * JSX rendering usages collected during AST analysis.
221
+ * Tracks arrays rendered via .map() and strings interpolated in JSX.
222
+ */
223
+ this.rawJsxRenderingUsages = [];
175
224
  this.lastAddToSchemaId = 0;
176
225
  this.lastEquivalencyId = 0;
177
226
  this.lastEquivalencyDatabaseId = 0;
@@ -183,6 +232,9 @@ export class ScopeDataStructure {
183
232
  // Index for O(1) lookup of external function calls by name
184
233
  // Invalidated by setting to null; rebuilt lazily on next access
185
234
  this.externalFunctionCallsIndex = null;
235
+ // Tracks internal functions that have been filtered out during captureCompleteSchema
236
+ // Prevents re-adding them via subsequent equivalency propagation (e.g., from getReturnValue)
237
+ this.filteredInternalFunctions = new Set();
186
238
  // Debug tracer for selective path/scope tracing
187
239
  // Enable via: CODEYAM_DEBUG=true CODEYAM_DEBUG_PATHS="user.*,signature" npm test
188
240
  this.tracer = new DebugTracer({
@@ -301,6 +353,8 @@ export class ScopeDataStructure {
301
353
  const efcName = this.pathManager.stripGenerics(efc.name);
302
354
  for (const manager of this.equivalencyManagers) {
303
355
  if (manager.internalFunctions.has(efcName)) {
356
+ // Track this so we don't re-add it via subsequent finalize calls
357
+ this.filteredInternalFunctions.add(efcName);
304
358
  return false;
305
359
  }
306
360
  }
@@ -321,11 +375,42 @@ export class ScopeDataStructure {
321
375
  });
322
376
  entry.sourceCandidates = entry.sourceCandidates.filter((candidate) => {
323
377
  const baseName = this.pathManager.stripGenerics(candidate.scopeNodeName);
378
+ // Check if this is a local variable path (doesn't contain function call pattern)
379
+ // Local variables like "surveys[]" or "items[]" are important for tracing data flow
380
+ // from parent to child components (e.g., surveys[] -> SurveyCard().signature[0].survey)
381
+ const isLocalVariablePath = !candidate.schemaPath.includes('()') &&
382
+ !candidate.schemaPath.startsWith('signature[') &&
383
+ !candidate.schemaPath.startsWith('returnValue');
324
384
  return (validExternalFacingScopeNames.has(baseName) &&
325
385
  (candidate.schemaPath.startsWith('signature[') ||
326
- candidate.schemaPath.startsWith(baseName)) &&
386
+ candidate.schemaPath.startsWith(baseName) ||
387
+ isLocalVariablePath) &&
327
388
  !containsArrayMethod(candidate.schemaPath));
328
389
  });
390
+ // If all sourceCandidates were filtered out (e.g., because they belonged to
391
+ // internal functions like useState), look for the highest-order intermediate
392
+ // that belongs to a valid external-facing scope
393
+ if (entry.sourceCandidates.length === 0 &&
394
+ Object.keys(entry.intermediatesOrder).length > 0) {
395
+ // Find intermediates that belong to valid external-facing scopes
396
+ const validIntermediates = Object.entries(entry.intermediatesOrder)
397
+ .filter(([pathId]) => {
398
+ const [scopeNodeName, schemaPath] = pathId.split('::');
399
+ if (!scopeNodeName || !schemaPath)
400
+ return false;
401
+ const baseName = this.pathManager.stripGenerics(scopeNodeName);
402
+ return (validExternalFacingScopeNames.has(baseName) &&
403
+ !containsArrayMethod(schemaPath));
404
+ })
405
+ .sort((a, b) => b[1] - a[1]); // Sort by order descending (highest first)
406
+ if (validIntermediates.length > 0) {
407
+ const [pathId] = validIntermediates[0];
408
+ const [scopeNodeName, schemaPath] = pathId.split('::');
409
+ if (scopeNodeName && schemaPath) {
410
+ entry.sourceCandidates.push({ scopeNodeName, schemaPath });
411
+ }
412
+ }
413
+ }
329
414
  }
330
415
  this.propagateSourceAndUsageEquivalencies(this.scopeNodes[this.scopeTreeManager.getRootName()]);
331
416
  for (const externalFunctionCall of this.externalFunctionCalls) {
@@ -390,6 +475,10 @@ export class ScopeDataStructure {
390
475
  }
391
476
  return;
392
477
  }
478
+ // PERF: Early exit for paths with repeated function-call signature patterns
479
+ if (this.hasExcessivePatternRepetition(path)) {
480
+ return;
481
+ }
393
482
  // Update chain metadata for database tracking
394
483
  if (equivalencyValueChain.length > 0) {
395
484
  equivalencyValueChain[equivalencyValueChain.length - 1].addToSchemaId =
@@ -559,7 +648,6 @@ export class ScopeDataStructure {
559
648
  }
560
649
  addEquivalency(path, equivalentPath, equivalentScopeName, scopeNode, equivalencyReason, equivalencyValueChain, traceId) {
561
650
  var _a;
562
- // DEBUG: Detect infinite loops
563
651
  addEquivalencyCallCount++;
564
652
  if (addEquivalencyCallCount > 50000) {
565
653
  console.error('INFINITE LOOP DETECTED in addEquivalency', {
@@ -754,10 +842,31 @@ export class ScopeDataStructure {
754
842
  const searchKey = getFunctionCallRoot(functionCallInfo.callSignature);
755
843
  const existingFunctionCall = this.getExternalFunctionCallsIndex().get(searchKey);
756
844
  if (existingFunctionCall) {
757
- existingFunctionCall.schema = {
845
+ // Preserve per-call schemas BEFORE merging to enable per-variable mock data.
846
+ // This is critical for hooks like useFetcher<UserData>() vs useFetcher<ReportData>()
847
+ // where each call returns different typed data.
848
+ if (!existingFunctionCall.perCallSignatureSchemas) {
849
+ // First merge - save the existing call's schema
850
+ existingFunctionCall.perCallSignatureSchemas = {
851
+ [existingFunctionCall.callSignature]: {
852
+ ...existingFunctionCall.schema,
853
+ },
854
+ };
855
+ }
856
+ // Save the new call's schema before it gets merged
857
+ existingFunctionCall.perCallSignatureSchemas[functionCallInfo.callSignature] = { ...functionCallInfo.schema };
858
+ // Merge schemas using selectBestValue to preserve specific types like 'null'
859
+ // over generic types like 'unknown'. This ensures ref variables detected
860
+ // earlier (marked as 'null') aren't overwritten by later 'unknown' values.
861
+ const mergedSchema = {
758
862
  ...existingFunctionCall.schema,
759
- ...functionCallInfo.schema,
760
863
  };
864
+ for (const key in functionCallInfo.schema) {
865
+ const existingValue = existingFunctionCall.schema[key];
866
+ const newValue = functionCallInfo.schema[key];
867
+ mergedSchema[key] = selectBestValue(existingValue, newValue, newValue);
868
+ }
869
+ existingFunctionCall.schema = mergedSchema;
761
870
  existingFunctionCall.equivalencies = {
762
871
  ...existingFunctionCall.equivalencies,
763
872
  ...functionCallInfo.equivalencies,
@@ -777,8 +886,13 @@ export class ScopeDataStructure {
777
886
  const isExternal = !callingScopeNode.instantiatedVariables?.includes(functionCallInfoNameParts[0]) &&
778
887
  !callingScopeNode.parentInstantiatedVariables?.includes(functionCallInfoNameParts[0]);
779
888
  if (isExternal) {
780
- this.externalFunctionCalls.push(functionCallInfo);
781
- this.invalidateExternalFunctionCallsIndex();
889
+ // Check if this function was already filtered out as an internal function
890
+ // (e.g., useState was filtered in captureCompleteSchema but finalize is trying to re-add it)
891
+ const strippedName = this.pathManager.stripGenerics(functionCallInfo.name);
892
+ if (!this.filteredInternalFunctions.has(strippedName)) {
893
+ this.externalFunctionCalls.push(functionCallInfo);
894
+ this.invalidateExternalFunctionCallsIndex();
895
+ }
782
896
  }
783
897
  }
784
898
  }
@@ -847,9 +961,26 @@ export class ScopeDataStructure {
847
961
  const remainingKey = remainingSchemaPathParts.join('|');
848
962
  const equivalentSchemaPath = equivalentSchemaPathMap.get(remainingKey);
849
963
  if (equivalentSchemaPath) {
964
+ // Skip propagation when there's a structural mismatch:
965
+ // - schemaPath ends with [] (array element, represents an object)
966
+ // - equivalentSchemaPath doesn't end with [] (non-array prop, usually a scalar)
967
+ // This prevents incorrectly typing array elements as strings when they're
968
+ // equivalent to scalar props like JSX keys (e.g., workouts[] ↔ Card().key)
969
+ const schemaPathEndsWithArray = schemaPath.endsWith('[]');
970
+ const equivalentEndsWithArray = equivalentSchemaPath.endsWith('[]');
971
+ if (schemaPathEndsWithArray !== equivalentEndsWithArray) {
972
+ // Don't propagate between array element paths and non-array paths
973
+ continue;
974
+ }
850
975
  const value1 = scopeNode.schema[schemaPath];
851
976
  const value2 = equivalentScopeNode.schema[equivalentSchemaPath];
852
977
  const bestValue = selectBestValue(value1, value2);
978
+ // PERF: Skip paths with repeated function-call signature patterns
979
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
980
+ if (this.hasExcessivePatternRepetition(schemaPath) ||
981
+ this.hasExcessivePatternRepetition(equivalentSchemaPath)) {
982
+ continue;
983
+ }
853
984
  scopeNode.schema[schemaPath] = bestValue;
854
985
  equivalentScopeNode.schema[equivalentSchemaPath] = bestValue;
855
986
  }
@@ -861,6 +992,10 @@ export class ScopeDataStructure {
861
992
  equivalentPath,
862
993
  ...remainingSchemaPathParts,
863
994
  ]);
995
+ // PERF: Skip paths with repeated function-call signature patterns
996
+ if (this.hasExcessivePatternRepetition(newEquivalentPath)) {
997
+ continue;
998
+ }
864
999
  equivalentScopeNode.schema[newEquivalentPath] =
865
1000
  scopeNode.schema[schemaPath];
866
1001
  }
@@ -917,26 +1052,103 @@ export class ScopeDataStructure {
917
1052
  isValidPath(path) {
918
1053
  return this.pathManager.isValidPath(path);
919
1054
  }
1055
+ /**
1056
+ * Detects if a path contains excessive repetition of the same pattern.
1057
+ *
1058
+ * This prevents exponential blowup when analyzing recursive type structures.
1059
+ * For example, TypeScript AST nodes have `.attributes.properties[]` where each
1060
+ * property is also a node with `.attributes.properties[]`. Without this check,
1061
+ * paths like `signature[0].attributes.properties[].attributes.properties[].attributes.properties[]...`
1062
+ * would be generated exponentially.
1063
+ *
1064
+ * Two detection strategies:
1065
+ * 1. Known patterns: Check RECURSIVE_PATH_PATTERNS for common recursive structures
1066
+ * 2. Generic detection: For longer paths, detect any 2-3 part segment that repeats
1067
+ *
1068
+ * @param path - The schema path to check
1069
+ * @param maxRepetitions - Maximum allowed repetitions of any pattern (default: 2)
1070
+ * @returns true if the path has excessive repetition
1071
+ */
1072
+ hasExcessivePatternRepetition(path, maxRepetitions = 2) {
1073
+ // Check known recursive patterns
1074
+ for (const pattern of RECURSIVE_PATH_PATTERNS) {
1075
+ const matches = path.match(pattern);
1076
+ if (matches && matches.length > maxRepetitions) {
1077
+ return true;
1078
+ }
1079
+ }
1080
+ // Check for repeated function calls that indicate recursive type expansion.
1081
+ // E.g., localeCompare(b[])...localeCompare(b[]) means string.localeCompare
1082
+ // returns a type that again has localeCompare, causing infinite expansion.
1083
+ // We extract all function call patterns like "funcName(args)" and check if
1084
+ // the same normalized call appears more than once.
1085
+ const funcCallPattern = /(?:^|\.)[^.([]+\([^)]*\)/g;
1086
+ const funcCallMatches = path.match(funcCallPattern);
1087
+ if (funcCallMatches && funcCallMatches.length > 1) {
1088
+ const seen = new Set();
1089
+ for (const match of funcCallMatches) {
1090
+ // Strip leading dot and normalize array indices
1091
+ const normalized = match.replace(/^\./, '').replace(/\[\d+\]/g, '[]');
1092
+ if (seen.has(normalized))
1093
+ return true;
1094
+ seen.add(normalized);
1095
+ }
1096
+ }
1097
+ // For longer paths, detect any repeated multi-part segments we haven't explicitly listed
1098
+ const pathParts = this.splitPath(path);
1099
+ if (pathParts.length <= 6) {
1100
+ return false;
1101
+ }
1102
+ // Check for repeated sequences of 2-3 consecutive parts
1103
+ for (let segmentLength = 2; segmentLength <= 3; segmentLength++) {
1104
+ const seen = new Map();
1105
+ for (let i = 0; i <= pathParts.length - segmentLength; i++) {
1106
+ const segment = pathParts.slice(i, i + segmentLength).join('.');
1107
+ const normalizedSegment = segment.replace(/\[\d+\]/g, '[]');
1108
+ const count = (seen.get(normalizedSegment) || 0) + 1;
1109
+ seen.set(normalizedSegment, count);
1110
+ if (count > maxRepetitions) {
1111
+ return true;
1112
+ }
1113
+ }
1114
+ }
1115
+ return false;
1116
+ }
920
1117
  addToTree(pathParts) {
921
1118
  this.scopeTreeManager.addPath(pathParts);
922
1119
  }
923
1120
  setInstantiatedVariables(scopeNode) {
924
1121
  let instantiatedVariables = scopeNode.analysis?.instantiatedVariables ?? [];
925
- for (const [path, equivalentPath] of Object.entries(scopeNode.analysis.isolatedEquivalentVariables ?? {})) {
926
- if (typeof equivalentPath !== 'string') {
927
- continue;
928
- }
929
- if (equivalentPath.startsWith('signature[')) {
930
- const equivalentPathParts = this.splitPath(equivalentPath);
931
- instantiatedVariables.push(equivalentPathParts[0]);
932
- instantiatedVariables.push(path);
1122
+ for (const [path, rawEquivalentPath] of Object.entries(scopeNode.analysis.isolatedEquivalentVariables ?? {})) {
1123
+ // Normalize to array for consistent handling (supports both string and string[])
1124
+ const equivalentPaths = Array.isArray(rawEquivalentPath)
1125
+ ? rawEquivalentPath
1126
+ : rawEquivalentPath
1127
+ ? [rawEquivalentPath]
1128
+ : [];
1129
+ for (const equivalentPath of equivalentPaths) {
1130
+ if (typeof equivalentPath !== 'string') {
1131
+ continue;
1132
+ }
1133
+ if (equivalentPath.startsWith('signature[')) {
1134
+ const equivalentPathParts = this.splitPath(equivalentPath);
1135
+ instantiatedVariables.push(equivalentPathParts[0]);
1136
+ instantiatedVariables.push(path);
1137
+ }
933
1138
  }
934
1139
  const duplicateInstantiated = instantiatedVariables.find((v) => path.split('::cyDuplicateKey')[0] === v.split('::cyDuplicateKey')[0]);
935
1140
  if (duplicateInstantiated) {
936
1141
  instantiatedVariables.push(path);
937
1142
  }
938
1143
  }
939
- instantiatedVariables = instantiatedVariables.filter((varName, index, self) => self.indexOf(varName) === index);
1144
+ const instantiatedSeen = new Set();
1145
+ instantiatedVariables = instantiatedVariables.filter((varName) => {
1146
+ if (instantiatedSeen.has(varName)) {
1147
+ return false;
1148
+ }
1149
+ instantiatedSeen.add(varName);
1150
+ return true;
1151
+ });
940
1152
  scopeNode.instantiatedVariables = instantiatedVariables;
941
1153
  if (!scopeNode.tree || scopeNode.tree.length === 0) {
942
1154
  return;
@@ -948,125 +1160,156 @@ export class ScopeDataStructure {
948
1160
  const parentInstantiatedVariables = [
949
1161
  ...(parentScopeNode.parentInstantiatedVariables ?? []),
950
1162
  ...parentScopeNode.instantiatedVariables.filter((v) => !v.startsWith('signature[') && !v.startsWith('returnValue')),
951
- ].filter((varName, index, self) => !instantiatedVariables.includes(varName) &&
952
- self.indexOf(varName) === index);
953
- scopeNode.parentInstantiatedVariables = parentInstantiatedVariables;
1163
+ ].filter((varName) => !instantiatedSeen.has(varName));
1164
+ const parentInstantiatedSeen = new Set();
1165
+ const dedupedParentInstantiatedVariables = parentInstantiatedVariables.filter((varName) => {
1166
+ if (parentInstantiatedSeen.has(varName)) {
1167
+ return false;
1168
+ }
1169
+ parentInstantiatedSeen.add(varName);
1170
+ return true;
1171
+ });
1172
+ scopeNode.parentInstantiatedVariables = dedupedParentInstantiatedVariables;
954
1173
  }
955
1174
  trackFunctionCalls(scopeNode) {
956
1175
  this.captureFunctionCalls(scopeNode);
957
1176
  this.checkExternalFunctionCalls();
958
1177
  }
959
1178
  determineEquivalenciesAndBuildSchema(scopeNode) {
960
- const { isolatedStructure, isolatedEquivalentVariables } = scopeNode.analysis;
961
- // DEBUG: Log all equivalencies related to useFetcher
962
- if (Object.keys(isolatedEquivalentVariables || {}).some((k) => k.includes('Fetcher') || k.includes('fetcher'))) {
963
- console.log('CodeYam DEBUG determineEquivalenciesAndBuildSchema:', JSON.stringify({
964
- scopeNodeName: scopeNode.name,
965
- fetcherEquivalencies: Object.entries(isolatedEquivalentVariables || {})
966
- .filter(([k, v]) => k.includes('Fetcher') ||
967
- k.includes('fetcher') ||
968
- String(v).includes('Fetcher') ||
969
- String(v).includes('fetcher'))
970
- .reduce((acc, [k, v]) => {
971
- acc[k] = v;
972
- return acc;
973
- }, {}),
974
- }, null, 2));
1179
+ if (!scopeNode.analysis) {
1180
+ return;
975
1181
  }
1182
+ const { isolatedStructure, isolatedEquivalentVariables } = scopeNode.analysis;
1183
+ // Flatten isolatedEquivalentVariables values for allPaths (handles both string and string[])
1184
+ const flattenedEquivValues = Object.values(isolatedEquivalentVariables || {}).flatMap((v) => (Array.isArray(v) ? v : [v]));
976
1185
  const allPaths = Array.from(new Set([
977
1186
  ...Object.keys(isolatedStructure || {}),
978
1187
  ...Object.keys(isolatedEquivalentVariables || {}),
979
- ...Object.values(isolatedEquivalentVariables || {}),
1188
+ ...flattenedEquivValues,
980
1189
  ]));
981
1190
  for (let path in isolatedEquivalentVariables) {
982
- let equivalentValue = isolatedEquivalentVariables?.[path];
983
- if (equivalentValue && this.isValidPath(equivalentValue)) {
984
- path = cleanPath(path.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
985
- equivalentValue = cleanPath(equivalentValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
986
- this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
987
- // Propagate equivalencies involving parent-scope variables to those parent scopes.
988
- // This handles patterns like: collected.push({...entity}) where 'collected' is defined
989
- // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
990
- // visible when tracing from the parent scope.
991
- const rootVariable = this.extractRootVariable(path);
992
- const equivalentRootVariable = this.extractRootVariable(equivalentValue);
993
- // Skip propagation for self-referential reassignment patterns like:
994
- // x = x.method().functionCallReturnValue
995
- // where the path IS the variable itself (not a sub-path like x[] or x.prop).
996
- // These create circular references since both sides reference the same variable.
997
- //
998
- // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
999
- // where the path has additional segments beyond the root variable.
1000
- const pathIsJustRootVariable = path === rootVariable;
1001
- const isSelfReferentialReassignment = pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1002
- if (rootVariable &&
1003
- !isSelfReferentialReassignment &&
1004
- scopeNode.parentInstantiatedVariables?.includes(rootVariable)) {
1005
- // Find the parent scope where this variable is defined
1006
- for (const parentScopeName of scopeNode.tree || []) {
1007
- const parentScope = this.scopeNodes[parentScopeName];
1008
- if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1009
- // Add the equivalency to the parent scope as well
1010
- this.addEquivalency(path, equivalentValue, scopeNode.name, // The equivalent path's scope remains the child scope
1011
- parentScope, // But store it in the parent scope's equivalencies
1012
- 'propagated parent-variable equivalency');
1013
- break;
1191
+ const rawEquivalentValue = isolatedEquivalentVariables?.[path];
1192
+ // Normalize to array for consistent handling
1193
+ const equivalentValues = Array.isArray(rawEquivalentValue)
1194
+ ? rawEquivalentValue
1195
+ : [rawEquivalentValue];
1196
+ for (let equivalentValue of equivalentValues) {
1197
+ if (equivalentValue && this.isValidPath(equivalentValue)) {
1198
+ // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1199
+ // These markers are critical for distinguishing variable reassignments.
1200
+ // For example, with:
1201
+ // let fetcher = useFetcher<ConfigData>();
1202
+ // const configData = fetcher.data?.data;
1203
+ // fetcher = useFetcher<SettingsData>();
1204
+ // const settingsData = fetcher.data?.data;
1205
+ //
1206
+ // mergeStatements creates:
1207
+ // fetcher useFetcher<ConfigData>()...
1208
+ // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1209
+ // configData fetcher.data.data
1210
+ // settingsData fetcher::cyDuplicateKey1::.data.data
1211
+ //
1212
+ // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1213
+ // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1214
+ path = cleanPath(path, allPaths);
1215
+ equivalentValue = cleanPath(equivalentValue, allPaths);
1216
+ this.addEquivalency(path, equivalentValue, scopeNode.name, scopeNode, 'original equivalency');
1217
+ // Propagate equivalencies involving parent-scope variables to those parent scopes.
1218
+ // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1219
+ // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1220
+ // visible when tracing from the parent scope.
1221
+ const rootVariable = this.extractRootVariable(path);
1222
+ const equivalentRootVariable = this.extractRootVariable(equivalentValue);
1223
+ // Skip propagation for self-referential reassignment patterns like:
1224
+ // x = x.method().functionCallReturnValue
1225
+ // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1226
+ // These create circular references since both sides reference the same variable.
1227
+ //
1228
+ // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1229
+ // where the path has additional segments beyond the root variable.
1230
+ const pathIsJustRootVariable = path === rootVariable;
1231
+ const isSelfReferentialReassignment = pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1232
+ if (rootVariable &&
1233
+ !isSelfReferentialReassignment &&
1234
+ scopeNode.parentInstantiatedVariables?.includes(rootVariable)) {
1235
+ // Find the parent scope where this variable is defined
1236
+ for (const parentScopeName of scopeNode.tree || []) {
1237
+ const parentScope = this.scopeNodes[parentScopeName];
1238
+ if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1239
+ // Add the equivalency to the parent scope as well
1240
+ this.addEquivalency(path, equivalentValue, scopeNode.name, // The equivalent path's scope remains the child scope
1241
+ parentScope, // But store it in the parent scope's equivalencies
1242
+ 'propagated parent-variable equivalency');
1243
+ break;
1244
+ }
1014
1245
  }
1015
1246
  }
1016
- }
1017
- // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1018
- // that has sub-properties defined in the isolatedEquivalentVariables.
1019
- // This handles cases like: dataItem={{ structure: completeDataStructure }}
1020
- // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1021
- // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1022
- const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
1023
- !equivalentValue.includes('functionCallReturnValue') &&
1024
- !equivalentValue.includes('.') &&
1025
- !equivalentValue.includes('[');
1026
- if (isSimpleVariable) {
1027
- // Look in current scope and all parent scopes for sub-properties
1028
- const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1029
- for (const scopeName of scopesToCheck) {
1030
- const checkScope = this.scopeNodes[scopeName];
1031
- if (!checkScope?.analysis?.isolatedEquivalentVariables)
1032
- continue;
1033
- for (const [subPath, subValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
1034
- // Check if this is a sub-property of the equivalentValue variable
1035
- // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1036
- const matchesDot = subPath.startsWith(equivalentValue + '.');
1037
- const matchesBracket = subPath.startsWith(equivalentValue + '[');
1038
- if (matchesDot || matchesBracket) {
1039
- const subPropertyPath = subPath.substring(equivalentValue.length);
1040
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1041
- const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1042
- if (newEquivalentValue &&
1043
- this.isValidPath(newEquivalentValue)) {
1044
- this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
1045
- scopeNode, 'propagated sub-property equivalency');
1247
+ // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1248
+ // that has sub-properties defined in the isolatedEquivalentVariables.
1249
+ // This handles cases like: dataItem={{ structure: completeDataStructure }}
1250
+ // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1251
+ // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1252
+ const isSimpleVariable = !equivalentValue.startsWith('signature[') &&
1253
+ !equivalentValue.includes('functionCallReturnValue') &&
1254
+ !equivalentValue.includes('.') &&
1255
+ !equivalentValue.includes('[');
1256
+ if (isSimpleVariable) {
1257
+ // Look in current scope and all parent scopes for sub-properties
1258
+ const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1259
+ for (const scopeName of scopesToCheck) {
1260
+ const checkScope = this.scopeNodes[scopeName];
1261
+ if (!checkScope?.analysis?.isolatedEquivalentVariables)
1262
+ continue;
1263
+ for (const [subPath, rawSubValue] of Object.entries(checkScope.analysis.isolatedEquivalentVariables)) {
1264
+ // Normalize to array for consistent handling
1265
+ const subValues = Array.isArray(rawSubValue)
1266
+ ? rawSubValue
1267
+ : rawSubValue
1268
+ ? [rawSubValue]
1269
+ : [];
1270
+ // Check if this is a sub-property of the equivalentValue variable
1271
+ // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1272
+ const matchesDot = subPath.startsWith(equivalentValue + '.');
1273
+ const matchesBracket = subPath.startsWith(equivalentValue + '[');
1274
+ if (matchesDot || matchesBracket) {
1275
+ const subPropertyPath = subPath.substring(equivalentValue.length);
1276
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
1277
+ for (const subValue of subValues) {
1278
+ if (typeof subValue !== 'string')
1279
+ continue;
1280
+ const newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1281
+ if (newEquivalentValue &&
1282
+ this.isValidPath(newEquivalentValue)) {
1283
+ this.addEquivalency(newPath, newEquivalentValue, checkScope.name, // Use the scope where the sub-property was found
1284
+ scopeNode, 'propagated sub-property equivalency');
1285
+ }
1286
+ }
1287
+ }
1288
+ // Also check if equivalentValue itself maps to a functionCallReturnValue
1289
+ // e.g., result = useMemo(...).functionCallReturnValue
1290
+ for (const subValue of subValues) {
1291
+ if (subPath === equivalentValue &&
1292
+ typeof subValue === 'string' &&
1293
+ subValue.endsWith('.functionCallReturnValue')) {
1294
+ this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
1295
+ }
1046
1296
  }
1047
- }
1048
- // Also check if equivalentValue itself maps to a functionCallReturnValue
1049
- // e.g., result = useMemo(...).functionCallReturnValue
1050
- if (subPath === equivalentValue &&
1051
- typeof subValue === 'string' &&
1052
- subValue.endsWith('.functionCallReturnValue')) {
1053
- this.propagateFunctionCallReturnSubProperties(path, subValue, scopeNode, allPaths);
1054
1297
  }
1055
1298
  }
1056
1299
  }
1057
- }
1058
- // Handle function call return values by propagating returnValue.* sub-properties
1059
- // from the callback scope to the usage path
1060
- if (equivalentValue.endsWith('.functionCallReturnValue')) {
1061
- this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
1062
- // Track which variable receives the return value of each function call
1063
- // This enables generating separate mock data for each call site
1064
- this.trackReceivingVariable(path, equivalentValue);
1065
- }
1066
- // Also track variables that receive destructured properties from function call return values
1067
- // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1068
- if (equivalentValue.includes('.functionCallReturnValue.')) {
1069
- this.trackReceivingVariable(path, equivalentValue);
1300
+ // Handle function call return values by propagating returnValue.* sub-properties
1301
+ // from the callback scope to the usage path
1302
+ if (equivalentValue.endsWith('.functionCallReturnValue')) {
1303
+ this.propagateFunctionCallReturnSubProperties(path, equivalentValue, scopeNode, allPaths);
1304
+ // Track which variable receives the return value of each function call
1305
+ // This enables generating separate mock data for each call site
1306
+ this.trackReceivingVariable(path, equivalentValue);
1307
+ }
1308
+ // Also track variables that receive destructured properties from function call return values
1309
+ // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1310
+ if (equivalentValue.includes('.functionCallReturnValue.')) {
1311
+ this.trackReceivingVariable(path, equivalentValue);
1312
+ }
1070
1313
  }
1071
1314
  }
1072
1315
  }
@@ -1074,7 +1317,7 @@ export class ScopeDataStructure {
1074
1317
  // This eliminates deep call stacks and improves deduplication
1075
1318
  this.batchProcessor = new BatchSchemaProcessor();
1076
1319
  this.batchQueuedSet = new Set();
1077
- for (const key of Array.from(allPaths)) {
1320
+ for (const key of allPaths) {
1078
1321
  let value = isolatedStructure[key] ?? 'unknown';
1079
1322
  if (['null', 'undefined'].includes(value)) {
1080
1323
  value = 'unknown';
@@ -1108,7 +1351,14 @@ export class ScopeDataStructure {
1108
1351
  processBatchQueue() {
1109
1352
  if (!this.batchProcessor)
1110
1353
  return;
1354
+ let iterations = 0;
1111
1355
  while (this.batchProcessor.hasWork()) {
1356
+ iterations++;
1357
+ // Safety: detect potential infinite loops
1358
+ if (iterations > 100000) {
1359
+ console.error(`[ScopeDataStructure] processBatchQueue exceeded 100k iterations, possible infinite loop!`);
1360
+ break;
1361
+ }
1112
1362
  const item = this.batchProcessor.getNextWork();
1113
1363
  if (!item)
1114
1364
  break;
@@ -1155,18 +1405,6 @@ export class ScopeDataStructure {
1155
1405
  // Find the FunctionCallInfo that matches this call signature
1156
1406
  const searchKey = getFunctionCallRoot(callSignature);
1157
1407
  const functionCallInfo = this.getExternalFunctionCallsIndex().get(searchKey);
1158
- // DEBUG: Track useFetcher calls
1159
- if (searchKey === 'useFetcher' || callSignature.includes('useFetcher')) {
1160
- console.log('CodeYam DEBUG trackReceivingVariable:', JSON.stringify({
1161
- receivingVariable,
1162
- equivalentValue,
1163
- callSignature,
1164
- searchKey,
1165
- foundFunctionCallInfo: !!functionCallInfo,
1166
- existingRecvVars: functionCallInfo?.receivingVariableNames,
1167
- existingCallSigToVar: functionCallInfo?.callSignatureToVariable,
1168
- }, null, 2));
1169
- }
1170
1408
  if (!functionCallInfo) {
1171
1409
  return;
1172
1410
  }
@@ -1215,8 +1453,15 @@ export class ScopeDataStructure {
1215
1453
  const checkScope = this.scopeNodes[scopeName];
1216
1454
  if (!checkScope?.analysis?.isolatedEquivalentVariables)
1217
1455
  continue;
1218
- const functionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
1219
- if (typeof functionRef === 'string' && functionRef.endsWith('F')) {
1456
+ const rawFunctionRef = checkScope.analysis.isolatedEquivalentVariables[functionName];
1457
+ // Normalize to array and find first string ending with 'F'
1458
+ const functionRefs = Array.isArray(rawFunctionRef)
1459
+ ? rawFunctionRef
1460
+ : rawFunctionRef
1461
+ ? [rawFunctionRef]
1462
+ : [];
1463
+ const functionRef = functionRefs.find((r) => typeof r === 'string' && r.endsWith('F'));
1464
+ if (typeof functionRef === 'string') {
1220
1465
  callbackScopeName = functionRef.slice(0, -1);
1221
1466
  break;
1222
1467
  }
@@ -1239,22 +1484,32 @@ export class ScopeDataStructure {
1239
1484
  if (!callbackScope.analysis?.isolatedEquivalentVariables)
1240
1485
  return;
1241
1486
  const isolatedVars = callbackScope.analysis.isolatedEquivalentVariables;
1487
+ // Get the first returnValue equivalency (normalize array to single value for these checks)
1488
+ const rawReturnValue = isolatedVars.returnValue;
1489
+ const firstReturnValue = Array.isArray(rawReturnValue)
1490
+ ? rawReturnValue[0]
1491
+ : rawReturnValue;
1242
1492
  // First, check if returnValue is an alias to another variable (e.g., returnValue = intermediate)
1243
1493
  // If so, we need to look for that variable's sub-properties too
1244
- const returnValueAlias = typeof isolatedVars.returnValue === 'string' &&
1245
- !isolatedVars.returnValue.includes('.')
1246
- ? isolatedVars.returnValue
1494
+ const returnValueAlias = typeof firstReturnValue === 'string' && !firstReturnValue.includes('.')
1495
+ ? firstReturnValue
1247
1496
  : undefined;
1248
1497
  // Pattern 3: Object.keys(X).reduce() - the reduce result has the same sub-properties as X
1249
1498
  // When returnValue = "Object.keys(source).reduce(...).functionCallReturnValue", look for source.* sub-properties
1250
1499
  let reduceSourceVar;
1251
- if (typeof isolatedVars.returnValue === 'string') {
1252
- const reduceMatch = isolatedVars.returnValue.match(/^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/);
1500
+ if (typeof firstReturnValue === 'string') {
1501
+ const reduceMatch = firstReturnValue.match(/^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/);
1253
1502
  if (reduceMatch) {
1254
1503
  reduceSourceVar = reduceMatch[1];
1255
1504
  }
1256
1505
  }
1257
- for (const [subPath, subValue] of Object.entries(isolatedVars)) {
1506
+ for (const [subPath, rawSubValue] of Object.entries(isolatedVars)) {
1507
+ // Normalize to array for consistent handling
1508
+ const subValues = Array.isArray(rawSubValue)
1509
+ ? rawSubValue
1510
+ : rawSubValue
1511
+ ? [rawSubValue]
1512
+ : [];
1258
1513
  // Check for direct returnValue.* sub-properties
1259
1514
  const isReturnValueSub = subPath.startsWith('returnValue.') ||
1260
1515
  subPath.startsWith('returnValue[');
@@ -1266,33 +1521,36 @@ export class ScopeDataStructure {
1266
1521
  const isReduceSourceSub = reduceSourceVar &&
1267
1522
  (subPath.startsWith(reduceSourceVar + '.') ||
1268
1523
  subPath.startsWith(reduceSourceVar + '['));
1269
- if (typeof subValue !== 'string' ||
1270
- (!isReturnValueSub && !isAliasSub && !isReduceSourceSub))
1524
+ if (!isReturnValueSub && !isAliasSub && !isReduceSourceSub)
1271
1525
  continue;
1272
- // Convert alias/reduceSource paths to returnValue paths
1273
- let effectiveSubPath = subPath;
1274
- if (isAliasSub && !isReturnValueSub) {
1275
- // Replace the alias prefix with returnValue
1276
- effectiveSubPath =
1277
- 'returnValue' + subPath.substring(returnValueAlias.length);
1278
- }
1279
- else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
1280
- // Replace the reduce source prefix with returnValue
1281
- effectiveSubPath =
1282
- 'returnValue' + subPath.substring(reduceSourceVar.length);
1283
- }
1284
- const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
1285
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1286
- let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1287
- // Resolve variable references through parent scope equivalencies
1288
- const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
1289
- newEquivalentValue = resolved.resolvedPath;
1290
- const equivalentScopeName = resolved.scopeName;
1291
- if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
1292
- continue;
1293
- this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
1294
- // Ensure the database entry has the usage path
1295
- this.addUsageToEquivalencyDatabaseEntry(newPath, newEquivalentValue, equivalentScopeName, scopeNode.name);
1526
+ for (const subValue of subValues) {
1527
+ if (typeof subValue !== 'string')
1528
+ continue;
1529
+ // Convert alias/reduceSource paths to returnValue paths
1530
+ let effectiveSubPath = subPath;
1531
+ if (isAliasSub && !isReturnValueSub) {
1532
+ // Replace the alias prefix with returnValue
1533
+ effectiveSubPath =
1534
+ 'returnValue' + subPath.substring(returnValueAlias.length);
1535
+ }
1536
+ else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
1537
+ // Replace the reduce source prefix with returnValue
1538
+ effectiveSubPath =
1539
+ 'returnValue' + subPath.substring(reduceSourceVar.length);
1540
+ }
1541
+ const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
1542
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
1543
+ let newEquivalentValue = cleanPath(subValue.replace(/::cyDuplicateKey\d+::/g, ''), allPaths);
1544
+ // Resolve variable references through parent scope equivalencies
1545
+ const resolved = this.resolveVariableThroughParentScopes(newEquivalentValue, callbackScope, allPaths);
1546
+ newEquivalentValue = resolved.resolvedPath;
1547
+ const equivalentScopeName = resolved.scopeName;
1548
+ if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
1549
+ continue;
1550
+ this.addEquivalency(newPath, newEquivalentValue, equivalentScopeName, scopeNode, 'propagated function call return sub-property equivalency');
1551
+ // Ensure the database entry has the usage path
1552
+ this.addUsageToEquivalencyDatabaseEntry(newPath, newEquivalentValue, equivalentScopeName, scopeNode.name);
1553
+ }
1296
1554
  }
1297
1555
  }
1298
1556
  /**
@@ -1324,7 +1582,14 @@ export class ScopeDataStructure {
1324
1582
  const parentScope = this.scopeNodes[parentScopeName];
1325
1583
  if (!parentScope?.analysis?.isolatedEquivalentVariables)
1326
1584
  continue;
1327
- const rootEquiv = parentScope.analysis.isolatedEquivalentVariables[rootVar];
1585
+ const rawRootEquiv = parentScope.analysis.isolatedEquivalentVariables[rootVar];
1586
+ // Normalize to array and use first string value
1587
+ const rootEquivs = Array.isArray(rawRootEquiv)
1588
+ ? rawRootEquiv
1589
+ : rawRootEquiv
1590
+ ? [rawRootEquiv]
1591
+ : [];
1592
+ const rootEquiv = rootEquivs.find((r) => typeof r === 'string');
1328
1593
  if (typeof rootEquiv === 'string') {
1329
1594
  return {
1330
1595
  resolvedPath: cleanPath(rootEquiv + restOfPath, allPaths),
@@ -1518,9 +1783,21 @@ export class ScopeDataStructure {
1518
1783
  const remainingPath = this.joinPathParts(remainingPathParts);
1519
1784
  if (relevantSubPathParts.every((part, i) => part === schemaPathParts[i]) &&
1520
1785
  equivalentValue.scopeNodeName === scopeNode.name) {
1786
+ // DEBUG
1521
1787
  continue;
1522
1788
  }
1523
1789
  const newEquivalentPath = this.joinPathParts([schemaPath, remainingPath]);
1790
+ // PERF: Detect repeated patterns in paths to prevent exponential blowup
1791
+ // Paths like `signature[0].attributes.properties[].attributes.properties[]...`
1792
+ // indicate recursive type structures that cause exponential schema explosion
1793
+ if (this.hasExcessivePatternRepetition(newEquivalentPath)) {
1794
+ if (traceId && debugLevel > 0) {
1795
+ console.info('Debug: skipping path with excessive pattern repetition', {
1796
+ path: newEquivalentPath,
1797
+ });
1798
+ }
1799
+ continue;
1800
+ }
1524
1801
  if (!equivalentScopeNode) {
1525
1802
  if (traceId) {
1526
1803
  console.info('Debug Propagation: missing equivalent scope info', {
@@ -1792,9 +2069,70 @@ export class ScopeDataStructure {
1792
2069
  // Update inverted index
1793
2070
  this.intermediatesOrderIndex.set(pathId, databaseEntry);
1794
2071
  if (intermediateIndex === 0) {
1795
- const isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
2072
+ let isValidSourceCandidate = pathInfo.schemaPath.startsWith('signature[') ||
1796
2073
  pathInfo.schemaPath.includes('functionCallReturnValue');
1797
- if (isValidSourceCandidate) {
2074
+ // Check if path STARTS with a spread pattern like [...var]
2075
+ // This handles cases like [...files][][0] or [...files].sort(...).functionCallReturnValue[][0]
2076
+ // where the spread source variable needs to be resolved to a signature path.
2077
+ // We do this REGARDLESS of isValidSourceCandidate because even paths containing
2078
+ // functionCallReturnValue may need spread resolution to trace back to the signature.
2079
+ const spreadMatch = pathInfo.schemaPath.match(/^\[\.\.\.(\w+)\]/);
2080
+ if (spreadMatch) {
2081
+ const spreadVar = spreadMatch[1];
2082
+ const spreadPattern = spreadMatch[0]; // The full [...var] match
2083
+ const scopeNode = this.scopeNodes[pathInfo.scopeNodeName];
2084
+ if (scopeNode?.equivalencies) {
2085
+ // Follow the equivalency chain to find a signature path
2086
+ // e.g., files (cyScope1) → files (root) → signature[0].files
2087
+ const resolveToSignature = (varName, currentScopeName, visited) => {
2088
+ const visitKey = `${currentScopeName}::${varName}`;
2089
+ if (visited.has(visitKey))
2090
+ return null;
2091
+ visited.add(visitKey);
2092
+ const currentScope = this.scopeNodes[currentScopeName];
2093
+ if (!currentScope?.equivalencies)
2094
+ return null;
2095
+ const varEquivs = currentScope.equivalencies[varName];
2096
+ if (!varEquivs)
2097
+ return null;
2098
+ // First check if any equivalency directly points to a signature path
2099
+ const signatureEquiv = varEquivs.find((eq) => eq.schemaPath.startsWith('signature['));
2100
+ if (signatureEquiv) {
2101
+ return signatureEquiv;
2102
+ }
2103
+ // Otherwise, follow the chain to other scopes
2104
+ for (const equiv of varEquivs) {
2105
+ // If the equivalency points to the same variable in a different scope,
2106
+ // follow the chain
2107
+ if (equiv.schemaPath === varName &&
2108
+ equiv.scopeNodeName !== currentScopeName) {
2109
+ const result = resolveToSignature(varName, equiv.scopeNodeName, visited);
2110
+ if (result)
2111
+ return result;
2112
+ }
2113
+ }
2114
+ return null;
2115
+ };
2116
+ const signatureEquiv = resolveToSignature(spreadVar, pathInfo.scopeNodeName, new Set());
2117
+ if (signatureEquiv) {
2118
+ // Replace ONLY the [...var] part with the resolved signature path
2119
+ // This preserves any suffix like .sort(...).functionCallReturnValue[][0]
2120
+ const resolvedPath = pathInfo.schemaPath.replace(spreadPattern, signatureEquiv.schemaPath);
2121
+ // Add the resolved path as a source candidate
2122
+ if (!databaseEntry.sourceCandidates.some((sc) => sc.schemaPath === resolvedPath &&
2123
+ sc.scopeNodeName === pathInfo.scopeNodeName)) {
2124
+ databaseEntry.sourceCandidates.push({
2125
+ scopeNodeName: pathInfo.scopeNodeName,
2126
+ schemaPath: resolvedPath,
2127
+ });
2128
+ }
2129
+ isValidSourceCandidate = true;
2130
+ }
2131
+ }
2132
+ }
2133
+ if (isValidSourceCandidate &&
2134
+ !databaseEntry.sourceCandidates.some((sc) => sc.schemaPath === pathInfo.schemaPath &&
2135
+ sc.scopeNodeName === pathInfo.scopeNodeName)) {
1798
2136
  databaseEntry.sourceCandidates.push(pathInfo);
1799
2137
  }
1800
2138
  }
@@ -1940,6 +2278,13 @@ export class ScopeDataStructure {
1940
2278
  delete scopeNode.schema[key];
1941
2279
  }
1942
2280
  }
2281
+ // Ensure parameter-to-signature equivalencies are fully propagated.
2282
+ // When a parameter variable (e.g., `node`) is equivalenced to `signature[N]`,
2283
+ // all sub-paths of that variable should also appear under `signature[N]`.
2284
+ // This handles cases where the sub-path was added to the schema via a propagation
2285
+ // chain that already included the variable↔signature equivalency, causing the
2286
+ // cycle detection to prevent the reverse mapping.
2287
+ this.propagateParameterToSignaturePaths(scopeNode);
1943
2288
  fillInSchemaGapsAndUnknowns(scopeNode, fillInUnknowns);
1944
2289
  if (final) {
1945
2290
  for (const manager of this.equivalencyManagers) {
@@ -1951,6 +2296,40 @@ export class ScopeDataStructure {
1951
2296
  ensureSchemaConsistency(scopeNode.schema);
1952
2297
  }
1953
2298
  }
2299
+ /**
2300
+ * For each equivalency where a simple variable maps to signature[N],
2301
+ * ensure all sub-paths of that variable are reflected under signature[N].
2302
+ */
2303
+ propagateParameterToSignaturePaths(scopeNode) {
2304
+ // Find variable → signature[N] equivalencies
2305
+ for (const [varName, equivalencies] of Object.entries(scopeNode.equivalencies)) {
2306
+ // Only process simple variable names (no dots, brackets, or parens)
2307
+ if (varName.includes('.') ||
2308
+ varName.includes('[') ||
2309
+ varName.includes('(')) {
2310
+ continue;
2311
+ }
2312
+ for (const equiv of equivalencies) {
2313
+ if (equiv.scopeNodeName === scopeNode.name &&
2314
+ equiv.schemaPath.startsWith('signature[')) {
2315
+ const signaturePath = equiv.schemaPath;
2316
+ const varPrefix = varName + '.';
2317
+ const varBracketPrefix = varName + '[';
2318
+ // Find all schema keys starting with the variable
2319
+ for (const key in scopeNode.schema) {
2320
+ if (key.startsWith(varPrefix) || key.startsWith(varBracketPrefix)) {
2321
+ const suffix = key.slice(varName.length);
2322
+ const sigKey = signaturePath + suffix;
2323
+ // Only add if the signature path doesn't already exist
2324
+ if (!scopeNode.schema[sigKey]) {
2325
+ scopeNode.schema[sigKey] = scopeNode.schema[key];
2326
+ }
2327
+ }
2328
+ }
2329
+ }
2330
+ }
2331
+ }
2332
+ }
1954
2333
  filterAndConvertSchema({ filterPath, newPath, schema, }) {
1955
2334
  const filterPathParts = this.splitPath(filterPath);
1956
2335
  return Object.keys(schema).reduce((acc, key) => {
@@ -2010,6 +2389,10 @@ export class ScopeDataStructure {
2010
2389
  path,
2011
2390
  ...this.splitPath(key).slice(equivalentValueSchemaPathParts.length),
2012
2391
  ]);
2392
+ // PERF: Skip keys with repeated function-call signature patterns
2393
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
2394
+ if (this.hasExcessivePatternRepetition(newKey))
2395
+ continue;
2013
2396
  resolvedSchema[newKey] = value;
2014
2397
  }
2015
2398
  }
@@ -2031,6 +2414,9 @@ export class ScopeDataStructure {
2031
2414
  if (!subSchema)
2032
2415
  continue;
2033
2416
  for (const resolvedKey in subSchema) {
2417
+ // PERF: Skip keys with repeated function-call signature patterns
2418
+ if (this.hasExcessivePatternRepetition(resolvedKey))
2419
+ continue;
2034
2420
  if (!resolvedSchema[resolvedKey] ||
2035
2421
  subSchema[resolvedKey] === 'unknown') {
2036
2422
  resolvedSchema[resolvedKey] = subSchema[resolvedKey];
@@ -2133,7 +2519,12 @@ export class ScopeDataStructure {
2133
2519
  return acc;
2134
2520
  }, {});
2135
2521
  }
2522
+ // CRITICAL: Set onlyEquivalencies to true to prevent database modifications
2523
+ // during this "getter" method. See comment in getFunctionSignature.
2524
+ const wasOnlyEquivalencies = this.onlyEquivalencies;
2525
+ this.onlyEquivalencies = true;
2136
2526
  this.validateSchema(scopeNode, true, fillInUnknowns);
2527
+ this.onlyEquivalencies = wasOnlyEquivalencies;
2137
2528
  const { schema } = scopeNode;
2138
2529
  // For root scope, merge in external function call schemas
2139
2530
  // This ensures that imported objects used as method call targets (like logger.error())
@@ -2162,9 +2553,22 @@ export class ScopeDataStructure {
2162
2553
  }
2163
2554
  }
2164
2555
  }
2165
- return mergedSchema;
2556
+ return this.filterDuplicateKeys(mergedSchema);
2166
2557
  }
2167
- return schema;
2558
+ return this.filterDuplicateKeys(schema);
2559
+ }
2560
+ /**
2561
+ * Filter out ::cyDuplicateKey:: entries from a schema.
2562
+ * These are internal markers for tracking variable reassignments
2563
+ * and should not appear in output schemas or LLM prompts.
2564
+ */
2565
+ filterDuplicateKeys(schema) {
2566
+ return Object.entries(schema).reduce((acc, [key, value]) => {
2567
+ if (!key.includes('::cyDuplicateKey')) {
2568
+ acc[key] = value;
2569
+ }
2570
+ return acc;
2571
+ }, {});
2168
2572
  }
2169
2573
  getEquivalencies(scopeName) {
2170
2574
  const scopeNode = this.getScopeOrFunctionCallInfo(scopeName);
@@ -2186,15 +2590,131 @@ export class ScopeDataStructure {
2186
2590
  if (!scopeNode) {
2187
2591
  return {};
2188
2592
  }
2189
- const entries = this.equivalencyDatabase.filter((entry) => entry.usages.some((usage) => usage.scopeNodeName === scopeNode.name));
2593
+ // Collect all descendant scope names (including the scope itself)
2594
+ // This ensures we include external calls from nested scopes like cyScope2
2595
+ const getAllDescendantScopeNames = (node) => {
2596
+ const names = new Set([node.name]);
2597
+ for (const child of node.children) {
2598
+ for (const name of getAllDescendantScopeNames(child)) {
2599
+ names.add(name);
2600
+ }
2601
+ }
2602
+ return names;
2603
+ };
2604
+ const treeNode = this.scopeTreeManager.findNode(scopeNode.name);
2605
+ const descendantScopeNames = treeNode
2606
+ ? getAllDescendantScopeNames(treeNode)
2607
+ : new Set([scopeNode.name]);
2608
+ // Get all external function calls made from this scope or any descendant scope
2609
+ // This allows us to include prop equivalencies from JSX components
2610
+ // that were rendered in nested scopes (e.g., FileTableRow called from cyScope2)
2611
+ const externalCallsFromScope = this.externalFunctionCalls.filter((efc) => descendantScopeNames.has(efc.callScope));
2612
+ const externalCallNames = new Set(externalCallsFromScope.map((efc) => efc.name));
2613
+ // Helper to check if a usage belongs to this scope (directly, via descendant, or via external call)
2614
+ const usageMatchesScope = (usage) => descendantScopeNames.has(usage.scopeNodeName) ||
2615
+ externalCallNames.has(usage.scopeNodeName);
2616
+ const entries = this.equivalencyDatabase.filter((entry) => entry.usages.some(usageMatchesScope));
2617
+ // Helper to resolve a source candidate through equivalency chains to find signature paths
2618
+ const resolveToSignature = (source, visited) => {
2619
+ const visitKey = `${source.scopeNodeName}::${source.schemaPath}`;
2620
+ if (visited.has(visitKey))
2621
+ return [];
2622
+ visited.add(visitKey);
2623
+ // If already a signature path, return as-is
2624
+ if (source.schemaPath.startsWith('signature[')) {
2625
+ return [source];
2626
+ }
2627
+ const currentScope = this.scopeNodes[source.scopeNodeName];
2628
+ if (!currentScope?.equivalencies)
2629
+ return [source];
2630
+ // Check for direct equivalencies FIRST (full path match)
2631
+ // This ensures paths like "useMemo(...).functionCallReturnValue" follow to "cyScope1::returnValue"
2632
+ // before prefix matching tries "useMemo(...)" which goes to the useMemo scope
2633
+ const directEquivs = currentScope.equivalencies[source.schemaPath];
2634
+ if (directEquivs?.length > 0) {
2635
+ const results = [];
2636
+ for (const equiv of directEquivs) {
2637
+ const resolved = resolveToSignature({
2638
+ scopeNodeName: equiv.scopeNodeName,
2639
+ schemaPath: equiv.schemaPath,
2640
+ }, visited);
2641
+ results.push(...resolved);
2642
+ }
2643
+ if (results.length > 0)
2644
+ return results;
2645
+ }
2646
+ // Handle spread patterns like [...items].sort().functionCallReturnValue
2647
+ // Extract the spread variable and resolve it through the equivalency chain
2648
+ const spreadMatch = source.schemaPath.match(/^\[\.\.\.(\w+)\]/);
2649
+ if (spreadMatch) {
2650
+ const spreadVar = spreadMatch[1];
2651
+ const spreadPattern = spreadMatch[0];
2652
+ const varEquivs = currentScope.equivalencies[spreadVar];
2653
+ if (varEquivs?.length > 0) {
2654
+ const results = [];
2655
+ for (const equiv of varEquivs) {
2656
+ // Follow the variable equivalency and then resolve from there
2657
+ const resolvedVar = resolveToSignature({
2658
+ scopeNodeName: equiv.scopeNodeName,
2659
+ schemaPath: equiv.schemaPath,
2660
+ }, visited);
2661
+ // For each resolved variable path, create the full path with array element suffix
2662
+ for (const rv of resolvedVar) {
2663
+ if (rv.schemaPath.startsWith('signature[')) {
2664
+ // Get the suffix after the spread pattern
2665
+ let suffix = source.schemaPath.slice(spreadPattern.length);
2666
+ // Clean the suffix: strip array method chains like .sort(...).functionCallReturnValue[]
2667
+ // These don't change the data identity, just transform it.
2668
+ // Keep only the final element access parts like [0], [1], etc.
2669
+ // Pattern: strip everything from a method call up through functionCallReturnValue[]
2670
+ suffix = suffix.replace(/\.\w+\([^)]*\)\.functionCallReturnValue\[\]/g, '');
2671
+ // Also handle simpler case without nested parens
2672
+ suffix = suffix.replace(/\.sort\(\w*\(\)\)\.functionCallReturnValue\[\]/g, '');
2673
+ // Add [] to indicate array element access from the spread
2674
+ const resolvedPath = rv.schemaPath + '[]' + suffix;
2675
+ results.push({
2676
+ scopeNodeName: rv.scopeNodeName,
2677
+ schemaPath: resolvedPath,
2678
+ });
2679
+ }
2680
+ }
2681
+ }
2682
+ if (results.length > 0)
2683
+ return results;
2684
+ }
2685
+ }
2686
+ // Try to find prefix equivalencies that can resolve this path
2687
+ // For path like "cyScope3().signature[0][0]", check "cyScope3().signature[0]", etc.
2688
+ const pathParts = this.splitPath(source.schemaPath);
2689
+ for (let i = pathParts.length - 1; i > 0; i--) {
2690
+ const prefix = this.joinPathParts(pathParts.slice(0, i));
2691
+ const suffix = this.joinPathParts(pathParts.slice(i));
2692
+ const prefixEquivs = currentScope.equivalencies[prefix];
2693
+ if (prefixEquivs?.length > 0) {
2694
+ const results = [];
2695
+ for (const equiv of prefixEquivs) {
2696
+ const newPath = this.joinPathParts([equiv.schemaPath, suffix]);
2697
+ const resolved = resolveToSignature({ scopeNodeName: equiv.scopeNodeName, schemaPath: newPath }, visited);
2698
+ results.push(...resolved);
2699
+ }
2700
+ if (results.length > 0)
2701
+ return results;
2702
+ }
2703
+ }
2704
+ return [source];
2705
+ };
2190
2706
  return entries.reduce((acc, entry) => {
2191
2707
  var _a;
2192
2708
  if (entry.sourceCandidates.length === 0)
2193
2709
  return acc;
2194
- const usages = entry.usages.filter((u) => u.scopeNodeName === scopeNode.name);
2710
+ const usages = entry.usages.filter(usageMatchesScope);
2195
2711
  for (const usage of usages) {
2196
2712
  acc[_a = usage.schemaPath] || (acc[_a] = []);
2197
- acc[usage.schemaPath].push(...entry.sourceCandidates);
2713
+ // Resolve each source candidate through the equivalency chain
2714
+ for (const source of entry.sourceCandidates) {
2715
+ const resolvedSources = resolveToSignature(source, new Set());
2716
+ acc[usage.schemaPath].push(...resolvedSources);
2717
+ }
2198
2718
  }
2199
2719
  return acc;
2200
2720
  }, {});
@@ -2230,11 +2750,12 @@ export class ScopeDataStructure {
2230
2750
  return acc;
2231
2751
  }, {});
2232
2752
  const equivalencies = this.getEquivalencies(functionName);
2753
+ const scopeName = functionName ?? this.scopeTreeManager.getRootName();
2233
2754
  for (const equivalenceKey in equivalencies ?? {}) {
2234
2755
  for (const equivalenceValue of equivalencies[equivalenceKey]) {
2235
2756
  const schemaPath = equivalenceValue.schemaPath;
2236
2757
  if (schemaPath.startsWith('signature[') &&
2237
- equivalenceValue.scopeNodeName === functionName &&
2758
+ equivalenceValue.scopeNodeName === scopeName &&
2238
2759
  !signatureInSchema[schemaPath]) {
2239
2760
  signatureInSchema[schemaPath] = 'unknown';
2240
2761
  }
@@ -2242,9 +2763,103 @@ export class ScopeDataStructure {
2242
2763
  }
2243
2764
  const tempScopeNode = this.createTempScopeNode(functionName ?? this.scopeTreeManager.getRootName(), signatureInSchema, equivalencies);
2244
2765
  this.validateSchema(tempScopeNode, true, fillInUnknowns);
2245
- return tempScopeNode.schema;
2766
+ // After validateSchema has filled in types, propagate nested paths from
2767
+ // variables to their signature equivalents.
2768
+ // e.g., workouts[].activity_type -> signature[0].workouts[].activity_type
2769
+ //
2770
+ // Build a map of variable names that are equivalent to signature paths
2771
+ // e.g., { 'workouts': 'signature[0].workouts' }
2772
+ const variableToSignatureMap = {};
2773
+ for (const equivalenceKey in equivalencies ?? {}) {
2774
+ for (const equivalenceValue of equivalencies[equivalenceKey]) {
2775
+ const schemaPath = equivalenceValue.schemaPath;
2776
+ // Track which variables map to signature paths
2777
+ // equivalenceKey is the variable name (e.g., 'workouts')
2778
+ // schemaPath is where it comes from (e.g., 'signature[0].workouts')
2779
+ if (schemaPath.startsWith('signature[') &&
2780
+ equivalenceValue.scopeNodeName === scopeName) {
2781
+ variableToSignatureMap[equivalenceKey] = schemaPath;
2782
+ }
2783
+ }
2784
+ }
2785
+ // Enrich schema with deeply nested paths from internal function call scopes.
2786
+ // When a function call like traverse(tree) exists, and traverse's scope has
2787
+ // signature[0].children[path][entityName] (from propagateParameterToSignaturePaths),
2788
+ // we need to map those paths back to the argument variable (tree) in this scope.
2789
+ // This handles cases where cycle detection prevented the equivalency chain from
2790
+ // propagating deep paths during Phase 2 batch queue processing.
2791
+ for (const equivalenceKey in equivalencies ?? {}) {
2792
+ // Look for keys matching function call pattern: funcName(...).signature[N]
2793
+ const funcCallMatch = equivalenceKey.match(/^([^(]+)\(.*?\)\.(signature\[\d+\])$/);
2794
+ if (!funcCallMatch)
2795
+ continue;
2796
+ const calledFunctionName = funcCallMatch[1];
2797
+ const signatureParam = funcCallMatch[2]; // e.g., "signature[0]"
2798
+ for (const equivalenceValue of equivalencies[equivalenceKey]) {
2799
+ if (equivalenceValue.scopeNodeName !== scopeName)
2800
+ continue;
2801
+ const targetVariable = equivalenceValue.schemaPath;
2802
+ // Get the called function's schema (includes propagated parameter paths)
2803
+ const childSchema = this.getSchema({
2804
+ scopeName: calledFunctionName,
2805
+ });
2806
+ if (!childSchema)
2807
+ continue;
2808
+ // Map child function's signature paths to parent variable paths
2809
+ const sigPrefix = signatureParam + '.';
2810
+ const sigBracketPrefix = signatureParam + '[';
2811
+ for (const childKey in childSchema) {
2812
+ let suffix = null;
2813
+ if (childKey.startsWith(sigPrefix)) {
2814
+ suffix = childKey.slice(signatureParam.length);
2815
+ }
2816
+ else if (childKey.startsWith(sigBracketPrefix)) {
2817
+ suffix = childKey.slice(signatureParam.length);
2818
+ }
2819
+ if (suffix !== null) {
2820
+ const parentKey = targetVariable + suffix;
2821
+ if (!schema[parentKey]) {
2822
+ schema[parentKey] = childSchema[childKey];
2823
+ }
2824
+ }
2825
+ }
2826
+ }
2827
+ }
2828
+ // Propagate nested paths from variables to their signature equivalents
2829
+ // e.g., if workouts = signature[0].workouts, then workouts[].title becomes
2830
+ // signature[0].workouts[].title
2831
+ for (const schemaKey in schema) {
2832
+ // Skip keys that already start with signature[
2833
+ if (schemaKey.startsWith('signature['))
2834
+ continue;
2835
+ // Check if this key starts with a variable that maps to a signature path
2836
+ for (const [variableName, signaturePath] of Object.entries(variableToSignatureMap)) {
2837
+ // Check if schemaKey starts with variableName followed by a property accessor
2838
+ // e.g., 'workouts[]' starts with 'workouts'
2839
+ if (schemaKey === variableName ||
2840
+ schemaKey.startsWith(variableName + '.') ||
2841
+ schemaKey.startsWith(variableName + '[')) {
2842
+ // Transform the path: replace the variable prefix with the signature path
2843
+ const suffix = schemaKey.slice(variableName.length);
2844
+ const signatureKey = signaturePath + suffix;
2845
+ // Add to schema if not already present
2846
+ if (!tempScopeNode.schema[signatureKey]) {
2847
+ tempScopeNode.schema[signatureKey] = schema[schemaKey];
2848
+ }
2849
+ }
2850
+ }
2851
+ }
2852
+ return this.filterDuplicateKeys(tempScopeNode.schema);
2246
2853
  }
2247
2854
  getReturnValue({ functionName, fillInUnknowns, }) {
2855
+ // Trigger finalization on all managers to apply any pending updates
2856
+ // (e.g., ref type propagation to external function call schemas)
2857
+ const rootScope = this.scopeNodes[this.scopeTreeManager.getRootName()];
2858
+ if (rootScope) {
2859
+ for (const manager of this.equivalencyManagers) {
2860
+ manager.finalize(rootScope, this);
2861
+ }
2862
+ }
2248
2863
  const scopeName = functionName ?? this.scopeTreeManager.getRootName();
2249
2864
  const scopeNode = this.scopeNodes[scopeName];
2250
2865
  let schema = {};
@@ -2255,7 +2870,8 @@ export class ScopeDataStructure {
2255
2870
  });
2256
2871
  }
2257
2872
  else {
2258
- for (const externalFunctionCall of this.externalFunctionCalls) {
2873
+ // Use getExternalFunctionCalls() which cleans cyScope from schemas
2874
+ for (const externalFunctionCall of this.getExternalFunctionCalls()) {
2259
2875
  const functionNameParts = this.splitPath(functionName).map((p) => this.functionOrScopeName(p));
2260
2876
  const nameParts = this.splitPath(externalFunctionCall.name).map((p) => this.functionOrScopeName(p));
2261
2877
  if (functionNameParts.every((part, index) => part === nameParts[index])) {
@@ -2276,14 +2892,27 @@ export class ScopeDataStructure {
2276
2892
  // Include function paths even if their return value wasn't captured
2277
2893
  // This ensures methods like onAuthStateChange are included in the schema
2278
2894
  // But exclude signature entries (they should only be included via functionCallReturnValue paths)
2279
- (schema[key] === 'function' && key.indexOf('signature[') === -1))
2895
+ // Also exclude bare function call signatures - paths that are JUST a call like
2896
+ // "useCustomSizes(projectSlug)" should not be included as return values.
2897
+ // These represent "the function exists" not actual return data, and including
2898
+ // them causes nested path bugs in dependencySchemas.
2899
+ (schema[key] === 'function' &&
2900
+ key.indexOf('signature[') === -1 &&
2901
+ // Exclude bare call signatures: function calls with no dots OUTSIDE parentheses
2902
+ // e.g., "useCustomSizes(projectSlug)" is bare (exclude)
2903
+ // e.g., "loadProject({nested.property})" is bare - dots are inside args (exclude)
2904
+ // e.g., "getSupabase().auth.method()" has dots outside - method chain (include)
2905
+ !this.isBareCallSignature(key)))
2280
2906
  .reduce((acc, key) => {
2281
2907
  acc[key] = schema[key];
2282
2908
  const keyParts = this.splitPath(key);
2283
2909
  for (const path in schema) {
2284
2910
  const pathParts = this.splitPath(path);
2285
2911
  if (pathParts.every((p, i) => keyParts[i] === p)) {
2286
- acc[path] = schema[path];
2912
+ // Also exclude bare call signatures from prefix paths
2913
+ if (!this.isBareCallSignature(path)) {
2914
+ acc[path] = schema[path];
2915
+ }
2287
2916
  }
2288
2917
  }
2289
2918
  return acc;
@@ -2291,12 +2920,68 @@ export class ScopeDataStructure {
2291
2920
  // Replace cyScope placeholders with actual callback text
2292
2921
  const resolvedSchema = this.replaceCyScopePlaceholders(returnValueSchema);
2293
2922
  const tempScopeNode = this.createTempScopeNode(scopeName, resolvedSchema);
2923
+ // CRITICAL: Set onlyEquivalencies to true to prevent database modifications
2924
+ // during this "getter" method. See comment in getFunctionSignature.
2925
+ const wasOnlyEquivalencies = this.onlyEquivalencies;
2926
+ this.onlyEquivalencies = true;
2294
2927
  this.validateSchema(tempScopeNode, true, fillInUnknowns);
2295
- return tempScopeNode.schema;
2928
+ this.onlyEquivalencies = wasOnlyEquivalencies;
2929
+ // Remove bare call signatures from the return value schema.
2930
+ // fillInSchemaGapsAndUnknowns may add parent paths like "useCustomSizes(projectSlug)"
2931
+ // when it sees "useCustomSizes(projectSlug).functionCallReturnValue". These bare
2932
+ // call signatures represent "the function exists" not actual return data, and
2933
+ // including them causes nested path bugs in dependencySchemas.
2934
+ const resultSchema = tempScopeNode.schema;
2935
+ for (const key of Object.keys(resultSchema)) {
2936
+ if (this.isBareCallSignature(key)) {
2937
+ delete resultSchema[key];
2938
+ }
2939
+ }
2940
+ return resultSchema;
2941
+ }
2942
+ /**
2943
+ * Checks if a schema key is a "bare call signature" - a function call with no
2944
+ * method chain before it and no path segments after it.
2945
+ *
2946
+ * A bare call signature represents "this function exists" rather than actual
2947
+ * return data, and including them causes nested path bugs in dependencySchemas.
2948
+ *
2949
+ * Examples:
2950
+ * - "useCustomSizes(projectSlug)" -> bare (true)
2951
+ * - "loadProject({nested.property})" -> bare (dots are inside args, true)
2952
+ * - "getSupabase().auth.method()" -> not bare (has dots outside parens, false)
2953
+ * - "useProject().functionCallReturnValue" -> not bare (has path after, false)
2954
+ */
2955
+ isBareCallSignature(key) {
2956
+ // Must end with ) and contain ( to be a call
2957
+ if (!key.endsWith(')') || key.indexOf('(') === -1) {
2958
+ return false;
2959
+ }
2960
+ // Check if there are any dots OUTSIDE of parentheses
2961
+ // Strip out content inside balanced parentheses, then check for dots
2962
+ let depth = 0;
2963
+ let hasDotsOutsideParens = false;
2964
+ for (let i = 0; i < key.length; i++) {
2965
+ const char = key[i];
2966
+ if (char === '(') {
2967
+ depth++;
2968
+ }
2969
+ else if (char === ')') {
2970
+ depth--;
2971
+ }
2972
+ else if (char === '.' && depth === 0) {
2973
+ hasDotsOutsideParens = true;
2974
+ break;
2975
+ }
2976
+ }
2977
+ // It's a bare call signature if there are no dots outside parentheses
2978
+ return !hasDotsOutsideParens;
2296
2979
  }
2297
2980
  /**
2298
2981
  * Replaces cyScope placeholder references (e.g., cyScope10()) in schema keys
2299
2982
  * with the actual callback function text from the corresponding scope node.
2983
+ * If the scope text can't be found, uses a generic fallback to avoid leaking
2984
+ * internal cyScope names into stored data.
2300
2985
  */
2301
2986
  replaceCyScopePlaceholders(schema) {
2302
2987
  const cyScopePattern = /cyScope(\d+)\(\)/g;
@@ -2308,10 +2993,10 @@ export class ScopeDataStructure {
2308
2993
  for (const match of matches) {
2309
2994
  const cyScopeName = `cyScope${match[1]}`;
2310
2995
  const scopeText = this.findCyScopeText(cyScopeName);
2311
- if (scopeText) {
2312
- // Replace cyScope10() with the actual callback text
2313
- newKey = newKey.replace(match[0], scopeText);
2314
- }
2996
+ // Always replace cyScope references - use actual text if available,
2997
+ // otherwise use a generic callback placeholder
2998
+ const replacement = scopeText || '() => {}';
2999
+ newKey = newKey.replace(match[0], replacement);
2315
3000
  }
2316
3001
  result[newKey] = value;
2317
3002
  }
@@ -2361,13 +3046,365 @@ export class ScopeDataStructure {
2361
3046
  getEquivalentSignatureVariables() {
2362
3047
  const scopeNode = this.scopeNodes[this.scopeTreeManager.getRootName()];
2363
3048
  const equivalentSignatureVariables = {};
3049
+ // Helper to add equivalencies - accumulates into array if multiple values for same key
3050
+ // This is critical for OR expressions like `x = a || b` where x should map to both a and b
3051
+ const addEquivalency = (key, value) => {
3052
+ const existing = equivalentSignatureVariables[key];
3053
+ if (existing === undefined) {
3054
+ // First value - store as string
3055
+ equivalentSignatureVariables[key] = value;
3056
+ }
3057
+ else if (typeof existing === 'string') {
3058
+ if (existing !== value) {
3059
+ // Second different value - convert to array
3060
+ equivalentSignatureVariables[key] = [existing, value];
3061
+ }
3062
+ // Same value - no change needed
3063
+ }
3064
+ else {
3065
+ // Already an array - add if not already present
3066
+ if (!existing.includes(value)) {
3067
+ existing.push(value);
3068
+ }
3069
+ }
3070
+ };
2364
3071
  for (const [path, equivalentValues] of Object.entries(scopeNode.equivalencies)) {
2365
3072
  for (const equivalentValue of equivalentValues) {
3073
+ // Case 1: Props/signature equivalencies (existing behavior)
3074
+ // Maps local variable names to their signature paths
3075
+ // e.g., "propValue" -> "signature[0].prop"
2366
3076
  if (path.startsWith('signature[')) {
2367
- equivalentSignatureVariables[equivalentValue.schemaPath] = path;
3077
+ addEquivalency(equivalentValue.schemaPath, path);
3078
+ }
3079
+ // Case 2: Hook variable equivalencies (new behavior)
3080
+ // The equivalencies are stored as: path = variable name, schemaPath = data source
3081
+ // e.g., path = "debugFetcher", schemaPath = "useFetcher<...>().functionCallReturnValue"
3082
+ // We need to map: "debugFetcher" -> "useFetcher<...>()"
3083
+ // This enables resolving paths like "debugFetcher.state" to
3084
+ // "useFetcher<...>().state" for execution flow validation
3085
+ if (equivalentValue.schemaPath.endsWith('.functionCallReturnValue')) {
3086
+ // Extract the hook call path (everything before .functionCallReturnValue)
3087
+ let hookCallPath = equivalentValue.schemaPath.slice(0, -'.functionCallReturnValue'.length);
3088
+ // Only include if it looks like a hook call (contains parentheses)
3089
+ // and the variable name (path) is a simple identifier (no dots)
3090
+ if (hookCallPath.includes('(') && !path.includes('.')) {
3091
+ // Special case: If hookCallPath is a callback scope (cyScope pattern),
3092
+ // trace through it to find what the callback actually returns.
3093
+ // This handles useState(() => { return prop; }) patterns.
3094
+ const cyScopeMatch = hookCallPath.match(/^(cyScope\d+)\(\)$/);
3095
+ if (cyScopeMatch) {
3096
+ // Use the equivalency database to trace the callback's return value
3097
+ // to its actual source (e.g., viewModeFromUrl -> segments -> params -> useParams)
3098
+ const dbEntry = this.getEquivalenciesDatabaseEntry(scopeNode.name, // Component scope
3099
+ path);
3100
+ if (dbEntry?.sourceCandidates?.length > 0) {
3101
+ // Use the traced source instead of the callback scope
3102
+ hookCallPath = dbEntry.sourceCandidates[0].schemaPath;
3103
+ }
3104
+ }
3105
+ addEquivalency(path, hookCallPath);
3106
+ }
3107
+ }
3108
+ // Case 3: Destructured variables from local variables
3109
+ // e.g., const { scenarios } = currentEntityAnalysis;
3110
+ // This creates: path = "scenarios", schemaPath = "currentEntityAnalysis.scenarios"
3111
+ // We need to map: "scenarios" -> "currentEntityAnalysis.scenarios"
3112
+ // AND resolve transitively if currentEntityAnalysis is itself equivalent to a hook call
3113
+ if (!path.includes('.') && // path is a simple identifier
3114
+ !equivalentValue.schemaPath.startsWith('signature[') && // not a signature path
3115
+ !equivalentValue.schemaPath.endsWith('.functionCallReturnValue') // not already handled above
3116
+ ) {
3117
+ // Add equivalency (will accumulate if multiple values for OR expressions)
3118
+ addEquivalency(path, equivalentValue.schemaPath);
3119
+ }
3120
+ // Case 4: Child component prop mappings (Fix 22)
3121
+ // When parent renders <ChildComponent prop={value} />, we get equivalencies like:
3122
+ // path = "ChildComponent().signature[0].prop"
3123
+ // schemaPath = "value" (the variable passed as the prop)
3124
+ // We need to include these so translateChildPathToParent can work.
3125
+ // Pattern: ComponentName().signature[N] or ComponentName().signature[N].propName
3126
+ if (path.includes('().signature[') &&
3127
+ !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable, not a function call
3128
+ ) {
3129
+ addEquivalency(path, equivalentValue.schemaPath);
3130
+ }
3131
+ // Case 5: Destructured function parameters (Fix 25)
3132
+ // When a function has destructured props: function Comp({ propA, propB }: Props)
3133
+ // We get equivalencies like:
3134
+ // path = "propA" (the destructured variable name)
3135
+ // schemaPath = "signature[0].propA" (the signature path)
3136
+ // We need to map: "propA" -> "signature[0].propA"
3137
+ // This enables translateChildPathToParent to resolve child variable paths
3138
+ // to their signature paths when merging execution flows.
3139
+ if (!path.includes('.') && // path is a simple identifier (destructured prop name)
3140
+ equivalentValue.schemaPath.startsWith('signature[') // schemaPath IS a signature path
3141
+ ) {
3142
+ addEquivalency(path, equivalentValue.schemaPath);
3143
+ }
3144
+ // Case 7: Method calls on variables that result in .functionCallReturnValue (Fix 33)
3145
+ // When we have patterns like:
3146
+ // path = "segments" (simple identifier)
3147
+ // schemaPath = "splat.split('/').functionCallReturnValue"
3148
+ // This is a method call on a variable (not a hook call), but we still need to
3149
+ // track it so transitive resolution can resolve `splat` to its actual source.
3150
+ // E.g., if splat -> useParams().functionCallReturnValue['*'], then
3151
+ // segments -> useParams().functionCallReturnValue['*'].split('/').functionCallReturnValue
3152
+ if (!path.includes('.') && // path is a simple identifier
3153
+ equivalentValue.schemaPath.endsWith('.functionCallReturnValue') && // ends with function return
3154
+ equivalentValue.schemaPath.includes('.') // has property access (method call)
3155
+ ) {
3156
+ // Check if this looks like a method call on a variable (not a hook call)
3157
+ // Hook calls look like: hookName() or hookName<T>()
3158
+ // Method calls look like: variable.method() or variable.method<T>()
3159
+ const hookCallPath = equivalentValue.schemaPath.slice(0, -'.functionCallReturnValue'.length);
3160
+ // If it's a method call (contains a dot before the parenthesis), include it
3161
+ const dotBeforeParen = hookCallPath.indexOf('.');
3162
+ const parenPos = hookCallPath.indexOf('(');
3163
+ if (dotBeforeParen !== -1 && dotBeforeParen < parenPos) {
3164
+ // This is a method call like "splat.split('/')", not a hook call
3165
+ addEquivalency(path, equivalentValue.schemaPath);
3166
+ }
3167
+ }
3168
+ }
3169
+ }
3170
+ // Case 6: Collect JSX child prop equivalencies from child scopes (Fix 26)
3171
+ // When a parent component renders <ChildComponent prop={value} />, the JSX
3172
+ // return statement may be in a child scope (e.g., cyScope2). The equivalencies
3173
+ // like ChildComponent().signature[0].prop -> value get stored in that child scope.
3174
+ // But translateChildPathToParent needs to find them from the parent scope's context.
3175
+ // So we collect Case 4 patterns from ALL child scopes that belong to this root scope.
3176
+ const rootName = this.scopeTreeManager.getRootName();
3177
+ for (const [scopeName, childScopeNode] of Object.entries(this.scopeNodes)) {
3178
+ // Skip the root scope (already processed above)
3179
+ if (scopeName === rootName)
3180
+ continue;
3181
+ // Only include scopes that are children of the root (their tree includes root)
3182
+ if (!childScopeNode.tree?.includes(rootName))
3183
+ continue;
3184
+ // Look for Case 4 patterns in the child scope
3185
+ for (const [path, equivalentValues] of Object.entries(childScopeNode.equivalencies || {})) {
3186
+ for (const equivalentValue of equivalentValues) {
3187
+ // Case 4 pattern: ChildComponent().signature[0].propName -> parentVariable
3188
+ if (path.includes('().signature[') &&
3189
+ !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable
3190
+ ) {
3191
+ // Only add if not already present from the root scope
3192
+ // Root scope values take precedence over child scope values
3193
+ if (!(path in equivalentSignatureVariables)) {
3194
+ addEquivalency(path, equivalentValue.schemaPath);
3195
+ }
3196
+ }
2368
3197
  }
2369
3198
  }
2370
3199
  }
3200
+ // Transitive resolution: Resolve variable chains through multiple levels
3201
+ // E.g., analysis → currentEntityAnalysis → useLoaderData().functionCallReturnValue.currentEntityAnalysis
3202
+ // We need multiple passes because resolutions can depend on each other
3203
+ const maxIterations = 5; // Prevent infinite loops
3204
+ // Helper function to resolve a single source path using equivalencies
3205
+ const resolveSourcePath = (sourcePath, equivMap) => {
3206
+ // Extract base variable from the path
3207
+ const dotIndex = sourcePath.indexOf('.');
3208
+ const bracketIndex = sourcePath.indexOf('[');
3209
+ let baseVar;
3210
+ let rest;
3211
+ if (dotIndex === -1 && bracketIndex === -1) {
3212
+ baseVar = sourcePath;
3213
+ rest = '';
3214
+ }
3215
+ else if (dotIndex === -1) {
3216
+ baseVar = sourcePath.slice(0, bracketIndex);
3217
+ rest = sourcePath.slice(bracketIndex);
3218
+ }
3219
+ else if (bracketIndex === -1) {
3220
+ baseVar = sourcePath.slice(0, dotIndex);
3221
+ rest = sourcePath.slice(dotIndex);
3222
+ }
3223
+ else {
3224
+ const firstIndex = Math.min(dotIndex, bracketIndex);
3225
+ baseVar = sourcePath.slice(0, firstIndex);
3226
+ rest = sourcePath.slice(firstIndex);
3227
+ }
3228
+ // Look up the base variable in equivalencies
3229
+ if (baseVar in equivMap && equivMap[baseVar] !== sourcePath) {
3230
+ const baseResolved = equivMap[baseVar];
3231
+ // Skip if baseResolved is an array (handle later)
3232
+ if (Array.isArray(baseResolved))
3233
+ return null;
3234
+ // If it resolves to a signature path, build the full resolved path
3235
+ if (baseResolved.startsWith('signature[') ||
3236
+ baseResolved.includes('()')) {
3237
+ if (baseResolved.endsWith('()')) {
3238
+ return baseResolved + '.functionCallReturnValue' + rest;
3239
+ }
3240
+ return baseResolved + rest;
3241
+ }
3242
+ }
3243
+ return null;
3244
+ };
3245
+ for (let iteration = 0; iteration < maxIterations; iteration++) {
3246
+ let changed = false;
3247
+ for (const [varName, sourcePathOrArray] of Object.entries(equivalentSignatureVariables)) {
3248
+ // Handle arrays (OR expressions) by resolving each element
3249
+ if (Array.isArray(sourcePathOrArray)) {
3250
+ const resolvedArray = [];
3251
+ let arrayChanged = false;
3252
+ for (const sourcePath of sourcePathOrArray) {
3253
+ // Try to resolve this path using transitive resolution
3254
+ const resolved = resolveSourcePath(sourcePath, equivalentSignatureVariables);
3255
+ if (resolved && resolved !== sourcePath) {
3256
+ resolvedArray.push(resolved);
3257
+ arrayChanged = true;
3258
+ }
3259
+ else {
3260
+ resolvedArray.push(sourcePath);
3261
+ }
3262
+ }
3263
+ if (arrayChanged) {
3264
+ equivalentSignatureVariables[varName] = resolvedArray;
3265
+ changed = true;
3266
+ }
3267
+ continue;
3268
+ }
3269
+ const sourcePath = sourcePathOrArray;
3270
+ // Skip if already fully resolved (contains function call syntax)
3271
+ // BUT first check for computed value patterns that need resolution (Fix 28)
3272
+ // AND method call patterns that need base variable resolution (Fix 33)
3273
+ if (sourcePath.includes('()')) {
3274
+ // Fix 28: Handle computed value patterns with dependency arrays
3275
+ // Patterns like `functionName(arg, [dep1, dep2, ...])` are NOT controllable
3276
+ // data sources. We trace through the dependencies to find controllable sources.
3277
+ const bracketStart = sourcePath.indexOf('[');
3278
+ const bracketEnd = sourcePath.lastIndexOf(']');
3279
+ if (bracketStart !== -1 && bracketEnd > bracketStart) {
3280
+ const arrayContent = sourcePath.slice(bracketStart + 1, bracketEnd);
3281
+ const items = arrayContent.split(',').map((s) => s.trim());
3282
+ // Only process if this looks like a dependency array:
3283
+ // multiple items that are all simple identifiers (not numbers or expressions)
3284
+ const isIdentifier = (s) => /^\w+$/.test(s) && !/^\d+$/.test(s);
3285
+ if (items.length > 1 && items.every(isIdentifier)) {
3286
+ // Look for a dependency that's already resolved to a controllable source
3287
+ for (const dep of items) {
3288
+ if (dep in equivalentSignatureVariables) {
3289
+ const resolvedDep = equivalentSignatureVariables[dep];
3290
+ // Use if it's a controllable path (contains hook call)
3291
+ // and is NOT another unresolved computed pattern (has comma-separated deps)
3292
+ const hasCommaInBrackets = resolvedDep.includes('[') &&
3293
+ resolvedDep.includes(',') &&
3294
+ resolvedDep.indexOf(',') > resolvedDep.indexOf('[');
3295
+ if (resolvedDep.includes('()') && !hasCommaInBrackets) {
3296
+ // Computed value is typically an element from an array
3297
+ equivalentSignatureVariables[varName] = resolvedDep + '[]';
3298
+ changed = true;
3299
+ break;
3300
+ }
3301
+ }
3302
+ }
3303
+ }
3304
+ }
3305
+ // Fix 33: Handle method call patterns on variables
3306
+ // Patterns like: "splat.split('/').functionCallReturnValue"
3307
+ // We need to resolve the base variable (splat) to its actual source
3308
+ // Check if this is a method call on a variable (dot before first parenthesis)
3309
+ const dotIndex = sourcePath.indexOf('.');
3310
+ const parenIndex = sourcePath.indexOf('(');
3311
+ if (dotIndex !== -1 &&
3312
+ dotIndex < parenIndex &&
3313
+ !sourcePath.startsWith('use') // Not a hook call like useState()
3314
+ ) {
3315
+ // Extract the base variable (before the first dot)
3316
+ const baseVar = sourcePath.slice(0, dotIndex);
3317
+ const rest = sourcePath.slice(dotIndex); // includes ".method(...).functionCallReturnValue"
3318
+ // Check if the base variable can be resolved
3319
+ if (baseVar in equivalentSignatureVariables &&
3320
+ baseVar !== varName) {
3321
+ const baseResolved = equivalentSignatureVariables[baseVar];
3322
+ // Skip if baseResolved is an array (OR expression)
3323
+ if (Array.isArray(baseResolved))
3324
+ continue;
3325
+ // Only resolve if the base resolved to something useful (contains () or .)
3326
+ if (baseResolved.includes('()') || baseResolved.includes('.')) {
3327
+ const newPath = baseResolved + rest;
3328
+ if (newPath !== equivalentSignatureVariables[varName]) {
3329
+ equivalentSignatureVariables[varName] = newPath;
3330
+ changed = true;
3331
+ }
3332
+ }
3333
+ }
3334
+ }
3335
+ // Fix 38: Handle cyScope lazy initializer return values
3336
+ // When we have viewMode -> cyScope20(), trace through to find what cyScope20 returns.
3337
+ // The lazy initializer's return value should be the controllable data source.
3338
+ // Pattern: cyScopeN() where N is a number
3339
+ const cyScopeMatch = sourcePath.match(/^(cyScope\d+)\(\)$/);
3340
+ if (cyScopeMatch) {
3341
+ const cyScopeName = cyScopeMatch[1];
3342
+ const cyScopeNode = this.scopeNodes[cyScopeName];
3343
+ if (cyScopeNode?.equivalencies) {
3344
+ // Look for returnValue equivalency in the cyScope
3345
+ const returnValueEquivs = cyScopeNode.equivalencies['returnValue'];
3346
+ if (returnValueEquivs && returnValueEquivs.length > 0) {
3347
+ // Get the first return value source
3348
+ const returnSource = returnValueEquivs[0].schemaPath;
3349
+ // If the return source is a simple variable (not a complex path),
3350
+ // resolve varName directly to that variable
3351
+ if (returnSource &&
3352
+ !returnSource.includes('(') &&
3353
+ !returnSource.includes('[')) {
3354
+ // Update varName to point to the return source
3355
+ if (equivalentSignatureVariables[varName] !== returnSource) {
3356
+ equivalentSignatureVariables[varName] = returnSource;
3357
+ changed = true;
3358
+ }
3359
+ }
3360
+ }
3361
+ }
3362
+ }
3363
+ continue;
3364
+ }
3365
+ // Check if the source path starts with a variable that's also in the map
3366
+ const dotIndex = sourcePath.indexOf('.');
3367
+ let baseVar;
3368
+ let rest;
3369
+ if (dotIndex > 0) {
3370
+ // Path has a dot: "a.b.c" -> baseVar="a", rest=".b.c"
3371
+ baseVar = sourcePath.slice(0, dotIndex);
3372
+ rest = sourcePath.slice(dotIndex); // includes the leading dot
3373
+ }
3374
+ else {
3375
+ // Path is a simple identifier: "currentEntityAnalysis" -> baseVar="currentEntityAnalysis", rest=""
3376
+ baseVar = sourcePath;
3377
+ rest = '';
3378
+ }
3379
+ if (baseVar in equivalentSignatureVariables && baseVar !== varName) {
3380
+ // Handle array case (OR expressions) - use first element
3381
+ const rawBaseResolved = equivalentSignatureVariables[baseVar];
3382
+ const baseResolved = Array.isArray(rawBaseResolved)
3383
+ ? rawBaseResolved[0]
3384
+ : rawBaseResolved;
3385
+ if (!baseResolved)
3386
+ continue;
3387
+ // If the base resolves to a hook call, add .functionCallReturnValue
3388
+ if (baseResolved.endsWith('()')) {
3389
+ const newPath = baseResolved + '.functionCallReturnValue' + rest;
3390
+ if (newPath !== equivalentSignatureVariables[varName]) {
3391
+ equivalentSignatureVariables[varName] = newPath;
3392
+ changed = true;
3393
+ }
3394
+ }
3395
+ else if (baseResolved !== sourcePath) {
3396
+ const newPath = baseResolved + rest;
3397
+ if (newPath !== equivalentSignatureVariables[varName]) {
3398
+ equivalentSignatureVariables[varName] = newPath;
3399
+ changed = true;
3400
+ }
3401
+ }
3402
+ }
3403
+ }
3404
+ // Stop if no changes were made in this iteration
3405
+ if (!changed)
3406
+ break;
3407
+ }
2371
3408
  return equivalentSignatureVariables;
2372
3409
  }
2373
3410
  getVariableInfo(variableName, scopeName, final) {
@@ -2399,7 +3436,12 @@ export class ScopeDataStructure {
2399
3436
  return { ...acc, ...filterdSchema };
2400
3437
  }, {});
2401
3438
  const tempScopeNode = this.createTempScopeNode(scopeName ?? this.scopeTreeManager.getRootName(), relevantSchema);
3439
+ // CRITICAL: Set onlyEquivalencies to true to prevent database modifications
3440
+ // during this "getter" method. See comment in getFunctionSignature.
3441
+ const wasOnlyEquivalencies = this.onlyEquivalencies;
3442
+ this.onlyEquivalencies = true;
2402
3443
  this.validateSchema(tempScopeNode, true, final);
3444
+ this.onlyEquivalencies = wasOnlyEquivalencies;
2403
3445
  return {
2404
3446
  name: variableName,
2405
3447
  equivalentTo: equivalents,
@@ -2407,7 +3449,96 @@ export class ScopeDataStructure {
2407
3449
  };
2408
3450
  }
2409
3451
  getExternalFunctionCalls() {
2410
- return this.externalFunctionCalls;
3452
+ // Replace cyScope placeholders in all external function call data
3453
+ // This ensures call signatures and schema paths use actual callback text
3454
+ // instead of internal cyScope names, preventing mock data merge conflicts.
3455
+ return this.externalFunctionCalls.map((efc) => this.cleanCyScopeFromFunctionCallInfo(efc));
3456
+ }
3457
+ /**
3458
+ * Cleans cyScope placeholder references from a FunctionCallInfo.
3459
+ * Replaces cyScopeN() with the actual callback text in:
3460
+ * - callSignature
3461
+ * - allCallSignatures
3462
+ * - schema keys
3463
+ */
3464
+ cleanCyScopeFromFunctionCallInfo(efc) {
3465
+ const cyScopePattern = /cyScope\d+\(\)/g;
3466
+ // Check if any cleaning is needed
3467
+ const hasCyScope = cyScopePattern.test(efc.callSignature) ||
3468
+ (efc.allCallSignatures &&
3469
+ efc.allCallSignatures.some((sig) => /cyScope\d+\(\)/.test(sig))) ||
3470
+ (efc.schema &&
3471
+ Object.keys(efc.schema).some((key) => /cyScope\d+\(\)/.test(key)));
3472
+ if (!hasCyScope) {
3473
+ return efc;
3474
+ }
3475
+ // Create cleaned copy
3476
+ const cleaned = { ...efc };
3477
+ // Clean callSignature
3478
+ cleaned.callSignature = this.replaceCyScopeInString(efc.callSignature);
3479
+ // Clean allCallSignatures
3480
+ if (efc.allCallSignatures) {
3481
+ cleaned.allCallSignatures = efc.allCallSignatures.map((sig) => this.replaceCyScopeInString(sig));
3482
+ }
3483
+ // Clean schema keys
3484
+ if (efc.schema) {
3485
+ cleaned.schema = this.replaceCyScopePlaceholders(efc.schema);
3486
+ }
3487
+ // Clean callSignatureToVariable keys
3488
+ if (efc.callSignatureToVariable) {
3489
+ cleaned.callSignatureToVariable = Object.entries(efc.callSignatureToVariable).reduce((acc, [key, value]) => {
3490
+ acc[this.replaceCyScopeInString(key)] = value;
3491
+ return acc;
3492
+ }, {});
3493
+ }
3494
+ return cleaned;
3495
+ }
3496
+ /**
3497
+ * Replaces cyScope placeholder references in a single string.
3498
+ * If the scope text can't be found, uses a generic fallback to avoid leaking
3499
+ * internal cyScope names into stored data.
3500
+ *
3501
+ * Handles two patterns:
3502
+ * 1. Function call style: cyScope7() - matched by cyScope(\d+)\(\)
3503
+ * 2. Scope name style: parentName____cyScopeXX or cyScopeXX - matched by (\w+____)?cyScope([0-9A-Fa-f]+)
3504
+ */
3505
+ replaceCyScopeInString(str) {
3506
+ let result = str;
3507
+ // Pattern 1: Function call style - cyScope7()
3508
+ const functionCallPattern = /cyScope(\d+)\(\)/g;
3509
+ const functionCallMatches = [...str.matchAll(functionCallPattern)];
3510
+ for (const match of functionCallMatches) {
3511
+ const cyScopeName = `cyScope${match[1]}`;
3512
+ const scopeText = this.findCyScopeText(cyScopeName);
3513
+ // Always replace cyScope references - use actual text if available,
3514
+ // otherwise use a generic callback placeholder
3515
+ const replacement = scopeText || '() => {}';
3516
+ result = result.replace(match[0], replacement);
3517
+ }
3518
+ // Pattern 2: Scope name style - parentName____cyScopeXX or just cyScopeXX
3519
+ // This handles hex-encoded scope IDs like cyScope1F
3520
+ const scopeNamePattern = /(\w+____)?cyScope([0-9A-Fa-f]+)/g;
3521
+ const scopeNameMatches = [...result.matchAll(scopeNamePattern)];
3522
+ for (const match of scopeNameMatches) {
3523
+ const fullMatch = match[0];
3524
+ const prefix = match[1] || ''; // e.g., "getTitleColor____"
3525
+ const cyScopeId = match[2]; // e.g., "1F"
3526
+ const cyScopeName = `cyScope${cyScopeId}`;
3527
+ // Try to find the scope text, checking both with and without prefix
3528
+ let scopeText = this.findCyScopeText(cyScopeName);
3529
+ if (!scopeText && prefix) {
3530
+ // Try looking up with the full prefixed name
3531
+ scopeText = this.findCyScopeText(`${prefix}${cyScopeName}`);
3532
+ }
3533
+ if (scopeText) {
3534
+ result = result.replace(fullMatch, scopeText);
3535
+ }
3536
+ else {
3537
+ // Replace with a generic identifier to avoid leaking internal names
3538
+ result = result.replace(fullMatch, 'callback');
3539
+ }
3540
+ }
3541
+ return result;
2411
3542
  }
2412
3543
  getEnvironmentVariables() {
2413
3544
  return this.environmentVariables;
@@ -2433,9 +3564,112 @@ export class ScopeDataStructure {
2433
3564
  }
2434
3565
  }
2435
3566
  }
3567
+ /**
3568
+ * Add conditional effects from AST analysis.
3569
+ * Called during scope analysis to collect all setter calls inside conditionals.
3570
+ */
3571
+ addConditionalEffects(effects) {
3572
+ // Add effects, avoiding duplicates based on effect stateVariable and condition paths
3573
+ for (const effect of effects) {
3574
+ const exists = this.rawConditionalEffects.some((existing) => {
3575
+ // Same effect target (stateVariable + value)
3576
+ const sameEffect = existing.effect.stateVariable === effect.effect.stateVariable &&
3577
+ existing.effect.value === effect.effect.value;
3578
+ if (!sameEffect)
3579
+ return false;
3580
+ // Same condition(s)
3581
+ if (existing.condition && effect.condition) {
3582
+ return (existing.condition.path === effect.condition.path &&
3583
+ existing.condition.requiredValue === effect.condition.requiredValue);
3584
+ }
3585
+ if (existing.conditions && effect.conditions) {
3586
+ if (existing.conditions.length !== effect.conditions.length)
3587
+ return false;
3588
+ return existing.conditions.every((ec, i) => {
3589
+ const newCond = effect.conditions[i];
3590
+ return (ec.path === newCond.path &&
3591
+ ec.requiredValue === newCond.requiredValue);
3592
+ });
3593
+ }
3594
+ return false;
3595
+ });
3596
+ if (!exists) {
3597
+ this.rawConditionalEffects.push(effect);
3598
+ }
3599
+ }
3600
+ }
3601
+ /**
3602
+ * Get conditional effects collected during analysis.
3603
+ */
3604
+ getConditionalEffects() {
3605
+ return this.rawConditionalEffects;
3606
+ }
3607
+ /**
3608
+ * Add compound conditionals from AST analysis.
3609
+ * Called during scope analysis to collect grouped conditions (e.g., a && b && c).
3610
+ */
3611
+ addCompoundConditionals(compounds) {
3612
+ // Add compounds, avoiding duplicates based on chainId
3613
+ for (const compound of compounds) {
3614
+ const exists = this.rawCompoundConditionals.some((existing) => existing.chainId === compound.chainId);
3615
+ if (!exists) {
3616
+ this.rawCompoundConditionals.push(compound);
3617
+ }
3618
+ }
3619
+ }
3620
+ /**
3621
+ * Get compound conditionals collected during analysis.
3622
+ */
3623
+ getCompoundConditionals() {
3624
+ return this.rawCompoundConditionals;
3625
+ }
3626
+ /**
3627
+ * Add child boundary gating conditions from AST analysis.
3628
+ * These track which conditions must be true for a child component to render.
3629
+ */
3630
+ addChildBoundaryGatingConditions(conditions) {
3631
+ for (const [childName, usages] of Object.entries(conditions)) {
3632
+ if (!this.rawChildBoundaryGatingConditions[childName]) {
3633
+ this.rawChildBoundaryGatingConditions[childName] = [];
3634
+ }
3635
+ // Add usages, avoiding duplicates
3636
+ for (const usage of usages) {
3637
+ const exists = this.rawChildBoundaryGatingConditions[childName].some((existing) => existing.path === usage.path &&
3638
+ existing.conditionType === usage.conditionType &&
3639
+ existing.isNegated === usage.isNegated);
3640
+ if (!exists) {
3641
+ this.rawChildBoundaryGatingConditions[childName].push(usage);
3642
+ }
3643
+ }
3644
+ }
3645
+ }
3646
+ /**
3647
+ * Get enriched child boundary gating conditions with source tracing.
3648
+ * Similar to getEnrichedConditionalUsages but for gating conditions.
3649
+ */
3650
+ getEnrichedChildBoundaryGatingConditions() {
3651
+ const enriched = {};
3652
+ const rootScopeName = this.scopeTreeManager.getTree().name;
3653
+ for (const [childName, usages] of Object.entries(this.rawChildBoundaryGatingConditions)) {
3654
+ enriched[childName] = usages.map((usage) => {
3655
+ // Try to trace this path back to a data source
3656
+ const explanation = this.explainPath(rootScopeName, usage.path);
3657
+ let sourceDataPath;
3658
+ if (explanation.source) {
3659
+ sourceDataPath = `${explanation.source.scope}.${explanation.source.path}`;
3660
+ }
3661
+ return {
3662
+ ...usage,
3663
+ sourceDataPath,
3664
+ };
3665
+ });
3666
+ }
3667
+ return enriched;
3668
+ }
2436
3669
  /**
2437
3670
  * Get enriched conditional usages with source tracing.
2438
3671
  * Uses explainPath to trace each local variable back to its data source.
3672
+ * Preserves all fields from the raw conditional usages including derivedFrom.
2439
3673
  */
2440
3674
  getEnrichedConditionalUsages() {
2441
3675
  const enriched = {};
@@ -2456,69 +3690,435 @@ export class ScopeDataStructure {
2456
3690
  }
2457
3691
  return enriched;
2458
3692
  }
3693
+ /**
3694
+ * Add JSX rendering usages from AST analysis.
3695
+ * These track arrays rendered via .map() and strings interpolated in JSX.
3696
+ */
3697
+ addJsxRenderingUsages(usages) {
3698
+ // Add usages, avoiding duplicates based on path and renderingType
3699
+ for (const usage of usages) {
3700
+ const exists = this.rawJsxRenderingUsages.some((existing) => existing.path === usage.path &&
3701
+ existing.renderingType === usage.renderingType);
3702
+ if (!exists) {
3703
+ this.rawJsxRenderingUsages.push(usage);
3704
+ }
3705
+ }
3706
+ }
3707
+ /**
3708
+ * Get JSX rendering usages collected during analysis.
3709
+ */
3710
+ getJsxRenderingUsages() {
3711
+ return this.rawJsxRenderingUsages;
3712
+ }
2459
3713
  toSerializable() {
2460
- // Helper to convert ScopeVariable to SerializableScopeVariable
3714
+ // Helper to clean cyScope and cyDuplicateKey from a string for output
3715
+ const cleanCyScope = (str) => this.replaceCyScopeInString(str).replace(/::cyDuplicateKey\d+::/g, '');
3716
+ // Helper to convert ScopeVariable to SerializableScopeVariable (with cyScope cleaned)
2461
3717
  const toSerializableVariable = (vars) => vars.map((v) => ({
2462
- scopeNodeName: v.scopeNodeName,
2463
- schemaPath: v.schemaPath,
3718
+ scopeNodeName: cleanCyScope(v.scopeNodeName),
3719
+ schemaPath: cleanCyScope(v.schemaPath),
2464
3720
  }));
3721
+ // Helper to clean cyScope from all keys in a schema
3722
+ const cleanSchemaKeys = (schema) => {
3723
+ return Object.entries(schema).reduce((acc, [key, value]) => {
3724
+ acc[cleanCyScope(key)] = value;
3725
+ return acc;
3726
+ }, {});
3727
+ };
2465
3728
  // Helper to get function result for a given function name
2466
3729
  const getFunctionResult = (functionName) => {
2467
3730
  return {
2468
- signature: this.getFunctionSignature({ functionName }) ?? {},
2469
- signatureWithUnknowns: this.getFunctionSignature({ functionName, fillInUnknowns: true }) ??
2470
- {},
2471
- returnValue: this.getReturnValue({ functionName }) ?? {},
2472
- returnValueWithUnknowns: this.getReturnValue({ functionName, fillInUnknowns: true }) ?? {},
3731
+ signature: cleanSchemaKeys(this.getFunctionSignature({ functionName }) ?? {}),
3732
+ signatureWithUnknowns: cleanSchemaKeys(this.getFunctionSignature({ functionName, fillInUnknowns: true }) ??
3733
+ {}),
3734
+ returnValue: cleanSchemaKeys(this.getReturnValue({ functionName }) ?? {}),
3735
+ returnValueWithUnknowns: cleanSchemaKeys(this.getReturnValue({ functionName, fillInUnknowns: true }) ?? {}),
2473
3736
  usageEquivalencies: Object.entries(this.getUsageEquivalencies(functionName) ?? {}).reduce((acc, [key, vars]) => {
2474
- acc[key] = toSerializableVariable(vars);
3737
+ // Clean cyScope from the key as well as variable properties
3738
+ acc[cleanCyScope(key)] = toSerializableVariable(vars);
2475
3739
  return acc;
2476
3740
  }, {}),
2477
3741
  sourceEquivalencies: Object.entries(this.getSourceEquivalencies(functionName) ?? {}).reduce((acc, [key, vars]) => {
2478
- acc[key] = toSerializableVariable(vars);
3742
+ // Clean cyScope from the key as well as variable properties
3743
+ acc[cleanCyScope(key)] = toSerializableVariable(vars);
2479
3744
  return acc;
2480
3745
  }, {}),
2481
3746
  environmentVariables: this.getEnvironmentVariables(),
2482
3747
  };
2483
3748
  };
2484
- // Convert external function calls
2485
- const externalFunctionCalls = this.externalFunctionCalls.map((efc) => ({
2486
- name: efc.name,
2487
- callSignature: efc.callSignature,
2488
- callScope: efc.callScope,
2489
- schema: efc.schema,
2490
- equivalencies: efc.equivalencies
2491
- ? Object.entries(efc.equivalencies).reduce((acc, [key, vars]) => {
2492
- acc[key] = toSerializableVariable(vars);
2493
- return acc;
2494
- }, {})
2495
- : undefined,
2496
- allCallSignatures: efc.allCallSignatures,
2497
- receivingVariableNames: efc.receivingVariableNames,
2498
- callSignatureToVariable: efc.callSignatureToVariable,
2499
- }));
3749
+ // Convert external function calls - use getExternalFunctionCalls() which cleans cyScope
3750
+ const cleanedExternalCalls = this.getExternalFunctionCalls();
3751
+ // Get root scope schema for building per-variable return value schemas
3752
+ const rootScopeName = this.scopeTreeManager.getRootName();
3753
+ const rootScope = this.scopeNodes[rootScopeName];
3754
+ const rootSchema = rootScope?.schema ?? {};
3755
+ const externalFunctionCalls = cleanedExternalCalls.map((efc) => {
3756
+ // Build perVariableSchemas from perCallSignatureSchemas when available.
3757
+ // This preserves distinct schemas per variable when the same function is called
3758
+ // multiple times with DIFFERENT call signatures (e.g., different type parameters).
3759
+ //
3760
+ // When field accesses happen in child scopes (like JSX expressions), the
3761
+ // rootSchema doesn't contain the detailed paths - they end up in child scope
3762
+ // schemas. Using perCallSignatureSchemas ensures we get the correct schema
3763
+ // for each call, regardless of where field accesses occur.
3764
+ let perVariableSchemas;
3765
+ // Use perCallSignatureSchemas only when:
3766
+ // 1. It exists and has distinct entries for different call signatures
3767
+ // 2. The number of distinct call signatures >= number of receiving variables
3768
+ //
3769
+ // This prevents using it when all calls have the same signature (e.g., useFetcher() x 2)
3770
+ // because in that case, perCallSignatureSchemas only has one entry.
3771
+ const numCallSignatures = efc.perCallSignatureSchemas
3772
+ ? Object.keys(efc.perCallSignatureSchemas).length
3773
+ : 0;
3774
+ const numReceivingVars = efc.receivingVariableNames?.length ?? 0;
3775
+ const hasDistinctSchemas = numCallSignatures >= numReceivingVars && numCallSignatures > 1;
3776
+ // CASE 1: Multiple call signatures with distinct schemas - use indexed variable names
3777
+ if (hasDistinctSchemas &&
3778
+ efc.perCallSignatureSchemas &&
3779
+ efc.callSignatureToVariable) {
3780
+ perVariableSchemas = {};
3781
+ // Build a reverse map: variable -> array of call signatures (in order)
3782
+ // This handles the case where the same variable name is reused for different calls
3783
+ const varToCallSigs = {};
3784
+ for (const [callSig, varName] of Object.entries(efc.callSignatureToVariable)) {
3785
+ if (!varToCallSigs[varName]) {
3786
+ varToCallSigs[varName] = [];
3787
+ }
3788
+ varToCallSigs[varName].push(callSig);
3789
+ }
3790
+ // Track how many times each variable name has been seen
3791
+ const varNameCounts = {};
3792
+ // For each receiving variable, get its original schema from perCallSignatureSchemas
3793
+ for (const varName of efc.receivingVariableNames ?? []) {
3794
+ const occurrence = varNameCounts[varName] ?? 0;
3795
+ varNameCounts[varName] = occurrence + 1;
3796
+ const callSigs = varToCallSigs[varName];
3797
+ // Use the nth call signature for the nth occurrence of this variable
3798
+ const callSig = callSigs?.[occurrence];
3799
+ if (callSig && efc.perCallSignatureSchemas[callSig]) {
3800
+ // Use indexed key if this variable name is reused (e.g., fetcher, fetcher[1])
3801
+ const key = occurrence === 0 ? varName : `${varName}[${occurrence}]`;
3802
+ // Clone the schema to avoid shared references
3803
+ perVariableSchemas[key] = {
3804
+ ...efc.perCallSignatureSchemas[callSig],
3805
+ };
3806
+ }
3807
+ }
3808
+ // Only include if we have entries for ALL receiving variables
3809
+ if (Object.keys(perVariableSchemas).length < numReceivingVars) {
3810
+ // Not all variables have schemas - fall back to rootSchema extraction
3811
+ perVariableSchemas = undefined;
3812
+ }
3813
+ else {
3814
+ // Also check that at least one schema is non-empty
3815
+ // Bug fix: perCallSignatureSchemas may have entries but with empty schemas {}
3816
+ // In this case, we should fall through to Fallback which uses rootSchema
3817
+ const hasNonEmptySchema = Object.values(perVariableSchemas).some((schema) => Object.keys(schema).length > 0);
3818
+ if (!hasNonEmptySchema) {
3819
+ perVariableSchemas = undefined;
3820
+ }
3821
+ }
3822
+ }
3823
+ // CASE 2: Single call signature with single variable - use perCallSignatureSchemas directly
3824
+ // This handles parameterized calls like useFetcher<ConfigData>() where each is a separate efc entry
3825
+ if (!perVariableSchemas &&
3826
+ efc.perCallSignatureSchemas &&
3827
+ numCallSignatures === 1 &&
3828
+ numReceivingVars === 1) {
3829
+ const varName = efc.receivingVariableNames[0];
3830
+ const callSig = Object.keys(efc.perCallSignatureSchemas)[0];
3831
+ const schema = efc.perCallSignatureSchemas[callSig];
3832
+ if (schema && Object.keys(schema).length > 0) {
3833
+ perVariableSchemas = { [varName]: { ...schema } };
3834
+ }
3835
+ }
3836
+ // CASE 3: Extract from efc.schema when perCallSignatureSchemas is missing or empty
3837
+ // This handles two scenarios:
3838
+ // 1. Parameterized calls that create SEPARATE efc entries (no perCallSignatureSchemas)
3839
+ // 2. Destructuring where perCallSignatureSchemas exists but has EMPTY schemas
3840
+ //
3841
+ // When useFetcher<ConfigData>() and useFetcher<SettingsData>() are called, they create separate
3842
+ // efc entries because getFunctionCallRoot preserves type parameters. Each entry has its own
3843
+ // `schema` field, but due to variable reassignment, the schema may be contaminated with paths
3844
+ // from other calls (the tracer attributes field accesses to ALL equivalencies).
3845
+ //
3846
+ // Solution: Filter efc.schema to only include paths that match THIS entry's call signature.
3847
+ // The schema paths include the full call signature prefix, so we can filter by it.
3848
+ //
3849
+ // Example: ConfigData entry has paths like:
3850
+ // "useFetcher<{ data: ConfigData | null }>().functionCallReturnValue.data.data.theme"
3851
+ // But also (contaminated):
3852
+ // "useFetcher<{ data: ConfigData | null }>().functionCallReturnValue.data.data.notifications"
3853
+ //
3854
+ // We filter to only keep paths that should belong to THIS call by checking if the
3855
+ // receiving variable's equivalency points to this call's return value.
3856
+ //
3857
+ // BUG FIX: The old condition `!efc.perCallSignatureSchemas` was FALSE when the object
3858
+ // existed (even with empty schemas), causing this case to be skipped. We now also check
3859
+ // if all schemas in perCallSignatureSchemas are empty.
3860
+ const hasNonEmptyPerCallSignatureSchemas = efc.perCallSignatureSchemas &&
3861
+ Object.values(efc.perCallSignatureSchemas).some((schema) => Object.keys(schema).length > 0);
3862
+ // Build the call signature prefix that paths should start with
3863
+ const callSigPrefix = `${efc.callSignature}.functionCallReturnValue`;
3864
+ // Check if efc.schema has variable-specific paths (indicating destructuring).
3865
+ // Destructuring: const { entities, gitStatus } = useLoaderData()
3866
+ // - efc.schema has paths like: useLoaderData().functionCallReturnValue.entities...
3867
+ // Multiple calls: const x = useFetcher(); const y = useFetcher();
3868
+ // - efc.schema has paths like: useFetcher().functionCallReturnValue.data...
3869
+ // CASE 3 should only run for destructuring (variable-specific paths exist).
3870
+ const hasVariableSpecificPaths = (efc.receivingVariableNames ?? []).some((varName) => Object.keys(efc.schema).some((path) => path.startsWith(`${callSigPrefix}.${varName}`)));
3871
+ if (!perVariableSchemas &&
3872
+ !hasNonEmptyPerCallSignatureSchemas &&
3873
+ numReceivingVars >= 1 &&
3874
+ hasVariableSpecificPaths) {
3875
+ // Filter efc.schema to only include paths matching this call signature
3876
+ const filteredSchema = {};
3877
+ for (const [path, type] of Object.entries(efc.schema)) {
3878
+ if (path.startsWith(callSigPrefix) || path === efc.callSignature) {
3879
+ filteredSchema[path] = type;
3880
+ }
3881
+ }
3882
+ // Build perVariableSchemas from the filtered schema
3883
+ // For destructuring, filter paths by variable name
3884
+ if (Object.keys(filteredSchema).length > 0) {
3885
+ perVariableSchemas = {};
3886
+ for (const varName of efc.receivingVariableNames ?? []) {
3887
+ // For destructuring, extract only paths specific to this variable
3888
+ const varSpecificPrefix = `${callSigPrefix}.${varName}`;
3889
+ const varSchema = {};
3890
+ for (const [path, type] of Object.entries(filteredSchema)) {
3891
+ if (path.startsWith(varSpecificPrefix)) {
3892
+ // Transform: useLoaderData().functionCallReturnValue.entities.sha
3893
+ // -> functionCallReturnValue.entities.sha (keep the variable name)
3894
+ const suffix = path.slice(callSigPrefix.length);
3895
+ const returnValuePath = `functionCallReturnValue${suffix}`;
3896
+ varSchema[returnValuePath] = type;
3897
+ }
3898
+ else if (path === efc.callSignature) {
3899
+ // Include the function call type itself
3900
+ varSchema[path] = type;
3901
+ }
3902
+ }
3903
+ if (Object.keys(varSchema).length > 0) {
3904
+ perVariableSchemas[varName] = varSchema;
3905
+ }
3906
+ }
3907
+ // Only include if we have entries
3908
+ if (Object.keys(perVariableSchemas).length === 0) {
3909
+ perVariableSchemas = undefined;
3910
+ }
3911
+ }
3912
+ }
3913
+ // Fallback: extract from root scope schema when perCallSignatureSchemas is not available
3914
+ // or doesn't have distinct entries for each variable.
3915
+ // This works when field accesses are in the root scope.
3916
+ if (!perVariableSchemas &&
3917
+ efc.receivingVariableNames &&
3918
+ efc.receivingVariableNames.length > 0) {
3919
+ perVariableSchemas = {};
3920
+ for (const varName of efc.receivingVariableNames) {
3921
+ const varSchema = {};
3922
+ for (const [path, type] of Object.entries(rootSchema)) {
3923
+ // Check if path starts with this variable name
3924
+ if (path === varName ||
3925
+ path.startsWith(varName + '.') ||
3926
+ path.startsWith(varName + '[')) {
3927
+ // Transform to functionCallReturnValue format
3928
+ // e.g., userFetcher.data.id -> functionCallReturnValue.data.id
3929
+ const suffix = path.slice(varName.length);
3930
+ const returnValuePath = `functionCallReturnValue${suffix}`;
3931
+ varSchema[returnValuePath] = type;
3932
+ }
3933
+ }
3934
+ if (Object.keys(varSchema).length > 0) {
3935
+ // Clean the variable name when using as key in output
3936
+ perVariableSchemas[cleanCyScope(varName)] = varSchema;
3937
+ }
3938
+ }
3939
+ // Only include if we have any entries
3940
+ if (Object.keys(perVariableSchemas).length === 0) {
3941
+ perVariableSchemas = undefined;
3942
+ }
3943
+ }
3944
+ // Enrich the schema with inferred types by applying fillInSchemaGapsAndUnknowns.
3945
+ // This ensures the serialized schema has the same type inference as getReturnValue().
3946
+ // Without this, evidence like "entities[].analyses: array" becomes "unknown".
3947
+ const enrichedSchema = { ...efc.schema };
3948
+ const tempScopeNode = {
3949
+ name: efc.name,
3950
+ schema: enrichedSchema,
3951
+ equivalencies: efc.equivalencies ?? {},
3952
+ };
3953
+ fillInSchemaGapsAndUnknowns(tempScopeNode, true);
3954
+ return {
3955
+ name: efc.name,
3956
+ callSignature: efc.callSignature,
3957
+ callScope: efc.callScope,
3958
+ schema: enrichedSchema,
3959
+ equivalencies: efc.equivalencies
3960
+ ? Object.entries(efc.equivalencies).reduce((acc, [key, vars]) => {
3961
+ // Clean cyScope from the key as well as variable properties
3962
+ acc[cleanCyScope(key)] = toSerializableVariable(vars);
3963
+ return acc;
3964
+ }, {})
3965
+ : undefined,
3966
+ allCallSignatures: efc.allCallSignatures,
3967
+ receivingVariableNames: efc.receivingVariableNames?.map(cleanCyScope),
3968
+ callSignatureToVariable: efc.callSignatureToVariable
3969
+ ? Object.fromEntries(Object.entries(efc.callSignatureToVariable).map(([k, v]) => [
3970
+ k,
3971
+ cleanCyScope(v),
3972
+ ]))
3973
+ : undefined,
3974
+ perVariableSchemas,
3975
+ };
3976
+ });
3977
+ // POST-PROCESSING: Deduplicate schemas across parameterized calls to same base function
3978
+ // When useFetcher<ConfigData>() and useFetcher<SettingsData>() are called, they create
3979
+ // separate entries. Due to variable reassignment, BOTH entries may have ALL fields.
3980
+ // We deduplicate by assigning each field to ONLY ONE entry based on order of appearance.
3981
+ //
3982
+ // Strategy: Fields that appear first in order belong to the first entry,
3983
+ // fields that appear later belong to later entries (split evenly).
3984
+ const deduplicateParameterizedEntries = (entries) => {
3985
+ // Group entries by base function name (without type parameters)
3986
+ const groups = new Map();
3987
+ for (const entry of entries) {
3988
+ // Extract base function name by stripping type parameters
3989
+ // e.g., "useFetcher<{ data: ConfigData | null }>" -> "useFetcher"
3990
+ const baseName = entry.name.replace(/<.*>$/, '');
3991
+ const group = groups.get(baseName) || [];
3992
+ group.push(entry);
3993
+ groups.set(baseName, group);
3994
+ }
3995
+ // Process groups with multiple parameterized entries
3996
+ for (const [, group] of groups) {
3997
+ if (group.length <= 1)
3998
+ continue;
3999
+ // Check if these are parameterized calls (have type parameters in name)
4000
+ const hasTypeParams = group.every((e) => e.name.includes('<'));
4001
+ if (!hasTypeParams)
4002
+ continue;
4003
+ // Collect ALL unique field suffixes across all entries (in order of first appearance)
4004
+ // Field suffix is the path after functionCallReturnValue, e.g., ".data.data.theme"
4005
+ const allFieldSuffixes = [];
4006
+ for (const entry of group) {
4007
+ if (!entry.perVariableSchemas)
4008
+ continue;
4009
+ for (const varSchema of Object.values(entry.perVariableSchemas)) {
4010
+ for (const path of Object.keys(varSchema)) {
4011
+ // Skip the base "functionCallReturnValue" entry
4012
+ if (path === 'functionCallReturnValue')
4013
+ continue;
4014
+ // Extract field suffix
4015
+ const match = path.match(/functionCallReturnValue(.+)/);
4016
+ if (!match)
4017
+ continue;
4018
+ const fieldSuffix = match[1];
4019
+ if (!allFieldSuffixes.includes(fieldSuffix)) {
4020
+ allFieldSuffixes.push(fieldSuffix);
4021
+ }
4022
+ }
4023
+ }
4024
+ }
4025
+ // Assign fields to entries: split evenly based on order
4026
+ // First N/2 fields go to first entry, remaining go to second entry
4027
+ const fieldToEntryMap = new Map();
4028
+ const fieldsPerEntry = Math.ceil(allFieldSuffixes.length / group.length);
4029
+ for (let i = 0; i < allFieldSuffixes.length; i++) {
4030
+ const fieldSuffix = allFieldSuffixes[i];
4031
+ const entryIdx = Math.min(Math.floor(i / fieldsPerEntry), group.length - 1);
4032
+ fieldToEntryMap.set(fieldSuffix, entryIdx);
4033
+ }
4034
+ // Filter each entry's perVariableSchemas to only include its assigned fields
4035
+ for (let i = 0; i < group.length; i++) {
4036
+ const entry = group[i];
4037
+ if (!entry.perVariableSchemas)
4038
+ continue;
4039
+ const filteredPerVarSchemas = {};
4040
+ for (const [varName, varSchema] of Object.entries(entry.perVariableSchemas)) {
4041
+ const filteredVarSchema = {};
4042
+ for (const [path, type] of Object.entries(varSchema)) {
4043
+ // Always keep the base functionCallReturnValue
4044
+ if (path === 'functionCallReturnValue') {
4045
+ filteredVarSchema[path] = type;
4046
+ continue;
4047
+ }
4048
+ // Extract field suffix
4049
+ const match = path.match(/functionCallReturnValue(.+)/);
4050
+ if (!match) {
4051
+ // Keep non-field paths
4052
+ filteredVarSchema[path] = type;
4053
+ continue;
4054
+ }
4055
+ const fieldSuffix = match[1];
4056
+ // Only include if this entry owns this field
4057
+ if (fieldToEntryMap.get(fieldSuffix) === i) {
4058
+ filteredVarSchema[path] = type;
4059
+ }
4060
+ }
4061
+ if (Object.keys(filteredVarSchema).length > 0) {
4062
+ filteredPerVarSchemas[varName] = filteredVarSchema;
4063
+ }
4064
+ }
4065
+ entry.perVariableSchemas =
4066
+ Object.keys(filteredPerVarSchemas).length > 0
4067
+ ? filteredPerVarSchemas
4068
+ : undefined;
4069
+ }
4070
+ }
4071
+ return entries;
4072
+ };
4073
+ // Apply deduplication
4074
+ const deduplicatedExternalFunctionCalls = deduplicateParameterizedEntries(externalFunctionCalls);
4075
+ // IMPORTANT: Get equivalent signature variables BEFORE calling getFunctionResult
4076
+ // because getFunctionResult calls validateSchema which may remove equivalencies
4077
+ // during the finalize step (e.g., cleanNonObjectFunctions removes method call
4078
+ // equivalencies like `segments -> splat.split('/').functionCallReturnValue`).
4079
+ // Fix 33: Move this call before any schema validation to preserve method call chains.
4080
+ const equivalentSignatureVariables = this.getEquivalentSignatureVariables();
2500
4081
  // Get root function result
2501
4082
  const rootFunction = getFunctionResult();
2502
- // Get results for each external function
4083
+ // Get results for each external function (use cleaned calls for consistency)
2503
4084
  const functionResults = {};
2504
- for (const efc of this.externalFunctionCalls) {
4085
+ for (const efc of cleanedExternalCalls) {
2505
4086
  functionResults[efc.name] = getFunctionResult(efc.name);
2506
4087
  }
2507
- // Get equivalent signature variables
2508
- const equivalentSignatureVariables = this.getEquivalentSignatureVariables();
2509
4088
  const environmentVariables = this.getEnvironmentVariables();
2510
4089
  // Get enriched conditional usages with source tracing
2511
4090
  const enrichedConditionalUsages = this.getEnrichedConditionalUsages();
2512
4091
  const conditionalUsages = Object.keys(enrichedConditionalUsages).length > 0
2513
4092
  ? enrichedConditionalUsages
2514
4093
  : undefined;
4094
+ // Get conditional effects (setter calls inside conditionals)
4095
+ const conditionalEffects = this.rawConditionalEffects.length > 0
4096
+ ? this.rawConditionalEffects
4097
+ : undefined;
4098
+ // Get compound conditionals (grouped conditions that must all be true)
4099
+ const compoundConditionals = this.rawCompoundConditionals.length > 0
4100
+ ? this.rawCompoundConditionals
4101
+ : undefined;
4102
+ // Get child boundary gating conditions
4103
+ const enrichedGatingConditions = this.getEnrichedChildBoundaryGatingConditions();
4104
+ const childBoundaryGatingConditions = Object.keys(enrichedGatingConditions).length > 0
4105
+ ? enrichedGatingConditions
4106
+ : undefined;
4107
+ // Get JSX rendering usages (arrays via .map(), strings via interpolation)
4108
+ const jsxRenderingUsages = this.rawJsxRenderingUsages.length > 0
4109
+ ? this.rawJsxRenderingUsages
4110
+ : undefined;
2515
4111
  return {
2516
- externalFunctionCalls,
4112
+ externalFunctionCalls: deduplicatedExternalFunctionCalls,
2517
4113
  rootFunction,
2518
4114
  functionResults,
2519
4115
  equivalentSignatureVariables,
2520
4116
  environmentVariables,
2521
4117
  conditionalUsages,
4118
+ conditionalEffects,
4119
+ compoundConditionals,
4120
+ childBoundaryGatingConditions,
4121
+ jsxRenderingUsages,
2522
4122
  };
2523
4123
  }
2524
4124
  // ═══════════════════════════════════════════════════════════════════════════