@codeyam/codeyam-cli 0.1.0-staging.323686 → 0.1.0-staging.4813bf3

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 (444) 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 +5 -5
  4. package/analyzer-template/packages/ai/index.ts +7 -1
  5. package/analyzer-template/packages/ai/package.json +2 -2
  6. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +62 -18
  7. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +67 -9
  8. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  9. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +409 -50
  10. package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
  11. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +21 -6
  12. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +992 -249
  13. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
  14. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.ts +16 -3
  15. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.ts +6 -4
  16. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +31 -3
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +37 -15
  18. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
  19. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +126 -11
  20. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +179 -0
  21. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.ts +40 -30
  22. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +367 -96
  23. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +33 -15
  24. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
  25. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +315 -6
  26. package/analyzer-template/packages/ai/src/lib/generateEntityScenarios.ts +9 -5
  27. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +49 -5
  28. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionalEffects.ts +1 -1
  29. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +649 -142
  30. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromJsxUsages.ts +1 -1
  31. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
  32. package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
  33. package/analyzer-template/packages/ai/src/lib/mergeStatements.ts +90 -96
  34. package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
  35. package/analyzer-template/packages/ai/src/lib/promptGenerators/gatherAttributesMap.ts +10 -7
  36. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
  37. package/analyzer-template/packages/ai/src/lib/resolvePathToControllable.ts +25 -13
  38. package/analyzer-template/packages/ai/src/lib/worker/SerializableDataStructure.ts +4 -3
  39. package/analyzer-template/packages/analyze/index.ts +2 -0
  40. package/analyzer-template/packages/analyze/src/lib/FileAnalyzer.ts +65 -59
  41. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +113 -26
  42. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.ts +19 -0
  43. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.ts +19 -0
  44. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getAllExports.ts +11 -0
  45. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.ts +8 -0
  46. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.ts +49 -1
  47. package/analyzer-template/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.ts +2 -1
  48. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +89 -9
  49. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +19 -4
  50. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +4 -2
  51. package/analyzer-template/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.ts +0 -3
  52. package/analyzer-template/packages/analyze/src/lib/files/analyzeRemixRoute.ts +4 -5
  53. package/analyzer-template/packages/analyze/src/lib/files/getImportedExports.ts +14 -12
  54. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
  55. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +61 -13
  56. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +37 -0
  57. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +229 -19
  58. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +117 -9
  59. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +459 -39
  60. package/analyzer-template/packages/analyze/src/lib/files/scenarios/propagateArrayItemSchemas.ts +474 -0
  61. package/analyzer-template/packages/analyze/src/lib/files/setImportedExports.ts +2 -1
  62. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  63. package/analyzer-template/packages/analyze/src/lib/utils/getFileByPath.ts +19 -0
  64. package/analyzer-template/packages/aws/package.json +1 -1
  65. package/analyzer-template/packages/database/package.json +1 -1
  66. package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
  67. package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
  68. package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
  69. package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
  70. package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
  71. package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
  72. package/analyzer-template/packages/database/src/lib/kysely/db.ts +6 -0
  73. package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +1 -1
  74. package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
  75. package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
  76. package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
  77. package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
  78. package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
  79. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
  80. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
  81. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
  82. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
  83. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
  84. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
  85. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
  86. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
  87. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
  88. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
  89. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
  90. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
  91. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  92. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  93. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +3 -0
  94. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  95. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +1 -1
  96. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
  97. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
  98. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  99. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  100. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
  101. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
  102. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
  103. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
  104. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
  105. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
  106. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  107. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  108. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  109. package/analyzer-template/packages/github/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  110. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  111. package/analyzer-template/packages/github/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  112. package/analyzer-template/packages/github/package.json +1 -1
  113. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +7 -0
  114. package/analyzer-template/packages/types/src/types/ScenariosDataStructure.ts +6 -5
  115. package/analyzer-template/packages/types/src/types/ScopeAnalysis.ts +6 -1
  116. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  117. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  118. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts +5 -5
  119. package/analyzer-template/packages/utils/dist/types/src/types/ScenariosDataStructure.d.ts.map +1 -1
  120. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts +6 -1
  121. package/analyzer-template/packages/utils/dist/types/src/types/ScopeAnalysis.d.ts.map +1 -1
  122. package/analyzer-template/project/constructMockCode.ts +90 -10
  123. package/analyzer-template/project/writeMockDataTsx.ts +181 -8
  124. package/analyzer-template/project/writeScenarioComponents.ts +60 -12
  125. package/analyzer-template/project/writeSimpleRoot.ts +21 -11
  126. package/background/src/lib/local/createLocalAnalyzer.js +1 -1
  127. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  128. package/background/src/lib/virtualized/project/constructMockCode.js +75 -4
  129. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  130. package/background/src/lib/virtualized/project/writeMockDataTsx.js +162 -4
  131. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  132. package/background/src/lib/virtualized/project/writeScenarioComponents.js +60 -15
  133. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  134. package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
  135. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  136. package/codeyam-cli/scripts/apply-setup.js +180 -0
  137. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  138. package/codeyam-cli/src/cli.js +2 -0
  139. package/codeyam-cli/src/cli.js.map +1 -1
  140. package/codeyam-cli/src/codeyam-cli.js +18 -2
  141. package/codeyam-cli/src/codeyam-cli.js.map +1 -1
  142. package/codeyam-cli/src/commands/analyze.js +4 -2
  143. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  144. package/codeyam-cli/src/commands/baseline.js +2 -0
  145. package/codeyam-cli/src/commands/baseline.js.map +1 -1
  146. package/codeyam-cli/src/commands/debug.js +9 -5
  147. package/codeyam-cli/src/commands/debug.js.map +1 -1
  148. package/codeyam-cli/src/commands/default.js +31 -20
  149. package/codeyam-cli/src/commands/default.js.map +1 -1
  150. package/codeyam-cli/src/commands/detect-universal-mocks.js +2 -0
  151. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +1 -1
  152. package/codeyam-cli/src/commands/init.js +49 -257
  153. package/codeyam-cli/src/commands/init.js.map +1 -1
  154. package/codeyam-cli/src/commands/memory.js +17 -26
  155. package/codeyam-cli/src/commands/memory.js.map +1 -1
  156. package/codeyam-cli/src/commands/recapture.js +2 -0
  157. package/codeyam-cli/src/commands/recapture.js.map +1 -1
  158. package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
  159. package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
  160. package/codeyam-cli/src/commands/setup-simulations.js +284 -0
  161. package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
  162. package/codeyam-cli/src/commands/test-startup.js +2 -0
  163. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  164. package/codeyam-cli/src/commands/verify.js +14 -2
  165. package/codeyam-cli/src/commands/verify.js.map +1 -1
  166. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +128 -86
  167. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  168. package/codeyam-cli/src/utils/analyzer.js +7 -0
  169. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  170. package/codeyam-cli/src/utils/backgroundServer.js +5 -0
  171. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  172. package/codeyam-cli/src/utils/generateReport.js +2 -2
  173. package/codeyam-cli/src/utils/install-skills.js +70 -45
  174. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  175. package/codeyam-cli/src/utils/labsAutoCheck.js +19 -0
  176. package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
  177. package/codeyam-cli/src/utils/progress.js +7 -0
  178. package/codeyam-cli/src/utils/progress.js.map +1 -1
  179. package/codeyam-cli/src/utils/queue/job.js +4 -0
  180. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  181. package/codeyam-cli/src/utils/requireSimulations.js +10 -0
  182. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
  183. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  184. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  185. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +230 -0
  186. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  187. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  188. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  189. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  190. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  191. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  192. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  193. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  194. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  195. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +75 -0
  196. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  197. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +378 -0
  198. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  199. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +115 -0
  200. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  201. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  202. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  203. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  204. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  205. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
  206. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  207. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  208. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  209. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
  210. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  211. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  212. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  213. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  214. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  215. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  216. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  217. package/codeyam-cli/src/utils/rules/index.js +1 -0
  218. package/codeyam-cli/src/utils/rules/index.js.map +1 -1
  219. package/codeyam-cli/src/utils/rules/parser.js +2 -25
  220. package/codeyam-cli/src/utils/rules/parser.js.map +1 -1
  221. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  222. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  223. package/codeyam-cli/src/utils/rules/staleness.js +16 -11
  224. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -1
  225. package/codeyam-cli/src/utils/serverState.js +37 -10
  226. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  227. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +21 -44
  228. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  229. package/codeyam-cli/src/webserver/app/lib/database.js +15 -3
  230. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  231. package/codeyam-cli/src/webserver/backgroundServer.js +24 -0
  232. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  233. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CA3JxPb7.js +1 -0
  234. package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-DsN1wKrm.js → EntityItem-B86KKU7e.js} +1 -1
  235. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-B5ctlSYt.js} +1 -1
  236. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-BqY8gDAW.js} +1 -1
  237. package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-C8lyxW9k.js → InlineSpinner-ClaLpuOo.js} +1 -1
  238. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-BDhPilK7.js} +2 -2
  239. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-VeqEBv9v.js} +1 -1
  240. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-Bs7Nn1Jr.js} +1 -1
  241. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-Bm3PmcCz.js} +1 -1
  242. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-OApQuNyq.js → ReportIssueModal-CgMEzchJ.js} +3 -8
  243. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-Gq3Ocjo6.js} +1 -1
  244. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DzccYyI8.js → ScenarioViewer-CBui0id_.js} +2 -2
  245. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-CiwXDxLh.js} +1 -1
  246. package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-B3TDXxnk.js} +1 -1
  247. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BwavGCpm.js → activity.(_tab)-BtBFH820.js} +6 -11
  248. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-CN61MOMa.js +11 -0
  249. package/codeyam-cli/src/webserver/build/client/assets/api.agent-transcripts-l0sNRNKZ.js +1 -0
  250. package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
  251. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  252. package/codeyam-cli/src/webserver/build/client/assets/book-open-PttOB2SF.js +6 -0
  253. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-TJp6ofnp.js} +1 -1
  254. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-JE9ZIoBl.js} +12 -12
  255. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-CXhHQYrI.js} +1 -1
  256. package/codeyam-cli/src/webserver/build/client/assets/copy-6y9ALfGT.js +11 -0
  257. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-Ca9fAY46.js} +1 -1
  258. package/codeyam-cli/src/webserver/build/client/assets/{dev.empty-BBnGWYga.js → dev.empty-C0epRiVn.js} +1 -1
  259. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-BJUiQqZF.js → entity._sha._-BVnB8a9L.js} +10 -10
  260. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js → entity._sha.scenarios._scenarioId.fullscreen-CBoafmVs.js} +1 -1
  261. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-D1T4TGjf.js → entity._sha_.create-scenario-DGgZjdFg.js} +1 -1
  262. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-38yPijoD.js} +1 -1
  263. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-BSHEfydn.js} +1 -1
  264. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-DCPhhSMo.js} +1 -1
  265. package/codeyam-cli/src/webserver/build/client/assets/{files-CJ6lTdTA.js → files-0N0YJQv7.js} +1 -1
  266. package/codeyam-cli/src/webserver/build/client/assets/{git-CPTZZ-JZ.js → git-DXnyr8uP.js} +1 -1
  267. package/codeyam-cli/src/webserver/build/client/assets/globals-CKT08Djd.css +1 -0
  268. package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-CcsFv748.js} +1 -1
  269. package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-ChN9-fAY.js} +1 -1
  270. package/codeyam-cli/src/webserver/build/client/assets/labs-BLJ7HxOC.js +1 -0
  271. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-CTqLEAGU.js} +1 -1
  272. package/codeyam-cli/src/webserver/build/client/assets/manifest-b171b9d3.js +1 -0
  273. package/codeyam-cli/src/webserver/build/client/assets/memory-CCQd4aZA.js +78 -0
  274. package/codeyam-cli/src/webserver/build/client/assets/pause-D6vreykR.js +11 -0
  275. package/codeyam-cli/src/webserver/build/client/assets/root-CHhiHoo_.js +62 -0
  276. package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-B8VUL8nl.js} +1 -1
  277. package/codeyam-cli/src/webserver/build/client/assets/settings-BejnUJ6R.js +1 -0
  278. package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-CPoAg7Zo.js} +1 -1
  279. package/codeyam-cli/src/webserver/build/client/assets/terminal-BrCP7uQo.js +11 -0
  280. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-BZz2NjYa.js} +1 -1
  281. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-DNwUduNu.js} +1 -1
  282. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-aSv48UbS.js → useLastLogLine-COky1GVF.js} +1 -1
  283. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-CpZgwliL.js} +1 -1
  284. package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-Bv9JFvUO.js} +1 -1
  285. package/codeyam-cli/src/webserver/build/server/assets/{index-DVzYx8PN.js → index-8Fv-lH1-.js} +1 -1
  286. package/codeyam-cli/src/webserver/build/server/assets/server-build-Akn3iYFP.js +257 -0
  287. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  288. package/codeyam-cli/src/webserver/build-info.json +5 -5
  289. package/codeyam-cli/templates/{codeyam:debug.md → codeyam-debug.md} +1 -1
  290. package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
  291. package/codeyam-cli/templates/codeyam-memory-hook.sh +19 -20
  292. package/codeyam-cli/templates/codeyam-memory.md +392 -0
  293. package/codeyam-cli/templates/codeyam-new-rule.md +13 -0
  294. package/codeyam-cli/templates/{codeyam:setup.md → codeyam-setup.md} +13 -1
  295. package/codeyam-cli/templates/{codeyam:sim.md → codeyam-sim.md} +1 -1
  296. package/codeyam-cli/templates/{codeyam:test.md → codeyam-test.md} +1 -1
  297. package/codeyam-cli/templates/{codeyam:verify.md → codeyam-verify.md} +1 -1
  298. package/codeyam-cli/templates/rule-notification-hook.py +56 -0
  299. package/codeyam-cli/templates/rule-reflection-hook.py +627 -0
  300. package/codeyam-cli/templates/rules-instructions.md +132 -0
  301. package/package.json +2 -2
  302. package/packages/ai/index.js +3 -2
  303. package/packages/ai/index.js.map +1 -1
  304. package/packages/ai/src/lib/analyzeScope.js +50 -13
  305. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  306. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +54 -8
  307. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  308. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  309. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  310. package/packages/ai/src/lib/astScopes/processExpression.js +317 -44
  311. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  312. package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
  313. package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
  314. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +763 -171
  315. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  316. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
  317. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  318. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js +13 -3
  319. package/packages/ai/src/lib/dataStructure/helpers/BatchSchemaProcessor.js.map +1 -1
  320. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js +6 -4
  321. package/packages/ai/src/lib/dataStructure/helpers/ScopeTreeManager.js.map +1 -1
  322. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +33 -3
  323. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  324. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +36 -11
  325. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  326. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  327. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  328. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +113 -11
  329. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  330. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +173 -0
  331. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -0
  332. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js +37 -20
  333. package/packages/ai/src/lib/dataStructure/helpers/deduplicateFunctionSchemas.js.map +1 -1
  334. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +309 -84
  335. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  336. package/packages/ai/src/lib/dataStructureChunking.js +26 -11
  337. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  338. package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
  339. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  340. package/packages/ai/src/lib/generateEntityScenarioData.js +227 -4
  341. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  342. package/packages/ai/src/lib/generateEntityScenarios.js +7 -1
  343. package/packages/ai/src/lib/generateEntityScenarios.js.map +1 -1
  344. package/packages/ai/src/lib/generateExecutionFlows.js +26 -4
  345. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  346. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +447 -80
  347. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  348. package/packages/ai/src/lib/isolateScopes.js +39 -3
  349. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  350. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
  351. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
  352. package/packages/ai/src/lib/mergeStatements.js +70 -51
  353. package/packages/ai/src/lib/mergeStatements.js.map +1 -1
  354. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
  355. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
  356. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js +10 -4
  357. package/packages/ai/src/lib/promptGenerators/gatherAttributesMap.js.map +1 -1
  358. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
  359. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  360. package/packages/ai/src/lib/resolvePathToControllable.js +24 -14
  361. package/packages/ai/src/lib/resolvePathToControllable.js.map +1 -1
  362. package/packages/ai/src/lib/worker/SerializableDataStructure.js.map +1 -1
  363. package/packages/analyze/index.js +1 -0
  364. package/packages/analyze/index.js.map +1 -1
  365. package/packages/analyze/src/lib/FileAnalyzer.js +60 -36
  366. package/packages/analyze/src/lib/FileAnalyzer.js.map +1 -1
  367. package/packages/analyze/src/lib/ProjectAnalyzer.js +96 -26
  368. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  369. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js +14 -0
  370. package/packages/analyze/src/lib/asts/sourceFiles/getAllDeclaredEntityNodes.js.map +1 -1
  371. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js +14 -0
  372. package/packages/analyze/src/lib/asts/sourceFiles/getAllEntityNodes.js.map +1 -1
  373. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js +6 -0
  374. package/packages/analyze/src/lib/asts/sourceFiles/getAllExports.js.map +1 -1
  375. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js +6 -0
  376. package/packages/analyze/src/lib/asts/sourceFiles/getImportsAnalysis.js.map +1 -1
  377. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js +39 -1
  378. package/packages/analyze/src/lib/asts/sourceFiles/getResolvedModule.js.map +1 -1
  379. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js +2 -1
  380. package/packages/analyze/src/lib/asts/sourceFiles/getSourceFilesForAllImports.js.map +1 -1
  381. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +65 -7
  382. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  383. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +17 -4
  384. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  385. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +2 -1
  386. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  387. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js +0 -3
  388. package/packages/analyze/src/lib/files/analyze/validateDependencyAnalyses.js.map +1 -1
  389. package/packages/analyze/src/lib/files/analyzeRemixRoute.js +3 -2
  390. package/packages/analyze/src/lib/files/analyzeRemixRoute.js.map +1 -1
  391. package/packages/analyze/src/lib/files/getImportedExports.js +11 -7
  392. package/packages/analyze/src/lib/files/getImportedExports.js.map +1 -1
  393. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
  394. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  395. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +56 -10
  396. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  397. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +33 -8
  398. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  399. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +150 -17
  400. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  401. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +56 -8
  402. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  403. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +399 -31
  404. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  405. package/packages/analyze/src/lib/files/setImportedExports.js +2 -1
  406. package/packages/analyze/src/lib/files/setImportedExports.js.map +1 -1
  407. package/packages/analyze/src/lib/index.js +1 -0
  408. package/packages/analyze/src/lib/index.js.map +1 -1
  409. package/packages/analyze/src/lib/utils/getFileByPath.js +12 -0
  410. package/packages/analyze/src/lib/utils/getFileByPath.js.map +1 -0
  411. package/packages/database/src/lib/analysisBranchToDb.js +1 -1
  412. package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
  413. package/packages/database/src/lib/analysisToDb.js +1 -1
  414. package/packages/database/src/lib/analysisToDb.js.map +1 -1
  415. package/packages/database/src/lib/branchToDb.js +1 -1
  416. package/packages/database/src/lib/branchToDb.js.map +1 -1
  417. package/packages/database/src/lib/commitBranchToDb.js +1 -1
  418. package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
  419. package/packages/database/src/lib/commitToDb.js +1 -1
  420. package/packages/database/src/lib/commitToDb.js.map +1 -1
  421. package/packages/database/src/lib/fileToDb.js +1 -1
  422. package/packages/database/src/lib/fileToDb.js.map +1 -1
  423. package/packages/database/src/lib/kysely/db.js +3 -0
  424. package/packages/database/src/lib/kysely/db.js.map +1 -1
  425. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  426. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  427. package/packages/database/src/lib/projectToDb.js +1 -1
  428. package/packages/database/src/lib/projectToDb.js.map +1 -1
  429. package/packages/database/src/lib/saveFiles.js +1 -1
  430. package/packages/database/src/lib/saveFiles.js.map +1 -1
  431. package/packages/database/src/lib/scenarioToDb.js +1 -1
  432. package/packages/database/src/lib/scenarioToDb.js.map +1 -1
  433. package/scripts/finalize-analyzer.cjs +8 -76
  434. package/codeyam-cli/src/webserver/build/client/assets/copy-Bb-80kDT.js +0 -6
  435. package/codeyam-cli/src/webserver/build/client/assets/file-code-Dhef1kWN.js +0 -6
  436. package/codeyam-cli/src/webserver/build/client/assets/globals-D3yhhV8x.css +0 -1
  437. package/codeyam-cli/src/webserver/build/client/assets/manifest-7522edd4.js +0 -1
  438. package/codeyam-cli/src/webserver/build/client/assets/memory-yxFcrxBX.js +0 -92
  439. package/codeyam-cli/src/webserver/build/client/assets/root-eVAaavTS.js +0 -62
  440. package/codeyam-cli/src/webserver/build/client/assets/settings-CS5f3WzT.js +0 -1
  441. package/codeyam-cli/src/webserver/build/server/assets/server-build-4Cr0uToj.js +0 -257
  442. package/codeyam-cli/templates/codeyam:diagnose.md +0 -803
  443. package/codeyam-cli/templates/codeyam:memory.md +0 -462
  444. package/codeyam-cli/templates/codeyam:new-rule.md +0 -13
