@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,22 @@
1
1
  {
2
2
  "name": "@anyswarm/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@anyswarm/core",
9
- "version": "0.5.1",
9
+ "version": "0.5.2",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@alibaba-group/opensandbox": "1.2.1",
13
- "@earendil-works/pi-tui": "1.3.0",
14
13
  "@modelcontextprotocol/client": "2.4.0",
15
14
  "ajv": "8.20.0",
16
15
  "es-module-lexer": "3.0.5",
17
16
  "js-tiktoken": "1.0.21"
18
17
  },
19
18
  "bin": {
20
- "anys": "dist/scripts/anyswarm.js",
21
- "anyswarm": "dist/scripts/anyswarm.js",
22
- "swarm": "dist/scripts/swarm.js"
19
+ "anyswarm": "dist/scripts/anyswarm.js"
23
20
  },
24
21
  "engines": {
25
22
  "node": ">=22.19.0"
@@ -48,19 +45,6 @@
48
45
  "node": ">=20.18.1"
49
46
  }
50
47
  },
51
- "node_modules/@earendil-works/pi-tui": {
52
- "version": "1.3.0",
53
- "resolved": "https://registry.npmjs.org/@earendil-works/pi-tui/-/pi-tui-1.3.0.tgz",
54
- "integrity": "sha512-AlKvEwEWyVtnuw7SVb4N/mUhlfIohyFslUNWarZVdLHHSdt3ca5EhMLwTzblBpDpaofSz+f+tAHie6CfxVrWKA==",
55
- "license": "MIT",
56
- "dependencies": {
57
- "get-east-asian-width": "1.6.0",
58
- "marked": "18.0.11"
59
- },
60
- "engines": {
61
- "node": ">=22.19.0"
62
- }
63
- },
64
48
  "node_modules/@modelcontextprotocol/client": {
65
49
  "version": "2.4.0",
66
50
  "resolved": "https://registry.npmjs.org/@modelcontextprotocol/client/-/client-2.4.0.tgz",
@@ -199,18 +183,6 @@
199
183
  ],
200
184
  "license": "BSD-3-Clause"
201
185
  },
202
- "node_modules/get-east-asian-width": {
203
- "version": "1.6.0",
204
- "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.6.0.tgz",
205
- "integrity": "sha512-QRbvDIbx6YklUe6RxeTeleMR0yv3cYH6PsPZHcnVn7xv7zO1BHN8r0XETu8n6Ye3Q+ahtSarc3WgtNWmehIBfA==",
206
- "license": "MIT",
207
- "engines": {
208
- "node": ">=18"
209
- },
210
- "funding": {
211
- "url": "https://github.com/sponsors/sindresorhus"
212
- }
213
- },
214
186
  "node_modules/isexe": {
215
187
  "version": "2.0.0",
216
188
  "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
@@ -241,18 +213,6 @@
241
213
  "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
242
214
  "license": "MIT"
243
215
  },
244
- "node_modules/marked": {
245
- "version": "18.0.11",
246
- "resolved": "https://registry.npmjs.org/marked/-/marked-18.0.11.tgz",
247
- "integrity": "sha512-HnslJfsZkRPBDJRHvVtAaWlZHEpSu7u8LgQuJCELjRKuWR+hpq4A7sLq3p8HaI9ypVoXDXxV34CsQJEe1+J5Aw==",
248
- "license": "MIT",
249
- "bin": {
250
- "marked": "bin/marked.js"
251
- },
252
- "engines": {
253
- "node": ">= 20"
254
- }
255
- },
256
216
  "node_modules/openapi-fetch": {
257
217
  "version": "0.14.1",
258
218
  "resolved": "https://registry.npmjs.org/openapi-fetch/-/openapi-fetch-0.14.1.tgz",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anyswarm/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "private": true,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -68,7 +68,6 @@
68
68
  },
69
69
  "dependencies": {
70
70
  "@alibaba-group/opensandbox": "1.2.1",
71
- "@earendil-works/pi-tui": "1.3.0",
72
71
  "@modelcontextprotocol/client": "2.4.0",
73
72
  "ajv": "8.20.0",
74
73
  "es-module-lexer": "3.0.5",
@@ -80,12 +79,9 @@
80
79
  }
81
80
  },
