@mastra/factory 0.28.0-alpha.0 → 0.28.0-alpha.10

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 (746) hide show
  1. package/README.md +528 -161
  2. package/dist/auth.d.ts.map +1 -1
  3. package/dist/auth.js +12 -6
  4. package/dist/auth.js.map +1 -1
  5. package/dist/boards/board-events.d.ts +54 -0
  6. package/dist/boards/board-events.d.ts.map +1 -0
  7. package/dist/boards/board-events.js +87 -0
  8. package/dist/boards/board-events.js.map +1 -0
  9. package/dist/boards/board-writes.d.ts +86 -0
  10. package/dist/boards/board-writes.d.ts.map +1 -0
  11. package/dist/boards/board-writes.js +266 -0
  12. package/dist/boards/board-writes.js.map +1 -0
  13. package/dist/boards/card-facts.d.ts +3 -1
  14. package/dist/boards/card-facts.d.ts.map +1 -1
  15. package/dist/boards/card-facts.js +30 -4
  16. package/dist/boards/card-facts.js.map +1 -1
  17. package/dist/boards/default-board.d.ts +7 -0
  18. package/dist/boards/default-board.d.ts.map +1 -0
  19. package/dist/boards/default-board.js +10 -0
  20. package/dist/boards/default-board.js.map +1 -0
  21. package/dist/boards/define-board.d.ts +56 -23
  22. package/dist/boards/define-board.d.ts.map +1 -1
  23. package/dist/boards/define-board.js +89 -45
  24. package/dist/boards/define-board.js.map +1 -1
  25. package/dist/boards/index.d.ts +6 -9
  26. package/dist/boards/index.d.ts.map +1 -1
  27. package/dist/boards/index.js +6 -20
  28. package/dist/boards/intake-routing.d.ts +55 -11
  29. package/dist/boards/intake-routing.d.ts.map +1 -1
  30. package/dist/boards/intake-routing.js +109 -19
  31. package/dist/boards/intake-routing.js.map +1 -1
  32. package/dist/boards/legacy-plan-role.d.ts.map +1 -1
  33. package/dist/boards/legacy-plan-role.js +14 -5
  34. package/dist/boards/legacy-plan-role.js.map +1 -1
  35. package/dist/boards/phase-automation.d.ts +7 -0
  36. package/dist/boards/phase-automation.d.ts.map +1 -1
  37. package/dist/boards/phase-automation.js +19 -3
  38. package/dist/boards/phase-automation.js.map +1 -1
  39. package/dist/boards/phase-runner.d.ts +18 -10
  40. package/dist/boards/phase-runner.d.ts.map +1 -1
  41. package/dist/boards/phase-runner.js +39 -34
  42. package/dist/boards/phase-runner.js.map +1 -1
  43. package/dist/boards/project-boards.d.ts +65 -8
  44. package/dist/boards/project-boards.d.ts.map +1 -1
  45. package/dist/boards/project-boards.js +217 -26
  46. package/dist/boards/project-boards.js.map +1 -1
  47. package/dist/boards/registry.d.ts +7 -1
  48. package/dist/boards/registry.d.ts.map +1 -1
  49. package/dist/boards/registry.js +19 -4
  50. package/dist/boards/registry.js.map +1 -1
  51. package/dist/boards/relocate.d.ts +1 -1
  52. package/dist/boards/relocate.d.ts.map +1 -1
  53. package/dist/boards/relocate.js +3 -2
  54. package/dist/boards/relocate.js.map +1 -1
  55. package/dist/boards/review.d.ts +5 -2
  56. package/dist/boards/review.d.ts.map +1 -1
  57. package/dist/boards/review.js +12 -11
  58. package/dist/boards/review.js.map +1 -1
  59. package/dist/boards/semantics.d.ts +160 -20
  60. package/dist/boards/semantics.d.ts.map +1 -1
  61. package/dist/boards/semantics.js +255 -23
  62. package/dist/boards/semantics.js.map +1 -1
  63. package/dist/boards/stored-board.d.ts +73 -1
  64. package/dist/boards/stored-board.d.ts.map +1 -1
  65. package/dist/boards/stored-board.js +157 -11
  66. package/dist/boards/stored-board.js.map +1 -1
  67. package/dist/boards/work-migrations.d.ts +43 -0
  68. package/dist/boards/work-migrations.d.ts.map +1 -0
  69. package/dist/boards/work-migrations.js +353 -0
  70. package/dist/boards/work-migrations.js.map +1 -0
  71. package/dist/boards/work-routes.d.ts +58 -0
  72. package/dist/boards/work-routes.d.ts.map +1 -0
  73. package/dist/boards/work-routes.js +270 -0
  74. package/dist/boards/work-routes.js.map +1 -0
  75. package/dist/boards/work-seeds.d.ts +9 -0
  76. package/dist/boards/work-seeds.d.ts.map +1 -0
  77. package/dist/boards/work-seeds.js +56 -0
  78. package/dist/boards/work-seeds.js.map +1 -0
  79. package/dist/boards/work.d.ts +8 -19
  80. package/dist/boards/work.d.ts.map +1 -1
  81. package/dist/boards/work.js +33 -281
  82. package/dist/boards/work.js.map +1 -1
  83. package/dist/environment/build-runner.d.ts.map +1 -1
  84. package/dist/environment/build-runner.js +2 -2
  85. package/dist/environment/build-runner.js.map +1 -1
  86. package/dist/environment/build-workflow.d.ts.map +1 -1
  87. package/dist/environment/build-workflow.js +6 -5
  88. package/dist/environment/build-workflow.js.map +1 -1
  89. package/dist/environment/build.d.ts +15 -2
  90. package/dist/environment/build.d.ts.map +1 -1
  91. package/dist/environment/build.js +32 -9
  92. package/dist/environment/build.js.map +1 -1
  93. package/dist/factory.d.ts +90 -9
  94. package/dist/factory.d.ts.map +1 -1
  95. package/dist/factory.js +334 -141
  96. package/dist/factory.js.map +1 -1
  97. package/dist/feed-events.d.ts +4 -4
  98. package/dist/feed-events.d.ts.map +1 -1
  99. package/dist/feed-events.js +6 -6
  100. package/dist/feed-events.js.map +1 -1
  101. package/dist/index.d.ts +10 -3
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js +7 -4
  104. package/dist/integrations/base.d.ts +12 -13
  105. package/dist/integrations/base.d.ts.map +1 -1
  106. package/dist/integrations/closing-references.d.ts +15 -0
  107. package/dist/integrations/closing-references.d.ts.map +1 -0
  108. package/dist/integrations/closing-references.js +69 -0
  109. package/dist/integrations/closing-references.js.map +1 -0
  110. package/dist/integrations/github/acceptance-labels.d.ts +4 -0
  111. package/dist/integrations/github/acceptance-labels.d.ts.map +1 -1
  112. package/dist/integrations/github/acceptance-labels.js +1 -1
  113. package/dist/integrations/github/acceptance-labels.js.map +1 -1
  114. package/dist/integrations/github/default-rules.d.ts +17 -75
  115. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  116. package/dist/integrations/github/default-rules.js +134 -77
  117. package/dist/integrations/github/default-rules.js.map +1 -1
  118. package/dist/integrations/github/integration.d.ts.map +1 -1
  119. package/dist/integrations/github/integration.js +7 -3
  120. package/dist/integrations/github/integration.js.map +1 -1
  121. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
  122. package/dist/integrations/github/issue-reconciler.js +21 -3
  123. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  124. package/dist/integrations/github/provenance.js +1 -1
  125. package/dist/integrations/github/provenance.js.map +1 -1
  126. package/dist/integrations/github/pull-request-source.d.ts +8 -0
  127. package/dist/integrations/github/pull-request-source.d.ts.map +1 -0
  128. package/dist/integrations/github/pull-request-source.js +17 -0
  129. package/dist/integrations/github/pull-request-source.js.map +1 -0
  130. package/dist/integrations/github/reconcile-worker.d.ts +5 -1
  131. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
  132. package/dist/integrations/github/reconcile-worker.js +39 -6
  133. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  134. package/dist/integrations/github/review-status-comment.d.ts +61 -0
  135. package/dist/integrations/github/review-status-comment.d.ts.map +1 -0
  136. package/dist/integrations/github/review-status-comment.js +217 -0
  137. package/dist/integrations/github/review-status-comment.js.map +1 -0
  138. package/dist/integrations/github/review-status-reporter.d.ts +42 -0
  139. package/dist/integrations/github/review-status-reporter.d.ts.map +1 -0
  140. package/dist/integrations/github/review-status-reporter.js +104 -0
  141. package/dist/integrations/github/review-status-reporter.js.map +1 -0
  142. package/dist/integrations/github/review-status.d.ts +28 -0
  143. package/dist/integrations/github/review-status.d.ts.map +1 -0
  144. package/dist/integrations/github/review-status.js +95 -0
  145. package/dist/integrations/github/review-status.js.map +1 -0
  146. package/dist/integrations/github/routes.d.ts +4 -3
  147. package/dist/integrations/github/routes.d.ts.map +1 -1
  148. package/dist/integrations/github/routes.js +11 -91
  149. package/dist/integrations/github/routes.js.map +1 -1
  150. package/dist/integrations/github/rules.d.ts +92 -8
  151. package/dist/integrations/github/rules.d.ts.map +1 -1
  152. package/dist/integrations/github/rules.js +498 -103
  153. package/dist/integrations/github/rules.js.map +1 -1
  154. package/dist/integrations/github/sandbox.d.ts +10 -2
  155. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  156. package/dist/integrations/github/sandbox.js +20 -4
  157. package/dist/integrations/github/sandbox.js.map +1 -1
  158. package/dist/integrations/github/session-subscriptions.js +2 -2
  159. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  160. package/dist/integrations/github/token-refresh.d.ts +2 -1
  161. package/dist/integrations/github/token-refresh.d.ts.map +1 -1
  162. package/dist/integrations/github/token-refresh.js.map +1 -1
  163. package/dist/integrations/gitlab/agent-tools.js +1 -1
  164. package/dist/integrations/gitlab/default-rules.d.ts +96 -39
  165. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  166. package/dist/integrations/gitlab/default-rules.js +109 -46
  167. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  168. package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -1
  169. package/dist/integrations/gitlab/issue-reconciler.js +2 -1
  170. package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
  171. package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
  172. package/dist/integrations/gitlab/merge-request-reconciler.js +12 -5
  173. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
  174. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  175. package/dist/integrations/gitlab/routes.js +2 -6
  176. package/dist/integrations/gitlab/routes.js.map +1 -1
  177. package/dist/integrations/gitlab/rules.d.ts +22 -1
  178. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  179. package/dist/integrations/gitlab/rules.js +188 -34
  180. package/dist/integrations/gitlab/rules.js.map +1 -1
  181. package/dist/integrations/gitlab/session-subscriptions.js +1 -1
  182. package/dist/integrations/incidentio/agent-tools.js +6 -6
  183. package/dist/integrations/incidentio/agent-tools.js.map +1 -1
  184. package/dist/integrations/incidentio/default-rules.d.ts +1 -9
  185. package/dist/integrations/incidentio/default-rules.d.ts.map +1 -1
  186. package/dist/integrations/incidentio/default-rules.js +6 -7
  187. package/dist/integrations/incidentio/default-rules.js.map +1 -1
  188. package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
  189. package/dist/integrations/incidentio/issue-reconciler.js +2 -1
  190. package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
  191. package/dist/integrations/incidentio/routes.d.ts +2 -2
  192. package/dist/integrations/incidentio/routes.d.ts.map +1 -1
  193. package/dist/integrations/incidentio/routes.js +11 -17
  194. package/dist/integrations/incidentio/routes.js.map +1 -1
  195. package/dist/integrations/incidentio/rules.d.ts +11 -4
  196. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  197. package/dist/integrations/incidentio/rules.js +52 -16
  198. package/dist/integrations/incidentio/rules.js.map +1 -1
  199. package/dist/integrations/issue-reconciler.js +1 -1
  200. package/dist/integrations/issue-reconciler.js.map +1 -1
  201. package/dist/integrations/jira/agent-tools.js +1 -1
  202. package/dist/integrations/jira/binding-scope.d.ts +5 -6
  203. package/dist/integrations/jira/binding-scope.d.ts.map +1 -1
  204. package/dist/integrations/jira/binding-scope.js +9 -11
  205. package/dist/integrations/jira/binding-scope.js.map +1 -1
  206. package/dist/integrations/jira/default-rules.d.ts +1 -9
  207. package/dist/integrations/jira/default-rules.d.ts.map +1 -1
  208. package/dist/integrations/jira/default-rules.js +6 -7
  209. package/dist/integrations/jira/default-rules.js.map +1 -1
  210. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
  211. package/dist/integrations/jira/issue-reconciler.js +2 -1
  212. package/dist/integrations/jira/issue-reconciler.js.map +1 -1
  213. package/dist/integrations/jira/routes.d.ts.map +1 -1
  214. package/dist/integrations/jira/routes.js +4 -9
  215. package/dist/integrations/jira/routes.js.map +1 -1
  216. package/dist/integrations/jira/rules.d.ts +11 -4
  217. package/dist/integrations/jira/rules.d.ts.map +1 -1
  218. package/dist/integrations/jira/rules.js +52 -16
  219. package/dist/integrations/jira/rules.js.map +1 -1
  220. package/dist/integrations/linear/agent-tools.d.ts +9 -1
  221. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  222. package/dist/integrations/linear/agent-tools.js +81 -3
  223. package/dist/integrations/linear/agent-tools.js.map +1 -1
  224. package/dist/integrations/linear/default-rules.d.ts +1 -9
  225. package/dist/integrations/linear/default-rules.d.ts.map +1 -1
  226. package/dist/integrations/linear/default-rules.js +6 -7
  227. package/dist/integrations/linear/default-rules.js.map +1 -1
  228. package/dist/integrations/linear/integration.d.ts +4 -1
  229. package/dist/integrations/linear/integration.d.ts.map +1 -1
  230. package/dist/integrations/linear/integration.js +21 -1
  231. package/dist/integrations/linear/integration.js.map +1 -1
  232. package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -1
  233. package/dist/integrations/linear/issue-reconciler.js +2 -1
  234. package/dist/integrations/linear/issue-reconciler.js.map +1 -1
  235. package/dist/integrations/linear/routes.d.ts +2 -1
  236. package/dist/integrations/linear/routes.d.ts.map +1 -1
  237. package/dist/integrations/linear/routes.js +16 -21
  238. package/dist/integrations/linear/routes.js.map +1 -1
  239. package/dist/integrations/linear/rules.d.ts +11 -4
  240. package/dist/integrations/linear/rules.d.ts.map +1 -1
  241. package/dist/integrations/linear/rules.js +50 -17
  242. package/dist/integrations/linear/rules.js.map +1 -1
  243. package/dist/integrations/platform/connect/routes.d.ts +7 -1
  244. package/dist/integrations/platform/connect/routes.d.ts.map +1 -1
  245. package/dist/integrations/platform/connect/routes.js +42 -5
  246. package/dist/integrations/platform/connect/routes.js.map +1 -1
  247. package/dist/integrations/platform/connect/session-tools.d.ts +12 -0
  248. package/dist/integrations/platform/connect/session-tools.d.ts.map +1 -0
  249. package/dist/integrations/platform/connect/session-tools.js +35 -0
  250. package/dist/integrations/platform/connect/session-tools.js.map +1 -0
  251. package/dist/integrations/platform/github/event-worker.d.ts +4 -1
  252. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  253. package/dist/integrations/platform/github/event-worker.js +39 -3
  254. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  255. package/dist/integrations/platform/github/integration.d.ts +8 -0
  256. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  257. package/dist/integrations/platform/github/integration.js +132 -90
  258. package/dist/integrations/platform/github/integration.js.map +1 -1
  259. package/dist/integrations/platform/jira/agent-tools.js +1 -1
  260. package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
  261. package/dist/integrations/platform/jira/routes.js +4 -9
  262. package/dist/integrations/platform/jira/routes.js.map +1 -1
  263. package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
  264. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
  265. package/dist/integrations/platform/linear/event-worker.js +10 -1
  266. package/dist/integrations/platform/linear/event-worker.js.map +1 -1
  267. package/dist/integrations/platform/linear/integration.d.ts +1 -1
  268. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  269. package/dist/integrations/platform/linear/integration.js +7 -8
  270. package/dist/integrations/platform/linear/integration.js.map +1 -1
  271. package/dist/integrations/slack/channel-reply-processor.d.ts +2 -0
  272. package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -1
  273. package/dist/integrations/slack/channel-reply-processor.js +6 -1
  274. package/dist/integrations/slack/channel-reply-processor.js.map +1 -1
  275. package/dist/integrations/slack/chat-tools.js +1 -1
  276. package/dist/integrations/slack/connect-route.d.ts.map +1 -1
  277. package/dist/integrations/slack/connect-route.js +1 -1
  278. package/dist/integrations/slack/connect-route.js.map +1 -1
  279. package/dist/integrations/slack/integration.d.ts +0 -2
  280. package/dist/integrations/slack/integration.d.ts.map +1 -1
  281. package/dist/integrations/slack/integration.js +2 -5
  282. package/dist/integrations/slack/integration.js.map +1 -1
  283. package/dist/integrations/slack/reply-tool.js +1 -1
  284. package/dist/integrations/slack/run-error-card.js +1 -0
  285. package/dist/integrations/slack/run-error-card.js.map +1 -1
  286. package/dist/integrations/slack/share-file-tool.js +1 -1
  287. package/dist/integrations/slack/slack.d.ts +23 -30
  288. package/dist/integrations/slack/slack.d.ts.map +1 -1
  289. package/dist/integrations/slack/slack.js +131 -125
  290. package/dist/integrations/slack/slack.js.map +1 -1
  291. package/dist/integrations/slack/voice-clips.d.ts +32 -0
  292. package/dist/integrations/slack/voice-clips.d.ts.map +1 -0
  293. package/dist/integrations/slack/voice-clips.js +201 -0
  294. package/dist/integrations/slack/voice-clips.js.map +1 -0
  295. package/dist/integrations/workos/integration.d.ts.map +1 -1
  296. package/dist/integrations/workos/integration.js +1 -3
  297. package/dist/integrations/workos/integration.js.map +1 -1
  298. package/dist/links.d.ts +1 -2
  299. package/dist/links.d.ts.map +1 -1
  300. package/dist/links.js +4 -4
  301. package/dist/links.js.map +1 -1
  302. package/dist/mcp/routes.js +2 -2
  303. package/dist/mcp/routes.js.map +1 -1
  304. package/dist/packages/_internals/workspace/dist/index.js +1 -1
  305. package/dist/provider-display-name.d.ts.map +1 -1
  306. package/dist/provider-display-name.js +1 -0
  307. package/dist/provider-display-name.js.map +1 -1
  308. package/dist/routes/attention-parked.d.ts +1 -0
  309. package/dist/routes/attention-parked.d.ts.map +1 -1
  310. package/dist/routes/attention-parked.js +2 -2
  311. package/dist/routes/attention-parked.js.map +1 -1
  312. package/dist/routes/attention-providers.d.ts +0 -25
  313. package/dist/routes/attention-providers.d.ts.map +1 -1
  314. package/dist/routes/attention-providers.js +3 -151
  315. package/dist/routes/attention-providers.js.map +1 -1
  316. package/dist/routes/attention.d.ts +0 -2
  317. package/dist/routes/attention.d.ts.map +1 -1
  318. package/dist/routes/attention.js +2 -13
  319. package/dist/routes/attention.js.map +1 -1
  320. package/dist/routes/automation-runs.d.ts +5 -1
  321. package/dist/routes/automation-runs.d.ts.map +1 -1
  322. package/dist/routes/automation-runs.js +16 -4
  323. package/dist/routes/automation-runs.js.map +1 -1
  324. package/dist/routes/board-snapshot.d.ts +15 -0
  325. package/dist/routes/board-snapshot.d.ts.map +1 -0
  326. package/dist/routes/board-snapshot.js +41 -0
  327. package/dist/routes/board-snapshot.js.map +1 -0
  328. package/dist/routes/boards.d.ts +9 -7
  329. package/dist/routes/boards.d.ts.map +1 -1
  330. package/dist/routes/boards.js +59 -145
  331. package/dist/routes/boards.js.map +1 -1
  332. package/dist/routes/config.d.ts +11 -1
  333. package/dist/routes/config.d.ts.map +1 -1
  334. package/dist/routes/config.js +122 -29
  335. package/dist/routes/config.js.map +1 -1
  336. package/dist/routes/contracts.d.ts +366 -34
  337. package/dist/routes/contracts.d.ts.map +1 -1
  338. package/dist/routes/contracts.js +179 -51
  339. package/dist/routes/contracts.js.map +1 -1
  340. package/dist/routes/feed-events.d.ts +15 -0
  341. package/dist/routes/feed-events.d.ts.map +1 -0
  342. package/dist/routes/feed-events.js +68 -0
  343. package/dist/routes/feed-events.js.map +1 -0
  344. package/dist/routes/fs.d.ts +4 -0
  345. package/dist/routes/fs.d.ts.map +1 -1
  346. package/dist/routes/fs.js +9 -8
  347. package/dist/routes/fs.js.map +1 -1
  348. package/dist/routes/intake-routes.d.ts.map +1 -1
  349. package/dist/routes/intake-routes.js +25 -13
  350. package/dist/routes/intake-routes.js.map +1 -1
  351. package/dist/routes/intake.d.ts +0 -23
  352. package/dist/routes/intake.d.ts.map +1 -1
  353. package/dist/routes/intake.js +16 -314
  354. package/dist/routes/intake.js.map +1 -1
  355. package/dist/routes/knowledge.d.ts.map +1 -1
  356. package/dist/routes/knowledge.js +2 -5
  357. package/dist/routes/knowledge.js.map +1 -1
  358. package/dist/routes/mastra-gateway.d.ts +19 -0
  359. package/dist/routes/mastra-gateway.d.ts.map +1 -0
  360. package/dist/routes/mastra-gateway.js +120 -0
  361. package/dist/routes/mastra-gateway.js.map +1 -0
  362. package/dist/routes/oauth.d.ts.map +1 -1
  363. package/dist/routes/oauth.js +1 -4
  364. package/dist/routes/oauth.js.map +1 -1
  365. package/dist/routes/projects.d.ts +3 -0
  366. package/dist/routes/projects.d.ts.map +1 -1
  367. package/dist/routes/projects.js +80 -61
  368. package/dist/routes/projects.js.map +1 -1
  369. package/dist/routes/provider-credentials.d.ts +6 -1
  370. package/dist/routes/provider-credentials.d.ts.map +1 -1
  371. package/dist/routes/provider-credentials.js +44 -3
  372. package/dist/routes/provider-credentials.js.map +1 -1
  373. package/dist/routes/route.d.ts +8 -0
  374. package/dist/routes/route.d.ts.map +1 -1
  375. package/dist/routes/route.js +5 -1
  376. package/dist/routes/route.js.map +1 -1
  377. package/dist/routes/running-packages.d.ts +13 -0
  378. package/dist/routes/running-packages.d.ts.map +1 -0
  379. package/dist/routes/running-packages.js +45 -0
  380. package/dist/routes/running-packages.js.map +1 -0
  381. package/dist/routes/sandbox-envs.d.ts +26 -0
  382. package/dist/routes/sandbox-envs.d.ts.map +1 -0
  383. package/dist/routes/sandbox-envs.js +180 -0
  384. package/dist/routes/sandbox-envs.js.map +1 -0
  385. package/dist/routes/session-access.d.ts.map +1 -1
  386. package/dist/routes/session-access.js +12 -3
  387. package/dist/routes/session-access.js.map +1 -1
  388. package/dist/routes/skills.d.ts.map +1 -1
  389. package/dist/routes/skills.js +1 -4
  390. package/dist/routes/skills.js.map +1 -1
  391. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  392. package/dist/routes/source-control-sessions.js +1 -3
  393. package/dist/routes/source-control-sessions.js.map +1 -1
  394. package/dist/routes/source-control-settings.d.ts.map +1 -1
  395. package/dist/routes/source-control-settings.js +3 -2
  396. package/dist/routes/source-control-settings.js.map +1 -1
  397. package/dist/routes/surface.d.ts +13 -9
  398. package/dist/routes/surface.d.ts.map +1 -1
  399. package/dist/routes/surface.js +116 -43
  400. package/dist/routes/surface.js.map +1 -1
  401. package/dist/routes/tenant-credentials.d.ts.map +1 -1
  402. package/dist/routes/tenant-credentials.js +5 -1
  403. package/dist/routes/tenant-credentials.js.map +1 -1
  404. package/dist/routes/voice.d.ts +48 -0
  405. package/dist/routes/voice.d.ts.map +1 -0
  406. package/dist/routes/voice.js +248 -0
  407. package/dist/routes/voice.js.map +1 -0
  408. package/dist/routes/work-items.d.ts +0 -3
  409. package/dist/routes/work-items.d.ts.map +1 -1
  410. package/dist/routes/work-items.js +39 -14
  411. package/dist/routes/work-items.js.map +1 -1
  412. package/dist/rules/binding-context.d.ts.map +1 -1
  413. package/dist/rules/binding-context.js +1 -0
  414. package/dist/rules/binding-context.js.map +1 -1
  415. package/dist/rules/decision-applicability.js +1 -1
  416. package/dist/rules/dispatcher.d.ts +28 -9
  417. package/dist/rules/dispatcher.d.ts.map +1 -1
  418. package/dist/rules/dispatcher.js +734 -143
  419. package/dist/rules/dispatcher.js.map +1 -1
  420. package/dist/rules/event-rules.d.ts +71 -1
  421. package/dist/rules/event-rules.d.ts.map +1 -1
  422. package/dist/rules/event-rules.js +94 -1
  423. package/dist/rules/event-rules.js.map +1 -1
  424. package/dist/rules/index.d.ts +2 -4
  425. package/dist/rules/index.d.ts.map +1 -1
  426. package/dist/rules/index.js +2 -3
  427. package/dist/rules/phase-goal.d.ts +54 -0
  428. package/dist/rules/phase-goal.d.ts.map +1 -0
  429. package/dist/rules/phase-goal.js +70 -0
  430. package/dist/rules/phase-goal.js.map +1 -0
  431. package/dist/rules/phase-tools.d.ts +11 -0
  432. package/dist/rules/phase-tools.d.ts.map +1 -0
  433. package/dist/rules/phase-tools.js +19 -0
  434. package/dist/rules/phase-tools.js.map +1 -0
  435. package/dist/rules/processor.d.ts.map +1 -1
  436. package/dist/rules/processor.js +116 -15
  437. package/dist/rules/processor.js.map +1 -1
  438. package/dist/rules/review-source-tool.d.ts +4 -1
  439. package/dist/rules/review-source-tool.d.ts.map +1 -1
  440. package/dist/rules/review-source-tool.js +24 -4
  441. package/dist/rules/review-source-tool.js.map +1 -1
  442. package/dist/rules/rule-group.d.ts +1 -1
  443. package/dist/rules/rule-group.d.ts.map +1 -1
  444. package/dist/rules/rule-group.js +15 -6
  445. package/dist/rules/rule-group.js.map +1 -1
  446. package/dist/rules/start-coordinator.d.ts +5 -1
  447. package/dist/rules/start-coordinator.d.ts.map +1 -1
  448. package/dist/rules/start-coordinator.js +9 -3
  449. package/dist/rules/start-coordinator.js.map +1 -1
  450. package/dist/rules/tools.d.ts.map +1 -1
  451. package/dist/rules/tools.js +39 -28
  452. package/dist/rules/tools.js.map +1 -1
  453. package/dist/rules/transition-service.d.ts +10 -7
  454. package/dist/rules/transition-service.d.ts.map +1 -1
  455. package/dist/rules/transition-service.js +63 -55
  456. package/dist/rules/transition-service.js.map +1 -1
  457. package/dist/rules/types.d.ts +140 -39
  458. package/dist/rules/types.d.ts.map +1 -1
  459. package/dist/rules/types.js +7 -41
  460. package/dist/rules/types.js.map +1 -1
  461. package/dist/rules/validation.d.ts.map +1 -1
  462. package/dist/rules/validation.js +89 -4
  463. package/dist/rules/validation.js.map +1 -1
  464. package/dist/run-error.d.ts +1 -1
  465. package/dist/run-error.d.ts.map +1 -1
  466. package/dist/run-error.js +38 -5
  467. package/dist/run-error.js.map +1 -1
  468. package/dist/sandbox/sandbox-env-cache.d.ts +33 -0
  469. package/dist/sandbox/sandbox-env-cache.d.ts.map +1 -0
  470. package/dist/sandbox/sandbox-env-cache.js +140 -0
  471. package/dist/sandbox/sandbox-env-cache.js.map +1 -0
  472. package/dist/sandbox/sandbox-env.d.ts +77 -0
  473. package/dist/sandbox/sandbox-env.d.ts.map +1 -0
  474. package/dist/sandbox/sandbox-env.js +130 -0
  475. package/dist/sandbox/sandbox-env.js.map +1 -0
  476. package/dist/secret-encryption.d.ts +21 -0
  477. package/dist/secret-encryption.d.ts.map +1 -1
  478. package/dist/secret-encryption.js +31 -4
  479. package/dist/secret-encryption.js.map +1 -1
  480. package/dist/session/credential-policy.d.ts +2 -2
  481. package/dist/session/credential-policy.d.ts.map +1 -1
  482. package/dist/session/credential-policy.js +3 -3
  483. package/dist/session/credential-policy.js.map +1 -1
  484. package/dist/session/default-model-hydration.d.ts +2 -2
  485. package/dist/session/default-model-hydration.d.ts.map +1 -1
  486. package/dist/session/default-model-hydration.js +4 -4
  487. package/dist/session/default-model-hydration.js.map +1 -1
  488. package/dist/session/live-sessions.d.ts +11 -4
  489. package/dist/session/live-sessions.d.ts.map +1 -1
  490. package/dist/session/live-sessions.js +31 -10
  491. package/dist/session/live-sessions.js.map +1 -1
  492. package/dist/session/self-review-gate.d.ts +6 -4
  493. package/dist/session/self-review-gate.d.ts.map +1 -1
  494. package/dist/session/self-review-gate.js +9 -12
  495. package/dist/session/self-review-gate.js.map +1 -1
  496. package/dist/session/session-threads.d.ts +10 -3
  497. package/dist/session/session-threads.d.ts.map +1 -1
  498. package/dist/session/session-threads.js +11 -1
  499. package/dist/session/session-threads.js.map +1 -1
  500. package/dist/session/source-control-tools.d.ts +39 -13
  501. package/dist/session/source-control-tools.d.ts.map +1 -1
  502. package/dist/session/source-control-tools.js +55 -61
  503. package/dist/session/source-control-tools.js.map +1 -1
  504. package/dist/session/work-item-state-processor.d.ts +24 -0
  505. package/dist/session/work-item-state-processor.d.ts.map +1 -0
  506. package/dist/session/work-item-state-processor.js +275 -0
  507. package/dist/session/work-item-state-processor.js.map +1 -0
  508. package/dist/skills/catalog.js +1 -1
  509. package/dist/storage/domains/audit/actions.d.ts +3 -2
  510. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  511. package/dist/storage/domains/audit/actions.js +7 -5
  512. package/dist/storage/domains/audit/actions.js.map +1 -1
  513. package/dist/storage/domains/audit/domain.d.ts.map +1 -1
  514. package/dist/storage/domains/audit/domain.js +1 -3
  515. package/dist/storage/domains/audit/domain.js.map +1 -1
  516. package/dist/storage/domains/boards/base.d.ts +107 -23
  517. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  518. package/dist/storage/domains/boards/base.js +201 -65
  519. package/dist/storage/domains/boards/base.js.map +1 -1
  520. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  521. package/dist/storage/domains/boards/schemas.js +25 -1
  522. package/dist/storage/domains/boards/schemas.js.map +1 -1
  523. package/dist/storage/domains/channel-identity/base.d.ts +0 -4
  524. package/dist/storage/domains/channel-identity/base.d.ts.map +1 -1
  525. package/dist/storage/domains/channel-identity/base.js +0 -7
  526. package/dist/storage/domains/channel-identity/base.js.map +1 -1
  527. package/dist/storage/domains/intake/base.d.ts +5 -45
  528. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  529. package/dist/storage/domains/intake/base.js +11 -89
  530. package/dist/storage/domains/intake/base.js.map +1 -1
  531. package/dist/storage/domains/memory-settings/base.d.ts +0 -8
  532. package/dist/storage/domains/memory-settings/base.d.ts.map +1 -1
  533. package/dist/storage/domains/memory-settings/base.js +1 -11
  534. package/dist/storage/domains/memory-settings/base.js.map +1 -1
  535. package/dist/storage/domains/projects/base.d.ts +23 -9
  536. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  537. package/dist/storage/domains/projects/base.js +24 -8
  538. package/dist/storage/domains/projects/base.js.map +1 -1
  539. package/dist/storage/domains/sandbox-envs/base.d.ts +70 -0
  540. package/dist/storage/domains/sandbox-envs/base.d.ts.map +1 -0
  541. package/dist/storage/domains/sandbox-envs/base.js +227 -0
  542. package/dist/storage/domains/sandbox-envs/base.js.map +1 -0
  543. package/dist/storage/domains/voice-settings/base.d.ts +31 -0
  544. package/dist/storage/domains/voice-settings/base.d.ts.map +1 -0
  545. package/dist/storage/domains/voice-settings/base.js +81 -0
  546. package/dist/storage/domains/voice-settings/base.js.map +1 -0
  547. package/dist/storage/domains/work-items/base.d.ts +93 -24
  548. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  549. package/dist/storage/domains/work-items/base.js +413 -188
  550. package/dist/storage/domains/work-items/base.js.map +1 -1
  551. package/dist/storage/domains/work-items/board-version.d.ts +6 -2
  552. package/dist/storage/domains/work-items/board-version.d.ts.map +1 -1
  553. package/dist/storage/domains/work-items/board-version.js +20 -9
  554. package/dist/storage/domains/work-items/board-version.js.map +1 -1
  555. package/dist/storage/domains/work-items/cards.d.ts +33 -5
  556. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  557. package/dist/storage/domains/work-items/cards.js +208 -25
  558. package/dist/storage/domains/work-items/cards.js.map +1 -1
  559. package/dist/storage/domains/work-items/legacy-review.d.ts +63 -0
  560. package/dist/storage/domains/work-items/legacy-review.d.ts.map +1 -0
  561. package/dist/storage/domains/work-items/legacy-review.js +109 -0
  562. package/dist/storage/domains/work-items/legacy-review.js.map +1 -0
  563. package/dist/storage/domains/work-items/metrics.d.ts +12 -4
  564. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
  565. package/dist/storage/domains/work-items/metrics.js +14 -32
  566. package/dist/storage/domains/work-items/metrics.js.map +1 -1
  567. package/dist/storage/domains/work-items/work-item-schema.d.ts +6 -2
  568. package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
  569. package/dist/storage/domains/work-items/work-item-schema.js +83 -27
  570. package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
  571. package/dist/timing.d.ts +1 -0
  572. package/dist/timing.d.ts.map +1 -1
  573. package/dist/timing.js +1 -1
  574. package/dist/timing.js.map +1 -1
  575. package/dist/tools/approval-tools.d.ts.map +1 -1
  576. package/dist/tools/approval-tools.js +28 -9
  577. package/dist/tools/approval-tools.js.map +1 -1
  578. package/dist/tools/index.d.ts +1 -1
  579. package/dist/tools/index.js +1 -1
  580. package/dist/tools/index.js.map +1 -1
  581. package/dist/tools/messaging-tools.d.ts +3 -0
  582. package/dist/tools/messaging-tools.d.ts.map +1 -1
  583. package/dist/tools/messaging-tools.js +2 -1
  584. package/dist/tools/messaging-tools.js.map +1 -1
  585. package/dist/tools/read-tools.d.ts +10 -6
  586. package/dist/tools/read-tools.d.ts.map +1 -1
  587. package/dist/tools/read-tools.js +89 -39
  588. package/dist/tools/read-tools.js.map +1 -1
  589. package/dist/tools/reports.d.ts +1 -0
  590. package/dist/tools/reports.d.ts.map +1 -1
  591. package/dist/tools/reports.js +2 -1
  592. package/dist/tools/reports.js.map +1 -1
  593. package/dist/tools/run-watch.d.ts +1 -1
  594. package/dist/tools/run-watch.d.ts.map +1 -1
  595. package/dist/tools/run-watch.js +1 -0
  596. package/dist/tools/run-watch.js.map +1 -1
  597. package/dist/tools/sandbox-tools.js +1 -1
  598. package/dist/tools/session-tools.d.ts +1 -1
  599. package/dist/tools/session-tools.d.ts.map +1 -1
  600. package/dist/tools/session-tools.js +1 -1
  601. package/dist/tools/session-tools.js.map +1 -1
  602. package/dist/tools/sessions-state-processor.d.ts +3 -1
  603. package/dist/tools/sessions-state-processor.d.ts.map +1 -1
  604. package/dist/tools/sessions-state-processor.js +13 -4
  605. package/dist/tools/sessions-state-processor.js.map +1 -1
  606. package/dist/tools/side-sessions.d.ts +2 -0
  607. package/dist/tools/side-sessions.d.ts.map +1 -1
  608. package/dist/tools/side-sessions.js +2 -1
  609. package/dist/tools/side-sessions.js.map +1 -1
  610. package/dist/tools/work-item-tools.d.ts +0 -3
  611. package/dist/tools/work-item-tools.d.ts.map +1 -1
  612. package/dist/tools/work-item-tools.js +10 -20
  613. package/dist/tools/work-item-tools.js.map +1 -1
  614. package/dist/voice/rate-limit.d.ts +13 -0
  615. package/dist/voice/rate-limit.d.ts.map +1 -0
  616. package/dist/voice/rate-limit.js +36 -0
  617. package/dist/voice/rate-limit.js.map +1 -0
  618. package/dist/voice/realtime.d.ts +13 -0
  619. package/dist/voice/realtime.d.ts.map +1 -0
  620. package/dist/voice/realtime.js +56 -0
  621. package/dist/voice/realtime.js.map +1 -0
  622. package/dist/voice/transcription.d.ts +51 -0
  623. package/dist/voice/transcription.d.ts.map +1 -0
  624. package/dist/voice/transcription.js +112 -0
  625. package/dist/voice/transcription.js.map +1 -0
  626. package/dist/work-item-branch.d.ts +13 -0
  627. package/dist/work-item-branch.d.ts.map +1 -1
  628. package/dist/work-item-branch.js +16 -1
  629. package/dist/work-item-branch.js.map +1 -1
  630. package/dist/work-items/create-work-item.d.ts +6 -0
  631. package/dist/work-items/create-work-item.d.ts.map +1 -1
  632. package/dist/work-items/create-work-item.js +28 -3
  633. package/dist/work-items/create-work-item.js.map +1 -1
  634. package/dist/work-items/description-context.d.ts +5 -0
  635. package/dist/work-items/description-context.d.ts.map +1 -0
  636. package/dist/work-items/description-context.js +17 -0
  637. package/dist/work-items/description-context.js.map +1 -0
  638. package/dist/work-items/providers/base.d.ts +4 -1
  639. package/dist/work-items/providers/base.d.ts.map +1 -1
  640. package/dist/work-items/providers/base.js +6 -1
  641. package/dist/work-items/providers/base.js.map +1 -1
  642. package/dist/work-items/providers/github.d.ts.map +1 -1
  643. package/dist/work-items/providers/github.js +2 -1
  644. package/dist/work-items/providers/github.js.map +1 -1
  645. package/dist/work-items/providers/gitlab.d.ts.map +1 -1
  646. package/dist/work-items/providers/gitlab.js +2 -1
  647. package/dist/work-items/providers/gitlab.js.map +1 -1
  648. package/dist/work-items/providers/jira.d.ts.map +1 -1
  649. package/dist/work-items/providers/jira.js +3 -2
  650. package/dist/work-items/providers/jira.js.map +1 -1
  651. package/dist/work-items/providers/linear.d.ts.map +1 -1
  652. package/dist/work-items/providers/linear.js +3 -2
  653. package/dist/work-items/providers/linear.js.map +1 -1
  654. package/dist/work-items/providers/types.d.ts +6 -0
  655. package/dist/work-items/providers/types.d.ts.map +1 -1
  656. package/dist/work-items/split-backfill.d.ts +13 -0
  657. package/dist/work-items/split-backfill.d.ts.map +1 -0
  658. package/dist/work-items/split-backfill.js +32 -0
  659. package/dist/work-items/split-backfill.js.map +1 -0
  660. package/dist/work-items/split-migration.d.ts +39 -2
  661. package/dist/work-items/split-migration.d.ts.map +1 -1
  662. package/dist/work-items/split-migration.js +178 -70
  663. package/dist/work-items/split-migration.js.map +1 -1
  664. package/dist/workspace.d.ts +3 -1
  665. package/dist/workspace.d.ts.map +1 -1
  666. package/dist/workspace.js +118 -34
  667. package/dist/workspace.js.map +1 -1
  668. package/factory-skills/configure-factory-rules/SKILL.md +13 -11
  669. package/factory-skills/factory-build/SKILL.md +64 -0
  670. package/factory-skills/factory-gitlab-rereview/SKILL.md +4 -4
  671. package/factory-skills/factory-gitlab-review/SKILL.md +6 -6
  672. package/factory-skills/factory-plan/SKILL.md +8 -10
  673. package/factory-skills/factory-rereview/SKILL.md +74 -28
  674. package/factory-skills/factory-review/SKILL.md +85 -29
  675. package/factory-skills/factory-self-review/SKILL.md +32 -13
  676. package/factory-skills/factory-triage/SKILL.md +36 -32
  677. package/package.json +12 -11
  678. package/dist/boards/index.js.map +0 -1
  679. package/dist/boards/pull-request-review.d.ts +0 -14
  680. package/dist/boards/pull-request-review.d.ts.map +0 -1
  681. package/dist/boards/pull-request-review.js +0 -81
  682. package/dist/boards/pull-request-review.js.map +0 -1
  683. package/dist/boards/work-tool-rules.d.ts +0 -8
  684. package/dist/boards/work-tool-rules.d.ts.map +0 -1
  685. package/dist/boards/work-tool-rules.js +0 -19
  686. package/dist/boards/work-tool-rules.js.map +0 -1
  687. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts +0 -8
  688. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts.map +0 -1
  689. package/dist/integrations/slack/emoji-shortcodes.generated.js +0 -1984
  690. package/dist/integrations/slack/emoji-shortcodes.generated.js.map +0 -1
  691. package/dist/integrations/slack/emoji.d.ts +0 -3
  692. package/dist/integrations/slack/emoji.d.ts.map +0 -1
  693. package/dist/integrations/slack/emoji.js +0 -11
  694. package/dist/integrations/slack/emoji.js.map +0 -1
  695. package/dist/integrations/slack/feed-publisher.d.ts +0 -26
  696. package/dist/integrations/slack/feed-publisher.d.ts.map +0 -1
  697. package/dist/integrations/slack/feed-publisher.js +0 -43
  698. package/dist/integrations/slack/feed-publisher.js.map +0 -1
  699. package/dist/routes/attention-activity.d.ts +0 -23
  700. package/dist/routes/attention-activity.d.ts.map +0 -1
  701. package/dist/routes/attention-activity.js +0 -154
  702. package/dist/routes/attention-activity.js.map +0 -1
  703. package/dist/rules/resolve.d.ts +0 -15
  704. package/dist/rules/resolve.d.ts.map +0 -1
  705. package/dist/rules/resolve.js +0 -22
  706. package/dist/rules/resolve.js.map +0 -1
  707. package/dist/storage/domains/comments/activity.d.ts +0 -40
  708. package/dist/storage/domains/comments/activity.d.ts.map +0 -1
  709. package/dist/storage/domains/comments/activity.js +0 -93
  710. package/dist/storage/domains/comments/activity.js.map +0 -1
  711. package/dist/storage/domains/comments/actor.d.ts +0 -51
  712. package/dist/storage/domains/comments/actor.d.ts.map +0 -1
  713. package/dist/storage/domains/comments/actor.js +0 -37
  714. package/dist/storage/domains/comments/actor.js.map +0 -1
  715. package/dist/storage/domains/comments/base.d.ts +0 -245
  716. package/dist/storage/domains/comments/base.d.ts.map +0 -1
  717. package/dist/storage/domains/comments/base.js +0 -539
  718. package/dist/storage/domains/comments/base.js.map +0 -1
  719. package/dist/storage/domains/comments/domain.d.ts +0 -135
  720. package/dist/storage/domains/comments/domain.d.ts.map +0 -1
  721. package/dist/storage/domains/comments/domain.js +0 -284
  722. package/dist/storage/domains/comments/domain.js.map +0 -1
  723. package/dist/storage/domains/comments/feed-context.d.ts +0 -22
  724. package/dist/storage/domains/comments/feed-context.d.ts.map +0 -1
  725. package/dist/storage/domains/comments/feed-context.js +0 -88
  726. package/dist/storage/domains/comments/feed-context.js.map +0 -1
  727. package/dist/storage/domains/comments/feed-sync.d.ts +0 -21
  728. package/dist/storage/domains/comments/feed-sync.d.ts.map +0 -1
  729. package/dist/storage/domains/comments/feed-sync.js +0 -1
  730. package/dist/storage/domains/comments/parse.d.ts +0 -23
  731. package/dist/storage/domains/comments/parse.d.ts.map +0 -1
  732. package/dist/storage/domains/comments/parse.js +0 -89
  733. package/dist/storage/domains/comments/parse.js.map +0 -1
  734. package/dist/storage/domains/comments/routes.d.ts +0 -24
  735. package/dist/storage/domains/comments/routes.d.ts.map +0 -1
  736. package/dist/storage/domains/comments/routes.js +0 -301
  737. package/dist/storage/domains/comments/routes.js.map +0 -1
  738. package/dist/storage/domains/comments/schema.d.ts +0 -5
  739. package/dist/storage/domains/comments/schema.d.ts.map +0 -1
  740. package/dist/storage/domains/comments/schema.js +0 -178
  741. package/dist/storage/domains/comments/schema.js.map +0 -1
  742. package/dist/storage/domains/comments/wire.d.ts +0 -40
  743. package/dist/storage/domains/comments/wire.d.ts.map +0 -1
  744. package/dist/storage/domains/comments/wire.js +0 -36
  745. package/dist/storage/domains/comments/wire.js.map +0 -1
  746. package/factory-skills/factory-complete-issue/SKILL.md +0 -24
