@mastra/factory 0.29.0-alpha.4 → 0.29.0-alpha.6

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 (401) hide show
  1. package/README.md +172 -89
  2. package/dist/boards/board-events.d.ts +89 -9
  3. package/dist/boards/board-events.d.ts.map +1 -1
  4. package/dist/boards/board-events.js +176 -13
  5. package/dist/boards/board-events.js.map +1 -1
  6. package/dist/boards/board-writes.d.ts.map +1 -1
  7. package/dist/boards/board-writes.js +14 -1
  8. package/dist/boards/board-writes.js.map +1 -1
  9. package/dist/boards/busy-card.d.ts +11 -0
  10. package/dist/boards/busy-card.d.ts.map +1 -0
  11. package/dist/boards/busy-card.js +15 -0
  12. package/dist/boards/busy-card.js.map +1 -0
  13. package/dist/boards/card-facts.d.ts.map +1 -1
  14. package/dist/boards/card-facts.js +18 -4
  15. package/dist/boards/card-facts.js.map +1 -1
  16. package/dist/boards/index.d.ts +2 -1
  17. package/dist/boards/index.d.ts.map +1 -1
  18. package/dist/boards/index.js +3 -2
  19. package/dist/boards/intake-dry-run.d.ts +109 -0
  20. package/dist/boards/intake-dry-run.d.ts.map +1 -0
  21. package/dist/boards/intake-dry-run.js +158 -0
  22. package/dist/boards/intake-dry-run.js.map +1 -0
  23. package/dist/boards/intake-lookup.d.ts +32 -0
  24. package/dist/boards/intake-lookup.d.ts.map +1 -0
  25. package/dist/boards/intake-lookup.js +12 -0
  26. package/dist/boards/intake-lookup.js.map +1 -0
  27. package/dist/boards/intake-order.d.ts +32 -0
  28. package/dist/boards/intake-order.d.ts.map +1 -0
  29. package/dist/boards/intake-order.js +60 -0
  30. package/dist/boards/intake-order.js.map +1 -0
  31. package/dist/boards/intake-routing.d.ts +246 -35
  32. package/dist/boards/intake-routing.d.ts.map +1 -1
  33. package/dist/boards/intake-routing.js +437 -52
  34. package/dist/boards/intake-routing.js.map +1 -1
  35. package/dist/boards/reroute.d.ts +7 -3
  36. package/dist/boards/reroute.d.ts.map +1 -1
  37. package/dist/boards/reroute.js +21 -4
  38. package/dist/boards/reroute.js.map +1 -1
  39. package/dist/boards/semantics.d.ts +8 -28
  40. package/dist/boards/semantics.d.ts.map +1 -1
  41. package/dist/boards/semantics.js +14 -40
  42. package/dist/boards/semantics.js.map +1 -1
  43. package/dist/boards/work-routes.d.ts +31 -11
  44. package/dist/boards/work-routes.d.ts.map +1 -1
  45. package/dist/boards/work-routes.js +104 -20
  46. package/dist/boards/work-routes.js.map +1 -1
  47. package/dist/factory.d.ts +37 -1
  48. package/dist/factory.d.ts.map +1 -1
  49. package/dist/factory.js +127 -48
  50. package/dist/factory.js.map +1 -1
  51. package/dist/integrations/base.d.ts +9 -0
  52. package/dist/integrations/base.d.ts.map +1 -1
  53. package/dist/integrations/dependabot/rules.js +1 -1
  54. package/dist/integrations/dependabot/rules.js.map +1 -1
  55. package/dist/integrations/github/default-rules.d.ts +22 -1
  56. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  57. package/dist/integrations/github/default-rules.js +23 -5
  58. package/dist/integrations/github/default-rules.js.map +1 -1
  59. package/dist/integrations/github/intake-lookup.d.ts +16 -0
  60. package/dist/integrations/github/intake-lookup.d.ts.map +1 -0
  61. package/dist/integrations/github/intake-lookup.js +76 -0
  62. package/dist/integrations/github/intake-lookup.js.map +1 -0
  63. package/dist/integrations/github/integration.d.ts +19 -5
  64. package/dist/integrations/github/integration.d.ts.map +1 -1
  65. package/dist/integrations/github/integration.js +21 -6
  66. package/dist/integrations/github/integration.js.map +1 -1
  67. package/dist/integrations/github/issue-intake.d.ts +15 -0
  68. package/dist/integrations/github/issue-intake.d.ts.map +1 -0
  69. package/dist/integrations/github/issue-intake.js +50 -0
  70. package/dist/integrations/github/issue-intake.js.map +1 -0
  71. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
  72. package/dist/integrations/github/issue-reconciler.js +10 -1
  73. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  74. package/dist/integrations/github/review-status-reporter.js +1 -1
  75. package/dist/integrations/github/routes.d.ts.map +1 -1
  76. package/dist/integrations/github/routes.js +14 -2
  77. package/dist/integrations/github/routes.js.map +1 -1
  78. package/dist/integrations/github/rules.d.ts +14 -1
  79. package/dist/integrations/github/rules.d.ts.map +1 -1
  80. package/dist/integrations/github/rules.js +221 -30
  81. package/dist/integrations/github/rules.js.map +1 -1
  82. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  83. package/dist/integrations/github/sandbox.js +30 -4
  84. package/dist/integrations/github/sandbox.js.map +1 -1
  85. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  86. package/dist/integrations/gitlab/default-rules.js +19 -3
  87. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  88. package/dist/integrations/gitlab/intake-lookup.d.ts +17 -0
  89. package/dist/integrations/gitlab/intake-lookup.d.ts.map +1 -0
  90. package/dist/integrations/gitlab/intake-lookup.js +85 -0
  91. package/dist/integrations/gitlab/intake-lookup.js.map +1 -0
  92. package/dist/integrations/gitlab/integration.d.ts +5 -0
  93. package/dist/integrations/gitlab/integration.d.ts.map +1 -1
  94. package/dist/integrations/gitlab/integration.js +21 -1
  95. package/dist/integrations/gitlab/integration.js.map +1 -1
  96. package/dist/integrations/gitlab/rules.d.ts +20 -0
  97. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  98. package/dist/integrations/gitlab/rules.js +108 -12
  99. package/dist/integrations/gitlab/rules.js.map +1 -1
  100. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  101. package/dist/integrations/incidentio/rules.js +14 -4
  102. package/dist/integrations/incidentio/rules.js.map +1 -1
  103. package/dist/integrations/jira/rules.d.ts.map +1 -1
  104. package/dist/integrations/jira/rules.js +12 -2
  105. package/dist/integrations/jira/rules.js.map +1 -1
  106. package/dist/integrations/linear/rules.d.ts.map +1 -1
  107. package/dist/integrations/linear/rules.js +13 -2
  108. package/dist/integrations/linear/rules.js.map +1 -1
  109. package/dist/integrations/platform/connect/routes.d.ts +43 -1
  110. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  111. package/dist/integrations/platform/connect/routes.js +82 -7
  112. package/dist/integrations/platform/connect/routes.js.map +1 -1
  113. package/dist/integrations/platform/connect/session-tools.d.ts +12 -0
  114. package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -1
  115. package/dist/integrations/platform/connect/session-tools.js +28 -10
  116. package/dist/integrations/platform/connect/session-tools.js.map +1 -1
  117. package/dist/integrations/platform/github/event-worker.js +9 -1
  118. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  119. package/dist/integrations/platform/github/integration.d.ts +6 -6
  120. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  121. package/dist/integrations/platform/github/integration.js +22 -3
  122. package/dist/integrations/platform/github/integration.js.map +1 -1
  123. package/dist/integrations/platform/vanta/integration.d.ts.map +1 -1
  124. package/dist/integrations/platform/vanta/integration.js +3 -3
  125. package/dist/integrations/platform/vanta/integration.js.map +1 -1
  126. package/dist/integrations/pull-request-head.d.ts +1 -1
  127. package/dist/integrations/pull-request-head.d.ts.map +1 -1
  128. package/dist/integrations/pull-request-head.js +5 -0
  129. package/dist/integrations/pull-request-head.js.map +1 -1
  130. package/dist/integrations/vanta/rules.js +1 -1
  131. package/dist/integrations/vanta/rules.js.map +1 -1
  132. package/dist/integrations/vanta/sync.d.ts +9 -0
  133. package/dist/integrations/vanta/sync.d.ts.map +1 -1
  134. package/dist/integrations/vanta/sync.js +10 -1
  135. package/dist/integrations/vanta/sync.js.map +1 -1
  136. package/dist/routes/board-snapshot.d.ts +13 -6
  137. package/dist/routes/board-snapshot.d.ts.map +1 -1
  138. package/dist/routes/board-snapshot.js +42 -20
  139. package/dist/routes/board-snapshot.js.map +1 -1
  140. package/dist/routes/boards.js.map +1 -1
  141. package/dist/routes/config.d.ts +17 -2
  142. package/dist/routes/config.d.ts.map +1 -1
  143. package/dist/routes/config.js +247 -77
  144. package/dist/routes/config.js.map +1 -1
  145. package/dist/routes/contracts.d.ts +1294 -7
  146. package/dist/routes/contracts.d.ts.map +1 -1
  147. package/dist/routes/contracts.js +603 -20
  148. package/dist/routes/contracts.js.map +1 -1
  149. package/dist/routes/custom-endpoint-url.d.ts +8 -0
  150. package/dist/routes/custom-endpoint-url.d.ts.map +1 -0
  151. package/dist/routes/custom-endpoint-url.js +45 -0
  152. package/dist/routes/custom-endpoint-url.js.map +1 -0
  153. package/dist/routes/custom-provider-source.d.ts +24 -8
  154. package/dist/routes/custom-provider-source.d.ts.map +1 -1
  155. package/dist/routes/custom-provider-source.js +93 -43
  156. package/dist/routes/custom-provider-source.js.map +1 -1
  157. package/dist/routes/intake-check.d.ts +92 -0
  158. package/dist/routes/intake-check.d.ts.map +1 -0
  159. package/dist/routes/intake-check.js +322 -0
  160. package/dist/routes/intake-check.js.map +1 -0
  161. package/dist/routes/intake-routes.d.ts +10 -2
  162. package/dist/routes/intake-routes.d.ts.map +1 -1
  163. package/dist/routes/intake-routes.js +292 -11
  164. package/dist/routes/intake-routes.js.map +1 -1
  165. package/dist/routes/intake.d.ts +6 -0
  166. package/dist/routes/intake.d.ts.map +1 -1
  167. package/dist/routes/intake.js +20 -0
  168. package/dist/routes/intake.js.map +1 -1
  169. package/dist/routes/mastra-gateway.d.ts.map +1 -1
  170. package/dist/routes/mastra-gateway.js +3 -2
  171. package/dist/routes/mastra-gateway.js.map +1 -1
  172. package/dist/routes/project-sessions.d.ts +61 -0
  173. package/dist/routes/project-sessions.d.ts.map +1 -0
  174. package/dist/routes/project-sessions.js +135 -0
  175. package/dist/routes/project-sessions.js.map +1 -0
  176. package/dist/routes/projects.d.ts +6 -1
  177. package/dist/routes/projects.d.ts.map +1 -1
  178. package/dist/routes/projects.js +19 -3
  179. package/dist/routes/projects.js.map +1 -1
  180. package/dist/routes/provider-credentials.d.ts +10 -1
  181. package/dist/routes/provider-credentials.d.ts.map +1 -1
  182. package/dist/routes/provider-credentials.js +13 -16
  183. package/dist/routes/provider-credentials.js.map +1 -1
  184. package/dist/routes/run-queue.d.ts +6 -6
  185. package/dist/routes/run-queue.d.ts.map +1 -1
  186. package/dist/routes/run-queue.js +28 -8
  187. package/dist/routes/run-queue.js.map +1 -1
  188. package/dist/routes/session-rows.d.ts +30 -0
  189. package/dist/routes/session-rows.d.ts.map +1 -0
  190. package/dist/routes/session-rows.js +94 -0
  191. package/dist/routes/session-rows.js.map +1 -0
  192. package/dist/routes/source-control-sessions.d.ts +4 -5
  193. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  194. package/dist/routes/source-control-sessions.js +8 -87
  195. package/dist/routes/source-control-sessions.js.map +1 -1
  196. package/dist/routes/surface.d.ts +16 -1
  197. package/dist/routes/surface.d.ts.map +1 -1
  198. package/dist/routes/surface.js +41 -30
  199. package/dist/routes/surface.js.map +1 -1
  200. package/dist/routes/tenant-credentials.d.ts.map +1 -1
  201. package/dist/routes/tenant-credentials.js +4 -4
  202. package/dist/routes/tenant-credentials.js.map +1 -1
  203. package/dist/routes/work-item-starters.d.ts +1 -0
  204. package/dist/routes/work-item-starters.d.ts.map +1 -1
  205. package/dist/routes/work-item-starters.js +14 -2
  206. package/dist/routes/work-item-starters.js.map +1 -1
  207. package/dist/routes/work-items.d.ts +22 -3
  208. package/dist/routes/work-items.d.ts.map +1 -1
  209. package/dist/routes/work-items.js +124 -48
  210. package/dist/routes/work-items.js.map +1 -1
  211. package/dist/rules/binding-context.d.ts +5 -0
  212. package/dist/rules/binding-context.d.ts.map +1 -1
  213. package/dist/rules/binding-context.js +51 -5
  214. package/dist/rules/binding-context.js.map +1 -1
  215. package/dist/rules/dispatch-errors.js +1 -1
  216. package/dist/rules/dispatch-errors.js.map +1 -1
  217. package/dist/rules/dispatcher.d.ts +39 -7
  218. package/dist/rules/dispatcher.d.ts.map +1 -1
  219. package/dist/rules/dispatcher.js +363 -123
  220. package/dist/rules/dispatcher.js.map +1 -1
  221. package/dist/rules/event-rules.d.ts +69 -1
  222. package/dist/rules/event-rules.d.ts.map +1 -1
  223. package/dist/rules/event-rules.js +151 -5
  224. package/dist/rules/event-rules.js.map +1 -1
  225. package/dist/rules/review-source-tool.js +1 -1
  226. package/dist/rules/rule-group.d.ts +18 -1
  227. package/dist/rules/rule-group.d.ts.map +1 -1
  228. package/dist/rules/rule-group.js +52 -8
  229. package/dist/rules/rule-group.js.map +1 -1
  230. package/dist/rules/run-bearing.d.ts +8 -0
  231. package/dist/rules/run-bearing.d.ts.map +1 -0
  232. package/dist/rules/run-bearing.js +11 -0
  233. package/dist/rules/run-bearing.js.map +1 -0
  234. package/dist/rules/start-coordinator.d.ts +2 -3
  235. package/dist/rules/start-coordinator.d.ts.map +1 -1
  236. package/dist/rules/start-coordinator.js +25 -38
  237. package/dist/rules/start-coordinator.js.map +1 -1
  238. package/dist/rules/tools.js +2 -1
  239. package/dist/rules/tools.js.map +1 -1
  240. package/dist/rules/transition-service.d.ts +16 -0
  241. package/dist/rules/transition-service.d.ts.map +1 -1
  242. package/dist/rules/transition-service.js +34 -10
  243. package/dist/rules/transition-service.js.map +1 -1
  244. package/dist/rules/types.d.ts +18 -5
  245. package/dist/rules/types.d.ts.map +1 -1
  246. package/dist/rules/types.js +2 -1
  247. package/dist/rules/types.js.map +1 -1
  248. package/dist/rules/update-fold.d.ts +32 -0
  249. package/dist/rules/update-fold.d.ts.map +1 -0
  250. package/dist/rules/update-fold.js +60 -0
  251. package/dist/rules/update-fold.js.map +1 -0
  252. package/dist/rules/validation.d.ts.map +1 -1
  253. package/dist/rules/validation.js +54 -6
  254. package/dist/rules/validation.js.map +1 -1
  255. package/dist/sandbox/session-retirement.d.ts +6 -0
  256. package/dist/sandbox/session-retirement.d.ts.map +1 -1
  257. package/dist/sandbox/session-retirement.js +17 -0
  258. package/dist/sandbox/session-retirement.js.map +1 -1
  259. package/dist/session/factory-session.d.ts.map +1 -1
  260. package/dist/session/factory-session.js +2 -1
  261. package/dist/session/factory-session.js.map +1 -1
  262. package/dist/session/live-sessions.d.ts +6 -1
  263. package/dist/session/live-sessions.d.ts.map +1 -1
  264. package/dist/session/live-sessions.js +4 -0
  265. package/dist/session/live-sessions.js.map +1 -1
  266. package/dist/session/resource-migration.d.ts.map +1 -1
  267. package/dist/session/resource-migration.js +2 -3
  268. package/dist/session/resource-migration.js.map +1 -1
  269. package/dist/session/run-audit.d.ts +10 -1
  270. package/dist/session/run-audit.d.ts.map +1 -1
  271. package/dist/session/run-audit.js +9 -1
  272. package/dist/session/run-audit.js.map +1 -1
  273. package/dist/session/self-review-gate.d.ts +26 -2
  274. package/dist/session/self-review-gate.d.ts.map +1 -1
  275. package/dist/session/self-review-gate.js +60 -10
  276. package/dist/session/self-review-gate.js.map +1 -1
  277. package/dist/session/session-row-query.d.ts +25 -0
  278. package/dist/session/session-row-query.d.ts.map +1 -0
  279. package/dist/session/session-row-query.js +47 -0
  280. package/dist/session/session-row-query.js.map +1 -0
  281. package/dist/session/session-row-status.d.ts +16 -0
  282. package/dist/session/session-row-status.d.ts.map +1 -0
  283. package/dist/session/session-row-status.js +14 -0
  284. package/dist/session/session-row-status.js.map +1 -0
  285. package/dist/session/session-row-view.d.ts +13 -0
  286. package/dist/session/session-row-view.d.ts.map +1 -0
  287. package/dist/session/session-row-view.js +118 -0
  288. package/dist/session/session-row-view.js.map +1 -0
  289. package/dist/session/session-rows.d.ts +60 -0
  290. package/dist/session/session-rows.d.ts.map +1 -0
  291. package/dist/session/session-rows.js +307 -0
  292. package/dist/session/session-rows.js.map +1 -0
  293. package/dist/session/session-threads.d.ts.map +1 -1
  294. package/dist/session/session-threads.js +1 -0
  295. package/dist/session/session-threads.js.map +1 -1
  296. package/dist/session/session-unloader.d.ts +101 -0
  297. package/dist/session/session-unloader.d.ts.map +1 -0
  298. package/dist/session/session-unloader.js +278 -0
  299. package/dist/session/session-unloader.js.map +1 -0
  300. package/dist/session/source-control-tools.d.ts +14 -7
  301. package/dist/session/source-control-tools.d.ts.map +1 -1
  302. package/dist/session/source-control-tools.js +10 -2
  303. package/dist/session/source-control-tools.js.map +1 -1
  304. package/dist/session/work-item-repository.d.ts +49 -1
  305. package/dist/session/work-item-repository.d.ts.map +1 -1
  306. package/dist/session/work-item-repository.js +118 -15
  307. package/dist/session/work-item-repository.js.map +1 -1
  308. package/dist/session/work-item-state-processor.d.ts.map +1 -1
  309. package/dist/session/work-item-state-processor.js +44 -8
  310. package/dist/session/work-item-state-processor.js.map +1 -1
  311. package/dist/session-list-changes.d.ts +9 -0
  312. package/dist/session-list-changes.d.ts.map +1 -0
  313. package/dist/session-list-changes.js +54 -0
  314. package/dist/session-list-changes.js.map +1 -0
  315. package/dist/storage/announced-lists.d.ts +14 -0
  316. package/dist/storage/announced-lists.d.ts.map +1 -0
  317. package/dist/storage/announced-lists.js +78 -0
  318. package/dist/storage/announced-lists.js.map +1 -0
  319. package/dist/storage/domains/audit/actions.d.ts +2 -1
  320. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  321. package/dist/storage/domains/audit/actions.js +3 -1
  322. package/dist/storage/domains/audit/actions.js.map +1 -1
  323. package/dist/storage/domains/boards/base.d.ts +163 -15
  324. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  325. package/dist/storage/domains/boards/base.js +440 -48
  326. package/dist/storage/domains/boards/base.js.map +1 -1
  327. package/dist/storage/domains/boards/schemas.d.ts +6 -0
  328. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  329. package/dist/storage/domains/boards/schemas.js +95 -1
  330. package/dist/storage/domains/boards/schemas.js.map +1 -1
  331. package/dist/storage/domains/custom-providers/base.d.ts +62 -19
  332. package/dist/storage/domains/custom-providers/base.d.ts.map +1 -1
  333. package/dist/storage/domains/custom-providers/base.js +131 -100
  334. package/dist/storage/domains/custom-providers/base.js.map +1 -1
  335. package/dist/storage/domains/intake/base.d.ts +25 -7
  336. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  337. package/dist/storage/domains/intake/base.js +83 -19
  338. package/dist/storage/domains/intake/base.js.map +1 -1
  339. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  340. package/dist/storage/domains/projects/base.js +19 -10
  341. package/dist/storage/domains/projects/base.js.map +1 -1
  342. package/dist/storage/domains/source-control/base.d.ts +8 -0
  343. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  344. package/dist/storage/domains/source-control/base.js +110 -61
  345. package/dist/storage/domains/source-control/base.js.map +1 -1
  346. package/dist/storage/domains/source-control/inmemory.d.ts +4 -0
  347. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  348. package/dist/storage/domains/source-control/inmemory.js +8 -5
  349. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  350. package/dist/storage/domains/work-items/base.d.ts +57 -18
  351. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  352. package/dist/storage/domains/work-items/base.js +168 -83
  353. package/dist/storage/domains/work-items/base.js.map +1 -1
  354. package/dist/storage/domains/work-items/cards.d.ts +3 -2
  355. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  356. package/dist/storage/domains/work-items/cards.js +4 -2
  357. package/dist/storage/domains/work-items/cards.js.map +1 -1
  358. package/dist/tools/audit-events-tool.d.ts +2 -2
  359. package/dist/tools/read-tools.d.ts +9 -5
  360. package/dist/tools/read-tools.d.ts.map +1 -1
  361. package/dist/tools/read-tools.js +61 -54
  362. package/dist/tools/read-tools.js.map +1 -1
  363. package/dist/tools/session-tools.d.ts +0 -13
  364. package/dist/tools/session-tools.d.ts.map +1 -1
  365. package/dist/tools/session-tools.js +128 -341
  366. package/dist/tools/session-tools.js.map +1 -1
  367. package/dist/tools/work-item-tools.d.ts +3 -0
  368. package/dist/tools/work-item-tools.d.ts.map +1 -1
  369. package/dist/tools/work-item-tools.js +99 -27
  370. package/dist/tools/work-item-tools.js.map +1 -1
  371. package/dist/work-item-branch.d.ts +4 -0
  372. package/dist/work-item-branch.d.ts.map +1 -1
  373. package/dist/work-item-branch.js +7 -1
  374. package/dist/work-item-branch.js.map +1 -1
  375. package/dist/work-items/card-context-sessions.d.ts +50 -0
  376. package/dist/work-items/card-context-sessions.d.ts.map +1 -0
  377. package/dist/work-items/card-context-sessions.js +84 -0
  378. package/dist/work-items/card-context-sessions.js.map +1 -0
  379. package/dist/work-items/card-reference.d.ts +21 -0
  380. package/dist/work-items/card-reference.d.ts.map +1 -0
  381. package/dist/work-items/card-reference.js +58 -0
  382. package/dist/work-items/card-reference.js.map +1 -0
  383. package/dist/work-items/change-requests.d.ts +87 -0
  384. package/dist/work-items/change-requests.d.ts.map +1 -0
  385. package/dist/work-items/change-requests.js +134 -0
  386. package/dist/work-items/change-requests.js.map +1 -0
  387. package/dist/work-items/create-work-item.d.ts +7 -2
  388. package/dist/work-items/create-work-item.d.ts.map +1 -1
  389. package/dist/work-items/create-work-item.js +44 -13
  390. package/dist/work-items/create-work-item.js.map +1 -1
  391. package/dist/work-items/list-related-cards.d.ts.map +1 -1
  392. package/dist/work-items/list-related-cards.js +1 -1
  393. package/dist/work-items/list-related-cards.js.map +1 -1
  394. package/dist/work-items/providers/github.d.ts.map +1 -1
  395. package/dist/work-items/providers/github.js +1 -0
  396. package/dist/work-items/providers/github.js.map +1 -1
  397. package/factory-skills/factory-build/SKILL.md +1 -1
  398. package/factory-skills/factory-plan/SKILL.md +5 -3
  399. package/factory-skills/factory-self-review/SKILL.md +2 -0
  400. package/factory-skills/factory-triage/SKILL.md +1 -1
  401. package/package.json +10 -10
