@codeyam/codeyam-cli 0.1.0-staging.2a88920 → 0.1.0-staging.4684848

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 (364) 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 +4 -4
  4. package/analyzer-template/packages/ai/index.ts +1 -0
  5. package/analyzer-template/packages/ai/package.json +2 -2
  6. package/analyzer-template/packages/ai/src/lib/analyzeScope.ts +23 -1
  7. package/analyzer-template/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.ts +10 -17
  8. package/analyzer-template/packages/ai/src/lib/astScopes/processExpression.ts +101 -0
  9. package/analyzer-template/packages/ai/src/lib/astScopes/sharedPatterns.ts +28 -0
  10. package/analyzer-template/packages/ai/src/lib/astScopes/types.ts +6 -0
  11. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +330 -9
  12. package/analyzer-template/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.ts +5 -1
  13. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.ts +11 -2
  14. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.ts +2 -2
  15. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.ts +70 -0
  16. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.ts +140 -14
  17. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.ts +20 -1
  18. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.ts +84 -19
  19. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +33 -15
  20. package/analyzer-template/packages/ai/src/lib/generateEntityDataStructure.ts +58 -3
  21. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +299 -5
  22. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +38 -2
  23. package/analyzer-template/packages/ai/src/lib/generateExecutionFlowsFromConditionals.ts +359 -142
  24. package/analyzer-template/packages/ai/src/lib/isolateScopes.ts +51 -3
  25. package/analyzer-template/packages/ai/src/lib/mergeJsonTypeDefinitions.ts +5 -0
  26. package/analyzer-template/packages/ai/src/lib/promptGenerators/collapseNullableObjects.ts +118 -0
  27. package/analyzer-template/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.ts +24 -4
  28. package/analyzer-template/packages/analyze/index.ts +2 -0
  29. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.ts +69 -3
  30. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +5 -0
  31. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +1315 -0
  32. package/analyzer-template/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.ts +4 -0
  33. package/analyzer-template/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.ts +59 -26
  34. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +194 -15
  35. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +372 -57
  36. package/analyzer-template/packages/analyze/src/lib/index.ts +1 -0
  37. package/analyzer-template/packages/database/package.json +1 -1
  38. package/analyzer-template/packages/database/src/lib/analysisBranchToDb.ts +1 -1
  39. package/analyzer-template/packages/database/src/lib/analysisToDb.ts +1 -1
  40. package/analyzer-template/packages/database/src/lib/branchToDb.ts +1 -1
  41. package/analyzer-template/packages/database/src/lib/commitBranchToDb.ts +1 -1
  42. package/analyzer-template/packages/database/src/lib/commitToDb.ts +1 -1
  43. package/analyzer-template/packages/database/src/lib/fileToDb.ts +1 -1
  44. package/analyzer-template/packages/database/src/lib/kysely/db.ts +6 -0
  45. package/analyzer-template/packages/database/src/lib/kysely/tables/debugReportsTable.ts +1 -1
  46. package/analyzer-template/packages/database/src/lib/kysely/tables/labsRequestsTable.ts +52 -0
  47. package/analyzer-template/packages/database/src/lib/projectToDb.ts +1 -1
  48. package/analyzer-template/packages/database/src/lib/saveFiles.ts +1 -1
  49. package/analyzer-template/packages/database/src/lib/scenarioToDb.ts +1 -1
  50. package/analyzer-template/packages/database/src/lib/userScenarioToDb.ts +1 -1
  51. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js +1 -1
  52. package/analyzer-template/packages/github/dist/database/src/lib/analysisBranchToDb.js.map +1 -1
  53. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js +1 -1
  54. package/analyzer-template/packages/github/dist/database/src/lib/analysisToDb.js.map +1 -1
  55. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js +1 -1
  56. package/analyzer-template/packages/github/dist/database/src/lib/branchToDb.js.map +1 -1
  57. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js +1 -1
  58. package/analyzer-template/packages/github/dist/database/src/lib/commitBranchToDb.js.map +1 -1
  59. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js +1 -1
  60. package/analyzer-template/packages/github/dist/database/src/lib/commitToDb.js.map +1 -1
  61. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js +1 -1
  62. package/analyzer-template/packages/github/dist/database/src/lib/fileToDb.js.map +1 -1
  63. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  64. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  65. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +3 -0
  66. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  67. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/debugReportsTable.d.ts +1 -1
  68. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts +23 -0
  69. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.d.ts.map +1 -0
  70. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  71. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  72. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js +1 -1
  73. package/analyzer-template/packages/github/dist/database/src/lib/projectToDb.js.map +1 -1
  74. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js +1 -1
  75. package/analyzer-template/packages/github/dist/database/src/lib/saveFiles.js.map +1 -1
  76. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js +1 -1
  77. package/analyzer-template/packages/github/dist/database/src/lib/scenarioToDb.js.map +1 -1
  78. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  79. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  80. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +7 -0
  81. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +7 -0
  82. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  83. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
  84. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +93 -2
  85. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  86. package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +108 -2
  87. package/analyzer-template/project/constructMockCode.ts +36 -1
  88. package/analyzer-template/project/writeMockDataTsx.ts +174 -12
  89. package/analyzer-template/project/writeScenarioComponents.ts +60 -12
  90. package/analyzer-template/project/writeSimpleRoot.ts +21 -11
  91. package/background/src/lib/local/createLocalAnalyzer.js +1 -1
  92. package/background/src/lib/local/createLocalAnalyzer.js.map +1 -1
  93. package/background/src/lib/virtualized/project/constructMockCode.js +30 -1
  94. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  95. package/background/src/lib/virtualized/project/writeMockDataTsx.js +156 -8
  96. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  97. package/background/src/lib/virtualized/project/writeScenarioComponents.js +60 -15
  98. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  99. package/background/src/lib/virtualized/project/writeSimpleRoot.js +21 -11
  100. package/background/src/lib/virtualized/project/writeSimpleRoot.js.map +1 -1
  101. package/codeyam-cli/scripts/apply-setup.js +180 -0
  102. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  103. package/codeyam-cli/src/cli.js +2 -0
  104. package/codeyam-cli/src/cli.js.map +1 -1
  105. package/codeyam-cli/src/codeyam-cli.js +18 -2
  106. package/codeyam-cli/src/codeyam-cli.js.map +1 -1
  107. package/codeyam-cli/src/commands/analyze.js +4 -2
  108. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  109. package/codeyam-cli/src/commands/baseline.js +2 -0
  110. package/codeyam-cli/src/commands/baseline.js.map +1 -1
  111. package/codeyam-cli/src/commands/debug.js +2 -0
  112. package/codeyam-cli/src/commands/debug.js.map +1 -1
  113. package/codeyam-cli/src/commands/default.js +31 -20
  114. package/codeyam-cli/src/commands/default.js.map +1 -1
  115. package/codeyam-cli/src/commands/detect-universal-mocks.js +2 -0
  116. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +1 -1
  117. package/codeyam-cli/src/commands/init.js +49 -257
  118. package/codeyam-cli/src/commands/init.js.map +1 -1
  119. package/codeyam-cli/src/commands/memory.js +17 -26
  120. package/codeyam-cli/src/commands/memory.js.map +1 -1
  121. package/codeyam-cli/src/commands/recapture.js +2 -0
  122. package/codeyam-cli/src/commands/recapture.js.map +1 -1
  123. package/codeyam-cli/src/commands/setup-sandbox.js +2 -0
  124. package/codeyam-cli/src/commands/setup-sandbox.js.map +1 -1
  125. package/codeyam-cli/src/commands/setup-simulations.js +284 -0
  126. package/codeyam-cli/src/commands/setup-simulations.js.map +1 -0
  127. package/codeyam-cli/src/commands/test-startup.js +2 -0
  128. package/codeyam-cli/src/commands/test-startup.js.map +1 -1
  129. package/codeyam-cli/src/commands/verify.js +14 -2
  130. package/codeyam-cli/src/commands/verify.js.map +1 -1
  131. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +128 -86
  132. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  133. package/codeyam-cli/src/utils/analyzer.js +7 -0
  134. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  135. package/codeyam-cli/src/utils/backgroundServer.js +9 -0
  136. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  137. package/codeyam-cli/src/utils/generateReport.js +2 -2
  138. package/codeyam-cli/src/utils/install-skills.js +57 -54
  139. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  140. package/codeyam-cli/src/utils/labsAutoCheck.js +19 -0
  141. package/codeyam-cli/src/utils/labsAutoCheck.js.map +1 -0
  142. package/codeyam-cli/src/utils/progress.js +7 -0
  143. package/codeyam-cli/src/utils/progress.js.map +1 -1
  144. package/codeyam-cli/src/utils/queue/job.js +4 -0
  145. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  146. package/codeyam-cli/src/utils/requireSimulations.js +10 -0
  147. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -0
  148. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js +82 -0
  149. package/codeyam-cli/src/utils/ruleReflection/__tests__/confusionDetector.test.js.map +1 -0
  150. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +230 -0
  151. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -0
  152. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +67 -0
  153. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -0
  154. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js +105 -0
  155. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/captureFixture.js.map +1 -0
  156. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js +34 -0
  157. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/loadCapturedFixture.js.map +1 -0
  158. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js +162 -0
  159. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/runClaude.js.map +1 -0
  160. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +75 -0
  161. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -0
  162. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +378 -0
  163. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -0
  164. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +115 -0
  165. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -0
  166. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js +127 -0
  167. package/codeyam-cli/src/utils/ruleReflection/__tests__/transcriptParser.test.js.map +1 -0
  168. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js +50 -0
  169. package/codeyam-cli/src/utils/ruleReflection/confusionDetector.js.map +1 -0
  170. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +116 -0
  171. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -0
  172. package/codeyam-cli/src/utils/ruleReflection/index.js +5 -0
  173. package/codeyam-cli/src/utils/ruleReflection/index.js.map +1 -0
  174. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js +44 -0
  175. package/codeyam-cli/src/utils/ruleReflection/promptBuilder.js.map +1 -0
  176. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js +85 -0
  177. package/codeyam-cli/src/utils/ruleReflection/transcriptParser.js.map +1 -0
  178. package/codeyam-cli/src/utils/ruleReflection/types.js +5 -0
  179. package/codeyam-cli/src/utils/ruleReflection/types.js.map +1 -0
  180. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js +293 -0
  181. package/codeyam-cli/src/utils/rules/__tests__/ruleState.test.js.map +1 -0
  182. package/codeyam-cli/src/utils/rules/index.js +1 -0
  183. package/codeyam-cli/src/utils/rules/index.js.map +1 -1
  184. package/codeyam-cli/src/utils/rules/parser.js +2 -25
  185. package/codeyam-cli/src/utils/rules/parser.js.map +1 -1
  186. package/codeyam-cli/src/utils/rules/ruleState.js +150 -0
  187. package/codeyam-cli/src/utils/rules/ruleState.js.map +1 -0
  188. package/codeyam-cli/src/utils/rules/staleness.js +16 -11
  189. package/codeyam-cli/src/utils/rules/staleness.js.map +1 -1
  190. package/codeyam-cli/src/utils/serverState.js +37 -10
  191. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  192. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +21 -44
  193. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  194. package/codeyam-cli/src/webserver/app/lib/database.js +15 -3
  195. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  196. package/codeyam-cli/src/webserver/backgroundServer.js +24 -0
  197. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  198. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CQ-wF3Tv.js +1 -0
  199. package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-DsN1wKrm.js → EntityItem-HdckCi0m.js} +1 -1
  200. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-DLqD3qNt.js → EntityTypeBadge-Dh5RJMOE.js} +1 -1
  201. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-Ba2JVPzP.js → EntityTypeIcon-BnjjBHJu.js} +1 -1
  202. package/codeyam-cli/src/webserver/build/client/assets/{InlineSpinner-C8lyxW9k.js → InlineSpinner-CUSfu6W5.js} +1 -1
  203. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-aht4aafF.js → InteractivePreview-Coll1aD6.js} +2 -2
  204. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CVtiBnY5.js → LibraryFunctionPreview-lYMY8h-y.js} +1 -1
  205. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-B0GLXMsr.js → LoadingDots-ay8XeA59.js} +1 -1
  206. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-xgeCVgSM.js → LogViewer-Dpul1_ik.js} +1 -1
  207. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-OApQuNyq.js → ReportIssueModal-CRBCfV2W.js} +3 -8
  208. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-DuDvi0jm.js → SafeScreenshot-DRTFDNFt.js} +1 -1
  209. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-DzccYyI8.js → ScenarioViewer-d6PSFxhS.js} +2 -2
  210. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-DyFZkK0l.js → TruncatedFilePath-DDEOQ6Iw.js} +1 -1
  211. package/codeyam-cli/src/webserver/build/client/assets/{_index-BwqWJOgH.js → _index-CkziGg5F.js} +1 -1
  212. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BwavGCpm.js → activity.(_tab)-B2v1pm9w.js} +6 -11
  213. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-BXIaK8Md.js +11 -0
  214. package/codeyam-cli/src/webserver/build/client/assets/api.agent-transcripts-l0sNRNKZ.js +1 -0
  215. package/codeyam-cli/src/webserver/build/client/assets/api.labs-unlock-l0sNRNKZ.js +1 -0
  216. package/codeyam-cli/src/webserver/build/client/assets/api.save-fixture-l0sNRNKZ.js +1 -0
  217. package/codeyam-cli/src/webserver/build/client/assets/book-open-qbapxy6o.js +6 -0
  218. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-Cx24_aWc.js → chevron-down-C-mKrwr1.js} +1 -1
  219. package/codeyam-cli/src/webserver/build/client/assets/{chunk-EPOLDU6W-CXRTFQ3F.js → chunk-JZWAC4HX-BAvUl1nT.js} +12 -12
  220. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BOARzkeR.js → circle-check-DlrT-SzI.js} +1 -1
  221. package/codeyam-cli/src/webserver/build/client/assets/copy-clIxnCqQ.js +11 -0
  222. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-BdhJEx6B.js → createLucideIcon-B931Etud.js} +1 -1
  223. package/codeyam-cli/src/webserver/build/client/assets/{dev.empty-BBnGWYga.js → dev.empty-BoPM6KnE.js} +1 -1
  224. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-oVRMh9Hl.js +16 -0
  225. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha.scenarios._scenarioId.fullscreen-DavjRmOY.js → entity._sha.scenarios._scenarioId.fullscreen-BjyzwQ7H.js} +1 -1
  226. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.create-scenario-D1T4TGjf.js → entity._sha_.create-scenario-DxuyDmZA.js} +1 -1
  227. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-CTBG2mmz.js → entity._sha_.edit._scenarioId-DESSZGQp.js} +1 -1
  228. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CS2cb_eZ.js → entry.client-D5Yb90Ad.js} +1 -1
  229. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-DMJ7zii9.js → fileTableUtils-DuObVYgh.js} +1 -1
  230. package/codeyam-cli/src/webserver/build/client/assets/{files-CJ6lTdTA.js → files-CDfz4Y-i.js} +1 -1
  231. package/codeyam-cli/src/webserver/build/client/assets/{git-CPTZZ-JZ.js → git-D6jOlDQw.js} +1 -1
  232. package/codeyam-cli/src/webserver/build/client/assets/globals-CKT08Djd.css +1 -0
  233. package/codeyam-cli/src/webserver/build/client/assets/{index-B1h680n5.js → index-DvOt1KIt.js} +1 -1
  234. package/codeyam-cli/src/webserver/build/client/assets/{index-lzqtyFU8.js → index-WfQFdoWK.js} +1 -1
  235. package/codeyam-cli/src/webserver/build/client/assets/labs-BbGyC1RY.js +1 -0
  236. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-B7B9V-bu.js → loader-circle-Bb7Y9k5O.js} +1 -1
  237. package/codeyam-cli/src/webserver/build/client/assets/manifest-fd06e67a.js +1 -0
  238. package/codeyam-cli/src/webserver/build/client/assets/memory-BXebUPaL.js +78 -0
  239. package/codeyam-cli/src/webserver/build/client/assets/pause-DaAHX2on.js +11 -0
  240. package/codeyam-cli/src/webserver/build/client/assets/root-CvNE9MaT.js +62 -0
  241. package/codeyam-cli/src/webserver/build/client/assets/{search-CxXUmBSd.js → search-DIqAPIrO.js} +1 -1
  242. package/codeyam-cli/src/webserver/build/client/assets/settings-DCIzBZM9.js +1 -0
  243. package/codeyam-cli/src/webserver/build/client/assets/{simulations-DwFIBT09.js → simulations-C6n_fNQY.js} +1 -1
  244. package/codeyam-cli/src/webserver/build/client/assets/terminal-CmPsszJy.js +11 -0
  245. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-B6LgvRJg.js → triangle-alert-Beg-oV50.js} +1 -1
  246. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-C1v1PQzo.js → useCustomSizes-D7TLbP3M.js} +1 -1
  247. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-aSv48UbS.js → useLastLogLine-Ce5rnai3.js} +1 -1
  248. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-DYxHZQuP.js → useReportContext-B4D3wj27.js} +1 -1
  249. package/codeyam-cli/src/webserver/build/client/assets/{useToast-mBRpZPiu.js → useToast-BDt_-DnY.js} +1 -1
  250. package/codeyam-cli/src/webserver/build/server/assets/{index-BM6TDT1Y.js → index-DDr9Cp9M.js} +1 -1
  251. package/codeyam-cli/src/webserver/build/server/assets/server-build-DjwiujaU.js +257 -0
  252. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  253. package/codeyam-cli/src/webserver/build-info.json +5 -5
  254. package/codeyam-cli/templates/{codeyam:debug.md → codeyam-debug.md} +1 -1
  255. package/codeyam-cli/templates/codeyam-diagnose.md +481 -0
  256. package/codeyam-cli/templates/codeyam-memory-hook.sh +19 -20
  257. package/codeyam-cli/templates/codeyam-memory.md +392 -0
  258. package/codeyam-cli/templates/{codeyam:new-rule.md → codeyam-new-rule.md} +2 -2
  259. package/codeyam-cli/templates/{codeyam:setup.md → codeyam-setup.md} +13 -1
  260. package/codeyam-cli/templates/{codeyam:sim.md → codeyam-sim.md} +1 -1
  261. package/codeyam-cli/templates/{codeyam:test.md → codeyam-test.md} +1 -1
  262. package/codeyam-cli/templates/{codeyam:verify.md → codeyam-verify.md} +1 -1
  263. package/codeyam-cli/templates/rule-notification-hook.py +56 -0
  264. package/codeyam-cli/templates/rule-reflection-hook.py +554 -87
  265. package/codeyam-cli/templates/rules-instructions.md +63 -24
  266. package/package.json +10 -10
  267. package/packages/ai/index.js +1 -1
  268. package/packages/ai/index.js.map +1 -1
  269. package/packages/ai/src/lib/analyzeScope.js +21 -1
  270. package/packages/ai/src/lib/analyzeScope.js.map +1 -1
  271. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js +10 -14
  272. package/packages/ai/src/lib/astScopes/patterns/forInStatementHandler.js.map +1 -1
  273. package/packages/ai/src/lib/astScopes/processExpression.js +78 -1
  274. package/packages/ai/src/lib/astScopes/processExpression.js.map +1 -1
  275. package/packages/ai/src/lib/astScopes/sharedPatterns.js +25 -0
  276. package/packages/ai/src/lib/astScopes/sharedPatterns.js.map +1 -1
  277. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +262 -8
  278. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  279. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js +5 -1
  280. package/packages/ai/src/lib/dataStructure/equivalencyManagers/frameworks/JavascriptFrameworkManager.js.map +1 -1
  281. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js +11 -2
  282. package/packages/ai/src/lib/dataStructure/helpers/cleanKnownObjectFunctions.js.map +1 -1
  283. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js +2 -2
  284. package/packages/ai/src/lib/dataStructure/helpers/cleanNonObjectFunctions.js.map +1 -1
  285. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js +63 -0
  286. package/packages/ai/src/lib/dataStructure/helpers/coerceObjectsToPrimitivesBySchema.js.map +1 -0
  287. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js +122 -12
  288. package/packages/ai/src/lib/dataStructure/helpers/convertDotNotation.js.map +1 -1
  289. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js +15 -1
  290. package/packages/ai/src/lib/dataStructure/helpers/convertTypeAnnotationsToValues.js.map +1 -1
  291. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js +78 -17
  292. package/packages/ai/src/lib/dataStructure/helpers/fillInSchemaGapsAndUnknowns.js.map +1 -1
  293. package/packages/ai/src/lib/dataStructureChunking.js +26 -11
  294. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  295. package/packages/ai/src/lib/generateEntityDataStructure.js +46 -2
  296. package/packages/ai/src/lib/generateEntityDataStructure.js.map +1 -1
  297. package/packages/ai/src/lib/generateEntityScenarioData.js +212 -3
  298. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  299. package/packages/ai/src/lib/generateExecutionFlows.js +16 -2
  300. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  301. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js +242 -81
  302. package/packages/ai/src/lib/generateExecutionFlowsFromConditionals.js.map +1 -1
  303. package/packages/ai/src/lib/isolateScopes.js +39 -3
  304. package/packages/ai/src/lib/isolateScopes.js.map +1 -1
  305. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js +5 -0
  306. package/packages/ai/src/lib/mergeJsonTypeDefinitions.js.map +1 -1
  307. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js +97 -0
  308. package/packages/ai/src/lib/promptGenerators/collapseNullableObjects.js.map +1 -0
  309. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js +17 -2
  310. package/packages/ai/src/lib/promptGenerators/generateEntityScenarioDataGenerator.js.map +1 -1
  311. package/packages/analyze/index.js +1 -0
  312. package/packages/analyze/index.js.map +1 -1
  313. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js +52 -2
  314. package/packages/analyze/src/lib/files/analyze/analyzeEntities/prepareDataStructures.js.map +1 -1
  315. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +3 -0
  316. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  317. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +880 -0
  318. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -0
  319. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js +5 -1
  320. package/packages/analyze/src/lib/files/scenarios/enrichArrayTypesFromChildSignatures.js.map +1 -1
  321. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js +51 -14
  322. package/packages/analyze/src/lib/files/scenarios/gatherDataForMocks.js.map +1 -1
  323. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +116 -13
  324. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  325. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +310 -45
  326. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  327. package/packages/analyze/src/lib/index.js +1 -0
  328. package/packages/analyze/src/lib/index.js.map +1 -1
  329. package/packages/database/src/lib/analysisBranchToDb.js +1 -1
  330. package/packages/database/src/lib/analysisBranchToDb.js.map +1 -1
  331. package/packages/database/src/lib/analysisToDb.js +1 -1
  332. package/packages/database/src/lib/analysisToDb.js.map +1 -1
  333. package/packages/database/src/lib/branchToDb.js +1 -1
  334. package/packages/database/src/lib/branchToDb.js.map +1 -1
  335. package/packages/database/src/lib/commitBranchToDb.js +1 -1
  336. package/packages/database/src/lib/commitBranchToDb.js.map +1 -1
  337. package/packages/database/src/lib/commitToDb.js +1 -1
  338. package/packages/database/src/lib/commitToDb.js.map +1 -1
  339. package/packages/database/src/lib/fileToDb.js +1 -1
  340. package/packages/database/src/lib/fileToDb.js.map +1 -1
  341. package/packages/database/src/lib/kysely/db.js +3 -0
  342. package/packages/database/src/lib/kysely/db.js.map +1 -1
  343. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js +35 -0
  344. package/packages/database/src/lib/kysely/tables/labsRequestsTable.js.map +1 -0
  345. package/packages/database/src/lib/projectToDb.js +1 -1
  346. package/packages/database/src/lib/projectToDb.js.map +1 -1
  347. package/packages/database/src/lib/saveFiles.js +1 -1
  348. package/packages/database/src/lib/saveFiles.js.map +1 -1
  349. package/packages/database/src/lib/scenarioToDb.js +1 -1
  350. package/packages/database/src/lib/scenarioToDb.js.map +1 -1
  351. package/packages/utils/src/lib/fs/rsyncCopy.js +93 -2
  352. package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  353. package/scripts/finalize-analyzer.cjs +8 -76
  354. package/codeyam-cli/src/webserver/build/client/assets/copy-Bb-80kDT.js +0 -6
  355. package/codeyam-cli/src/webserver/build/client/assets/entity._sha._-BJUiQqZF.js +0 -23
  356. package/codeyam-cli/src/webserver/build/client/assets/file-code-Dhef1kWN.js +0 -6
  357. package/codeyam-cli/src/webserver/build/client/assets/globals-D3yhhV8x.css +0 -1
  358. package/codeyam-cli/src/webserver/build/client/assets/manifest-a78b90a2.js +0 -1
  359. package/codeyam-cli/src/webserver/build/client/assets/memory--GCbFsBE.js +0 -92
  360. package/codeyam-cli/src/webserver/build/client/assets/root-eVAaavTS.js +0 -62
  361. package/codeyam-cli/src/webserver/build/client/assets/settings-CS5f3WzT.js +0 -1
  362. package/codeyam-cli/src/webserver/build/server/assets/server-build-dYC34MHw.js +0 -257
  363. package/codeyam-cli/templates/codeyam:diagnose.md +0 -803
  364. package/codeyam-cli/templates/codeyam:memory.md +0 -341
