@anyswarm/core 0.5.1 → 0.6.0

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 (301) hide show
  1. package/AGENTS.md +20 -5
  2. package/README.md +69 -55
  3. package/dist/examples/README.md +138 -77
  4. package/dist/examples/authoring/README.md +4 -4
  5. package/dist/examples/autoresearch/README.md +108 -16
  6. package/dist/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
  7. package/dist/examples/autoresearch/config.d.ts +48 -5
  8. package/dist/examples/autoresearch/config.js +57 -23
  9. package/dist/examples/autoresearch/demo.d.ts +12 -4
  10. package/dist/examples/autoresearch/demo.js +65 -22
  11. package/dist/examples/autoresearch/eject.json +2 -0
  12. package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
  13. package/dist/examples/autoresearch/frontiercs2-config.js +14 -0
  14. package/dist/examples/autoresearch/frontiercs2.d.ts +18 -1
  15. package/dist/examples/autoresearch/frontiercs2.js +71 -14
  16. package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
  17. package/dist/examples/autoresearch/prepare-demo.js +46 -0
  18. package/dist/examples/autoresearch/prepare.d.ts +105 -53
  19. package/dist/examples/autoresearch/prepare.js +126 -57
  20. package/dist/examples/autoresearch/project.d.ts +6 -95
  21. package/dist/examples/autoresearch/project.js +131 -45
  22. package/dist/examples/autoresearch/research-service.d.ts +16 -1
  23. package/dist/examples/autoresearch/research-service.js +84 -44
  24. package/dist/examples/code/README.md +25 -17
  25. package/dist/examples/code/REQUIREMENTS.zh.md +3 -3
  26. package/dist/examples/code/config.d.ts +1 -0
  27. package/dist/examples/first-harness/AGENTS.md +25 -0
  28. package/dist/examples/first-harness/README.md +136 -0
  29. package/dist/examples/first-harness/config.d.ts +9 -8
  30. package/dist/examples/first-harness/config.js +33 -26
  31. package/dist/examples/first-harness/eject.json +14 -0
  32. package/dist/examples/first-harness/handoff.js +3 -3
  33. package/dist/examples/first-harness/harness.d.ts +14 -18
  34. package/dist/examples/first-harness/harness.js +102 -77
  35. package/dist/examples/first-harness/input/README.md +7 -0
  36. package/dist/examples/first-harness/session.js +2 -1
  37. package/dist/examples/first-harness/tsconfig.json +2 -1
  38. package/dist/examples/harness-session/README.md +4 -4
  39. package/dist/examples/lead-worker/README.md +1 -1
  40. package/dist/examples/lead-worker/project-config.d.ts +1 -0
  41. package/dist/examples/messages/README.md +2 -2
  42. package/dist/examples/notes/README.md +5 -5
  43. package/dist/examples/notes/config.d.ts +1 -0
  44. package/dist/examples/parallel-swarm/AGENTS.md +32 -0
  45. package/dist/examples/parallel-swarm/README.md +136 -0
  46. package/dist/examples/parallel-swarm/board-service.js +25 -8
  47. package/dist/examples/parallel-swarm/board.d.ts +31 -1
  48. package/dist/examples/parallel-swarm/board.js +98 -13
  49. package/dist/examples/parallel-swarm/config.d.ts +11 -0
  50. package/dist/examples/parallel-swarm/config.js +39 -0
  51. package/dist/examples/parallel-swarm/eject.json +5 -0
  52. package/dist/examples/parallel-swarm/harness.d.ts +26 -20
  53. package/dist/examples/parallel-swarm/harness.js +77 -76
  54. package/dist/examples/parallel-swarm/report.d.ts +12 -0
  55. package/dist/examples/parallel-swarm/report.js +30 -0
  56. package/dist/examples/peermesh/README.md +1 -1
  57. package/dist/examples/peermesh/project-config.d.ts +1 -0
  58. package/dist/examples/services/agent-control/README.md +1 -1
  59. package/dist/examples/services/mathlib-search/README.md +1 -1
  60. package/dist/examples/services/mcp-managed/README.md +1 -1
  61. package/dist/examples/services/persistent-board/README.md +6 -3
  62. package/dist/examples/subagents/AGENTS.md +35 -0
  63. package/dist/examples/subagents/README.md +129 -93
  64. package/dist/examples/subagents/config.d.ts +2 -10
  65. package/dist/examples/subagents/config.js +9 -16
  66. package/dist/examples/subagents/eject.json +17 -0
  67. package/dist/examples/subagents/handoff-config.d.ts +41 -0
  68. package/dist/examples/subagents/handoff-config.js +13 -0
  69. package/dist/examples/subagents/model.d.ts +3 -0
  70. package/dist/examples/subagents/model.js +19 -0
  71. package/dist/examples/substrate/README.md +12 -6
  72. package/dist/examples/substrate/config.d.ts +1 -0
  73. package/dist/examples/substrate/project-config.d.ts +1 -0
  74. package/dist/examples/super/README.md +34 -22
  75. package/dist/examples/super/actions.d.ts +1 -1
  76. package/dist/examples/super/actions.js +11 -11
  77. package/dist/examples/super/config.js +3 -3
  78. package/dist/examples/super/eject.json +1 -1
  79. package/dist/examples/super/location.js +1 -1
  80. package/dist/examples/super/operator.d.ts +1 -0
  81. package/dist/examples/super/operator.js +31 -0
  82. package/dist/examples/super/project.d.ts +0 -107
  83. package/dist/examples/super/project.js +1 -3
  84. package/dist/examples/taskpool/README.md +1 -1
  85. package/dist/examples/taskpool/config.d.ts +1 -0
  86. package/dist/examples/taskpool/deploy/service-hosts/service-authority-snapshot.d.ts +4 -4
  87. package/dist/scripts/anyswarm-arguments.d.ts +7 -25
  88. package/dist/scripts/anyswarm-arguments.js +69 -97
  89. package/dist/scripts/anyswarm-eject.js +1 -1
  90. package/dist/scripts/anyswarm-harnesses.d.ts +0 -1
  91. package/dist/scripts/anyswarm-harnesses.js +1 -22
  92. package/dist/scripts/anyswarm-installation.d.ts +7 -40
  93. package/dist/scripts/anyswarm-installation.js +17 -291
  94. package/dist/scripts/anyswarm-launch.d.ts +6 -36
  95. package/dist/scripts/anyswarm-launch.js +32 -81
  96. package/dist/scripts/anyswarm-progress.d.ts +6 -0
  97. package/dist/scripts/anyswarm-progress.js +133 -0
  98. package/dist/scripts/anyswarm-project.d.ts +1 -9
  99. package/dist/scripts/anyswarm-project.js +40 -127
  100. package/dist/scripts/anyswarm-source-runner.js +9 -41
  101. package/dist/scripts/anyswarm.js +6 -26
  102. package/dist/scripts/build-provenance.json +1 -1
  103. package/dist/scripts/generate-architecture-coverage.js +1 -1
  104. package/dist/scripts/generate-architecture-prompts.js +18 -10
  105. package/dist/scripts/local-environment.d.ts +13 -7
  106. package/dist/scripts/local-environment.js +73 -21
  107. package/dist/scripts/local-setup.d.ts +3 -0
  108. package/dist/scripts/local-setup.js +153 -118
  109. package/dist/scripts/pack-release.js +31 -4
  110. package/dist/src/core/index.js +1 -1
  111. package/dist/src/core/sandbox/opensandbox-backend.js +10 -4
  112. package/dist/src/core/sandbox/sandbox-connection.d.ts +9 -2
  113. package/dist/src/core/sandbox/sandbox-connection.js +22 -7
  114. package/dist/src/core/worker-image.js +1 -1
  115. package/dist/src/harness/project-harness.d.ts +1 -0
  116. package/dist/src/harness/project-harness.js +5 -4
  117. package/dist/src/harness/project-rpc-client.js +19 -0
  118. package/dist/src/harness/project-runtime.js +3 -1
  119. package/dist/src/harness/typescript-loader.d.ts +2 -0
  120. package/dist/src/harness/typescript-loader.js +26 -8
  121. package/dist/src/trace-viewer/command.mjs +6 -3
  122. package/dist/src/trace-viewer/public/app.js +239 -59
  123. package/dist/src/trace-viewer/public/index.html +5 -0
  124. package/dist/src/trace-viewer/public/style.css +22 -0
  125. package/dist/src/trace-viewer/reader.mjs +242 -26
  126. package/dist/src/trace-viewer/run-root.d.mts +1 -0
  127. package/dist/src/trace-viewer/run-root.mjs +7 -0
  128. package/dist/src/trace-viewer/server.mjs +3 -1
  129. package/docs/INDEX.md +11 -9
  130. package/docs/architecture/04-services.md +1 -1
  131. package/docs/architecture/06-observability-experiments.md +21 -7
  132. package/docs/architecture/07-run-configuration.md +118 -19
  133. package/docs/architecture/08-prompts.md +21 -2
  134. package/docs/architecture/10-service-api-reference.md +12 -5
  135. package/docs/architecture/12-code-coverage.md +157 -115
  136. package/docs/architecture/15-core-runtime.md +1 -1
  137. package/docs/architecture/16-pi-opensandbox-backend.md +2 -0
  138. package/docs/architecture/17-harness-reporting.md +79 -1
  139. package/docs/architecture/22-website.md +52 -20
  140. package/docs/architecture/23-project-harness.md +109 -37
  141. package/docs/architecture/26-code.md +20 -5
  142. package/docs/architecture/27-personal.md +23 -8
  143. package/docs/architecture/28-autoresearch.md +18 -12
  144. package/docs/architecture/INDEX.md +1 -2
  145. package/docs/architecture/prompts/11-first-sdk-harness.md +9 -9
  146. package/docs/architecture/prompts/16-parallel-swarm.md +46 -13
  147. package/docs/architecture/prompts/22-autoresearch.md +9 -2
  148. package/docs/architecture/prompts/source-manifest.json +76 -52
  149. package/docs/architecture/source-map.json +445 -105
  150. package/docs/designs/core-harness/01-core.md +2 -2
  151. package/docs/designs/core-harness/06-project-harness.md +3 -3
  152. package/docs/designs/core-harness/README.md +2 -2
  153. package/docs/en/agents.md +1 -1
  154. package/docs/en/autoresearch.md +41 -0
  155. package/docs/en/blog/100b-tokens.md +157 -0
  156. package/docs/en/build-your-harness.md +47 -22
  157. package/docs/en/changelog.md +29 -1
  158. package/docs/en/first-harness.md +40 -32
  159. package/docs/en/harnesses/index.md +23 -23
  160. package/docs/en/harnesses/lead-worker.md +1 -1
  161. package/docs/en/harnesses/peermesh.md +2 -2
  162. package/docs/en/harnesses/subagents.md +10 -31
  163. package/docs/en/harnesses/substrate.md +4 -4
  164. package/docs/en/harnesses/taskpool.md +2 -2
  165. package/docs/en/latest.md +30 -5
  166. package/docs/en/overview.md +22 -22
  167. package/docs/en/quickstart.md +69 -56
  168. package/docs/en/reference/api.md +1 -1
  169. package/docs/en/reference/cli.md +47 -85
  170. package/docs/en/sandbox.md +3 -3
  171. package/docs/en/trace-viewer.md +32 -12
  172. package/docs/operations/trace-viewer.md +26 -11
  173. package/docs/third-party-notices.md +0 -1
  174. package/docs/workflows/development.md +160 -118
  175. package/docs/workflows/release-and-docs-versioning.md +207 -54
  176. package/docs/workflows/release-cli-acceptance.md +162 -0
  177. package/docs/zh/agents.md +1 -1
  178. package/docs/zh/autoresearch.md +41 -0
  179. package/docs/zh/blog/100b-tokens.md +102 -0
  180. package/docs/zh/build-your-harness.md +48 -23
  181. package/docs/zh/changelog.md +29 -1
  182. package/docs/zh/first-harness.md +43 -35
  183. package/docs/zh/harnesses/index.md +23 -23
  184. package/docs/zh/harnesses/lead-worker.md +1 -1
  185. package/docs/zh/harnesses/peermesh.md +2 -2
  186. package/docs/zh/harnesses/subagents.md +10 -31
  187. package/docs/zh/harnesses/substrate.md +4 -4
  188. package/docs/zh/harnesses/taskpool.md +2 -2
  189. package/docs/zh/latest.md +30 -5
  190. package/docs/zh/overview.md +23 -23
  191. package/docs/zh/quickstart.md +66 -57
  192. package/docs/zh/reference/api.md +1 -1
  193. package/docs/zh/reference/cli.md +19 -79
  194. package/docs/zh/sandbox.md +3 -3
  195. package/docs/zh/trace-viewer.md +32 -12
  196. package/examples/README.md +138 -77
  197. package/examples/authoring/README.md +4 -4
  198. package/examples/autoresearch/README.md +108 -16
  199. package/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
  200. package/examples/autoresearch/config.ts +64 -25
  201. package/examples/autoresearch/demo.ts +75 -22
  202. package/examples/autoresearch/eject.json +2 -0
  203. package/examples/autoresearch/frontiercs2-config.ts +15 -0
  204. package/examples/autoresearch/frontiercs2.ts +64 -11
  205. package/examples/autoresearch/prepare-demo.ts +44 -0
  206. package/examples/autoresearch/prepare.ts +134 -60
  207. package/examples/autoresearch/project.ts +120 -44
  208. package/examples/autoresearch/research-service.ts +91 -41
  209. package/examples/code/README.md +25 -17
  210. package/examples/code/REQUIREMENTS.zh.md +3 -3
  211. package/examples/first-harness/AGENTS.md +25 -0
  212. package/examples/first-harness/README.md +136 -0
  213. package/examples/first-harness/config.ts +41 -27
  214. package/examples/first-harness/eject.json +14 -0
  215. package/examples/first-harness/handoff.ts +3 -3
  216. package/examples/first-harness/harness.ts +104 -72
  217. package/examples/first-harness/input/README.md +7 -0
  218. package/examples/first-harness/session.ts +2 -1
  219. package/examples/first-harness/tsconfig.json +2 -1
  220. package/examples/harness-session/README.md +4 -4
  221. package/examples/lead-worker/README.md +1 -1
  222. package/examples/messages/README.md +2 -2
  223. package/examples/notes/README.md +5 -5
  224. package/examples/parallel-swarm/AGENTS.md +32 -0
  225. package/examples/parallel-swarm/README.md +136 -0
  226. package/examples/parallel-swarm/board-service.ts +28 -9
  227. package/examples/parallel-swarm/board.ts +107 -13
  228. package/examples/parallel-swarm/config.ts +47 -0
  229. package/examples/parallel-swarm/eject.json +5 -0
  230. package/examples/parallel-swarm/harness.ts +83 -71
  231. package/examples/parallel-swarm/report.ts +33 -0
  232. package/examples/peermesh/README.md +1 -1
  233. package/examples/services/agent-control/README.md +1 -1
  234. package/examples/services/mathlib-search/README.md +1 -1
  235. package/examples/services/mcp-managed/README.md +1 -1
  236. package/examples/services/persistent-board/README.md +6 -3
  237. package/examples/subagents/AGENTS.md +35 -0
  238. package/examples/subagents/README.md +129 -93
  239. package/examples/subagents/config.ts +9 -15
  240. package/examples/subagents/eject.json +17 -0
  241. package/examples/subagents/handoff-config.ts +14 -0
  242. package/examples/subagents/model.ts +20 -0
  243. package/examples/substrate/README.md +12 -6
  244. package/examples/super/README.md +34 -22
  245. package/examples/super/actions.ts +11 -11
  246. package/examples/super/config.ts +3 -3
  247. package/examples/super/eject.json +1 -1
  248. package/examples/super/location.ts +1 -1
  249. package/examples/super/operator.ts +28 -0
  250. package/examples/super/project.ts +1 -3
  251. package/examples/taskpool/README.md +1 -1
  252. package/npm-shrinkwrap.development.json +46 -1538
  253. package/npm-shrinkwrap.json +10 -43
  254. package/package.development.json +3 -6
  255. package/package.json +3 -5
  256. package/scripts/anyswarm-arguments.ts +67 -96
  257. package/scripts/anyswarm-eject.ts +1 -1
  258. package/scripts/anyswarm-harnesses.ts +1 -18
  259. package/scripts/anyswarm-installation.ts +18 -294
  260. package/scripts/anyswarm-launch.ts +30 -102
  261. package/scripts/anyswarm-progress.ts +125 -0
  262. package/scripts/anyswarm-project.ts +31 -123
  263. package/scripts/anyswarm-source-runner.ts +9 -36
  264. package/scripts/anyswarm.ts +4 -24
  265. package/scripts/generate-architecture-coverage.ts +1 -1
  266. package/scripts/generate-architecture-prompts.ts +21 -10
  267. package/scripts/local-environment.ts +79 -21
  268. package/scripts/local-setup.ts +150 -105
  269. package/scripts/pack-release.ts +28 -4
  270. package/src/core/index.ts +1 -1
  271. package/src/core/sandbox/opensandbox-backend.ts +10 -4
  272. package/src/core/sandbox/sandbox-connection.ts +22 -7
  273. package/src/core/worker-image.ts +1 -1
  274. package/src/harness/project-harness.ts +5 -4
  275. package/src/harness/project-rpc-client.ts +23 -0
  276. package/src/harness/project-runtime.ts +2 -1
  277. package/src/harness/typescript-loader.ts +28 -8
  278. package/src/trace-viewer/command.mjs +6 -3
  279. package/src/trace-viewer/public/app.js +239 -59
  280. package/src/trace-viewer/public/index.html +5 -0
  281. package/src/trace-viewer/public/style.css +22 -0
  282. package/src/trace-viewer/reader.mjs +242 -26
  283. package/src/trace-viewer/run-root.d.mts +1 -0
  284. package/src/trace-viewer/run-root.mjs +7 -0
  285. package/src/trace-viewer/server.mjs +3 -1
  286. package/dist/scripts/anyswarm-applications.d.ts +0 -19
  287. package/dist/scripts/anyswarm-applications.js +0 -19
  288. package/dist/scripts/anyswarm-tui-config.d.ts +0 -36
  289. package/dist/scripts/anyswarm-tui-config.js +0 -189
  290. package/dist/scripts/anyswarm-tui-session.d.ts +0 -66
  291. package/dist/scripts/anyswarm-tui-session.js +0 -304
  292. package/dist/scripts/anyswarm-tui-terminal.d.ts +0 -41
  293. package/dist/scripts/anyswarm-tui-terminal.js +0 -154
  294. package/dist/scripts/anyswarm-tui.d.ts +0 -2
  295. package/dist/scripts/anyswarm-tui.js +0 -1012
  296. package/docs/architecture/25-foreground-tui.md +0 -51
  297. package/scripts/anyswarm-applications.ts +0 -39
  298. package/scripts/anyswarm-tui-config.ts +0 -174
  299. package/scripts/anyswarm-tui-session.ts +0 -295
  300. package/scripts/anyswarm-tui-terminal.ts +0 -147
  301. package/scripts/anyswarm-tui.ts +0 -912