@@ -1,24 +1,30 @@
1
+ import { eventMovesCard, isPullRequestEvent } from "../boards/board-events.js";
1
2
  import "../boards/index.js";
2
- import { INTAKE_ROUTE_METADATA_KEY, landingPhase, placedByIntakeRoute, resolveIntakePlacement } from "../boards/intake-routing.js";
3
+ import { INTAKE_ROUTE_METADATA_KEY, closedIssueRuleFacts, landingPhase, placedByIntakeRoute, resolveEventRoute, resolveIntakePlacement, resolveIntakeRoute, routesHandleEvent } from "../boards/intake-routing.js";
4
+ import "../boards/define-board.js";
5
+ import { boardFlow, boardForWorkItem, cardBoardFlow, hasPullRequest, intakeTarget, isPullRequestCard, isTerminalWorkItem, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
3
6
  import { autoApprovedExitTool, startsInAutoPhase } from "../boards/phase-automation.js";
4
7
  import { toBoardSource } from "../boards/project-boards.js";
5
8
  import { moveCardToBoard } from "../boards/relocate.js";
6
9
  import { cardRuleFacts } from "../boards/card-facts.js";
7
- import { boardForWorkItem, isPullRequestCard, isTerminalWorkItem, pullRequestReviewPhase, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
8
10
  import { FACTORY_OPEN_RUN_STALE_MS, heartbeatSessionOpenRun, isOpenRunLiveElsewhere, listSessionOpenRuns, recordSessionRunStart, waitForSessionRunAudit } from "../session/run-audit.js";
9
11
  import { resolvePromptInvocation, resolveSkillInvocation, resolveSkillResumeInvocation } from "../skills/service.js";
10
12
  import { isHumanActorId } from "../storage/domains/audit/actors.js";
11
- import { withWorkItemFeed } from "../storage/domains/comments/feed-context.js";
12
- import { FACTORY_RULE_MATERIALIZATION_KEY } from "../storage/domains/work-items/base.js";
13
+ import { FACTORY_RULE_MATERIALIZATION_KEY, WorkItemSourceConflictError, WorkItemUpdateConflictError, externalSourceKey } from "../storage/domains/work-items/base.js";
14
+ import { withWorkItemDescription } from "../work-items/description-context.js";
13
15
  import { workItemProviderAdapter } from "../work-items/providers/index.js";
14
16
  import { decisionOvertaken } from "./decision-applicability.js";
15
17
  import { FactoryDispatchError, factoryDispatchFailureCode, factoryDispatchFailureMetadata } from "./dispatch-errors.js";
16
- import { FACTORY_RULE_STAGES, externalSourceForWorkItem, workItemSource } from "./types.js";
18
+ import { isStatusEventDecision } from "./event-rules.js";
19
+ import { PHASE_GOAL_METADATA_KEY, endPhaseGoal, phaseGoalOf, startPhaseGoal } from "./phase-goal.js";
20
+ import { authorTrusted, externalSourceForWorkItem, workItemSource } from "./types.js";
17
21
  import { assertFactoryDecisionTarget, validateFactoryRuleDecision } from "./validation.js";
18
22
  import { RequestContext } from "@mastra/core/request-context";
19
23
  import { PROVIDER_CALL_ERROR_NAME, classifyProviderError } from "@mastra/core/error";
20
24
  // src/rules/dispatcher.ts
21
25
  const LEASE_MS = 3e4;
26
+ /** How long the run waits on a status-comment write; well inside one lease so a slow provider never costs the claim. */
27
+ const REVIEW_STATUS_TIMEOUT_MS = 1e4;
22
28
  const POLL_MS = 1e3;
23
29
  const IDLE_RECHECK_MS = 36e5;
24
30
  const BATCH_SIZE = 10;
@@ -30,11 +36,12 @@ const RUN_REGISTRY_HEARTBEAT_MS = 6e5;
30
36
  const SKILL_COMPLETION_OBSERVATION_TIMEOUT_MS = 216e5;
31
37
  const MAX_IN_FLIGHT = 25;
32
38
  /**
33
- * Decisions that may start or wake an agent run and so hold a run slot. A
34
- * transition's message is queued as a separate sendMessage, so the transition
35
- * itself stays bookkeeping.
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.
36
43
  */
37
- const isRunBearingDecision = (decision) => decision.type === "invokeSkill" || decision.type === "sendMessage";
44
+ const isRunBearingDecision = (decision) => decision.type === "invokeSkill" || decision.type === "sendMessage" || decision.type === "signalActivity";
38
45
  const isBookkeepingDecision = (decision) => !isRunBearingDecision(decision);
39
46
  const BOOKKEEPING_MAX_IN_FLIGHT = 4;
40
47
  const STALE_BINDING_SWEEP_INTERVAL_MS = 6e5;
@@ -42,6 +49,9 @@ const STALE_BINDING_TTL_MS = 864e5;
42
49
  const RECONCILE_INTERVAL_MS = 3e4;
43
50
  /** The card moved on before this run could act; it settles as superseded, not succeeded. */
44
51
  var FactoryDecisionSuperseded = class extends Error {};
52
+ /** 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 {};
54
+ const POSTPONE_MS = 1e4;
45
55
  /** A run that ran and ended in error; the session's own listener reports it to followers. */
46
56
  var RunEndedInError = class extends FactoryDispatchError {};
47
57
  const CREDENTIAL_RESOLUTION_FAILURE = "tenant model credential policy could not be resolved";
@@ -71,6 +81,12 @@ function runErrorFailure(label, error) {
71
81
  if (!cause) return new RunEndedInError("run_failed", `${label} ended in error.`);
72
82
  return new RunEndedInError(runErrorCode(error, cause), `${label} ended in error: ${cause}`);
73
83
  }
84
+ /** A run in the review seat: a pull request review, unless it is the card's board's self-review. */
85
+ function reviewSeatSkill(decision) {
86
+ if (!decision || typeof decision !== "object") return void 0;
87
+ const value = decision;
88
+ return value.type === "invokeSkill" && value.role === "review" ? value : void 0;
89
+ }
74
90
  function isTerminalFailure(attempts, failureCode) {
75
91
  return attempts >= MAX_ATTEMPTS || !factoryDispatchFailureMetadata(failureCode).canRetry;
76
92
  }
@@ -85,7 +101,7 @@ function isPermanentProviderRejection(error) {
85
101
  const normalized = error.toLowerCase();
86
102
  return /\bhttp(?:\/\d(?:\.\d)?)?\s*400\b/.test(normalized) || /\bstatus(?:\s*code)?\s*[:=]?\s*400\b/.test(normalized) || /\b400\s*(?:bad request|status)\b/.test(normalized) || normalized.includes("model not supported") || normalized.includes("model is not supported") || normalized.includes("unsupported model") || normalized.includes("not supported with") || normalized.includes("unauthorized") || normalized.includes("authentication") || normalized.includes("invalid") && normalized.includes("model");
87
103
  }
88
- function watchRun(session, { timeoutMs, approvePlans, onAgentEnd, label, runStillActive }) {
104
+ function watchRun(session, { timeoutMs, approvePlans, requestContext, onAgentEnd, label, runStillActive }) {
89
105
  let resolveAgentEnd;
90
106
  let agentEnd;
91
107
  let endReason;
@@ -153,7 +169,8 @@ function watchRun(session, { timeoutMs, approvePlans, onAgentEnd, label, runStil
153
169
  arm();
154
170
  await session.respondToToolSuspension({
155
171
  resumeData: { action: "approved" },
156
- toolCallId
172
+ toolCallId,
173
+ requestContext
157
174
  });
158
175
  observed = await wait();
159
176
  }
@@ -253,12 +270,18 @@ function requestsConsent(boards, record, decision) {
253
270
  if (decision.type !== "transition" || !externalActor(record.actor)) return false;
254
271
  return (resolvePhaseSemantics(boards, decision.board, decision.stage)?.kind ?? "working") === "working";
255
272
  }
256
- function reviewsFactoryAuthoredCode(item, decision) {
273
+ function reviewsFactoryAuthoredCode(boards, item, decision) {
257
274
  if (item.metadata?.factoryAuthored !== true) return false;
258
- if (decision.type === "transition") return decision.stage === pullRequestReviewPhase(decision.board) && reviewsPullRequest({
259
- board: decision.board,
260
- item: { source: workItemSource(item.externalSource) }
261
- });
275
+ if (decision.type === "transition") {
276
+ const flow = boardFlow(boards.get(decision.board));
277
+ return decision.stage === flow.pullRequestReview && reviewsPullRequest({
278
+ flow,
279
+ item: {
280
+ source: workItemSource(item.externalSource),
281
+ workItem: item.workItem
282
+ }
283
+ });
284
+ }
262
285
  return decision.type === "invokeSkill" && decision.role === "review";
263
286
  }
264
287
  function leaseIdentity(record, ownerId) {
@@ -298,13 +321,24 @@ var FactoryDecisionDispatcher = class {
298
321
  #intakeRoutes;
299
322
  #storage;
300
323
  #ownerId;
301
- #isAutoRunEnabled;
302
324
  #reconcileToolResults;
303
325
  #prepareBinding;
304
326
  #primeCredentials;
305
327
  #reportRunEnd;
306
- #feedReader;
307
328
  #dismissStaleReviews;
329
+ #reportReviewStatus;
330
+ /** Review attempts that already said `queued`, and those that watched their run start. */
331
+ #reviewQueued = /* @__PURE__ */ new WeakSet();
332
+ #reviewWatched = /* @__PURE__ */ new WeakSet();
333
+ /** Re-claims that found an earlier attempt's kickoff landed and its run already over. */
334
+ #reviewReplayed = /* @__PURE__ */ new WeakSet();
335
+ /** Last pending status-comment write per run, so writes stay ordered. */
336
+ /**
337
+ * Per review run: the write chain, the newest step issued, and how many
338
+ * writes were issued and how far the landed ones reach, so a write that
339
+ * outlived its wait and landed after a newer one can be repaired.
340
+ */
341
+ #reviewStatusRuns = /* @__PURE__ */ new Map();
308
342
  #resolveLinkedWorkItemParentId;
309
343
  #factoryProjectExists;
310
344
  #maxInFlight;
@@ -340,13 +374,12 @@ var FactoryDecisionDispatcher = class {
340
374
  this.#intakeRoutes = options.intakeRoutes;
341
375
  this.#storage = options.storage;
342
376
  this.#ownerId = options.ownerId ?? `factory-dispatcher:${globalThis.crypto.randomUUID()}`;
343
- this.#isAutoRunEnabled = options.isAutoRunEnabled;
344
377
  this.#reconcileToolResults = options.reconcileToolResults;
345
378
  this.#prepareBinding = options.prepareBinding;
346
379
  this.#primeCredentials = options.primeCredentials;
347
380
  this.#reportRunEnd = options.reportRunEnd;
348
- this.#feedReader = options.feedReader;
349
381
  this.#dismissStaleReviews = options.dismissStaleReviews;
382
+ this.#reportReviewStatus = options.reportReviewStatus;
350
383
  this.#resolveLinkedWorkItemParentId = options.resolveLinkedWorkItemParentId;
351
384
  this.#factoryProjectExists = options.factoryProjectExists;
352
385
  const maxInFlight = options.maxInFlight ?? MAX_IN_FLIGHT;
@@ -576,12 +609,26 @@ var FactoryDecisionDispatcher = class {
576
609
  return;
577
610
  }
578
611
  await this.#supersedeProposals(record, decision);
612
+ if (record.attempts <= 1) await this.#reviewQueuedOnce(record, decision);
579
613
  await this.#withLease(async (leaseExpiresAt) => this.#storage.renewDeferredDecisionLease(leaseIdentity(record, this.#ownerId), leaseExpiresAt), async () => this.#executeDecision(record, decision));
580
614
  executionCompleted = true;
581
615
  if (!await this.#storage.completeDeferredDecision(leaseIdentity(record, this.#ownerId), /* @__PURE__ */ new Date())) throw new Error("Factory decision lease was lost before completion.");
616
+ if (this.#reviewWatched.has(record) || this.#reviewReplayed.has(record)) await this.#reviewStatus(record, decision, {
617
+ phase: "completed",
618
+ endedAt: /* @__PURE__ */ new Date(),
619
+ ...this.#reviewReplayed.has(record) ? { replayed: true } : {}
620
+ });
582
621
  } catch (error) {
583
622
  if (error instanceof FactoryDecisionSuperseded) {
584
623
  await this.#storage.supersedeLeasedDecision(leaseIdentity(record, this.#ownerId), /* @__PURE__ */ new Date());
624
+ await this.#reviewStatus(record, record.decision, {
625
+ phase: "cancelled",
626
+ endedAt: /* @__PURE__ */ new Date()
627
+ });
628
+ return;
629
+ }
630
+ if (error instanceof FactoryDecisionPostponed) {
631
+ await this.#storage.postponeDeferredDecision(leaseIdentity(record, this.#ownerId), new Date(now.getTime() + POSTPONE_MS), /* @__PURE__ */ new Date());
585
632
  return;
586
633
  }
587
634
  const failureCode = factoryDispatchFailureCode(error);
@@ -596,6 +643,198 @@ var FactoryDecisionDispatcher = class {
596
643
  advanceDeliveryGeneration: !executionCompleted
597
644
  });
598
645
  if (terminal && failed) await this.#supersedeFailureOnSettledCard(failed);
646
+ if (terminal || this.#reviewQueued.has(record)) await this.#reviewStatus(failed ?? record, record.decision, {
647
+ phase: terminal ? "failed" : "retrying",
648
+ endedAt: /* @__PURE__ */ new Date(),
649
+ reason: factoryDispatchFailureMetadata(failureCode).label
650
+ });
651
+ }
652
+ }
653
+ /**
654
+ * An earlier attempt's kickoff already landed, so this attempt only has to
655
+ * see that run end before a review's status can be finalized. The open-run
656
+ * wait covers runs in the ledger; a run that landed but died before
657
+ * registering there can still be live in this process, so wait it out too.
658
+ */
659
+ async #replayLanded(record, decision, session, runStillActive) {
660
+ if (!await this.#isReviewRun(record, decision)) return;
661
+ if (runStillActive()) {
662
+ const run = watchRun(session, {
663
+ timeoutMs: this.#skillCompletionObservationTimeoutMs,
664
+ approvePlans: false,
665
+ label: "Factory skill run",
666
+ runStillActive
667
+ });
668
+ try {
669
+ if (runStillActive()) await run.wait();
670
+ } finally {
671
+ run.close();
672
+ }
673
+ }
674
+ this.#reviewReplayed.add(record);
675
+ }
676
+ /**
677
+ * Holds the goal a phase's run pursues on the session's thread, and names it on the card so
678
+ * leaving the phase ends it. Keyed on the decision: a retry finds the goal already held.
679
+ */
680
+ async #setPhaseGoal(record, goal, session, binding) {
681
+ const item = record.workItemId ? await this.#storage.get({
682
+ orgId: record.orgId,
683
+ id: record.workItemId
684
+ }) : null;
685
+ const phaseKey = item?.stages.length === 1 ? item.stages[0] : void 0;
686
+ const objective = await startPhaseGoal(session.machinery.getAgent(), {
687
+ threadId: binding.threadId,
688
+ resourceId: binding.resourceId,
689
+ goalId: record.id,
690
+ objective: goal.objective,
691
+ maxRuns: goal.maxRuns,
692
+ judgeModelId: session.model.get() || void 0
693
+ });
694
+ if (!objective) throw new FactoryDispatchError("run_configuration_invalid", "The Factory session has no storage to hold a goal.");
695
+ if (!item || !phaseKey) return objective;
696
+ const stamp = {
697
+ phaseKey,
698
+ goalId: record.id,
699
+ threadId: binding.threadId,
700
+ sessionId: binding.sessionId
701
+ };
702
+ if (phaseGoalOf(item.metadata)?.goalId !== record.id) await this.#storage.update({
703
+ orgId: record.orgId,
704
+ id: item.id,
705
+ userId: "factory",
706
+ patch: { metadata: { [PHASE_GOAL_METADATA_KEY]: stamp } }
707
+ });
708
+ const after = await this.#storage.get({
709
+ orgId: record.orgId,
710
+ id: item.id
711
+ });
712
+ if (after?.stages.length !== 1 || after.stages[0] !== phaseKey) {
713
+ await endPhaseGoal(stamp, {
714
+ agentFor: async () => session.machinery.getAgent(),
715
+ store: async () => void 0
716
+ });
717
+ throw new FactoryDecisionSuperseded();
718
+ }
719
+ return objective;
720
+ }
721
+ /**
722
+ * Shows the goal in the thread once its run has the kickoff. A goal whose reminder never landed
723
+ * is paused rather than left judging a run nobody was told about; the retry resumes it.
724
+ */
725
+ async #remindPhaseGoal(record, goal, session, binding, requestContext) {
726
+ const reminderId = `${record.id}:goal`;
727
+ if ((await session.thread.listActiveMessages()).some((message) => message.id === reminderId)) return;
728
+ const agent = session.machinery.getAgent();
729
+ if (goal.status === "paused") await agent.updateObjectiveOptions({
730
+ threadId: binding.threadId,
731
+ status: "active"
732
+ });
733
+ try {
734
+ const settled = await session.sendSignal({
735
+ id: reminderId,
736
+ type: "system-reminder",
737
+ contents: goal.objective,
738
+ attributes: { type: "goal" },
739
+ metadata: {
740
+ goalId: goal.id,
741
+ goalMaxTurns: goal.maxRuns,
742
+ judgeModelId: goal.judgeModelId
743
+ }
744
+ }, {
745
+ requestContext,
746
+ requireDelivery: true
747
+ }).accepted;
748
+ if (settled.action !== "wake" && settled.action !== "deliver") throw new FactoryDispatchError("notification_delivery_failed", `Factory goal reminder did not reach the agent (${String(settled.action)}).`);
749
+ } catch (error) {
750
+ await agent.updateObjectiveOptions({
751
+ threadId: binding.threadId,
752
+ status: "paused"
753
+ });
754
+ throw error;
755
+ }
756
+ }
757
+ /** A retried decision whose kickoff already landed: make sure its goal is held and shown. */
758
+ async #startPhaseGoal(record, goal, session, binding, requestContext) {
759
+ const objective = await this.#setPhaseGoal(record, goal, session, binding);
760
+ await this.#remindPhaseGoal(record, objective, session, binding, requestContext);
761
+ }
762
+ /**
763
+ * A pull request review run: the only runs that keep a status comment on the pull request. A
764
+ * review-seat run of the skill the card's board self-reviews with checks the builder's own work
765
+ * and reviews no pull request, even on a card that carries one.
766
+ */
767
+ async #isReviewRun(record, decision) {
768
+ const run = reviewSeatSkill(decision);
769
+ if (!run) return false;
770
+ const item = record.workItemId ? await this.#storage.get({
771
+ orgId: record.orgId,
772
+ id: record.workItemId
773
+ }) : null;
774
+ if (!item) return true;
775
+ const board = (await this.#boards.load(record)).get(boardForWorkItem(item));
776
+ const selfReview = boardFlow(board).selfReview;
777
+ const phase = selfReview === void 0 ? void 0 : board?.phases[selfReview];
778
+ return phase?.kind !== "working" || phase.runner.skill !== run.skillName;
779
+ }
780
+ async #reviewQueuedOnce(record, decision) {
781
+ if (this.#reviewQueued.has(record)) return;
782
+ this.#reviewQueued.add(record);
783
+ await this.#reviewStatus(record, decision, { phase: "queued" });
784
+ }
785
+ /** Best-effort: a status comment is never worth failing or delaying the review it describes. */
786
+ async #reviewStatus(record, decision, step) {
787
+ const report = this.#reportReviewStatus;
788
+ if (!report || !record.workItemId) return;
789
+ try {
790
+ if (!await this.#isReviewRun(record, decision)) return;
791
+ } catch (error) {
792
+ console.warn("Factory review status update failed", sanitizeDispatchError(error));
793
+ return;
794
+ }
795
+ const event = {
796
+ orgId: record.orgId,
797
+ factoryProjectId: record.factoryProjectId,
798
+ workItemId: record.workItemId,
799
+ run: record.id,
800
+ requestedAt: record.createdAt,
801
+ generation: record.deliveryGeneration,
802
+ attempt: record.attempts,
803
+ ...step
804
+ };
805
+ const run = this.#reviewStatusRuns.get(record.id) ?? {
806
+ tail: Promise.resolve(),
807
+ issued: 0,
808
+ landed: 0,
809
+ latest: event
810
+ };
811
+ this.#reviewStatusRuns.set(record.id, run);
812
+ const previous = run.tail;
813
+ const seq = ++run.issued;
814
+ run.latest = event;
815
+ const send = (next) => report(next).catch((error) => {
816
+ console.warn("Factory review status update failed", sanitizeDispatchError(error));
817
+ });
818
+ let waited;
819
+ const delivered = Promise.race([previous, new Promise((resolve) => {
820
+ waited = setTimeout(resolve, REVIEW_STATUS_TIMEOUT_MS);
821
+ })]).finally(() => clearTimeout(waited)).then(async () => {
822
+ await send(event);
823
+ if (run.landed > seq) await send(run.latest);
824
+ run.landed = Math.max(run.landed, seq);
825
+ });
826
+ run.tail = delivered;
827
+ delivered.then(() => {
828
+ if (run.tail === delivered && run.landed >= run.issued && this.#reviewStatusRuns.get(record.id) === run) this.#reviewStatusRuns.delete(record.id);
829
+ });
830
+ let timer;
831
+ const timedOut = new Promise((resolve) => {
832
+ timer = setTimeout(() => resolve("timeout"), REVIEW_STATUS_TIMEOUT_MS);
833
+ });
834
+ try {
835
+ if (await Promise.race([delivered, timedOut]) === "timeout") console.warn(`Factory review status update (${step.phase}) still pending; continuing the run without it`);
836
+ } finally {
837
+ clearTimeout(timer);
599
838
  }
600
839
  }
