@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,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,31 +1,45 @@
1
- import * as sdk from '@anyswarm/core';
2
- import type { ModelConfig, RuntimeConnectionOptions, SandboxConfig } from '@anyswarm/core';
1
+ import { ProjectPreflightError, resolveSandboxConnection, workerImageFor, type ExecutorSelection, type ModelConfig,
2
+ type RuntimeConnectionOptions, type SandboxConfig } from '@anyswarm/core';
3
3
 
4
- const env = process.env;
5
- const resolved = sdk.resolveSandboxConnection();
6
- const sandbox: SandboxConfig = {
7
- lifecycleBaseUrl: resolved.lifecycleBaseUrl, apiKey: resolved.apiKey, endpointHost: resolved.endpointHost,
8
- };
9
-
10
- const protocol = env.ANYSWARM_MODEL_PROTOCOL ?? 'responses';
11
- if (!['responses', 'chat-completions'].includes(protocol)) {
12
- throw new Error('Select responses, or use chat-completions with the SDK that supports it.');
4
+ export interface FirstHarnessConfiguration {
5
+ sandbox: SandboxConfig;
6
+ connection: RuntimeConnectionOptions;
7
+ executor: ExecutorSelection;
8
+ image: string;
9
+ model: string;
10
+ models: Record<string, ModelConfig>;
11
+ /** Used by foreground clients. Explicit question clients ask for their own channel. */
12
+ channel?: string;
13
13
  }
14
- const contextWindow = env.ANYSWARM_CONTEXT_WINDOW === undefined ? undefined : Number(env.ANYSWARM_CONTEXT_WINDOW);
15
- if (contextWindow !== undefined && (!Number.isSafeInteger(contextWindow) || contextWindow < 2048)) {
16
- throw new Error('ANYSWARM_CONTEXT_WINDOW must be the configured model context limit, at least 2048 tokens.');
14
+
15
+ export function firstHarnessConfig(): FirstHarnessConfiguration {
16
+ const env = process.env;
17
+ const { image, advertiseHost, publicUrl, executor: setupExecutor, endpointSource: _source, ...sandbox } = resolveSandboxConnection();
18
+ const executor = env.ANYSWARM_EXECUTOR ?? setupExecutor ?? 'pi';
19
+ if (executor !== 'pi' && executor !== 'codex') throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set ANYSWARM_EXECUTOR to pi or codex, or provide an executor in your TypeScript configuration.');
20
+ const protocol = env.ANYSWARM_MODEL_PROTOCOL ?? 'responses';
21
+ if (protocol !== 'responses' && protocol !== 'chat-completions') {
22
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set ANYSWARM_MODEL_PROTOCOL to responses or chat-completions.');
23
+ }
24
+ if (executor === 'codex' && protocol !== 'responses') throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Codex requires ANYSWARM_MODEL_PROTOCOL=responses.');
25
+ if (executor === 'codex' && !env.ANYSWARM_MODEL_ID?.trim()) throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set ANYSWARM_MODEL_ID to a model supported by your Codex Responses endpoint.');
26
+ const contextWindow = env.ANYSWARM_CONTEXT_WINDOW === undefined ? undefined : Number(env.ANYSWARM_CONTEXT_WINDOW);
27
+ if (contextWindow !== undefined && (!Number.isSafeInteger(contextWindow) || contextWindow < 2048)) {
28
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'ANYSWARM_CONTEXT_WINDOW must be the configured model context limit, at least 2048 tokens.');
29
+ }
30
+ const model: ModelConfig = {
31
+ provider: env.ANYSWARM_MODEL_PROVIDER ?? 'openai',
32
+ model: env.ANYSWARM_MODEL_ID ?? 'gpt-5-mini',
33
+ upstream: { url: env.ANYSWARM_MODEL_URL ?? '', headers: env.ANYSWARM_MODEL_TOKEN ? { authorization: `Bearer ${env.ANYSWARM_MODEL_TOKEN}` } : {} },
34
+ ...(protocol === 'chat-completions' ? { protocol } : {}),
35
+ ...(contextWindow ? { capabilities: { contextWindow, maxOutputTokens: 1024, tools: true, reasoning: false } } : {}),
36
+ };
37
+ return {
38
+ sandbox, executor, image: image ?? workerImageFor(executor),
39
+ connection: { advertiseHost, publicUrl,
40
+ modelGateway: { requestTimeoutMs: 90_000, maxOutputTokens: executor === 'codex' ? null : 1024, maxRequests: 32 } },
41
+ channel: env.ANYSWARM_FIRST_CHANNEL ?? 'preview', model: 'default', models: { default: model },
42
+ };
17
43
  }
18
- const model: ModelConfig = {
19
- provider: env.ANYSWARM_MODEL_PROVIDER ?? 'openai',
20
- model: env.ANYSWARM_MODEL_ID ?? 'gpt-5-mini',
21
- upstream: { url: env.ANYSWARM_MODEL_URL ?? '', headers: env.ANYSWARM_MODEL_TOKEN ? { authorization: `Bearer ${env.ANYSWARM_MODEL_TOKEN}` } : {} },
22
- ...(protocol === 'chat-completions' ? { protocol } : {}),
23
- ...(contextWindow ? { capabilities: { contextWindow, maxOutputTokens: 1024, tools: true, reasoning: false } } : {}),
24
- };
25
- const connection: RuntimeConnectionOptions = {
26
- advertiseHost: resolved.advertiseHost,
27
- modelGateway: { requestTimeoutMs: 90_000, maxOutputTokens: 1024, maxRequests: 32 },
28
- };
29
- const image = resolved.image ?? sdk.workerImageFor('pi');
30
44
 
31
- export default { sandbox, connection, executor: 'pi' as const, image, channel: env.ANYSWARM_FIRST_CHANNEL, model: 'default', models: { default: model } };
45
+ 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
+ }
@@ -8,12 +8,12 @@ const record = {
8
8
  required: ['reference', 'question'], additionalProperties: false,
9
9
  };
