@anyswarm/core 0.5.0 → 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 (403) hide show
  1. package/AGENTS.md +1 -1
  2. package/README.md +21 -13
  3. package/deploy/worker/Dockerfile +12 -4
  4. package/dist/deploy/worker/Dockerfile +12 -4
  5. package/dist/examples/README.md +35 -12
  6. package/dist/examples/authoring/README.md +24 -0
  7. package/dist/examples/authoring/business.d.ts +2 -0
  8. package/dist/examples/authoring/business.js +4 -0
  9. package/dist/examples/authoring/config.d.ts +5 -0
  10. package/dist/examples/authoring/config.js +2 -0
  11. package/dist/examples/authoring/eject.json +5 -0
  12. package/dist/examples/authoring/harness.d.ts +4 -0
  13. package/dist/examples/authoring/harness.js +19 -0
  14. package/dist/examples/autoresearch/README.md +40 -0
  15. package/dist/examples/autoresearch/REQUIREMENTS.zh.md +11 -0
  16. package/dist/examples/autoresearch/config.d.ts +51 -0
  17. package/dist/examples/autoresearch/config.js +57 -0
  18. package/dist/examples/autoresearch/demo.d.ts +11 -0
  19. package/dist/examples/autoresearch/demo.js +52 -0
  20. package/dist/examples/autoresearch/eject.json +17 -0
  21. package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
  22. package/dist/examples/autoresearch/frontiercs2-config.js +3 -0
  23. package/dist/examples/autoresearch/frontiercs2.d.ts +87 -0
  24. package/dist/examples/autoresearch/frontiercs2.js +211 -0
  25. package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
  26. package/dist/examples/autoresearch/prepare-demo.js +15 -0
  27. package/dist/examples/autoresearch/prepare.d.ts +95 -0
  28. package/dist/examples/autoresearch/prepare.js +257 -0
  29. package/dist/examples/autoresearch/process.d.ts +13 -0
  30. package/dist/examples/autoresearch/process.js +48 -0
  31. package/dist/examples/autoresearch/project.d.ts +21 -0
  32. package/dist/examples/autoresearch/project.js +392 -0
  33. package/dist/examples/autoresearch/research-service.d.ts +106 -0
  34. package/dist/examples/autoresearch/research-service.js +255 -0
  35. package/dist/examples/code/README.md +33 -0
  36. package/dist/examples/code/REQUIREMENTS.zh.md +11 -0
  37. package/dist/examples/code/candidate.d.ts +19 -0
  38. package/dist/examples/code/candidate.js +80 -0
  39. package/dist/examples/code/config.d.ts +32 -0
  40. package/dist/examples/code/config.js +18 -0
  41. package/dist/examples/code/eject.json +5 -0
  42. package/dist/examples/code/project.d.ts +3 -0
  43. package/dist/examples/code/project.js +605 -0
  44. package/dist/examples/code/prompts.d.ts +5 -0
  45. package/dist/examples/code/prompts.js +12 -0
  46. package/dist/examples/code/verification.d.ts +19 -0
  47. package/dist/examples/code/verification.js +268 -0
  48. package/dist/examples/code/worktree.d.ts +17 -0
  49. package/dist/examples/code/worktree.js +233 -0
  50. package/dist/examples/harness-session/README.md +3 -6
  51. package/dist/examples/lead-worker/harness/dynamic-scheduler.d.ts +2 -1
  52. package/dist/examples/lead-worker/harness/dynamic-scheduler.js +5 -2
  53. package/dist/examples/lead-worker/harness/index.d.ts +60 -0
  54. package/dist/examples/lead-worker/harness/index.js +77 -6
  55. package/dist/examples/lead-worker/project.js +2 -2
  56. package/dist/examples/lead-worker/services/board.d.ts +5 -0
  57. package/dist/examples/lead-worker/services/board.js +19 -1
  58. package/dist/examples/messages/README.md +5 -5
  59. package/dist/examples/messages/handoff.d.ts +2 -0
  60. package/dist/examples/messages/handoff.js +5 -1
  61. package/dist/examples/messages/project.js +52 -2
  62. package/dist/examples/notes/README.md +13 -18
  63. package/dist/examples/notes/project.js +67 -6
  64. package/dist/examples/peermesh/harness/router.js +3 -1
  65. package/dist/examples/peermesh/harness/team.d.ts +8 -0
  66. package/dist/examples/peermesh/harness/team.js +13 -0
  67. package/dist/examples/peermesh/project.js +22 -4
  68. package/dist/examples/services/agent-control/README.md +3 -3
  69. package/dist/examples/services/mathlib-search/Dockerfile +4 -2
  70. package/dist/examples/services/mathlib-search/README.md +1 -1
  71. package/dist/examples/services/mcp-managed/README.md +2 -2
  72. package/dist/examples/services/persistent-board/README.md +16 -3
  73. package/dist/examples/services/persistent-board/business.d.ts +7 -0
  74. package/dist/examples/services/persistent-board/business.js +7 -0
  75. package/dist/examples/services/persistent-board/index.js +10 -0
  76. package/dist/examples/services/persistent-board/live.d.ts +3 -0
  77. package/dist/examples/services/persistent-board/live.js +58 -0
  78. package/dist/examples/subagents/README.md +5 -5
  79. package/dist/examples/subagents/business.js +3 -1
  80. package/dist/examples/subagents/config.js +3 -3
  81. package/dist/examples/subagents/harness/controller.d.ts +15 -0
  82. package/dist/examples/subagents/harness/controller.js +181 -32
  83. package/dist/examples/subagents/project.d.ts +2 -0
  84. package/dist/examples/subagents/project.js +43 -34
  85. package/dist/examples/subagents/prompts/prompts.d.ts +1 -0
  86. package/dist/examples/subagents/prompts/prompts.js +3 -0
  87. package/dist/examples/subagents/services/collaboration-service.d.ts +3 -2
  88. package/dist/examples/subagents/services/collaboration-service.js +14 -2
  89. package/dist/examples/substrate/README.md +2 -2
  90. package/dist/examples/substrate/harness/index.d.ts +1 -1
  91. package/dist/examples/substrate/harness/index.js +77 -12
  92. package/dist/examples/substrate/project.js +4 -1
  93. package/dist/examples/super/README.md +52 -0
  94. package/dist/examples/super/actions.d.ts +95 -0
  95. package/dist/examples/super/actions.js +230 -0
  96. package/dist/examples/super/artifact.d.ts +4 -0
  97. package/dist/examples/super/artifact.js +51 -0
  98. package/dist/examples/super/config.d.ts +80 -0
  99. package/dist/examples/super/config.js +83 -0
  100. package/dist/examples/super/coordinator.d.ts +33 -0
  101. package/dist/examples/super/coordinator.js +151 -0
  102. package/dist/examples/super/daemon.d.ts +11 -0
  103. package/dist/examples/super/daemon.js +109 -0
  104. package/dist/examples/super/decisions.d.ts +8 -0
  105. package/dist/examples/super/decisions.js +52 -0
  106. package/dist/examples/super/eject.json +5 -0
  107. package/dist/examples/super/execution.d.ts +11 -0
  108. package/dist/examples/super/execution.js +136 -0
  109. package/dist/examples/super/github.d.ts +62 -0
  110. package/dist/examples/super/github.js +269 -0
  111. package/dist/examples/super/inbox.d.ts +162 -0
  112. package/dist/examples/super/inbox.js +284 -0
  113. package/dist/examples/super/location.d.ts +5 -0
  114. package/dist/examples/super/location.js +64 -0
  115. package/dist/examples/super/operator.d.ts +1 -0
  116. package/dist/examples/super/operator.js +31 -0
  117. package/dist/examples/super/outbox.d.ts +5 -0
  118. package/dist/examples/super/outbox.js +103 -0
  119. package/dist/examples/super/project.d.ts +4 -0
  120. package/dist/examples/super/project.js +251 -0
  121. package/dist/examples/super/prompts.d.ts +3 -0
  122. package/dist/examples/super/prompts.js +25 -0
  123. package/dist/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
  124. package/dist/examples/taskpool/harness/controller.d.ts +35 -6
  125. package/dist/examples/taskpool/harness/controller.js +73 -7
  126. package/dist/examples/taskpool/project.js +18 -2
  127. package/dist/scripts/anyswarm-arguments.d.ts +18 -6
  128. package/dist/scripts/anyswarm-arguments.js +88 -52
  129. package/dist/scripts/anyswarm-author.d.ts +5 -0
  130. package/dist/scripts/anyswarm-author.js +24 -0
  131. package/dist/scripts/anyswarm-eject.d.ts +11 -0
  132. package/dist/scripts/anyswarm-eject.js +164 -0
  133. package/dist/scripts/anyswarm-harnesses.d.ts +1 -0
  134. package/dist/scripts/anyswarm-harnesses.js +10 -0
  135. package/dist/scripts/anyswarm-installation.d.ts +7 -40
  136. package/dist/scripts/anyswarm-installation.js +17 -285
  137. package/dist/scripts/anyswarm-launch.d.ts +7 -0
  138. package/dist/scripts/anyswarm-launch.js +37 -0
  139. package/dist/scripts/anyswarm-progress.d.ts +6 -0
  140. package/dist/scripts/anyswarm-progress.js +102 -0
  141. package/dist/scripts/anyswarm-project.d.ts +3 -1
  142. package/dist/scripts/anyswarm-project.js +49 -35
  143. package/dist/scripts/anyswarm-source-runner.d.ts +1 -0
  144. package/dist/scripts/anyswarm-source-runner.js +200 -0
  145. package/dist/scripts/anyswarm.js +28 -3
  146. package/dist/scripts/build-provenance.json +1 -0
  147. package/dist/scripts/build.js +7 -1
  148. package/dist/scripts/generate-architecture-api.js +2 -0
  149. package/dist/scripts/generate-architecture-prompts.js +24 -2
  150. package/dist/scripts/local-environment.d.ts +13 -2
  151. package/dist/scripts/local-environment.js +111 -28
  152. package/dist/scripts/local-setup-smoke.js +3 -2
  153. package/dist/scripts/local-setup-worker.d.ts +1 -1
  154. package/dist/scripts/local-setup-worker.js +15 -6
  155. package/dist/scripts/local-setup.d.ts +5 -2
  156. package/dist/scripts/local-setup.js +167 -79
  157. package/dist/scripts/opensandbox-agent-worker.js +2 -2
  158. package/dist/scripts/pack-release.d.ts +1 -0
  159. package/dist/scripts/pack-release.js +66 -0
  160. package/dist/scripts/pi-session-bridge.js +11 -3
  161. package/dist/scripts/run-harness.js +3 -1
  162. package/dist/scripts/setup-bootstrap.js +43 -6
  163. package/dist/src/core/allocation-ledger.js +4 -3
  164. package/dist/src/core/host-identity.d.ts +2 -0
  165. package/dist/src/core/host-identity.js +11 -0
  166. package/dist/src/core/index.d.ts +4 -2
  167. package/dist/src/core/index.js +12 -4
  168. package/dist/src/core/mcp-service.js +2 -2
  169. package/dist/src/core/runtime-management.d.ts +6 -0
  170. package/dist/src/core/runtime-management.js +24 -0
  171. package/dist/src/core/sandbox/executor-driver.d.ts +4 -2
  172. package/dist/src/core/sandbox/executor-driver.js +12 -14
  173. package/dist/src/core/sandbox/local-executor.d.ts +13 -1
  174. package/dist/src/core/sandbox/local-executor.js +69 -19
  175. package/dist/src/core/sandbox/local-worker.js +32 -21
  176. package/dist/src/core/sandbox/opensandbox-backend.d.ts +2 -0
  177. package/dist/src/core/sandbox/opensandbox-backend.js +36 -11
  178. package/dist/src/core/sandbox/sandbox-connection.d.ts +2 -0
  179. package/dist/src/core/sandbox/sandbox-connection.js +14 -6
  180. package/dist/src/core/service-live-state.d.ts +14 -0
  181. package/dist/src/core/service-live-state.js +161 -0
  182. package/dist/src/core/service-observation-types.d.ts +21 -1
  183. package/dist/src/core/service-process.d.ts +1 -1
  184. package/dist/src/core/service-process.js +45 -4
  185. package/dist/src/core/service-types.d.ts +5 -1
  186. package/dist/src/core/services.d.ts +1 -1
  187. package/dist/src/core/services.js +8 -3
  188. package/dist/src/core/types.d.ts +3 -0
  189. package/dist/src/core/worker-image.js +3 -3
  190. package/dist/src/harness/harness-session-types.d.ts +10 -0
  191. package/dist/src/harness/harness-session.js +42 -5
  192. package/dist/src/harness/project-harness.d.ts +14 -1
  193. package/dist/src/harness/project-harness.js +38 -12
  194. package/dist/src/harness/project-input.js +81 -15
  195. package/dist/src/harness/project-rpc-client.d.ts +1 -0
  196. package/dist/src/harness/project-rpc-client.js +5 -0
  197. package/dist/src/harness/project-rpc.d.ts +8 -2
  198. package/dist/src/harness/project-rpc.js +31 -7
  199. package/dist/src/harness/project-runtime.js +6 -2
  200. package/dist/src/harness/typescript-loader.d.ts +2 -0
  201. package/dist/src/harness/typescript-loader.js +41 -0
  202. package/dist/src/trace-viewer/public/app.js +6 -5
  203. package/dist/src/trace-viewer/reader.mjs +42 -2
  204. package/docs/INDEX.md +5 -2
  205. package/docs/architecture/00-overview.md +1 -1
  206. package/docs/architecture/01-agent-core.md +1 -1
  207. package/docs/architecture/04-services.md +1 -1
  208. package/docs/architecture/06-observability-experiments.md +1 -1
  209. package/docs/architecture/07-run-configuration.md +38 -18
  210. package/docs/architecture/08-prompts.md +22 -0
  211. package/docs/architecture/10-service-api-reference.md +53 -18
  212. package/docs/architecture/11-storage-reference.md +18 -1
  213. package/docs/architecture/12-code-coverage.md +152 -89
  214. package/docs/architecture/15-core-runtime.md +8 -0
  215. package/docs/architecture/16-pi-opensandbox-backend.md +5 -5
  216. package/docs/architecture/17-harness-reporting.md +1 -1
  217. package/docs/architecture/19-substrate-harness.md +28 -1
  218. package/docs/architecture/20-lead-worker-harness.md +34 -1
  219. package/docs/architecture/22-website.md +5 -6
  220. package/docs/architecture/23-project-harness.md +152 -8
  221. package/docs/architecture/24-runtime-recovery.md +10 -3
  222. package/docs/architecture/26-code.md +54 -0
  223. package/docs/architecture/27-personal.md +58 -0
  224. package/docs/architecture/28-autoresearch.md +43 -0
  225. package/docs/architecture/INDEX.md +3 -0
  226. package/docs/architecture/prompts/08-lead-worker-harness.md +4 -2
  227. package/docs/architecture/prompts/08-subagents-harness.md +21 -0
  228. package/docs/architecture/prompts/21-personal.md +44 -0
  229. package/docs/architecture/prompts/22-autoresearch.md +63 -0
  230. package/docs/architecture/prompts/26-code.md +55 -0
  231. package/docs/architecture/prompts/source-manifest.json +152 -33
  232. package/docs/architecture/source-map.json +473 -25
  233. package/docs/designs/core-harness/01-core.md +2 -2
  234. package/docs/designs/core-harness/06-project-harness.md +13 -2
  235. package/docs/designs/core-harness/README.md +7 -2
  236. package/docs/en/agents.md +1 -1
  237. package/docs/en/build-your-harness.md +3 -5
  238. package/docs/en/changelog.md +20 -4
  239. package/docs/en/first-harness.md +9 -12
  240. package/docs/en/harnesses/lead-worker.md +1 -1
  241. package/docs/en/harnesses/peermesh.md +2 -2
  242. package/docs/en/harnesses/subagents.md +2 -2
  243. package/docs/en/harnesses/substrate.md +4 -4
  244. package/docs/en/harnesses/taskpool.md +2 -2
  245. package/docs/en/latest.md +14 -121
  246. package/docs/en/overview.md +1 -1
  247. package/docs/en/quickstart.md +42 -39
  248. package/docs/en/reference/api.md +14 -4
  249. package/docs/en/reference/cli.md +53 -47
  250. package/docs/en/runtime.md +2 -2
  251. package/docs/en/sandbox.md +3 -3
  252. package/docs/en/services.md +4 -0
  253. package/docs/operations/trace-viewer.md +1 -1
  254. package/docs/workflows/development.md +28 -21
  255. package/docs/workflows/release-and-docs-versioning.md +77 -0
  256. package/docs/workflows/release-cli-acceptance.md +85 -0
  257. package/docs/zh/agents.md +1 -1
  258. package/docs/zh/build-your-harness.md +3 -5
  259. package/docs/zh/changelog.md +20 -4
  260. package/docs/zh/first-harness.md +9 -12
  261. package/docs/zh/harnesses/lead-worker.md +1 -1
  262. package/docs/zh/harnesses/peermesh.md +2 -2
  263. package/docs/zh/harnesses/subagents.md +2 -2
  264. package/docs/zh/harnesses/substrate.md +4 -4
  265. package/docs/zh/harnesses/taskpool.md +2 -2
  266. package/docs/zh/latest.md +15 -122
  267. package/docs/zh/overview.md +1 -1
  268. package/docs/zh/quickstart.md +42 -39
  269. package/docs/zh/reference/api.md +14 -4
  270. package/docs/zh/reference/cli.md +24 -40
  271. package/docs/zh/runtime.md +2 -2
  272. package/docs/zh/sandbox.md +3 -3
  273. package/docs/zh/services.md +4 -0
  274. package/examples/README.md +35 -12
  275. package/examples/authoring/README.md +24 -0
  276. package/examples/authoring/business.ts +4 -0
  277. package/examples/authoring/config.ts +2 -0
  278. package/examples/authoring/eject.json +5 -0
  279. package/examples/authoring/harness.ts +21 -0
  280. package/examples/autoresearch/README.md +40 -0
  281. package/examples/autoresearch/REQUIREMENTS.zh.md +11 -0
  282. package/examples/autoresearch/config.ts +90 -0
  283. package/examples/autoresearch/demo.ts +55 -0
  284. package/examples/autoresearch/eject.json +17 -0
  285. package/examples/autoresearch/frontiercs2-config.ts +4 -0
  286. package/examples/autoresearch/frontiercs2.ts +237 -0
  287. package/examples/autoresearch/prepare-demo.ts +15 -0
  288. package/examples/autoresearch/prepare.ts +267 -0
  289. package/examples/autoresearch/process.ts +50 -0
  290. package/examples/autoresearch/project.ts +380 -0
  291. package/examples/autoresearch/research-service.ts +302 -0
  292. package/examples/code/README.md +33 -0
  293. package/examples/code/REQUIREMENTS.zh.md +11 -0
  294. package/examples/code/candidate.ts +89 -0
  295. package/examples/code/config.ts +19 -0
  296. package/examples/code/eject.json +5 -0
  297. package/examples/code/project.ts +581 -0
  298. package/examples/code/prompts.ts +16 -0
  299. package/examples/code/verification.ts +239 -0
  300. package/examples/code/worktree.ts +188 -0
  301. package/examples/harness-session/README.md +3 -6
  302. package/examples/lead-worker/harness/dynamic-scheduler.ts +6 -3
  303. package/examples/lead-worker/harness/index.ts +61 -6
  304. package/examples/lead-worker/project.ts +2 -2
  305. package/examples/lead-worker/services/board.ts +14 -1
  306. package/examples/messages/README.md +5 -5
  307. package/examples/messages/handoff.ts +6 -2
  308. package/examples/messages/project.ts +47 -2
  309. package/examples/notes/README.md +13 -18
  310. package/examples/notes/project.ts +57 -9
  311. package/examples/peermesh/harness/router.ts +2 -2
  312. package/examples/peermesh/harness/team.ts +11 -0
  313. package/examples/peermesh/project.ts +19 -4
  314. package/examples/services/agent-control/README.md +3 -3
  315. package/examples/services/mathlib-search/Dockerfile +4 -2
  316. package/examples/services/mathlib-search/README.md +1 -1
  317. package/examples/services/mcp-managed/README.md +2 -2
  318. package/examples/services/persistent-board/README.md +16 -3
  319. package/examples/services/persistent-board/business.ts +10 -0
  320. package/examples/services/persistent-board/index.ts +10 -0
  321. package/examples/services/persistent-board/live.ts +54 -0
  322. package/examples/subagents/README.md +5 -5
  323. package/examples/subagents/business.ts +3 -1
  324. package/examples/subagents/config.ts +4 -3
  325. package/examples/subagents/harness/controller.ts +161 -29
  326. package/examples/subagents/project.ts +47 -33
  327. package/examples/subagents/prompts/prompts.ts +4 -0
  328. package/examples/subagents/services/collaboration-service.ts +14 -2
  329. package/examples/substrate/README.md +2 -2
  330. package/examples/substrate/harness/index.ts +67 -11
  331. package/examples/substrate/project.ts +5 -1
  332. package/examples/super/README.md +52 -0
  333. package/examples/super/actions.ts +196 -0
  334. package/examples/super/artifact.ts +56 -0
  335. package/examples/super/config.ts +95 -0
  336. package/examples/super/coordinator.ts +158 -0
  337. package/examples/super/daemon.ts +84 -0
  338. package/examples/super/decisions.ts +46 -0
  339. package/examples/super/eject.json +5 -0
  340. package/examples/super/execution.ts +131 -0
  341. package/examples/super/github.ts +242 -0
  342. package/examples/super/inbox.ts +306 -0
  343. package/examples/super/location.ts +54 -0
  344. package/examples/super/operator.ts +28 -0
  345. package/examples/super/outbox.ts +97 -0
  346. package/examples/super/project.ts +225 -0
  347. package/examples/super/prompts.ts +27 -0
  348. package/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
  349. package/examples/taskpool/harness/controller.ts +59 -7
  350. package/examples/taskpool/project.ts +18 -2
  351. package/npm-shrinkwrap.development.json +700 -0
  352. package/npm-shrinkwrap.json +95 -1969
  353. package/package.development.json +88 -0
  354. package/package.json +11 -8
  355. package/scripts/anyswarm-arguments.ts +91 -54
  356. package/scripts/anyswarm-author.ts +25 -0
  357. package/scripts/anyswarm-eject.ts +145 -0
  358. package/scripts/anyswarm-harnesses.ts +10 -0
  359. package/scripts/anyswarm-installation.ts +18 -288
  360. package/scripts/anyswarm-launch.ts +36 -0
  361. package/scripts/anyswarm-progress.ts +95 -0
  362. package/scripts/anyswarm-project.ts +35 -34
  363. package/scripts/anyswarm-source-runner.ts +176 -0
  364. package/scripts/anyswarm.ts +24 -3
  365. package/scripts/build.ts +8 -1
  366. package/scripts/generate-architecture-api.ts +2 -0
  367. package/scripts/generate-architecture-prompts.ts +35 -2
  368. package/scripts/local-environment.ts +117 -28
  369. package/scripts/local-setup-smoke.ts +3 -2
  370. package/scripts/local-setup-worker.ts +17 -7
  371. package/scripts/local-setup.ts +166 -73
  372. package/scripts/opensandbox-agent-worker.ts +2 -2
  373. package/scripts/pack-release.ts +70 -0
  374. package/scripts/pi-session-bridge.ts +10 -2
  375. package/scripts/run-harness.ts +3 -1
  376. package/scripts/setup-bootstrap.ts +41 -6
  377. package/src/core/allocation-ledger.ts +5 -3
  378. package/src/core/host-identity.ts +11 -0
  379. package/src/core/index.ts +12 -6
  380. package/src/core/mcp-service.ts +2 -2
  381. package/src/core/runtime-management.ts +22 -0
  382. package/src/core/sandbox/executor-driver.ts +15 -18
  383. package/src/core/sandbox/local-executor.ts +65 -19
  384. package/src/core/sandbox/local-worker.ts +29 -21
  385. package/src/core/sandbox/opensandbox-backend.ts +36 -11
  386. package/src/core/sandbox/sandbox-connection.ts +14 -5
  387. package/src/core/service-live-state.ts +156 -0
  388. package/src/core/service-observation-types.ts +23 -1
  389. package/src/core/service-process.ts +36 -3
  390. package/src/core/service-types.ts +3 -1
  391. package/src/core/services.ts +8 -3
  392. package/src/core/types.ts +3 -0
  393. package/src/core/worker-image.ts +3 -3
  394. package/src/harness/harness-session-types.ts +13 -1
  395. package/src/harness/harness-session.ts +40 -7
  396. package/src/harness/project-harness.ts +38 -12
  397. package/src/harness/project-input.ts +73 -15
  398. package/src/harness/project-rpc-client.ts +5 -0
  399. package/src/harness/project-rpc.ts +29 -8
  400. package/src/harness/project-runtime.ts +4 -2
  401. package/src/harness/typescript-loader.ts +37 -0
  402. package/src/trace-viewer/public/app.js +6 -5
  403. package/src/trace-viewer/reader.mjs +42 -2
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@anyswarm/core",
3
+ "version": "0.5.2",
4
+ "private": true,
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "license": "MIT",
9
+ "type": "module",
10
+ "description": "Build and run custom multi-agent collaboration with isolated coding agents.",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/AnySwarm/anyswarm.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/AnySwarm/anyswarm/issues"
17
+ },
18
+ "homepage": "https://anyswarm.github.io/anyswarm/",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/src/core/index.d.ts",
22
+ "default": "./dist/src/core/index.js"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist/src/",
27
+ "dist/scripts/",
28
+ "dist/deploy/",
29
+ "dist/examples/",
30
+ "dist/test-support/*.js",
31
+ "dist/test-support/subagents/",
32
+ "tsconfig.json",
33
+ ".dockerignore",
34
+ "src/",
35
+ "scripts/",
36
+ "deploy/",
37
+ "examples/",
38
+ "!examples/**/__pycache__/**",
39
+ "docs/",
40
+ "test-support/*.ts",
41
+ "test-support/subagents/",
42
+ "AGENTS.md",
43
+ "GLOSSARY.md",
44
+ "npm-shrinkwrap.json",
45
+ "package.development.json",
46
+ "npm-shrinkwrap.development.json",
47
+ ".env.example",
48
+ ".gitmodules"
49
+ ],
50
+ "engines": {
51
+ "node": ">=22.19.0"
52
+ },
53
+ "scripts": {
54
+ "build": "node scripts/build.ts",
55
+ "typecheck": "tsc --noEmit",
56
+ "prepack": "npm run build",
57
+ "pack:release": "node scripts/pack-release.ts",
58
+ "swarm": "node dist/scripts/swarm.js",
59
+ "test": "node --test --test-concurrency=1 'dist/test/**/*.test.js'",
60
+ "pretest": "npm run docs:check",
61
+ "test:focus": "node scripts/test-focused.ts",
62
+ "service:mathlib-search": "node dist/examples/services/mathlib-search/main.js",
63
+ "service:builtin": "node dist/examples/taskpool/deploy/service-hosts/start-service-host.js",
64
+ "docs:generate": "node dist/scripts/generate-architecture-prompts.js && node dist/scripts/generate-architecture-api.js && node dist/scripts/generate-architecture-coverage.js",
65
+ "docs:check": "node dist/scripts/check-architecture.js",
66
+ "predocs:generate": "npm run build",
67
+ "predocs:check": "npm run build"
68
+ },
69
+ "dependencies": {
70
+ "@alibaba-group/opensandbox": "1.2.1",
71
+ "@modelcontextprotocol/client": "2.4.0",
72
+ "ajv": "8.20.0",
73
+ "es-module-lexer": "3.0.5",
74
+ "js-tiktoken": "1.0.21"
75
+ },
76
+ "overrides": {
77
+ "@modelcontextprotocol/client": {
78
+ "cross-spawn": "7.1.2"
79
+ }
80
+ },
81
+ "bin": {
82
+ "anyswarm": "dist/scripts/anyswarm.js"
83
+ },
84
+ "devDependencies": {
85
+ "@types/node": "26.6.5",
86
+ "typescript": "^7.0.2"
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anyswarm/core",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -41,6 +41,8 @@
41
41
  "AGENTS.md",
42
42
  "GLOSSARY.md",
43
43
  "npm-shrinkwrap.json",
44
+ "package.development.json",
45
+ "npm-shrinkwrap.development.json",
44
46
  ".env.example",
45
47
  ".gitmodules"
46
48
  ],