@@ -1,5 +1,6 @@
1
1
  import { splitOutsideParenthesesAndArrays, joinParenthesesAndArrays, } from "../../../../../../packages/ai/index.js";
2
2
  import { cleanKnownObjectFunctionsFromMapping } from "../../../../../../packages/ai/index.js";
3
+ import { transformationTracer } from "./TransformationTracer.js";
3
4
  function cleanFunctionName(functionName) {
4
5
  return functionName?.split('<')[0];
5
6
  }
@@ -47,6 +48,12 @@ function isPrimitiveType(typeStr) {
47
48
  }
48
49
  return false;
49
50
  }
51
+ // Extract signature index from a path like "signature[0]" or "signature[0].foo"
52
+ // Returns the index number or undefined if not a signature path
53
+ function extractSignatureIndex(path) {
54
+ const match = path.match(/^signature\[(\d+)\]/);
55
+ return match ? parseInt(match[1], 10) : undefined;
56
+ }
50
57
  // Check if a new schema path would go through a primitive type
51
58
  // e.g., if schema has 'entities[].scenarioCount': 'number', then
52
59
  // 'entities[].scenarioCount.sha' would go through a primitive and should be rejected
@@ -128,6 +135,21 @@ export default function mergeInDependentDataStructure({ importedExports, depende
128
135
  }
129
136
  }
