@anyswarm/core 0.5.0 → 0.5.1
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/README.md +11 -10
- package/deploy/worker/Dockerfile +12 -4
- package/dist/deploy/worker/Dockerfile +12 -4
- package/dist/examples/README.md +24 -12
- package/dist/examples/authoring/README.md +24 -0
- package/dist/examples/authoring/business.d.ts +2 -0
- package/dist/examples/authoring/business.js +4 -0
- package/dist/examples/authoring/config.d.ts +5 -0
- package/dist/examples/authoring/config.js +2 -0
- package/dist/examples/authoring/eject.json +5 -0
- package/dist/examples/authoring/harness.d.ts +4 -0
- package/dist/examples/authoring/harness.js +19 -0
- package/dist/examples/autoresearch/README.md +33 -0
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +18 -0
- package/dist/examples/autoresearch/config.d.ts +51 -0
- package/dist/examples/autoresearch/config.js +57 -0
- package/dist/examples/autoresearch/demo.d.ts +11 -0
- package/dist/examples/autoresearch/demo.js +52 -0
- package/dist/examples/autoresearch/eject.json +15 -0
- package/dist/examples/autoresearch/frontiercs2.d.ts +87 -0
- package/dist/examples/autoresearch/frontiercs2.js +211 -0
- package/dist/examples/autoresearch/prepare.d.ts +95 -0
- package/dist/examples/autoresearch/prepare.js +257 -0
- package/dist/examples/autoresearch/process.d.ts +13 -0
- package/dist/examples/autoresearch/process.js +48 -0
- package/dist/examples/autoresearch/project.d.ts +115 -0
- package/dist/examples/autoresearch/project.js +410 -0
- package/dist/examples/autoresearch/research-service.d.ts +106 -0
- package/dist/examples/autoresearch/research-service.js +255 -0
- package/dist/examples/code/README.md +25 -0
- package/dist/examples/code/REQUIREMENTS.zh.md +11 -0
- package/dist/examples/code/candidate.d.ts +19 -0
- package/dist/examples/code/candidate.js +80 -0
- package/dist/examples/code/config.d.ts +32 -0
- package/dist/examples/code/config.js +18 -0
- package/dist/examples/code/eject.json +5 -0
- package/dist/examples/code/project.d.ts +3 -0
- package/dist/examples/code/project.js +605 -0
- package/dist/examples/code/prompts.d.ts +5 -0
- package/dist/examples/code/prompts.js +12 -0
- package/dist/examples/code/verification.d.ts +19 -0
- package/dist/examples/code/verification.js +268 -0
- package/dist/examples/code/worktree.d.ts +17 -0
- package/dist/examples/code/worktree.js +233 -0
- package/dist/examples/harness-session/README.md +3 -6
- package/dist/examples/lead-worker/harness/dynamic-scheduler.d.ts +2 -1
- package/dist/examples/lead-worker/harness/dynamic-scheduler.js +5 -2
- package/dist/examples/lead-worker/harness/index.d.ts +60 -0
- package/dist/examples/lead-worker/harness/index.js +77 -6
- package/dist/examples/lead-worker/project.js +2 -2
- package/dist/examples/lead-worker/services/board.d.ts +5 -0
- package/dist/examples/lead-worker/services/board.js +19 -1
- package/dist/examples/messages/README.md +5 -5
- package/dist/examples/messages/handoff.d.ts +2 -0
- package/dist/examples/messages/handoff.js +5 -1
- package/dist/examples/messages/project.js +52 -2
- package/dist/examples/notes/README.md +13 -18
- package/dist/examples/notes/project.js +67 -6
- package/dist/examples/peermesh/harness/router.js +3 -1
- package/dist/examples/peermesh/harness/team.d.ts +8 -0
- package/dist/examples/peermesh/harness/team.js +13 -0
- package/dist/examples/peermesh/project.js +22 -4
- package/dist/examples/services/agent-control/README.md +3 -3
- package/dist/examples/services/mathlib-search/Dockerfile +4 -2
- package/dist/examples/services/mathlib-search/README.md +1 -1
- package/dist/examples/services/mcp-managed/README.md +2 -2
- package/dist/examples/services/persistent-board/README.md +13 -3
- package/dist/examples/services/persistent-board/business.d.ts +7 -0
- package/dist/examples/services/persistent-board/business.js +7 -0
- package/dist/examples/services/persistent-board/index.js +10 -0
- package/dist/examples/services/persistent-board/live.d.ts +3 -0
- package/dist/examples/services/persistent-board/live.js +58 -0
- package/dist/examples/subagents/README.md +5 -5
- package/dist/examples/subagents/business.js +3 -1
- package/dist/examples/subagents/harness/controller.d.ts +15 -0
- package/dist/examples/subagents/harness/controller.js +181 -32
- package/dist/examples/subagents/project.d.ts +2 -0
- package/dist/examples/subagents/project.js +43 -34
- package/dist/examples/subagents/prompts/prompts.d.ts +1 -0
- package/dist/examples/subagents/prompts/prompts.js +3 -0
- package/dist/examples/subagents/services/collaboration-service.d.ts +3 -2
- package/dist/examples/subagents/services/collaboration-service.js +14 -2
- package/dist/examples/substrate/README.md +2 -2
- package/dist/examples/substrate/harness/index.d.ts +1 -1
- package/dist/examples/substrate/harness/index.js +77 -12
- package/dist/examples/substrate/project.js +4 -1
- package/dist/examples/super/README.md +40 -0
- package/dist/examples/super/actions.d.ts +95 -0
- package/dist/examples/super/actions.js +230 -0
- package/dist/examples/super/artifact.d.ts +4 -0
- package/dist/examples/super/artifact.js +51 -0
- package/dist/examples/super/config.d.ts +80 -0
- package/dist/examples/super/config.js +83 -0
- package/dist/examples/super/coordinator.d.ts +33 -0
- package/dist/examples/super/coordinator.js +151 -0
- package/dist/examples/super/daemon.d.ts +11 -0
- package/dist/examples/super/daemon.js +109 -0
- package/dist/examples/super/decisions.d.ts +8 -0
- package/dist/examples/super/decisions.js +52 -0
- package/dist/examples/super/eject.json +5 -0
- package/dist/examples/super/execution.d.ts +11 -0
- package/dist/examples/super/execution.js +136 -0
- package/dist/examples/super/github.d.ts +62 -0
- package/dist/examples/super/github.js +269 -0
- package/dist/examples/super/inbox.d.ts +162 -0
- package/dist/examples/super/inbox.js +284 -0
- package/dist/examples/super/location.d.ts +5 -0
- package/dist/examples/super/location.js +64 -0
- package/dist/examples/super/outbox.d.ts +5 -0
- package/dist/examples/super/outbox.js +103 -0
- package/dist/examples/super/project.d.ts +111 -0
- package/dist/examples/super/project.js +253 -0
- package/dist/examples/super/prompts.d.ts +3 -0
- package/dist/examples/super/prompts.js +25 -0
- package/dist/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
- package/dist/examples/taskpool/harness/controller.d.ts +35 -6
- package/dist/examples/taskpool/harness/controller.js +73 -7
- package/dist/examples/taskpool/project.js +18 -2
- package/dist/scripts/anyswarm-applications.d.ts +19 -0
- package/dist/scripts/anyswarm-applications.js +19 -0
- package/dist/scripts/anyswarm-arguments.d.ts +35 -5
- package/dist/scripts/anyswarm-arguments.js +87 -23
- package/dist/scripts/anyswarm-author.d.ts +5 -0
- package/dist/scripts/anyswarm-author.js +24 -0
- package/dist/scripts/anyswarm-eject.d.ts +11 -0
- package/dist/scripts/anyswarm-eject.js +164 -0
- package/dist/scripts/anyswarm-harnesses.d.ts +2 -0
- package/dist/scripts/anyswarm-harnesses.js +31 -0
- package/dist/scripts/anyswarm-installation.js +19 -13
- package/dist/scripts/anyswarm-launch.d.ts +37 -0
- package/dist/scripts/anyswarm-launch.js +86 -0
- package/dist/scripts/anyswarm-project.d.ts +12 -2
- package/dist/scripts/anyswarm-project.js +121 -20
- package/dist/scripts/anyswarm-source-runner.d.ts +1 -0
- package/dist/scripts/anyswarm-source-runner.js +232 -0
- package/dist/scripts/anyswarm-tui-config.d.ts +36 -0
- package/dist/scripts/anyswarm-tui-config.js +189 -0
- package/dist/scripts/anyswarm-tui-session.d.ts +66 -0
- package/dist/scripts/anyswarm-tui-session.js +304 -0
- package/dist/scripts/anyswarm-tui-terminal.d.ts +41 -0
- package/dist/scripts/anyswarm-tui-terminal.js +154 -0
- package/dist/scripts/anyswarm-tui.d.ts +2 -0
- package/dist/scripts/anyswarm-tui.js +1012 -0
- package/dist/scripts/anyswarm.js +47 -2
- package/dist/scripts/build-provenance.json +1 -0
- package/dist/scripts/build.js +7 -1
- package/dist/scripts/generate-architecture-api.js +2 -0
- package/dist/scripts/generate-architecture-prompts.js +24 -2
- package/dist/scripts/local-environment.d.ts +6 -1
- package/dist/scripts/local-environment.js +52 -16
- package/dist/scripts/local-setup-smoke.js +3 -2
- package/dist/scripts/local-setup-worker.d.ts +1 -1
- package/dist/scripts/local-setup-worker.js +15 -6
- package/dist/scripts/local-setup.d.ts +2 -2
- package/dist/scripts/local-setup.js +72 -12
- package/dist/scripts/opensandbox-agent-worker.js +2 -2
- package/dist/scripts/pack-release.d.ts +1 -0
- package/dist/scripts/pack-release.js +63 -0
- package/dist/scripts/pi-session-bridge.js +11 -3
- package/dist/scripts/run-harness.js +3 -1
- package/dist/scripts/setup-bootstrap.js +43 -6
- package/dist/src/core/allocation-ledger.js +4 -3
- package/dist/src/core/host-identity.d.ts +2 -0
- package/dist/src/core/host-identity.js +11 -0
- package/dist/src/core/index.d.ts +4 -2
- package/dist/src/core/index.js +12 -4
- package/dist/src/core/mcp-service.js +2 -2
- package/dist/src/core/runtime-management.d.ts +6 -0
- package/dist/src/core/runtime-management.js +24 -0
- package/dist/src/core/sandbox/executor-driver.d.ts +4 -2
- package/dist/src/core/sandbox/executor-driver.js +12 -14
- package/dist/src/core/sandbox/local-executor.d.ts +13 -1
- package/dist/src/core/sandbox/local-executor.js +69 -19
- package/dist/src/core/sandbox/local-worker.js +32 -21
- package/dist/src/core/sandbox/opensandbox-backend.d.ts +2 -0
- package/dist/src/core/sandbox/opensandbox-backend.js +36 -11
- package/dist/src/core/sandbox/sandbox-connection.d.ts +2 -0
- package/dist/src/core/sandbox/sandbox-connection.js +14 -6
- package/dist/src/core/service-live-state.d.ts +14 -0
- package/dist/src/core/service-live-state.js +161 -0
- package/dist/src/core/service-observation-types.d.ts +21 -1
- package/dist/src/core/service-process.d.ts +1 -1
- package/dist/src/core/service-process.js +45 -4
- package/dist/src/core/service-types.d.ts +5 -1
- package/dist/src/core/services.d.ts +1 -1
- package/dist/src/core/services.js +8 -3
- package/dist/src/core/types.d.ts +3 -0
- package/dist/src/core/worker-image.js +3 -3
- package/dist/src/harness/harness-session-types.d.ts +10 -0
- package/dist/src/harness/harness-session.js +42 -5
- package/dist/src/harness/project-harness.d.ts +13 -1
- package/dist/src/harness/project-harness.js +36 -10
- package/dist/src/harness/project-input.js +81 -15
- package/dist/src/harness/project-rpc-client.d.ts +1 -0
- package/dist/src/harness/project-rpc-client.js +5 -0
- package/dist/src/harness/project-rpc.d.ts +8 -2
- package/dist/src/harness/project-rpc.js +31 -7
- package/dist/src/harness/project-runtime.js +3 -1
- package/dist/src/harness/typescript-loader.d.ts +2 -0
- package/dist/src/harness/typescript-loader.js +41 -0
- package/dist/src/trace-viewer/public/app.js +6 -5
- package/dist/src/trace-viewer/reader.mjs +42 -2
- package/docs/INDEX.md +3 -1
- package/docs/architecture/00-overview.md +1 -1
- package/docs/architecture/01-agent-core.md +1 -1
- package/docs/architecture/06-observability-experiments.md +1 -1
- package/docs/architecture/07-run-configuration.md +18 -12
- package/docs/architecture/08-prompts.md +22 -0
- package/docs/architecture/10-service-api-reference.md +53 -18
- package/docs/architecture/11-storage-reference.md +18 -1
- package/docs/architecture/12-code-coverage.md +148 -84
- package/docs/architecture/15-core-runtime.md +8 -0
- package/docs/architecture/16-pi-opensandbox-backend.md +5 -5
- package/docs/architecture/17-harness-reporting.md +1 -1
- package/docs/architecture/19-substrate-harness.md +28 -1
- package/docs/architecture/20-lead-worker-harness.md +34 -1
- package/docs/architecture/22-website.md +5 -3
- package/docs/architecture/23-project-harness.md +124 -5
- package/docs/architecture/24-runtime-recovery.md +10 -3
- package/docs/architecture/25-foreground-tui.md +51 -0
- package/docs/architecture/26-code.md +39 -0
- package/docs/architecture/27-personal.md +43 -0
- package/docs/architecture/28-autoresearch.md +31 -0
- package/docs/architecture/INDEX.md +4 -0
- package/docs/architecture/prompts/08-lead-worker-harness.md +4 -2
- package/docs/architecture/prompts/08-subagents-harness.md +21 -0
- package/docs/architecture/prompts/21-personal.md +44 -0
- package/docs/architecture/prompts/22-autoresearch.md +63 -0
- package/docs/architecture/prompts/26-code.md +55 -0
- package/docs/architecture/prompts/source-manifest.json +152 -33
- package/docs/architecture/source-map.json +489 -21
- package/docs/designs/core-harness/06-project-harness.md +13 -2
- package/docs/designs/core-harness/README.md +5 -0
- package/docs/en/agents.md +1 -1
- package/docs/en/build-your-harness.md +3 -5
- package/docs/en/changelog.md +13 -4
- package/docs/en/first-harness.md +8 -11
- package/docs/en/harnesses/lead-worker.md +1 -1
- package/docs/en/harnesses/peermesh.md +2 -2
- package/docs/en/harnesses/subagents.md +2 -2
- package/docs/en/harnesses/substrate.md +4 -4
- package/docs/en/harnesses/taskpool.md +2 -2
- package/docs/en/latest.md +12 -123
- package/docs/en/overview.md +1 -1
- package/docs/en/quickstart.md +40 -16
- package/docs/en/reference/api.md +14 -4
- package/docs/en/reference/cli.md +58 -14
- package/docs/en/runtime.md +2 -2
- package/docs/en/services.md +4 -0
- package/docs/third-party-notices.md +1 -0
- package/docs/workflows/development.md +17 -12
- package/docs/workflows/release-and-docs-versioning.md +76 -0
- package/docs/zh/agents.md +1 -1
- package/docs/zh/build-your-harness.md +3 -5
- package/docs/zh/changelog.md +13 -4
- package/docs/zh/first-harness.md +8 -11
- package/docs/zh/harnesses/lead-worker.md +1 -1
- package/docs/zh/harnesses/peermesh.md +2 -2
- package/docs/zh/harnesses/subagents.md +2 -2
- package/docs/zh/harnesses/substrate.md +4 -4
- package/docs/zh/harnesses/taskpool.md +2 -2
- package/docs/zh/latest.md +13 -124
- package/docs/zh/overview.md +1 -1
- package/docs/zh/quickstart.md +40 -16
- package/docs/zh/reference/api.md +14 -4
- package/docs/zh/reference/cli.md +58 -14
- package/docs/zh/runtime.md +2 -2
- package/docs/zh/services.md +4 -0
- package/examples/README.md +24 -12
- package/examples/authoring/README.md +24 -0
- package/examples/authoring/business.ts +4 -0
- package/examples/authoring/config.ts +2 -0
- package/examples/authoring/eject.json +5 -0
- package/examples/authoring/harness.ts +21 -0
- package/examples/autoresearch/README.md +33 -0
- package/examples/autoresearch/REQUIREMENTS.zh.md +18 -0
- package/examples/autoresearch/config.ts +90 -0
- package/examples/autoresearch/demo.ts +55 -0
- package/examples/autoresearch/eject.json +15 -0
- package/examples/autoresearch/frontiercs2.ts +237 -0
- package/examples/autoresearch/prepare.ts +267 -0
- package/examples/autoresearch/process.ts +50 -0
- package/examples/autoresearch/project.ts +397 -0
- package/examples/autoresearch/research-service.ts +302 -0
- package/examples/code/README.md +25 -0
- package/examples/code/REQUIREMENTS.zh.md +11 -0
- package/examples/code/candidate.ts +89 -0
- package/examples/code/config.ts +19 -0
- package/examples/code/eject.json +5 -0
- package/examples/code/project.ts +581 -0
- package/examples/code/prompts.ts +16 -0
- package/examples/code/verification.ts +239 -0
- package/examples/code/worktree.ts +188 -0
- package/examples/harness-session/README.md +3 -6
- package/examples/lead-worker/harness/dynamic-scheduler.ts +6 -3
- package/examples/lead-worker/harness/index.ts +61 -6
- package/examples/lead-worker/project.ts +2 -2
- package/examples/lead-worker/services/board.ts +14 -1
- package/examples/messages/README.md +5 -5
- package/examples/messages/handoff.ts +6 -2
- package/examples/messages/project.ts +47 -2
- package/examples/notes/README.md +13 -18
- package/examples/notes/project.ts +57 -9
- package/examples/peermesh/harness/router.ts +2 -2
- package/examples/peermesh/harness/team.ts +11 -0
- package/examples/peermesh/project.ts +19 -4
- package/examples/services/agent-control/README.md +3 -3
- package/examples/services/mathlib-search/Dockerfile +4 -2
- package/examples/services/mathlib-search/README.md +1 -1
- package/examples/services/mcp-managed/README.md +2 -2
- package/examples/services/persistent-board/README.md +13 -3
- package/examples/services/persistent-board/business.ts +10 -0
- package/examples/services/persistent-board/index.ts +10 -0
- package/examples/services/persistent-board/live.ts +54 -0
- package/examples/subagents/README.md +5 -5
- package/examples/subagents/business.ts +3 -1
- package/examples/subagents/harness/controller.ts +161 -29
- package/examples/subagents/project.ts +47 -33
- package/examples/subagents/prompts/prompts.ts +4 -0
- package/examples/subagents/services/collaboration-service.ts +14 -2
- package/examples/substrate/README.md +2 -2
- package/examples/substrate/harness/index.ts +67 -11
- package/examples/substrate/project.ts +5 -1
- package/examples/super/README.md +40 -0
- package/examples/super/actions.ts +196 -0
- package/examples/super/artifact.ts +56 -0
- package/examples/super/config.ts +95 -0
- package/examples/super/coordinator.ts +158 -0
- package/examples/super/daemon.ts +84 -0
- package/examples/super/decisions.ts +46 -0
- package/examples/super/eject.json +5 -0
- package/examples/super/execution.ts +131 -0
- package/examples/super/github.ts +242 -0
- package/examples/super/inbox.ts +306 -0
- package/examples/super/location.ts +54 -0
- package/examples/super/outbox.ts +97 -0
- package/examples/super/project.ts +227 -0
- package/examples/super/prompts.ts +27 -0
- package/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
- package/examples/taskpool/harness/controller.ts +59 -7
- package/examples/taskpool/project.ts +18 -2
- package/npm-shrinkwrap.development.json +2199 -0
- package/npm-shrinkwrap.json +86 -1920
- package/package.development.json +92 -0
- package/package.json +13 -7
- package/scripts/anyswarm-applications.ts +39 -0
- package/scripts/anyswarm-arguments.ts +94 -28
- package/scripts/anyswarm-author.ts +25 -0
- package/scripts/anyswarm-eject.ts +145 -0
- package/scripts/anyswarm-harnesses.ts +27 -0
- package/scripts/anyswarm-installation.ts +19 -13
- package/scripts/anyswarm-launch.ts +108 -0
- package/scripts/anyswarm-project.ts +114 -21
- package/scripts/anyswarm-source-runner.ts +203 -0
- package/scripts/anyswarm-tui-config.ts +174 -0
- package/scripts/anyswarm-tui-session.ts +295 -0
- package/scripts/anyswarm-tui-terminal.ts +147 -0
- package/scripts/anyswarm-tui.ts +912 -0
- package/scripts/anyswarm.ts +43 -2
- package/scripts/build.ts +8 -1
- package/scripts/generate-architecture-api.ts +2 -0
- package/scripts/generate-architecture-prompts.ts +35 -2
- package/scripts/local-environment.ts +55 -17
- package/scripts/local-setup-smoke.ts +3 -2
- package/scripts/local-setup-worker.ts +17 -7
- package/scripts/local-setup.ts +66 -13
- package/scripts/opensandbox-agent-worker.ts +2 -2
- package/scripts/pack-release.ts +67 -0
- package/scripts/pi-session-bridge.ts +10 -2
- package/scripts/run-harness.ts +3 -1
- package/scripts/setup-bootstrap.ts +41 -6
- package/src/core/allocation-ledger.ts +5 -3
- package/src/core/host-identity.ts +11 -0
- package/src/core/index.ts +12 -6
- package/src/core/mcp-service.ts +2 -2
- package/src/core/runtime-management.ts +22 -0
- package/src/core/sandbox/executor-driver.ts +15 -18
- package/src/core/sandbox/local-executor.ts +65 -19
- package/src/core/sandbox/local-worker.ts +29 -21
- package/src/core/sandbox/opensandbox-backend.ts +36 -11
- package/src/core/sandbox/sandbox-connection.ts +14 -5
- package/src/core/service-live-state.ts +156 -0
- package/src/core/service-observation-types.ts +23 -1
- package/src/core/service-process.ts +36 -3
- package/src/core/service-types.ts +3 -1
- package/src/core/services.ts +8 -3
- package/src/core/types.ts +3 -0
- package/src/core/worker-image.ts +3 -3
- package/src/harness/harness-session-types.ts +13 -1
- package/src/harness/harness-session.ts +40 -7
- package/src/harness/project-harness.ts +36 -10
- package/src/harness/project-input.ts +73 -15
- package/src/harness/project-rpc-client.ts +5 -0
- package/src/harness/project-rpc.ts +29 -8
- package/src/harness/project-runtime.ts +2 -1
- package/src/harness/typescript-loader.ts +37 -0
- package/src/trace-viewer/public/app.js +6 -5
- package/src/trace-viewer/reader.mjs +42 -2
|
@@ -9,9 +9,8 @@ type Model = ModelConfig;
|
|
|
9
9
|
export interface ExecutorDriver {
|
|
10
10
|
readonly kind: string;
|
|
11
11
|
readonly name: string;
|
|
12
|
-
readonly version
|
|
12
|
+
readonly version?: string;
|
|
13
13
|
readonly capabilities: ExecutorCapabilities;
|
|
14
|
-
readonly compatibleVersions: readonly string[];
|
|
15
14
|
readonly adapter?: ExecutorAdapter;
|
|
16
15
|
readonly defaultMaxOutputTokens?: null;
|
|
17
16
|
assertEnvironment?(environment: Readonly<Record<string, string>> | undefined): void;
|
|
@@ -20,7 +19,7 @@ export interface ExecutorDriver {
|
|
|
20
19
|
environment: Record<string, string>;
|
|
21
20
|
secretEnvironment: Record<string, string>;
|
|
22
21
|
};
|
|
23
|
-
start(options: { model: Model; baseUrl: string; forkSession: boolean }):
|
|
22
|
+
start(options: { model: Model; baseUrl: string; forkSession: boolean; version: string }):
|
|
24
23
|
| { command: 'pi'; args: string[] }
|
|
25
24
|
| { command: 'codex'; args: string[]; codex: { model: string; baseUrl: string; version: string } }
|
|
26
25
|
| { command: string; args: []; externalExecutor: ExecutorAdapter };
|
|
@@ -36,8 +35,6 @@ const sharedCapabilities = {
|
|
|
36
35
|
const pi: ExecutorDriver = {
|
|
37
36
|
kind: 'pi',
|
|
38
37
|
name: 'Pi',
|
|
39
|
-
version: '1.3.0',
|
|
40
|
-
compatibleVersions: Object.freeze(['1.3.0', '1.4.0']),
|
|
41
38
|
capabilities: Object.freeze({ ...sharedCapabilities, contextFork: true,
|
|
42
39
|
session: Object.freeze({ configure: true, compact: true, abortRetry: true, clearQueue: true,
|
|
43
40
|
state: true, stats: true, messages: true, context: true, beforeCompact: true }),
|
|
@@ -56,12 +53,9 @@ const pi: ExecutorDriver = {
|
|
|
56
53
|
},
|
|
57
54
|
};
|
|
58
55
|
|
|
59
|
-
const codexVersion = '0.172.0';
|
|
60
56
|
const codex: ExecutorDriver = {
|
|
61
57
|
kind: 'codex',
|
|
62
58
|
name: 'Codex',
|
|
63
|
-
version: codexVersion,
|
|
64
|
-
compatibleVersions: Object.freeze([codexVersion]),
|
|
65
59
|
defaultMaxOutputTokens: null,
|
|
66
60
|
capabilities: Object.freeze({ ...sharedCapabilities, contextFork: false, steeringModes: Object.freeze(['all'] as const) }),
|
|
67
61
|
assertEnvironment(environment) {
|
|
@@ -72,30 +66,33 @@ const codex: ExecutorDriver = {
|
|
|
72
66
|
credentials(_model, _baseUrl, token) {
|
|
73
67
|
return { environment: {}, secretEnvironment: { OPENAI_API_KEY: token } };
|
|
74
68
|
},
|
|
75
|
-
start({ model, baseUrl }) {
|
|
76
|
-
return { command: 'codex', args: [], codex: { model: model.model, baseUrl, version
|
|
69
|
+
start({ model, baseUrl, version }) {
|
|
70
|
+
return { command: 'codex', args: [], codex: { model: model.model, baseUrl, version } };
|
|
77
71
|
},
|
|
78
72
|
};
|
|
79
73
|
|
|
80
74
|
const drivers = { pi: Object.freeze(pi), codex: Object.freeze(codex) } satisfies Record<ExecutorKind, ExecutorDriver>;
|
|
81
75
|
|
|
76
|
+
/** Preserve the contract for explicitly prepared deployments without a version pin. */
|
|
77
|
+
export function legacyImageExecutorVersion(kind: string) {
|
|
78
|
+
return kind === 'pi' ? '1.3.0' : kind === 'codex' ? '0.172.0' : undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
82
81
|
function invalid(message: string): never {
|
|
83
82
|
throw Object.assign(new Error(message), { code: 'INVALID_CONTRACT' });
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
export function createPiExecutor({ version
|
|
85
|
+
export function createPiExecutor({ version }: { version?: string } = {}): BuiltinExecutorSelection {
|
|
87
86
|
return builtinSelection('pi', version);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
export function createCodexExecutor({ version
|
|
89
|
+
export function createCodexExecutor({ version }: { version?: string } = {}): BuiltinExecutorSelection {
|
|
91
90
|
return builtinSelection('codex', version);
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
function builtinSelection(kind: ExecutorKind, version
|
|
95
|
-
if (!
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
return Object.freeze({ kind, version });
|
|
93
|
+
function builtinSelection(kind: ExecutorKind, version?: string) {
|
|
94
|
+
if (version !== undefined && !executorVersion(version)) invalid(`${kind} requires an exact executor version`);
|
|
95
|
+
return Object.freeze({ kind, ...(version === undefined ? {} : { version }) });
|
|
99
96
|
}
|
|
100
97
|
|
|
101
98
|
export function createExecutorAdapter(input: ExecutorAdapter): ExecutorAdapter {
|
|
@@ -118,7 +115,7 @@ export function selectExecutorDriver(executor: unknown = 'pi'): Readonly<Executo
|
|
|
118
115
|
const input = executor as BuiltinExecutorSelection | ExecutorAdapter;
|
|
119
116
|
if (typeof input.kind === 'string' && Object.hasOwn(drivers, input.kind)) {
|
|
120
117
|
const driver = drivers[input.kind as ExecutorKind];
|
|
121
|
-
return Object.freeze({ ...driver, ...builtinSelection(input.kind as ExecutorKind, input.version
|
|
118
|
+
return Object.freeze({ ...driver, ...builtinSelection(input.kind as ExecutorKind, input.version) });
|
|
122
119
|
}
|
|
123
120
|
const adapter = createExecutorAdapter(input as ExecutorAdapter);
|
|
124
121
|
return Object.freeze<ExecutorDriver>({
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
|
+
import { constants, createReadStream } from 'node:fs';
|
|
4
|
+
import { access, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rm, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { homedir, tmpdir } from 'node:os';
|
|
5
6
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
6
7
|
import { promisify } from 'node:util';
|
|
7
8
|
import type { ExecutorKind } from '../backend-config.js';
|
|
8
|
-
import {
|
|
9
|
+
import { executorVersion } from '../executor-adapter.js';
|
|
9
10
|
|
|
10
11
|
const execute = promisify(execFile);
|
|
11
12
|
const packageNames = { pi: '@earendil-works/pi-coding-agent', codex: '@openai/codex' } as const;
|
|
12
13
|
|
|
13
|
-
export type LocalExecutorSelection = { kind: ExecutorKind; entry: string };
|
|
14
|
+
export type LocalExecutorSelection = { kind: ExecutorKind; entry: string; version?: string };
|
|
14
15
|
type Package = {
|
|
15
16
|
name?: string;
|
|
16
17
|
version?: string;
|
|
@@ -25,11 +26,11 @@ export function executorFailure(message: string) {
|
|
|
25
26
|
return Object.assign(new Error(message), { code: 'LOCAL_EXECUTOR_UNAVAILABLE' });
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
export async function findExecutorEntry(kind: ExecutorKind) {
|
|
29
|
+
export async function findExecutorEntry(kind: ExecutorKind, accepts?: (entry: string) => Promise<boolean>) {
|
|
29
30
|
for (const base of (process.env.PATH ?? '').split(':')) {
|
|
30
31
|
if (!isAbsolute(base)) continue;
|
|
31
32
|
const entry = join(base, kind);
|
|
32
|
-
if (await access(entry, constants.X_OK).then(() => true, () => false)) return entry;
|
|
33
|
+
if (await access(entry, constants.X_OK).then(() => true, () => false) && (!accepts || await accepts(entry))) return entry;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -52,16 +53,13 @@ async function locatePackage(selection: LocalExecutorSelection, signal: AbortSig
|
|
|
52
53
|
while (directory !== dirname(directory) && !directory.endsWith(sep + 'node_modules' + sep + name)) {
|
|
53
54
|
directory = dirname(directory);
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
const npm = directory.endsWith(sep + 'node_modules' + sep + name);
|
|
57
|
+
if (!npm && !(process.platform === 'darwin' && kind === 'codex' && basename(executable) === 'codex')) throw notSupported();
|
|
56
58
|
const moduleRoot = dirname(dirname(directory));
|
|
57
|
-
const metadata = await readPackage(directory).catch(() => { throw notSupported(); });
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
throw notSupported();
|
|
61
|
-
}
|
|
62
|
-
const compatible = selectExecutorDriver(kind).compatibleVersions;
|
|
63
|
-
if (!metadata.version || !compatible.includes(metadata.version)) {
|
|
64
|
-
throw executorFailure(`Selected ${kind} at ${selection.entry} reports package version ${metadata.version ?? 'unknown'}. This SDK supports ${compatible.join(', ')}.`);
|
|
59
|
+
const metadata = npm ? await readPackage(directory).catch(() => { throw notSupported(); }) : undefined;
|
|
60
|
+
if (metadata) {
|
|
61
|
+
const entry = metadata.bin?.[kind];
|
|
62
|
+
if (metadata.name !== name || !entry || !below(directory, executable) || resolve(directory, entry) !== executable) throw notSupported();
|
|
65
63
|
}
|
|
66
64
|
const home = await mkdtemp(join(tmpdir(), 'anyswarm-executor-probe-'));
|
|
67
65
|
try {
|
|
@@ -72,9 +70,15 @@ async function locatePackage(selection: LocalExecutorSelection, signal: AbortSig
|
|
|
72
70
|
signal.throwIfAborted();
|
|
73
71
|
throw executorFailure(`Could not run ${kind} --version at ${selection.entry}. Check the installation and its dependencies.`);
|
|
74
72
|
});
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
const reported = stdout.trim();
|
|
74
|
+
const version = kind === 'pi' ? reported : /^codex-cli (.+)$/.exec(reported)?.[1];
|
|
75
|
+
if (!executorVersion(version) || (metadata && version !== metadata.version)) {
|
|
76
|
+
throw executorFailure(`Could not verify the exact version of the selected ${kind} at ${selection.entry}.`);
|
|
77
|
+
}
|
|
78
|
+
if (selection.version !== undefined && selection.version !== version) {
|
|
79
|
+
throw executorFailure(`The selected ${kind} at ${selection.entry} is ${version}, but ${selection.version} was requested.`);
|
|
80
|
+
}
|
|
81
|
+
return { directory, moduleRoot, metadata, version, executable };
|
|
78
82
|
} finally {
|
|
79
83
|
await rm(home, { recursive: true, force: true });
|
|
80
84
|
}
|
|
@@ -100,9 +104,51 @@ async function resolveDependency(directory: string, moduleRoot: string, name: st
|
|
|
100
104
|
|
|
101
105
|
const privateFiles = new Set(['.npmrc', '.ssh', '.git', '.env', 'auth.json']);
|
|
102
106
|
|
|
107
|
+
export async function snapshotLinuxExecutor(selection: LocalExecutorSelection, destination: string,
|
|
108
|
+
{ image, platform, signal }: { image: string; platform: string; signal: AbortSignal }) {
|
|
109
|
+
const { version } = await locatePackage(selection, signal);
|
|
110
|
+
const name = packageNames[selection.kind];
|
|
111
|
+
const container = `anyswarm-executor-${randomUUID()}`;
|
|
112
|
+
const cache = join(homedir(), '.cache', 'anyswarm', 'executor-npm', platform.replace('/', '-'));
|
|
113
|
+
await mkdir(destination, { recursive: true });
|
|
114
|
+
await mkdir(cache, { recursive: true, mode: 0o700 });
|
|
115
|
+
const cacheInfo = await lstat(cache);
|
|
116
|
+
if (!cacheInfo.isDirectory() || cacheInfo.uid !== process.getuid?.() || (cacheInfo.mode & 0o077) !== 0) {
|
|
117
|
+
throw executorFailure('The local executor npm cache must be an owner-only directory.');
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
await execute('docker', ['run', '--rm', '--name', container, '--platform', platform,
|
|
121
|
+
'--mount', `type=bind,source=${await realpath(destination)},target=/out`,
|
|
122
|
+
'--mount', `type=bind,source=${await realpath(cache)},target=/npm-cache`, '--entrypoint', 'sh', image, '-eu', '-c', `
|
|
123
|
+
cd /tmp
|
|
124
|
+
npm install --prefix /tmp/executor --save-exact --omit=dev --ignore-scripts --no-bin-links \\
|
|
125
|
+
--cache /npm-cache --no-audit --no-fund --fetch-retries=1 --fetch-timeout=120000 --registry=https://registry.npmjs.org/ "$1"
|
|
126
|
+
node -e 'const pkg = require(process.argv[1]); const entry = pkg.bin[process.argv[3]]; if (pkg.version !== process.argv[2] || typeof entry !== "string") process.exit(1); process.stdout.write(entry);' "/tmp/executor/node_modules/$2/package.json" "$3" "$4" > /out/entry
|
|
127
|
+
tar --create --file=/out/program.tar --directory=/tmp/executor/node_modules --format=gnu \\
|
|
128
|
+
--sort=name --mtime=@0 --owner=0 --group=0 --numeric-owner --mode=u=rwX,go=rX --hard-dereference \\
|
|
129
|
+
--exclude=.package-lock.json .
|
|
130
|
+
`, 'prepare-executor', `${name}@${version}`, name, version, selection.kind], { signal, timeout: 600_000, killSignal: 'SIGKILL', maxBuffer: 1024 * 1024 });
|
|
131
|
+
} catch {
|
|
132
|
+
signal.throwIfAborted();
|
|
133
|
+
throw executorFailure(`Could not prepare ${name}@${version} for ${platform}. Check registry access from Docker and availability of the exact Linux package.`);
|
|
134
|
+
} finally {
|
|
135
|
+
await execute('docker', ['rm', '-f', container], { timeout: 10_000 }).catch(() => {});
|
|
136
|
+
}
|
|
137
|
+
// Recheck the selected executable after Linux material generation, as on Linux.
|
|
138
|
+
if (await checkLocalExecutor(selection, signal) !== version) throw executorFailure('The selected installation changed during preparation.');
|
|
139
|
+
const hash = createHash('sha256');
|
|
140
|
+
for await (const chunk of createReadStream(join(destination, 'program.tar'), { signal })) hash.update(chunk);
|
|
141
|
+
const digest = hash.digest('hex');
|
|
142
|
+
await writeFile(join(destination, 'SHA256SUMS'), `${digest} program.tar\n`);
|
|
143
|
+
const entry = await readFile(join(destination, 'entry'), 'utf8');
|
|
144
|
+
if (!entry || isAbsolute(entry) || entry.split('/').includes('..')) throw executorFailure('Linux executor package has an invalid executable entry.');
|
|
145
|
+
return { ...selection, version, digest, guestEntry: `node_modules/${name}/${entry}` };
|
|
146
|
+
}
|
|
147
|
+
|
|
103
148
|
export async function snapshotLocalExecutor(selection: LocalExecutorSelection, destination: string, signal: AbortSignal) {
|
|
104
149
|
const installation = await locatePackage(selection, signal);
|
|
105
150
|
const { directory, moduleRoot, metadata, executable, version } = installation;
|
|
151
|
+
if (!metadata) throw executorFailure('This platform requires an npm installation of the selected executor.');
|
|
106
152
|
const packages = new Set<string>();
|
|
107
153
|
const files: string[] = [];
|
|
108
154
|
await mkdir(destination, { recursive: true });
|
|
@@ -8,7 +8,7 @@ import { promisify } from 'node:util';
|
|
|
8
8
|
import { PACKAGE_VERSION, WORKER_PROTOCOL } from '../worker-image.js';
|
|
9
9
|
import { fileProtocol } from '../files/core-file-seed.js';
|
|
10
10
|
import type { ExecutorKind } from '../backend-config.js';
|
|
11
|
-
import { snapshotLocalExecutor, executorFailure, type LocalExecutorSelection } from './local-executor.js';
|
|
11
|
+
import { snapshotLinuxExecutor, snapshotLocalExecutor, executorFailure, type LocalExecutorSelection } from './local-executor.js';
|
|
12
12
|
|
|
13
13
|
const execute = promisify(execFile);
|
|
14
14
|
const sdkRoot = fileURLToPath(new URL('../../../..', import.meta.url));
|
|
@@ -73,14 +73,15 @@ async function stageSdk(context: string, signal: AbortSignal) {
|
|
|
73
73
|
return hash.digest('hex');
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
async function inspect(reference: string, expected: Record<string, string>, signal: AbortSignal) {
|
|
76
|
+
async function inspect(reference: string, expected: Record<string, string>, signal: AbortSignal, platform?: string) {
|
|
77
77
|
const result = await execute('docker', ['image', 'inspect', reference], { signal, timeout: 10_000 }).catch(error => {
|
|
78
78
|
signal.throwIfAborted();
|
|
79
79
|
if (/No such image|not found/i.test(String(error.stderr))) return undefined;
|
|
80
80
|
throw workerFailure('Docker could not inspect a local Worker. Check access to the local Docker engine.');
|
|
81
81
|
});
|
|
82
82
|
if (!result) return;
|
|
83
|
-
const [image] = JSON.parse(result.stdout) as { Id: string; Config?: { Labels?: Record<string, string> } }[];
|
|
83
|
+
const [image] = JSON.parse(result.stdout) as { Id: string; Os: string; Architecture: string; Config?: { Labels?: Record<string, string> } }[];
|
|
84
|
+
if (platform && `${image?.Os}/${image?.Architecture}` !== platform) return;
|
|
84
85
|
const labels = image?.Config?.Labels;
|
|
85
86
|
if (imageId.test(image?.Id) && Object.entries(expected).every(([key, value]) => labels?.[label + key] === value)) return image.Id;
|
|
86
87
|
}
|
|
@@ -89,7 +90,9 @@ export async function prepareLocalWorker(selection: LocalExecutorSelection,
|
|
|
89
90
|
{ signal = AbortSignal.timeout(900_000), build = true, progress, requiredVersion }: {
|
|
90
91
|
signal?: AbortSignal; build?: boolean; requiredVersion?: string; progress?: (message: string) => void;
|
|
91
92
|
} = {}): Promise<LocalWorker> {
|
|
92
|
-
if (
|
|
93
|
+
if (requiredVersion !== undefined) selection = { ...selection, version: requiredVersion };
|
|
94
|
+
const darwin = process.platform === 'darwin';
|
|
95
|
+
if (!darwin && process.platform !== 'linux') throw workerFailure('Local Worker preparation requires Linux or macOS with a local Docker engine.');
|
|
93
96
|
await localDockerSocket(signal).catch(error => {
|
|
94
97
|
signal.throwIfAborted();
|
|
95
98
|
if (error.code === 'LOCAL_WORKER_UNAVAILABLE') throw error;
|
|
@@ -97,24 +100,29 @@ export async function prepareLocalWorker(selection: LocalExecutorSelection,
|
|
|
97
100
|
});
|
|
98
101
|
const context = await mkdtemp(join(tmpdir(), 'anyswarm-worker-'));
|
|
99
102
|
try {
|
|
103
|
+
const reportedPlatform = await execute('docker', ['info', '--format', '{{.OSType}}/{{.Architecture}}'], { signal, timeout: 10_000 })
|
|
104
|
+
.then(({ stdout }) => stdout.trim()).catch(() => {
|
|
105
|
+
signal.throwIfAborted();
|
|
106
|
+
throw workerFailure('Docker is unavailable. Check access to the local Linux Docker engine.');
|
|
107
|
+
});
|
|
108
|
+
const architecture = process.arch === 'x64' ? 'amd64' : process.arch;
|
|
109
|
+
if (!['arm64', 'amd64'].includes(architecture) || ![`linux/${architecture}`,
|
|
110
|
+
`linux/${architecture === 'amd64' ? 'x86_64' : 'aarch64'}`, `linux/${process.arch}`].includes(reportedPlatform)) {
|
|
111
|
+
throw workerFailure(`Docker platform ${reportedPlatform} does not match the native host architecture ${process.arch}.`);
|
|
112
|
+
}
|
|
113
|
+
const platform = darwin ? `linux/${architecture}` : reportedPlatform;
|
|
114
|
+
const sdkDigest = await stageSdk(context, signal);
|
|
115
|
+
const dockerfile = join(context, 'deploy/worker/Dockerfile');
|
|
116
|
+
const nodeImage = /^ARG NODE_IMAGE=(\S+@sha256:[a-f0-9]{64})$/m.exec(await readFile(dockerfile, 'utf8'))?.[1];
|
|
117
|
+
if (darwin && !nodeImage) throw workerFailure('Linux executor preparation requires a pinned Worker Node image.');
|
|
100
118
|
progress?.(`Checking the selected ${selection.kind} installation at ${selection.entry}`);
|
|
101
|
-
const
|
|
119
|
+
const destination = join(context, 'executor');
|
|
120
|
+
const executor = await (darwin ? snapshotLinuxExecutor(selection, destination, { image: nodeImage!, platform, signal })
|
|
121
|
+
: snapshotLocalExecutor(selection, destination, signal)).catch(error => {
|
|
102
122
|
signal.throwIfAborted();
|
|
103
123
|
if (error.code !== 'LOCAL_EXECUTOR_UNAVAILABLE') throw error;
|
|
104
124
|
throw executorFailure(`SDK ${PACKAGE_VERSION}: ${error.message}`);
|
|
105
125
|
});
|
|
106
|
-
if (requiredVersion !== undefined && requiredVersion !== executor.version) {
|
|
107
|
-
throw executorFailure(`This Runtime requests ${executor.kind} ${requiredVersion}, but the selected executable at ${executor.entry} is ${executor.version}.`);
|
|
108
|
-
}
|
|
109
|
-
const sdkDigest = await stageSdk(context, signal);
|
|
110
|
-
const platform = await execute('docker', ['info', '--format', '{{.OSType}}/{{.Architecture}}'], { signal, timeout: 10_000 })
|
|
111
|
-
.then(({ stdout }) => stdout.trim()).catch(() => {
|
|
112
|
-
signal.throwIfAborted();
|
|
113
|
-
throw workerFailure('Docker is unavailable. Check access to the same-host Linux Docker engine.');
|
|
114
|
-
});
|
|
115
|
-
if (!platform.startsWith('linux/') || ![process.arch, process.arch === 'x64' ? 'x86_64' : 'aarch64'].includes(platform.slice(6))) {
|
|
116
|
-
throw workerFailure(`Docker platform ${platform} does not match the Linux host executor architecture ${process.arch}.`);
|
|
117
|
-
}
|
|
118
126
|
const fingerprint = createHash('sha256')
|
|
119
127
|
.update(JSON.stringify([sdkDigest, executor.kind, executor.version, executor.digest, platform])).digest('hex');
|
|
120
128
|
const reference = 'anyswarm-worker-local:' + fingerprint;
|
|
@@ -132,7 +140,7 @@ export async function prepareLocalWorker(selection: LocalExecutorSelection,
|
|
|
132
140
|
executorEntry: executor.entry, executorDigest: executor.digest,
|
|
133
141
|
sdkVersion: PACKAGE_VERSION, sdkDigest, fingerprint,
|
|
134
142
|
};
|
|
135
|
-
const cached = await inspect(reference, verifiedLabels, signal);
|
|
143
|
+
const cached = await inspect(reference, verifiedLabels, signal, darwin ? platform : undefined);
|
|
136
144
|
if (cached) {
|
|
137
145
|
progress?.(`Reusing Worker ${reference} (${cached})`);
|
|
138
146
|
return { ...identity, id: cached, source: 'cache' };
|
|
@@ -142,14 +150,14 @@ export async function prepareLocalWorker(selection: LocalExecutorSelection,
|
|
|
142
150
|
progress?.(`Building Worker ${reference} for SDK ${PACKAGE_VERSION} and ${executor.kind} ${executor.version}`);
|
|
143
151
|
const resultFile = join(context, '.image-id');
|
|
144
152
|
const args = [
|
|
145
|
-
'build', '--
|
|
153
|
+
'build', ...(darwin ? ['--platform', platform] : []), '--file', dockerfile, '--tag', reference, '--iidfile', resultFile,
|
|
146
154
|
'--build-arg', `WORKER_EXECUTOR=${executor.kind}`, '--build-arg', `EXECUTOR_VERSION=${executor.version}`,
|
|
147
155
|
'--build-arg', `EXECUTOR_ENTRY=${executor.guestEntry}`,
|
|
148
156
|
...Object.entries(verifiedLabels).flatMap(([key, value]) => ['--label', `${label}${key}=${value}`]),
|
|
149
157
|
context,
|
|
150
158
|
];
|
|
151
159
|
try {
|
|
152
|
-
await execute('docker', args, { signal, timeout: 900_000, maxBuffer: 16 * 1024 * 1024 });
|
|
160
|
+
await execute('docker', args, { signal, timeout: 900_000, killSignal: 'SIGKILL', maxBuffer: 16 * 1024 * 1024 });
|
|
153
161
|
} catch (error) {
|
|
154
162
|
signal.throwIfAborted();
|
|
155
163
|
const cause = String((error as { stderr?: string }).stderr ?? '');
|
|
@@ -157,7 +165,7 @@ export async function prepareLocalWorker(selection: LocalExecutorSelection,
|
|
|
157
165
|
throw workerFailure(`Docker could not build ${reference}.${diagnostic ? ` ${diagnostic.slice(0, 500)}` : ''} Check build dependencies, Docker access and free disk space, then retry.`);
|
|
158
166
|
}
|
|
159
167
|
const built = (await readFile(resultFile, 'utf8')).trim();
|
|
160
|
-
if (!imageId.test(built) || !await inspect(built, verifiedLabels, signal)) {
|
|
168
|
+
if (!imageId.test(built) || !await inspect(built, verifiedLabels, signal, darwin ? platform : undefined)) {
|
|
161
169
|
throw workerFailure('Docker built a Worker whose identity does not match the SDK and executor materials.');
|
|
162
170
|
}
|
|
163
171
|
return { ...identity, id: built, source: 'build' };
|
|
@@ -62,6 +62,7 @@ interface BackendAgent {
|
|
|
62
62
|
started?: boolean;
|
|
63
63
|
executionEpoch?: number;
|
|
64
64
|
sessionReady?: boolean;
|
|
65
|
+
executorVersion?: string;
|
|
65
66
|
loadedResources?: readonly unknown[];
|
|
66
67
|
activeMessageId?: string;
|
|
67
68
|
sessionCommands?: Map<string, { fingerprint: string; command: string }>;
|
|
@@ -69,6 +70,7 @@ interface BackendAgent {
|
|
|
69
70
|
decisions?: Set<string>;
|
|
70
71
|
workerStartDispatched?: boolean;
|
|
71
72
|
polling?: Promise<void>;
|
|
73
|
+
eventRead?: Promise<boolean>;
|
|
72
74
|
submissions?: Map<string, InputSubmission>;
|
|
73
75
|
executionStopped?: boolean;
|
|
74
76
|
lease?: { expiresAt: string | null; dueAt: number; work?: Promise<void> };
|
|
@@ -182,7 +184,8 @@ interface BackendSpawnOptions {
|
|
|
182
184
|
|
|
183
185
|
import type { CreateRuntimeOptions } from '../types.js';
|
|
184
186
|
import type { ExecutorCapabilities, OpenSandboxBackendConfig, Sandbox, SandboxConfig, SandboxProviderConfig } from '../backend-config.js';
|
|
185
|
-
import { selectExecutorDriver, type ExecutorDriver } from './executor-driver.js';
|
|
187
|
+
import { legacyImageExecutorVersion, selectExecutorDriver, type ExecutorDriver } from './executor-driver.js';
|
|
188
|
+
import { executorVersion } from '../executor-adapter.js';
|
|
186
189
|
import { createHash, randomUUID } from 'node:crypto';
|
|
187
190
|
import { isDeepStrictEqual } from 'node:util';
|
|
188
191
|
import { isIP } from 'node:net';
|
|
@@ -354,6 +357,7 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
354
357
|
runtimeId, outputDir, bridge, modelAccess, registerPrivateValues = () => {}, durability, providers = [config.provider ?? createApiOpenSandboxProvider(config)],
|
|
355
358
|
}: BackendOptions) {
|
|
356
359
|
const { driver } = config;
|
|
360
|
+
const expectedExecutorVersion = driver.version ?? legacyImageExecutorVersion(driver.kind);
|
|
357
361
|
const ledger = durability?.ledger;
|
|
358
362
|
const controllerEpoch = ledger?.run.controllerEpoch;
|
|
359
363
|
const agents = new Map<string, BackendAgent>();
|
|
@@ -473,7 +477,7 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
473
477
|
trace(agent, { type: 'service-tool-directory', ...Object.fromEntries(['status', 'authorizationVersion', 'appliedDirectoryVersion', 'services'].map(key => [key, record[key]])) });
|
|
474
478
|
}
|
|
475
479
|
if (record.type === 'core_session_ready') {
|
|
476
|
-
if (!isDeepStrictEqual(record.capabilities, driver.capabilities.session) || record.version !==
|
|
480
|
+
if (!isDeepStrictEqual(record.capabilities, driver.capabilities.session) || record.version !== agent.executorVersion) {
|
|
477
481
|
agent.onEvent({ type: 'error', error: { code: 'EXECUTOR_CAPABILITY_MISMATCH', message: 'Guest session bridge does not match selected capabilities', retryable: false }, fatal: true });
|
|
478
482
|
} else {
|
|
479
483
|
agent.sessionReady = true;
|
|
@@ -589,7 +593,20 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
589
593
|
agent.polling = agent.eventPoll.run(signal => readWorkerEvents(agent, signal));
|
|
590
594
|
}
|
|
591
595
|
|
|
592
|
-
|
|
596
|
+
function readEventPage(agent: BackendAgent, waitMs: number, signal?: AbortSignal): Promise<boolean> {
|
|
597
|
+
// A command reply and the background poll share one authenticated event
|
|
598
|
+
// reader. Choose the cursor after its predecessor has committed its page.
|
|
599
|
+
const previous = agent.eventRead;
|
|
600
|
+
const work = (previous ?? Promise.resolve()).catch(() => undefined).then(() => {
|
|
601
|
+
if (signal?.aborted) return false;
|
|
602
|
+
return readEventPageNow(agent, waitMs, signal);
|
|
603
|
+
});
|
|
604
|
+
agent.eventRead = work;
|
|
605
|
+
void work.finally(() => { if (agent.eventRead === work) agent.eventRead = undefined; }).catch(() => {});
|
|
606
|
+
return work;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
async function readEventPageNow(agent: BackendAgent, waitMs: number, signal?: AbortSignal) {
|
|
593
610
|
const identity = agent.workerIdentity!;
|
|
594
611
|
eventReads++;
|
|
595
612
|
const page = await (agent.manager as OpenSandboxManager).readWorkerEvents(agent.id, {
|
|
@@ -602,7 +619,7 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
602
619
|
for (const record of unseen) {
|
|
603
620
|
if (record.type === 'agent_start') nativeExecuting = true;
|
|
604
621
|
if (record.type === 'agent_settled' || record.type === 'worker_exit') nativeExecuting = false;
|
|
605
|
-
if (record.type === 'core_session_ready' && record.version ===
|
|
622
|
+
if (record.type === 'core_session_ready' && record.version === agent.executorVersion &&
|
|
606
623
|
isDeepStrictEqual(record.capabilities, driver.capabilities.session)) {
|
|
607
624
|
sessionResources = Array.isArray(record.resources) ? record.resources : [];
|
|
608
625
|
}
|
|
@@ -617,6 +634,8 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
617
634
|
if (!agent.workerIdentity) { consume(agent, records); return; }
|
|
618
635
|
const sequence = records.at(-1)?.worker_sequence ?? 0;
|
|
619
636
|
for (let page = 0; page < 32 && agent.cursor < sequence; page++) {
|
|
637
|
+
await agent.eventRead;
|
|
638
|
+
if (agent.cursor >= sequence) break;
|
|
620
639
|
if (!await readEventPage(agent, 0)) break;
|
|
621
640
|
}
|
|
622
641
|
if (agent.cursor < sequence) throw Object.assign(new Error('Session reply event continuity was not confirmed'), { code: 'OPERATION_UNKNOWN' });
|
|
@@ -733,20 +752,22 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
733
752
|
await provider.prepareSandbox({ sandboxId: sandbox.sandbox_id, agent: identity, bridgeUrl: bridge.publicUrl,
|
|
734
753
|
modelUrl: credentials.baseUrl, additionalEndpoints: profile.network?.allow ?? [], workspace, assertOpen });
|
|
735
754
|
const versions = await manager.agentVersions({ executionId: agentId, executor: driver.kind, externalExecutor: Boolean(driver.adapter) });
|
|
736
|
-
const actualVersion = versions[`${driver.kind}Version`];
|
|
737
|
-
if (!
|
|
738
|
-
throw invalid(`Worker has ${driver.kind} ${actualVersion ?? 'unknown'};
|
|
755
|
+
const actualVersion = driver.adapter?.version ?? versions[`${driver.kind}Version`];
|
|
756
|
+
if (!executorVersion(actualVersion) || actualVersion !== expectedExecutorVersion) {
|
|
757
|
+
throw invalid(`Worker has ${driver.kind} ${actualVersion ?? 'unknown'}; expected ${expectedExecutorVersion}`);
|
|
739
758
|
}
|
|
759
|
+
agent.executorVersion = actualVersion;
|
|
760
|
+
ledger?.checkpoint(agentId, { privateState: { executorVersion: actualVersion } });
|
|
740
761
|
assertOpen();
|
|
741
762
|
const model = config.models[profile.model];
|
|
742
763
|
const tools = effectiveProfileTools(profile, model);
|
|
743
764
|
agent.workerStartDispatched = true;
|
|
744
765
|
const startupOptions = { executionId: agentId,
|
|
745
|
-
...driver.start({ model, baseUrl: credentials.baseUrl, forkSession: Boolean(forkSession) }),
|
|
766
|
+
...driver.start({ model, baseUrl: credentials.baseUrl, forkSession: Boolean(forkSession), version: actualVersion }),
|
|
746
767
|
filePolicy: config.filePolicy,
|
|
747
768
|
controllerSpoolDirectory: outputDir,
|
|
748
769
|
signal,
|
|
749
|
-
executorVersion:
|
|
770
|
+
executorVersion: actualVersion,
|
|
750
771
|
...(driver.kind === 'pi' ? {
|
|
751
772
|
piSession: { configuration: options.session ?? profile.session ?? {}, tools,
|
|
752
773
|
services: { ...(profile.serviceToolMode ? { mode: profile.serviceToolMode } : {}) },
|
|
@@ -774,7 +795,7 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
774
795
|
...(credentials.catalogContent !== undefined ? { modelCatalogContent: credentials.catalogContent } : {}) };
|
|
775
796
|
trace(agent, { type: 'startup-prompt-parameter', systemPromptSha256: createHash('sha256').update(startupOptions.systemPrompt).digest('hex') });
|
|
776
797
|
if (!driver.capabilities.session?.state) trace(agent, { type: 'session-configuration', source: 'executor-capabilities',
|
|
777
|
-
status: 'unsupported', executor: driver.kind, version:
|
|
798
|
+
status: 'unsupported', executor: driver.kind, version: actualVersion });
|
|
778
799
|
const startup = await manager.startAgent(startupOptions);
|
|
779
800
|
if (driver.adapter) {
|
|
780
801
|
const receipt = startup?.backend;
|
|
@@ -810,7 +831,7 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
810
831
|
if ((options.session || profile.session || beforeCompact) && !agent.sessionReady) throw Object.assign(new Error('Worker does not attest session controls'), { code: 'OPERATION_UNSUPPORTED' });
|
|
811
832
|
if (driver.kind === 'pi' && driver.capabilities.session?.state && !agent.sessionReady) {
|
|
812
833
|
trace(agent, { type: 'session-configuration', source: 'startup-handshake', status: 'not-provided',
|
|
813
|
-
executor: driver.kind, version:
|
|
834
|
+
executor: driver.kind, version: actualVersion });
|
|
814
835
|
}
|
|
815
836
|
startPolling(agent);
|
|
816
837
|
return { ...allocation, sandboxId: sandbox.sandbox_id, versions: {
|
|
@@ -829,6 +850,10 @@ export async function openOpenSandboxBackend(config: ResolvedOpenSandboxBackendC
|
|
|
829
850
|
agents.set(agent.id, agent);
|
|
830
851
|
const identity = { runtimeId, agentId: record.agentId, resourceKey: record.resourceKey, generation: record.executionGeneration };
|
|
831
852
|
const stored = record.privateState ?? {};
|
|
853
|
+
agent.executorVersion = expectedExecutorVersion;
|
|
854
|
+
if (stored.executorVersion !== undefined && stored.executorVersion !== expectedExecutorVersion) {
|
|
855
|
+
throw invalid('Recovered Worker version differs from the Runtime selection');
|
|
856
|
+
}
|
|
832
857
|
const workerIdentity = stored.workerIdentity as { workerInstanceId: string; streamEpoch: string; controllerEpoch: number } | undefined;
|
|
833
858
|
const reconnect = async () => {
|
|
834
859
|
let row = ledger.get(record.resourceKey);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { installSourceLoader } from '../../harness/typescript-loader.js';
|
|
1
2
|
import { constants, closeSync, fstatSync, openSync, readFileSync } from 'node:fs';
|
|
2
3
|
import { randomUUID } from 'node:crypto';
|
|
3
4
|
import { lstat, mkdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
5
|
import { homedir, networkInterfaces } from 'node:os';
|
|
5
6
|
import { dirname, join, resolve } from 'node:path';
|
|
6
7
|
import { pathToFileURL } from 'node:url';
|
|
8
|
+
import { executorVersion } from '../executor-adapter.js';
|
|
7
9
|
import type { LocalExecutorSelection } from './local-executor.js';
|
|
8
10
|
|
|
9
11
|
export const defaultLifecycleUrl = 'http://127.0.0.1:8080/v1';
|
|
@@ -42,6 +44,7 @@ interface ConnectionInput {
|
|
|
42
44
|
apiKey?: string;
|
|
43
45
|
endpointHost?: string;
|
|
44
46
|
advertiseHost?: string;
|
|
47
|
+
advertiseHostDiscovery?: 'docker-network';
|
|
45
48
|
publicUrl?: string;
|
|
46
49
|
image?: string;
|
|
47
50
|
useServerProxy?: boolean;
|
|
@@ -99,6 +102,9 @@ function loadSavedConnection(): ConnectionInput {
|
|
|
99
102
|
if (typeof setting !== 'string') throw connectionError(`Saved connection has an invalid ${field}`);
|
|
100
103
|
saved[field] = setting;
|
|
101
104
|
}
|
|
105
|
+
if (saved.advertiseHost && 'advertiseHostDiscovery' in value && value.advertiseHostDiscovery === 'docker-network') {
|
|
106
|
+
saved.advertiseHostDiscovery = value.advertiseHostDiscovery;
|
|
107
|
+
}
|
|
102
108
|
if ('useServerProxy' in value) {
|
|
103
109
|
if (typeof value.useServerProxy !== 'boolean') throw connectionError('Saved server proxy setting is invalid');
|
|
104
110
|
saved.useServerProxy = value.useServerProxy;
|
|
@@ -111,8 +117,9 @@ function loadSavedConnection(): ConnectionInput {
|
|
|
111
117
|
if ('providerId' in value && typeof value.providerId === 'string' && /^[a-f0-9]{64}$/.test(value.providerId)) saved.providerId = value.providerId;
|
|
112
118
|
if ('preparedImage' in value && typeof value.preparedImage === 'string' && /^sha256:[a-f0-9]{64}$/.test(value.preparedImage)) saved.preparedImage = value.preparedImage;
|
|
113
119
|
if ('localExecutor' in value && value.localExecutor && typeof value.localExecutor === 'object') {
|
|
114
|
-
const { kind, entry } = value.localExecutor as LocalExecutorSelection;
|
|
115
|
-
if ((kind === 'pi' || kind === 'codex') && typeof entry === 'string' && entry.startsWith('/')
|
|
120
|
+
const { kind, entry, version } = value.localExecutor as LocalExecutorSelection;
|
|
121
|
+
if ((kind === 'pi' || kind === 'codex') && typeof entry === 'string' && entry.startsWith('/') &&
|
|
122
|
+
(version === undefined || executorVersion(version))) saved.localExecutor = { kind, entry, ...(version === undefined ? {} : { version }) };
|
|
116
123
|
}
|
|
117
124
|
return saved;
|
|
118
125
|
}
|
|
@@ -166,6 +173,7 @@ export function resolveSandboxConnectionWithSources(input: ConnectionInput = {},
|
|
|
166
173
|
apiKey: input.apiKey ?? (environment.OPEN_SANDBOX_API_KEY || environment.ANYSWARM_LIFECYCLE_TOKEN || example('LIFECYCLE_TOKEN') ||
|
|
167
174
|
environment.OPENSANDBOX_API_KEY || undefined) ?? stored.apiKey ?? (local && readPrivateFile(localApiKeyPath(local), 256)),
|
|
168
175
|
advertiseHost: callback?.[1],
|
|
176
|
+
advertiseHostDiscovery: callback?.[0] === 'saved' ? stored.advertiseHostDiscovery : undefined,
|
|
169
177
|
publicUrl: publicUrl === undefined ? undefined : normalizeRuntimePublicUrl(publicUrl),
|
|
170
178
|
image: worker?.[1],
|
|
171
179
|
useServerProxy: input.useServerProxy ?? stored.useServerProxy,
|
|
@@ -181,7 +189,7 @@ export function resolveSandboxConnectionWithSources(input: ConnectionInput = {},
|
|
|
181
189
|
}
|
|
182
190
|
|
|
183
191
|
export function resolveSandboxConnection(...settings: Parameters<typeof resolveSandboxConnectionWithSources>) {
|
|
184
|
-
const { sources: _sources, management: _management, providerId: _providerId,
|
|
192
|
+
const { sources: _sources, advertiseHostDiscovery: _discovery, management: _management, providerId: _providerId,
|
|
185
193
|
localExecutor, preparedImage: _preparedImage, ...connection } = resolveSandboxConnectionWithSources(...settings);
|
|
186
194
|
return { ...connection, executor: localExecutor?.kind };
|
|
187
195
|
}
|
|
@@ -195,11 +203,11 @@ export async function saveSandboxConnection(input: ConnectionInput & { lifecycle
|
|
|
195
203
|
throw connectionError('OpenSandbox configuration directory must be owned by the current user and writable only by its owner');
|
|
196
204
|
}
|
|
197
205
|
const temporary = join(directory, `.opensandbox-${randomUUID()}.tmp`);
|
|
198
|
-
const { lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, image, useServerProxy, egressMode,
|
|
206
|
+
const { lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, advertiseHostDiscovery, image, useServerProxy, egressMode,
|
|
199
207
|
management, providerId, localExecutor, preparedImage } = input;
|
|
200
208
|
try {
|
|
201
209
|
await writeFile(temporary, JSON.stringify({
|
|
202
|
-
schema: 1, endpoint: lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, image, useServerProxy, egressMode,
|
|
210
|
+
schema: 1, endpoint: lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, advertiseHostDiscovery, image, useServerProxy, egressMode,
|
|
203
211
|
management, providerId, localExecutor, preparedImage,
|
|
204
212
|
}, null, 2) + '\n', { mode: 0o600, flag: 'wx' });
|
|
205
213
|
await rename(temporary, path);
|
|
@@ -209,6 +217,7 @@ export async function saveSandboxConnection(input: ConnectionInput & { lifecycle
|
|
|
209
217
|
}
|
|
210
218
|
|
|
211
219
|
export async function loadAnySwarmConfig(filename: string): Promise<unknown> {
|
|
220
|
+
installSourceLoader();
|
|
212
221
|
const configPath = resolve(filename);
|
|
213
222
|
try { process.loadEnvFile(join(dirname(configPath), '.env')); }
|
|
214
223
|
catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; }
|