@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
@@ -1,6 +1,7 @@
1
1
  import type { Runtime, InputReceipt, ConditionalInputReceipt, InterruptReceipt, StopReceipt, SendOptions, ErrorDiagnostic } from '../core/types.js';
2
2
  import type { AgentSessionPatch, AgentSessionState, AgentSessionStats, AgentSessionMessages, ContextInput, ContextSendOptions, ContextInputReceipt, SessionControlReceipt } from '../core/session-types.js';
3
3
  import type { HarnessInput, HarnessJson, Harness } from './project-harness.js';
4
+ import type { ServiceStateRead, ServiceStateSource } from '../core/service-observation-types.js';
4
5
  export type HarnessLifetime = 'task' | 'interactive';
5
6
  export type HarnessRequest = Readonly<{
6
7
  requestId: string;
@@ -26,6 +27,8 @@ export type HarnessInputDescriptor = Readonly<{
26
27
  description?: string;
27
28
  schema?: HarnessJson;
28
29
  targets?: HarnessJson;
30
+ /** Terminal slash commands or explicit @mentions routed as Harness input. */
31
+ commands?: readonly string[];
29
32
  }>;
30
33
  export type HarnessDescriptor = Readonly<{
31
34
  id: string;
@@ -224,6 +227,12 @@ export interface HarnessAgents {
224
227
  reason?: string;
225
228
  }): Promise<HarnessAgentReceipt<StopReceipt>>;
226
229
  }
