@codeyam/codeyam-cli 0.1.0-staging.8df382d → 0.1.0-staging.a890816

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 (331) hide show
  1. package/analyzer-template/.build-info.json +7 -7
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +34 -3
  4. package/analyzer-template/packages/ai/src/lib/completionCall.ts +14 -2
  5. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +27 -0
  6. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.ts +62 -0
  7. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +78 -2
  8. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +6 -0
  9. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +9 -1
  10. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +0 -6
  11. package/analyzer-template/packages/analyze/src/lib/files/analyze/findOrCreateEntity.ts +12 -0
  12. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +65 -28
  13. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +83 -0
  14. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +23 -4
  15. package/analyzer-template/packages/database/index.ts +1 -0
  16. package/analyzer-template/packages/database/src/lib/kysely/db.ts +8 -0
  17. package/analyzer-template/packages/database/src/lib/kysely/tables/editorScenariosTable.ts +62 -0
  18. package/analyzer-template/packages/database/src/lib/loadCommits.ts +31 -20
  19. package/analyzer-template/packages/database/src/lib/loadReadyToBeCapturedAnalyses.ts +0 -5
  20. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +151 -135
  21. package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatus.ts +58 -42
  22. package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.ts +81 -65
  23. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.ts +29 -1
  24. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.ts +33 -5
  25. package/analyzer-template/packages/github/dist/database/index.d.ts +1 -0
  26. package/analyzer-template/packages/github/dist/database/index.d.ts.map +1 -1
  27. package/analyzer-template/packages/github/dist/database/index.js +1 -0
  28. package/analyzer-template/packages/github/dist/database/index.js.map +1 -1
  29. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  30. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  31. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +5 -0
  32. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  33. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts +20 -0
  34. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts.map +1 -0
  35. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js +45 -0
  36. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
  37. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts +5 -0
  38. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts.map +1 -1
  39. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  40. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +23 -13
  41. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  42. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.d.ts.map +1 -1
  43. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
  44. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  45. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  46. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +100 -89
  47. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  48. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.d.ts.map +1 -1
  49. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js +41 -30
  50. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
  51. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.d.ts.map +1 -1
  52. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
  53. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
  54. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.d.ts.map +1 -1
  55. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
  56. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
  57. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.d.ts.map +1 -1
  58. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
  59. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  60. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +1 -0
  61. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  62. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts +10 -0
  63. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts.map +1 -1
  64. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +1 -0
  65. package/analyzer-template/packages/types/src/types/Scenario.ts +10 -0
  66. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +1 -0
  67. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  68. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts +10 -0
  69. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts.map +1 -1
  70. package/analyzer-template/playwright/captureFromUrl.ts +89 -82
  71. package/analyzer-template/project/constructMockCode.ts +136 -43
  72. package/analyzer-template/project/reconcileMockDataKeys.ts +19 -14
  73. package/analyzer-template/project/start.ts +3 -0
  74. package/analyzer-template/project/startScenarioCapture.ts +9 -0
  75. package/analyzer-template/project/writeClientLogRoute.ts +125 -0
  76. package/analyzer-template/project/writeMockDataTsx.ts +17 -0
  77. package/analyzer-template/project/writeScenarioComponents.ts +36 -7
  78. package/analyzer-template/tsconfig.json +13 -1
  79. package/background/src/lib/virtualized/project/constructMockCode.js +115 -34
  80. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  81. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +17 -11
  82. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
  83. package/background/src/lib/virtualized/project/start.js +2 -0
  84. package/background/src/lib/virtualized/project/start.js.map +1 -1
  85. package/background/src/lib/virtualized/project/startScenarioCapture.js +5 -0
  86. package/background/src/lib/virtualized/project/startScenarioCapture.js.map +1 -1
  87. package/background/src/lib/virtualized/project/writeClientLogRoute.js +110 -0
  88. package/background/src/lib/virtualized/project/writeClientLogRoute.js.map +1 -0
  89. package/background/src/lib/virtualized/project/writeMockDataTsx.js +12 -0
  90. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  91. package/background/src/lib/virtualized/project/writeScenarioComponents.js +29 -7
  92. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  93. package/codeyam-cli/scripts/apply-setup.js +208 -11
  94. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  95. package/codeyam-cli/src/cli.js +2 -0
  96. package/codeyam-cli/src/cli.js.map +1 -1
  97. package/codeyam-cli/src/commands/analyze.js +17 -7
  98. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  99. package/codeyam-cli/src/commands/default.js +58 -3
  100. package/codeyam-cli/src/commands/default.js.map +1 -1
  101. package/codeyam-cli/src/commands/editor.js +1037 -0
  102. package/codeyam-cli/src/commands/editor.js.map +1 -0
  103. package/codeyam-cli/src/commands/init.js +34 -10
  104. package/codeyam-cli/src/commands/init.js.map +1 -1
  105. package/codeyam-cli/src/commands/memory.js +26 -2
  106. package/codeyam-cli/src/commands/memory.js.map +1 -1
  107. package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js +9 -0
  108. package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js.map +1 -1
  109. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +26 -0
  110. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  111. package/codeyam-cli/src/utils/backgroundServer.js +19 -3
  112. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  113. package/codeyam-cli/src/utils/devModeEvents.js +40 -0
  114. package/codeyam-cli/src/utils/devModeEvents.js.map +1 -0
  115. package/codeyam-cli/src/utils/fileMetadata.js +5 -0
  116. package/codeyam-cli/src/utils/fileMetadata.js.map +1 -1
  117. package/codeyam-cli/src/utils/fileWatcher.js +25 -9
  118. package/codeyam-cli/src/utils/fileWatcher.js.map +1 -1
  119. package/codeyam-cli/src/utils/git.js +52 -0
  120. package/codeyam-cli/src/utils/git.js.map +1 -1
  121. package/codeyam-cli/src/utils/install-skills.js +31 -0
  122. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  123. package/codeyam-cli/src/utils/interactiveSyncWatcher.js +126 -0
  124. package/codeyam-cli/src/utils/interactiveSyncWatcher.js.map +1 -0
  125. package/codeyam-cli/src/utils/pathIgnoring.js +19 -7
  126. package/codeyam-cli/src/utils/pathIgnoring.js.map +1 -1
  127. package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js +11 -11
  128. package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js.map +1 -1
  129. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js +22 -0
  130. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js.map +1 -1
  131. package/codeyam-cli/src/utils/queue/heartbeat.js +13 -5
  132. package/codeyam-cli/src/utils/queue/heartbeat.js.map +1 -1
  133. package/codeyam-cli/src/utils/queue/job.js +70 -1
  134. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  135. package/codeyam-cli/src/utils/queue/manager.js +7 -6
  136. package/codeyam-cli/src/utils/queue/manager.js.map +1 -1
  137. package/codeyam-cli/src/utils/serverState.js +27 -2
  138. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  139. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +45 -4
  140. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  141. package/codeyam-cli/src/utils/testRunner.js +158 -0
  142. package/codeyam-cli/src/utils/testRunner.js.map +1 -0
  143. package/codeyam-cli/src/utils/transcriptPruning.js +67 -0
  144. package/codeyam-cli/src/utils/transcriptPruning.js.map +1 -0
  145. package/codeyam-cli/src/utils/webappDetection.js +14 -2
  146. package/codeyam-cli/src/utils/webappDetection.js.map +1 -1
  147. package/codeyam-cli/src/webserver/app/lib/database.js +41 -27
  148. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  149. package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
  150. package/codeyam-cli/src/webserver/backgroundServer.js +109 -19
  151. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  152. package/codeyam-cli/src/webserver/build/client/assets/{CopyButton-CtmbP4Gl.js → CopyButton-DmJveP3T.js} +1 -1
  153. package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-DlMph_Hm.js → EntityItem-C76mRRiF.js} +1 -1
  154. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeBadge-B-0PjGOU.js → EntityTypeBadge-g3saevPb.js} +1 -1
  155. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-DN9eiJAO.js → EntityTypeIcon-CobE682z.js} +1 -1
  156. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-Bu6c6aDe.js +1 -0
  157. package/codeyam-cli/src/webserver/build/client/assets/{InteractivePreview-rE_fI2h2.js → InteractivePreview-DYFW3lDD.js} +3 -3
  158. package/codeyam-cli/src/webserver/build/client/assets/{LibraryFunctionPreview-CnatsCw2.js → LibraryFunctionPreview-DLeucoVX.js} +1 -1
  159. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-CSP6DZrh.js → LoadingDots-BU_OAEMP.js} +1 -1
  160. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-CMK8Q7yk.js → LogViewer-ceAyBX-H.js} +1 -1
  161. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-TCV_HBjy.js → ReportIssueModal-djPLI-WV.js} +1 -1
  162. package/codeyam-cli/src/webserver/build/client/assets/{SafeScreenshot-CG2uh31y.js → SafeScreenshot-BED4B6sP.js} +1 -1
  163. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-CU_TDYd8.js → ScenarioViewer-B76aig_2.js} +1 -1
  164. package/codeyam-cli/src/webserver/build/client/assets/Spinner-Bb5uFQ5V.js +34 -0
  165. package/codeyam-cli/src/webserver/build/client/assets/Terminal-CcG8YTLx.js +41 -0
  166. package/codeyam-cli/src/webserver/build/client/assets/{TruncatedFilePath-D7IoaWUW.js → TruncatedFilePath-C8OKAR5x.js} +1 -1
  167. package/codeyam-cli/src/webserver/build/client/assets/{_index-B8z7mjR-.js → _index-C96V0n15.js} +1 -1
  168. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-DZu78RI1.js → activity.(_tab)-BpKzcsJz.js} +1 -1
  169. package/codeyam-cli/src/webserver/build/client/assets/addon-fit-CUXOrorO.js +1 -0
  170. package/codeyam-cli/src/webserver/build/client/assets/addon-web-links-Duc5hnl7.js +1 -0
  171. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-D9hemwl6.js +22 -0
  172. package/codeyam-cli/src/webserver/build/client/assets/api.dev-mode-events-l0sNRNKZ.js +1 -0
  173. package/codeyam-cli/src/webserver/build/client/assets/api.editor-capture-scenario-l0sNRNKZ.js +1 -0
  174. package/codeyam-cli/src/webserver/build/client/assets/api.editor-client-errors-l0sNRNKZ.js +1 -0
  175. package/codeyam-cli/src/webserver/build/client/assets/api.editor-commit-l0sNRNKZ.js +1 -0
  176. package/codeyam-cli/src/webserver/build/client/assets/api.editor-dev-server-l0sNRNKZ.js +1 -0
  177. package/codeyam-cli/src/webserver/build/client/assets/api.editor-entity-status-l0sNRNKZ.js +1 -0
  178. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-entry-l0sNRNKZ.js +1 -0
  179. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-image._-l0sNRNKZ.js +1 -0
  180. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-l0sNRNKZ.js +1 -0
  181. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-screenshot-l0sNRNKZ.js +1 -0
  182. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-update-l0sNRNKZ.js +1 -0
  183. package/codeyam-cli/src/webserver/build/client/assets/api.editor-refresh-l0sNRNKZ.js +1 -0
  184. package/codeyam-cli/src/webserver/build/client/assets/api.editor-register-scenario-l0sNRNKZ.js +1 -0
  185. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-data-l0sNRNKZ.js +1 -0
  186. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-image._-l0sNRNKZ.js +1 -0
  187. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenarios-l0sNRNKZ.js +1 -0
  188. package/codeyam-cli/src/webserver/build/client/assets/api.editor-switch-scenario-l0sNRNKZ.js +1 -0
  189. package/codeyam-cli/src/webserver/build/client/assets/api.editor-test-results-l0sNRNKZ.js +1 -0
  190. package/codeyam-cli/src/webserver/build/client/assets/{book-open-Bp5FLkd4.js → book-open-D_nMCFmP.js} +1 -1
  191. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-DQJA9f4o.js → chevron-down-BH2h1Ea2.js} +1 -1
  192. package/codeyam-cli/src/webserver/build/client/assets/{chunk-JZWAC4HX-7VptmeIr.js → chunk-JZWAC4HX-C4pqxYJB.js} +1 -1
  193. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-B6C4LY9o.js → circle-check-DyIKORY6.js} +1 -1
  194. package/codeyam-cli/src/webserver/build/client/assets/{copy-6nzYCu0G.js → copy-NDbZjXao.js} +1 -1
  195. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-D-QUFOwe.js → createLucideIcon-CMT1jU2q.js} +1 -1
  196. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-BiM6z3Do.js +1 -0
  197. package/codeyam-cli/src/webserver/build/client/assets/editor-W_IGJ2Kd.js +7 -0
  198. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._--zvFJ4OH.js → entity._sha._-CrjR3zZW.js} +10 -10
  199. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-D6SEzMCu.js +6 -0
  200. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-C28BiQzt.js +6 -0
  201. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-p9hhkjJM.js +6 -0
  202. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-C7ysA4Jq.js → entity._sha_.edit._scenarioId-BMvVHNXU.js} +2 -2
  203. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-CU6EUArK.js → entry.client-DTvKq3TY.js} +1 -1
  204. package/codeyam-cli/src/webserver/build/client/assets/{fileTableUtils-EWpfFU4X.js → fileTableUtils-cPo8LiG3.js} +1 -1
  205. package/codeyam-cli/src/webserver/build/client/assets/{files-CrxAoWIL.js → files-DO4CZ16O.js} +1 -1
  206. package/codeyam-cli/src/webserver/build/client/assets/{git-BldHtKeW.js → git-CFCTYk9I.js} +1 -1
  207. package/codeyam-cli/src/webserver/build/client/assets/globals-BZB_H1w2.css +1 -0
  208. package/codeyam-cli/src/webserver/build/client/assets/{index-7-1FmlHo.js → index-10oVnAAH.js} +1 -1
  209. package/codeyam-cli/src/webserver/build/client/assets/{index-DuYcwYp_.js → index-BcvgDzbZ.js} +1 -1
  210. package/codeyam-cli/src/webserver/build/client/assets/{labs-CPPVOSWB.js → labs-Zk7ryIM1.js} +1 -1
  211. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-BnDcD54R.js → loader-circle-BAXYRVEO.js} +1 -1
  212. package/codeyam-cli/src/webserver/build/client/assets/manifest-8daa4147.js +1 -0
  213. package/codeyam-cli/src/webserver/build/client/assets/{memory-CfpYxpNu.js → memory-FweZHj5U.js} +28 -28
  214. package/codeyam-cli/src/webserver/build/client/assets/{pause-DhQX2g22.js → pause-DTAcYxBt.js} +1 -1
  215. package/codeyam-cli/src/webserver/build/client/assets/root-DiRdBreB.js +67 -0
  216. package/codeyam-cli/src/webserver/build/client/assets/{search-DborVoKD.js → search-fKo7v0Zo.js} +1 -1
  217. package/codeyam-cli/src/webserver/build/client/assets/settings-DfuTtcJP.js +1 -0
  218. package/codeyam-cli/src/webserver/build/client/assets/{simulations-BtrtCYJg.js → simulations-B3aOzpCZ.js} +1 -1
  219. package/codeyam-cli/src/webserver/build/client/assets/{terminal-Bs4NC-VZ.js → terminal-BG4heKCG.js} +1 -1
  220. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-DTf3Jojp.js → triangle-alert-DtSmdtM4.js} +1 -1
  221. package/codeyam-cli/src/webserver/build/client/assets/{useCustomSizes-D_bDZyDU.js → useCustomSizes-ByhSyh0W.js} +1 -1
  222. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-C14nCb1q.js +2 -0
  223. package/codeyam-cli/src/webserver/build/client/assets/{useReportContext-BsQb6rFd.js → useReportContext-O-jkvSPx.js} +1 -1
  224. package/codeyam-cli/src/webserver/build/client/assets/{useToast-BOur3mUv.js → useToast-9FIWuYfK.js} +1 -1
  225. package/codeyam-cli/src/webserver/build/client/assets/xterm-DMSzMhqy.js +9 -0
  226. package/codeyam-cli/src/webserver/build/server/assets/index-BzAbACSx.js +1 -0
  227. package/codeyam-cli/src/webserver/build/server/assets/server-build-OdUocH6P.js +362 -0
  228. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  229. package/codeyam-cli/src/webserver/build-info.json +5 -5
  230. package/codeyam-cli/src/webserver/devServer.js +39 -5
  231. package/codeyam-cli/src/webserver/devServer.js.map +1 -1
  232. package/codeyam-cli/src/webserver/editorProxy.js +272 -0
  233. package/codeyam-cli/src/webserver/editorProxy.js.map +1 -0
  234. package/codeyam-cli/src/webserver/scripts/journalCapture.ts +140 -0
  235. package/codeyam-cli/src/webserver/server.js +177 -1
  236. package/codeyam-cli/src/webserver/server.js.map +1 -1
  237. package/codeyam-cli/src/webserver/terminalServer.js +753 -0
  238. package/codeyam-cli/src/webserver/terminalServer.js.map +1 -0
  239. package/codeyam-cli/templates/codeyam-dev-mode.md +237 -0
  240. package/codeyam-cli/templates/codeyam-editor-claude.md +68 -0
  241. package/codeyam-cli/templates/codeyam-editor.md +68 -0
  242. package/codeyam-cli/templates/editor-step-hook.py +145 -0
  243. package/codeyam-cli/templates/isolation-route/next-app.tsx.template +80 -0
  244. package/codeyam-cli/templates/isolation-route/next-pages.tsx.template +79 -0
  245. package/codeyam-cli/templates/isolation-route/vite-react.tsx.template +78 -0
  246. package/codeyam-cli/templates/msw/browser-setup.ts.template +47 -0
  247. package/codeyam-cli/templates/msw/handler-router.ts.template +47 -0
  248. package/codeyam-cli/templates/msw/server-setup.ts.template +52 -0
  249. package/codeyam-cli/templates/nextjs-prisma-sqlite/PRISMA_SETUP.md +84 -0
  250. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/api/todos/route.ts +17 -0
  251. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/globals.css +26 -0
  252. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/layout.tsx +34 -0
  253. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/lib/prisma.ts +19 -0
  254. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/page.tsx +10 -0
  255. package/codeyam-cli/templates/nextjs-prisma-sqlite/eslint.config.mjs +11 -0
  256. package/codeyam-cli/templates/nextjs-prisma-sqlite/gitignore +43 -0
  257. package/codeyam-cli/templates/nextjs-prisma-sqlite/next.config.ts +14 -0
  258. package/codeyam-cli/templates/nextjs-prisma-sqlite/package.json +35 -0
  259. package/codeyam-cli/templates/nextjs-prisma-sqlite/postcss.config.mjs +7 -0
  260. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/schema.prisma +27 -0
  261. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/seed.ts +37 -0
  262. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma.config.ts +12 -0
  263. package/codeyam-cli/templates/nextjs-prisma-sqlite/tsconfig.json +34 -0
  264. package/codeyam-cli/templates/prompts/conversation-guidance.txt +12 -0
  265. package/codeyam-cli/templates/prompts/conversation-prompt.txt +3 -3
  266. package/codeyam-cli/templates/prompts/interruption-prompt.txt +3 -3
  267. package/codeyam-cli/templates/prompts/stale-rules-prompt.txt +3 -3
  268. package/codeyam-cli/templates/rule-notification-hook.py +44 -17
  269. package/codeyam-cli/templates/rule-reflection-hook.py +24 -4
  270. package/codeyam-cli/templates/rules-instructions.md +4 -3
  271. package/package.json +4 -2
  272. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +22 -4
  273. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  274. package/packages/ai/src/lib/completionCall.js +10 -2
  275. package/packages/ai/src/lib/completionCall.js.map +1 -1
  276. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +21 -0
  277. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  278. package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js +54 -0
  279. package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js.map +1 -0
  280. package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js +34 -0
  281. package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js.map +1 -0
  282. package/packages/ai/src/lib/generateEntityScenarioData.js +57 -2
  283. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  284. package/packages/analyze/src/lib/ProjectAnalyzer.js +3 -0
  285. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  286. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +8 -1
  287. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  288. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +0 -5
  289. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  290. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js +9 -0
  291. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js.map +1 -1
  292. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +54 -27
  293. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -1
  294. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +65 -0
  295. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  296. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +18 -4
  297. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  298. package/packages/database/index.js +1 -0
  299. package/packages/database/index.js.map +1 -1
  300. package/packages/database/src/lib/kysely/db.js +5 -0
  301. package/packages/database/src/lib/kysely/db.js.map +1 -1
  302. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js +45 -0
  303. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
  304. package/packages/database/src/lib/loadCommits.js +23 -13
  305. package/packages/database/src/lib/loadCommits.js.map +1 -1
  306. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
  307. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  308. package/packages/database/src/lib/updateCommitMetadata.js +100 -89
  309. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  310. package/packages/database/src/lib/updateFreshAnalysisStatus.js +41 -30
  311. package/packages/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
  312. package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
  313. package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
  314. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
  315. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
  316. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
  317. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  318. package/codeyam-cli/src/webserver/app/routes/api.agent-transcripts.js +0 -486
  319. package/codeyam-cli/src/webserver/app/routes/api.agent-transcripts.js.map +0 -1
  320. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-C1rIyZdV.js +0 -34
  321. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-DxCa1oBt.js +0 -23
  322. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-DmzSmblj.js +0 -1
  323. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-DVTcUnur.js +0 -6
  324. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-BVgNO76F.js +0 -6
  325. package/codeyam-cli/src/webserver/build/client/assets/globals-B4MPiL7S.css +0 -1
  326. package/codeyam-cli/src/webserver/build/client/assets/manifest-c1fc3656.js +0 -1
  327. package/codeyam-cli/src/webserver/build/client/assets/root-CAAbm4U5.js +0 -62
  328. package/codeyam-cli/src/webserver/build/client/assets/settings-BpLDWmGh.js +0 -1
  329. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-DZp6rrQD.js +0 -2
  330. package/codeyam-cli/src/webserver/build/server/assets/index-B8A_aaGG.js +0 -1
  331. package/codeyam-cli/src/webserver/build/server/assets/server-build-69rRZnZo.js +0 -286
