@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,4 +1,4 @@
|
|
|
1
|
-
import { ServiceRegistry, createRuntime, runInput, createInputAdmission, ProjectPreflightError, runWithReport } from '@anyswarm/core';
|
|
1
|
+
import { ServiceRegistry, createRuntime, getExecutorCapabilities, runInput, createInputAdmission, ProjectPreflightError, runWithReport } from '@anyswarm/core';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { createSubstrateService } from '../services/substrate.js';
|
|
4
4
|
export const peerPrompt = 'Work as one peer in a fixed pool. Preserve private work between turns. Read and verify any shared contribution before citing it in a new publication.';
|
|
@@ -19,17 +19,60 @@ export function substratePeerProfile({ image, model = 'default', exportLimit = 2
|
|
|
19
19
|
collect: { paths: ['.'], includeGit: false, maxBytes: exportLimit, required: true } };
|
|
20
20
|
}
|
|
21
21
|
/** Fixed no-Task pool. Harness owns content and drivers; Core owns all Agents. */
|
|
22
|
-
export async function runSubstrate({ sandbox, executor, models, connection, filePolicy, runId, image, outputDir, question, model = 'default', poolSize = 3, maxRounds = 2, workTimeoutMs = 120_000, turnTimeoutMs = 30_000, closeTimeoutMs = 30_000, files, onRuntime, beforeCycle, onReady, onCycle, onPeerStop, questionForCycle, maxConcurrentInputs }, signal, run = runWithReport) {
|
|
22
|
+
export async function runSubstrate({ sandbox, executor, models, connection, filePolicy, runId, image, outputDir, question, model = 'default', poolSize = 3, maxRounds = 2, workTimeoutMs = 120_000, turnTimeoutMs = 30_000, closeTimeoutMs = 30_000, files, onRuntime, beforeCycle, onReady, onCycle, onPeerStop, onControl, questionForCycle, maxConcurrentInputs }, signal, run = runWithReport) {
|
|
23
23
|
if (typeof outputDir !== 'string' || !outputDir || typeof question !== 'string' || !question.trim() || Buffer.byteLength(question) > 8192 ||
|
|
24
24
|
typeof image !== 'string' || !image || !Number.isSafeInteger(maxRounds) || maxRounds < 2 || maxRounds > 32 ||
|
|
25
25
|
![workTimeoutMs, turnTimeoutMs, closeTimeoutMs].every(finite) || (signal !== undefined && !(signal instanceof AbortSignal)) ||
|
|
26
26
|
(maxConcurrentInputs !== undefined && (!Number.isSafeInteger(maxConcurrentInputs) || maxConcurrentInputs < 1 || maxConcurrentInputs > poolSize)) ||
|
|
27
|
-
[onRuntime, beforeCycle, onReady, onCycle, onPeerStop, questionForCycle].some((hook) => hook !== undefined && typeof hook !== 'function'))
|
|
27
|
+
[onRuntime, beforeCycle, onReady, onCycle, onPeerStop, onControl, questionForCycle].some((hook) => hook !== undefined && typeof hook !== 'function'))
|
|
28
28
|
throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Substrate requires a question, image, output directory, two to 32 rounds, finite waits and an optional trusted host lifecycle functions');
|
|
29
29
|
const substrate = createSubstrateService({ databasePath: join(outputDir, 'substrate.sqlite'), runId, poolSize });
|
|
30
30
|
const services = new ServiceRegistry();
|
|
31
31
|
services.register('substrate', substrate.service);
|
|
32
32
|
const peers = [], events = [];
|
|
33
|
+
const memberSignals = new Map();
|
|
34
|
+
const heldMembers = new Map();
|
|
35
|
+
async function memberReady(peer) {
|
|
36
|
+
if (peer.held && !peer.stopped) {
|
|
37
|
+
let waiting = heldMembers.get(peer.agentId);
|
|
38
|
+
if (!waiting)
|
|
39
|
+
heldMembers.set(peer.agentId, waiting = Promise.withResolvers());
|
|
40
|
+
await waitFor(waiting.promise, workSignal);
|
|
41
|
+
}
|
|
42
|
+
return !peer.stopped;
|
|
43
|
+
}
|
|
44
|
+
const memberControls = {
|
|
45
|
+
capabilities: {
|
|
46
|
+
send: { supported: getExecutorCapabilities(executor ?? 'pi').activeSteer, text: true, modes: ['steer'] },
|
|
47
|
+
interrupt: { supported: getExecutorCapabilities(executor ?? 'pi').queuedInputCancellation },
|
|
48
|
+
stop: { supported: true },
|
|
49
|
+
},
|
|
50
|
+
handlers: {
|
|
51
|
+
send(agentId, payload, request) {
|
|
52
|
+
const { input, options } = payload;
|
|
53
|
+
return runtime.send(agentId, input, { ...options, requestId: request.operationId });
|
|
54
|
+
},
|
|
55
|
+
async interrupt(agentId, _payload, request) {
|
|
56
|
+
const peer = peers.find(peer => peer.agentId === agentId);
|
|
57
|
+
peer.held = true;
|
|
58
|
+
peer.interventions.push({ kind: 'interrupt', requestId: request.requestId });
|
|
59
|
+
const core = await runtime.interrupt(agentId, { requestId: request.operationId });
|
|
60
|
+
onControl?.({ agentId, kind: 'interrupt', receipt: core, snapshot: substrate.snapshot() });
|
|
61
|
+
return { core, harnessEffects: { held: true, rescheduled: false } };
|
|
62
|
+
},
|
|
63
|
+
async stop(agentId, payload, request) {
|
|
64
|
+
const peer = peers.find(peer => peer.agentId === agentId);
|
|
65
|
+
peer.stopped = true;
|
|
66
|
+
memberSignals.get(agentId)?.abort();
|
|
67
|
+
peer.interventions.push({ kind: 'stop', requestId: request.requestId });
|
|
68
|
+
heldMembers.get(agentId)?.resolve();
|
|
69
|
+
substrate.retirePeer(agentId);
|
|
70
|
+
const core = await runtime.stop(agentId, { requestId: request.operationId, reason: payload?.reason });
|
|
71
|
+
onControl?.({ agentId, kind: 'stop', receipt: core, snapshot: substrate.snapshot() });
|
|
72
|
+
return { core, harnessEffects: { stopped: true, rescheduled: false } };
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
33
76
|
const evidence = () => ({ peers, events, substrate: substrate.snapshot(), databasePath: join(outputDir, 'substrate.sqlite'),
|
|
34
77
|
policy: { poolSize, maxRounds, workTimeoutMs, turnTimeoutMs, closeTimeoutMs, replacement: false,
|
|
35
78
|
ranking: 'token occurrences descending, incoming references descending, stable address ascending', maxSearchResults: 8 } });
|
|
@@ -69,7 +112,7 @@ export async function runSubstrate({ sandbox, executor, models, connection, file
|
|
|
69
112
|
substrate.bindRuntime(core.id);
|
|
70
113
|
const unsubscribe = core.onEvent((event) => events.push({ agentId: event.agentId, seq: events.length + 1, type: event.type, ...(event.outcome ? { outcome: event.outcome } : {}) }));
|
|
71
114
|
try {
|
|
72
|
-
onRuntime?.(core);
|
|
115
|
+
onRuntime?.(core, memberControls);
|
|
73
116
|
for (let index = 0; index < poolSize; index++) {
|
|
74
117
|
remaining();
|
|
75
118
|
const agent = await waitFor(core.spawn({ requestId: `peer:${index}`, profile: 'peer', files: files ?? {
|
|
@@ -77,20 +120,26 @@ export async function runSubstrate({ sandbox, executor, models, connection, file
|
|
|
77
120
|
} }), workSignal);
|
|
78
121
|
remaining();
|
|
79
122
|
substrate.bindPeer(agent.id);
|
|
80
|
-
|
|
123
|
+
memberSignals.set(agent.id, new AbortController());
|
|
124
|
+
peers.push({ index, agentId: agent.id, turns: [], failure: null, stop: null, held: false, stopped: false, interventions: [] });
|
|
81
125
|
}
|
|
82
126
|
if (onReady)
|
|
83
127
|
await waitFor(Promise.resolve().then(() => onReady({ runtime: core, peerIds: peers.map((peer) => peer.agentId), snapshot: substrate.snapshot() })), workSignal);
|
|
84
128
|
remaining();
|
|
85
129
|
await Promise.all(peers.map(async (peer) => {
|
|
130
|
+
const peerSignal = AbortSignal.any([workSignal, memberSignals.get(peer.agentId).signal]);
|
|
86
131
|
try {
|
|
87
132
|
for (let round = 0; round < maxRounds; round++) {
|
|
133
|
+
if (!await memberReady(peer))
|
|
134
|
+
break;
|
|
88
135
|
if (beforeCycle) {
|
|
89
136
|
remaining();
|
|
90
|
-
await waitFor(Promise.resolve().then(() => beforeCycle({ peerIndex: peer.index, agentId: peer.agentId, round, signal:
|
|
137
|
+
await waitFor(Promise.resolve().then(() => beforeCycle({ peerIndex: peer.index, agentId: peer.agentId, round, signal: peerSignal })), peerSignal);
|
|
91
138
|
remaining();
|
|
139
|
+
if (!await memberReady(peer))
|
|
140
|
+
break;
|
|
92
141
|
}
|
|
93
|
-
const cycleQuestion = questionForCycle ? await waitFor(Promise.resolve().then(() => questionForCycle({ peerIndex: peer.index, agentId: peer.agentId, round, signal:
|
|
142
|
+
const cycleQuestion = questionForCycle ? await waitFor(Promise.resolve().then(() => questionForCycle({ peerIndex: peer.index, agentId: peer.agentId, round, signal: peerSignal })), peerSignal) : question;
|
|
94
143
|
if (typeof cycleQuestion !== 'string' || !cycleQuestion.trim() || Buffer.byteLength(cycleQuestion) > 8192)
|
|
95
144
|
throw fail('SUBSTRATE_QUESTION_INVALID');
|
|
96
145
|
const requestId = `${peer.agentId}:cycle:${round}`;
|
|
@@ -113,15 +162,27 @@ export async function runSubstrate({ sandbox, executor, models, connection, file
|
|
|
113
162
|
const left = Math.floor(turnDeadline - performance.now());
|
|
114
163
|
if (left < 1)
|
|
115
164
|
throw fail('SUBSTRATE_CORRECTION_WINDOW_CLOSED');
|
|
116
|
-
return runInput(core, peer.agentId, text, { requestId: currentRequestId, timeoutMs: Math.min(left, remaining()), signal:
|
|
165
|
+
return runInput(core, peer.agentId, text, { requestId: currentRequestId, timeoutMs: Math.min(left, remaining()), signal: peerSignal,
|
|
166
|
+
beforeSend() { if (peer.held || peer.stopped)
|
|
167
|
+
throw fail('SUBSTRATE_MEMBER_HELD'); } });
|
|
117
168
|
};
|
|
118
|
-
|
|
169
|
+
let receipt;
|
|
170
|
+
try {
|
|
171
|
+
receipt = await (admission ? admission.run(sendInput) : sendInput());
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
if (!peer.held && !peer.stopped)
|
|
175
|
+
throw error;
|
|
176
|
+
turn.outcome = peer.stopped ? 'user-stopped' : 'user-interrupted';
|
|
177
|
+
await memberReady(peer);
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
119
180
|
const observed = { requestId: currentRequestId, inputId: receipt.inputId,
|
|
120
181
|
outcome: receipt.settled.outcome, attempt };
|
|
121
182
|
turn.attempts.push(observed);
|
|
122
183
|
Object.assign(turn, { inputId: observed.inputId, outcome: observed.outcome });
|
|
123
184
|
const decision = onCycle ? await waitFor(Promise.resolve().then(() => onCycle({ peerIndex: peer.index,
|
|
124
|
-
agentId: peer.agentId, round, attempt, requestId: currentRequestId, result: receipt, beforeSnapshot, snapshot: substrate.snapshot(), signal:
|
|
185
|
+
agentId: peer.agentId, round, attempt, requestId: currentRequestId, result: receipt, beforeSnapshot, snapshot: substrate.snapshot(), signal: peerSignal, deadlineAtMs: turnDeadline })), peerSignal) : undefined;
|
|
125
186
|
if (decision?.correction === undefined)
|
|
126
187
|
break;
|
|
127
188
|
if (typeof decision.correction !== 'string' || !decision.correction.trim() || Buffer.byteLength(decision.correction) > 4096 ||
|
|
@@ -133,10 +194,12 @@ export async function runSubstrate({ sandbox, executor, models, connection, file
|
|
|
133
194
|
attempt++;
|
|
134
195
|
}
|
|
135
196
|
}
|
|
197
|
+
await memberReady(peer);
|
|
136
198
|
}
|
|
137
199
|
catch (error) {
|
|
138
|
-
|
|
139
|
-
|
|
200
|
+
if (!peer.stopped)
|
|
201
|
+
peer.failure = { code: error.code ?? 'PEER_WORK_FAILED', ...(error.requestId ? { requestId: error.requestId } : {}),
|
|
202
|
+
...(error.inputId ? { inputId: error.inputId } : {}), ...(error.receipt ? { receipt: error.receipt } : {}) };
|
|
140
203
|
}
|
|
141
204
|
finally {
|
|
142
205
|
substrate.retirePeer(peer.agentId);
|
|
@@ -160,6 +223,8 @@ export async function runSubstrate({ sandbox, executor, models, connection, file
|
|
|
160
223
|
throw fail('SUBSTRATE_WORK_ABORTED');
|
|
161
224
|
if (peers.some((peer) => peer.failure))
|
|
162
225
|
throw fail('SUBSTRATE_PEERS_FAILED');
|
|
226
|
+
if (peers.some((peer) => peer.interventions.length))
|
|
227
|
+
throw fail('SUBSTRATE_USER_INTERVENTION');
|
|
163
228
|
return { peerIds: peers.map((peer) => peer.agentId), completedRounds: peers.map((peer) => peer.turns.length) };
|
|
164
229
|
}
|
|
165
230
|
finally {
|
|
@@ -27,12 +27,15 @@ const substrate = {
|
|
|
27
27
|
const result = await runSubstrate({
|
|
28
28
|
sandbox: sandboxHandle, executor: configuration.executor, connection, filePolicy: configuration.filePolicy, models, image, model, poolSize, maxRounds, workTimeoutMs, turnTimeoutMs, closeTimeoutMs,
|
|
29
29
|
runId: context.runId, outputDir: context.outputDir, question: context.input.prompt, files: context.initial.files,
|
|
30
|
-
onRuntime: (runtime
|
|
30
|
+
onRuntime: (runtime, controls) => {
|
|
31
|
+
observation = observeProjectRuntime(runtime, context, () => business, controls);
|
|
32
|
+
},
|
|
31
33
|
onReady: ({ peerIds, snapshot }) => {
|
|
32
34
|
progress({ stage: 'running', peerIds, publication: snapshot });
|
|
33
35
|
context.markRunning();
|
|
34
36
|
},
|
|
35
37
|
onCycle: ({ agentId, round, attempt, snapshot }) => progress({ stage: 'cycle', agentId, round, attempt, publication: snapshot }),
|
|
38
|
+
onControl: (event) => progress({ stage: 'owner-intervention', ...event }),
|
|
36
39
|
onPeerStop: ({ agentId, receipt, snapshot }) => progress({ stage: 'peer-stopped', agentId, receipt, publication: snapshot }),
|
|
37
40
|
}, context.signal, context.runWithRuntime);
|
|
38
41
|
return { ...result, acceptance: { status: 'not-run' },
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Personal
|
|
2
|
+
|
|
3
|
+
Personal receives GitHub Issue and linked PR requests in the background. The user and GitHub inbox address a Router, which assigns scoped Pi Workers and a read-only Reviewer as needed. See [the full Personal requirements](https://github.com/AnySwarm/anyswarm/pull/320).
|
|
4
|
+
|
|
5
|
+
## Connect and start
|
|
6
|
+
|
|
7
|
+
Use Node.js 22.19 or later, Git and an existing Pi/OpenSandbox connection. Run `anys setup --backend pi` for host setup. This candidate's end-to-end acceptance uses Linux. Set `ANYSWARM_MODEL_URL` to the full Responses endpoint and `ANYSWARM_MODEL_ID` to the model ID. Optional `ANYSWARM_MODEL_PROVIDER`, `ANYSWARM_MODEL_TOKEN` and `ANYSWARM_MODEL_HEADERS_JSON` follow the model provider. For a reasoning model outside the built-in model catalog, set `ANYSWARM_MODEL_REASONING=true`. Keep credentials in the host environment or credential manager.
|
|
8
|
+
|
|
9
|
+
Open `anys`, enter `/super`, then use the composer:
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
/setup --repo owner/project --path README.md
|
|
13
|
+
/start
|
|
14
|
+
/jobs
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For scripts, use the same actions through `anys -u super --cmd`, for example `anys -u super --cmd '/jobs #123'`. `/setup` infers the repository from a GitHub `origin` when available and defaults to the authenticated GitHub login and `README.md`. Use repeated `--user` or `--path` to allow other logins or up to eight existing UTF-8 files. Set `ANYSWARM_SUPER_GITHUB_TOKEN` or use an existing GitHub CLI login. Allow Issues and Pull requests read/write for conversations and Contents read for files. Creating or updating a Draft PR also needs Contents and Pull requests write.
|
|
18
|
+
|
|
19
|
+
`/setup` reports the verified GitHub identity, repository, comments and requested files. It validates the local Pi and model configuration and gives the fix for an invalid setting. GitHub reply and PR writes stay unverified until the corresponding operations succeed. `/start` initializes the Runtime. A real work item verifies Worker and model connectivity. `/jobs` and `/logs` show the most recent background failure stage and its repair hint.
|
|
20
|
+
|
|
21
|
+
## Work with the Router
|
|
22
|
+
|
|
23
|
+
Post `/super Update the installation instructions` on an Issue in scope or enter `/ask #123 Update the installation instructions` in the composer. GitHub follows the original Issue or its bound Draft PR. In the terminal, `@router #123 Add a Linux example` sends a follow-up through the same inbox. Use `#<issue>` or an unambiguous work ID prefix in place of `#123` for an existing work item.
|
|
24
|
+
|
|
25
|
+
When the Router asks a question, use `/answer #123 <text>` or answer its decision card. Personal sends the verified patch and Reviewer findings to the local approval card. Use `/approve #123` to let the host publish this patch and post a follow-up receipt. `/reject #123 [reason]` records the rejection locally. Use `--publish` at setup if you want automatic publication for the configured repository. `/jobs [work]` shows the artifact, decisions and reply receipts. `/stop-work <work>` stops a single work item.
|
|
26
|
+
|
|
27
|
+
Type `q` or `/quit` to detach. Use `/stop` to stop the daemon and `/logs` for its log path. `/trace` opens the Trace Viewer at the attached Personal instance's Runtime records. Every Runtime has a bounded model request budget.
|
|
28
|
+
|
|
29
|
+
State is keyed by the launch directory and lives under `$XDG_STATE_HOME/anyswarm/personal` or `~/.local/state/anyswarm/personal`. To reuse state across launch directories, set `ANYSWARM_SUPER_STATE_DIR` to the same absolute, private path. Stop an older candidate before starting a new version against its state. A restart retains tasks, verified artifacts, decisions and pending replies. Unknown GitHub mutations are reconciled by identity. Personal reads a newly linked PR's comments even if it has already advanced the repository cursor during recovery. The original Sandbox can require cleanup after a crash. Same-host recovery uses the original Worker-reachable address and `ANYSWARM_SUPER_CALLBACK_PORT` when set.
|
|
30
|
+
|
|
31
|
+
## Edit your copy
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
anys eject super --dir ./personal-src
|
|
35
|
+
cd ./personal-src
|
|
36
|
+
npm install
|
|
37
|
+
npm run start
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The SDK-bound export includes the TypeScript Harness, Slash Actions and GitHub adapter. `npm run start` opens the shared terminal with the exported module. The same module can run in a foreground process with `anys run ./project.ts --prompt 'Run Personal GitHub inbox'`. The exported and installed daemons use the same state lock. The export contains the application sources and SDK provenance.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { Harness } from '@anyswarm/core';
|
|
2
|
+
import { type PersonalStartupFailure } from './config.js';
|
|
3
|
+
type ActionContext = {
|
|
4
|
+
args: string;
|
|
5
|
+
cwd: string;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
};
|
|
8
|
+
declare function jobs({ args, cwd, signal }: ActionContext): Promise<{
|
|
9
|
+
jobs?: {
|
|
10
|
+
id: string;
|
|
11
|
+
issue: number;
|
|
12
|
+
pull: number | undefined;
|
|
13
|
+
branch: string | undefined;
|
|
14
|
+
waiting: string | undefined;
|
|
15
|
+
artifact: {
|
|
16
|
+
patch: string;
|
|
17
|
+
sha256: string;
|
|
18
|
+
checks: string[];
|
|
19
|
+
summary: string | undefined;
|
|
20
|
+
review: string | undefined;
|
|
21
|
+
} | undefined;
|
|
22
|
+
}[] | undefined;
|
|
23
|
+
events?: {
|
|
24
|
+
id: string;
|
|
25
|
+
job: string;
|
|
26
|
+
thread: number;
|
|
27
|
+
state: "delivered" | "failed" | "prepared" | "queued" | "stopped" | "unknown" | "working";
|
|
28
|
+
problem: string | undefined;
|
|
29
|
+
result: "completed" | "failed" | "waiting" | undefined;
|
|
30
|
+
publish: "approval" | "confirmed" | "queued" | "rejected" | "sending" | "unknown" | undefined;
|
|
31
|
+
reply: "confirmed" | "queued" | "sending" | "unknown" | undefined;
|
|
32
|
+
comment: string | undefined;
|
|
33
|
+
originalComment: string | undefined;
|
|
34
|
+
url: string | undefined;
|
|
35
|
+
rejectionReason: string | undefined;
|
|
36
|
+
}[] | undefined;
|
|
37
|
+
conflicts?: Record<string, import("node:sqlite").SQLOutputValue>[] | undefined;
|
|
38
|
+
state: string;
|
|
39
|
+
settings: import("./config.js").PersonalSettings;
|
|
40
|
+
runId: string | null | undefined;
|
|
41
|
+
live: import("@anyswarm/core").HarnessJson | undefined;
|
|
42
|
+
cleanup: unknown;
|
|
43
|
+
startupFailure: {} | undefined;
|
|
44
|
+
log: string;
|
|
45
|
+
}>;
|
|
46
|
+
export declare function personalActions(definition: Harness): {
|
|
47
|
+
setup: ({ args, cwd, signal }: ActionContext) => Promise<"Configure GitHub with /setup --repo owner/repo [--path README.md] [--user login] [--publish]." | {
|
|
48
|
+
configured: boolean;
|
|
49
|
+
source: string;
|
|
50
|
+
account: string;
|
|
51
|
+
repository: string;
|
|
52
|
+
users: string[];
|
|
53
|
+
paths: string[];
|
|
54
|
+
publish: boolean;
|
|
55
|
+
backend: {
|
|
56
|
+
readonly configuration: 'valid';
|
|
57
|
+
readonly executor: 'pi';
|
|
58
|
+
readonly connectivity: 'unverified';
|
|
59
|
+
} | {
|
|
60
|
+
readonly code: string;
|
|
61
|
+
readonly hint: string;
|
|
62
|
+
readonly executor?: undefined;
|
|
63
|
+
readonly configuration: 'invalid';
|
|
64
|
+
readonly connectivity: 'unverified';
|
|
65
|
+
};
|
|
66
|
+
connection: string;
|
|
67
|
+
github: {
|
|
68
|
+
repositoryRead: string;
|
|
69
|
+
commentRead: string;
|
|
70
|
+
contentRead: string;
|
|
71
|
+
replyWrite: string;
|
|
72
|
+
publicationWrite: string;
|
|
73
|
+
};
|
|
74
|
+
requiredPermissions: string;
|
|
75
|
+
verification: string;
|
|
76
|
+
}>;
|
|
77
|
+
start: ({ args, cwd, signal }: ActionContext) => Promise<{
|
|
78
|
+
state: string;
|
|
79
|
+
repository: string;
|
|
80
|
+
account?: undefined;
|
|
81
|
+
runId?: undefined;
|
|
82
|
+
} | {
|
|
83
|
+
state: string;
|
|
84
|
+
repository: string;
|
|
85
|
+
account: string;
|
|
86
|
+
runId: string | null;
|
|
87
|
+
}>;
|
|
88
|
+
jobs: typeof jobs;
|
|
89
|
+
logs: ({ cwd }: ActionContext) => {
|
|
90
|
+
log: string;
|
|
91
|
+
startupFailure: PersonalStartupFailure | undefined;
|
|
92
|
+
};
|
|
93
|
+
serve?: (({ cwd, signal }: ActionContext) => Promise<void>) | undefined;
|
|
94
|
+
};
|
|
95
|
+
export {};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { execFileSync, spawn } from 'node:child_process';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { closeSync, constants, existsSync, openSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { setTimeout as pause } from 'node:timers/promises';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { parseArgs } from 'node:util';
|
|
8
|
+
import { defaults, inspectBackendConfiguration } from './config.js';
|
|
9
|
+
import { observe, serve } from './daemon.js';
|
|
10
|
+
import { GitHub, githubToken, safePath } from './github.js';
|
|
11
|
+
import { openInbox } from './inbox.js';
|
|
12
|
+
import { loadSettings, lockPersonalState, privateDirectory, stateDirectory } from './location.js';
|
|
13
|
+
async function probe(cwd, shutdown) {
|
|
14
|
+
const signal = AbortSignal.any([shutdown, AbortSignal.timeout(1000)]);
|
|
15
|
+
return observe({ cwd, signal }).catch(() => undefined);
|
|
16
|
+
}
|
|
17
|
+
async function setup(args, cwd, directory, shutdown) {
|
|
18
|
+
const { values } = parseArgs({ args: args.split(/\s+/).filter(Boolean), options: {
|
|
19
|
+
repo: { type: 'string' }, user: { type: 'string', multiple: true }, path: { type: 'string', multiple: true },
|
|
20
|
+
publish: { type: 'boolean' }, 'poll-ms': { type: 'string' },
|
|
21
|
+
} });
|
|
22
|
+
let guessed;
|
|
23
|
+
try {
|
|
24
|
+
const remote = execFileSync('git', ['remote', 'get-url', 'origin'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
25
|
+
guessed = /^(?:https:\/\/github\.com\/|git@github\.com:)([^/]+\/[^/]+?)(?:\.git)?$/.exec(remote)?.[1];
|
|
26
|
+
}
|
|
27
|
+
catch { /* A local Git checkout is optional. */ }
|
|
28
|
+
const repository = values.repo ?? guessed;
|
|
29
|
+
if (!repository)
|
|
30
|
+
return 'Configure GitHub with /setup --repo owner/repo [--path README.md] [--user login] [--publish].';
|
|
31
|
+
const paths = values.path?.length ? [...new Set(values.path)] : ['README.md'];
|
|
32
|
+
const publish = values.publish ?? false;
|
|
33
|
+
if (paths.length > 8 || paths.some(path => !safePath(path) || path === 'personal-output.patch')) {
|
|
34
|
+
throw new Error('Select 1–8 existing text files using repository-relative paths without dot directories.');
|
|
35
|
+
}
|
|
36
|
+
const pollMs = Number(values['poll-ms'] ?? defaults.pollMs);
|
|
37
|
+
if (!Number.isSafeInteger(pollMs) || pollMs < 2000 || pollMs > 300_000)
|
|
38
|
+
throw new Error('Polling interval must be 2000–300000 ms.');
|
|
39
|
+
const signal = AbortSignal.any([shutdown, AbortSignal.timeout(60_000)]);
|
|
40
|
+
const github = new GitHub(repository, githubToken());
|
|
41
|
+
const { account, repo } = await github.inspect(signal);
|
|
42
|
+
const users = [...new Set((values.user ?? [account]).map(user => user.toLowerCase()))];
|
|
43
|
+
if (!users.length || users.length > 20 || users.some(user => !/^[a-z0-9][a-z0-9-]{0,38}$/.test(user))) {
|
|
44
|
+
throw new Error('Set 1–20 valid GitHub user logins.');
|
|
45
|
+
}
|
|
46
|
+
if (publish && repo.permissions?.push === false)
|
|
47
|
+
throw new Error('The authenticated GitHub account needs write access for --publish.');
|
|
48
|
+
const head = await github.head(signal);
|
|
49
|
+
await Promise.all(paths.map(path => github.file(path, head.sha, signal)));
|
|
50
|
+
const release = lockPersonalState(directory);
|
|
51
|
+
try {
|
|
52
|
+
const existing = await observe({ cwd, signal });
|
|
53
|
+
if (existing) {
|
|
54
|
+
existing.close();
|
|
55
|
+
throw new Error('Stop Personal before replacing its settings.');
|
|
56
|
+
}
|
|
57
|
+
const file = join(directory, 'settings.json');
|
|
58
|
+
const before = existsSync(file) ? loadSettings(directory) : undefined;
|
|
59
|
+
if (before && existsSync(join(directory, 'personal.sqlite')) &&
|
|
60
|
+
(JSON.stringify([...before.paths].sort()) !== JSON.stringify([...paths].sort()) ||
|
|
61
|
+
before.account.toLowerCase() !== account.toLowerCase() ||
|
|
62
|
+
JSON.stringify([...before.users].sort()) !== JSON.stringify([...users].sort()))) {
|
|
63
|
+
throw new Error('This state has work under a different account, requester list or file scope. Choose a new state directory for the changed scope.');
|
|
64
|
+
}
|
|
65
|
+
if (before && before.repository.toLowerCase() !== repository.toLowerCase()) {
|
|
66
|
+
throw new Error('This state is associated with another GitHub repository. Choose a new state directory.');
|
|
67
|
+
}
|
|
68
|
+
const temporary = join(directory, 'settings.' + randomUUID() + '.tmp');
|
|
69
|
+
try {
|
|
70
|
+
writeFileSync(temporary, JSON.stringify({
|
|
71
|
+
repository: repo.full_name, account, paths, users, publish, pollMs, since: before?.since ?? new Date().toISOString(),
|
|
72
|
+
}) + '\n', { flag: 'wx', mode: 0o600 });
|
|
73
|
+
renameSync(temporary, file);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
if (existsSync(temporary))
|
|
77
|
+
unlinkSync(temporary);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
release();
|
|
82
|
+
}
|
|
83
|
+
const backend = inspectBackendConfiguration(join(directory, 'runs'));
|
|
84
|
+
return { configured: true, source: 'GitHub', account, repository: repo.full_name, users, paths, publish, backend,
|
|
85
|
+
connection: 'repository and comment read verified',
|
|
86
|
+
github: { repositoryRead: 'verified', commentRead: 'verified', contentRead: 'verified', replyWrite: 'unverified',
|
|
87
|
+
publicationWrite: repo.permissions?.push === false ? 'repository-push-denied' : 'unverified' },
|
|
88
|
+
requiredPermissions: publish ? 'Issues and Pull requests: read/write; Contents: read/write'
|
|
89
|
+
: 'Issues and Pull requests: read/write; Contents: read',
|
|
90
|
+
verification: 'After the backend configuration is valid, /start initializes the Runtime. A real work item verifies Worker, model and reply connectivity. An approved publication verifies PR write access.' };
|
|
91
|
+
}
|
|
92
|
+
function directoryFor(cwd) {
|
|
93
|
+
const directory = stateDirectory(cwd);
|
|
94
|
+
privateDirectory(directory);
|
|
95
|
+
return directory;
|
|
96
|
+
}
|
|
97
|
+
function lastStartupFailure(directory) {
|
|
98
|
+
const inbox = existsSync(join(directory, 'personal.sqlite')) ? openInbox(directory, true) : undefined;
|
|
99
|
+
try {
|
|
100
|
+
return inbox?.get('startupFailure') ?? undefined;
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
inbox?.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async function start(cwd, directory, signal) {
|
|
107
|
+
const settings = loadSettings(directory);
|
|
108
|
+
const previous = await probe(cwd, signal);
|
|
109
|
+
if (previous) {
|
|
110
|
+
previous.close();
|
|
111
|
+
return { state: 'already_running', repository: settings.repository };
|
|
112
|
+
}
|
|
113
|
+
signal.throwIfAborted();
|
|
114
|
+
const backend = inspectBackendConfiguration(join(directory, 'runs'));
|
|
115
|
+
if (backend.configuration === 'invalid')
|
|
116
|
+
throw new Error(backend.hint);
|
|
117
|
+
githubToken();
|
|
118
|
+
const launchId = randomUUID();
|
|
119
|
+
const log = openSync(join(directory, 'daemon.log'), constants.O_WRONLY | constants.O_APPEND | constants.O_CREAT | constants.O_NOFOLLOW, 0o600);
|
|
120
|
+
let failure = false;
|
|
121
|
+
let exited = false;
|
|
122
|
+
try {
|
|
123
|
+
const cli = fileURLToPath(new URL('../../scripts/anyswarm.js', import.meta.resolve('@anyswarm/core')));
|
|
124
|
+
const project = fileURLToPath(new URL('./project.js', import.meta.url));
|
|
125
|
+
const entry = existsSync(project) ? project : fileURLToPath(new URL('./project.ts', import.meta.url));
|
|
126
|
+
const child = spawn(process.execPath, [cli, '-u', entry, '--cmd', '/serve'], {
|
|
127
|
+
cwd, detached: true, stdio: ['ignore', log, log],
|
|
128
|
+
env: { ...process.env, ANYSWARM_PERSONAL_DAEMON: '1', ANYSWARM_SUPER_STATE_DIR: directory, ANYSWARM_PERSONAL_LAUNCH: launchId },
|
|
129
|
+
});
|
|
130
|
+
child.on('error', () => { failure = true; });
|
|
131
|
+
child.on('exit', () => { exited = true; });
|
|
132
|
+
child.unref();
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
closeSync(log);
|
|
136
|
+
}
|
|
137
|
+
for (let attempt = 0; !failure && !exited && attempt < 80; attempt++) {
|
|
138
|
+
signal.throwIfAborted();
|
|
139
|
+
const client = await probe(cwd, signal);
|
|
140
|
+
if (client) {
|
|
141
|
+
try {
|
|
142
|
+
const state = await client.session.getState();
|
|
143
|
+
if (state.phase === 'running')
|
|
144
|
+
return { state: 'running', repository: settings.repository, account: settings.account, runId: state.runId };
|
|
145
|
+
if (state.phase === 'finished')
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// The daemon may finish and close its observer between attach and getState.
|
|
150
|
+
signal.throwIfAborted();
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
client.close();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
await pause(250, undefined, { signal });
|
|
157
|
+
}
|
|
158
|
+
const diagnostic = lastStartupFailure(directory);
|
|
159
|
+
if (diagnostic?.launchId === launchId)
|
|
160
|
+
throw new Error(`${diagnostic.phase}: ${diagnostic.hint}`);
|
|
161
|
+
if (failure)
|
|
162
|
+
throw new Error('Personal could not launch its background process. Check the Node installation and /logs.');
|
|
163
|
+
throw new Error('Personal did not become ready. Use /jobs and /logs for diagnostics.');
|
|
164
|
+
}
|
|
165
|
+
async function jobs({ args, cwd, signal }) {
|
|
166
|
+
const directory = directoryFor(cwd);
|
|
167
|
+
const settings = loadSettings(directory);
|
|
168
|
+
const client = await probe(cwd, signal);
|
|
169
|
+
try {
|
|
170
|
+
const state = await client?.session.getState();
|
|
171
|
+
const inbox = existsSync(join(directory, 'personal.sqlite')) ? openInbox(directory, true) : undefined;
|
|
172
|
+
try {
|
|
173
|
+
const status = inbox?.status(64, args || undefined);
|
|
174
|
+
if (args && !status?.jobs.length)
|
|
175
|
+
throw new Error('No Personal work found for that work ID or Issue.');
|
|
176
|
+
return { state: state?.phase ?? 'stopped', settings, runId: state?.runId,
|
|
177
|
+
live: args ? undefined : state?.business, ...status, cleanup: inbox?.get('cleanup'),
|
|
178
|
+
startupFailure: inbox?.get('startupFailure') ?? undefined, log: join(directory, 'daemon.log') };
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
inbox?.close();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
client?.close();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function send(command, { args, cwd, signal }) {
|
|
189
|
+
const client = await probe(cwd, signal);
|
|
190
|
+
if (!client) {
|
|
191
|
+
signal.throwIfAborted();
|
|
192
|
+
if (command === 'stop')
|
|
193
|
+
return { state: 'stopped', verification: 'Use /jobs for the last cleanup receipt.' };
|
|
194
|
+
throw new Error('Start Personal with /start first.');
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const request = { requestId: randomUUID() };
|
|
198
|
+
if (command === 'stop') {
|
|
199
|
+
if (args)
|
|
200
|
+
throw new Error('Use /stop to stop Personal or /stop-work <work> to stop one work item.');
|
|
201
|
+
const completion = client.session.completion;
|
|
202
|
+
const receipt = await client.session.stop({ ...request, reason: 'owner_stop' });
|
|
203
|
+
const result = await completion;
|
|
204
|
+
return { state: 'stopped', receipt, cleanup: result?.cleanup ?? { status: 'pending' } };
|
|
205
|
+
}
|
|
206
|
+
const receipt = await client.session.input(`/${command} ${args}`, request);
|
|
207
|
+
return receipt;
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
client.close();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
export function personalActions(definition) {
|
|
214
|
+
const commands = ['ask', 'answer', 'stop-work', 'approve', 'reject', 'stop'];
|
|
215
|
+
return {
|
|
216
|
+
setup: ({ args, cwd, signal }) => setup(args, cwd, directoryFor(cwd), signal),
|
|
217
|
+
start: ({ args, cwd, signal }) => {
|
|
218
|
+
if (args)
|
|
219
|
+
throw new Error('Use /start without arguments.');
|
|
220
|
+
return start(cwd, directoryFor(cwd), signal);
|
|
221
|
+
},
|
|
222
|
+
jobs,
|
|
223
|
+
logs: ({ cwd }) => {
|
|
224
|
+
const directory = directoryFor(cwd);
|
|
225
|
+
return { log: join(directory, 'daemon.log'), startupFailure: lastStartupFailure(directory) };
|
|
226
|
+
},
|
|
227
|
+
...Object.fromEntries(commands.map(command => [command, (context) => send(command, context)])),
|
|
228
|
+
...(process.env.ANYSWARM_PERSONAL_DAEMON === '1' && { serve: ({ cwd, signal }) => serve(definition, directoryFor(cwd), cwd, signal) }),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { mkdir, mkdtemp, rm, writeFile, rename } from 'node:fs/promises';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { promisify } from 'node:util';
|
|
5
|
+
import { digest } from './inbox.js';
|
|
6
|
+
const exec = promisify(execFile);
|
|
7
|
+
export function githubProject(directory, github, settings) {
|
|
8
|
+
return {
|
|
9
|
+
async baseline(entry, signal) {
|
|
10
|
+
const base = entry.job.last?.base ?? (await github.head(signal)).sha;
|
|
11
|
+
const files = Object.fromEntries(await Promise.all(settings.paths.map(async (path) => [path, await github.file(path, base, signal)])));
|
|
12
|
+
return { base, files };
|
|
13
|
+
},
|
|
14
|
+
async export(entry, baseline, files) {
|
|
15
|
+
const root = join(directory, 'artifacts');
|
|
16
|
+
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
17
|
+
const scratch = await mkdtemp(join(root, '.stage-'));
|
|
18
|
+
const env = {
|
|
19
|
+
PATH: process.env.PATH, LANG: 'C', GIT_CONFIG_NOSYSTEM: '1', GIT_CONFIG_GLOBAL: '/dev/null',
|
|
20
|
+
};
|
|
21
|
+
const git = async (...args) => (await exec('git', ['-c', 'core.autocrlf=false', ...args], { cwd: scratch, env, timeout: 10_000, maxBuffer: 8 * 1024 * 1024 })).stdout;
|
|
22
|
+
async function write(tree) {
|
|
23
|
+
for (const [path, text] of Object.entries(tree)) {
|
|
24
|
+
const target = join(scratch, path);
|
|
25
|
+
await mkdir(dirname(target), { recursive: true, mode: 0o700 });
|
|
26
|
+
await writeFile(target, text, { mode: 0o600 });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
await git('init', '-q');
|
|
31
|
+
await write(baseline.files);
|
|
32
|
+
await git('add', '--', ...settings.paths);
|
|
33
|
+
await write(files);
|
|
34
|
+
await git('diff', '--check');
|
|
35
|
+
const diff = await git('diff', '--no-ext-diff', '--no-textconv', '--binary');
|
|
36
|
+
const summary = (await git('diff', '--no-ext-diff', '--no-textconv', '--stat')).trim();
|
|
37
|
+
const name = digest(entry.input.id).slice(0, 24) + '.patch';
|
|
38
|
+
const patch = join(root, name);
|
|
39
|
+
await writeFile(join(scratch, 'personal-output.patch'), diff, { mode: 0o600 });
|
|
40
|
+
if (diff)
|
|
41
|
+
await git('apply', '--cached', '--check', '--', 'personal-output.patch');
|
|
42
|
+
await rename(join(scratch, 'personal-output.patch'), patch);
|
|
43
|
+
return { base: baseline.base, files, patch, sha256: digest(diff), summary,
|
|
44
|
+
checks: ['git diff --check: passed', ...(diff ? ['git apply --check against pinned base: passed'] : ['Patch is empty against pinned base.'])] };
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
await rm(scratch, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|