@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,7 +2,7 @@ import { isIP } from 'node:net';
2
2
  import { resolve } from 'node:path';
3
3
  import { stdin, stderr } from 'node:process';
4
4
  import { createInterface } from 'node:readline/promises';
5
- import { checkLinuxHost, checkLocalDocker, checkLocalProvider, ensureLocalProvider, localExecdImage, localEgressImage, localProviderImage, resolveLocalEnvironment, } from './local-environment.js';
5
+ import { checkSetupHost, checkHostTools, checkLocalDocker, checkLocalProvider, discoverMacCallback, ensureLocalProvider, localExecdImage, localEgressImage, localProviderImage, resolveLocalEnvironment, } from './local-environment.js';
6
6
  import { runLocalSmoke } from './local-setup-smoke.js';
7
7
  import { prepareWorkerImage } from './local-setup-worker.js';
8
8
  import { selectExecutorDriver } from '../src/core/sandbox/executor-driver.js';
@@ -12,7 +12,7 @@ import { resolveFilePolicy } from '../src/core/file-policy.js';
12
12
  import { claimOpenSandboxBackend, createSandbox } from '../src/core/sandbox/opensandbox-backend.js';
13
13
  import { snapshotModel } from '../src/core/model/model-access.js';
14
14
  import { modelClientProtocol } from '../src/core/model/model-transport.js';
