@gpustack/loopwright 0.0.0-stage → 0.0.3
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/LICENSE +191 -0
- package/README.md +356 -2
- package/bin/loopwright.js +3 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.js +122 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.d.ts +30 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.js +340 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.js +65 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.js +76 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.js +113 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.d.ts +4 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.d.ts +96 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.js +1712 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.js +146 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.js +836 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.js +2 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.js +280 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.js +12 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.d.ts +29 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.js +160 -0
- package/node_modules/@loopwright/agent-pi/dist/context.d.ts +56 -0
- package/node_modules/@loopwright/agent-pi/dist/context.js +351 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.d.ts +8 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.js +52 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.js +18 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.js +287 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.d.ts +12 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.js +17 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.js +9 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.js +19 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/events.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/events.js +132 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.js +25 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.d.ts +24 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.js +316 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.js +476 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.d.ts +87 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.js +526 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.js +74 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.js +2094 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.js +353 -0
- package/node_modules/@loopwright/agent-pi/dist/index.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/index.js +4 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.js +11 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.d.ts +35 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.js +92 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.js +63 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.d.ts +23 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.js +212 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.d.ts +5 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.js +28 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.d.ts +10 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.js +260 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.d.ts +60 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.js +700 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.d.ts +1 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.js +119 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.d.ts +17 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.js +131 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.d.ts +62 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.js +217 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.js +188 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.js +81 -0
- package/node_modules/@loopwright/agent-pi/dist/response.d.ts +20 -0
- package/node_modules/@loopwright/agent-pi/dist/response.js +259 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.js +37 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.js +633 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.d.ts +46 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.js +553 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.d.ts +21 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.js +315 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.js +102 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.js +85 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.js +105 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.d.ts +36 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.js +128 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.d.ts +71 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/types.d.ts +314 -0
- package/node_modules/@loopwright/agent-pi/dist/types.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.js +314 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.d.ts +27 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.js +142 -0
- package/node_modules/@loopwright/agent-pi/package.json +24 -0
- package/node_modules/@loopwright/agent-pi/runtime/Dockerfile +8 -0
- package/node_modules/@loopwright/agent-pi/runtime/seccomp.json +1 -0
- package/node_modules/@loopwright/cli/dist/arguments.d.ts +19 -0
- package/node_modules/@loopwright/cli/dist/arguments.js +358 -0
- package/node_modules/@loopwright/cli/dist/closure.d.ts +93 -0
- package/node_modules/@loopwright/cli/dist/closure.js +230 -0
- package/node_modules/@loopwright/cli/dist/draft.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/draft.js +106 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.js +701 -0
- package/node_modules/@loopwright/cli/dist/index.d.ts +6 -0
- package/node_modules/@loopwright/cli/dist/index.js +5 -0
- package/node_modules/@loopwright/cli/dist/main.d.ts +22 -0
- package/node_modules/@loopwright/cli/dist/main.js +1855 -0
- package/node_modules/@loopwright/cli/package.json +16 -0
- package/node_modules/@loopwright/controller/dist/acceptance.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/acceptance.js +446 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.d.ts +273 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.js +3147 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.js +139 -0
- package/node_modules/@loopwright/controller/dist/bundle.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/bundle.js +64 -0
- package/node_modules/@loopwright/controller/dist/capture.d.ts +89 -0
- package/node_modules/@loopwright/controller/dist/capture.js +587 -0
- package/node_modules/@loopwright/controller/dist/compile.d.ts +3 -0
- package/node_modules/@loopwright/controller/dist/compile.js +402 -0
- package/node_modules/@loopwright/controller/dist/config.d.ts +22 -0
- package/node_modules/@loopwright/controller/dist/config.js +255 -0
- package/node_modules/@loopwright/controller/dist/controller.d.ts +177 -0
- package/node_modules/@loopwright/controller/dist/controller.js +2135 -0
- package/node_modules/@loopwright/controller/dist/credentials.d.ts +29 -0
- package/node_modules/@loopwright/controller/dist/credentials.js +189 -0
- package/node_modules/@loopwright/controller/dist/deadlines.d.ts +18 -0
- package/node_modules/@loopwright/controller/dist/deadlines.js +71 -0
- package/node_modules/@loopwright/controller/dist/errors.d.ts +27 -0
- package/node_modules/@loopwright/controller/dist/errors.js +41 -0
- package/node_modules/@loopwright/controller/dist/events.d.ts +52 -0
- package/node_modules/@loopwright/controller/dist/events.js +228 -0
- package/node_modules/@loopwright/controller/dist/files.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/files.js +386 -0
- package/node_modules/@loopwright/controller/dist/finalize.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/finalize.js +32 -0
- package/node_modules/@loopwright/controller/dist/gate.d.ts +84 -0
- package/node_modules/@loopwright/controller/dist/gate.js +640 -0
- package/node_modules/@loopwright/controller/dist/git-objects.d.ts +11 -0
- package/node_modules/@loopwright/controller/dist/git-objects.js +59 -0
- package/node_modules/@loopwright/controller/dist/git-reader.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/git-reader.js +40 -0
- package/node_modules/@loopwright/controller/dist/handlers.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/handlers.js +45 -0
- package/node_modules/@loopwright/controller/dist/handoff.d.ts +71 -0
- package/node_modules/@loopwright/controller/dist/handoff.js +554 -0
- package/node_modules/@loopwright/controller/dist/index.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/index.js +21 -0
- package/node_modules/@loopwright/controller/dist/inspect.d.ts +30 -0
- package/node_modules/@loopwright/controller/dist/inspect.js +372 -0
- package/node_modules/@loopwright/controller/dist/interpolation.d.ts +9 -0
- package/node_modules/@loopwright/controller/dist/interpolation.js +79 -0
- package/node_modules/@loopwright/controller/dist/ownership.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/ownership.js +666 -0
- package/node_modules/@loopwright/controller/dist/parser.d.ts +5 -0
- package/node_modules/@loopwright/controller/dist/parser.js +200 -0
- package/node_modules/@loopwright/controller/dist/progress.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/progress.js +904 -0
- package/node_modules/@loopwright/controller/dist/publication.d.ts +60 -0
- package/node_modules/@loopwright/controller/dist/publication.js +329 -0
- package/node_modules/@loopwright/controller/dist/reconcile.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/reconcile.js +1378 -0
- package/node_modules/@loopwright/controller/dist/recovery.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/recovery.js +315 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.js +150 -0
- package/node_modules/@loopwright/controller/dist/registry.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/registry.js +374 -0
- package/node_modules/@loopwright/controller/dist/repair.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/repair.js +102 -0
- package/node_modules/@loopwright/controller/dist/report.d.ts +64 -0
- package/node_modules/@loopwright/controller/dist/report.js +596 -0
- package/node_modules/@loopwright/controller/dist/retained.d.ts +284 -0
- package/node_modules/@loopwright/controller/dist/retained.js +193 -0
- package/node_modules/@loopwright/controller/dist/rules.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/rules.js +110 -0
- package/node_modules/@loopwright/controller/dist/run-eval.d.ts +115 -0
- package/node_modules/@loopwright/controller/dist/run-eval.js +959 -0
- package/node_modules/@loopwright/controller/dist/scheduler.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/scheduler.js +41 -0
- package/node_modules/@loopwright/controller/dist/schema.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/schema.js +78 -0
- package/node_modules/@loopwright/controller/dist/source.d.ts +69 -0
- package/node_modules/@loopwright/controller/dist/source.js +872 -0
- package/node_modules/@loopwright/controller/dist/step.d.ts +38 -0
- package/node_modules/@loopwright/controller/dist/step.js +1776 -0
- package/node_modules/@loopwright/controller/dist/storage.d.ts +90 -0
- package/node_modules/@loopwright/controller/dist/storage.js +1345 -0
- package/node_modules/@loopwright/controller/dist/submission.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/submission.js +292 -0
- package/node_modules/@loopwright/controller/dist/types.d.ts +585 -0
- package/node_modules/@loopwright/controller/dist/types.js +9 -0
- package/node_modules/@loopwright/controller/dist/verification.d.ts +124 -0
- package/node_modules/@loopwright/controller/dist/verification.js +1308 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.d.ts +105 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.js +1312 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.d.ts +1 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.js +33 -0
- package/node_modules/@loopwright/controller/package.json +12 -0
- package/node_modules/@loopwright/core/dist/acceptance.d.ts +108 -0
- package/node_modules/@loopwright/core/dist/acceptance.js +327 -0
- package/node_modules/@loopwright/core/dist/artifacts.d.ts +63 -0
- package/node_modules/@loopwright/core/dist/artifacts.js +356 -0
- package/node_modules/@loopwright/core/dist/boundary.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/boundary.js +484 -0
- package/node_modules/@loopwright/core/dist/contracts.d.ts +287 -0
- package/node_modules/@loopwright/core/dist/contracts.js +694 -0
- package/node_modules/@loopwright/core/dist/diagnostics.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/diagnostics.js +51 -0
- package/node_modules/@loopwright/core/dist/evidence.d.ts +92 -0
- package/node_modules/@loopwright/core/dist/evidence.js +85 -0
- package/node_modules/@loopwright/core/dist/graph.d.ts +8 -0
- package/node_modules/@loopwright/core/dist/graph.js +44 -0
- package/node_modules/@loopwright/core/dist/identity.d.ts +162 -0
- package/node_modules/@loopwright/core/dist/identity.js +80 -0
- package/node_modules/@loopwright/core/dist/index.d.ts +30 -0
- package/node_modules/@loopwright/core/dist/index.js +39 -0
- package/node_modules/@loopwright/core/dist/limits.d.ts +99 -0
- package/node_modules/@loopwright/core/dist/limits.js +59 -0
- package/node_modules/@loopwright/core/dist/results.d.ts +161 -0
- package/node_modules/@loopwright/core/dist/results.js +98 -0
- package/node_modules/@loopwright/core/dist/scope.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scope.js +154 -0
- package/node_modules/@loopwright/core/dist/scrubber.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scrubber.js +63 -0
- package/node_modules/@loopwright/core/dist/usage.d.ts +68 -0
- package/node_modules/@loopwright/core/dist/usage.js +56 -0
- package/node_modules/@loopwright/core/package.json +12 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.js +337 -0
- package/node_modules/@loopwright/decisions/dist/client.d.ts +74 -0
- package/node_modules/@loopwright/decisions/dist/client.js +292 -0
- package/node_modules/@loopwright/decisions/dist/index.d.ts +15 -0
- package/node_modules/@loopwright/decisions/dist/index.js +8 -0
- package/node_modules/@loopwright/decisions/dist/nodes.d.ts +63 -0
- package/node_modules/@loopwright/decisions/dist/nodes.js +282 -0
- package/node_modules/@loopwright/decisions/dist/primitives.d.ts +36 -0
- package/node_modules/@loopwright/decisions/dist/primitives.js +300 -0
- package/node_modules/@loopwright/decisions/dist/redaction.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/redaction.js +146 -0
- package/node_modules/@loopwright/decisions/dist/router.d.ts +55 -0
- package/node_modules/@loopwright/decisions/dist/router.js +248 -0
- package/node_modules/@loopwright/decisions/dist/schema.d.ts +25 -0
- package/node_modules/@loopwright/decisions/dist/schema.js +536 -0
- package/node_modules/@loopwright/decisions/dist/types.d.ts +394 -0
- package/node_modules/@loopwright/decisions/dist/types.js +80 -0
- package/node_modules/@loopwright/decisions/package.json +12 -0
- package/node_modules/@loopwright/github-app/dist/action.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/action.js +2429 -0
- package/node_modules/@loopwright/github-app/dist/config.d.ts +23 -0
- package/node_modules/@loopwright/github-app/dist/config.js +297 -0
- package/node_modules/@loopwright/github-app/dist/digests.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/digests.js +1 -0
- package/node_modules/@loopwright/github-app/dist/index.d.ts +14 -0
- package/node_modules/@loopwright/github-app/dist/index.js +13 -0
- package/node_modules/@loopwright/github-app/dist/models-config.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/models-config.js +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.js +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.js +1 -0
- package/node_modules/@loopwright/github-app/dist/publisher.d.ts +58 -0
- package/node_modules/@loopwright/github-app/dist/publisher.js +1368 -0
- package/node_modules/@loopwright/github-app/dist/qualification.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/qualification.js +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.js +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.js +1 -0
- package/node_modules/@loopwright/github-app/dist/service.d.ts +52 -0
- package/node_modules/@loopwright/github-app/dist/service.js +1658 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.js +392 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.js +1 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.d.ts +44 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.js +423 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.d.ts +50 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.js +262 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.d.ts +35 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.js +1654 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.d.ts +16 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.js +34 -0
- package/node_modules/@loopwright/github-app/dist/types.d.ts +220 -0
- package/node_modules/@loopwright/github-app/dist/types.js +14 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.d.ts +13 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.js +65 -0
- package/node_modules/@loopwright/github-app/dist/webhook.d.ts +34 -0
- package/node_modules/@loopwright/github-app/dist/webhook.js +241 -0
- package/node_modules/@loopwright/github-app/dist/yaml.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/yaml.js +1 -0
- package/node_modules/@loopwright/github-app/package.json +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.d.ts +48 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.js +719 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.d.ts +230 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.js +3178 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.js +9 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.d.ts +128 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.js +1500 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.d.ts +81 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.js +1081 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.js +2997 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.d.ts +239 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.js +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.d.ts +49 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.js +1648 -0
- package/node_modules/@loopwright/hardware-runner/package.json +12 -0
- package/node_modules/@loopwright/memory/dist/cas.d.ts +21 -0
- package/node_modules/@loopwright/memory/dist/cas.js +510 -0
- package/node_modules/@loopwright/memory/dist/compaction.d.ts +18 -0
- package/node_modules/@loopwright/memory/dist/compaction.js +110 -0
- package/node_modules/@loopwright/memory/dist/finalizer.d.ts +23 -0
- package/node_modules/@loopwright/memory/dist/finalizer.js +538 -0
- package/node_modules/@loopwright/memory/dist/index.d.ts +9 -0
- package/node_modules/@loopwright/memory/dist/index.js +8 -0
- package/node_modules/@loopwright/memory/dist/schema.d.ts +36 -0
- package/node_modules/@loopwright/memory/dist/schema.js +510 -0
- package/node_modules/@loopwright/memory/dist/selector.d.ts +7 -0
- package/node_modules/@loopwright/memory/dist/selector.js +157 -0
- package/node_modules/@loopwright/memory/dist/store.d.ts +51 -0
- package/node_modules/@loopwright/memory/dist/store.js +554 -0
- package/node_modules/@loopwright/memory/dist/types.d.ts +442 -0
- package/node_modules/@loopwright/memory/dist/types.js +8 -0
- package/node_modules/@loopwright/memory/dist/verifier.d.ts +5 -0
- package/node_modules/@loopwright/memory/dist/verifier.js +328 -0
- package/node_modules/@loopwright/memory/package.json +12 -0
- package/node_modules/@loopwright/state/dist/admission.d.ts +321 -0
- package/node_modules/@loopwright/state/dist/admission.js +199 -0
- package/node_modules/@loopwright/state/dist/boundary.d.ts +53 -0
- package/node_modules/@loopwright/state/dist/boundary.js +194 -0
- package/node_modules/@loopwright/state/dist/checkpoint.d.ts +16 -0
- package/node_modules/@loopwright/state/dist/checkpoint.js +84 -0
- package/node_modules/@loopwright/state/dist/clock.d.ts +8 -0
- package/node_modules/@loopwright/state/dist/clock.js +27 -0
- package/node_modules/@loopwright/state/dist/connection.d.ts +55 -0
- package/node_modules/@loopwright/state/dist/connection.js +391 -0
- package/node_modules/@loopwright/state/dist/errors.d.ts +13 -0
- package/node_modules/@loopwright/state/dist/errors.js +34 -0
- package/node_modules/@loopwright/state/dist/index.d.ts +3 -0
- package/node_modules/@loopwright/state/dist/index.js +1 -0
- package/node_modules/@loopwright/state/dist/journal.d.ts +119 -0
- package/node_modules/@loopwright/state/dist/journal.js +72 -0
- package/node_modules/@loopwright/state/dist/model.d.ts +40 -0
- package/node_modules/@loopwright/state/dist/model.js +58 -0
- package/node_modules/@loopwright/state/dist/ownership.d.ts +14 -0
- package/node_modules/@loopwright/state/dist/ownership.js +45 -0
- package/node_modules/@loopwright/state/dist/pages.d.ts +11 -0
- package/node_modules/@loopwright/state/dist/pages.js +41 -0
- package/node_modules/@loopwright/state/dist/receipts.d.ts +33 -0
- package/node_modules/@loopwright/state/dist/receipts.js +97 -0
- package/node_modules/@loopwright/state/dist/schema.d.ts +28 -0
- package/node_modules/@loopwright/state/dist/schema.js +41 -0
- package/node_modules/@loopwright/state/dist/settlement.d.ts +10 -0
- package/node_modules/@loopwright/state/dist/settlement.js +129 -0
- package/node_modules/@loopwright/state/dist/store.d.ts +52 -0
- package/node_modules/@loopwright/state/dist/store.js +100 -0
- package/node_modules/@loopwright/state/dist/types.d.ts +315 -0
- package/node_modules/@loopwright/state/dist/types.js +1 -0
- package/node_modules/@loopwright/state/package.json +12 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.d.ts +195 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.js +1847 -0
- package/node_modules/@loopwright/taskpack/dist/digests.d.ts +61 -0
- package/node_modules/@loopwright/taskpack/dist/digests.js +715 -0
- package/node_modules/@loopwright/taskpack/dist/index.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/index.js +17 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.d.ts +112 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.js +1026 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.d.ts +28 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.js +157 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.d.ts +130 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.js +1497 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.d.ts +23 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.js +120 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.d.ts +121 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.js +2642 -0
- package/node_modules/@loopwright/taskpack/dist/schema.d.ts +197 -0
- package/node_modules/@loopwright/taskpack/dist/schema.js +4189 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.d.ts +47 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.js +283 -0
- package/node_modules/@loopwright/taskpack/dist/suite.d.ts +124 -0
- package/node_modules/@loopwright/taskpack/dist/suite.js +3256 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.d.ts +154 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.js +3634 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.d.ts +122 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.js +483 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.d.ts +437 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.js +7335 -0
- package/node_modules/@loopwright/taskpack/dist/types.d.ts +1274 -0
- package/node_modules/@loopwright/taskpack/dist/types.js +99 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.d.ts +261 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.js +2242 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.js +167 -0
- package/node_modules/@loopwright/taskpack/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.d.ts +137 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.js +474 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.d.ts +8 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.js +129 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.js +7 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.js +135 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.d.ts +130 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.js +927 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.d.ts +68 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.js +517 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.js +1796 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.d.ts +29 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.js +11 -0
- package/node_modules/@loopwright/taskpack-runner/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/README.md +77 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/support-records.md +57 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/supported-runners.md +98 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/manifest.json +205 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/expand_matrix.sh +273 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/matrix.yaml +280 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/resolve_dockerfile.sh +24 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pyproject.toml +46 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/runtime_runner/runner.py.json +5270 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/discovery/legacy-support.md +86 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/github/service.py +401 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/analysis.json +95 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/ready.json +109 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_assemble.py +263 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_check_draft.py +333 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_checks.py +1099 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_discovery.py +817 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_proposal.py +658 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_publish.py +987 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_summary.py +107 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/agent.py +610 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/assemble.py +84 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/check_draft.py +94 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/checks.py +1002 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/discovery.py +789 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/model.py +557 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/progress.py +174 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/analysis.md +40 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/proposal.md +65 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/repair.md +17 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/proposal.py +903 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/publish.py +997 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/summary.py +131 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/tool-versions.json +133 -0
- package/node_modules/package-lock.json +3025 -0
- package/package-lock.json +3025 -0
- package/package.json +52 -4
|
@@ -0,0 +1,1497 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
3
|
+
import { constants as fsConstants } from 'node:fs';
|
|
4
|
+
import { chmod, link, lstat, mkdir, mkdtemp, open, readdir, realpath, rm, unlink } from 'node:fs/promises';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
7
|
+
import { STANDARD_PI_PROVIDER_ENV } from '@loopwright/agent-pi/catalog';
|
|
8
|
+
import { OVERLAY_LIMITS } from '@loopwright/core';
|
|
9
|
+
import { assertDigestLockfileVerified, computeFileDigest } from './digests.js';
|
|
10
|
+
import { collectMcpReferencedEnvNames, IDENTIFIER_PATTERN, normalizeRelativePath, parseJsonSubset, validateExecutionAuthority, } from './schema.js';
|
|
11
|
+
import { createStreamScrubber, SecretScrubber } from './scrubber.js';
|
|
12
|
+
import { TaskpackError, } from './types.js';
|
|
13
|
+
import { applyUpstreamGroups, attachUpstreamContext, evaluateUpstreamIntakeDisposition, isPlainRecord, loadRepositoryBaselineVersions, normalizeHeldBackVersions, } from './upstreams.js';
|
|
14
|
+
export const STREAM_CHUNK_BYTES = 1_048_576;
|
|
15
|
+
export const PREFLIGHT_DEFAULT_TIMEOUT_SECONDS = 60;
|
|
16
|
+
export const PREFLIGHT_MAX_TIMEOUT_SECONDS = 3_600;
|
|
17
|
+
export const PREFLIGHT_MAX_OUTPUT_JSON_BYTES = 512 * 1024;
|
|
18
|
+
export const PREFLIGHT_OUTPUT_MAX_DEPTH = 12;
|
|
19
|
+
export const PREFLIGHT_MAX_STDIO_BYTES = 65_536;
|
|
20
|
+
export const PREFLIGHT_MAX_PROMPT_RESOURCE_BYTES = 64 * 1024;
|
|
21
|
+
export const PREFLIGHT_MAX_PROMPT_RESOURCES_TOTAL_BYTES = 256 * 1024;
|
|
22
|
+
export const PREFLIGHT_MAX_WORKSPACE_RESOURCE_BYTES = 128 * 1024 * 1024;
|
|
23
|
+
export const PREFLIGHT_MAX_WORKSPACE_RESOURCES_TOTAL_BYTES = 256 * 1024 * 1024;
|
|
24
|
+
export const PREFLIGHT_MAX_STAGED_RESOURCES = 64;
|
|
25
|
+
export const PREFLIGHT_MAX_UPSTREAMS = 64;
|
|
26
|
+
export const PREFLIGHT_MAX_METADATA_KEYS = 32;
|
|
27
|
+
export const PREFLIGHT_MAX_METADATA_BYTES = 8_192;
|
|
28
|
+
export const PREFLIGHT_SAFE_DEFAULT_PATH = '/usr/local/bin:/usr/bin:/bin';
|
|
29
|
+
const STDIO_DRAIN_GRACE_MS = 50;
|
|
30
|
+
const UPPERCASE_ENV_REF_PATTERN = /^\$\{([A-Z][A-Z0-9_]{0,63})\}$/;
|
|
31
|
+
const UPPERCASE_ENV_NAME_PATTERN = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
32
|
+
const RESERVED_PREFLIGHT_INJECTED_VARS = new Set([
|
|
33
|
+
'LOOPWRIGHT_PREFLIGHT_OUT',
|
|
34
|
+
'LOOPWRIGHT_REPO_ROOT',
|
|
35
|
+
'LOOPWRIGHT_STAGING_DIR',
|
|
36
|
+
]);
|
|
37
|
+
const CREDENTIAL_VALUE_ENV_NAMES = new Set([
|
|
38
|
+
'GITHUB_TOKEN',
|
|
39
|
+
'GH_TOKEN',
|
|
40
|
+
'GITHUB_APP_PRIVATE_KEY',
|
|
41
|
+
'GITHUB_APP_WEBHOOK_SECRET',
|
|
42
|
+
'INPUT_GITHUB-TOKEN',
|
|
43
|
+
'INPUT_GITHUB-APP-PRIVATE-KEY',
|
|
44
|
+
'OPENAI_API_KEY',
|
|
45
|
+
'ANTHROPIC_API_KEY',
|
|
46
|
+
'GEMINI_API_KEY',
|
|
47
|
+
'GOOGLE_API_KEY',
|
|
48
|
+
'TYPESAFE_API_KEY',
|
|
49
|
+
'AWS_ACCESS_KEY_ID',
|
|
50
|
+
'AWS_SECRET_ACCESS_KEY',
|
|
51
|
+
'AWS_SESSION_TOKEN',
|
|
52
|
+
'NPM_TOKEN',
|
|
53
|
+
'NODE_AUTH_TOKEN',
|
|
54
|
+
'AZURE_OPENAI_API_KEY',
|
|
55
|
+
'OPENROUTER_API_KEY',
|
|
56
|
+
'XAI_API_KEY',
|
|
57
|
+
'DEEPSEEK_API_KEY',
|
|
58
|
+
'MISTRAL_API_KEY',
|
|
59
|
+
'COHERE_API_KEY',
|
|
60
|
+
'GROQ_API_KEY',
|
|
61
|
+
'LLM_TOKEN',
|
|
62
|
+
...Object.values(STANDARD_PI_PROVIDER_ENV),
|
|
63
|
+
]);
|
|
64
|
+
const FORBIDDEN_CREDENTIAL_ENV_NAMES = new Set([
|
|
65
|
+
...CREDENTIAL_VALUE_ENV_NAMES,
|
|
66
|
+
'GITHUB_APP_ID',
|
|
67
|
+
'GITHUB_APP_INSTALLATION_ID',
|
|
68
|
+
'BASH_ENV',
|
|
69
|
+
'ENV',
|
|
70
|
+
'NODE_OPTIONS',
|
|
71
|
+
]);
|
|
72
|
+
const FORBIDDEN_CREDENTIAL_ENV_PREFIXES = Object.freeze([
|
|
73
|
+
'LOOPWRIGHT_',
|
|
74
|
+
'GITHUB_APP_',
|
|
75
|
+
'INPUT_',
|
|
76
|
+
'ACTIONS_',
|
|
77
|
+
'RUNNER_',
|
|
78
|
+
'GIT_',
|
|
79
|
+
'LD_',
|
|
80
|
+
'DYLD_',
|
|
81
|
+
]);
|
|
82
|
+
const CREDENTIAL_VALUE_ENV_PATTERN = /(?:^|[_-])(?:TOKEN|SECRET|PASSWORD|PASSWD|API[_-]?KEY|PRIVATE[_-]?KEY|ACCESS[_-]?KEY(?:[_-]?ID)?|AUTH[_-]?KEY|CREDENTIAL|BEARER|COOKIE|SESSION[_-]?KEY|SIGNING[_-]?KEY|GH[_-]?PAT)(?:$|[_-])/;
|
|
83
|
+
const NON_SECRET_METADATA_ENV_SUFFIX = /(?:[_-])(?:ENV(?:[_-]NAME)?|PATH|FILE|URL|URI|COUNT|LIMIT|BUDGET|SECONDS|MS)$/;
|
|
84
|
+
const FORBIDDEN_OBJECT_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
85
|
+
const ALLOWED_DISPOSITIONS = new Set(['candidate', 'no_change', 'blocked']);
|
|
86
|
+
const ALLOWED_UPSTREAM_STATUSES = new Set([
|
|
87
|
+
'available',
|
|
88
|
+
'up_to_date',
|
|
89
|
+
'held_back',
|
|
90
|
+
'blocked',
|
|
91
|
+
'failed',
|
|
92
|
+
]);
|
|
93
|
+
const ALLOWED_STAGED_KINDS = new Set(['instruction', 'skill', 'document']);
|
|
94
|
+
const ALLOWED_STAGED_MOUNTS = new Set(['prompt', 'workspace']);
|
|
95
|
+
function extractEnvRefName(raw) {
|
|
96
|
+
if (typeof raw !== 'string')
|
|
97
|
+
return undefined;
|
|
98
|
+
const trimmed = raw.trim();
|
|
99
|
+
const wrapped = UPPERCASE_ENV_REF_PATTERN.exec(trimmed);
|
|
100
|
+
if (wrapped !== null)
|
|
101
|
+
return wrapped[1];
|
|
102
|
+
if (UPPERCASE_ENV_NAME_PATTERN.test(trimmed))
|
|
103
|
+
return trimmed;
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
/** Collect every uppercase env-shaped secret/credential binding referenced by a Taskpack manifest. */
|
|
107
|
+
export function collectManifestSecretEnvNames(manifest) {
|
|
108
|
+
const names = new Set();
|
|
109
|
+
for (const model of manifest.spec.models ?? []) {
|
|
110
|
+
const envName = extractEnvRefName(model.apiKeyEnv);
|
|
111
|
+
if (envName !== undefined)
|
|
112
|
+
names.add(envName.toUpperCase());
|
|
113
|
+
}
|
|
114
|
+
for (const mcpEnv of collectMcpReferencedEnvNames(manifest.spec.mcp?.servers)) {
|
|
115
|
+
names.add(mcpEnv.toUpperCase());
|
|
116
|
+
}
|
|
117
|
+
for (const gate of manifest.spec.verification.externalGates) {
|
|
118
|
+
const signingEnv = extractEnvRefName(gate.signingCredentialRef);
|
|
119
|
+
if (signingEnv !== undefined)
|
|
120
|
+
names.add(signingEnv.toUpperCase());
|
|
121
|
+
const authEnv = extractEnvRefName(gate.authCredentialRef);
|
|
122
|
+
if (authEnv !== undefined)
|
|
123
|
+
names.add(authEnv.toUpperCase());
|
|
124
|
+
}
|
|
125
|
+
return names;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* True when an environment variable name holds Loopwright control-plane, GitHub App, CI/loader
|
|
129
|
+
* runtime injection, manifest-declared credential, or provider secret material that MUST always be
|
|
130
|
+
* stripped from preflight subprocesses unless explicitly passed via an operator-brokered map.
|
|
131
|
+
*/
|
|
132
|
+
const ALLOWED_PREFLIGHT_RUNNER_ENV_NAMES = new Set(['RUNNER_ENVIRONMENT']);
|
|
133
|
+
export function isForbiddenPreflightEnvName(name, extraForbidden) {
|
|
134
|
+
const upper = name.toUpperCase();
|
|
135
|
+
if (extraForbidden?.has(upper) === true)
|
|
136
|
+
return true;
|
|
137
|
+
if (FORBIDDEN_CREDENTIAL_ENV_NAMES.has(upper))
|
|
138
|
+
return true;
|
|
139
|
+
if (ALLOWED_PREFLIGHT_RUNNER_ENV_NAMES.has(upper))
|
|
140
|
+
return false;
|
|
141
|
+
if (FORBIDDEN_CREDENTIAL_ENV_PREFIXES.some(prefix => upper.startsWith(prefix)))
|
|
142
|
+
return true;
|
|
143
|
+
if (CREDENTIAL_VALUE_ENV_PATTERN.test(upper))
|
|
144
|
+
return true;
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* True when an environment variable holds credential/secret material whose VALUE should be
|
|
149
|
+
* registered in preflight leak-detection scrubbers. Excludes non-secret runner/input flags
|
|
150
|
+
* (for example `INPUT_DRY-RUN="false"`, `INPUT_MODE="auto"`, `RUNNER_OS="Linux"`, or
|
|
151
|
+
* `INPUT_PROVIDER-TOKEN-ENV`) that are stripped from child env for hygiene but must not mark
|
|
152
|
+
* ordinary words or booleans as leaked credentials.
|
|
153
|
+
*/
|
|
154
|
+
export function isCredentialPreflightEnvName(name, extraForbidden) {
|
|
155
|
+
const upper = name.toUpperCase();
|
|
156
|
+
if (extraForbidden?.has(upper) === true)
|
|
157
|
+
return true;
|
|
158
|
+
if (CREDENTIAL_VALUE_ENV_NAMES.has(upper))
|
|
159
|
+
return true;
|
|
160
|
+
if (NON_SECRET_METADATA_ENV_SUFFIX.test(upper))
|
|
161
|
+
return false;
|
|
162
|
+
return CREDENTIAL_VALUE_ENV_PATTERN.test(upper);
|
|
163
|
+
}
|
|
164
|
+
function isContainedInRoot(candidate, root) {
|
|
165
|
+
if (candidate === root)
|
|
166
|
+
return true;
|
|
167
|
+
const prefix = root.endsWith(sep) ? root : `${root}${sep}`;
|
|
168
|
+
return candidate.startsWith(prefix);
|
|
169
|
+
}
|
|
170
|
+
class BoundedStreamBuffer {
|
|
171
|
+
#maxBytes;
|
|
172
|
+
#chunks = [];
|
|
173
|
+
#totalBytes = 0;
|
|
174
|
+
truncated = false;
|
|
175
|
+
constructor(maxBytes) {
|
|
176
|
+
this.#maxBytes = maxBytes;
|
|
177
|
+
}
|
|
178
|
+
append(chunk) {
|
|
179
|
+
if (chunk.byteLength === 0)
|
|
180
|
+
return;
|
|
181
|
+
if (this.#totalBytes >= this.#maxBytes) {
|
|
182
|
+
this.truncated = true;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const remaining = this.#maxBytes - this.#totalBytes;
|
|
186
|
+
if (chunk.byteLength > remaining) {
|
|
187
|
+
this.#chunks.push(chunk.subarray(0, remaining));
|
|
188
|
+
this.#totalBytes += remaining;
|
|
189
|
+
this.truncated = true;
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.#chunks.push(chunk);
|
|
193
|
+
this.#totalBytes += chunk.byteLength;
|
|
194
|
+
}
|
|
195
|
+
toString() {
|
|
196
|
+
if (this.#chunks.length === 0)
|
|
197
|
+
return '';
|
|
198
|
+
const text = Buffer.concat(this.#chunks).toString('utf8');
|
|
199
|
+
return this.truncated ? `${text}\n[output truncated]` : text;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async function resolveSafeDirectory(dirPath, label, errorCode = 'TASKPACK_MANIFEST_INVALID') {
|
|
203
|
+
const resolved = resolve(dirPath);
|
|
204
|
+
const st = await lstat(resolved).catch(() => null);
|
|
205
|
+
if (st === null || st.isSymbolicLink() || !st.isDirectory()) {
|
|
206
|
+
throw new TaskpackError(errorCode, `${label} must be an existing non-symlink directory`, '/spec/preflight');
|
|
207
|
+
}
|
|
208
|
+
const real = await realpath(resolved).catch(() => {
|
|
209
|
+
throw new TaskpackError(errorCode, `${label} cannot be resolved`, '/spec/preflight');
|
|
210
|
+
});
|
|
211
|
+
return { resolved, real };
|
|
212
|
+
}
|
|
213
|
+
async function openAndReadNoFollowBoundedFile(fullPath, maxBytes, diagPath, options) {
|
|
214
|
+
const requireSingleLink = options?.requireSingleLink === true;
|
|
215
|
+
let before;
|
|
216
|
+
try {
|
|
217
|
+
before = await lstat(fullPath);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
const code = error?.code;
|
|
221
|
+
if (code === 'ELOOP') {
|
|
222
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: symbolic link traversal is forbidden`, diagPath);
|
|
223
|
+
}
|
|
224
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file does not exist or cannot be inspected`, diagPath);
|
|
225
|
+
}
|
|
226
|
+
if (before.isSymbolicLink()) {
|
|
227
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: symbolic links are forbidden`, diagPath);
|
|
228
|
+
}
|
|
229
|
+
if (!before.isFile()) {
|
|
230
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: path must be a regular file`, diagPath);
|
|
231
|
+
}
|
|
232
|
+
if (requireSingleLink && before.nlink !== 1) {
|
|
233
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: hardlinked file (nlink=${before.nlink}) is forbidden`, diagPath);
|
|
234
|
+
}
|
|
235
|
+
if (before.size > maxBytes) {
|
|
236
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file exceeds maximum ${maxBytes} bytes`, diagPath);
|
|
237
|
+
}
|
|
238
|
+
const noFollow = 'O_NOFOLLOW' in fsConstants ? fsConstants.O_NOFOLLOW : 0;
|
|
239
|
+
let handle;
|
|
240
|
+
try {
|
|
241
|
+
handle = await open(fullPath, fsConstants.O_RDONLY | noFollow);
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
const code = error?.code;
|
|
245
|
+
if (code === 'ELOOP') {
|
|
246
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: symbolic link detected while opening file`, diagPath);
|
|
247
|
+
}
|
|
248
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file could not be opened`, diagPath);
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
const info = await handle.stat();
|
|
252
|
+
if (requireSingleLink && info.nlink !== 1) {
|
|
253
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: hardlinked file (nlink=${info.nlink}) detected while reading`, diagPath);
|
|
254
|
+
}
|
|
255
|
+
if (!info.isFile() || info.size !== before.size || info.size > maxBytes) {
|
|
256
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file changed while reading or exceeds ${maxBytes} bytes`, diagPath);
|
|
257
|
+
}
|
|
258
|
+
const buf = Buffer.alloc(info.size + 1);
|
|
259
|
+
let offset = 0;
|
|
260
|
+
while (offset < buf.length) {
|
|
261
|
+
const { bytesRead } = await handle.read(buf, offset, buf.length - offset, offset);
|
|
262
|
+
if (bytesRead === 0)
|
|
263
|
+
break;
|
|
264
|
+
offset += bytesRead;
|
|
265
|
+
}
|
|
266
|
+
const after = await handle.stat();
|
|
267
|
+
if (requireSingleLink && after.nlink !== 1) {
|
|
268
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: hardlinked file (nlink=${after.nlink}) detected after reading`, diagPath);
|
|
269
|
+
}
|
|
270
|
+
if (offset !== info.size
|
|
271
|
+
|| after.dev !== info.dev
|
|
272
|
+
|| after.ino !== info.ino
|
|
273
|
+
|| after.size !== info.size
|
|
274
|
+
|| after.mtimeMs !== info.mtimeMs
|
|
275
|
+
|| after.ctimeMs !== info.ctimeMs) {
|
|
276
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file changed size while reading`, diagPath);
|
|
277
|
+
}
|
|
278
|
+
return buf.subarray(0, offset);
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
await handle.close();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
async function resolveNoSymlinkFileInRoot(rootResolved, rootReal, relPath, diagPath) {
|
|
285
|
+
const normalizedRel = normalizeRelativePath(relPath, diagPath);
|
|
286
|
+
const segments = normalizedRel.split('/');
|
|
287
|
+
let cursor = rootResolved;
|
|
288
|
+
for (const segment of segments) {
|
|
289
|
+
cursor = join(cursor, segment);
|
|
290
|
+
let st;
|
|
291
|
+
try {
|
|
292
|
+
st = await lstat(cursor);
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
const code = error?.code;
|
|
296
|
+
if (code === 'ENOENT' || code === 'ENOTDIR') {
|
|
297
|
+
return { exists: false };
|
|
298
|
+
}
|
|
299
|
+
if (code === 'ELOOP') {
|
|
300
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: path "${normalizedRel}" traverses a symbolic link`, diagPath);
|
|
301
|
+
}
|
|
302
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
303
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: failed to inspect path "${normalizedRel}": ${detail}`, diagPath);
|
|
304
|
+
}
|
|
305
|
+
if (st.isSymbolicLink()) {
|
|
306
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: path "${normalizedRel}" traverses or targets a symbolic link`, diagPath);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
const realFull = await realpath(cursor).catch(() => {
|
|
310
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: path "${normalizedRel}" cannot be resolved`, diagPath);
|
|
311
|
+
});
|
|
312
|
+
if (!isContainedInRoot(realFull, rootReal)) {
|
|
313
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: path "${normalizedRel}" escapes root`, diagPath);
|
|
314
|
+
}
|
|
315
|
+
return { exists: true, fullPath: cursor, normalizedRel };
|
|
316
|
+
}
|
|
317
|
+
async function resolveStagedResourceSource(rawPath, repoRoot, stagingRoot, diagPath) {
|
|
318
|
+
if (typeof rawPath !== 'string' || rawPath.length === 0 || rawPath.length > 1024 || /[\0\r\n\\]/.test(rawPath)) {
|
|
319
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: staged resource path is invalid`, diagPath);
|
|
320
|
+
}
|
|
321
|
+
if (rawPath.split('/').some(seg => seg === '..')) {
|
|
322
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: staged resource path "${rawPath}" must not traverse parent directories`, diagPath);
|
|
323
|
+
}
|
|
324
|
+
if (isAbsolute(rawPath)) {
|
|
325
|
+
const candidateResolved = resolve(rawPath);
|
|
326
|
+
const tryRoot = async (root, sourceRoot) => {
|
|
327
|
+
const base = isContainedInRoot(candidateResolved, root.real)
|
|
328
|
+
? root.real
|
|
329
|
+
: isContainedInRoot(candidateResolved, root.resolved)
|
|
330
|
+
? root.resolved
|
|
331
|
+
: null;
|
|
332
|
+
if (base === null)
|
|
333
|
+
return null;
|
|
334
|
+
const rel = relative(base, candidateResolved);
|
|
335
|
+
if (rel.length === 0 || rel.startsWith('..') || isAbsolute(rel))
|
|
336
|
+
return null;
|
|
337
|
+
const posixRel = rel.split(sep).join('/');
|
|
338
|
+
const found = await resolveNoSymlinkFileInRoot(root.resolved, root.real, posixRel, diagPath);
|
|
339
|
+
if (!found.exists) {
|
|
340
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: staged resource "${rawPath}" does not exist`, diagPath);
|
|
341
|
+
}
|
|
342
|
+
return { fullPath: found.fullPath, relativePath: found.normalizedRel, sourceRoot };
|
|
343
|
+
};
|
|
344
|
+
const inStaging = await tryRoot(stagingRoot, 'staging');
|
|
345
|
+
if (inStaging !== null)
|
|
346
|
+
return inStaging;
|
|
347
|
+
const inRepo = await tryRoot(repoRoot, 'repo');
|
|
348
|
+
if (inRepo !== null)
|
|
349
|
+
return inRepo;
|
|
350
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: absolute staged resource path "${rawPath}" escapes allowed roots`, diagPath);
|
|
351
|
+
}
|
|
352
|
+
const normalizedRel = normalizeRelativePath(rawPath, diagPath);
|
|
353
|
+
const inStaging = await resolveNoSymlinkFileInRoot(stagingRoot.resolved, stagingRoot.real, normalizedRel, diagPath);
|
|
354
|
+
if (inStaging.exists) {
|
|
355
|
+
return { fullPath: inStaging.fullPath, relativePath: inStaging.normalizedRel, sourceRoot: 'staging' };
|
|
356
|
+
}
|
|
357
|
+
const inRepo = await resolveNoSymlinkFileInRoot(repoRoot.resolved, repoRoot.real, normalizedRel, diagPath);
|
|
358
|
+
if (inRepo.exists) {
|
|
359
|
+
return { fullPath: inRepo.fullPath, relativePath: inRepo.normalizedRel, sourceRoot: 'repo' };
|
|
360
|
+
}
|
|
361
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: staged resource "${normalizedRel}" not found in staging directory or repository root`, diagPath);
|
|
362
|
+
}
|
|
363
|
+
function hasWorkspacePathPrefixCollision(candidateRel, existingRelPaths) {
|
|
364
|
+
for (const existing of existingRelPaths) {
|
|
365
|
+
if (existing === candidateRel
|
|
366
|
+
|| candidateRel.startsWith(`${existing}/`)
|
|
367
|
+
|| existing.startsWith(`${candidateRel}/`)) {
|
|
368
|
+
return existing;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
export async function projectVerifiedWorkspaceSource(options) {
|
|
374
|
+
const { srcFullPath, stagedRootDir, relativePath, maxFileBytes, maxRemainingTotalBytes, requireSingleLink, scrubber, strippedScrubber, diagPath, } = options;
|
|
375
|
+
let lstatBefore;
|
|
376
|
+
try {
|
|
377
|
+
lstatBefore = await lstat(srcFullPath);
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
const code = error?.code;
|
|
381
|
+
if (code === 'ELOOP') {
|
|
382
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: symbolic link traversal is forbidden`, diagPath);
|
|
383
|
+
}
|
|
384
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file does not exist or cannot be inspected`, diagPath);
|
|
385
|
+
}
|
|
386
|
+
if (lstatBefore.isSymbolicLink()) {
|
|
387
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: symbolic links are forbidden`, diagPath);
|
|
388
|
+
}
|
|
389
|
+
if (!lstatBefore.isFile()) {
|
|
390
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: path must be a regular file`, diagPath);
|
|
391
|
+
}
|
|
392
|
+
if (requireSingleLink && lstatBefore.nlink !== 1) {
|
|
393
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: hardlinked file (nlink=${lstatBefore.nlink}) is forbidden`, diagPath);
|
|
394
|
+
}
|
|
395
|
+
if (lstatBefore.size > maxFileBytes) {
|
|
396
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file exceeds maximum ${maxFileBytes} bytes`, diagPath);
|
|
397
|
+
}
|
|
398
|
+
if (lstatBefore.size > maxRemainingTotalBytes) {
|
|
399
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: aggregate workspace-mounted staged resources exceed maximum bytes`, diagPath);
|
|
400
|
+
}
|
|
401
|
+
const noFollow = 'O_NOFOLLOW' in fsConstants ? fsConstants.O_NOFOLLOW : 0;
|
|
402
|
+
let srcHandle;
|
|
403
|
+
try {
|
|
404
|
+
srcHandle = await open(srcFullPath, fsConstants.O_RDONLY | noFollow);
|
|
405
|
+
}
|
|
406
|
+
catch (error) {
|
|
407
|
+
const code = error?.code;
|
|
408
|
+
if (code === 'ELOOP' || code === 'EMLINK') {
|
|
409
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: symbolic link detected while opening file`, diagPath);
|
|
410
|
+
}
|
|
411
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file could not be opened`, diagPath);
|
|
412
|
+
}
|
|
413
|
+
const destPath = join(stagedRootDir, ...relativePath.split('/'));
|
|
414
|
+
const destParentDir = dirname(destPath);
|
|
415
|
+
let tmpDestPath = null;
|
|
416
|
+
let createdTmp = false;
|
|
417
|
+
let parentFh;
|
|
418
|
+
let tmpHandle;
|
|
419
|
+
let finalHandle;
|
|
420
|
+
try {
|
|
421
|
+
const srcBefore = await srcHandle.stat();
|
|
422
|
+
if (srcBefore.isSymbolicLink()) {
|
|
423
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: symbolic links are forbidden`, diagPath);
|
|
424
|
+
}
|
|
425
|
+
if (!srcBefore.isFile()) {
|
|
426
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: path must be a regular file`, diagPath);
|
|
427
|
+
}
|
|
428
|
+
if (requireSingleLink && srcBefore.nlink !== 1) {
|
|
429
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: hardlinked file (nlink=${srcBefore.nlink}) is forbidden`, diagPath);
|
|
430
|
+
}
|
|
431
|
+
if (srcBefore.size > maxFileBytes) {
|
|
432
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file exceeds maximum ${maxFileBytes} bytes`, diagPath);
|
|
433
|
+
}
|
|
434
|
+
if (srcBefore.size > maxRemainingTotalBytes) {
|
|
435
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: aggregate workspace-mounted staged resources exceed maximum bytes`, diagPath);
|
|
436
|
+
}
|
|
437
|
+
if (srcBefore.dev !== lstatBefore.dev
|
|
438
|
+
|| srcBefore.ino !== lstatBefore.ino
|
|
439
|
+
|| srcBefore.size !== lstatBefore.size) {
|
|
440
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: workspace resource changed before pinning`, diagPath);
|
|
441
|
+
}
|
|
442
|
+
const currentUid = typeof process.getuid === 'function' ? process.getuid() : undefined;
|
|
443
|
+
await mkdir(destParentDir, { recursive: true, mode: 0o700 });
|
|
444
|
+
parentFh = await open(destParentDir, fsConstants.O_RDONLY | noFollow);
|
|
445
|
+
const parentSt = await parentFh.stat();
|
|
446
|
+
if (parentSt.isSymbolicLink() || !parentSt.isDirectory() || (currentUid !== undefined && parentSt.uid !== currentUid)) {
|
|
447
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: staged destination parent failed O_NOFOLLOW ownership check`, diagPath);
|
|
448
|
+
}
|
|
449
|
+
let existingDest = null;
|
|
450
|
+
try {
|
|
451
|
+
existingDest = await lstat(destPath);
|
|
452
|
+
}
|
|
453
|
+
catch (err) {
|
|
454
|
+
if (err?.code !== 'ENOENT') {
|
|
455
|
+
throw err;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (existingDest !== null) {
|
|
459
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: staged destination "${relativePath}" already exists`, diagPath);
|
|
460
|
+
}
|
|
461
|
+
const streamTmpPath = join(destParentDir, `.lw-stage-${randomBytes(12).toString('hex')}`);
|
|
462
|
+
tmpHandle = await open(streamTmpPath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_RDWR | noFollow, 0o600);
|
|
463
|
+
tmpDestPath = streamTmpPath;
|
|
464
|
+
createdTmp = true;
|
|
465
|
+
const createdStat = await tmpHandle.stat();
|
|
466
|
+
if (!createdStat.isFile()
|
|
467
|
+
|| createdStat.isSymbolicLink()
|
|
468
|
+
|| createdStat.nlink !== 1
|
|
469
|
+
|| (currentUid !== undefined && createdStat.uid !== currentUid)
|
|
470
|
+
|| (createdStat.dev === srcBefore.dev && createdStat.ino === srcBefore.ino)) {
|
|
471
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: staged temp destination failed initial identity/nlink check`, diagPath);
|
|
472
|
+
}
|
|
473
|
+
const streamSrcHash = createHash('sha256');
|
|
474
|
+
const userStream = createStreamScrubber(scrubber);
|
|
475
|
+
const strippedStream = createStreamScrubber(strippedScrubber);
|
|
476
|
+
const chunk = Buffer.allocUnsafe(Math.min(STREAM_CHUNK_BYTES, Math.max(1, srcBefore.size)));
|
|
477
|
+
const probe = Buffer.allocUnsafe(1);
|
|
478
|
+
let offset = 0;
|
|
479
|
+
while (offset < srcBefore.size) {
|
|
480
|
+
const toRead = Math.min(chunk.byteLength, srcBefore.size - offset);
|
|
481
|
+
const { bytesRead } = await srcHandle.read(chunk, 0, toRead, offset);
|
|
482
|
+
if (bytesRead <= 0)
|
|
483
|
+
break;
|
|
484
|
+
const slice = chunk.subarray(0, bytesRead);
|
|
485
|
+
streamSrcHash.update(slice);
|
|
486
|
+
userStream.assertChunkClean(slice, diagPath);
|
|
487
|
+
strippedStream.assertChunkClean(slice, diagPath);
|
|
488
|
+
let written = 0;
|
|
489
|
+
while (written < slice.byteLength) {
|
|
490
|
+
const { bytesWritten } = await tmpHandle.write(slice, written, slice.byteLength - written, offset + written);
|
|
491
|
+
if (bytesWritten <= 0) {
|
|
492
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: short write staging "${relativePath}"`, diagPath);
|
|
493
|
+
}
|
|
494
|
+
written += bytesWritten;
|
|
495
|
+
}
|
|
496
|
+
offset += bytesRead;
|
|
497
|
+
}
|
|
498
|
+
const { bytesRead: extraRead } = await srcHandle.read(probe, 0, 1, offset);
|
|
499
|
+
userStream.flushClean(diagPath);
|
|
500
|
+
strippedStream.flushClean(diagPath);
|
|
501
|
+
const srcAfter = await srcHandle.stat();
|
|
502
|
+
if (requireSingleLink && srcAfter.nlink !== 1) {
|
|
503
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: hardlinked file (nlink=${srcAfter.nlink}) detected after streaming`, diagPath);
|
|
504
|
+
}
|
|
505
|
+
if (offset !== srcBefore.size
|
|
506
|
+
|| extraRead !== 0
|
|
507
|
+
|| srcAfter.dev !== srcBefore.dev
|
|
508
|
+
|| srcAfter.ino !== srcBefore.ino
|
|
509
|
+
|| srcAfter.size !== srcBefore.size
|
|
510
|
+
|| srcAfter.mtimeMs !== srcBefore.mtimeMs
|
|
511
|
+
|| srcAfter.ctimeMs !== srcBefore.ctimeMs) {
|
|
512
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: file changed while streaming`, diagPath);
|
|
513
|
+
}
|
|
514
|
+
const srcSha256 = streamSrcHash.digest('hex');
|
|
515
|
+
await tmpHandle.sync();
|
|
516
|
+
const verifyHash = createHash('sha256');
|
|
517
|
+
let verifyOffset = 0;
|
|
518
|
+
while (verifyOffset < srcBefore.size) {
|
|
519
|
+
const toRead = Math.min(chunk.byteLength, srcBefore.size - verifyOffset);
|
|
520
|
+
const { bytesRead } = await tmpHandle.read(chunk, 0, toRead, verifyOffset);
|
|
521
|
+
if (bytesRead <= 0)
|
|
522
|
+
break;
|
|
523
|
+
verifyHash.update(chunk.subarray(0, bytesRead));
|
|
524
|
+
verifyOffset += bytesRead;
|
|
525
|
+
}
|
|
526
|
+
const { bytesRead: verifyExtra } = await tmpHandle.read(probe, 0, 1, verifyOffset);
|
|
527
|
+
const verifiedTmpStat = await tmpHandle.stat();
|
|
528
|
+
const srcAfterVerify = await srcHandle.stat();
|
|
529
|
+
const destSha256 = verifyHash.digest('hex');
|
|
530
|
+
if (requireSingleLink && srcAfterVerify.nlink !== 1) {
|
|
531
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: hardlinked file (nlink=${srcAfterVerify.nlink}) detected during verification`, diagPath);
|
|
532
|
+
}
|
|
533
|
+
if (verifyOffset !== srcBefore.size
|
|
534
|
+
|| verifyExtra !== 0
|
|
535
|
+
|| verifiedTmpStat.dev !== createdStat.dev
|
|
536
|
+
|| verifiedTmpStat.ino !== createdStat.ino
|
|
537
|
+
|| verifiedTmpStat.nlink !== 1
|
|
538
|
+
|| (currentUid !== undefined && verifiedTmpStat.uid !== currentUid)
|
|
539
|
+
|| verifiedTmpStat.size !== srcBefore.size
|
|
540
|
+
|| srcAfterVerify.dev !== srcBefore.dev
|
|
541
|
+
|| srcAfterVerify.ino !== srcBefore.ino
|
|
542
|
+
|| srcAfterVerify.size !== srcBefore.size
|
|
543
|
+
|| srcAfterVerify.mtimeMs !== srcBefore.mtimeMs
|
|
544
|
+
|| srcAfterVerify.ctimeMs !== srcBefore.ctimeMs
|
|
545
|
+
|| destSha256 !== srcSha256) {
|
|
546
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: staged destination failed post-stream sha256/stability verification`, diagPath);
|
|
547
|
+
}
|
|
548
|
+
await tmpHandle.chmod(0o444);
|
|
549
|
+
await tmpHandle.sync();
|
|
550
|
+
const sealedStat = await tmpHandle.stat();
|
|
551
|
+
if (!sealedStat.isFile()
|
|
552
|
+
|| sealedStat.isSymbolicLink()
|
|
553
|
+
|| sealedStat.nlink !== 1
|
|
554
|
+
|| (currentUid !== undefined && sealedStat.uid !== currentUid)
|
|
555
|
+
|| sealedStat.dev !== createdStat.dev
|
|
556
|
+
|| sealedStat.ino !== createdStat.ino
|
|
557
|
+
|| sealedStat.size !== srcBefore.size
|
|
558
|
+
|| (sealedStat.mode & 0o777) !== 0o444) {
|
|
559
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: staged destination failed post-fchmod verification`, diagPath);
|
|
560
|
+
}
|
|
561
|
+
await link(streamTmpPath, destPath);
|
|
562
|
+
await unlink(streamTmpPath);
|
|
563
|
+
createdTmp = false;
|
|
564
|
+
tmpDestPath = null;
|
|
565
|
+
const afterParentStat = await lstat(destParentDir);
|
|
566
|
+
if (afterParentStat.isSymbolicLink()
|
|
567
|
+
|| !afterParentStat.isDirectory()
|
|
568
|
+
|| afterParentStat.dev !== parentSt.dev
|
|
569
|
+
|| afterParentStat.ino !== parentSt.ino) {
|
|
570
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: staged destination parent changed during publish`, diagPath);
|
|
571
|
+
}
|
|
572
|
+
finalHandle = await open(destPath, fsConstants.O_RDONLY | noFollow);
|
|
573
|
+
const finalStat = await finalHandle.stat();
|
|
574
|
+
const tmpAfterPublishStat = await tmpHandle.stat();
|
|
575
|
+
await finalHandle.close();
|
|
576
|
+
finalHandle = undefined;
|
|
577
|
+
await tmpHandle.close();
|
|
578
|
+
tmpHandle = undefined;
|
|
579
|
+
if (finalStat.isSymbolicLink()
|
|
580
|
+
|| !finalStat.isFile()
|
|
581
|
+
|| finalStat.nlink !== 1
|
|
582
|
+
|| tmpAfterPublishStat.nlink !== 1
|
|
583
|
+
|| tmpAfterPublishStat.dev !== createdStat.dev
|
|
584
|
+
|| tmpAfterPublishStat.ino !== createdStat.ino
|
|
585
|
+
|| (currentUid !== undefined && finalStat.uid !== currentUid)
|
|
586
|
+
|| finalStat.dev !== createdStat.dev
|
|
587
|
+
|| finalStat.ino !== createdStat.ino
|
|
588
|
+
|| finalStat.size !== srcBefore.size
|
|
589
|
+
|| (finalStat.mode & 0o777) !== 0o444) {
|
|
590
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: staged destination failed post-publish verification`, diagPath);
|
|
591
|
+
}
|
|
592
|
+
return { destPath, sha256: srcSha256, byteLength: offset };
|
|
593
|
+
}
|
|
594
|
+
catch (error) {
|
|
595
|
+
if (finalHandle !== undefined) {
|
|
596
|
+
await finalHandle.close().catch(() => undefined);
|
|
597
|
+
}
|
|
598
|
+
if (tmpHandle !== undefined) {
|
|
599
|
+
await tmpHandle.close().catch(() => undefined);
|
|
600
|
+
}
|
|
601
|
+
if (createdTmp && tmpDestPath !== null) {
|
|
602
|
+
await unlink(tmpDestPath).catch(() => undefined);
|
|
603
|
+
}
|
|
604
|
+
if (error instanceof TaskpackError)
|
|
605
|
+
throw error;
|
|
606
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
607
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: failed to stage workspace resource "${relativePath}": ${detail}`, diagPath);
|
|
608
|
+
}
|
|
609
|
+
finally {
|
|
610
|
+
if (parentFh !== undefined) {
|
|
611
|
+
await parentFh.close().catch(() => undefined);
|
|
612
|
+
}
|
|
613
|
+
await srcHandle.close().catch(() => undefined);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
export async function cloneVerifiedStagedFileForChecks(options) {
|
|
617
|
+
const { verifiedSrcPath, checkStagedRootDir, relativePath, expectedByteLength, expectedSha256, diagPath, } = options;
|
|
618
|
+
const checkDestPath = join(checkStagedRootDir, ...relativePath.split('/'));
|
|
619
|
+
const checkParentDir = dirname(checkDestPath);
|
|
620
|
+
await mkdir(checkParentDir, { recursive: true, mode: 0o700 });
|
|
621
|
+
const noFollow = 'O_NOFOLLOW' in fsConstants ? fsConstants.O_NOFOLLOW : 0;
|
|
622
|
+
const currentUid = typeof process.getuid === 'function' ? process.getuid() : undefined;
|
|
623
|
+
const srcStat = await lstat(verifiedSrcPath);
|
|
624
|
+
if (srcStat.isSymbolicLink() || !srcStat.isFile() || srcStat.nlink !== 1 || srcStat.size !== expectedByteLength) {
|
|
625
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: verified staged file invalid before check projection`, diagPath);
|
|
626
|
+
}
|
|
627
|
+
const srcHandle = await open(verifiedSrcPath, fsConstants.O_RDONLY | noFollow);
|
|
628
|
+
const streamTmpPath = join(checkParentDir, `.lw-stage-${randomBytes(12).toString('hex')}`);
|
|
629
|
+
let createdStreamTmp = false;
|
|
630
|
+
let parentFh;
|
|
631
|
+
let tmpHandle;
|
|
632
|
+
let finalHandle;
|
|
633
|
+
try {
|
|
634
|
+
parentFh = await open(checkParentDir, fsConstants.O_RDONLY | noFollow);
|
|
635
|
+
const parentSt = await parentFh.stat();
|
|
636
|
+
if (parentSt.isSymbolicLink() || !parentSt.isDirectory() || (currentUid !== undefined && parentSt.uid !== currentUid)) {
|
|
637
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: check projection parent failed O_NOFOLLOW ownership check`, diagPath);
|
|
638
|
+
}
|
|
639
|
+
let existingCheckDest = null;
|
|
640
|
+
try {
|
|
641
|
+
existingCheckDest = await lstat(checkDestPath);
|
|
642
|
+
}
|
|
643
|
+
catch (err) {
|
|
644
|
+
if (err?.code !== 'ENOENT') {
|
|
645
|
+
throw err;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (existingCheckDest !== null) {
|
|
649
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: check projection destination "${relativePath}" already exists`, diagPath);
|
|
650
|
+
}
|
|
651
|
+
const srcBefore = await srcHandle.stat();
|
|
652
|
+
if (!srcBefore.isFile()
|
|
653
|
+
|| srcBefore.isSymbolicLink()
|
|
654
|
+
|| srcBefore.nlink !== 1
|
|
655
|
+
|| srcBefore.dev !== srcStat.dev
|
|
656
|
+
|| srcBefore.ino !== srcStat.ino
|
|
657
|
+
|| srcBefore.size !== expectedByteLength) {
|
|
658
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: verified staged file invalid before clone`, diagPath);
|
|
659
|
+
}
|
|
660
|
+
tmpHandle = await open(streamTmpPath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_RDWR | noFollow, 0o600);
|
|
661
|
+
createdStreamTmp = true;
|
|
662
|
+
const createdStat = await tmpHandle.stat();
|
|
663
|
+
if (!createdStat.isFile()
|
|
664
|
+
|| createdStat.isSymbolicLink()
|
|
665
|
+
|| createdStat.nlink !== 1
|
|
666
|
+
|| (currentUid !== undefined && createdStat.uid !== currentUid)
|
|
667
|
+
|| (createdStat.dev === srcBefore.dev && createdStat.ino === srcBefore.ino)) {
|
|
668
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: check resource failed temp identity/nlink check`, diagPath);
|
|
669
|
+
}
|
|
670
|
+
const hash = createHash('sha256');
|
|
671
|
+
const chunk = Buffer.allocUnsafe(Math.min(STREAM_CHUNK_BYTES, Math.max(1, expectedByteLength)));
|
|
672
|
+
const probe = Buffer.allocUnsafe(1);
|
|
673
|
+
let offset = 0;
|
|
674
|
+
while (offset < expectedByteLength) {
|
|
675
|
+
const toRead = Math.min(chunk.byteLength, expectedByteLength - offset);
|
|
676
|
+
const { bytesRead } = await srcHandle.read(chunk, 0, toRead, offset);
|
|
677
|
+
if (bytesRead <= 0)
|
|
678
|
+
break;
|
|
679
|
+
const slice = chunk.subarray(0, bytesRead);
|
|
680
|
+
hash.update(slice);
|
|
681
|
+
let written = 0;
|
|
682
|
+
while (written < slice.byteLength) {
|
|
683
|
+
const { bytesWritten } = await tmpHandle.write(slice, written, slice.byteLength - written, offset + written);
|
|
684
|
+
if (bytesWritten <= 0) {
|
|
685
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: short write cloning check resource`, diagPath);
|
|
686
|
+
}
|
|
687
|
+
written += bytesWritten;
|
|
688
|
+
}
|
|
689
|
+
offset += bytesRead;
|
|
690
|
+
}
|
|
691
|
+
const { bytesRead: extraRead } = await srcHandle.read(probe, 0, 1, offset);
|
|
692
|
+
const srcAfter = await srcHandle.stat();
|
|
693
|
+
if (offset !== expectedByteLength
|
|
694
|
+
|| extraRead !== 0
|
|
695
|
+
|| srcAfter.dev !== srcBefore.dev
|
|
696
|
+
|| srcAfter.ino !== srcBefore.ino
|
|
697
|
+
|| srcAfter.nlink !== 1
|
|
698
|
+
|| srcAfter.size !== expectedByteLength
|
|
699
|
+
|| srcAfter.mtimeMs !== srcBefore.mtimeMs
|
|
700
|
+
|| srcAfter.ctimeMs !== srcBefore.ctimeMs
|
|
701
|
+
|| hash.digest('hex') !== expectedSha256) {
|
|
702
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: check resource digest or stability mismatch during clone`, diagPath);
|
|
703
|
+
}
|
|
704
|
+
await tmpHandle.sync();
|
|
705
|
+
const verifyHash = createHash('sha256');
|
|
706
|
+
let verifyOffset = 0;
|
|
707
|
+
while (verifyOffset < expectedByteLength) {
|
|
708
|
+
const toRead = Math.min(chunk.byteLength, expectedByteLength - verifyOffset);
|
|
709
|
+
const { bytesRead } = await tmpHandle.read(chunk, 0, toRead, verifyOffset);
|
|
710
|
+
if (bytesRead <= 0)
|
|
711
|
+
break;
|
|
712
|
+
verifyHash.update(chunk.subarray(0, bytesRead));
|
|
713
|
+
verifyOffset += bytesRead;
|
|
714
|
+
}
|
|
715
|
+
const { bytesRead: verifyExtra } = await tmpHandle.read(probe, 0, 1, verifyOffset);
|
|
716
|
+
const verifiedTmpStat = await tmpHandle.stat();
|
|
717
|
+
const srcAfterVerify = await srcHandle.stat();
|
|
718
|
+
if (verifyOffset !== expectedByteLength
|
|
719
|
+
|| verifyExtra !== 0
|
|
720
|
+
|| verifiedTmpStat.dev !== createdStat.dev
|
|
721
|
+
|| verifiedTmpStat.ino !== createdStat.ino
|
|
722
|
+
|| verifiedTmpStat.nlink !== 1
|
|
723
|
+
|| (currentUid !== undefined && verifiedTmpStat.uid !== currentUid)
|
|
724
|
+
|| verifiedTmpStat.size !== expectedByteLength
|
|
725
|
+
|| srcAfterVerify.dev !== srcBefore.dev
|
|
726
|
+
|| srcAfterVerify.ino !== srcBefore.ino
|
|
727
|
+
|| srcAfterVerify.nlink !== 1
|
|
728
|
+
|| verifyHash.digest('hex') !== expectedSha256) {
|
|
729
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: check resource failed post-clone sha256 verification`, diagPath);
|
|
730
|
+
}
|
|
731
|
+
await tmpHandle.chmod(0o444);
|
|
732
|
+
await tmpHandle.sync();
|
|
733
|
+
const sealed = await tmpHandle.stat();
|
|
734
|
+
if (!sealed.isFile()
|
|
735
|
+
|| sealed.isSymbolicLink()
|
|
736
|
+
|| sealed.nlink !== 1
|
|
737
|
+
|| (currentUid !== undefined && sealed.uid !== currentUid)
|
|
738
|
+
|| sealed.dev !== createdStat.dev
|
|
739
|
+
|| sealed.ino !== createdStat.ino
|
|
740
|
+
|| sealed.size !== expectedByteLength
|
|
741
|
+
|| (sealed.mode & 0o777) !== 0o444) {
|
|
742
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: check resource failed post-fchmod verification`, diagPath);
|
|
743
|
+
}
|
|
744
|
+
await link(streamTmpPath, checkDestPath);
|
|
745
|
+
await unlink(streamTmpPath);
|
|
746
|
+
createdStreamTmp = false;
|
|
747
|
+
const afterParentStat = await lstat(checkParentDir);
|
|
748
|
+
if (afterParentStat.isSymbolicLink()
|
|
749
|
+
|| !afterParentStat.isDirectory()
|
|
750
|
+
|| afterParentStat.dev !== parentSt.dev
|
|
751
|
+
|| afterParentStat.ino !== parentSt.ino) {
|
|
752
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: check projection parent changed during publish`, diagPath);
|
|
753
|
+
}
|
|
754
|
+
finalHandle = await open(checkDestPath, fsConstants.O_RDONLY | noFollow);
|
|
755
|
+
const finalStat = await finalHandle.stat();
|
|
756
|
+
const tmpAfterPublishStat = await tmpHandle.stat();
|
|
757
|
+
await finalHandle.close();
|
|
758
|
+
finalHandle = undefined;
|
|
759
|
+
await tmpHandle.close();
|
|
760
|
+
tmpHandle = undefined;
|
|
761
|
+
if (finalStat.isSymbolicLink()
|
|
762
|
+
|| !finalStat.isFile()
|
|
763
|
+
|| finalStat.nlink !== 1
|
|
764
|
+
|| tmpAfterPublishStat.nlink !== 1
|
|
765
|
+
|| tmpAfterPublishStat.dev !== createdStat.dev
|
|
766
|
+
|| tmpAfterPublishStat.ino !== createdStat.ino
|
|
767
|
+
|| (currentUid !== undefined && finalStat.uid !== currentUid)
|
|
768
|
+
|| finalStat.dev !== createdStat.dev
|
|
769
|
+
|| finalStat.ino !== createdStat.ino
|
|
770
|
+
|| finalStat.size !== expectedByteLength
|
|
771
|
+
|| (finalStat.mode & 0o777) !== 0o444) {
|
|
772
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `${diagPath}: check resource failed post-publish verification`, diagPath);
|
|
773
|
+
}
|
|
774
|
+
return checkDestPath;
|
|
775
|
+
}
|
|
776
|
+
catch (error) {
|
|
777
|
+
if (finalHandle !== undefined) {
|
|
778
|
+
await finalHandle.close().catch(() => undefined);
|
|
779
|
+
}
|
|
780
|
+
if (tmpHandle !== undefined) {
|
|
781
|
+
await tmpHandle.close().catch(() => undefined);
|
|
782
|
+
}
|
|
783
|
+
if (createdStreamTmp) {
|
|
784
|
+
await unlink(streamTmpPath).catch(() => undefined);
|
|
785
|
+
}
|
|
786
|
+
throw error;
|
|
787
|
+
}
|
|
788
|
+
finally {
|
|
789
|
+
if (parentFh !== undefined) {
|
|
790
|
+
await parentFh.close().catch(() => undefined);
|
|
791
|
+
}
|
|
792
|
+
await srcHandle.close().catch(() => undefined);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
async function chmodTreeReadOnly(dirPath) {
|
|
796
|
+
const noFollow = 'O_NOFOLLOW' in fsConstants ? fsConstants.O_NOFOLLOW : 0;
|
|
797
|
+
const currentUid = typeof process.getuid === 'function' ? process.getuid() : undefined;
|
|
798
|
+
const entries = await readdir(dirPath, { withFileTypes: true });
|
|
799
|
+
for (const entry of entries) {
|
|
800
|
+
const child = join(dirPath, entry.name);
|
|
801
|
+
if (entry.isDirectory()) {
|
|
802
|
+
await chmodTreeReadOnly(child);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const fh = await open(dirPath, fsConstants.O_RDONLY | noFollow);
|
|
806
|
+
try {
|
|
807
|
+
const st = await fh.stat();
|
|
808
|
+
if (st.isSymbolicLink() || !st.isDirectory() || (currentUid !== undefined && st.uid !== currentUid)) {
|
|
809
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `staged directory "${dirPath}" failed O_NOFOLLOW directory/ownership check`, '/preflight');
|
|
810
|
+
}
|
|
811
|
+
await fh.chmod(0o555);
|
|
812
|
+
}
|
|
813
|
+
finally {
|
|
814
|
+
await fh.close();
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Restore directory write/execute bits (`0o700`) prior to recursive removal without ever
|
|
819
|
+
* calling `chmod` on regular files (preventing permission mutation of hardlinked inodes).
|
|
820
|
+
*/
|
|
821
|
+
async function makeWritableAndRemoveTree(dirPath) {
|
|
822
|
+
const restoreDirs = async (target) => {
|
|
823
|
+
const st = await lstat(target).catch(() => null);
|
|
824
|
+
if (st === null || !st.isDirectory())
|
|
825
|
+
return;
|
|
826
|
+
await chmod(target, 0o700).catch(() => undefined);
|
|
827
|
+
const entries = await readdir(target, { withFileTypes: true }).catch(() => []);
|
|
828
|
+
for (const entry of entries) {
|
|
829
|
+
await restoreDirs(join(target, entry.name));
|
|
830
|
+
}
|
|
831
|
+
};
|
|
832
|
+
await restoreDirs(dirPath);
|
|
833
|
+
await rm(dirPath, { recursive: true, force: true });
|
|
834
|
+
}
|
|
835
|
+
function scrubJsonValue(value, scrub, depth = 0) {
|
|
836
|
+
if (depth > PREFLIGHT_OUTPUT_MAX_DEPTH)
|
|
837
|
+
return value;
|
|
838
|
+
if (typeof value === 'string')
|
|
839
|
+
return scrub(value);
|
|
840
|
+
if (Array.isArray(value))
|
|
841
|
+
return value.map(item => scrubJsonValue(item, scrub, depth + 1));
|
|
842
|
+
if (value !== null && typeof value === 'object') {
|
|
843
|
+
const out = Object.create(null);
|
|
844
|
+
for (const [k, v] of Object.entries(value)) {
|
|
845
|
+
if (FORBIDDEN_OBJECT_KEYS.has(k))
|
|
846
|
+
continue;
|
|
847
|
+
const scrubbedKey = scrub(k);
|
|
848
|
+
if (FORBIDDEN_OBJECT_KEYS.has(scrubbedKey))
|
|
849
|
+
continue;
|
|
850
|
+
out[scrubbedKey] = scrubJsonValue(v, scrub, depth + 1);
|
|
851
|
+
}
|
|
852
|
+
return Object.freeze(out);
|
|
853
|
+
}
|
|
854
|
+
return value;
|
|
855
|
+
}
|
|
856
|
+
function parsePreflightOutputDocument(rawJson, scrub) {
|
|
857
|
+
if (!isPlainRecord(rawJson)) {
|
|
858
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight output must be a JSON object', '/preflight');
|
|
859
|
+
}
|
|
860
|
+
const allowedTopKeys = new Set(['disposition', 'reason', 'upstreams', 'stagedResources']);
|
|
861
|
+
for (const key of Object.keys(rawJson)) {
|
|
862
|
+
if (FORBIDDEN_OBJECT_KEYS.has(key) || !allowedTopKeys.has(key)) {
|
|
863
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `unknown preflight output field "${key}"`, `/preflight/${key}`);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
const rawDisp = rawJson['disposition'];
|
|
867
|
+
if (typeof rawDisp !== 'string' || !ALLOWED_DISPOSITIONS.has(rawDisp)) {
|
|
868
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight output disposition must be "candidate", "no_change", or "blocked"', '/preflight/disposition');
|
|
869
|
+
}
|
|
870
|
+
const disposition = rawDisp;
|
|
871
|
+
let reason = null;
|
|
872
|
+
if (rawJson['reason'] !== undefined && rawJson['reason'] !== null) {
|
|
873
|
+
if (typeof rawJson['reason'] !== 'string' || rawJson['reason'].length > 4096) {
|
|
874
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight output reason must be a string of at most 4096 characters', '/preflight/reason');
|
|
875
|
+
}
|
|
876
|
+
reason = scrub(rawJson['reason']);
|
|
877
|
+
}
|
|
878
|
+
const upstreams = [];
|
|
879
|
+
if (rawJson['upstreams'] !== undefined) {
|
|
880
|
+
const rawUpstreams = rawJson['upstreams'];
|
|
881
|
+
if (!Array.isArray(rawUpstreams) || rawUpstreams.length > PREFLIGHT_MAX_UPSTREAMS) {
|
|
882
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `preflight output upstreams must be an array of 0..${PREFLIGHT_MAX_UPSTREAMS} items`, '/preflight/upstreams');
|
|
883
|
+
}
|
|
884
|
+
const seenIds = new Set();
|
|
885
|
+
const allowedUpstreamKeys = new Set(['id', 'status', 'version', 'currentVersion', 'reason', 'metadata']);
|
|
886
|
+
for (const [idx, item] of rawUpstreams.entries()) {
|
|
887
|
+
const itemPath = `/preflight/upstreams/${idx}`;
|
|
888
|
+
if (!isPlainRecord(item)) {
|
|
889
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight upstream entry must be an object', itemPath);
|
|
890
|
+
}
|
|
891
|
+
for (const key of Object.keys(item)) {
|
|
892
|
+
if (FORBIDDEN_OBJECT_KEYS.has(key) || !allowedUpstreamKeys.has(key)) {
|
|
893
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `unknown preflight upstream field "${key}"`, `${itemPath}/${key}`);
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
const id = item['id'];
|
|
897
|
+
if (typeof id !== 'string' || id.trim().length === 0 || id.length > 128 || /[\0\r\n]/.test(id)) {
|
|
898
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight upstream id must be a non-empty string (1..128 chars)', `${itemPath}/id`);
|
|
899
|
+
}
|
|
900
|
+
if (seenIds.has(id)) {
|
|
901
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `duplicate preflight upstream id "${id}"`, `${itemPath}/id`);
|
|
902
|
+
}
|
|
903
|
+
seenIds.add(id);
|
|
904
|
+
const status = item['status'];
|
|
905
|
+
if (typeof status !== 'string' || !ALLOWED_UPSTREAM_STATUSES.has(status)) {
|
|
906
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight upstream status is invalid', `${itemPath}/status`);
|
|
907
|
+
}
|
|
908
|
+
const rawVersion = item['version'];
|
|
909
|
+
if (rawVersion !== undefined && (typeof rawVersion !== 'string' || rawVersion.trim().length === 0 || rawVersion.length > 256 || /[\0\r\n]/.test(rawVersion))) {
|
|
910
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight upstream version must be a non-empty string (1..256 chars)', `${itemPath}/version`);
|
|
911
|
+
}
|
|
912
|
+
const rawCurrent = item['currentVersion'];
|
|
913
|
+
if (rawCurrent !== undefined && (typeof rawCurrent !== 'string' || rawCurrent.trim().length === 0 || rawCurrent.length > 256 || /[\0\r\n]/.test(rawCurrent))) {
|
|
914
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight upstream currentVersion must be a non-empty string (1..256 chars)', `${itemPath}/currentVersion`);
|
|
915
|
+
}
|
|
916
|
+
const rawReason = item['reason'];
|
|
917
|
+
if (rawReason !== undefined && (typeof rawReason !== 'string' || rawReason.length > 2048)) {
|
|
918
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight upstream reason must be a string (<= 2048 chars)', `${itemPath}/reason`);
|
|
919
|
+
}
|
|
920
|
+
let metadata;
|
|
921
|
+
if (item['metadata'] !== undefined) {
|
|
922
|
+
if (!isPlainRecord(item['metadata'])) {
|
|
923
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight upstream metadata must be a plain object', `${itemPath}/metadata`);
|
|
924
|
+
}
|
|
925
|
+
const entries = Object.entries(item['metadata']);
|
|
926
|
+
if (entries.length > PREFLIGHT_MAX_METADATA_KEYS) {
|
|
927
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `preflight upstream metadata exceeds ${PREFLIGHT_MAX_METADATA_KEYS} entries`, `${itemPath}/metadata`);
|
|
928
|
+
}
|
|
929
|
+
const cleaned = scrubJsonValue(item['metadata'], scrub, 0);
|
|
930
|
+
if (Buffer.byteLength(JSON.stringify(cleaned), 'utf8') > PREFLIGHT_MAX_METADATA_BYTES) {
|
|
931
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `preflight upstream metadata exceeds ${PREFLIGHT_MAX_METADATA_BYTES} bytes`, `${itemPath}/metadata`);
|
|
932
|
+
}
|
|
933
|
+
metadata = cleaned;
|
|
934
|
+
}
|
|
935
|
+
const typedStatus = status;
|
|
936
|
+
const normalizedVersions = normalizeHeldBackVersions(typedStatus, rawVersion, rawCurrent, undefined);
|
|
937
|
+
upstreams.push(Object.freeze({
|
|
938
|
+
upstreamId: id,
|
|
939
|
+
status: typedStatus,
|
|
940
|
+
...(normalizedVersions.version !== undefined ? { version: normalizedVersions.version } : {}),
|
|
941
|
+
...(rawCurrent !== undefined ? { currentVersion: rawCurrent } : {}),
|
|
942
|
+
...(normalizedVersions.targetVersion !== undefined ? { targetVersion: normalizedVersions.targetVersion } : {}),
|
|
943
|
+
...(rawReason !== undefined ? { reason: scrub(rawReason) } : {}),
|
|
944
|
+
...(metadata !== undefined ? { metadata } : {}),
|
|
945
|
+
}));
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
const stagedResources = [];
|
|
949
|
+
if (rawJson['stagedResources'] !== undefined) {
|
|
950
|
+
const rawStaged = rawJson['stagedResources'];
|
|
951
|
+
if (!Array.isArray(rawStaged) || rawStaged.length > PREFLIGHT_MAX_STAGED_RESOURCES) {
|
|
952
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `preflight output stagedResources must be an array of 0..${PREFLIGHT_MAX_STAGED_RESOURCES} items`, '/preflight/stagedResources');
|
|
953
|
+
}
|
|
954
|
+
const seenIds = new Set();
|
|
955
|
+
const allowedStagedKeys = new Set(['id', 'kind', 'path', 'mount', 'exposeToChecks']);
|
|
956
|
+
for (const [idx, item] of rawStaged.entries()) {
|
|
957
|
+
const itemPath = `/preflight/stagedResources/${idx}`;
|
|
958
|
+
if (!isPlainRecord(item)) {
|
|
959
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight stagedResource entry must be an object', itemPath);
|
|
960
|
+
}
|
|
961
|
+
for (const key of Object.keys(item)) {
|
|
962
|
+
if (FORBIDDEN_OBJECT_KEYS.has(key) || !allowedStagedKeys.has(key)) {
|
|
963
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `unknown stagedResource field "${key}"`, `${itemPath}/${key}`);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
const id = item['id'];
|
|
967
|
+
if (typeof id !== 'string' || !IDENTIFIER_PATTERN.test(id)) {
|
|
968
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'stagedResource id must be a valid identifier', `${itemPath}/id`);
|
|
969
|
+
}
|
|
970
|
+
if (seenIds.has(id)) {
|
|
971
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `duplicate stagedResource id "${id}"`, `${itemPath}/id`);
|
|
972
|
+
}
|
|
973
|
+
seenIds.add(id);
|
|
974
|
+
const kindRaw = item['kind'];
|
|
975
|
+
if (typeof kindRaw !== 'string' || !ALLOWED_STAGED_KINDS.has(kindRaw)) {
|
|
976
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'stagedResource kind must be "instruction", "skill", or "document"', `${itemPath}/kind`);
|
|
977
|
+
}
|
|
978
|
+
const kind = kindRaw;
|
|
979
|
+
const pathVal = item['path'];
|
|
980
|
+
if (typeof pathVal !== 'string' || pathVal.length === 0 || pathVal.length > 1024 || /[\0\r\n]/.test(pathVal)) {
|
|
981
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'stagedResource path must be a non-empty string (1..1024 chars)', `${itemPath}/path`);
|
|
982
|
+
}
|
|
983
|
+
let mount;
|
|
984
|
+
if (item['mount'] === undefined) {
|
|
985
|
+
mount = kind === 'document' ? 'workspace' : 'prompt';
|
|
986
|
+
}
|
|
987
|
+
else if (typeof item['mount'] === 'string' && ALLOWED_STAGED_MOUNTS.has(item['mount'])) {
|
|
988
|
+
mount = item['mount'];
|
|
989
|
+
}
|
|
990
|
+
else {
|
|
991
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'stagedResource mount must be "prompt" or "workspace"', `${itemPath}/mount`);
|
|
992
|
+
}
|
|
993
|
+
let exposeToChecks = false;
|
|
994
|
+
if (item['exposeToChecks'] !== undefined) {
|
|
995
|
+
if (typeof item['exposeToChecks'] !== 'boolean') {
|
|
996
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'stagedResource exposeToChecks must be a boolean', `${itemPath}/exposeToChecks`);
|
|
997
|
+
}
|
|
998
|
+
exposeToChecks = item['exposeToChecks'];
|
|
999
|
+
}
|
|
1000
|
+
stagedResources.push(Object.freeze({
|
|
1001
|
+
id,
|
|
1002
|
+
kind,
|
|
1003
|
+
path: pathVal,
|
|
1004
|
+
mount,
|
|
1005
|
+
exposeToChecks,
|
|
1006
|
+
}));
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
return {
|
|
1010
|
+
disposition,
|
|
1011
|
+
reason,
|
|
1012
|
+
upstreams: Object.freeze(upstreams),
|
|
1013
|
+
stagedResources: Object.freeze(stagedResources),
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
function resolveScriptInvocation(scriptFullPath, fileMode) {
|
|
1017
|
+
const lower = scriptFullPath.toLowerCase();
|
|
1018
|
+
if (lower.endsWith('.mjs') || lower.endsWith('.js') || lower.endsWith('.cjs')) {
|
|
1019
|
+
return { command: process.execPath, args: [scriptFullPath] };
|
|
1020
|
+
}
|
|
1021
|
+
if ((fileMode & 0o111) !== 0) {
|
|
1022
|
+
return { command: scriptFullPath, args: [] };
|
|
1023
|
+
}
|
|
1024
|
+
return { command: '/bin/sh', args: [scriptFullPath] };
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Format a compact path, CAS URI, and SHA-256 manifest summary of workspace-mounted staged resources
|
|
1028
|
+
* suitable for agent prompts without ever reading or concatenating file contents.
|
|
1029
|
+
*/
|
|
1030
|
+
export function formatWorkspaceResourcesManifest(resources, stagedRootDir, scrubber) {
|
|
1031
|
+
if (resources.length === 0)
|
|
1032
|
+
return 'workspaceResources: none';
|
|
1033
|
+
const normalizedRoot = typeof stagedRootDir === 'string' && stagedRootDir.trim().length > 0
|
|
1034
|
+
? resolve(stagedRootDir)
|
|
1035
|
+
: null;
|
|
1036
|
+
const scrub = scrubber !== undefined ? (text) => scrubber.scrub(text) : (text) => text;
|
|
1037
|
+
return resources
|
|
1038
|
+
.map(res => {
|
|
1039
|
+
const readOnlyPointer = normalizedRoot !== null
|
|
1040
|
+
? ` readOnlyPath=${scrub(join(normalizedRoot, ...res.relativePath.split('/')))}`
|
|
1041
|
+
: '';
|
|
1042
|
+
const uriVal = typeof res.uri === 'string' && res.uri.length > 0 ? res.uri : `cas://sha256/${res.sha256}`;
|
|
1043
|
+
return `- ${res.id} (${res.kind}): path=${scrub(res.relativePath)}${readOnlyPointer} uri=${uriVal} bytes=${res.byteLength} sha256=${res.sha256} exposeToChecks=${String(res.exposeToChecks)}`;
|
|
1044
|
+
})
|
|
1045
|
+
.join('\n');
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Execute a manifest-declared `spec.preflight` script on the host with fail-closed preconditions:
|
|
1049
|
+
* - Requires explicit `authorized: true` and `SecretScrubber` setup before touching files or spawning.
|
|
1050
|
+
* - Enforces dual-key execution authority via `validateExecutionAuthority` and `pinDigests` lockfile verification.
|
|
1051
|
+
* - Resolves `spec.preflight.script` strictly inside `repositoryRoot` (no symlinks) and records its SHA-256 digest.
|
|
1052
|
+
* - Strips all forbidden GitHub, Loopwright, CI/loader, manifest-declared, and provider credentials regardless of
|
|
1053
|
+
* `allowHostEnv` or `spec.preflight.env`.
|
|
1054
|
+
* - Enforces `nlink === 1` on `LOOPWRIGHT_PREFLIGHT_OUT` and `LOOPWRIGHT_STAGING_DIR` resources, parses output
|
|
1055
|
+
* strictly, and partitions `stagedResources` into UTF-8 `promptResources` (64 KiB / 256 KiB) versus CoW/streamed
|
|
1056
|
+
* read-only disk `workspaceResources` (`stagedDir` and `checkStagedDir`, preserving `nlink === 1`).
|
|
1057
|
+
*/
|
|
1058
|
+
export async function runTaskpackPreflight(options) {
|
|
1059
|
+
if (options.authorized !== true) {
|
|
1060
|
+
throw new TaskpackError('WEBHOOK_ACTOR_UNAUTHORIZED', 'spec.preflight refuses to execute without prior actor authorization (authorized: true)', '/spec/preflight');
|
|
1061
|
+
}
|
|
1062
|
+
if (!(options.scrubber instanceof SecretScrubber)) {
|
|
1063
|
+
throw new TaskpackError('TASKPACK_HOST_BINDING_INVALID', 'spec.preflight requires an initialized SecretScrubber instance', '/spec/preflight');
|
|
1064
|
+
}
|
|
1065
|
+
validateExecutionAuthority(options.manifest.spec.execution, options.hostPolicy);
|
|
1066
|
+
const preflightDecl = options.manifest.spec.preflight;
|
|
1067
|
+
if (preflightDecl === undefined) {
|
|
1068
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'manifest does not declare spec.preflight', '/spec/preflight');
|
|
1069
|
+
}
|
|
1070
|
+
if (preflightDecl.timeoutSeconds !== undefined) {
|
|
1071
|
+
if (typeof preflightDecl.timeoutSeconds !== 'number'
|
|
1072
|
+
|| !Number.isSafeInteger(preflightDecl.timeoutSeconds)
|
|
1073
|
+
|| preflightDecl.timeoutSeconds < 1
|
|
1074
|
+
|| preflightDecl.timeoutSeconds > PREFLIGHT_MAX_TIMEOUT_SECONDS) {
|
|
1075
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `spec.preflight.timeoutSeconds must be an integer within 1..${PREFLIGHT_MAX_TIMEOUT_SECONDS}`, '/spec/preflight/timeoutSeconds');
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
const declaredTimeoutSec = preflightDecl.timeoutSeconds ?? PREFLIGHT_DEFAULT_TIMEOUT_SECONDS;
|
|
1079
|
+
const timeoutMs = options.timeoutMs !== undefined
|
|
1080
|
+
? options.timeoutMs
|
|
1081
|
+
: declaredTimeoutSec * 1000;
|
|
1082
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > PREFLIGHT_MAX_TIMEOUT_SECONDS * 1000) {
|
|
1083
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', `preflight timeoutMs must be within 1..${PREFLIGHT_MAX_TIMEOUT_SECONDS * 1000}`, '/spec/preflight/timeoutSeconds');
|
|
1084
|
+
}
|
|
1085
|
+
const scriptRelPath = normalizeRelativePath(preflightDecl.script, '/spec/preflight/script');
|
|
1086
|
+
const repoRoot = await resolveSafeDirectory(options.repositoryRoot, 'repositoryRoot');
|
|
1087
|
+
if (options.manifest.spec.execution?.digests.pinDigests === true) {
|
|
1088
|
+
await assertDigestLockfileVerified(options.repositoryRoot, options.manifest);
|
|
1089
|
+
}
|
|
1090
|
+
const scriptLookup = await resolveNoSymlinkFileInRoot(repoRoot.resolved, repoRoot.real, scriptRelPath, '/spec/preflight/script');
|
|
1091
|
+
if (!scriptLookup.exists) {
|
|
1092
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `preflight script "${scriptRelPath}" does not exist inside repository root`, '/spec/preflight/script');
|
|
1093
|
+
}
|
|
1094
|
+
const scriptStat = await lstat(scriptLookup.fullPath);
|
|
1095
|
+
if (scriptStat.isSymbolicLink()) {
|
|
1096
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', `preflight script "${scriptRelPath}" must not be a symbolic link`, '/spec/preflight/script');
|
|
1097
|
+
}
|
|
1098
|
+
if (!scriptStat.isFile()) {
|
|
1099
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `preflight script "${scriptRelPath}" must be a regular file`, '/spec/preflight/script');
|
|
1100
|
+
}
|
|
1101
|
+
const scriptSha256 = await computeFileDigest(options.repositoryRoot, scriptRelPath);
|
|
1102
|
+
let baseTemp;
|
|
1103
|
+
if (options.tempRoot !== undefined) {
|
|
1104
|
+
const resolvedTemp = await resolveSafeDirectory(options.tempRoot, 'tempRoot', 'ACTION_INPUT_INVALID');
|
|
1105
|
+
baseTemp = resolvedTemp.real;
|
|
1106
|
+
}
|
|
1107
|
+
else {
|
|
1108
|
+
baseTemp = tmpdir();
|
|
1109
|
+
}
|
|
1110
|
+
let workDir;
|
|
1111
|
+
try {
|
|
1112
|
+
workDir = await mkdtemp(join(baseTemp, 'loopwright-preflight-'));
|
|
1113
|
+
await chmod(workDir, 0o700);
|
|
1114
|
+
}
|
|
1115
|
+
catch (error) {
|
|
1116
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1117
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', `failed to create preflight work directory: ${detail}`, '/spec/preflight');
|
|
1118
|
+
}
|
|
1119
|
+
let stagedDir = null;
|
|
1120
|
+
let checkStagedDir = null;
|
|
1121
|
+
let keepStagedDirs = false;
|
|
1122
|
+
try {
|
|
1123
|
+
const scratchHome = join(workDir, 'home');
|
|
1124
|
+
const scratchTmp = join(workDir, 'tmp');
|
|
1125
|
+
const stagingInputDir = join(workDir, 'staging-input');
|
|
1126
|
+
const outputJsonPath = join(workDir, 'preflight-out.json');
|
|
1127
|
+
await mkdir(scratchHome, { mode: 0o700 });
|
|
1128
|
+
await mkdir(scratchTmp, { mode: 0o700 });
|
|
1129
|
+
await mkdir(stagingInputDir, { mode: 0o700 });
|
|
1130
|
+
const stagingRoot = await resolveSafeDirectory(stagingInputDir, 'preflight staging directory');
|
|
1131
|
+
const manifestSecretEnvNames = new Set(collectManifestSecretEnvNames(options.manifest));
|
|
1132
|
+
if (options.excludedEnvNames !== undefined) {
|
|
1133
|
+
for (const envName of options.excludedEnvNames) {
|
|
1134
|
+
if (typeof envName === 'string' && envName.length > 0) {
|
|
1135
|
+
manifestSecretEnvNames.add(envName);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
}
|
|
1139
|
+
const hostEnv = options.env ?? process.env;
|
|
1140
|
+
const strippedScrubber = new SecretScrubber();
|
|
1141
|
+
for (const [key, val] of Object.entries(hostEnv)) {
|
|
1142
|
+
if (typeof val === 'string' && val.length > 0 && isCredentialPreflightEnvName(key, manifestSecretEnvNames)) {
|
|
1143
|
+
strippedScrubber.register(val);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
for (const val of Object.values(options.brokeredEnv ?? {})) {
|
|
1147
|
+
if (typeof val === 'string' && val.length > 0) {
|
|
1148
|
+
strippedScrubber.register(val);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
const scrubText = (text) => strippedScrubber.scrub(options.scrubber.scrub(text));
|
|
1152
|
+
const caps = options.manifest.spec.execution?.capabilities;
|
|
1153
|
+
const allowHostEnv = caps?.allowHostEnv === true;
|
|
1154
|
+
const allowHostPath = caps?.allowHostPath === true;
|
|
1155
|
+
const childEnv = {};
|
|
1156
|
+
if (allowHostEnv) {
|
|
1157
|
+
for (const [key, val] of Object.entries(hostEnv)) {
|
|
1158
|
+
if (typeof val !== 'string')
|
|
1159
|
+
continue;
|
|
1160
|
+
if (isForbiddenPreflightEnvName(key, manifestSecretEnvNames))
|
|
1161
|
+
continue;
|
|
1162
|
+
childEnv[key] = val;
|
|
1163
|
+
}
|
|
1164
|
+
if (!allowHostPath) {
|
|
1165
|
+
childEnv['PATH'] = PREFLIGHT_SAFE_DEFAULT_PATH;
|
|
1166
|
+
}
|
|
1167
|
+
else if (typeof childEnv['PATH'] !== 'string') {
|
|
1168
|
+
childEnv['PATH'] = PREFLIGHT_SAFE_DEFAULT_PATH;
|
|
1169
|
+
}
|
|
1170
|
+
if (typeof childEnv['HOME'] !== 'string')
|
|
1171
|
+
childEnv['HOME'] = scratchHome;
|
|
1172
|
+
if (typeof childEnv['TMPDIR'] !== 'string')
|
|
1173
|
+
childEnv['TMPDIR'] = scratchTmp;
|
|
1174
|
+
}
|
|
1175
|
+
else {
|
|
1176
|
+
childEnv['PATH'] = allowHostPath && typeof hostEnv['PATH'] === 'string'
|
|
1177
|
+
? hostEnv['PATH']
|
|
1178
|
+
: PREFLIGHT_SAFE_DEFAULT_PATH;
|
|
1179
|
+
childEnv['HOME'] = scratchHome;
|
|
1180
|
+
childEnv['TMPDIR'] = scratchTmp;
|
|
1181
|
+
childEnv['LANG'] = 'C.UTF-8';
|
|
1182
|
+
childEnv['LC_ALL'] = 'C.UTF-8';
|
|
1183
|
+
for (const envName of preflightDecl.env ?? []) {
|
|
1184
|
+
if (isForbiddenPreflightEnvName(envName, manifestSecretEnvNames)) {
|
|
1185
|
+
continue;
|
|
1186
|
+
}
|
|
1187
|
+
const val = hostEnv[envName];
|
|
1188
|
+
if (typeof val === 'string') {
|
|
1189
|
+
childEnv[envName] = val;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
if (options.brokeredEnv !== undefined) {
|
|
1194
|
+
for (const [key, val] of Object.entries(options.brokeredEnv)) {
|
|
1195
|
+
if (RESERVED_PREFLIGHT_INJECTED_VARS.has(key.toUpperCase()))
|
|
1196
|
+
continue;
|
|
1197
|
+
childEnv[key] = val;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
childEnv['LOOPWRIGHT_PREFLIGHT_OUT'] = outputJsonPath;
|
|
1201
|
+
childEnv['LOOPWRIGHT_REPO_ROOT'] = repoRoot.real;
|
|
1202
|
+
childEnv['LOOPWRIGHT_STAGING_DIR'] = stagingRoot.real;
|
|
1203
|
+
const invocation = resolveScriptInvocation(scriptLookup.fullPath, scriptStat.mode);
|
|
1204
|
+
const startMs = Date.now();
|
|
1205
|
+
const execResult = await new Promise((resolvePromise, rejectPromise) => {
|
|
1206
|
+
if (options.signal?.aborted) {
|
|
1207
|
+
rejectPromise(new TaskpackError('SANDBOX_EXECUTION_FAILED', 'preflight execution aborted before start', '/spec/preflight'));
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
const child = spawn(invocation.command, [...invocation.args], {
|
|
1211
|
+
cwd: repoRoot.real,
|
|
1212
|
+
env: childEnv,
|
|
1213
|
+
detached: true,
|
|
1214
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
1215
|
+
});
|
|
1216
|
+
const stdoutBuf = new BoundedStreamBuffer(PREFLIGHT_MAX_STDIO_BYTES);
|
|
1217
|
+
const stderrBuf = new BoundedStreamBuffer(PREFLIGHT_MAX_STDIO_BYTES);
|
|
1218
|
+
let timedOut = false;
|
|
1219
|
+
let aborted = false;
|
|
1220
|
+
let settled = false;
|
|
1221
|
+
let exitCode = null;
|
|
1222
|
+
let exitSignal = null;
|
|
1223
|
+
let drainTimer;
|
|
1224
|
+
const killTree = () => {
|
|
1225
|
+
if (child.pid !== undefined) {
|
|
1226
|
+
try {
|
|
1227
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
1228
|
+
return;
|
|
1229
|
+
}
|
|
1230
|
+
catch {
|
|
1231
|
+
// Fall through to direct kill.
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
try {
|
|
1235
|
+
child.kill('SIGKILL');
|
|
1236
|
+
}
|
|
1237
|
+
catch {
|
|
1238
|
+
// Child already exited.
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
const destroyStreams = () => {
|
|
1242
|
+
child.stdout.destroy();
|
|
1243
|
+
child.stderr.destroy();
|
|
1244
|
+
};
|
|
1245
|
+
const cleanupListeners = () => {
|
|
1246
|
+
clearTimeout(timer);
|
|
1247
|
+
if (drainTimer !== undefined) {
|
|
1248
|
+
clearTimeout(drainTimer);
|
|
1249
|
+
drainTimer = undefined;
|
|
1250
|
+
}
|
|
1251
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
1252
|
+
};
|
|
1253
|
+
const finish = (code, sig) => {
|
|
1254
|
+
if (settled)
|
|
1255
|
+
return;
|
|
1256
|
+
settled = true;
|
|
1257
|
+
killTree();
|
|
1258
|
+
cleanupListeners();
|
|
1259
|
+
resolvePromise({
|
|
1260
|
+
exitCode: code,
|
|
1261
|
+
signal: sig,
|
|
1262
|
+
timedOut,
|
|
1263
|
+
aborted,
|
|
1264
|
+
stdout: scrubText(stdoutBuf.toString()),
|
|
1265
|
+
stderr: scrubText(stderrBuf.toString()),
|
|
1266
|
+
});
|
|
1267
|
+
};
|
|
1268
|
+
const armDrainDestroy = () => {
|
|
1269
|
+
if (drainTimer !== undefined)
|
|
1270
|
+
return;
|
|
1271
|
+
drainTimer = setTimeout(() => {
|
|
1272
|
+
destroyStreams();
|
|
1273
|
+
finish(exitCode, exitSignal);
|
|
1274
|
+
}, STDIO_DRAIN_GRACE_MS);
|
|
1275
|
+
drainTimer.unref?.();
|
|
1276
|
+
};
|
|
1277
|
+
const onAbort = () => {
|
|
1278
|
+
aborted = true;
|
|
1279
|
+
killTree();
|
|
1280
|
+
armDrainDestroy();
|
|
1281
|
+
};
|
|
1282
|
+
options.signal?.addEventListener('abort', onAbort, { once: true });
|
|
1283
|
+
const timer = setTimeout(() => {
|
|
1284
|
+
timedOut = true;
|
|
1285
|
+
killTree();
|
|
1286
|
+
armDrainDestroy();
|
|
1287
|
+
}, timeoutMs);
|
|
1288
|
+
timer.unref?.();
|
|
1289
|
+
child.stdout.on('data', (chunk) => stdoutBuf.append(chunk));
|
|
1290
|
+
child.stderr.on('data', (chunk) => stderrBuf.append(chunk));
|
|
1291
|
+
child.on('error', err => {
|
|
1292
|
+
if (settled)
|
|
1293
|
+
return;
|
|
1294
|
+
settled = true;
|
|
1295
|
+
killTree();
|
|
1296
|
+
cleanupListeners();
|
|
1297
|
+
rejectPromise(new TaskpackError('SANDBOX_EXECUTION_FAILED', `preflight script failed to spawn: ${scrubText(err.message)}`, '/spec/preflight'));
|
|
1298
|
+
});
|
|
1299
|
+
child.on('exit', (code, sig) => {
|
|
1300
|
+
exitCode = code;
|
|
1301
|
+
exitSignal = sig;
|
|
1302
|
+
killTree();
|
|
1303
|
+
armDrainDestroy();
|
|
1304
|
+
});
|
|
1305
|
+
child.on('close', (code, sig) => finish(code, sig));
|
|
1306
|
+
});
|
|
1307
|
+
const durationMs = Math.max(0, Date.now() - startMs);
|
|
1308
|
+
if (execResult.aborted || options.signal?.aborted) {
|
|
1309
|
+
throw new TaskpackError('SANDBOX_EXECUTION_FAILED', 'preflight script execution aborted', '/spec/preflight');
|
|
1310
|
+
}
|
|
1311
|
+
if (execResult.timedOut) {
|
|
1312
|
+
const detail = execResult.stderr.trim() || execResult.stdout.trim();
|
|
1313
|
+
throw new TaskpackError('SANDBOX_EXECUTION_FAILED', `preflight script timed out after ${timeoutMs}ms${detail.length > 0 ? `: ${detail}` : ''}`, '/spec/preflight');
|
|
1314
|
+
}
|
|
1315
|
+
if (execResult.exitCode !== 0) {
|
|
1316
|
+
const detail = execResult.stderr.trim() || execResult.stdout.trim();
|
|
1317
|
+
throw new TaskpackError('SANDBOX_EXECUTION_FAILED', `preflight script exited with status ${String(execResult.exitCode)}${execResult.signal ? ` (signal ${execResult.signal})` : ''}${detail.length > 0 ? `: ${detail}` : ''}`, '/spec/preflight');
|
|
1318
|
+
}
|
|
1319
|
+
const outBytes = await openAndReadNoFollowBoundedFile(outputJsonPath, PREFLIGHT_MAX_OUTPUT_JSON_BYTES, '/preflight/output', { requireSingleLink: true });
|
|
1320
|
+
if (outBytes.includes(0)) {
|
|
1321
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight output JSON must not contain NUL bytes', '/preflight/output');
|
|
1322
|
+
}
|
|
1323
|
+
let outText;
|
|
1324
|
+
try {
|
|
1325
|
+
outText = new TextDecoder('utf-8', { fatal: true }).decode(outBytes);
|
|
1326
|
+
}
|
|
1327
|
+
catch {
|
|
1328
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', 'preflight output JSON is not valid UTF-8', '/preflight/output');
|
|
1329
|
+
}
|
|
1330
|
+
const parsedJson = parseJsonSubset(outText, {
|
|
1331
|
+
maxNodes: 8_192,
|
|
1332
|
+
maxDepth: PREFLIGHT_OUTPUT_MAX_DEPTH,
|
|
1333
|
+
maxCollection: 256,
|
|
1334
|
+
maxString: 32_768,
|
|
1335
|
+
diagPath: '/preflight',
|
|
1336
|
+
});
|
|
1337
|
+
const parsedOutput = parsePreflightOutputDocument(parsedJson, scrubText);
|
|
1338
|
+
const enrichedUpstreams = attachUpstreamContext(parsedOutput.upstreams, options.manifest.spec.upstreams);
|
|
1339
|
+
const repoBaselines = options.manifest.spec.upstreamGroups !== undefined && options.manifest.spec.upstreamGroups.length > 0
|
|
1340
|
+
? await loadRepositoryBaselineVersions(options.manifest, options.repositoryRoot)
|
|
1341
|
+
: undefined;
|
|
1342
|
+
const hadAvailableBeforeGroups = enrichedUpstreams.some(record => record.status === 'available');
|
|
1343
|
+
const groupedUpstreams = applyUpstreamGroups(enrichedUpstreams, options.manifest.spec.upstreamGroups, repoBaselines);
|
|
1344
|
+
const hasAvailableAfterGroups = groupedUpstreams.some(record => record.status === 'available');
|
|
1345
|
+
let effectiveDisposition = parsedOutput.disposition;
|
|
1346
|
+
let effectiveReason = parsedOutput.reason;
|
|
1347
|
+
if (effectiveDisposition === 'candidate' && hadAvailableBeforeGroups && !hasAvailableAfterGroups) {
|
|
1348
|
+
const reevaluated = evaluateUpstreamIntakeDisposition(groupedUpstreams);
|
|
1349
|
+
effectiveDisposition = reevaluated.disposition;
|
|
1350
|
+
effectiveReason = reevaluated.reason;
|
|
1351
|
+
}
|
|
1352
|
+
const overlayMaxBytes = options.manifest.spec.limits?.overlay?.maxBytes ?? 0;
|
|
1353
|
+
const maxWorkspaceFileBytes = Math.min(OVERLAY_LIMITS.maxMaxBytes, Math.max(PREFLIGHT_MAX_WORKSPACE_RESOURCE_BYTES, overlayMaxBytes));
|
|
1354
|
+
const maxWorkspaceTotalBytes = Math.min(OVERLAY_LIMITS.maxMaxBytes, Math.max(PREFLIGHT_MAX_WORKSPACE_RESOURCES_TOTAL_BYTES, overlayMaxBytes));
|
|
1355
|
+
const promptResources = [];
|
|
1356
|
+
const workspaceResources = [];
|
|
1357
|
+
let promptTotalBytes = 0;
|
|
1358
|
+
let workspaceTotalBytes = 0;
|
|
1359
|
+
const seenWorkspaceRelPaths = new Set();
|
|
1360
|
+
const disableReflink = options.disableReflink === true;
|
|
1361
|
+
for (const [idx, decl] of parsedOutput.stagedResources.entries()) {
|
|
1362
|
+
if (options.signal?.aborted) {
|
|
1363
|
+
throw new TaskpackError('SANDBOX_EXECUTION_FAILED', 'preflight script execution aborted during resource staging', '/spec/preflight');
|
|
1364
|
+
}
|
|
1365
|
+
const diagPath = `/preflight/stagedResources/${idx}`;
|
|
1366
|
+
const resolvedSrc = await resolveStagedResourceSource(decl.path, repoRoot, stagingRoot, diagPath);
|
|
1367
|
+
const requireSingleLink = true;
|
|
1368
|
+
if (decl.mount === 'prompt') {
|
|
1369
|
+
const bytes = await openAndReadNoFollowBoundedFile(resolvedSrc.fullPath, PREFLIGHT_MAX_PROMPT_RESOURCE_BYTES, diagPath, { requireSingleLink });
|
|
1370
|
+
promptTotalBytes += bytes.byteLength;
|
|
1371
|
+
if (promptTotalBytes > PREFLIGHT_MAX_PROMPT_RESOURCES_TOTAL_BYTES) {
|
|
1372
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: aggregate prompt-mounted staged resources exceed ${PREFLIGHT_MAX_PROMPT_RESOURCES_TOTAL_BYTES} bytes`, diagPath);
|
|
1373
|
+
}
|
|
1374
|
+
if (bytes.includes(0)) {
|
|
1375
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: prompt-mounted staged resource "${decl.id}" must not contain NUL bytes`, diagPath);
|
|
1376
|
+
}
|
|
1377
|
+
let content;
|
|
1378
|
+
try {
|
|
1379
|
+
content = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
1380
|
+
}
|
|
1381
|
+
catch {
|
|
1382
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: prompt-mounted staged resource "${decl.id}" is not valid UTF-8`, diagPath);
|
|
1383
|
+
}
|
|
1384
|
+
options.scrubber.assertClean(content, diagPath);
|
|
1385
|
+
strippedScrubber.assertClean(content, diagPath);
|
|
1386
|
+
const sha256 = createHash('sha256').update(bytes).digest('hex');
|
|
1387
|
+
promptResources.push(Object.freeze({
|
|
1388
|
+
id: decl.id,
|
|
1389
|
+
kind: decl.kind,
|
|
1390
|
+
path: resolvedSrc.relativePath,
|
|
1391
|
+
content,
|
|
1392
|
+
bytes,
|
|
1393
|
+
sha256,
|
|
1394
|
+
byteLength: bytes.byteLength,
|
|
1395
|
+
exposeToChecks: decl.exposeToChecks,
|
|
1396
|
+
}));
|
|
1397
|
+
}
|
|
1398
|
+
else {
|
|
1399
|
+
const collision = hasWorkspacePathPrefixCollision(resolvedSrc.relativePath, seenWorkspaceRelPaths);
|
|
1400
|
+
if (collision !== null) {
|
|
1401
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${diagPath}: workspace staged resource path "${resolvedSrc.relativePath}" collides with "${collision}"`, diagPath);
|
|
1402
|
+
}
|
|
1403
|
+
seenWorkspaceRelPaths.add(resolvedSrc.relativePath);
|
|
1404
|
+
if (stagedDir === null) {
|
|
1405
|
+
stagedDir = await mkdtemp(join(baseTemp, 'loopwright-staged-'));
|
|
1406
|
+
await chmod(stagedDir, 0o700);
|
|
1407
|
+
}
|
|
1408
|
+
const projected = await projectVerifiedWorkspaceSource({
|
|
1409
|
+
srcFullPath: resolvedSrc.fullPath,
|
|
1410
|
+
stagedRootDir: stagedDir,
|
|
1411
|
+
relativePath: resolvedSrc.relativePath,
|
|
1412
|
+
maxFileBytes: maxWorkspaceFileBytes,
|
|
1413
|
+
maxRemainingTotalBytes: maxWorkspaceTotalBytes - workspaceTotalBytes,
|
|
1414
|
+
requireSingleLink,
|
|
1415
|
+
disableReflink,
|
|
1416
|
+
scrubber: options.scrubber,
|
|
1417
|
+
strippedScrubber,
|
|
1418
|
+
diagPath,
|
|
1419
|
+
});
|
|
1420
|
+
workspaceTotalBytes += projected.byteLength;
|
|
1421
|
+
let checkDestPath = null;
|
|
1422
|
+
if (decl.exposeToChecks) {
|
|
1423
|
+
if (checkStagedDir === null) {
|
|
1424
|
+
checkStagedDir = await mkdtemp(join(baseTemp, 'loopwright-check-staged-'));
|
|
1425
|
+
await chmod(checkStagedDir, 0o700);
|
|
1426
|
+
}
|
|
1427
|
+
checkDestPath = await cloneVerifiedStagedFileForChecks({
|
|
1428
|
+
verifiedSrcPath: projected.destPath,
|
|
1429
|
+
checkStagedRootDir: checkStagedDir,
|
|
1430
|
+
relativePath: resolvedSrc.relativePath,
|
|
1431
|
+
expectedByteLength: projected.byteLength,
|
|
1432
|
+
expectedSha256: projected.sha256,
|
|
1433
|
+
disableReflink,
|
|
1434
|
+
diagPath,
|
|
1435
|
+
});
|
|
1436
|
+
}
|
|
1437
|
+
workspaceResources.push(Object.freeze({
|
|
1438
|
+
id: decl.id,
|
|
1439
|
+
kind: decl.kind,
|
|
1440
|
+
relativePath: resolvedSrc.relativePath,
|
|
1441
|
+
stagedPath: projected.destPath,
|
|
1442
|
+
checkStagedPath: checkDestPath,
|
|
1443
|
+
sha256: projected.sha256,
|
|
1444
|
+
byteLength: projected.byteLength,
|
|
1445
|
+
uri: `cas://sha256/${projected.sha256}`,
|
|
1446
|
+
exposeToChecks: decl.exposeToChecks,
|
|
1447
|
+
}));
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
if (options.signal?.aborted) {
|
|
1451
|
+
throw new TaskpackError('SANDBOX_EXECUTION_FAILED', 'preflight script execution aborted before completion', '/spec/preflight');
|
|
1452
|
+
}
|
|
1453
|
+
if (stagedDir !== null) {
|
|
1454
|
+
await chmodTreeReadOnly(stagedDir);
|
|
1455
|
+
}
|
|
1456
|
+
if (checkStagedDir !== null) {
|
|
1457
|
+
await chmodTreeReadOnly(checkStagedDir);
|
|
1458
|
+
}
|
|
1459
|
+
keepStagedDirs = true;
|
|
1460
|
+
const finalStagedDir = stagedDir;
|
|
1461
|
+
const finalCheckStagedDir = checkStagedDir;
|
|
1462
|
+
const cleanup = async () => {
|
|
1463
|
+
if (finalStagedDir !== null) {
|
|
1464
|
+
await makeWritableAndRemoveTree(finalStagedDir);
|
|
1465
|
+
}
|
|
1466
|
+
if (finalCheckStagedDir !== null) {
|
|
1467
|
+
await makeWritableAndRemoveTree(finalCheckStagedDir);
|
|
1468
|
+
}
|
|
1469
|
+
};
|
|
1470
|
+
return Object.freeze({
|
|
1471
|
+
script: scriptRelPath,
|
|
1472
|
+
scriptSha256,
|
|
1473
|
+
disposition: effectiveDisposition,
|
|
1474
|
+
reason: effectiveReason,
|
|
1475
|
+
upstreams: groupedUpstreams,
|
|
1476
|
+
promptResources: Object.freeze(promptResources),
|
|
1477
|
+
workspaceResources: Object.freeze(workspaceResources),
|
|
1478
|
+
stagedDir: finalStagedDir,
|
|
1479
|
+
checkStagedDir: finalCheckStagedDir,
|
|
1480
|
+
stdout: execResult.stdout,
|
|
1481
|
+
stderr: execResult.stderr,
|
|
1482
|
+
durationMs,
|
|
1483
|
+
cleanup,
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
finally {
|
|
1487
|
+
await makeWritableAndRemoveTree(workDir).catch(() => undefined);
|
|
1488
|
+
if (!keepStagedDirs) {
|
|
1489
|
+
if (stagedDir !== null) {
|
|
1490
|
+
await makeWritableAndRemoveTree(stagedDir).catch(() => undefined);
|
|
1491
|
+
}
|
|
1492
|
+
if (checkStagedDir !== null) {
|
|
1493
|
+
await makeWritableAndRemoveTree(checkStagedDir).catch(() => undefined);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
}
|