@anyswarm/core 0.5.1 → 0.5.2

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.
Files changed (171) hide show
  1. package/AGENTS.md +1 -1
  2. package/README.md +13 -6
  3. package/dist/examples/README.md +16 -5
  4. package/dist/examples/authoring/README.md +4 -4
  5. package/dist/examples/autoresearch/README.md +15 -8
  6. package/dist/examples/autoresearch/REQUIREMENTS.zh.md +3 -10
  7. package/dist/examples/autoresearch/demo.js +1 -1
  8. package/dist/examples/autoresearch/eject.json +2 -0
  9. package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
  10. package/dist/examples/autoresearch/frontiercs2-config.js +3 -0
  11. package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
  12. package/dist/examples/autoresearch/prepare-demo.js +15 -0
  13. package/dist/examples/autoresearch/prepare.js +3 -3
  14. package/dist/examples/autoresearch/project.d.ts +0 -94
  15. package/dist/examples/autoresearch/project.js +2 -20
  16. package/dist/examples/code/README.md +25 -17
  17. package/dist/examples/code/REQUIREMENTS.zh.md +3 -3
  18. package/dist/examples/harness-session/README.md +3 -3
  19. package/dist/examples/messages/README.md +1 -1
  20. package/dist/examples/notes/README.md +3 -3
  21. package/dist/examples/services/mathlib-search/README.md +1 -1
  22. package/dist/examples/services/persistent-board/README.md +5 -2
  23. package/dist/examples/subagents/README.md +2 -2
  24. package/dist/examples/subagents/config.js +3 -3
  25. package/dist/examples/substrate/README.md +2 -2
  26. package/dist/examples/super/README.md +34 -22
  27. package/dist/examples/super/actions.d.ts +1 -1
  28. package/dist/examples/super/actions.js +11 -11
  29. package/dist/examples/super/config.js +3 -3
  30. package/dist/examples/super/eject.json +1 -1
  31. package/dist/examples/super/location.js +1 -1
  32. package/dist/examples/super/operator.d.ts +1 -0
  33. package/dist/examples/super/operator.js +31 -0
  34. package/dist/examples/super/project.d.ts +0 -107
  35. package/dist/examples/super/project.js +1 -3
  36. package/dist/scripts/anyswarm-arguments.d.ts +7 -25
  37. package/dist/scripts/anyswarm-arguments.js +69 -97
  38. package/dist/scripts/anyswarm-eject.js +1 -1
  39. package/dist/scripts/anyswarm-harnesses.d.ts +0 -1
  40. package/dist/scripts/anyswarm-harnesses.js +1 -22
  41. package/dist/scripts/anyswarm-installation.d.ts +7 -40
  42. package/dist/scripts/anyswarm-installation.js +17 -291
  43. package/dist/scripts/anyswarm-launch.d.ts +6 -36
  44. package/dist/scripts/anyswarm-launch.js +32 -81
  45. package/dist/scripts/anyswarm-progress.d.ts +6 -0
  46. package/dist/scripts/anyswarm-progress.js +102 -0
  47. package/dist/scripts/anyswarm-project.d.ts +1 -9
  48. package/dist/scripts/anyswarm-project.js +40 -127
  49. package/dist/scripts/anyswarm-source-runner.js +9 -41
  50. package/dist/scripts/anyswarm.js +6 -26
  51. package/dist/scripts/build-provenance.json +1 -1
  52. package/dist/scripts/local-environment.d.ts +10 -4
  53. package/dist/scripts/local-environment.js +67 -20
  54. package/dist/scripts/local-setup.d.ts +3 -0
  55. package/dist/scripts/local-setup.js +135 -107
  56. package/dist/scripts/pack-release.js +4 -1
  57. package/dist/src/core/worker-image.js +1 -1
  58. package/dist/src/harness/project-harness.d.ts +1 -0
  59. package/dist/src/harness/project-harness.js +2 -2
  60. package/dist/src/harness/project-runtime.js +3 -1
  61. package/docs/INDEX.md +2 -1
  62. package/docs/architecture/04-services.md +1 -1
  63. package/docs/architecture/07-run-configuration.md +28 -14
  64. package/docs/architecture/12-code-coverage.md +56 -57
  65. package/docs/architecture/17-harness-reporting.md +1 -1
  66. package/docs/architecture/22-website.md +4 -7
  67. package/docs/architecture/23-project-harness.md +48 -23
  68. package/docs/architecture/26-code.md +20 -5
  69. package/docs/architecture/27-personal.md +23 -8
  70. package/docs/architecture/28-autoresearch.md +18 -6
  71. package/docs/architecture/INDEX.md +1 -2
  72. package/docs/architecture/prompts/source-manifest.json +5 -5
  73. package/docs/architecture/source-map.json +51 -71
  74. package/docs/designs/core-harness/01-core.md +2 -2
  75. package/docs/designs/core-harness/06-project-harness.md +3 -3
  76. package/docs/designs/core-harness/README.md +2 -2
  77. package/docs/en/agents.md +1 -1
  78. package/docs/en/build-your-harness.md +1 -1
  79. package/docs/en/changelog.md +7 -0
  80. package/docs/en/first-harness.md +6 -6
  81. package/docs/en/harnesses/lead-worker.md +1 -1
  82. package/docs/en/harnesses/peermesh.md +2 -2
  83. package/docs/en/harnesses/subagents.md +2 -2
  84. package/docs/en/harnesses/substrate.md +4 -4
  85. package/docs/en/harnesses/taskpool.md +2 -2
  86. package/docs/en/latest.md +9 -5
  87. package/docs/en/quickstart.md +20 -41
  88. package/docs/en/reference/api.md +1 -1
  89. package/docs/en/reference/cli.md +47 -85
  90. package/docs/en/sandbox.md +3 -3
  91. package/docs/operations/trace-viewer.md +1 -1
  92. package/docs/third-party-notices.md +0 -1
  93. package/docs/workflows/development.md +14 -12
  94. package/docs/workflows/release-and-docs-versioning.md +13 -12
  95. package/docs/workflows/release-cli-acceptance.md +85 -0
  96. package/docs/zh/agents.md +1 -1
  97. package/docs/zh/build-your-harness.md +1 -1
  98. package/docs/zh/changelog.md +8 -1
  99. package/docs/zh/first-harness.md +7 -7
  100. package/docs/zh/harnesses/lead-worker.md +1 -1
  101. package/docs/zh/harnesses/peermesh.md +2 -2
  102. package/docs/zh/harnesses/subagents.md +2 -2
  103. package/docs/zh/harnesses/substrate.md +4 -4
  104. package/docs/zh/harnesses/taskpool.md +2 -2
  105. package/docs/zh/latest.md +9 -5
  106. package/docs/zh/quickstart.md +20 -41
  107. package/docs/zh/reference/api.md +1 -1
  108. package/docs/zh/reference/cli.md +19 -79
  109. package/docs/zh/sandbox.md +3 -3
  110. package/examples/README.md +16 -5
  111. package/examples/authoring/README.md +4 -4
  112. package/examples/autoresearch/README.md +15 -8
  113. package/examples/autoresearch/REQUIREMENTS.zh.md +3 -10
  114. package/examples/autoresearch/demo.ts +1 -1
  115. package/examples/autoresearch/eject.json +2 -0
  116. package/examples/autoresearch/frontiercs2-config.ts +4 -0
  117. package/examples/autoresearch/prepare-demo.ts +15 -0
  118. package/examples/autoresearch/prepare.ts +3 -3
  119. package/examples/autoresearch/project.ts +2 -19
  120. package/examples/code/README.md +25 -17
  121. package/examples/code/REQUIREMENTS.zh.md +3 -3
  122. package/examples/harness-session/README.md +3 -3
  123. package/examples/messages/README.md +1 -1
  124. package/examples/notes/README.md +3 -3
  125. package/examples/services/mathlib-search/README.md +1 -1
  126. package/examples/services/persistent-board/README.md +5 -2
  127. package/examples/subagents/README.md +2 -2
  128. package/examples/subagents/config.ts +4 -3
  129. package/examples/substrate/README.md +2 -2
  130. package/examples/super/README.md +34 -22
  131. package/examples/super/actions.ts +11 -11
  132. package/examples/super/config.ts +3 -3
  133. package/examples/super/eject.json +1 -1
  134. package/examples/super/location.ts +1 -1
  135. package/examples/super/operator.ts +28 -0
  136. package/examples/super/project.ts +1 -3
  137. package/npm-shrinkwrap.development.json +42 -1541
  138. package/npm-shrinkwrap.json +3 -43
  139. package/package.development.json +2 -6
  140. package/package.json +2 -5
  141. package/scripts/anyswarm-arguments.ts +67 -96
  142. package/scripts/anyswarm-eject.ts +1 -1
  143. package/scripts/anyswarm-harnesses.ts +1 -18
  144. package/scripts/anyswarm-installation.ts +18 -294
  145. package/scripts/anyswarm-launch.ts +30 -102
  146. package/scripts/anyswarm-progress.ts +95 -0
  147. package/scripts/anyswarm-project.ts +31 -123
  148. package/scripts/anyswarm-source-runner.ts +9 -36
  149. package/scripts/anyswarm.ts +4 -24
  150. package/scripts/local-environment.ts +71 -20
  151. package/scripts/local-setup.ts +134 -94
  152. package/scripts/pack-release.ts +4 -1
  153. package/src/core/worker-image.ts +1 -1
  154. package/src/harness/project-harness.ts +2 -2
  155. package/src/harness/project-runtime.ts +2 -1
  156. package/dist/scripts/anyswarm-applications.d.ts +0 -19
  157. package/dist/scripts/anyswarm-applications.js +0 -19
  158. package/dist/scripts/anyswarm-tui-config.d.ts +0 -36
  159. package/dist/scripts/anyswarm-tui-config.js +0 -189
  160. package/dist/scripts/anyswarm-tui-session.d.ts +0 -66
  161. package/dist/scripts/anyswarm-tui-session.js +0 -304
  162. package/dist/scripts/anyswarm-tui-terminal.d.ts +0 -41
  163. package/dist/scripts/anyswarm-tui-terminal.js +0 -154
  164. package/dist/scripts/anyswarm-tui.d.ts +0 -2
  165. package/dist/scripts/anyswarm-tui.js +0 -1012
  166. package/docs/architecture/25-foreground-tui.md +0 -51
  167. package/scripts/anyswarm-applications.ts +0 -39
  168. package/scripts/anyswarm-tui-config.ts +0 -174
  169. package/scripts/anyswarm-tui-session.ts +0 -295
  170. package/scripts/anyswarm-tui-terminal.ts +0 -147
  171. package/scripts/anyswarm-tui.ts +0 -912