601
840
  /** Terminal cleanup ran before this failure landed, so it never saw this row. */
@@ -646,13 +885,10 @@ var FactoryDecisionDispatcher = class {
646
885
  orgId: record.orgId,
647
886
  id: record.workItemId
648
887
  }) : null;
649
- if (item?.autonomyArmedAt != null) return false;
650
- if (item && reviewsFactoryAuthoredCode(item, decision)) return false;
651
- if (item && startsInAutoPhase(boards, item, decision)) return false;
652
- return !await this.#isAutoRunEnabled({
653
- orgId: record.orgId,
654
- factoryProjectId: record.factoryProjectId
655
- });
888
+ if (!item) return true;
889
+ if (item.autonomyArmedAt != null) return false;
890
+ if (reviewsFactoryAuthoredCode(boards, item, decision)) return false;
891
+ return !startsInAutoPhase(boards, item, decision);
656
892
  }
657
893
  async #executeDecision(record, decision) {
658
894
  const nextChain = [...record.causalChain, {
@@ -661,72 +897,13 @@ var FactoryDecisionDispatcher = class {
661
897
  }];
662
898
  if (nextChain.length > 8) throw new Error("Factory rule causal depth exceeded.");
663
899
  switch (decision.type) {
664
- case "transition": {
665
- const item = await this.#requireItem(record);
666
- if (!await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, `decision:${record.idempotencyKey}`)) assertFactoryDecisionTarget(decision, await this.#boards.load(record), item.board ?? void 0);
667
- const result = await this.#transitionService.transition({
668
- orgId: record.orgId,
669
- factoryProjectId: record.factoryProjectId,
670
- workItemId: item.id,
671
- board: decision.board,
672
- stage: decision.stage,
673
- expectedRevision: item.revision,
674
- actor: record.approvedBy ? {
675
- type: "human",
676
- id: record.approvedBy
677
- } : {
678
- type: "system",
679
- id: "factory-rule-dispatcher"
680
- },
681
- ingress: {
682
- type: "rule",
683
- identity: `decision:${record.idempotencyKey}`
684
- },
685
- cause: "rule_decision",
686
- causalChain: nextChain,
687
- ...decision.reenter ? { reenter: true } : {}
688
- });
689
- if (result.status === "rejected") throw new Error(`${result.code}: ${result.reason}`);
690
- const transitionMessage = decision.message;
691
- if (!transitionMessage) return;
692
- const moved = await this.#storage.get({
693
- orgId: record.orgId,
694
- id: item.id
695
- });
696
- if (!moved) return;
697
- const messageKey = `${record.idempotencyKey}:message`;
698
- const queued = await this.#storage.commitRuleEvaluation({
699
- orgId: record.orgId,
700
- factoryProjectId: record.factoryProjectId,
701
- workItemId: item.id,
702
- ingress: {
703
- identity: `decision:${messageKey}@${moved.revision}`,
704
- triggerType: "transition.message"
705
- },
706
- configVersion: this.#transitionService.configVersion,
707
- expectedRevision: moved.revision,
708
- actor: record.actor ?? {
709
- type: "system",
710
- id: "factory-rule-dispatcher"
711
- },
712
- outcome: { status: "accepted" },
713
- decisions: [{
714
- type: "sendMessage",
715
- idempotencyKey: messageKey,
716
- message: transitionMessage.text,
717
- priority: "high",
718
- idleBehavior: "wake",
719
- ...transitionMessage.role !== void 0 ? { role: transitionMessage.role } : {}
720
- }],
721
- causalChain: nextChain,
722
- now: /* @__PURE__ */ new Date()
723
- });
724
- if (queued.status === "missing") return;
725
- if (queued.status === "stale") throw new Error("Factory transition message was not queued: the work item changed concurrently.");
726
- const queuedStatus = queued.result.status;
727
- if (queuedStatus !== "accepted") throw new Error(`Factory transition message was not queued: ${queuedStatus ?? "unknown"}.`);
900
+ case "transition":
901
+ if (decision.event) await this.#routeEvent(record, decision.event, nextChain, decision);
902
+ else await this.#applyTransition(record, decision, nextChain);
903
+ return;
904
+ case "routeEvent":
905
+ await this.#routeEvent(record, decision.event, nextChain);
728
906
  return;
