@codeyam/codeyam-cli 0.1.0-staging.323686 → 0.1.0-staging.415103

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 (683) hide show
  1. package/analyzer-template/.build-info.json +7 -7
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/package.json +18 -18
  4. package/analyzer-template/packages/ai/index.ts +7 -1
  5. package/analyzer-template/packages/ai/package.json +3 -3
  6. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +62 -18
  7. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +101 -12
  8. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  9. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +409 -50
  10. package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
  11. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +21 -6
  12. package/analyzer-template/packages/ai/src/lib/completionCall.ts +114 -113
  13. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +1250 -253
  14. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
  15. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +16 -3
  16. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +6 -4
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +31 -3
  18. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +37 -15
  19. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
  20. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.ts +62 -0
  21. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +140 -14
  22. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +179 -0
  23. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.ts +40 -30
  24. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +367 -96
  25. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.ts +35 -0
  26. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +40 -13
  27. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
  28. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +393 -8
  29. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +9 -5
  30. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +145 -5
  31. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
  32. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +649 -142
  33. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +1 -1
  34. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
  35. package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
  36. package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
  37. package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
  38. package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
  39. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
  40. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +25 -13
  41. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +4 -3
  42. package/analyzer-template/packages/analyze/index.ts +2 -0
  43. package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +65 -59
  44. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +119 -26
  45. package/analyzer-template/packages/analyze/src/lib/asts/nodes/getNodeType.ts +1 -0
  46. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
  47. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
  48. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
  49. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
  50. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
  51. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
  52. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +89 -9
  53. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +27 -4
  54. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +0 -6
  55. package/analyzer-template/packages/analyze/src/lib/files/analyze/findOrCreateEntity.ts +12 -0
  56. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
  57. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +0 -3
  58. package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
  59. package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
  60. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1352 -0
  61. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +61 -13
  62. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +87 -25
  63. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +312 -19
  64. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +117 -9
  65. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +591 -75
  66. package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
  67. package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
  68. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  69. package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
  70. package/analyzer-template/packages/aws/package.json +10 -10
  71. package/analyzer-template/packages/database/index.ts +1 -0
  72. package/analyzer-template/packages/database/package.json +1 -1
  73. package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
  74. package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
  75. package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
  76. package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
  77. package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
  78. package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
  79. package/analyzer-template/packages/database/src/lib/kysely/db.ts +14 -0
  80. package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +1 -1
  81. package/analyzer-template/packages/database/src/lib/kysely/tables/editorScenariosTable.ts +62 -0
  82. package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
  83. package/analyzer-template/packages/database/src/lib/loadCommits.ts +31 -20
  84. package/analyzer-template/packages/database/src/lib/loadReadyToBeCapturedAnalyses.ts +0 -5
  85. package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
  86. package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
  87. package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
  88. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +151 -135
  89. package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatus.ts +58 -42
  90. package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.ts +81 -65
  91. package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
  92. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.ts +29 -1
  93. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.ts +33 -5
  94. package/analyzer-template/packages/github/dist/database/index.d.ts +1 -0
  95. package/analyzer-template/packages/github/dist/database/index.d.ts.map +1 -1
  96. package/analyzer-template/packages/github/dist/database/index.js +1 -0
  97. package/analyzer-template/packages/github/dist/database/index.js.map +1 -1
  98. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
  99. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
  100. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
  101. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
  102. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
  103. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
  104. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
  105. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
  106. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
  107. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
  108. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
  109. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
  110. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +4 -0
  111. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  112. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +8 -0
  113. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  114. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +1 -1
  115. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts +20 -0
  116. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts.map +1 -0
  117. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js +45 -0
  118. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
  119. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
  120. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
  121. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  122. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  123. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts +5 -0
  124. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts.map +1 -1
  125. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  126. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +23 -13
  127. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  128. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.d.ts.map +1 -1
  129. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
  130. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  131. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
  132. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
  133. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
  134. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
  135. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
  136. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
  137. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  138. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +100 -89
  139. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  140. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.d.ts.map +1 -1
  141. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js +41 -30
  142. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
  143. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.d.ts.map +1 -1
  144. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
  145. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
  146. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.d.ts.map +1 -1
  147. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
  148. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
  149. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.d.ts.map +1 -1
  150. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
  151. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  152. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +8 -0
  153. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  154. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts +10 -0
  155. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts.map +1 -1
  156. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  157. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  158. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  159. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  160. package/analyzer-template/packages/github/package.json +1 -1
  161. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +8 -0
  162. package/analyzer-template/packages/types/src/types/Scenario.ts +10 -0
  163. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +6 -5
  164. package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
  165. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +8 -0
  166. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  167. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts +10 -0
  168. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts.map +1 -1
  169. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  170. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  171. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  172. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  173. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
  174. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +98 -3
  175. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  176. package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +121 -3
  177. package/analyzer-template/playwright/captureFromUrl.ts +89 -82
  178. package/analyzer-template/project/constructMockCode.ts +260 -60
  179. package/analyzer-template/project/orchestrateCapture.ts +4 -1
  180. package/analyzer-template/project/reconcileMockDataKeys.ts +19 -14
  181. package/analyzer-template/project/start.ts +3 -0
  182. package/analyzer-template/project/startScenarioCapture.ts +9 -0
  183. package/analyzer-template/project/writeClientLogRoute.ts +125 -0
  184. package/analyzer-template/project/writeMockDataTsx.ts +198 -8
  185. package/analyzer-template/project/writeScenarioComponents.ts +170 -29
  186. package/analyzer-template/project/writeSimpleRoot.ts +21 -11
  187. package/analyzer-template/tsconfig.json +13 -1
  188. package/background/src/lib/local/createLocalAnalyzer.js +1 -1
  189. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  190. package/background/src/lib/virtualized/project/constructMockCode.js +220 -45
  191. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  192. package/background/src/lib/virtualized/project/orchestrateCapture.js +4 -1
  193. package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
  194. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +17 -11
  195. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
  196. package/background/src/lib/virtualized/project/start.js +2 -0
  197. package/background/src/lib/virtualized/project/start.js.map +1 -1
  198. package/background/src/lib/virtualized/project/startScenarioCapture.js +5 -0
  199. package/background/src/lib/virtualized/project/startScenarioCapture.js.map +1 -1
  200. package/background/src/lib/virtualized/project/writeClientLogRoute.js +110 -0
  201. package/background/src/lib/virtualized/project/writeClientLogRoute.js.map +1 -0
  202. package/background/src/lib/virtualized/project/writeMockDataTsx.js +174 -4
  203. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  204. package/background/src/lib/virtualized/project/writeScenarioComponents.js +143 -27
  205. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  206. package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
  207. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  208. package/codeyam-cli/scripts/apply-setup.js +386 -9
  209. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  210. package/codeyam-cli/src/cli.js +33 -24
  211. package/codeyam-cli/src/cli.js.map +1 -1
  212. package/codeyam-cli/src/codeyam-cli.js +18 -2
  213. package/codeyam-cli/src/codeyam-cli.js.map +1 -1
  214. package/codeyam-cli/src/commands/analyze.js +21 -9
  215. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  216. package/codeyam-cli/src/commands/baseline.js +2 -0
  217. package/codeyam-cli/src/commands/baseline.js.map +1 -1
  218. package/codeyam-cli/src/commands/debug.js +9 -5
  219. package/codeyam-cli/src/commands/debug.js.map +1 -1
  220. package/codeyam-cli/src/commands/default.js +87 -21
  221. package/codeyam-cli/src/commands/default.js.map +1 -1
  222. package/codeyam-cli/src/commands/editor.js +696 -0
  223. package/codeyam-cli/src/commands/editor.js.map +1 -0
  224. package/codeyam-cli/src/commands/init.js +75 -259
  225. package/codeyam-cli/src/commands/init.js.map +1 -1
  226. package/codeyam-cli/src/commands/memory.js +97 -92
  227. package/codeyam-cli/src/commands/memory.js.map +1 -1
  228. package/codeyam-cli/src/commands/recapture.js +2 -0
  229. package/codeyam-cli/src/commands/recapture.js.map +1 -1
  230. package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
  231. package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
  232. package/codeyam-cli/src/commands/setup-simulations.js +284 -0
  233. package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
  234. package/codeyam-cli/src/commands/test-startup.js +2 -0
  235. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  236. package/codeyam-cli/src/commands/verify.js +14 -2
  237. package/codeyam-cli/src/commands/verify.js.map +1 -1
  238. package/codeyam-cli/src/utils/__tests__/npmVersionCheck.test.js +185 -0
  239. package/codeyam-cli/src/utils/__tests__/npmVersionCheck.test.js.map +1 -0
  240. package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js +9 -0
  241. package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js.map +1 -1
  242. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +154 -86
  243. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  244. package/codeyam-cli/src/utils/analyzer.js +7 -0
  245. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  246. package/codeyam-cli/src/utils/backgroundServer.js +109 -22
  247. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  248. package/codeyam-cli/src/utils/devModeEvents.js +40 -0
  249. package/codeyam-cli/src/utils/devModeEvents.js.map +1 -0
  250. package/codeyam-cli/src/utils/fileMetadata.js +5 -0
  251. package/codeyam-cli/src/utils/fileMetadata.js.map +1 -1
  252. package/codeyam-cli/src/utils/fileWatcher.js +25 -9
  253. package/codeyam-cli/src/utils/fileWatcher.js.map +1 -1
  254. package/codeyam-cli/src/utils/generateReport.js +2 -2
  255. package/codeyam-cli/src/utils/git.js +52 -0
  256. package/codeyam-cli/src/utils/git.js.map +1 -1
  257. package/codeyam-cli/src/utils/install-skills.js +101 -45
  258. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  259. package/codeyam-cli/src/utils/interactiveSyncWatcher.js +126 -0
  260. package/codeyam-cli/src/utils/interactiveSyncWatcher.js.map +1 -0
  261. package/codeyam-cli/src/utils/labsAutoCheck.js +19 -0
  262. package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
  263. package/codeyam-cli/src/utils/npmVersionCheck.js +76 -0
  264. package/codeyam-cli/src/utils/npmVersionCheck.js.map +1 -0
  265. package/codeyam-cli/src/utils/pathIgnoring.js +19 -7
  266. package/codeyam-cli/src/utils/pathIgnoring.js.map +1 -1
  267. package/codeyam-cli/src/utils/progress.js +7 -0
  268. package/codeyam-cli/src/utils/progress.js.map +1 -1
  269. package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js +11 -11
  270. package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js.map +1 -1
  271. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js +22 -0
  272. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js.map +1 -1
  273. package/codeyam-cli/src/utils/queue/heartbeat.js +13 -5
  274. package/codeyam-cli/src/utils/queue/heartbeat.js.map +1 -1
  275. package/codeyam-cli/src/utils/queue/job.js +74 -1
  276. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  277. package/codeyam-cli/src/utils/queue/manager.js +7 -6
  278. package/codeyam-cli/src/utils/queue/manager.js.map +1 -1
  279. package/codeyam-cli/src/utils/requireSimulations.js +10 -0
  280. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
  281. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  282. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  283. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +229 -0
  284. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  285. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  286. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  287. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  288. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  289. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  290. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  291. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  292. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  293. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +74 -0
  294. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  295. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +376 -0
  296. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  297. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +113 -0
  298. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  299. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  300. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  301. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  302. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  303. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
  304. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  305. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  306. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  307. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
  308. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  309. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  310. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  311. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  312. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  313. package/codeyam-cli/src/utils/rules/__tests__/parser.test.js +83 -0
  314. package/codeyam-cli/src/utils/rules/__tests__/parser.test.js.map +1 -0
  315. package/codeyam-cli/src/utils/rules/__tests__/pathMatcher.test.js +118 -0
  316. package/codeyam-cli/src/utils/rules/__tests__/pathMatcher.test.js.map +1 -0
  317. package/codeyam-cli/src/utils/rules/__tests__/rulePlacement.test.js +72 -0
  318. package/codeyam-cli/src/utils/rules/__tests__/rulePlacement.test.js.map +1 -0
  319. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  320. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  321. package/codeyam-cli/src/utils/rules/__tests__/sourceFiles.test.js +76 -0
  322. package/codeyam-cli/src/utils/rules/__tests__/sourceFiles.test.js.map +1 -0
  323. package/codeyam-cli/src/utils/rules/index.js +2 -0
  324. package/codeyam-cli/src/utils/rules/index.js.map +1 -1
  325. package/codeyam-cli/src/utils/rules/parser.js +16 -29
  326. package/codeyam-cli/src/utils/rules/parser.js.map +1 -1
  327. package/codeyam-cli/src/utils/rules/pathMatcher.js +34 -3
  328. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -1
  329. package/codeyam-cli/src/utils/rules/rulePlacement.js +65 -0
  330. package/codeyam-cli/src/utils/rules/rulePlacement.js.map +1 -0
  331. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  332. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  333. package/codeyam-cli/src/utils/rules/sourceFiles.js +43 -0
  334. package/codeyam-cli/src/utils/rules/sourceFiles.js.map +1 -0
  335. package/codeyam-cli/src/utils/rules/staleness.js +16 -11
  336. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -1
  337. package/codeyam-cli/src/utils/serverState.js +64 -12
  338. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  339. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +61 -43
  340. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  341. package/codeyam-cli/src/utils/simulationGateMiddleware.js +159 -0
  342. package/codeyam-cli/src/utils/simulationGateMiddleware.js.map +1 -0
  343. package/codeyam-cli/src/utils/syncMocksMiddleware.js +5 -24
  344. package/codeyam-cli/src/utils/syncMocksMiddleware.js.map +1 -1
  345. package/codeyam-cli/src/utils/testRunner.js +158 -0
  346. package/codeyam-cli/src/utils/testRunner.js.map +1 -0
  347. package/codeyam-cli/src/utils/transcriptPruning.js +67 -0
  348. package/codeyam-cli/src/utils/transcriptPruning.js.map +1 -0
  349. package/codeyam-cli/src/utils/versionInfo.js +46 -0
  350. package/codeyam-cli/src/utils/versionInfo.js.map +1 -1
  351. package/codeyam-cli/src/utils/webappDetection.js +14 -2
  352. package/codeyam-cli/src/utils/webappDetection.js.map +1 -1
  353. package/codeyam-cli/src/webserver/__tests__/dependency-smoke.test.js +66 -0
  354. package/codeyam-cli/src/webserver/__tests__/dependency-smoke.test.js.map +1 -0
  355. package/codeyam-cli/src/webserver/app/lib/database.js +15 -3
  356. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  357. package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
  358. package/codeyam-cli/src/webserver/backgroundServer.js +166 -16
  359. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  360. package/codeyam-cli/src/webserver/bootstrap.js +11 -0
  361. package/codeyam-cli/src/webserver/bootstrap.js.map +1 -1
  362. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-DmJveP3T.js +1 -0
  363. package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-DsN1wKrm.js → EntityItem-C76mRRiF.js} +1 -1
  364. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-g3saevPb.js} +1 -1
  365. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-CobE682z.js} +1 -1
  366. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-Bu6c6aDe.js +1 -0
  367. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-DYFW3lDD.js} +3 -3
  368. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-DLeucoVX.js} +1 -1
  369. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-BU_OAEMP.js} +1 -1
  370. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-ceAyBX-H.js} +1 -1
  371. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-OApQuNyq.js → ReportIssueModal-djPLI-WV.js} +3 -8
  372. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-BED4B6sP.js} +1 -1
  373. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DzccYyI8.js → ScenarioViewer-B76aig_2.js} +2 -2
  374. package/codeyam-cli/src/webserver/build/client/assets/Spinner-Bb5uFQ5V.js +34 -0
  375. package/codeyam-cli/src/webserver/build/client/assets/Terminal-BaIiqg_w.js +41 -0
  376. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-C8OKAR5x.js} +1 -1
  377. package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-C96V0n15.js} +1 -1
  378. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BwavGCpm.js → activity.(_tab)-BpKzcsJz.js} +6 -11
  379. package/codeyam-cli/src/webserver/build/client/assets/addon-fit-CUXOrorO.js +1 -0
  380. package/codeyam-cli/src/webserver/build/client/assets/addon-web-links-Duc5hnl7.js +1 -0
  381. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-D9hemwl6.js +22 -0
  382. package/codeyam-cli/src/webserver/build/client/assets/api.agent-transcripts-l0sNRNKZ.js +1 -0
  383. package/codeyam-cli/src/webserver/build/client/assets/api.dev-mode-events-l0sNRNKZ.js +1 -0
  384. package/codeyam-cli/src/webserver/build/client/assets/api.editor-capture-scenario-l0sNRNKZ.js +1 -0
  385. package/codeyam-cli/src/webserver/build/client/assets/api.editor-client-errors-l0sNRNKZ.js +1 -0
  386. package/codeyam-cli/src/webserver/build/client/assets/api.editor-commit-l0sNRNKZ.js +1 -0
  387. package/codeyam-cli/src/webserver/build/client/assets/api.editor-dev-server-l0sNRNKZ.js +1 -0
  388. package/codeyam-cli/src/webserver/build/client/assets/api.editor-entity-status-l0sNRNKZ.js +1 -0
  389. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-entry-l0sNRNKZ.js +1 -0
  390. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-image._-l0sNRNKZ.js +1 -0
  391. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-l0sNRNKZ.js +1 -0
  392. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-screenshot-l0sNRNKZ.js +1 -0
  393. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-update-l0sNRNKZ.js +1 -0
  394. package/codeyam-cli/src/webserver/build/client/assets/api.editor-refresh-l0sNRNKZ.js +1 -0
  395. package/codeyam-cli/src/webserver/build/client/assets/api.editor-register-scenario-l0sNRNKZ.js +1 -0
  396. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-data-l0sNRNKZ.js +1 -0
  397. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-image._-l0sNRNKZ.js +1 -0
  398. package/codeyam-cli/src/webserver/build/client/assets/api.editor-switch-scenario-l0sNRNKZ.js +1 -0
  399. package/codeyam-cli/src/webserver/build/client/assets/api.editor-test-results-l0sNRNKZ.js +1 -0
  400. package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
  401. package/codeyam-cli/src/webserver/build/client/assets/api.rule-path-l0sNRNKZ.js +1 -0
  402. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  403. package/codeyam-cli/src/webserver/build/client/assets/book-open-D_nMCFmP.js +6 -0
  404. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-BH2h1Ea2.js} +1 -1
  405. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-C4pqxYJB.js} +12 -12
  406. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-DyIKORY6.js} +1 -1
  407. package/codeyam-cli/src/webserver/build/client/assets/copy-NDbZjXao.js +11 -0
  408. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-CMT1jU2q.js} +1 -1
  409. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BiM6z3Do.js +1 -0
  410. package/codeyam-cli/src/webserver/build/client/assets/editor-BaC8lHDG.js +7 -0
  411. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-BJUiQqZF.js → entity._sha._-CrjR3zZW.js} +11 -11
  412. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-DloHYjtt.js +6 -0
  413. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-C28BiQzt.js +6 -0
  414. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-p9hhkjJM.js +6 -0
  415. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-BMvVHNXU.js} +2 -2
  416. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-DTvKq3TY.js} +1 -1
  417. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-cPo8LiG3.js} +1 -1
  418. package/codeyam-cli/src/webserver/build/client/assets/{files-CJ6lTdTA.js → files-DO4CZ16O.js} +1 -1
  419. package/codeyam-cli/src/webserver/build/client/assets/{git-CPTZZ-JZ.js → git-CFCTYk9I.js} +1 -1
  420. package/codeyam-cli/src/webserver/build/client/assets/globals-BH6uYxPM.css +1 -0
  421. package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-10oVnAAH.js} +1 -1
  422. package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-BcvgDzbZ.js} +1 -1
  423. package/codeyam-cli/src/webserver/build/client/assets/labs-Zk7ryIM1.js +1 -0
  424. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-BAXYRVEO.js} +1 -1
  425. package/codeyam-cli/src/webserver/build/client/assets/manifest-fb3128c3.js +1 -0
  426. package/codeyam-cli/src/webserver/build/client/assets/memory-FweZHj5U.js +93 -0
  427. package/codeyam-cli/src/webserver/build/client/assets/pause-DTAcYxBt.js +11 -0
  428. package/codeyam-cli/src/webserver/build/client/assets/root-Dzn8nIkU.js +67 -0
  429. package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-fKo7v0Zo.js} +1 -1
  430. package/codeyam-cli/src/webserver/build/client/assets/settings-DfuTtcJP.js +1 -0
  431. package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-B3aOzpCZ.js} +1 -1
  432. package/codeyam-cli/src/webserver/build/client/assets/terminal-BG4heKCG.js +11 -0
  433. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-DtSmdtM4.js} +1 -1
  434. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-ByhSyh0W.js} +1 -1
  435. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-C14nCb1q.js +2 -0
  436. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-O-jkvSPx.js} +1 -1
  437. package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-9FIWuYfK.js} +1 -1
  438. package/codeyam-cli/src/webserver/build/client/assets/xterm-DMSzMhqy.js +9 -0
  439. package/codeyam-cli/src/webserver/build/server/assets/index-DeSuKbSF.js +1 -0
  440. package/codeyam-cli/src/webserver/build/server/assets/server-build-BbQ8YBP-.js +362 -0
  441. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  442. package/codeyam-cli/src/webserver/build-info.json +5 -5
  443. package/codeyam-cli/src/webserver/devServer.js +39 -5
  444. package/codeyam-cli/src/webserver/devServer.js.map +1 -1
  445. package/codeyam-cli/src/webserver/editorProxy.js +272 -0
  446. package/codeyam-cli/src/webserver/editorProxy.js.map +1 -0
  447. package/codeyam-cli/src/webserver/scripts/journalCapture.ts +121 -0
  448. package/codeyam-cli/src/webserver/server.js +177 -1
  449. package/codeyam-cli/src/webserver/server.js.map +1 -1
  450. package/codeyam-cli/src/webserver/terminalServer.js +606 -0
  451. package/codeyam-cli/src/webserver/terminalServer.js.map +1 -0
  452. package/codeyam-cli/templates/{codeyam:debug.md → codeyam-debug.md} +1 -1
  453. package/codeyam-cli/templates/codeyam-dev-mode.md +237 -0
  454. package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
  455. package/codeyam-cli/templates/codeyam-editor-claude.md +68 -0
  456. package/codeyam-cli/templates/codeyam-editor.md +67 -0
  457. package/codeyam-cli/templates/codeyam-memory-hook.sh +19 -20
  458. package/codeyam-cli/templates/codeyam-memory.md +396 -0
  459. package/codeyam-cli/templates/codeyam-new-rule.md +11 -0
  460. package/codeyam-cli/templates/{codeyam:setup.md → codeyam-setup.md} +13 -1
  461. package/codeyam-cli/templates/{codeyam:sim.md → codeyam-sim.md} +1 -1
  462. package/codeyam-cli/templates/{codeyam:test.md → codeyam-test.md} +1 -1
  463. package/codeyam-cli/templates/{codeyam:verify.md → codeyam-verify.md} +1 -1
  464. package/codeyam-cli/templates/editor-step-hook.py +143 -0
  465. package/codeyam-cli/templates/hooks/staleness-check.sh +43 -0
  466. package/codeyam-cli/templates/isolation-route/next-app.tsx.template +80 -0
  467. package/codeyam-cli/templates/isolation-route/next-pages.tsx.template +79 -0
  468. package/codeyam-cli/templates/isolation-route/vite-react.tsx.template +78 -0
  469. package/codeyam-cli/templates/msw/browser-setup.ts.template +47 -0
  470. package/codeyam-cli/templates/msw/handler-router.ts.template +47 -0
  471. package/codeyam-cli/templates/msw/server-setup.ts.template +52 -0
  472. package/codeyam-cli/templates/nextjs-prisma-sqlite/PRISMA_SETUP.md +84 -0
  473. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/api/todos/route.ts +17 -0
  474. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/globals.css +26 -0
  475. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/layout.tsx +34 -0
  476. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/lib/prisma.ts +19 -0
  477. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/page.tsx +10 -0
  478. package/codeyam-cli/templates/nextjs-prisma-sqlite/eslint.config.mjs +11 -0
  479. package/codeyam-cli/templates/nextjs-prisma-sqlite/next.config.ts +14 -0
  480. package/codeyam-cli/templates/nextjs-prisma-sqlite/package.json +35 -0
  481. package/codeyam-cli/templates/nextjs-prisma-sqlite/postcss.config.mjs +7 -0
  482. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/schema.prisma +27 -0
  483. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/seed.ts +37 -0
  484. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma.config.ts +12 -0
  485. package/codeyam-cli/templates/nextjs-prisma-sqlite/tsconfig.json +34 -0
  486. package/codeyam-cli/templates/prompts/conversation-guidance.txt +44 -0
  487. package/codeyam-cli/templates/prompts/conversation-prompt.txt +28 -0
  488. package/codeyam-cli/templates/prompts/interruption-prompt.txt +31 -0
  489. package/codeyam-cli/templates/prompts/stale-rules-prompt.txt +24 -0
  490. package/codeyam-cli/templates/rule-notification-hook.py +83 -0
  491. package/codeyam-cli/templates/rule-reflection-hook.py +647 -0
  492. package/codeyam-cli/templates/rules-instructions.md +78 -0
  493. package/package.json +16 -14
  494. package/packages/ai/index.js +3 -2
  495. package/packages/ai/index.js.map +1 -1
  496. package/packages/ai/src/lib/analyzeScope.js +50 -13
  497. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  498. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +76 -12
  499. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  500. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  501. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  502. package/packages/ai/src/lib/astScopes/processExpression.js +317 -44
  503. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  504. package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
  505. package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
  506. package/packages/ai/src/lib/completionCall.js +10 -7
  507. package/packages/ai/src/lib/completionCall.js.map +1 -1
  508. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +996 -173
  509. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  510. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
  511. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  512. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
  513. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
  514. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
  515. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
  516. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +33 -3
  517. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  518. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +36 -11
  519. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  520. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  521. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  522. package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js +54 -0
  523. package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js.map +1 -0
  524. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +122 -12
  525. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  526. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
  527. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
  528. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
  529. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
  530. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +309 -84
  531. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  532. package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js +34 -0
  533. package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js.map +1 -0
  534. package/packages/ai/src/lib/dataStructureChunking.js +30 -11
  535. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  536. package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
  537. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  538. package/packages/ai/src/lib/generateEntityScenarioData.js +284 -6
  539. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  540. package/packages/ai/src/lib/generateEntityScenarios.js +7 -1
  541. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  542. package/packages/ai/src/lib/generateExecutionFlows.js +107 -4
  543. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  544. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +447 -80
  545. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  546. package/packages/ai/src/lib/isolateScopes.js +39 -3
  547. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  548. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
  549. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
  550. package/packages/ai/src/lib/mergeStatements.js +70 -51
  551. package/packages/ai/src/lib/mergeStatements.js.map +1 -1
  552. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
  553. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
  554. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +10 -4
  555. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
  556. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
  557. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  558. package/packages/ai/src/lib/resolvePathToControllable.js +24 -14
  559. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
  560. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  561. package/packages/analyze/index.js +1 -0
  562. package/packages/analyze/index.js.map +1 -1
  563. package/packages/analyze/src/lib/FileAnalyzer.js +60 -36
  564. package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
  565. package/packages/analyze/src/lib/ProjectAnalyzer.js +99 -26
  566. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  567. package/packages/analyze/src/lib/asts/nodes/getNodeType.js +1 -0
  568. package/packages/analyze/src/lib/asts/nodes/getNodeType.js.map +1 -1
  569. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
  570. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
  571. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
  572. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
  573. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
  574. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
  575. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
  576. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
  577. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
  578. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
  579. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
  580. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
  581. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +65 -7
  582. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  583. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +24 -4
  584. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  585. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +0 -5
  586. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  587. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js +9 -0
  588. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js.map +1 -1
  589. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
  590. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  591. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +0 -3
  592. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  593. package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
  594. package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
  595. package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
  596. package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
  597. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +907 -0
  598. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  599. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +56 -10
  600. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  601. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +75 -21
  602. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  603. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +215 -17
  604. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  605. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +56 -8
  606. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  607. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +494 -56
  608. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  609. package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
  610. package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
  611. package/packages/analyze/src/lib/index.js +1 -0
  612. package/packages/analyze/src/lib/index.js.map +1 -1
  613. package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
  614. package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
  615. package/packages/database/index.js +1 -0
  616. package/packages/database/index.js.map +1 -1
  617. package/packages/database/src/lib/analysisBranchToDb.js +1 -1
  618. package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
  619. package/packages/database/src/lib/analysisToDb.js +1 -1
  620. package/packages/database/src/lib/analysisToDb.js.map +1 -1
  621. package/packages/database/src/lib/branchToDb.js +1 -1
  622. package/packages/database/src/lib/branchToDb.js.map +1 -1
  623. package/packages/database/src/lib/commitBranchToDb.js +1 -1
  624. package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
  625. package/packages/database/src/lib/commitToDb.js +1 -1
  626. package/packages/database/src/lib/commitToDb.js.map +1 -1
  627. package/packages/database/src/lib/fileToDb.js +1 -1
  628. package/packages/database/src/lib/fileToDb.js.map +1 -1
  629. package/packages/database/src/lib/kysely/db.js +8 -0
  630. package/packages/database/src/lib/kysely/db.js.map +1 -1
  631. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js +45 -0
  632. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
  633. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  634. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  635. package/packages/database/src/lib/loadCommits.js +23 -13
  636. package/packages/database/src/lib/loadCommits.js.map +1 -1
  637. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
  638. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  639. package/packages/database/src/lib/projectToDb.js +1 -1
  640. package/packages/database/src/lib/projectToDb.js.map +1 -1
  641. package/packages/database/src/lib/saveFiles.js +1 -1
  642. package/packages/database/src/lib/saveFiles.js.map +1 -1
  643. package/packages/database/src/lib/scenarioToDb.js +1 -1
  644. package/packages/database/src/lib/scenarioToDb.js.map +1 -1
  645. package/packages/database/src/lib/updateCommitMetadata.js +100 -89
  646. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  647. package/packages/database/src/lib/updateFreshAnalysisStatus.js +41 -30
  648. package/packages/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
  649. package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
  650. package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
  651. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
  652. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
  653. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
  654. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  655. package/packages/utils/src/lib/fs/rsyncCopy.js +98 -3
  656. package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  657. package/scripts/finalize-analyzer.cjs +8 -76
  658. package/codeyam-cli/src/commands/detect-universal-mocks.js +0 -118
  659. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +0 -1
  660. package/codeyam-cli/src/commands/list.js +0 -31
  661. package/codeyam-cli/src/commands/list.js.map +0 -1
  662. package/codeyam-cli/src/commands/webapp-info.js +0 -146
  663. package/codeyam-cli/src/commands/webapp-info.js.map +0 -1
  664. package/codeyam-cli/src/utils/universal-mocks.js +0 -152
  665. package/codeyam-cli/src/utils/universal-mocks.js.map +0 -1
  666. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-C8lyxW9k.js +0 -34
  667. package/codeyam-cli/src/webserver/build/client/assets/copy-Bb-80kDT.js +0 -6
  668. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BBnGWYga.js +0 -1
  669. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js +0 -6
  670. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-D1T4TGjf.js +0 -6
  671. package/codeyam-cli/src/webserver/build/client/assets/file-code-Dhef1kWN.js +0 -6
  672. package/codeyam-cli/src/webserver/build/client/assets/globals-D3yhhV8x.css +0 -1
  673. package/codeyam-cli/src/webserver/build/client/assets/manifest-7522edd4.js +0 -1
  674. package/codeyam-cli/src/webserver/build/client/assets/memory-yxFcrxBX.js +0 -92
  675. package/codeyam-cli/src/webserver/build/client/assets/root-eVAaavTS.js +0 -62
  676. package/codeyam-cli/src/webserver/build/client/assets/settings-CS5f3WzT.js +0 -1
  677. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-aSv48UbS.js +0 -2
  678. package/codeyam-cli/src/webserver/build/server/assets/index-DVzYx8PN.js +0 -1
  679. package/codeyam-cli/src/webserver/build/server/assets/server-build-4Cr0uToj.js +0 -257
  680. package/codeyam-cli/templates/codeyam-stop-hook.sh +0 -284
  681. package/codeyam-cli/templates/codeyam:diagnose.md +0 -803
  682. package/codeyam-cli/templates/codeyam:memory.md +0 -462
  683. package/codeyam-cli/templates/codeyam:new-rule.md +0 -13