230
+ export interface HarnessServices {
231
+ list(): Promise<readonly (ServiceStateSource & {
232
+ readonly runtimeId: string;
233
+ })[]>;
234
+ read(runtimeId: string, name: string): Promise<ServiceStateRead>;
235
+ }
227
236
  export interface HarnessSession {
228
237
  describe(): Promise<HarnessDescriptor>;
229
238
  start(input: HarnessInput, request: HarnessRequest): Promise<HarnessStartReceipt>;
@@ -232,6 +241,7 @@ export interface HarnessSession {
232
241
  getState(): Promise<HarnessState>;
233
242
  onEvent(handler: (event: HarnessEvent) => void, options?: HarnessSubscriptionOptions): () => void;
234
243
  readonly agents: HarnessAgents;
244
+ readonly services: HarnessServices;
235
245
  stop(request: HarnessRequest & {
236
246
  reason?: string;
237
247
  }): Promise<HarnessStopReceipt>;
@@ -171,13 +171,34 @@ export function createHarnessSession(definition, options = {}) {
171
171
  if (!event || typeof event !== 'object' || Array.isArray(event) || !('messageId' in event) || typeof event.messageId !== 'string')
172
172
  return;
173
173
  const eventObject = event;
174
- const key = String(runtimeObject.agentId ?? '') + ':' + eventObject.messageId;
174
+ const agentId = runtimeObject.agentId ?? null;
175
+ const messageId = eventObject.messageId;
176
+ const key = JSON.stringify([agentId, messageId]);
175
177
  const previous = output.get(key);
176
- if (eventObject.type === 'textDelta' && typeof eventObject.delta === 'string') {
177
- output.set(key, { agentId: runtimeObject.agentId ?? null, messageId: eventObject.messageId, text: ((previous?.text ?? '') + eventObject.delta).slice(-16_384), truncated: (previous?.text?.length ?? 0) + eventObject.delta.length > 16_384, complete: false });
178
+ if (eventObject.type === 'textDelta' && typeof eventObject.delta === 'string' && !previous?.complete) {
179
+ const index = Number.isSafeInteger(eventObject.blockIndex) ? Number(eventObject.blockIndex) : 0;
180
+ const blocks = new Map(previous?.blocks);
181
+ blocks.set(index, (blocks.get(index) ?? '') + eventObject.delta);
182
+ let truncated = previous?.truncated ?? false;
183
+ if (blocks.size > 64) {
184
+ blocks.delete(blocks.keys().next().value);
185
+ truncated = true;
186
+ }
187
+ const ordered = [...blocks].sort(([left], [right]) => left - right);
188
+ let available = 16_384;
189
+ for (let position = ordered.length - 1; position >= 0; position--) {
190
+ const block = ordered[position];
191
+ if (block[1].length > available) {
192
+ block[1] = available ? block[1].slice(-available) : '';
193
+ truncated = true;
194
+ }
195
+ available -= block[1].length;
196
+ }
197
+ output.set(key, { agentId, messageId, text: ordered.map(([, text]) => text).join(''),
198
+ blocks: ordered, truncated, complete: false });
178
199
  }
179
200
  else if (eventObject.type === 'messageEnd') {
180
- output.set(key, { agentId: runtimeObject.agentId ?? null, messageId: eventObject.messageId, message: boundedView(eventObject.message ?? null, 16_384), complete: true });
201
+ output.set(key, { agentId, messageId, message: boundedView(eventObject.message ?? null, 16_384), complete: true });
181
202
  }
182
203
  while (output.size > 8 || Buffer.byteLength(JSON.stringify([...output.values()])) > Math.floor(limits.snapshotBytes / 4))
183
204
  output.delete(output.keys().next().value);
@@ -660,8 +681,24 @@ export function createHarnessSession(definition, options = {}) {
660
681
  interrupt: (agentId, request) => control('interrupt', agentId, null, request),
661
682
  stop: (agentId, options) => control('stop', agentId, { reason: options.reason }, options),
662
683
  };
684
+ const services = {
685
+ async list() {
686
+ if (stopping || finalizing)
687
+ return [];
688
+ return [...registrations.keys()].flatMap(({ runtime }) => (runtime.services?.listState?.() ?? []).map(source => ({ runtimeId: runtime.id, ...source })));
689
+ },
690
+ async read(runtimeId, name) {
691
+ const owner = [...registrations.keys()].find(({ runtime }) => runtime.id === runtimeId);
692
+ if (owner && !stopping && !finalizing && owner.runtime.services?.readState) {
693
+ const state = await owner.runtime.services.readState(name);
694
+ if (!stopping && !finalizing && registrations.has(owner))
695
+ return state;
696
+ }
697
+ return { status: 'unavailable', reason: 'Runtime does not provide live Service state for this Run' };
698
+ },
699
+ };
663
700
  const session = {
664
- agents,
701
+ agents, services,
665
702
  async describe() { for (const registration of registrations.keys())
666
703
  await refreshTargets(registration); return structuredClone(descriptor()); },
667
704
  async getState() { return snapshot(); },
@@ -50,6 +50,10 @@ export interface HarnessContext {
50
50
  readonly clientCapabilities: Readonly<{
51
51
  questions: boolean;
52
52
  }>;
53
+ /** Capture the live project with the same scope and policy as the initial input. Release temporary bytes when done. */
54
+ captureProject(signal?: AbortSignal): Promise<InitialProject & {
55
+ dispose(): Promise<void>;
56
+ }>;
53
57
  registerAgentControls(registration: HarnessAgentRegistration): () => void;
54
58
  /** Run owned work and use the close receipt in this Run's final report. */
55
59
  runWithRuntime<R extends CloseableRuntime>(options: HarnessRuntimeRunOptions<R>): Promise<HarnessRunOutcome>;
@@ -76,7 +80,15 @@ export type ProjectHarness = Harness;
76
80
  export type ProjectHarnessContext = HarnessContext;
77
81
  /** @deprecated Derive the author result from Harness.run. Use HarnessResult for Session completion. */
78
82
  export type ProjectHarnessResult = Awaited<ReturnType<Harness['run']>>;
79
- export declare function loadProjectHarness(directory: string, specifier: string, builtins?: Readonly<Record<string, string>>): Promise<Harness>;
83
+ export declare function loadProjectHarnessModule(directory: string, specifier: string, builtins?: Readonly<Record<string, string>>, options?: {
84
+ onSourceError?: (error: unknown) => void;
85
+ }): Promise<{
86
+ module: {
87
+ default?: Partial<ProjectHarness>;
88
+ } & Record<string, unknown>;
89
+ definition: Harness;
90
+ }>;
91
+ export declare function loadProjectHarness(...args: Parameters<typeof loadProjectHarnessModule>): Promise<Harness>;
80
92
  type Phase = 'idle' | 'starting' | 'running' | 'stopping' | 'finished';
81
93
  type StopReason = string;
82
94
  type Failure = {
@@ -112,6 +124,7 @@ type RunResult = ProjectHarnessResult & Pick<HarnessResult, 'operations' | 'ques
112
124
  reportPath?: string;
113
125
  };
114
126
  export declare function failureCode(error: unknown, fallback: string): string;
127
+ export declare function loadProjectConfiguration(directory: string, path: string | undefined): Promise<unknown>;
115
128
  export declare function createProjectHost(definition: ProjectHarness, options: StartupOptions, emit: (record: unknown) => void): {
116
129
  harness: {
117
130
  id: string;
@@ -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,14 +57,29 @@ 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 ?? {});
61
79
  return typeof code === 'string' && (/^[A-Z][A-Z0-9_]{0,79}$/.test(code) ||
62
80
  (errorDiagnostic(error) && /^[a-z][a-z0-9_]{0,79}$/.test(code))) ? code : fallback;
63
81
  }
64
- async function loadConfiguration(directory, path) {
82
+ export async function loadProjectConfiguration(directory, path) {
65
83
  if (!path)
66
84
  return undefined;
67
85
  let value;
@@ -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);
@@ -183,7 +201,7 @@ export function createProjectHost(definition, options, emit) {
183
201
  await writeFile(path, raw.prompt, { flag: 'wx', mode: 0o600 });
184
202
  promptPath = path;
185
203
  signal.throwIfAborted();
186
- const configuration = options.configuration !== undefined ? validateConfiguration(options.configuration) : await loadConfiguration(options.launchDirectory, options.configPath);
204
+ const configuration = options.configuration !== undefined ? validateConfiguration(options.configuration) : await loadProjectConfiguration(options.launchDirectory, options.configPath);
187
205
  signal.throwIfAborted();
188
206
  let filePolicy;
189
207
  try {
@@ -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 }),
@@ -63,7 +65,9 @@ export async function projectConfiguration(context, defaults) {
63
65
  throw new Error('Missing sandbox, models or image');
64
66
  }
65
67
  }
66
- catch {
68
+ catch (error) {
69
+ if (error instanceof ProjectPreflightError)
70
+ throw error;
67
71
  throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Configure sandbox, models and image for this Harness');
68
72
  }
69
73
  context.signal.throwIfAborted();
@@ -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
+ }