@excitedjs/dreamux 0.26.0-beta.265 → 0.26.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 (494) hide show
  1. package/CHANGELOG.json +393 -0
  2. package/CHANGELOG.md +71 -1
  3. package/README.md +47 -34
  4. package/dist/admin/client.js +18 -7
  5. package/dist/admin/client.js.map +1 -1
  6. package/dist/admin/socket.js +15 -104
  7. package/dist/admin/socket.js.map +1 -1
  8. package/dist/agent-runtime/capabilities.js +4 -17
  9. package/dist/agent-runtime/capabilities.js.map +1 -1
  10. package/dist/agent-runtime/catalog.js.map +1 -1
  11. package/dist/agent-runtime/external-provider.js.map +1 -1
  12. package/dist/agent-runtime/host-context.js +1 -12
  13. package/dist/agent-runtime/host-context.js.map +1 -1
  14. package/dist/agent-runtime/host-paths.js +1 -1
  15. package/dist/agent-runtime/host-paths.js.map +1 -1
  16. package/dist/agent-runtime/index.js +7 -0
  17. package/dist/agent-runtime/index.js.map +1 -1
  18. package/dist/agent-runtime/skill-sources.js +23 -6
  19. package/dist/agent-runtime/skill-sources.js.map +1 -1
  20. package/dist/channel/catalog.js.map +1 -1
  21. package/dist/channel/external-channel-provider.js.map +1 -1
  22. package/dist/cli/commands/daemon.js +5 -8
  23. package/dist/cli/commands/daemon.js.map +1 -1
  24. package/dist/cli/commands/dispatcher.js +11 -15
  25. package/dist/cli/commands/dispatcher.js.map +1 -1
  26. package/dist/cli/commands/index.js +4 -4
  27. package/dist/cli/commands/index.js.map +1 -1
  28. package/dist/cli/commands/mcp.js +2 -4
  29. package/dist/cli/commands/mcp.js.map +1 -1
  30. package/dist/cli/commands/onboard.js +0 -4
  31. package/dist/cli/commands/onboard.js.map +1 -1
  32. package/dist/cli/commands/parse.js +1 -1
  33. package/dist/cli/commands/parse.js.map +1 -1
  34. package/dist/cli/commands/serve.js +3 -2
  35. package/dist/cli/commands/serve.js.map +1 -1
  36. package/dist/cli/commands/status.js +3 -3
  37. package/dist/cli/commands/status.js.map +1 -1
  38. package/dist/cli/commands/types.js +25 -3
  39. package/dist/cli/commands/types.js.map +1 -1
  40. package/dist/cli/commands/uninstall.js +2 -8
  41. package/dist/cli/commands/uninstall.js.map +1 -1
  42. package/dist/cli/doctor-plugins.js +44 -0
  43. package/dist/cli/doctor-plugins.js.map +1 -0
  44. package/dist/cli/doctor-types.js +2 -0
  45. package/dist/cli/doctor-types.js.map +1 -0
  46. package/dist/cli/doctor.js +48 -125
  47. package/dist/cli/doctor.js.map +1 -1
  48. package/dist/cli/dreamux.js +2 -30
  49. package/dist/cli/dreamux.js.map +1 -1
  50. package/dist/cli/server.js +55 -70
  51. package/dist/cli/server.js.map +1 -1
  52. package/dist/command/errors.js +43 -2
  53. package/dist/command/errors.js.map +1 -1
  54. package/dist/command/host.js +10 -17
  55. package/dist/command/host.js.map +1 -1
  56. package/dist/command/payload.js +0 -9
  57. package/dist/command/payload.js.map +1 -1
  58. package/dist/command/port.js +0 -4
  59. package/dist/command/port.js.map +1 -1
  60. package/dist/command/registry.js +0 -4
  61. package/dist/command/registry.js.map +1 -1
  62. package/dist/command/schema.js.map +1 -1
  63. package/dist/command/types.js.map +1 -0
  64. package/dist/command/validate.js +22 -41
  65. package/dist/command/validate.js.map +1 -1
  66. package/dist/config/commands.js +46 -0
  67. package/dist/config/commands.js.map +1 -0
  68. package/dist/config/config.js +155 -169
  69. package/dist/config/config.js.map +1 -1
  70. package/dist/config/load.js +138 -0
  71. package/dist/config/load.js.map +1 -0
  72. package/dist/config/service.js +196 -0
  73. package/dist/config/service.js.map +1 -0
  74. package/dist/daemon/{service-control.js → control.js} +15 -16
  75. package/dist/daemon/control.js.map +1 -0
  76. package/dist/daemon/environment.js +353 -0
  77. package/dist/daemon/environment.js.map +1 -0
  78. package/dist/daemon/host.js +16 -0
  79. package/dist/daemon/host.js.map +1 -0
  80. package/dist/daemon/install.js +167 -69
  81. package/dist/daemon/install.js.map +1 -1
  82. package/dist/daemon/status.js +87 -0
  83. package/dist/daemon/status.js.map +1 -0
  84. package/dist/{cli/service-status-parse.js → daemon/unit.js} +90 -12
  85. package/dist/daemon/unit.js.map +1 -0
  86. package/dist/{service/mcp/descriptor.js → mcp/launch.js} +3 -7
  87. package/dist/mcp/launch.js.map +1 -0
  88. package/dist/mcp/server.js +9 -5
  89. package/dist/mcp/server.js.map +1 -1
  90. package/dist/mcp/shim.js +18 -16
  91. package/dist/mcp/shim.js.map +1 -1
  92. package/dist/onboard/config-files.js +12 -26
  93. package/dist/onboard/config-files.js.map +1 -1
  94. package/dist/onboard/run.js +47 -66
  95. package/dist/onboard/run.js.map +1 -1
  96. package/dist/onboard/uninstall.js +59 -42
  97. package/dist/onboard/uninstall.js.map +1 -1
  98. package/dist/onboard/wizard.js +33 -18
  99. package/dist/onboard/wizard.js.map +1 -1
  100. package/dist/{onboard/commands.js → platform/command-runner.js} +7 -3
  101. package/dist/platform/command-runner.js.map +1 -0
  102. package/dist/platform/deduplicate.js +32 -0
  103. package/dist/platform/deduplicate.js.map +1 -0
  104. package/dist/{state → platform}/dispatcher-id.js +1 -1
  105. package/dist/platform/dispatcher-id.js.map +1 -0
  106. package/dist/platform/errors.js +23 -23
  107. package/dist/platform/errors.js.map +1 -1
  108. package/dist/{onboard/ledger.js → platform/file-ledger.js} +13 -38
  109. package/dist/platform/file-ledger.js.map +1 -0
  110. package/dist/platform/history-page.js +62 -0
  111. package/dist/platform/history-page.js.map +1 -0
  112. package/dist/platform/in-flight-work.js.map +1 -0
  113. package/dist/platform/instance-lock.js +95 -0
  114. package/dist/platform/instance-lock.js.map +1 -0
  115. package/dist/platform/json-value.js +26 -15
  116. package/dist/platform/json-value.js.map +1 -1
  117. package/dist/platform/jsonl.js.map +1 -1
  118. package/dist/platform/logger.js +5 -5
  119. package/dist/platform/logger.js.map +1 -1
  120. package/dist/platform/package-bin.js +3 -1
  121. package/dist/platform/package-bin.js.map +1 -1
  122. package/dist/platform/paths.js +42 -69
  123. package/dist/platform/paths.js.map +1 -1
  124. package/dist/platform/runtime-sockets.js +7 -2
  125. package/dist/platform/runtime-sockets.js.map +1 -1
  126. package/dist/platform/serial-queue.js +22 -0
  127. package/dist/platform/serial-queue.js.map +1 -0
  128. package/dist/platform/shutdown-errors.js.map +1 -0
  129. package/dist/platform/work-fence.js +30 -0
  130. package/dist/platform/work-fence.js.map +1 -0
  131. package/dist/plugin/hooks.js +407 -0
  132. package/dist/plugin/hooks.js.map +1 -0
  133. package/dist/plugin/host.js +97 -0
  134. package/dist/plugin/host.js.map +1 -0
  135. package/dist/plugin/loader.js +250 -0
  136. package/dist/plugin/loader.js.map +1 -0
  137. package/dist/provider-diagnostics.js +12 -8
  138. package/dist/provider-diagnostics.js.map +1 -1
  139. package/dist/registry/builtins.js +49 -45
  140. package/dist/registry/builtins.js.map +1 -1
  141. package/dist/registry/index.js +10 -2
  142. package/dist/registry/index.js.map +1 -1
  143. package/dist/registry/provider-loader.js +41 -61
  144. package/dist/registry/provider-loader.js.map +1 -1
  145. package/dist/registry/provider-ref.js.map +1 -1
  146. package/dist/registry/registry.js +14 -22
  147. package/dist/registry/registry.js.map +1 -1
  148. package/dist/{command/catalog.js → server/command-catalog.js} +14 -5
  149. package/dist/server/command-catalog.js.map +1 -0
  150. package/dist/server/command-host.js +2 -0
  151. package/dist/server/command-host.js.map +1 -0
  152. package/dist/server-commands.js +1 -1
  153. package/dist/server-commands.js.map +1 -1
  154. package/dist/server.js +70 -129
  155. package/dist/server.js.map +1 -1
  156. package/dist/service/{agent-entity/activity-reader.js → agent/activity.js} +86 -34
  157. package/dist/service/agent/activity.js.map +1 -0
  158. package/dist/service/{teammate-service/admission-ledger.js → agent/admission.js} +66 -1
  159. package/dist/service/agent/admission.js.map +1 -0
  160. package/dist/service/{channel-submission.js → agent/channel-submission.js} +5 -5
  161. package/dist/service/agent/channel-submission.js.map +1 -0
  162. package/dist/service/{teammate-collection → agent}/commands.js +38 -50
  163. package/dist/service/agent/commands.js.map +1 -0
  164. package/dist/service/{teammate-service → agent}/completion-renderer.js +30 -5
  165. package/dist/service/agent/completion-renderer.js.map +1 -0
  166. package/dist/service/agent/errors.js.map +1 -0
  167. package/dist/service/agent/factory.js +78 -0
  168. package/dist/service/agent/factory.js.map +1 -0
  169. package/dist/service/{agent-entity/types.js → agent/identity.js} +28 -34
  170. package/dist/service/agent/identity.js.map +1 -0
  171. package/dist/service/agent/index.js +769 -0
  172. package/dist/service/agent/index.js.map +1 -0
  173. package/dist/service/agent/mcp.js +420 -0
  174. package/dist/service/agent/mcp.js.map +1 -0
  175. package/dist/service/agent/records.js +74 -0
  176. package/dist/service/agent/records.js.map +1 -0
  177. package/dist/service/agent/requests.js +172 -0
  178. package/dist/service/agent/requests.js.map +1 -0
  179. package/dist/service/{teammate-service/runtime-owner.js → agent/runtime-generation.js} +81 -79
  180. package/dist/service/agent/runtime-generation.js.map +1 -0
  181. package/dist/service/agent/runtime-id.js +22 -0
  182. package/dist/service/agent/runtime-id.js.map +1 -0
  183. package/dist/service/{agent-entity → agent}/runtime-state.js +33 -40
  184. package/dist/service/agent/runtime-state.js.map +1 -0
  185. package/dist/service/agent/service-types.js +28 -0
  186. package/dist/service/agent/service-types.js.map +1 -0
  187. package/dist/service/{teammate-service/index.js → agent/service.js} +236 -102
  188. package/dist/service/agent/service.js.map +1 -0
  189. package/dist/service/{agent-entity/identity-store.js → agent/store.js} +175 -96
  190. package/dist/service/agent/store.js.map +1 -0
  191. package/dist/service/agent/submission.js.map +1 -0
  192. package/dist/service/{teammate-collection → agent}/system-prompt.js +7 -3
  193. package/dist/service/agent/system-prompt.js.map +1 -0
  194. package/dist/service/agent/turn.js +89 -0
  195. package/dist/service/agent/turn.js.map +1 -0
  196. package/dist/service/agent/types.js.map +1 -0
  197. package/dist/service/channel-service/commands.js +7 -3
  198. package/dist/service/channel-service/commands.js.map +1 -1
  199. package/dist/{channel → service/channel-service}/core-port.js +6 -5
  200. package/dist/service/channel-service/core-port.js.map +1 -0
  201. package/dist/service/channel-service/index.js +211 -93
  202. package/dist/service/channel-service/index.js.map +1 -1
  203. package/dist/service/channel-service/mcp-delegate.js +8 -9
  204. package/dist/service/channel-service/mcp-delegate.js.map +1 -1
  205. package/dist/service/completion-router/index.js +27 -27
  206. package/dist/service/completion-router/index.js.map +1 -1
  207. package/dist/{channel → service/dispatcher-core-events}/conversation-projection.js +9 -7
  208. package/dist/service/dispatcher-core-events/conversation-projection.js.map +1 -0
  209. package/dist/service/dispatcher-core-events/index.js +76 -68
  210. package/dist/service/dispatcher-core-events/index.js.map +1 -1
  211. package/dist/service/dispatcher-core-events/seal.js +1 -24
  212. package/dist/service/dispatcher-core-events/seal.js.map +1 -1
  213. package/dist/service/dispatcher-service/agent.js +267 -45
  214. package/dist/service/dispatcher-service/agent.js.map +1 -1
  215. package/dist/service/dispatcher-service/base-prompt.js +2 -2
  216. package/dist/service/dispatcher-service/base-prompt.js.map +1 -1
  217. package/dist/service/dispatcher-service/index.js +139 -378
  218. package/dist/service/dispatcher-service/index.js.map +1 -1
  219. package/dist/service/dispatcher-service/lifecycle.js +230 -0
  220. package/dist/service/dispatcher-service/lifecycle.js.map +1 -0
  221. package/dist/{daemon → service/dispatcher-service}/restart-intent.js +17 -38
  222. package/dist/service/dispatcher-service/restart-intent.js.map +1 -0
  223. package/dist/service/dispatcher-workspace.js +10 -23
  224. package/dist/service/dispatcher-workspace.js.map +1 -1
  225. package/dist/service/dispatchers/commands.js +30 -31
  226. package/dist/service/dispatchers/commands.js.map +1 -1
  227. package/dist/service/dispatchers/index.js +92 -64
  228. package/dist/service/dispatchers/index.js.map +1 -1
  229. package/dist/service/index.js +2 -2
  230. package/dist/service/index.js.map +1 -1
  231. package/dist/{mcp → service/mcp}/catalog.js +11 -48
  232. package/dist/service/mcp/catalog.js.map +1 -0
  233. package/dist/service/mcp/commands.js +3 -3
  234. package/dist/service/mcp/commands.js.map +1 -1
  235. package/dist/service/mcp/dispatch-reminders.js +1 -1
  236. package/dist/service/mcp/dispatch-reminders.js.map +1 -1
  237. package/dist/service/mcp/identity-version.js +14 -0
  238. package/dist/service/mcp/identity-version.js.map +1 -1
  239. package/dist/service/mcp/leases.js +12 -33
  240. package/dist/service/mcp/leases.js.map +1 -1
  241. package/dist/service/mcp/tool-metadata.js +15 -76
  242. package/dist/service/mcp/tool-metadata.js.map +1 -1
  243. package/dist/service/name-allocator.js +2 -3
  244. package/dist/service/name-allocator.js.map +1 -1
  245. package/dist/service/scheduler/commands.js +7 -19
  246. package/dist/service/scheduler/commands.js.map +1 -1
  247. package/dist/service/scheduler/errors.js +1 -1
  248. package/dist/service/scheduler/errors.js.map +1 -1
  249. package/dist/service/scheduler/{service.js → index.js} +175 -142
  250. package/dist/service/scheduler/index.js.map +1 -0
  251. package/dist/service/scheduler/{mcp-delegate.js → mcp.js} +61 -58
  252. package/dist/service/scheduler/mcp.js.map +1 -0
  253. package/dist/service/scheduler/requests.js +60 -0
  254. package/dist/service/scheduler/requests.js.map +1 -0
  255. package/dist/service/scheduler/store.js +183 -151
  256. package/dist/service/scheduler/store.js.map +1 -1
  257. package/dist/service/scheduler/types.js +1 -33
  258. package/dist/service/scheduler/types.js.map +1 -1
  259. package/dist/service/{team-collection → team}/commands.js +45 -59
  260. package/dist/service/team/commands.js.map +1 -0
  261. package/dist/service/{team-collection → team}/create-request.js +8 -20
  262. package/dist/service/team/create-request.js.map +1 -0
  263. package/dist/service/{team-collection → team}/errors.js +7 -10
  264. package/dist/service/team/errors.js.map +1 -0
  265. package/dist/service/team/index.js +817 -0
  266. package/dist/service/team/index.js.map +1 -0
  267. package/dist/service/team/leader-mcp.js +42 -0
  268. package/dist/service/team/leader-mcp.js.map +1 -0
  269. package/dist/service/team/leader.js +157 -0
  270. package/dist/service/team/leader.js.map +1 -0
  271. package/dist/service/team/mcp.js +328 -0
  272. package/dist/service/team/mcp.js.map +1 -0
  273. package/dist/service/{team-collection/types.js → team/requests.js} +64 -15
  274. package/dist/service/team/requests.js.map +1 -0
  275. package/dist/service/team/service.js +903 -0
  276. package/dist/service/team/service.js.map +1 -0
  277. package/dist/service/team/store.js +373 -0
  278. package/dist/service/team/store.js.map +1 -0
  279. package/dist/service/team/team-summary.js.map +1 -0
  280. package/dist/service/team/teams-port.js +2 -0
  281. package/dist/service/team/teams-port.js.map +1 -0
  282. package/dist/service/team/types.js +22 -0
  283. package/dist/service/team/types.js.map +1 -0
  284. package/dist/service/workflow-service/commands.js +5 -6
  285. package/dist/service/workflow-service/commands.js.map +1 -1
  286. package/dist/service/workflow-service/errors.js +2 -0
  287. package/dist/service/workflow-service/errors.js.map +1 -1
  288. package/dist/service/workflow-service/index.js +80 -112
  289. package/dist/service/workflow-service/index.js.map +1 -1
  290. package/dist/service/workflow-service/journal.js +90 -6
  291. package/dist/service/workflow-service/journal.js.map +1 -1
  292. package/dist/service/workflow-service/limits.js +20 -9
  293. package/dist/service/workflow-service/limits.js.map +1 -1
  294. package/dist/service/workflow-service/mcp.js +171 -0
  295. package/dist/service/workflow-service/mcp.js.map +1 -0
  296. package/dist/service/workflow-service/protocol.js +72 -1
  297. package/dist/service/workflow-service/protocol.js.map +1 -1
  298. package/dist/service/workflow-service/requests.js +70 -0
  299. package/dist/service/workflow-service/requests.js.map +1 -0
  300. package/dist/service/workflow-service/run.js +258 -145
  301. package/dist/service/workflow-service/run.js.map +1 -1
  302. package/dist/service/workflow-service/runner-process.js +0 -19
  303. package/dist/service/workflow-service/runner-process.js.map +1 -1
  304. package/dist/service/workflow-service/runner.js +6 -30
  305. package/dist/service/workflow-service/runner.js.map +1 -1
  306. package/dist/service/workflow-service/script-compiler.js +7 -9
  307. package/dist/service/workflow-service/script-compiler.js.map +1 -1
  308. package/dist/service/workflow-service/{run-support.js → semaphore.js} +1 -30
  309. package/dist/service/workflow-service/semaphore.js.map +1 -0
  310. package/dist/service/workflow-service/store.js +105 -25
  311. package/dist/service/workflow-service/store.js.map +1 -1
  312. package/dist/service/workflow-service/types.js +1 -77
  313. package/dist/service/workflow-service/types.js.map +1 -1
  314. package/dist/service/worktree/manager.js +29 -62
  315. package/dist/service/worktree/manager.js.map +1 -1
  316. package/dist/service/worktree/paths.js +4 -1
  317. package/dist/service/worktree/paths.js.map +1 -1
  318. package/dist/service/worktree/repo-request.js +38 -14
  319. package/dist/service/worktree/repo-request.js.map +1 -1
  320. package/dist/service/worktree/types.js +2 -0
  321. package/dist/service/worktree/types.js.map +1 -0
  322. package/dist/service/worktree/workspaces.js +27 -34
  323. package/dist/service/worktree/workspaces.js.map +1 -1
  324. package/package.json +13 -8
  325. package/skills/dispatcher/dreamux-maintenance/SKILL.md +5 -4
  326. package/skills/dispatcher/dreamux-maintenance/references/builtin-bootstrap.md +50 -0
  327. package/skills/dispatcher/dreamux-maintenance/references/builtin-codex.md +4 -5
  328. package/skills/dispatcher/dreamux-maintenance/references/builtin-feishu.md +69 -11
  329. package/skills/dispatcher/dreamux-maintenance/references/config-envelope.md +77 -12
  330. package/skills/dispatcher/dreamux-maintenance/references/feishu-access-v3.md +39 -24
  331. package/skills/dispatcher/dreamux-maintenance/references/service-lifecycle.md +105 -37
  332. package/dist/channel/conversation-projection.js.map +0 -1
  333. package/dist/channel/core-port.js.map +0 -1
  334. package/dist/cli/server-ctl.js +0 -163
  335. package/dist/cli/server-ctl.js.map +0 -1
  336. package/dist/cli/service-status-parse.js.map +0 -1
  337. package/dist/command/catalog.js.map +0 -1
  338. package/dist/config/config-helpers.js +0 -100
  339. package/dist/config/config-helpers.js.map +0 -1
  340. package/dist/daemon/restart-intent.js.map +0 -1
  341. package/dist/daemon/service-control.js.map +0 -1
  342. package/dist/mcp/catalog.js.map +0 -1
  343. package/dist/mcp/failure-text.js +0 -46
  344. package/dist/mcp/failure-text.js.map +0 -1
  345. package/dist/onboard/commands.js.map +0 -1
  346. package/dist/onboard/ledger.js.map +0 -1
  347. package/dist/onboard/service-node.js +0 -183
  348. package/dist/onboard/service-node.js.map +0 -1
  349. package/dist/onboard/service.js +0 -310
  350. package/dist/onboard/service.js.map +0 -1
  351. package/dist/platform/atomic-write.js +0 -63
  352. package/dist/platform/atomic-write.js.map +0 -1
  353. package/dist/platform/error-info.js +0 -11
  354. package/dist/platform/error-info.js.map +0 -1
  355. package/dist/platform/json-document-store.js +0 -54
  356. package/dist/platform/json-document-store.js.map +0 -1
  357. package/dist/service/agent-entity/activity-errors.js +0 -71
  358. package/dist/service/agent-entity/activity-errors.js.map +0 -1
  359. package/dist/service/agent-entity/activity-reader.js.map +0 -1
  360. package/dist/service/agent-entity/agent-config.js +0 -48
  361. package/dist/service/agent-entity/agent-config.js.map +0 -1
  362. package/dist/service/agent-entity/history-query.js +0 -60
  363. package/dist/service/agent-entity/history-query.js.map +0 -1
  364. package/dist/service/agent-entity/identity-store.js.map +0 -1
  365. package/dist/service/agent-entity/read-helpers.js +0 -172
  366. package/dist/service/agent-entity/read-helpers.js.map +0 -1
  367. package/dist/service/agent-entity/runtime-profile.js +0 -53
  368. package/dist/service/agent-entity/runtime-profile.js.map +0 -1
  369. package/dist/service/agent-entity/runtime-state.js.map +0 -1
  370. package/dist/service/agent-entity/types.js.map +0 -1
  371. package/dist/service/channel-service/mcp-delegates.js +0 -21
  372. package/dist/service/channel-service/mcp-delegates.js.map +0 -1
  373. package/dist/service/channel-service/types.js.map +0 -1
  374. package/dist/service/channel-submission.js.map +0 -1
  375. package/dist/service/closed-fact.js +0 -49
  376. package/dist/service/closed-fact.js.map +0 -1
  377. package/dist/service/deduplicate.js +0 -42
  378. package/dist/service/deduplicate.js.map +0 -1
  379. package/dist/service/dispatcher-core-events/scoped-source.js +0 -59
  380. package/dist/service/dispatcher-core-events/scoped-source.js.map +0 -1
  381. package/dist/service/dispatcher-service/dispatcher-workflows.js +0 -50
  382. package/dist/service/dispatcher-service/dispatcher-workflows.js.map +0 -1
  383. package/dist/service/dispatcher-service/identity.js +0 -97
  384. package/dist/service/dispatcher-service/identity.js.map +0 -1
  385. package/dist/service/dispatcher-service/inbound-task-drain.js +0 -37
  386. package/dist/service/dispatcher-service/inbound-task-drain.js.map +0 -1
  387. package/dist/service/dispatcher-service/input-source-lifecycle.js +0 -312
  388. package/dist/service/dispatcher-service/input-source-lifecycle.js.map +0 -1
  389. package/dist/service/dispatcher-service/input-source-start-rollback.js +0 -53
  390. package/dist/service/dispatcher-service/input-source-start-rollback.js.map +0 -1
  391. package/dist/service/dispatcher-service/mcp-delegates.js +0 -67
  392. package/dist/service/dispatcher-service/mcp-delegates.js.map +0 -1
  393. package/dist/service/dispatcher-service/restart-notice.js +0 -27
  394. package/dist/service/dispatcher-service/restart-notice.js.map +0 -1
  395. package/dist/service/dispatcher-service/runnable-channel.js +0 -13
  396. package/dist/service/dispatcher-service/runnable-channel.js.map +0 -1
  397. package/dist/service/dispatcher-service/runtime-helpers.js +0 -11
  398. package/dist/service/dispatcher-service/runtime-helpers.js.map +0 -1
  399. package/dist/service/dispatcher-service/runtime-status.js +0 -35
  400. package/dist/service/dispatcher-service/runtime-status.js.map +0 -1
  401. package/dist/service/dispatcher-service/team-leader-handle.js +0 -29
  402. package/dist/service/dispatcher-service/team-leader-handle.js.map +0 -1
  403. package/dist/service/dispatcher-service/team-runtime-stop.js +0 -13
  404. package/dist/service/dispatcher-service/team-runtime-stop.js.map +0 -1
  405. package/dist/service/dispatcher-service/teammate-ops.js +0 -14
  406. package/dist/service/dispatcher-service/teammate-ops.js.map +0 -1
  407. package/dist/service/frozen-snapshot.js +0 -16
  408. package/dist/service/frozen-snapshot.js.map +0 -1
  409. package/dist/service/in-flight-work.js.map +0 -1
  410. package/dist/service/legacy-state.js +0 -119
  411. package/dist/service/legacy-state.js.map +0 -1
  412. package/dist/service/mcp/descriptor.js.map +0 -1
  413. package/dist/service/scheduler/mcp-delegate.js.map +0 -1
  414. package/dist/service/scheduler/service.js.map +0 -1
  415. package/dist/service/serial-queue.js +0 -64
  416. package/dist/service/serial-queue.js.map +0 -1
  417. package/dist/service/shutdown-errors.js.map +0 -1
  418. package/dist/service/team-collection/commands.js.map +0 -1
  419. package/dist/service/team-collection/create-request.js.map +0 -1
  420. package/dist/service/team-collection/errors.js.map +0 -1
  421. package/dist/service/team-collection/index.js +0 -304
  422. package/dist/service/team-collection/index.js.map +0 -1
  423. package/dist/service/team-collection/mcp-delegate.js +0 -389
  424. package/dist/service/team-collection/mcp-delegate.js.map +0 -1
  425. package/dist/service/team-collection/read-helpers.js +0 -66
  426. package/dist/service/team-collection/read-helpers.js.map +0 -1
  427. package/dist/service/team-collection/read-model.js +0 -120
  428. package/dist/service/team-collection/read-model.js.map +0 -1
  429. package/dist/service/team-collection/roster-reader.js +0 -52
  430. package/dist/service/team-collection/roster-reader.js.map +0 -1
  431. package/dist/service/team-collection/runtime-registry.js +0 -369
  432. package/dist/service/team-collection/runtime-registry.js.map +0 -1
  433. package/dist/service/team-collection/store.js +0 -320
  434. package/dist/service/team-collection/store.js.map +0 -1
  435. package/dist/service/team-collection/types.js.map +0 -1
  436. package/dist/service/team-collection/worktree-cleanup.js +0 -45
  437. package/dist/service/team-collection/worktree-cleanup.js.map +0 -1
  438. package/dist/service/team-service/closing.js +0 -279
  439. package/dist/service/team-service/closing.js.map +0 -1
  440. package/dist/service/team-service/collaborators.js +0 -82
  441. package/dist/service/team-service/collaborators.js.map +0 -1
  442. package/dist/service/team-service/completion-targets.js +0 -72
  443. package/dist/service/team-service/completion-targets.js.map +0 -1
  444. package/dist/service/team-service/index.js +0 -559
  445. package/dist/service/team-service/index.js.map +0 -1
  446. package/dist/service/team-service/leader-agent.js +0 -170
  447. package/dist/service/team-service/leader-agent.js.map +0 -1
  448. package/dist/service/team-service/roster-projection.js +0 -69
  449. package/dist/service/team-service/roster-projection.js.map +0 -1
  450. package/dist/service/team-service/team-summary.js.map +0 -1
  451. package/dist/service/team-service/types.js +0 -61
  452. package/dist/service/team-service/types.js.map +0 -1
  453. package/dist/service/teammate-collection/commands.js.map +0 -1
  454. package/dist/service/teammate-collection/dissolve-members.js +0 -44
  455. package/dist/service/teammate-collection/dissolve-members.js.map +0 -1
  456. package/dist/service/teammate-collection/errors.js.map +0 -1
  457. package/dist/service/teammate-collection/index.js +0 -497
  458. package/dist/service/teammate-collection/index.js.map +0 -1
  459. package/dist/service/teammate-collection/mcp-delegate.js +0 -210
  460. package/dist/service/teammate-collection/mcp-delegate.js.map +0 -1
  461. package/dist/service/teammate-collection/mcp-tool-descriptors.js +0 -421
  462. package/dist/service/teammate-collection/mcp-tool-descriptors.js.map +0 -1
  463. package/dist/service/teammate-collection/system-prompt.js.map +0 -1
  464. package/dist/service/teammate-collection/types.js.map +0 -1
  465. package/dist/service/teammate-service/admission-ledger.js.map +0 -1
  466. package/dist/service/teammate-service/completion-renderer.js.map +0 -1
  467. package/dist/service/teammate-service/factory.js +0 -5
  468. package/dist/service/teammate-service/factory.js.map +0 -1
  469. package/dist/service/teammate-service/index.js.map +0 -1
  470. package/dist/service/teammate-service/runtime-owner.js.map +0 -1
  471. package/dist/service/teammate-service/submission.js.map +0 -1
  472. package/dist/service/teammate-service/turn-coordinator.js +0 -93
  473. package/dist/service/teammate-service/turn-coordinator.js.map +0 -1
  474. package/dist/service/teammate-service/turn-recording.js +0 -178
  475. package/dist/service/teammate-service/turn-recording.js.map +0 -1
  476. package/dist/service/teammate-service/types.js +0 -12
  477. package/dist/service/teammate-service/types.js.map +0 -1
  478. package/dist/service/workflow-service/agent-policy.js +0 -6
  479. package/dist/service/workflow-service/agent-policy.js.map +0 -1
  480. package/dist/service/workflow-service/json-args.js +0 -72
  481. package/dist/service/workflow-service/json-args.js.map +0 -1
  482. package/dist/service/workflow-service/run-support.js.map +0 -1
  483. package/dist/service/workflow-service/run-terminal.js +0 -111
  484. package/dist/service/workflow-service/run-terminal.js.map +0 -1
  485. package/dist/state/dispatcher-id.js.map +0 -1
  486. package/dist/state/dispatcher-store.js +0 -73
  487. package/dist/state/dispatcher-store.js.map +0 -1
  488. /package/dist/{service/channel-service → command}/types.js +0 -0
  489. /package/dist/{service → platform}/in-flight-work.js +0 -0
  490. /package/dist/{service → platform}/shutdown-errors.js +0 -0
  491. /package/dist/service/{teammate-collection → agent}/errors.js +0 -0
  492. /package/dist/service/{teammate-service → agent}/submission.js +0 -0
  493. /package/dist/service/{teammate-collection → agent}/types.js +0 -0
  494. /package/dist/service/{team-service → team}/team-summary.js +0 -0
