@anyswarm/core 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/AGENTS.md +20 -5
  2. package/README.md +69 -55
  3. package/dist/examples/README.md +138 -77
  4. package/dist/examples/authoring/README.md +4 -4
  5. package/dist/examples/autoresearch/README.md +108 -16
  6. package/dist/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
  7. package/dist/examples/autoresearch/config.d.ts +48 -5
  8. package/dist/examples/autoresearch/config.js +57 -23
  9. package/dist/examples/autoresearch/demo.d.ts +12 -4
  10. package/dist/examples/autoresearch/demo.js +65 -22
  11. package/dist/examples/autoresearch/eject.json +2 -0
  12. package/dist/examples/autoresearch/frontiercs2-config.d.ts +2 -0
  13. package/dist/examples/autoresearch/frontiercs2-config.js +14 -0
  14. package/dist/examples/autoresearch/frontiercs2.d.ts +18 -1
  15. package/dist/examples/autoresearch/frontiercs2.js +71 -14
  16. package/dist/examples/autoresearch/prepare-demo.d.ts +1 -0
  17. package/dist/examples/autoresearch/prepare-demo.js +46 -0
  18. package/dist/examples/autoresearch/prepare.d.ts +105 -53
  19. package/dist/examples/autoresearch/prepare.js +126 -57
  20. package/dist/examples/autoresearch/project.d.ts +6 -95
  21. package/dist/examples/autoresearch/project.js +131 -45
  22. package/dist/examples/autoresearch/research-service.d.ts +16 -1
  23. package/dist/examples/autoresearch/research-service.js +84 -44
  24. package/dist/examples/code/README.md +25 -17
  25. package/dist/examples/code/REQUIREMENTS.zh.md +3 -3
  26. package/dist/examples/code/config.d.ts +1 -0
  27. package/dist/examples/first-harness/AGENTS.md +25 -0
  28. package/dist/examples/first-harness/README.md +136 -0
  29. package/dist/examples/first-harness/config.d.ts +9 -8
  30. package/dist/examples/first-harness/config.js +33 -26
  31. package/dist/examples/first-harness/eject.json +14 -0
  32. package/dist/examples/first-harness/handoff.js +3 -3
  33. package/dist/examples/first-harness/harness.d.ts +14 -18
  34. package/dist/examples/first-harness/harness.js +102 -77
  35. package/dist/examples/first-harness/input/README.md +7 -0
  36. package/dist/examples/first-harness/session.js +2 -1
  37. package/dist/examples/first-harness/tsconfig.json +2 -1
  38. package/dist/examples/harness-session/README.md +4 -4
  39. package/dist/examples/lead-worker/README.md +1 -1
  40. package/dist/examples/lead-worker/project-config.d.ts +1 -0
  41. package/dist/examples/messages/README.md +2 -2
  42. package/dist/examples/notes/README.md +5 -5
  43. package/dist/examples/notes/config.d.ts +1 -0
  44. package/dist/examples/parallel-swarm/AGENTS.md +32 -0
  45. package/dist/examples/parallel-swarm/README.md +136 -0
  46. package/dist/examples/parallel-swarm/board-service.js +25 -8
  47. package/dist/examples/parallel-swarm/board.d.ts +31 -1
  48. package/dist/examples/parallel-swarm/board.js +98 -13
  49. package/dist/examples/parallel-swarm/config.d.ts +11 -0
  50. package/dist/examples/parallel-swarm/config.js +39 -0
  51. package/dist/examples/parallel-swarm/eject.json +5 -0
  52. package/dist/examples/parallel-swarm/harness.d.ts +26 -20
  53. package/dist/examples/parallel-swarm/harness.js +77 -76
  54. package/dist/examples/parallel-swarm/report.d.ts +12 -0
  55. package/dist/examples/parallel-swarm/report.js +30 -0
  56. package/dist/examples/peermesh/README.md +1 -1
  57. package/dist/examples/peermesh/project-config.d.ts +1 -0
  58. package/dist/examples/services/agent-control/README.md +1 -1
  59. package/dist/examples/services/mathlib-search/README.md +1 -1
  60. package/dist/examples/services/mcp-managed/README.md +1 -1
  61. package/dist/examples/services/persistent-board/README.md +6 -3
  62. package/dist/examples/subagents/AGENTS.md +35 -0
  63. package/dist/examples/subagents/README.md +129 -93
  64. package/dist/examples/subagents/config.d.ts +2 -10
  65. package/dist/examples/subagents/config.js +9 -16
  66. package/dist/examples/subagents/eject.json +17 -0
  67. package/dist/examples/subagents/handoff-config.d.ts +41 -0
  68. package/dist/examples/subagents/handoff-config.js +13 -0
  69. package/dist/examples/subagents/model.d.ts +3 -0
  70. package/dist/examples/subagents/model.js +19 -0
  71. package/dist/examples/substrate/README.md +12 -6
  72. package/dist/examples/substrate/config.d.ts +1 -0
  73. package/dist/examples/substrate/project-config.d.ts +1 -0
  74. package/dist/examples/super/README.md +34 -22
  75. package/dist/examples/super/actions.d.ts +1 -1
  76. package/dist/examples/super/actions.js +11 -11
  77. package/dist/examples/super/config.js +3 -3
  78. package/dist/examples/super/eject.json +1 -1
  79. package/dist/examples/super/location.js +1 -1
  80. package/dist/examples/super/operator.d.ts +1 -0
  81. package/dist/examples/super/operator.js +31 -0
  82. package/dist/examples/super/project.d.ts +0 -107
  83. package/dist/examples/super/project.js +1 -3
  84. package/dist/examples/taskpool/README.md +1 -1
  85. package/dist/examples/taskpool/config.d.ts +1 -0
  86. package/dist/examples/taskpool/deploy/service-hosts/service-authority-snapshot.d.ts +4 -4
  87. package/dist/scripts/anyswarm-arguments.d.ts +7 -25
  88. package/dist/scripts/anyswarm-arguments.js +69 -97
  89. package/dist/scripts/anyswarm-eject.js +1 -1
  90. package/dist/scripts/anyswarm-harnesses.d.ts +0 -1
  91. package/dist/scripts/anyswarm-harnesses.js +1 -22
  92. package/dist/scripts/anyswarm-installation.d.ts +7 -40
  93. package/dist/scripts/anyswarm-installation.js +17 -291
  94. package/dist/scripts/anyswarm-launch.d.ts +6 -36
  95. package/dist/scripts/anyswarm-launch.js +32 -81
  96. package/dist/scripts/anyswarm-progress.d.ts +6 -0
  97. package/dist/scripts/anyswarm-progress.js +133 -0
  98. package/dist/scripts/anyswarm-project.d.ts +1 -9
  99. package/dist/scripts/anyswarm-project.js +40 -127
  100. package/dist/scripts/anyswarm-source-runner.js +9 -41
  101. package/dist/scripts/anyswarm.js +6 -26
  102. package/dist/scripts/build-provenance.json +1 -1
  103. package/dist/scripts/generate-architecture-coverage.js +1 -1
  104. package/dist/scripts/generate-architecture-prompts.js +18 -10
  105. package/dist/scripts/local-environment.d.ts +13 -7
  106. package/dist/scripts/local-environment.js +73 -21
  107. package/dist/scripts/local-setup.d.ts +3 -0
  108. package/dist/scripts/local-setup.js +153 -118
  109. package/dist/scripts/pack-release.js +31 -4
  110. package/dist/src/core/index.js +1 -1
  111. package/dist/src/core/sandbox/opensandbox-backend.js +10 -4
  112. package/dist/src/core/sandbox/sandbox-connection.d.ts +9 -2
  113. package/dist/src/core/sandbox/sandbox-connection.js +22 -7
  114. package/dist/src/core/worker-image.js +1 -1
  115. package/dist/src/harness/project-harness.d.ts +1 -0
  116. package/dist/src/harness/project-harness.js +5 -4
  117. package/dist/src/harness/project-rpc-client.js +19 -0
  118. package/dist/src/harness/project-runtime.js +3 -1
  119. package/dist/src/harness/typescript-loader.d.ts +2 -0
  120. package/dist/src/harness/typescript-loader.js +26 -8
  121. package/dist/src/trace-viewer/command.mjs +6 -3
  122. package/dist/src/trace-viewer/public/app.js +239 -59
  123. package/dist/src/trace-viewer/public/index.html +5 -0
  124. package/dist/src/trace-viewer/public/style.css +22 -0
  125. package/dist/src/trace-viewer/reader.mjs +242 -26
  126. package/dist/src/trace-viewer/run-root.d.mts +1 -0
  127. package/dist/src/trace-viewer/run-root.mjs +7 -0
  128. package/dist/src/trace-viewer/server.mjs +3 -1
  129. package/docs/INDEX.md +11 -9
  130. package/docs/architecture/04-services.md +1 -1
  131. package/docs/architecture/06-observability-experiments.md +21 -7
  132. package/docs/architecture/07-run-configuration.md +118 -19
  133. package/docs/architecture/08-prompts.md +21 -2
  134. package/docs/architecture/10-service-api-reference.md +12 -5
  135. package/docs/architecture/12-code-coverage.md +157 -115
  136. package/docs/architecture/15-core-runtime.md +1 -1
  137. package/docs/architecture/16-pi-opensandbox-backend.md +2 -0
  138. package/docs/architecture/17-harness-reporting.md +79 -1
  139. package/docs/architecture/22-website.md +52 -20
  140. package/docs/architecture/23-project-harness.md +109 -37
  141. package/docs/architecture/26-code.md +20 -5
  142. package/docs/architecture/27-personal.md +23 -8
  143. package/docs/architecture/28-autoresearch.md +18 -12
  144. package/docs/architecture/INDEX.md +1 -2
  145. package/docs/architecture/prompts/11-first-sdk-harness.md +9 -9
  146. package/docs/architecture/prompts/16-parallel-swarm.md +46 -13
  147. package/docs/architecture/prompts/22-autoresearch.md +9 -2
  148. package/docs/architecture/prompts/source-manifest.json +76 -52
  149. package/docs/architecture/source-map.json +445 -105
  150. package/docs/designs/core-harness/01-core.md +2 -2
  151. package/docs/designs/core-harness/06-project-harness.md +3 -3
  152. package/docs/designs/core-harness/README.md +2 -2
  153. package/docs/en/agents.md +1 -1
  154. package/docs/en/autoresearch.md +41 -0
  155. package/docs/en/blog/100b-tokens.md +157 -0
  156. package/docs/en/build-your-harness.md +47 -22
  157. package/docs/en/changelog.md +29 -1
  158. package/docs/en/first-harness.md +40 -32
  159. package/docs/en/harnesses/index.md +23 -23
  160. package/docs/en/harnesses/lead-worker.md +1 -1
  161. package/docs/en/harnesses/peermesh.md +2 -2
  162. package/docs/en/harnesses/subagents.md +10 -31
  163. package/docs/en/harnesses/substrate.md +4 -4
  164. package/docs/en/harnesses/taskpool.md +2 -2
  165. package/docs/en/latest.md +30 -5
  166. package/docs/en/overview.md +22 -22
  167. package/docs/en/quickstart.md +69 -56
  168. package/docs/en/reference/api.md +1 -1
  169. package/docs/en/reference/cli.md +47 -85
  170. package/docs/en/sandbox.md +3 -3
  171. package/docs/en/trace-viewer.md +32 -12
  172. package/docs/operations/trace-viewer.md +26 -11
  173. package/docs/third-party-notices.md +0 -1
  174. package/docs/workflows/development.md +160 -118
  175. package/docs/workflows/release-and-docs-versioning.md +207 -54
  176. package/docs/workflows/release-cli-acceptance.md +162 -0
  177. package/docs/zh/agents.md +1 -1
  178. package/docs/zh/autoresearch.md +41 -0
  179. package/docs/zh/blog/100b-tokens.md +102 -0
  180. package/docs/zh/build-your-harness.md +48 -23
  181. package/docs/zh/changelog.md +29 -1
  182. package/docs/zh/first-harness.md +43 -35
  183. package/docs/zh/harnesses/index.md +23 -23
  184. package/docs/zh/harnesses/lead-worker.md +1 -1
  185. package/docs/zh/harnesses/peermesh.md +2 -2
  186. package/docs/zh/harnesses/subagents.md +10 -31
  187. package/docs/zh/harnesses/substrate.md +4 -4
  188. package/docs/zh/harnesses/taskpool.md +2 -2
  189. package/docs/zh/latest.md +30 -5
  190. package/docs/zh/overview.md +23 -23
  191. package/docs/zh/quickstart.md +66 -57
  192. package/docs/zh/reference/api.md +1 -1
  193. package/docs/zh/reference/cli.md +19 -79
  194. package/docs/zh/sandbox.md +3 -3
  195. package/docs/zh/trace-viewer.md +32 -12
  196. package/examples/README.md +138 -77
  197. package/examples/authoring/README.md +4 -4
  198. package/examples/autoresearch/README.md +108 -16
  199. package/examples/autoresearch/REQUIREMENTS.zh.md +13 -12
  200. package/examples/autoresearch/config.ts +64 -25
  201. package/examples/autoresearch/demo.ts +75 -22
  202. package/examples/autoresearch/eject.json +2 -0
  203. package/examples/autoresearch/frontiercs2-config.ts +15 -0
  204. package/examples/autoresearch/frontiercs2.ts +64 -11
  205. package/examples/autoresearch/prepare-demo.ts +44 -0
  206. package/examples/autoresearch/prepare.ts +134 -60
  207. package/examples/autoresearch/project.ts +120 -44
  208. package/examples/autoresearch/research-service.ts +91 -41
  209. package/examples/code/README.md +25 -17
  210. package/examples/code/REQUIREMENTS.zh.md +3 -3
  211. package/examples/first-harness/AGENTS.md +25 -0
  212. package/examples/first-harness/README.md +136 -0
  213. package/examples/first-harness/config.ts +41 -27
  214. package/examples/first-harness/eject.json +14 -0
  215. package/examples/first-harness/handoff.ts +3 -3
  216. package/examples/first-harness/harness.ts +104 -72
  217. package/examples/first-harness/input/README.md +7 -0
  218. package/examples/first-harness/session.ts +2 -1
  219. package/examples/first-harness/tsconfig.json +2 -1
  220. package/examples/harness-session/README.md +4 -4
  221. package/examples/lead-worker/README.md +1 -1
  222. package/examples/messages/README.md +2 -2
  223. package/examples/notes/README.md +5 -5
  224. package/examples/parallel-swarm/AGENTS.md +32 -0
  225. package/examples/parallel-swarm/README.md +136 -0
  226. package/examples/parallel-swarm/board-service.ts +28 -9
  227. package/examples/parallel-swarm/board.ts +107 -13
  228. package/examples/parallel-swarm/config.ts +47 -0
  229. package/examples/parallel-swarm/eject.json +5 -0
  230. package/examples/parallel-swarm/harness.ts +83 -71
  231. package/examples/parallel-swarm/report.ts +33 -0
  232. package/examples/peermesh/README.md +1 -1
  233. package/examples/services/agent-control/README.md +1 -1
  234. package/examples/services/mathlib-search/README.md +1 -1
  235. package/examples/services/mcp-managed/README.md +1 -1
  236. package/examples/services/persistent-board/README.md +6 -3
  237. package/examples/subagents/AGENTS.md +35 -0
  238. package/examples/subagents/README.md +129 -93
  239. package/examples/subagents/config.ts +9 -15
  240. package/examples/subagents/eject.json +17 -0
  241. package/examples/subagents/handoff-config.ts +14 -0
  242. package/examples/subagents/model.ts +20 -0
  243. package/examples/substrate/README.md +12 -6
  244. package/examples/super/README.md +34 -22
  245. package/examples/super/actions.ts +11 -11
  246. package/examples/super/config.ts +3 -3
  247. package/examples/super/eject.json +1 -1
  248. package/examples/super/location.ts +1 -1
  249. package/examples/super/operator.ts +28 -0
  250. package/examples/super/project.ts +1 -3
  251. package/examples/taskpool/README.md +1 -1
  252. package/npm-shrinkwrap.development.json +46 -1538
  253. package/npm-shrinkwrap.json +10 -43
  254. package/package.development.json +3 -6
  255. package/package.json +3 -5
  256. package/scripts/anyswarm-arguments.ts +67 -96
  257. package/scripts/anyswarm-eject.ts +1 -1
  258. package/scripts/anyswarm-harnesses.ts +1 -18
  259. package/scripts/anyswarm-installation.ts +18 -294
  260. package/scripts/anyswarm-launch.ts +30 -102
  261. package/scripts/anyswarm-progress.ts +125 -0
  262. package/scripts/anyswarm-project.ts +31 -123
  263. package/scripts/anyswarm-source-runner.ts +9 -36
  264. package/scripts/anyswarm.ts +4 -24
  265. package/scripts/generate-architecture-coverage.ts +1 -1
  266. package/scripts/generate-architecture-prompts.ts +21 -10
  267. package/scripts/local-environment.ts +79 -21
  268. package/scripts/local-setup.ts +150 -105
  269. package/scripts/pack-release.ts +28 -4
  270. package/src/core/index.ts +1 -1
  271. package/src/core/sandbox/opensandbox-backend.ts +10 -4
  272. package/src/core/sandbox/sandbox-connection.ts +22 -7
  273. package/src/core/worker-image.ts +1 -1
  274. package/src/harness/project-harness.ts +5 -4
  275. package/src/harness/project-rpc-client.ts +23 -0
  276. package/src/harness/project-runtime.ts +2 -1
  277. package/src/harness/typescript-loader.ts +28 -8
  278. package/src/trace-viewer/command.mjs +6 -3
  279. package/src/trace-viewer/public/app.js +239 -59
  280. package/src/trace-viewer/public/index.html +5 -0
  281. package/src/trace-viewer/public/style.css +22 -0
  282. package/src/trace-viewer/reader.mjs +242 -26
  283. package/src/trace-viewer/run-root.d.mts +1 -0
  284. package/src/trace-viewer/run-root.mjs +7 -0
  285. package/src/trace-viewer/server.mjs +3 -1
  286. package/dist/scripts/anyswarm-applications.d.ts +0 -19
  287. package/dist/scripts/anyswarm-applications.js +0 -19
  288. package/dist/scripts/anyswarm-tui-config.d.ts +0 -36
  289. package/dist/scripts/anyswarm-tui-config.js +0 -189
  290. package/dist/scripts/anyswarm-tui-session.d.ts +0 -66
  291. package/dist/scripts/anyswarm-tui-session.js +0 -304
  292. package/dist/scripts/anyswarm-tui-terminal.d.ts +0 -41
  293. package/dist/scripts/anyswarm-tui-terminal.js +0 -154
  294. package/dist/scripts/anyswarm-tui.d.ts +0 -2
  295. package/dist/scripts/anyswarm-tui.js +0 -1012
  296. package/docs/architecture/25-foreground-tui.md +0 -51
  297. package/scripts/anyswarm-applications.ts +0 -39
  298. package/scripts/anyswarm-tui-config.ts +0 -174
  299. package/scripts/anyswarm-tui-session.ts +0 -295
  300. package/scripts/anyswarm-tui-terminal.ts +0 -147
  301. package/scripts/anyswarm-tui.ts +0 -912
