@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
|
@@ -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
|
export const defaultLifecycleUrl = 'http://127.0.0.1:8080/v1';
|
|
8
10
|
export function loopbackLifecycle(url) {
|
|
9
11
|
try {
|
|
@@ -97,6 +99,9 @@ function loadSavedConnection() {
|
|
|
97
99
|
throw connectionError(`Saved connection has an invalid ${field}`);
|
|
98
100
|
saved[field] = setting;
|
|
99
101
|
}
|
|
102
|
+
if (saved.advertiseHost && 'advertiseHostDiscovery' in value && value.advertiseHostDiscovery === 'docker-network') {
|
|
103
|
+
saved.advertiseHostDiscovery = value.advertiseHostDiscovery;
|
|
104
|
+
}
|
|
100
105
|
if ('useServerProxy' in value) {
|
|
101
106
|
if (typeof value.useServerProxy !== 'boolean')
|
|
102
107
|
throw connectionError('Saved server proxy setting is invalid');
|
|
@@ -114,9 +119,10 @@ function loadSavedConnection() {
|
|
|
114
119
|
if ('preparedImage' in value && typeof value.preparedImage === 'string' && /^sha256:[a-f0-9]{64}$/.test(value.preparedImage))
|
|
115
120
|
saved.preparedImage = value.preparedImage;
|
|
116
121
|
if ('localExecutor' in value && value.localExecutor && typeof value.localExecutor === 'object') {
|
|
117
|
-
const { kind, entry } = value.localExecutor;
|
|
118
|
-
if ((kind === 'pi' || kind === 'codex') && typeof entry === 'string' && entry.startsWith('/')
|
|
119
|
-
|
|
122
|
+
const { kind, entry, version } = value.localExecutor;
|
|
123
|
+
if ((kind === 'pi' || kind === 'codex') && typeof entry === 'string' && entry.startsWith('/') &&
|
|
124
|
+
(version === undefined || executorVersion(version)))
|
|
125
|
+
saved.localExecutor = { kind, entry, ...(version === undefined ? {} : { version }) };
|
|
120
126
|
}
|
|
121
127
|
return saved;
|
|
122
128
|
}
|
|
@@ -172,6 +178,7 @@ export function resolveSandboxConnectionWithSources(input = {}, scope, { useSave
|
|
|
172
178
|
apiKey: input.apiKey ?? (environment.OPEN_SANDBOX_API_KEY || environment.ANYSWARM_LIFECYCLE_TOKEN || example('LIFECYCLE_TOKEN') ||
|
|
173
179
|
environment.OPENSANDBOX_API_KEY || undefined) ?? stored.apiKey ?? (local && readPrivateFile(localApiKeyPath(local), 256)),
|
|
174
180
|
advertiseHost: callback?.[1],
|
|
181
|
+
advertiseHostDiscovery: callback?.[0] === 'saved' ? stored.advertiseHostDiscovery : undefined,
|
|
175
182
|
publicUrl: publicUrl === undefined ? undefined : normalizeRuntimePublicUrl(publicUrl),
|
|
176
183
|
image: worker?.[1],
|
|
177
184
|
useServerProxy: input.useServerProxy ?? stored.useServerProxy,
|
|
@@ -186,7 +193,7 @@ export function resolveSandboxConnectionWithSources(input = {}, scope, { useSave
|
|
|
186
193
|
};
|
|
187
194
|
}
|
|
188
195
|
export function resolveSandboxConnection(...settings) {
|
|
189
|
-
const { sources: _sources, management: _management, providerId: _providerId, localExecutor, preparedImage: _preparedImage, ...connection } = resolveSandboxConnectionWithSources(...settings);
|
|
196
|
+
const { sources: _sources, advertiseHostDiscovery: _discovery, management: _management, providerId: _providerId, localExecutor, preparedImage: _preparedImage, ...connection } = resolveSandboxConnectionWithSources(...settings);
|
|
190
197
|
return { ...connection, executor: localExecutor?.kind };
|
|
191
198
|
}
|
|
192
199
|
export async function saveSandboxConnection(input) {
|
|
@@ -198,10 +205,10 @@ export async function saveSandboxConnection(input) {
|
|
|
198
205
|
throw connectionError('OpenSandbox configuration directory must be owned by the current user and writable only by its owner');
|
|
199
206
|
}
|
|
200
207
|
const temporary = join(directory, `.opensandbox-${randomUUID()}.tmp`);
|
|
201
|
-
const { lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, image, useServerProxy, egressMode, management, providerId, localExecutor, preparedImage } = input;
|
|
208
|
+
const { lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, advertiseHostDiscovery, image, useServerProxy, egressMode, management, providerId, localExecutor, preparedImage } = input;
|
|
202
209
|
try {
|
|
203
210
|
await writeFile(temporary, JSON.stringify({
|
|
204
|
-
schema: 1, endpoint: lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, image, useServerProxy, egressMode,
|
|
211
|
+
schema: 1, endpoint: lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, advertiseHostDiscovery, image, useServerProxy, egressMode,
|
|
205
212
|
management, providerId, localExecutor, preparedImage,
|
|
206
213
|
}, null, 2) + '\n', { mode: 0o600, flag: 'wx' });
|
|
207
214
|
await rename(temporary, path);
|
|
@@ -211,6 +218,7 @@ export async function saveSandboxConnection(input) {
|
|
|
211
218
|
}
|
|
212
219
|
}
|
|
213
220
|
export async function loadAnySwarmConfig(filename) {
|
|
221
|
+
installSourceLoader();
|
|
214
222
|
const configPath = resolve(filename);
|
|
215
223
|
try {
|
|
216
224
|
process.loadEnvFile(join(dirname(configPath), '.env'));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ServiceStateRead } from './service-observation-types.js';
|
|
2
|
+
import type { ServiceAdapter } from './service-types.js';
|
|
3
|
+
type Source = {
|
|
4
|
+
instanceId: string;
|
|
5
|
+
readState?: ServiceAdapter['readState'];
|
|
6
|
+
ready(): boolean;
|
|
7
|
+
};
|
|
8
|
+
/** One bounded read per Service, with a separate capacity budget from business work. */
|
|
9
|
+
export declare function createServiceStateReader(redact: (value: unknown) => unknown): {
|
|
10
|
+
cancel(instanceId?: string): void;
|
|
11
|
+
reset(instanceId: string): void;
|
|
12
|
+
read(source: Source | undefined): Promise<ServiceStateRead>;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
const timeoutMs = 1_000;
|
|
2
|
+
const maxBytes = 64 * 1024;
|
|
3
|
+
const maxConcurrentReads = 8;
|
|
4
|
+
/** Detach from provider objects and bound the work before redaction or serialization. */
|
|
5
|
+
function copyJson(value) {
|
|
6
|
+
let allowance = maxBytes;
|
|
7
|
+
function spend(bytes) {
|
|
8
|
+
allowance -= bytes;
|
|
9
|
+
if (allowance < 0)
|
|
10
|
+
throw new Error('Service state exceeds its size limit');
|
|
11
|
+
}
|
|
12
|
+
function visit(value, depth) {
|
|
13
|
+
spend(1);
|
|
14
|
+
if (depth > 32)
|
|
15
|
+
throw new Error('Service state exceeds its depth limit');
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
spend(value.length);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
if (value === null || typeof value === 'boolean' || (typeof value === 'number' && Number.isFinite(value)))
|
|
21
|
+
return value;
|
|
22
|
+
if (!value || typeof value !== 'object')
|
|
23
|
+
throw new Error('Service state is not JSON');
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
if (value.length > allowance)
|
|
26
|
+
throw new Error('Service state exceeds its size limit');
|
|
27
|
+
return Array.from({ length: value.length }, (_, index) => visit(data(value, String(index)), depth + 1));
|
|
28
|
+
}
|
|
29
|
+
const prototype = Object.getPrototypeOf(value);
|
|
30
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
31
|
+
throw new Error('Service state is not a plain JSON object');
|
|
32
|
+
const entries = [];
|
|
33
|
+
for (const key in value) {
|
|
34
|
+
if (!Object.hasOwn(value, key))
|
|
35
|
+
continue;
|
|
36
|
+
spend(key.length + 1);
|
|
37
|
+
entries.push([key, visit(data(value, key), depth + 1)]);
|
|
38
|
+
}
|
|
39
|
+
return Object.fromEntries(entries);
|
|
40
|
+
}
|
|
41
|
+
return visit(value, 0);
|
|
42
|
+
}
|
|
43
|
+
function data(value, key) {
|
|
44
|
+
const entry = Object.getOwnPropertyDescriptor(value, key);
|
|
45
|
+
if (!entry || !Object.hasOwn(entry, 'value'))
|
|
46
|
+
throw new Error('Service state requires own data properties');
|
|
47
|
+
return entry.value;
|
|
48
|
+
}
|
|
49
|
+
function record(value) {
|
|
50
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
51
|
+
}
|
|
52
|
+
function pointer(value) {
|
|
53
|
+
return typeof value === 'string' && value.length <= 512 && /^(?:\/(?:[^~/]|~[01])*)*$/.test(value);
|
|
54
|
+
}
|
|
55
|
+
function label(value) {
|
|
56
|
+
return typeof value === 'string' && value.length > 0 && value.length <= 128;
|
|
57
|
+
}
|
|
58
|
+
function fields(value) {
|
|
59
|
+
return Array.isArray(value) && value.length <= 16 && value.every(field => record(field) && Object.keys(field).every(key => key === 'label' || key === 'path') && label(field.label) && pointer(field.path));
|
|
60
|
+
}
|
|
61
|
+
function presentationIsValid(value) {
|
|
62
|
+
return record(value) && Object.keys(value).every(key => key === 'summary' || key === 'tables') &&
|
|
63
|
+
(value.summary === undefined || fields(value.summary)) &&
|
|
64
|
+
(value.tables === undefined || (Array.isArray(value.tables) && value.tables.length <= 4 && value.tables.every(table => record(table) && Object.keys(table).every(key => ['title', 'path', 'columns'].includes(key)) &&
|
|
65
|
+
label(table.title) && pointer(table.path) && fields(table.columns))));
|
|
66
|
+
}
|
|
67
|
+
function capture(sample, redact) {
|
|
68
|
+
if (!record(sample))
|
|
69
|
+
throw new Error('Service state must provide a capture record');
|
|
70
|
+
const capturedAt = data(sample, 'capturedAt');
|
|
71
|
+
const revision = Object.hasOwn(sample, 'revision') ? data(sample, 'revision') : undefined;
|
|
72
|
+
const presentation = Object.hasOwn(sample, 'presentation') ? data(sample, 'presentation') : undefined;
|
|
73
|
+
const plain = copyJson({ state: data(sample, 'state'), capturedAt,
|
|
74
|
+
...(revision === undefined ? {} : { revision }),
|
|
75
|
+
...(presentation === undefined ? {} : { presentation }) });
|
|
76
|
+
if (!record(plain) || !Object.hasOwn(plain, 'state') || typeof plain.capturedAt !== 'string' ||
|
|
77
|
+
!/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d{1,3})?(?:Z|[+-]\d\d:\d\d)$/.test(plain.capturedAt) ||
|
|
78
|
+
!Number.isFinite(Date.parse(plain.capturedAt)) ||
|
|
79
|
+
(plain.revision !== undefined && !label(plain.revision)) ||
|
|
80
|
+
(plain.presentation !== undefined && !presentationIsValid(plain.presentation))) {
|
|
81
|
+
throw new Error('Service state has invalid data or presentation');
|
|
82
|
+
}
|
|
83
|
+
const safe = redact({
|
|
84
|
+
state: plain.state,
|
|
85
|
+
...(plain.revision === undefined ? {} : { revision: plain.revision }),
|
|
86
|
+
...(plain.presentation === undefined ? {} : { presentation: plain.presentation }),
|
|
87
|
+
});
|
|
88
|
+
const result = { ...safe, capturedAt: new Date(plain.capturedAt).toISOString() };
|
|
89
|
+
if (Buffer.byteLength(JSON.stringify(result)) > maxBytes)
|
|
90
|
+
throw new Error('Service state exceeds its size limit');
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
/** One bounded read per Service, with a separate capacity budget from business work. */
|
|
94
|
+
export function createServiceStateReader(redact) {
|
|
95
|
+
const pending = new Map();
|
|
96
|
+
const timestamps = new Map();
|
|
97
|
+
function failed(source, status, reason) {
|
|
98
|
+
const capturedAt = source && timestamps.get(source.instanceId);
|
|
99
|
+
return { status, reason, ...(capturedAt ? { capturedAt } : {}) };
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
cancel(instanceId) {
|
|
103
|
+
if (instanceId !== undefined)
|
|
104
|
+
pending.get(instanceId)?.cancel();
|
|
105
|
+
else
|
|
106
|
+
for (const read of pending.values())
|
|
107
|
+
read.cancel();
|
|
108
|
+
},
|
|
109
|
+
reset(instanceId) {
|
|
110
|
+
pending.get(instanceId)?.cancel();
|
|
111
|
+
timestamps.delete(instanceId);
|
|
112
|
+
},
|
|
113
|
+
async read(source) {
|
|
114
|
+
if (!source?.ready())
|
|
115
|
+
return failed(source, 'unavailable', 'Service is not ready');
|
|
116
|
+
const { instanceId, readState } = source;
|
|
117
|
+
if (!readState)
|
|
118
|
+
return failed(source, 'unsupported', 'Service does not provide live state');
|
|
119
|
+
const prior = pending.get(instanceId);
|
|
120
|
+
if (prior)
|
|
121
|
+
return structuredClone(await prior.result);
|
|
122
|
+
if (pending.size >= maxConcurrentReads)
|
|
123
|
+
return failed(source, 'unavailable', 'Service state reader is busy');
|
|
124
|
+
const controller = new AbortController();
|
|
125
|
+
const reply = Promise.withResolvers();
|
|
126
|
+
let timer;
|
|
127
|
+
function abort(status, reason) {
|
|
128
|
+
clearTimeout(timer);
|
|
129
|
+
controller.abort();
|
|
130
|
+
reply.resolve(failed(source, status, reason));
|
|
131
|
+
}
|
|
132
|
+
timer = setTimeout(() => abort('timeout', 'Service state read timed out'), timeoutMs);
|
|
133
|
+
pending.set(instanceId, { result: reply.promise, cancel: () => abort('unavailable', 'Service is not ready') });
|
|
134
|
+
async function perform() {
|
|
135
|
+
let result;
|
|
136
|
+
try {
|
|
137
|
+
const raw = await readState({ signal: controller.signal });
|
|
138
|
+
if (controller.signal.aborted)
|
|
139
|
+
return;
|
|
140
|
+
if (!source.ready())
|
|
141
|
+
return abort('unavailable', 'Service is not ready');
|
|
142
|
+
const sample = capture(raw, redact);
|
|
143
|
+
timestamps.set(instanceId, sample.capturedAt);
|
|
144
|
+
result = { ...sample, status: 'available' };
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
if (controller.signal.aborted)
|
|
148
|
+
return;
|
|
149
|
+
result = failed(source, 'error', 'Service state read failed');
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
clearTimeout(timer);
|
|
153
|
+
pending.delete(instanceId);
|
|
154
|
+
}
|
|
155
|
+
reply.resolve(result);
|
|
156
|
+
}
|
|
157
|
+
void perform();
|
|
158
|
+
return structuredClone(await reply.promise);
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import type { JsonValue } from './service-types.js';
|
|
2
|
+
/** Data-only display hints evaluated against a JSON state using JSON Pointer. */
|
|
2
3
|
export interface ServiceStatePresentation {
|
|
3
4
|
summary?: readonly {
|
|
4
5
|
label: string;
|
|
@@ -20,3 +21,22 @@ export interface ServiceStateMetadata {
|
|
|
20
21
|
description?: string;
|
|
21
22
|
presentation?: ServiceStatePresentation;
|
|
22
23
|
}
|
|
24
|
+
/** Explicit public projection produced by a running Service. */
|
|
25
|
+
export interface ServiceLiveState {
|
|
26
|
+
readonly state: JsonValue;
|
|
27
|
+
readonly capturedAt: string;
|
|
28
|
+
readonly revision?: string;
|
|
29
|
+
readonly presentation?: ServiceStatePresentation;
|
|
30
|
+
}
|
|
31
|
+
export interface ServiceStateSource {
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly supported: boolean;
|
|
34
|
+
}
|
|
35
|
+
export type ServiceStateRead = (ServiceLiveState & {
|
|
36
|
+
readonly status: 'available';
|
|
37
|
+
}) | {
|
|
38
|
+
readonly status: 'unsupported' | 'timeout' | 'error' | 'unavailable';
|
|
39
|
+
readonly reason: string;
|
|
40
|
+
/** Last successful capture by this Service instance, when available. */
|
|
41
|
+
readonly capturedAt?: string;
|
|
42
|
+
};
|
|
@@ -19,5 +19,5 @@ export type ProcessIdentity = {
|
|
|
19
19
|
export declare function processIdentity(pid: number): Promise<ProcessIdentity | undefined>;
|
|
20
20
|
export declare function matchProcessIdentity(prior: ProcessIdentity): Promise<ProcessIdentity | undefined>;
|
|
21
21
|
export declare function stopManagedProcess(prior: ProcessIdentity, signal: AbortSignal): Promise<void>;
|
|
22
|
-
/**
|
|
22
|
+
/** Same-host process ownership with argv execution and PID reuse protection. */
|
|
23
23
|
export declare function managedProcessLifecycle(options: ManagedProcessOptions): ServiceLifecycle;
|
|
@@ -1,8 +1,49 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
2
|
+
import { execFile, spawn } from 'node:child_process';
|
|
3
3
|
import { readFile, access } from 'node:fs/promises';
|
|
4
4
|
import { isAbsolute, resolve } from 'node:path';
|
|
5
|
+
import { promisify } from 'node:util';
|
|
6
|
+
import { darwinBootSession } from './host-identity.js';
|
|
7
|
+
const execute = promisify(execFile);
|
|
8
|
+
async function darwinProcessIdentity(pid) {
|
|
9
|
+
// The system JavaScript Objective-C bridge can query libproc without a
|
|
10
|
+
// build toolchain. PROC_PIDTBSDINFO (3) returns the 136-byte proc_bsdinfo.
|
|
11
|
+
const { stdout } = await execute('/usr/bin/osascript', ['-l', 'JavaScript', '-e', `
|
|
12
|
+
ObjC.import('Foundation');
|
|
13
|
+
ObjC.bindFunction('proc_pidinfo', ['int', ['int', 'int', 'uint64', 'void *', 'int']]);
|
|
14
|
+
function run(argv) {
|
|
15
|
+
const data = $.NSMutableData.dataWithLength(136);
|
|
16
|
+
const size = $.proc_pidinfo(Number(argv[0]), 3, 0, data.mutableBytes, 136);
|
|
17
|
+
return size === 136 ? ObjC.unwrap(data.base64EncodedStringWithOptions(0)) : 'unavailable';
|
|
18
|
+
}
|
|
19
|
+
`, '--', String(pid)], { timeout: 2_000, maxBuffer: 4096, env: { PATH: '/usr/bin:/bin' } });
|
|
20
|
+
if (stdout.trim() === 'unavailable') {
|
|
21
|
+
// An inaccessible process is not confirmed absent and must not be replaced.
|
|
22
|
+
try {
|
|
23
|
+
process.kill(pid, 0);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (error.code === 'ESRCH')
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
throw new Error('Managed process identity cannot be verified');
|
|
30
|
+
}
|
|
31
|
+
const data = Buffer.from(stdout.trim(), 'base64');
|
|
32
|
+
if (data.length !== 136 || data.readUInt32LE(12) !== pid)
|
|
33
|
+
throw new Error('Invalid managed process identity');
|
|
34
|
+
if (data.readUInt32LE(4) === 5)
|
|
35
|
+
return undefined; // SZOMB
|
|
36
|
+
const seconds = data.readBigUInt64LE(120);
|
|
37
|
+
const microseconds = data.readBigUInt64LE(128);
|
|
38
|
+
if (seconds === 0n || microseconds >= 1000000n)
|
|
39
|
+
throw new Error('Invalid managed process start time');
|
|
40
|
+
return { pid, startTime: `${seconds}.${microseconds.toString().padStart(6, '0')}`, bootId: darwinBootSession() };
|
|
41
|
+
}
|
|
5
42
|
export async function processIdentity(pid) {
|
|
43
|
+
if (!Number.isSafeInteger(pid) || pid < 1 || pid > 0x7fffffff)
|
|
44
|
+
throw new Error('Invalid managed process PID');
|
|
45
|
+
if (process.platform === 'darwin')
|
|
46
|
+
return darwinProcessIdentity(pid);
|
|
6
47
|
const stat = await readFile(`/proc/${pid}/stat`, 'utf8').catch(error => {
|
|
7
48
|
const code = error.code;
|
|
8
49
|
// Linux can remove the process between opening stat and reading it.
|
|
@@ -50,7 +91,7 @@ function resourceIdentity(context) {
|
|
|
50
91
|
return undefined;
|
|
51
92
|
return resource;
|
|
52
93
|
}
|
|
53
|
-
/**
|
|
94
|
+
/** Same-host process ownership with argv execution and PID reuse protection. */
|
|
54
95
|
export function managedProcessLifecycle(options) {
|
|
55
96
|
options = { ...options, args: [...options.args ?? []], cwd: resolve(options.cwd ?? process.cwd()),
|
|
56
97
|
env: Object.fromEntries(Object.entries({ ...process.env, ...options.env }).filter((entry) => entry[1] !== undefined).sort(([a], [b]) => a.localeCompare(b))),
|
|
@@ -64,8 +105,8 @@ export function managedProcessLifecycle(options) {
|
|
|
64
105
|
return {
|
|
65
106
|
ownership: 'managed', implementationId: options.implementationId, configurationFingerprint, storage: options.storage, resources: options.resources,
|
|
66
107
|
validate(resources) {
|
|
67
|
-
if (process.platform !== 'linux')
|
|
68
|
-
throw new Error('Managed process identity requires Linux
|
|
108
|
+
if (process.platform !== 'linux' && process.platform !== 'darwin')
|
|
109
|
+
throw new Error('Managed process identity requires Linux or macOS');
|
|
69
110
|
if (!isAbsolute(options.command) || !options.implementationId)
|
|
70
111
|
throw new Error('Managed process requires an absolute executable and implementation ID');
|
|
71
112
|
if (resources && Object.keys(resources).length)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ServiceStateMetadata } from './service-observation-types.js';
|
|
1
|
+
import type { ServiceLiveState, ServiceStateMetadata } from './service-observation-types.js';
|
|
2
2
|
import type { ServiceLifecycle } from './service-lifecycle-types.js';
|
|
3
3
|
export type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
4
4
|
[key: string]: JsonValue;
|
|
@@ -125,6 +125,10 @@ export interface ServiceAdapter {
|
|
|
125
125
|
confirmQuiescent?(options: {
|
|
126
126
|
signal: AbortSignal;
|
|
127
127
|
}): boolean | Promise<boolean>;
|
|
128
|
+
/** Optional host-only read of an explicitly public, bounded projection while ready. */
|
|
129
|
+
readState?(options: {
|
|
130
|
+
signal: AbortSignal;
|
|
131
|
+
}): ServiceLiveState | Promise<ServiceLiveState>;
|
|
128
132
|
/** Optional bounded host-only snapshot called during retirement or Runtime close. */
|
|
129
133
|
exportState?(options: {
|
|
130
134
|
signal: AbortSignal;
|
|
@@ -77,7 +77,7 @@ export declare function invokeServiceReply(registration: ServiceRegistration, {
|
|
|
77
77
|
/** Business result helper for the in-process compatibility paths. Bridge uses the full reply. */
|
|
78
78
|
export declare function invokeService(registration: ServiceRegistration, invocation: ServiceInvocation, timeoutMs?: number): Promise<JsonValue>;
|
|
79
79
|
export type ServiceHandler = (input: JsonValue, context: ServiceRequest) => JsonValue | Promise<JsonValue>;
|
|
80
|
-
export declare function inProcessService(definition: ServiceInterface, handlers: Readonly<Record<string, ServiceHandler
|
|
80
|
+
export declare function inProcessService(definition: ServiceInterface, handlers: Readonly<Record<string, ServiceHandler>>, observation?: Pick<ServiceAdapter, 'readState'>): ServiceDefinition;
|
|
81
81
|
/** Bind an explicit provider-reply handler without inspecting arbitrary business values. */
|
|
82
82
|
export declare function createServiceReplyAdapter(invokeReply: NonNullable<ServiceAdapter['invokeReply']>): ServiceAdapter;
|
|
83
83
|
export declare function setAdapterPrivateValues(adapter: ServiceAdapter, values: readonly string[]): void;
|
|
@@ -248,7 +248,7 @@ function captureLifecycle(lifecycle) {
|
|
|
248
248
|
function captureRegistration({ adapter, lifecycle, ...registration }) {
|
|
249
249
|
if (!adapter || typeof adapter.invoke !== 'function')
|
|
250
250
|
invalid('Service adapter requires invoke(request)');
|
|
251
|
-
for (const hook of ['invokeReply', 'exportStateMetadata']) {
|
|
251
|
+
for (const hook of ['invokeReply', 'readState', 'exportStateMetadata']) {
|
|
252
252
|
if (adapter[hook] !== undefined && typeof adapter[hook] !== 'function')
|
|
253
253
|
invalid(`Service ${hook} must be a function`);
|
|
254
254
|
}
|
|
@@ -258,6 +258,7 @@ function captureRegistration({ adapter, lifecycle, ...registration }) {
|
|
|
258
258
|
invalid('Service confirmQuiescent must be a function');
|
|
259
259
|
const captured = Object.freeze({ invoke: adapter.invoke.bind(adapter),
|
|
260
260
|
...(adapter.invokeReply ? { invokeReply: adapter.invokeReply.bind(adapter) } : {}),
|
|
261
|
+
...(adapter.readState ? { readState: adapter.readState.bind(adapter) } : {}),
|
|
261
262
|
...(adapter.exportStateMetadata ? { exportStateMetadata: adapter.exportStateMetadata.bind(adapter) } : {}),
|
|
262
263
|
...(adapter.exportState ? { exportState: adapter.exportState.bind(adapter) } : {}),
|
|
263
264
|
...(adapter.confirmQuiescent ? { confirmQuiescent: adapter.confirmQuiescent.bind(adapter) } : {}) });
|
|
@@ -496,15 +497,19 @@ export async function invokeService(registration, invocation, timeoutMs) {
|
|
|
496
497
|
operation, operation_id: envelope.operation_id, request_outcome: reply.meta.requestOutcome };
|
|
497
498
|
throw new AnySwarmError(reply.error.code, reply.error.message, details, { retryable: reply.error.retryable });
|
|
498
499
|
}
|
|
499
|
-
export function inProcessService(definition, handlers) {
|
|
500
|
+
export function inProcessService(definition, handlers, observation) {
|
|
500
501
|
if (!record(handlers) || !record(definition?.operations) ||
|
|
501
502
|
Object.keys(handlers).length !== Object.keys(definition.operations).length ||
|
|
502
503
|
Object.keys(definition.operations).some(operation => !Object.hasOwn(handlers, operation) || typeof handlers[operation] !== 'function')) {
|
|
503
504
|
invalid('In-process Service requires exactly one handler for each operation');
|
|
504
505
|
}
|
|
505
506
|
const snapshot = Object.freeze({ ...handlers });
|
|
507
|
+
const readState = observation?.readState;
|
|
508
|
+
if (readState !== undefined && typeof readState !== 'function')
|
|
509
|
+
invalid('Service readState must be a function');
|
|
506
510
|
return { interface: definition, provider: 'in-process', create: () => ({
|
|
507
|
-
adapter: { invoke: request => snapshot[request.capability.operation](request.input, request)
|
|
511
|
+
adapter: { invoke: request => snapshot[request.capability.operation](request.input, request),
|
|
512
|
+
...(readState ? { readState: readState.bind(observation) } : {}) },
|
|
508
513
|
}) };
|
|
509
514
|
}
|
|
510
515
|
/** Bind an explicit provider-reply handler without inspecting arbitrary business values. */
|
package/dist/src/core/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { ExecutorSelection } from './executor-adapter.js';
|
|
|
4
4
|
import type { FilePolicy } from './file-policy.js';
|
|
5
5
|
import type { ServiceRegistration, ServiceRegistry } from './services.js';
|
|
6
6
|
import type { ServiceStorage, ServiceResources } from './service-lifecycle-types.js';
|
|
7
|
+
import type { ServiceStateRead, ServiceStateSource } from './service-observation-types.js';
|
|
7
8
|
import type { JsonValue, ServiceDefinition, ServiceToolMode, ServiceManifest } from './service-types.js';
|
|
8
9
|
import type { AgentSessionConfig, ContextInput, ContextInputReceipt, ContextSendOptions, RuntimeHooks, RuntimeSession, SessionEvent } from './session-types.js';
|
|
9
10
|
export {};
|
|
@@ -463,6 +464,8 @@ export interface Runtime {
|
|
|
463
464
|
register(input: RuntimeServiceRegistration): Promise<RuntimeServiceDefinition>;
|
|
464
465
|
get(id: string): RuntimeServiceDefinition | null;
|
|
465
466
|
list(): readonly RuntimeServiceDefinition[];
|
|
467
|
+
listState(): readonly ServiceStateSource[];
|
|
468
|
+
readState(serviceId: string): Promise<ServiceStateRead>;
|
|
466
469
|
start(input: ServiceRetirement): Promise<RuntimeServiceDefinition>;
|
|
467
470
|
stop(input: ServiceRetirement): Promise<RuntimeServiceDefinition>;
|
|
468
471
|
restart(input: ServiceRetirement): Promise<RuntimeServiceDefinition>;
|
|
@@ -14,21 +14,21 @@ function readPackageVersion() {
|
|
|
14
14
|
// Try the compiled dist/src/core -> package root path next.
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
return '0.5.
|
|
17
|
+
return '0.5.1';
|
|
18
18
|
}
|
|
19
19
|
export const PACKAGE_VERSION = readPackageVersion();
|
|
20
20
|
/** Select the locally prepared Worker for the Runtime's executor. */
|
|
21
21
|
export const DEFAULT_WORKER_IMAGE = 'anyswarm-worker-local:default';
|
|
22
22
|
export function workerImageFor(executor = 'pi') {
|
|
23
23
|
const driver = selectExecutorDriver(executor);
|
|
24
|
-
return driver.adapter?.image ?? `anyswarm-worker-local:${driver.kind}${
|
|
24
|
+
return driver.adapter?.image ?? `anyswarm-worker-local:${driver.kind}${driver.version === undefined ? '' : `-${driver.version}`}`;
|
|
25
25
|
}
|
|
26
26
|
export function localWorkerSelector(image) {
|
|
27
27
|
if (image === DEFAULT_WORKER_IMAGE)
|
|
28
28
|
return {};
|
|
29
29
|
if (typeof image !== 'string')
|
|
30
30
|
return;
|
|
31
|
-
const match = /^anyswarm-worker-local:(pi|codex)(?:-(\d+\.\d+\.\d+))?$/.exec(image);
|
|
31
|
+
const match = /^anyswarm-worker-local:(pi|codex)(?:-(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?))?$/.exec(image);
|
|
32
32
|
if (match)
|
|
33
33
|
return { kind: match[1], version: match[2] };
|
|
34
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Runtime, InputReceipt, ConditionalInputReceipt, InterruptReceipt, StopReceipt, SendOptions, ErrorDiagnostic } from '../core/types.js';
|
|
2
2
|
import type { AgentSessionPatch, AgentSessionState, AgentSessionStats, AgentSessionMessages, ContextInput, ContextSendOptions, ContextInputReceipt, SessionControlReceipt } from '../core/session-types.js';
|
|
3
3
|
import type { HarnessInput, HarnessJson, Harness } from './project-harness.js';
|
|
4
|
+
import type { ServiceStateRead, ServiceStateSource } from '../core/service-observation-types.js';
|
|
4
5
|
export type HarnessLifetime = 'task' | 'interactive';
|
|
5
6
|
export type HarnessRequest = Readonly<{
|
|
6
7
|
requestId: string;
|
|
@@ -26,6 +27,8 @@ export type HarnessInputDescriptor = Readonly<{
|
|
|
26
27
|
description?: string;
|
|
27
28
|
schema?: HarnessJson;
|
|
28
29
|
targets?: HarnessJson;
|
|
30
|
+
/** Terminal slash commands or explicit @mentions routed as Harness input. */
|
|
31
|
+
commands?: readonly string[];
|
|
29
32
|
}>;
|
|
30
33
|
export type HarnessDescriptor = Readonly<{
|
|
31
34
|
id: string;
|
|
@@ -224,6 +227,12 @@ export interface HarnessAgents {
|
|
|
224
227
|
reason?: string;
|
|
225
228
|
}): Promise<HarnessAgentReceipt<StopReceipt>>;
|
|
226
229
|
}
|
|
230
|
+
export interface HarnessServices {
|
|
231
|
+
list(): Promise<readonly (ServiceStateSource & {
|
|
232
|
+
readonly runtimeId: string;
|
|
233
|
+
})[]>;
|
|
234
|
+
read(runtimeId: string, name: string): Promise<ServiceStateRead>;
|
|
235
|
+
}
|
|
227
236
|
export interface HarnessSession {
|
|
228
237
|
describe(): Promise<HarnessDescriptor>;
|
|
229
238
|
start(input: HarnessInput, request: HarnessRequest): Promise<HarnessStartReceipt>;
|
|
@@ -232,6 +241,7 @@ export interface HarnessSession {
|
|
|
232
241
|
getState(): Promise<HarnessState>;
|
|
233
242
|
onEvent(handler: (event: HarnessEvent) => void, options?: HarnessSubscriptionOptions): () => void;
|
|
234
243
|
readonly agents: HarnessAgents;
|
|
244
|
+
readonly services: HarnessServices;
|
|
235
245
|
stop(request: HarnessRequest & {
|
|
236
246
|
reason?: string;
|
|
237
247
|
}): Promise<HarnessStopReceipt>;
|
|
@@ -171,13 +171,34 @@ export function createHarnessSession(definition, options = {}) {
|
|
|
171
171
|
if (!event || typeof event !== 'object' || Array.isArray(event) || !('messageId' in event) || typeof event.messageId !== 'string')
|
|
172
172
|
return;
|
|
173
173
|
const eventObject = event;
|
|
174
|
-
const
|
|
174
|
+
const agentId = runtimeObject.agentId ?? null;
|
|
175
|
+
const messageId = eventObject.messageId;
|
|
176
|
+
const key = JSON.stringify([agentId, messageId]);
|
|
175
177
|
const previous = output.get(key);
|
|
176
|
-
if (eventObject.type === 'textDelta' && typeof eventObject.delta === 'string') {
|
|
177
|
-
|
|
178
|
+
if (eventObject.type === 'textDelta' && typeof eventObject.delta === 'string' && !previous?.complete) {
|
|
179
|
+
const index = Number.isSafeInteger(eventObject.blockIndex) ? Number(eventObject.blockIndex) : 0;
|
|
180
|
+
const blocks = new Map(previous?.blocks);
|
|
181
|
+
blocks.set(index, (blocks.get(index) ?? '') + eventObject.delta);
|
|
182
|
+
let truncated = previous?.truncated ?? false;
|
|
183
|
+
if (blocks.size > 64) {
|
|
184
|
+
blocks.delete(blocks.keys().next().value);
|
|
185
|
+
truncated = true;
|
|
186
|
+
}
|
|
187
|
+
const ordered = [...blocks].sort(([left], [right]) => left - right);
|
|
188
|
+
let available = 16_384;
|
|
189
|
+
for (let position = ordered.length - 1; position >= 0; position--) {
|
|
190
|
+
const block = ordered[position];
|
|
191
|
+
if (block[1].length > available) {
|
|
192
|
+
block[1] = available ? block[1].slice(-available) : '';
|
|
193
|
+
truncated = true;
|
|
194
|
+
}
|
|
195
|
+
available -= block[1].length;
|
|
196
|
+
}
|
|
197
|
+
output.set(key, { agentId, messageId, text: ordered.map(([, text]) => text).join(''),
|
|
198
|
+
blocks: ordered, truncated, complete: false });
|
|
178
199
|
}
|
|
179
200
|
else if (eventObject.type === 'messageEnd') {
|
|
180
|
-
output.set(key, { agentId
|
|
201
|
+
output.set(key, { agentId, messageId, message: boundedView(eventObject.message ?? null, 16_384), complete: true });
|
|
181
202
|
}
|
|
182
203
|
while (output.size > 8 || Buffer.byteLength(JSON.stringify([...output.values()])) > Math.floor(limits.snapshotBytes / 4))
|
|
183
204
|
output.delete(output.keys().next().value);
|
|
@@ -660,8 +681,24 @@ export function createHarnessSession(definition, options = {}) {
|
|
|
660
681
|
interrupt: (agentId, request) => control('interrupt', agentId, null, request),
|
|
661
682
|
stop: (agentId, options) => control('stop', agentId, { reason: options.reason }, options),
|
|
662
683
|
};
|
|
684
|
+
const services = {
|
|
685
|
+
async list() {
|
|
686
|
+
if (stopping || finalizing)
|
|
687
|
+
return [];
|
|
688
|
+
return [...registrations.keys()].flatMap(({ runtime }) => (runtime.services?.listState?.() ?? []).map(source => ({ runtimeId: runtime.id, ...source })));
|
|
689
|
+
},
|
|
690
|
+
async read(runtimeId, name) {
|
|
691
|
+
const owner = [...registrations.keys()].find(({ runtime }) => runtime.id === runtimeId);
|
|
692
|
+
if (owner && !stopping && !finalizing && owner.runtime.services?.readState) {
|
|
693
|
+
const state = await owner.runtime.services.readState(name);
|
|
694
|
+
if (!stopping && !finalizing && registrations.has(owner))
|
|
695
|
+
return state;
|
|
696
|
+
}
|
|
697
|
+
return { status: 'unavailable', reason: 'Runtime does not provide live Service state for this Run' };
|
|
698
|
+
},
|
|
699
|
+
};
|
|
663
700
|
const session = {
|
|
664
|
-
agents,
|
|
701
|
+
agents, services,
|
|
665
702
|
async describe() { for (const registration of registrations.keys())
|
|
666
703
|
await refreshTargets(registration); return structuredClone(descriptor()); },
|
|
667
704
|
async getState() { return snapshot(); },
|
|
@@ -50,6 +50,10 @@ export interface HarnessContext {
|
|
|
50
50
|
readonly clientCapabilities: Readonly<{
|
|
51
51
|
questions: boolean;
|
|
52
52
|
}>;
|
|
53
|
+
/** Capture the live project with the same scope and policy as the initial input. Release temporary bytes when done. */
|
|
54
|
+
captureProject(signal?: AbortSignal): Promise<InitialProject & {
|
|
55
|
+
dispose(): Promise<void>;
|
|
56
|
+
}>;
|
|
53
57
|
registerAgentControls(registration: HarnessAgentRegistration): () => void;
|
|
54
58
|
/** Run owned work and use the close receipt in this Run's final report. */
|
|
55
59
|
runWithRuntime<R extends CloseableRuntime>(options: HarnessRuntimeRunOptions<R>): Promise<HarnessRunOutcome>;
|
|
@@ -76,7 +80,15 @@ export type ProjectHarness = Harness;
|
|
|
76
80
|
export type ProjectHarnessContext = HarnessContext;
|
|
77
81
|
/** @deprecated Derive the author result from Harness.run. Use HarnessResult for Session completion. */
|
|
78
82
|
export type ProjectHarnessResult = Awaited<ReturnType<Harness['run']>>;
|
|
79
|
-
export declare function
|
|
83
|
+
export declare function loadProjectHarnessModule(directory: string, specifier: string, builtins?: Readonly<Record<string, string>>, options?: {
|
|
84
|
+
onSourceError?: (error: unknown) => void;
|
|
85
|
+
}): Promise<{
|
|
86
|
+
module: {
|
|
87
|
+
default?: Partial<ProjectHarness>;
|
|
88
|
+
} & Record<string, unknown>;
|
|
89
|
+
definition: Harness;
|
|
90
|
+
}>;
|
|
91
|
+
export declare function loadProjectHarness(...args: Parameters<typeof loadProjectHarnessModule>): Promise<Harness>;
|
|
80
92
|
type Phase = 'idle' | 'starting' | 'running' | 'stopping' | 'finished';
|
|
81
93
|
type StopReason = string;
|
|
82
94
|
type Failure = {
|