15
- import { loadAnySwarmConfig, saveSandboxConnection } from '../src/core/sandbox/sandbox-connection.js';
15
+ import { loadAnySwarmConfig, loopbackLifecycle, saveSandboxConnection } from '../src/core/sandbox/sandbox-connection.js';
16
16
  function modelState(config, executor) {
17
17
  if (config.models === undefined)
18
18
  return { configuration: 'missing', verification: 'not-verified' };
@@ -87,10 +87,12 @@ function reportedHost(value) {
87
87
  if (value && (/^[a-zA-Z0-9._-]+$/.test(value) || isIP(value)))
88
88
  return value;
89
89
  }
90
- function installNextStep(command) {
91
- return command.command === 'setup'
92
- ? 'Run your Harness with the same environment and resolveSandboxConnection(), or repeat the probe with anyswarm doctor --smoke.'
93
- : 'Run your Harness with the same environment.';
90
+ function installNextStep(command, mode) {
91
+ if (command.command !== 'setup')
92
+ return 'Run your Harness with the same environment.';
93
+ return mode === 'local'
94
+ ? 'Run your Harness with the same environment, or repeat the probe with anyswarm doctor --smoke.'
95
+ : 'Run your Harness with the same environment, or check the existing service with anyswarm doctor --mode existing --smoke.';
94
96
  }
95
97
  const phaseLabels = {
96
98
  host: 'Check local Docker',
@@ -99,43 +101,68 @@ const phaseLabels = {
99
101
  worker: 'Prepare Worker image',
100
102
  smoke: 'Start Worker and check Bridge, controlled Gateway, files and deletion',
101
103
  };
104
+ async function probeBackend(selection, signal) {
105
+ try {
106
+ return { selection, version: await checkLocalExecutor(selection, signal) };
107
+ }
108
+ catch (error) {
109
+ signal.throwIfAborted();
110
+ if (error.code !== 'LOCAL_EXECUTOR_UNAVAILABLE')
111
+ throw error;
112
+ return { selection, error: error.message };
113
+ }
114
+ }
115
+ async function backendOnPath(kind, version, signal) {
116
+ let firstFailure;
117
+ let available;
118
+ await findExecutorEntry(kind, async (entry) => {
119
+ const candidate = await probeBackend({ kind, entry, version }, signal);
120
+ if ('version' in candidate) {
121
+ available = candidate;
122
+ return true;
123
+ }
124
+ firstFailure ??= candidate;
125
+ return false;
126
+ });
127
+ return available ?? firstFailure;
128
+ }
102
129
  async function chooseBackend(command, saved, configured, signal) {
103
130
  const explicit = command.command === 'setup' ? command.backend : undefined;
104
- if (command.command === 'setup' && command.backendPath && explicit)
105
- return { kind: explicit, entry: resolve(command.backendPath) };
106
- const preferred = explicit ?? (configured ? selectExecutorDriver(configured).kind : saved?.kind);
107
- if (preferred && preferred !== 'pi' && preferred !== 'codex')
108
- return;
109
- if (saved && (!preferred || preferred === saved.kind) && !explicit)
110
- return saved;
111
- if (preferred) {
112
- const kind = preferred;
113
- const entry = await findExecutorEntry(kind);
114
- return entry ? { kind, entry } : undefined;
131
+ const driver = explicit || configured === undefined ? undefined : selectExecutorDriver(configured);
132
+ const preferred = explicit ?? driver?.kind ?? saved?.kind;
133
+ const version = explicit && command.command === 'setup' ? command.backendVersion : driver?.version;
134
+ if (command.command === 'setup' && command.backendPath && explicit) {
135
+ return probeBackend({ kind: explicit, entry: resolve(command.backendPath), version }, signal);
136
+ }
137
+ if (preferred === 'pi' || preferred === 'codex') {
138
+ if (saved?.kind === preferred && !explicit)
139
+ return probeBackend({ ...saved, version: version ?? saved.version }, signal);
140
+ if (saved?.kind === preferred && version !== undefined) {
141
+ const candidate = await probeBackend({ ...saved, version }, signal);
142
+ if ('version' in candidate)
143
+ return candidate;
144
+ }
145
+ return await backendOnPath(preferred, version, signal) ??
146
+ { issue: `Could not find the selected ${preferred} executable on PATH.` };
115
147
  }
116
- const installed = (await Promise.all(['pi', 'codex'].map(async (kind) => {
117
- const entry = await findExecutorEntry(kind);
118
- return entry ? { kind, entry } : undefined;
119
- }))).filter(value => value !== undefined);
120
- if (installed.length <= 1)
121
- return installed[0];
148
+ const detected = await Promise.all(['pi', 'codex'].map(kind => backendOnPath(kind, undefined, signal)));
149
+ const compatible = detected.filter(candidate => candidate !== undefined && 'version' in candidate);
150
+ if (compatible.length === 0) {
151
+ const errors = detected.filter(candidate => candidate !== undefined && 'error' in candidate).map(candidate => candidate.error);
152
+ return { issue: errors.length ? errors.join(' ') : 'Neither Pi nor Codex was found on PATH.' };
153
+ }
154
+ if (compatible.length === 1)
155
+ return compatible[0];
156
+ const selectBackend = { issue: 'Both Pi and Codex have compatible installations. Choose a backend to use.', ambiguous: true };
122
157
  if (command.command !== 'setup' || !stdin.isTTY || !stderr.isTTY)
123
- return;
158
+ return selectBackend;
124
159
  const input = createInterface({ input: stdin, output: stderr });
125
160
  try {
126
- const probes = await Promise.allSettled(installed.map(candidate => checkLocalExecutor(candidate, signal)));
127
- signal.throwIfAborted();
128
- const choices = installed.filter(({ kind, entry }, index) => {
129
- const probe = probes[index];
130
- stderr.write(probe.status === 'fulfilled'
131
- ? `${kind} ${probe.value} (${entry}) is compatible.\n`
132
- : `${probe.reason instanceof Error ? probe.reason.message : `Could not verify ${kind} at ${entry}.`}\n`);
133
- return probe.status === 'fulfilled';
134
- });
135
- if (choices.length <= 1)
136
- return choices[0];
137
- const answer = (await input.question(`Select a local backend [${choices.map(({ kind }) => kind).join(', ')}] (pi): `, { signal })).trim() || 'pi';
138
- return choices.find(candidate => candidate.kind === answer);
161
+ for (const { selection, version } of compatible) {
162
+ stderr.write(`${selection.kind} ${version} (${selection.entry}) is compatible.\n`);
163
+ }
164
+ const answer = (await input.question('Select a local backend [pi, codex] (pi): ', { signal })).trim() || 'pi';
165
+ return compatible.find(candidate => candidate.selection.kind === answer) ?? selectBackend;
139
166
  }
140
167
  finally {
141
168
  input.close();
@@ -170,11 +197,15 @@ export async function runLocalCommand(command, signal, progress) {
170
197
  let provider;
171
198
  let rootlessDocker = false;
172
199
  let stage = 'config';
200
+ progress?.('Detect host system and AnySwarm configuration…');
173
201
  try {
202
+ checks.push(...checkSetupHost());
203
+ report.tooling = await checkHostTools(signal);
174
204
  const config = command.configPath
175
205
  ? await loadAnySwarmConfig(command.configPath) : undefined;
176
206
  const configured = (config?.executor ?? process.env.ANYSWARM_EXECUTOR);
177
- let executor = (command.command === 'setup' ? command.backend : undefined) ?? configured;
207
+ let executor = command.command === 'setup' && command.backend
208
+ ? { kind: command.backend, version: command.backendVersion } : configured;
178
209
  const install = command.command === 'setup';
179
210
  let localExecutor;
180
211
  let driver;
@@ -192,38 +223,74 @@ export async function runLocalCommand(command, signal, progress) {
192
223
  image: config?.image,
193
224
  advertiseHost: config?.connection?.advertiseHost ?? config?.connection?.modelGateway?.advertiseHost,
194
225
  });
195
- const mode = (command.command === 'setup' ? command.mode : undefined) ?? environment.mode;
226
+ const hostname = new URL(environment.lifecycleBaseUrl).hostname;
227
+ const loopback = hostname === 'localhost' || hostname === '[::1]' || hostname.startsWith('127.') && isIP(hostname) === 4;
228
+ const reuseExisting = loopback && (environment.management === 'existing' ||
229
+ (!install && environment.mode === 'existing'));
230
+ const mode = command.mode ?? (reuseExisting ? 'existing' : 'local');
196
231
  const smoke = install ? mode === 'local' : command.smoke;
232
+ report.mode = mode;
233
+ report.lifecycleSource = environment.endpointSource;
234
+ if (mode === 'local' && (!loopback || !loopbackLifecycle(environment.lifecycleBaseUrl))) {
235
+ checks.push({ id: 'config.lifecycle', ok: false, detail: 'The selected Lifecycle configuration is outside the managed local HTTP loopback profile.',
236
+ remedy: environment.endpointSource === 'saved'
237
+ ? 'Use --mode existing to check the saved service, or run anyswarm setup --mode local --endpoint http://127.0.0.1:8080 to replace it after a successful local probe.'
238
+ : 'For local setup, remove the Lifecycle URL override or set it to http://127.0.0.1:8080. Use --mode existing only to connect to a service you explicitly select.' });
239
+ return report;
240
+ }
241
+ if (mode === 'existing' && environment.endpointSource === 'default') {
242
+ checks.push({ id: 'config.lifecycle', ok: false, detail: 'No existing Lifecycle service was configured.',
243
+ remedy: 'Run anyswarm setup for local OpenSandbox, or configure the existing Lifecycle URL and credentials explicitly.' });
244
+ return report;
245
+ }
197
246
  if (command.command === 'setup' && command.backend && mode !== 'local') {
198
- report.mode = mode;
199
- checks.push({ id: 'config.executor', ok: false, detail: 'Installation selection requires --mode local on the same Linux host.',
247
+ checks.push({ id: 'config.executor', ok: false, detail: 'Installation selection requires --mode local with a local Docker engine.',
200
248
  remedy: 'For an existing deployment, use its prepared Worker image.' });
201
249
  return report;
202
250
  }
251
+ if (command.command === 'setup' && environment.image && (command.backendPath || command.backendVersion)) {
252
+ checks.push({ id: 'config.executor', ok: false, detail: 'An installation path or version pin requires a locally built Worker.',
253
+ remedy: 'Remove the configured Worker image to select an installation, or pin the version in the project executor configuration.' });
254
+ return report;
255
+ }
203
256
  if (smoke && mode === 'existing' && !environment.image && !driver.adapter) {
204
- report.mode = mode;
205
257
  checks.push({ id: 'config.worker', ok: false, detail: 'An existing service requires an explicitly prepared Worker image.',
206
258
  remedy: 'Set ANYSWARM_WORKER_IMAGE to the image provided by the operator.' });
207
259
  return report;
208
260
  }
209
- if (mode === 'local' && !environment.image && !driver.adapter && (smoke || environment.localExecutor)) {
210
- localExecutor = await chooseBackend(command, environment.localExecutor, configured, signal);
211
- if (!localExecutor) {
212
- report.mode = mode;
213
- checks.push({
214
- id: 'config.executor', ok: false, detail: 'Select a supported local Pi or Codex executable.',
215
- remedy: 'Install Pi or Codex with npm and rerun setup --backend pi|codex. Use --backend-path for a different installation.',
216
- });
217
- return report;
261
+ let localVersion;
262
+ if (mode === 'local' && !environment.image && !driver.adapter) {
263
+ progress?.('Detect an installed Pi or Codex executable…');
264
+ const detected = await chooseBackend(command, environment.localExecutor, configured, signal);
265
+ if ('issue' in detected) {
266
+ const remedy = detected.ambiguous
267
+ ? 'Run anyswarm setup --backend pi or anyswarm setup --backend codex.'
268
+ : 'For Pi, run npm install -g @earendil-works/pi-coding-agent, then run anyswarm setup --backend pi. For Codex, run npm install -g @openai/codex, then run anyswarm setup --backend codex.';
269
+ checks.push({ id: 'config.executor', ok: false, detail: detected.issue, remedy });
270
+ }
271
+ else {
272
+ localExecutor = detected.selection;
273
+ executor = { kind: localExecutor.kind, version: localExecutor.version };
274
+ driver = selectExecutorDriver(executor);
275
+ if ('error' in detected) {
276
+ checks.push({ id: 'config.executor', ok: false, detail: detected.error,
277
+ remedy: 'Restore the saved executable or select a supported installation with anyswarm setup --backend pi or anyswarm setup --backend codex.' });
278
+ }
279
+ else {
280
+ localVersion = detected.version;
281
+ const detail = `Detected ${localExecutor.kind} ${localVersion} at ${localExecutor.entry}.`;
282
+ checks.push({ id: 'config.executor', ok: true, detail });
283
+ progress?.(detail);
284
+ }
218
285
  }
219
- executor = localExecutor.kind;
220
- driver = selectExecutorDriver(executor);
221
286
  }
222
- if (!config && process.env.ANYSWARM_MODEL_URL) {
287
+ const modelUrl = process.env.ANYSWARM_MODEL_URL || process.env.ANYSWARM_SUBAGENTS_MODEL_URL;
288
+ const modelId = process.env.ANYSWARM_MODEL_ID || process.env.ANYSWARM_SUBAGENTS_MODEL_ID;
289
+ if (!config && modelUrl && (modelId || driver.kind !== 'codex')) {
223
290
  const route = {
224
- provider: process.env.ANYSWARM_MODEL_PROVIDER ?? 'openai',
225
- model: process.env.ANYSWARM_MODEL_ID ?? '', protocol: process.env.ANYSWARM_MODEL_PROTOCOL,
226
- upstream: { url: process.env.ANYSWARM_MODEL_URL, headers: {} },
291
+ provider: process.env.ANYSWARM_MODEL_PROVIDER ?? process.env.ANYSWARM_SUBAGENTS_MODEL_PROVIDER ?? 'openai',
292
+ model: modelId || 'gpt-5.4', protocol: process.env.ANYSWARM_MODEL_PROTOCOL,
293
+ upstream: { url: modelUrl, headers: {} },
227
294
  };
228
295
  try {
229
296
  snapshotModel(route, driver.kind);
@@ -236,29 +303,28 @@ export async function runLocalCommand(command, signal, progress) {
236
303
  else {
237
304
  report.model = config ? modelState(config, driver.kind) : { configuration: 'missing', verification: 'not-verified' };
238
305
  }
306
+ if (report.model.configuration === 'missing') {
307
+ report.model.remedy = config ? 'Set an upstream endpoint for each active model route in the trusted configuration.'
308
+ : 'Before running the Quickstart Harness, set ANYSWARM_MODEL_URL and ANYSWARM_MODEL_ID. Set ANYSWARM_MODEL_TOKEN if the endpoint requires authentication.';
309
+ }
239
310
  if (report.model?.configuration === 'invalid')
240
311
  checks.push({
241
312
  id: 'config.models', ok: false, detail: 'An active model alias, capability declaration or protocol endpoint is invalid for the selected executor.',
242
313
  remedy: 'Use a supported executor and protocol combination, and configure an HTTP(S) endpoint without embedded credentials for each active model alias.',
243
314
  });
244
- if (checks.some(check => !check.ok))
245
- return report;
246
- if (config) {
315
+ if (config && report.model.configuration !== 'invalid') {
247
316
  const { lifecycleBaseUrl, apiKey, endpointHost } = environment;
248
317
  checks.push(checkProjectRuntime({
249
318
  ...config, executor, connection: { ...config.connection, publicUrl: environment.publicUrl },
250
319
  }, { ...config.sandbox, endpoint: undefined, lifecycleBaseUrl, apiKey, endpointHost }));
251
320
  }
252
- if (checks.some(check => !check.ok))
253
- return report;
254
321
  report.configuration = {
255
- executor: { id: driver.kind, version: driver.version, compatibleVersions: driver.compatibleVersions },
322
+ executor: { id: driver.kind, version: localVersion ?? driver.version, entry: localExecutor?.entry,
323
+ compatibleVersions: driver.adapter?.compatibleVersions },
256
324
  image: environment.image ?? workerImageFor(executor),
257
325
  filePolicy: resolveFilePolicy(config?.filePolicy),
258
326
  };
259
327
  const publicUrl = environment.publicUrl ?? config?.connection?.bridge?.publicUrl ?? config?.connection?.modelGateway?.publicUrl;
260
- report.mode = mode;
261
- report.lifecycleSource = environment.endpointSource;
262
328
  report.connection = {
263
329
  lifecycleBaseUrl: reportedEndpoint(environment.lifecycleBaseUrl),
264
330
  advertiseHost: reportedHost(environment.advertiseHost),
@@ -269,22 +335,21 @@ export async function runLocalCommand(command, signal, progress) {
269
335
  resolveWith: 'resolveSandboxConnection',
270
336
  };
271
337
  stage = 'host';
272
- checks.push(...checkLinuxHost());
273
- if (checks.some(check => !check.ok))
274
- return report;
338
+ const darwin = process.platform === 'darwin';
275
339
  let advertiseHost = environment.advertiseHost;
276
- if (mode === 'local' && smoke) {
340
+ let advertiseHostDiscovery = environment.advertiseHostDiscovery;
341
+ if (mode === 'local' && checks.find(check => check.id === 'host.platform')?.ok) {
277
342
  const docker = await timed('host', checkLocalDocker);
278
343
  checks.push(docker.diagnostic);
279
- if (!docker.docker)
280
- return report;
281
- rootlessDocker = docker.docker.rootless;
282
- if (advertiseHost === undefined && docker.docker.advertiseHost !== undefined) {
344
+ rootlessDocker = docker.docker?.rootless ?? false;
345
+ if (advertiseHost === undefined && docker.docker?.advertiseHost !== undefined) {
283
346
  advertiseHost = docker.docker.advertiseHost;
284
347
  report.connection.advertiseHost = reportedHost(advertiseHost);
285
348
  report.connection.sources.advertiseHost = 'docker-network';
286
349
  }
287
350
  }
351
+ if (checks.some(check => !check.ok))
352
+ return report;
288
353
  let image = report.configuration.image;
289
354
  if (mode === 'local' && smoke) {
290
355
  stage = 'worker';
@@ -300,8 +365,8 @@ export async function runLocalCommand(command, signal, progress) {
300
365
  report.connection.image = worker.image.reference;
301
366
  report.connection.sources.image = worker.source;
302
367
  report.configuration.image = worker.image.reference;
303
- if (localExecutor) {
304
- executor = { kind: localExecutor.kind, version: worker.image.version };
368
+ if (!driver.adapter && (worker.image.executor === 'pi' || worker.image.executor === 'codex')) {
369
+ executor = { kind: worker.image.executor, version: worker.image.version };
305
370
  report.configuration.executor.version = worker.image.version;
306
371
  }
307
372
  progress?.(`Worker image source: ${worker.source}`);
@@ -313,12 +378,26 @@ export async function runLocalCommand(command, signal, progress) {
313
378
  progress?.(provider.created ? 'Started managed OpenSandbox' : 'Reused managed OpenSandbox');
314
379
  }
315
380
  const active = provider?.config ?? environment;
316
- checks.push(...await timed('provider', () => checkLocalProvider(active)));
381
+ checks.push(...await timed('provider', () => checkLocalProvider(active, { managed: mode === 'local' })));
317
382
  if (checks.some(check => !check.ok))
318
383
  return report;
319
384
  report.infrastructure = 'preflight-passed';
320
385
  if (smoke) {
321
386
  stage = 'smoke';
387
+ if (darwin && mode === 'local' && publicUrl === undefined &&
388
+ (advertiseHost === undefined || advertiseHostDiscovery === 'docker-network')) {
389
+ const discovered = await discoverMacCallback(image, signal);
390
+ if (!install && discovered !== advertiseHost) {
391
+ checks.push({ id: 'config.callback', ok: false, detail: 'The saved Runtime callback needs to be refreshed.',
392
+ remedy: 'Run anyswarm setup to save and verify the current Docker callback.' });
393
+ report.infrastructure = 'failed';
394
+ return report;
395
+ }
396
+ advertiseHost = discovered;
397
+ advertiseHostDiscovery = 'docker-network';
398
+ report.connection.advertiseHost = advertiseHost;
399
+ report.connection.sources.advertiseHost = 'docker-network';
400
+ }
322
401
  report.smoke = await timed('smoke', () => runLocalSmoke({
323
402
  ...active, image, sandbox: config?.sandbox, connection: {
324
403
  ...config?.connection, publicUrl: environment.publicUrl,
@@ -336,7 +415,7 @@ export async function runLocalCommand(command, signal, progress) {
336
415
  signal.throwIfAborted();
337
416
  if (install) {
338
417
  await saveSandboxConnection({ ...active, publicUrl: environment.publicUrl,
339
- advertiseHost, image: environment.image, localExecutor,
418
+ advertiseHost, advertiseHostDiscovery, image: environment.image, localExecutor,
340
419
  management: mode, providerId: provider?.id, preparedImage: report.worker?.id,
341
420
  egressMode: mode === 'local' ? 'dns+nft' : environment.egressMode });
342
421
  checks.push({ id: 'connection.saved', ok: true, detail: 'OpenSandbox connection saved in the owner-only user configuration.' });
@@ -354,7 +433,11 @@ export async function runLocalCommand(command, signal, progress) {
354
433
  };
355
434
  let [detail, remedy] = failure[stage];
356
435
  const code = error?.code;
357
- if (stage === 'provider' && ['PROVIDER_EXECD_PULL_FAILED', 'PROVIDER_SERVER_PULL_FAILED', 'PROVIDER_EGRESS_PULL_FAILED'].includes(code ?? '')) {
436
+ if (code === 'DOCKER_CALLBACK_UNAVAILABLE') {
437
+ detail = 'The Docker container could not resolve a unique Mac callback IPv4 address.';
438
+ remedy = 'Check host.docker.internal from the selected local engine, or configure a Runtime publicUrl reachable from the Sandbox.';
439
+ }
440
+ else if (stage === 'provider' && ['PROVIDER_EXECD_PULL_FAILED', 'PROVIDER_SERVER_PULL_FAILED', 'PROVIDER_EGRESS_PULL_FAILED'].includes(code ?? '')) {
358
441
  const execd = code === 'PROVIDER_EXECD_PULL_FAILED';
359
442
  const egress = code === 'PROVIDER_EGRESS_PULL_FAILED';
360
443
  detail = `Docker could not pull the pinned OpenSandbox ${execd ? 'Execd' : egress ? 'egress' : 'server'} image.`;
@@ -418,8 +501,13 @@ export async function runLocalCommand(command, signal, progress) {
418
501
  progress?.(`Probe evidence: ${report.smoke.outputDir}`);
419
502
  progress?.('Controlled smoke completed. The configured model upstream was not contacted.');
420
503
  }
504
+ for (const tool of report.tooling?.filter(check => !check.ok) ?? []) {
505
+ progress?.([tool.detail, tool.remedy].filter(Boolean).join(' '));
506
+ }
507
+ if (report.model?.remedy)
508
+ progress?.(report.model.remedy);
421
509
  if (report.ok)
422
- progress?.(installNextStep(command));
510
+ progress?.(installNextStep(command, report.mode));
423
511
  }
424
512
  return report;
425
513
  }
@@ -336,8 +336,8 @@ async function startAgent(input) {
336
336
  }
337
337
  else if (executorKind === 'codex') {
338
338
  const version = spawnSync('setpriv', [...unprivileged, 'codex', '--version'], { cwd, env: agentEnvironment, timeout: 5_000, encoding: 'utf8' });
339
- executorVersion = input.executor_version ?? '0.172.0';
340
- if (version.status !== 0 || version.stdout.trim() !== `codex-cli ${executorVersion}`) {
339
+ executorVersion = input.executor_version ?? input.codex.version;
340
+ if (typeof executorVersion !== 'string' || version.status !== 0 || version.stdout.trim() !== `codex-cli ${executorVersion}`) {
341
341
  throw startupContractError('Codex CLI version differs from the Runtime selection');
342
342
  }
343
343
  const configuration = [
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,66 @@
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
+ const [destination, ...options] = process.argv.slice(2);
7
+ if (!destination || (options.length && options.join(' ') !== '--skip-build')) {
8
+ throw new Error('Usage: npm run pack:release -- <output-directory> [--skip-build]');
9
+ }
10
+ // Keep the build and staging umask independent of the caller.
11
+ process.umask(0o022);
12
+ const run = promisify(execFile);
13
+ const repository = resolve(import.meta.dirname, '..');
14
+ const output = resolve(destination);
15
+ if (!options.length) {
16
+ const build = spawnSync('npm', ['run', 'build'], { cwd: repository, stdio: ['ignore', 2, 2] });
17
+ if (build.error)
18
+ throw build.error;
19
+ if (build.status !== 0)
20
+ process.exit(build.status ?? 1);
21
+ }
22
+ async function pack(directory, destination) {
23
+ const { stdout } = await run('npm', ['pack', '--ignore-scripts', '--json', '--pack-destination', destination], {
24
+ cwd: directory, maxBuffer: 4 * 1024 ** 2,
25
+ });
26
+ return JSON.parse(stdout)[0].filename;
27
+ }
28
+ const temporary = await mkdtemp(join(tmpdir(), 'anyswarm-pack-release-'));
29
+ try {
30
+ // Start from npm's allowlist so private checkout files never enter staging.
31
+ const sourceArchive = await pack(repository, temporary);
32
+ await run('tar', ['-xzf', join(temporary, sourceArchive), '-C', temporary]);
33
+ const staged = join(temporary, 'package');
34
+ const manifestPath = join(staged, 'package.json');
35
+ const lockPath = join(staged, 'npm-shrinkwrap.json');
36
+ const manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
37
+ // Service images compile TypeScript. The Pi installation belongs to the executor.
38
+ delete manifest.devDependencies?.['@earendil-works/pi-coding-agent'];
39
+ await writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
40
+ await run('npm', ['install', '--package-lock-only', '--offline', '--ignore-scripts', '--no-audit', '--no-fund'], { cwd: staged });
41
+ const lock = JSON.parse(await readFile(lockPath, 'utf8'));
42
+ if (lock.lockfileVersion !== 3 || !lock.packages?.['']) {
43
+ throw new Error('Release packaging requires a v3 npm shrinkwrap with root package metadata');
44
+ }
45
+ await rename(manifestPath, join(staged, 'package.development.json'));
46
+ await rename(lockPath, join(staged, 'npm-shrinkwrap.development.json'));
47
+ delete manifest.private;
48
+ delete manifest.devDependencies;
49
+ delete lock.packages[''].devDependencies;
50
+ lock.packages = Object.fromEntries(Object.entries(lock.packages).filter(([, entry]) => !entry.dev));
51
+ await writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n');
52
+ await writeFile(lockPath, JSON.stringify(lock, null, 2) + '\n');
53
+ // npm records existing file modes, which can also depend on the checkout umask.
54
+ for (const entry of await readdir(staged, { recursive: true, withFileTypes: true })) {
55
+ if (!entry.isFile())
56
+ continue;
57
+ const path = join(entry.parentPath, entry.name);
58
+ const { mode } = await stat(path);
59
+ await chmod(path, mode & 0o111 ? 0o755 : 0o644);
60
+ }
61
+ await mkdir(output, { recursive: true });
62
+ console.log(join(output, await pack(staged, output)));
63
+ }
64
+ finally {
65
+ await rm(temporary, { recursive: true, force: true });
66
+ }
@@ -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
  // This module is a Guest executable. Core never imports the Pi runtime.
11
12
  async function loadPi() {
@@ -19,12 +20,19 @@ async function loadPi() {
19
20
  const sdk = await import(entry);
20
21
  const packagePath = new URL('../package.json', entry);
21
22
  const metadata = JSON.parse(await readFile(packagePath, 'utf8'));
22
- if (!['1.3.0', '1.4.0'].includes(metadata.version))
23
- throw new Error('Unsupported Pi SDK bridge version');
23
+ if (!executorVersion(metadata.version) || [
24
+ sdk.SettingsManager?.inMemory, sdk.DefaultResourceLoader, sdk.ModelRuntime?.create,
25
+ sdk.SessionManager?.create, sdk.SessionManager?.open,
26
+ sdk.createAgentSession, sdk.createCodemodeExtension, sdk.createToolSearchExtension,
27
+ ].some(required => typeof required !== 'function')) {
28
+ throw new Error('The installed Pi package does not expose the required Session Bridge API');
29
+ }
24
30
  return { sdk, version: metadata.version };
25
31
  }
26
- const options = JSON.parse(await readFile(process.argv[2], 'utf8'));
27
32
  const { sdk, version } = await loadPi();
33
+ if (process.argv[2] === '--check-sdk')
34
+ process.exit(0);
35
+ const options = JSON.parse(await readFile(process.argv[2], 'utf8'));
28
36
  const args = options.args ?? [];
29
37
  const argument = (name) => { const index = args.indexOf(name); return index < 0 ? undefined : args[index + 1]; };
30
38
  const cwd = process.cwd();
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { resolve } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
- const usage = 'node dist/scripts/run-harness.js --config <host-module.mjs>';
4
+ import { installSourceLoader } from '../src/harness/typescript-loader.js';
5
+ const usage = 'node dist/scripts/run-harness.js --config <host-module.ts>';
5
6
  const args = process.argv.slice(2);
6
7
  const lifetime = new AbortController();
7
8
  const stop = () => lifetime.abort();
@@ -45,6 +46,7 @@ try {
45
46
  else {
46
47
  if (args.length !== 2 || args[0] !== '--config' || !args[1] || args[1].startsWith('--'))
47
48
  throw Object.assign(new Error(), { code: 'HOST_ARGUMENTS_INVALID' });
49
+ installSourceLoader();
48
50
  const { default: configuration } = await import(pathToFileURL(resolve(args[1])).href);
49
51
  const { keepsForegroundCommandsOpen, runForegroundHarness } = await import('../src/cli/foreground-harnesses.js');
50
52
  const { runForegroundCommands } = await import('../src/harness/foreground-commands.js');
@@ -86,6 +86,37 @@ async function lockedSetup(startedAt, options) {
86
86
  bootstrap.timings.push({ id: 'build', elapsedMs: Math.round(performance.now() - start), cached: buildCached });
87
87
  return child(process.execPath, [cli, 'setup', ...options], { ...process.env, ANYSWARM_SETUP_BOOTSTRAP: JSON.stringify(bootstrap) }, true);
88
88
  }
89
+ async function macCheckoutSetup(startedAt, options) {
90
+ signal.throwIfAborted();
91
+ const lock = spawn('/usr/bin/lockf', ['-kn', '-t', '180', root, process.execPath, '-e',
92
+ 'console.log("locked"); process.stdin.resume()'], { stdio: ['pipe', 'pipe', 'inherit'] });
93
+ lock.stdin.on('error', () => { });
94
+ const cancel = () => lock.kill('SIGTERM');
95
+ signal.addEventListener('abort', cancel, { once: true });
96
+ try {
97
+ const acquired = await new Promise((ready, reject) => {
98
+ lock.once('error', reject);
99
+ lock.once('exit', code => {
100
+ if (code === 75)
101
+ ready(false);
102
+ else
103
+ reject(new Error('Could not lock the checkout.'));
104
+ });
105
+ lock.stdout.once('data', () => ready(true));
106
+ });
107
+ signal.removeEventListener('abort', cancel);
108
+ signal.throwIfAborted();
109
+ if (!acquired) {
110
+ failure('checkout-lock', 'Another setup still holds the checkout lock.', 'Wait for the other invocation and rerun setup.');
111
+ return 1;
112
+ }
113
+ return await lockedSetup(startedAt, options);
114
+ }
115
+ finally {
116
+ signal.removeEventListener('abort', cancel);
117
+ lock.stdin.end();
118
+ }
119
+ }
89
120
  const args = process.argv.slice(2);
90
121
  const lockInvocation = args[0] === '--under-checkout-lock';
91
122
  try {
@@ -99,18 +130,24 @@ try {
99
130
  console.log(command.help);
100
131
  }
101
132
  else {
102
- if (process.platform !== 'linux') {
103
- failure('host.linux', 'Setup requires Linux.', 'Run this command on Linux.');
133
+ if (process.platform !== 'linux' && process.platform !== 'darwin') {
134
+ failure('host.platform', 'Setup requires Linux or macOS.', 'Run this command on Linux or macOS.');
104
135
  process.exitCode = 1;
105
136
  }
106
137
  else if (command.command === 'setup') {
107
138
  const options = [
108
139
  ...(command.mode ? ['--mode', command.mode] : []),
140
+ ...(command.endpoint ? ['--endpoint', command.endpoint] : []),
141
+ ...(command.publicUrl ? ['--public-url', command.publicUrl] : []),
142
+ ...(command.backend ? ['--backend', command.backend] : []),
143
+ ...(command.backendVersion ? ['--backend-version', command.backendVersion] : []),
144
+ ...(command.backendPath ? ['--backend-path', resolve(command.backendPath)] : []),
109
145
  ...(command.configPath ? ['--config', resolve(command.configPath)] : []),
110
146
  ];
111
- process.exitCode = await child('flock', ['--no-fork', '--exclusive', '--timeout', '180', '--conflict-exit-code', '73',
112
- root, process.execPath, '--disable-warning=ExperimentalWarning', script, '--under-checkout-lock',
113
- String(startedAt), ...options], process.env, true);
147
+ process.exitCode = process.platform === 'darwin' ? await macCheckoutSetup(startedAt, options)
148
+ : await child('flock', ['--no-fork', '--exclusive', '--timeout', '180', '--conflict-exit-code', '73',
149
+ root, process.execPath, '--disable-warning=ExperimentalWarning', script, '--under-checkout-lock',
150
+ String(startedAt), ...options], process.env, true);
114
151
  if (process.exitCode === 73) {
115
152
  failure('checkout-lock', 'Another setup still holds the checkout lock.', 'Wait for the other invocation and rerun setup.');
116
153
  process.exitCode = 1;
@@ -129,7 +166,7 @@ catch (error) {
129
166
  process.exitCode = 2;
130
167
  }
131
168
  else {
132
- failure('bootstrap', 'The checkout could not be prepared.', 'Check Node.js, npm, flock and permissions on this checkout.');
169
+ failure('bootstrap', 'The checkout could not be prepared.', 'Check Node.js, npm, platform lock tools and permissions on this checkout.');
133
170
  process.exitCode = 1;
134
171
  }
135
172
  }
@@ -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
  function fault(code, message) {
7
8
  return Object.assign(new Error(message), { code, allocationLedger: true });
8
9
  }
@@ -40,12 +41,12 @@ function currentHostIdentity() {
40
41
  const node = process.env.ANYSWARM_RUNTIME_NODE_NAME;
41
42
  const identities = [node ? 'kubernetes' : 'host', node || hostname()];
42
43
  try {
43
- identities.push(readFileSync('/proc/sys/kernel/random/boot_id', 'utf8').trim());
44
+ identities.push(process.platform === 'darwin' ? darwinBootSession() : readFileSync('/proc/sys/kernel/random/boot_id', 'utf8').trim());
44
45
  }
45
46
  catch {
46
- throw fault('NOT_ALLOWED', 'Durable Runtime requires the Linux kernel boot identity');
47
+ throw fault('NOT_ALLOWED', 'Durable Runtime requires a verified kernel boot identity');
47
48
  }
48
- if (!node) {
49
+ if (!node && process.platform !== 'darwin') {
49
50
  try {
50
51
  identities.push(readFileSync('/etc/machine-id', 'utf8').trim());
51
52
  }
@@ -0,0 +1,2 @@
1
+ /** Cache only a verified UUID: a running Controller cannot survive a reboot. */
2
+ export declare function darwinBootSession(): string;