729
- }
730
907
  case "upsertLinkedWorkItem":
731
908
  await this.#upsertLinkedItem(record, decision, nextChain);
732
909
  return;
@@ -768,33 +945,19 @@ var FactoryDecisionDispatcher = class {
768
945
  const kickoffLanded = async () => (await session.thread.listActiveMessages()).some((message) => message.id === deliveryId);
769
946
  const kickoffStale = async () => await this.#roleSuperseded(record, decision.role) || (await this.#findBinding(record, decision.role))?.id !== binding.id || await this.#decisionOvertaken(record, decision.role);
770
947
  const runStillActive = () => this.#controller.listActiveThreadRuns().some((active) => active.threadId === binding.threadId);
771
- while (true) {
772
- const openRun = watchRun(session, {
773
- timeoutMs: this.#skillCompletionObservationTimeoutMs,
774
- approvePlans: false,
775
- label: "Factory skill run",
776
- runStillActive
777
- });
778
- try {
779
- const open = (await listSessionOpenRuns(session)).filter((entry) => entry.bindingId === binding.id);
780
- if (open.length === 0) break;
781
- if (open.some((entry) => isOpenRunLiveElsewhere(entry, this.#ownerId))) throw new FactoryDispatchError("session_unavailable", `Factory binding ${binding.id} has a run in flight on another dispatcher.`);
782
- if (!runStillActive()) break;
783
- if (!await openRun.wait()) break;
784
- } finally {
785
- openRun.close();
786
- }
787
- await waitForSessionRunAudit(session);
788
- }
948
+ await this.#waitForOpenRun(session, binding, "Factory skill run");
789
949
  if (await this.#roleSuperseded(record, decision.role)) throw new FactoryDecisionSuperseded();
790
950
  if ((await this.#requireBinding(record, decision.role)).id !== binding.id) throw new FactoryDispatchError("session_unavailable", `Factory binding ${binding.id} changed while waiting for its open run to end.`);
791
- if (await kickoffLanded()) return;
951
+ if (await kickoffLanded()) {
952
+ if (decision.goal) await this.#startPhaseGoal(record, decision.goal, session, binding, requestContext);
953
+ return this.#replayLanded(record, decision, session, runStillActive);
954
+ }
792
955
  if (await kickoffStale()) throw new FactoryDecisionSuperseded();
793
- const kickoffContents = await withWorkItemFeed(this.#feedReader, {
956
+ const current = record.workItemId ? await this.#storage.get({
794
957
  orgId: record.orgId,
795
- factoryProjectId: record.factoryProjectId,
796
- workItemId: record.workItemId
797
- }, resolved.contents);
958
+ id: record.workItemId
959
+ }) : null;
960
+ const kickoffContents = withWorkItemDescription(resolved.contents, current?.description);
798
961
  const kickoffSignal = resolved.skillName !== void 0 ? {
799
962
  type: "reactive",
800
963
  tagName: "skill",
@@ -803,8 +966,12 @@ var FactoryDecisionDispatcher = class {
803
966
  type: "user",
804
967
  tagName: "user"
805
968
  };
806
- if (await kickoffLanded()) return;
969
+ if (await kickoffLanded()) {
970
+ if (decision.goal) await this.#startPhaseGoal(record, decision.goal, session, binding, requestContext);
971
+ return this.#replayLanded(record, decision, session, runStillActive);
972
+ }
807
973
  if (await kickoffStale()) throw new FactoryDecisionSuperseded();
974
+ await this.#reviewQueuedOnce(record, decision);
808
975
  if (decision.cancelInFlight && session.stream.isActive()) session.abort();
809
976
  const precedingMessage = decision.precedingMessage;
810
977
  if (precedingMessage) {
@@ -823,10 +990,12 @@ var FactoryDecisionDispatcher = class {
823
990
  }));
824
991
  if (await kickoffStale()) throw new FactoryDecisionSuperseded();
825
992
  }
993
+ const goal = decision.goal ? await this.#setPhaseGoal(record, decision.goal, session, binding) : void 0;
826
994
  const since = /* @__PURE__ */ new Date();
827
995
  const run = watchRun(session, {
828
996
  timeoutMs: this.#skillCompletionObservationTimeoutMs,
829
997
  approvePlans: await this.#plansAreAutoApproved(record),
998
+ requestContext,
830
999
  onAgentEnd: () => this.#roleSuperseded(record, decision.role),
831
1000
  label: "Factory skill run",
832
1001
  runStillActive
@@ -853,7 +1022,13 @@ var FactoryDecisionDispatcher = class {
853
1022
  run.arm();
854
1023
  settled = await sendKickoff();
855
1024
  }
1025
+ if (goal) await this.#remindPhaseGoal(record, goal, session, binding, requestContext);
856
1026
  await this.#recordRunStart(session, binding, deliveryId, record.approvedBy ?? void 0, run.endReason, item?.title);
1027
+ this.#reviewWatched.add(record);
1028
+ await this.#reviewStatus(record, decision, {
1029
+ phase: "reviewing",
1030
+ startedAt: since
1031
+ });
857
1032
  try {
858
1033
  await this.#reportingRunEnd({
859
1034
  binding,
@@ -862,8 +1037,20 @@ var FactoryDecisionDispatcher = class {
862
1037
  attempts: record.attempts,
863
1038
  superseded: async () => await run.supersededAtEnd() ?? await this.#roleSuperseded(record, decision.role)
864
1039
  }, () => this.#withOpenRunHeartbeat(session, deliveryId, () => run.settle()));
1040
+ if (await run.supersededAtEnd()) {
1041
+ this.#reviewWatched.delete(record);
1042
+ await this.#reviewStatus(record, decision, {
1043
+ phase: "cancelled",
1044
+ endedAt: /* @__PURE__ */ new Date()
1045
+ });
1046
+ }
865
1047
  } catch (error) {
866
1048
  if (!(await run.supersededAtEnd() ?? await this.#roleSuperseded(record, decision.role))) throw error;
1049
+ this.#reviewWatched.delete(record);
1050
+ await this.#reviewStatus(record, decision, {
1051
+ phase: "cancelled",
1052
+ endedAt: /* @__PURE__ */ new Date()
1053
+ });
867
1054
  }
868
1055
  } finally {
869
1056
  run.close();
@@ -905,13 +1092,31 @@ var FactoryDecisionDispatcher = class {
905
1092
  }), true);
