@boxes-dev/dvb-runtime 1.0.297 → 1.0.299

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 (488) hide show
  1. package/dist/bin/.bundle-state.json +2 -2
  2. package/dist/bin/dvb.cjs +6 -6
  3. package/dist/bin/dvbd.cjs +6 -6
  4. package/package.json +7 -5
  5. package/dist/devbox/auth.d.ts +0 -22
  6. package/dist/devbox/auth.d.ts.map +0 -1
  7. package/dist/devbox/auth.js +0 -233
  8. package/dist/devbox/auth.js.map +0 -1
  9. package/dist/devbox/browser.d.ts +0 -19
  10. package/dist/devbox/browser.d.ts.map +0 -1
  11. package/dist/devbox/browser.js +0 -60
  12. package/dist/devbox/browser.js.map +0 -1
  13. package/dist/devbox/cli.d.ts +0 -7
  14. package/dist/devbox/cli.d.ts.map +0 -1
  15. package/dist/devbox/cli.js +0 -124
  16. package/dist/devbox/cli.js.map +0 -1
  17. package/dist/devbox/commandRegistry/args.d.ts +0 -18
  18. package/dist/devbox/commandRegistry/args.d.ts.map +0 -1
  19. package/dist/devbox/commandRegistry/args.js +0 -107
  20. package/dist/devbox/commandRegistry/args.js.map +0 -1
  21. package/dist/devbox/commandRegistry/catalog.d.ts +0 -4
  22. package/dist/devbox/commandRegistry/catalog.d.ts.map +0 -1
  23. package/dist/devbox/commandRegistry/catalog.js +0 -763
  24. package/dist/devbox/commandRegistry/catalog.js.map +0 -1
  25. package/dist/devbox/commandRegistry/dispatch.d.ts +0 -3
  26. package/dist/devbox/commandRegistry/dispatch.d.ts.map +0 -1
  27. package/dist/devbox/commandRegistry/dispatch.js +0 -61
  28. package/dist/devbox/commandRegistry/dispatch.js.map +0 -1
  29. package/dist/devbox/commandRegistry/errors.d.ts +0 -8
  30. package/dist/devbox/commandRegistry/errors.d.ts.map +0 -1
  31. package/dist/devbox/commandRegistry/errors.js +0 -26
  32. package/dist/devbox/commandRegistry/errors.js.map +0 -1
  33. package/dist/devbox/commandRegistry/help.d.ts +0 -5
  34. package/dist/devbox/commandRegistry/help.d.ts.map +0 -1
  35. package/dist/devbox/commandRegistry/help.js +0 -94
  36. package/dist/devbox/commandRegistry/help.js.map +0 -1
  37. package/dist/devbox/commandRegistry/resolve.d.ts +0 -7
  38. package/dist/devbox/commandRegistry/resolve.d.ts.map +0 -1
  39. package/dist/devbox/commandRegistry/resolve.js +0 -32
  40. package/dist/devbox/commandRegistry/resolve.js.map +0 -1
  41. package/dist/devbox/commandRegistry/tab.d.ts +0 -10
  42. package/dist/devbox/commandRegistry/tab.d.ts.map +0 -1
  43. package/dist/devbox/commandRegistry/tab.js +0 -83
  44. package/dist/devbox/commandRegistry/tab.js.map +0 -1
  45. package/dist/devbox/commandRegistry/types.d.ts +0 -32
  46. package/dist/devbox/commandRegistry/types.d.ts.map +0 -1
  47. package/dist/devbox/commandRegistry/types.js +0 -2
  48. package/dist/devbox/commandRegistry/types.js.map +0 -1
  49. package/dist/devbox/commands/agent.d.ts +0 -52
  50. package/dist/devbox/commands/agent.d.ts.map +0 -1
  51. package/dist/devbox/commands/agent.js +0 -397
  52. package/dist/devbox/commands/agent.js.map +0 -1
  53. package/dist/devbox/commands/boxSelect.d.ts +0 -25
  54. package/dist/devbox/commands/boxSelect.d.ts.map +0 -1
  55. package/dist/devbox/commands/boxSelect.js +0 -94
  56. package/dist/devbox/commands/boxSelect.js.map +0 -1
  57. package/dist/devbox/commands/checkpoint.d.ts +0 -9
  58. package/dist/devbox/commands/checkpoint.d.ts.map +0 -1
  59. package/dist/devbox/commands/checkpoint.js +0 -105
  60. package/dist/devbox/commands/checkpoint.js.map +0 -1
  61. package/dist/devbox/commands/commandProvider.d.ts +0 -33
  62. package/dist/devbox/commands/commandProvider.d.ts.map +0 -1
  63. package/dist/devbox/commands/commandProvider.js +0 -156
  64. package/dist/devbox/commands/commandProvider.js.map +0 -1
  65. package/dist/devbox/commands/connect.d.ts +0 -39
  66. package/dist/devbox/commands/connect.d.ts.map +0 -1
  67. package/dist/devbox/commands/connect.js +0 -1367
  68. package/dist/devbox/commands/connect.js.map +0 -1
  69. package/dist/devbox/commands/connectSessionMapping.d.ts +0 -64
  70. package/dist/devbox/commands/connectSessionMapping.d.ts.map +0 -1
  71. package/dist/devbox/commands/connectSessionMapping.js +0 -153
  72. package/dist/devbox/commands/connectSessionMapping.js.map +0 -1
  73. package/dist/devbox/commands/cp.d.ts +0 -60
  74. package/dist/devbox/commands/cp.d.ts.map +0 -1
  75. package/dist/devbox/commands/cp.js +0 -383
  76. package/dist/devbox/commands/cp.js.map +0 -1
  77. package/dist/devbox/commands/daemon.d.ts +0 -4
  78. package/dist/devbox/commands/daemon.d.ts.map +0 -1
  79. package/dist/devbox/commands/daemon.js +0 -49
  80. package/dist/devbox/commands/daemon.js.map +0 -1
  81. package/dist/devbox/commands/destroy.d.ts +0 -2
  82. package/dist/devbox/commands/destroy.d.ts.map +0 -1
  83. package/dist/devbox/commands/destroy.js +0 -204
  84. package/dist/devbox/commands/destroy.js.map +0 -1
  85. package/dist/devbox/commands/destroyE2b.d.ts +0 -22
  86. package/dist/devbox/commands/destroyE2b.d.ts.map +0 -1
  87. package/dist/devbox/commands/destroyE2b.js +0 -12
  88. package/dist/devbox/commands/destroyE2b.js.map +0 -1
  89. package/dist/devbox/commands/destroyLocalState.d.ts +0 -34
  90. package/dist/devbox/commands/destroyLocalState.d.ts.map +0 -1
  91. package/dist/devbox/commands/destroyLocalState.js +0 -187
  92. package/dist/devbox/commands/destroyLocalState.js.map +0 -1
  93. package/dist/devbox/commands/destroyModal.d.ts +0 -21
  94. package/dist/devbox/commands/destroyModal.d.ts.map +0 -1
  95. package/dist/devbox/commands/destroyModal.js +0 -13
  96. package/dist/devbox/commands/destroyModal.js.map +0 -1
  97. package/dist/devbox/commands/destroyShared.d.ts +0 -14
  98. package/dist/devbox/commands/destroyShared.d.ts.map +0 -1
  99. package/dist/devbox/commands/destroyShared.js +0 -37
  100. package/dist/devbox/commands/destroyShared.js.map +0 -1
  101. package/dist/devbox/commands/fork.d.ts +0 -9
  102. package/dist/devbox/commands/fork.d.ts.map +0 -1
  103. package/dist/devbox/commands/fork.js +0 -94
  104. package/dist/devbox/commands/fork.js.map +0 -1
  105. package/dist/devbox/commands/ide.d.ts +0 -35
  106. package/dist/devbox/commands/ide.d.ts.map +0 -1
  107. package/dist/devbox/commands/ide.js +0 -987
  108. package/dist/devbox/commands/ide.js.map +0 -1
  109. package/dist/devbox/commands/init/args.d.ts +0 -18
  110. package/dist/devbox/commands/init/args.d.ts.map +0 -1
  111. package/dist/devbox/commands/init/args.js +0 -44
  112. package/dist/devbox/commands/init/args.js.map +0 -1
  113. package/dist/devbox/commands/init/clack.d.ts +0 -22
  114. package/dist/devbox/commands/init/clack.d.ts.map +0 -1
  115. package/dist/devbox/commands/init/clack.js +0 -158
  116. package/dist/devbox/commands/init/clack.js.map +0 -1
  117. package/dist/devbox/commands/init/claudeBootstrap.d.ts +0 -49
  118. package/dist/devbox/commands/init/claudeBootstrap.d.ts.map +0 -1
  119. package/dist/devbox/commands/init/claudeBootstrap.js +0 -504
  120. package/dist/devbox/commands/init/claudeBootstrap.js.map +0 -1
  121. package/dist/devbox/commands/init/codex/artifacts.d.ts +0 -49
  122. package/dist/devbox/commands/init/codex/artifacts.d.ts.map +0 -1
  123. package/dist/devbox/commands/init/codex/artifacts.js +0 -278
  124. package/dist/devbox/commands/init/codex/artifacts.js.map +0 -1
  125. package/dist/devbox/commands/init/codex/config.d.ts +0 -6
  126. package/dist/devbox/commands/init/codex/config.d.ts.map +0 -1
  127. package/dist/devbox/commands/init/codex/config.js +0 -43
  128. package/dist/devbox/commands/init/codex/config.js.map +0 -1
  129. package/dist/devbox/commands/init/codex/events.d.ts +0 -14
  130. package/dist/devbox/commands/init/codex/events.d.ts.map +0 -1
  131. package/dist/devbox/commands/init/codex/events.js +0 -435
  132. package/dist/devbox/commands/init/codex/events.js.map +0 -1
  133. package/dist/devbox/commands/init/codex/execConfig.d.ts +0 -5
  134. package/dist/devbox/commands/init/codex/execConfig.d.ts.map +0 -1
  135. package/dist/devbox/commands/init/codex/execConfig.js +0 -10
  136. package/dist/devbox/commands/init/codex/execConfig.js.map +0 -1
  137. package/dist/devbox/commands/init/codex/index.d.ts +0 -136
  138. package/dist/devbox/commands/init/codex/index.d.ts.map +0 -1
  139. package/dist/devbox/commands/init/codex/index.js +0 -1115
  140. package/dist/devbox/commands/init/codex/index.js.map +0 -1
  141. package/dist/devbox/commands/init/codex/local.d.ts +0 -124
  142. package/dist/devbox/commands/init/codex/local.d.ts.map +0 -1
  143. package/dist/devbox/commands/init/codex/local.js +0 -1381
  144. package/dist/devbox/commands/init/codex/local.js.map +0 -1
  145. package/dist/devbox/commands/init/codex/localExecArgs.d.ts +0 -25
  146. package/dist/devbox/commands/init/codex/localExecArgs.d.ts.map +0 -1
  147. package/dist/devbox/commands/init/codex/localExecArgs.js +0 -48
  148. package/dist/devbox/commands/init/codex/localExecArgs.js.map +0 -1
  149. package/dist/devbox/commands/init/codex/plan.d.ts +0 -99
  150. package/dist/devbox/commands/init/codex/plan.d.ts.map +0 -1
  151. package/dist/devbox/commands/init/codex/plan.js +0 -231
  152. package/dist/devbox/commands/init/codex/plan.js.map +0 -1
  153. package/dist/devbox/commands/init/codex/prompts.d.ts +0 -9
  154. package/dist/devbox/commands/init/codex/prompts.d.ts.map +0 -1
  155. package/dist/devbox/commands/init/codex/prompts.js +0 -51
  156. package/dist/devbox/commands/init/codex/prompts.js.map +0 -1
  157. package/dist/devbox/commands/init/codex/proxy.d.ts +0 -10
  158. package/dist/devbox/commands/init/codex/proxy.d.ts.map +0 -1
  159. package/dist/devbox/commands/init/codex/proxy.js +0 -32
  160. package/dist/devbox/commands/init/codex/proxy.js.map +0 -1
  161. package/dist/devbox/commands/init/codex/remote.d.ts +0 -96
  162. package/dist/devbox/commands/init/codex/remote.d.ts.map +0 -1
  163. package/dist/devbox/commands/init/codex/remote.js +0 -927
  164. package/dist/devbox/commands/init/codex/remote.js.map +0 -1
  165. package/dist/devbox/commands/init/codex/retry.d.ts +0 -17
  166. package/dist/devbox/commands/init/codex/retry.d.ts.map +0 -1
  167. package/dist/devbox/commands/init/codex/retry.js +0 -17
  168. package/dist/devbox/commands/init/codex/retry.js.map +0 -1
  169. package/dist/devbox/commands/init/codex/scanStatus.d.ts +0 -5
  170. package/dist/devbox/commands/init/codex/scanStatus.d.ts.map +0 -1
  171. package/dist/devbox/commands/init/codex/scanStatus.js +0 -27
  172. package/dist/devbox/commands/init/codex/scanStatus.js.map +0 -1
  173. package/dist/devbox/commands/init/codex/shellHistory.d.ts +0 -39
  174. package/dist/devbox/commands/init/codex/shellHistory.d.ts.map +0 -1
  175. package/dist/devbox/commands/init/codex/shellHistory.js +0 -258
  176. package/dist/devbox/commands/init/codex/shellHistory.js.map +0 -1
  177. package/dist/devbox/commands/init/codex/template.d.ts +0 -3
  178. package/dist/devbox/commands/init/codex/template.d.ts.map +0 -1
  179. package/dist/devbox/commands/init/codex/template.js +0 -3
  180. package/dist/devbox/commands/init/codex/template.js.map +0 -1
  181. package/dist/devbox/commands/init/finalizeFlow.d.ts +0 -95
  182. package/dist/devbox/commands/init/finalizeFlow.d.ts.map +0 -1
  183. package/dist/devbox/commands/init/finalizeFlow.js +0 -786
  184. package/dist/devbox/commands/init/finalizeFlow.js.map +0 -1
  185. package/dist/devbox/commands/init/index.d.ts +0 -11
  186. package/dist/devbox/commands/init/index.d.ts.map +0 -1
  187. package/dist/devbox/commands/init/index.js +0 -1058
  188. package/dist/devbox/commands/init/index.js.map +0 -1
  189. package/dist/devbox/commands/init/modal.d.ts +0 -5
  190. package/dist/devbox/commands/init/modal.d.ts.map +0 -1
  191. package/dist/devbox/commands/init/modal.js +0 -4
  192. package/dist/devbox/commands/init/modal.js.map +0 -1
  193. package/dist/devbox/commands/init/packaging.d.ts +0 -5
  194. package/dist/devbox/commands/init/packaging.d.ts.map +0 -1
  195. package/dist/devbox/commands/init/packaging.js +0 -81
  196. package/dist/devbox/commands/init/packaging.js.map +0 -1
  197. package/dist/devbox/commands/init/progress.d.ts +0 -31
  198. package/dist/devbox/commands/init/progress.d.ts.map +0 -1
  199. package/dist/devbox/commands/init/progress.js +0 -205
  200. package/dist/devbox/commands/init/progress.js.map +0 -1
  201. package/dist/devbox/commands/init/provider/e2b.d.ts +0 -29
  202. package/dist/devbox/commands/init/provider/e2b.d.ts.map +0 -1
  203. package/dist/devbox/commands/init/provider/e2b.js +0 -130
  204. package/dist/devbox/commands/init/provider/e2b.js.map +0 -1
  205. package/dist/devbox/commands/init/provider/e2bRuntime.d.ts +0 -39
  206. package/dist/devbox/commands/init/provider/e2bRuntime.d.ts.map +0 -1
  207. package/dist/devbox/commands/init/provider/e2bRuntime.js +0 -679
  208. package/dist/devbox/commands/init/provider/e2bRuntime.js.map +0 -1
  209. package/dist/devbox/commands/init/provider/index.d.ts +0 -8
  210. package/dist/devbox/commands/init/provider/index.d.ts.map +0 -1
  211. package/dist/devbox/commands/init/provider/index.js +0 -5
  212. package/dist/devbox/commands/init/provider/index.js.map +0 -1
  213. package/dist/devbox/commands/init/provider/modal.d.ts +0 -34
  214. package/dist/devbox/commands/init/provider/modal.d.ts.map +0 -1
  215. package/dist/devbox/commands/init/provider/modal.js +0 -274
  216. package/dist/devbox/commands/init/provider/modal.js.map +0 -1
  217. package/dist/devbox/commands/init/provider/modalRuntime.d.ts +0 -3
  218. package/dist/devbox/commands/init/provider/modalRuntime.d.ts.map +0 -1
  219. package/dist/devbox/commands/init/provider/modalRuntime.js +0 -2
  220. package/dist/devbox/commands/init/provider/modalRuntime.js.map +0 -1
  221. package/dist/devbox/commands/init/provider/resolve.d.ts +0 -44
  222. package/dist/devbox/commands/init/provider/resolve.d.ts.map +0 -1
  223. package/dist/devbox/commands/init/provider/resolve.js +0 -172
  224. package/dist/devbox/commands/init/provider/resolve.js.map +0 -1
  225. package/dist/devbox/commands/init/provider/shared.d.ts +0 -10
  226. package/dist/devbox/commands/init/provider/shared.d.ts.map +0 -1
  227. package/dist/devbox/commands/init/provider/shared.js +0 -2
  228. package/dist/devbox/commands/init/provider/shared.js.map +0 -1
  229. package/dist/devbox/commands/init/provider/sprites.d.ts +0 -30
  230. package/dist/devbox/commands/init/provider/sprites.d.ts.map +0 -1
  231. package/dist/devbox/commands/init/provider/sprites.js +0 -183
  232. package/dist/devbox/commands/init/provider/sprites.js.map +0 -1
  233. package/dist/devbox/commands/init/provider/types.d.ts +0 -19
  234. package/dist/devbox/commands/init/provider/types.d.ts.map +0 -1
  235. package/dist/devbox/commands/init/provider/types.js +0 -2
  236. package/dist/devbox/commands/init/provider/types.js.map +0 -1
  237. package/dist/devbox/commands/init/provisionFlow.d.ts +0 -53
  238. package/dist/devbox/commands/init/provisionFlow.d.ts.map +0 -1
  239. package/dist/devbox/commands/init/provisionFlow.js +0 -541
  240. package/dist/devbox/commands/init/provisionFlow.js.map +0 -1
  241. package/dist/devbox/commands/init/registry.d.ts +0 -15
  242. package/dist/devbox/commands/init/registry.d.ts.map +0 -1
  243. package/dist/devbox/commands/init/registry.js +0 -38
  244. package/dist/devbox/commands/init/registry.js.map +0 -1
  245. package/dist/devbox/commands/init/remote.d.ts +0 -48
  246. package/dist/devbox/commands/init/remote.d.ts.map +0 -1
  247. package/dist/devbox/commands/init/remote.js +0 -766
  248. package/dist/devbox/commands/init/remote.js.map +0 -1
  249. package/dist/devbox/commands/init/repo.d.ts +0 -45
  250. package/dist/devbox/commands/init/repo.d.ts.map +0 -1
  251. package/dist/devbox/commands/init/repo.js +0 -235
  252. package/dist/devbox/commands/init/repo.js.map +0 -1
  253. package/dist/devbox/commands/init/retryableErrors.d.ts +0 -4
  254. package/dist/devbox/commands/init/retryableErrors.d.ts.map +0 -1
  255. package/dist/devbox/commands/init/retryableErrors.js +0 -42
  256. package/dist/devbox/commands/init/retryableErrors.js.map +0 -1
  257. package/dist/devbox/commands/init/scanProgress.d.ts +0 -18
  258. package/dist/devbox/commands/init/scanProgress.d.ts.map +0 -1
  259. package/dist/devbox/commands/init/scanProgress.js +0 -47
  260. package/dist/devbox/commands/init/scanProgress.js.map +0 -1
  261. package/dist/devbox/commands/init/session.d.ts +0 -72
  262. package/dist/devbox/commands/init/session.d.ts.map +0 -1
  263. package/dist/devbox/commands/init/session.js +0 -348
  264. package/dist/devbox/commands/init/session.js.map +0 -1
  265. package/dist/devbox/commands/init/setupArtifactsValidation.d.ts +0 -28
  266. package/dist/devbox/commands/init/setupArtifactsValidation.d.ts.map +0 -1
  267. package/dist/devbox/commands/init/setupArtifactsValidation.js +0 -113
  268. package/dist/devbox/commands/init/setupArtifactsValidation.js.map +0 -1
  269. package/dist/devbox/commands/init/setupPlanFlow.d.ts +0 -34
  270. package/dist/devbox/commands/init/setupPlanFlow.d.ts.map +0 -1
  271. package/dist/devbox/commands/init/setupPlanFlow.js +0 -967
  272. package/dist/devbox/commands/init/setupPlanFlow.js.map +0 -1
  273. package/dist/devbox/commands/init/ssh.d.ts +0 -19
  274. package/dist/devbox/commands/init/ssh.d.ts.map +0 -1
  275. package/dist/devbox/commands/init/ssh.js +0 -276
  276. package/dist/devbox/commands/init/ssh.js.map +0 -1
  277. package/dist/devbox/commands/init/state.d.ts +0 -73
  278. package/dist/devbox/commands/init/state.d.ts.map +0 -1
  279. package/dist/devbox/commands/init/state.js +0 -118
  280. package/dist/devbox/commands/init/state.js.map +0 -1
  281. package/dist/devbox/commands/init/statusFlow.d.ts +0 -27
  282. package/dist/devbox/commands/init/statusFlow.d.ts.map +0 -1
  283. package/dist/devbox/commands/init/statusFlow.js +0 -160
  284. package/dist/devbox/commands/init/statusFlow.js.map +0 -1
  285. package/dist/devbox/commands/list.d.ts +0 -35
  286. package/dist/devbox/commands/list.d.ts.map +0 -1
  287. package/dist/devbox/commands/list.js +0 -311
  288. package/dist/devbox/commands/list.js.map +0 -1
  289. package/dist/devbox/commands/listFormatting.d.ts +0 -27
  290. package/dist/devbox/commands/listFormatting.d.ts.map +0 -1
  291. package/dist/devbox/commands/listFormatting.js +0 -155
  292. package/dist/devbox/commands/listFormatting.js.map +0 -1
  293. package/dist/devbox/commands/logout.d.ts +0 -2
  294. package/dist/devbox/commands/logout.d.ts.map +0 -1
  295. package/dist/devbox/commands/logout.js +0 -64
  296. package/dist/devbox/commands/logout.js.map +0 -1
  297. package/dist/devbox/commands/managedProviderClient.d.ts +0 -24
  298. package/dist/devbox/commands/managedProviderClient.d.ts.map +0 -1
  299. package/dist/devbox/commands/managedProviderClient.js +0 -42
  300. package/dist/devbox/commands/managedProviderClient.js.map +0 -1
  301. package/dist/devbox/commands/managedProviderContext.d.ts +0 -34
  302. package/dist/devbox/commands/managedProviderContext.d.ts.map +0 -1
  303. package/dist/devbox/commands/managedProviderContext.js +0 -34
  304. package/dist/devbox/commands/managedProviderContext.js.map +0 -1
  305. package/dist/devbox/commands/mount.d.ts +0 -25
  306. package/dist/devbox/commands/mount.d.ts.map +0 -1
  307. package/dist/devbox/commands/mount.js +0 -200
  308. package/dist/devbox/commands/mount.js.map +0 -1
  309. package/dist/devbox/commands/ports.d.ts +0 -11
  310. package/dist/devbox/commands/ports.d.ts.map +0 -1
  311. package/dist/devbox/commands/ports.js +0 -183
  312. package/dist/devbox/commands/ports.js.map +0 -1
  313. package/dist/devbox/commands/power.d.ts +0 -10
  314. package/dist/devbox/commands/power.d.ts.map +0 -1
  315. package/dist/devbox/commands/power.js +0 -139
  316. package/dist/devbox/commands/power.js.map +0 -1
  317. package/dist/devbox/commands/provider/daemonRuntimeShared.d.ts +0 -25
  318. package/dist/devbox/commands/provider/daemonRuntimeShared.d.ts.map +0 -1
  319. package/dist/devbox/commands/provider/daemonRuntimeShared.js +0 -217
  320. package/dist/devbox/commands/provider/daemonRuntimeShared.js.map +0 -1
  321. package/dist/devbox/commands/provider/directDaemonRuntime.d.ts +0 -106
  322. package/dist/devbox/commands/provider/directDaemonRuntime.d.ts.map +0 -1
  323. package/dist/devbox/commands/provider/directDaemonRuntime.js +0 -1442
  324. package/dist/devbox/commands/provider/directDaemonRuntime.js.map +0 -1
  325. package/dist/devbox/commands/provider/e2bCommandContext.d.ts +0 -11
  326. package/dist/devbox/commands/provider/e2bCommandContext.d.ts.map +0 -1
  327. package/dist/devbox/commands/provider/e2bCommandContext.js +0 -16
  328. package/dist/devbox/commands/provider/e2bCommandContext.js.map +0 -1
  329. package/dist/devbox/commands/provider/e2bLifecycleShared.d.ts +0 -20
  330. package/dist/devbox/commands/provider/e2bLifecycleShared.d.ts.map +0 -1
  331. package/dist/devbox/commands/provider/e2bLifecycleShared.js +0 -42
  332. package/dist/devbox/commands/provider/e2bLifecycleShared.js.map +0 -1
  333. package/dist/devbox/commands/provider/modalCommandContext.d.ts +0 -22
  334. package/dist/devbox/commands/provider/modalCommandContext.d.ts.map +0 -1
  335. package/dist/devbox/commands/provider/modalCommandContext.js +0 -47
  336. package/dist/devbox/commands/provider/modalCommandContext.js.map +0 -1
  337. package/dist/devbox/commands/provider/modalLifecycle.d.ts +0 -158
  338. package/dist/devbox/commands/provider/modalLifecycle.d.ts.map +0 -1
  339. package/dist/devbox/commands/provider/modalLifecycle.js +0 -702
  340. package/dist/devbox/commands/provider/modalLifecycle.js.map +0 -1
  341. package/dist/devbox/commands/provider/modalRuntime.d.ts +0 -25
  342. package/dist/devbox/commands/provider/modalRuntime.d.ts.map +0 -1
  343. package/dist/devbox/commands/provider/modalRuntime.js +0 -791
  344. package/dist/devbox/commands/provider/modalRuntime.js.map +0 -1
  345. package/dist/devbox/commands/provider/runtimeTypes.d.ts +0 -8
  346. package/dist/devbox/commands/provider/runtimeTypes.d.ts.map +0 -1
  347. package/dist/devbox/commands/provider/runtimeTypes.js +0 -2
  348. package/dist/devbox/commands/provider/runtimeTypes.js.map +0 -1
  349. package/dist/devbox/commands/providerClient.d.ts +0 -82
  350. package/dist/devbox/commands/providerClient.d.ts.map +0 -1
  351. package/dist/devbox/commands/providerClient.js +0 -719
  352. package/dist/devbox/commands/providerClient.js.map +0 -1
  353. package/dist/devbox/commands/reboot.d.ts +0 -8
  354. package/dist/devbox/commands/reboot.d.ts.map +0 -1
  355. package/dist/devbox/commands/reboot.js +0 -100
  356. package/dist/devbox/commands/reboot.js.map +0 -1
  357. package/dist/devbox/commands/reset.d.ts +0 -30
  358. package/dist/devbox/commands/reset.d.ts.map +0 -1
  359. package/dist/devbox/commands/reset.js +0 -114
  360. package/dist/devbox/commands/reset.js.map +0 -1
  361. package/dist/devbox/commands/runtimeClient.d.ts +0 -65
  362. package/dist/devbox/commands/runtimeClient.d.ts.map +0 -1
  363. package/dist/devbox/commands/runtimeClient.js +0 -127
  364. package/dist/devbox/commands/runtimeClient.js.map +0 -1
  365. package/dist/devbox/commands/sentryTest.d.ts +0 -2
  366. package/dist/devbox/commands/sentryTest.d.ts.map +0 -1
  367. package/dist/devbox/commands/sentryTest.js +0 -117
  368. package/dist/devbox/commands/sentryTest.js.map +0 -1
  369. package/dist/devbox/commands/services.d.ts +0 -2
  370. package/dist/devbox/commands/services.d.ts.map +0 -1
  371. package/dist/devbox/commands/services.js +0 -619
  372. package/dist/devbox/commands/services.js.map +0 -1
  373. package/dist/devbox/commands/servicesConfig.d.ts +0 -19
  374. package/dist/devbox/commands/servicesConfig.d.ts.map +0 -1
  375. package/dist/devbox/commands/servicesConfig.js +0 -61
  376. package/dist/devbox/commands/servicesConfig.js.map +0 -1
  377. package/dist/devbox/commands/servicesToml.d.ts +0 -13
  378. package/dist/devbox/commands/servicesToml.d.ts.map +0 -1
  379. package/dist/devbox/commands/servicesToml.js +0 -201
  380. package/dist/devbox/commands/servicesToml.js.map +0 -1
  381. package/dist/devbox/commands/sessionUtils.d.ts +0 -10
  382. package/dist/devbox/commands/sessionUtils.d.ts.map +0 -1
  383. package/dist/devbox/commands/sessionUtils.js +0 -48
  384. package/dist/devbox/commands/sessionUtils.js.map +0 -1
  385. package/dist/devbox/commands/sessions.d.ts +0 -3
  386. package/dist/devbox/commands/sessions.d.ts.map +0 -1
  387. package/dist/devbox/commands/sessions.js +0 -490
  388. package/dist/devbox/commands/sessions.js.map +0 -1
  389. package/dist/devbox/commands/setup.d.ts +0 -36
  390. package/dist/devbox/commands/setup.d.ts.map +0 -1
  391. package/dist/devbox/commands/setup.js +0 -816
  392. package/dist/devbox/commands/setup.js.map +0 -1
  393. package/dist/devbox/commands/setupClaude.d.ts +0 -51
  394. package/dist/devbox/commands/setupClaude.d.ts.map +0 -1
  395. package/dist/devbox/commands/setupClaude.js +0 -202
  396. package/dist/devbox/commands/setupClaude.js.map +0 -1
  397. package/dist/devbox/commands/setupTooling.d.ts +0 -56
  398. package/dist/devbox/commands/setupTooling.d.ts.map +0 -1
  399. package/dist/devbox/commands/setupTooling.js +0 -187
  400. package/dist/devbox/commands/setupTooling.js.map +0 -1
  401. package/dist/devbox/commands/sshAccess.d.ts +0 -31
  402. package/dist/devbox/commands/sshAccess.d.ts.map +0 -1
  403. package/dist/devbox/commands/sshAccess.js +0 -353
  404. package/dist/devbox/commands/sshAccess.js.map +0 -1
  405. package/dist/devbox/commands/sshConfig.d.ts +0 -23
  406. package/dist/devbox/commands/sshConfig.d.ts.map +0 -1
  407. package/dist/devbox/commands/sshConfig.js +0 -366
  408. package/dist/devbox/commands/sshConfig.js.map +0 -1
  409. package/dist/devbox/commands/sshProxy.d.ts +0 -2
  410. package/dist/devbox/commands/sshProxy.d.ts.map +0 -1
  411. package/dist/devbox/commands/sshProxy.js +0 -215
  412. package/dist/devbox/commands/sshProxy.js.map +0 -1
  413. package/dist/devbox/commands/uninstall.d.ts +0 -2
  414. package/dist/devbox/commands/uninstall.d.ts.map +0 -1
  415. package/dist/devbox/commands/uninstall.js +0 -365
  416. package/dist/devbox/commands/uninstall.js.map +0 -1
  417. package/dist/devbox/commands/upgrade.d.ts +0 -14
  418. package/dist/devbox/commands/upgrade.d.ts.map +0 -1
  419. package/dist/devbox/commands/upgrade.js +0 -60
  420. package/dist/devbox/commands/upgrade.js.map +0 -1
  421. package/dist/devbox/commands/version.d.ts +0 -8
  422. package/dist/devbox/commands/version.d.ts.map +0 -1
  423. package/dist/devbox/commands/version.js +0 -134
  424. package/dist/devbox/commands/version.js.map +0 -1
  425. package/dist/devbox/commands/whoami.d.ts +0 -2
  426. package/dist/devbox/commands/whoami.d.ts.map +0 -1
  427. package/dist/devbox/commands/whoami.js +0 -114
  428. package/dist/devbox/commands/whoami.js.map +0 -1
  429. package/dist/devbox/completions/cache.d.ts +0 -53
  430. package/dist/devbox/completions/cache.d.ts.map +0 -1
  431. package/dist/devbox/completions/cache.js +0 -227
  432. package/dist/devbox/completions/cache.js.map +0 -1
  433. package/dist/devbox/completions/index.d.ts +0 -18
  434. package/dist/devbox/completions/index.d.ts.map +0 -1
  435. package/dist/devbox/completions/index.js +0 -759
  436. package/dist/devbox/completions/index.js.map +0 -1
  437. package/dist/devbox/controlPlane.d.ts +0 -460
  438. package/dist/devbox/controlPlane.d.ts.map +0 -1
  439. package/dist/devbox/controlPlane.js +0 -1910
  440. package/dist/devbox/controlPlane.js.map +0 -1
  441. package/dist/devbox/daemonClient.d.ts +0 -44
  442. package/dist/devbox/daemonClient.d.ts.map +0 -1
  443. package/dist/devbox/daemonClient.js +0 -677
  444. package/dist/devbox/daemonClient.js.map +0 -1
  445. package/dist/devbox/e2bExecErrors.d.ts +0 -11
  446. package/dist/devbox/e2bExecErrors.d.ts.map +0 -1
  447. package/dist/devbox/e2bExecErrors.js +0 -19
  448. package/dist/devbox/e2bExecErrors.js.map +0 -1
  449. package/dist/devbox/latency.d.ts +0 -25
  450. package/dist/devbox/latency.d.ts.map +0 -1
  451. package/dist/devbox/latency.js +0 -186
  452. package/dist/devbox/latency.js.map +0 -1
  453. package/dist/devbox/logger.d.ts +0 -2
  454. package/dist/devbox/logger.d.ts.map +0 -1
  455. package/dist/devbox/logger.js +0 -3
  456. package/dist/devbox/logger.js.map +0 -1
  457. package/dist/devbox/terminal/kittyCtrlCReleaseSuppressor.d.ts +0 -11
  458. package/dist/devbox/terminal/kittyCtrlCReleaseSuppressor.d.ts.map +0 -1
  459. package/dist/devbox/terminal/kittyCtrlCReleaseSuppressor.js +0 -118
  460. package/dist/devbox/terminal/kittyCtrlCReleaseSuppressor.js.map +0 -1
  461. package/dist/devbox/terminal/osc.d.ts +0 -11
  462. package/dist/devbox/terminal/osc.d.ts.map +0 -1
  463. package/dist/devbox/terminal/osc.js +0 -84
  464. package/dist/devbox/terminal/osc.js.map +0 -1
  465. package/dist/devbox/terminal/sessionProtocol.d.ts +0 -46
  466. package/dist/devbox/terminal/sessionProtocol.d.ts.map +0 -1
  467. package/dist/devbox/terminal/sessionProtocol.js +0 -631
  468. package/dist/devbox/terminal/sessionProtocol.js.map +0 -1
  469. package/dist/devbox/ui/colors.d.ts +0 -19
  470. package/dist/devbox/ui/colors.d.ts.map +0 -1
  471. package/dist/devbox/ui/colors.js +0 -22
  472. package/dist/devbox/ui/colors.js.map +0 -1
  473. package/dist/devbox/ui/copyableUrl.d.ts +0 -4
  474. package/dist/devbox/ui/copyableUrl.d.ts.map +0 -1
  475. package/dist/devbox/ui/copyableUrl.js +0 -10
  476. package/dist/devbox/ui/copyableUrl.js.map +0 -1
  477. package/dist/devbox/ui/qr.d.ts +0 -3
  478. package/dist/devbox/ui/qr.d.ts.map +0 -1
  479. package/dist/devbox/ui/qr.js +0 -17
  480. package/dist/devbox/ui/qr.js.map +0 -1
  481. package/dist/devbox/ui/statusLine.d.ts +0 -14
  482. package/dist/devbox/ui/statusLine.d.ts.map +0 -1
  483. package/dist/devbox/ui/statusLine.js +0 -92
  484. package/dist/devbox/ui/statusLine.js.map +0 -1
  485. package/dist/devbox/updateNotice.d.ts +0 -2
  486. package/dist/devbox/updateNotice.d.ts.map +0 -1
  487. package/dist/devbox/updateNotice.js +0 -43
  488. package/dist/devbox/updateNotice.js.map +0 -1