@@ -152,7 +152,7 @@ export interface ScopeInfo {
152
152
  [childComponentName: string]: Array<{
153
153
  path: string;
154
154
  conditionType: 'truthiness' | 'comparison';
155
- location: 'if' | 'ternary' | 'logical-and' | 'switch';
155
+ location: 'if' | 'ternary' | 'logical-and' | 'switch' | 'unconditional';
156
156
  isNegated?: boolean;
157
157
  }>;
158
158
  };
@@ -397,6 +397,7 @@ const SILENTLY_IGNORED_EQUIVALENCY_REASONS = new Set([
397
397
  'transformed non-object function equivalency - implicit parent equivalency - rerouted via useCallback',
398
398
  'transformed non-object function equivalency - Array.from() equivalency',
399
399
  'Spread operator equivalency key update: Explicit array deconstruction equivalency value',
400
+ // 'transformed non-object function equivalency - Explicit array deconstruction equivalency value',
400
401
  ]);
401
402
 
402
403
  export class ScopeDataStructure {
@@ -424,7 +425,7 @@ export class ScopeDataStructure {
424
425
  path: string;
425
426
  conditionType: 'truthiness' | 'comparison' | 'switch';
426
427
  comparedValues?: string[];
427
- location: 'if' | 'ternary' | 'logical-and' | 'switch';
428
+ location: 'if' | 'ternary' | 'logical-and' | 'switch' | 'unconditional';
428
429
  }>
429
430
  > = {};
430
431
 
@@ -799,6 +800,11 @@ export class ScopeDataStructure {
799
800
  return;
800
801
  }
801
802
 
803
+ // PERF: Early exit for paths with repeated function-call signature patterns
804
+ if (this.hasExcessivePatternRepetition(path)) {
805
+ return;
806
+ }
807
+
802
808
  // Update chain metadata for database tracking
803
809
  if (equivalencyValueChain.length > 0) {
804
810
  equivalencyValueChain[equivalencyValueChain.length - 1].addToSchemaId =
@@ -1102,6 +1108,33 @@ export class ScopeDataStructure {
1102
1108
  return;
1103
1109
  }
1104
1110
 
1111
+ // Case 3: Circular reference through scope-suffixed names (____cyScope pattern)
1112
+ // When a named arrow function is defined inside a scope (e.g., useEffect callback):
1113
+ // const identifyUser = async () => { ... };
1114
+ // identifyUser();
1115
+ // This creates a variable "identifyUser" and a scope "identifyUser____cyScope9F".
1116
+ // Mutual equivalencies between these cause infinite loops in Phase 2 because
1117
+ // processing one triggers addToSchema → followEquivalencies → addEquivalency
1118
+ // on the reverse, which repeats indefinitely.
1119
+ // Only block when the REVERSE direction already exists (creating a cycle).
1120
+ // The initial one-directional equivalency is necessary for scope resolution.
1121
+ if (
1122
+ path &&
1123
+ equivalentPath &&
1124
+ (equivalentPath.startsWith(path + '____') ||
1125
+ path.startsWith(equivalentPath + '____'))
1126
+ ) {
1127
+ // Check if the reverse equivalency already exists
1128
+ const reverseEquivalencies =
1129
+ scopeNode.equivalencies[equivalentPath] || [];
1130
+ const reverseExists = reverseEquivalencies.some(
1131
+ (v) => v.schemaPath === path,
1132
+ );
1133
+ if (reverseExists) {
1134
+ return;
1135
+ }
1136
+ }
1137
+
1105
1138
  if (!equivalentScopeName) {
1106
1139
  console.error(
1107
1140
  'CodeYam Error: Missing equivalent scope name - FULL CONTEXT:',
@@ -1486,6 +1519,15 @@ export class ScopeDataStructure {
1486
1519
 
1487
1520
  const bestValue = selectBestValue(value1, value2);
1488
1521
 
1522
+ // PERF: Skip paths with repeated function-call signature patterns
1523
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
1524
+ if (
1525
+ this.hasExcessivePatternRepetition(schemaPath) ||
1526
+ this.hasExcessivePatternRepetition(equivalentSchemaPath)
1527
+ ) {
1528
+ continue;
1529
+ }
1530
+
1489
1531
  scopeNode.schema[schemaPath] = bestValue;
1490
1532
  equivalentScopeNode.schema[equivalentSchemaPath] = bestValue;
1491
1533
  } else if (
@@ -1499,6 +1541,11 @@ export class ScopeDataStructure {
1499
1541
  ...remainingSchemaPathParts,
1500
1542
  ]);
1501
1543
 
1544
+ // PERF: Skip paths with repeated function-call signature patterns
1545
+ if (this.hasExcessivePatternRepetition(newEquivalentPath)) {
1546
+ continue;
1547
+ }
1548
+
1502
1549
  equivalentScopeNode.schema[newEquivalentPath] =
1503
1550
  scopeNode.schema[schemaPath];
1504
1551
  }
@@ -1618,6 +1665,23 @@ export class ScopeDataStructure {
1618
1665
  }
1619
1666
  }
1620
1667
 
1668
+ // Check for repeated function calls that indicate recursive type expansion.
1669
+ // E.g., localeCompare(b[])...localeCompare(b[]) means string.localeCompare
1670
+ // returns a type that again has localeCompare, causing infinite expansion.
1671
+ // We extract all function call patterns like "funcName(args)" and check if
1672
+ // the same normalized call appears more than once.
1673
+ const funcCallPattern = /(?:^|\.)[^.([]+\([^)]*\)/g;
1674
+ const funcCallMatches = path.match(funcCallPattern);
1675
+ if (funcCallMatches && funcCallMatches.length > 1) {
1676
+ const seen = new Set<string>();
1677
+ for (const match of funcCallMatches) {
1678
+ // Strip leading dot and normalize array indices
1679
+ const normalized = match.replace(/^\./, '').replace(/\[\d+\]/g, '[]');
1680
+ if (seen.has(normalized)) return true;
1681
+ seen.add(normalized);
1682
+ }
1683
+ }
1684
+
1621
1685
  // For longer paths, detect any repeated multi-part segments we haven't explicitly listed
1622
1686
  const pathParts = this.splitPath(path);
1623
1687
  if (pathParts.length <= 6) {
@@ -1650,17 +1714,26 @@ export class ScopeDataStructure {
1650
1714
  private setInstantiatedVariables(scopeNode: ScopeNode) {
1651
1715
  let instantiatedVariables = scopeNode.analysis?.instantiatedVariables ?? [];
1652
1716
 
1653
- for (const [path, equivalentPath] of Object.entries(
1717
+ for (const [path, rawEquivalentPath] of Object.entries(
1654
1718
  scopeNode.analysis.isolatedEquivalentVariables ?? {},
1655
1719
  )) {
1656
- if (typeof equivalentPath !== 'string') {
1657
- continue;
1658
- }
1720
+ // Normalize to array for consistent handling (supports both string and string[])
1721
+ const equivalentPaths = Array.isArray(rawEquivalentPath)
1722
+ ? rawEquivalentPath
1723
+ : rawEquivalentPath
1724
+ ? [rawEquivalentPath]
1725
+ : [];
1726
+
1727
+ for (const equivalentPath of equivalentPaths) {
1728
+ if (typeof equivalentPath !== 'string') {
1729
+ continue;
1730
+ }
1659
1731
 
1660
- if (equivalentPath.startsWith('signature[')) {
1661
- const equivalentPathParts = this.splitPath(equivalentPath);
1662
- instantiatedVariables.push(equivalentPathParts[0]);
1663
- instantiatedVariables.push(path);
1732
+ if (equivalentPath.startsWith('signature[')) {
1733
+ const equivalentPathParts = this.splitPath(equivalentPath);
1734
+ instantiatedVariables.push(equivalentPathParts[0]);
1735
+ instantiatedVariables.push(path);
1736
+ }
1664
1737
  }
1665
1738
 
1666
1739
  const duplicateInstantiated = instantiatedVariables.find(
@@ -1673,9 +1746,14 @@ export class ScopeDataStructure {
1673
1746
  }
1674
1747
  }
1675
1748
 
1676
- instantiatedVariables = instantiatedVariables.filter(
1677
- (varName, index, self) => self.indexOf(varName) === index,
1678
- );
1749
+ const instantiatedSeen = new Set<string>();
1750
+ instantiatedVariables = instantiatedVariables.filter((varName) => {
1751
+ if (instantiatedSeen.has(varName)) {
1752
+ return false;
1753
+ }
1754
+ instantiatedSeen.add(varName);
1755
+ return true;
1756
+ });
1679
1757
 
1680
1758
  scopeNode.instantiatedVariables = instantiatedVariables;
1681
1759
 
@@ -1696,13 +1774,19 @@ export class ScopeDataStructure {
1696
1774
  ...parentScopeNode.instantiatedVariables.filter(
1697
1775
  (v) => !v.startsWith('signature[') && !v.startsWith('returnValue'),
1698
1776
  ),
1699
- ].filter(
1700
- (varName, index, self) =>
1701
- !instantiatedVariables.includes(varName) &&
1702
- self.indexOf(varName) === index,
1703
- );
1777
+ ].filter((varName) => !instantiatedSeen.has(varName));
1778
+
1779
+ const parentInstantiatedSeen = new Set<string>();
1780
+ const dedupedParentInstantiatedVariables =
1781
+ parentInstantiatedVariables.filter((varName) => {
1782
+ if (parentInstantiatedSeen.has(varName)) {
1783
+ return false;
1784
+ }
1785
+ parentInstantiatedSeen.add(varName);
1786
+ return true;
1787
+ });
1704
1788
 
1705
- scopeNode.parentInstantiatedVariables = parentInstantiatedVariables;
1789
+ scopeNode.parentInstantiatedVariables = dedupedParentInstantiatedVariables;
1706
1790
  }
1707
1791
 
1708
1792
  private trackFunctionCalls(scopeNode: ScopeNode) {
@@ -1718,172 +1802,198 @@ export class ScopeDataStructure {
1718
1802
  const { isolatedStructure, isolatedEquivalentVariables } =
1719
1803
  scopeNode.analysis;
1720
1804
 
1805
+ // Flatten isolatedEquivalentVariables values for allPaths (handles both string and string[])
1806
+ const flattenedEquivValues = Object.values(
1807
+ isolatedEquivalentVariables || {},
1808
+ ).flatMap((v) => (Array.isArray(v) ? v : [v]));
1809
+
1721
1810
  const allPaths = Array.from(
1722
1811
  new Set([
1723
1812
  ...Object.keys(isolatedStructure || {}),
1724
1813
  ...Object.keys(isolatedEquivalentVariables || {}),
1725
- ...Object.values(isolatedEquivalentVariables || {}),
1814
+ ...flattenedEquivValues,
1726
1815
  ]),
1727
1816
  );
1728
1817
 
1729
1818
  for (let path in isolatedEquivalentVariables) {
1730
- let equivalentValue = isolatedEquivalentVariables?.[path];
1731
-
1732
- if (equivalentValue && this.isValidPath(equivalentValue)) {
1733
- // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1734
- // These markers are critical for distinguishing variable reassignments.
1735
- // For example, with:
1736
- // let fetcher = useFetcher<ConfigData>();
1737
- // const configData = fetcher.data?.data;
1738
- // fetcher = useFetcher<SettingsData>();
1739
- // const settingsData = fetcher.data?.data;
1740
- //
1741
- // mergeStatements creates:
1742
- // fetcher useFetcher<ConfigData>()...
1743
- // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1744
- // configData fetcher.data.data
1745
- // settingsData → fetcher::cyDuplicateKey1::.data.data
1746
- //
1747
- // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1748
- // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1749
- path = cleanPath(path, allPaths);
1750
- equivalentValue = cleanPath(equivalentValue, allPaths);
1751
-
1752
- this.addEquivalency(
1753
- path,
1754
- equivalentValue,
1755
- scopeNode.name,
1756
- scopeNode,
1757
- 'original equivalency',
1758
- );
1819
+ const rawEquivalentValue = isolatedEquivalentVariables?.[path];
1820
+ // Normalize to array for consistent handling
1821
+ const equivalentValues = Array.isArray(rawEquivalentValue)
1822
+ ? rawEquivalentValue
1823
+ : [rawEquivalentValue];
1824
+
1825
+ for (let equivalentValue of equivalentValues) {
1826
+ if (equivalentValue && this.isValidPath(equivalentValue)) {
1827
+ // IMPORTANT: DO NOT strip ::cyDuplicateKey:: markers from equivalencies.
1828
+ // These markers are critical for distinguishing variable reassignments.
1829
+ // For example, with:
1830
+ // let fetcher = useFetcher<ConfigData>();
1831
+ // const configData = fetcher.data?.data;
1832
+ // fetcher = useFetcher<SettingsData>();
1833
+ // const settingsData = fetcher.data?.data;
1834
+ //
1835
+ // mergeStatements creates:
1836
+ // fetcher useFetcher<ConfigData>()...
1837
+ // fetcher::cyDuplicateKey1:: useFetcher<SettingsData>()...
1838
+ // configData fetcher.data.data
1839
+ // settingsData fetcher::cyDuplicateKey1::.data.data
1840
+ //
1841
+ // If we strip ::cyDuplicateKey::, settingsData would incorrectly trace
1842
+ // to useFetcher<ConfigData>() instead of useFetcher<SettingsData>().
1843
+ path = cleanPath(path, allPaths);
1844
+ equivalentValue = cleanPath(equivalentValue, allPaths);
1845
+
1846
+ this.addEquivalency(
1847
+ path,
1848
+ equivalentValue,
1849
+ scopeNode.name,
1850
+ scopeNode,
1851
+ 'original equivalency',
1852
+ );
1759
1853
 
1760
- // Propagate equivalencies involving parent-scope variables to those parent scopes.
1761
- // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1762
- // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1763
- // visible when tracing from the parent scope.
1764
- const rootVariable = this.extractRootVariable(path);
1765
- const equivalentRootVariable =
1766
- this.extractRootVariable(equivalentValue);
1767
-
1768
- // Skip propagation for self-referential reassignment patterns like:
1769
- // x = x.method().functionCallReturnValue
1770
- // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1771
- // These create circular references since both sides reference the same variable.
1772
- //
1773
- // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1774
- // where the path has additional segments beyond the root variable.
1775
- const pathIsJustRootVariable = path === rootVariable;
1776
- const isSelfReferentialReassignment =
1777
- pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1854
+ // Propagate equivalencies involving parent-scope variables to those parent scopes.
1855
+ // This handles patterns like: collected.push({...entity}) where 'collected' is defined
1856
+ // in a parent scope. The equivalency collected[] -> push().signature[0] needs to be
1857
+ // visible when tracing from the parent scope.
1858
+ const rootVariable = this.extractRootVariable(path);
1859
+ const equivalentRootVariable =
1860
+ this.extractRootVariable(equivalentValue);
1861
+
1862
+ // Skip propagation for self-referential reassignment patterns like:
1863
+ // x = x.method().functionCallReturnValue
1864
+ // where the path IS the variable itself (not a sub-path like x[] or x.prop).
1865
+ // These create circular references since both sides reference the same variable.
1866
+ //
1867
+ // But DO propagate for patterns like collected[] -> collected.push(...).signature[0]
1868
+ // where the path has additional segments beyond the root variable.
1869
+ const pathIsJustRootVariable = path === rootVariable;
1870
+ const isSelfReferentialReassignment =
1871
+ pathIsJustRootVariable && rootVariable === equivalentRootVariable;
1778
1872
 
1779
- if (
1780
- rootVariable &&
1781
- !isSelfReferentialReassignment &&
1782
- scopeNode.parentInstantiatedVariables?.includes(rootVariable)
1783
- ) {
1784
- // Find the parent scope where this variable is defined
1785
- for (const parentScopeName of scopeNode.tree || []) {
1786
- const parentScope = this.scopeNodes[parentScopeName];
1787
- if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1788
- // Add the equivalency to the parent scope as well
1789
- this.addEquivalency(
1790
- path,
1791
- equivalentValue,
1792
- scopeNode.name, // The equivalent path's scope remains the child scope
1793
- parentScope, // But store it in the parent scope's equivalencies
1794
- 'propagated parent-variable equivalency',
1795
- );
1796
- break;
1873
+ if (
1874
+ rootVariable &&
1875
+ !isSelfReferentialReassignment &&
1876
+ scopeNode.parentInstantiatedVariables?.includes(rootVariable)
1877
+ ) {
1878
+ // Find the parent scope where this variable is defined
1879
+ for (const parentScopeName of scopeNode.tree || []) {
1880
+ const parentScope = this.scopeNodes[parentScopeName];
1881
+ if (parentScope?.instantiatedVariables?.includes(rootVariable)) {
1882
+ // Add the equivalency to the parent scope as well
1883
+ this.addEquivalency(
1884
+ path,
1885
+ equivalentValue,
1886
+ scopeNode.name, // The equivalent path's scope remains the child scope
1887
+ parentScope, // But store it in the parent scope's equivalencies
1888
+ 'propagated parent-variable equivalency',
1889
+ );
1890
+ break;
1891
+ }
1797
1892
  }
1798
1893
  }
1799
- }
1800
1894
 
1801
- // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1802
- // that has sub-properties defined in the isolatedEquivalentVariables.
1803
- // This handles cases like: dataItem={{ structure: completeDataStructure }}
1804
- // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1805
- // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1806
- const isSimpleVariable =
1807
- !equivalentValue.startsWith('signature[') &&
1808
- !equivalentValue.includes('functionCallReturnValue') &&
1809
- !equivalentValue.includes('.') &&
1810
- !equivalentValue.includes('[');
1811
-
1812
- if (isSimpleVariable) {
1813
- // Look in current scope and all parent scopes for sub-properties
1814
- const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1815
- for (const scopeName of scopesToCheck) {
1816
- const checkScope = this.scopeNodes[scopeName];
1817
- if (!checkScope?.analysis?.isolatedEquivalentVariables) continue;
1818
-
1819
- for (const [subPath, subValue] of Object.entries(
1820
- checkScope.analysis.isolatedEquivalentVariables,
1821
- )) {
1822
- // Check if this is a sub-property of the equivalentValue variable
1823
- // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1824
- const matchesDot = subPath.startsWith(equivalentValue + '.');
1825
- const matchesBracket = subPath.startsWith(equivalentValue + '[');
1826
- if (matchesDot || matchesBracket) {
1827
- const subPropertyPath = subPath.substring(
1828
- equivalentValue.length,
1829
- );
1830
- const newPath = cleanPath(path + subPropertyPath, allPaths);
1831
- const newEquivalentValue = cleanPath(
1832
- (subValue as string).replace(/::cyDuplicateKey\d+::/g, ''),
1833
- allPaths,
1895
+ // Propagate sub-property equivalencies when the equivalentValue is a simple variable
1896
+ // that has sub-properties defined in the isolatedEquivalentVariables.
1897
+ // This handles cases like: dataItem={{ structure: completeDataStructure }}
1898
+ // where completeDataStructure has sub-properties like completeDataStructure['Function Arguments']
1899
+ // We need to propagate these to create: dataItem.structure['Function Arguments'] equivalencies
1900
+ const isSimpleVariable =
1901
+ !equivalentValue.startsWith('signature[') &&
1902
+ !equivalentValue.includes('functionCallReturnValue') &&
1903
+ !equivalentValue.includes('.') &&
1904
+ !equivalentValue.includes('[');
1905
+
1906
+ if (isSimpleVariable) {
1907
+ // Look in current scope and all parent scopes for sub-properties
1908
+ const scopesToCheck = [scopeNode.name, ...scopeNode.tree];
1909
+ for (const scopeName of scopesToCheck) {
1910
+ const checkScope = this.scopeNodes[scopeName];
1911
+ if (!checkScope?.analysis?.isolatedEquivalentVariables) continue;
1912
+
1913
+ for (const [subPath, rawSubValue] of Object.entries(
1914
+ checkScope.analysis.isolatedEquivalentVariables,
1915
+ )) {
1916
+ // Normalize to array for consistent handling
1917
+ const subValues = Array.isArray(rawSubValue)
1918
+ ? rawSubValue
1919
+ : rawSubValue
1920
+ ? [rawSubValue]
1921
+ : [];
1922
+
1923
+ // Check if this is a sub-property of the equivalentValue variable
1924
+ // e.g., completeDataStructure['Function Arguments'] or completeDataStructure.foo
1925
+ const matchesDot = subPath.startsWith(equivalentValue + '.');
1926
+ const matchesBracket = subPath.startsWith(
1927
+ equivalentValue + '[',
1834
1928
  );
1835
-
1836
- if (
1837
- newEquivalentValue &&
1838
- this.isValidPath(newEquivalentValue)
1839
- ) {
1840
- this.addEquivalency(
1841
- newPath,
1842
- newEquivalentValue,
1843
- checkScope.name, // Use the scope where the sub-property was found
1844
- scopeNode,
1845
- 'propagated sub-property equivalency',
1929
+ if (matchesDot || matchesBracket) {
1930
+ const subPropertyPath = subPath.substring(
1931
+ equivalentValue.length,
1846
1932
  );
1933
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
1934
+
1935
+ for (const subValue of subValues) {
1936
+ if (typeof subValue !== 'string') continue;
1937
+ const newEquivalentValue = cleanPath(
1938
+ subValue.replace(/::cyDuplicateKey\d+::/g, ''),
1939
+ allPaths,
1940
+ );
1941
+
1942
+ if (
1943
+ newEquivalentValue &&
1944
+ this.isValidPath(newEquivalentValue)
1945
+ ) {
1946
+ this.addEquivalency(
1947
+ newPath,
1948
+ newEquivalentValue,
1949
+ checkScope.name, // Use the scope where the sub-property was found
1950
+ scopeNode,
1951
+ 'propagated sub-property equivalency',
1952
+ );
1953
+ }
1954
+ }
1847
1955
  }
1848
- }
1849
1956
 
1850
- // Also check if equivalentValue itself maps to a functionCallReturnValue
1851
- // e.g., result = useMemo(...).functionCallReturnValue
1852
- if (
1853
- subPath === equivalentValue &&
1854
- typeof subValue === 'string' &&
1855
- subValue.endsWith('.functionCallReturnValue')
1856
- ) {
1857
- this.propagateFunctionCallReturnSubProperties(
1858
- path,
1859
- subValue,
1860
- scopeNode,
1861
- allPaths,
1862
- );
1957
+ // Also check if equivalentValue itself maps to a functionCallReturnValue
1958
+ // e.g., result = useMemo(...).functionCallReturnValue
1959
+ for (const subValue of subValues) {
1960
+ if (
1961
+ subPath === equivalentValue &&
1962
+ typeof subValue === 'string' &&
1963
+ subValue.endsWith('.functionCallReturnValue')
1964
+ ) {
1965
+ this.propagateFunctionCallReturnSubProperties(
1966
+ path,
1967
+ subValue,
1968
+ scopeNode,
1969
+ allPaths,
1970
+ );
1971
+ }
1972
+ }
1863
1973
  }
1864
1974
  }
1865
1975
  }
1866
- }
1867
1976
 
1868
- // Handle function call return values by propagating returnValue.* sub-properties
1869
- // from the callback scope to the usage path
1870
- if (equivalentValue.endsWith('.functionCallReturnValue')) {
1871
- this.propagateFunctionCallReturnSubProperties(
1872
- path,
1873
- equivalentValue,
1874
- scopeNode,
1875
- allPaths,
1876
- );
1977
+ // Handle function call return values by propagating returnValue.* sub-properties
1978
+ // from the callback scope to the usage path
1979
+ if (equivalentValue.endsWith('.functionCallReturnValue')) {
1980
+ this.propagateFunctionCallReturnSubProperties(
1981
+ path,
1982
+ equivalentValue,
1983
+ scopeNode,
1984
+ allPaths,
1985
+ );
1877
1986
 
1878
- // Track which variable receives the return value of each function call
1879
- // This enables generating separate mock data for each call site
1880
- this.trackReceivingVariable(path, equivalentValue);
1881
- }
1987
+ // Track which variable receives the return value of each function call
1988
+ // This enables generating separate mock data for each call site
1989
+ this.trackReceivingVariable(path, equivalentValue);
1990
+ }
1882
1991
 
1883
- // Also track variables that receive destructured properties from function call return values
1884
- // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1885
- if (equivalentValue.includes('.functionCallReturnValue.')) {
1886
- this.trackReceivingVariable(path, equivalentValue);
1992
+ // Also track variables that receive destructured properties from function call return values
1993
+ // e.g., "userData" -> "db.query('users').functionCallReturnValue.data"
1994
+ if (equivalentValue.includes('.functionCallReturnValue.')) {
1995
+ this.trackReceivingVariable(path, equivalentValue);
1996
+ }
1887
1997
  }
1888
1998
  }
1889
1999
  }
@@ -2064,9 +2174,18 @@ export class ScopeDataStructure {
2064
2174
  const checkScope = this.scopeNodes[scopeName];
2065
2175
  if (!checkScope?.analysis?.isolatedEquivalentVariables) continue;
2066
2176
 
2067
- const functionRef =
2177
+ const rawFunctionRef =
2068
2178
  checkScope.analysis.isolatedEquivalentVariables[functionName];
2069
- if (typeof functionRef === 'string' && functionRef.endsWith('F')) {
2179
+ // Normalize to array and find first string ending with 'F'
2180
+ const functionRefs = Array.isArray(rawFunctionRef)
2181
+ ? rawFunctionRef
2182
+ : rawFunctionRef
2183
+ ? [rawFunctionRef]
2184
+ : [];
2185
+ const functionRef = functionRefs.find(
2186
+ (r) => typeof r === 'string' && r.endsWith('F'),
2187
+ );
2188
+ if (typeof functionRef === 'string') {
2070
2189
  callbackScopeName = functionRef.slice(0, -1);
2071
2190
  break;
2072
2191
  }
@@ -2094,19 +2213,24 @@ export class ScopeDataStructure {
2094
2213
 
2095
2214
  const isolatedVars = callbackScope.analysis.isolatedEquivalentVariables;
2096
2215
 
2216
+ // Get the first returnValue equivalency (normalize array to single value for these checks)
2217
+ const rawReturnValue = isolatedVars.returnValue;
2218
+ const firstReturnValue = Array.isArray(rawReturnValue)
2219
+ ? rawReturnValue[0]
2220
+ : rawReturnValue;
2221
+
2097
2222
  // First, check if returnValue is an alias to another variable (e.g., returnValue = intermediate)
2098
2223
  // If so, we need to look for that variable's sub-properties too
2099
2224
  const returnValueAlias =
2100
- typeof isolatedVars.returnValue === 'string' &&
2101
- !isolatedVars.returnValue.includes('.')
2102
- ? isolatedVars.returnValue
2225
+ typeof firstReturnValue === 'string' && !firstReturnValue.includes('.')
2226
+ ? firstReturnValue
2103
2227
  : undefined;
2104
2228
 
2105
2229
  // Pattern 3: Object.keys(X).reduce() - the reduce result has the same sub-properties as X
2106
2230
  // When returnValue = "Object.keys(source).reduce(...).functionCallReturnValue", look for source.* sub-properties
2107
2231
  let reduceSourceVar: string | undefined;
2108
- if (typeof isolatedVars.returnValue === 'string') {
2109
- const reduceMatch = isolatedVars.returnValue.match(
2232
+ if (typeof firstReturnValue === 'string') {
2233
+ const reduceMatch = firstReturnValue.match(
2110
2234
  /^Object\.keys\((\w+)\)\.reduce\(.*\)\.functionCallReturnValue$/,
2111
2235
  );
2112
2236
  if (reduceMatch) {
@@ -2114,7 +2238,14 @@ export class ScopeDataStructure {
2114
2238
  }
2115
2239
  }
2116
2240
 
2117
- for (const [subPath, subValue] of Object.entries(isolatedVars)) {
2241
+ for (const [subPath, rawSubValue] of Object.entries(isolatedVars)) {
2242
+ // Normalize to array for consistent handling
2243
+ const subValues = Array.isArray(rawSubValue)
2244
+ ? rawSubValue
2245
+ : rawSubValue
2246
+ ? [rawSubValue]
2247
+ : [];
2248
+
2118
2249
  // Check for direct returnValue.* sub-properties
2119
2250
  const isReturnValueSub =
2120
2251
  subPath.startsWith('returnValue.') ||
@@ -2132,57 +2263,59 @@ export class ScopeDataStructure {
2132
2263
  (subPath.startsWith(reduceSourceVar + '.') ||
2133
2264
  subPath.startsWith(reduceSourceVar + '['));
2134
2265
 
2135
- if (
2136
- typeof subValue !== 'string' ||
2137
- (!isReturnValueSub && !isAliasSub && !isReduceSourceSub)
2138
- )
2139
- continue;
2140
-
2141
- // Convert alias/reduceSource paths to returnValue paths
2142
- let effectiveSubPath = subPath;
2143
- if (isAliasSub && !isReturnValueSub) {
2144
- // Replace the alias prefix with returnValue
2145
- effectiveSubPath =
2146
- 'returnValue' + subPath.substring(returnValueAlias!.length);
2147
- } else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
2148
- // Replace the reduce source prefix with returnValue
2149
- effectiveSubPath =
2150
- 'returnValue' + subPath.substring(reduceSourceVar!.length);
2151
- }
2152
- const subPropertyPath = effectiveSubPath.substring('returnValue'.length);
2153
- const newPath = cleanPath(path + subPropertyPath, allPaths);
2154
- let newEquivalentValue = cleanPath(
2155
- subValue.replace(/::cyDuplicateKey\d+::/g, ''),
2156
- allPaths,
2157
- );
2266
+ if (!isReturnValueSub && !isAliasSub && !isReduceSourceSub) continue;
2267
+
2268
+ for (const subValue of subValues) {
2269
+ if (typeof subValue !== 'string') continue;
2270
+
2271
+ // Convert alias/reduceSource paths to returnValue paths
2272
+ let effectiveSubPath = subPath;
2273
+ if (isAliasSub && !isReturnValueSub) {
2274
+ // Replace the alias prefix with returnValue
2275
+ effectiveSubPath =
2276
+ 'returnValue' + subPath.substring(returnValueAlias!.length);
2277
+ } else if (isReduceSourceSub && !isReturnValueSub && !isAliasSub) {
2278
+ // Replace the reduce source prefix with returnValue
2279
+ effectiveSubPath =
2280
+ 'returnValue' + subPath.substring(reduceSourceVar!.length);
2281
+ }
2282
+ const subPropertyPath = effectiveSubPath.substring(
2283
+ 'returnValue'.length,
2284
+ );
2285
+ const newPath = cleanPath(path + subPropertyPath, allPaths);
2286
+ let newEquivalentValue = cleanPath(
2287
+ subValue.replace(/::cyDuplicateKey\d+::/g, ''),
2288
+ allPaths,
2289
+ );
2158
2290
 
2159
- // Resolve variable references through parent scope equivalencies
2160
- const resolved = this.resolveVariableThroughParentScopes(
2161
- newEquivalentValue,
2162
- callbackScope,
2163
- allPaths,
2164
- );
2165
- newEquivalentValue = resolved.resolvedPath;
2166
- const equivalentScopeName = resolved.scopeName;
2291
+ // Resolve variable references through parent scope equivalencies
2292
+ const resolved = this.resolveVariableThroughParentScopes(
2293
+ newEquivalentValue,
2294
+ callbackScope,
2295
+ allPaths,
2296
+ );
2297
+ newEquivalentValue = resolved.resolvedPath;
2298
+ const equivalentScopeName = resolved.scopeName;
2167
2299
 
2168
- if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
2169
- continue;
2300
+ if (!newEquivalentValue || !this.isValidPath(newEquivalentValue))
2301
+ continue;
2170
2302
 
2171
- this.addEquivalency(
2172
- newPath,
2173
- newEquivalentValue,
2174
- equivalentScopeName,
2175
- scopeNode,
2176
- 'propagated function call return sub-property equivalency',
2177
- );
2303
+ this.addEquivalency(
2304
+ newPath,
2305
+ newEquivalentValue,
2306
+ equivalentScopeName,
2307
+ scopeNode,
2308
+ 'propagated function call return sub-property equivalency',
2309
+ );
2178
2310
 
2179
- // Ensure the database entry has the usage path
2180
- this.addUsageToEquivalencyDatabaseEntry(
2181
- newPath,
2182
- newEquivalentValue,
2183
- equivalentScopeName,
2184
- scopeNode.name,
2185
- );
2311
+ // Ensure the database entry has the usage path
2312
+ this.addUsageToEquivalencyDatabaseEntry(
2313
+ newPath,
2314
+ newEquivalentValue,
2315
+ equivalentScopeName,
2316
+ scopeNode.name,
2317
+ );
2318
+ }
2186
2319
  }
2187
2320
  }
2188
2321
 
@@ -2222,8 +2355,15 @@ export class ScopeDataStructure {
2222
2355
  const parentScope = this.scopeNodes[parentScopeName];
2223
2356
  if (!parentScope?.analysis?.isolatedEquivalentVariables) continue;
2224
2357
 
2225
- const rootEquiv =
2358
+ const rawRootEquiv =
2226
2359
  parentScope.analysis.isolatedEquivalentVariables[rootVar];
2360
+ // Normalize to array and use first string value
2361
+ const rootEquivs = Array.isArray(rawRootEquiv)
2362
+ ? rawRootEquiv
2363
+ : rawRootEquiv
2364
+ ? [rawRootEquiv]
2365
+ : [];
2366
+ const rootEquiv = rootEquivs.find((r) => typeof r === 'string');
2227
2367
  if (typeof rootEquiv === 'string') {
2228
2368
  return {
2229
2369
  resolvedPath: cleanPath(rootEquiv + restOfPath, allPaths),
@@ -2498,6 +2638,7 @@ export class ScopeDataStructure {
2498
2638
  relevantSubPathParts.every((part, i) => part === schemaPathParts[i]) &&
2499
2639
  equivalentValue.scopeNodeName === scopeNode.name
2500
2640
  ) {
2641
+ // DEBUG
2501
2642
  continue;
2502
2643
  }
2503
2644
 
@@ -2684,6 +2825,8 @@ export class ScopeDataStructure {
2684
2825
  usageEquivalency.scopeNodeName,
2685
2826
  ) as ScopeNode;
2686
2827
 
2828
+ if (!usageScopeNode) continue;
2829
+
2687
2830
  // Guard against infinite recursion by tracking which paths we've already
2688
2831
  // added from addComplexSourcePathVariables
2689
2832
  if (
@@ -2763,6 +2906,8 @@ export class ScopeDataStructure {
2763
2906
  usageEquivalency.scopeNodeName,
2764
2907
  ) as ScopeNode;
2765
2908
 
2909
+ if (!usageScopeNode) continue;
2910
+
2766
2911
  // This is put in place to avoid propagating array functions like 'filter' through complex equivalencies
2767
2912
  // but may cause problems if the funtion call is not on a known object (e.g. string or array)
2768
2913
  if (
@@ -2889,10 +3034,105 @@ export class ScopeDataStructure {
2889
3034
  this.intermediatesOrderIndex.set(pathId, databaseEntry);
2890
3035
 
2891
3036
  if (intermediateIndex === 0) {
2892
- const isValidSourceCandidate =
3037
+ let isValidSourceCandidate =
2893
3038
  pathInfo.schemaPath.startsWith('signature[') ||
2894
3039
  pathInfo.schemaPath.includes('functionCallReturnValue');
2895
- if (isValidSourceCandidate) {
3040
+
3041
+ // Check if path STARTS with a spread pattern like [...var]
3042
+ // This handles cases like [...files][][0] or [...files].sort(...).functionCallReturnValue[][0]
3043
+ // where the spread source variable needs to be resolved to a signature path.
3044
+ // We do this REGARDLESS of isValidSourceCandidate because even paths containing
3045
+ // functionCallReturnValue may need spread resolution to trace back to the signature.
3046
+ const spreadMatch = pathInfo.schemaPath.match(/^\[\.\.\.(\w+)\]/);
3047
+ if (spreadMatch) {
3048
+ const spreadVar = spreadMatch[1];
3049
+ const spreadPattern = spreadMatch[0]; // The full [...var] match
3050
+ const scopeNode = this.scopeNodes[pathInfo.scopeNodeName];
3051
+
3052
+ if (scopeNode?.equivalencies) {
3053
+ // Follow the equivalency chain to find a signature path
3054
+ // e.g., files (cyScope1) → files (root) → signature[0].files
3055
+ const resolveToSignature = (
3056
+ varName: string,
3057
+ currentScopeName: string,
3058
+ visited: Set<string>,
3059
+ ): { schemaPath: string; scopeNodeName: string } | null => {
3060
+ const visitKey = `${currentScopeName}::${varName}`;
3061
+ if (visited.has(visitKey)) return null;
3062
+ visited.add(visitKey);
3063
+
3064
+ const currentScope = this.scopeNodes[currentScopeName];
3065
+ if (!currentScope?.equivalencies) return null;
3066
+
3067
+ const varEquivs = currentScope.equivalencies[varName];
3068
+ if (!varEquivs) return null;
3069
+
3070
+ // First check if any equivalency directly points to a signature path
3071
+ const signatureEquiv = varEquivs.find((eq) =>
3072
+ eq.schemaPath.startsWith('signature['),
3073
+ );
3074
+ if (signatureEquiv) {
3075
+ return signatureEquiv;
3076
+ }
3077
+
3078
+ // Otherwise, follow the chain to other scopes
3079
+ for (const equiv of varEquivs) {
3080
+ // If the equivalency points to the same variable in a different scope,
3081
+ // follow the chain
3082
+ if (
3083
+ equiv.schemaPath === varName &&
3084
+ equiv.scopeNodeName !== currentScopeName
3085
+ ) {
3086
+ const result = resolveToSignature(
3087
+ varName,
3088
+ equiv.scopeNodeName,
3089
+ visited,
3090
+ );
3091
+ if (result) return result;
3092
+ }
3093
+ }
3094
+
3095
+ return null;
3096
+ };
3097
+
3098
+ const signatureEquiv = resolveToSignature(
3099
+ spreadVar,
3100
+ pathInfo.scopeNodeName,
3101
+ new Set(),
3102
+ );
3103
+ if (signatureEquiv) {
3104
+ // Replace ONLY the [...var] part with the resolved signature path
3105
+ // This preserves any suffix like .sort(...).functionCallReturnValue[][0]
3106
+ const resolvedPath = pathInfo.schemaPath.replace(
3107
+ spreadPattern,
3108
+ signatureEquiv.schemaPath,
3109
+ );
3110
+ // Add the resolved path as a source candidate
3111
+ if (
3112
+ !databaseEntry.sourceCandidates.some(
3113
+ (sc) =>
3114
+ sc.schemaPath === resolvedPath &&
3115
+ sc.scopeNodeName === pathInfo.scopeNodeName,
3116
+ )
3117
+ ) {
3118
+ databaseEntry.sourceCandidates.push({
3119
+ scopeNodeName: pathInfo.scopeNodeName,
3120
+ schemaPath: resolvedPath,
3121
+ });
3122
+ }
3123
+ isValidSourceCandidate = true;
3124
+ }
3125
+ }
3126
+ }
3127
+
3128
+ if (
3129
+ isValidSourceCandidate &&
3130
+ !databaseEntry.sourceCandidates.some(
3131
+ (sc) =>
3132
+ sc.schemaPath === pathInfo.schemaPath &&
3133
+ sc.scopeNodeName === pathInfo.scopeNodeName,
3134
+ )
3135
+ ) {
2896
3136
  databaseEntry.sourceCandidates.push(pathInfo);
2897
3137
  }
2898
3138
  } else {
@@ -3120,6 +3360,14 @@ export class ScopeDataStructure {
3120
3360
  }
3121
3361
  }
3122
3362
 
3363
+ // Ensure parameter-to-signature equivalencies are fully propagated.
3364
+ // When a parameter variable (e.g., `node`) is equivalenced to `signature[N]`,
3365
+ // all sub-paths of that variable should also appear under `signature[N]`.
3366
+ // This handles cases where the sub-path was added to the schema via a propagation
3367
+ // chain that already included the variable↔signature equivalency, causing the
3368
+ // cycle detection to prevent the reverse mapping.
3369
+ this.propagateParameterToSignaturePaths(scopeNode);
3370
+
3123
3371
  fillInSchemaGapsAndUnknowns(scopeNode, fillInUnknowns);
3124
3372
 
3125
3373
  if (final) {
@@ -3134,6 +3382,97 @@ export class ScopeDataStructure {
3134
3382
  }
3135
3383
  }
3136
3384
 
3385
+ /**
3386
+ * For each equivalency where a simple variable maps to signature[N],
3387
+ * ensure all sub-paths of that variable are reflected under signature[N].
3388
+ */
3389
+ private propagateParameterToSignaturePaths(scopeNode: ScopeNode) {
3390
+ // Helper: check if a type is a concrete scalar that cannot have sub-properties.
3391
+ const SCALAR_TYPES = new Set([
3392
+ 'string',
3393
+ 'number',
3394
+ 'boolean',
3395
+ 'bigint',
3396
+ 'symbol',
3397
+ 'void',
3398
+ 'never',
3399
+ ]);
3400
+ const isDefinitelyScalar = (type: string): boolean => {
3401
+ const parts = type.split('|').map((s) => s.trim());
3402
+ const base = parts.filter((s) => s !== 'undefined' && s !== 'null');
3403
+ return base.length > 0 && base.every((b) => SCALAR_TYPES.has(b));
3404
+ };
3405
+
3406
+ // Find variable → signature[N] equivalencies
3407
+ for (const [varName, equivalencies] of Object.entries(
3408
+ scopeNode.equivalencies,
3409
+ )) {
3410
+ // Only process simple variable names (no dots, brackets, or parens)
3411
+ if (
3412
+ varName.includes('.') ||
3413
+ varName.includes('[') ||
3414
+ varName.includes('(')
3415
+ ) {
3416
+ continue;
3417
+ }
3418
+
3419
+ for (const equiv of equivalencies) {
3420
+ if (
3421
+ equiv.scopeNodeName === scopeNode.name &&
3422
+ equiv.schemaPath.startsWith('signature[')
3423
+ ) {
3424
+ const signaturePath = equiv.schemaPath;
3425
+ const varPrefix = varName + '.';
3426
+ const varBracketPrefix = varName + '[';
3427
+
3428
+ // Find all schema keys starting with the variable
3429
+ for (const key in scopeNode.schema) {
3430
+ if (key.startsWith(varPrefix) || key.startsWith(varBracketPrefix)) {
3431
+ const suffix = key.slice(varName.length);
3432
+ const sigKey = signaturePath + suffix;
3433
+
3434
+ // Only add if the signature path doesn't already exist
3435
+ if (!scopeNode.schema[sigKey]) {
3436
+ // Check if this path represents variable conflation:
3437
+ // When a standalone variable (e.g., showWorkoutForm from useState)
3438
+ // appears as a sub-property of a scalar-typed ancestor (e.g.,
3439
+ // activity_type = "string"), it's from scope conflation, not real
3440
+ // property access. Block these while allowing legitimate built-in
3441
+ // accesses like string.length or string.slice.
3442
+ let isConflatedPath = false;
3443
+ let checkPos = signaturePath.length;
3444
+ while (true) {
3445
+ checkPos = sigKey.indexOf('.', checkPos + 1);
3446
+ if (checkPos === -1) break;
3447
+ const ancestorPath = sigKey.substring(0, checkPos);
3448
+ const ancestorType = scopeNode.schema[ancestorPath];
3449
+ if (ancestorType && isDefinitelyScalar(ancestorType)) {
3450
+ // Ancestor is scalar — check if the immediate sub-property
3451
+ // is also a standalone variable (indicating conflation)
3452
+ const afterDot = sigKey.substring(checkPos + 1);
3453
+ const nextSep = afterDot.search(/[.\[]/);
3454
+ const subPropName =
3455
+ nextSep === -1
3456
+ ? afterDot
3457
+ : afterDot.substring(0, nextSep);
3458
+ if (scopeNode.schema[subPropName] !== undefined) {
3459
+ isConflatedPath = true;
3460
+ break;
3461
+ }
3462
+ }
3463
+ }
3464
+
3465
+ if (!isConflatedPath) {
3466
+ scopeNode.schema[sigKey] = scopeNode.schema[key];
3467
+ }
3468
+ }
3469
+ }
3470
+ }
3471
+ }
3472
+ }
3473
+ }
3474
+ }
3475
+
3137
3476
  private filterAndConvertSchema({
3138
3477
  filterPath,
3139
3478
  newPath,
@@ -3220,6 +3559,9 @@ export class ScopeDataStructure {
3220
3559
  equivalentValueSchemaPathParts.length,
3221
3560
  ),
3222
3561
  ]);
3562
+ // PERF: Skip keys with repeated function-call signature patterns
3563
+ // to prevent recursive type expansion (e.g., string.localeCompare returns string)
3564
+ if (this.hasExcessivePatternRepetition(newKey)) continue;
3223
3565
  resolvedSchema[newKey] = value;
3224
3566
  }
3225
3567
  }
@@ -3242,6 +3584,8 @@ export class ScopeDataStructure {
3242
3584
  if (!subSchema) continue;
3243
3585
 
3244
3586
  for (const resolvedKey in subSchema) {
3587
+ // PERF: Skip keys with repeated function-call signature patterns
3588
+ if (this.hasExcessivePatternRepetition(resolvedKey)) continue;
3245
3589
  if (
3246
3590
  !resolvedSchema[resolvedKey] ||
3247
3591
  subSchema[resolvedKey] === 'unknown'
@@ -3479,26 +3823,270 @@ export class ScopeDataStructure {
3479
3823
  return {};
3480
3824
  }
3481
3825
 
3826
+ // Collect all descendant scope names (including the scope itself)
3827
+ // This ensures we include external calls from nested scopes like cyScope2
3828
+ const getAllDescendantScopeNames = (
3829
+ node: import('./helpers/ScopeTreeManager').ScopeTreeNode,
3830
+ ): Set<string> => {
3831
+ const names = new Set<string>([node.name]);
3832
+ for (const child of node.children) {
3833
+ for (const name of getAllDescendantScopeNames(child)) {
3834
+ names.add(name);
3835
+ }
3836
+ }
3837
+ return names;
3838
+ };
3839
+
3840
+ const treeNode = this.scopeTreeManager.findNode(scopeNode.name);
3841
+ const descendantScopeNames = treeNode
3842
+ ? getAllDescendantScopeNames(treeNode)
3843
+ : new Set<string>([scopeNode.name]);
3844
+
3845
+ // Get all external function calls made from this scope or any descendant scope
3846
+ // This allows us to include prop equivalencies from JSX components
3847
+ // that were rendered in nested scopes (e.g., FileTableRow called from cyScope2)
3848
+ const externalCallsFromScope = this.externalFunctionCalls.filter((efc) =>
3849
+ descendantScopeNames.has(efc.callScope),
3850
+ );
3851
+ const externalCallNames = new Set(
3852
+ externalCallsFromScope.map((efc) => efc.name),
3853
+ );
3854
+
3855
+ // Helper to check if a usage belongs to this scope (directly, via descendant, or via external call)
3856
+ const usageMatchesScope = (usage: { scopeNodeName: string }) =>
3857
+ descendantScopeNames.has(usage.scopeNodeName) ||
3858
+ externalCallNames.has(usage.scopeNodeName);
3859
+
3482
3860
  const entries = this.equivalencyDatabase.filter((entry) =>
3483
- entry.usages.some((usage) => usage.scopeNodeName === scopeNode.name),
3861
+ entry.usages.some(usageMatchesScope),
3484
3862
  );
3485
- return entries.reduce(
3486
- (acc, entry) => {
3487
- if (entry.sourceCandidates.length === 0) return acc;
3488
- const usages = entry.usages.filter(
3489
- (u) => u.scopeNodeName === scopeNode.name,
3490
- );
3863
+
3864
+ // Helper to resolve a source candidate through equivalency chains to find signature paths
3865
+ const resolveToSignature = (
3866
+ source: Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>,
3867
+ visited: Set<string>,
3868
+ ): Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[] => {
3869
+ const visitKey = `${source.scopeNodeName}::${source.schemaPath}`;
3870
+ if (visited.has(visitKey)) return [];
3871
+ visited.add(visitKey);
3872
+
3873
+ // If already a signature path, return as-is
3874
+ if (source.schemaPath.startsWith('signature[')) {
3875
+ return [source];
3876
+ }
3877
+
3878
+ const currentScope = this.scopeNodes[source.scopeNodeName];
3879
+ if (!currentScope?.equivalencies) return [source];
3880
+
3881
+ // Check for direct equivalencies FIRST (full path match)
3882
+ // This ensures paths like "useMemo(...).functionCallReturnValue" follow to "cyScope1::returnValue"
3883
+ // before prefix matching tries "useMemo(...)" which goes to the useMemo scope
3884
+ const directEquivs = currentScope.equivalencies[source.schemaPath];
3885
+ if (directEquivs?.length > 0) {
3886
+ const results: Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[] =
3887
+ [];
3888
+ for (const equiv of directEquivs) {
3889
+ const resolved = resolveToSignature(
3890
+ {
3891
+ scopeNodeName: equiv.scopeNodeName,
3892
+ schemaPath: equiv.schemaPath,
3893
+ },
3894
+ visited,
3895
+ );
3896
+ results.push(...resolved);
3897
+ }
3898
+ if (results.length > 0) return results;
3899
+ }
3900
+
3901
+ // Handle spread patterns like [...items].sort().functionCallReturnValue
3902
+ // Extract the spread variable and resolve it through the equivalency chain
3903
+ const spreadMatch = source.schemaPath.match(/^\[\.\.\.(\w+)\]/);
3904
+ if (spreadMatch) {
3905
+ const spreadVar = spreadMatch[1];
3906
+ const spreadPattern = spreadMatch[0];
3907
+ const varEquivs = currentScope.equivalencies[spreadVar];
3908
+
3909
+ if (varEquivs?.length > 0) {
3910
+ const results: Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[] =
3911
+ [];
3912
+ for (const equiv of varEquivs) {
3913
+ // Follow the variable equivalency and then resolve from there
3914
+ const resolvedVar = resolveToSignature(
3915
+ {
3916
+ scopeNodeName: equiv.scopeNodeName,
3917
+ schemaPath: equiv.schemaPath,
3918
+ },
3919
+ visited,
3920
+ );
3921
+ // For each resolved variable path, create the full path with array element suffix
3922
+ for (const rv of resolvedVar) {
3923
+ if (rv.schemaPath.startsWith('signature[')) {
3924
+ // Get the suffix after the spread pattern
3925
+ let suffix = source.schemaPath.slice(spreadPattern.length);
3926
+
3927
+ // Clean the suffix: strip array method chains like .sort(...).functionCallReturnValue[]
3928
+ // These don't change the data identity, just transform it.
3929
+ // Keep only the final element access parts like [0], [1], etc.
3930
+ // Pattern: strip everything from a method call up through functionCallReturnValue[]
3931
+ suffix = suffix.replace(
3932
+ /\.\w+\([^)]*\)\.functionCallReturnValue\[\]/g,
3933
+ '',
3934
+ );
3935
+ // Also handle simpler case without nested parens
3936
+ suffix = suffix.replace(
3937
+ /\.sort\(\w*\(\)\)\.functionCallReturnValue\[\]/g,
3938
+ '',
3939
+ );
3940
+
3941
+ // Add [] to indicate array element access from the spread
3942
+ const resolvedPath = rv.schemaPath + '[]' + suffix;
3943
+ results.push({
3944
+ scopeNodeName: rv.scopeNodeName,
3945
+ schemaPath: resolvedPath,
3946
+ });
3947
+ }
3948
+ }
3949
+ }
3950
+ if (results.length > 0) return results;
3951
+ }
3952
+ }
3953
+
3954
+ // Try to find prefix equivalencies that can resolve this path
3955
+ // For path like "cyScope3().signature[0][0]", check "cyScope3().signature[0]", etc.
3956
+ const pathParts = this.splitPath(source.schemaPath);
3957
+ for (let i = pathParts.length - 1; i > 0; i--) {
3958
+ const prefix = this.joinPathParts(pathParts.slice(0, i));
3959
+ const suffix = this.joinPathParts(pathParts.slice(i));
3960
+ const prefixEquivs = currentScope.equivalencies[prefix];
3961
+
3962
+ if (prefixEquivs?.length > 0) {
3963
+ const results: Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[] =
3964
+ [];
3965
+ for (const equiv of prefixEquivs) {
3966
+ const newPath = this.joinPathParts([equiv.schemaPath, suffix]);
3967
+ const resolved = resolveToSignature(
3968
+ { scopeNodeName: equiv.scopeNodeName, schemaPath: newPath },
3969
+ visited,
3970
+ );
3971
+ results.push(...resolved);
3972
+ }
3973
+ if (results.length > 0) return results;
3974
+ }
3975
+ }
3976
+
3977
+ return [source];
3978
+ };
3979
+
3980
+ const acc = entries.reduce(
3981
+ (result, entry) => {
3982
+ if (entry.sourceCandidates.length === 0) return result;
3983
+ const usages = entry.usages.filter(usageMatchesScope);
3491
3984
  for (const usage of usages) {
3492
- acc[usage.schemaPath] ||= [];
3493
- acc[usage.schemaPath].push(...entry.sourceCandidates);
3985
+ result[usage.schemaPath] ||= [];
3986
+ // Resolve each source candidate through the equivalency chain
3987
+ for (const source of entry.sourceCandidates) {
3988
+ const resolvedSources = resolveToSignature(source, new Set());
3989
+ result[usage.schemaPath].push(...resolvedSources);
3990
+ }
3494
3991
  }
3495
- return acc;
3992
+ return result;
3496
3993
  },
3497
3994
  {} as Record<
3498
3995
  string,
3499
3996
  Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[]
3500
3997
  >,
3501
3998
  );
3999
+
4000
+ // Post-processing: enrich useState-backed sources with co-located external
4001
+ // function calls. When a useState value resolves to a setter variable that
4002
+ // lives in the same scope as a fetch/API call, that fetch is a data source.
4003
+ this.enrichUseStateSourcesWithCoLocatedCalls(acc);
4004
+
4005
+ return acc;
4006
+ }
4007
+
4008
+ /**
4009
+ * For each source that ends at a useState path, check if the setter was called
4010
+ * from a scope that also contains external function calls (like fetch).
4011
+ * If so, add those external calls as additional source candidates.
4012
+ */
4013
+ private enrichUseStateSourcesWithCoLocatedCalls(
4014
+ acc: Record<string, Pick<ScopeVariable, 'scopeNodeName' | 'schemaPath'>[]>,
4015
+ ) {
4016
+ const rootScopeName = this.scopeTreeManager.getRootName();
4017
+ const rootScope = this.scopeNodes[rootScopeName];
4018
+ if (!rootScope) return;
4019
+
4020
+ // Collect all descendants for each scope node
4021
+ const getAllDescendants = (
4022
+ node: import('./helpers/ScopeTreeManager').ScopeTreeNode,
4023
+ ): Set<string> => {
4024
+ const names = new Set<string>([node.name]);
4025
+ for (const child of node.children) {
4026
+ for (const name of getAllDescendants(child)) {
4027
+ names.add(name);
4028
+ }
4029
+ }
4030
+ return names;
4031
+ };
4032
+
4033
+ for (const [usagePath, sources] of Object.entries(acc)) {
4034
+ const additionalSources: Pick<
4035
+ ScopeVariable,
4036
+ 'scopeNodeName' | 'schemaPath'
4037
+ >[] = [];
4038
+
4039
+ for (const source of sources) {
4040
+ // Check if this source is a useState-related terminal path
4041
+ // (e.g., useState(X).functionCallReturnValue[1] or useState(X).signature[0])
4042
+ if (!source.schemaPath.match(/^useState\([^)]*\)\./)) continue;
4043
+
4044
+ // Find the useState call from the source path
4045
+ const useStateCallMatch = source.schemaPath.match(
4046
+ /^(useState\([^)]*\))\./,
4047
+ );
4048
+ if (!useStateCallMatch) continue;
4049
+ const useStateCall = useStateCallMatch[1];
4050
+
4051
+ // Look in the root scope for the useState value equivalency
4052
+ // which tells us where the setter was called from
4053
+ const valuePath = `${useStateCall}.functionCallReturnValue[0]`;
4054
+ const valueEquivs = rootScope.equivalencies[valuePath];
4055
+ if (!valueEquivs) continue;
4056
+
4057
+ for (const equiv of valueEquivs) {
4058
+ // Find the scope where the setter was called
4059
+ const setterScopeName = equiv.scopeNodeName;
4060
+ const setterScopeTree =
4061
+ this.scopeTreeManager.findNode(setterScopeName);
4062
+ if (!setterScopeTree) continue;
4063
+
4064
+ // Get all descendant scope names from the setter scope
4065
+ const relatedScopes = getAllDescendants(setterScopeTree);
4066
+
4067
+ // Find external function calls in those scopes whose return values
4068
+ // are actually consumed (assigned to a variable). This excludes
4069
+ // fire-and-forget calls like analytics.track() or console.log().
4070
+ const coLocatedCalls = this.externalFunctionCalls.filter(
4071
+ (efc) =>
4072
+ relatedScopes.has(efc.callScope) &&
4073
+ efc.receivingVariableNames &&
4074
+ efc.receivingVariableNames.length > 0,
4075
+ );
4076
+
4077
+ for (const call of coLocatedCalls) {
4078
+ additionalSources.push({
4079
+ scopeNodeName: call.callScope,
4080
+ schemaPath: `${call.callSignature}.functionCallReturnValue`,
4081
+ });
4082
+ }
4083
+ }
4084
+ }
4085
+
4086
+ if (additionalSources.length > 0) {
4087
+ acc[usagePath].push(...additionalSources);
4088
+ }
4089
+ }
3502
4090
  }
3503
4091
 
3504
4092
  getUsageEquivalencies(functionName?: string) {
@@ -3603,6 +4191,72 @@ export class ScopeDataStructure {
3603
4191
  }
3604
4192
  }
3605
4193
 
4194
+ // Enrich schema with deeply nested paths from internal function call scopes.
4195
+ // When a function call like traverse(tree) exists, and traverse's scope has
4196
+ // signature[0].children[path][entityName] (from propagateParameterToSignaturePaths),
4197
+ // we need to map those paths back to the argument variable (tree) in this scope.
4198
+ // This handles cases where cycle detection prevented the equivalency chain from
4199
+ // propagating deep paths during Phase 2 batch queue processing.
4200
+ for (const equivalenceKey in equivalencies ?? {}) {
4201
+ // Look for keys matching function call pattern: funcName(...).signature[N]
4202
+ const funcCallMatch = equivalenceKey.match(
4203
+ /^([^(]+)\(.*?\)\.(signature\[\d+\])$/,
4204
+ );
4205
+ if (!funcCallMatch) continue;
4206
+
4207
+ const calledFunctionName = funcCallMatch[1];
4208
+ const signatureParam = funcCallMatch[2]; // e.g., "signature[0]"
4209
+
4210
+ for (const equivalenceValue of equivalencies[equivalenceKey]) {
4211
+ if (equivalenceValue.scopeNodeName !== scopeName) continue;
4212
+
4213
+ const targetVariable = equivalenceValue.schemaPath;
4214
+
4215
+ // Get the called function's schema (includes propagated parameter paths)
4216
+ const childSchema = this.getSchema({
4217
+ scopeName: calledFunctionName,
4218
+ });
4219
+ if (!childSchema) continue;
4220
+
4221
+ // Map child function's signature paths to parent variable paths
4222
+ const sigPrefix = signatureParam + '.';
4223
+ const sigBracketPrefix = signatureParam + '[';
4224
+ for (const childKey in childSchema) {
4225
+ let suffix: string | null = null;
4226
+ if (childKey.startsWith(sigPrefix)) {
4227
+ suffix = childKey.slice(signatureParam.length);
4228
+ } else if (childKey.startsWith(sigBracketPrefix)) {
4229
+ suffix = childKey.slice(signatureParam.length);
4230
+ }
4231
+
4232
+ if (suffix !== null) {
4233
+ const parentKey = targetVariable + suffix;
4234
+ if (!schema[parentKey]) {
4235
+ schema[parentKey] = childSchema[childKey];
4236
+ }
4237
+ }
4238
+ }
4239
+ }
4240
+ }
4241
+
4242
+ // Helper: check if a type is a concrete scalar that cannot have sub-properties.
4243
+ // e.g., "string", "number | undefined", "boolean | null" are scalar.
4244
+ // "object", "array", "function", "unknown", "Workout", etc. are NOT scalar.
4245
+ const SCALAR_TYPES = new Set([
4246
+ 'string',
4247
+ 'number',
4248
+ 'boolean',
4249
+ 'bigint',
4250
+ 'symbol',
4251
+ 'void',
4252
+ 'never',
4253
+ ]);
4254
+ const isDefinitelyScalarType = (type: string): boolean => {
4255
+ const parts = type.split('|').map((s) => s.trim());
4256
+ const base = parts.filter((s) => s !== 'undefined' && s !== 'null');
4257
+ return base.length > 0 && base.every((b) => SCALAR_TYPES.has(b));
4258
+ };
4259
+
3606
4260
  // Propagate nested paths from variables to their signature equivalents
3607
4261
  // e.g., if workouts = signature[0].workouts, then workouts[].title becomes
3608
4262
  // signature[0].workouts[].title
@@ -3627,7 +4281,69 @@ export class ScopeDataStructure {
3627
4281
 
3628
4282
  // Add to schema if not already present
3629
4283
  if (!tempScopeNode.schema[signatureKey]) {
3630
- tempScopeNode.schema[signatureKey] = schema[schemaKey];
4284
+ // Check if this path represents variable conflation:
4285
+ // When a standalone variable (e.g., showWorkoutForm from useState)
4286
+ // appears as a sub-property of a scalar-typed ancestor (e.g.,
4287
+ // activity_type = "string"), it's from scope conflation, not real
4288
+ // property access. Block these while allowing legitimate built-in
4289
+ // accesses like string.length or string.slice.
4290
+ let isConflatedPath = false;
4291
+ let checkPos = signaturePath.length;
4292
+ while (true) {
4293
+ checkPos = signatureKey.indexOf('.', checkPos + 1);
4294
+ if (checkPos === -1) break;
4295
+ const ancestorPath = signatureKey.substring(0, checkPos);
4296
+ const ancestorType = tempScopeNode.schema[ancestorPath];
4297
+ if (ancestorType && isDefinitelyScalarType(ancestorType)) {
4298
+ // Ancestor is scalar — check if the immediate sub-property
4299
+ // is also a standalone variable (indicating conflation)
4300
+ const afterDot = signatureKey.substring(checkPos + 1);
4301
+ const nextSep = afterDot.search(/[.\[]/);
4302
+ const subPropName =
4303
+ nextSep === -1 ? afterDot : afterDot.substring(0, nextSep);
4304
+ if (schema[subPropName] !== undefined) {
4305
+ isConflatedPath = true;
4306
+ break;
4307
+ }
4308
+ }
4309
+ }
4310
+
4311
+ if (!isConflatedPath) {
4312
+ tempScopeNode.schema[signatureKey] = schema[schemaKey];
4313
+ }
4314
+ }
4315
+ }
4316
+ }
4317
+ }
4318
+
4319
+ // Post-process: filter out conflated signature paths.
4320
+ // During phase 2 scope analysis, useState(false) conflation can create
4321
+ // bad paths like signature[0].mockWorkouts[].activity_type.showWorkoutForm
4322
+ // directly in scopeNode.schema. These flow through signatureInSchema into
4323
+ // tempScopeNode.schema without any guard. Filter them out here by checking:
4324
+ // 1. An ancestor in the path has a concrete scalar type (string, number, boolean, etc.)
4325
+ // 2. The immediate sub-property of that scalar ancestor is also a standalone
4326
+ // variable in the schema (indicating conflation, not a real property access)
4327
+ for (const key of Object.keys(tempScopeNode.schema)) {
4328
+ if (!key.startsWith('signature[')) continue;
4329
+
4330
+ // Walk through the path looking for scalar-typed ancestors
4331
+ let pos = 0;
4332
+ while (true) {
4333
+ pos = key.indexOf('.', pos + 1);
4334
+ if (pos === -1) break;
4335
+ const ancestorPath = key.substring(0, pos);
4336
+ const ancestorType = tempScopeNode.schema[ancestorPath];
4337
+ if (ancestorType && isDefinitelyScalarType(ancestorType)) {
4338
+ // Found a scalar ancestor — check if the sub-property name
4339
+ // is a standalone variable in the getSchema() result
4340
+ const afterDot = key.substring(pos + 1);
4341
+ const nextSep = afterDot.search(/[.\[]/);
4342
+ const subPropName =
4343
+ nextSep === -1 ? afterDot : afterDot.substring(0, nextSep);
4344
+ if (schema[subPropName] !== undefined) {
4345
+ delete tempScopeNode.schema[key];
4346
+ break;
3631
4347
  }
3632
4348
  }
3633
4349
  }
@@ -3875,10 +4591,32 @@ export class ScopeDataStructure {
3875
4591
  return scopeText;
3876
4592
  }
3877
4593
 
3878
- getEquivalentSignatureVariables() {
4594
+ getEquivalentSignatureVariables(): Record<string, string | string[]> {
3879
4595
  const scopeNode = this.scopeNodes[this.scopeTreeManager.getRootName()];
3880
4596
 
3881
- const equivalentSignatureVariables: Record<string, string> = {};
4597
+ const equivalentSignatureVariables: Record<string, string | string[]> = {};
4598
+
4599
+ // Helper to add equivalencies - accumulates into array if multiple values for same key
4600
+ // This is critical for OR expressions like `x = a || b` where x should map to both a and b
4601
+ const addEquivalency = (key: string, value: string) => {
4602
+ const existing = equivalentSignatureVariables[key];
4603
+ if (existing === undefined) {
4604
+ // First value - store as string
4605
+ equivalentSignatureVariables[key] = value;
4606
+ } else if (typeof existing === 'string') {
4607
+ if (existing !== value) {
4608
+ // Second different value - convert to array
4609
+ equivalentSignatureVariables[key] = [existing, value];
4610
+ }
4611
+ // Same value - no change needed
4612
+ } else {
4613
+ // Already an array - add if not already present
4614
+ if (!existing.includes(value)) {
4615
+ existing.push(value);
4616
+ }
4617
+ }
4618
+ };
4619
+
3882
4620
  for (const [path, equivalentValues] of Object.entries(
3883
4621
  scopeNode.equivalencies,
3884
4622
  )) {
@@ -3887,7 +4625,7 @@ export class ScopeDataStructure {
3887
4625
  // Maps local variable names to their signature paths
3888
4626
  // e.g., "propValue" -> "signature[0].prop"
3889
4627
  if (path.startsWith('signature[')) {
3890
- equivalentSignatureVariables[equivalentValue.schemaPath] = path;
4628
+ addEquivalency(equivalentValue.schemaPath, path);
3891
4629
  }
3892
4630
 
3893
4631
  // Case 2: Hook variable equivalencies (new behavior)
@@ -3921,7 +4659,7 @@ export class ScopeDataStructure {
3921
4659
  hookCallPath = dbEntry.sourceCandidates[0].schemaPath;
3922
4660
  }
3923
4661
  }
3924
- equivalentSignatureVariables[path] = hookCallPath;
4662
+ addEquivalency(path, hookCallPath);
3925
4663
  }
3926
4664
  }
3927
4665
 
@@ -3935,10 +4673,17 @@ export class ScopeDataStructure {
3935
4673
  !equivalentValue.schemaPath.startsWith('signature[') && // not a signature path
3936
4674
  !equivalentValue.schemaPath.endsWith('.functionCallReturnValue') // not already handled above
3937
4675
  ) {
3938
- // Only add if we haven't already captured this variable in Case 1 or 2
3939
- if (!(path in equivalentSignatureVariables)) {
3940
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4676
+ // Skip bare "returnValue" from child scopes this is the child's return value,
4677
+ // not a meaningful data source path in the parent scope
4678
+ if (
4679
+ equivalentValue.schemaPath === 'returnValue' &&
4680
+ equivalentValue.scopeNodeName !==
4681
+ this.scopeTreeManager.getRootName()
4682
+ ) {
4683
+ continue;
3941
4684
  }
4685
+ // Add equivalency (will accumulate if multiple values for OR expressions)
4686
+ addEquivalency(path, equivalentValue.schemaPath);
3942
4687
  }
3943
4688
 
3944
4689
  // Case 4: Child component prop mappings (Fix 22)
@@ -3951,7 +4696,7 @@ export class ScopeDataStructure {
3951
4696
  path.includes('().signature[') &&
3952
4697
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable, not a function call
3953
4698
  ) {
3954
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4699
+ addEquivalency(path, equivalentValue.schemaPath);
3955
4700
  }
3956
4701
 
3957
4702
  // Case 5: Destructured function parameters (Fix 25)
@@ -3966,7 +4711,7 @@ export class ScopeDataStructure {
3966
4711
  !path.includes('.') && // path is a simple identifier (destructured prop name)
3967
4712
  equivalentValue.schemaPath.startsWith('signature[') // schemaPath IS a signature path
3968
4713
  ) {
3969
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4714
+ addEquivalency(path, equivalentValue.schemaPath);
3970
4715
  }
3971
4716
 
3972
4717
  // Case 7: Method calls on variables that result in .functionCallReturnValue (Fix 33)
@@ -3980,8 +4725,7 @@ export class ScopeDataStructure {
3980
4725
  if (
3981
4726
  !path.includes('.') && // path is a simple identifier
3982
4727
  equivalentValue.schemaPath.endsWith('.functionCallReturnValue') && // ends with function return
3983
- equivalentValue.schemaPath.includes('.') && // has property access (method call)
3984
- !(path in equivalentSignatureVariables) // not already captured
4728
+ equivalentValue.schemaPath.includes('.') // has property access (method call)
3985
4729
  ) {
3986
4730
  // Check if this looks like a method call on a variable (not a hook call)
3987
4731
  // Hook calls look like: hookName() or hookName<T>()
@@ -3995,7 +4739,7 @@ export class ScopeDataStructure {
3995
4739
  const parenPos = hookCallPath.indexOf('(');
3996
4740
  if (dotBeforeParen !== -1 && dotBeforeParen < parenPos) {
3997
4741
  // This is a method call like "splat.split('/')", not a hook call
3998
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4742
+ addEquivalency(path, equivalentValue.schemaPath);
3999
4743
  }
4000
4744
  }
4001
4745
  }
@@ -4026,8 +4770,9 @@ export class ScopeDataStructure {
4026
4770
  !equivalentValue.schemaPath.includes('()') // schemaPath is a simple variable
4027
4771
  ) {
4028
4772
  // Only add if not already present from the root scope
4773
+ // Root scope values take precedence over child scope values
4029
4774
  if (!(path in equivalentSignatureVariables)) {
4030
- equivalentSignatureVariables[path] = equivalentValue.schemaPath;
4775
+ addEquivalency(path, equivalentValue.schemaPath);
4031
4776
  }
4032
4777
  }
4033
4778
  }
@@ -4039,12 +4784,83 @@ export class ScopeDataStructure {
4039
4784
  // We need multiple passes because resolutions can depend on each other
4040
4785
  const maxIterations = 5; // Prevent infinite loops
4041
4786
 
4787
+ // Helper function to resolve a single source path using equivalencies
4788
+ const resolveSourcePath = (
4789
+ sourcePath: string,
4790
+ equivMap: Record<string, string | string[]>,
4791
+ ): string | null => {
4792
+ // Extract base variable from the path
4793
+ const dotIndex = sourcePath.indexOf('.');
4794
+ const bracketIndex = sourcePath.indexOf('[');
4795
+
4796
+ let baseVar: string;
4797
+ let rest: string;
4798
+
4799
+ if (dotIndex === -1 && bracketIndex === -1) {
4800
+ baseVar = sourcePath;
4801
+ rest = '';
4802
+ } else if (dotIndex === -1) {
4803
+ baseVar = sourcePath.slice(0, bracketIndex);
4804
+ rest = sourcePath.slice(bracketIndex);
4805
+ } else if (bracketIndex === -1) {
4806
+ baseVar = sourcePath.slice(0, dotIndex);
4807
+ rest = sourcePath.slice(dotIndex);
4808
+ } else {
4809
+ const firstIndex = Math.min(dotIndex, bracketIndex);
4810
+ baseVar = sourcePath.slice(0, firstIndex);
4811
+ rest = sourcePath.slice(firstIndex);
4812
+ }
4813
+
4814
+ // Look up the base variable in equivalencies
4815
+ if (baseVar in equivMap && equivMap[baseVar] !== sourcePath) {
4816
+ const baseResolved = equivMap[baseVar];
4817
+ // Skip if baseResolved is an array (handle later)
4818
+ if (Array.isArray(baseResolved)) return null;
4819
+ // If it resolves to a signature path, build the full resolved path
4820
+ if (
4821
+ baseResolved.startsWith('signature[') ||
4822
+ baseResolved.includes('()')
4823
+ ) {
4824
+ if (baseResolved.endsWith('()')) {
4825
+ return baseResolved + '.functionCallReturnValue' + rest;
4826
+ }
4827
+ return baseResolved + rest;
4828
+ }
4829
+ }
4830
+ return null;
4831
+ };
4832
+
4042
4833
  for (let iteration = 0; iteration < maxIterations; iteration++) {
4043
4834
  let changed = false;
4044
4835
 
4045
- for (const [varName, sourcePath] of Object.entries(
4836
+ for (const [varName, sourcePathOrArray] of Object.entries(
4046
4837
  equivalentSignatureVariables,
4047
4838
  )) {
4839
+ // Handle arrays (OR expressions) by resolving each element
4840
+ if (Array.isArray(sourcePathOrArray)) {
4841
+ const resolvedArray: string[] = [];
4842
+ let arrayChanged = false;
4843
+ for (const sourcePath of sourcePathOrArray) {
4844
+ // Try to resolve this path using transitive resolution
4845
+ const resolved = resolveSourcePath(
4846
+ sourcePath,
4847
+ equivalentSignatureVariables,
4848
+ );
4849
+ if (resolved && resolved !== sourcePath) {
4850
+ resolvedArray.push(resolved);
4851
+ arrayChanged = true;
4852
+ } else {
4853
+ resolvedArray.push(sourcePath);
4854
+ }
4855
+ }
4856
+ if (arrayChanged) {
4857
+ equivalentSignatureVariables[varName] = resolvedArray;
4858
+ changed = true;
4859
+ }
4860
+ continue;
4861
+ }
4862
+ const sourcePath = sourcePathOrArray;
4863
+
4048
4864
  // Skip if already fully resolved (contains function call syntax)
4049
4865
  // BUT first check for computed value patterns that need resolution (Fix 28)
4050
4866
  // AND method call patterns that need base variable resolution (Fix 33)
@@ -4106,6 +4922,8 @@ export class ScopeDataStructure {
4106
4922
  baseVar !== varName
4107
4923
  ) {
4108
4924
  const baseResolved = equivalentSignatureVariables[baseVar];
4925
+ // Skip if baseResolved is an array (OR expression)
4926
+ if (Array.isArray(baseResolved)) continue;
4109
4927
  // Only resolve if the base resolved to something useful (contains () or .)
4110
4928
  if (baseResolved.includes('()') || baseResolved.includes('.')) {
4111
4929
  const newPath = baseResolved + rest;
@@ -4170,7 +4988,12 @@ export class ScopeDataStructure {
4170
4988
  }
4171
4989
 
4172
4990
  if (baseVar in equivalentSignatureVariables && baseVar !== varName) {
4173
- const baseResolved = equivalentSignatureVariables[baseVar];
4991
+ // Handle array case (OR expressions) - use first element
4992
+ const rawBaseResolved = equivalentSignatureVariables[baseVar];
4993
+ const baseResolved = Array.isArray(rawBaseResolved)
4994
+ ? rawBaseResolved[0]
4995
+ : rawBaseResolved;
4996
+ if (!baseResolved) continue;
4174
4997
  // If the base resolves to a hook call, add .functionCallReturnValue
4175
4998
  if (baseResolved.endsWith('()')) {
4176
4999
  const newPath = baseResolved + '.functionCallReturnValue' + rest;
@@ -4260,9 +5083,109 @@ export class ScopeDataStructure {
4260
5083
  // Replace cyScope placeholders in all external function call data
4261
5084
  // This ensures call signatures and schema paths use actual callback text
4262
5085
  // instead of internal cyScope names, preventing mock data merge conflicts.
4263
- return this.externalFunctionCalls.map((efc) =>
4264
- this.cleanCyScopeFromFunctionCallInfo(efc),
4265
- );
5086
+ const rootScopeName = this.scopeTreeManager.getRootName();
5087
+ const rootSchema = this.scopeNodes[rootScopeName]?.schema ?? {};
5088
+
5089
+ return this.externalFunctionCalls.map((efc) => {
5090
+ const cleaned = this.cleanCyScopeFromFunctionCallInfo(efc);
5091
+ return this.filterConflatedExternalPaths(cleaned, rootSchema);
5092
+ });
5093
+ }
5094
+
5095
+ /**
5096
+ * Filters out conflated paths from external function call schemas.
5097
+ *
5098
+ * When multiple useState(false) calls create equivalency conflation during
5099
+ * Phase 1 analysis, standalone boolean state variables (like showWorkoutForm,
5100
+ * showGoalForm) can bleed into external function call schemas as sub-properties
5101
+ * of unrelated data fields (like data[].activity_type.showWorkoutForm).
5102
+ *
5103
+ * Detection: group sub-properties by parent path. If 2+ sub-properties of
5104
+ * the same parent all match standalone root scope variable names, treat them
5105
+ * as conflation artifacts and remove them.
5106
+ */
5107
+ private filterConflatedExternalPaths(
5108
+ efc: FunctionCallInfo,
5109
+ rootSchema: Record<string, string>,
5110
+ ): FunctionCallInfo {
5111
+ // Build a set of top-level root scope variable names (simple names, no dots/brackets)
5112
+ const topLevelRootVars = new Set<string>();
5113
+ for (const key of Object.keys(rootSchema)) {
5114
+ if (!key.includes('.') && !key.includes('[')) {
5115
+ topLevelRootVars.add(key);
5116
+ }
5117
+ }
5118
+
5119
+ if (topLevelRootVars.size === 0) return efc;
5120
+
5121
+ // Group sub-property matches by their parent path.
5122
+ // For a path like "...data[].activity_type.showWorkoutForm",
5123
+ // parent = "...data[].activity_type", child = "showWorkoutForm"
5124
+ const parentToConflatedKeys = new Map<string, string[]>();
5125
+
5126
+ for (const key of Object.keys(efc.schema)) {
5127
+ const lastDot = key.lastIndexOf('.');
5128
+ if (lastDot === -1) continue;
5129
+
5130
+ const parent = key.substring(0, lastDot);
5131
+ const child = key.substring(lastDot + 1);
5132
+
5133
+ // Skip array access or function call patterns
5134
+ if (child.includes('[') || child.includes('(')) continue;
5135
+
5136
+ // Only consider paths inside array element chains (contains []).
5137
+ // Direct children of functionCallReturnValue are legitimate destructured
5138
+ // return values, not conflation. Conflation happens deeper in the chain
5139
+ // when array element fields get corrupted sub-properties.
5140
+ if (!parent.includes('[')) continue;
5141
+
5142
+ if (topLevelRootVars.has(child)) {
5143
+ if (!parentToConflatedKeys.has(parent)) {
5144
+ parentToConflatedKeys.set(parent, []);
5145
+ }
5146
+ parentToConflatedKeys.get(parent)!.push(key);
5147
+ }
5148
+ }
5149
+
5150
+ // Only filter when 2+ sub-properties of the same parent match root scope vars.
5151
+ // This threshold avoids false positives from coincidental name matches.
5152
+ const keysToRemove = new Set<string>();
5153
+ const parentsToRestore = new Set<string>();
5154
+
5155
+ for (const [parent, conflatedKeys] of parentToConflatedKeys) {
5156
+ if (conflatedKeys.length >= 2) {
5157
+ for (const key of conflatedKeys) {
5158
+ keysToRemove.add(key);
5159
+ }
5160
+ parentsToRestore.add(parent);
5161
+ }
5162
+ }
5163
+
5164
+ if (keysToRemove.size === 0) return efc;
5165
+
5166
+ // Create a new schema without the conflated paths
5167
+ const newSchema: Record<string, string> = {};
5168
+ for (const [key, value] of Object.entries(efc.schema)) {
5169
+ if (keysToRemove.has(key)) continue;
5170
+
5171
+ // Restore parent type: if it was changed to "object" because of conflated
5172
+ // sub-properties, and now all those sub-properties are removed, change it
5173
+ // back to "unknown" (we don't know the original type)
5174
+ if (parentsToRestore.has(key) && value === 'object') {
5175
+ // Check if there are any remaining sub-properties
5176
+ const hasRemainingSubProps = Object.keys(efc.schema).some(
5177
+ (k) =>
5178
+ !keysToRemove.has(k) &&
5179
+ k !== key &&
5180
+ (k.startsWith(key + '.') || k.startsWith(key + '[')),
5181
+ );
5182
+ newSchema[key] = hasRemainingSubProps ? value : 'unknown';
5183
+ } else {
5184
+ newSchema[key] = value;
5185
+ }
5186
+ }
5187
+
5188
+ return { ...efc, schema: newSchema };
4266
5189
  }
4267
5190
 
4268
5191
  /**
@@ -4390,7 +5313,7 @@ export class ScopeDataStructure {
4390
5313
  path: string;
4391
5314
  conditionType: 'truthiness' | 'comparison' | 'switch';
4392
5315
  comparedValues?: string[];
4393
- location: 'if' | 'ternary' | 'logical-and' | 'switch';
5316
+ location: 'if' | 'ternary' | 'logical-and' | 'switch' | 'unconditional';
4394
5317
  }>
4395
5318
  >,
4396
5319
  ): void {
@@ -4555,6 +5478,10 @@ export class ScopeDataStructure {
4555
5478
  getEnrichedConditionalUsages(): Record<string, EnrichedConditionalUsage[]> {
4556
5479
  const enriched: Record<string, EnrichedConditionalUsage[]> = {};
4557
5480
 
5481
+ console.log(
5482
+ `[getEnrichedConditionalUsages] Processing ${Object.keys(this.rawConditionalUsages).length} conditional paths: [${Object.keys(this.rawConditionalUsages).join(', ')}]`,
5483
+ );
5484
+
4558
5485
  for (const [path, usages] of Object.entries(this.rawConditionalUsages)) {
4559
5486
  // Try to trace this path back to a data source
4560
5487
  // First, try the root scope
@@ -4563,10 +5490,69 @@ export class ScopeDataStructure {
4563
5490
 
4564
5491
  let sourceDataPath: string | undefined;
4565
5492
  if (explanation.source) {
4566
- // Build the full data path: scopeName.path
4567
- sourceDataPath = `${explanation.source.scope}.${explanation.source.path}`;
5493
+ const { scope, path: sourcePath } = explanation.source;
5494
+
5495
+ // Build initial path — avoid redundant prefix when path already contains the scope call
5496
+ let fullPath: string;
5497
+ if (sourcePath.startsWith(`${scope}(`)) {
5498
+ fullPath = sourcePath;
5499
+ } else {
5500
+ fullPath = `${scope}.${sourcePath}`;
5501
+ }
5502
+
5503
+ sourceDataPath = fullPath;
5504
+ console.log(
5505
+ `[getEnrichedConditionalUsages] "${path}" explainPath → scope="${scope}", sourcePath="${sourcePath}" → sourceDataPath="${sourceDataPath}"`,
5506
+ );
5507
+ } else {
5508
+ console.log(
5509
+ `[getEnrichedConditionalUsages] "${path}" explainPath → no source found`,
5510
+ );
5511
+ }
5512
+
5513
+ // If explainPath didn't find a useful external source (e.g., it traced to
5514
+ // useState or just to the component scope itself), check sourceEquivalencies
5515
+ // for an external function call source like a fetch call
5516
+ const hasExternalSource = sourceDataPath?.includes(
5517
+ '.functionCallReturnValue',
5518
+ );
5519
+ if (!hasExternalSource) {
5520
+ console.log(
5521
+ `[getEnrichedConditionalUsages] "${path}" no external source (sourceDataPath="${sourceDataPath}"), checking sourceEquivalencies fallback...`,
5522
+ );
5523
+ const sourceEquiv = this.getSourceEquivalencies();
5524
+ const returnValueKey = `returnValue.${path}`;
5525
+ const sources = sourceEquiv[returnValueKey];
5526
+ if (sources) {
5527
+ console.log(
5528
+ `[getEnrichedConditionalUsages] "${path}" sourceEquivalencies["${returnValueKey}"] has ${sources.length} sources: [${sources.map((s: { schemaPath: string }) => s.schemaPath).join(', ')}]`,
5529
+ );
5530
+ const externalSource = sources.find(
5531
+ (s: { schemaPath: string }) =>
5532
+ s.schemaPath.includes('.functionCallReturnValue') &&
5533
+ !s.schemaPath.startsWith('useState('),
5534
+ );
5535
+ if (externalSource) {
5536
+ console.log(
5537
+ `[getEnrichedConditionalUsages] "${path}" sourceEquivalencies fallback found external source: "${externalSource.schemaPath}"`,
5538
+ );
5539
+ sourceDataPath = externalSource.schemaPath;
5540
+ } else {
5541
+ console.log(
5542
+ `[getEnrichedConditionalUsages] "${path}" sourceEquivalencies fallback found no external function call source`,
5543
+ );
5544
+ }
5545
+ } else {
5546
+ console.log(
5547
+ `[getEnrichedConditionalUsages] "${path}" sourceEquivalencies["${returnValueKey}"] not found`,
5548
+ );
5549
+ }
4568
5550
  }
4569
5551
 
5552
+ console.log(
5553
+ `[getEnrichedConditionalUsages] "${path}" FINAL sourceDataPath="${sourceDataPath ?? '(none)'}" (${usages.length} usages)`,
5554
+ );
5555
+
4570
5556
  enriched[path] = usages.map((usage) => ({
4571
5557
  ...usage,
4572
5558
  sourceDataPath,
@@ -4914,11 +5900,22 @@ export class ScopeDataStructure {
4914
5900
  }
4915
5901
  }
4916
5902
 
5903
+ // Enrich the schema with inferred types by applying fillInSchemaGapsAndUnknowns.
5904
+ // This ensures the serialized schema has the same type inference as getReturnValue().
5905
+ // Without this, evidence like "entities[].analyses: array" becomes "unknown".
5906
+ const enrichedSchema = { ...efc.schema };
5907
+ const tempScopeNode = {
5908
+ name: efc.name,
5909
+ schema: enrichedSchema,
5910
+ equivalencies: efc.equivalencies ?? {},
5911
+ };
5912
+ fillInSchemaGapsAndUnknowns(tempScopeNode, true);
5913
+
4917
5914
  return {
4918
5915
  name: efc.name,
4919
5916
  callSignature: efc.callSignature,
4920
5917
  callScope: efc.callScope,
4921
- schema: efc.schema,
5918
+ schema: enrichedSchema,
4922
5919
  equivalencies: efc.equivalencies
4923
5920
  ? Object.entries(efc.equivalencies).reduce(
4924
5921
  (acc, [key, vars]) => {