82
81
  "bin": {
83
- "anyswarm": "dist/scripts/anyswarm.js",
84
- "swarm": "dist/scripts/swarm.js",
85
- "anys": "dist/scripts/anyswarm.js"
82
+ "anyswarm": "dist/scripts/anyswarm.js"
86
83
  },
87
84
  "devDependencies": {
88
- "@earendil-works/pi-coding-agent": "1.3.0",
89
85
  "@types/node": "26.6.5",
90
86
  "typescript": "^7.0.2"
91
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anyswarm/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -67,7 +67,6 @@
67
67
  },
68
68
  "dependencies": {
69
69
  "@alibaba-group/opensandbox": "1.2.1",
70
- "@earendil-works/pi-tui": "1.3.0",
71
70
  "@modelcontextprotocol/client": "2.4.0",
72
71
  "ajv": "8.20.0",
73
72
  "es-module-lexer": "3.0.5",
@@ -79,8 +78,6 @@
79
78
  }
80
79
  },
81
80
  "bin": {
82
- "anyswarm": "dist/scripts/anyswarm.js",
83
- "swarm": "dist/scripts/swarm.js",
84
- "anys": "dist/scripts/anyswarm.js"
81
+ "anyswarm": "dist/scripts/anyswarm.js"
85
82
  }
86
83
  }
@@ -2,38 +2,45 @@ import { parseArgs } from 'node:util';
2
2
 
3
3
  export const setupUsage = [
4
4
  'Usage: anyswarm setup [--mode existing|local] [--endpoint <url>] [--public-url <url>] [--backend pi|codex] [--backend-path <executable>] [--backend-version <version>] [--config <module>]',
5
- 'Without --mode, reuse a saved managed local service or a configured connection. With no connection, prepare local OpenSandbox.',
6
- 'Existing mode saves the authenticated connection. Run anyswarm doctor --smoke to verify Worker and Runtime callbacks.',
5
+ 'By default, prepare local OpenSandbox and reuse compatible local settings. Select --mode existing explicitly for a remote service.',
6
+ 'Existing mode saves the authenticated connection. Use anyswarm doctor --mode existing --smoke to verify that service.',
7
7
  ].join('\n');
8
8
  const updateUsage = [
9
- 'Usage: anyswarm update [--archive <package.tgz> --sha256 <digest>]',
10
- 'Update this CLI to the latest stable release in its verified installation scope. Project SDK and Worker preparation are independent.',
9
+ 'Usage: anyswarm update',
10
+ 'Print the update command for this installation. npm manages the installed version.',
11
11
  ].join('\n');
12
12
  const recoverUsage = 'Usage: anyswarm recover --run-dir <directory> --config <module>';
13
- export const doctorUsage = 'Usage: anyswarm doctor [--config <module>] [--smoke]';
13
+ export const doctorUsage = 'Usage: anyswarm doctor [--mode local|existing] [--config <module>] [--smoke]';
14
+ const runUsage = 'Usage: anyswarm run <entry.ts> [--cwd <dir>] [--config <module>] [--prompt <text>] [--output-dir <dir>]';
15
+ const ejectUsage = 'Usage: anyswarm eject <name> --dir <dir>';
14
16
  const projectUsage = [
15
- 'Usage: anyswarm --harness <module> --prompt <text> [--cwd <directory>] [--config <module>] [--output-dir <directory>] [--lifetime task|interactive] [--interaction none|questions]',
16
- ' anyswarm --harness <module> --mode rpc [--config <module>] [--output-dir <directory>] [--lifetime task|interactive] [--interaction none|questions]',
17
- 'Built-in Harnesses: subagents, taskpool, peermesh, substrate, lead-worker, notes, messages',
18
- 'Use a built-in name, an explicit TypeScript or ESM file, or a package installed from the invocation directory.',
19
- 'An explicit interactive lifetime or questions in foreground mode uses JSONL for subsequent commands.',
20
- 'The project directory defaults to the invocation directory. In RPC mode send cwd and prompt in the run request.',
17
+ 'Usage: anyswarm --harness <name|module> --prompt <text> [--cwd <dir>] [--config <module>] [--output-dir <dir>]',
18
+ ' anyswarm --harness <name|module> --mode rpc [--config <module>] [--output-dir <dir>] [--lifetime task|interactive] [--interaction none|questions]',
19
+ 'Built-in Harnesses: subagents, autoresearch, taskpool, peermesh, substrate, lead-worker, notes, messages',
21
20
  ].join('\n');