@@ -0,0 +1,753 @@
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
+ // Use globalThis so the sessions Set is shared across module instances.
8
+ // In Vite dev mode, this file is loaded twice: once by the Vite plugin (Node.js native)
9
+ // and once by the SSR context (ssrLoadModule). Without globalThis, each instance
10
+ // gets its own empty Set — so broadcastPreviewRefresh() called from the SSR instance
11
+ // (via the /api/dev-mode-refresh endpoint) would broadcast to 0 sessions.
12
+ const sessions = ((_a = globalThis).__codeyamTerminalSessions ?? (_a.__codeyamTerminalSessions = new Set()));
13
+ // Detached PTYs waiting for reconnection (keyed by sessionId).
14
+ // When a WebSocket drops, the PTY is moved here with a grace timer
15
+ // instead of being killed immediately, allowing the client to reconnect.
16
+ const detachedPtys = ((_b = globalThis).__codeyamDetachedPtys ?? (_b.__codeyamDetachedPtys = new Map()));
17
+ const PING_INTERVAL_MS = 30000;
18
+ const DETACH_GRACE_MS = 60000;
19
+ const OUTPUT_BUFFER_MAX = 8 * 1024; // 8KB
20
+ const ANSI_ESCAPE_RE = /\x1b\[[0-9;]*[a-zA-Z]/g;
21
+ /**
22
+ * Build a position map from ANSI-stripped indices to original indices.
23
+ * posMap[strippedIndex] = originalIndex, skipping over ANSI sequences.
24
+ */
25
+ function buildAnsiPositionMap(data, stripped) {
26
+ const posMap = [];
27
+ for (let di = 0, si = 0; di < data.length; di++) {
28
+ if (data[di] === '\x1b') {
29
+ const seqMatch = data.slice(di).match(/^\x1b\[[0-9;]*[a-zA-Z]/);
30
+ if (seqMatch) {
31
+ di += seqMatch[0].length - 1; // -1 because loop increments
32
+ continue;
33
+ }
34
+ }
35
+ posMap[si] = di;
36
+ si++;
37
+ }
38
+ posMap[stripped.length] = data.length; // sentinel for end-of-string markers
39
+ return posMap;
40
+ }
41
+ /**
42
+ * Transform {{scenario:Name:ID}} markers in PTY output into OSC 8 hyperlinks.
43
+ * OSC 8 format: \x1b]8;;URL\x07VISIBLE_TEXT\x1b]8;;\x07
44
+ * xterm.js renders the visible text as a clickable link.
45
+ *
46
+ * Claude Code's renderer inserts ANSI escape codes (colors/styles) within the
47
+ * marker text, so we can't regex match on the raw PTY data directly. Instead,
48
+ * strip ANSI codes to find markers, then map positions back to the original
49
+ * string for replacement.
50
+ */
51
+ function transformScenarioMarkers(data, port) {
52
+ // Strip ANSI escape sequences to get clean text for marker detection
53
+ const stripped = data.replace(ANSI_ESCAPE_RE, '');
54
+ if (!stripped.includes('{{scenario:'))
55
+ return data;
56
+ const posMap = buildAnsiPositionMap(data, stripped);
57
+ // Find markers in the stripped text
58
+ const markerRegex = /\{\{scenario:([^:}]+):([^}]+)\}\}/g;
59
+ const replacements = [];
60
+ let m;
61
+ while ((m = markerRegex.exec(stripped)) !== null) {
62
+ const url = `http://localhost:${port}/editor?scenario=${m[2]}&ref=link`;
63
+ const visibleName = m[1];
64
+ // Pad replacement to match the original marker's visible width so table
65
+ // columns stay aligned after the shorter hyperlink text replaces the marker.
66
+ const pad = ' '.repeat(Math.max(0, m[0].length - visibleName.length));
67
+ replacements.push({
68
+ origStart: posMap[m.index],
69
+ origEnd: posMap[m.index + m[0].length],
70
+ replacement: `\x1b]8;;${url}\x07${visibleName}\x1b]8;;\x07${pad}`,
71
+ });
72
+ }
73
+ if (replacements.length === 0)
74
+ return data;
75
+ // Replace from end to start so earlier positions stay valid
76
+ let result = data;
77
+ for (let i = replacements.length - 1; i >= 0; i--) {
78
+ const r = replacements[i];
79
+ result =
80
+ result.slice(0, r.origStart) + r.replacement + result.slice(r.origEnd);
81
+ }
82
+ return result;
83
+ }
84
+ /**
85
+ * Create a stateful scenario marker transformer that buffers partial markers
86
+ * across PTY chunks. Claude Code streams output token by token, so the PTY
87
+ * can split a {{scenario:Name:ID}} marker across two (or more) data events.
88
+ * Without buffering, split markers pass through un-transformed as raw text.
89
+ */
90
+ function createMarkerTransformer(port) {
91
+ let buffer = '';
92
+ return function transform(data) {
93
+ // Prepend any buffered partial-marker text from the previous chunk
94
+ const combined = buffer + data;
95
+ buffer = '';
96
+ // Strip ANSI to detect partial markers at the end
97
+ const stripped = combined.replace(ANSI_ESCAPE_RE, '');
98
+ // Check for an unclosed {{ at the end — potential partial marker
99
+ const lastOpen = stripped.lastIndexOf('{{');
100
+ if (lastOpen !== -1 && !stripped.slice(lastOpen).includes('}}')) {
101
+ // Map the stripped position back to the original string
102
+ const posMap = buildAnsiPositionMap(combined, stripped);
103
+ const splitPos = posMap[lastOpen];
104
+ // Safety: if partial marker exceeds 500 chars, it's not a real marker — flush it
105
+ if (combined.length - splitPos > 500) {
106
+ return transformScenarioMarkers(combined, port);
107
+ }
108
+ buffer = combined.slice(splitPos);
109
+ const toSend = combined.slice(0, splitPos);
110
+ // If nothing to send yet (entire chunk is a partial marker), return empty
111
+ if (toSend.length === 0)
112
+ return '';
113
+ return transformScenarioMarkers(toSend, port);
114
+ }
115
+ return transformScenarioMarkers(combined, port);
116
+ };
117
+ }
118
+ // Ping interval reference — shared so cleanup can clear it
119
+ let pingInterval = globalThis.__codeyamPingInterval ?? null;
120
+ // Keys to forward from the server env into the PTY shell.
121
+ // Keeps the env clean (no giant CODEYAM_PROJECT JSON blobs) while
122
+ // preserving everything Claude Code and the user's shell need.
123
+ const ENV_PASSTHROUGH_KEYS = [
124
+ 'PATH',
125
+ 'HOME',
126
+ 'USER',
127
+ 'LOGNAME',
128
+ 'SHELL',
129
+ 'TERM',
130
+ 'LANG',
131
+ 'LC_ALL',
132
+ 'LC_CTYPE',
133
+ 'EDITOR',
134
+ 'VISUAL',
135
+ 'TMPDIR',
136
+ 'XDG_CONFIG_HOME',
137
+ 'XDG_DATA_HOME',
138
+ 'XDG_CACHE_HOME',
139
+ // API keys Claude Code may need
140
+ 'ANTHROPIC_API_KEY',
141
+ 'OPENAI_API_KEY',
142
+ // nvm / fnm / volta node version managers
143
+ 'NVM_DIR',
144
+ 'NVM_BIN',
145
+ 'FNM_DIR',
146
+ 'VOLTA_HOME',
147
+ // Homebrew
148
+ 'HOMEBREW_PREFIX',
149
+ 'HOMEBREW_CELLAR',
150
+ 'HOMEBREW_REPOSITORY',
151
+ ];
152
+ function buildPtyEnv() {
153
+ const env = {};
154
+ for (const key of ENV_PASSTHROUGH_KEYS) {
155
+ const val = process.env[key];
156
+ if (val != null)
157
+ env[key] = val;
158
+ }
159
+ // Always set TERM for proper terminal behavior
160
+ if (!env.TERM)
161
+ env.TERM = 'xterm-256color';
162
+ return env;
163
+ }
164
+ /**
165
+ * Convert a name to a safe file name matching CodeYam's convention.
166
+ * e.g. "Default Scenario" -> "Default_Scenario"
167
+ */
168
+ function safeFileName(name) {
169
+ const safe = name.replace(/[^a-zA-Z0-9_]+/g, '_').replace(/^_+|_+$/g, '');
170
+ return safe.slice(0, 1).toUpperCase() + safe.slice(1);
171
+ }
172
+ /**
173
+ * Find the actual mock data file for a scenario in the tmp project.
174
+ * Tries a fast heuristic (extract app dir from entity file path) first,
175
+ * then falls back to a shallow directory search.
176
+ */
177
+ function findMockDataFile(projectRoot, entityFilePath, scenarioName) {
178
+ const scenarioSlug = safeFileName(scenarioName);
179
+ const mockFile = `MockData_${scenarioSlug}.tsx`;
180
+ // Heuristic: the __codeyamMocks__ dir lives at the app directory level.
181
+ // Extract "app/" (or "src/", "pages/") from the entity's file path.
182
+ if (entityFilePath) {
183
+ const parts = entityFilePath.split('/');
184
+ for (let i = 0; i < parts.length; i++) {
185
+ if (['app', 'src', 'pages'].includes(parts[i])) {
186
+ const appDir = parts.slice(0, i + 1).join('/');
187
+ const candidate = path.join(projectRoot, appDir, '__codeyamMocks__', mockFile);
188
+ if (fs.existsSync(candidate))
189
+ return candidate;
190
+ }
191
+ }
192
+ }
193
+ // Fallback: search __codeyamMocks__ directories up to 5 levels deep
194
+ function searchDir(dir, depth) {
195
+ if (depth > 5)
196
+ return null;
197
+ try {
198
+ for (const entry of fs.readdirSync(dir)) {
199
+ if (entry === 'node_modules' ||
200
+ entry === '.git' ||
201
+ entry === 'coverage')
202
+ continue;
203
+ const full = path.join(dir, entry);
204
+ if (entry === '__codeyamMocks__') {
205
+ const candidate = path.join(full, mockFile);
206
+ if (fs.existsSync(candidate))
207
+ return candidate;
208
+ continue;
209
+ }
210
+ try {
211
+ if (fs.statSync(full).isDirectory()) {
212
+ const result = searchDir(full, depth + 1);
213
+ if (result)
214
+ return result;
215
+ }
216
+ }
217
+ catch {
218
+ // Permission error or broken symlink
219
+ }
220
+ }
221
+ }
222
+ catch {
223
+ // Directory unreadable
224
+ }
225
+ return null;
226
+ }
227
+ return searchDir(projectRoot, 0);
228
+ }
229
+ /**
230
+ * Write a structured context file for the codeyam-dev-mode skill.
231
+ * The skill reads this file on startup instead of receiving a long CLI argument.
232
+ * Returns true if context was written successfully, false otherwise.
233
+ */
234
+ function writeDevModeContext(ctx) {
235
+ if (!ctx.entityName)
236
+ return false;
237
+ const codeyamRoot = process.env.CODEYAM_ROOT_PATH || process.cwd();
238
+ const contextDir = path.join(codeyamRoot, '.codeyam');
239
+ const contextPath = path.join(contextDir, 'dev-mode-context.md');
240
+ try {
241
+ fs.mkdirSync(contextDir, { recursive: true });
242
+ const lines = ['# Dev Mode Context', ''];
243
+ // Entity section
244
+ lines.push('## Entity');
245
+ lines.push(`- **Name:** ${ctx.entityName}`);
246
+ if (ctx.entityType)
247
+ lines.push(`- **Type:** ${ctx.entityType}`);
248
+ if (ctx.entitySha)
249
+ lines.push(`- **SHA:** ${ctx.entitySha}`);
250
+ if (ctx.entityFilePath)
251
+ lines.push(`- **Source file:** ${ctx.entityFilePath}`);
252
+ lines.push('');
253
+ // Scenario section
254
+ if (ctx.scenarioName) {
255
+ lines.push('## Scenario');
256
+ lines.push(`- **Name:** ${ctx.scenarioName}`);
257
+ if (ctx.scenarioDescription)
258
+ lines.push(`- **Description:** ${ctx.scenarioDescription}`);
259
+ if (ctx.analysisId)
260
+ lines.push(`- **Analysis ID:** ${ctx.analysisId}`);
261
+ lines.push('');
262
+ }
263
+ // Files section
264
+ lines.push('## Files');
265
+ if (ctx.entityFilePath) {
266
+ lines.push(`- **Source file:** ${ctx.entityFilePath}`);
267
+ }
268
+ if (ctx.projectSlug && ctx.scenarioName) {
269
+ const tmpBase = `/tmp/codeyam/local-dev/${ctx.projectSlug}`;
270
+ const tmpProject = `${tmpBase}/project`;
271
+ const mockDataPath = findMockDataFile(tmpProject, ctx.entityFilePath, ctx.scenarioName);
272
+ if (mockDataPath) {
273
+ lines.push(`- **Mock data:** ${mockDataPath}`);
274
+ }
275
+ else {
276
+ const scenarioSlug = safeFileName(ctx.scenarioName);
277
+ lines.push(`- **Mock data:** search for \`MockData_${scenarioSlug}.tsx\` in \`__codeyamMocks__\` under ${tmpProject}`);
278
+ }
279
+ lines.push(`- **Dev server project:** ${tmpProject}`);
280
+ lines.push(`- **Server log:** ${tmpBase}/codeyam/log.txt`);
281
+ }
282
+ lines.push('');
283
+ // Database
284
+ lines.push('## Database');
285
+ lines.push(`- **Path:** .codeyam/db.sqlite3`);
286
+ lines.push('');
287
+ // Server
288
+ const serverPort = process.env.CODEYAM_PORT || '3111';
289
+ lines.push('## Server');
290
+ lines.push(`- **Refresh preview:** \`curl -X POST http://localhost:${serverPort}/api/dev-mode-refresh\``);
291
+ lines.push('');
292
+ fs.writeFileSync(contextPath, lines.join('\n'), 'utf8');
293
+ return true;
294
+ }
295
+ catch (error) {
296
+ console.error('[terminalServer] Failed to write dev-mode-context.md:', error);
297
+ return false;
298
+ }
299
+ }
300
+ /**
301
+ * Write a structured context file for the codeyam-editor skill.
302
+ * Returns true if context was written successfully, false otherwise.
303
+ */
304
+ function writeEditorModeContext(ctx) {
305
+ if (!ctx.projectSlug)
306
+ return false;
307
+ const codeyamRoot = process.env.CODEYAM_ROOT_PATH || process.cwd();
308
+ const contextDir = path.join(codeyamRoot, '.codeyam');
309
+ const contextPath = path.join(contextDir, 'editor-mode-context.md');
310
+ try {
311
+ fs.mkdirSync(contextDir, { recursive: true });
312
+ const serverPort = process.env.CODEYAM_PORT || '3111';
313
+ const proxyPort = parseInt(serverPort, 10) + 1;
314
+ const lines = [
315
+ '# Editor Mode Context',
316
+ '',
317
+ '## Project',
318
+ `- **Root:** ${codeyamRoot}`,
319
+ `- **Slug:** ${ctx.projectSlug}`,
320
+ '',
321
+ '## Server',
322
+ `- **Port:** ${serverPort}`,
323
+ `- **Dashboard:** http://localhost:${serverPort}/editor`,
324
+ `- **Proxy:** http://localhost:${proxyPort} (used by the browser iframe only — do NOT use for health checks)`,
325
+ '',
326
+ '## Workflow',
327
+ '- **Guided steps:** Run `codeyam editor` for the next step (plan → prototype → confirm → deconstruct → extract → glossary → analyze → app scenarios → user scenarios → verify → review)',
328
+ '- Each feature follows 11 steps: `codeyam editor 1` through `codeyam editor 11`',
329
+ '- Steps 1, 3, and 11 require user confirmation before proceeding',
330
+ '',
331
+ '## Verifying the Dev Server',
332
+ '- Get the dev server URL: `curl -s http://localhost:' +
333
+ serverPort +
334
+ '/api/editor-dev-server` → look at the `"url"` field (e.g., `http://localhost:3000`)',
335
+ '- Check the page loads: `curl -s -o /dev/null -w "%{http_code}" http://localhost:3000` (use the actual dev server URL, NOT the proxy)',
336
+ '- Check API routes work: `curl -s http://localhost:3000/api/your-route` (should return JSON, not "Internal Server Error")',
337
+ '- **NEVER check localhost:' +
338
+ proxyPort +
339
+ ' for health** — the proxy returns 200 even when the app is broken',
340
+ '',
341
+ '## API Endpoints',
342
+ `- **Register scenario (auto-captures screenshot):** \`codeyam editor register '{"name":"...","description":"...","mockData":{"routes":{"/api/tasks":{"body":[...]}}}}'\``,
343
+ `- **Get active scenario data:** \`curl http://localhost:${serverPort}/api/editor-scenario-data\``,
344
+ `- **Refresh preview:** \`curl -X POST http://localhost:${serverPort}/api/dev-mode-refresh\``,
345
+ `- **Refresh config:** \`curl -X POST http://localhost:${serverPort}/api/editor-refresh\` (also starts dev server if a webapp is detected)`,
346
+ `- **Dev server status:** \`curl http://localhost:${serverPort}/api/editor-dev-server\``,
347
+ `- **Start dev server:** \`curl -X POST http://localhost:${serverPort}/api/editor-dev-server -H 'Content-Type: application/json' -d '{"action":"start"}'\``,
348
+ `- **Restart dev server:** \`curl -X POST http://localhost:${serverPort}/api/editor-dev-server -H 'Content-Type: application/json' -d '{"action":"restart"}'\``,
349
+ `- **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)`,
350
+ `- **Journal screenshot:** \`curl -X POST http://localhost:${serverPort}/api/editor-journal-screenshot -H 'Content-Type: application/json' -d '{"url":"...","filename":"..."}'\``,
351
+ `- **Journal entry:** \`curl -X POST http://localhost:${serverPort}/api/editor-journal-entry -H 'Content-Type: application/json' -d '{"title":"...","type":"feature","description":"..."}'\``,
352
+ '',
353
+ '## Scenario Data Format',
354
+ '- Use **route-keyed** mock data: keys are the API paths your app fetches',
355
+ '- Example: `{ "routes": { "/api/tasks": { "body": [...] }, "/api/users": { "body": [...] } } }`',
356
+ '- Error scenarios: `{ "routes": { "/api/tasks": { "status": 500, "body": { "error": "..." } } } }`',
357
+ '- The proxy intercepts GET requests to matching routes and returns the mock data',
358
+ '- POST/PUT/DELETE always go through to the real dev server',
359
+ '',
360
+ '## Component Isolation Routes',
361
+ '- To screenshot individual components, create ONE isolation route per component:',
362
+ ' - **Remix:** `app/routes/codeyam-isolate.ComponentName.tsx` → `/codeyam-isolate/ComponentName`',
363
+ ' - **Next.js:** `app/codeyam-isolate/ComponentName/page.tsx` → `/codeyam-isolate/ComponentName`',
364
+ '- The route defines a `scenarios` object mapping scenario names to props, reads `?s=ScenarioName` from the URL, and renders the component',
365
+ '- 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)',
366
+ '- **Create multiple scenarios per component** (like tests): default/happy path, edge cases (empty data, long text, max items), different visual states (loading, error, disabled)',
367
+ '- Register each scenario: `codeyam editor register \'{"name":"ComponentName - Scenario","componentName":"ComponentName","componentPath":"path/to/file.tsx","url":"/codeyam-isolate/ComponentName?s=Scenario","mockData":{"routes":{"/api/...":{"body":[...]}}}}\'`',
368
+ '- The url is a PATH, not a full URL — the proxy appends it and intercepts API calls the component makes',
369
+ '- `mockData.routes` provides data for any API calls the component makes internally (omit if none)',
370
+ '- Isolation routes stay in the project so the editor preview can display them',
371
+ '- Ensure `.gitignore` includes `**/codeyam-isolate*` so they are not committed',
372
+ '',
373
+ '## Files',
374
+ '- **Scenario data:** .codeyam/editor-scenarios/{scenario-id}.json',
375
+ '- **Scenario screenshots:** .codeyam/editor-scenarios/screenshots/{scenario-id}.png',
376
+ '- **Active scenario:** .codeyam/active-scenario.json',
377
+ '- **Database:** .codeyam/db.sqlite3',
378
+ '- **Journal:** .codeyam/journal/ (daily .md files + index.json + screenshots/)',
379
+ '',
380
+ ];
381
+ // Check if package.json exists to give context about project state
382
+ const hasPackageJson = fs.existsSync(path.join(codeyamRoot, 'package.json'));
383
+ if (!hasPackageJson) {
384
+ lines.push('## Status');
385
+ lines.push('- **Empty project** — no package.json found. Ask the user what they want to build.');
386
+ lines.push('');
387
+ }
388
+ fs.writeFileSync(contextPath, lines.join('\n'), 'utf8');
389
+ return true;
390
+ }
391
+ catch (error) {
392
+ console.error('[terminalServer] Failed to write editor-mode-context.md:', error);
393
+ return false;
394
+ }
395
+ }
396
+ /**
397
+ * Attach a WebSocket server at /ws/terminal to an existing HTTP server.
398
+ * Each WS connection spawns a PTY running the user's shell, then auto-starts `claude`.
399
+ *
400
+ * Features:
401
+ * - Ping/pong keepalive (30s interval) to detect dead connections
402
+ * - PTY detach/reattach: on WS close the PTY survives for 60s, allowing the client
403
+ * to reconnect with ?reconnectId=<sessionId> and reattach to the same PTY
404
+ * - Session IDs sent to client on connection for reconnect tracking
405
+ */
406
+ export function attachTerminalServer(httpServer) {
407
+ const wss = new WebSocketServer({ server: httpServer, path: '/ws/terminal' });
408
+ // --- Ping/pong keepalive ---
409
+ // The browser's native WebSocket automatically responds to ping frames with pong.
410
+ if (pingInterval)
411
+ clearInterval(pingInterval);
412
+ pingInterval = setInterval(() => {
413
+ for (const session of sessions) {
414
+ if (!session.isAlive) {
415
+ // Didn't respond to last ping — terminate
416
+ console.log(`[terminalServer] Session ${session.sessionId} ping timeout, terminating`);
417
+ session.ws.terminate();
418
+ continue;
419
+ }
420
+ session.isAlive = false;
421
+ session.ws.ping();
422
+ }
423
+ }, PING_INTERVAL_MS);
424
+ globalThis.__codeyamPingInterval = pingInterval;
425
+ wss.on('connection', (ws, req) => {
426
+ // Parse entity context from query params
427
+ const url = new URL(req.url || '', `http://${req.headers.host}`);
428
+ const entityName = url.searchParams.get('entityName') || '';
429
+ const entityType = url.searchParams.get('entityType') || '';
430
+ const entitySha = url.searchParams.get('entitySha') || '';
431
+ const entityFilePath = url.searchParams.get('entityFilePath') || '';
432
+ const scenarioName = url.searchParams.get('scenarioName') || '';
433
+ const scenarioDescription = url.searchParams.get('scenarioDescription') || '';
434
+ const analysisId = url.searchParams.get('analysisId') || '';
435
+ const projectSlug = url.searchParams.get('projectSlug') || '';
436
+ const editorMode = url.searchParams.get('editorMode') === 'true';
437
+ const reconnectId = url.searchParams.get('reconnectId') || '';
438
+ // --- Reconnection: reattach to a detached PTY ---
439
+ if (reconnectId && detachedPtys.has(reconnectId)) {
440
+ const detached = detachedPtys.get(reconnectId);
441
+ clearTimeout(detached.graceTimer);
442
+ detachedPtys.delete(reconnectId);
443
+ console.log(`[terminalServer] Reattaching session ${reconnectId}`);
444
+ const session = {
445
+ ws,
446
+ ptyProcess: detached.ptyProcess,
447
+ sessionId: detached.sessionId,
448
+ isAlive: true,
449
+ };
450
+ sessions.add(session);
451
+ // Send session ID so client can track it
452
+ ws.send(JSON.stringify({ type: 'session-id', sessionId: session.sessionId }));
453
+ // Send buffered output so client catches up
454
+ if (detached.outputBuffer) {
455
+ ws.send(JSON.stringify({ type: 'output', data: detached.outputBuffer }));
456
+ }
457
+ // Re-wire PTY output -> new WebSocket
458
+ // node-pty's onData returns a disposable; the old listener was still attached
459
+ // and was buffering output into detached.outputBuffer. We need to replace it.
460
+ // Unfortunately node-pty doesn't expose removeListener, so we use a closure flag.
461
+ let detachedFlag = false;
462
+ const reconnectPort = process.env.CODEYAM_PORT || '3111';
463
+ const reconnectTransformMarkers = createMarkerTransformer(reconnectPort);
464
+ detached.ptyProcess.onData((data) => {
465
+ if (detachedFlag)
466
+ return; // Superseded by a newer listener
467
+ if (ws.readyState === WebSocket.OPEN) {
468
+ if (!detached.hasClearedScreen &&
469
+ detached.hasContext &&
470
+ data.includes('╭')) {
471
+ detached.hasClearedScreen = true;
472
+ ws.send(JSON.stringify({ type: 'output', data: '\x1b[2J\x1b[H' }));
473
+ }
474
+ const transformed = reconnectTransformMarkers(data);
475
+ if (transformed.length > 0) {
476
+ ws.send(JSON.stringify({ type: 'output', data: transformed }));
477
+ }
478
+ const stripped = data.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
479
+ if (stripped.includes('Editor Mode \u2014')) {
480
+ console.log('[terminalServer] Detected claude-idle signal (reconnect)');
481
+ ws.send(JSON.stringify({ type: 'claude-idle' }));
482
+ }
483
+ }
484
+ });
485
+ detached.ptyProcess.onExit(() => {
486
+ sessions.delete(session);
487
+ if (ws.readyState === WebSocket.OPEN) {
488
+ ws.close();
489
+ }
490
+ });
491
+ // WebSocket messages -> PTY
492
+ ws.on('message', (raw) => {
493
+ try {
494
+ const msg = JSON.parse(raw.toString());
495
+ if (msg.type === 'input') {
496
+ detached.ptyProcess.write(msg.data);
497
+ }
498
+ else if (msg.type === 'resize' && msg.cols && msg.rows) {
499
+ detached.ptyProcess.resize(msg.cols, msg.rows);
500
+ }
501
+ }
502
+ catch {
503
+ detached.ptyProcess.write(raw.toString());
504
+ }
505
+ });
506
+ ws.on('pong', () => {
507
+ session.isAlive = true;
508
+ });
509
+ ws.on('close', () => {
510
+ detachedFlag = true;
511
+ detachSession(session, detached.hasContext, detached.hasClearedScreen);
512
+ });
513
+ return;
514
+ }
515
+ // --- New connection: spawn a fresh PTY ---
516
+ const shell = process.env.SHELL || '/bin/zsh';
517
+ const cwd = process.env.CODEYAM_ROOT_PATH || process.cwd();
518
+ // Verify cwd exists, fall back to HOME
519
+ const safeCwd = fs.existsSync(cwd) ? cwd : process.env.HOME || '/tmp';
520
+ // Spawn PTY with a clean env (no giant JSON blobs from CODEYAM_PROJECT etc.)
521
+ let ptyProcess;
522
+ try {
523
+ ptyProcess = pty.spawn(shell, ['-l'], {
524
+ name: 'xterm-256color',
525
+ cols: 120,
526
+ rows: 30,
527
+ cwd: safeCwd,
528
+ env: buildPtyEnv(),
529
+ });
530
+ }
531
+ catch (error) {
532
+ console.error('[terminalServer] Failed to spawn PTY:', {
533
+ shell,
534
+ cwd: safeCwd,
535
+ error,
536
+ });
537
+ ws.send(JSON.stringify({
538
+ type: 'output',
539
+ data: `\r\nFailed to start terminal: ${error.message}\r\n`,
540
+ }));
541
+ ws.close();
542
+ return;
543
+ }
544
+ const sessionId = crypto.randomUUID();
545
+ const session = {
546
+ ws,
547
+ ptyProcess,
548
+ sessionId,
549
+ isAlive: true,
550
+ };
551
+ sessions.add(session);
552
+ // Send session ID so client can use it for reconnection
553
+ ws.send(JSON.stringify({ type: 'session-id', sessionId }));
554
+ // Write context file for the appropriate skill (dev-mode or editor)
555
+ const hasContext = editorMode
556
+ ? writeEditorModeContext({ projectSlug })
557
+ : writeDevModeContext({
558
+ entityName,
559
+ entityType,
560
+ entitySha,
561
+ entityFilePath,
562
+ scenarioName,
563
+ scenarioDescription,
564
+ analysisId,
565
+ projectSlug,
566
+ });
567
+ let hasClearedScreen = false;
568
+ // Rolling buffer of trailing text to detect "Editor Mode —" across PTY chunks.
569
+ let idleDetectBuffer = '';
570
+ const IDLE_MARKER = 'Editor Mode \u2014';
571
+ // PTY output -> WebSocket
572
+ const serverPort = process.env.CODEYAM_PORT || '3111';
573
+ // Stateful transformer that buffers partial {{scenario:...}} markers
574
+ // across PTY chunks so they don't appear as raw text.
575
+ const transformMarkers = createMarkerTransformer(serverPort);
576
+ ptyProcess.onData((data) => {
577
+ if (ws.readyState === WebSocket.OPEN) {
578
+ // When Claude Code starts (indicated by its box-drawing welcome banner),
579
+ // clear the screen to hide the raw shell command.
580
+ if (!hasClearedScreen && hasContext && data.includes('╭')) {
581
+ hasClearedScreen = true;
582
+ ws.send(JSON.stringify({ type: 'output', data: '\x1b[2J\x1b[H' }));
583
+ }
584
+ // Transform {{scenario:Name:ID}} markers into OSC 8 clickable hyperlinks.
585
+ // Uses stateful buffering to handle markers split across PTY chunks.
586
+ const transformed = transformMarkers(data);
587
+ if (transformed.length > 0) {
588
+ ws.send(JSON.stringify({ type: 'output', data: transformed }));
589
+ }
590
+ // Detect the Stop hook output — signals Claude is waiting for user input.
591
+ // The hook outputs "Editor Mode —" when Claude finishes a turn.
592
+ // Strip ANSI escape codes and check buffer+current to handle cross-chunk splits.
593
+ const stripped = data.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '');
594
+ const combined = idleDetectBuffer + stripped;
595
+ if (combined.includes(IDLE_MARKER)) {
596
+ console.log('[terminalServer] Detected claude-idle signal');
597
+ ws.send(JSON.stringify({ type: 'claude-idle' }));
598
+ idleDetectBuffer = '';
599
+ }
600
+ else {
601
+ // Keep trailing chars in case the marker spans two chunks
602
+ idleDetectBuffer = stripped.slice(-(IDLE_MARKER.length - 1));
603
+ }
604
+ }
605
+ });
606
+ ptyProcess.onExit(() => {
607
+ sessions.delete(session);
608
+ // Also clean up from detachedPtys if it was detached
609
+ if (detachedPtys.has(sessionId)) {
610
+ clearTimeout(detachedPtys.get(sessionId).graceTimer);
611
+ detachedPtys.delete(sessionId);
612
+ }
613
+ if (ws.readyState === WebSocket.OPEN) {
614
+ ws.close();
615
+ }
616
+ });
617
+ // WebSocket messages -> PTY
618
+ ws.on('message', (raw) => {
619
+ try {
620
+ const msg = JSON.parse(raw.toString());
621
+ if (msg.type === 'input') {
622
+ ptyProcess.write(msg.data);
623
+ }
624
+ else if (msg.type === 'resize' && msg.cols && msg.rows) {
625
+ ptyProcess.resize(msg.cols, msg.rows);
626
+ }
627
+ }
628
+ catch {
629
+ // Non-JSON message, treat as raw input
630
+ ptyProcess.write(raw.toString());
631
+ }
632
+ });
633
+ ws.on('pong', () => {
634
+ session.isAlive = true;
635
+ });
636
+ ws.on('close', () => {
637
+ detachSession(session, hasContext, hasClearedScreen);
638
+ });
639
+ // Start Claude Code with the appropriate skill.
640
+ // Using a skill avoids shell escaping issues and multi-line paste detection.
641
+ setTimeout(() => {
642
+ if (editorMode && hasContext) {
643
+ ptyProcess.write("claude '/codeyam-editor'\r");
644
+ }
645
+ else if (hasContext) {
646
+ ptyProcess.write("claude '/codeyam-dev-mode'\r");
647
+ }
648
+ else {
649
+ ptyProcess.write('claude\r');
650
+ }
651
+ }, 500);
652
+ });
653
+ console.log('[terminalServer] WebSocket terminal server attached at /ws/terminal');
654
+ }
655
+ /**
656
+ * Detach a session's PTY instead of killing it, giving the client time to reconnect.
657
+ * The PTY is moved to `detachedPtys` with a grace timer; if the client reconnects
658
+ * within DETACH_GRACE_MS, the PTY is reattached. Otherwise it's killed.
659
+ */
660
+ function detachSession(session, hasContext = false, hasClearedScreen = false) {
661
+ sessions.delete(session);
662
+ const { sessionId, ptyProcess } = session;
663
+ // If already detached (shouldn't happen), skip
664
+ if (detachedPtys.has(sessionId))
665
+ return;
666
+ let outputBuffer = '';
667
+ // Buffer PTY output during detachment so the client can catch up on reconnect
668
+ ptyProcess.onData((data) => {
669
+ outputBuffer += data;
670
+ // Cap buffer size
671
+ if (outputBuffer.length > OUTPUT_BUFFER_MAX) {
672
+ outputBuffer = outputBuffer.slice(-OUTPUT_BUFFER_MAX);
673
+ }
674
+ });
675
+ const graceTimer = setTimeout(() => {
676
+ console.log(`[terminalServer] Grace period expired for session ${sessionId}, killing PTY`);
677
+ detachedPtys.delete(sessionId);
678
+ try {
679
+ ptyProcess.kill();
680
+ }
681
+ catch {
682
+ /* already dead */
683
+ }
684
+ }, DETACH_GRACE_MS);
685
+ detachedPtys.set(sessionId, {
686
+ ptyProcess,
687
+ sessionId,
688
+ graceTimer,
689
+ outputBuffer,
690
+ hasContext,
691
+ hasClearedScreen,
692
+ });
693
+ console.log(`[terminalServer] Session ${sessionId} detached, PTY kept alive for ${DETACH_GRACE_MS / 1000}s`);
694
+ }
695
+ /**
696
+ * Send a refresh-preview message to all connected terminal WebSocket clients.
697
+ * The Terminal component relays this to the parent page to reload the iframe.
698
+ */
699
+ export function broadcastPreviewRefresh() {
700
+ const msg = JSON.stringify({ type: 'refresh-preview' });
701
+ let count = 0;
702
+ for (const session of sessions) {
703
+ try {
704
+ if (session.ws.readyState === WebSocket.OPEN) {
705
+ session.ws.send(msg);
706
+ count++;
707
+ }
708
+ }
709
+ catch {
710
+ // Ignore send errors
711
+ }
712
+ }
713
+ return count;
714
+ }
715
+ /**
716
+ * Kill all active PTY sessions and detached PTYs. Call during shutdown.
717
+ */
718
+ export function cleanupAllTerminalSessions() {
719
+ // Clear ping interval
720
+ if (pingInterval) {
721
+ clearInterval(pingInterval);
722
+ pingInterval = null;
723
+ globalThis.__codeyamPingInterval = null;
724
+ }
725
+ // Clean up active sessions
726
+ for (const session of Array.from(sessions)) {
727
+ try {
728
+ session.ptyProcess.kill();
729
+ }
730
+ catch {
731
+ // Already dead
732
+ }
733
+ try {
734
+ session.ws.close();
735
+ }
736
+ catch {
737
+ // Already closed
738
+ }
739
+ }
740
+ sessions.clear();
741
+ // Clean up detached PTYs
742
+ for (const [, detached] of detachedPtys) {
743
+ clearTimeout(detached.graceTimer);
744
+ try {
745
+ detached.ptyProcess.kill();
746
+ }
747
+ catch {
748
+ // Already dead
749
+ }
750
+ }
751
+ detachedPtys.clear();
752
+ }
753
+ //# sourceMappingURL=terminalServer.js.map