@wenathlan/devthink 2.0.15 → 2.0.19

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 (444) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/{dist/bridge.d.ts → bridge.d.ts} +1 -1
  3. package/bridge.d.ts.map +1 -0
  4. package/bridge.js +1877 -0
  5. package/bun.d.ts.map +1 -0
  6. package/bun.js +52329 -0
  7. package/caps/background.json +712 -0
  8. package/caps/cli.json +360 -0
  9. package/caps/library.json +3611 -0
  10. package/caps/mcp.json +126 -0
  11. package/caps/pagebridge.json +377 -0
  12. package/caps/popup.json +51 -0
  13. package/caps/sidepanel.json +522 -0
  14. package/checksums.txt +142 -0
  15. package/cli.d.ts.map +1 -0
  16. package/{dist/cli.js → cli.js} +2 -2
  17. package/companion.d.ts.map +1 -0
  18. package/companion.js +389 -0
  19. package/crossbrowser.d.ts.map +1 -0
  20. package/crossbrowser.js +1191 -0
  21. package/dashdone.d.ts.map +1 -0
  22. package/dashdone.js +368 -0
  23. package/deno.d.ts.map +1 -0
  24. package/deno.js +52325 -0
  25. package/devthink.umd.js +52346 -0
  26. package/fixtures/bun.ts +7 -0
  27. package/fixtures/cjs.js +6 -0
  28. package/fixtures/deno.ts +6 -0
  29. package/fixtures/example-org-pagestate.json +22 -0
  30. package/fixtures/importers/automa-workflow.json +18 -0
  31. package/fixtures/importers/selenium-side.json +20 -0
  32. package/fixtures/importers/tabular-plan.csv +7 -0
  33. package/fixtures/importers/uivision-macro.json +10 -0
  34. package/fixtures/importers/v1-plan.json +13 -0
  35. package/fixtures/mcp-client.mjs +14 -0
  36. package/fixtures/pages/checkout.html +192 -0
  37. package/fixtures/pages/dashboard.html +110 -0
  38. package/fixtures/pages/feed.html +113 -0
  39. package/fixtures/pages/product-grid.html +150 -0
  40. package/fixtures/plans/form-inventory-plan.json +11 -0
  41. package/fixtures/plans/release-notes-plan.json +11 -0
  42. package/fixtures/recipes/agentscompete.json +11 -0
  43. package/fixtures/recipes/agentsforms.json +11 -0
  44. package/fixtures/recipes/agentsmonitor.json +11 -0
  45. package/fixtures/recipes/agentsreview.json +29 -0
  46. package/fixtures/recipes/agentswarm.json +11 -0
  47. package/fixtures/recipes/fillcalendar.json +12 -0
  48. package/fixtures/recipes/fillcheckout.json +13 -0
  49. package/fixtures/recipes/filldependentdropdowns.json +12 -0
  50. package/fixtures/recipes/fillfromcsv.json +13 -0
  51. package/fixtures/recipes/fillloginform.json +12 -0
  52. package/fixtures/recipes/fillmultistepwizard.json +13 -0
  53. package/fixtures/recipes/fillregistration.json +12 -0
  54. package/fixtures/recipes/fillsearchfilters.json +12 -0
  55. package/fixtures/recipes/filltypeahead.json +11 -0
  56. package/fixtures/recipes/monitoralerts.json +12 -0
  57. package/fixtures/recipes/monitoravailability.json +11 -0
  58. package/fixtures/recipes/monitornetworkquiet.json +12 -0
  59. package/fixtures/recipes/monitorpagechanges.json +11 -0
  60. package/fixtures/recipes/monitorpricechange.json +11 -0
  61. package/fixtures/recipes/monitorschedule.json +12 -0
  62. package/fixtures/recipes/scrapedynamicprices.json +13 -0
  63. package/fixtures/recipes/scrapeimagegallery.json +12 -0
  64. package/fixtures/recipes/scrapeinfinitefeed.json +13 -0
  65. package/fixtures/recipes/scrapenestedlists.json +12 -0
  66. package/fixtures/recipes/scrapeproductgrid.json +12 -0
  67. package/fixtures/recipes/scrapereviews.json +12 -0
  68. package/fixtures/recipes/scrapesearchresults.json +12 -0
  69. package/fixtures/recipes/scrapetablepagination.json +12 -0
  70. package/fixtures/recipes/testaccessibility.json +34 -0
  71. package/fixtures/recipes/testconsoleerrors.json +12 -0
  72. package/fixtures/recipes/testdeeplinks.json +12 -0
  73. package/fixtures/recipes/testformvalidation.json +13 -0
  74. package/fixtures/recipes/testlayoutshift.json +12 -0
  75. package/fixtures/recipes/testlinkcheck.json +12 -0
  76. package/fixtures/recipes/testloadtiming.json +12 -0
  77. package/fixtures/recipes/testvisualdiff.json +12 -0
  78. package/fixtures/workflows/changelog-digest-workflow.json +13 -0
  79. package/fixtures/workflows/form-survey-workflow.json +13 -0
  80. package/gallery.json +706 -0
  81. package/hardening.d.ts.map +1 -0
  82. package/hardening.js +188 -0
  83. package/headless.d.ts.map +1 -0
  84. package/headless.js +11522 -0
  85. package/http.d.ts.map +1 -0
  86. package/http.js +2165 -0
  87. package/index.cjs +54682 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +52310 -0
  90. package/index.neutral.js +46343 -0
  91. package/{web/manifest.json → manifest.json} +1 -1
  92. package/mcp.d.ts.map +1 -0
  93. package/mcp.js +20515 -0
  94. package/memory.d.ts.map +1 -0
  95. package/{memory.ts → memory.js} +2310 -3834
  96. package/nativehost.template.json +10 -0
  97. package/node.cjs +54686 -0
  98. package/node.d.ts.map +1 -0
  99. package/pack.d.ts.map +1 -0
  100. package/pack.js +805 -0
  101. package/package.json +83 -176
  102. package/policy.d.ts.map +1 -0
  103. package/{policy.ts → policy.js} +4679 -5073
  104. package/progress.d.ts.map +1 -0
  105. package/progress.js +645 -0
  106. package/protocol.d.ts.map +1 -0
  107. package/protocol.js +8334 -0
  108. package/schemas/audit.schema.json +226 -0
  109. package/schemas/capability.schema.json +113 -0
  110. package/schemas/envelope.schema.json +162 -0
  111. package/schemas/memory.schema.json +51 -0
  112. package/schemas/observation.schema.json +113 -0
  113. package/schemas/plan.schema.json +208 -0
  114. package/schemas/progress.schema.json +126 -0
  115. package/schemas/proposal.schema.json +68 -0
  116. package/schemas/session.schema.json +82 -0
  117. package/schemas/tool.schema.json +94 -0
  118. package/server.d.ts.map +1 -0
  119. package/server.js +28877 -0
  120. package/umd-example.html +18 -0
  121. package/umd.d.ts.map +1 -0
  122. package/accounts.ts +0 -2087
  123. package/agent.ts +0 -2331
  124. package/antigravity.ts +0 -2139
  125. package/apifreeze.ts +0 -4146
  126. package/auth.ts +0 -642
  127. package/background.ts +0 -16837
  128. package/bridge.ts +0 -2080
  129. package/build.ts +0 -54
  130. package/bun.ts +0 -26
  131. package/capture.ts +0 -1614
  132. package/checksecrets.ts +0 -72
  133. package/cjs.ts +0 -9
  134. package/cli.ts +0 -3500
  135. package/commands.ts +0 -1101
  136. package/companion.ts +0 -450
  137. package/compatibility.ts +0 -37
  138. package/config.ts +0 -3137
  139. package/constants.ts +0 -943
  140. package/core.ts +0 -1473
  141. package/crossbrowser.ts +0 -1359
  142. package/dashdone.ts +0 -605
  143. package/data.ts +0 -943
  144. package/database.ts +0 -133
  145. package/debug.ts +0 -850
  146. package/deno.ts +0 -27
  147. package/devthink.ts +0 -707
  148. package/dist/accounts.d.ts +0 -409
  149. package/dist/agent.d.ts +0 -837
  150. package/dist/antigravity.d.ts +0 -380
  151. package/dist/apifreeze.d.ts +0 -113
  152. package/dist/auth.d.ts +0 -224
  153. package/dist/capture.d.ts +0 -595
  154. package/dist/cjs.d.ts +0 -6
  155. package/dist/commands.d.ts +0 -310
  156. package/dist/compatibility.d.ts +0 -17
  157. package/dist/config.d.ts +0 -1853
  158. package/dist/constants.d.ts +0 -637
  159. package/dist/core.d.ts +0 -361
  160. package/dist/data.d.ts +0 -330
  161. package/dist/database.d.ts +0 -24
  162. package/dist/debug.d.ts +0 -270
  163. package/dist/engine.d.ts +0 -74
  164. package/dist/environments.d.ts +0 -244
  165. package/dist/evidence.d.ts +0 -277
  166. package/dist/export.d.ts +0 -311
  167. package/dist/fingerprint.d.ts +0 -594
  168. package/dist/flow.d.ts +0 -300
  169. package/dist/gates.d.ts +0 -103
  170. package/dist/identity.d.ts +0 -51
  171. package/dist/ids.d.ts +0 -7
  172. package/dist/llm.d.ts +0 -652
  173. package/dist/models.d.ts +0 -1807
  174. package/dist/net.d.ts +0 -325
  175. package/dist/neutral.d.ts +0 -41
  176. package/dist/oauth.d.ts +0 -703
  177. package/dist/page.d.ts +0 -1166
  178. package/dist/perf.d.ts +0 -481
  179. package/dist/plan.d.ts +0 -134
  180. package/dist/project.d.ts +0 -395
  181. package/dist/providers.d.ts +0 -37
  182. package/dist/quota.d.ts +0 -453
  183. package/dist/recovery.d.ts +0 -621
  184. package/dist/request.d.ts +0 -1492
  185. package/dist/run.d.ts +0 -779
  186. package/dist/runtime.d.ts +0 -212
  187. package/dist/search.d.ts +0 -375
  188. package/dist/security.d.ts +0 -534
  189. package/dist/serve.d.ts +0 -136
  190. package/dist/session.d.ts +0 -296
  191. package/dist/storage.d.ts +0 -53
  192. package/dist/streaming.d.ts +0 -1119
  193. package/dist/swarm.d.ts +0 -328
  194. package/dist/tools.d.ts +0 -170
  195. package/dist/types.d.ts +0 -8357
  196. package/dist/utils.d.ts +0 -82
  197. package/dist/version.d.ts +0 -7
  198. package/dist/versionregistry.d.ts +0 -406
  199. package/dist/views.d.ts +0 -579
  200. package/dist/workbenchsession.d.ts +0 -69
  201. package/dist/workflow.d.ts +0 -649
  202. package/docs/readme.md +0 -92
  203. package/docs/schemas/antigravity.json +0 -192
  204. package/engine.ts +0 -1524
  205. package/environments.ts +0 -1005
  206. package/evidence.ts +0 -643
  207. package/export.ts +0 -889
  208. package/fingerprint.ts +0 -1458
  209. package/flow.ts +0 -1190
  210. package/gates.ts +0 -307
  211. package/gateway.ts +0 -34
  212. package/hardening.ts +0 -191
  213. package/headless.ts +0 -369
  214. package/http.ts +0 -2110
  215. package/identity.ts +0 -246
  216. package/ids.ts +0 -26
  217. package/index.ts +0 -369
  218. package/llm.ts +0 -2682
  219. package/mcp.ts +0 -1835
  220. package/models.ts +0 -3805
  221. package/modes.ts +0 -43
  222. package/net.ts +0 -1214
  223. package/neutral.ts +0 -362
  224. package/node.ts +0 -26
  225. package/oauth.ts +0 -2216
  226. package/offscreen.ts +0 -170
  227. package/pack.ts +0 -956
  228. package/page.ts +0 -7824
  229. package/pagebridge.ts +0 -1116
  230. package/perf.ts +0 -957
  231. package/plan.ts +0 -672
  232. package/plugin.ts +0 -76
  233. package/prisma.config.ts +0 -27
  234. package/progress.ts +0 -1308
  235. package/project.ts +0 -1291
  236. package/protocol.ts +0 -4187
  237. package/providers.ts +0 -246
  238. package/quota.ts +0 -1887
  239. package/recovery.ts +0 -2433
  240. package/request.ts +0 -4482
  241. package/run.ts +0 -2135
  242. package/runtime.ts +0 -526
  243. package/search.ts +0 -1760
  244. package/security.ts +0 -1673
  245. package/serve.ts +0 -419
  246. package/server.ts +0 -5538
  247. package/session.ts +0 -1162
  248. package/storage.ts +0 -182
  249. package/streaming.ts +0 -4101
  250. package/swarm.ts +0 -884
  251. package/sync.ts +0 -56
  252. package/tests/agentcert.test.ts +0 -128
  253. package/tests/agentfleet.test.ts +0 -214
  254. package/tests/agentreview.test.ts +0 -241
  255. package/tests/agentstream.test.ts +0 -335
  256. package/tests/agentwork.test.ts +0 -356
  257. package/tests/apifreeze.test.ts +0 -290
  258. package/tests/apimap.test.ts +0 -112
  259. package/tests/approvalgate.test.ts +0 -175
  260. package/tests/artifactmanifest.test.ts +0 -204
  261. package/tests/attentionfeed.test.ts +0 -163
  262. package/tests/backgroundruns.test.ts +0 -100
  263. package/tests/batchscheduling.test.ts +0 -131
  264. package/tests/blackboard.test.ts +0 -238
  265. package/tests/bridge.test.ts +0 -1088
  266. package/tests/browsercoverage.test.ts +0 -134
  267. package/tests/browserpolyfills.test.ts +0 -124
  268. package/tests/build.mjs +0 -1260
  269. package/tests/clientauth.test.ts +0 -223
  270. package/tests/clitools.test.ts +0 -578
  271. package/tests/confirmgates.test.ts +0 -190
  272. package/tests/containerpack.test.ts +0 -143
  273. package/tests/controlflow.test.ts +0 -2120
  274. package/tests/coordination.test.ts +0 -345
  275. package/tests/copyscreen.test.ts +0 -139
  276. package/tests/core.test.ts +0 -417
  277. package/tests/costcert.test.ts +0 -95
  278. package/tests/crossbrowser.test.ts +0 -115
  279. package/tests/cspaudit.test.ts +0 -79
  280. package/tests/dashdone.test.ts +0 -615
  281. package/tests/datagrid.test.ts +0 -137
  282. package/tests/doccheck.test.ts +0 -107
  283. package/tests/dombatch.test.ts +0 -109
  284. package/tests/emulation.test.ts +0 -282
  285. package/tests/environments.test.ts +0 -259
  286. package/tests/evidenceviews.test.ts +0 -88
  287. package/tests/exporttools.test.ts +0 -185
  288. package/tests/firefoxprep.test.ts +0 -134
  289. package/tests/flowlibrary.test.ts +0 -242
  290. package/tests/flowrun.test.ts +0 -303
  291. package/tests/forensics.test.ts +0 -439
  292. package/tests/gateway.test.ts +0 -939
  293. package/tests/headlesslib.test.ts +0 -171
  294. package/tests/httpstream.test.ts +0 -277
  295. package/tests/immutablelog.test.ts +0 -157
  296. package/tests/inboundguard.test.ts +0 -177
  297. package/tests/lazyload.test.ts +0 -72
  298. package/tests/librarymodes.test.ts +0 -623
  299. package/tests/llm.test.ts +0 -696
  300. package/tests/manifest.test.ts +0 -226
  301. package/tests/maskinputs.test.ts +0 -150
  302. package/tests/matrixverify.test.ts +0 -111
  303. package/tests/mavenpack.test.ts +0 -75
  304. package/tests/mcpserver.test.ts +0 -704
  305. package/tests/memory.test.ts +0 -4155
  306. package/tests/memorycare.test.ts +0 -230
  307. package/tests/migrateplan.test.ts +0 -349
  308. package/tests/minimization.test.ts +0 -414
  309. package/tests/modelroute.test.ts +0 -112
  310. package/tests/multiagent.test.ts +0 -440
  311. package/tests/nativebridge.test.ts +0 -807
  312. package/tests/navigation.test.ts +0 -284
  313. package/tests/nugetpack.test.ts +0 -83
  314. package/tests/orchestration.test.ts +0 -449
  315. package/tests/originpolicy.test.ts +0 -405
  316. package/tests/outputcompare.test.ts +0 -97
  317. package/tests/package.test.ts +0 -91
  318. package/tests/pagebridge.test.ts +0 -5909
  319. package/tests/pentest.test.ts +0 -75
  320. package/tests/perfrecords.test.ts +0 -257
  321. package/tests/permdiff.test.ts +0 -85
  322. package/tests/phishguard.test.ts +0 -128
  323. package/tests/pickerviews.test.ts +0 -155
  324. package/tests/pipelines.test.ts +0 -381
  325. package/tests/planlint.test.ts +0 -240
  326. package/tests/planreview.test.ts +0 -383
  327. package/tests/platformtargets.test.ts +0 -56
  328. package/tests/policy.test.ts +0 -8284
  329. package/tests/portability.test.ts +0 -96
  330. package/tests/progress.test.ts +0 -1036
  331. package/tests/promptlibrary.test.ts +0 -116
  332. package/tests/protocol.test.ts +0 -4793
  333. package/tests/publishingpipeline.test.ts +0 -314
  334. package/tests/quickactions.test.ts +0 -164
  335. package/tests/readiness.test.ts +0 -78
  336. package/tests/recipes.test.ts +0 -163
  337. package/tests/redactshots.test.ts +0 -216
  338. package/tests/registernvidiakeys.ts +0 -51
  339. package/tests/relayserve.test.ts +0 -304
  340. package/tests/releasenotes.test.ts +0 -276
  341. package/tests/resilience.test.ts +0 -467
  342. package/tests/resourceaware.test.ts +0 -187
  343. package/tests/runbudget.test.ts +0 -125
  344. package/tests/runhistory.test.ts +0 -299
  345. package/tests/runreplay.test.ts +0 -113
  346. package/tests/runresume.test.ts +0 -184
  347. package/tests/runstate.test.ts +0 -288
  348. package/tests/runtimeadapters.test.ts +0 -251
  349. package/tests/safariskeleton.test.ts +0 -115
  350. package/tests/sandboxframe.test.ts +0 -196
  351. package/tests/sbom.test.ts +0 -105
  352. package/tests/secretvault.test.ts +0 -188
  353. package/tests/selcache.test.ts +0 -111
  354. package/tests/sessioninterface.test.ts +0 -791
  355. package/tests/sessions.test.ts +0 -591
  356. package/tests/siteprefs.test.ts +0 -228
  357. package/tests/snapshotdelta.test.ts +0 -165
  358. package/tests/statusviews.test.ts +0 -237
  359. package/tests/stepmeter.test.ts +0 -200
  360. package/tests/streamparse.test.ts +0 -163
  361. package/tests/stylepruning.test.ts +0 -90
  362. package/tests/surfaces.test.ts +0 -282
  363. package/tests/sweep.test.ts +0 -78
  364. package/tests/syncbridge.test.ts +0 -164
  365. package/tests/taskqueue.test.ts +0 -206
  366. package/tests/toolcalls.test.ts +0 -336
  367. package/tests/toolcatalog.test.ts +0 -201
  368. package/tests/torture-agent.test.ts +0 -706
  369. package/tests/torture-auth.test.ts +0 -461
  370. package/tests/torture-commands.test.ts +0 -895
  371. package/tests/torture-data.test.ts +0 -923
  372. package/tests/torture-environments.test.ts +0 -285
  373. package/tests/torture-export.test.ts +0 -263
  374. package/tests/torture-http.test.ts +0 -1379
  375. package/tests/torture-llm.test.ts +0 -808
  376. package/tests/torture-memory.test.ts +0 -1084
  377. package/tests/torture-plan.test.ts +0 -829
  378. package/tests/torture-run.test.ts +0 -626
  379. package/tests/torture-session.test.ts +0 -928
  380. package/tests/torture-swarm.test.ts +0 -1245
  381. package/tests/torture-tools.test.ts +0 -964
  382. package/tests/torture-workflow.test.ts +0 -2354
  383. package/tests/tourviews.test.ts +0 -52
  384. package/tests/transparency.test.ts +0 -147
  385. package/tests/trigger.test.ts +0 -941
  386. package/tests/v1sunset.test.ts +0 -428
  387. package/tests/virtlist.test.ts +0 -94
  388. package/tests/vision.test.ts +0 -540
  389. package/tests/vsixpack.test.ts +0 -145
  390. package/tests/webapi.test.ts +0 -523
  391. package/tests/workflow.test.ts +0 -1785
  392. package/tests/workfloweditor.test.ts +0 -759
  393. package/tests/xpipack.test.ts +0 -128
  394. package/tools.ts +0 -734
  395. package/types.ts +0 -9908
  396. package/umd.ts +0 -9
  397. package/utils.ts +0 -249
  398. package/version.ts +0 -8
  399. package/versionregistry.ts +0 -1310
  400. package/views.ts +0 -2153
  401. package/vitest.config.ts +0 -12
  402. package/web/App.tsx +0 -78
  403. package/web/README.md +0 -47
  404. package/web/capacitor.config.ts +0 -46
  405. package/web/const.ts +0 -19
  406. package/web/control.shell.tsx +0 -66
  407. package/web/dashboardpage.ts +0 -554
  408. package/web/db.ts +0 -493
  409. package/web/design.html +0 -541
  410. package/web/gatewayview/Gateway.tsx +0 -345
  411. package/web/gatewayview/config.ts +0 -1042
  412. package/web/gatewayview/definition.ts +0 -174
  413. package/web/icons.ts +0 -15
  414. package/web/optionspage.ts +0 -691
  415. package/web/popup.ts +0 -1651
  416. package/web/schema.prisma +0 -176
  417. package/web/sidepanel.ts +0 -7941
  418. package/web/sitemanifest.json +0 -13
  419. package/web/terminal-ui.tsx +0 -622
  420. package/web/transparencypage.ts +0 -541
  421. package/web/vite.config.ts +0 -39
  422. package/web/workspace.ts +0 -23
  423. package/workbenchmemory.ts +0 -104
  424. package/workbenchsession.ts +0 -304
  425. package/workflow.ts +0 -4495
  426. /package/{dist/bun.d.ts → bun.d.ts} +0 -0
  427. /package/{dist/cli.d.ts → cli.d.ts} +0 -0
  428. /package/{dist/companion.d.ts → companion.d.ts} +0 -0
  429. /package/{dist/crossbrowser.d.ts → crossbrowser.d.ts} +0 -0
  430. /package/{dist/dashdone.d.ts → dashdone.d.ts} +0 -0
  431. /package/{dist/deno.d.ts → deno.d.ts} +0 -0
  432. /package/{dist/hardening.d.ts → hardening.d.ts} +0 -0
  433. /package/{dist/headless.d.ts → headless.d.ts} +0 -0
  434. /package/{dist/http.d.ts → http.d.ts} +0 -0
  435. /package/{dist/index.d.ts → index.d.ts} +0 -0
  436. /package/{dist/mcp.d.ts → mcp.d.ts} +0 -0
  437. /package/{dist/memory.d.ts → memory.d.ts} +0 -0
  438. /package/{dist/node.d.ts → node.d.ts} +0 -0
  439. /package/{dist/pack.d.ts → pack.d.ts} +0 -0
  440. /package/{dist/policy.d.ts → policy.d.ts} +0 -0
  441. /package/{dist/progress.d.ts → progress.d.ts} +0 -0
  442. /package/{dist/protocol.d.ts → protocol.d.ts} +0 -0
  443. /package/{dist/server.d.ts → server.d.ts} +0 -0
  444. /package/{dist/umd.d.ts → umd.d.ts} +0 -0
