@codeyam/codeyam-cli 0.1.0-staging.c90f8c9 → 0.1.0-staging.c9dc00c

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