130
137
  let equivalentSchemaPaths = [];
138
+ // O(1) index for findOrCreateEquivalentSchemaPathsEntry.
139
+ // Maps "(rootPath)::(normalizedFuncName)" → the entry containing that root.
140
+ // This replaces the O(E) linear search that was causing O(E²) gather performance.
141
+ const espIndex = new Map();
142
+ const espIndexKey = (path, functionName) => {
143
+ const normalized = cleanFunctionName(functionName);
144
+ const funcKey = normalized === rootScopeName ? '__self__' : normalized || '__self__';
145
+ return `${path}::${funcKey}`;
146
+ };
147
+ const updateEspIndex = (entry) => {
148
+ for (const root of entry.equivalentRoots) {
149
+ const funcName = root.function?.name ?? rootScopeName;
150
+ espIndex.set(espIndexKey(root.schemaRootPath, funcName), entry);
151
+ }
152
+ };
131
153
  // Pre-build a lookup map from cleaned function name to dependency for O(1) lookups.
132
154
  // This avoids O(n) linear search in findRelevantDependency which was causing O(n²) performance.
133
155
  const dependencyByCleanedName = new Map();
@@ -166,8 +188,8 @@ export default function mergeInDependentDataStructure({ importedExports, depende
166
188
  });
167
189
  return mergedDataStructure.dependencySchemas[filePath][name];
