@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
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { resolve } from 'node:path';
|
|
2
1
|
import { frameworkErrorFields } from '../src/core/error-diagnostics.js';
|
|
3
|
-
import { captureHarnessSnapshot, createHarnessSession, failureCode, getHarnessExitCode,
|
|
2
|
+
import { captureHarnessSnapshot, createHarnessSession, failureCode, getHarnessExitCode, stopHarnessTransport } from '../src/harness/project-harness.js';
|
|
4
3
|
import { resolveHarnessInput } from '../src/harness/project-input.js';
|
|
5
4
|
import { runProjectRpc } from '../src/harness/project-rpc.js';
|
|
6
|
-
import type {
|
|
5
|
+
import type { ProjectCommand } from './anyswarm-arguments.js';
|
|
7
6
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { actionReport, actionRun, configuredStopTimeout, harnessLifetime, loadHarness, requestedTraceRoot, splitInput, type ActionRun } from './anyswarm-launch.js';
|
|
11
|
-
import { LauncherConfiguration } from './anyswarm-tui-config.js';
|
|
7
|
+
import { prepareProjectLaunch } from './anyswarm-launch.js';
|
|
8
|
+
import { foregroundProgress } from './anyswarm-progress.js';
|
|
12
9
|
|
|
13
10
|
const MAX_QUEUED_OUTPUT_BYTES = 1_048_576;
|
|
14
11
|
const MAX_OUTPUT_RECORD_BYTES = 8 * 1024 * 1024;
|
|
@@ -22,18 +19,15 @@ interface OutputFrame {
|
|
|
22
19
|
}
|
|
23
20
|
|
|
24
21
|
export async function runProjectCommand(command: ProjectCommand, launchDirectory: string,
|
|
25
|
-
options: { onSourceError?: (error: unknown) => void
|
|
26
|
-
|
|
27
|
-
} } = {}) {
|
|
22
|
+
options: { onSourceError?: (error: unknown) => void } = {}) {
|
|
23
|
+
const human = command.mode === 'foreground' && process.stdout.isTTY;
|
|
28
24
|
const stdout = process.stdout.write;
|
|
29
25
|
const transport = stdout.bind(process.stdout);
|
|
30
26
|
const startup = new AbortController();
|
|
31
27
|
let session: ReturnType<typeof createHarnessSession> | undefined;
|
|
32
28
|
let signalCode: number | undefined;
|
|
33
29
|
let outputFailed = false;
|
|
34
|
-
let
|
|
35
|
-
let trace: Promise<{ root: string; close(): Promise<void> } | undefined> | undefined;
|
|
36
|
-
let unsubscribeTrace: (() => void) | undefined;
|
|
30
|
+
let progress: ReturnType<typeof foregroundProgress> | undefined;
|
|
37
31
|
let lastWrite: Promise<void> | undefined;
|
|
38
32
|
const outputQueue: OutputFrame[] = [];
|
|
39
33
|
let queuedBytes = 0;
|
|
@@ -78,16 +72,8 @@ export async function runProjectCommand(command: ProjectCommand, launchDirectory
|
|
|
78
72
|
}
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
const
|
|
75
|
+
const enqueue = (data: string, replaceableState = false): Promise<void> => {
|
|
82
76
|
if (outputFailed) return Promise.resolve();
|
|
83
|
-
let encoded: string;
|
|
84
|
-
try {
|
|
85
|
-
encoded = JSON.stringify(record);
|
|
86
|
-
} catch {
|
|
87
|
-
pipeFailed();
|
|
88
|
-
return Promise.resolve();
|
|
89
|
-
}
|
|
90
|
-
const data = encoded + '\n';
|
|
91
77
|
const bytes = Buffer.byteLength(data);
|
|
92
78
|
const last = outputQueue.at(-1);
|
|
93
79
|
const replace = replaceableState && last?.replaceableState ? last : undefined;
|
|
@@ -107,6 +93,10 @@ export async function runProjectCommand(command: ProjectCommand, launchDirectory
|
|
|
107
93
|
void flushOutput();
|
|
108
94
|
return lastWrite;
|
|
109
95
|
};
|
|
96
|
+
const write = (record: unknown, replaceableState = false): Promise<void> => {
|
|
97
|
+
try { return enqueue(JSON.stringify(record) + '\n', replaceableState); }
|
|
98
|
+
catch { pipeFailed(); return Promise.resolve(); }
|
|
99
|
+
};
|
|
110
100
|
const ignoreDiagnosticError = () => {};
|
|
111
101
|
process.on('SIGINT', signal);
|
|
112
102
|
process.on('SIGTERM', signal);
|
|
@@ -118,79 +108,44 @@ export async function runProjectCommand(command: ProjectCommand, launchDirectory
|
|
|
118
108
|
const stopped = Promise.withResolvers<never>();
|
|
119
109
|
const abortStartup = () => stopped.reject(startup.signal.reason);
|
|
120
110
|
startup.signal.addEventListener('abort', abortStartup, { once: true });
|
|
121
|
-
|
|
122
|
-
const loaded = options.action?.loaded ?? (command.defaults
|
|
123
|
-
? await loadHarness(launchDirectory, command.harness, options) : undefined);
|
|
124
|
-
const definition = loaded?.definition ?? await loadProjectHarness(launchDirectory, command.harness, builtins, options);
|
|
125
|
-
const config = { launchDirectory, configPath: command.configPath, outputRoot: command.outputRoot,
|
|
126
|
-
lifetime: command.lifetime, clientCapabilities: { questions: command.mode !== 'headless' && command.interaction === 'questions' } };
|
|
127
|
-
if (!command.defaults) return createHarnessSession(definition, config);
|
|
128
|
-
const launcher = new LauncherConfiguration(command.harness, command.harness, launchDirectory,
|
|
129
|
-
'cwd' in command ? command.cwd : undefined, command.configPath);
|
|
130
|
-
let configuration = options.action?.run.configuration;
|
|
131
|
-
if (!options.action) {
|
|
132
|
-
await launcher.refresh();
|
|
133
|
-
if (launcher.error) throw new Error(launcher.error);
|
|
134
|
-
configuration = launcher.configuration;
|
|
135
|
-
if (!workspace && loaded?.workspace && command.mode !== 'rpc') {
|
|
136
|
-
workspace = loaded.workspace({ cwd: launcher.workspace, configuration });
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const lifetime = harnessLifetime(definition, command.lifetime, findApplication(command.harness)?.lifetime);
|
|
140
|
-
return createHarnessSession(definition, { ...config, configPath: undefined, configuration, lifetime,
|
|
141
|
-
stopTimeoutMs: configuredStopTimeout(configuration) });
|
|
142
|
-
};
|
|
111
|
+
let launch;
|
|
143
112
|
try {
|
|
144
|
-
|
|
113
|
+
launch = await Promise.race([prepareProjectLaunch(command, launchDirectory, options, startup.signal), stopped.promise]);
|
|
114
|
+
session = launch.session;
|
|
145
115
|
startup.signal.throwIfAborted();
|
|
146
116
|
} finally {
|
|
147
117
|
startup.signal.removeEventListener('abort', abortStartup);
|
|
148
118
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
const root = requestedTraceRoot(event.event, event.runId);
|
|
152
|
-
if (!root) return;
|
|
153
|
-
const modulePath = '../src/trace-viewer/server.mjs';
|
|
154
|
-
trace = import(modulePath).then(async ({ startTraceServer }) => {
|
|
155
|
-
const viewer = await startTraceServer({ root, port: 0 });
|
|
156
|
-
console.error('Live Trace URL ' + viewer.url);
|
|
157
|
-
return { root, close: () => viewer.close() };
|
|
158
|
-
}).catch(() => {
|
|
159
|
-
console.error('Could not open the live Trace Viewer. Replay this Run from its records.');
|
|
160
|
-
return undefined;
|
|
161
|
-
});
|
|
162
|
-
}, { initialSnapshot: false });
|
|
163
|
-
const input = command.mode !== 'rpc'
|
|
164
|
-
? resolveHarnessInput({ cwd: workspace, prompt: command.prompt }, launchDirectory)
|
|
165
|
-
: undefined;
|
|
166
|
-
if (command.mode === 'rpc' || (command.mode === 'foreground' && (command.lifetime === 'interactive' || command.interaction === 'questions'))) {
|
|
167
|
-
const code = await runProjectRpc(session, process.stdin, write, launchDirectory, input);
|
|
119
|
+
if (command.mode === 'rpc') {
|
|
120
|
+
const code = await runProjectRpc(session, process.stdin, write, launchDirectory);
|
|
168
121
|
await lastWrite;
|
|
169
122
|
return signalCode ?? (outputFailed ? 1 : code);
|
|
170
123
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
124
|
+
if (human) progress = foregroundProgress(session, launch.harnessId, launchDirectory, command.outputRoot, message => enqueue(message + '\n'));
|
|
125
|
+
const input = resolveHarnessInput({ cwd: launch.cwd, prompt: command.prompt }, launchDirectory);
|
|
126
|
+
const unsubscribe = progress && session.onEvent(progress.observe, {
|
|
127
|
+
initialSnapshot: false,
|
|
128
|
+
onError: () => { void enqueue('Live progress unavailable. Follow the Run in Trace.\n'); },
|
|
129
|
+
});
|
|
174
130
|
let result;
|
|
175
131
|
try {
|
|
176
|
-
await session.start(input
|
|
132
|
+
await session.start(input, { requestId: 'foreground-start' });
|
|
177
133
|
result = await session.completion!;
|
|
178
134
|
} finally { unsubscribe?.(); }
|
|
179
|
-
|
|
135
|
+
if (progress) await progress.finish(result);
|
|
136
|
+
else await write({ type: 'result', runId: result.runId, result });
|
|
180
137
|
return signalCode ?? (outputFailed ? 1 : getHarnessExitCode(session));
|
|
181
138
|
} catch (error) {
|
|
182
139
|
if (!startup.signal.aborted) {
|
|
183
140
|
const code = failureCode(error, 'HARNESS_COMMAND_FAILED');
|
|
184
|
-
|
|
141
|
+
const message = error instanceof Error ? error.message : undefined;
|
|
142
|
+
if (human) {
|
|
143
|
+
if (progress) await progress.fail(code, message);
|
|
144
|
+
else console.error(code + (message ? ' ' + message : ''));
|
|
145
|
+
} else await write({ type: 'error', code, ...(message ? { message } : {}), ...frameworkErrorFields(error) });
|
|
185
146
|
}
|
|
186
147
|
return signalCode ?? (outputFailed ? 1 : 2);
|
|
187
148
|
} finally {
|
|
188
|
-
unsubscribeTrace?.();
|
|
189
|
-
const viewer = await trace;
|
|
190
|
-
if (viewer) {
|
|
191
|
-
await viewer.close().catch(() => {});
|
|
192
|
-
console.error('Replay with anys trace --root ' + JSON.stringify(viewer.root));
|
|
193
|
-
}
|
|
194
149
|
process.stdout.write = stdout;
|
|
195
150
|
process.off('SIGINT', signal);
|
|
196
151
|
process.off('SIGTERM', signal);
|
|
@@ -198,50 +153,3 @@ export async function runProjectCommand(command: ProjectCommand, launchDirectory
|
|
|
198
153
|
process.stderr.off('error', ignoreDiagnosticError);
|
|
199
154
|
}
|
|
200
155
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
export async function runHarnessAction(command: Extract<HarnessCommand, { mode: 'action' }>, launchDirectory: string,
|
|
204
|
-
options?: Parameters<typeof loadHarness>[2]) {
|
|
205
|
-
const controller = new AbortController();
|
|
206
|
-
let exitCode = 0;
|
|
207
|
-
let start: { run: ActionRun; loaded: Awaited<ReturnType<typeof loadHarness>> } | undefined;
|
|
208
|
-
const cancel = (signal: 'SIGINT' | 'SIGTERM') => {
|
|
209
|
-
exitCode ||= signal === 'SIGINT' ? 130 : 143;
|
|
210
|
-
controller.abort();
|
|
211
|
-
};
|
|
212
|
-
const stdout = process.stdout.write;
|
|
213
|
-
process.stdout.write = process.stderr.write.bind(process.stderr);
|
|
214
|
-
process.on('SIGINT', cancel).on('SIGTERM', cancel);
|
|
215
|
-
try {
|
|
216
|
-
const loaded = await loadHarness(launchDirectory, command.harness, options);
|
|
217
|
-
const [name, args] = splitInput(command.slash.slice(1));
|
|
218
|
-
const handler = loaded.actions.get(name);
|
|
219
|
-
if (!handler) throw new Error('Harness has no standalone /' + name + ' action.');
|
|
220
|
-
const launcher = new LauncherConfiguration(command.harness, command.harness, launchDirectory, command.cwd, command.configPath);
|
|
221
|
-
await launcher.refresh();
|
|
222
|
-
if (launcher.error && launcher.path) throw new Error(launcher.error);
|
|
223
|
-
controller.signal.throwIfAborted();
|
|
224
|
-
const result = await handler({ cwd: launcher.workspace, configuration: launcher.configuration,
|
|
225
|
-
signal: controller.signal, outputRoot: command.outputRoot && resolve(launchDirectory, command.outputRoot), args });
|
|
226
|
-
controller.signal.throwIfAborted();
|
|
227
|
-
const run = actionRun(result);
|
|
228
|
-
if (run) start = { run: { ...run, configuration: run.configuration ?? launcher.configuration }, loaded };
|
|
229
|
-
else if (result !== undefined) {
|
|
230
|
-
const report = actionReport(result);
|
|
231
|
-
const output = report ? report.result : result;
|
|
232
|
-
await new Promise<void>((done, reject) => {
|
|
233
|
-
stdout.call(process.stdout, JSON.stringify(output) + '\n', undefined, error => error ? reject(error) : done());
|
|
234
|
-
});
|
|
235
|
-
exitCode ||= report?.exitCode ?? 0;
|
|
236
|
-
}
|
|
237
|
-
if (!start) return exitCode;
|
|
238
|
-
} catch (error) {
|
|
239
|
-
if (!exitCode) console.error(error instanceof Error ? error.message : 'Harness action failed.');
|
|
240
|
-
return exitCode || 1;
|
|
241
|
-
} finally {
|
|
242
|
-
process.stdout.write = stdout;
|
|
243
|
-
process.off('SIGINT', cancel).off('SIGTERM', cancel);
|
|
244
|
-
}
|
|
245
|
-
return runProjectCommand({ ...command, defaults: true, command: 'harness', mode: 'headless',
|
|
246
|
-
cwd: start.run.cwd, prompt: start.run.prompt }, launchDirectory, { ...options, action: start });
|
|
247
|
-
}
|
|
@@ -6,7 +6,7 @@ import { tmpdir } from 'node:os';
|
|
|
6
6
|
import { verifyExportedSdk } from './anyswarm-eject.js';
|
|
7
7
|
import type { Harness } from '../src/harness/project-harness.js';
|
|
8
8
|
import { installSourceLoader } from '../src/harness/typescript-loader.js';
|
|
9
|
-
import {
|
|
9
|
+
import { parseSourceHarnessCommand } from './anyswarm-arguments.js';
|
|
10
10
|
|
|
11
11
|
const [, , entry, ...args] = process.argv;
|
|
12
12
|
if (!entry) throw new TypeError('A TypeScript or JavaScript entry file is required');
|
|
@@ -15,17 +15,12 @@ const entryUrl = pathToFileURL(filename).href;
|
|
|
15
15
|
process.argv = [process.execPath, filename, ...args];
|
|
16
16
|
installSourceLoader();
|
|
17
17
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const modernFlags = args.some(arg => /^--(?:headless|rpc|cmd)(?:=|$)/.test(arg));
|
|
21
|
-
const hasPrompt = args.some(arg => arg === '--prompt' || arg.startsWith('--prompt='));
|
|
22
|
-
const outputsRecords = !hasOption('--mode', 'tui') &&
|
|
23
|
-
(hasPrompt || hasOption('--mode', 'foreground') || hasOption('--mode', 'rpc'));
|
|
18
|
+
const hasPrompt = args.some(arg => /^--prompt(?:=|$)/.test(arg));
|
|
19
|
+
const hasMode = args.some(arg => /^--mode(?:=|$)/.test(arg));
|
|
24
20
|
|
|
25
21
|
type SourceModule = { default?: Harness };
|
|
26
22
|
const isHarness = (source: SourceModule): source is { default: Harness } =>
|
|
27
23
|
source.default?.apiVersion === 1 && typeof source.default.run === 'function';
|
|
28
|
-
const isInteractiveOnly = (harness: Harness) => harness.lifetimes?.includes('interactive') && !harness.lifetimes.includes('task');
|
|
29
24
|
|
|
30
25
|
async function importWithDiagnostics<T>(load: () => Promise<T>, useStderr = true): Promise<T> {
|
|
31
26
|
if (!useStderr) return load();
|
|
@@ -132,7 +127,7 @@ async function importImplicitSource(load: () => Promise<SourceModule>) {
|
|
|
132
127
|
let destination: NodeJS.WriteStream = process.stderr;
|
|
133
128
|
try {
|
|
134
129
|
const source = await load();
|
|
135
|
-
if (!isHarness(source)
|
|
130
|
+
if (!isHarness(source)) destination = process.stdout;
|
|
136
131
|
else if (interactiveOutput) {
|
|
137
132
|
throw new Error('Use an explicit --prompt for a task Harness that writes to stdout while reading stdin during import.');
|
|
138
133
|
}
|
|
@@ -167,35 +162,13 @@ try {
|
|
|
167
162
|
try { import.meta.resolve(sdk); } finally { checkingEntry = false; }
|
|
168
163
|
}
|
|
169
164
|
const load = (): Promise<SourceModule> => import(entryUrl);
|
|
170
|
-
const
|
|
171
|
-
const probeSourceOutput = modernFlags || (args.length === 0 && /\.(?:ts|mts)$/.test(filename)) ||
|
|
172
|
-
(!interactive && !outputsRecords && args.length > 0);
|
|
173
|
-
const source = await (probeSourceOutput ? importImplicitSource(load) : importWithDiagnostics(load, outputsRecords));
|
|
165
|
+
const source = await (hasPrompt || hasMode ? importWithDiagnostics(load) : importImplicitSource(load));
|
|
174
166
|
if (isHarness(source)) {
|
|
167
|
+
const command = parseSourceHarnessCommand(args, filename);
|
|
175
168
|
const diagnostics = { onSourceError(error: unknown) { console.error(error instanceof Error ? error.stack : String(error)); } };
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const code = await runHarnessSelection(parseHarnessSelection(args, filename), process.cwd(), diagnostics);
|
|
180
|
-
process.stdout.write('', () => process.exit(code));
|
|
181
|
-
} else {
|
|
182
|
-
const command = parseAnySwarmCommand(['--harness', filename,
|
|
183
|
-
...(args.length || isInteractiveOnly(source.default) ? args : ['--prompt', 'Run this Harness.'])]);
|
|
184
|
-
if ('help' in command) {
|
|
185
|
-
console.log(command.help);
|
|
186
|
-
} else if (command.command === 'tui') {
|
|
187
|
-
const { runAnySwarmTui } = await import('./anyswarm-tui.js');
|
|
188
|
-
process.exit(await runAnySwarmTui(command, process.cwd()));
|
|
189
|
-
} else if (command.command === 'harness') {
|
|
190
|
-
if (command.configPath) {
|
|
191
|
-
const configPath = resolve(command.configPath);
|
|
192
|
-
const { loadAnySwarmConfig } = await import('../src/core/sandbox/sandbox-connection.js');
|
|
193
|
-
await importWithDiagnostics(() => loadAnySwarmConfig(configPath));
|
|
194
|
-
}
|
|
195
|
-
const { runProjectCommand } = await import('./anyswarm-project.js');
|
|
196
|
-
process.exitCode = await runProjectCommand(command, process.cwd(), diagnostics);
|
|
197
|
-
} else throw new TypeError('Harness arguments must use TUI, foreground or RPC options');
|
|
198
|
-
}
|
|
169
|
+
const { runProjectCommand } = await import('./anyswarm-project.js');
|
|
170
|
+
const code = await runProjectCommand(command, process.cwd(), diagnostics);
|
|
171
|
+
process.stdout.write('', () => process.exit(code));
|
|
199
172
|
}
|
|
200
173
|
} catch (error) {
|
|
201
174
|
console.error(error instanceof Error ? error.stack : String(error));
|
package/scripts/anyswarm.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { readFile, realpath } from 'node:fs/promises';
|
|
|
4
4
|
import { resolve } from 'node:path';
|
|
5
5
|
import { pathToFileURL } from 'node:url';
|
|
6
6
|
import { parseAnySwarmCommand } from './anyswarm-arguments.js';
|
|
7
|
-
import { builtins } from './anyswarm-harnesses.js';
|
|
8
7
|
|
|
9
8
|
const args = process.argv.slice(2);
|
|
10
9
|
if (args.length === 1 && args[0] === '--version') {
|
|
@@ -29,32 +28,12 @@ if (args.length === 1 && args[0] === '--version') {
|
|
|
29
28
|
} else {
|
|
30
29
|
let command;
|
|
31
30
|
try {
|
|
32
|
-
command = parseAnySwarmCommand(args
|
|
31
|
+
command = parseAnySwarmCommand(args);
|
|
33
32
|
} catch (error) {
|
|
34
33
|
console.error((error as Error).message);
|
|
35
34
|
process.exitCode = 2;
|
|
36
35
|
}
|
|
37
36
|
if (command && 'help' in command) console.log(command.help);
|
|
38
|
-
if (command && 'command' in command && command.command === 'tui') {
|
|
39
|
-
let code = 2;
|
|
40
|
-
try {
|
|
41
|
-
const { runAnySwarmTui } = await import('./anyswarm-tui.js');
|
|
42
|
-
code = await runAnySwarmTui(command, process.cwd());
|
|
43
|
-
} catch {
|
|
44
|
-
console.error('Could not load the TUI. Reinstall @anyswarm/core or use explicit foreground or RPC mode.');
|
|
45
|
-
}
|
|
46
|
-
process.exit(code);
|
|
47
|
-
}
|
|
48
|
-
if (command && 'command' in command && command.command === 'use') {
|
|
49
|
-
try {
|
|
50
|
-
const { runHarnessSelection } = await import('./anyswarm-launch.js');
|
|
51
|
-
const code = await runHarnessSelection(command, process.cwd());
|
|
52
|
-
process.stdout.write('', () => process.exit(code));
|
|
53
|
-
} catch (error) {
|
|
54
|
-
console.error(error instanceof Error ? error.message : 'Could not launch the requested Harness.');
|
|
55
|
-
process.exitCode = 1;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
37
|
if (command && 'command' in command && command.command === 'run') {
|
|
59
38
|
try {
|
|
60
39
|
const { runSourceCommand } = await import('./anyswarm-author.js');
|
|
@@ -110,10 +89,11 @@ if (args.length === 1 && args[0] === '--version') {
|
|
|
110
89
|
process.on('SIGTERM', interrupt);
|
|
111
90
|
try {
|
|
112
91
|
const report = command.command === 'update'
|
|
113
|
-
? await (await import('./anyswarm-installation.js')).updateAnySwarm(
|
|
92
|
+
? await (await import('./anyswarm-installation.js')).updateAnySwarm(controller.signal)
|
|
114
93
|
: await (await import('./local-setup.js')).runLocalCommand(command, controller.signal,
|
|
115
94
|
command.command === 'setup' || process.stderr.isTTY ? message => console.error(message) : undefined);
|
|
116
|
-
console.log(
|
|
95
|
+
if (command.command === 'update' && process.stdout.isTTY) console.log((report as { detail: string }).detail);
|
|
96
|
+
else console.log(JSON.stringify(report, null, 2));
|
|
117
97
|
process.exitCode = signalCode ?? (report.ok ? 0 : 1);
|
|
118
98
|
} catch {
|
|
119
99
|
console.error(JSON.stringify({ ok: false, error: 'The requested AnySwarm command could not start. Rebuild or reinstall @anyswarm/core.' }));
|
|
@@ -15,7 +15,7 @@ const safe = (path: any) => typeof path === 'string' && path !== '' && !path.sta
|
|
|
15
15
|
// runtime inputs. They can contain dependency symlinks and must never affect
|
|
16
16
|
// the tracked source inventory.
|
|
17
17
|
const skipRoots = new Set(['.git', '.worktree', '.worktrees', '.claude', 'node_modules', 'dist', '.codex', 'docs', 'test', 'test-support', 'experiments', 'reports']);
|
|
18
|
-
const skipPaths = new Set(['third_party/agensh', 'website/.astro', 'website/dist', 'website/node_modules']);
|
|
18
|
+
const skipPaths = new Set(['third_party/agensh', 'website/.astro', 'website/.generated', 'website/dist', 'website/node_modules']);
|
|
19
19
|
async function walk(directory: any, prefix: any = ''): Promise<any> {
|
|
20
20
|
const files: any[] = [];
|
|
21
21
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
@@ -97,11 +97,12 @@ const outputs = new Map<string, string>();
|
|
|
97
97
|
function output(file: string, text: string) { outputs.set(`${outputDir}/${file}`, `${text.trimEnd()}\n`); }
|
|
98
98
|
|
|
99
99
|
const researchSource = 'examples/autoresearch/project.ts';
|
|
100
|
-
let researchDoc = header('AutoResearch peer instructions', 'All peers receive the same Profile instructions. Their first native input uses the peer label, trusted configuration goal and the Run input.
|
|
100
|
+
let researchDoc = header('AutoResearch peer instructions', 'All peers receive the same Profile instructions. Their first native input uses the peer label, trusted configuration goal and the Run input. Later native inputs choose a fixed nudge based on the shared train allowance. An immutable patch can trigger a review notice by active steer or appended to the next regular input. The demo objective is also the default Run input.');
|
|
101
101
|
researchDoc += block('Shared Profile instruction', evaluate('`' + between(researchSource, 'const instructions = `', '`;') + '`', { candidatePath: '.anyswarm-candidate.patch' }));
|
|
102
102
|
researchDoc += block('Initial peer input', evaluate('`' + between(researchSource, '? `', '`\n', 'const prompt = turn === 0') + '`',
|
|
103
103
|
{ label: '<PEER_LABEL>', config: { goal: '<RESEARCH_GOAL>' }, context: { input: { prompt: '<RUN_INPUT>' } } }));
|
|
104
|
-
researchDoc += block('Follow-up peer input', between(researchSource, ": '", "';",
|
|
104
|
+
researchDoc += block('Follow-up peer input while train is available', between(researchSource, ": '", "';", 'const remainingWork = trainExhausted'));
|
|
105
|
+
researchDoc += block('Follow-up peer input after the train budget is used', between(researchSource, "? '", "'\n", 'const remainingWork = trainExhausted'));
|
|
105
106
|
researchDoc += block('Candidate review notice', evaluate('`' + between(researchSource, 'return `', '`;', 'function reviewNotice') + '`',
|
|
106
107
|
{ candidate: '<CANDIDATE_ID>', sha256: '<CANDIDATE_SHA256>' }));
|
|
107
108
|
researchDoc += block('FrontierCS-2 demo objective', between('examples/autoresearch/config.ts', "export const demoGoal = '", "';"));
|
|
@@ -381,16 +382,26 @@ output('11-first-sdk-harness.md', '# First SDK Harness prompts\n\n'
|
|
|
381
382
|
].join('\n'), 'Startup discovery includes the purpose and the description for the operation granted to that Agent.'));
|
|
382
383
|
const parallelHost = 'examples/parallel-swarm/harness.ts';
|
|
383
384
|
const parallelService = 'examples/parallel-swarm/board-service.ts';
|
|
385
|
+
const parallelLiteral = (name: string) => evaluate(between(parallelHost, `const ${name} = `, ';\n'));
|
|
386
|
+
const researchFocuses = parallelLiteral('researchFocuses') as string[];
|
|
387
|
+
const researchTemplate = between(parallelHost, 'runInput(runtime, peer.id,\n `', '`,');
|
|
388
|
+
const synthesisTemplate = between(parallelHost, 'runInput(runtime, synth.id, `', '`,');
|
|
389
|
+
const parallelInput = { input: { prompt: '<ORIGINAL_USER_PROMPT>' } };
|
|
384
390
|
output('16-parallel-swarm.md', '# Parallel Swarm prompts\n\n'
|
|
385
|
-
+ block('Researcher Profile',
|
|
386
|
-
+ block('Synthesizer Profile',
|
|
387
|
-
+ block(
|
|
388
|
-
|
|
389
|
-
|
|
391
|
+
+ block('Researcher Profile', parallelLiteral('researcherPrompt'))
|
|
392
|
+
+ block('Synthesizer Profile', parallelLiteral('synthesizerPrompt'))
|
|
393
|
+
+ researchFocuses.map((_, index) => block(`First research round: researcher ${index + 1}`,
|
|
394
|
+
evaluate('`' + researchTemplate + '`', { context: parallelInput, researchFocuses, index }),
|
|
395
|
+
'The user question comes from context.input.prompt; the focus is selected by this researcher’s host-assigned index.')).join('\n')
|
|
396
|
+
+ block('Peer review round', parallelLiteral('reviewInput'),
|
|
397
|
+
'The host sends this to all three original researchers only after every first-round contribution passes.')
|
|
398
|
+
+ block('Synthesis round', evaluate('`' + synthesisTemplate + '`', {
|
|
399
|
+
synthesisInput: parallelLiteral('synthesisInput'), context: parallelInput,
|
|
400
|
+
}))
|
|
390
401
|
+ block('Board discovery', [
|
|
391
|
-
between(parallelService,
|
|
392
|
-
between(parallelService,
|
|
393
|
-
between(parallelService,
|
|
402
|
+
evaluate(between(parallelService, 'purpose: ', ',\n')),
|
|
403
|
+
evaluate(between(parallelService, 'description: ', ',\n', "operation: 'publish',")),
|
|
404
|
+
evaluate(between(parallelService, 'description: ', ',\n', "operation: 'search',")),
|
|
394
405
|
].join('\n'), 'Each Profile receives guidance for the admitted operations. The shared board stores the actual authenticated caller.'));
|
|
395
406
|
const durableBoardPath = 'examples/services/persistent-board/run.ts';
|
|
396
407
|
output('17-persistent-board.md', header('Persistent Board Service example prompts',
|
|
@@ -2,7 +2,7 @@ import { execFile, spawn } from 'node:child_process';
|
|
|
2
2
|
import { randomBytes, randomUUID } from 'node:crypto';
|
|
3
3
|
import { access, lstat, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { createConnection, isIP } from 'node:net';
|
|
5
|
-
import { homedir, platform } from 'node:os';
|
|
5
|
+
import { homedir, platform, release } from 'node:os';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
@@ -75,18 +75,35 @@ export function resolveSubagentsEnvironment(config: Partial<LocalEnvironmentConf
|
|
|
75
75
|
return resolveLocalEnvironment(config, 'SUBAGENTS');
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export function checkSetupHost(
|
|
78
|
+
export function checkSetupHost(): DiagnosticCheck[] {
|
|
79
79
|
const [major, minor] = process.versions.node.split('.').map(Number);
|
|
80
80
|
const os = platform();
|
|
81
81
|
return [
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
: check('host.platform', os === 'linux' || os === 'darwin', `Host operating system ${os}`, 'Run this command on Linux or macOS.'),
|
|
86
|
-
check('host.node', major > 22 || major === 22 && minor >= 19, `Node.js ${process.versions.node}`, 'Install Node.js 22.19 or newer.'),
|
|
82
|
+
check('host.platform', os === 'linux' || os === 'darwin',
|
|
83
|
+
`Host operating system ${os} ${release()} (${process.arch})`, 'Run this command on Linux or macOS.'),
|
|
84
|
+
check('host.node', major > 22 || major === 22 && minor >= 19, `Node.js ${process.versions.node} (${process.execPath})`, 'Install Node.js 22.19 or newer.'),
|
|
87
85
|
];
|
|
88
86
|
}
|
|
89
87
|
|
|
88
|
+
export async function checkHostTools(signal: AbortSignal) {
|
|
89
|
+
return Promise.all((['npm', 'git'] as const).map(async tool => {
|
|
90
|
+
const id = `host.${tool}`;
|
|
91
|
+
const remedy = tool === 'npm' ? 'Install Node.js with npm and use that installation on PATH.'
|
|
92
|
+
: 'Install Git before running a project Harness that captures local files.';
|
|
93
|
+
const options = { signal, timeout: 5_000 };
|
|
94
|
+
let path: string | undefined;
|
|
95
|
+
try {
|
|
96
|
+
path = (await execute('/bin/sh', ['-c', 'command -v "$1"', 'anyswarm', tool], options)).stdout.trim();
|
|
97
|
+
const version = (await execute(tool, ['--version'], options)).stdout.trim();
|
|
98
|
+
return check(id, true, `${tool === 'git' ? version : 'npm ' + version} (${path})`);
|
|
99
|
+
} catch {
|
|
100
|
+
signal.throwIfAborted();
|
|
101
|
+
const detail = path ? `Could not verify ${tool} at ${path}.` : `${tool} was not found on PATH.`;
|
|
102
|
+
return check(id, false, detail, remedy);
|
|
103
|
+
}
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
|
|
90
107
|
async function dockerInstallRemedy(): Promise<string> {
|
|
91
108
|
const release = await readFile('/etc/os-release', 'utf8').catch(() => '');
|
|
92
109
|
const id = /^ID="?([a-z0-9_-]+)/m.exec(release)?.[1];
|
|
@@ -107,31 +124,70 @@ async function dockerInstallRemedy(): Promise<string> {
|
|
|
107
124
|
export async function resolveLocalDocker() {
|
|
108
125
|
const socket = await localDockerSocket();
|
|
109
126
|
const info = JSON.parse(await run('docker', ['info', '--format', '{{json .}}']));
|
|
110
|
-
if (info.OSType !== 'linux')
|
|
127
|
+
if (info.OSType !== 'linux') {
|
|
128
|
+
throw Object.assign(new Error('Local setup needs a Linux Docker Engine.'), { code: 'DOCKER_OS' });
|
|
129
|
+
}
|
|
111
130
|
if (darwin && ![nativeArchitecture, ...(nativeArchitecture === 'arm64' ? ['aarch64'] : ['x86_64'])].includes(info.Architecture)) {
|
|
112
131
|
throw Object.assign(new Error('The Docker daemon does not match the native Mac architecture.'), { code: 'DOCKER_ARCHITECTURE' });
|
|
113
132
|
}
|
|
114
133
|
const bridge = darwin ? undefined : JSON.parse(await run('docker', ['network', 'inspect', 'bridge']).catch(() => '[]'))[0];
|
|
115
134
|
const advertiseHost: string | undefined = bridge?.IPAM?.Config?.find((entry: { Gateway?: string }) => isIP(entry.Gateway ?? '') === 4)?.Gateway;
|
|
116
|
-
return { socket, advertiseHost, rootless: info.SecurityOptions?.some((value: string) => value.includes('rootless')) === true
|
|
135
|
+
return { socket, advertiseHost, rootless: info.SecurityOptions?.some((value: string) => value.includes('rootless')) === true,
|
|
136
|
+
clientVersion: info.ClientInfo?.Version as string | undefined, context: info.ClientInfo?.Context as string | undefined,
|
|
137
|
+
engineVersion: info.ServerVersion as string | undefined };
|
|
117
138
|
}
|
|
118
139
|
|
|
119
140
|
export async function checkLocalDocker() {
|
|
120
141
|
try {
|
|
121
142
|
const docker = await resolveLocalDocker();
|
|
122
|
-
|
|
143
|
+
const version = /^(\d+)\.(\d+)\./.exec(docker.engineVersion ?? '');
|
|
144
|
+
if (!darwin && docker.rootless && version &&
|
|
145
|
+
(Number(version[1]) < 29 || (Number(version[1]) === 29 && Number(version[2]) < 5))) {
|
|
146
|
+
return { diagnostic: check('host.docker-engine', false,
|
|
147
|
+
`Rootless Docker Engine ${docker.engineVersion} cannot expose the local OpenSandbox host-network port to this host.`,
|
|
148
|
+
'Use Docker Engine 29.5 or newer, a rootful local Docker context, or an existing OpenSandbox endpoint.') };
|
|
149
|
+
}
|
|
150
|
+
const engine = [`Linux Docker Engine`, docker.engineVersion, `(${docker.rootless ? 'rootless' : 'rootful'})`].filter(Boolean).join(' ');
|
|
151
|
+
const client = docker.clientVersion ? `Docker CLI ${docker.clientVersion}` : '';
|
|
152
|
+
const context = docker.context ? `context ${docker.context}` : '';
|
|
153
|
+
return { docker, diagnostic: check('host.docker-engine', true, [engine, client, context].filter(Boolean).join(', ')) };
|
|
123
154
|
} catch (error) {
|
|
124
155
|
if ((error as NodeJS.ErrnoException).code === 'DOCKER_ARCHITECTURE') {
|
|
125
156
|
return { diagnostic: check('host.docker-engine', false, 'The Docker daemon does not match the native Mac architecture.',
|
|
126
157
|
'Select a native local Docker engine for this Mac and run docker info. AnySwarm does not fall back to emulation.') };
|
|
127
158
|
}
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
:
|
|
133
|
-
|
|
134
|
-
|
|
159
|
+
const { code, syscall, stderr = '' } = error as NodeJS.ErrnoException & { stderr?: string };
|
|
160
|
+
const missing = code === 'ENOENT' && syscall === 'spawn docker';
|
|
161
|
+
const contextRemedy = 'Run docker context show and docker info. If needed, run docker context ls and docker context use <local-context>. Check DOCKER_CONTEXT and DOCKER_HOST overrides.';
|
|
162
|
+
if (code === 'LOCAL_WORKER_UNAVAILABLE') {
|
|
163
|
+
return { diagnostic: check('host.docker-engine', false, 'The selected Docker context does not use a local Unix socket.', contextRemedy) };
|
|
164
|
+
}
|
|
165
|
+
if (code === 'DOCKER_OS') {
|
|
166
|
+
return { diagnostic: check('host.docker-engine', false, 'The selected Docker daemon is not a Linux engine.', contextRemedy) };
|
|
167
|
+
}
|
|
168
|
+
if (code === 'EACCES' || code === 'EPERM' || /permission denied.*(?:socket|docker daemon)|(?:socket|docker daemon).*permission denied/i.test(stderr)) {
|
|
169
|
+
return { diagnostic: check('host.docker-engine', false, 'Permission denied while accessing the local Docker engine.',
|
|
170
|
+
'Ask the host administrator to grant socket access. Sign in again after any group change and run docker info as your login user.') };
|
|
171
|
+
}
|
|
172
|
+
let desktopRemedy = 'Install Docker Desktop for Mac (https://docs.docker.com/desktop/setup/install/mac-install/), open it, and wait for the engine to start.';
|
|
173
|
+
if (darwin) {
|
|
174
|
+
const app = 'Docker.app/Contents/Info.plist';
|
|
175
|
+
const installed = await Promise.all(['/Applications', join(homedir(), 'Applications')]
|
|
176
|
+
.map(directory => access(join(directory, app)).then(() => true, () => false)));
|
|
177
|
+
if (installed.some(Boolean)) {
|
|
178
|
+
desktopRemedy = 'Docker Desktop is installed. Open Docker Desktop or wait for its engine to finish starting, then check that its CLI is on PATH.';
|
|
179
|
+
}
|
|
180
|
+
desktopRemedy += ' If you already use another local Linux engine such as OrbStack, start that instead.';
|
|
181
|
+
}
|
|
182
|
+
if (missing) {
|
|
183
|
+
return { diagnostic: check('host.docker-engine', false, 'The Docker CLI was not found on PATH.',
|
|
184
|
+
darwin ? desktopRemedy + ' ' + contextRemedy : await dockerInstallRemedy()) };
|
|
185
|
+
}
|
|
186
|
+
const unavailable = code === 'ENOENT' || /cannot connect|connection refused|daemon running/i.test(stderr);
|
|
187
|
+
const detail = unavailable ? 'The Docker CLI is installed, but the local daemon or its Unix socket is unavailable.'
|
|
188
|
+
: 'Could not verify the selected local Docker engine.';
|
|
189
|
+
return { diagnostic: check('host.docker-engine', false, detail,
|
|
190
|
+
(darwin ? desktopRemedy : 'Start the local Docker engine, then verify access as your login user.') + ' ' + contextRemedy) };
|
|
135
191
|
}
|
|
136
192
|
}
|
|
137
193
|
|
|
@@ -244,14 +300,16 @@ async function authenticatedHealth(config: LocalEnvironmentConfig, budget?: Abor
|
|
|
244
300
|
}
|
|
245
301
|
}
|
|
246
302
|
|
|
247
|
-
export async function checkLocalProvider(config: LocalEnvironmentConfig, { requireAuth = true } = {}): Promise<DiagnosticCheck[]> {
|
|
303
|
+
export async function checkLocalProvider(config: LocalEnvironmentConfig, { requireAuth = true, managed = false } = {}): Promise<DiagnosticCheck[]> {
|
|
248
304
|
const [healthy, denied] = await Promise.all([providerHealthy(config, true), requireAuth ? providerHealthy(config, false) : true]);
|
|
249
305
|
return [
|
|
250
306
|
check('provider.health', healthy, healthy ? 'OpenSandbox lifecycle listing is reachable with the configured credentials.' : 'OpenSandbox lifecycle listing failed.',
|
|
251
|
-
|
|
307
|
+
managed ? 'Run anyswarm setup to start or restore the managed OpenSandbox service.'
|
|
308
|
+
: 'Check ANYSWARM_LIFECYCLE_URL (or sandbox.lifecycleBaseUrl in --config), TLS trust, and the lifecycle API key. Rerun the same command.'),
|
|
252
309
|
...(requireAuth ? [check('provider.authentication', denied && !!config.apiKey,
|
|
253
310
|
denied && config.apiKey ? 'Lifecycle rejects requests without the configured API key.' : 'Lifecycle authentication could not be confirmed.',
|
|
254
|
-
|
|
311
|
+
managed ? 'Run anyswarm setup to check the managed service and its local credentials.'
|
|
312
|
+
: 'Configure a lifecycle API key on OpenSandbox and pass it through trusted anyswarm configuration.')] : []),
|
|
255
313
|
];
|
|
256
314
|
}
|
|
257
315
|
|
|
@@ -339,7 +397,7 @@ async function ensureLocalProviderLocked(config: LocalEnvironmentConfig, { signa
|
|
|
339
397
|
if (existing) throw Object.assign(new Error('The key for the managed provider is missing'), { code: 'PROVIDER_AUTHENTICATION' });
|
|
340
398
|
try { await writeFile(filename, randomBytes(32).toString('hex'), { mode: 0o600, flag: 'wx' }); }
|
|
341
399
|
catch (error) { if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error; }
|
|
342
|
-
config = { ...config, apiKey: resolveSandboxConnection({ lifecycleBaseUrl: config.lifecycleBaseUrl }).apiKey };
|
|
400
|
+
config = { ...config, apiKey: resolveSandboxConnection({ lifecycleBaseUrl: config.lifecycleBaseUrl }, undefined, { discoverHost: false }).apiKey };
|
|
343
401
|
}
|
|
344
402
|
if (!config.apiKey) throw new Error('Could not load the owner-only OpenSandbox lifecycle key.');
|
|
345
403
|
if (existing) {
|