@elie-laloum/outpost 2.0.0 → 4.0.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 (588) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +3 -1
  3. package/SECURITY.md +3 -1
  4. package/dist/adapters/agents/claude-diagnostics.d.ts +1 -0
  5. package/dist/adapters/agents/claude-diagnostics.js +7 -0
  6. package/dist/adapters/agents/claude-diagnostics.js.map +1 -0
  7. package/dist/adapters/agents/cli-diagnostics.constants.d.ts +12 -0
  8. package/dist/adapters/agents/cli-diagnostics.constants.js +24 -0
  9. package/dist/adapters/agents/cli-diagnostics.constants.js.map +1 -0
  10. package/dist/adapters/agents/cli-diagnostics.d.ts +4 -0
  11. package/dist/adapters/agents/cli-diagnostics.js +14 -0
  12. package/dist/adapters/agents/cli-diagnostics.js.map +1 -0
  13. package/dist/adapters/agents/cli-diagnostics.types.d.ts +13 -0
  14. package/dist/adapters/agents/cli-diagnostics.types.js +2 -0
  15. package/dist/adapters/agents/cli-diagnostics.types.js.map +1 -0
  16. package/dist/adapters/agents/codex-diagnostics.d.ts +1 -0
  17. package/dist/adapters/agents/codex-diagnostics.js +7 -0
  18. package/dist/adapters/agents/codex-diagnostics.js.map +1 -0
  19. package/dist/adapters/agents/gemini-adapter.d.ts +3 -0
  20. package/dist/adapters/agents/gemini-adapter.js +15 -0
  21. package/dist/adapters/agents/gemini-adapter.js.map +1 -0
  22. package/dist/adapters/agents/gemini-diagnostics.d.ts +2 -0
  23. package/dist/adapters/agents/gemini-diagnostics.js +15 -0
  24. package/dist/adapters/agents/gemini-diagnostics.js.map +1 -0
  25. package/dist/adapters/agents/gemini-events.d.ts +2 -0
  26. package/dist/adapters/agents/gemini-events.js +50 -0
  27. package/dist/adapters/agents/gemini-events.js.map +1 -0
  28. package/dist/adapters/agents/gemini-request.d.ts +4 -0
  29. package/dist/adapters/agents/gemini-request.js +21 -0
  30. package/dist/adapters/agents/gemini-request.js.map +1 -0
  31. package/dist/adapters/agents/gemini.types.d.ts +6 -0
  32. package/dist/adapters/agents/gemini.types.js +2 -0
  33. package/dist/adapters/agents/gemini.types.js.map +1 -0
  34. package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -0
  35. package/dist/adapters/agents/protocol-fixtures.constants.js +105 -0
  36. package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -0
  37. package/dist/adapters/agents/protocol-fixtures.types.d.ts +6 -0
  38. package/dist/adapters/agents/protocol-fixtures.types.js +2 -0
  39. package/dist/adapters/agents/protocol-fixtures.types.js.map +1 -0
  40. package/dist/application/agent-bootstrap.constants.d.ts +1 -0
  41. package/dist/application/agent-bootstrap.constants.js +1 -0
  42. package/dist/application/agent-bootstrap.constants.js.map +1 -1
  43. package/dist/application/agent-bootstrap.js +6 -2
  44. package/dist/application/agent-bootstrap.js.map +1 -1
  45. package/dist/application/agent-output.js +9 -2
  46. package/dist/application/agent-output.js.map +1 -1
  47. package/dist/application/artifact-tasks.d.ts +5 -0
  48. package/dist/application/artifact-tasks.js +31 -0
  49. package/dist/application/artifact-tasks.js.map +1 -0
  50. package/dist/application/artifact-tasks.types.d.ts +8 -0
  51. package/dist/application/artifact-tasks.types.js +2 -0
  52. package/dist/application/artifact-tasks.types.js.map +1 -0
  53. package/dist/application/diagnostic-probe.d.ts +3 -0
  54. package/dist/application/diagnostic-probe.js +55 -0
  55. package/dist/application/diagnostic-probe.js.map +1 -0
  56. package/dist/application/dispatch-validation.js +2 -0
  57. package/dist/application/dispatch-validation.js.map +1 -1
  58. package/dist/application/doctor-agent.constants.d.ts +11 -0
  59. package/dist/application/doctor-agent.constants.js +10 -0
  60. package/dist/application/doctor-agent.constants.js.map +1 -0
  61. package/dist/application/doctor-agent.d.ts +3 -0
  62. package/dist/application/doctor-agent.js +53 -0
  63. package/dist/application/doctor-agent.js.map +1 -0
  64. package/dist/application/doctor-image.d.ts +3 -0
  65. package/dist/application/doctor-image.js +133 -0
  66. package/dist/application/doctor-image.js.map +1 -0
  67. package/dist/application/doctor-protocol.d.ts +3 -0
  68. package/dist/application/doctor-protocol.js +30 -0
  69. package/dist/application/doctor-protocol.js.map +1 -0
  70. package/dist/application/doctor-protocol.types.d.ts +10 -0
  71. package/dist/application/doctor-protocol.types.js +2 -0
  72. package/dist/application/doctor-protocol.types.js.map +1 -0
  73. package/dist/application/doctor-sandbox.constants.d.ts +5 -0
  74. package/dist/application/doctor-sandbox.constants.js +6 -0
  75. package/dist/application/doctor-sandbox.constants.js.map +1 -0
  76. package/dist/application/doctor-sandbox.d.ts +4 -0
  77. package/dist/application/doctor-sandbox.js +133 -0
  78. package/dist/application/doctor-sandbox.js.map +1 -0
  79. package/dist/application/doctor-sandbox.types.d.ts +23 -0
  80. package/dist/application/doctor-sandbox.types.js +2 -0
  81. package/dist/application/doctor-sandbox.types.js.map +1 -0
  82. package/dist/application/doctor-transfers.constants.d.ts +6 -0
  83. package/dist/application/doctor-transfers.constants.js +7 -0
  84. package/dist/application/doctor-transfers.constants.js.map +1 -0
  85. package/dist/application/doctor-transfers.d.ts +4 -0
  86. package/dist/application/doctor-transfers.js +88 -0
  87. package/dist/application/doctor-transfers.js.map +1 -0
  88. package/dist/application/doctor.constants.d.ts +9 -0
  89. package/dist/application/doctor.constants.js +15 -0
  90. package/dist/application/doctor.constants.js.map +1 -0
  91. package/dist/application/doctor.d.ts +3 -0
  92. package/dist/application/doctor.js +106 -0
  93. package/dist/application/doctor.js.map +1 -0
  94. package/dist/application/doctor.types.d.ts +39 -0
  95. package/dist/application/doctor.types.js +2 -0
  96. package/dist/application/doctor.types.js.map +1 -0
  97. package/dist/application/execution.js +1 -0
  98. package/dist/application/execution.js.map +1 -1
  99. package/dist/application/outpost.types.d.ts +4 -0
  100. package/dist/application/outpost.types.js.map +1 -1
  101. package/dist/application/queue-worker.d.ts +2 -0
  102. package/dist/application/queue-worker.js +75 -0
  103. package/dist/application/queue-worker.js.map +1 -0
  104. package/dist/application/queue-worker.types.d.ts +15 -0
  105. package/dist/application/queue-worker.types.js +2 -0
  106. package/dist/application/queue-worker.types.js.map +1 -0
  107. package/dist/application/queued-task.d.ts +3 -0
  108. package/dist/application/queued-task.js +56 -0
  109. package/dist/application/queued-task.js.map +1 -0
  110. package/dist/application/queued-task.types.d.ts +11 -0
  111. package/dist/application/queued-task.types.js +2 -0
  112. package/dist/application/queued-task.types.js.map +1 -0
  113. package/dist/application/recovery-checksum-capture.d.ts +2 -0
  114. package/dist/application/recovery-checksum-capture.js +32 -0
  115. package/dist/application/recovery-checksum-capture.js.map +1 -0
  116. package/dist/application/recovery-checksum-paths.d.ts +2 -0
  117. package/dist/application/recovery-checksum-paths.js +11 -0
  118. package/dist/application/recovery-checksum-paths.js.map +1 -0
  119. package/dist/application/recovery-checksums.constants.d.ts +5 -0
  120. package/dist/application/recovery-checksums.constants.js +6 -0
  121. package/dist/application/recovery-checksums.constants.js.map +1 -0
  122. package/dist/application/recovery-checksums.d.ts +3 -0
  123. package/dist/application/recovery-checksums.js +94 -0
  124. package/dist/application/recovery-checksums.js.map +1 -0
  125. package/dist/application/recovery-checksums.types.d.ts +17 -0
  126. package/dist/application/recovery-checksums.types.js +2 -0
  127. package/dist/application/recovery-checksums.types.js.map +1 -0
  128. package/dist/application/recovery-inspection.d.ts +2 -0
  129. package/dist/application/recovery-inspection.js +32 -0
  130. package/dist/application/recovery-inspection.js.map +1 -0
  131. package/dist/application/recovery-inspection.types.d.ts +18 -0
  132. package/dist/application/recovery-inspection.types.js +2 -0
  133. package/dist/application/recovery-inspection.types.js.map +1 -0
  134. package/dist/application/recovery-restorability.d.ts +2 -0
  135. package/dist/application/recovery-restorability.js +137 -0
  136. package/dist/application/recovery-restorability.js.map +1 -0
  137. package/dist/application/recovery-restore-snapshot.d.ts +2 -0
  138. package/dist/application/recovery-restore-snapshot.js +57 -0
  139. package/dist/application/recovery-restore-snapshot.js.map +1 -0
  140. package/dist/application/recovery-restore.d.ts +3 -0
  141. package/dist/application/recovery-restore.js +161 -0
  142. package/dist/application/recovery-restore.js.map +1 -0
  143. package/dist/application/recovery-restore.types.d.ts +28 -0
  144. package/dist/application/recovery-restore.types.js +2 -0
  145. package/dist/application/recovery-restore.types.js.map +1 -0
  146. package/dist/application/recovery-retention-policy.d.ts +2 -0
  147. package/dist/application/recovery-retention-policy.js +21 -0
  148. package/dist/application/recovery-retention-policy.js.map +1 -0
  149. package/dist/application/recovery-retention.constants.d.ts +3 -0
  150. package/dist/application/recovery-retention.constants.js +2 -0
  151. package/dist/application/recovery-retention.constants.js.map +1 -0
  152. package/dist/application/recovery-retention.d.ts +4 -0
  153. package/dist/application/recovery-retention.js +207 -0
  154. package/dist/application/recovery-retention.js.map +1 -0
  155. package/dist/application/recovery-retention.types.d.ts +52 -0
  156. package/dist/application/recovery-retention.types.js +2 -0
  157. package/dist/application/recovery-retention.types.js.map +1 -0
  158. package/dist/application/recovery-verification.constants.d.ts +5 -0
  159. package/dist/application/recovery-verification.constants.js +10 -0
  160. package/dist/application/recovery-verification.constants.js.map +1 -0
  161. package/dist/application/recovery-verification.d.ts +3 -0
  162. package/dist/application/recovery-verification.js +107 -0
  163. package/dist/application/recovery-verification.js.map +1 -0
  164. package/dist/application/recovery-verification.types.d.ts +26 -0
  165. package/dist/application/recovery-verification.types.js +2 -0
  166. package/dist/application/recovery-verification.types.js.map +1 -0
  167. package/dist/application/remote-apply.js +30 -6
  168. package/dist/application/remote-apply.js.map +1 -1
  169. package/dist/application/remote-backup.js +6 -2
  170. package/dist/application/remote-backup.js.map +1 -1
  171. package/dist/application/remote-download.js +38 -6
  172. package/dist/application/remote-download.js.map +1 -1
  173. package/dist/application/remote-history.d.ts +6 -0
  174. package/dist/application/remote-history.js +114 -0
  175. package/dist/application/remote-history.js.map +1 -0
  176. package/dist/application/remote-upload.d.ts +2 -0
  177. package/dist/application/remote-upload.js +17 -0
  178. package/dist/application/remote-upload.js.map +1 -0
  179. package/dist/application/remote-validation.js +39 -28
  180. package/dist/application/remote-validation.js.map +1 -1
  181. package/dist/application/remote-workspace.constants.d.ts +3 -0
  182. package/dist/application/remote-workspace.constants.js +2 -0
  183. package/dist/application/remote-workspace.constants.js.map +1 -0
  184. package/dist/application/remote-workspace.js +10 -10
  185. package/dist/application/remote-workspace.js.map +1 -1
  186. package/dist/application/remote-workspace.types.d.ts +3 -1
  187. package/dist/application/remote-workspace.types.js.map +1 -1
  188. package/dist/application/sandbox-activity.d.ts +3 -0
  189. package/dist/application/sandbox-activity.js +25 -0
  190. package/dist/application/sandbox-activity.js.map +1 -0
  191. package/dist/application/sandbox-provision.js +55 -10
  192. package/dist/application/sandbox-provision.js.map +1 -1
  193. package/dist/application/sandbox-session.types.d.ts +2 -0
  194. package/dist/application/sandbox-session.types.js.map +1 -1
  195. package/dist/application/sandbox.js +33 -10
  196. package/dist/application/sandbox.js.map +1 -1
  197. package/dist/application/speculation-host.d.ts +2 -0
  198. package/dist/application/speculation-host.js +30 -0
  199. package/dist/application/speculation-host.js.map +1 -0
  200. package/dist/application/speculation.constants.d.ts +4 -0
  201. package/dist/application/speculation.constants.js +2 -0
  202. package/dist/application/speculation.constants.js.map +1 -0
  203. package/dist/application/speculation.d.ts +2 -0
  204. package/dist/application/speculation.js +166 -0
  205. package/dist/application/speculation.js.map +1 -0
  206. package/dist/application/speculation.types.d.ts +56 -0
  207. package/dist/application/speculation.types.js +2 -0
  208. package/dist/application/speculation.types.js.map +1 -0
  209. package/dist/application/storage-reservation.d.ts +3 -0
  210. package/dist/application/storage-reservation.js +10 -0
  211. package/dist/application/storage-reservation.js.map +1 -0
  212. package/dist/application/storage-reservation.types.d.ts +4 -0
  213. package/dist/application/storage-reservation.types.js +2 -0
  214. package/dist/application/storage-reservation.types.js.map +1 -0
  215. package/dist/application/task-usage.d.ts +4 -0
  216. package/dist/application/task-usage.js +41 -0
  217. package/dist/application/task-usage.js.map +1 -0
  218. package/dist/application/task-usage.types.d.ts +5 -0
  219. package/dist/application/task-usage.types.js +2 -0
  220. package/dist/application/task-usage.types.js.map +1 -0
  221. package/dist/application/tasks.js +23 -2
  222. package/dist/application/tasks.js.map +1 -1
  223. package/dist/application/tasks.types.d.ts +4 -3
  224. package/dist/application/tasks.types.js.map +1 -1
  225. package/dist/application/workspace-allocation.d.ts +3 -0
  226. package/dist/application/workspace-allocation.js +34 -0
  227. package/dist/application/workspace-allocation.js.map +1 -0
  228. package/dist/application/workspace.js +2 -2
  229. package/dist/application/workspace.js.map +1 -1
  230. package/dist/cli/commands.js +4 -0
  231. package/dist/cli/commands.js.map +1 -1
  232. package/dist/cli/doctor-command.d.ts +3 -0
  233. package/dist/cli/doctor-command.js +38 -0
  234. package/dist/cli/doctor-command.js.map +1 -0
  235. package/dist/cli/main.constants.d.ts +38 -2
  236. package/dist/cli/main.constants.js +21 -2
  237. package/dist/cli/main.constants.js.map +1 -1
  238. package/dist/cli/recovery-command.d.ts +2 -0
  239. package/dist/cli/recovery-command.js +93 -0
  240. package/dist/cli/recovery-command.js.map +1 -0
  241. package/dist/cli/recovery-prune-command.d.ts +2 -0
  242. package/dist/cli/recovery-prune-command.js +34 -0
  243. package/dist/cli/recovery-prune-command.js.map +1 -0
  244. package/dist/cli/recovery-restore-command.d.ts +2 -0
  245. package/dist/cli/recovery-restore-command.js +34 -0
  246. package/dist/cli/recovery-restore-command.js.map +1 -0
  247. package/dist/cli/recovery-verify-command.d.ts +2 -0
  248. package/dist/cli/recovery-verify-command.js +43 -0
  249. package/dist/cli/recovery-verify-command.js.map +1 -0
  250. package/dist/cli/scaffold-files.js +2 -2
  251. package/dist/cli/scaffold-files.js.map +1 -1
  252. package/dist/cli/scaffold-validation.js +1 -1
  253. package/dist/cli/scaffold-validation.js.map +1 -1
  254. package/dist/cli/scaffold.constants.d.ts +5 -0
  255. package/dist/cli/scaffold.constants.js +7 -2
  256. package/dist/cli/scaffold.constants.js.map +1 -1
  257. package/dist/cli/scaffold.types.d.ts +1 -1
  258. package/dist/cli/scaffold.types.js.map +1 -1
  259. package/dist/domain/agent.types.d.ts +2 -0
  260. package/dist/domain/agent.types.js.map +1 -1
  261. package/dist/domain/artifact-reference.d.ts +4 -0
  262. package/dist/domain/artifact-reference.js +90 -0
  263. package/dist/domain/artifact-reference.js.map +1 -0
  264. package/dist/domain/artifact.constants.d.ts +2 -0
  265. package/dist/domain/artifact.constants.js +3 -0
  266. package/dist/domain/artifact.constants.js.map +1 -0
  267. package/dist/domain/artifact.d.ts +7 -0
  268. package/dist/domain/artifact.js +104 -0
  269. package/dist/domain/artifact.js.map +1 -0
  270. package/dist/domain/artifact.types.d.ts +44 -0
  271. package/dist/domain/artifact.types.js +2 -0
  272. package/dist/domain/artifact.types.js.map +1 -0
  273. package/dist/domain/egress.constants.d.ts +1 -0
  274. package/dist/domain/egress.constants.js +7 -0
  275. package/dist/domain/egress.constants.js.map +1 -0
  276. package/dist/domain/egress.d.ts +2 -0
  277. package/dist/domain/egress.js +48 -0
  278. package/dist/domain/egress.js.map +1 -0
  279. package/dist/domain/egress.types.d.ts +8 -0
  280. package/dist/domain/egress.types.js +2 -0
  281. package/dist/domain/egress.types.js.map +1 -0
  282. package/dist/domain/ports.d.ts +1 -1
  283. package/dist/domain/ports.js.map +1 -1
  284. package/dist/domain/sandbox.types.d.ts +13 -0
  285. package/dist/domain/sandbox.types.js.map +1 -1
  286. package/dist/domain/task-queue.constants.d.ts +8 -0
  287. package/dist/domain/task-queue.constants.js +9 -0
  288. package/dist/domain/task-queue.constants.js.map +1 -0
  289. package/dist/domain/task-queue.d.ts +11 -0
  290. package/dist/domain/task-queue.js +105 -0
  291. package/dist/domain/task-queue.js.map +1 -0
  292. package/dist/domain/task-queue.types.d.ts +41 -0
  293. package/dist/domain/task-queue.types.js +2 -0
  294. package/dist/domain/task-queue.types.js.map +1 -0
  295. package/dist/domain/workflow/budget.constants.d.ts +1 -0
  296. package/dist/domain/workflow/budget.constants.js +7 -0
  297. package/dist/domain/workflow/budget.constants.js.map +1 -0
  298. package/dist/domain/workflow/budget.d.ts +9 -0
  299. package/dist/domain/workflow/budget.js +69 -0
  300. package/dist/domain/workflow/budget.js.map +1 -0
  301. package/dist/domain/workflow/budget.types.d.ts +15 -0
  302. package/dist/domain/workflow/budget.types.js +2 -0
  303. package/dist/domain/workflow/budget.types.js.map +1 -0
  304. package/dist/domain/workflow/checkpoint-validation.d.ts +3 -0
  305. package/dist/domain/workflow/checkpoint-validation.js +81 -0
  306. package/dist/domain/workflow/checkpoint-validation.js.map +1 -0
  307. package/dist/domain/workflow/checkpoint-value.d.ts +2 -0
  308. package/dist/domain/workflow/checkpoint-value.js +49 -0
  309. package/dist/domain/workflow/checkpoint-value.js.map +1 -0
  310. package/dist/domain/workflow/checkpoint.d.ts +3 -0
  311. package/dist/domain/workflow/checkpoint.js +70 -0
  312. package/dist/domain/workflow/checkpoint.js.map +1 -0
  313. package/dist/domain/workflow/checkpoint.types.d.ts +40 -0
  314. package/dist/domain/workflow/checkpoint.types.js +2 -0
  315. package/dist/domain/workflow/checkpoint.types.js.map +1 -0
  316. package/dist/domain/workflow/gate-validation.d.ts +4 -0
  317. package/dist/domain/workflow/gate-validation.js +71 -0
  318. package/dist/domain/workflow/gate-validation.js.map +1 -0
  319. package/dist/domain/workflow/gates.constants.d.ts +4 -0
  320. package/dist/domain/workflow/gates.constants.js +5 -0
  321. package/dist/domain/workflow/gates.constants.js.map +1 -0
  322. package/dist/domain/workflow/gates.d.ts +7 -0
  323. package/dist/domain/workflow/gates.js +85 -0
  324. package/dist/domain/workflow/gates.js.map +1 -0
  325. package/dist/domain/workflow/gates.types.d.ts +27 -0
  326. package/dist/domain/workflow/gates.types.js +2 -0
  327. package/dist/domain/workflow/gates.types.js.map +1 -0
  328. package/dist/domain/workflow/task-runner.js +22 -3
  329. package/dist/domain/workflow/task-runner.js.map +1 -1
  330. package/dist/domain/workflow/usage-receipt.constants.d.ts +2 -0
  331. package/dist/domain/workflow/usage-receipt.constants.js +3 -0
  332. package/dist/domain/workflow/usage-receipt.constants.js.map +1 -0
  333. package/dist/domain/workflow/usage-receipt.d.ts +2 -0
  334. package/dist/domain/workflow/usage-receipt.js +18 -0
  335. package/dist/domain/workflow/usage-receipt.js.map +1 -0
  336. package/dist/domain/workflow/validation.js +6 -0
  337. package/dist/domain/workflow/validation.js.map +1 -1
  338. package/dist/domain/workflow/workflow-scheduler.js +68 -33
  339. package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
  340. package/dist/domain/workflow/workflow-state.d.ts +2 -1
  341. package/dist/domain/workflow/workflow-state.js +107 -3
  342. package/dist/domain/workflow/workflow-state.js.map +1 -1
  343. package/dist/domain/workflow.d.ts +2 -0
  344. package/dist/domain/workflow.js +1 -0
  345. package/dist/domain/workflow.js.map +1 -1
  346. package/dist/domain/workflow.types.d.ts +23 -3
  347. package/dist/domain/workflow.types.js.map +1 -1
  348. package/dist/index.d.ts +44 -5
  349. package/dist/index.js +19 -2
  350. package/dist/index.js.map +1 -1
  351. package/dist/infrastructure/artifact-store.constants.d.ts +1 -0
  352. package/dist/infrastructure/artifact-store.constants.js +2 -0
  353. package/dist/infrastructure/artifact-store.constants.js.map +1 -0
  354. package/dist/infrastructure/artifact-store.d.ts +3 -0
  355. package/dist/infrastructure/artifact-store.js +100 -0
  356. package/dist/infrastructure/artifact-store.js.map +1 -0
  357. package/dist/infrastructure/artifact-store.types.d.ts +4 -0
  358. package/dist/infrastructure/artifact-store.types.js +2 -0
  359. package/dist/infrastructure/artifact-store.types.js.map +1 -0
  360. package/dist/infrastructure/file-manifest.d.ts +6 -0
  361. package/dist/infrastructure/file-manifest.js +92 -0
  362. package/dist/infrastructure/file-manifest.js.map +1 -0
  363. package/dist/infrastructure/git/lock-inspection.constants.d.ts +4 -0
  364. package/dist/infrastructure/git/lock-inspection.constants.js +5 -0
  365. package/dist/infrastructure/git/lock-inspection.constants.js.map +1 -0
  366. package/dist/infrastructure/git/lock-inspection.d.ts +3 -0
  367. package/dist/infrastructure/git/lock-inspection.js +64 -0
  368. package/dist/infrastructure/git/lock-inspection.js.map +1 -0
  369. package/dist/infrastructure/git/lock-inspection.types.d.ts +27 -0
  370. package/dist/infrastructure/git/lock-inspection.types.js +2 -0
  371. package/dist/infrastructure/git/lock-inspection.types.js.map +1 -0
  372. package/dist/infrastructure/git/lock.d.ts +1 -0
  373. package/dist/infrastructure/git/lock.js +70 -29
  374. package/dist/infrastructure/git/lock.js.map +1 -1
  375. package/dist/infrastructure/git/process-identity.d.ts +3 -0
  376. package/dist/infrastructure/git/process-identity.js +73 -0
  377. package/dist/infrastructure/git/process-identity.js.map +1 -0
  378. package/dist/infrastructure/git/process-identity.types.d.ts +10 -0
  379. package/dist/infrastructure/git/process-identity.types.js +2 -0
  380. package/dist/infrastructure/git/process-identity.types.js.map +1 -0
  381. package/dist/infrastructure/git/verification-command.d.ts +1 -0
  382. package/dist/infrastructure/git/verification-command.js +37 -0
  383. package/dist/infrastructure/git/verification-command.js.map +1 -0
  384. package/dist/infrastructure/git/workspace-lease.js +1 -0
  385. package/dist/infrastructure/git/workspace-lease.js.map +1 -1
  386. package/dist/infrastructure/git/workspace.js +5 -1
  387. package/dist/infrastructure/git/workspace.js.map +1 -1
  388. package/dist/infrastructure/git/worktree-inspection.constants.d.ts +5 -0
  389. package/dist/infrastructure/git/worktree-inspection.constants.js +16 -0
  390. package/dist/infrastructure/git/worktree-inspection.constants.js.map +1 -0
  391. package/dist/infrastructure/git/worktree-inspection.d.ts +3 -0
  392. package/dist/infrastructure/git/worktree-inspection.js +120 -0
  393. package/dist/infrastructure/git/worktree-inspection.js.map +1 -0
  394. package/dist/infrastructure/git/worktree-inspection.types.d.ts +19 -0
  395. package/dist/infrastructure/git/worktree-inspection.types.js +2 -0
  396. package/dist/infrastructure/git/worktree-inspection.types.js.map +1 -0
  397. package/dist/infrastructure/inspection-file.constants.d.ts +1 -0
  398. package/dist/infrastructure/inspection-file.constants.js +5 -0
  399. package/dist/infrastructure/inspection-file.constants.js.map +1 -0
  400. package/dist/infrastructure/inspection-file.d.ts +1 -0
  401. package/dist/infrastructure/inspection-file.js +43 -0
  402. package/dist/infrastructure/inspection-file.js.map +1 -0
  403. package/dist/infrastructure/inspection-hash.constants.d.ts +1 -0
  404. package/dist/infrastructure/inspection-hash.constants.js +2 -0
  405. package/dist/infrastructure/inspection-hash.constants.js.map +1 -0
  406. package/dist/infrastructure/inspection-hash.d.ts +2 -0
  407. package/dist/infrastructure/inspection-hash.js +62 -0
  408. package/dist/infrastructure/inspection-hash.js.map +1 -0
  409. package/dist/infrastructure/inspection-hash.types.d.ts +5 -0
  410. package/dist/infrastructure/inspection-hash.types.js +2 -0
  411. package/dist/infrastructure/inspection-hash.types.js.map +1 -0
  412. package/dist/infrastructure/journal-retention.constants.d.ts +4 -0
  413. package/dist/infrastructure/journal-retention.constants.js +5 -0
  414. package/dist/infrastructure/journal-retention.constants.js.map +1 -0
  415. package/dist/infrastructure/journal-retention.d.ts +2 -0
  416. package/dist/infrastructure/journal-retention.js +51 -0
  417. package/dist/infrastructure/journal-retention.js.map +1 -0
  418. package/dist/infrastructure/journal.js +37 -13
  419. package/dist/infrastructure/journal.js.map +1 -1
  420. package/dist/infrastructure/opentelemetry.constants.d.ts +10 -0
  421. package/dist/infrastructure/opentelemetry.constants.js +11 -0
  422. package/dist/infrastructure/opentelemetry.constants.js.map +1 -0
  423. package/dist/infrastructure/opentelemetry.d.ts +3 -0
  424. package/dist/infrastructure/opentelemetry.js +131 -0
  425. package/dist/infrastructure/opentelemetry.js.map +1 -0
  426. package/dist/infrastructure/opentelemetry.types.d.ts +21 -0
  427. package/dist/infrastructure/opentelemetry.types.js +2 -0
  428. package/dist/infrastructure/opentelemetry.types.js.map +1 -0
  429. package/dist/infrastructure/resource-activity-inspection.d.ts +2 -0
  430. package/dist/infrastructure/resource-activity-inspection.js +152 -0
  431. package/dist/infrastructure/resource-activity-inspection.js.map +1 -0
  432. package/dist/infrastructure/resource-activity.constants.d.ts +8 -0
  433. package/dist/infrastructure/resource-activity.constants.js +26 -0
  434. package/dist/infrastructure/resource-activity.constants.js.map +1 -0
  435. package/dist/infrastructure/resource-activity.d.ts +2 -0
  436. package/dist/infrastructure/resource-activity.js +166 -0
  437. package/dist/infrastructure/resource-activity.js.map +1 -0
  438. package/dist/infrastructure/resource-activity.types.d.ts +53 -0
  439. package/dist/infrastructure/resource-activity.types.js +2 -0
  440. package/dist/infrastructure/resource-activity.types.js.map +1 -0
  441. package/dist/infrastructure/storage-inventory.constants.d.ts +6 -0
  442. package/dist/infrastructure/storage-inventory.constants.js +11 -0
  443. package/dist/infrastructure/storage-inventory.constants.js.map +1 -0
  444. package/dist/infrastructure/storage-inventory.d.ts +2 -0
  445. package/dist/infrastructure/storage-inventory.js +123 -0
  446. package/dist/infrastructure/storage-inventory.js.map +1 -0
  447. package/dist/infrastructure/storage-inventory.types.d.ts +38 -0
  448. package/dist/infrastructure/storage-inventory.types.js +2 -0
  449. package/dist/infrastructure/storage-inventory.types.js.map +1 -0
  450. package/dist/infrastructure/storage-mutation-lock.constants.d.ts +5 -0
  451. package/dist/infrastructure/storage-mutation-lock.constants.js +6 -0
  452. package/dist/infrastructure/storage-mutation-lock.constants.js.map +1 -0
  453. package/dist/infrastructure/storage-mutation-lock.d.ts +1 -0
  454. package/dist/infrastructure/storage-mutation-lock.js +21 -0
  455. package/dist/infrastructure/storage-mutation-lock.js.map +1 -0
  456. package/dist/infrastructure/storage-reservations.constants.d.ts +4 -0
  457. package/dist/infrastructure/storage-reservations.constants.js +5 -0
  458. package/dist/infrastructure/storage-reservations.constants.js.map +1 -0
  459. package/dist/infrastructure/storage-reservations.d.ts +2 -0
  460. package/dist/infrastructure/storage-reservations.js +150 -0
  461. package/dist/infrastructure/storage-reservations.js.map +1 -0
  462. package/dist/infrastructure/storage-reservations.types.d.ts +21 -0
  463. package/dist/infrastructure/storage-reservations.types.js +2 -0
  464. package/dist/infrastructure/storage-reservations.types.js.map +1 -0
  465. package/dist/infrastructure/task-queue-http.constants.d.ts +2 -0
  466. package/dist/infrastructure/task-queue-http.constants.js +3 -0
  467. package/dist/infrastructure/task-queue-http.constants.js.map +1 -0
  468. package/dist/infrastructure/task-queue-http.d.ts +4 -0
  469. package/dist/infrastructure/task-queue-http.js +158 -0
  470. package/dist/infrastructure/task-queue-http.js.map +1 -0
  471. package/dist/infrastructure/task-queue-http.types.d.ts +16 -0
  472. package/dist/infrastructure/task-queue-http.types.js +2 -0
  473. package/dist/infrastructure/task-queue-http.types.js.map +1 -0
  474. package/dist/infrastructure/task-queue.d.ts +2 -0
  475. package/dist/infrastructure/task-queue.js +134 -0
  476. package/dist/infrastructure/task-queue.js.map +1 -0
  477. package/dist/infrastructure/transfer.js +17 -0
  478. package/dist/infrastructure/transfer.js.map +1 -1
  479. package/dist/infrastructure/workflow-checkpoint.constants.d.ts +1 -0
  480. package/dist/infrastructure/workflow-checkpoint.constants.js +2 -0
  481. package/dist/infrastructure/workflow-checkpoint.constants.js.map +1 -0
  482. package/dist/infrastructure/workflow-checkpoint.d.ts +3 -0
  483. package/dist/infrastructure/workflow-checkpoint.js +77 -0
  484. package/dist/infrastructure/workflow-checkpoint.js.map +1 -0
  485. package/dist/infrastructure/workflow-checkpoint.types.d.ts +4 -0
  486. package/dist/infrastructure/workflow-checkpoint.types.js +2 -0
  487. package/dist/infrastructure/workflow-checkpoint.types.js.map +1 -0
  488. package/dist/providers/agents.d.ts +2 -0
  489. package/dist/providers/agents.js +1 -0
  490. package/dist/providers/agents.js.map +1 -1
  491. package/dist/providers/cloud.constants.d.ts +1 -0
  492. package/dist/providers/cloud.constants.js +1 -0
  493. package/dist/providers/cloud.constants.js.map +1 -1
  494. package/dist/providers/container-cache.constants.d.ts +11 -0
  495. package/dist/providers/container-cache.constants.js +9 -0
  496. package/dist/providers/container-cache.constants.js.map +1 -0
  497. package/dist/providers/container-cache.d.ts +4 -0
  498. package/dist/providers/container-cache.js +48 -0
  499. package/dist/providers/container-cache.js.map +1 -0
  500. package/dist/providers/container-cache.types.d.ts +8 -0
  501. package/dist/providers/container-cache.types.js +2 -0
  502. package/dist/providers/container-cache.types.js.map +1 -0
  503. package/dist/providers/container-isolation.d.ts +2 -0
  504. package/dist/providers/container-isolation.js +29 -0
  505. package/dist/providers/container-isolation.js.map +1 -0
  506. package/dist/providers/container-mounts.js +7 -2
  507. package/dist/providers/container-mounts.js.map +1 -1
  508. package/dist/providers/container-network.d.ts +2 -0
  509. package/dist/providers/container-network.js +14 -0
  510. package/dist/providers/container-network.js.map +1 -0
  511. package/dist/providers/container-plan.js +6 -2
  512. package/dist/providers/container-plan.js.map +1 -1
  513. package/dist/providers/container.constants.d.ts +1 -0
  514. package/dist/providers/container.constants.js +1 -0
  515. package/dist/providers/container.constants.js.map +1 -1
  516. package/dist/providers/container.js +50 -3
  517. package/dist/providers/container.js.map +1 -1
  518. package/dist/providers/container.types.d.ts +5 -0
  519. package/dist/providers/container.types.js.map +1 -1
  520. package/dist/providers/daytona-command.js +10 -6
  521. package/dist/providers/daytona-command.js.map +1 -1
  522. package/dist/providers/daytona-terminal.d.ts +3 -0
  523. package/dist/providers/daytona-terminal.js +128 -0
  524. package/dist/providers/daytona-terminal.js.map +1 -0
  525. package/dist/providers/daytona.js +15 -4
  526. package/dist/providers/daytona.js.map +1 -1
  527. package/dist/providers/diagnostic-container.d.ts +4 -0
  528. package/dist/providers/diagnostic-container.js +15 -0
  529. package/dist/providers/diagnostic-container.js.map +1 -0
  530. package/dist/providers/docker.d.ts +2 -0
  531. package/dist/providers/docker.js.map +1 -1
  532. package/dist/providers/file-batches.constants.d.ts +10 -0
  533. package/dist/providers/file-batches.constants.js +57 -0
  534. package/dist/providers/file-batches.constants.js.map +1 -0
  535. package/dist/providers/file-batches.d.ts +2 -0
  536. package/dist/providers/file-batches.js +160 -0
  537. package/dist/providers/file-batches.js.map +1 -0
  538. package/dist/providers/file-upload.constants.d.ts +1 -0
  539. package/dist/providers/file-upload.constants.js +68 -0
  540. package/dist/providers/file-upload.constants.js.map +1 -0
  541. package/dist/providers/file-upload.d.ts +2 -0
  542. package/dist/providers/file-upload.js +146 -0
  543. package/dist/providers/file-upload.js.map +1 -0
  544. package/dist/providers/firecracker-command.d.ts +5 -0
  545. package/dist/providers/firecracker-command.js +114 -0
  546. package/dist/providers/firecracker-command.js.map +1 -0
  547. package/dist/providers/firecracker-files.constants.d.ts +1 -0
  548. package/dist/providers/firecracker-files.constants.js +21 -0
  549. package/dist/providers/firecracker-files.constants.js.map +1 -0
  550. package/dist/providers/firecracker-files.d.ts +3 -0
  551. package/dist/providers/firecracker-files.js +110 -0
  552. package/dist/providers/firecracker-files.js.map +1 -0
  553. package/dist/providers/firecracker-machine.d.ts +3 -0
  554. package/dist/providers/firecracker-machine.js +155 -0
  555. package/dist/providers/firecracker-machine.js.map +1 -0
  556. package/dist/providers/firecracker.constants.d.ts +10 -0
  557. package/dist/providers/firecracker.constants.js +11 -0
  558. package/dist/providers/firecracker.constants.js.map +1 -0
  559. package/dist/providers/firecracker.d.ts +4 -0
  560. package/dist/providers/firecracker.js +103 -0
  561. package/dist/providers/firecracker.js.map +1 -0
  562. package/dist/providers/firecracker.types.d.ts +36 -0
  563. package/dist/providers/firecracker.types.js +2 -0
  564. package/dist/providers/firecracker.types.js.map +1 -0
  565. package/dist/providers/local.js +2 -1
  566. package/dist/providers/local.js.map +1 -1
  567. package/dist/providers/podman.d.ts +2 -0
  568. package/dist/providers/podman.js.map +1 -1
  569. package/dist/providers/terminal-bridge.d.ts +14 -0
  570. package/dist/providers/terminal-bridge.js +100 -0
  571. package/dist/providers/terminal-bridge.js.map +1 -0
  572. package/dist/providers/vercel-directory.d.ts +2 -0
  573. package/dist/providers/vercel-directory.js +7 -0
  574. package/dist/providers/vercel-directory.js.map +1 -0
  575. package/dist/providers/vercel-files.js +3 -2
  576. package/dist/providers/vercel-files.js.map +1 -1
  577. package/dist/providers/vercel-network.d.ts +2 -0
  578. package/dist/providers/vercel-network.js +18 -0
  579. package/dist/providers/vercel-network.js.map +1 -0
  580. package/dist/providers/vercel.d.ts +1 -0
  581. package/dist/providers/vercel.js +8 -2
  582. package/dist/providers/vercel.js.map +1 -1
  583. package/dist/providers/vercel.types.d.ts +2 -0
  584. package/dist/providers/vercel.types.js.map +1 -1
  585. package/dist/providers/versions.constants.d.ts +1 -0
  586. package/dist/providers/versions.constants.js +1 -0
  587. package/dist/providers/versions.constants.js.map +1 -1
  588. package/package.json +16 -1