22
21
  export const anyswarmUsage = [
23
- 'Usage: anyswarm | anys Open the streaming TUI',
24
- 'Usage: anys -u <harness> [prompt] [--headless | --rpc]',
25
- ' anys -u <harness> --cmd "/action [arguments]"',
26
- 'Harness options: --config <module>, --cwd <directory>, --output-dir <directory>, --lifetime task|interactive',
27
- ' anys run <harness> [prompt] Local source files can also accept script arguments',
28
- 'Usage: anys eject <application> --dir <directory>',
29
- 'Usage: anyswarm --version',
30
- projectUsage, setupUsage, updateUsage, doctorUsage, recoverUsage,
31
- 'Usage: anyswarm trace --root <runs-dir> [--port 8787] [--open]',
22
+ 'Usage: anyswarm <command> [options]',
23
+ '',
24
+ 'Quickstart',
25
+ ' anyswarm setup',
26
+ ' anyswarm --harness subagents --prompt "Read README.md and report its heading." --output-dir ./runs',
27
+ ' anyswarm trace --root ./runs',
28
+ '',
29
+ 'Configure your model endpoint before running a model-backed Harness.',
30
+ '',
31
+ ' setup / doctor [--smoke] Prepare and verify local execution',
32
+ ' update Show the npm upgrade command',
33
+ ' run <entry.ts> Run an editable Harness',
34
+ ' --harness <name|module> Run a Harness or use --mode rpc for JSONL',
35
+ ' eject <name> --dir <dir> Export editable source and its pinned SDK',
36
+ ' trace / recover Inspect Run records or recover pending cleanup',
37
+ '',
38
+ 'Run a command with --help for options. Use --version for the installed version.',
32
39
  ].join('\n');
33
40
 
34
41
  export type LocalCommand =
35
42
  | { command: 'setup'; mode?: 'existing' | 'local'; endpoint?: string; publicUrl?: string; configPath?: string; backend?: 'pi' | 'codex'; backendPath?: string; backendVersion?: string }
36
- | { command: 'doctor'; configPath?: string; smoke: boolean };
43
+ | { command: 'doctor'; mode?: 'existing' | 'local'; configPath?: string; smoke: boolean };
37
44
 