168
190
  };
169
- const cleanSchema = (schema) => {
170
- cleanKnownObjectFunctionsFromMapping(schema);
191
+ const cleanSchema = (schema, context) => {
192
+ transformationTracer.traceSchemaTransform(rootScopeName, 'cleanKnownObjectFunctionsFromMapping', schema, cleanKnownObjectFunctionsFromMapping, context);
171
193
  };
172
194
  const translatePath = (path, dependencyName) => {
173
195
  if (path.startsWith(dependencyName)) {
@@ -207,6 +229,41 @@ export default function mergeInDependentDataStructure({ importedExports, depende
207
229
  const gatherAllEquivalentSchemaPaths = (functionName, sourceAndUsageEquivalencies, dataStructure) => {
208
230
  if (!sourceAndUsageEquivalencies)
209
231
  return;
232
+ const normalizedSchemaCache = new Map();
233
+ const getSchemaIndex = (schema) => {
234
+ if (!schema)
235
+ return { byFirstPart: new Map() };
236
+ const cached = normalizedSchemaCache.get(schema);
237
+ if (cached)
238
+ return cached;
239
+ const byFirstPart = new Map();
240
+ for (const path in schema) {
241
+ let parts = splitOutsideParenthesesAndArrays(path);
242
+ if (parts[0].startsWith(functionName)) {
243
+ const baseName = cleanFunctionName(parts[0]);
244
+ if (!functionsWithMultipleTypeParams.has(baseName)) {
245
+ parts =
246
+ parts[1] === 'functionCallReturnValue'
247
+ ? ['returnValue', ...parts.slice(2)]
248
+ : parts.slice(1);
249
+ }
250
+ }
251
+ const entry = { path, parts };
252
+ // Index by the base of the first part (before any function call args)
253
+ const firstPart = parts[0] ?? '';
254
+ const parenIdx = firstPart.indexOf('(');
255
+ const firstPartBase = parenIdx >= 0 ? firstPart.slice(0, parenIdx) : firstPart;
256
+ let bucket = byFirstPart.get(firstPartBase);
257
+ if (!bucket) {
258
+ bucket = [];
259
+ byFirstPart.set(firstPartBase, bucket);
260
+ }
261
+ bucket.push(entry);
262
+ }
263
+ const result = { byFirstPart };
264
+ normalizedSchemaCache.set(schema, result);
265
+ return result;
266
+ };
210
267
  const findOrCreateEquivalentSchemaPathsEntry = (allPaths) => {
211
268
  const equivalentRoots = allPaths
212
269
  .filter((p) => p.functionName === rootScopeName ||
@@ -218,19 +275,93 @@ export default function mergeInDependentDataStructure({ importedExports, depende
218
275
  : findRelevantDependency(p.functionName),
219
276
  }));
220
277
  let equivalentSchemaPathsEntry;
278
+ // Collect the signature indices from the new roots we want to add
279
+ const newRootSignatureIndices = new Set();
280
+ for (const root of equivalentRoots) {
281
+ const idx = extractSignatureIndex(root.schemaRootPath);
282
+ if (idx !== undefined) {
283
+ newRootSignatureIndices.add(idx);
284
+ }
285
+ }
286
+ // Use espIndex Map for O(1) lookup instead of O(E) linear search.
287
+ // Falls back to linear search only when Map hit has a signature index conflict.
221
288
  for (const pathInfo of allPaths) {
222
- if (!equivalentSchemaPathsEntry) {
223
- equivalentSchemaPathsEntry = equivalentSchemaPaths.find((esp) => esp.equivalentRoots.some((er) => er.schemaRootPath === pathInfo.path &&
224
- (er.function?.name ===
225
- cleanFunctionName(pathInfo.functionName) ||
226
- (!er.function &&
227
- cleanFunctionName(pathInfo.functionName) ===
228
- rootScopeName))));
289
+ if (equivalentSchemaPathsEntry)
290
+ break;
291
+ const candidate = espIndex.get(espIndexKey(pathInfo.path, pathInfo.functionName));
292
+ if (!candidate)
293
+ continue;
294
+ // Verify no signature index conflict with the candidate entry
295
+ if (newRootSignatureIndices.size > 0) {
296
+ const existingIndicesByFunction = new Map();
297
+ for (const er of candidate.equivalentRoots) {
298
+ const funcKey = er.function
299
+ ? `${er.function.name}::${er.function.filePath}`
300
+ : '__self__';
301
+ const idx = extractSignatureIndex(er.schemaRootPath);
302
+ if (idx !== undefined) {
303
+ if (!existingIndicesByFunction.has(funcKey)) {
304
+ existingIndicesByFunction.set(funcKey, new Set());
305
+ }
306
+ existingIndicesByFunction.get(funcKey).add(idx);
307
+ }
308
+ }
309
+ let hasConflict = false;
310
+ for (const newRoot of equivalentRoots) {
311
+ const funcKey = newRoot.function
312
+ ? `${newRoot.function.name}::${newRoot.function.filePath}`
313
+ : '__self__';
314
+ const newIdx = extractSignatureIndex(newRoot.schemaRootPath);
315
+ if (newIdx !== undefined) {
316
+ const existingIndices = existingIndicesByFunction.get(funcKey);
317
+ if (existingIndices && existingIndices.size > 0) {
318
+ if (!existingIndices.has(newIdx)) {
319
+ hasConflict = true;
320
+ break;
321
+ }
322
+ }
323
+ }
324
+ }
325
+ if (hasConflict)
326
+ continue;
229
327
  }
328
+ equivalentSchemaPathsEntry = candidate;
230
329
  }
231
330
  if (!equivalentSchemaPathsEntry) {
331
+ // Before creating a new entry, filter out roots that have conflicting
332
+ // signature indices from the same function. An entry should never contain
333
+ // roots with different signature indices from the same function.
334
+ // This prevents the bug where signature[1], signature[2], signature[4]
335
+ // all get merged together due to incorrect sourceEquivalencies.
336
+ let filteredRoots = equivalentRoots;
337
+ if (newRootSignatureIndices.size > 1) {
338
+ // There are multiple signature indices - we need to filter to keep only
339
+ // one consistent set. We'll keep the roots that match the PRIMARY index
340
+ // (the first signature index we encounter from self, or the lowest index).
341
+ // First, determine the primary index - prefer the self root's index
342
+ let primaryIndex;
343
+ for (const root of equivalentRoots) {
344
+ if (!root.function) {
345
+ // This is a self root
346
+ const idx = extractSignatureIndex(root.schemaRootPath);
347
+ if (idx !== undefined) {
348
+ primaryIndex = idx;
349
+ break;
350
+ }
351
+ }
352
+ }
353
+ // If no self root has a signature index, use the lowest index
354
+ if (primaryIndex === undefined) {
355
+ primaryIndex = Math.min(...newRootSignatureIndices);
356
+ }
357
+ // Filter roots: keep if no signature index OR signature index matches primary
358
+ filteredRoots = equivalentRoots.filter((root) => {
359
+ const idx = extractSignatureIndex(root.schemaRootPath);
360
+ return idx === undefined || idx === primaryIndex;
361
+ });
362
+ }
232
363
  equivalentSchemaPathsEntry = {
233
- equivalentRoots,
364
+ equivalentRoots: filteredRoots,
234
365
  equivalentPostfixes: {},
235
366
  };
236
367
  equivalentSchemaPaths.push(equivalentSchemaPathsEntry);
@@ -248,6 +379,8 @@ export default function mergeInDependentDataStructure({ importedExports, depende
248
379
  seenRoots.add(key);
249
380
  return true;
250
381
  });
382
+ // Keep the espIndex in sync after adding/deduplicating roots
383
+ updateEspIndex(equivalentSchemaPathsEntry);
251
384
  return equivalentSchemaPathsEntry;
252
385
  };
253
386
  // Helper to extract function name from a path that starts with a function call.
@@ -303,6 +436,8 @@ export default function mergeInDependentDataStructure({ importedExports, depende
303
436
  p.functionName === rootScopeName ||
304
437
  p.functionName === effectiveFunctionName);
305
438
  const derivedBasePaths = [];
439
+ const allPathSet = new Set(allPaths.map((p) => p.path));
440
+ const derivedBasePathSet = new Set();
306
441
  // For each child path, find its equivalent parent path and derive bases
307
442
  for (const childPathInfo of childPaths) {
308
443
  const childParts = splitOutsideParenthesesAndArrays(childPathInfo.path);
@@ -351,23 +486,23 @@ export default function mergeInDependentDataStructure({ importedExports, depende
351
486
  parentHasArrayIterator &&
352
487
  !childHasArrayIterator &&
353
488
  !childBaseIsGenericSignature) {
354
- // Add child base if not already present
355
- const childBaseExists = allPaths.some((p) => p.path === childBase) ||
356
- derivedBasePaths.some((p) => p.path === childBase);
357
- if (!childBaseExists) {
489
+ // Add child base if not already present (O(1) Set lookup)
490
+ if (!allPathSet.has(childBase) &&
491
+ !derivedBasePathSet.has(childBase)) {
358
492
  derivedBasePaths.push({
359
493
  path: childBase,
360
494
  functionName: childPathInfo.functionName,
361
495
  });
496
+ derivedBasePathSet.add(childBase);
362
497
  }
363
- // Add parent base if not already present
364
- const parentBaseExists = allPaths.some((p) => p.path === parentBase) ||
365
- derivedBasePaths.some((p) => p.path === parentBase);
366
- if (!parentBaseExists) {
498
+ // Add parent base if not already present (O(1) Set lookup)
499
+ if (!allPathSet.has(parentBase) &&
500
+ !derivedBasePathSet.has(parentBase)) {
367
501
  derivedBasePaths.push({
368
502
  path: parentBase,
369
503
  functionName: parentPathInfo.functionName,
370
504
  });
505
+ derivedBasePathSet.add(parentBase);
371
506
  }
372
507
  }
373
508
  }
@@ -376,6 +511,25 @@ export default function mergeInDependentDataStructure({ importedExports, depende
376
511
  }
377
512
  allPaths.push(...derivedBasePaths);
378
513
  const entry = findOrCreateEquivalentSchemaPathsEntry(allPaths);
514
+ // Trace equivalency gathering - helps debug why paths may not be connected
515
+ if (allPaths.length > 1) {
516
+ transformationTracer.operation(rootScopeName, {
517
+ operation: 'gatherEquivalency',
518
+ stage: 'gathering',
519
+ path: translatedPath,
520
+ context: {
521
+ sourceFunction: functionName,
522
+ equivalentPaths: allPaths.map((p) => ({
523
+ path: p.path,
524
+ function: p.functionName,
525
+ })),
526
+ equivalentRoots: entry.equivalentRoots.map((r) => ({
527
+ path: r.schemaRootPath,
528
+ function: r.function?.name,
529
+ })),
530
+ },
531
+ });
532
+ }
379
533
  for (const equivalentRoot of entry.equivalentRoots) {
380
534
  const dataStructures = equivalentRoot.function &&
381
535
  equivalentRoot.function.name !== rootScopeName
@@ -404,18 +558,16 @@ export default function mergeInDependentDataStructure({ importedExports, depende
404
558
  pathParts = pathParts.slice(1);
405
559
  }
406
560
  for (const schema of schemas) {
407
- for (const schemaPath in schema) {
408
- let schemaPathParts = splitOutsideParenthesesAndArrays(schemaPath);
409
- if (schemaPathParts[0].startsWith(functionName)) {
410
- // Only normalize if the function doesn't have multiple different type parameters
411
- const baseName = cleanFunctionName(schemaPathParts[0]);
412
- if (!functionsWithMultipleTypeParams.has(baseName)) {
413
- schemaPathParts =
414
- schemaPathParts[1] === 'functionCallReturnValue'
415
- ? ['returnValue', ...schemaPathParts.slice(2)]
416
- : schemaPathParts.slice(1);
417
- }
418
- }
561
+ // Use pre-computed index to only iterate schema entries whose
562
+ // normalized first part matches pathParts[0], instead of all entries.
563
+ const schemaIndex = getSchemaIndex(schema);
564
+ const lookupPart = pathParts[0] ?? '';
565
+ const lookupParenIdx = lookupPart.indexOf('(');
566
+ const lookupBase = lookupParenIdx >= 0
567
+ ? lookupPart.slice(0, lookupParenIdx)
568
+ : lookupPart;
569
+ const candidates = schemaIndex.byFirstPart.get(lookupBase) || [];
570
+ for (const { path: schemaPath, parts: schemaPathParts, } of candidates) {
419
571
  if (schemaPathParts.length < pathParts.length)
420
572
  continue;
421
573
  // Check if all path parts match (allowing function call variants)
@@ -474,13 +626,27 @@ export default function mergeInDependentDataStructure({ importedExports, depende
474
626
  else {
475
627
  // Regular exact match - use the standard postfix logic
476
628
  const postfix = joinParenthesesAndArrays(schemaPathParts.slice(matchedUpToIndex));
477
- entry.equivalentPostfixes[postfix] = entry
478
- .equivalentPostfixes[postfix]
479
- ? bestValueFromOptions([
480
- entry.equivalentPostfixes[postfix],
481
- schema[schemaPath],
482
- ])
483
- : schema[schemaPath];
629
+ const previousValue = entry.equivalentPostfixes[postfix];
630
+ const newValue = schema[schemaPath];
631
+ entry.equivalentPostfixes[postfix] = previousValue
632
+ ? bestValueFromOptions([previousValue, newValue])
633
+ : newValue;
634
+ // Trace postfix gathering - shows where type info comes from
635
+ if (entry.equivalentPostfixes[postfix] !== previousValue) {
636
+ transformationTracer.operation(rootScopeName, {
637
+ operation: 'gatherPostfix',
638
+ stage: 'gathering',
639
+ path: postfix || '(root)',
640
+ before: previousValue,
641
+ after: entry.equivalentPostfixes[postfix],
642
+ context: {
643
+ sourceSchemaPath: schemaPath,
644
+ sourceFunction: equivalentRoot.function?.name || rootScopeName,
645
+ equivalentRootPath: equivalentRoot.schemaRootPath,
646
+ rawValue: newValue,
647
+ },
648
+ });
649
+ }
484
650
  }
485
651
  }
486
652
  }
@@ -512,10 +678,14 @@ export default function mergeInDependentDataStructure({ importedExports, depende
512
678
  const entry = findOrCreateEquivalentSchemaPathsEntry([
513
679
  { path: translatedBasePath, functionName: functionName },
514
680
  ]);
515
- entry.equivalentRoots.push({
681
+ const newRoot = {
516
682
  schemaRootPath: translatedBasePath,
517
683
  function: findRelevantDependency(functionName),
518
- });
684
+ };
685
+ entry.equivalentRoots.push(newRoot);
686
+ // Update index for the newly added root
687
+ const newRootFuncName = newRoot.function?.name ?? rootScopeName;
688
+ espIndex.set(espIndexKey(newRoot.schemaRootPath, newRootFuncName), entry);
519
689
  const basePathParts = splitOutsideParenthesesAndArrays(basePath);
520
690
  for (const schemaPath in dataStructure.returnValueSchema) {
521
691
  const schemaPathParts = splitOutsideParenthesesAndArrays(schemaPath);
@@ -529,12 +699,13 @@ export default function mergeInDependentDataStructure({ importedExports, depende
529
699
  continue;
530
700
  }
531
701
  const postfix = joinParenthesesAndArrays(schemaPathParts.slice(basePathParts.length));
532
- entry.equivalentPostfixes[postfix] = entry.equivalentPostfixes[postfix]
702
+ const newValue = entry.equivalentPostfixes[postfix]
533
703
  ? bestValueFromOptions([
534
704
  entry.equivalentPostfixes[postfix],
535
705
  dataStructure.returnValueSchema[schemaPath],
536
706
  ])
537
707
  : dataStructure.returnValueSchema[schemaPath];
708
+ entry.equivalentPostfixes[postfix] = newValue;
538
709
  }
539
710
  }
540
711
  }
@@ -573,6 +744,8 @@ export default function mergeInDependentDataStructure({ importedExports, depende
573
744
  }
574
745
  const findEquivalentSchemaPathEntry = (schemaSubPath, equivalentRootFunction) => {
575
746
  let postfix;
747
+ // Get the signature index we're looking for (if any)
748
+ const lookingForSignatureIndex = extractSignatureIndex(schemaSubPath);
576
749
  const equivalentEntry = mergedEquivalentSchemaPaths.find((esp) => esp.equivalentRoots.some((er) => {
577
750
  if ((schemaSubPath.startsWith('returnValue') ||
578
751
  schemaSubPath.startsWith('signature[')) &&
@@ -581,6 +754,26 @@ export default function mergeInDependentDataStructure({ importedExports, depende
581
754
  return false;
582
755
  }
583
756
  if (schemaSubPath === er.schemaRootPath) {
757
+ // Additional check: if we're looking for a signature path, make sure
758
+ // the entry doesn't already have DIFFERENT signature indices.
759
+ // This prevents entries with signature[1], signature[2], signature[4]
760
+ // from all being merged together.
761
+ if (lookingForSignatureIndex !== undefined) {
762
+ const hasConflictingSignatureIndex = esp.equivalentRoots.some((otherRoot) => {
763
+ // Only check roots from the same function
764
+ if (otherRoot.function?.name !== equivalentRootFunction?.name ||
765
+ otherRoot.function?.filePath !==
766
+ equivalentRootFunction?.filePath) {
767
+ return false;
768
+ }
769
+ const otherIndex = extractSignatureIndex(otherRoot.schemaRootPath);
770
+ return (otherIndex !== undefined &&
771
+ otherIndex !== lookingForSignatureIndex);
772
+ });
773
+ if (hasConflictingSignatureIndex) {
774
+ return false;
775
+ }
776
+ }
584
777
  postfix = er.postfix;
585
778
  return true;
586
779
  }
@@ -666,6 +859,9 @@ export default function mergeInDependentDataStructure({ importedExports, depende
666
859
  }
667
860
  }
668
861
  equivalentSchemaPaths = mergeAllEquivalentSchemaPaths();
862
+ // Collect schemas that need cleaning — batch the calls for the end instead of
863
+ // calling cleanSchema inside the inner root loop (which was O(roots * schemaSize)).
864
+ const schemasToClean = new Set();
669
865
  for (const esp of equivalentSchemaPaths) {
670
866
  // Pre-compute which postfixes have children to avoid O(n²) lookups in the inner loop.
671
867
  // A postfix "has children" if there are other postfixes that extend it.
@@ -744,6 +940,15 @@ export default function mergeInDependentDataStructure({ importedExports, depende
744
940
  // Skip paths that would go through a primitive type
745
941
  // e.g., if schema has 'entities[].scenarioCount': 'number', skip 'entities[].scenarioCount.sha'
746
942
  if (wouldGoThroughPrimitive(newSchemaPath, schema)) {
943
+ transformationTracer.operation(rootScopeName, {
944
+ operation: 'skipPrimitivePath',
945
+ stage: 'merged',
946
+ path: newSchemaPath,
947
+ context: {
948
+ reason: 'would go through primitive type',
949
+ postfixValue,
950
+ },
951
+ });
747
952
  continue;
748
953
  }
749
954
  // Skip setting primitive type when there are child postfixes that indicate structure.
@@ -762,20 +967,57 @@ export default function mergeInDependentDataStructure({ importedExports, depende
762
967
  // e.g., if schema has 'entities[].scenarioCount': 'number', don't overwrite with 'object'
763
968
  if (PRIMITIVE_TYPES.has(existingType) &&
764
969
  (postfixValue === 'object' || postfixValue === 'array')) {
970
+ transformationTracer.operation(rootScopeName, {
971
+ operation: 'skipTypeDowngrade',
972
+ stage: 'merged',
973
+ path: newSchemaPath,
974
+ context: {
975
+ reason: 'would overwrite primitive with object/array',
976
+ existingType,
977
+ newType: postfixValue,
978
+ },
979
+ });
765
980
  continue;
766
981
  }
767
982
  // Don't overwrite a complex/union type with a primitive
768
983
  // e.g., if schema has 'scenarios[]': 'Scenario | null', don't overwrite with 'string'
769
984
  if (!PRIMITIVE_TYPES.has(existingType) &&
770
985
  PRIMITIVE_TYPES.has(postfixValue)) {
986
+ transformationTracer.operation(rootScopeName, {
987
+ operation: 'skipTypeDowngrade',
988
+ stage: 'merged',
989
+ path: newSchemaPath,
990
+ context: {
991
+ reason: 'would overwrite complex type with primitive',
992
+ existingType,
993
+ newType: postfixValue,
994
+ },
995
+ });
771
996
  continue;
772
997
  }
773
998
  }
999
+ // Log the successful postfix merge
1000
+ transformationTracer.operation(rootScopeName, {
1001
+ operation: 'mergePostfix',
1002
+ stage: 'merged',
1003
+ path: newSchemaPath,
1004
+ before: existingType,
1005
+ after: postfixValue,
1006
+ context: {
1007
+ schemaRootPath: equivalentRoot.schemaRootPath,
1008
+ postfix: relevantPostfix,
1009
+ dependency: equivalentRoot.function?.name,
1010
+ },
1011
+ });
774
1012
  schema[newSchemaPath] = postfixValue;
775
1013
  }
776
- cleanSchema(schema);
1014
+ schemasToClean.add(schema);
777
1015
  }
778
1016
  }
1017
+ // Batch-clean all modified schemas once (instead of once per root per ESP entry)
1018
+ for (const schema of schemasToClean) {
1019
+ cleanSchema(schema, { stage: 'afterMergePostfix' });
1020
+ }
779
1021
  // Propagate equivalency-derived attributes to generic function call variants.
780
1022
  // When attributes are traced via equivalencies (e.g., fileComparisons from buildDataMap.signature[2]),
781
1023
  // they get written to non-generic paths (returnValue.data.x or funcName().functionCallReturnValue.data.x).
@@ -872,6 +1114,14 @@ export default function mergeInDependentDataStructure({ importedExports, depende
872
1114
  // e.g., returnValue[].label -> getOptions().functionCallReturnValue[].label
873
1115
  normalizedPath = path.replace(/^returnValue/, `${dependency.name}().functionCallReturnValue`);
874
1116
  }
1117
+ transformationTracer.operation(rootScopeName, {
1118
+ operation: 'normalizeReturnValuePath',
1119
+ stage: 'merged',
1120
+ path: normalizedPath,
1121
+ before: path,
1122
+ after: normalizedPath,
1123
+ context: { dependency: dependency.name, value },
1124
+ });
875
1125
  depSchema.returnValueSchema[normalizedPath] = value;
876
1126
  }
877
1127
  // Now copy paths from the source schema (dependencySchemas)
@@ -938,7 +1188,10 @@ export default function mergeInDependentDataStructure({ importedExports, depende
938
1188
  }
939
1189
  }
940
1190
  }
941
- cleanSchema(depSchema.returnValueSchema);
1191
+ cleanSchema(depSchema.returnValueSchema, {
1192
+ stage: 'afterMockedDependencyMerge',
1193
+ dependency: dependency.name,
1194
+ });
942
1195
  // Pull signature requirements from downstream functions into the mocked return value.
943
1196
  // When a mocked function's return flows into another function's signature (via usageEquivalencies),
944
1197
  // we need to include that function's signature requirements in the mock.
@@ -1003,7 +1256,10 @@ export default function mergeInDependentDataStructure({ importedExports, depende
1003
1256
  }
1004
1257
  }
1005
1258
  }
1006
- cleanSchema(depSchema.returnValueSchema);
1259
+ cleanSchema(depSchema.returnValueSchema, {
1260
+ stage: 'afterSignatureRequirementsMerge',
1261
+ dependency: dependency.name,
1262
+ });
1007
1263
  }
1008
1264
  // Process the input dependencySchemas FIRST (before child dependentAnalyses).
1009
1265
  // This ensures the parent entity's direct usage of dependencies takes precedence.
@@ -1039,7 +1295,11 @@ export default function mergeInDependentDataStructure({ importedExports, depende
1039
1295
  // from the copied schema. Without this, method call paths on primitives like
1040
1296
  // "projectSlug.replace(...)" would cause convertDotNotation to create nested
1041
1297
  // object structures instead of preserving the primitive type.
1042
- cleanSchema(depSchema.returnValueSchema);
1298
+ cleanSchema(depSchema.returnValueSchema, {
1299
+ stage: 'afterDependencySchemaCopy',
1300
+ filePath,
1301
+ dependency: name,
1302
+ });
1043
1303
  }
1044
1304
  // TYPE REFINEMENT: Check if dependentAnalyses has a more specific type for this dependency.
1045
1305
  // When a parent passes `entity.filePath` (string | undefined) to a child component
@@ -1098,7 +1358,12 @@ export default function mergeInDependentDataStructure({ importedExports, depende
1098
1358
  srcSchema.returnValueSchema[path];
1099
1359
  }
1100
1360
  }
1101
- cleanSchema(variantSchema.returnValueSchema);
1361
+ cleanSchema(variantSchema.returnValueSchema, {
1362
+ stage: 'afterTypeVariantCopy',
1363
+ filePath,
1364
+ dependency: name,
1365
+ variant,
1366
+ });
1102
1367
  }
1103
1368
  }
1104
1369
  }