@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
@@ -1,11 +1,11 @@
1
1
  # Code 用户需求
2
2
 
3
- 适用范围见 [#336](https://github.com/AnySwarm/anyswarm/issues/336)。用户在自己的项目目录运行 `anys -u code [任务]`,也可以打开 `anys` 后输入 `/code`。共享界面显示项目、执行器和模型。用户可以回答内联问题、用 `/diff` 查看最近一轮的改动,或继续输入。退出时提供清理结果。
3
+ 适用范围见 [#336](https://github.com/AnySwarm/anyswarm/issues/336)。[#351](https://github.com/AnySwarm/anyswarm/issues/351) 将 Code 保留为进阶 SDK 示例。单次运行接收任务和显式配置,多轮输入、问答、差异和成员控制由 SDK 或 RPC 客户端处理。
4
4
 
5
5
  - 一个会话由一个 Runtime 管理。主 Agent 默认在一个可写的隔离工作区读项目、改代码并运行检查。用户可以在聊天中要求委派,主 Agent 可以和独立子 Agent 同时工作,收取结果并审查。用户可针对任意活跃成员发消息、中断或停止。
6
6
  - 每轮以用户当前目录的内容为起点,包含已跟踪文件的未提交修改和未忽略的新文件。宿主比较主 Agent、已收取的子 Agent 结果和实时工作树,合并后按任务授权写回。用户改动冲突时显示路径并保留原文件。
7
7
  - 用户可见改动文件和实际 diff。宿主监督配置或用户确认的检查,并展示命令、退出码和状态。Node 检查可复用受支持的现有依赖安装,缺失时显示校验环境问题。无命令时显示未验证。校验失败时保留原项目文件。
8
- - `Ctrl+C` 请求中断当前轮,之后可以继续输入。`/quit` 等待资源清理。空闲时在成功任务后退出,清理确认后返回 0。会话收尾保留报告、检查结果、已写入的路径和 Trace。
9
- - `anys eject code` 导出完整 TS 应用。作者能在仓库外直接运行、修改并重新执行其副本。
8
+ - 多轮客户端可以请求中断当前轮,之后继续输入,也可停止整个会话并等待清理。单次运行在任务完成、清理确认后返回 0。会话收尾保留报告、检查结果、已写入的路径和 Trace。
9
+ - `anyswarm eject code` 导出完整 TS 应用。作者能在仓库外直接运行、修改并重新执行其副本。
10
10
 
11
11
  验收使用同一个仓库外安装的候选包。用真实项目覆盖默认单 Agent 两轮编辑、用户明确要求并行委派、中断后继续、验证失败、并行成员控制、退出清理和导出源码。记录每轮文件上传下载字节数、实际容器数、峰值内存和最终检查结果。ProgramBench 使用同一 Code 应用,运行状态和官方评分单独记录。
@@ -7,6 +7,7 @@ declare const _default: {
7
7
  useServerProxy: boolean | undefined;
8
8
  egressMode: "dns+nft" | undefined;
9
9
  endpointHost: undefined;
10
+ preparedImage?: string | undefined;
10
11
  resourceLimits: {
11
12
  cpu: string;
12
13
  memory: string;
@@ -0,0 +1,25 @@
1
+ # Editing this Harness
2
+
3
+ This is consumer-owned source exported from AnySwarm. Use the public
4
+ `@anyswarm/core` entry and the SDK recorded in `anyswarm-source.json`; run `npm
5
+ install` here and use `npm run start` or `npm exec -- anyswarm`. Keep imports local
6
+ to this project or to declared dependencies.
7
+
8
+ - `config.ts` owns the connection, selected executor/model, shared model-request
9
+ limit and foreground channel. Explicit `--config ./custom.ts` replaces this
10
+ configuration; start from its exported defaults when changing one setting.
11
+ - `harness.ts` owns the two Profiles, turn order and completion checks.
12
+ `context.runWithRuntime` owns close/report classification; `runInput` waits for
13
+ each exclusive Agent turn. Keep business verification outside `afterClose`.
14
+ - `handoff.ts` owns the Service contract and authenticated caller evidence.
15
+ The publisher may publish; the writer may take. Preserve request IDs and the
16
+ fresh publisher-only reference when changing the exercise.
17
+ - Default foreground execution must finish without a question. `session.ts`
18
+ deliberately enables questions for the SDK/RPC extension.
19
+ - Check both sandbox and exported `delivery.txt` bytes, including final newlines.
20
+ Keep business acceptance, artifact export and cleanup separate. Preserve the
21
+ original pending resources and receipts instead of inventing success after a
22
+ timeout or missing export.
23
+
24
+ Make the smallest change needed for the user's task, keep credentials in trusted
25
+ configuration, and update this project's README when its commands or checks change.
@@ -0,0 +1,136 @@
1
+ # First SDK Harness: a verified Service handoff
2
+
3
+ Two Agents exchange a fresh release reference through a host-owned Handoff
4
+ Service. The publisher reads the reference in its isolated Sandbox. The writer
5
+ retrieves it using its own Service permission and writes `delivery.txt`. The host
6
+ checks the authenticated author and reader, then checks the exact bytes in the
7
+ writer's Sandbox and again after export.
8
+
9
+ This is a small SDK exercise for Profiles, Services and artifact verification.
10
+ The foreground channel defaults to `preview`, so the ordinary run has no midway
11
+ questions. Explicit SDK and RPC question clients are available below.
12
+
13
+ ## Prepare and run the exported source
14
+
15
+ Use Node.js 22.19 or later, an AnySwarm installation, a working OpenSandbox and a
16
+ compatible Worker prepared with `anyswarm setup`. The example inherits setup's
17
+ executor, image and connection. Local setup needs Docker and the selected Pi or
18
+ Codex installation; an existing OpenSandbox needs its authenticated connection
19
+ and a callback address reachable by its Workers. No additional business service
20
+ is needed: Handoff runs in the host process.
21
+
22
+ Configure an existing streaming model endpoint with tool support. Set
23
+ `ANYSWARM_MODEL_URL`, and set `ANYSWARM_MODEL_ID` and `ANYSWARM_MODEL_PROVIDER` for
24
+ your model. Pi defaults to `gpt-5-mini`; Codex requires an explicit model ID. The
25
+ provider defaults to `openai`. Set `ANYSWARM_MODEL_TOKEN`
26
+ in the host environment only if the endpoint requires authentication. Pi supports
27
+ `ANYSWARM_MODEL_PROTOCOL=responses` or `chat-completions`; Codex requires
28
+ `responses`. The endpoint URL must match that protocol.
29
+
30
+ ```sh
31
+ anyswarm eject first-harness --dir ./first-harness
32
+ cd ./first-harness
33
+ npm install
34
+ npm run start -- --cwd ./input --prompt "Prepare a release handoff." --output-dir ./runs
35
+ npm exec -- anyswarm trace --root ./runs
36
+ ```
37
+
38
+ The export contains the Harness, Service, configuration, question client and input
39
+ directory, together with the exact SDK archive used by `npm install`. It does not
40
+ require a checkout of AnySwarm or any sibling example. When running from the
41
+ AnySwarm repository instead, build the repository and run
42
+ `node dist/scripts/anyswarm.js run examples/first-harness/harness.ts --cwd
43
+ examples/first-harness/input --prompt "Prepare a release handoff." --output-dir
44
+ ./runs`.
45
+
46
+ ## Change the channel or configuration
47
+
48
+ ```sh
49
+ ANYSWARM_FIRST_CHANNEL=beta-east npm run start -- --cwd ./input \
50
+ --prompt "Prepare a release handoff." --output-dir ./runs
51
+ ```
52
+
53
+ A channel starts with a lowercase letter and contains at most 24 lowercase
54
+ letters, digits or hyphens. For further changes, edit `config.ts`, or create a
55
+ complete configuration such as:
56
+
57
+ ```ts
58
+ import defaults from './config.js';
59
+
60
+ export default { ...defaults, channel: 'staging' };
61
+ ```
62
+
63
+ Pass it as `npm run start -- --config ./custom.ts --cwd ./input --prompt "Prepare
64
+ a release handoff."`. A supplied configuration is used directly; it is not
65
+ silently overwritten with environment values. The default configuration reads
66
+ common `ANYSWARM_*` connection settings before saved setup values, and
67
+ `ANYSWARM_EXECUTOR` before setup's executor. Set `ANYSWARM_WORKER_IMAGE` to an image
68
+ compatible with an executor override when necessary. With neither selection,
69
+ the executor falls back to Pi. `ANYSWARM_CONTEXT_WINDOW` can supply a context limit
70
+ of at least 2048 tokens for an unlisted model; edit `models.default.capabilities`
71
+ for its other capabilities.
72
+
73
+ The default shared gateway limit is 32 model requests. Each Agent turn has a
74
+ 120-second deadline; Runtime close has a 60-second wait. These are bounds, not a
75
+ promise about model response time or cost. The example uses two Agent slots in
76
+ one Runtime.
77
+
78
+ ## Inspect the result
79
+
80
+ The foreground command prints a final result record. Successful delivery has
81
+ `outcome: "completed"`, `acceptance.status: "verified"`, `export.status:
82
+ "complete"` and `cleanup.status: "complete"`. `acceptance.file` identifies the
83
+ exported file; `acceptance.bytes` and `acceptance.sha256` describe the bytes that
84
+ were checked. Its content is:
85
+
86
+ ```text
87
+ reference=<fresh 12-character hexadecimal reference>
88
+ channel=preview
89
+ ```
90
+
91
+ Both lines end with a newline. The reference is generated per Run, supplied only
92
+ to the publisher, and read by the writer through Handoff. The input directory is
93
+ captured as a snapshot; neither Agent writes back to it. `result.handoff` records
94
+ the real author, reader and request IDs. `reportPath` points to the saved host
95
+ report, while `cleanup.receipt` retains the original Runtime close receipt.
96
+
97
+ Check export and cleanup separately from business outcome. A pending required
98
+ export remains `export.status: "pending"` with the raw resource identity in
99
+ `cleanup.pending`; a completed turn does not make it verified. An exported file
100
+ with wrong bytes fails acceptance without being relabelled a cleanup failure.
101
+ A failed or cancelled run retains the available business and cleanup evidence.
102
+ No file is published to a real release channel by this exercise.
103
+
104
+ ## Explicit SDK and RPC questions
105
+
106
+ The advanced terminal client opts into question events. These commands ask for
107
+ the channel even if the foreground preset is set:
108
+
109
+ ```sh
110
+ npm exec -- anyswarm run ./session.ts ./input "Prepare a release handoff."
111
+ npm exec -- anyswarm run ./session.ts --rpc ./input "Prepare a release handoff."
112
+ ```
113
+
114
+ `session.ts` uses `createHarnessSession` directly or wraps the JSONL CLI with
115
+ `HarnessRpcClient`. It answers the pending `questionId` using `respond`, observes
116
+ completion, and stops on terminal EOF or interruption. A custom JSONL client can
117
+ use `anyswarm --harness ./harness.ts --mode rpc --interaction questions`, submit a
118
+ `run` operation, then answer the emitted question. An SDK client explicitly sets
119
+ `clientCapabilities: { questions: true }`. Plain foreground and clients without
120
+ question support use the preset channel.
121
+
122
+ ## Read and modify
123
+
124
+ | File | Responsibility |
125
+ | --- | --- |
126
+ | `harness.ts` | Profiles, publisher/writer turns, questions, exact byte checks and result projection. |
127
+ | `handoff.ts` | Service schemas, authenticated publish/take and caller evidence. |
128
+ | `config.ts` | Setup inheritance, model protocol, budgets and foreground channel. |
129
+ | `session.ts` | Explicit SDK/RPC question client. |
130
+ | `AGENTS.md` | Short instructions for the coding agent editing your exported source. |
131
+
132
+ Controlled tests exercise the real Runtime and authenticated Service Bridge with
133
+ a simulated Worker transport, including wrong bytes and pending export. Installed
134
+ Worker/model tests live in `test/first-harness-installed.test.ts` in the AnySwarm
135
+ repository and require a configured backend. Passing controlled tests alone does
136
+ not establish that a particular external model or Worker is ready.
@@ -1,13 +1,14 @@
1
- import type { ModelConfig, RuntimeConnectionOptions, SandboxConfig } from '@anyswarm/core';
2
- declare const _default: {
1
+ import { type ExecutorSelection, type ModelConfig, type RuntimeConnectionOptions, type SandboxConfig } from '@anyswarm/core';
2
+ export interface FirstHarnessConfiguration {
3
3
  sandbox: SandboxConfig;
4
4
  connection: RuntimeConnectionOptions;
5
- executor: 'pi';
5
+ executor: ExecutorSelection;
6
6
  image: string;
7
- channel: string | undefined;
8
7
  model: string;
9
- models: {
10
- default: ModelConfig;
11
- };
12
- };
8
+ models: Record<string, ModelConfig>;
9
+ /** Used by foreground clients. Explicit question clients ask for their own channel. */
10
+ channel?: string;
11
+ }
12
+ export declare function firstHarnessConfig(): FirstHarnessConfiguration;
13
+ declare const _default: FirstHarnessConfiguration;
13
14
  export default _default;
@@ -1,27 +1,34 @@
1
- import * as sdk from '@anyswarm/core';
2
- const env = process.env;
3
- const resolved = sdk.resolveSandboxConnection();
4
- const sandbox = {
5
- lifecycleBaseUrl: resolved.lifecycleBaseUrl, apiKey: resolved.apiKey, endpointHost: resolved.endpointHost,
6
- };
7
- const protocol = env.ANYSWARM_MODEL_PROTOCOL ?? 'responses';
8
- if (!['responses', 'chat-completions'].includes(protocol)) {
9
- throw new Error('Select responses, or use chat-completions with the SDK that supports it.');
1
+ import { ProjectPreflightError, resolveSandboxConnection, workerImageFor } from '@anyswarm/core';
2
+ export function firstHarnessConfig() {
3
+ const env = process.env;
4
+ const { image, advertiseHost, publicUrl, executor: setupExecutor, endpointSource: _source, ...sandbox } = resolveSandboxConnection();
5
+ const executor = env.ANYSWARM_EXECUTOR ?? setupExecutor ?? 'pi';
6
+ if (executor !== 'pi' && executor !== 'codex')
7
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set ANYSWARM_EXECUTOR to pi or codex, or provide an executor in your TypeScript configuration.');
8
+ const protocol = env.ANYSWARM_MODEL_PROTOCOL ?? 'responses';
9
+ if (protocol !== 'responses' && protocol !== 'chat-completions') {
10
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set ANYSWARM_MODEL_PROTOCOL to responses or chat-completions.');
11
+ }
12
+ if (executor === 'codex' && protocol !== 'responses')
13
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Codex requires ANYSWARM_MODEL_PROTOCOL=responses.');
14
+ if (executor === 'codex' && !env.ANYSWARM_MODEL_ID?.trim())
15
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set ANYSWARM_MODEL_ID to a model supported by your Codex Responses endpoint.');
16
+ const contextWindow = env.ANYSWARM_CONTEXT_WINDOW === undefined ? undefined : Number(env.ANYSWARM_CONTEXT_WINDOW);
17
+ if (contextWindow !== undefined && (!Number.isSafeInteger(contextWindow) || contextWindow < 2048)) {
18
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'ANYSWARM_CONTEXT_WINDOW must be the configured model context limit, at least 2048 tokens.');
19
+ }
20
+ const model = {
21
+ provider: env.ANYSWARM_MODEL_PROVIDER ?? 'openai',
22
+ model: env.ANYSWARM_MODEL_ID ?? 'gpt-5-mini',
23
+ upstream: { url: env.ANYSWARM_MODEL_URL ?? '', headers: env.ANYSWARM_MODEL_TOKEN ? { authorization: `Bearer ${env.ANYSWARM_MODEL_TOKEN}` } : {} },
24
+ ...(protocol === 'chat-completions' ? { protocol } : {}),
25
+ ...(contextWindow ? { capabilities: { contextWindow, maxOutputTokens: 1024, tools: true, reasoning: false } } : {}),
26
+ };
27
+ return {
28
+ sandbox, executor, image: image ?? workerImageFor(executor),
29
+ connection: { advertiseHost, publicUrl,
30
+ modelGateway: { requestTimeoutMs: 90_000, maxOutputTokens: executor === 'codex' ? null : 1024, maxRequests: 32 } },
31
+ channel: env.ANYSWARM_FIRST_CHANNEL ?? 'preview', model: 'default', models: { default: model },
32
+ };
10
33
  }
11
- const contextWindow = env.ANYSWARM_CONTEXT_WINDOW === undefined ? undefined : Number(env.ANYSWARM_CONTEXT_WINDOW);
12
- if (contextWindow !== undefined && (!Number.isSafeInteger(contextWindow) || contextWindow < 2048)) {
13
- throw new Error('ANYSWARM_CONTEXT_WINDOW must be the configured model context limit, at least 2048 tokens.');
14
- }
15
- const model = {
16
- provider: env.ANYSWARM_MODEL_PROVIDER ?? 'openai',
17
- model: env.ANYSWARM_MODEL_ID ?? 'gpt-5-mini',
18
- upstream: { url: env.ANYSWARM_MODEL_URL ?? '', headers: env.ANYSWARM_MODEL_TOKEN ? { authorization: `Bearer ${env.ANYSWARM_MODEL_TOKEN}` } : {} },
19
- ...(protocol === 'chat-completions' ? { protocol } : {}),
20
- ...(contextWindow ? { capabilities: { contextWindow, maxOutputTokens: 1024, tools: true, reasoning: false } } : {}),
21
- };
22
- const connection = {
23
- advertiseHost: resolved.advertiseHost,
24
- modelGateway: { requestTimeoutMs: 90_000, maxOutputTokens: 1024, maxRequests: 32 },
25
- };
26
- const image = resolved.image ?? sdk.workerImageFor('pi');
27
- export default { sandbox, connection, executor: 'pi', image, channel: env.ANYSWARM_FIRST_CHANNEL, model: 'default', models: { default: model } };
34
+ export default firstHarnessConfig();
@@ -0,0 +1,14 @@
1
+ {
2
+ "apiVersion": 1,
3
+ "entry": "harness.ts",
4
+ "files": [
5
+ "harness.ts",
6
+ "config.ts",
7
+ "handoff.ts",
8
+ "session.ts",
9
+ "tsconfig.json",
10
+ "input/README.md",
11
+ "README.md",
12
+ "AGENTS.md"
13
+ ]
14
+ }
@@ -7,12 +7,12 @@ const record = {
7
7
  required: ['reference', 'question'], additionalProperties: false,
8
8
  };
9
9
  export const handoffInterface = {
10
- description: 'Publish a release reference and user question for the next Agent.',
10
+ description: 'Publish a release reference and an optional client question for the next Agent.',
11
11
  operations: {
12
- publish: { description: 'Save the release reference and ask the user for a channel.',
12
+ publish: { description: 'Save the release reference and a question for clients that support channel questions.',
13
13
  usage: 'After reading release-data.txt.', inputSchema: record, outputSchema: record, idempotent: true },
14
14
  take: { description: 'Fetch the reference and question together.',
15
- usage: 'After the Harness gives you the user’s answer.', sideEffect: 'read', outputSchema: record },
15
+ usage: 'After the Harness supplies the preset or answered release channel.', sideEffect: 'read', outputSchema: record },
16
16
  },
17
17
  };
18
18
  export function createHandoff() {
@@ -1,13 +1,23 @@
1
+ import { type HarnessJson } from '@anyswarm/core';
1
2
  declare const firstHarness: {
2
3
  id: string;
3
4
  apiVersion: 1;
4
5
  questions: true;
5
6
  run(context: import("@anyswarm/core").HarnessContext): Promise<{
6
- outcome: "cancelled" | "completed" | "failed";
7
+ outcome: 'completed' | 'failed' | 'cancelled';
7
8
  reason: string;
9
+ export?: {
10
+ status: 'complete' | 'failed' | 'pending';
11
+ receipt?: HarnessJson;
12
+ };
13
+ cleanup: {
14
+ status: 'complete' | 'pending';
15
+ receipt?: HarnessJson;
16
+ pending?: HarnessJson;
17
+ retained?: HarnessJson;
18
+ };
8
19
  result: {
9
- runtimeId: string;
10
- failure: {
20
+ verificationFailure: {
11
21
  stage: string;
12
22
  code: string;
13
23
  } | null;
@@ -29,21 +39,7 @@ declare const firstHarness: {
29
39
  } | {
30
40
  status: string;
31
41
  };
32
- artifacts: {
33
- path: string;
34
- sha256: string;
35
- }[];
36
- export?: {
37
- status: "complete" | "failed" | "pending";
38
- } | undefined;
39
- cleanup: {
40
- status: "complete" | "pending";
41
- pending: {
42
- id: string;
43
- kind: "agent" | "backend" | "bridge" | "model" | "report" | "service";
44
- action: "archive-session" | "await-startup" | "close" | "collect-artifacts" | "delete-sandbox" | "retire-service" | "save" | "stop-execution";
45
- }[];
46
- };
42
+ artifacts: HarnessJson[];
47
43
  }>;
48
44
  };
49
45
  export default firstHarness;
@@ -1,109 +1,134 @@
1
1
  import { createHash, randomBytes } from 'node:crypto';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
- import { createRuntime, createSandbox, ProjectPreflightError, runInput, ServiceRegistry } from '@anyswarm/core';
4
+ import { createRuntime, createSandbox, projectConfiguration, ProjectPreflightError, runInput, ServiceRegistry } from '@anyswarm/core';
5
5
  import { createHandoff } from './handoff.js';
6
+ const channelPattern = /^[a-z][a-z0-9-]{0,23}$/;
7
+ const json = (value) => JSON.parse(JSON.stringify(value));
8
+ const failed = (code, message) => Object.assign(new Error(message), { code });
6
9
  const firstHarness = {
7
10
  id: 'first-harness', apiVersion: 1, questions: true,
8
11
  async run(context) {
9
- const config = (context.configuration ?? (await import('./config.js')).default);
10
- if (!context.clientCapabilities.questions && !/^[a-z][a-z0-9-]{0,23}$/.test(config.channel ?? '')) {
11
- throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set ANYSWARM_FIRST_CHANNEL for noninteractive execution');
12
+ const config = await projectConfiguration(context, () => import('./config.js'));
13
+ const presetChannel = config.channel ?? 'preview';
14
+ if (!context.clientCapabilities.questions && !channelPattern.test(presetChannel)) {
15
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set channel or ANYSWARM_FIRST_CHANNEL to a lowercase release channel such as preview or beta-east (at most 24 characters).');
16
+ }
17
+ if (!config.models || typeof config.models !== 'object' || Array.isArray(config.models) || typeof config.model !== 'string') {
18
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Provide a models map and select one of its aliases with model.');
19
+ }
20
+ const model = config.models[config.model];
21
+ const protocol = model?.protocol && typeof model.protocol === 'object' ? model.protocol.clientProtocol : model?.protocol ?? 'responses';
22
+ const executor = typeof config.executor === 'string' ? config.executor : config.executor?.kind;
23
+ if (!Object.hasOwn(config.models, config.model) || !model || model.protocol === null ||
24
+ (executor === 'codex' && protocol !== 'responses') ||
25
+ (executor === 'pi' && protocol !== 'responses' && protocol !== 'chat-completions')) {
26
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Select a configured model alias. Codex requires the Responses protocol; Pi also supports Chat Completions.');
12
27
  }
13
28
  const reference = randomBytes(6).toString('hex');
14
29
  const handoff = createHandoff();
15
30
  const services = new ServiceRegistry();
16
31
  services.register('handoff', handoff.service, { toolMode: 'cli' });
17
- const runtime = await createRuntime({
18
- sandbox: createSandbox(config.sandbox), connection: config.connection, executor: config.executor, models: config.models,
19
- services, maxAgents: 2, outputDir: context.outputDir,
20
- profiles: {
21
- publisher: {
22
- model: config.model, image: config.image, writable: false, services: { handoff: ['publish'] },
23
- addedSystemPrompt: 'Read release-data.txt. Publish its reference and one short question asking the user for a release channel. Run swarm service invoke handoff publish --help for arguments. Use the workspace for reading files.',
24
- },
25
- writer: {
26
- model: config.model, image: config.image, services: { handoff: ['take'] }, writable: true,
27
- addedSystemPrompt: 'Run swarm service invoke handoff take using the exact Bash command supplied in your task. Use the bash tool in your writable workspace. The command reads the reference from the Service and writes delivery.txt with two newline-terminated lines.',
28
- },
29
- },
30
- });
31
32
  const turn = { signal: context.signal, timeoutMs: 120_000 };
32
- let phase = 'publish';
33
+ let phase = 'starting';
33
34
  let writerId;
34
35
  let channel;
35
36
  let expected;
36
- let failure;
37
- let cleanup;
37
+ let closed;
38
38
  let unobserve;
39
+ let outcome;
39
40
  try {
40
- unobserve = context.registerAgentControls({ runtime });
41
- context.markRunning();
42
- const publisher = await runtime.spawn({
43
- requestId: 'spawn-publisher', profile: 'publisher',
44
- files: { ...context.initial.files, 'release-data.txt': { encoding: 'utf8', data: `${reference}\n` } },
45
- });
46
- await runInput(runtime, publisher.id, [
47
- context.input.prompt,
48
- 'Read the reference in release-data.txt.',
49
- 'Publish the real reference with --reference=<reference> and --question=<quoted text> or use JSON on stdin.',
50
- 'Use request ID publish-release. Finish when the handoff succeeds.',
51
- ].join(' '), { ...turn, requestId: 'publisher-turn' });
52
- const note = handoff.evidence().note;
53
- if (note?.reference !== reference || note.author !== publisher.id)
54
- throw Object.assign(new Error(), { code: 'HANDOFF_NOT_VERIFIED' });
55
- phase = 'channel';
56
- const answer = context.clientCapabilities.questions
57
- ? await context.askUser({ requestId: 'release-channel', kind: 'text', text: note.question, agentId: publisher.id, timeoutMs: 120_000 }, { id: 'release-handoff', agentId: publisher.id, signal: context.signal })
58
- : config.channel;
59
- channel = typeof answer === 'string' ? answer.trim() : undefined;
60
- if (!channel || !/^[a-z][a-z0-9-]{0,23}$/.test(channel))
61
- throw Object.assign(new Error(), { code: 'INVALID_CHANNEL' });
62
- phase = 'write';
63
- const writer = await runtime.spawn({
64
- requestId: 'spawn-writer', profile: 'writer', files: context.initial.files,
65
- collect: { paths: ['delivery.txt'], maxBytes: 4096, includeGit: false, required: true },
66
- });
67
- writerId = writer.id;
68
- await runInput(runtime, writer.id, `The user chose channel ${channel}. Run the following exact command with the bash tool in your workspace:
41
+ outcome = await context.runWithRuntime({
42
+ createRuntime: () => createRuntime({
43
+ sandbox: createSandbox(config.sandbox), connection: config.connection, executor: config.executor, models: config.models,
44
+ services, maxAgents: 2, outputDir: context.outputDir,
45
+ profiles: {
46
+ publisher: {
47
+ model: config.model, image: config.image, writable: false, services: { handoff: ['publish'] },
48
+ addedSystemPrompt: 'Read release-data.txt. Publish its reference and one short question asking for a release channel. The Harness supplies the preset channel or asks its explicit question client. Run swarm service invoke handoff publish --help for arguments. Use the workspace for reading files.',
49
+ },
50
+ writer: {
51
+ model: config.model, image: config.image, services: { handoff: ['take'] }, writable: true,
52
+ addedSystemPrompt: 'Run swarm service invoke handoff take using the exact shell command supplied in your task. Use your command execution tool in the writable workspace. The command reads the reference from the Service and writes delivery.txt with two newline-terminated lines.',
53
+ },
54
+ },
55
+ }),
56
+ async run(runtime) {
57
+ unobserve = context.registerAgentControls({ runtime });
58
+ context.markRunning();
59
+ phase = 'publish';
60
+ const publisher = await runtime.spawn({
61
+ requestId: 'spawn-publisher', profile: 'publisher',
62
+ files: { ...context.initial.files, 'release-data.txt': { encoding: 'utf8', data: `${reference}\n` } },
63
+ });
64
+ await runInput(runtime, publisher.id, [
65
+ context.input.prompt,
66
+ 'Read the reference in release-data.txt.',
67
+ 'Publish the real reference with --reference=<reference> and --question=<quoted text> or use JSON on stdin.',
68
+ 'Use request ID publish-release. Finish when the handoff succeeds.',
69
+ ].join(' '), { ...turn, requestId: 'publisher-turn' });
70
+ const note = handoff.evidence().note;
71
+ if (note?.reference !== reference || note.author !== publisher.id) {
72
+ throw failed('HANDOFF_NOT_VERIFIED', 'The authenticated publisher did not hand off its sandbox reference.');
73
+ }
74
+ phase = 'channel';
75
+ const answer = context.clientCapabilities.questions
76
+ ? await context.askUser({ requestId: 'release-channel', kind: 'text', text: note.question, agentId: publisher.id, timeoutMs: 120_000 }, { id: 'release-handoff', agentId: publisher.id, signal: context.signal })
77
+ : presetChannel;
78
+ channel = typeof answer === 'string' ? answer.trim() : undefined;
79
+ if (!channel || !channelPattern.test(channel))
80
+ throw failed('INVALID_CHANNEL', 'The release channel must start with a lowercase letter and contain at most 24 lowercase letters, digits or hyphens.');
81
+ phase = 'write';
82
+ const writer = await runtime.spawn({
83
+ requestId: 'spawn-writer', profile: 'writer', files: context.initial.files,
84
+ collect: { paths: ['delivery.txt'], maxBytes: 4096, includeGit: false, required: true },
85
+ });
86
+ writerId = writer.id;
87
+ await runInput(runtime, writer.id, `The user chose channel ${channel}. Run the following exact command with your command execution tool in your workspace:
69
88
  swarm service invoke handoff take --request-id take-release | node -e 'const { reference } = JSON.parse(require("node:fs").readFileSync(0, "utf8")).result; console.log("reference=" + reference); console.log("channel=${channel}");' > delivery.txt
70
89
  Finish when the command succeeds.`, { ...turn, requestId: 'writer-turn' });
71
- if (handoff.evidence().read?.reader !== writer.id)
72
- throw Object.assign(new Error(), { code: 'HANDOFF_NOT_READ' });
73
- phase = 'verify';
74
- expected = Buffer.from(`reference=${reference}\nchannel=${channel}\n`);
75
- const snapshot = await runtime.files.snapshot(writer.id, { requestId: 'verify-delivery', paths: ['delivery.txt'], maxBytes: 4096 });
76
- const file = snapshot.files['delivery.txt'];
77
- if (!file || !Buffer.from(file.data, file.encoding).equals(expected))
78
- throw Object.assign(new Error(), { code: 'DELIVERY_BYTES_MISMATCH' });
79
- }
80
- catch (error) {
81
- failure = { stage: phase, code: error.code ?? 'HANDOFF_FAILED' };
90
+ if (handoff.evidence().read?.reader !== writer.id)
91
+ throw failed('HANDOFF_NOT_READ', 'The authenticated writer did not read the published handoff.');
92
+ phase = 'verify-sandbox';
93
+ expected = Buffer.from(`reference=${reference}\nchannel=${channel}\n`);
94
+ const snapshot = await runtime.files.snapshot(writer.id, { requestId: 'verify-delivery', paths: ['delivery.txt'], maxBytes: 4096 });
95
+ const file = snapshot.files['delivery.txt'];
96
+ if (!file || !Buffer.from(file.data, file.encoding).equals(expected)) {
97
+ throw failed('DELIVERY_BYTES_MISMATCH', 'The sandbox delivery does not match the published reference and chosen channel.');
98
+ }
99
+ phase = 'export';
100
+ return { sandboxBytesVerified: true };
101
+ },
102
+ // Capture ownership evidence only. Business verification below must not
103
+ // throw from afterClose, whose errors are classified as cleanup failures.
104
+ afterClose(receipt) { closed = receipt; },
105
+ closeTimeoutMs: 60_000,
106
+ detail: () => ({ phase }),
107
+ });
82
108
  }
83
109
  finally {
84
- try {
85
- cleanup = await runtime.close({ timeoutMs: 60_000 });
86
- }
87
- finally {
88
- unobserve?.();
89
- }
110
+ unobserve?.();
90
111
  }
91
- const directory = cleanup?.agents.find(agent => agent.agentId === writerId)?.artifacts.find(path => path.endsWith('/artifacts/files'));
112
+ const writerReceipt = closed?.agents.find(agent => agent.agentId === writerId);
113
+ const directory = writerReceipt?.artifacts.find(path => path.endsWith('/artifacts/files'));
92
114
  const delivery = directory ? join(directory, 'delivery.txt') : undefined;
93
115
  const bytes = delivery ? await readFile(delivery).catch(() => undefined) : undefined;
94
- const verification = delivery && bytes && expected && bytes.equals(expected)
116
+ const pending = outcome.export?.status === 'pending' || (writerId !== undefined && closed === undefined);
117
+ const verification = outcome.outcome === 'completed' && delivery && bytes && expected && bytes.equals(expected)
95
118
  ? { file: delivery, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') } : undefined;
119
+ const wrongBytes = bytes && expected && !bytes.equals(expected);
120
+ const verificationFailure = outcome.outcome === 'completed' && !verification && (wrongBytes || !pending)
121
+ ? { stage: 'verify-export', code: bytes ? 'EXPORTED_BYTES_MISMATCH' : 'DELIVERY_EXPORT_MISSING' } : undefined;
96
122
  const { note, read } = handoff.evidence();
97
- const exportPending = cleanup?.pending?.some(resource => resource.action === 'collect-artifacts');
98
123
  return {
99
- outcome: context.signal.aborted ? 'cancelled' : failure ? 'failed' : 'completed',
100
- reason: failure?.code ?? (context.signal.aborted ? 'stopped' : 'release-handoff'),
101
- result: { runtimeId: runtime.id, failure: failure ?? null, handoff: { author: note?.author ?? null,
102
- publishRequestId: note?.requestId ?? null, read: read ?? null, channel: channel ?? null } },
124
+ ...outcome,
125
+ ...(verificationFailure ? { outcome: 'failed', reason: verificationFailure.code } : {}),
126
+ result: { ...outcome.result, verificationFailure: verificationFailure ?? null,
127
+ handoff: { author: note?.author ?? null, publishRequestId: note?.requestId ?? null, read: read ?? null, channel: channel ?? null } },
103
128
  acceptance: verification ? { status: 'verified', ...verification } : { status: 'unverified' },
104
- artifacts: verification ? [{ path: verification.file, sha256: verification.sha256 }] : [],
105
- ...(writerId ? { export: { status: verification ? 'complete' : exportPending ? 'pending' : 'failed' } } : {}),
106
- cleanup: { status: cleanup?.cleanup ?? 'pending', pending: cleanup?.pending?.map(({ id, kind, action }) => ({ id, kind, action })) ?? null },
129
+ artifacts: [...outcome.artifacts, ...(verification ? [{ path: verification.file, sha256: verification.sha256 }] : [])],
130
+ ...(writerId ? { export: { status: pending ? 'pending' : bytes ? 'complete' : 'failed',
131
+ receipt: json(writerReceipt ?? null) } } : {}),
107
132
  };
108
133
  },
109
134
  };
@@ -0,0 +1,7 @@
1
+ # Release handoff input
2
+
3
+ This directory is the input snapshot for the first SDK Harness. The host generates
4
+ a fresh release reference for every Run and supplies `release-data.txt` only to the
5
+ publisher. The writer must retrieve that reference from the authenticated Handoff
6
+ Service. It writes `delivery.txt` in its own Sandbox; the host verifies and exports
7
+ that file without changing this directory.
@@ -6,7 +6,8 @@ import { createHarnessSession, HarnessRpcClient } from '@anyswarm/core';
6
6
  import firstHarness from './harness.js';
7
7
  const rpc = process.argv[2] === '--rpc';
8
8
  const [cwd = process.cwd(), prompt = 'Prepare a release handoff.'] = process.argv.slice(rpc ? 3 : 2);
9
- const file = fileURLToPath(new URL('./harness.js', import.meta.url));
9
+ // The source export runs .ts directly; compiled package tests use its .js peer.
10
+ const file = fileURLToPath(new URL(new URL(import.meta.url).pathname.endsWith('.ts') ? './harness.ts' : './harness.js', import.meta.url));
10
11
  const child = rpc ? spawn('anyswarm', ['--harness', file, '--mode', 'rpc', '--interaction', 'questions'], { stdio: ['pipe', 'pipe', 'inherit'] }) : undefined;
11
12
  const session = child ? new HarnessRpcClient(child) : createHarnessSession(firstHarness, { clientCapabilities: { questions: true } });
12
13
  const terminal = createInterface({ input: process.stdin, output: process.stderr });
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2023",
4
- "module": "NodeNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
5
6
  "strict": true,
6
7
  "skipLibCheck": true,
7
8
  "types": ["node"],