@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,315 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { execFile, spawn } from 'node:child_process';
|
|
3
|
+
import { promisify } from 'node:util';
|
|
4
|
+
import { readFile, writeFile, mkdir, realpath, stat } from 'node:fs/promises';
|
|
5
|
+
import { resolve, join } from 'node:path';
|
|
6
|
+
import { randomBytes } from 'node:crypto';
|
|
7
|
+
import { Channel } from './protocol.js';
|
|
8
|
+
import { canonical, digest, freeze } from './boundary.js';
|
|
9
|
+
import { PiFailure, refuse } from './errors.js';
|
|
10
|
+
import { sameIdentity } from './policy.js';
|
|
11
|
+
import { profileIdentity, verifyRestrictions, restrictedArguments } from './runtime-profile.js';
|
|
12
|
+
export { profileIdentity } from './runtime-profile.js';
|
|
13
|
+
import { systemPrompt } from './resources.js';
|
|
14
|
+
import { receiveBrokerMessage } from './broker-channel.js';
|
|
15
|
+
import { stateValue } from './admission.js';
|
|
16
|
+
import { materializeCandidateDirectory, setDirectoryTreeMode } from './candidate.js';
|
|
17
|
+
import { isAbsentContainer } from './docker-absence.js';
|
|
18
|
+
import { registerChild, exitChild, registerAttach } from './execution-lease.js';
|
|
19
|
+
import { recoverSnapshot } from './recovery.js';
|
|
20
|
+
import { SnapshotTransfer } from './snapshot-transfer.js';
|
|
21
|
+
import { verifyNativeCompletion } from './lifecycle.js';
|
|
22
|
+
import { scheduleDeadline } from './deadline.js';
|
|
23
|
+
const exec = promisify(execFile);
|
|
24
|
+
export async function canonicalDirectory(path) {
|
|
25
|
+
try {
|
|
26
|
+
const canonicalPath = await realpath(path), info = await stat(path);
|
|
27
|
+
if (canonicalPath !== resolve(path) || !info.isDirectory() || info.uid !== process.getuid?.())
|
|
28
|
+
refuse('INPUT_INVALID');
|
|
29
|
+
return canonicalPath;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
refuse('INPUT_INVALID');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Internal constructor. The public factory supplies only its real state-aware sender. */
|
|
36
|
+
export class RuntimeSession {
|
|
37
|
+
host;
|
|
38
|
+
input;
|
|
39
|
+
broker;
|
|
40
|
+
directory;
|
|
41
|
+
nonce = randomBytes(16).toString('hex');
|
|
42
|
+
name = 'lw-pi-' + this.nonce;
|
|
43
|
+
#id = null;
|
|
44
|
+
#process = null;
|
|
45
|
+
#channel = null;
|
|
46
|
+
#bootWork = null;
|
|
47
|
+
#seccomp = '';
|
|
48
|
+
#snapshots = null;
|
|
49
|
+
#creationAttempted = false;
|
|
50
|
+
#closing = null;
|
|
51
|
+
#exited = null;
|
|
52
|
+
#closed = false;
|
|
53
|
+
#cleanupComplete = false;
|
|
54
|
+
#failed = false;
|
|
55
|
+
#pending = null;
|
|
56
|
+
constructor(host, input, broker, directory) {
|
|
57
|
+
this.host = host;
|
|
58
|
+
this.input = input;
|
|
59
|
+
this.broker = broker;
|
|
60
|
+
this.directory = directory;
|
|
61
|
+
}
|
|
62
|
+
async docker(args) {
|
|
63
|
+
const output = await exec(this.host.dockerExecutable, ['--config', join(this.directory, 'docker-client'), '--host', 'unix://' + this.host.dockerSocket, ...args], { timeout: 10000, maxBuffer: 1048576, env: { PATH: '/usr/local/bin:/usr/bin:/bin', HOME: this.directory, LANG: 'C.UTF-8' } });
|
|
64
|
+
return output.stdout;
|
|
65
|
+
}
|
|
66
|
+
async inspect(identity) { return JSON.parse(await this.docker(['inspect', identity]))[0]; }
|
|
67
|
+
start() {
|
|
68
|
+
if (this.#bootWork || this.#closed)
|
|
69
|
+
refuse('SESSION_BUSY');
|
|
70
|
+
const work = this.#boot();
|
|
71
|
+
this.#bootWork = work;
|
|
72
|
+
return work.catch(async (error) => { await this.close(); throw error; });
|
|
73
|
+
}
|
|
74
|
+
async #boot() {
|
|
75
|
+
if (!sameIdentity(await profileIdentity(), this.input.policy.runtime.configDigest))
|
|
76
|
+
refuse('RUNTIME_MISMATCH', '/policy/runtime/configDigest');
|
|
77
|
+
this.#seccomp = canonical(JSON.parse(await readFile(new URL('../runtime/seccomp.json', import.meta.url), 'utf8')));
|
|
78
|
+
const lockBytes = await readFile(new URL('../../../package-lock.json', import.meta.url));
|
|
79
|
+
if (!sameIdentity(digest(lockBytes), this.input.policy.runtime.graphDigest))
|
|
80
|
+
refuse('RUNTIME_MISMATCH', '/policy/runtime/graphDigest');
|
|
81
|
+
const image = JSON.parse(await this.docker(['image', 'inspect', this.input.policy.runtime.imageDigest]))[0];
|
|
82
|
+
if (image.Id !== this.input.policy.runtime.imageDigest || image.Os !== 'linux' || image.Architecture !== 'arm64' || image.Config.User !== '1000:1000' || !sameIdentity(image.Config.Entrypoint, ['node']))
|
|
83
|
+
refuse('RUNTIME_MISMATCH', '/policy/runtime/imageDigest');
|
|
84
|
+
await mkdir(this.directory, { mode: 0o700 });
|
|
85
|
+
await materializeCandidateDirectory(join(this.directory, 'candidate'), this.input);
|
|
86
|
+
const labels = { 'org.loopwright.generation': String(this.host.authority.generation), 'org.loopwright.run': this.input.lock.spec.runId, 'org.loopwright.session': this.input.sessionId, 'org.loopwright.nonce': this.nonce };
|
|
87
|
+
await writeFile(join(this.directory, 'container-intent.json'), JSON.stringify({ version: 1, name: this.name, nonce: this.nonce, labels, image: this.input.policy.runtime.imageDigest }), { flag: 'wx', mode: 0o600 });
|
|
88
|
+
const args = restrictedArguments(this.name, labels, join(this.directory, 'candidate'), this.input.policy.runtime.imageDigest, 'sdk', this.nonce);
|
|
89
|
+
await registerChild(this.host, { name: this.name, nonce: this.nonce, labels, image: this.input.policy.runtime.imageDigest });
|
|
90
|
+
this.#creationAttempted = true;
|
|
91
|
+
if (this.#closed)
|
|
92
|
+
refuse('CANCELLED');
|
|
93
|
+
this.#id = (await this.docker(args)).trim();
|
|
94
|
+
if (!/^[a-f0-9]{64}$/.test(this.#id))
|
|
95
|
+
refuse('CONTAINMENT_MISMATCH');
|
|
96
|
+
await writeFile(join(this.directory, 'container-id.json'), JSON.stringify({ id: this.#id, nonce: this.nonce }), { flag: 'wx', mode: 0o600 });
|
|
97
|
+
const inspected = await this.inspect(this.#id);
|
|
98
|
+
await writeFile(join(this.directory, 'inspect.json'), JSON.stringify(inspected), { mode: 0o600 });
|
|
99
|
+
this.#verify(inspected);
|
|
100
|
+
if (this.#closed)
|
|
101
|
+
refuse('CANCELLED');
|
|
102
|
+
const child = spawn(this.host.dockerExecutable, ['--config', join(this.directory, 'docker-client'), '--host', 'unix://' + this.host.dockerSocket, 'start', '--attach', '--interactive', this.#id], { stdio: ['pipe', 'pipe', 'pipe'], env: { PATH: '/usr/local/bin:/usr/bin:/bin', HOME: this.directory, LANG: 'C.UTF-8' } });
|
|
103
|
+
this.#process = child;
|
|
104
|
+
this.#exited = new Promise(resolve => { child.once('exit', (code, signal) => resolve({ code, signal })); child.once('error', () => { this.#fail(); resolve({ code: null, signal: null }); }); });
|
|
105
|
+
const diagnosticLimit = this.input.policy.limits.diagnosticBytes, retainedLimit = Math.floor((diagnosticLimit - 64) * 3 / 4);
|
|
106
|
+
let stderrBytes = 0, retained = Buffer.alloc(0);
|
|
107
|
+
child.stderr.on('data', (data) => {
|
|
108
|
+
stderrBytes += data.length;
|
|
109
|
+
const keep = Math.min(data.length, Math.max(0, retainedLimit - retained.length));
|
|
110
|
+
if (keep)
|
|
111
|
+
retained = Buffer.concat([retained, data.subarray(0, keep)]);
|
|
112
|
+
try {
|
|
113
|
+
if (this.input.policy.privateArtifacts)
|
|
114
|
+
writeFileSync(join(this.directory, 'private-sdk-stderr'), JSON.stringify({ encoding: 'base64', truncated: stderrBytes > retained.length, data: retained.toString('base64') }) + '\n', { mode: 0o600 });
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
this.#fail();
|
|
118
|
+
}
|
|
119
|
+
if (stderrBytes > diagnosticLimit) {
|
|
120
|
+
this.broker.runtimeFault?.('OUTPUT_LIMIT');
|
|
121
|
+
this.#fail();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
this.#channel = new Channel(this.nonce, child.stdout, child.stdin);
|
|
125
|
+
this.#snapshots = new SnapshotTransfer(this.#channel);
|
|
126
|
+
this.#channel.on('failed', () => this.#fail());
|
|
127
|
+
this.#channel.on('message', (message) => { void this.#receive(message).catch(() => this.#fail()); });
|
|
128
|
+
await registerAttach(this.host, this.nonce, child.pid);
|
|
129
|
+
const restored = await recoverSnapshot(this.host, this.input);
|
|
130
|
+
if (restored) {
|
|
131
|
+
const accepted = this.#wait('restore-ready');
|
|
132
|
+
await this.#channel.send('restore-start', { selection: this.input.policy.selection, toolNames: this.input.policy.tools, sessionBytes: this.input.policy.limits.sessionBytes });
|
|
133
|
+
await accepted;
|
|
134
|
+
async function* chunks() { yield restored.native; }
|
|
135
|
+
const complete = this.#wait('restore-complete', 90000);
|
|
136
|
+
await this.#snapshots.send(1, chunks(), this.input.policy.limits.sessionBytes);
|
|
137
|
+
await complete;
|
|
138
|
+
}
|
|
139
|
+
const ready = this.#wait('ready');
|
|
140
|
+
const [, response] = await Promise.all([this.#channel.send('init', { selection: this.input.policy.selection, systemPrompt: systemPrompt(this.input), toolNames: this.input.policy.tools, mcp: this.input.policy.mcp, toolResultBytes: this.input.policy.limits.toolResultBytes, sessionBytes: this.input.policy.limits.sessionBytes, outputTokens: Math.min(this.input.lock.spec.contract.spec.budgets.perCallOutputTokens, this.input.policy.context.maxOutputTokens), contextPolicy: this.input.policy.context }), ready]);
|
|
141
|
+
const facts = response;
|
|
142
|
+
if (!sameIdentity(facts.selection, this.input.policy.selection) || facts.thinkingLevel !== this.input.policy.selection.thinking || facts.node !== 'v26.13.0' || facts.platform !== 'linux' || facts.architecture !== 'arm64')
|
|
143
|
+
refuse('RUNTIME_MISMATCH');
|
|
144
|
+
return freeze({ version: 1, policyDigest: digest(Buffer.from(canonical(this.input.policy))), runtime: this.input.policy.runtime,
|
|
145
|
+
requested: this.input.policy.selection, catalogSupported: structuredClone(this.input.policy.selection), sessionEffective: structuredClone(this.input.policy.selection), outboundObserved: null,
|
|
146
|
+
resources: this.input.policy.resources, accounting: 'soft_only', contextFit: 'unproven', defaultMode: 'proven_bound', liveProvenBoundAvailable: false, optInMode: 'estimated_guard', contextEstimator: { id: 'lw-pi-final-json-bytes-v1', version: 1, provenance: 'estimated' }, toolExecution: { candidate: 'read_only', candidateWrites: 'mediated', scratch: 'per_call' } });
|
|
147
|
+
}
|
|
148
|
+
#verifyOwnership(value) {
|
|
149
|
+
const config = value.Config;
|
|
150
|
+
if (value.Id !== this.#id || value.Image !== this.input.policy.runtime.imageDigest || value.Name !== '/' + this.name || config.Labels['org.loopwright.generation'] !== String(this.host.authority.generation) || config.Labels['org.loopwright.nonce'] !== this.nonce || config.Labels['org.loopwright.run'] !== this.input.lock.spec.runId || config.Labels['org.loopwright.session'] !== this.input.sessionId)
|
|
151
|
+
refuse('CONTAINMENT_MISMATCH');
|
|
152
|
+
}
|
|
153
|
+
#verify(value) {
|
|
154
|
+
this.#verifyOwnership(value);
|
|
155
|
+
verifyRestrictions(value, join(this.directory, 'candidate'), this.#seccomp);
|
|
156
|
+
}
|
|
157
|
+
#wait(kind, timeoutMs = 10000, remaining) {
|
|
158
|
+
if (this.#pending)
|
|
159
|
+
refuse('SESSION_BUSY', '', { phase: 'session' });
|
|
160
|
+
if (this.#failed)
|
|
161
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'session' });
|
|
162
|
+
return new Promise((resolve, reject) => {
|
|
163
|
+
let stop = () => { };
|
|
164
|
+
const expires = performance.now() + timeoutMs;
|
|
165
|
+
this.#pending = { kind, resolve: value => { stop(); this.#pending = null; resolve(value); }, reject: error => { stop(); this.#pending = null; reject(error); } };
|
|
166
|
+
stop = scheduleDeadline(remaining ?? (() => expires - performance.now()), () => { this.#pending = null; reject(new PiFailure({ code: 'DEADLINE', path: '', phase: 'session', retryable: false, effect: 'possible', requestId: null, operationId: null, stateErrorCode: null })); this.#fail(); });
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async #receive(message) {
|
|
170
|
+
if (this.#closed)
|
|
171
|
+
throw new Error('Closed SDK channel');
|
|
172
|
+
if (await this.#snapshots.receive(message))
|
|
173
|
+
return;
|
|
174
|
+
if (await receiveBrokerMessage(this.#channel, this.broker, message))
|
|
175
|
+
return;
|
|
176
|
+
if (message.kind === 'refused') {
|
|
177
|
+
this.#snapshots?.close();
|
|
178
|
+
const body = message.body;
|
|
179
|
+
const code = body.code === 'MODEL_UNAVAILABLE' || body.code === 'THINKING_UNSUPPORTED' ? body.code : 'PROVIDER_RESPONSE_INVALID';
|
|
180
|
+
this.#pending?.reject(new PiFailure({ code, path: '/policy/selection', phase: 'session', retryable: false, effect: 'none', requestId: null, operationId: null, stateErrorCode: null }));
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (!this.#pending || message.kind !== this.#pending.kind)
|
|
184
|
+
throw new Error('Unrequested SDK result');
|
|
185
|
+
this.#pending.resolve(message.body);
|
|
186
|
+
}
|
|
187
|
+
#fail() { if (!this.#closed) {
|
|
188
|
+
this.#failed = true;
|
|
189
|
+
this.#snapshots?.close();
|
|
190
|
+
this.#pending?.reject(new Error('SDK channel failed'));
|
|
191
|
+
} }
|
|
192
|
+
async command(kind, body) {
|
|
193
|
+
if (this.#closed || !this.#channel)
|
|
194
|
+
refuse('CANCELLED', '', { phase: 'session' });
|
|
195
|
+
const view = stateValue(this.host.store.inspect(), 'session'), remaining = view.clock.remainingTaskMs.safeValue;
|
|
196
|
+
if (remaining === null || remaining <= 0)
|
|
197
|
+
refuse('DEADLINE', '', { phase: 'session' });
|
|
198
|
+
const pending = this.#wait('settled', undefined, () => { const current = this.host.store.inspect(); return current.ok && current.value.clockStatus === 'trusted' ? current.value.clock.remainingTaskMs.safeValue : null; });
|
|
199
|
+
const [, response] = await Promise.all([this.#channel.send(kind, body), pending]);
|
|
200
|
+
verifyNativeCompletion(response.native, kind);
|
|
201
|
+
return response;
|
|
202
|
+
}
|
|
203
|
+
async capture(sink) {
|
|
204
|
+
if (this.#closed || !this.#channel || !this.#snapshots)
|
|
205
|
+
refuse('CANCELLED');
|
|
206
|
+
const view = stateValue(this.host.store.inspect(), 'restore'), remaining = view.clock.remainingTaskMs.safeValue;
|
|
207
|
+
if (remaining === null || remaining <= 0)
|
|
208
|
+
refuse('DEADLINE');
|
|
209
|
+
const expected = this.#snapshots.expect(sink, this.input.policy.limits.sessionBytes, Math.min(90000, remaining));
|
|
210
|
+
try {
|
|
211
|
+
await this.#channel.send('capture', { query: expected.query });
|
|
212
|
+
await expected.done;
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
this.#snapshots.close();
|
|
216
|
+
if (error instanceof PiFailure && error.detail.code !== 'INPUT_INVALID')
|
|
217
|
+
throw error;
|
|
218
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
close() {
|
|
222
|
+
if (this.#closing)
|
|
223
|
+
return this.#closing;
|
|
224
|
+
const attempt = this.#cleanup();
|
|
225
|
+
this.#closing = attempt;
|
|
226
|
+
void attempt.then(() => { this.#closing = null; }, () => { this.#closing = null; });
|
|
227
|
+
return attempt;
|
|
228
|
+
}
|
|
229
|
+
async #cleanup() {
|
|
230
|
+
if (this.#cleanupComplete)
|
|
231
|
+
return;
|
|
232
|
+
this.#closed = true;
|
|
233
|
+
this.#snapshots?.close();
|
|
234
|
+
this.#pending?.reject(new Error('closed'));
|
|
235
|
+
await this.#bootWork?.catch(() => { });
|
|
236
|
+
try {
|
|
237
|
+
try {
|
|
238
|
+
if (this.#channel) {
|
|
239
|
+
try {
|
|
240
|
+
await this.#channel.send('close', null);
|
|
241
|
+
}
|
|
242
|
+
catch { /* exact engine cleanup follows */ }
|
|
243
|
+
this.#channel.close();
|
|
244
|
+
}
|
|
245
|
+
if (this.#exited) {
|
|
246
|
+
let timer;
|
|
247
|
+
try {
|
|
248
|
+
await Promise.race([this.#exited, new Promise(resolve => { timer = setTimeout(resolve, 2000); })]);
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
clearTimeout(timer);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (!this.#creationAttempted) {
|
|
255
|
+
this.#cleanupComplete = true;
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const identity = this.#id ?? this.name;
|
|
259
|
+
let inspected;
|
|
260
|
+
try {
|
|
261
|
+
inspected = await this.inspect(identity);
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
if (this.#id === null && this.#process === null && isAbsentContainer(identity, error)) {
|
|
265
|
+
await exitChild(this.host, this.nonce);
|
|
266
|
+
this.#cleanupComplete = true;
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
const id = inspected.Id;
|
|
272
|
+
this.#id = id;
|
|
273
|
+
this.#verifyOwnership(inspected);
|
|
274
|
+
if (inspected.State.Running)
|
|
275
|
+
await this.docker(['kill', id]);
|
|
276
|
+
const stopped = await this.inspect(id);
|
|
277
|
+
this.#verifyOwnership(stopped);
|
|
278
|
+
if (stopped.State.Running || !Number.isInteger(stopped.State.ExitCode))
|
|
279
|
+
refuse('CLEANUP_FAILED', '', { phase: 'cleanup' });
|
|
280
|
+
await this.docker(['rm', id]);
|
|
281
|
+
try {
|
|
282
|
+
await this.inspect(id);
|
|
283
|
+
refuse('CLEANUP_FAILED');
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
if (!isAbsentContainer(id, error))
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
await writeFile(join(this.directory, 'cleanup.json'), JSON.stringify({ id, nonce: this.nonce, removed: true, absenceConfirmed: true, state: stopped.State }), { mode: 0o600 });
|
|
290
|
+
}
|
|
291
|
+
finally {
|
|
292
|
+
this.#process?.stdin.destroy();
|
|
293
|
+
this.#process?.stdout.destroy();
|
|
294
|
+
this.#process?.stderr.destroy();
|
|
295
|
+
if (this.#process?.exitCode === null && this.#process.signalCode === null)
|
|
296
|
+
this.#process.kill('SIGKILL');
|
|
297
|
+
if (this.#exited) {
|
|
298
|
+
let timer;
|
|
299
|
+
try {
|
|
300
|
+
const exit = await Promise.race([this.#exited, new Promise((_, reject) => { timer = setTimeout(() => reject(new Error('Docker CLI cleanup deadline')), 2000); })]);
|
|
301
|
+
await writeFile(join(this.directory, 'cli-exit.json'), JSON.stringify(exit), { mode: 0o600 });
|
|
302
|
+
}
|
|
303
|
+
finally {
|
|
304
|
+
clearTimeout(timer);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
await exitChild(this.host, this.nonce);
|
|
309
|
+
this.#cleanupComplete = true;
|
|
310
|
+
}
|
|
311
|
+
finally {
|
|
312
|
+
await setDirectoryTreeMode(join(this.directory, 'candidate'), 0o755).catch(() => { });
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Channel, type ChannelMessage } from './protocol.js';
|
|
2
|
+
/** A single acknowledged 32 KiB chunk is in flight; aggregate snapshots need no large protocol message. */
|
|
3
|
+
export declare class SnapshotTransfer {
|
|
4
|
+
#private;
|
|
5
|
+
readonly channel: Channel;
|
|
6
|
+
constructor(channel: Channel);
|
|
7
|
+
expect(sink: (bytes: Uint8Array) => Promise<void>, max: number, timeout: number): {
|
|
8
|
+
query: number;
|
|
9
|
+
done: Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
send(query: number, chunks: AsyncIterable<Uint8Array>, max: number, beforeEnd?: () => void): Promise<void>;
|
|
12
|
+
receive(message: ChannelMessage): Promise<boolean>;
|
|
13
|
+
close(error?: unknown): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { object, integer, text } from './boundary.js';
|
|
3
|
+
import { refuse } from './errors.js';
|
|
4
|
+
/** A single acknowledged 32 KiB chunk is in flight; aggregate snapshots need no large protocol message. */
|
|
5
|
+
export class SnapshotTransfer {
|
|
6
|
+
channel;
|
|
7
|
+
#ordinal = 0;
|
|
8
|
+
#incoming = null;
|
|
9
|
+
#ack = null;
|
|
10
|
+
constructor(channel) {
|
|
11
|
+
this.channel = channel;
|
|
12
|
+
}
|
|
13
|
+
expect(sink, max, timeout) {
|
|
14
|
+
if (this.#incoming)
|
|
15
|
+
refuse('SESSION_BUSY');
|
|
16
|
+
const query = ++this.#ordinal;
|
|
17
|
+
const done = new Promise((resolve, reject) => { const timer = setTimeout(() => this.close(), timeout); this.#incoming = { query, index: 0, bytes: 0, max, busy: false, hash: createHash('sha256'), sink, resolve, reject, timer }; });
|
|
18
|
+
void done.catch(() => { });
|
|
19
|
+
return { query, done };
|
|
20
|
+
}
|
|
21
|
+
async send(query, chunks, max, beforeEnd = () => { }) {
|
|
22
|
+
const hash = createHash('sha256');
|
|
23
|
+
let length = 0, index = 0;
|
|
24
|
+
for await (const chunk of chunks) {
|
|
25
|
+
for (let offset = 0; offset < chunk.length; offset += 32768) {
|
|
26
|
+
const bytes = chunk.subarray(offset, offset + 32768);
|
|
27
|
+
length += bytes.length;
|
|
28
|
+
if (length > max || this.#ack)
|
|
29
|
+
refuse('OUTPUT_LIMIT');
|
|
30
|
+
hash.update(bytes);
|
|
31
|
+
let timer;
|
|
32
|
+
const ack = new Promise((resolve, reject) => { this.#ack = { query, index, resolve, reject }; timer = setTimeout(() => this.close(), 10000); });
|
|
33
|
+
void ack.catch(() => { });
|
|
34
|
+
try {
|
|
35
|
+
await this.channel.sendBytes('snapshot-chunk', { query, index }, bytes);
|
|
36
|
+
await ack;
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
clearTimeout(timer);
|
|
40
|
+
this.#ack = null;
|
|
41
|
+
}
|
|
42
|
+
index++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
beforeEnd();
|
|
46
|
+
await this.channel.send('snapshot-end', { query, chunks: index, byteLength: length, digest: hash.digest('hex') });
|
|
47
|
+
}
|
|
48
|
+
async receive(message) {
|
|
49
|
+
if (message.kind === 'snapshot-ack') {
|
|
50
|
+
const value = object(message.body, ['query', 'index']), ack = this.#ack;
|
|
51
|
+
if (!ack || value.query !== ack.query || value.index !== ack.index)
|
|
52
|
+
refuse('RECOVERY_REQUIRED');
|
|
53
|
+
this.#ack = null;
|
|
54
|
+
ack.resolve();
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (message.kind !== 'snapshot-chunk' && message.kind !== 'snapshot-end')
|
|
58
|
+
return false;
|
|
59
|
+
const incoming = this.#incoming;
|
|
60
|
+
if (!incoming || incoming.busy)
|
|
61
|
+
refuse('RECOVERY_REQUIRED');
|
|
62
|
+
incoming.busy = true;
|
|
63
|
+
try {
|
|
64
|
+
if (message.kind === 'snapshot-chunk') {
|
|
65
|
+
const value = message.body, meta = object(value.metadata, ['query', 'index']);
|
|
66
|
+
if (meta.query !== incoming.query || meta.index !== incoming.index || !(value.bytes instanceof Uint8Array) || value.bytes.length === 0 || value.bytes.length > 32768 || incoming.bytes + value.bytes.length > incoming.max)
|
|
67
|
+
refuse('RECOVERY_REQUIRED');
|
|
68
|
+
incoming.bytes += value.bytes.length;
|
|
69
|
+
incoming.hash.update(value.bytes);
|
|
70
|
+
await incoming.sink(value.bytes);
|
|
71
|
+
incoming.busy = false;
|
|
72
|
+
await this.channel.send('snapshot-ack', { query: incoming.query, index: incoming.index++ });
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const value = object(message.body, ['query', 'chunks', 'byteLength', 'digest']);
|
|
76
|
+
integer(value.chunks, 0, 8192);
|
|
77
|
+
integer(value.byteLength, 0, incoming.max);
|
|
78
|
+
text(value.digest);
|
|
79
|
+
if (value.query !== incoming.query || value.chunks !== incoming.index || value.byteLength !== incoming.bytes || value.digest !== incoming.hash.digest('hex'))
|
|
80
|
+
refuse('RECOVERY_REQUIRED');
|
|
81
|
+
clearTimeout(incoming.timer);
|
|
82
|
+
this.#incoming = null;
|
|
83
|
+
incoming.resolve();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
this.close(error);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
close(error = new Error('Snapshot transfer closed')) {
|
|
93
|
+
const incoming = this.#incoming;
|
|
94
|
+
this.#incoming = null;
|
|
95
|
+
if (incoming) {
|
|
96
|
+
clearTimeout(incoming.timer);
|
|
97
|
+
incoming.reject(error);
|
|
98
|
+
}
|
|
99
|
+
this.#ack?.reject(error);
|
|
100
|
+
this.#ack = null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type FileEntry } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import type { AdapterPolicy } from './types.js';
|
|
3
|
+
/** Private snapshot rows carry passive native data, not JSON schemas or executable loaders. */
|
|
4
|
+
export declare function snapshotRow(bytes: Uint8Array): Record<string, unknown>;
|
|
5
|
+
export declare function rowBytes(value: unknown): Buffer;
|
|
6
|
+
export type SnapshotPolicy = Pick<AdapterPolicy, 'selection' | 'tools'> & {
|
|
7
|
+
readonly limits: Pick<AdapterPolicy['limits'], 'sessionBytes'>;
|
|
8
|
+
};
|
|
9
|
+
/** The SDK parser skips malformed lines; the adapter instead validates every owned row and graph edge. */
|
|
10
|
+
export declare class NativeSnapshot {
|
|
11
|
+
#private;
|
|
12
|
+
readonly policy: SnapshotPolicy;
|
|
13
|
+
readonly maxBytes: number;
|
|
14
|
+
readonly retain: boolean;
|
|
15
|
+
constructor(policy: SnapshotPolicy, maxBytes?: number, retain?: boolean);
|
|
16
|
+
push(bytes: Uint8Array): void;
|
|
17
|
+
finish(): FileEntry[];
|
|
18
|
+
}
|
|
19
|
+
export declare function sameSnapshotValue(left: unknown, right: unknown): boolean;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { CURRENT_SESSION_VERSION } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import { parseBoundedJson } from './context.js';
|
|
3
|
+
import { object, canonical } from './boundary.js';
|
|
4
|
+
import { refuse } from './errors.js';
|
|
5
|
+
/** Private snapshot rows carry passive native data, not JSON schemas or executable loaders. */
|
|
6
|
+
export function snapshotRow(bytes) {
|
|
7
|
+
if (bytes.length > 8388608)
|
|
8
|
+
refuse('OUTPUT_LIMIT', '', { phase: 'restore' });
|
|
9
|
+
try {
|
|
10
|
+
const value = parseBoundedJson(new TextDecoder('utf-8', { fatal: true }).decode(bytes), { nodes: 524288, array: 16384, schemaReferences: false });
|
|
11
|
+
return object(value, Object.keys(value));
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function rowBytes(value) {
|
|
18
|
+
let bytes;
|
|
19
|
+
try {
|
|
20
|
+
bytes = Buffer.from(JSON.stringify(value) + '\n');
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
refuse('OUTPUT_LIMIT', '', { phase: 'restore' });
|
|
24
|
+
}
|
|
25
|
+
snapshotRow(bytes);
|
|
26
|
+
return bytes;
|
|
27
|
+
}
|
|
28
|
+
/** The SDK parser skips malformed lines; the adapter instead validates every owned row and graph edge. */
|
|
29
|
+
export class NativeSnapshot {
|
|
30
|
+
policy;
|
|
31
|
+
maxBytes;
|
|
32
|
+
retain;
|
|
33
|
+
#ids = new Set();
|
|
34
|
+
#entries = [];
|
|
35
|
+
#tools = new Set();
|
|
36
|
+
#header = false;
|
|
37
|
+
#headerId = '';
|
|
38
|
+
#bytes = 0;
|
|
39
|
+
#count = 0;
|
|
40
|
+
#partial = Buffer.alloc(0);
|
|
41
|
+
#finished = false;
|
|
42
|
+
constructor(policy, maxBytes = policy.limits.sessionBytes, retain = true) {
|
|
43
|
+
this.policy = policy;
|
|
44
|
+
this.maxBytes = maxBytes;
|
|
45
|
+
this.retain = retain;
|
|
46
|
+
}
|
|
47
|
+
push(bytes) {
|
|
48
|
+
if (this.#finished || (this.#bytes += bytes.byteLength) > this.maxBytes)
|
|
49
|
+
refuse('OUTPUT_LIMIT', '', { phase: 'restore' });
|
|
50
|
+
let offset = 0;
|
|
51
|
+
const data = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
52
|
+
while (offset < data.length) {
|
|
53
|
+
const end = data.indexOf(10, offset), part = data.subarray(offset, end < 0 ? data.length : end);
|
|
54
|
+
if (this.#partial.length + part.length > 8388608)
|
|
55
|
+
refuse('OUTPUT_LIMIT', '', { phase: 'restore' });
|
|
56
|
+
this.#partial = Buffer.concat([this.#partial, part]);
|
|
57
|
+
offset += part.length + (end < 0 ? 0 : 1);
|
|
58
|
+
if (end < 0)
|
|
59
|
+
break;
|
|
60
|
+
this.#accept(snapshotRow(this.#partial));
|
|
61
|
+
this.#partial = Buffer.alloc(0);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
#accept(value) {
|
|
65
|
+
if (this.#count++ >= 8192 || typeof value.id !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(value.id) || typeof value.timestamp !== 'string' || !Number.isFinite(Date.parse(value.timestamp)))
|
|
66
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
67
|
+
if (!this.#header) {
|
|
68
|
+
const item = object(value, ['type', 'version', 'id', 'timestamp', 'cwd']);
|
|
69
|
+
if (item.type !== 'session' || item.version !== CURRENT_SESSION_VERSION || item.cwd !== '/workspace/candidate')
|
|
70
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
71
|
+
this.#header = true;
|
|
72
|
+
this.#headerId = value.id;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (typeof value.type !== 'string' || !['message', 'thinking_level_change', 'model_change', 'usage', 'compaction', 'branch_summary', 'custom', 'custom_message', 'label', 'context_edit', 'session_info'].includes(value.type)
|
|
76
|
+
|| value.parentId !== null && (typeof value.parentId !== 'string' || !this.#ids.has(value.parentId)) || this.#ids.has(value.id) || value.id === this.#headerId)
|
|
77
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
78
|
+
if (value.type === 'model_change' && (value.provider !== this.policy.selection.provider || value.modelId !== this.policy.selection.model) || value.type === 'thinking_level_change' && value.thinkingLevel !== this.policy.selection.thinking)
|
|
79
|
+
refuse('BINDING_MISMATCH', '', { phase: 'restore' });
|
|
80
|
+
if (value.type === 'compaction' && (typeof value.summary !== 'string' || typeof value.firstKeptEntryId !== 'string' || !this.#ids.has(value.firstKeptEntryId)))
|
|
81
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
82
|
+
if (value.type === 'context_edit' || value.type === 'label')
|
|
83
|
+
if (typeof value.targetId !== 'string' || !this.#ids.has(value.targetId))
|
|
84
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
85
|
+
if (value.type === 'message') {
|
|
86
|
+
const message = value.message;
|
|
87
|
+
if (!message || typeof message !== 'object' || !['user', 'assistant', 'toolResult', 'system'].includes(message.role))
|
|
88
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
89
|
+
if (message.role === 'toolResult') {
|
|
90
|
+
if (typeof message.toolCallId !== 'string' || !this.#tools.delete(message.toolCallId))
|
|
91
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' });
|
|
92
|
+
}
|
|
93
|
+
if (message.role === 'assistant') {
|
|
94
|
+
if (!Array.isArray(message.content))
|
|
95
|
+
refuse('RECOVERY_REQUIRED');
|
|
96
|
+
let calls = 0;
|
|
97
|
+
for (const block of message.content) {
|
|
98
|
+
if (!block || typeof block !== 'object')
|
|
99
|
+
refuse('RECOVERY_REQUIRED');
|
|
100
|
+
if (block.type === 'toolCall') {
|
|
101
|
+
if (typeof block.id !== 'string' || block.id.length > 256 || !block.id || typeof block.name !== 'string' || !this.policy.tools.includes(block.name) || this.#tools.has(block.id))
|
|
102
|
+
refuse('RECOVERY_REQUIRED');
|
|
103
|
+
this.#tools.add(block.id);
|
|
104
|
+
calls++;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (message.stopReason === 'toolUse' && calls === 0 || message.stopReason === 'stop' && calls !== 0)
|
|
108
|
+
refuse('RECOVERY_REQUIRED');
|
|
109
|
+
}
|
|
110
|
+
if (message.role === 'assistant' && (message.provider !== this.policy.selection.provider || message.model !== this.policy.selection.model || message.api !== this.policy.selection.api || !['stop', 'toolUse'].includes(message.stopReason)))
|
|
111
|
+
refuse('BINDING_MISMATCH', '', { phase: 'restore' });
|
|
112
|
+
}
|
|
113
|
+
this.#ids.add(value.id);
|
|
114
|
+
}
|
|
115
|
+
if (this.retain)
|
|
116
|
+
this.#entries.push(value);
|
|
117
|
+
}
|
|
118
|
+
finish() { if (!this.#header || this.#partial.length || this.#finished || this.#tools.size)
|
|
119
|
+
refuse('RECOVERY_REQUIRED', '', { phase: 'restore' }); this.#finished = true; return this.#entries; }
|
|
120
|
+
}
|
|
121
|
+
export function sameSnapshotValue(left, right) { return canonical(left) === canonical(right); }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { OwnedContainer, type ContainerExit } from './containers.js';
|
|
2
|
+
import type { PiHost, PiOpenInput, PiErrorCode } from './types.js';
|
|
3
|
+
import type { ToolResult } from './tools.js';
|
|
4
|
+
export interface ToolProcessReply {
|
|
5
|
+
readonly result: ToolResult;
|
|
6
|
+
readonly code: PiErrorCode | null;
|
|
7
|
+
readonly produced: number;
|
|
8
|
+
}
|
|
9
|
+
export interface ToolProcessPort {
|
|
10
|
+
ready(): Promise<void>;
|
|
11
|
+
execute(name: 'read' | 'bash', bytes: Uint8Array, read: {
|
|
12
|
+
readonly path: string;
|
|
13
|
+
readonly digest: string;
|
|
14
|
+
} | null, guard: () => void): Promise<ToolProcessReply>;
|
|
15
|
+
close(): Promise<ContainerExit | null>;
|
|
16
|
+
}
|
|
17
|
+
/** Host-only control for a single contained native tool invocation. */
|
|
18
|
+
export declare class ToolProcess implements ToolProcessPort {
|
|
19
|
+
#private;
|
|
20
|
+
readonly host: PiHost;
|
|
21
|
+
readonly input: PiOpenInput;
|
|
22
|
+
readonly directory: string;
|
|
23
|
+
readonly signal: AbortSignal;
|
|
24
|
+
readonly container: OwnedContainer;
|
|
25
|
+
constructor(host: PiHost, input: PiOpenInput, directory: string, candidate: string, operationId: string, signal: AbortSignal);
|
|
26
|
+
ready(): Promise<void>;
|
|
27
|
+
execute(name: 'read' | 'bash', bytes: Uint8Array, read: {
|
|
28
|
+
readonly path: string;
|
|
29
|
+
readonly digest: string;
|
|
30
|
+
} | null, guard: () => void): Promise<ToolProcessReply>;
|
|
31
|
+
close(): Promise<ContainerExit | null>;
|
|
32
|
+
}
|