@elie-laloum/outpost 3.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 (381) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +3 -1
  3. package/SECURITY.md +3 -1
  4. package/dist/adapters/agents/gemini-adapter.d.ts +3 -0
  5. package/dist/adapters/agents/gemini-adapter.js +15 -0
  6. package/dist/adapters/agents/gemini-adapter.js.map +1 -0
  7. package/dist/adapters/agents/gemini-diagnostics.d.ts +2 -0
  8. package/dist/adapters/agents/gemini-diagnostics.js +15 -0
  9. package/dist/adapters/agents/gemini-diagnostics.js.map +1 -0
  10. package/dist/adapters/agents/gemini-events.d.ts +2 -0
  11. package/dist/adapters/agents/gemini-events.js +50 -0
  12. package/dist/adapters/agents/gemini-events.js.map +1 -0
  13. package/dist/adapters/agents/gemini-request.d.ts +4 -0
  14. package/dist/adapters/agents/gemini-request.js +21 -0
  15. package/dist/adapters/agents/gemini-request.js.map +1 -0
  16. package/dist/adapters/agents/gemini.types.d.ts +6 -0
  17. package/dist/adapters/agents/gemini.types.js +2 -0
  18. package/dist/adapters/agents/gemini.types.js.map +1 -0
  19. package/dist/adapters/agents/protocol-fixtures.constants.d.ts +1 -1
  20. package/dist/adapters/agents/protocol-fixtures.constants.js +37 -0
  21. package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -1
  22. package/dist/application/agent-bootstrap.constants.d.ts +1 -0
  23. package/dist/application/agent-bootstrap.constants.js +1 -0
  24. package/dist/application/agent-bootstrap.constants.js.map +1 -1
  25. package/dist/application/agent-bootstrap.js +6 -2
  26. package/dist/application/agent-bootstrap.js.map +1 -1
  27. package/dist/application/agent-output.js +9 -2
  28. package/dist/application/agent-output.js.map +1 -1
  29. package/dist/application/artifact-tasks.d.ts +5 -0
  30. package/dist/application/artifact-tasks.js +31 -0
  31. package/dist/application/artifact-tasks.js.map +1 -0
  32. package/dist/application/artifact-tasks.types.d.ts +8 -0
  33. package/dist/application/artifact-tasks.types.js +2 -0
  34. package/dist/application/artifact-tasks.types.js.map +1 -0
  35. package/dist/application/dispatch-validation.js +2 -0
  36. package/dist/application/dispatch-validation.js.map +1 -1
  37. package/dist/application/doctor-agent.constants.d.ts +2 -0
  38. package/dist/application/doctor-agent.constants.js +2 -0
  39. package/dist/application/doctor-agent.constants.js.map +1 -1
  40. package/dist/application/doctor-agent.js +1 -1
  41. package/dist/application/doctor-agent.js.map +1 -1
  42. package/dist/application/doctor-protocol.js +2 -1
  43. package/dist/application/doctor-protocol.js.map +1 -1
  44. package/dist/application/doctor.constants.js +1 -1
  45. package/dist/application/doctor.constants.js.map +1 -1
  46. package/dist/application/doctor.types.d.ts +1 -1
  47. package/dist/application/doctor.types.js.map +1 -1
  48. package/dist/application/outpost.types.d.ts +2 -0
  49. package/dist/application/outpost.types.js.map +1 -1
  50. package/dist/application/queue-worker.d.ts +2 -0
  51. package/dist/application/queue-worker.js +75 -0
  52. package/dist/application/queue-worker.js.map +1 -0
  53. package/dist/application/queue-worker.types.d.ts +15 -0
  54. package/dist/application/queue-worker.types.js +2 -0
  55. package/dist/application/queue-worker.types.js.map +1 -0
  56. package/dist/application/queued-task.d.ts +3 -0
  57. package/dist/application/queued-task.js +56 -0
  58. package/dist/application/queued-task.js.map +1 -0
  59. package/dist/application/queued-task.types.d.ts +11 -0
  60. package/dist/application/queued-task.types.js +2 -0
  61. package/dist/application/queued-task.types.js.map +1 -0
  62. package/dist/application/recovery-inspection.js +5 -0
  63. package/dist/application/recovery-inspection.js.map +1 -1
  64. package/dist/application/recovery-inspection.types.d.ts +3 -0
  65. package/dist/application/recovery-inspection.types.js.map +1 -1
  66. package/dist/application/recovery-restore-snapshot.d.ts +2 -0
  67. package/dist/application/recovery-restore-snapshot.js +57 -0
  68. package/dist/application/recovery-restore-snapshot.js.map +1 -0
  69. package/dist/application/recovery-restore.d.ts +3 -0
  70. package/dist/application/recovery-restore.js +161 -0
  71. package/dist/application/recovery-restore.js.map +1 -0
  72. package/dist/application/recovery-restore.types.d.ts +28 -0
  73. package/dist/application/recovery-restore.types.js +2 -0
  74. package/dist/application/recovery-restore.types.js.map +1 -0
  75. package/dist/application/recovery-retention.js +5 -0
  76. package/dist/application/recovery-retention.js.map +1 -1
  77. package/dist/application/recovery-verification.d.ts +2 -1
  78. package/dist/application/recovery-verification.js +1 -1
  79. package/dist/application/recovery-verification.js.map +1 -1
  80. package/dist/application/remote-apply.js +6 -0
  81. package/dist/application/remote-apply.js.map +1 -1
  82. package/dist/application/remote-download.js +2 -2
  83. package/dist/application/remote-download.js.map +1 -1
  84. package/dist/application/remote-history.d.ts +6 -0
  85. package/dist/application/remote-history.js +114 -0
  86. package/dist/application/remote-history.js.map +1 -0
  87. package/dist/application/remote-upload.d.ts +2 -0
  88. package/dist/application/remote-upload.js +17 -0
  89. package/dist/application/remote-upload.js.map +1 -0
  90. package/dist/application/remote-validation.js +20 -28
  91. package/dist/application/remote-validation.js.map +1 -1
  92. package/dist/application/remote-workspace.js +4 -10
  93. package/dist/application/remote-workspace.js.map +1 -1
  94. package/dist/application/sandbox-activity.d.ts +3 -0
  95. package/dist/application/sandbox-activity.js +25 -0
  96. package/dist/application/sandbox-activity.js.map +1 -0
  97. package/dist/application/sandbox-provision.js +55 -10
  98. package/dist/application/sandbox-provision.js.map +1 -1
  99. package/dist/application/sandbox-session.types.d.ts +2 -0
  100. package/dist/application/sandbox-session.types.js.map +1 -1
  101. package/dist/application/sandbox.js +23 -11
  102. package/dist/application/sandbox.js.map +1 -1
  103. package/dist/application/speculation-host.d.ts +2 -0
  104. package/dist/application/speculation-host.js +30 -0
  105. package/dist/application/speculation-host.js.map +1 -0
  106. package/dist/application/speculation.constants.d.ts +4 -0
  107. package/dist/application/speculation.constants.js +2 -0
  108. package/dist/application/speculation.constants.js.map +1 -0
  109. package/dist/application/speculation.d.ts +2 -0
  110. package/dist/application/speculation.js +166 -0
  111. package/dist/application/speculation.js.map +1 -0
  112. package/dist/application/speculation.types.d.ts +56 -0
  113. package/dist/application/speculation.types.js +2 -0
  114. package/dist/application/speculation.types.js.map +1 -0
  115. package/dist/application/storage-reservation.d.ts +3 -0
  116. package/dist/application/storage-reservation.js +10 -0
  117. package/dist/application/storage-reservation.js.map +1 -0
  118. package/dist/application/storage-reservation.types.d.ts +4 -0
  119. package/dist/application/storage-reservation.types.js +2 -0
  120. package/dist/application/storage-reservation.types.js.map +1 -0
  121. package/dist/application/task-usage.d.ts +1 -1
  122. package/dist/application/task-usage.js.map +1 -1
  123. package/dist/application/tasks.js +1 -1
  124. package/dist/application/tasks.js.map +1 -1
  125. package/dist/application/tasks.types.d.ts +4 -3
  126. package/dist/application/tasks.types.js.map +1 -1
  127. package/dist/application/workspace-allocation.d.ts +3 -0
  128. package/dist/application/workspace-allocation.js +34 -0
  129. package/dist/application/workspace-allocation.js.map +1 -0
  130. package/dist/application/workspace.js +2 -2
  131. package/dist/application/workspace.js.map +1 -1
  132. package/dist/cli/doctor-command.js +1 -1
  133. package/dist/cli/doctor-command.js.map +1 -1
  134. package/dist/cli/main.constants.d.ts +11 -2
  135. package/dist/cli/main.constants.js +8 -4
  136. package/dist/cli/main.constants.js.map +1 -1
  137. package/dist/cli/recovery-command.js +28 -4
  138. package/dist/cli/recovery-command.js.map +1 -1
  139. package/dist/cli/recovery-restore-command.d.ts +2 -0
  140. package/dist/cli/recovery-restore-command.js +34 -0
  141. package/dist/cli/recovery-restore-command.js.map +1 -0
  142. package/dist/cli/scaffold-files.js +2 -2
  143. package/dist/cli/scaffold-files.js.map +1 -1
  144. package/dist/cli/scaffold-validation.js +1 -1
  145. package/dist/cli/scaffold-validation.js.map +1 -1
  146. package/dist/cli/scaffold.constants.d.ts +5 -0
  147. package/dist/cli/scaffold.constants.js +7 -2
  148. package/dist/cli/scaffold.constants.js.map +1 -1
  149. package/dist/cli/scaffold.types.d.ts +1 -1
  150. package/dist/cli/scaffold.types.js.map +1 -1
  151. package/dist/domain/agent.types.d.ts +2 -0
  152. package/dist/domain/agent.types.js.map +1 -1
  153. package/dist/domain/artifact-reference.d.ts +4 -0
  154. package/dist/domain/artifact-reference.js +90 -0
  155. package/dist/domain/artifact-reference.js.map +1 -0
  156. package/dist/domain/artifact.constants.d.ts +2 -0
  157. package/dist/domain/artifact.constants.js +3 -0
  158. package/dist/domain/artifact.constants.js.map +1 -0
  159. package/dist/domain/artifact.d.ts +7 -0
  160. package/dist/domain/artifact.js +104 -0
  161. package/dist/domain/artifact.js.map +1 -0
  162. package/dist/domain/artifact.types.d.ts +44 -0
  163. package/dist/domain/artifact.types.js +2 -0
  164. package/dist/domain/artifact.types.js.map +1 -0
  165. package/dist/domain/egress.constants.d.ts +1 -0
  166. package/dist/domain/egress.constants.js +7 -0
  167. package/dist/domain/egress.constants.js.map +1 -0
  168. package/dist/domain/egress.d.ts +2 -0
  169. package/dist/domain/egress.js +48 -0
  170. package/dist/domain/egress.js.map +1 -0
  171. package/dist/domain/egress.types.d.ts +8 -0
  172. package/dist/domain/egress.types.js +2 -0
  173. package/dist/domain/egress.types.js.map +1 -0
  174. package/dist/domain/sandbox.types.d.ts +1 -0
  175. package/dist/domain/sandbox.types.js.map +1 -1
  176. package/dist/domain/task-queue.constants.d.ts +8 -0
  177. package/dist/domain/task-queue.constants.js +9 -0
  178. package/dist/domain/task-queue.constants.js.map +1 -0
  179. package/dist/domain/task-queue.d.ts +11 -0
  180. package/dist/domain/task-queue.js +105 -0
  181. package/dist/domain/task-queue.js.map +1 -0
  182. package/dist/domain/task-queue.types.d.ts +41 -0
  183. package/dist/domain/task-queue.types.js +2 -0
  184. package/dist/domain/task-queue.types.js.map +1 -0
  185. package/dist/domain/workflow/budget.d.ts +2 -2
  186. package/dist/domain/workflow/budget.js +5 -3
  187. package/dist/domain/workflow/budget.js.map +1 -1
  188. package/dist/domain/workflow/checkpoint-validation.d.ts +3 -0
  189. package/dist/domain/workflow/checkpoint-validation.js +81 -0
  190. package/dist/domain/workflow/checkpoint-validation.js.map +1 -0
  191. package/dist/domain/workflow/checkpoint-value.d.ts +2 -0
  192. package/dist/domain/workflow/checkpoint-value.js +49 -0
  193. package/dist/domain/workflow/checkpoint-value.js.map +1 -0
  194. package/dist/domain/workflow/checkpoint.d.ts +3 -0
  195. package/dist/domain/workflow/checkpoint.js +70 -0
  196. package/dist/domain/workflow/checkpoint.js.map +1 -0
  197. package/dist/domain/workflow/checkpoint.types.d.ts +40 -0
  198. package/dist/domain/workflow/checkpoint.types.js +2 -0
  199. package/dist/domain/workflow/checkpoint.types.js.map +1 -0
  200. package/dist/domain/workflow/gate-validation.d.ts +4 -0
  201. package/dist/domain/workflow/gate-validation.js +71 -0
  202. package/dist/domain/workflow/gate-validation.js.map +1 -0
  203. package/dist/domain/workflow/gates.constants.d.ts +4 -0
  204. package/dist/domain/workflow/gates.constants.js +5 -0
  205. package/dist/domain/workflow/gates.constants.js.map +1 -0
  206. package/dist/domain/workflow/gates.d.ts +7 -0
  207. package/dist/domain/workflow/gates.js +85 -0
  208. package/dist/domain/workflow/gates.js.map +1 -0
  209. package/dist/domain/workflow/gates.types.d.ts +27 -0
  210. package/dist/domain/workflow/gates.types.js +2 -0
  211. package/dist/domain/workflow/gates.types.js.map +1 -0
  212. package/dist/domain/workflow/task-runner.js +14 -2
  213. package/dist/domain/workflow/task-runner.js.map +1 -1
  214. package/dist/domain/workflow/usage-receipt.constants.d.ts +2 -0
  215. package/dist/domain/workflow/usage-receipt.constants.js +3 -0
  216. package/dist/domain/workflow/usage-receipt.constants.js.map +1 -0
  217. package/dist/domain/workflow/usage-receipt.d.ts +2 -0
  218. package/dist/domain/workflow/usage-receipt.js +18 -0
  219. package/dist/domain/workflow/usage-receipt.js.map +1 -0
  220. package/dist/domain/workflow/validation.js +6 -0
  221. package/dist/domain/workflow/validation.js.map +1 -1
  222. package/dist/domain/workflow/workflow-scheduler.js +65 -32
  223. package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
  224. package/dist/domain/workflow/workflow-state.d.ts +2 -1
  225. package/dist/domain/workflow/workflow-state.js +91 -16
  226. package/dist/domain/workflow/workflow-state.js.map +1 -1
  227. package/dist/domain/workflow.types.d.ts +13 -2
  228. package/dist/domain/workflow.types.js.map +1 -1
  229. package/dist/index.d.ts +32 -2
  230. package/dist/index.js +14 -1
  231. package/dist/index.js.map +1 -1
  232. package/dist/infrastructure/artifact-store.constants.d.ts +1 -0
  233. package/dist/infrastructure/artifact-store.constants.js +2 -0
  234. package/dist/infrastructure/artifact-store.constants.js.map +1 -0
  235. package/dist/infrastructure/artifact-store.d.ts +3 -0
  236. package/dist/infrastructure/artifact-store.js +100 -0
  237. package/dist/infrastructure/artifact-store.js.map +1 -0
  238. package/dist/infrastructure/artifact-store.types.d.ts +4 -0
  239. package/dist/infrastructure/artifact-store.types.js +2 -0
  240. package/dist/infrastructure/artifact-store.types.js.map +1 -0
  241. package/dist/infrastructure/file-manifest.d.ts +1 -1
  242. package/dist/infrastructure/file-manifest.js +3 -2
  243. package/dist/infrastructure/file-manifest.js.map +1 -1
  244. package/dist/infrastructure/git/verification-command.d.ts +1 -1
  245. package/dist/infrastructure/git/verification-command.js +3 -2
  246. package/dist/infrastructure/git/verification-command.js.map +1 -1
  247. package/dist/infrastructure/opentelemetry.js +1 -1
  248. package/dist/infrastructure/opentelemetry.js.map +1 -1
  249. package/dist/infrastructure/resource-activity-inspection.d.ts +2 -0
  250. package/dist/infrastructure/resource-activity-inspection.js +152 -0
  251. package/dist/infrastructure/resource-activity-inspection.js.map +1 -0
  252. package/dist/infrastructure/resource-activity.constants.d.ts +8 -0
  253. package/dist/infrastructure/resource-activity.constants.js +26 -0
  254. package/dist/infrastructure/resource-activity.constants.js.map +1 -0
  255. package/dist/infrastructure/resource-activity.d.ts +2 -0
  256. package/dist/infrastructure/resource-activity.js +166 -0
  257. package/dist/infrastructure/resource-activity.js.map +1 -0
  258. package/dist/infrastructure/resource-activity.types.d.ts +53 -0
  259. package/dist/infrastructure/resource-activity.types.js +2 -0
  260. package/dist/infrastructure/resource-activity.types.js.map +1 -0
  261. package/dist/infrastructure/storage-mutation-lock.constants.d.ts +5 -0
  262. package/dist/infrastructure/storage-mutation-lock.constants.js +6 -0
  263. package/dist/infrastructure/storage-mutation-lock.constants.js.map +1 -0
  264. package/dist/infrastructure/storage-mutation-lock.d.ts +1 -0
  265. package/dist/infrastructure/storage-mutation-lock.js +21 -0
  266. package/dist/infrastructure/storage-mutation-lock.js.map +1 -0
  267. package/dist/infrastructure/storage-reservations.constants.d.ts +4 -0
  268. package/dist/infrastructure/storage-reservations.constants.js +5 -0
  269. package/dist/infrastructure/storage-reservations.constants.js.map +1 -0
  270. package/dist/infrastructure/storage-reservations.d.ts +2 -0
  271. package/dist/infrastructure/storage-reservations.js +150 -0
  272. package/dist/infrastructure/storage-reservations.js.map +1 -0
  273. package/dist/infrastructure/storage-reservations.types.d.ts +21 -0
  274. package/dist/infrastructure/storage-reservations.types.js +2 -0
  275. package/dist/infrastructure/storage-reservations.types.js.map +1 -0
  276. package/dist/infrastructure/task-queue-http.constants.d.ts +2 -0
  277. package/dist/infrastructure/task-queue-http.constants.js +3 -0
  278. package/dist/infrastructure/task-queue-http.constants.js.map +1 -0
  279. package/dist/infrastructure/task-queue-http.d.ts +4 -0
  280. package/dist/infrastructure/task-queue-http.js +158 -0
  281. package/dist/infrastructure/task-queue-http.js.map +1 -0
  282. package/dist/infrastructure/task-queue-http.types.d.ts +16 -0
  283. package/dist/infrastructure/task-queue-http.types.js +2 -0
  284. package/dist/infrastructure/task-queue-http.types.js.map +1 -0
  285. package/dist/infrastructure/task-queue.d.ts +2 -0
  286. package/dist/infrastructure/task-queue.js +134 -0
  287. package/dist/infrastructure/task-queue.js.map +1 -0
  288. package/dist/infrastructure/transfer.js +5 -0
  289. package/dist/infrastructure/transfer.js.map +1 -1
  290. package/dist/infrastructure/workflow-checkpoint.constants.d.ts +1 -0
  291. package/dist/infrastructure/workflow-checkpoint.constants.js +2 -0
  292. package/dist/infrastructure/workflow-checkpoint.constants.js.map +1 -0
  293. package/dist/infrastructure/workflow-checkpoint.d.ts +3 -0
  294. package/dist/infrastructure/workflow-checkpoint.js +77 -0
  295. package/dist/infrastructure/workflow-checkpoint.js.map +1 -0
  296. package/dist/infrastructure/workflow-checkpoint.types.d.ts +4 -0
  297. package/dist/infrastructure/workflow-checkpoint.types.js +2 -0
  298. package/dist/infrastructure/workflow-checkpoint.types.js.map +1 -0
  299. package/dist/providers/agents.d.ts +2 -0
  300. package/dist/providers/agents.js +1 -0
  301. package/dist/providers/agents.js.map +1 -1
  302. package/dist/providers/container-isolation.d.ts +2 -0
  303. package/dist/providers/container-isolation.js +29 -0
  304. package/dist/providers/container-isolation.js.map +1 -0
  305. package/dist/providers/container-mounts.js +7 -2
  306. package/dist/providers/container-mounts.js.map +1 -1
  307. package/dist/providers/container-network.d.ts +2 -0
  308. package/dist/providers/container-network.js +14 -0
  309. package/dist/providers/container-network.js.map +1 -0
  310. package/dist/providers/container-plan.js +4 -2
  311. package/dist/providers/container-plan.js.map +1 -1
  312. package/dist/providers/container.constants.d.ts +1 -0
  313. package/dist/providers/container.constants.js +1 -0
  314. package/dist/providers/container.constants.js.map +1 -1
  315. package/dist/providers/container.js +19 -2
  316. package/dist/providers/container.js.map +1 -1
  317. package/dist/providers/container.types.d.ts +3 -0
  318. package/dist/providers/container.types.js.map +1 -1
  319. package/dist/providers/daytona-command.js +3 -2
  320. package/dist/providers/daytona-command.js.map +1 -1
  321. package/dist/providers/daytona-terminal.d.ts +3 -0
  322. package/dist/providers/daytona-terminal.js +128 -0
  323. package/dist/providers/daytona-terminal.js.map +1 -0
  324. package/dist/providers/daytona.js +2 -0
  325. package/dist/providers/daytona.js.map +1 -1
  326. package/dist/providers/docker.d.ts +1 -0
  327. package/dist/providers/docker.js.map +1 -1
  328. package/dist/providers/file-batches.d.ts +1 -1
  329. package/dist/providers/file-batches.js +9 -0
  330. package/dist/providers/file-batches.js.map +1 -1
  331. package/dist/providers/file-upload.constants.d.ts +1 -0
  332. package/dist/providers/file-upload.constants.js +68 -0
  333. package/dist/providers/file-upload.constants.js.map +1 -0
  334. package/dist/providers/file-upload.d.ts +2 -0
  335. package/dist/providers/file-upload.js +146 -0
  336. package/dist/providers/file-upload.js.map +1 -0
  337. package/dist/providers/firecracker-command.d.ts +5 -0
  338. package/dist/providers/firecracker-command.js +114 -0
  339. package/dist/providers/firecracker-command.js.map +1 -0
  340. package/dist/providers/firecracker-files.constants.d.ts +1 -0
  341. package/dist/providers/firecracker-files.constants.js +21 -0
  342. package/dist/providers/firecracker-files.constants.js.map +1 -0
  343. package/dist/providers/firecracker-files.d.ts +3 -0
  344. package/dist/providers/firecracker-files.js +110 -0
  345. package/dist/providers/firecracker-files.js.map +1 -0
  346. package/dist/providers/firecracker-machine.d.ts +3 -0
  347. package/dist/providers/firecracker-machine.js +155 -0
  348. package/dist/providers/firecracker-machine.js.map +1 -0
  349. package/dist/providers/firecracker.constants.d.ts +10 -0
  350. package/dist/providers/firecracker.constants.js +11 -0
  351. package/dist/providers/firecracker.constants.js.map +1 -0
  352. package/dist/providers/firecracker.d.ts +4 -0
  353. package/dist/providers/firecracker.js +103 -0
  354. package/dist/providers/firecracker.js.map +1 -0
  355. package/dist/providers/firecracker.types.d.ts +36 -0
  356. package/dist/providers/firecracker.types.js +2 -0
  357. package/dist/providers/firecracker.types.js.map +1 -0
  358. package/dist/providers/local.js +2 -1
  359. package/dist/providers/local.js.map +1 -1
  360. package/dist/providers/podman.d.ts +1 -0
  361. package/dist/providers/podman.js.map +1 -1
  362. package/dist/providers/terminal-bridge.d.ts +14 -0
  363. package/dist/providers/terminal-bridge.js +100 -0
  364. package/dist/providers/terminal-bridge.js.map +1 -0
  365. package/dist/providers/vercel-directory.d.ts +2 -0
  366. package/dist/providers/vercel-directory.js +7 -0
  367. package/dist/providers/vercel-directory.js.map +1 -0
  368. package/dist/providers/vercel-files.js +3 -2
  369. package/dist/providers/vercel-files.js.map +1 -1
  370. package/dist/providers/vercel-network.d.ts +2 -0
  371. package/dist/providers/vercel-network.js +18 -0
  372. package/dist/providers/vercel-network.js.map +1 -0
  373. package/dist/providers/vercel.d.ts +1 -0
  374. package/dist/providers/vercel.js +5 -1
  375. package/dist/providers/vercel.js.map +1 -1
  376. package/dist/providers/vercel.types.d.ts +2 -0
  377. package/dist/providers/vercel.types.js.map +1 -1
  378. package/dist/providers/versions.constants.d.ts +1 -0
  379. package/dist/providers/versions.constants.js +1 -0
  380. package/dist/providers/versions.constants.js.map +1 -1
  381. package/package.json +5 -1
