@gpustack/loopwright 0.0.0-stage → 0.0.2
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 +2083 -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 +1646 -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 +2605 -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 +7313 -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 +3021 -0
- package/package-lock.json +3021 -0
- package/package.json +52 -4
|
@@ -0,0 +1,1855 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { chmod, lstat, mkdir, mkdtemp, readdir, realpath, rm, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
import { STANDARD_PI_PROVIDER_ENV } from '@loopwright/agent-pi/catalog';
|
|
9
|
+
import { HostMcpRegistry } from '@loopwright/agent-pi/mcp';
|
|
10
|
+
import { compilePlan, formatRunReport, inspectRun, loadTrustedConfiguration, parseReportOutputFormats, readStatus, reconcileCycle, resumeCycle, resumeCycleWithPorts, runCycle, runCycleWithPorts, stepCancel, stepNext, stepSubmit } from '@loopwright/controller';
|
|
11
|
+
import { alignBaselineRevisions, assertCleanArtifact, BASELINE_CONFLICT_REASON, buildDefaultAuthorPrompt, checkTaskpackSuite, collectManifestSecretEnvNames, collectMcpReferencedEnvNames, compileDeclarativeTaskpack, computeTaskpackDigests, createTaskpackDecisionPort, DEFAULT_HOST_BUDGETS, DEFAULT_LOCAL_COMMAND_GATE_ENV, discoverTaskpackUpstreamsV2, evaluateUpstreamIntakeDisposition, executeTurnkeyCycle, finalizeLocalTurnkeyMemory, formatWorkspaceResourcesManifest, insideRoot, loadDeclarativeTaskpack, loadPiModelsJson, LOOPWRIGHT_ACTIVE_PROVIDER_TOKEN_ENV, normalizeRelativePath, openStagedTaskpackStepGate, parseActionInputLimits, parseAllowedHostMounts, parseBaselineAlignmentPolicy, parseLoopwrightEnvLimits, parseYamlDocument, readBoundedRegularFile, REPOSITORY_FULL_NAME_PATTERN, resolveDefaultProviderTokenEnv, resolveDigestLockfilePath, resolveExternalMcpConfigs, resolveRepositoryAndRevisions, resolveTaskpackModelCandidates, resolveTaskpackModelSelection, resolveTaskpackSuite, runTaskpackPreflight, SecretScrubber, selectHealthyModelCandidate, serializePrettyYaml, stageCompiledInstructionResources, stageTaskpackForStep, startLocalCommandGateServer, TaskpackError, validateGateToolchainPath, verifyDigestLockfile, writeDigestLockfile } from '@loopwright/taskpack';
|
|
12
|
+
import { parseArguments, UsageError } from './arguments.js';
|
|
13
|
+
import { appendStepSummary, initDraft, writeOutput } from './draft.js';
|
|
14
|
+
import { evaluateClosureMatrix, CLOSURE_FALSIFICATION_FORBIDDEN } from './closure.js';
|
|
15
|
+
function resolveCliVersion() {
|
|
16
|
+
try {
|
|
17
|
+
const raw = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
18
|
+
if (typeof raw.version === 'string' && raw.version.length > 0)
|
|
19
|
+
return raw.version;
|
|
20
|
+
}
|
|
21
|
+
catch { /* fallback */ }
|
|
22
|
+
return '0.0.0';
|
|
23
|
+
}
|
|
24
|
+
const CLI_VERSION = resolveCliVersion();
|
|
25
|
+
const HELP = `loopwright ${CLI_VERSION}\ninit --directory DIR [--force] [--json]\ncheck --config FILE --registry FILE --registry-sha256 HEX [--role-model ROLE=PROVIDER/MODEL[:THINKING]] [--json] [--output FILE]\nrun --dry-run --config FILE --registry FILE --registry-sha256 HEX [--role-model ROLE=PROVIDER/MODEL[:THINKING]] [--json] [--output FILE]\nrun --config FILE --registry FILE --registry-sha256 HEX --repo DIR --run-root DIR --run-id ID [--role-model ROLE=PROVIDER/MODEL[:THINKING]] [--allow-privileged] [--allow-workflow-writes] [--json] [--output-format FORMATS] [--step-summary-file FILE]\nrun --dry-run --taskpack FILE --repo DIR [--mode candidate|no-change|auto] [--baseline-alignment off|fail-fast|extract-context] [--source-revision REV] [--role-model ROLE=PROVIDER/MODEL[:THINKING]] [--allow-privileged] [--allow-workflow-writes] [--allow-host-mounts PATHS] [--json] [--output FILE]\nrun --taskpack FILE --repo DIR --run-root DIR --run-id ID [--mode candidate|no-change|auto] [--baseline-alignment off|fail-fast|extract-context] [--source-revision REV] [--role-model ROLE=PROVIDER/MODEL[:THINKING]] [--allow-privileged] [--allow-workflow-writes] [--allow-host-mounts PATHS] [--json] [--output-format FORMATS] [--step-summary-file FILE]\nresume --run-root DIR --run-id ID --config FILE --registry FILE --registry-sha256 HEX --repo DIR [--role-model ROLE=PROVIDER/MODEL[:THINKING]] [--allow-privileged] [--allow-workflow-writes] [--json] [--output-format FORMATS] [--step-summary-file FILE]\nstep next --run-root DIR --run-id ID (--taskpack FILE --repo DIR | --config FILE --registry FILE --registry-sha256 HEX --repo DIR | [--repo DIR]) [--role-model ROLE=PROVIDER/MODEL[:THINKING]] [--mode candidate|no-change] [--baseline-alignment off|fail-fast|extract-context] [--source-revision REV] [--reissue-lease] [--allow-privileged] [--allow-workflow-writes] [--allow-host-mounts PATHS] [--json] [--output-format FORMATS] [--step-summary-file FILE]\nstep submit --run-root DIR --run-id ID --lease TOKEN [--submission-file FILE] [--status completed|no_change|failed|blocked] [--reason TEXT] [--allow-privileged] [--allow-workflow-writes] [--allow-host-mounts PATHS] [--json] [--output-format FORMATS] [--step-summary-file FILE]\nstep cancel --run-root DIR --run-id ID [--json] [--output-format FORMATS] [--step-summary-file FILE]\ndigest sync --taskpack FILE [--repo DIR] [--check] [--json]\nsuite check --suite FILE [--repo DIR] [--verify-digests] [--json]\nsuite resolve --suite FILE [--repo DIR] [--event NAME] [--schedule KEY] [--comment-body TEXT] [--pr-head-ref REF] [--pr-base-ref REF] [--domain ID] [--json]\nreconcile --config FILE --registry FILE --registry-sha256 HEX --repo DIR --run-root DIR --run-id ID --receipt FILE [--allow-workflow-writes] [--json] [--output FILE] [--output-format FORMATS] [--step-summary-file FILE]\nstatus --run-root DIR --run-id ID [--json]\ninspect --run-root DIR --run-id ID [--json] [--output DIR]\nclosure [--repo DIR] [--output FILE] [--json] [--verify-failures]\napp-serve --config FILE [--repo DIR] [--json]\nrunner relay --config FILE [--json]\nrunner worker --config FILE [--once] [--json]\nConfig and registry files accept YAML (.yaml, .yml) or JSON (.json); init writes controller.draft.yaml and registry.draft.yaml.\nStatic plans do not establish execution readiness. Strict proven_bound is the default.\nJSON verification requires both complete manifests and framing to fit the 16384-byte header; selected file <=1032184 bytes.\n`;
|
|
26
|
+
const RUNNER_HELP = `loopwright ${CLI_VERSION} runner\nrunner relay --config FILE [--json]\nrunner worker --config FILE [--once] [--json]\n`;
|
|
27
|
+
export function encoded(value) {
|
|
28
|
+
return JSON.stringify(value).replace(/[\u007f-\u009f\u2028\u2029<>&]/g, char => '\\u' + char.charCodeAt(0).toString(16).padStart(4, '0')).replace(/::/g, '\\u003a\\u003a');
|
|
29
|
+
}
|
|
30
|
+
async function stdout(value) {
|
|
31
|
+
if (Buffer.byteLength(value) > 1048576)
|
|
32
|
+
throw new Error('CLI_OUTPUT_LIMIT');
|
|
33
|
+
await new Promise((done, reject) => { const timer = setTimeout(() => reject(new Error('CLI_BACKPRESSURE')), 1000); process.stdout.write(value, error => { clearTimeout(timer); if (error)
|
|
34
|
+
reject(error);
|
|
35
|
+
else
|
|
36
|
+
done(); }); });
|
|
37
|
+
}
|
|
38
|
+
async function stderr(value) {
|
|
39
|
+
if (Buffer.byteLength(value) > 1048576)
|
|
40
|
+
throw new Error('CLI_OUTPUT_LIMIT');
|
|
41
|
+
await new Promise((done, reject) => { const timer = setTimeout(() => reject(new Error('CLI_BACKPRESSURE')), 1000); process.stderr.write(value, error => { clearTimeout(timer); if (error)
|
|
42
|
+
reject(error);
|
|
43
|
+
else
|
|
44
|
+
done(); }); });
|
|
45
|
+
}
|
|
46
|
+
export function diagnosticExit(error) {
|
|
47
|
+
if (error.code === 'RECOVERY_REQUIRED' || error.code === 'AUTHORITY_REFUSED' || error.code === 'OWNER_BUSY' || error.code === 'RECEIPT_CONFLICT')
|
|
48
|
+
return 7;
|
|
49
|
+
if (error.code === 'CAPABILITY_UNSUPPORTED' || error.code === 'MCP_AUTHENTICATION_REQUIRED')
|
|
50
|
+
return 3;
|
|
51
|
+
if (error.code === 'BUDGET_EXHAUSTED' || error.code === 'ATTEMPT_LIMIT' || error.code === 'REPEAT_FAILURE')
|
|
52
|
+
return 5;
|
|
53
|
+
if (error.code === 'DEADLINE')
|
|
54
|
+
return 6;
|
|
55
|
+
if (['STATE_UNAVAILABLE', 'CLEANUP_FAILED', 'ARTIFACT_INVALID', 'OUTPUT_LIMIT'].includes(error.code))
|
|
56
|
+
return 8;
|
|
57
|
+
return ['admission', 'compile', 'configuration'].includes(error.phase) ? 2 : 4;
|
|
58
|
+
}
|
|
59
|
+
export function executionExit(value, signal) {
|
|
60
|
+
if (value.kind === 'incident')
|
|
61
|
+
return value.incident.code === 'RECOVERY_REQUIRED' ? 7 : 8;
|
|
62
|
+
switch (value.result.spec.status) {
|
|
63
|
+
case 'completed':
|
|
64
|
+
case 'no_change': return 0;
|
|
65
|
+
case 'blocked': return 3;
|
|
66
|
+
case 'failed': return 4;
|
|
67
|
+
case 'exhausted': return 5;
|
|
68
|
+
case 'expired': return 6;
|
|
69
|
+
case 'reconcile_required': return 7;
|
|
70
|
+
case 'cancelled': return signal === 'SIGTERM' ? 143 : 130;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function closureExitCode(report, verifyFailures) {
|
|
74
|
+
if (report.falsificationDetected || report.diagnostics.some(diagnostic => diagnostic.code === CLOSURE_FALSIFICATION_FORBIDDEN || diagnostic.code === 'CAPABILITY_UNSUPPORTED'))
|
|
75
|
+
return 3;
|
|
76
|
+
if (!report.integrity.ok)
|
|
77
|
+
return 8;
|
|
78
|
+
if (verifyFailures && (report.failureMatrix === null || !report.failureMatrix.allPassed))
|
|
79
|
+
return 4;
|
|
80
|
+
return report.summary.closedLocal === 18 && report.summary.unprovisionedExternal === 5 ? 0 : 3;
|
|
81
|
+
}
|
|
82
|
+
async function queryInspection(runRoot, runId) {
|
|
83
|
+
try {
|
|
84
|
+
const inspected = await inspectRun({ runRoot, runId });
|
|
85
|
+
return inspected.ok ? inspected.value : null;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function primaryModelInfo(configuration) {
|
|
92
|
+
const firstRole = configuration.configuration.spec.task.spec.roles[0];
|
|
93
|
+
return firstRole ? { provider: firstRole.provider, model: firstRole.model, thinking: firstRole.thinking } : null;
|
|
94
|
+
}
|
|
95
|
+
async function emitOutcomeReports(input) {
|
|
96
|
+
const { args, runRoot, runId, json, configuration, model, report, emitDefault } = input;
|
|
97
|
+
const outputFormats = args.values.has('output-format')
|
|
98
|
+
? parseReportOutputFormats(args.values.get('output-format'))
|
|
99
|
+
: [];
|
|
100
|
+
const rawSummaryFile = args.values.get('step-summary-file')
|
|
101
|
+
?? (outputFormats.includes('github-step-summary') ? process.env['GITHUB_STEP_SUMMARY'] : undefined);
|
|
102
|
+
const stepSummaryFile = rawSummaryFile !== undefined && rawSummaryFile.trim().length > 0 ? rawSummaryFile : undefined;
|
|
103
|
+
if (outputFormats.length === 0 && stepSummaryFile === undefined) {
|
|
104
|
+
await emitDefault();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const inspected = await queryInspection(runRoot, runId);
|
|
108
|
+
const reportInput = {
|
|
109
|
+
runId,
|
|
110
|
+
status: report.status,
|
|
111
|
+
reasonCode: report.reasonCode ?? null,
|
|
112
|
+
phase: report.phase ?? inspected?.status.stage ?? null,
|
|
113
|
+
checks: report.checks ?? [],
|
|
114
|
+
model: model !== undefined ? model : (configuration ? primaryModelInfo(configuration) : null),
|
|
115
|
+
usage: report.usage ?? inspected?.usage ?? null,
|
|
116
|
+
externalUrl: inspected?.externalUrl ?? null,
|
|
117
|
+
runEval: report.runEval ?? inspected?.runEval ?? null,
|
|
118
|
+
};
|
|
119
|
+
if (stepSummaryFile !== undefined) {
|
|
120
|
+
const summaryMd = formatRunReport(reportInput, 'github-step-summary') + '\n';
|
|
121
|
+
await appendStepSummary(stepSummaryFile, Buffer.from(summaryMd, 'utf8'));
|
|
122
|
+
}
|
|
123
|
+
if (json || outputFormats.length === 0) {
|
|
124
|
+
await emitDefault();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const stdoutFormats = outputFormats.filter(fmt => !(fmt === 'github-step-summary' && stepSummaryFile !== undefined));
|
|
128
|
+
if (stdoutFormats.length === 0) {
|
|
129
|
+
await emitDefault();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const fmt of stdoutFormats) {
|
|
133
|
+
await stdout(formatRunReport(reportInput, fmt) + '\n');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function emitExecutionOutcome(args, runRoot, runId, json, outcome, configuration, emit) {
|
|
137
|
+
await emitOutcomeReports({
|
|
138
|
+
args,
|
|
139
|
+
runRoot,
|
|
140
|
+
runId,
|
|
141
|
+
json,
|
|
142
|
+
...(configuration !== undefined ? { configuration } : {}),
|
|
143
|
+
report: outcome.kind === 'incident'
|
|
144
|
+
? { status: 'incident', reasonCode: outcome.incident.code, phase: outcome.incident.stage, checks: [] }
|
|
145
|
+
: {
|
|
146
|
+
status: outcome.result.spec.status,
|
|
147
|
+
reasonCode: outcome.result.spec.verification.spec.diagnostics[0]?.code ?? null,
|
|
148
|
+
phase: null,
|
|
149
|
+
checks: [...outcome.result.spec.verification.spec.required, ...outcome.result.spec.verification.spec.optional].map((row) => ({ checkId: row.checkId, status: row.status, code: row.reason, detail: row.detail })),
|
|
150
|
+
usage: outcome.result.spec.usage,
|
|
151
|
+
},
|
|
152
|
+
emitDefault: () => outcome.kind === 'incident'
|
|
153
|
+
? emit('incident', outcome.incident, outcome.incident.code)
|
|
154
|
+
: emit('result', outcome, outcome.result.spec.status),
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/** Map every TaskpackErrorCode exhaustively to its documented CLI exit code. */
|
|
158
|
+
export function taskpackExitCode(code, reason) {
|
|
159
|
+
if (reason === BASELINE_CONFLICT_REASON)
|
|
160
|
+
return 3;
|
|
161
|
+
switch (code) {
|
|
162
|
+
case 'TASKPACK_MANIFEST_INVALID':
|
|
163
|
+
case 'TASKPACK_UNTRUSTED_INTERPOLATION':
|
|
164
|
+
case 'TASKPACK_SCOPE_VIOLATION':
|
|
165
|
+
case 'TASKPACK_HOST_BINDING_INVALID':
|
|
166
|
+
case 'TASKPACK_TRIGGER_UNSUPPORTED':
|
|
167
|
+
case 'SANDBOX_POLICY_INVALID':
|
|
168
|
+
case 'GITHUB_APP_CONFIG_INVALID':
|
|
169
|
+
case 'TOKEN_BROKER_CONFIG_INVALID':
|
|
170
|
+
case 'ACTION_INPUT_INVALID':
|
|
171
|
+
case 'TENANT_IDENTITY_INVALID':
|
|
172
|
+
case 'WEBHOOK_GUIDANCE_INVALID':
|
|
173
|
+
case 'WEBHOOK_DELIVERY_INVALID':
|
|
174
|
+
return 2;
|
|
175
|
+
case 'PROVIDER_OAUTH_UNSUPPORTED':
|
|
176
|
+
case 'SANDBOX_BACKEND_UNAVAILABLE':
|
|
177
|
+
case 'SANDBOX_CAPABILITY_INSUFFICIENT':
|
|
178
|
+
case 'MCP_OAUTH_UNSUPPORTED':
|
|
179
|
+
case 'MCP_AUTHENTICATION_REQUIRED':
|
|
180
|
+
case 'HOST_PROFILE_UNQUALIFIED':
|
|
181
|
+
case 'WEBHOOK_ACTOR_UNAUTHORIZED':
|
|
182
|
+
case 'WEBHOOK_SIGNATURE_INVALID':
|
|
183
|
+
case 'TENANT_BOUNDARY_VIOLATION':
|
|
184
|
+
case 'TENANT_INSTALLATION_REVOKED':
|
|
185
|
+
case 'TOKEN_SCOPE_VIOLATION':
|
|
186
|
+
return 3;
|
|
187
|
+
case 'SANDBOX_EXECUTION_FAILED':
|
|
188
|
+
return 4;
|
|
189
|
+
case 'QUEUE_CAPACITY_EXCEEDED':
|
|
190
|
+
return 5;
|
|
191
|
+
case 'TOKEN_TTL_EXCEEDED':
|
|
192
|
+
return 6;
|
|
193
|
+
case 'HOST_CLOCK_UNTRUSTED':
|
|
194
|
+
case 'QUEUE_LEASE_FENCED':
|
|
195
|
+
case 'WEBHOOK_DELIVERY_CONFLICT':
|
|
196
|
+
return 7;
|
|
197
|
+
case 'STORAGE_PROFILE_INSUFFICIENT':
|
|
198
|
+
case 'TOKEN_SECRET_LEAK_DETECTED':
|
|
199
|
+
case 'SERVICE_FAULT':
|
|
200
|
+
case 'QUEUE_STATE_INVALID':
|
|
201
|
+
case 'WEBHOOK_PAYLOAD_TOO_LARGE':
|
|
202
|
+
return 8;
|
|
203
|
+
default: {
|
|
204
|
+
const _exhaustive = code;
|
|
205
|
+
return _exhaustive;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export { taskpackExitCode as gitHubAppExitCode };
|
|
210
|
+
/** Map every HardwareRunnerErrorCode exhaustively to its documented CLI exit code. */
|
|
211
|
+
export function hardwareRunnerExitCode(code) {
|
|
212
|
+
switch (code) {
|
|
213
|
+
case 'CONFIG_INVALID':
|
|
214
|
+
case 'PAYLOAD_TOO_LARGE':
|
|
215
|
+
return 2;
|
|
216
|
+
case 'AUTH_UNAUTHORIZED':
|
|
217
|
+
case 'AUTH_FORBIDDEN':
|
|
218
|
+
case 'RUNNER_SANDBOX_FAILED':
|
|
219
|
+
return 3;
|
|
220
|
+
case 'ARTIFACT_INVALID':
|
|
221
|
+
case 'ARTIFACT_MISSING':
|
|
222
|
+
case 'NOT_FOUND':
|
|
223
|
+
return 4;
|
|
224
|
+
case 'QUEUE_CAPACITY_EXCEEDED':
|
|
225
|
+
return 5;
|
|
226
|
+
case 'QUEUE_LEASE_FENCED':
|
|
227
|
+
case 'QUEUE_JOB_CONFLICT':
|
|
228
|
+
return 7;
|
|
229
|
+
case 'QUEUE_STATE_INVALID':
|
|
230
|
+
return 8;
|
|
231
|
+
default: {
|
|
232
|
+
const _exhaustive = code;
|
|
233
|
+
return _exhaustive;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function createCliScrubber(extraKeys = []) {
|
|
238
|
+
const scrubber = new SecretScrubber();
|
|
239
|
+
for (const key of ['GITHUB_TOKEN', 'GH_TOKEN', 'INPUT_GITHUB-TOKEN', 'INPUT_GITHUB-APP-PRIVATE-KEY', ...extraKeys]) {
|
|
240
|
+
const value = process.env[key];
|
|
241
|
+
if (typeof value === 'string' && value.length > 0)
|
|
242
|
+
scrubber.register(value);
|
|
243
|
+
}
|
|
244
|
+
return scrubber;
|
|
245
|
+
}
|
|
246
|
+
async function canonicalPath(target) {
|
|
247
|
+
const resolved = resolve(target);
|
|
248
|
+
return await realpath(resolved).catch(() => resolved);
|
|
249
|
+
}
|
|
250
|
+
function isInsidePathRoot(target, root) {
|
|
251
|
+
return target === root || target.startsWith(root.endsWith(sep) ? root : `${root}${sep}`);
|
|
252
|
+
}
|
|
253
|
+
async function removeStagedDirSafely(dirPath) {
|
|
254
|
+
const restoreDirs = async (target) => {
|
|
255
|
+
const st = await lstat(target).catch(() => null);
|
|
256
|
+
if (st === null || st.isSymbolicLink() || !st.isDirectory())
|
|
257
|
+
return;
|
|
258
|
+
await chmod(target, 0o700).catch(() => { });
|
|
259
|
+
const entries = await readdir(target, { withFileTypes: true }).catch(() => []);
|
|
260
|
+
for (const entry of entries) {
|
|
261
|
+
if (entry.isDirectory()) {
|
|
262
|
+
await restoreDirs(join(target, entry.name));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
await restoreDirs(dirPath);
|
|
267
|
+
await rm(dirPath, { recursive: true, force: true }).catch(() => { });
|
|
268
|
+
}
|
|
269
|
+
async function inspectExistingDisjointRunRoot(resolvedRunRoot, requestedRepo) {
|
|
270
|
+
let anc = resolvedRunRoot;
|
|
271
|
+
let ancStat;
|
|
272
|
+
for (;;) {
|
|
273
|
+
try {
|
|
274
|
+
ancStat = await lstat(anc);
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
if (error.code !== 'ENOENT') {
|
|
279
|
+
return { exists: false, prospectiveRunRoot: null, disjoint: false };
|
|
280
|
+
}
|
|
281
|
+
const parent = dirname(anc);
|
|
282
|
+
if (parent === anc) {
|
|
283
|
+
return { exists: false, prospectiveRunRoot: null, disjoint: false };
|
|
284
|
+
}
|
|
285
|
+
anc = parent;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const exists = anc === resolvedRunRoot;
|
|
289
|
+
if (exists && (ancStat.isSymbolicLink() || !ancStat.isDirectory())) {
|
|
290
|
+
return { exists: false, prospectiveRunRoot: null, disjoint: false };
|
|
291
|
+
}
|
|
292
|
+
if (!exists && !ancStat.isDirectory() && !ancStat.isSymbolicLink()) {
|
|
293
|
+
return { exists: false, prospectiveRunRoot: null, disjoint: false };
|
|
294
|
+
}
|
|
295
|
+
let realAnc;
|
|
296
|
+
try {
|
|
297
|
+
realAnc = await realpath(anc);
|
|
298
|
+
const realAncStat = await lstat(realAnc);
|
|
299
|
+
if (!realAncStat.isDirectory()) {
|
|
300
|
+
return { exists: false, prospectiveRunRoot: null, disjoint: false };
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
return { exists: false, prospectiveRunRoot: null, disjoint: false };
|
|
305
|
+
}
|
|
306
|
+
const prospectiveRunRoot = exists ? realAnc : resolve(realAnc, relative(anc, resolvedRunRoot));
|
|
307
|
+
const disjoint = !isInsidePathRoot(prospectiveRunRoot, requestedRepo)
|
|
308
|
+
&& !isInsidePathRoot(requestedRepo, prospectiveRunRoot);
|
|
309
|
+
return { exists, prospectiveRunRoot, disjoint };
|
|
310
|
+
}
|
|
311
|
+
async function withSignalAbort(fn) {
|
|
312
|
+
const abort = new AbortController();
|
|
313
|
+
let caughtSignal = null;
|
|
314
|
+
const interrupt = () => { caughtSignal ??= 'SIGINT'; abort.abort(); };
|
|
315
|
+
const terminate = () => { caughtSignal ??= 'SIGTERM'; abort.abort(); };
|
|
316
|
+
process.on('SIGINT', interrupt);
|
|
317
|
+
process.on('SIGTERM', terminate);
|
|
318
|
+
try {
|
|
319
|
+
return await fn(abort.signal, () => caughtSignal);
|
|
320
|
+
}
|
|
321
|
+
finally {
|
|
322
|
+
process.off('SIGINT', interrupt);
|
|
323
|
+
process.off('SIGTERM', terminate);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async function resolveRepoRelativeControlPath(rawPath, rawRepoRoot, repoRoot, label) {
|
|
327
|
+
if (!isAbsolute(rawPath)) {
|
|
328
|
+
return normalizeRelativePath(rawPath.replace(/\\/g, '/'), '/');
|
|
329
|
+
}
|
|
330
|
+
const absManifest = resolve(rawPath);
|
|
331
|
+
const relFromRaw = relative(rawRepoRoot, absManifest);
|
|
332
|
+
if (relFromRaw.length > 0 && relFromRaw !== '..' && !relFromRaw.startsWith(`..${sep}`) && !isAbsolute(relFromRaw)) {
|
|
333
|
+
return normalizeRelativePath(relFromRaw.split(sep).join('/'), '/');
|
|
334
|
+
}
|
|
335
|
+
const relFromReal = relative(repoRoot, absManifest);
|
|
336
|
+
if (relFromReal.length > 0 && relFromReal !== '..' && !relFromReal.startsWith(`..${sep}`) && !isAbsolute(relFromReal)) {
|
|
337
|
+
return normalizeRelativePath(relFromReal.split(sep).join('/'), '/');
|
|
338
|
+
}
|
|
339
|
+
let ancestor = dirname(absManifest);
|
|
340
|
+
let prev = '';
|
|
341
|
+
while (ancestor !== prev) {
|
|
342
|
+
const realAncestor = await realpath(ancestor).catch(() => null);
|
|
343
|
+
if (realAncestor === repoRoot) {
|
|
344
|
+
const relFromAncestor = relative(ancestor, absManifest);
|
|
345
|
+
if (relFromAncestor.length > 0 && relFromAncestor !== '..' && !relFromAncestor.startsWith(`..${sep}`) && !isAbsolute(relFromAncestor)) {
|
|
346
|
+
return normalizeRelativePath(relFromAncestor.split(sep).join('/'), '/');
|
|
347
|
+
}
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
prev = ancestor;
|
|
351
|
+
ancestor = dirname(ancestor);
|
|
352
|
+
}
|
|
353
|
+
throw new TaskpackError('TASKPACK_MANIFEST_INVALID', `${label} escapes the repository root`, '/');
|
|
354
|
+
}
|
|
355
|
+
async function resolveRepoRelativeTaskpackPath(rawTaskpack, rawRepoRoot, repoRoot) {
|
|
356
|
+
return await resolveRepoRelativeControlPath(rawTaskpack, rawRepoRoot, repoRoot, 'taskpack manifest');
|
|
357
|
+
}
|
|
358
|
+
function parseTaskpackAlignmentArgs(args) {
|
|
359
|
+
const baselineAlignment = args.values.has('baseline-alignment')
|
|
360
|
+
? parseBaselineAlignmentPolicy(args.values.get('baseline-alignment'), '/baselineAlignment')
|
|
361
|
+
: undefined;
|
|
362
|
+
const rawSourceRevision = args.values.get('source-revision')?.trim();
|
|
363
|
+
const sourceRevision = rawSourceRevision !== undefined && rawSourceRevision.length > 0 ? rawSourceRevision : undefined;
|
|
364
|
+
return {
|
|
365
|
+
...(baselineAlignment !== undefined ? { baselineAlignment } : {}),
|
|
366
|
+
...(sourceRevision !== undefined ? { sourceRevision } : {}),
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
async function emitTaskpackError(err, emit, scrubber) {
|
|
370
|
+
const effectiveScrubber = scrubber ?? createCliScrubber();
|
|
371
|
+
const message = effectiveScrubber.scrub(err.message);
|
|
372
|
+
const path = typeof err.path === 'string' && err.path.length > 0 ? effectiveScrubber.scrub(err.path) : null;
|
|
373
|
+
const reason = typeof err.reason === 'string' && err.reason.length > 0 ? effectiveScrubber.scrub(err.reason) : null;
|
|
374
|
+
await emit('diagnostic', { version: 1, code: err.code, ...(reason !== null ? { reason } : {}), message, ...(path !== null ? { path } : {}) }, reason !== null ? `${err.code}: ${reason}` : err.code);
|
|
375
|
+
return taskpackExitCode(err.code, err.reason);
|
|
376
|
+
}
|
|
377
|
+
async function runSuiteCommand(args, emit) {
|
|
378
|
+
const rawRepoRoot = resolve(args.values.has('repo') ? args.values.get('repo') : process.cwd());
|
|
379
|
+
const repoRoot = await canonicalPath(rawRepoRoot);
|
|
380
|
+
const scrubber = createCliScrubber();
|
|
381
|
+
try {
|
|
382
|
+
const suitePath = await resolveRepoRelativeControlPath(args.values.get('suite'), rawRepoRoot, repoRoot, 'suite manifest');
|
|
383
|
+
if (args.suiteAction === 'check') {
|
|
384
|
+
const verifyDigests = args.flags.has('verify-digests');
|
|
385
|
+
const loaded = await checkTaskpackSuite({
|
|
386
|
+
repositoryRoot: repoRoot,
|
|
387
|
+
suitePath,
|
|
388
|
+
policyProfile: 'local',
|
|
389
|
+
enforceHostAuthority: false,
|
|
390
|
+
verifyDigests,
|
|
391
|
+
});
|
|
392
|
+
const payload = {
|
|
393
|
+
version: 1,
|
|
394
|
+
action: 'check',
|
|
395
|
+
ok: true,
|
|
396
|
+
verifyDigests,
|
|
397
|
+
suiteName: scrubber.scrub(loaded.manifest.metadata.name),
|
|
398
|
+
suitePath: scrubber.scrub(loaded.suitePath),
|
|
399
|
+
controlRoot: scrubber.scrub(loaded.controlRoot),
|
|
400
|
+
suiteSha256: loaded.suiteSha256,
|
|
401
|
+
stageOrder: loaded.stageOrder,
|
|
402
|
+
suiteProtectedPaths: loaded.suiteProtectedPaths,
|
|
403
|
+
domains: loaded.domains.map(domain => ({
|
|
404
|
+
id: domain.id,
|
|
405
|
+
taskpackPath: scrubber.scrub(domain.taskpackPath),
|
|
406
|
+
taskpackName: scrubber.scrub(domain.taskpackName),
|
|
407
|
+
manifestSha256: domain.manifestSha256,
|
|
408
|
+
controlRoot: scrubber.scrub(domain.controlRoot),
|
|
409
|
+
enabled: domain.enabled,
|
|
410
|
+
...(domain.stage !== undefined ? { stage: domain.stage } : {}),
|
|
411
|
+
...(domain.schedules !== undefined ? { schedules: domain.schedules } : {}),
|
|
412
|
+
...(domain.matrix !== undefined ? { matrix: domain.matrix } : {}),
|
|
413
|
+
})),
|
|
414
|
+
};
|
|
415
|
+
const summary = scrubber.scrub(`suite check: ok (${loaded.domains.length} domains, ${loaded.stageOrder.length} stages, sha256:${loaded.suiteSha256.slice(0, 12)})`);
|
|
416
|
+
await emit('suite', payload, summary);
|
|
417
|
+
return 0;
|
|
418
|
+
}
|
|
419
|
+
const githubToken = process.env['GITHUB_TOKEN']?.trim() || process.env['GH_TOKEN']?.trim() || undefined;
|
|
420
|
+
const rawLoopwrightRepo = process.env['LOOPWRIGHT_REPOSITORY']?.trim();
|
|
421
|
+
const rawGithubWorkspace = process.env['GITHUB_WORKSPACE']?.trim();
|
|
422
|
+
let matchesGithubWorkspace = false;
|
|
423
|
+
if (rawGithubWorkspace !== undefined && rawGithubWorkspace.length > 0) {
|
|
424
|
+
const realGithubWorkspace = await realpath(rawGithubWorkspace).catch(() => null);
|
|
425
|
+
matchesGithubWorkspace = realGithubWorkspace === repoRoot;
|
|
426
|
+
}
|
|
427
|
+
const hasExplicitLoopwrightRepo = rawLoopwrightRepo !== undefined && rawLoopwrightRepo.length > 0;
|
|
428
|
+
const rawRepoFullName = hasExplicitLoopwrightRepo
|
|
429
|
+
? rawLoopwrightRepo
|
|
430
|
+
: (matchesGithubWorkspace ? process.env['GITHUB_REPOSITORY']?.trim() : undefined);
|
|
431
|
+
const repositoryFullName = rawRepoFullName !== undefined && REPOSITORY_FULL_NAME_PATTERN.test(rawRepoFullName)
|
|
432
|
+
? rawRepoFullName
|
|
433
|
+
: undefined;
|
|
434
|
+
const suiteEnv = (!hasExplicitLoopwrightRepo && matchesGithubWorkspace)
|
|
435
|
+
? process.env
|
|
436
|
+
: { ...process.env, GITHUB_REPOSITORY: undefined };
|
|
437
|
+
const resolution = await resolveTaskpackSuite({
|
|
438
|
+
repositoryRoot: repoRoot,
|
|
439
|
+
suitePath,
|
|
440
|
+
baseRevision: 'HEAD',
|
|
441
|
+
...(repositoryFullName !== undefined ? { repositoryFullName } : {}),
|
|
442
|
+
...(args.values.has('event') ? { eventName: args.values.get('event') } : {}),
|
|
443
|
+
...(args.values.has('schedule') ? { schedule: args.values.get('schedule') } : {}),
|
|
444
|
+
...(args.values.has('comment-body') ? { commentBody: args.values.get('comment-body') } : {}),
|
|
445
|
+
...(args.values.has('pr-head-ref') ? { prHeadRef: args.values.get('pr-head-ref') } : {}),
|
|
446
|
+
...(args.values.has('pr-base-ref') ? { prBaseRef: args.values.get('pr-base-ref') } : {}),
|
|
447
|
+
...(args.values.has('domain') ? { domain: args.values.get('domain') } : {}),
|
|
448
|
+
...(githubToken !== undefined ? { githubToken } : {}),
|
|
449
|
+
discoverUpstreamUpdates: true,
|
|
450
|
+
scrubber,
|
|
451
|
+
env: suiteEnv,
|
|
452
|
+
});
|
|
453
|
+
const scrubbedComment = resolution.comment !== undefined
|
|
454
|
+
? Object.freeze({
|
|
455
|
+
...resolution.comment,
|
|
456
|
+
guidance: scrubber.scrub(resolution.comment.guidance),
|
|
457
|
+
})
|
|
458
|
+
: undefined;
|
|
459
|
+
const payload = {
|
|
460
|
+
version: 1,
|
|
461
|
+
action: 'resolve',
|
|
462
|
+
...resolution,
|
|
463
|
+
...(scrubbedComment !== undefined ? { comment: scrubbedComment } : {}),
|
|
464
|
+
};
|
|
465
|
+
const cellSummary = resolution.cells.map(cell => `${cell.domainId}:${cell.disposition}:${cell.reason}`).join(', ');
|
|
466
|
+
const detailSuffix = resolution.detail !== undefined ? ` detail=${resolution.detail}` : '';
|
|
467
|
+
const summary = scrubber.scrub(`suite resolve: disposition=${resolution.disposition} reason=${resolution.reason} matrix=${resolution.matrix.include.length} cells=[${cellSummary}]${detailSuffix}`);
|
|
468
|
+
await emit('suite', payload, summary);
|
|
469
|
+
switch (resolution.disposition) {
|
|
470
|
+
case 'eligible':
|
|
471
|
+
case 'deferred':
|
|
472
|
+
case 'ignored':
|
|
473
|
+
return 0;
|
|
474
|
+
case 'blocked':
|
|
475
|
+
if (resolution.code === undefined || resolution.code === 'TASKPACK_SCOPE_VIOLATION') {
|
|
476
|
+
return 3;
|
|
477
|
+
}
|
|
478
|
+
return taskpackExitCode(resolution.code);
|
|
479
|
+
default: {
|
|
480
|
+
const _exhaustive = resolution.disposition;
|
|
481
|
+
return _exhaustive;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
catch (err) {
|
|
486
|
+
if (err instanceof TaskpackError) {
|
|
487
|
+
return await emitTaskpackError(err, emit, scrubber);
|
|
488
|
+
}
|
|
489
|
+
throw err;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
async function runDigestCommand(args, emit) {
|
|
493
|
+
const rawRepoRoot = resolve(args.values.has('repo') ? args.values.get('repo') : process.cwd());
|
|
494
|
+
const repoRoot = await canonicalPath(rawRepoRoot);
|
|
495
|
+
const checkOnly = args.flags.has('check');
|
|
496
|
+
try {
|
|
497
|
+
const manifestPath = await resolveRepoRelativeTaskpackPath(args.values.get('taskpack'), rawRepoRoot, repoRoot);
|
|
498
|
+
const manifest = await loadDeclarativeTaskpack({
|
|
499
|
+
manifestPath,
|
|
500
|
+
repositoryRoot: repoRoot,
|
|
501
|
+
policyProfile: 'local',
|
|
502
|
+
enforceHostAuthority: false,
|
|
503
|
+
});
|
|
504
|
+
const lockfilePath = resolveDigestLockfilePath(manifest, manifest.controlRoot);
|
|
505
|
+
if (checkOnly) {
|
|
506
|
+
const verified = await verifyDigestLockfile(repoRoot, manifest, manifest.controlRoot, lockfilePath);
|
|
507
|
+
if (verified.ok) {
|
|
508
|
+
await emit('digest', {
|
|
509
|
+
version: 1,
|
|
510
|
+
action: 'sync',
|
|
511
|
+
check: true,
|
|
512
|
+
ok: true,
|
|
513
|
+
taskpack: manifest.metadata.name,
|
|
514
|
+
lockfilePath: verified.lockfilePath,
|
|
515
|
+
entries: verified.computed.entries,
|
|
516
|
+
}, `digest sync --check: ok (${verified.computed.entries.length} entries in ${verified.lockfilePath})`);
|
|
517
|
+
return 0;
|
|
518
|
+
}
|
|
519
|
+
const scrubbedReason = createCliScrubber().scrub(verified.reason);
|
|
520
|
+
await emit('diagnostic', {
|
|
521
|
+
version: 1,
|
|
522
|
+
code: 'DIGEST_LOCKFILE_DRIFT',
|
|
523
|
+
message: scrubbedReason,
|
|
524
|
+
lockfilePath: verified.lockfilePath,
|
|
525
|
+
taskpack: manifest.metadata.name,
|
|
526
|
+
drifts: verified.drifts,
|
|
527
|
+
}, scrubbedReason);
|
|
528
|
+
return 4;
|
|
529
|
+
}
|
|
530
|
+
const lockfile = await computeTaskpackDigests(repoRoot, manifest, manifest.controlRoot);
|
|
531
|
+
await writeDigestLockfile(repoRoot, lockfilePath, lockfile);
|
|
532
|
+
await emit('digest', {
|
|
533
|
+
version: 1,
|
|
534
|
+
action: 'sync',
|
|
535
|
+
check: false,
|
|
536
|
+
ok: true,
|
|
537
|
+
taskpack: manifest.metadata.name,
|
|
538
|
+
lockfilePath,
|
|
539
|
+
entries: lockfile.entries,
|
|
540
|
+
}, `digest sync: wrote ${lockfile.entries.length} entries to ${lockfilePath}`);
|
|
541
|
+
return 0;
|
|
542
|
+
}
|
|
543
|
+
catch (err) {
|
|
544
|
+
if (err instanceof TaskpackError) {
|
|
545
|
+
return await emitTaskpackError(err, emit);
|
|
546
|
+
}
|
|
547
|
+
throw err;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
async function runStepCommand(args, json, emit) {
|
|
551
|
+
const get = (key) => args.values.get(key);
|
|
552
|
+
const runId = get('run-id');
|
|
553
|
+
const runRoot = resolve(get('run-root'));
|
|
554
|
+
const allowPrivileged = args.flags.has('allow-privileged');
|
|
555
|
+
const allowWorkflowWrites = args.flags.has('allow-workflow-writes');
|
|
556
|
+
let gateHandle = null;
|
|
557
|
+
let stagedDirToCleanOnUnadmittedFailure = null;
|
|
558
|
+
try {
|
|
559
|
+
const allowedHostMounts = parseAllowedHostMounts(args.values.get('allow-host-mounts'), '--allow-host-mounts');
|
|
560
|
+
const stepHostPolicy = {
|
|
561
|
+
policyProfile: 'local',
|
|
562
|
+
allowPrivileged,
|
|
563
|
+
allowWorkflowWrites,
|
|
564
|
+
allowedHostMounts,
|
|
565
|
+
};
|
|
566
|
+
let loadedConfiguration;
|
|
567
|
+
let resolvedRepo;
|
|
568
|
+
let stepped;
|
|
569
|
+
let caughtSignal = null;
|
|
570
|
+
try {
|
|
571
|
+
const overrideOpt = args.roleModelOverrides ? { roleModelOverrides: args.roleModelOverrides } : {};
|
|
572
|
+
if (args.stepAction === 'next' && args.values.has('taskpack')) {
|
|
573
|
+
const requestedRepo = await canonicalPath(get('repo'));
|
|
574
|
+
const preflightRunRoot = await inspectExistingDisjointRunRoot(runRoot, requestedRepo);
|
|
575
|
+
let hadRunDir = false;
|
|
576
|
+
if (preflightRunRoot.exists && preflightRunRoot.disjoint && preflightRunRoot.prospectiveRunRoot !== null) {
|
|
577
|
+
const runDirPath = join(preflightRunRoot.prospectiveRunRoot, runId);
|
|
578
|
+
hadRunDir = await lstat(runDirPath).then(() => true, () => false);
|
|
579
|
+
if (!hadRunDir) {
|
|
580
|
+
const stageCandidate = join(preflightRunRoot.prospectiveRunRoot, `.taskpack-${runId}`);
|
|
581
|
+
const stageStat = await lstat(stageCandidate).catch(() => null);
|
|
582
|
+
if (stageStat !== null
|
|
583
|
+
&& !stageStat.isSymbolicLink()
|
|
584
|
+
&& stageStat.isDirectory()
|
|
585
|
+
&& !isInsidePathRoot(requestedRepo, stageCandidate)) {
|
|
586
|
+
await removeStagedDirSafely(stageCandidate);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
const { baselineAlignment, sourceRevision } = parseTaskpackAlignmentArgs(args);
|
|
591
|
+
const staged = await stageTaskpackForStep({
|
|
592
|
+
taskpackPath: get('taskpack'),
|
|
593
|
+
repositoryRoot: requestedRepo,
|
|
594
|
+
runRoot,
|
|
595
|
+
runId,
|
|
596
|
+
mode: args.values.get('mode') ?? 'candidate',
|
|
597
|
+
...(baselineAlignment !== undefined ? { baselineAlignment } : {}),
|
|
598
|
+
...(sourceRevision !== undefined ? { sourceRevision } : {}),
|
|
599
|
+
policyProfile: 'local',
|
|
600
|
+
allowPrivileged,
|
|
601
|
+
allowWorkflowWrites,
|
|
602
|
+
allowedHostMounts,
|
|
603
|
+
hostPolicy: stepHostPolicy,
|
|
604
|
+
runPreflight: true,
|
|
605
|
+
runtimeEnv: process.env,
|
|
606
|
+
});
|
|
607
|
+
if (!hadRunDir)
|
|
608
|
+
stagedDirToCleanOnUnadmittedFailure = staged.stageDir;
|
|
609
|
+
const prevSecret = Object.hasOwn(process.env, staged.signingEnvName)
|
|
610
|
+
? process.env[staged.signingEnvName]
|
|
611
|
+
: undefined;
|
|
612
|
+
process.env[staged.signingEnvName] = staged.signingSecret;
|
|
613
|
+
let loaded;
|
|
614
|
+
try {
|
|
615
|
+
loaded = await loadTrustedConfiguration({
|
|
616
|
+
configPath: staged.configPath,
|
|
617
|
+
registryPath: staged.registryPath,
|
|
618
|
+
registrySha256: staged.registrySha256,
|
|
619
|
+
untrustedRoots: [requestedRepo, ...(requestedRepo !== staged.repositoryRoot ? [staged.repositoryRoot] : [])],
|
|
620
|
+
...overrideOpt,
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
finally {
|
|
624
|
+
if (prevSecret === undefined)
|
|
625
|
+
delete process.env[staged.signingEnvName];
|
|
626
|
+
else
|
|
627
|
+
process.env[staged.signingEnvName] = prevSecret;
|
|
628
|
+
}
|
|
629
|
+
if (!loaded.ok) {
|
|
630
|
+
await emit('diagnostic', loaded.error, loaded.error.code);
|
|
631
|
+
return diagnosticExit(loaded.error);
|
|
632
|
+
}
|
|
633
|
+
loadedConfiguration = loaded.value;
|
|
634
|
+
resolvedRepo = requestedRepo;
|
|
635
|
+
}
|
|
636
|
+
else if (args.stepAction === 'next' && args.values.has('config')) {
|
|
637
|
+
resolvedRepo = resolve(get('repo'));
|
|
638
|
+
const loaded = await loadTrustedConfiguration({
|
|
639
|
+
configPath: resolve(get('config')),
|
|
640
|
+
registryPath: resolve(get('registry')),
|
|
641
|
+
registrySha256: get('registry-sha256'),
|
|
642
|
+
untrustedRoots: [resolvedRepo],
|
|
643
|
+
...overrideOpt,
|
|
644
|
+
});
|
|
645
|
+
if (!loaded.ok) {
|
|
646
|
+
await emit('diagnostic', loaded.error, loaded.error.code);
|
|
647
|
+
return diagnosticExit(loaded.error);
|
|
648
|
+
}
|
|
649
|
+
loadedConfiguration = loaded.value;
|
|
650
|
+
}
|
|
651
|
+
gateHandle = args.stepAction === 'next' && args.values.has('config')
|
|
652
|
+
? null
|
|
653
|
+
: await openStagedTaskpackStepGate({ runRoot, runId, hostPolicy: stepHostPolicy, runtimeEnv: process.env });
|
|
654
|
+
const gateEnvOpt = gateHandle ? { environment: gateHandle.environment } : {};
|
|
655
|
+
const basePorts = gateHandle
|
|
656
|
+
? (gateHandle.ports ?? {
|
|
657
|
+
gateUrlOverrides: gateHandle.gateUrlOverrides,
|
|
658
|
+
...(gateHandle.allowWorkflowWrites !== undefined ? { allowWorkflowWrites: gateHandle.allowWorkflowWrites } : {}),
|
|
659
|
+
...(gateHandle.roleMcpServers !== undefined ? { roleMcpServers: gateHandle.roleMcpServers } : {}),
|
|
660
|
+
...(gateHandle.mcpServers !== undefined ? { mcpServers: gateHandle.mcpServers } : {}),
|
|
661
|
+
...(gateHandle.decisions !== undefined ? { decisions: gateHandle.decisions } : {}),
|
|
662
|
+
})
|
|
663
|
+
: {};
|
|
664
|
+
const gatePorts = allowWorkflowWrites && gateHandle === null
|
|
665
|
+
? { ...basePorts, allowWorkflowWrites: true }
|
|
666
|
+
: basePorts;
|
|
667
|
+
if (args.stepAction === 'next') {
|
|
668
|
+
const modeOpt = args.values.has('mode') ? { mode: get('mode') } : {};
|
|
669
|
+
const reissueOpt = args.flags.has('reissue-lease') ? { reissueLease: true } : {};
|
|
670
|
+
if (resolvedRepo === undefined && args.values.has('repo')) {
|
|
671
|
+
resolvedRepo = gateHandle !== null ? await canonicalPath(get('repo')) : resolve(get('repo'));
|
|
672
|
+
}
|
|
673
|
+
({ stepped, caughtSignal } = await withSignalAbort(async (signal, getSignal) => ({
|
|
674
|
+
stepped: await stepNext({
|
|
675
|
+
...(loadedConfiguration ? { configuration: loadedConfiguration } : {}),
|
|
676
|
+
...(resolvedRepo !== undefined ? { repository: resolvedRepo } : {}),
|
|
677
|
+
runRoot,
|
|
678
|
+
runId,
|
|
679
|
+
...modeOpt,
|
|
680
|
+
...reissueOpt,
|
|
681
|
+
...gateEnvOpt,
|
|
682
|
+
signal,
|
|
683
|
+
}, gatePorts),
|
|
684
|
+
caughtSignal: getSignal(),
|
|
685
|
+
})));
|
|
686
|
+
}
|
|
687
|
+
else if (args.stepAction === 'submit') {
|
|
688
|
+
({ stepped, caughtSignal } = await withSignalAbort(async (signal, getSignal) => ({
|
|
689
|
+
stepped: await stepSubmit({
|
|
690
|
+
runRoot,
|
|
691
|
+
runId,
|
|
692
|
+
leaseToken: get('lease'),
|
|
693
|
+
...(args.values.has('submission-file') ? { submissionFile: resolve(get('submission-file')) } : {}),
|
|
694
|
+
...(args.values.has('status') ? { status: get('status') } : {}),
|
|
695
|
+
...(args.values.has('reason') ? { reason: get('reason') } : {}),
|
|
696
|
+
...gateEnvOpt,
|
|
697
|
+
signal,
|
|
698
|
+
}, gatePorts),
|
|
699
|
+
caughtSignal: getSignal(),
|
|
700
|
+
})));
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
stepped = await stepCancel({ runRoot, runId, ...gateEnvOpt }, gatePorts);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
catch (err) {
|
|
707
|
+
if (err instanceof TaskpackError) {
|
|
708
|
+
return await emitTaskpackError(err, emit);
|
|
709
|
+
}
|
|
710
|
+
throw err;
|
|
711
|
+
}
|
|
712
|
+
if (!stepped.ok) {
|
|
713
|
+
await emit('diagnostic', stepped.error, stepped.error.code);
|
|
714
|
+
if (stepped.error.code === 'CANCELLED' && caughtSignal !== null) {
|
|
715
|
+
return caughtSignal === 'SIGTERM' ? 143 : 130;
|
|
716
|
+
}
|
|
717
|
+
return diagnosticExit(stepped.error);
|
|
718
|
+
}
|
|
719
|
+
const value = stepped.value;
|
|
720
|
+
if (value.kind === 'step') {
|
|
721
|
+
await emit('step', value, `awaiting_role: ${value.roleId} (${value.attemptId})`);
|
|
722
|
+
return 0;
|
|
723
|
+
}
|
|
724
|
+
await emitExecutionOutcome(args, runRoot, runId, json, value, loadedConfiguration, emit);
|
|
725
|
+
return executionExit(value, caughtSignal);
|
|
726
|
+
}
|
|
727
|
+
finally {
|
|
728
|
+
await gateHandle?.close();
|
|
729
|
+
if (stagedDirToCleanOnUnadmittedFailure !== null) {
|
|
730
|
+
const hasRunDirNow = await lstat(join(dirname(stagedDirToCleanOnUnadmittedFailure), runId)).then(() => true, () => false);
|
|
731
|
+
if (!hasRunDirNow) {
|
|
732
|
+
await removeStagedDirSafely(stagedDirToCleanOnUnadmittedFailure);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
const DRY_RUN_PUBLICATION_SENTINEL_URL = 'http://127.0.0.1:65535/loopwright-dry-run-publication';
|
|
738
|
+
function applyTaskpackRoleModelOverrides(manifest, overrides) {
|
|
739
|
+
if (overrides === undefined || overrides.length === 0) {
|
|
740
|
+
return { manifest };
|
|
741
|
+
}
|
|
742
|
+
const declaredRoles = manifest.spec.roles;
|
|
743
|
+
if (declaredRoles !== undefined && declaredRoles.length > 0) {
|
|
744
|
+
const byId = new Map();
|
|
745
|
+
const knownIds = new Set(declaredRoles.map(role => role.id));
|
|
746
|
+
for (const override of overrides) {
|
|
747
|
+
if (!knownIds.has(override.roleId)) {
|
|
748
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', `unknown --role-model role "${override.roleId}"`, '/roleModelOverrides');
|
|
749
|
+
}
|
|
750
|
+
byId.set(override.roleId, override);
|
|
751
|
+
}
|
|
752
|
+
const updatedRoles = declaredRoles.map(role => {
|
|
753
|
+
const override = byId.get(role.id);
|
|
754
|
+
if (override === undefined)
|
|
755
|
+
return role;
|
|
756
|
+
const { models: _unusedModels, ...roleBase } = role;
|
|
757
|
+
void _unusedModels;
|
|
758
|
+
return {
|
|
759
|
+
...roleBase,
|
|
760
|
+
provider: override.provider,
|
|
761
|
+
model: override.model,
|
|
762
|
+
...(override.thinking !== undefined ? { thinking: override.thinking } : {}),
|
|
763
|
+
};
|
|
764
|
+
});
|
|
765
|
+
return {
|
|
766
|
+
manifest: {
|
|
767
|
+
...manifest,
|
|
768
|
+
spec: {
|
|
769
|
+
...manifest.spec,
|
|
770
|
+
roles: updatedRoles,
|
|
771
|
+
},
|
|
772
|
+
},
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
let seenAuthor = false;
|
|
776
|
+
for (const override of overrides) {
|
|
777
|
+
if (override.roleId !== 'author') {
|
|
778
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', `unknown --role-model role "${override.roleId}"`, '/roleModelOverrides');
|
|
779
|
+
}
|
|
780
|
+
if (seenAuthor) {
|
|
781
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', 'duplicate --role-model override for role "author"', '/roleModelOverrides');
|
|
782
|
+
}
|
|
783
|
+
seenAuthor = true;
|
|
784
|
+
}
|
|
785
|
+
const authorOverride = overrides[0];
|
|
786
|
+
return {
|
|
787
|
+
manifest,
|
|
788
|
+
roleSelection: {
|
|
789
|
+
provider: authorOverride.provider,
|
|
790
|
+
model: authorOverride.model,
|
|
791
|
+
...(authorOverride.thinking !== undefined ? { thinking: authorOverride.thinking } : {}),
|
|
792
|
+
},
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function turnkeySummaryExit(summary, signal) {
|
|
796
|
+
switch (summary.status) {
|
|
797
|
+
case 'completed':
|
|
798
|
+
case 'no_change':
|
|
799
|
+
return 0;
|
|
800
|
+
case 'blocked':
|
|
801
|
+
return 3;
|
|
802
|
+
case 'exhausted':
|
|
803
|
+
return 5;
|
|
804
|
+
case 'expired':
|
|
805
|
+
return 6;
|
|
806
|
+
case 'reconcile_required':
|
|
807
|
+
return 7;
|
|
808
|
+
case 'cancelled':
|
|
809
|
+
return signal === 'SIGTERM' ? 143 : 130;
|
|
810
|
+
default:
|
|
811
|
+
break;
|
|
812
|
+
}
|
|
813
|
+
switch (summary.reasonCode) {
|
|
814
|
+
case 'RECOVERY_REQUIRED':
|
|
815
|
+
case 'AUTHORITY_REFUSED':
|
|
816
|
+
case 'OWNER_BUSY':
|
|
817
|
+
case 'RECEIPT_CONFLICT':
|
|
818
|
+
return 7;
|
|
819
|
+
case 'CAPABILITY_UNSUPPORTED':
|
|
820
|
+
case 'MCP_AUTHENTICATION_REQUIRED':
|
|
821
|
+
return 3;
|
|
822
|
+
case 'BUDGET_EXHAUSTED':
|
|
823
|
+
case 'ATTEMPT_LIMIT':
|
|
824
|
+
case 'REPEAT_FAILURE':
|
|
825
|
+
return 5;
|
|
826
|
+
case 'DEADLINE':
|
|
827
|
+
return 6;
|
|
828
|
+
case 'CANCELLED':
|
|
829
|
+
return signal === 'SIGTERM' ? 143 : 130;
|
|
830
|
+
case 'STATE_UNAVAILABLE':
|
|
831
|
+
case 'CLEANUP_FAILED':
|
|
832
|
+
case 'ARTIFACT_INVALID':
|
|
833
|
+
case 'OUTPUT_LIMIT':
|
|
834
|
+
return 8;
|
|
835
|
+
default:
|
|
836
|
+
return 4;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
async function writeCompiledTaskpackDir(trustedDirectory, compiled, scrubber) {
|
|
840
|
+
const registryDirectory = join(trustedDirectory, 'registry');
|
|
841
|
+
const configDirectory = join(trustedDirectory, 'config');
|
|
842
|
+
await mkdir(registryDirectory, { recursive: true, mode: 0o700 });
|
|
843
|
+
await mkdir(configDirectory, { recursive: true, mode: 0o700 });
|
|
844
|
+
await chmod(trustedDirectory, 0o700);
|
|
845
|
+
await chmod(registryDirectory, 0o700);
|
|
846
|
+
await chmod(configDirectory, 0o700);
|
|
847
|
+
const registryPath = join(registryDirectory, 'registry.yaml');
|
|
848
|
+
const configPath = join(configDirectory, 'config.yaml');
|
|
849
|
+
const configBytes = Buffer.from(serializePrettyYaml(compiled.config), 'utf8');
|
|
850
|
+
assertCleanArtifact(compiled.registryBytes, scrubber, '/registry');
|
|
851
|
+
assertCleanArtifact(configBytes, scrubber, '/config');
|
|
852
|
+
for (const resource of compiled.instructionResources ?? []) {
|
|
853
|
+
assertCleanArtifact(resource.bytes, scrubber, `/resources/${resource.id}`);
|
|
854
|
+
}
|
|
855
|
+
await writeFile(registryPath, compiled.registryBytes, { mode: 0o600 });
|
|
856
|
+
await writeFile(configPath, configBytes, { mode: 0o600 });
|
|
857
|
+
await chmod(registryPath, 0o600);
|
|
858
|
+
await chmod(configPath, 0o600);
|
|
859
|
+
if (compiled.instructionResources !== undefined && compiled.instructionResources.length > 0) {
|
|
860
|
+
await stageCompiledInstructionResources(registryDirectory, compiled.instructionResources);
|
|
861
|
+
}
|
|
862
|
+
return {
|
|
863
|
+
...compiled,
|
|
864
|
+
configBytes,
|
|
865
|
+
trustedDirectory,
|
|
866
|
+
registryPath,
|
|
867
|
+
configPath,
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
async function validateManifestCommandToolchainPaths(manifest, repositoryRoot, allowPrivileged) {
|
|
871
|
+
let realTmpRoot;
|
|
872
|
+
for (const check of manifest.spec.verification.localChecks) {
|
|
873
|
+
if (check.implementation !== 'command.v1')
|
|
874
|
+
continue;
|
|
875
|
+
const rawPaths = check.parameters?.['toolchainPaths'];
|
|
876
|
+
if (!Array.isArray(rawPaths) || rawPaths.length === 0)
|
|
877
|
+
continue;
|
|
878
|
+
realTmpRoot ??= await realpath(tmpdir());
|
|
879
|
+
const script = typeof check.parameters?.['script'] === 'string' ? check.parameters['script'] : '';
|
|
880
|
+
const gate = {
|
|
881
|
+
checkId: check.id,
|
|
882
|
+
gateId: `precheck-${check.id}`,
|
|
883
|
+
endpointRef: 'loopwright-local-command',
|
|
884
|
+
script,
|
|
885
|
+
scriptSha256: '0'.repeat(64),
|
|
886
|
+
timeoutSeconds: 30,
|
|
887
|
+
allowReadOnlyGitHubToken: false,
|
|
888
|
+
env: [],
|
|
889
|
+
allowPrivileged,
|
|
890
|
+
};
|
|
891
|
+
for (const tp of rawPaths) {
|
|
892
|
+
if (typeof tp !== 'string')
|
|
893
|
+
continue;
|
|
894
|
+
await validateGateToolchainPath(tp, gate, repositoryRoot, realTmpRoot);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
async function runTaskpackCommand(args, json, emit) {
|
|
899
|
+
const get = (key) => args.values.get(key);
|
|
900
|
+
const dryRun = args.flags.has('dry-run');
|
|
901
|
+
const allowPrivileged = args.flags.has('allow-privileged');
|
|
902
|
+
const allowWorkflowWrites = args.flags.has('allow-workflow-writes');
|
|
903
|
+
const output = args.values.get('output');
|
|
904
|
+
const scrubber = createCliScrubber();
|
|
905
|
+
let localGateServer;
|
|
906
|
+
let mcpRegistry;
|
|
907
|
+
let preflightResult;
|
|
908
|
+
try {
|
|
909
|
+
const rawRepoRoot = resolve(get('repo'));
|
|
910
|
+
let repoRoot;
|
|
911
|
+
try {
|
|
912
|
+
repoRoot = await realpath(rawRepoRoot);
|
|
913
|
+
const repoStat = await lstat(repoRoot);
|
|
914
|
+
if (!repoStat.isDirectory()) {
|
|
915
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', 'repositoryRoot must exist');
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
catch (err) {
|
|
919
|
+
if (err instanceof TaskpackError)
|
|
920
|
+
throw err;
|
|
921
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', 'repositoryRoot must exist');
|
|
922
|
+
}
|
|
923
|
+
const allowedHostMounts = parseAllowedHostMounts(args.values.get('allow-host-mounts'), '--allow-host-mounts');
|
|
924
|
+
const relativeTaskpackPath = await resolveRepoRelativeTaskpackPath(get('taskpack'), rawRepoRoot, repoRoot);
|
|
925
|
+
const hostPolicy = {
|
|
926
|
+
policyProfile: 'local',
|
|
927
|
+
allowPrivileged,
|
|
928
|
+
allowWorkflowWrites,
|
|
929
|
+
allowedHostMounts,
|
|
930
|
+
};
|
|
931
|
+
const rawManifest = await loadDeclarativeTaskpack({
|
|
932
|
+
manifestPath: relativeTaskpackPath,
|
|
933
|
+
repositoryRoot: repoRoot,
|
|
934
|
+
policyProfile: 'local',
|
|
935
|
+
hostPolicy,
|
|
936
|
+
});
|
|
937
|
+
if (!dryRun) {
|
|
938
|
+
if (rawManifest.spec.publication.mode === 'pull_request') {
|
|
939
|
+
throw new TaskpackError('TASKPACK_HOST_BINDING_INVALID', 'local CLI "loopwright run --taskpack" has no GitHub pull-request publisher bound; set spec.publication.mode to "disabled" or run via GitHub Action/App', '/spec/publication/mode');
|
|
940
|
+
}
|
|
941
|
+
if (rawManifest.spec.memory.apply === 'separate-pull-request') {
|
|
942
|
+
throw new TaskpackError('TASKPACK_HOST_BINDING_INVALID', 'local CLI "loopwright run --taskpack" has no GitHub pull-request memory publisher bound; set spec.memory.apply to "local-only" or "disabled"', '/spec/memory/apply');
|
|
943
|
+
}
|
|
944
|
+
if (rawManifest.spec.memory.apply === 'inline-with-candidate') {
|
|
945
|
+
throw new TaskpackError('TASKPACK_HOST_BINDING_INVALID', 'local CLI "loopwright run --taskpack" cannot publish a candidate pull request for memory.apply "inline-with-candidate"; set spec.memory.apply to "local-only" or "disabled", or run via GitHub Action/App', '/spec/memory/apply');
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
const { manifest, roleSelection } = applyTaskpackRoleModelOverrides(rawManifest, args.roleModelOverrides);
|
|
949
|
+
const manifestSecretEnvs = collectManifestSecretEnvNames(manifest);
|
|
950
|
+
for (const envName of manifestSecretEnvs) {
|
|
951
|
+
const val = process.env[envName];
|
|
952
|
+
if (typeof val === 'string' && val.length > 0)
|
|
953
|
+
scrubber.register(val);
|
|
954
|
+
}
|
|
955
|
+
const { baselineAlignment, sourceRevision: explicitSourceRevision } = parseTaskpackAlignmentArgs(args);
|
|
956
|
+
const envRepo = process.env['LOOPWRIGHT_REPOSITORY']?.trim();
|
|
957
|
+
const repositoryFullName = envRepo !== undefined && REPOSITORY_FULL_NAME_PATTERN.test(envRepo)
|
|
958
|
+
? envRepo
|
|
959
|
+
: 'local/repo';
|
|
960
|
+
const resolvedRepo = await resolveRepositoryAndRevisions({
|
|
961
|
+
repositoryRoot: repoRoot,
|
|
962
|
+
repositoryFullName,
|
|
963
|
+
baseRevision: 'HEAD',
|
|
964
|
+
...(explicitSourceRevision !== undefined
|
|
965
|
+
? { sourceRevision: explicitSourceRevision, preserveExplicitSourceRevision: true }
|
|
966
|
+
: {}),
|
|
967
|
+
eventName: 'workflow_dispatch',
|
|
968
|
+
scrubber,
|
|
969
|
+
});
|
|
970
|
+
const modelsJsonPath = process.env['LOOPWRIGHT_MODELS_JSON']?.trim() || undefined;
|
|
971
|
+
const modelsConfig = modelsJsonPath !== undefined
|
|
972
|
+
? await loadPiModelsJson(modelsJsonPath)
|
|
973
|
+
: undefined;
|
|
974
|
+
const allowManifestCustomBaseUrl = process.env['LOOPWRIGHT_ALLOW_MANIFEST_CUSTOM_BASE_URL'] === 'true';
|
|
975
|
+
const envLimits = parseLoopwrightEnvLimits(process.env);
|
|
976
|
+
const actionInputLimits = parseActionInputLimits(process.env);
|
|
977
|
+
const requestedMode = args.values.get('mode') ?? 'auto';
|
|
978
|
+
if (dryRun) {
|
|
979
|
+
const effectiveDryRunMode = requestedMode === 'no-change' ? 'no-change' : 'candidate';
|
|
980
|
+
const defaultProviderEnv = roleSelection?.provider !== undefined
|
|
981
|
+
? resolveDefaultProviderTokenEnv(roleSelection.provider, {
|
|
982
|
+
modelsJsonApiKeyEnv: modelsConfig?.providers.get(roleSelection.provider)?.apiKeyEnv,
|
|
983
|
+
env: process.env,
|
|
984
|
+
})
|
|
985
|
+
: manifest.spec.models !== undefined && manifest.spec.models.length > 0
|
|
986
|
+
? (manifest.spec.models[0].apiKeyEnv ?? resolveDefaultProviderTokenEnv(manifest.spec.models[0].provider, {
|
|
987
|
+
modelsJsonApiKeyEnv: modelsConfig?.providers.get(manifest.spec.models[0].provider)?.apiKeyEnv,
|
|
988
|
+
env: process.env,
|
|
989
|
+
}))
|
|
990
|
+
: 'LOOPWRIGHT_PROVIDER_TOKEN';
|
|
991
|
+
const dryRunBindings = {
|
|
992
|
+
mode: effectiveDryRunMode,
|
|
993
|
+
hostPolicy,
|
|
994
|
+
repository: repositoryFullName,
|
|
995
|
+
repositoryRoot: repoRoot,
|
|
996
|
+
taskpackPath: relativeTaskpackPath,
|
|
997
|
+
baseRevision: resolvedRepo.baseRevision,
|
|
998
|
+
sourceRevision: resolvedRepo.sourceRevision,
|
|
999
|
+
...(baselineAlignment !== undefined ? { baselineAlignment } : {}),
|
|
1000
|
+
targetMatrix: manifest.spec.target?.matrix ?? null,
|
|
1001
|
+
...(roleSelection !== undefined ? { roleSelection } : {}),
|
|
1002
|
+
allowManifestCustomBaseUrl,
|
|
1003
|
+
modelsJsonPath,
|
|
1004
|
+
budgets: DEFAULT_HOST_BUDGETS,
|
|
1005
|
+
limits: actionInputLimits,
|
|
1006
|
+
envLimits,
|
|
1007
|
+
publicationEndpoint: effectiveDryRunMode === 'candidate' && manifest.spec.publication.mode === 'pull_request'
|
|
1008
|
+
? {
|
|
1009
|
+
id: 'dry-run-publication',
|
|
1010
|
+
url: DRY_RUN_PUBLICATION_SENTINEL_URL,
|
|
1011
|
+
signingCredentialRef: 'taskpack-publication-signing',
|
|
1012
|
+
}
|
|
1013
|
+
: null,
|
|
1014
|
+
credentialEnvMap: {
|
|
1015
|
+
provider: defaultProviderEnv,
|
|
1016
|
+
gate: 'LOOPWRIGHT_GATE_SIGNING_SECRET',
|
|
1017
|
+
publication: 'LOOPWRIGHT_PUBLICATION_SIGNING_SECRET',
|
|
1018
|
+
publicationAuth: 'LOOPWRIGHT_PUBLICATION_AUTH_TOKEN',
|
|
1019
|
+
localCommandGate: DEFAULT_LOCAL_COMMAND_GATE_ENV,
|
|
1020
|
+
},
|
|
1021
|
+
scrubber,
|
|
1022
|
+
};
|
|
1023
|
+
const compiled = await compileDeclarativeTaskpack(manifest, dryRunBindings);
|
|
1024
|
+
const dryRunRoot = await realpath(await mkdtemp(join(tmpdir(), 'loopwright-dryrun-')));
|
|
1025
|
+
const savedEnv = new Map();
|
|
1026
|
+
try {
|
|
1027
|
+
const written = await writeCompiledTaskpackDir(dryRunRoot, compiled, scrubber);
|
|
1028
|
+
for (const binding of compiled.registry.spec.environmentBindings) {
|
|
1029
|
+
if (binding.classification === 'credential' && process.env[binding.name] === undefined) {
|
|
1030
|
+
savedEnv.set(binding.name, undefined);
|
|
1031
|
+
process.env[binding.name] = `dry-run-${randomBytes(8).toString('hex')}`;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
const loaded = await loadTrustedConfiguration({
|
|
1035
|
+
configPath: written.configPath,
|
|
1036
|
+
registryPath: written.registryPath,
|
|
1037
|
+
registrySha256: written.registrySha256,
|
|
1038
|
+
untrustedRoots: [repoRoot],
|
|
1039
|
+
});
|
|
1040
|
+
if (!loaded.ok) {
|
|
1041
|
+
await emit('diagnostic', loaded.error, loaded.error.code);
|
|
1042
|
+
return diagnosticExit(loaded.error);
|
|
1043
|
+
}
|
|
1044
|
+
const plan = await compilePlan(loaded.value);
|
|
1045
|
+
if (!plan.ok) {
|
|
1046
|
+
await emit('diagnostic', plan.error, plan.error.code);
|
|
1047
|
+
return diagnosticExit(plan.error);
|
|
1048
|
+
}
|
|
1049
|
+
if (output !== undefined)
|
|
1050
|
+
await writeOutput(output, Buffer.from(encoded(plan.value) + '\n'));
|
|
1051
|
+
await emit('plan', plan.value, 'Plan checked; admission not performed; execution readiness not checked.');
|
|
1052
|
+
return 0;
|
|
1053
|
+
}
|
|
1054
|
+
finally {
|
|
1055
|
+
for (const [key, prior] of savedEnv.entries()) {
|
|
1056
|
+
if (prior === undefined)
|
|
1057
|
+
delete process.env[key];
|
|
1058
|
+
else
|
|
1059
|
+
process.env[key] = prior;
|
|
1060
|
+
}
|
|
1061
|
+
await removeStagedDirSafely(dryRunRoot);
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
const runId = get('run-id');
|
|
1065
|
+
const resolvedRunRoot = resolve(get('run-root'));
|
|
1066
|
+
const preflightRootCheck = await inspectExistingDisjointRunRoot(resolvedRunRoot, repoRoot);
|
|
1067
|
+
if (preflightRootCheck.prospectiveRunRoot === null || !preflightRootCheck.disjoint) {
|
|
1068
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', 'runRoot must be a non-symlink directory outside the target repository checkout');
|
|
1069
|
+
}
|
|
1070
|
+
await mkdir(resolvedRunRoot, { recursive: true, mode: 0o700 });
|
|
1071
|
+
const runRootStat = await lstat(resolvedRunRoot);
|
|
1072
|
+
if (runRootStat.isSymbolicLink() || !runRootStat.isDirectory()) {
|
|
1073
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', 'runRoot must be a non-symlink directory');
|
|
1074
|
+
}
|
|
1075
|
+
await chmod(resolvedRunRoot, 0o700);
|
|
1076
|
+
const realRunRoot = await realpath(resolvedRunRoot);
|
|
1077
|
+
if (insideRoot(realRunRoot, repoRoot) || insideRoot(repoRoot, realRunRoot)) {
|
|
1078
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', 'runRoot must live outside the target repository checkout');
|
|
1079
|
+
}
|
|
1080
|
+
let upstreamRecords = [];
|
|
1081
|
+
let autoNoChangeReason = null;
|
|
1082
|
+
if (manifest.spec.preflight !== undefined) {
|
|
1083
|
+
const preflightRun = await withSignalAbort(async (signal, getCaughtSignal) => ({
|
|
1084
|
+
result: await runTaskpackPreflight({
|
|
1085
|
+
manifest,
|
|
1086
|
+
repositoryRoot: repoRoot,
|
|
1087
|
+
authorized: true,
|
|
1088
|
+
hostPolicy,
|
|
1089
|
+
env: process.env,
|
|
1090
|
+
scrubber,
|
|
1091
|
+
tempRoot: realRunRoot,
|
|
1092
|
+
signal,
|
|
1093
|
+
}),
|
|
1094
|
+
caughtSignal: getCaughtSignal(),
|
|
1095
|
+
}));
|
|
1096
|
+
preflightResult = preflightRun.result;
|
|
1097
|
+
if (preflightRun.caughtSignal !== null) {
|
|
1098
|
+
return preflightRun.caughtSignal === 'SIGTERM' ? 143 : 130;
|
|
1099
|
+
}
|
|
1100
|
+
if (preflightResult.disposition === 'blocked') {
|
|
1101
|
+
const rawReason = preflightResult.reason?.trim();
|
|
1102
|
+
const message = rawReason !== undefined && rawReason.length > 0
|
|
1103
|
+
? `preflight blocked: ${rawReason}`
|
|
1104
|
+
: 'preflight blocked: blocked by preflight';
|
|
1105
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', scrubber.scrub(message));
|
|
1106
|
+
}
|
|
1107
|
+
if (requestedMode === 'auto' && preflightResult.disposition === 'no_change') {
|
|
1108
|
+
autoNoChangeReason = preflightResult.reason ?? 'preflight returned no_change';
|
|
1109
|
+
}
|
|
1110
|
+
upstreamRecords = preflightResult.upstreams;
|
|
1111
|
+
}
|
|
1112
|
+
if (manifest.spec.upstreams.length > 0 && upstreamRecords.length === 0) {
|
|
1113
|
+
const discovered = await discoverTaskpackUpstreamsV2(manifest, {
|
|
1114
|
+
repositoryRoot: repoRoot,
|
|
1115
|
+
scrubber,
|
|
1116
|
+
env: process.env,
|
|
1117
|
+
});
|
|
1118
|
+
upstreamRecords = discovered.records;
|
|
1119
|
+
if (requestedMode === 'auto' && autoNoChangeReason === null) {
|
|
1120
|
+
const intakeDisp = evaluateUpstreamIntakeDisposition(discovered.records);
|
|
1121
|
+
if (intakeDisp.disposition === 'blocked') {
|
|
1122
|
+
throw new TaskpackError('ACTION_INPUT_INVALID', scrubber.scrub(intakeDisp.reason));
|
|
1123
|
+
}
|
|
1124
|
+
if (intakeDisp.disposition === 'no_change') {
|
|
1125
|
+
autoNoChangeReason = intakeDisp.reason;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
const isAutoNoChange = requestedMode === 'auto' && autoNoChangeReason !== null;
|
|
1130
|
+
const effectiveMode = (requestedMode === 'no-change' || isAutoNoChange)
|
|
1131
|
+
? 'no-change'
|
|
1132
|
+
: 'candidate';
|
|
1133
|
+
let baselineAlignmentResult;
|
|
1134
|
+
if (effectiveMode === 'candidate' && resolvedRepo.sourceRevision !== resolvedRepo.baseRevision) {
|
|
1135
|
+
baselineAlignmentResult = await alignBaselineRevisions({
|
|
1136
|
+
repositoryRoot: repoRoot,
|
|
1137
|
+
baseRevision: resolvedRepo.baseRevision,
|
|
1138
|
+
sourceRevision: resolvedRepo.sourceRevision,
|
|
1139
|
+
manifest,
|
|
1140
|
+
taskpackPath: relativeTaskpackPath,
|
|
1141
|
+
policyProfile: 'local',
|
|
1142
|
+
hostPolicy,
|
|
1143
|
+
...(baselineAlignment !== undefined ? { baselineAlignment } : {}),
|
|
1144
|
+
scrubber,
|
|
1145
|
+
scratchRoot: realRunRoot,
|
|
1146
|
+
});
|
|
1147
|
+
if (baselineAlignmentResult.status === 'blocked') {
|
|
1148
|
+
throw new TaskpackError('TASKPACK_SCOPE_VIOLATION', baselineAlignmentResult.detail, '/spec/baselineAlignment', { reason: baselineAlignmentResult.reason });
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
const enableBaselineConflictGate = effectiveMode === 'candidate'
|
|
1152
|
+
&& baselineAlignmentResult !== undefined
|
|
1153
|
+
&& (baselineAlignmentResult.conflictResource !== null || baselineAlignmentResult.disposition === 'unmerged_off');
|
|
1154
|
+
let activeGateEndpoints = [];
|
|
1155
|
+
let trackedSourceTokenEnvNames = [];
|
|
1156
|
+
const buildBindings = (candidate) => {
|
|
1157
|
+
const externalMcpTools = mcpRegistry !== undefined && mcpRegistry.toolNames.length > 0
|
|
1158
|
+
? mcpRegistry.toolNames
|
|
1159
|
+
: undefined;
|
|
1160
|
+
const externalMcpToolSchemas = mcpRegistry !== undefined && externalMcpTools !== undefined
|
|
1161
|
+
? mcpRegistry.toolSchemasFor(externalMcpTools)
|
|
1162
|
+
: undefined;
|
|
1163
|
+
const acceptanceCheckIds = [
|
|
1164
|
+
...manifest.spec.verification.localChecks.map(check => check.id),
|
|
1165
|
+
...manifest.spec.verification.externalGates.map(gate => gate.id),
|
|
1166
|
+
];
|
|
1167
|
+
const basePrompt = buildDefaultAuthorPrompt({
|
|
1168
|
+
mode: effectiveMode,
|
|
1169
|
+
repositoryFullName,
|
|
1170
|
+
upstreamRecords,
|
|
1171
|
+
externalMcpTools,
|
|
1172
|
+
acceptanceCheckIds,
|
|
1173
|
+
runtimeEnv: process.env,
|
|
1174
|
+
scrubber,
|
|
1175
|
+
});
|
|
1176
|
+
const wsManifestText = preflightResult !== undefined && preflightResult.workspaceResources.length > 0
|
|
1177
|
+
? formatWorkspaceResourcesManifest(preflightResult.workspaceResources, preflightResult.stagedDir, scrubber)
|
|
1178
|
+
: undefined;
|
|
1179
|
+
const authorPrompt = wsManifestText !== undefined && wsManifestText.length > 0
|
|
1180
|
+
? `${basePrompt}\n\n${wsManifestText}`
|
|
1181
|
+
: basePrompt;
|
|
1182
|
+
return {
|
|
1183
|
+
mode: effectiveMode,
|
|
1184
|
+
...(isAutoNoChange ? { checkOnlyNoChange: true } : {}),
|
|
1185
|
+
hostPolicy,
|
|
1186
|
+
repository: repositoryFullName,
|
|
1187
|
+
repositoryRoot: repoRoot,
|
|
1188
|
+
taskpackPath: relativeTaskpackPath,
|
|
1189
|
+
baseRevision: resolvedRepo.baseRevision,
|
|
1190
|
+
sourceRevision: resolvedRepo.sourceRevision,
|
|
1191
|
+
...(baselineAlignment !== undefined ? { baselineAlignment } : {}),
|
|
1192
|
+
...(baselineAlignmentResult !== undefined ? { baselineAlignmentResult } : {}),
|
|
1193
|
+
...(baselineAlignmentResult?.conflictResource != null ? { baselineConflictResource: baselineAlignmentResult.conflictResource } : {}),
|
|
1194
|
+
...(enableBaselineConflictGate ? { enableBaselineConflictGate: true } : {}),
|
|
1195
|
+
upstreamRecords,
|
|
1196
|
+
targetMatrix: manifest.spec.target?.matrix ?? null,
|
|
1197
|
+
...(roleSelection !== undefined ? { roleSelection } : {}),
|
|
1198
|
+
...(candidate !== undefined && roleSelection === undefined ? { candidateIndex: candidate.manifestIndex } : {}),
|
|
1199
|
+
allowManifestCustomBaseUrl,
|
|
1200
|
+
modelsJsonPath,
|
|
1201
|
+
budgets: DEFAULT_HOST_BUDGETS,
|
|
1202
|
+
limits: actionInputLimits,
|
|
1203
|
+
envLimits,
|
|
1204
|
+
...(externalMcpTools !== undefined ? { externalMcpTools } : {}),
|
|
1205
|
+
...(externalMcpToolSchemas !== undefined ? { externalMcpToolSchemas } : {}),
|
|
1206
|
+
gateEndpoints: activeGateEndpoints,
|
|
1207
|
+
publicationEndpoint: null,
|
|
1208
|
+
credentialEnvMap: {
|
|
1209
|
+
...(candidate !== undefined
|
|
1210
|
+
? { provider: candidate.providerEnvName }
|
|
1211
|
+
: (roleSelection?.provider !== undefined
|
|
1212
|
+
? {
|
|
1213
|
+
provider: resolveDefaultProviderTokenEnv(roleSelection.provider, {
|
|
1214
|
+
modelsJsonApiKeyEnv: modelsConfig?.providers.get(roleSelection.provider)?.apiKeyEnv,
|
|
1215
|
+
env: process.env,
|
|
1216
|
+
}),
|
|
1217
|
+
}
|
|
1218
|
+
: {})),
|
|
1219
|
+
gate: 'LOOPWRIGHT_GATE_SIGNING_SECRET',
|
|
1220
|
+
publication: 'LOOPWRIGHT_PUBLICATION_SIGNING_SECRET',
|
|
1221
|
+
publicationAuth: 'LOOPWRIGHT_PUBLICATION_AUTH_TOKEN',
|
|
1222
|
+
localCommandGate: DEFAULT_LOCAL_COMMAND_GATE_ENV,
|
|
1223
|
+
},
|
|
1224
|
+
...(trackedSourceTokenEnvNames.length > 0 ? { sourceTokenEnvNames: trackedSourceTokenEnvNames } : {}),
|
|
1225
|
+
authorPrompt,
|
|
1226
|
+
preflightPromptResources: preflightResult?.promptResources,
|
|
1227
|
+
preflightWorkspaceResources: preflightResult?.workspaceResources,
|
|
1228
|
+
scrubber,
|
|
1229
|
+
};
|
|
1230
|
+
};
|
|
1231
|
+
const roleProviderEnvNames = [];
|
|
1232
|
+
if (!isAutoNoChange && manifest.spec.roles !== undefined && manifest.spec.roles.length > 0) {
|
|
1233
|
+
for (const role of manifest.spec.roles) {
|
|
1234
|
+
const roleBindings = {
|
|
1235
|
+
...buildBindings(),
|
|
1236
|
+
candidateIndex: undefined,
|
|
1237
|
+
roleSelection: {
|
|
1238
|
+
provider: role.provider,
|
|
1239
|
+
model: role.model,
|
|
1240
|
+
...(role.thinking !== undefined ? { thinking: role.thinking } : {}),
|
|
1241
|
+
},
|
|
1242
|
+
};
|
|
1243
|
+
const { selection, apiKeyEnv } = resolveTaskpackModelSelection(manifest, roleBindings, modelsConfig);
|
|
1244
|
+
const modelsJsonApiKeyEnv = modelsConfig?.providers.get(selection.provider)?.apiKeyEnv;
|
|
1245
|
+
roleProviderEnvNames.push(resolveDefaultProviderTokenEnv(selection.provider, {
|
|
1246
|
+
modelsJsonApiKeyEnv,
|
|
1247
|
+
manifestApiKeyEnv: apiKeyEnv,
|
|
1248
|
+
env: process.env,
|
|
1249
|
+
}));
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
let activeCandidate;
|
|
1253
|
+
if (isAutoNoChange) {
|
|
1254
|
+
try {
|
|
1255
|
+
const ncCandidates = resolveTaskpackModelCandidates(manifest, buildBindings(), {
|
|
1256
|
+
modelsConfig,
|
|
1257
|
+
env: process.env,
|
|
1258
|
+
scrubber,
|
|
1259
|
+
});
|
|
1260
|
+
activeCandidate = ncCandidates[0];
|
|
1261
|
+
}
|
|
1262
|
+
catch (err) {
|
|
1263
|
+
if (err instanceof TaskpackError && err.code === 'PROVIDER_OAUTH_UNSUPPORTED')
|
|
1264
|
+
throw err;
|
|
1265
|
+
activeCandidate = undefined;
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
else {
|
|
1269
|
+
if (effectiveMode === 'candidate') {
|
|
1270
|
+
await validateManifestCommandToolchainPaths(manifest, repoRoot, hostPolicy.allowPrivileged === true);
|
|
1271
|
+
}
|
|
1272
|
+
const firstRole = manifest.spec.roles?.[0];
|
|
1273
|
+
const candidateBaseBindings = (manifest.spec.models === undefined && firstRole !== undefined && roleSelection === undefined)
|
|
1274
|
+
? {
|
|
1275
|
+
...buildBindings(),
|
|
1276
|
+
roleSelection: {
|
|
1277
|
+
provider: firstRole.provider,
|
|
1278
|
+
model: firstRole.model,
|
|
1279
|
+
...(firstRole.thinking !== undefined ? { thinking: firstRole.thinking } : {}),
|
|
1280
|
+
},
|
|
1281
|
+
}
|
|
1282
|
+
: buildBindings();
|
|
1283
|
+
const candidates = resolveTaskpackModelCandidates(manifest, candidateBaseBindings, {
|
|
1284
|
+
modelsConfig,
|
|
1285
|
+
env: process.env,
|
|
1286
|
+
scrubber,
|
|
1287
|
+
});
|
|
1288
|
+
if (candidates.length >= 2) {
|
|
1289
|
+
const selected = await selectHealthyModelCandidate(candidates, { scrubber });
|
|
1290
|
+
activeCandidate = candidates[selected.index];
|
|
1291
|
+
}
|
|
1292
|
+
else {
|
|
1293
|
+
activeCandidate = candidates[0];
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
const effectiveMcpDecls = manifest.spec.mcp?.servers ?? [];
|
|
1297
|
+
const forbiddenCommandEnvNames = new Set([
|
|
1298
|
+
...Object.values(STANDARD_PI_PROVIDER_ENV),
|
|
1299
|
+
...(activeCandidate !== undefined
|
|
1300
|
+
? [
|
|
1301
|
+
activeCandidate.providerEnvName,
|
|
1302
|
+
...(activeCandidate.sourceTokenEnvName !== undefined ? [activeCandidate.sourceTokenEnvName] : []),
|
|
1303
|
+
]
|
|
1304
|
+
: []),
|
|
1305
|
+
...roleProviderEnvNames,
|
|
1306
|
+
...(manifest.spec.roles?.map(role => resolveDefaultProviderTokenEnv(role.provider, { env: process.env })) ?? []),
|
|
1307
|
+
'LOOPWRIGHT_GATE_SIGNING_SECRET',
|
|
1308
|
+
'LOOPWRIGHT_PUBLICATION_SIGNING_SECRET',
|
|
1309
|
+
'LOOPWRIGHT_PUBLICATION_AUTH_TOKEN',
|
|
1310
|
+
DEFAULT_LOCAL_COMMAND_GATE_ENV,
|
|
1311
|
+
...manifestSecretEnvs,
|
|
1312
|
+
...collectMcpReferencedEnvNames(effectiveMcpDecls),
|
|
1313
|
+
]);
|
|
1314
|
+
trackedSourceTokenEnvNames = [...forbiddenCommandEnvNames];
|
|
1315
|
+
if (!isAutoNoChange && effectiveMcpDecls.length > 0) {
|
|
1316
|
+
const resolvedMcpConfigs = resolveExternalMcpConfigs({
|
|
1317
|
+
declarations: effectiveMcpDecls,
|
|
1318
|
+
runtimeEnv: process.env,
|
|
1319
|
+
allowLoopbackHttp: allowManifestCustomBaseUrl,
|
|
1320
|
+
scrubber,
|
|
1321
|
+
});
|
|
1322
|
+
if (resolvedMcpConfigs.length > 0) {
|
|
1323
|
+
mcpRegistry = await HostMcpRegistry.connect(resolvedMcpConfigs, {
|
|
1324
|
+
untrustedRoots: [repoRoot],
|
|
1325
|
+
trustedPathEnv: process.env['PATH'],
|
|
1326
|
+
scrub: text => scrubber.scrub(text),
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
const ephemeralEnv = {};
|
|
1331
|
+
if (activeCandidate !== undefined && activeCandidate.usesActiveTokenEnv && activeCandidate.token !== undefined) {
|
|
1332
|
+
ephemeralEnv[LOOPWRIGHT_ACTIVE_PROVIDER_TOKEN_ENV] = activeCandidate.token;
|
|
1333
|
+
scrubber.register(activeCandidate.token);
|
|
1334
|
+
}
|
|
1335
|
+
let compiled = await compileDeclarativeTaskpack(manifest, buildBindings(activeCandidate));
|
|
1336
|
+
const localCommandGates = compiled.localCommandGates ?? [];
|
|
1337
|
+
if (localCommandGates.length > 0) {
|
|
1338
|
+
const extractedConflictPaths = compiled.extractedConflictPaths
|
|
1339
|
+
?? baselineAlignmentResult?.conflictResource?.extractedPaths;
|
|
1340
|
+
localGateServer = await startLocalCommandGateServer({
|
|
1341
|
+
runRoot: realRunRoot,
|
|
1342
|
+
repositoryRoot: repoRoot,
|
|
1343
|
+
gates: localCommandGates,
|
|
1344
|
+
hostPolicy,
|
|
1345
|
+
runtimeEnv: process.env,
|
|
1346
|
+
scrubber,
|
|
1347
|
+
forbiddenEnvNames: forbiddenCommandEnvNames,
|
|
1348
|
+
checkStagedDir: preflightResult?.checkStagedDir,
|
|
1349
|
+
...(extractedConflictPaths !== undefined ? { extractedConflictPaths } : {}),
|
|
1350
|
+
});
|
|
1351
|
+
activeGateEndpoints = [localGateServer.endpointPlan];
|
|
1352
|
+
ephemeralEnv[DEFAULT_LOCAL_COMMAND_GATE_ENV] = localGateServer.signingSecret;
|
|
1353
|
+
compiled = await compileDeclarativeTaskpack(manifest, buildBindings(activeCandidate));
|
|
1354
|
+
}
|
|
1355
|
+
const trustedDirectory = join(realRunRoot, `lw-cli-${runId}-${process.pid}-${Date.now().toString(36)}`);
|
|
1356
|
+
const writtenTaskpack = await writeCompiledTaskpackDir(trustedDirectory, compiled, scrubber);
|
|
1357
|
+
const decisionPort = createTaskpackDecisionPort(manifest, {
|
|
1358
|
+
runtimeEnv: process.env,
|
|
1359
|
+
scrubber,
|
|
1360
|
+
hasPinnedRoles: (manifest.spec.roles?.length ?? 0) > 0 || (args.roleModelOverrides?.length ?? 0) > 0,
|
|
1361
|
+
});
|
|
1362
|
+
const stepMcpMetadata = mcpRegistry?.servers.map(srv => ({
|
|
1363
|
+
id: srv.id,
|
|
1364
|
+
transport: srv.transport,
|
|
1365
|
+
toolNames: srv.toolNames,
|
|
1366
|
+
}));
|
|
1367
|
+
const { cycleSummary, caughtSignal } = await withSignalAbort(async (signal, getSignal) => ({
|
|
1368
|
+
cycleSummary: await executeTurnkeyCycle({
|
|
1369
|
+
runId,
|
|
1370
|
+
attemptSeq: 0,
|
|
1371
|
+
repositoryRoot: repoRoot,
|
|
1372
|
+
taskpack: writtenTaskpack,
|
|
1373
|
+
runtimeEnv: process.env,
|
|
1374
|
+
ephemeralEnv,
|
|
1375
|
+
scrubber,
|
|
1376
|
+
...(mcpRegistry !== undefined ? { mcpRegistry } : {}),
|
|
1377
|
+
...(stepMcpMetadata !== undefined ? { mcpServers: stepMcpMetadata } : {}),
|
|
1378
|
+
decisions: decisionPort,
|
|
1379
|
+
policyProfile: 'local',
|
|
1380
|
+
allowWorkflowWrites: writtenTaskpack.allowWorkflowWrites,
|
|
1381
|
+
signal,
|
|
1382
|
+
memoryFinalizer: async ({ runRoot: settledRunRoot, runId: settledRunId }) => await finalizeLocalTurnkeyMemory({
|
|
1383
|
+
runRoot: settledRunRoot,
|
|
1384
|
+
runId: settledRunId,
|
|
1385
|
+
repositoryRoot: repoRoot,
|
|
1386
|
+
repositoryFullName,
|
|
1387
|
+
manifest,
|
|
1388
|
+
taskpackPath: relativeTaskpackPath,
|
|
1389
|
+
baseRevision: resolvedRepo.baseRevision,
|
|
1390
|
+
policyProfile: 'local',
|
|
1391
|
+
upstreamRecords,
|
|
1392
|
+
scrubber,
|
|
1393
|
+
}),
|
|
1394
|
+
}),
|
|
1395
|
+
caughtSignal: getSignal(),
|
|
1396
|
+
}));
|
|
1397
|
+
const firstRole = writtenTaskpack.config.spec.task.spec.roles[0];
|
|
1398
|
+
const primaryModel = firstRole
|
|
1399
|
+
? { provider: firstRole.provider, model: firstRole.model, thinking: firstRole.thinking }
|
|
1400
|
+
: null;
|
|
1401
|
+
await emitOutcomeReports({
|
|
1402
|
+
args,
|
|
1403
|
+
runRoot: realRunRoot,
|
|
1404
|
+
runId: cycleSummary.attemptRunId,
|
|
1405
|
+
json,
|
|
1406
|
+
model: primaryModel,
|
|
1407
|
+
report: {
|
|
1408
|
+
status: cycleSummary.status,
|
|
1409
|
+
reasonCode: cycleSummary.reasonCode,
|
|
1410
|
+
phase: null,
|
|
1411
|
+
checks: cycleSummary.checks,
|
|
1412
|
+
usage: cycleSummary.usage,
|
|
1413
|
+
runEval: cycleSummary.runEval ?? null,
|
|
1414
|
+
},
|
|
1415
|
+
emitDefault: () => emit('result', cycleSummary, cycleSummary.status),
|
|
1416
|
+
});
|
|
1417
|
+
return turnkeySummaryExit(cycleSummary, caughtSignal);
|
|
1418
|
+
}
|
|
1419
|
+
catch (err) {
|
|
1420
|
+
if (err instanceof TaskpackError) {
|
|
1421
|
+
return await emitTaskpackError(err, emit, scrubber);
|
|
1422
|
+
}
|
|
1423
|
+
throw err;
|
|
1424
|
+
}
|
|
1425
|
+
finally {
|
|
1426
|
+
if (localGateServer !== undefined) {
|
|
1427
|
+
await localGateServer.close().catch(() => { });
|
|
1428
|
+
}
|
|
1429
|
+
if (mcpRegistry !== undefined) {
|
|
1430
|
+
await mcpRegistry.close().catch(() => { });
|
|
1431
|
+
}
|
|
1432
|
+
if (preflightResult?.stagedDir) {
|
|
1433
|
+
await removeStagedDirSafely(preflightResult.stagedDir);
|
|
1434
|
+
}
|
|
1435
|
+
if (preflightResult?.checkStagedDir && preflightResult.checkStagedDir !== preflightResult.stagedDir) {
|
|
1436
|
+
await removeStagedDirSafely(preflightResult.checkStagedDir);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
async function registerRunnerConfigSecrets(configPath, scrubber, env, options) {
|
|
1441
|
+
try {
|
|
1442
|
+
await options.assertNoSymlinkAncestors(configPath, {
|
|
1443
|
+
checkLeaf: true,
|
|
1444
|
+
code: 'CONFIG_INVALID',
|
|
1445
|
+
diagPath: '/',
|
|
1446
|
+
});
|
|
1447
|
+
const rawBytes = await readBoundedRegularFile(configPath, options.maxConfigBytes, () => {
|
|
1448
|
+
throw new Error('UNBOUNDED');
|
|
1449
|
+
});
|
|
1450
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(rawBytes);
|
|
1451
|
+
const registerEnvName = (envName) => {
|
|
1452
|
+
if (envName !== undefined && Object.hasOwn(env, envName)) {
|
|
1453
|
+
const val = env[envName];
|
|
1454
|
+
if (typeof val === 'string' && val.length > 0)
|
|
1455
|
+
scrubber.register(val);
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1459
|
+
const scalarPattern = options.scalarEnvFields.map(escapeRegExp).join('|');
|
|
1460
|
+
const listPattern = options.listEnvFields.map(escapeRegExp).join('|');
|
|
1461
|
+
// Best-effort fallback extraction before YAML parsing so malformed YAML diagnostics stay scrubbed.
|
|
1462
|
+
for (const match of text.matchAll(/\benv:([A-Z][A-Z0-9_]{0,127})\b/g)) {
|
|
1463
|
+
registerEnvName(match[1]);
|
|
1464
|
+
}
|
|
1465
|
+
if (scalarPattern.length > 0) {
|
|
1466
|
+
const scalarRe = new RegExp(`['"]?(?:${scalarPattern})['"]?\\s*:\\s*['"]?(?:env:)?([A-Z][A-Z0-9_]{0,127})['"]?`, 'g');
|
|
1467
|
+
for (const match of text.matchAll(scalarRe)) {
|
|
1468
|
+
registerEnvName(match[1]);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
if (listPattern.length > 0) {
|
|
1472
|
+
const flowListRe = new RegExp(`['"]?(?:${listPattern})['"]?\\s*:\\s*\\[([^\\]]*)\\]`, 'g');
|
|
1473
|
+
for (const listMatch of text.matchAll(flowListRe)) {
|
|
1474
|
+
for (const item of listMatch[1].matchAll(/\b(?:env:)?([A-Z][A-Z0-9_]{0,127})\b/g)) {
|
|
1475
|
+
registerEnvName(item[1]);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
const blockListRe = new RegExp(`['"]?(?:${listPattern})['"]?\\s*:\\s*\\n((?:[ \\t]+-[ \\t]+[^\\n]+\\n?)+)`, 'g');
|
|
1479
|
+
for (const blockListMatch of text.matchAll(blockListRe)) {
|
|
1480
|
+
for (const item of blockListMatch[1].matchAll(/^[ \t]+-[ \t]+['"]?(?:env:)?([A-Z][A-Z0-9_]{0,127})['"]?/gm)) {
|
|
1481
|
+
registerEnvName(item[1]);
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
const parsed = parseYamlDocument(text);
|
|
1486
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
1487
|
+
const rec = parsed;
|
|
1488
|
+
for (const field of options.scalarEnvFields) {
|
|
1489
|
+
const ref = Object.hasOwn(rec, field) ? rec[field] : undefined;
|
|
1490
|
+
if (typeof ref === 'string') {
|
|
1491
|
+
registerEnvName(ref.startsWith('env:') ? ref.slice(4) : ref);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
for (const listField of options.listEnvFields) {
|
|
1495
|
+
const list = Object.hasOwn(rec, listField) ? rec[listField] : undefined;
|
|
1496
|
+
if (Array.isArray(list)) {
|
|
1497
|
+
for (const item of list) {
|
|
1498
|
+
if (typeof item === 'string') {
|
|
1499
|
+
registerEnvName(item.startsWith('env:') ? item.slice(4) : item);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
catch {
|
|
1507
|
+
// Best-effort pre-registration before strict config validation runs.
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
function scrubSettlement(summary, scrubber) {
|
|
1511
|
+
return {
|
|
1512
|
+
...summary,
|
|
1513
|
+
jobId: scrubber.scrub(summary.jobId),
|
|
1514
|
+
operationId: scrubber.scrub(summary.operationId),
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
async function runRunnerCommand(args, emit) {
|
|
1518
|
+
const get = (key) => args.values.get(key);
|
|
1519
|
+
const configPath = resolve(get('config'));
|
|
1520
|
+
const scrubber = createCliScrubber();
|
|
1521
|
+
const { assertNoSymlinkAncestors, MAX_RUNNER_CONFIG_BYTES, RUNNER_SECRET_ENV_FIELDS, RUNNER_SECRET_ENV_LIST_FIELDS, loadRelayConfig, loadWorkerConfig, startRelayServer, runHardwareWorker, HardwareRunnerError, isRunnerTeardownError, isRunnerTransportError, } = await import('@loopwright/hardware-runner');
|
|
1522
|
+
await registerRunnerConfigSecrets(configPath, scrubber, process.env, {
|
|
1523
|
+
maxConfigBytes: MAX_RUNNER_CONFIG_BYTES,
|
|
1524
|
+
assertNoSymlinkAncestors,
|
|
1525
|
+
scalarEnvFields: RUNNER_SECRET_ENV_FIELDS,
|
|
1526
|
+
listEnvFields: RUNNER_SECRET_ENV_LIST_FIELDS,
|
|
1527
|
+
});
|
|
1528
|
+
try {
|
|
1529
|
+
if (args.runnerAction === 'relay') {
|
|
1530
|
+
const config = await loadRelayConfig(configPath, { env: process.env });
|
|
1531
|
+
scrubber.register(config.controllerSigningSecret);
|
|
1532
|
+
if (config.controllerAuthToken !== undefined)
|
|
1533
|
+
scrubber.register(config.controllerAuthToken);
|
|
1534
|
+
for (const token of config.workerTokens)
|
|
1535
|
+
scrubber.register(token);
|
|
1536
|
+
const handle = await startRelayServer(config);
|
|
1537
|
+
let caughtSignal = null;
|
|
1538
|
+
let resolveSignal;
|
|
1539
|
+
const signalPromise = new Promise(resolveSig => {
|
|
1540
|
+
resolveSignal = resolveSig;
|
|
1541
|
+
});
|
|
1542
|
+
const onSigint = () => {
|
|
1543
|
+
if (caughtSignal === null) {
|
|
1544
|
+
caughtSignal = 'SIGINT';
|
|
1545
|
+
resolveSignal('SIGINT');
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
const onSigterm = () => {
|
|
1549
|
+
if (caughtSignal === null) {
|
|
1550
|
+
caughtSignal = 'SIGTERM';
|
|
1551
|
+
resolveSignal('SIGTERM');
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
process.on('SIGINT', onSigint);
|
|
1555
|
+
process.on('SIGTERM', onSigterm);
|
|
1556
|
+
try {
|
|
1557
|
+
await emit('status', {
|
|
1558
|
+
role: 'relay',
|
|
1559
|
+
host: handle.host,
|
|
1560
|
+
port: handle.port,
|
|
1561
|
+
url: handle.url,
|
|
1562
|
+
relayBootId: handle.relayBootId,
|
|
1563
|
+
}, `listening: ${handle.url}`);
|
|
1564
|
+
caughtSignal = await signalPromise;
|
|
1565
|
+
}
|
|
1566
|
+
finally {
|
|
1567
|
+
try {
|
|
1568
|
+
await handle.close();
|
|
1569
|
+
}
|
|
1570
|
+
finally {
|
|
1571
|
+
process.off('SIGINT', onSigint);
|
|
1572
|
+
process.off('SIGTERM', onSigterm);
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return caughtSignal === 'SIGTERM' ? 143 : 130;
|
|
1576
|
+
}
|
|
1577
|
+
const config = await loadWorkerConfig(configPath, { env: process.env });
|
|
1578
|
+
scrubber.register(config.workerToken);
|
|
1579
|
+
const shutdownController = new AbortController();
|
|
1580
|
+
const preemptController = new AbortController();
|
|
1581
|
+
let caughtSignal = null;
|
|
1582
|
+
let sawUnknownSettlement = false;
|
|
1583
|
+
let sawFencedSettlement = false;
|
|
1584
|
+
const onSigint = () => {
|
|
1585
|
+
caughtSignal ??= 'SIGINT';
|
|
1586
|
+
shutdownController.abort();
|
|
1587
|
+
};
|
|
1588
|
+
const onSigterm = () => {
|
|
1589
|
+
caughtSignal ??= 'SIGTERM';
|
|
1590
|
+
preemptController.abort();
|
|
1591
|
+
};
|
|
1592
|
+
process.on('SIGINT', onSigint);
|
|
1593
|
+
process.on('SIGTERM', onSigterm);
|
|
1594
|
+
const settlements = [];
|
|
1595
|
+
let workerResult;
|
|
1596
|
+
try {
|
|
1597
|
+
workerResult = await runHardwareWorker({
|
|
1598
|
+
config,
|
|
1599
|
+
once: args.flags.has('once'),
|
|
1600
|
+
signal: shutdownController.signal,
|
|
1601
|
+
preemptSignal: preemptController.signal,
|
|
1602
|
+
registerProcessSignalHandlers: false,
|
|
1603
|
+
onJobSettled: summary => {
|
|
1604
|
+
if (summary.outcome === 'unknown' || summary.acknowledgment === 'unknown') {
|
|
1605
|
+
sawUnknownSettlement = true;
|
|
1606
|
+
}
|
|
1607
|
+
if (summary.outcome === 'fenced' || summary.acknowledgment === 'fenced') {
|
|
1608
|
+
sawFencedSettlement = true;
|
|
1609
|
+
}
|
|
1610
|
+
if (settlements.length >= 64)
|
|
1611
|
+
settlements.shift();
|
|
1612
|
+
settlements.push(scrubSettlement(summary, scrubber));
|
|
1613
|
+
},
|
|
1614
|
+
});
|
|
1615
|
+
}
|
|
1616
|
+
finally {
|
|
1617
|
+
process.off('SIGINT', onSigint);
|
|
1618
|
+
process.off('SIGTERM', onSigterm);
|
|
1619
|
+
}
|
|
1620
|
+
const lastSettlement = workerResult.lastSettlement !== null
|
|
1621
|
+
? scrubSettlement(workerResult.lastSettlement, scrubber)
|
|
1622
|
+
: null;
|
|
1623
|
+
const safeWorkerId = scrubber.scrub(config.workerId);
|
|
1624
|
+
await emit('status', {
|
|
1625
|
+
role: 'worker',
|
|
1626
|
+
workerId: safeWorkerId,
|
|
1627
|
+
exitReason: workerResult.exitReason,
|
|
1628
|
+
polls: workerResult.polls,
|
|
1629
|
+
jobsProcessed: workerResult.jobsProcessed,
|
|
1630
|
+
lastSettlement,
|
|
1631
|
+
settlements,
|
|
1632
|
+
}, `worker ${safeWorkerId}: ${workerResult.exitReason} (jobsProcessed=${workerResult.jobsProcessed})`);
|
|
1633
|
+
if (sawUnknownSettlement
|
|
1634
|
+
|| (workerResult.lastSettlement !== null
|
|
1635
|
+
&& (workerResult.lastSettlement.outcome === 'unknown'
|
|
1636
|
+
|| workerResult.lastSettlement.acknowledgment === 'unknown'))) {
|
|
1637
|
+
return 8;
|
|
1638
|
+
}
|
|
1639
|
+
if (sawFencedSettlement
|
|
1640
|
+
|| (workerResult.lastSettlement !== null
|
|
1641
|
+
&& (workerResult.lastSettlement.outcome === 'fenced'
|
|
1642
|
+
|| workerResult.lastSettlement.acknowledgment === 'fenced'))) {
|
|
1643
|
+
return 7;
|
|
1644
|
+
}
|
|
1645
|
+
if (caughtSignal === 'SIGTERM' || workerResult.exitReason === 'preempted')
|
|
1646
|
+
return 143;
|
|
1647
|
+
if (caughtSignal === 'SIGINT' || workerResult.exitReason === 'aborted')
|
|
1648
|
+
return 130;
|
|
1649
|
+
return 0;
|
|
1650
|
+
}
|
|
1651
|
+
catch (err) {
|
|
1652
|
+
if (err instanceof HardwareRunnerError) {
|
|
1653
|
+
const isTeardown = isRunnerTeardownError(err);
|
|
1654
|
+
const isTransport = isRunnerTransportError(err);
|
|
1655
|
+
let code = err.code;
|
|
1656
|
+
if (isTeardown) {
|
|
1657
|
+
code = 'RUNNER_TEARDOWN_FAILED';
|
|
1658
|
+
}
|
|
1659
|
+
else if (isTransport) {
|
|
1660
|
+
code = 'RUNNER_TRANSPORT_ERROR';
|
|
1661
|
+
}
|
|
1662
|
+
const message = scrubber.scrub(err.message);
|
|
1663
|
+
const path = typeof err.path === 'string' && err.path.length > 0 ? scrubber.scrub(err.path) : null;
|
|
1664
|
+
await emit('diagnostic', { version: 1, code, message, ...(path !== null ? { path } : {}) }, `${code}: ${message}`);
|
|
1665
|
+
return isTeardown || isTransport ? 8 : hardwareRunnerExitCode(err.code);
|
|
1666
|
+
}
|
|
1667
|
+
const rawMessage = err instanceof Error ? err.message : String(err);
|
|
1668
|
+
const message = scrubber.scrub(rawMessage);
|
|
1669
|
+
await emit('diagnostic', { version: 1, code: 'RUNNER_UNAVAILABLE', message }, `RUNNER_UNAVAILABLE: ${message}`);
|
|
1670
|
+
return 8;
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
export async function main(argv) {
|
|
1674
|
+
if (argv.length === 1 && argv[0] === '--help') {
|
|
1675
|
+
await stdout(HELP);
|
|
1676
|
+
return 0;
|
|
1677
|
+
}
|
|
1678
|
+
if (argv.length === 2 && argv[0] === 'runner' && argv[1] === '--help') {
|
|
1679
|
+
await stdout(RUNNER_HELP);
|
|
1680
|
+
return 0;
|
|
1681
|
+
}
|
|
1682
|
+
if (argv.length === 3 && argv[0] === 'runner' && (argv[1] === 'relay' || argv[1] === 'worker') && argv[2] === '--help') {
|
|
1683
|
+
await stdout(RUNNER_HELP);
|
|
1684
|
+
return 0;
|
|
1685
|
+
}
|
|
1686
|
+
if (argv.length === 1 && argv[0] === '--version') {
|
|
1687
|
+
await stdout(`${CLI_VERSION}\n`);
|
|
1688
|
+
return 0;
|
|
1689
|
+
}
|
|
1690
|
+
let sequence = 0, runId = null, json = argv.includes('--json');
|
|
1691
|
+
const emit = async (kind, data, summary) => { const envelope = { version: 1, kind, sequence: ++sequence, runId, data }; if (!json && kind === 'diagnostic') {
|
|
1692
|
+
await stderr(encoded(summary ?? kind) + '\n');
|
|
1693
|
+
return;
|
|
1694
|
+
} await stdout(json ? encoded(envelope) + '\n' : encoded(summary ?? kind) + '\n'); };
|
|
1695
|
+
try {
|
|
1696
|
+
const args = parseArguments(argv), get = (key) => args.values.get(key), output = args.values.get('output');
|
|
1697
|
+
json = args.flags.has('json');
|
|
1698
|
+
if (args.command === 'init') {
|
|
1699
|
+
await initDraft(get('directory'), args.flags.has('force'));
|
|
1700
|
+
await emit('status', { runId: null, source: 'unavailable', stage: 'draft', status: 'unsupported', currentState: null, checkpoint: null, cleanup: null, unavailable: ['currentState', 'checkpoint', 'cleanup'] }, 'Draft written; execution readiness unsupported.');
|
|
1701
|
+
return 0;
|
|
1702
|
+
}
|
|
1703
|
+
if (args.command === 'closure') {
|
|
1704
|
+
const { runIntegratedFailureMatrix } = await import('./failure-matrix.js');
|
|
1705
|
+
const report = await evaluateClosureMatrix({ repoRoot: resolve(args.values.has('repo') ? get('repo') : process.cwd()), verifyFailures: args.flags.has('verify-failures'), runFailureMatrix: () => runIntegratedFailureMatrix() });
|
|
1706
|
+
if (args.values.has('output'))
|
|
1707
|
+
await writeOutput(resolve(get('output')), Buffer.from(encoded(report) + '\n'));
|
|
1708
|
+
const matrix = report.failureMatrix === null ? '' : `; failure matrix ${report.failureMatrix.passed}/${report.failureMatrix.total} passed`;
|
|
1709
|
+
await emit('closure', report, `closure: ${report.summary.closedLocal} closed local, ${report.summary.unprovisionedExternal} unprovisioned external; integrity ${report.integrity.ok ? 'ok' : 'failed'}; ${report.falsificationDetected ? 'falsification detected' : 'no falsification'}${matrix}`);
|
|
1710
|
+
return closureExitCode(report, args.flags.has('verify-failures'));
|
|
1711
|
+
}
|
|
1712
|
+
if (args.command === 'app-serve') {
|
|
1713
|
+
let handle;
|
|
1714
|
+
try {
|
|
1715
|
+
const { startConfiguredGitHubApp } = await import('@loopwright/github-app');
|
|
1716
|
+
handle = await startConfiguredGitHubApp(resolve(get('config')), {
|
|
1717
|
+
env: process.env,
|
|
1718
|
+
repoRoot: args.values.has('repo') ? resolve(get('repo')) : undefined,
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
catch (err) {
|
|
1722
|
+
if (err !== null && typeof err === 'object' && 'code' in err && typeof err.code === 'string') {
|
|
1723
|
+
const code = err.code;
|
|
1724
|
+
const rawMessage = err instanceof Error ? err.message : code;
|
|
1725
|
+
const message = createCliScrubber(['GITHUB_WEBHOOK_SECRET', 'GITHUB_APP_PRIVATE_KEY']).scrub(rawMessage);
|
|
1726
|
+
await emit('diagnostic', { version: 1, code, message }, code);
|
|
1727
|
+
return 2;
|
|
1728
|
+
}
|
|
1729
|
+
throw err;
|
|
1730
|
+
}
|
|
1731
|
+
await emit('status', { host: handle.host, port: handle.port, url: handle.url, webhookPath: handle.webhookPath }, `listening: ${handle.url}${handle.webhookPath}`);
|
|
1732
|
+
const caughtSignal = await new Promise(resolveSignal => {
|
|
1733
|
+
const onSigint = () => { process.off('SIGINT', onSigint); process.off('SIGTERM', onSigterm); resolveSignal('SIGINT'); };
|
|
1734
|
+
const onSigterm = () => { process.off('SIGINT', onSigint); process.off('SIGTERM', onSigterm); resolveSignal('SIGTERM'); };
|
|
1735
|
+
process.on('SIGINT', onSigint);
|
|
1736
|
+
process.on('SIGTERM', onSigterm);
|
|
1737
|
+
});
|
|
1738
|
+
await handle.close();
|
|
1739
|
+
return caughtSignal === 'SIGTERM' ? 143 : 130;
|
|
1740
|
+
}
|
|
1741
|
+
if (args.command === 'status' || args.command === 'inspect') {
|
|
1742
|
+
runId = get('run-id');
|
|
1743
|
+
const input = { runRoot: get('run-root'), runId };
|
|
1744
|
+
const observed = args.command === 'status' ? await readStatus(input) : await inspectRun({ ...input, ...(output === undefined ? {} : { output }) });
|
|
1745
|
+
if (!observed.ok) {
|
|
1746
|
+
await emit('diagnostic', observed.error, observed.error.code);
|
|
1747
|
+
return diagnosticExit(observed.error);
|
|
1748
|
+
}
|
|
1749
|
+
const status = 'manifest' in observed.value ? observed.value.status : observed.value;
|
|
1750
|
+
await emit(args.command === 'status' ? 'status' : 'inspection', observed.value, 'source' in status ? status.source + ': ' + status.status : 'inspection');
|
|
1751
|
+
return 'source' in status && status.source === 'unavailable' ? 8 : 0;
|
|
1752
|
+
}
|
|
1753
|
+
if (args.command === 'reconcile') {
|
|
1754
|
+
runId = get('run-id');
|
|
1755
|
+
const trusted = await loadTrustedConfiguration({ configPath: resolve(get('config')), registryPath: resolve(get('registry')), registrySha256: get('registry-sha256'), untrustedRoots: [resolve(get('repo'))] });
|
|
1756
|
+
if (!trusted.ok) {
|
|
1757
|
+
await emit('diagnostic', trusted.error, trusted.error.code);
|
|
1758
|
+
return diagnosticExit(trusted.error);
|
|
1759
|
+
}
|
|
1760
|
+
const reconcilePorts = args.flags.has('allow-workflow-writes')
|
|
1761
|
+
? { allowWorkflowWrites: true }
|
|
1762
|
+
: undefined;
|
|
1763
|
+
const reconciled = await reconcileCycle({ configuration: trusted.value, runRoot: resolve(get('run-root')), runId, receipt: resolve(get('receipt')) }, reconcilePorts);
|
|
1764
|
+
if (!reconciled.ok) {
|
|
1765
|
+
await emit('diagnostic', reconciled.error, reconciled.error.code);
|
|
1766
|
+
return diagnosticExit(reconciled.error);
|
|
1767
|
+
}
|
|
1768
|
+
if (args.values.has('output'))
|
|
1769
|
+
await writeOutput(resolve(get('output')), Buffer.from(encoded(reconciled.value)));
|
|
1770
|
+
await emitOutcomeReports({
|
|
1771
|
+
args,
|
|
1772
|
+
runRoot: resolve(get('run-root')),
|
|
1773
|
+
runId,
|
|
1774
|
+
json,
|
|
1775
|
+
configuration: trusted.value,
|
|
1776
|
+
report: reconciled.value.kind === 'settled'
|
|
1777
|
+
? { status: reconciled.value.status, reasonCode: null, phase: null, checks: [] }
|
|
1778
|
+
: { status: 'unresolved', reasonCode: reconciled.value.reason, phase: null, checks: [] },
|
|
1779
|
+
emitDefault: () => emit('result', reconciled.value, reconciled.value.kind === 'settled' ? 'reconciled: ' + reconciled.value.status : 'unresolved: ' + reconciled.value.reason),
|
|
1780
|
+
});
|
|
1781
|
+
return reconciled.value.kind === 'settled' ? reconciled.value.status === 'completed' ? 0 : reconciled.value.status === 'blocked' ? 3 : 4 : 7;
|
|
1782
|
+
}
|
|
1783
|
+
if (args.command === 'digest') {
|
|
1784
|
+
return await runDigestCommand(args, emit);
|
|
1785
|
+
}
|
|
1786
|
+
if (args.command === 'suite') {
|
|
1787
|
+
return await runSuiteCommand(args, emit);
|
|
1788
|
+
}
|
|
1789
|
+
if (args.command === 'runner') {
|
|
1790
|
+
return await runRunnerCommand(args, emit);
|
|
1791
|
+
}
|
|
1792
|
+
if (args.command === 'step') {
|
|
1793
|
+
runId = get('run-id');
|
|
1794
|
+
return await runStepCommand(args, json, emit);
|
|
1795
|
+
}
|
|
1796
|
+
if (args.command === 'run' && args.values.has('taskpack')) {
|
|
1797
|
+
if (!args.flags.has('dry-run'))
|
|
1798
|
+
runId = get('run-id');
|
|
1799
|
+
return await runTaskpackCommand(args, json, emit);
|
|
1800
|
+
}
|
|
1801
|
+
const loaded = await loadTrustedConfiguration({
|
|
1802
|
+
configPath: resolve(get('config')),
|
|
1803
|
+
registryPath: resolve(get('registry')),
|
|
1804
|
+
registrySha256: get('registry-sha256'),
|
|
1805
|
+
untrustedRoots: args.values.has('repo') ? [resolve(get('repo'))] : [],
|
|
1806
|
+
...(args.roleModelOverrides ? { roleModelOverrides: args.roleModelOverrides } : {}),
|
|
1807
|
+
});
|
|
1808
|
+
if (!loaded.ok) {
|
|
1809
|
+
await emit('diagnostic', loaded.error, loaded.error.code);
|
|
1810
|
+
return diagnosticExit(loaded.error);
|
|
1811
|
+
}
|
|
1812
|
+
if (args.command === 'check' || args.flags.has('dry-run')) {
|
|
1813
|
+
const compiled = await compilePlan(loaded.value);
|
|
1814
|
+
if (!compiled.ok) {
|
|
1815
|
+
await emit('diagnostic', compiled.error, compiled.error.code);
|
|
1816
|
+
return diagnosticExit(compiled.error);
|
|
1817
|
+
}
|
|
1818
|
+
if (output !== undefined)
|
|
1819
|
+
await writeOutput(output, Buffer.from(encoded(compiled.value) + '\n'));
|
|
1820
|
+
await emit('plan', compiled.value, 'Plan checked; admission not performed; execution readiness not checked.');
|
|
1821
|
+
return 0;
|
|
1822
|
+
}
|
|
1823
|
+
const targetRunId = get('run-id');
|
|
1824
|
+
runId = targetRunId;
|
|
1825
|
+
return await withSignalAbort(async (signal, getSignal) => {
|
|
1826
|
+
const input = {
|
|
1827
|
+
configuration: loaded.value, repository: resolve(get('repo')), runRoot: resolve(get('run-root')), runId: targetRunId, signal,
|
|
1828
|
+
onEvent: async (event) => { if (json)
|
|
1829
|
+
await emit('event', event);
|
|
1830
|
+
else
|
|
1831
|
+
process.stderr.write('progress\n'); },
|
|
1832
|
+
};
|
|
1833
|
+
const ports = args.flags.has('allow-workflow-writes')
|
|
1834
|
+
? { allowWorkflowWrites: true }
|
|
1835
|
+
: undefined;
|
|
1836
|
+
const execution = args.command === 'resume'
|
|
1837
|
+
? (ports ? await resumeCycleWithPorts(input, ports) : await resumeCycle(input))
|
|
1838
|
+
: (ports ? await runCycleWithPorts(input, ports) : await runCycle(input));
|
|
1839
|
+
if (!execution.ok) {
|
|
1840
|
+
await emit('diagnostic', execution.error, execution.error.code);
|
|
1841
|
+
return diagnosticExit(execution.error);
|
|
1842
|
+
}
|
|
1843
|
+
await emitExecutionOutcome(args, resolve(get('run-root')), targetRunId, json, execution.value, loaded.value, emit);
|
|
1844
|
+
return executionExit(execution.value, getSignal());
|
|
1845
|
+
});
|
|
1846
|
+
}
|
|
1847
|
+
catch (error) {
|
|
1848
|
+
const code = error instanceof UsageError ? 'CLI_USAGE' : 'CLI_UNAVAILABLE';
|
|
1849
|
+
await emit('diagnostic', { version: 1, code }, code);
|
|
1850
|
+
return error instanceof UsageError ? 2 : 8;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
1854
|
+
main(process.argv.slice(2)).then(code => { process.exitCode = code; }, () => { process.exitCode = 8; });
|
|
1855
|
+
}
|