@@ -51,6 +53,7 @@
51
53
  "build": "node scripts/build.ts",
52
54
  "typecheck": "tsc --noEmit",
53
55
  "prepack": "npm run build",
56
+ "pack:release": "node scripts/pack-release.ts",
54
57
  "swarm": "node dist/scripts/swarm.js",
55
58
  "test": "node --test --test-concurrency=1 'dist/test/**/*.test.js'",
56
59
  "pretest": "npm run docs:check",
@@ -66,15 +69,15 @@
66
69
  "@alibaba-group/opensandbox": "1.2.1",
67
70
  "@modelcontextprotocol/client": "2.4.0",
68
71
  "ajv": "8.20.0",
72
+ "es-module-lexer": "3.0.5",
69
73
  "js-tiktoken": "1.0.21"
70
74
  },
71
- "bin": {
72
- "anyswarm": "dist/scripts/anyswarm.js",
73
- "swarm": "dist/scripts/swarm.js"
75
+ "overrides": {
76
+ "@modelcontextprotocol/client": {
77
+ "cross-spawn": "7.1.2"
78
+ }
74
79
  },
75
- "devDependencies": {
76
- "@earendil-works/pi-coding-agent": "1.3.0",
77
- "@types/node": "26.6.5",
78
- "typescript": "^7.0.2"
80
+ "bin": {
81
+ "anyswarm": "dist/scripts/anyswarm.js"
79
82
  }
80
83
  }
@@ -1,101 +1,138 @@
1
1
  import { parseArgs } from 'node:util';
2
2
 
3
3
  export const setupUsage = [
4
- 'Usage: anyswarm setup [--mode existing|local] [--endpoint <url>] [--public-url <url>] [--backend pi|codex] [--backend-path <executable>] [--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.',
4
+ 'Usage: anyswarm setup [--mode existing|local] [--endpoint <url>] [--public-url <url>] [--backend pi|codex] [--backend-path <executable>] [--backend-version <version>] [--config <module>]',
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 .mjs or ESM .js 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 [--help]',
24
- 'Usage: anyswarm --version',
25
- projectUsage, setupUsage, updateUsage, doctorUsage, recoverUsage,
26
- '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.',
27
39
  ].join('\n');
28
40
 
29
41
  export type LocalCommand =
30
- | { command: 'setup'; mode?: 'existing' | 'local'; endpoint?: string; publicUrl?: string; configPath?: string; backend?: 'pi' | 'codex'; backendPath?: string }
31
- | { command: 'doctor'; configPath?: string; smoke: boolean };
42
+ | { command: 'setup'; mode?: 'existing' | 'local'; endpoint?: string; publicUrl?: string; configPath?: string; backend?: 'pi' | 'codex'; backendPath?: string; backendVersion?: string }
43
+ | { command: 'doctor'; mode?: 'existing' | 'local'; configPath?: string; smoke: boolean };
32
44
 
33
- export type ProjectCommand = {
34
- command: 'harness';
45
+ type HarnessOptions = {
35
46
  harness: string;
36
47
  configPath?: string;
37
48
  outputRoot?: string;
38
49
  lifetime?: 'task' | 'interactive';
39
50
  interaction?: 'none' | 'questions';
40
- } & ({ mode: 'foreground'; cwd?: string; prompt: string } | { mode: 'rpc' });
51
+ };
41
52
 
42
- type AnySwarmCommand = LocalCommand | { command: 'update'; archive?: string; sha256?: string } | ProjectCommand | { command: 'recover'; directory: string; configPath: string };
53
+ export type ProjectCommand = HarnessOptions & { command: 'harness' } &
54
+ ({ mode: 'foreground'; cwd?: string; prompt: string } | { mode: 'rpc' });
55
+
56
+ type AnySwarmCommand = { command: 'run'; entryPath: string; args: string[] } |
57
+ { command: 'eject'; application: string; directory: string } | LocalCommand |
58
+ { command: 'update' } | ProjectCommand | { command: 'recover'; directory: string; configPath: string };
59
+
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' },
65
+ lifetime: { type: 'string' }, interaction: { type: 'string' },
66
+ } });
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('') ||
70
+ (lifetime !== undefined && lifetime !== 'task' && lifetime !== 'interactive') ||
71
+ (interaction !== undefined && interaction !== 'none' && interaction !== 'questions')) throw new Error();
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();
79
+ }
80
+
81
+ export function parseSourceHarnessCommand(args: string[], entry: string) {
82
+ try { return parseProjectCommand(args, entry); }
83
+ catch { throw new Error(runUsage); }
84
+ }
43
85
 
