@anyswarm/core 0.5.1 → 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 +20 -5
- package/README.md +69 -55
- package/dist/examples/README.md +138 -77
- package/dist/examples/authoring/README.md +4 -4
- package/dist/examples/autoresearch/README.md +108 -16
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
- 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/eject.json +2 -0
- package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
- package/dist/examples/autoresearch/frontiercs2-config.js +14 -0
- package/dist/examples/autoresearch/frontiercs2.d.ts +18 -1
- package/dist/examples/autoresearch/frontiercs2.js +71 -14
- package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
- package/dist/examples/autoresearch/prepare-demo.js +46 -0
- 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 -95
- package/dist/examples/autoresearch/project.js +131 -45
- package/dist/examples/autoresearch/research-service.d.ts +16 -1
- package/dist/examples/autoresearch/research-service.js +84 -44
- package/dist/examples/code/README.md +25 -17
- package/dist/examples/code/REQUIREMENTS.zh.md +3 -3
- 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 +4 -4
- 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 +5 -5
- 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 +6 -3
- 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 +9 -16
- 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/super/README.md +34 -22
- package/dist/examples/super/actions.d.ts +1 -1
- package/dist/examples/super/actions.js +11 -11
- package/dist/examples/super/config.js +3 -3
- package/dist/examples/super/eject.json +1 -1
- package/dist/examples/super/location.js +1 -1
- package/dist/examples/super/operator.d.ts +1 -0
- package/dist/examples/super/operator.js +31 -0
- package/dist/examples/super/project.d.ts +0 -107
- package/dist/examples/super/project.js +1 -3
- 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-arguments.d.ts +7 -25
- package/dist/scripts/anyswarm-arguments.js +69 -97
- package/dist/scripts/anyswarm-eject.js +1 -1
- package/dist/scripts/anyswarm-harnesses.d.ts +0 -1
- package/dist/scripts/anyswarm-harnesses.js +1 -22
- package/dist/scripts/anyswarm-installation.d.ts +7 -40
- package/dist/scripts/anyswarm-installation.js +17 -291
- package/dist/scripts/anyswarm-launch.d.ts +6 -36
- package/dist/scripts/anyswarm-launch.js +32 -81
- package/dist/scripts/anyswarm-progress.d.ts +6 -0
- package/dist/scripts/anyswarm-progress.js +133 -0
- package/dist/scripts/anyswarm-project.d.ts +1 -9
- package/dist/scripts/anyswarm-project.js +40 -127
- package/dist/scripts/anyswarm-source-runner.js +9 -41
- package/dist/scripts/anyswarm.js +6 -26
- 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 +13 -7
- package/dist/scripts/local-environment.js +73 -21
- package/dist/scripts/local-setup.d.ts +3 -0
- package/dist/scripts/local-setup.js +153 -118
- package/dist/scripts/pack-release.js +31 -4
- 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/core/worker-image.js +1 -1
- package/dist/src/harness/project-harness.d.ts +1 -0
- package/dist/src/harness/project-harness.js +5 -4
- package/dist/src/harness/project-rpc-client.js +19 -0
- 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 +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 +11 -9
- package/docs/architecture/04-services.md +1 -1
- package/docs/architecture/06-observability-experiments.md +21 -7
- package/docs/architecture/07-run-configuration.md +118 -19
- 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 +157 -115
- 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 +79 -1
- package/docs/architecture/22-website.md +52 -20
- package/docs/architecture/23-project-harness.md +109 -37
- package/docs/architecture/26-code.md +20 -5
- package/docs/architecture/27-personal.md +23 -8
- package/docs/architecture/28-autoresearch.md +18 -12
- package/docs/architecture/INDEX.md +1 -2
- 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 +76 -52
- package/docs/architecture/source-map.json +445 -105
- package/docs/designs/core-harness/01-core.md +2 -2
- package/docs/designs/core-harness/06-project-harness.md +3 -3
- package/docs/designs/core-harness/README.md +2 -2
- package/docs/en/agents.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 +29 -1
- package/docs/en/first-harness.md +40 -32
- package/docs/en/harnesses/index.md +23 -23
- package/docs/en/harnesses/lead-worker.md +1 -1
- package/docs/en/harnesses/peermesh.md +2 -2
- package/docs/en/harnesses/subagents.md +10 -31
- package/docs/en/harnesses/substrate.md +4 -4
- package/docs/en/harnesses/taskpool.md +2 -2
- package/docs/en/latest.md +30 -5
- package/docs/en/overview.md +22 -22
- package/docs/en/quickstart.md +69 -56
- package/docs/en/reference/api.md +1 -1
- package/docs/en/reference/cli.md +47 -85
- package/docs/en/sandbox.md +3 -3
- package/docs/en/trace-viewer.md +32 -12
- package/docs/operations/trace-viewer.md +26 -11
- package/docs/third-party-notices.md +0 -1
- package/docs/workflows/development.md +160 -118
- package/docs/workflows/release-and-docs-versioning.md +207 -54
- package/docs/workflows/release-cli-acceptance.md +162 -0
- package/docs/zh/agents.md +1 -1
- 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 +29 -1
- package/docs/zh/first-harness.md +43 -35
- package/docs/zh/harnesses/index.md +23 -23
- package/docs/zh/harnesses/lead-worker.md +1 -1
- package/docs/zh/harnesses/peermesh.md +2 -2
- package/docs/zh/harnesses/subagents.md +10 -31
- package/docs/zh/harnesses/substrate.md +4 -4
- package/docs/zh/harnesses/taskpool.md +2 -2
- package/docs/zh/latest.md +30 -5
- package/docs/zh/overview.md +23 -23
- package/docs/zh/quickstart.md +66 -57
- package/docs/zh/reference/api.md +1 -1
- package/docs/zh/reference/cli.md +19 -79
- package/docs/zh/sandbox.md +3 -3
- package/docs/zh/trace-viewer.md +32 -12
- package/examples/README.md +138 -77
- package/examples/authoring/README.md +4 -4
- package/examples/autoresearch/README.md +108 -16
- package/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
- package/examples/autoresearch/config.ts +64 -25
- package/examples/autoresearch/demo.ts +75 -22
- package/examples/autoresearch/eject.json +2 -0
- package/examples/autoresearch/frontiercs2-config.ts +15 -0
- package/examples/autoresearch/frontiercs2.ts +64 -11
- package/examples/autoresearch/prepare-demo.ts +44 -0
- package/examples/autoresearch/prepare.ts +134 -60
- package/examples/autoresearch/project.ts +120 -44
- package/examples/autoresearch/research-service.ts +91 -41
- package/examples/code/README.md +25 -17
- package/examples/code/REQUIREMENTS.zh.md +3 -3
- 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 +4 -4
- package/examples/lead-worker/README.md +1 -1
- package/examples/messages/README.md +2 -2
- package/examples/notes/README.md +5 -5
- 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 +6 -3
- package/examples/subagents/AGENTS.md +35 -0
- package/examples/subagents/README.md +129 -93
- package/examples/subagents/config.ts +9 -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/super/README.md +34 -22
- package/examples/super/actions.ts +11 -11
- package/examples/super/config.ts +3 -3
- package/examples/super/eject.json +1 -1
- package/examples/super/location.ts +1 -1
- package/examples/super/operator.ts +28 -0
- package/examples/super/project.ts +1 -3
- package/examples/taskpool/README.md +1 -1
- package/npm-shrinkwrap.development.json +46 -1538
- package/npm-shrinkwrap.json +10 -43
- package/package.development.json +3 -6
- package/package.json +3 -5
- package/scripts/anyswarm-arguments.ts +67 -96
- package/scripts/anyswarm-eject.ts +1 -1
- package/scripts/anyswarm-harnesses.ts +1 -18
- package/scripts/anyswarm-installation.ts +18 -294
- package/scripts/anyswarm-launch.ts +30 -102
- package/scripts/anyswarm-progress.ts +125 -0
- package/scripts/anyswarm-project.ts +31 -123
- package/scripts/anyswarm-source-runner.ts +9 -36
- package/scripts/anyswarm.ts +4 -24
- package/scripts/generate-architecture-coverage.ts +1 -1
- package/scripts/generate-architecture-prompts.ts +21 -10
- package/scripts/local-environment.ts +79 -21
- package/scripts/local-setup.ts +150 -105
- package/scripts/pack-release.ts +28 -4
- 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/core/worker-image.ts +1 -1
- package/src/harness/project-harness.ts +5 -4
- package/src/harness/project-rpc-client.ts +23 -0
- package/src/harness/project-runtime.ts +2 -1
- 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
- package/dist/scripts/anyswarm-applications.d.ts +0 -19
- package/dist/scripts/anyswarm-applications.js +0 -19
- package/dist/scripts/anyswarm-tui-config.d.ts +0 -36
- package/dist/scripts/anyswarm-tui-config.js +0 -189
- package/dist/scripts/anyswarm-tui-session.d.ts +0 -66
- package/dist/scripts/anyswarm-tui-session.js +0 -304
- package/dist/scripts/anyswarm-tui-terminal.d.ts +0 -41
- package/dist/scripts/anyswarm-tui-terminal.js +0 -154
- package/dist/scripts/anyswarm-tui.d.ts +0 -2
- package/dist/scripts/anyswarm-tui.js +0 -1012
- package/docs/architecture/25-foreground-tui.md +0 -51
- package/scripts/anyswarm-applications.ts +0 -39
- package/scripts/anyswarm-tui-config.ts +0 -174
- package/scripts/anyswarm-tui-session.ts +0 -295
- package/scripts/anyswarm-tui-terminal.ts +0 -147
- package/scripts/anyswarm-tui.ts +0 -912
|
@@ -4,15 +4,29 @@ import { tmpdir } from 'node:os';
|
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
5
|
import { promisify } from 'node:util';
|
|
6
6
|
const [destination, ...options] = process.argv.slice(2);
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
let skipBuild = false;
|
|
8
|
+
let releaseVersion;
|
|
9
|
+
for (let index = 0; index < options.length; index++) {
|
|
10
|
+
const option = options[index];
|
|
11
|
+
if (option === '--skip-build' && !skipBuild)
|
|
12
|
+
skipBuild = true;
|
|
13
|
+
else if (option === '--version' && releaseVersion === undefined)
|
|
14
|
+
releaseVersion = options[++index];
|
|
15
|
+
else
|
|
16
|
+
throw new Error(`Unsupported or repeated pack option: ${option}`);
|
|
17
|
+
}
|
|
18
|
+
if (!destination || options.includes('--version') && !releaseVersion) {
|
|
19
|
+
throw new Error('Usage: npm run pack:release -- <output-directory> [--skip-build] [--version <next-version>]');
|
|
20
|
+
}
|
|
21
|
+
if (releaseVersion !== undefined && !/^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)-next\.[1-9][0-9]*\.g[a-f0-9]{12}$/.test(releaseVersion)) {
|
|
22
|
+
throw new Error('A staged version override must be an immutable next release version');
|
|
9
23
|
}
|
|
10
24
|
// Keep the build and staging umask independent of the caller.
|
|
11
25
|
process.umask(0o022);
|
|
12
26
|
const run = promisify(execFile);
|
|
13
27
|
const repository = resolve(import.meta.dirname, '..');
|
|
14
28
|
const output = resolve(destination);
|
|
15
|
-
if (!
|
|
29
|
+
if (!skipBuild) {
|
|
16
30
|
const build = spawnSync('npm', ['run', 'build'], { cwd: repository, stdio: ['ignore', 2, 2] });
|
|
17
31
|
if (build.error)
|
|
18
32
|
throw build.error;
|
|
@@ -34,11 +48,24 @@ try {
|
|
|
34
48
|
const manifestPath = join(staged, 'package.json');
|
|
35
49
|
const lockPath = join(staged, 'npm-shrinkwrap.json');
|
|
36
50
|
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
|
|
51
|
+
if (releaseVersion) {
|
|
52
|
+
manifest.version = releaseVersion;
|
|
53
|
+
const sourceLock = JSON.parse(await readFile(lockPath, 'utf8'));
|
|
54
|
+
if (sourceLock.lockfileVersion !== 3 || !sourceLock.packages?.['']) {
|
|
55
|
+
throw new Error('Release packaging requires a v3 npm shrinkwrap with root package metadata');
|
|
56
|
+
}
|
|
57
|
+
sourceLock.version = releaseVersion;
|
|
58
|
+
sourceLock.packages[''].version = releaseVersion;
|
|
59
|
+
await writeFile(lockPath, JSON.stringify(sourceLock, null, 2) + '\n');
|
|
60
|
+
}
|
|
61
|
+
// Service images compile TypeScript. The Pi installation belongs to the executor.
|
|
62
|
+
delete manifest.devDependencies?.['@earendil-works/pi-coding-agent'];
|
|
63
|
+
await writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
|
|
64
|
+
await run('npm', ['install', '--package-lock-only', '--offline', '--ignore-scripts', '--no-audit', '--no-fund'], { cwd: staged });
|
|
37
65
|
const lock = JSON.parse(await readFile(lockPath, 'utf8'));
|
|
38
66
|
if (lock.lockfileVersion !== 3 || !lock.packages?.['']) {
|
|
39
67
|
throw new Error('Release packaging requires a v3 npm shrinkwrap with root package metadata');
|
|
40
68
|
}
|
|
41
|
-
// Only the service-image build stages use the development inputs.
|
|
42
69
|
await rename(manifestPath, join(staged, 'package.development.json'));
|
|
43
70
|
await rename(lockPath, join(staged, 'npm-shrinkwrap.development.json'));
|
|
44
71
|
delete manifest.private;
|
package/dist/src/core/index.js
CHANGED
|
@@ -129,7 +129,7 @@ function planRuntimeWorker(options, config, profiles, recoveryDirectory) {
|
|
|
129
129
|
}
|
|
130
130
|
return { kind: worker.executor, prepare: async () => worker };
|
|
131
131
|
}
|
|
132
|
-
const { localExecutor } = resolveSandboxConnectionWithSources({ lifecycleBaseUrl: endpoint });
|
|
132
|
+
const { localExecutor } = resolveSandboxConnectionWithSources({ lifecycleBaseUrl: endpoint }, undefined, { discoverHost: false });
|
|
133
133
|
const kind = options.executor ? config.driver.kind : selectors.find(selector => selector.kind)?.kind ?? localExecutor?.kind ?? config.driver.kind;
|
|
134
134
|
if (kind !== 'pi' && kind !== 'codex')
|
|
135
135
|
throw executorFailure('Select Pi or Codex for the built-in local Worker.');
|
|
@@ -11,7 +11,7 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
11
11
|
import { isIP } from 'node:net';
|
|
12
12
|
import { lookup } from 'node:dns/promises';
|
|
13
13
|
import { createWorkerEventPoll } from '../worker-event-poll.js';
|
|
14
|
-
import { loopbackLifecycle, normalizeRuntimePublicUrl, resolveSandboxConnection } from './sandbox-connection.js';
|
|
14
|
+
import { discoverDockerCallbackHost, loopbackLifecycle, normalizeRuntimePublicUrl, resolveSandboxConnection } from './sandbox-connection.js';
|
|
15
15
|
import { validId } from '../config.js';
|
|
16
16
|
import { adaptSandboxProvider, createApiOpenSandboxProvider } from './opensandbox-provider.js';
|
|
17
17
|
const sandboxes = new WeakMap();
|
|
@@ -111,7 +111,9 @@ export function createSandbox(config = {}) {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
const { lifecycleBaseUrl: _alias, endpoint: _endpoint, endpointHost: _endpointHost, ...settings } = sandbox;
|
|
114
|
-
|
|
114
|
+
// Runtime callback options are supplied at claim time, after this handle is
|
|
115
|
+
// created. Snapshot configured settings here without enumerating interfaces.
|
|
116
|
+
const { lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, useServerProxy, egressMode } = resolveSandboxConnection(sandbox, undefined, { discoverHost: false });
|
|
115
117
|
sandboxes.set(handle, freeze(structuredClone({
|
|
116
118
|
sandbox: { ...settings, lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, useServerProxy, egressMode, timeoutSeconds },
|
|
117
119
|
isolation: { network: 'api' },
|
|
@@ -136,10 +138,14 @@ export function claimOpenSandboxBackend(handle, options) {
|
|
|
136
138
|
const port = connection?.bindPort ?? 0;
|
|
137
139
|
if (!Number.isSafeInteger(port) || port < 0 || port > 65_535)
|
|
138
140
|
throw invalid('connection.bindPort must be from 0 through 65535');
|
|
139
|
-
const advertiseHost = connection?.advertiseHost ?? gateway?.advertiseHost ?? settings.sandbox.advertiseHost ??
|
|
140
|
-
((settings.sandbox.lifecycleBaseUrl && loopbackLifecycle(settings.sandbox.lifecycleBaseUrl)) || settings.provider ? '172.17.0.1' : undefined);
|
|
141
141
|
const savedPublicUrl = settings.sandbox.publicUrl;
|
|
142
142
|
const advertised = [...candidates][0] ?? savedPublicUrl;
|
|
143
|
+
let advertiseHost = connection?.advertiseHost ?? gateway?.advertiseHost ?? settings.sandbox.advertiseHost;
|
|
144
|
+
if (advertiseHost === undefined && settings.provider)
|
|
145
|
+
advertiseHost = '172.17.0.1';
|
|
146
|
+
if (advertiseHost === undefined && !advertised && settings.sandbox.lifecycleBaseUrl && loopbackLifecycle(settings.sandbox.lifecycleBaseUrl)) {
|
|
147
|
+
advertiseHost = discoverDockerCallbackHost() ?? '172.17.0.1';
|
|
148
|
+
}
|
|
143
149
|
if (!advertised && !advertiseHost)
|
|
144
150
|
throw invalid('For an existing remote OpenSandbox, set connection.publicUrl to the Runtime address reachable from the Sandbox');
|
|
145
151
|
const workerHost = advertiseHost ?? new URL(advertised).hostname.replace(/^\[|\]$/g, '');
|
|
@@ -19,7 +19,9 @@ interface ConnectionInput {
|
|
|
19
19
|
preparedImage?: string;
|
|
20
20
|
}
|
|
21
21
|
export declare function normalizeRuntimePublicUrl(value: string): string;
|
|
22
|
-
export declare function
|
|
22
|
+
export declare function discoverDockerCallbackHost(): string | undefined;
|
|
23
|
+
export declare function resolveSandboxConnectionWithSources(input?: ConnectionInput, scope?: string, { useSaved, discoverHost }?: {
|
|
24
|
+
discoverHost?: boolean | undefined;
|
|
23
25
|
useSaved?: boolean | undefined;
|
|
24
26
|
}): {
|
|
25
27
|
lifecycleBaseUrl: string;
|
|
@@ -42,7 +44,11 @@ export declare function resolveSandboxConnectionWithSources(input?: ConnectionIn
|
|
|
42
44
|
image: string | undefined;
|
|
43
45
|
};
|
|
44
46
|
};
|
|
45
|
-
export declare function resolveSandboxConnection(
|
|
47
|
+
export declare function resolveSandboxConnection(input?: ConnectionInput, scope?: string, { useSaved, discoverHost, includePreparedImage }?: {
|
|
48
|
+
discoverHost?: boolean | undefined;
|
|
49
|
+
includePreparedImage?: boolean | undefined;
|
|
50
|
+
useSaved?: boolean | undefined;
|
|
51
|
+
}): {
|
|
46
52
|
lifecycleBaseUrl: string;
|
|
47
53
|
apiKey: string | undefined;
|
|
48
54
|
advertiseHost: string | undefined;
|
|
@@ -53,6 +59,7 @@ export declare function resolveSandboxConnection(...settings: Parameters<typeof
|
|
|
53
59
|
endpointHost: undefined;
|
|
54
60
|
endpointSource: string;
|
|
55
61
|
executor: import("../backend-config.js").ExecutorKind | undefined;
|
|
62
|
+
preparedImage?: string | undefined;
|
|
56
63
|
};
|
|
57
64
|
export declare function saveSandboxConnection(input: ConnectionInput & {
|
|
58
65
|
lifecycleBaseUrl: string;
|
|
@@ -126,7 +126,16 @@ function loadSavedConnection() {
|
|
|
126
126
|
}
|
|
127
127
|
return saved;
|
|
128
128
|
}
|
|
129
|
-
export function
|
|
129
|
+
export function discoverDockerCallbackHost() {
|
|
130
|
+
try {
|
|
131
|
+
return networkInterfaces().docker0?.find(item => item.family === 'IPv4')?.address;
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
throw Object.assign(new Error('Could not inspect host network interfaces for the Sandbox callback address. ' +
|
|
135
|
+
'Set ANYSWARM_ADVERTISE_HOST or ANYSWARM_RUNTIME_PUBLIC_URL to an address reachable from the Sandbox.'), { code: 'HOST_NETWORK_DISCOVERY_FAILED' });
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export function resolveSandboxConnectionWithSources(input = {}, scope, { useSaved = true, discoverHost = true } = {}) {
|
|
130
139
|
const environment = process.env;
|
|
131
140
|
const example = (name) => scope ? environment[`ANYSWARM_${scope}_${name}`] || undefined : undefined;
|
|
132
141
|
const explicit = input.endpoint === undefined ? undefined : lifecycleUrl(input.endpoint, 'endpoint');
|
|
@@ -163,12 +172,17 @@ export function resolveSandboxConnectionWithSources(input = {}, scope, { useSave
|
|
|
163
172
|
if (endpointHost !== undefined)
|
|
164
173
|
throw connectionError('endpointHost was removed. Configure OpenSandbox to publish a reachable endpoint.');
|
|
165
174
|
const publicUrl = input.publicUrl ?? (environment.ANYSWARM_RUNTIME_PUBLIC_URL || undefined) ?? stored.publicUrl;
|
|
175
|
+
const normalizedPublicUrl = publicUrl === undefined ? undefined : normalizeRuntimePublicUrl(publicUrl);
|
|
166
176
|
const from = (settings) => settings.find(([, value]) => value !== undefined && value !== '');
|
|
167
|
-
|
|
177
|
+
let callback = from([
|
|
168
178
|
['config', input.advertiseHost], ['ANYSWARM_ADVERTISE_HOST', environment.ANYSWARM_ADVERTISE_HOST],
|
|
169
179
|
[`ANYSWARM_${scope}_ADVERTISE_HOST`, example('ADVERTISE_HOST')], ['saved', stored.advertiseHost],
|
|
170
|
-
['docker0', local ? networkInterfaces().docker0?.find(address => address.family === 'IPv4')?.address : undefined],
|
|
171
180
|
]);
|
|
181
|
+
if (discoverHost && !callback && !normalizedPublicUrl && local) {
|
|
182
|
+
const address = discoverDockerCallbackHost();
|
|
183
|
+
if (address)
|
|
184
|
+
callback = ['docker0', address];
|
|
185
|
+
}
|
|
172
186
|
const worker = from([
|
|
173
187
|
['config', input.image], ['ANYSWARM_WORKER_IMAGE', environment.ANYSWARM_WORKER_IMAGE],
|
|
174
188
|
[`ANYSWARM_${scope}_IMAGE`, example('IMAGE')], ['saved', stored.image],
|
|
@@ -179,7 +193,7 @@ export function resolveSandboxConnectionWithSources(input = {}, scope, { useSave
|
|
|
179
193
|
environment.OPENSANDBOX_API_KEY || undefined) ?? stored.apiKey ?? (local && readPrivateFile(localApiKeyPath(local), 256)),
|
|
180
194
|
advertiseHost: callback?.[1],
|
|
181
195
|
advertiseHostDiscovery: callback?.[0] === 'saved' ? stored.advertiseHostDiscovery : undefined,
|
|
182
|
-
publicUrl:
|
|
196
|
+
publicUrl: normalizedPublicUrl,
|
|
183
197
|
image: worker?.[1],
|
|
184
198
|
useServerProxy: input.useServerProxy ?? stored.useServerProxy,
|
|
185
199
|
egressMode: input.egressMode ?? stored.egressMode,
|
|
@@ -192,9 +206,10 @@ export function resolveSandboxConnectionWithSources(input = {}, scope, { useSave
|
|
|
192
206
|
sources: { lifecycleBaseUrl: endpointSource, advertiseHost: callback?.[0], image: worker?.[0] },
|
|
193
207
|
};
|
|
194
208
|
}
|
|
195
|
-
export function resolveSandboxConnection(
|
|
196
|
-
const { sources: _sources, advertiseHostDiscovery: _discovery, management: _management, providerId: _providerId, localExecutor, preparedImage
|
|
197
|
-
return { ...connection, executor: localExecutor?.kind
|
|
209
|
+
export function resolveSandboxConnection(input, scope, { useSaved = true, discoverHost = true, includePreparedImage = false } = {}) {
|
|
210
|
+
const { sources: _sources, advertiseHostDiscovery: _discovery, management: _management, providerId: _providerId, localExecutor, preparedImage, ...connection } = resolveSandboxConnectionWithSources(input, scope, { useSaved, discoverHost });
|
|
211
|
+
return { ...connection, executor: localExecutor?.kind,
|
|
212
|
+
...(includePreparedImage && preparedImage ? { preparedImage } : {}) };
|
|
198
213
|
}
|
|
199
214
|
export async function saveSandboxConnection(input) {
|
|
200
215
|
const path = connectionPath();
|
|
@@ -14,7 +14,7 @@ function readPackageVersion() {
|
|
|
14
14
|
// Try the compiled dist/src/core -> package root path next.
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
return '0.5.
|
|
17
|
+
return '0.5.2';
|
|
18
18
|
}
|
|
19
19
|
export const PACKAGE_VERSION = readPackageVersion();
|
|
20
20
|
/** Select the locally prepared Worker for the Runtime's executor. */
|
|
@@ -124,6 +124,7 @@ type RunResult = ProjectHarnessResult & Pick<HarnessResult, 'operations' | 'ques
|
|
|
124
124
|
reportPath?: string;
|
|
125
125
|
};
|
|
126
126
|
export declare function failureCode(error: unknown, fallback: string): string;
|
|
127
|
+
export declare function loadProjectConfiguration(directory: string, path: string | undefined): Promise<unknown>;
|
|
127
128
|
export declare function createProjectHost(definition: ProjectHarness, options: StartupOptions, emit: (record: unknown) => void): {
|
|
128
129
|
harness: {
|
|
129
130
|
id: string;
|
|
@@ -4,7 +4,8 @@ import { loadAnySwarmConfig } from '../core/sandbox/sandbox-connection.js';
|
|
|
4
4
|
import { createHash, randomUUID } from 'node:crypto';
|
|
5
5
|
import { mkdir, mkdtemp, realpath, rm, writeFile } from 'node:fs/promises';
|
|
6
6
|
import { registerHooks } from 'node:module';
|
|
7
|
-
import {
|
|
7
|
+
import { tmpdir } from 'node:os';
|
|
8
|
+
import { defaultRunRoot } from '../trace-viewer/run-root.mjs';
|
|
8
9
|
import { extname, isAbsolute, join, resolve } from 'node:path';
|
|
9
10
|
import { pathToFileURL } from 'node:url';
|
|
10
11
|
import { captureProject, isInside, projectError, ProjectPreflightError, resolveProjectDirectory } from './project-input.js';
|
|
@@ -79,7 +80,7 @@ export function failureCode(error, fallback) {
|
|
|
79
80
|
return typeof code === 'string' && (/^[A-Z][A-Z0-9_]{0,79}$/.test(code) ||
|
|
80
81
|
(errorDiagnostic(error) && /^[a-z][a-z0-9_]{0,79}$/.test(code))) ? code : fallback;
|
|
81
82
|
}
|
|
82
|
-
async function
|
|
83
|
+
export async function loadProjectConfiguration(directory, path) {
|
|
83
84
|
if (!path)
|
|
84
85
|
return undefined;
|
|
85
86
|
let value;
|
|
@@ -111,7 +112,7 @@ async function prepareOutput(runId, options, cwd) {
|
|
|
111
112
|
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
112
113
|
return await realpath(path);
|
|
113
114
|
}
|
|
114
|
-
const stateDirectory =
|
|
115
|
+
const stateDirectory = defaultRunRoot();
|
|
115
116
|
if (!isInside(cwd, stateDirectory)) {
|
|
116
117
|
const stateRoot = await mkdir(stateDirectory, { recursive: true, mode: 0o700 })
|
|
117
118
|
.then(() => realpath(stateDirectory)).catch(() => null);
|
|
@@ -201,7 +202,7 @@ export function createProjectHost(definition, options, emit) {
|
|
|
201
202
|
await writeFile(path, raw.prompt, { flag: 'wx', mode: 0o600 });
|
|
202
203
|
promptPath = path;
|
|
203
204
|
signal.throwIfAborted();
|
|
204
|
-
const configuration = options.configuration !== undefined ? validateConfiguration(options.configuration) : await
|
|
205
|
+
const configuration = options.configuration !== undefined ? validateConfiguration(options.configuration) : await loadProjectConfiguration(options.launchDirectory, options.configPath);
|
|
205
206
|
signal.throwIfAborted();
|
|
206
207
|
let filePolicy;
|
|
207
208
|
try {
|
|
@@ -4,6 +4,19 @@ import { projectError } from './project-input.js';
|
|
|
4
4
|
import { readRpcLines } from './project-rpc-lines.js';
|
|
5
5
|
import { MAX_COMMAND_BYTES } from './foreground-commands.js';
|
|
6
6
|
import { HarnessEventStream } from './harness-event-stream.js';
|
|
7
|
+
// These launch errors contain public Host explanations, not author exceptions.
|
|
8
|
+
const startupMessageCodes = new Set(['HARNESS_MODULE_LOAD_FAILED', 'INVALID_HARNESS_MODULE',
|
|
9
|
+
'INVALID_HARNESS_SESSION', 'INVALID_RUN_CONFIGURATION', 'INVALID_REQUEST']);
|
|
10
|
+
function startupError(record) {
|
|
11
|
+
if (typeof record.code !== 'string' || !/^[A-Za-z0-9_.:-]{1,128}$/.test(record.code)) {
|
|
12
|
+
throw new Error('Invalid RPC startup error');
|
|
13
|
+
}
|
|
14
|
+
const message = startupMessageCodes.has(record.code) && typeof record.message === 'string'
|
|
15
|
+
? record.message.slice(0, 4096).replace(/[\p{Cc}\p{Cf}]/gu, (character) => '\\u' + character.charCodeAt(0).toString(16).padStart(4, '0'))
|
|
16
|
+
: 'Harness RPC startup failed';
|
|
17
|
+
const diagnostic = parseErrorDiagnostic(record.diagnostic);
|
|
18
|
+
return Object.assign(projectError(record.code, message), diagnostic ? frameworkErrorFields({ ...record, diagnostic }) : {});
|
|
19
|
+
}
|
|
7
20
|
export class HarnessRpcClient {
|
|
8
21
|
ready;
|
|
9
22
|
agents;
|
|
@@ -16,6 +29,7 @@ export class HarnessRpcClient {
|
|
|
16
29
|
#timeout;
|
|
17
30
|
#prefix = randomUUID();
|
|
18
31
|
#next = 0;
|
|
32
|
+
#readyConfirmed = false;
|
|
19
33
|
#started = false;
|
|
20
34
|
#failure;
|
|
21
35
|
#resultConfirmed = false;
|
|
@@ -141,11 +155,16 @@ export class HarnessRpcClient {
|
|
|
141
155
|
case 'ready':
|
|
142
156
|
if (record.version !== 'v1' || !record.harness || !record.status || !record.descriptor)
|
|
143
157
|
throw new Error('Invalid RPC handshake');
|
|
158
|
+
this.#readyConfirmed = true;
|
|
144
159
|
this.#started ||= typeof record.status.runId === 'string';
|
|
145
160
|
this.#ready.resolve(record);
|
|
146
161
|
break;
|
|
147
162
|
case 'reply':
|
|
148
163
|
case 'error': {
|
|
164
|
+
if (record.type === 'error' && record.id === undefined && !this.#readyConfirmed) {
|
|
165
|
+
this.#disconnect(startupError(record));
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
149
168
|
const pending = this.#pending.get(record.id);
|
|
150
169
|
if (!pending)
|
|
151
170
|
break;
|
|
@@ -65,7 +65,9 @@ export async function projectConfiguration(context, defaults) {
|
|
|
65
65
|
throw new Error('Missing sandbox, models or image');
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
catch {
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof ProjectPreflightError)
|
|
70
|
+
throw error;
|
|
69
71
|
throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Configure sandbox, models and image for this Harness');
|
|
70
72
|
}
|
|
71
73
|
context.signal.throwIfAborted();
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
/** Enable trusted author TypeScript without changing the author's package scope. */
|
|
2
2
|
export declare function installSourceLoader(): void;
|
|
3
|
+
/** Compile author source without lowering the JavaScript syntax supported by the running Node. */
|
|
4
|
+
export declare function transformAuthorSource(source: string, filename: string): string;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { createRequire, registerHooks } from 'node:module';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
4
5
|
let installed = false;
|
|
5
6
|
/** Enable trusted author TypeScript without changing the author's package scope. */
|
|
6
7
|
export function installSourceLoader() {
|
|
7
8
|
if (installed)
|
|
8
9
|
return;
|
|
9
10
|
installed = true;
|
|
10
|
-
// Node 22.19+ supports transformation and inline maps, including enums.
|
|
11
|
-
const transform = stripTypeScriptTypes;
|
|
12
11
|
const sdk = new URL('../core/index.js', import.meta.url).href;
|
|
13
12
|
registerHooks({
|
|
14
13
|
resolve(specifier, context, nextResolve) {
|
|
@@ -21,8 +20,11 @@ export function installSourceLoader() {
|
|
|
21
20
|
throw error;
|
|
22
21
|
if (specifier === '@anyswarm/core')
|
|
23
22
|
return { url: sdk, shortCircuit: true };
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const source = specifier.startsWith('file:') ? new URL(specifier)
|
|
24
|
+
: context.parentURL?.startsWith('file:') && /^(?:\.{1,2}\/|\/)/.test(specifier)
|
|
25
|
+
? new URL(specifier, context.parentURL) : undefined;
|
|
26
|
+
if (source && /\.m?js$/.test(source.pathname)) {
|
|
27
|
+
source.pathname = source.pathname.replace(/\.m?js$/, match => match === '.mjs' ? '.mts' : '.ts');
|
|
26
28
|
if (existsSync(source))
|
|
27
29
|
return { url: source.href, shortCircuit: true };
|
|
28
30
|
}
|
|
@@ -32,10 +34,26 @@ export function installSourceLoader() {
|
|
|
32
34
|
load(url, context, nextLoad) {
|
|
33
35
|
if (!url.startsWith('file:') || !/\.(?:ts|mts)$/.test(new URL(url).pathname))
|
|
34
36
|
return nextLoad(url, context);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
});
|
|
37
|
+
const filename = fileURLToPath(url);
|
|
38
|
+
const source = transformAuthorSource(readFileSync(filename, 'utf8'), filename);
|
|
38
39
|
return { format: 'module', source, shortCircuit: true };
|
|
39
40
|
},
|
|
40
41
|
});
|
|
41
42
|
}
|
|
43
|
+
/** Compile author source without lowering the JavaScript syntax supported by the running Node. */
|
|
44
|
+
export function transformAuthorSource(source, filename) {
|
|
45
|
+
const { transformSync } = require('@swc/wasm');
|
|
46
|
+
// The WASM transformer accepts these options even though its declarations lag the runtime.
|
|
47
|
+
const options = {
|
|
48
|
+
filename,
|
|
49
|
+
isModule: true,
|
|
50
|
+
sourceMaps: 'inline',
|
|
51
|
+
jsc: {
|
|
52
|
+
target: 'esnext',
|
|
53
|
+
parser: { syntax: 'typescript' },
|
|
54
|
+
transform: { verbatimModuleSyntax: true },
|
|
55
|
+
},
|
|
56
|
+
module: { type: 'es6' },
|
|
57
|
+
};
|
|
58
|
+
return transformSync(source, options).code;
|
|
59
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
|
+
import { defaultRunRoot } from './run-root.mjs';
|
|
3
4
|
|
|
4
5
|
export const traceUsage = [
|
|
5
|
-
'Usage: anyswarm trace --root <runs-dir> [--port 8787] [--open]',
|
|
6
|
+
'Usage: anyswarm trace [--root <runs-dir>] [--port 8787] [--open]',
|
|
6
7
|
' anyswarm trace <runs-dir> [--port 8787] [--open]',
|
|
8
|
+
'Default root: ${XDG_STATE_HOME:-$HOME/.local/state}/anyswarm/runs',
|
|
7
9
|
].join('\n');
|
|
8
10
|
|
|
9
11
|
function openBrowser(url) {
|
|
@@ -46,8 +48,8 @@ export async function runTraceCommand(args) {
|
|
|
46
48
|
console.log(traceUsage);
|
|
47
49
|
return null;
|
|
48
50
|
}
|
|
49
|
-
const root = values.root ?? positionals[0];
|
|
50
|
-
if (!root) throw new Error('--root
|
|
51
|
+
const root = values.root ?? positionals[0] ?? defaultRunRoot();
|
|
52
|
+
if (!root) throw new Error('--root must not be empty');
|
|
51
53
|
if (positionals.length > 1) {
|
|
52
54
|
throw new Error('Unexpected positional argument: ' + positionals[1]);
|
|
53
55
|
}
|
|
@@ -67,6 +69,7 @@ export async function runTraceCommand(args) {
|
|
|
67
69
|
throw error;
|
|
68
70
|
}
|
|
69
71
|
console.log('AnySwarm Trace Viewer listening at ' + viewer.url);
|
|
72
|
+
console.log('Run root: ' + viewer.root);
|
|
70
73
|
const actualPort = new URL(viewer.url).port;
|
|
71
74
|
const sshHint = formatSshHint(actualPort);
|
|
72
75
|
if (sshHint) console.log(sshHint);
|