@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
@@ -1,3 +1,4 @@
1
+ import { installSourceLoader } from './typescript-loader.js';
1
2
  import { errorDiagnostic, frameworkErrorFields } from '../core/error-diagnostics.js';
2
3
  import { loadAnySwarmConfig } from '../core/sandbox/sandbox-connection.js';
3
4
  import { createHash, randomUUID } from 'node:crypto';
@@ -13,8 +14,8 @@ import { fileSpool } from '../core/files/core-file-seed.js';
13
14
  export { createHarnessSession, captureHarnessSnapshot, getHarnessExitCode, getHarnessRunId, harnessSessionSignal, stopHarnessTransport } from './harness-session.js';
14
15
  function moduleSpecifier(directory, specifier) {
15
16
  if (isAbsolute(specifier) || specifier.startsWith('./') || specifier.startsWith('../')) {
16
- if (!['.mjs', '.js'].includes(extname(specifier))) {
17
- throw projectError('INVALID_HARNESS_MODULE', 'Local Harness modules must be built .mjs or .js files');
17
+ if (!['.mjs', '.js', '.ts', '.mts'].includes(extname(specifier))) {
18
+ throw projectError('INVALID_HARNESS_MODULE', 'Local Harness modules must be .ts, .mts, .mjs or .js files');
18
19
  }
19
20
  return pathToFileURL(resolve(directory, specifier)).href;
20
21
  }
@@ -24,7 +25,8 @@ function moduleSpecifier(directory, specifier) {
24
25
  }
25
26
  return specifier;
26
27
  }
27
- export async function loadProjectHarness(directory, specifier, builtins = {}) {
28
+ export async function loadProjectHarnessModule(directory, specifier, builtins = {}, options = {}) {
29
+ installSourceLoader();
28
30
  const builtin = Object.hasOwn(builtins, specifier) ? builtins[specifier] : undefined;
29
31
  const target = builtin ?? moduleSpecifier(directory, specifier);
30
32
  const parentURL = pathToFileURL(join(directory, '.anyswarm-harness-resolver.mjs')).href;
@@ -45,7 +47,8 @@ export async function loadProjectHarness(directory, specifier, builtins = {}) {
45
47
  hook?.deregister();
46
48
  }
47
49
  }
48
- catch {
50
+ catch (error) {
51
+ options.onSourceError?.(error);
49
52
  throw projectError('HARNESS_MODULE_LOAD_FAILED', `Could not load Harness ${JSON.stringify(specifier)}`);
50
53
  }
51
54
  const definition = module.default;
@@ -54,7 +57,22 @@ export async function loadProjectHarness(directory, specifier, builtins = {}) {
54
57
  typeof definition.run !== 'function' || (definition.input !== undefined && definition.input !== true)) {
55
58
  throw projectError('INVALID_HARNESS_MODULE', 'Harness default export requires apiVersion 1, a stable id and run(context)');
56
59
  }
57
- return definition;
60
+ if (options.onSourceError) {
61
+ const harness = definition;
62
+ return { module, definition: { ...harness, async run(context) {
63
+ try {
64
+ return await harness.run(context);
65
+ }
66
+ catch (error) {
67
+ options.onSourceError(error);
68
+ throw error;
69
+ }
70
+ } } };
71
+ }
72
+ return { module, definition: definition };
73
+ }
74
+ export async function loadProjectHarness(...args) {
75
+ return (await loadProjectHarnessModule(...args)).definition;
58
76
  }
59
77
  export function failureCode(error, fallback) {
60
78
  const { code } = (error ?? {});
@@ -171,7 +189,7 @@ export function createProjectHost(definition, options, emit) {
171
189
  let enteredHarness = false;
172
190
  let failure = null;
173
191
  const signal = controller.signal;
174
- let staged;
192
+ const spools = new Set();
175
193
  const work = async () => {
176
194
  // Resolve the directory first so an explicitly nested output can be excluded.
177
195
  cwd = await resolveProjectDirectory(raw.cwd);
@@ -192,9 +210,17 @@ export function createProjectHost(definition, options, emit) {
192
210
  catch {
193
211
  throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Invalid project file policy');
194
212
  }
195
- const captured = await captureProject(cwd, outputDir, signal, filePolicy);
213
+ const capture = async (requestSignal) => {
214
+ const captured = await captureProject(cwd, outputDir, requestSignal ? AbortSignal.any([signal, requestSignal]) : signal, filePolicy);
215
+ const directory = fileSpool(captured.files).directory;
216
+ spools.add(directory);
217
+ return { ...captured, async dispose() {
218
+ await rm(directory, { recursive: true, force: true });
219
+ spools.delete(directory);
220
+ } };
221
+ };
222
+ const { dispose: _dispose, ...captured } = await capture();
196
223
  const { files, manifest, ...source } = captured;
197
- staged = fileSpool(files);
198
224
  initial = { ...source, manifestPath: null };
199
225
  signal.throwIfAborted();
200
226
  const manifestPath = join(outputDir, 'initial-files.json');
@@ -205,6 +231,7 @@ export function createProjectHost(definition, options, emit) {
205
231
  return validateResult(await definition.run({
206
232
  input: Object.freeze({ cwd, prompt: raw.prompt }), initial: captured, configuration, runId: id, outputDir, signal,
207
233
  lifetime: 'task', clientCapabilities: { questions: false },
234
+ captureProject: capture,
208
235
  registerAgentControls() { return () => { }; },
209
236
  runWithRuntime() { throw projectError('INVALID_HARNESS_SESSION', 'Runtime reporting requires a HarnessSession'); },
210
237
  askUser() { return Promise.reject(projectError('OPERATION_UNSUPPORTED', 'No question channel is available')); },
@@ -228,8 +255,7 @@ export function createProjectHost(definition, options, emit) {
228
255
  let workFinished = false;
229
256
  const running = work().finally(() => { workFinished = true; });
230
257
  const removeSpool = async () => {
231
- if (staged)
232
- await rm(staged.directory, { recursive: true, force: true });
258
+ await Promise.all([...spools].map(directory => rm(directory, { recursive: true, force: true })));
233
259
  };
234
260
  let business;
235
261
  try {
@@ -1,4 +1,4 @@
1
- import { execFile } from 'node:child_process';
1
+ import { execFile, spawn } from 'node:child_process';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { constants } from 'node:fs';
4
4
  import { lstat, mkdtemp, open, opendir, realpath, rm } from 'node:fs/promises';
@@ -12,8 +12,12 @@ const git = promisify(execFile);
12
12
  const utf8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
13
13
  const maxPathBytes = 4095;
14
14
  const maxPathDepth = 128;
15
- const directoryFlags = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_DIRECTORY;
16
- const fileFlags = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK;
15
+ // Darwin's sys/fcntl.h O_NOFOLLOW_ANY checks every path component during open.
16
+ // Linux opens children relative to the already validated /proc directory descriptor.
17
+ const darwin = process.platform === 'darwin';
18
+ const noLinks = darwin ? 0x20000000 : constants.O_NOFOLLOW;
19
+ const directoryFlags = constants.O_RDONLY | noLinks | constants.O_DIRECTORY;
20
+ const fileFlags = constants.O_RDONLY | noLinks | constants.O_NONBLOCK;
17
21
  export function projectError(code, message) {
18
22
  return Object.assign(new Error(message), { code });
19
23
  }
@@ -67,8 +71,53 @@ function sameFile(a, b) {
67
71
  function sourceChanged(path) {
68
72
  return projectError('PROJECT_SOURCE_CHANGED', `Project source changed while capturing ${JSON.stringify(path)}`);
69
73
  }
70
- function accessPath(directory, name) {
71
- return `/proc/self/fd/${directory.fd}/${name}`;
74
+ async function* directoryNames(directory, label, signal) {
75
+ if (!darwin) {
76
+ // Node returns byte names for this option, which the opendir types omit.
77
+ const listing = await opendir(`/proc/self/fd/${directory.fd}/.`, { encoding: 'buffer' });
78
+ for await (const entry of listing)
79
+ yield entry.name;
80
+ return;
81
+ }
82
+ // Perl chdir on a filehandle uses fchdir. The helper opens "." relative to
83
+ // that descriptor, so concurrent path changes cannot redirect enumeration.
84
+ const listing = spawn('/usr/bin/perl', ['-e', String.raw `
85
+ open(my $anchor, "<&=3") or exit 1;
86
+ chdir($anchor) or exit 1;
87
+ opendir(my $directory, ".") or exit 1;
88
+ while (defined(my $name = readdir($directory))) {
89
+ print $name, "\0" unless $name eq "." || $name eq "..";
90
+ }
91
+ closedir($directory) or exit 1;
92
+ `], { stdio: ['ignore', 'pipe', 'ignore', directory.fd], env: { PATH: '/usr/bin:/bin' }, signal });
93
+ const exit = new Promise(resolveExit => {
94
+ listing.once('error', () => resolveExit(null));
95
+ listing.once('close', resolveExit);
96
+ });
97
+ try {
98
+ let partial = Buffer.alloc(0);
99
+ for await (const chunk of listing.stdout) {
100
+ signal.throwIfAborted();
101
+ const data = partial.length ? Buffer.concat([partial, chunk]) : chunk;
102
+ let offset = 0;
103
+ for (let end = data.indexOf(0); end !== -1; end = data.indexOf(0, offset)) {
104
+ yield data.subarray(offset, end);
105
+ offset = end + 1;
106
+ }
107
+ partial = data.subarray(offset);
108
+ if (partial.length > maxPathBytes)
109
+ throw sourceChanged(label);
110
+ }
111
+ const status = await exit;
112
+ signal.throwIfAborted();
113
+ if (status !== 0 || partial.length)
114
+ throw sourceChanged(label);
115
+ }
116
+ finally {
117
+ if (listing.exitCode === null && listing.signalCode === null)
118
+ listing.kill();
119
+ await exit;
120
+ }
72
121
  }
73
122
  async function gitFiles(cwd, signal, maxEntries) {
74
123
  const env = Object.fromEntries(Object.entries(process.env).filter(([name]) => !name.startsWith('GIT_')));
@@ -146,11 +195,26 @@ export async function captureProject(cwd, outputDir, signal, policy = DEFAULT_FI
146
195
  }
147
196
  }
148
197
  async function readProject(cwd, outputDir, spool, signal, policy) {
198
+ if (darwin) {
199
+ cwd = await resolveProjectDirectory(cwd);
200
+ outputDir = await realpath(outputDir);
201
+ }
149
202
  const excluded = isInside(cwd, outputDir) ? relative(cwd, outputDir) : null;
203
+ const directoryPaths = new WeakMap();
204
+ async function accessPath(directory, name, label) {
205
+ if (!darwin)
206
+ return `/proc/self/fd/${directory.fd}/${name}`;
207
+ const expected = directoryPaths.get(directory);
208
+ const current = await lstat(expected.path, { bigint: true }).catch(() => { throw sourceChanged(label); });
209
+ if (!sameFile(expected.stat, current))
210
+ throw sourceChanged(label);
211
+ return join(expected.path, name);
212
+ }
150
213
  const entries = [];
151
214
  const budget = policy.initial;
152
215
  const buffer = Buffer.alloc(MAX_COLLECTION_CHUNK_BYTES);
153
- const skip = (path) => isGitPath(path) ||
216
+ const skip = (path, tracked = false) => isGitPath(path) ||
217
+ (!tracked && /^(?:node_modules|\.anyswarm-sdk|\.anyswarm-code-recovery-[A-Za-z0-9]{6})(?:\/|$)/.test(path)) ||
154
218
  (excluded !== null && (path === excluded || path.startsWith(excluded + '/')));
155
219
  let bytes = 0;
156
220
  let count = 0;
@@ -160,6 +224,8 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
160
224
  try {
161
225
  if (!sameFile(before, await handle.stat({ bigint: true })))
162
226
  throw sourceChanged(label);
227
+ if (darwin && before.isDirectory())
228
+ directoryPaths.set(handle, { path, stat: before });
163
229
  return handle;
164
230
  }
165
231
  catch (error) {
@@ -176,7 +242,7 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
176
242
  info.size > BigInt(Math.min(budget.maxBytes, policy.controllerSpoolBytes) - bytes)) {
177
243
  throw projectError('PROJECT_FILE_LIMIT', `Project exceeds the file count or byte limit at ${JSON.stringify(path)}`);
178
244
  }
179
- const location = accessPath(parent, name);
245
+ const location = await accessPath(parent, name, path);
180
246
  // Check the shared physical filesystem before each file; write failures
181
247
  // still take precedence if another process consumes that space meanwhile.
182
248
  await checkFileSpace(spool, Number(info.size), 1, 'Controller staging');
@@ -218,7 +284,7 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
218
284
  if (!info.isDirectory()) {
219
285
  throw projectError('PROJECT_FILE_UNSUPPORTED', `Project ancestor is not a directory: ${JSON.stringify(path)}`);
220
286
  }
221
- const location = accessPath(parent, name);
287
+ const location = await accessPath(parent, name, path);
222
288
  const child = await openChecked(location, info, directoryFlags, path);
223
289
  try {
224
290
  await visit(child);
@@ -235,7 +301,8 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
235
301
  signal.throwIfAborted();
236
302
  const name = parts[depth];
237
303
  const path = parts.slice(0, depth + 1).join('/');
238
- const info = await lstat(accessPath(parent, name), { bigint: true }).catch(error => {
304
+ const location = await accessPath(parent, name, path);
305
+ const info = await lstat(location, { bigint: true }).catch(error => {
239
306
  if (error.code === 'ENOENT' && tracked)
240
307
  return null;
241
308
  if (error.code === 'ENOENT')
@@ -254,11 +321,9 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
254
321
  }
255
322
  }
256
323
  async function walk(directory, prefix = '') {
257
- // Node returns byte names for this option, which the opendir types omit.
258
- const listing = await opendir(accessPath(directory, '.'), { encoding: 'buffer' });
259
- for await (const entry of listing) {
324
+ for await (const entry of directoryNames(directory, prefix || '.', signal)) {
260
325
  signal.throwIfAborted();
261
- const name = decodePath(entry.name);
326
+ const name = decodePath(entry);
262
327
  const path = prefix + name;
263
328
  if (++enumerated > budget.maxEntries) {
264
329
  throw projectError('PROJECT_FILE_LIMIT', `Project exceeds the directory enumeration limit at ${JSON.stringify(path)}`);
@@ -266,7 +331,8 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
266
331
  if (skip(path))
267
332
  continue;
268
333
  normalizedPath(path);
269
- const info = await lstat(accessPath(directory, name), { bigint: true }).catch(() => { throw sourceChanged(path); });
334
+ const location = await accessPath(directory, name, path);
335
+ const info = await lstat(location, { bigint: true }).catch(() => { throw sourceChanged(path); });
270
336
  if (info.isDirectory())
271
337
  await inDirectory(directory, name, path, info, child => walk(child, path + '/'));
272
338
  else
@@ -284,7 +350,7 @@ async function readProject(cwd, outputDir, spool, signal, policy) {
284
350
  if (paths.size > budget.maxEntries)
285
351
  throw projectError('PROJECT_FILE_LIMIT', 'Project exceeds its Git enumeration limit');
286
352
  for (const [path, { tracked, gitlink }] of paths) {
287
- if (skip(path))
353
+ if (skip(path, tracked))
288
354
  continue;
289
355
  if (path.endsWith('/')) {
290
356
  throw projectError('PROJECT_GITLINK_UNSUPPORTED', `Nested repository is in the project scope: ${JSON.stringify(path)}`);
@@ -32,6 +32,7 @@ export declare class HarnessRpcClient implements HarnessSession {
32
32
  #private;
33
33
  readonly ready: Promise<HarnessRpcReady>;
34
34
  readonly agents: HarnessSession['agents'];
35
+ readonly services: HarnessSession['services'];
35
36
  constructor(transport: HarnessRpcTransport, options?: HarnessRpcClientOptions);
36
37
  describe(): ReturnType<HarnessSession['describe']>;
37
38
  start(...[input, request]: Parameters<HarnessSession['start']>): Promise<import("./harness-session-types.js").HarnessStartReceipt>;
@@ -7,6 +7,7 @@ import { HarnessEventStream } from './harness-event-stream.js';
7
7
  export class HarnessRpcClient {
8
8
  ready;
9
9
  agents;
10
+ services;
10
11
  #ready = Promise.withResolvers();
11
12
  #result = Promise.withResolvers();
12
13
  #pending = new Map();
@@ -78,6 +79,10 @@ export class HarnessRpcClient {
78
79
  interrupt: (agentId, { requestId, ...options }) => this.#call('agent.interrupt', { agentId, options }, requestId),
79
80
  stop: (agentId, { requestId, ...options }) => this.#call('agent.stop', { agentId, options }, requestId),
80
81
  });
82
+ this.services = Object.freeze({
83
+ list: () => this.#call('service.list'),
84
+ read: (runtimeId, name) => this.#call('service.read', { runtimeId, name }),
85
+ });
81
86
  }
82
87
  describe() {
83
88
  return this.#call('describe');
@@ -1,6 +1,12 @@
1
- import type { Readable } from 'node:stream';
2
1
  import { type HarnessInput } from './project-harness.js';
2
+ import { type RpcReadable } from './project-rpc-lines.js';
3
3
  import type { HarnessSession } from './harness-session-types.js';
4
4
  type Writer = (record: unknown, replaceableState?: boolean) => Promise<void>;
5
- export declare function runProjectRpc(session: HarnessSession, input: Readable, write: Writer, launchDirectory: string, initialInput?: HarnessInput): Promise<number>;
5
+ type RpcServerInput = RpcReadable & {
6
+ readonly destroyed: boolean;
7
+ pause(): unknown;
8
+ };
9
+ export declare function runProjectRpc(session: HarnessSession, input: RpcServerInput, write: Writer, launchDirectory: string, initialInput?: HarnessInput, options?: {
10
+ detachOnDisconnect?: boolean;
11
+ }): Promise<number>;
6
12
  export {};
@@ -5,7 +5,7 @@ import { MAX_COMMAND_BYTES } from './foreground-commands.js';
5
5
  import { captureHarnessSnapshot, failureCode, getHarnessExitCode, getHarnessRunId, harnessSessionSignal, stopHarnessTransport, } from './project-harness.js';
6
6
  import { projectError, resolveHarnessInput } from './project-input.js';
7
7
  import { readRpcLines } from './project-rpc-lines.js';
8
- const queryOperations = new Set(['status', 'describe', 'agent.getState', 'agent.getStats', 'agent.getMessages']);
8
+ const queryOperations = new Set(['status', 'describe', 'agent.getState', 'agent.getStats', 'agent.getMessages', 'service.list', 'service.read']);
9
9
  const mutationOperations = new Set([
10
10
  'run', 'input', 'answer', 'stop', 'agent.configure', 'agent.compact',
11
11
  'agent.abortRetry', 'agent.clearQueue', 'agent.send', 'agent.interrupt', 'agent.stop',
@@ -62,6 +62,14 @@ function dispatch(session, request, launchDirectory) {
62
62
  if (input !== undefined)
63
63
  throw projectError('INVALID_REQUEST', 'Describe takes no input');
64
64
  return session.describe();
65
+ case 'service.list':
66
+ if (input !== undefined)
67
+ throw projectError('INVALID_REQUEST', 'Service list takes no input');
68
+ return session.services.list();
69
+ case 'service.read': {
70
+ const { runtimeId, name } = named(input, ['runtimeId', 'name']);
71
+ return session.services.read(requiredString(runtimeId), requiredString(name));
72
+ }
65
73
  case 'answer': {
66
74
  const { questionId, answer } = named(input, ['questionId', 'answer']);
67
75
  if (typeof answer !== 'string' && typeof answer !== 'boolean')
@@ -143,7 +151,7 @@ function eventRecord(event) {
143
151
  return { type: 'event', runId: event.runId, event: { kind: event.type, ...event }, sessionEvent: event };
144
152
  }
145
153
  }
146
- export async function runProjectRpc(session, input, write, launchDirectory, initialInput) {
154
+ export async function runProjectRpc(session, input, write, launchDirectory, initialInput, options = {}) {
147
155
  const done = Promise.withResolvers();
148
156
  const queryReceipts = new Map();
149
157
  const signal = harnessSessionSignal(session);
@@ -164,7 +172,7 @@ export async function runProjectRpc(session, input, write, launchDirectory, init
164
172
  };
165
173
  function watchCompletion() {
166
174
  const completion = session.completion;
167
- if (!completion || watchingCompletion)
175
+ if (!completion || watchingCompletion || options.detachOnDisconnect)
168
176
  return;
169
177
  watchingCompletion = true;
170
178
  void completion.then(async (result) => {
@@ -243,6 +251,11 @@ export async function runProjectRpc(session, input, write, launchDirectory, init
243
251
  }
244
252
  signal.addEventListener('abort', stopTransport, { once: true });
245
253
  const unsubscribe = session.onEvent(event => {
254
+ if (event.type === 'result' && options.detachOnDisconnect) {
255
+ void write({ type: 'result', runId: event.result.runId, result: event.result })
256
+ .then(() => done.resolve(getHarnessExitCode(session) ?? 1), done.reject);
257
+ return;
258
+ }
246
259
  const record = eventRecord(event);
247
260
  if (record)
248
261
  send(record, event.type === 'state');
@@ -252,18 +265,29 @@ export async function runProjectRpc(session, input, write, launchDirectory, init
252
265
  const descriptor = await session.describe();
253
266
  const status = captureHarnessSnapshot(session);
254
267
  send({ type: 'ready', version: 'v1', harness: status.harness, status, descriptor });
268
+ if (options.detachOnDisconnect && status.phase === 'finished' && session.completion) {
269
+ const result = await session.completion;
270
+ await write({ type: 'result', runId: result.runId, result });
271
+ return getHarnessExitCode(session) ?? 1;
272
+ }
255
273
  if (signal.aborted)
256
274
  stopTransport();
257
275
  else if (initialInput)
258
276
  onLine(JSON.stringify({ id: 'foreground-start', operation: 'run', input: initialInput }));
277
+ const disconnect = (reason) => {
278
+ if (options.detachOnDisconnect)
279
+ done.resolve(0);
280
+ else
281
+ stopHarnessTransport(session, reason);
282
+ };
259
283
  detach = readRpcLines(input, MAX_COMMAND_BYTES, {
260
284
  line: onLine,
261
285
  invalid: () => send(errorRecord('INVALID_REQUEST')),
262
- end: () => stopHarnessTransport(session, 'input-ended'),
263
- error: () => stopHarnessTransport(session, 'input-failed'),
286
+ end: () => disconnect('input-ended'),
287
+ error: () => disconnect('input-failed'),
264
288
  });
265
- if (input.readableEnded)
266
- stopHarnessTransport(session, 'input-ended');
289
+ if (input.readableEnded || input.destroyed)
290
+ disconnect('input-ended');
267
291
  return await done.promise;
268
292
  }
269
293
  finally {
@@ -25,6 +25,8 @@ export function observeProjectRuntime(runtime, context, business, controls = {})
25
25
  }
26
26
  }
27
27
  async function refresh() {
28
+ if (!business)
29
+ return;
28
30
  pending = true;
29
31
  if (refreshing || closed)
30
32
  return;
@@ -33,7 +35,7 @@ export function observeProjectRuntime(runtime, context, business, controls = {})
33
35
  while (pending && !closed) {
34
36
  pending = false;
35
37
  try {
36
- const detail = await read(business?.() ?? null);
38
+ const detail = await read(business());
37
39
  if (!closed && !signal.aborted)
38
40
  context.updateStatus({
39
41
  business: json({ runtimeId: runtime.id, runtimeState: runtime.state, detail }),
@@ -0,0 +1,2 @@
1
+ /** Enable trusted author TypeScript without changing the author's package scope. */
2
+ export declare function installSourceLoader(): void;
@@ -0,0 +1,41 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { registerHooks, stripTypeScriptTypes } from 'node:module';
3
+ import { fileURLToPath } from 'node:url';
4
+ let installed = false;
5
+ /** Enable trusted author TypeScript without changing the author's package scope. */
6
+ export function installSourceLoader() {
7
+ if (installed)
8
+ return;
9
+ installed = true;
10
+ // Node 22.19+ supports transformation and inline maps, including enums.
11
+ const transform = stripTypeScriptTypes;
12
+ const sdk = new URL('../core/index.js', import.meta.url).href;
13
+ registerHooks({
14
+ resolve(specifier, context, nextResolve) {
15
+ try {
16
+ return nextResolve(specifier, context);
17
+ }
18
+ catch (error) {
19
+ if (error.code !== 'ERR_MODULE_NOT_FOUND' &&
20
+ error.code !== 'MODULE_NOT_FOUND')
21
+ throw error;
22
+ if (specifier === '@anyswarm/core')
23
+ return { url: sdk, shortCircuit: true };
24
+ if (context.parentURL?.startsWith('file:') && /^(?:\.{1,2}\/|\/)/.test(specifier) && /\.m?js$/.test(specifier)) {
25
+ const source = new URL(specifier.replace(/\.m?js$/, match => match === '.mjs' ? '.mts' : '.ts'), context.parentURL);
26
+ if (existsSync(source))
27
+ return { url: source.href, shortCircuit: true };
28
+ }
29
+ throw error;
30
+ }
31
+ },
32
+ load(url, context, nextLoad) {
33
+ if (!url.startsWith('file:') || !/\.(?:ts|mts)$/.test(new URL(url).pathname))
34
+ return nextLoad(url, context);
35
+ const source = transform(readFileSync(fileURLToPath(url), 'utf8'), {
36
+ mode: 'transform', sourceMap: true, sourceUrl: url,
37
+ });
38
+ return { format: 'module', source, shortCircuit: true };
39
+ },
40
+ });
41
+ }
@@ -13,6 +13,7 @@ const TRACK_DEFS = [
13
13
  { key: "model", label: "Model", color: "var(--purple)" },
14
14
  { key: "tool", label: "Tools", color: "var(--amber)" },
15
15
  { key: "service", label: "Service", color: "var(--teal)" },
16
+ { key: "research", label: "Research", color: "var(--teal)" },
16
17
  ];
17
18
 
18
19
  const state = {
@@ -1125,10 +1126,8 @@ function renderSwimlane() {
1125
1126
  let curY = rulerH;
1126
1127
  const geom = [];
1127
1128
  for (const ag of agents) {
1128
- const hasSvc = state.timelineItems.some(
1129
- (i) => laneContains(ag, i.agentId) && i.kind === "service",
1130
- );
1131
- const tracks = TRACK_DEFS.filter((td) => td.key !== "service" || hasSvc);
1129
+ const active = new Set(state.timelineItems.filter(item => laneContains(ag, item.agentId)).map(item => item.kind));
1130
+ const tracks = TRACK_DEFS.filter(track => !["service", "research"].includes(track.key) || active.has(track.key));
1132
1131
  const startY = curY;
1133
1132
  const rowY = {};
1134
1133
  curY += headH;
@@ -1453,7 +1452,7 @@ function renderSwimlane() {
1453
1452
  it.startedAt - state.domainStart <= state.winEnd,
1454
1453
  );
1455
1454
  const isPointTrack =
1456
- td.key === "input" || (td.key === "tool" && !run.hasNative);
1455
+ td.key === "input" || td.key === "research" || (td.key === "tool" && !run.hasNative);
1457
1456
  const { rects, merged, overlaps } = layoutTrackBars(
1458
1457
  trackItems,
1459
1458
  xOf,
@@ -1759,6 +1758,7 @@ function renderTrajectory() {
1759
1758
  tool: state.timelineItems.filter((i) => i.kind === "tool").length,
1760
1759
  service: state.timelineItems.filter((i) => i.kind === "service").length,
1761
1760
  input: state.timelineItems.filter((i) => i.kind === "input").length,
1761
+ research: state.timelineItems.filter((i) => i.kind === "research").length,
1762
1762
  error: state.timelineItems.filter((i) => i.isError).length,
1763
1763
  };
1764
1764
  const pills = $("#track-filter-pills");
@@ -1770,6 +1770,7 @@ function renderTrajectory() {
1770
1770
  ["service", `Service (${counts.service})`],
1771
1771
  ["input", `Input (${counts.input})`],
1772
1772
  ];
1773
+ if (counts.research) defs.push(["research", `Research (${counts.research})`]);
1773
1774
  if (counts.error) defs.push(["error", `Errors (${counts.error})`]);
1774
1775
  for (const [key, label] of defs) {
1775
1776
  const b = button(
@@ -1,3 +1,4 @@
1
+ import { spawn } from "node:child_process";
1
2
  import { createHash } from "node:crypto";
2
3
  import { deflateRawSync, inflateRawSync } from "node:zlib";
3
4
  import { constants } from "node:fs";
@@ -55,6 +56,32 @@ function failure(message, status = 400) {
55
56
  return Object.assign(new Error(message), { status, statusCode: status });
56
57
  }
57
58
 
59
+ const darwin = process.platform === "darwin";
60
+
61
+ async function openedFilePath(handle) {
62
+ if (!darwin) return realpath(`/proc/self/fd/${handle.fd}`);
63
+ // Use the inherited descriptor, not the original pathname. Darwin fcntl(2)
64
+ // F_GETPATH is 50, with a MAXPATHLEN (1024-byte) output buffer.
65
+ return new Promise((resolvePath, reject) => {
66
+ const helper = spawn("/usr/bin/perl", ["-e", String.raw`
67
+ open(my $file, "<&=3") or exit 1;
68
+ my $path = "\0" x 1024;
69
+ defined fcntl($file, 50, $path) or exit 1;
70
+ $path =~ s/\x00.*\z//s;
71
+ print $path;
72
+ `], { stdio: ["ignore", "pipe", "ignore", handle.fd], env: { PATH: "/usr/bin:/bin" },
73
+ signal: AbortSignal.timeout(2000) });
74
+ const chunks = [];
75
+ helper.stdout.on("data", chunk => chunks.push(chunk));
76
+ helper.once("error", () => reject(failure("Could not verify the opened file path", 403)));
77
+ helper.once("close", code => {
78
+ const path = Buffer.concat(chunks).toString("utf8");
79
+ if (code !== 0 || !isAbsolute(path)) reject(failure("Could not verify the opened file path", 403));
80
+ else resolvePath(path);
81
+ });
82
+ });
83
+ }
84
+
58
85
  /** Reads only files under a configured root, including after an open races with a rename. */
59
86
  async function safeOpen(root, name) {
60
87
  if (typeof name !== "string" || name.includes("\0") || isAbsolute(name))
@@ -70,10 +97,10 @@ async function safeOpen(root, name) {
70
97
  }
71
98
  const handle = await open(
72
99
  target,
73
- constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK,
100
+ constants.O_RDONLY | constants.O_NONBLOCK | (darwin ? 0x20000000 : constants.O_NOFOLLOW),
74
101
  );
75
102
  try {
76
- const openedPath = await realpath(`/proc/self/fd/${handle.fd}`);
103
+ const openedPath = await openedFilePath(handle);
77
104
  if (!inside(root, openedPath))
78
105
  throw failure("Opened file escapes the Run directory", 403);
79
106
  const stat = await handle.stat();
@@ -340,6 +367,7 @@ class RunIndex {
340
367
  this.gaps = [];
341
368
  this.gapKeys = new Set();
342
369
  this.spans = [];
370
+ this.researchPoints = [];
343
371
  this.inputObservations = [];
344
372
  this.sessionToolResults = [];
345
373
  this.relations = [];
@@ -492,6 +520,16 @@ class RunIndex {
492
520
  ...(record.type === "session-event" ? { operationId: record.event.operationId, configuration: record.event.configuration } : {}) });
493
521
  this.configurationRecords.set(agentId, observations);
494
522
  }
523
+ if (kind === "research") {
524
+ if (agent && record.operation === "peer.ready" && typeof record.label === "string")
525
+ agent.label = searchName(record.label) ?? agent.label;
526
+ this.researchPoints.push({
527
+ id: event.id, agentId, kind, label: event.label, time: event.time,
528
+ detail: [record.candidate, record.sha256, record.basedOn, record.basedOnSha256, record.detail, typeof record.score === "number" ? String(record.score) : undefined]
529
+ .filter(value => typeof value === "string").join(" · ").slice(0, 540),
530
+ status: record.operation === "train.unknown" ? "failed" : "recorded", evidenceIds: [event.id],
531
+ });
532
+ }
495
533
  if (record.type === "spawn" && agent) {
496
534
  this.coreAgents.add(agentId);
497
535
  if (record.profile) agent.profile = record.profile;
@@ -1085,6 +1123,7 @@ class RunIndex {
1085
1123
  });
1086
1124
  }
1087
1125
  await this.jsonl("evidence.jsonl");
1126
+ await this.jsonl("research-events.jsonl", "research");
1088
1127
  const names = await readdir(this.path);
1089
1128
  for (const name of names.filter(name => /^service-calls(?:-recovery-\d+)?\.jsonl$/.test(name)).sort()) {
1090
1129
  await this.jsonl(name, "service");
@@ -1232,6 +1271,7 @@ class RunIndex {
1232
1271
  ...this.spans,
1233
1272
  ...openSpans,
1234
1273
  ...this.inputObservations,
1274
+ ...this.researchPoints,
1235
1275
  ...(!this.hasNative ? this.sessionToolResults : []),
1236
1276
  ];
1237
1277
  }
package/docs/INDEX.md CHANGED
@@ -14,7 +14,7 @@ Start with the user guides to run a Harness or build your own. The English and C
14
14
  | Build a parallel Swarm step by step | [Build a Swarm Harness](en/build-your-harness.md) | [实战:构建 Swarm Harness](zh/build-your-harness.md) |
15
15
  | Compare the five collaboration patterns | [Choose a Harness](en/harnesses/index.md) | [选择 Harness](zh/harnesses/index.md) |
16
16
  | Look up SDK exports, CLI flags & types | [API](en/reference/api.md) · [CLI](en/reference/cli.md) · [Types](en/reference/types.md) | [API](zh/reference/api.md) · [CLI](zh/reference/cli.md) · [类型](zh/reference/types.md) |
17
- | Track the latest release & changelog | [Releases and main updates](en/latest.md) · [Changelog](en/changelog.md) | [最新版本](zh/latest.md) · [更新日志](zh/changelog.md) |
17
+ | Track the latest release & changelog | [Releases](en/latest.md) · [Changelog](en/changelog.md) | [最新版本](zh/latest.md) · [更新日志](zh/changelog.md) |
18
18
 
19
19
  ## Understand or change the implementation
20
20
 
@@ -23,8 +23,10 @@ Start with the user guides to run a Harness or build your own. The English and C
23
23
  | Reference | Purpose |
24
24
  | --- | --- |
25
25
  | [Development](workflows/development.md) | Build, validate and contribute changes. |
26
+ | [Release updates and documentation versions](workflows/release-and-docs-versioning.md) | Publish the next release and plan versioned guides. |
26
27
  | [Coding Agent instructions](../AGENTS.md) | Project-specific work rules, permissions and documentation requirements. |
27
28
  | [Engineering record conventions](../AGENTS.md#engineering-record-conventions) | Issue scope, evidence and triage conventions. |
29
+ | [AutoResearch](architecture/28-autoresearch.md) | Prepare the FrontierCS-2 demo, watch peer research and inspect official evaluation records. |
28
30
  | [Trace Viewer](operations/trace-viewer.md) | Inspect saved and active Run records. |
29
31
  | [Website implementation](architecture/22-website.md) | Content loading, links, bilingual build and deployment. |
30
32
  | [Research context](PROJECT.md) · [Experiment workflow](workflows/experiment.md) | Research questions, resources and evidence standards. |
@@ -96,4 +96,4 @@ The [known boundaries](09-known-boundaries.md) belong to the current contract. T
96
96
 
97
97
  AnySwarm ships one package, `@anyswarm/core`. The host invokes `anyswarm`, and the Agent invokes `swarm` in its Sandbox. The Controller and Worker share `ANYSWARM_*` variables and `x-anyswarm-*` headers. The Worker advertises `anyswarm-core-v2` and installs its programs under `/opt/anyswarm`. Runtime startup and recovery attest the Worker protocol before using its control and event interfaces. An incompatible Worker fails the protocol check; a failed startup retains ownership until allocation cleanup is confirmed.
98
98
 
99
- Setup writes private connection settings under `~/.config/anyswarm/` and local Lifecycle keys under `~/.cache/anyswarm/opensandbox/`. Editable projects use `.anyswarm/`; default foreground run output is under the `anyswarm/runs` path of the user state directory. Existing release settings and editable projects require migration. Keep the previous host and Worker available for any in-progress recovery, and use an explicit trace root to inspect older saved reports. See the [upgrade steps](../en/latest.md#migrate-from-v030).
99
+ Setup writes private connection settings under `~/.config/anyswarm/` and local Lifecycle keys under `~/.cache/anyswarm/opensandbox/`. Editable projects use `.anyswarm/`; default foreground run output is under the `anyswarm/runs` path of the user state directory. Existing release settings and editable projects require migration. Keep the previous host and Worker available for any in-progress recovery, and use an explicit trace root to inspect older saved reports. See the [upgrade steps](https://github.com/AnySwarm/anyswarm/blob/v0.5.0/docs/en/latest.md#migrate-from-v030).