@anyswarm/core 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +20 -5
- package/README.md +69 -55
- package/dist/examples/README.md +138 -77
- package/dist/examples/authoring/README.md +4 -4
- package/dist/examples/autoresearch/README.md +108 -16
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
- package/dist/examples/autoresearch/config.d.ts +48 -5
- package/dist/examples/autoresearch/config.js +57 -23
- package/dist/examples/autoresearch/demo.d.ts +12 -4
- package/dist/examples/autoresearch/demo.js +65 -22
- package/dist/examples/autoresearch/eject.json +2 -0
- package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
- package/dist/examples/autoresearch/frontiercs2-config.js +14 -0
- package/dist/examples/autoresearch/frontiercs2.d.ts +18 -1
- package/dist/examples/autoresearch/frontiercs2.js +71 -14
- package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
- package/dist/examples/autoresearch/prepare-demo.js +46 -0
- package/dist/examples/autoresearch/prepare.d.ts +105 -53
- package/dist/examples/autoresearch/prepare.js +126 -57
- package/dist/examples/autoresearch/project.d.ts +6 -95
- package/dist/examples/autoresearch/project.js +131 -45
- package/dist/examples/autoresearch/research-service.d.ts +16 -1
- package/dist/examples/autoresearch/research-service.js +84 -44
- package/dist/examples/code/README.md +25 -17
- package/dist/examples/code/REQUIREMENTS.zh.md +3 -3
- package/dist/examples/code/config.d.ts +1 -0
- package/dist/examples/first-harness/AGENTS.md +25 -0
- package/dist/examples/first-harness/README.md +136 -0
- package/dist/examples/first-harness/config.d.ts +9 -8
- package/dist/examples/first-harness/config.js +33 -26
- package/dist/examples/first-harness/eject.json +14 -0
- package/dist/examples/first-harness/handoff.js +3 -3
- package/dist/examples/first-harness/harness.d.ts +14 -18
- package/dist/examples/first-harness/harness.js +102 -77
- package/dist/examples/first-harness/input/README.md +7 -0
- package/dist/examples/first-harness/session.js +2 -1
- package/dist/examples/first-harness/tsconfig.json +2 -1
- package/dist/examples/harness-session/README.md +4 -4
- package/dist/examples/lead-worker/README.md +1 -1
- package/dist/examples/lead-worker/project-config.d.ts +1 -0
- package/dist/examples/messages/README.md +2 -2
- package/dist/examples/notes/README.md +5 -5
- package/dist/examples/notes/config.d.ts +1 -0
- package/dist/examples/parallel-swarm/AGENTS.md +32 -0
- package/dist/examples/parallel-swarm/README.md +136 -0
- package/dist/examples/parallel-swarm/board-service.js +25 -8
- package/dist/examples/parallel-swarm/board.d.ts +31 -1
- package/dist/examples/parallel-swarm/board.js +98 -13
- package/dist/examples/parallel-swarm/config.d.ts +11 -0
- package/dist/examples/parallel-swarm/config.js +39 -0
- package/dist/examples/parallel-swarm/eject.json +5 -0
- package/dist/examples/parallel-swarm/harness.d.ts +26 -20
- package/dist/examples/parallel-swarm/harness.js +77 -76
- package/dist/examples/parallel-swarm/report.d.ts +12 -0
- package/dist/examples/parallel-swarm/report.js +30 -0
- package/dist/examples/peermesh/README.md +1 -1
- package/dist/examples/peermesh/project-config.d.ts +1 -0
- package/dist/examples/services/agent-control/README.md +1 -1
- package/dist/examples/services/mathlib-search/README.md +1 -1
- package/dist/examples/services/mcp-managed/README.md +1 -1
- package/dist/examples/services/persistent-board/README.md +6 -3
- package/dist/examples/subagents/AGENTS.md +35 -0
- package/dist/examples/subagents/README.md +129 -93
- package/dist/examples/subagents/config.d.ts +2 -10
- package/dist/examples/subagents/config.js +9 -16
- package/dist/examples/subagents/eject.json +17 -0
- package/dist/examples/subagents/handoff-config.d.ts +41 -0
- package/dist/examples/subagents/handoff-config.js +13 -0
- package/dist/examples/subagents/model.d.ts +3 -0
- package/dist/examples/subagents/model.js +19 -0
- package/dist/examples/substrate/README.md +12 -6
- package/dist/examples/substrate/config.d.ts +1 -0
- package/dist/examples/substrate/project-config.d.ts +1 -0
- package/dist/examples/super/README.md +34 -22
- package/dist/examples/super/actions.d.ts +1 -1
- package/dist/examples/super/actions.js +11 -11
- package/dist/examples/super/config.js +3 -3
- package/dist/examples/super/eject.json +1 -1
- package/dist/examples/super/location.js +1 -1
- package/dist/examples/super/operator.d.ts +1 -0
- package/dist/examples/super/operator.js +31 -0
- package/dist/examples/super/project.d.ts +0 -107
- package/dist/examples/super/project.js +1 -3
- package/dist/examples/taskpool/README.md +1 -1
- package/dist/examples/taskpool/config.d.ts +1 -0
- package/dist/examples/taskpool/deploy/service-hosts/service-authority-snapshot.d.ts +4 -4
- package/dist/scripts/anyswarm-arguments.d.ts +7 -25
- package/dist/scripts/anyswarm-arguments.js +69 -97
- package/dist/scripts/anyswarm-eject.js +1 -1
- package/dist/scripts/anyswarm-harnesses.d.ts +0 -1
- package/dist/scripts/anyswarm-harnesses.js +1 -22
- package/dist/scripts/anyswarm-installation.d.ts +7 -40
- package/dist/scripts/anyswarm-installation.js +17 -291
- package/dist/scripts/anyswarm-launch.d.ts +6 -36
- package/dist/scripts/anyswarm-launch.js +32 -81
- package/dist/scripts/anyswarm-progress.d.ts +6 -0
- package/dist/scripts/anyswarm-progress.js +133 -0
- package/dist/scripts/anyswarm-project.d.ts +1 -9
- package/dist/scripts/anyswarm-project.js +40 -127
- package/dist/scripts/anyswarm-source-runner.js +9 -41
- package/dist/scripts/anyswarm.js +6 -26
- package/dist/scripts/build-provenance.json +1 -1
- package/dist/scripts/generate-architecture-coverage.js +1 -1
- package/dist/scripts/generate-architecture-prompts.js +18 -10
- package/dist/scripts/local-environment.d.ts +13 -7
- package/dist/scripts/local-environment.js +73 -21
- package/dist/scripts/local-setup.d.ts +3 -0
- package/dist/scripts/local-setup.js +153 -118
- package/dist/scripts/pack-release.js +31 -4
- package/dist/src/core/index.js +1 -1
- package/dist/src/core/sandbox/opensandbox-backend.js +10 -4
- package/dist/src/core/sandbox/sandbox-connection.d.ts +9 -2
- package/dist/src/core/sandbox/sandbox-connection.js +22 -7
- package/dist/src/core/worker-image.js +1 -1
- package/dist/src/harness/project-harness.d.ts +1 -0
- package/dist/src/harness/project-harness.js +5 -4
- package/dist/src/harness/project-rpc-client.js +19 -0
- package/dist/src/harness/project-runtime.js +3 -1
- package/dist/src/harness/typescript-loader.d.ts +2 -0
- package/dist/src/harness/typescript-loader.js +26 -8
- package/dist/src/trace-viewer/command.mjs +6 -3
- package/dist/src/trace-viewer/public/app.js +239 -59
- package/dist/src/trace-viewer/public/index.html +5 -0
- package/dist/src/trace-viewer/public/style.css +22 -0
- package/dist/src/trace-viewer/reader.mjs +242 -26
- package/dist/src/trace-viewer/run-root.d.mts +1 -0
- package/dist/src/trace-viewer/run-root.mjs +7 -0
- package/dist/src/trace-viewer/server.mjs +3 -1
- package/docs/INDEX.md +11 -9
- package/docs/architecture/04-services.md +1 -1
- package/docs/architecture/06-observability-experiments.md +21 -7
- package/docs/architecture/07-run-configuration.md +118 -19
- package/docs/architecture/08-prompts.md +21 -2
- package/docs/architecture/10-service-api-reference.md +12 -5
- package/docs/architecture/12-code-coverage.md +157 -115
- package/docs/architecture/15-core-runtime.md +1 -1
- package/docs/architecture/16-pi-opensandbox-backend.md +2 -0
- package/docs/architecture/17-harness-reporting.md +79 -1
- package/docs/architecture/22-website.md +52 -20
- package/docs/architecture/23-project-harness.md +109 -37
- package/docs/architecture/26-code.md +20 -5
- package/docs/architecture/27-personal.md +23 -8
- package/docs/architecture/28-autoresearch.md +18 -12
- package/docs/architecture/INDEX.md +1 -2
- package/docs/architecture/prompts/11-first-sdk-harness.md +9 -9
- package/docs/architecture/prompts/16-parallel-swarm.md +46 -13
- package/docs/architecture/prompts/22-autoresearch.md +9 -2
- package/docs/architecture/prompts/source-manifest.json +76 -52
- package/docs/architecture/source-map.json +445 -105
- package/docs/designs/core-harness/01-core.md +2 -2
- package/docs/designs/core-harness/06-project-harness.md +3 -3
- package/docs/designs/core-harness/README.md +2 -2
- package/docs/en/agents.md +1 -1
- package/docs/en/autoresearch.md +41 -0
- package/docs/en/blog/100b-tokens.md +157 -0
- package/docs/en/build-your-harness.md +47 -22
- package/docs/en/changelog.md +29 -1
- package/docs/en/first-harness.md +40 -32
- package/docs/en/harnesses/index.md +23 -23
- package/docs/en/harnesses/lead-worker.md +1 -1
- package/docs/en/harnesses/peermesh.md +2 -2
- package/docs/en/harnesses/subagents.md +10 -31
- package/docs/en/harnesses/substrate.md +4 -4
- package/docs/en/harnesses/taskpool.md +2 -2
- package/docs/en/latest.md +30 -5
- package/docs/en/overview.md +22 -22
- package/docs/en/quickstart.md +69 -56
- package/docs/en/reference/api.md +1 -1
- package/docs/en/reference/cli.md +47 -85
- package/docs/en/sandbox.md +3 -3
- package/docs/en/trace-viewer.md +32 -12
- package/docs/operations/trace-viewer.md +26 -11
- package/docs/third-party-notices.md +0 -1
- package/docs/workflows/development.md +160 -118
- package/docs/workflows/release-and-docs-versioning.md +207 -54
- package/docs/workflows/release-cli-acceptance.md +162 -0
- package/docs/zh/agents.md +1 -1
- package/docs/zh/autoresearch.md +41 -0
- package/docs/zh/blog/100b-tokens.md +102 -0
- package/docs/zh/build-your-harness.md +48 -23
- package/docs/zh/changelog.md +29 -1
- package/docs/zh/first-harness.md +43 -35
- package/docs/zh/harnesses/index.md +23 -23
- package/docs/zh/harnesses/lead-worker.md +1 -1
- package/docs/zh/harnesses/peermesh.md +2 -2
- package/docs/zh/harnesses/subagents.md +10 -31
- package/docs/zh/harnesses/substrate.md +4 -4
- package/docs/zh/harnesses/taskpool.md +2 -2
- package/docs/zh/latest.md +30 -5
- package/docs/zh/overview.md +23 -23
- package/docs/zh/quickstart.md +66 -57
- package/docs/zh/reference/api.md +1 -1
- package/docs/zh/reference/cli.md +19 -79
- package/docs/zh/sandbox.md +3 -3
- package/docs/zh/trace-viewer.md +32 -12
- package/examples/README.md +138 -77
- package/examples/authoring/README.md +4 -4
- package/examples/autoresearch/README.md +108 -16
- package/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
- package/examples/autoresearch/config.ts +64 -25
- package/examples/autoresearch/demo.ts +75 -22
- package/examples/autoresearch/eject.json +2 -0
- package/examples/autoresearch/frontiercs2-config.ts +15 -0
- package/examples/autoresearch/frontiercs2.ts +64 -11
- package/examples/autoresearch/prepare-demo.ts +44 -0
- package/examples/autoresearch/prepare.ts +134 -60
- package/examples/autoresearch/project.ts +120 -44
- package/examples/autoresearch/research-service.ts +91 -41
- package/examples/code/README.md +25 -17
- package/examples/code/REQUIREMENTS.zh.md +3 -3
- package/examples/first-harness/AGENTS.md +25 -0
- package/examples/first-harness/README.md +136 -0
- package/examples/first-harness/config.ts +41 -27
- package/examples/first-harness/eject.json +14 -0
- package/examples/first-harness/handoff.ts +3 -3
- package/examples/first-harness/harness.ts +104 -72
- package/examples/first-harness/input/README.md +7 -0
- package/examples/first-harness/session.ts +2 -1
- package/examples/first-harness/tsconfig.json +2 -1
- package/examples/harness-session/README.md +4 -4
- package/examples/lead-worker/README.md +1 -1
- package/examples/messages/README.md +2 -2
- package/examples/notes/README.md +5 -5
- package/examples/parallel-swarm/AGENTS.md +32 -0
- package/examples/parallel-swarm/README.md +136 -0
- package/examples/parallel-swarm/board-service.ts +28 -9
- package/examples/parallel-swarm/board.ts +107 -13
- package/examples/parallel-swarm/config.ts +47 -0
- package/examples/parallel-swarm/eject.json +5 -0
- package/examples/parallel-swarm/harness.ts +83 -71
- package/examples/parallel-swarm/report.ts +33 -0
- package/examples/peermesh/README.md +1 -1
- package/examples/services/agent-control/README.md +1 -1
- package/examples/services/mathlib-search/README.md +1 -1
- package/examples/services/mcp-managed/README.md +1 -1
- package/examples/services/persistent-board/README.md +6 -3
- package/examples/subagents/AGENTS.md +35 -0
- package/examples/subagents/README.md +129 -93
- package/examples/subagents/config.ts +9 -15
- package/examples/subagents/eject.json +17 -0
- package/examples/subagents/handoff-config.ts +14 -0
- package/examples/subagents/model.ts +20 -0
- package/examples/substrate/README.md +12 -6
- package/examples/super/README.md +34 -22
- package/examples/super/actions.ts +11 -11
- package/examples/super/config.ts +3 -3
- package/examples/super/eject.json +1 -1
- package/examples/super/location.ts +1 -1
- package/examples/super/operator.ts +28 -0
- package/examples/super/project.ts +1 -3
- package/examples/taskpool/README.md +1 -1
- package/npm-shrinkwrap.development.json +46 -1538
- package/npm-shrinkwrap.json +10 -43
- package/package.development.json +3 -6
- package/package.json +3 -5
- package/scripts/anyswarm-arguments.ts +67 -96
- package/scripts/anyswarm-eject.ts +1 -1
- package/scripts/anyswarm-harnesses.ts +1 -18
- package/scripts/anyswarm-installation.ts +18 -294
- package/scripts/anyswarm-launch.ts +30 -102
- package/scripts/anyswarm-progress.ts +125 -0
- package/scripts/anyswarm-project.ts +31 -123
- package/scripts/anyswarm-source-runner.ts +9 -36
- package/scripts/anyswarm.ts +4 -24
- package/scripts/generate-architecture-coverage.ts +1 -1
- package/scripts/generate-architecture-prompts.ts +21 -10
- package/scripts/local-environment.ts +79 -21
- package/scripts/local-setup.ts +150 -105
- package/scripts/pack-release.ts +28 -4
- package/src/core/index.ts +1 -1
- package/src/core/sandbox/opensandbox-backend.ts +10 -4
- package/src/core/sandbox/sandbox-connection.ts +22 -7
- package/src/core/worker-image.ts +1 -1
- package/src/harness/project-harness.ts +5 -4
- package/src/harness/project-rpc-client.ts +23 -0
- package/src/harness/project-runtime.ts +2 -1
- package/src/harness/typescript-loader.ts +28 -8
- package/src/trace-viewer/command.mjs +6 -3
- package/src/trace-viewer/public/app.js +239 -59
- package/src/trace-viewer/public/index.html +5 -0
- package/src/trace-viewer/public/style.css +22 -0
- package/src/trace-viewer/reader.mjs +242 -26
- package/src/trace-viewer/run-root.d.mts +1 -0
- package/src/trace-viewer/run-root.mjs +7 -0
- package/src/trace-viewer/server.mjs +3 -1
- package/dist/scripts/anyswarm-applications.d.ts +0 -19
- package/dist/scripts/anyswarm-applications.js +0 -19
- package/dist/scripts/anyswarm-tui-config.d.ts +0 -36
- package/dist/scripts/anyswarm-tui-config.js +0 -189
- package/dist/scripts/anyswarm-tui-session.d.ts +0 -66
- package/dist/scripts/anyswarm-tui-session.js +0 -304
- package/dist/scripts/anyswarm-tui-terminal.d.ts +0 -41
- package/dist/scripts/anyswarm-tui-terminal.js +0 -154
- package/dist/scripts/anyswarm-tui.d.ts +0 -2
- package/dist/scripts/anyswarm-tui.js +0 -1012
- package/docs/architecture/25-foreground-tui.md +0 -51
- package/scripts/anyswarm-applications.ts +0 -39
- package/scripts/anyswarm-tui-config.ts +0 -174
- package/scripts/anyswarm-tui-session.ts +0 -295
- package/scripts/anyswarm-tui-terminal.ts +0 -147
- package/scripts/anyswarm-tui.ts +0 -912
|
@@ -4,7 +4,8 @@ import { loadAnySwarmConfig } from '../core/sandbox/sandbox-connection.js';
|
|
|
4
4
|
import { createHash, randomUUID } from 'node:crypto';
|
|
5
5
|
import { mkdir, mkdtemp, realpath, rm, writeFile } from 'node:fs/promises';
|
|
6
6
|
import { registerHooks } from 'node:module';
|
|
7
|
-
import {
|
|
7
|
+
import { tmpdir } from 'node:os';
|
|
8
|
+
import { defaultRunRoot } from '../trace-viewer/run-root.mjs';
|
|
8
9
|
import { extname, isAbsolute, join, resolve } from 'node:path';
|
|
9
10
|
import { pathToFileURL } from 'node:url';
|
|
10
11
|
import { captureProject, isInside, projectError, ProjectPreflightError, resolveProjectDirectory } from './project-input.js';
|
|
@@ -165,7 +166,7 @@ export function failureCode(error: unknown, fallback: string) {
|
|
|
165
166
|
(errorDiagnostic(error) && /^[a-z][a-z0-9_]{0,79}$/.test(code))) ? code : fallback;
|
|
166
167
|
}
|
|
167
168
|
|
|
168
|
-
async function
|
|
169
|
+
export async function loadProjectConfiguration(directory: string, path: string | undefined): Promise<unknown> {
|
|
169
170
|
if (!path) return undefined;
|
|
170
171
|
let value: unknown;
|
|
171
172
|
try {
|
|
@@ -196,7 +197,7 @@ async function prepareOutput(runId: string, options: StartupOptions, cwd: string
|
|
|
196
197
|
await mkdir(path, { recursive: true, mode: 0o700 });
|
|
197
198
|
return await realpath(path);
|
|
198
199
|
}
|
|
199
|
-
const stateDirectory =
|
|
200
|
+
const stateDirectory = defaultRunRoot();
|
|
200
201
|
if (!isInside(cwd, stateDirectory)) {
|
|
201
202
|
const stateRoot = await mkdir(stateDirectory, { recursive: true, mode: 0o700 })
|
|
202
203
|
.then(() => realpath(stateDirectory)).catch(() => null);
|
|
@@ -290,7 +291,7 @@ export function createProjectHost(definition: ProjectHarness, options: StartupOp
|
|
|
290
291
|
await writeFile(path, raw.prompt, { flag: 'wx', mode: 0o600 });
|
|
291
292
|
promptPath = path;
|
|
292
293
|
signal.throwIfAborted();
|
|
293
|
-
const configuration = options.configuration !== undefined ? validateConfiguration(options.configuration) : await
|
|
294
|
+
const configuration = options.configuration !== undefined ? validateConfiguration(options.configuration) : await loadProjectConfiguration(options.launchDirectory, options.configPath);
|
|
294
295
|
signal.throwIfAborted();
|
|
295
296
|
let filePolicy;
|
|
296
297
|
try { filePolicy = resolveFilePolicy((configuration as { filePolicy?: FilePolicy } | undefined)?.filePolicy); }
|
|
@@ -45,6 +45,23 @@ type Pending = {
|
|
|
45
45
|
release(): void;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
+
// These launch errors contain public Host explanations, not author exceptions.
|
|
49
|
+
const startupMessageCodes = new Set(['HARNESS_MODULE_LOAD_FAILED', 'INVALID_HARNESS_MODULE',
|
|
50
|
+
'INVALID_HARNESS_SESSION', 'INVALID_RUN_CONFIGURATION', 'INVALID_REQUEST']);
|
|
51
|
+
|
|
52
|
+
function startupError(record: any) {
|
|
53
|
+
if (typeof record.code !== 'string' || !/^[A-Za-z0-9_.:-]{1,128}$/.test(record.code)) {
|
|
54
|
+
throw new Error('Invalid RPC startup error');
|
|
55
|
+
}
|
|
56
|
+
const message = startupMessageCodes.has(record.code) && typeof record.message === 'string'
|
|
57
|
+
? record.message.slice(0, 4096).replace(/[\p{Cc}\p{Cf}]/gu, (character: string) =>
|
|
58
|
+
'\\u' + character.charCodeAt(0).toString(16).padStart(4, '0'))
|
|
59
|
+
: 'Harness RPC startup failed';
|
|
60
|
+
const diagnostic = parseErrorDiagnostic(record.diagnostic);
|
|
61
|
+
return Object.assign(projectError(record.code, message),
|
|
62
|
+
diagnostic ? frameworkErrorFields({ ...record, diagnostic }) : {});
|
|
63
|
+
}
|
|
64
|
+
|
|
48
65
|
export class HarnessRpcClient implements HarnessSession {
|
|
49
66
|
readonly ready: Promise<HarnessRpcReady>;
|
|
50
67
|
readonly agents: HarnessSession['agents'];
|
|
@@ -57,6 +74,7 @@ export class HarnessRpcClient implements HarnessSession {
|
|
|
57
74
|
readonly #timeout: number;
|
|
58
75
|
readonly #prefix = randomUUID();
|
|
59
76
|
#next = 0;
|
|
77
|
+
#readyConfirmed = false;
|
|
60
78
|
#started = false;
|
|
61
79
|
#failure?: Error;
|
|
62
80
|
#resultConfirmed = false;
|
|
@@ -187,11 +205,16 @@ export class HarnessRpcClient implements HarnessSession {
|
|
|
187
205
|
switch (record.type) {
|
|
188
206
|
case 'ready':
|
|
189
207
|
if (record.version !== 'v1' || !record.harness || !record.status || !record.descriptor) throw new Error('Invalid RPC handshake');
|
|
208
|
+
this.#readyConfirmed = true;
|
|
190
209
|
this.#started ||= typeof record.status.runId === 'string';
|
|
191
210
|
this.#ready.resolve(record);
|
|
192
211
|
break;
|
|
193
212
|
case 'reply':
|
|
194
213
|
case 'error': {
|
|
214
|
+
if (record.type === 'error' && record.id === undefined && !this.#readyConfirmed) {
|
|
215
|
+
this.#disconnect(startupError(record));
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
195
218
|
const pending = this.#pending.get(record.id);
|
|
196
219
|
if (!pending) break;
|
|
197
220
|
this.#pending.delete(record.id);
|
|
@@ -63,7 +63,8 @@ export async function projectConfiguration<C>(context: ProjectHarnessContext, de
|
|
|
63
63
|
if (!value || typeof value !== 'object' || !('sandbox' in value) || !('models' in value) || !('image' in value)) {
|
|
64
64
|
throw new Error('Missing sandbox, models or image');
|
|
65
65
|
}
|
|
66
|
-
} catch {
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error instanceof ProjectPreflightError) throw error;
|
|
67
68
|
throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Configure sandbox, models and image for this Harness');
|
|
68
69
|
}
|
|
69
70
|
context.signal.throwIfAborted();
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import {
|
|
2
|
+
import { createRequire, registerHooks } from 'node:module';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
|
|
5
7
|
let installed = false;
|
|
6
8
|
|
|
7
9
|
/** Enable trusted author TypeScript without changing the author's package scope. */
|
|
8
10
|
export function installSourceLoader() {
|
|
9
11
|
if (installed) return;
|
|
10
12
|
installed = true;
|
|
11
|
-
// Node 22.19+ supports transformation and inline maps, including enums.
|
|
12
|
-
const transform = stripTypeScriptTypes as unknown as (source: string, options: { mode: 'transform'; sourceMap: true; sourceUrl: string }) => string;
|
|
13
13
|
const sdk = new URL('../core/index.js', import.meta.url).href;
|
|
14
14
|
registerHooks({
|
|
15
15
|
resolve(specifier, context, nextResolve) {
|
|
@@ -19,8 +19,11 @@ export function installSourceLoader() {
|
|
|
19
19
|
if ((error as NodeJS.ErrnoException).code !== 'ERR_MODULE_NOT_FOUND' &&
|
|
20
20
|
(error as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') throw error;
|
|
21
21
|
if (specifier === '@anyswarm/core') return { url: sdk, shortCircuit: true };
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const source = specifier.startsWith('file:') ? new URL(specifier)
|
|
23
|
+
: context.parentURL?.startsWith('file:') && /^(?:\.{1,2}\/|\/)/.test(specifier)
|
|
24
|
+
? new URL(specifier, context.parentURL) : undefined;
|
|
25
|
+
if (source && /\.m?js$/.test(source.pathname)) {
|
|
26
|
+
source.pathname = source.pathname.replace(/\.m?js$/, match => match === '.mjs' ? '.mts' : '.ts');
|
|
24
27
|
if (existsSync(source)) return { url: source.href, shortCircuit: true };
|
|
25
28
|
}
|
|
26
29
|
throw error;
|
|
@@ -28,10 +31,27 @@ export function installSourceLoader() {
|
|
|
28
31
|
},
|
|
29
32
|
load(url, context, nextLoad) {
|
|
30
33
|
if (!url.startsWith('file:') || !/\.(?:ts|mts)$/.test(new URL(url).pathname)) return nextLoad(url, context);
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
});
|
|
34
|
+
const filename = fileURLToPath(url);
|
|
35
|
+
const source = transformAuthorSource(readFileSync(filename, 'utf8'), filename);
|
|
34
36
|
return { format: 'module', source, shortCircuit: true };
|
|
35
37
|
},
|
|
36
38
|
});
|
|
37
39
|
}
|
|
40
|
+
|
|
41
|
+
/** Compile author source without lowering the JavaScript syntax supported by the running Node. */
|
|
42
|
+
export function transformAuthorSource(source: string, filename: string): string {
|
|
43
|
+
const { transformSync }: typeof import('@swc/wasm') = require('@swc/wasm');
|
|
44
|
+
// The WASM transformer accepts these options even though its declarations lag the runtime.
|
|
45
|
+
const options = {
|
|
46
|
+
filename,
|
|
47
|
+
isModule: true,
|
|
48
|
+
sourceMaps: 'inline',
|
|
49
|
+
jsc: {
|
|
50
|
+
target: 'esnext',
|
|
51
|
+
parser: { syntax: 'typescript' },
|
|
52
|
+
transform: { verbatimModuleSyntax: true },
|
|
53
|
+
},
|
|
54
|
+
module: { type: 'es6' },
|
|
55
|
+
} as unknown as import('@swc/wasm').Options;
|
|
56
|
+
return transformSync(source, options).code;
|
|
57
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { parseArgs } from 'node:util';
|
|
3
|
+
import { defaultRunRoot } from './run-root.mjs';
|
|
3
4
|
|
|
4
5
|
export const traceUsage = [
|
|
5
|
-
'Usage: anyswarm trace --root <runs-dir> [--port 8787] [--open]',
|
|
6
|
+
'Usage: anyswarm trace [--root <runs-dir>] [--port 8787] [--open]',
|
|
6
7
|
' anyswarm trace <runs-dir> [--port 8787] [--open]',
|
|
8
|
+
'Default root: ${XDG_STATE_HOME:-$HOME/.local/state}/anyswarm/runs',
|
|
7
9
|
].join('\n');
|
|
8
10
|
|
|
9
11
|
function openBrowser(url) {
|
|
@@ -46,8 +48,8 @@ export async function runTraceCommand(args) {
|
|
|
46
48
|
console.log(traceUsage);
|
|
47
49
|
return null;
|
|
48
50
|
}
|
|
49
|
-
const root = values.root ?? positionals[0];
|
|
50
|
-
if (!root) throw new Error('--root
|
|
51
|
+
const root = values.root ?? positionals[0] ?? defaultRunRoot();
|
|
52
|
+
if (!root) throw new Error('--root must not be empty');
|
|
51
53
|
if (positionals.length > 1) {
|
|
52
54
|
throw new Error('Unexpected positional argument: ' + positionals[1]);
|
|
53
55
|
}
|
|
@@ -67,6 +69,7 @@ export async function runTraceCommand(args) {
|
|
|
67
69
|
throw error;
|
|
68
70
|
}
|
|
69
71
|
console.log('AnySwarm Trace Viewer listening at ' + viewer.url);
|
|
72
|
+
console.log('Run root: ' + viewer.root);
|
|
70
73
|
const actualPort = new URL(viewer.url).port;
|
|
71
74
|
const sshHint = formatSshHint(actualPort);
|
|
72
75
|
if (sshHint) console.log(sshHint);
|