@codeyam/codeyam-cli 0.1.0-staging.1669d45 → 0.1.0-staging.323686

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 (362) hide show
  1. package/analyzer-template/.build-info.json +8 -8
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/package.json +3 -3
  4. package/analyzer-template/packages/ai/index.ts +9 -1
  5. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +48 -34
  6. package/analyzer-template/packages/ai/src/lib/astScopes/arrayDerivationDetector.ts +199 -0
  7. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +31 -0
  8. package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +139 -23
  9. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.ts +6 -126
  10. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +277 -8
  11. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +73 -1
  12. package/analyzer-template/packages/ai/src/lib/completionCall.ts +198 -34
  13. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +108 -1
  14. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.ts +205 -0
  15. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.ts +10 -2
  16. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +23 -0
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +87 -2
  18. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +32 -7
  19. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.ts +129 -0
  20. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +156 -0
  21. package/analyzer-template/packages/ai/src/lib/e2eDataTracking.ts +334 -0
  22. package/analyzer-template/packages/ai/src/lib/extractCriticalDataKeys.ts +120 -0
  23. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +626 -6
  24. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +26 -1
  25. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +375 -6
  26. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +1003 -45
  27. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +239 -0
  28. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateChunkPrompt.ts +82 -0
  29. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateCriticalKeysPrompt.ts +103 -0
  30. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +23 -6
  31. package/analyzer-template/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.ts +391 -0
  32. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +154 -32
  33. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +22 -1
  34. package/analyzer-template/packages/ai/src/lib/worker/analyzeScopeWorker.ts +114 -2
  35. package/analyzer-template/packages/analyze/src/lib/analysisContext.ts +44 -4
  36. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +10 -13
  37. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +6 -0
  38. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +33 -7
  39. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +142 -73
  40. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +42 -5
  41. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +1 -1
  42. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +77 -0
  43. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.ts +56 -11
  44. package/analyzer-template/packages/aws/package.json +1 -1
  45. package/analyzer-template/packages/database/src/lib/kysely/db.ts +8 -1
  46. package/analyzer-template/packages/database/src/lib/kysely/tables/commitsTable.ts +6 -0
  47. package/analyzer-template/packages/database/src/lib/loadAnalyses.ts +58 -1
  48. package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +13 -0
  49. package/analyzer-template/packages/database/src/lib/loadBranch.ts +16 -1
  50. package/analyzer-template/packages/database/src/lib/loadCommit.ts +11 -0
  51. package/analyzer-template/packages/database/src/lib/loadCommits.ts +28 -0
  52. package/analyzer-template/packages/database/src/lib/loadEntities.ts +26 -3
  53. package/analyzer-template/packages/database/src/lib/loadEntityBranches.ts +12 -0
  54. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +7 -14
  55. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  56. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +8 -1
  57. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  58. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/analysesTable.d.ts.map +1 -1
  59. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts +1 -0
  60. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts.map +1 -1
  61. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js +3 -0
  62. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  63. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts +2 -0
  64. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts.map +1 -1
  65. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js +45 -2
  66. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js.map +1 -1
  67. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
  68. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +8 -0
  69. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
  70. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js +11 -1
  71. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js.map +1 -1
  72. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.d.ts.map +1 -1
  73. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js +7 -0
  74. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js.map +1 -1
  75. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts +3 -1
  76. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  77. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +22 -1
  78. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  79. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts +3 -1
  80. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  81. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +23 -4
  82. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  83. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.d.ts.map +1 -1
  84. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js +9 -0
  85. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js.map +1 -1
  86. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts +2 -2
  87. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  88. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +5 -4
  89. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  90. package/analyzer-template/packages/github/dist/types/index.d.ts +1 -1
  91. package/analyzer-template/packages/github/dist/types/index.d.ts.map +1 -1
  92. package/analyzer-template/packages/github/dist/types/index.js.map +1 -1
  93. package/analyzer-template/packages/github/dist/types/src/types/Analysis.d.ts +25 -1
  94. package/analyzer-template/packages/github/dist/types/src/types/Analysis.d.ts.map +1 -1
  95. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts +2 -0
  96. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts.map +1 -1
  97. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +51 -1
  98. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  99. package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.d.ts +9 -1
  100. package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.d.ts.map +1 -1
  101. package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.js +29 -3
  102. package/analyzer-template/packages/github/dist/utils/src/lib/safeFileName.js.map +1 -1
  103. package/analyzer-template/packages/types/index.ts +1 -0
  104. package/analyzer-template/packages/types/src/types/Analysis.ts +25 -0
  105. package/analyzer-template/packages/types/src/types/Commit.ts +2 -0
  106. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +64 -1
  107. package/analyzer-template/packages/utils/dist/types/index.d.ts +1 -1
  108. package/analyzer-template/packages/utils/dist/types/index.d.ts.map +1 -1
  109. package/analyzer-template/packages/utils/dist/types/index.js.map +1 -1
  110. package/analyzer-template/packages/utils/dist/types/src/types/Analysis.d.ts +25 -1
  111. package/analyzer-template/packages/utils/dist/types/src/types/Analysis.d.ts.map +1 -1
  112. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts +2 -0
  113. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts.map +1 -1
  114. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +51 -1
  115. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  116. package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.d.ts +9 -1
  117. package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.d.ts.map +1 -1
  118. package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.js +29 -3
  119. package/analyzer-template/packages/utils/dist/utils/src/lib/safeFileName.js.map +1 -1
  120. package/analyzer-template/packages/utils/src/lib/safeFileName.ts +48 -3
  121. package/analyzer-template/playwright/capture.ts +20 -8
  122. package/analyzer-template/playwright/captureStatic.ts +1 -1
  123. package/analyzer-template/project/analyzeBaselineCommit.ts +5 -0
  124. package/analyzer-template/project/analyzeRegularCommit.ts +5 -0
  125. package/analyzer-template/project/captureLibraryFunctionDirect.ts +29 -26
  126. package/analyzer-template/project/constructMockCode.ts +314 -29
  127. package/analyzer-template/project/createEntitiesAndSortFiles.ts +83 -0
  128. package/analyzer-template/project/loadReadyToBeCaptured.ts +65 -41
  129. package/analyzer-template/project/orchestrateCapture/AwsCaptureTaskRunner.ts +12 -4
  130. package/analyzer-template/project/orchestrateCapture/SequentialCaptureTaskRunner.ts +18 -7
  131. package/analyzer-template/project/orchestrateCapture/taskRunner.ts +4 -2
  132. package/analyzer-template/project/orchestrateCapture.ts +71 -6
  133. package/analyzer-template/project/reconcileMockDataKeys.ts +152 -9
  134. package/analyzer-template/project/runAnalysis.ts +4 -0
  135. package/analyzer-template/project/start.ts +35 -11
  136. package/analyzer-template/project/writeMockDataTsx.ts +114 -2
  137. package/analyzer-template/project/writeScenarioComponents.ts +101 -8
  138. package/analyzer-template/scripts/comboWorkerLoop.cjs +98 -50
  139. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js +5 -0
  140. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js.map +1 -1
  141. package/background/src/lib/virtualized/project/analyzeRegularCommit.js +5 -0
  142. package/background/src/lib/virtualized/project/analyzeRegularCommit.js.map +1 -1
  143. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js +3 -3
  144. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js.map +1 -1
  145. package/background/src/lib/virtualized/project/constructMockCode.js +255 -4
  146. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  147. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js +73 -1
  148. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js.map +1 -1
  149. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js +19 -8
  150. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js.map +1 -1
  151. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js +2 -2
  152. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js.map +1 -1
  153. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js +7 -5
  154. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js.map +1 -1
  155. package/background/src/lib/virtualized/project/orchestrateCapture.js +58 -6
  156. package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
  157. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +126 -9
  158. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
  159. package/background/src/lib/virtualized/project/runAnalysis.js +3 -0
  160. package/background/src/lib/virtualized/project/runAnalysis.js.map +1 -1
  161. package/background/src/lib/virtualized/project/start.js +32 -11
  162. package/background/src/lib/virtualized/project/start.js.map +1 -1
  163. package/background/src/lib/virtualized/project/writeMockDataTsx.js +89 -2
  164. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  165. package/background/src/lib/virtualized/project/writeScenarioComponents.js +57 -8
  166. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  167. package/codeyam-cli/src/cli.js +2 -0
  168. package/codeyam-cli/src/cli.js.map +1 -1
  169. package/codeyam-cli/src/commands/memory.js +273 -0
  170. package/codeyam-cli/src/commands/memory.js.map +1 -0
  171. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +4 -0
  172. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  173. package/codeyam-cli/src/utils/analysisRunner.js +21 -2
  174. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  175. package/codeyam-cli/src/utils/install-skills.js +20 -6
  176. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  177. package/codeyam-cli/src/utils/queue/job.js +1 -0
  178. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  179. package/codeyam-cli/src/utils/queue/manager.js +6 -0
  180. package/codeyam-cli/src/utils/queue/manager.js.map +1 -1
  181. package/codeyam-cli/src/utils/rules/index.js +5 -0
  182. package/codeyam-cli/src/utils/rules/index.js.map +1 -0
  183. package/codeyam-cli/src/utils/rules/parser.js +106 -0
  184. package/codeyam-cli/src/utils/rules/parser.js.map +1 -0
  185. package/codeyam-cli/src/utils/rules/pathMatcher.js +18 -0
  186. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -0
  187. package/codeyam-cli/src/utils/rules/staleness.js +132 -0
  188. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -0
  189. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +2 -0
  190. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  191. package/codeyam-cli/src/webserver/app/lib/database.js +7 -3
  192. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  193. package/codeyam-cli/src/webserver/bootstrap.js +40 -0
  194. package/codeyam-cli/src/webserver/bootstrap.js.map +1 -1
  195. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-DsN1wKrm.js +11 -0
  196. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-COi5OvsN.js → EntityTypeBadge-DLqD3qNt.js} +1 -1
  197. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-BwdQv49w.js → EntityTypeIcon-Ba2JVPzP.js} +1 -1
  198. package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-CEleMv_j.js → InlineSpinner-C8lyxW9k.js} +1 -1
  199. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-D68KarMg.js → InteractivePreview-aht4aafF.js} +2 -2
  200. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-L75Wvqgw.js → LibraryFunctionPreview-CVtiBnY5.js} +1 -1
  201. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-C53WM8qn.js → LoadingDots-B0GLXMsr.js} +1 -1
  202. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-CrNkmy4i.js → LogViewer-xgeCVgSM.js} +1 -1
  203. package/codeyam-cli/src/webserver/build/client/assets/ReportIssueModal-OApQuNyq.js +16 -0
  204. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-CQifa1n-.js → SafeScreenshot-DuDvi0jm.js} +1 -1
  205. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-CyaBFX7l.js → ScenarioViewer-DzccYyI8.js} +3 -13
  206. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-D36O1rzU.js → TruncatedFilePath-DyFZkK0l.js} +1 -1
  207. package/codeyam-cli/src/webserver/build/client/assets/_index-BwqWJOgH.js +11 -0
  208. package/codeyam-cli/src/webserver/build/client/assets/activity.(_tab)-BwavGCpm.js +32 -0
  209. package/codeyam-cli/src/webserver/build/client/assets/api.health-l0sNRNKZ.js +1 -0
  210. package/codeyam-cli/src/webserver/build/client/assets/api.memory-profile-l0sNRNKZ.js +1 -0
  211. package/codeyam-cli/src/webserver/build/client/assets/api.restart-server-l0sNRNKZ.js +1 -0
  212. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-DgTPh8H-.js → chevron-down-Cx24_aWc.js} +1 -1
  213. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-DdQKK6on.js → chunk-EPOLDU6W-CXRTFQ3F.js} +1 -1
  214. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-Dmr2bb1R.js → circle-check-BOARzkeR.js} +1 -1
  215. package/codeyam-cli/src/webserver/build/client/assets/copy-Bb-80kDT.js +6 -0
  216. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-Do4ZLUYa.js → createLucideIcon-BdhJEx6B.js} +1 -1
  217. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BBnGWYga.js +1 -0
  218. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-CbdFyxZh.js → entity._sha._-BJUiQqZF.js} +12 -12
  219. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-B4iCfs5M.js → entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js} +1 -1
  220. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-wDWZZO1W.js → entity._sha_.create-scenario-D1T4TGjf.js} +1 -1
  221. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-BMbl7MeQ.js → entity._sha_.edit._scenarioId-CTBG2mmz.js} +1 -1
  222. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-5wRKRIH9.js → entry.client-CS2cb_eZ.js} +1 -1
  223. package/codeyam-cli/src/webserver/build/client/assets/file-code-Dhef1kWN.js +6 -0
  224. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DD3SDH7t.js → fileTableUtils-DMJ7zii9.js} +1 -1
  225. package/codeyam-cli/src/webserver/build/client/assets/files-CJ6lTdTA.js +1 -0
  226. package/codeyam-cli/src/webserver/build/client/assets/{git-zXjT7J0G.js → git-CPTZZ-JZ.js} +8 -8
  227. package/codeyam-cli/src/webserver/build/client/assets/globals-D3yhhV8x.css +1 -0
  228. package/codeyam-cli/src/webserver/build/client/assets/{index-DLbXwndH.js → index-B1h680n5.js} +1 -1
  229. package/codeyam-cli/src/webserver/build/client/assets/{index-gPZ-lad1.js → index-lzqtyFU8.js} +1 -1
  230. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-BsPXJ81F.js → loader-circle-B7B9V-bu.js} +1 -1
  231. package/codeyam-cli/src/webserver/build/client/assets/manifest-7522edd4.js +1 -0
  232. package/codeyam-cli/src/webserver/build/client/assets/memory-yxFcrxBX.js +92 -0
  233. package/codeyam-cli/src/webserver/build/client/assets/root-eVAaavTS.js +62 -0
  234. package/codeyam-cli/src/webserver/build/client/assets/{search-P2FKIUql.js → search-CxXUmBSd.js} +1 -1
  235. package/codeyam-cli/src/webserver/build/client/assets/{settings-B2eDuBj8.js → settings-CS5f3WzT.js} +1 -1
  236. package/codeyam-cli/src/webserver/build/client/assets/{simulations-L18M6-kN.js → simulations-DwFIBT09.js} +1 -1
  237. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-BDz7kbVA.js → triangle-alert-B6LgvRJg.js} +1 -1
  238. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-29dDmbH8.js → useCustomSizes-C1v1PQzo.js} +1 -1
  239. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-BUm0UVJm.js → useLastLogLine-aSv48UbS.js} +1 -1
  240. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-CkIOKTrZ.js → useReportContext-DYxHZQuP.js} +1 -1
  241. package/codeyam-cli/src/webserver/build/client/assets/{useToast-KKw5kTn-.js → useToast-mBRpZPiu.js} +1 -1
  242. package/codeyam-cli/src/webserver/build/server/assets/index-DVzYx8PN.js +1 -0
  243. package/codeyam-cli/src/webserver/build/server/assets/server-build-4Cr0uToj.js +257 -0
  244. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  245. package/codeyam-cli/src/webserver/build-info.json +5 -5
  246. package/codeyam-cli/templates/codeyam-memory-hook.sh +200 -0
  247. package/codeyam-cli/templates/codeyam:debug.md +47 -3
  248. package/codeyam-cli/templates/codeyam:diagnose.md +203 -25
  249. package/codeyam-cli/templates/codeyam:memory.md +462 -0
  250. package/codeyam-cli/templates/codeyam:new-rule.md +13 -0
  251. package/package.json +8 -5
  252. package/packages/ai/index.js +5 -2
  253. package/packages/ai/index.js.map +1 -1
  254. package/packages/ai/src/lib/analyzeScope.js +41 -17
  255. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  256. package/packages/ai/src/lib/astScopes/arrayDerivationDetector.js +150 -0
  257. package/packages/ai/src/lib/astScopes/arrayDerivationDetector.js.map +1 -0
  258. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +24 -0
  259. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  260. package/packages/ai/src/lib/astScopes/methodSemantics.js +109 -23
  261. package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
  262. package/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.js +1 -102
  263. package/packages/ai/src/lib/astScopes/patterns/variableDeclarationHandler.js.map +1 -1
  264. package/packages/ai/src/lib/astScopes/processExpression.js +228 -11
  265. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  266. package/packages/ai/src/lib/completionCall.js +161 -30
  267. package/packages/ai/src/lib/completionCall.js.map +1 -1
  268. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +86 -1
  269. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  270. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.js +179 -0
  271. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/MuiManager.js.map +1 -1
  272. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.js +7 -1
  273. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/ReactFrameworkManager.js.map +1 -1
  274. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +19 -0
  275. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  276. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +70 -2
  277. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  278. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +29 -7
  279. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  280. package/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.js +107 -0
  281. package/packages/ai/src/lib/dataStructure/helpers/fixNullIdsBySchema.js.map +1 -0
  282. package/packages/ai/src/lib/dataStructureChunking.js +111 -0
  283. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -0
  284. package/packages/ai/src/lib/e2eDataTracking.js +241 -0
  285. package/packages/ai/src/lib/e2eDataTracking.js.map +1 -0
  286. package/packages/ai/src/lib/extractCriticalDataKeys.js +96 -0
  287. package/packages/ai/src/lib/extractCriticalDataKeys.js.map +1 -0
  288. package/packages/ai/src/lib/generateEntityScenarioData.js +510 -7
  289. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  290. package/packages/ai/src/lib/generateEntityScenarios.js +19 -1
  291. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  292. package/packages/ai/src/lib/generateExecutionFlows.js +273 -4
  293. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  294. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +738 -40
  295. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  296. package/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.js +194 -0
  297. package/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.js.map +1 -0
  298. package/packages/ai/src/lib/promptGenerators/generateChunkPrompt.js +54 -0
  299. package/packages/ai/src/lib/promptGenerators/generateChunkPrompt.js.map +1 -0
  300. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +15 -7
  301. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  302. package/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.js +335 -0
  303. package/packages/ai/src/lib/promptGenerators/simplifyKeysForLLM.js.map +1 -0
  304. package/packages/ai/src/lib/resolvePathToControllable.js +131 -27
  305. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
  306. package/packages/ai/src/lib/worker/SerializableDataStructure.js +7 -0
  307. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  308. package/packages/ai/src/lib/worker/analyzeScopeWorker.js +94 -1
  309. package/packages/ai/src/lib/worker/analyzeScopeWorker.js.map +1 -1
  310. package/packages/analyze/src/lib/analysisContext.js +30 -5
  311. package/packages/analyze/src/lib/analysisContext.js.map +1 -1
  312. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +8 -4
  313. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  314. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +5 -0
  315. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  316. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +31 -7
  317. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  318. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +116 -66
  319. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  320. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +37 -5
  321. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  322. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +1 -1
  323. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  324. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +65 -0
  325. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  326. package/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.js +46 -9
  327. package/packages/analyze/src/lib/files/scenarios/mergeValidatedDataStructures.js.map +1 -1
  328. package/packages/database/src/lib/kysely/db.js +8 -1
  329. package/packages/database/src/lib/kysely/db.js.map +1 -1
  330. package/packages/database/src/lib/kysely/tables/commitsTable.js +3 -0
  331. package/packages/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  332. package/packages/database/src/lib/loadAnalyses.js +45 -2
  333. package/packages/database/src/lib/loadAnalyses.js.map +1 -1
  334. package/packages/database/src/lib/loadAnalysis.js +8 -0
  335. package/packages/database/src/lib/loadAnalysis.js.map +1 -1
  336. package/packages/database/src/lib/loadBranch.js +11 -1
  337. package/packages/database/src/lib/loadBranch.js.map +1 -1
  338. package/packages/database/src/lib/loadCommit.js +7 -0
  339. package/packages/database/src/lib/loadCommit.js.map +1 -1
  340. package/packages/database/src/lib/loadCommits.js +22 -1
  341. package/packages/database/src/lib/loadCommits.js.map +1 -1
  342. package/packages/database/src/lib/loadEntities.js +23 -4
  343. package/packages/database/src/lib/loadEntities.js.map +1 -1
  344. package/packages/database/src/lib/loadEntityBranches.js +9 -0
  345. package/packages/database/src/lib/loadEntityBranches.js.map +1 -1
  346. package/packages/database/src/lib/updateCommitMetadata.js +5 -4
  347. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  348. package/packages/types/index.js.map +1 -1
  349. package/packages/utils/src/lib/safeFileName.js +29 -3
  350. package/packages/utils/src/lib/safeFileName.js.map +1 -1
  351. package/scripts/finalize-analyzer.cjs +3 -3
  352. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-vauWK972.js +0 -1
  353. package/codeyam-cli/src/webserver/build/client/assets/ReportIssueModal-DzJRkCkr.js +0 -11
  354. package/codeyam-cli/src/webserver/build/client/assets/_index-Be83mo_j.js +0 -11
  355. package/codeyam-cli/src/webserver/build/client/assets/activity.(_tab)-BN6wu6Y-.js +0 -37
  356. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-Bn6aCAy_.js +0 -1
  357. package/codeyam-cli/src/webserver/build/client/assets/files-DKyMFI90.js +0 -1
  358. package/codeyam-cli/src/webserver/build/client/assets/globals-DTTQ3gY7.css +0 -1
  359. package/codeyam-cli/src/webserver/build/client/assets/manifest-22590fcf.js +0 -1
  360. package/codeyam-cli/src/webserver/build/client/assets/root-BsAarjAM.js +0 -57
  361. package/codeyam-cli/src/webserver/build/server/assets/index-BND5I5fv.js +0 -1
  362. package/codeyam-cli/src/webserver/build/server/assets/server-build-CFXnd7MG.js +0 -228
