@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
@@ -3,7 +3,7 @@ import { resolve } from 'node:path';
3
3
  import { stdin, stderr } from 'node:process';
4
4
  import { createInterface } from 'node:readline/promises';
5
5
  import {
6
- checkLinuxHost, checkLocalDocker, checkLocalProvider, ensureLocalProvider, localExecdImage, localEgressImage, localProviderImage, resolveLocalEnvironment,
6
+ checkSetupHost, checkLocalDocker, checkLocalProvider, discoverMacCallback, ensureLocalProvider, localExecdImage, localEgressImage, localProviderImage, resolveLocalEnvironment,
7
7
  type DiagnosticCheck,
8
8
  } from './local-environment.js';
9
9
  import { runLocalSmoke } from './local-setup-smoke.js';
@@ -113,12 +113,28 @@ async function chooseBackend(
113
113
  command: LocalCommand, saved: LocalExecutorSelection | undefined, configured: ExecutorSelection | undefined, signal: AbortSignal,
114
114
  ): Promise<LocalExecutorSelection | undefined> {
115
115
  const explicit = command.command === 'setup' ? command.backend : undefined;
116
- if (command.command === 'setup' && command.backendPath && explicit) return { kind: explicit, entry: resolve(command.backendPath) };
116
+ const version = command.command === 'setup' ? command.backendVersion : undefined;
117
+ if (command.command === 'setup' && command.backendPath && explicit) return { kind: explicit, entry: resolve(command.backendPath), version };
117
118
  const preferred = explicit ?? (configured ? selectExecutorDriver(configured).kind : saved?.kind);
118
119
  if (preferred && preferred !== 'pi' && preferred !== 'codex') return;
119
120
  if (saved && (!preferred || preferred === saved.kind) && !explicit) return saved;
120
121
  if (preferred) {
121
122
  const kind = preferred as LocalExecutorSelection['kind'];
123
+ if (version !== undefined) {
124
+ const matches = async (entry: string) => {
125
+ try {
126
+ await checkLocalExecutor({ kind, entry, version }, signal);
127
+ return true;
128
+ } catch (error) {
129
+ signal.throwIfAborted();
130
+ if ((error as { code?: string }).code !== 'LOCAL_EXECUTOR_UNAVAILABLE') throw error;
131
+ return false;
132
+ }
133
+ };
134
+ if (saved?.kind === kind && await matches(saved.entry)) return { kind, entry: saved.entry, version };
135
+ const entry = await findExecutorEntry(kind, matches) ?? await findExecutorEntry(kind);
136
+ return entry ? { kind, entry, version } : undefined;
137
+ }
122
138
  const entry = await findExecutorEntry(kind);
123
139
  return entry ? { kind, entry } : undefined;
124
140
  }
@@ -169,7 +185,7 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
169
185
  model?: Model;
170
186
  modelUpstreamVerification: 'not-verified';
171
187
  configuration?: {
172
- executor: { id: string; version: string; compatibleVersions: readonly string[] };
188
+ executor: { id: string; version?: string; compatibleVersions?: readonly string[] };
173
189
  image: string;
174
190
  filePolicy: ResolvedFilePolicy;
175
191
  };
@@ -210,7 +226,8 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
210
226
  const config = command.configPath
211
227
  ? await loadAnySwarmConfig(command.configPath) as ProjectConfig : undefined;
212
228
  const configured = (config?.executor ?? process.env.ANYSWARM_EXECUTOR) as ExecutorSelection | undefined;
213
- let executor = (command.command === 'setup' ? command.backend : undefined) ?? configured;
229
+ let executor = command.command === 'setup' && command.backend
230
+ ? { kind: command.backend, version: command.backendVersion } : configured;
214
231
  const install = command.command === 'setup';
215
232
  let localExecutor: LocalExecutorSelection | undefined;
216
233
  let driver;
@@ -230,10 +247,16 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
230
247
  const smoke = install ? mode === 'local' : command.smoke;
231
248
  if (command.command === 'setup' && command.backend && mode !== 'local') {
232
249
  report.mode = mode;
233
- checks.push({ id: 'config.executor', ok: false, detail: 'Installation selection requires --mode local on the same Linux host.',
250
+ checks.push({ id: 'config.executor', ok: false, detail: 'Installation selection requires --mode local with a local Docker engine.',
234
251
  remedy: 'For an existing deployment, use its prepared Worker image.' });
235
252
  return report;
236
253
  }
254
+ if (command.command === 'setup' && environment.image && (command.backendPath || command.backendVersion)) {
255
+ report.mode = mode;
256
+ checks.push({ id: 'config.executor', ok: false, detail: 'An installation path or version pin requires a locally built Worker.',
257
+ remedy: 'Remove the configured Worker image to select an installation, or pin the version in the project executor configuration.' });
258
+ return report;
259
+ }
237
260
  if (smoke && mode === 'existing' && !environment.image && !driver.adapter) {
238
261
  report.mode = mode;
239
262
  checks.push({ id: 'config.worker', ok: false, detail: 'An existing service requires an explicitly prepared Worker image.',
@@ -250,7 +273,8 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
250
273
  });
251
274
  return report;
252
275
  }
253
- executor = localExecutor.kind;
276
+ if (driver.version !== undefined) localExecutor = { ...localExecutor, version: driver.version };
277
+ executor = { kind: localExecutor.kind, version: localExecutor.version };
254
278
  driver = selectExecutorDriver(executor);
255
279
  }
256
280
  if (!config && process.env.ANYSWARM_MODEL_URL) {
@@ -281,10 +305,20 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
281
305
  }
282
306
  if (checks.some(check => !check.ok)) return report;
283
307
  report.configuration = {
284
- executor: { id: driver.kind, version: driver.version, compatibleVersions: driver.compatibleVersions },
308
+ executor: { id: driver.kind, version: driver.version, compatibleVersions: driver.adapter?.compatibleVersions },
285
309
  image: environment.image ?? workerImageFor(executor),
286
310
  filePolicy: resolveFilePolicy(config?.filePolicy),
287
311
  };
312
+ if (localExecutor && !smoke) {
313
+ try {
314
+ report.configuration.executor.version = await checkLocalExecutor(localExecutor, signal);
315
+ } catch (error) {
316
+ signal.throwIfAborted();
317
+ if ((error as { code?: string }).code !== 'LOCAL_EXECUTOR_UNAVAILABLE') throw error;
318
+ checks.push({ id: 'config.executor', ok: false, detail: (error as Error).message });
319
+ return report;
320
+ }
321
+ }
288
322
  const publicUrl = environment.publicUrl ?? config?.connection?.bridge?.publicUrl ?? config?.connection?.modelGateway?.publicUrl;
289
323
  report.mode = mode;
290
324
  report.lifecycleSource = environment.endpointSource;
@@ -298,10 +332,12 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
298
332
  resolveWith: 'resolveSandboxConnection',
299
333
  };
300
334
  stage = 'host';
301
- checks.push(...checkLinuxHost());
335
+ const darwin = process.platform === 'darwin';
336
+ checks.push(...checkSetupHost({ requiresLinux: !darwin }));
302
337
  if (checks.some(check => !check.ok)) return report;
303
338
  let advertiseHost = environment.advertiseHost;
304
- if (mode === 'local' && smoke) {
339
+ let advertiseHostDiscovery = environment.advertiseHostDiscovery;
340
+ if (mode === 'local' && (smoke || darwin)) {
305
341
  const docker = await timed('host', checkLocalDocker);
306
342
  checks.push(docker.diagnostic);
307
343
  if (!docker.docker) return report;
@@ -326,8 +362,8 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
326
362
  report.connection.image = worker.image.reference;
327
363
  report.connection.sources.image = worker.source;
328
364
  report.configuration.image = worker.image.reference;
329
- if (localExecutor) {
330
- executor = { kind: localExecutor.kind, version: worker.image.version };
365
+ if (!driver.adapter && (worker.image.executor === 'pi' || worker.image.executor === 'codex')) {
366
+ executor = { kind: worker.image.executor, version: worker.image.version };
331
367
  report.configuration.executor.version = worker.image.version;
332
368
  }
333
369
  progress?.(`Worker image source: ${worker.source}`);
@@ -345,6 +381,20 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
345
381
  report.infrastructure = 'preflight-passed';
346
382
  if (smoke) {
347
383
  stage = 'smoke';
384
+ if (darwin && mode === 'local' && publicUrl === undefined &&
385
+ (advertiseHost === undefined || advertiseHostDiscovery === 'docker-network')) {
386
+ const discovered = await discoverMacCallback(image, signal);
387
+ if (!install && discovered !== advertiseHost) {
388
+ checks.push({ id: 'config.callback', ok: false, detail: 'The saved Runtime callback needs to be refreshed.',
389
+ remedy: 'Run anyswarm setup to save and verify the current Docker callback.' });
390
+ report.infrastructure = 'failed';
391
+ return report;
392
+ }
393
+ advertiseHost = discovered;
394
+ advertiseHostDiscovery = 'docker-network';
395
+ report.connection.advertiseHost = advertiseHost;
396
+ report.connection.sources.advertiseHost = 'docker-network';
397
+ }
348
398
  report.smoke = await timed('smoke', () => runLocalSmoke({
349
399
  ...active, image, sandbox: config?.sandbox, connection: {
350
400
  ...config?.connection, publicUrl: environment.publicUrl,
@@ -362,7 +412,7 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
362
412
  signal.throwIfAborted();
363
413
  if (install) {
364
414
  await saveSandboxConnection({ ...active, publicUrl: environment.publicUrl,
365
- advertiseHost, image: environment.image, localExecutor,
415
+ advertiseHost, advertiseHostDiscovery, image: environment.image, localExecutor,
366
416
  management: mode, providerId: provider?.id, preparedImage: report.worker?.id,
367
417
  egressMode: mode === 'local' ? 'dns+nft' : environment.egressMode });
368
418
  checks.push({ id: 'connection.saved', ok: true, detail: 'OpenSandbox connection saved in the owner-only user configuration.' });
@@ -379,7 +429,10 @@ export async function runLocalCommand(command: LocalCommand, signal: AbortSignal
379
429
  };
380
430
  let [detail, remedy] = failure[stage];
381
431
  const code = (error as { code?: string })?.code;
382
- if (stage === 'provider' && ['PROVIDER_EXECD_PULL_FAILED', 'PROVIDER_SERVER_PULL_FAILED', 'PROVIDER_EGRESS_PULL_FAILED'].includes(code ?? '')) {
432
+ if (code === 'DOCKER_CALLBACK_UNAVAILABLE') {
433
+ detail = 'The Docker container could not resolve a unique Mac callback IPv4 address.';
434
+ remedy = 'Check host.docker.internal from the selected local engine, or configure a Runtime publicUrl reachable from the Sandbox.';
435
+ } else if (stage === 'provider' && ['PROVIDER_EXECD_PULL_FAILED', 'PROVIDER_SERVER_PULL_FAILED', 'PROVIDER_EGRESS_PULL_FAILED'].includes(code ?? '')) {
383
436
  const execd = code === 'PROVIDER_EXECD_PULL_FAILED';
384
437
  const egress = code === 'PROVIDER_EGRESS_PULL_FAILED';
385
438
  detail = `Docker could not pull the pinned OpenSandbox ${execd ? 'Execd' : egress ? 'egress' : 'server'} image.`;
@@ -302,8 +302,8 @@ async function startAgent(input: any) {
302
302
  } else if (executorKind === 'codex') {
303
303
  const version = spawnSync('setpriv', [...unprivileged, 'codex', '--version'],
304
304
  { cwd, env: agentEnvironment, timeout: 5_000, encoding: 'utf8' });
305
- executorVersion = input.executor_version ?? '0.172.0';
306
- if (version.status !== 0 || version.stdout.trim() !== `codex-cli ${executorVersion}`) {
305
+ executorVersion = input.executor_version ?? input.codex.version;
306
+ if (typeof executorVersion !== 'string' || version.status !== 0 || version.stdout.trim() !== `codex-cli ${executorVersion}`) {
307
307
  throw startupContractError('Codex CLI version differs from the Runtime selection');
308
308
  }
309
309
  const configuration = [
@@ -0,0 +1,67 @@
1
+ import { execFile, spawnSync } from 'node:child_process';
2
+ import { chmod, mkdir, mkdtemp, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join, resolve } from 'node:path';
5
+ import { promisify } from 'node:util';
6
+
7
+ const [destination, ...options] = process.argv.slice(2);
8
+ if (!destination || (options.length && options.join(' ') !== '--skip-build')) {
9
+ throw new Error('Usage: npm run pack:release -- <output-directory> [--skip-build]');
10
+ }
11
+
12
+ // Keep the build and staging umask independent of the caller.
13
+ process.umask(0o022);
14
+
15
+ const run = promisify(execFile);
16
+ const repository = resolve(import.meta.dirname, '..');
17
+ const output = resolve(destination);
18
+ if (!options.length) {
19
+ const build = spawnSync('npm', ['run', 'build'], { cwd: repository, stdio: ['ignore', 2, 2] });
20
+ if (build.error) throw build.error;
21
+ if (build.status !== 0) process.exit(build.status ?? 1);
22
+ }
23
+
24
+ async function pack(directory: string, destination: string): Promise<string> {
25
+ const { stdout } = await run('npm', ['pack', '--ignore-scripts', '--json', '--pack-destination', destination], {
26
+ cwd: directory, maxBuffer: 4 * 1024 ** 2,
27
+ });
28
+ return JSON.parse(stdout)[0].filename;
29
+ }
30
+
31
+ const temporary = await mkdtemp(join(tmpdir(), 'anyswarm-pack-release-'));
32
+ try {
33
+ // Start from npm's allowlist so private checkout files never enter staging.
34
+ const sourceArchive = await pack(repository, temporary);
35
+ await run('tar', ['-xzf', join(temporary, sourceArchive), '-C', temporary]);
36
+ const staged = join(temporary, 'package');
37
+ const manifestPath = join(staged, 'package.json');
38
+ const lockPath = join(staged, 'npm-shrinkwrap.json');
39
+ const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
40
+ const lock = JSON.parse(await readFile(lockPath, 'utf8'));
41
+ if (lock.lockfileVersion !== 3 || !lock.packages?.['']) {
42
+ throw new Error('Release packaging requires a v3 npm shrinkwrap with root package metadata');
43
+ }
44
+
45
+ // Only the service-image build stages use the development inputs.
46
+ await rename(manifestPath, join(staged, 'package.development.json'));
47
+ await rename(lockPath, join(staged, 'npm-shrinkwrap.development.json'));
48
+ delete manifest.private;
49
+ delete manifest.devDependencies;
50
+ delete lock.packages[''].devDependencies;
51
+ lock.packages = Object.fromEntries(
52
+ Object.entries<{ dev?: boolean }>(lock.packages).filter(([, entry]) => !entry.dev),
53
+ );
54
+ await writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
55
+ await writeFile(lockPath, JSON.stringify(lock, null, 2) + '\n');
56
+ // npm records existing file modes, which can also depend on the checkout umask.
57
+ for (const entry of await readdir(staged, { recursive: true, withFileTypes: true })) {
58
+ if (!entry.isFile()) continue;
59
+ const path = join(entry.parentPath, entry.name);
60
+ const { mode } = await stat(path);
61
+ await chmod(path, mode & 0o111 ? 0o755 : 0o644);
62
+ }
63
+ await mkdir(output, { recursive: true });
64
+ console.log(join(output, await pack(staged, output)));
65
+ } finally {
66
+ await rm(temporary, { recursive: true, force: true });
67
+ }
@@ -6,6 +6,7 @@ import { createHash } from 'node:crypto';
6
6
  import { createInterface } from 'node:readline';
7
7
  import { assertPiThinkingLevel, createPiSessionController, PI_SESSION_CAPABILITIES } from './pi-session-controller.js';
8
8
  import { createPiServiceTools } from './pi-service-tools.js';
9
+ import { executorVersion } from '../src/core/executor-adapter.js';
9
10
  import { PI_SESSION_OUTPUT_LIMIT as maximumOutputBytes } from './pi-session-diagnostics.js';
10
11
 
11
12
  // This module is a Guest executable. Core never imports the Pi runtime.
@@ -16,11 +17,18 @@ async function loadPi() {
16
17
  const sdk: any = await import(entry);
17
18
  const packagePath = new URL('../package.json', entry);
18
19
  const metadata = JSON.parse(await readFile(packagePath, 'utf8'));
19
- if (!['1.3.0', '1.4.0'].includes(metadata.version)) throw new Error('Unsupported Pi SDK bridge version');
20
+ if (!executorVersion(metadata.version) || [
21
+ sdk.SettingsManager?.inMemory, sdk.DefaultResourceLoader, sdk.ModelRuntime?.create,
22
+ sdk.SessionManager?.create, sdk.SessionManager?.open,
23
+ sdk.createAgentSession, sdk.createCodemodeExtension, sdk.createToolSearchExtension,
24
+ ].some(required => typeof required !== 'function')) {
25
+ throw new Error('The installed Pi package does not expose the required Session Bridge API');
26
+ }
20
27
  return { sdk, version: metadata.version };
21
28
  }
22
- const options = JSON.parse(await readFile(process.argv[2], 'utf8'));
23
29
  const { sdk, version } = await loadPi();
30
+ if (process.argv[2] === '--check-sdk') process.exit(0);
31
+ const options = JSON.parse(await readFile(process.argv[2], 'utf8'));
24
32
  const args: string[] = options.args ?? [];
25
33
  const argument = (name: string) => { const index = args.indexOf(name); return index < 0 ? undefined : args[index + 1]; };
26
34
  const cwd = process.cwd();
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { resolve } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
+ import { installSourceLoader } from '../src/harness/typescript-loader.js';
4
5
 
5
- const usage = 'node dist/scripts/run-harness.js --config <host-module.mjs>';
6
+ const usage = 'node dist/scripts/run-harness.js --config <host-module.ts>';
6
7
  const args = process.argv.slice(2);
7
8
  const lifetime = new AbortController();
8
9
  const stop = () => lifetime.abort();
@@ -32,6 +33,7 @@ try {
32
33
  await writeOutput(`${usage}\nConfiguration default export selects mode (taskpool or peermesh), options and finite timeoutMs. Read JSON-line status, kickoff, input, wait or stop commands from stdin.\n`);
33
34
  } else {
34
35
  if (args.length !== 2 || args[0] !== '--config' || !args[1] || args[1].startsWith('--')) throw Object.assign(new Error(), { code: 'HOST_ARGUMENTS_INVALID' });
36
+ installSourceLoader();
35
37
  const { default: configuration } = await import(pathToFileURL(resolve(args[1])).href);
36
38
  const { keepsForegroundCommandsOpen, runForegroundHarness } = await import('../src/cli/foreground-harnesses.js');
37
39
  const { runForegroundCommands } = await import('../src/harness/foreground-commands.js');
@@ -93,6 +93,35 @@ async function lockedSetup(startedAt: number, options: string[]) {
93
93
  { ...process.env, ANYSWARM_SETUP_BOOTSTRAP: JSON.stringify(bootstrap) }, true);
94
94
  }
95
95
 
96
+ async function macCheckoutSetup(startedAt: number, options: string[]) {
97
+ signal.throwIfAborted();
98
+ const lock = spawn('/usr/bin/lockf', ['-kn', '-t', '180', root, process.execPath, '-e',
99
+ 'console.log("locked"); process.stdin.resume()'], { stdio: ['pipe', 'pipe', 'inherit'] });
100
+ lock.stdin.on('error', () => {});
101
+ const cancel = () => lock.kill('SIGTERM');
102
+ signal.addEventListener('abort', cancel, { once: true });
103
+ try {
104
+ const acquired = await new Promise<boolean>((ready, reject) => {
105
+ lock.once('error', reject);
106
+ lock.once('exit', code => {
107
+ if (code === 75) ready(false);
108
+ else reject(new Error('Could not lock the checkout.'));
109
+ });
110
+ lock.stdout.once('data', () => ready(true));
111
+ });
112
+ signal.removeEventListener('abort', cancel);
113
+ signal.throwIfAborted();
114
+ if (!acquired) {
115
+ failure('checkout-lock', 'Another setup still holds the checkout lock.', 'Wait for the other invocation and rerun setup.');
116
+ return 1;
117
+ }
118
+ return await lockedSetup(startedAt, options);
119
+ } finally {
120
+ signal.removeEventListener('abort', cancel);
121
+ lock.stdin.end();
122
+ }
123
+ }
124
+
96
125
  const args = process.argv.slice(2);
97
126
  const lockInvocation = args[0] === '--under-checkout-lock';
98
127
  try {
@@ -104,17 +133,23 @@ try {
104
133
  if ('help' in command) {
105
134
  console.log(command.help);
106
135
  } else {
107
- if (process.platform !== 'linux') {
108
- failure('host.linux', 'Setup requires Linux.', 'Run this command on Linux.');
136
+ if (process.platform !== 'linux' && process.platform !== 'darwin') {
137
+ failure('host.platform', 'Setup requires Linux or macOS.', 'Run this command on Linux or macOS.');
109
138
  process.exitCode = 1;
110
139
  } else if (command.command === 'setup') {
111
140
  const options = [
112
141
  ...(command.mode ? ['--mode', command.mode] : []),
142
+ ...(command.endpoint ? ['--endpoint', command.endpoint] : []),
143
+ ...(command.publicUrl ? ['--public-url', command.publicUrl] : []),
144
+ ...(command.backend ? ['--backend', command.backend] : []),
145
+ ...(command.backendVersion ? ['--backend-version', command.backendVersion] : []),
146
+ ...(command.backendPath ? ['--backend-path', resolve(command.backendPath)] : []),
113
147
  ...(command.configPath ? ['--config', resolve(command.configPath)] : []),
114
148
  ];
115
- process.exitCode = await child('flock', ['--no-fork', '--exclusive', '--timeout', '180', '--conflict-exit-code', '73',
116
- root, process.execPath, '--disable-warning=ExperimentalWarning', script, '--under-checkout-lock',
117
- String(startedAt), ...options], process.env, true);
149
+ process.exitCode = process.platform === 'darwin' ? await macCheckoutSetup(startedAt, options)
150
+ : await child('flock', ['--no-fork', '--exclusive', '--timeout', '180', '--conflict-exit-code', '73',
151
+ root, process.execPath, '--disable-warning=ExperimentalWarning', script, '--under-checkout-lock',
152
+ String(startedAt), ...options], process.env, true);
118
153
  if (process.exitCode === 73) {
119
154
  failure('checkout-lock', 'Another setup still holds the checkout lock.', 'Wait for the other invocation and rerun setup.');
120
155
  process.exitCode = 1;
@@ -130,7 +165,7 @@ try {
130
165
  console.error(setupUsage);
131
166
  process.exitCode = 2;
132
167
  } else {
133
- failure('bootstrap', 'The checkout could not be prepared.', 'Check Node.js, npm, flock and permissions on this checkout.');
168
+ failure('bootstrap', 'The checkout could not be prepared.', 'Check Node.js, npm, platform lock tools and permissions on this checkout.');
134
169
  process.exitCode = 1;
135
170
  }
136
171
  }
@@ -3,6 +3,7 @@ import { constants, closeSync, fstatSync, lstatSync, mkdirSync, openSync, readFi
3
3
  import { hostname } from 'node:os';
4
4
  import { join, resolve } from 'node:path';
5
5
  import { DatabaseSync } from 'node:sqlite';
6
+ import { darwinBootSession } from './host-identity.js';
6
7
 
7
8
  export type AllocationState = 'intent' | 'dispatched' | 'created' | 'starting' | 'ready' | 'unknown' | 'stopping' | 'exporting' | 'retained' | 'deleting' | 'deleted' | 'rejected';
8
9
  export type AllocationRunState = 'open' | 'closing' | 'closed';
@@ -126,9 +127,10 @@ function currentHostIdentity() {
126
127
  // recreated Pod can differ in hostname while retaining the same node boot.
127
128
  const node = process.env.ANYSWARM_RUNTIME_NODE_NAME;
128
129
  const identities = [node ? 'kubernetes' : 'host', node || hostname()];
129
- try { identities.push(readFileSync('/proc/sys/kernel/random/boot_id', 'utf8').trim()); }
130
- catch { throw fault('NOT_ALLOWED', 'Durable Runtime requires the Linux kernel boot identity'); }
131
- if (!node) {
130
+ try {
131
+ identities.push(process.platform === 'darwin' ? darwinBootSession() : readFileSync('/proc/sys/kernel/random/boot_id', 'utf8').trim());
132
+ } catch { throw fault('NOT_ALLOWED', 'Durable Runtime requires a verified kernel boot identity'); }
133
+ if (!node && process.platform !== 'darwin') {
132
134
  try { identities.push(readFileSync('/etc/machine-id', 'utf8').trim()); } catch { /* hostname and boot ID still identify the owner */ }
133
135
  }
134
136
  return createHash('sha256').update(identities.join('\n')).digest('hex');
@@ -0,0 +1,11 @@
1
+ import { execFileSync } from 'node:child_process';
2
+
3
+ let bootSession: string | undefined;
4
+
5
+ /** Cache only a verified UUID: a running Controller cannot survive a reboot. */
6
+ export function darwinBootSession() {
7
+ if (bootSession) return bootSession;
8
+ const uuid = execFileSync('/usr/sbin/sysctl', ['-n', 'kern.bootsessionuuid'], { encoding: 'utf8', timeout: 2_000 }).trim();
9
+ if (!/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(uuid)) throw new Error('Invalid Darwin boot session UUID');
10
+ return bootSession = `darwin:${uuid.toLowerCase()}`;
11
+ }
package/src/core/index.ts CHANGED
@@ -26,7 +26,7 @@ import { createRedactor, createRunRecords, runtimeConfiguration } from './run-re
26
26
  import { createRuntimeManagement } from './runtime-management.js';
27
27
  import { claimOpenSandboxBackend, openOpenSandboxBackend } from './sandbox/opensandbox-backend.js';
28
28
  import { isOfficialWorkerImage, localWorkerSelector } from './worker-image.js';
29
- import { selectExecutorDriver } from './sandbox/executor-driver.js';
29
+ import { legacyImageExecutorVersion, selectExecutorDriver } from './sandbox/executor-driver.js';
30
30
  import { findExecutorEntry, executorFailure } from './sandbox/local-executor.js';
31
31
  import { prepareLocalWorker, workerFailure, type LocalWorker } from './sandbox/local-worker.js';
32
32
  import { loopbackLifecycle, resolveSandboxConnectionWithSources } from './sandbox/sandbox-connection.js';
@@ -45,10 +45,11 @@ export type {
45
45
  HarnessAnswerReceipt, HarnessCapability, HarnessDescriptor, HarnessEvent, HarnessInputDescriptor,
46
46
  HarnessInputReceipt, HarnessLifetime, HarnessOperation, HarnessPhase, HarnessQuestion, HarnessQuestionKind,
47
47
  HarnessQuestionRequest, HarnessQuestionSource, HarnessRequest, HarnessDispatchRequest, HarnessResult, HarnessSession,
48
- HarnessSessionOptions, HarnessStartReceipt, HarnessState, HarnessStopReceipt, HarnessSubscriptionOptions,
48
+ HarnessServices, HarnessSessionOptions, HarnessStartReceipt, HarnessState, HarnessStopReceipt, HarnessSubscriptionOptions,
49
49
  } from '../harness/harness-session-types.js';
50
50
  export { ProjectPreflightError } from '../harness/project-input.js';
51
51
  export { HarnessRpcClient } from '../harness/project-rpc-client.js';
52
+ export { runProjectRpc } from '../harness/project-rpc.js';
52
53
  export type { HarnessRpcClientOptions, HarnessRpcReady, HarnessRpcTransport } from '../harness/project-rpc-client.js';
53
54
  export { observeProjectRuntime, projectConfiguration, projectResult } from '../harness/project-runtime.js';
54
55
  export { runInput, type RunInputResult } from '../harness/run-input.js';
@@ -60,6 +61,7 @@ export { httpClient } from '../harness/http.js';
60
61
  export { checkGitProject, seedTeamRepository, seededCheckoutInstruction } from '../harness/project-git.js';
61
62
  export { initializeGitRepository, importGitTree, commitGitTree, isGitTreePath } from '../harness/git-tree.js';
62
63
  export { decodeFileSeed as decodeFileTree, snapshotFileSeed as snapshotFileTree, completeDigest as completeFileTreeDigest } from './files/core-file-seed.js';
64
+ export { resolveFilePolicy } from './file-policy.js';
63
65
  export { AnySwarmError } from '../errors.js';
64
66
  export { requestHttp } from '../protocol/http-request.js';
65
67
  export { stableStringify } from '../protocol/stable-json.js';
@@ -73,7 +75,7 @@ export { DEFAULT_WORKER_IMAGE, workerImageFor } from './worker-image.js';
73
75
  export { ServiceRegistry, serviceFromManifest, inProcessService, httpService, createInProcessAdapter, createHttpJsonAdapter, createServiceReplyAdapter } from './services.js';
74
76
  export { mcpService } from './mcp-service.js';
75
77
  export type { McpServiceOptions, McpHttpServiceOptions, McpStdioServiceOptions } from './mcp-service.js';
76
- export type { ServiceStateMetadata, ServiceStatePresentation } from './service-observation-types.js';
78
+ export type { ServiceLiveState, ServiceStateMetadata, ServiceStatePresentation, ServiceStateRead, ServiceStateSource } from './service-observation-types.js';
77
79
  export { managedProcessLifecycle } from './service-process.js';
78
80
  export type { ManagedProcessOptions } from './service-process.js';
79
81
  export type { ServiceLifecycle, ServiceLifecycleContext, ServiceStorage, ServiceResources } from './service-lifecycle-types.js';
@@ -227,14 +229,14 @@ function planRuntimeWorker(
227
229
  const configuredEntry = options.localWorker?.backendPath
228
230
  ? resolve(options.localWorker.backendPath) : localExecutor?.kind === kind ? localExecutor.entry : undefined;
229
231
  const requiredVersions = new Set(selectors.flatMap(selector => selector.version ? [selector.version] : []));
230
- if (typeof options.executor === 'object') requiredVersions.add(config.driver.version);
232
+ if (config.driver.version !== undefined) requiredVersions.add(config.driver.version);
231
233
  if (requiredVersions.size > 1) throw executorFailure('All local Worker selectors must match the selected installation version.');
232
234
  const [requiredVersion] = requiredVersions;
233
235
  const progress = options.localWorker?.onProgress;
234
236
  return { kind: kind as LocalWorker["executor"], prepare: async () => {
235
237
  const entry = configuredEntry ?? await findExecutorEntry(kind);
236
238
  if (!entry) throw executorFailure(`No local ${kind} executable was found. Install it with npm and run the CLI from this SDK package with setup --backend ${kind}.`);
237
- return prepareLocalWorker({ kind, entry }, { progress, requiredVersion });
239
+ return prepareLocalWorker({ kind, entry }, { progress, requiredVersion: requiredVersion ?? (configuredEntry === localExecutor?.entry ? localExecutor?.version : undefined) });
238
240
  } };
239
241
  }
240
242
 
@@ -318,6 +320,9 @@ async function assembleRuntime(options: CreateRuntimeOptions, recovery?: { runti
318
320
  localWorker = await plan.prepare();
319
321
  config = Object.freeze({ ...config, driver: selectExecutorDriver({ kind: localWorker.executor, version: localWorker.version }) });
320
322
  for (const [id, profile] of profiles) profiles.set(id, freezeProfileWorker(profile, config, localWorker));
323
+ } else if (config.driver.version === undefined) {
324
+ const version = legacyImageExecutorVersion(config.driver.kind);
325
+ if (version !== undefined) config = Object.freeze({ ...config, driver: selectExecutorDriver({ kind: config.driver.kind, version }) });
321
326
  }
322
327
  if (options.persistence) {
323
328
  const { deploymentId, contract, retainForMs: duration = 900_000 } = options.persistence;
@@ -334,7 +339,7 @@ async function assembleRuntime(options: CreateRuntimeOptions, recovery?: { runti
334
339
  }));
335
340
  const fingerprintInput = { contract, connectionFingerprint, callback: config.callback, limits, retainForMs,
336
341
  ...(options.hooks?.beforeCompact ? { beforeCompactTimeoutMs: options.hooks.beforeCompact.timeoutMs ?? 10_000 } : {}),
337
- models: modelConfig, modelGateway: config.modelGateway, executor: [config.driver.kind, config.driver.version],
342
+ models: modelConfig, modelGateway: config.modelGateway, executor: [config.driver.kind, config.driver.version ?? legacyImageExecutorVersion(config.driver.kind)],
338
343
  profiles: Object.fromEntries(profiles), services: [...registrations.values()].map(registration => registration.manifest).sort((a, b) => a.id.localeCompare(b.id)),
339
344
  files: config.filePolicy, requests: config.sandbox.resourceRequests, limitsSandbox: config.sandbox.resourceLimits };
340
345
  const configFingerprint = fingerprint(fingerprintInput);
@@ -1318,6 +1323,7 @@ async function assembleRuntime(options: CreateRuntimeOptions, recovery?: { runti
1318
1323
  const wasClosing = closing;
1319
1324
  durable(owner => owner.beginClose());
1320
1325
  closing = true;
1326
+ management.cancelServiceStateReads();
1321
1327
  if (!closeWork) {
1322
1328
  for (const agent of agents.values()) revoke(agent.info.id);
1323
1329
  closeWork = Promise.resolve().then(async () => {
@@ -80,11 +80,11 @@ function mcpEndpoint(options: McpServiceOptions) {
80
80
  } }),
81
81
  };
82
82
  }
83
- if (process.platform !== 'linux' || !isAbsolute(options.command) ||
83
+ if (!['linux', 'darwin'].includes(process.platform) || !isAbsolute(options.command) ||
84
84
  (options.args !== undefined && (!Array.isArray(options.args) || options.args.some(argument => typeof argument !== 'string'))) ||
85
85
  (options.cwd !== undefined && !isAbsolute(options.cwd)) ||
86
86
  (options.env !== undefined && Object.values(options.env).some(value => typeof value !== 'string'))) {
87
- throw new AnySwarmError('INVALID_CONTRACT', 'Managed MCP stdio requires Linux, an absolute executable and typed argv/environment');
87
+ throw new AnySwarmError('INVALID_CONTRACT', 'Managed MCP stdio requires Linux or macOS, an absolute executable and typed argv/environment');
88
88
  }
89
89
  const parameters = { command: options.command, args: [...options.args ?? []], cwd: options.cwd,
90
90
  env: Object.fromEntries(Object.entries(options.env ?? {}).sort(([a], [b]) => a.localeCompare(b))) };
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import type { JsonValue } from './service-types.js';
3
3
  import type { ServiceLifecycleContext } from './service-lifecycle-types.js';
4
+ import { createServiceStateReader } from './service-live-state.js';
4
5
  import { createHash } from 'node:crypto';
5
6
  import type {
6
7
  AgentAccess, AgentAccessGrant, AgentAccessMutation, ErrorInfo, PendingCleanup, Profile, ProfileDefinition, ProfileRegistration, RuntimeManagementChange,
@@ -86,6 +87,7 @@ export function createRuntimeManagement({
86
87
 
87
88
  const serviceRequests = new Map<string, { digest: string; adapter: ServiceRegistration['adapter']; result: RuntimeServiceDefinition }>();
88
89
  const services = new Map<string, RegisteredService>();
90
+ const stateReader = createServiceStateReader(redact);
89
91
  const unresolvedServices = new Map<string, RuntimeServiceDefinition>();
90
92
  const unresolvedDynamic = new Map<string, boolean>();
91
93
  const remoteWrites = new Map<string, { serviceId: string; operation: string; operationId: string; state: 'dispatched' | 'unknown' }>();
@@ -196,6 +198,7 @@ export function createRuntimeManagement({
196
198
  changed({ operation: 'service.start', sequence, caller: 'host', requestId: 'directory-change', definition: service.definition });
197
199
  } catch (error) {
198
200
  registrations.delete(serviceId);
201
+ if (service.definition.instanceId) stateReader.cancel(service.definition.instanceId);
199
202
  lifecycleChange(service, 'service.start', 'blocked', 'directory-change', {
200
203
  code: 'INVALID_CONTRACT', message: String(redact((error as Error).message)), retryable: false,
201
204
  });
@@ -218,6 +221,7 @@ export function createRuntimeManagement({
218
221
  const lifecycle = service.registration.lifecycle!;
219
222
  lifecycleRequests.set(key, {});
220
223
  service.action = 'start';
224
+ if (service.definition.instanceId) stateReader.reset(service.definition.instanceId);
221
225
  service.registration = { ...service.registration, instanceId: `${runtimeId}:${input.serviceId}:${randomUUID()}` };
222
226
  service.definition = { ...service.definition, instanceId: service.registration.instanceId };
223
227
  lifecycleChange(service, 'service.start', 'starting', input.requestId);
@@ -261,6 +265,7 @@ export function createRuntimeManagement({
261
265
  if (service.recoveryBlocked) throw problem('RECOVERY_BLOCKED', 'Original Service identity must be reconciled before stop');
262
266
  lifecycleRequests.set(key, { instanceId: service.definition.instanceId });
263
267
  registrations.delete(input.serviceId);
268
+ if (service.definition.instanceId) stateReader.cancel(service.definition.instanceId);
264
269
  service.unwatch?.();
265
270
  service.unwatch = undefined;
266
271
  service.action = 'stop';
@@ -368,6 +373,20 @@ export function createRuntimeManagement({
368
373
  return [...new Set([...services.keys(), ...unresolvedServices.keys()])].map(id => serviceGet(id)!);
369
374
  }
370
375
 
376
+ function listServiceState() {
377
+ return [...services].map(([name, service]) => ({ name, supported: !!service.registration.adapter.readState }));
378
+ }
379
+
380
+ function readServiceState(name: string) {
381
+ const service = services.get(name);
382
+ const instanceId = service?.definition.instanceId;
383
+ return stateReader.read(service && instanceId ? {
384
+ instanceId,
385
+ readState: service.registration.adapter.readState,
386
+ ready: () => !isClosing() && service.definition.state === 'ready' && service.definition.instanceId === instanceId && registrations.has(name),
387
+ } : undefined);
388
+ }
389
+
371
390
  async function registerService(parameters: RuntimeServiceRegistration) {
372
391
  const input = parameters && 'name' in parameters ? {
373
392
  requestId: parameters.requestId, actorId: parameters.actorId,
@@ -436,6 +455,7 @@ export function createRuntimeManagement({
436
455
  if (service.work) await waitForWork(service, timeoutMs);
437
456
  if (service.work) return serviceGet(serviceId)!;
438
457
  registrations.delete(serviceId);
458
+ if (service.definition.instanceId) stateReader.cancel(service.definition.instanceId);
439
459
  service.unwatch?.();
440
460
  service.unwatch = undefined;
441
461
  service.retirement = { requestId, caller };
@@ -684,12 +704,14 @@ export function createRuntimeManagement({
684
704
  return {
685
705
  profiles: Object.freeze({ register: (input: ProfileRegistration) => registerProfile(input), get: profileGet, list: profileList }),
686
706
  services: Object.freeze({ register: (input: RuntimeServiceRegistration) => registerService(input), get: serviceGet, list: serviceList,
707
+ listState: listServiceState, readState: readServiceState,
687
708
  start: startService, stop: stopService, restart: restartService, health: serviceHealth,
688
709
  retire: (input: ServiceRetirement) => retireService(input) }),
689
710
  access: Object.freeze({ get: accessGet,
690
711
  grant: (input: AgentAccessGrant) => mutateAccess('grant', input), revoke: (input: AgentAccessMutation) => mutateAccess('revoke', input) }),
691
712
  mutateAccess, initAccess, bridgeAccess, checkpoint, restore,
692
713
  recordRemoteWrite, prepareAll, retireAll, pendingServices, knowsService: (id: string) => services.has(id),
714
+ cancelServiceStateReads: () => stateReader.cancel(),
693
715
  retiredExports: () => ownedRetirements().flatMap(({ definition, exported }) => exported ? [{ serviceId: definition.id, ...exported }] : []),
694
716
  profileDigest: (id: string) => definitions.get(id)?.digest,
695
717
  snapshot: () => ({ sequence, profiles: profileList(), services: serviceList(), access: [...access.keys()].map(id => accessGet(id)!) }),