@codeyam/codeyam-cli 0.1.0-staging.c5503ac → 0.1.0-staging.c85943e

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 (719) hide show
  1. package/analyzer-template/.build-info.json +8 -8
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/package.json +23 -23
  4. package/analyzer-template/packages/ai/package.json +3 -3
  5. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +34 -3
  6. package/analyzer-template/packages/ai/src/lib/completionCall.ts +114 -113
  7. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +259 -5
  8. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.ts +62 -0
  9. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.ts +35 -0
  10. package/analyzer-template/packages/ai/src/lib/dataStructureChunking.ts +15 -6
  11. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +78 -2
  12. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +96 -33
  13. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +19 -7
  14. package/analyzer-template/packages/analyze/src/lib/asts/index.ts +7 -2
  15. package/analyzer-template/packages/analyze/src/lib/asts/nodes/getNodeType.ts +1 -0
  16. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +9 -1
  17. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +0 -6
  18. package/analyzer-template/packages/analyze/src/lib/files/analyze/findOrCreateEntity.ts +12 -0
  19. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +65 -28
  20. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +83 -0
  21. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +0 -98
  22. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +23 -4
  23. package/analyzer-template/packages/aws/package.json +10 -10
  24. package/analyzer-template/packages/database/index.ts +1 -0
  25. package/analyzer-template/packages/database/package.json +3 -3
  26. package/analyzer-template/packages/database/src/lib/kysely/db.ts +8 -0
  27. package/analyzer-template/packages/database/src/lib/kysely/tables/editorScenariosTable.ts +164 -0
  28. package/analyzer-template/packages/database/src/lib/loadCommits.ts +31 -20
  29. package/analyzer-template/packages/database/src/lib/loadEntities.ts +0 -6
  30. package/analyzer-template/packages/database/src/lib/loadReadyToBeCapturedAnalyses.ts +0 -5
  31. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +94 -143
  32. package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatus.ts +58 -42
  33. package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.ts +81 -65
  34. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.ts +29 -1
  35. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.ts +33 -5
  36. package/analyzer-template/packages/github/dist/database/index.d.ts +1 -0
  37. package/analyzer-template/packages/github/dist/database/index.d.ts.map +1 -1
  38. package/analyzer-template/packages/github/dist/database/index.js +1 -0
  39. package/analyzer-template/packages/github/dist/database/index.js.map +1 -1
  40. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  41. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  42. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +5 -0
  43. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  44. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts +29 -0
  45. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts.map +1 -0
  46. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js +149 -0
  47. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
  48. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts +5 -0
  49. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts.map +1 -1
  50. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  51. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +23 -13
  52. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  53. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  54. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +0 -6
  55. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  56. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.d.ts.map +1 -1
  57. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
  58. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  59. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  60. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +76 -90
  61. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  62. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.d.ts.map +1 -1
  63. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js +41 -30
  64. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
  65. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.d.ts.map +1 -1
  66. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
  67. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
  68. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.d.ts.map +1 -1
  69. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
  70. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
  71. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.d.ts.map +1 -1
  72. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
  73. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  74. package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.d.ts +2 -0
  75. package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.d.ts.map +1 -1
  76. package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.js +2 -0
  77. package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.js.map +1 -1
  78. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +1 -0
  79. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  80. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts +10 -0
  81. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts.map +1 -1
  82. package/analyzer-template/packages/github/package.json +1 -1
  83. package/analyzer-template/packages/types/src/enums/ProjectFramework.ts +2 -0
  84. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +1 -0
  85. package/analyzer-template/packages/types/src/types/Scenario.ts +10 -0
  86. package/analyzer-template/packages/ui-components/package.json +1 -1
  87. package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.d.ts +2 -0
  88. package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.d.ts.map +1 -1
  89. package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.js +2 -0
  90. package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.js.map +1 -1
  91. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +1 -0
  92. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  93. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts +10 -0
  94. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts.map +1 -1
  95. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
  96. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +6 -2
  97. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  98. package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +14 -2
  99. package/analyzer-template/playwright/captureFromUrl.ts +89 -82
  100. package/analyzer-template/project/constructMockCode.ts +168 -48
  101. package/analyzer-template/project/orchestrateCapture.ts +4 -1
  102. package/analyzer-template/project/reconcileMockDataKeys.ts +19 -14
  103. package/analyzer-template/project/start.ts +3 -0
  104. package/analyzer-template/project/startScenarioCapture.ts +9 -0
  105. package/analyzer-template/project/writeClientLogRoute.ts +125 -0
  106. package/analyzer-template/project/writeMockDataTsx.ts +17 -0
  107. package/analyzer-template/project/writeScenarioComponents.ts +110 -17
  108. package/analyzer-template/tsconfig.json +13 -1
  109. package/background/src/lib/virtualized/project/constructMockCode.js +143 -39
  110. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  111. package/background/src/lib/virtualized/project/orchestrateCapture.js +4 -1
  112. package/background/src/lib/virtualized/project/orchestrateCapture.js.map +1 -1
  113. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +17 -11
  114. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
  115. package/background/src/lib/virtualized/project/start.js +2 -0
  116. package/background/src/lib/virtualized/project/start.js.map +1 -1
  117. package/background/src/lib/virtualized/project/startScenarioCapture.js +5 -0
  118. package/background/src/lib/virtualized/project/startScenarioCapture.js.map +1 -1
  119. package/background/src/lib/virtualized/project/writeClientLogRoute.js +110 -0
  120. package/background/src/lib/virtualized/project/writeClientLogRoute.js.map +1 -0
  121. package/background/src/lib/virtualized/project/writeMockDataTsx.js +12 -0
  122. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  123. package/background/src/lib/virtualized/project/writeScenarioComponents.js +83 -12
  124. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  125. package/codeyam-cli/scripts/apply-setup.js +208 -11
  126. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  127. package/codeyam-cli/src/__tests__/memory-scripts/filter-session.test.js +196 -0
  128. package/codeyam-cli/src/__tests__/memory-scripts/filter-session.test.js.map +1 -0
  129. package/codeyam-cli/src/__tests__/memory-scripts/read-json-field.test.js +114 -0
  130. package/codeyam-cli/src/__tests__/memory-scripts/read-json-field.test.js.map +1 -0
  131. package/codeyam-cli/src/__tests__/memory-scripts/ripgrep-fallback.test.js +149 -0
  132. package/codeyam-cli/src/__tests__/memory-scripts/ripgrep-fallback.test.js.map +1 -0
  133. package/codeyam-cli/src/cli.js +32 -25
  134. package/codeyam-cli/src/cli.js.map +1 -1
  135. package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js +56 -0
  136. package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js.map +1 -0
  137. package/codeyam-cli/src/commands/__tests__/init.gitignore.test.js +101 -47
  138. package/codeyam-cli/src/commands/__tests__/init.gitignore.test.js.map +1 -1
  139. package/codeyam-cli/src/commands/analyze.js +17 -7
  140. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  141. package/codeyam-cli/src/commands/default.js +14 -2
  142. package/codeyam-cli/src/commands/default.js.map +1 -1
  143. package/codeyam-cli/src/commands/editor.js +4357 -0
  144. package/codeyam-cli/src/commands/editor.js.map +1 -0
  145. package/codeyam-cli/src/commands/init.js +108 -45
  146. package/codeyam-cli/src/commands/init.js.map +1 -1
  147. package/codeyam-cli/src/commands/memory.js +89 -75
  148. package/codeyam-cli/src/commands/memory.js.map +1 -1
  149. package/codeyam-cli/src/data/techStacks.js +77 -0
  150. package/codeyam-cli/src/data/techStacks.js.map +1 -0
  151. package/codeyam-cli/src/utils/__tests__/analyzerFinalization.test.js +173 -0
  152. package/codeyam-cli/src/utils/__tests__/analyzerFinalization.test.js.map +1 -0
  153. package/codeyam-cli/src/utils/__tests__/backgroundServer.test.js +46 -0
  154. package/codeyam-cli/src/utils/__tests__/backgroundServer.test.js.map +1 -0
  155. package/codeyam-cli/src/utils/__tests__/devServerState.test.js +134 -0
  156. package/codeyam-cli/src/utils/__tests__/devServerState.test.js.map +1 -0
  157. package/codeyam-cli/src/utils/__tests__/editorApi.test.js +137 -0
  158. package/codeyam-cli/src/utils/__tests__/editorApi.test.js.map +1 -0
  159. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +1831 -0
  160. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -0
  161. package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js +76 -0
  162. package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js.map +1 -0
  163. package/codeyam-cli/src/utils/__tests__/editorCapture.test.js +93 -0
  164. package/codeyam-cli/src/utils/__tests__/editorCapture.test.js.map +1 -0
  165. package/codeyam-cli/src/utils/__tests__/editorDeleteScenario.test.js +100 -0
  166. package/codeyam-cli/src/utils/__tests__/editorDeleteScenario.test.js.map +1 -0
  167. package/codeyam-cli/src/utils/__tests__/editorDevServer.test.js +304 -0
  168. package/codeyam-cli/src/utils/__tests__/editorDevServer.test.js.map +1 -0
  169. package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js +124 -0
  170. package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js.map +1 -0
  171. package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js +261 -0
  172. package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js.map +1 -0
  173. package/codeyam-cli/src/utils/__tests__/editorImageVerifier.test.js +294 -0
  174. package/codeyam-cli/src/utils/__tests__/editorImageVerifier.test.js.map +1 -0
  175. package/codeyam-cli/src/utils/__tests__/editorJournal.test.js +542 -0
  176. package/codeyam-cli/src/utils/__tests__/editorJournal.test.js.map +1 -0
  177. package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js +594 -0
  178. package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js.map +1 -0
  179. package/codeyam-cli/src/utils/__tests__/editorMigration.test.js +435 -0
  180. package/codeyam-cli/src/utils/__tests__/editorMigration.test.js.map +1 -0
  181. package/codeyam-cli/src/utils/__tests__/editorMockState.test.js +270 -0
  182. package/codeyam-cli/src/utils/__tests__/editorMockState.test.js.map +1 -0
  183. package/codeyam-cli/src/utils/__tests__/editorPreloadHelpers.test.js +217 -0
  184. package/codeyam-cli/src/utils/__tests__/editorPreloadHelpers.test.js.map +1 -0
  185. package/codeyam-cli/src/utils/__tests__/editorPreview.test.js +353 -0
  186. package/codeyam-cli/src/utils/__tests__/editorPreview.test.js.map +1 -0
  187. package/codeyam-cli/src/utils/__tests__/editorProxySession.test.js +153 -0
  188. package/codeyam-cli/src/utils/__tests__/editorProxySession.test.js.map +1 -0
  189. package/codeyam-cli/src/utils/__tests__/editorScenarioLookup.test.js +139 -0
  190. package/codeyam-cli/src/utils/__tests__/editorScenarioLookup.test.js.map +1 -0
  191. package/codeyam-cli/src/utils/__tests__/editorScenarioSwitch.test.js +221 -0
  192. package/codeyam-cli/src/utils/__tests__/editorScenarioSwitch.test.js.map +1 -0
  193. package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js +1483 -0
  194. package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js.map +1 -0
  195. package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js +280 -0
  196. package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js.map +1 -0
  197. package/codeyam-cli/src/utils/__tests__/editorSeedAdapterPrismaValidation.test.js +143 -0
  198. package/codeyam-cli/src/utils/__tests__/editorSeedAdapterPrismaValidation.test.js.map +1 -0
  199. package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js +66 -0
  200. package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js.map +1 -0
  201. package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js +53 -0
  202. package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js.map +1 -0
  203. package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js +1857 -0
  204. package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js.map +1 -0
  205. package/codeyam-cli/src/utils/__tests__/git.editor.test.js +134 -0
  206. package/codeyam-cli/src/utils/__tests__/git.editor.test.js.map +1 -0
  207. package/codeyam-cli/src/utils/__tests__/journalCaptureStabilization.test.js +107 -0
  208. package/codeyam-cli/src/utils/__tests__/journalCaptureStabilization.test.js.map +1 -0
  209. package/codeyam-cli/src/utils/__tests__/npmVersionCheck.test.js +26 -20
  210. package/codeyam-cli/src/utils/__tests__/npmVersionCheck.test.js.map +1 -1
  211. package/codeyam-cli/src/utils/__tests__/parseRegisterArg.test.js +129 -0
  212. package/codeyam-cli/src/utils/__tests__/parseRegisterArg.test.js.map +1 -0
  213. package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js +9 -0
  214. package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js.map +1 -1
  215. package/codeyam-cli/src/utils/__tests__/project.test.js +65 -0
  216. package/codeyam-cli/src/utils/__tests__/project.test.js.map +1 -0
  217. package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js +118 -0
  218. package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js.map +1 -0
  219. package/codeyam-cli/src/utils/__tests__/scenarioCoverage.test.js +227 -0
  220. package/codeyam-cli/src/utils/__tests__/scenarioCoverage.test.js.map +1 -0
  221. package/codeyam-cli/src/utils/__tests__/scenarioMarkers.test.js +121 -0
  222. package/codeyam-cli/src/utils/__tests__/scenarioMarkers.test.js.map +1 -0
  223. package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js +493 -0
  224. package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js.map +1 -0
  225. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +51 -4
  226. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  227. package/codeyam-cli/src/utils/__tests__/templateConsistency.test.js +51 -0
  228. package/codeyam-cli/src/utils/__tests__/templateConsistency.test.js.map +1 -0
  229. package/codeyam-cli/src/utils/__tests__/webappDetection.test.js +142 -0
  230. package/codeyam-cli/src/utils/__tests__/webappDetection.test.js.map +1 -0
  231. package/codeyam-cli/src/utils/analysisRunner.js +3 -1
  232. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  233. package/codeyam-cli/src/utils/analyzer.js +9 -0
  234. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  235. package/codeyam-cli/src/utils/analyzerFinalization.js +100 -0
  236. package/codeyam-cli/src/utils/analyzerFinalization.js.map +1 -0
  237. package/codeyam-cli/src/utils/backgroundServer.js +104 -12
  238. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  239. package/codeyam-cli/src/utils/buildFlags.js +4 -0
  240. package/codeyam-cli/src/utils/buildFlags.js.map +1 -0
  241. package/codeyam-cli/src/utils/database.js +37 -2
  242. package/codeyam-cli/src/utils/database.js.map +1 -1
  243. package/codeyam-cli/src/utils/devModeEvents.js +40 -0
  244. package/codeyam-cli/src/utils/devModeEvents.js.map +1 -0
  245. package/codeyam-cli/src/utils/devServerState.js +71 -0
  246. package/codeyam-cli/src/utils/devServerState.js.map +1 -0
  247. package/codeyam-cli/src/utils/editorApi.js +79 -0
  248. package/codeyam-cli/src/utils/editorApi.js.map +1 -0
  249. package/codeyam-cli/src/utils/editorAudit.js +343 -0
  250. package/codeyam-cli/src/utils/editorAudit.js.map +1 -0
  251. package/codeyam-cli/src/utils/editorBroadcastViewport.js +26 -0
  252. package/codeyam-cli/src/utils/editorBroadcastViewport.js.map +1 -0
  253. package/codeyam-cli/src/utils/editorCapture.js +102 -0
  254. package/codeyam-cli/src/utils/editorCapture.js.map +1 -0
  255. package/codeyam-cli/src/utils/editorDeleteScenario.js +67 -0
  256. package/codeyam-cli/src/utils/editorDeleteScenario.js.map +1 -0
  257. package/codeyam-cli/src/utils/editorDevServer.js +197 -0
  258. package/codeyam-cli/src/utils/editorDevServer.js.map +1 -0
  259. package/codeyam-cli/src/utils/editorEntityChangeStatus.js +44 -0
  260. package/codeyam-cli/src/utils/editorEntityChangeStatus.js.map +1 -0
  261. package/codeyam-cli/src/utils/editorEntityHelpers.js +129 -0
  262. package/codeyam-cli/src/utils/editorEntityHelpers.js.map +1 -0
  263. package/codeyam-cli/src/utils/editorImageVerifier.js +155 -0
  264. package/codeyam-cli/src/utils/editorImageVerifier.js.map +1 -0
  265. package/codeyam-cli/src/utils/editorJournal.js +225 -0
  266. package/codeyam-cli/src/utils/editorJournal.js.map +1 -0
  267. package/codeyam-cli/src/utils/editorLoaderHelpers.js +152 -0
  268. package/codeyam-cli/src/utils/editorLoaderHelpers.js.map +1 -0
  269. package/codeyam-cli/src/utils/editorMigration.js +224 -0
  270. package/codeyam-cli/src/utils/editorMigration.js.map +1 -0
  271. package/codeyam-cli/src/utils/editorMockState.js +248 -0
  272. package/codeyam-cli/src/utils/editorMockState.js.map +1 -0
  273. package/codeyam-cli/src/utils/editorPreloadHelpers.js +135 -0
  274. package/codeyam-cli/src/utils/editorPreloadHelpers.js.map +1 -0
  275. package/codeyam-cli/src/utils/editorPreview.js +137 -0
  276. package/codeyam-cli/src/utils/editorPreview.js.map +1 -0
  277. package/codeyam-cli/src/utils/editorScenarioSwitch.js +112 -0
  278. package/codeyam-cli/src/utils/editorScenarioSwitch.js.map +1 -0
  279. package/codeyam-cli/src/utils/editorScenarios.js +548 -0
  280. package/codeyam-cli/src/utils/editorScenarios.js.map +1 -0
  281. package/codeyam-cli/src/utils/editorSeedAdapter.js +422 -0
  282. package/codeyam-cli/src/utils/editorSeedAdapter.js.map +1 -0
  283. package/codeyam-cli/src/utils/editorShouldRevalidate.js +21 -0
  284. package/codeyam-cli/src/utils/editorShouldRevalidate.js.map +1 -0
  285. package/codeyam-cli/src/utils/entityChangeStatus.js +366 -0
  286. package/codeyam-cli/src/utils/entityChangeStatus.js.map +1 -0
  287. package/codeyam-cli/src/utils/entityChangeStatus.server.js +196 -0
  288. package/codeyam-cli/src/utils/entityChangeStatus.server.js.map +1 -0
  289. package/codeyam-cli/src/utils/fileMetadata.js +5 -0
  290. package/codeyam-cli/src/utils/fileMetadata.js.map +1 -1
  291. package/codeyam-cli/src/utils/fileWatcher.js +63 -9
  292. package/codeyam-cli/src/utils/fileWatcher.js.map +1 -1
  293. package/codeyam-cli/src/utils/git.js +103 -0
  294. package/codeyam-cli/src/utils/git.js.map +1 -1
  295. package/codeyam-cli/src/utils/install-skills.js +66 -15
  296. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  297. package/codeyam-cli/src/utils/interactiveSyncWatcher.js +126 -0
  298. package/codeyam-cli/src/utils/interactiveSyncWatcher.js.map +1 -0
  299. package/codeyam-cli/src/utils/npmVersionCheck.js +2 -2
  300. package/codeyam-cli/src/utils/npmVersionCheck.js.map +1 -1
  301. package/codeyam-cli/src/utils/parseRegisterArg.js +31 -0
  302. package/codeyam-cli/src/utils/parseRegisterArg.js.map +1 -0
  303. package/codeyam-cli/src/utils/pathIgnoring.js +19 -7
  304. package/codeyam-cli/src/utils/pathIgnoring.js.map +1 -1
  305. package/codeyam-cli/src/utils/progress.js +2 -2
  306. package/codeyam-cli/src/utils/progress.js.map +1 -1
  307. package/codeyam-cli/src/utils/project.js +15 -5
  308. package/codeyam-cli/src/utils/project.js.map +1 -1
  309. package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js +11 -11
  310. package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js.map +1 -1
  311. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js +22 -0
  312. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js.map +1 -1
  313. package/codeyam-cli/src/utils/queue/heartbeat.js +13 -5
  314. package/codeyam-cli/src/utils/queue/heartbeat.js.map +1 -1
  315. package/codeyam-cli/src/utils/queue/job.js +70 -1
  316. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  317. package/codeyam-cli/src/utils/queue/manager.js +7 -6
  318. package/codeyam-cli/src/utils/queue/manager.js.map +1 -1
  319. package/codeyam-cli/src/utils/requireSimulations.js +1 -1
  320. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -1
  321. package/codeyam-cli/src/utils/routePatternMatching.js +129 -0
  322. package/codeyam-cli/src/utils/routePatternMatching.js.map +1 -0
  323. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +5 -6
  324. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -1
  325. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js +1 -1
  326. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/assertRules.js.map +1 -1
  327. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js +0 -1
  328. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/helpers/setupTempProject.js.map +1 -1
  329. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js +2 -4
  330. package/codeyam-cli/src/utils/ruleReflection/__tests__/integration/ruleReflectionE2E.test.js.map +1 -1
  331. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +4 -6
  332. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -1
  333. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js +1 -1
  334. package/codeyam-cli/src/utils/ruleReflection/contextBuilder.js.map +1 -1
  335. package/codeyam-cli/src/utils/rules/__tests__/parser.test.js +83 -0
  336. package/codeyam-cli/src/utils/rules/__tests__/parser.test.js.map +1 -0
  337. package/codeyam-cli/src/utils/rules/__tests__/pathMatcher.test.js +118 -0
  338. package/codeyam-cli/src/utils/rules/__tests__/pathMatcher.test.js.map +1 -0
  339. package/codeyam-cli/src/utils/rules/__tests__/rulePlacement.test.js +72 -0
  340. package/codeyam-cli/src/utils/rules/__tests__/rulePlacement.test.js.map +1 -0
  341. package/codeyam-cli/src/utils/rules/__tests__/sourceFiles.test.js +76 -0
  342. package/codeyam-cli/src/utils/rules/__tests__/sourceFiles.test.js.map +1 -0
  343. package/codeyam-cli/src/utils/rules/index.js +1 -0
  344. package/codeyam-cli/src/utils/rules/index.js.map +1 -1
  345. package/codeyam-cli/src/utils/rules/parser.js +14 -4
  346. package/codeyam-cli/src/utils/rules/parser.js.map +1 -1
  347. package/codeyam-cli/src/utils/rules/pathMatcher.js +34 -3
  348. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -1
  349. package/codeyam-cli/src/utils/rules/rulePlacement.js +65 -0
  350. package/codeyam-cli/src/utils/rules/rulePlacement.js.map +1 -0
  351. package/codeyam-cli/src/utils/rules/sourceFiles.js +43 -0
  352. package/codeyam-cli/src/utils/rules/sourceFiles.js.map +1 -0
  353. package/codeyam-cli/src/utils/scenarioCoverage.js +74 -0
  354. package/codeyam-cli/src/utils/scenarioCoverage.js.map +1 -0
  355. package/codeyam-cli/src/utils/scenarioMarkers.js +134 -0
  356. package/codeyam-cli/src/utils/scenarioMarkers.js.map +1 -0
  357. package/codeyam-cli/src/utils/scenariosManifest.js +249 -0
  358. package/codeyam-cli/src/utils/scenariosManifest.js.map +1 -0
  359. package/codeyam-cli/src/utils/serverState.js +57 -2
  360. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  361. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +83 -11
  362. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  363. package/codeyam-cli/src/utils/simulationGateMiddleware.js +166 -0
  364. package/codeyam-cli/src/utils/simulationGateMiddleware.js.map +1 -0
  365. package/codeyam-cli/src/utils/slugUtils.js +25 -0
  366. package/codeyam-cli/src/utils/slugUtils.js.map +1 -0
  367. package/codeyam-cli/src/utils/syncMocksMiddleware.js +7 -26
  368. package/codeyam-cli/src/utils/syncMocksMiddleware.js.map +1 -1
  369. package/codeyam-cli/src/utils/testRunner.js +158 -0
  370. package/codeyam-cli/src/utils/testRunner.js.map +1 -0
  371. package/codeyam-cli/src/utils/transcriptPruning.js +67 -0
  372. package/codeyam-cli/src/utils/transcriptPruning.js.map +1 -0
  373. package/codeyam-cli/src/utils/versionInfo.js +46 -0
  374. package/codeyam-cli/src/utils/versionInfo.js.map +1 -1
  375. package/codeyam-cli/src/utils/webappDetection.js +35 -2
  376. package/codeyam-cli/src/utils/webappDetection.js.map +1 -1
  377. package/codeyam-cli/src/webserver/__tests__/buildPtyEnv.test.js +35 -0
  378. package/codeyam-cli/src/webserver/__tests__/buildPtyEnv.test.js.map +1 -0
  379. package/codeyam-cli/src/webserver/__tests__/clientErrors.test.js +40 -0
  380. package/codeyam-cli/src/webserver/__tests__/clientErrors.test.js.map +1 -0
  381. package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js +600 -0
  382. package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js.map +1 -0
  383. package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js +146 -0
  384. package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js.map +1 -0
  385. package/codeyam-cli/src/webserver/app/lib/clientErrors.js +65 -0
  386. package/codeyam-cli/src/webserver/app/lib/clientErrors.js.map +1 -0
  387. package/codeyam-cli/src/webserver/app/lib/database.js +41 -27
  388. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  389. package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
  390. package/codeyam-cli/src/webserver/app/lib/git.js +397 -0
  391. package/codeyam-cli/src/webserver/app/lib/git.js.map +1 -0
  392. package/codeyam-cli/src/webserver/app/types/editor.js +8 -0
  393. package/codeyam-cli/src/webserver/app/types/editor.js.map +1 -0
  394. package/codeyam-cli/src/webserver/backgroundServer.js +134 -20
  395. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  396. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CzTDWkF2.js +1 -0
  397. package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-bwuHPyTa.js → EntityItem-BFbq6iFk.js} +5 -5
  398. package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-CQgyEGV-.js +1 -0
  399. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-BH0XDim7.js → EntityTypeIcon-B6OMi58N.js} +9 -9
  400. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-DuYodzo1.js +1 -0
  401. package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-CXo9EeCl.js +25 -0
  402. package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-DYCNb2It.js +3 -0
  403. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-BvMu2i-g.js → LoadingDots-By5zI316.js} +1 -1
  404. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-kgBTLoJD.js → LogViewer-CZgY3sxX.js} +3 -3
  405. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-BzPgx-xO.js → ReportIssueModal-CnYYwRDw.js} +4 -4
  406. package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-CDoF7ZpU.js +1 -0
  407. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-BX2Ny2Qj.js → ScenarioViewer-DrnfvaLL.js} +3 -3
  408. package/codeyam-cli/src/webserver/build/client/assets/Spinner-Df3UCi8k.js +34 -0
  409. package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-CK7-NaPZ.js +1 -0
  410. package/codeyam-cli/src/webserver/build/client/assets/ViewportInspectBar-DRKR9T0U.js +1 -0
  411. package/codeyam-cli/src/webserver/build/client/assets/{_index-BRx8ZGZo.js → _index-ClR-g3tY.js} +4 -4
  412. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-4S4yPfFw.js → activity.(_tab)-DTH6ydEA.js} +8 -8
  413. package/codeyam-cli/src/webserver/build/client/assets/addon-canvas-DpzMmAy5.js +1 -0
  414. package/codeyam-cli/src/webserver/build/client/assets/addon-fit-YJmn1quW.js +12 -0
  415. package/codeyam-cli/src/webserver/build/client/assets/addon-web-links-74hnHF59.js +1 -0
  416. package/codeyam-cli/src/webserver/build/client/assets/addon-webgl-DI8QOUvO.js +58 -0
  417. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-B8CYhCO9.js +22 -0
  418. package/codeyam-cli/src/webserver/build/client/assets/api.dev-mode-events-l0sNRNKZ.js +1 -0
  419. package/codeyam-cli/src/webserver/build/client/assets/api.editor-audit-l0sNRNKZ.js +1 -0
  420. package/codeyam-cli/src/webserver/build/client/assets/api.editor-capture-scenario-l0sNRNKZ.js +1 -0
  421. package/codeyam-cli/src/webserver/build/client/assets/api.editor-client-errors-l0sNRNKZ.js +1 -0
  422. package/codeyam-cli/src/webserver/build/client/assets/api.editor-commit-l0sNRNKZ.js +1 -0
  423. package/codeyam-cli/src/webserver/build/client/assets/api.editor-dev-server-l0sNRNKZ.js +1 -0
  424. package/codeyam-cli/src/webserver/build/client/assets/api.editor-entity-status-l0sNRNKZ.js +1 -0
  425. package/codeyam-cli/src/webserver/build/client/assets/api.editor-file-diff-l0sNRNKZ.js +1 -0
  426. package/codeyam-cli/src/webserver/build/client/assets/api.editor-file-l0sNRNKZ.js +1 -0
  427. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-entry-l0sNRNKZ.js +1 -0
  428. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-image._-l0sNRNKZ.js +1 -0
  429. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-l0sNRNKZ.js +1 -0
  430. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-screenshot-l0sNRNKZ.js +1 -0
  431. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-update-l0sNRNKZ.js +1 -0
  432. package/codeyam-cli/src/webserver/build/client/assets/api.editor-load-commit-l0sNRNKZ.js +1 -0
  433. package/codeyam-cli/src/webserver/build/client/assets/api.editor-project-info-l0sNRNKZ.js +1 -0
  434. package/codeyam-cli/src/webserver/build/client/assets/api.editor-refresh-l0sNRNKZ.js +1 -0
  435. package/codeyam-cli/src/webserver/build/client/assets/api.editor-register-scenario-l0sNRNKZ.js +1 -0
  436. package/codeyam-cli/src/webserver/build/client/assets/api.editor-rename-scenario-l0sNRNKZ.js +1 -0
  437. package/codeyam-cli/src/webserver/build/client/assets/api.editor-save-seed-state-l0sNRNKZ.js +1 -0
  438. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-coverage-l0sNRNKZ.js +1 -0
  439. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-data-l0sNRNKZ.js +1 -0
  440. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-image._-l0sNRNKZ.js +1 -0
  441. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-prompt-l0sNRNKZ.js +1 -0
  442. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenarios-l0sNRNKZ.js +1 -0
  443. package/codeyam-cli/src/webserver/build/client/assets/api.editor-session-l0sNRNKZ.js +1 -0
  444. package/codeyam-cli/src/webserver/build/client/assets/api.editor-switch-scenario-l0sNRNKZ.js +1 -0
  445. package/codeyam-cli/src/webserver/build/client/assets/api.editor-test-results-l0sNRNKZ.js +1 -0
  446. package/codeyam-cli/src/webserver/build/client/assets/api.rule-path-l0sNRNKZ.js +1 -0
  447. package/codeyam-cli/src/webserver/build/client/assets/{book-open-D4IPYH_y.js → book-open-CLaoh4ac.js} +2 -2
  448. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-CG65viiV.js → chevron-down-BZ2DZxbW.js} +2 -2
  449. package/codeyam-cli/src/webserver/build/client/assets/{chunk-JZWAC4HX-DB3aFuEO.js → chunk-JZWAC4HX-BBXArFPl.js} +13 -21
  450. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-igfMr5DY.js → circle-check-CT4unAk-.js} +2 -2
  451. package/codeyam-cli/src/webserver/build/client/assets/{copy-Coc4o_8c.js → copy-zK0B6Nu-.js} +3 -3
  452. package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-DJB0YQJL.js +41 -0
  453. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-CkXFP_i-.js +1 -0
  454. package/codeyam-cli/src/webserver/build/client/assets/editor._tab-DPw7NZHc.js +1 -0
  455. package/codeyam-cli/src/webserver/build/client/assets/editor.entity.(_sha)-DmBK1JBK.js +58 -0
  456. package/codeyam-cli/src/webserver/build/client/assets/editorPreview-DBa7T2FK.js +41 -0
  457. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-B0h9AqE6.js → entity._sha._-BqAN7hyG.js} +11 -11
  458. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-BOi8kpwd.js +6 -0
  459. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-Dg1NhIms.js +6 -0
  460. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-CJX6kkkV.js +6 -0
  461. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-PePWg17F.js → entity._sha_.edit._scenarioId-BhVjZhKg.js} +2 -2
  462. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-I-Wo99C_.js → entry.client-_gzKltPN.js} +6 -6
  463. package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-Daa96Fr1.js +1 -0
  464. package/codeyam-cli/src/webserver/build/client/assets/files-CV_17tZS.js +1 -0
  465. package/codeyam-cli/src/webserver/build/client/assets/git-D-YXmMbR.js +1 -0
  466. package/codeyam-cli/src/webserver/build/client/assets/globals-CGrDAxj0.css +1 -0
  467. package/codeyam-cli/src/webserver/build/client/assets/index-Blo6EK8G.js +15 -0
  468. package/codeyam-cli/src/webserver/build/client/assets/{index-CUM5iXwc.js → index-BsX0F-9C.js} +1 -1
  469. package/codeyam-cli/src/webserver/build/client/assets/{index-_417gcQW.js → index-CCrgCshv.js} +1 -1
  470. package/codeyam-cli/src/webserver/build/client/assets/jsx-runtime-D_zvdyIk.js +9 -0
  471. package/codeyam-cli/src/webserver/build/client/assets/labs-Byazq8Pv.js +1 -0
  472. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-TzRHMVog.js → loader-circle-DVQ0oHR7.js} +2 -2
  473. package/codeyam-cli/src/webserver/build/client/assets/manifest-b3f77062.js +1 -0
  474. package/codeyam-cli/src/webserver/build/client/assets/memory-b-VmA2Vj.js +101 -0
  475. package/codeyam-cli/src/webserver/build/client/assets/{pause-hjzB7t2z.js → pause-DGcndCAa.js} +3 -3
  476. package/codeyam-cli/src/webserver/build/client/assets/root-D5Zi3U2Z.js +67 -0
  477. package/codeyam-cli/src/webserver/build/client/assets/{search-DcAwD_Ln.js → search-C0Uw0bcK.js} +2 -2
  478. package/codeyam-cli/src/webserver/build/client/assets/settings-OoNgHIfW.js +1 -0
  479. package/codeyam-cli/src/webserver/build/client/assets/simulations-Bcemfu8a.js +1 -0
  480. package/codeyam-cli/src/webserver/build/client/assets/{terminal-DbEAHMbA.js → terminal-BgMmG7R9.js} +3 -3
  481. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-CAD5b1o_.js → triangle-alert-Cs87hJYK.js} +2 -2
  482. package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-BR3Rs7JY.js +1 -0
  483. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-BxxP_XF9.js +2 -0
  484. package/codeyam-cli/src/webserver/build/client/assets/useReportContext-BermyNU5.js +1 -0
  485. package/codeyam-cli/src/webserver/build/client/assets/useToast-a_QN_W9_.js +1 -0
  486. package/codeyam-cli/src/webserver/build/client/assets/xterm-BqvuqXEL.js +27 -0
  487. package/codeyam-cli/src/webserver/build/client/sound-test.html +98 -0
  488. package/codeyam-cli/src/webserver/build/server/assets/analysisRunner-yTyb36j3.js +13 -0
  489. package/codeyam-cli/src/webserver/build/server/assets/index-Cr7d_IsG.js +1 -0
  490. package/codeyam-cli/src/webserver/build/server/assets/init-M_wqNAfu.js +10 -0
  491. package/codeyam-cli/src/webserver/build/server/assets/progress-CHTtrxFG.js +1 -0
  492. package/codeyam-cli/src/webserver/build/server/assets/server-build-_ybRgrlc.js +551 -0
  493. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  494. package/codeyam-cli/src/webserver/build-info.json +5 -5
  495. package/codeyam-cli/src/webserver/devServer.js +39 -5
  496. package/codeyam-cli/src/webserver/devServer.js.map +1 -1
  497. package/codeyam-cli/src/webserver/editorProxy.js +959 -0
  498. package/codeyam-cli/src/webserver/editorProxy.js.map +1 -0
  499. package/codeyam-cli/src/webserver/idleDetector.js +73 -0
  500. package/codeyam-cli/src/webserver/idleDetector.js.map +1 -0
  501. package/codeyam-cli/src/webserver/mockStateEvents.js +28 -0
  502. package/codeyam-cli/src/webserver/mockStateEvents.js.map +1 -0
  503. package/codeyam-cli/src/webserver/public/sound-test.html +98 -0
  504. package/codeyam-cli/src/webserver/scripts/codeyam-preload.mjs +414 -0
  505. package/codeyam-cli/src/webserver/scripts/journalCapture.ts +230 -0
  506. package/codeyam-cli/src/webserver/server.js +309 -1
  507. package/codeyam-cli/src/webserver/server.js.map +1 -1
  508. package/codeyam-cli/src/webserver/terminalServer.js +831 -0
  509. package/codeyam-cli/src/webserver/terminalServer.js.map +1 -0
  510. package/codeyam-cli/templates/chrome-extension-react/EXTENSION_SETUP.md +75 -0
  511. package/codeyam-cli/templates/chrome-extension-react/README.md +46 -0
  512. package/codeyam-cli/templates/chrome-extension-react/gitignore +15 -0
  513. package/codeyam-cli/templates/chrome-extension-react/index.html +12 -0
  514. package/codeyam-cli/templates/chrome-extension-react/package.json +27 -0
  515. package/codeyam-cli/templates/chrome-extension-react/popup.html +12 -0
  516. package/codeyam-cli/templates/chrome-extension-react/public/manifest.json +15 -0
  517. package/codeyam-cli/templates/chrome-extension-react/src/background/service-worker.ts +7 -0
  518. package/codeyam-cli/templates/chrome-extension-react/src/globals.css +6 -0
  519. package/codeyam-cli/templates/chrome-extension-react/src/lib/storage.ts +37 -0
  520. package/codeyam-cli/templates/chrome-extension-react/src/popup/App.tsx +12 -0
  521. package/codeyam-cli/templates/chrome-extension-react/src/popup/main.tsx +10 -0
  522. package/codeyam-cli/templates/chrome-extension-react/tsconfig.json +24 -0
  523. package/codeyam-cli/templates/chrome-extension-react/vite.config.ts +41 -0
  524. package/codeyam-cli/templates/codeyam-editor-claude.md +147 -0
  525. package/codeyam-cli/templates/editor-step-hook.py +321 -0
  526. package/codeyam-cli/templates/expo-react-native/MOBILE_SETUP.md +89 -0
  527. package/codeyam-cli/templates/expo-react-native/README.md +41 -0
  528. package/codeyam-cli/templates/expo-react-native/app/(tabs)/_layout.tsx +33 -0
  529. package/codeyam-cli/templates/expo-react-native/app/(tabs)/index.tsx +12 -0
  530. package/codeyam-cli/templates/expo-react-native/app/(tabs)/settings.tsx +12 -0
  531. package/codeyam-cli/templates/expo-react-native/app/_layout.tsx +12 -0
  532. package/codeyam-cli/templates/expo-react-native/app.json +18 -0
  533. package/codeyam-cli/templates/expo-react-native/babel.config.js +9 -0
  534. package/codeyam-cli/templates/expo-react-native/gitignore +12 -0
  535. package/codeyam-cli/templates/expo-react-native/global.css +3 -0
  536. package/codeyam-cli/templates/expo-react-native/lib/storage.ts +32 -0
  537. package/codeyam-cli/templates/expo-react-native/metro.config.js +6 -0
  538. package/codeyam-cli/templates/expo-react-native/nativewind-env.d.ts +1 -0
  539. package/codeyam-cli/templates/expo-react-native/package.json +38 -0
  540. package/codeyam-cli/templates/expo-react-native/tailwind.config.js +10 -0
  541. package/codeyam-cli/templates/expo-react-native/tsconfig.json +10 -0
  542. package/codeyam-cli/templates/hooks/staleness-check.sh +43 -0
  543. package/codeyam-cli/templates/isolation-route/next-app.tsx.template +80 -0
  544. package/codeyam-cli/templates/isolation-route/next-pages.tsx.template +79 -0
  545. package/codeyam-cli/templates/isolation-route/vite-react.tsx.template +78 -0
  546. package/codeyam-cli/templates/msw/browser-setup.ts.template +47 -0
  547. package/codeyam-cli/templates/msw/handler-router.ts.template +47 -0
  548. package/codeyam-cli/templates/msw/server-setup.ts.template +52 -0
  549. package/codeyam-cli/templates/nextjs-prisma-sqlite/AUTH_PATTERNS.md +308 -0
  550. package/codeyam-cli/templates/nextjs-prisma-sqlite/AUTH_UPGRADE.md +304 -0
  551. package/codeyam-cli/templates/nextjs-prisma-sqlite/DATABASE.md +126 -0
  552. package/codeyam-cli/templates/nextjs-prisma-sqlite/FEATURE_PATTERNS.md +37 -0
  553. package/codeyam-cli/templates/nextjs-prisma-sqlite/README.md +53 -0
  554. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/api/todos/route.ts +17 -0
  555. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/codeyam-isolate/layout.tsx +12 -0
  556. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/globals.css +26 -0
  557. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/layout.tsx +34 -0
  558. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/lib/prisma.ts +24 -0
  559. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/page.tsx +10 -0
  560. package/codeyam-cli/templates/nextjs-prisma-sqlite/env +4 -0
  561. package/codeyam-cli/templates/nextjs-prisma-sqlite/eslint.config.mjs +11 -0
  562. package/codeyam-cli/templates/nextjs-prisma-sqlite/gitignore +64 -0
  563. package/codeyam-cli/templates/nextjs-prisma-sqlite/next.config.ts +14 -0
  564. package/codeyam-cli/templates/nextjs-prisma-sqlite/package.json +39 -0
  565. package/codeyam-cli/templates/nextjs-prisma-sqlite/postcss.config.mjs +7 -0
  566. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/schema.prisma +27 -0
  567. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/seed.ts +40 -0
  568. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma.config.ts +12 -0
  569. package/codeyam-cli/templates/nextjs-prisma-sqlite/seed-adapter.ts +127 -0
  570. package/codeyam-cli/templates/nextjs-prisma-sqlite/tsconfig.json +34 -0
  571. package/codeyam-cli/templates/nextjs-prisma-sqlite/vitest.config.ts +13 -0
  572. package/codeyam-cli/templates/nextjs-prisma-supabase/README.md +52 -0
  573. package/codeyam-cli/templates/nextjs-prisma-supabase/SUPABASE_SETUP.md +104 -0
  574. package/codeyam-cli/templates/nextjs-prisma-supabase/app/api/todos/route.ts +17 -0
  575. package/codeyam-cli/templates/nextjs-prisma-supabase/app/globals.css +26 -0
  576. package/codeyam-cli/templates/nextjs-prisma-supabase/app/layout.tsx +34 -0
  577. package/codeyam-cli/templates/nextjs-prisma-supabase/app/lib/prisma.ts +20 -0
  578. package/codeyam-cli/templates/nextjs-prisma-supabase/app/lib/supabase.ts +12 -0
  579. package/codeyam-cli/templates/nextjs-prisma-supabase/app/page.tsx +10 -0
  580. package/codeyam-cli/templates/nextjs-prisma-supabase/env +9 -0
  581. package/codeyam-cli/templates/nextjs-prisma-supabase/eslint.config.mjs +11 -0
  582. package/codeyam-cli/templates/nextjs-prisma-supabase/gitignore +40 -0
  583. package/codeyam-cli/templates/nextjs-prisma-supabase/next.config.ts +11 -0
  584. package/codeyam-cli/templates/nextjs-prisma-supabase/package.json +37 -0
  585. package/codeyam-cli/templates/nextjs-prisma-supabase/postcss.config.mjs +7 -0
  586. package/codeyam-cli/templates/nextjs-prisma-supabase/prisma/schema.prisma +27 -0
  587. package/codeyam-cli/templates/nextjs-prisma-supabase/prisma/seed.ts +39 -0
  588. package/codeyam-cli/templates/nextjs-prisma-supabase/prisma.config.ts +12 -0
  589. package/codeyam-cli/templates/nextjs-prisma-supabase/tsconfig.json +34 -0
  590. package/codeyam-cli/templates/prompts/conversation-guidance.txt +44 -0
  591. package/codeyam-cli/templates/prompts/conversation-prompt.txt +28 -0
  592. package/codeyam-cli/templates/prompts/interruption-prompt.txt +31 -0
  593. package/codeyam-cli/templates/prompts/stale-rules-prompt.txt +24 -0
  594. package/codeyam-cli/templates/rule-notification-hook.py +44 -17
  595. package/codeyam-cli/templates/rule-reflection-hook.py +25 -5
  596. package/codeyam-cli/templates/rules-instructions.md +34 -88
  597. package/codeyam-cli/templates/seed-adapters/supabase.ts +282 -0
  598. package/codeyam-cli/templates/skills/codeyam-dev-mode/SKILL.md +237 -0
  599. package/codeyam-cli/templates/skills/codeyam-editor/SKILL.md +211 -0
  600. package/codeyam-cli/templates/{codeyam-memory.md → skills/codeyam-memory/SKILL.md} +215 -0
  601. package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/deprecated-prompt.md +100 -0
  602. package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/detect-deprecated-patterns.mjs +139 -0
  603. package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/find-exports.mjs +52 -0
  604. package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/misleading-api-prompt.md +117 -0
  605. package/codeyam-cli/templates/skills/codeyam-memory/scripts/lib/read-json-field.mjs +61 -0
  606. package/codeyam-cli/templates/skills/codeyam-memory/scripts/lib/ripgrep-fallback.mjs +155 -0
  607. package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/analyze-prompt.md +46 -0
  608. package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/cleanup.mjs +13 -0
  609. package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/filter-session.mjs +95 -0
  610. package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/preprocess.mjs +160 -0
  611. package/codeyam-cli/templates/{codeyam-new-rule.md → skills/codeyam-new-rule/SKILL.md} +0 -2
  612. package/package.json +21 -14
  613. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +22 -4
  614. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  615. package/packages/ai/src/lib/completionCall.js +10 -7
  616. package/packages/ai/src/lib/completionCall.js.map +1 -1
  617. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +234 -3
  618. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  619. package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js +54 -0
  620. package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js.map +1 -0
  621. package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js +34 -0
  622. package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js.map +1 -0
  623. package/packages/ai/src/lib/dataStructureChunking.js +9 -5
  624. package/packages/ai/src/lib/dataStructureChunking.js.map +1 -1
  625. package/packages/ai/src/lib/generateEntityScenarioData.js +57 -2
  626. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  627. package/packages/ai/src/lib/generateExecutionFlows.js +81 -11
  628. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  629. package/packages/analyze/src/lib/ProjectAnalyzer.js +13 -4
  630. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  631. package/packages/analyze/src/lib/asts/index.js +4 -2
  632. package/packages/analyze/src/lib/asts/index.js.map +1 -1
  633. package/packages/analyze/src/lib/asts/nodes/getNodeType.js +1 -0
  634. package/packages/analyze/src/lib/asts/nodes/getNodeType.js.map +1 -1
  635. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +8 -1
  636. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  637. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +0 -5
  638. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  639. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js +9 -0
  640. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js.map +1 -1
  641. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +54 -27
  642. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -1
  643. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +65 -0
  644. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  645. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +0 -40
  646. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  647. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +18 -4
  648. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  649. package/packages/database/index.js +1 -0
  650. package/packages/database/index.js.map +1 -1
  651. package/packages/database/src/lib/kysely/db.js +5 -0
  652. package/packages/database/src/lib/kysely/db.js.map +1 -1
  653. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js +149 -0
  654. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
  655. package/packages/database/src/lib/loadCommits.js +23 -13
  656. package/packages/database/src/lib/loadCommits.js.map +1 -1
  657. package/packages/database/src/lib/loadEntities.js +0 -6
  658. package/packages/database/src/lib/loadEntities.js.map +1 -1
  659. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
  660. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  661. package/packages/database/src/lib/updateCommitMetadata.js +76 -90
  662. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  663. package/packages/database/src/lib/updateFreshAnalysisStatus.js +41 -30
  664. package/packages/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
  665. package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
  666. package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
  667. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
  668. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
  669. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
  670. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  671. package/packages/types/src/enums/ProjectFramework.js +2 -0
  672. package/packages/types/src/enums/ProjectFramework.js.map +1 -1
  673. package/packages/utils/src/lib/fs/rsyncCopy.js +6 -2
  674. package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  675. package/scripts/npm-post-install.cjs +34 -0
  676. package/codeyam-cli/src/commands/detect-universal-mocks.js +0 -120
  677. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +0 -1
  678. package/codeyam-cli/src/commands/list.js +0 -31
  679. package/codeyam-cli/src/commands/list.js.map +0 -1
  680. package/codeyam-cli/src/commands/webapp-info.js +0 -146
  681. package/codeyam-cli/src/commands/webapp-info.js.map +0 -1
  682. package/codeyam-cli/src/utils/universal-mocks.js +0 -152
  683. package/codeyam-cli/src/utils/universal-mocks.js.map +0 -1
  684. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-jNYXRRNI.js +0 -1
  685. package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-CvzqMxcu.js +0 -1
  686. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-EhOseatT.js +0 -34
  687. package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-yjIHlOGa.js +0 -25
  688. package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-Cq5o8jL4.js +0 -3
  689. package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-CwZrv-Ok.js +0 -1
  690. package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-CDpEprKa.js +0 -1
  691. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-DHKuQSmR.js +0 -17
  692. package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-D1zB-pYc.js +0 -21
  693. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-JTAjQ54M.js +0 -1
  694. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-DjLxr2JB.js +0 -6
  695. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-CtYowLOt.js +0 -6
  696. package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-9sMMAiWJ.js +0 -1
  697. package/codeyam-cli/src/webserver/build/client/assets/files-Co65J0s3.js +0 -1
  698. package/codeyam-cli/src/webserver/build/client/assets/git-BdHOxVfg.js +0 -15
  699. package/codeyam-cli/src/webserver/build/client/assets/globals-CCgBKWy4.css +0 -1
  700. package/codeyam-cli/src/webserver/build/client/assets/labs-BK0C1H1T.js +0 -1
  701. package/codeyam-cli/src/webserver/build/client/assets/manifest-7d29f0c4.js +0 -1
  702. package/codeyam-cli/src/webserver/build/client/assets/memory-CzZySbBE.js +0 -78
  703. package/codeyam-cli/src/webserver/build/client/assets/root-COPwrT8R.js +0 -62
  704. package/codeyam-cli/src/webserver/build/client/assets/settings-CclxrcPK.js +0 -1
  705. package/codeyam-cli/src/webserver/build/client/assets/simulations-DVNJVQgD.js +0 -1
  706. package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-BqgrAzs3.js +0 -1
  707. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-DAFqfEDH.js +0 -2
  708. package/codeyam-cli/src/webserver/build/client/assets/useReportContext-DZlYx2c4.js +0 -1
  709. package/codeyam-cli/src/webserver/build/client/assets/useToast-ihdMtlf6.js +0 -1
  710. package/codeyam-cli/src/webserver/build/server/assets/index-ChT1lWao.js +0 -1
  711. package/codeyam-cli/src/webserver/build/server/assets/server-build-CtNSi7yC.js +0 -259
  712. package/codeyam-cli/templates/codeyam-stop-hook.sh +0 -284
  713. package/scripts/finalize-analyzer.cjs +0 -13
  714. /package/codeyam-cli/templates/{codeyam-diagnose.md → commands/codeyam-diagnose.md} +0 -0
  715. /package/codeyam-cli/templates/{codeyam-debug.md → skills/codeyam-debug/SKILL.md} +0 -0
  716. /package/codeyam-cli/templates/{codeyam-setup.md → skills/codeyam-setup/SKILL.md} +0 -0
  717. /package/codeyam-cli/templates/{codeyam-sim.md → skills/codeyam-sim/SKILL.md} +0 -0
  718. /package/codeyam-cli/templates/{codeyam-test.md → skills/codeyam-test/SKILL.md} +0 -0
  719. /package/codeyam-cli/templates/{codeyam-verify.md → skills/codeyam-verify/SKILL.md} +0 -0
