@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.
Files changed (210) hide show
  1. package/AGENTS.md +19 -4
  2. package/README.md +68 -61
  3. package/dist/examples/README.md +134 -84
  4. package/dist/examples/autoresearch/README.md +106 -21
  5. package/dist/examples/autoresearch/REQUIREMENTS.zh.md +14 -6
  6. package/dist/examples/autoresearch/config.d.ts +48 -5
  7. package/dist/examples/autoresearch/config.js +57 -23
  8. package/dist/examples/autoresearch/demo.d.ts +12 -4
  9. package/dist/examples/autoresearch/demo.js +65 -22
  10. package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -2
  11. package/dist/examples/autoresearch/frontiercs2-config.js +13 -2
  12. package/dist/examples/autoresearch/frontiercs2.d.ts +18 -1
  13. package/dist/examples/autoresearch/frontiercs2.js +71 -14
  14. package/dist/examples/autoresearch/prepare-demo.js +34 -3
  15. package/dist/examples/autoresearch/prepare.d.ts +105 -53
  16. package/dist/examples/autoresearch/prepare.js +126 -57
  17. package/dist/examples/autoresearch/project.d.ts +6 -1
  18. package/dist/examples/autoresearch/project.js +130 -26
  19. package/dist/examples/autoresearch/research-service.d.ts +16 -1
  20. package/dist/examples/autoresearch/research-service.js +84 -44
  21. package/dist/examples/code/config.d.ts +1 -0
  22. package/dist/examples/first-harness/AGENTS.md +25 -0
  23. package/dist/examples/first-harness/README.md +136 -0
  24. package/dist/examples/first-harness/config.d.ts +9 -8
  25. package/dist/examples/first-harness/config.js +33 -26
  26. package/dist/examples/first-harness/eject.json +14 -0
  27. package/dist/examples/first-harness/handoff.js +3 -3
  28. package/dist/examples/first-harness/harness.d.ts +14 -18
  29. package/dist/examples/first-harness/harness.js +102 -77
  30. package/dist/examples/first-harness/input/README.md +7 -0
  31. package/dist/examples/first-harness/session.js +2 -1
  32. package/dist/examples/first-harness/tsconfig.json +2 -1
  33. package/dist/examples/harness-session/README.md +1 -1
  34. package/dist/examples/lead-worker/README.md +1 -1
  35. package/dist/examples/lead-worker/project-config.d.ts +1 -0
  36. package/dist/examples/messages/README.md +2 -2
  37. package/dist/examples/notes/README.md +2 -2
  38. package/dist/examples/notes/config.d.ts +1 -0
  39. package/dist/examples/parallel-swarm/AGENTS.md +32 -0
  40. package/dist/examples/parallel-swarm/README.md +136 -0
  41. package/dist/examples/parallel-swarm/board-service.js +25 -8
  42. package/dist/examples/parallel-swarm/board.d.ts +31 -1
  43. package/dist/examples/parallel-swarm/board.js +98 -13
  44. package/dist/examples/parallel-swarm/config.d.ts +11 -0
  45. package/dist/examples/parallel-swarm/config.js +39 -0
  46. package/dist/examples/parallel-swarm/eject.json +5 -0
  47. package/dist/examples/parallel-swarm/harness.d.ts +26 -20
  48. package/dist/examples/parallel-swarm/harness.js +77 -76
  49. package/dist/examples/parallel-swarm/report.d.ts +12 -0
  50. package/dist/examples/parallel-swarm/report.js +30 -0
  51. package/dist/examples/peermesh/README.md +1 -1
  52. package/dist/examples/peermesh/project-config.d.ts +1 -0
  53. package/dist/examples/services/agent-control/README.md +1 -1
  54. package/dist/examples/services/mathlib-search/README.md +1 -1
  55. package/dist/examples/services/mcp-managed/README.md +1 -1
  56. package/dist/examples/services/persistent-board/README.md +1 -1
  57. package/dist/examples/subagents/AGENTS.md +35 -0
  58. package/dist/examples/subagents/README.md +129 -93
  59. package/dist/examples/subagents/config.d.ts +2 -10
  60. package/dist/examples/subagents/config.js +8 -15
  61. package/dist/examples/subagents/eject.json +17 -0
  62. package/dist/examples/subagents/handoff-config.d.ts +41 -0
  63. package/dist/examples/subagents/handoff-config.js +13 -0
  64. package/dist/examples/subagents/model.d.ts +3 -0
  65. package/dist/examples/subagents/model.js +19 -0
  66. package/dist/examples/substrate/README.md +12 -6
  67. package/dist/examples/substrate/config.d.ts +1 -0
  68. package/dist/examples/substrate/project-config.d.ts +1 -0
  69. package/dist/examples/taskpool/README.md +1 -1
  70. package/dist/examples/taskpool/config.d.ts +1 -0
  71. package/dist/examples/taskpool/deploy/service-hosts/service-authority-snapshot.d.ts +4 -4
  72. package/dist/scripts/anyswarm-progress.js +36 -5
  73. package/dist/scripts/build-provenance.json +1 -1
  74. package/dist/scripts/generate-architecture-coverage.js +1 -1
  75. package/dist/scripts/generate-architecture-prompts.js +18 -10
  76. package/dist/scripts/local-environment.d.ts +3 -3
  77. package/dist/scripts/local-environment.js +6 -1
  78. package/dist/scripts/local-setup.js +25 -18
  79. package/dist/scripts/pack-release.js +27 -3
  80. package/dist/src/core/index.js +1 -1
  81. package/dist/src/core/sandbox/opensandbox-backend.js +10 -4
  82. package/dist/src/core/sandbox/sandbox-connection.d.ts +9 -2
  83. package/dist/src/core/sandbox/sandbox-connection.js +22 -7
  84. package/dist/src/harness/project-harness.js +3 -2
  85. package/dist/src/harness/project-rpc-client.js +19 -0
  86. package/dist/src/harness/typescript-loader.d.ts +2 -0
  87. package/dist/src/harness/typescript-loader.js +26 -8
  88. package/dist/src/trace-viewer/command.mjs +6 -3
  89. package/dist/src/trace-viewer/public/app.js +239 -59
  90. package/dist/src/trace-viewer/public/index.html +5 -0
  91. package/dist/src/trace-viewer/public/style.css +22 -0
  92. package/dist/src/trace-viewer/reader.mjs +242 -26
  93. package/dist/src/trace-viewer/run-root.d.mts +1 -0
  94. package/dist/src/trace-viewer/run-root.mjs +7 -0
  95. package/dist/src/trace-viewer/server.mjs +3 -1
  96. package/docs/INDEX.md +9 -8
  97. package/docs/architecture/06-observability-experiments.md +21 -7
  98. package/docs/architecture/07-run-configuration.md +97 -12
  99. package/docs/architecture/08-prompts.md +21 -2
  100. package/docs/architecture/10-service-api-reference.md +12 -5
  101. package/docs/architecture/12-code-coverage.md +129 -86
  102. package/docs/architecture/15-core-runtime.md +1 -1
  103. package/docs/architecture/16-pi-opensandbox-backend.md +2 -0
  104. package/docs/architecture/17-harness-reporting.md +78 -0
  105. package/docs/architecture/22-website.md +53 -18
  106. package/docs/architecture/23-project-harness.md +63 -16
  107. package/docs/architecture/28-autoresearch.md +16 -22
  108. package/docs/architecture/prompts/11-first-sdk-harness.md +9 -9
  109. package/docs/architecture/prompts/16-parallel-swarm.md +46 -13
  110. package/docs/architecture/prompts/22-autoresearch.md +9 -2
  111. package/docs/architecture/prompts/source-manifest.json +78 -54
  112. package/docs/architecture/source-map.json +396 -36
  113. package/docs/designs/core-harness/06-project-harness.md +1 -1
  114. package/docs/en/autoresearch.md +41 -0
  115. package/docs/en/blog/100b-tokens.md +157 -0
  116. package/docs/en/build-your-harness.md +47 -22
  117. package/docs/en/changelog.md +22 -1
  118. package/docs/en/first-harness.md +40 -32
  119. package/docs/en/harnesses/index.md +23 -23
  120. package/docs/en/harnesses/subagents.md +8 -29
  121. package/docs/en/latest.md +26 -5
  122. package/docs/en/overview.md +22 -22
  123. package/docs/en/quickstart.md +55 -21
  124. package/docs/en/reference/api.md +1 -1
  125. package/docs/en/trace-viewer.md +32 -12
  126. package/docs/operations/trace-viewer.md +25 -10
  127. package/docs/workflows/development.md +160 -120
  128. package/docs/workflows/release-and-docs-versioning.md +207 -55
  129. package/docs/workflows/release-cli-acceptance.md +124 -47
  130. package/docs/zh/autoresearch.md +41 -0
  131. package/docs/zh/blog/100b-tokens.md +102 -0
  132. package/docs/zh/build-your-harness.md +48 -23
  133. package/docs/zh/changelog.md +22 -1
  134. package/docs/zh/first-harness.md +43 -35
  135. package/docs/zh/harnesses/index.md +23 -23
  136. package/docs/zh/harnesses/subagents.md +8 -29
  137. package/docs/zh/latest.md +26 -5
  138. package/docs/zh/overview.md +23 -23
  139. package/docs/zh/quickstart.md +51 -21
  140. package/docs/zh/reference/api.md +1 -1
  141. package/docs/zh/trace-viewer.md +32 -12
  142. package/examples/README.md +134 -84
  143. package/examples/autoresearch/README.md +106 -21
  144. package/examples/autoresearch/REQUIREMENTS.zh.md +14 -6
  145. package/examples/autoresearch/config.ts +64 -25
  146. package/examples/autoresearch/demo.ts +75 -22
  147. package/examples/autoresearch/frontiercs2-config.ts +13 -2
  148. package/examples/autoresearch/frontiercs2.ts +64 -11
  149. package/examples/autoresearch/prepare-demo.ts +32 -3
  150. package/examples/autoresearch/prepare.ts +134 -60
  151. package/examples/autoresearch/project.ts +119 -26
  152. package/examples/autoresearch/research-service.ts +91 -41
  153. package/examples/first-harness/AGENTS.md +25 -0
  154. package/examples/first-harness/README.md +136 -0
  155. package/examples/first-harness/config.ts +41 -27
  156. package/examples/first-harness/eject.json +14 -0
  157. package/examples/first-harness/handoff.ts +3 -3
  158. package/examples/first-harness/harness.ts +104 -72
  159. package/examples/first-harness/input/README.md +7 -0
  160. package/examples/first-harness/session.ts +2 -1
  161. package/examples/first-harness/tsconfig.json +2 -1
  162. package/examples/harness-session/README.md +1 -1
  163. package/examples/lead-worker/README.md +1 -1
  164. package/examples/messages/README.md +2 -2
  165. package/examples/notes/README.md +2 -2
  166. package/examples/parallel-swarm/AGENTS.md +32 -0
  167. package/examples/parallel-swarm/README.md +136 -0
  168. package/examples/parallel-swarm/board-service.ts +28 -9
  169. package/examples/parallel-swarm/board.ts +107 -13
  170. package/examples/parallel-swarm/config.ts +47 -0
  171. package/examples/parallel-swarm/eject.json +5 -0
  172. package/examples/parallel-swarm/harness.ts +83 -71
  173. package/examples/parallel-swarm/report.ts +33 -0
  174. package/examples/peermesh/README.md +1 -1
  175. package/examples/services/agent-control/README.md +1 -1
  176. package/examples/services/mathlib-search/README.md +1 -1
  177. package/examples/services/mcp-managed/README.md +1 -1
  178. package/examples/services/persistent-board/README.md +1 -1
  179. package/examples/subagents/AGENTS.md +35 -0
  180. package/examples/subagents/README.md +129 -93
  181. package/examples/subagents/config.ts +8 -15
  182. package/examples/subagents/eject.json +17 -0
  183. package/examples/subagents/handoff-config.ts +14 -0
  184. package/examples/subagents/model.ts +20 -0
  185. package/examples/substrate/README.md +12 -6
  186. package/examples/taskpool/README.md +1 -1
  187. package/npm-shrinkwrap.development.json +9 -2
  188. package/npm-shrinkwrap.json +9 -2
  189. package/package.development.json +2 -1
  190. package/package.json +2 -1
  191. package/scripts/anyswarm-progress.ts +36 -6
  192. package/scripts/generate-architecture-coverage.ts +1 -1
  193. package/scripts/generate-architecture-prompts.ts +21 -10
  194. package/scripts/local-environment.ts +8 -1
  195. package/scripts/local-setup.ts +22 -17
  196. package/scripts/pack-release.ts +24 -3
  197. package/src/core/index.ts +1 -1
  198. package/src/core/sandbox/opensandbox-backend.ts +10 -4
  199. package/src/core/sandbox/sandbox-connection.ts +22 -7
  200. package/src/harness/project-harness.ts +3 -2
  201. package/src/harness/project-rpc-client.ts +23 -0
  202. package/src/harness/typescript-loader.ts +28 -8
  203. package/src/trace-viewer/command.mjs +6 -3
  204. package/src/trace-viewer/public/app.js +239 -59
  205. package/src/trace-viewer/public/index.html +5 -0
  206. package/src/trace-viewer/public/style.css +22 -0
  207. package/src/trace-viewer/reader.mjs +242 -26
  208. package/src/trace-viewer/run-root.d.mts +1 -0
  209. package/src/trace-viewer/run-root.mjs +7 -0
  210. package/src/trace-viewer/server.mjs +3 -1