@@ -0,0 +1,32 @@
1
+ # Editing this Parallel Swarm Harness
2
+
3
+ These instructions are for a Coding Agent customizing the exported application.
4
+ Read `README.md`, then the actual collaboration in `harness.ts`, configuration
5
+ in `config.ts`, and the Board and report checks before changing behavior.
6
+
7
+ - Import SDK capabilities from `@anyswarm/core`. Use the installed public types;
8
+ do not depend on the AnySwarm repository's internal source or sibling examples.
9
+ - Keep the collaboration policy visible in ordinary TypeScript. One Harness
10
+ creates one Runtime with researcher and synthesizer Profiles; the CLI/SDK/RPC
11
+ clients use that same default Harness export.
12
+ - Read the user's repository from `context.initial.files` and their question
13
+ from `context.input.prompt`. Preserve snapshot identity and independent Agent
14
+ directories. Export results instead of modifying the user's original files.
15
+ - Honor `context.configuration`. Keep credentials in environment variables or
16
+ the user's private config, and preserve the selected executor and connection.
17
+ - Let the host assign author IDs and rounds. Keep Service permissions, exact
18
+ source checks and cross-author review checks when adapting the Board.
19
+ - Use `context.runWithRuntime` and `runInput` for owned work. Preserve cancellation,
20
+ finite waits, raw export/cleanup receipts and pending resources. A failed
21
+ business check is not a cleanup exception.
22
+ - State exactly what acceptance checks establish. Model text, file existence
23
+ and valid citations do not establish semantic correctness. Add a task-specific
24
+ checker only when the user has specified its actual acceptance rule.
25
+ - Verify changed behavior with focused deterministic checks and review the
26
+ resulting report. Use live model calls only within the user's authorized
27
+ endpoint, model and budget; identify any unrun integration checks honestly.
28
+
29
+ Run the edited source with `npm start -- --cwd /absolute/path/to/project
30
+ --prompt 'your question' --output-dir /absolute/path/to/runs`. The ejected
31
+ `package.json` pins the SDK archive recorded in `anyswarm-source.json`; changing
32
+ the application does not require a new AnySwarm framework or private API.
@@ -0,0 +1,136 @@
1
+ # Parallel repository investigation
2
+
3
+ Ask a concrete question about a local repository and export an engineering
4
+ handoff or change-impact report. Three researchers inspect private copies of the
5
+ same captured input, publish source references to an in-process Board, and review
6
+ one another's findings. A fourth Agent integrates their work into `report.md`.
7
+
8
+ The complete collaboration policy is in `harness.ts`. The example uses public
9
+ `@anyswarm/core` APIs, one Runtime, and the same Harness definition for the CLI,
10
+ SDK and JSONL RPC. It has no mid-run questions or external business Services.
11
+
12
+ ## Run your own repository question
13
+
14
+ Use AnySwarm 0.6.0 or a matching source build to export this example.
15
+ Prepare its Worker and OpenSandbox connection with `anyswarm setup`. You also
16
+ need a model endpoint reachable from the host and credentials for that endpoint;
17
+ setup's Sandbox selection does not configure your model account.
18
+
19
+ ```sh
20
+ anyswarm eject parallel-swarm --dir ./my-swarm
21
+ cd ./my-swarm
22
+ npm install
23
+
24
+ export ANYSWARM_MODEL_URL='https://your-provider.example/v1/responses'
25
+ export ANYSWARM_MODEL_ID='your-model'
26
+ # If required by your provider, set ANYSWARM_MODEL_TOKEN in your environment.
27
+
28
+ npm start -- \
29
+ --cwd /absolute/path/to/your-project \
30
+ --prompt 'Prepare an engineering handoff for this repository: identify the relevant entry points, configuration, main data flow and existing tests. Cite source paths and line numbers. Separate established facts from inferences and checks still needed.' \
31
+ --output-dir /absolute/path/to/runs
32
+ ```
33
+
34
+ Replace the question with your actual concern, for example: “We plan to change
35
+ how configuration is loaded; which modules and existing tests are involved, and
36
+ what still needs to be checked?” No Git diff or known repository defect is needed.
37
+ From this source directory the equivalent entry is
38
+ `anyswarm run ./harness.ts --cwd /absolute/path/to/your-project --prompt '…'`.
39
+ The exported package's `npm start` runs that same editable source.
40
+
41
+ Use `anyswarm trace --root /absolute/path/to/runs --open` to inspect the Run.
42
+ The final result's `artifacts` entry with `kind: "report"` names the actual
43
+ Markdown file. `result.detail.board` contains the findings, authenticated author
44
+ IDs, rounds, citations and checked source excerpts. The Runtime also exports the
45
+ Board's Service state. The original close receipt remains in `cleanup.receipt`.
46
+
47
+ Each Agent receives the captured project files selected by the SDK's file policy.
48
+ The host does not copy changes back to your repository. Researchers cannot write
49
+ their copies. The synthesizer can write its private copy and only `report.md` is
50
+ requested for collection. Changes made to your local project after input capture
51
+ are not part of this Run.
52
+
53
+ ## Configuration and budgets
54
+
55
+ `harness.ts` uses `context.configuration` when supplied, including a CLI
56
+ `--config ./my-config.ts` module. That object is the complete configuration;
57
+ otherwise the Harness loads its own visible `config.ts`. It does not depend on a
58
+ configuration file from another example.
59
+
60
+ The default configuration resolves the saved setup connection and executor for
61
+ the selected endpoint. Common `ANYSWARM_*` model/executor variables override
62
+ `ANYSWARM_PARALLEL_SWARM_*` variables; the saved executor is the next fallback,
63
+ then Pi. Worker image and Sandbox connection overrides use the SDK's
64
+ `resolveSandboxConnection({}, 'PARALLEL_SWARM')` rules. A configured or saved
65
+ image is preserved; otherwise `workerImageFor(executor)` selects it.
66
+
67
+ | Setting | Default behavior |
68
+ | --- | --- |
69
+ | `ANYSWARM_MODEL_URL` | Required model endpoint; scoped fallback is `ANYSWARM_PARALLEL_SWARM_MODEL_URL`. |
70
+ | `ANYSWARM_MODEL_ID`, `ANYSWARM_MODEL_PROVIDER` | Pi defaults to `gpt-5-mini` / `openai`; choose a model your provider supports. Codex requires an explicit model ID. |
71
+ | `ANYSWARM_MODEL_TOKEN` | Optional bearer token; keep it in the environment. |
72
+ | `ANYSWARM_EXECUTOR` | `pi` or `codex`; otherwise inherit setup's executor. |
73
+ | `ANYSWARM_MODEL_PROTOCOL` | `responses`; Pi also accepts `chat-completions`. Codex requires Responses. |
74
+ | `ANYSWARM_CONTEXT_WINDOW` | Optional explicit model context limit, at least 2,048 tokens. |
75
+ | `model`, `models` in a config module | Select a model alias and its complete public SDK model configuration. |
76
+ | `turnTimeoutMs`, `closeTimeoutMs` | 120 seconds for each owned Agent input and 60 seconds for close/reconciliation. All waits must be finite positive integers. |
77
+
78
+ When `ANYSWARM_CONTEXT_WINDOW` supplies capabilities for a custom model, the
79
+ default profile declares `reasoning: false`. If your Responses endpoint returns
80
+ reasoning items, set `models.default.capabilities.reasoning` to `true` in the
81
+ exported `config.ts` or in the full configuration you pass with `--config`.
82
+ Keep the context window and output limit appropriate for the selected model.
83
+ Otherwise the gateway can return `unsupported_responses_request` when the
84
+ executor includes a reasoning item in a subsequent request.
85
+
86
+ The example retains three researchers, two rounds, one synthesizer and a maximum
87
+ of four live Agents. Pi's default output cap is 2,048 tokens per model response;
88
+ Codex preserves executor output parameters. These bounds are configuration,
89
+ not a runtime or cost promise. Adjust the visible config to suit the question
90
+ and your authorized provider budget.
91
+
92
+ ## What the host checks
93
+
94
+ 1. Each of the three researchers publishes at least one first-round finding.
95
+ 2. Every finding includes 1–8 source references. Each reference has a relative
96
+ `path`, 1-based `startLine` / `endLine`, and exact `excerpt` from the captured
97
+ input. Ranges contain 1–40 lines, excerpts are nonblank and at most 4,096 bytes,
98
+ and the final line separator is omitted. CRLF is normalized to LF for checking.
99
+ 3. Each researcher publishes a new second-round review citing a first-round
100
+ finding by another author. The host assigns the round; clients cannot submit
101
+ an author or round override. Unknown citations and self-only reviews fail.
102
+ 4. The synthesizer's required `report.md` is exported, readable as UTF-8 and
103
+ nonblank, within the 1 MiB collection limit. If the input already contained
104
+ `report.md`, an unchanged copy does not pass this export check.
105
+
106
+ `acceptance.status: "verified"` applies only to the listed collaboration and
107
+ export checks; `acceptance.semanticCorrectness` remains `"not-run"`. Source
108
+ locations matching the input do not prove that an excerpt supports a conclusion,
109
+ that reviews are useful, or that a report is complete. The host does not execute
110
+ project tests or validate Markdown citations against the Board. Read the report
111
+ and its evidence before using its recommendations.
112
+
113
+ Incomplete contributions stop the workflow before synthesis. Invalid evidence
114
+ is rejected by the Board without publication. A confirmed bad report is a
115
+ business verification failure, separate from resource cleanup. Unconfirmed
116
+ collection stays `export.status: "pending"` and retains the SDK receipt; it is
117
+ not reported as a confirmed missing file. Cleanup can remain pending even when
118
+ the report has already been exported and checked. Cancellation and Runtime
119
+ initialization errors retain the existing Harness result classification.
120
+
121
+ ## Source and validation
122
+
123
+ | File | What to change |
124
+ | --- | --- |
125
+ | `harness.ts` | Research focus, prompts, rounds, Profiles, input handling and completion checks. |
126
+ | `config.ts` | Connections, executor/model selection, time limits and file policy. |
127
+ | `board.ts` | Source evidence checks, contribution accounting and review rules. |
128
+ | `board-service.ts` | Public Service schemas and authenticated caller mapping. |
129
+ | `report.ts` | Export verification, independently of close/cleanup classification. |
130
+ | `AGENTS.md` | Guidance for a Coding Agent editing this exported Harness. |
131
+
132
+ Repository tests exercise the Board and report failure cases, and run the real
133
+ HarnessSession/Runtime/Service Bridge with a controlled local transport. They
134
+ establish contract behavior, not model quality or compatibility with a particular
135
+ live model. A new paid model or Docker-based run is not implied by these tests;
136
+ record real-run evidence separately with its SDK, model, input and limitations.
@@ -4,18 +4,34 @@ import {
4
4
  type ServiceRegistration,
5
5
  serviceFromManifest,
6
6
  } from '@anyswarm/core';