@@ -0,0 +1,831 @@
1
+ var _a, _b;
2
+ import { WebSocketServer, WebSocket } from 'ws';
3
+ import crypto from 'crypto';
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ import * as pty from 'node-pty';
7
+ import { createMarkerTransformer } from "../utils/scenarioMarkers.js";
8
+ import { IdleDetector } from "./idleDetector.js";
9
+ import { mockStateEventEmitter } from "./mockStateEvents.js";
10
+ // Use globalThis so the sessions Set is shared across module instances.
11
+ // In Vite dev mode, this file is loaded twice: once by the Vite plugin (Node.js native)
12
+ // and once by the SSR context (ssrLoadModule). Without globalThis, each instance
13
+ // gets its own empty Set — so broadcastPreviewRefresh() called from the SSR instance
14
+ // (via the /api/dev-mode-preview endpoint) would broadcast to 0 sessions.
15
+ const sessions = ((_a = globalThis).__codeyamTerminalSessions ?? (_a.__codeyamTerminalSessions = new Set()));
16
+ // Detached PTYs waiting for reconnection (keyed by sessionId).
17
+ // When a WebSocket drops, the PTY is moved here with a grace timer
18
+ // instead of being killed immediately, allowing the client to reconnect.
19
+ const detachedPtys = ((_b = globalThis).__codeyamDetachedPtys ?? (_b.__codeyamDetachedPtys = new Map()));
20
+ const PING_INTERVAL_MS = 30000;
21
+ const DETACH_GRACE_MS = 60000;
22
+ const OUTPUT_BUFFER_MAX = 8 * 1024; // 8KB
23
+ // Ping interval reference — shared so cleanup can clear it
24
+ let pingInterval = globalThis.__codeyamPingInterval ?? null;
25
+ // Keys to forward from the server env into the PTY shell.
26
+ // Keeps the env clean (no giant CODEYAM_PROJECT JSON blobs) while
27
+ // preserving everything Claude Code and the user's shell need.
28
+ const ENV_PASSTHROUGH_KEYS = [
29
+ 'PATH',
30
+ 'HOME',
31
+ 'USER',
32
+ 'LOGNAME',
33
+ 'SHELL',
34
+ 'TERM',
35
+ 'LANG',
36
+ 'LC_ALL',
37
+ 'LC_CTYPE',
38
+ 'EDITOR',
39
+ 'VISUAL',
40
+ 'TMPDIR',
41
+ 'XDG_CONFIG_HOME',
42
+ 'XDG_DATA_HOME',
43
+ 'XDG_CACHE_HOME',
44
+ // API keys Claude Code may need
45
+ 'ANTHROPIC_API_KEY',
46
+ 'OPENAI_API_KEY',
47
+ // nvm / fnm / volta node version managers
48
+ 'NVM_DIR',
49
+ 'NVM_BIN',
50
+ 'FNM_DIR',
51
+ 'VOLTA_HOME',
52
+ // Homebrew
53
+ 'HOMEBREW_PREFIX',
54
+ 'HOMEBREW_CELLAR',
55
+ 'HOMEBREW_REPOSITORY',
56
+ ];
57
+ export function buildPtyEnv(options) {
58
+ const env = {};
59
+ for (const key of ENV_PASSTHROUGH_KEYS) {
60
+ const val = process.env[key];
61
+ if (val != null)
62
+ env[key] = val;
63
+ }
64
+ // Always set TERM for proper terminal behavior
65
+ if (!env.TERM)
66
+ env.TERM = 'xterm-256color';
67
+ // Signal to hooks that this is an editor Build session.
68
+ // Without this, editor hooks fire in ALL Claude sessions in the project.
69
+ if (options?.editorMode) {
70
+ env.CODEYAM_EDITOR_ACTIVE = '1';
71
+ }
72
+ return env;
73
+ }
74
+ /**
75
+ * Convert a name to a safe file name matching CodeYam's convention.
76
+ * e.g. "Default Scenario" -> "Default_Scenario"
77
+ */
78
+ function safeFileName(name) {
79
+ const safe = name.replace(/[^a-zA-Z0-9_]+/g, '_').replace(/^_+|_+$/g, '');
80
+ return safe.slice(0, 1).toUpperCase() + safe.slice(1);
81
+ }
82
+ /**
83
+ * Find the actual mock data file for a scenario in the tmp project.
84
+ * Tries a fast heuristic (extract app dir from entity file path) first,
85
+ * then falls back to a shallow directory search.
86
+ */
87
+ function findMockDataFile(projectRoot, entityFilePath, scenarioName) {
88
+ const scenarioSlug = safeFileName(scenarioName);
89
+ const mockFile = `MockData_${scenarioSlug}.tsx`;
90
+ // Heuristic: the __codeyamMocks__ dir lives at the app directory level.
91
+ // Extract "app/" (or "src/", "pages/") from the entity's file path.
92
+ if (entityFilePath) {
93
+ const parts = entityFilePath.split('/');
94
+ for (let i = 0; i < parts.length; i++) {
95
+ if (['app', 'src', 'pages'].includes(parts[i])) {
96
+ const appDir = parts.slice(0, i + 1).join('/');
97
+ const candidate = path.join(projectRoot, appDir, '__codeyamMocks__', mockFile);
98
+ if (fs.existsSync(candidate))
99
+ return candidate;
100
+ }
101
+ }
102
+ }
103
+ // Fallback: search __codeyamMocks__ directories up to 5 levels deep
104
+ function searchDir(dir, depth) {
105
+ if (depth > 5)
106
+ return null;
107
+ try {
108
+ for (const entry of fs.readdirSync(dir)) {
109
+ if (entry === 'node_modules' ||
110
+ entry === '.git' ||
111
+ entry === 'coverage')
112
+ continue;
113
+ const full = path.join(dir, entry);
114
+ if (entry === '__codeyamMocks__') {
115
+ const candidate = path.join(full, mockFile);
116
+ if (fs.existsSync(candidate))
117
+ return candidate;
118
+ continue;
119
+ }
120
+ try {
121
+ if (fs.statSync(full).isDirectory()) {
122
+ const result = searchDir(full, depth + 1);
123
+ if (result)
124
+ return result;
125
+ }
126
+ }
127
+ catch {
128
+ // Permission error or broken symlink
129
+ }
130
+ }
131
+ }
132
+ catch {
133
+ // Directory unreadable
134
+ }
135
+ return null;
136
+ }
137
+ return searchDir(projectRoot, 0);
138
+ }
139
+ /**
140
+ * Write a structured context file for the codeyam-dev-mode skill.
141
+ * The skill reads this file on startup instead of receiving a long CLI argument.
142
+ * Returns true if context was written successfully, false otherwise.
143
+ */
144
+ function writeDevModeContext(ctx) {
145
+ if (!ctx.entityName)
146
+ return false;
147
+ const codeyamRoot = process.env.CODEYAM_ROOT_PATH || process.cwd();
148
+ const contextDir = path.join(codeyamRoot, '.codeyam');
149
+ const contextPath = path.join(contextDir, 'dev-mode-context.md');
150
+ try {
151
+ fs.mkdirSync(contextDir, { recursive: true });
152
+ const lines = ['# Dev Mode Context', ''];
153
+ // Entity section
154
+ lines.push('## Entity');
155
+ lines.push(`- **Name:** ${ctx.entityName}`);
156
+ if (ctx.entityType)
157
+ lines.push(`- **Type:** ${ctx.entityType}`);
158
+ if (ctx.entitySha)
159
+ lines.push(`- **SHA:** ${ctx.entitySha}`);
160
+ if (ctx.entityFilePath)
161
+ lines.push(`- **Source file:** ${ctx.entityFilePath}`);
162
+ lines.push('');
163
+ // Scenario section
164
+ if (ctx.scenarioName) {
165
+ lines.push('## Scenario');
166
+ lines.push(`- **Name:** ${ctx.scenarioName}`);
167
+ if (ctx.scenarioDescription)
168
+ lines.push(`- **Description:** ${ctx.scenarioDescription}`);
169
+ if (ctx.analysisId)
170
+ lines.push(`- **Analysis ID:** ${ctx.analysisId}`);
171
+ lines.push('');
172
+ }
173
+ // Files section
174
+ lines.push('## Files');
175
+ if (ctx.entityFilePath) {
176
+ lines.push(`- **Source file:** ${ctx.entityFilePath}`);
177
+ }
178
+ if (ctx.projectSlug && ctx.scenarioName) {
179
+ const tmpBase = `/tmp/codeyam/local-dev/${ctx.projectSlug}`;
180
+ const tmpProject = `${tmpBase}/project`;
181
+ const mockDataPath = findMockDataFile(tmpProject, ctx.entityFilePath, ctx.scenarioName);
182
+ if (mockDataPath) {
183
+ lines.push(`- **Mock data:** ${mockDataPath}`);
184
+ }
185
+ else {
186
+ const scenarioSlug = safeFileName(ctx.scenarioName);
187
+ lines.push(`- **Mock data:** search for \`MockData_${scenarioSlug}.tsx\` in \`__codeyamMocks__\` under ${tmpProject}`);
188
+ }
189
+ lines.push(`- **Dev server project:** ${tmpProject}`);
190
+ lines.push(`- **Server log:** ${tmpBase}/codeyam/log.txt`);
191
+ }
192
+ lines.push('');
193
+ // Database
194
+ lines.push('## Database');
195
+ lines.push(`- **Path:** .codeyam/db.sqlite3`);
196
+ lines.push('');
197
+ // Server
198
+ const serverPort = process.env.CODEYAM_PORT || '3111';
199
+ lines.push('## Server');
200
+ lines.push(`- **Refresh preview:** \`curl -X POST http://localhost:${serverPort}/api/dev-mode-preview -H 'Content-Type: application/json' -d '{"dimension":"Desktop"}'\` (dimension is REQUIRED)`);
201
+ lines.push('');
202
+ fs.writeFileSync(contextPath, lines.join('\n'), 'utf8');
203
+ return true;
204
+ }
205
+ catch (error) {
206
+ console.error('[terminalServer] Failed to write dev-mode-context.md:', error);
207
+ return false;
208
+ }
209
+ }
210
+ /**
211
+ * Write a structured context file for the codeyam-editor skill.
212
+ * Returns true if context was written successfully, false otherwise.
213
+ */
214
+ function writeEditorModeContext(ctx) {
215
+ if (!ctx.projectSlug)
216
+ return false;
217
+ const codeyamRoot = process.env.CODEYAM_ROOT_PATH || process.cwd();
218
+ const contextDir = path.join(codeyamRoot, '.codeyam');
219
+ const contextPath = path.join(contextDir, 'editor-mode-context.md');
220
+ try {
221
+ fs.mkdirSync(contextDir, { recursive: true });
222
+ const serverPort = process.env.CODEYAM_PORT || '3111';
223
+ const proxyPort = parseInt(serverPort, 10) + 1;
224
+ const lines = [
225
+ '# Editor Mode Context',
226
+ '',
227
+ '## Project',
228
+ `- **Root:** ${codeyamRoot}`,
229
+ `- **Slug:** ${ctx.projectSlug}`,
230
+ '',
231
+ '## Server',
232
+ `- **Port:** ${serverPort}`,
233
+ `- **Dashboard:** http://localhost:${serverPort}/editor`,
234
+ `- **Proxy:** http://localhost:${proxyPort} (used by the browser iframe only — do NOT use for health checks)`,
235
+ '',
236
+ '## Workflow',
237
+ '- **Guided steps:** Run `codeyam editor steps` for the next step (plan → prototype → confirm → deconstruct → extract → glossary → analyze → app scenarios → user scenarios → verify → journal → review → present → commit → finalize → push)',
238
+ '- Each feature follows 16 steps: `codeyam editor 1` through `codeyam editor 16`',
239
+ '- Steps 1, 3, 13, and 16 require user confirmation before proceeding',
240
+ '',
241
+ '## Preview Updates',
242
+ '- **Refresh the preview frequently** — the user watches the preview as you work. Refresh after every meaningful change (new page, UI section, data seeding, styling), not just at the end.',
243
+ `- **Refresh command:** \`curl -s -X POST http://localhost:${serverPort}/api/dev-mode-preview -H 'Content-Type: application/json' -d '{"dimension":"Desktop"}'\` (dimension is REQUIRED)`,
244
+ '- Aim for 4-8+ preview updates during a typical building session.',
245
+ '',
246
+ '## Verifying the Dev Server',
247
+ '- Get the dev server URL: `curl -s http://localhost:' +
248
+ serverPort +
249
+ '/api/editor-dev-server` → look at the `"url"` field (e.g., `http://localhost:3000`)',
250
+ '- Check the page loads: `curl -s -o /dev/null -w "%{http_code}" http://localhost:3000` (use the actual dev server URL, NOT the proxy)',
251
+ '- Check API routes work: `curl -s http://localhost:3000/api/your-route` (should return JSON, not "Internal Server Error")',
252
+ '- **NEVER check localhost:' +
253
+ proxyPort +
254
+ ' for health** — the proxy returns 200 even when the app is broken',
255
+ '',
256
+ '## API Endpoints',
257
+ `- **Register scenario (auto-captures screenshot):** \`codeyam editor register '{"name":"...","url":"/page-to-screenshot","type":"application","seed":{...}}'\` — ALWAYS include "url" for the page to screenshot. For large payloads, write JSON to a file and use @ prefix: \`codeyam editor register @/tmp/scenario.json\``,
258
+ `- **Get active scenario data:** \`curl http://localhost:${serverPort}/api/editor-scenario-data\``,
259
+ `- **Refresh/navigate/switch preview:** \`curl -X POST http://localhost:${serverPort}/api/dev-mode-preview -H 'Content-Type: application/json' -d '{"dimension":"Desktop"}'\` (dimension is REQUIRED in every call; add \`"path":"/route"\` to navigate; add \`"scenarioId":"..."\` to switch scenario). Clears logs, waits for HMR, checks SSR health.`,
260
+ `- **Refresh config:** \`curl -X POST http://localhost:${serverPort}/api/editor-refresh\` (also starts dev server if a webapp is detected)`,
261
+ `- **Dev server status:** \`curl http://localhost:${serverPort}/api/editor-dev-server\``,
262
+ `- **Start dev server:** \`curl -X POST http://localhost:${serverPort}/api/editor-dev-server -H 'Content-Type: application/json' -d '{"action":"start"}'\``,
263
+ `- **Restart dev server:** \`curl -X POST http://localhost:${serverPort}/api/editor-dev-server -H 'Content-Type: application/json' -d '{"action":"restart"}'\``,
264
+ `- **Re-capture scenario screenshot:** \`curl -X POST http://localhost:${serverPort}/api/editor-capture-scenario -H 'Content-Type: application/json' -d '{"scenarioId":"...","url":"..."}'\` (for manual re-capture; register auto-captures)`,
265
+ `- **Journal screenshot:** \`curl -X POST http://localhost:${serverPort}/api/editor-journal-screenshot -H 'Content-Type: application/json' -d '{"url":"...","filename":"..."}'\``,
266
+ `- **Journal entry:** \`curl -X POST http://localhost:${serverPort}/api/editor-journal-entry -H 'Content-Type: application/json' -d '{"title":"...","type":"feature","description":"..."}'\``,
267
+ '',
268
+ '## Scenario Data Format',
269
+ '- Use **route-keyed** mock data: keys are the API paths your app fetches',
270
+ '- Example: `{ "routes": { "/api/tasks": { "body": [...] }, "/api/users": { "body": [...] } } }`',
271
+ '- Error scenarios: `{ "routes": { "/api/tasks": { "status": 500, "body": { "error": "..." } } } }`',
272
+ '- The proxy intercepts GET requests to matching routes and returns the mock data',
273
+ '- POST/PUT/DELETE always go through to the real dev server',
274
+ '',
275
+ '## Component Isolation Routes',
276
+ '- Create isolation route dirs: `codeyam editor isolate ComponentA ComponentB ...`',
277
+ ' - This creates the layout guard and a directory per component under `app/isolated-components/`',
278
+ '- Create ONE isolation route page per component:',
279
+ ' - **Remix:** `app/routes/isolated-components.ComponentName.tsx` → `/isolated-components/ComponentName`',
280
+ ' - **Next.js:** `app/isolated-components/ComponentName/page.tsx` → `/isolated-components/ComponentName`',
281
+ '- The route defines a `scenarios` object mapping scenario names to props, reads `?s=ScenarioName` from the URL, and renders the component',
282
+ '- Wrap the component in a centered container: `<div style="display:flex;justify-content:center;align-items:center;min-height:100vh;padding:20px"><div style="width:100%;max-width:...">` — set max-width to match the component\'s real container (e.g. card in 3-col grid → 24rem)',
283
+ '- **Create multiple scenarios per component** (like tests): default/happy path, edge cases (empty data, long text, max items), different visual states (loading, error, disabled)',
284
+ '- Register each scenario: `codeyam editor register \'{"name":"ComponentName - Scenario","componentName":"ComponentName","componentPath":"path/to/file.tsx","url":"/isolated-components/ComponentName?s=Scenario","mockData":{"routes":{"/api/...":{"body":[...]}}}}\'`',
285
+ '- The url is a PATH, not a full URL — the proxy appends it and intercepts API calls the component makes',
286
+ '- `mockData.routes` provides data for any API calls the component makes internally (omit if none)',
287
+ '- Isolation routes stay in the project so the editor preview can display them',
288
+ '- Ensure `.gitignore` includes `**/isolated-components*` so they are not committed',
289
+ '',
290
+ '## Files',
291
+ '- **Scenario data:** .codeyam/editor-scenarios/{scenario-id}.json',
292
+ '- **Scenario screenshots:** .codeyam/editor-scenarios/screenshots/{scenario-id}.png',
293
+ '- **Active scenario:** .codeyam/active-scenario.json',
294
+ '- **Database:** .codeyam/db.sqlite3',
295
+ '- **Journal:** .codeyam/journal/ (daily .md files + index.json + screenshots/)',
296
+ '',
297
+ ];
298
+ // Check if package.json exists to give context about project state
299
+ const hasPackageJson = fs.existsSync(path.join(codeyamRoot, 'package.json'));
300
+ if (!hasPackageJson) {
301
+ lines.push('## Status');
302
+ lines.push('- **Empty project** — no package.json found. Ask the user what they want to build.');
303
+ lines.push('');
304
+ }
305
+ fs.writeFileSync(contextPath, lines.join('\n'), 'utf8');
306
+ return true;
307
+ }
308
+ catch (error) {
309
+ console.error('[terminalServer] Failed to write editor-mode-context.md:', error);
310
+ return false;
311
+ }
312
+ }
313
+ /**
314
+ * Attach a WebSocket server at /ws/terminal to an existing HTTP server.
315
+ * Each WS connection spawns a PTY running the user's shell, then auto-starts `claude`.
316
+ *
317
+ * Features:
318
+ * - Ping/pong keepalive (30s interval) to detect dead connections
319
+ * - PTY detach/reattach: on WS close the PTY survives for 60s, allowing the client
320
+ * to reconnect with ?reconnectId=<sessionId> and reattach to the same PTY
321
+ * - Session IDs sent to client on connection for reconnect tracking
322
+ */
323
+ export function attachTerminalServer(httpServer) {
324
+ const wss = new WebSocketServer({ server: httpServer, path: '/ws/terminal' });
325
+ // --- Ping/pong keepalive ---
326
+ // The browser's native WebSocket automatically responds to ping frames with pong.
327
+ if (pingInterval)
328
+ clearInterval(pingInterval);
329
+ pingInterval = setInterval(() => {
330
+ for (const session of sessions) {
331
+ if (!session.isAlive) {
332
+ // Didn't respond to last ping — terminate
333
+ console.log(`[terminalServer] Session ${session.sessionId} ping timeout, terminating`);
334
+ session.ws.terminate();
335
+ continue;
336
+ }
337
+ session.isAlive = false;
338
+ session.ws.ping();
339
+ }
340
+ }, PING_INTERVAL_MS);
341
+ globalThis.__codeyamPingInterval = pingInterval;
342
+ // Subscribe to mock state events and broadcast to all terminal clients
343
+ mockStateEventEmitter.on('event', (event) => {
344
+ if (event.type === 'data-mutation-forwarded') {
345
+ broadcastDataMutationForwarded(event.method, event.pathname);
346
+ }
347
+ });
348
+ wss.on('connection', (ws, req) => {
349
+ // Parse entity context from query params
350
+ const url = new URL(req.url || '', `http://${req.headers.host}`);
351
+ const entityName = url.searchParams.get('entityName') || '';
352
+ const entityType = url.searchParams.get('entityType') || '';
353
+ const entitySha = url.searchParams.get('entitySha') || '';
354
+ const entityFilePath = url.searchParams.get('entityFilePath') || '';
355
+ const scenarioName = url.searchParams.get('scenarioName') || '';
356
+ const scenarioDescription = url.searchParams.get('scenarioDescription') || '';
357
+ const analysisId = url.searchParams.get('analysisId') || '';
358
+ const projectSlug = url.searchParams.get('projectSlug') || '';
359
+ const editorMode = url.searchParams.get('editorMode') === 'true';
360
+ const reconnectId = url.searchParams.get('reconnectId') || '';
361
+ const claudeStartMode = url.searchParams.get('claudeStartMode') || '';
362
+ const claudeSessionId = url.searchParams.get('claudeSessionId') || '';
363
+ // --- Reconnection: reattach to a detached PTY ---
364
+ if (reconnectId && detachedPtys.has(reconnectId)) {
365
+ const detached = detachedPtys.get(reconnectId);
366
+ clearTimeout(detached.graceTimer);
367
+ detachedPtys.delete(reconnectId);
368
+ console.log(`[terminalServer] Reattaching session ${reconnectId}`);
369
+ const session = {
370
+ ws,
371
+ ptyProcess: detached.ptyProcess,
372
+ sessionId: detached.sessionId,
373
+ isAlive: true,
374
+ };
375
+ sessions.add(session);
376
+ // Send session ID so client can track it
377
+ ws.send(JSON.stringify({ type: 'session-id', sessionId: session.sessionId }));
378
+ // Send buffered output so client catches up
379
+ if (detached.outputBuffer) {
380
+ ws.send(JSON.stringify({ type: 'output', data: detached.outputBuffer }));
381
+ }
382
+ // Re-wire PTY output -> new WebSocket
383
+ // node-pty's onData returns a disposable; the old listener was still attached
384
+ // and was buffering output into detached.outputBuffer. We need to replace it.
385
+ // Unfortunately node-pty doesn't expose removeListener, so we use a closure flag.
386
+ let detachedFlag = false;
387
+ const reconnectPort = process.env.CODEYAM_PORT || '3111';
388
+ const reconnectTransformMarkers = createMarkerTransformer(reconnectPort);
389
+ const reconnectIdleDetector = new IdleDetector({
390
+ onIdle: () => {
391
+ if (ws.readyState === WebSocket.OPEN) {
392
+ ws.send(JSON.stringify({ type: 'claude-idle' }));
393
+ }
394
+ },
395
+ onActive: () => {
396
+ if (ws.readyState === WebSocket.OPEN) {
397
+ ws.send(JSON.stringify({ type: 'claude-active' }));
398
+ }
399
+ },
400
+ });
401
+ detached.ptyProcess.onData((data) => {
402
+ if (detachedFlag)
403
+ return; // Superseded by a newer listener
404
+ if (ws.readyState === WebSocket.OPEN) {
405
+ if (!detached.hasClearedScreen &&
406
+ detached.hasContext &&
407
+ data.includes('╭')) {
408
+ detached.hasClearedScreen = true;
409
+ ws.send(JSON.stringify({ type: 'output', data: '\x1b[2J\x1b[H' }));
410
+ }
411
+ const transformed = reconnectTransformMarkers(data);
412
+ if (transformed.length > 0) {
413
+ ws.send(JSON.stringify({ type: 'output', data: transformed }));
414
+ }
415
+ reconnectIdleDetector.onPtyOutput(data.length);
416
+ }
417
+ });
418
+ detached.ptyProcess.onExit(() => {
419
+ reconnectIdleDetector.dispose();
420
+ sessions.delete(session);
421
+ if (ws.readyState === WebSocket.OPEN) {
422
+ ws.close();
423
+ }
424
+ });
425
+ // WebSocket messages -> PTY
426
+ ws.on('message', (raw) => {
427
+ try {
428
+ const msg = JSON.parse(raw.toString());
429
+ if (msg.type === 'input') {
430
+ reconnectIdleDetector.onUserInput();
431
+ detached.ptyProcess.write(msg.data);
432
+ }
433
+ else if (msg.type === 'resize' && msg.cols && msg.rows) {
434
+ detached.ptyProcess.resize(msg.cols, msg.rows);
435
+ }
436
+ }
437
+ catch {
438
+ detached.ptyProcess.write(raw.toString());
439
+ }
440
+ });
441
+ ws.on('pong', () => {
442
+ session.isAlive = true;
443
+ });
444
+ ws.on('close', () => {
445
+ detachedFlag = true;
446
+ detachSession(session, detached.hasContext, detached.hasClearedScreen);
447
+ });
448
+ return;
449
+ }
450
+ // --- New connection: spawn a fresh PTY ---
451
+ const shell = process.env.SHELL || '/bin/zsh';
452
+ const cwd = process.env.CODEYAM_ROOT_PATH || process.cwd();
453
+ // Verify cwd exists, fall back to HOME
454
+ const safeCwd = fs.existsSync(cwd) ? cwd : process.env.HOME || '/tmp';
455
+ // Spawn PTY with a clean env (no giant JSON blobs from CODEYAM_PROJECT etc.)
456
+ let ptyProcess;
457
+ try {
458
+ ptyProcess = pty.spawn(shell, ['-l'], {
459
+ name: 'xterm-256color',
460
+ cols: 120,
461
+ rows: 30,
462
+ cwd: safeCwd,
463
+ env: buildPtyEnv({ editorMode }),
464
+ });
465
+ }
466
+ catch (error) {
467
+ console.error('[terminalServer] Failed to spawn PTY:', {
468
+ shell,
469
+ cwd: safeCwd,
470
+ error,
471
+ });
472
+ ws.send(JSON.stringify({
473
+ type: 'output',
474
+ data: `\r\nFailed to start terminal: ${error.message}\r\n`,
475
+ }));
476
+ ws.close();
477
+ return;
478
+ }
479
+ const sessionId = crypto.randomUUID();
480
+ const session = {
481
+ ws,
482
+ ptyProcess,
483
+ sessionId,
484
+ isAlive: true,
485
+ };
486
+ sessions.add(session);
487
+ // Send session ID so client can use it for reconnection
488
+ ws.send(JSON.stringify({ type: 'session-id', sessionId }));
489
+ // Write context file for the appropriate skill (dev-mode or editor)
490
+ const hasContext = editorMode
491
+ ? writeEditorModeContext({ projectSlug })
492
+ : writeDevModeContext({
493
+ entityName,
494
+ entityType,
495
+ entitySha,
496
+ entityFilePath,
497
+ scenarioName,
498
+ scenarioDescription,
499
+ analysisId,
500
+ projectSlug,
501
+ });
502
+ let hasClearedScreen = false;
503
+ // Safety timeout: stop suppressing output after 5s even if ╭ never arrives.
504
+ // Prevents "Starting Claude..." hanging forever if the banner format changes.
505
+ if (hasContext) {
506
+ setTimeout(() => {
507
+ if (!hasClearedScreen) {
508
+ hasClearedScreen = true;
509
+ console.log('[terminalServer] Suppression timeout — showing output');
510
+ }
511
+ }, 5000);
512
+ }
513
+ const idleDetector = new IdleDetector({
514
+ onIdle: () => {
515
+ if (ws.readyState === WebSocket.OPEN) {
516
+ ws.send(JSON.stringify({ type: 'claude-idle' }));
517
+ }
518
+ },
519
+ onActive: () => {
520
+ if (ws.readyState === WebSocket.OPEN) {
521
+ ws.send(JSON.stringify({ type: 'claude-active' }));
522
+ }
523
+ },
524
+ });
525
+ // PTY output -> WebSocket
526
+ const serverPort = process.env.CODEYAM_PORT || '3111';
527
+ // Stateful transformer that buffers partial {{scenario:...}} markers
528
+ // across PTY chunks so they don't appear as raw text.
529
+ const transformMarkers = createMarkerTransformer(serverPort);
530
+ ptyProcess.onData((data) => {
531
+ if (ws.readyState === WebSocket.OPEN) {
532
+ // When Claude Code starts (indicated by its box-drawing welcome banner),
533
+ // clear the screen to hide the raw shell command.
534
+ if (!hasClearedScreen && hasContext && data.includes('╭')) {
535
+ hasClearedScreen = true;
536
+ ws.send(JSON.stringify({ type: 'output', data: '\x1b[2J\x1b[H' }));
537
+ }
538
+ // Suppress output before the screen clear so the user doesn't see
539
+ // the raw `claude '/codeyam-editor'` command being echoed by the shell.
540
+ if (!hasClearedScreen && hasContext) {
541
+ // Skip sending to client AND idle detection — Claude hasn't started
542
+ // yet, so any output gap is just startup latency, not Claude waiting
543
+ // for input. Without this, the idle detector fires a false positive
544
+ // during the startup gap and the user gets a spurious notification.
545
+ }
546
+ else {
547
+ // Transform {{scenario:Name:ID}} markers into OSC 8 clickable hyperlinks.
548
+ // Uses stateful buffering to handle markers split across PTY chunks.
549
+ const transformed = transformMarkers(data);
550
+ if (transformed.length > 0) {
551
+ ws.send(JSON.stringify({ type: 'output', data: transformed }));
552
+ }
553
+ idleDetector.onPtyOutput(data.length);
554
+ }
555
+ }
556
+ });
557
+ ptyProcess.onExit(() => {
558
+ idleDetector.dispose();
559
+ sessions.delete(session);
560
+ // Also clean up from detachedPtys if it was detached
561
+ if (detachedPtys.has(sessionId)) {
562
+ clearTimeout(detachedPtys.get(sessionId).graceTimer);
563
+ detachedPtys.delete(sessionId);
564
+ }
565
+ if (ws.readyState === WebSocket.OPEN) {
566
+ ws.close();
567
+ }
568
+ });
569
+ // WebSocket messages -> PTY
570
+ ws.on('message', (raw) => {
571
+ try {
572
+ const msg = JSON.parse(raw.toString());
573
+ if (msg.type === 'input') {
574
+ idleDetector.onUserInput();
575
+ ptyProcess.write(msg.data);
576
+ }
577
+ else if (msg.type === 'resize' && msg.cols && msg.rows) {
578
+ ptyProcess.resize(msg.cols, msg.rows);
579
+ }
580
+ }
581
+ catch {
582
+ // Non-JSON message, treat as raw input
583
+ ptyProcess.write(raw.toString());
584
+ }
585
+ });
586
+ ws.on('pong', () => {
587
+ session.isAlive = true;
588
+ });
589
+ ws.on('close', () => {
590
+ detachSession(session, hasContext, hasClearedScreen);
591
+ });
592
+ // Show a loading indicator while Claude Code starts up.
593
+ // PTY output is suppressed until Claude's welcome banner (╭) appears
594
+ // and triggers a screen clear, so the user never sees the raw command.
595
+ if (hasContext) {
596
+ ws.send(JSON.stringify({
597
+ type: 'output',
598
+ data: '\x1b[2J\x1b[H\r\n\x1b[90m Starting Claude...\x1b[0m\r\n',
599
+ }));
600
+ }
601
+ // Start Claude Code with the appropriate skill.
602
+ // Using a skill avoids shell escaping issues and multi-line paste detection.
603
+ //
604
+ // Session recovery modes (editor only):
605
+ // resume + sessionId → claude --resume <uuid> (resumes exact conversation)
606
+ // resume, no sessionId → claude --continue (fallback for pre-existing sessions)
607
+ // fresh → generate UUID, write to .codeyam/claude-session-id.txt,
608
+ // launch claude --session-id <uuid> '/codeyam-editor'
609
+ //
610
+ // The UUID is generated HERE (not in printStep1) so it's available before
611
+ // Claude launches. printStep1 runs inside the session — too late.
612
+ setTimeout(() => {
613
+ if (editorMode && hasContext) {
614
+ if (claudeStartMode === 'resume' && claudeSessionId) {
615
+ ptyProcess.write(`claude --resume '${claudeSessionId}' 'The session was interrupted. Please continue where you left off.'\r`);
616
+ }
617
+ else if (claudeStartMode === 'resume') {
618
+ // No session ID available — fall back to most recent session
619
+ ptyProcess.write("claude --continue 'The session was interrupted. Please continue where you left off.'\r");
620
+ }
621
+ else {
622
+ // Fresh session: generate a trackable UUID
623
+ const newSessionId = crypto.randomUUID();
624
+ const sessionIdPath = path.join(cwd, '.codeyam', 'claude-session-id.txt');
625
+ try {
626
+ fs.mkdirSync(path.dirname(sessionIdPath), { recursive: true });
627
+ fs.writeFileSync(sessionIdPath, newSessionId, 'utf8');
628
+ }
629
+ catch (err) {
630
+ console.error('[terminalServer] Failed to write claude-session-id.txt:', err);
631
+ }
632
+ ptyProcess.write(`claude --session-id '${newSessionId}' '/codeyam-editor'\r`);
633
+ }
634
+ }
635
+ else if (hasContext) {
636
+ ptyProcess.write("claude '/codeyam-dev-mode'\r");
637
+ }
638
+ else {
639
+ ptyProcess.write('claude\r');
640
+ }
641
+ }, 500);
642
+ });
643
+ console.log('[terminalServer] WebSocket terminal server attached at /ws/terminal');
644
+ }
645
+ /**
646
+ * Detach a session's PTY instead of killing it, giving the client time to reconnect.
647
+ * The PTY is moved to `detachedPtys` with a grace timer; if the client reconnects
648
+ * within DETACH_GRACE_MS, the PTY is reattached. Otherwise it's killed.
649
+ */
650
+ function detachSession(session, hasContext = false, hasClearedScreen = false) {
651
+ sessions.delete(session);
652
+ const { sessionId, ptyProcess } = session;
653
+ // If already detached (shouldn't happen), skip
654
+ if (detachedPtys.has(sessionId))
655
+ return;
656
+ let outputBuffer = '';
657
+ // Buffer PTY output during detachment so the client can catch up on reconnect
658
+ ptyProcess.onData((data) => {
659
+ outputBuffer += data;
660
+ // Cap buffer size
661
+ if (outputBuffer.length > OUTPUT_BUFFER_MAX) {
662
+ outputBuffer = outputBuffer.slice(-OUTPUT_BUFFER_MAX);
663
+ }
664
+ });
665
+ const graceTimer = setTimeout(() => {
666
+ console.log(`[terminalServer] Grace period expired for session ${sessionId}, killing PTY`);
667
+ detachedPtys.delete(sessionId);
668
+ try {
669
+ ptyProcess.kill();
670
+ }
671
+ catch {
672
+ /* already dead */
673
+ }
674
+ }, DETACH_GRACE_MS);
675
+ detachedPtys.set(sessionId, {
676
+ ptyProcess,
677
+ sessionId,
678
+ graceTimer,
679
+ outputBuffer,
680
+ hasContext,
681
+ hasClearedScreen,
682
+ });
683
+ console.log(`[terminalServer] Session ${sessionId} detached, PTY kept alive for ${DETACH_GRACE_MS / 1000}s`);
684
+ }
685
+ /**
686
+ * Send a refresh-preview message to all connected terminal WebSocket clients.
687
+ * The Terminal component relays this to the parent page to reload the iframe.
688
+ */
689
+ export function broadcastPreviewRefresh(path, scenarioId) {
690
+ const msg = JSON.stringify({
691
+ type: 'refresh-preview',
692
+ ...(path && { path }),
693
+ ...(scenarioId && { scenarioId }),
694
+ });
695
+ let count = 0;
696
+ for (const session of sessions) {
697
+ try {
698
+ if (session.ws.readyState === WebSocket.OPEN) {
699
+ session.ws.send(msg);
700
+ count++;
701
+ }
702
+ }
703
+ catch {
704
+ // Ignore send errors
705
+ }
706
+ }
707
+ return count;
708
+ }
709
+ /**
710
+ * Notify all connected terminal WebSocket clients that a data mutation
711
+ * was forwarded to the real dev server (seed-based scenario).
712
+ * The Terminal component relays this to editor.tsx to show a save banner.
713
+ */
714
+ export function broadcastDataMutationForwarded(method, pathname) {
715
+ const msg = JSON.stringify({
716
+ type: 'data-mutation-forwarded',
717
+ method,
718
+ pathname,
719
+ });
720
+ let count = 0;
721
+ for (const session of sessions) {
722
+ try {
723
+ if (session.ws.readyState === WebSocket.OPEN) {
724
+ session.ws.send(msg);
725
+ count++;
726
+ }
727
+ }
728
+ catch {
729
+ // Ignore send errors
730
+ }
731
+ }
732
+ return count;
733
+ }
734
+ /**
735
+ * Show the results panel below the terminal in the Build tab.
736
+ * Triggered by Claude at end of step 12.
737
+ */
738
+ export function broadcastShowResults() {
739
+ const msg = JSON.stringify({ type: 'show-results' });
740
+ let count = 0;
741
+ for (const session of sessions) {
742
+ try {
743
+ if (session.ws.readyState === WebSocket.OPEN) {
744
+ session.ws.send(msg);
745
+ count++;
746
+ }
747
+ }
748
+ catch {
749
+ // Ignore send errors
750
+ }
751
+ }
752
+ return count;
753
+ }
754
+ /**
755
+ * Hide the results panel (e.g. after Save & Commit).
756
+ */
757
+ export function broadcastHideResults() {
758
+ const msg = JSON.stringify({ type: 'hide-results' });
759
+ let count = 0;
760
+ for (const session of sessions) {
761
+ try {
762
+ if (session.ws.readyState === WebSocket.OPEN) {
763
+ session.ws.send(msg);
764
+ count++;
765
+ }
766
+ }
767
+ catch {
768
+ // Ignore send errors
769
+ }
770
+ }
771
+ return count;
772
+ }
773
+ /**
774
+ * Send a set-viewport message to all connected terminal WebSocket clients.
775
+ * The Terminal component relays this to the parent page to update the preview viewport.
776
+ */
777
+ export function broadcastSetViewport(viewport) {
778
+ const msg = JSON.stringify({ type: 'set-viewport', ...viewport });
779
+ let count = 0;
780
+ for (const session of sessions) {
781
+ try {
782
+ if (session.ws.readyState === WebSocket.OPEN) {
783
+ session.ws.send(msg);
784
+ count++;
785
+ }
786
+ }
787
+ catch {
788
+ // Ignore send errors
789
+ }
790
+ }
791
+ return count;
792
+ }
793
+ /**
794
+ * Kill all active PTY sessions and detached PTYs. Call during shutdown.
795
+ */
796
+ export function cleanupAllTerminalSessions() {
797
+ // Clear ping interval
798
+ if (pingInterval) {
799
+ clearInterval(pingInterval);
800
+ pingInterval = null;
801
+ globalThis.__codeyamPingInterval = null;
802
+ }
803
+ // Clean up active sessions
804
+ for (const session of Array.from(sessions)) {
805
+ try {
806
+ session.ptyProcess.kill();
807
+ }
808
+ catch {
809
+ // Already dead
810
+ }
811
+ try {
812
+ session.ws.close();
813
+ }
814
+ catch {
815
+ // Already closed
816
+ }
817
+ }
818
+ sessions.clear();
819
+ // Clean up detached PTYs
820
+ for (const [, detached] of detachedPtys) {
821
+ clearTimeout(detached.graceTimer);
822
+ try {
823
+ detached.ptyProcess.kill();
824
+ }
825
+ catch {
826
+ // Already dead
827
+ }
828
+ }
829
+ detachedPtys.clear();
830
+ }
831
+ //# sourceMappingURL=terminalServer.js.map