@anyswarm/core 0.5.0 → 0.5.1

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 (398) hide show
  1. package/README.md +11 -10
  2. package/deploy/worker/Dockerfile +12 -4
  3. package/dist/deploy/worker/Dockerfile +12 -4
  4. package/dist/examples/README.md +24 -12
  5. package/dist/examples/authoring/README.md +24 -0
  6. package/dist/examples/authoring/business.d.ts +2 -0
  7. package/dist/examples/authoring/business.js +4 -0
  8. package/dist/examples/authoring/config.d.ts +5 -0
  9. package/dist/examples/authoring/config.js +2 -0
  10. package/dist/examples/authoring/eject.json +5 -0
  11. package/dist/examples/authoring/harness.d.ts +4 -0
  12. package/dist/examples/authoring/harness.js +19 -0
  13. package/dist/examples/autoresearch/README.md +33 -0
  14. package/dist/examples/autoresearch/REQUIREMENTS.zh.md +18 -0
  15. package/dist/examples/autoresearch/config.d.ts +51 -0
  16. package/dist/examples/autoresearch/config.js +57 -0
  17. package/dist/examples/autoresearch/demo.d.ts +11 -0
  18. package/dist/examples/autoresearch/demo.js +52 -0
  19. package/dist/examples/autoresearch/eject.json +15 -0
  20. package/dist/examples/autoresearch/frontiercs2.d.ts +87 -0
  21. package/dist/examples/autoresearch/frontiercs2.js +211 -0
  22. package/dist/examples/autoresearch/prepare.d.ts +95 -0
  23. package/dist/examples/autoresearch/prepare.js +257 -0
  24. package/dist/examples/autoresearch/process.d.ts +13 -0
  25. package/dist/examples/autoresearch/process.js +48 -0
  26. package/dist/examples/autoresearch/project.d.ts +115 -0
  27. package/dist/examples/autoresearch/project.js +410 -0
  28. package/dist/examples/autoresearch/research-service.d.ts +106 -0
  29. package/dist/examples/autoresearch/research-service.js +255 -0
  30. package/dist/examples/code/README.md +25 -0
  31. package/dist/examples/code/REQUIREMENTS.zh.md +11 -0
  32. package/dist/examples/code/candidate.d.ts +19 -0
  33. package/dist/examples/code/candidate.js +80 -0
  34. package/dist/examples/code/config.d.ts +32 -0
  35. package/dist/examples/code/config.js +18 -0
  36. package/dist/examples/code/eject.json +5 -0
  37. package/dist/examples/code/project.d.ts +3 -0
  38. package/dist/examples/code/project.js +605 -0
  39. package/dist/examples/code/prompts.d.ts +5 -0
  40. package/dist/examples/code/prompts.js +12 -0
  41. package/dist/examples/code/verification.d.ts +19 -0
  42. package/dist/examples/code/verification.js +268 -0
  43. package/dist/examples/code/worktree.d.ts +17 -0
  44. package/dist/examples/code/worktree.js +233 -0
  45. package/dist/examples/harness-session/README.md +3 -6
  46. package/dist/examples/lead-worker/harness/dynamic-scheduler.d.ts +2 -1
  47. package/dist/examples/lead-worker/harness/dynamic-scheduler.js +5 -2
  48. package/dist/examples/lead-worker/harness/index.d.ts +60 -0
  49. package/dist/examples/lead-worker/harness/index.js +77 -6
  50. package/dist/examples/lead-worker/project.js +2 -2
  51. package/dist/examples/lead-worker/services/board.d.ts +5 -0
  52. package/dist/examples/lead-worker/services/board.js +19 -1
  53. package/dist/examples/messages/README.md +5 -5
  54. package/dist/examples/messages/handoff.d.ts +2 -0
  55. package/dist/examples/messages/handoff.js +5 -1
  56. package/dist/examples/messages/project.js +52 -2
  57. package/dist/examples/notes/README.md +13 -18
  58. package/dist/examples/notes/project.js +67 -6
  59. package/dist/examples/peermesh/harness/router.js +3 -1
  60. package/dist/examples/peermesh/harness/team.d.ts +8 -0
  61. package/dist/examples/peermesh/harness/team.js +13 -0
  62. package/dist/examples/peermesh/project.js +22 -4
  63. package/dist/examples/services/agent-control/README.md +3 -3
  64. package/dist/examples/services/mathlib-search/Dockerfile +4 -2
  65. package/dist/examples/services/mathlib-search/README.md +1 -1
  66. package/dist/examples/services/mcp-managed/README.md +2 -2
  67. package/dist/examples/services/persistent-board/README.md +13 -3
  68. package/dist/examples/services/persistent-board/business.d.ts +7 -0
  69. package/dist/examples/services/persistent-board/business.js +7 -0
  70. package/dist/examples/services/persistent-board/index.js +10 -0
  71. package/dist/examples/services/persistent-board/live.d.ts +3 -0
  72. package/dist/examples/services/persistent-board/live.js +58 -0
  73. package/dist/examples/subagents/README.md +5 -5
  74. package/dist/examples/subagents/business.js +3 -1
  75. package/dist/examples/subagents/harness/controller.d.ts +15 -0
  76. package/dist/examples/subagents/harness/controller.js +181 -32
  77. package/dist/examples/subagents/project.d.ts +2 -0
  78. package/dist/examples/subagents/project.js +43 -34
  79. package/dist/examples/subagents/prompts/prompts.d.ts +1 -0
  80. package/dist/examples/subagents/prompts/prompts.js +3 -0
  81. package/dist/examples/subagents/services/collaboration-service.d.ts +3 -2
  82. package/dist/examples/subagents/services/collaboration-service.js +14 -2
  83. package/dist/examples/substrate/README.md +2 -2
  84. package/dist/examples/substrate/harness/index.d.ts +1 -1
  85. package/dist/examples/substrate/harness/index.js +77 -12
  86. package/dist/examples/substrate/project.js +4 -1
  87. package/dist/examples/super/README.md +40 -0
  88. package/dist/examples/super/actions.d.ts +95 -0
  89. package/dist/examples/super/actions.js +230 -0
  90. package/dist/examples/super/artifact.d.ts +4 -0
  91. package/dist/examples/super/artifact.js +51 -0
  92. package/dist/examples/super/config.d.ts +80 -0
  93. package/dist/examples/super/config.js +83 -0
  94. package/dist/examples/super/coordinator.d.ts +33 -0
  95. package/dist/examples/super/coordinator.js +151 -0
  96. package/dist/examples/super/daemon.d.ts +11 -0
  97. package/dist/examples/super/daemon.js +109 -0
  98. package/dist/examples/super/decisions.d.ts +8 -0
  99. package/dist/examples/super/decisions.js +52 -0
  100. package/dist/examples/super/eject.json +5 -0
  101. package/dist/examples/super/execution.d.ts +11 -0
  102. package/dist/examples/super/execution.js +136 -0
  103. package/dist/examples/super/github.d.ts +62 -0
  104. package/dist/examples/super/github.js +269 -0
  105. package/dist/examples/super/inbox.d.ts +162 -0
  106. package/dist/examples/super/inbox.js +284 -0
  107. package/dist/examples/super/location.d.ts +5 -0
  108. package/dist/examples/super/location.js +64 -0
  109. package/dist/examples/super/outbox.d.ts +5 -0
  110. package/dist/examples/super/outbox.js +103 -0
  111. package/dist/examples/super/project.d.ts +111 -0
  112. package/dist/examples/super/project.js +253 -0
  113. package/dist/examples/super/prompts.d.ts +3 -0
  114. package/dist/examples/super/prompts.js +25 -0
  115. package/dist/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
  116. package/dist/examples/taskpool/harness/controller.d.ts +35 -6
  117. package/dist/examples/taskpool/harness/controller.js +73 -7
  118. package/dist/examples/taskpool/project.js +18 -2
  119. package/dist/scripts/anyswarm-applications.d.ts +19 -0
  120. package/dist/scripts/anyswarm-applications.js +19 -0
  121. package/dist/scripts/anyswarm-arguments.d.ts +35 -5
  122. package/dist/scripts/anyswarm-arguments.js +87 -23
  123. package/dist/scripts/anyswarm-author.d.ts +5 -0
  124. package/dist/scripts/anyswarm-author.js +24 -0
  125. package/dist/scripts/anyswarm-eject.d.ts +11 -0
  126. package/dist/scripts/anyswarm-eject.js +164 -0
  127. package/dist/scripts/anyswarm-harnesses.d.ts +2 -0
  128. package/dist/scripts/anyswarm-harnesses.js +31 -0
  129. package/dist/scripts/anyswarm-installation.js +19 -13
  130. package/dist/scripts/anyswarm-launch.d.ts +37 -0
  131. package/dist/scripts/anyswarm-launch.js +86 -0
  132. package/dist/scripts/anyswarm-project.d.ts +12 -2
  133. package/dist/scripts/anyswarm-project.js +121 -20
  134. package/dist/scripts/anyswarm-source-runner.d.ts +1 -0
  135. package/dist/scripts/anyswarm-source-runner.js +232 -0
  136. package/dist/scripts/anyswarm-tui-config.d.ts +36 -0
  137. package/dist/scripts/anyswarm-tui-config.js +189 -0
  138. package/dist/scripts/anyswarm-tui-session.d.ts +66 -0
  139. package/dist/scripts/anyswarm-tui-session.js +304 -0
  140. package/dist/scripts/anyswarm-tui-terminal.d.ts +41 -0
  141. package/dist/scripts/anyswarm-tui-terminal.js +154 -0
  142. package/dist/scripts/anyswarm-tui.d.ts +2 -0
  143. package/dist/scripts/anyswarm-tui.js +1012 -0
  144. package/dist/scripts/anyswarm.js +47 -2
  145. package/dist/scripts/build-provenance.json +1 -0
  146. package/dist/scripts/build.js +7 -1
  147. package/dist/scripts/generate-architecture-api.js +2 -0
  148. package/dist/scripts/generate-architecture-prompts.js +24 -2
  149. package/dist/scripts/local-environment.d.ts +6 -1
  150. package/dist/scripts/local-environment.js +52 -16
  151. package/dist/scripts/local-setup-smoke.js +3 -2
  152. package/dist/scripts/local-setup-worker.d.ts +1 -1
  153. package/dist/scripts/local-setup-worker.js +15 -6
  154. package/dist/scripts/local-setup.d.ts +2 -2
  155. package/dist/scripts/local-setup.js +72 -12
  156. package/dist/scripts/opensandbox-agent-worker.js +2 -2
  157. package/dist/scripts/pack-release.d.ts +1 -0
  158. package/dist/scripts/pack-release.js +63 -0
  159. package/dist/scripts/pi-session-bridge.js +11 -3
  160. package/dist/scripts/run-harness.js +3 -1
  161. package/dist/scripts/setup-bootstrap.js +43 -6
  162. package/dist/src/core/allocation-ledger.js +4 -3
  163. package/dist/src/core/host-identity.d.ts +2 -0
  164. package/dist/src/core/host-identity.js +11 -0
  165. package/dist/src/core/index.d.ts +4 -2
  166. package/dist/src/core/index.js +12 -4
  167. package/dist/src/core/mcp-service.js +2 -2
  168. package/dist/src/core/runtime-management.d.ts +6 -0
  169. package/dist/src/core/runtime-management.js +24 -0
  170. package/dist/src/core/sandbox/executor-driver.d.ts +4 -2
  171. package/dist/src/core/sandbox/executor-driver.js +12 -14
  172. package/dist/src/core/sandbox/local-executor.d.ts +13 -1
  173. package/dist/src/core/sandbox/local-executor.js +69 -19
  174. package/dist/src/core/sandbox/local-worker.js +32 -21
  175. package/dist/src/core/sandbox/opensandbox-backend.d.ts +2 -0
  176. package/dist/src/core/sandbox/opensandbox-backend.js +36 -11
  177. package/dist/src/core/sandbox/sandbox-connection.d.ts +2 -0
  178. package/dist/src/core/sandbox/sandbox-connection.js +14 -6
  179. package/dist/src/core/service-live-state.d.ts +14 -0
  180. package/dist/src/core/service-live-state.js +161 -0
  181. package/dist/src/core/service-observation-types.d.ts +21 -1
  182. package/dist/src/core/service-process.d.ts +1 -1
  183. package/dist/src/core/service-process.js +45 -4
  184. package/dist/src/core/service-types.d.ts +5 -1
  185. package/dist/src/core/services.d.ts +1 -1
  186. package/dist/src/core/services.js +8 -3
  187. package/dist/src/core/types.d.ts +3 -0
  188. package/dist/src/core/worker-image.js +3 -3
  189. package/dist/src/harness/harness-session-types.d.ts +10 -0
  190. package/dist/src/harness/harness-session.js +42 -5
  191. package/dist/src/harness/project-harness.d.ts +13 -1
  192. package/dist/src/harness/project-harness.js +36 -10
  193. package/dist/src/harness/project-input.js +81 -15
  194. package/dist/src/harness/project-rpc-client.d.ts +1 -0
  195. package/dist/src/harness/project-rpc-client.js +5 -0
  196. package/dist/src/harness/project-rpc.d.ts +8 -2
  197. package/dist/src/harness/project-rpc.js +31 -7
  198. package/dist/src/harness/project-runtime.js +3 -1
  199. package/dist/src/harness/typescript-loader.d.ts +2 -0
  200. package/dist/src/harness/typescript-loader.js +41 -0
  201. package/dist/src/trace-viewer/public/app.js +6 -5
  202. package/dist/src/trace-viewer/reader.mjs +42 -2
  203. package/docs/INDEX.md +3 -1
  204. package/docs/architecture/00-overview.md +1 -1
  205. package/docs/architecture/01-agent-core.md +1 -1
  206. package/docs/architecture/06-observability-experiments.md +1 -1
  207. package/docs/architecture/07-run-configuration.md +18 -12
  208. package/docs/architecture/08-prompts.md +22 -0
  209. package/docs/architecture/10-service-api-reference.md +53 -18
  210. package/docs/architecture/11-storage-reference.md +18 -1
  211. package/docs/architecture/12-code-coverage.md +148 -84
  212. package/docs/architecture/15-core-runtime.md +8 -0
  213. package/docs/architecture/16-pi-opensandbox-backend.md +5 -5
  214. package/docs/architecture/17-harness-reporting.md +1 -1
  215. package/docs/architecture/19-substrate-harness.md +28 -1
  216. package/docs/architecture/20-lead-worker-harness.md +34 -1
  217. package/docs/architecture/22-website.md +5 -3
  218. package/docs/architecture/23-project-harness.md +124 -5
  219. package/docs/architecture/24-runtime-recovery.md +10 -3
  220. package/docs/architecture/25-foreground-tui.md +51 -0
  221. package/docs/architecture/26-code.md +39 -0
  222. package/docs/architecture/27-personal.md +43 -0
  223. package/docs/architecture/28-autoresearch.md +31 -0
  224. package/docs/architecture/INDEX.md +4 -0
  225. package/docs/architecture/prompts/08-lead-worker-harness.md +4 -2
  226. package/docs/architecture/prompts/08-subagents-harness.md +21 -0
  227. package/docs/architecture/prompts/21-personal.md +44 -0
  228. package/docs/architecture/prompts/22-autoresearch.md +63 -0
  229. package/docs/architecture/prompts/26-code.md +55 -0
  230. package/docs/architecture/prompts/source-manifest.json +152 -33
  231. package/docs/architecture/source-map.json +489 -21
  232. package/docs/designs/core-harness/06-project-harness.md +13 -2
  233. package/docs/designs/core-harness/README.md +5 -0
  234. package/docs/en/agents.md +1 -1
  235. package/docs/en/build-your-harness.md +3 -5
  236. package/docs/en/changelog.md +13 -4
  237. package/docs/en/first-harness.md +8 -11
  238. package/docs/en/harnesses/lead-worker.md +1 -1
  239. package/docs/en/harnesses/peermesh.md +2 -2
  240. package/docs/en/harnesses/subagents.md +2 -2
  241. package/docs/en/harnesses/substrate.md +4 -4
  242. package/docs/en/harnesses/taskpool.md +2 -2
  243. package/docs/en/latest.md +12 -123
  244. package/docs/en/overview.md +1 -1
  245. package/docs/en/quickstart.md +40 -16
  246. package/docs/en/reference/api.md +14 -4
  247. package/docs/en/reference/cli.md +58 -14
  248. package/docs/en/runtime.md +2 -2
  249. package/docs/en/services.md +4 -0
  250. package/docs/third-party-notices.md +1 -0
  251. package/docs/workflows/development.md +17 -12
  252. package/docs/workflows/release-and-docs-versioning.md +76 -0
  253. package/docs/zh/agents.md +1 -1
  254. package/docs/zh/build-your-harness.md +3 -5
  255. package/docs/zh/changelog.md +13 -4
  256. package/docs/zh/first-harness.md +8 -11
  257. package/docs/zh/harnesses/lead-worker.md +1 -1
  258. package/docs/zh/harnesses/peermesh.md +2 -2
  259. package/docs/zh/harnesses/subagents.md +2 -2
  260. package/docs/zh/harnesses/substrate.md +4 -4
  261. package/docs/zh/harnesses/taskpool.md +2 -2
  262. package/docs/zh/latest.md +13 -124
  263. package/docs/zh/overview.md +1 -1
  264. package/docs/zh/quickstart.md +40 -16
  265. package/docs/zh/reference/api.md +14 -4
  266. package/docs/zh/reference/cli.md +58 -14
  267. package/docs/zh/runtime.md +2 -2
  268. package/docs/zh/services.md +4 -0
  269. package/examples/README.md +24 -12
  270. package/examples/authoring/README.md +24 -0
  271. package/examples/authoring/business.ts +4 -0
  272. package/examples/authoring/config.ts +2 -0
  273. package/examples/authoring/eject.json +5 -0
  274. package/examples/authoring/harness.ts +21 -0
  275. package/examples/autoresearch/README.md +33 -0
  276. package/examples/autoresearch/REQUIREMENTS.zh.md +18 -0
  277. package/examples/autoresearch/config.ts +90 -0
  278. package/examples/autoresearch/demo.ts +55 -0
  279. package/examples/autoresearch/eject.json +15 -0
  280. package/examples/autoresearch/frontiercs2.ts +237 -0
  281. package/examples/autoresearch/prepare.ts +267 -0
  282. package/examples/autoresearch/process.ts +50 -0
  283. package/examples/autoresearch/project.ts +397 -0
  284. package/examples/autoresearch/research-service.ts +302 -0
  285. package/examples/code/README.md +25 -0
  286. package/examples/code/REQUIREMENTS.zh.md +11 -0
  287. package/examples/code/candidate.ts +89 -0
  288. package/examples/code/config.ts +19 -0
  289. package/examples/code/eject.json +5 -0
  290. package/examples/code/project.ts +581 -0
  291. package/examples/code/prompts.ts +16 -0
  292. package/examples/code/verification.ts +239 -0
  293. package/examples/code/worktree.ts +188 -0
  294. package/examples/harness-session/README.md +3 -6
  295. package/examples/lead-worker/harness/dynamic-scheduler.ts +6 -3
  296. package/examples/lead-worker/harness/index.ts +61 -6
  297. package/examples/lead-worker/project.ts +2 -2
  298. package/examples/lead-worker/services/board.ts +14 -1
  299. package/examples/messages/README.md +5 -5
  300. package/examples/messages/handoff.ts +6 -2
  301. package/examples/messages/project.ts +47 -2
  302. package/examples/notes/README.md +13 -18
  303. package/examples/notes/project.ts +57 -9
  304. package/examples/peermesh/harness/router.ts +2 -2
  305. package/examples/peermesh/harness/team.ts +11 -0
  306. package/examples/peermesh/project.ts +19 -4
  307. package/examples/services/agent-control/README.md +3 -3
  308. package/examples/services/mathlib-search/Dockerfile +4 -2
  309. package/examples/services/mathlib-search/README.md +1 -1
  310. package/examples/services/mcp-managed/README.md +2 -2
  311. package/examples/services/persistent-board/README.md +13 -3
  312. package/examples/services/persistent-board/business.ts +10 -0
  313. package/examples/services/persistent-board/index.ts +10 -0
  314. package/examples/services/persistent-board/live.ts +54 -0
  315. package/examples/subagents/README.md +5 -5
  316. package/examples/subagents/business.ts +3 -1
  317. package/examples/subagents/harness/controller.ts +161 -29
  318. package/examples/subagents/project.ts +47 -33
  319. package/examples/subagents/prompts/prompts.ts +4 -0
  320. package/examples/subagents/services/collaboration-service.ts +14 -2
  321. package/examples/substrate/README.md +2 -2
  322. package/examples/substrate/harness/index.ts +67 -11
  323. package/examples/substrate/project.ts +5 -1
  324. package/examples/super/README.md +40 -0
  325. package/examples/super/actions.ts +196 -0
  326. package/examples/super/artifact.ts +56 -0
  327. package/examples/super/config.ts +95 -0
  328. package/examples/super/coordinator.ts +158 -0
  329. package/examples/super/daemon.ts +84 -0
  330. package/examples/super/decisions.ts +46 -0
  331. package/examples/super/eject.json +5 -0
  332. package/examples/super/execution.ts +131 -0
  333. package/examples/super/github.ts +242 -0
  334. package/examples/super/inbox.ts +306 -0
  335. package/examples/super/location.ts +54 -0
  336. package/examples/super/outbox.ts +97 -0
  337. package/examples/super/project.ts +227 -0
  338. package/examples/super/prompts.ts +27 -0
  339. package/examples/taskpool/deploy/service-hosts/Dockerfile +4 -2
  340. package/examples/taskpool/harness/controller.ts +59 -7
  341. package/examples/taskpool/project.ts +18 -2
  342. package/npm-shrinkwrap.development.json +2199 -0
  343. package/npm-shrinkwrap.json +86 -1920
  344. package/package.development.json +92 -0
  345. package/package.json +13 -7
  346. package/scripts/anyswarm-applications.ts +39 -0
  347. package/scripts/anyswarm-arguments.ts +94 -28
  348. package/scripts/anyswarm-author.ts +25 -0
  349. package/scripts/anyswarm-eject.ts +145 -0
  350. package/scripts/anyswarm-harnesses.ts +27 -0
  351. package/scripts/anyswarm-installation.ts +19 -13
  352. package/scripts/anyswarm-launch.ts +108 -0
  353. package/scripts/anyswarm-project.ts +114 -21
  354. package/scripts/anyswarm-source-runner.ts +203 -0
  355. package/scripts/anyswarm-tui-config.ts +174 -0
  356. package/scripts/anyswarm-tui-session.ts +295 -0
  357. package/scripts/anyswarm-tui-terminal.ts +147 -0
  358. package/scripts/anyswarm-tui.ts +912 -0
  359. package/scripts/anyswarm.ts +43 -2
  360. package/scripts/build.ts +8 -1
  361. package/scripts/generate-architecture-api.ts +2 -0
  362. package/scripts/generate-architecture-prompts.ts +35 -2
  363. package/scripts/local-environment.ts +55 -17
  364. package/scripts/local-setup-smoke.ts +3 -2
  365. package/scripts/local-setup-worker.ts +17 -7
  366. package/scripts/local-setup.ts +66 -13
  367. package/scripts/opensandbox-agent-worker.ts +2 -2
  368. package/scripts/pack-release.ts +67 -0
  369. package/scripts/pi-session-bridge.ts +10 -2
  370. package/scripts/run-harness.ts +3 -1
  371. package/scripts/setup-bootstrap.ts +41 -6
  372. package/src/core/allocation-ledger.ts +5 -3
  373. package/src/core/host-identity.ts +11 -0
  374. package/src/core/index.ts +12 -6
  375. package/src/core/mcp-service.ts +2 -2
  376. package/src/core/runtime-management.ts +22 -0
  377. package/src/core/sandbox/executor-driver.ts +15 -18
  378. package/src/core/sandbox/local-executor.ts +65 -19
  379. package/src/core/sandbox/local-worker.ts +29 -21
  380. package/src/core/sandbox/opensandbox-backend.ts +36 -11
  381. package/src/core/sandbox/sandbox-connection.ts +14 -5
  382. package/src/core/service-live-state.ts +156 -0
  383. package/src/core/service-observation-types.ts +23 -1
  384. package/src/core/service-process.ts +36 -3
  385. package/src/core/service-types.ts +3 -1
  386. package/src/core/services.ts +8 -3
  387. package/src/core/types.ts +3 -0
  388. package/src/core/worker-image.ts +3 -3
  389. package/src/harness/harness-session-types.ts +13 -1
  390. package/src/harness/harness-session.ts +40 -7
  391. package/src/harness/project-harness.ts +36 -10
  392. package/src/harness/project-input.ts +73 -15
  393. package/src/harness/project-rpc-client.ts +5 -0
  394. package/src/harness/project-rpc.ts +29 -8
  395. package/src/harness/project-runtime.ts +2 -1
  396. package/src/harness/typescript-loader.ts +37 -0
  397. package/src/trace-viewer/public/app.js +6 -5
  398. package/src/trace-viewer/reader.mjs +42 -2
