@nexus-cortex/executors 4.26.0

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 (365) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +2 -0
  3. package/README.md +13 -0
  4. package/dist/ExecutorRegistry.d.ts +89 -0
  5. package/dist/ExecutorRegistry.d.ts.map +1 -0
  6. package/dist/ExecutorRegistry.js +219 -0
  7. package/dist/ExecutorRegistry.js.map +1 -0
  8. package/dist/base/BaseTool.d.ts +108 -0
  9. package/dist/base/BaseTool.d.ts.map +1 -0
  10. package/dist/base/BaseTool.js +111 -0
  11. package/dist/base/BaseTool.js.map +1 -0
  12. package/dist/base/ToolRegistry.d.ts +141 -0
  13. package/dist/base/ToolRegistry.d.ts.map +1 -0
  14. package/dist/base/ToolRegistry.js +241 -0
  15. package/dist/base/ToolRegistry.js.map +1 -0
  16. package/dist/base/ToolResult.d.ts +63 -0
  17. package/dist/base/ToolResult.d.ts.map +1 -0
  18. package/dist/base/ToolResult.js +8 -0
  19. package/dist/base/ToolResult.js.map +1 -0
  20. package/dist/base/index.d.ts +10 -0
  21. package/dist/base/index.d.ts.map +1 -0
  22. package/dist/base/index.js +8 -0
  23. package/dist/base/index.js.map +1 -0
  24. package/dist/implementations/addon/CreateArtifactTool.d.ts +221 -0
  25. package/dist/implementations/addon/CreateArtifactTool.d.ts.map +1 -0
  26. package/dist/implementations/addon/CreateArtifactTool.js +1042 -0
  27. package/dist/implementations/addon/CreateArtifactTool.js.map +1 -0
  28. package/dist/implementations/addon/FrameDiffCache.d.ts +166 -0
  29. package/dist/implementations/addon/FrameDiffCache.d.ts.map +1 -0
  30. package/dist/implementations/addon/FrameDiffCache.js +395 -0
  31. package/dist/implementations/addon/FrameDiffCache.js.map +1 -0
  32. package/dist/implementations/addon/H264StreamEncoder.d.ts +84 -0
  33. package/dist/implementations/addon/H264StreamEncoder.d.ts.map +1 -0
  34. package/dist/implementations/addon/H264StreamEncoder.js +203 -0
  35. package/dist/implementations/addon/H264StreamEncoder.js.map +1 -0
  36. package/dist/implementations/addon/HybridScreenshotManager.d.ts +197 -0
  37. package/dist/implementations/addon/HybridScreenshotManager.d.ts.map +1 -0
  38. package/dist/implementations/addon/HybridScreenshotManager.js +415 -0
  39. package/dist/implementations/addon/HybridScreenshotManager.js.map +1 -0
  40. package/dist/implementations/addon/InspectSandboxTool.d.ts +54 -0
  41. package/dist/implementations/addon/InspectSandboxTool.d.ts.map +1 -0
  42. package/dist/implementations/addon/InspectSandboxTool.js +226 -0
  43. package/dist/implementations/addon/InspectSandboxTool.js.map +1 -0
  44. package/dist/implementations/addon/InteractWithSandboxTool.d.ts +90 -0
  45. package/dist/implementations/addon/InteractWithSandboxTool.d.ts.map +1 -0
  46. package/dist/implementations/addon/InteractWithSandboxTool.js +367 -0
  47. package/dist/implementations/addon/InteractWithSandboxTool.js.map +1 -0
  48. package/dist/implementations/addon/KeyframeDetector.d.ts +140 -0
  49. package/dist/implementations/addon/KeyframeDetector.d.ts.map +1 -0
  50. package/dist/implementations/addon/KeyframeDetector.js +390 -0
  51. package/dist/implementations/addon/KeyframeDetector.js.map +1 -0
  52. package/dist/implementations/addon/ModifySandboxTool.d.ts +62 -0
  53. package/dist/implementations/addon/ModifySandboxTool.d.ts.map +1 -0
  54. package/dist/implementations/addon/ModifySandboxTool.js +266 -0
  55. package/dist/implementations/addon/ModifySandboxTool.js.map +1 -0
  56. package/dist/implementations/addon/ReactArtifactBuilder.d.ts +27 -0
  57. package/dist/implementations/addon/ReactArtifactBuilder.d.ts.map +1 -0
  58. package/dist/implementations/addon/ReactArtifactBuilder.js +198 -0
  59. package/dist/implementations/addon/ReactArtifactBuilder.js.map +1 -0
  60. package/dist/implementations/addon/SandboxEventBroadcaster.d.ts +143 -0
  61. package/dist/implementations/addon/SandboxEventBroadcaster.d.ts.map +1 -0
  62. package/dist/implementations/addon/SandboxEventBroadcaster.js +258 -0
  63. package/dist/implementations/addon/SandboxEventBroadcaster.js.map +1 -0
  64. package/dist/implementations/addon/SandboxIntrospectionTools.d.ts +77 -0
  65. package/dist/implementations/addon/SandboxIntrospectionTools.d.ts.map +1 -0
  66. package/dist/implementations/addon/SandboxIntrospectionTools.js +292 -0
  67. package/dist/implementations/addon/SandboxIntrospectionTools.js.map +1 -0
  68. package/dist/implementations/addon/SandboxViewServer.d.ts +127 -0
  69. package/dist/implementations/addon/SandboxViewServer.d.ts.map +1 -0
  70. package/dist/implementations/addon/SandboxViewServer.js +775 -0
  71. package/dist/implementations/addon/SandboxViewServer.js.map +1 -0
  72. package/dist/implementations/addon/ScreenStream.d.ts +149 -0
  73. package/dist/implementations/addon/ScreenStream.d.ts.map +1 -0
  74. package/dist/implementations/addon/ScreenStream.js +306 -0
  75. package/dist/implementations/addon/ScreenStream.js.map +1 -0
  76. package/dist/implementations/addon/StopSandboxTool.d.ts +61 -0
  77. package/dist/implementations/addon/StopSandboxTool.d.ts.map +1 -0
  78. package/dist/implementations/addon/StopSandboxTool.js +252 -0
  79. package/dist/implementations/addon/StopSandboxTool.js.map +1 -0
  80. package/dist/implementations/addon/TerminalSandbox.d.ts +111 -0
  81. package/dist/implementations/addon/TerminalSandbox.d.ts.map +1 -0
  82. package/dist/implementations/addon/TerminalSandbox.js +345 -0
  83. package/dist/implementations/addon/TerminalSandbox.js.map +1 -0
  84. package/dist/implementations/addon/VisualFeedbackBridge.d.ts +367 -0
  85. package/dist/implementations/addon/VisualFeedbackBridge.d.ts.map +1 -0
  86. package/dist/implementations/addon/VisualFeedbackBridge.js +888 -0
  87. package/dist/implementations/addon/VisualFeedbackBridge.js.map +1 -0
  88. package/dist/implementations/addon/WindowManager.d.ts +138 -0
  89. package/dist/implementations/addon/WindowManager.d.ts.map +1 -0
  90. package/dist/implementations/addon/WindowManager.js +276 -0
  91. package/dist/implementations/addon/WindowManager.js.map +1 -0
  92. package/dist/implementations/addon/index.d.ts +29 -0
  93. package/dist/implementations/addon/index.d.ts.map +1 -0
  94. package/dist/implementations/addon/index.js +29 -0
  95. package/dist/implementations/addon/index.js.map +1 -0
  96. package/dist/implementations/addon/injectables/reactIntrospection.d.ts +57 -0
  97. package/dist/implementations/addon/injectables/reactIntrospection.d.ts.map +1 -0
  98. package/dist/implementations/addon/injectables/reactIntrospection.js +480 -0
  99. package/dist/implementations/addon/injectables/reactIntrospection.js.map +1 -0
  100. package/dist/implementations/addon/terminal-client.html +253 -0
  101. package/dist/implementations/agent/PRAgentTool.d.ts +37 -0
  102. package/dist/implementations/agent/PRAgentTool.d.ts.map +1 -0
  103. package/dist/implementations/agent/PRAgentTool.js +257 -0
  104. package/dist/implementations/agent/PRAgentTool.js.map +1 -0
  105. package/dist/implementations/agent/TaskTool.d.ts +76 -0
  106. package/dist/implementations/agent/TaskTool.d.ts.map +1 -0
  107. package/dist/implementations/agent/TaskTool.js +424 -0
  108. package/dist/implementations/agent/TaskTool.js.map +1 -0
  109. package/dist/implementations/agent/index.d.ts +5 -0
  110. package/dist/implementations/agent/index.d.ts.map +1 -0
  111. package/dist/implementations/agent/index.js +3 -0
  112. package/dist/implementations/agent/index.js.map +1 -0
  113. package/dist/implementations/execution/BackgroundProcessRegistry.d.ts +68 -0
  114. package/dist/implementations/execution/BackgroundProcessRegistry.d.ts.map +1 -0
  115. package/dist/implementations/execution/BackgroundProcessRegistry.js +146 -0
  116. package/dist/implementations/execution/BackgroundProcessRegistry.js.map +1 -0
  117. package/dist/implementations/execution/BashOutputTool.d.ts +42 -0
  118. package/dist/implementations/execution/BashOutputTool.d.ts.map +1 -0
  119. package/dist/implementations/execution/BashOutputTool.js +168 -0
  120. package/dist/implementations/execution/BashOutputTool.js.map +1 -0
  121. package/dist/implementations/execution/CodeExecuteTool.d.ts +31 -0
  122. package/dist/implementations/execution/CodeExecuteTool.d.ts.map +1 -0
  123. package/dist/implementations/execution/CodeExecuteTool.js +127 -0
  124. package/dist/implementations/execution/CodeExecuteTool.js.map +1 -0
  125. package/dist/implementations/execution/KillShellTool.d.ts +37 -0
  126. package/dist/implementations/execution/KillShellTool.d.ts.map +1 -0
  127. package/dist/implementations/execution/KillShellTool.js +144 -0
  128. package/dist/implementations/execution/KillShellTool.js.map +1 -0
  129. package/dist/implementations/execution/SearchToolsTool.d.ts +32 -0
  130. package/dist/implementations/execution/SearchToolsTool.d.ts.map +1 -0
  131. package/dist/implementations/execution/SearchToolsTool.js +109 -0
  132. package/dist/implementations/execution/SearchToolsTool.js.map +1 -0
  133. package/dist/implementations/execution/ShellTool.d.ts +108 -0
  134. package/dist/implementations/execution/ShellTool.d.ts.map +1 -0
  135. package/dist/implementations/execution/ShellTool.js +546 -0
  136. package/dist/implementations/execution/ShellTool.js.map +1 -0
  137. package/dist/implementations/execution/WorkspaceManagerTool.d.ts +40 -0
  138. package/dist/implementations/execution/WorkspaceManagerTool.d.ts.map +1 -0
  139. package/dist/implementations/execution/WorkspaceManagerTool.js +370 -0
  140. package/dist/implementations/execution/WorkspaceManagerTool.js.map +1 -0
  141. package/dist/implementations/execution/index.d.ts +13 -0
  142. package/dist/implementations/execution/index.d.ts.map +1 -0
  143. package/dist/implementations/execution/index.js +13 -0
  144. package/dist/implementations/execution/index.js.map +1 -0
  145. package/dist/implementations/extensions/EndTurnTool.d.ts +62 -0
  146. package/dist/implementations/extensions/EndTurnTool.d.ts.map +1 -0
  147. package/dist/implementations/extensions/EndTurnTool.js +172 -0
  148. package/dist/implementations/extensions/EndTurnTool.js.map +1 -0
  149. package/dist/implementations/extensions/ResearchBacklogTool.d.ts +37 -0
  150. package/dist/implementations/extensions/ResearchBacklogTool.d.ts.map +1 -0
  151. package/dist/implementations/extensions/ResearchBacklogTool.js +102 -0
  152. package/dist/implementations/extensions/ResearchBacklogTool.js.map +1 -0
  153. package/dist/implementations/extensions/SkillTool.d.ts +108 -0
  154. package/dist/implementations/extensions/SkillTool.d.ts.map +1 -0
  155. package/dist/implementations/extensions/SkillTool.js +351 -0
  156. package/dist/implementations/extensions/SkillTool.js.map +1 -0
  157. package/dist/implementations/extensions/SlashCommandTool.d.ts +112 -0
  158. package/dist/implementations/extensions/SlashCommandTool.d.ts.map +1 -0
  159. package/dist/implementations/extensions/SlashCommandTool.js +315 -0
  160. package/dist/implementations/extensions/SlashCommandTool.js.map +1 -0
  161. package/dist/implementations/extensions/index.d.ts +14 -0
  162. package/dist/implementations/extensions/index.d.ts.map +1 -0
  163. package/dist/implementations/extensions/index.js +10 -0
  164. package/dist/implementations/extensions/index.js.map +1 -0
  165. package/dist/implementations/file/EditTool.d.ts +232 -0
  166. package/dist/implementations/file/EditTool.d.ts.map +1 -0
  167. package/dist/implementations/file/EditTool.js +707 -0
  168. package/dist/implementations/file/EditTool.js.map +1 -0
  169. package/dist/implementations/file/ReadFileTool.d.ts +49 -0
  170. package/dist/implementations/file/ReadFileTool.d.ts.map +1 -0
  171. package/dist/implementations/file/ReadFileTool.js +225 -0
  172. package/dist/implementations/file/ReadFileTool.js.map +1 -0
  173. package/dist/implementations/file/WriteBinaryTool.d.ts +21 -0
  174. package/dist/implementations/file/WriteBinaryTool.d.ts.map +1 -0
  175. package/dist/implementations/file/WriteBinaryTool.js +153 -0
  176. package/dist/implementations/file/WriteBinaryTool.js.map +1 -0
  177. package/dist/implementations/file/WriteFileTool.d.ts +41 -0
  178. package/dist/implementations/file/WriteFileTool.d.ts.map +1 -0
  179. package/dist/implementations/file/WriteFileTool.js +220 -0
  180. package/dist/implementations/file/WriteFileTool.js.map +1 -0
  181. package/dist/implementations/file/index.d.ts +8 -0
  182. package/dist/implementations/file/index.d.ts.map +1 -0
  183. package/dist/implementations/file/index.js +8 -0
  184. package/dist/implementations/file/index.js.map +1 -0
  185. package/dist/implementations/historical/GetConversationSegmentTool.d.ts +44 -0
  186. package/dist/implementations/historical/GetConversationSegmentTool.d.ts.map +1 -0
  187. package/dist/implementations/historical/GetConversationSegmentTool.js +220 -0
  188. package/dist/implementations/historical/GetConversationSegmentTool.js.map +1 -0
  189. package/dist/implementations/historical/ListCompactionBoundariesTool.d.ts +36 -0
  190. package/dist/implementations/historical/ListCompactionBoundariesTool.d.ts.map +1 -0
  191. package/dist/implementations/historical/ListCompactionBoundariesTool.js +174 -0
  192. package/dist/implementations/historical/ListCompactionBoundariesTool.js.map +1 -0
  193. package/dist/implementations/historical/ListSessionsTool.d.ts +38 -0
  194. package/dist/implementations/historical/ListSessionsTool.d.ts.map +1 -0
  195. package/dist/implementations/historical/ListSessionsTool.js +140 -0
  196. package/dist/implementations/historical/ListSessionsTool.js.map +1 -0
  197. package/dist/implementations/historical/LoadSessionTool.d.ts +39 -0
  198. package/dist/implementations/historical/LoadSessionTool.d.ts.map +1 -0
  199. package/dist/implementations/historical/LoadSessionTool.js +171 -0
  200. package/dist/implementations/historical/LoadSessionTool.js.map +1 -0
  201. package/dist/implementations/historical/RequestHistoricalContextTool.d.ts +46 -0
  202. package/dist/implementations/historical/RequestHistoricalContextTool.d.ts.map +1 -0
  203. package/dist/implementations/historical/RequestHistoricalContextTool.js +224 -0
  204. package/dist/implementations/historical/RequestHistoricalContextTool.js.map +1 -0
  205. package/dist/implementations/historical/SearchConversationHistoryTool.d.ts +51 -0
  206. package/dist/implementations/historical/SearchConversationHistoryTool.d.ts.map +1 -0
  207. package/dist/implementations/historical/SearchConversationHistoryTool.js +306 -0
  208. package/dist/implementations/historical/SearchConversationHistoryTool.js.map +1 -0
  209. package/dist/implementations/historical/index.d.ts +12 -0
  210. package/dist/implementations/historical/index.d.ts.map +1 -0
  211. package/dist/implementations/historical/index.js +12 -0
  212. package/dist/implementations/historical/index.js.map +1 -0
  213. package/dist/implementations/index.d.ts +16 -0
  214. package/dist/implementations/index.d.ts.map +1 -0
  215. package/dist/implementations/index.js +28 -0
  216. package/dist/implementations/index.js.map +1 -0
  217. package/dist/implementations/mcp/DiscoveredMcpTool.d.ts +58 -0
  218. package/dist/implementations/mcp/DiscoveredMcpTool.d.ts.map +1 -0
  219. package/dist/implementations/mcp/DiscoveredMcpTool.js +269 -0
  220. package/dist/implementations/mcp/DiscoveredMcpTool.js.map +1 -0
  221. package/dist/implementations/mcp/index.d.ts +9 -0
  222. package/dist/implementations/mcp/index.d.ts.map +1 -0
  223. package/dist/implementations/mcp/index.js +8 -0
  224. package/dist/implementations/mcp/index.js.map +1 -0
  225. package/dist/implementations/notebook/NotebookEditTool.d.ts +96 -0
  226. package/dist/implementations/notebook/NotebookEditTool.d.ts.map +1 -0
  227. package/dist/implementations/notebook/NotebookEditTool.js +390 -0
  228. package/dist/implementations/notebook/NotebookEditTool.js.map +1 -0
  229. package/dist/implementations/notebook/index.d.ts +7 -0
  230. package/dist/implementations/notebook/index.d.ts.map +1 -0
  231. package/dist/implementations/notebook/index.js +7 -0
  232. package/dist/implementations/notebook/index.js.map +1 -0
  233. package/dist/implementations/search/GlobTool.d.ts +73 -0
  234. package/dist/implementations/search/GlobTool.d.ts.map +1 -0
  235. package/dist/implementations/search/GlobTool.js +213 -0
  236. package/dist/implementations/search/GlobTool.js.map +1 -0
  237. package/dist/implementations/search/GrepTool.d.ts +102 -0
  238. package/dist/implementations/search/GrepTool.d.ts.map +1 -0
  239. package/dist/implementations/search/GrepTool.js +754 -0
  240. package/dist/implementations/search/GrepTool.js.map +1 -0
  241. package/dist/implementations/search/index.d.ts +6 -0
  242. package/dist/implementations/search/index.d.ts.map +1 -0
  243. package/dist/implementations/search/index.js +6 -0
  244. package/dist/implementations/search/index.js.map +1 -0
  245. package/dist/implementations/tmux/TmuxSessionTool.d.ts +82 -0
  246. package/dist/implementations/tmux/TmuxSessionTool.d.ts.map +1 -0
  247. package/dist/implementations/tmux/TmuxSessionTool.js +371 -0
  248. package/dist/implementations/tmux/TmuxSessionTool.js.map +1 -0
  249. package/dist/implementations/tmux/TmuxViewServer.d.ts +86 -0
  250. package/dist/implementations/tmux/TmuxViewServer.d.ts.map +1 -0
  251. package/dist/implementations/tmux/TmuxViewServer.js +480 -0
  252. package/dist/implementations/tmux/TmuxViewServer.js.map +1 -0
  253. package/dist/implementations/tmux/index.d.ts +6 -0
  254. package/dist/implementations/tmux/index.d.ts.map +1 -0
  255. package/dist/implementations/tmux/index.js +6 -0
  256. package/dist/implementations/tmux/index.js.map +1 -0
  257. package/dist/implementations/ui/AskUserQuestionTool.d.ts +77 -0
  258. package/dist/implementations/ui/AskUserQuestionTool.d.ts.map +1 -0
  259. package/dist/implementations/ui/AskUserQuestionTool.js +241 -0
  260. package/dist/implementations/ui/AskUserQuestionTool.js.map +1 -0
  261. package/dist/implementations/ui/ExitPlanModeTool.d.ts +44 -0
  262. package/dist/implementations/ui/ExitPlanModeTool.d.ts.map +1 -0
  263. package/dist/implementations/ui/ExitPlanModeTool.js +150 -0
  264. package/dist/implementations/ui/ExitPlanModeTool.js.map +1 -0
  265. package/dist/implementations/ui/TodoWriteTool.d.ts +59 -0
  266. package/dist/implementations/ui/TodoWriteTool.d.ts.map +1 -0
  267. package/dist/implementations/ui/TodoWriteTool.js +315 -0
  268. package/dist/implementations/ui/TodoWriteTool.js.map +1 -0
  269. package/dist/implementations/ui/index.d.ts +9 -0
  270. package/dist/implementations/ui/index.d.ts.map +1 -0
  271. package/dist/implementations/ui/index.js +9 -0
  272. package/dist/implementations/ui/index.js.map +1 -0
  273. package/dist/implementations/web/BrowseTool.d.ts +43 -0
  274. package/dist/implementations/web/BrowseTool.d.ts.map +1 -0
  275. package/dist/implementations/web/BrowseTool.js +181 -0
  276. package/dist/implementations/web/BrowseTool.js.map +1 -0
  277. package/dist/implementations/web/SandboxTransferTool.d.ts +30 -0
  278. package/dist/implementations/web/SandboxTransferTool.d.ts.map +1 -0
  279. package/dist/implementations/web/SandboxTransferTool.js +261 -0
  280. package/dist/implementations/web/SandboxTransferTool.js.map +1 -0
  281. package/dist/implementations/web/WebFetchTool.d.ts +93 -0
  282. package/dist/implementations/web/WebFetchTool.d.ts.map +1 -0
  283. package/dist/implementations/web/WebFetchTool.js +484 -0
  284. package/dist/implementations/web/WebFetchTool.js.map +1 -0
  285. package/dist/implementations/web/WebSearchTool.d.ts +53 -0
  286. package/dist/implementations/web/WebSearchTool.d.ts.map +1 -0
  287. package/dist/implementations/web/WebSearchTool.js +227 -0
  288. package/dist/implementations/web/WebSearchTool.js.map +1 -0
  289. package/dist/implementations/web/escalateDirective.d.ts +11 -0
  290. package/dist/implementations/web/escalateDirective.d.ts.map +1 -0
  291. package/dist/implementations/web/escalateDirective.js +20 -0
  292. package/dist/implementations/web/escalateDirective.js.map +1 -0
  293. package/dist/implementations/web/index.d.ts +10 -0
  294. package/dist/implementations/web/index.d.ts.map +1 -0
  295. package/dist/implementations/web/index.js +10 -0
  296. package/dist/implementations/web/index.js.map +1 -0
  297. package/dist/implementations/web/webBackends.d.ts +65 -0
  298. package/dist/implementations/web/webBackends.d.ts.map +1 -0
  299. package/dist/implementations/web/webBackends.js +430 -0
  300. package/dist/implementations/web/webBackends.js.map +1 -0
  301. package/dist/implementations/web/webFetchRequestInit.d.ts +9 -0
  302. package/dist/implementations/web/webFetchRequestInit.d.ts.map +1 -0
  303. package/dist/implementations/web/webFetchRequestInit.js +21 -0
  304. package/dist/implementations/web/webFetchRequestInit.js.map +1 -0
  305. package/dist/index.d.ts +14 -0
  306. package/dist/index.d.ts.map +1 -0
  307. package/dist/index.js +18 -0
  308. package/dist/index.js.map +1 -0
  309. package/dist/utils/ArtifactRegistry.d.ts +138 -0
  310. package/dist/utils/ArtifactRegistry.d.ts.map +1 -0
  311. package/dist/utils/ArtifactRegistry.js +259 -0
  312. package/dist/utils/ArtifactRegistry.js.map +1 -0
  313. package/dist/utils/ChromiumBrowserManager.d.ts +56 -0
  314. package/dist/utils/ChromiumBrowserManager.d.ts.map +1 -0
  315. package/dist/utils/ChromiumBrowserManager.js +243 -0
  316. package/dist/utils/ChromiumBrowserManager.js.map +1 -0
  317. package/dist/utils/FileUtils.d.ts +81 -0
  318. package/dist/utils/FileUtils.d.ts.map +1 -0
  319. package/dist/utils/FileUtils.js +148 -0
  320. package/dist/utils/FileUtils.js.map +1 -0
  321. package/dist/utils/GitPolicy.d.ts +70 -0
  322. package/dist/utils/GitPolicy.d.ts.map +1 -0
  323. package/dist/utils/GitPolicy.js +166 -0
  324. package/dist/utils/GitPolicy.js.map +1 -0
  325. package/dist/utils/GitUtils.d.ts +18 -0
  326. package/dist/utils/GitUtils.d.ts.map +1 -0
  327. package/dist/utils/GitUtils.js +62 -0
  328. package/dist/utils/GitUtils.js.map +1 -0
  329. package/dist/utils/SandboxRegistry.d.ts +110 -0
  330. package/dist/utils/SandboxRegistry.d.ts.map +1 -0
  331. package/dist/utils/SandboxRegistry.js +220 -0
  332. package/dist/utils/SandboxRegistry.js.map +1 -0
  333. package/dist/utils/SchemaValidator.d.ts +21 -0
  334. package/dist/utils/SchemaValidator.d.ts.map +1 -0
  335. package/dist/utils/SchemaValidator.js +67 -0
  336. package/dist/utils/SchemaValidator.js.map +1 -0
  337. package/dist/utils/SessionLock.d.ts +96 -0
  338. package/dist/utils/SessionLock.d.ts.map +1 -0
  339. package/dist/utils/SessionLock.js +276 -0
  340. package/dist/utils/SessionLock.js.map +1 -0
  341. package/dist/utils/SessionPersistence.d.ts +89 -0
  342. package/dist/utils/SessionPersistence.d.ts.map +1 -0
  343. package/dist/utils/SessionPersistence.js +244 -0
  344. package/dist/utils/SessionPersistence.js.map +1 -0
  345. package/dist/utils/TextUtils.d.ts +77 -0
  346. package/dist/utils/TextUtils.d.ts.map +1 -0
  347. package/dist/utils/TextUtils.js +112 -0
  348. package/dist/utils/TextUtils.js.map +1 -0
  349. package/dist/utils/TmuxCapture.d.ts +94 -0
  350. package/dist/utils/TmuxCapture.d.ts.map +1 -0
  351. package/dist/utils/TmuxCapture.js +131 -0
  352. package/dist/utils/TmuxCapture.js.map +1 -0
  353. package/dist/utils/TmuxManager.d.ts +65 -0
  354. package/dist/utils/TmuxManager.d.ts.map +1 -0
  355. package/dist/utils/TmuxManager.js +304 -0
  356. package/dist/utils/TmuxManager.js.map +1 -0
  357. package/dist/utils/autoResearchPlanGate.d.ts +10 -0
  358. package/dist/utils/autoResearchPlanGate.d.ts.map +1 -0
  359. package/dist/utils/autoResearchPlanGate.js +57 -0
  360. package/dist/utils/autoResearchPlanGate.js.map +1 -0
  361. package/dist/utils/index.d.ts +19 -0
  362. package/dist/utils/index.d.ts.map +1 -0
  363. package/dist/utils/index.js +13 -0
  364. package/dist/utils/index.js.map +1 -0
  365. package/package.json +83 -0
