@anyswarm/core 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/deploy/worker/Dockerfile +12 -4
- package/dist/deploy/worker/Dockerfile +12 -4
- package/dist/examples/README.md +24 -12
- package/dist/examples/authoring/README.md +24 -0
- package/dist/examples/authoring/business.d.ts +2 -0
- package/dist/examples/authoring/business.js +4 -0
- package/dist/examples/authoring/config.d.ts +5 -0
- package/dist/examples/authoring/config.js +2 -0
- package/dist/examples/authoring/eject.json +5 -0
- package/dist/examples/authoring/harness.d.ts +4 -0
- package/dist/examples/authoring/harness.js +19 -0
- package/dist/examples/autoresearch/README.md +33 -0
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +18 -0
- package/dist/examples/autoresearch/config.d.ts +51 -0
- package/dist/examples/autoresearch/config.js +57 -0
- package/dist/examples/autoresearch/demo.d.ts +11 -0
- package/dist/examples/autoresearch/demo.js +52 -0
- package/dist/examples/autoresearch/eject.json +15 -0
- package/dist/examples/autoresearch/frontiercs2.d.ts +87 -0
- package/dist/examples/autoresearch/frontiercs2.js +211 -0
- package/dist/examples/autoresearch/prepare.d.ts +95 -0
- package/dist/examples/autoresearch/prepare.js +257 -0
- package/dist/examples/autoresearch/process.d.ts +13 -0
- package/dist/examples/autoresearch/process.js +48 -0
- package/dist/examples/autoresearch/project.d.ts +115 -0
- package/dist/examples/autoresearch/project.js +410 -0
- package/dist/examples/autoresearch/research-service.d.ts +106 -0
- package/dist/examples/autoresearch/research-service.js +255 -0
- package/dist/examples/code/README.md +25 -0
- package/dist/examples/code/REQUIREMENTS.zh.md +11 -0
- package/dist/examples/code/candidate.d.ts +19 -0
- package/dist/examples/code/candidate.js +80 -0
- package/dist/examples/code/config.d.ts +32 -0
- package/dist/examples/code/config.js +18 -0
- package/dist/examples/code/eject.json +5 -0
- package/dist/examples/code/project.d.ts +3 -0
- package/dist/examples/code/project.js +605 -0
- package/dist/examples/code/prompts.d.ts +5 -0
- package/dist/examples/code/prompts.js +12 -0
- package/dist/examples/code/verification.d.ts +19 -0
- package/dist/examples/code/verification.js +268 -0
- package/dist/examples/code/worktree.d.ts +17 -0
- package/dist/examples/code/worktree.js +233 -0
- package/dist/examples/harness-session/README.md +3 -6
- package/dist/examples/lead-worker/harness/dynamic-scheduler.d.ts +2 -1
- package/dist/examples/lead-worker/harness/dynamic-scheduler.js +5 -2
- package/dist/examples/lead-worker/harness/index.d.ts +60 -0
- package/dist/examples/lead-worker/harness/index.js +77 -6
- package/dist/examples/lead-worker/project.js +2 -2
- package/dist/examples/lead-worker/services/board.d.ts +5 -0
- package/dist/examples/lead-worker/services/board.js +19 -1
- package/dist/examples/messages/README.md +5 -5
- package/dist/examples/messages/handoff.d.ts +2 -0
- package/dist/examples/messages/handoff.js +5 -1
- package/dist/examples/messages/project.js +52 -2
- package/dist/examples/notes/README.md +13 -18
- package/dist/examples/notes/project.js +67 -6
- package/dist/examples/peermesh/harness/router.js +3 -1
- package/dist/examples/peermesh/harness/team.d.ts +8 -0
- package/dist/examples/peermesh/harness/team.js +13 -0
- package/dist/examples/peermesh/project.js +22 -4
- package/dist/examples/services/agent-control/README.md +3 -3
- package/dist/examples/services/mathlib-search/Dockerfile +4 -2
- package/dist/examples/services/mathlib-search/README.md +1 -1
- package/dist/examples/services/mcp-managed/README.md +2 -2
- package/dist/examples/services/persistent-board/README.md +13 -3
- package/dist/examples/services/persistent-board/business.d.ts +7 -0
- package/dist/examples/services/persistent-board/business.js +7 -0
- package/dist/examples/services/persistent-board/index.js +10 -0
- package/dist/examples/services/persistent-board/live.d.ts +3 -0
- package/dist/examples/services/persistent-board/live.js +58 -0
- package/dist/examples/subagents/README.md +5 -5
- package/dist/examples/subagents/business.js +3 -1
- package/dist/examples/subagents/harness/controller.d.ts +15 -0
- package/dist/examples/subagents/harness/controller.js +181 -32
- package/dist/examples/subagents/project.d.ts +2 -0
- package/dist/examples/subagents/project.js +43 -34
- package/dist/examples/subagents/prompts/prompts.d.ts +1 -0
- package/dist/examples/subagents/prompts/prompts.js +3 -0
- package/dist/examples/subagents/services/collaboration-service.d.ts +3 -2
- package/dist/examples/subagents/services/collaboration-service.js +14 -2
- package/dist/examples/substrate/README.md +2 -2
- package/dist/examples/substrate/harness/index.d.ts +1 -1
- package/dist/examples/substrate/harness/index.js +77 -12
- package/dist/examples/substrate/project.js +4 -1
- package/dist/examples/super/README.md +40 -0
- package/dist/examples/super/actions.d.ts +95 -0
- package/dist/examples/super/actions.js +230 -0
- package/dist/examples/super/artifact.d.ts +4 -0
- package/dist/examples/super/artifact.js +51 -0
- package/dist/examples/super/config.d.ts +80 -0
- package/dist/examples/super/config.js +83 -0
- package/dist/examples/super/coordinator.d.ts +33 -0
- package/dist/examples/super/coordinator.js +151 -0
- package/dist/examples/super/daemon.d.ts +11 -0
- package/dist/examples/super/daemon.js +109 -0
- package/dist/examples/super/decisions.d.ts +8 -0
- package/dist/examples/super/decisions.js +52 -0
- package/dist/examples/super/eject.json +5 -0
- package/dist/examples/super/execution.d.ts +11 -0
- package/dist/examples/super/execution.js +136 -0
- package/dist/examples/super/github.d.ts +62 -0
- package/dist/examples/super/github.js +269 -0
- package/dist/examples/super/inbox.d.ts +162 -0
- package/dist/examples/super/inbox.js +284 -0
- package/dist/examples/super/location.d.ts +5 -0
- package/dist/examples/super/location.js +64 -0
- package/dist/examples/super/outbox.d.ts +5 -0
- package/dist/examples/super/outbox.js +103 -0
- package/dist/examples/super/project.d.ts +111 -0
- package/dist/examples/super/project.js +253 -0
- package/dist/examples/super/prompts.d.ts +3 -0
- package/dist/examples/super/prompts.js +25 -0
- package/dist/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
- package/dist/examples/taskpool/harness/controller.d.ts +35 -6
- package/dist/examples/taskpool/harness/controller.js +73 -7
- package/dist/examples/taskpool/project.js +18 -2
- package/dist/scripts/anyswarm-applications.d.ts +19 -0
- package/dist/scripts/anyswarm-applications.js +19 -0
- package/dist/scripts/anyswarm-arguments.d.ts +35 -5
- package/dist/scripts/anyswarm-arguments.js +87 -23
- package/dist/scripts/anyswarm-author.d.ts +5 -0
- package/dist/scripts/anyswarm-author.js +24 -0
- package/dist/scripts/anyswarm-eject.d.ts +11 -0
- package/dist/scripts/anyswarm-eject.js +164 -0
- package/dist/scripts/anyswarm-harnesses.d.ts +2 -0
- package/dist/scripts/anyswarm-harnesses.js +31 -0
- package/dist/scripts/anyswarm-installation.js +19 -13
- package/dist/scripts/anyswarm-launch.d.ts +37 -0
- package/dist/scripts/anyswarm-launch.js +86 -0
- package/dist/scripts/anyswarm-project.d.ts +12 -2
- package/dist/scripts/anyswarm-project.js +121 -20
- package/dist/scripts/anyswarm-source-runner.d.ts +1 -0
- package/dist/scripts/anyswarm-source-runner.js +232 -0
- package/dist/scripts/anyswarm-tui-config.d.ts +36 -0
- package/dist/scripts/anyswarm-tui-config.js +189 -0
- package/dist/scripts/anyswarm-tui-session.d.ts +66 -0
- package/dist/scripts/anyswarm-tui-session.js +304 -0
- package/dist/scripts/anyswarm-tui-terminal.d.ts +41 -0
- package/dist/scripts/anyswarm-tui-terminal.js +154 -0
- package/dist/scripts/anyswarm-tui.d.ts +2 -0
- package/dist/scripts/anyswarm-tui.js +1012 -0
- package/dist/scripts/anyswarm.js +47 -2
- package/dist/scripts/build-provenance.json +1 -0
- package/dist/scripts/build.js +7 -1
- package/dist/scripts/generate-architecture-api.js +2 -0
- package/dist/scripts/generate-architecture-prompts.js +24 -2
- package/dist/scripts/local-environment.d.ts +6 -1
- package/dist/scripts/local-environment.js +52 -16
- package/dist/scripts/local-setup-smoke.js +3 -2
- package/dist/scripts/local-setup-worker.d.ts +1 -1
- package/dist/scripts/local-setup-worker.js +15 -6
- package/dist/scripts/local-setup.d.ts +2 -2
- package/dist/scripts/local-setup.js +72 -12
- package/dist/scripts/opensandbox-agent-worker.js +2 -2
- package/dist/scripts/pack-release.d.ts +1 -0
- package/dist/scripts/pack-release.js +63 -0
- package/dist/scripts/pi-session-bridge.js +11 -3
- package/dist/scripts/run-harness.js +3 -1
- package/dist/scripts/setup-bootstrap.js +43 -6
- package/dist/src/core/allocation-ledger.js +4 -3
- package/dist/src/core/host-identity.d.ts +2 -0
- package/dist/src/core/host-identity.js +11 -0
- package/dist/src/core/index.d.ts +4 -2
- package/dist/src/core/index.js +12 -4
- package/dist/src/core/mcp-service.js +2 -2
- package/dist/src/core/runtime-management.d.ts +6 -0
- package/dist/src/core/runtime-management.js +24 -0
- package/dist/src/core/sandbox/executor-driver.d.ts +4 -2
- package/dist/src/core/sandbox/executor-driver.js +12 -14
- package/dist/src/core/sandbox/local-executor.d.ts +13 -1
- package/dist/src/core/sandbox/local-executor.js +69 -19
- package/dist/src/core/sandbox/local-worker.js +32 -21
- package/dist/src/core/sandbox/opensandbox-backend.d.ts +2 -0
- package/dist/src/core/sandbox/opensandbox-backend.js +36 -11
- package/dist/src/core/sandbox/sandbox-connection.d.ts +2 -0
- package/dist/src/core/sandbox/sandbox-connection.js +14 -6
- package/dist/src/core/service-live-state.d.ts +14 -0
- package/dist/src/core/service-live-state.js +161 -0
- package/dist/src/core/service-observation-types.d.ts +21 -1
- package/dist/src/core/service-process.d.ts +1 -1
- package/dist/src/core/service-process.js +45 -4
- package/dist/src/core/service-types.d.ts +5 -1
- package/dist/src/core/services.d.ts +1 -1
- package/dist/src/core/services.js +8 -3
- package/dist/src/core/types.d.ts +3 -0
- package/dist/src/core/worker-image.js +3 -3
- package/dist/src/harness/harness-session-types.d.ts +10 -0
- package/dist/src/harness/harness-session.js +42 -5
- package/dist/src/harness/project-harness.d.ts +13 -1
- package/dist/src/harness/project-harness.js +36 -10
- package/dist/src/harness/project-input.js +81 -15
- package/dist/src/harness/project-rpc-client.d.ts +1 -0
- package/dist/src/harness/project-rpc-client.js +5 -0
- package/dist/src/harness/project-rpc.d.ts +8 -2
- package/dist/src/harness/project-rpc.js +31 -7
- package/dist/src/harness/project-runtime.js +3 -1
- package/dist/src/harness/typescript-loader.d.ts +2 -0
- package/dist/src/harness/typescript-loader.js +41 -0
- package/dist/src/trace-viewer/public/app.js +6 -5
- package/dist/src/trace-viewer/reader.mjs +42 -2
- package/docs/INDEX.md +3 -1
- package/docs/architecture/00-overview.md +1 -1
- package/docs/architecture/01-agent-core.md +1 -1
- package/docs/architecture/06-observability-experiments.md +1 -1
- package/docs/architecture/07-run-configuration.md +18 -12
- package/docs/architecture/08-prompts.md +22 -0
- package/docs/architecture/10-service-api-reference.md +53 -18
- package/docs/architecture/11-storage-reference.md +18 -1
- package/docs/architecture/12-code-coverage.md +148 -84
- package/docs/architecture/15-core-runtime.md +8 -0
- package/docs/architecture/16-pi-opensandbox-backend.md +5 -5
- package/docs/architecture/17-harness-reporting.md +1 -1
- package/docs/architecture/19-substrate-harness.md +28 -1
- package/docs/architecture/20-lead-worker-harness.md +34 -1
- package/docs/architecture/22-website.md +5 -3
- package/docs/architecture/23-project-harness.md +124 -5
- package/docs/architecture/24-runtime-recovery.md +10 -3
- package/docs/architecture/25-foreground-tui.md +51 -0
- package/docs/architecture/26-code.md +39 -0
- package/docs/architecture/27-personal.md +43 -0
- package/docs/architecture/28-autoresearch.md +31 -0
- package/docs/architecture/INDEX.md +4 -0
- package/docs/architecture/prompts/08-lead-worker-harness.md +4 -2
- package/docs/architecture/prompts/08-subagents-harness.md +21 -0
- package/docs/architecture/prompts/21-personal.md +44 -0
- package/docs/architecture/prompts/22-autoresearch.md +63 -0
- package/docs/architecture/prompts/26-code.md +55 -0
- package/docs/architecture/prompts/source-manifest.json +152 -33
- package/docs/architecture/source-map.json +489 -21
- package/docs/designs/core-harness/06-project-harness.md +13 -2
- package/docs/designs/core-harness/README.md +5 -0
- package/docs/en/agents.md +1 -1
- package/docs/en/build-your-harness.md +3 -5
- package/docs/en/changelog.md +13 -4
- package/docs/en/first-harness.md +8 -11
- package/docs/en/harnesses/lead-worker.md +1 -1
- package/docs/en/harnesses/peermesh.md +2 -2
- package/docs/en/harnesses/subagents.md +2 -2
- package/docs/en/harnesses/substrate.md +4 -4
- package/docs/en/harnesses/taskpool.md +2 -2
- package/docs/en/latest.md +12 -123
- package/docs/en/overview.md +1 -1
- package/docs/en/quickstart.md +40 -16
- package/docs/en/reference/api.md +14 -4
- package/docs/en/reference/cli.md +58 -14
- package/docs/en/runtime.md +2 -2
- package/docs/en/services.md +4 -0
- package/docs/third-party-notices.md +1 -0
- package/docs/workflows/development.md +17 -12
- package/docs/workflows/release-and-docs-versioning.md +76 -0
- package/docs/zh/agents.md +1 -1
- package/docs/zh/build-your-harness.md +3 -5
- package/docs/zh/changelog.md +13 -4
- package/docs/zh/first-harness.md +8 -11
- package/docs/zh/harnesses/lead-worker.md +1 -1
- package/docs/zh/harnesses/peermesh.md +2 -2
- package/docs/zh/harnesses/subagents.md +2 -2
- package/docs/zh/harnesses/substrate.md +4 -4
- package/docs/zh/harnesses/taskpool.md +2 -2
- package/docs/zh/latest.md +13 -124
- package/docs/zh/overview.md +1 -1
- package/docs/zh/quickstart.md +40 -16
- package/docs/zh/reference/api.md +14 -4
- package/docs/zh/reference/cli.md +58 -14
- package/docs/zh/runtime.md +2 -2
- package/docs/zh/services.md +4 -0
- package/examples/README.md +24 -12
- package/examples/authoring/README.md +24 -0
- package/examples/authoring/business.ts +4 -0
- package/examples/authoring/config.ts +2 -0
- package/examples/authoring/eject.json +5 -0
- package/examples/authoring/harness.ts +21 -0
- package/examples/autoresearch/README.md +33 -0
- package/examples/autoresearch/REQUIREMENTS.zh.md +18 -0
- package/examples/autoresearch/config.ts +90 -0
- package/examples/autoresearch/demo.ts +55 -0
- package/examples/autoresearch/eject.json +15 -0
- package/examples/autoresearch/frontiercs2.ts +237 -0
- package/examples/autoresearch/prepare.ts +267 -0
- package/examples/autoresearch/process.ts +50 -0
- package/examples/autoresearch/project.ts +397 -0
- package/examples/autoresearch/research-service.ts +302 -0
- package/examples/code/README.md +25 -0
- package/examples/code/REQUIREMENTS.zh.md +11 -0
- package/examples/code/candidate.ts +89 -0
- package/examples/code/config.ts +19 -0
- package/examples/code/eject.json +5 -0
- package/examples/code/project.ts +581 -0
- package/examples/code/prompts.ts +16 -0
- package/examples/code/verification.ts +239 -0
- package/examples/code/worktree.ts +188 -0
- package/examples/harness-session/README.md +3 -6
- package/examples/lead-worker/harness/dynamic-scheduler.ts +6 -3
- package/examples/lead-worker/harness/index.ts +61 -6
- package/examples/lead-worker/project.ts +2 -2
- package/examples/lead-worker/services/board.ts +14 -1
- package/examples/messages/README.md +5 -5
- package/examples/messages/handoff.ts +6 -2
- package/examples/messages/project.ts +47 -2
- package/examples/notes/README.md +13 -18
- package/examples/notes/project.ts +57 -9
- package/examples/peermesh/harness/router.ts +2 -2
- package/examples/peermesh/harness/team.ts +11 -0
- package/examples/peermesh/project.ts +19 -4
- package/examples/services/agent-control/README.md +3 -3
- package/examples/services/mathlib-search/Dockerfile +4 -2
- package/examples/services/mathlib-search/README.md +1 -1
- package/examples/services/mcp-managed/README.md +2 -2
- package/examples/services/persistent-board/README.md +13 -3
- package/examples/services/persistent-board/business.ts +10 -0
- package/examples/services/persistent-board/index.ts +10 -0
- package/examples/services/persistent-board/live.ts +54 -0
- package/examples/subagents/README.md +5 -5
- package/examples/subagents/business.ts +3 -1
- package/examples/subagents/harness/controller.ts +161 -29
- package/examples/subagents/project.ts +47 -33
- package/examples/subagents/prompts/prompts.ts +4 -0
- package/examples/subagents/services/collaboration-service.ts +14 -2
- package/examples/substrate/README.md +2 -2
- package/examples/substrate/harness/index.ts +67 -11
- package/examples/substrate/project.ts +5 -1
- package/examples/super/README.md +40 -0
- package/examples/super/actions.ts +196 -0
- package/examples/super/artifact.ts +56 -0
- package/examples/super/config.ts +95 -0
- package/examples/super/coordinator.ts +158 -0
- package/examples/super/daemon.ts +84 -0
- package/examples/super/decisions.ts +46 -0
- package/examples/super/eject.json +5 -0
- package/examples/super/execution.ts +131 -0
- package/examples/super/github.ts +242 -0
- package/examples/super/inbox.ts +306 -0
- package/examples/super/location.ts +54 -0
- package/examples/super/outbox.ts +97 -0
- package/examples/super/project.ts +227 -0
- package/examples/super/prompts.ts +27 -0
- package/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
- package/examples/taskpool/harness/controller.ts +59 -7
- package/examples/taskpool/project.ts +18 -2
- package/npm-shrinkwrap.development.json +2199 -0
- package/npm-shrinkwrap.json +86 -1920
- package/package.development.json +92 -0
- package/package.json +13 -7
- package/scripts/anyswarm-applications.ts +39 -0
- package/scripts/anyswarm-arguments.ts +94 -28
- package/scripts/anyswarm-author.ts +25 -0
- package/scripts/anyswarm-eject.ts +145 -0
- package/scripts/anyswarm-harnesses.ts +27 -0
- package/scripts/anyswarm-installation.ts +19 -13
- package/scripts/anyswarm-launch.ts +108 -0
- package/scripts/anyswarm-project.ts +114 -21
- package/scripts/anyswarm-source-runner.ts +203 -0
- package/scripts/anyswarm-tui-config.ts +174 -0
- package/scripts/anyswarm-tui-session.ts +295 -0
- package/scripts/anyswarm-tui-terminal.ts +147 -0
- package/scripts/anyswarm-tui.ts +912 -0
- package/scripts/anyswarm.ts +43 -2
- package/scripts/build.ts +8 -1
- package/scripts/generate-architecture-api.ts +2 -0
- package/scripts/generate-architecture-prompts.ts +35 -2
- package/scripts/local-environment.ts +55 -17
- package/scripts/local-setup-smoke.ts +3 -2
- package/scripts/local-setup-worker.ts +17 -7
- package/scripts/local-setup.ts +66 -13
- package/scripts/opensandbox-agent-worker.ts +2 -2
- package/scripts/pack-release.ts +67 -0
- package/scripts/pi-session-bridge.ts +10 -2
- package/scripts/run-harness.ts +3 -1
- package/scripts/setup-bootstrap.ts +41 -6
- package/src/core/allocation-ledger.ts +5 -3
- package/src/core/host-identity.ts +11 -0
- package/src/core/index.ts +12 -6
- package/src/core/mcp-service.ts +2 -2
- package/src/core/runtime-management.ts +22 -0
- package/src/core/sandbox/executor-driver.ts +15 -18
- package/src/core/sandbox/local-executor.ts +65 -19
- package/src/core/sandbox/local-worker.ts +29 -21
- package/src/core/sandbox/opensandbox-backend.ts +36 -11
- package/src/core/sandbox/sandbox-connection.ts +14 -5
- package/src/core/service-live-state.ts +156 -0
- package/src/core/service-observation-types.ts +23 -1
- package/src/core/service-process.ts +36 -3
- package/src/core/service-types.ts +3 -1
- package/src/core/services.ts +8 -3
- package/src/core/types.ts +3 -0
- package/src/core/worker-image.ts +3 -3
- package/src/harness/harness-session-types.ts +13 -1
- package/src/harness/harness-session.ts +40 -7
- package/src/harness/project-harness.ts +36 -10
- package/src/harness/project-input.ts +73 -15
- package/src/harness/project-rpc-client.ts +5 -0
- package/src/harness/project-rpc.ts +29 -8
- package/src/harness/project-runtime.ts +2 -1
- package/src/harness/typescript-loader.ts +37 -0
- package/src/trace-viewer/public/app.js +6 -5
- package/src/trace-viewer/reader.mjs +42 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { ownerInterventionText } from '../prompts/prompts.js';
|
|
2
3
|
function createMember(path, parent) {
|
|
3
|
-
return { path, parent, inbox: [], submitted: new Map(),
|
|
4
|
+
return { path, parent, inbox: [], submitted: new Map(), offers: new Map(), deliveries: new Map(),
|
|
5
|
+
executionRevision: 0, pendingDispatches: 0, ownerEpoch: 0 };
|
|
4
6
|
}
|
|
5
7
|
const namePattern = /^[a-z0-9_]{1,48}$/;
|
|
6
8
|
const inputLimit = 65_536;
|
|
@@ -35,11 +37,11 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
35
37
|
let rootEpoch = 0;
|
|
36
38
|
let rootPaused = false;
|
|
37
39
|
let rootControl;
|
|
38
|
-
const rootOffers =
|
|
40
|
+
const rootOffers = root.offers;
|
|
39
41
|
const reconciledRootControls = new Map();
|
|
40
42
|
const rootControlQueries = new Map();
|
|
41
43
|
const pendingRootControls = new Map();
|
|
42
|
-
const rootDeliveries =
|
|
44
|
+
const rootDeliveries = root.deliveries;
|
|
43
45
|
function open() {
|
|
44
46
|
if (!accepting)
|
|
45
47
|
fail('NOT_ALLOWED', 'The team is closing');
|
|
@@ -104,7 +106,7 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
104
106
|
}
|
|
105
107
|
function releaseWait(member) {
|
|
106
108
|
const messages = pending(member);
|
|
107
|
-
if (!member.wait || messages.length === 0 || (member === root && (rootPaused || rootControl)))
|
|
109
|
+
if (member.ownerStopped || member.ownerInterrupted || !member.wait || messages.length === 0 || (member === root && (rootPaused || rootControl)))
|
|
108
110
|
return false;
|
|
109
111
|
for (const message of messages)
|
|
110
112
|
message.state = 'returned';
|
|
@@ -116,6 +118,8 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
116
118
|
member.inbox = member.inbox.filter(item => item !== message);
|
|
117
119
|
}
|
|
118
120
|
async function offer(member, message) {
|
|
121
|
+
if (member.ownerStopped || member.ownerInterrupted)
|
|
122
|
+
return;
|
|
119
123
|
if (message.state === 'returned' || (message.state === 'pending' && releaseWait(member)))
|
|
120
124
|
return;
|
|
121
125
|
if (member === root && (rootPaused || rootControl))
|
|
@@ -125,9 +129,8 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
125
129
|
const { state: _state, ...payload } = message;
|
|
126
130
|
const body = JSON.stringify(payload);
|
|
127
131
|
const hash = createHash('sha256').update(body).digest('hex');
|
|
128
|
-
const activeOffer =
|
|
129
|
-
|
|
130
|
-
rootOffers.set(hash, activeOffer);
|
|
132
|
+
const activeOffer = { message, discarded: false };
|
|
133
|
+
member.offers.set(hash, activeOffer);
|
|
131
134
|
let receipt;
|
|
132
135
|
try {
|
|
133
136
|
receipt = await runtime.send(member.id, body, {
|
|
@@ -135,8 +138,7 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
135
138
|
});
|
|
136
139
|
}
|
|
137
140
|
finally {
|
|
138
|
-
|
|
139
|
-
rootOffers.delete(hash);
|
|
141
|
+
member.offers.delete(hash);
|
|
140
142
|
}
|
|
141
143
|
if (activeOffer?.discarded)
|
|
142
144
|
return;
|
|
@@ -187,7 +189,7 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
187
189
|
member.executionRevision++;
|
|
188
190
|
if (event.type === 'settled') {
|
|
189
191
|
member.lastOutcome = event.outcome === 'aborted' ? 'interrupted' : event.outcome;
|
|
190
|
-
if (event.outcome !== 'aborted' && !(member.fatalReported && event.outcome === 'failed'))
|
|
192
|
+
if (!member.ownerStopped && event.outcome !== 'aborted' && !(member.fatalReported && event.outcome === 'failed'))
|
|
191
193
|
resultFor(member, event, seq);
|
|
192
194
|
}
|
|
193
195
|
else if (event.type === 'error' && event.fatal && !member.fatalReported) {
|
|
@@ -211,8 +213,13 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
211
213
|
}
|
|
212
214
|
}
|
|
213
215
|
function submit(member, entry, text, from, requestId, authorize, options = {}, signal) {
|
|
216
|
+
entry.memberEpoch ??= member.ownerEpoch;
|
|
214
217
|
const guard = () => {
|
|
215
218
|
signal?.throwIfAborted();
|
|
219
|
+
if (member.ownerStopped)
|
|
220
|
+
fail('SESSION_UNAVAILABLE', 'The owner stopped this member');
|
|
221
|
+
if (entry.memberEpoch !== member.ownerEpoch)
|
|
222
|
+
fail('RUN_INPUT_CANCELLED', 'The input predates the member control barrier');
|
|
216
223
|
if (member !== root)
|
|
217
224
|
return;
|
|
218
225
|
if (entry.rootEpoch !== rootEpoch)
|
|
@@ -241,35 +248,36 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
241
248
|
const body = messages.length || from !== 'user'
|
|
242
249
|
? JSON.stringify({ kind: from === 'user' ? 'user' : 'new-task', from, text, messages: messages.map(({ state: _state, ...message }) => message) })
|
|
243
250
|
: text;
|
|
244
|
-
const
|
|
251
|
+
const delivery = member.deliveries.get(requestId) ?? {
|
|
245
252
|
hash: createHash('sha256').update(body).digest('hex'), messages, status: 'dispatching',
|
|
246
|
-
}
|
|
247
|
-
if (
|
|
248
|
-
|
|
253
|
+
};
|
|
254
|
+
if (!member.deliveries.has(requestId))
|
|
255
|
+
member.deliveries.set(requestId, delivery);
|
|
249
256
|
let receipt;
|
|
250
257
|
try {
|
|
251
258
|
guard();
|
|
252
259
|
receipt = await runtime.send(member.id, body, { source: from, wakeIfIdle: true, ...options, requestId });
|
|
253
260
|
}
|
|
254
261
|
catch (error) {
|
|
255
|
-
|
|
262
|
+
member.deliveries.delete(requestId);
|
|
256
263
|
for (const message of messages)
|
|
257
264
|
message.state = 'pending';
|
|
258
265
|
releaseWait(member);
|
|
259
266
|
throw error;
|
|
260
267
|
}
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (receipt.status !== 'unknown' &&
|
|
265
|
-
|
|
268
|
+
if (member.deliveries.get(requestId) === delivery) {
|
|
269
|
+
delivery.inputId = receipt.inputId;
|
|
270
|
+
delivery.status = receipt.status === 'accepted' ? receipt.disposition : receipt.status;
|
|
271
|
+
if (receipt.status !== 'unknown' && delivery.status !== 'queued')
|
|
272
|
+
member.deliveries.delete(requestId);
|
|
266
273
|
}
|
|
267
274
|
// A concurrent interrupt or clear already settled this input from the native queue.
|
|
268
|
-
if (member === root && entry.rootEpoch !== rootEpoch)
|
|
275
|
+
if (entry.memberEpoch !== member.ownerEpoch || (member === root && entry.rootEpoch !== rootEpoch))
|
|
269
276
|
return receipt;
|
|
270
277
|
if (receipt.status === 'accepted') {
|
|
271
278
|
for (const message of messages)
|
|
272
279
|
removeMemberMessage(member, message);
|
|
280
|
+
member.ownerInterrupted = false;
|
|
273
281
|
if (member === root)
|
|
274
282
|
rootPaused = false;
|
|
275
283
|
member.wait?.({ reason: 'input' });
|
|
@@ -285,7 +293,7 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
285
293
|
function waitForMessage(member, duration, signal) {
|
|
286
294
|
if (member.wait)
|
|
287
295
|
fail('CONFLICT', 'This member is already waiting');
|
|
288
|
-
if (signal.aborted || (member === root && rootPaused))
|
|
296
|
+
if (signal.aborted || member.ownerStopped || member.ownerInterrupted || (member === root && rootPaused))
|
|
289
297
|
return Promise.resolve({ reason: 'cancelled' });
|
|
290
298
|
return new Promise(resolve => {
|
|
291
299
|
const timer = setTimeout(() => finish({ reason: 'timeout' }), duration);
|
|
@@ -304,15 +312,15 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
304
312
|
onChange?.();
|
|
305
313
|
});
|
|
306
314
|
}
|
|
307
|
-
function
|
|
315
|
+
function restoreMemberQueue(member, hashes, scope) {
|
|
308
316
|
const discarded = new Set(hashes);
|
|
309
317
|
const inputs = [];
|
|
310
318
|
const inbox = [];
|
|
311
319
|
const restore = (message) => {
|
|
312
320
|
message.state = 'pending';
|
|
313
|
-
if (!
|
|
321
|
+
if (!member.inbox.some(item => item.id === message.id)) {
|
|
314
322
|
try {
|
|
315
|
-
reserveMessage(
|
|
323
|
+
reserveMessage(member, message);
|
|
316
324
|
}
|
|
317
325
|
catch {
|
|
318
326
|
deliveryFailures.push({ id: message.id, reason: 'MAILBOX_FULL_AFTER_CONTROL' });
|
|
@@ -321,20 +329,20 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
321
329
|
}
|
|
322
330
|
inbox.push(message.id);
|
|
323
331
|
};
|
|
324
|
-
for (const [hash, message] of
|
|
332
|
+
for (const [hash, message] of member.submitted) {
|
|
325
333
|
if (scope && !scope.submitted.has(hash))
|
|
326
334
|
continue;
|
|
327
335
|
if (discarded.has(hash))
|
|
328
336
|
restore(message);
|
|
329
|
-
|
|
337
|
+
member.submitted.delete(hash);
|
|
330
338
|
}
|
|
331
|
-
for (const [hash, offer] of
|
|
339
|
+
for (const [hash, offer] of member.offers) {
|
|
332
340
|
if (discarded.has(hash) && (!scope || scope.submitted.has(hash))) {
|
|
333
341
|
offer.discarded = true;
|
|
334
342
|
restore(offer.message);
|
|
335
343
|
}
|
|
336
344
|
}
|
|
337
|
-
for (const [requestId, delivery] of
|
|
345
|
+
for (const [requestId, delivery] of member.deliveries) {
|
|
338
346
|
if (scope && !scope.deliveries.has(requestId))
|
|
339
347
|
continue;
|
|
340
348
|
if (discarded.has(delivery.hash)) {
|
|
@@ -347,9 +355,9 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
347
355
|
}
|
|
348
356
|
else {
|
|
349
357
|
for (const message of delivery.messages)
|
|
350
|
-
removeMemberMessage(
|
|
358
|
+
removeMemberMessage(member, message);
|
|
351
359
|
}
|
|
352
|
-
|
|
360
|
+
member.deliveries.delete(requestId);
|
|
353
361
|
}
|
|
354
362
|
return { discardedUserInputs: inputs, restoredInbox: inbox };
|
|
355
363
|
}
|
|
@@ -362,7 +370,7 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
362
370
|
const scope = pendingRootControls.get(requestId);
|
|
363
371
|
if (!confirmed || !scope)
|
|
364
372
|
return { core, harnessEffects: { status: 'unknown', ...paused } };
|
|
365
|
-
const result = { core, harnessEffects: { status: 'complete', ...
|
|
373
|
+
const result = { core, harnessEffects: { status: 'complete', ...restoreMemberQueue(root, core.discardedInputHashes ?? [], scope), ...paused } };
|
|
366
374
|
pendingRootControls.delete(requestId);
|
|
367
375
|
reconciledRootControls.set(requestId, result);
|
|
368
376
|
return result;
|
|
@@ -371,6 +379,8 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
371
379
|
open();
|
|
372
380
|
if (!root.id)
|
|
373
381
|
fail('RUN_NOT_READY', 'Root is not available yet');
|
|
382
|
+
if (root.ownerStopped)
|
|
383
|
+
fail('SESSION_UNAVAILABLE', 'The owner stopped Root');
|
|
374
384
|
if (rootControl)
|
|
375
385
|
fail('OPERATION_BUSY', 'Root already has a reserved control');
|
|
376
386
|
rootControl = operation;
|
|
@@ -398,6 +408,8 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
398
408
|
signal.throwIfAborted();
|
|
399
409
|
if (!root.id)
|
|
400
410
|
fail('RUN_NOT_READY', 'Root is not available yet');
|
|
411
|
+
if (root.ownerStopped)
|
|
412
|
+
fail('SESSION_UNAVAILABLE', 'The owner stopped Root');
|
|
401
413
|
if (epoch !== rootEpoch)
|
|
402
414
|
fail('RUN_INPUT_CANCELLED', 'The Root input predates its control barrier');
|
|
403
415
|
if (rootControl)
|
|
@@ -419,6 +431,8 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
419
431
|
open();
|
|
420
432
|
if (!root.id)
|
|
421
433
|
fail('RUN_NOT_READY', 'Root is not available yet');
|
|
434
|
+
if (root.ownerStopped)
|
|
435
|
+
fail('SESSION_UNAVAILABLE', 'The owner stopped Root');
|
|
422
436
|
if (rootControl || root.pendingDispatches)
|
|
423
437
|
fail('OPERATION_BUSY', 'Root dispatch is in progress');
|
|
424
438
|
rootControl = 'compact';
|
|
@@ -429,12 +443,142 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
429
443
|
rootControl = undefined;
|
|
430
444
|
}
|
|
431
445
|
}
|
|
446
|
+
const ownerControls = new Map();
|
|
447
|
+
const ownerControlScopes = new Map();
|
|
448
|
+
function ownerMember(agentId) {
|
|
449
|
+
const member = byId.get(agentId);
|
|
450
|
+
if (!member)
|
|
451
|
+
fail('NOT_FOUND', 'The member does not belong to this team');
|
|
452
|
+
return member;
|
|
453
|
+
}
|
|
454
|
+
function reportIntervention(member, operation, requestId) {
|
|
455
|
+
if (!member.parent || !accepting)
|
|
456
|
+
return;
|
|
457
|
+
const recipient = member.parent;
|
|
458
|
+
const message = { id: 'owner:' + requestId, kind: operation === 'steer' ? 'message' : 'result', from: member.path,
|
|
459
|
+
text: ownerInterventionText(operation),
|
|
460
|
+
...(operation === 'steer' ? {} : { outcome: 'failed' }), eventSeq: ++eventSequence, state: 'pending' };
|
|
461
|
+
void track(serial(recipient, async () => { reserveMessage(recipient, message); await offer(recipient, message); }))
|
|
462
|
+
.catch(error => { if (deliveryFailures.length < mailboxLimit)
|
|
463
|
+
deliveryFailures.push({ id: message.id, reason: error.code ?? 'SERVICE_UNAVAILABLE' }); });
|
|
464
|
+
}
|
|
465
|
+
function settleOwnerControl(member, operation, requestId, core) {
|
|
466
|
+
const confirmed = operation === 'interrupt' ? core.status === 'interrupted' : core.execution === 'stopped';
|
|
467
|
+
if (!confirmed)
|
|
468
|
+
return { core, harnessEffects: { status: 'unknown', target: member.path } };
|
|
469
|
+
if (operation === 'interrupt') {
|
|
470
|
+
member.lastOutcome = 'interrupted';
|
|
471
|
+
restoreMemberQueue(member, core.discardedInputHashes ?? [], ownerControlScopes.get(requestId));
|
|
472
|
+
}
|
|
473
|
+
ownerControlScopes.delete(requestId);
|
|
474
|
+
member.wait?.({ reason: 'cancelled' });
|
|
475
|
+
reportIntervention(member, operation, requestId);
|
|
476
|
+
onChange?.();
|
|
477
|
+
return { core, harnessEffects: { status: 'complete', target: member.path, ownerInterrupted: !!member.ownerInterrupted,
|
|
478
|
+
ownerStopped: !!member.ownerStopped } };
|
|
479
|
+
}
|
|
480
|
+
function ownerControl(operation, agentId, requestId, reason) {
|
|
481
|
+
const existing = ownerControls.get(requestId);
|
|
482
|
+
if (existing) {
|
|
483
|
+
if (existing.operation !== operation || existing.agentId !== agentId || existing.reason !== reason)
|
|
484
|
+
fail('CONFLICT', 'The owner request changed');
|
|
485
|
+
return existing.result;
|
|
486
|
+
}
|
|
487
|
+
open();
|
|
488
|
+
if (ownerControls.size >= operationLimit)
|
|
489
|
+
fail('NOT_ALLOWED', 'The owner control limit has been reached');
|
|
490
|
+
const member = ownerMember(agentId);
|
|
491
|
+
if (member.ownerStopped)
|
|
492
|
+
fail('SESSION_UNAVAILABLE', 'The owner stopped this member');
|
|
493
|
+
ownerControlScopes.set(requestId, { deliveries: new Set(member.deliveries.keys()),
|
|
494
|
+
submitted: new Set([...member.submitted.keys(), ...member.offers.keys()]) });
|
|
495
|
+
member.ownerEpoch++;
|
|
496
|
+
member.ownerInterrupted = true;
|
|
497
|
+
if (operation === 'stop')
|
|
498
|
+
member.ownerStopped = true;
|
|
499
|
+
member.wait?.({ reason: 'cancelled' });
|
|
500
|
+
if (member === root) {
|
|
501
|
+
rootEpoch++;
|
|
502
|
+
rootPaused = true;
|
|
503
|
+
}
|
|
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
|
+
}
|
|
432
511
|
function attachRoot(id) {
|
|
433
512
|
root.id = id;
|
|
434
513
|
byId.set(id, root);
|
|
435
514
|
}
|
|
436
515
|
return {
|
|
437
516
|
attachRoot,
|
|
517
|
+
ownerControl,
|
|
518
|
+
sendMember(agentId, input, requestId, options, signal) {
|
|
519
|
+
const member = ownerMember(agentId);
|
|
520
|
+
if (member === root)
|
|
521
|
+
return this.submitUser(input, { operationId: requestId }, options, signal);
|
|
522
|
+
inputText(input);
|
|
523
|
+
return operate(requestId, { agentId, input, options }, async (entry) => {
|
|
524
|
+
const receipt = await submit(member, entry, input, 'user', requestId, undefined, options, signal);
|
|
525
|
+
if (receipt.status === 'accepted' && !entry.ownerNotified) {
|
|
526
|
+
entry.ownerNotified = true;
|
|
527
|
+
reportIntervention(member, 'steer', requestId);
|
|
528
|
+
}
|
|
529
|
+
return receipt;
|
|
530
|
+
});
|
|
531
|
+
},
|
|
532
|
+
async reconcileMemberInput(agentId, requestId, query) {
|
|
533
|
+
const member = ownerMember(agentId);
|
|
534
|
+
const entry = operations.get(requestId);
|
|
535
|
+
if (!entry?.inputDispatched)
|
|
536
|
+
return { status: 'unknown' };
|
|
537
|
+
const receipt = await query();
|
|
538
|
+
if (receipt.status === 'unknown')
|
|
539
|
+
return receipt;
|
|
540
|
+
entry.result = Promise.resolve(receipt);
|
|
541
|
+
if (entry.memberEpoch === member.ownerEpoch) {
|
|
542
|
+
for (const message of entry.batch ?? []) {
|
|
543
|
+
if (receipt.status === 'accepted')
|
|
544
|
+
removeMemberMessage(member, message);
|
|
545
|
+
else
|
|
546
|
+
message.state = 'pending';
|
|
547
|
+
}
|
|
548
|
+
if (receipt.status === 'accepted') {
|
|
549
|
+
member.ownerInterrupted = false;
|
|
550
|
+
member.wait?.({ reason: 'input' });
|
|
551
|
+
if (!entry.ownerNotified) {
|
|
552
|
+
entry.ownerNotified = true;
|
|
553
|
+
reportIntervention(member, 'steer', requestId);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
else
|
|
557
|
+
releaseWait(member);
|
|
558
|
+
}
|
|
559
|
+
onChange?.();
|
|
560
|
+
return receipt;
|
|
561
|
+
},
|
|
562
|
+
async reconcileOwnerControl(operation, agentId, requestId, query) {
|
|
563
|
+
const previous = ownerControls.get(requestId);
|
|
564
|
+
if (!previous || previous.operation !== operation || previous.agentId !== agentId)
|
|
565
|
+
return { status: 'unknown' };
|
|
566
|
+
const original = await previous.result;
|
|
567
|
+
if (original.harnessEffects?.status === 'complete')
|
|
568
|
+
return original;
|
|
569
|
+
if (previous.reconciling)
|
|
570
|
+
return previous.reconciling;
|
|
571
|
+
const result = (operation === 'stop' ? runtime.stop(agentId) : query())
|
|
572
|
+
.then(core => settleOwnerControl(ownerMember(agentId), operation, requestId, core));
|
|
573
|
+
previous.result = result;
|
|
574
|
+
previous.reconciling = result.finally(() => { previous.reconciling = undefined; });
|
|
575
|
+
return previous.reconciling;
|
|
576
|
+
},
|
|
577
|
+
readLiveState() {
|
|
578
|
+
return { memberCount: byPath.size, operationCount: operations.size,
|
|
579
|
+
members: [...byPath.values()].slice(0, 100).map(member => ({ path: member.path, agentId: member.id ?? null,
|
|
580
|
+
parent: member.parent?.path ?? null, lastOutcome: member.lastOutcome ?? null, waiting: !!member.wait })) };
|
|
581
|
+
},
|
|
438
582
|
rootId: () => root.id,
|
|
439
583
|
rootEpoch: () => rootEpoch,
|
|
440
584
|
rootBusy: () => !!rootControl || root.pendingDispatches > 0,
|
|
@@ -507,6 +651,8 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
507
651
|
if (!caller)
|
|
508
652
|
fail('NOT_ALLOWED', 'Caller does not belong to this team');
|
|
509
653
|
request.assertAuthorized();
|
|
654
|
+
if (caller.ownerStopped)
|
|
655
|
+
fail('SESSION_UNAVAILABLE', 'The owner stopped this member');
|
|
510
656
|
const call = request.input;
|
|
511
657
|
const operation = request.capability.operation;
|
|
512
658
|
if (operation === 'list_agents') {
|
|
@@ -562,6 +708,8 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
562
708
|
return { task_name: child.path, agentId: child.id, ...receipt };
|
|
563
709
|
}
|
|
564
710
|
const recipient = target(caller, call.target);
|
|
711
|
+
if (recipient.ownerStopped)
|
|
712
|
+
fail('SESSION_UNAVAILABLE', 'The owner stopped this member');
|
|
565
713
|
if (operation === 'followup_task') {
|
|
566
714
|
if (recipient === root)
|
|
567
715
|
fail('NOT_ALLOWED', 'The Root only receives follow-up tasks from the host');
|
|
@@ -637,6 +785,7 @@ export function createSubagentsController(runtime, { maxDepth, childWorkspace, c
|
|
|
637
785
|
members: [...byPath.values()].map(member => ({
|
|
638
786
|
path: member.path, agentId: member.id ?? null, parent: member.parent?.path ?? null,
|
|
639
787
|
lastOutcome: member.lastOutcome ?? null, waiting: Boolean(member.wait),
|
|
788
|
+
ownerInterrupted: !!member.ownerInterrupted, ownerStopped: !!member.ownerStopped,
|
|
640
789
|
nativeQueuedAdmissions: member.submitted.size,
|
|
641
790
|
pending: member.inbox.map(({ id, state }) => ({ id, state })),
|
|
642
791
|
})),
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type HarnessAgentRegistration, type ExecutorCapabilities } from '@anyswarm/core';
|
|
2
|
+
export declare function subagentsAgentControls(team: ReturnType<typeof import('./harness/controller.js').createSubagentsController>, native: ExecutorCapabilities, reconcile?: (agentId: string, operation: string, requestId: string) => Promise<unknown>): Omit<HarnessAgentRegistration, 'runtime'>;
|
|
1
3
|
declare const subagents: {
|
|
2
4
|
id: string;
|
|
3
5
|
apiVersion: 1;
|
|
@@ -20,6 +20,48 @@ function parseInput(payload) {
|
|
|
20
20
|
}
|
|
21
21
|
throw Object.assign(new TypeError('Expected nonblank Root text and an optional send mode'), { code: 'INVALID_HARNESS_INPUT' });
|
|
22
22
|
}
|
|
23
|
+
export function subagentsAgentControls(team, native, reconcile = async () => ({ status: 'unknown' })) {
|
|
24
|
+
return {
|
|
25
|
+
fence: team.beginClose,
|
|
26
|
+
reconcile: (operation, agentId, { operationId }, payload) => {
|
|
27
|
+
const text = operation === 'send' && typeof payload.input === 'string';
|
|
28
|
+
const nativeOperation = operation === 'send' && !text ? 'context' : operation;
|
|
29
|
+
const lookup = () => reconcile(agentId, nativeOperation, operationId);
|
|
30
|
+
if (operation === 'stop' || (operation === 'interrupt' && agentId !== team.rootId())) {
|
|
31
|
+
return team.reconcileOwnerControl(operation, agentId, operationId, lookup);
|
|
32
|
+
}
|
|
33
|
+
if (operation === 'interrupt' || operation === 'clearQueue')
|
|
34
|
+
return team.reconcileRootControl(operation, operationId, lookup);
|
|
35
|
+
if (text)
|
|
36
|
+
return agentId === team.rootId() ? team.reconcileRootInput(operationId, lookup)
|
|
37
|
+
: team.reconcileMemberInput(agentId, operationId, lookup);
|
|
38
|
+
return lookup();
|
|
39
|
+
},
|
|
40
|
+
capabilities: agentId => ({
|
|
41
|
+
...(agentId === team.rootId() ? {
|
|
42
|
+
configure: { supported: true, fields: configureFields },
|
|
43
|
+
compact: { supported: true, ...(team.rootBusy() ? { available: false, reason: 'OPERATION_BUSY' } : {}) },
|
|
44
|
+
abortRetry: { supported: true }, clearQueue: { supported: true },
|
|
45
|
+
} : {}),
|
|
46
|
+
send: { supported: native.activeSteer || native.followUp, text: true, context: agentId === team.rootId(),
|
|
47
|
+
modes: modes.filter(mode => mode === 'steer' ? native.activeSteer : native.followUp), deliveries },
|
|
48
|
+
interrupt: { supported: native.queuedInputCancellation },
|
|
49
|
+
stop: { supported: true },
|
|
50
|
+
}),
|
|
51
|
+
handlers: {
|
|
52
|
+
compact: (_agentId, payload, request) => team.compactRoot({ ...payload, requestId: request.operationId }),
|
|
53
|
+
clearQueue: (_agentId, _payload, request) => team.rootQueueControl('clearQueue', request.operationId),
|
|
54
|
+
interrupt: (agentId, _payload, request) => agentId === team.rootId()
|
|
55
|
+
? team.rootQueueControl('interrupt', request.operationId) : team.ownerControl('interrupt', agentId, request.operationId),
|
|
56
|
+
stop: (agentId, payload, request) => team.ownerControl('stop', agentId, request.operationId, payload.reason),
|
|
57
|
+
send(agentId, payload, request) {
|
|
58
|
+
const { input, options } = payload;
|
|
59
|
+
return typeof input === 'string' ? team.sendMember(agentId, input, request.operationId, options, request.signal)
|
|
60
|
+
: team.sendRootContext(input, { ...options, requestId: request.operationId }, request.signal);
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
23
65
|
const subagents = {
|
|
24
66
|
id: 'subagents',
|
|
25
67
|
apiVersion: 1,
|
|
@@ -64,40 +106,7 @@ const subagents = {
|
|
|
64
106
|
onChange: () => { void observation?.refresh(); },
|
|
65
107
|
userQuestions: context.clientCapabilities.questions ? createUserQuestionsService(context) : undefined,
|
|
66
108
|
onRuntime: (runtime, team) => {
|
|
67
|
-
|
|
68
|
-
observation = observeProjectRuntime(runtime, context, team.exportState, {
|
|
69
|
-
fence: team.beginClose,
|
|
70
|
-
reconcile: (operation, agentId, { operationId }, payload) => {
|
|
71
|
-
const text = operation === 'send' && typeof payload.input === 'string';
|
|
72
|
-
const nativeOperation = operation === 'send' && !text ? 'context' : operation;
|
|
73
|
-
const lookup = () => observation.reconcile(agentId, nativeOperation, operationId);
|
|
74
|
-
if (operation === 'interrupt' || operation === 'clearQueue')
|
|
75
|
-
return team.reconcileRootControl(operation, operationId, lookup);
|
|
76
|
-
return text ? team.reconcileRootInput(operationId, lookup) : lookup();
|
|
77
|
-
},
|
|
78
|
-
capabilities: agentId => {
|
|
79
|
-
if (agentId !== team.rootId())
|
|
80
|
-
return {};
|
|
81
|
-
return {
|
|
82
|
-
configure: { supported: true, fields: configureFields },
|
|
83
|
-
compact: { supported: true, ...(team.rootBusy() ? { available: false, reason: 'OPERATION_BUSY' } : {}) },
|
|
84
|
-
abortRetry: { supported: true },
|
|
85
|
-
clearQueue: { supported: true },
|
|
86
|
-
send: { supported: true, text: true, context: true, modes, deliveries },
|
|
87
|
-
interrupt: { supported: native.queuedInputCancellation },
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
handlers: {
|
|
91
|
-
compact: (_agentId, payload, request) => team.compactRoot({ ...payload, requestId: request.operationId }),
|
|
92
|
-
clearQueue: (_agentId, _payload, request) => team.rootQueueControl('clearQueue', request.operationId),
|
|
93
|
-
interrupt: (_agentId, _payload, request) => team.rootQueueControl('interrupt', request.operationId),
|
|
94
|
-
send(_agentId, payload, request) {
|
|
95
|
-
const { input, options } = payload;
|
|
96
|
-
return typeof input === 'string' ? team.submitUser(input, request, options, request.signal)
|
|
97
|
-
: team.sendRootContext(input, { ...options, requestId: request.operationId }, request.signal);
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
});
|
|
109
|
+
observation = observeProjectRuntime(runtime, context, team.exportState, subagentsAgentControls(team, getExecutorCapabilities(config.executor ?? 'pi'), (agentId, operation, requestId) => observation.reconcile(agentId, operation, requestId)));
|
|
101
110
|
},
|
|
102
111
|
onReady: harness => {
|
|
103
112
|
context.registerInput((input, { operationId, signal, binding }) => {
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
export declare function ownerInterventionText(operation: 'steer' | 'interrupt' | 'stop'): string;
|
|
1
2
|
export declare 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\nAddress 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
3
|
export declare 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\nAddress 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.";
|
|
@@ -1,3 +1,6 @@
|
|
|
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
|
+
export function ownerInterventionText(operation) {
|
|
3
|
+
return `user-${operation}: the Run owner ${operation === 'stop' ? 'stopped' : operation === 'steer' ? 'steered' : 'interrupted'} this member`;
|
|
4
|
+
}
|
|
2
5
|
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}`;
|
|
3
6
|
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}`;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type HarnessContext, type ServiceRequest, type JsonValue } from '@anyswarm/core';
|
|
2
2
|
export declare const collaborationOperations: ("followup_task" | "interrupt_agent" | "list_agents" | "send_message" | "spawn_agent" | "wait_agent")[];
|
|
3
|
-
export declare function createCollaborationService(invoke: (request: ServiceRequest) => Promise<JsonValue>, exportState: () => JsonValue, { allowContextFork }?: {
|
|
4
|
-
allowContextFork?: boolean
|
|
3
|
+
export declare function createCollaborationService(invoke: (request: ServiceRequest) => Promise<JsonValue>, exportState: () => JsonValue, { allowContextFork, readState }?: {
|
|
4
|
+
allowContextFork?: boolean;
|
|
5
|
+
readState?: () => JsonValue;
|
|
5
6
|
}): import("@anyswarm/core").ServiceDefinition;
|
|
6
7
|
export declare function createUserQuestionsService(context: HarnessContext): import("@anyswarm/core").ServiceDefinition;
|
|
@@ -43,8 +43,20 @@ const freshChildManifest = {
|
|
|
43
43
|
}),
|
|
44
44
|
};
|
|
45
45
|
export const collaborationOperations = capabilities.map(([operation]) => operation);
|
|
46
|
-
export function createCollaborationService(invoke, exportState, { allowContextFork = true } = {}) {
|
|
47
|
-
return serviceFromManifest({ manifest: allowContextFork ? manifest : freshChildManifest, adapter: createInProcessAdapter({
|
|
46
|
+
export function createCollaborationService(invoke, exportState, { allowContextFork = true, readState } = {}) {
|
|
47
|
+
return serviceFromManifest({ manifest: allowContextFork ? manifest : freshChildManifest, adapter: createInProcessAdapter({
|
|
48
|
+
invoke, exportState,
|
|
49
|
+
...(readState ? { readState: () => ({
|
|
50
|
+
state: readState(), capturedAt: new Date().toISOString(),
|
|
51
|
+
presentation: {
|
|
52
|
+
summary: [{ label: 'Members', path: '/memberCount' }, { label: 'Operations', path: '/operationCount' }],
|
|
53
|
+
tables: [{ title: 'Team members', path: '/members', columns: [
|
|
54
|
+
{ label: 'Member', path: '/path' }, { label: 'Parent', path: '/parent' },
|
|
55
|
+
{ label: 'Last outcome', path: '/lastOutcome' }, { label: 'Waiting', path: '/waiting' },
|
|
56
|
+
] }],
|
|
57
|
+
},
|
|
58
|
+
}) } : {}),
|
|
59
|
+
}) })[1];
|
|
48
60
|
}
|
|
49
61
|
const questionManifest = {
|
|
50
62
|
id: 'user-interaction', title: 'Ask the user', purpose: 'Ask an explicit question needed for the current work.',
|
|
@@ -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
|
|
@@ -18,4 +18,4 @@ export declare function substratePeerProfile({ image, model, exportLimit }: any)
|
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
/** Fixed no-Task pool. Harness owns content and drivers; Core owns all Agents. */
|
|
21
|
-
export declare function runSubstrate({ sandbox, executor, models, connection, filePolicy, runId, image, outputDir, question, model, poolSize, maxRounds, workTimeoutMs, turnTimeoutMs, closeTimeoutMs, files, onRuntime, beforeCycle, onReady, onCycle, onPeerStop, questionForCycle, maxConcurrentInputs }: any, signal: any, run?: typeof runWithReport): Promise<any>;
|
|
21
|
+
export declare function runSubstrate({ sandbox, executor, models, connection, filePolicy, runId, image, outputDir, question, model, poolSize, maxRounds, workTimeoutMs, turnTimeoutMs, closeTimeoutMs, files, onRuntime, beforeCycle, onReady, onCycle, onPeerStop, onControl, questionForCycle, maxConcurrentInputs }: any, signal: any, run?: typeof runWithReport): Promise<any>;
|