@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
|
@@ -9,26 +9,53 @@ export type LocalCommand = {
|
|
|
9
9
|
configPath?: string;
|
|
10
10
|
backend?: 'pi' | 'codex';
|
|
11
11
|
backendPath?: string;
|
|
12
|
+
backendVersion?: string;
|
|
12
13
|
} | {
|
|
13
14
|
command: 'doctor';
|
|
14
15
|
configPath?: string;
|
|
15
16
|
smoke: boolean;
|
|
16
17
|
};
|
|
17
|
-
|
|
18
|
-
command: 'harness';
|
|
18
|
+
type HarnessOptions = {
|
|
19
19
|
harness: string;
|
|
20
20
|
configPath?: string;
|
|
21
21
|
outputRoot?: string;
|
|
22
22
|
lifetime?: 'task' | 'interactive';
|
|
23
23
|
interaction?: 'none' | 'questions';
|
|
24
|
+
};
|
|
25
|
+
export type ProjectCommand = HarnessOptions & {
|
|
26
|
+
command: 'harness';
|
|
27
|
+
defaults?: boolean;
|
|
24
28
|
} & ({
|
|
25
|
-
mode: 'foreground';
|
|
29
|
+
mode: 'foreground' | 'headless';
|
|
26
30
|
cwd?: string;
|
|
27
31
|
prompt: string;
|
|
28
32
|
} | {
|
|
29
33
|
mode: 'rpc';
|
|
30
34
|
});
|
|
31
|
-
type
|
|
35
|
+
export type TuiCommand = Partial<HarnessOptions> & {
|
|
36
|
+
command: 'tui';
|
|
37
|
+
cwd?: string;
|
|
38
|
+
prompt?: string;
|
|
39
|
+
};
|
|
40
|
+
export type HarnessCommand = HarnessOptions & {
|
|
41
|
+
command: 'use';
|
|
42
|
+
cwd?: string;
|
|
43
|
+
prompt?: string;
|
|
44
|
+
} & ({
|
|
45
|
+
mode: 'auto' | 'tui' | 'headless' | 'foreground' | 'rpc';
|
|
46
|
+
} | {
|
|
47
|
+
mode: 'action';
|
|
48
|
+
slash: string;
|
|
49
|
+
});
|
|
50
|
+
type AnySwarmCommand = TuiCommand | HarnessCommand | {
|
|
51
|
+
command: 'run';
|
|
52
|
+
entryPath: string;
|
|
53
|
+
args: string[];
|
|
54
|
+
} | {
|
|
55
|
+
command: 'eject';
|
|
56
|
+
application: string;
|
|
57
|
+
directory: string;
|
|
58
|
+
} | LocalCommand | {
|
|
32
59
|
command: 'update';
|
|
33
60
|
archive?: string;
|
|
34
61
|
sha256?: string;
|
|
@@ -37,7 +64,10 @@ type AnySwarmCommand = LocalCommand | {
|
|
|
37
64
|
directory: string;
|
|
38
65
|
configPath: string;
|
|
39
66
|
};
|
|
40
|
-
export declare function
|
|
67
|
+
export declare function isLocalHarness(specifier: string): boolean;
|
|
68
|
+
export declare function isHarnessName(specifier: string): boolean;
|
|
69
|
+
export declare function parseHarnessSelection(args: string[], selected?: string): HarnessCommand;
|
|
70
|
+
export declare function parseAnySwarmCommand(args: string[], registered?: Readonly<Record<string, string>>): AnySwarmCommand | {
|
|
41
71
|
help: string;
|
|
42
72
|
};
|
|
43
73
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
2
|
export const setupUsage = [
|
|
3
|
-
'Usage: anyswarm setup [--mode existing|local] [--endpoint <url>] [--public-url <url>] [--backend pi|codex] [--backend-path <executable>] [--config <module>]',
|
|
3
|
+
'Usage: anyswarm setup [--mode existing|local] [--endpoint <url>] [--public-url <url>] [--backend pi|codex] [--backend-path <executable>] [--backend-version <version>] [--config <module>]',
|
|
4
4
|
'Without --mode, reuse a saved managed local service or a configured connection. With no connection, prepare local OpenSandbox.',
|
|
5
5
|
'Existing mode saves the authenticated connection. Run anyswarm doctor --smoke to verify Worker and Runtime callbacks.',
|
|
6
6
|
].join('\n');
|
|
@@ -14,60 +14,122 @@ const projectUsage = [
|
|
|
14
14
|
'Usage: anyswarm --harness <module> --prompt <text> [--cwd <directory>] [--config <module>] [--output-dir <directory>] [--lifetime task|interactive] [--interaction none|questions]',
|
|
15
15
|
' anyswarm --harness <module> --mode rpc [--config <module>] [--output-dir <directory>] [--lifetime task|interactive] [--interaction none|questions]',
|
|
16
16
|
'Built-in Harnesses: subagents, taskpool, peermesh, substrate, lead-worker, notes, messages',
|
|
17
|
-
'Use a built-in name, an explicit
|
|
17
|
+
'Use a built-in name, an explicit TypeScript or ESM file, or a package installed from the invocation directory.',
|
|
18
18
|
'An explicit interactive lifetime or questions in foreground mode uses JSONL for subsequent commands.',
|
|
19
19
|
'The project directory defaults to the invocation directory. In RPC mode send cwd and prompt in the run request.',
|
|
20
20
|
].join('\n');
|
|
21
21
|
export const anyswarmUsage = [
|
|
22
|
-
'Usage: anyswarm
|
|
22
|
+
'Usage: anyswarm | anys Open the streaming TUI',
|
|
23
|
+
'Usage: anys -u <harness> [prompt] [--headless | --rpc]',
|
|
24
|
+
' anys -u <harness> --cmd "/action [arguments]"',
|
|
25
|
+
'Harness options: --config <module>, --cwd <directory>, --output-dir <directory>, --lifetime task|interactive',
|
|
26
|
+
' anys run <harness> [prompt] Local source files can also accept script arguments',
|
|
27
|
+
'Usage: anys eject <application> --dir <directory>',
|
|
23
28
|
'Usage: anyswarm --version',
|
|
24
29
|
projectUsage, setupUsage, updateUsage, doctorUsage, recoverUsage,
|
|
25
30
|
'Usage: anyswarm trace --root <runs-dir> [--port 8787] [--open]',
|
|
26
31
|
].join('\n');
|
|
27
|
-
export function
|
|
32
|
+
export function isLocalHarness(specifier) {
|
|
33
|
+
return specifier.startsWith('./') || specifier.startsWith('../') || specifier.startsWith('/');
|
|
34
|
+
}
|
|
35
|
+
export function isHarnessName(specifier) {
|
|
36
|
+
return /^(?:@[a-z0-9_.-]+\/)?[a-z0-9][a-z0-9_.-]*$/i.test(specifier);
|
|
37
|
+
}
|
|
38
|
+
function parseHarnessOptions(args, allowPositionals) {
|
|
39
|
+
const { values, positionals } = parseArgs({ args, allowPositionals, options: {
|
|
40
|
+
use: { type: 'string', short: 'u' }, harness: { type: 'string' }, prompt: { type: 'string' },
|
|
41
|
+
cwd: { type: 'string' }, mode: { type: 'string' }, config: { type: 'string' }, 'output-dir': { type: 'string' },
|
|
42
|
+
lifetime: { type: 'string' }, interaction: { type: 'string' },
|
|
43
|
+
headless: { type: 'boolean' }, rpc: { type: 'boolean' }, cmd: { type: 'string' },
|
|
44
|
+
} });
|
|
45
|
+
const { lifetime, interaction } = values;
|
|
46
|
+
if ([values.use, values.harness, values.cwd, values.config, values['output-dir']].includes('') ||
|
|
47
|
+
(lifetime !== undefined && lifetime !== 'task' && lifetime !== 'interactive') ||
|
|
48
|
+
(interaction !== undefined && interaction !== 'none' && interaction !== 'questions'))
|
|
49
|
+
throw new Error();
|
|
50
|
+
return { values, positionals, options: { configPath: values.config, outputRoot: values['output-dir'], lifetime, interaction } };
|
|
51
|
+
}
|
|
52
|
+
export function parseHarnessSelection(args, selected) {
|
|
53
|
+
const { values, positionals, options } = parseHarnessOptions(args, true);
|
|
54
|
+
const harness = selected ?? values.use;
|
|
55
|
+
if (!harness || values.harness !== undefined || (selected && values.use !== undefined) ||
|
|
56
|
+
(positionals.length && values.prompt !== undefined))
|
|
57
|
+
throw new Error(anyswarmUsage);
|
|
58
|
+
const prompt = values.prompt ?? (positionals.length ? positionals.join(' ') : undefined);
|
|
59
|
+
if (prompt !== undefined && !prompt.trim())
|
|
60
|
+
throw new Error(anyswarmUsage);
|
|
61
|
+
const project = { command: 'use', harness, ...options, prompt, cwd: values.cwd };
|
|
62
|
+
if ([values.mode, values.headless, values.rpc, values.cmd].filter(value => value !== undefined).length > 1)
|
|
63
|
+
throw new Error(anyswarmUsage);
|
|
64
|
+
const mode = values.mode ?? (values.headless ? 'headless' : values.rpc ? 'rpc' : 'auto');
|
|
65
|
+
if (values.cmd !== undefined) {
|
|
66
|
+
if (prompt !== undefined || !/^\/[a-z][\w-]*(?:\s|$)/i.test(values.cmd.trim()))
|
|
67
|
+
throw new Error(anyswarmUsage);
|
|
68
|
+
return { ...project, mode: 'action', slash: values.cmd.trim() };
|
|
69
|
+
}
|
|
70
|
+
if (mode === 'rpc' && (prompt !== undefined || values.cwd !== undefined))
|
|
71
|
+
throw new Error(anyswarmUsage);
|
|
72
|
+
if (mode === 'auto' || mode === 'tui' || mode === 'headless' || mode === 'foreground' || mode === 'rpc')
|
|
73
|
+
return { ...project, mode };
|
|
74
|
+
throw new Error(anyswarmUsage);
|
|
75
|
+
}
|
|
76
|
+
export function parseAnySwarmCommand(args, registered = {}) {
|
|
28
77
|
const [command, ...options] = args;
|
|
29
78
|
if (command === undefined)
|
|
30
|
-
return {
|
|
79
|
+
return { command: 'tui' };
|
|
31
80
|
if (command === '--help' && options.length === 0)
|
|
32
81
|
return { help: anyswarmUsage };
|
|
33
|
-
const usages = { setup: setupUsage, update: updateUsage, doctor: doctorUsage, recover: recoverUsage };
|
|
82
|
+
const usages = { run: 'Usage: anys run <harness> [prompt or source arguments]', eject: 'Usage: anys eject <application> --dir <directory>', setup: setupUsage, update: updateUsage, doctor: doctorUsage, recover: recoverUsage };
|
|
34
83
|
const usage = Object.hasOwn(usages, command) ? usages[command] : anyswarmUsage;
|
|
35
|
-
if (options.length === 1 && options[0] === '--help' &&
|
|
84
|
+
if (options.length === 1 && options[0] === '--help' && Object.hasOwn(usages, command))
|
|
36
85
|
return { help: usage };
|
|
37
86
|
try {
|
|
87
|
+
if (command === 'run') {
|
|
88
|
+
if (!options[0] || options[0].startsWith('-'))
|
|
89
|
+
throw new Error();
|
|
90
|
+
return isLocalHarness(options[0]) || /^[^@]+\.(?:[cm]?[jt]s)$/.test(options[0])
|
|
91
|
+
? { command, entryPath: options[0], args: options.slice(1) }
|
|
92
|
+
: parseHarnessSelection(options.slice(1), options[0]);
|
|
93
|
+
}
|
|
94
|
+
if (command === 'eject') {
|
|
95
|
+
const { values, positionals } = parseArgs({ args: options, allowPositionals: true, options: { dir: { type: 'string' } } });
|
|
96
|
+
if (positionals.length === 1 && isHarnessName(positionals[0]) && !positionals[0].includes('/') && values.dir) {
|
|
97
|
+
return { command, application: positionals[0], directory: values.dir };
|
|
98
|
+
}
|
|
99
|
+
throw new Error();
|
|
100
|
+
}
|
|
101
|
+
if (command === '-u' || command.startsWith('-u=') || command === '--use' || command.startsWith('--use=')) {
|
|
102
|
+
return parseHarnessSelection(args);
|
|
103
|
+
}
|
|
38
104
|
if (command.startsWith('--')) {
|
|
39
|
-
const { values } =
|
|
40
|
-
|
|
41
|
-
mode: { type: 'string' }, config: { type: 'string' }, 'output-dir': { type: 'string' },
|
|
42
|
-
lifetime: { type: 'string' }, interaction: { type: 'string' },
|
|
43
|
-
} });
|
|
44
|
-
if (!values.harness || values.config === '' || values['output-dir'] === '')
|
|
105
|
+
const { values, options: selection } = parseHarnessOptions(args, false);
|
|
106
|
+
if (values.cmd !== undefined || values.headless !== undefined || values.rpc !== undefined || values.use !== undefined)
|
|
45
107
|
throw new Error();
|
|
46
|
-
const {
|
|
47
|
-
if (
|
|
48
|
-
|
|
108
|
+
const project = { command: 'harness', harness: values.harness, ...selection };
|
|
109
|
+
if (values.mode === 'tui' || (values.mode === undefined && values.prompt === undefined)) {
|
|
110
|
+
return { ...project, command: 'tui', harness: values.harness, cwd: values.cwd, prompt: values.prompt };
|
|
111
|
+
}
|
|
112
|
+
if (!project.harness)
|
|
49
113
|
throw new Error();
|
|
50
|
-
const project = { command: 'harness', harness: values.harness, configPath: values.config,
|
|
51
|
-
outputRoot: values['output-dir'],
|
|
52
|
-
lifetime: lifetime, interaction: interaction };
|
|
53
114
|
if (values.mode === 'rpc' && values.prompt === undefined && values.cwd === undefined)
|
|
54
115
|
return { ...project, mode: 'rpc' };
|
|
55
|
-
if (values.mode === undefined
|
|
116
|
+
if ((values.mode === undefined || values.mode === 'foreground') && values.prompt?.trim()) {
|
|
56
117
|
return { ...project, mode: 'foreground', cwd: values.cwd, prompt: values.prompt };
|
|
57
118
|
}
|
|
58
119
|
}
|
|
59
120
|
if (command === 'setup') {
|
|
60
121
|
const { values } = parseArgs({ args: options, options: {
|
|
61
122
|
mode: { type: 'string' }, endpoint: { type: 'string' }, 'public-url': { type: 'string' }, config: { type: 'string' },
|
|
62
|
-
backend: { type: 'string' }, 'backend-path': { type: 'string' },
|
|
123
|
+
backend: { type: 'string' }, 'backend-path': { type: 'string' }, 'backend-version': { type: 'string' },
|
|
63
124
|
} });
|
|
64
125
|
const { backend, mode } = values;
|
|
65
126
|
if (values.config !== '' && values.endpoint !== '' && values['public-url'] !== '' &&
|
|
66
127
|
(mode === undefined || mode === 'existing' || mode === 'local') &&
|
|
67
128
|
(backend === undefined || backend === 'pi' || backend === 'codex') &&
|
|
68
|
-
(values['backend-path'] === undefined || (backend && values['backend-path']))
|
|
129
|
+
(values['backend-path'] === undefined || (backend && values['backend-path'])) &&
|
|
130
|
+
(values['backend-version'] === undefined || (backend && values['backend-version']))) {
|
|
69
131
|
return { command, mode, endpoint: values.endpoint, publicUrl: values['public-url'], configPath: values.config,
|
|
70
|
-
backend, backendPath: values['backend-path'] };
|
|
132
|
+
backend, backendPath: values['backend-path'], backendVersion: values['backend-version'] };
|
|
71
133
|
}
|
|
72
134
|
}
|
|
73
135
|
if (command === 'update') {
|
|
@@ -88,6 +150,8 @@ export function parseAnySwarmCommand(args) {
|
|
|
88
150
|
if (values.config !== '')
|
|
89
151
|
return { command, configPath: values.config, smoke: values.smoke === true };
|
|
90
152
|
}
|
|
153
|
+
if (Object.hasOwn(registered, command))
|
|
154
|
+
return parseHarnessSelection(options, command);
|
|
91
155
|
}
|
|
92
156
|
catch {
|
|
93
157
|
// Argument errors can contain untrusted input. Print only the command usage.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { realpath } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
export async function runSourceCommand(command, cwd) {
|
|
6
|
+
const entry = await realpath(resolve(cwd, command.entryPath));
|
|
7
|
+
const runner = fileURLToPath(new URL('./anyswarm-source-runner.js', import.meta.url));
|
|
8
|
+
const child = spawn(process.execPath, ['--enable-source-maps', runner, entry, ...command.args], { cwd, stdio: 'inherit' });
|
|
9
|
+
const interrupt = () => { child.kill('SIGINT'); };
|
|
10
|
+
const terminate = () => { child.kill('SIGTERM'); };
|
|
11
|
+
process.on('SIGINT', interrupt);
|
|
12
|
+
process.on('SIGTERM', terminate);
|
|
13
|
+
try {
|
|
14
|
+
return await new Promise((done, reject) => {
|
|
15
|
+
child.once('error', reject);
|
|
16
|
+
child.once('exit', (code, signal) => done(code ?? (signal === 'SIGINT' ? 130 : signal === 'SIGTERM' ? 143 : 1)));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
process.off('SIGINT', interrupt);
|
|
21
|
+
process.off('SIGTERM', terminate);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export { ejectSourceCommand } from './anyswarm-eject.js';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Export an application's explicit source allowlist and its installed SDK identity. */
|
|
2
|
+
export declare function ejectSourceCommand(command: {
|
|
3
|
+
application: string;
|
|
4
|
+
directory: string;
|
|
5
|
+
}, cwd: string): Promise<{
|
|
6
|
+
directory: string;
|
|
7
|
+
entryPath: string;
|
|
8
|
+
provenancePath: string;
|
|
9
|
+
}>;
|
|
10
|
+
/** Verify the executing host and return a guard for SDK resolutions inside a source export. */
|
|
11
|
+
export declare function verifyExportedSdk(entry: string): Promise<((url: string) => void) | undefined>;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { cp, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { findPackageJSON } from 'node:module';
|
|
6
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { promisify } from 'node:util';
|
|
9
|
+
const execute = promisify(execFile);
|
|
10
|
+
const packageRoot = fileURLToPath(new URL('../..', import.meta.url));
|
|
11
|
+
const forbidden = /(?:^|\/)(?:\.env(?:\..*)?|node_modules|dist|runs?|experiments|\.git|\.anyswarm(?:-sdk)?)(?:\/|$)|\.(?:db|sqlite|sqlite3|log|ndjson|pem|key)$/i;
|
|
12
|
+
const reserved = new Set(['package.json', 'anyswarm-source.json']);
|
|
13
|
+
const packageSpecifier = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9_.-]+$/;
|
|
14
|
+
function digestFiles(directory, files) {
|
|
15
|
+
const hash = createHash('sha256');
|
|
16
|
+
for (const file of [...files].sort((left, right) => left.localeCompare(right, 'en'))) {
|
|
17
|
+
const data = readFileSync(join(directory, file));
|
|
18
|
+
hash.update(file).update('\0').update(String(data.length)).update('\0').update(data);
|
|
19
|
+
}
|
|
20
|
+
return hash.digest('hex');
|
|
21
|
+
}
|
|
22
|
+
async function installationSource() {
|
|
23
|
+
const lock = await readFile(resolve(packageRoot, '../../.package-lock.json'), 'utf8').then(JSON.parse).catch(() => undefined);
|
|
24
|
+
const installed = lock?.packages?.['node_modules/@anyswarm/core'];
|
|
25
|
+
return { source: typeof installed?.resolved === 'string' ? installed.resolved : 'installed-package-content',
|
|
26
|
+
integrity: typeof installed?.integrity === 'string' ? installed.integrity : null };
|
|
27
|
+
}
|
|
28
|
+
/** Export an application's explicit source allowlist and its installed SDK identity. */
|
|
29
|
+
export async function ejectSourceCommand(command, cwd) {
|
|
30
|
+
if (!/^[a-z0-9][a-z0-9_.-]*$/i.test(command.application))
|
|
31
|
+
throw new TypeError('Expected a bundled application name');
|
|
32
|
+
const application = command.application === 'example' ? 'authoring' : command.application;
|
|
33
|
+
const sourceRoot = join(packageRoot, 'examples', application);
|
|
34
|
+
const manifest = await readFile(join(sourceRoot, 'eject.json'), 'utf8').then(JSON.parse).catch(error => {
|
|
35
|
+
if (error.code === 'ENOENT')
|
|
36
|
+
throw new Error(`The ${command.application} application has no source export in this package. Install a package containing its application manifest.`);
|
|
37
|
+
throw error;
|
|
38
|
+
});
|
|
39
|
+
if (manifest.apiVersion !== 1 || typeof manifest.entry !== 'string' ||
|
|
40
|
+
!/^(?:[\w.-]+\/)*[\w.-]+\.(?:ts|mts)$/.test(manifest.entry) ||
|
|
41
|
+
!Array.isArray(manifest.files) || !manifest.files.includes(manifest.entry)) {
|
|
42
|
+
throw new TypeError('Application source manifest requires apiVersion 1, an entry, and an explicit files list containing the entry');
|
|
43
|
+
}
|
|
44
|
+
const dependencies = manifest.dependencies ?? {};
|
|
45
|
+
if (!dependencies || typeof dependencies !== 'object' || Array.isArray(dependencies) ||
|
|
46
|
+
Object.entries(dependencies).some(([name, version]) => name === '@anyswarm/core' || !packageSpecifier.test(name) || typeof version !== 'string' || !version.trim())) {
|
|
47
|
+
throw new TypeError('Application source dependencies must be package specs. The SDK source is supplied by eject.');
|
|
48
|
+
}
|
|
49
|
+
const target = resolve(cwd, command.directory);
|
|
50
|
+
const targetInfo = await lstat(target).catch(error => { if (error.code === 'ENOENT')
|
|
51
|
+
return null; throw error; });
|
|
52
|
+
if (targetInfo && (!targetInfo.isDirectory() || (await readdir(target)).length))
|
|
53
|
+
throw new Error('The export target must be an empty directory');
|
|
54
|
+
await mkdir(dirname(target), { recursive: true });
|
|
55
|
+
const staging = await mkdtemp(join(dirname(target), `.${basename(target)}-eject-`));
|
|
56
|
+
try {
|
|
57
|
+
for (const file of manifest.files) {
|
|
58
|
+
if (typeof file !== 'string' || !file || isAbsolute(file) || file.includes('\\') || file.split('/').some(part => part === '..' || part === '.' || !part) || reserved.has(file) || forbidden.test(file)) {
|
|
59
|
+
throw new TypeError('Application source manifest contains an unsafe or private path');
|
|
60
|
+
}
|
|
61
|
+
const source = join(sourceRoot, file);
|
|
62
|
+
const info = await lstat(source);
|
|
63
|
+
if (!info.isFile() || info.isSymbolicLink())
|
|
64
|
+
throw new TypeError('Application source exports must be regular files');
|
|
65
|
+
// Each parent must also be a directory rather than a symlink to private state.
|
|
66
|
+
let parent = dirname(source);
|
|
67
|
+
while (parent !== sourceRoot) {
|
|
68
|
+
if ((await lstat(parent)).isSymbolicLink())
|
|
69
|
+
throw new TypeError('Application source exports cannot traverse symlinks');
|
|
70
|
+
parent = dirname(parent);
|
|
71
|
+
}
|
|
72
|
+
await mkdir(dirname(join(staging, file)), { recursive: true });
|
|
73
|
+
await cp(source, join(staging, file), { errorOnExist: true, force: false });
|
|
74
|
+
}
|
|
75
|
+
const sdkDirectory = join(staging, '.anyswarm-sdk');
|
|
76
|
+
await mkdir(sdkDirectory);
|
|
77
|
+
const packed = await execute('npm', ['pack', '--ignore-scripts', '--json', '--pack-destination', sdkDirectory], {
|
|
78
|
+
cwd: packageRoot, timeout: 60_000, maxBuffer: 4 * 1024 * 1024,
|
|
79
|
+
});
|
|
80
|
+
const packedPackage = JSON.parse(packed.stdout)[0];
|
|
81
|
+
if (packedPackage.files.some((file) => file.path !== '.env.example' &&
|
|
82
|
+
/(?:^|\/)(?:\.env(?:\..*)?|runs|experiments|[^/]+-runs)(?:\/|$)|\.(?:db|sqlite|sqlite3|pem|key|ndjson|jsonl)$/i.test(file.path))) {
|
|
83
|
+
throw new Error('The installed SDK package contains private or runtime files and cannot be exported');
|
|
84
|
+
}
|
|
85
|
+
const archive = join(sdkDirectory, packedPackage.filename);
|
|
86
|
+
const archiveSha256 = createHash('sha256').update(await readFile(archive)).digest('hex');
|
|
87
|
+
await rename(archive, join(sdkDirectory, 'core.tgz'));
|
|
88
|
+
const sdk = JSON.parse(await readFile(join(packageRoot, 'package.json'), 'utf8'));
|
|
89
|
+
const source = await readFile(join(packageRoot, 'dist/scripts/build-provenance.json'), 'utf8').then(JSON.parse).catch(() => null);
|
|
90
|
+
const files = packedPackage.files.map((file) => file.path);
|
|
91
|
+
const provenance = { schema: 2, application: command.application, source,
|
|
92
|
+
sdk: { name: sdk.name, version: sdk.version, ...await installationSource(),
|
|
93
|
+
archiveSha256, content: { sha256: digestFiles(packageRoot, files), files } } };
|
|
94
|
+
await writeFile(join(staging, 'anyswarm-source.json'), JSON.stringify(provenance, null, 2) + '\n');
|
|
95
|
+
await writeFile(join(staging, 'package.json'), JSON.stringify({ name: `anyswarm-${command.application}-source`, private: true,
|
|
96
|
+
scripts: { start: `anys run ./${manifest.entry}` }, dependencies: { ...dependencies, '@anyswarm/core': 'file:./.anyswarm-sdk/core.tgz' },
|
|
97
|
+
}, null, 2) + '\n');
|
|
98
|
+
if (targetInfo)
|
|
99
|
+
await rmdir(target);
|
|
100
|
+
await rename(staging, target);
|
|
101
|
+
return { directory: target, entryPath: join(target, manifest.entry), provenancePath: join(target, 'anyswarm-source.json') };
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
await rm(staging, { recursive: true, force: true });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** Verify the executing host and return a guard for SDK resolutions inside a source export. */
|
|
108
|
+
export async function verifyExportedSdk(entry) {
|
|
109
|
+
let directory = dirname(entry);
|
|
110
|
+
for (;;) {
|
|
111
|
+
const manifest = await readFile(join(directory, 'anyswarm-source.json'), 'utf8').then(JSON.parse).catch(error => {
|
|
112
|
+
if (error.code === 'ENOENT')
|
|
113
|
+
return undefined;
|
|
114
|
+
throw error;
|
|
115
|
+
});
|
|
116
|
+
if (manifest) {
|
|
117
|
+
const content = manifest.schema === 1 ? { sha256: manifest.sdk?.contentSha256, files: manifest.sdk?.files } :
|
|
118
|
+
manifest.schema === 2 ? manifest.sdk?.content : undefined;
|
|
119
|
+
const files = content?.files;
|
|
120
|
+
if (typeof content?.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(content.sha256) ||
|
|
121
|
+
!Array.isArray(files) || !files.length || files.some(file => typeof file !== 'string' || !file || isAbsolute(file) ||
|
|
122
|
+
file.includes('\\') || file.split('/').some(part => !part || part === '.' || part === '..'))) {
|
|
123
|
+
throw new Error('Invalid exported SDK provenance');
|
|
124
|
+
}
|
|
125
|
+
const mismatch = () => new Error('The source export requires its recorded SDK candidate. Run npm install in the exported directory and start it with npm run start.');
|
|
126
|
+
const checked = new Set();
|
|
127
|
+
const verifyRoot = (root) => {
|
|
128
|
+
if (checked.has(root))
|
|
129
|
+
return;
|
|
130
|
+
let digest;
|
|
131
|
+
try {
|
|
132
|
+
digest = digestFiles(root, files);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
throw mismatch();
|
|
136
|
+
}
|
|
137
|
+
if (digest !== content.sha256)
|
|
138
|
+
throw mismatch();
|
|
139
|
+
checked.add(root);
|
|
140
|
+
};
|
|
141
|
+
verifyRoot(resolve(packageRoot));
|
|
142
|
+
return (url) => {
|
|
143
|
+
let manifestPath;
|
|
144
|
+
try {
|
|
145
|
+
if (url.startsWith('file:'))
|
|
146
|
+
manifestPath = findPackageJSON(url);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
throw mismatch();
|
|
150
|
+
}
|
|
151
|
+
if (!manifestPath)
|
|
152
|
+
throw mismatch();
|
|
153
|
+
const root = dirname(manifestPath);
|
|
154
|
+
if (!files.includes(relative(root, fileURLToPath(url)).split(sep).join('/')))
|
|
155
|
+
throw mismatch();
|
|
156
|
+
verifyRoot(root);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const parent = dirname(directory);
|
|
160
|
+
if (parent === directory)
|
|
161
|
+
return;
|
|
162
|
+
directory = parent;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { applicationDescriptors, findApplication } from './anyswarm-applications.js';
|
|
3
|
+
export const builtins = {
|
|
4
|
+
...Object.fromEntries(applicationDescriptors().map(app => [app.id, app.harness])),
|
|
5
|
+
'lead-worker': new URL('../examples/lead-worker/project.js', import.meta.url).href,
|
|
6
|
+
peermesh: new URL('../examples/peermesh/project.js', import.meta.url).href,
|
|
7
|
+
notes: new URL('../examples/notes/project.js', import.meta.url).href,
|
|
8
|
+
messages: new URL('../examples/messages/project.js', import.meta.url).href,
|
|
9
|
+
taskpool: new URL('../examples/taskpool/project.js', import.meta.url).href,
|
|
10
|
+
substrate: new URL('../examples/substrate/project.js', import.meta.url).href,
|
|
11
|
+
subagents: new URL('../examples/subagents/project.js', import.meta.url).href,
|
|
12
|
+
};
|
|
13
|
+
export async function builtinConfiguration(name) {
|
|
14
|
+
if (name === 'messages')
|
|
15
|
+
return (await import('../examples/messages/handoff-config.js')).handoffConfig();
|
|
16
|
+
if (name === 'peermesh')
|
|
17
|
+
return (await import('../examples/peermesh/project-config.js')).peerMeshConfig();
|
|
18
|
+
if (name === 'substrate')
|
|
19
|
+
return (await import('../examples/substrate/project-config.js')).substrateConfiguration();
|
|
20
|
+
if (name === 'lead-worker')
|
|
21
|
+
return {
|
|
22
|
+
...(await import('../examples/lead-worker/project-config.js')).leadWorkerConfig(),
|
|
23
|
+
team: process.env.ANYSWARM_LEAD_WORKER_TEAM,
|
|
24
|
+
checkingImage: process.env.ANYSWARM_LEAD_WORKER_CHECKING_IMAGE,
|
|
25
|
+
};
|
|
26
|
+
const path = new URL('../examples/' + name + '/config.js', import.meta.url);
|
|
27
|
+
if (findApplication(name) && !existsSync(path))
|
|
28
|
+
return undefined;
|
|
29
|
+
path.search = 'launcher=' + Date.now();
|
|
30
|
+
return (await import(path.href)).default;
|
|
31
|
+
}
|
|
@@ -12,7 +12,7 @@ const previousPackageNames = ['@anyswarm/anyswarm', '@luna-shi/anyswarm'];
|
|
|
12
12
|
const packageRoot = resolve(fileURLToPath(new URL('../..', import.meta.url)));
|
|
13
13
|
const releaseRoot = 'https://github.com/AnySwarm/anyswarm/releases/download';
|
|
14
14
|
const stableVersion = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
|
|
15
|
-
const bins = ['anyswarm', 'swarm'];
|
|
15
|
+
const bins = ['anyswarm', 'anys', 'swarm'];
|
|
16
16
|
const installDirectory = (prefix) => join(prefix, 'lib', 'anyswarm');
|
|
17
17
|
const installedPackage = (stage) => join(stage, 'node_modules', packageName);
|
|
18
18
|
const installBin = (prefix, name) => join(prefix, 'bin', name);
|
|
@@ -56,7 +56,10 @@ function binTarget(prefix, name) {
|
|
|
56
56
|
async function lockActivation(prefix, action, signal) {
|
|
57
57
|
signal?.throwIfAborted();
|
|
58
58
|
const lock = join(installDirectory(prefix), 'activation-flock');
|
|
59
|
-
const
|
|
59
|
+
const darwin = process.platform === 'darwin';
|
|
60
|
+
// Keep the inode stable so waiting and newly arriving processes lock the same file.
|
|
61
|
+
const flags = darwin ? ['-k', '-t', '15'] : ['--exclusive', '--timeout', '15'];
|
|
62
|
+
const child = spawn(darwin ? '/usr/bin/lockf' : 'flock', [...flags, lock, process.execPath, '-e',
|
|
60
63
|
'console.log("locked"); process.stdin.resume()'], { stdio: ['pipe', 'pipe', 'ignore'] });
|
|
61
64
|
child.stdin.on('error', () => { });
|
|
62
65
|
const cancelled = () => child.kill();
|
|
@@ -83,6 +86,13 @@ async function activate(prefix, stage, source, sha256, signal, expected) {
|
|
|
83
86
|
const { name, version } = await manifest(root);
|
|
84
87
|
if (name !== packageName || !stableVersion.test(version))
|
|
85
88
|
throw new Error('The archive does not contain a stable AnySwarm distribution.');
|
|
89
|
+
for (const bin of ['anyswarm', 'swarm']) {
|
|
90
|
+
const path = join(stage, 'node_modules', '.bin', bin);
|
|
91
|
+
if (await realpath(path) !== join(root, 'dist', 'scripts', `${bin}.js`)) {
|
|
92
|
+
throw new Error(`The staged ${bin} entry does not belong to the package.`);
|
|
93
|
+
}
|
|
94
|
+
await access(path, constants.X_OK);
|
|
95
|
+
}
|
|
86
96
|
const { stdout } = await execute(join(stage, 'node_modules', '.bin', 'anyswarm'), ['--version'], {
|
|
87
97
|
signal, timeout: 10_000, env: { ...process.env, NODE_OPTIONS: '' },
|
|
88
98
|
});
|
|
@@ -90,13 +100,6 @@ async function activate(prefix, stage, source, sha256, signal, expected) {
|
|
|
90
100
|
throw new Error('The staged CLI did not report the package version.');
|
|
91
101
|
await writeFile(join(stage, 'install.json'), JSON.stringify({ schema: 1, prefix, version, source, sha256 }), { mode: 0o600 });
|
|
92
102
|
await mkdir(join(prefix, 'bin'), { recursive: true });
|
|
93
|
-
for (const bin of bins) {
|
|
94
|
-
const path = join(stage, 'node_modules', '.bin', bin);
|
|
95
|
-
if (await realpath(path) !== join(root, 'dist', 'scripts', `${bin}.js`)) {
|
|
96
|
-
throw new Error(`The staged ${bin} entry does not belong to the package.`);
|
|
97
|
-
}
|
|
98
|
-
await access(path, constants.X_OK);
|
|
99
|
-
}
|
|
100
103
|
return lockActivation(prefix, async () => {
|
|
101
104
|
const changed = [];
|
|
102
105
|
try {
|
|
@@ -106,12 +109,15 @@ async function activate(prefix, stage, source, sha256, signal, expected) {
|
|
|
106
109
|
}
|
|
107
110
|
for (const bin of bins) {
|
|
108
111
|
const path = installBin(prefix, bin);
|
|
109
|
-
const
|
|
112
|
+
const host = bin === 'anys' ? 'anyswarm' : bin;
|
|
113
|
+
const target = binTarget(prefix, host);
|
|
110
114
|
const previous = await inspectLink(path);
|
|
111
115
|
if (previous === target)
|
|
112
116
|
continue;
|
|
113
|
-
const npmTargets = [packageName, ...previousPackageNames].map(name => join(prefix, 'lib', 'node_modules', name, 'dist', 'scripts', `${
|
|
114
|
-
|
|
117
|
+
const npmTargets = [packageName, ...previousPackageNames].map(name => join(prefix, 'lib', 'node_modules', name, 'dist', 'scripts', `${host}.js`));
|
|
118
|
+
const legacyAlias = bin === 'anys' && previous === binTarget(prefix, 'anys') && oldCurrent &&
|
|
119
|
+
dirname(resolve(installDirectory(prefix), oldCurrent)) === join(installDirectory(prefix), 'versions');
|
|
120
|
+
if (previous && !legacyAlias && !npmTargets.includes(resolve(dirname(path), previous))) {
|
|
115
121
|
throw new Error(`The link at ${path} belongs to another installation.`);
|
|
116
122
|
}
|
|
117
123
|
await replaceLink(path, target);
|
|
@@ -212,7 +218,7 @@ export async function updateAnySwarm(options, signal, progress) {
|
|
|
212
218
|
return {
|
|
213
219
|
ok: false, before, after: before, path: invocation, packageRoot, source: 'npm global',
|
|
214
220
|
result: 'preserved', environment: 'separate',
|
|
215
|
-
detail: `
|
|
221
|
+
detail: `This CLI was installed with npm. Update it with \`npm install -g --prefix ${quoted(npmPrefix)} ${packageName}@latest\`.`,
|
|
216
222
|
};
|
|
217
223
|
return {
|
|
218
224
|
ok: false, before, path: invocation, packageRoot, source: 'other',
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { loadProjectHarnessModule, type Harness, type HarnessLifetime } from '../src/harness/project-harness.js';
|
|
2
|
+
import type { HarnessCommand } from './anyswarm-arguments.js';
|
|
3
|
+
import { type ApplicationObservation } from './anyswarm-applications.js';
|
|
4
|
+
export type LaunchContext = {
|
|
5
|
+
cwd: string;
|
|
6
|
+
configuration?: unknown;
|
|
7
|
+
signal: AbortSignal;
|
|
8
|
+
outputRoot?: string;
|
|
9
|
+
progress?: (message: string) => void;
|
|
10
|
+
};
|
|
11
|
+
export type ActionRun = {
|
|
12
|
+
kind: 'start-run';
|
|
13
|
+
cwd: string;
|
|
14
|
+
prompt: string;
|
|
15
|
+
configuration?: Record<string, unknown>;
|
|
16
|
+
};
|
|
17
|
+
export declare function actionRun(value: unknown): ActionRun | undefined;
|
|
18
|
+
export declare function actionReport(value: unknown): {
|
|
19
|
+
exitCode: number;
|
|
20
|
+
result: unknown;
|
|
21
|
+
} | undefined;
|
|
22
|
+
export declare function configuredStopTimeout(configuration: Record<string, unknown> | undefined): number | undefined;
|
|
23
|
+
export declare function requestedTraceRoot(value: unknown, runId: string | null): string | undefined;
|
|
24
|
+
type SlashAction = (options: LaunchContext & {
|
|
25
|
+
args: string;
|
|
26
|
+
}) => unknown | Promise<unknown>;
|
|
27
|
+
export declare function loadHarness(launchDirectory: string, specifier: string, options?: Parameters<typeof loadProjectHarnessModule>[3]): Promise<{
|
|
28
|
+
definition: Harness;
|
|
29
|
+
observe: ((options: LaunchContext) => Promise<ApplicationObservation | undefined>) | undefined;
|
|
30
|
+
actions: Map<string, SlashAction>;
|
|
31
|
+
workspace: ((options: Pick<LaunchContext, 'cwd' | 'configuration'>) => string) | undefined;
|
|
32
|
+
}>;
|
|
33
|
+
export declare function harnessLifetime(harness: Harness, requested?: HarnessLifetime, preferred?: HarnessLifetime): HarnessLifetime;
|
|
34
|
+
export declare function splitInput(text: string): [string, string];
|
|
35
|
+
export declare function interactiveTerminal(): boolean;
|
|
36
|
+
export declare function runHarnessSelection(command: HarnessCommand, launchDirectory: string, options?: Parameters<typeof loadProjectHarnessModule>[3]): Promise<number | undefined>;
|
|
37
|
+
export {};
|