@@ -0,0 +1,86 @@
1
+ import { loadProjectHarnessModule } from '../src/harness/project-harness.js';
2
+ import { basename, isAbsolute, resolve } from 'node:path';
3
+ import { findApplication } from './anyswarm-applications.js';
4
+ import { builtins } from './anyswarm-harnesses.js';
5
+ export function actionRun(value) {
6
+ if (!value || typeof value !== 'object' || !('kind' in value) || value.kind !== 'start-run')
7
+ return;
8
+ const run = value;
9
+ if (typeof run.cwd !== 'string' || !run.cwd || typeof run.prompt !== 'string' || !run.prompt.trim()) {
10
+ throw new Error('A standalone action must supply a workspace and prompt to start a Run.');
11
+ }
12
+ return run;
13
+ }
14
+ export function actionReport(value) {
15
+ if (!value || typeof value !== 'object' || !('kind' in value) || value.kind !== 'action-report')
16
+ return;
17
+ if (!('result' in value) || !('exitCode' in value) || typeof value.exitCode !== 'number' ||
18
+ !Number.isSafeInteger(value.exitCode) || value.exitCode < 0 || value.exitCode > 125) {
19
+ throw new Error('An action report must supply a result and an exit code from 0 to 125.');
20
+ }
21
+ return { exitCode: value.exitCode, result: value.result };
22
+ }
23
+ export function configuredStopTimeout(configuration) {
24
+ const ms = configuration?.closeTimeoutMs ?? configuration?.cleanupTimeoutMs;
25
+ return typeof ms === 'number' && Number.isSafeInteger(ms) && ms > 0 ? Math.min(2_147_483_647, ms + 5000) : undefined;
26
+ }
27
+ export function requestedTraceRoot(value, runId) {
28
+ if (!runId || !value || typeof value !== 'object' || !('kind' in value) || value.kind !== 'trace.request' ||
29
+ !('runDirectory' in value) || typeof value.runDirectory !== 'string' || !isAbsolute(value.runDirectory) ||
30
+ basename(value.runDirectory) !== runId)
31
+ return;
32
+ return value.runDirectory;
33
+ }
34
+ export async function loadHarness(launchDirectory, specifier, options) {
35
+ const application = findApplication(specifier);
36
+ if (application && !application.available)
37
+ throw new Error(application.title + ' is not included in this SDK build.');
38
+ const { module, definition } = await loadProjectHarnessModule(launchDirectory, specifier, builtins, options);
39
+ const observe = typeof module.observe === 'function'
40
+ ? module.observe
41
+ : undefined;
42
+ const actions = new Map();
43
+ if (module.slashActions && typeof module.slashActions === 'object') {
44
+ for (const [name, handler] of Object.entries(module.slashActions)) {
45
+ if (!/^[a-z][\w-]*$/.test(name) || typeof handler !== 'function') {
46
+ throw new Error('Harness slashActions must map command names to functions.');
47
+ }
48
+ actions.set(name, handler);
49
+ }
50
+ }
51
+ const workspace = typeof module.resolveWorkspace === 'function'
52
+ ? module.resolveWorkspace
53
+ : undefined;
54
+ return { definition, observe, actions, workspace };
55
+ }
56
+ export function harnessLifetime(harness, requested, preferred) {
57
+ const supported = harness.lifetimes ?? ['task'];
58
+ const lifetime = requested ?? (preferred && supported.includes(preferred) ? preferred : supported[0]);
59
+ if (!supported.includes(lifetime))
60
+ throw new Error('This Harness does not support the requested lifetime.');
61
+ return lifetime;
62
+ }
63
+ export function splitInput(text) {
64
+ const end = text.search(/\s/);
65
+ return end < 0 ? [text, ''] : [text.slice(0, end), text.slice(end).trimStart()];
66
+ }
67
+ export function interactiveTerminal() {
68
+ return process.stdin.isTTY && process.stdout.isTTY && process.env.TERM !== 'dumb';
69
+ }
70
+ export async function runHarnessSelection(command, launchDirectory, options) {
71
+ if (command.mode === 'action') {
72
+ const { runHarnessAction } = await import('./anyswarm-project.js');
73
+ return runHarnessAction(command, launchDirectory, options);
74
+ }
75
+ const mode = command.mode === 'auto' ? (interactiveTerminal() ? 'tui' : 'headless') : command.mode;
76
+ if (mode === 'tui') {
77
+ const { runAnySwarmTui } = await import('./anyswarm-tui.js');
78
+ return runAnySwarmTui({ ...command, command: 'tui' }, launchDirectory);
79
+ }
80
+ const { runProjectCommand } = await import('./anyswarm-project.js');
81
+ const project = { ...command, command: 'harness', defaults: true };
82
+ if (mode === 'rpc')
83
+ return runProjectCommand({ ...project, mode }, launchDirectory, options);
84
+ return runProjectCommand({ ...project, mode, cwd: command.cwd && resolve(launchDirectory, command.cwd),
85
+ prompt: command.prompt ?? 'Run this Harness.' }, launchDirectory, options);
86
+ }
@@ -1,2 +1,12 @@
1
- import type { ProjectCommand } from './anyswarm-arguments.js';
2
- export declare function runProjectCommand(command: ProjectCommand, launchDirectory: string): Promise<number | undefined>;
1
+ import type { HarnessCommand, ProjectCommand } from './anyswarm-arguments.js';
2
+ import { loadHarness, type ActionRun } from './anyswarm-launch.js';
3
+ export declare function runProjectCommand(command: ProjectCommand, launchDirectory: string, options?: {
4
+ onSourceError?: (error: unknown) => void;
5
+ action?: {
6
+ run: ActionRun;
7
+ loaded: Awaited<ReturnType<typeof loadHarness>>;
8
+ };
9
+ }): Promise<number | undefined>;
10
+ export declare function runHarnessAction(command: Extract<HarnessCommand, {
11
+ mode: 'action';
12
+ }>, launchDirectory: string, options?: Parameters<typeof loadHarness>[2]): Promise<number | undefined>;
@@ -1,26 +1,25 @@
1
+ import { resolve } from 'node:path';
1
2
  import { frameworkErrorFields } from '../src/core/error-diagnostics.js';
