@anyswarm/core 0.5.2 → 0.6.0
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/AGENTS.md +19 -4
- package/README.md +68 -61
- package/dist/examples/README.md +134 -84
- package/dist/examples/autoresearch/README.md +106 -21
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +14 -6
- package/dist/examples/autoresearch/config.d.ts +48 -5
- package/dist/examples/autoresearch/config.js +57 -23
- package/dist/examples/autoresearch/demo.d.ts +12 -4
- package/dist/examples/autoresearch/demo.js +65 -22
- package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -2
- package/dist/examples/autoresearch/frontiercs2-config.js +13 -2
- package/dist/examples/autoresearch/frontiercs2.d.ts +18 -1
- package/dist/examples/autoresearch/frontiercs2.js +71 -14
- package/dist/examples/autoresearch/prepare-demo.js +34 -3
- package/dist/examples/autoresearch/prepare.d.ts +105 -53
- package/dist/examples/autoresearch/prepare.js +126 -57
- package/dist/examples/autoresearch/project.d.ts +6 -1
- package/dist/examples/autoresearch/project.js +130 -26
- package/dist/examples/autoresearch/research-service.d.ts +16 -1
- package/dist/examples/autoresearch/research-service.js +84 -44
- package/dist/examples/code/config.d.ts +1 -0
- package/dist/examples/first-harness/AGENTS.md +25 -0
- package/dist/examples/first-harness/README.md +136 -0
- package/dist/examples/first-harness/config.d.ts +9 -8
- package/dist/examples/first-harness/config.js +33 -26
- package/dist/examples/first-harness/eject.json +14 -0
- package/dist/examples/first-harness/handoff.js +3 -3
- package/dist/examples/first-harness/harness.d.ts +14 -18
- package/dist/examples/first-harness/harness.js +102 -77
- package/dist/examples/first-harness/input/README.md +7 -0
- package/dist/examples/first-harness/session.js +2 -1
- package/dist/examples/first-harness/tsconfig.json +2 -1
- package/dist/examples/harness-session/README.md +1 -1
- package/dist/examples/lead-worker/README.md +1 -1
- package/dist/examples/lead-worker/project-config.d.ts +1 -0
- package/dist/examples/messages/README.md +2 -2
- package/dist/examples/notes/README.md +2 -2
- package/dist/examples/notes/config.d.ts +1 -0
- package/dist/examples/parallel-swarm/AGENTS.md +32 -0
- package/dist/examples/parallel-swarm/README.md +136 -0
- package/dist/examples/parallel-swarm/board-service.js +25 -8
- package/dist/examples/parallel-swarm/board.d.ts +31 -1
- package/dist/examples/parallel-swarm/board.js +98 -13
- package/dist/examples/parallel-swarm/config.d.ts +11 -0
- package/dist/examples/parallel-swarm/config.js +39 -0
- package/dist/examples/parallel-swarm/eject.json +5 -0
- package/dist/examples/parallel-swarm/harness.d.ts +26 -20
- package/dist/examples/parallel-swarm/harness.js +77 -76
- package/dist/examples/parallel-swarm/report.d.ts +12 -0
- package/dist/examples/parallel-swarm/report.js +30 -0
- package/dist/examples/peermesh/README.md +1 -1
- package/dist/examples/peermesh/project-config.d.ts +1 -0
- package/dist/examples/services/agent-control/README.md +1 -1
- package/dist/examples/services/mathlib-search/README.md +1 -1
- package/dist/examples/services/mcp-managed/README.md +1 -1
- package/dist/examples/services/persistent-board/README.md +1 -1
- package/dist/examples/subagents/AGENTS.md +35 -0
- package/dist/examples/subagents/README.md +129 -93
- package/dist/examples/subagents/config.d.ts +2 -10
- package/dist/examples/subagents/config.js +8 -15
- package/dist/examples/subagents/eject.json +17 -0
- package/dist/examples/subagents/handoff-config.d.ts +41 -0
- package/dist/examples/subagents/handoff-config.js +13 -0
- package/dist/examples/subagents/model.d.ts +3 -0
- package/dist/examples/subagents/model.js +19 -0
- package/dist/examples/substrate/README.md +12 -6
- package/dist/examples/substrate/config.d.ts +1 -0
- package/dist/examples/substrate/project-config.d.ts +1 -0
- package/dist/examples/taskpool/README.md +1 -1
- package/dist/examples/taskpool/config.d.ts +1 -0
- package/dist/examples/taskpool/deploy/service-hosts/service-authority-snapshot.d.ts +4 -4
- package/dist/scripts/anyswarm-progress.js +36 -5
- package/dist/scripts/build-provenance.json +1 -1
- package/dist/scripts/generate-architecture-coverage.js +1 -1
- package/dist/scripts/generate-architecture-prompts.js +18 -10
- package/dist/scripts/local-environment.d.ts +3 -3
- package/dist/scripts/local-environment.js +6 -1
- package/dist/scripts/local-setup.js +25 -18
- package/dist/scripts/pack-release.js +27 -3
- package/dist/src/core/index.js +1 -1
- package/dist/src/core/sandbox/opensandbox-backend.js +10 -4
- package/dist/src/core/sandbox/sandbox-connection.d.ts +9 -2
- package/dist/src/core/sandbox/sandbox-connection.js +22 -7
- package/dist/src/harness/project-harness.js +3 -2
- package/dist/src/harness/project-rpc-client.js +19 -0
- package/dist/src/harness/typescript-loader.d.ts +2 -0
- package/dist/src/harness/typescript-loader.js +26 -8
- package/dist/src/trace-viewer/command.mjs +6 -3
- package/dist/src/trace-viewer/public/app.js +239 -59
- package/dist/src/trace-viewer/public/index.html +5 -0
- package/dist/src/trace-viewer/public/style.css +22 -0
- package/dist/src/trace-viewer/reader.mjs +242 -26
- package/dist/src/trace-viewer/run-root.d.mts +1 -0
- package/dist/src/trace-viewer/run-root.mjs +7 -0
- package/dist/src/trace-viewer/server.mjs +3 -1
- package/docs/INDEX.md +9 -8
- package/docs/architecture/06-observability-experiments.md +21 -7
- package/docs/architecture/07-run-configuration.md +97 -12
- package/docs/architecture/08-prompts.md +21 -2
- package/docs/architecture/10-service-api-reference.md +12 -5
- package/docs/architecture/12-code-coverage.md +129 -86
- package/docs/architecture/15-core-runtime.md +1 -1
- package/docs/architecture/16-pi-opensandbox-backend.md +2 -0
- package/docs/architecture/17-harness-reporting.md +78 -0
- package/docs/architecture/22-website.md +53 -18
- package/docs/architecture/23-project-harness.md +63 -16
- package/docs/architecture/28-autoresearch.md +16 -22
- package/docs/architecture/prompts/11-first-sdk-harness.md +9 -9
- package/docs/architecture/prompts/16-parallel-swarm.md +46 -13
- package/docs/architecture/prompts/22-autoresearch.md +9 -2
- package/docs/architecture/prompts/source-manifest.json +78 -54
- package/docs/architecture/source-map.json +396 -36
- package/docs/designs/core-harness/06-project-harness.md +1 -1
- package/docs/en/autoresearch.md +41 -0
- package/docs/en/blog/100b-tokens.md +157 -0
- package/docs/en/build-your-harness.md +47 -22
- package/docs/en/changelog.md +22 -1
- package/docs/en/first-harness.md +40 -32
- package/docs/en/harnesses/index.md +23 -23
- package/docs/en/harnesses/subagents.md +8 -29
- package/docs/en/latest.md +26 -5
- package/docs/en/overview.md +22 -22
- package/docs/en/quickstart.md +55 -21
- package/docs/en/reference/api.md +1 -1
- package/docs/en/trace-viewer.md +32 -12
- package/docs/operations/trace-viewer.md +25 -10
- package/docs/workflows/development.md +160 -120
- package/docs/workflows/release-and-docs-versioning.md +207 -55
- package/docs/workflows/release-cli-acceptance.md +124 -47
- package/docs/zh/autoresearch.md +41 -0
- package/docs/zh/blog/100b-tokens.md +102 -0
- package/docs/zh/build-your-harness.md +48 -23
- package/docs/zh/changelog.md +22 -1
- package/docs/zh/first-harness.md +43 -35
- package/docs/zh/harnesses/index.md +23 -23
- package/docs/zh/harnesses/subagents.md +8 -29
- package/docs/zh/latest.md +26 -5
- package/docs/zh/overview.md +23 -23
- package/docs/zh/quickstart.md +51 -21
- package/docs/zh/reference/api.md +1 -1
- package/docs/zh/trace-viewer.md +32 -12
- package/examples/README.md +134 -84
- package/examples/autoresearch/README.md +106 -21
- package/examples/autoresearch/REQUIREMENTS.zh.md +14 -6
- package/examples/autoresearch/config.ts +64 -25
- package/examples/autoresearch/demo.ts +75 -22
- package/examples/autoresearch/frontiercs2-config.ts +13 -2
- package/examples/autoresearch/frontiercs2.ts +64 -11
- package/examples/autoresearch/prepare-demo.ts +32 -3
- package/examples/autoresearch/prepare.ts +134 -60
- package/examples/autoresearch/project.ts +119 -26
- package/examples/autoresearch/research-service.ts +91 -41
- package/examples/first-harness/AGENTS.md +25 -0
- package/examples/first-harness/README.md +136 -0
- package/examples/first-harness/config.ts +41 -27
- package/examples/first-harness/eject.json +14 -0
- package/examples/first-harness/handoff.ts +3 -3
- package/examples/first-harness/harness.ts +104 -72
- package/examples/first-harness/input/README.md +7 -0
- package/examples/first-harness/session.ts +2 -1
- package/examples/first-harness/tsconfig.json +2 -1
- package/examples/harness-session/README.md +1 -1
- package/examples/lead-worker/README.md +1 -1
- package/examples/messages/README.md +2 -2
- package/examples/notes/README.md +2 -2
- package/examples/parallel-swarm/AGENTS.md +32 -0
- package/examples/parallel-swarm/README.md +136 -0
- package/examples/parallel-swarm/board-service.ts +28 -9
- package/examples/parallel-swarm/board.ts +107 -13
- package/examples/parallel-swarm/config.ts +47 -0
- package/examples/parallel-swarm/eject.json +5 -0
- package/examples/parallel-swarm/harness.ts +83 -71
- package/examples/parallel-swarm/report.ts +33 -0
- package/examples/peermesh/README.md +1 -1
- package/examples/services/agent-control/README.md +1 -1
- package/examples/services/mathlib-search/README.md +1 -1
- package/examples/services/mcp-managed/README.md +1 -1
- package/examples/services/persistent-board/README.md +1 -1
- package/examples/subagents/AGENTS.md +35 -0
- package/examples/subagents/README.md +129 -93
- package/examples/subagents/config.ts +8 -15
- package/examples/subagents/eject.json +17 -0
- package/examples/subagents/handoff-config.ts +14 -0
- package/examples/subagents/model.ts +20 -0
- package/examples/substrate/README.md +12 -6
- package/examples/taskpool/README.md +1 -1
- package/npm-shrinkwrap.development.json +9 -2
- package/npm-shrinkwrap.json +9 -2
- package/package.development.json +2 -1
- package/package.json +2 -1
- package/scripts/anyswarm-progress.ts +36 -6
- package/scripts/generate-architecture-coverage.ts +1 -1
- package/scripts/generate-architecture-prompts.ts +21 -10
- package/scripts/local-environment.ts +8 -1
- package/scripts/local-setup.ts +22 -17
- package/scripts/pack-release.ts +24 -3
- package/src/core/index.ts +1 -1
- package/src/core/sandbox/opensandbox-backend.ts +10 -4
- package/src/core/sandbox/sandbox-connection.ts +22 -7
- package/src/harness/project-harness.ts +3 -2
- package/src/harness/project-rpc-client.ts +23 -0
- package/src/harness/typescript-loader.ts +28 -8
- package/src/trace-viewer/command.mjs +6 -3
- package/src/trace-viewer/public/app.js +239 -59
- package/src/trace-viewer/public/index.html +5 -0
- package/src/trace-viewer/public/style.css +22 -0
- package/src/trace-viewer/reader.mjs +242 -26
- package/src/trace-viewer/run-root.d.mts +1 -0
- package/src/trace-viewer/run-root.mjs +7 -0
- package/src/trace-viewer/server.mjs +3 -1
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
import type { FrontierConfiguration } from './demo.js';
|
|
1
5
|
import { prepareFrontier } from './prepare.js';
|
|
2
6
|
|
|
3
7
|
const controller = new AbortController();
|
|
@@ -7,9 +11,34 @@ const interrupt = (signal: NodeJS.Signals) => {
|
|
|
7
11
|
};
|
|
8
12
|
process.on('SIGINT', interrupt).on('SIGTERM', interrupt);
|
|
9
13
|
try {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
const { values } = parseArgs({ options: {
|
|
15
|
+
config: { type: 'string', default: './frontiercs2-config.ts' },
|
|
16
|
+
check: { type: 'boolean' },
|
|
17
|
+
help: { type: 'boolean' },
|
|
18
|
+
} });
|
|
19
|
+
if (values.help) {
|
|
20
|
+
console.log('Usage: anyswarm run ./prepare-demo.ts [--config ./frontiercs2-config.ts] [--check]');
|
|
21
|
+
console.log('Choose an executor with anyswarm setup, then set a model and a team budget in the shared configuration. --check reports prerequisites without preparing the pinned task or calling a model.');
|
|
22
|
+
} else {
|
|
23
|
+
const { default: configuration } = await import(pathToFileURL(resolve(values.config)).href) as { default: FrontierConfiguration };
|
|
24
|
+
if (!configuration?.frontierStateDir || !configuration.budget || !configuration.sandbox || !configuration.connection) {
|
|
25
|
+
throw new Error('The configuration must default-export frontierDemo({ model, budget, ... }). See frontiercs2-config.ts.');
|
|
26
|
+
}
|
|
27
|
+
const report = await prepareFrontier({ configuration, checkOnly: values.check, signal: controller.signal, progress: console.error });
|
|
28
|
+
for (const row of report.checks) console.error(`${row.ok ? 'OK' : 'ACTION'} ${row.name}: ${row.detail}`);
|
|
29
|
+
console.error('Model inference was not attempted.');
|
|
30
|
+
if (report.ok && !values.check) {
|
|
31
|
+
console.error('Prepared. Use the same configuration with anyswarm run ./project.ts --config <your-config> --prompt "Run the FrontierCS-2 task." --output-dir ./runs');
|
|
32
|
+
}
|
|
33
|
+
console.log(JSON.stringify(report, null, 2));
|
|
34
|
+
process.exitCode ??= report.ok ? 0 : 2;
|
|
35
|
+
}
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (!controller.signal.aborted) {
|
|
38
|
+
console.error(error instanceof Error ? error.message : 'Could not load the FrontierCS-2 configuration.');
|
|
39
|
+
console.error('Check the exported frontiercs2-config.ts and run anyswarm setup or anyswarm doctor for your backend.');
|
|
40
|
+
process.exitCode = 2;
|
|
41
|
+
}
|
|
13
42
|
} finally {
|
|
14
43
|
process.off('SIGINT', interrupt).off('SIGTERM', interrupt);
|
|
15
44
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { availableParallelism, freemem } from 'node:os';
|
|
2
|
+
import type { ModelConfig, SandboxConfig } from '@anyswarm/core';
|
|
3
|
+
import type { FrontierConfiguration } from './demo.js';
|
|
2
4
|
import { cp, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, statfs, writeFile } from 'node:fs/promises';
|
|
3
5
|
import { join } from 'node:path';
|
|
4
|
-
import {
|
|
5
|
-
import { bridgeDockerfile, bridgeWorkflow, digest, FrontierRun, frontierRevision, frontierTask, installBridge, judgeImages, pumpkinPin, type FrontierPaths, type JudgeImages } from './frontiercs2.js';
|
|
6
|
+
import { frontierBudget, frontierHome, modelConfigurationError, type ResearchBudget } from './config.js';
|
|
7
|
+
import { bridgeDockerfile, bridgeWorkflow, digest, FrontierRun, frontierRevision, frontierTask, installBridge, judgeImages, preparePumpkin, pumpkinPin, type FrontierPaths, type JudgeImages } from './frontiercs2.js';
|
|
6
8
|
import { command, requireSuccess } from './process.js';
|
|
7
9
|
|
|
8
10
|
const upstream = 'https://github.com/FrontierCS/FrontierCS-2.git';
|
|
@@ -12,45 +14,48 @@ const GiB = 1024 ** 3;
|
|
|
12
14
|
const prepareTimeout = 2_700_000;
|
|
13
15
|
const pinFiles = ['.pumpkinversion', 'PUMPKIN.star', 'pumpkin', ...shared];
|
|
14
16
|
|
|
15
|
-
export function resourcePlan(budget: ResearchBudget) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
export function resourcePlan(budget: ResearchBudget, sandbox: SandboxConfig) {
|
|
18
|
+
const lifecycle = URL.parse(sandbox.endpoint ?? sandbox.lifecycleBaseUrl ?? 'http://127.0.0.1');
|
|
19
|
+
const localWorkers = lifecycle !== null && ['localhost', '127.0.0.1', '[::1]'].includes(lifecycle.hostname);
|
|
20
|
+
const bridge = { role: 'Pumpkin submission role', count: 1, cpu: 2, memoryGiB: 4, placement: 'controller' };
|
|
21
|
+
const judge = { role: 'Active official judge', count: 1, cpu: 2, memoryGiB: 4, placement: 'controller' };
|
|
22
|
+
const controller = { role: 'Controller, services and headroom', count: 1, cpu: 2, memoryGiB: 2, placement: 'controller' };
|
|
23
|
+
const worker = { role: 'AnySwarm Workers', count: budget.workers, cpu: 2, memoryGiB: 4,
|
|
24
|
+
placement: localWorkers ? 'controller' : 'opensandbox' };
|
|
25
|
+
const totals = (roles: (typeof controller)[]) => ({
|
|
26
|
+
roles, cpu: roles.reduce((sum, role) => sum + role.count * role.cpu, 0),
|
|
27
|
+
memoryGiB: roles.reduce((sum, role) => sum + role.count * role.memoryGiB, 0),
|
|
28
|
+
diskGiB: 12, gpu: 0,
|
|
29
|
+
});
|
|
23
30
|
return {
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
prepare: totals([bridge, judge, controller, { role: 'Image build headroom', count: 1, cpu: 2, memoryGiB: 4, placement: 'controller' }]),
|
|
32
|
+
run: totals([worker, bridge, judge, controller]),
|
|
33
|
+
localWorkers,
|
|
26
34
|
};
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
export interface Check { name: string; ok: boolean; detail: string }
|
|
30
38
|
|
|
31
|
-
export async function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return [{ name: 'kimi-k3-config', ok: false, detail: (error as Error).message }];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const config = { name: 'kimi-k3-config', ok: true, detail: 'Configured provider, model ID and fixed Responses URL.' };
|
|
40
|
-
const name = 'kimi-k3-route';
|
|
39
|
+
export async function checkModelRoute(model: ModelConfig, executor: FrontierConfiguration['executor'], signal: AbortSignal): Promise<Check[]> {
|
|
40
|
+
const problem = modelConfigurationError(model, executor);
|
|
41
|
+
const config = { name: 'model-config', ok: !problem, detail: problem ?? 'A model, protocol and endpoint are configured.' };
|
|
42
|
+
if (problem) return [config];
|
|
43
|
+
const name = 'model-http';
|
|
41
44
|
try {
|
|
42
45
|
const response = await fetch(model.upstream.url, {
|
|
43
46
|
method: 'HEAD', headers: model.upstream.headers, redirect: 'manual',
|
|
44
47
|
signal: AbortSignal.any([signal, AbortSignal.timeout(5000)]),
|
|
45
48
|
});
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
: `
|
|
50
|
-
|
|
49
|
+
const reachable = response.ok || [405, 501].includes(response.status);
|
|
50
|
+
const headOnly = !(model.provider === 'kimi_proxy' && model.model === 'k3') && [400, 404].includes(response.status);
|
|
51
|
+
const detail = reachable ? `Endpoint responded to HEAD (HTTP ${response.status}).`
|
|
52
|
+
: headOnly ? `Endpoint is reachable; its HEAD probe returned HTTP ${response.status}. Confirm the configured POST route on the first run.`
|
|
53
|
+
: [401, 403].includes(response.status) ? `HEAD denied (HTTP ${response.status}). Check your endpoint token and access policy.`
|
|
54
|
+
: `Unexpected HEAD response (HTTP ${response.status}). Check the configured endpoint and protocol.`;
|
|
55
|
+
return [config, { name, ok: reachable || headOnly, detail }];
|
|
51
56
|
} catch {
|
|
52
57
|
signal.throwIfAborted();
|
|
53
|
-
return [config, { name, ok: false, detail: 'Could not reach the
|
|
58
|
+
return [config, { name, ok: false, detail: 'Could not reach the configured model endpoint within 5 seconds. Check its URL, DNS and network access from the controller.' }];
|
|
54
59
|
}
|
|
55
60
|
}
|
|
56
61
|
|
|
@@ -63,7 +68,6 @@ interface Prepared {
|
|
|
63
68
|
bridgeImage: string;
|
|
64
69
|
judges: JudgeImages;
|
|
65
70
|
dockerContext: string;
|
|
66
|
-
budget: ResearchBudget;
|
|
67
71
|
referenceRecord: string;
|
|
68
72
|
}
|
|
69
73
|
|
|
@@ -71,10 +75,14 @@ function paths(home: string, dockerContext: string): FrontierPaths {
|
|
|
71
75
|
return { source: join(home, 'bridge'), config: join(home, 'pumpkin.toml'), dockerContext, cache: join(home, 'cache') };
|
|
72
76
|
}
|
|
73
77
|
|
|
78
|
+
export const starterPath = (home: string) => join(home, 'reference', taskPackage, 'repo');
|
|
79
|
+
|
|
74
80
|
export async function loadPrepared(home = frontierHome()) {
|
|
75
|
-
const saved =
|
|
81
|
+
const saved = await readFile(join(home, 'prepared.json'), 'utf8')
|
|
82
|
+
.then(raw => JSON.parse(raw) as Prepared)
|
|
83
|
+
.catch(() => { throw new Error('Prepare this state directory first with anyswarm run ./prepare-demo.ts --config ./frontiercs2-config.ts.'); });
|
|
76
84
|
if (saved.version !== 2 || saved.revision !== frontierRevision || saved.pumpkin !== pumpkinPin ||
|
|
77
|
-
!/^[a-zA-Z0-9._-]+$/.test(saved.dockerContext)) throw new Error('Run anyswarm
|
|
85
|
+
!/^[a-zA-Z0-9._-]+$/.test(saved.dockerContext)) throw new Error('Run anyswarm run ./prepare-demo.ts with the same --config to refresh this demo.');
|
|
78
86
|
const locations = paths(home, saved.dockerContext);
|
|
79
87
|
const reference = join(home, 'reference');
|
|
80
88
|
const [bridgeDigest, sourceDigest] = await Promise.all([treeDigest(locations.source), treeDigest(reference)]);
|
|
@@ -83,15 +91,14 @@ export async function loadPrepared(home = frontierHome()) {
|
|
|
83
91
|
const roleDockerfile = await readFile(join(locations.source, 'lib', 'anyswarm-bridge', 'Dockerfile'), 'utf8');
|
|
84
92
|
const activeConfig = await readFile(locations.config, 'utf8');
|
|
85
93
|
if (saved.bridgeDigest !== bridgeDigest || saved.sourceDigest !== sourceDigest || activeWorkflow !== bridgeWorkflow(officialWorkflow) ||
|
|
86
|
-
roleDockerfile !== bridgeDockerfile || activeConfig !== pumpkinConfig(saved.dockerContext)) throw new Error('Prepared FrontierCS-2 materials changed.
|
|
87
|
-
const
|
|
88
|
-
const starter = join(reference, taskPackage, 'repo');
|
|
94
|
+
roleDockerfile !== bridgeDockerfile || activeConfig !== pumpkinConfig(saved.dockerContext)) throw new Error('Prepared FrontierCS-2 materials changed. Run prepare-demo.ts with your configuration to refresh it.');
|
|
95
|
+
const starter = starterPath(home);
|
|
89
96
|
const tracked = requireSuccess(await command('git', ['ls-files', '--', 'README.md', 'include/binaryfusefilter.h'],
|
|
90
97
|
{ cwd: starter, timeoutMs: 5000 }), 'Validate tracked FrontierCS-2 starter');
|
|
91
98
|
if (!tracked.split('\n').includes('README.md') || !tracked.split('\n').includes('include/binaryfusefilter.h')) {
|
|
92
|
-
throw new Error('The pinned Git starter is missing required tracked files.
|
|
99
|
+
throw new Error('The pinned Git starter is missing required tracked files. Run prepare-demo.ts with your configuration to refresh it.');
|
|
93
100
|
}
|
|
94
|
-
return { saved
|
|
101
|
+
return { saved, paths: locations, starter };
|
|
95
102
|
}
|
|
96
103
|
|
|
97
104
|
async function treeDigest(root: string) {
|
|
@@ -115,7 +122,7 @@ async function sourceAt(home: string, signal: AbortSignal) {
|
|
|
115
122
|
const head = await command('git', ['rev-parse', 'HEAD'], { cwd: cached, timeoutMs: 5000, signal });
|
|
116
123
|
const status = await command('git', ['status', '--porcelain', '--untracked-files=no'], { cwd: cached, timeoutMs: 10_000, signal });
|
|
117
124
|
if (head.stdout.trim() === frontierRevision && status.code === 0 && !status.stdout.trim()) return cached;
|
|
118
|
-
throw new Error('Prepared reference source has local changes. Move it aside and
|
|
125
|
+
throw new Error('Prepared reference source has local changes. Move it aside and run prepare-demo.ts again with your configuration.');
|
|
119
126
|
}
|
|
120
127
|
const temp = await mkdtemp(join(home, 'source-'));
|
|
121
128
|
const git = async (args: string[], timeoutMs: number) => requireSuccess(await command('git', args,
|
|
@@ -144,9 +151,15 @@ async function verifyReference(record: string) {
|
|
|
144
151
|
const train = actions.find(action => action.kind === 'start_call' && action.grant === 'train');
|
|
145
152
|
const final = actions.find(action => action.kind === 'start_final_call');
|
|
146
153
|
const submission = outcome.agents?.find((agent: { role: string }) => agent.role === 'agent')?.submission;
|
|
147
|
-
const returned = (job: number) => events.
|
|
154
|
+
const returned = (job: number) => events.find(({ event }) => event?.job === job && event.kind === 'call_returned')?.event.returned;
|
|
155
|
+
const measured = (values: { name: string; value: unknown }[] | undefined, name: string) => values?.find(row => row.name === name)?.value;
|
|
156
|
+
const trainScore = measured(train && returned(train.job), 'raw_score');
|
|
157
|
+
const finalScore = measured(outcome.verdict?.result?.values, 'score');
|
|
158
|
+
const verdict = measured(outcome.verdict?.result?.values, 'summary');
|
|
148
159
|
if (outcome.state !== 'finished' || outcome.verdict?.kind !== 'returned' || outcome.usage?.model_requests !== 0 ||
|
|
149
|
-
!submission?.finalized ||
|
|
160
|
+
!submission?.finalized || typeof trainScore !== 'number' || !Number.isFinite(trainScore) || trainScore <= 0 ||
|
|
161
|
+
!final || !returned(final.job) || typeof finalScore !== 'number' || !Number.isFinite(finalScore) ||
|
|
162
|
+
typeof verdict !== 'string' || (verdict !== 'strict PASS' && !verdict.startsWith('valid;')) ||
|
|
150
163
|
!final.selections?.some((item: { role: string; selection?: { digest?: string } }) =>
|
|
151
164
|
item.role === 'agent' && item.selection?.digest === submission.payload?.digest)) {
|
|
152
165
|
throw new Error(`The reference record does not establish completed no-model train and final: ${record}`);
|
|
@@ -176,11 +189,12 @@ async function referenceRecord(source: string, state: FrontierPaths, home: strin
|
|
|
176
189
|
}
|
|
177
190
|
}
|
|
178
191
|
|
|
179
|
-
export async function prepareFrontier({ signal, progress,
|
|
180
|
-
signal: AbortSignal; progress: (message: string) => void;
|
|
192
|
+
export async function prepareFrontier({ signal, progress, configuration, checkOnly = false }: {
|
|
193
|
+
signal: AbortSignal; progress: (message: string) => void; configuration: FrontierConfiguration; checkOnly?: boolean;
|
|
181
194
|
}) {
|
|
182
|
-
const
|
|
183
|
-
const
|
|
195
|
+
const { frontierStateDir: home, executor, image, model, sandbox, connection, preparedWorker } = configuration;
|
|
196
|
+
const budget = frontierBudget(configuration.budget);
|
|
197
|
+
const resources = resourcePlan(budget, sandbox);
|
|
184
198
|
const checks: Check[] = [];
|
|
185
199
|
const check = (name: string, ok: boolean, detail: string) => checks.push({ name, ok, detail });
|
|
186
200
|
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
@@ -192,24 +206,60 @@ export async function prepareFrontier({ signal, progress, home = frontierHome()
|
|
|
192
206
|
const result = await command(tool as string, args as string[], { timeoutMs: 5000, signal }).catch(() => undefined);
|
|
193
207
|
check(tool as string, result?.code === 0, result?.stdout.trim() || remedy as string);
|
|
194
208
|
}));
|
|
209
|
+
const installer = await command('/bin/sh', ['-c', 'for tool in sha256sum tar xz flock; do command -v "$tool" >/dev/null || printf "%s " "$tool"; done; command -v curl >/dev/null || command -v wget >/dev/null || printf "curl/wget"'],
|
|
210
|
+
{ timeoutMs: 5000, signal }).catch(() => undefined);
|
|
211
|
+
const missing = installer?.stdout.trim();
|
|
212
|
+
check('pumpkin-tools', installer?.code === 0 && !missing, installer?.code === 0 && !missing
|
|
213
|
+
? 'Found downloader, SHA-256, tar, xz and flock.'
|
|
214
|
+
: `Install curl, ca-certificates, coreutils, tar, xz-utils and util-linux.${missing ? ` Missing: ${missing}.` : ''}`);
|
|
195
215
|
const local = await command('docker', ['context', 'show'], { timeoutMs: 5000, signal }).catch(() => undefined);
|
|
196
216
|
const dockerContext = local?.code === 0 ? local.stdout.trim() : '';
|
|
197
217
|
const validContext = /^[a-zA-Z0-9._-]+$/.test(dockerContext);
|
|
198
218
|
check('docker-cli', validContext, validContext ? dockerContext : 'Install Docker CLI and select a local context.');
|
|
219
|
+
const buildx = validContext ? await command('docker', ['--context', dockerContext, 'buildx', 'version'],
|
|
220
|
+
{ timeoutMs: 5000, signal }).catch(() => undefined) : undefined;
|
|
221
|
+
check('docker-buildx', buildx?.code === 0, buildx?.code === 0 ? buildx.stdout.trim()
|
|
222
|
+
: 'Install the Docker Buildx plugin for your Docker CLI and verify it with docker buildx version.');
|
|
199
223
|
const info = validContext ? await command('docker', ['--context', dockerContext, 'info', '--format',
|
|
200
|
-
'{{.OSType}} {{.Architecture}} {{.NCPU}} {{.MemTotal}}'], { timeoutMs: 8000, signal }).catch(() => undefined) : undefined;
|
|
201
|
-
const [
|
|
224
|
+
'{{.OSType}} {{.Architecture}} {{.NCPU}} {{.MemTotal}}\n{{json .DriverStatus}}'], { timeoutMs: 8000, signal }).catch(() => undefined) : undefined;
|
|
225
|
+
const [platform, driver] = info?.stdout.trim().split('\n', 2) ?? [];
|
|
226
|
+
const [os, arch, cpu, memory] = platform?.split(/\s+/) ?? [];
|
|
202
227
|
check('docker-daemon', info?.code === 0 && os === 'linux' && ['x86_64', 'amd64'].includes(arch),
|
|
203
228
|
info?.code === 0 ? `${os}/${arch}, ${cpu} CPUs, ${Math.floor(Number(memory) / GiB)} GiB` : 'Start Docker and verify daemon access with docker info.');
|
|
229
|
+
const imageStore = info?.code === 0 && driver?.includes('"io.containerd.snapshotter.v1"');
|
|
230
|
+
check('docker-image-store', !!imageStore, imageStore ? 'Docker uses the containerd image store.'
|
|
231
|
+
: 'Pumpkin requires the containerd image store. Check docker info --format "{{ .DriverStatus }}" and see the Docker setup section of README.md.');
|
|
232
|
+
const availableCpu = Math.min(availableParallelism(), Number(cpu));
|
|
233
|
+
const availableMemory = Math.min(freemem(), Number(memory)) / GiB;
|
|
204
234
|
const disk = await statfs(home);
|
|
235
|
+
const tmp = await statfs(process.env.TMPDIR ?? '/tmp');
|
|
205
236
|
const diskGiB = disk.bavail * disk.bsize / GiB;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
237
|
+
const tmpGiB = tmp.bavail * tmp.bsize / GiB;
|
|
238
|
+
for (const [phase, plan] of [['prepare', resources.prepare], ['run', resources.run]] as const) {
|
|
239
|
+
const local = plan.roles.filter(role => role.placement === 'controller');
|
|
240
|
+
const localCpu = local.reduce((sum, role) => sum + role.cpu * role.count, 0);
|
|
241
|
+
const localMemory = local.reduce((sum, role) => sum + role.memoryGiB * role.count, 0);
|
|
242
|
+
check(phase + '-capacity', availableCpu >= localCpu && availableMemory >= localMemory,
|
|
243
|
+
`Controller needs ${localCpu} vCPU and ${localMemory} GiB available for ${phase}. Observed: ${Number.isFinite(availableCpu) ? availableCpu : 'unknown'} vCPU and ${Number.isFinite(availableMemory) ? Math.floor(availableMemory) : 'unknown'} GiB. For run capacity, reduce budget.workers or use a larger host.`);
|
|
244
|
+
}
|
|
245
|
+
check('storage', diskGiB >= resources.prepare.diskGiB && disk.ffree >= 25_000 && tmp.ffree >= 25_000 && tmpGiB >= 1,
|
|
246
|
+
`State: ${Math.floor(diskGiB)} GiB, ${disk.ffree} inodes. Temporary storage: ${Math.floor(tmpGiB)} GiB, ${tmp.ffree} inodes. Allow 12 GiB for state, 1 GiB for temporary files and 25000 free inodes on both mounts.`);
|
|
247
|
+
checks.push(...await checkModelRoute(model, executor, signal));
|
|
248
|
+
const placement = typeof executor === 'string' ? executor : executor?.kind;
|
|
249
|
+
check('executor', !!placement && !!image, placement && image
|
|
250
|
+
? `Selected backend: ${placement}; Worker image: ${image}. The first Worker startup checks executor compatibility.`
|
|
251
|
+
: 'Run anyswarm setup --backend pi or --backend codex, or configure executor and its matching image.');
|
|
252
|
+
check('callback', !!(connection.advertiseHost || connection.publicUrl),
|
|
253
|
+
connection.advertiseHost || connection.publicUrl
|
|
254
|
+
? 'Runtime callback is configured. Use anyswarm doctor --smoke to check guest connectivity.'
|
|
255
|
+
: 'Configure ANYSWARM_ADVERTISE_HOST or ANYSWARM_RUNTIME_PUBLIC_URL for the Worker callback, or run anyswarm setup.');
|
|
256
|
+
const limits = sandbox.resourceLimits;
|
|
257
|
+
check('worker-spec', limits?.cpu === '2' && limits.memory === '4Gi',
|
|
258
|
+
'FrontierCS-2 reserves 2 vCPU and 4 GiB per Worker. Keep sandbox.resourceLimits.cpu=2 and memory=4Gi.');
|
|
210
259
|
try {
|
|
211
|
-
const
|
|
212
|
-
|
|
260
|
+
const base = sandbox.endpoint ?? sandbox.lifecycleBaseUrl;
|
|
261
|
+
if (!base) throw new Error('Lifecycle endpoint is required');
|
|
262
|
+
const url = base.replace(/\/$/, '') + '/sandboxes?page=1&pageSize=1';
|
|
213
263
|
const deadline = AbortSignal.any([signal, AbortSignal.timeout(8000)]);
|
|
214
264
|
const [authenticated, anonymous] = await Promise.all([
|
|
215
265
|
fetch(url, { redirect: 'error', signal: deadline, headers: { 'OPEN-SANDBOX-API-KEY': sandbox.apiKey ?? '' } }),
|
|
@@ -217,19 +267,34 @@ export async function prepareFrontier({ signal, progress, home = frontierHome()
|
|
|
217
267
|
]);
|
|
218
268
|
const ok = Boolean(sandbox.apiKey && authenticated.ok && [401, 403].includes(anonymous.status) && sandbox.egressMode === 'dns+nft');
|
|
219
269
|
await Promise.all([authenticated.body?.cancel(), anonymous.body?.cancel()]);
|
|
220
|
-
check('opensandbox', ok, ok ? 'Authenticated Lifecycle endpoint
|
|
221
|
-
|
|
270
|
+
check('opensandbox', ok, ok ? 'Authenticated Lifecycle endpoint and configured dns+nft egress.'
|
|
271
|
+
: 'Run anyswarm setup and anyswarm doctor. For an existing deployment configure the Lifecycle endpoint, API key and dns+nft egress.');
|
|
272
|
+
} catch {
|
|
273
|
+
signal.throwIfAborted();
|
|
274
|
+
check('opensandbox', false, 'Could not reach the configured Lifecycle endpoint. Run anyswarm setup or check the existing service with anyswarm doctor.');
|
|
275
|
+
}
|
|
276
|
+
if (resources.localWorkers) {
|
|
277
|
+
const worker = validContext && image && await command('docker', ['--context', dockerContext, 'image', 'inspect', '--format', '{{.Id}}', preparedWorker ?? image],
|
|
222
278
|
{ timeoutMs: 8000, signal }).catch(() => undefined);
|
|
223
|
-
check('worker-image', !!worker && worker.code === 0,
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
279
|
+
check('worker-image', !!worker && worker.code === 0, worker && worker.code === 0 ? `Docker resolved ${worker.stdout.trim()} for ${image}.`
|
|
280
|
+
: 'Run anyswarm setup to prepare the selected Worker on this Docker daemon, or select its image in the configuration.');
|
|
281
|
+
} else {
|
|
282
|
+
check('worker-image', !!image, 'Worker is assigned to the existing OpenSandbox service. Confirm the image is available there with anyswarm doctor --mode existing --smoke.');
|
|
283
|
+
}
|
|
284
|
+
const savedManifest = await readFile(join(home, 'prepared.json'), 'utf8').then(raw => JSON.parse(raw) as Prepared).catch(() => undefined);
|
|
285
|
+
check('task-materials', !savedManifest || savedManifest.dockerContext === dockerContext,
|
|
286
|
+
!savedManifest ? 'The pinned task will be downloaded and checked during prepare.'
|
|
287
|
+
: savedManifest.dockerContext === dockerContext ? 'Prepared manifest found. Prepare verifies its material and image identities before reuse.'
|
|
288
|
+
: 'The state directory belongs to another Docker context. Set ANYSWARM_AUTORESEARCH_STATE_DIR to a fresh directory for this context.');
|
|
289
|
+
const report = { ok: checks.every(row => row.ok), benchmark: frontierRevision, pumpkin: pumpkinPin, budget, resources, checks, home,
|
|
290
|
+
model: { provider: model?.provider || null, id: model?.model || null }, modelInference: 'not-attempted' as const };
|
|
291
|
+
if (!report.ok || checkOnly) return report;
|
|
228
292
|
signal.throwIfAborted();
|
|
229
293
|
const state = paths(home, dockerContext);
|
|
230
294
|
const lock = join(home, 'preparing');
|
|
231
295
|
await mkdir(lock, { mode: 0o700 }).catch(() => { throw new Error('FrontierCS-2 preparation is already active. Inspect the preparing directory before retrying.'); });
|
|
232
296
|
try {
|
|
297
|
+
progress('Checking pinned FrontierCS-2 source and Git LFS material.');
|
|
233
298
|
const source = await sourceAt(home, signal);
|
|
234
299
|
const sourceDigest = await treeDigest(source);
|
|
235
300
|
const current = await loadPrepared(home).catch(() => undefined);
|
|
@@ -242,6 +307,7 @@ export async function prepareFrontier({ signal, progress, home = frontierHome()
|
|
|
242
307
|
if (cachedImage.code === 0) return { ...report, ok: true, reused: true, prepared: current.saved };
|
|
243
308
|
}
|
|
244
309
|
await writeFile(state.config, pumpkinConfig(dockerContext), { mode: 0o600 });
|
|
310
|
+
await preparePumpkin(source, state.cache, signal);
|
|
245
311
|
progress('Validating official FrontierCS-2 reference and building pinned judge images.');
|
|
246
312
|
const reference = await referenceRecord(source, state, home, signal);
|
|
247
313
|
await mkdir(state.source, { recursive: true, mode: 0o700 });
|
|
@@ -251,17 +317,25 @@ export async function prepareFrontier({ signal, progress, home = frontierHome()
|
|
|
251
317
|
const bridgeRuns = await mkdtemp(join(home, 'bridge-check-'));
|
|
252
318
|
const bridge = new FrontierRun(state, bridgeRuns);
|
|
253
319
|
try {
|
|
254
|
-
await bridge.start(120, signal, prepareTimeout);
|
|
320
|
+
await bridge.start(120, signal, prepareTimeout, budget.maxEvaluations);
|
|
255
321
|
if (JSON.stringify(bridge.judges) !== JSON.stringify(reference.judges)) throw new Error('Submission bridge changed the official judge images');
|
|
256
322
|
}
|
|
257
323
|
finally {
|
|
258
324
|
if (await bridge.close() !== 'complete') throw new Error(`Pumpkin submission role cleanup is pending: ${bridge.record}`);
|
|
259
325
|
}
|
|
260
326
|
const manifest: Prepared = { version: 2, revision: frontierRevision, pumpkin: pumpkinPin, sourceDigest,
|
|
261
|
-
bridgeDigest: await treeDigest(state.source), bridgeImage: bridge.imageId!, dockerContext,
|
|
327
|
+
bridgeDigest: await treeDigest(state.source), bridgeImage: bridge.imageId!, dockerContext, referenceRecord: reference.record, judges: reference.judges };
|
|
262
328
|
const pending = join(lock, 'prepared.json');
|
|
263
329
|
await writeFile(pending, JSON.stringify(manifest, null, 2) + '\n', { mode: 0o600 });
|
|
264
330
|
await rename(pending, join(home, 'prepared.json'));
|
|
265
331
|
return { ...report, ok: true, reused: false, prepared: manifest };
|
|
332
|
+
} catch (error) {
|
|
333
|
+
signal.throwIfAborted();
|
|
334
|
+
const detail = error instanceof Error ? error.message : 'Preparation failed. Check the pinned task and Docker logs.';
|
|
335
|
+
const remedy = detail.includes("can't be tagged") && detail.includes('No such image')
|
|
336
|
+
? 'Check the selected Docker daemon and Buildx. Try Docker Engine 29 with the official Buildx plugin and the containerd image store, then rerun prepare.\n'
|
|
337
|
+
: '';
|
|
338
|
+
check('prepare-materials', false, remedy + detail);
|
|
339
|
+
return { ...report, ok: false };
|
|
266
340
|
} finally { await rm(lock, { recursive: true, force: true }); }
|
|
267
341
|
}
|