44
86
  export function parseAnySwarmCommand(args: string[]): AnySwarmCommand | { help: string } {
45
87
  const [command, ...options] = args;
46
- if (command === undefined) return { help: anyswarmUsage };
47
- if (command === '--help' && options.length === 0) return { help: anyswarmUsage };
48
- const usages = { setup: setupUsage, update: updateUsage, doctor: doctorUsage, recover: recoverUsage };
49
- const usage = Object.hasOwn(usages, command) ? usages[command as keyof typeof usages] : anyswarmUsage;
50
- if (options.length === 1 && options[0] === '--help' && usage !== anyswarmUsage) return { help: usage };
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;
94
+ if (options.length === 1 && options[0] === '--help' && Object.hasOwn(usages, command)) return { help: usage };
51
95
  try {
52
- if (command.startsWith('--')) {
53
- const { values } = parseArgs({ args, options: {
54
- harness: { type: 'string' }, prompt: { type: 'string' }, cwd: { type: 'string' },
55
- mode: { type: 'string' }, config: { type: 'string' }, 'output-dir': { type: 'string' },
56
- lifetime: { type: 'string' }, interaction: { type: 'string' },
57
- } });
58
- if (!values.harness || values.config === '' || values['output-dir'] === '') throw new Error();
59
- const { lifetime, interaction } = values;
60
- if ((lifetime !== undefined && lifetime !== 'task' && lifetime !== 'interactive') ||
61
- (interaction !== undefined && interaction !== 'none' && interaction !== 'questions')) throw new Error();
62
- const project = { command: 'harness' as const, harness: values.harness, configPath: values.config,
63
- outputRoot: values['output-dir'],
64
- lifetime: lifetime as ProjectCommand['lifetime'], interaction: interaction as ProjectCommand['interaction'] };
65
- if (values.mode === 'rpc' && values.prompt === undefined && values.cwd === undefined) return { ...project, mode: 'rpc' };
66
- if (values.mode === undefined && values.prompt?.trim() && values.cwd !== '') {
67
- return { ...project, mode: 'foreground', cwd: values.cwd, prompt: values.prompt };
96
+ if (command === 'run') {
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) };
99
+ }
100
+ if (command === 'eject') {
101
+ const { values, positionals } = parseArgs({ args: options, allowPositionals: true, options: { dir: { type: 'string' } } });
102
+ if (positionals.length === 1 && /^[a-z0-9][a-z0-9_.-]*$/i.test(positionals[0]) && values.dir) {
103
+ return { command, application: positionals[0], directory: values.dir };
68
104
  }
105
+ throw new Error();
69
106
  }
107
+ if (command.startsWith('--')) return parseProjectCommand(args);
70
108
  if (command === 'setup') {
71
109
  const { values } = parseArgs({ args: options, options: {
72
110
  mode: { type: 'string' }, endpoint: { type: 'string' }, 'public-url': { type: 'string' }, config: { type: 'string' },
73
- backend: { type: 'string' }, 'backend-path': { type: 'string' },
111
+ backend: { type: 'string' }, 'backend-path': { type: 'string' }, 'backend-version': { type: 'string' },
74
112
  } });
75
113
  const { backend, mode } = values;
76
114
  if (values.config !== '' && values.endpoint !== '' && values['public-url'] !== '' &&
77
115
  (mode === undefined || mode === 'existing' || mode === 'local') &&
78
116
  (backend === undefined || backend === 'pi' || backend === 'codex') &&
79
- (values['backend-path'] === undefined || (backend && values['backend-path']))) {
117
+ (values['backend-path'] === undefined || (backend && values['backend-path'])) &&
118
+ (values['backend-version'] === undefined || (backend && values['backend-version']))) {
80
119
  return { command, mode, endpoint: values.endpoint, publicUrl: values['public-url'], configPath: values.config,
81
- backend, backendPath: values['backend-path'] };
82
- }
83
- }
84
- if (command === 'update') {
85
- const { values } = parseArgs({ args: options, options: { archive: { type: 'string' }, sha256: { type: 'string' } } });
86
- if (options.length === 0 || (values.archive && /^[a-f0-9]{64}$/i.test(values.sha256 ?? ''))) {
87
- return { command, archive: values.archive, sha256: values.sha256?.toLowerCase() };
120
+ backend, backendPath: values['backend-path'], backendVersion: values['backend-version'] };
88
121
  }
89
122
  }
123
+ if (command === 'update' && options.length === 0) return { command };
90
124
  if (command === 'recover') {
91
125
  const { values } = parseArgs({ args: options, options: { 'run-dir': { type: 'string' }, config: { type: 'string' } } });
92
126
  if (values['run-dir'] && values.config) return { command, directory: values['run-dir'], configPath: values.config };
93
127
  }
94
128
  if (command === 'doctor') {
95
129
  const { values } = parseArgs({
96
- args: options, options: { config: { type: 'string' }, smoke: { type: 'boolean' } },
130
+ args: options, options: { config: { type: 'string' }, smoke: { type: 'boolean' }, mode: { type: 'string' } },
97
131
  });
98
- 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
+ }
99
136
  }
