@gpustack/loopwright 0.0.0-stage → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +356 -2
- package/bin/loopwright.js +3 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.js +122 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.d.ts +30 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.js +340 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.js +65 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.js +76 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.js +113 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.d.ts +4 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.d.ts +96 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.js +1712 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.js +146 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.js +836 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.js +2 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.js +280 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.js +12 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.d.ts +29 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.js +160 -0
- package/node_modules/@loopwright/agent-pi/dist/context.d.ts +56 -0
- package/node_modules/@loopwright/agent-pi/dist/context.js +351 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.d.ts +8 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.js +52 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.js +18 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.js +287 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.d.ts +12 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.js +17 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.js +9 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.js +19 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/events.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/events.js +132 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.js +25 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.d.ts +24 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.js +316 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.js +476 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.d.ts +87 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.js +526 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.js +74 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.js +2094 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.js +353 -0
- package/node_modules/@loopwright/agent-pi/dist/index.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/index.js +4 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.js +11 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.d.ts +35 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.js +92 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.js +63 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.d.ts +23 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.js +212 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.d.ts +5 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.js +28 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.d.ts +10 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.js +260 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.d.ts +60 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.js +700 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.d.ts +1 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.js +119 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.d.ts +17 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.js +131 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.d.ts +62 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.js +217 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.js +188 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.js +81 -0
- package/node_modules/@loopwright/agent-pi/dist/response.d.ts +20 -0
- package/node_modules/@loopwright/agent-pi/dist/response.js +259 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.js +37 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.js +633 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.d.ts +46 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.js +553 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.d.ts +21 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.js +315 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.js +102 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.js +85 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.js +105 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.d.ts +36 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.js +128 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.d.ts +71 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/types.d.ts +314 -0
- package/node_modules/@loopwright/agent-pi/dist/types.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.js +314 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.d.ts +27 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.js +142 -0
- package/node_modules/@loopwright/agent-pi/package.json +24 -0
- package/node_modules/@loopwright/agent-pi/runtime/Dockerfile +8 -0
- package/node_modules/@loopwright/agent-pi/runtime/seccomp.json +1 -0
- package/node_modules/@loopwright/cli/dist/arguments.d.ts +19 -0
- package/node_modules/@loopwright/cli/dist/arguments.js +358 -0
- package/node_modules/@loopwright/cli/dist/closure.d.ts +93 -0
- package/node_modules/@loopwright/cli/dist/closure.js +230 -0
- package/node_modules/@loopwright/cli/dist/draft.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/draft.js +106 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.js +701 -0
- package/node_modules/@loopwright/cli/dist/index.d.ts +6 -0
- package/node_modules/@loopwright/cli/dist/index.js +5 -0
- package/node_modules/@loopwright/cli/dist/main.d.ts +22 -0
- package/node_modules/@loopwright/cli/dist/main.js +1855 -0
- package/node_modules/@loopwright/cli/package.json +16 -0
- package/node_modules/@loopwright/controller/dist/acceptance.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/acceptance.js +446 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.d.ts +273 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.js +3147 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.js +139 -0
- package/node_modules/@loopwright/controller/dist/bundle.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/bundle.js +64 -0
- package/node_modules/@loopwright/controller/dist/capture.d.ts +89 -0
- package/node_modules/@loopwright/controller/dist/capture.js +587 -0
- package/node_modules/@loopwright/controller/dist/compile.d.ts +3 -0
- package/node_modules/@loopwright/controller/dist/compile.js +402 -0
- package/node_modules/@loopwright/controller/dist/config.d.ts +22 -0
- package/node_modules/@loopwright/controller/dist/config.js +255 -0
- package/node_modules/@loopwright/controller/dist/controller.d.ts +177 -0
- package/node_modules/@loopwright/controller/dist/controller.js +2135 -0
- package/node_modules/@loopwright/controller/dist/credentials.d.ts +29 -0
- package/node_modules/@loopwright/controller/dist/credentials.js +189 -0
- package/node_modules/@loopwright/controller/dist/deadlines.d.ts +18 -0
- package/node_modules/@loopwright/controller/dist/deadlines.js +71 -0
- package/node_modules/@loopwright/controller/dist/errors.d.ts +27 -0
- package/node_modules/@loopwright/controller/dist/errors.js +41 -0
- package/node_modules/@loopwright/controller/dist/events.d.ts +52 -0
- package/node_modules/@loopwright/controller/dist/events.js +228 -0
- package/node_modules/@loopwright/controller/dist/files.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/files.js +386 -0
- package/node_modules/@loopwright/controller/dist/finalize.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/finalize.js +32 -0
- package/node_modules/@loopwright/controller/dist/gate.d.ts +84 -0
- package/node_modules/@loopwright/controller/dist/gate.js +640 -0
- package/node_modules/@loopwright/controller/dist/git-objects.d.ts +11 -0
- package/node_modules/@loopwright/controller/dist/git-objects.js +59 -0
- package/node_modules/@loopwright/controller/dist/git-reader.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/git-reader.js +40 -0
- package/node_modules/@loopwright/controller/dist/handlers.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/handlers.js +45 -0
- package/node_modules/@loopwright/controller/dist/handoff.d.ts +71 -0
- package/node_modules/@loopwright/controller/dist/handoff.js +554 -0
- package/node_modules/@loopwright/controller/dist/index.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/index.js +21 -0
- package/node_modules/@loopwright/controller/dist/inspect.d.ts +30 -0
- package/node_modules/@loopwright/controller/dist/inspect.js +372 -0
- package/node_modules/@loopwright/controller/dist/interpolation.d.ts +9 -0
- package/node_modules/@loopwright/controller/dist/interpolation.js +79 -0
- package/node_modules/@loopwright/controller/dist/ownership.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/ownership.js +666 -0
- package/node_modules/@loopwright/controller/dist/parser.d.ts +5 -0
- package/node_modules/@loopwright/controller/dist/parser.js +200 -0
- package/node_modules/@loopwright/controller/dist/progress.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/progress.js +904 -0
- package/node_modules/@loopwright/controller/dist/publication.d.ts +60 -0
- package/node_modules/@loopwright/controller/dist/publication.js +329 -0
- package/node_modules/@loopwright/controller/dist/reconcile.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/reconcile.js +1378 -0
- package/node_modules/@loopwright/controller/dist/recovery.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/recovery.js +315 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.js +150 -0
- package/node_modules/@loopwright/controller/dist/registry.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/registry.js +374 -0
- package/node_modules/@loopwright/controller/dist/repair.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/repair.js +102 -0
- package/node_modules/@loopwright/controller/dist/report.d.ts +64 -0
- package/node_modules/@loopwright/controller/dist/report.js +596 -0
- package/node_modules/@loopwright/controller/dist/retained.d.ts +284 -0
- package/node_modules/@loopwright/controller/dist/retained.js +193 -0
- package/node_modules/@loopwright/controller/dist/rules.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/rules.js +110 -0
- package/node_modules/@loopwright/controller/dist/run-eval.d.ts +115 -0
- package/node_modules/@loopwright/controller/dist/run-eval.js +959 -0
- package/node_modules/@loopwright/controller/dist/scheduler.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/scheduler.js +41 -0
- package/node_modules/@loopwright/controller/dist/schema.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/schema.js +78 -0
- package/node_modules/@loopwright/controller/dist/source.d.ts +69 -0
- package/node_modules/@loopwright/controller/dist/source.js +872 -0
- package/node_modules/@loopwright/controller/dist/step.d.ts +38 -0
- package/node_modules/@loopwright/controller/dist/step.js +1776 -0
- package/node_modules/@loopwright/controller/dist/storage.d.ts +90 -0
- package/node_modules/@loopwright/controller/dist/storage.js +1345 -0
- package/node_modules/@loopwright/controller/dist/submission.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/submission.js +292 -0
- package/node_modules/@loopwright/controller/dist/types.d.ts +585 -0
- package/node_modules/@loopwright/controller/dist/types.js +9 -0
- package/node_modules/@loopwright/controller/dist/verification.d.ts +124 -0
- package/node_modules/@loopwright/controller/dist/verification.js +1308 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.d.ts +105 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.js +1312 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.d.ts +1 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.js +33 -0
- package/node_modules/@loopwright/controller/package.json +12 -0
- package/node_modules/@loopwright/core/dist/acceptance.d.ts +108 -0
- package/node_modules/@loopwright/core/dist/acceptance.js +327 -0
- package/node_modules/@loopwright/core/dist/artifacts.d.ts +63 -0
- package/node_modules/@loopwright/core/dist/artifacts.js +356 -0
- package/node_modules/@loopwright/core/dist/boundary.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/boundary.js +484 -0
- package/node_modules/@loopwright/core/dist/contracts.d.ts +287 -0
- package/node_modules/@loopwright/core/dist/contracts.js +694 -0
- package/node_modules/@loopwright/core/dist/diagnostics.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/diagnostics.js +51 -0
- package/node_modules/@loopwright/core/dist/evidence.d.ts +92 -0
- package/node_modules/@loopwright/core/dist/evidence.js +85 -0
- package/node_modules/@loopwright/core/dist/graph.d.ts +8 -0
- package/node_modules/@loopwright/core/dist/graph.js +44 -0
- package/node_modules/@loopwright/core/dist/identity.d.ts +162 -0
- package/node_modules/@loopwright/core/dist/identity.js +80 -0
- package/node_modules/@loopwright/core/dist/index.d.ts +30 -0
- package/node_modules/@loopwright/core/dist/index.js +39 -0
- package/node_modules/@loopwright/core/dist/limits.d.ts +99 -0
- package/node_modules/@loopwright/core/dist/limits.js +59 -0
- package/node_modules/@loopwright/core/dist/results.d.ts +161 -0
- package/node_modules/@loopwright/core/dist/results.js +98 -0
- package/node_modules/@loopwright/core/dist/scope.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scope.js +154 -0
- package/node_modules/@loopwright/core/dist/scrubber.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scrubber.js +63 -0
- package/node_modules/@loopwright/core/dist/usage.d.ts +68 -0
- package/node_modules/@loopwright/core/dist/usage.js +56 -0
- package/node_modules/@loopwright/core/package.json +12 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.js +337 -0
- package/node_modules/@loopwright/decisions/dist/client.d.ts +74 -0
- package/node_modules/@loopwright/decisions/dist/client.js +292 -0
- package/node_modules/@loopwright/decisions/dist/index.d.ts +15 -0
- package/node_modules/@loopwright/decisions/dist/index.js +8 -0
- package/node_modules/@loopwright/decisions/dist/nodes.d.ts +63 -0
- package/node_modules/@loopwright/decisions/dist/nodes.js +282 -0
- package/node_modules/@loopwright/decisions/dist/primitives.d.ts +36 -0
- package/node_modules/@loopwright/decisions/dist/primitives.js +300 -0
- package/node_modules/@loopwright/decisions/dist/redaction.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/redaction.js +146 -0
- package/node_modules/@loopwright/decisions/dist/router.d.ts +55 -0
- package/node_modules/@loopwright/decisions/dist/router.js +248 -0
- package/node_modules/@loopwright/decisions/dist/schema.d.ts +25 -0
- package/node_modules/@loopwright/decisions/dist/schema.js +536 -0
- package/node_modules/@loopwright/decisions/dist/types.d.ts +394 -0
- package/node_modules/@loopwright/decisions/dist/types.js +80 -0
- package/node_modules/@loopwright/decisions/package.json +12 -0
- package/node_modules/@loopwright/github-app/dist/action.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/action.js +2429 -0
- package/node_modules/@loopwright/github-app/dist/config.d.ts +23 -0
- package/node_modules/@loopwright/github-app/dist/config.js +297 -0
- package/node_modules/@loopwright/github-app/dist/digests.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/digests.js +1 -0
- package/node_modules/@loopwright/github-app/dist/index.d.ts +14 -0
- package/node_modules/@loopwright/github-app/dist/index.js +13 -0
- package/node_modules/@loopwright/github-app/dist/models-config.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/models-config.js +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.js +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.js +1 -0
- package/node_modules/@loopwright/github-app/dist/publisher.d.ts +58 -0
- package/node_modules/@loopwright/github-app/dist/publisher.js +1368 -0
- package/node_modules/@loopwright/github-app/dist/qualification.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/qualification.js +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.js +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.js +1 -0
- package/node_modules/@loopwright/github-app/dist/service.d.ts +52 -0
- package/node_modules/@loopwright/github-app/dist/service.js +1658 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.js +392 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.js +1 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.d.ts +44 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.js +423 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.d.ts +50 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.js +262 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.d.ts +35 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.js +1654 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.d.ts +16 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.js +34 -0
- package/node_modules/@loopwright/github-app/dist/types.d.ts +220 -0
- package/node_modules/@loopwright/github-app/dist/types.js +14 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.d.ts +13 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.js +65 -0
- package/node_modules/@loopwright/github-app/dist/webhook.d.ts +34 -0
- package/node_modules/@loopwright/github-app/dist/webhook.js +241 -0
- package/node_modules/@loopwright/github-app/dist/yaml.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/yaml.js +1 -0
- package/node_modules/@loopwright/github-app/package.json +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.d.ts +48 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.js +719 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.d.ts +230 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.js +3178 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.js +9 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.d.ts +128 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.js +1500 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.d.ts +81 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.js +1081 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.js +2997 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.d.ts +239 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.js +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.d.ts +49 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.js +1648 -0
- package/node_modules/@loopwright/hardware-runner/package.json +12 -0
- package/node_modules/@loopwright/memory/dist/cas.d.ts +21 -0
- package/node_modules/@loopwright/memory/dist/cas.js +510 -0
- package/node_modules/@loopwright/memory/dist/compaction.d.ts +18 -0
- package/node_modules/@loopwright/memory/dist/compaction.js +110 -0
- package/node_modules/@loopwright/memory/dist/finalizer.d.ts +23 -0
- package/node_modules/@loopwright/memory/dist/finalizer.js +538 -0
- package/node_modules/@loopwright/memory/dist/index.d.ts +9 -0
- package/node_modules/@loopwright/memory/dist/index.js +8 -0
- package/node_modules/@loopwright/memory/dist/schema.d.ts +36 -0
- package/node_modules/@loopwright/memory/dist/schema.js +510 -0
- package/node_modules/@loopwright/memory/dist/selector.d.ts +7 -0
- package/node_modules/@loopwright/memory/dist/selector.js +157 -0
- package/node_modules/@loopwright/memory/dist/store.d.ts +51 -0
- package/node_modules/@loopwright/memory/dist/store.js +554 -0
- package/node_modules/@loopwright/memory/dist/types.d.ts +442 -0
- package/node_modules/@loopwright/memory/dist/types.js +8 -0
- package/node_modules/@loopwright/memory/dist/verifier.d.ts +5 -0
- package/node_modules/@loopwright/memory/dist/verifier.js +328 -0
- package/node_modules/@loopwright/memory/package.json +12 -0
- package/node_modules/@loopwright/state/dist/admission.d.ts +321 -0
- package/node_modules/@loopwright/state/dist/admission.js +199 -0
- package/node_modules/@loopwright/state/dist/boundary.d.ts +53 -0
- package/node_modules/@loopwright/state/dist/boundary.js +194 -0
- package/node_modules/@loopwright/state/dist/checkpoint.d.ts +16 -0
- package/node_modules/@loopwright/state/dist/checkpoint.js +84 -0
- package/node_modules/@loopwright/state/dist/clock.d.ts +8 -0
- package/node_modules/@loopwright/state/dist/clock.js +27 -0
- package/node_modules/@loopwright/state/dist/connection.d.ts +55 -0
- package/node_modules/@loopwright/state/dist/connection.js +391 -0
- package/node_modules/@loopwright/state/dist/errors.d.ts +13 -0
- package/node_modules/@loopwright/state/dist/errors.js +34 -0
- package/node_modules/@loopwright/state/dist/index.d.ts +3 -0
- package/node_modules/@loopwright/state/dist/index.js +1 -0
- package/node_modules/@loopwright/state/dist/journal.d.ts +119 -0
- package/node_modules/@loopwright/state/dist/journal.js +72 -0
- package/node_modules/@loopwright/state/dist/model.d.ts +40 -0
- package/node_modules/@loopwright/state/dist/model.js +58 -0
- package/node_modules/@loopwright/state/dist/ownership.d.ts +14 -0
- package/node_modules/@loopwright/state/dist/ownership.js +45 -0
- package/node_modules/@loopwright/state/dist/pages.d.ts +11 -0
- package/node_modules/@loopwright/state/dist/pages.js +41 -0
- package/node_modules/@loopwright/state/dist/receipts.d.ts +33 -0
- package/node_modules/@loopwright/state/dist/receipts.js +97 -0
- package/node_modules/@loopwright/state/dist/schema.d.ts +28 -0
- package/node_modules/@loopwright/state/dist/schema.js +41 -0
- package/node_modules/@loopwright/state/dist/settlement.d.ts +10 -0
- package/node_modules/@loopwright/state/dist/settlement.js +129 -0
- package/node_modules/@loopwright/state/dist/store.d.ts +52 -0
- package/node_modules/@loopwright/state/dist/store.js +100 -0
- package/node_modules/@loopwright/state/dist/types.d.ts +315 -0
- package/node_modules/@loopwright/state/dist/types.js +1 -0
- package/node_modules/@loopwright/state/package.json +12 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.d.ts +195 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.js +1847 -0
- package/node_modules/@loopwright/taskpack/dist/digests.d.ts +61 -0
- package/node_modules/@loopwright/taskpack/dist/digests.js +715 -0
- package/node_modules/@loopwright/taskpack/dist/index.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/index.js +17 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.d.ts +112 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.js +1026 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.d.ts +28 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.js +157 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.d.ts +130 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.js +1497 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.d.ts +23 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.js +120 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.d.ts +121 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.js +2642 -0
- package/node_modules/@loopwright/taskpack/dist/schema.d.ts +197 -0
- package/node_modules/@loopwright/taskpack/dist/schema.js +4189 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.d.ts +47 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.js +283 -0
- package/node_modules/@loopwright/taskpack/dist/suite.d.ts +124 -0
- package/node_modules/@loopwright/taskpack/dist/suite.js +3256 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.d.ts +154 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.js +3634 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.d.ts +122 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.js +483 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.d.ts +437 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.js +7335 -0
- package/node_modules/@loopwright/taskpack/dist/types.d.ts +1274 -0
- package/node_modules/@loopwright/taskpack/dist/types.js +99 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.d.ts +261 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.js +2242 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.js +167 -0
- package/node_modules/@loopwright/taskpack/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.d.ts +137 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.js +474 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.d.ts +8 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.js +129 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.js +7 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.js +135 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.d.ts +130 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.js +927 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.d.ts +68 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.js +517 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.js +1796 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.d.ts +29 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.js +11 -0
- package/node_modules/@loopwright/taskpack-runner/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/README.md +77 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/support-records.md +57 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/supported-runners.md +98 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/manifest.json +205 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/expand_matrix.sh +273 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/matrix.yaml +280 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/resolve_dockerfile.sh +24 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pyproject.toml +46 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/runtime_runner/runner.py.json +5270 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/discovery/legacy-support.md +86 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/github/service.py +401 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/analysis.json +95 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/ready.json +109 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_assemble.py +263 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_check_draft.py +333 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_checks.py +1099 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_discovery.py +817 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_proposal.py +658 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_publish.py +987 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_summary.py +107 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/agent.py +610 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/assemble.py +84 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/check_draft.py +94 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/checks.py +1002 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/discovery.py +789 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/model.py +557 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/progress.py +174 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/analysis.md +40 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/proposal.md +65 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/repair.md +17 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/proposal.py +903 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/publish.py +997 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/summary.py +131 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/tool-versions.json +133 -0
- package/node_modules/package-lock.json +3025 -0
- package/package-lock.json +3025 -0
- package/package.json +52 -4
|
@@ -0,0 +1,2429 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { closeSync, constants as fsConstants, existsSync, openSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { chmod, lstat, mkdir, open, realpath, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { PI_THINKING_LEVELS, PI_WIRE_APIS, STANDARD_PI_PROVIDER_ENV, isOAuthOnlyPiProvider, resolveCatalogModel } from '@loopwright/agent-pi/catalog';
|
|
8
|
+
import { HostMcpRegistry } from '@loopwright/agent-pi/mcp';
|
|
9
|
+
import { formatDurationMs, formatTokenCount } from '@loopwright/controller';
|
|
10
|
+
import { DECISION_PROVIDER_API_KEY_ENV } from '@loopwright/decisions';
|
|
11
|
+
import { alignBaselineRevisions, BASELINE_CONFLICT_REASON, boundUtf8Lines, buildDefaultAuthorPrompt, collectHostCredentialEnvNames, collectHostGateCredentialEnvNames, createTaskpackDecisionPort, insideRoot, loadTaskpackSuite, mergeMcpServerDeclarations, parseAllowedHostMounts, parseBaselineAlignmentPolicy, parseMcpServersOverride, resolveBaselineAlignmentConfig, resolveExternalMcpConfigs, resolveTaskpackSuite, serializeActionResultSummary as taskpackSerializeActionResultSummary, } from '@loopwright/taskpack';
|
|
12
|
+
import { LOOPWRIGHT_ACTIVE_PROVIDER_TOKEN_ENV, loadPiModelsJson, resolveDefaultProviderTokenEnv, resolveTaskpackModelCandidates, resolveTaskpackModelSelection, selectHealthyModelCandidate, } from './models-config.js';
|
|
13
|
+
import { resolveActionOutputFormats, writeActionOutputSinks } from './output-format.js';
|
|
14
|
+
import { collectManifestSecretEnvNames, formatWorkspaceResourcesManifest, runTaskpackPreflight, } from './preflight.js';
|
|
15
|
+
import { startNativePullRequestPublisherServer } from './publisher.js';
|
|
16
|
+
import { validateMcpAuthConfiguration, qualifyDeploymentHostProfile } from './qualification.js';
|
|
17
|
+
import { negotiateSandboxBackend, resolveEffectiveTaskpackSandboxPolicy } from './sandbox.js';
|
|
18
|
+
import { collectMcpReferencedEnvNames, hasAnyDeclaredGitHubTrigger, isGitHubTriggerDeclared } from './schema.js';
|
|
19
|
+
import { validateGitHubApiBaseUrl, verifySuiteCommentPullRequest, } from './suite-pr-lookup.js';
|
|
20
|
+
import { authorizeRepositoryActor, compileDeclarativeTaskpack, DEFAULT_HOST_BUDGETS, loadDeclarativeTaskpack, mergeTaskpackLimits, parseActionInputLimits, parseCommentCommand, parseLoopwrightEnvLimits, prepareTaskpackIntake, resolveTaskpackMemoryLocation, stageCompiledInstructionResources, validateCommentGuidance, } from './taskpack.js';
|
|
21
|
+
import { assertCleanArtifact, SecretScrubber } from './token-broker.js';
|
|
22
|
+
import { createTurnkeyCycleDelegate, normalizeControllerRunId, startLocalCommandGateServer, validateGateToolchainPath, } from './turnkey.js';
|
|
23
|
+
import { finalizeAndPublishTurnkeyMemory } from './turnkey-memory.js';
|
|
24
|
+
import { checkManagedPrMatchesDiscoveredState, COMMIT_SHA_PATTERN, DEFAULT_GIT_COMMIT_IDENTITY, discoverTaskpackUpstreamsV2, findOpenManagedPullRequest, isPlainRecord, parseOptionalGitIdentityInput, resolveGitCommitSha, resolveGitHubAuth, resolveGitHubToken, resolveRepositoryAndRevisions, shouldPreserveExplicitSourceRevision, validateGitAuthorEmail, validateGitAuthorName, } from './upstreams.js';
|
|
25
|
+
import { serializePrettyYaml } from './yaml.js';
|
|
26
|
+
import { DEFAULT_LOCAL_COMMAND_GATE_ENV, GitHubAppError, LOCAL_COMMAND_GATE_ENDPOINT_ID, TASKPACK_COMMENT_COMMANDS, } from './types.js';
|
|
27
|
+
export { boundUtf8Lines, buildDefaultAuthorPrompt, createTaskpackDecisionPort, insideRoot, mergeMcpServerDeclarations, parseMcpServersOverride, };
|
|
28
|
+
function isSuiteActionResult(result) {
|
|
29
|
+
return result.kind === 'eligible' || result.kind === 'deferred' || result.kind === 'ignored';
|
|
30
|
+
}
|
|
31
|
+
export function serializeActionResultSummary(result, scrubber) {
|
|
32
|
+
if (isSuiteActionResult(result)) {
|
|
33
|
+
const payload = {
|
|
34
|
+
kind: result.kind,
|
|
35
|
+
disposition: result.disposition,
|
|
36
|
+
reason: result.reason,
|
|
37
|
+
...(result.detail !== undefined ? { detail: result.detail } : {}),
|
|
38
|
+
suite: result.suite,
|
|
39
|
+
matrix: result.matrix,
|
|
40
|
+
};
|
|
41
|
+
return scrubber.scrub(JSON.stringify(payload));
|
|
42
|
+
}
|
|
43
|
+
return taskpackSerializeActionResultSummary(result, scrubber);
|
|
44
|
+
}
|
|
45
|
+
function systemSample() {
|
|
46
|
+
return { wallMs: Date.now(), monotonicMs: (process.hrtime.bigint() / 1000000n).toString() };
|
|
47
|
+
}
|
|
48
|
+
async function validateManifestCommandToolchainPaths(manifest, repositoryRoot, allowPrivileged) {
|
|
49
|
+
let realTmpRoot;
|
|
50
|
+
for (const check of manifest.spec.verification.localChecks) {
|
|
51
|
+
if (check.implementation !== 'command.v1')
|
|
52
|
+
continue;
|
|
53
|
+
const rawPaths = check.parameters?.['toolchainPaths'];
|
|
54
|
+
if (!Array.isArray(rawPaths) || rawPaths.length === 0)
|
|
55
|
+
continue;
|
|
56
|
+
realTmpRoot ??= await realpath(tmpdir());
|
|
57
|
+
const script = typeof check.parameters?.['script'] === 'string' ? check.parameters['script'] : '';
|
|
58
|
+
const gate = {
|
|
59
|
+
checkId: check.id,
|
|
60
|
+
gateId: `precheck-${check.id}`,
|
|
61
|
+
endpointRef: LOCAL_COMMAND_GATE_ENDPOINT_ID,
|
|
62
|
+
script,
|
|
63
|
+
scriptSha256: '0'.repeat(64),
|
|
64
|
+
timeoutSeconds: 30,
|
|
65
|
+
allowReadOnlyGitHubToken: false,
|
|
66
|
+
env: [],
|
|
67
|
+
allowPrivileged,
|
|
68
|
+
};
|
|
69
|
+
for (const tp of rawPaths) {
|
|
70
|
+
if (typeof tp !== 'string')
|
|
71
|
+
continue;
|
|
72
|
+
await validateGateToolchainPath(tp, gate, repositoryRoot, realTmpRoot);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function blocked(reason, detail) {
|
|
77
|
+
return detail === undefined ? { kind: 'blocked', reason } : { kind: 'blocked', reason, detail };
|
|
78
|
+
}
|
|
79
|
+
function readString(record, field) {
|
|
80
|
+
if (record === null || typeof record !== 'object' || Array.isArray(record))
|
|
81
|
+
return null;
|
|
82
|
+
const value = record[field];
|
|
83
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
84
|
+
}
|
|
85
|
+
function extractPreliminaryCommentCommand(payload, eventName, commentPrefixes) {
|
|
86
|
+
const isPullRequestReview = eventName === 'pull_request_review';
|
|
87
|
+
const payloadRecord = payload !== null && typeof payload === 'object' && !Array.isArray(payload)
|
|
88
|
+
? payload
|
|
89
|
+
: null;
|
|
90
|
+
if (payloadRecord === null)
|
|
91
|
+
return null;
|
|
92
|
+
const action = typeof payloadRecord['action'] === 'string' ? payloadRecord['action'] : '';
|
|
93
|
+
if (isPullRequestReview ? action !== 'submitted' : action !== 'created')
|
|
94
|
+
return null;
|
|
95
|
+
if (!isPullRequestReview && readObject(payloadRecord['issue'], 'pull_request') === null)
|
|
96
|
+
return null;
|
|
97
|
+
const containerRaw = payloadRecord['comment'] ?? payloadRecord['review'];
|
|
98
|
+
const body = readString(containerRaw, 'body');
|
|
99
|
+
const userObj = readObject(containerRaw, 'user');
|
|
100
|
+
const login = readString(userObj, 'login');
|
|
101
|
+
const association = readString(containerRaw, 'author_association');
|
|
102
|
+
if (body === null || login === null || association === null)
|
|
103
|
+
return null;
|
|
104
|
+
const userType = readString(userObj, 'type');
|
|
105
|
+
if (userType === 'Bot' || login.toLowerCase().endsWith('[bot]'))
|
|
106
|
+
return null;
|
|
107
|
+
return parseCommentCommand(body, commentPrefixes, TASKPACK_COMMENT_COMMANDS)?.command ?? null;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Evaluate a comment/review event payload under the manifest trigger configuration. Bot authors (by
|
|
111
|
+
* `user.type` or a `[bot]` login suffix), non-created/non-submitted actions, comments outside pull
|
|
112
|
+
* requests, unknown prefixes, and commands outside the configured set are ignored; authorized actors with
|
|
113
|
+
* valid guidance yield a bound evaluation.
|
|
114
|
+
*/
|
|
115
|
+
export function evaluateCommentPayload(payload, options) {
|
|
116
|
+
const isPullRequestReview = options.eventName === 'pull_request_review';
|
|
117
|
+
const payloadRecord = payload !== null && typeof payload === 'object' && !Array.isArray(payload) ? payload : null;
|
|
118
|
+
const action = payloadRecord === null ? '' : typeof payloadRecord['action'] === 'string' ? payloadRecord['action'] : '';
|
|
119
|
+
if (isPullRequestReview) {
|
|
120
|
+
if (action !== 'submitted')
|
|
121
|
+
return { ignoredReason: `review action ${action} is not submitted` };
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
if (action !== 'created')
|
|
125
|
+
return { ignoredReason: `comment action ${action} is not created` };
|
|
126
|
+
}
|
|
127
|
+
const containerRaw = payloadRecord === null ? null : payloadRecord['comment'] ?? payloadRecord['review'];
|
|
128
|
+
const body = readString(containerRaw, 'body');
|
|
129
|
+
const login = readString(readObject(containerRaw, 'user'), 'login');
|
|
130
|
+
const association = readString(containerRaw, 'author_association');
|
|
131
|
+
if (body === null || login === null || association === null)
|
|
132
|
+
return { blockedReason: 'event payload is missing comment attribution' };
|
|
133
|
+
const userType = readString(readObject(containerRaw, 'user'), 'type');
|
|
134
|
+
if (userType === 'Bot' || login.toLowerCase().endsWith('[bot]'))
|
|
135
|
+
return { ignoredReason: 'comment author is a bot' };
|
|
136
|
+
if (!isPullRequestReview) {
|
|
137
|
+
const issue = payloadRecord === null ? null : payloadRecord['issue'];
|
|
138
|
+
if (readObject(issue, 'pull_request') === null)
|
|
139
|
+
return { ignoredReason: 'comment is not on a pull request' };
|
|
140
|
+
}
|
|
141
|
+
const command = parseCommentCommand(body, options.commentPrefixes, options.commentCommands);
|
|
142
|
+
if (command === null)
|
|
143
|
+
return { ignoredReason: 'comment without a configured command prefix or supported command' };
|
|
144
|
+
if (!authorizeRepositoryActor(association, login, options.operatorAllowlist)) {
|
|
145
|
+
return { blockedReason: `actor ${login} lacks write access (${association})` };
|
|
146
|
+
}
|
|
147
|
+
const guidance = validateCommentGuidance(command.guidance);
|
|
148
|
+
if (!guidance.ok)
|
|
149
|
+
return { blockedReason: 'comment guidance breaks the intake bounds', detail: guidance.detail };
|
|
150
|
+
const issue = payloadRecord === null ? null : payloadRecord['issue'];
|
|
151
|
+
const pullRequest = readObject(issue, 'pull_request');
|
|
152
|
+
const head = readObject(pullRequest, 'head');
|
|
153
|
+
const rawId = containerRaw !== null && typeof containerRaw === 'object' && !Array.isArray(containerRaw)
|
|
154
|
+
? containerRaw['id'] : undefined;
|
|
155
|
+
const commentId = typeof rawId === 'number' && Number.isSafeInteger(rawId) && rawId > 0 ? rawId : 0;
|
|
156
|
+
return {
|
|
157
|
+
command: command.command,
|
|
158
|
+
guidance: command.guidance,
|
|
159
|
+
login,
|
|
160
|
+
authorAssociation: association,
|
|
161
|
+
commandId: commentId,
|
|
162
|
+
headSha: readString(head, 'sha') ?? readString(pullRequest, 'sha') ?? `pr-${issue === null ? 'unknown' : String(readNumber(issue, 'number') ?? 'unknown')}`,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function readObject(value, field) {
|
|
166
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
167
|
+
return null;
|
|
168
|
+
const child = value[field];
|
|
169
|
+
return child !== null && typeof child === 'object' && !Array.isArray(child) ? child : null;
|
|
170
|
+
}
|
|
171
|
+
function readNumber(value, field) {
|
|
172
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
173
|
+
return null;
|
|
174
|
+
const number = value[field];
|
|
175
|
+
return typeof number === 'number' && Number.isSafeInteger(number) ? number : null;
|
|
176
|
+
}
|
|
177
|
+
function shouldRotateModelCandidate(outcome) {
|
|
178
|
+
if (outcome.ok)
|
|
179
|
+
return false;
|
|
180
|
+
if (/reconcile_required|PUBLICATION_|GATE_/i.test(outcome.detail))
|
|
181
|
+
return false;
|
|
182
|
+
if (outcome.retryableProviderFailure !== undefined)
|
|
183
|
+
return outcome.retryableProviderFailure;
|
|
184
|
+
return /PROVIDER_RESPONSE_INVALID|PROVIDER_TIMEOUT|MODEL_UNAVAILABLE|insufficient_quota|quota|rate_limit|http_402|http_429|1113/i.test(outcome.detail);
|
|
185
|
+
}
|
|
186
|
+
async function invokeDelegateForCandidate(candidate, taskpack, delegate) {
|
|
187
|
+
if (!candidate.usesActiveTokenEnv || candidate.token === undefined) {
|
|
188
|
+
return delegate(taskpack);
|
|
189
|
+
}
|
|
190
|
+
const previous = process.env[LOOPWRIGHT_ACTIVE_PROVIDER_TOKEN_ENV];
|
|
191
|
+
process.env[LOOPWRIGHT_ACTIVE_PROVIDER_TOKEN_ENV] = candidate.token;
|
|
192
|
+
try {
|
|
193
|
+
return await delegate(taskpack);
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
if (previous === undefined) {
|
|
197
|
+
delete process.env[LOOPWRIGHT_ACTIVE_PROVIDER_TOKEN_ENV];
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
process.env[LOOPWRIGHT_ACTIVE_PROVIDER_TOKEN_ENV] = previous;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function serializeSuiteMatrixJson(matrix, scrubber) {
|
|
205
|
+
const include = matrix.include.map(cell => {
|
|
206
|
+
let normalizedMatrix;
|
|
207
|
+
if (cell.matrix !== undefined) {
|
|
208
|
+
if (Array.isArray(cell.matrix)) {
|
|
209
|
+
normalizedMatrix = cell.matrix.map(entry => ({
|
|
210
|
+
id: entry.id,
|
|
211
|
+
platform: entry.platform,
|
|
212
|
+
variant: entry.variant,
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const sorted = {};
|
|
217
|
+
for (const key of Object.keys(cell.matrix).sort()) {
|
|
218
|
+
const val = cell.matrix[key];
|
|
219
|
+
if (val !== undefined)
|
|
220
|
+
sorted[key] = val;
|
|
221
|
+
}
|
|
222
|
+
normalizedMatrix = sorted;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
domainId: cell.domainId,
|
|
227
|
+
taskpackPath: cell.taskpackPath,
|
|
228
|
+
taskpackName: cell.taskpackName,
|
|
229
|
+
manifestSha256: cell.manifestSha256,
|
|
230
|
+
controlRoot: cell.controlRoot,
|
|
231
|
+
baseRevision: cell.baseRevision,
|
|
232
|
+
...(cell.headSha !== undefined ? { headSha: cell.headSha } : {}),
|
|
233
|
+
...(cell.stage !== undefined ? { stage: cell.stage } : {}),
|
|
234
|
+
...(normalizedMatrix !== undefined ? { matrix: normalizedMatrix } : {}),
|
|
235
|
+
protectedPaths: [...cell.protectedPaths],
|
|
236
|
+
};
|
|
237
|
+
});
|
|
238
|
+
return scrubber.scrub(JSON.stringify({ include })).replace(/[\r\n]/g, ' ');
|
|
239
|
+
}
|
|
240
|
+
async function writeSuiteMatrixGithubOutput(githubOutputPath, matrix, scrubber) {
|
|
241
|
+
if (githubOutputPath === undefined || githubOutputPath.trim().length === 0)
|
|
242
|
+
return;
|
|
243
|
+
const resolved = resolve(githubOutputPath);
|
|
244
|
+
const parent = dirname(resolved);
|
|
245
|
+
await mkdir(parent, { recursive: true });
|
|
246
|
+
const parentStats = await lstat(parent);
|
|
247
|
+
if (parentStats.isSymbolicLink() || !parentStats.isDirectory()) {
|
|
248
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `output parent "${parent}" must be a non-symlink directory`);
|
|
249
|
+
}
|
|
250
|
+
const realParentBefore = await realpath(parent);
|
|
251
|
+
const noFollow = 'O_NOFOLLOW' in fsConstants ? fsConstants.O_NOFOLLOW : 0;
|
|
252
|
+
const serialized = serializeSuiteMatrixJson(matrix, scrubber);
|
|
253
|
+
const payload = `matrix<<LOOPWRIGHT_EOF\n${serialized}\nLOOPWRIGHT_EOF\n`;
|
|
254
|
+
const handle = await open(resolved, fsConstants.O_CREAT | fsConstants.O_APPEND | fsConstants.O_WRONLY | noFollow, 0o600);
|
|
255
|
+
try {
|
|
256
|
+
const stats = await handle.stat();
|
|
257
|
+
const postParentStats = await lstat(parent);
|
|
258
|
+
const postRealParent = await realpath(parent);
|
|
259
|
+
const postLeafStats = await lstat(resolved);
|
|
260
|
+
if (!stats.isFile()
|
|
261
|
+
|| stats.nlink !== 1
|
|
262
|
+
|| postParentStats.isSymbolicLink()
|
|
263
|
+
|| postParentStats.dev !== parentStats.dev
|
|
264
|
+
|| postParentStats.ino !== parentStats.ino
|
|
265
|
+
|| postRealParent !== realParentBefore
|
|
266
|
+
|| postLeafStats.isSymbolicLink()
|
|
267
|
+
|| postLeafStats.dev !== stats.dev
|
|
268
|
+
|| postLeafStats.ino !== stats.ino) {
|
|
269
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', `output sink "${resolved}" must be a non-symlink regular file under a stable directory`);
|
|
270
|
+
}
|
|
271
|
+
await handle.writeFile(payload, 'utf8');
|
|
272
|
+
}
|
|
273
|
+
finally {
|
|
274
|
+
await handle.close();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
export async function runGitHubActionEntrypoint(input) {
|
|
278
|
+
const entrypointStartedMs = performance.now();
|
|
279
|
+
const runtimeEnv = input.env ?? process.env;
|
|
280
|
+
const turnkeyScrubber = new SecretScrubber();
|
|
281
|
+
const emitProgress = input.progressSink !== undefined
|
|
282
|
+
? (line) => { input.progressSink(turnkeyScrubber.scrub(line)); }
|
|
283
|
+
: undefined;
|
|
284
|
+
let explicitLimitsOverride;
|
|
285
|
+
let envLimitsFallback;
|
|
286
|
+
let explicitGitAuthorName;
|
|
287
|
+
let explicitGitAuthorEmail;
|
|
288
|
+
try {
|
|
289
|
+
envLimitsFallback = parseLoopwrightEnvLimits(runtimeEnv);
|
|
290
|
+
const actionInputLimits = parseActionInputLimits(runtimeEnv);
|
|
291
|
+
explicitLimitsOverride = mergeTaskpackLimits(actionInputLimits, input.limits);
|
|
292
|
+
explicitGitAuthorName = parseOptionalGitIdentityInput(input.gitAuthorName, runtimeEnv['INPUT_GIT-AUTHOR-NAME'], validateGitAuthorName);
|
|
293
|
+
explicitGitAuthorEmail = parseOptionalGitIdentityInput(input.gitAuthorEmail, runtimeEnv['INPUT_GIT-AUTHOR-EMAIL'], validateGitAuthorEmail);
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
if (error instanceof GitHubAppError) {
|
|
297
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
298
|
+
}
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
const storageProfile = input.storageProfile ?? 'actions-basic';
|
|
302
|
+
const startSample = input.previousClockSample ?? systemSample();
|
|
303
|
+
const preManifestWallSeconds = explicitLimitsOverride.wallTimeSeconds ?? envLimitsFallback.wallTimeSeconds;
|
|
304
|
+
const basisWallTimeMs = preManifestWallSeconds !== undefined
|
|
305
|
+
? preManifestWallSeconds * 1000
|
|
306
|
+
: (input.budgets?.wallTimeMs ?? DEFAULT_HOST_BUDGETS.wallTimeMs);
|
|
307
|
+
const basis = input.clockBasis ?? {
|
|
308
|
+
clockEpoch: input.runId,
|
|
309
|
+
created: { ...startSample },
|
|
310
|
+
taskDeadlineMonotonicMs: (BigInt(startSample.monotonicMs) + BigInt(basisWallTimeMs)).toString(),
|
|
311
|
+
};
|
|
312
|
+
await mkdir(input.runRoot, { recursive: true, mode: 0o700 }).catch(() => undefined);
|
|
313
|
+
await chmod(input.runRoot, 0o700).catch(() => undefined);
|
|
314
|
+
const qualification = await qualifyDeploymentHostProfile({
|
|
315
|
+
platform: process.platform,
|
|
316
|
+
arch: process.arch,
|
|
317
|
+
nodeVersion: process.version,
|
|
318
|
+
filesystemType: input.filesystemType ?? 'local-posix',
|
|
319
|
+
storageProfile,
|
|
320
|
+
clockBasis: basis,
|
|
321
|
+
previousClockSample: startSample,
|
|
322
|
+
currentClockSample: input.currentClockSample ?? systemSample(),
|
|
323
|
+
hasVerifiedCheckpointLedger: true,
|
|
324
|
+
autoResumeOnHostLossRequested: false,
|
|
325
|
+
probeDirectory: input.probeDirectory ?? input.runRoot,
|
|
326
|
+
});
|
|
327
|
+
if (!qualification.ok) {
|
|
328
|
+
return qualification.recommendedRunStatus === undefined
|
|
329
|
+
? { kind: 'refused', code: qualification.code, reason: qualification.reason }
|
|
330
|
+
: { kind: 'refused', code: qualification.code, reason: qualification.reason, recommendedRunStatus: qualification.recommendedRunStatus };
|
|
331
|
+
}
|
|
332
|
+
const mcp = validateMcpAuthConfiguration({ servers: input.mcpServers ?? [], transportChallenge: input.mcpTransportChallenge ?? null });
|
|
333
|
+
if (!mcp.ok)
|
|
334
|
+
return { kind: 'refused', code: mcp.code, reason: mcp.reason };
|
|
335
|
+
if (input.provider !== undefined && isOAuthOnlyPiProvider(input.provider)) {
|
|
336
|
+
return {
|
|
337
|
+
kind: 'refused',
|
|
338
|
+
code: 'PROVIDER_OAUTH_UNSUPPORTED',
|
|
339
|
+
reason: `Pi provider "${input.provider}" uses OAuth or CLI login, which Loopwright refuses; configure a token-authenticated Pi provider`,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
let parsedAllowedHostMounts;
|
|
343
|
+
try {
|
|
344
|
+
parsedAllowedHostMounts = parseAllowedHostMounts(input.hostPolicy?.allowedHostMounts
|
|
345
|
+
?? input.allowHostMounts
|
|
346
|
+
?? runtimeEnv['INPUT_ALLOW-HOST-MOUNTS'], 'allow-host-mounts');
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
return blocked('ACTION_INPUT_INVALID', error instanceof Error ? error.message : String(error));
|
|
350
|
+
}
|
|
351
|
+
const hostPolicy = Object.freeze({
|
|
352
|
+
policyProfile: 'github',
|
|
353
|
+
allowPrivileged: input.hostPolicy?.allowPrivileged
|
|
354
|
+
?? input.allowPrivilegedExecution
|
|
355
|
+
?? (runtimeEnv['INPUT_ALLOW-PRIVILEGED-EXECUTION'] === 'true'),
|
|
356
|
+
allowWorkflowWrites: input.hostPolicy?.allowWorkflowWrites
|
|
357
|
+
?? input.allowWorkflowWrites
|
|
358
|
+
?? (runtimeEnv['INPUT_ALLOW-WORKFLOW-WRITES'] === 'true'),
|
|
359
|
+
allowedHostMounts: parsedAllowedHostMounts,
|
|
360
|
+
});
|
|
361
|
+
const effectiveSuitePath = (input.suitePath ?? runtimeEnv['INPUT_SUITE-PATH'])?.trim() || undefined;
|
|
362
|
+
const effectiveDomain = (input.domain ?? runtimeEnv['INPUT_DOMAIN'])?.trim() || undefined;
|
|
363
|
+
const rawResolveSuiteOnlyEnv = runtimeEnv['INPUT_RESOLVE-SUITE-ONLY']?.trim();
|
|
364
|
+
let resolveSuiteOnly = false;
|
|
365
|
+
if (input.resolveSuiteOnly !== undefined) {
|
|
366
|
+
resolveSuiteOnly = input.resolveSuiteOnly;
|
|
367
|
+
}
|
|
368
|
+
else if (rawResolveSuiteOnlyEnv !== undefined && rawResolveSuiteOnlyEnv.length > 0) {
|
|
369
|
+
if (rawResolveSuiteOnlyEnv === 'true') {
|
|
370
|
+
resolveSuiteOnly = true;
|
|
371
|
+
}
|
|
372
|
+
else if (rawResolveSuiteOnlyEnv === 'false') {
|
|
373
|
+
resolveSuiteOnly = false;
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
return blocked('ACTION_INPUT_INVALID', `resolve-suite-only must be "true" or "false" (received "${rawResolveSuiteOnlyEnv}")`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
if (effectiveDomain !== undefined && effectiveSuitePath === undefined) {
|
|
380
|
+
return blocked('ACTION_INPUT_INVALID', 'domain input requires suite-path');
|
|
381
|
+
}
|
|
382
|
+
if (resolveSuiteOnly && effectiveSuitePath === undefined) {
|
|
383
|
+
return blocked('ACTION_INPUT_INVALID', 'resolve-suite-only requires suite-path');
|
|
384
|
+
}
|
|
385
|
+
const rawApiBaseUrl = input.githubApiBaseUrl?.trim() || runtimeEnv['GITHUB_API_URL']?.trim() || undefined;
|
|
386
|
+
let effectiveApiBaseUrl;
|
|
387
|
+
if (rawApiBaseUrl !== undefined) {
|
|
388
|
+
try {
|
|
389
|
+
effectiveApiBaseUrl = validateGitHubApiBaseUrl(rawApiBaseUrl, 'ACTION_INPUT_INVALID', '/githubApiBaseUrl');
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
if (error instanceof GitHubAppError) {
|
|
393
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
394
|
+
}
|
|
395
|
+
throw error;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const effectiveGithubOutputPath = input.githubOutputPath ?? runtimeEnv['GITHUB_OUTPUT'];
|
|
399
|
+
const decisionApiKeyEnvs = Object.values(DECISION_PROVIDER_API_KEY_ENV).flat();
|
|
400
|
+
let effectiveTaskpackPath = input.taskpackPath;
|
|
401
|
+
let effectiveBaseRevision = input.baseRevision;
|
|
402
|
+
let effectiveEventPayload = input.eventPayload;
|
|
403
|
+
let effectiveTargetMatrix = input.targetMatrix;
|
|
404
|
+
let suiteExtraProtectedPaths;
|
|
405
|
+
let loadedSuite;
|
|
406
|
+
let suiteResolution;
|
|
407
|
+
let verifiedSuiteCommentMeta;
|
|
408
|
+
if (effectiveSuitePath !== undefined) {
|
|
409
|
+
try {
|
|
410
|
+
loadedSuite = await loadTaskpackSuite({
|
|
411
|
+
repositoryRoot: input.repositoryRoot,
|
|
412
|
+
suitePath: effectiveSuitePath,
|
|
413
|
+
policyProfile: 'github',
|
|
414
|
+
hostPolicy,
|
|
415
|
+
allowLoopbackHttp: input.allowManifestCustomBaseUrl === true,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
if (error instanceof GitHubAppError) {
|
|
420
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED'
|
|
421
|
+
|| error.code === 'MCP_OAUTH_UNSUPPORTED'
|
|
422
|
+
|| error.code === 'TASKPACK_HOST_BINDING_INVALID'
|
|
423
|
+
|| (error.code === 'TASKPACK_SCOPE_VIOLATION' && error.path?.startsWith('/spec/execution') === true)) {
|
|
424
|
+
return { kind: 'refused', code: error.code, reason: error.message };
|
|
425
|
+
}
|
|
426
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
427
|
+
}
|
|
428
|
+
throw error;
|
|
429
|
+
}
|
|
430
|
+
for (const secretEnvKey of [
|
|
431
|
+
'GITHUB_TOKEN',
|
|
432
|
+
'GH_TOKEN',
|
|
433
|
+
'INPUT_GITHUB-TOKEN',
|
|
434
|
+
'INPUT_GITHUB-APP-PRIVATE-KEY',
|
|
435
|
+
input.providerTokenEnv,
|
|
436
|
+
input.credentialEnvMap?.provider,
|
|
437
|
+
input.credentialEnvMap?.gate ?? 'LOOPWRIGHT_GATE_SIGNING_SECRET',
|
|
438
|
+
input.credentialEnvMap?.publication ?? 'LOOPWRIGHT_PUBLICATION_SIGNING_SECRET',
|
|
439
|
+
input.credentialEnvMap?.publicationAuth ?? 'LOOPWRIGHT_PUBLICATION_AUTH_TOKEN',
|
|
440
|
+
input.credentialEnvMap?.localCommandGate ?? DEFAULT_LOCAL_COMMAND_GATE_ENV,
|
|
441
|
+
...Object.values(STANDARD_PI_PROVIDER_ENV),
|
|
442
|
+
...decisionApiKeyEnvs,
|
|
443
|
+
...loadedSuite.domains.flatMap(dom => [
|
|
444
|
+
...collectManifestSecretEnvNames(dom.manifest),
|
|
445
|
+
...collectMcpReferencedEnvNames(dom.manifest.spec.mcp?.servers),
|
|
446
|
+
]),
|
|
447
|
+
]) {
|
|
448
|
+
if (typeof secretEnvKey === 'string' && secretEnvKey.length > 0) {
|
|
449
|
+
const val = runtimeEnv[secretEnvKey];
|
|
450
|
+
if (typeof val === 'string' && val.trim().length > 0) {
|
|
451
|
+
turnkeyScrubber.register(val.trim());
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
if (typeof input.decisionApiKey === 'string' && input.decisionApiKey.trim().length > 0) {
|
|
456
|
+
turnkeyScrubber.register(input.decisionApiKey.trim());
|
|
457
|
+
}
|
|
458
|
+
if (typeof input.githubToken === 'string' && input.githubToken.trim().length > 0) {
|
|
459
|
+
turnkeyScrubber.register(input.githubToken.trim());
|
|
460
|
+
}
|
|
461
|
+
if (typeof input.githubAppPrivateKey === 'string' && input.githubAppPrivateKey.trim().length > 0) {
|
|
462
|
+
turnkeyScrubber.register(input.githubAppPrivateKey.trim());
|
|
463
|
+
}
|
|
464
|
+
let suiteGithubToken;
|
|
465
|
+
try {
|
|
466
|
+
suiteGithubToken = await resolveGitHubToken({
|
|
467
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
468
|
+
repositoryFullName: input.repositoryFullName,
|
|
469
|
+
githubToken: input.githubToken,
|
|
470
|
+
appId: input.githubAppId,
|
|
471
|
+
appPrivateKey: input.githubAppPrivateKey,
|
|
472
|
+
appInstallationId: input.githubAppInstallationId,
|
|
473
|
+
fetchImpl: input.probeFetch,
|
|
474
|
+
scrubber: turnkeyScrubber,
|
|
475
|
+
env: runtimeEnv,
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
catch (error) {
|
|
479
|
+
if (error instanceof GitHubAppError) {
|
|
480
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
481
|
+
}
|
|
482
|
+
throw error;
|
|
483
|
+
}
|
|
484
|
+
if (input.eventName === 'issue_comment' || input.eventName === 'pull_request_review') {
|
|
485
|
+
const prLookup = await verifySuiteCommentPullRequest({
|
|
486
|
+
suite: loadedSuite,
|
|
487
|
+
eventName: input.eventName,
|
|
488
|
+
eventPayload: input.eventPayload,
|
|
489
|
+
repositoryFullName: input.repositoryFullName,
|
|
490
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
491
|
+
explicitDomain: effectiveDomain,
|
|
492
|
+
resolveToken: () => suiteGithubToken,
|
|
493
|
+
commentPrefixes: input.commentPrefixes,
|
|
494
|
+
operatorAllowlist: input.operatorAllowlist,
|
|
495
|
+
fetchImpl: input.probeFetch,
|
|
496
|
+
scrubber: turnkeyScrubber,
|
|
497
|
+
});
|
|
498
|
+
if (prLookup.kind === 'verified') {
|
|
499
|
+
verifiedSuiteCommentMeta = prLookup.value;
|
|
500
|
+
}
|
|
501
|
+
else if (prLookup.kind !== 'ignored') {
|
|
502
|
+
try {
|
|
503
|
+
await writeSuiteMatrixGithubOutput(effectiveGithubOutputPath, { include: Object.freeze([]) }, turnkeyScrubber);
|
|
504
|
+
}
|
|
505
|
+
catch (outErr) {
|
|
506
|
+
if (outErr instanceof GitHubAppError) {
|
|
507
|
+
return blocked(outErr.code, turnkeyScrubber.scrub(outErr.message));
|
|
508
|
+
}
|
|
509
|
+
throw outErr;
|
|
510
|
+
}
|
|
511
|
+
const blockedReason = (prLookup.kind === 'lookup_failed' || prLookup.kind === 'metadata_unavailable')
|
|
512
|
+
? prLookup.reason
|
|
513
|
+
: prLookup.code;
|
|
514
|
+
return blocked(blockedReason, turnkeyScrubber.scrub(prLookup.detail));
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
const allowOfflineStagePrCheck = input.dryRun === true
|
|
518
|
+
&& !resolveSuiteOnly
|
|
519
|
+
&& effectiveApiBaseUrl === undefined
|
|
520
|
+
&& input.probeFetch === undefined
|
|
521
|
+
&& suiteGithubToken === undefined;
|
|
522
|
+
const resolvedSuiteBaseRevision = verifiedSuiteCommentMeta?.prBaseSha ?? input.baseRevision;
|
|
523
|
+
suiteResolution = await resolveTaskpackSuite({
|
|
524
|
+
repositoryRoot: input.repositoryRoot,
|
|
525
|
+
loadedSuite,
|
|
526
|
+
suitePath: effectiveSuitePath,
|
|
527
|
+
policyProfile: 'github',
|
|
528
|
+
hostPolicy,
|
|
529
|
+
allowLoopbackHttp: input.allowManifestCustomBaseUrl === true,
|
|
530
|
+
baseRevision: resolvedSuiteBaseRevision,
|
|
531
|
+
eventName: input.eventName,
|
|
532
|
+
eventPayload: input.eventPayload,
|
|
533
|
+
schedule: input.schedule,
|
|
534
|
+
domain: effectiveDomain,
|
|
535
|
+
...(input.commentPrefixes !== undefined ? { commentPrefixes: input.commentPrefixes } : {}),
|
|
536
|
+
...(verifiedSuiteCommentMeta !== undefined
|
|
537
|
+
? {
|
|
538
|
+
prHeadRef: verifiedSuiteCommentMeta.prHeadRef,
|
|
539
|
+
prBaseRef: verifiedSuiteCommentMeta.prBaseRef,
|
|
540
|
+
prHeadSha: verifiedSuiteCommentMeta.prHeadSha,
|
|
541
|
+
prHeadRepoFullName: input.repositoryFullName,
|
|
542
|
+
prHeadRepoFork: false,
|
|
543
|
+
}
|
|
544
|
+
: {}),
|
|
545
|
+
operatorAllowlist: input.operatorAllowlist,
|
|
546
|
+
repositoryFullName: input.repositoryFullName,
|
|
547
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
548
|
+
githubToken: suiteGithubToken,
|
|
549
|
+
fetchImpl: input.probeFetch,
|
|
550
|
+
scrubber: turnkeyScrubber,
|
|
551
|
+
env: runtimeEnv,
|
|
552
|
+
discoverUpstreamUpdates: !allowOfflineStagePrCheck,
|
|
553
|
+
allowOfflineStagePrCheck,
|
|
554
|
+
});
|
|
555
|
+
const scrubPublicSuiteResolution = (res) => {
|
|
556
|
+
if (res.comment === undefined && res.detail === undefined)
|
|
557
|
+
return res;
|
|
558
|
+
return Object.freeze({
|
|
559
|
+
...res,
|
|
560
|
+
...(res.detail !== undefined ? { detail: turnkeyScrubber.scrub(res.detail) } : {}),
|
|
561
|
+
...(res.comment !== undefined
|
|
562
|
+
? {
|
|
563
|
+
comment: Object.freeze({
|
|
564
|
+
...res.comment,
|
|
565
|
+
guidance: turnkeyScrubber.scrub(res.comment.guidance),
|
|
566
|
+
}),
|
|
567
|
+
}
|
|
568
|
+
: {}),
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
if (input.commentPrefixes !== undefined
|
|
572
|
+
&& suiteResolution.comment !== undefined
|
|
573
|
+
&& !input.commentPrefixes.includes(suiteResolution.comment.prefix)) {
|
|
574
|
+
const emptyMatrix = Object.freeze({ include: Object.freeze([]) });
|
|
575
|
+
try {
|
|
576
|
+
await writeSuiteMatrixGithubOutput(effectiveGithubOutputPath, emptyMatrix, turnkeyScrubber);
|
|
577
|
+
}
|
|
578
|
+
catch (outErr) {
|
|
579
|
+
if (outErr instanceof GitHubAppError) {
|
|
580
|
+
return blocked(outErr.code, turnkeyScrubber.scrub(outErr.message));
|
|
581
|
+
}
|
|
582
|
+
throw outErr;
|
|
583
|
+
}
|
|
584
|
+
const ignoredSuite = scrubPublicSuiteResolution(Object.freeze({
|
|
585
|
+
...suiteResolution,
|
|
586
|
+
disposition: 'ignored',
|
|
587
|
+
reason: 'comment_prefix_not_configured_for_domain',
|
|
588
|
+
cells: Object.freeze([]),
|
|
589
|
+
eligibleCells: Object.freeze([]),
|
|
590
|
+
matrix: emptyMatrix,
|
|
591
|
+
}));
|
|
592
|
+
return {
|
|
593
|
+
kind: 'ignored',
|
|
594
|
+
disposition: 'ignored',
|
|
595
|
+
reason: ignoredSuite.reason,
|
|
596
|
+
suite: ignoredSuite,
|
|
597
|
+
matrix: emptyMatrix,
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
try {
|
|
601
|
+
await writeSuiteMatrixGithubOutput(effectiveGithubOutputPath, suiteResolution.matrix, turnkeyScrubber);
|
|
602
|
+
}
|
|
603
|
+
catch (outErr) {
|
|
604
|
+
if (outErr instanceof GitHubAppError) {
|
|
605
|
+
return blocked(outErr.code, turnkeyScrubber.scrub(outErr.message));
|
|
606
|
+
}
|
|
607
|
+
throw outErr;
|
|
608
|
+
}
|
|
609
|
+
if (suiteResolution.disposition === 'blocked') {
|
|
610
|
+
return blocked(suiteResolution.code ?? suiteResolution.reason, suiteResolution.detail !== undefined
|
|
611
|
+
? turnkeyScrubber.scrub(suiteResolution.detail)
|
|
612
|
+
: turnkeyScrubber.scrub(suiteResolution.reason));
|
|
613
|
+
}
|
|
614
|
+
if (resolveSuiteOnly
|
|
615
|
+
|| suiteResolution.disposition === 'deferred'
|
|
616
|
+
|| suiteResolution.disposition === 'ignored') {
|
|
617
|
+
const scrubbedSuite = scrubPublicSuiteResolution(suiteResolution);
|
|
618
|
+
return {
|
|
619
|
+
kind: suiteResolution.disposition,
|
|
620
|
+
disposition: suiteResolution.disposition,
|
|
621
|
+
reason: scrubbedSuite.reason,
|
|
622
|
+
...(scrubbedSuite.detail !== undefined ? { detail: scrubbedSuite.detail } : {}),
|
|
623
|
+
suite: scrubbedSuite,
|
|
624
|
+
matrix: scrubbedSuite.matrix,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
const selectedCell = effectiveDomain !== undefined
|
|
628
|
+
? suiteResolution.eligibleCells.find(c => c.domainId === effectiveDomain)
|
|
629
|
+
: (suiteResolution.eligibleCells.length === 1 ? suiteResolution.eligibleCells[0] : undefined);
|
|
630
|
+
if (selectedCell === undefined) {
|
|
631
|
+
return blocked('ACTION_INPUT_INVALID', `suite "${loadedSuite.manifest.metadata.name}" resolved ${suiteResolution.eligibleCells.length} eligible domains (${suiteResolution.eligibleCells.map(c => c.domainId).join(', ')}); pass domain or resolve-suite-only: true`);
|
|
632
|
+
}
|
|
633
|
+
const selectedDomain = loadedSuite.domains.find(d => d.id === selectedCell.domainId);
|
|
634
|
+
if (selectedDomain === undefined) {
|
|
635
|
+
return blocked('TASKPACK_MANIFEST_INVALID', `resolved suite domain "${selectedCell.domainId}" is missing`);
|
|
636
|
+
}
|
|
637
|
+
effectiveTaskpackPath = selectedDomain.taskpackPath;
|
|
638
|
+
effectiveBaseRevision = selectedCell.baseRevision;
|
|
639
|
+
suiteExtraProtectedPaths = selectedDomain.protectedPaths;
|
|
640
|
+
if (effectiveTargetMatrix === undefined && Array.isArray(selectedDomain.matrix)) {
|
|
641
|
+
effectiveTargetMatrix = selectedDomain.matrix;
|
|
642
|
+
}
|
|
643
|
+
if (verifiedSuiteCommentMeta !== undefined && isPlainRecord(input.eventPayload)) {
|
|
644
|
+
const existingPr = isPlainRecord(input.eventPayload['pull_request']) ? input.eventPayload['pull_request'] : {};
|
|
645
|
+
effectiveEventPayload = {
|
|
646
|
+
...input.eventPayload,
|
|
647
|
+
pull_request: {
|
|
648
|
+
...existingPr,
|
|
649
|
+
...(verifiedSuiteCommentMeta.prNumber !== undefined ? { number: verifiedSuiteCommentMeta.prNumber } : {}),
|
|
650
|
+
head: {
|
|
651
|
+
ref: verifiedSuiteCommentMeta.prHeadRef,
|
|
652
|
+
sha: verifiedSuiteCommentMeta.prHeadSha,
|
|
653
|
+
repo: { full_name: input.repositoryFullName, fork: false },
|
|
654
|
+
},
|
|
655
|
+
base: {
|
|
656
|
+
ref: verifiedSuiteCommentMeta.prBaseRef,
|
|
657
|
+
...(verifiedSuiteCommentMeta.prBaseSha !== undefined ? { sha: verifiedSuiteCommentMeta.prBaseSha } : {}),
|
|
658
|
+
repo: { full_name: input.repositoryFullName, fork: false },
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
let manifest;
|
|
665
|
+
if (loadedSuite !== undefined && effectiveTaskpackPath !== undefined) {
|
|
666
|
+
const boundDomain = loadedSuite.domains.find(d => d.taskpackPath === effectiveTaskpackPath);
|
|
667
|
+
if (boundDomain === undefined) {
|
|
668
|
+
return blocked('TASKPACK_MANIFEST_INVALID', `suite domain at "${effectiveTaskpackPath}" was not found`);
|
|
669
|
+
}
|
|
670
|
+
manifest = boundDomain.manifest;
|
|
671
|
+
}
|
|
672
|
+
else {
|
|
673
|
+
const manifestPath = join(input.repositoryRoot, effectiveTaskpackPath ?? '.loopwright/taskpack.yaml');
|
|
674
|
+
try {
|
|
675
|
+
manifest = await loadDeclarativeTaskpack({
|
|
676
|
+
manifestPath,
|
|
677
|
+
repositoryRoot: input.repositoryRoot,
|
|
678
|
+
policyProfile: 'github',
|
|
679
|
+
hostPolicy,
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
catch (error) {
|
|
683
|
+
if (error instanceof GitHubAppError) {
|
|
684
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED'
|
|
685
|
+
|| error.code === 'MCP_OAUTH_UNSUPPORTED'
|
|
686
|
+
|| error.code === 'TASKPACK_HOST_BINDING_INVALID'
|
|
687
|
+
|| (error.code === 'TASKPACK_SCOPE_VIOLATION' && error.path?.startsWith('/spec/execution') === true)) {
|
|
688
|
+
return { kind: 'refused', code: error.code, reason: error.message };
|
|
689
|
+
}
|
|
690
|
+
return blocked('target repository manifest failed validation', 'loadDeclarativeTaskpack refused the manifest');
|
|
691
|
+
}
|
|
692
|
+
throw error;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
let effectiveMcpDecls;
|
|
696
|
+
try {
|
|
697
|
+
const overrideMcpDecls = input.mcpServerConfigs ?? parseMcpServersOverride(input.mcpServersJson ?? runtimeEnv['INPUT_MCP-SERVERS'] ?? runtimeEnv['LOOPWRIGHT_MCP_SERVERS'], input.allowManifestCustomBaseUrl === true);
|
|
698
|
+
effectiveMcpDecls = mergeMcpServerDeclarations(manifest.spec.mcp?.servers, overrideMcpDecls);
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
if (error instanceof GitHubAppError) {
|
|
702
|
+
if (error.code === 'MCP_OAUTH_UNSUPPORTED') {
|
|
703
|
+
return { kind: 'refused', code: 'MCP_OAUTH_UNSUPPORTED', reason: error.message };
|
|
704
|
+
}
|
|
705
|
+
return blocked(error.code, error.message);
|
|
706
|
+
}
|
|
707
|
+
throw error;
|
|
708
|
+
}
|
|
709
|
+
resolveActionOutputFormats(input.output, manifest);
|
|
710
|
+
let effectiveBaselineOverride;
|
|
711
|
+
let effectiveBaselineConfig;
|
|
712
|
+
try {
|
|
713
|
+
const rawAlignEnv = runtimeEnv['INPUT_BASELINE-ALIGNMENT']?.trim();
|
|
714
|
+
effectiveBaselineOverride = input.baselineAlignment
|
|
715
|
+
?? (rawAlignEnv !== undefined && rawAlignEnv.length > 0
|
|
716
|
+
? parseBaselineAlignmentPolicy(rawAlignEnv)
|
|
717
|
+
: undefined);
|
|
718
|
+
effectiveBaselineConfig = resolveBaselineAlignmentConfig(manifest.spec.baselineAlignment, effectiveBaselineOverride);
|
|
719
|
+
}
|
|
720
|
+
catch (error) {
|
|
721
|
+
if (error instanceof GitHubAppError) {
|
|
722
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
723
|
+
}
|
|
724
|
+
throw error;
|
|
725
|
+
}
|
|
726
|
+
// Register known host secrets onto turnkeyScrubber BEFORE any preflight script or external call runs.
|
|
727
|
+
const manifestSecretEnvs = collectManifestSecretEnvNames(manifest);
|
|
728
|
+
for (const secretEnvKey of [
|
|
729
|
+
'GITHUB_TOKEN',
|
|
730
|
+
'GH_TOKEN',
|
|
731
|
+
'INPUT_GITHUB-TOKEN',
|
|
732
|
+
'INPUT_GITHUB-APP-PRIVATE-KEY',
|
|
733
|
+
input.providerTokenEnv,
|
|
734
|
+
input.credentialEnvMap?.provider,
|
|
735
|
+
input.credentialEnvMap?.gate ?? 'LOOPWRIGHT_GATE_SIGNING_SECRET',
|
|
736
|
+
input.credentialEnvMap?.publication ?? 'LOOPWRIGHT_PUBLICATION_SIGNING_SECRET',
|
|
737
|
+
input.credentialEnvMap?.publicationAuth ?? 'LOOPWRIGHT_PUBLICATION_AUTH_TOKEN',
|
|
738
|
+
input.credentialEnvMap?.localCommandGate ?? DEFAULT_LOCAL_COMMAND_GATE_ENV,
|
|
739
|
+
...Object.values(STANDARD_PI_PROVIDER_ENV),
|
|
740
|
+
...decisionApiKeyEnvs,
|
|
741
|
+
...manifestSecretEnvs,
|
|
742
|
+
...collectMcpReferencedEnvNames(effectiveMcpDecls),
|
|
743
|
+
]) {
|
|
744
|
+
if (typeof secretEnvKey === 'string' && secretEnvKey.length > 0) {
|
|
745
|
+
const val = runtimeEnv[secretEnvKey];
|
|
746
|
+
if (typeof val === 'string' && val.trim().length > 0) {
|
|
747
|
+
turnkeyScrubber.register(val.trim());
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
if (typeof input.decisionApiKey === 'string' && input.decisionApiKey.trim().length > 0) {
|
|
752
|
+
turnkeyScrubber.register(input.decisionApiKey.trim());
|
|
753
|
+
}
|
|
754
|
+
if (typeof input.githubToken === 'string' && input.githubToken.trim().length > 0) {
|
|
755
|
+
turnkeyScrubber.register(input.githubToken.trim());
|
|
756
|
+
}
|
|
757
|
+
if (typeof input.githubAppPrivateKey === 'string' && input.githubAppPrivateKey.trim().length > 0) {
|
|
758
|
+
turnkeyScrubber.register(input.githubAppPrivateKey.trim());
|
|
759
|
+
}
|
|
760
|
+
// Enforce manifest spec.triggers eligibility and comment/review actor authorization STRICTLY BEFORE running spec.preflight!
|
|
761
|
+
let preEvaluatedComment;
|
|
762
|
+
if (!eventNameIsTrigger(input.eventName) && input.eventName !== 'issue_comment' && input.eventName !== 'pull_request_review') {
|
|
763
|
+
if (!hasAnyDeclaredGitHubTrigger(manifest.spec.triggers)) {
|
|
764
|
+
return {
|
|
765
|
+
kind: 'refused',
|
|
766
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
767
|
+
reason: `GitHub event "${input.eventName}" is not enabled in spec.triggers`,
|
|
768
|
+
};
|
|
769
|
+
}
|
|
770
|
+
return blocked(`unsupported event ${input.eventName}`);
|
|
771
|
+
}
|
|
772
|
+
if (eventNameIsTrigger(input.eventName)) {
|
|
773
|
+
if (!isGitHubTriggerDeclared(manifest.spec.triggers, input.eventName)) {
|
|
774
|
+
return {
|
|
775
|
+
kind: 'refused',
|
|
776
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
777
|
+
reason: `GitHub event "${input.eventName}" is not enabled in spec.triggers`,
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
if (input.eventName === 'release') {
|
|
781
|
+
const releaseAction = isPlainRecord(input.eventPayload) && typeof input.eventPayload['action'] === 'string'
|
|
782
|
+
? input.eventPayload['action']
|
|
783
|
+
: undefined;
|
|
784
|
+
if (releaseAction !== 'published') {
|
|
785
|
+
return {
|
|
786
|
+
kind: 'refused',
|
|
787
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
788
|
+
reason: releaseAction === undefined
|
|
789
|
+
? 'release event payload is missing required action "published"'
|
|
790
|
+
: `release action "${releaseAction}" is not enabled in spec.triggers`,
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
if (input.eventName === 'issue_comment' || input.eventName === 'pull_request_review') {
|
|
796
|
+
if (!isGitHubTriggerDeclared(manifest.spec.triggers, input.eventName)) {
|
|
797
|
+
return {
|
|
798
|
+
kind: 'refused',
|
|
799
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
800
|
+
reason: `GitHub event "${input.eventName}" is not enabled in spec.triggers.commentCommands`,
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
if (suiteResolution?.comment !== undefined && verifiedSuiteCommentMeta !== undefined) {
|
|
804
|
+
if (!isGitHubTriggerDeclared(manifest.spec.triggers, {
|
|
805
|
+
eventName: input.eventName,
|
|
806
|
+
commentCommand: suiteResolution.comment.command,
|
|
807
|
+
})) {
|
|
808
|
+
return {
|
|
809
|
+
kind: 'refused',
|
|
810
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
811
|
+
reason: `comment command "${suiteResolution.comment.command}" is not enabled in spec.triggers.commentCommands`,
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
preEvaluatedComment = {
|
|
815
|
+
command: suiteResolution.comment.command,
|
|
816
|
+
guidance: suiteResolution.comment.guidance,
|
|
817
|
+
login: verifiedSuiteCommentMeta.login,
|
|
818
|
+
authorAssociation: verifiedSuiteCommentMeta.authorAssociation,
|
|
819
|
+
commandId: verifiedSuiteCommentMeta.commandId,
|
|
820
|
+
headSha: verifiedSuiteCommentMeta.prHeadSha,
|
|
821
|
+
};
|
|
822
|
+
}
|
|
823
|
+
else {
|
|
824
|
+
const effectivePrefixes = input.commentPrefixes ?? manifest.spec.triggers.commentPrefixes;
|
|
825
|
+
const preliminaryCmd = extractPreliminaryCommentCommand(input.eventPayload, input.eventName, effectivePrefixes);
|
|
826
|
+
if (preliminaryCmd !== null
|
|
827
|
+
&& !isGitHubTriggerDeclared(manifest.spec.triggers, {
|
|
828
|
+
eventName: input.eventName,
|
|
829
|
+
commentCommand: preliminaryCmd,
|
|
830
|
+
})) {
|
|
831
|
+
return {
|
|
832
|
+
kind: 'refused',
|
|
833
|
+
code: 'TASKPACK_TRIGGER_UNSUPPORTED',
|
|
834
|
+
reason: `comment command "${preliminaryCmd}" is not enabled in spec.triggers.commentCommands`,
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
preEvaluatedComment = evaluateCommentPayload(input.eventPayload, {
|
|
838
|
+
eventName: input.eventName,
|
|
839
|
+
commentPrefixes: effectivePrefixes,
|
|
840
|
+
commentCommands: manifest.spec.triggers.commentCommands,
|
|
841
|
+
operatorAllowlist: input.operatorAllowlist,
|
|
842
|
+
});
|
|
843
|
+
if ('ignoredReason' in preEvaluatedComment) {
|
|
844
|
+
return blocked(`comment ignored: ${preEvaluatedComment.ignoredReason}`);
|
|
845
|
+
}
|
|
846
|
+
if ('blockedReason' in preEvaluatedComment) {
|
|
847
|
+
return blocked(preEvaluatedComment.blockedReason, preEvaluatedComment.detail);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
const turnkeyEnabled = input.turnkey === true && input.dryRun !== true;
|
|
852
|
+
let effectiveRepositoryId = input.repositoryId ?? 0;
|
|
853
|
+
let effectiveInstallationId = input.installationId ?? 0;
|
|
854
|
+
const explicitSourceRevision = (input.sourceRevision ?? runtimeEnv['INPUT_SOURCE-REVISION'])?.trim() || undefined;
|
|
855
|
+
let effectiveSourceRevision = explicitSourceRevision
|
|
856
|
+
?? verifiedSuiteCommentMeta?.prHeadSha
|
|
857
|
+
?? effectiveBaseRevision;
|
|
858
|
+
let effectiveUpstreamRecords = input.upstreamRecords;
|
|
859
|
+
let githubToken;
|
|
860
|
+
let gitCommitIdentity = Object.freeze({
|
|
861
|
+
name: explicitGitAuthorName ?? DEFAULT_GIT_COMMIT_IDENTITY.name,
|
|
862
|
+
email: explicitGitAuthorEmail ?? DEFAULT_GIT_COMMIT_IDENTITY.email,
|
|
863
|
+
});
|
|
864
|
+
let openManagedPr = null;
|
|
865
|
+
let managedPrMatchesDiscoveredState = input.managedPrMatchesDiscoveredState;
|
|
866
|
+
let preflightResult;
|
|
867
|
+
try {
|
|
868
|
+
let hostGateCredentialEnvs;
|
|
869
|
+
try {
|
|
870
|
+
hostGateCredentialEnvs = collectHostCredentialEnvNames({
|
|
871
|
+
credentialEnvMap: input.credentialEnvMap !== undefined || input.providerTokenEnv !== undefined
|
|
872
|
+
? {
|
|
873
|
+
...(input.credentialEnvMap ?? {}),
|
|
874
|
+
...(input.credentialEnvMap?.provider === undefined && input.providerTokenEnv !== undefined
|
|
875
|
+
? { provider: input.providerTokenEnv }
|
|
876
|
+
: {}),
|
|
877
|
+
}
|
|
878
|
+
: undefined,
|
|
879
|
+
gateEndpoints: input.gateEndpoints,
|
|
880
|
+
});
|
|
881
|
+
if (input.providerTokenEnv !== undefined && !/^[A-Z][A-Z0-9_]{0,63}$/.test(input.providerTokenEnv)) {
|
|
882
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', 'providerTokenEnv credential environment name must match [A-Z][A-Z0-9_]{0,63}');
|
|
883
|
+
}
|
|
884
|
+
const benchmarkEndpointIds = new Set();
|
|
885
|
+
for (const declaredGate of manifest.spec.verification.externalGates) {
|
|
886
|
+
if (declaredGate.implementation === 'benchmark-gate.v1') {
|
|
887
|
+
benchmarkEndpointIds.add(declaredGate.endpointId);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
for (const plan of input.gateEndpoints ?? []) {
|
|
891
|
+
if (plan.implementation === 'benchmark-gate.v1') {
|
|
892
|
+
benchmarkEndpointIds.add(plan.id);
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
const byCredRef = input.credentialEnvMap?.byCredentialRef;
|
|
896
|
+
const lookupByCredRef = (ref) => (byCredRef !== undefined && Object.hasOwn(byCredRef, ref) ? byCredRef[ref] : undefined);
|
|
897
|
+
for (const plan of input.gateEndpoints ?? []) {
|
|
898
|
+
if (!benchmarkEndpointIds.has(plan.id))
|
|
899
|
+
continue;
|
|
900
|
+
const signingEnv = lookupByCredRef(plan.signingCredentialRef) ?? input.credentialEnvMap?.gate;
|
|
901
|
+
if (signingEnv === 'GITHUB_TOKEN' || signingEnv === 'GH_TOKEN') {
|
|
902
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', `benchmark-gate.v1 host binding "${plan.id}" cannot reuse GitHub token env "${signingEnv}"`);
|
|
903
|
+
}
|
|
904
|
+
if (plan.authCredentialRef != null) {
|
|
905
|
+
const authEnv = lookupByCredRef(plan.authCredentialRef) ?? input.credentialEnvMap?.gateAuth;
|
|
906
|
+
if (authEnv === 'GITHUB_TOKEN' || authEnv === 'GH_TOKEN') {
|
|
907
|
+
throw new GitHubAppError('TASKPACK_HOST_BINDING_INVALID', `benchmark-gate.v1 host binding "${plan.id}" cannot reuse GitHub token env "${authEnv}"`);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
catch (error) {
|
|
913
|
+
if (error instanceof GitHubAppError) {
|
|
914
|
+
if (error.code === 'TASKPACK_HOST_BINDING_INVALID') {
|
|
915
|
+
return { kind: 'refused', code: 'TASKPACK_HOST_BINDING_INVALID', reason: turnkeyScrubber.scrub(error.message) };
|
|
916
|
+
}
|
|
917
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
918
|
+
}
|
|
919
|
+
throw error;
|
|
920
|
+
}
|
|
921
|
+
for (const envName of hostGateCredentialEnvs) {
|
|
922
|
+
const val = runtimeEnv[envName];
|
|
923
|
+
if (typeof val === 'string' && val.trim().length > 0) {
|
|
924
|
+
turnkeyScrubber.register(val.trim());
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
if (turnkeyEnabled) {
|
|
928
|
+
try {
|
|
929
|
+
const effectivePolicy = resolveEffectiveTaskpackSandboxPolicy(manifest, {
|
|
930
|
+
workspaceRoot: input.repositoryRoot,
|
|
931
|
+
relativeTaskpackPath: effectiveTaskpackPath,
|
|
932
|
+
env: runtimeEnv,
|
|
933
|
+
policyProfile: 'github',
|
|
934
|
+
hostPolicy,
|
|
935
|
+
});
|
|
936
|
+
const negotiated = negotiateSandboxBackend(effectivePolicy, {
|
|
937
|
+
platform: process.platform,
|
|
938
|
+
arch: process.arch,
|
|
939
|
+
});
|
|
940
|
+
if (input.delegate === undefined && negotiated.backendId === 'docker') {
|
|
941
|
+
return blocked('SANDBOX_POLICY_INVALID', 'turnkey host-session mode runs without Docker; docker sandbox backend cannot be used when delegate is unset');
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
catch (error) {
|
|
945
|
+
if (error instanceof GitHubAppError) {
|
|
946
|
+
return blocked(error.code, error.message);
|
|
947
|
+
}
|
|
948
|
+
throw error;
|
|
949
|
+
}
|
|
950
|
+
try {
|
|
951
|
+
const resolvedAuth = await resolveGitHubAuth({
|
|
952
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
953
|
+
repositoryFullName: input.repositoryFullName,
|
|
954
|
+
repositoryId: effectiveRepositoryId > 0 ? effectiveRepositoryId : undefined,
|
|
955
|
+
githubToken: input.githubToken,
|
|
956
|
+
appId: input.githubAppId,
|
|
957
|
+
appPrivateKey: input.githubAppPrivateKey,
|
|
958
|
+
appInstallationId: input.githubAppInstallationId,
|
|
959
|
+
gitAuthorName: explicitGitAuthorName,
|
|
960
|
+
gitAuthorEmail: explicitGitAuthorEmail,
|
|
961
|
+
fetchImpl: input.probeFetch,
|
|
962
|
+
scrubber: turnkeyScrubber,
|
|
963
|
+
env: runtimeEnv,
|
|
964
|
+
});
|
|
965
|
+
githubToken = resolvedAuth.token;
|
|
966
|
+
gitCommitIdentity = resolvedAuth.gitCommitIdentity;
|
|
967
|
+
if (effectiveInstallationId <= 0 && resolvedAuth.installationId !== undefined) {
|
|
968
|
+
effectiveInstallationId = resolvedAuth.installationId;
|
|
969
|
+
}
|
|
970
|
+
const commentCommand = preEvaluatedComment !== undefined
|
|
971
|
+
&& !('ignoredReason' in preEvaluatedComment)
|
|
972
|
+
&& !('blockedReason' in preEvaluatedComment)
|
|
973
|
+
? preEvaluatedComment.command
|
|
974
|
+
: undefined;
|
|
975
|
+
const preserveExplicitSourceRevision = shouldPreserveExplicitSourceRevision({
|
|
976
|
+
eventName: input.eventName,
|
|
977
|
+
explicitSourceRevision,
|
|
978
|
+
commentCommand,
|
|
979
|
+
});
|
|
980
|
+
const resolvedRepo = await resolveRepositoryAndRevisions({
|
|
981
|
+
repositoryRoot: input.repositoryRoot,
|
|
982
|
+
repositoryFullName: input.repositoryFullName,
|
|
983
|
+
baseRevision: effectiveBaseRevision,
|
|
984
|
+
sourceRevision: explicitSourceRevision,
|
|
985
|
+
preserveExplicitSourceRevision,
|
|
986
|
+
eventName: input.eventName,
|
|
987
|
+
eventPayload: effectiveEventPayload,
|
|
988
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
989
|
+
githubToken,
|
|
990
|
+
fetchImpl: input.probeFetch,
|
|
991
|
+
scrubber: turnkeyScrubber,
|
|
992
|
+
env: runtimeEnv,
|
|
993
|
+
});
|
|
994
|
+
effectiveRepositoryId = input.repositoryId !== undefined && input.repositoryId > 0
|
|
995
|
+
? input.repositoryId
|
|
996
|
+
: resolvedRepo.repositoryId;
|
|
997
|
+
effectiveBaseRevision = resolvedRepo.baseRevision;
|
|
998
|
+
effectiveSourceRevision = resolvedRepo.sourceRevision;
|
|
999
|
+
}
|
|
1000
|
+
catch (error) {
|
|
1001
|
+
if (error instanceof GitHubAppError) {
|
|
1002
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
1003
|
+
}
|
|
1004
|
+
throw error;
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
else if ((explicitSourceRevision !== undefined || verifiedSuiteCommentMeta !== undefined)
|
|
1008
|
+
&& existsSync(join(input.repositoryRoot, '.git'))) {
|
|
1009
|
+
try {
|
|
1010
|
+
effectiveBaseRevision = await resolveGitCommitSha(input.repositoryRoot, effectiveBaseRevision);
|
|
1011
|
+
if (explicitSourceRevision !== undefined) {
|
|
1012
|
+
effectiveSourceRevision = explicitSourceRevision === input.baseRevision
|
|
1013
|
+
? effectiveBaseRevision
|
|
1014
|
+
: await resolveGitCommitSha(input.repositoryRoot, explicitSourceRevision);
|
|
1015
|
+
}
|
|
1016
|
+
else if (verifiedSuiteCommentMeta !== undefined) {
|
|
1017
|
+
effectiveSourceRevision = verifiedSuiteCommentMeta.prHeadSha;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
catch (error) {
|
|
1021
|
+
if (error instanceof GitHubAppError) {
|
|
1022
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
1023
|
+
}
|
|
1024
|
+
throw error;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
else if (verifiedSuiteCommentMeta !== undefined && effectiveSourceRevision === undefined) {
|
|
1028
|
+
effectiveSourceRevision = verifiedSuiteCommentMeta.prHeadSha;
|
|
1029
|
+
}
|
|
1030
|
+
const isStatusComment = preEvaluatedComment !== undefined
|
|
1031
|
+
&& !('ignoredReason' in preEvaluatedComment)
|
|
1032
|
+
&& !('blockedReason' in preEvaluatedComment)
|
|
1033
|
+
&& preEvaluatedComment.command === 'status';
|
|
1034
|
+
if (verifiedSuiteCommentMeta !== undefined && !isStatusComment) {
|
|
1035
|
+
if (verifiedSuiteCommentMeta.prBaseSha === undefined) {
|
|
1036
|
+
return blocked('ACTION_INPUT_INVALID', 'pull_request_metadata_unavailable: pull request base.sha must be a verified 40-hex commit SHA');
|
|
1037
|
+
}
|
|
1038
|
+
if (effectiveBaseRevision.toLowerCase() !== verifiedSuiteCommentMeta.prBaseSha.toLowerCase()) {
|
|
1039
|
+
return blocked('ACTION_INPUT_INVALID', `resolved base revision "${effectiveBaseRevision}" disagrees with verified pull request base SHA "${verifiedSuiteCommentMeta.prBaseSha}"`);
|
|
1040
|
+
}
|
|
1041
|
+
const resolvedSourceForCheck = effectiveSourceRevision ?? effectiveBaseRevision;
|
|
1042
|
+
if (resolvedSourceForCheck.toLowerCase() !== verifiedSuiteCommentMeta.prHeadSha.toLowerCase()) {
|
|
1043
|
+
return blocked('ACTION_INPUT_INVALID', `resolved source revision "${resolvedSourceForCheck}" disagrees with verified pull request head SHA "${verifiedSuiteCommentMeta.prHeadSha}"`);
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
const willRunPreflight = manifest.spec.preflight !== undefined && !isStatusComment;
|
|
1047
|
+
let modelsConfig;
|
|
1048
|
+
if (willRunPreflight && input.modelsJsonPath !== undefined) {
|
|
1049
|
+
try {
|
|
1050
|
+
modelsConfig = await loadPiModelsJson(input.modelsJsonPath);
|
|
1051
|
+
}
|
|
1052
|
+
catch (error) {
|
|
1053
|
+
if (error instanceof GitHubAppError) {
|
|
1054
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
1055
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
1056
|
+
}
|
|
1057
|
+
return blocked(error.code, error.message);
|
|
1058
|
+
}
|
|
1059
|
+
throw error;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
const registerEnvSecrets = (names) => {
|
|
1063
|
+
for (const envName of names) {
|
|
1064
|
+
const val = runtimeEnv[envName];
|
|
1065
|
+
if (typeof val === 'string' && val.trim().length > 0) {
|
|
1066
|
+
turnkeyScrubber.register(val.trim());
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
};
|
|
1070
|
+
const collectModelsJsonApiKeyEnvs = (cfg) => {
|
|
1071
|
+
if (cfg === undefined)
|
|
1072
|
+
return;
|
|
1073
|
+
for (const providerCfg of cfg.providers.values()) {
|
|
1074
|
+
if (typeof providerCfg.apiKeyEnv === 'string' && providerCfg.apiKeyEnv.length > 0 && !modelsJsonApiKeyEnvs.includes(providerCfg.apiKeyEnv)) {
|
|
1075
|
+
modelsJsonApiKeyEnvs.push(providerCfg.apiKeyEnv);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
};
|
|
1079
|
+
const modelsJsonApiKeyEnvs = [];
|
|
1080
|
+
collectModelsJsonApiKeyEnvs(modelsConfig);
|
|
1081
|
+
const preflightExcludedEnvs = new Set([
|
|
1082
|
+
...hostGateCredentialEnvs,
|
|
1083
|
+
...(input.providerTokenEnv !== undefined && input.providerTokenEnv.length > 0 ? [input.providerTokenEnv] : []),
|
|
1084
|
+
...modelsJsonApiKeyEnvs,
|
|
1085
|
+
input.credentialEnvMap?.gate ?? 'LOOPWRIGHT_GATE_SIGNING_SECRET',
|
|
1086
|
+
input.credentialEnvMap?.gateAuth ?? 'LOOPWRIGHT_GATE_AUTH_TOKEN',
|
|
1087
|
+
input.credentialEnvMap?.localCommandGate ?? DEFAULT_LOCAL_COMMAND_GATE_ENV,
|
|
1088
|
+
input.credentialEnvMap?.publication ?? 'LOOPWRIGHT_PUBLICATION_SIGNING_SECRET',
|
|
1089
|
+
input.credentialEnvMap?.publicationAuth ?? 'LOOPWRIGHT_PUBLICATION_AUTH_TOKEN',
|
|
1090
|
+
]);
|
|
1091
|
+
registerEnvSecrets(preflightExcludedEnvs);
|
|
1092
|
+
if (manifest.spec.preflight !== undefined && !isStatusComment) {
|
|
1093
|
+
try {
|
|
1094
|
+
preflightResult = await runTaskpackPreflight({
|
|
1095
|
+
manifest,
|
|
1096
|
+
repositoryRoot: input.repositoryRoot,
|
|
1097
|
+
authorized: true,
|
|
1098
|
+
hostPolicy,
|
|
1099
|
+
scrubber: turnkeyScrubber,
|
|
1100
|
+
env: runtimeEnv,
|
|
1101
|
+
excludedEnvNames: preflightExcludedEnvs,
|
|
1102
|
+
tempRoot: input.runRoot,
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
catch (error) {
|
|
1106
|
+
if (error instanceof GitHubAppError) {
|
|
1107
|
+
if (error.code === 'TASKPACK_HOST_BINDING_INVALID'
|
|
1108
|
+
|| (error.code === 'TASKPACK_SCOPE_VIOLATION' && error.path?.startsWith('/spec/execution') === true)) {
|
|
1109
|
+
return { kind: 'refused', code: error.code, reason: turnkeyScrubber.scrub(error.message) };
|
|
1110
|
+
}
|
|
1111
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
1112
|
+
}
|
|
1113
|
+
throw error;
|
|
1114
|
+
}
|
|
1115
|
+
if (preflightResult.disposition === 'blocked') {
|
|
1116
|
+
return blocked('preflight blocked execution', preflightResult.reason ?? 'preflight returned disposition=blocked');
|
|
1117
|
+
}
|
|
1118
|
+
if (effectiveUpstreamRecords === undefined && preflightResult.upstreams.length > 0) {
|
|
1119
|
+
effectiveUpstreamRecords = preflightResult.upstreams;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
if (turnkeyEnabled) {
|
|
1123
|
+
if (effectiveUpstreamRecords === undefined
|
|
1124
|
+
&& (input.upstreamRecordsJson !== undefined || (manifest.spec.preflight === undefined && manifest.spec.upstreams.length > 0))) {
|
|
1125
|
+
try {
|
|
1126
|
+
const discovered = await discoverTaskpackUpstreamsV2(manifest, {
|
|
1127
|
+
repositoryRoot: input.repositoryRoot,
|
|
1128
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
1129
|
+
githubToken,
|
|
1130
|
+
upstreamRecordsJson: input.upstreamRecordsJson,
|
|
1131
|
+
fetchImpl: input.probeFetch,
|
|
1132
|
+
scrubber: turnkeyScrubber,
|
|
1133
|
+
env: runtimeEnv,
|
|
1134
|
+
});
|
|
1135
|
+
effectiveUpstreamRecords = discovered.records;
|
|
1136
|
+
}
|
|
1137
|
+
catch (error) {
|
|
1138
|
+
if (error instanceof GitHubAppError) {
|
|
1139
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
1140
|
+
}
|
|
1141
|
+
throw error;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
if (manifest.spec.publication.mode === 'pull_request'
|
|
1145
|
+
&& input.publicationEndpoint === undefined
|
|
1146
|
+
&& (input.mode === 'candidate' || input.mode === 'auto')
|
|
1147
|
+
&& (effectiveApiBaseUrl !== undefined || githubToken !== undefined)) {
|
|
1148
|
+
try {
|
|
1149
|
+
openManagedPr = await findOpenManagedPullRequest({
|
|
1150
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
1151
|
+
repositoryFullName: input.repositoryFullName,
|
|
1152
|
+
targetBranch: manifest.spec.publication.targetBranch,
|
|
1153
|
+
headBranchPrefix: manifest.spec.publication.headBranchPrefix,
|
|
1154
|
+
githubToken,
|
|
1155
|
+
fetchImpl: input.probeFetch,
|
|
1156
|
+
scrubber: turnkeyScrubber,
|
|
1157
|
+
env: runtimeEnv,
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
catch (error) {
|
|
1161
|
+
if (error instanceof GitHubAppError) {
|
|
1162
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
1163
|
+
}
|
|
1164
|
+
throw error;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if (managedPrMatchesDiscoveredState === undefined
|
|
1168
|
+
&& openManagedPr !== null
|
|
1169
|
+
&& effectiveUpstreamRecords !== undefined
|
|
1170
|
+
&& effectiveUpstreamRecords.length > 0) {
|
|
1171
|
+
managedPrMatchesDiscoveredState = await checkManagedPrMatchesDiscoveredState({
|
|
1172
|
+
repositoryRoot: input.repositoryRoot,
|
|
1173
|
+
repositoryFullName: input.repositoryFullName,
|
|
1174
|
+
manifest,
|
|
1175
|
+
openManagedPr,
|
|
1176
|
+
records: effectiveUpstreamRecords,
|
|
1177
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
1178
|
+
githubToken,
|
|
1179
|
+
fetchImpl: input.probeFetch,
|
|
1180
|
+
scrubber: turnkeyScrubber,
|
|
1181
|
+
env: runtimeEnv,
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
else if (input.upstreamRecords === undefined && input.upstreamRecordsJson !== undefined) {
|
|
1186
|
+
try {
|
|
1187
|
+
const discovered = await discoverTaskpackUpstreamsV2(manifest, {
|
|
1188
|
+
repositoryRoot: input.repositoryRoot,
|
|
1189
|
+
upstreamRecordsJson: input.upstreamRecordsJson,
|
|
1190
|
+
scrubber: turnkeyScrubber,
|
|
1191
|
+
env: runtimeEnv,
|
|
1192
|
+
});
|
|
1193
|
+
effectiveUpstreamRecords = discovered.records;
|
|
1194
|
+
}
|
|
1195
|
+
catch (error) {
|
|
1196
|
+
if (error instanceof GitHubAppError) {
|
|
1197
|
+
return blocked(error.code, turnkeyScrubber.scrub(error.message));
|
|
1198
|
+
}
|
|
1199
|
+
throw error;
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
if (effectiveUpstreamRecords !== undefined && effectiveUpstreamRecords.length > 0) {
|
|
1203
|
+
emitProgress?.(`upstreams: ${effectiveUpstreamRecords.map(r => `${r.upstreamId}=${r.status}${r.version ? `(${r.version})` : ''}`).join(', ')}`);
|
|
1204
|
+
}
|
|
1205
|
+
const tenant = {
|
|
1206
|
+
installationId: effectiveInstallationId,
|
|
1207
|
+
repositoryId: effectiveRepositoryId,
|
|
1208
|
+
repositoryFullName: input.repositoryFullName,
|
|
1209
|
+
taskpackId: manifest.metadata.name,
|
|
1210
|
+
};
|
|
1211
|
+
let intake;
|
|
1212
|
+
let reviseGuidance;
|
|
1213
|
+
let autoCheckOnlyNoChangeReason = null;
|
|
1214
|
+
const forceDiscovery = (input.force ?? (runtimeEnv['INPUT_FORCE'] === 'true')) === true
|
|
1215
|
+
&& (input.mode === 'candidate' || input.mode === 'auto');
|
|
1216
|
+
const runDiscoverIntake = (allowForce, bypassManagedPrDedupe = false) => {
|
|
1217
|
+
if (!allowForce
|
|
1218
|
+
&& preflightResult !== undefined
|
|
1219
|
+
&& preflightResult.disposition === 'no_change') {
|
|
1220
|
+
const pfReason = preflightResult.reason ?? 'preflight reported no_change';
|
|
1221
|
+
emitProgress?.(`intake: no_change (${pfReason})`);
|
|
1222
|
+
if (input.mode === 'auto') {
|
|
1223
|
+
autoCheckOnlyNoChangeReason = pfReason;
|
|
1224
|
+
return {
|
|
1225
|
+
ok: true,
|
|
1226
|
+
intake: {
|
|
1227
|
+
kind: 'discover',
|
|
1228
|
+
disposition: 'no_change',
|
|
1229
|
+
updates: [],
|
|
1230
|
+
failures: [],
|
|
1231
|
+
reason: pfReason,
|
|
1232
|
+
summary: pfReason,
|
|
1233
|
+
targetMatrix: effectiveTargetMatrix ?? manifest.spec.target?.matrix ?? null,
|
|
1234
|
+
},
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
return { ok: false, exit: { kind: 'no_change', reason: pfReason } };
|
|
1238
|
+
}
|
|
1239
|
+
if (allowForce
|
|
1240
|
+
&& preflightResult !== undefined
|
|
1241
|
+
&& (effectiveUpstreamRecords === undefined || effectiveUpstreamRecords.length === 0)) {
|
|
1242
|
+
return {
|
|
1243
|
+
ok: true,
|
|
1244
|
+
intake: {
|
|
1245
|
+
kind: 'discover',
|
|
1246
|
+
disposition: 'ready',
|
|
1247
|
+
baseRevision: effectiveBaseRevision,
|
|
1248
|
+
updates: [],
|
|
1249
|
+
targetMatrix: effectiveTargetMatrix ?? manifest.spec.target?.matrix ?? null,
|
|
1250
|
+
},
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
if (preflightResult !== undefined
|
|
1254
|
+
&& preflightResult.disposition === 'candidate'
|
|
1255
|
+
&& (effectiveUpstreamRecords === undefined || effectiveUpstreamRecords.length === 0)) {
|
|
1256
|
+
return {
|
|
1257
|
+
ok: true,
|
|
1258
|
+
intake: {
|
|
1259
|
+
kind: 'discover',
|
|
1260
|
+
disposition: 'ready',
|
|
1261
|
+
baseRevision: effectiveBaseRevision,
|
|
1262
|
+
updates: [],
|
|
1263
|
+
targetMatrix: effectiveTargetMatrix ?? manifest.spec.target?.matrix ?? null,
|
|
1264
|
+
},
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
const outcome = prepareTaskpackIntake({
|
|
1268
|
+
mode: 'discover', tenant, baseRevision: effectiveBaseRevision,
|
|
1269
|
+
records: effectiveUpstreamRecords ?? [],
|
|
1270
|
+
...(allowForce ? { force: true } : {}),
|
|
1271
|
+
...(!bypassManagedPrDedupe && managedPrMatchesDiscoveredState !== undefined ? { managedPrMatchesDiscoveredState } : {}),
|
|
1272
|
+
targetMatrix: effectiveTargetMatrix ?? manifest.spec.target?.matrix ?? null,
|
|
1273
|
+
});
|
|
1274
|
+
if (outcome.kind === 'discover' && outcome.disposition === 'no_change') {
|
|
1275
|
+
emitProgress?.(`intake: no_change (${outcome.reason})`);
|
|
1276
|
+
if (input.mode === 'auto') {
|
|
1277
|
+
autoCheckOnlyNoChangeReason = outcome.reason;
|
|
1278
|
+
return { ok: true, intake: outcome };
|
|
1279
|
+
}
|
|
1280
|
+
return { ok: false, exit: { kind: 'no_change', reason: outcome.reason } };
|
|
1281
|
+
}
|
|
1282
|
+
if (outcome.kind === 'discover' && outcome.disposition === 'blocked') {
|
|
1283
|
+
return {
|
|
1284
|
+
ok: false,
|
|
1285
|
+
exit: blocked('upstream sources are unavailable', outcome.failures.map(failure => `${failure.upstreamId}: ${failure.error}`).join('; ')),
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
return { ok: true, intake: outcome };
|
|
1289
|
+
};
|
|
1290
|
+
if (eventNameIsTrigger(input.eventName)) {
|
|
1291
|
+
const discovered = runDiscoverIntake(forceDiscovery);
|
|
1292
|
+
if (!discovered.ok)
|
|
1293
|
+
return discovered.exit;
|
|
1294
|
+
intake = discovered.intake;
|
|
1295
|
+
}
|
|
1296
|
+
else if (input.eventName === 'issue_comment' || input.eventName === 'pull_request_review') {
|
|
1297
|
+
const evaluation = preEvaluatedComment;
|
|
1298
|
+
if ('ignoredReason' in evaluation)
|
|
1299
|
+
return blocked(`comment ignored: ${evaluation.ignoredReason}`);
|
|
1300
|
+
if ('blockedReason' in evaluation)
|
|
1301
|
+
return blocked(evaluation.blockedReason, evaluation.detail);
|
|
1302
|
+
const commandDigest = createHash('sha256').update(evaluation.guidance, 'utf8').digest('hex');
|
|
1303
|
+
if (evaluation.command === 'status') {
|
|
1304
|
+
intake = { kind: 'status', disposition: 'ready', summary: `status query admitted for ${input.repositoryFullName}/${manifest.metadata.name}` };
|
|
1305
|
+
}
|
|
1306
|
+
else if (evaluation.command === 'revise') {
|
|
1307
|
+
const boundHeadSha = evaluation.headSha.startsWith('pr-') && COMMIT_SHA_PATTERN.test(effectiveSourceRevision)
|
|
1308
|
+
? effectiveSourceRevision
|
|
1309
|
+
: evaluation.headSha;
|
|
1310
|
+
const reviseInput = {
|
|
1311
|
+
mode: 'revise', tenant,
|
|
1312
|
+
command: { commandId: evaluation.commandId, headSha: boundHeadSha, commandDigest },
|
|
1313
|
+
actorLogin: evaluation.login, authorAssociation: evaluation.authorAssociation,
|
|
1314
|
+
guidance: evaluation.guidance,
|
|
1315
|
+
...(input.operatorAllowlist !== undefined ? { operatorAllowlist: input.operatorAllowlist } : {}),
|
|
1316
|
+
};
|
|
1317
|
+
const outcome = prepareTaskpackIntake(reviseInput);
|
|
1318
|
+
if (outcome.kind === 'revise' && outcome.disposition === 'blocked')
|
|
1319
|
+
return blocked(`revise command rejected: ${outcome.reason}`, outcome.detail);
|
|
1320
|
+
reviseGuidance = evaluation.guidance;
|
|
1321
|
+
intake = outcome;
|
|
1322
|
+
}
|
|
1323
|
+
else {
|
|
1324
|
+
// PR comment commands follow comment-command dispatch semantics; force applies only to non-comment trigger events.
|
|
1325
|
+
// Explicit operator `retry` comments bypass open-PR deduplication while still settling `no_change` if no updates are available.
|
|
1326
|
+
const discovered = runDiscoverIntake(false, true);
|
|
1327
|
+
if (!discovered.ok)
|
|
1328
|
+
return discovered.exit;
|
|
1329
|
+
if (evaluation.guidance.trim().length > 0) {
|
|
1330
|
+
reviseGuidance = evaluation.guidance;
|
|
1331
|
+
}
|
|
1332
|
+
intake = discovered.intake;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
else {
|
|
1336
|
+
return blocked(`unsupported event ${input.eventName}`);
|
|
1337
|
+
}
|
|
1338
|
+
emitProgress?.(`intake: taskpack=${manifest.metadata.name} mode=${input.mode} repo=${input.repositoryFullName} base=${effectiveBaseRevision.slice(0, 12)} kind=${intake.kind}`);
|
|
1339
|
+
if (modelsConfig === undefined && input.modelsJsonPath !== undefined) {
|
|
1340
|
+
try {
|
|
1341
|
+
modelsConfig = await loadPiModelsJson(input.modelsJsonPath);
|
|
1342
|
+
collectModelsJsonApiKeyEnvs(modelsConfig);
|
|
1343
|
+
registerEnvSecrets(modelsJsonApiKeyEnvs);
|
|
1344
|
+
}
|
|
1345
|
+
catch (error) {
|
|
1346
|
+
if (error instanceof GitHubAppError) {
|
|
1347
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
1348
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
1349
|
+
}
|
|
1350
|
+
return blocked(error.code, error.message);
|
|
1351
|
+
}
|
|
1352
|
+
throw error;
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
const scrubber = turnkeyScrubber;
|
|
1356
|
+
const gateEnvName = input.credentialEnvMap?.gate ?? 'LOOPWRIGHT_GATE_SIGNING_SECRET';
|
|
1357
|
+
const gateAuthEnvName = input.credentialEnvMap?.gateAuth ?? 'LOOPWRIGHT_GATE_AUTH_TOKEN';
|
|
1358
|
+
const publicationEnvName = input.credentialEnvMap?.publication ?? 'LOOPWRIGHT_PUBLICATION_SIGNING_SECRET';
|
|
1359
|
+
const publicationAuthEnvName = input.credentialEnvMap?.publicationAuth ?? 'LOOPWRIGHT_PUBLICATION_AUTH_TOKEN';
|
|
1360
|
+
const localCmdGateEnvName = input.credentialEnvMap?.localCommandGate ?? DEFAULT_LOCAL_COMMAND_GATE_ENV;
|
|
1361
|
+
registerEnvSecrets([gateEnvName, gateAuthEnvName, publicationEnvName, publicationAuthEnvName, localCmdGateEnvName]);
|
|
1362
|
+
const hasHostRoleOverrides = input.provider !== undefined
|
|
1363
|
+
|| input.model !== undefined
|
|
1364
|
+
|| input.thinking !== undefined
|
|
1365
|
+
|| input.api !== undefined
|
|
1366
|
+
|| input.baseUrl !== undefined;
|
|
1367
|
+
const roleSelection = hasHostRoleOverrides
|
|
1368
|
+
? {
|
|
1369
|
+
provider: input.provider,
|
|
1370
|
+
model: input.model,
|
|
1371
|
+
thinking: input.thinking,
|
|
1372
|
+
api: input.api,
|
|
1373
|
+
baseUrl: input.baseUrl,
|
|
1374
|
+
}
|
|
1375
|
+
: undefined;
|
|
1376
|
+
const isAutoNoChange = input.mode === 'auto' && autoCheckOnlyNoChangeReason !== null;
|
|
1377
|
+
const effectiveCompileMode = (input.mode === 'no-change' || isAutoNoChange)
|
|
1378
|
+
? 'no-change'
|
|
1379
|
+
: 'candidate';
|
|
1380
|
+
const needsNativePublicationEndpoint = manifest.spec.publication.mode === 'pull_request'
|
|
1381
|
+
&& input.publicationEndpoint === undefined
|
|
1382
|
+
&& effectiveCompileMode === 'candidate';
|
|
1383
|
+
const DRY_RUN_PUBLICATION_SENTINEL_URL = 'http://127.0.0.1:65535/loopwright-dry-run-publication';
|
|
1384
|
+
let activeGateEndpoints = input.gateEndpoints ?? [];
|
|
1385
|
+
let activePublicationEndpoint = input.publicationEndpoint ?? (input.dryRun === true && needsNativePublicationEndpoint
|
|
1386
|
+
? {
|
|
1387
|
+
id: 'dry-run-publication',
|
|
1388
|
+
url: DRY_RUN_PUBLICATION_SENTINEL_URL,
|
|
1389
|
+
signingCredentialRef: 'taskpack-publication-signing',
|
|
1390
|
+
}
|
|
1391
|
+
: null);
|
|
1392
|
+
let mcpRegistry;
|
|
1393
|
+
let baselineAlignmentResult;
|
|
1394
|
+
let enableBaselineConflictGate = false;
|
|
1395
|
+
let extractedConflictPaths;
|
|
1396
|
+
let trackedSourceTokenEnvNames = input.providerTokenEnv !== undefined
|
|
1397
|
+
? [input.providerTokenEnv]
|
|
1398
|
+
: [];
|
|
1399
|
+
const loggedMemoryWarnings = new Set();
|
|
1400
|
+
const buildBindings = (candidate) => {
|
|
1401
|
+
const externalMcpTools = mcpRegistry !== undefined && mcpRegistry.toolNames.length > 0
|
|
1402
|
+
? mcpRegistry.toolNames
|
|
1403
|
+
: undefined;
|
|
1404
|
+
const externalMcpToolSchemas = mcpRegistry !== undefined && externalMcpTools !== undefined
|
|
1405
|
+
? mcpRegistry.toolSchemasFor(externalMcpTools)
|
|
1406
|
+
: undefined;
|
|
1407
|
+
const acceptanceCheckIds = [
|
|
1408
|
+
...manifest.spec.verification.localChecks.map(c => c.id),
|
|
1409
|
+
...manifest.spec.verification.externalGates.map(g => g.id),
|
|
1410
|
+
];
|
|
1411
|
+
const baseGeneratedPrompt = buildDefaultAuthorPrompt({
|
|
1412
|
+
mode: effectiveCompileMode,
|
|
1413
|
+
repositoryFullName: input.repositoryFullName,
|
|
1414
|
+
upstreamRecords: effectiveUpstreamRecords,
|
|
1415
|
+
openManagedPr,
|
|
1416
|
+
reviseGuidance,
|
|
1417
|
+
externalMcpTools,
|
|
1418
|
+
acceptanceCheckIds,
|
|
1419
|
+
runtimeEnv,
|
|
1420
|
+
scrubber,
|
|
1421
|
+
});
|
|
1422
|
+
const wsManifestText = preflightResult !== undefined && preflightResult.workspaceResources.length > 0
|
|
1423
|
+
? formatWorkspaceResourcesManifest(preflightResult.workspaceResources, preflightResult.stagedDir, scrubber)
|
|
1424
|
+
: undefined;
|
|
1425
|
+
const authorPrompt = input.authorPrompt ?? (wsManifestText !== undefined && wsManifestText.length > 0
|
|
1426
|
+
? `${baseGeneratedPrompt}\n\n${wsManifestText}`
|
|
1427
|
+
: baseGeneratedPrompt);
|
|
1428
|
+
return {
|
|
1429
|
+
mode: effectiveCompileMode,
|
|
1430
|
+
...(isAutoNoChange ? { checkOnlyNoChange: true } : {}),
|
|
1431
|
+
hostPolicy,
|
|
1432
|
+
repository: input.repositoryFullName,
|
|
1433
|
+
repositoryRoot: input.repositoryRoot,
|
|
1434
|
+
taskpackPath: effectiveTaskpackPath,
|
|
1435
|
+
baseRevision: effectiveBaseRevision,
|
|
1436
|
+
sourceRevision: effectiveSourceRevision,
|
|
1437
|
+
baselineAlignment: effectiveBaselineConfig,
|
|
1438
|
+
...(baselineAlignmentResult !== undefined ? { baselineAlignmentResult } : {}),
|
|
1439
|
+
...(baselineAlignmentResult?.conflictResource !== null && baselineAlignmentResult?.conflictResource !== undefined
|
|
1440
|
+
? { baselineConflictResource: baselineAlignmentResult.conflictResource }
|
|
1441
|
+
: {}),
|
|
1442
|
+
...(enableBaselineConflictGate ? { enableBaselineConflictGate: true } : {}),
|
|
1443
|
+
upstreamRecords: effectiveUpstreamRecords,
|
|
1444
|
+
targetMatrix: effectiveTargetMatrix ?? manifest.spec.target?.matrix ?? null,
|
|
1445
|
+
roleSelection,
|
|
1446
|
+
...(candidate !== undefined ? { candidateIndex: candidate.manifestIndex } : {}),
|
|
1447
|
+
allowManifestCustomBaseUrl: input.allowManifestCustomBaseUrl,
|
|
1448
|
+
modelsJsonPath: input.modelsJsonPath,
|
|
1449
|
+
...(modelsConfig !== undefined ? { modelsConfig } : {}),
|
|
1450
|
+
runtimeOptions: {},
|
|
1451
|
+
budgets: input.budgets ?? DEFAULT_HOST_BUDGETS,
|
|
1452
|
+
limits: explicitLimitsOverride,
|
|
1453
|
+
envLimits: envLimitsFallback,
|
|
1454
|
+
...(externalMcpTools !== undefined ? { externalMcpTools } : {}),
|
|
1455
|
+
...(externalMcpToolSchemas !== undefined ? { externalMcpToolSchemas } : {}),
|
|
1456
|
+
gateEndpoints: activeGateEndpoints,
|
|
1457
|
+
publicationEndpoint: activePublicationEndpoint,
|
|
1458
|
+
credentialEnvMap: {
|
|
1459
|
+
...(input.credentialEnvMap ?? {}),
|
|
1460
|
+
...(candidate !== undefined
|
|
1461
|
+
? {
|
|
1462
|
+
byProvider: {
|
|
1463
|
+
...(input.credentialEnvMap?.byProvider ?? {}),
|
|
1464
|
+
[candidate.selection.provider]: candidate.providerEnvName,
|
|
1465
|
+
},
|
|
1466
|
+
}
|
|
1467
|
+
: {}),
|
|
1468
|
+
provider: candidate !== undefined
|
|
1469
|
+
? candidate.providerEnvName
|
|
1470
|
+
: (input.credentialEnvMap?.provider ?? input.providerTokenEnv),
|
|
1471
|
+
gate: gateEnvName,
|
|
1472
|
+
gateAuth: gateAuthEnvName,
|
|
1473
|
+
publication: publicationEnvName,
|
|
1474
|
+
publicationAuth: publicationAuthEnvName,
|
|
1475
|
+
localCommandGate: localCmdGateEnvName,
|
|
1476
|
+
},
|
|
1477
|
+
...(trackedSourceTokenEnvNames.length > 0 ? { sourceTokenEnvNames: trackedSourceTokenEnvNames } : {}),
|
|
1478
|
+
resourceVersion: input.resourceVersion,
|
|
1479
|
+
authorPrompt,
|
|
1480
|
+
preflightPromptResources: preflightResult?.promptResources,
|
|
1481
|
+
preflightWorkspaceResources: preflightResult?.workspaceResources,
|
|
1482
|
+
scrubber,
|
|
1483
|
+
onMemoryWarning: message => {
|
|
1484
|
+
if (!loggedMemoryWarnings.has(message)) {
|
|
1485
|
+
loggedMemoryWarnings.add(message);
|
|
1486
|
+
emitProgress?.(`memory: ${message}`);
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
};
|
|
1490
|
+
};
|
|
1491
|
+
const realRunRoot = await realpath(input.runRoot);
|
|
1492
|
+
const realRepositoryRoot = await realpath(input.repositoryRoot);
|
|
1493
|
+
if (insideRoot(realRunRoot, realRepositoryRoot)) {
|
|
1494
|
+
throw new GitHubAppError('ACTION_INPUT_INVALID', 'run root must live outside the target repository checkout');
|
|
1495
|
+
}
|
|
1496
|
+
if (isAutoNoChange) {
|
|
1497
|
+
let checkOnlyCandidate;
|
|
1498
|
+
try {
|
|
1499
|
+
const resolved = resolveTaskpackModelCandidates(manifest, buildBindings(), {
|
|
1500
|
+
modelsConfig,
|
|
1501
|
+
env: runtimeEnv,
|
|
1502
|
+
explicitProviderTokenEnv: input.providerTokenEnv,
|
|
1503
|
+
scrubber,
|
|
1504
|
+
});
|
|
1505
|
+
checkOnlyCandidate = resolved[0];
|
|
1506
|
+
}
|
|
1507
|
+
catch (error) {
|
|
1508
|
+
if (error instanceof GitHubAppError && error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
1509
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
1510
|
+
}
|
|
1511
|
+
checkOnlyCandidate = undefined;
|
|
1512
|
+
}
|
|
1513
|
+
const ncForbiddenEnvNames = new Set([
|
|
1514
|
+
...Object.values(STANDARD_PI_PROVIDER_ENV),
|
|
1515
|
+
...(checkOnlyCandidate !== undefined
|
|
1516
|
+
? [
|
|
1517
|
+
checkOnlyCandidate.providerEnvName,
|
|
1518
|
+
...(checkOnlyCandidate.sourceTokenEnvName !== undefined ? [checkOnlyCandidate.sourceTokenEnvName] : []),
|
|
1519
|
+
]
|
|
1520
|
+
: []),
|
|
1521
|
+
...(manifest.spec.roles?.map(role => resolveDefaultProviderTokenEnv(role.provider, { env: runtimeEnv })) ?? []),
|
|
1522
|
+
...(input.providerTokenEnv !== undefined ? [input.providerTokenEnv] : []),
|
|
1523
|
+
...(input.credentialEnvMap?.provider !== undefined ? [input.credentialEnvMap.provider] : []),
|
|
1524
|
+
...modelsJsonApiKeyEnvs,
|
|
1525
|
+
gateEnvName,
|
|
1526
|
+
publicationEnvName,
|
|
1527
|
+
publicationAuthEnvName,
|
|
1528
|
+
localCmdGateEnvName,
|
|
1529
|
+
...hostGateCredentialEnvs,
|
|
1530
|
+
...decisionApiKeyEnvs,
|
|
1531
|
+
...manifestSecretEnvs,
|
|
1532
|
+
...collectMcpReferencedEnvNames(effectiveMcpDecls),
|
|
1533
|
+
]);
|
|
1534
|
+
trackedSourceTokenEnvNames = [...ncForbiddenEnvNames];
|
|
1535
|
+
let checkOnlyCompiled;
|
|
1536
|
+
try {
|
|
1537
|
+
checkOnlyCompiled = await compileDeclarativeTaskpack(manifest, buildBindings(checkOnlyCandidate));
|
|
1538
|
+
}
|
|
1539
|
+
catch (error) {
|
|
1540
|
+
if (error instanceof GitHubAppError) {
|
|
1541
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
1542
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
1543
|
+
}
|
|
1544
|
+
return blocked(error.code, error.message);
|
|
1545
|
+
}
|
|
1546
|
+
throw error;
|
|
1547
|
+
}
|
|
1548
|
+
let ncLocalGateServer;
|
|
1549
|
+
const ncEphemeralEnv = {};
|
|
1550
|
+
try {
|
|
1551
|
+
const ncCommandGates = checkOnlyCompiled.localCommandGates ?? [];
|
|
1552
|
+
const hasExplicitLocalEndpoint = (input.gateEndpoints ?? []).some(plan => plan.id === LOCAL_COMMAND_GATE_ENDPOINT_ID);
|
|
1553
|
+
if (turnkeyEnabled
|
|
1554
|
+
&& input.delegate === undefined
|
|
1555
|
+
&& ncCommandGates.length > 0
|
|
1556
|
+
&& !hasExplicitLocalEndpoint) {
|
|
1557
|
+
try {
|
|
1558
|
+
ncLocalGateServer = await startLocalCommandGateServer({
|
|
1559
|
+
runRoot: realRunRoot,
|
|
1560
|
+
repositoryRoot: realRepositoryRoot,
|
|
1561
|
+
gates: ncCommandGates,
|
|
1562
|
+
hostPolicy,
|
|
1563
|
+
runtimeEnv,
|
|
1564
|
+
readOnlyGitHubToken: githubToken,
|
|
1565
|
+
scrubber,
|
|
1566
|
+
forbiddenEnvNames: ncForbiddenEnvNames,
|
|
1567
|
+
checkStagedDir: preflightResult?.checkStagedDir,
|
|
1568
|
+
onLog: emitProgress,
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
catch (error) {
|
|
1572
|
+
if (error instanceof GitHubAppError) {
|
|
1573
|
+
if (error.code === 'ACTION_INPUT_INVALID') {
|
|
1574
|
+
return blocked(scrubber.scrub(error.message));
|
|
1575
|
+
}
|
|
1576
|
+
return blocked(error.code, scrubber.scrub(error.message));
|
|
1577
|
+
}
|
|
1578
|
+
throw error;
|
|
1579
|
+
}
|
|
1580
|
+
activeGateEndpoints = [...activeGateEndpoints, ncLocalGateServer.endpointPlan];
|
|
1581
|
+
ncEphemeralEnv[localCmdGateEnvName] = ncLocalGateServer.signingSecret;
|
|
1582
|
+
try {
|
|
1583
|
+
checkOnlyCompiled = await compileDeclarativeTaskpack(manifest, buildBindings(checkOnlyCandidate));
|
|
1584
|
+
}
|
|
1585
|
+
catch (error) {
|
|
1586
|
+
if (error instanceof GitHubAppError) {
|
|
1587
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
1588
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
1589
|
+
}
|
|
1590
|
+
return blocked(error.code, error.message);
|
|
1591
|
+
}
|
|
1592
|
+
throw error;
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
const trustedDirectory = join(realRunRoot, `lw-action-nc-${process.pid}-${Date.now().toString(36)}`);
|
|
1596
|
+
const registryDirectory = join(trustedDirectory, 'registry');
|
|
1597
|
+
const configDirectory = join(trustedDirectory, 'config');
|
|
1598
|
+
await mkdir(registryDirectory, { recursive: true });
|
|
1599
|
+
await mkdir(configDirectory, { recursive: true });
|
|
1600
|
+
await chmod(trustedDirectory, 0o700);
|
|
1601
|
+
await chmod(registryDirectory, 0o700);
|
|
1602
|
+
await chmod(configDirectory, 0o700);
|
|
1603
|
+
const registryPath = join(registryDirectory, 'registry.yaml');
|
|
1604
|
+
const configPath = join(configDirectory, 'config.yaml');
|
|
1605
|
+
const configBytes = Buffer.from(serializePrettyYaml(checkOnlyCompiled.config), 'utf8');
|
|
1606
|
+
assertCleanArtifact(checkOnlyCompiled.registryBytes, scrubber, '/registry');
|
|
1607
|
+
assertCleanArtifact(configBytes, scrubber, '/config');
|
|
1608
|
+
for (const resource of checkOnlyCompiled.instructionResources ?? []) {
|
|
1609
|
+
assertCleanArtifact(resource.bytes, scrubber, `/resources/${resource.id}`);
|
|
1610
|
+
}
|
|
1611
|
+
await writeFile(registryPath, checkOnlyCompiled.registryBytes, { mode: 0o600 });
|
|
1612
|
+
await writeFile(configPath, configBytes, { mode: 0o600 });
|
|
1613
|
+
await chmod(registryPath, 0o600);
|
|
1614
|
+
await chmod(configPath, 0o600);
|
|
1615
|
+
if (checkOnlyCompiled.instructionResources !== undefined && checkOnlyCompiled.instructionResources.length > 0) {
|
|
1616
|
+
await stageCompiledInstructionResources(registryDirectory, checkOnlyCompiled.instructionResources);
|
|
1617
|
+
}
|
|
1618
|
+
const writtenNoChange = {
|
|
1619
|
+
...checkOnlyCompiled,
|
|
1620
|
+
configBytes,
|
|
1621
|
+
trustedDirectory,
|
|
1622
|
+
registryPath,
|
|
1623
|
+
configPath,
|
|
1624
|
+
};
|
|
1625
|
+
const ncDelegate = input.delegate ?? (turnkeyEnabled
|
|
1626
|
+
? createTurnkeyCycleDelegate({
|
|
1627
|
+
runId: input.runId,
|
|
1628
|
+
repositoryRoot: realRepositoryRoot,
|
|
1629
|
+
runtimeEnv,
|
|
1630
|
+
ephemeralEnv: ncEphemeralEnv,
|
|
1631
|
+
scrubber,
|
|
1632
|
+
policyProfile: 'github',
|
|
1633
|
+
allowWorkflowWrites: writtenNoChange.allowWorkflowWrites,
|
|
1634
|
+
openHostSessionAdapter: input.openHostSessionAdapter,
|
|
1635
|
+
onLog: emitProgress,
|
|
1636
|
+
})
|
|
1637
|
+
: undefined);
|
|
1638
|
+
const ncOutcome = (input.dryRun === true || ncDelegate === undefined)
|
|
1639
|
+
? null
|
|
1640
|
+
: await ncDelegate(writtenNoChange);
|
|
1641
|
+
return {
|
|
1642
|
+
kind: 'no_change',
|
|
1643
|
+
reason: autoCheckOnlyNoChangeReason,
|
|
1644
|
+
taskpack: writtenNoChange,
|
|
1645
|
+
delegateOutcome: ncOutcome === null ? null : { ok: ncOutcome.ok, detail: scrubber.scrub(ncOutcome.detail) },
|
|
1646
|
+
};
|
|
1647
|
+
}
|
|
1648
|
+
finally {
|
|
1649
|
+
if (ncLocalGateServer !== undefined) {
|
|
1650
|
+
await ncLocalGateServer.close().catch(() => undefined);
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
// Pre-probe 3-way baseline alignment: runs STRICTLY BEFORE model candidate probing (`selectHealthyModelCandidate`)!
|
|
1655
|
+
if (input.dryRun !== true
|
|
1656
|
+
&& effectiveCompileMode === 'candidate'
|
|
1657
|
+
&& effectiveSourceRevision !== effectiveBaseRevision
|
|
1658
|
+
&& (existsSync(join(realRepositoryRoot, '.git')) || effectiveBaselineConfig.policy !== 'off')) {
|
|
1659
|
+
try {
|
|
1660
|
+
baselineAlignmentResult = await alignBaselineRevisions({
|
|
1661
|
+
repositoryRoot: realRepositoryRoot,
|
|
1662
|
+
baseRevision: effectiveBaseRevision,
|
|
1663
|
+
sourceRevision: effectiveSourceRevision,
|
|
1664
|
+
manifest,
|
|
1665
|
+
taskpackPath: effectiveTaskpackPath,
|
|
1666
|
+
policyProfile: 'github',
|
|
1667
|
+
hostPolicy,
|
|
1668
|
+
extraProtectedPaths: suiteExtraProtectedPaths,
|
|
1669
|
+
baselineAlignment: effectiveBaselineConfig,
|
|
1670
|
+
scrubber,
|
|
1671
|
+
scratchRoot: realRunRoot,
|
|
1672
|
+
onLog: emitProgress,
|
|
1673
|
+
});
|
|
1674
|
+
}
|
|
1675
|
+
catch (error) {
|
|
1676
|
+
if (error instanceof GitHubAppError) {
|
|
1677
|
+
return blocked(error.code, scrubber.scrub(error.message));
|
|
1678
|
+
}
|
|
1679
|
+
throw error;
|
|
1680
|
+
}
|
|
1681
|
+
if (baselineAlignmentResult.status === 'blocked') {
|
|
1682
|
+
const conflictDetail = scrubber.scrub(baselineAlignmentResult.detail || baselineAlignmentResult.reason);
|
|
1683
|
+
input.onTurnkeyReport?.({
|
|
1684
|
+
manifest,
|
|
1685
|
+
scrubber,
|
|
1686
|
+
report: {
|
|
1687
|
+
runId: normalizeControllerRunId(input.runId),
|
|
1688
|
+
status: 'blocked',
|
|
1689
|
+
reasonCode: BASELINE_CONFLICT_REASON,
|
|
1690
|
+
detail: conflictDetail,
|
|
1691
|
+
discovery: intake.kind === 'discover'
|
|
1692
|
+
? { disposition: intake.disposition, ...(intake.disposition === 'ready' ? { updatesCount: intake.updates.length } : {}) }
|
|
1693
|
+
: null,
|
|
1694
|
+
scrub: text => scrubber.scrub(text),
|
|
1695
|
+
},
|
|
1696
|
+
});
|
|
1697
|
+
return blocked(BASELINE_CONFLICT_REASON, conflictDetail);
|
|
1698
|
+
}
|
|
1699
|
+
enableBaselineConflictGate = baselineAlignmentResult.conflictResource !== null
|
|
1700
|
+
|| baselineAlignmentResult.disposition === 'unmerged_off';
|
|
1701
|
+
extractedConflictPaths = baselineAlignmentResult.conflictResource?.extractedPaths;
|
|
1702
|
+
}
|
|
1703
|
+
const roleProviderEnvNames = [];
|
|
1704
|
+
if (manifest.spec.roles !== undefined && manifest.spec.roles.length > 0) {
|
|
1705
|
+
try {
|
|
1706
|
+
for (const [roleIdx, role] of manifest.spec.roles.entries()) {
|
|
1707
|
+
const normalizedProvider = role.provider.trim().toLowerCase();
|
|
1708
|
+
if (isOAuthOnlyPiProvider(normalizedProvider) || normalizedProvider === 'antigravity' || normalizedProvider === 'pi-oauth') {
|
|
1709
|
+
throw new GitHubAppError('PROVIDER_OAUTH_UNSUPPORTED', `Pi provider "${role.provider}" uses OAuth or CLI login, which Loopwright refuses; configure a token-authenticated Pi provider`, `/spec/roles/${roleIdx}/provider`);
|
|
1710
|
+
}
|
|
1711
|
+
if (role.thinking !== undefined && !PI_THINKING_LEVELS.includes(role.thinking)) {
|
|
1712
|
+
throw new GitHubAppError('TASKPACK_MANIFEST_INVALID', `spec.roles[].thinking must be one of ${PI_THINKING_LEVELS.join(', ')}`, `/spec/roles/${roleIdx}/thinking`);
|
|
1713
|
+
}
|
|
1714
|
+
const roleBindings = {
|
|
1715
|
+
...buildBindings(),
|
|
1716
|
+
candidateIndex: undefined,
|
|
1717
|
+
roleSelection: {
|
|
1718
|
+
provider: role.provider,
|
|
1719
|
+
model: role.model,
|
|
1720
|
+
...(role.thinking !== undefined ? { thinking: role.thinking } : {}),
|
|
1721
|
+
},
|
|
1722
|
+
};
|
|
1723
|
+
const { selection, apiKeyEnv } = resolveTaskpackModelSelection(manifest, roleBindings, modelsConfig);
|
|
1724
|
+
const modelsJsonApiKeyEnv = modelsConfig?.providers.get(selection.provider)?.apiKeyEnv;
|
|
1725
|
+
roleProviderEnvNames.push(resolveDefaultProviderTokenEnv(selection.provider, {
|
|
1726
|
+
modelsJsonApiKeyEnv,
|
|
1727
|
+
manifestApiKeyEnv: apiKeyEnv,
|
|
1728
|
+
env: runtimeEnv,
|
|
1729
|
+
}));
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
catch (error) {
|
|
1733
|
+
if (error instanceof GitHubAppError) {
|
|
1734
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
1735
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
1736
|
+
}
|
|
1737
|
+
return blocked(error.code, error.message);
|
|
1738
|
+
}
|
|
1739
|
+
throw error;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
let candidates;
|
|
1743
|
+
try {
|
|
1744
|
+
const firstRole = manifest.spec.roles?.[0];
|
|
1745
|
+
const candidateBaseBindings = (manifest.spec.models === undefined && firstRole !== undefined && roleSelection === undefined)
|
|
1746
|
+
? {
|
|
1747
|
+
...buildBindings(),
|
|
1748
|
+
roleSelection: {
|
|
1749
|
+
provider: firstRole.provider,
|
|
1750
|
+
model: firstRole.model,
|
|
1751
|
+
...(firstRole.thinking !== undefined ? { thinking: firstRole.thinking } : {}),
|
|
1752
|
+
},
|
|
1753
|
+
}
|
|
1754
|
+
: buildBindings();
|
|
1755
|
+
candidates = resolveTaskpackModelCandidates(manifest, candidateBaseBindings, {
|
|
1756
|
+
modelsConfig,
|
|
1757
|
+
env: runtimeEnv,
|
|
1758
|
+
explicitProviderTokenEnv: input.providerTokenEnv,
|
|
1759
|
+
scrubber,
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
catch (error) {
|
|
1763
|
+
if (error instanceof GitHubAppError) {
|
|
1764
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
1765
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
1766
|
+
}
|
|
1767
|
+
return blocked(error.code, error.message);
|
|
1768
|
+
}
|
|
1769
|
+
throw error;
|
|
1770
|
+
}
|
|
1771
|
+
const forbiddenCommandEnvNames = new Set([
|
|
1772
|
+
...candidates.flatMap(candidate => [
|
|
1773
|
+
candidate.providerEnvName,
|
|
1774
|
+
...(candidate.sourceTokenEnvName !== undefined ? [candidate.sourceTokenEnvName] : []),
|
|
1775
|
+
]),
|
|
1776
|
+
...roleProviderEnvNames,
|
|
1777
|
+
...(manifest.spec.roles?.map(role => resolveDefaultProviderTokenEnv(role.provider, { env: runtimeEnv })) ?? []),
|
|
1778
|
+
...(input.providerTokenEnv !== undefined ? [input.providerTokenEnv] : []),
|
|
1779
|
+
...(input.credentialEnvMap?.provider !== undefined ? [input.credentialEnvMap.provider] : []),
|
|
1780
|
+
...modelsJsonApiKeyEnvs,
|
|
1781
|
+
gateEnvName,
|
|
1782
|
+
gateAuthEnvName,
|
|
1783
|
+
publicationEnvName,
|
|
1784
|
+
publicationAuthEnvName,
|
|
1785
|
+
localCmdGateEnvName,
|
|
1786
|
+
...hostGateCredentialEnvs,
|
|
1787
|
+
...decisionApiKeyEnvs,
|
|
1788
|
+
...manifestSecretEnvs,
|
|
1789
|
+
...collectMcpReferencedEnvNames(effectiveMcpDecls),
|
|
1790
|
+
]);
|
|
1791
|
+
trackedSourceTokenEnvNames = [...forbiddenCommandEnvNames];
|
|
1792
|
+
if (input.dryRun !== true
|
|
1793
|
+
&& effectiveCompileMode === 'candidate'
|
|
1794
|
+
&& !(input.gateEndpoints ?? []).some(plan => plan.id === LOCAL_COMMAND_GATE_ENDPOINT_ID)) {
|
|
1795
|
+
try {
|
|
1796
|
+
await validateManifestCommandToolchainPaths(manifest, realRepositoryRoot, hostPolicy.allowPrivileged === true);
|
|
1797
|
+
}
|
|
1798
|
+
catch (error) {
|
|
1799
|
+
if (error instanceof GitHubAppError) {
|
|
1800
|
+
return blocked(error.code, scrubber.scrub(error.message));
|
|
1801
|
+
}
|
|
1802
|
+
throw error;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
const effectiveExternalGateEnvs = new Set([
|
|
1806
|
+
gateEnvName,
|
|
1807
|
+
gateAuthEnvName,
|
|
1808
|
+
...collectHostGateCredentialEnvNames({
|
|
1809
|
+
credentialEnvMap: input.credentialEnvMap !== undefined
|
|
1810
|
+
? { ...input.credentialEnvMap, localCommandGate: undefined }
|
|
1811
|
+
: undefined,
|
|
1812
|
+
gateEndpoints: activeGateEndpoints.filter(ep => ep.id !== LOCAL_COMMAND_GATE_ENDPOINT_ID),
|
|
1813
|
+
}),
|
|
1814
|
+
]);
|
|
1815
|
+
const effectiveMcpExcludedGateEnvs = new Set([
|
|
1816
|
+
...effectiveExternalGateEnvs,
|
|
1817
|
+
localCmdGateEnvName,
|
|
1818
|
+
]);
|
|
1819
|
+
for (const candidate of candidates) {
|
|
1820
|
+
const candidateEnvs = [
|
|
1821
|
+
candidate.providerEnvName,
|
|
1822
|
+
...(candidate.sourceTokenEnvName !== undefined ? [candidate.sourceTokenEnvName] : []),
|
|
1823
|
+
];
|
|
1824
|
+
for (const envName of candidateEnvs) {
|
|
1825
|
+
if (effectiveExternalGateEnvs.has(envName)) {
|
|
1826
|
+
return {
|
|
1827
|
+
kind: 'refused',
|
|
1828
|
+
code: 'TASKPACK_HOST_BINDING_INVALID',
|
|
1829
|
+
reason: scrubber.scrub(`provider credential environment variable "${envName}" must not overlap a host external gate credential`),
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
let currentPos = 0;
|
|
1835
|
+
if (input.dryRun !== true && candidates.length >= 2) {
|
|
1836
|
+
try {
|
|
1837
|
+
const selected = await selectHealthyModelCandidate(candidates, {
|
|
1838
|
+
fetchImpl: input.probeFetch,
|
|
1839
|
+
totalTimeoutMs: input.probeTimeoutMs,
|
|
1840
|
+
scrubber,
|
|
1841
|
+
});
|
|
1842
|
+
currentPos = selected.index;
|
|
1843
|
+
}
|
|
1844
|
+
catch (error) {
|
|
1845
|
+
if (error instanceof GitHubAppError) {
|
|
1846
|
+
return blocked(error.code, error.message);
|
|
1847
|
+
}
|
|
1848
|
+
throw error;
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
let localGateServer;
|
|
1852
|
+
let publisherServer;
|
|
1853
|
+
let lastTurnkeySummary;
|
|
1854
|
+
try {
|
|
1855
|
+
const ephemeralEnv = {};
|
|
1856
|
+
if (turnkeyEnabled && input.delegate === undefined) {
|
|
1857
|
+
if (effectiveMcpDecls.length > 0) {
|
|
1858
|
+
let resolvedMcpConfigs;
|
|
1859
|
+
try {
|
|
1860
|
+
resolvedMcpConfigs = resolveExternalMcpConfigs({
|
|
1861
|
+
declarations: effectiveMcpDecls,
|
|
1862
|
+
runtimeEnv,
|
|
1863
|
+
githubToken,
|
|
1864
|
+
allowLoopbackHttp: input.allowManifestCustomBaseUrl === true,
|
|
1865
|
+
scrubber,
|
|
1866
|
+
excludedEnvNames: effectiveMcpExcludedGateEnvs,
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1869
|
+
catch (error) {
|
|
1870
|
+
if (error instanceof GitHubAppError) {
|
|
1871
|
+
if (error.code === 'MCP_AUTHENTICATION_REQUIRED') {
|
|
1872
|
+
return { kind: 'refused', code: 'MCP_AUTHENTICATION_REQUIRED', reason: scrubber.scrub(error.message) };
|
|
1873
|
+
}
|
|
1874
|
+
return blocked(error.code, scrubber.scrub(error.message));
|
|
1875
|
+
}
|
|
1876
|
+
throw error;
|
|
1877
|
+
}
|
|
1878
|
+
if (resolvedMcpConfigs.length > 0) {
|
|
1879
|
+
try {
|
|
1880
|
+
mcpRegistry = await HostMcpRegistry.connect(resolvedMcpConfigs, {
|
|
1881
|
+
untrustedRoots: [realRepositoryRoot],
|
|
1882
|
+
trustedPathEnv: runtimeEnv['PATH'],
|
|
1883
|
+
scrub: text => scrubber.scrub(text),
|
|
1884
|
+
});
|
|
1885
|
+
}
|
|
1886
|
+
catch (error) {
|
|
1887
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1888
|
+
return blocked('MCP_CONNECTION_FAILED', scrubber.scrub(message));
|
|
1889
|
+
}
|
|
1890
|
+
for (const srv of mcpRegistry.servers) {
|
|
1891
|
+
emitProgress?.(`mcp: connected ${srv.id} (${srv.transport}) — ${srv.toolNames.length} tools`);
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
if (needsNativePublicationEndpoint && manifest.spec.publication.mode === 'pull_request') {
|
|
1896
|
+
publisherServer = await startNativePullRequestPublisherServer({
|
|
1897
|
+
runRoot: realRunRoot,
|
|
1898
|
+
repositoryRoot: realRepositoryRoot,
|
|
1899
|
+
repositoryFullName: input.repositoryFullName,
|
|
1900
|
+
targetBranch: manifest.spec.publication.targetBranch,
|
|
1901
|
+
headBranchPrefix: manifest.spec.publication.headBranchPrefix,
|
|
1902
|
+
proposalPath: manifest.spec.proposal?.path,
|
|
1903
|
+
titleTemplate: manifest.spec.publication.titleTemplate,
|
|
1904
|
+
openManagedPr,
|
|
1905
|
+
remoteUrl: input.gitRemoteUrl,
|
|
1906
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
1907
|
+
gitWriteToken: githubToken,
|
|
1908
|
+
gitCommitIdentity,
|
|
1909
|
+
fetchImpl: input.probeFetch,
|
|
1910
|
+
scrubber,
|
|
1911
|
+
extractedConflictPaths,
|
|
1912
|
+
});
|
|
1913
|
+
activePublicationEndpoint = publisherServer.endpointPlan;
|
|
1914
|
+
ephemeralEnv[publicationEnvName] = publisherServer.signingSecret;
|
|
1915
|
+
ephemeralEnv[publicationAuthEnvName] = publisherServer.authToken;
|
|
1916
|
+
}
|
|
1917
|
+
const hasCommandChecks = effectiveCompileMode === 'candidate'
|
|
1918
|
+
&& (manifest.spec.verification.localChecks.some(check => check.implementation === 'command.v1')
|
|
1919
|
+
|| enableBaselineConflictGate);
|
|
1920
|
+
if (hasCommandChecks) {
|
|
1921
|
+
let preview;
|
|
1922
|
+
try {
|
|
1923
|
+
preview = await compileDeclarativeTaskpack(manifest, buildBindings(candidates[currentPos]));
|
|
1924
|
+
}
|
|
1925
|
+
catch (error) {
|
|
1926
|
+
if (error instanceof GitHubAppError) {
|
|
1927
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
1928
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
1929
|
+
}
|
|
1930
|
+
if (error.code === 'ACTION_INPUT_INVALID') {
|
|
1931
|
+
return blocked(error.message);
|
|
1932
|
+
}
|
|
1933
|
+
return blocked(error.code, error.message);
|
|
1934
|
+
}
|
|
1935
|
+
throw error;
|
|
1936
|
+
}
|
|
1937
|
+
const hasExplicitLocalEndpoint = (input.gateEndpoints ?? []).some(plan => plan.id === LOCAL_COMMAND_GATE_ENDPOINT_ID);
|
|
1938
|
+
if (!hasExplicitLocalEndpoint) {
|
|
1939
|
+
try {
|
|
1940
|
+
localGateServer = await startLocalCommandGateServer({
|
|
1941
|
+
runRoot: realRunRoot,
|
|
1942
|
+
repositoryRoot: realRepositoryRoot,
|
|
1943
|
+
gates: preview.localCommandGates ?? [],
|
|
1944
|
+
hostPolicy,
|
|
1945
|
+
runtimeEnv,
|
|
1946
|
+
readOnlyGitHubToken: githubToken,
|
|
1947
|
+
scrubber,
|
|
1948
|
+
forbiddenEnvNames: forbiddenCommandEnvNames,
|
|
1949
|
+
checkStagedDir: preflightResult?.checkStagedDir,
|
|
1950
|
+
extractedConflictPaths: preview.extractedConflictPaths ?? extractedConflictPaths,
|
|
1951
|
+
onLog: emitProgress,
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1954
|
+
catch (error) {
|
|
1955
|
+
if (error instanceof GitHubAppError) {
|
|
1956
|
+
if (error.code === 'ACTION_INPUT_INVALID') {
|
|
1957
|
+
return blocked(scrubber.scrub(error.message));
|
|
1958
|
+
}
|
|
1959
|
+
return blocked(error.code, scrubber.scrub(error.message));
|
|
1960
|
+
}
|
|
1961
|
+
throw error;
|
|
1962
|
+
}
|
|
1963
|
+
activeGateEndpoints = [...activeGateEndpoints, localGateServer.endpointPlan];
|
|
1964
|
+
ephemeralEnv[localCmdGateEnvName] = localGateServer.signingSecret;
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
const compileAndWriteCandidate = async (candidate, attemptSeq) => {
|
|
1969
|
+
const compiled = await compileDeclarativeTaskpack(manifest, buildBindings(candidate));
|
|
1970
|
+
// The controller loader adds dirname(configPath) to its trust roots and requires every trusted parent
|
|
1971
|
+
// directory to be 0o700, so registry and config live in separate owner-only subdirectories.
|
|
1972
|
+
const suffix = attemptSeq === 0 ? '' : `-fallback-${attemptSeq}`;
|
|
1973
|
+
const trustedDirectory = join(realRunRoot, `lw-action-${process.pid}-${Date.now().toString(36)}${suffix}`);
|
|
1974
|
+
const registryDirectory = join(trustedDirectory, 'registry');
|
|
1975
|
+
const configDirectory = join(trustedDirectory, 'config');
|
|
1976
|
+
await mkdir(registryDirectory, { recursive: true });
|
|
1977
|
+
await mkdir(configDirectory, { recursive: true });
|
|
1978
|
+
await chmod(trustedDirectory, 0o700);
|
|
1979
|
+
await chmod(registryDirectory, 0o700);
|
|
1980
|
+
await chmod(configDirectory, 0o700);
|
|
1981
|
+
const registryPath = join(registryDirectory, 'registry.yaml');
|
|
1982
|
+
const configPath = join(configDirectory, 'config.yaml');
|
|
1983
|
+
const configBytes = Buffer.from(serializePrettyYaml(compiled.config), 'utf8');
|
|
1984
|
+
await writeFile(registryPath, compiled.registryBytes, { mode: 0o600 });
|
|
1985
|
+
await writeFile(configPath, configBytes, { mode: 0o600 });
|
|
1986
|
+
await chmod(registryPath, 0o600);
|
|
1987
|
+
await chmod(configPath, 0o600);
|
|
1988
|
+
if (compiled.instructionResources !== undefined && compiled.instructionResources.length > 0) {
|
|
1989
|
+
await stageCompiledInstructionResources(registryDirectory, compiled.instructionResources);
|
|
1990
|
+
for (const resource of compiled.instructionResources) {
|
|
1991
|
+
assertCleanArtifact(resource.bytes, scrubber, `/resources/${resource.id}`);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
assertCleanArtifact(compiled.registryBytes, scrubber, '/registry');
|
|
1995
|
+
assertCleanArtifact(configBytes, scrubber, '/config');
|
|
1996
|
+
return {
|
|
1997
|
+
...compiled, configBytes, trustedDirectory, registryPath, configPath,
|
|
1998
|
+
};
|
|
1999
|
+
};
|
|
2000
|
+
let activeCandidate = candidates[currentPos];
|
|
2001
|
+
let activeTaskpack;
|
|
2002
|
+
try {
|
|
2003
|
+
activeTaskpack = await compileAndWriteCandidate(activeCandidate, 0);
|
|
2004
|
+
}
|
|
2005
|
+
catch (error) {
|
|
2006
|
+
if (error instanceof GitHubAppError) {
|
|
2007
|
+
if (error.code === 'PROVIDER_OAUTH_UNSUPPORTED') {
|
|
2008
|
+
return { kind: 'refused', code: 'PROVIDER_OAUTH_UNSUPPORTED', reason: error.message };
|
|
2009
|
+
}
|
|
2010
|
+
if (error.code === 'ACTION_INPUT_INVALID') {
|
|
2011
|
+
return blocked(error.message);
|
|
2012
|
+
}
|
|
2013
|
+
return blocked(error.code, error.message);
|
|
2014
|
+
}
|
|
2015
|
+
throw error;
|
|
2016
|
+
}
|
|
2017
|
+
let activeContextWindow = resolveCatalogModel(activeCandidate.selection).record.contextWindow;
|
|
2018
|
+
const activeBudgets = activeTaskpack.config.spec.task.spec.budgets;
|
|
2019
|
+
emitProgress?.(`model: ${activeCandidate.selection.provider}/${activeCandidate.selection.model} (thinking=${activeCandidate.selection.thinking ?? 'off'})`
|
|
2020
|
+
+ ` — wallTime=${formatDurationMs(activeBudgets.wallTimeMs)}, totalTokens=${formatTokenCount(activeBudgets.totalTokens)}, maxOutputTokens=${formatTokenCount(activeBudgets.perCallOutputTokens)}, contextWindow=${formatTokenCount(activeContextWindow)}`);
|
|
2021
|
+
let decisionPort;
|
|
2022
|
+
try {
|
|
2023
|
+
decisionPort = createTaskpackDecisionPort(manifest, {
|
|
2024
|
+
runtimeEnv,
|
|
2025
|
+
apiKey: input.decisionApiKey,
|
|
2026
|
+
transport: input.decisionTransport,
|
|
2027
|
+
scrubber,
|
|
2028
|
+
hasPinnedRoles: (manifest.spec.roles?.length ?? 0) > 0 || hasHostRoleOverrides,
|
|
2029
|
+
excludedEnvNames: effectiveExternalGateEnvs,
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
catch (error) {
|
|
2033
|
+
if (error instanceof GitHubAppError) {
|
|
2034
|
+
if (error.code === 'TASKPACK_HOST_BINDING_INVALID') {
|
|
2035
|
+
return { kind: 'refused', code: 'TASKPACK_HOST_BINDING_INVALID', reason: scrubber.scrub(error.message) };
|
|
2036
|
+
}
|
|
2037
|
+
return blocked(error.code, scrubber.scrub(error.message));
|
|
2038
|
+
}
|
|
2039
|
+
throw error;
|
|
2040
|
+
}
|
|
2041
|
+
const stepMcpMetadata = mcpRegistry?.servers.map(srv => ({
|
|
2042
|
+
id: srv.id,
|
|
2043
|
+
transport: srv.transport,
|
|
2044
|
+
toolNames: srv.toolNames,
|
|
2045
|
+
}));
|
|
2046
|
+
const effectiveDelegate = input.delegate ?? (turnkeyEnabled
|
|
2047
|
+
? createTurnkeyCycleDelegate({
|
|
2048
|
+
runId: input.runId,
|
|
2049
|
+
repositoryRoot: realRepositoryRoot,
|
|
2050
|
+
runtimeEnv,
|
|
2051
|
+
ephemeralEnv,
|
|
2052
|
+
scrubber,
|
|
2053
|
+
mcpRegistry,
|
|
2054
|
+
mcpServers: stepMcpMetadata,
|
|
2055
|
+
decisions: decisionPort,
|
|
2056
|
+
policyProfile: 'github',
|
|
2057
|
+
allowWorkflowWrites: activeTaskpack.allowWorkflowWrites,
|
|
2058
|
+
openHostSessionAdapter: input.openHostSessionAdapter,
|
|
2059
|
+
onLog: emitProgress,
|
|
2060
|
+
onAttemptSettled: summary => {
|
|
2061
|
+
lastTurnkeySummary = summary;
|
|
2062
|
+
},
|
|
2063
|
+
})
|
|
2064
|
+
: undefined);
|
|
2065
|
+
const reportMcpServers = mcpRegistry?.servers.map((srv) => ({
|
|
2066
|
+
id: srv.id,
|
|
2067
|
+
transport: srv.transport,
|
|
2068
|
+
toolCount: srv.toolNames.length,
|
|
2069
|
+
status: 'connected',
|
|
2070
|
+
}));
|
|
2071
|
+
if (input.dryRun === true || effectiveDelegate === undefined) {
|
|
2072
|
+
input.onTurnkeyReport?.({
|
|
2073
|
+
manifest,
|
|
2074
|
+
scrubber,
|
|
2075
|
+
report: {
|
|
2076
|
+
runId: normalizeControllerRunId(input.runId),
|
|
2077
|
+
status: input.dryRun === true ? 'dry_run' : 'compiled',
|
|
2078
|
+
discovery: intake.kind === 'discover'
|
|
2079
|
+
? { disposition: intake.disposition, ...(intake.disposition === 'ready' ? { updatesCount: intake.updates.length } : {}) }
|
|
2080
|
+
: null,
|
|
2081
|
+
model: {
|
|
2082
|
+
provider: activeCandidate.selection.provider,
|
|
2083
|
+
model: activeCandidate.selection.model,
|
|
2084
|
+
thinking: activeCandidate.selection.thinking ?? null,
|
|
2085
|
+
contextWindow: activeContextWindow,
|
|
2086
|
+
},
|
|
2087
|
+
...(reportMcpServers !== undefined && reportMcpServers.length > 0 ? { mcpServers: reportMcpServers } : {}),
|
|
2088
|
+
scrub: text => scrubber.scrub(text),
|
|
2089
|
+
},
|
|
2090
|
+
});
|
|
2091
|
+
return { kind: 'compiled', manifest, intake, taskpack: activeTaskpack, delegateOutcome: null };
|
|
2092
|
+
}
|
|
2093
|
+
let attemptSeq = 0;
|
|
2094
|
+
let lastOutcome = await invokeDelegateForCandidate(activeCandidate, activeTaskpack, effectiveDelegate);
|
|
2095
|
+
if (candidates.length === 1 && shouldRotateModelCandidate(lastOutcome)) {
|
|
2096
|
+
const elapsedEntrypointMs = Math.max(0, Math.round(performance.now() - entrypointStartedMs));
|
|
2097
|
+
const configuredWallTimeMs = activeTaskpack.config.spec.task.spec.budgets.wallTimeMs;
|
|
2098
|
+
const minReserveMs = Math.min(60_000, Math.floor(configuredWallTimeMs / 4));
|
|
2099
|
+
if (elapsedEntrypointMs + minReserveMs < configuredWallTimeMs) {
|
|
2100
|
+
attemptSeq += 1;
|
|
2101
|
+
emitProgress?.(`model: retrying primary candidate #${attemptSeq} after transient provider failure (${activeCandidate.selection.provider}/${activeCandidate.selection.model}, contextWindow=${formatTokenCount(activeContextWindow)})`);
|
|
2102
|
+
activeTaskpack = await compileAndWriteCandidate(activeCandidate, attemptSeq);
|
|
2103
|
+
lastOutcome = await invokeDelegateForCandidate(activeCandidate, activeTaskpack, effectiveDelegate);
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
else {
|
|
2107
|
+
while (shouldRotateModelCandidate(lastOutcome) && currentPos + 1 < candidates.length) {
|
|
2108
|
+
const remaining = candidates.slice(currentPos + 1);
|
|
2109
|
+
let nextSelected;
|
|
2110
|
+
try {
|
|
2111
|
+
nextSelected = await selectHealthyModelCandidate(remaining, {
|
|
2112
|
+
fetchImpl: input.probeFetch,
|
|
2113
|
+
totalTimeoutMs: input.probeTimeoutMs,
|
|
2114
|
+
forceProbe: true,
|
|
2115
|
+
scrubber,
|
|
2116
|
+
});
|
|
2117
|
+
}
|
|
2118
|
+
catch {
|
|
2119
|
+
lastOutcome = {
|
|
2120
|
+
ok: false,
|
|
2121
|
+
detail: scrubber.scrub(`${lastOutcome.detail}; remaining model fallback candidates failed readiness probe`),
|
|
2122
|
+
};
|
|
2123
|
+
break;
|
|
2124
|
+
}
|
|
2125
|
+
currentPos = currentPos + 1 + nextSelected.index;
|
|
2126
|
+
activeCandidate = candidates[currentPos];
|
|
2127
|
+
activeContextWindow = resolveCatalogModel(activeCandidate.selection).record.contextWindow;
|
|
2128
|
+
attemptSeq += 1;
|
|
2129
|
+
emitProgress?.(`model: rotating to fallback #${attemptSeq} (${activeCandidate.selection.provider}/${activeCandidate.selection.model}, contextWindow=${formatTokenCount(activeContextWindow)})`);
|
|
2130
|
+
activeTaskpack = await compileAndWriteCandidate(activeCandidate, attemptSeq);
|
|
2131
|
+
lastOutcome = await invokeDelegateForCandidate(activeCandidate, activeTaskpack, effectiveDelegate);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
const settledRunId = lastTurnkeySummary?.attemptRunId ?? normalizeControllerRunId(input.runId);
|
|
2135
|
+
let memorySummary;
|
|
2136
|
+
if (lastTurnkeySummary !== undefined || existsSync(join(realRunRoot, settledRunId, 'run.json'))) {
|
|
2137
|
+
const memoryTargetCell = effectiveTargetMatrix !== undefined
|
|
2138
|
+
? (effectiveTargetMatrix !== null && effectiveTargetMatrix.length === 1 ? effectiveTargetMatrix[0] : null)
|
|
2139
|
+
: undefined;
|
|
2140
|
+
try {
|
|
2141
|
+
const publishedCandidate = publisherServer?.getLastPublishedPullRequest() ?? null;
|
|
2142
|
+
memorySummary = await finalizeAndPublishTurnkeyMemory({
|
|
2143
|
+
runRoot: realRunRoot,
|
|
2144
|
+
runId: settledRunId,
|
|
2145
|
+
repositoryRoot: realRepositoryRoot,
|
|
2146
|
+
repositoryFullName: input.repositoryFullName,
|
|
2147
|
+
manifest,
|
|
2148
|
+
taskpackPath: effectiveTaskpackPath,
|
|
2149
|
+
baseRevision: effectiveBaseRevision,
|
|
2150
|
+
upstreamRecords: effectiveUpstreamRecords,
|
|
2151
|
+
...(memoryTargetCell !== undefined ? { targetMatrix: memoryTargetCell } : {}),
|
|
2152
|
+
...(publishedCandidate !== null && publishedCandidate.runId === settledRunId
|
|
2153
|
+
? { candidatePublication: publishedCandidate }
|
|
2154
|
+
: {}),
|
|
2155
|
+
remoteUrl: input.gitRemoteUrl,
|
|
2156
|
+
apiBaseUrl: effectiveApiBaseUrl,
|
|
2157
|
+
githubToken,
|
|
2158
|
+
gitCommitIdentity,
|
|
2159
|
+
fetchImpl: input.probeFetch,
|
|
2160
|
+
runtimeEnv,
|
|
2161
|
+
scrubber,
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
catch (error) {
|
|
2165
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2166
|
+
let fallbackDirectory = manifest.spec.memory.directory;
|
|
2167
|
+
try {
|
|
2168
|
+
fallbackDirectory = resolveTaskpackMemoryLocation(manifest, effectiveTaskpackPath).memoryDirectory;
|
|
2169
|
+
}
|
|
2170
|
+
catch {
|
|
2171
|
+
// keep declared directory when location resolution itself failed
|
|
2172
|
+
}
|
|
2173
|
+
memorySummary = Object.freeze({
|
|
2174
|
+
status: 'failed',
|
|
2175
|
+
directory: fallbackDirectory,
|
|
2176
|
+
proposalId: null,
|
|
2177
|
+
entryCount: 0,
|
|
2178
|
+
rebased: false,
|
|
2179
|
+
branchName: null,
|
|
2180
|
+
pullRequestUrl: null,
|
|
2181
|
+
pullRequestNumber: null,
|
|
2182
|
+
reason: scrubber.scrub(message),
|
|
2183
|
+
});
|
|
2184
|
+
}
|
|
2185
|
+
emitProgress?.(`memory: ${memorySummary.status} (${memorySummary.entryCount} entries`
|
|
2186
|
+
+ `${memorySummary.pullRequestUrl ? `, pr=${memorySummary.pullRequestUrl}` : ''}`
|
|
2187
|
+
+ `${memorySummary.reason ? ` — ${memorySummary.reason}` : ''})`);
|
|
2188
|
+
}
|
|
2189
|
+
input.onTurnkeyReport?.({
|
|
2190
|
+
manifest,
|
|
2191
|
+
scrubber,
|
|
2192
|
+
...(memorySummary !== undefined ? { memory: memorySummary } : {}),
|
|
2193
|
+
report: {
|
|
2194
|
+
runId: settledRunId,
|
|
2195
|
+
status: lastTurnkeySummary?.status ?? (lastOutcome.ok ? 'passed' : 'failed'),
|
|
2196
|
+
reasonCode: lastTurnkeySummary?.reasonCode ?? null,
|
|
2197
|
+
detail: !lastOutcome.ok ? (lastTurnkeySummary?.detail ?? lastOutcome.detail) : null,
|
|
2198
|
+
discovery: intake.kind === 'discover'
|
|
2199
|
+
? { disposition: intake.disposition, ...(intake.disposition === 'ready' ? { updatesCount: intake.updates.length } : {}) }
|
|
2200
|
+
: null,
|
|
2201
|
+
checks: lastTurnkeySummary?.checks,
|
|
2202
|
+
model: {
|
|
2203
|
+
provider: activeCandidate.selection.provider,
|
|
2204
|
+
model: activeCandidate.selection.model,
|
|
2205
|
+
thinking: activeCandidate.selection.thinking ?? null,
|
|
2206
|
+
contextWindow: activeContextWindow,
|
|
2207
|
+
tokenRotations: attemptSeq,
|
|
2208
|
+
},
|
|
2209
|
+
...(reportMcpServers !== undefined && reportMcpServers.length > 0 ? { mcpServers: reportMcpServers } : {}),
|
|
2210
|
+
usage: lastTurnkeySummary?.usage ?? null,
|
|
2211
|
+
elapsedMs: lastTurnkeySummary?.elapsedMs ?? null,
|
|
2212
|
+
externalUrl: lastTurnkeySummary?.externalUrl ?? null,
|
|
2213
|
+
...(lastTurnkeySummary?.runEval !== undefined && lastTurnkeySummary.runEval !== null
|
|
2214
|
+
? { runEval: lastTurnkeySummary.runEval }
|
|
2215
|
+
: {}),
|
|
2216
|
+
scrub: text => scrubber.scrub(text),
|
|
2217
|
+
},
|
|
2218
|
+
});
|
|
2219
|
+
return {
|
|
2220
|
+
kind: 'compiled',
|
|
2221
|
+
manifest,
|
|
2222
|
+
intake,
|
|
2223
|
+
taskpack: activeTaskpack,
|
|
2224
|
+
delegateOutcome: { ok: lastOutcome.ok, detail: scrubber.scrub(lastOutcome.detail) },
|
|
2225
|
+
...(memorySummary !== undefined ? { memory: memorySummary } : {}),
|
|
2226
|
+
};
|
|
2227
|
+
}
|
|
2228
|
+
finally {
|
|
2229
|
+
await mcpRegistry?.close().catch(() => undefined);
|
|
2230
|
+
await localGateServer?.close().catch(() => undefined);
|
|
2231
|
+
await publisherServer?.close().catch(() => undefined);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
finally {
|
|
2235
|
+
await preflightResult?.cleanup().catch(() => undefined);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
function eventNameIsTrigger(eventName) {
|
|
2239
|
+
return eventName === 'schedule' || eventName === 'workflow_dispatch' || eventName === 'repository_dispatch' || eventName === 'release';
|
|
2240
|
+
}
|
|
2241
|
+
/** Minimal GitHub Actions CLI shim: map INPUT_* environment variables and run the entrypoint. */
|
|
2242
|
+
export async function runActionCli(env = process.env, options) {
|
|
2243
|
+
const repositoryRoot = env['GITHUB_WORKSPACE'] ?? process.cwd();
|
|
2244
|
+
const eventPath = env['INPUT_EVENT-PATH'];
|
|
2245
|
+
let eventPayload;
|
|
2246
|
+
if (eventPath !== undefined && eventPath.length > 0 && isAbsolute(eventPath)) {
|
|
2247
|
+
try {
|
|
2248
|
+
const descriptor = openSync(eventPath, 'r');
|
|
2249
|
+
const raw = readFileSync(descriptor, 'utf8');
|
|
2250
|
+
closeSync(descriptor);
|
|
2251
|
+
eventPayload = raw.trim().length > 0 ? JSON.parse(raw) : undefined;
|
|
2252
|
+
}
|
|
2253
|
+
catch {
|
|
2254
|
+
eventPayload = undefined;
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
const thinking = env['INPUT_THINKING']?.trim();
|
|
2258
|
+
const api = env['INPUT_API']?.trim();
|
|
2259
|
+
const storageProfile = env['INPUT_STORAGE-PROFILE'];
|
|
2260
|
+
const mode = env['INPUT_MODE'];
|
|
2261
|
+
const gateEndpointUrl = env['INPUT_GATE-ENDPOINT-URL']?.trim();
|
|
2262
|
+
const explicitGateEndpointId = env['INPUT_GATE-ENDPOINT-ID']?.trim() || env['LOOPWRIGHT_GATE_ENDPOINT_ID']?.trim();
|
|
2263
|
+
const gateEndpointId = explicitGateEndpointId || 'default';
|
|
2264
|
+
const gateEndpointImplRaw = env['INPUT_GATE-ENDPOINT-IMPLEMENTATION']?.trim() || env['LOOPWRIGHT_GATE_ENDPOINT_IMPLEMENTATION']?.trim();
|
|
2265
|
+
let gateEndpointImpl;
|
|
2266
|
+
if (gateEndpointImplRaw !== undefined && gateEndpointImplRaw.length > 0) {
|
|
2267
|
+
if (gateEndpointImplRaw !== 'gate.v1' && gateEndpointImplRaw !== 'benchmark-gate.v1') {
|
|
2268
|
+
process.stderr.write(`invalid gate endpoint implementation "${gateEndpointImplRaw}" (expected "gate.v1" or "benchmark-gate.v1")\n`);
|
|
2269
|
+
return 1;
|
|
2270
|
+
}
|
|
2271
|
+
gateEndpointImpl = gateEndpointImplRaw;
|
|
2272
|
+
}
|
|
2273
|
+
if ((gateEndpointImpl !== undefined || (explicitGateEndpointId !== undefined && explicitGateEndpointId.length > 0)) && !gateEndpointUrl) {
|
|
2274
|
+
process.stderr.write('explicit gate endpoint designation requires INPUT_GATE-ENDPOINT-URL\n');
|
|
2275
|
+
return 1;
|
|
2276
|
+
}
|
|
2277
|
+
const hasGateAuthToken = typeof env['LOOPWRIGHT_GATE_AUTH_TOKEN'] === 'string' && env['LOOPWRIGHT_GATE_AUTH_TOKEN'].trim().length > 0;
|
|
2278
|
+
const publicationEndpointUrl = env['INPUT_PUBLICATION-ENDPOINT-URL']?.trim();
|
|
2279
|
+
const dryRun = env['INPUT_DRY-RUN'] === 'true';
|
|
2280
|
+
const force = env['INPUT_FORCE'] === 'true';
|
|
2281
|
+
const inputRunId = env['INPUT_RUN-ID']?.trim() || env['GITHUB_RUN_ID'] || 'local';
|
|
2282
|
+
const inputOutput = env['INPUT_OUTPUT']?.trim() || undefined;
|
|
2283
|
+
const sourceRevision = env['INPUT_SOURCE-REVISION']?.trim() || undefined;
|
|
2284
|
+
const prevalidatedInputFormats = inputOutput !== undefined
|
|
2285
|
+
? resolveActionOutputFormats(inputOutput, undefined)
|
|
2286
|
+
: undefined;
|
|
2287
|
+
let capturedReport;
|
|
2288
|
+
const result = await runGitHubActionEntrypoint({
|
|
2289
|
+
repositoryRoot,
|
|
2290
|
+
suitePath: env['INPUT_SUITE-PATH']?.trim() || undefined,
|
|
2291
|
+
domain: env['INPUT_DOMAIN']?.trim() || undefined,
|
|
2292
|
+
taskpackPath: env['INPUT_TASKPACK-PATH']?.trim() || undefined,
|
|
2293
|
+
repositoryFullName: env['LOOPWRIGHT_REPOSITORY'] ?? env['GITHUB_REPOSITORY'] ?? basename(repositoryRoot),
|
|
2294
|
+
baseRevision: env['GITHUB_SHA'] ?? 'HEAD',
|
|
2295
|
+
sourceRevision,
|
|
2296
|
+
mode: mode === 'no-change' ? 'no-change' : mode === 'auto' ? 'auto' : 'candidate',
|
|
2297
|
+
eventName: env['INPUT_EVENT-NAME']?.trim() || env['GITHUB_EVENT_NAME'] || 'workflow_dispatch',
|
|
2298
|
+
eventPayload,
|
|
2299
|
+
runRoot: env['INPUT_RUN-ROOT']?.trim() || env['RUNNER_TEMP'] || resolve(repositoryRoot, '../.loopwright-runs'),
|
|
2300
|
+
runId: inputRunId,
|
|
2301
|
+
storageProfile: storageProfile === 'durable' ? 'durable' : 'actions-basic',
|
|
2302
|
+
provider: env['INPUT_PROVIDER']?.trim() || undefined,
|
|
2303
|
+
model: env['INPUT_MODEL']?.trim() || undefined,
|
|
2304
|
+
thinking: thinking !== undefined && PI_THINKING_LEVELS.includes(thinking) ? thinking : undefined,
|
|
2305
|
+
api: api !== undefined && PI_WIRE_APIS.includes(api) ? api : undefined,
|
|
2306
|
+
baseUrl: env['INPUT_BASE-URL']?.trim() || undefined,
|
|
2307
|
+
providerTokenEnv: env['INPUT_PROVIDER-TOKEN-ENV']?.trim() || undefined,
|
|
2308
|
+
modelsJsonPath: env['INPUT_MODELS-JSON']?.trim() || undefined,
|
|
2309
|
+
allowManifestCustomBaseUrl: env['INPUT_ALLOW-CUSTOM-BASE-URL'] === 'true',
|
|
2310
|
+
allowPrivilegedExecution: env['INPUT_ALLOW-PRIVILEGED-EXECUTION'] === 'true',
|
|
2311
|
+
allowWorkflowWrites: env['INPUT_ALLOW-WORKFLOW-WRITES'] === 'true',
|
|
2312
|
+
allowHostMounts: env['INPUT_ALLOW-HOST-MOUNTS']?.trim() || undefined,
|
|
2313
|
+
gateEndpoints: gateEndpointUrl
|
|
2314
|
+
? [{
|
|
2315
|
+
id: gateEndpointId,
|
|
2316
|
+
url: gateEndpointUrl,
|
|
2317
|
+
signingCredentialRef: 'taskpack-gate-signing',
|
|
2318
|
+
...(hasGateAuthToken ? { authCredentialRef: 'taskpack-gate-auth' } : {}),
|
|
2319
|
+
...(gateEndpointImpl !== undefined ? { implementation: gateEndpointImpl } : {}),
|
|
2320
|
+
}]
|
|
2321
|
+
: undefined,
|
|
2322
|
+
publicationEndpoint: publicationEndpointUrl ? { id: 'default', url: publicationEndpointUrl, signingCredentialRef: 'taskpack-publication-signing' } : undefined,
|
|
2323
|
+
operatorAllowlist: env['LOOPWRIGHT_OPERATOR_ALLOWLIST']?.split(',').filter(entry => entry.length > 0),
|
|
2324
|
+
env,
|
|
2325
|
+
dryRun,
|
|
2326
|
+
force,
|
|
2327
|
+
turnkey: !dryRun,
|
|
2328
|
+
githubApiBaseUrl: env['GITHUB_API_URL']?.trim() || undefined,
|
|
2329
|
+
githubToken: env['INPUT_GITHUB-TOKEN']?.trim() || undefined,
|
|
2330
|
+
githubAppId: env['INPUT_GITHUB-APP-ID']?.trim() || undefined,
|
|
2331
|
+
githubAppPrivateKey: env['INPUT_GITHUB-APP-PRIVATE-KEY']?.trim() || undefined,
|
|
2332
|
+
githubAppInstallationId: env['INPUT_GITHUB-APP-INSTALLATION-ID']?.trim() || undefined,
|
|
2333
|
+
gitAuthorName: env['INPUT_GIT-AUTHOR-NAME'] || undefined,
|
|
2334
|
+
gitAuthorEmail: env['INPUT_GIT-AUTHOR-EMAIL'] || undefined,
|
|
2335
|
+
upstreamRecordsJson: env['INPUT_UPSTREAM-RECORDS']?.trim() || undefined,
|
|
2336
|
+
mcpServersJson: env['INPUT_MCP-SERVERS']?.trim() || env['LOOPWRIGHT_MCP_SERVERS']?.trim() || undefined,
|
|
2337
|
+
gitRemoteUrl: env['INPUT_REMOTE-URL']?.trim() || undefined,
|
|
2338
|
+
output: inputOutput,
|
|
2339
|
+
progressSink: !dryRun
|
|
2340
|
+
? (line => {
|
|
2341
|
+
process.stderr.write(`[loopwright] ${line}\n`);
|
|
2342
|
+
})
|
|
2343
|
+
: undefined,
|
|
2344
|
+
onTurnkeyReport: info => {
|
|
2345
|
+
capturedReport = info;
|
|
2346
|
+
},
|
|
2347
|
+
...(options?.openHostSessionAdapter !== undefined
|
|
2348
|
+
? { openHostSessionAdapter: options.openHostSessionAdapter }
|
|
2349
|
+
: {}),
|
|
2350
|
+
});
|
|
2351
|
+
const fallbackScrubber = capturedReport?.scrubber ?? new SecretScrubber();
|
|
2352
|
+
for (const key of [
|
|
2353
|
+
'INPUT_GITHUB-TOKEN',
|
|
2354
|
+
'GITHUB_TOKEN',
|
|
2355
|
+
'INPUT_GITHUB-APP-PRIVATE-KEY',
|
|
2356
|
+
'LOOPWRIGHT_GATE_SIGNING_SECRET',
|
|
2357
|
+
'LOOPWRIGHT_GATE_AUTH_TOKEN',
|
|
2358
|
+
'LOOPWRIGHT_PUBLICATION_SIGNING_SECRET',
|
|
2359
|
+
'LOOPWRIGHT_PUBLICATION_AUTH_TOKEN',
|
|
2360
|
+
]) {
|
|
2361
|
+
const val = env[key];
|
|
2362
|
+
if (typeof val === 'string' && val.length > 0)
|
|
2363
|
+
fallbackScrubber.register(val);
|
|
2364
|
+
}
|
|
2365
|
+
const serialized = serializeActionResultSummary(result, fallbackScrubber);
|
|
2366
|
+
process.stdout.write(`${serialized}\n`);
|
|
2367
|
+
const manifest = capturedReport?.manifest ?? (result.kind === 'compiled' ? result.manifest : null);
|
|
2368
|
+
const formats = prevalidatedInputFormats ?? resolveActionOutputFormats(undefined, manifest);
|
|
2369
|
+
const suiteOnly = isSuiteActionResult(result);
|
|
2370
|
+
const report = capturedReport?.report ?? {
|
|
2371
|
+
runId: normalizeControllerRunId(inputRunId),
|
|
2372
|
+
status: isSuiteActionResult(result)
|
|
2373
|
+
? result.kind
|
|
2374
|
+
: result.kind === 'no_change'
|
|
2375
|
+
? (result.delegateOutcome?.ok === false ? 'failed' : 'no_change')
|
|
2376
|
+
: result.kind === 'blocked'
|
|
2377
|
+
? 'blocked'
|
|
2378
|
+
: result.kind === 'refused'
|
|
2379
|
+
? 'refused'
|
|
2380
|
+
: (result.delegateOutcome?.ok === false ? 'failed' : 'passed'),
|
|
2381
|
+
reasonCode: result.kind === 'refused'
|
|
2382
|
+
? result.code
|
|
2383
|
+
: result.kind === 'blocked'
|
|
2384
|
+
? result.reason
|
|
2385
|
+
: isSuiteActionResult(result)
|
|
2386
|
+
? result.reason
|
|
2387
|
+
: null,
|
|
2388
|
+
detail: result.kind === 'refused'
|
|
2389
|
+
? result.reason
|
|
2390
|
+
: result.kind === 'blocked'
|
|
2391
|
+
? (result.detail ?? null)
|
|
2392
|
+
: isSuiteActionResult(result)
|
|
2393
|
+
? (result.detail ?? result.reason)
|
|
2394
|
+
: result.kind === 'no_change'
|
|
2395
|
+
? (result.delegateOutcome?.ok === false ? result.delegateOutcome.detail : result.reason)
|
|
2396
|
+
: (result.delegateOutcome?.ok === false ? result.delegateOutcome.detail : null),
|
|
2397
|
+
scrub: text => fallbackScrubber.scrub(text),
|
|
2398
|
+
};
|
|
2399
|
+
const memorySummary = capturedReport?.memory ?? (result.kind === 'compiled' ? result.memory : undefined);
|
|
2400
|
+
await writeActionOutputSinks({
|
|
2401
|
+
formats,
|
|
2402
|
+
report,
|
|
2403
|
+
memory: memorySummary,
|
|
2404
|
+
stepSummaryPath: env['GITHUB_STEP_SUMMARY'],
|
|
2405
|
+
githubOutputPath: env['GITHUB_OUTPUT'],
|
|
2406
|
+
actionResultJson: serialized,
|
|
2407
|
+
scrubber: fallbackScrubber,
|
|
2408
|
+
includeExtendedGithubOutputs: !dryRun || inputOutput !== undefined,
|
|
2409
|
+
alwaysLogTextSummary: !dryRun,
|
|
2410
|
+
});
|
|
2411
|
+
const executionSucceeded = suiteOnly
|
|
2412
|
+
|| (result.kind === 'no_change'
|
|
2413
|
+
&& (result.delegateOutcome === undefined || result.delegateOutcome === null || result.delegateOutcome.ok))
|
|
2414
|
+
|| (result.kind === 'compiled' && (result.delegateOutcome === null || result.delegateOutcome.ok));
|
|
2415
|
+
return executionSucceeded ? 0 : 1;
|
|
2416
|
+
}
|
|
2417
|
+
const invokedDirectly = process.argv[1] !== undefined && (() => {
|
|
2418
|
+
try {
|
|
2419
|
+
return resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
2420
|
+
}
|
|
2421
|
+
catch {
|
|
2422
|
+
return false;
|
|
2423
|
+
}
|
|
2424
|
+
})();
|
|
2425
|
+
if (invokedDirectly) {
|
|
2426
|
+
void runActionCli().then(code => {
|
|
2427
|
+
process.exitCode = code;
|
|
2428
|
+
});
|
|
2429
|
+
}
|