@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
@@ -1,6 +1,7 @@
1
1
  import completionCall from './completionCall';
2
2
  import { saveLlmCall } from '~codeyam/aws/dynamodb';
3
3
  import generateEntityScenariosGenerator from './promptGenerators/generateEntityScenariosGenerator';
4
+ import { getFlowsForScenarioGeneration } from './generateExecutionFlows';
4
5
 
5
6
  import {
6
7
  Analysis,
@@ -13,6 +14,13 @@ import { awsLog } from '~codeyam/utils';
13
14
  import { sanitizePlaywrightInstructions } from './validatePlaywrightInstructions';
14
15
  import { AI, DEFAULT_LARGER_MODEL, parseJsonSafe } from '~codeyam/ai';
15
16
 
17
+ /**
18
+ * Maximum number of execution flows to send to the LLM for scenario generation.
19
+ * When there are more flows than this threshold, we filter to the top N
20
+ * highest priority flows to avoid overwhelming the LLM and wasting tokens.
21
+ */
22
+ const MAX_FLOWS_FOR_SCENARIO_GENERATION = 30;
23
+
16
24
  export interface ScenarioResult {
17
25
  name: string;
18
26
  testName: string;
@@ -75,9 +83,26 @@ export default async function generateEntityScenarios({
75
83
  };
76
84
  }
77
85
 
86
+ // Filter execution flows to top N highest priority when there are many flows
87
+ // This prevents overwhelming the LLM and wasting tokens on low-priority flows
88
+ let filteredFlows = executionFlows;
89
+ if (
90
+ executionFlows &&
91
+ executionFlows.length > MAX_FLOWS_FOR_SCENARIO_GENERATION
92
+ ) {
93
+ filteredFlows = getFlowsForScenarioGeneration(executionFlows, {
94
+ maxFlows: MAX_FLOWS_FOR_SCENARIO_GENERATION,
95
+ ensureGroupDiversity: true,
96
+ }) as ExecutionFlow[];
97
+
98
+ console.log(
99
+ `CodeYam: Filtered ${executionFlows.length} flows to ${filteredFlows.length} for scenario generation`,
100
+ );
101
+ }
102
+
78
103
  const prompt = generateEntityScenariosGenerator({
79
104
  entity,
80
- executionFlows,
105
+ executionFlows: filteredFlows,
81
106
  error,
82
107
  });
83
108
 
@@ -5,6 +5,7 @@
5
5
  * instead of LLM calls. Flows are derived from:
6
6
  * 1. conditionalUsages - variables used in if/ternary/&&/switch
7
7
  * 2. conditionalEffects - setter calls inside conditionals
8
+ * 3. jsxRenderingUsages - arrays rendered via .map() and strings interpolated in JSX
8
9
  *
9
10
  * Only paths that resolve to controllable data sources produce flows,
10
11
  * eliminating the problem of invalid paths like useState variables.
@@ -20,13 +21,16 @@ import { awsLog } from '~codeyam/utils';
20
21
  import { gatherAttributesMap } from './promptGenerators/gatherAttributesMap';
21
22
  import { fillInDirectSchemaGapsAndUnknowns } from './dataStructure/helpers/fillInSchemaGapsAndUnknowns';
22
23
  import { clearAttributesFromMapping } from './dataStructure/helpers/cleanNonObjectFunctions';
23
- import type { CompoundConditional, ConditionalUsage } from '~codeyam/types';
24
+ import type { CompoundConditional } from '~codeyam/types';
24
25
  import { LlmCall } from '~codeyam/types';
25
26
  import generateExecutionFlowsFromConditionalEffects from './generateExecutionFlowsFromConditionalEffects';
26
27
  import generateExecutionFlowsFromConditionals, {
27
28
  ChildComponentConditionalData,
28
29
  } from './generateExecutionFlowsFromConditionals';
30
+ import generateExecutionFlowsFromJsxUsages from './generateExecutionFlowsFromJsxUsages';
31
+ import resolvePathToControllable from './resolvePathToControllable';
29
32
  import { AI } from '~codeyam/ai';
33
+ import type { JsxRenderingUsage, ConditionalUsage } from './astScopes/types';
30
34
 
31
35
  interface GenerateExecutionFlowsArgs {
32
36
  entity: Pick<Entity, 'sha' | 'name' | 'filePath' | 'code' | 'metadata'>;
@@ -55,6 +59,7 @@ export default function generateExecutionFlows({
55
59
  });
56
60
 
57
61
  const isolatedDataStructure = entity.metadata?.isolatedDataStructure;
62
+
58
63
  const equivalentSignatureVariables =
59
64
  isolatedDataStructure?.equivalentSignatureVariables ?? {};
60
65
  const { attributesMap, associationMap } = gatherAttributesMap(
@@ -92,10 +97,11 @@ export default function generateExecutionFlows({
92
97
  });
93
98
 
94
99
  // Build fullToShortPathMap from associationMap
95
- // associationMap maps full paths short paths (e.g., "useFetcher<...>().functionCallReturnValue.state" "state")
96
- // fullToShortPathMap is the same mapping (we just use associationMap directly)
100
+ // When reverse=true (which is what we pass), associationMap maps shortfull
101
+ // (e.g., "state" "useFetcher<...>().functionCallReturnValue.state")
102
+ // We need full→short for path resolution lookups
97
103
  const fullToShortPathMap: Record<string, string> = {};
98
- for (const [fullPath, shortPath] of Object.entries(associationMap)) {
104
+ for (const [shortPath, fullPath] of Object.entries(associationMap)) {
99
105
  fullToShortPathMap[fullPath] = shortPath;
100
106
  }
101
107
 
@@ -106,6 +112,11 @@ export default function generateExecutionFlows({
106
112
  entity.metadata?.isolatedDataStructure?.compoundConditionals ?? [];
107
113
  const conditionalEffects: ConditionalEffect[] =
108
114
  entity.metadata?.isolatedDataStructure?.conditionalEffects ?? [];
115
+ // Get derivedVariables for multi-level derivation tracing
116
+ // This allows tracing through intermediate derived variables that aren't directly
117
+ // used in conditionals (e.g., isInCurrentRun that feeds into isAnalyzing)
118
+ const derivedVariables =
119
+ entity.metadata?.isolatedDataStructure?.derivedVariables;
109
120
 
110
121
  // Build child component data for merging child flows into parent
111
122
  // This requires:
@@ -147,6 +158,7 @@ export default function generateExecutionFlows({
147
158
  Object.keys(childComponentData).length > 0
148
159
  ? childComponentData
149
160
  : undefined,
161
+ derivedVariables,
150
162
  });
151
163
 
152
164
  console.log(
@@ -169,8 +181,22 @@ export default function generateExecutionFlows({
169
181
  `CodeYam: Generated ${effectsBasedFlows.length} flows from conditional effects`,
170
182
  );
171
183
 
184
+ // Generate flows from JSX rendering usages (array.map, text interpolation)
185
+ const jsxRenderingUsages: JsxRenderingUsage[] =
186
+ entity.metadata?.isolatedDataStructure?.jsxRenderingUsages ?? [];
187
+
188
+ const jsxBasedFlows = generateExecutionFlowsFromJsxUsages({
189
+ jsxRenderingUsages,
190
+ attributesMap: resolvedAttributesMap,
191
+ equivalentSignatureVariables,
192
+ fullToShortPathMap,
193
+ structure: isolatedDataStructure?.structure ?? {},
194
+ });
195
+
172
196
  // Merge all flows, deduplicating by ID
173
197
  // Effects-based flows take precedence as they have precise data source paths
198
+ // Conditionals-based flows second
199
+ // JSX-based flows last (lower priority as they're variation flows)
174
200
  const allFlows: ExecutionFlow[] = [];
175
201
  const seenIds = new Set<string>();
176
202
 
@@ -190,12 +216,355 @@ export default function generateExecutionFlows({
190
216
  }
191
217
  }
192
218
 
193
- console.log(
194
- `CodeYam: Total execution flows for ${entity.name}: ${allFlows.length}`,
219
+ // Add JSX-based flows (lowest priority - variation flows)
220
+ for (const flow of jsxBasedFlows) {
221
+ if (!seenIds.has(flow.id)) {
222
+ seenIds.add(flow.id);
223
+ allFlows.push(flow);
224
+ }
225
+ }
226
+
227
+ // Build a map of gating paths → child components they gate
228
+ // This allows us to identify which flows control child component rendering
229
+ const gatingPathToChildren = buildGatingPathToChildrenMap(
230
+ childBoundaryGatingConditions,
231
+ equivalentSignatureVariables,
232
+ resolvedAttributesMap,
233
+ fullToShortPathMap,
195
234
  );
196
235
 
236
+ // Calculate priority and childComponentsControlled for each flow
237
+ for (const flow of allFlows) {
238
+ calculateFlowPriority(flow, gatingPathToChildren);
239
+ }
240
+
241
+ // Sort flows by priority (highest first)
242
+ allFlows.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
243
+
197
244
  return {
198
245
  executionFlows: allFlows,
199
246
  llmCall: null as LlmCall | null, // No LLM calls in static analysis mode
200
247
  };
201
248
  }
249
+
250
+ /**
251
+ * Build a map of gating paths to the child components they gate.
252
+ * This is used to identify which flows control child component rendering.
253
+ */
254
+ function buildGatingPathToChildrenMap(
255
+ childBoundaryGatingConditions: Record<string, ConditionalUsage[]>,
256
+ equivalentSignatureVariables: Record<string, string>,
257
+ attributesMap: Record<string, string>,
258
+ fullToShortPathMap: Record<string, string>,
259
+ ): Map<string, string[]> {
260
+ const gatingPathToChildren = new Map<string, string[]>();
261
+
262
+ for (const [childName, gatingConditions] of Object.entries(
263
+ childBoundaryGatingConditions,
264
+ )) {
265
+ for (const condition of gatingConditions) {
266
+ // Get the path that gates this child
267
+ let gatingPath = condition.path;
268
+
269
+ // If there's a derivedFrom sourcePath, use that
270
+ if (condition.derivedFrom?.sourcePath) {
271
+ gatingPath = condition.derivedFrom.sourcePath;
272
+ }
273
+
274
+ // Try to resolve to a controllable path
275
+ const resolution = resolvePathToControllable(
276
+ gatingPath,
277
+ attributesMap,
278
+ equivalentSignatureVariables,
279
+ fullToShortPathMap,
280
+ );
281
+
282
+ const finalPath =
283
+ resolution.isControllable && resolution.resolvedPath
284
+ ? resolution.resolvedPath
285
+ : (equivalentSignatureVariables[gatingPath] ?? gatingPath);
286
+
287
+ // Add this child to the list of children gated by this path
288
+ const existing = gatingPathToChildren.get(finalPath) ?? [];
289
+ if (!existing.includes(childName)) {
290
+ existing.push(childName);
291
+ gatingPathToChildren.set(finalPath, existing);
292
+ }
293
+
294
+ // Also handle comparison conditions like "activeTab === 'scenarios'"
295
+ const comparisonMatch = gatingPath.match(
296
+ /^([a-zA-Z_][a-zA-Z0-9_]*)\s*(===?|!==?)\s*['"]?([^'"]+)['"]?$/,
297
+ );
298
+ if (comparisonMatch) {
299
+ const [, varName] = comparisonMatch;
300
+ const varResolution = resolvePathToControllable(
301
+ varName,
302
+ attributesMap,
303
+ equivalentSignatureVariables,
304
+ fullToShortPathMap,
305
+ );
306
+ const resolvedVarPath =
307
+ varResolution.isControllable && varResolution.resolvedPath
308
+ ? varResolution.resolvedPath
309
+ : (equivalentSignatureVariables[varName] ?? varName);
310
+
311
+ const varExisting = gatingPathToChildren.get(resolvedVarPath) ?? [];
312
+ if (!varExisting.includes(childName)) {
313
+ varExisting.push(childName);
314
+ gatingPathToChildren.set(resolvedVarPath, varExisting);
315
+ }
316
+ }
317
+ }
318
+ }
319
+
320
+ return gatingPathToChildren;
321
+ }
322
+
323
+ /**
324
+ * Calculate priority and childComponentsControlled for a flow.
325
+ *
326
+ * Priority factors (in order of importance):
327
+ * 1. Controls rendering of child components (more components = higher priority)
328
+ * 2. Controls JSX rendering (impact = 'high')
329
+ * 3. Number of conditions required
330
+ */
331
+ function calculateFlowPriority(
332
+ flow: ExecutionFlow,
333
+ gatingPathToChildren: Map<string, string[]>,
334
+ ): void {
335
+ // Find which child components this flow controls
336
+ const childComponentsControlled = new Set<string>();
337
+
338
+ for (const rv of flow.requiredValues) {
339
+ // Check if this required value's path gates any child components
340
+ const children = gatingPathToChildren.get(rv.attributePath);
341
+ if (children) {
342
+ // Only count truthy values as "enabling" the child component
343
+ // Falsy values would hide the child, not enable it
344
+ if (rv.comparison === 'truthy' || rv.comparison === 'equals') {
345
+ for (const child of children) {
346
+ childComponentsControlled.add(child);
347
+ }
348
+ }
349
+ }
350
+
351
+ // Also check without function call markers for broader matching
352
+ const simplifiedPath = rv.attributePath
353
+ .replace(/\(\)/g, '')
354
+ .replace(/\.functionCallReturnValue/g, '');
355
+ const childrenSimplified = gatingPathToChildren.get(simplifiedPath);
356
+ if (childrenSimplified) {
357
+ if (rv.comparison === 'truthy' || rv.comparison === 'equals') {
358
+ for (const child of childrenSimplified) {
359
+ childComponentsControlled.add(child);
360
+ }
361
+ }
362
+ }
363
+ }
364
+
365
+ // Set childComponentsControlled if any were found
366
+ if (childComponentsControlled.size > 0) {
367
+ flow.childComponentsControlled = Array.from(childComponentsControlled);
368
+
369
+ // Upgrade impact to 'high' if this flow controls child components
370
+ // A flow that controls which child components render DOES impact JSX rendering,
371
+ // even if the condition itself isn't directly in the JSX tree.
372
+ // This ensures flows like viewMode === 'screenshot' (which controls SafeScreenshot
373
+ // rendering via ScenarioViewer) get proper prioritization.
374
+ if (flow.impact !== 'high') {
375
+ flow.impact = 'high';
376
+ }
377
+ }
378
+
379
+ // Calculate priority score
380
+ let priority = 0;
381
+
382
+ // Base priority by impact level
383
+ if (flow.impact === 'high') {
384
+ priority += 100;
385
+ } else if (flow.impact === 'medium') {
386
+ priority += 50;
387
+ } else {
388
+ priority += 25;
389
+ }
390
+
391
+ // Add priority for each child component controlled
392
+ // Each child component adds significant priority
393
+ priority += (flow.childComponentsControlled?.length ?? 0) * 75;
394
+
395
+ // Add small bonus for number of required values (more specific = slightly higher priority)
396
+ priority += Math.min(flow.requiredValues.length * 5, 25);
397
+
398
+ flow.priority = priority;
399
+ }
400
+
401
+ /**
402
+ * Get execution flows suitable for LLM scenario generation.
403
+ *
404
+ * Filters and sorts flows based on priority, ensuring diversity
405
+ * across exclusive groups and respecting min/max thresholds.
406
+ */
407
+ export function getFlowsForScenarioGeneration(
408
+ flows: ExecutionFlow[],
409
+ options: {
410
+ /** Maximum number of flows to return (default: 20) */
411
+ maxFlows?: number;
412
+ /** Minimum priority threshold (default: 0) */
413
+ minPriority?: number;
414
+ /** Ensure at least one flow per exclusive group (default: false) */
415
+ ensureGroupDiversity?: boolean;
416
+ /** Return both included and excluded flows (default: false) */
417
+ includeExcludedFlows?: boolean;
418
+ } = {},
419
+ ):
420
+ | ExecutionFlow[]
421
+ | { includedFlows: ExecutionFlow[]; excludedFlows: ExecutionFlow[] } {
422
+ const {
423
+ maxFlows = 20,
424
+ minPriority = 0,
425
+ ensureGroupDiversity = false,
426
+ includeExcludedFlows = false,
427
+ } = options;
428
+
429
+ // Filter by minimum priority
430
+ let eligibleFlows = flows.filter((f) => (f.priority ?? 0) >= minPriority);
431
+
432
+ // Flows should already be sorted by priority, but ensure it
433
+ eligibleFlows = [...eligibleFlows].sort(
434
+ (a, b) => (b.priority ?? 0) - (a.priority ?? 0),
435
+ );
436
+
437
+ let includedFlows: ExecutionFlow[];
438
+
439
+ if (ensureGroupDiversity) {
440
+ // Ensure diversity across exclusive groups
441
+ includedFlows = selectFlowsWithGroupDiversity(eligibleFlows, maxFlows);
442
+ } else {
443
+ // Simple top-N selection
444
+ includedFlows = eligibleFlows.slice(0, maxFlows);
445
+ }
446
+
447
+ if (includeExcludedFlows) {
448
+ const includedIds = new Set(includedFlows.map((f) => f.id));
449
+ const excludedFlows = flows.filter((f) => !includedIds.has(f.id));
450
+ return { includedFlows, excludedFlows };
451
+ }
452
+
453
+ return includedFlows;
454
+ }
455
+
456
+ /**
457
+ * Build a map of attribute-value pairs to help identify related flows.
458
+ * Flows with the same attributePath but different values are considered "value siblings".
459
+ * For example, viewMode='interactive' and viewMode='screenshot' are value siblings.
460
+ */
461
+ function buildValueGroupMap(flows: ExecutionFlow[]): Map<string, string[]> {
462
+ // Map from attributePath to array of (flowId, value) pairs
463
+ const pathToValues = new Map<
464
+ string,
465
+ Array<{ flowId: string; value: string }>
466
+ >();
467
+
468
+ for (const flow of flows) {
469
+ for (const rv of flow.requiredValues) {
470
+ // Only consider equals comparisons with specific values (not truthy/falsy)
471
+ if (
472
+ rv.comparison === 'equals' &&
473
+ rv.value &&
474
+ rv.value !== 'truthy' &&
475
+ rv.value !== 'falsy'
476
+ ) {
477
+ // Normalize the attributePath for comparison
478
+ const normalizedPath = rv.attributePath
479
+ .toLowerCase()
480
+ .replace(/[^a-z0-9]/g, '');
481
+
482
+ if (!pathToValues.has(normalizedPath)) {
483
+ pathToValues.set(normalizedPath, []);
484
+ }
485
+ pathToValues
486
+ .get(normalizedPath)!
487
+ .push({ flowId: flow.id, value: rv.value });
488
+ }
489
+ }
490
+ }
491
+
492
+ // Now create the value group map: flowId -> list of sibling flowIds
493
+ const valueGroupMap = new Map<string, string[]>();
494
+
495
+ for (const [, flowValues] of pathToValues) {
496
+ // Only create groups if there are multiple different values for the same path
497
+ const uniqueValues = new Set(flowValues.map((fv) => fv.value));
498
+ if (uniqueValues.size > 1) {
499
+ // This attribute has multiple values, so all flows are siblings
500
+ const siblingIds = flowValues.map((fv) => fv.flowId);
501
+ for (const fv of flowValues) {
502
+ valueGroupMap.set(
503
+ fv.flowId,
504
+ siblingIds.filter((id) => id !== fv.flowId),
505
+ );
506
+ }
507
+ }
508
+ }
509
+
510
+ return valueGroupMap;
511
+ }
512
+
513
+ /**
514
+ * Select flows ensuring diversity across exclusive groups AND attribute values.
515
+ * Guarantees:
516
+ * 1. At least one flow per exclusive group
517
+ * 2. When a flow with a specific attribute value is selected, include sibling values too
518
+ */
519
+ function selectFlowsWithGroupDiversity(
520
+ flows: ExecutionFlow[],
521
+ maxFlows: number,
522
+ ): ExecutionFlow[] {
523
+ const selected: ExecutionFlow[] = [];
524
+ const selectedIds = new Set<string>();
525
+ const groupsRepresented = new Set<string>();
526
+
527
+ // Build value group map to identify sibling flows
528
+ const valueGroupMap = buildValueGroupMap(flows);
529
+
530
+ // First pass: ensure at least one flow per exclusive group
531
+ for (const flow of flows) {
532
+ if (selectedIds.has(flow.id)) continue;
533
+ if (selected.length >= maxFlows) break;
534
+
535
+ if (flow.exclusiveGroup && !groupsRepresented.has(flow.exclusiveGroup)) {
536
+ selected.push(flow);
537
+ selectedIds.add(flow.id);
538
+ groupsRepresented.add(flow.exclusiveGroup);
539
+ }
540
+ }
541
+
542
+ // Second pass: fill remaining slots with highest priority flows
543
+ // But also include sibling value flows when we select a flow with a specific value
544
+ for (const flow of flows) {
545
+ if (selectedIds.has(flow.id)) continue;
546
+ if (selected.length >= maxFlows) break;
547
+
548
+ selected.push(flow);
549
+ selectedIds.add(flow.id);
550
+
551
+ // Check if this flow has sibling value flows that should also be included
552
+ const siblingIds = valueGroupMap.get(flow.id);
553
+ if (siblingIds && siblingIds.length > 0) {
554
+ // Try to include sibling flows (different values of the same attribute)
555
+ for (const siblingId of siblingIds) {
556
+ if (selectedIds.has(siblingId)) continue;
557
+ if (selected.length >= maxFlows) break;
558
+
559
+ const siblingFlow = flows.find((f) => f.id === siblingId);
560
+ if (siblingFlow) {
561
+ selected.push(siblingFlow);
562
+ selectedIds.add(siblingId);
563
+ }
564
+ }
565
+ }
566
+ }
567
+
568
+ // Re-sort by priority to maintain consistent ordering
569
+ return selected.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
570
+ }