@@ -39,6 +39,203 @@ export class MuiManager implements EquivalencyManager {
39
39
 
40
40
  // Also check if this scope is inside a DataGrid callback and propagate row property accesses
41
41
  this.propagateFromChildScope(scopeNode, scopeDataStructure);
42
+
43
+ // NOTE: processGridApiContext, processCreateTheme, and processGridSelector
44
+ // are now called from finalize() instead of here.
45
+ // This is because external function calls are only added AFTER postProcess()
46
+ // runs (in trackFunctionCalls), so getExternalFunctionCallInfo() would return
47
+ // undefined during postProcess(). See Issue 23.
48
+ }
49
+
50
+ /**
51
+ * Handle useGridApiContext() calls by adding the expected apiRef structure to the schema.
52
+ *
53
+ * useGridApiContext() returns an apiRef that has internal state used by useGridSelector.
54
+ * When useGridSelector(apiRef, selector) is called, it accesses apiRef.current.state
55
+ * to extract data like filterModel, sortModel, etc.
56
+ *
57
+ * We add the state structure directly to the external function call's schema
58
+ * to ensure mocks include the necessary paths.
59
+ */
60
+ private processGridApiContext(
61
+ _scopeNode: ScopeNode,
62
+ scopeDataStructure: ScopeDataStructure,
63
+ ) {
64
+ // Find the external function call for useGridApiContext
65
+ const gridApiContextCall =
66
+ scopeDataStructure.getExternalFunctionCallInfo('useGridApiContext');
67
+
68
+ if (!gridApiContextCall) {
69
+ return;
70
+ }
71
+
72
+ // Add the state structure that useGridSelector needs to the external function call's schema
73
+ // useGridSelector reads from apiRef.current.state internally
74
+ // gridFilterModelSelector reads state.filter.filterModel
75
+ const basePath = 'useGridApiContext().functionCallReturnValue.current';
76
+ const statePaths: Record<string, string> = {
77
+ [`${basePath}.state`]: 'object',
78
+ [`${basePath}.state.filter`]: 'object',
79
+ [`${basePath}.state.filter.filterModel`]: 'object',
80
+ [`${basePath}.state.filter.filterModel.items`]: 'array',
81
+ // Also add common state paths that might be needed by other selectors
82
+ [`${basePath}.state.sorting`]: 'object',
83
+ [`${basePath}.state.sorting.sortModel`]: 'array',
84
+ [`${basePath}.state.pagination`]: 'object',
85
+ [`${basePath}.state.pagination.paginationModel`]: 'object',
86
+ [`${basePath}.state.pagination.paginationModel.page`]: 'number',
87
+ [`${basePath}.state.pagination.paginationModel.pageSize`]: 'number',
88
+ [`${basePath}.state.rows`]: 'object',
89
+ [`${basePath}.state.rows.dataRowIds`]: 'array',
90
+ [`${basePath}.state.columns`]: 'object',
91
+ [`${basePath}.state.columns.all`]: 'array',
92
+ };
93
+
94
+ // Add each path to the external function call's schema if it doesn't exist
95
+ for (const [path, type] of Object.entries(statePaths)) {
96
+ if (!gridApiContextCall.schema[path]) {
97
+ gridApiContextCall.schema[path] = type;
98
+ }
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Handle createTheme() calls by adding required MUI theme properties to the schema.
104
+ *
105
+ * MUI's ThemeProvider and related components check for specific properties:
106
+ * - `'$$material' in theme` - validates it's a MUI theme object
107
+ * - `'colorSchemes' in theme` - checks for color scheme support (MUI v6+)
108
+ *
109
+ * Without these properties, ThemeProvider throws:
110
+ * "TypeError: Cannot use 'in' operator to search for '$$material' in object"
111
+ * "TypeError: Cannot use 'in' operator to search for 'colorSchemes' in true"
112
+ *
113
+ * We add these properties to the createTheme return value schema
114
+ * to ensure mocks include the necessary properties.
115
+ */
116
+ private processCreateTheme(
117
+ _scopeNode: ScopeNode,
118
+ scopeDataStructure: ScopeDataStructure,
119
+ ) {
120
+ // Find the external function call for createTheme
121
+ const createThemeCall =
122
+ scopeDataStructure.getExternalFunctionCallInfo('createTheme');
123
+
124
+ if (!createThemeCall) {
125
+ return;
126
+ }
127
+
128
+ // Use the actual call signature to construct the path
129
+ // createTheme can be called with various arguments:
130
+ // - createTheme()
131
+ // - createTheme(options)
132
+ // - createTheme(getTheme(false), { components: {} })
133
+ const callSignature = createThemeCall.callSignature;
134
+ const basePath = `${callSignature}.functionCallReturnValue`;
135
+
136
+ // Add required MUI theme properties
137
+ const themeProperties: Record<string, string> = {
138
+ [`${basePath}.$$material`]: 'boolean',
139
+ [`${basePath}.colorSchemes`]: 'object',
140
+ };
141
+
142
+ for (const [path, type] of Object.entries(themeProperties)) {
143
+ if (!createThemeCall.schema[path]) {
144
+ createThemeCall.schema[path] = type;
145
+ }
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Handle useGridSelector(apiRef, selector) calls by adding return value schema.
151
+ *
152
+ * useGridSelector is a MUI X Data Grid hook that extracts data from the grid's
153
+ * internal state using a selector function. It's unique because:
154
+ * 1. It takes arguments (apiRef and selector), so it's not automatically mocked
155
+ * 2. But its return value depends on which selector is used
156
+ * 3. The selector reads from apiRef.current.state
157
+ *
158
+ * Common selectors and their return types:
159
+ * - gridFilterModelSelector -> { items: GridFilterItem[] }
160
+ * - gridSortModelSelector -> GridSortItem[]
161
+ * - gridPaginationModelSelector -> { page: number, pageSize: number }
162
+ * - gridRowCountSelector -> number
163
+ *
164
+ * We detect which selector is used from the call signature and add the
165
+ * appropriate return value schema.
166
+ */
167
+ private processGridSelector(
168
+ _scopeNode: ScopeNode,
169
+ scopeDataStructure: ScopeDataStructure,
170
+ ) {
171
+ // Find external function calls for useGridSelector
172
+ const gridSelectorCall =
173
+ scopeDataStructure.getExternalFunctionCallInfo('useGridSelector');
174
+
175
+ if (!gridSelectorCall) {
176
+ return;
177
+ }
178
+
179
+ const callSignature = gridSelectorCall.callSignature;
180
+ const basePath = `${callSignature}.functionCallReturnValue`;
181
+
182
+ // Determine which selector is being used and add appropriate schema
183
+ if (callSignature.includes('gridFilterModelSelector')) {
184
+ // gridFilterModelSelector returns { items: GridFilterItem[] }
185
+ const filterPaths: Record<string, string> = {
186
+ [basePath]: 'object',
187
+ [`${basePath}.items`]: 'array',
188
+ [`${basePath}.items[]`]: 'object',
189
+ [`${basePath}.items[].field`]: 'string',
190
+ [`${basePath}.items[].operator`]: 'string',
191
+ [`${basePath}.items[].value`]: 'array',
192
+ [`${basePath}.items[].value[]`]: 'string',
193
+ };
194
+
195
+ for (const [path, type] of Object.entries(filterPaths)) {
196
+ if (!gridSelectorCall.schema[path]) {
197
+ gridSelectorCall.schema[path] = type;
198
+ }
199
+ }
200
+ } else if (callSignature.includes('gridSortModelSelector')) {
201
+ // gridSortModelSelector returns GridSortItem[]
202
+ const sortPaths: Record<string, string> = {
203
+ [basePath]: 'array',
204
+ [`${basePath}[]`]: 'object',
205
+ [`${basePath}[].field`]: 'string',
206
+ [`${basePath}[].sort`]: 'string',
207
+ };
208
+
209
+ for (const [path, type] of Object.entries(sortPaths)) {
210
+ if (!gridSelectorCall.schema[path]) {
211
+ gridSelectorCall.schema[path] = type;
212
+ }
213
+ }
214
+ } else if (callSignature.includes('gridPaginationModelSelector')) {
215
+ // gridPaginationModelSelector returns { page: number, pageSize: number }
216
+ const paginationPaths: Record<string, string> = {
217
+ [basePath]: 'object',
218
+ [`${basePath}.page`]: 'number',
219
+ [`${basePath}.pageSize`]: 'number',
220
+ };
221
+
222
+ for (const [path, type] of Object.entries(paginationPaths)) {
223
+ if (!gridSelectorCall.schema[path]) {
224
+ gridSelectorCall.schema[path] = type;
225
+ }
226
+ }
227
+ } else if (callSignature.includes('gridRowCountSelector')) {
228
+ // gridRowCountSelector returns number
229
+ if (!gridSelectorCall.schema[basePath]) {
230
+ gridSelectorCall.schema[basePath] = 'number';
231
+ }
232
+ } else {
233
+ // Unknown selector - add generic object return type
234
+ // This ensures the hook is at least mocked with some structure
235
+ if (!gridSelectorCall.schema[basePath]) {
236
+ gridSelectorCall.schema[basePath] = 'object';
237
+ }
238
+ }
42
239
  }
43
240
 
44
241
  private processDataGridCallbacks(
@@ -662,6 +859,14 @@ export class MuiManager implements EquivalencyManager {
662
859
  }
663
860
 
664
861
  finalize(_scopeNode: ScopeNode, scopeDataStructure: ScopeDataStructure) {
862
+ // Process external function call schemas ONCE (not per-scope) since they
863
+ // are global. These were moved from postProcess() because external function
864
+ // calls are only available AFTER postProcess() runs (in trackFunctionCalls).
865
+ // See Issue 23.
866
+ this.processGridApiContext(_scopeNode, scopeDataStructure);
867
+ this.processCreateTheme(_scopeNode, scopeDataStructure);
868
+ this.processGridSelector(_scopeNode, scopeDataStructure);
869
+
665
870
  // Iterate through all scopes (finalize is only called on root)
666
871
  for (const [scopeName, scopeNode] of Object.entries(
667
872
  scopeDataStructure.scopeNodes,
@@ -239,10 +239,18 @@ export class ReactFrameworkManager implements EquivalencyManager {
239
239
  });
240
240
  }
241
241
 
242
+ // Get the initial value path (what signature[0] is equivalent to)
243
+ const initialValuePath = equivalentValues[0].schemaPath;
244
+ const initialValueScopeName = equivalentValues[0].scopeNodeName;
245
+
246
+ // Note: Callback scope tracing (for useState(() => { return prop; }))
247
+ // is handled in getEquivalentSignatureVariables() where the full
248
+ // equivalency database is available for deep tracing.
249
+
242
250
  scopeDataStructure.addEquivalency(
243
251
  relevantUseStateInfo.value,
244
- equivalentValues[0].schemaPath,
245
- scopeNode.name,
252
+ initialValuePath,
253
+ initialValueScopeName,
246
254
  scopeNode,
247
255
  'useState value equivalency',
248
256
  );
@@ -35,6 +35,29 @@ const getParts = (path: string): string[] => {
35
35
  return parts;
36
36
  };
37
37
 
38
+ /**
39
+ * Clear the module-level cache.
40
+ * Call this between entity analyses to prevent unbounded memory growth.
41
+ */
42
+ export function clearCleanKnownObjectFunctionsCache(): {
43
+ count: number;
44
+ estimatedBytes: number;
45
+ } {
46
+ let totalBytes = 0;
47
+ for (const [key, value] of partsCache) {
48
+ // Key is a string, value is string[] - estimate UTF-16 encoding (2 bytes per char)
49
+ totalBytes += key.length * 2;
50
+ for (const part of value) {
51
+ totalBytes += part.length * 2;
52
+ }
53
+ // Add overhead for array and Map entry (~50 bytes per entry)
54
+ totalBytes += 50;
55
+ }
56
+ const count = partsCache.size;
57
+ partsCache.clear();
58
+ return { count, estimatedBytes: totalBytes };
59
+ }
60
+
38
61
  /** pre-compute the prototype-method sets once per module load */
39
62
  const protoMethodSets: Record<PrimitiveKind, Set<string>> = {
40
63
  array: new Set(
@@ -119,6 +119,17 @@ const stringMethodsSet = new Set([
119
119
  ]);
120
120
  export const allMethodsSet = new Set([...arrayMethodsSet, ...stringMethodsSet]);
121
121
 
122
+ // Methods that exist in both stringMethodsSet and arrayMethodsSet.
123
+ // When ONLY these methods are called on an object, we can't determine if it's a string or array.
124
+ // Don't infer 'string' type from these alone - leave as 'unknown' for other type resolution.
125
+ const stringArrayAmbiguousMethodsSet = new Set([
126
+ 'includes', // exists in both String.includes() and Array.includes()
127
+ 'indexOf', // exists in both String.indexOf() and Array.indexOf()
128
+ 'lastIndexOf', // exists in both String.lastIndexOf() and Array.lastIndexOf()
129
+ 'concat', // exists in both String.concat() and Array.concat()
130
+ 'slice', // exists in both String.slice() and Array.slice()
131
+ ]);
132
+
122
133
  const signatureKeyWord = 'signature';
123
134
  const returnValueKeyWord = 'functionCallReturnValue';
124
135
 
@@ -140,6 +151,29 @@ function cachedSplit(str: string): string[] {
140
151
  return parts;
141
152
  }
142
153
 
154
+ /**
155
+ * Clear the module-level cache.
156
+ * Call this between entity analyses to prevent unbounded memory growth.
157
+ */
158
+ export function clearCleanNonObjectFunctionsCache(): {
159
+ count: number;
160
+ estimatedBytes: number;
161
+ } {
162
+ let totalBytes = 0;
163
+ for (const [key, value] of splitCache) {
164
+ // Key is a string, value is string[] - estimate UTF-16 encoding (2 bytes per char)
165
+ totalBytes += key.length * 2;
166
+ for (const part of value) {
167
+ totalBytes += part.length * 2;
168
+ }
169
+ // Add overhead for array and Map entry (~50 bytes per entry)
170
+ totalBytes += 50;
171
+ }
172
+ const count = splitCache.size;
173
+ splitCache.clear();
174
+ return { count, estimatedBytes: totalBytes };
175
+ }
176
+
143
177
  // --- Prefix Index for O(1) lookup in subPathIsFromKnownObject ---
144
178
  // Maps parent prefix -> array of last parts (method names without parens)
145
179
  type PrefixIndex = Map<string, string[]>;
@@ -697,7 +731,14 @@ function handleFunctionMapping(
697
731
  allProperties.every((prop) => stringMethodsSet.has(getMethodName(prop)))
698
732
  ) {
699
733
  if (allProperties.every((prop) => isValidStringMethod(prop))) {
700
- keyMapping[previousPath] = 'string';
734
+ // Don't infer string if ALL methods are ambiguous between string and array
735
+ // (like includes, indexOf, concat, slice - these exist on both types)
736
+ const hasOnlyStringArrayAmbiguousMethods = allProperties.every(
737
+ (prop) => stringArrayAmbiguousMethodsSet.has(getMethodName(prop)),
738
+ );
739
+ if (!hasOnlyStringArrayAmbiguousMethods) {
740
+ keyMapping[previousPath] = 'string';
741
+ }
701
742
  } else {
702
743
  return false;
703
744
  }
@@ -718,19 +759,36 @@ function handleFunctionMapping(
718
759
 
719
760
  // Don't add [] element for ambiguous methods without other array evidence
720
761
  // Also don't add [] if the path was already identified as a string type
762
+ // Also don't add [] if the method is ambiguous between string and array (like includes)
721
763
  const methodName = getMethodName(lastPart);
722
764
  const isAmbiguousMethod = ambiguousArrayMethodsSet.has(methodName);
765
+ const isStringArrayAmbiguous =
766
+ stringArrayAmbiguousMethodsSet.has(methodName);
723
767
  const isStringType = keyMapping[previousPath] === 'string';
724
768
  if (
725
769
  !isValidFunctionCall(previousPart) &&
726
770
  arrayMethodsSet.has(methodName) &&
727
771
  !keyMapping[previousPath + '[]'] &&
728
772
  !isAmbiguousMethod &&
773
+ !isStringArrayAmbiguous &&
729
774
  !isStringType
730
775
  ) {
731
776
  keyMapping[previousPath + '[]'] = 'unknown';
732
777
  }
733
778
 
779
+ // For primitive-returning methods (like includes, indexOf, some, every),
780
+ // also delete the .functionCallReturnValue children since the return value
781
+ // is just a primitive (boolean/number) and not useful data.
782
+ // For other methods (like filter, map), keep children for transformation.
783
+ const isPrimitiveReturning = primitiveReturningMethodsSet.has(methodName);
784
+ if (isPrimitiveReturning) {
785
+ for (const otherPath of Object.keys(keyMapping)) {
786
+ if (otherPath.startsWith(path + '.')) {
787
+ delete keyMapping[otherPath];
788
+ }
789
+ }
790
+ }
791
+
734
792
  delete keyMapping[path];
735
793
  return true;
736
794
  }
@@ -956,14 +1014,34 @@ function clearAttributes(
956
1014
  }
957
1015
  }
958
1016
 
1017
+ // Track paths that have primitive-returning method calls (like includes, some, every)
1018
+ // These need cleanup even if we can't determine the base type
1019
+ const pathsWithPrimitiveReturningMethods = new Set<string>();
1020
+
959
1021
  for (const key in functionCallsOnObjects) {
960
1022
  const functionCalls = functionCallsOnObjects[key];
1023
+
1024
+ // Check if any method calls are primitive-returning
1025
+ const hasPrimitiveReturningMethods = functionCalls.some((f) =>
1026
+ primitiveReturningMethodsSet.has(getMethodName(f)),
1027
+ );
1028
+ if (hasPrimitiveReturningMethods) {
1029
+ pathsWithPrimitiveReturningMethods.add(key);
1030
+ }
1031
+
961
1032
  if (
962
1033
  functionCalls.every(
963
1034
  (f) => stringMethodsSet.has(getMethodName(f)) && isValidStringMethod(f),
964
1035
  )
965
1036
  ) {
966
- mapping[key] = 'string';
1037
+ // Don't infer string if ALL methods are ambiguous between string and array
1038
+ // (like includes, indexOf, concat, slice - these exist on both types)
1039
+ const hasOnlyStringArrayAmbiguousMethods = functionCalls.every((f) =>
1040
+ stringArrayAmbiguousMethodsSet.has(getMethodName(f)),
1041
+ );
1042
+ if (!hasOnlyStringArrayAmbiguousMethods) {
1043
+ mapping[key] = 'string';
1044
+ }
967
1045
  } else if (
968
1046
  functionCalls.every(
969
1047
  (f) => arrayMethodsSet.has(getMethodName(f)) && isValidArrayMethod(f),
@@ -1000,6 +1078,13 @@ function clearAttributes(
1000
1078
  }
1001
1079
  }
1002
1080
 
1081
+ // Also add paths with primitive-returning method calls (like includes, some, every)
1082
+ // to knownBasePaths so their method call paths get cleaned up, even if we couldn't
1083
+ // determine the base type (e.g., when only ambiguous methods like includes are used)
1084
+ for (const path of pathsWithPrimitiveReturningMethods) {
1085
+ knownBasePaths.add(path);
1086
+ }
1087
+
1003
1088
  for (const key in mapping) {
1004
1089
  const keyParts = cachedSplit(key);
1005
1090
  for (const basePath of knownBasePaths) {
@@ -486,6 +486,17 @@ const STRONG_ARRAY_METHODS = new Set([
486
486
  'with',
487
487
  ]);
488
488
 
489
+ /**
490
+ * Check if a method call argument looks like a string literal.
491
+ * String literals start with ' or " (e.g., includes('foo'), indexOf("bar"))
492
+ */
493
+ function hasStringLiteralArgument(methodCall: string): boolean {
494
+ const parenIndex = methodCall.indexOf('(');
495
+ if (parenIndex === -1) return false;
496
+ const arg = methodCall.slice(parenIndex + 1).trim();
497
+ return arg.startsWith("'") || arg.startsWith('"') || arg.startsWith('`');
498
+ }
499
+
489
500
  function checkIfKnownType(
490
501
  key: string,
491
502
  functionAndAttributesKeysMapping: Record<string, string[]>,
@@ -496,6 +507,7 @@ function checkIfKnownType(
496
507
  let hasOnlyAmbiguousArrayMethods = true;
497
508
  let hasLengthAccess = false;
498
509
  let hasArrayStringAmbiguousMethod = false;
510
+ let hasIncludesOrIndexOfWithVariable = false;
499
511
 
500
512
  for (const functionOrAttributeName of functionAndAttributesKeysMapping[key] ??
501
513
  []) {
@@ -519,6 +531,17 @@ function checkIfKnownType(
519
531
  hasArrayStringAmbiguousMethod = true;
520
532
  }
521
533
 
534
+ // Check if .includes() or .indexOf() is called with a variable argument (not a string literal).
535
+ // Pattern: arr.includes(item) -> likely array (checking if item exists)
536
+ // Pattern: str.includes('substring') -> likely string (checking for substring)
537
+ if (
538
+ (methodName === 'includes' || methodName === 'indexOf') &&
539
+ functionOrAttributeName.includes('(') &&
540
+ !hasStringLiteralArgument(functionOrAttributeName)
541
+ ) {
542
+ hasIncludesOrIndexOfWithVariable = true;
543
+ }
544
+
522
545
  // Check if this is strong evidence of an array (unambiguous array methods)
523
546
  if (STRONG_ARRAY_METHODS.has(methodName)) {
524
547
  hasStrongArrayEvidence = true;
@@ -549,18 +572,20 @@ function checkIfKnownType(
549
572
  return 'array';
550
573
  }
551
574
 
552
- // When we have BOTH .length AND an ambiguous method like .includes(),
553
- // prefer array. This pattern (checking .length AND calling .includes)
554
- // is very common with arrays (e.g., arr.length > 0 && arr.includes(x))
555
- // but rare with strings (you'd typically just call str.includes(x))
556
- if (isArray && hasLengthAccess && hasArrayStringAmbiguousMethod) {
575
+ // When .includes() or .indexOf() is called with a variable argument AND we have .length,
576
+ // prefer array. This pattern (arr.length > 0 && arr.includes(item)) is common for arrays.
577
+ // But str.includes('literal') is common for strings - that case is handled by hasStringLiteralArgument.
578
+ if (isArray && hasLengthAccess && hasIncludesOrIndexOfWithVariable) {
557
579
  return 'array';
558
580
  }
559
581
 
582
+ // When both array and string are possible, prefer string.
583
+ // Strings have .length, .slice(), .includes(), etc. just like arrays.
584
+ // We only infer 'array' if we have STRONG evidence (like .map, .filter, .reduce).
560
585
  if (isString) return 'string';
561
586
 
562
- // Only infer array if we have strong evidence OR not only ambiguous methods
563
- // This prevents router.push() from being incorrectly inferred as an array
587
+ // Only infer array if we have strong evidence (already handled above)
588
+ // or non-ambiguous array methods that don't exist on strings
564
589
  if (isArray && !hasOnlyAmbiguousArrayMethods) {
565
590
  return 'array';
566
591
  }
@@ -0,0 +1,129 @@
1
+ import { awsLog } from '~codeyam/utils';
2
+
3
+ /**
4
+ * Fixes null values for ID fields when the schema indicates they should be non-null numbers.
5
+ *
6
+ * The LLM sometimes generates `null` for ID fields (e.g., `"id": null`) when the schema
7
+ * type is `"number"` or `"number | undefined"` (but NOT `"number | null"`). This causes
8
+ * runtime issues when code checks `if (!data?.id)` expecting a truthy value.
9
+ *
10
+ * This function traverses data and schema together:
11
+ * - If field name looks like an ID field AND value is null AND schema doesn't allow null,
12
+ * replace with a valid default value (1 for numbers, generated UUID for strings)
13
+ *
14
+ * @param data The data object with potential null ID values
15
+ * @param schema The schema describing expected types
16
+ * @param path Current path in the data structure (for logging)
17
+ * @returns The data with null IDs fixed (mutates original)
18
+ */
19
+ export default function fixNullIdsBySchema<T>(
20
+ data: T,
21
+ schema: unknown,
22
+ path: string = '',
23
+ ): T {
24
+ // Handle null/undefined data
25
+ if (data === null || data === undefined) {
26
+ return data;
27
+ }
28
+
29
+ // Only process objects
30
+ if (typeof data !== 'object') {
31
+ return data;
32
+ }
33
+
34
+ // Handle arrays
35
+ if (Array.isArray(data)) {
36
+ // For arrays, the schema should be an array with one element describing the item type
37
+ const itemSchema = Array.isArray(schema) ? schema[0] : undefined;
38
+ for (let i = 0; i < data.length; i++) {
39
+ data[i] = fixNullIdsBySchema(data[i], itemSchema, `${path}[${i}]`);
40
+ }
41
+ return data;
42
+ }
43
+
44
+ // Handle objects
45
+ const dataObj = data as Record<string, unknown>;
46
+ const schemaObj = schema as Record<string, unknown> | undefined;
47
+
48
+ for (const key of Object.keys(dataObj)) {
49
+ const value = dataObj[key];
50
+ const fieldSchema = schemaObj?.[key];
51
+ const fieldPath = path ? `${path}.${key}` : key;
52
+
53
+ if (value === null && isIdField(key)) {
54
+ // Check if schema indicates this should be a non-null number
55
+ const replacement = getIdReplacementValue(fieldSchema);
56
+ if (replacement !== null) {
57
+ dataObj[key] = replacement;
58
+ awsLog(
59
+ `CodeYam: Fixed null ID field "${fieldPath}": null -> ${replacement}`,
60
+ );
61
+ }
62
+ } else if (typeof value === 'object' && value !== null) {
63
+ // Recursively process nested objects/arrays
64
+ fixNullIdsBySchema(value, fieldSchema, fieldPath);
65
+ }
66
+ }
67
+
68
+ return data;
69
+ }
70
+
71
+ /**
72
+ * Pattern for field names that are likely ID fields.
73
+ * Matches: id, Id, ID, userId, user_id, quoteId, quote_id, etc.
74
+ */
75
+ const ID_FIELD_PATTERNS = [
76
+ /^id$/i, // Exact match for "id", "Id", "ID"
77
+ /Id$/, // Ends with "Id" (camelCase): userId, quoteId
78
+ /_id$/i, // Ends with "_id" (snake_case): user_id, quote_id
79
+ /^.*_id$/i, // Contains "_id": some_object_id
80
+ ];
81
+
82
+ /**
83
+ * Determines if a field name looks like an ID field.
84
+ */
85
+ function isIdField(fieldName: string): boolean {
86
+ return ID_FIELD_PATTERNS.some((pattern) => pattern.test(fieldName));
87
+ }
88
+
89
+ /**
90
+ * Gets the replacement value for a null ID based on schema type.
91
+ * Returns null if the schema allows null values (no replacement needed).
92
+ *
93
+ * @param fieldSchema The schema type for the field
94
+ * @returns Replacement value (1 for numbers, generated string for strings) or null if no replacement
95
+ */
96
+ function getIdReplacementValue(fieldSchema: unknown): number | string | null {
97
+ // If no schema for this field, be conservative - don't replace
98
+ if (fieldSchema === undefined || fieldSchema === null) {
99
+ return null;
100
+ }
101
+
102
+ // If schema is a string type definition
103
+ if (typeof fieldSchema === 'string') {
104
+ // If schema explicitly allows null, don't replace
105
+ if (fieldSchema.includes('null')) {
106
+ return null;
107
+ }
108
+
109
+ // If schema is a number type, return 1 as default
110
+ if (
111
+ fieldSchema === 'number' ||
112
+ fieldSchema.startsWith('number') ||
113
+ fieldSchema.includes('number')
114
+ ) {
115
+ return 1;
116
+ }
117
+
118
+ // If schema is a string type, return a generated ID
119
+ if (
120
+ fieldSchema === 'string' ||
121
+ fieldSchema.startsWith('string') ||
122
+ fieldSchema.includes('string')
123
+ ) {
124
+ return 'id-1';
125
+ }
126
+ }
127
+
128
+ return null;
129
+ }