906
1093
  return;
907
1094
  }
1095
+ case "signalActivity":
1096
+ await this.#signalActivity(record, decision);
1097
+ return;
908
1098
  case "dismissStaleReviews":
909
1099
  if (!this.#dismissStaleReviews) throw new Error("GitHub review dismissal is not configured.");
910
1100
  await this.#dismissStaleReviews(decision);
911
1101
  return;
912
1102
  case "notify": {
913
1103
  const binding = await this.#requireBinding(record);
1104
+ const startedBy = (record.workItemId ? await this.#storage.get({
1105
+ orgId: record.orgId,
1106
+ id: record.workItemId
1107
+ }) : null)?.sessions[binding.role]?.startedBy;
1108
+ if (!startedBy) throw new Error(`Factory binding ${binding.id} has no authenticated session owner.`);
1109
+ await this.#primeCredentials?.({
1110
+ orgId: record.orgId,
1111
+ userId: startedBy
1112
+ });
914
1113
  const session = await this.#requireSession(binding);
1114
+ const requestContext = factoryRequestContext({
1115
+ session,
1116
+ binding,
1117
+ userId: startedBy,
1118
+ orgId: record.orgId
1119
+ });
915
1120
  await awaitNotification(() => session.sendNotificationSignal({
916
1121
  source: "factory",
917
1122
  kind: "rule-notification",
@@ -922,7 +1127,7 @@ var FactoryDecisionDispatcher = class {
922
1127
  },
923
1128
  sourceId: record.id,
924
1129
  dedupeKey: record.idempotencyKey
925
- }));
1130
+ }, { requestContext }));
926
1131
  }
