@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
@@ -0,0 +1,302 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { appendFileSync } from 'node:fs';
3
+ import { mkdir, writeFile } from 'node:fs/promises';
4
+ import { join } from 'node:path';
5
+ import { inProcessService, type JsonValue, type Runtime, type ServiceInterface } from '@anyswarm/core';
6
+
7
+ export const candidatePath = '.anyswarm-candidate.patch';
8
+ const maxPatch = 1024 * 1024 - 1536;
9
+ const patchChunk = 24 * 1024;
10
+ const maxNotes = 512;
11
+
12
+ export interface Evaluation {
13
+ valid: boolean;
14
+ score: number | null;
15
+ feedback: JsonValue;
16
+ }
17
+
18
+ export interface Evaluator {
19
+ start?(directory: string, signal: AbortSignal): Promise<void>;
20
+ close?(): Promise<'complete' | 'pending'>;
21
+ evidence?(): JsonValue;
22
+ train(candidate: Buffer, signal: AbortSignal, admitted: (reference: string | number) => void): Promise<Evaluation>;
23
+ final(candidate: Buffer, signal: AbortSignal): Promise<JsonValue>;
24
+ }
25
+
26
+ export interface Candidate {
27
+ id: string;
28
+ agentId: string;
29
+ sha256: string;
30
+ bytes: number;
31
+ summary: string;
32
+ basedOn: string | null;
33
+ path: string;
34
+ state: 'queued' | 'evaluating' | 'scored' | 'invalid' | 'unknown' | 'cancelled';
35
+ officialJob?: string | number;
36
+ evaluation?: Evaluation;
37
+ }
38
+
39
+ interface ResearchEvent {
40
+ seq: number;
41
+ at: string;
42
+ type: 'research';
43
+ operation: string;
44
+ agentId?: string;
45
+ to?: string;
46
+ detail?: string;
47
+ candidate?: string;
48
+ basedOn?: string;
49
+ sha256?: string;
50
+ basedOnSha256?: string;
51
+ score?: number | null;
52
+ officialJob?: string | number;
53
+ label?: string;
54
+ }
55
+
56
+ const text = (maxLength: number) => ({ type: 'string', minLength: 1, maxLength });
57
+ const object = (properties: Record<string, unknown>, required: string[]) =>
58
+ ({ type: 'object', properties, required, additionalProperties: false });
59
+ const identifier = text(200);
60
+ const summary = text(400);
61
+ const candidateId = { type: 'string', pattern: '^candidate-[0-9]+$' };
62
+
63
+ const researchInterface: ServiceInterface = {
64
+ description: 'One team’s shared research directions, peer messages, candidate patches and trusted train results.',
65
+ operations: {
66
+ board: { description: 'See the team’s current directions, messages, candidates and train scores.', sideEffect: 'read' },
67
+ claim: { description: 'Announce the research direction you are taking.', inputSchema: object({ direction: summary }, ['direction']), idempotent: true },
68
+ publish: { description: 'Share a finding or a peer candidate review.', inputSchema: object({
69
+ kind: { enum: ['finding', 'review'] }, summary, candidate: candidateId,
70
+ }, ['kind', 'summary']), idempotent: true },
71
+ message: { description: 'Send a short research message to another peer.', inputSchema: object({ peer: identifier, summary }, ['peer', 'summary']), idempotent: true },
72
+ submit: { description: `Queue the exact patch saved at ${candidatePath} for trusted evaluation. Optionally reference a peer candidate you built on.`,
73
+ inputSchema: object({ summary, basedOn: candidateId }, ['summary']), idempotent: true },
74
+ read_patch: { description: 'Read a peer candidate patch segment by byte offset. Decode base64 and use nextOffset until it is null.', sideEffect: 'read',
75
+ inputSchema: object({ candidate: candidateId, offset: { type: 'integer', minimum: 0 } }, ['candidate', 'offset']) },
76
+ },
77
+ };
78
+ export const researchOperations = Object.keys(researchInterface.operations);
79
+
80
+ function validScore(result: Evaluation) {
81
+ return result.valid && typeof result.score === 'number' && Number.isFinite(result.score);
82
+ }
83
+
84
+ export function createResearch(options: {
85
+ outputDir: string;
86
+ direction: 'max' | 'min';
87
+ maxEvaluations: number;
88
+ targetScore?: number;
89
+ deadlineAt: number;
90
+ evaluationTimeoutMs: number;
91
+ signal: AbortSignal;
92
+ trainSignal?: AbortSignal;
93
+ evaluator: Evaluator;
94
+ traceEvent: (event: ResearchEvent) => void;
95
+ statusChanged: () => void;
96
+ stopWork?: (reason: string) => void;
97
+ readPatch: (agentId: string, requestId: string) => Promise<Buffer>;
98
+ }) {
99
+ const events: ResearchEvent[] = [];
100
+ const peers = new Map<string, string>();
101
+ const candidates = new Map<string, Candidate>();
102
+ const known = new Map<string, Candidate>();
103
+ const patches = new Map<string, Buffer>();
104
+ const reads = new Map<string, Map<string, number>>();
105
+ const claims = new Map<string, string>();
106
+ let best: Candidate | undefined;
107
+ let reserved = 0;
108
+ let closed = false;
109
+ let stopReason: string | undefined;
110
+ let queue = Promise.resolve();
111
+ const project = (record: unknown) => record as JsonValue;
112
+ const reached = (score: number, target: number) => options.direction === 'max' ? score >= target : score <= target;
113
+ function event(operation: string, data: Omit<ResearchEvent, 'operation' | 'seq' | 'at' | 'type'> = {}) {
114
+ const entry = { ...data, seq: events.length + 1, at: new Date().toISOString(), type: 'research' as const, operation };
115
+ events.push(entry);
116
+ options.traceEvent(entry);
117
+ options.statusChanged();
118
+ }
119
+ function admit() {
120
+ if (closed || stopReason || options.signal.aborted || events.length >= maxNotes) throw new Error('Research admissions are closed');
121
+ }
122
+ function state() {
123
+ return {
124
+ peers: [...peers].map(([agentId, label]) => ({ agentId, label })),
125
+ best: best ? { id: best.id, score: best.evaluation?.score, author: peers.get(best.agentId) } : null,
126
+ budget: { evaluations: reserved, maxEvaluations: options.maxEvaluations, deadlineAt: options.deadlineAt },
127
+ recent: events.slice(-12).map(entry => ({ ...entry, peer: entry.agentId ? peers.get(entry.agentId) : 'host' })),
128
+ };
129
+ }
130
+ function readEntirePatch(agentId: string, id: string) {
131
+ const bytes = patches.get(id);
132
+ return bytes !== undefined && reads.get(agentId)?.get(id) === bytes.length;
133
+ }
134
+ async function evaluate(candidate: Candidate, bytes: Buffer) {
135
+ if (closed || stopReason || options.signal.aborted || Date.now() >= options.deadlineAt) {
136
+ candidate.state = 'cancelled';
137
+ event('candidate.cancelled', { agentId: candidate.agentId, candidate: candidate.id });
138
+ return;
139
+ }
140
+ candidate.state = 'evaluating';
141
+ event('train.started', { agentId: candidate.agentId, candidate: candidate.id });
142
+ try {
143
+ const signal = AbortSignal.any([options.trainSignal ?? options.signal, AbortSignal.timeout(options.evaluationTimeoutMs)]);
144
+ const evaluation = await withDeadline(signal, () => options.evaluator.train(Buffer.from(bytes), signal, reference => {
145
+ if (signal.aborted || candidate.state !== 'evaluating') return;
146
+ candidate.officialJob = reference;
147
+ event('train.admitted', { agentId: candidate.agentId, candidate: candidate.id, officialJob: reference });
148
+ }));
149
+ candidate.evaluation = evaluation;
150
+ candidate.state = validScore(evaluation) ? 'scored' : 'invalid';
151
+ event('train.returned', { agentId: candidate.agentId, candidate: candidate.id, score: evaluation.score });
152
+ if (validScore(evaluation) && (!best || (evaluation.score !== best.evaluation!.score && reached(evaluation.score!, best.evaluation!.score!)))) {
153
+ best = candidate;
154
+ event('candidate.best', { agentId: candidate.agentId, candidate: candidate.id, score: evaluation.score });
155
+ }
156
+ if (best && options.targetScore !== undefined && reached(best.evaluation!.score!, options.targetScore)) {
157
+ stopReason = 'target-reached';
158
+ options.stopWork?.(stopReason);
159
+ }
160
+ } catch (error) {
161
+ candidate.state = 'unknown';
162
+ stopReason = 'train-outcome-unknown';
163
+ event('train.unknown', { agentId: candidate.agentId, candidate: candidate.id, detail: error instanceof Error ? error.message.slice(0, 320) : 'Evaluation failed' });
164
+ options.stopWork?.(stopReason);
165
+ }
166
+ }
167
+ const service = inProcessService(researchInterface, {
168
+ board: (_, { caller, assertAuthorized }) => {
169
+ assertAuthorized();
170
+ return project({
171
+ ...state(), recent: events.filter(entry => !entry.to || entry.to === caller.agentId || entry.agentId === caller.agentId).slice(-12),
172
+ claims: [...claims].slice(-32).map(([direction, agentId]) => ({ direction, agentId })),
173
+ candidates: [...candidates.values()].slice(-8).map(({ path: _, ...candidate }) => candidate),
174
+ });
175
+ },
176
+ claim: (input, { caller, assertAuthorized }) => {
177
+ assertAuthorized();
178
+ admit();
179
+ const direction = (input as { direction: string }).direction.trim();
180
+ if (!direction) throw new Error('Provide a research direction');
181
+ const key = direction.toLowerCase();
182
+ const current = claims.get(key);
183
+ if (current) return { claimed: current === caller.agentId, agentId: current };
184
+ claims.set(key, caller.agentId);
185
+ event('peer.claim', { agentId: caller.agentId, detail: direction });
186
+ return { claimed: true, agentId: caller.agentId };
187
+ },
188
+ publish: (input, { caller, assertAuthorized }) => {
189
+ assertAuthorized();
190
+ admit();
191
+ const { kind, summary, candidate } = input as { kind: 'finding' | 'review'; summary: string; candidate?: string };
192
+ const reviewed = candidate === undefined ? undefined : candidates.get(candidate);
193
+ if (candidate !== undefined && !reviewed) throw new Error('Candidate does not exist');
194
+ if (kind === 'review' && (!reviewed || reviewed.agentId === caller.agentId || !readEntirePatch(caller.agentId, reviewed.id))) {
195
+ throw new Error('Read the other peer’s candidate before reviewing it');
196
+ }
197
+ event(`peer.${kind}`, { agentId: caller.agentId, detail: summary,
198
+ ...(reviewed ? { candidate: reviewed.id, sha256: reviewed.sha256 } : {}) });
199
+ return { published: true };
200
+ },
201
+ message: (input, { caller, assertAuthorized }) => {
202
+ assertAuthorized();
203
+ admit();
204
+ const { peer, summary } = input as { peer: string; summary: string };
205
+ if (peer === caller.agentId || !peers.has(peer)) throw new Error('Peer does not belong to this Run');
206
+ event('peer.message', { agentId: caller.agentId, to: peer, detail: summary });
207
+ return { sent: true };
208
+ },
209
+ read_patch: (input, { caller, assertAuthorized }) => {
210
+ assertAuthorized();
211
+ admit();
212
+ const { candidate, offset } = input as { candidate: string; offset: number };
213
+ const bytes = patches.get(candidate);
214
+ if (!bytes || offset >= bytes.length) throw new Error('Candidate or patch offset does not exist');
215
+ let progress = reads.get(caller.agentId);
216
+ if (!progress) reads.set(caller.agentId, progress = new Map());
217
+ const received = progress.get(candidate) ?? 0;
218
+ if (offset > received) throw new Error('Read the patch in order, starting at offset 0');
219
+ const start = offset;
220
+ const end = Math.min(bytes.length, start + patchChunk);
221
+ const sha256 = candidates.get(candidate)!.sha256;
222
+ if (end > received) {
223
+ progress.set(candidate, end);
224
+ if (end === bytes.length) event('peer.read-patch', { agentId: caller.agentId, candidate, sha256, to: caller.agentId });
225
+ }
226
+ return { candidate, sha256, data: bytes.subarray(start, end).toString('base64'), nextOffset: end < bytes.length ? end : null };
227
+ },
228
+ submit: async (input, { caller, envelope, assertAuthorized }) => {
229
+ assertAuthorized();
230
+ admit();
231
+ const { summary, basedOn } = input as { summary: string; basedOn?: string };
232
+ if (basedOn && !readEntirePatch(caller.agentId, basedOn)) throw new Error('Read the referenced candidate before building on it');
233
+ const bytes = await options.readPatch(caller.agentId, envelope.operation_id);
234
+ assertAuthorized();
235
+ admit();
236
+ if (!bytes.length || bytes.length > maxPatch) throw new Error('Candidate patch is empty or exceeds the size limit');
237
+ const sha256 = createHash('sha256').update(bytes).digest('hex');
238
+ const previous = known.get(sha256);
239
+ if (previous) return { candidate: previous.id, status: previous.state, duplicate: true, sha256 };
240
+ if (reserved >= options.maxEvaluations) throw new Error('Shared evaluation budget is exhausted');
241
+ reserved++;
242
+ const id = `candidate-${reserved}`;
243
+ const path = join(options.outputDir, 'candidates', `${id}.patch`);
244
+ const candidate: Candidate = { id, agentId: caller.agentId, summary, basedOn: basedOn ?? null, path,
245
+ sha256, bytes: bytes.length, state: 'queued' };
246
+ known.set(sha256, candidate);
247
+ try {
248
+ await mkdir(join(options.outputDir, 'candidates'), { recursive: true, mode: 0o700 });
249
+ await writeFile(path, bytes, { mode: 0o600, flag: 'wx' });
250
+ assertAuthorized();
251
+ admit();
252
+ } catch (error) {
253
+ candidate.state = 'cancelled';
254
+ candidates.set(id, candidate);
255
+ throw error;
256
+ }
257
+ patches.set(id, bytes);
258
+ candidates.set(id, candidate);
259
+ event(basedOn ? 'candidate.built-on' : 'candidate.queued', { agentId: caller.agentId, candidate: id, sha256, detail: summary,
260
+ ...(basedOn ? { basedOn, basedOnSha256: candidates.get(basedOn)!.sha256 } : {}) });
261
+ queue = queue.then(() => evaluate(candidate, bytes));
262
+ return { candidate: id, status: candidate.state, duplicate: false, sha256 };
263
+ },
264
+ }, {
265
+ readState: () => ({
266
+ state: project(state()), capturedAt: new Date().toISOString(), revision: String(events.length),
267
+ presentation: {
268
+ summary: [{ label: 'Best', path: '/best/id' }, { label: 'Score', path: '/best/score' },
269
+ { label: 'Evaluations queued', path: '/budget/evaluations' }, { label: 'Evaluation limit', path: '/budget/maxEvaluations' }],
270
+ tables: [{ title: 'Research activity', path: '/recent', columns: [
271
+ { label: 'Peer', path: '/peer' }, { label: 'Activity', path: '/operation' }, { label: 'Candidate', path: '/candidate' }, { label: 'Detail', path: '/detail' },
272
+ ] }],
273
+ },
274
+ }),
275
+ });
276
+ return { service, state, event,
277
+ addPeer: (id: string, label: string) => { peers.set(id, label); event('peer.ready', { agentId: id, label }); },
278
+ close: () => { closed = true; },
279
+ stopReason: () => stopReason,
280
+ drained: () => queue,
281
+ best: () => best,
282
+ peerLabel: (agentId: string) => peers.get(agentId),
283
+ selection: () => best ?? [...candidates.values()].find(candidate => candidate.state === 'invalid'),
284
+ patch: (candidate: Candidate) => Buffer.from(patches.get(candidate.id)!),
285
+ candidates: () => [...candidates.values()],
286
+ };
287
+ }
288
+
289
+ export async function withDeadline<T>(signal: AbortSignal, work: () => Promise<T>): Promise<T> {
290
+ signal.throwIfAborted();
291
+ let rejectAborted: () => void;
292
+ const aborted = new Promise<never>((_, reject) => {
293
+ rejectAborted = () => reject(signal.reason instanceof Error ? signal.reason : new Error(String(signal.reason)));
294
+ signal.addEventListener('abort', rejectAborted, { once: true });
295
+ });
296
+ try { return await Promise.race([aborted, work()]); }
297
+ finally { signal.removeEventListener('abort', rejectAborted!); }
298
+ }
299
+
300
+ export function appendResearchEvent(runtime: Runtime, output: string, entry: ResearchEvent) {
301
+ appendFileSync(join(output, runtime.id, 'research-events.jsonl'), JSON.stringify({ ...entry, runtimeId: runtime.id }) + '\n', { mode: 0o600 });
302
+ }
@@ -0,0 +1,33 @@
1
+ # Code SDK example
2
+
3
+ Code runs a coding Agent in a writable Sandbox, verifies a candidate on the Linux
4
+ host and applies authorized edits to the project. Ask the lead Agent to delegate
5
+ a separable task when you want an editor to work in parallel. Between turns,
6
+ Code reconciles edits made by the user and returns conflicting paths for review.
7
+
8
+ Prepare OpenSandbox, a supported Pi or Codex Worker and a model route. Export the
9
+ source outside the target project and install its pinned SDK.
10
+
11
+ ```sh
12
+ anyswarm eject code --dir ./my-code
13
+ cd ./my-code
14
+ npm install
15
+ npm run start -- --cwd /path/to/project --config ./trusted.ts --prompt "Add a test for empty input" --output-dir ./runs
16
+ anyswarm trace --root ./runs
17
+ ```
18
+
19
+ The default configuration reads `ANYSWARM_MODEL_URL`, optional
20
+ `ANYSWARM_MODEL_TOKEN`, `ANYSWARM_MODEL_ID` and `ANYSWARM_MODEL_PROVIDER`.
21
+ Code-specific `ANYSWARM_CODE_*` values take precedence. The example command uses
22
+ an explicit trusted config. Set `check` to an argv array to authorize
23
+ verification, or set `check: false` to skip it. Checks run with the host user's
24
+ permissions in a temporary copy and can reuse a supported Node dependency
25
+ installation. A failed check or writeback conflict retains the original files.
26
+ The Run report includes verification, changed paths and the retained diff.
27
+
28
+ For follow-up turns and questions, import the Harness in an application and
29
+ drive it through `createHarnessSession`, or connect to
30
+ `npm run start -- --mode rpc --lifetime interactive --interaction questions`
31
+ with `HarnessRpcClient`. Send the target directory in the RPC `run` input.
32
+ See [HarnessSession clients](../harness-session/README.md) for the protocol and
33
+ [Code architecture](../../docs/architecture/26-code.md) for writeback rules.
@@ -0,0 +1,11 @@
1
+ # Code 用户需求
2
+
3
+ 适用范围见 [#336](https://github.com/AnySwarm/anyswarm/issues/336)。[#351](https://github.com/AnySwarm/anyswarm/issues/351) 将 Code 保留为进阶 SDK 示例。单次运行接收任务和显式配置,多轮输入、问答、差异和成员控制由 SDK 或 RPC 客户端处理。
4
+
5
+ - 一个会话由一个 Runtime 管理。主 Agent 默认在一个可写的隔离工作区读项目、改代码并运行检查。用户可以在聊天中要求委派,主 Agent 可以和独立子 Agent 同时工作,收取结果并审查。用户可针对任意活跃成员发消息、中断或停止。
6
+ - 每轮以用户当前目录的内容为起点,包含已跟踪文件的未提交修改和未忽略的新文件。宿主比较主 Agent、已收取的子 Agent 结果和实时工作树,合并后按任务授权写回。用户改动冲突时显示路径并保留原文件。
7
+ - 用户可见改动文件和实际 diff。宿主监督配置或用户确认的检查,并展示命令、退出码和状态。Node 检查可复用受支持的现有依赖安装,缺失时显示校验环境问题。无命令时显示未验证。校验失败时保留原项目文件。
8
+ - 多轮客户端可以请求中断当前轮,之后继续输入,也可停止整个会话并等待清理。单次运行在任务完成、清理确认后返回 0。会话收尾保留报告、检查结果、已写入的路径和 Trace。
9
+ - `anyswarm eject code` 导出完整 TS 应用。作者能在仓库外直接运行、修改并重新执行其副本。
10
+
11
+ 验收使用同一个仓库外安装的候选包。用真实项目覆盖默认单 Agent 两轮编辑、用户明确要求并行委派、中断后继续、验证失败、并行成员控制、退出清理和导出源码。记录每轮文件上传下载字节数、实际容器数、峰值内存和最终检查结果。ProgramBench 使用同一 Code 应用,运行状态和官方评分单独记录。
@@ -0,0 +1,89 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { completeFileTreeDigest, decodeFileTree, isGitTreePath, snapshotFileTree,
3
+ type CompleteFileDigest, type FileBudget, type FileEntry, type FileTree } from '@anyswarm/core';
4
+
5
+ export interface CodeChange {
6
+ readonly path: string;
7
+ readonly before?: FileEntry;
8
+ readonly after?: FileEntry;
9
+ }
10
+
11
+ type Candidate = { status: 'conflict'; paths: readonly string[] } | {
12
+ status: 'ready'; files: FileTree; digest: CompleteFileDigest; changes: readonly CodeChange[];
13
+ };
14
+
15
+ function canonical(tree: FileTree, budget?: FileBudget) {
16
+ return new Map(decodeFileTree(tree, budget).entries.map(({ path, bytes, mode }) => [path, Object.freeze({
17
+ encoding: 'base64' as const, data: Buffer.from(bytes).toString('base64'), mode: mode as 0o644 | 0o755,
18
+ })]));
19
+ }
20
+
21
+ function same(left: FileEntry | undefined, right: FileEntry | undefined) {
22
+ return left?.mode === right?.mode && left?.data === right?.data;
23
+ }
24
+
25
+ export async function selectEditorFiles(cwd: string, baseline: FileTree, files: FileTree, git: boolean, signal: AbortSignal) {
26
+ const added = Object.keys(files).filter(path => !Object.hasOwn(baseline, path));
27
+ const excluded = new Set(added.filter(path => /^(?:node_modules|\.anyswarm-sdk|\.anyswarm-code-recovery-[A-Za-z0-9]{6})(?:\/|$)/.test(path)));
28
+ const remaining = added.filter(path => !excluded.has(path));
29
+ if (git && remaining.length) {
30
+ const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_')));
31
+ const ignored = await new Promise<string>((resolve, reject) => {
32
+ const process = execFile('git', ['check-ignore', '-z', '--stdin'], { cwd, env,
33
+ signal, timeout: 10_000, maxBuffer: 64 * 1024 ** 2 }, (error, stdout) => {
34
+ if (!error || error.code === 1) resolve(stdout);
35
+ else reject(error);
36
+ });
37
+ process.stdin?.on('error', reject);
38
+ process.stdin?.end(remaining.join('\0') + '\0');
39
+ });
40
+ for (const path of ignored.split('\0')) if (path) excluded.add(path);
41
+ }
42
+ return excluded.size ? Object.fromEntries(Object.entries(files).filter(([path]) => !excluded.has(path))) : files;
43
+ }
44
+
45
+ /** Integrate independent Worker proposals against the live host tree before verification and apply. */
46
+ export function prepareCodeCandidate(baseline: FileTree, current: FileTree, proposals: readonly FileTree[], budget?: FileBudget, candidateBudget = budget): Candidate {
47
+ const base = canonical(baseline, budget);
48
+ const host = canonical(current, budget);
49
+ const edits = new Map<string, FileEntry | undefined>();
50
+ const conflicts = new Set<string>();
51
+
52
+ for (const proposal of proposals) {
53
+ const worker = canonical(proposal, budget);
54
+ for (const path of new Set([...base.keys(), ...worker.keys()])) {
55
+ const previous = base.get(path);
56
+ const after = worker.get(path);
57
+ if (same(previous, after)) continue;
58
+ const local = host.get(path);
59
+ if (!isGitTreePath(path) || (!same(local, previous) && !same(local, after)) ||
60
+ (edits.has(path) && !same(edits.get(path), after))) {
61
+ conflicts.add(path);
62
+ }
63
+ edits.set(path, after);
64
+ }
65
+ }
66
+
67
+ const files = new Map<string, FileEntry>(host);
68
+ const changes: CodeChange[] = [];
69
+ for (const path of [...edits.keys()].sort()) {
70
+ const before = host.get(path);
71
+ const after = edits.get(path);
72
+ if (same(before, after)) continue;
73
+ if (after) files.set(path, after);
74
+ else files.delete(path);
75
+ changes.push(Object.freeze({ path, before, after }));
76
+ }
77
+
78
+ for (const path of files.keys()) {
79
+ for (let slash = path.indexOf('/'); slash !== -1; slash = path.indexOf('/', slash + 1)) {
80
+ const parent = path.slice(0, slash);
81
+ if (files.has(parent)) conflicts.add(parent);
82
+ }
83
+ }
84
+ if (conflicts.size) return { status: 'conflict', paths: [...conflicts].sort() };
85
+
86
+ const candidate = Object.freeze(Object.fromEntries(files));
87
+ const { digest } = snapshotFileTree(candidate, candidateBudget);
88
+ return { status: 'ready', digest: completeFileTreeDigest(digest), files: candidate, changes: Object.freeze(changes) };
89
+ }
@@ -0,0 +1,19 @@
1
+ import { resolveSandboxConnection, workerImageFor } from '@anyswarm/core';
2
+
3
+ const { image, advertiseHost, publicUrl, endpointSource: _source, executor: installedExecutor, ...sandbox } = resolveSandboxConnection({}, 'CODE');
4
+ const upstream = process.env.ANYSWARM_CODE_MODEL_URL ?? process.env.ANYSWARM_MODEL_URL;
5
+ if (!upstream) throw new Error('Set ANYSWARM_MODEL_URL or ANYSWARM_CODE_MODEL_URL before running Code');
6
+ const token = process.env.ANYSWARM_CODE_MODEL_TOKEN ?? process.env.ANYSWARM_MODEL_TOKEN;
7
+ const executor = process.env.ANYSWARM_CODE_EXECUTOR ?? process.env.ANYSWARM_EXECUTOR ?? installedExecutor ?? 'pi';
8
+ const model = process.env.ANYSWARM_CODE_MODEL_ID ?? process.env.ANYSWARM_MODEL_ID ?? 'gpt-5.4';
9
+
10
+ export default {
11
+ executor,
12
+ image: image ?? workerImageFor(executor),
13
+ sandbox: { ...sandbox, resourceLimits: { cpu: '1', memory: '1Gi' } },
14
+ connection: { publicUrl, advertiseHost },
15
+ models: { default: {
16
+ provider: process.env.ANYSWARM_CODE_MODEL_PROVIDER ?? process.env.ANYSWARM_MODEL_PROVIDER ?? 'openai', model,
17
+ upstream: { url: upstream, headers: token ? { authorization: `Bearer ${token}` } : {} },
18
+ } },
19
+ };
@@ -0,0 +1,5 @@
1
+ {
2
+ "apiVersion": 1,
3
+ "entry": "project.ts",
4
+ "files": ["project.ts", "config.ts", "candidate.ts", "worktree.ts", "verification.ts", "prompts.ts", "README.md", "REQUIREMENTS.zh.md"]
5
+ }