2
3
  import { captureHarnessSnapshot, createHarnessSession, failureCode, getHarnessExitCode, loadProjectHarness, stopHarnessTransport } from '../src/harness/project-harness.js';
3
4
  import { resolveHarnessInput } from '../src/harness/project-input.js';
4
5
  import { runProjectRpc } from '../src/harness/project-rpc.js';
5
- const builtins = {
6
- 'lead-worker': new URL('../examples/lead-worker/project.js', import.meta.url).href,
7
- peermesh: new URL('../examples/peermesh/project.js', import.meta.url).href,
8
- notes: new URL('../examples/notes/project.js', import.meta.url).href,
9
- messages: new URL('../examples/messages/project.js', import.meta.url).href,
10
- taskpool: new URL('../examples/taskpool/project.js', import.meta.url).href,
11
- substrate: new URL('../examples/substrate/project.js', import.meta.url).href,
12
- subagents: new URL('../examples/subagents/project.js', import.meta.url).href,
13
- };
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';
14
10
  const MAX_QUEUED_OUTPUT_BYTES = 1_048_576;
15
11
  const MAX_OUTPUT_RECORD_BYTES = 8 * 1024 * 1024;
16
12
  const OUTPUT_FLUSH_TIMEOUT_MS = 5_000;
17
- export async function runProjectCommand(command, launchDirectory) {
13
+ export async function runProjectCommand(command, launchDirectory, options = {}) {
18
14
  const stdout = process.stdout.write;
19
15
  const transport = stdout.bind(process.stdout);
20
16
  const startup = new AbortController();
21
17
  let session;
22
18
  let signalCode;
23
19
  let outputFailed = false;
20
+ let workspace = 'cwd' in command ? command.cwd : undefined;
21
+ let trace;
22
+ let unsubscribeTrace;
24
23
  let lastWrite;
25
24
  const outputQueue = [];
26
25
  let queuedBytes = 0;
@@ -112,30 +111,75 @@ export async function runProjectCommand(command, launchDirectory) {
112
111
  // Only the host's captured transport can write protocol output.
113
112
  process.stdout.write = process.stderr.write.bind(process.stderr);
114
113
  try {
115
- const config = { launchDirectory, configPath: command.configPath, outputRoot: command.outputRoot,
116
- lifetime: command.lifetime, clientCapabilities: { questions: command.interaction === 'questions' } };
117
114
  const stopped = Promise.withResolvers();
118
115
  const abortStartup = () => stopped.reject(startup.signal.reason);
119
116
  startup.signal.addEventListener('abort', abortStartup, { once: true });
120
- let definition;
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
+ };
121
140
  try {
122
- definition = await Promise.race([loadProjectHarness(launchDirectory, command.harness, builtins), stopped.promise]);
141
+ session = await Promise.race([prepare(), stopped.promise]);
123
142
  startup.signal.throwIfAborted();
124
143
  }
125
144
  finally {
126
145
  startup.signal.removeEventListener('abort', abortStartup);
127
146
  }
128
- session = createHarnessSession(definition, config);
129
- const input = command.mode === 'foreground'
130
- ? resolveHarnessInput({ cwd: command.cwd, prompt: command.prompt }, launchDirectory)
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)
131
165
  : undefined;
132
- if (command.mode === 'rpc' || command.lifetime === 'interactive' || config.clientCapabilities.questions) {
166
+ if (command.mode === 'rpc' || (command.mode === 'foreground' && (command.lifetime === 'interactive' || command.interaction === 'questions'))) {
133
167
  const code = await runProjectRpc(session, process.stdin, write, launchDirectory, input);
134
168
  await lastWrite;
135
169
  return signalCode ?? (outputFailed ? 1 : code);
136
170
  }
137
- await session.start(input, { requestId: 'foreground-start' });
138
- const result = await session.completion;
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;
175
+ let result;
176
+ try {
177
+ await session.start(input, { requestId: 'foreground-start' });
178
+ result = await session.completion;
179
+ }
180
+ finally {
181
+ unsubscribe?.();
182
+ }
139
183
  await write({ type: 'result', runId: result.runId, result });
140
184
  return signalCode ?? (outputFailed ? 1 : getHarnessExitCode(session));
141
185
  }
@@ -147,6 +191,12 @@ export async function runProjectCommand(command, launchDirectory) {
147
191
  return signalCode ?? (outputFailed ? 1 : 2);
148
192
  }
149
193
  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
+ }
150
200
  process.stdout.write = stdout;
151
201
  process.off('SIGINT', signal);
152
202
  process.off('SIGTERM', signal);
@@ -154,3 +204,54 @@ export async function runProjectCommand(command, launchDirectory) {
154
204
  process.stderr.off('error', ignoreDiagnosticError);
155
205
  }
156
206
  }
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
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,232 @@
1
+ import { join, resolve } from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { registerHooks } from 'node:module';
4
+ import { closeSync, mkdtempSync, openSync, readSync, rmdirSync, unlinkSync, writeFileSync } from 'node:fs';
5
+ import { tmpdir } from 'node:os';
6
+ import { verifyExportedSdk } from './anyswarm-eject.js';
7
+ import { installSourceLoader } from '../src/harness/typescript-loader.js';
8
+ import { parseAnySwarmCommand, parseHarnessSelection } from './anyswarm-arguments.js';
9
+ const [, , entry, ...args] = process.argv;
10
+ if (!entry)
11
+ throw new TypeError('A TypeScript or JavaScript entry file is required');
12
+ const filename = resolve(entry);
13
+ const entryUrl = pathToFileURL(filename).href;
14
+ process.argv = [process.execPath, filename, ...args];
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'));
22
+ 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
+ async function importWithDiagnostics(load, useStderr = true) {
25
+ if (!useStderr)
26
+ return load();
27
+ const stdout = process.stdout.write;
28
+ process.stdout.write = process.stderr.write.bind(process.stderr);
29
+ try {
30
+ return await load();
31
+ }
32
+ finally {
33
+ process.stdout.write = stdout;
34
+ }
35
+ }
36
+ async function importImplicitSource(load) {
37
+ const { init, parse } = await import('es-module-lexer');
38
+ await init;
39
+ const stdout = process.stdout.write;
40
+ let pending;
41
+ let position = 0;
42
+ let streaming = false;
43
+ let interactiveOutput = false;
44
+ let inputReplay;
45
+ const hook = registerHooks({ load(url, context, nextLoad) {
46
+ const loaded = nextLoad(url, context);
47
+ if (url === entryUrl && loaded.format === 'module' && loaded.source !== undefined) {
48
+ try {
49
+ const code = typeof loaded.source === 'string' ? loaded.source : new TextDecoder().decode(loaded.source);
50
+ const hasDefault = parse(code)[1].some(entry => 'name' in entry && entry.name === 'default' && !entry.typeOnly);
51
+ if (!hasDefault) {
52
+ streaming = true;
53
+ process.stdout.write = stdout;
54
+ }
55
+ }
56
+ catch { /* Let Node diagnose the source if the lexer cannot classify it. */ }
57
+ }
58
+ return loaded;
59
+ } });
60
+ process.stdout.write = (chunk, encoding, callback) => {
61
+ const charset = typeof encoding === 'string' ? encoding : undefined;
62
+ const done = typeof encoding === 'function' ? encoding : callback;
63
+ if (streaming && pending === undefined) {
64
+ interactiveOutput = true;
65
+ return stdout.call(process.stdout, chunk, charset, done);
66
+ }
67
+ if (pending === undefined) {
68
+ const directory = mkdtempSync(join(tmpdir(), 'anys-source-output-'));
69
+ const path = join(directory, 'stdout');
70
+ try {
71
+ pending = openSync(path, 'wx+', 0o600);
72
+ unlinkSync(path);
73
+ }
74
+ finally {
75
+ rmdirSync(directory);
76
+ }
77
+ }
78
+ writeFileSync(pending, chunk, charset);
79
+ if (done)
80
+ process.nextTick(done);
81
+ return true;
82
+ };
83
+ async function replay(destination) {
84
+ const fd = pending;
85
+ const write = destination === process.stdout ? stdout : destination.write;
86
+ try {
87
+ if (fd === undefined)
88
+ return;
89
+ const chunk = Buffer.alloc(64 * 1024);
90
+ for (;;) {
91
+ const size = readSync(fd, chunk, 0, chunk.length, position);
92
+ if (!size)
93
+ break;
94
+ position += size;
95
+ await new Promise((done, reject) => write.call(destination, chunk.subarray(0, size), undefined, error => error ? reject(error) : done()));
96
+ }
97
+ }
98
+ finally {
99
+ pending = undefined;
100
+ if (fd !== undefined)
101
+ closeSync(fd);
102
+ }
103
+ }
104
+ const streamForInput = () => {
105
+ if (streaming)
106
+ return;
107
+ streaming = true;
108
+ interactiveOutput = pending !== undefined;
109
+ inputReplay = replay(process.stdout);
110
+ void inputReplay.catch(() => { });
111
+ };
112
+ const stdin = process.stdin;
113
+ const read = stdin.read;
114
+ const ownRead = Object.getOwnPropertyDescriptor(stdin, 'read');
115
+ function readForInput(size) {
116
+ // Readable also calls read(0) internally to prepare its buffer.
117
+ if (size !== 0)
118
+ streamForInput();
119
+ return read.call(this, size);
120
+ }
121
+ const watchInput = (event) => {
122
+ if (event === 'data' || event === 'readable' || event === 'keypress')
123
+ streamForInput();
124
+ };
125
+ stdin.read = readForInput;
126
+ stdin.on('newListener', watchInput).on('resume', streamForInput);
127
+ // Explicit exit cannot wait on queued pipe writes. Keep stdout's normal
128
+ // backpressure and leave any queued replay writes in their original order.
129
+ const flushOnExit = () => {
130
+ if (pending === undefined || position > 0)
131
+ return;
132
+ try {
133
+ for (;;) {
134
+ const chunk = Buffer.alloc(64 * 1024);
135
+ const size = readSync(pending, chunk, 0, chunk.length, position);
136
+ if (!size || !stdout.call(process.stdout, chunk.subarray(0, size)))
137
+ return;
138
+ position += size;
139
+ }
140
+ }
141
+ catch { /* Preserve the explicit exit code if output can no longer be written. */ }
142
+ };
143
+ process.once('exit', flushOnExit);
144
+ let destination = process.stderr;
145
+ try {
146
+ const source = await load();
147
+ if (!isHarness(source) || (args.length === 0 && isInteractiveOnly(source.default)))
148
+ destination = process.stdout;
149
+ else if (interactiveOutput) {
150
+ throw new Error('Use an explicit --prompt for a task Harness that writes to stdout while reading stdin during import.');
151
+ }
152
+ return source;
153
+ }
154
+ finally {
155
+ hook.deregister();
156
+ stdin.off('newListener', watchInput).off('resume', streamForInput);
157
+ if (stdin.read === readForInput) {
158
+ if (ownRead)
159
+ Object.defineProperty(stdin, 'read', ownRead);
160
+ else
161
+ Reflect.deleteProperty(stdin, 'read');
162
+ }
163
+ try {
164
+ await (inputReplay ?? replay(destination));
165
+ }
166
+ finally {
167
+ process.stdout.write = stdout;
168
+ process.off('exit', flushOnExit);
169
+ }
170
+ }
171
+ }
172
+ try {
173
+ const verifySdk = await verifyExportedSdk(filename);
174
+ if (verifySdk) {
175
+ const sdk = '@anyswarm/core';
176
+ let checkingEntry = true;
177
+ registerHooks({ resolve(specifier, context, nextResolve) {
178
+ if (specifier !== sdk)
179
+ return nextResolve(specifier, context);
180
+ const resolved = nextResolve(specifier, checkingEntry ? { ...context, parentURL: entryUrl } : context);
181
+ verifySdk(resolved.url);
182
+ return resolved;
183
+ } });
184
+ // Use Node's ESM conditions with the same parent and fallback as the entry.
185
+ try {
186
+ import.meta.resolve(sdk);
187
+ }
188
+ finally {
189
+ checkingEntry = false;
190
+ }
191
+ }
192
+ 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));
197
+ if (isHarness(source)) {
198
+ 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
+ }
227
+ }
228
+ }
229
+ catch (error) {
230
+ console.error(error instanceof Error ? error.stack : String(error));
231
+ process.exitCode = 1;
232
+ }
@@ -0,0 +1,36 @@
1
+ import { runLocalCommand } from './local-setup.js';
2
+ export declare function terminalObject(value: unknown): Record<string, unknown>;
3
+ type ConfigurationChoice = {
4
+ path?: string;
5
+ source: string;
6
+ };
7
+ type Preference = {
8
+ version: 1;
9
+ harness: string;
10
+ configPath: string;
11
+ };
12
+ export declare class LauncherConfiguration {
13
+ readonly harness: string;
14
+ readonly specifier: string;
15
+ readonly launchDirectory: string;
16
+ readonly workspace: string;
17
+ readonly preferencePath: string;
18
+ readonly isBuiltin: boolean;
19
+ source: string;
20
+ path?: string;
21
+ preference?: Preference;
22
+ preferenceError?: string;
23
+ error?: string;
24
+ configuration?: Record<string, unknown>;
25
+ diagnostics?: Awaited<ReturnType<typeof runLocalCommand>>;
26
+ private choice?;
27
+ constructor(harness: string, specifier: string, launchDirectory: string, cwd?: string, path?: string, choice?: ConfigurationChoice);
28
+ selectedChoice(): ConfigurationChoice | undefined;
29
+ refresh(): Promise<void>;
30
+ private validateRuntime;
31
+ select(path: string): Promise<void>;
32
+ remember(): Promise<void>;
33
+ forget(): Promise<void>;
34
+ diagnose(prepare: boolean, signal: AbortSignal, progress: (message: string) => void, backend?: 'pi' | 'codex'): Promise<void>;
35
+ }
36
+ export {};