@anyswarm/core 0.5.2 → 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 +19 -4
- package/README.md +68 -61
- package/dist/examples/README.md +134 -84
- package/dist/examples/autoresearch/README.md +106 -21
- package/dist/examples/autoresearch/REQUIREMENTS.zh.md +14 -6
- 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/frontiercs2-config.d.ts +2 -2
- package/dist/examples/autoresearch/frontiercs2-config.js +13 -2
- package/dist/examples/autoresearch/frontiercs2.d.ts +18 -1
- package/dist/examples/autoresearch/frontiercs2.js +71 -14
- package/dist/examples/autoresearch/prepare-demo.js +34 -3
- 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 -1
- package/dist/examples/autoresearch/project.js +130 -26
- package/dist/examples/autoresearch/research-service.d.ts +16 -1
- package/dist/examples/autoresearch/research-service.js +84 -44
- 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 +1 -1
- 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 +2 -2
- 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 +1 -1
- 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 +8 -15
- 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/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-progress.js +36 -5
- 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 +3 -3
- package/dist/scripts/local-environment.js +6 -1
- package/dist/scripts/local-setup.js +25 -18
- package/dist/scripts/pack-release.js +27 -3
- 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/harness/project-harness.js +3 -2
- package/dist/src/harness/project-rpc-client.js +19 -0
- 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 +9 -8
- package/docs/architecture/06-observability-experiments.md +21 -7
- package/docs/architecture/07-run-configuration.md +97 -12
- 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 +129 -86
- 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 +78 -0
- package/docs/architecture/22-website.md +53 -18
- package/docs/architecture/23-project-harness.md +63 -16
- package/docs/architecture/28-autoresearch.md +16 -22
- 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 +78 -54
- package/docs/architecture/source-map.json +396 -36
- package/docs/designs/core-harness/06-project-harness.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 +22 -1
- package/docs/en/first-harness.md +40 -32
- package/docs/en/harnesses/index.md +23 -23
- package/docs/en/harnesses/subagents.md +8 -29
- package/docs/en/latest.md +26 -5
- package/docs/en/overview.md +22 -22
- package/docs/en/quickstart.md +55 -21
- package/docs/en/reference/api.md +1 -1
- package/docs/en/trace-viewer.md +32 -12
- package/docs/operations/trace-viewer.md +25 -10
- package/docs/workflows/development.md +160 -120
- package/docs/workflows/release-and-docs-versioning.md +207 -55
- package/docs/workflows/release-cli-acceptance.md +124 -47
- 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 +22 -1
- package/docs/zh/first-harness.md +43 -35
- package/docs/zh/harnesses/index.md +23 -23
- package/docs/zh/harnesses/subagents.md +8 -29
- package/docs/zh/latest.md +26 -5
- package/docs/zh/overview.md +23 -23
- package/docs/zh/quickstart.md +51 -21
- package/docs/zh/reference/api.md +1 -1
- package/docs/zh/trace-viewer.md +32 -12
- package/examples/README.md +134 -84
- package/examples/autoresearch/README.md +106 -21
- package/examples/autoresearch/REQUIREMENTS.zh.md +14 -6
- package/examples/autoresearch/config.ts +64 -25
- package/examples/autoresearch/demo.ts +75 -22
- package/examples/autoresearch/frontiercs2-config.ts +13 -2
- package/examples/autoresearch/frontiercs2.ts +64 -11
- package/examples/autoresearch/prepare-demo.ts +32 -3
- package/examples/autoresearch/prepare.ts +134 -60
- package/examples/autoresearch/project.ts +119 -26
- package/examples/autoresearch/research-service.ts +91 -41
- 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 +1 -1
- package/examples/lead-worker/README.md +1 -1
- package/examples/messages/README.md +2 -2
- package/examples/notes/README.md +2 -2
- 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 +1 -1
- package/examples/subagents/AGENTS.md +35 -0
- package/examples/subagents/README.md +129 -93
- package/examples/subagents/config.ts +8 -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/taskpool/README.md +1 -1
- package/npm-shrinkwrap.development.json +9 -2
- package/npm-shrinkwrap.json +9 -2
- package/package.development.json +2 -1
- package/package.json +2 -1
- package/scripts/anyswarm-progress.ts +36 -6
- package/scripts/generate-architecture-coverage.ts +1 -1
- package/scripts/generate-architecture-prompts.ts +21 -10
- package/scripts/local-environment.ts +8 -1
- package/scripts/local-setup.ts +22 -17
- package/scripts/pack-release.ts +24 -3
- 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/harness/project-harness.ts +3 -2
- package/src/harness/project-rpc-client.ts +23 -0
- 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
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Parallel repository investigation
|
|
2
|
+
|
|
3
|
+
Ask a concrete question about a local repository and export an engineering
|
|
4
|
+
handoff or change-impact report. Three researchers inspect private copies of the
|
|
5
|
+
same captured input, publish source references to an in-process Board, and review
|
|
6
|
+
one another's findings. A fourth Agent integrates their work into `report.md`.
|
|
7
|
+
|
|
8
|
+
The complete collaboration policy is in `harness.ts`. The example uses public
|
|
9
|
+
`@anyswarm/core` APIs, one Runtime, and the same Harness definition for the CLI,
|
|
10
|
+
SDK and JSONL RPC. It has no mid-run questions or external business Services.
|
|
11
|
+
|
|
12
|
+
## Run your own repository question
|
|
13
|
+
|
|
14
|
+
Use AnySwarm 0.6.0 or a matching source build to export this example.
|
|
15
|
+
Prepare its Worker and OpenSandbox connection with `anyswarm setup`. You also
|
|
16
|
+
need a model endpoint reachable from the host and credentials for that endpoint;
|
|
17
|
+
setup's Sandbox selection does not configure your model account.
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
anyswarm eject parallel-swarm --dir ./my-swarm
|
|
21
|
+
cd ./my-swarm
|
|
22
|
+
npm install
|
|
23
|
+
|
|
24
|
+
export ANYSWARM_MODEL_URL='https://your-provider.example/v1/responses'
|
|
25
|
+
export ANYSWARM_MODEL_ID='your-model'
|
|
26
|
+
# If required by your provider, set ANYSWARM_MODEL_TOKEN in your environment.
|
|
27
|
+
|
|
28
|
+
npm start -- \
|
|
29
|
+
--cwd /absolute/path/to/your-project \
|
|
30
|
+
--prompt 'Prepare an engineering handoff for this repository: identify the relevant entry points, configuration, main data flow and existing tests. Cite source paths and line numbers. Separate established facts from inferences and checks still needed.' \
|
|
31
|
+
--output-dir /absolute/path/to/runs
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Replace the question with your actual concern, for example: “We plan to change
|
|
35
|
+
how configuration is loaded; which modules and existing tests are involved, and
|
|
36
|
+
what still needs to be checked?” No Git diff or known repository defect is needed.
|
|
37
|
+
From this source directory the equivalent entry is
|
|
38
|
+
`anyswarm run ./harness.ts --cwd /absolute/path/to/your-project --prompt '…'`.
|
|
39
|
+
The exported package's `npm start` runs that same editable source.
|
|
40
|
+
|
|
41
|
+
Use `anyswarm trace --root /absolute/path/to/runs --open` to inspect the Run.
|
|
42
|
+
The final result's `artifacts` entry with `kind: "report"` names the actual
|
|
43
|
+
Markdown file. `result.detail.board` contains the findings, authenticated author
|
|
44
|
+
IDs, rounds, citations and checked source excerpts. The Runtime also exports the
|
|
45
|
+
Board's Service state. The original close receipt remains in `cleanup.receipt`.
|
|
46
|
+
|
|
47
|
+
Each Agent receives the captured project files selected by the SDK's file policy.
|
|
48
|
+
The host does not copy changes back to your repository. Researchers cannot write
|
|
49
|
+
their copies. The synthesizer can write its private copy and only `report.md` is
|
|
50
|
+
requested for collection. Changes made to your local project after input capture
|
|
51
|
+
are not part of this Run.
|
|
52
|
+
|
|
53
|
+
## Configuration and budgets
|
|
54
|
+
|
|
55
|
+
`harness.ts` uses `context.configuration` when supplied, including a CLI
|
|
56
|
+
`--config ./my-config.ts` module. That object is the complete configuration;
|
|
57
|
+
otherwise the Harness loads its own visible `config.ts`. It does not depend on a
|
|
58
|
+
configuration file from another example.
|
|
59
|
+
|
|
60
|
+
The default configuration resolves the saved setup connection and executor for
|
|
61
|
+
the selected endpoint. Common `ANYSWARM_*` model/executor variables override
|
|
62
|
+
`ANYSWARM_PARALLEL_SWARM_*` variables; the saved executor is the next fallback,
|
|
63
|
+
then Pi. Worker image and Sandbox connection overrides use the SDK's
|
|
64
|
+
`resolveSandboxConnection({}, 'PARALLEL_SWARM')` rules. A configured or saved
|
|
65
|
+
image is preserved; otherwise `workerImageFor(executor)` selects it.
|
|
66
|
+
|
|
67
|
+
| Setting | Default behavior |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `ANYSWARM_MODEL_URL` | Required model endpoint; scoped fallback is `ANYSWARM_PARALLEL_SWARM_MODEL_URL`. |
|
|
70
|
+
| `ANYSWARM_MODEL_ID`, `ANYSWARM_MODEL_PROVIDER` | Pi defaults to `gpt-5-mini` / `openai`; choose a model your provider supports. Codex requires an explicit model ID. |
|
|
71
|
+
| `ANYSWARM_MODEL_TOKEN` | Optional bearer token; keep it in the environment. |
|
|
72
|
+
| `ANYSWARM_EXECUTOR` | `pi` or `codex`; otherwise inherit setup's executor. |
|
|
73
|
+
| `ANYSWARM_MODEL_PROTOCOL` | `responses`; Pi also accepts `chat-completions`. Codex requires Responses. |
|
|
74
|
+
| `ANYSWARM_CONTEXT_WINDOW` | Optional explicit model context limit, at least 2,048 tokens. |
|
|
75
|
+
| `model`, `models` in a config module | Select a model alias and its complete public SDK model configuration. |
|
|
76
|
+
| `turnTimeoutMs`, `closeTimeoutMs` | 120 seconds for each owned Agent input and 60 seconds for close/reconciliation. All waits must be finite positive integers. |
|
|
77
|
+
|
|
78
|
+
When `ANYSWARM_CONTEXT_WINDOW` supplies capabilities for a custom model, the
|
|
79
|
+
default profile declares `reasoning: false`. If your Responses endpoint returns
|
|
80
|
+
reasoning items, set `models.default.capabilities.reasoning` to `true` in the
|
|
81
|
+
exported `config.ts` or in the full configuration you pass with `--config`.
|
|
82
|
+
Keep the context window and output limit appropriate for the selected model.
|
|
83
|
+
Otherwise the gateway can return `unsupported_responses_request` when the
|
|
84
|
+
executor includes a reasoning item in a subsequent request.
|
|
85
|
+
|
|
86
|
+
The example retains three researchers, two rounds, one synthesizer and a maximum
|
|
87
|
+
of four live Agents. Pi's default output cap is 2,048 tokens per model response;
|
|
88
|
+
Codex preserves executor output parameters. These bounds are configuration,
|
|
89
|
+
not a runtime or cost promise. Adjust the visible config to suit the question
|
|
90
|
+
and your authorized provider budget.
|
|
91
|
+
|
|
92
|
+
## What the host checks
|
|
93
|
+
|
|
94
|
+
1. Each of the three researchers publishes at least one first-round finding.
|
|
95
|
+
2. Every finding includes 1–8 source references. Each reference has a relative
|
|
96
|
+
`path`, 1-based `startLine` / `endLine`, and exact `excerpt` from the captured
|
|
97
|
+
input. Ranges contain 1–40 lines, excerpts are nonblank and at most 4,096 bytes,
|
|
98
|
+
and the final line separator is omitted. CRLF is normalized to LF for checking.
|
|
99
|
+
3. Each researcher publishes a new second-round review citing a first-round
|
|
100
|
+
finding by another author. The host assigns the round; clients cannot submit
|
|
101
|
+
an author or round override. Unknown citations and self-only reviews fail.
|
|
102
|
+
4. The synthesizer's required `report.md` is exported, readable as UTF-8 and
|
|
103
|
+
nonblank, within the 1 MiB collection limit. If the input already contained
|
|
104
|
+
`report.md`, an unchanged copy does not pass this export check.
|
|
105
|
+
|
|
106
|
+
`acceptance.status: "verified"` applies only to the listed collaboration and
|
|
107
|
+
export checks; `acceptance.semanticCorrectness` remains `"not-run"`. Source
|
|
108
|
+
locations matching the input do not prove that an excerpt supports a conclusion,
|
|
109
|
+
that reviews are useful, or that a report is complete. The host does not execute
|
|
110
|
+
project tests or validate Markdown citations against the Board. Read the report
|
|
111
|
+
and its evidence before using its recommendations.
|
|
112
|
+
|
|
113
|
+
Incomplete contributions stop the workflow before synthesis. Invalid evidence
|
|
114
|
+
is rejected by the Board without publication. A confirmed bad report is a
|
|
115
|
+
business verification failure, separate from resource cleanup. Unconfirmed
|
|
116
|
+
collection stays `export.status: "pending"` and retains the SDK receipt; it is
|
|
117
|
+
not reported as a confirmed missing file. Cleanup can remain pending even when
|
|
118
|
+
the report has already been exported and checked. Cancellation and Runtime
|
|
119
|
+
initialization errors retain the existing Harness result classification.
|
|
120
|
+
|
|
121
|
+
## Source and validation
|
|
122
|
+
|
|
123
|
+
| File | What to change |
|
|
124
|
+
| --- | --- |
|
|
125
|
+
| `harness.ts` | Research focus, prompts, rounds, Profiles, input handling and completion checks. |
|
|
126
|
+
| `config.ts` | Connections, executor/model selection, time limits and file policy. |
|
|
127
|
+
| `board.ts` | Source evidence checks, contribution accounting and review rules. |
|
|
128
|
+
| `board-service.ts` | Public Service schemas and authenticated caller mapping. |
|
|
129
|
+
| `report.ts` | Export verification, independently of close/cleanup classification. |
|
|
130
|
+
| `AGENTS.md` | Guidance for a Coding Agent editing this exported Harness. |
|
|
131
|
+
|
|
132
|
+
Repository tests exercise the Board and report failure cases, and run the real
|
|
133
|
+
HarnessSession/Runtime/Service Bridge with a controlled local transport. They
|
|
134
|
+
establish contract behavior, not model quality or compatibility with a particular
|
|
135
|
+
live model. A new paid model or Docker-based run is not implied by these tests;
|
|
136
|
+
record real-run evidence separately with its SDK, model, input and limitations.
|
|
@@ -4,18 +4,34 @@ import {
|
|
|
4
4
|
type ServiceRegistration,
|
|
5
5
|
serviceFromManifest,
|
|
6
6
|
} from '@anyswarm/core';
|
|
7
|
-
import { FindingsBoard } from './board.js';
|
|
7
|
+
import { FindingsBoard, type SourceReference } from './board.js';
|
|
8
|
+
|
|
9
|
+
const EVIDENCE_SCHEMA = {
|
|
10
|
+
type: 'array', minItems: 1, maxItems: 8,
|
|
11
|
+
items: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
path: { type: 'string', minLength: 1 },
|
|
15
|
+
startLine: { type: 'integer', minimum: 1 },
|
|
16
|
+
endLine: { type: 'integer', minimum: 1 },
|
|
17
|
+
excerpt: { type: 'string', minLength: 1, maxLength: 4096 },
|
|
18
|
+
},
|
|
19
|
+
required: ['path', 'startLine', 'endLine', 'excerpt'], additionalProperties: false,
|
|
20
|
+
},
|
|
21
|
+
} as const;
|
|
8
22
|
|
|
9
23
|
const FINDING_SCHEMA = {
|
|
10
24
|
type: 'object',
|
|
11
25
|
properties: {
|
|
12
26
|
id: { type: 'integer' },
|
|
13
27
|
authorId: { type: 'string' },
|
|
28
|
+
round: { type: 'string', enum: ['research', 'review'] },
|
|
14
29
|
topic: { type: 'string' },
|
|
15
30
|
summary: { type: 'string' },
|
|
31
|
+
evidence: EVIDENCE_SCHEMA,
|
|
16
32
|
cites: { type: 'array', items: { type: 'integer' } },
|
|
17
33
|
},
|
|
18
|
-
required: ['id', 'authorId', 'topic', 'summary', 'cites'],
|
|
34
|
+
required: ['id', 'authorId', 'round', 'topic', 'summary', 'evidence', 'cites'],
|
|
19
35
|
additionalProperties: false,
|
|
20
36
|
} as const;
|
|
21
37
|
|
|
@@ -26,25 +42,27 @@ export function createBoardRegistration(board: FindingsBoard): ServiceRegistrati
|
|
|
26
42
|
id: 'board',
|
|
27
43
|
title: 'Shared Research Board',
|
|
28
44
|
purpose: 'Publish, search, and cite findings across parallel swarm researchers.',
|
|
29
|
-
provider_version: '
|
|
45
|
+
provider_version: '2.0.0',
|
|
30
46
|
endpoint: { transport: 'in-process' },
|
|
31
47
|
capabilities: [
|
|
32
48
|
{
|
|
33
49
|
name: 'publish',
|
|
34
50
|
operation: 'publish',
|
|
35
|
-
description: 'Publish a
|
|
51
|
+
description: 'Publish a finding with exact source references. During review, cite another researcher\'s first-round finding. Source locations are checked; conclusions are not.',
|
|
36
52
|
side_effect: 'write',
|
|
37
53
|
idempotent: false,
|
|
38
54
|
help: { when: 'After discovering or cross-checking a concrete fact' },
|
|
39
|
-
errors: [
|
|
55
|
+
errors: ['NOT_FOUND', 'INVALID_EVIDENCE', 'INVALID_FINDING', 'REVIEW_REQUIRED', 'BOARD_CLOSED', 'NOT_RESEARCHER']
|
|
56
|
+
.map(code => ({ code, retryable: false })),
|
|
40
57
|
input_schema: {
|
|
41
58
|
type: 'object',
|
|
42
59
|
properties: {
|
|
43
60
|
topic: { type: 'string', minLength: 1, maxLength: 120 },
|
|
44
61
|
summary: { type: 'string', minLength: 1, maxLength: 2000 },
|
|
45
|
-
|
|
62
|
+
evidence: EVIDENCE_SCHEMA,
|
|
63
|
+
cites: { type: 'array', items: { type: 'integer', minimum: 1 }, maxItems: 8, uniqueItems: true },
|
|
46
64
|
},
|
|
47
|
-
required: ['topic', 'summary'],
|
|
65
|
+
required: ['topic', 'summary', 'evidence'],
|
|
48
66
|
additionalProperties: false,
|
|
49
67
|
},
|
|
50
68
|
output_schema: FINDING_SCHEMA,
|
|
@@ -75,12 +93,13 @@ export function createBoardRegistration(board: FindingsBoard): ServiceRegistrati
|
|
|
75
93
|
invoke({ capability, input, caller, assertAuthorized }): JsonValue {
|
|
76
94
|
if (capability.operation === 'publish') {
|
|
77
95
|
assertAuthorized();
|
|
78
|
-
const { topic, summary, cites } = input as {
|
|
96
|
+
const { topic, summary, evidence, cites } = input as unknown as {
|
|
79
97
|
topic: string;
|
|
80
98
|
summary: string;
|
|
99
|
+
evidence: SourceReference[];
|
|
81
100
|
cites?: number[];
|
|
82
101
|
};
|
|
83
|
-
return board.publish(caller.agentId, topic, summary, cites) as unknown as JsonValue;
|
|
102
|
+
return board.publish(caller.agentId, topic, summary, evidence, cites) as unknown as JsonValue;
|
|
84
103
|
}
|
|
85
104
|
const { query } = input as { query?: string };
|
|
86
105
|
return { entries: board.search(query) } as unknown as JsonValue;
|
|
@@ -1,35 +1,129 @@
|
|
|
1
|
+
import type { FileTree } from '@anyswarm/core';
|
|
2
|
+
|
|
3
|
+
export interface SourceReference {
|
|
4
|
+
path: string;
|
|
5
|
+
startLine: number;
|
|
6
|
+
endLine: number;
|
|
7
|
+
excerpt: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
export interface Finding {
|
|
2
11
|
id: number;
|
|
3
12
|
authorId: string;
|
|
13
|
+
round: 'research' | 'review';
|
|
4
14
|
topic: string;
|
|
5
15
|
summary: string;
|
|
16
|
+
evidence: SourceReference[];
|
|
6
17
|
cites: number[];
|
|
7
18
|
}
|
|
8
19
|
|
|
20
|
+
function reject(code: string, message: string): never {
|
|
21
|
+
throw Object.assign(new Error(message), { code });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Checks locations and exact excerpts, not whether they support a conclusion. */
|
|
25
|
+
export function verifySourceReference(files: FileTree, reference: SourceReference): SourceReference {
|
|
26
|
+
const { path, startLine, endLine, excerpt } = reference;
|
|
27
|
+
if (typeof path !== 'string' || !path || /[\\\0]/.test(path) || /^[A-Za-z]:/.test(path) ||
|
|
28
|
+
path.split('/').some(part => !part || part === '.' || part === '..') || !Object.hasOwn(files, path)) {
|
|
29
|
+
reject('INVALID_EVIDENCE', 'Evidence must name a relative file in this Run\'s input snapshot');
|
|
30
|
+
}
|
|
31
|
+
if (!Number.isSafeInteger(startLine) || !Number.isSafeInteger(endLine) || startLine < 1 || endLine < startLine ||
|
|
32
|
+
endLine - startLine >= 40 || typeof excerpt !== 'string' || !excerpt.trim() || Buffer.byteLength(excerpt) > 4096) {
|
|
33
|
+
reject('INVALID_EVIDENCE', 'Evidence requires 1–40 source lines and an exact, nonblank excerpt of at most 4096 bytes');
|
|
34
|
+
}
|
|
35
|
+
const entry = files[path];
|
|
36
|
+
let text: string;
|
|
37
|
+
try {
|
|
38
|
+
const bytes = Buffer.from(entry.data, entry.encoding === 'base64' ? 'base64' : 'utf8');
|
|
39
|
+
text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes).replaceAll('\r\n', '\n');
|
|
40
|
+
} catch {
|
|
41
|
+
reject('INVALID_EVIDENCE', 'Evidence must refer to a UTF-8 source file');
|
|
42
|
+
}
|
|
43
|
+
const lines = text.split('\n');
|
|
44
|
+
if (lines.at(-1) === '') lines.pop();
|
|
45
|
+
const normalized = excerpt.replaceAll('\r\n', '\n');
|
|
46
|
+
if (endLine > lines.length || normalized !== lines.slice(startLine - 1, endLine).join('\n')) {
|
|
47
|
+
reject('INVALID_EVIDENCE', 'The line range and excerpt do not match the captured source');
|
|
48
|
+
}
|
|
49
|
+
return { path, startLine, endLine, excerpt: normalized };
|
|
50
|
+
}
|
|
51
|
+
|
|
9
52
|
export class FindingsBoard {
|
|
10
53
|
private entries: Finding[] = [];
|
|
54
|
+
private researchers: string[] = [];
|
|
55
|
+
private round: 'waiting' | 'research' | 'review' | 'closed' = 'waiting';
|
|
56
|
+
|
|
57
|
+
constructor(private readonly files: FileTree) {}
|
|
58
|
+
|
|
59
|
+
beginResearch(researchers: readonly string[]) {
|
|
60
|
+
if (this.round !== 'waiting' || researchers.length < 2 || new Set(researchers).size !== researchers.length ||
|
|
61
|
+
researchers.some(id => typeof id !== 'string' || !id)) {
|
|
62
|
+
reject('INVALID_ROUND', 'Start one research round with distinct researcher identities');
|
|
63
|
+
}
|
|
64
|
+
this.researchers = [...researchers];
|
|
65
|
+
this.round = 'research';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
beginReview() {
|
|
69
|
+
if (this.round !== 'research') reject('INVALID_ROUND', 'The review round must follow research');
|
|
70
|
+
this.requireContributions('research');
|
|
71
|
+
this.round = 'review';
|
|
72
|
+
}
|
|
11
73
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
74
|
+
finishReview() {
|
|
75
|
+
if (this.round !== 'review') reject('INVALID_ROUND', 'Finish the review round before synthesis');
|
|
76
|
+
this.requireContributions('review');
|
|
77
|
+
this.round = 'closed';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private requireContributions(round: 'research' | 'review') {
|
|
81
|
+
const missing = this.researchers.filter(id => !this.entries.some(entry => entry.authorId === id && entry.round === round));
|
|
82
|
+
if (missing.length) reject(round === 'research' ? 'RESEARCH_INCOMPLETE' : 'REVIEW_INCOMPLETE',
|
|
83
|
+
`Missing ${round} contribution from ${missing.join(', ')}`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
publish(authorId: string, topic: string, summary: string, evidence: readonly SourceReference[], cites: readonly number[] = []): Finding {
|
|
87
|
+
if (this.round !== 'research' && this.round !== 'review') reject('BOARD_CLOSED', 'The Board is not accepting publications');
|
|
88
|
+
if (!this.researchers.includes(authorId)) reject('NOT_RESEARCHER', 'Only this Run\'s researchers may publish');
|
|
89
|
+
if (typeof topic !== 'string' || !topic.trim() || topic.length > 120 ||
|
|
90
|
+
typeof summary !== 'string' || !summary.trim() || summary.length > 2000) {
|
|
91
|
+
reject('INVALID_FINDING', 'Provide a topic and a concise summary');
|
|
92
|
+
}
|
|
93
|
+
if (!Array.isArray(evidence) || evidence.length < 1 || evidence.length > 8) {
|
|
94
|
+
reject('INVALID_EVIDENCE', 'Each finding needs 1–8 source references');
|
|
95
|
+
}
|
|
96
|
+
const checked = evidence.map(reference => verifySourceReference(this.files, reference));
|
|
97
|
+
if (!Array.isArray(cites) || cites.length > 8 || new Set(cites).size !== cites.length) {
|
|
98
|
+
reject('NOT_FOUND', 'Citations must name at most eight distinct existing findings');
|
|
19
99
|
}
|
|
20
|
-
const
|
|
100
|
+
const cited = cites.map(id => {
|
|
101
|
+
const entry = this.entries.find(entry => entry.id === id);
|
|
102
|
+
if (!entry) reject('NOT_FOUND', `Referenced finding #${id} does not exist`);
|
|
103
|
+
return entry;
|
|
104
|
+
});
|
|
105
|
+
if (this.round === 'review' && !cited.some(entry => entry.authorId !== authorId && entry.round === 'research')) {
|
|
106
|
+
reject('REVIEW_REQUIRED', 'A review must cite another researcher\'s first-round finding');
|
|
107
|
+
}
|
|
108
|
+
const entry: Finding = { id: this.entries.length + 1, authorId, round: this.round, topic, summary,
|
|
109
|
+
evidence: checked, cites: [...cites] };
|
|
21
110
|
this.entries.push(entry);
|
|
22
|
-
return entry;
|
|
111
|
+
return structuredClone(entry);
|
|
23
112
|
}
|
|
24
113
|
|
|
25
114
|
search(query = ''): Finding[] {
|
|
26
115
|
const q = query.trim().toLowerCase();
|
|
27
|
-
return q
|
|
28
|
-
|
|
29
|
-
|
|
116
|
+
return structuredClone(q ? this.entries.filter(entry => `${entry.topic} ${entry.summary}`.toLowerCase().includes(q)) : this.entries);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
contributions() {
|
|
120
|
+
return this.researchers.map(authorId => ({ authorId,
|
|
121
|
+
research: this.entries.filter(entry => entry.authorId === authorId && entry.round === 'research').length,
|
|
122
|
+
review: this.entries.filter(entry => entry.authorId === authorId && entry.round === 'review').length,
|
|
123
|
+
}));
|
|
30
124
|
}
|
|
31
125
|
|
|
32
126
|
exportState() {
|
|
33
|
-
return { total: this.entries.length,
|
|
127
|
+
return { round: this.round, total: this.entries.length, contributions: this.contributions(), entries: this.search() };
|
|
34
128
|
}
|
|
35
129
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ProjectPreflightError, resolveSandboxConnection, workerImageFor,
|
|
2
|
+
type CreateRuntimeOptions, type SandboxConfig } from '@anyswarm/core';
|
|
3
|
+
|
|
4
|
+
export interface ParallelSwarmConfig extends Pick<CreateRuntimeOptions, 'executor' | 'connection' | 'models' | 'filePolicy'> {
|
|
5
|
+
sandbox: SandboxConfig;
|
|
6
|
+
image: string;
|
|
7
|
+
model?: string;
|
|
8
|
+
turnTimeoutMs?: number;
|
|
9
|
+
closeTimeoutMs?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function invalid(message: string): never {
|
|
13
|
+
throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', message);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function parallelSwarmConfig(): ParallelSwarmConfig {
|
|
17
|
+
const env = process.env;
|
|
18
|
+
const setting = (key: string) => env[`ANYSWARM_${key}`] ?? env[`ANYSWARM_PARALLEL_SWARM_${key}`];
|
|
19
|
+
const { image, advertiseHost, publicUrl, endpointSource: _source, executor: setupExecutor, ...sandbox } =
|
|
20
|
+
resolveSandboxConnection({}, 'PARALLEL_SWARM');
|
|
21
|
+
const executor = setting('EXECUTOR') ?? setupExecutor ?? 'pi';
|
|
22
|
+
if (executor !== 'pi' && executor !== 'codex') invalid('Select pi or codex with ANYSWARM_EXECUTOR.');
|
|
23
|
+
const url = setting('MODEL_URL');
|
|
24
|
+
if (!url) invalid('Set ANYSWARM_MODEL_URL to your model endpoint before running Parallel Swarm.');
|
|
25
|
+
const protocol = setting('MODEL_PROTOCOL') ?? 'responses';
|
|
26
|
+
if (protocol !== 'responses' && protocol !== 'chat-completions') invalid('Select responses or chat-completions with ANYSWARM_MODEL_PROTOCOL.');
|
|
27
|
+
if (executor === 'codex' && protocol !== 'responses') invalid('The Codex executor requires a Responses model endpoint.');
|
|
28
|
+
const model = setting('MODEL_ID') ?? (executor === 'pi' ? 'gpt-5-mini' : undefined);
|
|
29
|
+
if (!model) invalid('Set ANYSWARM_MODEL_ID to a model supported by the selected Codex executor.');
|
|
30
|
+
const token = setting('MODEL_TOKEN');
|
|
31
|
+
const contextWindow = setting('CONTEXT_WINDOW') === undefined ? undefined : Number(setting('CONTEXT_WINDOW'));
|
|
32
|
+
if (contextWindow !== undefined && (!Number.isSafeInteger(contextWindow) || contextWindow < 2048)) {
|
|
33
|
+
invalid('ANYSWARM_CONTEXT_WINDOW must be the model context limit, at least 2048 tokens.');
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
sandbox, executor, image: image ?? workerImageFor(executor), model: 'default',
|
|
37
|
+
turnTimeoutMs: 120_000, closeTimeoutMs: 60_000,
|
|
38
|
+
connection: { advertiseHost, publicUrl, modelGateway: { maxOutputTokens: executor === 'codex' ? null : 2048 } },
|
|
39
|
+
models: { default: {
|
|
40
|
+
provider: setting('MODEL_PROVIDER') ?? 'openai', model, protocol,
|
|
41
|
+
...(contextWindow ? { capabilities: { contextWindow, maxOutputTokens: 2048, tools: true, reasoning: false } } : {}),
|
|
42
|
+
upstream: { url, headers: token ? { authorization: `Bearer ${token}` } : {} },
|
|
43
|
+
} },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default parallelSwarmConfig();
|
|
@@ -1,89 +1,101 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { readFile } from 'node:fs/promises';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
1
|
import {
|
|
5
|
-
createRuntime, createSandbox,
|
|
6
|
-
|
|
2
|
+
createRuntime, createSandbox, projectConfiguration, ProjectPreflightError, runInput, ServiceRegistry,
|
|
3
|
+
type Harness,
|
|
7
4
|
} from '@anyswarm/core';
|
|
8
5
|
import { FindingsBoard } from './board.js';
|
|
9
6
|
import { boardService } from './board-service.js';
|
|
7
|
+
import type { ParallelSwarmConfig } from './config.js';
|
|
8
|
+
import { checkReportExport, type ReportCheck } from './report.js';
|
|
10
9
|
|
|
11
|
-
const researcherPrompt = '
|
|
12
|
-
const synthesizerPrompt = 'Use swarm service invoke board search to read the
|
|
13
|
-
const
|
|
14
|
-
const
|
|
10
|
+
const researcherPrompt = 'Investigate the user\'s question in the captured local repository. Publish concrete findings with swarm service invoke board publish. Each finding needs evidence: relative path, 1-based startLine/endLine, and an exact short excerpt (1–40 lines, at most 4096 bytes; omit the final newline). Distinguish facts, inferences and unverified questions in the summary. Do not modify source files or invent a defect. Read peer findings with swarm service invoke board search.';
|
|
11
|
+
const synthesizerPrompt = 'Use swarm service invoke board search to read the research and reviews. Answer the user\'s question in report.md: give conclusions, relative source paths and line numbers, finding IDs, disagreements and unverified items. Separate facts from inference. The host checks the Board\'s source locations and the report export; it does not establish that your conclusions are correct. Do not modify other project files.';
|
|
12
|
+
const researchFocuses = ['Entry points, configuration and how to run the relevant behavior.', 'Core modules, data flow and dependencies relevant to the question.', 'Existing tests, observable guarantees and checks still needed.'];
|
|
13
|
+
const reviewInput = 'Read the other researchers\' first-round findings. Check their source evidence and publish at least one NEW follow-up addressing a gap, disagreement or corroboration relevant to the user\'s question. Include your own exact source evidence and cite at least one first-round finding by ANOTHER author in cites. A first-round publication does not count as this review.';
|
|
14
|
+
const synthesisInput = 'Read the Board, integrate the research and cross-author reviews, and write report.md for the task below. Cite source paths, line numbers and finding IDs; mark anything not verified.';
|
|
15
15
|
|
|
16
16
|
const parallelSwarm = {
|
|
17
17
|
id: 'parallel-swarm', apiVersion: 1,
|
|
18
18
|
async run(context) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const config = await projectConfiguration<ParallelSwarmConfig>(context, () => import('./config.js'));
|
|
20
|
+
const { image, model = 'default', turnTimeoutMs = 120_000, closeTimeoutMs = 60_000 } = config;
|
|
21
|
+
if (!image || ![turnTimeoutMs, closeTimeoutMs].every(ms => Number.isSafeInteger(ms) && ms > 0 && ms <= 2_147_483_647)) {
|
|
22
|
+
throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Parallel Swarm needs an image and finite positive turn/close time limits.');
|
|
23
|
+
}
|
|
24
|
+
const board = new FindingsBoard(context.initial.files);
|
|
22
25
|
const services = new ServiceRegistry();
|
|
23
26
|
services.register('board', boardService(board), { toolMode: 'cli' });
|
|
24
|
-
const { image: configuredImage, advertiseHost, publicUrl, executor: setupExecutor, endpointSource: _source, ...sandbox } = resolveSandboxConnection();
|
|
25
|
-
const executor = process.env.ANYSWARM_EXECUTOR ?? setupExecutor ?? 'pi';
|
|
26
|
-
if (executor !== undefined && executor !== 'pi' && executor !== 'codex') throw new Error('Select pi or codex with ANYSWARM_EXECUTOR.');
|
|
27
|
-
const image = configuredImage ?? workerImageFor(executor);
|
|
28
|
-
const token = process.env.ANYSWARM_MODEL_TOKEN;
|
|
29
|
-
const runtime = await createRuntime({
|
|
30
|
-
sandbox: createSandbox(sandbox), connection: { advertiseHost, publicUrl }, executor, services, maxAgents: 4, outputDir: context.outputDir,
|
|
31
|
-
models: { default: {
|
|
32
|
-
provider: process.env.ANYSWARM_MODEL_PROVIDER ?? 'openai',
|
|
33
|
-
model: process.env.ANYSWARM_MODEL_ID ?? 'gpt-5-mini',
|
|
34
|
-
upstream: { url, headers: token ? { authorization: `Bearer ${token}` } : {} },
|
|
35
|
-
} },
|
|
36
|
-
profiles: {
|
|
37
|
-
researcher: { addedSystemPrompt: researcherPrompt, model: 'default', image, writable: false,
|
|
38
|
-
services: { board: ['publish', 'search'] } },
|
|
39
|
-
synthesizer: { addedSystemPrompt: synthesizerPrompt, model: 'default', image, writable: true,
|
|
40
|
-
services: { board: ['search'] },
|
|
41
|
-
collect: { paths: ['report.md'], includeGit: false, maxBytes: 1_048_576, required: true } },
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
const turn = { signal: context.signal, timeoutMs: 120_000 };
|
|
45
|
-
let synthId: string | undefined;
|
|
46
|
-
let failure: string | undefined;
|
|
47
|
-
let cleanup: Awaited<ReturnType<typeof runtime.close>> | undefined;
|
|
48
27
|
let unobserve: (() => void) | undefined;
|
|
28
|
+
let synthId: string | undefined;
|
|
29
|
+
let researchChecked = false;
|
|
30
|
+
let reviewChecked = false;
|
|
31
|
+
const checks: { report: ReportCheck; finalized?: ReportCheck } = {
|
|
32
|
+
report: { status: 'not-run', reason: 'SYNTHESIZER_NOT_STARTED' },
|
|
33
|
+
};
|
|
49
34
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
35
|
+
const result = await context.runWithRuntime({
|
|
36
|
+
closeTimeoutMs,
|
|
37
|
+
createRuntime: () => createRuntime({
|
|
38
|
+
sandbox: createSandbox(config.sandbox), connection: config.connection, executor: config.executor,
|
|
39
|
+
models: config.models, filePolicy: config.filePolicy, services, maxAgents: 4, outputDir: context.outputDir,
|
|
40
|
+
profiles: {
|
|
41
|
+
researcher: { addedSystemPrompt: researcherPrompt, model, image, writable: false,
|
|
42
|
+
services: { board: ['publish', 'search'] } },
|
|
43
|
+
synthesizer: { addedSystemPrompt: synthesizerPrompt, model, image, writable: true,
|
|
44
|
+
services: { board: ['search'] },
|
|
45
|
+
collect: { paths: ['report.md'], includeGit: false, maxBytes: 1_048_576, required: true } },
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
async run(runtime) {
|
|
49
|
+
unobserve = context.registerAgentControls({ runtime });
|
|
50
|
+
context.markRunning();
|
|
51
|
+
const turn = { signal: context.signal, timeoutMs: turnTimeoutMs };
|
|
52
|
+
context.signal.throwIfAborted();
|
|
53
|
+
const peers = await Promise.all(researchFocuses.map((_, index) =>
|
|
54
|
+
runtime.spawn({ requestId: `spawn-r${index + 1}`, profile: 'researcher', files: context.initial.files })));
|
|
55
|
+
board.beginResearch(peers.map(peer => peer.id));
|
|
56
|
+
await Promise.all(peers.map((peer, index) => runInput(runtime, peer.id,
|
|
57
|
+
`${context.input.prompt}\n\nYour focus: ${researchFocuses[index]}\nPublish at least one source-backed finding.`,
|
|
58
|
+
{ ...turn, requestId: `research-${index + 1}` })));
|
|
59
|
+
board.beginReview();
|
|
60
|
+
researchChecked = true;
|
|
61
|
+
await Promise.all(peers.map((peer, index) => runInput(runtime, peer.id, reviewInput,
|
|
62
|
+
{ ...turn, requestId: `review-${index + 1}` })));
|
|
63
|
+
board.finishReview();
|
|
64
|
+
reviewChecked = true;
|
|
65
|
+
await Promise.all(peers.map(peer => runtime.stop(peer.id, { timeoutMs: closeTimeoutMs })));
|
|
66
|
+
context.signal.throwIfAborted();
|
|
67
|
+
const synth = await runtime.spawn({ requestId: 'spawn-synthesizer', profile: 'synthesizer', files: context.initial.files });
|
|
68
|
+
synthId = synth.id;
|
|
69
|
+
checks.report = { status: 'pending', reason: 'REPORT_EXPORT_PENDING' };
|
|
70
|
+
await runInput(runtime, synth.id, `${synthesisInput}\n\n${context.input.prompt}`, { ...turn, requestId: 'synthesize' });
|
|
71
|
+
return { synthesizerId: synthId, contributions: board.contributions() };
|
|
72
|
+
},
|
|
73
|
+
// A failed report check is business evidence, not a thrown cleanup error.
|
|
74
|
+
afterClose: async receipt => { checks.report = await checkReportExport(receipt, synthId, context.initial.files); },
|
|
75
|
+
detail: () => {
|
|
76
|
+
// Keep the final projection stable if a post-close read outlives its wait.
|
|
77
|
+
checks.finalized = { ...checks.report };
|
|
78
|
+
return { board: board.exportState(), report: checks.finalized };
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const report = checks.finalized!;
|
|
82
|
+
const reportFailed = report.status === 'unverified';
|
|
83
|
+
return {
|
|
84
|
+
...result,
|
|
85
|
+
...(result.outcome === 'completed' && reportFailed ? { outcome: 'failed' as const, reason: report.reason } : {}),
|
|
86
|
+
acceptance: {
|
|
87
|
+
status: researchChecked && reviewChecked && report.status === 'verified' ? 'verified' : report.status === 'pending' ? 'pending' : 'unverified',
|
|
88
|
+
scope: 'participant-contributions, cross-author-reviews, Board-source-references, report-export',
|
|
89
|
+
research: researchChecked ? 'verified' : 'unverified', review: reviewChecked ? 'verified' : 'unverified',
|
|
90
|
+
sourceReferences: board.search().length ? 'verified' : 'not-run', report: { ...report }, semanticCorrectness: 'not-run',
|
|
91
|
+
},
|
|
92
|
+
artifacts: [...result.artifacts, ...(report.status === 'verified' ? [{ agentId: synthId!, kind: 'report', ...report }] : [])],
|
|
93
|
+
...(synthId ? { export: { ...result.export, status: result.export?.status === 'pending' || report.status === 'pending'
|
|
94
|
+
? 'pending' as const : report.status === 'verified' ? 'complete' as const : 'failed' as const } } : {}),
|
|
95
|
+
};
|
|
67
96
|
} finally {
|
|
68
|
-
|
|
69
|
-
finally { unobserve?.(); }
|
|
97
|
+
unobserve?.();
|
|
70
98
|
}
|
|
71
|
-
const directory = cleanup.agents.find(agent => agent.agentId === synthId)?.artifacts.find(path => path.endsWith('/artifacts/files'));
|
|
72
|
-
const file = directory && join(directory, 'report.md');
|
|
73
|
-
const bytes = file ? await readFile(file).catch(() => undefined) : undefined;
|
|
74
|
-
const artifact = file && bytes && bytes.toString('utf8').trim() ? {
|
|
75
|
-
path: file, sha256: createHash('sha256').update(bytes).digest('hex'),
|
|
76
|
-
} : undefined;
|
|
77
|
-
const findings = board.search();
|
|
78
|
-
return {
|
|
79
|
-
outcome: context.signal.aborted ? 'cancelled' : failure || !artifact ? 'failed' : 'completed',
|
|
80
|
-
reason: failure ?? (artifact ? 'report-verified' : 'report-missing'),
|
|
81
|
-
result: { runtimeId: runtime.id, findings: findings.length, citedFindings: findings.filter(finding => finding.cites.length > 0).length },
|
|
82
|
-
acceptance: { status: artifact ? 'verified' : 'unverified' },
|
|
83
|
-
artifacts: artifact ? [artifact] : [],
|
|
84
|
-
...(synthId ? { export: { status: artifact ? 'complete' : 'failed' } } : {}),
|
|
85
|
-
cleanup: { status: cleanup.cleanup, pending: cleanup.pending.map(({ id, kind, action }) => ({ id, kind, action })) },
|
|
86
|
-
};
|
|
87
99
|
},
|
|
88
100
|
} satisfies Harness;
|
|
89
101
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import type { CloseReceipt, FileTree } from '@anyswarm/core';
|
|
5
|
+
|
|
6
|
+
export type ReportCheck =
|
|
7
|
+
| { status: 'not-run' | 'pending' | 'unverified'; reason: string }
|
|
8
|
+
| { status: 'verified'; path: string; sha256: string; bytes: number };
|
|
9
|
+
|
|
10
|
+
/** A readable, newly written report is an export check, not a semantic review. */
|
|
11
|
+
export async function checkReportExport(receipt: CloseReceipt, agentId: string | undefined, initial: FileTree): Promise<ReportCheck> {
|
|
12
|
+
if (!agentId) return { status: 'not-run', reason: 'SYNTHESIZER_NOT_STARTED' };
|
|
13
|
+
const agent = receipt.agents.find(agent => agent.agentId === agentId);
|
|
14
|
+
const directory = agent?.artifacts.find(path => path.endsWith(join('artifacts', 'files')));
|
|
15
|
+
if (!directory) {
|
|
16
|
+
const pending = !agent || agent.execution !== 'stopped' || agent.cleanup === 'pending' ||
|
|
17
|
+
receipt.pending.some(entry => entry.kind === 'agent' && entry.id === agentId);
|
|
18
|
+
return { status: pending ? 'pending' : 'unverified', reason: pending ? 'REPORT_EXPORT_PENDING' : 'REPORT_MISSING' };
|
|
19
|
+
}
|
|
20
|
+
const path = join(directory, 'report.md');
|
|
21
|
+
try {
|
|
22
|
+
const bytes = await readFile(path);
|
|
23
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
24
|
+
if (!text.trim()) return { status: 'unverified', reason: 'REPORT_EMPTY' };
|
|
25
|
+
const before = initial['report.md'];
|
|
26
|
+
if (before && bytes.equals(Buffer.from(before.data, before.encoding === 'base64' ? 'base64' : 'utf8'))) {
|
|
27
|
+
return { status: 'unverified', reason: 'REPORT_UNCHANGED' };
|
|
28
|
+
}
|
|
29
|
+
return { status: 'verified', path, sha256: createHash('sha256').update(bytes).digest('hex'), bytes: bytes.length };
|
|
30
|
+
} catch {
|
|
31
|
+
return { status: 'unverified', reason: 'REPORT_UNREADABLE' };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -70,7 +70,7 @@ repository sources.
|
|
|
70
70
|
|
|
71
71
|
```sh
|
|
72
72
|
npm init -y
|
|
73
|
-
npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.
|
|
73
|
+
npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.2}"
|
|
74
74
|
npm install --save-dev typescript @types/node
|
|
75
75
|
sdk=node_modules/@anyswarm/core
|
|
76
76
|
cp -R "$sdk"/examples/peermesh demo
|