@@ -1,24 +1,109 @@
1
+ function reject(code, message) {
2
+ throw Object.assign(new Error(message), { code });
3
+ }
4
+ /** Checks locations and exact excerpts, not whether they support a conclusion. */
5
+ export function verifySourceReference(files, reference) {
6
+ const { path, startLine, endLine, excerpt } = reference;
7
+ if (typeof path !== 'string' || !path || /[\\\0]/.test(path) || /^[A-Za-z]:/.test(path) ||
8
+ path.split('/').some(part => !part || part === '.' || part === '..') || !Object.hasOwn(files, path)) {
9
+ reject('INVALID_EVIDENCE', 'Evidence must name a relative file in this Run\'s input snapshot');
10
+ }
11
+ if (!Number.isSafeInteger(startLine) || !Number.isSafeInteger(endLine) || startLine < 1 || endLine < startLine ||
12
+ endLine - startLine >= 40 || typeof excerpt !== 'string' || !excerpt.trim() || Buffer.byteLength(excerpt) > 4096) {
13
+ reject('INVALID_EVIDENCE', 'Evidence requires 1–40 source lines and an exact, nonblank excerpt of at most 4096 bytes');
14
+ }
15
+ const entry = files[path];
16
+ let text;
17
+ try {
18
+ const bytes = Buffer.from(entry.data, entry.encoding === 'base64' ? 'base64' : 'utf8');
19
+ text = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes).replaceAll('\r\n', '\n');
20
+ }
21
+ catch {
22
+ reject('INVALID_EVIDENCE', 'Evidence must refer to a UTF-8 source file');
23
+ }
24
+ const lines = text.split('\n');
25
+ if (lines.at(-1) === '')
26
+ lines.pop();
27
+ const normalized = excerpt.replaceAll('\r\n', '\n');
28
+ if (endLine > lines.length || normalized !== lines.slice(startLine - 1, endLine).join('\n')) {
29
+ reject('INVALID_EVIDENCE', 'The line range and excerpt do not match the captured source');
30
+ }
31
+ return { path, startLine, endLine, excerpt: normalized };
32
+ }
1
33
  export class FindingsBoard {
34
+ files;
2
35
  entries = [];
3
- publish(authorId, topic, summary, cites = []) {
4
- for (const refId of cites) {
5
- if (!this.entries.some((e) => e.id === refId)) {
6
- throw Object.assign(new Error(`Referenced finding #${refId} does not exist`), {
7
- code: 'NOT_FOUND',
8
- });
9
- }
36
+ researchers = [];
37
+ round = 'waiting';
38
+ constructor(files) {
39
+ this.files = files;
40
+ }
41
+ beginResearch(researchers) {
42
+ if (this.round !== 'waiting' || researchers.length < 2 || new Set(researchers).size !== researchers.length ||
43
+ researchers.some(id => typeof id !== 'string' || !id)) {
44
+ reject('INVALID_ROUND', 'Start one research round with distinct researcher identities');
10
45
  }
11
- const entry = { id: this.entries.length + 1, authorId, topic, summary, cites };
46
+ this.researchers = [...researchers];
47
+ this.round = 'research';
48
+ }
49
+ beginReview() {
50
+ if (this.round !== 'research')
51
+ reject('INVALID_ROUND', 'The review round must follow research');
52
+ this.requireContributions('research');
53
+ this.round = 'review';
54
+ }
55
+ finishReview() {
56
+ if (this.round !== 'review')
57
+ reject('INVALID_ROUND', 'Finish the review round before synthesis');
58
+ this.requireContributions('review');
59
+ this.round = 'closed';
60
+ }
61
+ requireContributions(round) {
62
+ const missing = this.researchers.filter(id => !this.entries.some(entry => entry.authorId === id && entry.round === round));
63
+ if (missing.length)
64
+ reject(round === 'research' ? 'RESEARCH_INCOMPLETE' : 'REVIEW_INCOMPLETE', `Missing ${round} contribution from ${missing.join(', ')}`);
65
+ }
66
+ publish(authorId, topic, summary, evidence, cites = []) {
67
+ if (this.round !== 'research' && this.round !== 'review')
68
+ reject('BOARD_CLOSED', 'The Board is not accepting publications');
69
+ if (!this.researchers.includes(authorId))
70
+ reject('NOT_RESEARCHER', 'Only this Run\'s researchers may publish');
71
+ if (typeof topic !== 'string' || !topic.trim() || topic.length > 120 ||
72
+ typeof summary !== 'string' || !summary.trim() || summary.length > 2000) {
73
+ reject('INVALID_FINDING', 'Provide a topic and a concise summary');
74
+ }
75
+ if (!Array.isArray(evidence) || evidence.length < 1 || evidence.length > 8) {
76
+ reject('INVALID_EVIDENCE', 'Each finding needs 1–8 source references');
77
+ }
78
+ const checked = evidence.map(reference => verifySourceReference(this.files, reference));
79
+ if (!Array.isArray(cites) || cites.length > 8 || new Set(cites).size !== cites.length) {
80
+ reject('NOT_FOUND', 'Citations must name at most eight distinct existing findings');
81
+ }
82
+ const cited = cites.map(id => {
83
+ const entry = this.entries.find(entry => entry.id === id);
84
+ if (!entry)
85
+ reject('NOT_FOUND', `Referenced finding #${id} does not exist`);
86
+ return entry;
87
+ });
88
+ if (this.round === 'review' && !cited.some(entry => entry.authorId !== authorId && entry.round === 'research')) {
89
+ reject('REVIEW_REQUIRED', 'A review must cite another researcher\'s first-round finding');
90
+ }
91
+ const entry = { id: this.entries.length + 1, authorId, round: this.round, topic, summary,
92
+ evidence: checked, cites: [...cites] };
12
93
  this.entries.push(entry);
13
- return entry;
94
+ return structuredClone(entry);
14
95
  }
15
96
  search(query = '') {
16
97
  const q = query.trim().toLowerCase();
17
- return q
18
- ? this.entries.filter((e) => `${e.topic} ${e.summary}`.toLowerCase().includes(q))
19
- : [...this.entries];
98
+ return structuredClone(q ? this.entries.filter(entry => `${entry.topic} ${entry.summary}`.toLowerCase().includes(q)) : this.entries);
99
+ }
100
+ contributions() {
101
+ return this.researchers.map(authorId => ({ authorId,
102
+ research: this.entries.filter(entry => entry.authorId === authorId && entry.round === 'research').length,
103
+ review: this.entries.filter(entry => entry.authorId === authorId && entry.round === 'review').length,
104
+ }));
20
105
  }
21
106
  exportState() {
22
- return { total: this.entries.length, entries: this.entries };
107
+ return { round: this.round, total: this.entries.length, contributions: this.contributions(), entries: this.search() };
23
108
  }
24
109
  }
@@ -0,0 +1,11 @@
1
+ import { type CreateRuntimeOptions, type SandboxConfig } from '@anyswarm/core';
2
+ export interface ParallelSwarmConfig extends Pick<CreateRuntimeOptions, 'executor' | 'connection' | 'models' | 'filePolicy'> {
3
+ sandbox: SandboxConfig;
4
+ image: string;
5
+ model?: string;
6
+ turnTimeoutMs?: number;
7
+ closeTimeoutMs?: number;
8
+ }
9
+ export declare function parallelSwarmConfig(): ParallelSwarmConfig;
10
+ declare const _default: ParallelSwarmConfig;
11
+ export default _default;
@@ -0,0 +1,39 @@
1
+ import { ProjectPreflightError, resolveSandboxConnection, workerImageFor } from '@anyswarm/core';
2
+ function invalid(message) {
3
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', message);
4
+ }
5
+ export function parallelSwarmConfig() {
6
+ const env = process.env;
7
+ const setting = (key) => env[`ANYSWARM_${key}`] ?? env[`ANYSWARM_PARALLEL_SWARM_${key}`];
8
+ const { image, advertiseHost, publicUrl, endpointSource: _source, executor: setupExecutor, ...sandbox } = resolveSandboxConnection({}, 'PARALLEL_SWARM');
9
+ const executor = setting('EXECUTOR') ?? setupExecutor ?? 'pi';
10
+ if (executor !== 'pi' && executor !== 'codex')
11
+ invalid('Select pi or codex with ANYSWARM_EXECUTOR.');
12
+ const url = setting('MODEL_URL');
13
+ if (!url)
14
+ invalid('Set ANYSWARM_MODEL_URL to your model endpoint before running Parallel Swarm.');
15
+ const protocol = setting('MODEL_PROTOCOL') ?? 'responses';
16
+ if (protocol !== 'responses' && protocol !== 'chat-completions')
17
+ invalid('Select responses or chat-completions with ANYSWARM_MODEL_PROTOCOL.');
18
+ if (executor === 'codex' && protocol !== 'responses')
19
+ invalid('The Codex executor requires a Responses model endpoint.');
20
+ const model = setting('MODEL_ID') ?? (executor === 'pi' ? 'gpt-5-mini' : undefined);
21
+ if (!model)
22
+ invalid('Set ANYSWARM_MODEL_ID to a model supported by the selected Codex executor.');
23
+ const token = setting('MODEL_TOKEN');
24
+ const contextWindow = setting('CONTEXT_WINDOW') === undefined ? undefined : Number(setting('CONTEXT_WINDOW'));
25
+ if (contextWindow !== undefined && (!Number.isSafeInteger(contextWindow) || contextWindow < 2048)) {
26
+ invalid('ANYSWARM_CONTEXT_WINDOW must be the model context limit, at least 2048 tokens.');
27
+ }
28
+ return {
29
+ sandbox, executor, image: image ?? workerImageFor(executor), model: 'default',
30
+ turnTimeoutMs: 120_000, closeTimeoutMs: 60_000,
31
+ connection: { advertiseHost, publicUrl, modelGateway: { maxOutputTokens: executor === 'codex' ? null : 2048 } },
32
+ models: { default: {
33
+ provider: setting('MODEL_PROVIDER') ?? 'openai', model, protocol,
34
+ ...(contextWindow ? { capabilities: { contextWindow, maxOutputTokens: 2048, tools: true, reasoning: false } } : {}),
35
+ upstream: { url, headers: token ? { authorization: `Bearer ${token}` } : {} },
36
+ } },
37
+ };
38
+ }
39
+ export default parallelSwarmConfig();
@@ -0,0 +1,5 @@
1
+ {
2
+ "apiVersion": 1,
3
+ "entry": "harness.ts",
4
+ "files": ["harness.ts", "config.ts", "board.ts", "board-service.ts", "report.ts", "README.md", "AGENTS.md"]
5
+ }
@@ -2,31 +2,37 @@ declare const parallelSwarm: {
2
2
  id: string;
3
3
  apiVersion: 1;
4
4
  run(context: import("@anyswarm/core").HarnessContext): Promise<{
5
- outcome: "cancelled" | "completed" | "failed";
5
+ outcome: 'completed' | 'failed' | 'cancelled';
6
6
  reason: string;
7
- result: {
8
- runtimeId: string;
9
- findings: number;
10
- citedFindings: number;
7
+ result?: import("@anyswarm/core").HarnessJson;
8
+ export?: {
9
+ status: 'complete' | 'failed' | 'pending';
10
+ receipt?: import("@anyswarm/core").HarnessJson;
11
+ };
12
+ cleanup: {
13
+ status: 'complete' | 'pending';
14
+ receipt?: import("@anyswarm/core").HarnessJson;
15
+ pending?: import("@anyswarm/core").HarnessJson;
16
+ retained?: import("@anyswarm/core").HarnessJson;
11
17
  };
12
18
  acceptance: {
13
19
  status: string;
20
+ scope: string;
21
+ research: string;
22
+ review: string;
23
+ sourceReferences: string;
24
+ report: {
25
+ status: 'not-run' | 'pending' | 'unverified';
26
+ reason: string;
27
+ } | {
28
+ status: 'verified';
29
+ path: string;
30
+ sha256: string;
31
+ bytes: number;
32
+ };
33
+ semanticCorrectness: string;
14
34
  };
15
- artifacts: {
16
- path: string;
17
- sha256: string;
18
- }[];
19
- export?: {
20
- status: "complete" | "failed";
21
- } | undefined;
22
- cleanup: {
23
- status: "complete" | "pending";
24
- pending: {
25
- id: string;
26
- kind: "agent" | "backend" | "bridge" | "model" | "report" | "service";
27
- action: "archive-session" | "await-startup" | "close" | "collect-artifacts" | "delete-sandbox" | "retire-service" | "save" | "stop-execution";
28
- }[];
29
- };
35
+ artifacts: import("@anyswarm/core").HarnessJson[];
30
36
  }>;
31
37
  };
32
38
  export default parallelSwarm;
@@ -1,91 +1,92 @@
1
- import { createHash } from 'node:crypto';
2
- import { readFile } from 'node:fs/promises';
3
- import { join } from 'node:path';
4
- import { createRuntime, createSandbox, resolveSandboxConnection, runInput, ServiceRegistry, workerImageFor, } from '@anyswarm/core';
1
+ import { createRuntime, createSandbox, projectConfiguration, ProjectPreflightError, runInput, ServiceRegistry, } from '@anyswarm/core';
5
2
  import { FindingsBoard } from './board.js';
6
3
  import { boardService } from './board-service.js';
7
- const researcherPrompt = 'Inspect the workspace. Publish concrete findings with swarm service invoke board publish. Read peer findings with swarm service invoke board search.';
8
- const synthesizerPrompt = 'Use swarm service invoke board search to read the findings and citations. Write a concise report.md in your workspace.';
9
- const reviewInput = 'Read the other researchers’ findings and publish a follow-up addressing a gap or disagreement. Cite the entries you relied on.';
10
- const synthesisInput = 'Summarize the board findings and citations in report.md.';
4
+ import { checkReportExport } from './report.js';
5
+ 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.';
6
+ 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.';
7
+ 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.'];
8
+ 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.';
9
+ 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.';
11
10
  const parallelSwarm = {
12
11
  id: 'parallel-swarm', apiVersion: 1,
13
12
  async run(context) {
14
- const url = process.env.ANYSWARM_MODEL_URL;
15
- if (!url)
16
- throw new Error('Set ANYSWARM_MODEL_URL to a streaming Responses endpoint before running.');
17
- const board = new FindingsBoard();
13
+ const config = await projectConfiguration(context, () => import('./config.js'));
14
+ const { image, model = 'default', turnTimeoutMs = 120_000, closeTimeoutMs = 60_000 } = config;
15
+ if (!image || ![turnTimeoutMs, closeTimeoutMs].every(ms => Number.isSafeInteger(ms) && ms > 0 && ms <= 2_147_483_647)) {
16
+ throw new ProjectPreflightError('INVALID_RUN_CONFIGURATION', 'Parallel Swarm needs an image and finite positive turn/close time limits.');
17
+ }
18
+ const board = new FindingsBoard(context.initial.files);
18
19
  const services = new ServiceRegistry();
19
20
  services.register('board', boardService(board), { toolMode: 'cli' });
20
- const { image: configuredImage, advertiseHost, publicUrl, executor: setupExecutor, endpointSource: _source, ...sandbox } = resolveSandboxConnection();
21
- const executor = process.env.ANYSWARM_EXECUTOR ?? setupExecutor ?? 'pi';
22
- if (executor !== undefined && executor !== 'pi' && executor !== 'codex')
23
- throw new Error('Select pi or codex with ANYSWARM_EXECUTOR.');
24
- const image = configuredImage ?? workerImageFor(executor);
25
- const token = process.env.ANYSWARM_MODEL_TOKEN;
26
- const runtime = await createRuntime({
27
- sandbox: createSandbox(sandbox), connection: { advertiseHost, publicUrl }, executor, services, maxAgents: 4, outputDir: context.outputDir,
28
- models: { default: {
29
- provider: process.env.ANYSWARM_MODEL_PROVIDER ?? 'openai',
30
- model: process.env.ANYSWARM_MODEL_ID ?? 'gpt-5-mini',
31
- upstream: { url, headers: token ? { authorization: `Bearer ${token}` } : {} },
32
- } },
33
- profiles: {
34
- researcher: { addedSystemPrompt: researcherPrompt, model: 'default', image, writable: false,
35
- services: { board: ['publish', 'search'] } },
36
- synthesizer: { addedSystemPrompt: synthesizerPrompt, model: 'default', image, writable: true,
37
- services: { board: ['search'] },
38
- collect: { paths: ['report.md'], includeGit: false, maxBytes: 1_048_576, required: true } },
39
- },
40
- });
41
- const turn = { signal: context.signal, timeoutMs: 120_000 };
42
- let synthId;
43
- let failure;
44
- let cleanup;
45
21
  let unobserve;
22
+ let synthId;
23
+ let researchChecked = false;
24
+ let reviewChecked = false;
25
+ const checks = {
26
+ report: { status: 'not-run', reason: 'SYNTHESIZER_NOT_STARTED' },
27
+ };
46
28
  try {
47
- unobserve = context.registerAgentControls({ runtime });
48
- context.markRunning();
49
- const peers = await Promise.all([1, 2, 3].map(index => runtime.spawn({ requestId: `spawn-r${index}`, profile: 'researcher', files: context.initial.files })));
50
- await Promise.all(peers.map((peer, index) => runInput(runtime, peer.id, context.input.prompt, { ...turn, requestId: `research-${index + 1}` })));
51
- const firstRound = board.search().length;
52
- if (firstRound === 0)
53
- throw new Error('The first round published no findings.');
54
- await Promise.all(peers.map((peer, index) => runInput(runtime, peer.id, reviewInput, { ...turn, requestId: `review-${index + 1}` })));
55
- if (board.search().length <= firstRound)
56
- throw new Error('The review round published no follow-up findings.');
57
- await Promise.all(peers.map(peer => runtime.stop(peer.id)));
58
- const synth = await runtime.spawn({ requestId: 'spawn-synthesizer', profile: 'synthesizer', files: context.initial.files });
59
- synthId = synth.id;
60
- await runInput(runtime, synth.id, synthesisInput, { ...turn, requestId: 'synthesize' });
61
- }
62
- catch (error) {
63
- failure = error.code ?? 'SWARM_FAILED';
29
+ const result = await context.runWithRuntime({
30
+ closeTimeoutMs,
31
+ createRuntime: () => createRuntime({
32
+ sandbox: createSandbox(config.sandbox), connection: config.connection, executor: config.executor,
33
+ models: config.models, filePolicy: config.filePolicy, services, maxAgents: 4, outputDir: context.outputDir,
34
+ profiles: {
35
+ researcher: { addedSystemPrompt: researcherPrompt, model, image, writable: false,
36
+ services: { board: ['publish', 'search'] } },
37
+ synthesizer: { addedSystemPrompt: synthesizerPrompt, model, image, writable: true,
38
+ services: { board: ['search'] },
39
+ collect: { paths: ['report.md'], includeGit: false, maxBytes: 1_048_576, required: true } },
40
+ },
41
+ }),
42
+ async run(runtime) {
43
+ unobserve = context.registerAgentControls({ runtime });
44
+ context.markRunning();
45
+ const turn = { signal: context.signal, timeoutMs: turnTimeoutMs };
46
+ context.signal.throwIfAborted();
47
+ const peers = await Promise.all(researchFocuses.map((_, index) => runtime.spawn({ requestId: `spawn-r${index + 1}`, profile: 'researcher', files: context.initial.files })));
48
+ board.beginResearch(peers.map(peer => peer.id));
49
+ await Promise.all(peers.map((peer, index) => runInput(runtime, peer.id, `${context.input.prompt}\n\nYour focus: ${researchFocuses[index]}\nPublish at least one source-backed finding.`, { ...turn, requestId: `research-${index + 1}` })));
50
+ board.beginReview();
51
+ researchChecked = true;
52
+ await Promise.all(peers.map((peer, index) => runInput(runtime, peer.id, reviewInput, { ...turn, requestId: `review-${index + 1}` })));
53
+ board.finishReview();
54
+ reviewChecked = true;
55
+ await Promise.all(peers.map(peer => runtime.stop(peer.id, { timeoutMs: closeTimeoutMs })));
56
+ context.signal.throwIfAborted();
57
+ const synth = await runtime.spawn({ requestId: 'spawn-synthesizer', profile: 'synthesizer', files: context.initial.files });
58
+ synthId = synth.id;
59
+ checks.report = { status: 'pending', reason: 'REPORT_EXPORT_PENDING' };
60
+ await runInput(runtime, synth.id, `${synthesisInput}\n\n${context.input.prompt}`, { ...turn, requestId: 'synthesize' });
61
+ return { synthesizerId: synthId, contributions: board.contributions() };
62
+ },
63
+ // A failed report check is business evidence, not a thrown cleanup error.
64
+ afterClose: async (receipt) => { checks.report = await checkReportExport(receipt, synthId, context.initial.files); },
65
+ detail: () => {
66
+ // Keep the final projection stable if a post-close read outlives its wait.
67
+ checks.finalized = { ...checks.report };
68
+ return { board: board.exportState(), report: checks.finalized };
69
+ },
70
+ });
71
+ const report = checks.finalized;
72
+ const reportFailed = report.status === 'unverified';
73
+ return {
74
+ ...result,
75
+ ...(result.outcome === 'completed' && reportFailed ? { outcome: 'failed', reason: report.reason } : {}),
76
+ acceptance: {
77
+ status: researchChecked && reviewChecked && report.status === 'verified' ? 'verified' : report.status === 'pending' ? 'pending' : 'unverified',
78
+ scope: 'participant-contributions, cross-author-reviews, Board-source-references, report-export',
79
+ research: researchChecked ? 'verified' : 'unverified', review: reviewChecked ? 'verified' : 'unverified',
80
+ sourceReferences: board.search().length ? 'verified' : 'not-run', report: { ...report }, semanticCorrectness: 'not-run',
81
+ },
82
+ artifacts: [...result.artifacts, ...(report.status === 'verified' ? [{ agentId: synthId, kind: 'report', ...report }] : [])],
83
+ ...(synthId ? { export: { ...result.export, status: result.export?.status === 'pending' || report.status === 'pending'
84
+ ? 'pending' : report.status === 'verified' ? 'complete' : 'failed' } } : {}),
85
+ };
64
86
  }
65
87
  finally {
66
- try {
67
- cleanup = await runtime.close({ timeoutMs: 60_000 });
68
- }
69
- finally {
70
- unobserve?.();
71
- }
88
+ unobserve?.();
72
89
  }
73
- const directory = cleanup.agents.find(agent => agent.agentId === synthId)?.artifacts.find(path => path.endsWith('/artifacts/files'));
74
- const file = directory && join(directory, 'report.md');
75
- const bytes = file ? await readFile(file).catch(() => undefined) : undefined;
76
- const artifact = file && bytes && bytes.toString('utf8').trim() ? {
77
- path: file, sha256: createHash('sha256').update(bytes).digest('hex'),
78
- } : undefined;
79
- const findings = board.search();
80
- return {
81
- outcome: context.signal.aborted ? 'cancelled' : failure || !artifact ? 'failed' : 'completed',
82
- reason: failure ?? (artifact ? 'report-verified' : 'report-missing'),
83
- result: { runtimeId: runtime.id, findings: findings.length, citedFindings: findings.filter(finding => finding.cites.length > 0).length },
84
- acceptance: { status: artifact ? 'verified' : 'unverified' },
85
- artifacts: artifact ? [artifact] : [],
86
- ...(synthId ? { export: { status: artifact ? 'complete' : 'failed' } } : {}),
87
- cleanup: { status: cleanup.cleanup, pending: cleanup.pending.map(({ id, kind, action }) => ({ id, kind, action })) },
88
- };
89
90
  },
90
91
  };
91
92
  export default parallelSwarm;
@@ -0,0 +1,12 @@
1
+ import type { CloseReceipt, FileTree } from '@anyswarm/core';
2
+ export type ReportCheck = {
3
+ status: 'not-run' | 'pending' | 'unverified';
4
+ reason: string;
5
+ } | {
6
+ status: 'verified';
7
+ path: string;
8
+ sha256: string;
9
+ bytes: number;
10
+ };
11
+ /** A readable, newly written report is an export check, not a semantic review. */
12
+ export declare function checkReportExport(receipt: CloseReceipt, agentId: string | undefined, initial: FileTree): Promise<ReportCheck>;
@@ -0,0 +1,30 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ /** A readable, newly written report is an export check, not a semantic review. */
5
+ export async function checkReportExport(receipt, agentId, initial) {
6
+ if (!agentId)
7
+ return { status: 'not-run', reason: 'SYNTHESIZER_NOT_STARTED' };
8
+ const agent = receipt.agents.find(agent => agent.agentId === agentId);
9
+ const directory = agent?.artifacts.find(path => path.endsWith(join('artifacts', 'files')));
10
+ if (!directory) {
11
+ const pending = !agent || agent.execution !== 'stopped' || agent.cleanup === 'pending' ||
12
+ receipt.pending.some(entry => entry.kind === 'agent' && entry.id === agentId);
13
+ return { status: pending ? 'pending' : 'unverified', reason: pending ? 'REPORT_EXPORT_PENDING' : 'REPORT_MISSING' };
14
+ }
15
+ const path = join(directory, 'report.md');
16
+ try {
17
+ const bytes = await readFile(path);
18
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
19
+ if (!text.trim())
20
+ return { status: 'unverified', reason: 'REPORT_EMPTY' };
21
+ const before = initial['report.md'];
22
+ if (before && bytes.equals(Buffer.from(before.data, before.encoding === 'base64' ? 'base64' : 'utf8'))) {
23
+ return { status: 'unverified', reason: 'REPORT_UNCHANGED' };
24
+ }
25
+ return { status: 'verified', path, sha256: createHash('sha256').update(bytes).digest('hex'), bytes: bytes.length };
26
+ }
27
+ catch {
28
+ return { status: 'unverified', reason: 'REPORT_UNREADABLE' };
29
+ }
30
+ }
@@ -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.0}"
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
@@ -7,6 +7,7 @@ export declare function peerMeshConfig(durationMs?: number): {
7
7
  useServerProxy: boolean | undefined;
8
8
  egressMode: "dns+nft" | undefined;
9
9
  endpointHost: undefined;
10
+ preparedImage?: string | undefined;
10
11
  timeoutSeconds: number;
11
12
  resourceLimits: {
12
13
  cpu: string;
@@ -10,7 +10,7 @@ Run these commands in an empty directory. To use a source build, set `ANYSWARM_S
10
10
 
11
11
  ```sh
12
12
  npm init -y
13
- npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
13
+ npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.2}"
14
14
  npm install --save-dev typescript @types/node
15
15
  cp -R node_modules/@anyswarm/core/examples/services/agent-control demo
16
16
  cd demo
@@ -39,7 +39,7 @@ process. See the maintained [Mathlib service implementation](../../../docs/archi
39
39
 
40
40
  To run the host without a container after building the checkout, use
41
41
  `npm run service:mathlib-search` from the root, or
42
- `../../../node_modules/.bin/anyswarm run ./main.ts` from this directory.
42
+ `node ../../../dist/scripts/anyswarm.js run ./main.ts` from this directory.
43
43
  The caller supplies the host token with `MATHLIB_SEARCH_TOKEN`, and configures
44
44
  the endpoint in its own service adapter. The application/operator owns the
45
45
  external provider's lifecycle and persistent data; Runtime close does not remove it.
@@ -10,7 +10,7 @@ Use Linux with Node 24 or later. Run these commands in an empty directory. To us
10
10
 
11
11
  ```sh
12
12
  npm init -y
13
- npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
13
+ npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.2}"
14
14
  npm install --save-dev typescript @types/node
15
15
  cp -R node_modules/@anyswarm/core/examples/services/mcp-managed demo
16
16
  cd demo
@@ -10,7 +10,7 @@ Use Node 24 or later. The HTTP variant also needs Python 3. Run these commands i
10
10
 
11
11
  ```sh
12
12
  npm init -y
13
- npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.0}"
13
+ npm install --ignore-scripts "${ANYSWARM_SDK_ARCHIVE:-@anyswarm/core@0.5.2}"
14
14
  npm install --save-dev typescript @types/node
15
15
  cp -R node_modules/@anyswarm/core/examples/services/persistent-board demo
16
16
  cd demo
@@ -0,0 +1,35 @@
1
+ # Customize this Subagents Harness
2
+
3
+ This file is for a Coding Agent editing an exported application. Start by reading
4
+ `README.md`, `project.ts`, `business.ts`, and `config.ts`. Read the installed
5
+ `@anyswarm/core` package-root TypeScript declarations for exact SDK signatures.
6
+
7
+ - Keep the application in ordinary TypeScript. `project.ts` exports the public
8
+ `Harness`; one Runtime owns Root and its children. Do not create a Runtime for
9
+ every Agent or add a second session/workflow abstraction.
10
+ - `config.ts` owns model, executor, Sandbox, capacity and deadlines. Respect the
11
+ user's saved setup and explicit configuration. Keep tokens in the host
12
+ environment; never put credentials in prompts, seed files or reports.
13
+ - `business.ts` assembles Profiles and Services. The controller in
14
+ `harness/controller.ts` owns named children, messages, follow-up and closure.
15
+ The Service adapter gets the caller from the authenticated Bridge; never trust
16
+ an author or parent supplied in Agent text.
17
+ - Initial project files are captured once and passed to separate private
18
+ Sandboxes. A child message does not synchronize files. Root must integrate
19
+ contributions and write the requested deliverable in its own directory.
20
+ - Preserve accepted/unknown input receipts, cancellation, bounded close and raw
21
+ export/cleanup receipts. An unknown write is reconciled with its original
22
+ request ID. Do not silently retry it with a new identity.
23
+ - Define the application's actual output and business checks before editing.
24
+ Agent settlement and file presence do not establish correctness. Generic
25
+ Subagents returns `acceptance: not-run`; add a domain check only when its
26
+ contract is explicit. Keep business failure separate from cleanup failure.
27
+ - Read `anyswarm-source.json` for the SDK identity. Install with `npm install`
28
+ and run with the local `npm start` so source and SDK stay matched. Change the
29
+ visible source here, rather than wrapping an inaccessible bundled Harness.
30
+
31
+ Use a real input directory and question for manual acceptance. Verify the
32
+ requested members contributed, inspect citations against the captured input,
33
+ read the exported result, and check cleanup. Deterministic test fixtures verify
34
+ protocol and failure handling; they are not evidence of model quality. Report
35
+ which checks ran and any remaining real-model acceptance separately.