@@ -0,0 +1,114 @@
1
+ import { mkdir, rename, rm } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { OutpostError } from "../domain/errors.js";
4
+ import { verificationGit } from "../infrastructure/git/verification-command.js";
5
+ async function probe(operation) {
6
+ try {
7
+ return await operation();
8
+ }
9
+ catch (error) {
10
+ if (error instanceof OutpostError &&
11
+ (error.details.status === 1 || error.details.status === 128))
12
+ return undefined;
13
+ if (error &&
14
+ typeof error === "object" &&
15
+ "code" in error &&
16
+ (error.code === 1 || error.code === 128))
17
+ return undefined;
18
+ throw error;
19
+ }
20
+ }
21
+ export async function seedHistory(workspace, lease, options, recovery, remoteBundle, run) {
22
+ const local = (args) => verificationGit(workspace.directory, args, options.limits?.gitMs, options.signal);
23
+ const bundle = join(recovery, "initial.bundle");
24
+ await local(["bundle", "create", bundle, "--all", "HEAD"]);
25
+ const head = (await local(["rev-parse", "HEAD"])).trim();
26
+ const candidate = (await probe(() => run(["rev-parse", "--verify", "HEAD"])))?.trim();
27
+ let base;
28
+ if (candidate &&
29
+ /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(candidate) &&
30
+ (await probe(() => local(["merge-base", "--is-ancestor", candidate, head]))) !== undefined &&
31
+ (await probe(() => run(["rev-list", "--objects", "--missing=error", "--quiet", candidate]))) !== undefined)
32
+ base = candidate;
33
+ if (base === head) {
34
+ await run(["checkout", "-B", workspace.branch, head]);
35
+ return;
36
+ }
37
+ let payload = bundle;
38
+ if (base) {
39
+ payload = join(recovery, "initial-delta.bundle");
40
+ await local(["bundle", "create", payload, "--all", "HEAD", `^${base}`]);
41
+ }
42
+ await lease.upload(payload, remoteBundle, {
43
+ ...(options.signal ? { signal: options.signal } : {}),
44
+ ...(options.limits?.copyMs ? { deadlineMs: options.limits.copyMs } : {}),
45
+ });
46
+ if (base &&
47
+ (await probe(() => run(["bundle", "verify", remoteBundle]))) === undefined)
48
+ await lease.upload(bundle, remoteBundle, {
49
+ ...(options.signal ? { signal: options.signal } : {}),
50
+ ...(options.limits?.copyMs ? { deadlineMs: options.limits.copyMs } : {}),
51
+ });
52
+ await run(["bundle", "verify", remoteBundle]);
53
+ await run(["fetch", remoteBundle, "HEAD"]);
54
+ await run(["checkout", "-B", workspace.branch, "FETCH_HEAD"]);
55
+ }
56
+ export async function prepareHistoryValidation(context, transfer) {
57
+ const validation = join(transfer, "validation");
58
+ await mkdir(validation, { recursive: true });
59
+ const snapshot = join(transfer, "host.bundle");
60
+ const run = (directory, args) => verificationGit(directory, args, context.options.limits?.gitMs);
61
+ await run(context.workspace.directory, [
62
+ "bundle",
63
+ "create",
64
+ snapshot,
65
+ "HEAD",
66
+ ]);
67
+ const format = (await run(context.workspace.directory, [
68
+ "rev-parse",
69
+ "--show-object-format",
70
+ ])).trim();
71
+ await run(validation, ["init", `--object-format=${format}`]);
72
+ await run(validation, ["config", "core.autocrlf", "false"]);
73
+ await run(validation, ["fetch", snapshot, "HEAD"]);
74
+ await run(validation, ["update-ref", "HEAD", "FETCH_HEAD"]);
75
+ await rm(snapshot);
76
+ return validation;
77
+ }
78
+ export async function downloadHistory(context, synchronized, head, transfer) {
79
+ const { run, lease, remoteBundle, options } = context;
80
+ const validation = await prepareHistoryValidation(context, transfer);
81
+ const local = (args) => verificationGit(validation, args, options.limits?.gitMs);
82
+ const usable = (await probe(() => local([
83
+ "rev-list",
84
+ "--objects",
85
+ "--missing=error",
86
+ "--quiet",
87
+ synchronized,
88
+ ]))) !== undefined &&
89
+ (await probe(() => run(["merge-base", "--is-ancestor", synchronized, head]))) !== undefined;
90
+ await run([
91
+ "bundle",
92
+ "create",
93
+ remoteBundle,
94
+ "HEAD",
95
+ ...(usable ? [`^${synchronized}`] : []),
96
+ ]);
97
+ const bundle = join(transfer, "commits.bundle");
98
+ const received = usable ? join(transfer, "commits-delta.bundle") : bundle;
99
+ await lease.download(remoteBundle, received, {
100
+ ...(options.limits?.copyMs ? { deadlineMs: options.limits.copyMs } : {}),
101
+ });
102
+ await local(["bundle", "verify", received]);
103
+ await local(["fetch", received, "HEAD"]);
104
+ if ((await local(["rev-parse", "FETCH_HEAD"])).trim() !== head)
105
+ throw new OutpostError("workspace", "Remote bundle HEAD changed during synchronization");
106
+ await local(["rev-list", "--objects", "--missing=error", "--quiet", head]);
107
+ await local(["update-ref", "HEAD", head]);
108
+ const complete = join(transfer, "complete.bundle");
109
+ await local(["bundle", "create", complete, "HEAD"]);
110
+ await rename(complete, bundle);
111
+ if (usable)
112
+ await rm(received);
113
+ }
114
+ //# sourceMappingURL=remote-history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-history.js","sourceRoot":"","sources":["../../src/application/remote-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAMhF,KAAK,UAAU,KAAK,CAClB,SAAgC;IAEhC,IAAI,CAAC;QACH,OAAO,MAAM,SAAS,EAAE,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IACE,KAAK,YAAY,YAAY;YAC7B,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,KAAK,GAAG,CAAC;YAE5D,OAAO,SAA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MAAM,CAAC,CAAC;IAC/B,IAAI,MAAM;QAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,CAAC;AACjC,CAAC","sourcesContent":["import { mkdir, rename, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport type { SandboxLease } from \"../domain/sandbox.types.ts\";\nimport type { WorkspaceRecord } from \"../domain/workspace.types.ts\";\nimport { verificationGit } from \"../infrastructure/git/verification-command.ts\";\nimport type {\n RemoteSyncOptions,\n RemoteWorkspaceContext,\n} from \"./remote-workspace.types.ts\";\n\nasync function probe(\n operation: () => Promise<string>,\n): Promise<string | undefined> {\n try {\n return await operation();\n } catch (error) {\n if (\n error instanceof OutpostError &&\n (error.details.status === 1 || error.details.status === 128)\n )\n return undefined;\n if (\n error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n (error.code === 1 || error.code === 128)\n )\n return undefined;\n throw error;\n }\n}\n\nexport async function seedHistory(\n workspace: WorkspaceRecord,\n lease: SandboxLease,\n options: RemoteSyncOptions,\n recovery: string,\n remoteBundle: string,\n run: RemoteWorkspaceContext[\"run\"],\n): Promise<void> {\n const local = (args: readonly string[]) =>\n verificationGit(\n workspace.directory,\n args,\n options.limits?.gitMs,\n options.signal,\n );\n const bundle = join(recovery, \"initial.bundle\");\n await local([\"bundle\", \"create\", bundle, \"--all\", \"HEAD\"]);\n const head = (await local([\"rev-parse\", \"HEAD\"])).trim();\n const candidate = (\n await probe(() => run([\"rev-parse\", \"--verify\", \"HEAD\"]))\n )?.trim();\n let base: string | undefined;\n if (\n candidate &&\n /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(candidate) &&\n (await probe(() =>\n local([\"merge-base\", \"--is-ancestor\", candidate, head]),\n )) !== undefined &&\n (await probe(() =>\n run([\"rev-list\", \"--objects\", \"--missing=error\", \"--quiet\", candidate]),\n )) !== undefined\n )\n base = candidate;\n if (base === head) {\n await run([\"checkout\", \"-B\", workspace.branch, head]);\n return;\n }\n let payload = bundle;\n if (base) {\n payload = join(recovery, \"initial-delta.bundle\");\n await local([\"bundle\", \"create\", payload, \"--all\", \"HEAD\", `^${base}`]);\n }\n await lease.upload(payload, remoteBundle, {\n ...(options.signal ? { signal: options.signal } : {}),\n ...(options.limits?.copyMs ? { deadlineMs: options.limits.copyMs } : {}),\n });\n if (\n base &&\n (await probe(() => run([\"bundle\", \"verify\", remoteBundle]))) === undefined\n )\n await lease.upload(bundle, remoteBundle, {\n ...(options.signal ? { signal: options.signal } : {}),\n ...(options.limits?.copyMs ? { deadlineMs: options.limits.copyMs } : {}),\n });\n await run([\"bundle\", \"verify\", remoteBundle]);\n await run([\"fetch\", remoteBundle, \"HEAD\"]);\n await run([\"checkout\", \"-B\", workspace.branch, \"FETCH_HEAD\"]);\n}\n\nexport async function prepareHistoryValidation(\n context: RemoteWorkspaceContext,\n transfer: string,\n): Promise<string> {\n const validation = join(transfer, \"validation\");\n await mkdir(validation, { recursive: true });\n const snapshot = join(transfer, \"host.bundle\");\n const run = (directory: string, args: readonly string[]) =>\n verificationGit(directory, args, context.options.limits?.gitMs);\n await run(context.workspace.directory, [\n \"bundle\",\n \"create\",\n snapshot,\n \"HEAD\",\n ]);\n const format = (\n await run(context.workspace.directory, [\n \"rev-parse\",\n \"--show-object-format\",\n ])\n ).trim();\n await run(validation, [\"init\", `--object-format=${format}`]);\n await run(validation, [\"config\", \"core.autocrlf\", \"false\"]);\n await run(validation, [\"fetch\", snapshot, \"HEAD\"]);\n await run(validation, [\"update-ref\", \"HEAD\", \"FETCH_HEAD\"]);\n await rm(snapshot);\n return validation;\n}\n\nexport async function downloadHistory(\n context: RemoteWorkspaceContext,\n synchronized: string,\n head: string,\n transfer: string,\n): Promise<void> {\n const { run, lease, remoteBundle, options } = context;\n const validation = await prepareHistoryValidation(context, transfer);\n const local = (args: readonly string[]) =>\n verificationGit(validation, args, options.limits?.gitMs);\n const usable =\n (await probe(() =>\n local([\n \"rev-list\",\n \"--objects\",\n \"--missing=error\",\n \"--quiet\",\n synchronized,\n ]),\n )) !== undefined &&\n (await probe(() =>\n run([\"merge-base\", \"--is-ancestor\", synchronized, head]),\n )) !== undefined;\n await run([\n \"bundle\",\n \"create\",\n remoteBundle,\n \"HEAD\",\n ...(usable ? [`^${synchronized}`] : []),\n ]);\n const bundle = join(transfer, \"commits.bundle\");\n const received = usable ? join(transfer, \"commits-delta.bundle\") : bundle;\n await lease.download(remoteBundle, received, {\n ...(options.limits?.copyMs ? { deadlineMs: options.limits.copyMs } : {}),\n });\n await local([\"bundle\", \"verify\", received]);\n await local([\"fetch\", received, \"HEAD\"]);\n if ((await local([\"rev-parse\", \"FETCH_HEAD\"])).trim() !== head)\n throw new OutpostError(\n \"workspace\",\n \"Remote bundle HEAD changed during synchronization\",\n );\n await local([\"rev-list\", \"--objects\", \"--missing=error\", \"--quiet\", head]);\n await local([\"update-ref\", \"HEAD\", head]);\n const complete = join(transfer, \"complete.bundle\");\n await local([\"bundle\", \"create\", complete, \"HEAD\"]);\n await rename(complete, bundle);\n if (usable) await rm(received);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import type { SandboxLease, TransferOptions } from "../domain/sandbox.types.ts";
2
+ export declare function uploadFiles(lease: SandboxLease, source: string, paths: readonly string[], options?: TransferOptions): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import { posix } from "node:path";
2
+ import { fileManifest } from "../infrastructure/file-manifest.js";
3
+ import { safeDestination } from "../infrastructure/files.js";
4
+ export async function uploadFiles(lease, source, paths, options = {}) {
5
+ if (lease.fileTransfers?.uploadBatch) {
6
+ const entries = [];
7
+ for (const path of paths) {
8
+ options.signal?.throwIfAborted();
9
+ entries.push(await fileManifest(source, path, options.signal));
10
+ }
11
+ await lease.fileTransfers.uploadBatch(source, entries, lease.root, options);
12
+ return;
13
+ }
14
+ for (const path of paths)
15
+ await lease.upload(await safeDestination(source, path), posix.join(lease.root, path), options);
16
+ }
17
+ //# sourceMappingURL=remote-upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-upload.js","sourceRoot":"","sources":["../../src/application/remote-upload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAmB,EACnB,MAAc,EACd,KAAwB,EACxB,UAA2B,EAAE;IAE7B,IAAI,KAAK,CAAC,aAAa,EAAE,WAAW,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,EAAE,CAAC;QACnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;YACjC,OAAO,CAAC,IAAI,CAAC,MAAM,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QACjE,CAAC;QACD,MAAM,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC5E,OAAO;IACT,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK;QACtB,MAAM,KAAK,CAAC,MAAM,CAChB,MAAM,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,EACnC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,EAC5B,OAAO,CACR,CAAC;AACN,CAAC","sourcesContent":["import { posix } from \"node:path\";\nimport type { SandboxLease, TransferOptions } from \"../domain/sandbox.types.ts\";\nimport { fileManifest } from \"../infrastructure/file-manifest.ts\";\nimport { safeDestination } from \"../infrastructure/files.ts\";\n\nexport async function uploadFiles(\n lease: SandboxLease,\n source: string,\n paths: readonly string[],\n options: TransferOptions = {},\n): Promise<void> {\n if (lease.fileTransfers?.uploadBatch) {\n const entries = [];\n for (const path of paths) {\n options.signal?.throwIfAborted();\n entries.push(await fileManifest(source, path, options.signal));\n }\n await lease.fileTransfers.uploadBatch(source, entries, lease.root, options);\n return;\n }\n for (const path of paths)\n await lease.upload(\n await safeDestination(source, path),\n posix.join(lease.root, path),\n options,\n );\n}\n"]}
@@ -1,5 +1,7 @@
1
- import { readFile } from "node:fs/promises";
1
+ import { readFile, rm } from "node:fs/promises";
2
2
  import { join } from "node:path";