package/swarm.ts DELETED
@@ -1,884 +0,0 @@
1
- /**
2
- * The swarm module of the 1.1.90 consolidation: every correlated variation of the swarm logic interned in this one file, so the module family carries one surface without duplicate variations.
3
- * The correlation is the multi agent swarm organized over one shared queue and one shared board: orchestration holds the organizing topology (leader worker election by user rule, work slicing, result collection, worker scaling inside the user bound, the planner executor split with step reporting, critic reviews, verifier checks, the progressboard aggregation, human decided escalations, arbitration of competing claims and consensus rounds with quorum); taskqueue holds the shared work every agent of the swarm claims from (lanes, priorities, claims with heartbeats, work stealing with lane ownership, completion policy and the requeue of orphaned tasks); and blackboard is the shared memory every agent reads with no relay (sections, posting with authors, freshness filtered reads, retirement by the user window and the consent class inheritance of the source extraction).
4
- * Orchestration never bypasses review: the leader only organizes work whose proposals still pass the same human review, the critic reads outputs without acting on the page, and every escalation lands on the user.
5
- */
6
-
7
- /* ── Merged from orchestration.ts ── */
8
-
9
- import type {
10
- agentidentity,
11
- arbitrationrule,
12
- boardlane,
13
- boardmilestone,
14
- consensusround,
15
- consensusvote,
16
- criticreview,
17
- escalationrecord,
18
- executorreport,
19
- leaderworker,
20
- plannerexecutor,
21
- progressboard,
22
- reviewrequest,
23
- reviewverdict,
24
- taskitem,
25
- taskqueue,
26
- verifiercheck,
27
- workerassignment,
28
- } from "./types.js";
29
-
30
- /**
31
- * Multi agent orchestration logic of the 1.1.59 family.
32
- * Every correlated rule for the leader worker topology (election by user rule, work slicing, result collection, worker scaling), the planner executor split with step reporting, critic reviews over agent outputs, verifier checks of result claims, the progressboard aggregation, escalations that stay human decided, arbitration of competing claims and consensus rounds with quorum lives in this file.
33
- * Orchestration never bypasses review: the leader only organizes work whose proposals still pass the same human review, the critic reads outputs without acting on the page and every escalation lands on the user.
34
- */
35
-
36
- /** Elects the leader of the swarm and builds the leader worker topology: the user rule names the leader (first registration or one named agent), the live workers, critics and verifiers join their lanes by role, and the topology records the election. */
37
- export function electleader(input: {
38
- agents: agentidentity[];
39
- id: string;
40
- rule?: { kind: "first" | "named"; agentid?: string };
41
- now: number;
42
- }): leaderworker {
43
- const live = input.agents.filter((agent) => agent.state !== "stopped");
44
- if (live.length === 0)
45
- throw new Error("The swarm holds no live agent; the leader election waits for the user to register one.");
46
- const rule = input.rule ?? { kind: "first" as const };
47
- let leader: agentidentity | undefined;
48
- if (rule.kind === "named") {
49
- if (rule.agentid === undefined || rule.agentid.trim() === "")
50
- throw new Error("The named election rule needs the agent id the user named.");
51
- leader = live.find((agent) => agent.id === rule.agentid);
52
- if (!leader)
53
- throw new Error(
54
- `The named election rule names the agent ${rule.agentid} which is not a live agent of the swarm.`,
55
- );
56
- } else {
57
- leader = live[live.length - 1];
58
- }
59
- if (!leader) throw new Error("The leader election found no live agent.");
60
- const leaderid = leader.id;
61
- const workers = live.filter((agent) => agent.id !== leaderid && agent.role === "worker");
62
- const critics = live.filter((agent) => agent.id !== leaderid && agent.role === "critic");
63
- const verifiers = live.filter((agent) => agent.id !== leaderid && agent.role === "verifier");
64
- return {
65
- id: input.id,
66
- leaderid: leader.id,
67
- workerids: workers.map((agent) => agent.id),
68
- criticids: critics.map((agent) => agent.id),
69
- verifierids: verifiers.map((agent) => agent.id),
70
- assignments: [],
71
- rule: { kind: rule.kind, ...(rule.agentid !== undefined ? { agentid: rule.agentid } : {}) },
72
- electedat: input.now,
73
- };
74
- }
75
-
76
- /** Slices the tasks across the workers of the topology: the workers take turns over the queued and claimed tasks in queue order, every slice names the task payload it owns and the assignments record the worker, the task and the slice. */
77
- export function assignwork(input: { topology: leaderworker; tasks: taskitem[]; now: number }): leaderworker {
78
- if (input.topology.workerids.length === 0)
79
- throw new Error("The topology holds no worker; the user adds workers before the assignment.");
80
- const assignments: workerassignment[] = [];
81
- const tasks = input.tasks.filter((task) => task.state === "queued" || task.state === "claimed");
82
- tasks.forEach((task, index) => {
83
- const workerid = input.topology.workerids[index % input.topology.workerids.length]!;
84
- assignments.push({
85
- workerid,
86
- taskid: task.id,
87
- slice: `${task.payload} (slice ${Math.floor(index / input.topology.workerids.length) + 1} of lane ${task.lane})`,
88
- assignedat: input.now,
89
- });
90
- });
91
- return { ...input.topology, assignments };
92
- }
93
-
94
- /** Gathers the worker outputs with status: every assignment reports its state while the outputs the workers returned land beside their tasks, and the missing list names the assignments still without an output. */
95
- export function collectresults(input: {
96
- topology: leaderworker;
97
- outputs: Array<{ workerid: string; taskid: string; state: string; summary: string }>;
98
- }): { gathered: Array<{ workerid: string; taskid: string; state: string; summary: string }>; missing: string[] } {
99
- const gathered = input.topology.assignments.map((assignment) => {
100
- const output = input.outputs.find(
101
- (entry) => entry.taskid === assignment.taskid && entry.workerid === assignment.workerid,
102
- );
103
- return (
104
- output ?? {
105
- workerid: assignment.workerid,
106
- taskid: assignment.taskid,
107
- state: "pending",
108
- summary: `The worker ${assignment.workerid} has not returned its slice of the task ${assignment.taskid} yet.`,
109
- }
110
- );
111
- });
112
- return {
113
- gathered,
114
- missing: gathered.filter((entry) => entry.state === "pending").map((entry) => `${entry.workerid}:${entry.taskid}`),
115
- };
116
- }
117
-
118
- /** Scales the worker lane by load: queued work beyond the current workers adds the live worker role agents the swarm already holds (never past the user configured bound while one exists), idle workers retire down to the work left, and no engine cap ever exists. */
119
- export function scaleworkers(input: {
120
- topology: leaderworker;
121
- agents: agentidentity[];
122
- pending: number;
123
- bound?: number;
124
- now: number;
125
- }): { topology: leaderworker; added: string[]; retired: string[]; reason: string } {
126
- const live = input.agents.filter(
127
- (agent) => agent.state === "active" && agent.role === "worker" && agent.id !== input.topology.leaderid,
128
- );
129
- const current = input.topology.workerids.filter((workerid) => live.some((agent) => agent.id === workerid));
130
- const ceiling = input.bound;
131
- if (input.pending > current.length) {
132
- const available = live.filter((agent) => !current.includes(agent.id)).map((agent) => agent.id);
133
- const wanted = input.pending - current.length;
134
- const addable =
135
- ceiling === undefined
136
- ? available.slice(0, wanted)
137
- : available.slice(0, Math.min(wanted, Math.max(ceiling - current.length, 0)));
138
- if (addable.length === 0)
139
- return {
140
- topology: input.topology,
141
- added: [],
142
- retired: [],
143
- reason:
144
- ceiling === undefined
145
- ? `The load of ${input.pending} pending slices exceeds the ${current.length} workers but the swarm holds no further live worker role agent to add.`
146
- : `The load of ${input.pending} pending slices exceeds the ${current.length} workers but the user configured bound of ${ceiling} workers holds.`,
147
- };
148
- return {
149
- topology: {
150
- ...input.topology,
151
- workerids: [...current, ...addable],
152
- electedat: input.topology.electedat,
153
- assignments: input.topology.assignments,
154
- },
155
- added: addable,
156
- retired: [],
157
- reason: `The load of ${input.pending} pending slices added the workers ${addable.join(", ")}; ${ceiling === undefined ? "no bound is configured so the user scale stands alone" : `the user configured bound of ${ceiling} workers holds`}.`,
158
- };
159
- }
160
- const keep = Math.max(input.pending, 0);
161
- if (current.length > keep) {
162
- const retired = current.slice(keep);
163
- return {
164
- topology: {
165
- ...input.topology,
166
- workerids: current.slice(0, keep),
167
- electedat: input.topology.electedat,
168
- assignments: input.topology.assignments.filter((assignment) => !retired.includes(assignment.workerid)),
169
- },
170
- added: [],
171
- retired,
172
- reason: `The load of ${input.pending} pending slices retired the idle workers ${retired.join(", ")}.`,
173
- };
174
- }
175
- return {
176
- topology: input.topology,
177
- added: [],
178
- retired: [],
179
- reason: `The load of ${input.pending} pending slices matches the ${current.length} workers; the scale stays unchanged.`,
180
- };
181
- }
182
-
183
- /** Splits one task between the planner and the executor: the plan owner agent drafts the reviewed plan while the run owner agent executes it, and the split record starts empty of step reports. */
184
- export function plannersplit(input: {
185
- id: string;
186
- planownerid: string;
187
- runownerid: string;
188
- taskid?: string;
189
- now: number;
190
- }): plannerexecutor {
191
- if (input.planownerid.trim() === "" || input.runownerid.trim() === "")
192
- throw new Error("The planner executor split needs its plan owner and run owner agent ids.");
193
- if (input.planownerid === input.runownerid)
194
- throw new Error(
195
- "The planner executor split keeps plan drafting and execution in different agents; one agent holds both sides never.",
196
- );
197
- return {
198
- id: input.id,
199
- planownerid: input.planownerid,
200
- runownerid: input.runownerid,
201
- ...(input.taskid !== undefined && input.taskid.trim() !== "" ? { taskid: input.taskid } : {}),
202
- stepreports: [],
203
- splitat: input.now,
204
- };
205
- }
206
-
207
- /** Reports one executor step outcome back to the planner agent: the executor appends its report to the split record so the planner reads every step result. */
208
- export function reportstep(input: {
209
- split: plannerexecutor;
210
- stepid: string;
211
- outcome: "done" | "failed";
212
- detail: string;
213
- now: number;
214
- }): plannerexecutor {
215
- if (input.stepid.trim() === "") throw new Error("The executor report needs its step id.");
216
- if (input.detail.trim() === "") throw new Error("The executor report needs its detail in plain language.");
217
- const report: executorreport = {
218
- stepid: input.stepid.trim(),
219
- outcome: input.outcome,
220
- detail: input.detail,
221
- reportedat: input.now,
222
- };
223
- return {
224
- ...input.split,
225
- stepreports: [...input.split.stepreports.filter((entry) => entry.stepid !== report.stepid), report],
226
- };
227
- }
228
-
229
- /** Routes one review request to a reviewing agent: the request names the subject and payload and stays open until its ack, its answer or its user configured timeout. */
230
- export function requestreview(input: {
231
- requests: reviewrequest[];
232
- id: string;
233
- fromagentid: string;
234
- toagentid: string;
235
- subject: string;
236
- payload: string;
237
- timeoutms?: number;
238
- now: number;
239
- }): reviewrequest[] {
240
- if (input.subject.trim() === "") throw new Error("The review request needs its subject.");
241
- if (input.payload.trim() === "") throw new Error("The review request needs its payload.");
242
- if (input.toagentid.trim() === "" || input.toagentid === input.fromagentid)
243
- throw new Error("The review request names another reviewing agent, never its own requester.");
244
- const request: reviewrequest = {
245
- id: input.id,
246
- fromagentid: input.fromagentid,
247
- toagentid: input.toagentid,
248
- subject: input.subject,
249
- payload: input.payload,
250
- state: "open",
251
- requestedat: input.now,
252
- ...(input.timeoutms !== undefined ? { timeoutat: input.now + input.timeoutms } : {}),
253
- };
254
- return [request, ...input.requests];
255
- }
256
-
257
- /** Acks one review request: the reviewing agent confirms receipt while the answer still waits. */
258
- export function ackreview(input: { requests: reviewrequest[]; id: string; now: number }): reviewrequest[] {
259
- const request = input.requests.find((entry) => entry.id === input.id);
260
- if (!request) throw new Error(`The review request ${input.id} does not exist.`);
261
- if (request.state !== "open")
262
- throw new Error(`The review request ${input.id} is ${request.state}; only an open request receives its ack.`);
263
- return input.requests.map((entry) =>
264
- entry.id === input.id ? { ...entry, state: "acked" as const, ackedat: input.now } : entry,
265
- );
266
- }
267
-
268
- /** Applies the critic verdict to one review request: the review carries the verdict, the issues and the required changes while the request closes as answered. */
269
- export function applyreview(input: {
270
- requests: reviewrequest[];
271
- id: string;
272
- reviewerid: string;
273
- verdict: reviewverdict;
274
- issues: string[];
275
- requiredchanges: string[];
276
- taskid?: string;
277
- now: number;
278
- }): { review: criticreview; requests: reviewrequest[] } {
279
- const request = input.requests.find((entry) => entry.id === input.id);
280
- if (!request) throw new Error(`The review request ${input.id} does not exist.`);
281
- if (request.state === "answered" || request.state === "timeout")
282
- throw new Error(
283
- `The review request ${input.id} is ${request.state}; an answered or timed out request never reviews again.`,
284
- );
285
- if (request.toagentid !== input.reviewerid)
286
- throw new Error(
287
- `The review request ${input.id} routes to the agent ${request.toagentid}; the agent ${input.reviewerid} never answers in its place.`,
288
- );
289
- if (input.verdict === "changes" && input.requiredchanges.length === 0)
290
- throw new Error("A changes verdict needs its required changes in plain language.");
291
- const review: criticreview = {
292
- id: request.id,
293
- reviewerid: input.reviewerid,
294
- subjectagentid: request.fromagentid,
295
- ...(input.taskid !== undefined && input.taskid.trim() !== "" ? { taskid: input.taskid } : {}),
296
- verdict: input.verdict,
297
- issues: input.issues,
298
- requiredchanges: input.requiredchanges,
299
- reviewedat: input.now,
300
- };
301
- return {
302
- review,
303
- requests: input.requests.map((entry) =>
304
- entry.id === input.id ? { ...entry, state: "answered" as const, answeredat: input.now } : entry,
305
- ),
306
- };
307
- }
308
-
309
- /** Sweeps the review requests past their user configured timeout: an unanswered request without an ack or an answer times out and the requester reads the expiry. */
310
- export function sweepreviews(input: { requests: reviewrequest[]; now: number }): {
311
- requests: reviewrequest[];
312
- timedout: string[];
313
- } {
314
- const expired = input.requests
315
- .filter((request) => request.state === "open" || request.state === "acked")
316
- .filter((request) => request.timeoutat !== undefined && input.now > request.timeoutat);
317
- if (expired.length === 0) return { requests: input.requests, timedout: [] };
318
- const ids = new Set(expired.map((request) => request.id));
319
- return {
320
- requests: input.requests.map((request) =>
321
- ids.has(request.id) ? { ...request, state: "timeout" as const } : request,
322
- ),
323
- timedout: [...ids],
324
- };
325
- }
326
-
327
- /** Records one verifier check of a result claim: the verifier names the claim, the method it used and the pass or fail outcome with its evidence; the check itself never writes to the page. */
328
- export function checkclaim(input: {
329
- id: string;
330
- verifierid: string;
331
- claimagentid: string;
332
- claim: string;
333
- method: string;
334
- outcome: "pass" | "fail";
335
- evidence?: string;
336
- taskid?: string;
337
- now: number;
338
- }): verifiercheck {
339
- if (input.claim.trim() === "") throw new Error("The verifier check needs its claim in plain language.");
340
- if (input.method.trim() === "") throw new Error("The verifier check needs the method the user configured.");
341
- if (input.claimagentid.trim() === "") throw new Error("The verifier check names the agent whose claim it checks.");
342
- return {
343
- id: input.id,
344
- verifierid: input.verifierid,
345
- claimagentid: input.claimagentid,
346
- ...(input.taskid !== undefined && input.taskid.trim() !== "" ? { taskid: input.taskid } : {}),
347
- claim: input.claim,
348
- method: input.method,
349
- outcome: input.outcome,
350
- ...(input.evidence !== undefined && input.evidence.trim() !== "" ? { evidence: input.evidence } : {}),
351
- checkedat: input.now,
352
- };
353
- }
354
-
355
- /** Builds the progressboard that aggregates the swarm: one lane per live agent with its role, state, lane of work, current task and milestones, so the user reads every agent at once. */
356
- export function boardstate(input: {
357
- agents: agentidentity[];
358
- queue: taskqueue;
359
- topology?: leaderworker;
360
- milestones?: Record<string, boardmilestone[]>;
361
- now: number;
362
- }): progressboard {
363
- const lanes: boardlane[] = input.agents
364
- .filter((agent) => agent.state !== "stopped")
365
- .map((agent) => {
366
- const assignment = input.topology?.assignments.find((entry) => entry.workerid === agent.id);
367
- const claim = input.queue.claims.find(
368
- (record) =>
369
- record.agentid === agent.id &&
370
- input.queue.items.some((item) => item.id === record.taskid && item.state === "claimed"),
371
- );
372
- const task = claim !== undefined ? input.queue.items.find((item) => item.id === claim.taskid) : undefined;
373
- const lane =
374
- task?.lane ??
375
- (agent.role === "critic" || agent.role === "verifier"
376
- ? agent.role
377
- : agent.role === "planner"
378
- ? "planning"
379
- : "idle");
380
- return {
381
- agentid: agent.id,
382
- name: agent.name,
383
- role: agent.role,
384
- state: agent.state,
385
- lane,
386
- ...(task !== undefined
387
- ? { currenttask: task.payload }
388
- : assignment !== undefined
389
- ? { currenttask: assignment.slice }
390
- : {}),
391
- milestones: input.milestones?.[agent.id] ?? [],
392
- };
393
- });
394
- return { id: `board:${input.now}`, lanes, builtat: input.now };
395
- }
396
-
397
- /** Lifts one stalled agent decision to the user with its full context: the escalation stays open until the user writes the decision because escalations are always human decided. */
398
- export function escalate(input: {
399
- id: string;
400
- agentid: string;
401
- subject: string;
402
- context: string;
403
- now: number;
404
- }): escalationrecord {
405
- if (input.subject.trim() === "") throw new Error("The escalation needs its subject.");
406
- if (input.context.trim() === "")
407
- throw new Error("The escalation needs its full context in plain language; the user decides on what the agent saw.");
408
- if (input.agentid.trim() === "") throw new Error("The escalation names the agent whose decision it lifts.");
409
- return {
410
- id: input.id,
411
- agentid: input.agentid,
412
- subject: input.subject,
413
- context: input.context,
414
- state: "open",
415
- raisedat: input.now,
416
- };
417
- }
418
-
419
- /** Resolves one escalation with the decision the user wrote; the decision time records and the record closes. */
420
- export function resolveescalation(input: {
421
- escalation: escalationrecord;
422
- decision: string;
423
- now: number;
424
- }): escalationrecord {
425
- if (input.escalation.state === "decided") throw new Error("The escalation already carries its user decision.");
426
- if (input.decision.trim() === "") throw new Error("The escalation decision needs the words the user wrote.");
427
- return { ...input.escalation, state: "decided", decision: input.decision, decidedat: input.now };
428
- }
429
-
430
- /** Orders competing resource claims by the user configured arbitration rule: the priority strategy follows the user ordered agent list, the age strategy gives the resource to the oldest claim and the leader strategy names the elected leader first. */
431
- export function arbitrate(input: {
432
- rule: arbitrationrule;
433
- leaderid?: string;
434
- claims: Array<{ agentid: string; claimedat: number }>;
435
- }): string[] {
436
- if (input.claims.length === 0) return [];
437
- if (input.rule.strategy === "priority") {
438
- const order = input.rule.priorityorder;
439
- return [...input.claims]
440
- .sort((one, two) => {
441
- const oneindex = order.indexOf(one.agentid);
442
- const twoindex = order.indexOf(two.agentid);
443
- return (
444
- (oneindex === -1 ? order.length : oneindex) - (twoindex === -1 ? order.length : twoindex) ||
445
- one.claimedat - two.claimedat
446
- );
447
- })
448
- .map((claim) => claim.agentid);
449
- }
450
- if (input.rule.strategy === "age")
451
- return [...input.claims]
452
- .sort((one, two) => one.claimedat - two.claimedat || (one.agentid < two.agentid ? -1 : 1))
453
- .map((claim) => claim.agentid);
454
- if (input.leaderid === undefined)
455
- throw new Error("The leader arbitration strategy needs the elected leader of the topology.");
456
- return [...input.claims]
457
- .sort(
458
- (one, two) =>
459
- (one.agentid === input.leaderid ? -1 : 1) - (two.agentid === input.leaderid ? -1 : 1) ||
460
- one.claimedat - two.claimedat,
461
- )
462
- .map((claim) => claim.agentid);
463
- }
464
-
465
- /** Opens one consensus round: the subject stays plain language and the quorum stays the user configured value the round needs to carry. */
466
- export function openconsensus(input: { id: string; subject: string; quorum: number; now: number }): consensusround {
467
- if (input.subject.trim() === "") throw new Error("The consensus round needs its subject in plain language.");
468
- if (!Number.isInteger(input.quorum) || input.quorum < 1)
469
- throw new Error("The consensus round needs its quorum as a positive whole number the user configured.");
470
- return { id: input.id, subject: input.subject, votes: [], quorum: input.quorum, state: "open", openedat: input.now };
471
- }
472
-
473
- /** Collects one verdict into a consensus round: an agent votes once, the round stays open until the votes carry or the round closes, and the quorum counts yes votes only. */
474
- export function castvote(input: {
475
- round: consensusround;
476
- agentid: string;
477
- vote: consensusvote;
478
- now: number;
479
- }): consensusround {
480
- if (input.agentid.trim() === "") throw new Error("The consensus vote names its agent; a blank agent id never votes.");
481
- if (input.round.state !== "open")
482
- throw new Error(`The consensus round ${input.round.id} is ${input.round.state}; a closed round collects no vote.`);
483
- if (input.round.votes.some((entry) => entry.agentid === input.agentid))
484
- throw new Error(`The agent ${input.agentid} already voted in the round ${input.round.id}.`);
485
- const votes = [...input.round.votes, { agentid: input.agentid, vote: input.vote, votedat: input.now }];
486
- const yes = votes.filter((entry) => entry.vote === "yes").length;
487
- const no = votes.filter((entry) => entry.vote === "no").length;
488
- if (yes >= input.round.quorum) return { ...input.round, votes, state: "carried", closedat: input.now };
489
- if (no >= input.round.quorum) return { ...input.round, votes, state: "failed", closedat: input.now };
490
- return { ...input.round, votes };
491
- }
492
-
493
- /** Reads the state of one consensus round: the yes, no and abstain counts beside the quorum so the panel shows the votes and the quorum state at once. */
494
- export function consensusstate(round: consensusround): {
495
- yes: number;
496
- no: number;
497
- abstain: number;
498
- quorum: number;
499
- state: string;
500
- } {
501
- return {
502
- yes: round.votes.filter((entry) => entry.vote === "yes").length,
503
- no: round.votes.filter((entry) => entry.vote === "no").length,
504
- abstain: round.votes.filter((entry) => entry.vote === "abstain").length,
505
- quorum: round.quorum,
506
- state: round.state,
507
- };
508
- }
509
-
510
- /* ── Merged from taskqueue.ts ── */
511
-
512
- import type { claimrecord } from "./types.js";
513
-
514
- /**
515
- * Shared task queue logic of the 1.1.58 multi agent family.
516
- * Every correlated rule for lanes, priorities, claims, work stealing with lane ownership, completion, heartbeats and the requeue of orphaned tasks lives in this file.
517
- * The queue never executes anything: a claimed task only names the work whose proposal still passes the same human review every single agent proposal passes.
518
- */
519
-
520
- /** One lane ownership rule the user configures: the lane name and the roles allowed to steal from it; a lane without a rule stays open to every agent of the approved swarm. */
521
- export interface laneownership {
522
- lane: string;
523
- roles: string[];
524
- }
525
-
526
- /** Builds one empty queue with the user configured lanes, priority scale and completion policy; the empty set of lanes accepts any lane name the user enqueues. */
527
- export function emptyqueue(
528
- input: { lanes?: string[]; priorities?: number[]; completionpolicy?: "all" | "any" } = {},
529
- ): taskqueue {
530
- return {
531
- lanes: input.lanes ?? [],
532
- priorities: input.priorities ?? [],
533
- completionpolicy: input.completionpolicy ?? "all",
534
- items: [],
535
- claims: [],
536
- };
537
- }
538
-
539
- /** Enqueues one task item into a lane with its priority; a configured lane list refuses unknown lanes and the payload stays the plain language text the user typed. */
540
- export function enqueue(input: {
541
- queue: taskqueue;
542
- id: string;
543
- lane: string;
544
- priority: number;
545
- payload: string;
546
- now: number;
547
- }): taskqueue {
548
- if (input.lane.trim() === "") throw new Error("The task needs its lane name.");
549
- if (input.payload.trim() === "") throw new Error("The task needs its payload in plain language.");
550
- if (input.queue.lanes.length > 0 && !input.queue.lanes.includes(input.lane))
551
- throw new Error(`The lane ${input.lane} is not one of the configured lanes.`);
552
- if (input.queue.items.some((item) => item.id === input.id))
553
- throw new Error(`The task id ${input.id} already waits in the queue.`);
554
- const item: taskitem = {
555
- id: input.id,
556
- lane: input.lane,
557
- priority: input.priority,
558
- payload: input.payload,
559
- state: "queued",
560
- enqueuedat: input.now,
561
- };
562
- return { ...input.queue, items: [...input.queue.items, item] };
563
- }
564
-
565
- /** Sorts the queued items of one lane: the highest priority first and the oldest task wins a tie. */
566
- function orderedcandidates(queue: taskqueue, lane?: string): taskitem[] {
567
- return queue.items
568
- .filter((item) => item.state === "queued" && (lane === undefined || item.lane === lane))
569
- .sort((one, two) => two.priority - one.priority || one.enqueuedat - two.enqueuedat);
570
- }
571
-
572
- /** Lets one agent claim the highest priority queued task; the claim carries the heartbeat time that keeps it alive and an agent holds one task at a time. */
573
- export function claim(input: { queue: taskqueue; agentid: string; now: number }): {
574
- queue: taskqueue;
575
- task?: taskitem;
576
- } {
577
- const held = input.queue.claims.find((record) => record.agentid === input.agentid);
578
- if (held) {
579
- const task = input.queue.items.find((item) => item.id === held.taskid);
580
- if (task && task.state === "claimed") return { queue: input.queue, task };
581
- }
582
- const candidate = orderedcandidates(input.queue)[0];
583
- if (!candidate) return { queue: input.queue };
584
- const record: claimrecord = {
585
- agentid: input.agentid,
586
- taskid: candidate.id,
587
- claimedat: input.now,
588
- heartbeatat: input.now,
589
- };
590
- return {
591
- queue: {
592
- ...input.queue,
593
- items: input.queue.items.map((item) =>
594
- item.id === candidate.id ? { ...item, state: "claimed" as const } : item,
595
- ),
596
- claims: [
597
- ...input.queue.claims.filter(
598
- (entry) =>
599
- entry.agentid !== input.agentid ||
600
- input.queue.items.find((item) => item.id === entry.taskid)?.state !== "claimed",
601
- ),
602
- record,
603
- ],
604
- },
605
- task: { ...candidate, state: "claimed" },
606
- };
607
- }
608
-
609
- /** Lets one idle agent steal a queued task from a named lane; the lane ownership rules the user configures refuse agents whose role holds no grant for the lane. */
610
- export function steal(input: {
611
- queue: taskqueue;
612
- agentid: string;
613
- role: string;
614
- fromlane: string;
615
- ownership?: laneownership[];
616
- now: number;
617
- }): { queue: taskqueue; task?: taskitem } {
618
- const rule = (input.ownership ?? []).find((entry) => entry.lane === input.fromlane);
619
- if (rule && !rule.roles.includes(input.role))
620
- throw new Error(
621
- `The lane ${input.fromlane} only lets the roles ${rule.roles.join(", ")} steal its tasks; the ${input.role} agent stays out.`,
622
- );
623
- const candidate = orderedcandidates(input.queue, input.fromlane)[0];
624
- if (!candidate) return { queue: input.queue };
625
- const record: claimrecord = {
626
- agentid: input.agentid,
627
- taskid: candidate.id,
628
- claimedat: input.now,
629
- heartbeatat: input.now,
630
- };
631
- return {
632
- queue: {
633
- ...input.queue,
634
- items: input.queue.items.map((item) =>
635
- item.id === candidate.id ? { ...item, state: "claimed" as const } : item,
636
- ),
637
- claims: [...input.queue.claims.filter((entry) => entry.agentid !== input.agentid), record],
638
- },
639
- task: { ...candidate, state: "claimed" },
640
- };
641
- }
642
-
643
- /** Marks one task done and releases the claim of the agent that held it. */
644
- export function complete(input: { queue: taskqueue; taskid: string; now: number }): taskqueue {
645
- const task = input.queue.items.find((item) => item.id === input.taskid);
646
- if (!task) throw new Error(`The task ${input.taskid} is not in the queue.`);
647
- if (task.state !== "claimed")
648
- throw new Error(`The task ${input.taskid} is ${task.state}; only a claimed task completes.`);
649
- return {
650
- ...input.queue,
651
- items: input.queue.items.map((item) => (item.id === input.taskid ? { ...item, state: "done" as const } : item)),
652
- claims: input.queue.claims.filter((record) => record.taskid !== input.taskid),
653
- };
654
- }
655
-
656
- /** Cancels one queued or claimed task; the cancelled task releases its claim and leaves the queue. */
657
- export function canceltask(input: { queue: taskqueue; taskid: string; now: number }): taskqueue {
658
- const task = input.queue.items.find((item) => item.id === input.taskid);
659
- if (!task) throw new Error(`The task ${input.taskid} is not in the queue.`);
660
- if (task.state === "done") throw new Error(`The task ${input.taskid} is done; a completed task never cancels.`);
661
- return {
662
- ...input.queue,
663
- items: input.queue.items.map((item) =>
664
- item.id === input.taskid ? { ...item, state: "cancelled" as const } : item,
665
- ),
666
- claims: input.queue.claims.filter((record) => record.taskid !== input.taskid),
667
- };
668
- }
669
-
670
- /** Refreshes the heartbeats of every live claim of one agent so a working agent keeps its tasks. */
671
- export function claimheartbeat(input: { queue: taskqueue; agentid: string; now: number }): taskqueue {
672
- return {
673
- ...input.queue,
674
- claims: input.queue.claims.map((record) =>
675
- record.agentid === input.agentid ? { ...record, heartbeatat: input.now } : record,
676
- ),
677
- };
678
- }
679
-
680
- /** Returns the orphaned tasks to their lane: a claim whose heartbeat stayed silent past the user configured expiry window releases and the task waits as queued again; an absent window never expires a claim. */
681
- export function requeue(input: { queue: taskqueue; now: number; window?: number }): {
682
- queue: taskqueue;
683
- requeued: string[];
684
- } {
685
- if (input.window === undefined) return { queue: input.queue, requeued: [] };
686
- const window = input.window;
687
- const expired = input.queue.claims.filter((record) => input.now - record.heartbeatat > window);
688
- if (expired.length === 0) return { queue: input.queue, requeued: [] };
689
- const expiredids = new Set(expired.map((record) => record.taskid));
690
- return {
691
- queue: {
692
- ...input.queue,
693
- items: input.queue.items.map((item) =>
694
- expiredids.has(item.id) && item.state === "claimed" ? { ...item, state: "queued" as const } : item,
695
- ),
696
- claims: input.queue.claims.filter((record) => !expiredids.has(record.taskid)),
697
- },
698
- requeued: [...expiredids],
699
- };
700
- }
701
-
702
- /** Reports every lane with its queued, claimed, done and cancelled task counts and the live claims, so the queue view reads the lanes at a glance. */
703
- export function lanereport(
704
- queue: taskqueue,
705
- ): Array<{
706
- lane: string;
707
- queued: number;
708
- claimed: number;
709
- done: number;
710
- cancelled: number;
711
- claims: Array<{ agentid: string; taskid: string; heartbeatat: number }>;
712
- }> {
713
- const lanes = [...queue.lanes, ...queue.items.map((item) => item.lane)].filter(
714
- (lane, index, all) => all.indexOf(lane) === index,
715
- );
716
- return lanes.map((lane) => ({
717
- lane,
718
- queued: queue.items.filter((item) => item.lane === lane && item.state === "queued").length,
719
- claimed: queue.items.filter((item) => item.lane === lane && item.state === "claimed").length,
720
- done: queue.items.filter((item) => item.lane === lane && item.state === "done").length,
721
- cancelled: queue.items.filter((item) => item.lane === lane && item.state === "cancelled").length,
722
- claims: queue.claims
723
- .filter((record) =>
724
- queue.items.some((item) => item.id === record.taskid && item.lane === lane && item.state === "claimed"),
725
- )
726
- .map((record) => ({ agentid: record.agentid, taskid: record.taskid, heartbeatat: record.heartbeatat })),
727
- }));
728
- }
729
-
730
- /** Evaluates the completion policy of the queue: all completes only when every task is done while any completes with the first done task. */
731
- export function queuecomplete(queue: taskqueue): boolean {
732
- const open = queue.items.filter((item) => item.state !== "cancelled");
733
- if (open.length === 0) return false;
734
- return queue.completionpolicy === "any"
735
- ? open.some((item) => item.state === "done")
736
- : open.every((item) => item.state === "done");
737
- }
738
-
739
- /** Counts the tasks by claim state for the popup gauge: the claimed tasks are the active work of the swarm. */
740
- export function taskcounts(queue: taskqueue): { queued: number; claimed: number; done: number; cancelled: number } {
741
- return {
742
- queued: queue.items.filter((item) => item.state === "queued").length,
743
- claimed: queue.items.filter((item) => item.state === "claimed").length,
744
- done: queue.items.filter((item) => item.state === "done").length,
745
- cancelled: queue.items.filter((item) => item.state === "cancelled").length,
746
- };
747
- }
748
-
749
- /* ── Merged from blackboard.ts ── */
750
-
751
- import type { actionrisk, blackboard, blackboardentry, blackboardsection } from "./types.js";
752
-
753
- /**
754
- * Blackboard shared memory logic of the 1.1.58 multi agent family.
755
- * Every correlated rule for the shared sections, posting with authors, reading with freshness filters, retirement by the user configured window and the consent class inheritance of the source extraction lives in this file.
756
- * Every agent of the swarm reads the same board: the writes of one agent are visible to every other agent with no relay.
757
- */
758
-
759
- /** The blackboard sections the swarm shares by default; the user may narrow the list to the sections in use. */
760
- export const blackboardsections: blackboardsection[] = ["goals", "facts", "findings", "scratch"];
761
-
762
- /** Builds one empty blackboard over the four shared sections with no retirement window; an absent window keeps every entry. */
763
- export function emptyboard(sections?: blackboardsection[]): blackboard {
764
- return { sections: sections ?? blackboardsections, entries: [] };
765
- }
766
-
767
- /** Writes one entry to a section with its author: the key and value stay the plain text the author typed, the section joins the board when it is new and the entry carries the consent class of its source extraction. */
768
- export function postentry(input: {
769
- board: blackboard;
770
- id: string;
771
- key: string;
772
- value: string;
773
- section: blackboardsection;
774
- author: string;
775
- valuekind?: "text" | "json";
776
- consentclass?: actionrisk;
777
- now: number;
778
- }): blackboard {
779
- if (input.key.trim() === "") throw new Error("The blackboard entry needs its key.");
780
- if (input.value.trim() === "") throw new Error("The blackboard entry needs its value.");
781
- if (input.author.trim() === "") throw new Error("The blackboard entry needs its author.");
782
- if (!blackboardsections.includes(input.section))
783
- throw new Error(`The section ${input.section} is not one of the shared blackboard sections.`);
784
- if (input.board.entries.some((entry) => entry.id === input.id))
785
- throw new Error(`The blackboard entry id ${input.id} already exists.`);
786
- if (input.valuekind === "json") {
787
- try {
788
- JSON.parse(input.value);
789
- } catch {
790
- throw new Error("The json blackboard entry needs a well-formed json value.");
791
- }
792
- }
793
- const entry: blackboardentry = {
794
- id: input.id,
795
- key: input.key.trim(),
796
- valuekind: input.valuekind ?? "text",
797
- value: input.value,
798
- author: input.author,
799
- section: input.section,
800
- consentclass: input.consentclass ?? "read",
801
- postedat: input.now,
802
- };
803
- return {
804
- ...input.board,
805
- sections: input.board.sections.includes(input.section)
806
- ? input.board.sections
807
- : [...input.board.sections, input.section],
808
- entries: [entry, ...input.board.entries],
809
- };
810
- }
811
-
812
- /** True when one entry stayed fresh inside the window; an absent window keeps every entry fresh. */
813
- export function entryfresh(entry: blackboardentry, now: number, window?: number): boolean {
814
- if (entry.retiredat !== undefined) return false;
815
- if (window === undefined) return true;
816
- return now - entry.postedat <= window;
817
- }
818
-
819
- /** Returns the entries of one section with freshness filters: retired entries stay out and an optional window keeps only the fresh ones; an absent section returns every live entry. */
820
- export function readentries(input: {
821
- board: blackboard;
822
- section?: blackboardsection;
823
- freshness?: number;
824
- now: number;
825
- }): blackboardentry[] {
826
- return input.board.entries
827
- .filter((entry) => entry.retiredat === undefined)
828
- .filter((entry) => input.section === undefined || entry.section === input.section)
829
- .filter((entry) => entryfresh(entry, input.now, input.freshness))
830
- .sort((one, two) => two.postedat - one.postedat);
831
- }
832
-
833
- /** Retires the stale entries by the user configured policy: entries older than the retirement window of the board receive their retirement time while an absent window retires nothing. */
834
- export function retireentries(input: { board: blackboard; now: number }): { board: blackboard; retired: string[] } {
835
- if (input.board.retirementwindow === undefined) return { board: input.board, retired: [] };
836
- const stale = input.board.entries.filter(
837
- (entry) => entry.retiredat === undefined && input.now - entry.postedat > input.board.retirementwindow!,
838
- );
839
- if (stale.length === 0) return { board: input.board, retired: [] };
840
- const staleids = new Set(stale.map((entry) => entry.id));
841
- return {
842
- board: {
843
- ...input.board,
844
- entries: input.board.entries.map((entry) =>
845
- staleids.has(entry.id) ? { ...entry, retiredat: input.now } : entry,
846
- ),
847
- },
848
- retired: [...staleids],
849
- };
850
- }
851
-
852
- /** Retires one entry by its id; the retired entry stays stored for the audit trail while the live reads stop showing it. */
853
- export function retireentry(input: { board: blackboard; entryid: string; now: number }): blackboard {
854
- const entry = input.board.entries.find((candidate) => candidate.id === input.entryid);
855
- if (!entry) throw new Error(`The blackboard entry ${input.entryid} does not exist.`);
856
- if (entry.retiredat !== undefined) throw new Error(`The blackboard entry ${entry.key} is already retired.`);
857
- return {
858
- ...input.board,
859
- entries: input.board.entries.map((candidate) =>
860
- candidate.id === input.entryid ? { ...candidate, retiredat: input.now } : candidate,
861
- ),
862
- };
863
- }
864
-
865
- /** Inherits the consent class of the source extraction into one entry: the reader of the entry sees the class of the extraction it came from, so a sensitive extraction stays sensitive on the board. */
866
- export function inheritconsent(entry: blackboardentry, sourcerisk: actionrisk): blackboardentry {
867
- return { ...entry, consentclass: sourcerisk };
868
- }
869
-
870
- /** Summarizes the board for the panel: every section with its live entry count, its authors and the freshest posting time. */
871
- export function boardsummary(
872
- board: blackboard,
873
- now: number,
874
- ): Array<{ section: blackboardsection; entries: number; authors: string[]; freshestat?: number }> {
875
- return board.sections.map((section) => {
876
- const live = board.entries.filter((entry) => entry.section === section && entry.retiredat === undefined);
877
- return {
878
- section,
879
- entries: live.length,
880
- authors: [...new Set(live.map((entry) => entry.author))],
881
- ...(live.length > 0 ? { freshestat: Math.max(...live.map((entry) => entry.postedat)) } : {}),
882
- };
883
- });
884
- }