@@ -1,43 +1,90 @@
1
- import { isUnsupportedFeatureError } from '@excitedjs/dreamux-utils';
2
- import { errorInfo, errorMessage } from '../../platform/error-info.js';
3
- import { InFlightWork } from '../in-flight-work.js';
4
- import { throwSettledFailures } from '../shutdown-errors.js';
1
+ import { errorInfo, errorMessage, isUnsupportedFeatureError, } from '@excitedjs/dreamux-utils';
2
+ import { ForkedWorkflowRunner } from './runner-process.js';
3
+ import { InFlightWork } from '../../platform/in-flight-work.js';
4
+ import { workflowRunJournalPath } from '../../platform/paths.js';
5
+ import { throwSettledFailures } from '../../platform/shutdown-errors.js';
5
6
  import { AGENT_TASK_SOURCE } from '../submission-sources.js';
6
- import { WORKFLOW_AGENT_SYSTEM_PROMPT } from './agent-policy.js';
7
- import { isWorkflowRunnerChildMessage, } from './runner-process.js';
8
- import { nonEmpty, normalizeAgentOptions, WorkflowPersistenceError, WorkflowSemaphore, } from './run-support.js';
9
- import { WorkflowRunTerminal } from './run-terminal.js';
10
- const MAX_AGENTS = 1000;
7
+ import { WorkflowPersistenceError } from './errors.js';
8
+ import { WorkflowJournal, } from './journal.js';
9
+ import { MAX_AGENTS } from './limits.js';
10
+ import { isWorkflowRunnerChildMessage, normalizeAgentOptions, } from './protocol.js';
11
+ import { WorkflowSemaphore } from './semaphore.js';
12
+ /** Appended to every agent's system prompt: this call's output is consumed
13
+ * by the workflow, not shown to a human. */
14
+ export const WORKFLOW_AGENT_SYSTEM_PROMPT = 'You are executing one agent call inside a Dreamux workflow. Your final ' +
15
+ 'response is the return value consumed by the workflow, not a human-facing ' +
16
+ 'progress message. Return only the requested value. When an output schema is ' +
17
+ "provided, use the runtime's structured-output mechanism and satisfy the " +
18
+ 'schema exactly.';
19
+ /** `value` when it is a non-empty (after trimming) string, otherwise `null`. */
20
+ function nonEmpty(value) {
21
+ if (value === undefined || value.trim() === '')
22
+ return null;
23
+ return value;
24
+ }
11
25
  /** One live Workflow entity with direct locked TeamMate and Turn ownership. */