927
1132
  }
928
1133
  }
@@ -933,11 +1138,12 @@ var FactoryDecisionDispatcher = class {
933
1138
  async #linearCardByIssueId(record, decision, boards) {
934
1139
  const issueId = decision.metadata?.linearIssueId;
935
1140
  if (decision.source !== "linear-issue" || typeof issueId !== "string") return null;
936
- const cards = (await this.#storage.list({
1141
+ const cards = (await this.#storage.listShared({
937
1142
  orgId: record.orgId,
938
1143
  factoryProjectId: record.factoryProjectId
939
1144
  })).filter((item) => item.externalSource?.integrationId === "linear" && item.workItem.metadata?.linearIssueId === issueId);
940
- return cards.find((item) => !isTerminalWorkItem(boards, item)) ?? cards[0] ?? null;
1145
+ const card = cards.find((item) => !isTerminalWorkItem(boards, item)) ?? cards[0];
1146
+ return card ? structuredClone(card) : null;
941
1147
  }
942
1148
  async #upsertLinkedItem(record, requested, causalChain) {
943
1149
  if (this.#factoryProjectExists && !await this.#factoryProjectExists({
@@ -949,6 +1155,29 @@ var FactoryDecisionDispatcher = class {
949
1155
  factoryProjectId: record.factoryProjectId,
950
1156
  source: externalSourceForDecision(requested)
951
1157
  });
