@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,158 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { defaults } from './config.js';
|
|
3
|
+
import type { Artifact, Delivery, Entry, Inbox } from './inbox.js';
|
|
4
|
+
|
|
5
|
+
export type Role = 'worker' | 'reviewer';
|
|
6
|
+
export type MemberResult = { summary: string; files?: Record<string, string> };
|
|
7
|
+
type Decision = { action: 'delegate' | 'start'; role: Role; text: string }
|
|
8
|
+
| { action: 'ask' | 'reply'; text: string }
|
|
9
|
+
| { action: 'wait' | 'stop'; member: string }
|
|
10
|
+
| { action: 'steer'; member: string; text: string };
|
|
11
|
+
export interface ActiveMember {
|
|
12
|
+
id: string;
|
|
13
|
+
result: Promise<MemberResult>;
|
|
14
|
+
steer(text: string): Promise<string>;
|
|
15
|
+
stop(): Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
export interface WorkSession {
|
|
18
|
+
route(input: object): Promise<string>;
|
|
19
|
+
start(role: Role, text: string, files: Record<string, string>): Promise<ActiveMember>;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export interface WorkBackend {
|
|
23
|
+
open(entry: Entry, signal: AbortSignal): Promise<WorkSession>;
|
|
24
|
+
}
|
|
25
|
+
export type Baseline = { base: string; files: Record<string, string> };
|
|
26
|
+
|
|
27
|
+
export interface WorkProject {
|
|
28
|
+
baseline(entry: Entry, signal: AbortSignal): Promise<Baseline>;
|
|
29
|
+
export(entry: Entry, baseline: Baseline, files: Record<string, string>): Promise<Artifact | undefined>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function decision(message: string): Decision {
|
|
33
|
+
const json = JSON.parse(message.trim().replace(/^```(?:json)?\s*|\s*```$/g, ''));
|
|
34
|
+
if (!json || typeof json !== 'object') throw new Error('Invalid Router response');
|
|
35
|
+
const text = typeof json.text === 'string' && json.text.trim() && Buffer.byteLength(json.text) <= 8192;
|
|
36
|
+
const member = typeof json.member === 'string' && json.member.length > 0 && json.member.length <= 128;
|
|
37
|
+
if (text && (json.action === 'delegate' || json.action === 'start') && (json.role === 'worker' || json.role === 'reviewer')) return json;
|
|
38
|
+
if (text && (json.action === 'ask' || json.action === 'reply')) return json;
|
|
39
|
+
if (member && ((text && json.action === 'steer') || json.action === 'stop' || json.action === 'wait')) return json;
|
|
40
|
+
throw new Error('Unsupported Router decision');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function coordinate(inbox: Inbox, backend: WorkBackend, project: WorkProject, publish: boolean, changed: () => void) {
|
|
44
|
+
const active = new Map<string, { controller: AbortController; done: Promise<void> }>();
|
|
45
|
+
let stopping = false;
|
|
46
|
+
|
|
47
|
+
async function run(entry: Entry, signal: AbortSignal) {
|
|
48
|
+
let session: WorkSession | undefined;
|
|
49
|
+
let delivery: Delivery | undefined;
|
|
50
|
+
try {
|
|
51
|
+
session = await backend.open(entry, signal);
|
|
52
|
+
let baseline: Baseline | undefined;
|
|
53
|
+
let files: Record<string, string> | undefined;
|
|
54
|
+
let feedback: object | undefined;
|
|
55
|
+
let review: string | undefined;
|
|
56
|
+
let member: { handle: ActiveMember; role: Role } | undefined;
|
|
57
|
+
async function collect() {
|
|
58
|
+
const active = member!;
|
|
59
|
+
const result = await active.handle.result;
|
|
60
|
+
member = undefined;
|
|
61
|
+
const puts = result.files ?? {};
|
|
62
|
+
if (Object.entries(puts).some(([path, text]) => !Object.hasOwn(files!, path) || Buffer.byteLength(text) > defaults.fileBytes)) {
|
|
63
|
+
throw new Error('Worker changed a file outside the approved scope');
|
|
64
|
+
}
|
|
65
|
+
const changed = Object.keys(puts).filter(path => files![path] !== puts[path]);
|
|
66
|
+
if (active.role === 'worker') {
|
|
67
|
+
files = { ...files, ...puts };
|
|
68
|
+
if (changed.length) review = undefined;
|
|
69
|
+
} else review = result.summary.trim().slice(0, 1200);
|
|
70
|
+
return { role: active.role, summary: result.summary.slice(0, 8192), changed };
|
|
71
|
+
}
|
|
72
|
+
for (let step = 0; step < defaults.maxTurns; step++) {
|
|
73
|
+
signal.throwIfAborted();
|
|
74
|
+
const route = decision(await session.route(step === 0 ? {
|
|
75
|
+
issue: entry.job.thread, work: entry.job.id, message: entry.input.text,
|
|
76
|
+
previousQuestion: entry.job.question, previousTurns: entry.history, previousChanges: Object.keys(entry.job.last?.files ?? {}),
|
|
77
|
+
} : { work: entry.job.id, feedback, activeMember: member?.handle.id, remaining: defaults.maxTurns - step - 1 }));
|
|
78
|
+
signal.throwIfAborted();
|
|
79
|
+
if (route.action === 'delegate' || route.action === 'start') {
|
|
80
|
+
if (member) { feedback = { error: 'Wait for or stop the active member first' }; continue; }
|
|
81
|
+
baseline ??= await project.baseline(entry, signal);
|
|
82
|
+
files ??= Object.fromEntries(Object.entries(baseline.files).map(([path, text]) =>
|
|
83
|
+
[path, entry.job.last?.files[path] ?? text]));
|
|
84
|
+
const handle = await session.start(route.role, route.text, files);
|
|
85
|
+
member = { handle, role: route.role };
|
|
86
|
+
feedback = route.action === 'delegate' ? await collect() : { started: handle.id, role: route.role };
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if ('member' in route) {
|
|
90
|
+
if (!member || route.member !== member.handle.id) { feedback = { error: 'Invalid member for this work' }; continue; }
|
|
91
|
+
if (route.action === 'wait') feedback = await collect();
|
|
92
|
+
else if (route.action === 'steer') feedback = { steer: await member.handle.steer(route.text) };
|
|
93
|
+
else {
|
|
94
|
+
feedback = { stop: await member.handle.stop() };
|
|
95
|
+
member = undefined;
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (member) { feedback = { error: 'Wait for or stop the active member before replying' }; continue; }
|
|
100
|
+
const modified = baseline && files && Object.keys(files).some(path =>
|
|
101
|
+
files![path] !== (entry.job.last?.files[path] ?? baseline!.files[path]));
|
|
102
|
+
if (modified && !review) {
|
|
103
|
+
feedback = { error: 'Delegate a read-only Reviewer to check the current edited files before asking or replying.' };
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const patch = modified ? await project.export(entry, baseline!, files!) : undefined;
|
|
107
|
+
const artifact = patch && { ...patch, review };
|
|
108
|
+
signal.throwIfAborted();
|
|
109
|
+
if (route.action !== 'ask' && route.action !== 'reply') throw new Error('Invalid Router final action');
|
|
110
|
+
delivery = {
|
|
111
|
+
text: route.text, reply: 'queued', result: route.action === 'ask' ? 'waiting' : 'completed',
|
|
112
|
+
...(route.action === 'ask' && { question: route.text }),
|
|
113
|
+
...(artifact && { artifact, publish: publish ? 'queued' : 'approval' }),
|
|
114
|
+
};
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (!delivery) throw new Error('Router did not finish within the action budget');
|
|
118
|
+
} catch {
|
|
119
|
+
if (!signal.aborted) {
|
|
120
|
+
delivery = {
|
|
121
|
+
text: 'Personal could not complete this request. Check the Run Trace or send a follow-up to retry.',
|
|
122
|
+
reply: 'queued', result: 'failed',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
} finally {
|
|
126
|
+
await session?.close().catch(() => {});
|
|
127
|
+
}
|
|
128
|
+
if (delivery && !signal.aborted) inbox.prepare(entry, delivery);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function dispatch() {
|
|
132
|
+
if (stopping) return;
|
|
133
|
+
while (active.size < defaults.maxWork) {
|
|
134
|
+
const entry = inbox.claim([...active.keys()]);
|
|
135
|
+
if (!entry) break;
|
|
136
|
+
const controller = new AbortController();
|
|
137
|
+
const done = run(entry, controller.signal).finally(() => {
|
|
138
|
+
active.delete(entry.job.id);
|
|
139
|
+
if (!stopping) dispatch();
|
|
140
|
+
changed();
|
|
141
|
+
});
|
|
142
|
+
active.set(entry.job.id, { controller, done });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
dispatch,
|
|
147
|
+
stopWork(id: string) {
|
|
148
|
+
const changed = inbox.stop(id);
|
|
149
|
+
active.get(id)?.controller.abort();
|
|
150
|
+
return changed;
|
|
151
|
+
},
|
|
152
|
+
async close() {
|
|
153
|
+
stopping = true;
|
|
154
|
+
for (const item of active.values()) item.controller.abort();
|
|
155
|
+
await Promise.allSettled([...active.values()].map(item => item.done));
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstatSync, mkdirSync, unlinkSync } from 'node:fs';
|
|
3
|
+
import { connect, createServer, type Socket } from 'node:net';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { createHarnessSession, HarnessRpcClient, runProjectRpc, type Harness } from '@anyswarm/core';
|
|
6
|
+
import { lockPersonalState, privateDirectory, stateDirectory } from './location.js';
|
|
7
|
+
|
|
8
|
+
export async function observe({ cwd, signal }: { cwd: string; signal: AbortSignal }) {
|
|
9
|
+
signal.throwIfAborted();
|
|
10
|
+
const directory = stateDirectory(cwd);
|
|
11
|
+
privateDirectory(directory);
|
|
12
|
+
const socket = connect(join(directory, 'rpc'));
|
|
13
|
+
let code: string | undefined;
|
|
14
|
+
socket.on('error', (error: NodeJS.ErrnoException) => { code = error.code; });
|
|
15
|
+
const session = new HarnessRpcClient({
|
|
16
|
+
stdin: socket, stdout: socket, on: socket.on.bind(socket), off: socket.off.bind(socket),
|
|
17
|
+
}, { timeoutMs: 3000 });
|
|
18
|
+
const close = () => socket.destroy();
|
|
19
|
+
signal.addEventListener('abort', close, { once: true });
|
|
20
|
+
try { await session.ready; }
|
|
21
|
+
catch (error) {
|
|
22
|
+
close();
|
|
23
|
+
signal.throwIfAborted();
|
|
24
|
+
if (code === 'ENOENT' || code === 'ECONNREFUSED') return;
|
|
25
|
+
throw error;
|
|
26
|
+
} finally { signal.removeEventListener('abort', close); }
|
|
27
|
+
return { session, close, traceRoot: join(directory, 'runs') };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function serve(definition: Harness, directory: string, launchDirectory: string, signal: AbortSignal) {
|
|
31
|
+
signal.throwIfAborted();
|
|
32
|
+
const release = lockPersonalState(directory);
|
|
33
|
+
const path = join(directory, 'rpc');
|
|
34
|
+
let session: ReturnType<typeof createHarnessSession> | undefined;
|
|
35
|
+
const clients = new Set<Socket>();
|
|
36
|
+
const server = createServer(socket => {
|
|
37
|
+
clients.add(socket);
|
|
38
|
+
socket.on('error', () => {}).once('close', () => clients.delete(socket));
|
|
39
|
+
const write = (record: unknown) => {
|
|
40
|
+
if (socket.destroyed || socket.writableLength > 1024 * 1024) { socket.destroy(); return Promise.resolve(); }
|
|
41
|
+
return new Promise<void>(done => socket.write(JSON.stringify(record) + '\n', () => done()));
|
|
42
|
+
};
|
|
43
|
+
void runProjectRpc(session!, socket, write, launchDirectory, undefined, { detachOnDisconnect: true })
|
|
44
|
+
.catch(() => {}).finally(() => socket.end());
|
|
45
|
+
});
|
|
46
|
+
server.maxConnections = 16;
|
|
47
|
+
const stop = () => { void session?.stop({ requestId: randomUUID(), reason: 'personal-signal' }).catch(() => {}); };
|
|
48
|
+
try {
|
|
49
|
+
// The ownership lock fences this SDK version. Also recognize a live socket from an older candidate.
|
|
50
|
+
const existing = await observe({ cwd: launchDirectory, signal: AbortSignal.any([signal, AbortSignal.timeout(3500)]) });
|
|
51
|
+
if (existing) { existing.close(); throw new Error('Personal already has a live observer socket.'); }
|
|
52
|
+
try {
|
|
53
|
+
const stat = lstatSync(path);
|
|
54
|
+
if (!stat.isSocket() || stat.uid !== process.getuid?.()) throw new Error('Refusing to replace a foreign Personal socket path.');
|
|
55
|
+
unlinkSync(path);
|
|
56
|
+
} catch (error) { if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error; }
|
|
57
|
+
const cwd = join(directory, 'launch');
|
|
58
|
+
mkdirSync(cwd, { mode: 0o700, recursive: true });
|
|
59
|
+
session = createHarnessSession(definition, {
|
|
60
|
+
launchDirectory: cwd, outputRoot: join(directory, 'reports'), lifetime: 'interactive', stopTimeoutMs: 55_000,
|
|
61
|
+
clientCapabilities: { questions: true },
|
|
62
|
+
});
|
|
63
|
+
signal.throwIfAborted();
|
|
64
|
+
signal.addEventListener('abort', stop, { once: true });
|
|
65
|
+
await session.start({ cwd, prompt: 'Run Personal GitHub inbox.' }, { requestId: randomUUID() });
|
|
66
|
+
await new Promise<void>((resolve, reject) => {
|
|
67
|
+
server.once('error', reject).listen(path, () => {
|
|
68
|
+
server.removeListener('error', reject);
|
|
69
|
+
server.on('error', stop);
|
|
70
|
+
resolve();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
console.error(JSON.stringify({ event: 'personal_listening', at: new Date().toISOString() }));
|
|
74
|
+
const result = await session.completion!;
|
|
75
|
+
console.error(JSON.stringify({ event: 'personal_exit', outcome: result.outcome, reason: result.reason,
|
|
76
|
+
cleanup: result.cleanup.status, at: new Date().toISOString() }));
|
|
77
|
+
} finally {
|
|
78
|
+
signal.removeEventListener('abort', stop);
|
|
79
|
+
if (session?.completion) { stop(); await session.completion.catch(() => {}); }
|
|
80
|
+
const disconnect = setTimeout(() => { for (const socket of clients) socket.destroy(); }, 1000);
|
|
81
|
+
try { await new Promise<void>(done => server.close(() => done())); }
|
|
82
|
+
finally { clearTimeout(disconnect); release(); }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { HarnessContext } from '@anyswarm/core';
|
|
2
|
+
import { digest, type Inbox } from './inbox.js';
|
|
3
|
+
|
|
4
|
+
type Decision = ReturnType<Inbox['decisions']>[number];
|
|
5
|
+
|
|
6
|
+
export function personalDecisions(context: HarnessContext, inbox: Inbox, respond: (decision: Decision, answer: string | boolean, id: string) => void) {
|
|
7
|
+
const cards = new Map<string, AbortController>();
|
|
8
|
+
const shown = new Set<string>();
|
|
9
|
+
const identity = ({ entry, kind }: Decision) => kind + '-' + digest(entry.input.id).slice(0, 16);
|
|
10
|
+
const close = () => { for (const card of cards.values()) card.abort(); cards.clear(); };
|
|
11
|
+
return {
|
|
12
|
+
refresh() {
|
|
13
|
+
if (context.signal.aborted) return;
|
|
14
|
+
const decisions = inbox.decisions();
|
|
15
|
+
const active = new Set(decisions.map(identity));
|
|
16
|
+
for (const [id, card] of cards) if (!active.has(id)) { card.abort(); cards.delete(id); }
|
|
17
|
+
for (const decision of decisions) {
|
|
18
|
+
const id = identity(decision);
|
|
19
|
+
if (shown.has(id)) continue;
|
|
20
|
+
shown.add(id);
|
|
21
|
+
if (shown.size > 4096) shown.delete(shown.values().next().value!);
|
|
22
|
+
const { entry, kind } = decision;
|
|
23
|
+
const selector = '#' + entry.job.thread;
|
|
24
|
+
const delivery = entry.delivery!;
|
|
25
|
+
const prompt = kind === 'publication' ? [
|
|
26
|
+
`Approve the patch for ${selector} (${entry.job.id.slice(0, 8)})?`,
|
|
27
|
+
'Changes: ' + (delivery.artifact?.summary ?? delivery.text.slice(0, 500)),
|
|
28
|
+
'Reviewer: ' + (delivery.artifact?.review ?? 'This saved patch predates recorded Reviewer summaries.'),
|
|
29
|
+
`/approve ${selector} or /reject ${selector} [reason]`,
|
|
30
|
+
].join('\n') : `${selector} · ${delivery.question!.slice(0, 1200)}\n/answer ${selector} <text> or @router ${selector} <text>`;
|
|
31
|
+
context.emit({ kind: 'personal-decision', summary: prompt });
|
|
32
|
+
if (!context.clientCapabilities.questions) continue;
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
cards.set(id, controller);
|
|
35
|
+
void context.askUser({ requestId: id, questionId: id, kind: kind === 'publication' ? 'confirm' : 'text', text: prompt,
|
|
36
|
+
businessRef: { work: entry.job.id, issue: entry.job.thread }, timeoutMs: 3_600_000 },
|
|
37
|
+
{ id, signal: AbortSignal.any([controller.signal, context.signal]) }).then(answer => {
|
|
38
|
+
if (!controller.signal.aborted && !context.signal.aborted) respond(decision, answer, id);
|
|
39
|
+
}).catch(() => {
|
|
40
|
+
// The durable decision remains available through /jobs and the same Slash Actions.
|
|
41
|
+
}).finally(() => { if (cards.get(id) === controller) cards.delete(id); });
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
close,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
createRuntime, recoverRuntime, runInput, ServiceRegistry, inProcessService,
|
|
4
|
+
type AgentInfo, type FileTree, type JsonValue, type Runtime,
|
|
5
|
+
} from '@anyswarm/core';
|
|
6
|
+
import { defaults, runtimeOptions } from './config.js';
|
|
7
|
+
import { reviewerPrompt, routerPrompt, workerPrompt } from './prompts.js';
|
|
8
|
+
import type { WorkBackend } from './coordinator.js';
|
|
9
|
+
|
|
10
|
+
export function personalRuntime(outputDir: string, status: () => JsonValue) {
|
|
11
|
+
const { image, options } = runtimeOptions(outputDir);
|
|
12
|
+
const services = new ServiceRegistry();
|
|
13
|
+
services.register('personal', inProcessService({
|
|
14
|
+
description: 'Bounded work, source and delivery status for the local owner.',
|
|
15
|
+
operations: {
|
|
16
|
+
status: {
|
|
17
|
+
description: 'Read status', sideEffect: 'read', idempotent: true,
|
|
18
|
+
inputSchema: { type: 'object', additionalProperties: false }, outputSchema: { type: 'object' },
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}, { status }, {
|
|
22
|
+
readState: () => ({
|
|
23
|
+
state: status(), capturedAt: new Date().toISOString(),
|
|
24
|
+
presentation: {
|
|
25
|
+
summary: [{ label: 'Repository', path: '/repository' }, { label: 'Source', path: '/source/state' }],
|
|
26
|
+
tables: [{ title: 'Recent work events', path: '/events', columns: [
|
|
27
|
+
{ label: 'Work', path: '/job' }, { label: 'Thread', path: '/thread' },
|
|
28
|
+
{ label: 'Queue', path: '/state' }, { label: 'Result', path: '/result' },
|
|
29
|
+
{ label: 'Reply', path: '/reply' }, { label: 'Problem', path: '/problem' },
|
|
30
|
+
] }],
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
}));
|
|
34
|
+
const profile = (prompt: string, tools: string[], writable = false) => ({
|
|
35
|
+
addedSystemPrompt: prompt, image, model: 'default', writable, tools, services: {},
|
|
36
|
+
});
|
|
37
|
+
const config = { ...options, services, maxAgents: defaults.maxWork * 2, profiles: {
|
|
38
|
+
router: profile(routerPrompt, []),
|
|
39
|
+
worker: profile(workerPrompt, ['read', 'edit', 'write'], true),
|
|
40
|
+
reviewer: profile(reviewerPrompt, ['read']),
|
|
41
|
+
} };
|
|
42
|
+
return {
|
|
43
|
+
durable: Boolean(options.persistence),
|
|
44
|
+
create: () => createRuntime(config),
|
|
45
|
+
async recover(runDirectory: string) {
|
|
46
|
+
if (!options.persistence) return { cleanup: 'pending', reason: 'Set the original durable callback configuration to recover resources.' };
|
|
47
|
+
const runtime = await recoverRuntime({ ...config, runDirectory, cleanupOnly: true });
|
|
48
|
+
return runtime.close({ timeoutMs: 30_000 });
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function memberBackend(runtime: Runtime, members: Map<string, string>): WorkBackend {
|
|
54
|
+
const seed = (files: Record<string, string>): FileTree =>
|
|
55
|
+
Object.fromEntries(Object.entries(files).map(([path, data]) => [path, { encoding: 'utf8', data }]));
|
|
56
|
+
return {
|
|
57
|
+
async open(entry, signal) {
|
|
58
|
+
const spawned = new Set<string>();
|
|
59
|
+
async function spawn(profile: string, files?: FileTree, parentId?: string) {
|
|
60
|
+
signal.throwIfAborted();
|
|
61
|
+
const agent = await runtime.spawn({ profile, files, parentId, requestId: randomUUID() });
|
|
62
|
+
spawned.add(agent.id);
|
|
63
|
+
members.set(agent.id, entry.job.id);
|
|
64
|
+
return agent;
|
|
65
|
+
}
|
|
66
|
+
async function closeMember(id: string) {
|
|
67
|
+
const receipt = await runtime.stop(id, { timeoutMs: 15_000 });
|
|
68
|
+
if (receipt.cleanup === 'complete') {
|
|
69
|
+
spawned.delete(id);
|
|
70
|
+
members.delete(id);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function turn(agent: AgentInfo, input: unknown, turnSignal = signal) {
|
|
74
|
+
signal.throwIfAborted();
|
|
75
|
+
const result = await runInput(runtime, agent.id, JSON.stringify(input), {
|
|
76
|
+
requestId: randomUUID(), signal: turnSignal, timeoutMs: 180_000,
|
|
77
|
+
});
|
|
78
|
+
return result.settled.output ?? (await runtime.get(agent.id)).latestOutput ?? '';
|
|
79
|
+
}
|
|
80
|
+
const router = await spawn('router');
|
|
81
|
+
return {
|
|
82
|
+
route: input => turn(router, input),
|
|
83
|
+
async start(role, text, files) {
|
|
84
|
+
const worker = await spawn(role, seed(files), router.id);
|
|
85
|
+
const controller = new AbortController();
|
|
86
|
+
const turnSignal = AbortSignal.any([signal, controller.signal]);
|
|
87
|
+
let settled = false;
|
|
88
|
+
const result = (async () => {
|
|
89
|
+
try {
|
|
90
|
+
const summary = await turn(worker, { assignment: text, allowedPaths: Object.keys(files) }, turnSignal);
|
|
91
|
+
turnSignal.throwIfAborted();
|
|
92
|
+
if (role === 'reviewer') return { summary };
|
|
93
|
+
const view = await runtime.files.snapshot(worker.id, {
|
|
94
|
+
requestId: randomUUID(), paths: Object.keys(files), maxBytes: defaults.fileBytes * Object.keys(files).length,
|
|
95
|
+
});
|
|
96
|
+
turnSignal.throwIfAborted();
|
|
97
|
+
const exported = Object.fromEntries(Object.keys(files).map(path => {
|
|
98
|
+
const file = view.files[path];
|
|
99
|
+
if (!file || file.mode === 0o755) throw new Error('Worker changed an approved file type or removed it.');
|
|
100
|
+
const text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(Buffer.from(file.data, file.encoding));
|
|
101
|
+
if (text.includes('\0')) throw new Error('Worker output was not text.');
|
|
102
|
+
return [path, text];
|
|
103
|
+
}));
|
|
104
|
+
return { summary, files: exported };
|
|
105
|
+
} finally { settled = true; await closeMember(worker.id); }
|
|
106
|
+
})();
|
|
107
|
+
// A Router may decide to stop without ever waiting for this member.
|
|
108
|
+
void result.catch(() => {});
|
|
109
|
+
return {
|
|
110
|
+
id: worker.id, result,
|
|
111
|
+
async steer(text) {
|
|
112
|
+
if (settled) return 'settled';
|
|
113
|
+
try {
|
|
114
|
+
const receipt = await runtime.send(worker.id, text, { mode: 'steer', wakeIfIdle: false, requestId: randomUUID() });
|
|
115
|
+
return receipt.status === 'accepted' ? receipt.disposition : receipt.status;
|
|
116
|
+
} catch { return 'unavailable'; }
|
|
117
|
+
},
|
|
118
|
+
async stop() {
|
|
119
|
+
controller.abort();
|
|
120
|
+
await result.catch(() => {});
|
|
121
|
+
return spawned.has(worker.id) ? 'cleanup_pending' : 'stopped';
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
async close() {
|
|
126
|
+
await Promise.allSettled([...spawned].reverse().map(closeMember));
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|