@gpustack/loopwright 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +356 -2
- package/bin/loopwright.js +3 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter-v2.js +122 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.d.ts +30 -0
- package/node_modules/@loopwright/agent-pi/dist/adapter.js +340 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/admission.js +65 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/artifacts.js +76 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/boundary.js +113 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.d.ts +4 -0
- package/node_modules/@loopwright/agent-pi/dist/broker-channel.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.d.ts +96 -0
- package/node_modules/@loopwright/agent-pi/dist/candidate.js +1712 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/capture.js +146 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/cas.js +836 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog-api.js +2 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/catalog.js +280 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.js +12 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.d.ts +29 -0
- package/node_modules/@loopwright/agent-pi/dist/containers.js +160 -0
- package/node_modules/@loopwright/agent-pi/dist/context.d.ts +56 -0
- package/node_modules/@loopwright/agent-pi/dist/context.js +351 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.d.ts +8 -0
- package/node_modules/@loopwright/agent-pi/dist/daemon.js +52 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/deadline.js +18 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.d.ts +39 -0
- package/node_modules/@loopwright/agent-pi/dist/decode-capture.js +287 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.d.ts +12 -0
- package/node_modules/@loopwright/agent-pi/dist/descriptor.js +17 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/docker-absence.js +9 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/errors.js +19 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/event-sequence.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/events.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/events.js +132 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.d.ts +9 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-guard.js +25 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.d.ts +24 -0
- package/node_modules/@loopwright/agent-pi/dist/execution-lease.js +316 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/execution.js +476 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.d.ts +87 -0
- package/node_modules/@loopwright/agent-pi/dist/external-mcp.js +526 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.d.ts +15 -0
- package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.js +74 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.d.ts +51 -0
- package/node_modules/@loopwright/agent-pi/dist/host-session.js +2083 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/http-mcp.js +353 -0
- package/node_modules/@loopwright/agent-pi/dist/index.d.ts +7 -0
- package/node_modules/@loopwright/agent-pi/dist/index.js +4 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/lifecycle.js +11 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.d.ts +35 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-process.js +92 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.d.ts +25 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp-transport.js +63 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.d.ts +23 -0
- package/node_modules/@loopwright/agent-pi/dist/mcp.js +212 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.d.ts +5 -0
- package/node_modules/@loopwright/agent-pi/dist/operation.js +28 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.d.ts +10 -0
- package/node_modules/@loopwright/agent-pi/dist/policy-v2.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/policy.js +260 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.d.ts +60 -0
- package/node_modules/@loopwright/agent-pi/dist/preflight.js +700 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.d.ts +1 -0
- package/node_modules/@loopwright/agent-pi/dist/progress-summary.js +119 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.d.ts +17 -0
- package/node_modules/@loopwright/agent-pi/dist/protocol.js +131 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.d.ts +62 -0
- package/node_modules/@loopwright/agent-pi/dist/provider.js +217 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.d.ts +3 -0
- package/node_modules/@loopwright/agent-pi/dist/receipt.js +64 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/recovery.js +188 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.d.ts +13 -0
- package/node_modules/@loopwright/agent-pi/dist/resources.js +81 -0
- package/node_modules/@loopwright/agent-pi/dist/response.d.ts +20 -0
- package/node_modules/@loopwright/agent-pi/dist/response.js +259 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.d.ts +6 -0
- package/node_modules/@loopwright/agent-pi/dist/runtime-profile.js +37 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/sdk-worker.js +633 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.d.ts +46 -0
- package/node_modules/@loopwright/agent-pi/dist/sender.js +553 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.d.ts +21 -0
- package/node_modules/@loopwright/agent-pi/dist/session-host.js +315 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.d.ts +14 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.js +102 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.d.ts +19 -0
- package/node_modules/@loopwright/agent-pi/dist/snapshot.js +121 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.d.ts +32 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-process.js +85 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.d.ts +2 -0
- package/node_modules/@loopwright/agent-pi/dist/tool-worker.js +105 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.d.ts +36 -0
- package/node_modules/@loopwright/agent-pi/dist/tools.js +128 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.d.ts +71 -0
- package/node_modules/@loopwright/agent-pi/dist/types-v2.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/types.d.ts +314 -0
- package/node_modules/@loopwright/agent-pi/dist/types.js +1 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.d.ts +18 -0
- package/node_modules/@loopwright/agent-pi/dist/usage.js +314 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.d.ts +27 -0
- package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.js +142 -0
- package/node_modules/@loopwright/agent-pi/package.json +24 -0
- package/node_modules/@loopwright/agent-pi/runtime/Dockerfile +8 -0
- package/node_modules/@loopwright/agent-pi/runtime/seccomp.json +1 -0
- package/node_modules/@loopwright/cli/dist/arguments.d.ts +19 -0
- package/node_modules/@loopwright/cli/dist/arguments.js +358 -0
- package/node_modules/@loopwright/cli/dist/closure.d.ts +93 -0
- package/node_modules/@loopwright/cli/dist/closure.js +230 -0
- package/node_modules/@loopwright/cli/dist/draft.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/draft.js +106 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.d.ts +9 -0
- package/node_modules/@loopwright/cli/dist/failure-matrix.js +701 -0
- package/node_modules/@loopwright/cli/dist/index.d.ts +6 -0
- package/node_modules/@loopwright/cli/dist/index.js +5 -0
- package/node_modules/@loopwright/cli/dist/main.d.ts +22 -0
- package/node_modules/@loopwright/cli/dist/main.js +1855 -0
- package/node_modules/@loopwright/cli/package.json +16 -0
- package/node_modules/@loopwright/controller/dist/acceptance.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/acceptance.js +446 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.d.ts +273 -0
- package/node_modules/@loopwright/controller/dist/benchmark-gate.js +3147 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/budget-observations.js +139 -0
- package/node_modules/@loopwright/controller/dist/bundle.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/bundle.js +64 -0
- package/node_modules/@loopwright/controller/dist/capture.d.ts +89 -0
- package/node_modules/@loopwright/controller/dist/capture.js +587 -0
- package/node_modules/@loopwright/controller/dist/compile.d.ts +3 -0
- package/node_modules/@loopwright/controller/dist/compile.js +402 -0
- package/node_modules/@loopwright/controller/dist/config.d.ts +22 -0
- package/node_modules/@loopwright/controller/dist/config.js +255 -0
- package/node_modules/@loopwright/controller/dist/controller.d.ts +177 -0
- package/node_modules/@loopwright/controller/dist/controller.js +2135 -0
- package/node_modules/@loopwright/controller/dist/credentials.d.ts +29 -0
- package/node_modules/@loopwright/controller/dist/credentials.js +189 -0
- package/node_modules/@loopwright/controller/dist/deadlines.d.ts +18 -0
- package/node_modules/@loopwright/controller/dist/deadlines.js +71 -0
- package/node_modules/@loopwright/controller/dist/errors.d.ts +27 -0
- package/node_modules/@loopwright/controller/dist/errors.js +41 -0
- package/node_modules/@loopwright/controller/dist/events.d.ts +52 -0
- package/node_modules/@loopwright/controller/dist/events.js +228 -0
- package/node_modules/@loopwright/controller/dist/files.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/files.js +386 -0
- package/node_modules/@loopwright/controller/dist/finalize.d.ts +25 -0
- package/node_modules/@loopwright/controller/dist/finalize.js +32 -0
- package/node_modules/@loopwright/controller/dist/gate.d.ts +84 -0
- package/node_modules/@loopwright/controller/dist/gate.js +640 -0
- package/node_modules/@loopwright/controller/dist/git-objects.d.ts +11 -0
- package/node_modules/@loopwright/controller/dist/git-objects.js +59 -0
- package/node_modules/@loopwright/controller/dist/git-reader.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/git-reader.js +40 -0
- package/node_modules/@loopwright/controller/dist/handlers.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/handlers.js +45 -0
- package/node_modules/@loopwright/controller/dist/handoff.d.ts +71 -0
- package/node_modules/@loopwright/controller/dist/handoff.js +554 -0
- package/node_modules/@loopwright/controller/dist/index.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/index.js +21 -0
- package/node_modules/@loopwright/controller/dist/inspect.d.ts +30 -0
- package/node_modules/@loopwright/controller/dist/inspect.js +372 -0
- package/node_modules/@loopwright/controller/dist/interpolation.d.ts +9 -0
- package/node_modules/@loopwright/controller/dist/interpolation.js +79 -0
- package/node_modules/@loopwright/controller/dist/ownership.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/ownership.js +666 -0
- package/node_modules/@loopwright/controller/dist/parser.d.ts +5 -0
- package/node_modules/@loopwright/controller/dist/parser.js +200 -0
- package/node_modules/@loopwright/controller/dist/progress.d.ts +41 -0
- package/node_modules/@loopwright/controller/dist/progress.js +904 -0
- package/node_modules/@loopwright/controller/dist/publication.d.ts +60 -0
- package/node_modules/@loopwright/controller/dist/publication.js +329 -0
- package/node_modules/@loopwright/controller/dist/reconcile.d.ts +26 -0
- package/node_modules/@loopwright/controller/dist/reconcile.js +1378 -0
- package/node_modules/@loopwright/controller/dist/recovery.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/recovery.js +315 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.d.ts +43 -0
- package/node_modules/@loopwright/controller/dist/refusal-record.js +150 -0
- package/node_modules/@loopwright/controller/dist/registry.d.ts +6 -0
- package/node_modules/@loopwright/controller/dist/registry.js +374 -0
- package/node_modules/@loopwright/controller/dist/repair.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/repair.js +102 -0
- package/node_modules/@loopwright/controller/dist/report.d.ts +64 -0
- package/node_modules/@loopwright/controller/dist/report.js +596 -0
- package/node_modules/@loopwright/controller/dist/retained.d.ts +284 -0
- package/node_modules/@loopwright/controller/dist/retained.js +193 -0
- package/node_modules/@loopwright/controller/dist/rules.d.ts +31 -0
- package/node_modules/@loopwright/controller/dist/rules.js +110 -0
- package/node_modules/@loopwright/controller/dist/run-eval.d.ts +115 -0
- package/node_modules/@loopwright/controller/dist/run-eval.js +959 -0
- package/node_modules/@loopwright/controller/dist/scheduler.d.ts +10 -0
- package/node_modules/@loopwright/controller/dist/scheduler.js +41 -0
- package/node_modules/@loopwright/controller/dist/schema.d.ts +17 -0
- package/node_modules/@loopwright/controller/dist/schema.js +78 -0
- package/node_modules/@loopwright/controller/dist/source.d.ts +69 -0
- package/node_modules/@loopwright/controller/dist/source.js +872 -0
- package/node_modules/@loopwright/controller/dist/step.d.ts +38 -0
- package/node_modules/@loopwright/controller/dist/step.js +1776 -0
- package/node_modules/@loopwright/controller/dist/storage.d.ts +90 -0
- package/node_modules/@loopwright/controller/dist/storage.js +1345 -0
- package/node_modules/@loopwright/controller/dist/submission.d.ts +51 -0
- package/node_modules/@loopwright/controller/dist/submission.js +292 -0
- package/node_modules/@loopwright/controller/dist/types.d.ts +585 -0
- package/node_modules/@loopwright/controller/dist/types.js +9 -0
- package/node_modules/@loopwright/controller/dist/verification.d.ts +124 -0
- package/node_modules/@loopwright/controller/dist/verification.js +1308 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.d.ts +105 -0
- package/node_modules/@loopwright/controller/dist/verifier-protocol.js +1312 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.d.ts +1 -0
- package/node_modules/@loopwright/controller/dist/verifier-worker.js +33 -0
- package/node_modules/@loopwright/controller/package.json +12 -0
- package/node_modules/@loopwright/core/dist/acceptance.d.ts +108 -0
- package/node_modules/@loopwright/core/dist/acceptance.js +327 -0
- package/node_modules/@loopwright/core/dist/artifacts.d.ts +63 -0
- package/node_modules/@loopwright/core/dist/artifacts.js +356 -0
- package/node_modules/@loopwright/core/dist/boundary.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/boundary.js +484 -0
- package/node_modules/@loopwright/core/dist/contracts.d.ts +287 -0
- package/node_modules/@loopwright/core/dist/contracts.js +694 -0
- package/node_modules/@loopwright/core/dist/diagnostics.d.ts +21 -0
- package/node_modules/@loopwright/core/dist/diagnostics.js +51 -0
- package/node_modules/@loopwright/core/dist/evidence.d.ts +92 -0
- package/node_modules/@loopwright/core/dist/evidence.js +85 -0
- package/node_modules/@loopwright/core/dist/graph.d.ts +8 -0
- package/node_modules/@loopwright/core/dist/graph.js +44 -0
- package/node_modules/@loopwright/core/dist/identity.d.ts +162 -0
- package/node_modules/@loopwright/core/dist/identity.js +80 -0
- package/node_modules/@loopwright/core/dist/index.d.ts +30 -0
- package/node_modules/@loopwright/core/dist/index.js +39 -0
- package/node_modules/@loopwright/core/dist/limits.d.ts +99 -0
- package/node_modules/@loopwright/core/dist/limits.js +59 -0
- package/node_modules/@loopwright/core/dist/results.d.ts +161 -0
- package/node_modules/@loopwright/core/dist/results.js +98 -0
- package/node_modules/@loopwright/core/dist/scope.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scope.js +154 -0
- package/node_modules/@loopwright/core/dist/scrubber.d.ts +13 -0
- package/node_modules/@loopwright/core/dist/scrubber.js +63 -0
- package/node_modules/@loopwright/core/dist/usage.d.ts +68 -0
- package/node_modules/@loopwright/core/dist/usage.js +56 -0
- package/node_modules/@loopwright/core/package.json +12 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/benchmark.js +337 -0
- package/node_modules/@loopwright/decisions/dist/client.d.ts +74 -0
- package/node_modules/@loopwright/decisions/dist/client.js +292 -0
- package/node_modules/@loopwright/decisions/dist/index.d.ts +15 -0
- package/node_modules/@loopwright/decisions/dist/index.js +8 -0
- package/node_modules/@loopwright/decisions/dist/nodes.d.ts +63 -0
- package/node_modules/@loopwright/decisions/dist/nodes.js +282 -0
- package/node_modules/@loopwright/decisions/dist/primitives.d.ts +36 -0
- package/node_modules/@loopwright/decisions/dist/primitives.js +300 -0
- package/node_modules/@loopwright/decisions/dist/redaction.d.ts +23 -0
- package/node_modules/@loopwright/decisions/dist/redaction.js +146 -0
- package/node_modules/@loopwright/decisions/dist/router.d.ts +55 -0
- package/node_modules/@loopwright/decisions/dist/router.js +248 -0
- package/node_modules/@loopwright/decisions/dist/schema.d.ts +25 -0
- package/node_modules/@loopwright/decisions/dist/schema.js +536 -0
- package/node_modules/@loopwright/decisions/dist/types.d.ts +394 -0
- package/node_modules/@loopwright/decisions/dist/types.js +80 -0
- package/node_modules/@loopwright/decisions/package.json +12 -0
- package/node_modules/@loopwright/github-app/dist/action.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/action.js +2429 -0
- package/node_modules/@loopwright/github-app/dist/config.d.ts +23 -0
- package/node_modules/@loopwright/github-app/dist/config.js +297 -0
- package/node_modules/@loopwright/github-app/dist/digests.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/digests.js +1 -0
- package/node_modules/@loopwright/github-app/dist/index.d.ts +14 -0
- package/node_modules/@loopwright/github-app/dist/index.js +13 -0
- package/node_modules/@loopwright/github-app/dist/models-config.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/models-config.js +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/output-format.js +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/preflight.js +1 -0
- package/node_modules/@loopwright/github-app/dist/publisher.d.ts +58 -0
- package/node_modules/@loopwright/github-app/dist/publisher.js +1368 -0
- package/node_modules/@loopwright/github-app/dist/qualification.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/qualification.js +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/sandbox.js +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/schema.js +1 -0
- package/node_modules/@loopwright/github-app/dist/service.d.ts +52 -0
- package/node_modules/@loopwright/github-app/dist/service.js +1658 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.d.ts +90 -0
- package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.js +392 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/taskpack.js +1 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.d.ts +44 -0
- package/node_modules/@loopwright/github-app/dist/tenant-queue.js +423 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.d.ts +50 -0
- package/node_modules/@loopwright/github-app/dist/token-broker.js +262 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.d.ts +35 -0
- package/node_modules/@loopwright/github-app/dist/turnkey-memory.js +1654 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.d.ts +16 -0
- package/node_modules/@loopwright/github-app/dist/turnkey.js +34 -0
- package/node_modules/@loopwright/github-app/dist/types.d.ts +220 -0
- package/node_modules/@loopwright/github-app/dist/types.js +14 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.d.ts +13 -0
- package/node_modules/@loopwright/github-app/dist/upstreams.js +65 -0
- package/node_modules/@loopwright/github-app/dist/webhook.d.ts +34 -0
- package/node_modules/@loopwright/github-app/dist/webhook.js +241 -0
- package/node_modules/@loopwright/github-app/dist/yaml.d.ts +1 -0
- package/node_modules/@loopwright/github-app/dist/yaml.js +1 -0
- package/node_modules/@loopwright/github-app/package.json +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.d.ts +48 -0
- package/node_modules/@loopwright/hardware-runner/dist/config.js +719 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.d.ts +230 -0
- package/node_modules/@loopwright/hardware-runner/dist/evaluator.js +3178 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/index.js +9 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.d.ts +128 -0
- package/node_modules/@loopwright/hardware-runner/dist/provenance.js +1500 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.d.ts +81 -0
- package/node_modules/@loopwright/hardware-runner/dist/queue.js +1081 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.d.ts +13 -0
- package/node_modules/@loopwright/hardware-runner/dist/relay-server.js +2997 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.d.ts +239 -0
- package/node_modules/@loopwright/hardware-runner/dist/types.js +12 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.d.ts +49 -0
- package/node_modules/@loopwright/hardware-runner/dist/worker.js +1646 -0
- package/node_modules/@loopwright/hardware-runner/package.json +12 -0
- package/node_modules/@loopwright/memory/dist/cas.d.ts +21 -0
- package/node_modules/@loopwright/memory/dist/cas.js +510 -0
- package/node_modules/@loopwright/memory/dist/compaction.d.ts +18 -0
- package/node_modules/@loopwright/memory/dist/compaction.js +110 -0
- package/node_modules/@loopwright/memory/dist/finalizer.d.ts +23 -0
- package/node_modules/@loopwright/memory/dist/finalizer.js +538 -0
- package/node_modules/@loopwright/memory/dist/index.d.ts +9 -0
- package/node_modules/@loopwright/memory/dist/index.js +8 -0
- package/node_modules/@loopwright/memory/dist/schema.d.ts +36 -0
- package/node_modules/@loopwright/memory/dist/schema.js +510 -0
- package/node_modules/@loopwright/memory/dist/selector.d.ts +7 -0
- package/node_modules/@loopwright/memory/dist/selector.js +157 -0
- package/node_modules/@loopwright/memory/dist/store.d.ts +51 -0
- package/node_modules/@loopwright/memory/dist/store.js +554 -0
- package/node_modules/@loopwright/memory/dist/types.d.ts +442 -0
- package/node_modules/@loopwright/memory/dist/types.js +8 -0
- package/node_modules/@loopwright/memory/dist/verifier.d.ts +5 -0
- package/node_modules/@loopwright/memory/dist/verifier.js +328 -0
- package/node_modules/@loopwright/memory/package.json +12 -0
- package/node_modules/@loopwright/state/dist/admission.d.ts +321 -0
- package/node_modules/@loopwright/state/dist/admission.js +199 -0
- package/node_modules/@loopwright/state/dist/boundary.d.ts +53 -0
- package/node_modules/@loopwright/state/dist/boundary.js +194 -0
- package/node_modules/@loopwright/state/dist/checkpoint.d.ts +16 -0
- package/node_modules/@loopwright/state/dist/checkpoint.js +84 -0
- package/node_modules/@loopwright/state/dist/clock.d.ts +8 -0
- package/node_modules/@loopwright/state/dist/clock.js +27 -0
- package/node_modules/@loopwright/state/dist/connection.d.ts +55 -0
- package/node_modules/@loopwright/state/dist/connection.js +391 -0
- package/node_modules/@loopwright/state/dist/errors.d.ts +13 -0
- package/node_modules/@loopwright/state/dist/errors.js +34 -0
- package/node_modules/@loopwright/state/dist/index.d.ts +3 -0
- package/node_modules/@loopwright/state/dist/index.js +1 -0
- package/node_modules/@loopwright/state/dist/journal.d.ts +119 -0
- package/node_modules/@loopwright/state/dist/journal.js +72 -0
- package/node_modules/@loopwright/state/dist/model.d.ts +40 -0
- package/node_modules/@loopwright/state/dist/model.js +58 -0
- package/node_modules/@loopwright/state/dist/ownership.d.ts +14 -0
- package/node_modules/@loopwright/state/dist/ownership.js +45 -0
- package/node_modules/@loopwright/state/dist/pages.d.ts +11 -0
- package/node_modules/@loopwright/state/dist/pages.js +41 -0
- package/node_modules/@loopwright/state/dist/receipts.d.ts +33 -0
- package/node_modules/@loopwright/state/dist/receipts.js +97 -0
- package/node_modules/@loopwright/state/dist/schema.d.ts +28 -0
- package/node_modules/@loopwright/state/dist/schema.js +41 -0
- package/node_modules/@loopwright/state/dist/settlement.d.ts +10 -0
- package/node_modules/@loopwright/state/dist/settlement.js +129 -0
- package/node_modules/@loopwright/state/dist/store.d.ts +52 -0
- package/node_modules/@loopwright/state/dist/store.js +100 -0
- package/node_modules/@loopwright/state/dist/types.d.ts +315 -0
- package/node_modules/@loopwright/state/dist/types.js +1 -0
- package/node_modules/@loopwright/state/package.json +12 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.d.ts +195 -0
- package/node_modules/@loopwright/taskpack/dist/baseline-align.js +1847 -0
- package/node_modules/@loopwright/taskpack/dist/digests.d.ts +61 -0
- package/node_modules/@loopwright/taskpack/dist/digests.js +715 -0
- package/node_modules/@loopwright/taskpack/dist/index.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/index.js +17 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.d.ts +112 -0
- package/node_modules/@loopwright/taskpack/dist/models-config.js +1026 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.d.ts +28 -0
- package/node_modules/@loopwright/taskpack/dist/output-format.js +157 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.d.ts +130 -0
- package/node_modules/@loopwright/taskpack/dist/preflight.js +1497 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.d.ts +23 -0
- package/node_modules/@loopwright/taskpack/dist/qualification.js +120 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.d.ts +121 -0
- package/node_modules/@loopwright/taskpack/dist/sandbox.js +2605 -0
- package/node_modules/@loopwright/taskpack/dist/schema.d.ts +197 -0
- package/node_modules/@loopwright/taskpack/dist/schema.js +4189 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.d.ts +47 -0
- package/node_modules/@loopwright/taskpack/dist/scrubber.js +283 -0
- package/node_modules/@loopwright/taskpack/dist/suite.d.ts +124 -0
- package/node_modules/@loopwright/taskpack/dist/suite.js +3256 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.d.ts +154 -0
- package/node_modules/@loopwright/taskpack/dist/taskpack.js +3634 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.d.ts +122 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey-memory.js +483 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.d.ts +437 -0
- package/node_modules/@loopwright/taskpack/dist/turnkey.js +7313 -0
- package/node_modules/@loopwright/taskpack/dist/types.d.ts +1274 -0
- package/node_modules/@loopwright/taskpack/dist/types.js +99 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.d.ts +261 -0
- package/node_modules/@loopwright/taskpack/dist/upstreams.js +2242 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.d.ts +18 -0
- package/node_modules/@loopwright/taskpack/dist/yaml.js +167 -0
- package/node_modules/@loopwright/taskpack/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.d.ts +137 -0
- package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.js +474 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.d.ts +8 -0
- package/node_modules/@loopwright/taskpack-runner/dist/corpus.js +129 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.d.ts +13 -0
- package/node_modules/@loopwright/taskpack-runner/dist/index.js +7 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/intake.js +135 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.d.ts +130 -0
- package/node_modules/@loopwright/taskpack-runner/dist/parity.js +927 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.d.ts +68 -0
- package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.js +517 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.d.ts +149 -0
- package/node_modules/@loopwright/taskpack-runner/dist/service.js +1796 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.d.ts +29 -0
- package/node_modules/@loopwright/taskpack-runner/dist/types.js +11 -0
- package/node_modules/@loopwright/taskpack-runner/package.json +12 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/README.md +77 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/support-records.md +57 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/supported-runners.md +98 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/manifest.json +205 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/expand_matrix.sh +273 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/matrix.yaml +280 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/resolve_dockerfile.sh +24 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pyproject.toml +46 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/runtime_runner/runner.py.json +5270 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/discovery/legacy-support.md +86 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/github/service.py +401 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/analysis.json +95 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/ready.json +109 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_assemble.py +263 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_check_draft.py +333 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_checks.py +1099 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_discovery.py +817 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_proposal.py +658 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_publish.py +987 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_summary.py +107 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/agent.py +610 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/assemble.py +84 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/check_draft.py +94 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/checks.py +1002 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/discovery.py +789 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/model.py +557 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/progress.py +174 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/analysis.md +40 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/proposal.md +65 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/repair.md +17 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/proposal.py +903 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/publish.py +997 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/summary.py +131 -0
- package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/tool-versions.json +133 -0
- package/node_modules/package-lock.json +3021 -0
- package/package-lock.json +3021 -0
- package/package.json +52 -4
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
2
|
+
import { types } from 'node:util';
|
|
3
|
+
import { constructAdapterFromCaptured, runtimePorts } from './adapter.js';
|
|
4
|
+
import { composeCandidateStreamCheckers, createBuiltInPiStreamChecker } from './cas.js';
|
|
5
|
+
import { effectivePolicyV2, isHttpMcp } from './policy-v2.js';
|
|
6
|
+
import { object, freeze, snapshot, text } from './boundary.js';
|
|
7
|
+
import { sameIdentity, validateRuntime } from './policy.js';
|
|
8
|
+
import { snapshotOpenInputSync, validateStructuralInputWithPolicy } from './preflight.js';
|
|
9
|
+
import { HttpMcpProcess, HttpMcpFailure } from './http-mcp.js';
|
|
10
|
+
import { PiFailure, refuse } from './errors.js';
|
|
11
|
+
export async function constructAdapterV2(unownedHost, unownedInput, ports) {
|
|
12
|
+
try {
|
|
13
|
+
// Capture and snapshot ALL caller-owned input and host fields synchronously BEFORE the first await.
|
|
14
|
+
const captured = snapshotOpenInputSync(unownedInput, 2);
|
|
15
|
+
if (!unownedHost || typeof unownedHost !== 'object' || types.isProxy(unownedHost)) {
|
|
16
|
+
refuse('INPUT_INVALID', '/host');
|
|
17
|
+
}
|
|
18
|
+
const hasStreamChecker = Object.hasOwn(unownedHost, 'createCandidateStreamChecker');
|
|
19
|
+
const hostFields = [
|
|
20
|
+
'store', 'authority', 'directory', 'artifactsDirectory', 'dockerExecutable', 'dockerSocket', 'runtime', 'resolveCredential', 'resolveMcpCredential',
|
|
21
|
+
...(hasStreamChecker ? ['createCandidateStreamChecker'] : []),
|
|
22
|
+
];
|
|
23
|
+
const data = object(unownedHost, hostFields, '/host');
|
|
24
|
+
if (typeof data.resolveMcpCredential !== 'function' || typeof data.resolveCredential !== 'function')
|
|
25
|
+
throw new TypeError('Host callback');
|
|
26
|
+
if (hasStreamChecker && data.createCandidateStreamChecker !== undefined && typeof data.createCandidateStreamChecker !== 'function') {
|
|
27
|
+
throw new TypeError('Host callback');
|
|
28
|
+
}
|
|
29
|
+
const runtime = validateRuntime(snapshot(data.runtime), '/host/runtime');
|
|
30
|
+
for (const name of ['directory', 'artifactsDirectory']) {
|
|
31
|
+
if (typeof data[name] !== 'string' || /[,\r\n\0]/.test(data[name])) {
|
|
32
|
+
refuse('INPUT_INVALID', '/host/' + name);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const rawDirectory = text(data.directory, '/host/directory');
|
|
36
|
+
const rawArtifactsDirectory = text(data.artifactsDirectory, '/host/artifactsDirectory');
|
|
37
|
+
if (!isAbsolute(rawArtifactsDirectory))
|
|
38
|
+
refuse('INPUT_INVALID', '/host/artifactsDirectory');
|
|
39
|
+
const artifactsDirectory = resolve(rawArtifactsDirectory);
|
|
40
|
+
let lastFailure = null;
|
|
41
|
+
const resolvedSecrets = new Set();
|
|
42
|
+
const rawResolveCredential = data.resolveCredential.bind(unownedHost);
|
|
43
|
+
const rawResolveMcpCredential = data.resolveMcpCredential.bind(unownedHost);
|
|
44
|
+
const wrappedResolveCredential = async (binding) => {
|
|
45
|
+
if (lastFailure)
|
|
46
|
+
throw new PiFailure({ ...lastFailure, code: 'MCP_FAILED' });
|
|
47
|
+
const resolved = await rawResolveCredential(binding);
|
|
48
|
+
if (resolved && typeof resolved.bearerToken === 'string' && resolved.bearerToken.length > 0) {
|
|
49
|
+
resolvedSecrets.add(resolved.bearerToken);
|
|
50
|
+
}
|
|
51
|
+
return resolved;
|
|
52
|
+
};
|
|
53
|
+
const wrappedResolveMcpCredential = async (binding) => {
|
|
54
|
+
const resolved = await rawResolveMcpCredential(binding);
|
|
55
|
+
if (resolved && typeof resolved.bearerToken === 'string' && resolved.bearerToken.length > 0) {
|
|
56
|
+
resolvedSecrets.add(resolved.bearerToken);
|
|
57
|
+
}
|
|
58
|
+
return resolved;
|
|
59
|
+
};
|
|
60
|
+
const rawStreamChecker = typeof data.createCandidateStreamChecker === 'function'
|
|
61
|
+
? data.createCandidateStreamChecker.bind(unownedHost)
|
|
62
|
+
: undefined;
|
|
63
|
+
const host = Object.freeze({
|
|
64
|
+
store: data.store,
|
|
65
|
+
authority: freeze(snapshot(data.authority)),
|
|
66
|
+
directory: rawDirectory,
|
|
67
|
+
artifactsDirectory,
|
|
68
|
+
dockerExecutable: text(data.dockerExecutable, '/host/dockerExecutable'),
|
|
69
|
+
dockerSocket: text(data.dockerSocket, '/host/dockerSocket'),
|
|
70
|
+
runtime: freeze(runtime),
|
|
71
|
+
resolveCredential: wrappedResolveCredential,
|
|
72
|
+
createCandidateStreamChecker: () => composeCandidateStreamCheckers(rawStreamChecker?.(), createBuiltInPiStreamChecker(resolvedSecrets)),
|
|
73
|
+
});
|
|
74
|
+
// Neither unownedHost nor unownedInput is ever read after this point.
|
|
75
|
+
const policy = await effectivePolicyV2(captured.rawPolicy);
|
|
76
|
+
const prepared = validateStructuralInputWithPolicy(captured, policy.native);
|
|
77
|
+
if (!sameIdentity(host.runtime, prepared.policy.runtime))
|
|
78
|
+
refuse('RUNTIME_MISMATCH', '/policy/runtime');
|
|
79
|
+
const originalMcp = policy.source.mcp;
|
|
80
|
+
const selected = isHttpMcp(originalMcp) ? { ...ports, mcp: (owner, value) => ({ process: () => new HttpMcpProcess(owner, value, originalMcp, wrappedResolveMcpCredential, error => { lastFailure ??= error; }, ports.http) }) } : ports;
|
|
81
|
+
const opened = await constructAdapterFromCaptured(host, prepared, selected);
|
|
82
|
+
if (!opened.ok)
|
|
83
|
+
return { ok: false, error: lastFailure ?? opened.error };
|
|
84
|
+
const adapter = opened.value;
|
|
85
|
+
if (lastFailure) {
|
|
86
|
+
const closed = await adapter.close();
|
|
87
|
+
return { ok: false, error: closed.ok ? lastFailure : closed.error };
|
|
88
|
+
}
|
|
89
|
+
const mapped = (outcome) => {
|
|
90
|
+
if (!lastFailure)
|
|
91
|
+
return outcome;
|
|
92
|
+
const current = host.store.inspect();
|
|
93
|
+
const uncertain = !current.ok || current.value.counts.dispatchedRequests > 0 || current.value.counts.unresolvedRequests > 0 || current.value.counts.unresolvedOperations > 0
|
|
94
|
+
|| outcome.providerTermination === 'unknown' || outcome.usage === 'incomplete' || outcome.localCleanup !== 'complete';
|
|
95
|
+
return freeze({ ...outcome, status: uncertain ? 'recovery_required' : outcome.status === 'cancelled' ? 'cancelled' : 'blocked', error: { ...lastFailure } });
|
|
96
|
+
};
|
|
97
|
+
const execute = async (call, allowFailed = false) => {
|
|
98
|
+
if (lastFailure && !allowFailed)
|
|
99
|
+
return { ok: false, error: lastFailure };
|
|
100
|
+
const result = await call();
|
|
101
|
+
return result.ok ? { ok: true, value: mapped(result.value) } : { ok: false, error: lastFailure ?? result.error };
|
|
102
|
+
};
|
|
103
|
+
return { ok: true, value: Object.freeze({
|
|
104
|
+
capabilities: () => freeze({ ...adapter.capabilities(), version: 2, sourcePolicyDigest: { ...policy.sourceDigest },
|
|
105
|
+
mcpTransport: isHttpMcp(originalMcp) ? originalMcp.transport : 'stdio' }),
|
|
106
|
+
execute: (command) => execute(() => adapter.execute(command)),
|
|
107
|
+
compact: (command) => execute(() => adapter.compact(command)),
|
|
108
|
+
cancel: (command) => execute(() => adapter.cancel(command), true),
|
|
109
|
+
events: () => adapter.events(), capture: (command) => adapter.capture(command), close: () => adapter.close(),
|
|
110
|
+
}) };
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error instanceof HttpMcpFailure)
|
|
114
|
+
return { ok: false, error: error.detail };
|
|
115
|
+
if (error instanceof PiFailure)
|
|
116
|
+
return { ok: false, error: error.detail };
|
|
117
|
+
return { ok: false, error: { code: 'INPUT_INVALID', path: '', phase: 'preflight', retryable: false, effect: 'none', requestId: null, operationId: null, stateErrorCode: null } };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export function openPiAdapterV2(host, input) {
|
|
121
|
+
return constructAdapterV2(host, input, runtimePorts);
|
|
122
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type StructuralPreparedInput } from './preflight.js';
|
|
2
|
+
import { Sender } from './sender.js';
|
|
3
|
+
import { Execution } from './execution.js';
|
|
4
|
+
import { type McpPorts } from './mcp.js';
|
|
5
|
+
import type { RuntimeBroker } from './provider.js';
|
|
6
|
+
import type { PiAdapter, PiHost, PiOpenInput, PiCapabilities, PiResult } from './types.js';
|
|
7
|
+
interface Session {
|
|
8
|
+
start(): Promise<PiCapabilities>;
|
|
9
|
+
command(kind: 'execute' | 'compact', input: unknown): Promise<unknown>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
capture?(sink: (bytes: Uint8Array) => Promise<void>): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export interface LeasePort {
|
|
14
|
+
release(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface FactoryPorts {
|
|
17
|
+
readonly mcp?: (host: PiHost, input: PiOpenInput) => McpPorts;
|
|
18
|
+
readonly sender?: (host: PiHost, input: PiOpenInput) => Sender;
|
|
19
|
+
readonly lease?: (host: PiHost, input: PiOpenInput) => Promise<LeasePort>;
|
|
20
|
+
readonly execution?: (host: PiHost, input: PiOpenInput, candidate: string) => Execution;
|
|
21
|
+
readonly environment: (host: PiHost) => Promise<void>;
|
|
22
|
+
readonly session: (host: PiHost, input: PiOpenInput, sender: RuntimeBroker, directory: string) => Session;
|
|
23
|
+
}
|
|
24
|
+
/** Internal dependency injection only; absent from package exports. */
|
|
25
|
+
export declare function constructAdapterFromCaptured(host: PiHost, prepared: StructuralPreparedInput, ports: FactoryPorts): Promise<PiResult<PiAdapter>>;
|
|
26
|
+
export declare function constructAdapter(unownedHost: PiHost, input: unknown, ports: FactoryPorts): Promise<PiResult<PiAdapter>>;
|
|
27
|
+
export declare function openPiAdapter(host: PiHost, input: unknown): Promise<PiResult<PiAdapter>>;
|
|
28
|
+
/** Private ports shared with executable qualifications; absent from package exports. */
|
|
29
|
+
export declare const runtimePorts: FactoryPorts;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { join, isAbsolute, resolve } from 'node:path';
|
|
3
|
+
import { types } from 'node:util';
|
|
4
|
+
import { validateRuntime, sameIdentity } from './policy.js';
|
|
5
|
+
import { snapshot, object, freeze, id, text, digest } from './boundary.js';
|
|
6
|
+
import { finalizePreparedInputAsync, parseAndValidateStructuralInput, } from './preflight.js';
|
|
7
|
+
import { composeCandidateStreamCheckers, createBuiltInPiStreamChecker } from './cas.js';
|
|
8
|
+
import { PiFailure, refuse, result } from './errors.js';
|
|
9
|
+
import { canonicalDirectory, RuntimeSession } from './session-host.js';
|
|
10
|
+
import { Sender } from './sender.js';
|
|
11
|
+
import { Execution } from './execution.js';
|
|
12
|
+
import { Mcp } from './mcp.js';
|
|
13
|
+
import { eventSequence } from './event-sequence.js';
|
|
14
|
+
import { Events } from './events.js';
|
|
15
|
+
import { ExecutionLease } from './execution-lease.js';
|
|
16
|
+
import { ExecutionGuard } from './execution-guard.js';
|
|
17
|
+
import { recoverSnapshot } from './recovery.js';
|
|
18
|
+
import { captureCheckpoint } from './capture.js';
|
|
19
|
+
import { selectedCatalog } from './catalog.js';
|
|
20
|
+
function stateFailure(error) {
|
|
21
|
+
refuse(error.commit === 'unknown' ? 'RECOVERY_REQUIRED' : (error.code.startsWith('OWNER_') || error.code === 'STALE_OWNER') ? 'AUTHORITY_REFUSED' : 'STATE_REFUSED', '', {
|
|
22
|
+
phase: 'admission', retryable: error.retryable, effect: error.commit === 'unknown' ? 'possible' : 'none', stateErrorCode: error.code
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function cleanupFailure(error) {
|
|
26
|
+
return error instanceof PiFailure ? freeze({ ...error.detail, phase: 'cleanup' }) : freeze({ code: 'CLEANUP_FAILED', path: '', phase: 'cleanup', retryable: false, effect: 'none', requestId: null, operationId: null, stateErrorCode: null });
|
|
27
|
+
}
|
|
28
|
+
async function environment(host) {
|
|
29
|
+
try {
|
|
30
|
+
await canonicalDirectory(host.directory);
|
|
31
|
+
await canonicalDirectory(host.artifactsDirectory);
|
|
32
|
+
if (!isAbsolute(host.dockerExecutable) || !(await stat(host.dockerExecutable)).isFile() || !isAbsolute(host.dockerSocket) || !(await stat(host.dockerSocket)).isSocket())
|
|
33
|
+
refuse('CONTAINMENT_UNAVAILABLE');
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
refuse('CONTAINMENT_UNAVAILABLE');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Internal dependency injection only; absent from package exports. */
|
|
40
|
+
export async function constructAdapterFromCaptured(host, prepared, ports) {
|
|
41
|
+
return result(async () => {
|
|
42
|
+
const owned = await finalizePreparedInputAsync(prepared, host.artifactsDirectory);
|
|
43
|
+
const viewed = host.store.inspect();
|
|
44
|
+
if (!viewed.ok)
|
|
45
|
+
stateFailure(viewed.error);
|
|
46
|
+
const view = viewed.value;
|
|
47
|
+
if (view.runId !== owned.lock.spec.runId || !sameIdentity(view.lockHash, owned.lock.spec.lockHash) || view.binding.resourceVersion !== owned.policy.resourceVersion || !view.binding.adapters.some(item => item.id === 'pi' && item.version === '0.0.0'))
|
|
48
|
+
refuse('BINDING_MISMATCH', '/host/store');
|
|
49
|
+
if (view.counts.dispatchedRequests || view.counts.unresolvedRequests || view.counts.unresolvedOperations || view.ledger.violations.length)
|
|
50
|
+
refuse('RECOVERY_REQUIRED', '/host/store');
|
|
51
|
+
if (view.clockStatus !== 'trusted' || view.owner.mode !== 'active')
|
|
52
|
+
refuse('RECOVERY_REQUIRED', '/host/store');
|
|
53
|
+
if ((view.clock.remainingTaskMs.safeValue ?? 0) <= 0)
|
|
54
|
+
refuse('DEADLINE', '/host/store');
|
|
55
|
+
const restored = await recoverSnapshot(host, owned);
|
|
56
|
+
if (owned.policy.mcp.names.length && !sameIdentity(digest(await readFile(new URL('./workspace-mcp.js', import.meta.url))), owned.policy.mcp.scriptDigest))
|
|
57
|
+
refuse('RUNTIME_MISMATCH', '/policy/mcp/scriptDigest');
|
|
58
|
+
const catalog = selectedCatalog(owned);
|
|
59
|
+
await ports.environment(host);
|
|
60
|
+
const lease = await (ports.lease ? ports.lease(host, owned) : ExecutionLease.acquire(host, owned));
|
|
61
|
+
let sequencing;
|
|
62
|
+
try {
|
|
63
|
+
sequencing = await eventSequence(host, owned, restored?.sequence ?? 0);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
await lease.release();
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
const sender = ports.sender?.(host, owned) ?? new Sender(host, owned, { fetch: globalThis.fetch, catalog });
|
|
70
|
+
const candidateDirectory = join(host.directory, 'sdk-' + owned.sessionId, 'candidate');
|
|
71
|
+
const execution = ports.execution ? ports.execution(host, owned, candidateDirectory) : new Execution(host, owned, candidateDirectory);
|
|
72
|
+
sender.installTools(execution);
|
|
73
|
+
const session = ports.session(host, owned, sender, join(host.directory, 'sdk-' + owned.sessionId));
|
|
74
|
+
const mcp = new Mcp(host, owned, execution.candidate, code => sender.runtimeFault(code), ports.mcp?.(host, owned));
|
|
75
|
+
const cleanupRoles = async () => { const results = await Promise.allSettled([execution.close(), mcp.close(), session.close()]); if (results.some(item => item.status === 'rejected'))
|
|
76
|
+
refuse('CLEANUP_FAILED', '', { phase: 'cleanup' }); };
|
|
77
|
+
sender.installMcp(mcp, () => { void stopEvents().catch(() => { }); });
|
|
78
|
+
let closed = false, cleanupComplete = false, fatal = null;
|
|
79
|
+
const guard = new ExecutionGuard();
|
|
80
|
+
let stopEvents = async () => { guard.revoke(); sender.cancel(); await cleanupRoles(); events.close(); };
|
|
81
|
+
const events = new Events(owned, () => stopEvents(), () => { sender.cancel('EVENT_OVERFLOW'); void stopEvents().catch(() => { }); });
|
|
82
|
+
events.restoreSequence(sequencing.sequence, sequencing.persist);
|
|
83
|
+
sender.installEvents((kind, fields) => events.push(kind, fields));
|
|
84
|
+
let lastProgress = null, safeCapture = restored !== null;
|
|
85
|
+
let activeCommand = null;
|
|
86
|
+
const renewTimer = setInterval(() => {
|
|
87
|
+
const renewed = host.store.renew(host.authority);
|
|
88
|
+
if (!renewed.ok) {
|
|
89
|
+
fatal = renewed.error;
|
|
90
|
+
guard.revoke();
|
|
91
|
+
sender.cancel('AUTHORITY_REFUSED');
|
|
92
|
+
clearInterval(renewTimer);
|
|
93
|
+
void (async () => { await events.push('cancellation', { code: 'AUTHORITY_REFUSED' }).catch(() => { }); await stopEvents(); })().catch(() => { });
|
|
94
|
+
}
|
|
95
|
+
}, Math.max(250, Math.min(1000, Math.floor(view.policy.leaseMs / 3))));
|
|
96
|
+
renewTimer.unref();
|
|
97
|
+
let deadlineTimer;
|
|
98
|
+
const scheduleDeadline = () => {
|
|
99
|
+
const current = host.store.inspect(), remaining = current.ok && current.value.clockStatus === 'trusted' ? current.value.clock.remainingTaskMs.safeValue : null;
|
|
100
|
+
if (remaining !== null && remaining > 0) {
|
|
101
|
+
deadlineTimer = setTimeout(scheduleDeadline, Math.min(remaining, 2147483647));
|
|
102
|
+
deadlineTimer.unref();
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
guard.revoke();
|
|
106
|
+
sender.cancel(remaining === null ? 'AUTHORITY_REFUSED' : 'DEADLINE');
|
|
107
|
+
clearInterval(renewTimer);
|
|
108
|
+
void (async () => { await events.push('cancellation', { code: remaining === null ? 'AUTHORITY_REFUSED' : 'DEADLINE' }).catch(() => { }); await stopEvents(); })().catch(() => { });
|
|
109
|
+
};
|
|
110
|
+
scheduleDeadline();
|
|
111
|
+
let facts;
|
|
112
|
+
try {
|
|
113
|
+
facts = freeze(await session.start());
|
|
114
|
+
if (owned.candidate.baseline) {
|
|
115
|
+
await execution.candidate.captureBaselineStats();
|
|
116
|
+
}
|
|
117
|
+
if (fatal)
|
|
118
|
+
stateFailure(fatal);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
clearInterval(renewTimer);
|
|
122
|
+
clearTimeout(deadlineTimer);
|
|
123
|
+
await cleanupRoles();
|
|
124
|
+
await lease.release();
|
|
125
|
+
if (error instanceof PiFailure)
|
|
126
|
+
throw error;
|
|
127
|
+
refuse('CONTAINMENT_UNAVAILABLE');
|
|
128
|
+
}
|
|
129
|
+
const ready = () => { if (fatal)
|
|
130
|
+
stateFailure(fatal); if (closed)
|
|
131
|
+
refuse('CANCELLED', '', { phase: 'session' }); };
|
|
132
|
+
let shutdownWork = null;
|
|
133
|
+
const shutdown = () => shutdownWork ??= result(async () => {
|
|
134
|
+
closed = true;
|
|
135
|
+
guard.revoke();
|
|
136
|
+
sender.cancel();
|
|
137
|
+
try {
|
|
138
|
+
if (!cleanupComplete) {
|
|
139
|
+
await cleanupRoles();
|
|
140
|
+
cleanupComplete = true;
|
|
141
|
+
await events.push('process_exit').catch(() => { });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
refuse('CLEANUP_FAILED', '', { phase: 'cleanup' });
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
clearInterval(renewTimer);
|
|
149
|
+
clearTimeout(deadlineTimer);
|
|
150
|
+
events.close();
|
|
151
|
+
}
|
|
152
|
+
return Object.freeze({ closed: true });
|
|
153
|
+
});
|
|
154
|
+
const close = async () => {
|
|
155
|
+
const stopped = await shutdown();
|
|
156
|
+
await guard.drain();
|
|
157
|
+
if (stopped.ok)
|
|
158
|
+
return result(async () => { try {
|
|
159
|
+
await lease.release();
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
throw new PiFailure(cleanupFailure(error));
|
|
163
|
+
} return stopped.value; });
|
|
164
|
+
return stopped;
|
|
165
|
+
};
|
|
166
|
+
stopEvents = async () => { const stopped = await close(); if (!stopped.ok)
|
|
167
|
+
refuse(stopped.error.code, stopped.error.path, stopped.error); };
|
|
168
|
+
try {
|
|
169
|
+
await events.push('resource_identity', { digest: facts.policyDigest });
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
await close();
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
const exclusive = (action, onCleanupFailure) => result(async () => {
|
|
176
|
+
let value;
|
|
177
|
+
try {
|
|
178
|
+
value = await guard.run(action);
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (closed && cleanupComplete)
|
|
182
|
+
await lease.release();
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
if (closed && cleanupComplete) {
|
|
186
|
+
try {
|
|
187
|
+
await lease.release();
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
const detail = cleanupFailure(error);
|
|
191
|
+
if (onCleanupFailure)
|
|
192
|
+
return onCleanupFailure(value, detail);
|
|
193
|
+
throw new PiFailure(detail);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return value;
|
|
197
|
+
});
|
|
198
|
+
const dispatch = (kind, command) => exclusive(async () => {
|
|
199
|
+
ready();
|
|
200
|
+
sender.begin(kind, command);
|
|
201
|
+
safeCapture = false;
|
|
202
|
+
const executing = { outcome: null };
|
|
203
|
+
activeCommand = executing;
|
|
204
|
+
try {
|
|
205
|
+
try {
|
|
206
|
+
await session.command(kind, command);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
sender.cancel(error instanceof PiFailure ? error.detail.code : 'PROVIDER_RESPONSE_INVALID');
|
|
210
|
+
}
|
|
211
|
+
let outcome = sender.finish();
|
|
212
|
+
if (fatal)
|
|
213
|
+
outcome = freeze({ ...outcome, status: 'recovery_required', error: outcome.error ? { ...outcome.error, stateErrorCode: outcome.error.stateErrorCode ?? fatal.code } : { code: 'AUTHORITY_REFUSED', path: '', phase: 'admission', retryable: fatal.retryable, effect: outcome.requestIds.length ? 'possible' : 'none', requestId: outcome.requestIds.at(-1) ?? null, operationId: null, stateErrorCode: fatal.code } });
|
|
214
|
+
if (sender.outboundObserved)
|
|
215
|
+
facts = freeze({ ...facts, outboundObserved: owned.policy.selection });
|
|
216
|
+
try {
|
|
217
|
+
await events.push('settled', { count: outcome.requestIds.length, code: outcome.error?.code ?? null });
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
outcome = freeze({ ...outcome, status: outcome.status === 'execution_settled' ? 'failed' : outcome.status, error: outcome.error ?? { code: 'EVENT_OVERFLOW', path: '', phase: 'session', retryable: false, effect: outcome.requestIds.length ? 'possible' : 'none', requestId: outcome.requestIds.at(-1) ?? null, operationId: null, stateErrorCode: null } });
|
|
221
|
+
}
|
|
222
|
+
if (outcome.status !== 'execution_settled') {
|
|
223
|
+
const stopped = await shutdown();
|
|
224
|
+
outcome = freeze({ ...outcome, status: stopped.ok ? outcome.status : 'recovery_required', localCleanup: stopped.ok ? 'complete' : 'failed', cleanupError: stopped.ok ? null : stopped.error });
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
safeCapture = true;
|
|
228
|
+
outcome = freeze({ ...outcome, localCleanup: 'complete' });
|
|
229
|
+
}
|
|
230
|
+
executing.outcome = outcome;
|
|
231
|
+
lastProgress = outcome;
|
|
232
|
+
return outcome;
|
|
233
|
+
}
|
|
234
|
+
finally {
|
|
235
|
+
if (activeCommand === executing)
|
|
236
|
+
activeCommand = null;
|
|
237
|
+
}
|
|
238
|
+
}, (outcome, error) => { lastProgress = freeze({ ...outcome, status: 'recovery_required', localCleanup: 'failed', cleanupError: error }); return lastProgress; });
|
|
239
|
+
return Object.freeze({ capabilities: () => facts,
|
|
240
|
+
execute: (command) => dispatch('execute', command), compact: (command) => dispatch('compact', command),
|
|
241
|
+
events: () => events.iterator(),
|
|
242
|
+
cancel: async (command) => result(async () => {
|
|
243
|
+
const item = object(command, ['reason']);
|
|
244
|
+
if (!['operator', 'deadline', 'consumer_disconnected'].includes(item.reason))
|
|
245
|
+
refuse('INPUT_INVALID');
|
|
246
|
+
const active = activeCommand, progress = sender.progress(), prior = active ? null : lastProgress;
|
|
247
|
+
guard.revoke();
|
|
248
|
+
sender.cancel(item.reason === 'deadline' ? 'DEADLINE' : 'CANCELLED');
|
|
249
|
+
await events.push('cancellation', { code: item.reason === 'deadline' ? 'DEADLINE' : 'CANCELLED' }).catch(() => { });
|
|
250
|
+
const stopped = await close();
|
|
251
|
+
const finalView = host.store.inspect(), unresolved = !finalView.ok || finalView.value.counts.unresolvedRequests > 0 || finalView.value.counts.dispatchedRequests > 0 || finalView.value.counts.unresolvedOperations > 0;
|
|
252
|
+
const outcome = active ? active.outcome ?? progress : prior;
|
|
253
|
+
return freeze({ ...(outcome ?? { requestIds: [], operationIds: [], providerTermination: 'none', usage: 'none', error: null }), status: !stopped.ok || unresolved || outcome?.providerTermination === 'unknown' ? 'recovery_required' : outcome?.status ?? 'cancelled', localCleanup: stopped.ok ? 'complete' : 'failed', cleanupError: stopped.ok ? null : stopped.error });
|
|
254
|
+
}),
|
|
255
|
+
capture: async (command) => exclusive(async () => {
|
|
256
|
+
ready();
|
|
257
|
+
const item = object(command, ['checkpointId']), checkpointId = id(item.checkpointId, '/checkpointId');
|
|
258
|
+
if (!safeCapture)
|
|
259
|
+
refuse('REQUEST_REFUSED', '', { phase: 'restore' });
|
|
260
|
+
if (!session.capture)
|
|
261
|
+
refuse('CAPABILITY_UNSUPPORTED', '', { phase: 'restore' });
|
|
262
|
+
try {
|
|
263
|
+
return freeze(await captureCheckpoint(host, owned, execution.candidate, { capture: sink => session.capture(sink) }, checkpointId, events.sequence, guard.signal));
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
if (error instanceof PiFailure && ['RECOVERY_REQUIRED', 'BINDING_MISMATCH', 'RESOURCE_MISMATCH', 'CLEANUP_FAILED', 'OUTPUT_LIMIT'].includes(error.detail.code)) {
|
|
267
|
+
safeCapture = false;
|
|
268
|
+
await shutdown();
|
|
269
|
+
}
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}), close });
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
export async function constructAdapter(unownedHost, input, ports) {
|
|
276
|
+
return result(async () => {
|
|
277
|
+
// Capture and validate BOTH caller-owned input (including baseline) and host synchronously
|
|
278
|
+
// BEFORE the first await so neither unownedHost nor input is ever read across an async boundary.
|
|
279
|
+
const prepared = parseAndValidateStructuralInput(input);
|
|
280
|
+
if (!unownedHost || typeof unownedHost !== 'object' || types.isProxy(unownedHost)) {
|
|
281
|
+
refuse('INPUT_INVALID', '/host');
|
|
282
|
+
}
|
|
283
|
+
const hasStreamChecker = Object.hasOwn(unownedHost, 'createCandidateStreamChecker');
|
|
284
|
+
const hostFields = [
|
|
285
|
+
'store', 'authority', 'directory', 'artifactsDirectory', 'dockerExecutable', 'dockerSocket', 'runtime', 'resolveCredential',
|
|
286
|
+
...(hasStreamChecker ? ['createCandidateStreamChecker'] : []),
|
|
287
|
+
];
|
|
288
|
+
const data = object(unownedHost, hostFields, '/host');
|
|
289
|
+
if (typeof data.resolveCredential !== 'function')
|
|
290
|
+
refuse('INPUT_INVALID', '/host/resolveCredential');
|
|
291
|
+
if (hasStreamChecker && data.createCandidateStreamChecker !== undefined && typeof data.createCandidateStreamChecker !== 'function') {
|
|
292
|
+
refuse('INPUT_INVALID', '/host/createCandidateStreamChecker');
|
|
293
|
+
}
|
|
294
|
+
const runtime = validateRuntime(snapshot(data.runtime), '/host/runtime');
|
|
295
|
+
if (!sameIdentity(runtime, prepared.policy.runtime))
|
|
296
|
+
refuse('RUNTIME_MISMATCH', '/policy/runtime');
|
|
297
|
+
for (const name of ['directory', 'artifactsDirectory']) {
|
|
298
|
+
if (typeof data[name] !== 'string' || /[,\r\n\0]/.test(data[name])) {
|
|
299
|
+
refuse('INPUT_INVALID', '/host/' + name);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const rawDirectory = text(data.directory, '/host/directory');
|
|
303
|
+
const rawArtifactsDirectory = text(data.artifactsDirectory, '/host/artifactsDirectory');
|
|
304
|
+
if (!isAbsolute(rawArtifactsDirectory))
|
|
305
|
+
refuse('INPUT_INVALID', '/host/artifactsDirectory');
|
|
306
|
+
const artifactsDirectory = resolve(rawArtifactsDirectory);
|
|
307
|
+
const resolvedSecrets = new Set();
|
|
308
|
+
const rawResolveCredential = data.resolveCredential.bind(unownedHost);
|
|
309
|
+
const wrappedResolveCredential = async (binding) => {
|
|
310
|
+
const resolved = await rawResolveCredential(binding);
|
|
311
|
+
if (resolved && typeof resolved.bearerToken === 'string' && resolved.bearerToken.length > 0) {
|
|
312
|
+
resolvedSecrets.add(resolved.bearerToken);
|
|
313
|
+
}
|
|
314
|
+
return resolved;
|
|
315
|
+
};
|
|
316
|
+
const rawStreamChecker = typeof data.createCandidateStreamChecker === 'function'
|
|
317
|
+
? data.createCandidateStreamChecker.bind(unownedHost)
|
|
318
|
+
: undefined;
|
|
319
|
+
const host = Object.freeze({
|
|
320
|
+
store: data.store,
|
|
321
|
+
authority: freeze(snapshot(data.authority)),
|
|
322
|
+
directory: rawDirectory,
|
|
323
|
+
artifactsDirectory,
|
|
324
|
+
dockerExecutable: text(data.dockerExecutable, '/host/dockerExecutable'),
|
|
325
|
+
dockerSocket: text(data.dockerSocket, '/host/dockerSocket'),
|
|
326
|
+
runtime: freeze(runtime),
|
|
327
|
+
resolveCredential: wrappedResolveCredential,
|
|
328
|
+
createCandidateStreamChecker: () => composeCandidateStreamCheckers(rawStreamChecker?.(), createBuiltInPiStreamChecker(resolvedSecrets)),
|
|
329
|
+
});
|
|
330
|
+
const opened = await constructAdapterFromCaptured(host, prepared, ports);
|
|
331
|
+
if (!opened.ok)
|
|
332
|
+
throw new PiFailure(opened.error);
|
|
333
|
+
return opened.value;
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
export function openPiAdapter(host, input) {
|
|
337
|
+
return constructAdapter(host, input, runtimePorts);
|
|
338
|
+
}
|
|
339
|
+
/** Private ports shared with executable qualifications; absent from package exports. */
|
|
340
|
+
export const runtimePorts = { environment, session: (owner, owned, sender, directory) => new RuntimeSession(owner, owned, sender, directory) };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RequestAdmission, StateResult } from '@loopwright/state';
|
|
2
|
+
import type { PiHost, PiError } from './types.js';
|
|
3
|
+
export interface DispatchPayload {
|
|
4
|
+
readonly destination: string;
|
|
5
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
6
|
+
readonly body: Uint8Array;
|
|
7
|
+
readonly signal: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
export interface DispatchTicket {
|
|
10
|
+
readonly requestId: string;
|
|
11
|
+
}
|
|
12
|
+
export interface DispatchPorts {
|
|
13
|
+
readonly destination: string;
|
|
14
|
+
readonly fetch: typeof globalThis.fetch;
|
|
15
|
+
readonly maxRequestBytes?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function stateValue<T>(value: StateResult<T>, phase?: PiError['phase']): T;
|
|
18
|
+
/** Original live tickets never leave this owner and cannot be recreated from persistent dispatch markers. */
|
|
19
|
+
export declare class Admission {
|
|
20
|
+
#private;
|
|
21
|
+
readonly host: PiHost;
|
|
22
|
+
constructor(host: PiHost, ports: DispatchPorts);
|
|
23
|
+
issue(input: RequestAdmission, payload: DispatchPayload): DispatchTicket;
|
|
24
|
+
dispatch(ticket: DispatchTicket): Promise<Response>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { canonical, digest, freeze, snapshot } from './boundary.js';
|
|
2
|
+
import { refuse } from './errors.js';
|
|
3
|
+
export function stateValue(value, phase = 'admission') {
|
|
4
|
+
if (value.ok)
|
|
5
|
+
return value.value;
|
|
6
|
+
const error = value.error;
|
|
7
|
+
const code = error.commit === 'unknown' ? 'RECOVERY_REQUIRED' : error.code === 'STALE_OWNER' || error.code.startsWith('OWNER_') ? 'AUTHORITY_REFUSED'
|
|
8
|
+
: error.code === 'DEADLINE_EXCEEDED' ? 'DEADLINE' : ['BUDGET_EXHAUSTED', 'CAPABILITY_UNSUPPORTED', 'LIMIT_EXCEEDED'].includes(error.code) ? 'REQUEST_REFUSED' : 'STATE_REFUSED';
|
|
9
|
+
refuse(code, error.path, { phase, retryable: error.retryable, effect: error.commit === 'unknown' ? 'possible' : 'none', stateErrorCode: error.code });
|
|
10
|
+
}
|
|
11
|
+
/** Original live tickets never leave this owner and cannot be recreated from persistent dispatch markers. */
|
|
12
|
+
export class Admission {
|
|
13
|
+
host;
|
|
14
|
+
#tickets = new WeakMap();
|
|
15
|
+
#used = new WeakSet();
|
|
16
|
+
#authority;
|
|
17
|
+
#destination;
|
|
18
|
+
#fetch;
|
|
19
|
+
#maxRequestBytes;
|
|
20
|
+
constructor(host, ports) {
|
|
21
|
+
this.host = host;
|
|
22
|
+
this.#authority = freeze(snapshot(host.authority));
|
|
23
|
+
this.#destination = ports.destination;
|
|
24
|
+
this.#fetch = ports.fetch;
|
|
25
|
+
this.#maxRequestBytes = ports.maxRequestBytes ?? 65536;
|
|
26
|
+
}
|
|
27
|
+
issue(input, payload) {
|
|
28
|
+
if (payload.signal.aborted)
|
|
29
|
+
refuse('CANCELLED', '', { phase: 'admission' });
|
|
30
|
+
if (payload.destination !== this.#destination || !(payload.body instanceof Uint8Array) || payload.body.buffer instanceof SharedArrayBuffer || payload.body.byteLength > this.#maxRequestBytes)
|
|
31
|
+
refuse('PAYLOAD_MISMATCH', '', { phase: 'admission' });
|
|
32
|
+
const body = Buffer.from(payload.body), headers = Object.freeze({ ...payload.headers });
|
|
33
|
+
stateValue(this.host.store.reserveRequest(this.#authority, input));
|
|
34
|
+
const authorized = stateValue(this.host.store.authorizeRequestDispatch(this.#authority, input.requestId));
|
|
35
|
+
if (authorized.kind !== 'new_dispatch')
|
|
36
|
+
refuse('REQUEST_REFUSED', '', { phase: 'dispatch', requestId: input.requestId, operationId: input.operationId });
|
|
37
|
+
const ticket = Object.freeze({ requestId: input.requestId });
|
|
38
|
+
this.#tickets.set(ticket, { permit: authorized.permit, admission: authorized.record.admission, payload: { destination: this.#destination, headers, body, signal: payload.signal }, bodyDigest: digest(body).hex });
|
|
39
|
+
return ticket;
|
|
40
|
+
}
|
|
41
|
+
#assertCurrent(value) {
|
|
42
|
+
const renewed = stateValue(this.host.store.renew(this.#authority), 'dispatch');
|
|
43
|
+
if (canonical(renewed.authority) !== canonical(this.#authority))
|
|
44
|
+
refuse('AUTHORITY_REFUSED', '', { phase: 'dispatch' });
|
|
45
|
+
const current = stateValue(this.host.store.getRequest(value.admission.requestId), 'dispatch');
|
|
46
|
+
if (current.state !== 'dispatch_authorized' || current.dispatch?.dispatchId !== value.permit.dispatchId || current.dispatch.generation !== value.permit.generation || canonical(current.admission) !== canonical(value.admission) || digest(value.payload.body).hex !== value.bodyDigest)
|
|
47
|
+
refuse('PAYLOAD_MISMATCH', '', { phase: 'dispatch' });
|
|
48
|
+
const view = stateValue(this.host.store.inspect(), 'dispatch'), permit = value.permit;
|
|
49
|
+
if (view.clockStatus !== 'trusted' || view.owner.mode !== 'active' || view.owner.ownerId !== this.#authority.ownerId || view.owner.generation !== this.#authority.generation || permit.generation !== this.#authority.generation
|
|
50
|
+
|| view.clock.basis.clockEpoch !== permit.clockEpoch || view.storeId !== permit.storeId || view.runId !== permit.runId || canonical(view.lockHash) !== canonical(permit.lockHash)
|
|
51
|
+
|| BigInt(view.clock.sampledNow.monotonicMs) >= BigInt(permit.notAfterMonotonicMs) || BigInt(view.clock.sampledNow.monotonicMs) >= BigInt(view.clock.basis.taskDeadlineMonotonicMs))
|
|
52
|
+
refuse('AUTHORITY_REFUSED', '', { phase: 'dispatch' });
|
|
53
|
+
}
|
|
54
|
+
async dispatch(ticket) {
|
|
55
|
+
const value = this.#tickets.get(ticket);
|
|
56
|
+
if (!value || this.#used.has(ticket))
|
|
57
|
+
refuse('REQUEST_REFUSED', '', { phase: 'dispatch' });
|
|
58
|
+
if (value.payload.signal.aborted)
|
|
59
|
+
refuse('CANCELLED', '', { phase: 'dispatch' });
|
|
60
|
+
this.#assertCurrent(value);
|
|
61
|
+
this.#used.add(ticket);
|
|
62
|
+
// No await or asynchronous queue between the final qualified clock/owner check and invoking the sole HTTP transport.
|
|
63
|
+
return this.#fetch(value.payload.destination, { method: 'POST', headers: value.payload.headers, body: Buffer.from(value.payload.body), signal: value.payload.signal, redirect: 'error' });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ArtifactRef } from '@loopwright/core';
|
|
2
|
+
/** New immutable internal artifacts publish through a synced temporary inode and no-overwrite link. */
|
|
3
|
+
export declare class ArtifactWriter {
|
|
4
|
+
#private;
|
|
5
|
+
readonly root: string;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly maxBytes: number;
|
|
8
|
+
readonly signal: AbortSignal;
|
|
9
|
+
readonly temporary: string;
|
|
10
|
+
constructor(root: string, name: string, maxBytes: number, signal: AbortSignal);
|
|
11
|
+
start(): Promise<void>;
|
|
12
|
+
append(bytes: Uint8Array): Promise<void>;
|
|
13
|
+
finish(): Promise<ArtifactRef>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|