1158
+ if (existing && externalSourceKey(existing.externalSource) !== externalSourceKey(externalSourceForDecision(requested))) {
1159
+ const source = externalSourceForDecision(requested);
1160
+ const facts = workItemProviderAdapter(source).toSource(source, requested.metadata ?? null);
1161
+ if (facts?.state === "open") await this.#storage.syncWorkItemSource({
1162
+ orgId: record.orgId,
1163
+ factoryProjectId: record.factoryProjectId,
1164
+ provider: facts.provider,
1165
+ externalId: facts.externalId,
1166
+ patch: (current) => current.state === "closed" || current.state === "merged" ? {
1167
+ state: facts.state,
1168
+ metadata: {
1169
+ ...current.metadata,
1170
+ ...facts.metadata
1171
+ }
1172
+ } : null
1173
+ });
1174
+ return;
1175
+ }
1176
+ if (!existing && requested.attachTo) {
1177
+ const attachBoards = await this.#boards.load(record);
1178
+ if (await this.#attachLinkedItem(record, requested, requested.attachTo.workItemId, causalChain, (card) => cardBoardFlow(attachBoards, card).pullRequestReview !== void 0 ? { phase: null } : void 0)) return;
1179
+ }
1180
+ if (!existing && requested.closesIssue && await this.#joinClosedIssue(record, requested, causalChain)) return;
952
1181
  const materializedHere = existing?.metadata?.[FACTORY_RULE_MATERIALIZATION_KEY] === record.idempotencyKey;
953
1182
  if (materializedHere && requested.skipRules === true) return;
954
1183
  const boards = await this.#boards.load(record);
@@ -996,7 +1225,10 @@ var FactoryDecisionDispatcher = class {
996
1225
  reuseMode: "preserve"
997
1226
  });
998
1227
  const itemBoard = boardForWorkItem(result.item);
999
- const board = itemBoard === "review" && decision.board === "work" && isPullRequestCard({ source: workItemSource(result.item.externalSource) }) ? itemBoard : decision.board;
1228
+ const itemFlow = itemBoard === decision.board ? void 0 : boardFlow(boards.get(itemBoard));
1229
+ const keptReview = isPullRequestCard({ source: workItemSource(result.item.externalSource) }) ? itemFlow?.pullRequestReview : void 0;
1230
+ const board = keptReview === void 0 ? decision.board : itemBoard;
1231
+ const placeStage = keptReview !== void 0 && decision.stage === boardFlow(definition).pullRequestReview ? keptReview : decision.stage;
1000
1232
  if (!skipRules && itemBoard !== board) throw new Error(`The work item belongs to board "${itemBoard}", not "${board}".`);
1001
1233
  if (!result.item.parentWorkItemId && parentWorkItemId && parentWorkItemId !== result.item.id) {
1002
1234
  const item = await this.#storage.setParentWorkItemIfMissing({
@@ -1028,14 +1260,22 @@ var FactoryDecisionDispatcher = class {
1028
1260
  }
1029
1261
  }
1030
1262
  if (skipRules) {
1031
- if (!result.created) await moveCardToBoard({
1032
- workItems: this.#storage,
1033
- boardRegistry: boards,
1034
- userId: "factory-rule-dispatcher",
1035
- item: result.item,
1036
- targetBoard: board,
1037
- targetStage: decision.stage
1038
- });
1263
+ let item = result.created ? null : result.item;
1264
+ for (let attempt = 0; item && attempt < 3; attempt += 1) {
1265
+ if (await moveCardToBoard({
1266
+ workItems: this.#storage,
1267
+ boardRegistry: boards,
1268
+ userId: "factory-rule-dispatcher",
1269
+ item,
1270
+ targetBoard: board,
1271
+ targetStage: placeStage
1272
+ }) !== "skipped") break;
1273
+ const fresh = await this.#storage.get({
1274
+ orgId: record.orgId,
1275
+ id: item.id
1276
+ });
1277
+ item = fresh && fresh.revision !== item.revision ? fresh : null;
1278
+ }
1039
1279
  return;
1040
1280
  }
1041
1281
  const materializedByDecision = result.item.metadata?.[FACTORY_RULE_MATERIALIZATION_KEY] === record.idempotencyKey;
@@ -1090,26 +1330,134 @@ var FactoryDecisionDispatcher = class {
1090
1330
  if (moved.status === "rejected") throw new Error(`${moved.code}: ${moved.reason}`);
1091
1331
  }
1092
1332
  /**
1093
- * Applies the project's intake routes to an arrival: a decision filing the card at its
1094
- * board's initial phase. A decision naming a later phase (a maintainer's review request)
1095
- * or placing the card outright (`skipRules`) already chose where the card goes.
1333
+ * Files a pull or merge request on the existing card `workItemId`, as one more source, when
1334
+ * `admit` takes the card as it is now; the card then moves to the phase `admit` names when its
1335
+ * board allows it. Returns false when the card can't take it (gone, finished, a pull request's
1336
+ * own card, refused by `admit`, or another card took the record first), so the caller files the
1337
+ * record as usual. `admit` runs again on a fresh read whenever the card changed in between.
1096
1338
  */
1097
- async #routeArrival(record, decision, boards) {
1098
- if (!this.#intakeRoutes || decision.skipRules === true) return decision;
1099
- if (decision.stage !== boards.get(decision.board)?.initialPhase) return decision;
1100
- if (record.workItemId !== null) return decision;
1339
+ async #attachLinkedItem(record, decision, workItemId, causalChain, admit) {
1340
+ if (this.#storage.legacyMode) return false;
1341
+ const boards = await this.#boards.load(record);
1342
+ let attached;
1343
+ for (let attempt = 0; attempt < 3 && !attached; attempt++) {
1344
+ const card = await this.#storage.get({
1345
+ orgId: record.orgId,
1346
+ id: workItemId
1347
+ });
1348
+ if (!card || card.factoryProjectId !== record.factoryProjectId || isTerminalWorkItem(boards, card) || isPullRequestCard({ source: workItemSource(card.externalSource) })) return false;
1349
+ const admitted = admit(card);
1350
+ if (!admitted) return false;
1351
+ try {
1352
+ const result = await this.#storage.attachSource({
1353
+ orgId: record.orgId,
1354
+ id: card.id,
1355
+ source: externalSourceForDecision(decision),
1356
+ metadata: decision.metadata ?? null,
1357
+ expectedRevision: card.revision
1358
+ });
1359
+ if (!result) return false;
1360
+ attached = {
1361
+ card: result.item,
1362
+ phase: admitted.phase
1363
+ };
1364
+ } catch (error) {
1365
+ if (error instanceof WorkItemSourceConflictError) return false;
1366
+ if (error instanceof WorkItemUpdateConflictError) continue;
1367
+ throw error;
1368
+ }
1369
+ }
1370
+ if (!attached) return false;
1371
+ const { card, phase } = attached;
1372
+ const stage = card.stages.length === 1 ? card.stages[0] : void 0;
1373
+ const board = boards.get(boardForWorkItem(card));
1374
+ if (!phase || !stage || stage === phase) return true;
1375
+ if (!board?.allowsTransition(stage, phase)) {
1376
+ console.warn(`[factory] attached a pull request to ${card.id}, which stays in ${stage}: its board has no move to ${phase}`);
1377
+ return true;
1378
+ }
1379
+ const moved = await this.#transitionService.transition({
1380
+ orgId: record.orgId,
1381
+ factoryProjectId: record.factoryProjectId,
1382
+ workItemId: card.id,
1383
+ board: board.id,
1384
+ stage: phase,
1385
+ expectedRevision: card.revision,
1386
+ actor: {
1387
+ type: "system",
1388
+ id: "factory-rule-dispatcher"
1389
+ },
1390
+ ingress: {
1391
+ type: "rule",
1392
+ identity: `decision:${record.idempotencyKey}:${card.id}:attach`
1393
+ },
1394
+ cause: "linked_item_attached",
1395
+ causalChain
1396
+ });
1397
+ if (moved.status === "rejected") console.warn(`[factory] attached a pull request to ${card.id} but could not move it to ${phase}: ${moved.code}: ${moved.reason}`);
1398
+ return true;
1399
+ }
1400
+ /**
1401
+ * Joins a pull or merge request to the card of the issue it closes when the project's intake
1402
+ * routes say so: the first route matching the arrival, with the facts of that card as it is now,
1403
+ * is a joining one. Only an arrival the routes would place qualifies, and only from an author
1404
+ * with write access: no route can put an outsider's pull request on someone else's card.
1405
+ */
1406
+ async #joinClosedIssue(record, decision, causalChain) {
1407
+ if (!authorTrusted(decision.metadata) || !this.#intakeRoutes || decision.skipRules === true) return false;
1408
+ if (record.workItemId !== null) return false;
1409
+ const boards = await this.#boards.load(record);
1101
1410
  const routes = await this.#intakeRoutes.listIntakeRoutes({
1102
1411
  orgId: record.orgId,
1103
1412
  factoryProjectId: record.factoryProjectId
1104
1413
  });
1105
- if (routes.length === 0) return decision;
1106
- const facts = cardRuleFacts({
1414
+ if (routes.length === 0) return false;
1415
+ const arrival = cardRuleFacts({
1107
1416
  title: decision.title,
1108
1417
  metadata: decision.metadata ?? {},
1109
1418
  externalSource: externalSourceForDecision(decision)
1110
1419
  });
1420
+ return this.#attachLinkedItem(record, decision, decision.closesIssue.workItemId, causalChain, (card) => {
1421
+ const route = resolveIntakeRoute(routes, {
1422
+ ...arrival,
1423
+ ...closedIssueRuleFacts(card)
1424
+ }, boards, card);
1425
+ return route?.type === "join" ? { phase: route.phase } : void 0;
1426
+ });
1427
+ }
1428
+ /**
1429
+ * Places an arrival where the project's intake routes say: the first enabled route matching it,
1430
+ * else the default board's first phase. The board and phase an integration's rule named don't
1431
+ * count; only a decision placing the card outright (`skipRules`) keeps its own.
1432
+ */
1433
+ async #routeArrival(record, decision, boards) {
1434
+ if (!this.#intakeRoutes || decision.skipRules === true) return decision;
1435
+ if (record.workItemId !== null) return decision;
1436
+ const routes = await this.#intakeRoutes.listIntakeRoutes({
1437
+ orgId: record.orgId,
1438
+ factoryProjectId: record.factoryProjectId
1439
+ });
1440
+ const closedIssue = decision.closesIssue ? await this.#storage.get({
1441
+ orgId: record.orgId,
1442
+ id: decision.closesIssue.workItemId
1443
+ }) : null;
1444
+ const facts = {
1445
+ ...cardRuleFacts({
1446
+ title: decision.title,
1447
+ metadata: decision.metadata ?? {},
1448
+ externalSource: externalSourceForDecision(decision)
1449
+ }),
1450
+ ...decision.closesIssue ? closedIssueRuleFacts(closedIssue && closedIssue.factoryProjectId === record.factoryProjectId && !isTerminalWorkItem(boards, closedIssue) ? closedIssue : void 0) : {}
1451
+ };
1111
1452
  const placement = resolveIntakePlacement(routes, facts, boards);
1112
- if (!placement) return decision;
1453
+ if (!placement) {
1454
+ const fallback = intakeTarget(boards);
1455
+ return fallback ? {
1456
+ ...decision,
1457
+ board: fallback.board,
1458
+ stage: fallback.initialPhase
1459
+ } : decision;
1460
+ }
1113
1461
  return {
1114
1462
  ...decision,
1115
1463
  board: placement.board,
@@ -1122,7 +1470,7 @@ var FactoryDecisionDispatcher = class {
1122
1470
  }
1123
1471
  /**
1124
1472
  * A card an intake route placed stays on the route's board when its source is filed again
1125
- * (a reconcile replaying "opened" with today's label route or binding): the decision lands
1473
+ * (a reconcile replaying "opened"): the decision lands
1126
1474
  * on the card's board at its first phase, so it only backfills facts and moves nothing.
1127
1475
  * An explicit placement (`skipRules`) still wins.
1128
1476
  */
@@ -1161,6 +1509,163 @@ var FactoryDecisionDispatcher = class {
1161
1509
  stage: board.initialPhase
1162
1510
  };
1163
1511
  }
