@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,526 @@
|
|
|
1
|
+
import { constants as fsConstants } from 'node:fs';
|
|
2
|
+
import { access, lstat, realpath } from 'node:fs/promises';
|
|
3
|
+
import { delimiter, isAbsolute, join, resolve, sep } from 'node:path';
|
|
4
|
+
import { McpClient, StdioTransport, StreamableHttpTransport, toLlmContent, } from '@earendil-works/pi-mcp';
|
|
5
|
+
import { list } from './boundary.js';
|
|
6
|
+
import { refuse } from './errors.js';
|
|
7
|
+
import { clampToolResultBytes } from './tools.js';
|
|
8
|
+
export const EXTERNAL_MCP_TOOL_NAME_PATTERN = /^mcp__([a-z][a-z0-9]*(?:[_-][a-z0-9]+)*)__([A-Za-z0-9_]+(?:-[A-Za-z0-9_]+)*)$/;
|
|
9
|
+
const MCP_SERVER_ID_PATTERN = /^[a-z][a-z0-9]*(?:[_-][a-z0-9]+)*$/;
|
|
10
|
+
const MAX_MCP_SERVER_ID_LENGTH = 24;
|
|
11
|
+
const MAX_PROVIDER_TOOL_NAME_LENGTH = 64;
|
|
12
|
+
const BARE_EXECUTABLE_PATTERN = /^[A-Za-z0-9._+-]{1,128}$/;
|
|
13
|
+
const DEFAULT_TRUSTED_PATH = '/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin';
|
|
14
|
+
const DEFAULT_MCP_TIMEOUT_MS = 30_000;
|
|
15
|
+
const MAX_MCP_MESSAGE_BYTES = 16_777_216;
|
|
16
|
+
const MAX_MCP_STDERR_BYTES = 65_536;
|
|
17
|
+
const MAX_TOOLS_PER_SERVER = 64;
|
|
18
|
+
const MAX_TOTAL_EXTERNAL_MCP_TOOLS = 120;
|
|
19
|
+
export function parseExternalMcpServerId(name) {
|
|
20
|
+
if (typeof name !== 'string' || name.length > MAX_PROVIDER_TOOL_NAME_LENGTH)
|
|
21
|
+
return null;
|
|
22
|
+
const match = EXTERNAL_MCP_TOOL_NAME_PATTERN.exec(name);
|
|
23
|
+
if (match === null || match[1] === 'workspace' || match[1].length > MAX_MCP_SERVER_ID_LENGTH) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return match[1];
|
|
27
|
+
}
|
|
28
|
+
export function isExternalMcpToolName(name) {
|
|
29
|
+
return parseExternalMcpServerId(name) !== null;
|
|
30
|
+
}
|
|
31
|
+
export function validateAllowedMcpServers(allowedServers, path = '/options/allowedMcpServers') {
|
|
32
|
+
if (allowedServers === undefined)
|
|
33
|
+
return null;
|
|
34
|
+
const items = list(allowedServers, 128, path);
|
|
35
|
+
const serverSet = new Set();
|
|
36
|
+
for (let index = 0; index < items.length; index++) {
|
|
37
|
+
const serverId = items[index];
|
|
38
|
+
if (typeof serverId !== 'string'
|
|
39
|
+
|| serverId.length === 0
|
|
40
|
+
|| serverId.length > MAX_MCP_SERVER_ID_LENGTH
|
|
41
|
+
|| serverId === 'workspace'
|
|
42
|
+
|| !MCP_SERVER_ID_PATTERN.test(serverId)) {
|
|
43
|
+
refuse('INPUT_INVALID', `${path}/${index}`);
|
|
44
|
+
}
|
|
45
|
+
serverSet.add(serverId);
|
|
46
|
+
}
|
|
47
|
+
return serverSet;
|
|
48
|
+
}
|
|
49
|
+
export function createRoleMcpAllowlist(options) {
|
|
50
|
+
const roleTools = new Set(options.roleTools);
|
|
51
|
+
const policyTools = new Set(options.policyTools);
|
|
52
|
+
const allowedServers = validateAllowedMcpServers(options.allowedServers);
|
|
53
|
+
const isToolAllowed = (name, serverId) => {
|
|
54
|
+
const parsedServerId = parseExternalMcpServerId(name);
|
|
55
|
+
if (parsedServerId === null)
|
|
56
|
+
return false;
|
|
57
|
+
if (serverId !== undefined && serverId !== null && serverId !== parsedServerId)
|
|
58
|
+
return false;
|
|
59
|
+
if (!roleTools.has(name) || !policyTools.has(name))
|
|
60
|
+
return false;
|
|
61
|
+
if (allowedServers !== null && !allowedServers.has(parsedServerId))
|
|
62
|
+
return false;
|
|
63
|
+
return true;
|
|
64
|
+
};
|
|
65
|
+
return Object.freeze({
|
|
66
|
+
allowedServers,
|
|
67
|
+
isToolAllowed,
|
|
68
|
+
filterToolNames: (toolNames) => Object.freeze(toolNames.filter(name => !isExternalMcpToolName(name) || isToolAllowed(name))),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function isRoleMcpAllowlist(value) {
|
|
72
|
+
return 'isToolAllowed' in value && typeof value.isToolAllowed === 'function';
|
|
73
|
+
}
|
|
74
|
+
export function createRoleScopedMcpExecutor(registry, allowlistOrOptions) {
|
|
75
|
+
const allowlist = isRoleMcpAllowlist(allowlistOrOptions)
|
|
76
|
+
? allowlistOrOptions
|
|
77
|
+
: createRoleMcpAllowlist(allowlistOrOptions);
|
|
78
|
+
const resolveServerId = (name) => {
|
|
79
|
+
const parsed = parseExternalMcpServerId(name);
|
|
80
|
+
if (parsed === null)
|
|
81
|
+
return null;
|
|
82
|
+
const identity = registry.targetIdentityFor(name);
|
|
83
|
+
if (identity !== null) {
|
|
84
|
+
if (!identity.startsWith('mcp:'))
|
|
85
|
+
return null;
|
|
86
|
+
const colon = identity.indexOf(':', 4);
|
|
87
|
+
if (colon <= 4)
|
|
88
|
+
return null;
|
|
89
|
+
const identityServerId = identity.slice(4, colon);
|
|
90
|
+
if (identityServerId !== parsed)
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
else if (registry.hasTool(name)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return parsed;
|
|
97
|
+
};
|
|
98
|
+
return Object.freeze({
|
|
99
|
+
hasTool(name) {
|
|
100
|
+
const serverId = resolveServerId(name);
|
|
101
|
+
return serverId !== null && allowlist.isToolAllowed(name, serverId) && registry.hasTool(name);
|
|
102
|
+
},
|
|
103
|
+
targetIdentityFor(name) {
|
|
104
|
+
const serverId = resolveServerId(name);
|
|
105
|
+
if (serverId === null || !allowlist.isToolAllowed(name, serverId))
|
|
106
|
+
return null;
|
|
107
|
+
return registry.targetIdentityFor(name);
|
|
108
|
+
},
|
|
109
|
+
async callTool(name, args, options) {
|
|
110
|
+
const serverId = resolveServerId(name);
|
|
111
|
+
if (serverId === null || !allowlist.isToolAllowed(name, serverId)) {
|
|
112
|
+
refuse('TOOL_DENIED', `/mcp/${name}`, { phase: 'tool' });
|
|
113
|
+
}
|
|
114
|
+
return registry.callTool(name, args, options);
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function isInsideRoot(targetPath, rootPath) {
|
|
119
|
+
const normalizedRoot = rootPath.endsWith(sep) ? rootPath.slice(0, -1) : rootPath;
|
|
120
|
+
return targetPath === normalizedRoot || targetPath.startsWith(`${normalizedRoot}${sep}`);
|
|
121
|
+
}
|
|
122
|
+
async function resolveCanonicalUntrustedRoots(roots) {
|
|
123
|
+
if (!roots || roots.length === 0)
|
|
124
|
+
return [];
|
|
125
|
+
const resolved = [];
|
|
126
|
+
for (const root of roots) {
|
|
127
|
+
const abs = resolve(root);
|
|
128
|
+
resolved.push(abs);
|
|
129
|
+
try {
|
|
130
|
+
const real = await realpath(abs);
|
|
131
|
+
if (real !== abs)
|
|
132
|
+
resolved.push(real);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Ignore missing root paths while retaining lexical path guard.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return resolved;
|
|
139
|
+
}
|
|
140
|
+
async function verifyExecutableCandidate(candidatePath, untrustedRoots) {
|
|
141
|
+
if (!isAbsolute(candidatePath))
|
|
142
|
+
return null;
|
|
143
|
+
for (const untrusted of untrustedRoots) {
|
|
144
|
+
if (isInsideRoot(candidatePath, untrusted))
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
await access(candidatePath, fsConstants.X_OK);
|
|
149
|
+
const real = await realpath(candidatePath);
|
|
150
|
+
for (const untrusted of untrustedRoots) {
|
|
151
|
+
if (isInsideRoot(real, untrusted))
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const info = await lstat(real);
|
|
155
|
+
if (!info.isFile())
|
|
156
|
+
return null;
|
|
157
|
+
return real;
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async function resolveTrustedStdioCommand(rawCommand, trustedPathEnv, untrustedRoots) {
|
|
164
|
+
if (rawCommand.includes('/') || rawCommand.includes('\\')) {
|
|
165
|
+
if (!isAbsolute(rawCommand) || rawCommand.includes('\\') || rawCommand.includes('\0')) {
|
|
166
|
+
throw new Error(`MCP stdio command "${rawCommand}" must be a bare executable name or absolute path`);
|
|
167
|
+
}
|
|
168
|
+
const verified = await verifyExecutableCandidate(rawCommand, untrustedRoots);
|
|
169
|
+
if (verified === null) {
|
|
170
|
+
throw new Error(`MCP stdio command "${rawCommand}" is missing, not executable, or inside an untrusted root`);
|
|
171
|
+
}
|
|
172
|
+
return verified;
|
|
173
|
+
}
|
|
174
|
+
if (!BARE_EXECUTABLE_PATTERN.test(rawCommand)) {
|
|
175
|
+
throw new Error(`MCP stdio command "${rawCommand}" contains invalid characters`);
|
|
176
|
+
}
|
|
177
|
+
const dirs = `${trustedPathEnv}${delimiter}${DEFAULT_TRUSTED_PATH}`
|
|
178
|
+
.split(delimiter)
|
|
179
|
+
.map(part => part.trim())
|
|
180
|
+
.filter(part => part.length > 0 && isAbsolute(part));
|
|
181
|
+
const seen = new Set();
|
|
182
|
+
for (const dir of dirs) {
|
|
183
|
+
if (seen.has(dir))
|
|
184
|
+
continue;
|
|
185
|
+
seen.add(dir);
|
|
186
|
+
if (untrustedRoots.some(root => isInsideRoot(dir, root)))
|
|
187
|
+
continue;
|
|
188
|
+
const candidate = join(dir, rawCommand);
|
|
189
|
+
const verified = await verifyExecutableCandidate(candidate, untrustedRoots);
|
|
190
|
+
if (verified !== null)
|
|
191
|
+
return verified;
|
|
192
|
+
}
|
|
193
|
+
throw new Error(`MCP stdio command "${rawCommand}" was not found on trusted PATH`);
|
|
194
|
+
}
|
|
195
|
+
function sanitizeToolSegment(upstreamName, usedNames, serverId) {
|
|
196
|
+
const maxSegmentLength = Math.max(8, MAX_PROVIDER_TOOL_NAME_LENGTH - `mcp__${serverId}__`.length);
|
|
197
|
+
const cleaned = upstreamName
|
|
198
|
+
.replace(/[^A-Za-z0-9_]+/g, '_')
|
|
199
|
+
.replace(/^_+|_+$/g, '')
|
|
200
|
+
.slice(0, Math.max(4, maxSegmentLength - 4));
|
|
201
|
+
const base = cleaned.length > 0 ? cleaned : 'tool';
|
|
202
|
+
let candidate = base;
|
|
203
|
+
let suffix = 2;
|
|
204
|
+
while (usedNames.has(`mcp__${serverId}__${candidate}`)) {
|
|
205
|
+
const tag = `_${suffix++}`;
|
|
206
|
+
candidate = `${base.slice(0, Math.max(1, maxSegmentLength - tag.length))}${tag}`;
|
|
207
|
+
}
|
|
208
|
+
return candidate;
|
|
209
|
+
}
|
|
210
|
+
const DISALLOWED_SCHEMA_KEYS = new Set([
|
|
211
|
+
'$schema',
|
|
212
|
+
'$id',
|
|
213
|
+
'$anchor',
|
|
214
|
+
'$dynamicRef',
|
|
215
|
+
'$dynamicAnchor',
|
|
216
|
+
'__proto__',
|
|
217
|
+
'constructor',
|
|
218
|
+
'prototype',
|
|
219
|
+
]);
|
|
220
|
+
function sanitizeJsonSchemaValue(value, depth) {
|
|
221
|
+
if (depth > 16 || value === null || value === undefined)
|
|
222
|
+
return undefined;
|
|
223
|
+
if (typeof value === 'string')
|
|
224
|
+
return value.slice(0, 2048);
|
|
225
|
+
if (typeof value === 'boolean')
|
|
226
|
+
return value;
|
|
227
|
+
if (typeof value === 'number') {
|
|
228
|
+
return Number.isFinite(value) && Math.abs(value) <= Number.MAX_SAFE_INTEGER ? value : undefined;
|
|
229
|
+
}
|
|
230
|
+
if (Array.isArray(value)) {
|
|
231
|
+
const items = [];
|
|
232
|
+
for (const item of value.slice(0, 64)) {
|
|
233
|
+
const clean = sanitizeJsonSchemaValue(item, depth + 1);
|
|
234
|
+
if (clean !== undefined)
|
|
235
|
+
items.push(clean);
|
|
236
|
+
}
|
|
237
|
+
return items;
|
|
238
|
+
}
|
|
239
|
+
if (typeof value === 'object') {
|
|
240
|
+
const raw = value;
|
|
241
|
+
const out = {};
|
|
242
|
+
let count = 0;
|
|
243
|
+
for (const key of Object.keys(raw)) {
|
|
244
|
+
if (DISALLOWED_SCHEMA_KEYS.has(key))
|
|
245
|
+
continue;
|
|
246
|
+
if (key === '$ref') {
|
|
247
|
+
const refVal = raw[key];
|
|
248
|
+
if (typeof refVal !== 'string' || !refVal.startsWith('#/'))
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (++count > 64)
|
|
252
|
+
break;
|
|
253
|
+
const clean = sanitizeJsonSchemaValue(raw[key], depth + 1);
|
|
254
|
+
if (clean !== undefined)
|
|
255
|
+
out[key] = clean;
|
|
256
|
+
}
|
|
257
|
+
return out;
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
export function sanitizeMcpToolInputSchema(rawSchema) {
|
|
262
|
+
const cleaned = sanitizeJsonSchemaValue(rawSchema, 0);
|
|
263
|
+
if (cleaned === null || typeof cleaned !== 'object' || Array.isArray(cleaned)) {
|
|
264
|
+
return Object.freeze({ type: 'object', properties: {} });
|
|
265
|
+
}
|
|
266
|
+
const obj = cleaned;
|
|
267
|
+
if (obj['type'] !== 'object') {
|
|
268
|
+
obj['type'] = 'object';
|
|
269
|
+
}
|
|
270
|
+
if (obj['properties'] === undefined || typeof obj['properties'] !== 'object' || obj['properties'] === null || Array.isArray(obj['properties'])) {
|
|
271
|
+
obj['properties'] = {};
|
|
272
|
+
}
|
|
273
|
+
return Object.freeze(obj);
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Host-owned multi-server MCP client registry supporting both `stdio` and Streamable `http`
|
|
277
|
+
* MCP servers. Keeps credentials and network/child-process authority strictly inside the
|
|
278
|
+
* trusted host process while exposing scrubbed, byte-bounded `read_only` tool definitions.
|
|
279
|
+
*/
|
|
280
|
+
export class HostMcpRegistry {
|
|
281
|
+
#servers;
|
|
282
|
+
#handles;
|
|
283
|
+
#toolsByName;
|
|
284
|
+
#scrub;
|
|
285
|
+
#onLog;
|
|
286
|
+
#closed = false;
|
|
287
|
+
constructor(servers, handles, toolsByName, scrub, onLog) {
|
|
288
|
+
this.#servers = Object.freeze([...servers]);
|
|
289
|
+
this.#handles = handles;
|
|
290
|
+
this.#toolsByName = toolsByName;
|
|
291
|
+
this.#scrub = scrub;
|
|
292
|
+
this.#onLog = onLog;
|
|
293
|
+
}
|
|
294
|
+
static async connect(configs, options = {}) {
|
|
295
|
+
const scrub = options.scrub ?? ((text) => text);
|
|
296
|
+
const untrustedRoots = await resolveCanonicalUntrustedRoots(options.untrustedRoots);
|
|
297
|
+
const trustedPathEnv = options.trustedPathEnv ?? process.env['PATH'] ?? DEFAULT_TRUSTED_PATH;
|
|
298
|
+
const summaries = [];
|
|
299
|
+
const handles = [];
|
|
300
|
+
const toolsByName = new Map();
|
|
301
|
+
const usedNames = new Set(['mcp__workspace__read_file']);
|
|
302
|
+
const seenServerIds = new Set();
|
|
303
|
+
try {
|
|
304
|
+
for (const config of configs) {
|
|
305
|
+
if (config.id.length > MAX_MCP_SERVER_ID_LENGTH
|
|
306
|
+
|| !MCP_SERVER_ID_PATTERN.test(config.id)
|
|
307
|
+
|| config.id === 'workspace') {
|
|
308
|
+
throw new Error(`Invalid or reserved MCP server id "${config.id}"`);
|
|
309
|
+
}
|
|
310
|
+
if (seenServerIds.has(config.id)) {
|
|
311
|
+
throw new Error(`Duplicate MCP server id "${config.id}"`);
|
|
312
|
+
}
|
|
313
|
+
seenServerIds.add(config.id);
|
|
314
|
+
const timeoutMs = config.timeoutMs !== undefined && Number.isSafeInteger(config.timeoutMs) && config.timeoutMs >= 100
|
|
315
|
+
? Math.min(config.timeoutMs, 600_000)
|
|
316
|
+
: DEFAULT_MCP_TIMEOUT_MS;
|
|
317
|
+
let transport;
|
|
318
|
+
let client;
|
|
319
|
+
try {
|
|
320
|
+
if (config.transport === 'stdio') {
|
|
321
|
+
const executable = await resolveTrustedStdioCommand(config.command, trustedPathEnv, untrustedRoots);
|
|
322
|
+
const childEnv = {
|
|
323
|
+
PATH: DEFAULT_TRUSTED_PATH,
|
|
324
|
+
HOME: process.env['HOME'] ?? '/tmp',
|
|
325
|
+
TMPDIR: process.env['TMPDIR'] ?? '/tmp',
|
|
326
|
+
LANG: 'C.UTF-8',
|
|
327
|
+
LC_ALL: 'C.UTF-8',
|
|
328
|
+
...(config.env ?? {}),
|
|
329
|
+
};
|
|
330
|
+
transport = new StdioTransport({
|
|
331
|
+
command: executable,
|
|
332
|
+
args: config.args ?? [],
|
|
333
|
+
...(config.cwd !== undefined ? { cwd: config.cwd } : {}),
|
|
334
|
+
env: childEnv,
|
|
335
|
+
inheritEnv: false,
|
|
336
|
+
stderr: 'pipe',
|
|
337
|
+
maxMessageBytes: MAX_MCP_MESSAGE_BYTES,
|
|
338
|
+
maxStderrBytes: MAX_MCP_STDERR_BYTES,
|
|
339
|
+
closeTimeoutMs: 2_000,
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
let parsedUrl;
|
|
344
|
+
try {
|
|
345
|
+
parsedUrl = new URL(config.url);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
throw new Error(`Invalid HTTP MCP URL for server "${config.id}"`);
|
|
349
|
+
}
|
|
350
|
+
if (parsedUrl.username.length > 0 || parsedUrl.password.length > 0) {
|
|
351
|
+
throw new Error(`HTTP MCP URL for server "${config.id}" must not embed credentials`);
|
|
352
|
+
}
|
|
353
|
+
const allowHttp = config.allowInsecureHttp === true && parsedUrl.protocol === 'http:';
|
|
354
|
+
if (parsedUrl.protocol !== 'https:' && !allowHttp) {
|
|
355
|
+
throw new Error(`HTTP MCP server "${config.id}" requires https:// URL`);
|
|
356
|
+
}
|
|
357
|
+
transport = new StreamableHttpTransport({
|
|
358
|
+
url: parsedUrl,
|
|
359
|
+
...(config.headers !== undefined ? { headers: { ...config.headers } } : {}),
|
|
360
|
+
...(config.fetchImpl !== undefined ? { fetch: config.fetchImpl } : {}),
|
|
361
|
+
openGetStream: false,
|
|
362
|
+
maxMessageBytes: MAX_MCP_MESSAGE_BYTES,
|
|
363
|
+
reconnect: {
|
|
364
|
+
initialDelayMs: 250,
|
|
365
|
+
maxDelayMs: 1_000,
|
|
366
|
+
maxRetries: 1,
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
client = new McpClient({
|
|
371
|
+
name: 'loopwright',
|
|
372
|
+
version: '0.1.0',
|
|
373
|
+
requestTimeoutMs: timeoutMs,
|
|
374
|
+
});
|
|
375
|
+
client.onError(() => {
|
|
376
|
+
// Suppress unhandled transport errors; individual tool calls report soft errors.
|
|
377
|
+
});
|
|
378
|
+
await client.connect(transport);
|
|
379
|
+
const listedTools = await client.listTools({ timeoutMs });
|
|
380
|
+
const allowSet = config.includeTools && config.includeTools.length > 0
|
|
381
|
+
? new Set(config.includeTools)
|
|
382
|
+
: null;
|
|
383
|
+
const filtered = listedTools
|
|
384
|
+
.filter(tool => typeof tool.name === 'string' && tool.name.length > 0 && (allowSet === null || allowSet.has(tool.name)))
|
|
385
|
+
.slice(0, MAX_TOOLS_PER_SERVER);
|
|
386
|
+
const registeredForServer = [];
|
|
387
|
+
for (const tool of filtered) {
|
|
388
|
+
if (toolsByName.size >= MAX_TOTAL_EXTERNAL_MCP_TOOLS)
|
|
389
|
+
break;
|
|
390
|
+
const segment = sanitizeToolSegment(tool.name, usedNames, config.id);
|
|
391
|
+
const fullName = `mcp__${config.id}__${segment}`;
|
|
392
|
+
usedNames.add(fullName);
|
|
393
|
+
const description = scrub((tool.description ?? `MCP tool ${tool.name} from ${config.id}`).slice(0, 2048));
|
|
394
|
+
const schema = Object.freeze({
|
|
395
|
+
name: fullName,
|
|
396
|
+
serverId: config.id,
|
|
397
|
+
upstreamName: tool.name,
|
|
398
|
+
description: `[MCP ${config.id}/${tool.name}] ${description}`,
|
|
399
|
+
inputSchema: sanitizeMcpToolInputSchema(tool.inputSchema),
|
|
400
|
+
});
|
|
401
|
+
toolsByName.set(fullName, { schema, client, timeoutMs });
|
|
402
|
+
registeredForServer.push(fullName);
|
|
403
|
+
}
|
|
404
|
+
handles.push({ id: config.id, client, transport });
|
|
405
|
+
summaries.push(Object.freeze({
|
|
406
|
+
id: config.id,
|
|
407
|
+
transport: config.transport,
|
|
408
|
+
status: 'connected',
|
|
409
|
+
toolNames: Object.freeze(registeredForServer),
|
|
410
|
+
error: null,
|
|
411
|
+
}));
|
|
412
|
+
options.onLog?.(`Connected MCP server "${config.id}" (${config.transport}): ${registeredForServer.length} tool${registeredForServer.length === 1 ? '' : 's'} ready`);
|
|
413
|
+
}
|
|
414
|
+
catch (error) {
|
|
415
|
+
await client?.close().catch(() => undefined);
|
|
416
|
+
await transport?.close().catch(() => undefined);
|
|
417
|
+
const detail = scrub(error instanceof Error ? error.message : String(error));
|
|
418
|
+
if (config.required === true) {
|
|
419
|
+
throw new Error(`Required MCP server "${config.id}" failed to initialize: ${detail}`, { cause: error });
|
|
420
|
+
}
|
|
421
|
+
summaries.push(Object.freeze({
|
|
422
|
+
id: config.id,
|
|
423
|
+
transport: config.transport,
|
|
424
|
+
status: 'failed',
|
|
425
|
+
toolNames: Object.freeze([]),
|
|
426
|
+
error: detail,
|
|
427
|
+
}));
|
|
428
|
+
options.onLog?.(`Warning: MCP server "${config.id}" (${config.transport}) unavailable: ${detail}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
return new HostMcpRegistry(summaries, handles, toolsByName, scrub, options.onLog);
|
|
432
|
+
}
|
|
433
|
+
catch (error) {
|
|
434
|
+
for (const handle of handles) {
|
|
435
|
+
await handle.client.close().catch(() => undefined);
|
|
436
|
+
await handle.transport.close().catch(() => undefined);
|
|
437
|
+
}
|
|
438
|
+
throw error;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
get servers() {
|
|
442
|
+
return this.#servers;
|
|
443
|
+
}
|
|
444
|
+
get toolNames() {
|
|
445
|
+
return Object.freeze([...this.#toolsByName.keys()]);
|
|
446
|
+
}
|
|
447
|
+
hasTool(name) {
|
|
448
|
+
return this.#toolsByName.has(name);
|
|
449
|
+
}
|
|
450
|
+
serverIdFor(name) {
|
|
451
|
+
return this.#toolsByName.get(name)?.schema.serverId ?? null;
|
|
452
|
+
}
|
|
453
|
+
targetIdentityFor(name) {
|
|
454
|
+
const entry = this.#toolsByName.get(name);
|
|
455
|
+
if (!entry)
|
|
456
|
+
return null;
|
|
457
|
+
return `mcp:${entry.schema.serverId}:${entry.schema.upstreamName}`;
|
|
458
|
+
}
|
|
459
|
+
toolSchemasFor(allowedToolNames, allowedServers) {
|
|
460
|
+
const allowed = new Set(allowedToolNames);
|
|
461
|
+
const allowedServerSet = allowedServers !== undefined ? new Set(allowedServers) : null;
|
|
462
|
+
const result = [];
|
|
463
|
+
for (const [name, entry] of this.#toolsByName.entries()) {
|
|
464
|
+
if (allowed.has(name) && (allowedServerSet === null || allowedServerSet.has(entry.schema.serverId))) {
|
|
465
|
+
result.push(entry.schema);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return Object.freeze(result);
|
|
469
|
+
}
|
|
470
|
+
async callTool(name, args, options) {
|
|
471
|
+
const startedMs = performance.now();
|
|
472
|
+
if (this.#closed) {
|
|
473
|
+
return clampToolResultBytes({ content: [{ type: 'text', text: `MCP error (${name}): MCP registry is closed` }], isError: true, details: null }, options.maxResultBytes, { tool: 'bash' });
|
|
474
|
+
}
|
|
475
|
+
const entry = this.#toolsByName.get(name);
|
|
476
|
+
if (!entry) {
|
|
477
|
+
return clampToolResultBytes({ content: [{ type: 'text', text: `MCP error: unknown MCP tool "${name}"` }], isError: true, details: null }, options.maxResultBytes, { tool: 'bash' });
|
|
478
|
+
}
|
|
479
|
+
try {
|
|
480
|
+
const rawResult = await entry.client.callTool(entry.schema.upstreamName, { ...args }, {
|
|
481
|
+
...(options.signal !== undefined ? { signal: options.signal } : {}),
|
|
482
|
+
timeoutMs: options.timeoutMs ?? entry.timeoutMs,
|
|
483
|
+
});
|
|
484
|
+
const llmBlocks = toLlmContent(rawResult);
|
|
485
|
+
const textParts = [];
|
|
486
|
+
for (const block of llmBlocks) {
|
|
487
|
+
if (block.type === 'text') {
|
|
488
|
+
textParts.push(this.#scrub(block.text));
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
textParts.push(`[MCP binary image (${this.#scrub(block.mimeType)}) omitted in text-only session]`);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (textParts.length === 0) {
|
|
495
|
+
textParts.push(rawResult.isError ? 'MCP tool returned an empty error response.' : '(empty MCP tool response)');
|
|
496
|
+
}
|
|
497
|
+
const elapsedMs = Math.max(1, Math.round(performance.now() - startedMs));
|
|
498
|
+
this.#onLog?.(`MCP ${entry.schema.serverId}/${entry.schema.upstreamName} ${rawResult.isError ? 'returned error' : 'completed'} (${elapsedMs}ms)`);
|
|
499
|
+
const shaped = {
|
|
500
|
+
content: [{ type: 'text', text: textParts.join('\n') }],
|
|
501
|
+
...(rawResult.isError === true ? { isError: true } : {}),
|
|
502
|
+
details: null,
|
|
503
|
+
};
|
|
504
|
+
return clampToolResultBytes(shaped, options.maxResultBytes, { tool: 'bash' });
|
|
505
|
+
}
|
|
506
|
+
catch (error) {
|
|
507
|
+
const elapsedMs = Math.max(1, Math.round(performance.now() - startedMs));
|
|
508
|
+
const detail = this.#scrub(error instanceof Error ? error.message : String(error));
|
|
509
|
+
this.#onLog?.(`MCP ${entry.schema.serverId}/${entry.schema.upstreamName} failed (${elapsedMs}ms): ${detail}`);
|
|
510
|
+
return clampToolResultBytes({
|
|
511
|
+
content: [{ type: 'text', text: `MCP tool error (${entry.schema.serverId}/${entry.schema.upstreamName}): ${detail}` }],
|
|
512
|
+
isError: true,
|
|
513
|
+
details: null,
|
|
514
|
+
}, options.maxResultBytes, { tool: 'bash' });
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async close() {
|
|
518
|
+
if (this.#closed)
|
|
519
|
+
return;
|
|
520
|
+
this.#closed = true;
|
|
521
|
+
for (const handle of this.#handles) {
|
|
522
|
+
await handle.client.close().catch(() => undefined);
|
|
523
|
+
await handle.transport.close().catch(() => undefined);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SettingsManager, type ExtensionFactory, type ResourceLoader } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
export interface TrustedFactory {
|
|
3
|
+
readonly name: 'loopwright-authorization' | 'loopwright-mcp' | 'loopwright-codemode';
|
|
4
|
+
readonly factory: ExtensionFactory;
|
|
5
|
+
}
|
|
6
|
+
/** Container-only by default; isolated host-session workers must opt in via LOOPWRIGHT_HOST_SESSION=1. */
|
|
7
|
+
export declare function compileTrustedFactories(factories: readonly TrustedFactory[], prompt: string): Promise<{
|
|
8
|
+
loader: ResourceLoader;
|
|
9
|
+
extensions: import("@earendil-works/pi-coding-agent").LoadExtensionsResult;
|
|
10
|
+
eventBus: import("@earendil-works/pi-coding-agent").EventBusController;
|
|
11
|
+
settings: SettingsManager;
|
|
12
|
+
directory: string;
|
|
13
|
+
}>;
|
|
14
|
+
/** Exact-output validation only; it never filters resources or makes an unsafe input namespace acceptable. */
|
|
15
|
+
export declare function verifyCompilerOutput(compiler: ResourceLoader, paths: readonly string[]): void;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createEventBus, DefaultResourceLoader, SettingsManager } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import { lstat, mkdir, mkdtemp, readdir, realpath } from 'node:fs/promises';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { isAbsolute, join } from 'node:path';
|
|
5
|
+
import { frozenLoader } from './resources.js';
|
|
6
|
+
const INERT = 'Loopwright trusted inline factory compiler. No role or task execution occurs here.';
|
|
7
|
+
const names = ['loopwright-authorization', 'loopwright-mcp', 'loopwright-codemode'];
|
|
8
|
+
async function emptyDirectory(path) {
|
|
9
|
+
const info = await lstat(path);
|
|
10
|
+
if (!info.isDirectory() || info.isSymbolicLink() || info.uid !== process.getuid?.() || await realpath(path) !== path || (await readdir(path)).length)
|
|
11
|
+
throw new Error('Unsafe factory namespace');
|
|
12
|
+
}
|
|
13
|
+
/** Container-only by default; isolated host-session workers must opt in via LOOPWRIGHT_HOST_SESSION=1. */
|
|
14
|
+
export async function compileTrustedFactories(factories, prompt) {
|
|
15
|
+
const isHostSession = process.env.LOOPWRIGHT_HOST_SESSION === '1';
|
|
16
|
+
if (Object.hasOwn(process.env, 'LOOPWRIGHT_HOST_SESSION')) {
|
|
17
|
+
if (!isHostSession)
|
|
18
|
+
throw new Error('Unsafe factory environment');
|
|
19
|
+
delete process.env.LOOPWRIGHT_HOST_SESSION;
|
|
20
|
+
}
|
|
21
|
+
let home;
|
|
22
|
+
if (isHostSession) {
|
|
23
|
+
const supportedPlatform = (process.platform === 'linux' && (process.arch === 'arm64' || process.arch === 'x64'))
|
|
24
|
+
|| (process.platform === 'darwin' && process.arch === 'arm64');
|
|
25
|
+
const rawHome = process.env.HOME;
|
|
26
|
+
if (!supportedPlatform || typeof rawHome !== 'string' || !isAbsolute(rawHome) || homedir() !== rawHome || process.env.PI_OFFLINE !== '1'
|
|
27
|
+
|| Object.keys(process.env).some(key => /(?:AGENT_DIR|PACKAGE_DIR)$/.test(key)))
|
|
28
|
+
throw new Error('Unsafe factory environment');
|
|
29
|
+
home = rawHome;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
if (process.platform !== 'linux' || process.env.HOME !== '/tmp/home' || homedir() !== '/tmp/home' || process.env.PI_OFFLINE !== '1'
|
|
33
|
+
|| Object.keys(process.env).some(key => /(?:AGENT_DIR|PACKAGE_DIR)$/.test(key)))
|
|
34
|
+
throw new Error('Unsafe factory environment');
|
|
35
|
+
home = '/tmp/home';
|
|
36
|
+
}
|
|
37
|
+
if (factories.length < 1 || factories.length > 3 || factories.some((item, index) => item.name !== names[index] || typeof item.factory !== 'function'))
|
|
38
|
+
throw new Error('Unexpected factory provenance');
|
|
39
|
+
// The only non-project automatic root is HOME/.agents/skills. Reject a preexisting HOME tree before SDK resolution.
|
|
40
|
+
try {
|
|
41
|
+
await mkdir(home, { mode: 0o700 });
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error.code !== 'EEXIST')
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
await emptyDirectory(home);
|
|
48
|
+
const tmpRoot = isHostSession ? await realpath(process.env.TMPDIR || '/tmp') : '/tmp';
|
|
49
|
+
const directory = await mkdtemp(join(tmpRoot, 'loopwright-factory-'));
|
|
50
|
+
await emptyDirectory(directory);
|
|
51
|
+
const settings = SettingsManager.inMemory({ packages: [], extensions: [], skills: [], prompts: [], themes: [],
|
|
52
|
+
retry: { enabled: false, maxRetries: 0, provider: { maxRetries: 0 } }, cacheWarming: 'off', compaction: { enabled: false, reserveTokens: 1024, keepRecentTokens: 4096 } }, { projectTrusted: false });
|
|
53
|
+
const eventBus = createEventBus();
|
|
54
|
+
const compiler = new DefaultResourceLoader({ cwd: directory, agentDir: directory, settingsManager: settings, eventBus,
|
|
55
|
+
extensionFactories: factories.map(item => ({ name: item.name, factory: item.factory })), disabledBuiltinExtensions: ['mcp', 'codemode', 'tool-search'],
|
|
56
|
+
additionalExtensionPaths: [], additionalSkillPaths: [], additionalPromptTemplatePaths: [], additionalThemePaths: [],
|
|
57
|
+
noExtensions: true, noContextFiles: true, noSkills: true, noPromptTemplates: true, noThemes: true, systemPrompt: INERT, appendSystemPrompt: [] });
|
|
58
|
+
await compiler.reload();
|
|
59
|
+
const extensions = compiler.getExtensions();
|
|
60
|
+
verifyCompilerOutput(compiler, factories.map(item => `<inline:${item.name}>`));
|
|
61
|
+
// Keep the original native records/runtime and the bus captured by their real ExtensionAPI closures.
|
|
62
|
+
return { loader: frozenLoader(prompt, extensions), extensions, eventBus, settings, directory };
|
|
63
|
+
}
|
|
64
|
+
/** Exact-output validation only; it never filters resources or makes an unsafe input namespace acceptable. */
|
|
65
|
+
export function verifyCompilerOutput(compiler, paths) {
|
|
66
|
+
const result = compiler.getExtensions();
|
|
67
|
+
if (result.errors.length || result.warnings?.length || result.extensions.length !== paths.length
|
|
68
|
+
|| result.extensions.some((item, index) => item.path !== paths[index] || item.resolvedPath !== paths[index])
|
|
69
|
+
|| !result.runtime || compiler.getSystemPrompt() !== INERT || compiler.getSystemPromptSource() !== undefined
|
|
70
|
+
|| compiler.getAppendSystemPrompt().length || compiler.getAppendSystemPromptSources().length || compiler.getAgentsFiles().agentsFiles.length
|
|
71
|
+
|| compiler.getSkills().skills.length || compiler.getSkills().diagnostics.length || compiler.getPrompts().prompts.length
|
|
72
|
+
|| compiler.getPrompts().diagnostics.length || compiler.getThemes().themes.length || compiler.getThemes().diagnostics.length)
|
|
73
|
+
throw new Error('Unexpected native compiler output');
|
|
74
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type CallExternalMcpToolOptions, type ConnectHostMcpOptions, type ConnectedMcpServerSummary, type ExternalMcpHttpServerConfig, type ExternalMcpServerConfig, type ExternalMcpStdioServerConfig, type ExternalMcpToolSchema, type HostMcpRegistry } from './external-mcp.js';
|
|
2
|
+
import type { PiAdapterV2, PiHostV2, PiOpenInputV2, PiResultV2 } from './types-v2.js';
|
|
3
|
+
import type { PiAdapter, PiHost, PiResult } from './types.js';
|
|
4
|
+
export type { CallExternalMcpToolOptions, ConnectHostMcpOptions, ConnectedMcpServerSummary, ExternalMcpHttpServerConfig, ExternalMcpServerConfig, ExternalMcpStdioServerConfig, ExternalMcpToolSchema, HostMcpRegistry, };
|
|
5
|
+
export type HostSessionProgressEvent = {
|
|
6
|
+
readonly kind: 'request_start';
|
|
7
|
+
readonly turn: number;
|
|
8
|
+
readonly provider: string;
|
|
9
|
+
readonly model: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: 'request_settled';
|
|
12
|
+
readonly turn: number;
|
|
13
|
+
readonly stopReason: string;
|
|
14
|
+
readonly inputTokens: number;
|
|
15
|
+
readonly outputTokens: number;
|
|
16
|
+
readonly elapsedMs: number;
|
|
17
|
+
readonly toolCallNames: readonly string[];
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: 'tool_start';
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly summary?: string | undefined;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'tool_end';
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly isError: boolean;
|
|
26
|
+
readonly elapsedMs: number;
|
|
27
|
+
readonly summary?: string | undefined;
|
|
28
|
+
readonly errorCode?: string | undefined;
|
|
29
|
+
readonly errorPath?: string | undefined;
|
|
30
|
+
} | {
|
|
31
|
+
readonly kind: 'circuit_breaker';
|
|
32
|
+
readonly reason: 'max_turns' | 'consecutive_tool_errors' | 'no_progress';
|
|
33
|
+
readonly turn: number;
|
|
34
|
+
readonly message: string;
|
|
35
|
+
};
|
|
36
|
+
export interface HostSessionCircuitBreakerOptions {
|
|
37
|
+
readonly maxTurns?: number | undefined;
|
|
38
|
+
readonly maxRepairTurns?: number | undefined;
|
|
39
|
+
readonly maxConsecutiveErrorTurns?: number | undefined;
|
|
40
|
+
readonly maxRepairNoProgressTurns?: number | undefined;
|
|
41
|
+
}
|
|
42
|
+
export interface OpenPiHostSessionOptions {
|
|
43
|
+
readonly mcpRegistry?: HostMcpRegistry | undefined;
|
|
44
|
+
readonly allowedMcpServers?: readonly string[] | undefined;
|
|
45
|
+
readonly onProgress?: ((event: HostSessionProgressEvent) => void) | undefined;
|
|
46
|
+
readonly circuitBreaker?: HostSessionCircuitBreakerOptions | undefined;
|
|
47
|
+
readonly scrub?: ((text: string) => string) | undefined;
|
|
48
|
+
}
|
|
49
|
+
export declare function isSupportedHostSessionPlatform(platform?: string, arch?: string): boolean;
|
|
50
|
+
export declare function openPiHostSessionAdapter(host: PiHost, input: unknown, options?: OpenPiHostSessionOptions): Promise<PiResult<PiAdapter>>;
|
|
51
|
+
export declare function openPiHostSessionAdapterV2(host: PiHostV2, input: PiOpenInputV2, options?: OpenPiHostSessionOptions): Promise<PiResultV2<PiAdapterV2>>;
|