12
26
  export class WorkflowRun {
13
27
  deps;
14
28
  record;
29
+ /** This run's own durability journal, bound from its own scope and run id
30
+ * — no owner hands one in. */
31
+ journal;
15
32
  runner;
16
33
  semaphore;
17
- terminal;
18
34
  calls = new Map();
19
35
  materializations = new InFlightWork();
20
36
  runnerMessageTasks = new InFlightWork();
21
37
  agentTasks = new InFlightWork();
22
38
  unlockedHandles = new Set();
23
- mutationTail = Promise.resolve();
24
39
  runnerMessageTail = Promise.resolve();
40
+ /** Flips at *receipt* of a `run_result` message, before it is queued behind
41
+ * `runnerMessageTail` — distinct from `terminalIntent`, which is set only
42
+ * once that queued message is actually processed. Guards the receive-time
43
+ * window between the two: a second `run_result` or an `onExit` racing in
44
+ * it must still be dropped. */
25
45
  runnerTerminalMessageSeen = false;
46
+ /** The full record {@link finalize} will commit, computed once after
47
+ * teardown and memoized so a retried finalize reuses the same `ended_at`
48
+ * instead of recomputing a different one — unlike `terminalIntent`, which
49
+ * is reserved before teardown even starts. */
26
50
  terminalCandidate = null;
27
- terminalJournalCommitted = false;
28
51
  /**
29
52
  * The terminal report this run still owes its initiator; `null` once it is
30
53
  * delivered, or once a stop made it not news: the initiator or its own scope
31
54
  * fence asked for the stop, so the party that ended the run would read it.
32
55
  */
33
- deliverTerminal;
34
- terminalLogged = false;
56
+ recipient;
57
+ /** Set once, by whichever of {@link reserveStop}/{@link requestTerminal}
58
+ * wins. */
59
+ terminalIntent = null;
60
+ /** Memoized {@link finalize} task; cleared on failure so a retry re-runs
61
+ * it. */
62
+ terminalTask = null;
63
+ announceSettled;
64
+ /**
65
+ * Resolves once this run is durably over: terminal record written, terminal
66
+ * completion delivered, nothing left to retry.
67
+ *
68
+ * It is a fact the run states about itself, not an instruction. The owner
69
+ * that holds the run decides what being over means for its own bookkeeping;
70
+ * the run does not reach up and remove itself from a collection it is not
71
+ * allowed to know about.
72
+ */
73
+ settled;
35
74
  constructor(deps) {
36
75
  this.deps = deps;
37
76
  this.record = deps.record;
38
- this.deliverTerminal = deps.deliverTerminal;
77
+ this.journal = new WorkflowJournal(workflowRunJournalPath({
78
+ dispatcherId: deps.record.dispatcher_id,
79
+ teamId: deps.record.team_id,
80
+ runId: deps.record.run_id,
81
+ }));
82
+ this.recipient = deps.recipient;
39
83
  this.semaphore = new WorkflowSemaphore(deps.record.max_concurrency);
40
- this.runner = deps.createRunner({
84
+ this.settled = new Promise((resolve) => {
85
+ this.announceSettled = resolve;
86
+ });
87
+ this.runner = new ForkedWorkflowRunner(deps.runnerEntryPath, {
41
88
  onMessage: (message) => this.receiveRunnerMessage(message),
42
89
  onExit: (exit) => {
43
90
  deps.log.info({
@@ -46,41 +93,35 @@ export class WorkflowRun {
46
93
  signal: exit.signal,
47
94
  }, 'workflow runner exited');
48
95
  if (!this.runnerTerminalMessageSeen &&
49
- this.terminal.requested === null) {
50
- this.terminal.observe('failed', null, `workflow runner exited before reporting a result (code=${String(exit.code)}, signal=${String(exit.signal)})`);
96
+ this.terminalRequested === null) {
97
+ this.observeTerminal('failed', null, `workflow runner exited before reporting a result (code=${String(exit.code)}, signal=${String(exit.signal)})`);
51
98
  }
52
99
  },
53
100
  onError: (error) => {
54
101
  deps.log.error({ run_id: this.record.run_id, err: errorInfo(error) }, 'workflow runner error');
55
- if (this.terminal.requested === null) {
56
- this.terminal.observe('failed', null, error.message);
102
+ if (this.terminalRequested === null) {
103
+ this.observeTerminal('failed', null, error.message);
57
104
  }
58
105
  },
59
106
  });
60
- this.terminal = new WorkflowRunTerminal({
61
- runId: this.record.run_id,
62
- status: () => this.record.status,
63
- abortRunner: () => this.runner.send({ type: 'abort' }),
64
- closeAdmission: (status) => {
65
- this.semaphore.close(new Error(`workflow ${status}`));
66
- // Reached once, when the first terminal intent is reserved. Only a
67
- // stop reserves `stopped`; a completed or failed intent that won first
68
- // keeps its report, and a delivery already under way is never behind
69
- // this call.
70
- if (status === 'stopped')
71
- this.deliverTerminal = null;
72
- },
73
- finalize: (status, result, error) => this.finalize(status, result, error),
74
- log: deps.log,
75
- });
76
107
  }
77
- /** Resolves once this run is durably terminal; the owner reads it to evict. */
78
- get settled() { return this.terminal.settled; }
108
+ /**
109
+ * The run's last *committed* value — what `workflow_status`/`workflow_list`
110
+ * read — never the in-progress draft `this.record` becomes between a
111
+ * mutation and the {@link persist} call that publishes it. Reachable only
112
+ * after `initialize()` has published this run's first committed record
113
+ * (the owner does not register this `WorkflowRun` until then), so the
114
+ * handle is always loaded here.
115
+ */
79
116
  snapshot() {
80
- return structuredClone(this.record);
117
+ const current = this.deps.store.handle(this.record.run_id).current;
118
+ if (current === null) {
119
+ throw new Error(`workflow run ${JSON.stringify(this.record.run_id)} has no committed record`);
120
+ }
121
+ return structuredClone(current);
81
122
  }
82
123
  async initialize() {
83
- await this.deps.journal.create({
124
+ await this.journal.create({
84
125
  kind: 'run',
85
126
  version: 1,
86
127
  run_id: this.record.run_id,
@@ -94,41 +135,117 @@ export class WorkflowRun {
94
135
  }
95
136
  async start(script, args) {
96
137
  try {
97
- if (this.terminal.requested !== null) {
98
- await this.terminal.stop();
138
+ if (this.terminalRequested !== null) {
139
+ await this.stop();
99
140
  return;
100
141
  }
101
142
  await this.runner.start();
102
- if (this.terminal.requested !== null) {
103
- await this.terminal.stop();
143
+ if (this.terminalRequested !== null) {
144
+ await this.stop();
104
145
  return;
105
146
  }
106
147
  await this.runner.send({ type: 'run_start', script, args });
107
148
  }
108
149
  catch (error) {
109
- await this.terminal.request('failed', null, errorMessage(error));
150
+ await this.requestTerminal('failed', null, errorMessage(error));
110
151
  }
111
152
  }
112
153
  async stop() {
113
- return this.terminal.stop();
154
+ if (this.terminalIntent === null && this.record.status !== 'running') {
155
+ return this.record.status;
156
+ }
157
+ this.reserveStop();
158
+ await this.ensureTerminalTask();
159
+ return (this.terminalRequested ?? this.record.status);
160
+ }
161
+ requestStop() {
162
+ this.reserveStop();
163
+ }
164
+ get terminalRequested() {
165
+ return this.terminalIntent?.status ?? null;
166
+ }
167
+ /** Gates a new `agent_start` and an `emit` phase/log update: no terminal
168
+ * intent reserved, and `record.status` — the committed fact, kept even
169
+ * though a live run cannot leave `running` without first reserving one —
170
+ * still says `running`. */
171
+ get terminalAccepting() {
172
+ return this.terminalIntent === null && this.record.status === 'running';
114
173
  }
115
- closeAdmission() {
116
- this.terminal.reserveStop();
174
+ get terminalSuppressDelivery() {
175
+ return this.terminalIntent !== null;
176
+ }
177
+ /** Reserve the `stopped` intent and signal the runner; a no-op once an
178
+ * intent is already reserved or the run is no longer `running`. */
179
+ reserveStop() {
180
+ if (this.terminalIntent !== null || this.record.status !== 'running') {
181
+ return;
182
+ }
183
+ this.terminalIntent = { status: 'stopped', result: null, error: null };
184
+ this.closeOnTerminalIntent('stopped');
185
+ this.deps.log.info({ run_id: this.record.run_id }, 'stopping workflow run');
186
+ void this.runner.send({ type: 'abort' }).catch((error) => {
187
+ this.deps.log.warn({ run_id: this.record.run_id, err: errorInfo(error) }, 'workflow abort IPC failed; killing runner');
188
+ });
189
+ }
190
+ /** Reserve an already-known status/result/error, then return the shared
191
+ * {@link finalize} task; a no-op reservation once an intent exists, but the
192
+ * task is still returned so every caller converges on the same wait. */
193
+ requestTerminal(status, result, error) {
194
+ if (this.terminalIntent === null) {
195
+ this.terminalIntent = { status, result, error };
196
+ this.closeOnTerminalIntent(status);
197
+ }
198
+ return this.ensureTerminalTask();
199
+ }
200
+ /** Fire-and-forget {@link requestTerminal}, for an observed terminal fact
201
+ * (a runner exit) rather than one the caller itself caused. */
202
+ observeTerminal(status, result, error) {
203
+ void this.requestTerminal(status, result, error).catch((terminalError) => {
204
+ this.deps.log.error({ run_id: this.record.run_id, err: errorInfo(terminalError) }, 'workflow terminal transition failed');
205
+ });
206
+ }
207
+ /** Reached once, when the first terminal intent is reserved: no further
208
+ * Agent may acquire a concurrency slot, and — only for a stop — the
209
+ * initiator no longer gets a completion push, since the party that ended
210
+ * the run would read it itself. A completed or failed intent that won the
211
+ * race keeps its report. */
212
+ closeOnTerminalIntent(status) {
213
+ this.semaphore.close(new Error(`workflow ${status}`));
214
+ if (status === 'stopped')
215
+ this.recipient = null;
216
+ }
217
+ /** The one retryable {@link finalize} task, shared by every caller. */
218
+ ensureTerminalTask() {
219
+ if (this.terminalTask !== null)
220
+ return this.terminalTask;
221
+ const intent = this.terminalIntent;
222
+ if (intent === null)
223
+ return Promise.resolve();
224
+ const task = this.finalize(intent.status, intent.result, intent.error)
225
+ .then(() => {
226
+ this.announceSettled();
227
+ })
228
+ .catch((error) => {
229
+ if (this.terminalTask === task)
230
+ this.terminalTask = null;
231
+ throw error;
232
+ });
233
+ this.terminalTask = task;
234
+ return task;
117
235
  }
118
236
  receiveRunnerMessage(message) {
119
237
  if (!isWorkflowRunnerChildMessage(message)) {
120
238
  this.deps.log.warn({ run_id: this.record.run_id }, 'ignoring malformed workflow runner message');
121
239
  return;
122
240
  }
123
- if (this.runnerTerminalMessageSeen ||
124
- this.terminal.requested !== null)
241
+ if (this.runnerTerminalMessageSeen || this.terminalRequested !== null)
125
242
  return;
126
243
  if (message.type === 'run_result')
127
244
  this.runnerTerminalMessageSeen = true;
128
245
  const task = this.runnerMessageTail
129
246
  .then(() => this.handleRunnerMessage(message))
130
247
  .catch((error) => {
131
- this.terminal.observe('failed', null, errorMessage(error));
248
+ this.observeTerminal('failed', null, errorMessage(error));
132
249
  });
133
250
  this.runnerMessageTail = task;
134
251
  if (message.type !== 'run_result')
@@ -140,16 +257,15 @@ export class WorkflowRun {
140
257
  await this.handleAgentStart(message);
141
258
  return;
142
259
  case 'emit':
143
- if (this.record.status !== 'running' ||
144
- this.terminal.requested !== null)
260
+ if (!this.terminalAccepting)
145
261
  return;
146
- await this.mutate(async () => {
147
- if (message.kind === 'phase')
148
- this.record.phase = message.message;
149
- else
150
- this.record.last_log = message.message;
151
- this.record.updated_at = this.now();
152
- await this.deps.journal.append({
262
+ if (message.kind === 'phase')
263
+ this.record.phase = message.message;
264
+ else
265
+ this.record.last_log = message.message;
266
+ this.record.updated_at = Date.now();
267
+ await this.persist(async () => {
268
+ await this.journal.append({
153
269
  kind: message.kind,
154
270
  message: message.message,
155
271
  created_at: this.record.updated_at,
@@ -158,16 +274,14 @@ export class WorkflowRun {
158
274
  });
159
275
  return;
160
276
  case 'run_result':
161
- if (this.terminal.requested !== null)
277
+ if (this.terminalRequested !== null)
162
278
  return;
163
- await this.terminal.request(message.status === 'completed' ? 'completed' : 'failed', message.status === 'completed' ? message.result ?? null : null, message.status === 'completed' ? null : message.error);
279
+ await this.requestTerminal(message.status === 'completed' ? 'completed' : 'failed', message.status === 'completed' ? (message.result ?? null) : null, message.status === 'completed' ? null : message.error);
164
280
  return;
165
281
  }
166
282
  }
167
283
  async handleAgentStart(message) {
168
- if (!this.terminal.accepting ||
169
- this.record.status !== 'running' ||
170
- this.terminal.requested !== null) {
284
+ if (!this.terminalAccepting) {
171
285
  await this.sendAgentError(message.index, 'workflow is no longer running');
172
286
  return;
173
287
  }
@@ -187,7 +301,7 @@ export class WorkflowRun {
187
301
  await this.sendAgentError(message.index, errorMessage(error));
188
302
  return;
189
303
  }
190
- const createdAt = this.now();
304
+ const createdAt = Date.now();
191
305
  const record = {
192
306
  index: message.index,
193
307
  name: null,
@@ -206,13 +320,12 @@ export class WorkflowRun {
206
320
  handle: null,
207
321
  turn: null,
208
322
  resultCandidate: null,
209
- resultJournalCommitted: false,
210
323
  completed: false,
211
324
  };
212
325
  this.calls.set(message.index, call);
213
326
  this.record.agents.push(record);
214
327
  this.record.updated_at = createdAt;
215
- await this.mutate(() => this.deps.store.write(this.record));
328
+ await this.persist(() => this.deps.store.write(this.record));
216
329
  this.deps.log.info({
217
330
  run_id: this.record.run_id,
218
331
  index: message.index,
@@ -227,30 +340,26 @@ export class WorkflowRun {
227
340
  let releaseSlot = null;
228
341
  try {
229
342
  releaseSlot = await this.semaphore.acquire();
230
- if (this.terminal.requested !== null) {
343
+ if (this.terminalRequested !== null) {
231
344
  await this.completeAgent(call, 'stopped', null, null);
232
345
  return;
233
346
  }
234
347
  call.record.status = 'running';
235
348
  call.record.phase = call.options.phase ?? this.record.phase;
236
- this.record.updated_at = this.now();
237
- await this.mutate(() => this.deps.store.write(this.record));
238
- if (this.terminal.requested !== null) {
349
+ this.record.updated_at = Date.now();
350
+ await this.persist(() => this.deps.store.write(this.record));
351
+ if (this.terminalRequested !== null) {
239
352
  await this.completeAgent(call, 'stopped', null, null);
240
353
  return;
241
354
  }
242
- const materialization = this.deps.createLocked({
355
+ const materialization = this.deps.teammates.createLocked({
243
356
  name: nonEmpty(call.options.label) ??
244
357
  `workflow-${this.record.run_id}-${call.record.index + 1}`,
245
358
  prompt,
246
359
  intent: call.options.intent ??
247
360
  `Workflow ${this.record.run_id} agent ${call.record.index + 1}`,
248
- ...(call.options.agentType !== undefined
249
- ? { agentRuntime: call.options.agentType }
250
- : {}),
251
- ...(call.options.identity !== undefined
252
- ? { identity: call.options.identity }
253
- : {}),
361
+ agentRuntime: call.options.agentType,
362
+ identity: call.options.identity,
254
363
  }, {
255
364
  systemPromptAppend: [WORKFLOW_AGENT_SYSTEM_PROMPT],
256
365
  outputSchema: call.options.schema,
@@ -260,10 +369,10 @@ export class WorkflowRun {
260
369
  const handle = await materialization;
261
370
  call.handle = handle;
262
371
  call.record.name = handle.name;
263
- const submittedAt = this.now();
372
+ const submittedAt = Date.now();
264
373
  this.record.updated_at = submittedAt;
265
- await this.mutate(async () => {
266
- await this.deps.journal.append({
374
+ await this.persist(async () => {
375
+ await this.journal.append({
267
376
  kind: 'submit',
268
377
  index: call.record.index,
269
378
  name: handle.name,
@@ -271,7 +380,7 @@ export class WorkflowRun {
271
380
  });
272
381
  await this.deps.store.write(this.record);
273
382
  });
274
- if (this.terminal.requested !== null) {
383
+ if (this.terminalRequested !== null) {
275
384
  await this.completeAgent(call, 'stopped', null, null);
276
385
  return;
277
386
  }
@@ -279,10 +388,10 @@ export class WorkflowRun {
279
388
  prompt,
280
389
  // A Workflow step is work one Agent handed to another, exactly like an
281
390
  // MCP spawn; who scheduled it is already the turn's own identity.
391
+ // The step's output schema is already bound at creation time (above,
392
+ // via CreateLockedTeammateOptions) and cannot vary per submission —
393
+ // WorkflowTeammateSubmitInput carries no outputSchema field.
282
394
  source: AGENT_TASK_SOURCE,
283
- ...(call.options.schema !== undefined
284
- ? { outputSchema: call.options.schema }
285
- : {}),
286
395
  });
287
396
  this.deps.log.info({
288
397
  run_id: this.record.run_id,
@@ -294,16 +403,16 @@ export class WorkflowRun {
294
403
  }
295
404
  catch (error) {
296
405
  if (error instanceof WorkflowPersistenceError) {
297
- this.terminal.observe('failed', null, error.message);
406
+ this.observeTerminal('failed', null, error.message);
298
407
  return;
299
408
  }
300
409
  if (!call.completed) {
301
- const stopped = this.terminal.requested !== null;
410
+ const stopped = this.terminalRequested !== null;
302
411
  const publicError = errorMessage(error);
303
412
  await this.completeAgent(call, stopped ? 'stopped' : 'failed', null, stopped ? null : publicError, !stopped && isUnsupportedFeatureError(error, 'outputSchema')
304
413
  ? publicError
305
414
  : undefined).catch((persistenceError) => {
306
- this.terminal.observe('failed', null, errorMessage(persistenceError));
415
+ this.observeTerminal('failed', null, errorMessage(persistenceError));
307
416
  });
308
417
  }
309
418
  }
@@ -327,15 +436,10 @@ export class WorkflowRun {
327
436
  return;
328
437
  }
329
438
  call.turn = admission.turn;
330
- let outcome;
331
- try {
332
- outcome = await admission.turn.settled;
333
- }
334
- catch (error) {
335
- const persistenceError = errorMessage(error);
336
- await this.terminal.failAfterNotification(persistenceError, () => this.completeAgent(call, 'failed', null, persistenceError, persistenceError, true));
337
- return;
338
- }
439
+ // Never rejects: EntityTurn.settled folds every rejection into a
440
+ // `{status: 'failed', ...}` outcome (service/agent/turn.ts) before it
441
+ // resolves.
442
+ const outcome = await admission.turn.settled;
339
443
  if (outcome.status !== 'completed') {
340
444
  await this.completeAgent(call, outcome.status, null, outcome.status === 'failed' ? outcome.error.message : null);
341
445
  return;
@@ -363,7 +467,7 @@ export class WorkflowRun {
363
467
  }
364
468
  await this.completeAgent(call, error === null ? 'completed' : 'failed', result, error, runnerError);
365
469
  }
366
- async completeAgent(call, status, result, error, runnerError, deliverWhileTerminal = false) {
470
+ async completeAgent(call, status, result, error, runnerError) {
367
471
  if (call.completed)
368
472
  return;
369
473
  call.resultCandidate ??= {
@@ -372,7 +476,7 @@ export class WorkflowRun {
372
476
  status,
373
477
  result: status === 'completed' ? result : null,
374
478
  error,
375
- settled_at: call.record.settled_at ?? this.now(),
479
+ settled_at: call.record.settled_at ?? Date.now(),
376
480
  };
377
481
  const candidate = call.resultCandidate;
378
482
  call.record.status = candidate.status;
@@ -380,11 +484,8 @@ export class WorkflowRun {
380
484
  call.record.error = candidate.error;
381
485
  call.record.settled_at = candidate.settled_at;
382
486
  this.record.updated_at = candidate.settled_at;
383
- await this.mutate(async () => {
384
- if (!call.resultJournalCommitted) {
385
- await this.deps.journal.ensureAgentResult(candidate);
386
- call.resultJournalCommitted = true;
387
- }
487
+ await this.persist(async () => {
488
+ await this.journal.ensureAgentResult(candidate);
388
489
  await this.deps.store.write(this.record);
389
490
  });
390
491
  call.completed = true;
@@ -394,7 +495,7 @@ export class WorkflowRun {
394
495
  producer: call.record.name,
395
496
  status: candidate.status,
396
497
  }, 'workflow agent settled');
397
- if (this.terminal.suppressDelivery && !deliverWhileTerminal)
498
+ if (this.terminalSuppressDelivery)
398
499
  return;
399
500
  if (runnerError !== undefined) {
400
501
  await this.runner.send({
@@ -412,34 +513,44 @@ export class WorkflowRun {
412
513
  }
413
514
  }
414
515
  async sendAgentError(index, error) {
415
- if (this.terminal.suppressDelivery)
516
+ if (this.terminalSuppressDelivery)
416
517
  return;
417
518
  await this.runner.send({ type: 'agent_result', index, error });
418
519
  }
419
520
  async finalize(requestedStatus, result, requestedError) {
420
521
  const runnerStopResults = await Promise.allSettled([this.runner.stop()]);
522
+ // Admission-bookkeeping convergence, not a wait on an Agent's own turn:
523
+ // this waits only for createLocked() (registering the locked handle) to
524
+ // resolve, so the `handles` list read just below is complete before the
525
+ // close pass runs, not for a still-running turn to finish naturally.
421
526
  await this.materializations.drain();
422
- const handles = [...new Set([...this.calls.values()]
527
+ const handles = [
528
+ ...new Set([...this.calls.values()]
423
529
  .map((call) => call.handle)
424
- .filter((handle) => handle !== null))].filter((handle) => !this.unlockedHandles.has(handle));
530
+ .filter((handle) => handle !== null)),
531
+ ].filter((handle) => !this.unlockedHandles.has(handle));
425
532
  const closeResults = await Promise.allSettled(handles.map(async (handle) => handle.close({
426
533
  note: `Workflow ${this.record.run_id} ${requestedStatus}`,
427
534
  })));
428
535
  if (closeResults.some((close) => close.status === 'rejected')) {
429
536
  throwSettledFailures([...runnerStopResults, ...closeResults], `workflow ${JSON.stringify(this.record.run_id)} runner or TeamMates failed to stop`);
430
537
  }
538
+ // Each of these three waits for this run's own already-admitted write
539
+ // (a queued runner message, a completeAgent call, a store write) to land
540
+ // truthfully — never for an Agent's own turn to finish naturally, which
541
+ // a stop must never wait on.
431
542
  await this.runnerMessageTasks.drain();
432
543
  await this.agentTasks.drain();
433
- await this.mutationTail;
544
+ await this.deps.store.handle(this.record.run_id).drain();
434
545
  for (const call of this.calls.values()) {
435
546
  if (!call.completed) {
436
547
  await this.completeAgent(call, 'stopped', null, requestedError);
437
548
  }
438
549
  }
439
- await this.mutationTail;
550
+ await this.deps.store.handle(this.record.run_id).drain();
440
551
  throwSettledFailures(runnerStopResults, `workflow ${JSON.stringify(this.record.run_id)} runner failed to stop`);
441
552
  if (this.terminalCandidate === null) {
442
- const endedAt = this.now();
553
+ const endedAt = Date.now();
443
554
  this.terminalCandidate = {
444
555
  ...structuredClone(this.record),
445
556
  status: requestedStatus,
@@ -450,16 +561,13 @@ export class WorkflowRun {
450
561
  };
451
562
  }
452
563
  const candidate = this.terminalCandidate;
453
- if (!this.terminalJournalCommitted) {
454
- await this.deps.journal.ensureTerminal({
455
- kind: 'end',
456
- status: candidate.status,
457
- result: candidate.result,
458
- error: candidate.error,
459
- ended_at: candidate.ended_at,
460
- });
461
- this.terminalJournalCommitted = true;
462
- }
564
+ await this.journal.ensureTerminal({
565
+ kind: 'end',
566
+ status: candidate.status,
567
+ result: candidate.result,
568
+ error: candidate.error,
569
+ ended_at: candidate.ended_at,
570
+ });
463
571
  await this.deps.store.write(candidate);
464
572
  Object.assign(this.record, structuredClone(candidate));
465
573
  for (const handle of handles) {
@@ -468,9 +576,9 @@ export class WorkflowRun {
468
576
  handle.unlock();
469
577
  this.unlockedHandles.add(handle);
470
578
  }
471
- const deliverTerminal = this.deliverTerminal;
472
- if (deliverTerminal !== null) {
473
- await deliverTerminal({
579
+ const recipient = this.recipient;
580
+ if (recipient !== null) {
581
+ await this.deps.completionDelivery.deliver(recipient, {
474
582
  kind: 'workflow',
475
583
  source: 'workflow',
476
584
  runId: this.record.run_id,
@@ -485,29 +593,34 @@ export class WorkflowRun {
485
593
  .map((agent) => ({ index: agent.index, name: agent.name })),
486
594
  }, null, 2),
487
595
  });
488
- this.deliverTerminal = null;
489
- }
490
- if (!this.terminalLogged) {
491
- this.terminalLogged = true;
492
- this.deps.log.info({
493
- run_id: this.record.run_id,
494
- status: candidate.status,
495
- agent_count: candidate.agents.length,
496
- err: candidate.error === null
497
- ? undefined
498
- : { message: candidate.error },
499
- }, 'workflow run terminal');
596
+ this.recipient = null;
500
597
  }
598
+ this.deps.log.info({
599
+ run_id: this.record.run_id,
600
+ status: candidate.status,
601
+ agent_count: candidate.agents.length,
602
+ err: candidate.error === null ? undefined : { message: candidate.error },
603
+ }, 'workflow run terminal');
501
604
  }
502
- mutate(task) {
503
- const next = this.mutationTail.then(task, task);
504
- this.mutationTail = next.then(() => undefined, () => undefined);
505
- return next.catch((error) => {
605
+ /**
606
+ * Run a durable write (journal append and/or `store.write`) and reclassify
607
+ * any failure as a {@link WorkflowPersistenceError}. Ordering between two
608
+ * durable writes from this same `WorkflowRun` instance comes from awaiting
609
+ * them in sequence, not from a queue here: each per-run `TransactionalStore`
610
+ * already serializes concurrent writers on its own file.
611
+ * Result- and terminal-bearing writes await their matching journal fact
612
+ * before the corresponding store write is enqueued.
613
+ * `executeAgent`'s catch depends on this classification to tell "this run's
614
+ * own storage failed" (a terminal failure) apart from "this Agent's runtime
615
+ * work failed" (an ordinary agent failure another write can still record).
616
+ */
617
+ async persist(work) {
618
+ try {
619
+ return await work();
620
+ }
621
+ catch (error) {
506
622
  throw new WorkflowPersistenceError(errorMessage(error));
507
- });
508
- }
509
- now() {
510
- return this.deps.now?.() ?? Date.now();
623
+ }
511
624
  }
512
625
  }
513
626
  //# sourceMappingURL=run.js.map