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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (563) hide show
  1. package/analyzer-template/.build-info.json +7 -7
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/package.json +8 -8
  4. package/analyzer-template/packages/ai/index.ts +11 -2
  5. package/analyzer-template/packages/ai/package.json +2 -2
  6. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +100 -18
  7. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +67 -9
  8. package/analyzer-template/packages/ai/src/lib/astScopes/methodSemantics.ts +41 -17
  9. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  10. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +409 -50
  11. package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
  12. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +21 -6
  13. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +1007 -249
  14. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
  15. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +16 -3
  16. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +6 -4
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +54 -3
  18. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +60 -15
  19. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
  20. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +140 -14
  21. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +179 -0
  22. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.ts +40 -30
  23. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +393 -97
  24. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +33 -15
  25. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
  26. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +315 -6
  27. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +9 -5
  28. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +49 -5
  29. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
  30. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +649 -142
  31. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +1 -1
  32. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
  33. package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
  34. package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
  35. package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
  36. package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
  37. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
  38. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +25 -13
  39. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +4 -3
  40. package/analyzer-template/packages/ai/src/lib/worker/analyzeScopeWorker.ts +114 -2
  41. package/analyzer-template/packages/analyze/index.ts +2 -0
  42. package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +65 -59
  43. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +113 -26
  44. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
  45. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
  46. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
  47. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
  48. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
  49. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
  50. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +89 -9
  51. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +19 -4
  52. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +6 -0
  53. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
  54. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +0 -3
  55. package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
  56. package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
  57. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
  58. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +61 -13
  59. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +87 -25
  60. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +229 -19
  61. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +117 -9
  62. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +571 -74
  63. package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
  64. package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
  65. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  66. package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
  67. package/analyzer-template/packages/aws/package.json +1 -1
  68. package/analyzer-template/packages/database/package.json +1 -1
  69. package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
  70. package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
  71. package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
  72. package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
  73. package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
  74. package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
  75. package/analyzer-template/packages/database/src/lib/kysely/db.ts +14 -1
  76. package/analyzer-template/packages/database/src/lib/kysely/tables/commitsTable.ts +6 -0
  77. package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +1 -1
  78. package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
  79. package/analyzer-template/packages/database/src/lib/loadAnalyses.ts +58 -1
  80. package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +13 -0
  81. package/analyzer-template/packages/database/src/lib/loadBranch.ts +16 -1
  82. package/analyzer-template/packages/database/src/lib/loadCommit.ts +11 -0
  83. package/analyzer-template/packages/database/src/lib/loadCommits.ts +28 -0
  84. package/analyzer-template/packages/database/src/lib/loadEntities.ts +26 -3
  85. package/analyzer-template/packages/database/src/lib/loadEntityBranches.ts +12 -0
  86. package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
  87. package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
  88. package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
  89. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +7 -14
  90. package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
  91. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
  92. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
  93. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
  94. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
  95. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
  96. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
  97. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
  98. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
  99. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
  100. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
  101. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
  102. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
  103. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  104. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  105. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +11 -1
  106. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  107. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts +1 -0
  108. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.d.ts.map +1 -1
  109. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js +3 -0
  110. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  111. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +1 -1
  112. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
  113. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
  114. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  115. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  116. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts +2 -0
  117. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.d.ts.map +1 -1
  118. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js +45 -2
  119. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalyses.js.map +1 -1
  120. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
  121. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +8 -0
  122. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
  123. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js +11 -1
  124. package/analyzer-template/packages/github/dist/database/src/lib/loadBranch.js.map +1 -1
  125. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.d.ts.map +1 -1
  126. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js +7 -0
  127. package/analyzer-template/packages/github/dist/database/src/lib/loadCommit.js.map +1 -1
  128. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts +3 -1
  129. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  130. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +22 -1
  131. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  132. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts +3 -1
  133. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  134. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +23 -4
  135. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  136. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.d.ts.map +1 -1
  137. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js +9 -0
  138. package/analyzer-template/packages/github/dist/database/src/lib/loadEntityBranches.js.map +1 -1
  139. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
  140. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
  141. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
  142. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
  143. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
  144. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
  145. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts +2 -2
  146. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  147. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +5 -4
  148. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  149. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts +2 -0
  150. package/analyzer-template/packages/github/dist/types/src/types/Commit.d.ts.map +1 -1
  151. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  152. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  153. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  154. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  155. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  156. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  157. package/analyzer-template/packages/github/package.json +1 -1
  158. package/analyzer-template/packages/types/src/types/Commit.ts +2 -0
  159. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +7 -0
  160. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +6 -5
  161. package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
  162. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts +2 -0
  163. package/analyzer-template/packages/utils/dist/types/src/types/Commit.d.ts.map +1 -1
  164. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  165. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  166. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  167. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  168. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  169. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  170. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
  171. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +93 -2
  172. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  173. package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +108 -2
  174. package/analyzer-template/playwright/capture.ts +20 -8
  175. package/analyzer-template/playwright/captureStatic.ts +1 -1
  176. package/analyzer-template/project/analyzeBaselineCommit.ts +5 -0
  177. package/analyzer-template/project/analyzeRegularCommit.ts +5 -0
  178. package/analyzer-template/project/captureLibraryFunctionDirect.ts +29 -26
  179. package/analyzer-template/project/constructMockCode.ts +92 -12
  180. package/analyzer-template/project/createEntitiesAndSortFiles.ts +83 -0
  181. package/analyzer-template/project/loadReadyToBeCaptured.ts +65 -41
  182. package/analyzer-template/project/orchestrateCapture/AwsCaptureTaskRunner.ts +12 -4
  183. package/analyzer-template/project/orchestrateCapture/SequentialCaptureTaskRunner.ts +11 -6
  184. package/analyzer-template/project/orchestrateCapture/taskRunner.ts +4 -2
  185. package/analyzer-template/project/orchestrateCapture.ts +45 -6
  186. package/analyzer-template/project/start.ts +35 -11
  187. package/analyzer-template/project/writeMockDataTsx.ts +181 -8
  188. package/analyzer-template/project/writeScenarioComponents.ts +103 -12
  189. package/analyzer-template/project/writeSimpleRoot.ts +21 -11
  190. package/analyzer-template/scripts/comboWorkerLoop.cjs +98 -50
  191. package/background/src/lib/local/createLocalAnalyzer.js +1 -1
  192. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  193. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js +5 -0
  194. package/background/src/lib/virtualized/project/analyzeBaselineCommit.js.map +1 -1
  195. package/background/src/lib/virtualized/project/analyzeRegularCommit.js +5 -0
  196. package/background/src/lib/virtualized/project/analyzeRegularCommit.js.map +1 -1
  197. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js +3 -3
  198. package/background/src/lib/virtualized/project/captureLibraryFunctionDirect.js.map +1 -1
  199. package/background/src/lib/virtualized/project/constructMockCode.js +77 -6
  200. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  201. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js +73 -1
  202. package/background/src/lib/virtualized/project/createEntitiesAndSortFiles.js.map +1 -1
  203. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js +19 -8
  204. package/background/src/lib/virtualized/project/loadReadyToBeCaptured.js.map +1 -1
  205. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js +2 -2
  206. package/background/src/lib/virtualized/project/orchestrateCapture/AwsCaptureTaskRunner.js.map +1 -1
  207. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js +4 -4
  208. package/background/src/lib/virtualized/project/orchestrateCapture/SequentialCaptureTaskRunner.js.map +1 -1
  209. package/background/src/lib/virtualized/project/orchestrateCapture.js +38 -6
  210. package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
  211. package/background/src/lib/virtualized/project/start.js +32 -11
  212. package/background/src/lib/virtualized/project/start.js.map +1 -1
  213. package/background/src/lib/virtualized/project/writeMockDataTsx.js +162 -4
  214. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  215. package/background/src/lib/virtualized/project/writeScenarioComponents.js +85 -15
  216. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  217. package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
  218. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  219. package/codeyam-cli/scripts/apply-setup.js +180 -0
  220. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  221. package/codeyam-cli/src/cli.js +4 -0
  222. package/codeyam-cli/src/cli.js.map +1 -1
  223. package/codeyam-cli/src/codeyam-cli.js +18 -2
  224. package/codeyam-cli/src/codeyam-cli.js.map +1 -1
  225. package/codeyam-cli/src/commands/analyze.js +4 -2
  226. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  227. package/codeyam-cli/src/commands/baseline.js +2 -0
  228. package/codeyam-cli/src/commands/baseline.js.map +1 -1
  229. package/codeyam-cli/src/commands/debug.js +9 -5
  230. package/codeyam-cli/src/commands/debug.js.map +1 -1
  231. package/codeyam-cli/src/commands/default.js +31 -20
  232. package/codeyam-cli/src/commands/default.js.map +1 -1
  233. package/codeyam-cli/src/commands/detect-universal-mocks.js +2 -0
  234. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +1 -1
  235. package/codeyam-cli/src/commands/init.js +49 -257
  236. package/codeyam-cli/src/commands/init.js.map +1 -1
  237. package/codeyam-cli/src/commands/memory.js +264 -0
  238. package/codeyam-cli/src/commands/memory.js.map +1 -0
  239. package/codeyam-cli/src/commands/recapture.js +2 -0
  240. package/codeyam-cli/src/commands/recapture.js.map +1 -1
  241. package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
  242. package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
  243. package/codeyam-cli/src/commands/setup-simulations.js +284 -0
  244. package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
  245. package/codeyam-cli/src/commands/test-startup.js +2 -0
  246. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  247. package/codeyam-cli/src/commands/verify.js +14 -2
  248. package/codeyam-cli/src/commands/verify.js.map +1 -1
  249. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +128 -86
  250. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  251. package/codeyam-cli/src/utils/analysisRunner.js +21 -2
  252. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  253. package/codeyam-cli/src/utils/analyzer.js +7 -0
  254. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  255. package/codeyam-cli/src/utils/backgroundServer.js +107 -19
  256. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  257. package/codeyam-cli/src/utils/generateReport.js +2 -2
  258. package/codeyam-cli/src/utils/install-skills.js +72 -47
  259. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  260. package/codeyam-cli/src/utils/labsAutoCheck.js +19 -0
  261. package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
  262. package/codeyam-cli/src/utils/progress.js +7 -0
  263. package/codeyam-cli/src/utils/progress.js.map +1 -1
  264. package/codeyam-cli/src/utils/queue/job.js +4 -0
  265. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  266. package/codeyam-cli/src/utils/requireSimulations.js +10 -0
  267. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
  268. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  269. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  270. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +230 -0
  271. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  272. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  273. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  274. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  275. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  276. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  277. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  278. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  279. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  280. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +75 -0
  281. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  282. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +378 -0
  283. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  284. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +115 -0
  285. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  286. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  287. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  288. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  289. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  290. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
  291. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  292. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  293. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  294. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
  295. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  296. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  297. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  298. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  299. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  300. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  301. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  302. package/codeyam-cli/src/utils/rules/index.js +6 -0
  303. package/codeyam-cli/src/utils/rules/index.js.map +1 -0
  304. package/codeyam-cli/src/utils/rules/parser.js +83 -0
  305. package/codeyam-cli/src/utils/rules/parser.js.map +1 -0
  306. package/codeyam-cli/src/utils/rules/pathMatcher.js +18 -0
  307. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -0
  308. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  309. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  310. package/codeyam-cli/src/utils/rules/staleness.js +137 -0
  311. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -0
  312. package/codeyam-cli/src/utils/serverState.js +37 -10
  313. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  314. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +21 -44
  315. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  316. package/codeyam-cli/src/webserver/app/lib/database.js +21 -6
  317. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  318. package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
  319. package/codeyam-cli/src/webserver/backgroundServer.js +50 -0
  320. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  321. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-D9i_zSlY.js +1 -0
  322. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-BLlhOa3C.js +11 -0
  323. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-De5b5pC7.js} +1 -1
  324. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-CzdG5I7z.js} +1 -1
  325. package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-C8lyxW9k.js → InlineSpinner-Bclf8Hka.js} +1 -1
  326. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-Ce-byqKl.js} +2 -2
  327. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-DEMHrl7v.js} +1 -1
  328. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-B1LNGboS.js} +1 -1
  329. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-B0Ll1DjK.js} +1 -1
  330. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-D4TZhLuw.js → ReportIssueModal-CVOvmCKb.js} +3 -13
  331. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-L0DWHa_L.js} +1 -1
  332. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DEx02QDa.js → ScenarioViewer-D54Mmpwi.js} +3 -3
  333. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-C7PFQfXy.js} +1 -1
  334. package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-CKTtYlBU.js} +1 -1
  335. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-DoLIqZX2.js → activity.(_tab)-CdziRIWU.js} +6 -16
  336. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-CPXtdaWm.js +17 -0
  337. package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
  338. package/codeyam-cli/src/webserver/build/client/assets/api.memory-profile-l0sNRNKZ.js +1 -0
  339. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  340. package/codeyam-cli/src/webserver/build/client/assets/book-open-Ch8b7GyQ.js +6 -0
  341. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-vJHJExlT.js} +1 -1
  342. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-BEyX4X6_.js} +12 -12
  343. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-rwynPZTW.js} +1 -1
  344. package/codeyam-cli/src/webserver/build/client/assets/copy-BBSpeBYf.js +11 -0
  345. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-DHVDauuc.js} +1 -1
  346. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-B9_ZqelV.js +1 -0
  347. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-BOPComvD.js +16 -0
  348. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js → entity._sha.scenarios._scenarioId.fullscreen-Cfw__yQa.js} +1 -1
  349. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-D1T4TGjf.js → entity._sha_.create-scenario-BIDUUrI3.js} +1 -1
  350. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-BEqewwtZ.js} +1 -1
  351. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-Dxqz8ygt.js} +1 -1
  352. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-CYnF5KWN.js} +1 -1
  353. package/codeyam-cli/src/webserver/build/client/assets/files-B_dAq2PQ.js +1 -0
  354. package/codeyam-cli/src/webserver/build/client/assets/{git-B4RJRvYB.js → git-BHPqH3Ch.js} +8 -8
  355. package/codeyam-cli/src/webserver/build/client/assets/globals-BJGhRykz.css +1 -0
  356. package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-DgAAopZk.js} +1 -1
  357. package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-viijWaN6.js} +1 -1
  358. package/codeyam-cli/src/webserver/build/client/assets/labs-ChoAe3xq.js +1 -0
  359. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-LGi2eKI5.js} +1 -1
  360. package/codeyam-cli/src/webserver/build/client/assets/manifest-87493a32.js +1 -0
  361. package/codeyam-cli/src/webserver/build/client/assets/memory-D9eA6kTo.js +78 -0
  362. package/codeyam-cli/src/webserver/build/client/assets/pause-DxJFmMsK.js +11 -0
  363. package/codeyam-cli/src/webserver/build/client/assets/root-C3r0p_7H.js +62 -0
  364. package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-Cu3QE9E5.js} +1 -1
  365. package/codeyam-cli/src/webserver/build/client/assets/settings-KH9TdArD.js +1 -0
  366. package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-D9Fkx0-d.js} +1 -1
  367. package/codeyam-cli/src/webserver/build/client/assets/terminal-dAhIBEcd.js +11 -0
  368. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-C4CYTEeP.js} +1 -1
  369. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-CLPnITMB.js} +1 -1
  370. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-aSv48UbS.js → useLastLogLine-DmGI38Et.js} +1 -1
  371. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-BK0S88PB.js} +1 -1
  372. package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-CJ-JqR0l.js} +1 -1
  373. package/codeyam-cli/src/webserver/build/server/assets/index-CkkmL6r5.js +1 -0
  374. package/codeyam-cli/src/webserver/build/server/assets/server-build-iBGjHYtO.js +259 -0
  375. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  376. package/codeyam-cli/src/webserver/build-info.json +5 -5
  377. package/codeyam-cli/templates/{codeyam:debug.md → codeyam-debug.md} +1 -1
  378. package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
  379. package/codeyam-cli/templates/{codeyam-power-rules-hook.sh → codeyam-memory-hook.sh} +22 -23
  380. package/codeyam-cli/templates/codeyam-memory.md +396 -0
  381. package/codeyam-cli/templates/codeyam-new-rule.md +13 -0
  382. package/codeyam-cli/templates/{codeyam:setup.md → codeyam-setup.md} +13 -1
  383. package/codeyam-cli/templates/{codeyam:sim.md → codeyam-sim.md} +1 -1
  384. package/codeyam-cli/templates/{codeyam:test.md → codeyam-test.md} +1 -1
  385. package/codeyam-cli/templates/{codeyam:verify.md → codeyam-verify.md} +1 -1
  386. package/codeyam-cli/templates/rule-notification-hook.py +56 -0
  387. package/codeyam-cli/templates/rule-reflection-hook.py +627 -0
  388. package/codeyam-cli/templates/rules-instructions.md +132 -0
  389. package/package.json +15 -13
  390. package/packages/ai/index.js +3 -2
  391. package/packages/ai/index.js.map +1 -1
  392. package/packages/ai/src/lib/analyzeScope.js +82 -13
  393. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  394. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +54 -8
  395. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  396. package/packages/ai/src/lib/astScopes/methodSemantics.js +41 -17
  397. package/packages/ai/src/lib/astScopes/methodSemantics.js.map +1 -1
  398. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  399. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  400. package/packages/ai/src/lib/astScopes/processExpression.js +317 -44
  401. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  402. package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
  403. package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
  404. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +776 -171
  405. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  406. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
  407. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  408. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
  409. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
  410. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
  411. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
  412. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +52 -3
  413. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  414. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +55 -11
  415. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  416. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  417. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  418. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +122 -12
  419. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  420. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
  421. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
  422. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
  423. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
  424. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +333 -86
  425. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  426. package/packages/ai/src/lib/dataStructureChunking.js +26 -11
  427. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  428. package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
  429. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  430. package/packages/ai/src/lib/generateEntityScenarioData.js +227 -4
  431. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  432. package/packages/ai/src/lib/generateEntityScenarios.js +7 -1
  433. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  434. package/packages/ai/src/lib/generateExecutionFlows.js +26 -4
  435. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  436. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +447 -80
  437. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  438. package/packages/ai/src/lib/isolateScopes.js +39 -3
  439. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  440. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
  441. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
  442. package/packages/ai/src/lib/mergeStatements.js +70 -51
  443. package/packages/ai/src/lib/mergeStatements.js.map +1 -1
  444. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
  445. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
  446. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +10 -4
  447. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
  448. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
  449. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  450. package/packages/ai/src/lib/resolvePathToControllable.js +24 -14
  451. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
  452. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  453. package/packages/ai/src/lib/worker/analyzeScopeWorker.js +94 -1
  454. package/packages/ai/src/lib/worker/analyzeScopeWorker.js.map +1 -1
  455. package/packages/analyze/index.js +1 -0
  456. package/packages/analyze/index.js.map +1 -1
  457. package/packages/analyze/src/lib/FileAnalyzer.js +60 -36
  458. package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
  459. package/packages/analyze/src/lib/ProjectAnalyzer.js +96 -26
  460. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  461. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
  462. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
  463. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
  464. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
  465. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
  466. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
  467. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
  468. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
  469. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
  470. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
  471. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
  472. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
  473. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +65 -7
  474. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  475. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +17 -4
  476. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  477. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +5 -0
  478. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  479. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
  480. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  481. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +0 -3
  482. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  483. package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
  484. package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
  485. package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
  486. package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
  487. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
  488. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  489. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +56 -10
  490. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  491. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +75 -21
  492. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  493. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +150 -17
  494. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  495. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +56 -8
  496. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  497. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +478 -54
  498. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  499. package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
  500. package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
  501. package/packages/analyze/src/lib/index.js +1 -0
  502. package/packages/analyze/src/lib/index.js.map +1 -1
  503. package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
  504. package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
  505. package/packages/database/src/lib/analysisBranchToDb.js +1 -1
  506. package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
  507. package/packages/database/src/lib/analysisToDb.js +1 -1
  508. package/packages/database/src/lib/analysisToDb.js.map +1 -1
  509. package/packages/database/src/lib/branchToDb.js +1 -1
  510. package/packages/database/src/lib/branchToDb.js.map +1 -1
  511. package/packages/database/src/lib/commitBranchToDb.js +1 -1
  512. package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
  513. package/packages/database/src/lib/commitToDb.js +1 -1
  514. package/packages/database/src/lib/commitToDb.js.map +1 -1
  515. package/packages/database/src/lib/fileToDb.js +1 -1
  516. package/packages/database/src/lib/fileToDb.js.map +1 -1
  517. package/packages/database/src/lib/kysely/db.js +11 -1
  518. package/packages/database/src/lib/kysely/db.js.map +1 -1
  519. package/packages/database/src/lib/kysely/tables/commitsTable.js +3 -0
  520. package/packages/database/src/lib/kysely/tables/commitsTable.js.map +1 -1
  521. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  522. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  523. package/packages/database/src/lib/loadAnalyses.js +45 -2
  524. package/packages/database/src/lib/loadAnalyses.js.map +1 -1
  525. package/packages/database/src/lib/loadAnalysis.js +8 -0
  526. package/packages/database/src/lib/loadAnalysis.js.map +1 -1
  527. package/packages/database/src/lib/loadBranch.js +11 -1
  528. package/packages/database/src/lib/loadBranch.js.map +1 -1
  529. package/packages/database/src/lib/loadCommit.js +7 -0
  530. package/packages/database/src/lib/loadCommit.js.map +1 -1
  531. package/packages/database/src/lib/loadCommits.js +22 -1
  532. package/packages/database/src/lib/loadCommits.js.map +1 -1
  533. package/packages/database/src/lib/loadEntities.js +23 -4
  534. package/packages/database/src/lib/loadEntities.js.map +1 -1
  535. package/packages/database/src/lib/loadEntityBranches.js +9 -0
  536. package/packages/database/src/lib/loadEntityBranches.js.map +1 -1
  537. package/packages/database/src/lib/projectToDb.js +1 -1
  538. package/packages/database/src/lib/projectToDb.js.map +1 -1
  539. package/packages/database/src/lib/saveFiles.js +1 -1
  540. package/packages/database/src/lib/saveFiles.js.map +1 -1
  541. package/packages/database/src/lib/scenarioToDb.js +1 -1
  542. package/packages/database/src/lib/scenarioToDb.js.map +1 -1
  543. package/packages/database/src/lib/updateCommitMetadata.js +5 -4
  544. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  545. package/packages/utils/src/lib/fs/rsyncCopy.js +93 -2
  546. package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  547. package/scripts/finalize-analyzer.cjs +8 -76
  548. package/codeyam-cli/src/webserver/build/client/assets/EntityItem-BXhEawa3.js +0 -1
  549. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BRb-0kQl.js +0 -1
  550. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-C2N4Op8e.js +0 -23
  551. package/codeyam-cli/src/webserver/build/client/assets/files-Cs4MdYtv.js +0 -1
  552. package/codeyam-cli/src/webserver/build/client/assets/git-commit-horizontal-CysbcZxi.js +0 -6
  553. package/codeyam-cli/src/webserver/build/client/assets/globals-DMUaGAqV.css +0 -1
  554. package/codeyam-cli/src/webserver/build/client/assets/manifest-f874c610.js +0 -1
  555. package/codeyam-cli/src/webserver/build/client/assets/root-Bz5TunQg.js +0 -57
  556. package/codeyam-cli/src/webserver/build/client/assets/rules-hEkvVw2-.js +0 -97
  557. package/codeyam-cli/src/webserver/build/client/assets/settings-CS5f3WzT.js +0 -1
  558. package/codeyam-cli/src/webserver/build/server/assets/index-967OuJoF.js +0 -1
  559. package/codeyam-cli/src/webserver/build/server/assets/server-build-DRTmerg9.js +0 -257
  560. package/codeyam-cli/templates/codeyam:diagnose.md +0 -650
  561. package/codeyam-cli/templates/codeyam:new-rule.md +0 -13
  562. package/codeyam-cli/templates/codeyam:power-rules.md +0 -447
  563. /package/codeyam-cli/src/webserver/build/client/assets/{api.rules-l0sNRNKZ.js → api.agent-transcripts-l0sNRNKZ.js} +0 -0