7
- import { FindingsBoard } from './board.js';
7
+ import { FindingsBoard, type SourceReference } from './board.js';
8
+
9
+ const EVIDENCE_SCHEMA = {
10
+ type: 'array', minItems: 1, maxItems: 8,
11
+ items: {
12
+ type: 'object',
13
+ properties: {
14
+ path: { type: 'string', minLength: 1 },
15
+ startLine: { type: 'integer', minimum: 1 },
16
+ endLine: { type: 'integer', minimum: 1 },
17
+ excerpt: { type: 'string', minLength: 1, maxLength: 4096 },
18
+ },
19
+ required: ['path', 'startLine', 'endLine', 'excerpt'], additionalProperties: false,
20
+ },
21
+ } as const;
8
22
 
9
23
  const FINDING_SCHEMA = {
10
24
  type: 'object',
11
25
  properties: {
12
26
  id: { type: 'integer' },
13
27
  authorId: { type: 'string' },
28
+ round: { type: 'string', enum: ['research', 'review'] },
14
29
  topic: { type: 'string' },
15
30
  summary: { type: 'string' },
31
+ evidence: EVIDENCE_SCHEMA,
16
32
  cites: { type: 'array', items: { type: 'integer' } },
17
33
  },
18
- required: ['id', 'authorId', 'topic', 'summary', 'cites'],
34
+ required: ['id', 'authorId', 'round', 'topic', 'summary', 'evidence', 'cites'],
19
35
  additionalProperties: false,
20
36
  } as const;
