@elie-laloum/outpost 3.0.0 → 4.1.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 +32 -0
- package/README.md +5 -3
- package/SECURITY.md +3 -1
- package/dist/adapters/agents/codex-adapter.js +2 -0
- package/dist/adapters/agents/codex-adapter.js.map +1 -1
- package/dist/adapters/agents/codex-provider.d.ts +2 -0
- package/dist/adapters/agents/codex-provider.js +32 -0
- package/dist/adapters/agents/codex-provider.js.map +1 -0
- package/dist/adapters/agents/codex-request.js +2 -1
- package/dist/adapters/agents/codex-request.js.map +1 -1
- 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 +23 -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 +1 -1
- package/dist/adapters/agents/protocol-fixtures.constants.js +37 -0
- package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -1
- package/dist/adapters/agents/settings.types.d.ts +5 -0
- package/dist/adapters/agents/settings.types.js.map +1 -1
- 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/dispatch-validation.js +2 -0
- package/dist/application/dispatch-validation.js.map +1 -1
- package/dist/application/doctor-agent.constants.d.ts +2 -0
- package/dist/application/doctor-agent.constants.js +2 -0
- package/dist/application/doctor-agent.constants.js.map +1 -1
- package/dist/application/doctor-agent.js +1 -1
- package/dist/application/doctor-agent.js.map +1 -1
- package/dist/application/doctor-protocol.js +2 -1
- package/dist/application/doctor-protocol.js.map +1 -1
- package/dist/application/doctor.constants.js +1 -1
- package/dist/application/doctor.constants.js.map +1 -1
- package/dist/application/doctor.types.d.ts +1 -1
- package/dist/application/doctor.types.js.map +1 -1
- package/dist/application/outpost.types.d.ts +2 -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-inspection.js +5 -0
- package/dist/application/recovery-inspection.js.map +1 -1
- package/dist/application/recovery-inspection.types.d.ts +3 -0
- package/dist/application/recovery-inspection.types.js.map +1 -1
- 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.js +5 -0
- package/dist/application/recovery-retention.js.map +1 -1
- package/dist/application/recovery-verification.d.ts +2 -1
- package/dist/application/recovery-verification.js +1 -1
- package/dist/application/recovery-verification.js.map +1 -1
- package/dist/application/remote-apply.js +6 -0
- package/dist/application/remote-apply.js.map +1 -1
- package/dist/application/remote-download.js +2 -2
- 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 +20 -28
- package/dist/application/remote-validation.js.map +1 -1
- package/dist/application/remote-workspace.js +4 -10
- package/dist/application/remote-workspace.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 +23 -11
- 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 +1 -1
- package/dist/application/task-usage.js.map +1 -1
- package/dist/application/tasks.js +1 -1
- 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 +55 -18
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doctor-command.js +1 -1
- package/dist/cli/doctor-command.js.map +1 -1
- package/dist/cli/init-authentication.constants.d.ts +13 -0
- package/dist/cli/init-authentication.constants.js +10 -0
- package/dist/cli/init-authentication.constants.js.map +1 -0
- package/dist/cli/init-authentication.d.ts +4 -0
- package/dist/cli/init-authentication.js +43 -0
- package/dist/cli/init-authentication.js.map +1 -0
- package/dist/cli/init-command.js +74 -15
- package/dist/cli/init-command.js.map +1 -1
- package/dist/cli/main.constants.d.ts +111 -2
- package/dist/cli/main.constants.js +148 -42
- package/dist/cli/main.constants.js.map +1 -1
- package/dist/cli/recovery-command.js +28 -4
- package/dist/cli/recovery-command.js.map +1 -1
- 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/scaffold-files.js +3 -2
- package/dist/cli/scaffold-files.js.map +1 -1
- package/dist/cli/scaffold-validation.js +20 -1
- package/dist/cli/scaffold-validation.js.map +1 -1
- package/dist/cli/scaffold.constants.js +2 -2
- package/dist/cli/scaffold.constants.js.map +1 -1
- package/dist/cli/scaffold.js +13 -0
- package/dist/cli/scaffold.js.map +1 -1
- package/dist/cli/scaffold.types.d.ts +4 -1
- package/dist/cli/scaffold.types.js.map +1 -1
- package/dist/cli/starters.js +9 -2
- package/dist/cli/starters.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/sandbox.types.d.ts +1 -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.d.ts +2 -2
- package/dist/domain/workflow/budget.js +5 -3
- package/dist/domain/workflow/budget.js.map +1 -1
- 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 +14 -2
- 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 +65 -32
- 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 +91 -16
- package/dist/domain/workflow/workflow-state.js.map +1 -1
- package/dist/domain/workflow.types.d.ts +13 -2
- package/dist/domain/workflow.types.js.map +1 -1
- package/dist/index.d.ts +32 -2
- package/dist/index.js +14 -1
- 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 +1 -1
- package/dist/infrastructure/file-manifest.js +3 -2
- package/dist/infrastructure/file-manifest.js.map +1 -1
- package/dist/infrastructure/git/verification-command.d.ts +1 -1
- package/dist/infrastructure/git/verification-command.js +3 -2
- package/dist/infrastructure/git/verification-command.js.map +1 -1
- package/dist/infrastructure/opentelemetry.js +1 -1
- package/dist/infrastructure/opentelemetry.js.map +1 -1
- 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-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 +5 -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 +3 -1
- package/dist/providers/agents.js +1 -0
- package/dist/providers/agents.js.map +1 -1
- 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 +4 -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 +19 -2
- package/dist/providers/container.js.map +1 -1
- package/dist/providers/container.types.d.ts +3 -0
- package/dist/providers/container.types.js.map +1 -1
- package/dist/providers/daytona-command.constants.d.ts +2 -0
- package/dist/providers/daytona-command.constants.js +13 -0
- package/dist/providers/daytona-command.constants.js.map +1 -0
- package/dist/providers/daytona-command.js +12 -5
- package/dist/providers/daytona-command.js.map +1 -1
- package/dist/providers/daytona-output.d.ts +4 -0
- package/dist/providers/daytona-output.js +37 -0
- package/dist/providers/daytona-output.js.map +1 -0
- package/dist/providers/daytona-terminal.d.ts +3 -0
- package/dist/providers/daytona-terminal.js +130 -0
- package/dist/providers/daytona-terminal.js.map +1 -0
- package/dist/providers/daytona.js +2 -0
- package/dist/providers/daytona.js.map +1 -1
- package/dist/providers/docker.d.ts +1 -0
- package/dist/providers/docker.js.map +1 -1
- package/dist/providers/file-batches.d.ts +1 -1
- package/dist/providers/file-batches.js +9 -0
- package/dist/providers/file-batches.js.map +1 -1
- 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 +1 -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-command.js +2 -2
- package/dist/providers/vercel-command.js.map +1 -1
- 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 +5 -1
- 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 +10 -2
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { artifactDigestPattern } from "../domain/artifact.constants.js";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { link, lstat, mkdir, open, rm } from "node:fs/promises";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { readInspectionFile } from "./inspection-file.js";
|
|
6
|
+
import { artifactMaxBytes } from "./artifact-store.constants.js";
|
|
7
|
+
async function directory(path) {
|
|
8
|
+
const parent = dirname(path);
|
|
9
|
+
if (parent !== path) {
|
|
10
|
+
await directory(parent);
|
|
11
|
+
try {
|
|
12
|
+
await mkdir(path, { mode: 0o700 });
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (!code(error, "EEXIST"))
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (!(await lstat(path)).isDirectory())
|
|
20
|
+
throw new Error("Artifact directory must not contain symlinks");
|
|
21
|
+
}
|
|
22
|
+
function code(error, expected) {
|
|
23
|
+
return (!!error &&
|
|
24
|
+
typeof error === "object" &&
|
|
25
|
+
"code" in error &&
|
|
26
|
+
error.code === expected);
|
|
27
|
+
}
|
|
28
|
+
async function readArtifactFile(path, maxBytes) {
|
|
29
|
+
try {
|
|
30
|
+
return await readInspectionFile(path, maxBytes);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (!(error instanceof Error) ||
|
|
34
|
+
error.message !== "Inspection file changed")
|
|
35
|
+
throw error;
|
|
36
|
+
// Removing the staging hard link can change ctime once after publication.
|
|
37
|
+
return readInspectionFile(path, maxBytes);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export function fileArtifactStore(options) {
|
|
41
|
+
const root = resolve(options.directory), maxBytes = options.maxBytes ?? artifactMaxBytes;
|
|
42
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
|
|
43
|
+
throw new Error("Artifact maxBytes must be a positive safe integer");
|
|
44
|
+
const path = (id) => {
|
|
45
|
+
if (!artifactDigestPattern.test(id))
|
|
46
|
+
throw new Error("Invalid artifact storage ID");
|
|
47
|
+
return join(root, `${id}.blob`);
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
async put(id, input, signal) {
|
|
51
|
+
signal?.throwIfAborted();
|
|
52
|
+
const target = path(id);
|
|
53
|
+
if (input.byteLength > maxBytes)
|
|
54
|
+
throw new Error("Artifact exceeds maxBytes");
|
|
55
|
+
const bytes = Buffer.from(input);
|
|
56
|
+
await directory(root);
|
|
57
|
+
const temporary = join(root, `.${randomUUID()}.tmp`);
|
|
58
|
+
try {
|
|
59
|
+
const file = await open(temporary, "wx", 0o600);
|
|
60
|
+
try {
|
|
61
|
+
await file.writeFile(bytes, signal ? { signal } : {});
|
|
62
|
+
await file.sync();
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
await file.close();
|
|
66
|
+
}
|
|
67
|
+
signal?.throwIfAborted();
|
|
68
|
+
try {
|
|
69
|
+
await link(temporary, target);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (!code(error, "EEXIST"))
|
|
73
|
+
throw error;
|
|
74
|
+
if (!bytes.equals(await readArtifactFile(target, maxBytes)))
|
|
75
|
+
throw new Error("Existing artifact content integrity mismatch");
|
|
76
|
+
}
|
|
77
|
+
if (process.platform !== "win32") {
|
|
78
|
+
const parent = await open(root, "r");
|
|
79
|
+
try {
|
|
80
|
+
await parent.sync();
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
await parent.close();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
await rm(temporary, { force: true });
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
async get(id, signal) {
|
|
92
|
+
signal?.throwIfAborted();
|
|
93
|
+
const target = path(id);
|
|
94
|
+
const bytes = await readArtifactFile(target, maxBytes);
|
|
95
|
+
signal?.throwIfAborted();
|
|
96
|
+
return bytes;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=artifact-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-store.js","sourceRoot":"","sources":["../../src/infrastructure/artifact-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,KAAK,UAAU,SAAS,CAAC,IAAY;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,KAAK,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC;gBAAE,MAAM,KAAK,CAA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CAAC,CAAC;gBACpE,CAAC;gBACD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;oBACjC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;oBACrC,IAAI,CAAC;wBACH,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;oBACtB,CAAC;4BAAS,CAAC;wBACT,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;oBACvB,CAAC;gBACH,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,MAAM,EAAE,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YACvC,CAAC;QACH,CAAC;QACD,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM;YAClB,MAAM,EAAE,cAAc,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;YACxB,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;YACvD,MAAM,EAAE,cAAc,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { artifactDigestPattern } from \"../domain/artifact.constants.ts\";\nimport { randomUUID } from \"node:crypto\";\nimport { link, lstat, mkdir, open, rm } from \"node:fs/promises\";\nimport { dirname, join, resolve } from \"node:path\";\nimport type { ArtifactStore } from \"../domain/artifact.types.ts\";\nimport { readInspectionFile } from \"./inspection-file.ts\";\nimport { artifactMaxBytes } from \"./artifact-store.constants.ts\";\nimport type { FileArtifactStoreOptions } from \"./artifact-store.types.ts\";\n\nasync function directory(path: string): Promise<void> {\n const parent = dirname(path);\n if (parent !== path) {\n await directory(parent);\n try {\n await mkdir(path, { mode: 0o700 });\n } catch (error) {\n if (!code(error, \"EEXIST\")) throw error;\n }\n }\n if (!(await lstat(path)).isDirectory())\n throw new Error(\"Artifact directory must not contain symlinks\");\n}\n\nfunction code(error: unknown, expected: string): boolean {\n return (\n !!error &&\n typeof error === \"object\" &&\n \"code\" in error &&\n error.code === expected\n );\n}\n\nasync function readArtifactFile(\n path: string,\n maxBytes: number,\n): Promise<Buffer> {\n try {\n return await readInspectionFile(path, maxBytes);\n } catch (error) {\n if (\n !(error instanceof Error) ||\n error.message !== \"Inspection file changed\"\n )\n throw error;\n // Removing the staging hard link can change ctime once after publication.\n return readInspectionFile(path, maxBytes);\n }\n}\n\nexport function fileArtifactStore(\n options: FileArtifactStoreOptions,\n): ArtifactStore {\n const root = resolve(options.directory),\n maxBytes = options.maxBytes ?? artifactMaxBytes;\n if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)\n throw new Error(\"Artifact maxBytes must be a positive safe integer\");\n const path = (id: string) => {\n if (!artifactDigestPattern.test(id))\n throw new Error(\"Invalid artifact storage ID\");\n return join(root, `${id}.blob`);\n };\n return {\n async put(id, input, signal) {\n signal?.throwIfAborted();\n const target = path(id);\n if (input.byteLength > maxBytes)\n throw new Error(\"Artifact exceeds maxBytes\");\n const bytes = Buffer.from(input);\n await directory(root);\n const temporary = join(root, `.${randomUUID()}.tmp`);\n try {\n const file = await open(temporary, \"wx\", 0o600);\n try {\n await file.writeFile(bytes, signal ? { signal } : {});\n await file.sync();\n } finally {\n await file.close();\n }\n signal?.throwIfAborted();\n try {\n await link(temporary, target);\n } catch (error) {\n if (!code(error, \"EEXIST\")) throw error;\n if (!bytes.equals(await readArtifactFile(target, maxBytes)))\n throw new Error(\"Existing artifact content integrity mismatch\");\n }\n if (process.platform !== \"win32\") {\n const parent = await open(root, \"r\");\n try {\n await parent.sync();\n } finally {\n await parent.close();\n }\n }\n } finally {\n await rm(temporary, { force: true });\n }\n },\n async get(id, signal) {\n signal?.throwIfAborted();\n const target = path(id);\n const bytes = await readArtifactFile(target, maxBytes);\n signal?.throwIfAborted();\n return bytes;\n },\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-store.types.js","sourceRoot":"","sources":["../../src/infrastructure/artifact-store.types.ts"],"names":[],"mappings":"","sourcesContent":["export interface FileArtifactStoreOptions {\n readonly directory: string;\n readonly maxBytes?: number;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FileManifestEntry } from "../domain/sandbox.types.ts";
|
|
2
|
-
export declare function fileManifest(root: string, path: string): Promise<FileManifestEntry>;
|
|
2
|
+
export declare function fileManifest(root: string, path: string, signal?: AbortSignal): Promise<FileManifestEntry>;
|
|
3
3
|
export declare function sameFile(left: FileManifestEntry, right: FileManifestEntry): boolean;
|
|
4
4
|
export declare function sameLocalFile(remote: FileManifestEntry, local: FileManifestEntry): boolean;
|
|
5
5
|
export declare function validateFilePaths(paths: readonly string[]): void;
|
|
@@ -3,7 +3,8 @@ import { createReadStream } from "node:fs";
|
|
|
3
3
|
import { lstat, readlink } from "node:fs/promises";
|
|
4
4
|
import { OutpostError } from "../domain/errors.js";
|
|
5
5
|
import { safeDestination } from "./files.js";
|
|
6
|
-
export async function fileManifest(root, path) {
|
|
6
|
+
export async function fileManifest(root, path, signal) {
|
|
7
|
+
signal?.throwIfAborted();
|
|
7
8
|
const target = await safeDestination(root, path);
|
|
8
9
|
const info = await lstat(target);
|
|
9
10
|
if (!info.isFile() && !info.isSymbolicLink())
|
|
@@ -18,7 +19,7 @@ export async function fileManifest(root, path) {
|
|
|
18
19
|
hash.update(value);
|
|
19
20
|
}
|
|
20
21
|
else {
|
|
21
|
-
for await (const chunk of createReadStream(target))
|
|
22
|
+
for await (const chunk of createReadStream(target, { signal }))
|
|
22
23
|
hash.update(chunk);
|
|
23
24
|
}
|
|
24
25
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-manifest.js","sourceRoot":"","sources":["../../src/infrastructure/file-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM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,IAAI,KAAK,QAAQ;YAC9B,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;YAC7B,KAAK,CAAC,IAAI,GAAG,CAAC;YACd,KAAK,CAAC,IAAI,GAAG,KAAK;YAClB,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;YAClB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;YAC9B,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;YACjC,KAAK,CAAC,IAAI,GAAG,CAAC;YACd,CAAC,CAAC,QAAQ,IAAI,KAAK,CAAC;YACpB,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ;YAChC,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YAEpC,MAAM,IAAI,YAAY,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC;QACpE,OAAO;YACL,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { createReadStream } from \"node:fs\";\nimport { lstat, readlink } from \"node:fs/promises\";\nimport { OutpostError } from \"../domain/errors.ts\";\nimport type { FileManifestEntry } from \"../domain/sandbox.types.ts\";\nimport { safeDestination } from \"./files.ts\";\n\nexport async function fileManifest(\n root: string,\n path: string,\n signal?: AbortSignal,\n): Promise<FileManifestEntry> {\n signal?.throwIfAborted();\n const target = await safeDestination(root, path);\n const info = await lstat(target);\n if (!info.isFile() && !info.isSymbolicLink())\n throw new OutpostError(\"provider\", \"Unsupported manifest file type\", {\n path,\n });\n const hash = createHash(\"sha256\");\n let size = info.size;\n if (info.isSymbolicLink()) {\n const value = Buffer.from(await readlink(target));\n size = value.length;\n hash.update(value);\n } else {\n for await (const chunk of createReadStream(target, { signal }))\n hash.update(chunk);\n }\n return {\n path,\n kind: info.isSymbolicLink() ? \"link\" : \"file\",\n mode: info.mode & 0o777,\n size,\n sha256: hash.digest(\"hex\"),\n };\n}\n\nexport function sameFile(\n left: FileManifestEntry,\n right: FileManifestEntry,\n): boolean {\n return (\n left.path === right.path &&\n left.kind === right.kind &&\n left.mode === right.mode &&\n left.size === right.size &&\n left.sha256 === right.sha256\n );\n}\n\nexport function sameLocalFile(\n remote: FileManifestEntry,\n local: FileManifestEntry,\n): boolean {\n if (process.platform !== \"win32\") return sameFile(remote, local);\n return sameFile(\n { ...remote, mode: remote.mode & 0o200 },\n { ...local, mode: local.mode & 0o200 },\n );\n}\n\nexport function validateFilePaths(paths: readonly string[]): void {\n if (\n new Set(paths).size !== paths.length ||\n paths.some(\n (path) =>\n !path ||\n path.includes(\"\\\\\") ||\n path.includes(\"\\0\") ||\n path\n .split(\"/\")\n .some(\n (part) =>\n !part ||\n part === \".\" ||\n part === \"..\" ||\n part.toLowerCase() === \".git\",\n ),\n )\n )\n throw new OutpostError(\"provider\", \"Unsafe or duplicate manifest path\");\n}\n\nexport function parseManifest(\n value: unknown,\n paths: readonly string[],\n): FileManifestEntry[] {\n validateFilePaths(paths);\n if (!Array.isArray(value) || value.length !== paths.length)\n throw new OutpostError(\"provider\", \"Invalid file manifest\");\n return value.map((entry: unknown, index) => {\n if (\n !entry ||\n typeof entry !== \"object\" ||\n !(\"path\" in entry) ||\n typeof entry.path !== \"string\" ||\n entry.path !== paths[index] ||\n !(\"kind\" in entry) ||\n (entry.kind !== \"file\" && entry.kind !== \"link\") ||\n !(\"mode\" in entry) ||\n typeof entry.mode !== \"number\" ||\n !Number.isInteger(entry.mode) ||\n entry.mode < 0 ||\n entry.mode > 0o777 ||\n !(\"size\" in entry) ||\n typeof entry.size !== \"number\" ||\n !Number.isSafeInteger(entry.size) ||\n entry.size < 0 ||\n !(\"sha256\" in entry) ||\n typeof entry.sha256 !== \"string\" ||\n !/^[a-f0-9]{64}$/.test(entry.sha256)\n )\n throw new OutpostError(\"provider\", \"Invalid file manifest entry\");\n return {\n path: entry.path,\n kind: entry.kind,\n mode: entry.mode,\n size: entry.size,\n sha256: entry.sha256,\n };\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function verificationGit(directory: string, args: readonly string[]): Promise<string>;
|
|
1
|
+
export declare function verificationGit(directory: string, args: readonly string[], deadlineMs?: number, signal?: AbortSignal): Promise<string>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { promisify } from "node:util";
|
|
3
3
|
import { gitDefaults } from "./git.constants.js";
|
|
4
|
-
export async function verificationGit(directory, args) {
|
|
4
|
+
export async function verificationGit(directory, args, deadlineMs = gitDefaults.deadlineMs, signal) {
|
|
5
5
|
const environment = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.toUpperCase().startsWith("GIT_")));
|
|
6
6
|
const result = await promisify(execFile)("git", [
|
|
7
7
|
"-c",
|
|
@@ -26,7 +26,8 @@ export async function verificationGit(directory, args) {
|
|
|
26
26
|
GIT_OPTIONAL_LOCKS: "0",
|
|
27
27
|
LC_ALL: "C",
|
|
28
28
|
},
|
|
29
|
-
timeout:
|
|
29
|
+
timeout: deadlineMs,
|
|
30
|
+
...(signal ? { signal } : {}),
|
|
30
31
|
maxBuffer: gitDefaults.retainBytes,
|
|
31
32
|
encoding: "utf8",
|
|
32
33
|
windowsHide: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verification-command.js","sourceRoot":"","sources":["../../../src/infrastructure/git/verification-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,SAAiB,EACjB,IAAuB;
|
|
1
|
+
{"version":3,"file":"verification-command.js","sourceRoot":"","sources":["../../../src/infrastructure/git/verification-command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,SAAiB,EACjB,IAAuB,EACvB,aAAqB,WAAW,CAAC,UAAU,EAC3C,MAAoB;IAEpB,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CACpC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,CAChC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CACjD,CACF,CAAC;IACF,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,CACtC,KAAK,EACL;QACE,IAAI;QACJ,kBAAkB,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,EAAE;QACtE,IAAI;QACJ,sBAAsB;QACtB,IAAI;QACJ,wBAAwB;QACxB,IAAI;QACJ,WAAW;QACX,GAAG,IAAI;KACR,EACD;QACE,GAAG,EAAE,SAAS;QACd,GAAG,EAAE;YACH,GAAG,WAAW;YACd,mBAAmB,EAAE,GAAG;YACxB,iBAAiB,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW;YACrE,iBAAiB,EAAE,GAAG;YACtB,iBAAiB,EAAE,GAAG;YACtB,kBAAkB,EAAE,MAAM;YAC1B,mBAAmB,EAAE,GAAG;YACxB,kBAAkB,EAAE,GAAG;YACvB,MAAM,EAAE,GAAG;SACZ;QACD,OAAO,EAAE,UAAU;QACnB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC7B,SAAS,EAAE,WAAW,CAAC,WAAW;QAClC,QAAQ,EAAE,MAAM;QAChB,WAAW,EAAE,IAAI;KAClB,CACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC","sourcesContent":["import { execFile } from \"node:child_process\";\nimport { promisify } from \"node:util\";\nimport { gitDefaults } from \"./git.constants.ts\";\n\nexport async function verificationGit(\n directory: string,\n args: readonly string[],\n deadlineMs: number = gitDefaults.deadlineMs,\n signal?: AbortSignal,\n): Promise<string> {\n const environment = Object.fromEntries(\n Object.entries(process.env).filter(\n ([key]) => !key.toUpperCase().startsWith(\"GIT_\"),\n ),\n );\n const result = await promisify(execFile)(\n \"git\",\n [\n \"-c\",\n `core.hooksPath=${process.platform === \"win32\" ? \"NUL\" : \"/dev/null\"}`,\n \"-c\",\n \"core.fsmonitor=false\",\n \"-c\",\n \"maintenance.auto=false\",\n \"-c\",\n \"gc.auto=0\",\n ...args,\n ],\n {\n cwd: directory,\n env: {\n ...environment,\n GIT_CONFIG_NOSYSTEM: \"1\",\n GIT_CONFIG_GLOBAL: process.platform === \"win32\" ? \"NUL\" : \"/dev/null\",\n GIT_ATTR_NOSYSTEM: \"1\",\n GIT_NO_LAZY_FETCH: \"1\",\n GIT_ALLOW_PROTOCOL: \"file\",\n GIT_TERMINAL_PROMPT: \"0\",\n GIT_OPTIONAL_LOCKS: \"0\",\n LC_ALL: \"C\",\n },\n timeout: deadlineMs,\n ...(signal ? { signal } : {}),\n maxBuffer: gitDefaults.retainBytes,\n encoding: \"utf8\",\n windowsHide: true,\n },\n );\n return result.stdout;\n}\n"]}
|
|
@@ -44,7 +44,7 @@ export function openTelemetry(options) {
|
|
|
44
44
|
return;
|
|
45
45
|
const attributes = { "outpost.status": status };
|
|
46
46
|
safe(() => operation.span?.setAttributes(attributes));
|
|
47
|
-
if (status !== "skipped")
|
|
47
|
+
if (status !== "skipped" && status !== "paused")
|
|
48
48
|
safe(() => operation.span?.setStatus({
|
|
49
49
|
code: status === "done" ? SpanStatusCode.OK : SpanStatusCode.ERROR,
|
|
50
50
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opentelemetry.js","sourceRoot":"","sources":["../../src/infrastructure/opentelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAa9D,MAAM,UAAU,aAAa,CAC3B,OAA6B;IAE7B,SAAS,IAAI,CAAI,MAAe;QAC9B,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC;gBACH,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACZ,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GAAG;QACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CACnB,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CACtD;QACD,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACpE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC1E,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CA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C,GAAG,CACjB,KAAK,CAAC,GAAG,EACT,KAAK,CAAC,cAAc,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CACtD,CAAC;gBACF,OAAO;YACT,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC1C,MAAM,CACJ,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EACjC,KAAK,CAAC,MAAM,EACZ,EAAE,EACF,SAAS,CAAC,OAAO,CAClB,CAAC;gBACF,MAAM,CACJ,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAC9B,KAAK,CAAC,MAAM,EACZ,EAAE,EACF,SAAS,CAAC,IAAI,CACf,CAAC;gBACF,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACrC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QACD,KAAK;YACH,IAAI,MAAM;gBAAE,OAAO;YACnB,MAAM,GAAG,IAAI,CAAC;YACd,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,MAAM,EAAE;gBACzC,QAAQ,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YAC/C,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { context, trace, SpanStatusCode } from \"@opentelemetry/api\";\nimport type { Context, Histogram } from \"@opentelemetry/api\";\nimport type { WorkflowEvent } from \"../domain/workflow.types.ts\";\nimport { usageDimensions } from \"../domain/workflow/budget.constants.ts\";\nimport { telemetryNames } from \"./opentelemetry.constants.ts\";\nimport type {\n OpenTelemetryObserver,\n OpenTelemetryOptions,\n TelemetryExecution,\n TelemetryOperation,\n} from \"./opentelemetry.types.ts\";\n\nexport type {\n OpenTelemetryObserver,\n OpenTelemetryOptions,\n} from \"./opentelemetry.types.ts\";\n\nexport function openTelemetry(\n options: OpenTelemetryOptions,\n): OpenTelemetryObserver {\n function safe<T>(action: () => T): T | undefined {\n try {\n return action();\n } catch (error) {\n try {\n options.onError?.(error);\n } catch {}\n }\n }\n const counters = {\n workflows: safe(() =>\n options.meter.createCounter(telemetryNames.workflows),\n ),\n tasks: safe(() => options.meter.createCounter(telemetryNames.tasks)),\n attempts: safe(() => options.meter.createCounter(telemetryNames.attempts)),\n retries: safe(() => options.meter.createCounter(telemetryNames.retries)),\n usage: safe(() =>\n options.meter.createCounter(telemetryNames.usage, { unit: \"{token}\" }),\n ),\n };\n const durations = {\n workflow: safe(() =>\n options.meter.createHistogram(telemetryNames.workflowDuration, {\n unit: \"s\",\n }),\n ),\n task: safe(() =>\n options.meter.createHistogram(telemetryNames.taskDuration, { unit: \"s\" }),\n ),\n attempt: safe(() =>\n options.meter.createHistogram(telemetryNames.attemptDuration, {\n unit: \"s\",\n }),\n ),\n };\n const executions = new Map<string, TelemetryExecution>();\n let closed = false;\n function start(\n name: string,\n parent: Context,\n at: number,\n ): TelemetryOperation {\n const span = safe(() =>\n options.tracer.startSpan(name, { startTime: at }, parent),\n );\n return {\n span,\n context: span ? trace.setSpan(parent, span) : parent,\n started: at,\n };\n }\n function finish(\n operation: TelemetryOperation | undefined,\n status: string,\n at: number,\n duration: Histogram | undefined,\n ): void {\n if (!operation) return;\n const attributes = { \"outpost.status\": status };\n safe(() => operation.span?.setAttributes(attributes));\n if (status !== \"skipped\")\n safe(() =>\n operation.span?.setStatus({\n code: status === \"done\" ? SpanStatusCode.OK : SpanStatusCode.ERROR,\n }),\n );\n safe(() => operation.span?.end(at));\n safe(() =>\n duration?.record(Math.max(0, at - operation.started) / 1000, attributes),\n );\n }\n function complete(\n execution: TelemetryExecution,\n status: string,\n at: number,\n ): void {\n for (const attempt of execution.attempts.values())\n finish(attempt, status, at, durations.attempt);\n for (const task of execution.tasks.values())\n finish(task, status, at, durations.task);\n finish(execution.workflow, status, at, durations.workflow);\n safe(() => counters.workflows?.add(1, { \"outpost.status\": status }));\n }\n return {\n observe(event: WorkflowEvent) {\n if (closed) return;\n const at = Date.parse(event.timestamp);\n if (!Number.isFinite(at)) return;\n if (event.type === \"start\") {\n if (executions.has(event.executionId)) return;\n executions.set(event.executionId, {\n workflow: start(\"outpost.workflow\", context.active(), at),\n tasks: new Map(),\n attempts: new Map(),\n });\n return;\n }\n const execution = executions.get(event.executionId);\n if (!execution) return;\n if (event.type === \"finish\") {\n executions.delete(event.executionId);\n complete(execution, event.status ?? \"done\", at);\n return;\n }\n if (event.type === \"usage\") {\n for (const dimension of usageDimensions) {\n const value = event.usage?.[dimension];\n if (value !== undefined && Number.isFinite(value) && value > 0)\n safe(() =>\n counters.usage?.add(value, { \"outpost.token.type\": dimension }),\n );\n }\n return;\n }\n if (event.key === undefined) return;\n if (event.type === \"attempt\") {\n execution.attempts.set(\n event.key,\n start(\n \"outpost.task.attempt\",\n execution.tasks.get(event.key)?.context ??\n execution.workflow.context,\n at,\n ),\n );\n safe(() => counters.attempts?.add(1));\n return;\n }\n if (event.type === \"retry\") {\n finish(\n execution.attempts.get(event.key),\n \"failed\",\n at,\n durations.attempt,\n );\n execution.attempts.delete(event.key);\n safe(() => counters.retries?.add(1));\n return;\n }\n if (event.type === \"task\" && event.status === \"active\") {\n execution.tasks.set(\n event.key,\n start(\"outpost.task\", execution.workflow.context, at),\n );\n return;\n }\n if (event.type === \"task\" && event.status) {\n finish(\n execution.attempts.get(event.key),\n event.status,\n at,\n durations.attempt,\n );\n finish(\n execution.tasks.get(event.key),\n event.status,\n at,\n durations.task,\n );\n execution.attempts.delete(event.key);\n execution.tasks.delete(event.key);\n safe(() => counters.tasks?.add(1, { \"outpost.status\": event.status }));\n }\n },\n close() {\n if (closed) return;\n closed = true;\n for (const execution of executions.values())\n complete(execution, \"cancelled\", Date.now());\n executions.clear();\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"opentelemetry.js","sourceRoot":"","sources":["../../src/infrastructure/opentelemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpE,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAa9D,MAAM,UAAU,aAAa,CAC3B,OAA6B;IAE7B,SAAS,IAAI,CAAI,MAAe;QAC9B,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC;gBACH,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;YAC3B,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACZ,CAAC;IACH,CAAC;IACD,MAAM,QAAQ,GAAG;QACf,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,CACnB,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,SAAS,CAAC,CACtD;QACD,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QACpE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC1E,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACxE,KAA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AG,EACT,KAAK,CAAC,cAAc,EAAE,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CACtD,CAAC;gBACF,OAAO;YACT,CAAC;YACD,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;gBAC1C,MAAM,CACJ,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EACjC,KAAK,CAAC,MAAM,EACZ,EAAE,EACF,SAAS,CAAC,OAAO,CAClB,CAAC;gBACF,MAAM,CACJ,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAC9B,KAAK,CAAC,MAAM,EACZ,EAAE,EACF,SAAS,CAAC,IAAI,CACf,CAAC;gBACF,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACrC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,gBAAgB,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QACD,KAAK;YACH,IAAI,MAAM;gBAAE,OAAO;YACnB,MAAM,GAAG,IAAI,CAAC;YACd,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,MAAM,EAAE;gBACzC,QAAQ,CAAC,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YAC/C,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { context, trace, SpanStatusCode } from \"@opentelemetry/api\";\nimport type { Context, Histogram } from \"@opentelemetry/api\";\nimport type { WorkflowEvent } from \"../domain/workflow.types.ts\";\nimport { usageDimensions } from \"../domain/workflow/budget.constants.ts\";\nimport { telemetryNames } from \"./opentelemetry.constants.ts\";\nimport type {\n OpenTelemetryObserver,\n OpenTelemetryOptions,\n TelemetryExecution,\n TelemetryOperation,\n} from \"./opentelemetry.types.ts\";\n\nexport type {\n OpenTelemetryObserver,\n OpenTelemetryOptions,\n} from \"./opentelemetry.types.ts\";\n\nexport function openTelemetry(\n options: OpenTelemetryOptions,\n): OpenTelemetryObserver {\n function safe<T>(action: () => T): T | undefined {\n try {\n return action();\n } catch (error) {\n try {\n options.onError?.(error);\n } catch {}\n }\n }\n const counters = {\n workflows: safe(() =>\n options.meter.createCounter(telemetryNames.workflows),\n ),\n tasks: safe(() => options.meter.createCounter(telemetryNames.tasks)),\n attempts: safe(() => options.meter.createCounter(telemetryNames.attempts)),\n retries: safe(() => options.meter.createCounter(telemetryNames.retries)),\n usage: safe(() =>\n options.meter.createCounter(telemetryNames.usage, { unit: \"{token}\" }),\n ),\n };\n const durations = {\n workflow: safe(() =>\n options.meter.createHistogram(telemetryNames.workflowDuration, {\n unit: \"s\",\n }),\n ),\n task: safe(() =>\n options.meter.createHistogram(telemetryNames.taskDuration, { unit: \"s\" }),\n ),\n attempt: safe(() =>\n options.meter.createHistogram(telemetryNames.attemptDuration, {\n unit: \"s\",\n }),\n ),\n };\n const executions = new Map<string, TelemetryExecution>();\n let closed = false;\n function start(\n name: string,\n parent: Context,\n at: number,\n ): TelemetryOperation {\n const span = safe(() =>\n options.tracer.startSpan(name, { startTime: at }, parent),\n );\n return {\n span,\n context: span ? trace.setSpan(parent, span) : parent,\n started: at,\n };\n }\n function finish(\n operation: TelemetryOperation | undefined,\n status: string,\n at: number,\n duration: Histogram | undefined,\n ): void {\n if (!operation) return;\n const attributes = { \"outpost.status\": status };\n safe(() => operation.span?.setAttributes(attributes));\n if (status !== \"skipped\" && status !== \"paused\")\n safe(() =>\n operation.span?.setStatus({\n code: status === \"done\" ? SpanStatusCode.OK : SpanStatusCode.ERROR,\n }),\n );\n safe(() => operation.span?.end(at));\n safe(() =>\n duration?.record(Math.max(0, at - operation.started) / 1000, attributes),\n );\n }\n function complete(\n execution: TelemetryExecution,\n status: string,\n at: number,\n ): void {\n for (const attempt of execution.attempts.values())\n finish(attempt, status, at, durations.attempt);\n for (const task of execution.tasks.values())\n finish(task, status, at, durations.task);\n finish(execution.workflow, status, at, durations.workflow);\n safe(() => counters.workflows?.add(1, { \"outpost.status\": status }));\n }\n return {\n observe(event: WorkflowEvent) {\n if (closed) return;\n const at = Date.parse(event.timestamp);\n if (!Number.isFinite(at)) return;\n if (event.type === \"start\") {\n if (executions.has(event.executionId)) return;\n executions.set(event.executionId, {\n workflow: start(\"outpost.workflow\", context.active(), at),\n tasks: new Map(),\n attempts: new Map(),\n });\n return;\n }\n const execution = executions.get(event.executionId);\n if (!execution) return;\n if (event.type === \"finish\") {\n executions.delete(event.executionId);\n complete(execution, event.status ?? \"done\", at);\n return;\n }\n if (event.type === \"usage\") {\n for (const dimension of usageDimensions) {\n const value = event.usage?.[dimension];\n if (value !== undefined && Number.isFinite(value) && value > 0)\n safe(() =>\n counters.usage?.add(value, { \"outpost.token.type\": dimension }),\n );\n }\n return;\n }\n if (event.key === undefined) return;\n if (event.type === \"attempt\") {\n execution.attempts.set(\n event.key,\n start(\n \"outpost.task.attempt\",\n execution.tasks.get(event.key)?.context ??\n execution.workflow.context,\n at,\n ),\n );\n safe(() => counters.attempts?.add(1));\n return;\n }\n if (event.type === \"retry\") {\n finish(\n execution.attempts.get(event.key),\n \"failed\",\n at,\n durations.attempt,\n );\n execution.attempts.delete(event.key);\n safe(() => counters.retries?.add(1));\n return;\n }\n if (event.type === \"task\" && event.status === \"active\") {\n execution.tasks.set(\n event.key,\n start(\"outpost.task\", execution.workflow.context, at),\n );\n return;\n }\n if (event.type === \"task\" && event.status) {\n finish(\n execution.attempts.get(event.key),\n event.status,\n at,\n durations.attempt,\n );\n finish(\n execution.tasks.get(event.key),\n event.status,\n at,\n durations.task,\n );\n execution.attempts.delete(event.key);\n execution.tasks.delete(event.key);\n safe(() => counters.tasks?.add(1, { \"outpost.status\": event.status }));\n }\n },\n close() {\n if (closed) return;\n closed = true;\n for (const execution of executions.values())\n complete(execution, \"cancelled\", Date.now());\n executions.clear();\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { lstat, opendir, realpath } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { invariant, positive } from "../domain/errors.js";
|
|
4
|
+
import { observeOwnership } from "./git/process-identity.js";
|
|
5
|
+
import { readInspectionFile } from "./inspection-file.js";
|
|
6
|
+
import { resourceActivityDefaults as defaults, resourceOperationKinds, resourcePhases, } from "./resource-activity.constants.js";
|
|
7
|
+
function object(value) {
|
|
8
|
+
invariant(!!value && typeof value === "object" && !Array.isArray(value), "Invalid activity object");
|
|
9
|
+
}
|
|
10
|
+
function text(value) {
|
|
11
|
+
invariant(typeof value === "string" &&
|
|
12
|
+
value.length > 0 &&
|
|
13
|
+
value.length <= defaults.maxText, "Invalid activity text");
|
|
14
|
+
}
|
|
15
|
+
function date(value) {
|
|
16
|
+
text(value);
|
|
17
|
+
invariant(Number.isFinite(Date.parse(value)), "Invalid activity time");
|
|
18
|
+
}
|
|
19
|
+
function operation(value) {
|
|
20
|
+
object(value);
|
|
21
|
+
invariant(typeof value.count === "number" &&
|
|
22
|
+
Number.isSafeInteger(value.count) &&
|
|
23
|
+
value.count > 0, "Invalid activity count");
|
|
24
|
+
date(value.startedAt);
|
|
25
|
+
const kind = resourceOperationKinds.find((kind) => kind === value.kind);
|
|
26
|
+
invariant(kind, "Invalid activity operation");
|
|
27
|
+
return { count: value.count, startedAt: value.startedAt, kind };
|
|
28
|
+
}
|
|
29
|
+
function result(value) {
|
|
30
|
+
const base = operation(value);
|
|
31
|
+
object(value);
|
|
32
|
+
text(value.id);
|
|
33
|
+
date(value.finishedAt);
|
|
34
|
+
invariant(value.outcome === "completed" || value.outcome === "failed", "Invalid activity outcome");
|
|
35
|
+
return {
|
|
36
|
+
...base,
|
|
37
|
+
id: value.id,
|
|
38
|
+
finishedAt: value.finishedAt,
|
|
39
|
+
outcome: value.outcome,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function identity(value) {
|
|
43
|
+
if (value === undefined)
|
|
44
|
+
return undefined;
|
|
45
|
+
object(value);
|
|
46
|
+
text(value.host);
|
|
47
|
+
text(value.boot);
|
|
48
|
+
text(value.namespace);
|
|
49
|
+
text(value.started);
|
|
50
|
+
return {
|
|
51
|
+
host: value.host,
|
|
52
|
+
boot: value.boot,
|
|
53
|
+
namespace: value.namespace,
|
|
54
|
+
started: value.started,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function record(value) {
|
|
58
|
+
object(value);
|
|
59
|
+
invariant(value.version === 1, "Unknown activity version");
|
|
60
|
+
text(value.id);
|
|
61
|
+
text(value.provider);
|
|
62
|
+
text(value.workspace);
|
|
63
|
+
date(value.createdAt);
|
|
64
|
+
date(value.updatedAt);
|
|
65
|
+
invariant(typeof value.pid === "number" &&
|
|
66
|
+
Number.isSafeInteger(value.pid) &&
|
|
67
|
+
value.pid > 0 &&
|
|
68
|
+
value.pid <= 2_147_483_647, "Invalid activity owner");
|
|
69
|
+
invariant(value.placement === "host" ||
|
|
70
|
+
value.placement === "mounted" ||
|
|
71
|
+
value.placement === "remote", "Invalid activity placement");
|
|
72
|
+
const phase = resourcePhases.find((phase) => phase === value.phase);
|
|
73
|
+
invariant(phase, "Invalid activity phase");
|
|
74
|
+
invariant(Array.isArray(value.operations) &&
|
|
75
|
+
value.operations.length <= resourceOperationKinds.length, "Invalid activity operations");
|
|
76
|
+
const owner = identity(value.identity);
|
|
77
|
+
return {
|
|
78
|
+
version: 1,
|
|
79
|
+
id: value.id,
|
|
80
|
+
pid: value.pid,
|
|
81
|
+
...(owner ? { identity: owner } : {}),
|
|
82
|
+
provider: value.provider,
|
|
83
|
+
placement: value.placement,
|
|
84
|
+
workspace: value.workspace,
|
|
85
|
+
createdAt: value.createdAt,
|
|
86
|
+
updatedAt: value.updatedAt,
|
|
87
|
+
phase,
|
|
88
|
+
operations: value.operations.map(operation),
|
|
89
|
+
...(value.lastOperation === undefined
|
|
90
|
+
? {}
|
|
91
|
+
: { lastOperation: result(value.lastOperation) }),
|
|
92
|
+
...(value.lastFailure === undefined
|
|
93
|
+
? {}
|
|
94
|
+
: { lastFailure: result(value.lastFailure) }),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export async function inspectResourceActivity(repository, maxEntries = defaults.maxRecords) {
|
|
98
|
+
positive(maxEntries, "maxEntries");
|
|
99
|
+
const entries = [];
|
|
100
|
+
const issues = [];
|
|
101
|
+
let path = repository;
|
|
102
|
+
try {
|
|
103
|
+
for (const part of [".outpost", "locks", defaults.directory]) {
|
|
104
|
+
path = join(path, part);
|
|
105
|
+
const info = await lstat(path);
|
|
106
|
+
invariant(info.isDirectory() &&
|
|
107
|
+
!info.isSymbolicLink() &&
|
|
108
|
+
(await realpath(path)) === path, "Unsafe activity directory");
|
|
109
|
+
}
|
|
110
|
+
for await (const entry of await opendir(path)) {
|
|
111
|
+
const file = join(path, entry.name);
|
|
112
|
+
if (entries.length >= Math.min(maxEntries, defaults.maxRecords)) {
|
|
113
|
+
issues.push({ path, code: "RESOURCE_ENTRY_LIMIT" });
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const value = record(JSON.parse((await readInspectionFile(file, defaults.maxRecordBytes)).toString("utf8")));
|
|
118
|
+
invariant(entry.name === `${value.id}.json`, "Activity identity mismatch");
|
|
119
|
+
entries.push({
|
|
120
|
+
path: file,
|
|
121
|
+
record: value,
|
|
122
|
+
ownership: await observeOwnership(value.pid, value.identity),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
entries.push({
|
|
127
|
+
path: file,
|
|
128
|
+
ownership: {
|
|
129
|
+
status: "unknown",
|
|
130
|
+
reason: "RESOURCE_RECORD_UNREADABLE",
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
issues.push({ path: file, code: "RESOURCE_RECORD_UNREADABLE" });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (cause) {
|
|
138
|
+
if (!(cause &&
|
|
139
|
+
typeof cause === "object" &&
|
|
140
|
+
"code" in cause &&
|
|
141
|
+
cause.code === "ENOENT"))
|
|
142
|
+
issues.push({ path, code: "RESOURCE_DIRECTORY_UNAVAILABLE" });
|
|
143
|
+
}
|
|
144
|
+
entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
145
|
+
return {
|
|
146
|
+
scope: "recorded-sandboxes",
|
|
147
|
+
complete: issues.length === 0,
|
|
148
|
+
entries,
|
|
149
|
+
issues,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=resource-activity-inspection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-activity-inspection.js","sourceRoot":"","sources":["../../src/infrastructure/resource-activity-inspection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EACL,wBAAwB,IAAI,QAAQ,EACpC,sBAAsB,EACtB,cAAc,GACf,MAAM,kCAAkC,CAAC;AAU1C,SAAS,MAAM,CAAC,KAAc;IAC5B,SAAS,CACP,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAC7D,yBAAyB,CAC1B,CA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,EAAE,oBAAoB;QAC3B,QAAQ,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC7B,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import { lstat, opendir, realpath } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { invariant, positive } from \"../domain/errors.ts\";\nimport { observeOwnership } from \"./git/process-identity.ts\";\nimport type { LocalProcessIdentity } from \"./git/process-identity.types.ts\";\nimport { readInspectionFile } from \"./inspection-file.ts\";\nimport {\n resourceActivityDefaults as defaults,\n resourceOperationKinds,\n resourcePhases,\n} from \"./resource-activity.constants.ts\";\nimport type {\n ResourceActivityRecord,\n ResourceInspection,\n ResourceInspectionEntry,\n ResourceOperation,\n ResourceOperationResult,\n} from \"./resource-activity.types.ts\";\nimport type { StorageIssue } from \"./storage-inventory.types.ts\";\n\nfunction object(value: unknown): asserts value is Record<string, unknown> {\n invariant(\n !!value && typeof value === \"object\" && !Array.isArray(value),\n \"Invalid activity object\",\n );\n}\nfunction text(value: unknown): asserts value is string {\n invariant(\n typeof value === \"string\" &&\n value.length > 0 &&\n value.length <= defaults.maxText,\n \"Invalid activity text\",\n );\n}\nfunction date(value: unknown): asserts value is string {\n text(value);\n invariant(Number.isFinite(Date.parse(value)), \"Invalid activity time\");\n}\nfunction operation(value: unknown): ResourceOperation {\n object(value);\n invariant(\n typeof value.count === \"number\" &&\n Number.isSafeInteger(value.count) &&\n value.count > 0,\n \"Invalid activity count\",\n );\n date(value.startedAt);\n const kind = resourceOperationKinds.find((kind) => kind === value.kind);\n invariant(kind, \"Invalid activity operation\");\n return { count: value.count, startedAt: value.startedAt, kind };\n}\nfunction result(value: unknown): ResourceOperationResult {\n const base = operation(value);\n object(value);\n text(value.id);\n date(value.finishedAt);\n invariant(\n value.outcome === \"completed\" || value.outcome === \"failed\",\n \"Invalid activity outcome\",\n );\n return {\n ...base,\n id: value.id,\n finishedAt: value.finishedAt,\n outcome: value.outcome,\n };\n}\nfunction identity(value: unknown): LocalProcessIdentity | undefined {\n if (value === undefined) return undefined;\n object(value);\n text(value.host);\n text(value.boot);\n text(value.namespace);\n text(value.started);\n return {\n host: value.host,\n boot: value.boot,\n namespace: value.namespace,\n started: value.started,\n };\n}\nfunction record(value: unknown): ResourceActivityRecord {\n object(value);\n invariant(value.version === 1, \"Unknown activity version\");\n text(value.id);\n text(value.provider);\n text(value.workspace);\n date(value.createdAt);\n date(value.updatedAt);\n invariant(\n typeof value.pid === \"number\" &&\n Number.isSafeInteger(value.pid) &&\n value.pid > 0 &&\n value.pid <= 2_147_483_647,\n \"Invalid activity owner\",\n );\n invariant(\n value.placement === \"host\" ||\n value.placement === \"mounted\" ||\n value.placement === \"remote\",\n \"Invalid activity placement\",\n );\n const phase = resourcePhases.find((phase) => phase === value.phase);\n invariant(phase, \"Invalid activity phase\");\n invariant(\n Array.isArray(value.operations) &&\n value.operations.length <= resourceOperationKinds.length,\n \"Invalid activity operations\",\n );\n const owner = identity(value.identity);\n return {\n version: 1,\n id: value.id,\n pid: value.pid,\n ...(owner ? { identity: owner } : {}),\n provider: value.provider,\n placement: value.placement,\n workspace: value.workspace,\n createdAt: value.createdAt,\n updatedAt: value.updatedAt,\n phase,\n operations: value.operations.map(operation),\n ...(value.lastOperation === undefined\n ? {}\n : { lastOperation: result(value.lastOperation) }),\n ...(value.lastFailure === undefined\n ? {}\n : { lastFailure: result(value.lastFailure) }),\n };\n}\n\nexport async function inspectResourceActivity(\n repository: string,\n maxEntries: number = defaults.maxRecords,\n): Promise<ResourceInspection> {\n positive(maxEntries, \"maxEntries\");\n const entries: ResourceInspectionEntry[] = [];\n const issues: StorageIssue[] = [];\n let path = repository;\n try {\n for (const part of [\".outpost\", \"locks\", defaults.directory]) {\n path = join(path, part);\n const info = await lstat(path);\n invariant(\n info.isDirectory() &&\n !info.isSymbolicLink() &&\n (await realpath(path)) === path,\n \"Unsafe activity directory\",\n );\n }\n for await (const entry of await opendir(path)) {\n const file = join(path, entry.name);\n if (entries.length >= Math.min(maxEntries, defaults.maxRecords)) {\n issues.push({ path, code: \"RESOURCE_ENTRY_LIMIT\" });\n break;\n }\n try {\n const value = record(\n JSON.parse(\n (await readInspectionFile(file, defaults.maxRecordBytes)).toString(\n \"utf8\",\n ),\n ),\n );\n invariant(\n entry.name === `${value.id}.json`,\n \"Activity identity mismatch\",\n );\n entries.push({\n path: file,\n record: value,\n ownership: await observeOwnership(value.pid, value.identity),\n });\n } catch {\n entries.push({\n path: file,\n ownership: {\n status: \"unknown\",\n reason: \"RESOURCE_RECORD_UNREADABLE\",\n },\n });\n issues.push({ path: file, code: \"RESOURCE_RECORD_UNREADABLE\" });\n }\n }\n } catch (cause) {\n if (!(\n cause &&\n typeof cause === \"object\" &&\n \"code\" in cause &&\n cause.code === \"ENOENT\"\n ))\n issues.push({ path, code: \"RESOURCE_DIRECTORY_UNAVAILABLE\" });\n }\n entries.sort((left, right) => left.path.localeCompare(right.path));\n return {\n scope: \"recorded-sandboxes\",\n complete: issues.length === 0,\n entries,\n issues,\n };\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const resourceActivityDefaults: {
|
|
2
|
+
readonly directory: "resource-activity";
|
|
3
|
+
readonly maxRecords: 10000;
|
|
4
|
+
readonly maxRecordBytes: 65536;
|
|
5
|
+
readonly maxText: 4096;
|
|
6
|
+
};
|
|
7
|
+
export declare const resourcePhases: readonly ["allocating", "ready", "closing", "cleanup-failed", "allocation-uncertain"];
|
|
8
|
+
export declare const resourceOperationKinds: readonly ["dispatch", "attach", "diagnose", "command", "invoke", "upload", "download", "manifest", "download-batch", "upload-batch"];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const resourceActivityDefaults = {
|
|
2
|
+
directory: "resource-activity",
|
|
3
|
+
maxRecords: 10_000,
|
|
4
|
+
maxRecordBytes: 65_536,
|
|
5
|
+
maxText: 4_096,
|
|
6
|
+
};
|
|
7
|
+
export const resourcePhases = [
|
|
8
|
+
"allocating",
|
|
9
|
+
"ready",
|
|
10
|
+
"closing",
|
|
11
|
+
"cleanup-failed",
|
|
12
|
+
"allocation-uncertain",
|
|
13
|
+
];
|
|
14
|
+
export const resourceOperationKinds = [
|
|
15
|
+
"dispatch",
|
|
16
|
+
"attach",
|
|
17
|
+
"diagnose",
|
|
18
|
+
"command",
|
|
19
|
+
"invoke",
|
|
20
|
+
"upload",
|
|
21
|
+
"download",
|
|
22
|
+
"manifest",
|
|
23
|
+
"download-batch",
|
|
24
|
+
"upload-batch",
|
|
25
|
+
];
|
|
26
|
+
//# sourceMappingURL=resource-activity.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-activity.constants.js","sourceRoot":"","sources":["../../src/infrastructure/resource-activity.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,SAAS,EAAE,mBAAmB;IAC9B,UAAU,EAAE,MAAM;IAClB,cAAc,EAAE,MAAM;IACtB,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,YAAY;IACZ,OAAO;IACP,SAAS;IACT,gBAAgB;IAChB,sBAAsB;CACd,CAAC;AACX,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,UAAU;IACV,QAAQ;IACR,UAAU;IACV,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,UAAU;IACV,gBAAgB;IAChB,cAAc;CACN,CAAC","sourcesContent":["export const resourceActivityDefaults = {\n directory: \"resource-activity\",\n maxRecords: 10_000,\n maxRecordBytes: 65_536,\n maxText: 4_096,\n} as const;\n\nexport const resourcePhases = [\n \"allocating\",\n \"ready\",\n \"closing\",\n \"cleanup-failed\",\n \"allocation-uncertain\",\n] as const;\nexport const resourceOperationKinds = [\n \"dispatch\",\n \"attach\",\n \"diagnose\",\n \"command\",\n \"invoke\",\n \"upload\",\n \"download\",\n \"manifest\",\n \"download-batch\",\n \"upload-batch\",\n] as const;\n"]}
|