@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 @@
1
+ {"version":3,"file":"file-upload.constants.js","sourceRoot":"","sources":["../../src/providers/file-upload.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkEzC,CAAC","sourcesContent":["export const fileUploadScript = String.raw`\nconst f = require('node:fs'), p = require('node:path'), c = require('node:crypto'), z = require('node:zlib');\nconst [operation, root, input, staging] = process.argv.slice(1);\nconst keys = ['path', 'kind', 'mode', 'size', 'sha256'];\nfunction safe(path) {\n 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');\n const target = p.resolve(root, path);\n let parent = p.dirname(target);\n while (true) {\n let stat;\n try { stat = f.lstatSync(parent); } catch (error) { if (error.code !== 'ENOENT') throw error; }\n if (stat && (!stat.isDirectory() || stat.isSymbolicLink())) throw Error('Upload path traverses non-directory');\n if (parent === p.resolve(root)) break;\n parent = p.dirname(parent);\n }\n return target;\n}\nasync function inspect(target, path) {\n const stat = f.lstatSync(target), hash = c.createHash('sha256');\n if (!stat.isFile() && !stat.isSymbolicLink()) throw Error('Unsupported upload destination');\n let size = stat.size;\n if (stat.isSymbolicLink()) { const data = Buffer.from(f.readlinkSync(target)); size = data.length; hash.update(data); }\n else for await (const chunk of f.createReadStream(target)) hash.update(chunk);\n return { path, kind: stat.isSymbolicLink() ? 'link' : 'file', mode: stat.mode & 511, size, sha256: hash.digest('hex') };\n}\nfunction same(left, right) { return keys.every(key => left[key] === right[key]); }\n(async () => {\n if (operation === 'cleanup') { f.rmSync(input, { recursive: true, force: true }); return; }\n if (operation === 'stage') { f.mkdirSync(input, { mode: 448 }); process.stdout.write(input); return; }\n const entries = JSON.parse(input);\n if (operation === 'missing') {\n const missing = [];\n for (const entry of entries) {\n const target = safe(entry.path);\n let actual;\n try { actual = await inspect(target, entry.path); } catch (error) { if (error.code !== 'ENOENT') throw error; }\n if (!actual || !same(actual, entry)) missing.push(entry.path);\n }\n process.stdout.write(JSON.stringify(missing)); return;\n }\n const records = operation === 'batch' ? JSON.parse(z.gunzipSync(f.readFileSync(p.join(staging, 'payload')), { maxOutputLength: 16777216 }).toString('utf8')) : undefined;\n if (records && (!Array.isArray(records) || records.length !== entries.length)) throw Error('Invalid upload batch');\n for (const [index, entry] of entries.entries()) {\n safe(entry.path);\n const temporary = p.join(staging, 'entry-' + index);\n if (records) {\n const record = records[index];\n if (!record || !same(record, entry) || typeof record.data !== 'string') throw Error('Invalid upload batch');\n const data = Buffer.from(record.data, 'base64');\n if (data.length !== entry.size || c.createHash('sha256').update(data).digest('hex') !== entry.sha256) throw Error('Upload checksum mismatch');\n if (entry.kind === 'link') f.symlinkSync(data.toString('utf8'), temporary);\n else { f.writeFileSync(temporary, data, { flag: 'wx', mode: entry.mode }); f.chmodSync(temporary, entry.mode); }\n } else {\n if (entry.kind !== 'file') throw Error('Invalid large upload');\n const actual = await inspect(p.join(staging, 'payload'), entry.path);\n if (actual.kind !== entry.kind || actual.size !== entry.size || actual.sha256 !== entry.sha256) throw Error('Upload checksum mismatch');\n f.renameSync(p.join(staging, 'payload'), temporary); f.chmodSync(temporary, entry.mode);\n }\n }\n for (const [index, entry] of entries.entries()) {\n const target = safe(entry.path);\n f.mkdirSync(p.dirname(target), { recursive: true });\n f.renameSync(p.join(staging, 'entry-' + index), target);\n if (!same(await inspect(target, entry.path), entry)) throw Error('Upload verification failed');\n }\n})().catch(error => { console.error(error.message); process.exitCode = 1; });\n`;\n"]}
@@ -0,0 +1,2 @@
1
+ import type { FileTransfers, SandboxLease } from "../domain/sandbox.types.ts";
2
+ export declare function uploadBatch(lease: Pick<SandboxLease, "invoke" | "upload">): NonNullable<FileTransfers["uploadBatch"]>;
@@ -0,0 +1,146 @@
1
+ import { createHash, randomUUID } from "node:crypto";
2
+ import { copyFile, mkdtemp, open, readlink, rm, writeFile, } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { gzipSync } from "node:zlib";
6
+ import { OutpostError } from "../domain/errors.js";
7
+ import { fileManifest, parseManifest, sameFile, } from "../infrastructure/file-manifest.js";
8
+ import { inspectionFileFlags } from "../infrastructure/inspection-file.constants.js";
9
+ import { safeDestination } from "../infrastructure/files.js";
10
+ import { transfer } from "../infrastructure/transfer.js";
11
+ import { fileBatchLimits } from "./file-batches.constants.js";
12
+ import { fileUploadScript } from "./file-upload.constants.js";
13
+ export function uploadBatch(lease) {
14
+ return (source, entries, destination, options = {}) => transfer(options, async (signal) => {
15
+ parseManifest(entries, entries.map((entry) => entry.path));
16
+ const run = async (operation, input, staging = "", controls = { ...options, signal }) => {
17
+ const result = await lease.invoke({
18
+ executable: "node",
19
+ arguments: [
20
+ "-e",
21
+ fileUploadScript,
22
+ operation,
23
+ destination,
24
+ input,
25
+ staging,
26
+ ],
27
+ retain: fileBatchLimits.manifestBytes,
28
+ ...controls,
29
+ });
30
+ if (result.status !== 0)
31
+ throw new OutpostError("provider", "Remote file upload failed", {
32
+ stderr: result.stderr,
33
+ });
34
+ return result.stdout;
35
+ };
36
+ const staging = await mkdtemp(join(tmpdir(), "outpost-upload-"));
37
+ try {
38
+ let pending = [], bytes = 0;
39
+ const flush = async () => {
40
+ if (!pending.length)
41
+ return;
42
+ signal.throwIfAborted();
43
+ for (const entry of pending) {
44
+ if (!sameFile(entry, await fileManifest(source, entry.path, signal)))
45
+ throw new OutpostError("provider", "Upload source changed", {
46
+ path: entry.path,
47
+ });
48
+ }
49
+ const missing = JSON.parse(await run("missing", JSON.stringify(pending)));
50
+ if (!Array.isArray(missing) ||
51
+ missing.some((path) => typeof path !== "string" ||
52
+ !pending.some((entry) => entry.path === path)) ||
53
+ new Set(missing).size !== missing.length)
54
+ throw new OutpostError("provider", "Invalid destination upload manifest");
55
+ const selected = pending.filter((entry) => missing.includes(entry.path));
56
+ if (selected.length) {
57
+ const remote = `${destination.replaceAll("\\", "/").replace(/\/$/, "")}/.outpost-upload-${randomUUID()}`;
58
+ try {
59
+ if ((await run("stage", remote)) !== remote)
60
+ throw new OutpostError("provider", "Invalid remote upload staging path");
61
+ const payload = join(staging, "payload");
62
+ await rm(payload, { force: true });
63
+ const large = selected[0].size > fileBatchLimits.bytes;
64
+ if (large) {
65
+ const entry = selected[0];
66
+ await copyFile(await safeDestination(source, entry.path), payload);
67
+ if (!sameFile({ ...entry, path: "payload" }, await fileManifest(staging, "payload", signal)))
68
+ throw new OutpostError("provider", "Upload source changed", {
69
+ path: entry.path,
70
+ });
71
+ }
72
+ else {
73
+ const records = [];
74
+ for (const entry of selected) {
75
+ signal.throwIfAborted();
76
+ const path = await safeDestination(source, entry.path);
77
+ const data = entry.kind === "link"
78
+ ? Buffer.from(await readlink(path))
79
+ : await readPayload(path, entry.size, signal);
80
+ if (data.length !== entry.size ||
81
+ createHash("sha256").update(data).digest("hex") !==
82
+ entry.sha256 ||
83
+ !sameFile(entry, await fileManifest(source, entry.path, signal)))
84
+ throw new OutpostError("provider", "Upload source changed", { path: entry.path });
85
+ records.push({ ...entry, data: data.toString("base64") });
86
+ }
87
+ await writeFile(payload, gzipSync(Buffer.from(JSON.stringify(records))), { mode: 0o600 });
88
+ }
89
+ signal.throwIfAborted();
90
+ await lease.upload(payload, `${remote}/payload`, {
91
+ ...options,
92
+ signal,
93
+ });
94
+ signal.throwIfAborted();
95
+ await run(large ? "large" : "batch", JSON.stringify(selected), remote);
96
+ }
97
+ finally {
98
+ await run("cleanup", remote, "", {
99
+ deadlineMs: fileBatchLimits.cleanupMs,
100
+ }).catch(() => undefined);
101
+ }
102
+ }
103
+ for (const entry of pending) {
104
+ if (!sameFile(entry, await fileManifest(source, entry.path, signal)))
105
+ throw new OutpostError("provider", "Upload source changed", {
106
+ path: entry.path,
107
+ });
108
+ }
109
+ signal.throwIfAborted();
110
+ pending = [];
111
+ bytes = 0;
112
+ };
113
+ for (const entry of entries) {
114
+ if (Buffer.byteLength(JSON.stringify([entry])) >
115
+ fileBatchLimits.argumentBytes)
116
+ throw new OutpostError("provider", "Upload path exceeds command size limit");
117
+ if (pending.length >= fileBatchLimits.entries ||
118
+ bytes + entry.size > fileBatchLimits.bytes ||
119
+ Buffer.byteLength(JSON.stringify([...pending, entry])) >
120
+ fileBatchLimits.argumentBytes)
121
+ await flush();
122
+ pending.push(entry);
123
+ bytes += entry.size;
124
+ if (entry.size > fileBatchLimits.bytes)
125
+ await flush();
126
+ }
127
+ await flush();
128
+ }
129
+ finally {
130
+ await rm(staging, { recursive: true, force: true });
131
+ }
132
+ });
133
+ }
134
+ async function readPayload(path, size, signal) {
135
+ const chunks = [];
136
+ let bytes = 0;
137
+ const file = await open(path, inspectionFileFlags);
138
+ for await (const chunk of file.createReadStream({ signal })) {
139
+ bytes += chunk.length;
140
+ if (bytes > size)
141
+ throw new OutpostError("provider", "Upload source changed", { path });
142
+ chunks.push(chunk);
143
+ }
144
+ return Buffer.concat(chunks);
145
+ }
146
+ //# sourceMappingURL=file-upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-upload.js","sourceRoot":"","sources":["../../src/providers/file-upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACL,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,QAAQ,EACR,EAAE,EACF,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MA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n} from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { gzipSync } 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} from \"../infrastructure/file-manifest.ts\";\nimport { inspectionFileFlags } from \"../infrastructure/inspection-file.constants.ts\";\nimport { safeDestination } from \"../infrastructure/files.ts\";\nimport { transfer } from \"../infrastructure/transfer.ts\";\nimport { fileBatchLimits } from \"./file-batches.constants.ts\";\nimport { fileUploadScript } from \"./file-upload.constants.ts\";\n\nexport function uploadBatch(\n lease: Pick<SandboxLease, \"invoke\" | \"upload\">,\n): NonNullable<FileTransfers[\"uploadBatch\"]> {\n return (source, entries, destination, options = {}) =>\n transfer(options, async (signal) => {\n parseManifest(\n entries,\n entries.map((entry) => entry.path),\n );\n const run = async (\n operation: string,\n input: string,\n staging = \"\",\n controls: TransferOptions = { ...options, signal },\n ) => {\n const result = await lease.invoke({\n executable: \"node\",\n arguments: [\n \"-e\",\n fileUploadScript,\n operation,\n destination,\n input,\n staging,\n ],\n retain: fileBatchLimits.manifestBytes,\n ...controls,\n });\n if (result.status !== 0)\n throw new OutpostError(\"provider\", \"Remote file upload failed\", {\n stderr: result.stderr,\n });\n return result.stdout;\n };\n const staging = await mkdtemp(join(tmpdir(), \"outpost-upload-\"));\n try {\n let pending: FileManifestEntry[] = [],\n bytes = 0;\n const flush = async () => {\n if (!pending.length) return;\n signal.throwIfAborted();\n for (const entry of pending) {\n if (\n !sameFile(entry, await fileManifest(source, entry.path, signal))\n )\n throw new OutpostError(\"provider\", \"Upload source changed\", {\n path: entry.path,\n });\n }\n const missing: unknown = JSON.parse(\n await run(\"missing\", JSON.stringify(pending)),\n );\n if (\n !Array.isArray(missing) ||\n missing.some(\n (path) =>\n typeof path !== \"string\" ||\n !pending.some((entry) => entry.path === path),\n ) ||\n new Set(missing).size !== missing.length\n )\n throw new OutpostError(\n \"provider\",\n \"Invalid destination upload manifest\",\n );\n const selected = pending.filter((entry) =>\n missing.includes(entry.path),\n );\n if (selected.length) {\n const remote = `${destination.replaceAll(\"\\\\\", \"/\").replace(/\\/$/, \"\")}/.outpost-upload-${randomUUID()}`;\n try {\n if ((await run(\"stage\", remote)) !== remote)\n throw new OutpostError(\n \"provider\",\n \"Invalid remote upload staging path\",\n );\n const payload = join(staging, \"payload\");\n await rm(payload, { force: true });\n const large = selected[0]!.size > fileBatchLimits.bytes;\n if (large) {\n const entry = selected[0]!;\n await copyFile(\n await safeDestination(source, entry.path),\n payload,\n );\n if (\n !sameFile(\n { ...entry, path: \"payload\" },\n await fileManifest(staging, \"payload\", signal),\n )\n )\n throw new OutpostError(\"provider\", \"Upload source changed\", {\n path: entry.path,\n });\n } else {\n const records = [];\n for (const entry of selected) {\n signal.throwIfAborted();\n const path = await safeDestination(source, entry.path);\n const data =\n entry.kind === \"link\"\n ? Buffer.from(await readlink(path))\n : await readPayload(path, entry.size, signal);\n if (\n data.length !== entry.size ||\n createHash(\"sha256\").update(data).digest(\"hex\") !==\n entry.sha256 ||\n !sameFile(\n entry,\n await fileManifest(source, entry.path, signal),\n )\n )\n throw new OutpostError(\n \"provider\",\n \"Upload source changed\",\n { path: entry.path },\n );\n records.push({ ...entry, data: data.toString(\"base64\") });\n }\n await writeFile(\n payload,\n gzipSync(Buffer.from(JSON.stringify(records))),\n { mode: 0o600 },\n );\n }\n signal.throwIfAborted();\n await lease.upload(payload, `${remote}/payload`, {\n ...options,\n signal,\n });\n signal.throwIfAborted();\n await run(\n large ? \"large\" : \"batch\",\n JSON.stringify(selected),\n remote,\n );\n } finally {\n await run(\"cleanup\", remote, \"\", {\n deadlineMs: fileBatchLimits.cleanupMs,\n }).catch(() => undefined);\n }\n }\n for (const entry of pending) {\n if (\n !sameFile(entry, await fileManifest(source, entry.path, signal))\n )\n throw new OutpostError(\"provider\", \"Upload source changed\", {\n path: entry.path,\n });\n }\n signal.throwIfAborted();\n pending = [];\n bytes = 0;\n };\n for (const entry of entries) {\n if (\n Buffer.byteLength(JSON.stringify([entry])) >\n fileBatchLimits.argumentBytes\n )\n throw new OutpostError(\n \"provider\",\n \"Upload path exceeds command size limit\",\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 if (entry.size > fileBatchLimits.bytes) await flush();\n }\n await flush();\n } finally {\n await rm(staging, { recursive: true, force: true });\n }\n });\n}\n\nasync function readPayload(\n path: string,\n size: number,\n signal: AbortSignal,\n): Promise<Buffer> {\n const chunks: Buffer[] = [];\n let bytes = 0;\n const file = await open(path, inspectionFileFlags);\n for await (const chunk of file.createReadStream({ signal })) {\n bytes += chunk.length;\n if (bytes > size)\n throw new OutpostError(\"provider\", \"Upload source changed\", { path });\n chunks.push(chunk);\n }\n return Buffer.concat(chunks);\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { Command } from "../domain/command.types.ts";
2
+ import type { SandboxLease } from "../domain/sandbox.types.ts";
3
+ import type { FirecrackerOptions, FirecrackerRuntime } from "./firecracker.types.ts";
4
+ export declare function firecrackerSsh(options: FirecrackerOptions, script: string): Command;
5
+ export declare function firecrackerCommand(runtime: FirecrackerRuntime): SandboxLease["invoke"];
@@ -0,0 +1,114 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { invariant, OutpostError, positive } from "../domain/errors.js";
3
+ import { executeProcess, quote, requireSuccess, } from "../infrastructure/process.js";
4
+ import { firecrackerDefaults } from "./firecracker.constants.js";
5
+ export function firecrackerSsh(options, script) {
6
+ const ssh = options.ssh;
7
+ return {
8
+ executable: ssh.binary ?? "ssh",
9
+ arguments: [
10
+ "-F",
11
+ "/dev/null",
12
+ "-T",
13
+ "-o",
14
+ "BatchMode=yes",
15
+ "-o",
16
+ "IdentitiesOnly=yes",
17
+ "-o",
18
+ "StrictHostKeyChecking=yes",
19
+ "-o",
20
+ `UserKnownHostsFile=${ssh.knownHosts}`,
21
+ "-o",
22
+ "GlobalKnownHostsFile=/dev/null",
23
+ "-o",
24
+ "ConnectTimeout=2",
25
+ "-o",
26
+ "ServerAliveInterval=2",
27
+ "-o",
28
+ "ServerAliveCountMax=2",
29
+ "-i",
30
+ ssh.identity,
31
+ "-p",
32
+ String(ssh.port ?? 22),
33
+ "-l",
34
+ ssh.user,
35
+ "--",
36
+ ssh.host,
37
+ script,
38
+ ],
39
+ };
40
+ }
41
+ export function firecrackerCommand(runtime) {
42
+ return async (command) => {
43
+ if (runtime.isClosed())
44
+ throw new OutpostError("provider", "Firecracker sandbox is closed");
45
+ invariant(!command.interactive && !command.elevated, "Firecracker research provider does not support interactive or elevated commands");
46
+ command.signal?.throwIfAborted();
47
+ const variables = { ...runtime.variables, ...command.variables };
48
+ invariant(Object.keys(variables).every((key) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(key)), "Invalid environment key");
49
+ const id = `/tmp/outpost-command-${randomUUID()}`;
50
+ const wrapper = `umask 077; echo $$ > ${quote(id)}; test ! -e ${quote(id + ".cancel")} || exit 130; cd ${quote(command.directory ?? runtime.root)} || exit; exec env ${Object.entries(variables)
51
+ .map(([key, value]) => quote(`${key}=${value}`))
52
+ .join(" ")} ${[command.executable, ...(command.arguments ?? [])].map(quote).join(" ")}`;
53
+ const stop = new AbortController();
54
+ const signal = command.signal
55
+ ? AbortSignal.any([command.signal, stop.signal])
56
+ : stop.signal;
57
+ const deadlineMs = command.deadlineMs ?? firecrackerDefaults.commandMs;
58
+ positive(deadlineMs, "deadlineMs");
59
+ let cancellation;
60
+ const cancel = () => {
61
+ cancellation ??= requireSuccess({
62
+ ...firecrackerSsh(runtime.options, `umask 077; touch ${quote(id + ".cancel")}; if [ -f ${quote(id)} ]; then node -e ${quote("const fs=require('node:fs');const pid=Number(fs.readFileSync(process.argv[1],'utf8'));if(!Number.isSafeInteger(pid)||pid<2)process.exit(1);const kill=s=>{try{process.kill(-pid,s)}catch(e){if(e.code!=='ESRCH')throw e}};kill('SIGTERM');setTimeout(()=>kill('SIGKILL'),100)")} ${quote(id)}; fi`),
63
+ deadlineMs: firecrackerDefaults.cleanupMs,
64
+ }, executeProcess);
65
+ void cancellation.catch(() => undefined);
66
+ };
67
+ signal.addEventListener("abort", cancel, { once: true });
68
+ const timer = setTimeout(() => stop.abort(new OutpostError("timeout", `Command exceeded ${deadlineMs} ms`)), deadlineMs);
69
+ let interrupted = false;
70
+ try {
71
+ const { directory: _directory, variables: _variables, ...invocation } = command;
72
+ const result = await runtime.executor({
73
+ ...invocation,
74
+ ...(command.observe
75
+ ? {
76
+ observe: (channel, text) => {
77
+ try {
78
+ command.observe(channel, text);
79
+ }
80
+ catch (cause) {
81
+ stop.abort(cause);
82
+ }
83
+ },
84
+ }
85
+ : {}),
86
+ signal,
87
+ ...firecrackerSsh(runtime.options, `setsid --wait sh -c ${quote(wrapper)}`),
88
+ });
89
+ signal.throwIfAborted();
90
+ return result;
91
+ }
92
+ catch (cause) {
93
+ interrupted = true;
94
+ try {
95
+ cancel();
96
+ await cancellation;
97
+ }
98
+ catch (cleanup) {
99
+ throw new AggregateError([cause, cleanup], "Guest cancellation could not be confirmed; release the VM");
100
+ }
101
+ throw cause;
102
+ }
103
+ finally {
104
+ clearTimeout(timer);
105
+ signal.removeEventListener("abort", cancel);
106
+ if (!interrupted && !runtime.isClosed())
107
+ await executeProcess({
108
+ ...firecrackerSsh(runtime.options, `rm -f -- ${quote(id)}`),
109
+ deadlineMs: firecrackerDefaults.cleanupMs,
110
+ }).catch(() => undefined);
111
+ }
112
+ };
113
+ }
114
+ //# sourceMappingURL=firecracker-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firecracker-command.js","sourceRoot":"","sources":["../../src/providers/firecracker-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,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CAAC;gBACP,MAAM;gBACN,GAAG,cAAc,CACf,OAAO,CAAC,OAAO,EACf,uBAAuB,KAAK,CAAC,OAAO,CAAC,EAAE,CACxC;aACF,CAAC,CAAC;YACH,MAAM,CAAC,cAAc,EAAE,CAAC;YACxB,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC;gBACH,MAAM,EAAE,CAAC;gBACT,MAAM,YAAY,CAAC;YACrB,CAAC;YAAC,OAAO,OAAO,EAAE,CAAC;gBACjB,MAAM,IAAI,cAAc,CACtB,CAAC,KAAK,EAAE,OAAO,CAAC,EAChB,2DAA2D,CAC5D,CAAC;YACJ,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC5C,IAAI,CAAC,WAAW,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;gBACrC,MAAM,cAAc,CAAC;oBACnB,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;oBAC3D,UAAU,EAAE,mBAAmB,CAAC,SAAS;iBAC1C,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { invariant, OutpostError, positive } from \"../domain/errors.ts\";\nimport type { Command } from \"../domain/command.types.ts\";\nimport type { SandboxLease } from \"../domain/sandbox.types.ts\";\nimport {\n executeProcess,\n quote,\n requireSuccess,\n} from \"../infrastructure/process.ts\";\nimport { firecrackerDefaults } from \"./firecracker.constants.ts\";\nimport type {\n FirecrackerOptions,\n FirecrackerRuntime,\n} from \"./firecracker.types.ts\";\n\nexport function firecrackerSsh(\n options: FirecrackerOptions,\n script: string,\n): Command {\n const ssh = options.ssh;\n return {\n executable: ssh.binary ?? \"ssh\",\n arguments: [\n \"-F\",\n \"/dev/null\",\n \"-T\",\n \"-o\",\n \"BatchMode=yes\",\n \"-o\",\n \"IdentitiesOnly=yes\",\n \"-o\",\n \"StrictHostKeyChecking=yes\",\n \"-o\",\n `UserKnownHostsFile=${ssh.knownHosts}`,\n \"-o\",\n \"GlobalKnownHostsFile=/dev/null\",\n \"-o\",\n \"ConnectTimeout=2\",\n \"-o\",\n \"ServerAliveInterval=2\",\n \"-o\",\n \"ServerAliveCountMax=2\",\n \"-i\",\n ssh.identity,\n \"-p\",\n String(ssh.port ?? 22),\n \"-l\",\n ssh.user,\n \"--\",\n ssh.host,\n script,\n ],\n };\n}\n\nexport function firecrackerCommand(\n runtime: FirecrackerRuntime,\n): SandboxLease[\"invoke\"] {\n return async (command) => {\n if (runtime.isClosed())\n throw new OutpostError(\"provider\", \"Firecracker sandbox is closed\");\n invariant(\n !command.interactive && !command.elevated,\n \"Firecracker research provider does not support interactive or elevated commands\",\n );\n command.signal?.throwIfAborted();\n const variables = { ...runtime.variables, ...command.variables };\n invariant(\n Object.keys(variables).every((key) =>\n /^[A-Za-z_][A-Za-z0-9_]*$/.test(key),\n ),\n \"Invalid environment key\",\n );\n const id = `/tmp/outpost-command-${randomUUID()}`;\n const wrapper = `umask 077; echo $$ > ${quote(id)}; test ! -e ${quote(id + \".cancel\")} || exit 130; cd ${quote(command.directory ?? runtime.root)} || exit; exec env ${Object.entries(\n variables,\n )\n .map(([key, value]) => quote(`${key}=${value}`))\n .join(\n \" \",\n )} ${[command.executable, ...(command.arguments ?? [])].map(quote).join(\" \")}`;\n const stop = new AbortController();\n const signal = command.signal\n ? AbortSignal.any([command.signal, stop.signal])\n : stop.signal;\n const deadlineMs = command.deadlineMs ?? firecrackerDefaults.commandMs;\n positive(deadlineMs, \"deadlineMs\");\n let cancellation: Promise<unknown> | undefined;\n const cancel = () => {\n cancellation ??= requireSuccess(\n {\n ...firecrackerSsh(\n runtime.options,\n `umask 077; touch ${quote(id + \".cancel\")}; if [ -f ${quote(id)} ]; then node -e ${quote(\"const fs=require('node:fs');const pid=Number(fs.readFileSync(process.argv[1],'utf8'));if(!Number.isSafeInteger(pid)||pid<2)process.exit(1);const kill=s=>{try{process.kill(-pid,s)}catch(e){if(e.code!=='ESRCH')throw e}};kill('SIGTERM');setTimeout(()=>kill('SIGKILL'),100)\")} ${quote(id)}; fi`,\n ),\n deadlineMs: firecrackerDefaults.cleanupMs,\n },\n executeProcess,\n );\n void cancellation.catch(() => undefined);\n };\n signal.addEventListener(\"abort\", cancel, { once: true });\n const timer = setTimeout(\n () =>\n stop.abort(\n new OutpostError(\"timeout\", `Command exceeded ${deadlineMs} ms`),\n ),\n deadlineMs,\n );\n let interrupted = false;\n try {\n const {\n directory: _directory,\n variables: _variables,\n ...invocation\n } = command;\n const result = await runtime.executor({\n ...invocation,\n ...(command.observe\n ? {\n observe: (channel, text) => {\n try {\n command.observe!(channel, text);\n } catch (cause) {\n stop.abort(cause);\n }\n },\n }\n : {}),\n signal,\n ...firecrackerSsh(\n runtime.options,\n `setsid --wait sh -c ${quote(wrapper)}`,\n ),\n });\n signal.throwIfAborted();\n return result;\n } catch (cause) {\n interrupted = true;\n try {\n cancel();\n await cancellation;\n } catch (cleanup) {\n throw new AggregateError(\n [cause, cleanup],\n \"Guest cancellation could not be confirmed; release the VM\",\n );\n }\n throw cause;\n } finally {\n clearTimeout(timer);\n signal.removeEventListener(\"abort\", cancel);\n if (!interrupted && !runtime.isClosed())\n await executeProcess({\n ...firecrackerSsh(runtime.options, `rm -f -- ${quote(id)}`),\n deadlineMs: firecrackerDefaults.cleanupMs,\n }).catch(() => undefined);\n }\n };\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const firecrackerFileScript: string;
@@ -0,0 +1,21 @@
1
+ export const firecrackerFileScript = String.raw `
2
+ const fs = require('node:fs'), p = require('node:path'), { pipeline } = require('node:stream/promises');
3
+ const [op, input, extra] = process.argv.slice(1), path = p.resolve(input);
4
+ function safe(target) {
5
+ for (let current = target; current !== '/'; current = p.dirname(current)) {
6
+ try { if (fs.lstatSync(current).isSymbolicLink()) throw Error('Transfer destination traverses a symlink'); }
7
+ catch (error) { if (error.code !== 'ENOENT') throw error; }
8
+ }
9
+ }
10
+ (async () => {
11
+ if (op === 'read') { safe(p.dirname(path)); await pipeline(fs.createReadStream(path, { flags: fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW }), process.stdout); return; }
12
+ safe(path);
13
+ if (op === 'directory') { fs.mkdirSync(path, { recursive: true }); return; }
14
+ if (op === 'mode') { fs.chmodSync(path, Number(extra)); return; }
15
+ fs.mkdirSync(p.dirname(path), { recursive: true });
16
+ if (op === 'link') { fs.symlinkSync(extra, path); return; }
17
+ if (op === 'write') { await pipeline(process.stdin, fs.createWriteStream(path, { flags: fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_TRUNC | fs.constants.O_NOFOLLOW, mode: 384 })); return; }
18
+ throw Error('Unknown transfer operation');
19
+ })().catch(error => { console.error(error.message); process.exitCode = 1; });
20
+ `;
21
+ //# sourceMappingURL=firecracker-files.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firecracker-files.constants.js","sourceRoot":"","sources":["../../src/providers/firecracker-files.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;CAmB9C,CAAC","sourcesContent":["export const firecrackerFileScript = String.raw`\nconst fs = require('node:fs'), p = require('node:path'), { pipeline } = require('node:stream/promises');\nconst [op, input, extra] = process.argv.slice(1), path = p.resolve(input);\nfunction safe(target) {\n for (let current = target; current !== '/'; current = p.dirname(current)) {\n try { if (fs.lstatSync(current).isSymbolicLink()) throw Error('Transfer destination traverses a symlink'); }\n catch (error) { if (error.code !== 'ENOENT') throw error; }\n }\n}\n(async () => {\n if (op === 'read') { safe(p.dirname(path)); await pipeline(fs.createReadStream(path, { flags: fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW }), process.stdout); return; }\n safe(path);\n if (op === 'directory') { fs.mkdirSync(path, { recursive: true }); return; }\n if (op === 'mode') { fs.chmodSync(path, Number(extra)); return; }\n fs.mkdirSync(p.dirname(path), { recursive: true });\n if (op === 'link') { fs.symlinkSync(extra, path); return; }\n if (op === 'write') { await pipeline(process.stdin, fs.createWriteStream(path, { flags: fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_TRUNC | fs.constants.O_NOFOLLOW, mode: 384 })); return; }\n throw Error('Unknown transfer operation');\n})().catch(error => { console.error(error.message); process.exitCode = 1; });\n`;\n"]}
@@ -0,0 +1,3 @@
1
+ import type { SandboxLease } from "../domain/sandbox.types.ts";
2
+ import type { FirecrackerRuntime } from "./firecracker.types.ts";
3
+ export declare function firecrackerFiles(runtime: FirecrackerRuntime): Pick<SandboxLease, "upload" | "download">;
@@ -0,0 +1,110 @@
1
+ import { chmod } from "node:fs/promises";
2
+ import { Readable, Writable } from "node:stream";
3
+ import { posix } from "node:path";
4
+ import { OutpostError } from "../domain/errors.js";
5
+ import { binaryExecutor } from "../infrastructure/binary-process.js";
6
+ import { transferDestination } from "../infrastructure/transfer-copy.js";
7
+ import { safeDestination } from "../infrastructure/files.js";
8
+ import { transfer } from "../infrastructure/transfer.js";
9
+ import { downloadTree, uploadTree } from "./cloud-files.js";
10
+ import { manifestScript } from "./cloud-files.constants.js";
11
+ import { firecrackerCommand } from "./firecracker-command.js";
12
+ import { firecrackerDefaults } from "./firecracker.constants.js";
13
+ import { firecrackerFileScript } from "./firecracker-files.constants.js";
14
+ export function firecrackerFiles(runtime) {
15
+ const invoke = firecrackerCommand(runtime);
16
+ const run = async (args, signal) => {
17
+ const result = await invoke({
18
+ executable: "node",
19
+ arguments: ["-e", firecrackerFileScript, ...args],
20
+ signal,
21
+ });
22
+ if (result.status !== 0)
23
+ throw new OutpostError("provider", "Guest file operation failed", {
24
+ stderr: result.stderr,
25
+ });
26
+ };
27
+ return {
28
+ upload(source, destination, options = {}) {
29
+ return transfer(options, async (signal) => {
30
+ const modes = [];
31
+ await uploadTree(source, posix.resolve(runtime.root, destination), async (path, data) => {
32
+ await firecrackerCommand({
33
+ ...runtime,
34
+ executor: binaryExecutor({ input: Readable.from([data]) }),
35
+ })({
36
+ executable: "node",
37
+ arguments: ["-e", firecrackerFileScript, "write", path],
38
+ signal,
39
+ });
40
+ }, (target, path) => run(["link", path, target], signal), async (path, directory, mode) => {
41
+ if (directory) {
42
+ await run(["directory", path], signal);
43
+ modes.push([path, mode]);
44
+ return;
45
+ }
46
+ await run(["mode", path, String(mode)], signal);
47
+ }, signal);
48
+ for (const [path, mode] of modes.reverse())
49
+ await run(["mode", path, String(mode)], signal);
50
+ });
51
+ },
52
+ download(source, destination, options = {}) {
53
+ return transfer(options, async (signal) => {
54
+ await transferDestination(destination);
55
+ const remote = posix.resolve(runtime.root, source);
56
+ const manifest = await invoke({
57
+ executable: "node",
58
+ arguments: ["-e", manifestScript, remote],
59
+ retain: firecrackerDefaults.manifestBytes,
60
+ signal,
61
+ });
62
+ if (manifest.status !== 0)
63
+ throw new OutpostError("provider", "Guest manifest failed", {
64
+ stderr: manifest.stderr,
65
+ });
66
+ await downloadTree(remote, destination, manifest.stdout, async (path) => {
67
+ const chunks = [];
68
+ const output = new Writable({
69
+ write(chunk, _encoding, done) {
70
+ chunks.push(chunk);
71
+ done();
72
+ },
73
+ });
74
+ await firecrackerCommand({
75
+ ...runtime,
76
+ executor: binaryExecutor({ output }),
77
+ })({
78
+ executable: "node",
79
+ arguments: ["-e", firecrackerFileScript, "read", path],
80
+ signal,
81
+ });
82
+ return Buffer.concat(chunks);
83
+ }, signal);
84
+ const entries = JSON.parse(manifest.stdout);
85
+ if (!Array.isArray(entries))
86
+ throw new OutpostError("provider", "Invalid transfer manifest");
87
+ const records = entries;
88
+ for (const entry of records.reverse()) {
89
+ if (!entry ||
90
+ typeof entry !== "object" ||
91
+ !("kind" in entry) ||
92
+ !("path" in entry) ||
93
+ typeof entry.path !== "string" ||
94
+ !("mode" in entry) ||
95
+ typeof entry.mode !== "number" ||
96
+ !Number.isSafeInteger(entry.mode))
97
+ throw new OutpostError("provider", "Invalid transfer entry");
98
+ if (entry.kind !== "directory")
99
+ continue;
100
+ signal.throwIfAborted();
101
+ const path = entry.path
102
+ ? await safeDestination(destination, entry.path)
103
+ : destination;
104
+ await chmod(path, entry.mode & 0o777);
105
+ }
106
+ });
107
+ },
108
+ };
109
+ }
110
+ //# sourceMappingURL=firecracker-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firecracker-files.js","sourceRoot":"","sources":["../../src/providers/firecracker-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,MAAM,UAAU,gBAAgB,CAC9B,OAA2B;IAE3B,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OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;wBAC9B,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;wBAEjC,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAC;oBAC/D,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;wBAAE,SAAS;oBACzC,MAAM,CAAC,cAAc,EAAE,CAAC;oBACxB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI;wBACrB,CAAC,CAAC,MAAM,eAAe,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC;wBAChD,CAAC,CAAC,WAAW,CAAC;oBAChB,MAAM,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC;gBACxC,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { chmod } from \"node:fs/promises\";\nimport { Readable, Writable } from \"node:stream\";\nimport { posix } from \"node:path\";\nimport type { SandboxLease } from \"../domain/sandbox.types.ts\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport { binaryExecutor } from \"../infrastructure/binary-process.ts\";\nimport { transferDestination } from \"../infrastructure/transfer-copy.ts\";\nimport { safeDestination } from \"../infrastructure/files.ts\";\nimport { transfer } from \"../infrastructure/transfer.ts\";\nimport { downloadTree, uploadTree } from \"./cloud-files.ts\";\nimport { manifestScript } from \"./cloud-files.constants.ts\";\nimport { firecrackerCommand } from \"./firecracker-command.ts\";\nimport { firecrackerDefaults } from \"./firecracker.constants.ts\";\nimport { firecrackerFileScript } from \"./firecracker-files.constants.ts\";\nimport type { FirecrackerRuntime } from \"./firecracker.types.ts\";\n\nexport function firecrackerFiles(\n runtime: FirecrackerRuntime,\n): Pick<SandboxLease, \"upload\" | \"download\"> {\n const invoke = firecrackerCommand(runtime);\n const run = async (args: string[], signal: AbortSignal) => {\n const result = await invoke({\n executable: \"node\",\n arguments: [\"-e\", firecrackerFileScript, ...args],\n signal,\n });\n if (result.status !== 0)\n throw new OutpostError(\"provider\", \"Guest file operation failed\", {\n stderr: result.stderr,\n });\n };\n return {\n upload(source, destination, options = {}) {\n return transfer(options, async (signal) => {\n const modes: [string, number][] = [];\n await uploadTree(\n source,\n posix.resolve(runtime.root, destination),\n async (path, data) => {\n await firecrackerCommand({\n ...runtime,\n executor: binaryExecutor({ input: Readable.from([data]) }),\n })({\n executable: \"node\",\n arguments: [\"-e\", firecrackerFileScript, \"write\", path],\n signal,\n });\n },\n (target, path) => run([\"link\", path, target], signal),\n async (path, directory, mode) => {\n if (directory) {\n await run([\"directory\", path], signal);\n modes.push([path, mode]);\n return;\n }\n await run([\"mode\", path, String(mode)], signal);\n },\n signal,\n );\n for (const [path, mode] of modes.reverse())\n await run([\"mode\", path, String(mode)], signal);\n });\n },\n download(source, destination, options = {}) {\n return transfer(options, async (signal) => {\n await transferDestination(destination);\n const remote = posix.resolve(runtime.root, source);\n const manifest = await invoke({\n executable: \"node\",\n arguments: [\"-e\", manifestScript, remote],\n retain: firecrackerDefaults.manifestBytes,\n signal,\n });\n if (manifest.status !== 0)\n throw new OutpostError(\"provider\", \"Guest manifest failed\", {\n stderr: manifest.stderr,\n });\n await downloadTree(\n remote,\n destination,\n manifest.stdout,\n async (path) => {\n const chunks: Buffer[] = [];\n const output = new Writable({\n write(chunk: Buffer, _encoding, done) {\n chunks.push(chunk);\n done();\n },\n });\n await firecrackerCommand({\n ...runtime,\n executor: binaryExecutor({ output }),\n })({\n executable: \"node\",\n arguments: [\"-e\", firecrackerFileScript, \"read\", path],\n signal,\n });\n return Buffer.concat(chunks);\n },\n signal,\n );\n const entries: unknown = JSON.parse(manifest.stdout);\n if (!Array.isArray(entries))\n throw new OutpostError(\"provider\", \"Invalid transfer manifest\");\n const records: unknown[] = entries;\n for (const entry of records.reverse()) {\n if (\n !entry ||\n typeof entry !== \"object\" ||\n !(\"kind\" in entry) ||\n !(\"path\" in entry) ||\n typeof entry.path !== \"string\" ||\n !(\"mode\" in entry) ||\n typeof entry.mode !== \"number\" ||\n !Number.isSafeInteger(entry.mode)\n )\n throw new OutpostError(\"provider\", \"Invalid transfer entry\");\n if (entry.kind !== \"directory\") continue;\n signal.throwIfAborted();\n const path = entry.path\n ? await safeDestination(destination, entry.path)\n : destination;\n await chmod(path, entry.mode & 0o777);\n }\n });\n },\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { FirecrackerMachine, FirecrackerOptions } from "./firecracker.types.ts";
2
+ export declare function validateFirecracker(options: FirecrackerOptions): void;
3
+ export declare function firecrackerMachine(options: FirecrackerOptions, signal?: AbortSignal): Promise<FirecrackerMachine>;