@@ -1,4 +1,4 @@
1
- import { ProjectPreflightError, resolveSandboxConnection, workerImageFor, type ExecutorSelection,
1
+ import { ProjectPreflightError, resolveSandboxConnection, workerImageFor, type ExecutorSelection, type HarnessContext,
2
2
  type ModelConfig, type RuntimeConnectionOptions, type SandboxConfig } from '@anyswarm/core';
3
3
  import { homedir } from 'node:os';
4
4
  import { join, resolve } from 'node:path';
@@ -14,6 +14,7 @@ export interface ResearchBudget {
14
14
  export interface ResearchConfiguration {
15
15
  targetPath?: string;
16
16
  requiredFiles?: readonly string[];
17
+ validateStarter?(initial: HarnessContext['initial']): Promise<void>;
17
18
  goal: string;
18
19
  direction: 'max' | 'min';
19
20
  targetScore?: number;
@@ -27,14 +28,18 @@ export interface ResearchConfiguration {
27
28
  evaluationTimeoutMs?: number;
28
29
  closeTimeoutMs?: number;
29
30
  restrictNetwork?: boolean;
31
+ continueAfterTrainBudget?: boolean;
30
32
  }
31
33
 
32
34
  export const demoBudget: Readonly<ResearchBudget> = Object.freeze({
33
35
  workers: 4, workMs: 720_000, maxEvaluations: 8,
34
36
  });
35
- export function frontierBudget(saved: ResearchBudget = demoBudget): ResearchBudget {
36
- const { workers, workMs, maxEvaluations } = saved;
37
- return checkBudget({ workers, workMs, maxEvaluations }, 4);
37
+ export const smallBudget: Readonly<ResearchBudget> = Object.freeze({
38
+ workers: 2, workMs: 720_000, maxEvaluations: 4, maxModelRequests: 128,
39
+ });
40
+
41
+ export function frontierBudget(budget: ResearchBudget = demoBudget): ResearchBudget {
42
+ return checkBudget(budget, 2);
38
43
  }
39
44
  export const demoGoal = 'Solve the official FrontierCS-2 binary_fuse_filter task described in README.md. The 8-bit and 16-bit population routines in include/binaryfusefilter.h are stubs. Implement both routines and send a complete first patch to public train promptly. If a local C compiler is unavailable, use train for compile and correctness feedback. Then explore memory, construction or lookup performance. Change only include/, coordinate directly and review peers’ patches against the official public train feedback.';
40
45
  export const demoCloseTimeoutMs = 365_000;
@@ -44,36 +49,70 @@ export function frontierHome() {
44
49
  join(process.env.XDG_STATE_HOME ?? join(homedir(), '.local', 'state'), 'anyswarm', 'autoresearch', 'frontiercs2'));
45
50
  }
46
51
 
47
- export function defaultResearchConnection() {
48
- const saved = resolveSandboxConnection({}, 'AUTORESEARCH');
52
+ type ResearchConnection = Pick<ResearchConfiguration, 'executor' | 'image' | 'sandbox' | 'connection'>;
53
+
54
+ export function defaultResearchConnection(options: Partial<ResearchConnection> = {}) {
55
+ const { sandbox, connection } = options;
56
+ const saved = resolveSandboxConnection({
57
+ ...sandbox, publicUrl: connection?.publicUrl, advertiseHost: connection?.advertiseHost, image: options.image,
58
+ }, 'AUTORESEARCH', { includePreparedImage: true });
59
+ const executor = options.executor ?? saved.executor ?? 'pi';
60
+ const kind = typeof executor === 'string' ? executor : executor.kind;
49
61
  return {
50
- executor: saved.executor ?? 'pi',
51
- image: saved.image ?? workerImageFor(saved.executor ?? 'pi'),
62
+ executor,
63
+ image: saved.image ?? workerImageFor(executor),
64
+ // Setup records the immutable image separately from the Runtime's local Worker selector.
65
+ preparedWorker: saved.image === undefined && saved.executor === kind ? saved.preparedImage : undefined,
52
66
  sandbox: {
67
+ ...sandbox, endpoint: undefined,
53
68
  lifecycleBaseUrl: saved.lifecycleBaseUrl, apiKey: saved.apiKey,
54
69
  useServerProxy: saved.useServerProxy, egressMode: saved.egressMode,
55
- resourceLimits: { cpu: '2', memory: '4Gi' },
70
+ resourceLimits: sandbox?.resourceLimits ?? { cpu: '2', memory: '4Gi' },
56
71
  },
57
- connection: { publicUrl: saved.publicUrl, advertiseHost: saved.advertiseHost },
58
- } satisfies Pick<ResearchConfiguration, 'executor' | 'image' | 'sandbox' | 'connection'>;
72
+ connection: { ...connection, publicUrl: saved.publicUrl, advertiseHost: saved.advertiseHost },
73
+ } satisfies ResearchConnection & { preparedWorker?: string };
74
+ }
75
+
76
+ export function modelFromEnvironment(env = process.env): ModelConfig {
77
+ const protocol = env.ANYSWARM_MODEL_PROTOCOL as ModelConfig['protocol'];
78
+ const token = env.ANYSWARM_MODEL_TOKEN;
79
+ return {
80
+ provider: env.ANYSWARM_MODEL_PROVIDER ?? '',
81
+ model: env.ANYSWARM_MODEL_ID ?? '',
82
+ protocol,
83
+ upstream: { url: env.ANYSWARM_MODEL_URL ?? '', headers: token ? { authorization: `Bearer ${token}` } : {} },
84
+ };
59
85
  }
60
86
 
61
- export function kimiModel(): ModelConfig {
62
- const url = process.env.ANYSWARM_MODEL_URL;
63
- if (!url) throw new ProjectPreflightError('AUTORESEARCH_MODEL_REQUIRED', 'Set ANYSWARM_MODEL_URL for the Kimi K3 route and ANYSWARM_MODEL_TOKEN if required by your proxy.');
64
- const provider = process.env.ANYSWARM_MODEL_PROVIDER ?? 'kimi_proxy';
65
- const model = process.env.ANYSWARM_MODEL_ID ?? 'k3';
66
- if (provider !== 'kimi_proxy' || model !== 'k3') {
67
- throw new ProjectPreflightError('AUTORESEARCH_K3_REQUIRED', 'Select the kimi_proxy/k3 model for the FrontierCS-2 demo.');
87
+ export function modelConfigurationError(model: ModelConfig | undefined, executor?: ExecutorSelection) {
88
+ if (!model?.provider?.trim() || !model.model?.trim() || !model.upstream?.url || !model.upstream.headers) {
89
+ return 'Set model.provider, model.model and model.upstream in the shared configuration, or set ANYSWARM_MODEL_PROVIDER, ANYSWARM_MODEL_ID and ANYSWARM_MODEL_URL. Set ANYSWARM_MODEL_TOKEN if your endpoint requires a token.';
90
+ }
91
+ const url = URL.canParse(model.upstream.url) ? new URL(model.upstream.url) : undefined;
92
+ if (!url || !['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
93
+ return 'Use a full HTTP(S) request URL in model.upstream.url. Put credentials in protected headers instead of the URL.';
94
+ }
95
+ const protocol = typeof model.protocol === 'object' ? model.protocol.clientProtocol : model.protocol ?? 'responses';
96
+ const backend = typeof executor === 'object' ? executor.kind : executor;
97
+ if ((!protocol && typeof model.protocol !== 'object') || (backend === 'codex' && protocol !== 'responses') ||
98
+ (backend === 'pi' && protocol !== 'responses' && protocol !== 'chat-completions')) {
99
+ return 'Select a model protocol supported by your backend. Codex uses Responses. Pi supports Responses and Chat Completions.';
100
+ }
101
+ const suffix = protocol === 'chat-completions' ? '/v1/chat/completions' : '/v1/responses';
102
+ if (typeof model.protocol === 'object' ? model.protocol.validateUpstream(url) !== true : !url.pathname.endsWith(suffix)) {
103
+ return `Set the full model request URL for the selected protocol, ending in ${suffix} for the built-in transport.`;
104
+ }
105
+ if (model.provider === 'kimi_proxy' && model.model === 'k3' && protocol !== 'responses') {
106
+ return 'The kimi_proxy/k3 configuration requires a fixed /v1/responses URL without a query string.';
68
107
  }
69
- const endpoint = URL.canParse(url) ? new URL(url) : undefined;
70
- if (!endpoint || !['http:', 'https:'].includes(endpoint.protocol) || endpoint.username || endpoint.password ||
71
- endpoint.search || endpoint.hash || !endpoint.pathname.endsWith('/v1/responses')) {
72
- throw new ProjectPreflightError('AUTORESEARCH_MODEL_URL_INVALID',
73
- 'Set ANYSWARM_MODEL_URL to a fixed HTTP(S) /v1/responses endpoint without credentials, query or fragment.');
108
+ if (model.capabilities?.tools === false) return 'Select a tool-capable model so peers can work on files and use the research Service.';
109
+ if (model.capabilities && (!Number.isSafeInteger(model.capabilities.contextWindow) ||
110
+ model.capabilities.contextWindow < 16 || !Number.isSafeInteger(model.capabilities.maxOutputTokens) ||
111
+ model.capabilities.maxOutputTokens < 16 || model.capabilities.maxOutputTokens > model.capabilities.contextWindow ||
112
+ typeof model.capabilities.reasoning !== 'boolean' || model.capabilities.tools !== true)) {
113
+ return 'Set capabilities from your provider catalog: contextWindow, maxOutputTokens, tools: true and reasoning.';
74
114
  }
75
- const token = process.env.ANYSWARM_MODEL_TOKEN;
76
- return { provider, model, upstream: { url: endpoint.href, headers: token ? { authorization: `Bearer ${token}` } : {} } };
115
+ return undefined;
77
116
  }
78
117
 
79
118
  export function checkBudget(budget: ResearchBudget, minimum = 1): ResearchBudget {
@@ -1,8 +1,12 @@
1
1
  import type { JsonValue } from '@anyswarm/core';
2
- import { join } from 'node:path';
3
- import { defaultResearchConnection, demoCloseTimeoutMs, demoGoal, kimiModel, type ResearchConfiguration } from './config.js';
4
- import { FrontierRun, frontierFinalTimeMs, frontierSubmission, judgeTimeMs } from './frontiercs2.js';
5
- import { loadPrepared, resourcePlan } from './prepare.js';
2
+ import type { FinalEvaluation } from './research-service.js';
3
+ import { readFile } from 'node:fs/promises';
4
+ import { join, resolve } from 'node:path';
5
+ import { ProjectPreflightError } from '@anyswarm/core';
6
+ import { defaultResearchConnection, demoCloseTimeoutMs, demoGoal, frontierBudget, frontierHome, modelConfigurationError, modelFromEnvironment, type ResearchConfiguration } from './config.js';
7
+ import { command, requireSuccess } from './process.js';
8
+ import { digest, FrontierRun, frontierFinalTimeMs, frontierSubmission, judgeTimeMs } from './frontiercs2.js';
9
+ import { loadPrepared, resourcePlan, starterPath } from './prepare.js';
6
10
 
7
11
  export function frontierTrainEvaluation(returned: Record<string, unknown>) {
8
12
  const observed = returned.raw_score;
@@ -16,40 +20,89 @@ export function frontierTrainEvaluation(returned: Record<string, unknown>) {
16
20
  };
17
21
  }
18
22
 
19
- export async function frontierDemo() {
20
- const ready = await loadPrepared().catch(() => { throw new Error('Prepare the pinned demo first with anys -u autoresearch --cmd /prepare.'); });
21
- const { budget, paths, saved, starter } = ready;
22
- const defaults = defaultResearchConnection();
23
- const model = kimiModel();
23
+ export function frontierFinalEvaluation(result: Awaited<ReturnType<FrontierRun['finish']>>, targetScore?: number): FinalEvaluation {
24
+ const values = new Map(result.verdict.result?.values?.map(({ name, value }) => [name, value]));
25
+ const reportedScore = values.get('score');
26
+ const score = typeof reportedScore === 'number' && Number.isFinite(reportedScore) ? reportedScore : null;
27
+ const reportedSummary = values.get('summary');
28
+ const summary = typeof reportedSummary === 'string' ? reportedSummary : null;
29
+ const beatsReference = values.get('beats_reference');
30
+ const evidence = { record: result.record, payload: result.submission.payload, summary,
31
+ beatsReference: beatsReference === 1 ? true : beatsReference === 0 ? false : null };
32
+ if (summary?.startsWith('invalid candidate:')) return { status: 'rejected', score, meetsObjective: false, evidence };
33
+ if (score === null || !(summary === 'strict PASS' || summary?.startsWith('valid;'))) {
34
+ return { status: 'unknown', score: null, meetsObjective: null, evidence };
35
+ }
36
+ return { status: 'valid', score, meetsObjective: targetScore === undefined ? null : score >= targetScore, evidence };
37
+ }
38
+
39
+ export interface FrontierConfiguration extends ResearchConfiguration {
40
+ frontierStateDir: string;
41
+ preparedWorker?: string;
42
+ }
43
+
44
+ type FrontierOptions = Partial<Pick<ResearchConfiguration,
45
+ 'budget' | 'model' | 'goal' | 'executor' | 'image' | 'sandbox' | 'connection' | 'continueAfterTrainBudget' | 'targetScore'>> &
46
+ { home?: string };
47
+
48
+ export function frontierDemo(options: FrontierOptions = {}): FrontierConfiguration {
49
+ const { home: stateDir = frontierHome(), executor, image, sandbox: worker, connection, ...settings } = options;
50
+ const home = resolve(stateDir);
51
+ const defaults = defaultResearchConnection({ executor, image, sandbox: worker, connection });
52
+ const budget = frontierBudget(settings.budget);
53
+ const model = settings.model ?? modelFromEnvironment();
54
+ const { sandbox } = defaults;
55
+ // The official bridge starts before the Workers. Budget startup, one active
56
+ // judge at the stop boundary, final and cleanup independently of research.
57
+ const setupSeconds = 360;
58
+ const settleSeconds = Math.ceil((judgeTimeMs + frontierFinalTimeMs + demoCloseTimeoutMs) / 1000);
59
+ const lifetimeSeconds = setupSeconds + Math.ceil(budget.workMs / 1000) + settleSeconds;
24
60
  let frontier: FrontierRun | undefined;
25
- const configuration: ResearchConfiguration = {
26
- ...defaults, model, restrictNetwork: true, goal: demoGoal, direction: 'max', budget,
27
- sandbox: { ...defaults.sandbox, timeoutSeconds: Math.ceil((budget.workMs + demoCloseTimeoutMs) / 1000) + 60 },
28
- targetPath: starter,
61
+ let ready: Awaited<ReturnType<typeof loadPrepared>> | undefined;
62
+ return {
63
+ ...defaults, ...settings, model, restrictNetwork: true, goal: settings.goal ?? demoGoal, direction: 'max', budget,
64
+ sandbox: { ...sandbox, timeoutSeconds: sandbox.timeoutSeconds ?? lifetimeSeconds },
65
+ frontierStateDir: home,
66
+ targetPath: starterPath(home),
29
67
  requiredFiles: ['README.md', 'include/binaryfusefilter.h'],
68
+ async validateStarter(initial) {
69
+ ready = await loadPrepared(home);
70
+ const tracked = requireSuccess(await command('git', ['ls-files', '-z', '--', '.'],
71
+ { cwd: ready.starter, timeoutMs: 5000 }), 'Read tracked FrontierCS-2 starter files').split('\0').filter(Boolean);
72
+ const captured = new Map(initial.manifest.map(file => [file.path, file.sha256]));
73
+ const expected = await Promise.all(tracked.map(async file => [file, digest(await readFile(join(ready!.starter, file)))] as const));
74
+ if (captured.size !== expected.length || expected.some(([path, hash]) => captured.get(path) !== hash)) {
75
+ throw new ProjectPreflightError('AUTORESEARCH_STARTER_CHANGED', 'Use the prepared, unchanged FrontierCS-2 starter. Remove --cwd when running the FrontierCS-2 configuration.');
76
+ }
77
+ },
30
78
  evaluationTimeoutMs: judgeTimeMs + 25_000,
31
79
  closeTimeoutMs: demoCloseTimeoutMs,
32
80
  evaluator: {
33
81
  async start(directory, signal) {
34
- frontier = new FrontierRun(paths, join(directory, 'pumpkin'));
35
- await frontier.start(Math.ceil((budget.workMs + frontierFinalTimeMs) / 1000), signal);
36
- if (frontier.imageId !== saved.bridgeImage || JSON.stringify(frontier.judges) !== JSON.stringify(saved.judges)) {
37
- throw new Error('Pumpkin image identity changed after preparation');
82
+ const problem = modelConfigurationError(model, defaults.executor);
83
+ if (problem) throw new ProjectPreflightError('AUTORESEARCH_MODEL_REQUIRED', problem);
84
+ ready ??= await loadPrepared(home);
85
+ frontier = new FrontierRun(ready.paths, join(directory, 'pumpkin'));
86
+ await frontier.start(lifetimeSeconds, signal, undefined, budget.maxEvaluations);
87
+ if (frontier.imageId !== ready.saved.bridgeImage || JSON.stringify(frontier.judges) !== JSON.stringify(ready.saved.judges)) {
88
+ throw new Error('Pumpkin image identity changed after preparation. Run prepare again.');
38
89
  }
39
90
  },
40
91
  async train(patch, signal, admitted) {
41
92
  const receipt = await frontier!.train(frontierSubmission(patch), signal, admitted);
42
- return frontierTrainEvaluation(receipt.returned);
93
+ return { ...frontierTrainEvaluation(receipt.returned), payload: receipt.payload };
43
94
  },
44
95
  async final(patch, signal) {
45
- return await frontier!.finish(frontierSubmission(patch), signal) as unknown as JsonValue;
96
+ return frontierFinalEvaluation(await frontier!.finish(frontierSubmission(patch), signal), settings.targetScore);
46
97
  },
47
98
  async close() { return frontier ? await frontier.close() : 'complete'; },
48
99
  evidence() {
49
- return { reference: saved.referenceRecord, record: frontier?.record ?? null, bridgeImage: frontier?.imageId ?? null, judges: frontier?.judges ?? null,
50
- benchmark: saved.revision, pumpkin: saved.pumpkin, resources: resourcePlan(budget) };
100
+ return {
101
+ reference: ready?.saved.referenceRecord ?? null, record: frontier?.record ?? null, bridgeImage: frontier?.imageId ?? null,
102
+ judges: frontier?.judges ?? null, grants: frontier?.grants ?? null, cleanup: frontier?.cleanupEvidence ?? null,
103
+ benchmark: ready?.saved.revision ?? null, pumpkin: ready?.saved.pumpkin ?? null, resources: resourcePlan(budget, sandbox),
104
+ };
51
105
  },
52
106
  },
53
107
  };
54
- return { configuration, starter };
55
108
  }
@@ -9,6 +9,8 @@
9
9
  "research-service.ts",
10
10
  "demo.ts",
11
11
  "prepare.ts",
12
+ "prepare-demo.ts",
13
+ "frontiercs2-config.ts",
12
14
  "frontiercs2.ts",
13
15
  "process.ts"
14
16
  ]
@@ -0,0 +1,15 @@
1
+ import { frontierDemo } from './demo.js';
2
+ import { modelFromEnvironment, smallBudget } from './config.js';
3
+
4
+ export default frontierDemo({
5
+ // Run anyswarm setup to choose an executor and Worker, or set executor, image,
6
+ // sandbox and connection here for an existing OpenSandbox deployment.
7
+ // Set ANYSWARM_MODEL_PROVIDER, ANYSWARM_MODEL_ID and ANYSWARM_MODEL_URL.
8
+ // Optional: ANYSWARM_MODEL_PROTOCOL (responses by default) and ANYSWARM_MODEL_TOKEN.
9
+ // You can replace this model with your own ModelConfig, including capabilities
10
+ // from your provider catalog for a reasoning model. Keep tokens in the environment.
11
+ model: modelFromEnvironment(),
12
+ budget: { ...smallBudget },
13
+ // For timed runs, set continueAfterTrainBudget: true to keep reviewing and
14
+ // testing locally after the last train admission, within the model budget.
15
+ });
@@ -1,5 +1,6 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
- import { mkdir, readFile, readdir, writeFile } from 'node:fs/promises';
2
+ import { constants } from 'node:fs';
3
+ import { mkdir, open, readFile, readdir, writeFile } from 'node:fs/promises';
3
4
  import { join } from 'node:path';
4
5
  import { setTimeout as delay } from 'node:timers/promises';
5
6
  import { command, requireSuccess } from './process.js';
@@ -8,9 +9,28 @@ export const frontierRevision = '7e48965c7cef2a567c2669c8e2f10b06386289c9';
8
9
  export const pumpkinPin = '2026-11-30 ca3ce7ae0da5616464b00ee7962aecac0fc0b38d a1bb9c633f1f700ea42bceb9cd9512f684e9063d3a8ae6c9485526a1dd68016f';
9
10
  export const frontierTask = 'tasks/binary_fuse_filter/task.star';
10
11
  export const submissionLimit = 1024 * 1024;
12
+ const officialJudgeSeconds = 180;
13
+ const grantCallTimeoutSeconds = 181;
11
14
  export const judgeTimeMs = 190_000;
12
15
  export const frontierFinalTimeMs = 250_000;
13
16
 
17
+ export async function preparePumpkin(source: string, cache: string, signal: AbortSignal) {
18
+ await mkdir(cache, { recursive: true, mode: 0o700 });
19
+ // The pinned launcher extracts with the caller's umask. Only the bootstrap
20
+ // needs 022; prepare and the official evaluation keep the operator's umask.
21
+ requireSuccess(await command('/bin/sh', ['-c', 'umask 022; exec ./pumpkin --version'], {
22
+ cwd: source, env: { ...process.env, XDG_CACHE_HOME: cache }, timeoutMs: 240_000, signal,
23
+ }), 'Initialize pinned Pumpkin tools');
24
+ // Repair a cache populated by an earlier prepare under a restrictive umask.
25
+ const checksum = pumpkinPin.split(' ')[2];
26
+ const binary = await open(join(cache, 'pumpkin', checksum, 'bin', 'sandboxd'), constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
27
+ try {
28
+ const info = await binary.stat();
29
+ if (!info.isFile()) throw new Error('The pinned Pumpkin sandboxd is not a regular file');
30
+ if ((info.mode & 0o111) !== 0o111) await binary.chmod((info.mode & 0o777) | 0o111);
31
+ } finally { await binary.close(); }
32
+ }
33
+
14
34
  export function digest(bytes: Uint8Array | string): string {
15
35
  return createHash('sha256').update(bytes).digest('hex');
16
36
  }
@@ -110,6 +130,9 @@ export class FrontierRun {
110
130
  container?: string;
111
131
  imageId?: string;
112
132
  judges?: JudgeImages;
133
+ grants?: { trainCalls: number; trainCumulativeSeconds: number; judgeSeconds: number; callTimeoutSeconds: number; maxBytes: number };
134
+ cleanupEvidence: { status: 'complete' | 'pending'; runIds: string[]; pendingContainers: string[] } =
135
+ { status: 'pending', runIds: [], pendingContainers: [] };
113
136
  private closed = false;
114
137
 
115
138
  constructor(readonly paths: FrontierPaths, readonly runs: string) {}
@@ -124,7 +147,7 @@ export class FrontierRun {
124
147
 
125
148
  get record() { return this.id ? join(this.runs, this.id) : undefined; }
126
149
 
127
- async start(seconds: number, signal: AbortSignal, timeoutMs = 360_000): Promise<void> {
150
+ async start(seconds: number, signal: AbortSignal, timeoutMs = 360_000, maxEvaluations = 1): Promise<void> {
128
151
  await mkdir(this.runs, { recursive: true, mode: 0o700 });
129
152
  const start = await this.pumpkin(['run', frontierTask, '--arg', 'agent=anyswarm', '--arg', `deadline_seconds=${seconds}`,
130
153
  '--config', this.paths.config, '--runs', this.runs], timeoutMs, signal);
@@ -147,11 +170,14 @@ export class FrontierRun {
147
170
  const role = ir.roles?.find((role: { name: string }) => role.name === 'agent');
148
171
  const grantTrain = role?.runtime?.agent?.grants?.find((grant: { name: string }) => grant.name === 'train');
149
172
  const grantFinal = role?.runtime?.agent?.grants?.find((grant: { name: string }) => grant.name === 'final');
150
- if (grantTrain?.job?.target !== 'train_judge' || !(grantTrain.job.calls >= 8) ||
173
+ if (grantTrain?.job?.target !== 'train_judge' || !(grantTrain.job.calls >= maxEvaluations) ||
174
+ grantTrain.job.cumulative_seconds !== 12_000 || grantTrain.job.call_timeout_seconds !== grantCallTimeoutSeconds ||
151
175
  grantTrain.job.payload_max_bytes !== submissionLimit || grantFinal?.now?.payload_max_bytes !== submissionLimit ||
152
176
  grantFinal.now.body?.arguments?.finalize?.type !== 'bool' || ir.final?.target !== undefined && ir.final.target !== 'final_judge') {
153
- throw new Error('The Pumpkin role does not have the pinned train and final grants');
177
+ throw new Error('The Pumpkin role does not authorize the requested train budget or the pinned judge limits');
154
178
  }
179
+ this.grants = { trainCalls: grantTrain.job.calls, trainCumulativeSeconds: grantTrain.job.cumulative_seconds,
180
+ judgeSeconds: officialJudgeSeconds, callTimeoutSeconds: grantTrain.job.call_timeout_seconds, maxBytes: grantTrain.job.payload_max_bytes };
155
181
  const grants = await this.docker(['exec', this.container, '/bin/sh', '-eu', '-c',
156
182
  'test -w /pumpkin; exec /.pumpkin/bin/sandboxctl ops'], 5_000, started);
157
183
  const ops = JSON.parse(requireSuccess(grants, 'Check official Pumpkin grants and submission scratch space'));
@@ -180,7 +206,26 @@ export class FrontierRun {
180
206
  const reply = await this.docker(['exec', this.container!, '/.pumpkin/bin/sandboxctl', 'status', String(job)], 5_000, deadline);
181
207
  const state = JSON.parse(reply.stdout) as PumpkinReply;
182
208
  if (state.kind !== 'status' || state.job !== job) throw new Error('Official train status is unknown');
183
- if (state.state === 'completed' && state.returned) return { job, returned: state.returned };
209
+ if (state.state === 'completed' && state.returned) {
210
+ const payload = { digest: `sha256:${digest(bytes)}`, size: bytes.byteLength };
211
+ // A score can be available while Pumpkin is still releasing the job's
212
+ // sandbox. The next admission is safe only after the recorded teardown.
213
+ while (true) {
214
+ const log = await readFile(join(this.record!, 'log.jsonl'), { encoding: 'utf8', signal: deadline });
215
+ const lines = log.split('\n');
216
+ lines.pop(); // The last line may still be in flight.
217
+ const entries = lines.map(line => JSON.parse(line));
218
+ const action = entries.flatMap(entry => entry.actions ?? [])
219
+ .find(entry => entry.kind === 'start_call' && entry.grant === 'train' && entry.job === job);
220
+ if (action?.payload?.digest !== payload.digest || action.payload.size !== payload.size) {
221
+ throw new Error('Official train result does not match the submitted payload');
222
+ }
223
+ if (entries.some(({ event }) => event?.kind === 'call_torn_down' && event.job === job)) {
224
+ return { job, returned: state.returned, payload };
225
+ }
226
+ await delay(250, undefined, { signal: deadline });
227
+ }
228
+ }
184
229
  if (state.state === 'errored') throw new Error(`Official train job ${job} failed`);
185
230
  if (state.state !== 'queued' && state.state !== 'running') throw new Error(`Official train job ${job} has an unknown status`);
186
231
  await delay(750, undefined, { signal: deadline });
@@ -212,17 +257,25 @@ export class FrontierRun {
212
257
  }
213
258
 
214
259
  async close(): Promise<'complete' | 'pending'> {
260
+ this.cleanupEvidence = { status: 'pending', runIds: [], pendingContainers: [] };
215
261
  try {
216
- const ids = this.id ? [this.id] : (await readdir(this.runs, { withFileTypes: true }).catch(() => []))
217
- .filter(entry => entry.isDirectory() && runId.test(entry.name)).map(entry => entry.name);
262
+ const ids = this.id ? [this.id] : (await readdir(this.runs, { withFileTypes: true }).catch(error => {
263
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return [];
264
+ throw error;
265
+ })).filter(entry => entry.isDirectory() && runId.test(entry.name)).map(entry => entry.name);
266
+ this.cleanupEvidence.runIds = ids;
267
+ let confirmed = true;
218
268
  for (const id of ids) {
219
269
  const finished = this.closed || await readFile(join(this.runs, id, 'outcome.json'), 'utf8')
220
270
  .then(raw => JSON.parse(raw).state === 'finished').catch(() => false);
221
- if (!finished) await this.pumpkin(['cancel', '--runs', this.runs, id], 20_000).catch(() => {});
222
- const remaining = await this.docker(['container', 'ls', '-a', '--filter', `label=pumpkin.run=${id}`, '--format', '{{.ID}}'], 5_000);
223
- if (remaining.code !== 0 || remaining.stdout.trim()) return 'pending';
271
+ const cancelled = finished || (await this.pumpkin(['cancel', '--runs', this.runs, id], 20_000).catch(() => undefined))?.code === 0;
272
+ const remaining = await this.docker(['container', 'ls', '-a', '--no-trunc', '--filter', `label=pumpkin.run=${id}`, '--format', '{{.ID}}'], 5_000)
273
+ .catch(() => undefined);
274
+ if (!cancelled || remaining?.code !== 0) confirmed = false;
275
+ if (remaining?.code === 0) this.cleanupEvidence.pendingContainers.push(...remaining.stdout.trim().split('\n').filter(Boolean));
224
276
  }
225
- return 'complete';
277
+ if (confirmed && !this.cleanupEvidence.pendingContainers.length) this.cleanupEvidence.status = 'complete';
278
+ return this.cleanupEvidence.status;
226
279
  } catch { return 'pending'; }
227
280
  }
228
281
  }
@@ -0,0 +1,44 @@
1
+ import { resolve } from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { parseArgs } from 'node:util';
4
+ import type { FrontierConfiguration } from './demo.js';
5
+ import { prepareFrontier } from './prepare.js';
6
+
7
+ const controller = new AbortController();
8
+ const interrupt = (signal: NodeJS.Signals) => {
9
+ process.exitCode = signal === 'SIGINT' ? 130 : 143;
10
+ controller.abort();
11
+ };
12
+ process.on('SIGINT', interrupt).on('SIGTERM', interrupt);
13
+ try {
14
+ const { values } = parseArgs({ options: {
15
+ config: { type: 'string', default: './frontiercs2-config.ts' },
16
+ check: { type: 'boolean' },
17
+ help: { type: 'boolean' },
18
+ } });
19
+ if (values.help) {
20
+ console.log('Usage: anyswarm run ./prepare-demo.ts [--config ./frontiercs2-config.ts] [--check]');
21
+ console.log('Choose an executor with anyswarm setup, then set a model and a team budget in the shared configuration. --check reports prerequisites without preparing the pinned task or calling a model.');
22
+ } else {
23
+ const { default: configuration } = await import(pathToFileURL(resolve(values.config)).href) as { default: FrontierConfiguration };
24
+ if (!configuration?.frontierStateDir || !configuration.budget || !configuration.sandbox || !configuration.connection) {
25
+ throw new Error('The configuration must default-export frontierDemo({ model, budget, ... }). See frontiercs2-config.ts.');
26
+ }
27
+ const report = await prepareFrontier({ configuration, checkOnly: values.check, signal: controller.signal, progress: console.error });
28
+ for (const row of report.checks) console.error(`${row.ok ? 'OK' : 'ACTION'} ${row.name}: ${row.detail}`);
29
+ console.error('Model inference was not attempted.');
30
+ if (report.ok && !values.check) {
31
+ console.error('Prepared. Use the same configuration with anyswarm run ./project.ts --config <your-config> --prompt "Run the FrontierCS-2 task." --output-dir ./runs');
32
+ }
33
+ console.log(JSON.stringify(report, null, 2));
34
+ process.exitCode ??= report.ok ? 0 : 2;
35
+ }
36
+ } catch (error) {
37
+ if (!controller.signal.aborted) {
38
+ console.error(error instanceof Error ? error.message : 'Could not load the FrontierCS-2 configuration.');
39
+ console.error('Check the exported frontiercs2-config.ts and run anyswarm setup or anyswarm doctor for your backend.');
40
+ process.exitCode = 2;
41
+ }
42
+ } finally {
43
+ process.off('SIGINT', interrupt).off('SIGTERM', interrupt);
44
+ }