@@ -0,0 +1,128 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { setTimeout } from "node:timers/promises";
3
+ import { OutpostError } from "../domain/errors.js";
4
+ import { interruptible } from "../infrastructure/abort.js";
5
+ import { quote } from "../infrastructure/process.js";
6
+ import { cloudDefaults } from "./cloud.constants.js";
7
+ import { terminalBridge } from "./terminal-bridge.js";
8
+ export async function daytonaTerminal(runtime, command, signal) {
9
+ const { sandbox, root, options, context } = runtime;
10
+ const id = `outpost-${randomUUID()}`;
11
+ const base = `/tmp/${id}`;
12
+ const program = [
13
+ ...(command.elevated ? ["sudo", "-n", "--"] : []),
14
+ command.executable,
15
+ ...(command.arguments ?? []),
16
+ ]
17
+ .map(quote)
18
+ .join(" ");
19
+ const script = `kill -0 -$$ 2>/dev/null || exit 125
20
+ echo $$ > ${quote(base + ".pid")}
21
+ ${program}
22
+ status=$?
23
+ printf '%s' "$status" > ${quote(base + ".status")}
24
+ exit "$status"
25
+ `;
26
+ let handle;
27
+ let bridge;
28
+ let completed = false;
29
+ let creating = false;
30
+ let failure;
31
+ try {
32
+ await sandbox.fs.uploadFile(Buffer.from(script), base);
33
+ signal.throwIfAborted();
34
+ bridge = terminalBridge(command, command.retain ?? options.retain ?? cloudDefaults.retainBytes);
35
+ // createPty owns its connection timeout; await ownership before cancellation cleanup.
36
+ creating = true;
37
+ handle = await sandbox.process.createPty({
38
+ id,
39
+ cwd: command.directory ?? root,
40
+ envs: {
41
+ TERM: process.env.TERM ?? "xterm-256color",
42
+ ...context.variables,
43
+ ...command.variables,
44
+ },
45
+ ...bridge.size(),
46
+ onData: bridge.output,
47
+ });
48
+ signal.throwIfAborted();
49
+ await interruptible(handle.sendInput(`exec sh ${quote(base)}\n`), signal);
50
+ bridge.connect(handle);
51
+ if (command.stdin !== undefined)
52
+ await interruptible(handle.sendInput(command.stdin), signal);
53
+ let nativeStatus;
54
+ const nativeFailure = handle.wait().then((exit) => {
55
+ nativeStatus = exit.exitCode;
56
+ if (exit.error && exit.exitCode === undefined)
57
+ throw new OutpostError("provider", `Daytona terminal failed: ${exit.error}`);
58
+ return new Promise(() => { });
59
+ });
60
+ void nativeFailure.catch(() => undefined);
61
+ // The SDK can infer success from socket closure; the script records process completion.
62
+ while (true) {
63
+ const status = await interruptible(Promise.race([
64
+ sandbox.process.executeCommand(`if [ -f ${quote(base + ".status")} ]; then cat ${quote(base + ".status")}; else exit 3; fi`),
65
+ bridge.failure,
66
+ nativeFailure,
67
+ ]), signal);
68
+ const recorded = status.exitCode === 0 && /^\d+$/.test(status.result.trim());
69
+ if (recorded ||
70
+ (status.exitCode === 3 &&
71
+ nativeStatus !== undefined &&
72
+ nativeStatus !== 0)) {
73
+ completed = true;
74
+ await interruptible(bridge.flush(), signal);
75
+ return {
76
+ status: recorded ? Number(status.result.trim()) : nativeStatus,
77
+ stdout: bridge.text(),
78
+ stderr: "",
79
+ };
80
+ }
81
+ if (status.exitCode !== 3)
82
+ throw new OutpostError("provider", "Daytona terminal returned invalid completion status");
83
+ await Promise.race([
84
+ setTimeout(cloudDefaults.pollMs, undefined, { signal }),
85
+ bridge.failure,
86
+ nativeFailure,
87
+ ]);
88
+ }
89
+ }
90
+ catch (cause) {
91
+ failure = signal.aborted ? signal.reason : cause;
92
+ throw failure;
93
+ }
94
+ finally {
95
+ const errors = [];
96
+ const cleanup = async (operation) => {
97
+ try {
98
+ await interruptible(Promise.resolve().then(operation), AbortSignal.timeout(cloudDefaults.cancellationMs));
99
+ }
100
+ catch (cause) {
101
+ errors.push(cause);
102
+ }
103
+ };
104
+ await cleanup(() => bridge?.close());
105
+ if (!completed) {
106
+ // The native PTY already supplies a session; terminate its existing process group.
107
+ const kill = `if [ -f ${quote(base + ".pid")} ]; then p=$(cat ${quote(base + ".pid")}); kill -KILL -"$p" 2>/dev/null || true; fi`;
108
+ await cleanup(() => sandbox.process.executeCommand(command.elevated ? `sudo -n sh -c ${quote(kill)}` : kill));
109
+ if (creating)
110
+ await cleanup(async () => {
111
+ try {
112
+ if (handle)
113
+ return await handle.kill();
114
+ await sandbox.process.killPtySession(id);
115
+ }
116
+ catch (cause) {
117
+ if (!(cause instanceof Error && cause.name === "DaytonaNotFoundError"))
118
+ throw cause;
119
+ }
120
+ });
121
+ }
122
+ await cleanup(() => handle?.disconnect());
123
+ await cleanup(() => sandbox.process.executeCommand(`rm -f ${quote(base)} ${quote(base + ".pid")} ${quote(base + ".status")}`));
124
+ if (errors.length)
125
+ throw new AggregateError(failure === undefined ? errors : [failure, ...errors], "Daytona terminal cleanup failed");
126
+ }
127
+ }
128
+ //# sourceMappingURL=daytona-terminal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"daytona-terminal.js","sourceRoot":"","sources":["../../src/providers/daytona-terminal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAuB,EACvB,OAAgB,EAChB,MAAmB;IAEnB,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACpD,MAAM,EAAE,GAAG,WAAW,UAAU,EAAE,EAAE,CAAC;IACrC,MAA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AAS,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,EAAE,CAC1E,CACF,CAAC;QACF,IAAI,MAAM,CAAC,MAAM;YACf,MAAM,IAAI,cAAc,CACtB,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,EACrD,iCAAiC,CAClC,CAAC;IACN,CAAC;AACH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { setTimeout } from \"node:timers/promises\";\nimport type { PtyHandle } from \"@daytona/sdk\";\nimport type { Command, CommandResult } from \"../domain/command.types.ts\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport { interruptible } from \"../infrastructure/abort.ts\";\nimport { quote } from \"../infrastructure/process.ts\";\nimport { cloudDefaults } from \"./cloud.constants.ts\";\nimport type { DaytonaRuntime } from \"./daytona.types.ts\";\nimport { terminalBridge } from \"./terminal-bridge.ts\";\n\nexport async function daytonaTerminal(\n runtime: DaytonaRuntime,\n command: Command,\n signal: AbortSignal,\n): Promise<CommandResult> {\n const { sandbox, root, options, context } = runtime;\n const id = `outpost-${randomUUID()}`;\n const base = `/tmp/${id}`;\n const program = [\n ...(command.elevated ? [\"sudo\", \"-n\", \"--\"] : []),\n command.executable,\n ...(command.arguments ?? []),\n ]\n .map(quote)\n .join(\" \");\n const script = `kill -0 -$$ 2>/dev/null || exit 125\necho $$ > ${quote(base + \".pid\")}\n${program}\nstatus=$?\nprintf '%s' \"$status\" > ${quote(base + \".status\")}\nexit \"$status\"\n`;\n let handle: PtyHandle | undefined;\n let bridge: ReturnType<typeof terminalBridge> | undefined;\n let completed = false;\n let creating = false;\n let failure: unknown;\n try {\n await sandbox.fs.uploadFile(Buffer.from(script), base);\n signal.throwIfAborted();\n bridge = terminalBridge(\n command,\n command.retain ?? options.retain ?? cloudDefaults.retainBytes,\n );\n // createPty owns its connection timeout; await ownership before cancellation cleanup.\n creating = true;\n handle = await sandbox.process.createPty({\n id,\n cwd: command.directory ?? root,\n envs: {\n TERM: process.env.TERM ?? \"xterm-256color\",\n ...context.variables,\n ...command.variables,\n },\n ...bridge.size(),\n onData: bridge.output,\n });\n signal.throwIfAborted();\n await interruptible(handle.sendInput(`exec sh ${quote(base)}\\n`), signal);\n bridge.connect(handle);\n if (command.stdin !== undefined)\n await interruptible(handle.sendInput(command.stdin), signal);\n let nativeStatus: number | undefined;\n const nativeFailure = handle.wait().then((exit) => {\n nativeStatus = exit.exitCode;\n if (exit.error && exit.exitCode === undefined)\n throw new OutpostError(\n \"provider\",\n `Daytona terminal failed: ${exit.error}`,\n );\n return new Promise<never>(() => {});\n });\n void nativeFailure.catch(() => undefined);\n // The SDK can infer success from socket closure; the script records process completion.\n while (true) {\n const status = await interruptible(\n Promise.race([\n sandbox.process.executeCommand(\n `if [ -f ${quote(base + \".status\")} ]; then cat ${quote(base + \".status\")}; else exit 3; fi`,\n ),\n bridge.failure,\n nativeFailure,\n ]),\n signal,\n );\n const recorded =\n status.exitCode === 0 && /^\\d+$/.test(status.result.trim());\n if (\n recorded ||\n (status.exitCode === 3 &&\n nativeStatus !== undefined &&\n nativeStatus !== 0)\n ) {\n completed = true;\n await interruptible(bridge.flush(), signal);\n return {\n status: recorded ? Number(status.result.trim()) : nativeStatus!,\n stdout: bridge.text(),\n stderr: \"\",\n };\n }\n if (status.exitCode !== 3)\n throw new OutpostError(\n \"provider\",\n \"Daytona terminal returned invalid completion status\",\n );\n await Promise.race([\n setTimeout(cloudDefaults.pollMs, undefined, { signal }),\n bridge.failure,\n nativeFailure,\n ]);\n }\n } catch (cause) {\n failure = signal.aborted ? signal.reason : cause;\n throw failure;\n } finally {\n const errors: unknown[] = [];\n const cleanup = async (operation: () => unknown) => {\n try {\n await interruptible(\n Promise.resolve().then(operation),\n AbortSignal.timeout(cloudDefaults.cancellationMs),\n );\n } catch (cause) {\n errors.push(cause);\n }\n };\n await cleanup(() => bridge?.close());\n if (!completed) {\n // The native PTY already supplies a session; terminate its existing process group.\n const kill = `if [ -f ${quote(base + \".pid\")} ]; then p=$(cat ${quote(base + \".pid\")}); kill -KILL -\"$p\" 2>/dev/null || true; fi`;\n await cleanup(() =>\n sandbox.process.executeCommand(\n command.elevated ? `sudo -n sh -c ${quote(kill)}` : kill,\n ),\n );\n if (creating)\n await cleanup(async () => {\n try {\n if (handle) return await handle.kill();\n await sandbox.process.killPtySession(id);\n } catch (cause) {\n if (!(\n cause instanceof Error && cause.name === \"DaytonaNotFoundError\"\n ))\n throw cause;\n }\n });\n }\n await cleanup(() => handle?.disconnect());\n await cleanup(() =>\n sandbox.process.executeCommand(\n `rm -f ${quote(base)} ${quote(base + \".pid\")} ${quote(base + \".status\")}`,\n ),\n );\n if (errors.length)\n throw new AggregateError(\n failure === undefined ? errors : [failure, ...errors],\n \"Daytona terminal cleanup failed\",\n );\n }\n}\n"]}
@@ -1,9 +1,12 @@
1
+ import { invariant } from "../domain/errors.js";
1
2
  import { posix } from "node:path";