@@ -0,0 +1,266 @@
1
+ import { BaseTool } from '../../base/BaseTool.js';
2
+ import { CreateArtifactToolExecutor } from './CreateArtifactTool.js';
3
+ import { visualBridge } from './VisualFeedbackBridge.js';
4
+ import { broadcaster } from './SandboxEventBroadcaster.js';
5
+ import { rebuildReactBundle } from './ReactArtifactBuilder.js';
6
+ import { promises as fs } from 'fs';
7
+ import { join } from 'path';
8
+ /**
9
+ * ModifySandboxTool - Edit sandbox code with automatic hot reload and verification
10
+ *
11
+ * This tool provides a higher-level interface than raw Write tool:
12
+ * - Edits files within the sandbox directory
13
+ * - Waits for hot reload to complete
14
+ * - Captures visual snapshot after changes
15
+ * - Verifies changes took effect
16
+ *
17
+ * Advantages over Write tool:
18
+ * 1. Sandbox-aware - knows sandbox directory structure
19
+ * 2. Hot reload integration - waits for restart
20
+ * 3. Automatic verification - captures post-edit snapshot
21
+ * 4. Error detection - checks if reload succeeded
22
+ *
23
+ * Use Cases:
24
+ * 1. Iterative development - Edit → See → Edit again
25
+ * 2. Bug fixing - Modify code, verify fix visually
26
+ * 3. Feature addition - Add code, test immediately
27
+ * 4. Styling - Change CSS, see results instantly
28
+ *
29
+ * Example:
30
+ * ```
31
+ * await modifySandbox({
32
+ * sandboxId: "abc-123",
33
+ * file: "index.js",
34
+ * content: "// fixed code",
35
+ * waitForReload: true,
36
+ * captureAfterReload: true
37
+ * });
38
+ * ```
39
+ */
40
+ export class ModifySandboxExecutor extends BaseTool {
41
+ sandboxDir;
42
+ constructor(config) {
43
+ const schema = {
44
+ type: 'object',
45
+ properties: {
46
+ sandboxId: {
47
+ type: 'string',
48
+ description: 'Unique ID of the sandbox to modify'
49
+ },
50
+ file: {
51
+ type: 'string',
52
+ description: 'Filename to edit (relative to sandbox directory, e.g., "index.js")'
53
+ },
54
+ content: {
55
+ type: 'string',
56
+ description: 'New file content'
57
+ },
58
+ waitForReload: {
59
+ type: 'boolean',
60
+ description: 'Wait for hot reload to complete (default: true for dev mode)'
61
+ },
62
+ captureAfterReload: {
63
+ type: 'boolean',
64
+ description: 'Capture visual snapshot after reload (default: true)'
65
+ },
66
+ verifyChanges: {
67
+ type: 'boolean',
68
+ description: 'Verify changes via visual diff (default: false, expensive)'
69
+ }
70
+ },
71
+ required: ['sandboxId', 'file', 'content']
72
+ };
73
+ super('ModifySandbox', 'ModifySandbox', 'Edit sandbox code with automatic hot reload and visual verification', schema);
74
+ this.sandboxDir = join(config.workingDirectory, '.addon-tools');
75
+ }
76
+ validateToolParams(params) {
77
+ if (!params.sandboxId || params.sandboxId.trim().length === 0) {
78
+ return 'sandboxId is required';
79
+ }
80
+ if (!params.file || params.file.trim().length === 0) {
81
+ return 'file is required';
82
+ }
83
+ // Prevent path traversal
84
+ if (params.file.includes('..') || params.file.startsWith('/')) {
85
+ return 'file must be a relative path within the sandbox (no .. or absolute paths)';
86
+ }
87
+ if (params.content === undefined || params.content === null) {
88
+ return 'content is required (can be empty string for clearing file)';
89
+ }
90
+ return null;
91
+ }
92
+ async execute(params, signal) {
93
+ const startTime = Date.now();
94
+ const validationError = this.validateToolParams(params);
95
+ if (validationError) {
96
+ return this.createErrorResult(validationError);
97
+ }
98
+ try {
99
+ // Get sandbox session
100
+ const session = CreateArtifactToolExecutor.getActiveSandbox(params.sandboxId);
101
+ if (!session) {
102
+ return this.createErrorResult(`Sandbox not found: ${params.sandboxId}. It may have been stopped or never existed.`);
103
+ }
104
+ // Prefer the session's real served/built directory (the workspace). Fall back to the
105
+ // legacy reconstructed path only if the session didn't record one.
106
+ const sandboxPath = session.path || join(this.sandboxDir, params.sandboxId);
107
+ // Verify sandbox directory exists
108
+ try {
109
+ await fs.access(sandboxPath);
110
+ }
111
+ catch {
112
+ return this.createErrorResult(`Sandbox directory not found: ${sandboxPath}`);
113
+ }
114
+ // Capture snapshot before modification (for comparison)
115
+ let snapshotBefore = session.visualSnapshot;
116
+ if (params.verifyChanges && session.url) {
117
+ try {
118
+ await visualBridge.initialize();
119
+ snapshotBefore = await visualBridge.captureSnapshot(session.url);
120
+ }
121
+ catch (error) {
122
+ console.warn('Could not capture before snapshot:', error);
123
+ }
124
+ }
125
+ // Write new file content
126
+ const filePath = join(sandboxPath, params.file);
127
+ await fs.writeFile(filePath, params.content, 'utf-8');
128
+ // Emit file changed event
129
+ broadcaster.emitFileChange(params.sandboxId, params.file, 'modified');
130
+ // React bundled artifacts: re-run esbuild so the served bundle reflects the edit
131
+ // (the static http-server has no process to hot-reload). No-op for CDN/non-React.
132
+ let reactRebuilt = false;
133
+ const rebuild = await rebuildReactBundle(sandboxPath);
134
+ if (rebuild.rebuilt) {
135
+ reactRebuilt = true;
136
+ broadcaster.emitHotReload(params.sandboxId, params.file);
137
+ }
138
+ else if (rebuild.error) {
139
+ console.warn(`[ModifySandbox] React re-bundle failed: ${rebuild.error}`);
140
+ }
141
+ // Determine if we should wait for reload
142
+ const waitForReload = params.waitForReload ?? (session.mode === 'dev');
143
+ const captureAfterReload = params.captureAfterReload ?? true;
144
+ let snapshotAfter = null;
145
+ let reloadWaitTime = 0;
146
+ if (waitForReload) {
147
+ // Wait for hot reload to complete
148
+ // Hot reload typically takes:
149
+ // - 100-500ms to detect file change
150
+ // - 1-2s to restart process
151
+ // - 500ms for server to be ready
152
+ reloadWaitTime = 3000; // 3 seconds total
153
+ await this.wait(reloadWaitTime);
154
+ // Capture snapshot after reload
155
+ if (captureAfterReload && session.url) {
156
+ try {
157
+ await visualBridge.initialize();
158
+ snapshotAfter = await visualBridge.captureSnapshot(session.url);
159
+ session.visualSnapshot = snapshotAfter;
160
+ session.lastActivity = new Date();
161
+ // Emit screenshot captured event
162
+ broadcaster.emitScreenshot(params.sandboxId, snapshotAfter.screenshot, session.url);
163
+ }
164
+ catch (error) {
165
+ console.warn('Could not capture after snapshot:', error);
166
+ broadcaster.emitError(params.sandboxId, error);
167
+ }
168
+ }
169
+ }
170
+ // Compute visual diff if requested
171
+ let visualDiff = null;
172
+ if (params.verifyChanges && snapshotBefore && snapshotAfter) {
173
+ // TODO: Implement getVisualDiff in VisualFeedbackBridge
174
+ // For now, skip visual diff
175
+ console.warn('Visual diff not yet implemented');
176
+ }
177
+ // Format output
178
+ const output = this.formatModificationOutput(session, params, snapshotAfter, visualDiff, reloadWaitTime, reactRebuilt);
179
+ return {
180
+ ...this.createSuccessResult(output),
181
+ metadata: {
182
+ executionTime: Date.now() - startTime,
183
+ sandboxId: params.sandboxId,
184
+ fileModified: params.file,
185
+ bytesWritten: params.content.length,
186
+ waitedForReload: waitForReload,
187
+ reloadWaitTime,
188
+ capturedSnapshot: !!snapshotAfter,
189
+ hasVisualDiff: !!visualDiff,
190
+ reactRebuilt
191
+ }
192
+ };
193
+ }
194
+ catch (error) {
195
+ return this.createErrorResult(`Failed to modify sandbox: ${error.message}`);
196
+ }
197
+ }
198
+ /**
199
+ * Wait helper
200
+ */
201
+ wait(ms) {
202
+ return new Promise(resolve => setTimeout(resolve, ms));
203
+ }
204
+ /**
205
+ * Format modification output for model consumption
206
+ */
207
+ formatModificationOutput(session, params, snapshotAfter, visualDiff, reloadWaitTime, reactRebuilt) {
208
+ const lines = [];
209
+ lines.push(`# ✏ Sandbox Modified: ${session.name}`);
210
+ lines.push('');
211
+ lines.push(`**Sandbox ID**: ${session.id}`);
212
+ lines.push(`**File Modified**: ${params.file}`);
213
+ lines.push(`**Bytes Written**: ${params.content.length}`);
214
+ lines.push('');
215
+ if (reactRebuilt) {
216
+ lines.push('## React Re-bundle');
217
+ lines.push('');
218
+ lines.push('[OK] esbuild re-bundled the React source; the served bundle now reflects your edit.');
219
+ lines.push('');
220
+ }
221
+ if (params.waitForReload) {
222
+ lines.push('## Hot Reload');
223
+ lines.push('');
224
+ lines.push(`[OK] Waited ${reloadWaitTime}ms for hot reload to complete`);
225
+ lines.push('[OK] Process restarted automatically');
226
+ lines.push('');
227
+ }
228
+ if (snapshotAfter) {
229
+ lines.push('---');
230
+ lines.push('');
231
+ lines.push('## Visual State After Modification');
232
+ lines.push('');
233
+ lines.push(visualBridge.formatForModel(snapshotAfter));
234
+ lines.push('');
235
+ }
236
+ if (visualDiff) {
237
+ lines.push('---');
238
+ lines.push('');
239
+ lines.push('## Visual Diff');
240
+ lines.push('');
241
+ lines.push(`**Changes Detected**: ${visualDiff.hasChanges ? 'Yes' : 'No'}`);
242
+ if (visualDiff.hasChanges) {
243
+ lines.push('');
244
+ lines.push('**What Changed**:');
245
+ if (visualDiff.domDiff) {
246
+ lines.push(`- DOM: ${visualDiff.domDiff.added || 0} additions, ${visualDiff.domDiff.removed || 0} removals`);
247
+ }
248
+ if (visualDiff.screenshotDiff) {
249
+ lines.push(`- Visual: ${visualDiff.screenshotDiff.percentDiff}% pixels changed`);
250
+ }
251
+ }
252
+ lines.push('');
253
+ }
254
+ lines.push('---');
255
+ lines.push('');
256
+ lines.push('**Status**: File successfully modified');
257
+ lines.push('');
258
+ lines.push('**Next Steps**:');
259
+ lines.push('- Verify changes look correct in visual snapshot above');
260
+ lines.push('- Test functionality (Use InteractWithSandbox)');
261
+ lines.push('- Continue editing if needed (Call ModifySandbox again)');
262
+ lines.push('- Inspect detailed state (Use InspectSandbox)');
263
+ return lines.join('\n');
264
+ }
265
+ }
266
+ //# sourceMappingURL=ModifySandboxTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModifySandboxTool.js","sourceRoot":"","sources":["../../../src/implementations/addon/ModifySandboxTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD,OAAO,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8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AC,IAAI,CAAC,gDAAgD,CAAC,CAAC;QAC7D,KAAK,CAAC,IAAI,CAAC,yDAAyD,CAAC,CAAC;QACtE,KAAK,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;QAE5D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,27 @@
1
+ export interface ReactBuildOptions {
2
+ /** The user's entry component source. Should define (or default-export) `App`. */
3
+ code: string;
4
+ /** Extra source modules for bundled mode, e.g. { path: 'components/Button.tsx', code }. */
5
+ additionalFiles?: Array<{
6
+ path: string;
7
+ code: string;
8
+ }>;
9
+ /** Force a mode. Default: 'bundled' if esbuild is installed, else 'cdn'. */
10
+ reactMode?: 'cdn' | 'bundled';
11
+ /** Pin the CDN React version (cdn mode). Default 18. */
12
+ cdnReactVersion?: string;
13
+ }
14
+ export interface ReactBuildResult {
15
+ mode: 'cdn' | 'bundled';
16
+ warnings: string[];
17
+ }
18
+ export declare function buildReactArtifact(artifactPath: string, opts: ReactBuildOptions): Promise<ReactBuildResult>;
19
+ /**
20
+ * Re-bundle a bundled React artifact after a source edit (Phase 3). No-op for CDN or
21
+ * non-React artifacts. Returns whether a bundle was produced.
22
+ */
23
+ export declare function rebuildReactBundle(artifactPath: string): Promise<{
24
+ rebuilt: boolean;
25
+ error?: string;
26
+ }>;
27
+ //# sourceMappingURL=ReactArtifactBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactArtifactBuilder.d.ts","sourceRoot":"","sources":["../../../src/implementations/addon/ReactArtifactBuilder.ts"],"names":[],"mappings":"AAoBA,MAAM,WAAW,iBAAiB;IAChC,kFAAkF;IAClF,IAAI,EAAE,MAAM,CAAC;IACb,2FAA2F;IAC3F,eAAe,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,4EAA4E;IAC5E,SAAS,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC9B,wDAAwD;IACxD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,SAAS,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAgCD,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,gBAAgB,CAAC,CAqB3B;AAoFD;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAe/C"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * React artifact builder — turns a user component into a static directory served by
3
+ * the existing http-server path. Two modes (react_artifact_templates_plan.md):
4
+ *
5
+ * - 'cdn' : single index.html, React dev UMD + @babel/standalone, JSX compiled in the
6
+ * browser with development:true so React records _debugSource (scan/grab see
7
+ * componentName + props + a sourceLocation of `App.tsx:line`). Zero deps.
8
+ * - 'bundled' : esbuild bundles src/* (react/react-dom resolved from THIS package — no
9
+ * per-artifact npm install) with real source maps + jsxDev, so grab's
10
+ * sourceLocation points at real `src/App.tsx:line:col`. Optional dep; falls
11
+ * back to 'cdn' when esbuild is unavailable.
12
+ *
13
+ * Both write index.html and let CreateArtifactTool serve via `npx http-server`.
14
+ */
15
+ import { promises as fs } from 'fs';
16
+ import { join, dirname } from 'path';
17
+ import { createRequire } from 'module';
18
+ const require_ = createRequire(import.meta.url);
19
+ /** Ensure the entry source default-exports an `App` (idempotent). */
20
+ function ensureDefaultExport(code) {
21
+ if (/export\s+default/.test(code))
22
+ return code;
23
+ if (/(?:function|const|let|class)\s+App\b/.test(code)) {
24
+ return `${code}\nexport default App;\n`;
25
+ }
26
+ return code; // user wrote their own structure; leave as-is
27
+ }
28
+ /** CDN mode: strip module syntax React can't run inline (imports of react / export kw). */
29
+ function stripForInlineScript(code) {
30
+ return code
31
+ .replace(/^\s*import\s+[^;]*?from\s+['"]react(?:-dom)?(?:\/[^'"]*)?['"];?\s*$/gm, '')
32
+ .replace(/^\s*export\s+default\s+function\b/gm, 'function')
33
+ .replace(/^\s*export\s+default\s+class\b/gm, 'class')
34
+ .replace(/^\s*export\s+default\s+/gm, 'const __default = ')
35
+ .replace(/^\s*export\s+/gm, '');
36
+ }
37
+ function isBundledAvailable() {
38
+ try {
39
+ require_.resolve('esbuild');
40
+ require_.resolve('react');
41
+ require_.resolve('react-dom');
42
+ return true;
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
48
+ export async function buildReactArtifact(artifactPath, opts) {
49
+ const warnings = [];
50
+ let mode = opts.reactMode ?? (isBundledAvailable() ? 'bundled' : 'cdn');
51
+ if (mode === 'bundled' && !isBundledAvailable()) {
52
+ warnings.push('Bundled mode requested but esbuild/react not installed — falling back to CDN mode.');
53
+ mode = 'cdn';
54
+ }
55
+ if (mode === 'bundled') {
56
+ try {
57
+ await buildBundled(artifactPath, opts);
58
+ return { mode: 'bundled', warnings };
59
+ }
60
+ catch (err) {
61
+ warnings.push(`esbuild bundle failed (${err.message}); falling back to CDN mode.`);
62
+ mode = 'cdn';
63
+ }
64
+ }
65
+ await buildCdn(artifactPath, opts, warnings);
66
+ return { mode: 'cdn', warnings };
67
+ }
68
+ async function buildCdn(artifactPath, opts, warnings) {
69
+ if (opts.additionalFiles?.length) {
70
+ warnings.push('additionalFiles are ignored in CDN mode — use bundled mode for multi-file artifacts.');
71
+ }
72
+ const version = opts.cdnReactVersion ?? '18';
73
+ const userSource = stripForInlineScript(ensureDefaultExport(opts.code));
74
+ // Keep the user source verbatim in a non-executing block; a bootstrap compiles it with
75
+ // @babel/standalone using development:true (records JSX _debugSource), then renders <App/>.
76
+ const html = `<!DOCTYPE html>
77
+ <html lang="en">
78
+ <head>
79
+ <meta charset="UTF-8" />
80
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
81
+ <title>React Artifact</title>
82
+ <script crossorigin src="https://unpkg.com/react@${version}/umd/react.development.js"></script>
83
+ <script crossorigin src="https://unpkg.com/react-dom@${version}/umd/react-dom.development.js"></script>
84
+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
85
+ </head>
86
+ <body>
87
+ <div id="root"></div>
88
+ <script type="text/plain" id="cortex-app-source">${escapeForScript(userSource)}</script>
89
+ <script>
90
+ (function () {
91
+ try {
92
+ var src = document.getElementById('cortex-app-source').textContent;
93
+ var out = Babel.transform(src, {
94
+ presets: [['react', { development: true }], 'typescript'],
95
+ filename: 'App.tsx'
96
+ }).code;
97
+ // Indirect eval -> global scope, so 'App' is reachable by the render call below.
98
+ (0, eval)(out);
99
+ var Root = (typeof App !== 'undefined') ? App
100
+ : (typeof __default !== 'undefined') ? __default : null;
101
+ if (!Root) throw new Error('No App component found. Name your component "App" or default-export it.');
102
+ ReactDOM.createRoot(document.getElementById('root')).render(React.createElement(Root));
103
+ } catch (e) {
104
+ document.getElementById('root').innerHTML =
105
+ '<pre style="color:#c00;white-space:pre-wrap">React artifact error:\\n' +
106
+ String(e && e.message || e) + '</pre>';
107
+ console.error('[react-artifact]', e);
108
+ }
109
+ })();
110
+ </script>
111
+ </body>
112
+ </html>
113
+ `;
114
+ await fs.writeFile(join(artifactPath, 'index.html'), html);
115
+ }
116
+ /** Re-run esbuild for an already-scaffolded bundled artifact (src/main.tsx present). */
117
+ async function runEsbuild(artifactPath) {
118
+ const esbuild = require_('esbuild');
119
+ // Resolve react/react-dom from THIS package's node_modules — never per-artifact install.
120
+ const reactDir = dirname(require_.resolve('react/package.json'));
121
+ const reactDomDir = dirname(require_.resolve('react-dom/package.json'));
122
+ const reactNodeModules = join(reactDir, '..');
123
+ await esbuild.build({
124
+ entryPoints: [join(artifactPath, 'src', 'main.tsx')],
125
+ bundle: true,
126
+ outfile: join(artifactPath, 'dist', 'bundle.js'),
127
+ sourcemap: true, // dist/bundle.js.map references src/*.tsx
128
+ jsx: 'automatic',
129
+ jsxDev: true, // emit jsxDEV(...) with __source -> grab.sourceLocation
130
+ format: 'iife',
131
+ target: 'es2020',
132
+ define: { 'process.env.NODE_ENV': '"development"' },
133
+ nodePaths: [reactNodeModules], // bare 'react'/'react-dom' resolve here
134
+ // Dedup React: when the artifact builds INSIDE a monorepo, esbuild's upward
135
+ // node_modules walk can resolve the user's `import 'react'` and react-dom's internal
136
+ // `react` to DIFFERENT copies -> "Invalid hook call (more than one copy of React)" ->
137
+ // <App> crashes and #root stays empty (react-dom still registers a renderer, so detect
138
+ // reports react:true). Pin every react/react-dom (and subpaths) to ONE resolved dir.
139
+ alias: { 'react': reactDir, 'react-dom': reactDomDir },
140
+ logLevel: 'silent'
141
+ });
142
+ }
143
+ /**
144
+ * Re-bundle a bundled React artifact after a source edit (Phase 3). No-op for CDN or
145
+ * non-React artifacts. Returns whether a bundle was produced.
146
+ */
147
+ export async function rebuildReactBundle(artifactPath) {
148
+ try {
149
+ await fs.access(join(artifactPath, 'src', 'main.tsx'));
150
+ }
151
+ catch {
152
+ return { rebuilt: false }; // not a bundled React artifact
153
+ }
154
+ if (!isBundledAvailable()) {
155
+ return { rebuilt: false, error: 'esbuild not available' };
156
+ }
157
+ try {
158
+ await runEsbuild(artifactPath);
159
+ return { rebuilt: true };
160
+ }
161
+ catch (err) {
162
+ return { rebuilt: false, error: err.message };
163
+ }
164
+ }
165
+ async function buildBundled(artifactPath, opts) {
166
+ const srcDir = join(artifactPath, 'src');
167
+ await fs.mkdir(srcDir, { recursive: true });
168
+ await fs.writeFile(join(srcDir, 'App.tsx'), ensureDefaultExport(opts.code));
169
+ await fs.writeFile(join(srcDir, 'main.tsx'), `import { createRoot } from 'react-dom/client';\n` +
170
+ `import App from './App';\n` +
171
+ `const el = document.getElementById('root');\n` +
172
+ `if (el) createRoot(el).render(<App />);\n`);
173
+ for (const f of opts.additionalFiles ?? []) {
174
+ const dest = join(srcDir, f.path);
175
+ await fs.mkdir(dirname(dest), { recursive: true });
176
+ await fs.writeFile(dest, f.code);
177
+ }
178
+ await runEsbuild(artifactPath);
179
+ const html = `<!DOCTYPE html>
180
+ <html lang="en">
181
+ <head>
182
+ <meta charset="UTF-8" />
183
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
184
+ <title>React Artifact</title>
185
+ </head>
186
+ <body>
187
+ <div id="root"></div>
188
+ <script src="./dist/bundle.js"></script>
189
+ </body>
190
+ </html>
191
+ `;
192
+ await fs.writeFile(join(artifactPath, 'index.html'), html);
193
+ }
194
+ /** Make user source safe inside a <script> block (only </script> can break out). */
195
+ function escapeForScript(code) {
196
+ return code.replace(/<\/script>/gi, '<\\/script>');
197
+ }
198
+ //# sourceMappingURL=ReactArtifactBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactArtifactBuilder.js","sourceRoot":"","sources":["../../../src/implementations/addon/ReactArtifactBuilder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAkBhD,qEAAqE;AACrE,SAAS,mBAAmB,CAAC,IAAY;IACvC,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/C,IAAI,sCAAsC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACtD,OAAO,GAAG,IAAI,yBAAyB,CAAC;IAC1C,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,8CAA8C;AAC7D,CAAC;AAED,2FAA2F;AAC3F,SAAS,oBAAoB,CAAC,IAAY;IACxC,O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
2
+ /**
3
+ * Event types emitted by sandboxes
4
+ */
5
+ export type SandboxEventType = 'sandbox-created' | 'sandbox-started' | 'sandbox-stopped' | 'file-changed' | 'console-log' | 'console-error' | 'console-warn' | 'network-request' | 'network-response' | 'screenshot-captured' | 'interaction-executed' | 'hot-reload-triggered' | 'process-restarted' | 'error-occurred';
6
+ /**
7
+ * Base event structure
8
+ */
9
+ export interface SandboxEvent {
10
+ type: SandboxEventType;
11
+ sandboxId: string;
12
+ timestamp: number;
13
+ data: any;
14
+ }
15
+ /**
16
+ * SandboxEventBroadcaster - Centralized event system for sandbox operations
17
+ *
18
+ * This singleton class provides real-time event broadcasting for all sandbox operations.
19
+ * It enables:
20
+ * - User real-time monitoring via WebSocket connections
21
+ * - Model observability of sandbox state changes
22
+ * - Debugging and audit trails
23
+ * - Multi-sandbox coordination
24
+ *
25
+ * Event Flow:
26
+ * 1. Tool (CreateAddon, Modify, Interact) emits event → broadcaster.emit()
27
+ * 2. Broadcaster stores event in history
28
+ * 3. Broadcaster notifies all listeners (WebSocket, logs, etc.)
29
+ * 4. User sees update in dashboard
30
+ *
31
+ * Example Usage:
32
+ * ```
33
+ * // In CreateAddonToolEnhanced
34
+ * broadcaster.emit({
35
+ * type: 'sandbox-created',
36
+ * sandboxId: session.id,
37
+ * timestamp: Date.now(),
38
+ * data: { name: session.name, url: session.url }
39
+ * });
40
+ *
41
+ * // In SandboxViewServer
42
+ * broadcaster.on('console-log', (event) => {
43
+ * io.to(event.sandboxId).emit('console-log', event.data);
44
+ * });
45
+ * ```
46
+ */
47
+ export declare class SandboxEventBroadcaster extends EventEmitter {
48
+ private static instance;
49
+ /**
50
+ * Event history (last 1000 events per sandbox)
51
+ */
52
+ private eventHistory;
53
+ /**
54
+ * Maximum events to keep per sandbox
55
+ */
56
+ private readonly MAX_EVENTS_PER_SANDBOX;
57
+ private constructor();
58
+ /**
59
+ * Get singleton instance
60
+ */
61
+ static getInstance(): SandboxEventBroadcaster;
62
+ /**
63
+ * Emit a sandbox event
64
+ */
65
+ emitSandboxEvent(event: SandboxEvent): void;
66
+ /**
67
+ * Add event to history
68
+ */
69
+ private addToHistory;
70
+ /**
71
+ * Get event history for a sandbox
72
+ */
73
+ getHistory(sandboxId: string, limit?: number): SandboxEvent[];
74
+ /**
75
+ * Get all sandbox IDs with events
76
+ */
77
+ getActiveSandboxes(): string[];
78
+ /**
79
+ * Clear history for a sandbox
80
+ */
81
+ clearHistory(sandboxId: string): void;
82
+ /**
83
+ * Clear all history
84
+ */
85
+ clearAllHistory(): void;
86
+ /**
87
+ * Helper: Emit console log
88
+ */
89
+ emitConsoleLog(sandboxId: string, level: 'log' | 'error' | 'warn', message: string): void;
90
+ /**
91
+ * Helper: Emit file change
92
+ */
93
+ emitFileChange(sandboxId: string, filePath: string, changeType: 'created' | 'modified' | 'deleted'): void;
94
+ /**
95
+ * Helper: Emit screenshot
96
+ */
97
+ emitScreenshot(sandboxId: string, screenshot: string, url: string): void;
98
+ /**
99
+ * Helper: Emit network request
100
+ */
101
+ emitNetworkRequest(sandboxId: string, method: string, url: string, status?: number): void;
102
+ /**
103
+ * Helper: Emit interaction
104
+ */
105
+ emitInteraction(sandboxId: string, actionType: string, selector?: string, success?: boolean): void;
106
+ /**
107
+ * Helper: Emit hot reload
108
+ */
109
+ emitHotReload(sandboxId: string, fileName: string): void;
110
+ /**
111
+ * Helper: Emit process restart
112
+ */
113
+ emitProcessRestart(sandboxId: string, reason: string): void;
114
+ /**
115
+ * Helper: Emit error
116
+ */
117
+ emitError(sandboxId: string, error: Error | string): void;
118
+ /**
119
+ * Subscribe to all events for a specific sandbox
120
+ */
121
+ subscribeToSandbox(sandboxId: string, callback: (event: SandboxEvent) => void): () => void;
122
+ /**
123
+ * Subscribe to specific event type
124
+ */
125
+ subscribeToEventType(eventType: SandboxEventType, callback: (event: SandboxEvent) => void): () => void;
126
+ /**
127
+ * Subscribe to all events
128
+ */
129
+ subscribeToAll(callback: (event: SandboxEvent) => void): () => void;
130
+ /**
131
+ * Get event statistics
132
+ */
133
+ getStats(): {
134
+ activeSandboxes: number;
135
+ totalEvents: number;
136
+ eventsByType: Record<string, number>;
137
+ };
138
+ }
139
+ /**
140
+ * Export singleton instance
141
+ */
142
+ export declare const broadcaster: SandboxEventBroadcaster;
143
+ //# sourceMappingURL=SandboxEventBroadcaster.d.ts.map