10
10
  export const handoffInterface: ServiceInterface = {
11
- description: 'Publish a release reference and user question for the next Agent.',
11
+ description: 'Publish a release reference and an optional client question for the next Agent.',
12
12
  operations: {
13
- publish: { description: 'Save the release reference and ask the user for a channel.',
13
+ publish: { description: 'Save the release reference and a question for clients that support channel questions.',
14
14
  usage: 'After reading release-data.txt.', inputSchema: record, outputSchema: record, idempotent: true },
15
15
  take: { description: 'Fetch the reference and question together.',
16
- usage: 'After the Harness gives you the user’s answer.', sideEffect: 'read', outputSchema: record },
16
+ usage: 'After the Harness supplies the preset or answered release channel.', sideEffect: 'read', outputSchema: record },
17
17
  },
18
18
  };
19
19
 
@@ -1,108 +1,140 @@
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, type Harness } from '@anyswarm/core';
4
+ import { createRuntime, createSandbox, projectConfiguration, ProjectPreflightError, runInput, ServiceRegistry,
5
+ type CloseReceipt, type Harness, type HarnessJson } from '@anyswarm/core';
6
+ import type { FirstHarnessConfiguration } from './config.js';
5
7
  import { createHandoff } from './handoff.js';
6
8
 
7
- type Configuration = typeof import('./config.js').default & { channel?: string };
9
+ const channelPattern = /^[a-z][a-z0-9-]{0,23}$/;
10
+ const json = (value: unknown): HarnessJson => JSON.parse(JSON.stringify(value));
11
+ const failed = (code: string, message: string) => Object.assign(new Error(message), { code });
8
12
 
