@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
package/scripts/local-setup.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { resolve } from 'node:path';
|
|
|
3
3
|
import { stdin, stderr } from 'node:process';
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
5
|
import {
|
|
6
|
-
checkSetupHost, checkLocalDocker, checkLocalProvider, discoverMacCallback, ensureLocalProvider, localExecdImage, localEgressImage, localProviderImage, resolveLocalEnvironment,
|
|
6
|
+
checkSetupHost, checkHostTools, checkLocalDocker, checkLocalProvider, discoverMacCallback, ensureLocalProvider, localExecdImage, localEgressImage, localProviderImage, resolveLocalEnvironment,
|
|
7
7
|
type DiagnosticCheck,
|
|
8
8
|
} from './local-environment.js';
|
|
9
9
|
import { runLocalSmoke } from './local-setup-smoke.js';
|
|
@@ -16,16 +16,17 @@ import { checkLocalExecutor, findExecutorEntry, type LocalExecutorSelection } fr
|
|
|
16
16
|
import { resolveFilePolicy, type ResolvedFilePolicy } from '../src/core/file-policy.js';
|
|
17
17
|
import { claimOpenSandboxBackend, createSandbox } from '../src/core/sandbox/opensandbox-backend.js';
|
|
18
18
|
import { snapshotModel } from '../src/core/model/model-access.js';
|
|
19
|
+
import { readSubagentsModel } from '../examples/subagents/model.js';
|
|
19
20
|
import { modelClientProtocol } from '../src/core/model/model-transport.js';
|
|
20
21
|
import type { SandboxConfig } from '../src/core/backend-config.js';
|
|
21
|
-
import { loadAnySwarmConfig, saveSandboxConnection } from '../src/core/sandbox/sandbox-connection.js';
|
|
22
|
+
import { loadAnySwarmConfig, loopbackLifecycle, saveSandboxConnection } from '../src/core/sandbox/sandbox-connection.js';
|
|
22
23
|
import type { LocalCommand } from './anyswarm-arguments.js';
|
|
23
24
|
|
|
24
25
|
type ProjectConfig = Parameters<typeof createSubagentsHarness>[0];
|
|
25
26
|
type Provider = Awaited<ReturnType<typeof ensureLocalProvider>>;
|
|
26
27
|
type Smoke = Awaited<ReturnType<typeof runLocalSmoke>>;
|
|
27
28
|
type Timing = { id: string; elapsedMs: number; cached?: boolean };
|
|
28
|
-
type Model = { configuration: 'complete' | 'missing' | 'invalid'; verification: 'not-verified' };
|
|
29
|
+
type Model = { configuration: 'complete' | 'missing' | 'invalid'; verification: 'not-verified'; remedy?: string };
|
|
29
30
|
|
|
30
31
|
function modelState(config: ProjectConfig, executor: string): Model {
|
|
31
32
|
if (config.models === undefined) return { configuration: 'missing', verification: 'not-verified' };
|
|
@@ -95,10 +96,11 @@ function reportedHost(value?: string): string | undefined {
|
|
|
95
96
|
if (value && (/^[a-zA-Z0-9._-]+$/.test(value) || isIP(value))) return value;
|
|
96
97
|
}
|
|
97
98
|
|
|
98
|
-
function installNextStep(command: LocalCommand): string {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
function installNextStep(command: LocalCommand, mode?: 'existing' | 'local'): string {
|
|
100
|
+
if (command.command !== 'setup') return 'Run your Harness with the same environment.';
|
|
101
|
+
return mode === 'local'
|
|
102
|
+
? 'Run your Harness with the same environment, or repeat the probe with anyswarm doctor --smoke.'
|
|
103
|
+
: 'Run your Harness with the same environment, or check the existing service with anyswarm doctor --mode existing --smoke.';
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
const phaseLabels: Record<string, string> = {
|
|
@@ -109,56 +111,71 @@ const phaseLabels: Record<string, string> = {
|
|
|
109
111
|
smoke: 'Start Worker and check Bridge, controlled Gateway, files and deletion',
|
|
110
112
|
};
|
|
111
113
|
|
|
114
|
+
type BackendProbe = {
|
|
115
|
+
selection: LocalExecutorSelection;
|
|
116
|
+
} & ({ version: string } | { error: string });
|
|
117
|
+
|
|
118
|
+
async function probeBackend(selection: LocalExecutorSelection, signal: AbortSignal): Promise<BackendProbe> {
|
|
119
|
+
try {
|
|
120
|
+
return { selection, version: await checkLocalExecutor(selection, signal) };
|
|
121
|
+
} catch (error) {
|
|
122
|
+
signal.throwIfAborted();
|
|
123
|
+
if ((error as { code?: string }).code !== 'LOCAL_EXECUTOR_UNAVAILABLE') throw error;
|
|
124
|
+
return { selection, error: (error as Error).message };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function backendOnPath(kind: LocalExecutorSelection['kind'], version: string | undefined, signal: AbortSignal) {
|
|
129
|
+
let firstFailure: BackendProbe | undefined;
|
|
130
|
+
let available: BackendProbe | undefined;
|
|
131
|
+
await findExecutorEntry(kind, async entry => {
|
|
132
|
+
const candidate = await probeBackend({ kind, entry, version }, signal);
|
|
133
|
+
if ('version' in candidate) {
|
|
134
|
+
available = candidate;
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
firstFailure ??= candidate;
|
|
138
|
+
return false;
|
|
139
|
+
});
|
|
140
|
+
return available ?? firstFailure;
|
|
141
|
+
}
|
|
142
|
+
|
|
112
143
|
async function chooseBackend(
|
|
113
144
|
command: LocalCommand, saved: LocalExecutorSelection | undefined, configured: ExecutorSelection | undefined, signal: AbortSignal,
|
|
114
|
-
): Promise<
|
|
145
|
+
): Promise<BackendProbe | { issue: string; ambiguous?: boolean }> {
|
|
115
146
|
const explicit = command.command === 'setup' ? command.backend : undefined;
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return true;
|
|
128
|
-
} catch (error) {
|
|
129
|
-
signal.throwIfAborted();
|
|
130
|
-
if ((error as { code?: string }).code !== 'LOCAL_EXECUTOR_UNAVAILABLE') throw error;
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
if (saved?.kind === kind && await matches(saved.entry)) return { kind, entry: saved.entry, version };
|
|
135
|
-
const entry = await findExecutorEntry(kind, matches) ?? await findExecutorEntry(kind);
|
|
136
|
-
return entry ? { kind, entry, version } : undefined;
|
|
147
|
+
const driver = explicit || configured === undefined ? undefined : selectExecutorDriver(configured);
|
|
148
|
+
const preferred = explicit ?? driver?.kind ?? saved?.kind;
|
|
149
|
+
const version = explicit && command.command === 'setup' ? command.backendVersion : driver?.version;
|
|
150
|
+
if (command.command === 'setup' && command.backendPath && explicit) {
|
|
151
|
+
return probeBackend({ kind: explicit, entry: resolve(command.backendPath), version }, signal);
|
|
152
|
+
}
|
|
153
|
+
if (preferred === 'pi' || preferred === 'codex') {
|
|
154
|
+
if (saved?.kind === preferred && !explicit) return probeBackend({ ...saved, version: version ?? saved.version }, signal);
|
|
155
|
+
if (saved?.kind === preferred && version !== undefined) {
|
|
156
|
+
const candidate = await probeBackend({ ...saved, version }, signal);
|
|
157
|
+
if ('version' in candidate) return candidate;
|
|
137
158
|
}
|
|
138
|
-
|
|
139
|
-
|
|
159
|
+
return await backendOnPath(preferred, version, signal) ??
|
|
160
|
+
{ issue: `Could not find the selected ${preferred} executable on PATH.` };
|
|
140
161
|
}
|
|
141
162
|
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
163
|
+
const detected = await Promise.all((['pi', 'codex'] as const).map(kind => backendOnPath(kind, undefined, signal)));
|
|
164
|
+
const compatible = detected.filter(candidate => candidate !== undefined && 'version' in candidate);
|
|
165
|
+
if (compatible.length === 0) {
|
|
166
|
+
const errors = detected.filter(candidate => candidate !== undefined && 'error' in candidate).map(candidate => candidate.error);
|
|
167
|
+
return { issue: errors.length ? errors.join(' ') : 'Neither Pi nor Codex was found on PATH.' };
|
|
168
|
+
}
|
|
169
|
+
if (compatible.length === 1) return compatible[0]!;
|
|
170
|
+
const selectBackend = { issue: 'Both Pi and Codex have compatible installations. Choose a backend to use.', ambiguous: true };
|
|
171
|
+
if (command.command !== 'setup' || !stdin.isTTY || !stderr.isTTY) return selectBackend;
|
|
148
172
|
const input = createInterface({ input: stdin, output: stderr });
|
|
149
173
|
try {
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
? `${kind} ${probe.value} (${entry}) is compatible.\n`
|
|
156
|
-
: `${probe.reason instanceof Error ? probe.reason.message : `Could not verify ${kind} at ${entry}.`}\n`);
|
|
157
|
-
return probe.status === 'fulfilled';
|
|
158
|
-
});
|
|
159
|
-
if (choices.length <= 1) return choices[0];
|
|
160
|
-
const answer = (await input.question(`Select a local backend [${choices.map(({ kind }) => kind).join(', ')}] (pi): `, { signal })).trim() || 'pi';
|
|
161
|
-
return choices.find(candidate => candidate.kind === answer);
|
|
174
|
+
for (const { selection, version } of compatible) {
|
|
175
|
+
stderr.write(`${selection.kind} ${version} (${selection.entry}) is compatible.\n`);
|
|
176
|
+
}
|
|
177
|
+
const answer = (await input.question('Select a local backend [pi, codex] (pi): ', { signal })).trim() || 'pi';
|
|
178
|
+
return compatible.find(candidate => candidate.selection.kind === answer) ?? selectBackend;
|
|
162
179
|
} finally {
|
|
163
180
|
input.close();
|
|
164
181
|
}
|
|
@@ -185,11 +202,12 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
|
|
|
185
202
|
model?: Model;
|
|
186
203
|
modelUpstreamVerification: 'not-verified';
|
|
187
204
|
configuration?: {
|
|
188
|
-
executor: { id: string; version?: string; compatibleVersions?: readonly string[] };
|
|
205
|
+
executor: { id: string; version?: string; entry?: string; compatibleVersions?: readonly string[] };
|
|
189
206
|
image: string;
|
|
190
207
|
filePolicy: ResolvedFilePolicy;
|
|
191
208
|
};
|
|
192
209
|
checks: DiagnosticCheck[];
|
|
210
|
+
tooling?: DiagnosticCheck[];
|
|
193
211
|
timings: Timing[];
|
|
194
212
|
elapsedMs: number;
|
|
195
213
|
interrupted: boolean;
|
|
@@ -222,7 +240,10 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
|
|
|
222
240
|
let provider: Provider | undefined;
|
|
223
241
|
let rootlessDocker = false;
|
|
224
242
|
let stage = 'config';
|
|
243
|
+
progress?.('Detect host system and AnySwarm configuration…');
|
|
225
244
|
try {
|
|
245
|
+
checks.push(...checkSetupHost());
|
|
246
|
+
report.tooling = await checkHostTools(signal);
|
|
226
247
|
const config = command.configPath
|
|
227
248
|
? await loadAnySwarmConfig(command.configPath) as ProjectConfig : undefined;
|
|
228
249
|
const configured = (config?.executor ?? process.env.ANYSWARM_EXECUTOR) as ExecutorSelection | undefined;
|
|
@@ -236,92 +257,108 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
|
|
|
236
257
|
checks.push({ id: 'config.executor', ok: false, detail: 'Select a configured executor.' });
|
|
237
258
|
return report;
|
|
238
259
|
}
|
|
260
|
+
stage = 'connection';
|
|
261
|
+
const configuredPublicUrl = config?.connection?.publicUrl ?? config?.connection?.bridge?.publicUrl ?? config?.connection?.modelGateway?.publicUrl;
|
|
239
262
|
const environment = await resolveLocalEnvironment({
|
|
240
263
|
...config?.sandbox,
|
|
241
264
|
...(command.command === 'setup' && command.endpoint ? { endpoint: command.endpoint, lifecycleBaseUrl: undefined } : {}),
|
|
242
|
-
publicUrl: command.command === 'setup' ? command.publicUrl ??
|
|
265
|
+
publicUrl: command.command === 'setup' ? command.publicUrl ?? configuredPublicUrl : configuredPublicUrl,
|
|
243
266
|
image: config?.image,
|
|
244
267
|
advertiseHost: config?.connection?.advertiseHost ?? config?.connection?.modelGateway?.advertiseHost,
|
|
245
268
|
});
|
|
246
|
-
|
|
269
|
+
stage = 'config';
|
|
270
|
+
const hostname = new URL(environment.lifecycleBaseUrl).hostname;
|
|
271
|
+
const loopback = hostname === 'localhost' || hostname === '[::1]' || hostname.startsWith('127.') && isIP(hostname) === 4;
|
|
272
|
+
const reuseExisting = loopback && (environment.management === 'existing' ||
|
|
273
|
+
(!install && environment.mode === 'existing'));
|
|
274
|
+
const mode = command.mode ?? (reuseExisting ? 'existing' : 'local');
|
|
247
275
|
const smoke = install ? mode === 'local' : command.smoke;
|
|
276
|
+
report.mode = mode;
|
|
277
|
+
report.lifecycleSource = environment.endpointSource;
|
|
278
|
+
if (mode === 'local' && (!loopback || !loopbackLifecycle(environment.lifecycleBaseUrl))) {
|
|
279
|
+
checks.push({ id: 'config.lifecycle', ok: false, detail: 'The selected Lifecycle configuration is outside the managed local HTTP loopback profile.',
|
|
280
|
+
remedy: environment.endpointSource === 'saved'
|
|
281
|
+
? 'Use --mode existing to check the saved service, or run anyswarm setup --mode local --endpoint http://127.0.0.1:8080 to replace it after a successful local probe.'
|
|
282
|
+
: 'For local setup, remove the Lifecycle URL override or set it to http://127.0.0.1:8080. Use --mode existing only to connect to a service you explicitly select.' });
|
|
283
|
+
return report;
|
|
284
|
+
}
|
|
285
|
+
if (mode === 'existing' && environment.endpointSource === 'default') {
|
|
286
|
+
checks.push({ id: 'config.lifecycle', ok: false, detail: 'No existing Lifecycle service was configured.',
|
|
287
|
+
remedy: 'Run anyswarm setup for local OpenSandbox, or configure the existing Lifecycle URL and credentials explicitly.' });
|
|
288
|
+
return report;
|
|
289
|
+
}
|
|
248
290
|
if (command.command === 'setup' && command.backend && mode !== 'local') {
|
|
249
|
-
report.mode = mode;
|
|
250
291
|
checks.push({ id: 'config.executor', ok: false, detail: 'Installation selection requires --mode local with a local Docker engine.',
|
|
251
292
|
remedy: 'For an existing deployment, use its prepared Worker image.' });
|
|
252
293
|
return report;
|
|
253
294
|
}
|
|
254
295
|
if (command.command === 'setup' && environment.image && (command.backendPath || command.backendVersion)) {
|
|
255
|
-
report.mode = mode;
|
|
256
296
|
checks.push({ id: 'config.executor', ok: false, detail: 'An installation path or version pin requires a locally built Worker.',
|
|
257
297
|
remedy: 'Remove the configured Worker image to select an installation, or pin the version in the project executor configuration.' });
|
|
258
298
|
return report;
|
|
259
299
|
}
|
|
260
300
|
if (smoke && mode === 'existing' && !environment.image && !driver.adapter) {
|
|
261
|
-
report.mode = mode;
|
|
262
301
|
checks.push({ id: 'config.worker', ok: false, detail: 'An existing service requires an explicitly prepared Worker image.',
|
|
263
302
|
remedy: 'Set ANYSWARM_WORKER_IMAGE to the image provided by the operator.' });
|
|
264
303
|
return report;
|
|
265
304
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
305
|
+
let localVersion: string | undefined;
|
|
306
|
+
if (mode === 'local' && !environment.image && !driver.adapter) {
|
|
307
|
+
progress?.('Detect an installed Pi or Codex executable…');
|
|
308
|
+
const detected = await chooseBackend(command, environment.localExecutor, configured, signal);
|
|
309
|
+
if ('issue' in detected) {
|
|
310
|
+
const remedy = detected.ambiguous
|
|
311
|
+
? 'Run anyswarm setup --backend pi or anyswarm setup --backend codex.'
|
|
312
|
+
: 'For Pi, run npm install -g @earendil-works/pi-coding-agent, then run anyswarm setup --backend pi. For Codex, run npm install -g @openai/codex, then run anyswarm setup --backend codex.';
|
|
313
|
+
checks.push({ id: 'config.executor', ok: false, detail: detected.issue, remedy });
|
|
314
|
+
} else {
|
|
315
|
+
localExecutor = detected.selection;
|
|
316
|
+
executor = { kind: localExecutor.kind, version: localExecutor.version };
|
|
317
|
+
driver = selectExecutorDriver(executor);
|
|
318
|
+
if ('error' in detected) {
|
|
319
|
+
checks.push({ id: 'config.executor', ok: false, detail: detected.error,
|
|
320
|
+
remedy: 'Restore the saved executable or select a supported installation with anyswarm setup --backend pi or anyswarm setup --backend codex.' });
|
|
321
|
+
} else {
|
|
322
|
+
localVersion = detected.version;
|
|
323
|
+
const detail = `Detected ${localExecutor.kind} ${localVersion} at ${localExecutor.entry}.`;
|
|
324
|
+
checks.push({ id: 'config.executor', ok: true, detail });
|
|
325
|
+
progress?.(detail);
|
|
326
|
+
}
|
|
275
327
|
}
|
|
276
|
-
if (driver.version !== undefined) localExecutor = { ...localExecutor, version: driver.version };
|
|
277
|
-
executor = { kind: localExecutor.kind, version: localExecutor.version };
|
|
278
|
-
driver = selectExecutorDriver(executor);
|
|
279
328
|
}
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
model: process.env.ANYSWARM_MODEL_ID ?? '', protocol: process.env.ANYSWARM_MODEL_PROTOCOL,
|
|
284
|
-
upstream: { url: process.env.ANYSWARM_MODEL_URL, headers: {} },
|
|
285
|
-
};
|
|
329
|
+
if (config) {
|
|
330
|
+
report.model = modelState(config, driver.kind);
|
|
331
|
+
} else {
|
|
286
332
|
try {
|
|
287
|
-
|
|
288
|
-
|
|
333
|
+
const route = readSubagentsModel(driver.kind);
|
|
334
|
+
if (route) snapshotModel(route, driver.kind);
|
|
335
|
+
report.model = { configuration: route ? 'complete' : 'missing', verification: 'not-verified' };
|
|
289
336
|
} catch {
|
|
290
337
|
report.model = { configuration: 'invalid', verification: 'not-verified' };
|
|
291
338
|
}
|
|
292
|
-
}
|
|
293
|
-
|
|
339
|
+
}
|
|
340
|
+
if (report.model.configuration === 'missing') {
|
|
341
|
+
report.model.remedy = config ? 'Set an upstream endpoint for each active model route in the trusted configuration.'
|
|
342
|
+
: 'Before running the Quickstart Harness, set ANYSWARM_MODEL_URL and ANYSWARM_MODEL_ID. Set ANYSWARM_MODEL_TOKEN if the endpoint requires authentication.';
|
|
294
343
|
}
|
|
295
344
|
if (report.model?.configuration === 'invalid') checks.push({
|
|
296
345
|
id: 'config.models', ok: false, detail: 'An active model alias, capability declaration or protocol endpoint is invalid for the selected executor.',
|
|
297
346
|
remedy: 'Use a supported executor and protocol combination, and configure an HTTP(S) endpoint without embedded credentials for each active model alias.',
|
|
298
347
|
});
|
|
299
|
-
if (
|
|
300
|
-
if (config) {
|
|
348
|
+
if (config && report.model.configuration !== 'invalid') {
|
|
301
349
|
const { lifecycleBaseUrl, apiKey, endpointHost } = environment;
|
|
302
350
|
checks.push(checkProjectRuntime({
|
|
303
|
-
...config, executor, connection: { ...config.connection, publicUrl: environment.publicUrl
|
|
351
|
+
...config, executor, connection: { ...config.connection, publicUrl: environment.publicUrl,
|
|
352
|
+
advertiseHost: environment.advertiseHost },
|
|
304
353
|
}, { ...config.sandbox, endpoint: undefined, lifecycleBaseUrl, apiKey, endpointHost }));
|
|
305
354
|
}
|
|
306
|
-
if (checks.some(check => !check.ok)) return report;
|
|
307
355
|
report.configuration = {
|
|
308
|
-
executor: { id: driver.kind, version: driver.version,
|
|
356
|
+
executor: { id: driver.kind, version: localVersion ?? driver.version, entry: localExecutor?.entry,
|
|
357
|
+
compatibleVersions: driver.adapter?.compatibleVersions },
|
|
309
358
|
image: environment.image ?? workerImageFor(executor),
|
|
310
359
|
filePolicy: resolveFilePolicy(config?.filePolicy),
|
|
311
360
|
};
|
|
312
|
-
|
|
313
|
-
try {
|
|
314
|
-
report.configuration.executor.version = await checkLocalExecutor(localExecutor, signal);
|
|
315
|
-
} catch (error) {
|
|
316
|
-
signal.throwIfAborted();
|
|
317
|
-
if ((error as { code?: string }).code !== 'LOCAL_EXECUTOR_UNAVAILABLE') throw error;
|
|
318
|
-
checks.push({ id: 'config.executor', ok: false, detail: (error as Error).message });
|
|
319
|
-
return report;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
const publicUrl = environment.publicUrl ?? config?.connection?.bridge?.publicUrl ?? config?.connection?.modelGateway?.publicUrl;
|
|
323
|
-
report.mode = mode;
|
|
324
|
-
report.lifecycleSource = environment.endpointSource;
|
|
361
|
+
const publicUrl = environment.publicUrl;
|
|
325
362
|
report.connection = {
|
|
326
363
|
lifecycleBaseUrl: reportedEndpoint(environment.lifecycleBaseUrl),
|
|
327
364
|
advertiseHost: reportedHost(environment.advertiseHost),
|
|
@@ -333,21 +370,19 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
|
|
|
333
370
|
};
|
|
334
371
|
stage = 'host';
|
|
335
372
|
const darwin = process.platform === 'darwin';
|
|
336
|
-
checks.push(...checkSetupHost({ requiresLinux: !darwin }));
|
|
337
|
-
if (checks.some(check => !check.ok)) return report;
|
|
338
373
|
let advertiseHost = environment.advertiseHost;
|
|
339
374
|
let advertiseHostDiscovery = environment.advertiseHostDiscovery;
|
|
340
|
-
if (mode === 'local' && (
|
|
375
|
+
if (mode === 'local' && checks.find(check => check.id === 'host.platform')?.ok) {
|
|
341
376
|
const docker = await timed('host', checkLocalDocker);
|
|
342
377
|
checks.push(docker.diagnostic);
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
if (advertiseHost === undefined && docker.docker.advertiseHost !== undefined) {
|
|
378
|
+
rootlessDocker = docker.docker?.rootless ?? false;
|
|
379
|
+
if (advertiseHost === undefined && docker.docker?.advertiseHost !== undefined) {
|
|
346
380
|
advertiseHost = docker.docker.advertiseHost;
|
|
347
381
|
report.connection.advertiseHost = reportedHost(advertiseHost);
|
|
348
382
|
report.connection.sources.advertiseHost = 'docker-network';
|
|
349
383
|
}
|
|
350
384
|
}
|
|
385
|
+
if (checks.some(check => !check.ok)) return report;
|
|
351
386
|
let image = report.configuration.image;
|
|
352
387
|
if (mode === 'local' && smoke) {
|
|
353
388
|
stage = 'worker';
|
|
@@ -375,7 +410,7 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
|
|
|
375
410
|
progress?.(provider.created ? 'Started managed OpenSandbox' : 'Reused managed OpenSandbox');
|
|
376
411
|
}
|
|
377
412
|
const active = provider?.config ?? environment;
|
|
378
|
-
checks.push(...await timed('provider', () => checkLocalProvider(active)));
|
|
413
|
+
checks.push(...await timed('provider', () => checkLocalProvider(active, { managed: mode === 'local' })));
|
|
379
414
|
if (checks.some(check => !check.ok)) return report;
|
|
380
415
|
|
|
381
416
|
report.infrastructure = 'preflight-passed';
|
|
@@ -422,14 +457,20 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
|
|
|
422
457
|
// Configuration imports and provider/npm errors can contain credentials.
|
|
423
458
|
const failure: Record<string, [string, string]> = {
|
|
424
459
|
config: ['Could not load the project configuration.', 'Check the trusted config.js and adjacent .env file.'],
|
|
460
|
+
connection: ['Could not resolve the OpenSandbox connection.', 'Check the Lifecycle endpoint and Runtime callback settings.'],
|
|
425
461
|
host: ['Could not complete the host capability checks.', 'Check the installation diagnostics for the selected setup mode.'],
|
|
426
462
|
worker: ['Could not prepare the compatible Worker image.', 'Check local Docker and the configured Worker image.'],
|
|
427
463
|
provider: ['Could not prepare or verify a compatible OpenSandbox provider.', 'Run anyswarm doctor to check lifecycle authentication. Ensure the requested endpoint or local port is available.'],
|
|
428
464
|
smoke: ['Could not complete the infrastructure probe.', 'Check the local OpenSandbox service, Worker image and host network.'],
|
|
429
465
|
};
|
|
430
466
|
let [detail, remedy] = failure[stage];
|
|
467
|
+
let checkId = stage;
|
|
431
468
|
const code = (error as { code?: string })?.code;
|
|
432
|
-
if (code === '
|
|
469
|
+
if (code === 'HOST_NETWORK_DISCOVERY_FAILED' && stage === 'connection') {
|
|
470
|
+
checkId = 'host.network-discovery';
|
|
471
|
+
detail = 'Could not inspect host network interfaces for the Sandbox callback address.';
|
|
472
|
+
remedy = 'Set ANYSWARM_ADVERTISE_HOST or ANYSWARM_RUNTIME_PUBLIC_URL to an address reachable from the Sandbox, then rerun the command.';
|
|
473
|
+
} else if (code === 'DOCKER_CALLBACK_UNAVAILABLE') {
|
|
433
474
|
detail = 'The Docker container could not resolve a unique Mac callback IPv4 address.';
|
|
434
475
|
remedy = 'Check host.docker.internal from the selected local engine, or configure a Runtime publicUrl reachable from the Sandbox.';
|
|
435
476
|
} else if (stage === 'provider' && ['PROVIDER_EXECD_PULL_FAILED', 'PROVIDER_SERVER_PULL_FAILED', 'PROVIDER_EGRESS_PULL_FAILED'].includes(code ?? '')) {
|
|
@@ -453,7 +494,7 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
|
|
|
453
494
|
} else if (stage === 'provider' && rootlessDocker) {
|
|
454
495
|
remedy = 'Verify that the selected rootless Docker context can start containers and expose the Lifecycle address. Check delegated CPU and memory controllers before retrying.';
|
|
455
496
|
}
|
|
456
|
-
if (!signal.aborted) checks.push({ id:
|
|
497
|
+
if (!signal.aborted) checks.push({ id: checkId, ok: false, detail, remedy });
|
|
457
498
|
// A provider deployment can fail before returning its ownership handle.
|
|
458
499
|
if (stage === 'provider' && error && typeof error === 'object' && 'cleanup' in error && error.cleanup && typeof error.cleanup === 'object' &&
|
|
459
500
|
'id' in error.cleanup && typeof error.cleanup.id === 'string' && 'status' in error.cleanup &&
|
|
@@ -484,7 +525,11 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
|
|
|
484
525
|
if (report.smoke.outputDir) progress?.(`Probe evidence: ${report.smoke.outputDir}`);
|
|
485
526
|
progress?.('Controlled smoke completed. The configured model upstream was not contacted.');
|
|
486
527
|
}
|
|
487
|
-
|
|
528
|
+
for (const tool of report.tooling?.filter(check => !check.ok) ?? []) {
|
|
529
|
+
progress?.([tool.detail, tool.remedy].filter(Boolean).join(' '));
|
|
530
|
+
}
|
|
531
|
+
if (report.model?.remedy) progress?.(report.model.remedy);
|
|
532
|
+
if (report.ok) progress?.(installNextStep(command, report.mode));
|
|
488
533
|
}
|
|
489
534
|
return report;
|
|
490
535
|
}
|
package/scripts/pack-release.ts
CHANGED
|
@@ -5,8 +5,19 @@ import { join, resolve } from 'node:path';
|
|
|
5
5
|
import { promisify } from 'node:util';
|
|
6
6
|
|
|
7
7
|
const [destination, ...options] = process.argv.slice(2);
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
let skipBuild = false;
|
|
9
|
+
let releaseVersion: string | undefined;
|
|
10
|
+
for (let index = 0; index < options.length; index++) {
|
|
11
|
+
const option = options[index];
|
|
12
|
+
if (option === '--skip-build' && !skipBuild) skipBuild = true;
|
|
13
|
+
else if (option === '--version' && releaseVersion === undefined) releaseVersion = options[++index];
|
|
14
|
+
else throw new Error(`Unsupported or repeated pack option: ${option}`);
|
|
15
|
+
}
|
|
16
|
+
if (!destination || options.includes('--version') && !releaseVersion) {
|
|
17
|
+
throw new Error('Usage: npm run pack:release -- <output-directory> [--skip-build] [--version <next-version>]');
|
|
18
|
+
}
|
|
19
|
+
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)) {
|
|
20
|
+
throw new Error('A staged version override must be an immutable next release version');
|
|
10
21
|
}
|
|
11
22
|
|
|
12
23
|
// Keep the build and staging umask independent of the caller.
|
|
@@ -15,7 +26,7 @@ process.umask(0o022);
|
|
|
15
26
|
const run = promisify(execFile);
|
|
16
27
|
const repository = resolve(import.meta.dirname, '..');
|
|
17
28
|
const output = resolve(destination);
|
|
18
|
-
if (!
|
|
29
|
+
if (!skipBuild) {
|
|
19
30
|
const build = spawnSync('npm', ['run', 'build'], { cwd: repository, stdio: ['ignore', 2, 2] });
|
|
20
31
|
if (build.error) throw build.error;
|
|
21
32
|
if (build.status !== 0) process.exit(build.status ?? 1);
|
|
@@ -37,12 +48,25 @@ try {
|
|
|
37
48
|
const manifestPath = join(staged, 'package.json');
|
|
38
49
|
const lockPath = join(staged, 'npm-shrinkwrap.json');
|
|
39
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 });
|
|
40
65
|
const lock = JSON.parse(await readFile(lockPath, 'utf8'));
|
|
41
66
|
if (lock.lockfileVersion !== 3 || !lock.packages?.['']) {
|
|
42
67
|
throw new Error('Release packaging requires a v3 npm shrinkwrap with root package metadata');
|
|
43
68
|
}
|
|
44
69
|
|
|
45
|
-
// Only the service-image build stages use the development inputs.
|
|
46
70
|
await rename(manifestPath, join(staged, 'package.development.json'));
|
|
47
71
|
await rename(lockPath, join(staged, 'npm-shrinkwrap.development.json'));
|
|
48
72
|
delete manifest.private;
|
package/src/core/index.ts
CHANGED
|
@@ -220,7 +220,7 @@ function planRuntimeWorker(
|
|
|
220
220
|
}
|
|
221
221
|
return { kind: worker.executor, prepare: async () => worker };
|
|
222
222
|
}
|
|
223
|
-
const { localExecutor } = resolveSandboxConnectionWithSources({ lifecycleBaseUrl: endpoint });
|
|
223
|
+
const { localExecutor } = resolveSandboxConnectionWithSources({ lifecycleBaseUrl: endpoint }, undefined, { discoverHost: false });
|
|
224
224
|
const kind = options.executor ? config.driver.kind : selectors.find(selector => selector.kind)?.kind ?? localExecutor?.kind ?? config.driver.kind;
|
|
225
225
|
if (kind !== 'pi' && kind !== 'codex') throw executorFailure('Select Pi or Codex for the built-in local Worker.');
|
|
226
226
|
if (selectors.some(selector => selector.kind && selector.kind !== kind)) {
|
|
@@ -191,7 +191,7 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
191
191
|
import { isIP } from 'node:net';
|
|
192
192
|
import { lookup } from 'node:dns/promises';
|
|
193
193
|
import { createWorkerEventPoll } from '../worker-event-poll.js';
|
|
194
|
-
import { loopbackLifecycle, normalizeRuntimePublicUrl, resolveSandboxConnection } from './sandbox-connection.js';
|
|
194
|
+
import { discoverDockerCallbackHost, loopbackLifecycle, normalizeRuntimePublicUrl, resolveSandboxConnection } from './sandbox-connection.js';
|
|
195
195
|
import { validId } from '../config.js';
|
|
196
196
|
import { adaptSandboxProvider, createApiOpenSandboxProvider, type OpenSandboxProvider } from './opensandbox-provider.js';
|
|
197
197
|
|
|
@@ -294,7 +294,10 @@ export function createSandbox(config: SandboxConfig | SandboxProviderConfig = {}
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
const { lifecycleBaseUrl: _alias, endpoint: _endpoint, endpointHost: _endpointHost, ...settings } = sandbox;
|
|
297
|
-
|
|
297
|
+
// Runtime callback options are supplied at claim time, after this handle is
|
|
298
|
+
// created. Snapshot configured settings here without enumerating interfaces.
|
|
299
|
+
const { lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, useServerProxy, egressMode } =
|
|
300
|
+
resolveSandboxConnection(sandbox, undefined, { discoverHost: false });
|
|
298
301
|
sandboxes.set(handle, freeze(structuredClone({
|
|
299
302
|
sandbox: { ...settings, lifecycleBaseUrl, apiKey, publicUrl, advertiseHost, useServerProxy, egressMode, timeoutSeconds },
|
|
300
303
|
isolation: { network: 'api' } as const,
|
|
@@ -316,10 +319,13 @@ export function claimOpenSandboxBackend(handle: Sandbox, options: Pick<CreateRun
|
|
|
316
319
|
if (hosts.size > 1) throw invalid('Bridge and Model Gateway must use the same connection.bindHost');
|
|
317
320
|
const port = connection?.bindPort ?? 0;
|
|
318
321
|
if (!Number.isSafeInteger(port) || port < 0 || port > 65_535) throw invalid('connection.bindPort must be from 0 through 65535');
|
|
319
|
-
const advertiseHost = connection?.advertiseHost ?? gateway?.advertiseHost ?? settings.sandbox.advertiseHost ??
|
|
320
|
-
((settings.sandbox.lifecycleBaseUrl && loopbackLifecycle(settings.sandbox.lifecycleBaseUrl)) || settings.provider ? '172.17.0.1' : undefined);
|
|
321
322
|
const savedPublicUrl = settings.sandbox.publicUrl;
|
|
322
323
|
const advertised = [...candidates][0] ?? savedPublicUrl;
|
|
324
|
+
let advertiseHost = connection?.advertiseHost ?? gateway?.advertiseHost ?? settings.sandbox.advertiseHost;
|
|
325
|
+
if (advertiseHost === undefined && settings.provider) advertiseHost = '172.17.0.1';
|
|
326
|
+
if (advertiseHost === undefined && !advertised && settings.sandbox.lifecycleBaseUrl && loopbackLifecycle(settings.sandbox.lifecycleBaseUrl)) {
|
|
327
|
+
advertiseHost = discoverDockerCallbackHost() ?? '172.17.0.1';
|
|
328
|
+
}
|
|
323
329
|
if (!advertised && !advertiseHost) throw invalid('For an existing remote OpenSandbox, set connection.publicUrl to the Runtime address reachable from the Sandbox');
|
|
324
330
|
const workerHost = advertiseHost ?? new URL(advertised!).hostname.replace(/^\[|\]$/g, '');
|
|
325
331
|
if (!/^[a-zA-Z0-9.:-]+$/.test(workerHost) || ['localhost', '0.0.0.0', '::'].includes(workerHost) && !advertised) {
|
|
@@ -124,7 +124,16 @@ function loadSavedConnection(): ConnectionInput {
|
|
|
124
124
|
return saved;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
export function
|
|
127
|
+
export function discoverDockerCallbackHost(): string | undefined {
|
|
128
|
+
try { return networkInterfaces().docker0?.find(item => item.family === 'IPv4')?.address; }
|
|
129
|
+
catch {
|
|
130
|
+
throw Object.assign(new Error('Could not inspect host network interfaces for the Sandbox callback address. ' +
|
|
131
|
+
'Set ANYSWARM_ADVERTISE_HOST or ANYSWARM_RUNTIME_PUBLIC_URL to an address reachable from the Sandbox.'),
|
|
132
|
+
{ code: 'HOST_NETWORK_DISCOVERY_FAILED' });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function resolveSandboxConnectionWithSources(input: ConnectionInput = {}, scope?: string, { useSaved = true, discoverHost = true } = {}) {
|
|
128
137
|
const environment = process.env;
|
|
129
138
|
const example = (name: string) => scope ? environment[`ANYSWARM_${scope}_${name}`] || undefined : undefined;
|
|
130
139
|
const explicit = input.endpoint === undefined ? undefined : lifecycleUrl(input.endpoint, 'endpoint');
|
|
@@ -157,13 +166,17 @@ export function resolveSandboxConnectionWithSources(input: ConnectionInput = {},
|
|
|
157
166
|
const endpointHost = input.endpointHost ?? (environment.ANYSWARM_ENDPOINT_HOST || undefined) ?? example('ENDPOINT_HOST');
|
|
158
167
|
if (endpointHost !== undefined) throw connectionError('endpointHost was removed. Configure OpenSandbox to publish a reachable endpoint.');
|
|
159
168
|
const publicUrl = input.publicUrl ?? (environment.ANYSWARM_RUNTIME_PUBLIC_URL || undefined) ?? stored.publicUrl;
|
|
169
|
+
const normalizedPublicUrl = publicUrl === undefined ? undefined : normalizeRuntimePublicUrl(publicUrl);
|
|
160
170
|
const from = (settings: readonly (readonly [string, string | undefined])[]) =>
|
|
161
171
|
settings.find(([, value]) => value !== undefined && value !== '');
|
|
162
|
-
|
|
172
|
+
let callback = from([
|
|
163
173
|
['config', input.advertiseHost], ['ANYSWARM_ADVERTISE_HOST', environment.ANYSWARM_ADVERTISE_HOST],
|
|
164
174
|
[`ANYSWARM_${scope}_ADVERTISE_HOST`, example('ADVERTISE_HOST')], ['saved', stored.advertiseHost],
|
|
165
|
-
['docker0', local ? networkInterfaces().docker0?.find(address => address.family === 'IPv4')?.address : undefined],
|
|
166
175
|
]);
|
|
176
|
+
if (discoverHost && !callback && !normalizedPublicUrl && local) {
|
|
177
|
+
const address = discoverDockerCallbackHost();
|
|
178
|
+
if (address) callback = ['docker0', address];
|
|
179
|
+
}
|
|
167
180
|
const worker = from([
|
|
168
181
|
['config', input.image], ['ANYSWARM_WORKER_IMAGE', environment.ANYSWARM_WORKER_IMAGE],
|
|
169
182
|
[`ANYSWARM_${scope}_IMAGE`, example('IMAGE')], ['saved', stored.image],
|
|
@@ -174,7 +187,7 @@ export function resolveSandboxConnectionWithSources(input: ConnectionInput = {},
|
|
|
174
187
|
environment.OPENSANDBOX_API_KEY || undefined) ?? stored.apiKey ?? (local && readPrivateFile(localApiKeyPath(local), 256)),
|
|
175
188
|
advertiseHost: callback?.[1],
|
|
176
189
|
advertiseHostDiscovery: callback?.[0] === 'saved' ? stored.advertiseHostDiscovery : undefined,
|
|
177
|
-
publicUrl:
|
|
190
|
+
publicUrl: normalizedPublicUrl,
|
|
178
191
|
image: worker?.[1],
|
|
179
192
|
useServerProxy: input.useServerProxy ?? stored.useServerProxy,
|
|
180
193
|
egressMode: input.egressMode ?? stored.egressMode,
|
|
@@ -188,10 +201,12 @@ export function resolveSandboxConnectionWithSources(input: ConnectionInput = {},
|
|
|
188
201
|
};
|
|
189
202
|
}
|
|
190
203
|
|
|
191
|
-
export function resolveSandboxConnection(
|
|
204
|
+
export function resolveSandboxConnection(input?: ConnectionInput, scope?: string,
|
|
205
|
+
{ useSaved = true, discoverHost = true, includePreparedImage = false } = {}) {
|
|
192
206
|
const { sources: _sources, advertiseHostDiscovery: _discovery, management: _management, providerId: _providerId,
|
|
193
|
-
localExecutor, preparedImage
|
|
194
|
-
return { ...connection, executor: localExecutor?.kind
|
|
207
|
+
localExecutor, preparedImage, ...connection } = resolveSandboxConnectionWithSources(input, scope, { useSaved, discoverHost });
|
|
208
|
+
return { ...connection, executor: localExecutor?.kind,
|
|
209
|
+
...(includePreparedImage && preparedImage ? { preparedImage } : {}) };
|
|
195
210
|
}
|
|
196
211
|
|
|
197
212
|
export async function saveSandboxConnection(input: ConnectionInput & { lifecycleBaseUrl: string }) {
|