@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
@@ -2,6 +2,18 @@ import { runWithReport } from '@anyswarm/core';
2
2
  export declare function createLeadWorkerHarness(options: any): Promise<Readonly<{
3
3
  id: any;
4
4
  snapshot: () => {
5
+ userControls: {
6
+ [k: string]: {
7
+ kind: 'interrupt' | 'stop';
8
+ requestId: string;
9
+ };
10
+ };
11
+ pendingMemberControls: {
12
+ [k: string]: {
13
+ kind: 'interrupt' | 'stop';
14
+ requestId: string;
15
+ };
16
+ };
5
17
  runId: any;
6
18
  runtimeId: any;
7
19
  initialCommit: string | undefined;
@@ -50,6 +62,18 @@ export declare function createLeadWorkerHarness(options: any): Promise<Readonly<
50
62
  }): Promise<{
51
63
  submitted: any;
52
64
  harness: {
65
+ userControls: {
66
+ [k: string]: {
67
+ kind: 'interrupt' | 'stop';
68
+ requestId: string;
69
+ };
70
+ };
71
+ pendingMemberControls: {
72
+ [k: string]: {
73
+ kind: 'interrupt' | 'stop';
74
+ requestId: string;
75
+ };
76
+ };
53
77
  runId: any;
54
78
  runtimeId: any;
55
79
  initialCommit: string | undefined;
@@ -98,6 +122,18 @@ export declare function createLeadWorkerHarness(options: any): Promise<Readonly<
98
122
  ok: boolean;
99
123
  };
100
124
  harness: {
125
+ userControls: {
126
+ [k: string]: {
127
+ kind: 'interrupt' | 'stop';
128
+ requestId: string;
129
+ };
130
+ };
131
+ pendingMemberControls: {
132
+ [k: string]: {
133
+ kind: 'interrupt' | 'stop';
134
+ requestId: string;
135
+ };
136
+ };
101
137
  runId: any;
102
138
  runtimeId: any;
103
139
  initialCommit: string | undefined;
@@ -145,6 +181,18 @@ export declare function createLeadWorkerHarness(options: any): Promise<Readonly<
145
181
  direction: any;
146
182
  submitted: any;
147
183
  harness: {
184
+ userControls: {
185
+ [k: string]: {
186
+ kind: 'interrupt' | 'stop';
187
+ requestId: string;
188
+ };
189
+ };
190
+ pendingMemberControls: {
191
+ [k: string]: {
192
+ kind: 'interrupt' | 'stop';
193
+ requestId: string;
194
+ };
195
+ };
148
196
  runId: any;
149
197
  runtimeId: any;
150
198
  initialCommit: string | undefined;
@@ -193,6 +241,18 @@ export declare function createLeadWorkerHarness(options: any): Promise<Readonly<
193
241
  originalDirection: any;
194
242
  adjustedDirection: any;
195
243
  harness: {
244
+ userControls: {
245
+ [k: string]: {
246
+ kind: 'interrupt' | 'stop';
247
+ requestId: string;
248
+ };
249
+ };
250
+ pendingMemberControls: {
251
+ [k: string]: {
252
+ kind: 'interrupt' | 'stop';
253
+ requestId: string;
254
+ };
255
+ };
196
256
  runId: any;
197
257
  runtimeId: any;
198
258
  initialCommit: string | undefined;
@@ -1,6 +1,6 @@
1
1
  import { mkdir } from 'node:fs/promises';
2
2
  import { join, resolve } from 'node:path';
3
- import { createRuntime, ServiceRegistry, createOwnedResources, seededCheckoutInstruction, runInput, runWithReport } from '@anyswarm/core';
3
+ import { createRuntime, getExecutorCapabilities, ServiceRegistry, createOwnedResources, seededCheckoutInstruction, runInput, runWithReport } from '@anyswarm/core';
4
4
  import { createBoard, boardPermissions, projectBoardPermissions } from '../services/board.js';
5
5
  import { leadWorkerRoles } from './team.js';
6
6
  import { createDynamicLeadWorker, dynamicServices } from './dynamic.js';
@@ -46,6 +46,62 @@ export async function createLeadWorkerHarness(options) {
46
46
  let boardFenceFailure;
47
47
  const pendingFences = new Map();
48
48
  const activeInputs = new Set();
49
+ const pendingMemberControls = new Map();
50
+ function recordMemberControl(agentId, control) {
51
+ try {
52
+ board.interveneMember({ agentId, ...control });
53
+ pendingMemberControls.delete(agentId);
54
+ }
55
+ catch {
56
+ pendingMemberControls.set(agentId, control);
57
+ }
58
+ }
59
+ const userControls = new Map();
60
+ const heldMembers = new Map();
61
+ async function waitForMember(agentId, signal) {
62
+ if (userControls.get(agentId)?.kind !== 'interrupt')
63
+ return;
64
+ let waiting = heldMembers.get(agentId);
65
+ if (!waiting)
66
+ heldMembers.set(agentId, waiting = Promise.withResolvers());
67
+ const abort = () => waiting.reject(fail('WORKFLOW_STOPPED'));
68
+ signal.addEventListener('abort', abort, { once: true });
69
+ try {
70
+ signal.throwIfAborted();
71
+ await waiting.promise;
72
+ }
73
+ finally {
74
+ signal.removeEventListener('abort', abort);
75
+ }
76
+ }
77
+ const memberControls = {
78
+ capabilities: {
79
+ send: { supported: getExecutorCapabilities(executor ?? 'pi').activeSteer, text: true, modes: ['steer'] },
80
+ interrupt: { supported: getExecutorCapabilities(executor ?? 'pi').queuedInputCancellation },
81
+ stop: { supported: true },
82
+ },
83
+ handlers: {
84
+ send(agentId, payload, request) {
85
+ const { input, options } = payload;
86
+ return runtime.send(agentId, input, { ...options, requestId: request.operationId });
87
+ },
88
+ async interrupt(agentId, _payload, request) {
89
+ const control = { kind: 'interrupt', requestId: request.requestId };
90
+ userControls.set(agentId, control);
91
+ recordMemberControl(agentId, control);
92
+ const core = await runtime.interrupt(agentId, { requestId: request.operationId });
93
+ return { core, harnessEffects: { held: true, rescheduled: false, boardRecorded: !pendingMemberControls.has(agentId) } };
94
+ },
95
+ async stop(agentId, payload, request) {
96
+ const control = { kind: 'stop', requestId: request.requestId };
97
+ userControls.set(agentId, control);
98
+ recordMemberControl(agentId, control);
99
+ heldMembers.get(agentId)?.resolve();
100
+ const core = await runtime.stop(agentId, { requestId: request.operationId, reason: payload?.reason });
101
+ return { core, harnessEffects: { stopped: true, rescheduled: false, boardRecorded: !pendingMemberControls.has(agentId) } };
102
+ },
103
+ },
104
+ };
49
105
  const team = {};
50
106
  const inputs = [];
51
107
  const events = [];
@@ -64,7 +120,7 @@ export async function createLeadWorkerHarness(options) {
64
120
  catch {
65
121
  boardReadFailure = { code: 'BOARD_READ_FAILED' };
66
122
  }
67
- return { runId, runtimeId: runtime?.id, initialCommit, initialDigest: options.initialDigest, boardPath, team: { ...team }, stages: structuredClone(stages), rejections: structuredClone(rejections), preparation: structuredClone(preparedStages ?? null), git: git?.identities(), board: publicBoard, ...(boardReadFailure ? { boardReadFailure } : {}), inputs: structuredClone(inputs), events: structuredClone(events),
123
+ return { userControls: Object.fromEntries(userControls), pendingMemberControls: Object.fromEntries(pendingMemberControls), runId, runtimeId: runtime?.id, initialCommit, initialDigest: options.initialDigest, boardPath, team: { ...team }, stages: structuredClone(stages), rejections: structuredClone(rejections), preparation: structuredClone(preparedStages ?? null), git: git?.identities(), board: publicBoard, ...(boardReadFailure ? { boardReadFailure } : {}), inputs: structuredClone(inputs), events: structuredClone(events),
68
124
  delivered: publicBoard?.subtasks.filter((row) => row.delivery?.verified) ?? [], unfinished: publicBoard?.subtasks.filter((row) => row.state !== 'complete') ?? [], inputUnknown: inputs.filter((row) => row.uncertain).map((row) => ({ agentId: row.agentId, requestId: row.requestId, inputId: row.inputId, code: row.code })), resources: resources.snapshot(),
69
125
  ...(boardFenceFailure ? { boardFenceFailure, pendingBoardFailures: [...pendingFences.values()] } : {}), ...(dynamicControl ? { dynamic: dynamicControl.snapshot() } : {}),
70
126
  limitations: ['Local SQLite Board and exclusive turn controller', dynamic ? 'One dynamic member and no claim reclamation' : 'Fixed preconfigured team; no replacement or claim reclamation', 'Upstream scale and performance not verified'] };
@@ -112,7 +168,9 @@ export async function createLeadWorkerHarness(options) {
112
168
  recordFence({ agentId, code: failure.code, execution: core.agents?.find((row) => row.agentId === agentId)?.execution === 'stopped' ? 'stopped' : 'unknown' });
113
169
  if (boardFenceFailure)
114
170
  recordFence();
115
- if (boardReadFailed || boardFenceFailure || pendingFences.size)
171
+ for (const [agentId, control] of pendingMemberControls)
172
+ recordMemberControl(agentId, control);
173
+ if (boardReadFailed || boardFenceFailure || pendingFences.size || pendingMemberControls.size)
116
174
  return { ...core, cleanup: 'pending', harness: { cleanup: 'pending', pending: [{ kind: 'board-evidence', id: boardPath, action: 'persist-failure', error: { code: 'BOARD_FENCE_FAILED' } }], resources: resources.snapshot() } };
117
175
  if (core.cleanup !== 'complete' || core.agents.some((row) => row.execution !== 'stopped' || row.cleanup !== 'complete'))
118
176
  return { ...core, harness: { cleanup: 'pending', pending: resources.snapshot().filter((row) => !['closed', 'retained'].includes(row.state)) } };
@@ -133,6 +191,9 @@ export async function createLeadWorkerHarness(options) {
133
191
  const dispatch = async (role, requestId, payload, workSignal, deadlineAtMs) => {
134
192
  if (workSignal.aborted || closing)
135
193
  throw fail('WORKFLOW_STOPPED');
194
+ await waitForMember(team[role], workSignal);
195
+ if (userControls.get(team[role])?.kind === 'stop')
196
+ return { status: 'user-stopped' };
136
197
  const timeoutMs = deadlineAtMs === undefined ? turnTimeoutMs : Math.ceil(deadlineAtMs - performance.now());
137
198
  if (timeoutMs < 1)
138
199
  throw fail('WORKFLOW_STOPPED');
@@ -141,12 +202,20 @@ export async function createLeadWorkerHarness(options) {
141
202
  inputs.push(row);
142
203
  activeInputs.add(team[role]);
143
204
  try {
144
- const result = await runInput(runtime, team[role], JSON.stringify(payload), { requestId, timeoutMs, signal: workSignal });
205
+ const result = await runInput(runtime, team[role], JSON.stringify(payload), { requestId, timeoutMs, signal: workSignal,
206
+ beforeSend() { if (userControls.has(team[role]))
207
+ throw fail('MEMBER_HELD'); },
208
+ });
145
209
  Object.assign(row, { inputId: result.inputId, receipt: result.receipt, state: 'completed', settled: { agentId: result.settled.agentId, outcome: result.settled.outcome } });
146
210
  return result;
147
211
  }
148
212
  catch (error) {
149
213
  Object.assign(row, { inputId: error.inputId, receipt: error.receipt, state: 'failed', code: error.code ?? 'INPUT_FAILED', uncertain: !['input_failed', 'input_aborted'].includes(error.code) });
214
+ if (userControls.has(team[role])) {
215
+ row.state = userControls.get(team[role]).kind === 'stop' ? 'user-stopped' : 'user-interrupted';
216
+ await waitForMember(team[role], workSignal);
217
+ return { status: row.state };
218
+ }
150
219
  if (dynamic && error.code === 'input_unknown') {
151
220
  const recorded = runtime.send(team[role], JSON.stringify(payload), { requestId, mode: 'followUp' });
152
221
  try {
@@ -209,12 +278,14 @@ export async function createLeadWorkerHarness(options) {
209
278
  runtime = await createRuntime({ sandbox, executor, models, connection, filePolicy, services, profiles, maxAgents: roles.length + (dynamic ? 1 : 0), outputDir, ...(dynamicControl ? { agentAccessPolicy: dynamicControl.agentAccessPolicy } : {}) });
210
279
  if (startup.aborted)
211
280
  throw fail('HARNESS_START_ABORTED');
212
- options.onRuntime?.(runtime, snapshot, board.subscribe);
281
+ options.onRuntime?.(runtime, snapshot, board.subscribe, memberControls);
213
282
  unsubscribe = runtime.onEvent((event) => {
214
283
  if (event.type === 'session')
215
284
  return;
216
285
  if (events.length < (dynamic ? 2048 : 256))
217
286
  events.push({ agentId: event.agentId, seq: events.length + 1, type: event.type, ...(event.outcome ? { outcome: event.outcome } : {}) });
287
+ if (userControls.has(event.agentId) && (event.type === 'settled' && event.outcome === 'aborted' || event.type === 'exit'))
288
+ return;
218
289
  if (!dynamic && events.length >= 256 || event.type === 'error' && event.fatal || event.type === 'settled' && event.outcome !== 'completed' || event.type === 'exit' && !event.expected) {
219
290
  if (!closing) {
220
291
  recordFence({ agentId: event.agentId, code: 'AGENT_FAILED' });
@@ -246,7 +317,7 @@ export async function createLeadWorkerHarness(options) {
246
317
  const workSignal = AbortSignal.any([lifetime.signal, AbortSignal.timeout(workTimeoutMs), ...(signal ? [signal] : [])]);
247
318
  try {
248
319
  workSignal.throwIfAborted();
249
- const submitted = await runDynamicSchedule({ board, team, goal: dynamic.goal, signal: workSignal, dispatch: dispatchWork });
320
+ const submitted = await runDynamicSchedule({ board, team, goal: dynamic.goal, signal: workSignal, dispatch: dispatchWork, canDispatch: agentId => !userControls.has(agentId) });
250
321
  if (!dynamic.verifyFinal)
251
322
  return { submitted, harness: snapshot() };
252
323
  const verdict = await dynamic.verifyFinal({ repositoryUrl: facilities.repositoryUrl, token: facilities.actors.lead.token,
@@ -40,8 +40,8 @@ const leadWorker = {
40
40
  ...config, sandbox, runId: context.runId.replaceAll('-', '').slice(0, 24), outputDir: context.outputDir,
41
41
  signal: context.signal, projectFiles: context.initial.files, initialDigest: context.initial.digest,
42
42
  dynamic: deploy ? { goal: context.input.prompt, projectFiles: context.initial.files, deploy } : undefined,
43
- onRuntime: (runtime, snapshot, subscribeBoard) => {
44
- observation = observeProjectRuntime(runtime, context, snapshot);
43
+ onRuntime: (runtime, snapshot, subscribeBoard, controls) => {
44
+ observation = observeProjectRuntime(runtime, context, snapshot, controls);
45
45
  unsubscribeBoard = subscribeBoard(() => { void observation?.refresh(); });
46
46
  },
47
47
  beforeInitialDispatch: () => context.markRunning(),
@@ -25,6 +25,11 @@ export declare function createBoard({ path: databasePath, runId, helperCount, ve
25
25
  };
26
26
  }): void;
27
27
  readyMember(agentId: string): void;
28
+ interveneMember({ agentId, kind, requestId }: {
29
+ agentId: string;
30
+ kind: 'interrupt' | 'stop';
31
+ requestId: string;
32
+ }): void;
28
33
  subscribe(listener: () => void): () => boolean;
29
34
  registerUserInput(requestId: any, input: any): void;
30
35
  fence({ agentId, code, execution }?: any): void;
@@ -80,6 +80,8 @@ export function createBoard({ path: databasePath, runId, helperCount, verifyDeli
80
80
  const role = (dynamic ? member?.role : profile) === 'lead' ? 'lead' : 'helper';
81
81
  if (!profile || dynamic && !member.ready || state.runtimeId !== caller.runtimeId || caller.profile !== profile || caller.binding !== `${runId}:board` || !permissions[role].includes(operation))
82
82
  throw error('NOT_ALLOWED');
83
+ if (state.userInterventions?.[caller.agentId]?.kind === 'stop' && !['read', 'list_subtasks'].includes(operation))
84
+ throw error('MEMBER_STOPPED');
83
85
  if ((memoryFenced || state.fenced) && !['read', 'list_subtasks'].includes(operation))
84
86
  throw error('BOARD_FENCED');
85
87
  return role;
@@ -104,7 +106,7 @@ export function createBoard({ path: databasePath, runId, helperCount, verifyDeli
104
106
  }
105
107
  const registration = { manifest: { id: 'board', title: 'Lead-Worker Board', purpose: 'Durable direction, exclusive ownership and verified delivery', provider_version: 'lead-worker-board-1', contract_version: '2', endpoint: { transport: 'in-process' },
106
108
  capabilities: Object.entries(capabilities).map(([operation, input_schema]) => ({ name: operation, operation, description: `Public Board ${operation}`, help: { when: 'Read direction before claiming or completing work; never reclaim an owner' }, side_effect: ['read', 'list_subtasks'].includes(operation) ? 'read' : 'write', idempotent: true, input_schema,
107
- output_schema: { type: 'object', additionalProperties: true }, errors: ['NOT_ALLOWED', 'CONFLICT', 'NOT_FOUND', 'BOARD_FENCED', 'BOARD_LIMIT', 'FEEDBACK_NOT_READ', 'DIRECTION_NOT_READ', 'DELIVERY_INVALID'].map((code) => ({ code, retryable: false })) })) },
109
+ output_schema: { type: 'object', additionalProperties: true }, errors: ['NOT_ALLOWED', 'CONFLICT', 'NOT_FOUND', 'BOARD_FENCED', 'BOARD_LIMIT', 'FEEDBACK_NOT_READ', 'DIRECTION_NOT_READ', 'DELIVERY_INVALID', 'MEMBER_STOPPED'].map((code) => ({ code, retryable: false })) })) },
108
110
  adapter: { async invoke({ capability, input, envelope, caller, signal, assertAuthorized }) {
109
111
  const operation = capability.operation;
110
112
  const state = load();
@@ -261,6 +263,22 @@ export function createBoard({ path: databasePath, runId, helperCount, verifyDeli
261
263
  event(state, 'member_ready', agentId, { profile: member.profile, requestId: member.requestId });
262
264
  });
263
265
  },
266
+ interveneMember({ agentId, kind, requestId }) {
267
+ transaction((state) => {
268
+ if (!state.team || !Object.values(state.team).includes(agentId))
269
+ throw error('NOT_ALLOWED');
270
+ state.userInterventions ??= {};
271
+ const previous = state.userInterventions[agentId];
272
+ if (previous?.kind === 'stop')
273
+ return;
274
+ const intervention = { kind, requestId };
275
+ state.userInterventions[agentId] = intervention;
276
+ for (const task of state.subtasks)
277
+ if (task.owner === agentId && task.state !== 'complete')
278
+ task.intervention = intervention;
279
+ event(state, 'user_control', agentId, intervention);
280
+ });
281
+ },
264
282
  subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
265
283
  registerUserInput(requestId, input) { transaction((state) => { if (state.fenced || typeof requestId !== 'string' || !/^[A-Za-z0-9_.:-]{1,128}$/.test(requestId) || typeof input !== 'string' || Buffer.byteLength(input) > 16384 || state.userInputs.length >= 5 || state.userInputs.some((row) => row.requestId === requestId))
266
284
  throw error('NOT_ALLOWED'); state.userInputs.push({ requestId, sha256: createHash('sha256').update(input).digest('hex') }); }); },
@@ -36,13 +36,13 @@ directory and returns its report path; `--output-dir` chooses another location.
36
36
 
37
37
  ## Install and build matching sources
38
38
 
39
- Set `ANYSWARM_SDK_ARCHIVE` to the absolute path of a candidate tarball whose
40
- SHA-256 you have verified. Run these commands in an empty directory. The copied
41
- source and installed SDK come from the same archive.
39
+ Run these commands in an empty directory. To use a source build, set
40
+ `ANYSWARM_SDK_ARCHIVE` to the absolute path of its verified archive. Copy the
41
+ example sources from the SDK you installed.
42
42
 
43
43
  ```sh
44
44
  npm init -y
45
- npm install --ignore-scripts "$ANYSWARM_SDK_ARCHIVE"
45
+ npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
46
46
  npm install --save-dev typescript @types/node
47
47
  cp -R node_modules/@anyswarm/core/examples/messages demo
48
48
  cd demo
@@ -116,7 +116,7 @@ The external Service remains running after the Harness closes.
116
116
 
117
117
  [`project.ts`](project.ts) consumes the user's directory and prompt.
118
118
  [`handoff.ts`](handoff.ts) is a separate fixed-payload diagnostic, invoked from
119
- the checkout root with `node dist/examples/messages/handoff.js`. It seeds a
119
+ the checkout root with `anyswarm run ./examples/messages/handoff.ts`. It seeds a
120
120
  value in the writer's files, then compares the reader's exported `received.txt`
121
121
  byte for byte. Its report goes under `handoff-runs/` unless `ANYSWARM_SDK_OUTPUT`
122
122
  overrides it. The common project runner has its own input and report handling.
@@ -7,6 +7,8 @@ export declare function runMessageHandoff(config: HandoffConfig, abort: AbortSig
7
7
  ready(): void;
8
8
  observe(runtime: Runtime): () => void;
9
9
  progress?(state: unknown): void;
10
+ inputSignal?(agentId: string): AbortSignal;
11
+ assertMember?(agentId: string): void;
10
12
  }): Promise<{
11
13
  report: {
12
14
  runtimeId: string;
@@ -61,10 +61,13 @@ export async function runMessageHandoff(config, abort, onEvent = () => { }, proj
61
61
  submissions.push(submission);
62
62
  project?.progress?.({ stage: operation, key, agentId, operationId, requestId });
63
63
  try {
64
- const turn = await runInput(runtime, agentId, input, { requestId, signal, timeoutMs: config.workTimeoutMs });
64
+ const local = project?.inputSignal?.(agentId);
65
+ const turn = await runInput(runtime, agentId, input, { requestId, signal: local ? AbortSignal.any([signal, local]) : signal,
66
+ timeoutMs: config.workTimeoutMs, beforeSend: () => project?.assertMember?.(agentId) });
65
67
  submission.inputId = turn.inputId;
66
68
  }
67
69
  catch (error) {
70
+ project?.assertMember?.(agentId);
68
71
  const turn = error;
69
72
  submission.inputId = turn.inputId;
70
73
  if (turn.code === 'agent_exited' || turn.code === 'agent_failed')
@@ -77,6 +80,7 @@ export async function runMessageHandoff(config, abort, onEvent = () => { }, proj
77
80
  throw error;
78
81
  }
79
82
  signal.throwIfAborted();
83
+ project?.assertMember?.(agentId);
80
84
  const call = calls.get(callKey(agentId, operation, operationId));
81
85
  if (!call || (operation === 'put' ? call.author !== agentId : call.text !== writtenText))
82
86
  throw failure('HANDOFF_SERVICE_UNCONFIRMED');
@@ -1,4 +1,4 @@
1
- import { observeProjectRuntime, projectConfiguration, ProjectPreflightError } from '@anyswarm/core';
1
+ import { AnySwarmError, getExecutorCapabilities, observeProjectRuntime, projectConfiguration, ProjectPreflightError } from '@anyswarm/core';
2
2
  import { runMessageHandoff } from './handoff.js';
3
3
  import { handoffConfig } from './handoff-config.js';
4
4
  const messages = {
@@ -10,15 +10,65 @@ const messages = {
10
10
  throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Messages requires finite work and cleanup time limits');
11
11
  }
12
12
  }
13
+ const interventions = [];
14
+ const blocked = new Set();
15
+ const waits = new Map();
16
+ const assertMember = (agentId) => {
17
+ if (blocked.has(agentId))
18
+ throw new AnySwarmError('MEMBER_WORK_CANCELLED', 'The owner intervened in this member’s work');
19
+ };
13
20
  let business = { stage: 'put' };
14
21
  let observation;
15
22
  const { report, submissions } = await runMessageHandoff({ ...config, outputDir: context.outputDir }, context.signal, undefined, {
16
23
  files: context.initial.files, prompt: context.input.prompt,
17
24
  artifact: `anyswarm-message-${context.runId}.txt`, ready: context.markRunning,
18
25
  observe(runtime) {
19
- observation = observeProjectRuntime(runtime, context, () => business);
26
+ const native = getExecutorCapabilities(config.executor ?? 'pi');
27
+ const controlEffects = (core) => ({ core, harnessEffects: { memberWork: 'cancelled', status: 'complete' } });
28
+ const intervene = async (operation, agentId, requestId) => {
29
+ blocked.add(agentId);
30
+ interventions.push({ agentId, operation, requestId });
31
+ context.emit({ kind: 'user-intervention', agentId, operation, requestId });
32
+ void observation?.refresh();
33
+ try {
34
+ const core = operation === 'interrupt' ? await runtime.interrupt(agentId, { requestId })
35
+ : await runtime.stop(agentId, { timeoutMs: config.cleanupTimeoutMs });
36
+ return controlEffects(core);
37
+ }
38
+ finally {
39
+ waits.get(agentId)?.abort();
40
+ }
41
+ };
42
+ observation = observeProjectRuntime(runtime, context, () => Object.assign({}, business, { interventions }), {
43
+ capabilities: {
44
+ send: { supported: native.activeSteer, text: true, modes: ['steer'] },
45
+ interrupt: { supported: native.queuedInputCancellation }, stop: { supported: true },
46
+ },
47
+ handlers: {
48
+ send(agentId, payload, request) {
49
+ assertMember(agentId);
50
+ const { input, options } = payload;
51
+ return runtime.send(agentId, input, { ...options, mode: 'steer', wakeIfIdle: false, requestId: request.operationId });
52
+ },
53
+ interrupt: (agentId, _payload, request) => intervene('interrupt', agentId, request.operationId),
54
+ stop: (agentId, _payload, request) => intervene('stop', agentId, request.operationId),
55
+ },
56
+ async reconcile(operation, agentId, request) {
57
+ if (operation === 'stop')
58
+ return controlEffects(await runtime.stop(agentId, { timeoutMs: config.cleanupTimeoutMs }));
59
+ const core = await observation.reconcile(agentId, operation, request.operationId);
60
+ return operation === 'interrupt' ? controlEffects(core) : core;
61
+ },
62
+ });
20
63
  return observation.close;
21
64
  },
65
+ inputSignal(agentId) {
66
+ assertMember(agentId);
67
+ const wait = new AbortController();
68
+ waits.set(agentId, wait);
69
+ return wait.signal;
70
+ },
71
+ assertMember,
22
72
  progress(state) {
23
73
  business = state;
24
74
  void observation?.refresh();
@@ -9,12 +9,12 @@ anyswarm --harness notes --prompt "Inspect this project and explain how to verif
9
9
 
10
10
  The writer and reader use the same captured project to publish and use a task observation. The reader exports an artifact that includes the retrieved note.
11
11
 
12
- After installing the built tarball, configure the model route, compatible Worker image and other runtime resources described below. A JavaScript config can also be supplied with `--config`. The common command saves its outputs outside the input directory by default.
12
+ After installing the SDK, configure the model route, compatible Worker image and other runtime resources described below. A JavaScript config can also be supplied with `--config`. The common command saves its outputs outside the input directory by default.
13
13
 
14
14
 
15
15
  The host imports only from `@anyswarm/core` for Runtime, Sandbox and Service author APIs. See the [Runtime guide](../../docs/en/runtime.md) for configuration and resource ownership.
16
16
 
17
- Install a release using [Quickstart](../../docs/en/quickstart.md), or build a checkout tarball. Install checkout dependencies with `npm ci --ignore-scripts` first. TypeScript sources compile with `npm run build` into `dist/`; `npm pack` builds JavaScript and declarations before archiving.
17
+ Install a release using [Quickstart](../../docs/en/quickstart.md), or build a checkout tarball. Install checkout dependencies with `npm ci --ignore-scripts` first. Use `npm run pack:release -- /path/to/output-directory` to build and pack the candidate.
18
18
 
19
19
  Two independent Agents hand off one supplied source fact through a custom Notes Service. The writer publishes the exact seeded text using `swarm notes put --input note-request.json --request-id notes-put`. The host seeds this request with a string `text` field containing `review-input.json`; passing that JSON text through `--text` would coerce it to an object and fail schema validation. The reader checks it and saves `review.md`, then copies that file to `followup.md` in a second turn. The host checks the Service author and read record and opens both files from the archive after stopping the reader.
20
20
 
@@ -28,51 +28,46 @@ from your prompt. Both use the same custom Notes Service.
28
28
 
29
29
  ## Install and configure
30
30
 
31
- This example requires Node.js 22.19 or newer, an authenticated OpenSandbox service reachable from the Controller, and a compatible worker image containing the selected executor. The repository Worker image ships Pi 1.3.0 and Codex CLI 0.172.0. Use an absolute path to the checkout of the tested implementation to build the tarball. The rest of the example runs in an independent directory from that tarball.
31
+ This example requires Node.js 22.19 or newer, an authenticated OpenSandbox service reachable from the Controller, and a compatible worker image containing the selected executor. The repository Worker image ships Pi 1.3.0 and Codex CLI 0.172.0. Run these commands in an empty directory. To use a source build, set `ANYSWARM_SDK_ARCHIVE` to the absolute path of its verified archive.
32
32
 
33
33
  ```sh
34
- repo=/absolute/path/to/anyswarm
35
- example_dir=$(mktemp -d)
36
- archive=$(npm pack "$repo" --pack-destination "$example_dir" --silent)
37
- cd "$example_dir"
38
34
  npm init -y
39
- npm pkg set type=module
40
- npm install --omit=dev --ignore-scripts "./$archive"
41
- example=node_modules/@anyswarm/core/dist/examples/notes
35
+ npm install --omit=dev --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
36
+ example=node_modules/@anyswarm/core/examples/notes
42
37
  ```
43
38
 
44
- Set `ANYSWARM_NOTES_IMAGE` to your compatible worker image ID and `ANYSWARM_NOTES_MODEL_URL` to the trusted Responses endpoint, including the exact `/v1/responses` path. Set `ANYSWARM_NOTES_MODEL_TOKEN` if the endpoint requires a bearer token. Configure `ANYSWARM_NOTES_ADVERTISE_HOST` to the host's guest-reachable IPv4 address if it differs from `172.17.0.1`. The sample `config.js` also reads optional lifecycle host, endpoint host and token variables. Model and lifecycle secrets stay on the host.
39
+ Set `ANYSWARM_NOTES_IMAGE` to your compatible worker image ID and `ANYSWARM_NOTES_MODEL_URL` to the trusted Responses endpoint, including the exact `/v1/responses` path. Set `ANYSWARM_NOTES_MODEL_TOKEN` if the endpoint requires a bearer token. Configure `ANYSWARM_NOTES_ADVERTISE_HOST` to the host's guest-reachable IPv4 address if it differs from `172.17.0.1`. The sample `config.ts` also reads optional lifecycle host, endpoint host and token variables. Model and lifecycle secrets stay on the host.
45
40
 
46
41
  The sample uses Pi and the configured common model route by default (`openai` / `gpt-5.4` when model labels are omitted). Common `ANYSWARM_MODEL_*` and `ANYSWARM_EXECUTOR` variables take precedence over scoped Notes variables. To run Codex, set `ANYSWARM_NOTES_EXECUTOR=codex` and `ANYSWARM_NOTES_MODEL_ID` to the model served by your endpoint. `ANYSWARM_NOTES_MODEL_PROVIDER` labels the model and defaults to `openai` for Codex. For a custom configuration module, set `executor` and its `models` mapping. The same Reader thread handles both reader inputs. See the [backend guide](../../docs/architecture/16-pi-opensandbox-backend.md#codex-app-server) for the credential and trace contract.
47
42
 
48
43
  ```sh
49
- node "$example/main.js" --help
50
- node "$example/main.js" "$example/config.js" > notes-result.json
44
+ node_modules/.bin/anyswarm run "$example/main.ts" --help
45
+ node_modules/.bin/anyswarm run "$example/main.ts" "$example/config.ts" > notes-result.json
51
46
  ```
52
47
 
53
- `main.js` imports Runtime, Service Registry and the configurable OpenSandbox backend from the public package exports. `run-input.js`, `run-report.js` and `read-result.js` are editable host modules. The Harness owns the turn order, the Notes manifest and adapter, the role grants and verification. It uses `followUp` on an idle Agent after subscribing, with one input source and a fresh ID. An unknown or queued submission remains explicit and sends no replacement.
48
+ `main.ts` imports Runtime, Service Registry and the configurable OpenSandbox backend from the public package exports. `run-input.ts`, `run-report.ts` and `read-result.ts` are editable host modules. The Harness owns the turn order, the Notes manifest and adapter, the role grants and verification. It uses `followUp` on an idle Agent after subscribing, with one input source and a fresh ID. An unknown or queued submission remains explicit and sends no replacement.
54
49
 
55
50
  ## Run and inspect the handoff
56
51
 
57
- The example runs one fixed writer turn and two reader turns, then closes. The seeded `fact` is its project input. The host exclusively owns these inputs and their request IDs. To change a later reader turn, edit its input in `main.js` before starting a new run. The example accepts no interactive directed input while the handoff is in progress. Ctrl+C or SIGTERM ends the current business wait and then enters the configured bounded cleanup. Check the returned per-Agent execution and cleanup receipts after either signal.
52
+ The example runs one fixed writer turn and two reader turns, then closes. The seeded `fact` is its project input. The host exclusively owns these inputs and their request IDs. To change a later reader turn, edit its input in `main.ts` before starting a new run. The example accepts no interactive directed input while the handoff is in progress. Ctrl+C or SIGTERM ends the current business wait and then enters the configured bounded cleanup. Check the returned per-Agent execution and cleanup receipts after either signal.
58
53
 
59
54
  Read the final CLI report from `notes-result.json`. It contains the Runtime identity and saved report location, including when the command returned a business or cleanup failure. The shell commands below select that same identity and inspect its saved receipts.
60
55
 
61
56
  ```sh
62
57
  runtime_id=$(node -e 'const fs=require("node:fs"); console.log(JSON.parse(fs.readFileSync("notes-result.json","utf8")).runtimeId)')
63
58
  run_dir=$(node -e 'const fs=require("node:fs"),path=require("node:path"); console.log(path.dirname(JSON.parse(fs.readFileSync("notes-result.json","utf8")).reportPath))')
64
- node "$example/main.js" --result "$run_dir" --runtime-id "$runtime_id"
59
+ node_modules/.bin/anyswarm run "$example/main.ts" --result "$run_dir" --runtime-id "$runtime_id"
65
60
  ```
66
61
 
67
62
  Result inspection reads `harness-report.json` and `runtime.json`, checks both recorded identities, and projects business failure, recorded Core status, per-Agent execution/cleanup, pending count and artifact availability. It reports the Harness result's location without printing its content or interpreting business acceptance. Open the indicated Harness report's `result.verifiedFiles` and reader archive to inspect the actual checked deliverables. A pending receipt remains pending even if another recorded receipt later reports complete. This command reads saved files and does not contact or control a running Runtime.
68
63
 
69
- The running command exits 0 when its business function returned and cleanup and report save succeeded, and exits 1 when any of those failed. Result inspection exits 0 when both correctly identified reports were readable, including a recorded business failure, and exits 1 for missing, invalid, unreadable or foreign records. Invalid command arguments exit 2. Configuration import and startup failures emit a safe error code on stderr and exit 1. Run inspection with only its arguments; it does not load `config.js` or require provider credentials.
64
+ The running command exits 0 when its business function returned and cleanup and report save succeeded, and exits 1 when any of those failed. Result inspection exits 0 when both correctly identified reports were readable, including a recorded business failure, and exits 1 for missing, invalid, unreadable or foreign records. Invalid command arguments exit 2. Configuration import and startup failures emit a safe error code on stderr and exit 1. Run inspection with only its arguments; it does not load `config.ts` or require provider credentials.
70
65
 
71
66
  With the default configuration, each fresh Runtime writes its own directory under `notes-runs`. Read `harness-report.json` for the business result, input receipts, Notes state, cleanup and any save failure. Core writes `runtime.json`, the ordered evidence file and, on successful collection, the reader's artifacts and manifest. A required collection failure can leave a sandbox and Slot pending. Inspect the reported Agent/provider identity and original error. Handle pending ownership in the same host process if embedding the example. The one-shot CLI has no cross-process recovery command.
72
67
 
73
68
  ## Change the collaboration
74
69
 
75
- To use a different source observation, set `fact` in `config.js` to an object with `baseline`, `source` and `finding`. Edit `createNotes` and its manifest to change the business Service and adjust Profile grants as needed. The example has no Mission, Task or Execution records. It demonstrates explicit Service handoff and continuity for one reader. Model quality and automated source review are outside its scope.
70
+ To use a different source observation, set `fact` in `config.ts` to an object with `baseline`, `source` and `finding`. Edit `createNotes` and its manifest to change the business Service and adjust Profile grants as needed. The example has no Mission, Task or Execution records. It demonstrates explicit Service handoff and continuity for one reader. Model quality and automated source review are outside its scope.
76
71
 
77
72
  ## Host assembly
78
73