@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.
- package/AGENTS.md +20 -5
- package/README.md +69 -55
- package/dist/examples/README.md +138 -77
- package/dist/examples/authoring/README.md +4 -4
- package/dist/examples/autoresearch/README.md +108 -16
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
- package/dist/examples/autoresearch/config.d.ts +48 -5
- package/dist/examples/autoresearch/config.js +57 -23
- package/dist/examples/autoresearch/demo.d.ts +12 -4
- package/dist/examples/autoresearch/demo.js +65 -22
- package/dist/examples/autoresearch/eject.json +2 -0
- package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
- package/dist/examples/autoresearch/frontiercs2-config.js +14 -0
- package/dist/examples/autoresearch/frontiercs2.d.ts +18 -1
- package/dist/examples/autoresearch/frontiercs2.js +71 -14
- package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
- package/dist/examples/autoresearch/prepare-demo.js +46 -0
- package/dist/examples/autoresearch/prepare.d.ts +105 -53
- package/dist/examples/autoresearch/prepare.js +126 -57
- package/dist/examples/autoresearch/project.d.ts +6 -95
- package/dist/examples/autoresearch/project.js +131 -45
- package/dist/examples/autoresearch/research-service.d.ts +16 -1
- package/dist/examples/autoresearch/research-service.js +84 -44
- package/dist/examples/code/README.md +25 -17
- package/dist/examples/code/REQUIREMENTS.zh.md +3 -3
- package/dist/examples/code/config.d.ts +1 -0
- package/dist/examples/first-harness/AGENTS.md +25 -0
- package/dist/examples/first-harness/README.md +136 -0
- package/dist/examples/first-harness/config.d.ts +9 -8
- package/dist/examples/first-harness/config.js +33 -26
- package/dist/examples/first-harness/eject.json +14 -0
- package/dist/examples/first-harness/handoff.js +3 -3
- package/dist/examples/first-harness/harness.d.ts +14 -18
- package/dist/examples/first-harness/harness.js +102 -77
- package/dist/examples/first-harness/input/README.md +7 -0
- package/dist/examples/first-harness/session.js +2 -1
- package/dist/examples/first-harness/tsconfig.json +2 -1
- package/dist/examples/harness-session/README.md +4 -4
- package/dist/examples/lead-worker/README.md +1 -1
- package/dist/examples/lead-worker/project-config.d.ts +1 -0
- package/dist/examples/messages/README.md +2 -2
- package/dist/examples/notes/README.md +5 -5
- package/dist/examples/notes/config.d.ts +1 -0
- package/dist/examples/parallel-swarm/AGENTS.md +32 -0
- package/dist/examples/parallel-swarm/README.md +136 -0
- package/dist/examples/parallel-swarm/board-service.js +25 -8
- package/dist/examples/parallel-swarm/board.d.ts +31 -1
- package/dist/examples/parallel-swarm/board.js +98 -13
- package/dist/examples/parallel-swarm/config.d.ts +11 -0
- package/dist/examples/parallel-swarm/config.js +39 -0
- package/dist/examples/parallel-swarm/eject.json +5 -0
- package/dist/examples/parallel-swarm/harness.d.ts +26 -20
- package/dist/examples/parallel-swarm/harness.js +77 -76
- package/dist/examples/parallel-swarm/report.d.ts +12 -0
- package/dist/examples/parallel-swarm/report.js +30 -0
- package/dist/examples/peermesh/README.md +1 -1
- package/dist/examples/peermesh/project-config.d.ts +1 -0
- package/dist/examples/services/agent-control/README.md +1 -1
- package/dist/examples/services/mathlib-search/README.md +1 -1
- package/dist/examples/services/mcp-managed/README.md +1 -1
- package/dist/examples/services/persistent-board/README.md +6 -3
- package/dist/examples/subagents/AGENTS.md +35 -0
- package/dist/examples/subagents/README.md +129 -93
- package/dist/examples/subagents/config.d.ts +2 -10
- package/dist/examples/subagents/config.js +9 -16
- package/dist/examples/subagents/eject.json +17 -0
- package/dist/examples/subagents/handoff-config.d.ts +41 -0
- package/dist/examples/subagents/handoff-config.js +13 -0
- package/dist/examples/subagents/model.d.ts +3 -0
- package/dist/examples/subagents/model.js +19 -0
- package/dist/examples/substrate/README.md +12 -6
- package/dist/examples/substrate/config.d.ts +1 -0
- package/dist/examples/substrate/project-config.d.ts +1 -0
- package/dist/examples/super/README.md +34 -22
- package/dist/examples/super/actions.d.ts +1 -1
- package/dist/examples/super/actions.js +11 -11
- package/dist/examples/super/config.js +3 -3
- package/dist/examples/super/eject.json +1 -1
- package/dist/examples/super/location.js +1 -1
- package/dist/examples/super/operator.d.ts +1 -0
- package/dist/examples/super/operator.js +31 -0
- package/dist/examples/super/project.d.ts +0 -107
- package/dist/examples/super/project.js +1 -3
- package/dist/examples/taskpool/README.md +1 -1
- package/dist/examples/taskpool/config.d.ts +1 -0
- package/dist/examples/taskpool/deploy/service-hosts/service-authority-snapshot.d.ts +4 -4
- package/dist/scripts/anyswarm-arguments.d.ts +7 -25
- package/dist/scripts/anyswarm-arguments.js +69 -97
- package/dist/scripts/anyswarm-eject.js +1 -1
- package/dist/scripts/anyswarm-harnesses.d.ts +0 -1
- package/dist/scripts/anyswarm-harnesses.js +1 -22
- package/dist/scripts/anyswarm-installation.d.ts +7 -40
- package/dist/scripts/anyswarm-installation.js +17 -291
- package/dist/scripts/anyswarm-launch.d.ts +6 -36
- package/dist/scripts/anyswarm-launch.js +32 -81
- package/dist/scripts/anyswarm-progress.d.ts +6 -0
- package/dist/scripts/anyswarm-progress.js +133 -0
- package/dist/scripts/anyswarm-project.d.ts +1 -9
- package/dist/scripts/anyswarm-project.js +40 -127
- package/dist/scripts/anyswarm-source-runner.js +9 -41
- package/dist/scripts/anyswarm.js +6 -26
- package/dist/scripts/build-provenance.json +1 -1
- package/dist/scripts/generate-architecture-coverage.js +1 -1
- package/dist/scripts/generate-architecture-prompts.js +18 -10
- package/dist/scripts/local-environment.d.ts +13 -7
- package/dist/scripts/local-environment.js +73 -21
- package/dist/scripts/local-setup.d.ts +3 -0
- package/dist/scripts/local-setup.js +153 -118
- package/dist/scripts/pack-release.js +31 -4
- package/dist/src/core/index.js +1 -1
- package/dist/src/core/sandbox/opensandbox-backend.js +10 -4
- package/dist/src/core/sandbox/sandbox-connection.d.ts +9 -2
- package/dist/src/core/sandbox/sandbox-connection.js +22 -7
- package/dist/src/core/worker-image.js +1 -1
- package/dist/src/harness/project-harness.d.ts +1 -0
- package/dist/src/harness/project-harness.js +5 -4
- package/dist/src/harness/project-rpc-client.js +19 -0
- package/dist/src/harness/project-runtime.js +3 -1
- package/dist/src/harness/typescript-loader.d.ts +2 -0
- package/dist/src/harness/typescript-loader.js +26 -8
- package/dist/src/trace-viewer/command.mjs +6 -3
- package/dist/src/trace-viewer/public/app.js +239 -59
- package/dist/src/trace-viewer/public/index.html +5 -0
- package/dist/src/trace-viewer/public/style.css +22 -0
- package/dist/src/trace-viewer/reader.mjs +242 -26
- package/dist/src/trace-viewer/run-root.d.mts +1 -0
- package/dist/src/trace-viewer/run-root.mjs +7 -0
- package/dist/src/trace-viewer/server.mjs +3 -1
- package/docs/INDEX.md +11 -9
- package/docs/architecture/04-services.md +1 -1
- package/docs/architecture/06-observability-experiments.md +21 -7
- package/docs/architecture/07-run-configuration.md +118 -19
- package/docs/architecture/08-prompts.md +21 -2
- package/docs/architecture/10-service-api-reference.md +12 -5
- package/docs/architecture/12-code-coverage.md +157 -115
- package/docs/architecture/15-core-runtime.md +1 -1
- package/docs/architecture/16-pi-opensandbox-backend.md +2 -0
- package/docs/architecture/17-harness-reporting.md +79 -1
- package/docs/architecture/22-website.md +52 -20
- package/docs/architecture/23-project-harness.md +109 -37
- package/docs/architecture/26-code.md +20 -5
- package/docs/architecture/27-personal.md +23 -8
- package/docs/architecture/28-autoresearch.md +18 -12
- package/docs/architecture/INDEX.md +1 -2
- package/docs/architecture/prompts/11-first-sdk-harness.md +9 -9
- package/docs/architecture/prompts/16-parallel-swarm.md +46 -13
- package/docs/architecture/prompts/22-autoresearch.md +9 -2
- package/docs/architecture/prompts/source-manifest.json +76 -52
- package/docs/architecture/source-map.json +445 -105
- package/docs/designs/core-harness/01-core.md +2 -2
- package/docs/designs/core-harness/06-project-harness.md +3 -3
- package/docs/designs/core-harness/README.md +2 -2
- package/docs/en/agents.md +1 -1
- package/docs/en/autoresearch.md +41 -0
- package/docs/en/blog/100b-tokens.md +157 -0
- package/docs/en/build-your-harness.md +47 -22
- package/docs/en/changelog.md +29 -1
- package/docs/en/first-harness.md +40 -32
- package/docs/en/harnesses/index.md +23 -23
- package/docs/en/harnesses/lead-worker.md +1 -1
- package/docs/en/harnesses/peermesh.md +2 -2
- package/docs/en/harnesses/subagents.md +10 -31
- package/docs/en/harnesses/substrate.md +4 -4
- package/docs/en/harnesses/taskpool.md +2 -2
- package/docs/en/latest.md +30 -5
- package/docs/en/overview.md +22 -22
- package/docs/en/quickstart.md +69 -56
- package/docs/en/reference/api.md +1 -1
- package/docs/en/reference/cli.md +47 -85
- package/docs/en/sandbox.md +3 -3
- package/docs/en/trace-viewer.md +32 -12
- package/docs/operations/trace-viewer.md +26 -11
- package/docs/third-party-notices.md +0 -1
- package/docs/workflows/development.md +160 -118
- package/docs/workflows/release-and-docs-versioning.md +207 -54
- package/docs/workflows/release-cli-acceptance.md +162 -0
- package/docs/zh/agents.md +1 -1
- package/docs/zh/autoresearch.md +41 -0
- package/docs/zh/blog/100b-tokens.md +102 -0
- package/docs/zh/build-your-harness.md +48 -23
- package/docs/zh/changelog.md +29 -1
- package/docs/zh/first-harness.md +43 -35
- package/docs/zh/harnesses/index.md +23 -23
- package/docs/zh/harnesses/lead-worker.md +1 -1
- package/docs/zh/harnesses/peermesh.md +2 -2
- package/docs/zh/harnesses/subagents.md +10 -31
- package/docs/zh/harnesses/substrate.md +4 -4
- package/docs/zh/harnesses/taskpool.md +2 -2
- package/docs/zh/latest.md +30 -5
- package/docs/zh/overview.md +23 -23
- package/docs/zh/quickstart.md +66 -57
- package/docs/zh/reference/api.md +1 -1
- package/docs/zh/reference/cli.md +19 -79
- package/docs/zh/sandbox.md +3 -3
- package/docs/zh/trace-viewer.md +32 -12
- package/examples/README.md +138 -77
- package/examples/authoring/README.md +4 -4
- package/examples/autoresearch/README.md +108 -16
- package/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
- package/examples/autoresearch/config.ts +64 -25
- package/examples/autoresearch/demo.ts +75 -22
- package/examples/autoresearch/eject.json +2 -0
- package/examples/autoresearch/frontiercs2-config.ts +15 -0
- package/examples/autoresearch/frontiercs2.ts +64 -11
- package/examples/autoresearch/prepare-demo.ts +44 -0
- package/examples/autoresearch/prepare.ts +134 -60
- package/examples/autoresearch/project.ts +120 -44
- package/examples/autoresearch/research-service.ts +91 -41
- package/examples/code/README.md +25 -17
- package/examples/code/REQUIREMENTS.zh.md +3 -3
- package/examples/first-harness/AGENTS.md +25 -0
- package/examples/first-harness/README.md +136 -0
- package/examples/first-harness/config.ts +41 -27
- package/examples/first-harness/eject.json +14 -0
- package/examples/first-harness/handoff.ts +3 -3
- package/examples/first-harness/harness.ts +104 -72
- package/examples/first-harness/input/README.md +7 -0
- package/examples/first-harness/session.ts +2 -1
- package/examples/first-harness/tsconfig.json +2 -1
- package/examples/harness-session/README.md +4 -4
- package/examples/lead-worker/README.md +1 -1
- package/examples/messages/README.md +2 -2
- package/examples/notes/README.md +5 -5
- package/examples/parallel-swarm/AGENTS.md +32 -0
- package/examples/parallel-swarm/README.md +136 -0
- package/examples/parallel-swarm/board-service.ts +28 -9
- package/examples/parallel-swarm/board.ts +107 -13
- package/examples/parallel-swarm/config.ts +47 -0
- package/examples/parallel-swarm/eject.json +5 -0
- package/examples/parallel-swarm/harness.ts +83 -71
- package/examples/parallel-swarm/report.ts +33 -0
- package/examples/peermesh/README.md +1 -1
- package/examples/services/agent-control/README.md +1 -1
- package/examples/services/mathlib-search/README.md +1 -1
- package/examples/services/mcp-managed/README.md +1 -1
- package/examples/services/persistent-board/README.md +6 -3
- package/examples/subagents/AGENTS.md +35 -0
- package/examples/subagents/README.md +129 -93
- package/examples/subagents/config.ts +9 -15
- package/examples/subagents/eject.json +17 -0
- package/examples/subagents/handoff-config.ts +14 -0
- package/examples/subagents/model.ts +20 -0
- package/examples/substrate/README.md +12 -6
- package/examples/super/README.md +34 -22
- package/examples/super/actions.ts +11 -11
- package/examples/super/config.ts +3 -3
- package/examples/super/eject.json +1 -1
- package/examples/super/location.ts +1 -1
- package/examples/super/operator.ts +28 -0
- package/examples/super/project.ts +1 -3
- package/examples/taskpool/README.md +1 -1
- package/npm-shrinkwrap.development.json +46 -1538
- package/npm-shrinkwrap.json +10 -43
- package/package.development.json +3 -6
- package/package.json +3 -5
- package/scripts/anyswarm-arguments.ts +67 -96
- package/scripts/anyswarm-eject.ts +1 -1
- package/scripts/anyswarm-harnesses.ts +1 -18
- package/scripts/anyswarm-installation.ts +18 -294
- package/scripts/anyswarm-launch.ts +30 -102
- package/scripts/anyswarm-progress.ts +125 -0
- package/scripts/anyswarm-project.ts +31 -123
- package/scripts/anyswarm-source-runner.ts +9 -36
- package/scripts/anyswarm.ts +4 -24
- package/scripts/generate-architecture-coverage.ts +1 -1
- package/scripts/generate-architecture-prompts.ts +21 -10
- package/scripts/local-environment.ts +79 -21
- package/scripts/local-setup.ts +150 -105
- package/scripts/pack-release.ts +28 -4
- package/src/core/index.ts +1 -1
- package/src/core/sandbox/opensandbox-backend.ts +10 -4
- package/src/core/sandbox/sandbox-connection.ts +22 -7
- package/src/core/worker-image.ts +1 -1
- package/src/harness/project-harness.ts +5 -4
- package/src/harness/project-rpc-client.ts +23 -0
- package/src/harness/project-runtime.ts +2 -1
- package/src/harness/typescript-loader.ts +28 -8
- package/src/trace-viewer/command.mjs +6 -3
- package/src/trace-viewer/public/app.js +239 -59
- package/src/trace-viewer/public/index.html +5 -0
- package/src/trace-viewer/public/style.css +22 -0
- package/src/trace-viewer/reader.mjs +242 -26
- package/src/trace-viewer/run-root.d.mts +1 -0
- package/src/trace-viewer/run-root.mjs +7 -0
- package/src/trace-viewer/server.mjs +3 -1
- package/dist/scripts/anyswarm-applications.d.ts +0 -19
- package/dist/scripts/anyswarm-applications.js +0 -19
- package/dist/scripts/anyswarm-tui-config.d.ts +0 -36
- package/dist/scripts/anyswarm-tui-config.js +0 -189
- package/dist/scripts/anyswarm-tui-session.d.ts +0 -66
- package/dist/scripts/anyswarm-tui-session.js +0 -304
- package/dist/scripts/anyswarm-tui-terminal.d.ts +0 -41
- package/dist/scripts/anyswarm-tui-terminal.js +0 -154
- package/dist/scripts/anyswarm-tui.d.ts +0 -2
- package/dist/scripts/anyswarm-tui.js +0 -1012
- package/docs/architecture/25-foreground-tui.md +0 -51
- package/scripts/anyswarm-applications.ts +0 -39
- package/scripts/anyswarm-tui-config.ts +0 -174
- package/scripts/anyswarm-tui-session.ts +0 -295
- package/scripts/anyswarm-tui-terminal.ts +0 -147
- 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)
|
|
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
|
-
-
|
|
9
|
-
- `
|
|
8
|
+
- 多轮客户端可以请求中断当前轮,之后继续输入,也可停止整个会话并等待清理。单次运行在任务完成、清理确认后返回 0。会话收尾保留报告、检查结果、已写入的路径和 Trace。
|
|
9
|
+
- `anyswarm eject code` 导出完整 TS 应用。作者能在仓库外直接运行、修改并重新执行其副本。
|
|
10
10
|
|
|
11
11
|
验收使用同一个仓库外安装的候选包。用真实项目覆盖默认单 Agent 两轮编辑、用户明确要求并行委派、中断后继续、验证失败、并行成员控制、退出清理和导出源码。记录每轮文件上传下载字节数、实际容器数、峰值内存和最终检查结果。ProgramBench 使用同一 Code 应用,运行状态和官方评分单独记录。
|
|
@@ -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
|
|
2
|
-
|
|
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:
|
|
5
|
+
executor: ExecutorSelection;
|
|
6
6
|
image: string;
|
|
7
|
-
channel: string | undefined;
|
|
8
7
|
model: string;
|
|
9
|
-
models:
|
|
10
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const sandbox =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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();
|
|
@@ -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
|
|
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
|
|
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
|
|
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:
|
|
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
|
-
|
|
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
|
|
10
|
-
|
|
11
|
-
|
|
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 = '
|
|
33
|
+
let phase = 'starting';
|
|
33
34
|
let writerId;
|
|
34
35
|
let channel;
|
|
35
36
|
let expected;
|
|
36
|
-
let
|
|
37
|
-
let cleanup;
|
|
37
|
+
let closed;
|
|
38
38
|
let unobserve;
|
|
39
|
+
let outcome;
|
|
39
40
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
85
|
-
cleanup = await runtime.close({ timeoutMs: 60_000 });
|
|
86
|
-
}
|
|
87
|
-
finally {
|
|
88
|
-
unobserve?.();
|
|
89
|
-
}
|
|
110
|
+
unobserve?.();
|
|
90
111
|
}
|
|
91
|
-
const
|
|
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
|
|
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
|
|
100
|
-
|
|
101
|
-
result: {
|
|
102
|
-
|
|
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:
|
|
106
|
-
|
|
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
|
-
|
|
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 });
|