3
+ import { fileBatches } from "./file-batches.js";
2
4
  import { registerCleanup } from "../infrastructure/shutdown.js";
3
5
  import { cloudRoots } from "./cloud.constants.js";
4
6
  import { daytonaCommand } from "./daytona-command.js";
5
7
  import { daytonaFiles } from "./daytona-files.js";
6
8
  export function daytona(options = {}, connect = async (config) => new (await import("@daytona/sdk")).Daytona(config)) {
9
+ invariant(!("egress" in options) || options.egress === undefined, "Daytona does not support Outpost egress policies; configure provider-native networking explicitly");
7
10
  return {
8
11
  name: "daytona",
9
12
  placement: "remote",
@@ -12,8 +15,6 @@ export function daytona(options = {}, connect = async (config) => new (await imp
12
15
  context.signal?.throwIfAborted();
13
16
  const client = await connect(options.connection);
14
17
  const sandbox = await client.create(options.create ?? {});
15
- const home = (await sandbox.getUserHomeDir()) ?? cloudRoots.daytonaHome;
16
- const root = options.root ?? posix.join(home, "outpost");
17
18
  let closed = false, releasing;
18
19
  let unregister = () => { };
19
20
  const release = () => (releasing ??= client
@@ -27,14 +28,23 @@ export function daytona(options = {}, connect = async (config) => new (await imp
27
28
  throw error;
28
29
  }));
29
30
  unregister = registerCleanup(release);
31
+ let home;
32
+ let root;
30
33
  try {
34
+ home = (await sandbox.getUserHomeDir()) ?? cloudRoots.daytonaHome;
35
+ root = options.root ?? posix.join(home, "outpost");
31
36
  await sandbox.fs.createFolder(root, "755");
32
37
  }
33
38
  catch (cause) {
34
- await release();
39
+ try {
40
+ await release();
41
+ }
42
+ catch (cleanup) {
43
+ throw new AggregateError([cause, cleanup], "Cloud setup and cleanup failed");
44
+ }
35
45
  throw cause;
36
46
  }
37
- return {
47
+ const lease = {
38
48
  root,
39
49
  home,
40
50
  invoke: daytonaCommand({
@@ -47,6 +57,7 @@ export function daytona(options = {}, connect = async (config) => new (await imp
47
57
  ...daytonaFiles(sandbox),
48
58
  release,
49
59
  };
60
+ return { ...lease, fileTransfers: fileBatches(lease) };
50
61
  },
51
62
  };
52
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"daytona.js","sourceRoot":"","sources":["../../src/providers/daytona.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAKlD,MAAM,UAAU,OAAO,CACrB,UAA0B,EAAE,EAC5B,UAEmD,KAAK,EAAE,MAAM,EAAE,EAAE,CAClE,IAAI,CAAC,MAAM,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAEpD,OAAO;QACL,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,QAAQ;QACnB,SAAS,EAAE,EAAE,GAAG,OAAO,CAA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ACP,IAAI;oBACJ,OAAO;oBACP,OAAO;oBACP,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM;iBACvB,CAAC;gBACF,GAAG,YAAY,CAAC,OAAO,CAAC;gBACxB,OAAO;aACR,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { Daytona, DaytonaConfig } from \"@daytona/sdk\";\nimport { posix } from \"node:path\";\nimport type { SandboxProvider } from \"../domain/sandbox.types.ts\";\nimport { registerCleanup } from \"../infrastructure/shutdown.ts\";\nimport { cloudRoots } from \"./cloud.constants.ts\";\nimport { daytonaCommand } from \"./daytona-command.ts\";\nimport { daytonaFiles } from \"./daytona-files.ts\";\nimport type { DaytonaOptions } from \"./daytona.types.ts\";\n\nexport type { DaytonaOptions } from \"./daytona.types.ts\";\n\nexport function daytona(\n options: DaytonaOptions = {},\n connect: (\n config?: DaytonaConfig,\n ) => Promise<Pick<Daytona, \"create\" | \"delete\">> = async (config) =>\n new (await import(\"@daytona/sdk\")).Daytona(config),\n): SandboxProvider {\n return {\n name: \"daytona\",\n placement: \"remote\",\n variables: { ...options.variables },\n async acquire(context) {\n context.signal?.throwIfAborted();\n const client = await connect(options.connection);\n const sandbox = await client.create(options.create ?? {});\n const home = (await sandbox.getUserHomeDir()) ?? cloudRoots.daytonaHome;\n const root = options.root ?? posix.join(home, \"outpost\");\n let closed = false,\n releasing: Promise<void> | undefined;\n let unregister = () => {};\n const release = () =>\n (releasing ??= client\n .delete(sandbox)\n .then(() => {\n closed = true;\n unregister();\n })\n .catch((error) => {\n releasing = undefined;\n throw error;\n }));\n unregister = registerCleanup(release);\n try {\n await sandbox.fs.createFolder(root, \"755\");\n } catch (cause) {\n await release();\n throw cause;\n }\n return {\n root,\n home,\n invoke: daytonaCommand({\n sandbox,\n root,\n options,\n context,\n isClosed: () => closed,\n }),\n ...daytonaFiles(sandbox),\n release,\n };\n },\n };\n}\n"]}
1
+ {"version":3,"file":"daytona.js","sourceRoot":"","sources":["../../src/providers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C;AACJ,CAAC","sourcesContent":["import type { Daytona, DaytonaConfig } from \"@daytona/sdk\";\nimport { invariant } from \"../domain/errors.ts\";\nimport { posix } from \"node:path\";\nimport type { SandboxProvider } from \"../domain/sandbox.types.ts\";\nimport { fileBatches } from \"./file-batches.ts\";\nimport { registerCleanup } from \"../infrastructure/shutdown.ts\";\nimport { cloudRoots } from \"./cloud.constants.ts\";\nimport { daytonaCommand } from \"./daytona-command.ts\";\nimport { daytonaFiles } from \"./daytona-files.ts\";\nimport type { DaytonaOptions } from \"./daytona.types.ts\";\n\nexport type { DaytonaOptions } from \"./daytona.types.ts\";\n\nexport function daytona(\n options: DaytonaOptions = {},\n connect: (\n config?: DaytonaConfig,\n ) => Promise<Pick<Daytona, \"create\" | \"delete\">> = async (config) =>\n new (await import(\"@daytona/sdk\")).Daytona(config),\n): SandboxProvider {\n invariant(\n !(\"egress\" in options) || options.egress === undefined,\n \"Daytona does not support Outpost egress policies; configure provider-native networking explicitly\",\n );\n return {\n name: \"daytona\",\n placement: \"remote\",\n variables: { ...options.variables },\n async acquire(context) {\n context.signal?.throwIfAborted();\n const client = await connect(options.connection);\n const sandbox = await client.create(options.create ?? {});\n let closed = false,\n releasing: Promise<void> | undefined;\n let unregister = () => {};\n const release = () =>\n (releasing ??= client\n .delete(sandbox)\n .then(() => {\n closed = true;\n unregister();\n })\n .catch((error) => {\n releasing = undefined;\n throw error;\n }));\n unregister = registerCleanup(release);\n let home: string;\n let root: string;\n try {\n home = (await sandbox.getUserHomeDir()) ?? cloudRoots.daytonaHome;\n root = options.root ?? posix.join(home, \"outpost\");\n await sandbox.fs.createFolder(root, \"755\");\n } catch (cause) {\n try {\n await release();\n } catch (cleanup) {\n throw new AggregateError(\n [cause, cleanup],\n \"Cloud setup and cleanup failed\",\n );\n }\n throw cause;\n }\n const lease = {\n root,\n home,\n invoke: daytonaCommand({\n sandbox,\n root,\n options,\n context,\n isClosed: () => closed,\n }),\n ...daytonaFiles(sandbox),\n release,\n };\n return { ...lease, fileTransfers: fileBatches(lease) };\n },\n };\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { SandboxProvider } from "../domain/sandbox.types.ts";
2
+ import type { Executor } from "../infrastructure/process.types.ts";
3
+ import type { ContainerEngine } from "./container.types.ts";
4
+ export declare function diagnosticContainer(engine: ContainerEngine, image: string, deadlineMs: number, execute?: Executor): SandboxProvider;
@@ -0,0 +1,15 @@
1
+ import { executeProcess } from "../infrastructure/process.js";
2
+ import { containerProvider } from "./container.js";
3
+ export function diagnosticContainer(engine, image, deadlineMs, execute = executeProcess) {
4
+ return containerProvider(engine, { image, networks: "none" }, (command) => {
5
+ const args = command.arguments ?? [];
6
+ return execute({
7
+ ...command,
8
+ deadlineMs: Math.min(command.deadlineMs ?? deadlineMs, deadlineMs),
9
+ arguments: args[0] === "create"
10
+ ? ["create", "--pull=never", ...args.slice(1)]
11
+ : args,
12
+ });
13
+ });
14
+ }
15
+ //# sourceMappingURL=diagnostic-container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diagnostic-container.js","sourceRoot":"","sources":["../../src/providers/diagnostic-container.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,MAAM,UAAU,mBAAmB,CACjC,MAAuB,EACvB,KAAa,EACb,UAAkB,EAClB,UAAoB,cAAc;IAElC,OAAO,iBAAiB,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,OAAO,EAAE,EAAE;QACxE,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;QACrC,OAAO,OAAO,CAAC;YACb,GAAG,OAAO;YACV,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,IAAI,UAAU,EAAE,UAAU,CAAC;YAClE,SAAS,EACP,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;gBAClB,CAAC,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAC9C,CAAC,CAAC,IAAI;SACX,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { SandboxProvider } from \"../domain/sandbox.types.ts\";\nimport { executeProcess } from \"../infrastructure/process.ts\";\nimport type { Executor } from \"../infrastructure/process.types.ts\";\nimport { containerProvider } from \"./container.ts\";\nimport type { ContainerEngine } from \"./container.types.ts\";\n\nexport function diagnosticContainer(\n engine: ContainerEngine,\n image: string,\n deadlineMs: number,\n execute: Executor = executeProcess,\n): SandboxProvider {\n return containerProvider(engine, { image, networks: \"none\" }, (command) => {\n const args = command.arguments ?? [];\n return execute({\n ...command,\n deadlineMs: Math.min(command.deadlineMs ?? deadlineMs, deadlineMs),\n arguments:\n args[0] === \"create\"\n ? [\"create\", \"--pull=never\", ...args.slice(1)]\n : args,\n });\n });\n}\n"]}
@@ -1,3 +1,5 @@
1
1
  import type { ContainerOptions } from "./container.types.ts";
2
2
  export type { ContainerOptions } from "./container.ts";
3
3
  export declare const docker: (options?: ContainerOptions) => import("../index.ts").SandboxProvider;
4
+ export type { DependencyCache } from "./container-cache.types.ts";
5
+ export type { EgressPolicy } from "../domain/egress.types.ts";
@@ -1 +1 @@
1
- {"version":3,"file":"docker.js","sourceRoot":"","sources":["../../src/providers/docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKnD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,UAA4B,EAAE,EAAE,EAAE,CACvD,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import { containerProvider } from \"./container.ts\";\nimport type { ContainerOptions } from \"./container.types.ts\";\n\nexport type { ContainerOptions } from \"./container.ts\";\n\nexport const docker = (options: ContainerOptions = {}) =>\n containerProvider(\"docker\", options);\n"]}
1
+ {"version":3,"file":"docker.js","sourceRoot":"","sources":["../../src/providers/docker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKnD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,UAA4B,EAAE,EAAE,EAAE,CACvD,iBAAiB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC","sourcesContent":["import { containerProvider } from \"./container.ts\";\nimport type { ContainerOptions } from \"./container.types.ts\";\n\nexport type { ContainerOptions } from \"./container.ts\";\n\nexport const docker = (options: ContainerOptions = {}) =>\n containerProvider(\"docker\", options);\n\nexport type { DependencyCache } from \"./container-cache.types.ts\";\n\nexport type { EgressPolicy } from \"../domain/egress.types.ts\";\n"]}
@@ -0,0 +1,10 @@
1
+ export declare const fileBatchLimits: {
2
+ readonly bytes: number;
3
+ readonly entries: 128;
4
+ readonly argumentBytes: number;
5
+ readonly cleanupMs: 10000;
6
+ readonly manifestBytes: number;
7
+ readonly decodedBytes: number;
8
+ };
9
+ export declare const fileBatchScript: string;
10
+ export declare const fileBatchCleanupScript = "require(\"node:fs\").rmSync(process.argv[1], { force: true })";
@@ -0,0 +1,57 @@
1
+ export const fileBatchLimits = {
2
+ bytes: 8 * 1024 * 1024,
3
+ entries: 128,
4
+ argumentBytes: 48 * 1024,
5
+ cleanupMs: 10_000,
6
+ manifestBytes: 2 * 1024 * 1024,
7
+ decodedBytes: 16 * 1024 * 1024,
8
+ };
9
+ export const fileBatchScript = String.raw `
10
+ const fs = require('node:fs'), p = require('node:path'), c = require('node:crypto'), z = require('node:zlib');
11
+ const [operation, root, input, output] = process.argv.slice(1), entries = JSON.parse(input);
12
+ function safe(path) {
13
+ if (!path || p.isAbsolute(path) || path.includes('\\') || path.includes('\0') || path.split('/').some(x => x === '..' || x.toLowerCase() === '.git')) throw Error('Unsafe transfer path');
14
+ const target = p.resolve(root, path);
15
+ let parent = p.dirname(target);
16
+ while (true) {
17
+ if (fs.lstatSync(parent).isSymbolicLink()) throw Error('Transfer path traverses symlink');
18
+ if (parent === p.resolve(root)) break;
19
+ parent = p.dirname(parent);
20
+ }
21
+ return target;
22
+ }
23
+ async function inspect(path, expected) {
24
+ const dataRequired = expected !== undefined;
25
+ const target = safe(path), stat = fs.lstatSync(target), hash = c.createHash('sha256');
26
+ if (!stat.isFile() && !stat.isSymbolicLink()) throw Error('Unsupported transfer file');
27
+ if (expected && stat.isFile() && stat.size !== expected.size) throw Error('Remote file changed during transfer');
28
+ let data, size = stat.size;
29
+ if (stat.isSymbolicLink()) { data = Buffer.from(fs.readlinkSync(target)); size = data.length; hash.update(data); }
30
+ else {
31
+ const chunks = []; let bytes = 0;
32
+ for await (const chunk of fs.createReadStream(target)) {
33
+ hash.update(chunk);
34
+ if (dataRequired) {
35
+ bytes += chunk.length;
36
+ if (bytes > expected.size) throw Error('Remote file changed during transfer');
37
+ chunks.push(chunk);
38
+ }
39
+ }
40
+ if (dataRequired) data = Buffer.concat(chunks);
41
+ }
42
+ const entry = { path, kind: stat.isSymbolicLink() ? 'link' : 'file', mode: stat.mode & 511, size, sha256: hash.digest('hex') };
43
+ return dataRequired ? { ...entry, data: data.toString('base64') } : entry;
44
+ }
45
+ (async () => {
46
+ const result = [];
47
+ for (const entry of entries) {
48
+ const item = await inspect(operation === 'manifest' ? entry : entry.path, operation === 'batch' ? entry : undefined);
49
+ if (operation === 'batch' && ['path', 'kind', 'mode', 'size', 'sha256'].some(key => item[key] !== entry[key])) throw Error('Remote file changed during transfer');
50
+ result.push(item);
51
+ }
52
+ if (operation === 'manifest') { process.stdout.write(JSON.stringify(result)); return; }
53
+ fs.writeFileSync(output, z.gzipSync(Buffer.from(JSON.stringify(result))), { mode: 384, flag: 'wx' });
54
+ })().catch(error => { console.error(error.message); process.exitCode = 1; });
55
+ `;
56
+ export const fileBatchCleanupScript = `require("node:fs").rmSync(process.argv[1], { force: true })`;
57
+ //# sourceMappingURL=file-batches.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-batches.constants.js","sourceRoot":"","sources":["../../src/providers/file-batches.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;IACtB,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,EAAE,GAAG,IAAI;IACxB,SAAS,EAAE,MAAM;IACjB,aAAa,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI;IAC9B,YAAY,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;CACtB,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8CxC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,6DAA6D,CAAC","sourcesContent":["export const fileBatchLimits = {\n bytes: 8 * 1024 * 1024,\n entries: 128,\n argumentBytes: 48 * 1024,\n cleanupMs: 10_000,\n manifestBytes: 2 * 1024 * 1024,\n decodedBytes: 16 * 1024 * 1024,\n} as const;\n\nexport const fileBatchScript = String.raw`\nconst fs = require('node:fs'), p = require('node:path'), c = require('node:crypto'), z = require('node:zlib');\nconst [operation, root, input, output] = process.argv.slice(1), entries = JSON.parse(input);\nfunction safe(path) {\n if (!path || p.isAbsolute(path) || path.includes('\\\\') || path.includes('\\0') || path.split('/').some(x => x === '..' || x.toLowerCase() === '.git')) throw Error('Unsafe transfer path');\n const target = p.resolve(root, path);\n let parent = p.dirname(target);\n while (true) {\n if (fs.lstatSync(parent).isSymbolicLink()) throw Error('Transfer path traverses symlink');\n if (parent === p.resolve(root)) break;\n parent = p.dirname(parent);\n }\n return target;\n}\nasync function inspect(path, expected) {\n const dataRequired = expected !== undefined;\n const target = safe(path), stat = fs.lstatSync(target), hash = c.createHash('sha256');\n if (!stat.isFile() && !stat.isSymbolicLink()) throw Error('Unsupported transfer file');\n if (expected && stat.isFile() && stat.size !== expected.size) throw Error('Remote file changed during transfer');\n let data, size = stat.size;\n if (stat.isSymbolicLink()) { data = Buffer.from(fs.readlinkSync(target)); size = data.length; hash.update(data); }\n else {\n const chunks = []; let bytes = 0;\n for await (const chunk of fs.createReadStream(target)) {\n hash.update(chunk);\n if (dataRequired) {\n bytes += chunk.length;\n if (bytes > expected.size) throw Error('Remote file changed during transfer');\n chunks.push(chunk);\n }\n }\n if (dataRequired) data = Buffer.concat(chunks);\n }\n const entry = { path, kind: stat.isSymbolicLink() ? 'link' : 'file', mode: stat.mode & 511, size, sha256: hash.digest('hex') };\n return dataRequired ? { ...entry, data: data.toString('base64') } : entry;\n}\n(async () => {\n const result = [];\n for (const entry of entries) {\n const item = await inspect(operation === 'manifest' ? entry : entry.path, operation === 'batch' ? entry : undefined);\n if (operation === 'batch' && ['path', 'kind', 'mode', 'size', 'sha256'].some(key => item[key] !== entry[key])) throw Error('Remote file changed during transfer');\n result.push(item);\n }\n if (operation === 'manifest') { process.stdout.write(JSON.stringify(result)); return; }\n fs.writeFileSync(output, z.gzipSync(Buffer.from(JSON.stringify(result))), { mode: 384, flag: 'wx' });\n})().catch(error => { console.error(error.message); process.exitCode = 1; });\n`;\n\nexport const fileBatchCleanupScript = `require(\"node:fs\").rmSync(process.argv[1], { force: true })`;\n"]}
@@ -0,0 +1,2 @@
1
+ import type { FileTransfers, SandboxLease } from "../domain/sandbox.types.ts";
2
+ export declare function fileBatches(lease: Pick<SandboxLease, "invoke" | "download"> & Partial<Pick<SandboxLease, "upload">>): FileTransfers;
@@ -0,0 +1,160 @@
1
+ import { randomUUID, createHash } from "node:crypto";
2
+ import { chmod, lstat, mkdir, mkdtemp, readFile, rm, symlink, writeFile, } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { dirname, join } from "node:path";
5
+ import { gunzipSync } from "node:zlib";
6
+ import { OutpostError } from "../domain/errors.js";
7
+ import { fileManifest, parseManifest, sameFile, sameLocalFile, validateFilePaths, } from "../infrastructure/file-manifest.js";
8
+ import { safeDestination } from "../infrastructure/files.js";
9
+ import { transfer } from "../infrastructure/transfer.js";
10
+ import { fileBatchCleanupScript, fileBatchLimits, fileBatchScript, } from "./file-batches.constants.js";
11
+ import { uploadBatch } from "./file-upload.js";
12
+ export function fileBatches(lease) {
13
+ const run = async (args, options) => {
14
+ const result = await lease.invoke({
15
+ executable: "node",
16
+ arguments: ["-e", fileBatchScript, ...args],
17
+ retain: fileBatchLimits.manifestBytes,
18
+ ...options,
19
+ });
20
+ if (result.status !== 0)
21
+ throw new OutpostError("provider", "Remote file manifest or batch failed", { stderr: result.stderr });
22
+ return result.stdout;
23
+ };
24
+ return {
25
+ ...(lease.upload
26
+ ? {
27
+ uploadBatch: uploadBatch({
28
+ invoke: lease.invoke.bind(lease),
29
+ upload: lease.upload.bind(lease),
30
+ }),
31
+ }
32
+ : {}),
33
+ manifest(source, paths, options = {}) {
34
+ return transfer(options, async (signal) => {
35
+ validateFilePaths(paths);
36
+ const result = [];
37
+ for (let offset = 0; offset < paths.length;) {
38
+ signal.throwIfAborted();
39
+ const selected = paths.slice(offset, offset + fileBatchLimits.entries);
40
+ while (Buffer.byteLength(JSON.stringify(selected)) >
41
+ fileBatchLimits.argumentBytes)
42
+ selected.pop();
43
+ if (!selected.length)
44
+ throw new OutpostError("provider", "Manifest path exceeds command size limit");
45
+ offset += selected.length;
46
+ result.push(...parseManifest(JSON.parse(await run(["manifest", source, JSON.stringify(selected)], {
47
+ ...options,
48
+ signal,
49
+ })), selected));
50
+ }
51
+ return result;
52
+ });
53
+ },
54
+ downloadBatch(source, entries, destination, options = {}) {
55
+ return transfer(options, async (signal) => {
56
+ parseManifest(entries, entries.map((entry) => entry.path));
57
+ if (!entries.length)
58
+ return;
59
+ const staging = await mkdtemp(join(tmpdir(), "outpost-batch-"));
60
+ try {
61
+ let pending = [], bytes = 0;
62
+ const flush = async () => {
63
+ if (!pending.length)
64
+ return;
65
+ const remote = `${source.replaceAll("\\", "/")}/../.outpost-${randomUUID()}.json.gz`;
66
+ try {
67
+ await run(["batch", source, JSON.stringify(pending), remote], {
68
+ ...options,
69
+ signal,
70
+ });
71
+ signal.throwIfAborted();
72
+ const archive = join(staging, "batch.json.gz");
73
+ await lease.download(remote, archive, { ...options, signal });
74
+ signal.throwIfAborted();
75
+ await unpackBatch(archive, pending, destination, signal);
76
+ }
77
+ finally {
78
+ await lease
79
+ .invoke({
80
+ executable: "node",
81
+ arguments: ["-e", fileBatchCleanupScript, remote],
82
+ deadlineMs: fileBatchLimits.cleanupMs,
83
+ })
84
+ .catch(() => undefined);
85
+ }
86
+ pending = [];
87
+ bytes = 0;
88
+ };
89
+ for (const entry of entries) {
90
+ signal.throwIfAborted();
91
+ await safeDestination(destination, entry.path);
92
+ if (entry.size > fileBatchLimits.bytes) {
93
+ await flush();
94
+ const target = await safeDestination(destination, entry.path);
95
+ await lease.download(`${source}/${entry.path}`, target, {
96
+ ...options,
97
+ signal,
98
+ });
99
+ if (!sameLocalFile(entry, await fileManifest(destination, entry.path)))
100
+ throw new OutpostError("provider", "Remote file changed during transfer", { path: entry.path });
101
+ continue;
102
+ }
103
+ if (pending.length >= fileBatchLimits.entries ||
104
+ bytes + entry.size > fileBatchLimits.bytes ||
105
+ Buffer.byteLength(JSON.stringify([...pending, entry])) >
106
+ fileBatchLimits.argumentBytes)
107
+ await flush();
108
+ pending.push(entry);
109
+ bytes += entry.size;
110
+ }
111
+ await flush();
112
+ }
113
+ finally {
114
+ await rm(staging, { recursive: true, force: true });
115
+ }
116
+ });
117
+ },
118
+ };
119
+ }
120
+ async function unpackBatch(archive, entries, destination, signal) {
121
+ const payload = JSON.parse(gunzipSync(await readFile(archive), {
122
+ maxOutputLength: fileBatchLimits.decodedBytes,
123
+ }).toString("utf8"));
124
+ const manifest = parseManifest(payload, entries.map((entry) => entry.path));
125
+ if (!Array.isArray(payload))
126
+ throw new OutpostError("provider", "Invalid file batch");
127
+ for (const [index, entry] of manifest.entries()) {
128
+ signal.throwIfAborted();
129
+ const record = payload[index];
130
+ if (!record ||
131
+ typeof record !== "object" ||
132
+ !("data" in record) ||
133
+ typeof record.data !== "string")
134
+ throw new OutpostError("provider", "Invalid batch payload");
135
+ const data = Buffer.from(record.data, "base64");
136
+ if (!sameFile(entry, entries[index]) ||
137
+ data.length !== entry.size ||
138
+ createHash("sha256").update(data).digest("hex") !== entry.sha256)
139
+ throw new OutpostError("provider", "File batch checksum mismatch", {
140
+ path: entry.path,
141
+ });
142
+ const target = await safeDestination(destination, entry.path);
143
+ await mkdir(dirname(target), { recursive: true });
144
+ if (await lstat(target).catch((error) => {
145
+ if (error.code === "ENOENT")
146
+ return undefined;
147
+ throw error;
148
+ }))
149
+ throw new OutpostError("provider", "Batch destination already exists", {
150
+ path: entry.path,
151
+ });
152
+ if (entry.kind === "link") {
153
+ await symlink(data.toString("utf8"), target);
154
+ continue;
155
+ }
156
+ await writeFile(target, data, { mode: entry.mode, flag: "wx" });
157
+ await chmod(target, entry.mode);
158
+ }
159
+ }
160
+ //# sourceMappingURL=file-batches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-batches.js","sourceRoot":"","sources":["../../src/providers/file-batches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACL,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,EACP,QAAQ,EACR,EAAE,EACF,OAAO,EACP,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOnD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,aAAa,EACb,iBAAiB,GAClB,MAAM,oCAAoC,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AAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,MAAM;YAEhE,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,8BAA8B,EAAE;gBACjE,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,CAAC;QACL,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAC9D,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,IACE,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YAClC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAO,SAAS,CAAC;YAC9C,MAAM,KAAK,CAAC;QACd,CAAC,CAAC;YAEF,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,kCAAkC,EAAE;gBACrE,IAAI,EAAE,KAAK,CAAC,IAAI;aACjB,CAAC,CAAC;QACL,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC1B,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;YAC7C,SAAS;QACX,CAAC;QACD,MAAM,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;AACH,CAAC","sourcesContent":["import { randomUUID, createHash } from \"node:crypto\";\nimport {\n chmod,\n lstat,\n mkdir,\n mkdtemp,\n readFile,\n rm,\n symlink,\n writeFile,\n} from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, join } from \"node:path\";\nimport { gunzipSync } from \"node:zlib\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport type {\n FileManifestEntry,\n FileTransfers,\n SandboxLease,\n TransferOptions,\n} from \"../domain/sandbox.types.ts\";\nimport {\n fileManifest,\n parseManifest,\n sameFile,\n sameLocalFile,\n validateFilePaths,\n} from \"../infrastructure/file-manifest.ts\";\nimport { safeDestination } from \"../infrastructure/files.ts\";\nimport { transfer } from \"../infrastructure/transfer.ts\";\nimport {\n fileBatchCleanupScript,\n fileBatchLimits,\n fileBatchScript,\n} from \"./file-batches.constants.ts\";\n\nimport { uploadBatch } from \"./file-upload.ts\";\n\nexport function fileBatches(\n lease: Pick<SandboxLease, \"invoke\" | \"download\"> &\n Partial<Pick<SandboxLease, \"upload\">>,\n): FileTransfers {\n const run = async (args: readonly string[], options: TransferOptions) => {\n const result = await lease.invoke({\n executable: \"node\",\n arguments: [\"-e\", fileBatchScript, ...args],\n retain: fileBatchLimits.manifestBytes,\n ...options,\n });\n if (result.status !== 0)\n throw new OutpostError(\n \"provider\",\n \"Remote file manifest or batch failed\",\n { stderr: result.stderr },\n );\n return result.stdout;\n };\n return {\n ...(lease.upload\n ? {\n uploadBatch: uploadBatch({\n invoke: lease.invoke.bind(lease),\n upload: lease.upload.bind(lease),\n }),\n }\n : {}),\n manifest(source, paths, options = {}) {\n return transfer(options, async (signal) => {\n validateFilePaths(paths);\n const result: FileManifestEntry[] = [];\n for (let offset = 0; offset < paths.length;) {\n signal.throwIfAborted();\n const selected = paths.slice(\n offset,\n offset + fileBatchLimits.entries,\n );\n while (\n Buffer.byteLength(JSON.stringify(selected)) >\n fileBatchLimits.argumentBytes\n )\n selected.pop();\n if (!selected.length)\n throw new OutpostError(\n \"provider\",\n \"Manifest path exceeds command size limit\",\n );\n offset += selected.length;\n result.push(\n ...parseManifest(\n JSON.parse(\n await run([\"manifest\", source, JSON.stringify(selected)], {\n ...options,\n signal,\n }),\n ),\n selected,\n ),\n );\n }\n return result;\n });\n },\n downloadBatch(source, entries, destination, options = {}) {\n return transfer(options, async (signal) => {\n parseManifest(\n entries,\n entries.map((entry) => entry.path),\n );\n if (!entries.length) return;\n const staging = await mkdtemp(join(tmpdir(), \"outpost-batch-\"));\n try {\n let pending: FileManifestEntry[] = [],\n bytes = 0;\n const flush = async () => {\n if (!pending.length) return;\n const remote = `${source.replaceAll(\"\\\\\", \"/\")}/../.outpost-${randomUUID()}.json.gz`;\n try {\n await run([\"batch\", source, JSON.stringify(pending), remote], {\n ...options,\n signal,\n });\n signal.throwIfAborted();\n const archive = join(staging, \"batch.json.gz\");\n await lease.download(remote, archive, { ...options, signal });\n signal.throwIfAborted();\n await unpackBatch(archive, pending, destination, signal);\n } finally {\n await lease\n .invoke({\n executable: \"node\",\n arguments: [\"-e\", fileBatchCleanupScript, remote],\n deadlineMs: fileBatchLimits.cleanupMs,\n })\n .catch(() => undefined);\n }\n pending = [];\n bytes = 0;\n };\n for (const entry of entries) {\n signal.throwIfAborted();\n await safeDestination(destination, entry.path);\n if (entry.size > fileBatchLimits.bytes) {\n await flush();\n const target = await safeDestination(destination, entry.path);\n await lease.download(`${source}/${entry.path}`, target, {\n ...options,\n signal,\n });\n if (\n !sameLocalFile(\n entry,\n await fileManifest(destination, entry.path),\n )\n )\n throw new OutpostError(\n \"provider\",\n \"Remote file changed during transfer\",\n { path: entry.path },\n );\n continue;\n }\n if (\n pending.length >= fileBatchLimits.entries ||\n bytes + entry.size > fileBatchLimits.bytes ||\n Buffer.byteLength(JSON.stringify([...pending, entry])) >\n fileBatchLimits.argumentBytes\n )\n await flush();\n pending.push(entry);\n bytes += entry.size;\n }\n await flush();\n } finally {\n await rm(staging, { recursive: true, force: true });\n }\n });\n },\n };\n}\n\nasync function unpackBatch(\n archive: string,\n entries: readonly FileManifestEntry[],\n destination: string,\n signal: AbortSignal,\n): Promise<void> {\n const payload: unknown = JSON.parse(\n gunzipSync(await readFile(archive), {\n maxOutputLength: fileBatchLimits.decodedBytes,\n }).toString(\"utf8\"),\n );\n const manifest = parseManifest(\n payload,\n entries.map((entry) => entry.path),\n );\n if (!Array.isArray(payload))\n throw new OutpostError(\"provider\", \"Invalid file batch\");\n for (const [index, entry] of manifest.entries()) {\n signal.throwIfAborted();\n const record: unknown = payload[index];\n if (\n !record ||\n typeof record !== \"object\" ||\n !(\"data\" in record) ||\n typeof record.data !== \"string\"\n )\n throw new OutpostError(\"provider\", \"Invalid batch payload\");\n const data = Buffer.from(record.data, \"base64\");\n if (\n !sameFile(entry, entries[index]!) ||\n data.length !== entry.size ||\n createHash(\"sha256\").update(data).digest(\"hex\") !== entry.sha256\n )\n throw new OutpostError(\"provider\", \"File batch checksum mismatch\", {\n path: entry.path,\n });\n const target = await safeDestination(destination, entry.path);\n await mkdir(dirname(target), { recursive: true });\n if (\n await lstat(target).catch((error) => {\n if (error.code === \"ENOENT\") return undefined;\n throw error;\n })\n )\n throw new OutpostError(\"provider\", \"Batch destination already exists\", {\n path: entry.path,\n });\n if (entry.kind === \"link\") {\n await symlink(data.toString(\"utf8\"), target);\n continue;\n }\n await writeFile(target, data, { mode: entry.mode, flag: \"wx\" });\n await chmod(target, entry.mode);\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const fileUploadScript: string;
@@ -0,0 +1,68 @@
1
+ export const fileUploadScript = String.raw `
2
+ const f = require('node:fs'), p = require('node:path'), c = require('node:crypto'), z = require('node:zlib');
3
+ const [operation, root, input, staging] = process.argv.slice(1);
4
+ const keys = ['path', 'kind', 'mode', 'size', 'sha256'];
5
+ function safe(path) {
6
+ if (!path || p.isAbsolute(path) || path.includes('\\') || path.includes('\0') || path.split('/').some(x => !x || x === '.' || x === '..' || x.toLowerCase() === '.git')) throw Error('Unsafe upload path');
7
+ const target = p.resolve(root, path);
8
+ let parent = p.dirname(target);
9
+ while (true) {
10
+ let stat;
11
+ try { stat = f.lstatSync(parent); } catch (error) { if (error.code !== 'ENOENT') throw error; }
12
+ if (stat && (!stat.isDirectory() || stat.isSymbolicLink())) throw Error('Upload path traverses non-directory');
13
+ if (parent === p.resolve(root)) break;
14
+ parent = p.dirname(parent);
15
+ }
16
+ return target;
17
+ }
18
+ async function inspect(target, path) {
19
+ const stat = f.lstatSync(target), hash = c.createHash('sha256');
20
+ if (!stat.isFile() && !stat.isSymbolicLink()) throw Error('Unsupported upload destination');
21
+ let size = stat.size;
22
+ if (stat.isSymbolicLink()) { const data = Buffer.from(f.readlinkSync(target)); size = data.length; hash.update(data); }
23
+ else for await (const chunk of f.createReadStream(target)) hash.update(chunk);
24
+ return { path, kind: stat.isSymbolicLink() ? 'link' : 'file', mode: stat.mode & 511, size, sha256: hash.digest('hex') };
25
+ }
26
+ function same(left, right) { return keys.every(key => left[key] === right[key]); }
27
+ (async () => {
28
+ if (operation === 'cleanup') { f.rmSync(input, { recursive: true, force: true }); return; }
29
+ if (operation === 'stage') { f.mkdirSync(input, { mode: 448 }); process.stdout.write(input); return; }
30
+ const entries = JSON.parse(input);
31
+ if (operation === 'missing') {
32
+ const missing = [];
33
+ for (const entry of entries) {
34
+ const target = safe(entry.path);
35
+ let actual;
36
+ try { actual = await inspect(target, entry.path); } catch (error) { if (error.code !== 'ENOENT') throw error; }
37
+ if (!actual || !same(actual, entry)) missing.push(entry.path);
38
+ }
39
+ process.stdout.write(JSON.stringify(missing)); return;
40
+ }
41
+ const records = operation === 'batch' ? JSON.parse(z.gunzipSync(f.readFileSync(p.join(staging, 'payload')), { maxOutputLength: 16777216 }).toString('utf8')) : undefined;
42
+ if (records && (!Array.isArray(records) || records.length !== entries.length)) throw Error('Invalid upload batch');
43
+ for (const [index, entry] of entries.entries()) {
44
+ safe(entry.path);
45
+ const temporary = p.join(staging, 'entry-' + index);
46
+ if (records) {
47
+ const record = records[index];
48
+ if (!record || !same(record, entry) || typeof record.data !== 'string') throw Error('Invalid upload batch');
49
+ const data = Buffer.from(record.data, 'base64');
50
+ if (data.length !== entry.size || c.createHash('sha256').update(data).digest('hex') !== entry.sha256) throw Error('Upload checksum mismatch');
51
+ if (entry.kind === 'link') f.symlinkSync(data.toString('utf8'), temporary);
52
+ else { f.writeFileSync(temporary, data, { flag: 'wx', mode: entry.mode }); f.chmodSync(temporary, entry.mode); }
53
+ } else {
54
+ if (entry.kind !== 'file') throw Error('Invalid large upload');
55
+ const actual = await inspect(p.join(staging, 'payload'), entry.path);
56
+ if (actual.kind !== entry.kind || actual.size !== entry.size || actual.sha256 !== entry.sha256) throw Error('Upload checksum mismatch');
57
+ f.renameSync(p.join(staging, 'payload'), temporary); f.chmodSync(temporary, entry.mode);
58
+ }
59
+ }
60
+ for (const [index, entry] of entries.entries()) {
61
+ const target = safe(entry.path);
62
+ f.mkdirSync(p.dirname(target), { recursive: true });
63
+ f.renameSync(p.join(staging, 'entry-' + index), target);
64
+ if (!same(await inspect(target, entry.path), entry)) throw Error('Upload verification failed');
65
+ }
66
+ })().catch(error => { console.error(error.message); process.exitCode = 1; });
67
+ `;
68
+ //# sourceMappingURL=file-upload.constants.js.map