9
13
  const firstHarness = {
10
14
  id: 'first-harness', apiVersion: 1, questions: true,
11
15
  async run(context) {
12
- const config = (context.configuration ?? (await import('./config.js')).default) as Configuration;
13
- if (!context.clientCapabilities.questions && !/^[a-z][a-z0-9-]{0,23}$/.test(config.channel ?? '')) {
14
- throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Set ANYSWARM_FIRST_CHANNEL for noninteractive execution');
16
+ const config = await projectConfiguration<FirstHarnessConfiguration>(context, () => import('./config.js'));
17
+ const presetChannel = config.channel ?? 'preview';
18
+ if (!context.clientCapabilities.questions && !channelPattern.test(presetChannel)) {
19
+ 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).');
15
20
  }
21
+ if (!config.models || typeof config.models !== 'object' || Array.isArray(config.models) || typeof config.model !== 'string') {
22
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Provide a models map and select one of its aliases with model.');
23
+ }
24
+ const model = config.models[config.model];
25
+ const protocol = model?.protocol && typeof model.protocol === 'object' ? model.protocol.clientProtocol : model?.protocol ?? 'responses';
26
+ const executor = typeof config.executor === 'string' ? config.executor : config.executor?.kind;
27
+ if (!Object.hasOwn(config.models, config.model) || !model || model.protocol === null ||
28
+ (executor === 'codex' && protocol !== 'responses') ||
29
+ (executor === 'pi' && protocol !== 'responses' && protocol !== 'chat-completions')) {
30
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Select a configured model alias. Codex requires the Responses protocol; Pi also supports Chat Completions.');
31
+ }
32
+
16
33
  const reference = randomBytes(6).toString('hex');
17
34
  const handoff = createHandoff();
18
35
  const services = new ServiceRegistry();
19
36
  services.register('handoff', handoff.service, { toolMode: 'cli' });
20
- const runtime = await createRuntime({
21
- sandbox: createSandbox(config.sandbox), connection: config.connection, executor: config.executor, models: config.models,
22
- services, maxAgents: 2, outputDir: context.outputDir,
23
- profiles: {
24
- publisher: {
25
- model: config.model, image: config.image, writable: false, services: { handoff: ['publish'] },
26
- 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.',
27
- },
28
- writer: {
29
- model: config.model, image: config.image, services: { handoff: ['take'] }, writable: true,
30
- 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.',
31
- },
32
- },
33
- });
34
37
  const turn = { signal: context.signal, timeoutMs: 120_000 };
35
- let phase = 'publish';
38
+ let phase = 'starting';
36
39
  let writerId: string | undefined;
37
40
  let channel: string | undefined;
38
41
  let expected: Buffer | undefined;
39
- let failure: { stage: string; code: string } | undefined;
40
- let cleanup: Awaited<ReturnType<typeof runtime.close>> | undefined;
42
+ let closed: CloseReceipt | undefined;
41
43
  let unobserve: (() => void) | undefined;
42
44
 
45
+ let outcome;
43
46
  try {
44
- unobserve = context.registerAgentControls({ runtime });
45
- context.markRunning();
46
- const publisher = await runtime.spawn({
47
- requestId: 'spawn-publisher', profile: 'publisher',
48
- files: { ...context.initial.files, 'release-data.txt': { encoding: 'utf8', data: `${reference}\n` } },
49
- });
50
- await runInput(runtime, publisher.id, [
51
- context.input.prompt,
52
- 'Read the reference in release-data.txt.',
53
- 'Publish the real reference with --reference=<reference> and --question=<quoted text> or use JSON on stdin.',
54
- 'Use request ID publish-release. Finish when the handoff succeeds.',
55
- ].join(' '), { ...turn, requestId: 'publisher-turn' });
56
- const note = handoff.evidence().note;
57
- if (note?.reference !== reference || note.author !== publisher.id) throw Object.assign(new Error(), { code: 'HANDOFF_NOT_VERIFIED' });
47
+ outcome = await context.runWithRuntime({
48
+ createRuntime: () => createRuntime({
49
+ sandbox: createSandbox(config.sandbox), connection: config.connection, executor: config.executor, models: config.models,
50
+ services, maxAgents: 2, outputDir: context.outputDir,
51
+ profiles: {
52
+ publisher: {
53
+ model: config.model, image: config.image, writable: false, services: { handoff: ['publish'] },
54
+ 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.',
55
+ },
56
+ writer: {
57
+ model: config.model, image: config.image, services: { handoff: ['take'] }, writable: true,
58
+ 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.',
59
+ },
60
+ },
61
+ }),
62
+ async run(runtime) {
63
+ unobserve = context.registerAgentControls({ runtime });
64
+ context.markRunning();
65
+ phase = 'publish';
66
+ const publisher = await runtime.spawn({
67
+ requestId: 'spawn-publisher', profile: 'publisher',
68
+ files: { ...context.initial.files, 'release-data.txt': { encoding: 'utf8', data: `${reference}\n` } },
69
+ });
70
+ await runInput(runtime, publisher.id, [
71
+ context.input.prompt,
72
+ 'Read the reference in release-data.txt.',
73
+ 'Publish the real reference with --reference=<reference> and --question=<quoted text> or use JSON on stdin.',
74
+ 'Use request ID publish-release. Finish when the handoff succeeds.',
75
+ ].join(' '), { ...turn, requestId: 'publisher-turn' });
76
+ const note = handoff.evidence().note;
77
+ if (note?.reference !== reference || note.author !== publisher.id) {
78
+ throw failed('HANDOFF_NOT_VERIFIED', 'The authenticated publisher did not hand off its sandbox reference.');
79
+ }
58
80
 
59
- phase = 'channel';
60
- const answer = context.clientCapabilities.questions
61
- ? await context.askUser({ requestId: 'release-channel', kind: 'text', text: note.question, agentId: publisher.id, timeoutMs: 120_000 },
62
- { id: 'release-handoff', agentId: publisher.id, signal: context.signal })
63
- : config.channel;
64
- channel = typeof answer === 'string' ? answer.trim() : undefined;
65
- if (!channel || !/^[a-z][a-z0-9-]{0,23}$/.test(channel)) throw Object.assign(new Error(), { code: 'INVALID_CHANNEL' });
81
+ phase = 'channel';
82
+ const answer = context.clientCapabilities.questions
83
+ ? await context.askUser({ requestId: 'release-channel', kind: 'text', text: note.question, agentId: publisher.id, timeoutMs: 120_000 },
84
+ { id: 'release-handoff', agentId: publisher.id, signal: context.signal })
85
+ : presetChannel;
86
+ channel = typeof answer === 'string' ? answer.trim() : undefined;
87
+ if (!channel || !channelPattern.test(channel)) throw failed('INVALID_CHANNEL', 'The release channel must start with a lowercase letter and contain at most 24 lowercase letters, digits or hyphens.');
66
88
 
67
- phase = 'write';
68
- const writer = await runtime.spawn({
69
- requestId: 'spawn-writer', profile: 'writer', files: context.initial.files,
70
- collect: { paths: ['delivery.txt'], maxBytes: 4096, includeGit: false, required: true },
71
- });
72
- writerId = writer.id;
73
- await runInput(runtime, writer.id, `The user chose channel ${channel}. Run the following exact command with the bash tool in your workspace:
89
+ phase = 'write';
90
+ const writer = await runtime.spawn({
91
+ requestId: 'spawn-writer', profile: 'writer', files: context.initial.files,
92
+ collect: { paths: ['delivery.txt'], maxBytes: 4096, includeGit: false, required: true },
93
+ });
94
+ writerId = writer.id;
95
+ await runInput(runtime, writer.id, `The user chose channel ${channel}. Run the following exact command with your command execution tool in your workspace:
74
96
  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
75
97
  Finish when the command succeeds.`, { ...turn, requestId: 'writer-turn' });
76
- if (handoff.evidence().read?.reader !== writer.id) throw Object.assign(new Error(), { code: 'HANDOFF_NOT_READ' });
98
+ if (handoff.evidence().read?.reader !== writer.id) throw failed('HANDOFF_NOT_READ', 'The authenticated writer did not read the published handoff.');
77
99
 
78
- phase = 'verify';
79
- expected = Buffer.from(`reference=${reference}\nchannel=${channel}\n`);
80
- const snapshot = await runtime.files.snapshot(writer.id, { requestId: 'verify-delivery', paths: ['delivery.txt'], maxBytes: 4096 });
81
- const file = snapshot.files['delivery.txt'];
82
- if (!file || !Buffer.from(file.data, file.encoding).equals(expected)) throw Object.assign(new Error(), { code: 'DELIVERY_BYTES_MISMATCH' });
83
- } catch (error) {
84
- failure = { stage: phase, code: (error as { code?: string }).code ?? 'HANDOFF_FAILED' };
85
- } finally {
86
- try { cleanup = await runtime.close({ timeoutMs: 60_000 }); }
87
- finally { unobserve?.(); }
88
- }
100
+ phase = 'verify-sandbox';
101
+ expected = Buffer.from(`reference=${reference}\nchannel=${channel}\n`);
102
+ const snapshot = await runtime.files.snapshot(writer.id, { requestId: 'verify-delivery', paths: ['delivery.txt'], maxBytes: 4096 });
103
+ const file = snapshot.files['delivery.txt'];
104
+ if (!file || !Buffer.from(file.data, file.encoding).equals(expected)) {
105
+ throw failed('DELIVERY_BYTES_MISMATCH', 'The sandbox delivery does not match the published reference and chosen channel.');
106
+ }
107
+ phase = 'export';
108
+ return { sandboxBytesVerified: true };
109
+ },
110
+ // Capture ownership evidence only. Business verification below must not
111
+ // throw from afterClose, whose errors are classified as cleanup failures.
112
+ afterClose(receipt) { closed = receipt; },
113
+ closeTimeoutMs: 60_000,
114
+ detail: () => ({ phase }),
115
+ });
116
+ } finally { unobserve?.(); }
89
117
 
90
- const directory = cleanup?.agents.find(agent => agent.agentId === writerId)?.artifacts.find(path => path.endsWith('/artifacts/files'));
118
+ const writerReceipt = closed?.agents.find(agent => agent.agentId === writerId);
119
+ const directory = writerReceipt?.artifacts.find(path => path.endsWith('/artifacts/files'));
91
120
  const delivery = directory ? join(directory, 'delivery.txt') : undefined;
92
121
  const bytes = delivery ? await readFile(delivery).catch(() => undefined) : undefined;
93
- const verification = delivery && bytes && expected && bytes.equals(expected)
122
+ const pending = outcome.export?.status === 'pending' || (writerId !== undefined && closed === undefined);
123
+ const verification = outcome.outcome === 'completed' && delivery && bytes && expected && bytes.equals(expected)
94
124
  ? { file: delivery, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex') } : undefined;
125
+ const wrongBytes = bytes && expected && !bytes.equals(expected);
126
+ const verificationFailure = outcome.outcome === 'completed' && !verification && (wrongBytes || !pending)
127
+ ? { stage: 'verify-export', code: bytes ? 'EXPORTED_BYTES_MISMATCH' : 'DELIVERY_EXPORT_MISSING' } : undefined;
95
128
  const { note, read } = handoff.evidence();
96
- const exportPending = cleanup?.pending?.some(resource => resource.action === 'collect-artifacts');
97
129
  return {
98
- outcome: context.signal.aborted ? 'cancelled' : failure ? 'failed' : 'completed',
99
- reason: failure?.code ?? (context.signal.aborted ? 'stopped' : 'release-handoff'),
100
- result: { runtimeId: runtime.id, failure: failure ?? null, handoff: { author: note?.author ?? null,
101
- publishRequestId: note?.requestId ?? null, read: read ?? null, channel: channel ?? null } },
130
+ ...outcome,
131
+ ...(verificationFailure ? { outcome: 'failed' as const, reason: verificationFailure.code } : {}),
132
+ result: { ...(outcome.result as Record<string, HarnessJson>), verificationFailure: verificationFailure ?? null,
133
+ handoff: { author: note?.author ?? null, publishRequestId: note?.requestId ?? null, read: read ?? null, channel: channel ?? null } },
102
134
  acceptance: verification ? { status: 'verified', ...verification } : { status: 'unverified' },
103
- artifacts: verification ? [{ path: verification.file, sha256: verification.sha256 }] : [],
104
- ...(writerId ? { export: { status: verification ? 'complete' : exportPending ? 'pending' : 'failed' } } : {}),
105
- cleanup: { status: cleanup?.cleanup ?? 'pending', pending: cleanup?.pending?.map(({ id, kind, action }) => ({ id, kind, action })) ?? null },
135
+ artifacts: [...outcome.artifacts, ...(verification ? [{ path: verification.file, sha256: verification.sha256 }] : [])],
136
+ ...(writerId ? { export: { status: pending ? 'pending' as const : bytes ? 'complete' as const : 'failed' as const,
137
+ receipt: json(writerReceipt ?? null) } } : {}),
106
138
  };
107
139
  },
108
140
  } satisfies Harness;
@@ -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.
@@ -7,7 +7,8 @@ import firstHarness from './harness.js';
7
7
 
8
8
  const rpc = process.argv[2] === '--rpc';
9
9
  const [cwd = process.cwd(), prompt = 'Prepare a release handoff.'] = process.argv.slice(rpc ? 3 : 2);
10
- const file = fileURLToPath(new URL('./harness.js', import.meta.url));
10
+ // The source export runs .ts directly; compiled package tests use its .js peer.
11
+ const file = fileURLToPath(new URL(new URL(import.meta.url).pathname.endsWith('.ts') ? './harness.ts' : './harness.js', import.meta.url));
11
12
  const child = rpc ? spawn('anyswarm', ['--harness', file, '--mode', 'rpc', '--interaction', 'questions'],
12
13
  { stdio: ['pipe', 'pipe', 'inherit'] }) : undefined;
13
14
  const session = child ? new HarnessRpcClient(child) : createHarnessSession(firstHarness, { clientCapabilities: { questions: true } });
@@ -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"],
@@ -11,13 +11,13 @@ outside the checkout. Copy the example from that SDK.
11
11
 
12
12
  ```sh
13
13
  npm init -y
14
- npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
14
+ npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.2}"
15
15
  sdk=node_modules/@anyswarm/core
16
16
  cp -R "$sdk"/examples/harness-session demo
17
17
  cd demo
18
- ../node_modules/.bin/anys run ./sdk.ts /absolute/path/to/project 'Run the direct SDK example'
19
- ../node_modules/.bin/anys run ./rpc.ts /absolute/path/to/project 'Run the RPC example'
20
- ../node_modules/.bin/anys run ./terminal.ts /absolute/path/to/project 'Ask me the two business questions'
18
+ ../node_modules/.bin/anyswarm run ./sdk.ts /absolute/path/to/project 'Run the direct SDK example'
19
+ ../node_modules/.bin/anyswarm run ./rpc.ts /absolute/path/to/project 'Run the RPC example'
20
+ ../node_modules/.bin/anyswarm run ./terminal.ts /absolute/path/to/project 'Ask me the two business questions'
21
21
  ```
22
22
 
23
23
  The SDK and RPC programs answer both questions and send a subsequent input
@@ -46,7 +46,7 @@ repository sources.
46
46
 
47
47
  ```sh
48
48
  npm init -y
49
- npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
49
+ npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.2}"
50
50
  npm install --save-dev typescript @types/node
51
51
  sdk=node_modules/@anyswarm/core
52
52
  cp -R "$sdk"/examples/lead-worker demo
@@ -42,7 +42,7 @@ example sources from the SDK you installed.
42
42
 
43
43
  ```sh
44
44
  npm init -y
45
- npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
45
+ npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.2}"
46
46
  npm install --save-dev typescript @types/node
47
47
  cp -R node_modules/@anyswarm/core/examples/messages demo
48
48
  cd demo
@@ -116,7 +116,7 @@ The external Service remains running after the Harness closes.
116
116
 
117
117
  [`project.ts`](project.ts) consumes the user's directory and prompt.
118
118
  [`handoff.ts`](handoff.ts) is a separate fixed-payload diagnostic, invoked from
119
- the checkout root with `anys run ./examples/messages/handoff.ts`. It seeds a
119
+ the built checkout root with `node dist/scripts/anyswarm.js run ./examples/messages/handoff.ts`. It seeds a
120
120
  value in the writer's files, then compares the reader's exported `received.txt`
121
121
  byte for byte. Its report goes under `handoff-runs/` unless `ANYSWARM_SDK_OUTPUT`
122
122
  overrides it. The common project runner has its own input and report handling.
@@ -32,7 +32,7 @@ This example requires Node.js 22.19 or newer, an authenticated OpenSandbox servi
32
32
 
33
33
  ```sh
34
34
  npm init -y
35
- npm install --omit=dev --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
35
+ npm install --omit=dev --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.2}"
36
36
  example=node_modules/@anyswarm/core/examples/notes
37
37
  ```
38
38
 
@@ -41,11 +41,11 @@ Set `ANYSWARM_NOTES_IMAGE` to your compatible worker image ID and `ANYSWARM_NOTE
41
41
  The sample uses Pi and the configured common model route by default (`openai` / `gpt-5.4` when model labels are omitted). Common `ANYSWARM_MODEL_*` and `ANYSWARM_EXECUTOR` variables take precedence over scoped Notes variables. To run Codex, set `ANYSWARM_NOTES_EXECUTOR=codex` and `ANYSWARM_NOTES_MODEL_ID` to the model served by your endpoint. `ANYSWARM_NOTES_MODEL_PROVIDER` labels the model and defaults to `openai` for Codex. For a custom configuration module, set `executor` and its `models` mapping. The same Reader thread handles both reader inputs. See the [backend guide](../../docs/architecture/16-pi-opensandbox-backend.md#codex-app-server) for the credential and trace contract.
42
42
 
43
43
  ```sh
44
- node_modules/.bin/anys run "$example/main.ts" --help
45
- node_modules/.bin/anys run "$example/main.ts" "$example/config.ts" > notes-result.json
44
+ node_modules/.bin/anyswarm run "$example/main.ts" --help
45
+ node_modules/.bin/anyswarm run "$example/main.ts" "$example/config.ts" > notes-result.json
46
46
  ```
47
47
 
48
- `main.ts` imports Runtime, Service Registry and the configurable OpenSandbox backend from the public package exports. `run-input.ts`, `run-report.ts` and `read-result.ts` are editable host modules. The Harness owns the turn order, the Notes manifest and adapter, the role grants and verification. It uses `followUp` on an idle Agent after subscribing, with one input source and a fresh ID. An unknown or queued submission remains explicit and sends no replacement.
48
+ `main.ts` imports Runtime, Service Registry, the configurable OpenSandbox backend, `runInput`, `runWithReport` and `readHarnessResult` from the public package exports. Turn order and business checks live in `main.ts`; the editable Service manifest and adapter live in `notes.ts`. Input/report/result helpers belong to the SDK rather than adjacent copied modules. The Harness uses `followUp` on an idle Agent after subscribing, with one input source and a fresh ID. An unknown or queued submission remains explicit and sends no replacement.
49
49
 
50
50
  ## Run and inspect the handoff
51
51
 
@@ -56,7 +56,7 @@ Read the final CLI report from `notes-result.json`. It contains the Runtime iden
56
56
  ```sh
57
57
  runtime_id=$(node -e 'const fs=require("node:fs"); console.log(JSON.parse(fs.readFileSync("notes-result.json","utf8")).runtimeId)')
58
58
  run_dir=$(node -e 'const fs=require("node:fs"),path=require("node:path"); console.log(path.dirname(JSON.parse(fs.readFileSync("notes-result.json","utf8")).reportPath))')
59
- node_modules/.bin/anys run "$example/main.ts" --result "$run_dir" --runtime-id "$runtime_id"
59
+ node_modules/.bin/anyswarm run "$example/main.ts" --result "$run_dir" --runtime-id "$runtime_id"
60
60
  ```
61
61
 
62
62
  Result inspection reads `harness-report.json` and `runtime.json`, checks both recorded identities, and projects business failure, recorded Core status, per-Agent execution/cleanup, pending count and artifact availability. It reports the Harness result's location without printing its content or interpreting business acceptance. Open the indicated Harness report's `result.verifiedFiles` and reader archive to inspect the actual checked deliverables. A pending receipt remains pending even if another recorded receipt later reports complete. This command reads saved files and does not contact or control a running Runtime.