@anyswarm/core 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/README.md +21 -13
- package/deploy/worker/Dockerfile +12 -4
- package/dist/deploy/worker/Dockerfile +12 -4
- package/dist/examples/README.md +35 -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 +40 -0
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +11 -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 +17 -0
- package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
- package/dist/examples/autoresearch/frontiercs2-config.js +3 -0
- package/dist/examples/autoresearch/frontiercs2.d.ts +87 -0
- package/dist/examples/autoresearch/frontiercs2.js +211 -0
- package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
- package/dist/examples/autoresearch/prepare-demo.js +15 -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 +21 -0
- package/dist/examples/autoresearch/project.js +392 -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 +33 -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 +16 -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/config.js +3 -3
- 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 +52 -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/operator.d.ts +1 -0
- package/dist/examples/super/operator.js +31 -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 +4 -0
- package/dist/examples/super/project.js +251 -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-arguments.d.ts +18 -6
- package/dist/scripts/anyswarm-arguments.js +88 -52
- 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 +1 -0
- package/dist/scripts/anyswarm-harnesses.js +10 -0
- package/dist/scripts/anyswarm-installation.d.ts +7 -40
- package/dist/scripts/anyswarm-installation.js +17 -285
- package/dist/scripts/anyswarm-launch.d.ts +7 -0
- package/dist/scripts/anyswarm-launch.js +37 -0
- package/dist/scripts/anyswarm-progress.d.ts +6 -0
- package/dist/scripts/anyswarm-progress.js +102 -0
- package/dist/scripts/anyswarm-project.d.ts +3 -1
- package/dist/scripts/anyswarm-project.js +49 -35
- package/dist/scripts/anyswarm-source-runner.d.ts +1 -0
- package/dist/scripts/anyswarm-source-runner.js +200 -0
- package/dist/scripts/anyswarm.js +28 -3
- 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 +13 -2
- package/dist/scripts/local-environment.js +111 -28
- 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 +5 -2
- package/dist/scripts/local-setup.js +167 -79
- package/dist/scripts/opensandbox-agent-worker.js +2 -2
- package/dist/scripts/pack-release.d.ts +1 -0
- package/dist/scripts/pack-release.js +66 -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 +14 -1
- package/dist/src/harness/project-harness.js +38 -12
- 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 +6 -2
- 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 +5 -2
- package/docs/architecture/00-overview.md +1 -1
- package/docs/architecture/01-agent-core.md +1 -1
- package/docs/architecture/04-services.md +1 -1
- package/docs/architecture/06-observability-experiments.md +1 -1
- package/docs/architecture/07-run-configuration.md +38 -18
- 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 +152 -89
- 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 -6
- package/docs/architecture/23-project-harness.md +152 -8
- package/docs/architecture/24-runtime-recovery.md +10 -3
- package/docs/architecture/26-code.md +54 -0
- package/docs/architecture/27-personal.md +58 -0
- package/docs/architecture/28-autoresearch.md +43 -0
- package/docs/architecture/INDEX.md +3 -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 +473 -25
- package/docs/designs/core-harness/01-core.md +2 -2
- package/docs/designs/core-harness/06-project-harness.md +13 -2
- package/docs/designs/core-harness/README.md +7 -2
- package/docs/en/agents.md +1 -1
- package/docs/en/build-your-harness.md +3 -5
- package/docs/en/changelog.md +20 -4
- package/docs/en/first-harness.md +9 -12
- 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 +14 -121
- package/docs/en/overview.md +1 -1
- package/docs/en/quickstart.md +42 -39
- package/docs/en/reference/api.md +14 -4
- package/docs/en/reference/cli.md +53 -47
- package/docs/en/runtime.md +2 -2
- package/docs/en/sandbox.md +3 -3
- package/docs/en/services.md +4 -0
- package/docs/operations/trace-viewer.md +1 -1
- package/docs/workflows/development.md +28 -21
- package/docs/workflows/release-and-docs-versioning.md +77 -0
- package/docs/workflows/release-cli-acceptance.md +85 -0
- package/docs/zh/agents.md +1 -1
- package/docs/zh/build-your-harness.md +3 -5
- package/docs/zh/changelog.md +20 -4
- package/docs/zh/first-harness.md +9 -12
- 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 +15 -122
- package/docs/zh/overview.md +1 -1
- package/docs/zh/quickstart.md +42 -39
- package/docs/zh/reference/api.md +14 -4
- package/docs/zh/reference/cli.md +24 -40
- package/docs/zh/runtime.md +2 -2
- package/docs/zh/sandbox.md +3 -3
- package/docs/zh/services.md +4 -0
- package/examples/README.md +35 -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 +40 -0
- package/examples/autoresearch/REQUIREMENTS.zh.md +11 -0
- package/examples/autoresearch/config.ts +90 -0
- package/examples/autoresearch/demo.ts +55 -0
- package/examples/autoresearch/eject.json +17 -0
- package/examples/autoresearch/frontiercs2-config.ts +4 -0
- package/examples/autoresearch/frontiercs2.ts +237 -0
- package/examples/autoresearch/prepare-demo.ts +15 -0
- package/examples/autoresearch/prepare.ts +267 -0
- package/examples/autoresearch/process.ts +50 -0
- package/examples/autoresearch/project.ts +380 -0
- package/examples/autoresearch/research-service.ts +302 -0
- package/examples/code/README.md +33 -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 +16 -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/config.ts +4 -3
- 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 +52 -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/operator.ts +28 -0
- package/examples/super/outbox.ts +97 -0
- package/examples/super/project.ts +225 -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 +700 -0
- package/npm-shrinkwrap.json +95 -1969
- package/package.development.json +88 -0
- package/package.json +11 -8
- package/scripts/anyswarm-arguments.ts +91 -54
- package/scripts/anyswarm-author.ts +25 -0
- package/scripts/anyswarm-eject.ts +145 -0
- package/scripts/anyswarm-harnesses.ts +10 -0
- package/scripts/anyswarm-installation.ts +18 -288
- package/scripts/anyswarm-launch.ts +36 -0
- package/scripts/anyswarm-progress.ts +95 -0
- package/scripts/anyswarm-project.ts +35 -34
- package/scripts/anyswarm-source-runner.ts +176 -0
- package/scripts/anyswarm.ts +24 -3
- 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 +117 -28
- package/scripts/local-setup-smoke.ts +3 -2
- package/scripts/local-setup-worker.ts +17 -7
- package/scripts/local-setup.ts +166 -73
- package/scripts/opensandbox-agent-worker.ts +2 -2
- package/scripts/pack-release.ts +70 -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 +38 -12
- 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 +4 -2
- 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,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 = {
|
|
@@ -112,6 +124,7 @@ type RunResult = ProjectHarnessResult & Pick<HarnessResult, 'operations' | 'ques
|
|
|
112
124
|
reportPath?: string;
|
|
113
125
|
};
|
|
114
126
|
export declare function failureCode(error: unknown, fallback: string): string;
|
|
127
|
+
export declare function loadProjectConfiguration(directory: string, path: string | undefined): Promise<unknown>;
|
|
115
128
|
export declare function createProjectHost(definition: ProjectHarness, options: StartupOptions, emit: (record: unknown) => void): {
|
|
116
129
|
harness: {
|
|
117
130
|
id: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { installSourceLoader } from './typescript-loader.js';
|
|
1
2
|
import { errorDiagnostic, frameworkErrorFields } from '../core/error-diagnostics.js';
|
|
2
3
|
import { loadAnySwarmConfig } from '../core/sandbox/sandbox-connection.js';
|
|
3
4
|
import { createHash, randomUUID } from 'node:crypto';
|
|
@@ -13,8 +14,8 @@ import { fileSpool } from '../core/files/core-file-seed.js';
|
|
|
13
14
|
export { createHarnessSession, captureHarnessSnapshot, getHarnessExitCode, getHarnessRunId, harnessSessionSignal, stopHarnessTransport } from './harness-session.js';
|
|
14
15
|
function moduleSpecifier(directory, specifier) {
|
|
15
16
|
if (isAbsolute(specifier) || specifier.startsWith('./') || specifier.startsWith('../')) {
|
|
16
|
-
if (!['.mjs', '.js'].includes(extname(specifier))) {
|
|
17
|
-
throw projectError('INVALID_HARNESS_MODULE', 'Local Harness modules must be
|
|
17
|
+
if (!['.mjs', '.js', '.ts', '.mts'].includes(extname(specifier))) {
|
|
18
|
+
throw projectError('INVALID_HARNESS_MODULE', 'Local Harness modules must be .ts, .mts, .mjs or .js files');
|
|
18
19
|
}
|
|
19
20
|
return pathToFileURL(resolve(directory, specifier)).href;
|
|
20
21
|
}
|
|
@@ -24,7 +25,8 @@ function moduleSpecifier(directory, specifier) {
|
|
|
24
25
|
}
|
|
25
26
|
return specifier;
|
|
26
27
|
}
|
|
27
|
-
export async function
|
|
28
|
+
export async function loadProjectHarnessModule(directory, specifier, builtins = {}, options = {}) {
|
|
29
|
+
installSourceLoader();
|
|
28
30
|
const builtin = Object.hasOwn(builtins, specifier) ? builtins[specifier] : undefined;
|
|
29
31
|
const target = builtin ?? moduleSpecifier(directory, specifier);
|
|
30
32
|
const parentURL = pathToFileURL(join(directory, '.anyswarm-harness-resolver.mjs')).href;
|
|
@@ -45,7 +47,8 @@ export async function loadProjectHarness(directory, specifier, builtins = {}) {
|
|
|
45
47
|
hook?.deregister();
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
|
-
catch {
|
|
50
|
+
catch (error) {
|
|
51
|
+
options.onSourceError?.(error);
|
|
49
52
|
throw projectError('HARNESS_MODULE_LOAD_FAILED', `Could not load Harness ${JSON.stringify(specifier)}`);
|
|
50
53
|
}
|
|
51
54
|
const definition = module.default;
|
|
@@ -54,14 +57,29 @@ export async function loadProjectHarness(directory, specifier, builtins = {}) {
|
|
|
54
57
|
typeof definition.run !== 'function' || (definition.input !== undefined && definition.input !== true)) {
|
|
55
58
|
throw projectError('INVALID_HARNESS_MODULE', 'Harness default export requires apiVersion 1, a stable id and run(context)');
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
if (options.onSourceError) {
|
|
61
|
+
const harness = definition;
|
|
62
|
+
return { module, definition: { ...harness, async run(context) {
|
|
63
|
+
try {
|
|
64
|
+
return await harness.run(context);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
options.onSourceError(error);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
} } };
|
|
71
|
+
}
|
|
72
|
+
return { module, definition: definition };
|
|
73
|
+
}
|
|
74
|
+
export async function loadProjectHarness(...args) {
|
|
75
|
+
return (await loadProjectHarnessModule(...args)).definition;
|
|
58
76
|
}
|
|
59
77
|
export function failureCode(error, fallback) {
|
|
60
78
|
const { code } = (error ?? {});
|
|
61
79
|
return typeof code === 'string' && (/^[A-Z][A-Z0-9_]{0,79}$/.test(code) ||
|
|
62
80
|
(errorDiagnostic(error) && /^[a-z][a-z0-9_]{0,79}$/.test(code))) ? code : fallback;
|
|
63
81
|
}
|
|
64
|
-
async function
|
|
82
|
+
export async function loadProjectConfiguration(directory, path) {
|
|
65
83
|
if (!path)
|
|
66
84
|
return undefined;
|
|
67
85
|
let value;
|
|
@@ -171,7 +189,7 @@ export function createProjectHost(definition, options, emit) {
|
|
|
171
189
|
let enteredHarness = false;
|
|
172
190
|
let failure = null;
|
|
173
191
|
const signal = controller.signal;
|
|
174
|
-
|
|
192
|
+
const spools = new Set();
|
|
175
193
|
const work = async () => {
|
|
176
194
|
// Resolve the directory first so an explicitly nested output can be excluded.
|
|
177
195
|
cwd = await resolveProjectDirectory(raw.cwd);
|
|
@@ -183,7 +201,7 @@ export function createProjectHost(definition, options, emit) {
|
|
|
183
201
|
await writeFile(path, raw.prompt, { flag: 'wx', mode: 0o600 });
|
|
184
202
|
promptPath = path;
|
|
185
203
|
signal.throwIfAborted();
|
|
186
|
-
const configuration = options.configuration !== undefined ? validateConfiguration(options.configuration) : await
|
|
204
|
+
const configuration = options.configuration !== undefined ? validateConfiguration(options.configuration) : await loadProjectConfiguration(options.launchDirectory, options.configPath);
|
|
187
205
|
signal.throwIfAborted();
|
|
188
206
|
let filePolicy;
|
|
189
207
|
try {
|
|
@@ -192,9 +210,17 @@ export function createProjectHost(definition, options, emit) {
|
|
|
192
210
|
catch {
|
|
193
211
|
throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Invalid project file policy');
|
|
194
212
|
}
|
|
195
|
-
const
|
|
213
|
+
const capture = async (requestSignal) => {
|
|
214
|
+
const captured = await captureProject(cwd, outputDir, requestSignal ? AbortSignal.any([signal, requestSignal]) : signal, filePolicy);
|
|
215
|
+
const directory = fileSpool(captured.files).directory;
|
|
216
|
+
spools.add(directory);
|
|
217
|
+
return { ...captured, async dispose() {
|
|
218
|
+
await rm(directory, { recursive: true, force: true });
|
|
219
|
+
spools.delete(directory);
|
|
220
|
+
} };
|
|
221
|
+
};
|
|
222
|
+
const { dispose: _dispose, ...captured } = await capture();
|
|
196
223
|
const { files, manifest, ...source } = captured;
|
|
197
|
-
staged = fileSpool(files);
|
|
198
224
|
initial = { ...source, manifestPath: null };
|
|
199
225
|
signal.throwIfAborted();
|
|
200
226
|
const manifestPath = join(outputDir, 'initial-files.json');
|
|
@@ -205,6 +231,7 @@ export function createProjectHost(definition, options, emit) {
|
|
|
205
231
|
return validateResult(await definition.run({
|
|
206
232
|
input: Object.freeze({ cwd, prompt: raw.prompt }), initial: captured, configuration, runId: id, outputDir, signal,
|
|
207
233
|
lifetime: 'task', clientCapabilities: { questions: false },
|
|
234
|
+
captureProject: capture,
|
|
208
235
|
registerAgentControls() { return () => { }; },
|
|
209
236
|
runWithRuntime() { throw projectError('INVALID_HARNESS_SESSION', 'Runtime reporting requires a HarnessSession'); },
|
|
210
237
|
askUser() { return Promise.reject(projectError('OPERATION_UNSUPPORTED', 'No question channel is available')); },
|
|
@@ -228,8 +255,7 @@ export function createProjectHost(definition, options, emit) {
|
|
|
228
255
|
let workFinished = false;
|
|
229
256
|
const running = work().finally(() => { workFinished = true; });
|
|
230
257
|
const removeSpool = async () => {
|
|
231
|
-
|
|
232
|
-
await rm(staged.directory, { recursive: true, force: true });
|
|
258
|
+
await Promise.all([...spools].map(directory => rm(directory, { recursive: true, force: true })));
|
|
233
259
|
};
|
|
234
260
|
let business;
|
|
235
261
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execFile } from 'node:child_process';
|
|
1
|
+
import { execFile, spawn } from 'node:child_process';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { constants } from 'node:fs';
|
|
4
4
|
import { lstat, mkdtemp, open, opendir, realpath, rm } from 'node:fs/promises';
|
|
@@ -12,8 +12,12 @@ const git = promisify(execFile);
|
|
|
12
12
|
const utf8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
13
13
|
const maxPathBytes = 4095;
|
|
14
14
|
const maxPathDepth = 128;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// Darwin's sys/fcntl.h O_NOFOLLOW_ANY checks every path component during open.
|
|
16
|
+
// Linux opens children relative to the already validated /proc directory descriptor.
|
|
17
|
+
const darwin = process.platform === 'darwin';
|
|
18
|
+
const noLinks = darwin ? 0x20000000 : constants.O_NOFOLLOW;
|
|
19
|
+
const directoryFlags = constants.O_RDONLY | noLinks | constants.O_DIRECTORY;
|
|
20
|
+
const fileFlags = constants.O_RDONLY | noLinks | constants.O_NONBLOCK;
|
|
17
21
|
export function projectError(code, message) {
|
|
18
22
|
return Object.assign(new Error(message), { code });
|
|
19
23
|
}
|
|
@@ -67,8 +71,53 @@ function sameFile(a, b) {
|
|
|
67
71
|
function sourceChanged(path) {
|
|
68
72
|
return projectError('PROJECT_SOURCE_CHANGED', `Project source changed while capturing ${JSON.stringify(path)}`);
|
|
69
73
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
74
|
+
async function* directoryNames(directory, label, signal) {
|
|
75
|
+
if (!darwin) {
|
|
76
|
+
// Node returns byte names for this option, which the opendir types omit.
|
|
77
|
+
const listing = await opendir(`/proc/self/fd/${directory.fd}/.`, { encoding: 'buffer' });
|
|
78
|
+
for await (const entry of listing)
|
|
79
|
+
yield entry.name;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Perl chdir on a filehandle uses fchdir. The helper opens "." relative to
|
|
83
|
+
// that descriptor, so concurrent path changes cannot redirect enumeration.
|
|
84
|
+
const listing = spawn('/usr/bin/perl', ['-e', String.raw `
|
|
85
|
+
open(my $anchor, "<&=3") or exit 1;
|
|
86
|
+
chdir($anchor) or exit 1;
|
|
87
|
+
opendir(my $directory, ".") or exit 1;
|
|
88
|
+
while (defined(my $name = readdir($directory))) {
|
|
89
|
+
print $name, "\0" unless $name eq "." || $name eq "..";
|
|
90
|
+
}
|
|
91
|
+
closedir($directory) or exit 1;
|
|
92
|
+
`], { stdio: ['ignore', 'pipe', 'ignore', directory.fd], env: { PATH: '/usr/bin:/bin' }, signal });
|
|
93
|
+
const exit = new Promise(resolveExit => {
|
|
94
|
+
listing.once('error', () => resolveExit(null));
|
|
95
|
+
listing.once('close', resolveExit);
|
|
96
|
+
});
|
|
97
|
+
try {
|
|
98
|
+
let partial = Buffer.alloc(0);
|
|
99
|
+
for await (const chunk of listing.stdout) {
|
|
100
|
+
signal.throwIfAborted();
|
|
101
|
+
const data = partial.length ? Buffer.concat([partial, chunk]) : chunk;
|
|
102
|
+
let offset = 0;
|
|
103
|
+
for (let end = data.indexOf(0); end !== -1; end = data.indexOf(0, offset)) {
|
|
104
|
+
yield data.subarray(offset, end);
|
|
105
|
+
offset = end + 1;
|
|
106
|
+
}
|
|
107
|
+
partial = data.subarray(offset);
|
|
108
|
+
if (partial.length > maxPathBytes)
|
|
109
|
+
throw sourceChanged(label);
|
|
110
|
+
}
|
|
111
|
+
const status = await exit;
|
|
112
|
+
signal.throwIfAborted();
|
|
113
|
+
if (status !== 0 || partial.length)
|
|
114
|
+
throw sourceChanged(label);
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
if (listing.exitCode === null && listing.signalCode === null)
|
|
118
|
+
listing.kill();
|
|
119
|
+
await exit;
|
|
120
|
+
}
|
|
72
121
|
}
|
|
73
122
|
async function gitFiles(cwd, signal, maxEntries) {
|
|
74
123
|
const env = Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith('GIT_')));
|
|
@@ -146,11 +195,26 @@ export async function captureProject(cwd, outputDir, signal, policy = DEFAULT_FI
|
|
|
146
195
|
}
|
|
147
196
|
}
|
|
148
197
|
async function readProject(cwd, outputDir, spool, signal, policy) {
|
|
198
|
+
if (darwin) {
|
|
199
|
+
cwd = await resolveProjectDirectory(cwd);
|
|
200
|
+
outputDir = await realpath(outputDir);
|
|
201
|
+
}
|
|
149
202
|
const excluded = isInside(cwd, outputDir) ? relative(cwd, outputDir) : null;
|
|
203
|
+
const directoryPaths = new WeakMap();
|
|
204
|
+
async function accessPath(directory, name, label) {
|
|
205
|
+
if (!darwin)
|
|
206
|
+
return `/proc/self/fd/${directory.fd}/${name}`;
|
|
207
|
+
const expected = directoryPaths.get(directory);
|
|
208
|
+
const current = await lstat(expected.path, { bigint: true }).catch(() => { throw sourceChanged(label); });
|
|
209
|
+
if (!sameFile(expected.stat, current))
|
|
210
|
+
throw sourceChanged(label);
|
|
211
|
+
return join(expected.path, name);
|
|
212
|
+
}
|
|
150
213
|
const entries = [];
|
|
151
214
|
const budget = policy.initial;
|
|
152
215
|
const buffer = Buffer.alloc(MAX_COLLECTION_CHUNK_BYTES);
|
|
153
|
-
const skip = (path) => isGitPath(path) ||
|
|
216
|
+
const skip = (path, tracked = false) => isGitPath(path) ||
|
|
217
|
+
(!tracked && /^(?:node_modules|\.anyswarm-sdk|\.anyswarm-code-recovery-[A-Za-z0-9]{6})(?:\/|$)/.test(path)) ||
|
|
154
218
|
(excluded !== null && (path === excluded || path.startsWith(excluded + '/')));
|
|
155
219
|
let bytes = 0;
|
|
156
220
|
let count = 0;
|
|
@@ -160,6 +224,8 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
|
|
|
160
224
|
try {
|
|
161
225
|
if (!sameFile(before, await handle.stat({ bigint: true })))
|
|
162
226
|
throw sourceChanged(label);
|
|
227
|
+
if (darwin && before.isDirectory())
|
|
228
|
+
directoryPaths.set(handle, { path, stat: before });
|
|
163
229
|
return handle;
|
|
164
230
|
}
|
|
165
231
|
catch (error) {
|
|
@@ -176,7 +242,7 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
|
|
|
176
242
|
info.size > BigInt(Math.min(budget.maxBytes, policy.controllerSpoolBytes) - bytes)) {
|
|
177
243
|
throw projectError('PROJECT_FILE_LIMIT', `Project exceeds the file count or byte limit at ${JSON.stringify(path)}`);
|
|
178
244
|
}
|
|
179
|
-
const location = accessPath(parent, name);
|
|
245
|
+
const location = await accessPath(parent, name, path);
|
|
180
246
|
// Check the shared physical filesystem before each file; write failures
|
|
181
247
|
// still take precedence if another process consumes that space meanwhile.
|
|
182
248
|
await checkFileSpace(spool, Number(info.size), 1, 'Controller staging');
|
|
@@ -218,7 +284,7 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
|
|
|
218
284
|
if (!info.isDirectory()) {
|
|
219
285
|
throw projectError('PROJECT_FILE_UNSUPPORTED', `Project ancestor is not a directory: ${JSON.stringify(path)}`);
|
|
220
286
|
}
|
|
221
|
-
const location = accessPath(parent, name);
|
|
287
|
+
const location = await accessPath(parent, name, path);
|
|
222
288
|
const child = await openChecked(location, info, directoryFlags, path);
|
|
223
289
|
try {
|
|
224
290
|
await visit(child);
|
|
@@ -235,7 +301,8 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
|
|
|
235
301
|
signal.throwIfAborted();
|
|
236
302
|
const name = parts[depth];
|
|
237
303
|
const path = parts.slice(0, depth + 1).join('/');
|
|
238
|
-
const
|
|
304
|
+
const location = await accessPath(parent, name, path);
|
|
305
|
+
const info = await lstat(location, { bigint: true }).catch(error => {
|
|
239
306
|
if (error.code === 'ENOENT' && tracked)
|
|
240
307
|
return null;
|
|
241
308
|
if (error.code === 'ENOENT')
|
|
@@ -254,11 +321,9 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
|
|
|
254
321
|
}
|
|
255
322
|
}
|
|
256
323
|
async function walk(directory, prefix = '') {
|
|
257
|
-
|
|
258
|
-
const listing = await opendir(accessPath(directory, '.'), { encoding: 'buffer' });
|
|
259
|
-
for await (const entry of listing) {
|
|
324
|
+
for await (const entry of directoryNames(directory, prefix || '.', signal)) {
|
|
260
325
|
signal.throwIfAborted();
|
|
261
|
-
const name = decodePath(entry
|
|
326
|
+
const name = decodePath(entry);
|
|
262
327
|
const path = prefix + name;
|
|
263
328
|
if (++enumerated > budget.maxEntries) {
|
|
264
329
|
throw projectError('PROJECT_FILE_LIMIT', `Project exceeds the directory enumeration limit at ${JSON.stringify(path)}`);
|
|
@@ -266,7 +331,8 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
|
|
|
266
331
|
if (skip(path))
|
|
267
332
|
continue;
|
|
268
333
|
normalizedPath(path);
|
|
269
|
-
const
|
|
334
|
+
const location = await accessPath(directory, name, path);
|
|
335
|
+
const info = await lstat(location, { bigint: true }).catch(() => { throw sourceChanged(path); });
|
|
270
336
|
if (info.isDirectory())
|
|
271
337
|
await inDirectory(directory, name, path, info, child => walk(child, path + '/'));
|
|
272
338
|
else
|
|
@@ -284,7 +350,7 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
|
|
|
284
350
|
if (paths.size > budget.maxEntries)
|
|
285
351
|
throw projectError('PROJECT_FILE_LIMIT', 'Project exceeds its Git enumeration limit');
|
|
286
352
|
for (const [path, { tracked, gitlink }] of paths) {
|
|
287
|
-
if (skip(path))
|
|
353
|
+
if (skip(path, tracked))
|
|
288
354
|
continue;
|
|
289
355
|
if (path.endsWith('/')) {
|
|
290
356
|
throw projectError('PROJECT_GITLINK_UNSUPPORTED', `Nested repository is in the project scope: ${JSON.stringify(path)}`);
|
|
@@ -32,6 +32,7 @@ export declare class HarnessRpcClient implements HarnessSession {
|
|
|
32
32
|
#private;
|
|
33
33
|
readonly ready: Promise<HarnessRpcReady>;
|
|
34
34
|
readonly agents: HarnessSession['agents'];
|
|
35
|
+
readonly services: HarnessSession['services'];
|
|
35
36
|
constructor(transport: HarnessRpcTransport, options?: HarnessRpcClientOptions);
|
|
36
37
|
describe(): ReturnType<HarnessSession['describe']>;
|
|
37
38
|
start(...[input, request]: Parameters<HarnessSession['start']>): Promise<import("./harness-session-types.js").HarnessStartReceipt>;
|
|
@@ -7,6 +7,7 @@ import { HarnessEventStream } from './harness-event-stream.js';
|
|
|
7
7
|
export class HarnessRpcClient {
|
|
8
8
|
ready;
|
|
9
9
|
agents;
|
|
10
|
+
services;
|
|
10
11
|
#ready = Promise.withResolvers();
|
|
11
12
|
#result = Promise.withResolvers();
|
|
12
13
|
#pending = new Map();
|
|
@@ -78,6 +79,10 @@ export class HarnessRpcClient {
|
|
|
78
79
|
interrupt: (agentId, { requestId, ...options }) => this.#call('agent.interrupt', { agentId, options }, requestId),
|
|
79
80
|
stop: (agentId, { requestId, ...options }) => this.#call('agent.stop', { agentId, options }, requestId),
|
|
80
81
|
});
|
|
82
|
+
this.services = Object.freeze({
|
|
83
|
+
list: () => this.#call('service.list'),
|
|
84
|
+
read: (runtimeId, name) => this.#call('service.read', { runtimeId, name }),
|
|
85
|
+
});
|
|
81
86
|
}
|
|
82
87
|
describe() {
|
|
83
88
|
return this.#call('describe');
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import type { Readable } from 'node:stream';
|
|
2
1
|
import { type HarnessInput } from './project-harness.js';
|
|
2
|
+
import { type RpcReadable } from './project-rpc-lines.js';
|
|
3
3
|
import type { HarnessSession } from './harness-session-types.js';
|
|
4
4
|
type Writer = (record: unknown, replaceableState?: boolean) => Promise<void>;
|
|
5
|
-
|
|
5
|
+
type RpcServerInput = RpcReadable & {
|
|
6
|
+
readonly destroyed: boolean;
|
|
7
|
+
pause(): unknown;
|
|
8
|
+
};
|
|
9
|
+
export declare function runProjectRpc(session: HarnessSession, input: RpcServerInput, write: Writer, launchDirectory: string, initialInput?: HarnessInput, options?: {
|
|
10
|
+
detachOnDisconnect?: boolean;
|
|
11
|
+
}): Promise<number>;
|
|
6
12
|
export {};
|
|
@@ -5,7 +5,7 @@ import { MAX_COMMAND_BYTES } from './foreground-commands.js';
|
|
|
5
5
|
import { captureHarnessSnapshot, failureCode, getHarnessExitCode, getHarnessRunId, harnessSessionSignal, stopHarnessTransport, } from './project-harness.js';
|
|
6
6
|
import { projectError, resolveHarnessInput } from './project-input.js';
|
|
7
7
|
import { readRpcLines } from './project-rpc-lines.js';
|
|
8
|
-
const queryOperations = new Set(['status', 'describe', 'agent.getState', 'agent.getStats', 'agent.getMessages']);
|
|
8
|
+
const queryOperations = new Set(['status', 'describe', 'agent.getState', 'agent.getStats', 'agent.getMessages', 'service.list', 'service.read']);
|
|
9
9
|
const mutationOperations = new Set([
|
|
10
10
|
'run', 'input', 'answer', 'stop', 'agent.configure', 'agent.compact',
|
|
11
11
|
'agent.abortRetry', 'agent.clearQueue', 'agent.send', 'agent.interrupt', 'agent.stop',
|
|
@@ -62,6 +62,14 @@ function dispatch(session, request, launchDirectory) {
|
|
|
62
62
|
if (input !== undefined)
|
|
63
63
|
throw projectError('INVALID_REQUEST', 'Describe takes no input');
|
|
64
64
|
return session.describe();
|
|
65
|
+
case 'service.list':
|
|
66
|
+
if (input !== undefined)
|
|
67
|
+
throw projectError('INVALID_REQUEST', 'Service list takes no input');
|
|
68
|
+
return session.services.list();
|
|
69
|
+
case 'service.read': {
|
|
70
|
+
const { runtimeId, name } = named(input, ['runtimeId', 'name']);
|
|
71
|
+
return session.services.read(requiredString(runtimeId), requiredString(name));
|
|
72
|
+
}
|
|
65
73
|
case 'answer': {
|
|
66
74
|
const { questionId, answer } = named(input, ['questionId', 'answer']);
|
|
67
75
|
if (typeof answer !== 'string' && typeof answer !== 'boolean')
|
|
@@ -143,7 +151,7 @@ function eventRecord(event) {
|
|
|
143
151
|
return { type: 'event', runId: event.runId, event: { kind: event.type, ...event }, sessionEvent: event };
|
|
144
152
|
}
|
|
145
153
|
}
|
|
146
|
-
export async function runProjectRpc(session, input, write, launchDirectory, initialInput) {
|
|
154
|
+
export async function runProjectRpc(session, input, write, launchDirectory, initialInput, options = {}) {
|
|
147
155
|
const done = Promise.withResolvers();
|
|
148
156
|
const queryReceipts = new Map();
|
|
149
157
|
const signal = harnessSessionSignal(session);
|
|
@@ -164,7 +172,7 @@ export async function runProjectRpc(session, input, write, launchDirectory, init
|
|
|
164
172
|
};
|
|
165
173
|
function watchCompletion() {
|
|
166
174
|
const completion = session.completion;
|
|
167
|
-
if (!completion || watchingCompletion)
|
|
175
|
+
if (!completion || watchingCompletion || options.detachOnDisconnect)
|
|
168
176
|
return;
|
|
169
177
|
watchingCompletion = true;
|
|
170
178
|
void completion.then(async (result) => {
|
|
@@ -243,6 +251,11 @@ export async function runProjectRpc(session, input, write, launchDirectory, init
|
|
|
243
251
|
}
|
|
244
252
|
signal.addEventListener('abort', stopTransport, { once: true });
|
|
245
253
|
const unsubscribe = session.onEvent(event => {
|
|
254
|
+
if (event.type === 'result' && options.detachOnDisconnect) {
|
|
255
|
+
void write({ type: 'result', runId: event.result.runId, result: event.result })
|
|
256
|
+
.then(() => done.resolve(getHarnessExitCode(session) ?? 1), done.reject);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
246
259
|
const record = eventRecord(event);
|
|
247
260
|
if (record)
|
|
248
261
|
send(record, event.type === 'state');
|
|
@@ -252,18 +265,29 @@ export async function runProjectRpc(session, input, write, launchDirectory, init
|
|
|
252
265
|
const descriptor = await session.describe();
|
|
253
266
|
const status = captureHarnessSnapshot(session);
|
|
254
267
|
send({ type: 'ready', version: 'v1', harness: status.harness, status, descriptor });
|
|
268
|
+
if (options.detachOnDisconnect && status.phase === 'finished' && session.completion) {
|
|
269
|
+
const result = await session.completion;
|
|
270
|
+
await write({ type: 'result', runId: result.runId, result });
|
|
271
|
+
return getHarnessExitCode(session) ?? 1;
|
|
272
|
+
}
|
|
255
273
|
if (signal.aborted)
|
|
256
274
|
stopTransport();
|
|
257
275
|
else if (initialInput)
|
|
258
276
|
onLine(JSON.stringify({ id: 'foreground-start', operation: 'run', input: initialInput }));
|
|
277
|
+
const disconnect = (reason) => {
|
|
278
|
+
if (options.detachOnDisconnect)
|
|
279
|
+
done.resolve(0);
|
|
280
|
+
else
|
|
281
|
+
stopHarnessTransport(session, reason);
|
|
282
|
+
};
|
|
259
283
|
detach = readRpcLines(input, MAX_COMMAND_BYTES, {
|
|
260
284
|
line: onLine,
|
|
261
285
|
invalid: () => send(errorRecord('INVALID_REQUEST')),
|
|
262
|
-
end: () =>
|
|
263
|
-
error: () =>
|
|
286
|
+
end: () => disconnect('input-ended'),
|
|
287
|
+
error: () => disconnect('input-failed'),
|
|
264
288
|
});
|
|
265
|
-
if (input.readableEnded)
|
|
266
|
-
|
|
289
|
+
if (input.readableEnded || input.destroyed)
|
|
290
|
+
disconnect('input-ended');
|
|
267
291
|
return await done.promise;
|
|
268
292
|
}
|
|
269
293
|
finally {
|
|
@@ -25,6 +25,8 @@ export function observeProjectRuntime(runtime, context, business, controls = {})
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
async function refresh() {
|
|
28
|
+
if (!business)
|
|
29
|
+
return;
|
|
28
30
|
pending = true;
|
|
29
31
|
if (refreshing || closed)
|
|
30
32
|
return;
|
|
@@ -33,7 +35,7 @@ export function observeProjectRuntime(runtime, context, business, controls = {})
|
|
|
33
35
|
while (pending && !closed) {
|
|
34
36
|
pending = false;
|
|
35
37
|
try {
|
|
36
|
-
const detail = await read(business
|
|
38
|
+
const detail = await read(business());
|
|
37
39
|
if (!closed && !signal.aborted)
|
|
38
40
|
context.updateStatus({
|
|
39
41
|
business: json({ runtimeId: runtime.id, runtimeState: runtime.state, detail }),
|
|
@@ -63,7 +65,9 @@ export async function projectConfiguration(context, defaults) {
|
|
|
63
65
|
throw new Error('Missing sandbox, models or image');
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
|
-
catch {
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof ProjectPreflightError)
|
|
70
|
+
throw error;
|
|
67
71
|
throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Configure sandbox, models and image for this Harness');
|
|
68
72
|
}
|
|
69
73
|
context.signal.throwIfAborted();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { registerHooks, stripTypeScriptTypes } from 'node:module';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
let installed = false;
|
|
5
|
+
/** Enable trusted author TypeScript without changing the author's package scope. */
|
|
6
|
+
export function installSourceLoader() {
|
|
7
|
+
if (installed)
|
|
8
|
+
return;
|
|
9
|
+
installed = true;
|
|
10
|
+
// Node 22.19+ supports transformation and inline maps, including enums.
|
|
11
|
+
const transform = stripTypeScriptTypes;
|
|
12
|
+
const sdk = new URL('../core/index.js', import.meta.url).href;
|
|
13
|
+
registerHooks({
|
|
14
|
+
resolve(specifier, context, nextResolve) {
|
|
15
|
+
try {
|
|
16
|
+
return nextResolve(specifier, context);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error.code !== 'ERR_MODULE_NOT_FOUND' &&
|
|
20
|
+
error.code !== 'MODULE_NOT_FOUND')
|
|
21
|
+
throw error;
|
|
22
|
+
if (specifier === '@anyswarm/core')
|
|
23
|
+
return { url: sdk, shortCircuit: true };
|
|
24
|
+
if (context.parentURL?.startsWith('file:') && /^(?:\.{1,2}\/|\/)/.test(specifier) && /\.m?js$/.test(specifier)) {
|
|
25
|
+
const source = new URL(specifier.replace(/\.m?js$/, match => match === '.mjs' ? '.mts' : '.ts'), context.parentURL);
|
|
26
|
+
if (existsSync(source))
|
|
27
|
+
return { url: source.href, shortCircuit: true };
|
|
28
|
+
}
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
load(url, context, nextLoad) {
|
|
33
|
+
if (!url.startsWith('file:') || !/\.(?:ts|mts)$/.test(new URL(url).pathname))
|
|
34
|
+
return nextLoad(url, context);
|
|
35
|
+
const source = transform(readFileSync(fileURLToPath(url), 'utf8'), {
|
|
36
|
+
mode: 'transform', sourceMap: true, sourceUrl: url,
|
|
37
|
+
});
|
|
38
|
+
return { format: 'module', source, shortCircuit: true };
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|