@@ -1,1442 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import WebSocket from "ws";
3
- import { buildControlAuthMessage, CONTROL_TTY_REPLACED_CLOSE_CODE, CONTROL_TTY_REPLACED_ERROR_CODE, createLogger, findMissingTtyControlCapabilities, parseControlReadyMessage, TTY_CONTROL_PROTOCOL_VERSION, } from "@boxes-dev/core";
4
- import { parseDaemonControlError, parseDaemonJsonRecord, } from "./daemonRuntimeShared.js";
5
- const DIRECT_DAEMON_CONTROL_WS_PATH = "/ws";
6
- const MANAGED_DAEMON_CONNECT_TOKEN_QUERY = "_modal_connect_token";
7
- const DIRECT_DAEMON_CONTROL_IDLE_MS = 15 * 60 * 1000;
8
- const DIRECT_DAEMON_CONTROL_CONNECT_TIMEOUT_PADDING_MS = 10_000;
9
- const DIRECT_DAEMON_CONTROL_CONNECT_TIMEOUT_MIN_MS = 25_000;
10
- const DIRECT_DAEMON_CONTROL_CONNECT_TIMEOUT_MAX_MS = 120_000;
11
- const DIRECT_DAEMON_CONTROL_CONNECT_RETRY_INITIAL_DELAY_MS = 250;
12
- const DIRECT_DAEMON_CONTROL_CONNECT_RETRY_MAX_DELAY_MS = 2_000;
13
- const DIRECT_DAEMON_CONTROL_PING_INTERVAL_MS = 20_000;
14
- const DIRECT_DAEMON_CONTROL_PONG_GRACE_MS = 45_000;
15
- const DIRECT_DAEMON_REQUEST_TRANSPORT_RETRY_LIMIT = 1;
16
- const logger = createLogger("direct_daemon_runtime");
17
- const DEFAULT_DIRECT_DAEMON_CONTROL_TIMING = {
18
- idleMs: DIRECT_DAEMON_CONTROL_IDLE_MS,
19
- connectTimeoutPaddingMs: DIRECT_DAEMON_CONTROL_CONNECT_TIMEOUT_PADDING_MS,
20
- connectTimeoutMinMs: DIRECT_DAEMON_CONTROL_CONNECT_TIMEOUT_MIN_MS,
21
- connectTimeoutMaxMs: DIRECT_DAEMON_CONTROL_CONNECT_TIMEOUT_MAX_MS,
22
- connectRetryInitialDelayMs: DIRECT_DAEMON_CONTROL_CONNECT_RETRY_INITIAL_DELAY_MS,
23
- connectRetryMaxDelayMs: DIRECT_DAEMON_CONTROL_CONNECT_RETRY_MAX_DELAY_MS,
24
- pingIntervalMs: DIRECT_DAEMON_CONTROL_PING_INTERVAL_MS,
25
- pongGraceMs: DIRECT_DAEMON_CONTROL_PONG_GRACE_MS,
26
- };
27
- let directDaemonControlTimingOverrides = null;
28
- const formatProviderLabel = (provider) => provider === "e2b" ? "E2B" : "Modal";
29
- const resolveDirectDaemonRequestType = (requestPayload) => typeof requestPayload.type === "string" ? requestPayload.type : "unknown";
30
- const DIRECT_DAEMON_REPLAY_SAFE_REQUEST_TYPES = new Set([
31
- "fs_read",
32
- "services_list",
33
- "service_get",
34
- "sessions_list",
35
- ]);
36
- const isDirectDaemonReplaySafeRequest = (requestPayload) => DIRECT_DAEMON_REPLAY_SAFE_REQUEST_TYPES.has(resolveDirectDaemonRequestType(requestPayload));
37
- const buildDirectDaemonWsUrl = (connectInfo) => {
38
- const url = new URL(connectInfo.url);
39
- url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
40
- url.pathname = DIRECT_DAEMON_CONTROL_WS_PATH;
41
- url.search = "";
42
- if (connectInfo.provider === "modal") {
43
- url.searchParams.set(MANAGED_DAEMON_CONNECT_TOKEN_QUERY, connectInfo.connectToken);
44
- }
45
- return url.toString();
46
- };
47
- const buildDirectDaemonAuthPayload = (connectInfo) => buildControlAuthMessage(connectInfo.provider === "e2b" ? connectInfo.authToken : undefined);
48
- const buildDirectDaemonRequestContext = (args) => {
49
- const requestType = resolveDirectDaemonRequestType(args.requestPayload);
50
- const wsUrl = new URL(buildDirectDaemonWsUrl(args.connectInfo));
51
- const parts = [
52
- `alias=${args.alias}`,
53
- `request=${requestType}`,
54
- `expected=${args.expectedType}`,
55
- `ws=${wsUrl.origin}${wsUrl.pathname}`,
56
- ];
57
- if (typeof args.requestPayload.path === "string") {
58
- parts.push(`path=${args.requestPayload.path}`);
59
- }
60
- if (typeof args.requestPayload.serviceName === "string") {
61
- parts.push(`service=${args.requestPayload.serviceName}`);
62
- }
63
- if (typeof args.requestPayload.sessionId === "string") {
64
- parts.push(`session=${args.requestPayload.sessionId}`);
65
- }
66
- return `${formatProviderLabel(args.provider)} control request failed (${parts.join(", ")})`;
67
- };
68
- const isDirectDaemonAuthRefreshError = (provider, error) => {
69
- const message = error instanceof Error ? error.message : String(error);
70
- if (provider === "e2b") {
71
- return (message.includes("Auth token is required.") ||
72
- message.includes("invalid auth token"));
73
- }
74
- return /Unexpected server response: (401|403)/.test(message);
75
- };
76
- const buildDirectDaemonControlErrorText = (provider, message) => {
77
- const { text } = parseDaemonControlError(message, `${formatProviderLabel(provider)} daemon control request failed.`);
78
- return text;
79
- };
80
- const buildDirectDaemonWsLogFields = (connectInfo) => {
81
- if (!connectInfo) {
82
- return {};
83
- }
84
- const wsUrl = new URL(buildDirectDaemonWsUrl(connectInfo));
85
- return {
86
- wsOrigin: wsUrl.origin,
87
- wsPath: wsUrl.pathname,
88
- };
89
- };
90
- const buildDirectDaemonRequestLogFields = (requestPayload) => ({
91
- requestType: resolveDirectDaemonRequestType(requestPayload),
92
- ...(typeof requestPayload.path === "string"
93
- ? { path: requestPayload.path }
94
- : {}),
95
- ...(typeof requestPayload.serviceName === "string"
96
- ? { serviceName: requestPayload.serviceName }
97
- : {}),
98
- ...(typeof requestPayload.sessionId === "string"
99
- ? { sessionId: requestPayload.sessionId }
100
- : {}),
101
- });
102
- const buildDirectDaemonOperationLogFields = (args) => ({
103
- alias: args.alias,
104
- provider: args.provider,
105
- operationId: args.operationId,
106
- attempt: args.attempt,
107
- expectedType: args.expectedType,
108
- ...buildDirectDaemonRequestLogFields(args.requestPayload),
109
- });
110
- const formatDirectDaemonWebSocketState = (ws) => {
111
- if (!ws) {
112
- return "none";
113
- }
114
- switch (ws.readyState) {
115
- case WebSocket.CONNECTING:
116
- return "connecting";
117
- case WebSocket.OPEN:
118
- return "open";
119
- case WebSocket.CLOSING:
120
- return "closing";
121
- case WebSocket.CLOSED:
122
- return "closed";
123
- default:
124
- return `unknown:${String(ws.readyState)}`;
125
- }
126
- };
127
- const measureDirectDaemonRawMessageBytes = (raw) => {
128
- if (typeof raw === "string") {
129
- return Buffer.byteLength(raw);
130
- }
131
- if (raw instanceof ArrayBuffer) {
132
- return raw.byteLength;
133
- }
134
- if (Array.isArray(raw)) {
135
- return raw.reduce((total, chunk) => total + chunk.length, 0);
136
- }
137
- if (ArrayBuffer.isView(raw)) {
138
- return raw.byteLength;
139
- }
140
- return null;
141
- };
142
- const refDirectDaemonWebSocket = (ws) => {
143
- const socket = ws._socket;
144
- socket?.ref?.();
145
- };
146
- const unrefDirectDaemonWebSocket = (ws) => {
147
- const socket = ws._socket;
148
- socket?.unref?.();
149
- };
150
- const getDirectDaemonControlTiming = () => ({
151
- ...DEFAULT_DIRECT_DAEMON_CONTROL_TIMING,
152
- ...(directDaemonControlTimingOverrides ?? {}),
153
- });
154
- const setDirectDaemonControlTimingForTests = (overrides) => {
155
- directDaemonControlTimingOverrides = overrides;
156
- };
157
- const sleep = async (ms) => {
158
- await new Promise((resolve) => {
159
- // Foreground request retries must keep the process alive until the next
160
- // connect attempt runs, otherwise Node can exit cleanly while the caller
161
- // is still awaiting the request promise.
162
- setTimeout(resolve, ms);
163
- });
164
- };
165
- const resolveDirectDaemonConnectTimeoutMs = (requestTimeoutMs) => {
166
- const timing = getDirectDaemonControlTiming();
167
- const baseTimeoutMs = Number.isFinite(requestTimeoutMs)
168
- ? Math.max(0, Math.ceil(requestTimeoutMs))
169
- : 0;
170
- return Math.min(Math.max(baseTimeoutMs + timing.connectTimeoutPaddingMs, timing.connectTimeoutMinMs), timing.connectTimeoutMaxMs);
171
- };
172
- const createDirectDaemonTransportError = (args) => {
173
- const error = new Error(args.message);
174
- error.directDaemonTransport = true;
175
- error.transportCode = args.transportCode;
176
- error.retryable = args.retryable;
177
- error.provider = args.provider;
178
- error.alias = args.alias;
179
- if (args.cause !== undefined) {
180
- error.cause = args.cause;
181
- }
182
- return error;
183
- };
184
- const isDirectDaemonTransportError = (error) => Boolean(error &&
185
- typeof error === "object" &&
186
- "directDaemonTransport" in error &&
187
- error.directDaemonTransport ===
188
- true);
189
- const wrapDirectDaemonRequestError = (context, error) => {
190
- if (isDirectDaemonTransportError(error)) {
191
- return createDirectDaemonTransportError({
192
- provider: error.provider,
193
- alias: error.alias,
194
- transportCode: error.transportCode,
195
- retryable: error.retryable,
196
- message: `${context}: ${error.message}`,
197
- cause: error,
198
- });
199
- }
200
- const detail = error instanceof Error ? error.message : String(error);
201
- const wrapped = new Error(`${context}: ${detail}`);
202
- wrapped.cause = error;
203
- return wrapped;
204
- };
205
- const validateDirectDaemonControlReadyMessage = (args) => {
206
- const ready = parseControlReadyMessage(args.message);
207
- const providerLabel = formatProviderLabel(args.provider);
208
- if (!ready) {
209
- throw createDirectDaemonTransportError({
210
- provider: args.provider,
211
- alias: args.alias,
212
- transportCode: "invalid_handshake",
213
- retryable: false,
214
- message: `${providerLabel} control handshake is missing protocol metadata.`,
215
- });
216
- }
217
- if (ready.protocolVersion !== TTY_CONTROL_PROTOCOL_VERSION) {
218
- throw createDirectDaemonTransportError({
219
- provider: args.provider,
220
- alias: args.alias,
221
- transportCode: "protocol_version_mismatch",
222
- retryable: false,
223
- message: `Unsupported ${providerLabel} control protocol version ${String(ready.protocolVersion)} (expected ${String(TTY_CONTROL_PROTOCOL_VERSION)}).`,
224
- });
225
- }
226
- const missingCapabilities = findMissingTtyControlCapabilities(ready.capabilities);
227
- if (missingCapabilities.length > 0) {
228
- throw createDirectDaemonTransportError({
229
- provider: args.provider,
230
- alias: args.alias,
231
- transportCode: "missing_capabilities",
232
- retryable: false,
233
- message: `${providerLabel} control handshake is missing capabilities: ${missingCapabilities.join(", ")}.`,
234
- });
235
- }
236
- return ready;
237
- };
238
- class DirectDaemonControlSocket {
239
- provider;
240
- resolveConnectInfo;
241
- alias;
242
- onDispose;
243
- ws = null;
244
- connectInfo = null;
245
- authenticated = false;
246
- connecting = null;
247
- idleTimer = null;
248
- pingInterval = null;
249
- lastPongAt = 0;
250
- controlProtocolVersion = null;
251
- controlCapabilities = new Set();
252
- reconnecting = false;
253
- disposed = false;
254
- pendingRequests = new Map();
255
- constructor(provider, resolveConnectInfo, alias, onDispose) {
256
- this.provider = provider;
257
- this.resolveConnectInfo = resolveConnectInfo;
258
- this.alias = alias;
259
- this.onDispose = onDispose;
260
- }
261
- buildLogFields(extra = {}) {
262
- return {
263
- provider: this.provider,
264
- alias: this.alias,
265
- authenticated: this.authenticated,
266
- pendingCount: this.pendingRequests.size,
267
- wsState: formatDirectDaemonWebSocketState(this.ws),
268
- reconnecting: this.reconnecting,
269
- protocolVersion: this.controlProtocolVersion,
270
- capabilities: [...this.controlCapabilities],
271
- ...buildDirectDaemonWsLogFields(this.connectInfo),
272
- ...extra,
273
- };
274
- }
275
- clearIdleTimer() {
276
- if (!this.idleTimer) {
277
- return;
278
- }
279
- clearTimeout(this.idleTimer);
280
- this.idleTimer = null;
281
- }
282
- scheduleIdleClose() {
283
- if (this.pendingRequests.size > 0 || this.disposed) {
284
- return;
285
- }
286
- this.clearIdleTimer();
287
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
288
- unrefDirectDaemonWebSocket(this.ws);
289
- }
290
- const { idleMs } = getDirectDaemonControlTiming();
291
- this.idleTimer = setTimeout(() => {
292
- this.dispose();
293
- }, idleMs);
294
- this.idleTimer.unref();
295
- }
296
- stopKeepalive() {
297
- if (!this.pingInterval) {
298
- return;
299
- }
300
- clearInterval(this.pingInterval);
301
- this.pingInterval = null;
302
- }
303
- startKeepalive() {
304
- this.stopKeepalive();
305
- this.lastPongAt = Date.now();
306
- const { pingIntervalMs, pongGraceMs } = getDirectDaemonControlTiming();
307
- this.pingInterval = setInterval(() => {
308
- const ws = this.ws;
309
- if (!ws || ws.readyState !== WebSocket.OPEN) {
310
- return;
311
- }
312
- const now = Date.now();
313
- const elapsedSincePongMs = now - this.lastPongAt;
314
- if (elapsedSincePongMs > pongGraceMs) {
315
- const error = createDirectDaemonTransportError({
316
- provider: this.provider,
317
- alias: this.alias,
318
- transportCode: "keepalive_timeout",
319
- retryable: true,
320
- message: `${formatProviderLabel(this.provider)} control websocket missed keepalive pong for ${String(pongGraceMs)}ms.`,
321
- });
322
- logger.warn("direct_daemon_control_keepalive_timeout", this.buildLogFields({
323
- elapsedSincePongMs,
324
- pongGraceMs,
325
- }));
326
- try {
327
- ws.terminate();
328
- }
329
- catch {
330
- // ignore termination failures
331
- }
332
- this.failConnection(error);
333
- return;
334
- }
335
- try {
336
- ws.send(JSON.stringify({
337
- type: "ping",
338
- ts: now,
339
- }));
340
- }
341
- catch {
342
- // ignore ping failures; socket lifecycle handles disconnects
343
- }
344
- }, pingIntervalMs);
345
- this.pingInterval.unref();
346
- }
347
- cleanupWebSocket() {
348
- const ws = this.ws;
349
- this.ws = null;
350
- this.connectInfo = null;
351
- this.authenticated = false;
352
- this.stopKeepalive();
353
- this.lastPongAt = 0;
354
- this.controlProtocolVersion = null;
355
- this.controlCapabilities = new Set();
356
- if (!ws) {
357
- return;
358
- }
359
- ws.removeAllListeners();
360
- try {
361
- if (ws.readyState <= WebSocket.OPEN) {
362
- ws.close();
363
- }
364
- }
365
- catch {
366
- // ignore close failures
367
- }
368
- }
369
- failPendingRequests(error) {
370
- const pendingEntries = [...this.pendingRequests.entries()];
371
- this.pendingRequests.clear();
372
- if (pendingEntries.length > 0) {
373
- logger.warn("direct_daemon_control_pending_requests_failed", this.buildLogFields({
374
- failedRequestCount: pendingEntries.length,
375
- error: error instanceof Error ? error.message : String(error),
376
- }));
377
- }
378
- for (const [, pending] of pendingEntries) {
379
- if (pending.timer) {
380
- clearTimeout(pending.timer);
381
- }
382
- pending.reject(wrapDirectDaemonRequestError(pending.context, error));
383
- }
384
- }
385
- handleAuthenticatedMessage(message) {
386
- const type = typeof message.type === "string" ? message.type : "";
387
- if (type === "pong") {
388
- this.lastPongAt = Date.now();
389
- return;
390
- }
391
- const responseRequestId = typeof message.requestId === "string" ? message.requestId : null;
392
- if (!responseRequestId) {
393
- if (type === "error") {
394
- this.failConnection(new Error(buildDirectDaemonControlErrorText(this.provider, message)));
395
- }
396
- return;
397
- }
398
- const pending = this.pendingRequests.get(responseRequestId);
399
- if (!pending) {
400
- logger.warn("direct_daemon_control_response_unmatched", this.buildLogFields({
401
- requestId: responseRequestId,
402
- responseType: type || "unknown",
403
- status: typeof message.status === "string" ? message.status : null,
404
- }));
405
- return;
406
- }
407
- this.pendingRequests.delete(responseRequestId);
408
- if (pending.timer) {
409
- clearTimeout(pending.timer);
410
- }
411
- this.scheduleIdleClose();
412
- logger.debug("direct_daemon_control_response_received", this.buildLogFields({
413
- requestId: responseRequestId,
414
- responseType: type || "unknown",
415
- expectedType: pending.expectedType,
416
- status: typeof message.status === "string" ? message.status : null,
417
- }));
418
- if (type === "error") {
419
- pending.reject(wrapDirectDaemonRequestError(pending.context, buildDirectDaemonControlErrorText(this.provider, message)));
420
- return;
421
- }
422
- if (type !== pending.expectedType) {
423
- pending.reject(wrapDirectDaemonRequestError(pending.context, `Unexpected ${formatProviderLabel(this.provider)} control response type "${type}" (expected "${pending.expectedType}").`));
424
- return;
425
- }
426
- pending.resolve(message);
427
- }
428
- failConnection(error) {
429
- this.reconnecting = !this.disposed;
430
- this.cleanupWebSocket();
431
- this.failPendingRequests(error);
432
- this.scheduleIdleClose();
433
- }
434
- async ensureConnected(args) {
435
- const forceRefresh = args.forceRefresh === true;
436
- if (this.disposed) {
437
- throw new Error(`${formatProviderLabel(this.provider)} control socket is closed.`);
438
- }
439
- if (forceRefresh) {
440
- this.reconnecting = true;
441
- this.cleanupWebSocket();
442
- }
443
- if (this.authenticated &&
444
- this.ws &&
445
- this.ws.readyState === WebSocket.OPEN &&
446
- this.connectInfo) {
447
- return this.connectInfo;
448
- }
449
- if (this.connecting) {
450
- await this.connecting;
451
- if (this.authenticated &&
452
- this.ws &&
453
- this.ws.readyState === WebSocket.OPEN &&
454
- this.connectInfo) {
455
- return this.connectInfo;
456
- }
457
- }
458
- this.connecting = this.connectWithRetry({
459
- forceRefresh,
460
- requestPayload: args.requestPayload,
461
- expectedType: args.expectedType,
462
- timeoutMs: args.timeoutMs,
463
- }).finally(() => {
464
- this.connecting = null;
465
- });
466
- await this.connecting;
467
- if (!this.connectInfo) {
468
- throw new Error(`${formatProviderLabel(this.provider)} control socket lost connect info after handshake.`);
469
- }
470
- return this.connectInfo;
471
- }
472
- async connectWithRetry(args) {
473
- const startedAt = Date.now();
474
- const connectTimeoutMs = resolveDirectDaemonConnectTimeoutMs(args.timeoutMs);
475
- let attempt = 0;
476
- let delayMs = getDirectDaemonControlTiming().connectRetryInitialDelayMs;
477
- let lastError = null;
478
- let lastConnectInfo = null;
479
- const wrapConnectError = (error) => {
480
- const normalized = error instanceof Error ? error : new Error(String(error));
481
- if (!lastConnectInfo) {
482
- return normalized;
483
- }
484
- const context = buildDirectDaemonRequestContext({
485
- alias: this.alias,
486
- provider: this.provider,
487
- requestPayload: args.requestPayload,
488
- expectedType: args.expectedType,
489
- connectInfo: lastConnectInfo,
490
- });
491
- return wrapDirectDaemonRequestError(context, normalized);
492
- };
493
- while (!this.disposed) {
494
- attempt += 1;
495
- const forceRefresh = args.forceRefresh || attempt > 1;
496
- try {
497
- lastConnectInfo = await this.resolveConnectInfo({
498
- alias: this.alias,
499
- intent: "proxy",
500
- // Direct daemon control is always driven by an active CLI operation,
501
- // so retries and forced reconnects should keep wake enabled instead
502
- // of failing when a devbox sleeps between request attempts.
503
- allowWake: true,
504
- ...(forceRefresh ? { forceRefresh: true } : {}),
505
- });
506
- logger.debug("direct_daemon_control_socket_connect_start", this.buildLogFields({
507
- ...buildDirectDaemonWsLogFields(lastConnectInfo),
508
- attempt,
509
- connectTimeoutMs,
510
- expectedType: args.expectedType,
511
- ...buildDirectDaemonRequestLogFields(args.requestPayload),
512
- }));
513
- await this.connectOnce(lastConnectInfo);
514
- if (this.reconnecting || attempt > 1) {
515
- logger.info("direct_daemon_control_socket_reconnected", this.buildLogFields({
516
- attempt,
517
- elapsedMs: Date.now() - startedAt,
518
- connectTimeoutMs,
519
- ...buildDirectDaemonRequestLogFields(args.requestPayload),
520
- }));
521
- }
522
- this.reconnecting = false;
523
- return;
524
- }
525
- catch (error) {
526
- const failure = error instanceof Error ? error : new Error(String(error));
527
- lastError = failure;
528
- if (isDirectDaemonAuthRefreshError(this.provider, failure)) {
529
- logger.warn("direct_daemon_control_connect_info_auth_failed", this.buildLogFields({
530
- attempt,
531
- connectTimeoutMs,
532
- error: failure.message,
533
- ...buildDirectDaemonRequestLogFields(args.requestPayload),
534
- ...(lastConnectInfo
535
- ? buildDirectDaemonWsLogFields(lastConnectInfo)
536
- : {}),
537
- }));
538
- throw wrapConnectError(failure);
539
- }
540
- if (!isDirectDaemonTransportError(failure)) {
541
- logger.warn("direct_daemon_control_connect_info_failed", this.buildLogFields({
542
- attempt,
543
- connectTimeoutMs,
544
- error: failure.message,
545
- ...buildDirectDaemonRequestLogFields(args.requestPayload),
546
- ...(lastConnectInfo
547
- ? buildDirectDaemonWsLogFields(lastConnectInfo)
548
- : {}),
549
- }));
550
- throw wrapConnectError(failure);
551
- }
552
- if (!failure.retryable) {
553
- throw wrapConnectError(failure);
554
- }
555
- const elapsedMs = Date.now() - startedAt;
556
- const remainingMs = Math.max(0, connectTimeoutMs - elapsedMs);
557
- if (remainingMs <= 0) {
558
- break;
559
- }
560
- this.reconnecting = true;
561
- const retryInMs = Math.min(delayMs, remainingMs);
562
- logger.warn("direct_daemon_control_socket_connect_retry", this.buildLogFields({
563
- attempt,
564
- elapsedMs,
565
- retryInMs,
566
- connectTimeoutMs,
567
- error: failure.message,
568
- ...buildDirectDaemonRequestLogFields(args.requestPayload),
569
- ...(lastConnectInfo
570
- ? buildDirectDaemonWsLogFields(lastConnectInfo)
571
- : {}),
572
- }));
573
- await sleep(retryInMs);
574
- delayMs = Math.min(delayMs * 2, getDirectDaemonControlTiming().connectRetryMaxDelayMs);
575
- }
576
- }
577
- this.reconnecting = false;
578
- if (this.disposed) {
579
- throw new Error(`${formatProviderLabel(this.provider)} control socket is closed.`);
580
- }
581
- const detail = lastError && lastError.message.trim().length > 0
582
- ? `: ${lastError.message}`
583
- : "";
584
- throw wrapConnectError(createDirectDaemonTransportError({
585
- provider: this.provider,
586
- alias: this.alias,
587
- transportCode: "connect_timeout",
588
- retryable: true,
589
- message: `Timed out connecting ${formatProviderLabel(this.provider)} control websocket for "${this.alias}"${detail}`,
590
- ...(lastError ? { cause: lastError } : {}),
591
- }));
592
- }
593
- async connectOnce(connectInfo) {
594
- this.cleanupWebSocket();
595
- await new Promise((resolve, reject) => {
596
- let settled = false;
597
- const ws = new WebSocket(buildDirectDaemonWsUrl(connectInfo));
598
- this.ws = ws;
599
- this.connectInfo = connectInfo;
600
- this.authenticated = false;
601
- this.lastPongAt = Date.now();
602
- const finishResolve = () => {
603
- if (settled) {
604
- return;
605
- }
606
- settled = true;
607
- resolve();
608
- };
609
- const finishReject = (error) => {
610
- if (settled) {
611
- return;
612
- }
613
- settled = true;
614
- this.cleanupWebSocket();
615
- reject(error instanceof Error ? error : new Error(String(error)));
616
- };
617
- ws.on("open", () => {
618
- logger.debug("direct_daemon_control_socket_open", this.buildLogFields(buildDirectDaemonWsLogFields(connectInfo)));
619
- try {
620
- ws.send(JSON.stringify(buildDirectDaemonAuthPayload(connectInfo)));
621
- }
622
- catch (error) {
623
- finishReject(createDirectDaemonTransportError({
624
- provider: this.provider,
625
- alias: this.alias,
626
- transportCode: "socket_error",
627
- retryable: true,
628
- message: `${formatProviderLabel(this.provider)} control websocket failed to send auth.`,
629
- cause: error,
630
- }));
631
- }
632
- });
633
- ws.on("message", (raw) => {
634
- const parsed = parseDaemonJsonRecord(raw);
635
- if (!parsed) {
636
- logger.warn("direct_daemon_control_socket_message_parse_failed", this.buildLogFields({
637
- rawBytes: measureDirectDaemonRawMessageBytes(raw),
638
- }));
639
- return;
640
- }
641
- const type = typeof parsed.type === "string" ? parsed.type : "";
642
- if (!this.authenticated) {
643
- if (type === "pong") {
644
- this.lastPongAt = Date.now();
645
- return;
646
- }
647
- if (type === "control_ready") {
648
- try {
649
- const ready = validateDirectDaemonControlReadyMessage({
650
- provider: this.provider,
651
- alias: this.alias,
652
- message: parsed,
653
- });
654
- this.authenticated = true;
655
- this.controlProtocolVersion = ready.protocolVersion;
656
- this.controlCapabilities = new Set(ready.capabilities);
657
- this.lastPongAt = Date.now();
658
- this.startKeepalive();
659
- logger.debug("direct_daemon_control_socket_ready", this.buildLogFields(buildDirectDaemonWsLogFields(connectInfo)));
660
- finishResolve();
661
- }
662
- catch (error) {
663
- if (isDirectDaemonTransportError(error)) {
664
- try {
665
- ws.removeAllListeners();
666
- ws.close(1008, error.transportCode === "protocol_version_mismatch"
667
- ? "unsupported protocol version"
668
- : error.transportCode === "missing_capabilities"
669
- ? "missing control capabilities"
670
- : "invalid control handshake");
671
- }
672
- catch {
673
- // ignore close failures
674
- }
675
- }
676
- finishReject(error);
677
- }
678
- return;
679
- }
680
- if (type === "error") {
681
- finishReject(new Error(buildDirectDaemonControlErrorText(this.provider, parsed)));
682
- }
683
- return;
684
- }
685
- this.handleAuthenticatedMessage(parsed);
686
- });
687
- ws.on("pong", () => {
688
- this.lastPongAt = Date.now();
689
- });
690
- ws.on("error", (error) => {
691
- logger.warn("direct_daemon_control_socket_error", this.buildLogFields({
692
- ...buildDirectDaemonWsLogFields(connectInfo),
693
- error: error.message,
694
- }));
695
- const transportError = createDirectDaemonTransportError({
696
- provider: this.provider,
697
- alias: this.alias,
698
- transportCode: "socket_error",
699
- retryable: true,
700
- message: `${formatProviderLabel(this.provider)} control websocket error: ${error.message}`,
701
- cause: error,
702
- });
703
- if (!this.authenticated) {
704
- finishReject(transportError);
705
- return;
706
- }
707
- this.failConnection(transportError);
708
- });
709
- ws.on("close", (code, reason) => {
710
- const reasonText = reason.toString("utf8");
711
- logger.warn("direct_daemon_control_socket_close", this.buildLogFields({
712
- ...buildDirectDaemonWsLogFields(connectInfo),
713
- code,
714
- reason: reasonText || "no reason",
715
- }));
716
- const closeError = createDirectDaemonTransportError({
717
- provider: this.provider,
718
- alias: this.alias,
719
- transportCode: "socket_closed",
720
- retryable: true,
721
- message: `${formatProviderLabel(this.provider)} control websocket closed (${String(code)}): ${reasonText || "no reason"}`,
722
- });
723
- if (!this.authenticated) {
724
- finishReject(closeError);
725
- return;
726
- }
727
- this.failConnection(closeError);
728
- });
729
- });
730
- }
731
- async request(args) {
732
- this.clearIdleTimer();
733
- const connectInfo = await this.ensureConnected({
734
- forceRefresh: args.forceRefresh === true,
735
- requestPayload: args.requestPayload,
736
- expectedType: args.expectedType,
737
- timeoutMs: args.timeoutMs,
738
- });
739
- const requestId = randomUUID().replace(/-/g, "");
740
- const requestContext = buildDirectDaemonRequestContext({
741
- alias: this.alias,
742
- provider: this.provider,
743
- requestPayload: args.requestPayload,
744
- expectedType: args.expectedType,
745
- connectInfo,
746
- });
747
- return await new Promise((resolve, reject) => {
748
- const pending = {
749
- expectedType: args.expectedType,
750
- context: requestContext,
751
- resolve: (value) => resolve(value),
752
- reject,
753
- timer: null,
754
- };
755
- pending.timer = setTimeout(() => {
756
- this.pendingRequests.delete(requestId);
757
- this.scheduleIdleClose();
758
- logger.warn("direct_daemon_control_request_timeout", this.buildLogFields({
759
- requestId,
760
- expectedType: args.expectedType,
761
- timeoutMs: args.timeoutMs,
762
- ...buildDirectDaemonRequestLogFields(args.requestPayload),
763
- }));
764
- reject(wrapDirectDaemonRequestError(requestContext, createDirectDaemonTransportError({
765
- provider: this.provider,
766
- alias: this.alias,
767
- transportCode: "request_timeout",
768
- retryable: true,
769
- message: `Timed out waiting for ${formatProviderLabel(this.provider)} control response (${args.expectedType}).`,
770
- })));
771
- }, args.timeoutMs);
772
- pending.timer.unref();
773
- this.pendingRequests.set(requestId, pending);
774
- try {
775
- const ws = this.ws;
776
- if (!ws || ws.readyState !== WebSocket.OPEN) {
777
- throw createDirectDaemonTransportError({
778
- provider: this.provider,
779
- alias: this.alias,
780
- transportCode: "socket_closed",
781
- retryable: true,
782
- message: `${formatProviderLabel(this.provider)} control websocket is not open.`,
783
- });
784
- }
785
- refDirectDaemonWebSocket(ws);
786
- logger.debug("direct_daemon_control_request_send", this.buildLogFields({
787
- requestId,
788
- expectedType: args.expectedType,
789
- timeoutMs: args.timeoutMs,
790
- ...buildDirectDaemonRequestLogFields(args.requestPayload),
791
- }));
792
- ws.send(JSON.stringify({
793
- ...args.requestPayload,
794
- requestId,
795
- }));
796
- }
797
- catch (error) {
798
- this.failConnection(isDirectDaemonTransportError(error)
799
- ? error
800
- : createDirectDaemonTransportError({
801
- provider: this.provider,
802
- alias: this.alias,
803
- transportCode: "socket_error",
804
- retryable: true,
805
- message: `${formatProviderLabel(this.provider)} control websocket send failed.`,
806
- cause: error,
807
- }));
808
- }
809
- });
810
- }
811
- dispose() {
812
- if (this.disposed) {
813
- return;
814
- }
815
- this.disposed = true;
816
- this.reconnecting = false;
817
- logger.debug("direct_daemon_control_socket_dispose", this.buildLogFields());
818
- this.clearIdleTimer();
819
- this.failPendingRequests(new Error(`${formatProviderLabel(this.provider)} control socket disposed.`));
820
- this.cleanupWebSocket();
821
- this.onDispose();
822
- }
823
- }
824
- const directDaemonControlSockets = new Map();
825
- const buildDirectDaemonControlSocketKey = (provider, alias) => `${provider}:${alias}`;
826
- const resolveDirectDaemonControlSocket = (args) => {
827
- const key = buildDirectDaemonControlSocketKey(args.provider, args.alias);
828
- if (args.forceRefresh) {
829
- directDaemonControlSockets.get(key)?.dispose();
830
- directDaemonControlSockets.delete(key);
831
- }
832
- const existing = directDaemonControlSockets.get(key);
833
- if (existing) {
834
- return existing;
835
- }
836
- const socket = new DirectDaemonControlSocket(args.provider, args.resolveConnectInfo, args.alias, () => {
837
- const current = directDaemonControlSockets.get(key);
838
- if (current === socket) {
839
- directDaemonControlSockets.delete(key);
840
- }
841
- });
842
- directDaemonControlSockets.set(key, socket);
843
- return socket;
844
- };
845
- const closeAllDirectDaemonControlSocketsForTests = () => {
846
- for (const socket of directDaemonControlSockets.values()) {
847
- socket.dispose();
848
- }
849
- directDaemonControlSockets.clear();
850
- setDirectDaemonControlTimingForTests(null);
851
- };
852
- class DirectDaemonExecSocket {
853
- provider;
854
- resolveConnectInfo;
855
- alias;
856
- options;
857
- binaryType = "nodebuffer";
858
- readyState = 0;
859
- listeners = {
860
- open: new Set(),
861
- close: new Set(),
862
- error: new Set(),
863
- message: new Set(),
864
- };
865
- pongListeners = new Set();
866
- requestId = randomUUID().replace(/-/g, "");
867
- channelId = randomUUID().replace(/-/g, "");
868
- sessionId = null;
869
- ws = null;
870
- closed = false;
871
- authenticated = false;
872
- handshakeTimer = null;
873
- replayInProgress = false;
874
- replayBufferedOutbound = [];
875
- constructor(provider, resolveConnectInfo, alias, options) {
876
- this.provider = provider;
877
- this.resolveConnectInfo = resolveConnectInfo;
878
- this.alias = alias;
879
- this.options = options;
880
- if (typeof this.options.sessionId === "string" && this.options.sessionId) {
881
- this.sessionId = this.options.sessionId;
882
- }
883
- void this.start();
884
- }
885
- emit(type, event = {}) {
886
- for (const listener of this.listeners[type]) {
887
- listener(event);
888
- }
889
- }
890
- emitPong() {
891
- for (const listener of this.pongListeners) {
892
- listener();
893
- }
894
- }
895
- clearHandshakeTimer() {
896
- if (!this.handshakeTimer) {
897
- return;
898
- }
899
- clearTimeout(this.handshakeTimer);
900
- this.handshakeTimer = null;
901
- }
902
- startHandshakeTimer() {
903
- this.clearHandshakeTimer();
904
- const providerLabel = formatProviderLabel(this.provider);
905
- this.handshakeTimer = setTimeout(() => {
906
- if (this.closed || this.readyState !== 0) {
907
- return;
908
- }
909
- this.emit("error", {
910
- data: new Error(`Timed out waiting for ${providerLabel} tty session handshake.`),
911
- });
912
- this.close();
913
- }, 30_000);
914
- this.handshakeTimer.unref();
915
- }
916
- sendJson(payload) {
917
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
918
- throw new Error(`${formatProviderLabel(this.provider)} daemon socket is not open.`);
919
- }
920
- this.ws.send(JSON.stringify(payload));
921
- }
922
- markReplayActivity() {
923
- this.emit("message", { data: new Uint8Array(0) });
924
- }
925
- queueOrSend(payload) {
926
- if (this.replayInProgress) {
927
- this.replayBufferedOutbound.push(payload);
928
- this.markReplayActivity();
929
- return;
930
- }
931
- this.sendJson(payload);
932
- }
933
- flushReplayBufferedOutbound() {
934
- if (this.replayInProgress || this.replayBufferedOutbound.length === 0) {
935
- return;
936
- }
937
- const pending = [...this.replayBufferedOutbound];
938
- this.replayBufferedOutbound = [];
939
- for (const payload of pending) {
940
- try {
941
- this.sendJson(payload);
942
- }
943
- catch (error) {
944
- this.emit("error", {
945
- data: error instanceof Error ? error : new Error(String(error)),
946
- });
947
- this.close();
948
- return;
949
- }
950
- }
951
- }
952
- buildExecLogFields(extra) {
953
- return {
954
- alias: this.alias,
955
- provider: this.provider,
956
- requestId: this.requestId,
957
- channelId: this.channelId,
958
- ...(this.sessionId ? { sessionId: this.sessionId } : {}),
959
- ...(this.options.ephemeral === true ? { ephemeral: true } : {}),
960
- ...extra,
961
- };
962
- }
963
- buildTtyOpenPayload() {
964
- const payload = {
965
- type: "tty_open",
966
- requestId: this.requestId,
967
- channelId: this.channelId,
968
- };
969
- if (typeof this.options.sessionId === "string" && this.options.sessionId) {
970
- payload.sessionId = this.options.sessionId;
971
- payload.allowCreateIfMissing = this.options.allowCreateIfMissing === true;
972
- }
973
- if (Array.isArray(this.options.cmd) && this.options.cmd.length > 0) {
974
- payload.command = this.options.cmd;
975
- }
976
- if (typeof this.options.cwd === "string" && this.options.cwd) {
977
- payload.cwd = this.options.cwd;
978
- }
979
- if (this.options.env) {
980
- payload.env = this.options.env;
981
- }
982
- if (typeof this.options.cols === "number") {
983
- payload.cols = this.options.cols;
984
- }
985
- if (typeof this.options.rows === "number") {
986
- payload.rows = this.options.rows;
987
- }
988
- if (typeof this.options.logPath === "string" && this.options.logPath) {
989
- payload.logPath = this.options.logPath;
990
- }
991
- if (typeof this.options.ephemeral === "boolean") {
992
- payload.ephemeral = this.options.ephemeral;
993
- }
994
- return payload;
995
- }
996
- closeFromRemote(code) {
997
- if (this.closed)
998
- return;
999
- this.clearHandshakeTimer();
1000
- this.closed = true;
1001
- this.replayBufferedOutbound = [];
1002
- this.readyState = 3;
1003
- if (this.ws && this.ws.readyState <= WebSocket.OPEN) {
1004
- try {
1005
- this.ws.close();
1006
- }
1007
- catch {
1008
- // ignore close failures
1009
- }
1010
- }
1011
- this.emit("close", { code: code ?? 1000 });
1012
- }
1013
- handleDaemonMessage(message) {
1014
- const type = typeof message.type === "string" ? message.type : "";
1015
- if (!this.authenticated) {
1016
- if (type === "control_ready") {
1017
- try {
1018
- validateDirectDaemonControlReadyMessage({
1019
- provider: this.provider,
1020
- alias: this.alias,
1021
- message,
1022
- });
1023
- }
1024
- catch (error) {
1025
- this.emit("error", {
1026
- data: error instanceof Error ? error : new Error(String(error)),
1027
- });
1028
- this.close();
1029
- return;
1030
- }
1031
- this.authenticated = true;
1032
- try {
1033
- this.sendJson(this.buildTtyOpenPayload());
1034
- }
1035
- catch (error) {
1036
- this.emit("error", {
1037
- data: error instanceof Error ? error : new Error(String(error)),
1038
- });
1039
- this.close();
1040
- }
1041
- return;
1042
- }
1043
- if (type === "error") {
1044
- this.emit("error", {
1045
- data: new Error(buildDirectDaemonControlErrorText(this.provider, message)),
1046
- });
1047
- this.close();
1048
- }
1049
- return;
1050
- }
1051
- if (type === "tty_open_result") {
1052
- const responseRequestId = typeof message.requestId === "string" ? message.requestId : null;
1053
- if (responseRequestId !== this.requestId) {
1054
- return;
1055
- }
1056
- if (message.status === "error") {
1057
- this.emit("error", {
1058
- data: new Error(buildDirectDaemonControlErrorText(this.provider, message)),
1059
- });
1060
- this.close();
1061
- return;
1062
- }
1063
- const channelId = typeof message.channelId === "string" ? message.channelId.trim() : "";
1064
- if (channelId) {
1065
- this.channelId = channelId;
1066
- }
1067
- const sessionId = typeof message.sessionId === "string" ? message.sessionId.trim() : "";
1068
- if (sessionId) {
1069
- this.sessionId = sessionId;
1070
- }
1071
- return;
1072
- }
1073
- if (type === "tty_ready") {
1074
- this.clearHandshakeTimer();
1075
- this.readyState = 1;
1076
- this.emit("open");
1077
- queueMicrotask(() => {
1078
- if (this.closed)
1079
- return;
1080
- this.emit("message", { data: JSON.stringify(message) });
1081
- });
1082
- return;
1083
- }
1084
- if (type === "tty_replay_start") {
1085
- this.replayInProgress = true;
1086
- this.markReplayActivity();
1087
- this.emit("message", { data: JSON.stringify(message) });
1088
- return;
1089
- }
1090
- if (type === "tty_replay_done") {
1091
- this.replayInProgress = false;
1092
- this.markReplayActivity();
1093
- this.flushReplayBufferedOutbound();
1094
- this.emit("message", { data: JSON.stringify(message) });
1095
- return;
1096
- }
1097
- if (type === "tty_data") {
1098
- this.emit("message", { data: JSON.stringify(message) });
1099
- return;
1100
- }
1101
- if (type === "tty_exit") {
1102
- this.emit("message", { data: JSON.stringify(message) });
1103
- this.close();
1104
- return;
1105
- }
1106
- if (type === "tty_closed") {
1107
- const closeCode = typeof message.code === "number" && Number.isFinite(message.code)
1108
- ? message.code
1109
- : undefined;
1110
- const closeReason = typeof message.reason === "string" && message.reason.length > 0
1111
- ? message.reason
1112
- : "no reason";
1113
- const errorPayload = message.error && typeof message.error === "object"
1114
- ? message.error
1115
- : null;
1116
- const errorCode = errorPayload && typeof errorPayload.code === "string"
1117
- ? errorPayload.code
1118
- : undefined;
1119
- const errorMessage = errorPayload && typeof errorPayload.message === "string"
1120
- ? errorPayload.message
1121
- : undefined;
1122
- const replacedByNewerClient = closeCode === CONTROL_TTY_REPLACED_CLOSE_CODE ||
1123
- errorPayload?.code === CONTROL_TTY_REPLACED_ERROR_CODE;
1124
- const ttyCloseLogFields = this.buildExecLogFields({
1125
- ...(typeof closeCode === "number" ? { code: closeCode } : {}),
1126
- reason: closeReason,
1127
- replacedByNewerClient,
1128
- ...(errorCode ? { errorCode } : {}),
1129
- ...(errorMessage ? { errorMessage } : {}),
1130
- });
1131
- if (replacedByNewerClient) {
1132
- logger.info("direct_daemon_exec_tty_closed", ttyCloseLogFields);
1133
- }
1134
- else if (closeCode === 1000 &&
1135
- typeof errorMessage !== "string" &&
1136
- typeof errorCode !== "string") {
1137
- logger.info("direct_daemon_exec_tty_closed", ttyCloseLogFields);
1138
- }
1139
- else {
1140
- logger.warn("direct_daemon_exec_tty_closed", ttyCloseLogFields);
1141
- }
1142
- if (replacedByNewerClient) {
1143
- this.closeFromRemote(CONTROL_TTY_REPLACED_CLOSE_CODE);
1144
- return;
1145
- }
1146
- if (errorPayload && typeof errorPayload.message === "string") {
1147
- this.emit("error", { data: new Error(errorPayload.message) });
1148
- }
1149
- this.closeFromRemote(closeCode);
1150
- return;
1151
- }
1152
- if (type === "error") {
1153
- this.emit("error", {
1154
- data: new Error(buildDirectDaemonControlErrorText(this.provider, message)),
1155
- });
1156
- return;
1157
- }
1158
- if (type === "pong") {
1159
- this.emitPong();
1160
- return;
1161
- }
1162
- if (type === "port_opened" || type === "port_closed") {
1163
- this.emit("message", { data: JSON.stringify(message) });
1164
- }
1165
- }
1166
- async start() {
1167
- try {
1168
- if (this.closed)
1169
- return;
1170
- const connectInfo = await this.resolveConnectInfo({
1171
- alias: this.alias,
1172
- intent: "shell",
1173
- allowWake: true,
1174
- });
1175
- if (this.closed)
1176
- return;
1177
- const ws = new WebSocket(buildDirectDaemonWsUrl(connectInfo));
1178
- this.ws = ws;
1179
- this.startHandshakeTimer();
1180
- ws.on("open", () => {
1181
- try {
1182
- this.sendJson(buildDirectDaemonAuthPayload(connectInfo));
1183
- }
1184
- catch (error) {
1185
- this.emit("error", {
1186
- data: error instanceof Error ? error : new Error(String(error)),
1187
- });
1188
- this.close();
1189
- }
1190
- });
1191
- ws.on("message", (raw) => {
1192
- const parsed = parseDaemonJsonRecord(raw);
1193
- if (!parsed)
1194
- return;
1195
- this.handleDaemonMessage(parsed);
1196
- });
1197
- ws.on("pong", () => {
1198
- this.emitPong();
1199
- });
1200
- ws.on("error", (error) => {
1201
- this.clearHandshakeTimer();
1202
- logger.warn("direct_daemon_exec_socket_error", this.buildExecLogFields({
1203
- ...buildDirectDaemonWsLogFields(connectInfo),
1204
- error: error instanceof Error
1205
- ? error.message
1206
- : new Error(String(error)).message,
1207
- }));
1208
- this.emit("error", {
1209
- data: error instanceof Error ? error : new Error(String(error)),
1210
- });
1211
- });
1212
- ws.on("close", (code, reason) => {
1213
- this.clearHandshakeTimer();
1214
- const reasonText = reason.toString("utf8") || "no reason";
1215
- const logMethod = code === 1000 ? logger.info : logger.warn;
1216
- logMethod("direct_daemon_exec_socket_close", this.buildExecLogFields({
1217
- ...buildDirectDaemonWsLogFields(connectInfo),
1218
- code,
1219
- reason: reasonText,
1220
- }));
1221
- if (this.closed)
1222
- return;
1223
- this.closed = true;
1224
- this.readyState = 3;
1225
- this.emit("close", { code });
1226
- });
1227
- }
1228
- catch (error) {
1229
- this.clearHandshakeTimer();
1230
- this.emit("error", {
1231
- data: error instanceof Error ? error : new Error(String(error)),
1232
- });
1233
- this.close();
1234
- }
1235
- }
1236
- send(data, cb) {
1237
- if (this.closed) {
1238
- cb?.();
1239
- return;
1240
- }
1241
- try {
1242
- if (typeof data === "string") {
1243
- try {
1244
- const parsed = JSON.parse(data);
1245
- if (parsed && typeof parsed === "object") {
1246
- const record = parsed;
1247
- if (record.type === "resize") {
1248
- this.queueOrSend({
1249
- type: "tty_resize",
1250
- channelId: this.channelId,
1251
- cols: record.cols,
1252
- rows: record.rows,
1253
- });
1254
- cb?.();
1255
- return;
1256
- }
1257
- if (record.type === "detach") {
1258
- this.queueOrSend({
1259
- type: "tty_detach",
1260
- channelId: this.channelId,
1261
- });
1262
- cb?.();
1263
- return;
1264
- }
1265
- }
1266
- }
1267
- catch {
1268
- // fall through to stdin send
1269
- }
1270
- this.queueOrSend({
1271
- type: "tty_input",
1272
- channelId: this.channelId,
1273
- data: Buffer.from(data, "utf8").toString("base64"),
1274
- });
1275
- cb?.();
1276
- return;
1277
- }
1278
- this.queueOrSend({
1279
- type: "tty_input",
1280
- channelId: this.channelId,
1281
- data: Buffer.from(data).toString("base64"),
1282
- });
1283
- cb?.();
1284
- }
1285
- catch (error) {
1286
- cb?.(error instanceof Error ? error : new Error(String(error)));
1287
- }
1288
- }
1289
- close() {
1290
- if (this.closed)
1291
- return;
1292
- this.clearHandshakeTimer();
1293
- this.closed = true;
1294
- this.replayBufferedOutbound = [];
1295
- this.readyState = 3;
1296
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
1297
- try {
1298
- this.sendJson({
1299
- type: "tty_close",
1300
- channelId: this.channelId,
1301
- });
1302
- }
1303
- catch {
1304
- // ignore close send failures
1305
- }
1306
- }
1307
- if (this.ws && this.ws.readyState <= WebSocket.OPEN) {
1308
- try {
1309
- this.ws.close();
1310
- }
1311
- catch {
1312
- // ignore close failures
1313
- }
1314
- }
1315
- this.emit("close", { code: 1000 });
1316
- }
1317
- ping() {
1318
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN)
1319
- return;
1320
- try {
1321
- this.ws.ping();
1322
- }
1323
- catch {
1324
- try {
1325
- this.sendJson({ type: "ping", ts: Date.now() });
1326
- }
1327
- catch {
1328
- // ignore ping failure
1329
- }
1330
- }
1331
- }
1332
- get bufferedAmount() {
1333
- return this.ws?.bufferedAmount ?? 0;
1334
- }
1335
- addEventListener(type, listener) {
1336
- this.listeners[type].add(listener);
1337
- }
1338
- removeEventListener(type, listener) {
1339
- this.listeners[type].delete(listener);
1340
- }
1341
- on(event, listener) {
1342
- if (event !== "pong") {
1343
- return;
1344
- }
1345
- this.pongListeners.add(listener);
1346
- }
1347
- off(event, listener) {
1348
- if (event !== "pong") {
1349
- return;
1350
- }
1351
- this.pongListeners.delete(listener);
1352
- }
1353
- removeListener(event, listener) {
1354
- this.off(event, listener);
1355
- }
1356
- }
1357
- const runDirectDaemonControlRequest = async (args) => {
1358
- const operationId = randomUUID().replace(/-/g, "");
1359
- const executeRequest = async (forceRefresh = false) => {
1360
- const socket = resolveDirectDaemonControlSocket({
1361
- provider: args.provider,
1362
- resolveConnectInfo: args.resolveConnectInfo,
1363
- alias: args.alias,
1364
- ...(forceRefresh ? { forceRefresh: true } : {}),
1365
- });
1366
- return await socket.request({
1367
- requestPayload: args.requestPayload,
1368
- expectedType: args.expectedType,
1369
- timeoutMs: args.timeoutMs,
1370
- ...(forceRefresh ? { forceRefresh: true } : {}),
1371
- });
1372
- };
1373
- let attempt = 0;
1374
- let authRefreshRetried = false;
1375
- let transportRetries = 0;
1376
- let forceRefresh = false;
1377
- while (true) {
1378
- attempt += 1;
1379
- try {
1380
- const response = await executeRequest(forceRefresh);
1381
- if (transportRetries > 0) {
1382
- logger.info("direct_daemon_control_request_retry_recovered", buildDirectDaemonOperationLogFields({
1383
- alias: args.alias,
1384
- provider: args.provider,
1385
- operationId,
1386
- attempt,
1387
- expectedType: args.expectedType,
1388
- requestPayload: args.requestPayload,
1389
- }));
1390
- }
1391
- return response;
1392
- }
1393
- catch (error) {
1394
- if (!authRefreshRetried &&
1395
- isDirectDaemonAuthRefreshError(args.provider, error)) {
1396
- authRefreshRetried = true;
1397
- forceRefresh = true;
1398
- logger.warn("direct_daemon_control_request_auth_retry", {
1399
- ...buildDirectDaemonOperationLogFields({
1400
- alias: args.alias,
1401
- provider: args.provider,
1402
- operationId,
1403
- attempt,
1404
- expectedType: args.expectedType,
1405
- requestPayload: args.requestPayload,
1406
- }),
1407
- nextAttempt: attempt + 1,
1408
- error: error instanceof Error ? error.message : String(error),
1409
- });
1410
- continue;
1411
- }
1412
- if (transportRetries < DIRECT_DAEMON_REQUEST_TRANSPORT_RETRY_LIMIT &&
1413
- isDirectDaemonReplaySafeRequest(args.requestPayload) &&
1414
- isDirectDaemonTransportError(error) &&
1415
- error.retryable) {
1416
- transportRetries += 1;
1417
- forceRefresh = true;
1418
- logger.warn("direct_daemon_control_request_retry", {
1419
- ...buildDirectDaemonOperationLogFields({
1420
- alias: args.alias,
1421
- provider: args.provider,
1422
- operationId,
1423
- attempt,
1424
- expectedType: args.expectedType,
1425
- requestPayload: args.requestPayload,
1426
- }),
1427
- nextAttempt: attempt + 1,
1428
- transportCode: error.transportCode,
1429
- error: error.message,
1430
- });
1431
- continue;
1432
- }
1433
- throw error;
1434
- }
1435
- }
1436
- };
1437
- export { DirectDaemonExecSocket, isDirectDaemonTransportError, runDirectDaemonControlRequest, };
1438
- export const __testOnly = {
1439
- closeAllDirectDaemonControlSocketsForTests,
1440
- setDirectDaemonControlTimingForTests,
1441
- };
1442
- //# sourceMappingURL=directDaemonRuntime.js.map