@@ -9,13 +9,14 @@ import { Entity } from '~codeyam/types';
9
9
  import { FileAnalyzer, ProjectAnalyzer } from '~codeyam/analyze';
10
10
  import { analyzeScopeLocal } from '../analyzeScope';
11
11
  import {
12
- ScopeInfo,
13
12
  resetScopeDataStructureMetrics,
13
+ ScopeInfo,
14
14
  } from '../dataStructure/ScopeDataStructure';
15
15
  import { SerializableDataStructure } from './SerializableDataStructure';
16
16
  import { AI } from '~codeyam/ai';
17
17
  import { setThreadContext } from '~codeyam/utils';
18
18
  import { threadId } from 'worker_threads';
19
+ import v8 from 'v8';
19
20
 
20
21
  // Set thread context for logging
21
22
  setThreadContext(`<worker-${threadId}>`);
@@ -45,6 +46,80 @@ let projectAnalyzerKey: string | null = null;
45
46
  let fileAnalyzer: FileAnalyzer | null = null;
46
47
  let fileAnalyzerPath: string | null = null;
47
48
 
49
+ // Memory tracking
50
+ let entitiesProcessed = 0;
51
+ let lastMemoryLogAt = 0;
52
+ const MEMORY_LOG_INTERVAL = 100; // Log every N entities
53
+ const MEMORY_LOG_TIME_INTERVAL = 60_000; // Or every 60 seconds
54
+
55
+ /**
56
+ * Get memory stats for logging
57
+ */
58
+ function getWorkerMemoryStats() {
59
+ const mem = process.memoryUsage();
60
+ const heapStats = v8.getHeapStatistics();
61
+ return {
62
+ rss: `${Math.round(mem.rss / 1024 / 1024)}MB`,
63
+ heapUsed: `${Math.round(mem.heapUsed / 1024 / 1024)}MB`,
64
+ heapTotal: `${Math.round(mem.heapTotal / 1024 / 1024)}MB`,
65
+ external: `${Math.round(mem.external / 1024 / 1024)}MB`,
66
+ // V8 heap stats give more detail
67
+ v8TotalHeapSize: `${Math.round(heapStats.total_heap_size / 1024 / 1024)}MB`,
68
+ v8UsedHeapSize: `${Math.round(heapStats.used_heap_size / 1024 / 1024)}MB`,
69
+ v8HeapSizeLimit: `${Math.round(heapStats.heap_size_limit / 1024 / 1024)}MB`,
70
+ v8MallocedMemory: `${Math.round(heapStats.malloced_memory / 1024 / 1024)}MB`,
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Get ts.Program stats for understanding TypeScript memory usage
76
+ */
77
+ function getTsProgramStats(pa: ProjectAnalyzer) {
78
+ const sourceFiles = pa.program.getSourceFiles();
79
+ const projectSourceFiles = sourceFiles.filter(
80
+ (sf) => !sf.fileName.includes('node_modules'),
81
+ );
82
+ const nodeModulesFiles = sourceFiles.filter((sf) =>
83
+ sf.fileName.includes('node_modules'),
84
+ );
85
+
86
+ // Estimate AST size by sampling text length (rough proxy)
87
+ let totalProjectTextLength = 0;
88
+ for (const sf of projectSourceFiles) {
89
+ totalProjectTextLength += sf.getFullText().length;
90
+ }
91
+
92
+ return {
93
+ totalSourceFiles: sourceFiles.length,
94
+ projectSourceFiles: projectSourceFiles.length,
95
+ nodeModulesFiles: nodeModulesFiles.length,
96
+ projectTextSizeMB: `${(totalProjectTextLength / 1024 / 1024).toFixed(1)}MB`,
97
+ // Note: Actual AST memory is typically 10-20x the source text size
98
+ estimatedAstSizeMB: `${((totalProjectTextLength * 15) / 1024 / 1024).toFixed(0)}MB`,
99
+ };
100
+ }
101
+
102
+ /**
103
+ * Write a heap snapshot for detailed profiling.
104
+ * The snapshot can be loaded in Chrome DevTools for analysis.
105
+ *
106
+ * TODO: Once we understand memory usage, change this back to env-var controlled
107
+ */
108
+ const HEAP_SNAPSHOT_MODE: 'off' | 'once' | 'periodic' = 'off';
109
+
110
+ function maybeWriteHeapSnapshot(label: string) {
111
+ if (HEAP_SNAPSHOT_MODE === 'off') return;
112
+
113
+ try {
114
+ const filename = v8.writeHeapSnapshot();
115
+ console.log(
116
+ `CodeYam Worker: Heap snapshot written (${label}): ${filename}`,
117
+ );
118
+ } catch (error) {
119
+ console.error('CodeYam Worker: Failed to write heap snapshot:', error);
120
+ }
121
+ }
122
+
48
123
  /**
49
124
  * Main worker function called by Piscina
50
125
  */
@@ -61,8 +136,25 @@ export default async function runAnalyzeScope(
61
136
  // Create or reuse ProjectAnalyzer
62
137
  const paKey = `${dirPath}`;
63
138
  if (!projectAnalyzer || projectAnalyzerKey !== paKey) {
64
- projectAnalyzer = await ProjectAnalyzer.from({ project, dirPath });
139
+ const memBefore = process.memoryUsage();
140
+ console.log('CodeYam Worker: Creating ProjectAnalyzer (ts.Program)...', {
141
+ memBefore: getWorkerMemoryStats(),
142
+ });
143
+
144
+ projectAnalyzer = ProjectAnalyzer.from({ project, dirPath });
65
145
  projectAnalyzerKey = paKey;
146
+
147
+ const memAfter = process.memoryUsage();
148
+ const tsProgramStats = getTsProgramStats(projectAnalyzer);
149
+ console.log('CodeYam Worker: ProjectAnalyzer created', {
150
+ memAfter: getWorkerMemoryStats(),
151
+ rssDelta: `+${Math.round((memAfter.rss - memBefore.rss) / 1024 / 1024)}MB`,
152
+ heapDelta: `+${Math.round((memAfter.heapUsed - memBefore.heapUsed) / 1024 / 1024)}MB`,
153
+ tsProgramStats,
154
+ });
155
+
156
+ // Optionally write heap snapshot after ts.Program creation
157
+ maybeWriteHeapSnapshot('after-ts-program');
66
158
  }
67
159
 
68
160
  // Create or reuse FileAnalyzer
@@ -95,6 +187,26 @@ export default async function runAnalyzeScope(
95
187
  );
96
188
  }
97
189
 
190
+ // Periodic memory logging
191
+ entitiesProcessed++;
192
+ const now = Date.now();
193
+ const shouldLogMemory =
194
+ entitiesProcessed % MEMORY_LOG_INTERVAL === 0 ||
195
+ now - lastMemoryLogAt > MEMORY_LOG_TIME_INTERVAL;
196
+
197
+ if (shouldLogMemory) {
198
+ lastMemoryLogAt = now;
199
+ console.log('CodeYam Worker: Memory stats', {
200
+ entitiesProcessed,
201
+ ...getWorkerMemoryStats(),
202
+ });
203
+
204
+ // Optionally write periodic heap snapshots
205
+ if (HEAP_SNAPSHOT_MODE === 'periodic' && entitiesProcessed % 500 === 0) {
206
+ maybeWriteHeapSnapshot(`after-${entitiesProcessed}-entities`);
207
+ }
208
+ }
209
+
98
210
  return { dataStructure: dataStructure.toSerializable() };
99
211
  } catch (error) {
100
212
  console.error(
@@ -41,6 +41,8 @@ export { default as mergeValidatedDataStructures } from './src/lib/files/scenari
41
41
 
42
42
  export { discoverDirectDependencies } from './src/lib/files/analyze/dependencyResolver';
43
43
 
44
+ export { transformationTracer } from './src/lib/files/scenarios/TransformationTracer';
45
+
44
46
  export { default as getAnalysisError } from './src/lib/utils/getAnalysisError';
45
47
  export { default as measureAndReportExecutionTime } from './src/lib/utils/measureAndReportExecutionTime';
46
48
 
@@ -9,6 +9,7 @@ import {
9
9
  import { FunctionNode } from './types';
10
10
  import getEntityType from './files/getEntityType';
11
11
  import getEntityCode from './files/getEntityCode';
12
+ import { getFileByPathSafe } from './utils/getFileByPath';
12
13
 
13
14
  export class FileAnalyzer {
14
15
  public projectAnalyzer: lib.ProjectAnalyzer;
@@ -19,6 +20,7 @@ export class FileAnalyzer {
19
20
  // Current per-file caching helps when multiple entities in the same file call getResolvedImportsRelevantToFunctionName,
20
21
  // but a project-level cache would also benefit the recursive import chain traversals that cross file boundaries.
21
22
  private resolvedImportsCache: Map<string, FunctionDependenciesMap>;
23
+ private allEntityNodesOnlyAliasesCache?: Record<string, ts.Node>;
22
24
 
23
25
  constructor({
24
26
  projectAnalyzer,
@@ -62,18 +64,23 @@ export class FileAnalyzer {
62
64
 
63
65
  getAllEntityNodesOnlyAliases() {
64
66
  if (!this.sourceFile) return {};
67
+ if (this.allEntityNodesOnlyAliasesCache) {
68
+ return this.allEntityNodesOnlyAliasesCache;
69
+ }
65
70
  try {
66
71
  const allEntityNodes = lib.asts.sourceFiles.getAllEntityNodes({
67
72
  sourceFile: this.sourceFile,
68
73
  });
69
- if (allEntityNodes.default) {
70
- const namedDefault = Object.entries(allEntityNodes).find(
74
+ const aliasesOnly = { ...allEntityNodes };
75
+ if (aliasesOnly.default) {
76
+ const namedDefault = Object.entries(aliasesOnly).find(
71
77
  ([otherEntityName, node]) =>
72
- otherEntityName !== 'default' && node === allEntityNodes.default,
78
+ otherEntityName !== 'default' && node === aliasesOnly.default,
73
79
  );
74
- if (namedDefault) delete allEntityNodes.default;
80
+ if (namedDefault) delete aliasesOnly.default;
75
81
  }
76
- return allEntityNodes;
82
+ this.allEntityNodesOnlyAliasesCache = aliasesOnly;
83
+ return aliasesOnly;
77
84
  } catch (error) {
78
85
  console.log('CodeYam ERROR: getAllEntityNodesOnlyAliases failed:', {
79
86
  filePath: this.file?.path,
@@ -223,15 +230,11 @@ export class FileAnalyzer {
223
230
 
224
231
  // Handle dist -> src mapping for workspace packages
225
232
  let targetPath = resolvedPath;
226
- let targetFile = this.projectAnalyzer.project.files.find(
227
- (f) => f.path === targetPath,
228
- );
233
+ let targetFile = getFileByPathSafe(this.projectAnalyzer, targetPath);
229
234
 
230
235
  if (!targetFile && targetPath.includes('/dist/')) {
231
236
  const srcPath = targetPath.replace('/dist/', '/src/');
232
- targetFile = this.projectAnalyzer.project.files.find(
233
- (f) => f.path === srcPath,
234
- );
237
+ targetFile = getFileByPathSafe(this.projectAnalyzer, srcPath);
235
238
  if (targetFile) {
236
239
  targetPath = srcPath;
237
240
  }
@@ -239,9 +242,9 @@ export class FileAnalyzer {
239
242
  // Try with different extensions if still not found
240
243
  if (!targetFile) {
241
244
  const basePath = srcPath.replace(/\.d\.ts$/, '').replace(/\.js$/, '');
242
- targetFile = this.projectAnalyzer.project.files.find(
243
- (f) => f.path === basePath + '.ts' || f.path === basePath + '.tsx',
244
- );
245
+ targetFile =
246
+ getFileByPathSafe(this.projectAnalyzer, basePath + '.ts') ??
247
+ getFileByPathSafe(this.projectAnalyzer, basePath + '.tsx');
245
248
  if (targetFile) {
246
249
  targetPath = targetFile.path;
247
250
  }
@@ -301,24 +304,25 @@ export class FileAnalyzer {
301
304
 
302
305
  getLocalEntitiesUsedInFunction(functionName: string) {
303
306
  if (!this.sourceFile) return [];
304
- const entityNodes = lib.asts.sourceFiles.getAllEntityNodes({
305
- sourceFile: this.sourceFile,
306
- });
307
+ const entityNodes = this.getAllEntityNodes();
307
308
 
308
309
  // Defensive check: ensure the function exists in entityNodes
309
- if (!entityNodes[functionName]) {
310
+ const functionNode = entityNodes[functionName];
311
+ if (!functionNode) {
310
312
  return [];
311
313
  }
312
314
 
313
315
  try {
314
- const identifiers = this.getIdentifiersInNode(entityNodes[functionName]);
316
+ const identifiers = this.getIdentifiersInNode(functionNode);
315
317
  return identifiers
316
- .filter(
317
- (identifier, index, self) =>
318
- entityNodes[identifier] !== entityNodes[functionName] &&
319
- Object.keys(entityNodes).includes(identifier) &&
320
- self.indexOf(identifier) === index,
321
- )
318
+ .filter((identifier) => {
319
+ const node = entityNodes[identifier];
320
+ return (
321
+ !!node &&
322
+ node !== functionNode &&
323
+ typeof (node as ts.Node).kind === 'number'
324
+ );
325
+ })
322
326
  .map((identifier) => ({
323
327
  name: identifier,
324
328
  node: entityNodes[identifier],
@@ -348,14 +352,13 @@ export class FileAnalyzer {
348
352
  sourceFile: this.sourceFile,
349
353
  });
350
354
  const identifiersInRelevantNode = this.getIdentifiersInNode(relevantNode);
355
+ const identifiersSet = new Set(identifiersInRelevantNode);
351
356
 
352
357
  const entries = Object.entries(importsAnalysis)
353
358
  .map(([importedFilePath, importedExpressions]) => {
354
359
  const relevantExpressions = importedExpressions.filter(
355
360
  (importedExpression) => {
356
- return identifiersInRelevantNode.includes(
357
- importedExpression.importAlias,
358
- );
361
+ return identifiersSet.has(importedExpression.importAlias);
359
362
  },
360
363
  );
361
364
 
@@ -439,8 +442,9 @@ export class FileAnalyzer {
439
442
  resolvedImport.resolvedFileName,
440
443
  );
441
444
 
442
- let importedFile = this.projectAnalyzer.project.files.find(
443
- (f) => f.path === projectPath,
445
+ let importedFile = getFileByPathSafe(
446
+ this.projectAnalyzer,
447
+ projectPath,
444
448
  );
445
449
 
446
450
  // Workspace packages often resolve to dist/ paths (from package.json "types" or "main"),
@@ -448,9 +452,7 @@ export class FileAnalyzer {
448
452
  if (!importedFile && projectPath.includes('/dist/')) {
449
453
  const srcPath = projectPath.replace('/dist/', '/src/');
450
454
  // Try exact match first (e.g., dist/index.d.ts -> src/index.ts)
451
- importedFile = this.projectAnalyzer.project.files.find(
452
- (f) => f.path === srcPath,
453
- );
455
+ importedFile = getFileByPathSafe(this.projectAnalyzer, srcPath);
454
456
  if (importedFile) {
455
457
  projectPath = srcPath;
456
458
  }
@@ -460,10 +462,9 @@ export class FileAnalyzer {
460
462
  const basePath = srcPath
461
463
  .replace(/\.d\.ts$/, '')
462
464
  .replace(/\.js$/, '');
463
- importedFile = this.projectAnalyzer.project.files.find(
464
- (f) =>
465
- f.path === basePath + '.ts' || f.path === basePath + '.tsx',
466
- );
465
+ importedFile =
466
+ getFileByPathSafe(this.projectAnalyzer, basePath + '.ts') ??
467
+ getFileByPathSafe(this.projectAnalyzer, basePath + '.tsx');
467
468
  if (importedFile) {
468
469
  projectPath = importedFile.path;
469
470
  }
@@ -591,24 +592,35 @@ export class FileAnalyzer {
591
592
 
592
593
  getNamespaceIdentifiersInNode(node: ts.Node, namespaceIdentifier: string) {
593
594
  const identifiers: string[] = [];
595
+ const seen = new Set<string>();
594
596
 
595
597
  const identifierVisitor = (child: ts.Node) => {
596
598
  if (ts.isPropertyAccessExpression(child)) {
597
599
  if (child.expression.getText() === namespaceIdentifier) {
598
- identifiers.push(child.name.getText());
600
+ const name = child.name.getText();
601
+ if (!seen.has(name)) {
602
+ seen.add(name);
603
+ identifiers.push(name);
604
+ }
599
605
  }
600
606
  }
601
607
  ts.forEachChild(child, identifierVisitor);
602
608
  };
603
609
 
604
610
  ts.forEachChild(node, identifierVisitor);
605
- return identifiers.filter(
606
- (identifier, index, self) => self.indexOf(identifier) === index,
607
- );
611
+ return identifiers;
608
612
  }
609
613
 
610
614
  getIdentifiersInNode(node: ts.Node): string[] {
611
615
  const identifiers: string[] = [];
616
+ const seen = new Set<string>();
617
+
618
+ const addIdentifier = (text: string, allowDefault = false) => {
619
+ if (!allowDefault && text === 'default') return;
620
+ if (seen.has(text)) return;
621
+ seen.add(text);
622
+ identifiers.push(text);
623
+ };
612
624
 
613
625
  // Helper to safely get text from an identifier or string literal
614
626
  const getNodeText = (node: ts.Identifier | ts.StringLiteral): string => {
@@ -637,63 +649,57 @@ export class FileAnalyzer {
637
649
  };
638
650
 
639
651
  if (ts.isIdentifier(node)) {
640
- identifiers.push(getNodeText(node));
652
+ addIdentifier(getNodeText(node));
641
653
  }
642
654
 
643
655
  const identifierVisitor = (child: ts.Node) => {
644
656
  if (ts.isIdentifier(child)) {
645
- const text = getNodeText(child);
646
- if (text === 'default') return;
647
- identifiers.push(text);
657
+ addIdentifier(getNodeText(child));
648
658
  } else if (ts.isExportDeclaration(child)) {
649
659
  if (child.exportClause && ts.isNamedExports(child.exportClause)) {
650
660
  child.exportClause.elements.forEach((element) => {
651
- identifiers.push(getNodeText(element.name));
661
+ addIdentifier(getNodeText(element.name), true);
652
662
  });
653
663
  } else if (
654
664
  child.exportClause &&
655
665
  ts.isNamespaceExport(child.exportClause)
656
666
  ) {
657
- identifiers.push(getNodeText(child.exportClause.name));
667
+ addIdentifier(getNodeText(child.exportClause.name));
658
668
  }
659
669
  } else if (ts.isExportAssignment(child)) {
660
670
  if (ts.isIdentifier(child.expression)) {
661
- identifiers.push(getNodeText(child.expression));
671
+ addIdentifier(getNodeText(child.expression));
662
672
  }
663
673
  } else if (ts.isExportSpecifier(child)) {
664
- identifiers.push(getNodeText(child.name));
674
+ addIdentifier(getNodeText(child.name), true);
665
675
  return;
666
676
  } else if (ts.isFunctionDeclaration(child) && child.name) {
667
- identifiers.push(getNodeText(child.name));
677
+ addIdentifier(getNodeText(child.name));
668
678
  } else if (ts.isVariableStatement(child)) {
669
679
  child.declarationList.declarations.forEach((declaration) => {
670
680
  if (ts.isIdentifier(declaration.name)) {
671
- identifiers.push(getNodeText(declaration.name));
681
+ addIdentifier(getNodeText(declaration.name));
672
682
  }
673
683
  });
674
684
  } else if (ts.isImportDeclaration(child)) {
675
685
  if (child.importClause && child.importClause.namedBindings) {
676
686
  if (ts.isNamespaceImport(child.importClause.namedBindings)) {
677
- identifiers.push(
678
- getNodeText(child.importClause.namedBindings.name),
679
- );
687
+ addIdentifier(getNodeText(child.importClause.namedBindings.name));
680
688
  } else if (ts.isNamedImports(child.importClause.namedBindings)) {
681
689
  child.importClause.namedBindings.elements.forEach((element) => {
682
- identifiers.push(getNodeText(element.name));
690
+ addIdentifier(getNodeText(element.name));
683
691
  });
684
692
  }
685
693
  }
686
694
  } else if (ts.isImportSpecifier(child)) {
687
- identifiers.push(getNodeText(child.name));
695
+ addIdentifier(getNodeText(child.name), true);
688
696
  return;
689
697
  }
690
698
  ts.forEachChild(child, identifierVisitor);
691
699
  };
692
700
 
693
701
  ts.forEachChild(node, identifierVisitor);
694
- return identifiers.filter(
695
- (identifier, index, self) => self.indexOf(identifier) === index,
696
- );
702
+ return identifiers;
697
703
  }
698
704
 
699
705
  resolveNamespaceImport(
@@ -13,6 +13,8 @@ export class ProjectAnalyzer {
13
13
  programs: ts.Program[]; // All programs from all tsconfigs
14
14
  typeChecker: ts.TypeChecker;
15
15
  private filesByPath: Map<string, File>; // O(1) lookup cache for files
16
+ private sourceFileByPath: Map<string, ts.SourceFile>; // O(1) lookup cache for source files
17
+ private typeCheckerByPath: Map<string, ts.TypeChecker>; // O(1) lookup cache for type checkers by file
16
18
 
17
19
  private constructor({
18
20
  project,
@@ -47,6 +49,11 @@ export class ProjectAnalyzer {
47
49
  // Primary program is the first one (usually root) for backward compatibility
48
50
  this.program = this.programs[0];
49
51
  this.typeChecker = this.program.getTypeChecker();
52
+
53
+ // Build source file and type checker indexes for fast lookups
54
+ this.sourceFileByPath = new Map();
55
+ this.typeCheckerByPath = new Map();
56
+ this.buildSourceFileIndex();
50
57
  }
51
58
 
52
59
  static from({
@@ -73,32 +80,7 @@ export class ProjectAnalyzer {
73
80
  }
74
81
 
75
82
  getFileAnalyzerByPath(filePath: string) {
76
- if (this.project.files?.length !== this.filesByPath.size) {
77
- // Rebuild the cache if project.files has changed
78
- this.filesByPath.clear();
79
- for (const file of this.project.files) {
80
- this.filesByPath.set(file.path, file);
81
- }
82
- }
83
-
84
- // Convert absolute path to relative if needed
85
- let relativePath = filePath;
86
- if (filePath.startsWith(this.dirPath + '/')) {
87
- relativePath = this.getRelativePath(filePath);
88
- } else if (filePath.startsWith('/')) {
89
- // Might be an absolute path with a different prefix (e.g., symlink)
90
- // Try to normalize it to match our dirPath
91
- try {
92
- const normalizedPath = realpathSync(filePath);
93
- if (normalizedPath.startsWith(this.dirPath + '/')) {
94
- relativePath = normalizedPath.replace(this.dirPath + '/', '');
95
- }
96
- } catch (error) {
97
- // If normalization fails, keep the original path
98
- }
99
- }
100
-
101
- const file = this.filesByPath.get(relativePath);
83
+ const file = this.getFileByPath(filePath);
102
84
  if (!file) {
103
85
  // Technically FileAnalyzer was built to accept null file, but most of
104
86
  // the code we've written since assumes fileAnalyzer.sourceFile exists,
@@ -109,6 +91,33 @@ export class ProjectAnalyzer {
109
91
  return new lib.FileAnalyzer({ projectAnalyzer: this, file });
110
92
  }
111
93
 
94
+ getFileByPath(filePath: string): File | undefined {
95
+ this.ensureFileCache();
96
+
97
+ const candidates = new Set<string>();
98
+ if (filePath) {
99
+ candidates.add(filePath);
100
+ }
101
+
102
+ if (!filePath.startsWith('/')) {
103
+ candidates.add(filePath);
104
+ } else if (filePath.startsWith(this.dirPath + '/')) {
105
+ candidates.add(filePath.slice(this.dirPath.length + 1));
106
+ }
107
+
108
+ const relativePath = this.toProjectRelativePath(filePath);
109
+ if (relativePath) {
110
+ candidates.add(relativePath);
111
+ }
112
+
113
+ for (const candidate of candidates) {
114
+ const file = this.filesByPath.get(candidate);
115
+ if (file) return file;
116
+ }
117
+
118
+ return undefined;
119
+ }
120
+
112
121
  getFileAnalyzer(file: File) {
113
122
  this.filesByPath.set(file.path, file);
114
123
  return new lib.FileAnalyzer({ projectAnalyzer: this, file });
@@ -142,6 +151,16 @@ export class ProjectAnalyzer {
142
151
 
143
152
  getSourceFile(filePath: string): ts.SourceFile | undefined {
144
153
  const absolutePath = this.getAbsolutePath(filePath);
154
+ const relativePath = filePath.startsWith('/')
155
+ ? this.toProjectRelativePath(filePath)
156
+ : filePath;
157
+
158
+ if (relativePath) {
159
+ const cached = this.sourceFileByPath.get(relativePath);
160
+ if (cached) {
161
+ return cached;
162
+ }
163
+ }
145
164
 
146
165
  // Search across all programs
147
166
  for (const program of this.programs) {
@@ -241,6 +260,16 @@ export class ProjectAnalyzer {
241
260
  */
242
261
  getTypeCheckerForFile(filePath: string): ts.TypeChecker {
243
262
  const absolutePath = this.getAbsolutePath(filePath);
263
+ const relativePath = filePath.startsWith('/')
264
+ ? this.toProjectRelativePath(filePath)
265
+ : filePath;
266
+
267
+ if (relativePath) {
268
+ const cachedChecker = this.typeCheckerByPath.get(relativePath);
269
+ if (cachedChecker) {
270
+ return cachedChecker;
271
+ }
272
+ }
244
273
 
245
274
  // Search for the file in each program and return that program's typeChecker
246
275
  for (const program of this.programs) {
@@ -320,5 +349,63 @@ export class ProjectAnalyzer {
320
349
  // Update primary program for backward compatibility
321
350
  this.program = this.programs[0];
322
351
  this.typeChecker = this.program.getTypeChecker();
352
+
353
+ this.buildSourceFileIndex();
354
+ }
355
+
356
+ private ensureFileCache(): void {
357
+ if (this.project.files?.length !== this.filesByPath.size) {
358
+ // Rebuild the cache if project.files has changed
359
+ this.filesByPath.clear();
360
+ for (const file of this.project.files) {
361
+ this.filesByPath.set(file.path, file);
362
+ }
363
+ }
364
+ }
365
+
366
+ private toProjectRelativePath(filePath: string): string | null {
367
+ if (!filePath) return null;
368
+
369
+ if (filePath.startsWith(this.dirPath + '/')) {
370
+ return filePath.replace(this.dirPath + '/', '');
371
+ }
372
+
373
+ if (!filePath.startsWith('/')) {
374
+ return null;
375
+ }
376
+
377
+ try {
378
+ const normalizedPath = realpathSync(filePath);
379
+ if (normalizedPath.startsWith(this.dirPath + '/')) {
380
+ return normalizedPath.replace(this.dirPath + '/', '');
381
+ }
382
+ } catch (error) {
383
+ // If normalization fails, return null
384
+ }
385
+
386
+ return null;
387
+ }
388
+
389
+ private buildSourceFileIndex(): void {
390
+ this.sourceFileByPath.clear();
391
+ this.typeCheckerByPath.clear();
392
+
393
+ for (const program of this.programs) {
394
+ const checker = program.getTypeChecker();
395
+ for (const sf of program.getSourceFiles()) {
396
+ // Skip node_modules files to keep the index small
397
+ if (sf.fileName.includes('node_modules')) {
398
+ continue;
399
+ }
400
+
401
+ const relativePath = this.toProjectRelativePath(sf.fileName);
402
+ if (!relativePath) continue;
403
+
404
+ if (!this.sourceFileByPath.has(relativePath)) {
405
+ this.sourceFileByPath.set(relativePath, sf);
406
+ this.typeCheckerByPath.set(relativePath, checker);
407
+ }
408
+ }
409
+ }
323
410
  }
324
411
  }
@@ -7,6 +7,11 @@ interface GetAllDeclaredEntityNodesArgs {
7
7
  entities?: { [key: string]: ts.Node };
8
8
  }
9
9
 
10
+ const allDeclaredEntityNodesCache = new WeakMap<
11
+ ts.SourceFile,
12
+ { [key: string]: ts.Node }
13
+ >();
14
+
10
15
  /**
11
16
  * Returns all declared entity nodes in a source file.
12
17
  *
@@ -24,6 +29,14 @@ export function getAllDeclaredEntityNodes({
24
29
  entities = {},
25
30
  }: GetAllDeclaredEntityNodesArgs): { [key: string]: ts.Node } {
26
31
  try {
32
+ const isRootCall = !possibleIdentifierNode && !entityNode;
33
+ if (isRootCall) {
34
+ const cached = allDeclaredEntityNodesCache.get(sourceFile);
35
+ if (cached) {
36
+ return cached;
37
+ }
38
+ }
39
+
27
40
  if (!possibleIdentifierNode) {
28
41
  possibleIdentifierNode = sourceFile;
29
42
  }
@@ -34,6 +47,9 @@ export function getAllDeclaredEntityNodes({
34
47
  entities[possibleIdentifierNode.text] =
35
48
  entityNode ?? possibleIdentifierNode;
36
49
  }
50
+ if (isRootCall) {
51
+ allDeclaredEntityNodesCache.set(sourceFile, entities);
52
+ }
37
53
  return entities;
38
54
  }
39
55
 
@@ -225,6 +241,9 @@ export function getAllDeclaredEntityNodes({
225
241
  }
226
242
  });
227
243
 
244
+ if (isRootCall) {
245
+ allDeclaredEntityNodesCache.set(sourceFile, entities);
246
+ }
228
247
  return entities;
229
248
  } catch (e) {
230
249
  console.log(