100
137
  } catch {
101
138
  // Argument errors can contain untrusted input. Print only the command usage.
@@ -0,0 +1,25 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { realpath } from 'node:fs/promises';
3
+ import { resolve } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ export async function runSourceCommand(command: { entryPath: string; args: readonly string[] }, cwd: string): Promise<number> {
7
+ const entry = await realpath(resolve(cwd, command.entryPath));
8
+ const runner = fileURLToPath(new URL('./anyswarm-source-runner.js', import.meta.url));
9
+ const child = spawn(process.execPath, ['--enable-source-maps', runner, entry, ...command.args], { cwd, stdio: 'inherit' });
10
+ const interrupt = () => { child.kill('SIGINT'); };
11
+ const terminate = () => { child.kill('SIGTERM'); };
12
+ process.on('SIGINT', interrupt);
13
+ process.on('SIGTERM', terminate);
14
+ try {
15
+ return await new Promise<number>((done, reject) => {
16
+ child.once('error', reject);
17
+ child.once('exit', (code, signal) => done(code ?? (signal === 'SIGINT' ? 130 : signal === 'SIGTERM' ? 143 : 1)));
18
+ });
19
+ } finally {
20
+ process.off('SIGINT', interrupt);
21
+ process.off('SIGTERM', terminate);
22
+ }
23
+ }
24
+
25
+ export { ejectSourceCommand } from './anyswarm-eject.js';
@@ -0,0 +1,145 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { readFileSync } from 'node:fs';
4
+ import { cp, lstat, mkdir, mkdtemp, readFile, readdir, rename, rm, rmdir, writeFile } from 'node:fs/promises';
5
+ import { findPackageJSON } from 'node:module';
6
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
7
+ import { fileURLToPath } from 'node:url';
8
+ import { promisify } from 'node:util';
9
+
10
+ const execute = promisify(execFile);
11
+ const packageRoot = fileURLToPath(new URL('../..', import.meta.url));
12
+ const forbidden = /(?:^|\/)(?:\.env(?:\..*)?|node_modules|dist|runs?|experiments|\.git|\.anyswarm(?:-sdk)?)(?:\/|$)|\.(?:db|sqlite|sqlite3|log|ndjson|pem|key)$/i;
13
+ const reserved = new Set(['package.json', 'anyswarm-source.json']);
14
+ const packageSpecifier = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9_.-]+$/;
15
+
16
+ function digestFiles(directory: string, files: readonly string[]) {
17
+ const hash = createHash('sha256');
18
+ for (const file of [...files].sort((left, right) => left.localeCompare(right, 'en'))) {
19
+ const data = readFileSync(join(directory, file));
20
+ hash.update(file).update('\0').update(String(data.length)).update('\0').update(data);
21
+ }
22
+ return hash.digest('hex');
23
+ }
24
+
25
+ async function installationSource() {
26
+ const lock = await readFile(resolve(packageRoot, '../../.package-lock.json'), 'utf8').then(JSON.parse).catch(() => undefined);
27
+ const installed = lock?.packages?.['node_modules/@anyswarm/core'];
28
+ return { source: typeof installed?.resolved === 'string' ? installed.resolved : 'installed-package-content',
29
+ integrity: typeof installed?.integrity === 'string' ? installed.integrity : null };
30
+ }
31
+
32
+ /** Export an application's explicit source allowlist and its installed SDK identity. */
33
+ export async function ejectSourceCommand(command: { application: string; directory: string }, cwd: string) {
34
+ if (!/^[a-z0-9][a-z0-9_.-]*$/i.test(command.application)) throw new TypeError('Expected a bundled application name');
35
+ const application = command.application === 'example' ? 'authoring' : command.application;
36
+ const sourceRoot = join(packageRoot, 'examples', application);
37
+ const manifest = await readFile(join(sourceRoot, 'eject.json'), 'utf8').then(JSON.parse).catch(error => {
38
+ if (error.code === 'ENOENT') throw new Error(`The ${command.application} application has no source export in this package. Install a package containing its application manifest.`);
39
+ throw error;
40
+ });
41
+ if (manifest.apiVersion !== 1 || typeof manifest.entry !== 'string' ||
42
+ !/^(?:[\w.-]+\/)*[\w.-]+\.(?:ts|mts)$/.test(manifest.entry) ||
43
+ !Array.isArray(manifest.files) || !manifest.files.includes(manifest.entry)) {
44
+ throw new TypeError('Application source manifest requires apiVersion 1, an entry, and an explicit files list containing the entry');
45
+ }
46
+ const dependencies: unknown = manifest.dependencies ?? {};
47
+ if (!dependencies || typeof dependencies !== 'object' || Array.isArray(dependencies) ||
48
+ Object.entries(dependencies).some(([name, version]) =>
49
+ name === '@anyswarm/core' || !packageSpecifier.test(name) || typeof version !== 'string' || !version.trim())) {
50
+ throw new TypeError('Application source dependencies must be package specs. The SDK source is supplied by eject.');
51
+ }
52
+ const target = resolve(cwd, command.directory);
53
+ const targetInfo = await lstat(target).catch(error => { if (error.code === 'ENOENT') return null; throw error; });
54
+ if (targetInfo && (!targetInfo.isDirectory() || (await readdir(target)).length)) throw new Error('The export target must be an empty directory');
55
+ await mkdir(dirname(target), { recursive: true });
56
+ const staging = await mkdtemp(join(dirname(target), `.${basename(target)}-eject-`));
57
+ try {
58
+ for (const file of manifest.files) {
59
+ if (typeof file !== 'string' || !file || isAbsolute(file) || file.includes('\\') || file.split('/').some(part => part === '..' || part === '.' || !part) || reserved.has(file) || forbidden.test(file)) {
60
+ throw new TypeError('Application source manifest contains an unsafe or private path');
61
+ }
62
+ const source = join(sourceRoot, file);
63
+ const info = await lstat(source);
64
+ if (!info.isFile() || info.isSymbolicLink()) throw new TypeError('Application source exports must be regular files');
65
+ // Each parent must also be a directory rather than a symlink to private state.
66
+ let parent = dirname(source);
67
+ while (parent !== sourceRoot) {
68
+ if ((await lstat(parent)).isSymbolicLink()) throw new TypeError('Application source exports cannot traverse symlinks');
69
+ parent = dirname(parent);
70
+ }
71
+ await mkdir(dirname(join(staging, file)), { recursive: true });
72
+ await cp(source, join(staging, file), { errorOnExist: true, force: false });
73
+ }
74
+ const sdkDirectory = join(staging, '.anyswarm-sdk');
75
+ await mkdir(sdkDirectory);
76
+ const packed = await execute('npm', ['pack', '--ignore-scripts', '--json', '--pack-destination', sdkDirectory], {
77
+ cwd: packageRoot, timeout: 60_000, maxBuffer: 4 * 1024 * 1024,
78
+ });
79
+ const packedPackage = JSON.parse(packed.stdout)[0];
80
+ if (packedPackage.files.some((file: { path: string }) => file.path !== '.env.example' &&
81
+ /(?:^|\/)(?:\.env(?:\..*)?|runs|experiments|[^/]+-runs)(?:\/|$)|\.(?:db|sqlite|sqlite3|pem|key|ndjson|jsonl)$/i.test(file.path))) {
82
+ throw new Error('The installed SDK package contains private or runtime files and cannot be exported');
83
+ }
84
+ const archive = join(sdkDirectory, packedPackage.filename);
85
+ const archiveSha256 = createHash('sha256').update(await readFile(archive)).digest('hex');
86
+ await rename(archive, join(sdkDirectory, 'core.tgz'));
87
+ const sdk = JSON.parse(await readFile(join(packageRoot, 'package.json'), 'utf8'));
88
+ const source = await readFile(join(packageRoot, 'dist/scripts/build-provenance.json'), 'utf8').then(JSON.parse).catch(() => null);
89
+ const files: string[] = packedPackage.files.map((file: { path: string }) => file.path);
90
+ const provenance = { schema: 2, application: command.application, source,
91
+ sdk: { name: sdk.name, version: sdk.version, ...await installationSource(),
92
+ archiveSha256, content: { sha256: digestFiles(packageRoot, files), files } } };
93
+ await writeFile(join(staging, 'anyswarm-source.json'), JSON.stringify(provenance, null, 2) + '\n');
94
+ await writeFile(join(staging, 'package.json'), JSON.stringify({ name: `anyswarm-${command.application}-source`, private: true,
95
+ scripts: { start: `anyswarm run ./${manifest.entry}` }, dependencies: { ...dependencies, '@anyswarm/core': 'file:./.anyswarm-sdk/core.tgz' },
96
+ }, null, 2) + '\n');
97
+ if (targetInfo) await rmdir(target);
98
+ await rename(staging, target);
99
+ return { directory: target, entryPath: join(target, manifest.entry), provenancePath: join(target, 'anyswarm-source.json') };
100
+ } finally {
101
+ await rm(staging, { recursive: true, force: true });
102
+ }
103
+ }
104
+
105
+ /** Verify the executing host and return a guard for SDK resolutions inside a source export. */
106
+ export async function verifyExportedSdk(entry: string) {
107
+ let directory = dirname(entry);
108
+ for (;;) {
109
+ const manifest = await readFile(join(directory, 'anyswarm-source.json'), 'utf8').then(JSON.parse).catch(error => {
110
+ if (error.code === 'ENOENT') return undefined;
111
+ throw error;
112
+ });
113
+ if (manifest) {
114
+ const content = manifest.schema === 1 ? { sha256: manifest.sdk?.contentSha256, files: manifest.sdk?.files } :
115
+ manifest.schema === 2 ? manifest.sdk?.content : undefined;
116
+ const files = content?.files;
117
+ if (typeof content?.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(content.sha256) ||
118
+ !Array.isArray(files) || !files.length || files.some(file => typeof file !== 'string' || !file || isAbsolute(file) ||
119
+ file.includes('\\') || file.split('/').some(part => !part || part === '.' || part === '..'))) {
120
+ throw new Error('Invalid exported SDK provenance');
121
+ }
122
+ const mismatch = () => new Error('The source export requires its recorded SDK candidate. Run npm install in the exported directory and start it with npm run start.');
123
+ const checked = new Set<string>();
124
+ const verifyRoot = (root: string) => {
125
+ if (checked.has(root)) return;
126
+ let digest: string;
127
+ try { digest = digestFiles(root, files); } catch { throw mismatch(); }
128
+ if (digest !== content.sha256) throw mismatch();
129
+ checked.add(root);
130
+ };
131
+ verifyRoot(resolve(packageRoot));
132
+ return (url: string) => {
133
+ let manifestPath: string | undefined;
134
+ try { if (url.startsWith('file:')) manifestPath = findPackageJSON(url); } catch { throw mismatch(); }
135
+ if (!manifestPath) throw mismatch();
136
+ const root = dirname(manifestPath);
137
+ if (!files.includes(relative(root, fileURLToPath(url)).split(sep).join('/'))) throw mismatch();
138
+ verifyRoot(root);
139
+ };
140
+ }
141
+ const parent = dirname(directory);
142
+ if (parent === directory) return;
143
+ directory = parent;
144
+ }
145
+ }
@@ -0,0 +1,10 @@
1
+ export const builtins: Record<string, string> = {
2
+ autoresearch: new URL('../examples/autoresearch/project.js', import.meta.url).href,
3
+ 'lead-worker': new URL('../examples/lead-worker/project.js', import.meta.url).href,
4
+ peermesh: new URL('../examples/peermesh/project.js', import.meta.url).href,
5
+ notes: new URL('../examples/notes/project.js', import.meta.url).href,
6
+ messages: new URL('../examples/messages/project.js', import.meta.url).href,
7
+ taskpool: new URL('../examples/taskpool/project.js', import.meta.url).href,
8
+ substrate: new URL('../examples/substrate/project.js', import.meta.url).href,
9
+ subagents: new URL('../examples/subagents/project.js', import.meta.url).href,
10
+ };