21
37
 
@@ -26,25 +42,27 @@ export function createBoardRegistration(board: FindingsBoard): ServiceRegistrati
26
42
  id: 'board',
27
43
  title: 'Shared Research Board',
28
44
  purpose: 'Publish, search, and cite findings across parallel swarm researchers.',
29
- provider_version: '1.0.0',
45
+ provider_version: '2.0.0',
30
46
  endpoint: { transport: 'in-process' },
31
47
  capabilities: [
32
48
  {
33
49
  name: 'publish',
34
50
  operation: 'publish',
35
- description: 'Publish a verified finding and optionally cite prior finding IDs.',
51
+ description: 'Publish a finding with exact source references. During review, cite another researcher\'s first-round finding. Source locations are checked; conclusions are not.',
36
52
  side_effect: 'write',
37
53
  idempotent: false,
38
54
  help: { when: 'After discovering or cross-checking a concrete fact' },
39
- errors: [{ code: 'NOT_FOUND', retryable: false }],
55
+ errors: ['NOT_FOUND', 'INVALID_EVIDENCE', 'INVALID_FINDING', 'REVIEW_REQUIRED', 'BOARD_CLOSED', 'NOT_RESEARCHER']
56
+ .map(code => ({ code, retryable: false })),
40
57
  input_schema: {
41
58
  type: 'object',
42
59
  properties: {
43
60
  topic: { type: 'string', minLength: 1, maxLength: 120 },
44
61
  summary: { type: 'string', minLength: 1, maxLength: 2000 },
45
- cites: { type: 'array', items: { type: 'integer', minimum: 1 }, maxItems: 8 },
62
+ evidence: EVIDENCE_SCHEMA,
63
+ cites: { type: 'array', items: { type: 'integer', minimum: 1 }, maxItems: 8, uniqueItems: true },
46
64
  },
47
- required: ['topic', 'summary'],
65
+ required: ['topic', 'summary', 'evidence'],
48
66
  additionalProperties: false,
49
67
  },
50
68
  output_schema: FINDING_SCHEMA,
@@ -75,12 +93,13 @@ export function createBoardRegistration(board: FindingsBoard): ServiceRegistrati
75
93
  invoke({ capability, input, caller, assertAuthorized }): JsonValue {
76
94
  if (capability.operation === 'publish') {
77
95
  assertAuthorized();
78
- const { topic, summary, cites } = input as {
96
+ const { topic, summary, evidence, cites } = input as unknown as {
79
97
  topic: string;
80
98
  summary: string;
99
+ evidence: SourceReference[];
81
100
  cites?: number[];
82
101
  };
83
- return board.publish(caller.agentId, topic, summary, cites) as unknown as JsonValue;
102
+ return board.publish(caller.agentId, topic, summary, evidence, cites) as unknown as JsonValue;
84
103
  }
85
104
  const { query } = input as { query?: string };
86
105
  return { entries: board.search(query) } as unknown as JsonValue;
@@ -1,35 +1,129 @@
1
+ import type { FileTree } from '@anyswarm/core';
2
+
3
+ export interface SourceReference {
4
+ path: string;
5
+ startLine: number;
6
+ endLine: number;
7
+ excerpt: string;
8
+ }
9
+
1
10
  export interface Finding {
2
11
  id: number;
3
12
  authorId: string;
13
+ round: 'research' | 'review';
4
14
  topic: string;
5
15
  summary: string;
16
+ evidence: SourceReference[];
6
17
  cites: number[];
7
18
  }
8
19
 
20
+ function reject(code: string, message: string): never {
21
+ throw Object.assign(new Error(message), { code });
22
+ }
23
+
24
+ /** Checks locations and exact excerpts, not whether they support a conclusion. */
25
+ export function verifySourceReference(files: FileTree, reference: SourceReference): SourceReference {
26
+ const { path, startLine, endLine, excerpt } = reference;
27
+ if (typeof path !== 'string' || !path || /[\\\0]/.test(path) || /^[A-Za-z]:/.test(path) ||
28
+ path.split('/').some(part => !part || part === '.' || part === '..') || !Object.hasOwn(files, path)) {
29
+ reject('INVALID_EVIDENCE', 'Evidence must name a relative file in this Run\'s input snapshot');
30
+ }
31
+ if (!Number.isSafeInteger(startLine) || !Number.isSafeInteger(endLine) || startLine < 1 || endLine < startLine ||
32
+ endLine - startLine >= 40 || typeof excerpt !== 'string' || !excerpt.trim() || Buffer.byteLength(excerpt) > 4096) {
33
+ reject('INVALID_EVIDENCE', 'Evidence requires 1–40 source lines and an exact, nonblank excerpt of at most 4096 bytes');
34
+ }
35
+ const entry = files[path];
36
+ let text: string;
37
+ try {
38
+ const bytes = Buffer.from(entry.data, entry.encoding === 'base64' ? 'base64' : 'utf8');
39
+ text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes).replaceAll('\r\n', '\n');
40
+ } catch {
41
+ reject('INVALID_EVIDENCE', 'Evidence must refer to a UTF-8 source file');
42
+ }
43
+ const lines = text.split('\n');
44
+ if (lines.at(-1) === '') lines.pop();
45
+ const normalized = excerpt.replaceAll('\r\n', '\n');
46
+ if (endLine > lines.length || normalized !== lines.slice(startLine - 1, endLine).join('\n')) {
47
+ reject('INVALID_EVIDENCE', 'The line range and excerpt do not match the captured source');
48
+ }
49
+ return { path, startLine, endLine, excerpt: normalized };
50
+ }
51
+
9
52
  export class FindingsBoard {
10
53
  private entries: Finding[] = [];
54
+ private researchers: string[] = [];
55
+ private round: 'waiting' | 'research' | 'review' | 'closed' = 'waiting';
56
+
57
+ constructor(private readonly files: FileTree) {}
58
+
59
+ beginResearch(researchers: readonly string[]) {
60
+ if (this.round !== 'waiting' || researchers.length < 2 || new Set(researchers).size !== researchers.length ||
61
+ researchers.some(id => typeof id !== 'string' || !id)) {
62
+ reject('INVALID_ROUND', 'Start one research round with distinct researcher identities');
63
+ }
64
+ this.researchers = [...researchers];
65
+ this.round = 'research';
66
+ }
67
+
68
+ beginReview() {
69
+ if (this.round !== 'research') reject('INVALID_ROUND', 'The review round must follow research');
70
+ this.requireContributions('research');
71
+ this.round = 'review';
72
+ }
11
73
 
12
- publish(authorId: string, topic: string, summary: string, cites: number[] = []): Finding {
13
- for (const refId of cites) {
14
- if (!this.entries.some((e) => e.id === refId)) {
15
- throw Object.assign(new Error(`Referenced finding #${refId} does not exist`), {
16
- code: 'NOT_FOUND',
17
- });
18
- }
74
+ finishReview() {
75
+ if (this.round !== 'review') reject('INVALID_ROUND', 'Finish the review round before synthesis');
76
+ this.requireContributions('review');
77
+ this.round = 'closed';
78
+ }
79
+
80
+ private requireContributions(round: 'research' | 'review') {
81
+ const missing = this.researchers.filter(id => !this.entries.some(entry => entry.authorId === id && entry.round === round));
82
+ if (missing.length) reject(round === 'research' ? 'RESEARCH_INCOMPLETE' : 'REVIEW_INCOMPLETE',
83
+ `Missing ${round} contribution from ${missing.join(', ')}`);
84
+ }
85
+
86
+ publish(authorId: string, topic: string, summary: string, evidence: readonly SourceReference[], cites: readonly number[] = []): Finding {
87
+ if (this.round !== 'research' && this.round !== 'review') reject('BOARD_CLOSED', 'The Board is not accepting publications');
88
+ if (!this.researchers.includes(authorId)) reject('NOT_RESEARCHER', 'Only this Run\'s researchers may publish');
89
+ if (typeof topic !== 'string' || !topic.trim() || topic.length > 120 ||
90
+ typeof summary !== 'string' || !summary.trim() || summary.length > 2000) {
91
+ reject('INVALID_FINDING', 'Provide a topic and a concise summary');
92
+ }
93
+ if (!Array.isArray(evidence) || evidence.length < 1 || evidence.length > 8) {
94
+ reject('INVALID_EVIDENCE', 'Each finding needs 1–8 source references');
95
+ }
96
+ const checked = evidence.map(reference => verifySourceReference(this.files, reference));
97
+ if (!Array.isArray(cites) || cites.length > 8 || new Set(cites).size !== cites.length) {
98
+ reject('NOT_FOUND', 'Citations must name at most eight distinct existing findings');
19
99
  }
20
- const entry: Finding = { id: this.entries.length + 1, authorId, topic, summary, cites };
100
+ const cited = cites.map(id => {
101
+ const entry = this.entries.find(entry => entry.id === id);
102
+ if (!entry) reject('NOT_FOUND', `Referenced finding #${id} does not exist`);
103
+ return entry;
104
+ });
105
+ if (this.round === 'review' && !cited.some(entry => entry.authorId !== authorId && entry.round === 'research')) {
106
+ reject('REVIEW_REQUIRED', 'A review must cite another researcher\'s first-round finding');
107
+ }
108
+ const entry: Finding = { id: this.entries.length + 1, authorId, round: this.round, topic, summary,
109
+ evidence: checked, cites: [...cites] };
21
110
  this.entries.push(entry);
22
- return entry;
111
+ return structuredClone(entry);
23
112
  }
24
113
 
25
114
  search(query = ''): Finding[] {
26
115
  const q = query.trim().toLowerCase();
27
- return q
28
- ? this.entries.filter((e) => `${e.topic} ${e.summary}`.toLowerCase().includes(q))
29
- : [...this.entries];
116
+ return structuredClone(q ? this.entries.filter(entry => `${entry.topic} ${entry.summary}`.toLowerCase().includes(q)) : this.entries);
117
+ }
118
+
119
+ contributions() {
120
+ return this.researchers.map(authorId => ({ authorId,
121
+ research: this.entries.filter(entry => entry.authorId === authorId && entry.round === 'research').length,
122
+ review: this.entries.filter(entry => entry.authorId === authorId && entry.round === 'review').length,
123
+ }));
30
124
  }
31
125
 
32
126
  exportState() {
33
- return { total: this.entries.length, entries: this.entries };
127
+ return { round: this.round, total: this.entries.length, contributions: this.contributions(), entries: this.search() };
34
128
  }
35
129
  }
@@ -0,0 +1,47 @@
1
+ import { ProjectPreflightError, resolveSandboxConnection, workerImageFor,
2
+ type CreateRuntimeOptions, type SandboxConfig } from '@anyswarm/core';
3
+
4
+ export interface ParallelSwarmConfig extends Pick<CreateRuntimeOptions, 'executor' | 'connection' | 'models' | 'filePolicy'> {
5
+ sandbox: SandboxConfig;
6
+ image: string;
7
+ model?: string;
8
+ turnTimeoutMs?: number;
9
+ closeTimeoutMs?: number;
10
+ }
11
+
12
+ function invalid(message: string): never {
13
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', message);
14
+ }
15
+
16
+ export function parallelSwarmConfig(): ParallelSwarmConfig {
17
+ const env = process.env;
18
+ const setting = (key: string) => env[`ANYSWARM_${key}`] ?? env[`ANYSWARM_PARALLEL_SWARM_${key}`];
19
+ const { image, advertiseHost, publicUrl, endpointSource: _source, executor: setupExecutor, ...sandbox } =
20
+ resolveSandboxConnection({}, 'PARALLEL_SWARM');
21
+ const executor = setting('EXECUTOR') ?? setupExecutor ?? 'pi';
22
+ if (executor !== 'pi' && executor !== 'codex') invalid('Select pi or codex with ANYSWARM_EXECUTOR.');
23
+ const url = setting('MODEL_URL');
24
+ if (!url) invalid('Set ANYSWARM_MODEL_URL to your model endpoint before running Parallel Swarm.');
25
+ const protocol = setting('MODEL_PROTOCOL') ?? 'responses';
26
+ if (protocol !== 'responses' && protocol !== 'chat-completions') invalid('Select responses or chat-completions with ANYSWARM_MODEL_PROTOCOL.');
27
+ if (executor === 'codex' && protocol !== 'responses') invalid('The Codex executor requires a Responses model endpoint.');
28
+ const model = setting('MODEL_ID') ?? (executor === 'pi' ? 'gpt-5-mini' : undefined);
29
+ if (!model) invalid('Set ANYSWARM_MODEL_ID to a model supported by the selected Codex executor.');
30
+ const token = setting('MODEL_TOKEN');
31
+ const contextWindow = setting('CONTEXT_WINDOW') === undefined ? undefined : Number(setting('CONTEXT_WINDOW'));
32
+ if (contextWindow !== undefined && (!Number.isSafeInteger(contextWindow) || contextWindow < 2048)) {
33
+ invalid('ANYSWARM_CONTEXT_WINDOW must be the model context limit, at least 2048 tokens.');
34
+ }
35
+ return {
36
+ sandbox, executor, image: image ?? workerImageFor(executor), model: 'default',
37
+ turnTimeoutMs: 120_000, closeTimeoutMs: 60_000,
38
+ connection: { advertiseHost, publicUrl, modelGateway: { maxOutputTokens: executor === 'codex' ? null : 2048 } },
39
+ models: { default: {
40
+ provider: setting('MODEL_PROVIDER') ?? 'openai', model, protocol,
41
+ ...(contextWindow ? { capabilities: { contextWindow, maxOutputTokens: 2048, tools: true, reasoning: false } } : {}),
42
+ upstream: { url, headers: token ? { authorization: `Bearer ${token}` } : {} },
43
+ } },
44
+ };
45
+ }
46
+
47
+ export default parallelSwarmConfig();
@@ -0,0 +1,5 @@
1
+ {
2
+ "apiVersion": 1,
3
+ "entry": "harness.ts",
4
+ "files": ["harness.ts", "config.ts", "board.ts", "board-service.ts", "report.ts", "README.md", "AGENTS.md"]
5
+ }
@@ -1,89 +1,101 @@
1
- import { createHash } from 'node:crypto';
2
- import { readFile } from 'node:fs/promises';
3
- import { join } from 'node:path';
4
1
  import {
5
- createRuntime, createSandbox, resolveSandboxConnection, runInput, ServiceRegistry,
6
- workerImageFor, type Harness,
2
+ createRuntime, createSandbox, projectConfiguration, ProjectPreflightError, runInput, ServiceRegistry,
3
+ type Harness,
7
4
  } from '@anyswarm/core';
8
5
  import { FindingsBoard } from './board.js';
9
6
  import { boardService } from './board-service.js';
7
+ import type { ParallelSwarmConfig } from './config.js';
8
+ import { checkReportExport, type ReportCheck } from './report.js';
10
9
 
11
- const researcherPrompt = 'Inspect the workspace. Publish concrete findings with swarm service invoke board publish. Read peer findings with swarm service invoke board search.';
12
- const synthesizerPrompt = 'Use swarm service invoke board search to read the findings and citations. Write a concise report.md in your workspace.';
13
- const reviewInput = 'Read the other researchers’ findings and publish a follow-up addressing a gap or disagreement. Cite the entries you relied on.';
14
- const synthesisInput = 'Summarize the board findings and citations in report.md.';
10
+ const researcherPrompt = 'Investigate the user\'s question in the captured local repository. Publish concrete findings with swarm service invoke board publish. Each finding needs evidence: relative path, 1-based startLine/endLine, and an exact short excerpt (1–40 lines, at most 4096 bytes; omit the final newline). Distinguish facts, inferences and unverified questions in the summary. Do not modify source files or invent a defect. Read peer findings with swarm service invoke board search.';
11
+ const synthesizerPrompt = 'Use swarm service invoke board search to read the research and reviews. Answer the user\'s question in report.md: give conclusions, relative source paths and line numbers, finding IDs, disagreements and unverified items. Separate facts from inference. The host checks the Board\'s source locations and the report export; it does not establish that your conclusions are correct. Do not modify other project files.';
12
+ const researchFocuses = ['Entry points, configuration and how to run the relevant behavior.', 'Core modules, data flow and dependencies relevant to the question.', 'Existing tests, observable guarantees and checks still needed.'];
13
+ const reviewInput = 'Read the other researchers\' first-round findings. Check their source evidence and publish at least one NEW follow-up addressing a gap, disagreement or corroboration relevant to the user\'s question. Include your own exact source evidence and cite at least one first-round finding by ANOTHER author in cites. A first-round publication does not count as this review.';
14
+ const synthesisInput = 'Read the Board, integrate the research and cross-author reviews, and write report.md for the task below. Cite source paths, line numbers and finding IDs; mark anything not verified.';
15
15
 
16
16
  const parallelSwarm = {
17
17
  id: 'parallel-swarm', apiVersion: 1,
18
18
  async run(context) {
19
- const url = process.env.ANYSWARM_MODEL_URL;
20
- if (!url) throw new Error('Set ANYSWARM_MODEL_URL to a streaming Responses endpoint before running.');
21
- const board = new FindingsBoard();
19
+ const config = await projectConfiguration<ParallelSwarmConfig>(context, () => import('./config.js'));
20
+ const { image, model = 'default', turnTimeoutMs = 120_000, closeTimeoutMs = 60_000 } = config;
21
+ if (!image || ![turnTimeoutMs, closeTimeoutMs].every(ms => Number.isSafeInteger(ms) && ms > 0 && ms <= 2_147_483_647)) {
22
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Parallel Swarm needs an image and finite positive turn/close time limits.');
23
+ }
24
+ const board = new FindingsBoard(context.initial.files);
22
25
  const services = new ServiceRegistry();
23
26
  services.register('board', boardService(board), { toolMode: 'cli' });
24
- const { image: configuredImage, advertiseHost, publicUrl, executor: setupExecutor, endpointSource: _source, ...sandbox } = resolveSandboxConnection();
25
- const executor = process.env.ANYSWARM_EXECUTOR ?? setupExecutor ?? 'pi';
26
- if (executor !== undefined && executor !== 'pi' && executor !== 'codex') throw new Error('Select pi or codex with ANYSWARM_EXECUTOR.');
27
- const image = configuredImage ?? workerImageFor(executor);
28
- const token = process.env.ANYSWARM_MODEL_TOKEN;
29
- const runtime = await createRuntime({
30
- sandbox: createSandbox(sandbox), connection: { advertiseHost, publicUrl }, executor, services, maxAgents: 4, outputDir: context.outputDir,
31
- models: { default: {
32
- provider: process.env.ANYSWARM_MODEL_PROVIDER ?? 'openai',
33
- model: process.env.ANYSWARM_MODEL_ID ?? 'gpt-5-mini',
34
- upstream: { url, headers: token ? { authorization: `Bearer ${token}` } : {} },
35
- } },
36
- profiles: {
37
- researcher: { addedSystemPrompt: researcherPrompt, model: 'default', image, writable: false,
38
- services: { board: ['publish', 'search'] } },
39
- synthesizer: { addedSystemPrompt: synthesizerPrompt, model: 'default', image, writable: true,
40
- services: { board: ['search'] },
41
- collect: { paths: ['report.md'], includeGit: false, maxBytes: 1_048_576, required: true } },
42
- },
43
- });
44
- const turn = { signal: context.signal, timeoutMs: 120_000 };
45
- let synthId: string | undefined;
46
- let failure: string | undefined;
47
- let cleanup: Awaited<ReturnType<typeof runtime.close>> | undefined;
48
27
  let unobserve: (() => void) | undefined;
28
+ let synthId: string | undefined;
29
+ let researchChecked = false;
30
+ let reviewChecked = false;
31
+ const checks: { report: ReportCheck; finalized?: ReportCheck } = {
32
+ report: { status: 'not-run', reason: 'SYNTHESIZER_NOT_STARTED' },
33
+ };
49
34
  try {
50
- unobserve = context.registerAgentControls({ runtime });
51
- context.markRunning();
52
- const peers = await Promise.all([1, 2, 3].map(index =>
53
- runtime.spawn({ requestId: `spawn-r${index}`, profile: 'researcher', files: context.initial.files })));
54
- await Promise.all(peers.map((peer, index) =>
55
- runInput(runtime, peer.id, context.input.prompt, { ...turn, requestId: `research-${index + 1}` })));
56
- const firstRound = board.search().length;
57
- if (firstRound === 0) throw new Error('The first round published no findings.');
58
- await Promise.all(peers.map((peer, index) =>
59
- runInput(runtime, peer.id, reviewInput, { ...turn, requestId: `review-${index + 1}` })));
60
- if (board.search().length <= firstRound) throw new Error('The review round published no follow-up findings.');
61
- await Promise.all(peers.map(peer => runtime.stop(peer.id)));
62
- const synth = await runtime.spawn({ requestId: 'spawn-synthesizer', profile: 'synthesizer', files: context.initial.files });
63
- synthId = synth.id;
64
- await runInput(runtime, synth.id, synthesisInput, { ...turn, requestId: 'synthesize' });
65
- } catch (error) {
66
- failure = (error as { code?: string }).code ?? 'SWARM_FAILED';
35
+ const result = await context.runWithRuntime({
36
+ closeTimeoutMs,
37
+ createRuntime: () => createRuntime({
38
+ sandbox: createSandbox(config.sandbox), connection: config.connection, executor: config.executor,
39
+ models: config.models, filePolicy: config.filePolicy, services, maxAgents: 4, outputDir: context.outputDir,
40
+ profiles: {
41
+ researcher: { addedSystemPrompt: researcherPrompt, model, image, writable: false,
42
+ services: { board: ['publish', 'search'] } },
43
+ synthesizer: { addedSystemPrompt: synthesizerPrompt, model, image, writable: true,
44
+ services: { board: ['search'] },
45
+ collect: { paths: ['report.md'], includeGit: false, maxBytes: 1_048_576, required: true } },
46
+ },
47
+ }),
48
+ async run(runtime) {
49
+ unobserve = context.registerAgentControls({ runtime });
50
+ context.markRunning();
51
+ const turn = { signal: context.signal, timeoutMs: turnTimeoutMs };
52
+ context.signal.throwIfAborted();
53
+ const peers = await Promise.all(researchFocuses.map((_, index) =>
54
+ runtime.spawn({ requestId: `spawn-r${index + 1}`, profile: 'researcher', files: context.initial.files })));
55
+ board.beginResearch(peers.map(peer => peer.id));
56
+ await Promise.all(peers.map((peer, index) => runInput(runtime, peer.id,
57
+ `${context.input.prompt}\n\nYour focus: ${researchFocuses[index]}\nPublish at least one source-backed finding.`,
58
+ { ...turn, requestId: `research-${index + 1}` })));
59
+ board.beginReview();
60
+ researchChecked = true;
61
+ await Promise.all(peers.map((peer, index) => runInput(runtime, peer.id, reviewInput,
62
+ { ...turn, requestId: `review-${index + 1}` })));
63
+ board.finishReview();
64
+ reviewChecked = true;
65
+ await Promise.all(peers.map(peer => runtime.stop(peer.id, { timeoutMs: closeTimeoutMs })));
66
+ context.signal.throwIfAborted();
67
+ const synth = await runtime.spawn({ requestId: 'spawn-synthesizer', profile: 'synthesizer', files: context.initial.files });
68
+ synthId = synth.id;
69
+ checks.report = { status: 'pending', reason: 'REPORT_EXPORT_PENDING' };
70
+ await runInput(runtime, synth.id, `${synthesisInput}\n\n${context.input.prompt}`, { ...turn, requestId: 'synthesize' });
71
+ return { synthesizerId: synthId, contributions: board.contributions() };
72
+ },
73
+ // A failed report check is business evidence, not a thrown cleanup error.
74
+ afterClose: async receipt => { checks.report = await checkReportExport(receipt, synthId, context.initial.files); },
75
+ detail: () => {
76
+ // Keep the final projection stable if a post-close read outlives its wait.
77
+ checks.finalized = { ...checks.report };
78
+ return { board: board.exportState(), report: checks.finalized };
79
+ },
80
+ });
81
+ const report = checks.finalized!;
82
+ const reportFailed = report.status === 'unverified';
83
+ return {
84
+ ...result,
85
+ ...(result.outcome === 'completed' && reportFailed ? { outcome: 'failed' as const, reason: report.reason } : {}),
86
+ acceptance: {
87
+ status: researchChecked && reviewChecked && report.status === 'verified' ? 'verified' : report.status === 'pending' ? 'pending' : 'unverified',
88
+ scope: 'participant-contributions, cross-author-reviews, Board-source-references, report-export',
89
+ research: researchChecked ? 'verified' : 'unverified', review: reviewChecked ? 'verified' : 'unverified',
90
+ sourceReferences: board.search().length ? 'verified' : 'not-run', report: { ...report }, semanticCorrectness: 'not-run',
91
+ },
92
+ artifacts: [...result.artifacts, ...(report.status === 'verified' ? [{ agentId: synthId!, kind: 'report', ...report }] : [])],
93
+ ...(synthId ? { export: { ...result.export, status: result.export?.status === 'pending' || report.status === 'pending'
94
+ ? 'pending' as const : report.status === 'verified' ? 'complete' as const : 'failed' as const } } : {}),
95
+ };
67
96
  } finally {
68
- try { cleanup = await runtime.close({ timeoutMs: 60_000 }); }
69
- finally { unobserve?.(); }
97
+ unobserve?.();
70
98
  }
71
- const directory = cleanup.agents.find(agent => agent.agentId === synthId)?.artifacts.find(path => path.endsWith('/artifacts/files'));
72
- const file = directory && join(directory, 'report.md');
73
- const bytes = file ? await readFile(file).catch(() => undefined) : undefined;
74
- const artifact = file && bytes && bytes.toString('utf8').trim() ? {
75
- path: file, sha256: createHash('sha256').update(bytes).digest('hex'),
76
- } : undefined;
77
- const findings = board.search();
78
- return {
79
- outcome: context.signal.aborted ? 'cancelled' : failure || !artifact ? 'failed' : 'completed',
80
- reason: failure ?? (artifact ? 'report-verified' : 'report-missing'),
81
- result: { runtimeId: runtime.id, findings: findings.length, citedFindings: findings.filter(finding => finding.cites.length > 0).length },
82
- acceptance: { status: artifact ? 'verified' : 'unverified' },
83
- artifacts: artifact ? [artifact] : [],
84
- ...(synthId ? { export: { status: artifact ? 'complete' : 'failed' } } : {}),
85
- cleanup: { status: cleanup.cleanup, pending: cleanup.pending.map(({ id, kind, action }) => ({ id, kind, action })) },
86
- };
87
99
  },
88
100
  } satisfies Harness;
89
101