@@ -3,9 +3,11 @@ import type { ExecutionFlow, ScenariosDataStructure } from '~codeyam/types';
3
3
  // Type for a single required value from ExecutionFlow
4
4
  type RequiredValue = NonNullable<ExecutionFlow['requiredValues']>[number];
5
5
 
6
- const DEFAULT_MAX_KEYS_PER_CHUNK = 8;
6
+ const DEFAULT_MAX_CHUNK_SIZE = 10_000; // ~10K chars per chunk
7
7
 
8
8
  export interface ChunkOptions {
9
+ maxChunkSize?: number;
10
+ /** @deprecated Use maxChunkSize instead. Kept for backward compatibility in tests. */
9
11
  maxKeysPerChunk?: number;
10
12
  }
11
13
 
@@ -15,8 +17,12 @@ export interface ChunkOptions {
15
17
  * Large schemas overwhelm LLMs, causing them to make mistakes on some keys.
16
18
  * By processing smaller chunks, each key gets more focused attention.
17
19
  *
20
+ * Uses cumulative JSON size to decide chunk boundaries rather than a fixed
21
+ * key count, so a single oversized key gets its own chunk while many small
22
+ * keys are grouped together efficiently.
23
+ *
18
24
  * @param dataForMocks - The full data structure schema
19
- * @param options - Chunking options (maxKeysPerChunk defaults to 8)
25
+ * @param options - Chunking options (maxChunkSize defaults to 10_000)
20
26
  * @returns Array of smaller data structure chunks
21
27
  */
22
28
  export function chunkDataStructure(
@@ -27,27 +33,39 @@ export function chunkDataStructure(
27
33
  return [dataForMocks];
28
34
  }
29
35
 
30
- const { maxKeysPerChunk = DEFAULT_MAX_KEYS_PER_CHUNK } = options;
36
+ const { maxChunkSize = DEFAULT_MAX_CHUNK_SIZE } = options;
31
37
  const keys = Object.keys(dataForMocks);
32
38
 
33
- // Don't chunk if already small enough
34
- if (keys.length <= maxKeysPerChunk) {
39
+ // Calculate total size to see if chunking is needed
40
+ const totalSize = JSON.stringify(dataForMocks).length;
41
+ if (totalSize <= maxChunkSize) {
35
42
  return [dataForMocks];
36
43
  }
37
44
 
45
+ // Greedily pack keys into chunks by cumulative size
38
46
  const chunks: Array<ScenariosDataStructure['dataForMocks']> = [];
39
-
40
- for (let i = 0; i < keys.length; i += maxKeysPerChunk) {
41
- const chunkKeys = keys.slice(i, i + maxKeysPerChunk);
42
- const chunk: ScenariosDataStructure['dataForMocks'] = {};
43
-
44
- for (const key of chunkKeys) {
45
- (chunk as Record<string, unknown>)[key] = (
46
- dataForMocks as Record<string, unknown>
47
- )[key];
47
+ let currentChunk: Record<string, unknown> = {};
48
+ let currentSize = 0;
49
+
50
+ for (const key of keys) {
51
+ const keySize = JSON.stringify(
52
+ (dataForMocks as Record<string, unknown>)[key],
53
+ ).length;
54
+
55
+ // If adding this key would exceed the limit AND chunk isn't empty, start a new chunk
56
+ if (currentSize > 0 && currentSize + keySize > maxChunkSize) {
57
+ chunks.push(currentChunk as ScenariosDataStructure['dataForMocks']);
58
+ currentChunk = {};
59
+ currentSize = 0;
48
60
  }
49
61
 
50
- chunks.push(chunk);
62
+ currentChunk[key] = (dataForMocks as Record<string, unknown>)[key];
63
+ currentSize += keySize;
64
+ }
65
+
66
+ // Push the last chunk
67
+ if (Object.keys(currentChunk).length > 0) {
68
+ chunks.push(currentChunk as ScenariosDataStructure['dataForMocks']);
51
69
  }
52
70
 
53
71
  return chunks;
@@ -1,9 +1,12 @@
1
1
  import { Entity } from '~codeyam/types';
2
2
  import isolateScopes from './isolateScopes';
3
3
  import analyzeScope from './analyzeScope';
4
- import { FileAnalyzer } from '~codeyam/analyze';
4
+ import { FileAnalyzer, transformationTracer } from '~codeyam/analyze';
5
5
  import { AI, SerializableDataStructure } from '~codeyam/ai';
6
- import { resetScopeDataStructureMetrics } from './dataStructure/ScopeDataStructure';
6
+ import {
7
+ resetScopeDataStructureMetrics,
8
+ ScopeDataStructure,
9
+ } from './dataStructure/ScopeDataStructure';
7
10
 
8
11
  // import { awsLog } from '~codeyam/utils';
9
12
 
@@ -91,8 +94,60 @@ export default async function generateEntityDataStructure({
91
94
  }
92
95
 
93
96
  // Inspect the runtime type of dataStructure to see if it must be serialized
97
+ // Note: When worker threads are used, dataStructure is already serialized (no toSerializable).
98
+ // Workers are disabled when CODEYAM_TRACE_TRANSFORMS=1 to enable full tracing.
94
99
  if ('toSerializable' in entityScope.dataStructure) {
95
- return entityScope.dataStructure.toSerializable();
100
+ const scopeDataStructure =
101
+ entityScope.dataStructure as unknown as ScopeDataStructure;
102
+
103
+ // Trace the internal state BEFORE serialization - captures what methods return
104
+ if (transformationTracer.isEnabled()) {
105
+ transformationTracer.startEntity({
106
+ name: entity.name,
107
+ entityType: entity.entityType ?? 'unknown',
108
+ filePath: entity.filePath,
109
+ });
110
+
111
+ // Capture internal state - this is what getReturnValue/getFunctionSignature return
112
+ transformationTracer.snapshot(entity.name, 'scopeDataStructure', {
113
+ signatureSchema: scopeDataStructure.getFunctionSignature({
114
+ fillInUnknowns: true,
115
+ }),
116
+ returnValueSchema: scopeDataStructure.getReturnValue({
117
+ fillInUnknowns: true,
118
+ }),
119
+ });
120
+ }
121
+
122
+ const serialized = scopeDataStructure.toSerializable();
123
+
124
+ // Trace AFTER serialization - shows what gets output
125
+ if (transformationTracer.isEnabled()) {
126
+ // Build schema from external function calls for comparison
127
+ const externalSchemas: Record<string, string> = {};
128
+ for (const efc of serialized.externalFunctionCalls ?? []) {
129
+ for (const [path, type] of Object.entries(efc.schema ?? {})) {
130
+ externalSchemas[path] = type;
131
+ }
132
+ }
133
+
134
+ transformationTracer.snapshot(entity.name, 'serialized', {
135
+ signatureSchema:
136
+ serialized.functionResults?.[entity.name]?.signatureWithUnknowns,
137
+ returnValueSchema:
138
+ serialized.functionResults?.[entity.name]?.returnValueWithUnknowns,
139
+ // Include external function schemas to detect serialization gaps
140
+ dependencySchemas: {
141
+ externalFunctions: {
142
+ combined: {
143
+ returnValueSchema: externalSchemas,
144
+ },
145
+ },
146
+ },
147
+ });
148
+ }
149
+
150
+ return serialized;
96
151
  }
97
152
  return entityScope.dataStructure;
98
153
  }
@@ -16,7 +16,9 @@ import validateJson from './validateJson';
16
16
  import { awsLog, awsLogDebugLevel } from '~codeyam/utils';
17
17
  import { AI, parseJsonSafe } from '~codeyam/ai';
18
18
  import convertNullToUndefinedBySchema from './dataStructure/helpers/convertNullToUndefinedBySchema';
19
+ import convertTypeAnnotationsToValues from './dataStructure/helpers/convertTypeAnnotationsToValues';
19
20
  import fixNullIdsBySchema from './dataStructure/helpers/fixNullIdsBySchema';
21
+ import coerceObjectsToPrimitivesBySchema from './dataStructure/helpers/coerceObjectsToPrimitivesBySchema';
20
22
  import { JsonTypeDefinition } from '~codeyam/types';
21
23
  import { deepMerge } from '~codeyam/generate';
22
24
  import {
@@ -292,11 +294,13 @@ function generateDefaultForSchemaType(schemaType: unknown): unknown {
292
294
  if (schemaType.includes('| null')) return null;
293
295
  return schemaType; // Return the type as a string placeholder
294
296
  }
295
- if (
296
- typeof schemaType === 'object' &&
297
- schemaType !== null &&
298
- !Array.isArray(schemaType)
299
- ) {
297
+ if (Array.isArray(schemaType)) {
298
+ if (schemaType.length === 0) return [];
299
+ // Generate a single default element based on the first element's schema
300
+ const elementDefault = generateDefaultForSchemaType(schemaType[0]);
301
+ return elementDefault !== undefined ? [elementDefault] : [];
302
+ }
303
+ if (typeof schemaType === 'object' && schemaType !== null) {
300
304
  // Recursively generate defaults for nested objects
301
305
  const result: Record<string, unknown> = {};
302
306
  for (const [key, value] of Object.entries(schemaType)) {
@@ -424,6 +428,8 @@ function fillMissingMockDataKeysWithDefaults(
424
428
  const missingKeys: string[] = [];
425
429
 
426
430
  for (const key of Object.keys(dataForMocks)) {
431
+ if (key === '_nullable') continue; // Internal marker, not a data key
432
+
427
433
  const fullPath = pathPrefix ? `${pathPrefix}.${key}` : key;
428
434
 
429
435
  if (mockData[key] === undefined) {
@@ -459,6 +465,193 @@ function fillMissingMockDataKeysWithDefaults(
459
465
  }
460
466
  }
461
467
 
468
+ /**
469
+ * Enforce execution flow requiredValues by setting falsy paths to null.
470
+ *
471
+ * The LLM doesn't reliably generate null for `comparison: 'falsy'` requirements.
472
+ * For example, a flow like "diffView: falsy" should hide a modal, but the LLM
473
+ * might generate a truthy object, causing the modal to show in all screenshots.
474
+ *
475
+ * This function:
476
+ * 1. Gets requiredValues from covered flows
477
+ * 2. For 'falsy' comparisons: sets the value to null
478
+ * 3. For 'truthy' comparisons with falsy values: generates a default truthy value
479
+ */
480
+ function enforceRequiredValues(
481
+ mockData: Record<string, unknown>,
482
+ coveredFlowIds: string[],
483
+ executionFlows: ExecutionFlow[],
484
+ ): void {
485
+ if (!coveredFlowIds.length || !executionFlows.length) {
486
+ return;
487
+ }
488
+
489
+ // Get all requiredValues from covered flows
490
+ const coveredFlows = executionFlows.filter((flow) =>
491
+ coveredFlowIds.includes(flow.id),
492
+ );
493
+
494
+ for (const flow of coveredFlows) {
495
+ if (!flow.requiredValues) continue;
496
+
497
+ for (const rv of flow.requiredValues) {
498
+ if (!rv.attributePath) continue;
499
+
500
+ // Find the value in mockData - the path could be nested
501
+ // e.g., attributePath: "diffView" could be at mockData['useDiffModal()'].diffView
502
+ const result = findAndSetValueInMockData(
503
+ mockData,
504
+ rv.attributePath,
505
+ rv.comparison,
506
+ rv.valueType,
507
+ );
508
+
509
+ if (result.found) {
510
+ awsLog(
511
+ `CodeYam: Enforced ${rv.comparison} for ${rv.attributePath} (set to ${result.newValue === null ? 'null' : typeof result.newValue})`,
512
+ );
513
+ }
514
+ }
515
+ }
516
+ }
517
+
518
+ /**
519
+ * Find a value in mockData by attributePath and enforce the comparison.
520
+ * The attributePath could be a simple key or a nested path.
521
+ *
522
+ * Returns { found: boolean, newValue: unknown }
523
+ */
524
+ function findAndSetValueInMockData(
525
+ mockData: Record<string, unknown>,
526
+ attributePath: string,
527
+ comparison: string,
528
+ valueType?: string,
529
+ ): { found: boolean; newValue?: unknown } {
530
+ // Try to find the path at various nesting levels
531
+ // The attributePath might be "diffView" but the actual location is
532
+ // mockData['useDiffModal()'].diffView
533
+
534
+ // Strategy 1: Direct path (e.g., mockData[attributePath])
535
+ if (attributePath in mockData) {
536
+ const currentValue = mockData[attributePath];
537
+ const { shouldChange, newValue } = getEnforcedValue(
538
+ currentValue,
539
+ comparison,
540
+ valueType,
541
+ );
542
+ if (shouldChange) {
543
+ mockData[attributePath] = newValue;
544
+ return { found: true, newValue };
545
+ }
546
+ return { found: true, newValue: currentValue };
547
+ }
548
+
549
+ // Strategy 2: Search in nested objects
550
+ for (const [key, value] of Object.entries(mockData)) {
551
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
552
+ const nestedObj = value as Record<string, unknown>;
553
+
554
+ // Check if attributePath exists in this nested object
555
+ if (attributePath in nestedObj) {
556
+ const currentValue = nestedObj[attributePath];
557
+ const { shouldChange, newValue } = getEnforcedValue(
558
+ currentValue,
559
+ comparison,
560
+ valueType,
561
+ );
562
+ if (shouldChange) {
563
+ nestedObj[attributePath] = newValue;
564
+ return { found: true, newValue };
565
+ }
566
+ return { found: true, newValue: currentValue };
567
+ }
568
+
569
+ // Also check dot-notation paths (e.g., "diffView.type")
570
+ if (attributePath.includes('.')) {
571
+ const parts = attributePath.split('.');
572
+ const firstPart = parts[0];
573
+ if (firstPart in nestedObj) {
574
+ // Recurse with the rest of the path
575
+ const result = findAndSetValueInMockData(
576
+ nestedObj,
577
+ attributePath,
578
+ comparison,
579
+ valueType,
580
+ );
581
+ if (result.found) return result;
582
+ }
583
+ }
584
+
585
+ // Recursively search deeper
586
+ const result = findAndSetValueInMockData(
587
+ nestedObj,
588
+ attributePath,
589
+ comparison,
590
+ valueType,
591
+ );
592
+ if (result.found) return result;
593
+ }
594
+ }
595
+
596
+ return { found: false };
597
+ }
598
+
599
+ /**
600
+ * Determine if a value should be changed to match a comparison requirement.
601
+ *
602
+ * For 'falsy' comparison: truthy values should become null
603
+ * For 'truthy' comparison: falsy values should become a default truthy value
604
+ */
605
+ function getEnforcedValue(
606
+ currentValue: unknown,
607
+ comparison: string,
608
+ valueType?: string,
609
+ ): { shouldChange: boolean; newValue: unknown } {
610
+ const isTruthy = Boolean(currentValue);
611
+
612
+ if (comparison === 'falsy') {
613
+ // Value should be falsy
614
+ if (isTruthy) {
615
+ return { shouldChange: true, newValue: null };
616
+ }
617
+ return { shouldChange: false, newValue: currentValue };
618
+ }
619
+
620
+ if (comparison === 'truthy') {
621
+ // Value should be truthy
622
+ if (!isTruthy) {
623
+ // Generate a default truthy value based on valueType
624
+ const defaultValue = generateDefaultTruthyValue(valueType);
625
+ return { shouldChange: true, newValue: defaultValue };
626
+ }
627
+ return { shouldChange: false, newValue: currentValue };
628
+ }
629
+
630
+ // For other comparisons (equals, exists, etc.), don't auto-enforce
631
+ return { shouldChange: false, newValue: currentValue };
632
+ }
633
+
634
+ /**
635
+ * Generate a default truthy value for a given type.
636
+ */
637
+ function generateDefaultTruthyValue(valueType?: string): unknown {
638
+ if (!valueType) return { _placeholder: true };
639
+
640
+ switch (valueType.toLowerCase()) {
641
+ case 'string':
642
+ return 'default-value';
643
+ case 'number':
644
+ return 1;
645
+ case 'boolean':
646
+ return true;
647
+ case 'array':
648
+ return [{ _placeholder: true }];
649
+ case 'object':
650
+ default:
651
+ return { _placeholder: true };
652
+ }
653
+ }
654
+
462
655
  type ScenarioDataWithoutDescription = Omit<ScenarioData, 'scenarioDescription'>;
463
656
 
464
657
  interface GenerateEntityScenarioDataArgs {
@@ -652,6 +845,29 @@ export async function generateDataForScenario({
652
845
  }
653
846
  }
654
847
 
848
+ // Detect keys that were lost from failed or partial chunk responses
849
+ // and fill them with schema-based defaults so they aren't permanently lost.
850
+ const allChunkedKeys = chunks.flatMap((c) => Object.keys(c || {}));
851
+ const returnedKeys = new Set(Object.keys(chunkedMockData));
852
+ const missingChunkKeys = allChunkedKeys.filter(
853
+ (k) => !returnedKeys.has(k),
854
+ );
855
+
856
+ if (missingChunkKeys.length > 0) {
857
+ awsLog(
858
+ `Chunked processing: ${missingChunkKeys.length} key(s) missing from chunk results, filling with defaults: ${missingChunkKeys.join(', ')}`,
859
+ );
860
+ const dataForMocksRecord = structure.dataForMocks as Record<
861
+ string,
862
+ unknown
863
+ >;
864
+ for (const key of missingChunkKeys) {
865
+ chunkedMockData[key] = generateDefaultForSchemaType(
866
+ dataForMocksRecord[key],
867
+ );
868
+ }
869
+ }
870
+
655
871
  awsLog(
656
872
  `Chunked processing complete. Generated ${Object.keys(chunkedMockData).length} keys total`,
657
873
  );
@@ -869,6 +1085,19 @@ export async function generateDataForScenario({
869
1085
  );
870
1086
  }
871
1087
 
1088
+ // Coerce objects/arrays to primitives when the schema expects a primitive type.
1089
+ // The LLM sometimes generates an object where the schema expects "string",
1090
+ // e.g., { body: { "env": "production" } } instead of { body: "some string" }.
1091
+ // This causes runtime errors like "TypeError: body.match is not a function".
1092
+ // Must run BEFORE convertCommaSeparatedStringsToArrays, which intentionally
1093
+ // overrides schema types for array-like field names.
1094
+ if (structure.dataForMocks && fullScenarioData.data.mockData) {
1095
+ coerceObjectsToPrimitivesBySchema(
1096
+ fullScenarioData.data.mockData,
1097
+ structure.dataForMocks,
1098
+ );
1099
+ }
1100
+
872
1101
  // Convert comma-separated strings to arrays when appropriate.
873
1102
  // The LLM sometimes generates strings like "color,size" instead of arrays
874
1103
  // like ["color", "size"] when the schema type is incorrectly inferred as
@@ -878,6 +1107,16 @@ export async function generateDataForScenario({
878
1107
  convertCommaSeparatedStringsToArrays(fullScenarioData.data.mockData);
879
1108
  }
880
1109
 
1110
+ // Convert type annotation strings that appear as values to actual values.
1111
+ // The LLM sometimes echoes the schema type annotation as the value.
1112
+ // For example, if the schema says { filePath: "string | undefined" },
1113
+ // the LLM might return { filePath: "string | undefined" } instead of
1114
+ // generating an actual value. This converts those type strings to
1115
+ // appropriate default values (e.g., "string | undefined" → undefined).
1116
+ if (fullScenarioData.data.mockData) {
1117
+ convertTypeAnnotationsToValues(fullScenarioData.data.mockData);
1118
+ }
1119
+
881
1120
  // Fix null values for ID fields when the schema indicates they should be non-null.
882
1121
  // The LLM sometimes generates `null` for ID fields (e.g., `"id": null`) when
883
1122
  // the schema type is `"number"`. This causes runtime issues when code checks
@@ -886,6 +1125,18 @@ export async function generateDataForScenario({
886
1125
  fixNullIdsBySchema(fullScenarioData.data.mockData, structure.dataForMocks);
887
1126
  }
888
1127
 
1128
+ // Enforce execution flow requiredValues by setting falsy paths to null.
1129
+ // The LLM doesn't reliably generate null for falsy requirements (e.g., diffView: falsy
1130
+ // to hide a modal). This post-processing ensures that scenarios match their
1131
+ // covered flows' requiredValues.
1132
+ if (fullScenarioData.data.mockData && executionFlows) {
1133
+ enforceRequiredValues(
1134
+ fullScenarioData.data.mockData,
1135
+ scenario.metadata?.coveredFlows || [],
1136
+ executionFlows,
1137
+ );
1138
+ }
1139
+
889
1140
  if (structure.arguments && fullScenarioData.data.argumentsData) {
890
1141
  for (let i = 0; i < fullScenarioData.data.argumentsData.length; i++) {
891
1142
  if (structure.arguments[i]) {
@@ -1075,6 +1326,60 @@ export default async function generateEntityScenarioData({
1075
1326
  defaultScenarioData.data.argumentsData.map((arg) => ({ ...arg }));
1076
1327
  }
1077
1328
 
1329
+ // Enforce requiredValues AFTER merge for non-default scenarios
1330
+ // This ensures that if a non-default scenario doesn't cover a certain flow,
1331
+ // it inherits the enforcement from the default scenario
1332
+ if (scenarioData.data?.mockData && executionFlows) {
1333
+ // Get the flows covered by this scenario
1334
+ const scenarioCoveredFlows =
1335
+ nonDefaultScenarios.find(
1336
+ (s) => s.name === result.scenarioData.scenarioDescription,
1337
+ )?.metadata?.coveredFlows || [];
1338
+
1339
+ // Get the paths that the scenario's flows affect
1340
+ const scenarioAffectedPaths = new Set<string>();
1341
+ for (const flowId of scenarioCoveredFlows) {
1342
+ const flow = executionFlows.find((f) => f.id === flowId);
1343
+ if (flow?.requiredValues) {
1344
+ for (const rv of flow.requiredValues) {
1345
+ if (rv.attributePath) {
1346
+ // Extract base path (e.g., "diffView" from "diffView.type")
1347
+ const basePath = rv.attributePath.split('.')[0];
1348
+ scenarioAffectedPaths.add(basePath);
1349
+ }
1350
+ }
1351
+ }
1352
+ }
1353
+
1354
+ // Get the default scenario's flows
1355
+ const defaultCoveredFlows =
1356
+ defaultScenario.metadata?.coveredFlows || [];
1357
+
1358
+ // For paths NOT affected by the scenario, apply default's enforcement
1359
+ const defaultFlowsForUnaffectedPaths = defaultCoveredFlows.filter(
1360
+ (flowId) => {
1361
+ const flow = executionFlows.find((f) => f.id === flowId);
1362
+ if (!flow?.requiredValues) return false;
1363
+
1364
+ // Check if this flow affects a path that the scenario doesn't cover
1365
+ return flow.requiredValues.some((rv) => {
1366
+ if (!rv.attributePath) return false;
1367
+ const basePath = rv.attributePath.split('.')[0];
1368
+ return !scenarioAffectedPaths.has(basePath);
1369
+ });
1370
+ },
1371
+ );
1372
+
1373
+ // Apply enforcement from default scenario for unaffected paths
1374
+ if (defaultFlowsForUnaffectedPaths.length > 0) {
1375
+ enforceRequiredValues(
1376
+ scenarioData.data.mockData,
1377
+ defaultFlowsForUnaffectedPaths,
1378
+ executionFlows,
1379
+ );
1380
+ }
1381
+ }
1382
+
1078
1383
  return scenarioData;
1079
1384
  });
1080
1385
 
@@ -1104,7 +1409,8 @@ Generate COMPLETE, robust data for the entire data structure.
1104
1409
  : `## Non-Default Scenario
1105
1410
  Generate ONLY the differences from the default scenario.
1106
1411
  - Include only fields that need to change
1107
- - Set to \`null\` to remove data
1412
+ - For object/scalar fields: set to \`null\` to remove/unset the data
1413
+ - For array fields: use \`[]\` for empty arrays (not \`null\`) unless the schema type explicitly includes \`| null\`
1108
1414
  - Omit unchanged fields—they merge from default`;
1109
1415
 
1110
1416
  // Only include the "NO ERROR DATA" instruction when the scenario doesn't require error data
@@ -1188,6 +1494,7 @@ Use simple elements only (\`<div>\`, \`<span>\`). No custom components.
1188
1494
  - Arrays should have many items (at least 4) unless specified otherwise
1189
1495
  - Each item must follow the exact structure provided
1190
1496
  - In general we want robust data, not minimal data unless specified otherwise
1497
+ - For empty arrays, use \`[]\` (not \`null\`) unless the schema type explicitly includes \`| null\` and the scenario requires the attribute be removed
1191
1498
 
1192
1499
  ## CRITICAL: Preserve Exact Structure
1193
1500
  Your response MUST mirror the EXACT nested structure provided in mockData Structure.
@@ -1267,6 +1574,7 @@ Use simple elements only (\`<div>\`, \`<span>\`). No custom components.
1267
1574
  ### Arrays
1268
1575
  - Arrays should have many items (at least 4) unless specified otherwise
1269
1576
  - Each item must follow the exact structure provided
1577
+ - For empty arrays, use \`[]\` (not \`null\`) unless the schema type explicitly includes \`| null\` and the scenario requires the attribute be removed
1270
1578
 
1271
1579
  ## CRITICAL: Preserve Exact Structure
1272
1580
  Your response MUST mirror the EXACT nested structure provided for the missing keys.
@@ -1395,4 +1703,5 @@ NEVER include "error" fields in responses. Skip them entirely.
1395
1703
  - No \`undefined\`—use \`null\` or omit
1396
1704
  - Generate data for ALL keys in the chunk (don't skip any)
1397
1705
  - Arrays should have many items (at least 4) unless specified otherwise
1706
+ - For empty arrays, use \`[]\` (not \`null\`) unless the schema type explicitly includes \`| null\` and the scenario requires the attribute be removed
1398
1707
  `;
@@ -176,11 +176,15 @@ export default async function generateEntityScenarios({
176
176
  return { scenarios: [], llmCall };
177
177
  }
178
178
 
179
- const scenarios = (
180
- result[
181
- `${error ? 'errorD' : 'd'}ataScenarios`
182
- ] as unknown as ScenarioResult[]
183
- ).map(
179
+ const dataScenarios = result[`${error ? 'errorD' : 'd'}ataScenarios`];
180
+
181
+ // Gracefully handle missing dataScenarios (e.g., when LLM returns unexpected format
182
+ // or when test fixtures don't include the expected key)
183
+ if (!Array.isArray(dataScenarios)) {
184
+ return { scenarios: [], llmCall };
185
+ }
186
+
187
+ const scenarios = (dataScenarios as unknown as ScenarioResult[]).map(
184
188
  (scenarioInfo) =>
185
189
  ({
186
190
  projectId: entity.projectId,