3
+ import { prepareHistoryValidation } from "./remote-history.js";
4
+ import { verificationGit } from "../infrastructure/git/verification-command.js";
3
5
  import { OutpostError } from "../domain/errors.js";
4
6
  import { git } from "../infrastructure/git/command.js";
5
7
  import { remoteSyncLimits } from "./remote-workspace.constants.js";
@@ -40,42 +42,32 @@ export async function validateChanges(context, changes, synchronized, expected,
40
42
  }
41
43
  if ((await digest(workspace.directory, recovery)) !== expected)
42
44
  throw new OutpostError("conflict", "Host workspace changed while the remote sandbox was active", { recovery });
43
- if (head !== synchronized) {
44
- await git(workspace.directory, [
45
- "fetch",
46
- join(transfer, "commits.bundle"),
47
- "HEAD",
48
- ]);
49
- await git(workspace.directory, [
45
+ const validation = join(transfer, "validation");
46
+ if (head === synchronized)
47
+ await prepareHistoryValidation(context, transfer);
48
+ if (head !== synchronized)
49
+ await verificationGit(validation, [
50
50
  "merge-base",
51
51
  "--is-ancestor",
52
- "HEAD",
53
- "FETCH_HEAD",
52
+ synchronized,
53
+ head,
54
54
  ]);
55
- }
56
- const validation = join(transfer, "validation");
57
- await git(workspace.directory, [
58
- "worktree",
59
- "add",
60
- "--detach",
61
- validation,
62
- head,
63
- ]);
55
+ await verificationGit(validation, ["checkout", "--detach", head]);
64
56
  try {
65
57
  if ((await readFile(patch)).length)
66
- await git(validation, ["apply", "--binary", patch]);
58
+ await verificationGit(validation, ["apply", "--binary", patch]);
67
59
  if (!options.includeUncommitted && (await readFile(initialPatch)).length)
68
- await git(validation, ["apply", "--binary", initialPatch]);
60
+ await verificationGit(validation, ["apply", "--binary", initialPatch]);
69
61
  if (!options.includeUncommitted && (await readFile(initialIndex)).length)
70
- await git(validation, ["apply", "--cached", "--binary", initialIndex]);
62
+ await verificationGit(validation, [
63
+ "apply",
64
+ "--cached",
65
+ "--binary",
66
+ initialIndex,
67
+ ]);
71
68
  }
72
69
  finally {
73
- await git(workspace.directory, [
74
- "worktree",
75
- "remove",
76
- "--force",
77
- validation,
78
- ]);
70
+ await rm(validation, { recursive: true, force: true });
79
71
  }
80
72
  }
81
73
  //# sourceMappingURL=remote-validation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-validation.js","sourceRoot":"","sources":["../../src/application/remote-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AAKvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAA+B,EAC/B,OAAsB,EACtB,YAAoB,EACpB,QAAgB,EAChB,QAAgB;IAEhB,MAAM,EACJ,SAAS,EACT,OAAO,EACP,QAAQ,EACR,GAAG,EACH,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,GACb,GAAG,OAAO,CAAC;IACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC1C,MAAM,eAAe,GAAa,EAAE,CAAC;IACrC,KACE,IAAI,MAAM,GAAG,CAAC,EACd,MAAM,GAAG,QAAQ,CAAC,MAAM,EACxB,MAAM,IAAI,gBAAgB,CAAC,SAAS,EACpC,CAAC;QACD,eAAe,CAAC,IAAI,CAClB,GAAG,CACD,MAAM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AAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;IAC3E,CAAC;YAAS,CAAC;QACT,MAAM,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE;YAC7B,UAAU;YACV,QAAQ;YACR,SAAS;YACT,UAAU;SACX,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport type {\n RemoteChanges,\n RemoteWorkspaceContext,\n} from \"./remote-workspace.types.ts\";\nimport { remoteSyncLimits } from \"./remote-workspace.constants.ts\";\nimport { digest } from \"./workspace-fingerprint.ts\";\n\nexport async function validateChanges(\n context: RemoteWorkspaceContext,\n changes: RemoteChanges,\n synchronized: string,\n expected: string,\n transfer: string,\n): Promise<void> {\n const {\n workspace,\n options,\n recovery,\n run,\n protectedFiles,\n originalHead,\n initialPatch,\n initialIndex,\n } = context;\n const { head, patch, incoming } = changes;\n const ignoredOverlaps: string[] = [];\n for (\n let offset = 0;\n offset < incoming.length;\n offset += remoteSyncLimits.pathspecs\n ) {\n ignoredOverlaps.push(\n ...(\n await git(workspace.directory, [\n \"ls-files\",\n \"--others\",\n \"--ignored\",\n \"--exclude-standard\",\n \"-z\",\n \"--\",\n ...incoming\n .slice(offset, offset + remoteSyncLimits.pathspecs)\n .map((path) => `:(literal)${path}`),\n ])\n )\n .split(\"\\0\")\n .filter(Boolean),\n );\n }\n if (ignoredOverlaps.length)\n throw new OutpostError(\n \"conflict\",\n \"Remote changes overlap ignored host files\",\n { files: ignoredOverlaps, recovery: transfer },\n );\n if (protectedFiles.length) {\n const changed = new Set([\n ...(await run([\"diff\", \"--name-only\", \"-z\", originalHead]))\n .split(\"\\0\")\n .filter(Boolean),\n ...incoming,\n ]);\n const overlaps = protectedFiles.filter((file) =>\n [...changed].some(\n (path) =>\n path === file ||\n path.startsWith(`${file}/`) ||\n file.startsWith(`${path}/`),\n ),\n );\n if (overlaps.length)\n throw new OutpostError(\n \"conflict\",\n \"Remote changes overlap uncommitted host files\",\n { files: overlaps, recovery: transfer },\n );\n }\n if ((await digest(workspace.directory, recovery)) !== expected)\n throw new OutpostError(\n \"conflict\",\n \"Host workspace changed while the remote sandbox was active\",\n { recovery },\n );\n if (head !== synchronized) {\n await git(workspace.directory, [\n \"fetch\",\n join(transfer, \"commits.bundle\"),\n \"HEAD\",\n ]);\n await git(workspace.directory, [\n \"merge-base\",\n \"--is-ancestor\",\n \"HEAD\",\n \"FETCH_HEAD\",\n ]);\n }\n const validation = join(transfer, \"validation\");\n await git(workspace.directory, [\n \"worktree\",\n \"add\",\n \"--detach\",\n validation,\n head,\n ]);\n try {\n if ((await readFile(patch)).length)\n await git(validation, [\"apply\", \"--binary\", patch]);\n if (!options.includeUncommitted && (await readFile(initialPatch)).length)\n await git(validation, [\"apply\", \"--binary\", initialPatch]);\n if (!options.includeUncommitted && (await readFile(initialIndex)).length)\n await git(validation, [\"apply\", \"--cached\", \"--binary\", initialIndex]);\n } finally {\n await git(workspace.directory, [\n \"worktree\",\n \"remove\",\n \"--force\",\n validation,\n ]);\n }\n}\n"]}
1
+ {"version":3,"file":"remote-validation.js","sourceRoot":"","sources":["../../src/application/remote-validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AAKvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD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AE,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC,OAAO,CAAC,kBAAkB,IAAI,CAAC,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM;YACtE,MAAM,eAAe,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC,OAAO,CAAC,kBAAkB,IAAI,CAAC,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM;YACtE,MAAM,eAAe,CAAC,UAAU,EAAE;gBAChC,OAAO;gBACP,UAAU;gBACV,UAAU;gBACV,YAAY;aACb,CAAC,CAAC;IACP,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACzD,CAAC;AACH,CAAC","sourcesContent":["import { readFile, rm } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { prepareHistoryValidation } from \"./remote-history.ts\";\nimport { verificationGit } from \"../infrastructure/git/verification-command.ts\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport type {\n RemoteChanges,\n RemoteWorkspaceContext,\n} from \"./remote-workspace.types.ts\";\nimport { remoteSyncLimits } from \"./remote-workspace.constants.ts\";\nimport { digest } from \"./workspace-fingerprint.ts\";\n\nexport async function validateChanges(\n context: RemoteWorkspaceContext,\n changes: RemoteChanges,\n synchronized: string,\n expected: string,\n transfer: string,\n): Promise<void> {\n const {\n workspace,\n options,\n recovery,\n run,\n protectedFiles,\n originalHead,\n initialPatch,\n initialIndex,\n } = context;\n const { head, patch, incoming } = changes;\n const ignoredOverlaps: string[] = [];\n for (\n let offset = 0;\n offset < incoming.length;\n offset += remoteSyncLimits.pathspecs\n ) {\n ignoredOverlaps.push(\n ...(\n await git(workspace.directory, [\n \"ls-files\",\n \"--others\",\n \"--ignored\",\n \"--exclude-standard\",\n \"-z\",\n \"--\",\n ...incoming\n .slice(offset, offset + remoteSyncLimits.pathspecs)\n .map((path) => `:(literal)${path}`),\n ])\n )\n .split(\"\\0\")\n .filter(Boolean),\n );\n }\n if (ignoredOverlaps.length)\n throw new OutpostError(\n \"conflict\",\n \"Remote changes overlap ignored host files\",\n { files: ignoredOverlaps, recovery: transfer },\n );\n if (protectedFiles.length) {\n const changed = new Set([\n ...(await run([\"diff\", \"--name-only\", \"-z\", originalHead]))\n .split(\"\\0\")\n .filter(Boolean),\n ...incoming,\n ]);\n const overlaps = protectedFiles.filter((file) =>\n [...changed].some(\n (path) =>\n path === file ||\n path.startsWith(`${file}/`) ||\n file.startsWith(`${path}/`),\n ),\n );\n if (overlaps.length)\n throw new OutpostError(\n \"conflict\",\n \"Remote changes overlap uncommitted host files\",\n { files: overlaps, recovery: transfer },\n );\n }\n if ((await digest(workspace.directory, recovery)) !== expected)\n throw new OutpostError(\n \"conflict\",\n \"Host workspace changed while the remote sandbox was active\",\n { recovery },\n );\n const validation = join(transfer, \"validation\");\n if (head === synchronized) await prepareHistoryValidation(context, transfer);\n if (head !== synchronized)\n await verificationGit(validation, [\n \"merge-base\",\n \"--is-ancestor\",\n synchronized,\n head,\n ]);\n await verificationGit(validation, [\"checkout\", \"--detach\", head]);\n try {\n if ((await readFile(patch)).length)\n await verificationGit(validation, [\"apply\", \"--binary\", patch]);\n if (!options.includeUncommitted && (await readFile(initialPatch)).length)\n await verificationGit(validation, [\"apply\", \"--binary\", initialPatch]);\n if (!options.includeUncommitted && (await readFile(initialIndex)).length)\n await verificationGit(validation, [\n \"apply\",\n \"--cached\",\n \"--binary\",\n initialIndex,\n ]);\n } finally {\n await rm(validation, { recursive: true, force: true });\n }\n}\n"]}
@@ -2,7 +2,8 @@ import { randomUUID } from "node:crypto";
2
2
  import { mkdir, readFile, rm } from "node:fs/promises";
3
3
  import { join, posix } from "node:path";
4
4
  import { OutpostError } from "../domain/errors.js";
5
- import { safeDestination } from "../infrastructure/files.js";
5
+ import { seedHistory } from "./remote-history.js";
6
+ import { uploadFiles } from "./remote-upload.js";
6
7
  import { git } from "../infrastructure/git/command.js";
7
8
  import { gitDefaults } from "../infrastructure/git/git.constants.js";
8
9
  import { applyChanges } from "./remote-apply.js";
@@ -14,10 +15,7 @@ export async function seedRemote(workspace, lease, options = {}) {
14
15
  options.signal?.throwIfAborted();
15
16
  const recovery = join(workspace.repository, ".outpost", "recovery", randomUUID());
16
17
  await mkdir(recovery, { recursive: true });
17
- const bundle = join(recovery, "initial.bundle");
18
- await git(workspace.directory, ["bundle", "create", bundle, "--all", "HEAD"]);
19
18
  const remoteBundle = posix.join(lease.root.replaceAll("\\", "/"), "..", `outpost-${randomUUID()}.bundle`);
20
- await lease.upload(bundle, remoteBundle);
21
19
  let initializing = true, failed = false;
22
20
  const run = async (args) => {
23
21
  let result;
@@ -46,8 +44,7 @@ export async function seedRemote(workspace, lease, options = {}) {
46
44
  };
47
45
  await run(["init"]);
48
46
  await run(["config", "core.autocrlf", "false"]);
49
- await run(["fetch", remoteBundle, "HEAD"]);
50
- await run(["checkout", "-B", workspace.branch, "FETCH_HEAD"]);
47
+ await seedHistory(workspace, lease, options, recovery, remoteBundle, run);
51
48
  for (const key of ["user.name", "user.email"]) {
52
49
  const fallback = key === "user.name" ? "Outpost" : "outpost@localhost";
53
50
  const value = (await git(workspace.repository, ["config", "--get", key]).catch(() => fallback)).trim() || fallback;
@@ -80,10 +77,7 @@ export async function seedRemote(workspace, lease, options = {}) {
80
77
  await lease.upload(initialPatch, `${remoteBundle}.patch`);
81
78
  await run(["apply", "--binary", `${remoteBundle}.patch`]);
82
79
  }
83
- for (const file of options.includeUncommitted
84
- ? await extras(workspace.directory)
85
- : [])
86
- await lease.upload(await safeDestination(workspace.directory, file), posix.join(lease.root, file));
80
+ await uploadFiles(lease, workspace.directory, options.includeUncommitted ? await extras(workspace.directory) : [], { ...(options.signal ? { signal: options.signal } : {}) });
87
81
  let synchronized = (await run(["rev-parse", "HEAD"])).trim();
88
82
  initializing = false;
89
83
  let expected = await digest(workspace.directory, recovery);
@@ -1 +1 @@
1
- {"version":3,"file":"remote-workspace.js","sourceRoot":"","sources":["../../src/application/remote-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAMzD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAO5D,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,SAA0B,EAC1B,KAAmB,EACnB,UAA6B,EAAE;IAE/B,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,IAAI,CACnB,SAAS,CAAC,UAAU,EACpB,UAAU,EACV,UAAU,EACV,UAAU,EAAE,CACb,CAAC;IACF,MAAM,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;IAChD,MAAM,GAAG,CAA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EACP,MAAM,EACN,YAAY,EACZ,QAAQ,EACR,QAAQ,CACT,CAAC;gBACF,OAAO,CAAC,WAAW,EAAE,KAAK,EAAE,CAAC;gBAC7B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,IAAI,EAAE;oBACxC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC9C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;gBACzB,YAAY,GAAG,IAAI,CAAC;gBACpB,QAAQ,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBACvD,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACvD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,IAAI,YAAY,CACpB,WAAW,EACX,yEAAyE,EACzE,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,EACtD,KAAK,CACN,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rm } from \"node:fs/promises\";\nimport { join, posix } from \"node:path\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport type { SandboxLease } from \"../domain/sandbox.types.ts\";\nimport type { WorkspaceRecord } from \"../domain/workspace.types.ts\";\nimport { safeDestination } from \"../infrastructure/files.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { gitDefaults } from \"../infrastructure/git/git.constants.ts\";\nimport { applyChanges } from \"./remote-apply.ts\";\nimport { backupHost } from \"./remote-backup.ts\";\nimport { downloadChanges } from \"./remote-download.ts\";\nimport { validateChanges } from \"./remote-validation.ts\";\nimport type {\n RemoteSync,\n RemoteSyncOptions,\n RemoteWorkspaceContext,\n} from \"./remote-workspace.types.ts\";\nimport { digest, extras } from \"./workspace-fingerprint.ts\";\n\nexport type {\n RemoteSync,\n RemoteSyncOptions,\n} from \"./remote-workspace.types.ts\";\n\nexport async function seedRemote(\n workspace: WorkspaceRecord,\n lease: SandboxLease,\n options: RemoteSyncOptions = {},\n): Promise<RemoteSync> {\n options.signal?.throwIfAborted();\n const recovery = join(\n workspace.repository,\n \".outpost\",\n \"recovery\",\n randomUUID(),\n );\n await mkdir(recovery, { recursive: true });\n const bundle = join(recovery, \"initial.bundle\");\n await git(workspace.directory, [\"bundle\", \"create\", bundle, \"--all\", \"HEAD\"]);\n const remoteBundle = posix.join(\n lease.root.replaceAll(\"\\\\\", \"/\"),\n \"..\",\n `outpost-${randomUUID()}.bundle`,\n );\n await lease.upload(bundle, remoteBundle);\n let initializing = true,\n failed = false;\n const run = async (args: readonly string[]) => {\n let result;\n for (let attempt = 0; attempt < 3; attempt++) {\n result = await lease.invoke({\n executable: \"git\",\n arguments: args,\n directory: lease.root,\n retain: gitDefaults.retainBytes,\n ...(initializing && options.signal ? { signal: options.signal } : {}),\n ...(options.limits?.gitMs ? { deadlineMs: options.limits.gitMs } : {}),\n });\n if (!initializing || result.status !== 126) break;\n }\n if (!result)\n throw new OutpostError(\"workspace\", \"Remote Git did not start\");\n if (result.status !== 0)\n throw new OutpostError(\"workspace\", \"Remote Git operation failed\", {\n ...result,\n recovery,\n });\n if (result.stdout.length >= gitDefaults.retainBytes)\n throw new OutpostError(\n \"workspace\",\n \"Remote Git output exceeds synchronization limit\",\n { recovery },\n );\n return result.stdout;\n };\n await run([\"init\"]);\n await run([\"config\", \"core.autocrlf\", \"false\"]);\n await run([\"fetch\", remoteBundle, \"HEAD\"]);\n await run([\"checkout\", \"-B\", workspace.branch, \"FETCH_HEAD\"]);\n for (const key of [\"user.name\", \"user.email\"] as const) {\n const fallback = key === \"user.name\" ? \"Outpost\" : \"outpost@localhost\";\n const value =\n (\n await git(workspace.repository, [\"config\", \"--get\", key]).catch(\n () => fallback,\n )\n ).trim() || fallback;\n await run([\"config\", key, value]);\n }\n const initialPatch = join(recovery, \"initial.patch\");\n await git(workspace.directory, [\n \"diff\",\n \"--binary\",\n \"HEAD\",\n `--output=${initialPatch}`,\n ]);\n const initialIndex = join(recovery, \"initial-index.patch\");\n await git(workspace.directory, [\n \"diff\",\n \"--cached\",\n \"--binary\",\n `--output=${initialIndex}`,\n ]);\n const protectedFiles = options.includeUncommitted\n ? []\n : [\n ...(\n await git(workspace.directory, [\"diff\", \"--name-only\", \"-z\", \"HEAD\"])\n )\n .split(\"\\0\")\n .filter(Boolean),\n ...(await extras(workspace.directory)),\n ];\n const originalHead = (\n await git(workspace.directory, [\"rev-parse\", \"HEAD\"])\n ).trim();\n if (options.includeUncommitted && (await readFile(initialPatch)).length) {\n await lease.upload(initialPatch, `${remoteBundle}.patch`);\n await run([\"apply\", \"--binary\", `${remoteBundle}.patch`]);\n }\n for (const file of options.includeUncommitted\n ? await extras(workspace.directory)\n : [])\n await lease.upload(\n await safeDestination(workspace.directory, file),\n posix.join(lease.root, file),\n );\n let synchronized = (await run([\"rev-parse\", \"HEAD\"])).trim();\n initializing = false;\n let expected = await digest(workspace.directory, recovery);\n const context: RemoteWorkspaceContext = {\n transferred: new Map(),\n workspace,\n lease,\n options,\n recovery,\n remoteBundle,\n run,\n protectedFiles,\n originalHead,\n initialPatch,\n initialIndex,\n };\n return {\n async close() {\n if (!failed) await rm(recovery, { recursive: true, force: true });\n },\n async pull() {\n const transfer = join(recovery, randomUUID());\n await mkdir(transfer, { recursive: true });\n try {\n const changes = await downloadChanges(context, synchronized, transfer);\n await validateChanges(\n context,\n changes,\n synchronized,\n expected,\n transfer,\n );\n const backup = await backupHost(\n context,\n changes,\n synchronized,\n transfer,\n );\n await applyChanges(\n context,\n changes,\n backup,\n synchronized,\n expected,\n transfer,\n );\n context.transferred?.clear();\n for (const entry of changes.manifest ?? [])\n context.transferred?.set(entry.path, entry);\n const { head } = changes;\n synchronized = head;\n expected = await digest(workspace.directory, recovery);\n await rm(transfer, { recursive: true, force: true });\n } catch (cause) {\n failed = true;\n throw new OutpostError(\n \"workspace\",\n \"Remote changes could not be fully synchronized; recovery files retained\",\n { recovery: transfer, directory: workspace.directory },\n cause,\n );\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"remote-workspace.js","sourceRoot":"","sources":["../../src/application/remote-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wCAAwC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAMzD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAO5D,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,SAA0B,EAC1B,KAAmB,EACnB,UAA6B,EAAE;IAE/B,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACjC,MAAM,QAAQ,GAAG,IAAI,CACnB,SAAS,CAAC,UAAU,EACpB,UAAU,EACV,UAAU,EACV,UAAU,EAAE,CACb,CAAC;IACF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oBACxC,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;gBAC9C,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;gBACzB,YAAY,GAAG,IAAI,CAAC;gBACpB,QAAQ,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;gBACvD,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACvD,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,GAAG,IAAI,CAAC;gBACd,MAAM,IAAI,YAAY,CACpB,WAAW,EACX,yEAAyE,EACzE,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,EACtD,KAAK,CACN,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { mkdir, readFile, rm } from \"node:fs/promises\";\nimport { join, posix } from \"node:path\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport type { SandboxLease } from \"../domain/sandbox.types.ts\";\nimport type { WorkspaceRecord } from \"../domain/workspace.types.ts\";\nimport { seedHistory } from \"./remote-history.ts\";\nimport { uploadFiles } from \"./remote-upload.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { gitDefaults } from \"../infrastructure/git/git.constants.ts\";\nimport { applyChanges } from \"./remote-apply.ts\";\nimport { backupHost } from \"./remote-backup.ts\";\nimport { downloadChanges } from \"./remote-download.ts\";\nimport { validateChanges } from \"./remote-validation.ts\";\nimport type {\n RemoteSync,\n RemoteSyncOptions,\n RemoteWorkspaceContext,\n} from \"./remote-workspace.types.ts\";\nimport { digest, extras } from \"./workspace-fingerprint.ts\";\n\nexport type {\n RemoteSync,\n RemoteSyncOptions,\n} from \"./remote-workspace.types.ts\";\n\nexport async function seedRemote(\n workspace: WorkspaceRecord,\n lease: SandboxLease,\n options: RemoteSyncOptions = {},\n): Promise<RemoteSync> {\n options.signal?.throwIfAborted();\n const recovery = join(\n workspace.repository,\n \".outpost\",\n \"recovery\",\n randomUUID(),\n );\n await mkdir(recovery, { recursive: true });\n const remoteBundle = posix.join(\n lease.root.replaceAll(\"\\\\\", \"/\"),\n \"..\",\n `outpost-${randomUUID()}.bundle`,\n );\n let initializing = true,\n failed = false;\n const run = async (args: readonly string[]) => {\n let result;\n for (let attempt = 0; attempt < 3; attempt++) {\n result = await lease.invoke({\n executable: \"git\",\n arguments: args,\n directory: lease.root,\n retain: gitDefaults.retainBytes,\n ...(initializing && options.signal ? { signal: options.signal } : {}),\n ...(options.limits?.gitMs ? { deadlineMs: options.limits.gitMs } : {}),\n });\n if (!initializing || result.status !== 126) break;\n }\n if (!result)\n throw new OutpostError(\"workspace\", \"Remote Git did not start\");\n if (result.status !== 0)\n throw new OutpostError(\"workspace\", \"Remote Git operation failed\", {\n ...result,\n recovery,\n });\n if (result.stdout.length >= gitDefaults.retainBytes)\n throw new OutpostError(\n \"workspace\",\n \"Remote Git output exceeds synchronization limit\",\n { recovery },\n );\n return result.stdout;\n };\n await run([\"init\"]);\n await run([\"config\", \"core.autocrlf\", \"false\"]);\n await seedHistory(workspace, lease, options, recovery, remoteBundle, run);\n for (const key of [\"user.name\", \"user.email\"] as const) {\n const fallback = key === \"user.name\" ? \"Outpost\" : \"outpost@localhost\";\n const value =\n (\n await git(workspace.repository, [\"config\", \"--get\", key]).catch(\n () => fallback,\n )\n ).trim() || fallback;\n await run([\"config\", key, value]);\n }\n const initialPatch = join(recovery, \"initial.patch\");\n await git(workspace.directory, [\n \"diff\",\n \"--binary\",\n \"HEAD\",\n `--output=${initialPatch}`,\n ]);\n const initialIndex = join(recovery, \"initial-index.patch\");\n await git(workspace.directory, [\n \"diff\",\n \"--cached\",\n \"--binary\",\n `--output=${initialIndex}`,\n ]);\n const protectedFiles = options.includeUncommitted\n ? []\n : [\n ...(\n await git(workspace.directory, [\"diff\", \"--name-only\", \"-z\", \"HEAD\"])\n )\n .split(\"\\0\")\n .filter(Boolean),\n ...(await extras(workspace.directory)),\n ];\n const originalHead = (\n await git(workspace.directory, [\"rev-parse\", \"HEAD\"])\n ).trim();\n if (options.includeUncommitted && (await readFile(initialPatch)).length) {\n await lease.upload(initialPatch, `${remoteBundle}.patch`);\n await run([\"apply\", \"--binary\", `${remoteBundle}.patch`]);\n }\n await uploadFiles(\n lease,\n workspace.directory,\n options.includeUncommitted ? await extras(workspace.directory) : [],\n { ...(options.signal ? { signal: options.signal } : {}) },\n );\n let synchronized = (await run([\"rev-parse\", \"HEAD\"])).trim();\n initializing = false;\n let expected = await digest(workspace.directory, recovery);\n const context: RemoteWorkspaceContext = {\n transferred: new Map(),\n workspace,\n lease,\n options,\n recovery,\n remoteBundle,\n run,\n protectedFiles,\n originalHead,\n initialPatch,\n initialIndex,\n };\n return {\n async close() {\n if (!failed) await rm(recovery, { recursive: true, force: true });\n },\n async pull() {\n const transfer = join(recovery, randomUUID());\n await mkdir(transfer, { recursive: true });\n try {\n const changes = await downloadChanges(context, synchronized, transfer);\n await validateChanges(\n context,\n changes,\n synchronized,\n expected,\n transfer,\n );\n const backup = await backupHost(\n context,\n changes,\n synchronized,\n transfer,\n );\n await applyChanges(\n context,\n changes,\n backup,\n synchronized,\n expected,\n transfer,\n );\n context.transferred?.clear();\n for (const entry of changes.manifest ?? [])\n context.transferred?.set(entry.path, entry);\n const { head } = changes;\n synchronized = head;\n expected = await digest(workspace.directory, recovery);\n await rm(transfer, { recursive: true, force: true });\n } catch (cause) {\n failed = true;\n throw new OutpostError(\n \"workspace\",\n \"Remote changes could not be fully synchronized; recovery files retained\",\n { recovery: transfer, directory: workspace.directory },\n cause,\n );\n }\n },\n };\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import type { SandboxLease } from "../domain/sandbox.types.ts";
2
+ import type { ResourceActivity } from "../infrastructure/resource-activity.types.ts";
3
+ export declare function trackedSandboxLease(lease: SandboxLease, activity: ResourceActivity): SandboxLease;
@@ -0,0 +1,25 @@
1
+ export function trackedSandboxLease(lease, activity) {
2
+ const transfers = lease.fileTransfers;
3
+ const upload = transfers?.uploadBatch?.bind(transfers);
4
+ const uploadBatch = upload
5
+ ? (...args) => activity.run("upload-batch", () => upload(...args))
6
+ : undefined;
7
+ return {
8
+ ...lease,
9
+ invoke: (command) => activity.run("invoke", () => lease.invoke(command)),
10
+ upload: (source, destination, options) => activity.run("upload", () => lease.upload(source, destination, options)),
11
+ download: (source, destination, options) => activity.run("download", () => lease.download(source, destination, options)),
12
+ release: lease.release.bind(lease),
13
+ ...(transfers
14
+ ? {
15
+ fileTransfers: {
16
+ ...transfers,
17
+ ...(uploadBatch ? { uploadBatch } : {}),
18
+ manifest: (source, paths, options) => activity.run("manifest", () => transfers.manifest(source, paths, options)),
19
+ downloadBatch: (source, entries, destination, options) => activity.run("download-batch", () => transfers.downloadBatch(source, entries, destination, options)),
20
+ },
21
+ }
22
+ : {}),
23
+ };
24
+ }
25
+ //# sourceMappingURL=sandbox-activity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-activity.js","sourceRoot":"","sources":["../../src/application/sandbox-activity.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,mBAAmB,CACjC,KAAmB,EACnB,QAA0B;IAE1B,MAAM,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC;IACtC,MAAM,MAAM,GAAG,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACvD,MAAM,WAAW,GAAiC,MAAM;QACtD,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;QAClE,CAAC,CAAC,SAAS,CAAC;IACd,OAAO;QACL,GAAG,KAAK;QACR,MAAM,EAAE,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J,CAAC","sourcesContent":["import type { FileTransfers, SandboxLease } from \"../domain/sandbox.types.ts\";\nimport type { ResourceActivity } from \"../infrastructure/resource-activity.types.ts\";\n\nexport function trackedSandboxLease(\n lease: SandboxLease,\n activity: ResourceActivity,\n): SandboxLease {\n const transfers = lease.fileTransfers;\n const upload = transfers?.uploadBatch?.bind(transfers);\n const uploadBatch: FileTransfers[\"uploadBatch\"] = upload\n ? (...args) => activity.run(\"upload-batch\", () => upload(...args))\n : undefined;\n return {\n ...lease,\n invoke: (command) => activity.run(\"invoke\", () => lease.invoke(command)),\n upload: (source, destination, options) =>\n activity.run(\"upload\", () => lease.upload(source, destination, options)),\n download: (source, destination, options) =>\n activity.run(\"download\", () =>\n lease.download(source, destination, options),\n ),\n release: lease.release.bind(lease),\n ...(transfers\n ? {\n fileTransfers: {\n ...transfers,\n ...(uploadBatch ? { uploadBatch } : {}),\n manifest: (source, paths, options) =>\n activity.run(\"manifest\", () =>\n transfers.manifest(source, paths, options),\n ),\n downloadBatch: (source, entries, destination, options) =>\n activity.run(\"download-batch\", () =>\n transfers.downloadBatch(source, entries, destination, options),\n ),\n },\n }\n : {}),\n };\n}\n"]}
@@ -1,13 +1,16 @@
1
- import { stat } from "node:fs/promises";
1
+ import { lstat } from "node:fs/promises";
2
2
  import { join, posix } from "node:path";
3
3
  import { invariant } from "../domain/errors.js";
4
4
  import { git } from "../infrastructure/git/command.js";
5
5
  import { executeProcess } from "../infrastructure/process.js";
6
6
  import { resolveVariables } from "../infrastructure/settings.js";
7
+ import { registerResourceActivity } from "../infrastructure/resource-activity.js";
8
+ import { trackedSandboxLease } from "./sandbox-activity.js";
7
9
  import { boundedTransfers } from "../infrastructure/transfer.js";
8
10
  import { docker } from "../providers/docker.js";
9
11
  import { prepareAdapter } from "./agent-bootstrap.js";
10
12
  import { hooks } from "./lifecycle-hooks.js";
13
+ import { uploadFiles } from "./remote-upload.js";
11
14
  import { seedRemote } from "./remote-workspace.js";
12
15
  import { startupFailure } from "./startup-recovery.js";
13
16
  import { workspaces } from "./workspace-registry.js";
@@ -18,7 +21,10 @@ export async function provisionSandbox(options) {
18
21
  if (provider.placement === "remote" && !options.workspace && !options.branch)
19
22
  options = { ...options, branch: { mode: "integrate" } };
20
23
  invariant(!options.workspace ||
21
- (!options.repository && !options.branch && !options.copies), "A supplied workspace owns its repository, branch and copied inputs");
24
+ (!options.repository &&
25
+ !options.branch &&
26
+ !options.copies &&
27
+ !options.storageQuota), "A supplied workspace owns its repository, branch, copied inputs and storage quota");
22
28
  const owned = !options.workspace;
23
29
  invariant(provider.placement !== "remote" ||
24
30
  ((options.workspace?.policy ?? options.branch)?.mode !== "current" &&
@@ -33,9 +39,17 @@ export async function provisionSandbox(options) {
33
39
  ? AbortSignal.any([options.signal, stop.signal])
34
40
  : stop.signal;
35
41
  let lease, sync;
42
+ let activity;
43
+ let acquisitionStarted = false;
36
44
  const prepared = new Map();
37
45
  const staging = join(workspace.repository, ".outpost", "recovery", "conversations");
38
46
  try {
47
+ activity = await registerResourceActivity({
48
+ repository: workspace.repository,
49
+ workspace: workspace.directory,
50
+ provider: provider.name,
51
+ placement: provider.placement,
52
+ });
39
53
  const configured = await resolveVariables(workspace.repository, {}, provider.variables);
40
54
  const name = (await git(workspace.repository, ["config", "--get", "user.name"]).catch(() => "Outpost")).trim();
41
55
  const email = (await git(workspace.repository, ["config", "--get", "user.email"]).catch(() => "outpost@localhost")).trim();
@@ -46,13 +60,14 @@ export async function provisionSandbox(options) {
46
60
  GIT_COMMITTER_EMAIL: email,
47
61
  ...configured,
48
62
  };
49
- lease = boundedTransfers(await provider.acquire({
63
+ acquisitionStarted = true;
64
+ lease = boundedTransfers(trackedSandboxLease(await provider.acquire({
50
65
  repository: workspace.repository,
51
66
  directory: workspace.directory,
52
67
  gitDirectories: workspace.gitDirectories,
53
68
  variables,
54
69
  signal: setupSignal,
55
- }), {
70
+ }), activity), {
56
71
  ...(options.limits?.copyMs
57
72
  ? { deadlineMs: options.limits.copyMs }
58
73
  : {}),
@@ -63,13 +78,24 @@ export async function provisionSandbox(options) {
63
78
  ...(options.limits ? { limits: options.limits } : {}),
64
79
  signal: setupSignal,
65
80
  });
66
- for (const path of options.copies ?? [])
67
- if (await stat(join(workspace.directory, path)).catch((error) => {
81
+ const copiedFiles = [];
82
+ for (const path of options.copies ?? []) {
83
+ const info = await lstat(join(workspace.directory, path)).catch((error) => {
68
84
  if (error.code === "ENOENT")
69
85
  return undefined;
70
86
  throw error;
71
- }))
72
- await lease.upload(join(workspace.directory, path), posix.join(lease.root, path.replaceAll("\\", "/")));
87
+ });
88
+ if (!info)
89
+ continue;
90
+ if (info.isFile() || info.isSymbolicLink()) {
91
+ copiedFiles.push(path.replaceAll("\\", "/"));
92
+ continue;
93
+ }
94
+ await lease.upload(join(workspace.directory, path), posix.join(lease.root, path.replaceAll("\\", "/")), { signal: setupSignal });
95
+ }
96
+ await uploadFiles(lease, workspace.directory, [...new Set(copiedFiles)], {
97
+ signal: setupSignal,
98
+ });
73
99
  if (options.bootstrap !== false && options.agent)
74
100
  prepared.set(options.agent, await prepareAdapter(options.agent, lease, setupSignal));
75
101
  }
@@ -83,13 +109,31 @@ export async function provisionSandbox(options) {
83
109
  const failure = initialized.find((item) => item.status === "rejected");
84
110
  if (failure?.status === "rejected")
85
111
  throw failure.reason;
112
+ await activity.phase("ready");
86
113
  }
87
114
  catch (cause) {
88
115
  await startupFailure(workspace, cause, options);
89
- await lease?.release().catch(() => undefined);
116
+ const allocationUncertain = acquisitionStarted && !lease;
117
+ let cleanupFailed = allocationUncertain;
118
+ await activity?.phase("closing").catch(() => {
119
+ cleanupFailed = true;
120
+ });
121
+ await lease?.release().catch(() => {
122
+ cleanupFailed = true;
123
+ });
124
+ if (activity && !(await activity.idle()))
125
+ cleanupFailed = true;
90
126
  state.active = false;
91
127
  if (owned)
92
- await workspace.close();
128
+ await workspace.close({ preserve: cleanupFailed }).catch(() => {
129
+ cleanupFailed = true;
130
+ });
131
+ if (cleanupFailed)
132
+ await activity
133
+ ?.phase(allocationUncertain ? "allocation-uncertain" : "cleanup-failed")
134
+ .catch(() => undefined);
135
+ if (!cleanupFailed)
136
+ await activity?.remove().catch(() => undefined);
93
137
  throw cause;
94
138
  }
95
139
  return {
@@ -100,6 +144,7 @@ export async function provisionSandbox(options) {
100
144
  owned,
101
145
  stop,
102
146
  runtime: lease,
147
+ activity,
103
148
  sync,
104
149
  prepared,
105
150
  staging,