38
45
  type HarnessOptions = {
39
46
  harness: string;
@@ -43,94 +50,61 @@ type HarnessOptions = {
43
50
  interaction?: 'none' | 'questions';
44
51
  };
45
52
 
46
- export type ProjectCommand = HarnessOptions & { command: 'harness'; defaults?: boolean } &
47
- ({ mode: 'foreground' | 'headless'; cwd?: string; prompt: string } | { mode: 'rpc' });
48
- export type TuiCommand = Partial<HarnessOptions> & { command: 'tui'; cwd?: string; prompt?: string };
49
- export type HarnessCommand = HarnessOptions & { command: 'use'; cwd?: string; prompt?: string } &
50
- ({ mode: 'auto' | 'tui' | 'headless' | 'foreground' | 'rpc' } | { mode: 'action'; slash: string });
53
+ export type ProjectCommand = HarnessOptions & { command: 'harness' } &
54
+ ({ mode: 'foreground'; cwd?: string; prompt: string } | { mode: 'rpc' });
51
55
 
52
- type AnySwarmCommand = TuiCommand | HarnessCommand | { command: 'run'; entryPath: string; args: string[] } |
56
+ type AnySwarmCommand = { command: 'run'; entryPath: string; args: string[] } |
53
57
  { command: 'eject'; application: string; directory: string } | LocalCommand |
54
- { command: 'update'; archive?: string; sha256?: string } | ProjectCommand | { command: 'recover'; directory: string; configPath: string };
58
+ { command: 'update' } | ProjectCommand | { command: 'recover'; directory: string; configPath: string };
55
59
 
56
- export function isLocalHarness(specifier: string) {
57
- return specifier.startsWith('./') || specifier.startsWith('../') || specifier.startsWith('/');
58
- }
59
-
60
- export function isHarnessName(specifier: string) {
61
- return /^(?:@[a-z0-9_.-]+\/)?[a-z0-9][a-z0-9_.-]*$/i.test(specifier);
62
- }
63
-
64
- function parseHarnessOptions(args: string[], allowPositionals: boolean) {
65
- const { values, positionals } = parseArgs({ args, allowPositionals, options: {
66
- use: { type: 'string', short: 'u' }, harness: { type: 'string' }, prompt: { type: 'string' },
67
- cwd: { type: 'string' }, mode: { type: 'string' }, config: { type: 'string' }, 'output-dir': { type: 'string' },
60
+ export function parseProjectCommand(args: string[], source?: string): ProjectCommand {
61
+ const { values } = parseArgs({ args, options: {
62
+ harness: { type: 'string' },
63
+ prompt: { type: 'string' }, cwd: { type: 'string' }, mode: { type: 'string' },
64
+ config: { type: 'string' }, 'output-dir': { type: 'string' },
68
65
  lifetime: { type: 'string' }, interaction: { type: 'string' },
69
- headless: { type: 'boolean' }, rpc: { type: 'boolean' }, cmd: { type: 'string' },
70
66
  } });
71
- const { lifetime, interaction } = values;
72
- if ([values.use, values.harness, values.cwd, values.config, values['output-dir']].includes('') ||
67
+ const { lifetime, interaction, mode, cwd } = values;
68
+ const harness = source ?? values.harness;
69
+ if ((source && values.harness !== undefined) || !harness?.trim() || [cwd, values.config, values['output-dir']].includes('') ||
73
70
  (lifetime !== undefined && lifetime !== 'task' && lifetime !== 'interactive') ||
74
71
  (interaction !== undefined && interaction !== 'none' && interaction !== 'questions')) throw new Error();
75
- return { values, positionals, options: { configPath: values.config, outputRoot: values['output-dir'], lifetime, interaction } as Omit<HarnessOptions, 'harness'> };
72
+ const project: HarnessOptions & { command: 'harness' } = { command: 'harness', harness, configPath: values.config, outputRoot: values['output-dir'], lifetime, interaction };
73
+ if (mode === 'rpc' && values.prompt === undefined && cwd === undefined) return { ...project, mode };
74
+ const prompt = values.prompt ?? (source ? 'Run this Harness.' : undefined);
75
+ if ((mode === undefined || mode === 'foreground') && prompt?.trim() && lifetime !== 'interactive' && interaction !== 'questions') {
76
+ return { ...project, mode: 'foreground', cwd, prompt };
77
+ }
78
+ throw new Error();
76
79
  }
77
80
 
78
- export function parseHarnessSelection(args: string[], selected?: string): HarnessCommand {
79
- const { values, positionals, options } = parseHarnessOptions(args, true);
80
- const harness = selected ?? values.use;
81
- if (!harness || values.harness !== undefined || (selected && values.use !== undefined) ||
82
- (positionals.length && values.prompt !== undefined)) throw new Error(anyswarmUsage);
83
- const prompt = values.prompt ?? (positionals.length ? positionals.join(' ') : undefined);
84
- if (prompt !== undefined && !prompt.trim()) throw new Error(anyswarmUsage);
85
- const project = { command: 'use' as const, harness, ...options, prompt, cwd: values.cwd };
86
- if ([values.mode, values.headless, values.rpc, values.cmd].filter(value => value !== undefined).length > 1) throw new Error(anyswarmUsage);
87
- const mode = values.mode ?? (values.headless ? 'headless' : values.rpc ? 'rpc' : 'auto');
88
- if (values.cmd !== undefined) {
89
- if (prompt !== undefined || !/^\/[a-z][\w-]*(?:\s|$)/i.test(values.cmd.trim())) throw new Error(anyswarmUsage);
90
- return { ...project, mode: 'action', slash: values.cmd.trim() };
91
- }
92
- if (mode === 'rpc' && (prompt !== undefined || values.cwd !== undefined)) throw new Error(anyswarmUsage);
93
- if (mode === 'auto' || mode === 'tui' || mode === 'headless' || mode === 'foreground' || mode === 'rpc') return { ...project, mode };
94
- throw new Error(anyswarmUsage);
81
+ export function parseSourceHarnessCommand(args: string[], entry: string) {
82
+ try { return parseProjectCommand(args, entry); }
83
+ catch { throw new Error(runUsage); }
95
84
  }
96
85
 
97
- export function parseAnySwarmCommand(args: string[], registered: Readonly<Record<string, string>> = {}): AnySwarmCommand | { help: string } {
86
+ export function parseAnySwarmCommand(args: string[]): AnySwarmCommand | { help: string } {
98
87
  const [command, ...options] = args;
99
- if (command === undefined) return { command: 'tui' };
100
- if (command === '--help' && options.length === 0) return { help: anyswarmUsage };
101
- const usages = { run: 'Usage: anys run <harness> [prompt or source arguments]', eject: 'Usage: anys eject <application> --dir <directory>', setup: setupUsage, update: updateUsage, doctor: doctorUsage, recover: recoverUsage };
102
- const usage = Object.hasOwn(usages, command) ? usages[command as keyof typeof usages] : anyswarmUsage;
88
+ if (command === undefined || (command === '--help' && options.length === 0)) return { help: anyswarmUsage };
89
+ if ((command === '--harness' || command.startsWith('--harness=')) && options.at(-1) === '--help' &&
90
+ (options.length === 1 || (command === '--harness' && options.length === 2))) return { help: projectUsage };
91
+ const usages = { run: runUsage, eject: ejectUsage, setup: setupUsage, update: updateUsage, doctor: doctorUsage, recover: recoverUsage };
92
+ const usage = Object.hasOwn(usages, command) ? usages[command as keyof typeof usages]
93
+ : args.some(arg => /^--harness(?:=|$)/.test(arg)) ? projectUsage : anyswarmUsage;
103
94
  if (options.length === 1 && options[0] === '--help' && Object.hasOwn(usages, command)) return { help: usage };
104
95
  try {
105
96
  if (command === 'run') {
106
- if (!options[0] || options[0].startsWith('-')) throw new Error();
107
- return isLocalHarness(options[0]) || /^[^@]+\.(?:[cm]?[jt]s)$/.test(options[0])
108
- ? { command, entryPath: options[0], args: options.slice(1) }
109
- : parseHarnessSelection(options.slice(1), options[0]);
97
+ if (!options[0] || options[0].startsWith('-') || !/\.[cm]?[jt]s$/.test(options[0])) throw new Error();
98
+ return { command, entryPath: options[0], args: options.slice(1) };
110
99
  }
111
100
  if (command === 'eject') {
112
101
  const { values, positionals } = parseArgs({ args: options, allowPositionals: true, options: { dir: { type: 'string' } } });
113
- if (positionals.length === 1 && isHarnessName(positionals[0]) && !positionals[0].includes('/') && values.dir) {
102
+ if (positionals.length === 1 && /^[a-z0-9][a-z0-9_.-]*$/i.test(positionals[0]) && values.dir) {
114
103
  return { command, application: positionals[0], directory: values.dir };
115
104
  }
116
105
  throw new Error();
117
106
  }
118
- if (command === '-u' || command.startsWith('-u=') || command === '--use' || command.startsWith('--use=')) {
119
- return parseHarnessSelection(args);
120
- }
121
- if (command.startsWith('--')) {
122
- const { values, options: selection } = parseHarnessOptions(args, false);
123
- if (values.cmd !== undefined || values.headless !== undefined || values.rpc !== undefined || values.use !== undefined) throw new Error();
124
- const project = { command: 'harness' as const, harness: values.harness!, ...selection };
125
- if (values.mode === 'tui' || (values.mode === undefined && values.prompt === undefined)) {
126
- return { ...project, command: 'tui', harness: values.harness, cwd: values.cwd, prompt: values.prompt };
127
- }
128
- if (!project.harness) throw new Error();
129
- if (values.mode === 'rpc' && values.prompt === undefined && values.cwd === undefined) return { ...project, mode: 'rpc' };
130
- if ((values.mode === undefined || values.mode === 'foreground') && values.prompt?.trim()) {
131
- return { ...project, mode: 'foreground', cwd: values.cwd, prompt: values.prompt };
132
- }
133
- }
107
+ if (command.startsWith('--')) return parseProjectCommand(args);
134
108
  if (command === 'setup') {
135
109
  const { values } = parseArgs({ args: options, options: {
136
110
  mode: { type: 'string' }, endpoint: { type: 'string' }, 'public-url': { type: 'string' }, config: { type: 'string' },
@@ -146,23 +120,20 @@ export function parseAnySwarmCommand(args: string[], registered: Readonly<Record
146
120
  backend, backendPath: values['backend-path'], backendVersion: values['backend-version'] };
147
121
  }
148
122
  }
149
- if (command === 'update') {
150
- const { values } = parseArgs({ args: options, options: { archive: { type: 'string' }, sha256: { type: 'string' } } });
151
- if (options.length === 0 || (values.archive && /^[a-f0-9]{64}$/i.test(values.sha256 ?? ''))) {
152
- return { command, archive: values.archive, sha256: values.sha256?.toLowerCase() };
153
- }
154
- }
123
+ if (command === 'update' && options.length === 0) return { command };
155
124
  if (command === 'recover') {
156
125
  const { values } = parseArgs({ args: options, options: { 'run-dir': { type: 'string' }, config: { type: 'string' } } });
157
126
  if (values['run-dir'] && values.config) return { command, directory: values['run-dir'], configPath: values.config };
158
127
  }
159
128
  if (command === 'doctor') {
160
129
  const { values } = parseArgs({
161
- args: options, options: { config: { type: 'string' }, smoke: { type: 'boolean' } },
130
+ args: options, options: { config: { type: 'string' }, smoke: { type: 'boolean' }, mode: { type: 'string' } },
162
131
  });
163
- if (values.config !== '') return { command, configPath: values.config, smoke: values.smoke === true };
132
+ const { mode } = values;
133
+ if (values.config !== '' && (mode === undefined || mode === 'existing' || mode === 'local')) {
134
+ return { command, mode, configPath: values.config, smoke: values.smoke === true };
135
+ }
164
136
  }
165
- if (Object.hasOwn(registered, command)) return parseHarnessSelection(options, command);
166
137
  } catch {
167
138
  // Argument errors can contain untrusted input. Print only the command usage.
168
139
  }
@@ -92,7 +92,7 @@ export async function ejectSourceCommand(command: { application: string; directo
92
92
  archiveSha256, content: { sha256: digestFiles(packageRoot, files), files } } };
93
93
  await writeFile(join(staging, 'anyswarm-source.json'), JSON.stringify(provenance, null, 2) + '\n');
94
94
  await writeFile(join(staging, 'package.json'), JSON.stringify({ name: `anyswarm-${command.application}-source`, private: true,
95
- scripts: { start: `anys run ./${manifest.entry}` }, dependencies: { ...dependencies, '@anyswarm/core': 'file:./.anyswarm-sdk/core.tgz' },
95
+ scripts: { start: `anyswarm run ./${manifest.entry}` }, dependencies: { ...dependencies, '@anyswarm/core': 'file:./.anyswarm-sdk/core.tgz' },
96
96
  }, null, 2) + '\n');
97
97
  if (targetInfo) await rmdir(target);
98
98
  await rename(staging, target);
@@ -1,7 +1,5 @@
1
- import { existsSync } from 'node:fs';
2
- import { applicationDescriptors, findApplication } from './anyswarm-applications.js';
3
1
  export const builtins: Record<string, string> = {
4
- ...Object.fromEntries(applicationDescriptors().map(app => [app.id, app.harness])),
2
+ autoresearch: new URL('../examples/autoresearch/project.js', import.meta.url).href,
5
3
  'lead-worker': new URL('../examples/lead-worker/project.js', import.meta.url).href,
6
4
  peermesh: new URL('../examples/peermesh/project.js', import.meta.url).href,
7
5
  notes: new URL('../examples/notes/project.js', import.meta.url).href,
@@ -10,18 +8,3 @@ export const builtins: Record<string, string> = {
10
8
  substrate: new URL('../examples/substrate/project.js', import.meta.url).href,
11
9
  subagents: new URL('../examples/subagents/project.js', import.meta.url).href,
12
10
  };
13
-
14
- export async function builtinConfiguration(name: string) {
15
- if (name === 'messages') return (await import('../examples/messages/handoff-config.js')).handoffConfig();
16
- if (name === 'peermesh') return (await import('../examples/peermesh/project-config.js')).peerMeshConfig();
17
- if (name === 'substrate') return (await import('../examples/substrate/project-config.js')).substrateConfiguration();
18
- if (name === 'lead-worker') return {
19
- ...(await import('../examples/lead-worker/project-config.js')).leadWorkerConfig(),
20
- team: process.env.ANYSWARM_LEAD_WORKER_TEAM,
21
- checkingImage: process.env.ANYSWARM_LEAD_WORKER_CHECKING_IMAGE,
22
- };
23
- const path = new URL('../examples/' + name + '/config.js', import.meta.url);
24
- if (findApplication(name) && !existsSync(path)) return undefined;
25
- path.search = 'launcher=' + Date.now();
26
- return (await import(path.href)).default;
27
- }