@@ -1,25 +1,21 @@
1
- import { resolve } from 'node:path';
2
1
  import { frameworkErrorFields } from '../src/core/error-diagnostics.js';
3
- import { captureHarnessSnapshot, createHarnessSession, failureCode, getHarnessExitCode, loadProjectHarness, stopHarnessTransport } from '../src/harness/project-harness.js';
2
+ import { captureHarnessSnapshot, 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 { findApplication } from './anyswarm-applications.js';
7
- import { builtins } from './anyswarm-harnesses.js';
8
- import { actionReport, actionRun, configuredStopTimeout, harnessLifetime, loadHarness, requestedTraceRoot, splitInput } from './anyswarm-launch.js';
9
- import { LauncherConfiguration } from './anyswarm-tui-config.js';
5
+ import { prepareProjectLaunch } from './anyswarm-launch.js';
6
+ import { foregroundProgress } from './anyswarm-progress.js';
10
7
  const MAX_QUEUED_OUTPUT_BYTES = 1_048_576;
11
8
  const MAX_OUTPUT_RECORD_BYTES = 8 * 1024 * 1024;
12
9
  const OUTPUT_FLUSH_TIMEOUT_MS = 5_000;
13
10
  export async function runProjectCommand(command, launchDirectory, options = {}) {
11
+ const human = command.mode === 'foreground' && process.stdout.isTTY;
14
12
  const stdout = process.stdout.write;
15
13
  const transport = stdout.bind(process.stdout);
16
14
  const startup = new AbortController();
17
15
  let session;
18
16
  let signalCode;
19
17
  let outputFailed = false;
20
- let workspace = 'cwd' in command ? command.cwd : undefined;
21
- let trace;
22
- let unsubscribeTrace;
18
+ let progress;
23
19
  let lastWrite;
24
20
  const outputQueue = [];
25
21
  let queuedBytes = 0;
@@ -70,18 +66,9 @@ export async function runProjectCommand(command, launchDirectory, options = {})
70
66
  flushing = false;
71
67
  }
72
68
  }