1512
+ /** Moves the card as a rule decided, then queues the decision's message for the card's session. */
1513
+ async #applyTransition(record, decision, nextChain) {
1514
+ const item = await this.#requireItem(record);
1515
+ if (!await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, `decision:${record.idempotencyKey}`)) assertFactoryDecisionTarget(decision, await this.#boards.load(record), item.board ?? void 0);
1516
+ const result = await this.#transitionService.transition({
1517
+ orgId: record.orgId,
1518
+ factoryProjectId: record.factoryProjectId,
1519
+ workItemId: item.id,
1520
+ board: decision.board,
1521
+ stage: decision.stage,
1522
+ expectedRevision: item.revision,
1523
+ actor: record.approvedBy ? {
1524
+ type: "human",
1525
+ id: record.approvedBy
1526
+ } : {
1527
+ type: "system",
1528
+ id: "factory-rule-dispatcher"
1529
+ },
1530
+ ingress: {
1531
+ type: "rule",
1532
+ identity: `decision:${record.idempotencyKey}`
1533
+ },
1534
+ cause: "rule_decision",
1535
+ causalChain: nextChain,
1536
+ ...decision.reenter ? { reenter: true } : {}
1537
+ });
1538
+ if (result.status === "rejected") throw new Error(`${result.code}: ${result.reason}`);
1539
+ const transitionMessage = decision.message;
1540
+ if (!transitionMessage) return;
1541
+ const moved = await this.#storage.get({
1542
+ orgId: record.orgId,
1543
+ id: item.id
1544
+ });
1545
+ if (!moved) return;
1546
+ const messageKey = `${record.idempotencyKey}:message`;
1547
+ const queued = await this.#storage.commitRuleEvaluation({
1548
+ orgId: record.orgId,
1549
+ factoryProjectId: record.factoryProjectId,
1550
+ workItemId: item.id,
1551
+ ingress: {
1552
+ identity: `decision:${messageKey}@${moved.revision}`,
1553
+ triggerType: "transition.message"
1554
+ },
1555
+ configVersion: this.#transitionService.configVersion,
1556
+ expectedRevision: moved.revision,
1557
+ actor: record.actor ?? {
1558
+ type: "system",
1559
+ id: "factory-rule-dispatcher"
1560
+ },
1561
+ outcome: { status: "accepted" },
1562
+ decisions: [{
1563
+ type: "sendMessage",
1564
+ idempotencyKey: messageKey,
1565
+ message: transitionMessage.text,
1566
+ priority: "high",
1567
+ idleBehavior: "wake",
1568
+ ...transitionMessage.role !== void 0 ? { role: transitionMessage.role } : {}
1569
+ }],
1570
+ causalChain: nextChain,
1571
+ now: /* @__PURE__ */ new Date()
1572
+ });
1573
+ if (queued.status === "missing") return;
1574
+ if (queued.status === "stale") throw new Error("Factory transition message was not queued: the work item changed concurrently.");
1575
+ const queuedStatus = queued.result.status;
1576
+ if (queuedStatus !== "accepted") throw new Error(`Factory transition message was not queued: ${queuedStatus ?? "unknown"}.`);
1577
+ }
1578
+ /**
1579
+ * Moves a card where the project's intake routes send it on a status event. A move into a
1580
+ * working or resting phase waits for the run in flight on the card to end, going back to the
1581
+ * queue without holding a dispatch slot until it has; a move into a
1582
+ * terminal phase does not, so terminal cleanup stops that run at once, as a close always has.
1583
+ * A close moves only an unfinished card and a reopen only a finished one. When no route on the
1584
+ * card's board handles the event at all, the rule's own move (a board's `sourceClosed` phase)
1585
+ * applies instead; when one does but none matches, the card stays. A route's move is a system
1586
+ * move by the route: recorded in the card's history and audit, keyed so a replayed delivery
1587
+ * moves nothing twice.
1588
+ */
1589
+ async #routeEvent(record, event, causalChain, fallback) {
1590
+ const identity = `event-route:${record.idempotencyKey}`;
1591
+ if (await this.#storage.getTransitionResultByIngress(record.orgId, record.factoryProjectId, identity)) return;
1592
+ if (await this.#statusEventOvertaken(record)) throw new FactoryDecisionSuperseded();
1593
+ const resolve = async () => {
1594
+ const item = await this.#requireItem(record);
1595
+ const board = (await this.#boards.load(record)).get(boardForWorkItem(item));
1596
+ if (!board) return void 0;
1597
+ const stage = item.stages.length === 1 ? item.stages[0] : void 0;
1598
+ const finished = stage !== void 0 && board.isTerminal(stage);
1599
+ if (!eventMovesCard(event.type, finished)) return void 0;
1600
+ const routes = this.#intakeRoutes ? await this.#intakeRoutes.listIntakeRoutes({
1601
+ orgId: record.orgId,
1602
+ factoryProjectId: record.factoryProjectId
1603
+ }) : [];
1604
+ if (!routesHandleEvent(routes, event, board)) return {
1605
+ item,
1606
+ board,
1607
+ fallback: true
1608
+ };
1609
+ const route = resolveEventRoute(routes, event, cardRuleFacts(item), board, hasPullRequest(item));
1610
+ if (!route) return fallback && isPullRequestEvent(event.type) ? {
1611
+ item,
1612
+ board,
1613
+ fallback: true
1614
+ } : void 0;
1615
+ if (fallback && isPullRequestEvent(event.type) && route.phase === fallback.stage) return {
1616
+ item,
1617
+ board,
1618
+ fallback: true
1619
+ };
1620
+ if (stage === route.phase) return void 0;
1621
+ return {
1622
+ item,
1623
+ board,
1624
+ route
1625
+ };
1626
+ };
1627
+ const first = await resolve();
1628
+ if (!first) return;
1629
+ if ("fallback" in first) {
1630
+ if (fallback) await this.#applyTransition(record, fallback, causalChain);
1631
+ return;
1632
+ }
1633
+ if (!first.board.isTerminal(first.route.phase)) {
1634
+ const binding = await this.#findBinding(record);
1635
+ const session = binding ? await this.#findSession(binding) : void 0;
1636
+ if (binding && session && await this.#hasRunInFlight(session, binding)) throw new FactoryDecisionPostponed();
1637
+ }
1638
+ const { item, board, route } = first;
1639
+ const result = await this.#transitionService.transition({
1640
+ orgId: record.orgId,
1641
+ factoryProjectId: record.factoryProjectId,
1642
+ workItemId: item.id,
1643
+ board: board.id,
1644
+ stage: route.phase,
1645
+ expectedRevision: item.revision,
1646
+ actor: {
1647
+ type: "system",
1648
+ id: `intake-route:${route.routeId}`
1649
+ },
1650
+ ingress: {
1651
+ type: "rule",
1652
+ identity
1653
+ },
1654
+ cause: "event_route",
1655
+ causalChain,
1656
+ eventRoute: { routeId: route.routeId }
1657
+ });
1658
+ if (result.status === "rejected" && result.code === "stale") throw new Error(`${result.code}: ${result.reason}`);
1659
+ }
1660
+ /**
1661
+ * Whether a later status event was queued for the same card: the source's last word wins, so a
1662
+ * close still queued when the issue is reopened moves nothing. Of events queued in the same
1663
+ * millisecond, the one with the greatest id is the last; one already settled had its turn.
1664
+ */
1665
+ async #statusEventOvertaken(record) {
1666
+ if (!record.workItemId || !isStatusEventDecision(record.decision)) return false;
1667
+ return (await this.#storage.listDeferredDecisions(record.orgId, record.factoryProjectId, { workItemId: record.workItemId })).some((other) => other.id !== record.id && isStatusEventDecision(other.decision) && (other.createdAt.getTime() > record.createdAt.getTime() || other.createdAt.getTime() === record.createdAt.getTime() && other.completedAt === null && other.id > record.id));
1668
+ }
1164
1669
  async #requireItem(record) {
1165
1670
  if (!record.workItemId) throw new Error("Factory decision is not linked to a work item.");
1166
1671
  const item = await this.#storage.get({
@@ -1172,9 +1677,18 @@ var FactoryDecisionDispatcher = class {
1172
1677
  }
1173
1678
  async #findBinding(record, role) {
1174
1679
  if (!record.workItemId) throw new Error("Factory decision is not linked to a work item.");
1175
- return (await this.#storage.listRunBindings(record.orgId, record.factoryProjectId, record.workItemId)).filter((candidate) => candidate.status === "active" && (role === void 0 || candidate.role === role)).sort((left, right) => {
1176
- if (role === void 0 && left.role === "work" && right.role !== "work") return -1;
1177
- if (role === void 0 && right.role === "work" && left.role !== "work") return 1;
1680
+ const active = (await this.#storage.listRunBindings(record.orgId, record.factoryProjectId, record.workItemId)).filter((candidate) => candidate.status === "active" && (role === void 0 || candidate.role === role));
1681
+ let builder;
1682
+ if (role === void 0 && active.length > 1) {
1683
+ const item = await this.#storage.get({
1684
+ orgId: record.orgId,
1685
+ id: record.workItemId
1686
+ });
1687
+ builder = item ? cardBoardFlow(await this.#boards.load(record), item).buildRole : void 0;
1688
+ }
1689
+ return active.sort((left, right) => {
1690
+ if (builder !== void 0 && left.role === builder && right.role !== builder) return -1;
1691
+ if (builder !== void 0 && right.role === builder && left.role !== builder) return 1;
1178
1692
  return right.createdAt.getTime() - left.createdAt.getTime() || left.id.localeCompare(right.id);
1179
1693
  })[0];
1180
1694
  }
@@ -1183,6 +1697,50 @@ var FactoryDecisionDispatcher = class {
1183
1697
  if (!binding) throw new FactoryDispatchError("session_unavailable", role ? `No active Factory binding for role ${role}.` : "No active Factory binding.");
1184
1698
  return binding;
1185
1699
  }
1700
+ /**
1701
+ * Points the card's live session at new activity on its source. The message
1702
+ * is written here from the decision's pointers, never from provider text.
1703
+ * Activity while the session is busy waits as one pending notification per
1704
+ * card and kind of activity, counting how many arrived; an idle session is
1705
+ * woken unless the decision asks to only persist. A card nobody is working
1706
+ * has nobody to tell, so it is dropped.
1707
+ */
1708
+ async #signalActivity(record, decision) {
1709
+ if (!record.workItemId) return;
1710
+ const binding = await this.#findBinding(record);
1711
+ if (!binding) return;
1712
+ const startedBy = (await this.#storage.get({
1713
+ orgId: record.orgId,
1714
+ id: record.workItemId
1715
+ }))?.sessions[binding.role]?.startedBy;
1716
+ if (!startedBy) throw new Error(`Factory binding ${binding.id} has no authenticated session owner.`);
1717
+ await this.#primeCredentials?.({
1718
+ orgId: record.orgId,
1719
+ userId: startedBy
1720
+ });
1721
+ const session = await this.#requireSession(binding);
1722
+ const author = decision.author ? `@${decision.author}${decision.authorTrusted ? "" : " (untrusted author)"}` : decision.authorTrusted ? void 0 : "an untrusted author";
1723
+ const message = decision.event === "work_item.commented" ? `New comment${author ? ` by ${author}` : ""} on ${decision.reference}: ${decision.url}` : `${decision.reference} was edited${author ? ` by ${author}` : ""}: ${decision.url}`;
1724
+ const wakes = decision.authorTrusted && decision.idleBehavior !== "persist";
1725
+ await awaitNotification(() => session.sendNotificationSignal({
1726
+ source: "factory",
1727
+ kind: "source-activity",
1728
+ summary: message,
1729
+ priority: wakes ? "medium" : "low",
1730
+ sourceId: record.id,
1731
+ dedupeKey: record.idempotencyKey,
1732
+ coalesceKey: `${record.workItemId}:${decision.event}`
1733
+ }, {
1734
+ ifActive: { behavior: "persist" },
1735
+ ifIdle: { behavior: wakes ? "wake" : "persist" },
1736
+ requestContext: factoryRequestContext({
1737
+ session,
1738
+ binding,
1739
+ userId: startedBy,
1740
+ orgId: record.orgId
1741
+ })
1742
+ }));
1743
+ }
1186
1744
  async #messageBinding(record, decision) {
1187
1745
  if (decision.prepareBinding && decision.role !== void 0) return this.#requireOrPrepareBinding(record, decision.role);
1188
1746
  return this.#findBinding(record, decision.role);
@@ -1259,6 +1817,38 @@ var FactoryDecisionDispatcher = class {
1259
1817
  factoryProjectId
1260
1818
  }), item) === "submit_plan";
1261
1819
  }
1820
+ /**
1821
+ * Whether a run is in flight on `binding`: live here, or live on another dispatcher. An open-run
1822
+ * entry with nothing live behind it is an orphan of a dead process and does not count.
1823
+ */
1824
+ async #hasRunInFlight(session, binding) {
1825
+ const open = (await listSessionOpenRuns(session)).filter((entry) => entry.bindingId === binding.id);
1826
+ if (open.length === 0) return false;
1827
+ if (open.some((entry) => isOpenRunLiveElsewhere(entry, this.#ownerId))) return true;
1828
+ return this.#controller.listActiveThreadRuns().some((active) => active.threadId === binding.threadId);
1829
+ }
1830
+ /** Waits for the run in flight on `binding` to end, so a kickoff never overlaps it. */
1831
+ async #waitForOpenRun(session, binding, label) {
1832
+ const runStillActive = () => this.#controller.listActiveThreadRuns().some((active) => active.threadId === binding.threadId);
1833
+ while (true) {
1834
+ const openRun = watchRun(session, {
1835
+ timeoutMs: this.#skillCompletionObservationTimeoutMs,
1836
+ approvePlans: false,
1837
+ label,
1838
+ runStillActive
1839
+ });
1840
+ try {
1841
+ const open = (await listSessionOpenRuns(session)).filter((entry) => entry.bindingId === binding.id);
1842
+ if (open.length === 0) break;
1843
+ if (open.some((entry) => isOpenRunLiveElsewhere(entry, this.#ownerId))) throw new FactoryDispatchError("session_unavailable", `Factory binding ${binding.id} has a run in flight on another dispatcher.`);
1844
+ if (!runStillActive()) break;
1845
+ if (!await openRun.wait()) break;
1846
+ } finally {
1847
+ openRun.close();
1848
+ }
1849
+ await waitForSessionRunAudit(session);
1850
+ }
1851
+ }
1262
1852
  async #requireSession(binding) {
1263
1853
  const session = await this.#findSession(binding);
1264
1854
  if (!session) throw new FactoryDispatchError("session_unavailable", "Bound Factory session not found.");
@@ -1402,6 +1992,7 @@ var FactoryDecisionDispatcher = class {
1402
1992
  ...record,
1403
1993
  workItemId: binding.workItemId
1404
1994
  }),
1995
+ requestContext,
1405
1996
  label: "Factory kickoff run",
1406
1997
  runStillActive: () => this.#controller.listActiveThreadRuns().some((active) => active.threadId === binding.threadId)
1407
1998
  });
@@ -1463,7 +2054,7 @@ const FACTORY_DISPATCH_CONSTANTS = {
1463
2054
  runRegistryHeartbeatMs: RUN_REGISTRY_HEARTBEAT_MS,
1464
2055
  openRunStaleMs: FACTORY_OPEN_RUN_STALE_MS,
1465
2056
  maxInFlight: MAX_IN_FLIGHT,
1466
- stages: FACTORY_RULE_STAGES
2057
+ reviewStatusTimeoutMs: REVIEW_STATUS_TIMEOUT_MS
1467
2058
  };
1468
2059
  export { FACTORY_DISPATCH_CONSTANTS, FactoryDecisionDispatcher };
1469
2060