@@ -1,13 +1,14 @@
1
- import { eventMovesCard, isPullRequestEvent } from "../boards/board-events.js";
1
+ import { isUpdateEvent } from "../boards/board-events.js";
2
2
  import "../boards/index.js";
3
- import { INTAKE_ROUTE_METADATA_KEY, closedIssueRuleFacts, landingPhase, placedByIntakeRoute, resolveEventRoute, resolveIntakePlacement, resolveIntakeRoute, routesHandleEvent } from "../boards/intake-routing.js";
3
+ import { INTAKE_ROUTE_METADATA_KEY, arrivalRuleFacts, landingPhase, placedByIntakeRoute, planEventMove, projectIntakeEvaluator, resolveIntake } from "../boards/intake-routing.js";
4
4
  import "../boards/define-board.js";
5
- import { boardFlow, boardForWorkItem, cardBoardFlow, hasPullRequest, intakeTarget, isPullRequestCard, isTerminalWorkItem, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
5
+ import { UNTRUSTED_PULL_REQUESTS_KEY, isOpenPullRequestSource, isPullRequestCard, pullRequestSources, pullRequestTrustKey, trustedPullRequestSource } from "../work-items/change-requests.js";
6
+ import { boardFlow, boardForWorkItem, cardBoardFlow, isTerminalWorkItem, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
6
7
  import { autoApprovedExitTool, startsInAutoPhase } from "../boards/phase-automation.js";
7
8
  import { toBoardSource } from "../boards/project-boards.js";
8
9
  import { moveCardToBoard } from "../boards/relocate.js";
9
- import { FACTORY_OPEN_RUN_STALE_MS, heartbeatSessionOpenRun, isOpenRunLiveElsewhere, listSessionOpenRuns, recordSessionRunStart, waitForSessionRunAudit } from "../session/run-audit.js";
10
- import { cardRuleFacts } from "../boards/card-facts.js";
10
+ import { FACTORY_OPEN_RUN_STALE_MS, heartbeatSessionOpenRun, isOpenRunLiveElsewhere, listSessionOpenRuns, listThreadOpenRuns, recordSessionRunStart, waitForSessionRunAudit } from "../session/run-audit.js";
11
+ import { sessionHoldsWork } from "../session/session-unloader.js";
11
12
  import { resolvePromptInvocation, resolveSkillInvocation, resolveSkillResumeInvocation } from "../skills/service.js";
12
13
  import { isHumanActorId } from "../storage/domains/audit/actors.js";
13
14
  import { FACTORY_RULE_MATERIALIZATION_KEY, FactoryRunBindingSupersededError, WorkItemSourceConflictError, WorkItemUpdateConflictError, externalSourceKey } from "../storage/domains/work-items/base.js";
@@ -17,7 +18,9 @@ import { decisionOvertaken } from "./decision-applicability.js";
17
18
  import { FactoryDispatchError, factoryDispatchFailureCode, factoryDispatchFailureMetadata } from "./dispatch-errors.js";
18
19
  import { isStatusEventDecision } from "./event-rules.js";
19
20
  import { PHASE_GOAL_METADATA_KEY, endPhaseGoal, phaseGoalOf, startPhaseGoal } from "./phase-goal.js";
21
+ import { isRunBearingDecision } from "./run-bearing.js";
20
22
  import { authorTrusted, externalSourceForWorkItem, workItemSource } from "./types.js";
23
+ import { eventRouteIngress, foldUpdate, updateGroup } from "./update-fold.js";
21
24
  import { assertFactoryDecisionTarget, validateFactoryRuleDecision } from "./validation.js";
22
25
  import { RequestContext } from "@mastra/core/request-context";
23
26
  import { PROVIDER_CALL_ERROR_NAME, classifyProviderError } from "@mastra/core/error";
@@ -35,14 +38,17 @@ const MAX_BACKOFF_MS = 6e4;
35
38
  const RUN_REGISTRY_HEARTBEAT_MS = 6e5;
36
39
  const SKILL_COMPLETION_OBSERVATION_TIMEOUT_MS = 216e5;
37
40
  const MAX_IN_FLIGHT = 10;
41
+ const isBookkeepingDecision = (decision) => !isRunBearingDecision(decision);
38
42
  /**
39
- * Decisions that may start or wake an agent run, or wait for one to end, and so
40
- * hold a run slot. A transition's message is queued as a separate sendMessage,
41
- * so a transition stays bookkeeping, and so does a status event's route move:
42
- * it never waits for a run inline, it hands itself back until the run ends.
43
+ * A wake a person is waiting on: a reply a person sent on the card's pull
44
+ * request or issue, which GitHub typed as a `User` (not an app or bot) with
45
+ * write access, that Factory did not write itself, and that came straight from
46
+ * the webhook rather than from a move or decision it caused. Everything else,
47
+ * including actors with no record of being a person, stays automated.
43
48
  */
44
- const isRunBearingDecision = (decision) => decision.type === "invokeSkill" || decision.type === "sendMessage" || decision.type === "signalActivity";
45
- const isBookkeepingDecision = (decision) => !isRunBearingDecision(decision);
49
+ const isInteractiveDecision = (decision, { actor, causalChain }) => (decision.type === "sendMessage" || decision.type === "signalActivity") && decision.idleBehavior !== "persist" && causalChain.length === 0 && actor?.type === "github" && actor.human === true && actor.trusted === true && actor.factoryAuthored === false;
50
+ const isAutomatedRunDecision = (decision, provenance) => isRunBearingDecision(decision) && !isInteractiveDecision(decision, provenance);
51
+ const MAX_INTERACTIVE_IN_FLIGHT = 2;
46
52
  const BOOKKEEPING_MAX_IN_FLIGHT = 4;
47
53
  const STALE_BINDING_SWEEP_INTERVAL_MS = 6e5;
48
54
  const STALE_BINDING_TTL_MS = 864e5;
@@ -50,7 +56,18 @@ const RECONCILE_INTERVAL_MS = 3e4;
50
56
  /** The card moved on before this run could act; it settles as superseded, not succeeded. */
51
57
  var FactoryDecisionSuperseded = class extends Error {};
52
58
  /** The decision cannot act yet and did nothing: it goes back to the queue and is claimed again later. */
53
- var FactoryDecisionPostponed = class extends Error {};
59
+ var FactoryDecisionPostponed = class extends Error {
60
+ availableAt;
61
+ constructor(availableAt) {
62
+ super();
63
+ this.availableAt = availableAt;
64
+ }
65
+ };
66
+ /**
67
+ * How long an update waits for more updates to the same card before its routes run: a burst of
68
+ * label or assignee changes within this window becomes one event.
69
+ */
70
+ const UPDATE_BURST_MS = 5e3;
54
71
  const POSTPONE_MS = 1e4;
55
72
  /** A run that ran and ended in error; the session's own listener reports it to followers. */
56
73
  var RunEndedInError = class extends FactoryDispatchError {};
@@ -328,12 +345,31 @@ async function awaitNotification(send, requireDelivery = false) {
328
345
  throw new FactoryDispatchError("notification_delivery_failed", `Factory notification delivery failed: ${sanitizeDispatchError(error)}`, { cause: error });
329
346
  }
330
347
  }
348
+ /** Card metadata key: the facts each linked pull request joined the card with, by its trust key. */
349
+ const LINKED_PULL_REQUESTS_KEY = "linkedPullRequests";
350
+ function linkedPullRequests(metadata) {
351
+ const links = metadata?.[LINKED_PULL_REQUESTS_KEY];
352
+ return links && typeof links === "object" && !Array.isArray(links) ? links : {};
353
+ }
354
+ /**
355
+ * A pull request's link to `card`, read off the card it joins. Only another trusted, open pull
356
+ * request counts as one the card already has: an outsider's can't keep a maintainer's from Review.
357
+ */
358
+ function linkFacts(card, trusted, trustKey) {
359
+ return {
360
+ trusted,
361
+ phase: card.stages.length === 1 ? card.stages[0] : null,
362
+ hasPullRequest: pullRequestSources(card).some((source) => pullRequestTrustKey(source) !== trustKey && isOpenPullRequestSource(source) && trustedPullRequestSource(card, source))
363
+ };
364
+ }
331
365
  var FactoryDecisionDispatcher = class {
332
366
  #audit;
333
367
  #controller;
334
368
  #transitionService;
335
369
  #boards;
336
370
  #intakeRoutes;
371
+ /** Forced on every project; undefined: each project's own setting. */
372
+ #intakeEvaluator;
337
373
  #storage;
338
374
  #ownerId;
339
375
  #autoApproving = /* @__PURE__ */ new Set();
@@ -359,6 +395,7 @@ var FactoryDecisionDispatcher = class {
359
395
  #resolveLinkedWorkItemParentId;
360
396
  #factoryProjectExists;
361
397
  #maxInFlight;
398
+ #maxInteractiveInFlight;
362
399
  #staleBindingSweepIntervalMs;
363
400
  #staleBindingTtlMs;
364
401
  #lastStaleBindingSweepAt;
@@ -378,6 +415,8 @@ var FactoryDecisionDispatcher = class {
378
415
  #timer;
379
416
  /** Starts and run-bearing decisions; capped by `maxInFlight`. */
380
417
  #runInFlight = /* @__PURE__ */ new Set();
418
+ /** Wakes a person is waiting on; capped by `maxInteractiveInFlight`, borrowing free run slots past it. */
419
+ #interactiveInFlight = /* @__PURE__ */ new Set();
381
420
  /** Fast board bookkeeping (transitions, linked-card upserts); its own small cap. */
382
421
  #bookkeepingInFlight = /* @__PURE__ */ new Set();
383
422
  /** Background work awaited on stop but outside both caps. */
@@ -389,6 +428,7 @@ var FactoryDecisionDispatcher = class {
389
428
  this.#transitionService = options.transitionService;
390
429
  this.#boards = toBoardSource(options.boards);
391
430
  this.#intakeRoutes = options.intakeRoutes;
431
+ this.#intakeEvaluator = options.intakeEvaluator;
392
432
  this.#storage = options.storage;
393
433
  this.#ownerId = options.ownerId ?? `factory-dispatcher:${globalThis.crypto.randomUUID()}`;
394
434
  this.#reconcileToolResults = options.reconcileToolResults;
@@ -402,6 +442,8 @@ var FactoryDecisionDispatcher = class {
402
442
  this.#factoryProjectExists = options.factoryProjectExists;
403
443
  const maxInFlight = options.maxInFlight ?? MAX_IN_FLIGHT;
404
444
  this.#maxInFlight = Number.isFinite(maxInFlight) && maxInFlight > 0 ? Math.floor(maxInFlight) : MAX_IN_FLIGHT;
445
+ const maxInteractiveInFlight = options.maxInteractiveInFlight ?? MAX_INTERACTIVE_IN_FLIGHT;
446
+ this.#maxInteractiveInFlight = Number.isFinite(maxInteractiveInFlight) && maxInteractiveInFlight >= 0 ? Math.floor(maxInteractiveInFlight) : MAX_INTERACTIVE_IN_FLIGHT;
405
447
  this.#staleBindingSweepIntervalMs = positiveMs(options.staleBindingSweepIntervalMs, STALE_BINDING_SWEEP_INTERVAL_MS);
406
448
  this.#staleBindingTtlMs = positiveMs(options.staleBindingTtlMs, STALE_BINDING_TTL_MS);
407
449
  this.#reconcileIntervalMs = positiveMs(options.reconcileIntervalMs, RECONCILE_INTERVAL_MS);
@@ -422,6 +464,7 @@ var FactoryDecisionDispatcher = class {
422
464
  await this.#loop;
423
465
  await Promise.allSettled([
424
466
  ...this.#runInFlight,
467
+ ...this.#interactiveInFlight,
425
468
  ...this.#bookkeepingInFlight,
426
469
  ...this.#backgroundInFlight
427
470
  ]);
@@ -454,11 +497,19 @@ var FactoryDecisionDispatcher = class {
454
497
  this.#reconcileOwed = true;
455
498
  this.wake();
456
499
  }
457
- /** Run slots this process holds now, out of its cap. Per process: other replicas keep their own. */
500
+ /**
501
+ * Run slots this process holds now, out of its caps. Per process: other
502
+ * replicas keep their own. `inUse` counts automated slots, including any a
503
+ * person's wake borrowed once the interactive reserve was full.
504
+ */
458
505
  runSlots() {
459
506
  return {
460
507
  inUse: this.#runInFlight.size,
461
- cap: this.#maxInFlight
508
+ cap: this.#maxInFlight,
509
+ interactive: {
510
+ inUse: this.#interactiveInFlight.size,
511
+ cap: this.#maxInteractiveInFlight
512
+ }
462
513
  };
463
514
  }
464
515
  async runOnce(now = /* @__PURE__ */ new Date()) {
@@ -494,7 +545,7 @@ var FactoryDecisionDispatcher = class {
494
545
  async #cycle() {
495
546
  const now = /* @__PURE__ */ new Date();
496
547
  this.#maybeSweepStaleBindings(now);
497
- const active = this.#runInFlight.size > 0 || this.#bookkeepingInFlight.size > 0 || this.#controller.listActiveThreadRuns().length > 0 || this.#lastBoundThreadRunAt !== void 0 && now.getTime() - this.#lastBoundThreadRunAt < this.#reconcileIntervalMs;
548
+ const active = this.#runInFlight.size > 0 || this.#interactiveInFlight.size > 0 || this.#bookkeepingInFlight.size > 0 || this.#controller.listActiveThreadRuns().length > 0 || this.#lastBoundThreadRunAt !== void 0 && now.getTime() - this.#lastBoundThreadRunAt < this.#reconcileIntervalMs;
498
549
  if (!this.#reconcileToolResults) this.#reconcileOwed = false;
499
550
  else if (active) this.#reconcileOwed = true;
500
551
  if (this.#reconcileOwed && this.#maybeReconcileToolResults(now) && !active) this.#reconcileOwed = false;
@@ -509,7 +560,7 @@ var FactoryDecisionDispatcher = class {
509
560
  console.error("Factory decision dispatch cycle failed", sanitizeDispatchError(error));
510
561
  return POLL_MS;
511
562
  }
512
- if (full || this.#runInFlight.size > 0 || this.#bookkeepingInFlight.size > 0) return POLL_MS;
563
+ if (full || this.#runInFlight.size > 0 || this.#interactiveInFlight.size > 0 || this.#bookkeepingInFlight.size > 0) return POLL_MS;
513
564
  const dueTimes = [];
514
565
  if (this.#reconcileOwed) dueTimes.push((this.#lastReconcileAt?.getTime() ?? 0) + this.#reconcileIntervalMs);
515
566
  try {
@@ -532,26 +583,44 @@ var FactoryDecisionDispatcher = class {
532
583
  let full = false;
533
584
  const leaseExpiresAt = new Date(now.getTime() + LEASE_MS);
534
585
  const dispatches = [];
535
- const runCapacity = this.#maxInFlight - this.#runInFlight.size;
536
- if (runCapacity > 0) {
537
- const limit = Math.min(BATCH_SIZE, runCapacity);
586
+ const startCapacity = this.#maxInFlight - this.#runInFlight.size;
587
+ if (startCapacity > 0) {
588
+ const limit = Math.min(BATCH_SIZE, startCapacity);
538
589
  const starts = await this.#storage.claimPendingStarts({
539
590
  ownerId: this.#ownerId,
540
591
  now,
541
592
  leaseExpiresAt,
542
593
  limit
543
594
  });
544
- const decisionsLimit = limit - starts.length;
545
- full = decisionsLimit <= 0;
546
- const decisions = decisionsLimit > 0 ? await this.#storage.claimDeferredDecisions({
595
+ full ||= starts.length >= limit;
596
+ dispatches.push(...starts.map((start) => this.#track(this.#runInFlight, this.#dispatchPendingStart(start, now))));
597
+ }
598
+ const reserveCapacity = Math.max(0, this.#maxInteractiveInFlight - this.#interactiveInFlight.size);
599
+ const interactiveCapacity = reserveCapacity + Math.max(0, this.#maxInFlight - this.#runInFlight.size);
600
+ if (interactiveCapacity > 0) {
601
+ const limit = Math.min(BATCH_SIZE, interactiveCapacity);
602
+ const decisions = await this.#storage.claimDeferredDecisions({
547
603
  ownerId: this.#ownerId,
548
604
  now,
549
605
  leaseExpiresAt,
550
- limit: decisionsLimit,
551
- decisionFilter: isRunBearingDecision
552
- }) : [];
553
- full ||= starts.length + decisions.length >= limit;
554
- dispatches.push(...starts.map((start) => this.#track(this.#runInFlight, this.#dispatchPendingStart(start, now))), ...decisions.map((decision) => this.#track(this.#runInFlight, this.#dispatchDecision(decision, now))));
606
+ limit,
607
+ decisionFilter: isInteractiveDecision
608
+ });
609
+ full ||= decisions.length >= limit;
610
+ dispatches.push(...decisions.map((decision, index) => this.#track(index < reserveCapacity ? this.#interactiveInFlight : this.#runInFlight, this.#dispatchDecision(decision, now))));
611
+ }
612
+ const runCapacity = this.#maxInFlight - this.#runInFlight.size;
613
+ if (runCapacity > 0) {
614
+ const limit = Math.min(BATCH_SIZE, runCapacity);
615
+ const decisions = await this.#storage.claimDeferredDecisions({
616
+ ownerId: this.#ownerId,
617
+ now,
618
+ leaseExpiresAt,
619
+ limit,
620
+ decisionFilter: isAutomatedRunDecision
621
+ });
622
+ full ||= decisions.length >= limit;
623
+ dispatches.push(...decisions.map((decision) => this.#track(this.#runInFlight, this.#dispatchDecision(decision, now))));
555
624
  }
556
625
  const bookkeepingCapacity = BOOKKEEPING_MAX_IN_FLIGHT - this.#bookkeepingInFlight.size;
557
626
  if (bookkeepingCapacity > 0) {
@@ -605,7 +674,7 @@ var FactoryDecisionDispatcher = class {
605
674
  try {
606
675
  const session = await this.#controller.getSession(binding.sessionId);
607
676
  if (session?.thread.getId() !== binding.threadId) return false;
608
- return session.suspensions.hasPending() || session.run.isRunning();
677
+ return sessionHoldsWork(session);
609
678
  } catch {
610
679
  return false;
611
680
  }
@@ -635,7 +704,7 @@ var FactoryDecisionDispatcher = class {
635
704
  }
636
705
  await this.#supersedeProposals(record, decision);
637
706
  if (record.attempts <= 1) await this.#reviewQueuedOnce(record, decision);
638
- await this.#withLease(async (leaseExpiresAt) => this.#storage.renewDeferredDecisionLease(leaseIdentity(record, this.#ownerId), leaseExpiresAt), async () => this.#executeDecision(record, decision));
707
+ await this.#withLease(async (leaseExpiresAt) => this.#storage.renewDeferredDecisionLease(leaseIdentity(record, this.#ownerId), leaseExpiresAt), async () => this.#executeDecision(record, decision, now));
639
708
  executionCompleted = true;
640
709
  if (!await this.#storage.completeDeferredDecision(leaseIdentity(record, this.#ownerId), /* @__PURE__ */ new Date())) throw new Error("Factory decision lease was lost before completion.");
641
710
  if (this.#reviewWatched.has(record) || this.#reviewReplayed.has(record)) await this.#reviewStatus(record, decision, {
@@ -653,7 +722,7 @@ var FactoryDecisionDispatcher = class {
653
722
  return;
654
723
  }
655
724
  if (error instanceof FactoryDecisionPostponed) {
656
- await this.#storage.postponeDeferredDecision(leaseIdentity(record, this.#ownerId), new Date(now.getTime() + POSTPONE_MS), /* @__PURE__ */ new Date());
725
+ await this.#storage.postponeDeferredDecision(leaseIdentity(record, this.#ownerId), error.availableAt ?? new Date(now.getTime() + POSTPONE_MS), /* @__PURE__ */ new Date());
657
726
  return;
658
727
  }
659
728
  const failureCode = factoryDispatchFailureCode(error);
@@ -914,7 +983,7 @@ var FactoryDecisionDispatcher = class {
914
983
  if (reviewsFactoryAuthoredCode(boards, item, decision)) return false;
915
984
  return !startsInAutoPhase(boards, item, decision);
916
985
  }
917
- async #executeDecision(record, decision) {
986
+ async #executeDecision(record, decision, now) {
918
987
  const nextChain = [...record.causalChain, {
919
988
  ingressId: record.idempotencyKey,
920
989
  decisionType: decision.type
@@ -926,6 +995,11 @@ var FactoryDecisionDispatcher = class {
926
995
  else await this.#applyTransition(record, decision, nextChain);
927
996
  return;
928
997
  case "routeEvent":
998
+ if (isUpdateEvent(decision.event.type)) {
999
+ const combined = await this.#foldUpdates(record, decision, now);
1000
+ if (combined) await this.#routeEvent(record, combined, nextChain);
1001
+ return;
1002
+ }
929
1003
  await this.#routeEvent(record, decision.event, nextChain);
930
1004
  return;
931
1005
  case "upsertLinkedWorkItem":
@@ -1228,6 +1302,7 @@ var FactoryDecisionDispatcher = class {
1228
1302
  if (existing && externalSourceKey(existing.externalSource) !== externalSourceKey(externalSourceForDecision(requested))) {
1229
1303
  const source = externalSourceForDecision(requested);
1230
1304
  const facts = workItemProviderAdapter(source).toSource(source, requested.metadata ?? null);
1305
+ if (requested.closesIssue?.workItemId === existing.id && record.workItemId === null) await this.#queueLinkedPullRequestOpened(record, requested, existing, causalChain);
1231
1306
  if (facts?.state === "open") await this.#storage.syncWorkItemSource({
1232
1307
  orgId: record.orgId,
1233
1308
  factoryProjectId: record.factoryProjectId,
@@ -1247,16 +1322,20 @@ var FactoryDecisionDispatcher = class {
1247
1322
  const attachBoards = await this.#boards.load(record);
1248
1323
  if (await this.#attachLinkedItem(record, requested, requested.attachTo.workItemId, causalChain, (card) => cardBoardFlow(attachBoards, card).pullRequestReview !== void 0 ? { phase: null } : void 0)) return;
1249
1324
  }
1250
- if (!existing && requested.closesIssue && await this.#joinClosedIssue(record, requested, causalChain)) return;
1325
+ if (!existing && requested.closesIssue && await this.#linkClosedIssue(record, requested, causalChain)) return;
1251
1326
  const materializedHere = existing?.metadata?.[FACTORY_RULE_MATERIALIZATION_KEY] === record.idempotencyKey;
1252
1327
  if (materializedHere && requested.skipRules === true) return;
1253
1328
  const boards = await this.#boards.load(record);
1254
1329
  const renamed = existing ? null : await this.#linearCardByIssueId(record, requested, boards);
1255
1330
  const current = existing ?? renamed;
1256
1331
  const decision = !current ? await this.#routeArrival(record, requested, boards) : materializedHere ? await this.#resumeRoutedCard(record, current, requested, boards) : this.#keepRoutedCard(current, requested, boards);
1332
+ if (!decision) return;
1257
1333
  if (materializedHere) for (const suffix of ["destination", "initial-entry"]) {
1258
1334
  const replay = await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, `decision:${record.idempotencyKey}:${existing.id}:${suffix}`);
1259
- if (replay?.status === "accepted" && replay.stage === decision.stage) return;
1335
+ if (replay?.status === "accepted" && replay.stage === decision.stage) {
1336
+ await this.#resolveNotRouted(record, decision.sourceKey);
1337
+ return;
1338
+ }
1260
1339
  }
1261
1340
  assertFactoryDecisionTarget(decision, boards);
1262
1341
  const definition = boards.get(decision.board);
@@ -1295,6 +1374,7 @@ var FactoryDecisionDispatcher = class {
1295
1374
  },
1296
1375
  reuseMode: "preserve"
1297
1376
  });
1377
+ const filed = () => this.#resolveNotRouted(record, decision.sourceKey);
1298
1378
  const itemBoard = boardForWorkItem(result.item);
1299
1379
  const itemFlow = itemBoard === decision.board ? void 0 : boardFlow(boards.get(itemBoard));
1300
1380
  const keptReview = isPullRequestCard({ source: workItemSource(result.item.externalSource) }) ? itemFlow?.pullRequestReview : void 0;
@@ -1347,10 +1427,14 @@ var FactoryDecisionDispatcher = class {
1347
1427
  });
1348
1428
  item = fresh && fresh.revision !== item.revision ? fresh : null;
1349
1429
  }
1430
+ await filed();
1350
1431
  return;
1351
1432
  }
1352
1433
  const materializedByDecision = result.item.metadata?.[FACTORY_RULE_MATERIALIZATION_KEY] === record.idempotencyKey;
1353
- if (!materializedByDecision && (decision.stage === initialPhase || !result.item.stages.includes(initialPhase))) return;
1434
+ if (!materializedByDecision && (decision.stage === initialPhase || !result.item.stages.includes(initialPhase))) {
1435
+ await filed();
1436
+ return;
1437
+ }
1354
1438
  let expectedRevision = result.item.revision;
1355
1439
  if (materializedByDecision) {
1356
1440
  const initial = await this.#transitionService.transition({
@@ -1379,6 +1463,7 @@ var FactoryDecisionDispatcher = class {
1379
1463
  }
1380
1464
  expectedRevision = initial.revision;
1381
1465
  }
1466
+ await filed();
1382
1467
  if (decision.stage === initialPhase) return;
1383
1468
  const moved = await this.#transitionService.transition({
1384
1469
  orgId: record.orgId,
@@ -1407,7 +1492,7 @@ var FactoryDecisionDispatcher = class {
1407
1492
  * own card, refused by `admit`, or another card took the record first), so the caller files the
1408
1493
  * record as usual. `admit` runs again on a fresh read whenever the card changed in between.
1409
1494
  */
1410
- async #attachLinkedItem(record, decision, workItemId, causalChain, admit) {
1495
+ async #attachLinkedItem(record, decision, workItemId, causalChain, admit, cardMetadata, afterAttach) {
1411
1496
  if (this.#storage.legacyMode) return false;
1412
1497
  const boards = await this.#boards.load(record);
1413
1498
  let attached;
@@ -1425,7 +1510,8 @@ var FactoryDecisionDispatcher = class {
1425
1510
  id: card.id,
1426
1511
  source: externalSourceForDecision(decision),
1427
1512
  metadata: decision.metadata ?? null,
1428
- expectedRevision: card.revision
1513
+ expectedRevision: card.revision,
1514
+ ...cardMetadata ? { cardMetadata: (metadata) => cardMetadata(metadata, card) } : {}
1429
1515
  });
1430
1516
  if (!result) return false;
1431
1517
  attached = {
@@ -1440,6 +1526,7 @@ var FactoryDecisionDispatcher = class {
1440
1526
  }
1441
1527
  if (!attached) return false;
1442
1528
  const { card, phase } = attached;
1529
+ await afterAttach?.(card);
1443
1530
  const stage = card.stages.length === 1 ? card.stages[0] : void 0;
1444
1531
  const board = boards.get(boardForWorkItem(card));
1445
1532
  if (!phase || !stage || stage === phase) return true;
@@ -1469,74 +1556,172 @@ var FactoryDecisionDispatcher = class {
1469
1556
  return true;
1470
1557
  }
1471
1558
  /**
1472
- * Joins a pull or merge request to the card of the issue it closes when the project's intake
1473
- * routes say so: the first route matching the arrival, with the facts of that card as it is now,
1474
- * is a joining one. Only an arrival the routes would place qualifies, and only from an author
1475
- * with write access: no route can put an outsider's pull request on someone else's card.
1559
+ * Links a pull or merge request to the card of the issue it closes, whoever opened it: Factory
1560
+ * does this itself, before intake, wherever the card sits, so long as it is unfinished. Linking
1561
+ * runs nothing. An outsider's pull request is recorded as untrusted on the card, so it never
1562
+ * becomes the card's working pull request on its own; a person picks it. The card then gets the
1563
+ * pull request's `pull_request.opened`, so its board's own card-move rules decide whether it moves.
1476
1564
  */
1477
- async #joinClosedIssue(record, decision, causalChain) {
1478
- if (!authorTrusted(decision.metadata) || !this.#intakeRoutes || decision.skipRules === true) return false;
1479
- if (record.workItemId !== null) return false;
1480
- const boards = await this.#boards.load(record);
1481
- const routes = await this.#intakeRoutes.listIntakeRoutes({
1565
+ async #linkClosedIssue(record, decision, causalChain) {
1566
+ if (decision.skipRules === true || record.workItemId !== null) return false;
1567
+ const trusted = authorTrusted(decision.metadata);
1568
+ const trustKey = this.#pullRequestTrustKey(decision);
1569
+ return this.#attachLinkedItem(record, decision, decision.closesIssue.workItemId, causalChain, () => ({ phase: null }), (metadata, card) => {
1570
+ const links = linkedPullRequests(metadata);
1571
+ const withLink = {
1572
+ ...metadata,
1573
+ [LINKED_PULL_REQUESTS_KEY]: {
1574
+ ...links,
1575
+ [trustKey]: links[trustKey] ?? linkFacts(card, trusted, trustKey)
1576
+ }
1577
+ };
1578
+ if (trusted) return withLink;
1579
+ const listed = metadata[UNTRUSTED_PULL_REQUESTS_KEY];
1580
+ const untrusted = Array.isArray(listed) ? listed.filter((entry) => typeof entry === "string") : [];
1581
+ return untrusted.includes(trustKey) ? withLink : {
1582
+ ...withLink,
1583
+ [UNTRUSTED_PULL_REQUESTS_KEY]: [...untrusted, trustKey]
1584
+ };
1585
+ }, (card) => this.#queueLinkedPullRequestOpened(record, decision, card, causalChain));
1586
+ }
1587
+ /** The key a card lists an untrusted attached pull request under (see `UNTRUSTED_PULL_REQUESTS_KEY`). */
1588
+ #pullRequestTrustKey(decision) {
1589
+ const source = externalSourceForDecision(decision);
1590
+ return pullRequestTrustKey(workItemProviderAdapter(source).toSource(source, decision.metadata ?? null));
1591
+ }
1592
+ /**
1593
+ * Hands the card a linked pull request's `pull_request.opened`, with the facts saved when it
1594
+ * joined (the card's phase then, and whether a trusted open pull request was already on it), so
1595
+ * a retry after the card changed still describes the link as it happened. Keyed by the card and
1596
+ * the pull request, so whichever delivery files the pull request, and however often, the card
1597
+ * gets the event once.
1598
+ */
1599
+ async #queueLinkedPullRequestOpened(record, decision, card, causalChain) {
1600
+ const sourceKey = externalSourceKey(externalSourceForDecision(decision));
1601
+ const key = `linked-pull-request:${card.id}:${sourceKey}`;
1602
+ const trustKey = this.#pullRequestTrustKey(decision);
1603
+ const link = linkedPullRequests(card.metadata)[trustKey] ?? linkFacts(card, authorTrusted(decision.metadata), trustKey);
1604
+ if ((await this.#storage.commitRuleEvaluation({
1605
+ orgId: record.orgId,
1606
+ factoryProjectId: record.factoryProjectId,
1607
+ workItemId: card.id,
1608
+ ingress: { identity: `decision:${key}` },
1609
+ expectedRevision: card.revision,
1610
+ actor: {
1611
+ type: "system",
1612
+ id: "factory-rule-dispatcher"
1613
+ },
1614
+ outcome: { status: "accepted" },
1615
+ decisions: [{
1616
+ type: "routeEvent",
1617
+ idempotencyKey: key,
1618
+ event: {
1619
+ type: "pull_request.opened",
1620
+ pullRequestTrusted: link.trusted,
1621
+ closedIssue: {
1622
+ phase: link.phase,
1623
+ hasPullRequest: link.hasPullRequest
1624
+ }
1625
+ }
1626
+ }],
1627
+ causalChain,
1628
+ now: /* @__PURE__ */ new Date()
1629
+ })).status === "stale") throw new Error("Factory linked pull request event was not queued: the work item changed concurrently.");
1630
+ }
1631
+ /**
1632
+ * Leaves a warning in the decision log for each card-move rule that matched but whose target
1633
+ * couldn't take the card; a redelivery of the same event replaces it.
1634
+ */
1635
+ async #logSkippedRoutes(record, item, event, skipped) {
1636
+ if (!this.#intakeRoutes || skipped.length === 0) return;
1637
+ const scope = {
1482
1638
  orgId: record.orgId,
1483
1639
  factoryProjectId: record.factoryProjectId
1640
+ };
1641
+ const evaluator = await projectIntakeEvaluator(this.#intakeEvaluator, this.#intakeRoutes, scope);
1642
+ for (const skip of skipped) await this.#intakeRoutes.recordIntakeDecision(scope, {
1643
+ idempotencyKey: `rule-skipped:${record.idempotencyKey}:${skip.routeId}`,
1644
+ outcome: "rule_skipped",
1645
+ evaluator,
1646
+ boardKey: skip.boardKey,
1647
+ routeId: skip.routeId,
1648
+ reason: `The card-move rule matched ${event.type} but was skipped: ${skip.reason}.`,
1649
+ sourceKey: item.externalSource?.externalId ?? null,
1650
+ title: item.title,
1651
+ url: item.externalSource?.url ?? null
1484
1652
  });
1485
- if (routes.length === 0) return false;
1486
- const arrival = cardRuleFacts({
1487
- title: decision.title,
1488
- metadata: decision.metadata ?? {},
1489
- externalSource: externalSourceForDecision(decision)
1490
- });
1491
- return this.#attachLinkedItem(record, decision, decision.closesIssue.workItemId, causalChain, (card) => {
1492
- const route = resolveIntakeRoute(routes, {
1493
- ...arrival,
1494
- ...closedIssueRuleFacts(card)
1495
- }, boards, card);
1496
- return route?.type === "join" ? { phase: route.phase } : void 0;
1497
- });
1653
+ }
1654
+ /** Marks the item's Not routed record, if any, resolved: its card is filed. */
1655
+ async #resolveNotRouted(record, sourceKey) {
1656
+ await this.#intakeRoutes?.resolveNotRouted({
1657
+ orgId: record.orgId,
1658
+ factoryProjectId: record.factoryProjectId
1659
+ }, sourceKey, "factory-rule-dispatcher");
1498
1660
  }
1499
1661
  /**
1500
- * Places an arrival where the project's intake routes say: the first enabled route matching it,
1501
- * else the default board's first phase. The board and phase an integration's rule named don't
1502
- * count; only a decision placing the card outright (`skipRules`) keeps its own.
1662
+ * Places an arrival where intake says (see `resolveIntake`). The board and phase an
1663
+ * integration's rule named don't count; only a decision placing the card outright (`skipRules`)
1664
+ * keeps its own. Undefined when no board takes it: it is logged Not routed and no card is filed.
1665
+ * Every decision is logged, keyed by the arrival's decision so a redelivery replaces its row.
1503
1666
  */
1504
1667
  async #routeArrival(record, decision, boards) {
1505
- if (!this.#intakeRoutes || decision.skipRules === true) return decision;
1668
+ if (decision.skipRules === true) return decision;
1506
1669
  if (record.workItemId !== null) return decision;
1507
- const routes = await this.#intakeRoutes.listIntakeRoutes({
1670
+ if (!this.#intakeRoutes) {
1671
+ if (this.#intakeEvaluator !== "route-list") throw new Error("Intake rules are unavailable right now.");
1672
+ return decision;
1673
+ }
1674
+ const scope = {
1508
1675
  orgId: record.orgId,
1509
1676
  factoryProjectId: record.factoryProjectId
1677
+ };
1678
+ const evaluator = decision.idempotencyKey.startsWith("intake-route-again:") ? "intake-order" : await projectIntakeEvaluator(this.#intakeEvaluator, this.#intakeRoutes, scope);
1679
+ const [routes, order] = await Promise.all([this.#intakeRoutes.listIntakeRoutes(scope), evaluator === "intake-order" ? this.#intakeRoutes.readIntakeOrder(scope, { boards: [...boards.keys()] }) : void 0]);
1680
+ const facts = await arrivalRuleFacts(decision, {
1681
+ factoryProjectId: record.factoryProjectId,
1682
+ registry: boards,
1683
+ card: (id) => this.#storage.get({
1684
+ orgId: record.orgId,
1685
+ id
1686
+ })
1510
1687
  });
1511
- const closedIssue = decision.closesIssue ? await this.#storage.get({
1512
- orgId: record.orgId,
1513
- id: decision.closesIssue.workItemId
1514
- }) : null;
1515
- const facts = {
1516
- ...cardRuleFacts({
1517
- title: decision.title,
1518
- metadata: decision.metadata ?? {},
1519
- externalSource: externalSourceForDecision(decision)
1520
- }),
1521
- ...decision.closesIssue ? closedIssueRuleFacts(closedIssue && closedIssue.factoryProjectId === record.factoryProjectId && !isTerminalWorkItem(boards, closedIssue) ? closedIssue : void 0) : {}
1688
+ const resolution = resolveIntake({
1689
+ evaluator,
1690
+ routes,
1691
+ order: order?.boardKeys ?? [],
1692
+ facts,
1693
+ registry: boards
1694
+ });
1695
+ const logged = {
1696
+ idempotencyKey: record.idempotencyKey,
1697
+ evaluator,
1698
+ sourceKey: decision.sourceKey,
1699
+ title: decision.title,
1700
+ url: decision.url
1522
1701
  };
1523
- const placement = resolveIntakePlacement(routes, facts, boards);
1524
- if (!placement) {
1525
- const fallback = intakeTarget(boards);
1526
- return fallback ? {
1527
- ...decision,
1528
- board: fallback.board,
1529
- stage: fallback.initialPhase
1530
- } : decision;
1702
+ if (resolution.outcome === "not_routed") {
1703
+ await this.#intakeRoutes.recordIntakeDecision(scope, {
1704
+ ...logged,
1705
+ outcome: "not_routed",
1706
+ reason: resolution.reason,
1707
+ arrival: { ...decision }
1708
+ });
1709
+ return;
1531
1710
  }
1711
+ await this.#intakeRoutes.recordIntakeDecision(scope, {
1712
+ ...logged,
1713
+ outcome: "placed",
1714
+ boardKey: resolution.board,
1715
+ routeId: resolution.routeId
1716
+ });
1532
1717
  return {
1533
1718
  ...decision,
1534
- board: placement.board,
1535
- stage: placement.phase,
1536
- metadata: {
1719
+ board: resolution.board,
1720
+ stage: resolution.phase,
1721
+ ...resolution.routeId !== null && { metadata: {
1537
1722
  ...decision.metadata,
1538
- [INTAKE_ROUTE_METADATA_KEY]: placement.routeId
1539
- }
1723
+ ["intakeRouteId"]: resolution.routeId
1724
+ } }
1540
1725
  };
1541
1726
  }
1542
1727
  /**
@@ -1654,41 +1839,39 @@ var FactoryDecisionDispatcher = class {
1654
1839
  * moves nothing twice.
1655
1840
  */
1656
1841
  async #routeEvent(record, event, causalChain, fallback) {
1657
- const identity = `event-route:${record.idempotencyKey}`;
1842
+ const identity = eventRouteIngress(record.idempotencyKey);
1658
1843
  if (await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, identity)) return;
1659
1844
  if (await this.#statusEventOvertaken(record)) throw new FactoryDecisionSuperseded();
1660
1845
  const resolve = async () => {
1661
1846
  const item = await this.#requireItem(record);
1662
- const board = (await this.#boards.load(record)).get(boardForWorkItem(item));
1847
+ const boards = await this.#boards.load(record);
1848
+ const board = boards.get(boardForWorkItem(item));
1663
1849
  if (!board) return void 0;
1664
- const stage = item.stages.length === 1 ? item.stages[0] : void 0;
1665
- const finished = stage !== void 0 && board.isTerminal(stage);
1666
- if (!eventMovesCard(event.type, finished)) return void 0;
1667
1850
  const routes = this.#intakeRoutes ? await this.#intakeRoutes.listIntakeRoutes({
1668
1851
  orgId: record.orgId,
1669
1852
  factoryProjectId: record.factoryProjectId
1670
1853
  }) : [];
1671
- if (!routesHandleEvent(routes, event, board)) return {
1854
+ const skipped = [];
1855
+ const plan = planEventMove({
1856
+ routes,
1857
+ event,
1672
1858
  item,
1673
- board,
1674
- fallback: true
1675
- };
1676
- const route = resolveEventRoute(routes, event, cardRuleFacts(item), board, hasPullRequest(item));
1677
- if (!route) return fallback && isPullRequestEvent(event.type) ? {
1678
- item,
1679
- board,
1680
- fallback: true
1681
- } : void 0;
1682
- if (fallback && isPullRequestEvent(event.type) && route.phase === fallback.stage) return {
1859
+ registry: boards,
1860
+ ...fallback && { fallback: { stage: fallback.stage } },
1861
+ onSkip: (skip) => skipped.push(skip)
1862
+ });
1863
+ await this.#logSkippedRoutes(record, item, event, skipped);
1864
+ if (plan.outcome === "rule_default") return {
1683
1865
  item,
1684
1866
  board,
1685
1867
  fallback: true
1686
1868
  };
1687
- if (stage === route.phase) return void 0;
1869
+ if (plan.outcome !== "moves") return void 0;
1688
1870
  return {
1689
1871
  item,
1690
1872
  board,
1691
- route
1873
+ route: plan.move,
1874
+ target: boards.get(plan.move.board)
1692
1875
  };
1693
1876
  };
1694
1877
  const first = await resolve();
@@ -1697,25 +1880,15 @@ var FactoryDecisionDispatcher = class {
1697
1880
  if (fallback) await this.#applyTransition(record, fallback, causalChain);
1698
1881
  return;
1699
1882
  }
1700
- if (!first.board.isTerminal(first.route.phase)) {
1701
- const binding = await this.#findBinding(record);
1702
- const startedBy = binding ? first.item.sessions[binding.role]?.startedBy : void 0;
1703
- if (startedBy) await this.#primeCredentials?.({
1704
- orgId: record.orgId,
1705
- userId: startedBy
1706
- });
1707
- const session = binding && startedBy ? await this.#findSession(binding, {
1708
- userId: startedBy,
1709
- orgId: record.orgId
1710
- }) : void 0;
1711
- if (binding && session && await this.#hasRunInFlight(session, binding)) throw new FactoryDecisionPostponed();
1712
- }
1883
+ if (!first.target.isTerminal(first.route.phase) && await this.#cardRunInFlight(record, first.item)) throw new FactoryDecisionPostponed();
1713
1884
  const { item, board, route } = first;
1885
+ const crossesBoards = route.board !== board.id;
1714
1886
  const result = await this.#transitionService.transition({
1715
1887
  orgId: record.orgId,
1716
1888
  factoryProjectId: record.factoryProjectId,
1717
1889
  workItemId: item.id,
1718
1890
  board: board.id,
1891
+ ...crossesBoards ? { toBoard: route.board } : {},
1719
1892
  stage: route.phase,
1720
1893
  expectedRevision: item.revision,
1721
1894
  actor: {
@@ -1731,6 +1904,59 @@ var FactoryDecisionDispatcher = class {
1731
1904
  eventRoute: { routeId: route.routeId }
1732
1905
  });
1733
1906
  if (result.status === "rejected" && result.code === "stale") throw new Error(`${result.code}: ${result.reason}`);
1907
+ if (result.status === "accepted" && crossesBoards) await this.#storage.supersedeDecisionsForWorkItem({
1908
+ orgId: record.orgId,
1909
+ factoryProjectId: record.factoryProjectId,
1910
+ workItemId: item.id,
1911
+ except: result.decisions.map((decision) => String(decision.idempotencyKey)),
1912
+ supersededAt: /* @__PURE__ */ new Date()
1913
+ });
1914
+ }
1915
+ /**
1916
+ * Whether the card's session has a run in flight. A binding with no recorded owner never
1917
+ * started a run, so it has none.
1918
+ */
1919
+ async #cardRunInFlight(record, item) {
1920
+ const binding = await this.#findBinding(record);
1921
+ const startedBy = binding ? item.sessions[binding.role]?.startedBy : void 0;
1922
+ if (!binding || !startedBy) return false;
1923
+ await this.#primeCredentials?.({
1924
+ orgId: record.orgId,
1925
+ userId: startedBy
1926
+ });
1927
+ const session = await this.#findSession(binding, {
1928
+ userId: startedBy,
1929
+ orgId: record.orgId
1930
+ });
1931
+ return session !== void 0 && await this.#hasRunInFlight(session, binding);
1932
+ }
1933
+ /**
1934
+ * The one update event an update decision stands for, or undefined when it has nothing to do.
1935
+ * Updates to the same card of the same kind (work item or pull request, the card's own session
1936
+ * or anyone else) and to the same pull request fold into the newest one: an older one gives way to it, and the newest carries
1937
+ * the net change of every one since the group last moved the card, so a label added then removed
1938
+ * nets out. The newest waits until no update has arrived for {@link UPDATE_BURST_MS}, and one
1939
+ * from the card's own session also until the session's run ends.
1940
+ */
1941
+ async #foldUpdates(record, decision, now) {
1942
+ if (!record.workItemId) return void 0;
1943
+ const group = updateGroup(await this.#storage.listDeferredDecisions(record.orgId, record.factoryProjectId, { workItemId: record.workItemId }), decision);
1944
+ const { superseded, since, event } = await foldUpdate(group, record.id, (other) => this.#moveCommitted(record, other));
1945
+ if (superseded) throw new FactoryDecisionSuperseded();
1946
+ const sameClaim = (other) => other.leaseOwner === record.leaseOwner && other.leaseExpiresAt?.getTime() === record.leaseExpiresAt?.getTime();
1947
+ if (since.some((other) => other.status === "leased" && !sameClaim(other))) throw new FactoryDecisionPostponed();
1948
+ const quietAt = record.createdAt.getTime() + UPDATE_BURST_MS;
1949
+ if (now.getTime() < quietAt) throw new FactoryDecisionPostponed(new Date(quietAt));
1950
+ if (decision.fromCardSession) {
1951
+ const item = await this.#requireItem(record);
1952
+ if (await this.#cardRunInFlight(record, item)) throw new FactoryDecisionPostponed();
1953
+ }
1954
+ return event;
1955
+ }
1956
+ /** Whether `other`'s card move committed, even if its decision never finished. */
1957
+ async #moveCommitted(record, other) {
1958
+ const identity = eventRouteIngress(other.idempotencyKey);
1959
+ return Boolean(await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, identity));
1734
1960
  }
1735
1961
  /**
1736
1962
  * Whether a later status event was queued for the same card: the source's last word wins, so a
@@ -1916,13 +2142,27 @@ var FactoryDecisionDispatcher = class {
1916
2142
  return this.#autoApproving.has(toolCallId);
1917
2143
  }
1918
2144
  /**
2145
+ * Whether a run is in flight on any of the card's active seats, as the board shows it: a run the
2146
+ * registry here holds on a seat's thread, whoever started it, or one live on another dispatcher.
2147
+ * A read-only probe: it never switches a session's thread.
2148
+ */
2149
+ async hasRunInFlightOnCard({ orgId, factoryProjectId, workItemId }) {
2150
+ const bindings = (await this.#storage.listRunBindings(orgId, factoryProjectId, workItemId)).filter((binding) => binding.status === "active");
2151
+ const liveThreads = new Set(this.#controller.listActiveThreadRuns().map((active) => active.threadId));
2152
+ for (const binding of bindings) {
2153
+ if (liveThreads.has(binding.threadId)) return true;
2154
+ const session = await this.#controller.getSession(binding.sessionId);
2155
+ if (session && await this.#hasRunInFlight(session, binding)) return true;
2156
+ }
2157
+ return false;
2158
+ }
2159
+ /**
1919
2160
  * Whether a run is in flight on `binding`: live here, or live on another dispatcher. An open-run
1920
- * entry with nothing live behind it is an orphan of a dead process and does not count.
2161
+ * entry with nothing live behind it is an orphan of a dead process and does not count. Reads the
2162
+ * binding's own thread, which the session may have switched away from.
1921
2163
  */
1922
2164
  async #hasRunInFlight(session, binding) {
1923
- const open = (await listSessionOpenRuns(session)).filter((entry) => entry.bindingId === binding.id);
1924
- if (open.length === 0) return false;
1925
- if (open.some((entry) => isOpenRunLiveElsewhere(entry, this.#ownerId))) return true;
2165
+ if ((await listThreadOpenRuns(session, binding.threadId)).filter((entry) => entry.bindingId === binding.id).some((entry) => isOpenRunLiveElsewhere(entry, this.#ownerId))) return true;
1926
2166
  return this.#controller.listActiveThreadRuns().some((active) => active.threadId === binding.threadId);
1927
2167
  }
1928
2168
  /** Waits for the run in flight on `binding` to end, so a kickoff never overlaps it. */
@@ -2166,6 +2406,6 @@ const FACTORY_DISPATCH_CONSTANTS = {
2166
2406
  maxInFlight: MAX_IN_FLIGHT,
2167
2407
  reviewStatusTimeoutMs: REVIEW_STATUS_TIMEOUT_MS
2168
2408
  };
2169
- export { FACTORY_DISPATCH_CONSTANTS, FactoryDecisionDispatcher, isRunBearingDecision };
2409
+ export { FACTORY_DISPATCH_CONSTANTS, FactoryDecisionDispatcher, UPDATE_BURST_MS, isInteractiveDecision };
2170
2410
 
2171
2411
  //# sourceMappingURL=dispatcher.js.map