@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.
- package/CHANGELOG.md +42 -0
- package/README.md +3 -1
- package/SECURITY.md +3 -1
- package/dist/adapters/agents/claude-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/claude-diagnostics.js +7 -0
- package/dist/adapters/agents/claude-diagnostics.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.constants.d.ts +12 -0
- package/dist/adapters/agents/cli-diagnostics.constants.js +24 -0
- package/dist/adapters/agents/cli-diagnostics.constants.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.d.ts +4 -0
- package/dist/adapters/agents/cli-diagnostics.js +14 -0
- package/dist/adapters/agents/cli-diagnostics.js.map +1 -0
- package/dist/adapters/agents/cli-diagnostics.types.d.ts +13 -0
- package/dist/adapters/agents/cli-diagnostics.types.js +2 -0
- package/dist/adapters/agents/cli-diagnostics.types.js.map +1 -0
- package/dist/adapters/agents/codex-diagnostics.d.ts +1 -0
- package/dist/adapters/agents/codex-diagnostics.js +7 -0
- package/dist/adapters/agents/codex-diagnostics.js.map +1 -0
- package/dist/adapters/agents/gemini-adapter.d.ts +3 -0
- package/dist/adapters/agents/gemini-adapter.js +15 -0
- package/dist/adapters/agents/gemini-adapter.js.map +1 -0
- package/dist/adapters/agents/gemini-diagnostics.d.ts +2 -0
- package/dist/adapters/agents/gemini-diagnostics.js +15 -0
- package/dist/adapters/agents/gemini-diagnostics.js.map +1 -0
- package/dist/adapters/agents/gemini-events.d.ts +2 -0
- package/dist/adapters/agents/gemini-events.js +50 -0
- package/dist/adapters/agents/gemini-events.js.map +1 -0
- package/dist/adapters/agents/gemini-request.d.ts +4 -0
- package/dist/adapters/agents/gemini-request.js +21 -0
- package/dist/adapters/agents/gemini-request.js.map +1 -0
- package/dist/adapters/agents/gemini.types.d.ts +6 -0
- package/dist/adapters/agents/gemini.types.js +2 -0
- package/dist/adapters/agents/gemini.types.js.map +1 -0
- package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -0
- package/dist/adapters/agents/protocol-fixtures.constants.js +105 -0
- package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -0
- package/dist/adapters/agents/protocol-fixtures.types.d.ts +6 -0
- package/dist/adapters/agents/protocol-fixtures.types.js +2 -0
- package/dist/adapters/agents/protocol-fixtures.types.js.map +1 -0
- package/dist/application/agent-bootstrap.constants.d.ts +1 -0
- package/dist/application/agent-bootstrap.constants.js +1 -0
- package/dist/application/agent-bootstrap.constants.js.map +1 -1
- package/dist/application/agent-bootstrap.js +6 -2
- package/dist/application/agent-bootstrap.js.map +1 -1
- package/dist/application/agent-output.js +9 -2
- package/dist/application/agent-output.js.map +1 -1
- package/dist/application/artifact-tasks.d.ts +5 -0
- package/dist/application/artifact-tasks.js +31 -0
- package/dist/application/artifact-tasks.js.map +1 -0
- package/dist/application/artifact-tasks.types.d.ts +8 -0
- package/dist/application/artifact-tasks.types.js +2 -0
- package/dist/application/artifact-tasks.types.js.map +1 -0
- package/dist/application/diagnostic-probe.d.ts +3 -0
- package/dist/application/diagnostic-probe.js +55 -0
- package/dist/application/diagnostic-probe.js.map +1 -0
- package/dist/application/dispatch-validation.js +2 -0
- package/dist/application/dispatch-validation.js.map +1 -1
- package/dist/application/doctor-agent.constants.d.ts +11 -0
- package/dist/application/doctor-agent.constants.js +10 -0
- package/dist/application/doctor-agent.constants.js.map +1 -0
- package/dist/application/doctor-agent.d.ts +3 -0
- package/dist/application/doctor-agent.js +53 -0
- package/dist/application/doctor-agent.js.map +1 -0
- package/dist/application/doctor-image.d.ts +3 -0
- package/dist/application/doctor-image.js +133 -0
- package/dist/application/doctor-image.js.map +1 -0
- package/dist/application/doctor-protocol.d.ts +3 -0
- package/dist/application/doctor-protocol.js +30 -0
- package/dist/application/doctor-protocol.js.map +1 -0
- package/dist/application/doctor-protocol.types.d.ts +10 -0
- package/dist/application/doctor-protocol.types.js +2 -0
- package/dist/application/doctor-protocol.types.js.map +1 -0
- package/dist/application/doctor-sandbox.constants.d.ts +5 -0
- package/dist/application/doctor-sandbox.constants.js +6 -0
- package/dist/application/doctor-sandbox.constants.js.map +1 -0
- package/dist/application/doctor-sandbox.d.ts +4 -0
- package/dist/application/doctor-sandbox.js +133 -0
- package/dist/application/doctor-sandbox.js.map +1 -0
- package/dist/application/doctor-sandbox.types.d.ts +23 -0
- package/dist/application/doctor-sandbox.types.js +2 -0
- package/dist/application/doctor-sandbox.types.js.map +1 -0
- package/dist/application/doctor-transfers.constants.d.ts +6 -0
- package/dist/application/doctor-transfers.constants.js +7 -0
- package/dist/application/doctor-transfers.constants.js.map +1 -0
- package/dist/application/doctor-transfers.d.ts +4 -0
- package/dist/application/doctor-transfers.js +88 -0
- package/dist/application/doctor-transfers.js.map +1 -0
- package/dist/application/doctor.constants.d.ts +9 -0
- package/dist/application/doctor.constants.js +15 -0
- package/dist/application/doctor.constants.js.map +1 -0
- package/dist/application/doctor.d.ts +3 -0
- package/dist/application/doctor.js +106 -0
- package/dist/application/doctor.js.map +1 -0
- package/dist/application/doctor.types.d.ts +39 -0
- package/dist/application/doctor.types.js +2 -0
- package/dist/application/doctor.types.js.map +1 -0
- package/dist/application/execution.js +1 -0
- package/dist/application/execution.js.map +1 -1
- package/dist/application/outpost.types.d.ts +4 -0
- package/dist/application/outpost.types.js.map +1 -1
- package/dist/application/queue-worker.d.ts +2 -0
- package/dist/application/queue-worker.js +75 -0
- package/dist/application/queue-worker.js.map +1 -0
- package/dist/application/queue-worker.types.d.ts +15 -0
- package/dist/application/queue-worker.types.js +2 -0
- package/dist/application/queue-worker.types.js.map +1 -0
- package/dist/application/queued-task.d.ts +3 -0
- package/dist/application/queued-task.js +56 -0
- package/dist/application/queued-task.js.map +1 -0
- package/dist/application/queued-task.types.d.ts +11 -0
- package/dist/application/queued-task.types.js +2 -0
- package/dist/application/queued-task.types.js.map +1 -0
- package/dist/application/recovery-checksum-capture.d.ts +2 -0
- package/dist/application/recovery-checksum-capture.js +32 -0
- package/dist/application/recovery-checksum-capture.js.map +1 -0
- package/dist/application/recovery-checksum-paths.d.ts +2 -0
- package/dist/application/recovery-checksum-paths.js +11 -0
- package/dist/application/recovery-checksum-paths.js.map +1 -0
- package/dist/application/recovery-checksums.constants.d.ts +5 -0
- package/dist/application/recovery-checksums.constants.js +6 -0
- package/dist/application/recovery-checksums.constants.js.map +1 -0
- package/dist/application/recovery-checksums.d.ts +3 -0
- package/dist/application/recovery-checksums.js +94 -0
- package/dist/application/recovery-checksums.js.map +1 -0
- package/dist/application/recovery-checksums.types.d.ts +17 -0
- package/dist/application/recovery-checksums.types.js +2 -0
- package/dist/application/recovery-checksums.types.js.map +1 -0
- package/dist/application/recovery-inspection.d.ts +2 -0
- package/dist/application/recovery-inspection.js +32 -0
- package/dist/application/recovery-inspection.js.map +1 -0
- package/dist/application/recovery-inspection.types.d.ts +18 -0
- package/dist/application/recovery-inspection.types.js +2 -0
- package/dist/application/recovery-inspection.types.js.map +1 -0
- package/dist/application/recovery-restorability.d.ts +2 -0
- package/dist/application/recovery-restorability.js +137 -0
- package/dist/application/recovery-restorability.js.map +1 -0
- package/dist/application/recovery-restore-snapshot.d.ts +2 -0
- package/dist/application/recovery-restore-snapshot.js +57 -0
- package/dist/application/recovery-restore-snapshot.js.map +1 -0
- package/dist/application/recovery-restore.d.ts +3 -0
- package/dist/application/recovery-restore.js +161 -0
- package/dist/application/recovery-restore.js.map +1 -0
- package/dist/application/recovery-restore.types.d.ts +28 -0
- package/dist/application/recovery-restore.types.js +2 -0
- package/dist/application/recovery-restore.types.js.map +1 -0
- package/dist/application/recovery-retention-policy.d.ts +2 -0
- package/dist/application/recovery-retention-policy.js +21 -0
- package/dist/application/recovery-retention-policy.js.map +1 -0
- package/dist/application/recovery-retention.constants.d.ts +3 -0
- package/dist/application/recovery-retention.constants.js +2 -0
- package/dist/application/recovery-retention.constants.js.map +1 -0
- package/dist/application/recovery-retention.d.ts +4 -0
- package/dist/application/recovery-retention.js +207 -0
- package/dist/application/recovery-retention.js.map +1 -0
- package/dist/application/recovery-retention.types.d.ts +52 -0
- package/dist/application/recovery-retention.types.js +2 -0
- package/dist/application/recovery-retention.types.js.map +1 -0
- package/dist/application/recovery-verification.constants.d.ts +5 -0
- package/dist/application/recovery-verification.constants.js +10 -0
- package/dist/application/recovery-verification.constants.js.map +1 -0
- package/dist/application/recovery-verification.d.ts +3 -0
- package/dist/application/recovery-verification.js +107 -0
- package/dist/application/recovery-verification.js.map +1 -0
- package/dist/application/recovery-verification.types.d.ts +26 -0
- package/dist/application/recovery-verification.types.js +2 -0
- package/dist/application/recovery-verification.types.js.map +1 -0
- package/dist/application/remote-apply.js +30 -6
- package/dist/application/remote-apply.js.map +1 -1
- package/dist/application/remote-backup.js +6 -2
- package/dist/application/remote-backup.js.map +1 -1
- package/dist/application/remote-download.js +38 -6
- package/dist/application/remote-download.js.map +1 -1
- package/dist/application/remote-history.d.ts +6 -0
- package/dist/application/remote-history.js +114 -0
- package/dist/application/remote-history.js.map +1 -0
- package/dist/application/remote-upload.d.ts +2 -0
- package/dist/application/remote-upload.js +17 -0
- package/dist/application/remote-upload.js.map +1 -0
- package/dist/application/remote-validation.js +39 -28
- package/dist/application/remote-validation.js.map +1 -1
- package/dist/application/remote-workspace.constants.d.ts +3 -0
- package/dist/application/remote-workspace.constants.js +2 -0
- package/dist/application/remote-workspace.constants.js.map +1 -0
- package/dist/application/remote-workspace.js +10 -10
- package/dist/application/remote-workspace.js.map +1 -1
- package/dist/application/remote-workspace.types.d.ts +3 -1
- package/dist/application/remote-workspace.types.js.map +1 -1
- package/dist/application/sandbox-activity.d.ts +3 -0
- package/dist/application/sandbox-activity.js +25 -0
- package/dist/application/sandbox-activity.js.map +1 -0
- package/dist/application/sandbox-provision.js +55 -10
- package/dist/application/sandbox-provision.js.map +1 -1
- package/dist/application/sandbox-session.types.d.ts +2 -0
- package/dist/application/sandbox-session.types.js.map +1 -1
- package/dist/application/sandbox.js +33 -10
- package/dist/application/sandbox.js.map +1 -1
- package/dist/application/speculation-host.d.ts +2 -0
- package/dist/application/speculation-host.js +30 -0
- package/dist/application/speculation-host.js.map +1 -0
- package/dist/application/speculation.constants.d.ts +4 -0
- package/dist/application/speculation.constants.js +2 -0
- package/dist/application/speculation.constants.js.map +1 -0
- package/dist/application/speculation.d.ts +2 -0
- package/dist/application/speculation.js +166 -0
- package/dist/application/speculation.js.map +1 -0
- package/dist/application/speculation.types.d.ts +56 -0
- package/dist/application/speculation.types.js +2 -0
- package/dist/application/speculation.types.js.map +1 -0
- package/dist/application/storage-reservation.d.ts +3 -0
- package/dist/application/storage-reservation.js +10 -0
- package/dist/application/storage-reservation.js.map +1 -0
- package/dist/application/storage-reservation.types.d.ts +4 -0
- package/dist/application/storage-reservation.types.js +2 -0
- package/dist/application/storage-reservation.types.js.map +1 -0
- package/dist/application/task-usage.d.ts +4 -0
- package/dist/application/task-usage.js +41 -0
- package/dist/application/task-usage.js.map +1 -0
- package/dist/application/task-usage.types.d.ts +5 -0
- package/dist/application/task-usage.types.js +2 -0
- package/dist/application/task-usage.types.js.map +1 -0
- package/dist/application/tasks.js +23 -2
- package/dist/application/tasks.js.map +1 -1
- package/dist/application/tasks.types.d.ts +4 -3
- package/dist/application/tasks.types.js.map +1 -1
- package/dist/application/workspace-allocation.d.ts +3 -0
- package/dist/application/workspace-allocation.js +34 -0
- package/dist/application/workspace-allocation.js.map +1 -0
- package/dist/application/workspace.js +2 -2
- package/dist/application/workspace.js.map +1 -1
- package/dist/cli/commands.js +4 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doctor-command.d.ts +3 -0
- package/dist/cli/doctor-command.js +38 -0
- package/dist/cli/doctor-command.js.map +1 -0
- package/dist/cli/main.constants.d.ts +38 -2
- package/dist/cli/main.constants.js +21 -2
- package/dist/cli/main.constants.js.map +1 -1
- package/dist/cli/recovery-command.d.ts +2 -0
- package/dist/cli/recovery-command.js +93 -0
- package/dist/cli/recovery-command.js.map +1 -0
- package/dist/cli/recovery-prune-command.d.ts +2 -0
- package/dist/cli/recovery-prune-command.js +34 -0
- package/dist/cli/recovery-prune-command.js.map +1 -0
- package/dist/cli/recovery-restore-command.d.ts +2 -0
- package/dist/cli/recovery-restore-command.js +34 -0
- package/dist/cli/recovery-restore-command.js.map +1 -0
- package/dist/cli/recovery-verify-command.d.ts +2 -0
- package/dist/cli/recovery-verify-command.js +43 -0
- package/dist/cli/recovery-verify-command.js.map +1 -0
- package/dist/cli/scaffold-files.js +2 -2
- package/dist/cli/scaffold-files.js.map +1 -1
- package/dist/cli/scaffold-validation.js +1 -1
- package/dist/cli/scaffold-validation.js.map +1 -1
- package/dist/cli/scaffold.constants.d.ts +5 -0
- package/dist/cli/scaffold.constants.js +7 -2
- package/dist/cli/scaffold.constants.js.map +1 -1
- package/dist/cli/scaffold.types.d.ts +1 -1
- package/dist/cli/scaffold.types.js.map +1 -1
- package/dist/domain/agent.types.d.ts +2 -0
- package/dist/domain/agent.types.js.map +1 -1
- package/dist/domain/artifact-reference.d.ts +4 -0
- package/dist/domain/artifact-reference.js +90 -0
- package/dist/domain/artifact-reference.js.map +1 -0
- package/dist/domain/artifact.constants.d.ts +2 -0
- package/dist/domain/artifact.constants.js +3 -0
- package/dist/domain/artifact.constants.js.map +1 -0
- package/dist/domain/artifact.d.ts +7 -0
- package/dist/domain/artifact.js +104 -0
- package/dist/domain/artifact.js.map +1 -0
- package/dist/domain/artifact.types.d.ts +44 -0
- package/dist/domain/artifact.types.js +2 -0
- package/dist/domain/artifact.types.js.map +1 -0
- package/dist/domain/egress.constants.d.ts +1 -0
- package/dist/domain/egress.constants.js +7 -0
- package/dist/domain/egress.constants.js.map +1 -0
- package/dist/domain/egress.d.ts +2 -0
- package/dist/domain/egress.js +48 -0
- package/dist/domain/egress.js.map +1 -0
- package/dist/domain/egress.types.d.ts +8 -0
- package/dist/domain/egress.types.js +2 -0
- package/dist/domain/egress.types.js.map +1 -0
- package/dist/domain/ports.d.ts +1 -1
- package/dist/domain/ports.js.map +1 -1
- package/dist/domain/sandbox.types.d.ts +13 -0
- package/dist/domain/sandbox.types.js.map +1 -1
- package/dist/domain/task-queue.constants.d.ts +8 -0
- package/dist/domain/task-queue.constants.js +9 -0
- package/dist/domain/task-queue.constants.js.map +1 -0
- package/dist/domain/task-queue.d.ts +11 -0
- package/dist/domain/task-queue.js +105 -0
- package/dist/domain/task-queue.js.map +1 -0
- package/dist/domain/task-queue.types.d.ts +41 -0
- package/dist/domain/task-queue.types.js +2 -0
- package/dist/domain/task-queue.types.js.map +1 -0
- package/dist/domain/workflow/budget.constants.d.ts +1 -0
- package/dist/domain/workflow/budget.constants.js +7 -0
- package/dist/domain/workflow/budget.constants.js.map +1 -0
- package/dist/domain/workflow/budget.d.ts +9 -0
- package/dist/domain/workflow/budget.js +69 -0
- package/dist/domain/workflow/budget.js.map +1 -0
- package/dist/domain/workflow/budget.types.d.ts +15 -0
- package/dist/domain/workflow/budget.types.js +2 -0
- package/dist/domain/workflow/budget.types.js.map +1 -0
- package/dist/domain/workflow/checkpoint-validation.d.ts +3 -0
- package/dist/domain/workflow/checkpoint-validation.js +81 -0
- package/dist/domain/workflow/checkpoint-validation.js.map +1 -0
- package/dist/domain/workflow/checkpoint-value.d.ts +2 -0
- package/dist/domain/workflow/checkpoint-value.js +49 -0
- package/dist/domain/workflow/checkpoint-value.js.map +1 -0
- package/dist/domain/workflow/checkpoint.d.ts +3 -0
- package/dist/domain/workflow/checkpoint.js +70 -0
- package/dist/domain/workflow/checkpoint.js.map +1 -0
- package/dist/domain/workflow/checkpoint.types.d.ts +40 -0
- package/dist/domain/workflow/checkpoint.types.js +2 -0
- package/dist/domain/workflow/checkpoint.types.js.map +1 -0
- package/dist/domain/workflow/gate-validation.d.ts +4 -0
- package/dist/domain/workflow/gate-validation.js +71 -0
- package/dist/domain/workflow/gate-validation.js.map +1 -0
- package/dist/domain/workflow/gates.constants.d.ts +4 -0
- package/dist/domain/workflow/gates.constants.js +5 -0
- package/dist/domain/workflow/gates.constants.js.map +1 -0
- package/dist/domain/workflow/gates.d.ts +7 -0
- package/dist/domain/workflow/gates.js +85 -0
- package/dist/domain/workflow/gates.js.map +1 -0
- package/dist/domain/workflow/gates.types.d.ts +27 -0
- package/dist/domain/workflow/gates.types.js +2 -0
- package/dist/domain/workflow/gates.types.js.map +1 -0
- package/dist/domain/workflow/task-runner.js +22 -3
- package/dist/domain/workflow/task-runner.js.map +1 -1
- package/dist/domain/workflow/usage-receipt.constants.d.ts +2 -0
- package/dist/domain/workflow/usage-receipt.constants.js +3 -0
- package/dist/domain/workflow/usage-receipt.constants.js.map +1 -0
- package/dist/domain/workflow/usage-receipt.d.ts +2 -0
- package/dist/domain/workflow/usage-receipt.js +18 -0
- package/dist/domain/workflow/usage-receipt.js.map +1 -0
- package/dist/domain/workflow/validation.js +6 -0
- package/dist/domain/workflow/validation.js.map +1 -1
- package/dist/domain/workflow/workflow-scheduler.js +68 -33
- package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
- package/dist/domain/workflow/workflow-state.d.ts +2 -1
- package/dist/domain/workflow/workflow-state.js +107 -3
- package/dist/domain/workflow/workflow-state.js.map +1 -1
- package/dist/domain/workflow.d.ts +2 -0
- package/dist/domain/workflow.js +1 -0
- package/dist/domain/workflow.js.map +1 -1
- package/dist/domain/workflow.types.d.ts +23 -3
- package/dist/domain/workflow.types.js.map +1 -1
- package/dist/index.d.ts +44 -5
- package/dist/index.js +19 -2
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/artifact-store.constants.d.ts +1 -0
- package/dist/infrastructure/artifact-store.constants.js +2 -0
- package/dist/infrastructure/artifact-store.constants.js.map +1 -0
- package/dist/infrastructure/artifact-store.d.ts +3 -0
- package/dist/infrastructure/artifact-store.js +100 -0
- package/dist/infrastructure/artifact-store.js.map +1 -0
- package/dist/infrastructure/artifact-store.types.d.ts +4 -0
- package/dist/infrastructure/artifact-store.types.js +2 -0
- package/dist/infrastructure/artifact-store.types.js.map +1 -0
- package/dist/infrastructure/file-manifest.d.ts +6 -0
- package/dist/infrastructure/file-manifest.js +92 -0
- package/dist/infrastructure/file-manifest.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.constants.d.ts +4 -0
- package/dist/infrastructure/git/lock-inspection.constants.js +5 -0
- package/dist/infrastructure/git/lock-inspection.constants.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.d.ts +3 -0
- package/dist/infrastructure/git/lock-inspection.js +64 -0
- package/dist/infrastructure/git/lock-inspection.js.map +1 -0
- package/dist/infrastructure/git/lock-inspection.types.d.ts +27 -0
- package/dist/infrastructure/git/lock-inspection.types.js +2 -0
- package/dist/infrastructure/git/lock-inspection.types.js.map +1 -0
- package/dist/infrastructure/git/lock.d.ts +1 -0
- package/dist/infrastructure/git/lock.js +70 -29
- package/dist/infrastructure/git/lock.js.map +1 -1
- package/dist/infrastructure/git/process-identity.d.ts +3 -0
- package/dist/infrastructure/git/process-identity.js +73 -0
- package/dist/infrastructure/git/process-identity.js.map +1 -0
- package/dist/infrastructure/git/process-identity.types.d.ts +10 -0
- package/dist/infrastructure/git/process-identity.types.js +2 -0
- package/dist/infrastructure/git/process-identity.types.js.map +1 -0
- package/dist/infrastructure/git/verification-command.d.ts +1 -0
- package/dist/infrastructure/git/verification-command.js +37 -0
- package/dist/infrastructure/git/verification-command.js.map +1 -0
- package/dist/infrastructure/git/workspace-lease.js +1 -0
- package/dist/infrastructure/git/workspace-lease.js.map +1 -1
- package/dist/infrastructure/git/workspace.js +5 -1
- package/dist/infrastructure/git/workspace.js.map +1 -1
- package/dist/infrastructure/git/worktree-inspection.constants.d.ts +5 -0
- package/dist/infrastructure/git/worktree-inspection.constants.js +16 -0
- package/dist/infrastructure/git/worktree-inspection.constants.js.map +1 -0
- package/dist/infrastructure/git/worktree-inspection.d.ts +3 -0
- package/dist/infrastructure/git/worktree-inspection.js +120 -0
- package/dist/infrastructure/git/worktree-inspection.js.map +1 -0
- package/dist/infrastructure/git/worktree-inspection.types.d.ts +19 -0
- package/dist/infrastructure/git/worktree-inspection.types.js +2 -0
- package/dist/infrastructure/git/worktree-inspection.types.js.map +1 -0
- package/dist/infrastructure/inspection-file.constants.d.ts +1 -0
- package/dist/infrastructure/inspection-file.constants.js +5 -0
- package/dist/infrastructure/inspection-file.constants.js.map +1 -0
- package/dist/infrastructure/inspection-file.d.ts +1 -0
- package/dist/infrastructure/inspection-file.js +43 -0
- package/dist/infrastructure/inspection-file.js.map +1 -0
- package/dist/infrastructure/inspection-hash.constants.d.ts +1 -0
- package/dist/infrastructure/inspection-hash.constants.js +2 -0
- package/dist/infrastructure/inspection-hash.constants.js.map +1 -0
- package/dist/infrastructure/inspection-hash.d.ts +2 -0
- package/dist/infrastructure/inspection-hash.js +62 -0
- package/dist/infrastructure/inspection-hash.js.map +1 -0
- package/dist/infrastructure/inspection-hash.types.d.ts +5 -0
- package/dist/infrastructure/inspection-hash.types.js +2 -0
- package/dist/infrastructure/inspection-hash.types.js.map +1 -0
- package/dist/infrastructure/journal-retention.constants.d.ts +4 -0
- package/dist/infrastructure/journal-retention.constants.js +5 -0
- package/dist/infrastructure/journal-retention.constants.js.map +1 -0
- package/dist/infrastructure/journal-retention.d.ts +2 -0
- package/dist/infrastructure/journal-retention.js +51 -0
- package/dist/infrastructure/journal-retention.js.map +1 -0
- package/dist/infrastructure/journal.js +37 -13
- package/dist/infrastructure/journal.js.map +1 -1
- package/dist/infrastructure/opentelemetry.constants.d.ts +10 -0
- package/dist/infrastructure/opentelemetry.constants.js +11 -0
- package/dist/infrastructure/opentelemetry.constants.js.map +1 -0
- package/dist/infrastructure/opentelemetry.d.ts +3 -0
- package/dist/infrastructure/opentelemetry.js +131 -0
- package/dist/infrastructure/opentelemetry.js.map +1 -0
- package/dist/infrastructure/opentelemetry.types.d.ts +21 -0
- package/dist/infrastructure/opentelemetry.types.js +2 -0
- package/dist/infrastructure/opentelemetry.types.js.map +1 -0
- package/dist/infrastructure/resource-activity-inspection.d.ts +2 -0
- package/dist/infrastructure/resource-activity-inspection.js +152 -0
- package/dist/infrastructure/resource-activity-inspection.js.map +1 -0
- package/dist/infrastructure/resource-activity.constants.d.ts +8 -0
- package/dist/infrastructure/resource-activity.constants.js +26 -0
- package/dist/infrastructure/resource-activity.constants.js.map +1 -0
- package/dist/infrastructure/resource-activity.d.ts +2 -0
- package/dist/infrastructure/resource-activity.js +166 -0
- package/dist/infrastructure/resource-activity.js.map +1 -0
- package/dist/infrastructure/resource-activity.types.d.ts +53 -0
- package/dist/infrastructure/resource-activity.types.js +2 -0
- package/dist/infrastructure/resource-activity.types.js.map +1 -0
- package/dist/infrastructure/storage-inventory.constants.d.ts +6 -0
- package/dist/infrastructure/storage-inventory.constants.js +11 -0
- package/dist/infrastructure/storage-inventory.constants.js.map +1 -0
- package/dist/infrastructure/storage-inventory.d.ts +2 -0
- package/dist/infrastructure/storage-inventory.js +123 -0
- package/dist/infrastructure/storage-inventory.js.map +1 -0
- package/dist/infrastructure/storage-inventory.types.d.ts +38 -0
- package/dist/infrastructure/storage-inventory.types.js +2 -0
- package/dist/infrastructure/storage-inventory.types.js.map +1 -0
- package/dist/infrastructure/storage-mutation-lock.constants.d.ts +5 -0
- package/dist/infrastructure/storage-mutation-lock.constants.js +6 -0
- package/dist/infrastructure/storage-mutation-lock.constants.js.map +1 -0
- package/dist/infrastructure/storage-mutation-lock.d.ts +1 -0
- package/dist/infrastructure/storage-mutation-lock.js +21 -0
- package/dist/infrastructure/storage-mutation-lock.js.map +1 -0
- package/dist/infrastructure/storage-reservations.constants.d.ts +4 -0
- package/dist/infrastructure/storage-reservations.constants.js +5 -0
- package/dist/infrastructure/storage-reservations.constants.js.map +1 -0
- package/dist/infrastructure/storage-reservations.d.ts +2 -0
- package/dist/infrastructure/storage-reservations.js +150 -0
- package/dist/infrastructure/storage-reservations.js.map +1 -0
- package/dist/infrastructure/storage-reservations.types.d.ts +21 -0
- package/dist/infrastructure/storage-reservations.types.js +2 -0
- package/dist/infrastructure/storage-reservations.types.js.map +1 -0
- package/dist/infrastructure/task-queue-http.constants.d.ts +2 -0
- package/dist/infrastructure/task-queue-http.constants.js +3 -0
- package/dist/infrastructure/task-queue-http.constants.js.map +1 -0
- package/dist/infrastructure/task-queue-http.d.ts +4 -0
- package/dist/infrastructure/task-queue-http.js +158 -0
- package/dist/infrastructure/task-queue-http.js.map +1 -0
- package/dist/infrastructure/task-queue-http.types.d.ts +16 -0
- package/dist/infrastructure/task-queue-http.types.js +2 -0
- package/dist/infrastructure/task-queue-http.types.js.map +1 -0
- package/dist/infrastructure/task-queue.d.ts +2 -0
- package/dist/infrastructure/task-queue.js +134 -0
- package/dist/infrastructure/task-queue.js.map +1 -0
- package/dist/infrastructure/transfer.js +17 -0
- package/dist/infrastructure/transfer.js.map +1 -1
- package/dist/infrastructure/workflow-checkpoint.constants.d.ts +1 -0
- package/dist/infrastructure/workflow-checkpoint.constants.js +2 -0
- package/dist/infrastructure/workflow-checkpoint.constants.js.map +1 -0
- package/dist/infrastructure/workflow-checkpoint.d.ts +3 -0
- package/dist/infrastructure/workflow-checkpoint.js +77 -0
- package/dist/infrastructure/workflow-checkpoint.js.map +1 -0
- package/dist/infrastructure/workflow-checkpoint.types.d.ts +4 -0
- package/dist/infrastructure/workflow-checkpoint.types.js +2 -0
- package/dist/infrastructure/workflow-checkpoint.types.js.map +1 -0
- package/dist/providers/agents.d.ts +2 -0
- package/dist/providers/agents.js +1 -0
- package/dist/providers/agents.js.map +1 -1
- package/dist/providers/cloud.constants.d.ts +1 -0
- package/dist/providers/cloud.constants.js +1 -0
- package/dist/providers/cloud.constants.js.map +1 -1
- package/dist/providers/container-cache.constants.d.ts +11 -0
- package/dist/providers/container-cache.constants.js +9 -0
- package/dist/providers/container-cache.constants.js.map +1 -0
- package/dist/providers/container-cache.d.ts +4 -0
- package/dist/providers/container-cache.js +48 -0
- package/dist/providers/container-cache.js.map +1 -0
- package/dist/providers/container-cache.types.d.ts +8 -0
- package/dist/providers/container-cache.types.js +2 -0
- package/dist/providers/container-cache.types.js.map +1 -0
- package/dist/providers/container-isolation.d.ts +2 -0
- package/dist/providers/container-isolation.js +29 -0
- package/dist/providers/container-isolation.js.map +1 -0
- package/dist/providers/container-mounts.js +7 -2
- package/dist/providers/container-mounts.js.map +1 -1
- package/dist/providers/container-network.d.ts +2 -0
- package/dist/providers/container-network.js +14 -0
- package/dist/providers/container-network.js.map +1 -0
- package/dist/providers/container-plan.js +6 -2
- package/dist/providers/container-plan.js.map +1 -1
- package/dist/providers/container.constants.d.ts +1 -0
- package/dist/providers/container.constants.js +1 -0
- package/dist/providers/container.constants.js.map +1 -1
- package/dist/providers/container.js +50 -3
- package/dist/providers/container.js.map +1 -1
- package/dist/providers/container.types.d.ts +5 -0
- package/dist/providers/container.types.js.map +1 -1
- package/dist/providers/daytona-command.js +10 -6
- package/dist/providers/daytona-command.js.map +1 -1
- package/dist/providers/daytona-terminal.d.ts +3 -0
- package/dist/providers/daytona-terminal.js +128 -0
- package/dist/providers/daytona-terminal.js.map +1 -0
- package/dist/providers/daytona.js +15 -4
- package/dist/providers/daytona.js.map +1 -1
- package/dist/providers/diagnostic-container.d.ts +4 -0
- package/dist/providers/diagnostic-container.js +15 -0
- package/dist/providers/diagnostic-container.js.map +1 -0
- package/dist/providers/docker.d.ts +2 -0
- package/dist/providers/docker.js.map +1 -1
- package/dist/providers/file-batches.constants.d.ts +10 -0
- package/dist/providers/file-batches.constants.js +57 -0
- package/dist/providers/file-batches.constants.js.map +1 -0
- package/dist/providers/file-batches.d.ts +2 -0
- package/dist/providers/file-batches.js +160 -0
- package/dist/providers/file-batches.js.map +1 -0
- package/dist/providers/file-upload.constants.d.ts +1 -0
- package/dist/providers/file-upload.constants.js +68 -0
- package/dist/providers/file-upload.constants.js.map +1 -0
- package/dist/providers/file-upload.d.ts +2 -0
- package/dist/providers/file-upload.js +146 -0
- package/dist/providers/file-upload.js.map +1 -0
- package/dist/providers/firecracker-command.d.ts +5 -0
- package/dist/providers/firecracker-command.js +114 -0
- package/dist/providers/firecracker-command.js.map +1 -0
- package/dist/providers/firecracker-files.constants.d.ts +1 -0
- package/dist/providers/firecracker-files.constants.js +21 -0
- package/dist/providers/firecracker-files.constants.js.map +1 -0
- package/dist/providers/firecracker-files.d.ts +3 -0
- package/dist/providers/firecracker-files.js +110 -0
- package/dist/providers/firecracker-files.js.map +1 -0
- package/dist/providers/firecracker-machine.d.ts +3 -0
- package/dist/providers/firecracker-machine.js +155 -0
- package/dist/providers/firecracker-machine.js.map +1 -0
- package/dist/providers/firecracker.constants.d.ts +10 -0
- package/dist/providers/firecracker.constants.js +11 -0
- package/dist/providers/firecracker.constants.js.map +1 -0
- package/dist/providers/firecracker.d.ts +4 -0
- package/dist/providers/firecracker.js +103 -0
- package/dist/providers/firecracker.js.map +1 -0
- package/dist/providers/firecracker.types.d.ts +36 -0
- package/dist/providers/firecracker.types.js +2 -0
- package/dist/providers/firecracker.types.js.map +1 -0
- package/dist/providers/local.js +2 -1
- package/dist/providers/local.js.map +1 -1
- package/dist/providers/podman.d.ts +2 -0
- package/dist/providers/podman.js.map +1 -1
- package/dist/providers/terminal-bridge.d.ts +14 -0
- package/dist/providers/terminal-bridge.js +100 -0
- package/dist/providers/terminal-bridge.js.map +1 -0
- package/dist/providers/vercel-directory.d.ts +2 -0
- package/dist/providers/vercel-directory.js +7 -0
- package/dist/providers/vercel-directory.js.map +1 -0
- package/dist/providers/vercel-files.js +3 -2
- package/dist/providers/vercel-files.js.map +1 -1
- package/dist/providers/vercel-network.d.ts +2 -0
- package/dist/providers/vercel-network.js +18 -0
- package/dist/providers/vercel-network.js.map +1 -0
- package/dist/providers/vercel.d.ts +1 -0
- package/dist/providers/vercel.js +8 -2
- package/dist/providers/vercel.js.map +1 -1
- package/dist/providers/vercel.types.d.ts +2 -0
- package/dist/providers/vercel.types.js.map +1 -1
- package/dist/providers/versions.constants.d.ts +1 -0
- package/dist/providers/versions.constants.js +1 -0
- package/dist/providers/versions.constants.js.map +1 -1
- 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,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,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAOnD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,GACT,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,MAAM,UAAU,WAAW,CACzB,KAA8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CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC;AAED,KAAK,UAAU,WAAW,CACxB,IAAY,EACZ,IAAY,EACZ,MAAmB;IAEnB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IACnD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;QAC5D,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC;QACtB,IAAI,KAAK,GAAG,IAAI;YACd,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,uBAAuB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QACxE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { createHash, randomUUID } from \"node:crypto\";\nimport {\n copyFile,\n mkdtemp,\n open,\n readlink,\n rm,\n writeFile,\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,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAGxE,OAAO,EACL,cAAc,EACd,KAAK,EACL,cAAc,GACf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAMjE,MAAM,UAAU,cAAc,CAC5B,OAA2B,EAC3B,MAAc;IAEd,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACxB,OAAO;QACL,UAAU,EAAE,GAAG,CAAC,MAAM,IAAI,KAAK;QAC/B,SAAS,EAAE;YACT,IAAI;YACJ,WAAW;YACX,IAAI;YACJ,IAAI;YACJ,eAAe;YACf,IAAI;YACJ,oBAAoB;YACpB,IAAI;YACJ,2BAA2B;YAC3B,IAAI;YACJ,sBAAsB,GAAG,CAAC,UAAU,EAAE;YACtC,IAAI;YACJ,gCAAgC;YAChC,IAAI;YACJ,kBAAkB;YAClB,IAAI;YACJ,uBAAuB;YACvB,IAAI;YACJ,uBAAuB;YACvB,IAAI;YACJ,GAAG,CAAC,QAAQ;YACZ,IAAI;YACJ,MAAM,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC;YACtB,IAAI;YACJ,GAAG,CAAC,IAAI;YACR,IAAI;YACJ,GAAG,CAAC,IA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C,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,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>;
|