73
- const write = (record, replaceableState = false) => {
69
+ const enqueue = (data, replaceableState = false) => {
74
70
  if (outputFailed)
75
71
  return Promise.resolve();
76
- let encoded;
77
- try {
78
- encoded = JSON.stringify(record);
79
- }
80
- catch {
81
- pipeFailed();
82
- return Promise.resolve();
83
- }
84
- const data = encoded + '\n';
85
72
  const bytes = Buffer.byteLength(data);
86
73
  const last = outputQueue.at(-1);
87
74
  const replace = replaceableState && last?.replaceableState ? last : undefined;
@@ -103,6 +90,15 @@ export async function runProjectCommand(command, launchDirectory, options = {})
103
90
  void flushOutput();
104
91
  return lastWrite;
105
92
  };
93
+ const write = (record, replaceableState = false) => {
94
+ try {
95
+ return enqueue(JSON.stringify(record) + '\n', replaceableState);
96
+ }
97
+ catch {
98
+ pipeFailed();
99
+ return Promise.resolve();
100
+ }
101
+ };
106
102
  const ignoreDiagnosticError = () => { };
107
103
  process.on('SIGINT', signal);
108
104
  process.on('SIGTERM', signal);
@@ -114,64 +110,27 @@ export async function runProjectCommand(command, launchDirectory, options = {})
114
110
  const stopped = Promise.withResolvers();
115
111
  const abortStartup = () => stopped.reject(startup.signal.reason);
116
112
  startup.signal.addEventListener('abort', abortStartup, { once: true });
117
- const prepare = async () => {
118
- const loaded = options.action?.loaded ?? (command.defaults
119
- ? await loadHarness(launchDirectory, command.harness, options) : undefined);
120
- const definition = loaded?.definition ?? await loadProjectHarness(launchDirectory, command.harness, builtins, options);
121
- const config = { launchDirectory, configPath: command.configPath, outputRoot: command.outputRoot,
122
- lifetime: command.lifetime, clientCapabilities: { questions: command.mode !== 'headless' && command.interaction === 'questions' } };
123
- if (!command.defaults)
124
- return createHarnessSession(definition, config);
125
- const launcher = new LauncherConfiguration(command.harness, command.harness, launchDirectory, 'cwd' in command ? command.cwd : undefined, command.configPath);
126
- let configuration = options.action?.run.configuration;
127
- if (!options.action) {
128
- await launcher.refresh();
129
- if (launcher.error)
130
- throw new Error(launcher.error);
131
- configuration = launcher.configuration;
132
- if (!workspace && loaded?.workspace && command.mode !== 'rpc') {
133
- workspace = loaded.workspace({ cwd: launcher.workspace, configuration });
134
- }
135
- }
136
- const lifetime = harnessLifetime(definition, command.lifetime, findApplication(command.harness)?.lifetime);
137
- return createHarnessSession(definition, { ...config, configPath: undefined, configuration, lifetime,
138
- stopTimeoutMs: configuredStopTimeout(configuration) });
139
- };
113
+ let launch;
140
114
  try {
141
- session = await Promise.race([prepare(), stopped.promise]);
115
+ launch = await Promise.race([prepareProjectLaunch(command, launchDirectory, options, startup.signal), stopped.promise]);
116
+ session = launch.session;
142
117
  startup.signal.throwIfAborted();
143
118
  }
144
119
  finally {
145
120
  startup.signal.removeEventListener('abort', abortStartup);
146
121
  }
147
- unsubscribeTrace = session.onEvent(event => {
148
- if (trace || event.type !== 'event')
149
- return;
150
- const root = requestedTraceRoot(event.event, event.runId);
151
- if (!root)
152
- 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);
122
+ if (command.mode === 'rpc') {
123
+ const code = await runProjectRpc(session, process.stdin, write, launchDirectory);
168
124
  await lastWrite;
169
125
  return signalCode ?? (outputFailed ? 1 : code);
170
126
  }
171
- const unsubscribe = command.mode === 'headless' ? session.onEvent(event => {
172
- if (event.type !== 'result')
173
- void write(event, event.type === 'state');
174
- }, { onError: pipeFailed }) : undefined;
127
+ if (human)
128
+ progress = foregroundProgress(session, launch.harnessId, launchDirectory, command.outputRoot, message => enqueue(message + '\n'));
129
+ const input = resolveHarnessInput({ cwd: launch.cwd, prompt: command.prompt }, launchDirectory);
130
+ const unsubscribe = progress && session.onEvent(progress.observe, {
131
+ initialSnapshot: false,
132
+ onError: () => { void enqueue('Live progress unavailable. Follow the Run in Trace.\n'); },
133
+ });
175
134
  let result;
176
135
  try {
177
136
  await session.start(input, { requestId: 'foreground-start' });
@@ -180,23 +139,28 @@ export async function runProjectCommand(command, launchDirectory, options = {})
180
139
  finally {
181
140
  unsubscribe?.();
182
141
  }
183
- await write({ type: 'result', runId: result.runId, result });
142
+ if (progress)
143
+ await progress.finish(result);
144
+ else
145
+ await write({ type: 'result', runId: result.runId, result });
184
146
  return signalCode ?? (outputFailed ? 1 : getHarnessExitCode(session));
185
147
  }
186
148
  catch (error) {
187
149
  if (!startup.signal.aborted) {
188
150
  const code = failureCode(error, 'HARNESS_COMMAND_FAILED');
189
- await write({ type: 'error', code, ...(error instanceof Error ? { message: error.message } : {}), ...frameworkErrorFields(error) });
151
+ const message = error instanceof Error ? error.message : undefined;
152
+ if (human) {
153
+ if (progress)
154
+ await progress.fail(code, message);
155
+ else
156
+ console.error(code + (message ? ' ' + message : ''));
157
+ }
158
+ else
159
+ await write({ type: 'error', code, ...(message ? { message } : {}), ...frameworkErrorFields(error) });
190
160
  }
191
161
  return signalCode ?? (outputFailed ? 1 : 2);
192
162
  }
193
163
  finally {
194
- unsubscribeTrace?.();
195
- const viewer = await trace;
196
- if (viewer) {
197
- await viewer.close().catch(() => { });
198
- console.error('Replay with anys trace --root ' + JSON.stringify(viewer.root));
199
- }
200
164
  process.stdout.write = stdout;
201
165
  process.off('SIGINT', signal);
202
166
  process.off('SIGTERM', signal);
@@ -204,54 +168,3 @@ export async function runProjectCommand(command, launchDirectory, options = {})
204
168
  process.stderr.off('error', ignoreDiagnosticError);
205
169
  }
206
170
  }
207
- export async function runHarnessAction(command, launchDirectory, options) {
208
- const controller = new AbortController();
209
- let exitCode = 0;
210
- let start;
211
- const cancel = (signal) => {
212
- exitCode ||= signal === 'SIGINT' ? 130 : 143;
213
- controller.abort();
214
- };
215
- const stdout = process.stdout.write;
216
- process.stdout.write = process.stderr.write.bind(process.stderr);
217
- process.on('SIGINT', cancel).on('SIGTERM', cancel);
218
- try {
219
- const loaded = await loadHarness(launchDirectory, command.harness, options);
220
- const [name, args] = splitInput(command.slash.slice(1));
221
- const handler = loaded.actions.get(name);
222
- if (!handler)
223
- throw new Error('Harness has no standalone /' + name + ' action.');
224
- const launcher = new LauncherConfiguration(command.harness, command.harness, launchDirectory, command.cwd, command.configPath);
225
- await launcher.refresh();
226
- if (launcher.error && launcher.path)
227
- throw new Error(launcher.error);
228
- controller.signal.throwIfAborted();
229
- const result = await handler({ cwd: launcher.workspace, configuration: launcher.configuration,
230
- signal: controller.signal, outputRoot: command.outputRoot && resolve(launchDirectory, command.outputRoot), args });
231
- controller.signal.throwIfAborted();
232
- const run = actionRun(result);
233
- if (run)
234
- start = { run: { ...run, configuration: run.configuration ?? launcher.configuration }, loaded };
235
- else if (result !== undefined) {
236
- const report = actionReport(result);
237
- const output = report ? report.result : result;
238
- await new Promise((done, reject) => {
239
- stdout.call(process.stdout, JSON.stringify(output) + '\n', undefined, error => error ? reject(error) : done());
240
- });
241
- exitCode ||= report?.exitCode ?? 0;
242
- }
243
- if (!start)
244
- return exitCode;
245
- }
246
- catch (error) {
247
- if (!exitCode)
248
- console.error(error instanceof Error ? error.message : 'Harness action failed.');
249
- return exitCode || 1;
250
- }
251
- finally {
252
- process.stdout.write = stdout;
253
- process.off('SIGINT', cancel).off('SIGTERM', cancel);
254
- }
255
- return runProjectCommand({ ...command, defaults: true, command: 'harness', mode: 'headless',
256
- cwd: start.run.cwd, prompt: start.run.prompt }, launchDirectory, { ...options, action: start });
257
- }
@@ -5,7 +5,7 @@ import { closeSync, mkdtempSync, openSync, readSync, rmdirSync, unlinkSync, writ
5
5
  import { tmpdir } from 'node:os';
6
6
  import { verifyExportedSdk } from './anyswarm-eject.js';
7
7
  import { installSourceLoader } from '../src/harness/typescript-loader.js';
8
- import { parseAnySwarmCommand, parseHarnessSelection } from './anyswarm-arguments.js';
8
+ import { parseSourceHarnessCommand } from './anyswarm-arguments.js';
9
9
  const [, , entry, ...args] = process.argv;
10
10
  if (!entry)
11
11
  throw new TypeError('A TypeScript or JavaScript entry file is required');
@@ -13,14 +13,9 @@ const filename = resolve(entry);
13
13
  const entryUrl = pathToFileURL(filename).href;
14
14
  process.argv = [process.execPath, filename, ...args];
15
15
  installSourceLoader();
16
- const hasOption = (name, value) => args.includes(`${name}=${value}`) ||
17
- args.some((arg, index) => arg === name && args[index + 1] === value);
18
- const modernFlags = args.some(arg => /^--(?:headless|rpc|cmd)(?:=|$)/.test(arg));
19
- const hasPrompt = args.some(arg => arg === '--prompt' || arg.startsWith('--prompt='));
20
- const outputsRecords = !hasOption('--mode', 'tui') &&
21
- (hasPrompt || hasOption('--mode', 'foreground') || hasOption('--mode', 'rpc'));
16
+ const hasPrompt = args.some(arg => /^--prompt(?:=|$)/.test(arg));
17
+ const hasMode = args.some(arg => /^--mode(?:=|$)/.test(arg));
22
18
  const isHarness = (source) => source.default?.apiVersion === 1 && typeof source.default.run === 'function';
23
- const isInteractiveOnly = (harness) => harness.lifetimes?.includes('interactive') && !harness.lifetimes.includes('task');
24
19
  async function importWithDiagnostics(load, useStderr = true) {
25
20
  if (!useStderr)
26
21
  return load();
@@ -144,7 +139,7 @@ async function importImplicitSource(load) {
144
139
  let destination = process.stderr;
145
140
  try {
146
141
  const source = await load();
147
- if (!isHarness(source) || (args.length === 0 && isInteractiveOnly(source.default)))
142
+ if (!isHarness(source))
148
143
  destination = process.stdout;
149
144
  else if (interactiveOutput) {
150
145
  throw new Error('Use an explicit --prompt for a task Harness that writes to stdout while reading stdin during import.');
@@ -190,40 +185,13 @@ try {
190
185
  }
191
186
  }
192
187
  const load = () => import(entryUrl);
193
- const interactive = process.stdin.isTTY && process.stdout.isTTY && process.env.TERM !== 'dumb';
194
- const probeSourceOutput = modernFlags || (args.length === 0 && /\.(?:ts|mts)$/.test(filename)) ||
195
- (!interactive && !outputsRecords && args.length > 0);
196
- const source = await (probeSourceOutput ? importImplicitSource(load) : importWithDiagnostics(load, outputsRecords));
188
+ const source = await (hasPrompt || hasMode ? importWithDiagnostics(load) : importImplicitSource(load));
197
189
  if (isHarness(source)) {
190
+ const command = parseSourceHarnessCommand(args, filename);
198
191
  const diagnostics = { onSourceError(error) { console.error(error instanceof Error ? error.stack : String(error)); } };
199
- if (modernFlags || (!hasPrompt && !args.includes('--help') &&
200
- !args.some(arg => /^--mode(?:=|$)/.test(arg)) && (args.length > 0 || interactive))) {
201
- const { runHarnessSelection } = await import('./anyswarm-launch.js');
202
- const code = await runHarnessSelection(parseHarnessSelection(args, filename), process.cwd(), diagnostics);
203
- process.stdout.write('', () => process.exit(code));
204
- }
205
- else {
206
- const command = parseAnySwarmCommand(['--harness', filename,
207
- ...(args.length || isInteractiveOnly(source.default) ? args : ['--prompt', 'Run this Harness.'])]);
208
- if ('help' in command) {
209
- console.log(command.help);
210
- }
211
- else if (command.command === 'tui') {
212
- const { runAnySwarmTui } = await import('./anyswarm-tui.js');
213
- process.exit(await runAnySwarmTui(command, process.cwd()));
214
- }
215
- else if (command.command === 'harness') {
216
- if (command.configPath) {
217
- const configPath = resolve(command.configPath);
218
- const { loadAnySwarmConfig } = await import('../src/core/sandbox/sandbox-connection.js');
219
- await importWithDiagnostics(() => loadAnySwarmConfig(configPath));
220
- }
221
- const { runProjectCommand } = await import('./anyswarm-project.js');
222
- process.exitCode = await runProjectCommand(command, process.cwd(), diagnostics);
223
- }
224
- else
225
- throw new TypeError('Harness arguments must use TUI, foreground or RPC options');
226
- }
192
+ const { runProjectCommand } = await import('./anyswarm-project.js');
193
+ const code = await runProjectCommand(command, process.cwd(), diagnostics);
194
+ process.stdout.write('', () => process.exit(code));
227
195
  }
228
196
  }
229
197
  catch (error) {
@@ -3,7 +3,6 @@ import { readFile, realpath } from 'node:fs/promises';
3
3
  import { resolve } from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import { parseAnySwarmCommand } from './anyswarm-arguments.js';
6
- import { builtins } from './anyswarm-harnesses.js';
7
6
  const args = process.argv.slice(2);
8
7
  if (args.length === 1 && args[0] === '--version') {
9
8
  const manifest = JSON.parse(await readFile(new URL('../../package.json', import.meta.url), 'utf8'));
@@ -28,7 +27,7 @@ else if (args[0] === 'trace') {
28
27
  else {
29
28
  let command;
30
29
  try {
31
- command = parseAnySwarmCommand(args, builtins);
30
+ command = parseAnySwarmCommand(args);
32
31
  }
33
32
  catch (error) {
34
33
  console.error(error.message);
@@ -36,28 +35,6 @@ else {
36
35
  }
37
36
  if (command && 'help' in command)
38
37
  console.log(command.help);
39
- if (command && 'command' in command && command.command === 'tui') {
40
- let code = 2;
41
- try {
42
- const { runAnySwarmTui } = await import('./anyswarm-tui.js');
43
- code = await runAnySwarmTui(command, process.cwd());
44
- }
45
- catch {
46
- console.error('Could not load the TUI. Reinstall @anyswarm/core or use explicit foreground or RPC mode.');
47
- }
48
- process.exit(code);
49
- }
50
- if (command && 'command' in command && command.command === 'use') {
51
- try {
52
- const { runHarnessSelection } = await import('./anyswarm-launch.js');
53
- const code = await runHarnessSelection(command, process.cwd());
54
- process.stdout.write('', () => process.exit(code));
55
- }
56
- catch (error) {
57
- console.error(error instanceof Error ? error.message : 'Could not launch the requested Harness.');
58
- process.exitCode = 1;
59
- }
60
- }
61
38
  if (command && 'command' in command && command.command === 'run') {
62
39
  try {
63
40
  const { runSourceCommand } = await import('./anyswarm-author.js');
@@ -117,9 +94,12 @@ else {
117
94
  process.on('SIGTERM', interrupt);
118
95
  try {
119
96
  const report = command.command === 'update'
120
- ? await (await import('./anyswarm-installation.js')).updateAnySwarm(command, controller.signal, console.error)
97
+ ? await (await import('./anyswarm-installation.js')).updateAnySwarm(controller.signal)
121
98
  : await (await import('./local-setup.js')).runLocalCommand(command, controller.signal, command.command === 'setup' || process.stderr.isTTY ? message => console.error(message) : undefined);
122
- console.log(JSON.stringify(report, null, 2));
99
+ if (command.command === 'update' && process.stdout.isTTY)
100
+ console.log(report.detail);
101
+ else
102
+ console.log(JSON.stringify(report, null, 2));
123
103
  process.exitCode = signalCode ?? (report.ok ? 0 : 1);
124
104
  }
125
105
  catch {
@@ -1 +1 @@
1
- {"commit":"9856d2ac811c272a0be6f7c44cc5f9a636426132","dirty":false}
1
+ {"commit":"070b025305af5dcb96a9df11b74e91ff5f786964","dirty":false}
@@ -80,19 +80,24 @@ export declare function resolveSubagentsEnvironment(config?: Partial<LocalEnviro
80
80
  };
81
81
  mode: "existing" | "local";
82
82
  }>;
83
- export declare function checkSetupHost({ requiresLinux }?: {
84
- requiresLinux?: boolean;
85
- }): DiagnosticCheck[];
83
+ export declare function checkSetupHost(): DiagnosticCheck[];
84
+ export declare function checkHostTools(signal: AbortSignal): Promise<DiagnosticCheck[]>;
86
85
  export declare function resolveLocalDocker(): Promise<{
87
86
  socket: string;
88
87
  advertiseHost: string | undefined;
89
88
  rootless: boolean;
89
+ clientVersion: string | undefined;
90
+ context: string | undefined;
91
+ engineVersion: string | undefined;
90
92
  }>;
91
93
  export declare function checkLocalDocker(): Promise<{
92
94
  docker: {
93
95
  socket: string;
94
96
  advertiseHost: string | undefined;
95
97
  rootless: boolean;
98
+ clientVersion: string | undefined;
99
+ context: string | undefined;
100
+ engineVersion: string | undefined;
96
101
  };
97
102
  diagnostic: DiagnosticCheck;
98
103
  } | {
@@ -100,7 +105,8 @@ export declare function checkLocalDocker(): Promise<{
100
105
  diagnostic: DiagnosticCheck;
101
106
  }>;
102
107
  export declare function discoverMacCallback(image: string, signal?: AbortSignal): Promise<string>;
103
- export declare function checkLocalProvider(config: LocalEnvironmentConfig, { requireAuth }?: {
108
+ export declare function checkLocalProvider(config: LocalEnvironmentConfig, { requireAuth, managed }?: {
109
+ managed?: boolean | undefined;
104
110
  requireAuth?: boolean | undefined;
105
111
  }): Promise<DiagnosticCheck[]>;
106
112
  export declare function ensureLocalProvider(config: LocalEnvironmentConfig, { signal }?: {
@@ -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';
@@ -34,16 +34,33 @@ export async function resolveLocalEnvironment(partial = {}, scope) {
34
34
  export function resolveSubagentsEnvironment(config = {}) {
35
35
  return resolveLocalEnvironment(config, 'SUBAGENTS');
36
36
  }
37
- export function checkSetupHost({ requiresLinux = true } = {}) {
37
+ export function checkSetupHost() {
38
38
  const [major, minor] = process.versions.node.split('.').map(Number);
39
39
  const os = platform();
40
40
  return [
41
- requiresLinux
42
- ? check('host.linux', os === 'linux', `Host operating system ${os}`, os === 'darwin' ? 'macOS managed Worker preparation and smoke are not yet available in this build.' : 'Run this command on Linux.')
43
- : check('host.platform', os === 'linux' || os === 'darwin', `Host operating system ${os}`, 'Run this command on Linux or macOS.'),
44
- check('host.node', major > 22 || major === 22 && minor >= 19, `Node.js ${process.versions.node}`, 'Install Node.js 22.19 or newer.'),
41
+ check('host.platform', os === 'linux' || os === 'darwin', `Host operating system ${os} ${release()} (${process.arch})`, 'Run this command on Linux or macOS.'),
42
+ check('host.node', major > 22 || major === 22 && minor >= 19, `Node.js ${process.versions.node} (${process.execPath})`, 'Install Node.js 22.19 or newer.'),
45
43
  ];
46
44
  }
45
+ export async function checkHostTools(signal) {
46
+ return Promise.all(['npm', 'git'].map(async (tool) => {
47
+ const id = `host.${tool}`;
48
+ const remedy = tool === 'npm' ? 'Install Node.js with npm and use that installation on PATH.'
49
+ : 'Install Git before running a project Harness that captures local files.';
50
+ const options = { signal, timeout: 5_000 };
51
+ let path;
52
+ try {
53
+ path = (await execute('/bin/sh', ['-c', 'command -v "$1"', 'anyswarm', tool], options)).stdout.trim();
54
+ const version = (await execute(tool, ['--version'], options)).stdout.trim();
55
+ return check(id, true, `${tool === 'git' ? version : 'npm ' + version} (${path})`);
56
+ }
57
+ catch {
58
+ signal.throwIfAborted();
59
+ const detail = path ? `Could not verify ${tool} at ${path}.` : `${tool} was not found on PATH.`;
60
+ return check(id, false, detail, remedy);
61
+ }
62
+ }));
63
+ }
47
64
  async function dockerInstallRemedy() {
48
65
  const release = await readFile('/etc/os-release', 'utf8').catch(() => '');
49
66
  const id = /^ID="?([a-z0-9_-]+)/m.exec(release)?.[1];
@@ -63,31 +80,59 @@ async function dockerInstallRemedy() {
63
80
  export async function resolveLocalDocker() {
64
81
  const socket = await localDockerSocket();
65
82
  const info = JSON.parse(await run('docker', ['info', '--format', '{{json .}}']));
66
- if (info.OSType !== 'linux')
67
- throw new Error('Local setup needs a Linux Docker Engine.');
83
+ if (info.OSType !== 'linux') {
84
+ throw Object.assign(new Error('Local setup needs a Linux Docker Engine.'), { code: 'DOCKER_OS' });
85
+ }
68
86
  if (darwin && ![nativeArchitecture, ...(nativeArchitecture === 'arm64' ? ['aarch64'] : ['x86_64'])].includes(info.Architecture)) {
69
87
  throw Object.assign(new Error('The Docker daemon does not match the native Mac architecture.'), { code: 'DOCKER_ARCHITECTURE' });
70
88
  }
71
89
  const bridge = darwin ? undefined : JSON.parse(await run('docker', ['network', 'inspect', 'bridge']).catch(() => '[]'))[0];
72
90
  const advertiseHost = bridge?.IPAM?.Config?.find((entry) => isIP(entry.Gateway ?? '') === 4)?.Gateway;
73
- return { socket, advertiseHost, rootless: info.SecurityOptions?.some((value) => value.includes('rootless')) === true };
91
+ return { socket, advertiseHost, rootless: info.SecurityOptions?.some((value) => value.includes('rootless')) === true,
92
+ clientVersion: info.ClientInfo?.Version, context: info.ClientInfo?.Context,
93
+ engineVersion: info.ServerVersion };
74
94
  }
75
95
  export async function checkLocalDocker() {
76
96
  try {
77
97
  const docker = await resolveLocalDocker();
78
- return { docker, diagnostic: check('host.docker-engine', true, `Linux Docker Engine (${docker.rootless ? 'rootless' : 'rootful'})`) };
98
+ const engine = [`Linux Docker Engine`, docker.engineVersion, `(${docker.rootless ? 'rootless' : 'rootful'})`].filter(Boolean).join(' ');
99
+ const client = docker.clientVersion ? `Docker CLI ${docker.clientVersion}` : '';
100
+ const context = docker.context ? `context ${docker.context}` : '';
101
+ return { docker, diagnostic: check('host.docker-engine', true, [engine, client, context].filter(Boolean).join(', ')) };
79
102
  }
80
103
  catch (error) {
81
104
  if (error.code === 'DOCKER_ARCHITECTURE') {
82
105
  return { diagnostic: check('host.docker-engine', false, 'The Docker daemon does not match the native Mac architecture.', 'Select a native local Docker engine for this Mac and run docker info. AnySwarm does not fall back to emulation.') };
83
106
  }
84
- const missing = error.code === 'ENOENT' &&
85
- error.syscall === 'spawn docker';
86
- const remedy = platform() === 'darwin'
87
- ? 'Install Docker Desktop for Mac (https://docs.docker.com/desktop/setup/install/mac-install/), open it, and wait for the engine to start. If you already use another local Linux engine such as OrbStack, start that instead. The Docker CLI alone is not enough. Run docker context show and docker info. If needed, run docker context ls and docker context use <local-context>. Also check any DOCKER_CONTEXT or DOCKER_HOST override.'
88
- : missing ? await dockerInstallRemedy() :
89
- 'Run docker context show and docker info. Start the selected engine or use an authorized local Docker context. For a socket permission error, ask the host administrator to grant access and sign in again after any group change. Then rerun the same anyswarm setup command.';
90
- return { diagnostic: check('host.docker-engine', false, 'Could not access a Linux Docker Engine through the selected local Unix Docker context.', remedy) };
107
+ const { code, syscall, stderr = '' } = error;
108
+ const missing = code === 'ENOENT' && syscall === 'spawn docker';
109
+ 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.';
110
+ if (code === 'LOCAL_WORKER_UNAVAILABLE') {
111
+ return { diagnostic: check('host.docker-engine', false, 'The selected Docker context does not use a local Unix socket.', contextRemedy) };
112
+ }
113
+ if (code === 'DOCKER_OS') {
114
+ return { diagnostic: check('host.docker-engine', false, 'The selected Docker daemon is not a Linux engine.', contextRemedy) };
115
+ }
116
+ if (code === 'EACCES' || code === 'EPERM' || /permission denied.*(?:socket|docker daemon)|(?:socket|docker daemon).*permission denied/i.test(stderr)) {
117
+ return { diagnostic: check('host.docker-engine', false, 'Permission denied while accessing the local Docker engine.', 'Ask the host administrator to grant socket access. Sign in again after any group change and run docker info as your login user.') };
118
+ }
119
+ 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.';
120
+ if (darwin) {
121
+ const app = 'Docker.app/Contents/Info.plist';
122
+ const installed = await Promise.all(['/Applications', join(homedir(), 'Applications')]
123
+ .map(directory => access(join(directory, app)).then(() => true, () => false)));
124
+ if (installed.some(Boolean)) {
125
+ desktopRemedy = 'Docker Desktop is installed. Open Docker Desktop or wait for its engine to finish starting, then check that its CLI is on PATH.';
126
+ }
127
+ desktopRemedy += ' If you already use another local Linux engine such as OrbStack, start that instead.';
128
+ }
129
+ if (missing) {
130
+ return { diagnostic: check('host.docker-engine', false, 'The Docker CLI was not found on PATH.', darwin ? desktopRemedy + ' ' + contextRemedy : await dockerInstallRemedy()) };
131
+ }
132
+ const unavailable = code === 'ENOENT' || /cannot connect|connection refused|daemon running/i.test(stderr);
133
+ const detail = unavailable ? 'The Docker CLI is installed, but the local daemon or its Unix socket is unavailable.'
134
+ : 'Could not verify the selected local Docker engine.';
135
+ return { diagnostic: check('host.docker-engine', false, detail, (darwin ? desktopRemedy : 'Start the local Docker engine, then verify access as your login user.') + ' ' + contextRemedy) };
91
136
  }
92
137
  }
93
138
  export async function discoverMacCallback(image, signal) {
@@ -198,11 +243,13 @@ async function authenticatedHealth(config, budget) {
198
243
  return error instanceof SandboxApiException && (error.statusCode === 401 || error.statusCode === 403) ? 'denied' : 'unreachable';
199
244
  }
200
245
  }
201
- export async function checkLocalProvider(config, { requireAuth = true } = {}) {
246
+ export async function checkLocalProvider(config, { requireAuth = true, managed = false } = {}) {
202
247
  const [healthy, denied] = await Promise.all([providerHealthy(config, true), requireAuth ? providerHealthy(config, false) : true]);
203
248
  return [
204
- check('provider.health', healthy, healthy ? 'OpenSandbox lifecycle listing is reachable with the configured credentials.' : 'OpenSandbox lifecycle listing failed.', 'Check ANYSWARM_LIFECYCLE_URL (or sandbox.lifecycleBaseUrl in --config), TLS trust, and the lifecycle API key. Rerun the same command.'),
205
- ...(requireAuth ? [check('provider.authentication', denied && !!config.apiKey, denied && config.apiKey ? 'Lifecycle rejects requests without the configured API key.' : 'Lifecycle authentication could not be confirmed.', 'Configure a lifecycle API key on OpenSandbox and pass it through trusted anyswarm configuration.')] : []),
249
+ check('provider.health', healthy, healthy ? 'OpenSandbox lifecycle listing is reachable with the configured credentials.' : 'OpenSandbox lifecycle listing failed.', managed ? 'Run anyswarm setup to start or restore the managed OpenSandbox service.'
250
+ : 'Check ANYSWARM_LIFECYCLE_URL (or sandbox.lifecycleBaseUrl in --config), TLS trust, and the lifecycle API key. Rerun the same command.'),
251
+ ...(requireAuth ? [check('provider.authentication', denied && !!config.apiKey, denied && config.apiKey ? 'Lifecycle rejects requests without the configured API key.' : 'Lifecycle authentication could not be confirmed.', managed ? 'Run anyswarm setup to check the managed service and its local credentials.'
252
+ : 'Configure a lifecycle API key on OpenSandbox and pass it through trusted anyswarm configuration.')] : []),
206
253
  ];
207
254
  }
208
255
  async function withProviderLock(config, action, signal) {
@@ -13,6 +13,7 @@ type Timing = {
13
13
  type Model = {
14
14
  configuration: 'complete' | 'missing' | 'invalid';
15
15
  verification: 'not-verified';
16
+ remedy?: string;
16
17
  };
17
18
  export declare function runLocalCommand(command: LocalCommand, signal: AbortSignal, progress?: (message: string) => void): Promise<{
18
19
  command: LocalCommand['command'];
@@ -39,12 +40,14 @@ export declare function runLocalCommand(command: LocalCommand, signal: AbortSign
39
40
  executor: {
40
41
  id: string;
41
42
  version?: string;
43
+ entry?: string;
42
44
  compatibleVersions?: readonly string[];
43
45
  };
44
46
  image: string;
45
47
  filePolicy: ResolvedFilePolicy;
46
48
  };
47
49
  checks: DiagnosticCheck[];
50
+ tooling?: DiagnosticCheck[];
48
51
  timings: Timing[];
49
52
  elapsedMs: number;
50
53
  interrupted: boolean;