@anyswarm/core 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -10
- package/deploy/worker/Dockerfile +12 -4
- package/dist/deploy/worker/Dockerfile +12 -4
- package/dist/examples/README.md +24 -12
- package/dist/examples/authoring/README.md +24 -0
- package/dist/examples/authoring/business.d.ts +2 -0
- package/dist/examples/authoring/business.js +4 -0
- package/dist/examples/authoring/config.d.ts +5 -0
- package/dist/examples/authoring/config.js +2 -0
- package/dist/examples/authoring/eject.json +5 -0
- package/dist/examples/authoring/harness.d.ts +4 -0
- package/dist/examples/authoring/harness.js +19 -0
- package/dist/examples/autoresearch/README.md +33 -0
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +18 -0
- package/dist/examples/autoresearch/config.d.ts +51 -0
- package/dist/examples/autoresearch/config.js +57 -0
- package/dist/examples/autoresearch/demo.d.ts +11 -0
- package/dist/examples/autoresearch/demo.js +52 -0
- package/dist/examples/autoresearch/eject.json +15 -0
- package/dist/examples/autoresearch/frontiercs2.d.ts +87 -0
- package/dist/examples/autoresearch/frontiercs2.js +211 -0
- package/dist/examples/autoresearch/prepare.d.ts +95 -0
- package/dist/examples/autoresearch/prepare.js +257 -0
- package/dist/examples/autoresearch/process.d.ts +13 -0
- package/dist/examples/autoresearch/process.js +48 -0
- package/dist/examples/autoresearch/project.d.ts +115 -0
- package/dist/examples/autoresearch/project.js +410 -0
- package/dist/examples/autoresearch/research-service.d.ts +106 -0
- package/dist/examples/autoresearch/research-service.js +255 -0
- package/dist/examples/code/README.md +25 -0
- package/dist/examples/code/REQUIREMENTS.zh.md +11 -0
- package/dist/examples/code/candidate.d.ts +19 -0
- package/dist/examples/code/candidate.js +80 -0
- package/dist/examples/code/config.d.ts +32 -0
- package/dist/examples/code/config.js +18 -0
- package/dist/examples/code/eject.json +5 -0
- package/dist/examples/code/project.d.ts +3 -0
- package/dist/examples/code/project.js +605 -0
- package/dist/examples/code/prompts.d.ts +5 -0
- package/dist/examples/code/prompts.js +12 -0
- package/dist/examples/code/verification.d.ts +19 -0
- package/dist/examples/code/verification.js +268 -0
- package/dist/examples/code/worktree.d.ts +17 -0
- package/dist/examples/code/worktree.js +233 -0
- package/dist/examples/harness-session/README.md +3 -6
- package/dist/examples/lead-worker/harness/dynamic-scheduler.d.ts +2 -1
- package/dist/examples/lead-worker/harness/dynamic-scheduler.js +5 -2
- package/dist/examples/lead-worker/harness/index.d.ts +60 -0
- package/dist/examples/lead-worker/harness/index.js +77 -6
- package/dist/examples/lead-worker/project.js +2 -2
- package/dist/examples/lead-worker/services/board.d.ts +5 -0
- package/dist/examples/lead-worker/services/board.js +19 -1
- package/dist/examples/messages/README.md +5 -5
- package/dist/examples/messages/handoff.d.ts +2 -0
- package/dist/examples/messages/handoff.js +5 -1
- package/dist/examples/messages/project.js +52 -2
- package/dist/examples/notes/README.md +13 -18
- package/dist/examples/notes/project.js +67 -6
- package/dist/examples/peermesh/harness/router.js +3 -1
- package/dist/examples/peermesh/harness/team.d.ts +8 -0
- package/dist/examples/peermesh/harness/team.js +13 -0
- package/dist/examples/peermesh/project.js +22 -4
- package/dist/examples/services/agent-control/README.md +3 -3
- package/dist/examples/services/mathlib-search/Dockerfile +4 -2
- package/dist/examples/services/mathlib-search/README.md +1 -1
- package/dist/examples/services/mcp-managed/README.md +2 -2
- package/dist/examples/services/persistent-board/README.md +13 -3
- package/dist/examples/services/persistent-board/business.d.ts +7 -0
- package/dist/examples/services/persistent-board/business.js +7 -0
- package/dist/examples/services/persistent-board/index.js +10 -0
- package/dist/examples/services/persistent-board/live.d.ts +3 -0
- package/dist/examples/services/persistent-board/live.js +58 -0
- package/dist/examples/subagents/README.md +5 -5
- package/dist/examples/subagents/business.js +3 -1
- package/dist/examples/subagents/harness/controller.d.ts +15 -0
- package/dist/examples/subagents/harness/controller.js +181 -32
- package/dist/examples/subagents/project.d.ts +2 -0
- package/dist/examples/subagents/project.js +43 -34
- package/dist/examples/subagents/prompts/prompts.d.ts +1 -0
- package/dist/examples/subagents/prompts/prompts.js +3 -0
- package/dist/examples/subagents/services/collaboration-service.d.ts +3 -2
- package/dist/examples/subagents/services/collaboration-service.js +14 -2
- package/dist/examples/substrate/README.md +2 -2
- package/dist/examples/substrate/harness/index.d.ts +1 -1
- package/dist/examples/substrate/harness/index.js +77 -12
- package/dist/examples/substrate/project.js +4 -1
- package/dist/examples/super/README.md +40 -0
- package/dist/examples/super/actions.d.ts +95 -0
- package/dist/examples/super/actions.js +230 -0
- package/dist/examples/super/artifact.d.ts +4 -0
- package/dist/examples/super/artifact.js +51 -0
- package/dist/examples/super/config.d.ts +80 -0
- package/dist/examples/super/config.js +83 -0
- package/dist/examples/super/coordinator.d.ts +33 -0
- package/dist/examples/super/coordinator.js +151 -0
- package/dist/examples/super/daemon.d.ts +11 -0
- package/dist/examples/super/daemon.js +109 -0
- package/dist/examples/super/decisions.d.ts +8 -0
- package/dist/examples/super/decisions.js +52 -0
- package/dist/examples/super/eject.json +5 -0
- package/dist/examples/super/execution.d.ts +11 -0
- package/dist/examples/super/execution.js +136 -0
- package/dist/examples/super/github.d.ts +62 -0
- package/dist/examples/super/github.js +269 -0
- package/dist/examples/super/inbox.d.ts +162 -0
- package/dist/examples/super/inbox.js +284 -0
- package/dist/examples/super/location.d.ts +5 -0
- package/dist/examples/super/location.js +64 -0
- package/dist/examples/super/outbox.d.ts +5 -0
- package/dist/examples/super/outbox.js +103 -0
- package/dist/examples/super/project.d.ts +111 -0
- package/dist/examples/super/project.js +253 -0
- package/dist/examples/super/prompts.d.ts +3 -0
- package/dist/examples/super/prompts.js +25 -0
- package/dist/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
- package/dist/examples/taskpool/harness/controller.d.ts +35 -6
- package/dist/examples/taskpool/harness/controller.js +73 -7
- package/dist/examples/taskpool/project.js +18 -2
- package/dist/scripts/anyswarm-applications.d.ts +19 -0
- package/dist/scripts/anyswarm-applications.js +19 -0
- package/dist/scripts/anyswarm-arguments.d.ts +35 -5
- package/dist/scripts/anyswarm-arguments.js +87 -23
- package/dist/scripts/anyswarm-author.d.ts +5 -0
- package/dist/scripts/anyswarm-author.js +24 -0
- package/dist/scripts/anyswarm-eject.d.ts +11 -0
- package/dist/scripts/anyswarm-eject.js +164 -0
- package/dist/scripts/anyswarm-harnesses.d.ts +2 -0
- package/dist/scripts/anyswarm-harnesses.js +31 -0
- package/dist/scripts/anyswarm-installation.js +19 -13
- package/dist/scripts/anyswarm-launch.d.ts +37 -0
- package/dist/scripts/anyswarm-launch.js +86 -0
- package/dist/scripts/anyswarm-project.d.ts +12 -2
- package/dist/scripts/anyswarm-project.js +121 -20
- package/dist/scripts/anyswarm-source-runner.d.ts +1 -0
- package/dist/scripts/anyswarm-source-runner.js +232 -0
- package/dist/scripts/anyswarm-tui-config.d.ts +36 -0
- package/dist/scripts/anyswarm-tui-config.js +189 -0
- package/dist/scripts/anyswarm-tui-session.d.ts +66 -0
- package/dist/scripts/anyswarm-tui-session.js +304 -0
- package/dist/scripts/anyswarm-tui-terminal.d.ts +41 -0
- package/dist/scripts/anyswarm-tui-terminal.js +154 -0
- package/dist/scripts/anyswarm-tui.d.ts +2 -0
- package/dist/scripts/anyswarm-tui.js +1012 -0
- package/dist/scripts/anyswarm.js +47 -2
- package/dist/scripts/build-provenance.json +1 -0
- package/dist/scripts/build.js +7 -1
- package/dist/scripts/generate-architecture-api.js +2 -0
- package/dist/scripts/generate-architecture-prompts.js +24 -2
- package/dist/scripts/local-environment.d.ts +6 -1
- package/dist/scripts/local-environment.js +52 -16
- package/dist/scripts/local-setup-smoke.js +3 -2
- package/dist/scripts/local-setup-worker.d.ts +1 -1
- package/dist/scripts/local-setup-worker.js +15 -6
- package/dist/scripts/local-setup.d.ts +2 -2
- package/dist/scripts/local-setup.js +72 -12
- package/dist/scripts/opensandbox-agent-worker.js +2 -2
- package/dist/scripts/pack-release.d.ts +1 -0
- package/dist/scripts/pack-release.js +63 -0
- package/dist/scripts/pi-session-bridge.js +11 -3
- package/dist/scripts/run-harness.js +3 -1
- package/dist/scripts/setup-bootstrap.js +43 -6
- package/dist/src/core/allocation-ledger.js +4 -3
- package/dist/src/core/host-identity.d.ts +2 -0
- package/dist/src/core/host-identity.js +11 -0
- package/dist/src/core/index.d.ts +4 -2
- package/dist/src/core/index.js +12 -4
- package/dist/src/core/mcp-service.js +2 -2
- package/dist/src/core/runtime-management.d.ts +6 -0
- package/dist/src/core/runtime-management.js +24 -0
- package/dist/src/core/sandbox/executor-driver.d.ts +4 -2
- package/dist/src/core/sandbox/executor-driver.js +12 -14
- package/dist/src/core/sandbox/local-executor.d.ts +13 -1
- package/dist/src/core/sandbox/local-executor.js +69 -19
- package/dist/src/core/sandbox/local-worker.js +32 -21
- package/dist/src/core/sandbox/opensandbox-backend.d.ts +2 -0
- package/dist/src/core/sandbox/opensandbox-backend.js +36 -11
- package/dist/src/core/sandbox/sandbox-connection.d.ts +2 -0
- package/dist/src/core/sandbox/sandbox-connection.js +14 -6
- package/dist/src/core/service-live-state.d.ts +14 -0
- package/dist/src/core/service-live-state.js +161 -0
- package/dist/src/core/service-observation-types.d.ts +21 -1
- package/dist/src/core/service-process.d.ts +1 -1
- package/dist/src/core/service-process.js +45 -4
- package/dist/src/core/service-types.d.ts +5 -1
- package/dist/src/core/services.d.ts +1 -1
- package/dist/src/core/services.js +8 -3
- package/dist/src/core/types.d.ts +3 -0
- package/dist/src/core/worker-image.js +3 -3
- package/dist/src/harness/harness-session-types.d.ts +10 -0
- package/dist/src/harness/harness-session.js +42 -5
- package/dist/src/harness/project-harness.d.ts +13 -1
- package/dist/src/harness/project-harness.js +36 -10
- package/dist/src/harness/project-input.js +81 -15
- package/dist/src/harness/project-rpc-client.d.ts +1 -0
- package/dist/src/harness/project-rpc-client.js +5 -0
- package/dist/src/harness/project-rpc.d.ts +8 -2
- package/dist/src/harness/project-rpc.js +31 -7
- package/dist/src/harness/project-runtime.js +3 -1
- package/dist/src/harness/typescript-loader.d.ts +2 -0
- package/dist/src/harness/typescript-loader.js +41 -0
- package/dist/src/trace-viewer/public/app.js +6 -5
- package/dist/src/trace-viewer/reader.mjs +42 -2
- package/docs/INDEX.md +3 -1
- package/docs/architecture/00-overview.md +1 -1
- package/docs/architecture/01-agent-core.md +1 -1
- package/docs/architecture/06-observability-experiments.md +1 -1
- package/docs/architecture/07-run-configuration.md +18 -12
- package/docs/architecture/08-prompts.md +22 -0
- package/docs/architecture/10-service-api-reference.md +53 -18
- package/docs/architecture/11-storage-reference.md +18 -1
- package/docs/architecture/12-code-coverage.md +148 -84
- package/docs/architecture/15-core-runtime.md +8 -0
- package/docs/architecture/16-pi-opensandbox-backend.md +5 -5
- package/docs/architecture/17-harness-reporting.md +1 -1
- package/docs/architecture/19-substrate-harness.md +28 -1
- package/docs/architecture/20-lead-worker-harness.md +34 -1
- package/docs/architecture/22-website.md +5 -3
- package/docs/architecture/23-project-harness.md +124 -5
- package/docs/architecture/24-runtime-recovery.md +10 -3
- package/docs/architecture/25-foreground-tui.md +51 -0
- package/docs/architecture/26-code.md +39 -0
- package/docs/architecture/27-personal.md +43 -0
- package/docs/architecture/28-autoresearch.md +31 -0
- package/docs/architecture/INDEX.md +4 -0
- package/docs/architecture/prompts/08-lead-worker-harness.md +4 -2
- package/docs/architecture/prompts/08-subagents-harness.md +21 -0
- package/docs/architecture/prompts/21-personal.md +44 -0
- package/docs/architecture/prompts/22-autoresearch.md +63 -0
- package/docs/architecture/prompts/26-code.md +55 -0
- package/docs/architecture/prompts/source-manifest.json +152 -33
- package/docs/architecture/source-map.json +489 -21
- package/docs/designs/core-harness/06-project-harness.md +13 -2
- package/docs/designs/core-harness/README.md +5 -0
- package/docs/en/agents.md +1 -1
- package/docs/en/build-your-harness.md +3 -5
- package/docs/en/changelog.md +13 -4
- package/docs/en/first-harness.md +8 -11
- package/docs/en/harnesses/lead-worker.md +1 -1
- package/docs/en/harnesses/peermesh.md +2 -2
- package/docs/en/harnesses/subagents.md +2 -2
- package/docs/en/harnesses/substrate.md +4 -4
- package/docs/en/harnesses/taskpool.md +2 -2
- package/docs/en/latest.md +12 -123
- package/docs/en/overview.md +1 -1
- package/docs/en/quickstart.md +40 -16
- package/docs/en/reference/api.md +14 -4
- package/docs/en/reference/cli.md +58 -14
- package/docs/en/runtime.md +2 -2
- package/docs/en/services.md +4 -0
- package/docs/third-party-notices.md +1 -0
- package/docs/workflows/development.md +17 -12
- package/docs/workflows/release-and-docs-versioning.md +76 -0
- package/docs/zh/agents.md +1 -1
- package/docs/zh/build-your-harness.md +3 -5
- package/docs/zh/changelog.md +13 -4
- package/docs/zh/first-harness.md +8 -11
- package/docs/zh/harnesses/lead-worker.md +1 -1
- package/docs/zh/harnesses/peermesh.md +2 -2
- package/docs/zh/harnesses/subagents.md +2 -2
- package/docs/zh/harnesses/substrate.md +4 -4
- package/docs/zh/harnesses/taskpool.md +2 -2
- package/docs/zh/latest.md +13 -124
- package/docs/zh/overview.md +1 -1
- package/docs/zh/quickstart.md +40 -16
- package/docs/zh/reference/api.md +14 -4
- package/docs/zh/reference/cli.md +58 -14
- package/docs/zh/runtime.md +2 -2
- package/docs/zh/services.md +4 -0
- package/examples/README.md +24 -12
- package/examples/authoring/README.md +24 -0
- package/examples/authoring/business.ts +4 -0
- package/examples/authoring/config.ts +2 -0
- package/examples/authoring/eject.json +5 -0
- package/examples/authoring/harness.ts +21 -0
- package/examples/autoresearch/README.md +33 -0
- package/examples/autoresearch/REQUIREMENTS.zh.md +18 -0
- package/examples/autoresearch/config.ts +90 -0
- package/examples/autoresearch/demo.ts +55 -0
- package/examples/autoresearch/eject.json +15 -0
- package/examples/autoresearch/frontiercs2.ts +237 -0
- package/examples/autoresearch/prepare.ts +267 -0
- package/examples/autoresearch/process.ts +50 -0
- package/examples/autoresearch/project.ts +397 -0
- package/examples/autoresearch/research-service.ts +302 -0
- package/examples/code/README.md +25 -0
- package/examples/code/REQUIREMENTS.zh.md +11 -0
- package/examples/code/candidate.ts +89 -0
- package/examples/code/config.ts +19 -0
- package/examples/code/eject.json +5 -0
- package/examples/code/project.ts +581 -0
- package/examples/code/prompts.ts +16 -0
- package/examples/code/verification.ts +239 -0
- package/examples/code/worktree.ts +188 -0
- package/examples/harness-session/README.md +3 -6
- package/examples/lead-worker/harness/dynamic-scheduler.ts +6 -3
- package/examples/lead-worker/harness/index.ts +61 -6
- package/examples/lead-worker/project.ts +2 -2
- package/examples/lead-worker/services/board.ts +14 -1
- package/examples/messages/README.md +5 -5
- package/examples/messages/handoff.ts +6 -2
- package/examples/messages/project.ts +47 -2
- package/examples/notes/README.md +13 -18
- package/examples/notes/project.ts +57 -9
- package/examples/peermesh/harness/router.ts +2 -2
- package/examples/peermesh/harness/team.ts +11 -0
- package/examples/peermesh/project.ts +19 -4
- package/examples/services/agent-control/README.md +3 -3
- package/examples/services/mathlib-search/Dockerfile +4 -2
- package/examples/services/mathlib-search/README.md +1 -1
- package/examples/services/mcp-managed/README.md +2 -2
- package/examples/services/persistent-board/README.md +13 -3
- package/examples/services/persistent-board/business.ts +10 -0
- package/examples/services/persistent-board/index.ts +10 -0
- package/examples/services/persistent-board/live.ts +54 -0
- package/examples/subagents/README.md +5 -5
- package/examples/subagents/business.ts +3 -1
- package/examples/subagents/harness/controller.ts +161 -29
- package/examples/subagents/project.ts +47 -33
- package/examples/subagents/prompts/prompts.ts +4 -0
- package/examples/subagents/services/collaboration-service.ts +14 -2
- package/examples/substrate/README.md +2 -2
- package/examples/substrate/harness/index.ts +67 -11
- package/examples/substrate/project.ts +5 -1
- package/examples/super/README.md +40 -0
- package/examples/super/actions.ts +196 -0
- package/examples/super/artifact.ts +56 -0
- package/examples/super/config.ts +95 -0
- package/examples/super/coordinator.ts +158 -0
- package/examples/super/daemon.ts +84 -0
- package/examples/super/decisions.ts +46 -0
- package/examples/super/eject.json +5 -0
- package/examples/super/execution.ts +131 -0
- package/examples/super/github.ts +242 -0
- package/examples/super/inbox.ts +306 -0
- package/examples/super/location.ts +54 -0
- package/examples/super/outbox.ts +97 -0
- package/examples/super/project.ts +227 -0
- package/examples/super/prompts.ts +27 -0
- package/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
- package/examples/taskpool/harness/controller.ts +59 -7
- package/examples/taskpool/project.ts +18 -2
- package/npm-shrinkwrap.development.json +2199 -0
- package/npm-shrinkwrap.json +86 -1920
- package/package.development.json +92 -0
- package/package.json +13 -7
- package/scripts/anyswarm-applications.ts +39 -0
- package/scripts/anyswarm-arguments.ts +94 -28
- package/scripts/anyswarm-author.ts +25 -0
- package/scripts/anyswarm-eject.ts +145 -0
- package/scripts/anyswarm-harnesses.ts +27 -0
- package/scripts/anyswarm-installation.ts +19 -13
- package/scripts/anyswarm-launch.ts +108 -0
- package/scripts/anyswarm-project.ts +114 -21
- package/scripts/anyswarm-source-runner.ts +203 -0
- package/scripts/anyswarm-tui-config.ts +174 -0
- package/scripts/anyswarm-tui-session.ts +295 -0
- package/scripts/anyswarm-tui-terminal.ts +147 -0
- package/scripts/anyswarm-tui.ts +912 -0
- package/scripts/anyswarm.ts +43 -2
- package/scripts/build.ts +8 -1
- package/scripts/generate-architecture-api.ts +2 -0
- package/scripts/generate-architecture-prompts.ts +35 -2
- package/scripts/local-environment.ts +55 -17
- package/scripts/local-setup-smoke.ts +3 -2
- package/scripts/local-setup-worker.ts +17 -7
- package/scripts/local-setup.ts +66 -13
- package/scripts/opensandbox-agent-worker.ts +2 -2
- package/scripts/pack-release.ts +67 -0
- package/scripts/pi-session-bridge.ts +10 -2
- package/scripts/run-harness.ts +3 -1
- package/scripts/setup-bootstrap.ts +41 -6
- package/src/core/allocation-ledger.ts +5 -3
- package/src/core/host-identity.ts +11 -0
- package/src/core/index.ts +12 -6
- package/src/core/mcp-service.ts +2 -2
- package/src/core/runtime-management.ts +22 -0
- package/src/core/sandbox/executor-driver.ts +15 -18
- package/src/core/sandbox/local-executor.ts +65 -19
- package/src/core/sandbox/local-worker.ts +29 -21
- package/src/core/sandbox/opensandbox-backend.ts +36 -11
- package/src/core/sandbox/sandbox-connection.ts +14 -5
- package/src/core/service-live-state.ts +156 -0
- package/src/core/service-observation-types.ts +23 -1
- package/src/core/service-process.ts +36 -3
- package/src/core/service-types.ts +3 -1
- package/src/core/services.ts +8 -3
- package/src/core/types.ts +3 -0
- package/src/core/worker-image.ts +3 -3
- package/src/harness/harness-session-types.ts +13 -1
- package/src/harness/harness-session.ts +40 -7
- package/src/harness/project-harness.ts +36 -10
- package/src/harness/project-input.ts +73 -15
- package/src/harness/project-rpc-client.ts +5 -0
- package/src/harness/project-rpc.ts +29 -8
- package/src/harness/project-runtime.ts +2 -1
- package/src/harness/typescript-loader.ts +37 -0
- package/src/trace-viewer/public/app.js +6 -5
- package/src/trace-viewer/reader.mjs +42 -2
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
5
|
+
import { command, requireSuccess } from './process.js';
|
|
6
|
+
export const frontierRevision = '7e48965c7cef2a567c2669c8e2f10b06386289c9';
|
|
7
|
+
export const pumpkinPin = '2026-11-30 ca3ce7ae0da5616464b00ee7962aecac0fc0b38d a1bb9c633f1f700ea42bceb9cd9512f684e9063d3a8ae6c9485526a1dd68016f';
|
|
8
|
+
export const frontierTask = 'tasks/binary_fuse_filter/task.star';
|
|
9
|
+
export const submissionLimit = 1024 * 1024;
|
|
10
|
+
export const judgeTimeMs = 190_000;
|
|
11
|
+
export const frontierFinalTimeMs = 250_000;
|
|
12
|
+
export function digest(bytes) {
|
|
13
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
14
|
+
}
|
|
15
|
+
export function frontierSubmission(patch) {
|
|
16
|
+
const bytes = Math.ceil(patch.byteLength / 512) * 512 + 512 * 3;
|
|
17
|
+
if (!patch.byteLength || bytes > submissionLimit)
|
|
18
|
+
throw new Error('Patch exceeds the FrontierCS-2 submission limit or is empty');
|
|
19
|
+
const archive = Buffer.alloc(bytes);
|
|
20
|
+
archive.write('payload/solution.patch');
|
|
21
|
+
archive.write('0000644\0', 100);
|
|
22
|
+
archive.write('0000000\0', 108);
|
|
23
|
+
archive.write('0000000\0', 116);
|
|
24
|
+
archive.write(patch.byteLength.toString(8).padStart(11, '0') + '\0', 124);
|
|
25
|
+
archive.write('00000000000\0', 136);
|
|
26
|
+
archive.fill(32, 148, 156);
|
|
27
|
+
archive.write('0', 156);
|
|
28
|
+
archive.write('ustar\0' + '00', 257);
|
|
29
|
+
let checksum = 0;
|
|
30
|
+
for (const byte of archive.subarray(0, 512))
|
|
31
|
+
checksum += byte;
|
|
32
|
+
archive.write(checksum.toString(8).padStart(6, '0') + '\0 ', 148);
|
|
33
|
+
archive.set(patch, 512);
|
|
34
|
+
return archive;
|
|
35
|
+
}
|
|
36
|
+
function replaceOnce(source, needle, replacement) {
|
|
37
|
+
const first = source.indexOf(needle);
|
|
38
|
+
if (first < 0 || source.indexOf(needle, first + needle.length) >= 0)
|
|
39
|
+
throw new Error('Unexpected pinned FrontierCS-2 workflow');
|
|
40
|
+
return source.replace(needle, replacement);
|
|
41
|
+
}
|
|
42
|
+
export const bridgeDockerfile = 'FROM ubuntu:24.04@sha256:fe81560990fae86dc4743202b2cb4d3df98d0bcf949173cecef15ce1127ef852\n';
|
|
43
|
+
export function bridgeWorkflow(source) {
|
|
44
|
+
return replaceOnce(source, ' elif AGENT == "reference":', ` elif AGENT == "anyswarm":
|
|
45
|
+
agent_role = {
|
|
46
|
+
"name": "agent",
|
|
47
|
+
"image": image("Dockerfile", context = "//lib/anyswarm-bridge"),
|
|
48
|
+
"user": AGENT_USER,
|
|
49
|
+
"needs": agent,
|
|
50
|
+
"runtime": {"agent": {
|
|
51
|
+
"command": {"argv": ["/bin/sh", "-c", "while :; do sleep 1; done"], "cwd": "/pumpkin"},
|
|
52
|
+
"finalize_grace_seconds": 1,
|
|
53
|
+
}},
|
|
54
|
+
}
|
|
55
|
+
elif AGENT == "reference":`);
|
|
56
|
+
}
|
|
57
|
+
export async function judgeImages(record) {
|
|
58
|
+
const ir = JSON.parse(await readFile(join(record, 'ir.json'), 'utf8'));
|
|
59
|
+
function image(name) {
|
|
60
|
+
const roles = ir.roles?.filter((role) => role.name === name);
|
|
61
|
+
const id = roles?.[0]?.image;
|
|
62
|
+
if (roles?.length !== 1 || typeof id !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(id)) {
|
|
63
|
+
throw new Error(`Cannot establish pinned Pumpkin image for ${name}`);
|
|
64
|
+
}
|
|
65
|
+
return id;
|
|
66
|
+
}
|
|
67
|
+
return { train_judge: image('train_judge'), final_judge: image('final_judge') };
|
|
68
|
+
}
|
|
69
|
+
const runId = /^\d{8}-\d{6}-[a-f0-9]{8}$/;
|
|
70
|
+
export class FrontierRun {
|
|
71
|
+
paths;
|
|
72
|
+
runs;
|
|
73
|
+
id;
|
|
74
|
+
container;
|
|
75
|
+
imageId;
|
|
76
|
+
judges;
|
|
77
|
+
closed = false;
|
|
78
|
+
constructor(paths, runs) {
|
|
79
|
+
this.paths = paths;
|
|
80
|
+
this.runs = runs;
|
|
81
|
+
}
|
|
82
|
+
pumpkin(args, timeoutMs, signal) {
|
|
83
|
+
return command('./pumpkin', args, { cwd: this.paths.source, env: { ...process.env, XDG_CACHE_HOME: this.paths.cache }, timeoutMs, signal });
|
|
84
|
+
}
|
|
85
|
+
docker(args, timeoutMs, signal, input) {
|
|
86
|
+
return command('docker', ['--context', this.paths.dockerContext, ...args], { timeoutMs, signal, input });
|
|
87
|
+
}
|
|
88
|
+
get record() { return this.id ? join(this.runs, this.id) : undefined; }
|
|
89
|
+
async start(seconds, signal, timeoutMs = 360_000) {
|
|
90
|
+
await mkdir(this.runs, { recursive: true, mode: 0o700 });
|
|
91
|
+
const start = await this.pumpkin(['run', frontierTask, '--arg', 'agent=anyswarm', '--arg', `deadline_seconds=${seconds}`,
|
|
92
|
+
'--config', this.paths.config, '--runs', this.runs], timeoutMs, signal);
|
|
93
|
+
const id = requireSuccess(start, 'Start official Pumpkin workflow').split(/\s+/)[0];
|
|
94
|
+
if (!runId.test(id))
|
|
95
|
+
throw new Error('Pumpkin returned an invalid run ID');
|
|
96
|
+
this.id = id;
|
|
97
|
+
const started = AbortSignal.any([signal, AbortSignal.timeout(20_000)]);
|
|
98
|
+
while (!this.container) {
|
|
99
|
+
const result = await this.docker(['container', 'ls', '--no-trunc', '--filter', `label=pumpkin.run=${id}`,
|
|
100
|
+
'--filter', 'label=pumpkin.role=agent', '--format', '{{.ID}}'], 5_000, started);
|
|
101
|
+
const ids = requireSuccess(result, 'Find the official agent role').split(/\s+/).filter(Boolean);
|
|
102
|
+
if (ids.length > 1 || (ids.length && !/^[a-f0-9]{64}$/.test(ids[0])))
|
|
103
|
+
throw new Error('Ambiguous Pumpkin agent container');
|
|
104
|
+
this.container = ids[0];
|
|
105
|
+
if (!this.container)
|
|
106
|
+
await delay(250, undefined, { signal: started });
|
|
107
|
+
}
|
|
108
|
+
this.imageId = requireSuccess(await this.docker(['inspect', '--format', '{{.Image}}', this.container], 5_000, started), 'Inspect bridge image');
|
|
109
|
+
const record = this.record;
|
|
110
|
+
this.judges = await judgeImages(record);
|
|
111
|
+
const ir = JSON.parse(await readFile(join(record, 'ir.json'), 'utf8'));
|
|
112
|
+
const role = ir.roles?.find((role) => role.name === 'agent');
|
|
113
|
+
const grantTrain = role?.runtime?.agent?.grants?.find((grant) => grant.name === 'train');
|
|
114
|
+
const grantFinal = role?.runtime?.agent?.grants?.find((grant) => grant.name === 'final');
|
|
115
|
+
if (grantTrain?.job?.target !== 'train_judge' || !(grantTrain.job.calls >= 8) ||
|
|
116
|
+
grantTrain.job.payload_max_bytes !== submissionLimit || grantFinal?.now?.payload_max_bytes !== submissionLimit ||
|
|
117
|
+
grantFinal.now.body?.arguments?.finalize?.type !== 'bool' || ir.final?.target !== undefined && ir.final.target !== 'final_judge') {
|
|
118
|
+
throw new Error('The Pumpkin role does not have the pinned train and final grants');
|
|
119
|
+
}
|
|
120
|
+
const grants = await this.docker(['exec', this.container, '/bin/sh', '-eu', '-c',
|
|
121
|
+
'test -w /pumpkin; exec /.pumpkin/bin/sandboxctl ops'], 5_000, started);
|
|
122
|
+
const ops = JSON.parse(requireSuccess(grants, 'Check official Pumpkin grants and submission scratch space'));
|
|
123
|
+
if (ops.kind !== 'ops')
|
|
124
|
+
throw new Error('The Pumpkin role has no official grants');
|
|
125
|
+
}
|
|
126
|
+
async call(name, bytes, signal) {
|
|
127
|
+
if (!this.container || this.closed)
|
|
128
|
+
throw new Error('Pumpkin submission role is unavailable');
|
|
129
|
+
const result = await this.docker(['exec', '-i', this.container, '/bin/sh', '-eu', '-c',
|
|
130
|
+
'umask 077; file="/pumpkin/$1.tar"; shift; trap \'rm -f -- "$file"\' EXIT; cat > "$file"; name="$1"; shift; /.pumpkin/bin/sandboxctl call "$name" "$file" "$@"',
|
|
131
|
+
'anyswarm-submit', randomUUID(), name, ...(name === 'final' ? ['--arg', 'finalize=true'] : [])], 15_000, signal, bytes);
|
|
132
|
+
if (!result.stdout.trim()) {
|
|
133
|
+
throw new Error(`Official ${name} admission is unknown: ${result.stderr.trim().slice(-320) || `exit ${result.code}`}`);
|
|
134
|
+
}
|
|
135
|
+
return JSON.parse(result.stdout);
|
|
136
|
+
}
|
|
137
|
+
async train(bytes, signal, onAdmission) {
|
|
138
|
+
const reply = await this.call('train', bytes, signal);
|
|
139
|
+
if (reply.kind === 'refused')
|
|
140
|
+
throw new Error(reply.message ?? 'Official train refused the candidate');
|
|
141
|
+
if (reply.kind !== 'call' || !Number.isSafeInteger(reply.job))
|
|
142
|
+
throw new Error('Official train admission is unknown');
|
|
143
|
+
const job = reply.job;
|
|
144
|
+
onAdmission(job);
|
|
145
|
+
const deadline = AbortSignal.any([signal, AbortSignal.timeout(judgeTimeMs)]);
|
|
146
|
+
while (true) {
|
|
147
|
+
const reply = await this.docker(['exec', this.container, '/.pumpkin/bin/sandboxctl', 'status', String(job)], 5_000, deadline);
|
|
148
|
+
const state = JSON.parse(reply.stdout);
|
|
149
|
+
if (state.kind !== 'status' || state.job !== job)
|
|
150
|
+
throw new Error('Official train status is unknown');
|
|
151
|
+
if (state.state === 'completed' && state.returned)
|
|
152
|
+
return { job, returned: state.returned };
|
|
153
|
+
if (state.state === 'errored')
|
|
154
|
+
throw new Error(`Official train job ${job} failed`);
|
|
155
|
+
if (state.state !== 'queued' && state.state !== 'running')
|
|
156
|
+
throw new Error(`Official train job ${job} has an unknown status`);
|
|
157
|
+
await delay(750, undefined, { signal: deadline });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async finish(bytes, signal) {
|
|
161
|
+
const sha256 = digest(bytes);
|
|
162
|
+
const reply = await this.call('final', bytes, signal).catch(() => undefined);
|
|
163
|
+
if (reply?.kind === 'refused')
|
|
164
|
+
throw new Error(reply.message ?? 'Official final refused the candidate');
|
|
165
|
+
// A missing acknowledgement may still have stored and locked the payload. Verify
|
|
166
|
+
// the authoritative outcome against the immutable payload before crediting it.
|
|
167
|
+
const { outcome, record } = await this.outcome(signal);
|
|
168
|
+
const submission = outcome.agents?.find(agent => agent.role === 'agent')?.submission;
|
|
169
|
+
if (outcome.state !== 'finished' || outcome.verdict?.kind !== 'returned' ||
|
|
170
|
+
submission?.payload?.digest !== `sha256:${sha256}` || submission.payload.size !== bytes.byteLength || !submission.finalized) {
|
|
171
|
+
throw new Error('Official final result could not be associated with the selected candidate');
|
|
172
|
+
}
|
|
173
|
+
return { record, submission, verdict: outcome.verdict, usage: outcome.usage ?? null, driver: outcome.driver ?? null };
|
|
174
|
+
}
|
|
175
|
+
async outcome(signal) {
|
|
176
|
+
const record = this.record;
|
|
177
|
+
if (!record)
|
|
178
|
+
throw new Error('There is no official Pumpkin run');
|
|
179
|
+
await this.pumpkin(['wait', '--runs', this.runs, '--outcome', this.id], frontierFinalTimeMs, signal);
|
|
180
|
+
const outcome = JSON.parse(await readFile(join(record, 'outcome.json'), 'utf8'));
|
|
181
|
+
this.closed = outcome.state === 'finished';
|
|
182
|
+
return { outcome, record };
|
|
183
|
+
}
|
|
184
|
+
async close() {
|
|
185
|
+
try {
|
|
186
|
+
const ids = this.id ? [this.id] : (await readdir(this.runs, { withFileTypes: true }).catch(() => []))
|
|
187
|
+
.filter(entry => entry.isDirectory() && runId.test(entry.name)).map(entry => entry.name);
|
|
188
|
+
for (const id of ids) {
|
|
189
|
+
const finished = this.closed || await readFile(join(this.runs, id, 'outcome.json'), 'utf8')
|
|
190
|
+
.then(raw => JSON.parse(raw).state === 'finished').catch(() => false);
|
|
191
|
+
if (!finished)
|
|
192
|
+
await this.pumpkin(['cancel', '--runs', this.runs, id], 20_000).catch(() => { });
|
|
193
|
+
const remaining = await this.docker(['container', 'ls', '-a', '--filter', `label=pumpkin.run=${id}`, '--format', '{{.ID}}'], 5_000);
|
|
194
|
+
if (remaining.code !== 0 || remaining.stdout.trim())
|
|
195
|
+
return 'pending';
|
|
196
|
+
}
|
|
197
|
+
return 'complete';
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return 'pending';
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
export async function installBridge(source) {
|
|
205
|
+
const file = join(source, 'lib', 'fcs.star');
|
|
206
|
+
const original = await readFile(file, 'utf8');
|
|
207
|
+
const role = join(source, 'lib', 'anyswarm-bridge');
|
|
208
|
+
await mkdir(role, { recursive: true, mode: 0o700 });
|
|
209
|
+
await writeFile(join(role, 'Dockerfile'), bridgeDockerfile);
|
|
210
|
+
await writeFile(file, bridgeWorkflow(original));
|
|
211
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type ResearchBudget } from './config.js';
|
|
2
|
+
import { type FrontierPaths, type JudgeImages } from './frontiercs2.js';
|
|
3
|
+
export declare function resourcePlan(budget: ResearchBudget): {
|
|
4
|
+
roles: {
|
|
5
|
+
role: string;
|
|
6
|
+
count: number;
|
|
7
|
+
cpu: number;
|
|
8
|
+
memoryGiB: number;
|
|
9
|
+
}[];
|
|
10
|
+
cpu: number;
|
|
11
|
+
memoryGiB: number;
|
|
12
|
+
diskGiB: number;
|
|
13
|
+
gpu: number;
|
|
14
|
+
};
|
|
15
|
+
export interface Check {
|
|
16
|
+
name: string;
|
|
17
|
+
ok: boolean;
|
|
18
|
+
detail: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function checkKimiRoute(signal: AbortSignal): Promise<Check[]>;
|
|
21
|
+
export declare function loadPrepared(home?: string): Promise<{
|
|
22
|
+
saved: {
|
|
23
|
+
version: 2;
|
|
24
|
+
revision: string;
|
|
25
|
+
pumpkin: string;
|
|
26
|
+
sourceDigest: string;
|
|
27
|
+
bridgeDigest: string;
|
|
28
|
+
bridgeImage: string;
|
|
29
|
+
judges: JudgeImages;
|
|
30
|
+
dockerContext: string;
|
|
31
|
+
referenceRecord: string;
|
|
32
|
+
budget: ResearchBudget;
|
|
33
|
+
};
|
|
34
|
+
paths: FrontierPaths;
|
|
35
|
+
budget: ResearchBudget;
|
|
36
|
+
starter: string;
|
|
37
|
+
}>;
|
|
38
|
+
export declare function prepareFrontier({ signal, progress, home }: {
|
|
39
|
+
signal: AbortSignal;
|
|
40
|
+
progress: (message: string) => void;
|
|
41
|
+
home?: string;
|
|
42
|
+
}): Promise<{
|
|
43
|
+
ok: boolean;
|
|
44
|
+
benchmark: string;
|
|
45
|
+
pumpkin: string;
|
|
46
|
+
budget: ResearchBudget;
|
|
47
|
+
resources: {
|
|
48
|
+
roles: {
|
|
49
|
+
role: string;
|
|
50
|
+
count: number;
|
|
51
|
+
cpu: number;
|
|
52
|
+
memoryGiB: number;
|
|
53
|
+
}[];
|
|
54
|
+
cpu: number;
|
|
55
|
+
memoryGiB: number;
|
|
56
|
+
diskGiB: number;
|
|
57
|
+
gpu: number;
|
|
58
|
+
};
|
|
59
|
+
checks: Check[];
|
|
60
|
+
home: string;
|
|
61
|
+
modelInference: 'not-attempted';
|
|
62
|
+
} | {
|
|
63
|
+
benchmark: string;
|
|
64
|
+
pumpkin: string;
|
|
65
|
+
budget: ResearchBudget;
|
|
66
|
+
resources: {
|
|
67
|
+
roles: {
|
|
68
|
+
role: string;
|
|
69
|
+
count: number;
|
|
70
|
+
cpu: number;
|
|
71
|
+
memoryGiB: number;
|
|
72
|
+
}[];
|
|
73
|
+
cpu: number;
|
|
74
|
+
memoryGiB: number;
|
|
75
|
+
diskGiB: number;
|
|
76
|
+
gpu: number;
|
|
77
|
+
};
|
|
78
|
+
checks: Check[];
|
|
79
|
+
home: string;
|
|
80
|
+
modelInference: 'not-attempted';
|
|
81
|
+
ok: boolean;
|
|
82
|
+
reused: boolean;
|
|
83
|
+
prepared: {
|
|
84
|
+
version: 2;
|
|
85
|
+
revision: string;
|
|
86
|
+
pumpkin: string;
|
|
87
|
+
sourceDigest: string;
|
|
88
|
+
bridgeDigest: string;
|
|
89
|
+
bridgeImage: string;
|
|
90
|
+
judges: JudgeImages;
|
|
91
|
+
dockerContext: string;
|
|
92
|
+
referenceRecord: string;
|
|
93
|
+
budget: ResearchBudget;
|
|
94
|
+
};
|
|
95
|
+
}>;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { availableParallelism, freemem } from 'node:os';
|
|
2
|
+
import { cp, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, statfs, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { defaultResearchConnection, frontierBudget, frontierHome, kimiModel } from './config.js';
|
|
5
|
+
import { bridgeDockerfile, bridgeWorkflow, digest, FrontierRun, frontierRevision, frontierTask, installBridge, judgeImages, pumpkinPin } from './frontiercs2.js';
|
|
6
|
+
import { command, requireSuccess } from './process.js';
|
|
7
|
+
const upstream = 'https://github.com/FrontierCS/FrontierCS-2.git';
|
|
8
|
+
const taskPackage = 'tasks/binary_fuse_filter';
|
|
9
|
+
const shared = ['fetch', 'lib', 'shared', taskPackage];
|
|
10
|
+
const GiB = 1024 ** 3;
|
|
11
|
+
const prepareTimeout = 2_700_000;
|
|
12
|
+
const pinFiles = ['.pumpkinversion', 'PUMPKIN.star', 'pumpkin', ...shared];
|
|
13
|
+
export function resourcePlan(budget) {
|
|
14
|
+
const roles = [
|
|
15
|
+
{ role: 'AnySwarm Workers', count: budget.workers, cpu: 2, memoryGiB: 4 },
|
|
16
|
+
{ role: 'Pumpkin submission role', count: 1, cpu: 2, memoryGiB: 4 },
|
|
17
|
+
{ role: 'Active judge', count: 1, cpu: 2, memoryGiB: 4 },
|
|
18
|
+
{ role: 'Host and services headroom', count: 1, cpu: 2, memoryGiB: 2 },
|
|
19
|
+
{ role: 'Image build headroom', count: 1, cpu: 2, memoryGiB: 4 },
|
|
20
|
+
];
|
|
21
|
+
return {
|
|
22
|
+
roles, cpu: roles.reduce((n, role) => n + role.count * role.cpu, 0),
|
|
23
|
+
memoryGiB: roles.reduce((n, role) => n + role.count * role.memoryGiB, 0), diskGiB: 12, gpu: 0,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export async function checkKimiRoute(signal) {
|
|
27
|
+
let model;
|
|
28
|
+
try {
|
|
29
|
+
model = kimiModel();
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return [{ name: 'kimi-k3-config', ok: false, detail: error.message }];
|
|
33
|
+
}
|
|
34
|
+
const config = { name: 'kimi-k3-config', ok: true, detail: 'Configured provider, model ID and fixed Responses URL.' };
|
|
35
|
+
const name = 'kimi-k3-route';
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(model.upstream.url, {
|
|
38
|
+
method: 'HEAD', headers: model.upstream.headers, redirect: 'manual',
|
|
39
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(5000)]),
|
|
40
|
+
});
|
|
41
|
+
const ok = response.ok || response.status === 405;
|
|
42
|
+
const detail = ok ? `Endpoint responded to HEAD (HTTP ${response.status}).`
|
|
43
|
+
: [401, 403].includes(response.status) ? `HEAD denied (HTTP ${response.status}). Check the proxy's access policy and token.`
|
|
44
|
+
: `Unexpected response to HEAD (HTTP ${response.status}). Check the configured Responses route.`;
|
|
45
|
+
return [config, { name, ok, detail }];
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
signal.throwIfAborted();
|
|
49
|
+
return [config, { name, ok: false, detail: 'Could not reach the Responses route within 5 seconds. Check the endpoint and connectivity.' }];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function paths(home, dockerContext) {
|
|
53
|
+
return { source: join(home, 'bridge'), config: join(home, 'pumpkin.toml'), dockerContext, cache: join(home, 'cache') };
|
|
54
|
+
}
|
|
55
|
+
export async function loadPrepared(home = frontierHome()) {
|
|
56
|
+
const saved = JSON.parse(await readFile(join(home, 'prepared.json'), 'utf8'));
|
|
57
|
+
if (saved.version !== 2 || saved.revision !== frontierRevision || saved.pumpkin !== pumpkinPin ||
|
|
58
|
+
!/^[a-zA-Z0-9._-]+$/.test(saved.dockerContext))
|
|
59
|
+
throw new Error('Run anys autoresearch demo frontiercs2 --prepare to refresh this demo.');
|
|
60
|
+
const locations = paths(home, saved.dockerContext);
|
|
61
|
+
const reference = join(home, 'reference');
|
|
62
|
+
const [bridgeDigest, sourceDigest] = await Promise.all([treeDigest(locations.source), treeDigest(reference)]);
|
|
63
|
+
const activeWorkflow = await readFile(join(locations.source, 'lib', 'fcs.star'), 'utf8');
|
|
64
|
+
const officialWorkflow = await readFile(join(reference, 'lib', 'fcs.star'), 'utf8');
|
|
65
|
+
const roleDockerfile = await readFile(join(locations.source, 'lib', 'anyswarm-bridge', 'Dockerfile'), 'utf8');
|
|
66
|
+
const activeConfig = await readFile(locations.config, 'utf8');
|
|
67
|
+
if (saved.bridgeDigest !== bridgeDigest || saved.sourceDigest !== sourceDigest || activeWorkflow !== bridgeWorkflow(officialWorkflow) ||
|
|
68
|
+
roleDockerfile !== bridgeDockerfile || activeConfig !== pumpkinConfig(saved.dockerContext))
|
|
69
|
+
throw new Error('Prepared FrontierCS-2 materials changed. Refresh with --prepare.');
|
|
70
|
+
const budget = frontierBudget(saved.budget);
|
|
71
|
+
const starter = join(reference, taskPackage, 'repo');
|
|
72
|
+
const tracked = requireSuccess(await command('git', ['ls-files', '--', 'README.md', 'include/binaryfusefilter.h'], { cwd: starter, timeoutMs: 5000 }), 'Validate tracked FrontierCS-2 starter');
|
|
73
|
+
if (!tracked.split('\n').includes('README.md') || !tracked.split('\n').includes('include/binaryfusefilter.h')) {
|
|
74
|
+
throw new Error('The pinned Git starter is missing required tracked files. Refresh with --prepare.');
|
|
75
|
+
}
|
|
76
|
+
return { saved: { ...saved, budget }, paths: locations, budget, starter };
|
|
77
|
+
}
|
|
78
|
+
async function treeDigest(root) {
|
|
79
|
+
const hashes = [];
|
|
80
|
+
async function visit(relative) {
|
|
81
|
+
const absolute = join(root, relative);
|
|
82
|
+
const metadata = await lstat(absolute);
|
|
83
|
+
if (metadata.isDirectory()) {
|
|
84
|
+
for (const item of (await readdir(absolute)).sort())
|
|
85
|
+
await visit(join(relative, item));
|
|
86
|
+
}
|
|
87
|
+
else if (metadata.isFile()) {
|
|
88
|
+
hashes.push({ relative, digest: digest(await readFile(absolute)) });
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
throw new Error('Unexpected link or special file in pinned task materials');
|
|
92
|
+
}
|
|
93
|
+
for (const relative of pinFiles)
|
|
94
|
+
await visit(relative);
|
|
95
|
+
return digest(JSON.stringify(hashes));
|
|
96
|
+
}
|
|
97
|
+
async function sourceAt(home, signal) {
|
|
98
|
+
const cached = join(home, 'reference');
|
|
99
|
+
if (await readFile(join(cached, '.pumpkinversion'), 'utf8').catch(() => '') === pumpkinPin + '\n') {
|
|
100
|
+
const head = await command('git', ['rev-parse', 'HEAD'], { cwd: cached, timeoutMs: 5000, signal });
|
|
101
|
+
const status = await command('git', ['status', '--porcelain', '--untracked-files=no'], { cwd: cached, timeoutMs: 10_000, signal });
|
|
102
|
+
if (head.stdout.trim() === frontierRevision && status.code === 0 && !status.stdout.trim())
|
|
103
|
+
return cached;
|
|
104
|
+
throw new Error('Prepared reference source has local changes. Move it aside and re-run --prepare.');
|
|
105
|
+
}
|
|
106
|
+
const temp = await mkdtemp(join(home, 'source-'));
|
|
107
|
+
const git = async (args, timeoutMs) => requireSuccess(await command('git', args, { cwd: temp, timeoutMs, env: { ...process.env, GIT_LFS_SKIP_SMUDGE: '1' }, signal }), 'Prepare pinned FrontierCS-2 source');
|
|
108
|
+
try {
|
|
109
|
+
await git(['init', '--quiet'], 5000);
|
|
110
|
+
await git(['remote', 'add', 'origin', upstream], 5000);
|
|
111
|
+
await git(['fetch', '--quiet', '--filter=blob:none', '--depth=1', 'origin', frontierRevision], 240_000);
|
|
112
|
+
await git(['sparse-checkout', 'set', '--cone', ...shared], 30_000);
|
|
113
|
+
await git(['checkout', '--quiet', '--detach', frontierRevision], 240_000);
|
|
114
|
+
await git(['lfs', 'pull', '--include', shared.map(item => item + '/**').join(',')], 240_000);
|
|
115
|
+
if ((await readFile(join(temp, '.pumpkinversion'), 'utf8')).trim() !== pumpkinPin)
|
|
116
|
+
throw new Error('Unexpected Pumpkin release pin');
|
|
117
|
+
await rename(temp, cached);
|
|
118
|
+
return cached;
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
await rm(temp, { recursive: true, force: true });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const pumpkinConfig = (context) => `[docker]\ncontext = ${JSON.stringify(context)}\n\n[providers.local.docker]\n`;
|
|
125
|
+
async function verifyReference(record) {
|
|
126
|
+
const outcome = JSON.parse(await readFile(join(record, 'outcome.json'), 'utf8'));
|
|
127
|
+
const events = (await readFile(join(record, 'log.jsonl'), 'utf8')).trim().split('\n').map(line => JSON.parse(line));
|
|
128
|
+
const actions = events.flatMap(entry => entry.actions ?? []);
|
|
129
|
+
const train = actions.find(action => action.kind === 'start_call' && action.grant === 'train');
|
|
130
|
+
const final = actions.find(action => action.kind === 'start_final_call');
|
|
131
|
+
const submission = outcome.agents?.find((agent) => agent.role === 'agent')?.submission;
|
|
132
|
+
const returned = (job) => events.some(({ event }) => event?.job === job && event.kind === 'call_returned');
|
|
133
|
+
if (outcome.state !== 'finished' || outcome.verdict?.kind !== 'returned' || outcome.usage?.model_requests !== 0 ||
|
|
134
|
+
!submission?.finalized || !train || !final || !returned(train.job) || !returned(final.job) ||
|
|
135
|
+
!final.selections?.some((item) => item.role === 'agent' && item.selection?.digest === submission.payload?.digest)) {
|
|
136
|
+
throw new Error(`The reference record does not establish completed no-model train and final: ${record}`);
|
|
137
|
+
}
|
|
138
|
+
return await judgeImages(record);
|
|
139
|
+
}
|
|
140
|
+
async function referenceRecord(source, state, home, signal) {
|
|
141
|
+
const runs = await mkdtemp(join(home, 'reference-'));
|
|
142
|
+
const reference = new FrontierRun({ ...state, source }, runs);
|
|
143
|
+
try {
|
|
144
|
+
const result = await command('./pumpkin', ['run', frontierTask, '--arg', 'agent=reference', '--arg', 'deadline_seconds=360',
|
|
145
|
+
'--config', state.config, '--runs', runs, '--wait', '--outcome'], {
|
|
146
|
+
cwd: source, signal, timeoutMs: prepareTimeout, env: { ...process.env, XDG_CACHE_HOME: state.cache },
|
|
147
|
+
});
|
|
148
|
+
await writeFile(join(runs, 'launcher.log'), result.stdout + '\n' + result.stderr, { mode: 0o600 });
|
|
149
|
+
requireSuccess(result, 'Official no-model reference self-check');
|
|
150
|
+
for (const entry of await readdir(runs, { withFileTypes: true })) {
|
|
151
|
+
if (!entry.isDirectory())
|
|
152
|
+
continue;
|
|
153
|
+
const record = join(runs, entry.name);
|
|
154
|
+
const judges = await verifyReference(record);
|
|
155
|
+
return { record, judges };
|
|
156
|
+
}
|
|
157
|
+
throw new Error(`The reference record does not establish completed train and final: ${runs}`);
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
if (await reference.close() !== 'complete')
|
|
161
|
+
throw new Error(`Pumpkin reference cleanup is pending: ${runs}`);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export async function prepareFrontier({ signal, progress, home = frontierHome() }) {
|
|
165
|
+
const budget = frontierBudget();
|
|
166
|
+
const resources = resourcePlan(budget);
|
|
167
|
+
const checks = [];
|
|
168
|
+
const check = (name, ok, detail) => checks.push({ name, ok, detail });
|
|
169
|
+
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
170
|
+
check('linux-x86-64', process.platform === 'linux' && process.arch === 'x64', 'FrontierCS-2 requires Linux x86-64.');
|
|
171
|
+
await Promise.all([
|
|
172
|
+
['git', ['--version'], 'Install Git.'], ['git-lfs', ['version'], 'Install Git LFS and expose git-lfs on PATH.'],
|
|
173
|
+
['python3', ['--version'], 'Install Python 3.'],
|
|
174
|
+
].map(async ([tool, args, remedy]) => {
|
|
175
|
+
const result = await command(tool, args, { timeoutMs: 5000, signal }).catch(() => undefined);
|
|
176
|
+
check(tool, result?.code === 0, result?.stdout.trim() || remedy);
|
|
177
|
+
}));
|
|
178
|
+
const local = await command('docker', ['context', 'show'], { timeoutMs: 5000, signal }).catch(() => undefined);
|
|
179
|
+
const dockerContext = local?.code === 0 ? local.stdout.trim() : '';
|
|
180
|
+
const validContext = /^[a-zA-Z0-9._-]+$/.test(dockerContext);
|
|
181
|
+
check('docker-cli', validContext, validContext ? dockerContext : 'Install Docker CLI and select a local context.');
|
|
182
|
+
const info = validContext ? await command('docker', ['--context', dockerContext, 'info', '--format',
|
|
183
|
+
'{{.OSType}} {{.Architecture}} {{.NCPU}} {{.MemTotal}}'], { timeoutMs: 8000, signal }).catch(() => undefined) : undefined;
|
|
184
|
+
const [os, arch, cpu, memory] = info?.stdout.trim().split(/\s+/) ?? [];
|
|
185
|
+
check('docker-daemon', info?.code === 0 && os === 'linux' && ['x86_64', 'amd64'].includes(arch), info?.code === 0 ? `${os}/${arch}, ${cpu} CPUs, ${Math.floor(Number(memory) / GiB)} GiB` : 'Start Docker and verify daemon access with docker info.');
|
|
186
|
+
const disk = await statfs(home);
|
|
187
|
+
const diskGiB = disk.bavail * disk.bsize / GiB;
|
|
188
|
+
check('resources', Math.min(availableParallelism(), Number(cpu)) >= resources.cpu &&
|
|
189
|
+
Math.min(freemem(), Number(memory)) >= resources.memoryGiB * GiB && diskGiB >= resources.diskGiB && disk.ffree >= 25_000, `Plan: ${resources.cpu} CPUs, ${resources.memoryGiB} GiB RAM, ${resources.diskGiB} GiB disk and 25000 free inodes for the four-worker demo. Available disk: ${Math.floor(diskGiB)} GiB, ${disk.ffree} inodes.`);
|
|
190
|
+
checks.push(...await checkKimiRoute(signal));
|
|
191
|
+
try {
|
|
192
|
+
const { sandbox, image } = defaultResearchConnection();
|
|
193
|
+
const url = sandbox.lifecycleBaseUrl.replace(/\/$/, '') + '/sandboxes?page=1&pageSize=1';
|
|
194
|
+
const deadline = AbortSignal.any([signal, AbortSignal.timeout(8000)]);
|
|
195
|
+
const [authenticated, anonymous] = await Promise.all([
|
|
196
|
+
fetch(url, { redirect: 'error', signal: deadline, headers: { 'OPEN-SANDBOX-API-KEY': sandbox.apiKey ?? '' } }),
|
|
197
|
+
fetch(url, { redirect: 'error', signal: deadline }),
|
|
198
|
+
]);
|
|
199
|
+
const ok = Boolean(sandbox.apiKey && authenticated.ok && [401, 403].includes(anonymous.status) && sandbox.egressMode === 'dns+nft');
|
|
200
|
+
await Promise.all([authenticated.body?.cancel(), anonymous.body?.cancel()]);
|
|
201
|
+
check('opensandbox', ok, ok ? 'Authenticated Lifecycle endpoint.' : 'Configure an authenticated OpenSandbox with dns+nft egress and run anys doctor.');
|
|
202
|
+
const worker = validContext && await command('docker', ['--context', dockerContext, 'image', 'inspect', '--format', '{{.Id}}', image], { timeoutMs: 8000, signal }).catch(() => undefined);
|
|
203
|
+
check('worker-image', !!worker && worker.code === 0, worker && worker.code === 0 ? worker.stdout.trim() : 'Select the prepared AnySwarm Worker image for this Docker daemon.');
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
check('opensandbox', false, `Check the existing endpoint with anys doctor. ${error.name}`);
|
|
207
|
+
}
|
|
208
|
+
const report = { ok: false, benchmark: frontierRevision, pumpkin: pumpkinPin, budget, resources, checks, home, modelInference: 'not-attempted' };
|
|
209
|
+
if (checks.some(row => !row.ok))
|
|
210
|
+
return report;
|
|
211
|
+
signal.throwIfAborted();
|
|
212
|
+
const state = paths(home, dockerContext);
|
|
213
|
+
const lock = join(home, 'preparing');
|
|
214
|
+
await mkdir(lock, { mode: 0o700 }).catch(() => { throw new Error('FrontierCS-2 preparation is already active. Inspect the preparing directory before retrying.'); });
|
|
215
|
+
try {
|
|
216
|
+
const source = await sourceAt(home, signal);
|
|
217
|
+
const sourceDigest = await treeDigest(source);
|
|
218
|
+
const current = await loadPrepared(home).catch(() => undefined);
|
|
219
|
+
if (current?.saved.sourceDigest === sourceDigest && current.saved.dockerContext === dockerContext &&
|
|
220
|
+
await readFile(join(current.saved.referenceRecord, 'outcome.json'), 'utf8').catch(() => '')) {
|
|
221
|
+
const judges = await verifyReference(current.saved.referenceRecord);
|
|
222
|
+
if (JSON.stringify(judges) !== JSON.stringify(current.saved.judges))
|
|
223
|
+
throw new Error('Prepared judge identity changed.');
|
|
224
|
+
const cachedImage = await command('docker', ['--context', dockerContext, 'image', 'inspect', current.saved.bridgeImage, ...Object.values(judges)], { timeoutMs: 8000, signal });
|
|
225
|
+
if (cachedImage.code === 0)
|
|
226
|
+
return { ...report, ok: true, reused: true, prepared: current.saved };
|
|
227
|
+
}
|
|
228
|
+
await writeFile(state.config, pumpkinConfig(dockerContext), { mode: 0o600 });
|
|
229
|
+
progress('Validating official FrontierCS-2 reference and building pinned judge images.');
|
|
230
|
+
const reference = await referenceRecord(source, state, home, signal);
|
|
231
|
+
await mkdir(state.source, { recursive: true, mode: 0o700 });
|
|
232
|
+
for (const relative of pinFiles)
|
|
233
|
+
await cp(join(source, relative), join(state.source, relative), { recursive: true });
|
|
234
|
+
await installBridge(state.source);
|
|
235
|
+
progress('Preparing the authorized AnySwarm submission role and checking its grants.');
|
|
236
|
+
const bridgeRuns = await mkdtemp(join(home, 'bridge-check-'));
|
|
237
|
+
const bridge = new FrontierRun(state, bridgeRuns);
|
|
238
|
+
try {
|
|
239
|
+
await bridge.start(120, signal, prepareTimeout);
|
|
240
|
+
if (JSON.stringify(bridge.judges) !== JSON.stringify(reference.judges))
|
|
241
|
+
throw new Error('Submission bridge changed the official judge images');
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
if (await bridge.close() !== 'complete')
|
|
245
|
+
throw new Error(`Pumpkin submission role cleanup is pending: ${bridge.record}`);
|
|
246
|
+
}
|
|
247
|
+
const manifest = { version: 2, revision: frontierRevision, pumpkin: pumpkinPin, sourceDigest,
|
|
248
|
+
bridgeDigest: await treeDigest(state.source), bridgeImage: bridge.imageId, dockerContext, budget, referenceRecord: reference.record, judges: reference.judges };
|
|
249
|
+
const pending = join(lock, 'prepared.json');
|
|
250
|
+
await writeFile(pending, JSON.stringify(manifest, null, 2) + '\n', { mode: 0o600 });
|
|
251
|
+
await rename(pending, join(home, 'prepared.json'));
|
|
252
|
+
return { ...report, ok: true, reused: false, prepared: manifest };
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
await rm(lock, { recursive: true, force: true });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ProcessResult {
|
|
2
|
+
code: number | null;
|
|
3
|
+
stdout: string;
|
|
4
|
+
stderr: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function command(executable: string, args: readonly string[], options: {
|
|
7
|
+
cwd?: string;
|
|
8
|
+
env?: NodeJS.ProcessEnv;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
timeoutMs: number;
|
|
11
|
+
input?: Uint8Array;
|
|
12
|
+
}): Promise<ProcessResult>;
|
|
13
|
+
export declare function requireSuccess(result: ProcessResult, description: string): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
export function command(executable, args, options) {
|
|
3
|
+
const { cwd, env, input } = options;
|
|
4
|
+
const timer = AbortSignal.timeout(options.timeoutMs);
|
|
5
|
+
const signal = options.signal ? AbortSignal.any([options.signal, timer]) : timer;
|
|
6
|
+
signal.throwIfAborted();
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const child = spawn(executable, args, { cwd, env, signal, detached: true, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
9
|
+
const stdout = [], stderr = [];
|
|
10
|
+
let bytes = 0;
|
|
11
|
+
let failure;
|
|
12
|
+
const kill = () => {
|
|
13
|
+
if (!child.pid)
|
|
14
|
+
return;
|
|
15
|
+
try {
|
|
16
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
17
|
+
}
|
|
18
|
+
catch { /* Already exited. */ }
|
|
19
|
+
};
|
|
20
|
+
const capture = (target) => (chunk) => {
|
|
21
|
+
bytes += chunk.length;
|
|
22
|
+
if (bytes <= 1024 * 1024)
|
|
23
|
+
target.push(chunk);
|
|
24
|
+
else {
|
|
25
|
+
failure ??= new Error(`${executable} exceeded its output limit`);
|
|
26
|
+
kill();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
child.stdout.on('data', capture(stdout));
|
|
30
|
+
child.stderr.on('data', capture(stderr));
|
|
31
|
+
child.stdin.on('error', () => { });
|
|
32
|
+
child.once('error', error => { failure ??= error; });
|
|
33
|
+
signal.addEventListener('abort', kill, { once: true });
|
|
34
|
+
child.once('close', code => {
|
|
35
|
+
signal.removeEventListener('abort', kill);
|
|
36
|
+
if (failure || signal.aborted)
|
|
37
|
+
reject(failure ?? signal.reason);
|
|
38
|
+
else
|
|
39
|
+
resolve({ code, stdout: Buffer.concat(stdout).toString(), stderr: Buffer.concat(stderr).toString() });
|
|
40
|
+
});
|
|
41
|
+
child.stdin.end(input);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function requireSuccess(result, description) {
|
|
45
|
+
if (result.code !== 0)
|
|
46
|
+
throw new Error(`${description}: ${result.stderr.trim().slice(-2000) || `exit ${result.code}`}`);
|
|
47
|
+
return result.stdout.trim();
|
|
48
|
+
}
|