@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
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import {
|
|
3
|
+
createRuntime, createSandbox, resolveSandboxConnection, ServiceRegistry, workerImageFor, type Harness,
|
|
4
|
+
} from '@anyswarm/core';
|
|
5
|
+
import { Board } from './business.js';
|
|
6
|
+
import { boardService } from './index.js';
|
|
7
|
+
|
|
8
|
+
const harness: Harness = {
|
|
9
|
+
apiVersion: 1,
|
|
10
|
+
id: 'live-board',
|
|
11
|
+
lifetimes: ['interactive'],
|
|
12
|
+
input: true,
|
|
13
|
+
inputDescriptor: { description: 'Commit a finding to the Board', schema: { type: 'string', minLength: 1, maxLength: 10000 } },
|
|
14
|
+
async run(context) {
|
|
15
|
+
const connection = resolveSandboxConnection();
|
|
16
|
+
const storagePath = join(context.outputDir, 'board.sqlite');
|
|
17
|
+
const services = new ServiceRegistry();
|
|
18
|
+
services.register('board', boardService({ storagePath }));
|
|
19
|
+
return context.runWithRuntime({
|
|
20
|
+
createRuntime: () => createRuntime({
|
|
21
|
+
sandbox: createSandbox({ lifecycleBaseUrl: connection.lifecycleBaseUrl, apiKey: connection.apiKey }),
|
|
22
|
+
connection: { advertiseHost: connection.advertiseHost, publicUrl: connection.publicUrl },
|
|
23
|
+
// This Harness publishes Host input and never spawns a model-backed Agent.
|
|
24
|
+
models: { default: { provider: 'openai', model: 'unused', upstream: { url: 'http://127.0.0.1:1/v1/responses', headers: {} } } },
|
|
25
|
+
profiles: { observer: { model: 'default', image: connection.image ?? workerImageFor('pi'), writable: false } },
|
|
26
|
+
services, maxAgents: 1, outputDir: join(context.outputDir, 'runtime'),
|
|
27
|
+
}),
|
|
28
|
+
async run(runtime) {
|
|
29
|
+
const unregister = context.registerAgentControls({ runtime });
|
|
30
|
+
let writer: Board | undefined;
|
|
31
|
+
try {
|
|
32
|
+
const board = new Board(storagePath, { create: false });
|
|
33
|
+
writer = board;
|
|
34
|
+
context.registerInput(input => {
|
|
35
|
+
if (typeof input !== 'string') throw new TypeError('Enter a text finding');
|
|
36
|
+
const { id } = board.publish('run-owner', input);
|
|
37
|
+
const summary = 'Committed entries ' + board.observation().count;
|
|
38
|
+
context.updateStatus({ business: { summary } });
|
|
39
|
+
context.emit({ kind: 'board.commit', summary: summary + ' · entry ' + id });
|
|
40
|
+
return { id };
|
|
41
|
+
});
|
|
42
|
+
context.markRunning();
|
|
43
|
+
context.updateStatus({ business: { summary: 'Committed entries ' + board.observation().count } });
|
|
44
|
+
await new Promise<void>(resolve => {
|
|
45
|
+
if (context.signal.aborted) resolve();
|
|
46
|
+
else context.signal.addEventListener('abort', () => resolve(), { once: true });
|
|
47
|
+
});
|
|
48
|
+
return { committed: board.observation().count };
|
|
49
|
+
} finally { writer?.close(); unregister(); }
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
export default harness;
|
|
@@ -52,12 +52,12 @@ The example defaults to a local OpenSandbox lifecycle URL of `http://127.0.0.1:8
|
|
|
52
52
|
From `examples/subagents/`, run one task.
|
|
53
53
|
|
|
54
54
|
```sh
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
../../node_modules/.bin/anys run ./main.ts \
|
|
56
|
+
./config.ts \
|
|
57
57
|
'Suggest two checks to make before merging a pull request.'
|
|
58
58
|
```
|
|
59
59
|
|
|
60
|
-
The entry waits for Root's reply, closes the team, and writes the task result and cleanup receipts to `subagents-runs/<runtimeId>/harness-report.json`. Edit `config.ts` or `main.ts` here and
|
|
60
|
+
The entry waits for Root's reply, closes the team, and writes the task result and cleanup receipts to `subagents-runs/<runtimeId>/harness-report.json`. Edit `config.ts` or `main.ts` here and run the TS entry again to try changes.
|
|
61
61
|
|
|
62
62
|
## Fixed or interactive host entry
|
|
63
63
|
|
|
@@ -79,8 +79,8 @@ Install the published SDK or a matching source archive as described above. The e
|
|
|
79
79
|
|
|
80
80
|
```sh
|
|
81
81
|
sdk=node_modules/@anyswarm/core
|
|
82
|
-
example="$sdk"/
|
|
83
|
-
|
|
82
|
+
example="$sdk"/examples/subagents
|
|
83
|
+
node_modules/.bin/anys run "$example/main.ts" "$example/config.ts" --interactive
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
The configured `doctor --smoke` path covers Pi projects. The installed Codex example runs through the same local OpenSandbox provider and its own executor. [Codex startup and capabilities](../../docs/architecture/16-pi-opensandbox-backend.md#codex-app-server)
|
|
@@ -53,7 +53,9 @@ export async function createSubagentsHarness(config: Config, controls: ProjectCo
|
|
|
53
53
|
const services = new ServiceRegistry();
|
|
54
54
|
let team: ReturnType<typeof createSubagentsController>;
|
|
55
55
|
const { contextFork: allowContextFork } = getExecutorCapabilities(config.executor ?? 'pi');
|
|
56
|
-
services.register('collaboration', createCollaborationService(request => team.invoke(request), () => team.exportState(), {
|
|
56
|
+
services.register('collaboration', createCollaborationService(request => team.invoke(request), () => team.exportState(), {
|
|
57
|
+
allowContextFork, readState: () => team.readLiveState(),
|
|
58
|
+
}));
|
|
57
59
|
if (controls.userQuestions) services.register('user-interaction', controls.userQuestions);
|
|
58
60
|
const common = { image, writable: true, serviceToolMode: 'cli' as const, services: { collaboration: collaborationOperations,
|
|
59
61
|
...(controls.userQuestions ? { 'user-interaction': ['ask'] } : {}),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { ownerInterventionText } from '../prompts/prompts.js';
|
|
2
3
|
import {
|
|
3
4
|
type RuntimeEvent, type ConditionalInputReceipt, type Runtime, type SpawnOptions, type JsonValue,
|
|
4
5
|
type ContextInput, type ContextSendOptions, type SendOptions,
|
|
@@ -25,13 +26,19 @@ type Member = {
|
|
|
25
26
|
id?: string;
|
|
26
27
|
inbox: Message[];
|
|
27
28
|
submitted: Map<string, Message>;
|
|
29
|
+
offers: Map<string, { message: Message; discarded?: boolean }>;
|
|
30
|
+
deliveries: Map<string, { hash: string; messages: Message[]; inputId?: string; status: string }>;
|
|
28
31
|
executionRevision: number;
|
|
29
32
|
wait?: Wait;
|
|
30
33
|
lastOutcome?: 'completed' | 'failed' | 'interrupted';
|
|
31
34
|
fatalReported?: boolean;
|
|
32
35
|
tail?: Promise<unknown>;
|
|
33
36
|
pendingDispatches: number;
|
|
37
|
+
ownerEpoch: number;
|
|
38
|
+
ownerInterrupted?: boolean;
|
|
39
|
+
ownerStopped?: boolean;
|
|
34
40
|
};
|
|
41
|
+
type QueueScope = { deliveries: Set<string>; submitted: Set<string> };
|
|
35
42
|
type Operation = {
|
|
36
43
|
id: string;
|
|
37
44
|
fingerprint: string;
|
|
@@ -42,9 +49,12 @@ type Operation = {
|
|
|
42
49
|
inputDispatched?: boolean;
|
|
43
50
|
interruptStatus?: string;
|
|
44
51
|
rootEpoch?: number;
|
|
52
|
+
memberEpoch?: number;
|
|
53
|
+
ownerNotified?: boolean;
|
|
45
54
|
};
|
|
46
55
|
function createMember(path: string, parent?: Member): Member {
|
|
47
|
-
return { path, parent, inbox: [], submitted: new Map(),
|
|
56
|
+
return { path, parent, inbox: [], submitted: new Map(), offers: new Map(), deliveries: new Map(),
|
|
57
|
+
executionRevision: 0, pendingDispatches: 0, ownerEpoch: 0 };
|
|
48
58
|
}
|
|
49
59
|
|
|
50
60
|
const namePattern = /^[a-z0-9_]{1,48}$/;
|
|
@@ -89,11 +99,11 @@ export function createSubagentsController(
|
|
|
89
99
|
let rootEpoch = 0;
|
|
90
100
|
let rootPaused = false;
|
|
91
101
|
let rootControl: 'compact' | 'interrupt' | 'clearQueue' | undefined;
|
|
92
|
-
const rootOffers =
|
|
102
|
+
const rootOffers = root.offers;
|
|
93
103
|
const reconciledRootControls = new Map<string, unknown>();
|
|
94
104
|
const rootControlQueries = new Map<string, Promise<unknown>>();
|
|
95
|
-
const pendingRootControls = new Map<string,
|
|
96
|
-
const rootDeliveries =
|
|
105
|
+
const pendingRootControls = new Map<string, QueueScope>();
|
|
106
|
+
const rootDeliveries = root.deliveries;
|
|
97
107
|
|
|
98
108
|
function open() {
|
|
99
109
|
if (!accepting) fail('NOT_ALLOWED', 'The team is closing');
|
|
@@ -157,7 +167,7 @@ export function createSubagentsController(
|
|
|
157
167
|
|
|
158
168
|
function releaseWait(member: Member) {
|
|
159
169
|
const messages = pending(member);
|
|
160
|
-
if (!member.wait || messages.length === 0 || (member === root && (rootPaused || rootControl))) return false;
|
|
170
|
+
if (member.ownerStopped || member.ownerInterrupted || !member.wait || messages.length === 0 || (member === root && (rootPaused || rootControl))) return false;
|
|
161
171
|
for (const message of messages) message.state = 'returned';
|
|
162
172
|
member.inbox = member.inbox.filter(message => message.state !== 'returned');
|
|
163
173
|
member.wait({ reason: 'message', messages: structuredClone(messages) });
|
|
@@ -169,21 +179,22 @@ export function createSubagentsController(
|
|
|
169
179
|
}
|
|
170
180
|
|
|
171
181
|
async function offer(member: Member, message: Message) {
|
|
182
|
+
if (member.ownerStopped || member.ownerInterrupted) return;
|
|
172
183
|
if (message.state === 'returned' || (message.state === 'pending' && releaseWait(member))) return;
|
|
173
184
|
if (member === root && (rootPaused || rootControl)) return;
|
|
174
185
|
if (member.submitted.size >= operationLimit) fail('NOT_ALLOWED', 'The recipient delivery history limit has been reached');
|
|
175
186
|
const { state: _state, ...payload } = message;
|
|
176
187
|
const body = JSON.stringify(payload);
|
|
177
188
|
const hash = createHash('sha256').update(body).digest('hex');
|
|
178
|
-
const activeOffer =
|
|
179
|
-
|
|
189
|
+
const activeOffer = { message, discarded: false };
|
|
190
|
+
member.offers.set(hash, activeOffer);
|
|
180
191
|
let receipt: ConditionalInputReceipt;
|
|
181
192
|
try {
|
|
182
193
|
receipt = await runtime.send(member.id!, body, {
|
|
183
194
|
requestId: message.id, source: message.from, mode: 'steer', wakeIfIdle: false,
|
|
184
195
|
});
|
|
185
196
|
} finally {
|
|
186
|
-
|
|
197
|
+
member.offers.delete(hash);
|
|
187
198
|
}
|
|
188
199
|
if (activeOffer?.discarded) return;
|
|
189
200
|
if (receipt.status === 'accepted') {
|
|
@@ -227,7 +238,7 @@ export function createSubagentsController(
|
|
|
227
238
|
if (event.type === 'settled' || event.type === 'exit') member.executionRevision++;
|
|
228
239
|
if (event.type === 'settled') {
|
|
229
240
|
member.lastOutcome = event.outcome === 'aborted' ? 'interrupted' : event.outcome;
|
|
230
|
-
if (event.outcome !== 'aborted' && !(member.fatalReported && event.outcome === 'failed')) resultFor(member, event, seq);
|
|
241
|
+
if (!member.ownerStopped && event.outcome !== 'aborted' && !(member.fatalReported && event.outcome === 'failed')) resultFor(member, event, seq);
|
|
231
242
|
} else if (event.type === 'error' && event.fatal && !member.fatalReported) {
|
|
232
243
|
member.lastOutcome = 'failed';
|
|
233
244
|
member.fatalReported = true;
|
|
@@ -250,8 +261,11 @@ export function createSubagentsController(
|
|
|
250
261
|
|
|
251
262
|
function submit(member: Member, entry: Operation, text: string, from: string, requestId: string, authorize?: () => void,
|
|
252
263
|
options: Omit<SendOptions, 'requestId'> = {}, signal?: AbortSignal) {
|
|
264
|
+
entry.memberEpoch ??= member.ownerEpoch;
|
|
253
265
|
const guard = () => {
|
|
254
266
|
signal?.throwIfAborted();
|
|
267
|
+
if (member.ownerStopped) fail('SESSION_UNAVAILABLE', 'The owner stopped this member');
|
|
268
|
+
if (entry.memberEpoch !== member.ownerEpoch) fail('RUN_INPUT_CANCELLED', 'The input predates the member control barrier');
|
|
255
269
|
if (member !== root) return;
|
|
256
270
|
if (entry.rootEpoch !== rootEpoch) fail('RUN_INPUT_CANCELLED', 'The Root input predates its control barrier');
|
|
257
271
|
if (rootControl) fail('OPERATION_BUSY', 'Root dispatch is reserved for control');
|
|
@@ -275,29 +289,30 @@ export function createSubagentsController(
|
|
|
275
289
|
const body = messages.length || from !== 'user'
|
|
276
290
|
? JSON.stringify({ kind: from === 'user' ? 'user' : 'new-task', from, text, messages: messages.map(({ state: _state, ...message }) => message) })
|
|
277
291
|
: text;
|
|
278
|
-
const
|
|
292
|
+
const delivery = member.deliveries.get(requestId) ?? {
|
|
279
293
|
hash: createHash('sha256').update(body).digest('hex'), messages, status: 'dispatching',
|
|
280
|
-
}
|
|
281
|
-
if (
|
|
294
|
+
};
|
|
295
|
+
if (!member.deliveries.has(requestId)) member.deliveries.set(requestId, delivery);
|
|
282
296
|
let receipt: ConditionalInputReceipt;
|
|
283
297
|
try {
|
|
284
298
|
guard();
|
|
285
299
|
receipt = await runtime.send(member.id!, body, { source: from, wakeIfIdle: true, ...options, requestId });
|
|
286
300
|
} catch (error) {
|
|
287
|
-
|
|
301
|
+
member.deliveries.delete(requestId);
|
|
288
302
|
for (const message of messages) message.state = 'pending';
|
|
289
303
|
releaseWait(member);
|
|
290
304
|
throw error;
|
|
291
305
|
}
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (receipt.status !== 'unknown' &&
|
|
306
|
+
if (member.deliveries.get(requestId) === delivery) {
|
|
307
|
+
delivery.inputId = receipt.inputId;
|
|
308
|
+
delivery.status = receipt.status === 'accepted' ? receipt.disposition : receipt.status;
|
|
309
|
+
if (receipt.status !== 'unknown' && delivery.status !== 'queued') member.deliveries.delete(requestId);
|
|
296
310
|
}
|
|
297
311
|
// A concurrent interrupt or clear already settled this input from the native queue.
|
|
298
|
-
if (member === root && entry.rootEpoch !== rootEpoch) return receipt;
|
|
312
|
+
if (entry.memberEpoch !== member.ownerEpoch || (member === root && entry.rootEpoch !== rootEpoch)) return receipt;
|
|
299
313
|
if (receipt.status === 'accepted') {
|
|
300
314
|
for (const message of messages) removeMemberMessage(member, message);
|
|
315
|
+
member.ownerInterrupted = false;
|
|
301
316
|
if (member === root) rootPaused = false;
|
|
302
317
|
member.wait?.({ reason: 'input' });
|
|
303
318
|
} else if (receipt.status === 'not-accepted') {
|
|
@@ -310,7 +325,7 @@ export function createSubagentsController(
|
|
|
310
325
|
|
|
311
326
|
function waitForMessage(member: Member, duration: number, signal: AbortSignal) {
|
|
312
327
|
if (member.wait) fail('CONFLICT', 'This member is already waiting');
|
|
313
|
-
if (signal.aborted || (member === root && rootPaused)) return Promise.resolve<WaitResult>({ reason: 'cancelled' });
|
|
328
|
+
if (signal.aborted || member.ownerStopped || member.ownerInterrupted || (member === root && rootPaused)) return Promise.resolve<WaitResult>({ reason: 'cancelled' });
|
|
314
329
|
return new Promise<WaitResult>(resolve => {
|
|
315
330
|
const timer = setTimeout(() => finish({ reason: 'timeout' }), duration);
|
|
316
331
|
const cancel = () => finish({ reason: 'cancelled' });
|
|
@@ -328,14 +343,14 @@ export function createSubagentsController(
|
|
|
328
343
|
});
|
|
329
344
|
}
|
|
330
345
|
|
|
331
|
-
function
|
|
346
|
+
function restoreMemberQueue(member: Member, hashes: readonly string[], scope?: QueueScope) {
|
|
332
347
|
const discarded = new Set(hashes);
|
|
333
348
|
const inputs: { requestId: string; inputId?: string }[] = [];
|
|
334
349
|
const inbox: string[] = [];
|
|
335
350
|
const restore = (message: Message) => {
|
|
336
351
|
message.state = 'pending';
|
|
337
|
-
if (!
|
|
338
|
-
try { reserveMessage(
|
|
352
|
+
if (!member.inbox.some(item => item.id === message.id)) {
|
|
353
|
+
try { reserveMessage(member, message); }
|
|
339
354
|
catch {
|
|
340
355
|
deliveryFailures.push({ id: message.id, reason: 'MAILBOX_FULL_AFTER_CONTROL' });
|
|
341
356
|
return;
|
|
@@ -343,18 +358,18 @@ export function createSubagentsController(
|
|
|
343
358
|
}
|
|
344
359
|
inbox.push(message.id);
|
|
345
360
|
};
|
|
346
|
-
for (const [hash, message] of
|
|
361
|
+
for (const [hash, message] of member.submitted) {
|
|
347
362
|
if (scope && !scope.submitted.has(hash)) continue;
|
|
348
363
|
if (discarded.has(hash)) restore(message);
|
|
349
|
-
|
|
364
|
+
member.submitted.delete(hash);
|
|
350
365
|
}
|
|
351
|
-
for (const [hash, offer] of
|
|
366
|
+
for (const [hash, offer] of member.offers) {
|
|
352
367
|
if (discarded.has(hash) && (!scope || scope.submitted.has(hash))) {
|
|
353
368
|
offer.discarded = true;
|
|
354
369
|
restore(offer.message);
|
|
355
370
|
}
|
|
356
371
|
}
|
|
357
|
-
for (const [requestId, delivery] of
|
|
372
|
+
for (const [requestId, delivery] of member.deliveries) {
|
|
358
373
|
if (scope && !scope.deliveries.has(requestId)) continue;
|
|
359
374
|
if (discarded.has(delivery.hash)) {
|
|
360
375
|
inputs.push({ requestId, ...(delivery.inputId ? { inputId: delivery.inputId } : {}) });
|
|
@@ -362,9 +377,9 @@ export function createSubagentsController(
|
|
|
362
377
|
} else if (delivery.status === 'unknown' || delivery.status === 'dispatching') {
|
|
363
378
|
continue;
|
|
364
379
|
} else {
|
|
365
|
-
for (const message of delivery.messages) removeMemberMessage(
|
|
380
|
+
for (const message of delivery.messages) removeMemberMessage(member, message);
|
|
366
381
|
}
|
|
367
|
-
|
|
382
|
+
member.deliveries.delete(requestId);
|
|
368
383
|
}
|
|
369
384
|
return { discardedUserInputs: inputs, restoredInbox: inbox };
|
|
370
385
|
}
|
|
@@ -376,7 +391,7 @@ export function createSubagentsController(
|
|
|
376
391
|
const confirmed = operation === 'interrupt' ? core.status === 'interrupted' : ['completed', 'noop'].includes(core.status);
|
|
377
392
|
const scope = pendingRootControls.get(requestId);
|
|
378
393
|
if (!confirmed || !scope) return { core, harnessEffects: { status: 'unknown', ...paused } };
|
|
379
|
-
const result = { core, harnessEffects: { status: 'complete', ...
|
|
394
|
+
const result = { core, harnessEffects: { status: 'complete', ...restoreMemberQueue(root, core.discardedInputHashes ?? [], scope), ...paused } };
|
|
380
395
|
pendingRootControls.delete(requestId);
|
|
381
396
|
reconciledRootControls.set(requestId, result);
|
|
382
397
|
return result;
|
|
@@ -385,6 +400,7 @@ export function createSubagentsController(
|
|
|
385
400
|
async function rootQueueControl(operation: 'interrupt' | 'clearQueue', requestId: string) {
|
|
386
401
|
open();
|
|
387
402
|
if (!root.id) fail('RUN_NOT_READY', 'Root is not available yet');
|
|
403
|
+
if (root.ownerStopped) fail('SESSION_UNAVAILABLE', 'The owner stopped Root');
|
|
388
404
|
if (rootControl) fail('OPERATION_BUSY', 'Root already has a reserved control');
|
|
389
405
|
rootControl = operation;
|
|
390
406
|
rootEpoch++;
|
|
@@ -408,6 +424,7 @@ export function createSubagentsController(
|
|
|
408
424
|
open();
|
|
409
425
|
signal.throwIfAborted();
|
|
410
426
|
if (!root.id) fail('RUN_NOT_READY', 'Root is not available yet');
|
|
427
|
+
if (root.ownerStopped) fail('SESSION_UNAVAILABLE', 'The owner stopped Root');
|
|
411
428
|
if (epoch !== rootEpoch) fail('RUN_INPUT_CANCELLED', 'The Root input predates its control barrier');
|
|
412
429
|
if (rootControl) fail('OPERATION_BUSY', 'Root dispatch is reserved for control');
|
|
413
430
|
const receipt = await runtime.send(root.id, input, options);
|
|
@@ -426,12 +443,72 @@ export function createSubagentsController(
|
|
|
426
443
|
async function compactRoot(options: Parameters<Runtime['session']['compact']>[1]) {
|
|
427
444
|
open();
|
|
428
445
|
if (!root.id) fail('RUN_NOT_READY', 'Root is not available yet');
|
|
446
|
+
if (root.ownerStopped) fail('SESSION_UNAVAILABLE', 'The owner stopped Root');
|
|
429
447
|
if (rootControl || root.pendingDispatches) fail('OPERATION_BUSY', 'Root dispatch is in progress');
|
|
430
448
|
rootControl = 'compact';
|
|
431
449
|
try { return await runtime.session.compact(root.id, options); }
|
|
432
450
|
finally { rootControl = undefined; }
|
|
433
451
|
}
|
|
434
452
|
|
|
453
|
+
const ownerControls = new Map<string, { operation: string; agentId: string; reason?: string; result: Promise<unknown>; reconciling?: Promise<unknown> }>();
|
|
454
|
+
const ownerControlScopes = new Map<string, QueueScope>();
|
|
455
|
+
|
|
456
|
+
function ownerMember(agentId: string) {
|
|
457
|
+
const member = byId.get(agentId);
|
|
458
|
+
if (!member) fail('NOT_FOUND', 'The member does not belong to this team');
|
|
459
|
+
return member;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function reportIntervention(member: Member, operation: 'steer' | 'interrupt' | 'stop', requestId: string) {
|
|
463
|
+
if (!member.parent || !accepting) return;
|
|
464
|
+
const recipient = member.parent;
|
|
465
|
+
const message: Message = { id: 'owner:' + requestId, kind: operation === 'steer' ? 'message' : 'result', from: member.path,
|
|
466
|
+
text: ownerInterventionText(operation),
|
|
467
|
+
...(operation === 'steer' ? {} : { outcome: 'failed' as const }), eventSeq: ++eventSequence, state: 'pending' };
|
|
468
|
+
void track(serial(recipient, async () => { reserveMessage(recipient, message); await offer(recipient, message); }))
|
|
469
|
+
.catch(error => { if (deliveryFailures.length < mailboxLimit) deliveryFailures.push({ id: message.id, reason: error.code ?? 'SERVICE_UNAVAILABLE' }); });
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function settleOwnerControl(member: Member, operation: 'interrupt' | 'stop', requestId: string, core: any) {
|
|
473
|
+
const confirmed = operation === 'interrupt' ? core.status === 'interrupted' : core.execution === 'stopped';
|
|
474
|
+
if (!confirmed) return { core, harnessEffects: { status: 'unknown', target: member.path } };
|
|
475
|
+
if (operation === 'interrupt') {
|
|
476
|
+
member.lastOutcome = 'interrupted';
|
|
477
|
+
restoreMemberQueue(member, core.discardedInputHashes ?? [], ownerControlScopes.get(requestId));
|
|
478
|
+
}
|
|
479
|
+
ownerControlScopes.delete(requestId);
|
|
480
|
+
member.wait?.({ reason: 'cancelled' });
|
|
481
|
+
reportIntervention(member, operation, requestId);
|
|
482
|
+
onChange?.();
|
|
483
|
+
return { core, harnessEffects: { status: 'complete', target: member.path, ownerInterrupted: !!member.ownerInterrupted,
|
|
484
|
+
ownerStopped: !!member.ownerStopped } };
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function ownerControl(operation: 'interrupt' | 'stop', agentId: string, requestId: string, reason?: string) {
|
|
488
|
+
const existing = ownerControls.get(requestId);
|
|
489
|
+
if (existing) {
|
|
490
|
+
if (existing.operation !== operation || existing.agentId !== agentId || existing.reason !== reason) fail('CONFLICT', 'The owner request changed');
|
|
491
|
+
return existing.result;
|
|
492
|
+
}
|
|
493
|
+
open();
|
|
494
|
+
if (ownerControls.size >= operationLimit) fail('NOT_ALLOWED', 'The owner control limit has been reached');
|
|
495
|
+
const member = ownerMember(agentId);
|
|
496
|
+
if (member.ownerStopped) fail('SESSION_UNAVAILABLE', 'The owner stopped this member');
|
|
497
|
+
ownerControlScopes.set(requestId, { deliveries: new Set(member.deliveries.keys()),
|
|
498
|
+
submitted: new Set([...member.submitted.keys(), ...member.offers.keys()]) });
|
|
499
|
+
member.ownerEpoch++;
|
|
500
|
+
member.ownerInterrupted = true;
|
|
501
|
+
if (operation === 'stop') member.ownerStopped = true;
|
|
502
|
+
member.wait?.({ reason: 'cancelled' });
|
|
503
|
+
if (member === root) { rootEpoch++; rootPaused = true; }
|
|
504
|
+
const result = Promise.resolve().then(async () => {
|
|
505
|
+
const core = operation === 'interrupt' ? await runtime.interrupt(agentId, { requestId }) : await runtime.stop(agentId);
|
|
506
|
+
return settleOwnerControl(member, operation, requestId, core);
|
|
507
|
+
});
|
|
508
|
+
ownerControls.set(requestId, { operation, agentId, reason, result });
|
|
509
|
+
return track(result);
|
|
510
|
+
}
|
|
511
|
+
|
|
435
512
|
function attachRoot(id: string) {
|
|
436
513
|
root.id = id;
|
|
437
514
|
byId.set(id, root);
|
|
@@ -439,6 +516,58 @@ export function createSubagentsController(
|
|
|
439
516
|
|
|
440
517
|
return {
|
|
441
518
|
attachRoot,
|
|
519
|
+
ownerControl,
|
|
520
|
+
sendMember(agentId: string, input: string, requestId: string, options: Omit<SendOptions, 'requestId'>, signal: AbortSignal) {
|
|
521
|
+
const member = ownerMember(agentId);
|
|
522
|
+
if (member === root) return this.submitUser(input, { operationId: requestId }, options, signal);
|
|
523
|
+
inputText(input);
|
|
524
|
+
return operate(requestId, { agentId, input, options }, async entry => {
|
|
525
|
+
const receipt = await submit(member, entry, input, 'user', requestId, undefined, options, signal);
|
|
526
|
+
if (receipt.status === 'accepted' && !entry.ownerNotified) {
|
|
527
|
+
entry.ownerNotified = true;
|
|
528
|
+
reportIntervention(member, 'steer', requestId);
|
|
529
|
+
}
|
|
530
|
+
return receipt;
|
|
531
|
+
});
|
|
532
|
+
},
|
|
533
|
+
async reconcileMemberInput(agentId: string, requestId: string, query: () => Promise<any>) {
|
|
534
|
+
const member = ownerMember(agentId);
|
|
535
|
+
const entry = operations.get(requestId);
|
|
536
|
+
if (!entry?.inputDispatched) return { status: 'unknown' };
|
|
537
|
+
const receipt = await query();
|
|
538
|
+
if (receipt.status === 'unknown') return receipt;
|
|
539
|
+
entry.result = Promise.resolve(receipt);
|
|
540
|
+
if (entry.memberEpoch === member.ownerEpoch) {
|
|
541
|
+
for (const message of entry.batch ?? []) {
|
|
542
|
+
if (receipt.status === 'accepted') removeMemberMessage(member, message);
|
|
543
|
+
else message.state = 'pending';
|
|
544
|
+
}
|
|
545
|
+
if (receipt.status === 'accepted') {
|
|
546
|
+
member.ownerInterrupted = false;
|
|
547
|
+
member.wait?.({ reason: 'input' });
|
|
548
|
+
if (!entry.ownerNotified) { entry.ownerNotified = true; reportIntervention(member, 'steer', requestId); }
|
|
549
|
+
} else releaseWait(member);
|
|
550
|
+
}
|
|
551
|
+
onChange?.();
|
|
552
|
+
return receipt;
|
|
553
|
+
},
|
|
554
|
+
async reconcileOwnerControl(operation: 'interrupt' | 'stop', agentId: string, requestId: string, query: () => Promise<any>) {
|
|
555
|
+
const previous = ownerControls.get(requestId);
|
|
556
|
+
if (!previous || previous.operation !== operation || previous.agentId !== agentId) return { status: 'unknown' };
|
|
557
|
+
const original: any = await previous.result;
|
|
558
|
+
if (original.harnessEffects?.status === 'complete') return original;
|
|
559
|
+
if (previous.reconciling) return previous.reconciling;
|
|
560
|
+
const result = (operation === 'stop' ? runtime.stop(agentId) : query())
|
|
561
|
+
.then(core => settleOwnerControl(ownerMember(agentId), operation, requestId, core));
|
|
562
|
+
previous.result = result;
|
|
563
|
+
previous.reconciling = result.finally(() => { previous.reconciling = undefined; });
|
|
564
|
+
return previous.reconciling;
|
|
565
|
+
},
|
|
566
|
+
readLiveState() {
|
|
567
|
+
return { memberCount: byPath.size, operationCount: operations.size,
|
|
568
|
+
members: [...byPath.values()].slice(0, 100).map(member => ({ path: member.path, agentId: member.id ?? null,
|
|
569
|
+
parent: member.parent?.path ?? null, lastOutcome: member.lastOutcome ?? null, waiting: !!member.wait })) };
|
|
570
|
+
},
|
|
442
571
|
rootId: () => root.id,
|
|
443
572
|
rootEpoch: () => rootEpoch,
|
|
444
573
|
rootBusy: () => !!rootControl || root.pendingDispatches > 0,
|
|
@@ -500,6 +629,7 @@ export function createSubagentsController(
|
|
|
500
629
|
const caller = request.caller.runtimeId === runtime.id && byId.get(request.caller.agentId);
|
|
501
630
|
if (!caller) fail('NOT_ALLOWED', 'Caller does not belong to this team');
|
|
502
631
|
request.assertAuthorized();
|
|
632
|
+
if (caller.ownerStopped) fail('SESSION_UNAVAILABLE', 'The owner stopped this member');
|
|
503
633
|
const call = request.input as Record<string, JsonValue>;
|
|
504
634
|
const operation = request.capability.operation;
|
|
505
635
|
if (operation === 'list_agents') {
|
|
@@ -550,6 +680,7 @@ export function createSubagentsController(
|
|
|
550
680
|
return { task_name: child.path, agentId: child.id, ...receipt };
|
|
551
681
|
}
|
|
552
682
|
const recipient = target(caller, call.target);
|
|
683
|
+
if (recipient.ownerStopped) fail('SESSION_UNAVAILABLE', 'The owner stopped this member');
|
|
553
684
|
if (operation === 'followup_task') {
|
|
554
685
|
if (recipient === root) fail('NOT_ALLOWED', 'The Root only receives follow-up tasks from the host');
|
|
555
686
|
const receipt = await submit(recipient, entry, inputText(call.message), caller.path, entry.id, request.assertAuthorized);
|
|
@@ -615,6 +746,7 @@ export function createSubagentsController(
|
|
|
615
746
|
members: [...byPath.values()].map(member => ({
|
|
616
747
|
path: member.path, agentId: member.id ?? null, parent: member.parent?.path ?? null,
|
|
617
748
|
lastOutcome: member.lastOutcome ?? null, waiting: Boolean(member.wait),
|
|
749
|
+
ownerInterrupted: !!member.ownerInterrupted, ownerStopped: !!member.ownerStopped,
|
|
618
750
|
nativeQueuedAdmissions: member.submitted.size,
|
|
619
751
|
pending: member.inbox.map(({ id, state }) => ({ id, state })),
|
|
620
752
|
})),
|
|
@@ -4,7 +4,7 @@ import { createUserQuestionsService } from './services/collaboration-service.js'
|
|
|
4
4
|
import {
|
|
5
5
|
getExecutorCapabilities, type ContextInput, type ContextSendOptions,
|
|
6
6
|
type HarnessJson, type Harness, type SendOptions,
|
|
7
|
-
ProjectPreflightError, observeProjectRuntime, projectConfiguration,
|
|
7
|
+
ProjectPreflightError, observeProjectRuntime, projectConfiguration, type HarnessAgentRegistration, type ExecutorCapabilities,
|
|
8
8
|
} from '@anyswarm/core';
|
|
9
9
|
|
|
10
10
|
const rootInput = {
|
|
@@ -27,6 +27,49 @@ function parseInput(payload: HarnessJson) {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
|
|
30
|
+
export function subagentsAgentControls(team: ReturnType<typeof import('./harness/controller.js').createSubagentsController>,
|
|
31
|
+
native: ExecutorCapabilities, reconcile: (agentId: string, operation: string, requestId: string) => Promise<unknown> = async () => ({ status: 'unknown' })):
|
|
32
|
+
Omit<HarnessAgentRegistration, 'runtime'> {
|
|
33
|
+
return {
|
|
34
|
+
fence: team.beginClose,
|
|
35
|
+
reconcile: (operation, agentId, { operationId }, payload) => {
|
|
36
|
+
const text = operation === 'send' && typeof (payload as { input: unknown }).input === 'string';
|
|
37
|
+
const nativeOperation = operation === 'send' && !text ? 'context' : operation;
|
|
38
|
+
const lookup = () => reconcile(agentId, nativeOperation, operationId);
|
|
39
|
+
if (operation === 'stop' || (operation === 'interrupt' && agentId !== team.rootId())) {
|
|
40
|
+
return team.reconcileOwnerControl(operation, agentId, operationId, lookup);
|
|
41
|
+
}
|
|
42
|
+
if (operation === 'interrupt' || operation === 'clearQueue') return team.reconcileRootControl(operation, operationId, lookup);
|
|
43
|
+
if (text) return agentId === team.rootId() ? team.reconcileRootInput(operationId, lookup)
|
|
44
|
+
: team.reconcileMemberInput(agentId, operationId, lookup);
|
|
45
|
+
return lookup();
|
|
46
|
+
},
|
|
47
|
+
capabilities: agentId => ({
|
|
48
|
+
...(agentId === team.rootId() ? {
|
|
49
|
+
configure: { supported: true, fields: configureFields },
|
|
50
|
+
compact: { supported: true, ...(team.rootBusy() ? { available: false, reason: 'OPERATION_BUSY' } : {}) },
|
|
51
|
+
abortRetry: { supported: true }, clearQueue: { supported: true },
|
|
52
|
+
} : {}),
|
|
53
|
+
send: { supported: native.activeSteer || native.followUp, text: true, context: agentId === team.rootId(),
|
|
54
|
+
modes: modes.filter(mode => mode === 'steer' ? native.activeSteer : native.followUp), deliveries },
|
|
55
|
+
interrupt: { supported: native.queuedInputCancellation },
|
|
56
|
+
stop: { supported: true },
|
|
57
|
+
}),
|
|
58
|
+
handlers: {
|
|
59
|
+
compact: (_agentId, payload, request) => team.compactRoot({ ...(payload as { customInstructions?: string }), requestId: request.operationId }),
|
|
60
|
+
clearQueue: (_agentId, _payload, request) => team.rootQueueControl('clearQueue', request.operationId),
|
|
61
|
+
interrupt: (agentId, _payload, request) => agentId === team.rootId()
|
|
62
|
+
? team.rootQueueControl('interrupt', request.operationId) : team.ownerControl('interrupt', agentId, request.operationId),
|
|
63
|
+
stop: (agentId, payload, request) => team.ownerControl('stop', agentId, request.operationId, (payload as { reason?: string }).reason),
|
|
64
|
+
send(agentId, payload, request) {
|
|
65
|
+
const { input, options } = payload as { input: string | ContextInput; options: Omit<SendOptions, 'requestId'> | ContextSendOptions };
|
|
66
|
+
return typeof input === 'string' ? team.sendMember(agentId, input, request.operationId, options as SendOptions, request.signal)
|
|
67
|
+
: team.sendRootContext(input, { ...options, requestId: request.operationId } as ContextSendOptions, request.signal);
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
30
73
|
const subagents = {
|
|
31
74
|
id: 'subagents',
|
|
32
75
|
apiVersion: 1,
|
|
@@ -67,38 +110,9 @@ const subagents = {
|
|
|
67
110
|
onChange: () => { void observation?.refresh(); },
|
|
68
111
|
userQuestions: context.clientCapabilities.questions ? createUserQuestionsService(context) : undefined,
|
|
69
112
|
onRuntime: (runtime, team) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
reconcile: (operation, agentId, { operationId }, payload) => {
|
|
74
|
-
const text = operation === 'send' && typeof (payload as { input: unknown }).input === 'string';
|
|
75
|
-
const nativeOperation = operation === 'send' && !text ? 'context' : operation;
|
|
76
|
-
const lookup = () => observation!.reconcile(agentId, nativeOperation, operationId);
|
|
77
|
-
if (operation === 'interrupt' || operation === 'clearQueue') return team.reconcileRootControl(operation, operationId, lookup);
|
|
78
|
-
return text ? team.reconcileRootInput(operationId, lookup) : lookup();
|
|
79
|
-
},
|
|
80
|
-
capabilities: agentId => {
|
|
81
|
-
if (agentId !== team.rootId()) return {};
|
|
82
|
-
return {
|
|
83
|
-
configure: { supported: true, fields: configureFields },
|
|
84
|
-
compact: { supported: true, ...(team.rootBusy() ? { available: false, reason: 'OPERATION_BUSY' } : {}) },
|
|
85
|
-
abortRetry: { supported: true },
|
|
86
|
-
clearQueue: { supported: true },
|
|
87
|
-
send: { supported: true, text: true, context: true, modes, deliveries },
|
|
88
|
-
interrupt: { supported: native.queuedInputCancellation },
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
handlers: {
|
|
92
|
-
compact: (_agentId, payload, request) => team.compactRoot({ ...(payload as { customInstructions?: string }), requestId: request.operationId }),
|
|
93
|
-
clearQueue: (_agentId, _payload, request) => team.rootQueueControl('clearQueue', request.operationId),
|
|
94
|
-
interrupt: (_agentId, _payload, request) => team.rootQueueControl('interrupt', request.operationId),
|
|
95
|
-
send(_agentId, payload, request) {
|
|
96
|
-
const { input, options } = payload as { input: string | ContextInput; options: Omit<SendOptions, 'requestId'> | ContextSendOptions };
|
|
97
|
-
return typeof input === 'string' ? team.submitUser(input, request, options as SendOptions, request.signal)
|
|
98
|
-
: team.sendRootContext(input, { ...options, requestId: request.operationId } as ContextSendOptions, request.signal);
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
});
|
|
113
|
+
observation = observeProjectRuntime(runtime, context, team.exportState,
|
|
114
|
+
subagentsAgentControls(team, getExecutorCapabilities(config.executor ?? 'pi'),
|
|
115
|
+
(agentId, operation, requestId) => observation!.reconcile(agentId, operation, requestId)));
|
|
102
116
|
},
|
|
103
117
|
onReady: harness => {
|
|
104
118
|
context.registerInput((input, { operationId, signal, binding }) => {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
const collaboration = `Address a member by absolute path or a child by name. Reuse the original request ID to reconcile an unknown write. Child outcomes go to their direct parent. Share small patches or findings through messages, or use a configured shared workspace for files.`;
|
|
2
2
|
|
|
3
|
+
export function ownerInterventionText(operation: 'steer' | 'interrupt' | 'stop'): string {
|
|
4
|
+
return `user-${operation}: the Run owner ${operation === 'stop' ? 'stopped' : operation === 'steer' ? 'steered' : 'interrupted'} this member`;
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
export const rootPrompt = `You are Root. Delegate independent work early with distinct deliverables and keep complementary work for yourself. Ask for early usable results, integrate and verify contributions, and relay new requirements to affected children. Deliver the requested files and report what you verified.\n\n${collaboration}`;
|
|
4
8
|
|
|
5
9
|
export const childPrompt = `Complete your assignment and send the first usable finding, test or patch to your parent promptly. Verify the result, identify unfinished checks, and incorporate later corrections. Delegate only useful independent work.\n\n${collaboration}`;
|
|
@@ -50,9 +50,21 @@ export const collaborationOperations = capabilities.map(([operation]) => operati
|
|
|
50
50
|
export function createCollaborationService(
|
|
51
51
|
invoke: (request: ServiceRequest) => Promise<JsonValue>,
|
|
52
52
|
exportState: () => JsonValue,
|
|
53
|
-
{ allowContextFork = true } = {},
|
|
53
|
+
{ allowContextFork = true, readState }: { allowContextFork?: boolean; readState?: () => JsonValue } = {},
|
|
54
54
|
) {
|
|
55
|
-
return serviceFromManifest({ manifest: allowContextFork ? manifest : freshChildManifest, adapter: createInProcessAdapter({
|
|
55
|
+
return serviceFromManifest({ manifest: allowContextFork ? manifest : freshChildManifest, adapter: createInProcessAdapter({
|
|
56
|
+
invoke, exportState,
|
|
57
|
+
...(readState ? { readState: () => ({
|
|
58
|
+
state: readState(), capturedAt: new Date().toISOString(),
|
|
59
|
+
presentation: {
|
|
60
|
+
summary: [{ label: 'Members', path: '/memberCount' }, { label: 'Operations', path: '/operationCount' }],
|
|
61
|
+
tables: [{ title: 'Team members', path: '/members', columns: [
|
|
62
|
+
{ label: 'Member', path: '/path' }, { label: 'Parent', path: '/parent' },
|
|
63
|
+
{ label: 'Last outcome', path: '/lastOutcome' }, { label: 'Waiting', path: '/waiting' },
|
|
64
|
+
] }],
|
|
65
|
+
},
|
|
66
|
+
}) } : {}),
|
|
67
|
+
}) })[1];
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
const questionManifest: ServiceManifest = {
|
|
@@ -65,8 +65,8 @@ requires `ANYSWARM_SUBSTRATE_RUN`; it is not the input to the normal project com
|
|
|
65
65
|
From this directory after building:
|
|
66
66
|
|
|
67
67
|
```sh
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
../../node_modules/.bin/anys run ./main.ts --help
|
|
69
|
+
../../node_modules/.bin/anys run ./main.ts ./config.ts
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
For an installed package, replace `../../dist/examples/substrate` with
|