@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 +1 @@
1
- {"version":3,"file":"binding-scope.js","names":[],"sources":["../../../src/integrations/jira/binding-scope.ts"],"sourcesContent":["import { bindingLabelSlice, bindingTakesIssue } from '../../storage/domains/intake/base.js';\nimport type { IntakeSourceBinding, IntakeStorage } from '../../storage/domains/intake/base.js';\nimport type { JiraIntakeScope } from './intake-jql.js';\n\n/** The selected Jira projects that feed one Factory project, and the slice of each it takes. */\nexport interface JiraProjectScope {\n /** Bound board per source id, for the rules that land new cards. */\n intakeBoards: Record<string, string>;\n /** One JQL scope per bound source, narrowed to this Factory's label slice. */\n scopes: JiraIntakeScope[];\n /** Whether an issue from `sourceId` carrying `labels` belongs to this Factory. */\n takes(sourceId: string, labels: readonly string[]): boolean;\n}\n\n/**\n * Narrow the caller's selected Jira projects to the ones that feed this\n * Factory project, with the label slice its binding takes from each.\n *\n * A Jira issue carries no Factory project of its own, so without a binding\n * every board view would ingest every selected project's issues into whichever\n * Factory happened to be on screen. Routing is explicit: a project feeds this\n * Factory only when its binding names both the Factory project and a board.\n * Several Factories may share a project; their slices are disjoint, so each\n * issue feeds exactly one of them. A sibling binding without a board does not\n * poll, so it takes nothing from the others' slices until its board is set.\n */\nexport async function scopeJiraSourcesToProject({\n intake,\n orgId,\n factoryProjectId,\n selectedIds,\n}: {\n intake: Pick<IntakeStorage, 'listBindings'>;\n orgId: string;\n factoryProjectId: string;\n selectedIds: readonly string[];\n}): Promise<JiraProjectScope> {\n const selected = new Set(selectedIds);\n const bySource = new Map<string, IntakeSourceBinding[]>();\n for (const binding of await intake.listBindings({ orgId, integrationId: 'jira' })) {\n bySource.set(binding.sourceId, [...(bySource.get(binding.sourceId) ?? []), binding]);\n }\n const intakeBoards: Record<string, string> = {};\n const scopes: JiraIntakeScope[] = [];\n const owned = new Map<string, { binding: IntakeSourceBinding; siblings: IntakeSourceBinding[] }>();\n for (const [sourceId, siblings] of bySource) {\n const binding = siblings.find(candidate => candidate.factoryProjectId === factoryProjectId);\n if (!binding?.board || !selected.has(sourceId)) continue;\n const active = siblings.filter(sibling => sibling.board);\n intakeBoards[sourceId] = binding.board;\n scopes.push({ projectId: sourceId, ...bindingLabelSlice(binding, active) });\n owned.set(sourceId, { binding, siblings: active });\n }\n return {\n intakeBoards,\n scopes,\n takes(sourceId, labels) {\n const entry = owned.get(sourceId);\n return entry !== undefined && bindingTakesIssue(entry.binding, entry.siblings, labels);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,eAAsB,0BAA0B,EAC9C,QACA,OACA,kBACA,eAM4B;CAC5B,MAAM,WAAW,IAAI,IAAI,WAAW;CACpC,MAAM,2BAAW,IAAI,IAAmC;CACxD,KAAK,MAAM,WAAW,MAAM,OAAO,aAAa;EAAE;EAAO,eAAe;CAAO,CAAC,GAC9E,SAAS,IAAI,QAAQ,UAAU,CAAC,GAAI,SAAS,IAAI,QAAQ,QAAQ,KAAK,CAAC,GAAI,OAAO,CAAC;CAErF,MAAM,eAAuC,CAAC;CAC9C,MAAM,SAA4B,CAAC;CACnC,MAAM,wBAAQ,IAAI,IAA+E;CACjG,KAAK,MAAM,CAAC,UAAU,aAAa,UAAU;EAC3C,MAAM,UAAU,SAAS,MAAK,cAAa,UAAU,qBAAqB,gBAAgB;EAC1F,IAAI,CAAC,SAAS,SAAS,CAAC,SAAS,IAAI,QAAQ,GAAG;EAChD,MAAM,SAAS,SAAS,QAAO,YAAW,QAAQ,KAAK;EACvD,aAAa,YAAY,QAAQ;EACjC,OAAO,KAAK;GAAE,WAAW;GAAU,GAAG,kBAAkB,SAAS,MAAM;EAAE,CAAC;EAC1E,MAAM,IAAI,UAAU;GAAE;GAAS,UAAU;EAAO,CAAC;CACnD;CACA,OAAO;EACL;EACA;EACA,MAAM,UAAU,QAAQ;GACtB,MAAM,QAAQ,MAAM,IAAI,QAAQ;GAChC,OAAO,UAAU,KAAA,KAAa,kBAAkB,MAAM,SAAS,MAAM,UAAU,MAAM;EACvF;CACF;AACF"}
1
+ {"version":3,"file":"binding-scope.js","names":[],"sources":["../../../src/integrations/jira/binding-scope.ts"],"sourcesContent":["import { bindingLabelSlice, bindingTakesIssue } from '../../storage/domains/intake/base.js';\nimport type { IntakeSourceBinding, IntakeStorage } from '../../storage/domains/intake/base.js';\nimport type { JiraIntakeScope } from './intake-jql.js';\n\n/** The selected Jira projects that feed one Factory project, and the slice of each it takes. */\nexport interface JiraProjectScope {\n /** The selected Jira projects bound to this Factory project. */\n sourceIds: string[];\n /** One JQL scope per bound source, narrowed to this Factory's label slice. */\n scopes: JiraIntakeScope[];\n /** Whether an issue from `sourceId` carrying `labels` belongs to this Factory. */\n takes(sourceId: string, labels: readonly string[]): boolean;\n}\n\n/**\n * Narrow the caller's selected Jira projects to the ones that feed this\n * Factory project, with the label slice its binding takes from each.\n *\n * A Jira issue carries no Factory project of its own, so without a binding\n * every board view would ingest every selected project's issues into whichever\n * Factory happened to be on screen. Routing is explicit: a project feeds this\n * Factory only when it is bound to the Factory project. Several Factories may\n * share a project; their slices are disjoint, so each issue feeds exactly one\n * of them.\n */\nexport async function scopeJiraSourcesToProject({\n intake,\n orgId,\n factoryProjectId,\n selectedIds,\n}: {\n intake: Pick<IntakeStorage, 'listBindings'>;\n orgId: string;\n factoryProjectId: string;\n selectedIds: readonly string[];\n}): Promise<JiraProjectScope> {\n const selected = new Set(selectedIds);\n const bySource = new Map<string, IntakeSourceBinding[]>();\n for (const binding of await intake.listBindings({ orgId, integrationId: 'jira' })) {\n bySource.set(binding.sourceId, [...(bySource.get(binding.sourceId) ?? []), binding]);\n }\n const sourceIds: string[] = [];\n const scopes: JiraIntakeScope[] = [];\n const owned = new Map<string, { binding: IntakeSourceBinding; siblings: IntakeSourceBinding[] }>();\n for (const [sourceId, siblings] of bySource) {\n const binding = siblings.find(candidate => candidate.factoryProjectId === factoryProjectId);\n if (!binding || !selected.has(sourceId)) continue;\n sourceIds.push(sourceId);\n scopes.push({ projectId: sourceId, ...bindingLabelSlice(binding, siblings) });\n owned.set(sourceId, { binding, siblings });\n }\n return {\n sourceIds,\n scopes,\n takes(sourceId, labels) {\n const entry = owned.get(sourceId);\n return entry !== undefined && bindingTakesIssue(entry.binding, entry.siblings, labels);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAyBA,eAAsB,0BAA0B,EAC9C,QACA,OACA,kBACA,eAM4B;CAC5B,MAAM,WAAW,IAAI,IAAI,WAAW;CACpC,MAAM,2BAAW,IAAI,IAAmC;CACxD,KAAK,MAAM,WAAW,MAAM,OAAO,aAAa;EAAE;EAAO,eAAe;CAAO,CAAC,GAC9E,SAAS,IAAI,QAAQ,UAAU,CAAC,GAAI,SAAS,IAAI,QAAQ,QAAQ,KAAK,CAAC,GAAI,OAAO,CAAC;CAErF,MAAM,YAAsB,CAAC;CAC7B,MAAM,SAA4B,CAAC;CACnC,MAAM,wBAAQ,IAAI,IAA+E;CACjG,KAAK,MAAM,CAAC,UAAU,aAAa,UAAU;EAC3C,MAAM,UAAU,SAAS,MAAK,cAAa,UAAU,qBAAqB,gBAAgB;EAC1F,IAAI,CAAC,WAAW,CAAC,SAAS,IAAI,QAAQ,GAAG;EACzC,UAAU,KAAK,QAAQ;EACvB,OAAO,KAAK;GAAE,WAAW;GAAU,GAAG,kBAAkB,SAAS,QAAQ;EAAE,CAAC;EAC5E,MAAM,IAAI,UAAU;GAAE;GAAS;EAAS,CAAC;CAC3C;CACA,OAAO;EACL;EACA;EACA,MAAM,UAAU,QAAQ;GACtB,MAAM,QAAQ,MAAM,IAAI,QAAQ;GAChC,OAAO,UAAU,KAAA,KAAa,kBAAkB,MAAM,SAAS,MAAM,UAAU,MAAM;EACvF;CACF;AACF"}
@@ -28,15 +28,7 @@ declare function jiraIssueObserved(context: FactoryJiraRuleContext): {
28
28
  readonly updatedAt: string;
29
29
  };
30
30
  } | undefined;
31
- declare function jiraIssueClosed(context: FactoryJiraRuleContext): {
32
- readonly type: 'transition';
33
- readonly idempotencyKey: `${string}:issue-closed`;
34
- readonly board: import("../../rules/types.js").FactoryRuleBoard;
35
- readonly stage: string;
36
- readonly message: {
37
- readonly text: `Jira issue ${string} was canceled; this ${string} card was moved to ${string}.` | `Jira issue ${string} was completed; this ${string} card was moved to ${string}.`;
38
- };
39
- } | undefined;
31
+ declare function jiraIssueClosed(context: FactoryJiraRuleContext): import("../../rules/types.js").FactoryTransitionDecision | undefined;
40
32
  export declare const defaultJiraRules: Readonly<{
41
33
  issueObserved: typeof jiraIssueObserved;
42
34
  issueClosed: typeof jiraIssueClosed;
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/default-rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE7G,MAAM,MAAM,iBAAiB,GAAG,OAAO,CACrC,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,sBAAsB,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,CAC5F,CAAC;AACF,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,sBAAsB,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAEvH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,sBAAsB;mBAGhD,sBAAsB;;;qBAKpB,YAAY;;;;;;iBAMlB,UAAU;iBACV,QAAQ;iBACR,eAAe;iBACf,KAAK;iBACL,SAAS;iBACT,QAAQ;iBACR,OAAO;iBACP,IAAI;iBACJ,QAAQ;iBACR,SAAS,EAA8D,MAAM,EAAE;iBAC/E,OAAO;iBACP,MAAM;iBACN,MAAM,EAA+B,MAAM,EAAE;iBAC7C,SAAS;iBACT,SAAS;;cAGd;AAED,iBAAS,eAAe,CAAC,OAAO,EAAE,sBAAsB;mBAY9C,YAAY;;;;;iBAKhB,IAAI;;cAGT;AAED,eAAO,MAAM,gBAAgB;;;EAGF,CAAC;AAE5B,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,iBAAiB,GAAG,cAAc,CAsB9E"}
1
+ {"version":3,"file":"default-rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/default-rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE7G,MAAM,MAAM,iBAAiB,GAAG,OAAO,CACrC,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,sBAAsB,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,CAC5F,CAAC;AACF,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,sBAAsB,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;AAEvH,iBAAS,iBAAiB,CAAC,OAAO,EAAE,sBAAsB;mBAGhD,sBAAsB;;;qBAIpB,YAAY;;;;;;iBAMlB,UAAU;iBACV,QAAQ;iBACR,eAAe;iBACf,KAAK;iBACL,SAAS;iBACT,QAAQ;iBACR,OAAO;iBACP,IAAI;iBACJ,QAAQ;iBACR,SAAS,EAA8D,MAAM,EAAE;iBAC/E,OAAO;iBACP,MAAM;iBACN,MAAM,EAA+B,MAAM,EAAE;iBAC7C,SAAS;iBACT,SAAS;;cAGd;AAED,iBAAS,eAAe,CAAC,OAAO,EAAE,sBAAsB,wEAoBvD;AAED,eAAO,MAAM,gBAAgB;;;EAGF,CAAC;AAE5B,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,iBAAiB,GAAG,cAAc,CAsB9E"}
@@ -1,16 +1,16 @@
1
- import { recordExplicitRuleOverrides } from "../../rules/event-rules.js";
1
+ import { closedByRoutes, recordExplicitRuleOverrides } from "../../rules/event-rules.js";
2
2
  // src/integrations/jira/default-rules.ts
3
3
  function jiraIssueObserved(context) {
4
- if (context.item) return;
4
+ if (context.item || !context.intake) return;
5
5
  return {
6
6
  type: "upsertLinkedWorkItem",
7
7
  idempotencyKey: `${context.ingress.id}:issue-triage`,
8
- board: context.intake?.board ?? "work",
8
+ board: context.intake.board,
9
9
  source: "jira-issue",
10
10
  sourceKey: context.issue.id,
11
11
  title: context.issue.title,
12
12
  url: context.issue.url,
13
- stage: context.intake?.initialPhase ?? "intake",
13
+ stage: context.intake.initialPhase,
14
14
  metadata: {
15
15
  identifier: context.issue.identifier,
16
16
  issueRef: context.issue.id,
@@ -38,13 +38,12 @@ function jiraIssueClosed(context) {
38
38
  if (stateType !== "completed" && stateType !== "canceled") return;
39
39
  const canceled = stateType === "canceled";
40
40
  const target = canceled ? closure.canceled : closure.completed;
41
- return {
42
- type: "transition",
41
+ return closedByRoutes(canceled, {
43
42
  idempotencyKey: `${context.ingress.id}:issue-closed`,
44
43
  board: context.board,
45
44
  stage: target.phase,
46
45
  message: { text: `Jira issue ${context.issue.identifier} was ${canceled ? "canceled" : "completed"}; this ${closure.boardTitle} card was moved to ${target.title}.` }
47
- };
46
+ });
48
47
  }
49
48
  const defaultJiraRules = Object.freeze({
50
49
  issueObserved: jiraIssueObserved,
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/jira/default-rules.ts"],"sourcesContent":["import { recordExplicitRuleOverrides } from '../../rules/event-rules.js';\nimport type { FactoryJiraEventName, FactoryJiraRuleContext, FactoryRuleHandler } from '../../rules/types.js';\n\nexport type JiraRuleOverrides = Partial<\n Record<FactoryJiraEventName, FactoryRuleHandler<FactoryJiraRuleContext> | null | undefined>\n>;\nexport type JiraEventRules = Readonly<Record<FactoryJiraEventName, FactoryRuleHandler<FactoryJiraRuleContext> | null>>;\n\nfunction jiraIssueObserved(context: FactoryJiraRuleContext) {\n if (context.item) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-triage`,\n // A source bound to a custom board lands on that board's initial phase;\n // otherwise the issue waits in Work Intake.\n board: context.intake?.board ?? 'work',\n source: 'jira-issue',\n sourceKey: context.issue.id,\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake?.initialPhase ?? 'intake',\n metadata: {\n identifier: context.issue.identifier,\n issueRef: context.issue.id,\n sourceCreatedAt: context.issue.createdAt,\n state: context.issue.state,\n stateType: context.issue.stateType,\n priority: context.issue.priorityLabel,\n project: context.issue.project,\n site: context.issue.site,\n assignee: context.issue.assignee,\n assignees: (context.issue.assignee ? [context.issue.assignee] : []) as string[],\n creator: context.issue.author,\n author: context.issue.author,\n labels: [...context.issue.labels] as string[],\n createdAt: context.issue.createdAt,\n updatedAt: context.issue.updatedAt,\n },\n } as const;\n}\n\nfunction jiraIssueClosed(context: FactoryJiraRuleContext) {\n if (!context.item || context.item.source !== 'jira-issue') return;\n // The card's board decides where a closed source sends it; boards that declare no\n // `sourceClosed` mapping keep the card where it is, as do cards already finished.\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // Only terminal state types trigger close.\n const stateType = context.issue.stateType;\n if (stateType !== 'completed' && stateType !== 'canceled') return;\n const canceled = stateType === 'canceled';\n const target = canceled ? closure.canceled : closure.completed;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: target.phase,\n message: {\n text: `Jira issue ${context.issue.identifier} was ${canceled ? 'canceled' : 'completed'}; this ${closure.boardTitle} card was moved to ${target.title}.`,\n },\n } as const;\n}\n\nexport const defaultJiraRules = Object.freeze({\n issueObserved: jiraIssueObserved,\n issueClosed: jiraIssueClosed,\n} satisfies JiraEventRules);\n\nexport function resolveJiraRules(overrides?: JiraRuleOverrides): JiraEventRules {\n if (\n overrides !== undefined &&\n (overrides === null ||\n typeof overrides !== 'object' ||\n Array.isArray(overrides) ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(overrides)))\n ) {\n throw new Error('Jira rules must be a plain object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryJiraRuleContext> | null> = { ...defaultJiraRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultJiraRules, key)) {\n throw new Error(`Unknown Jira rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryJiraEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`Jira rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as JiraEventRules, overrides);\n}\n"],"mappings":";;AAQA,SAAS,kBAAkB,SAAiC;CAC1D,IAAI,QAAQ,MAAM;CAClB,OAAO;EACL,MAAM;EACN,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EAGtC,OAAO,QAAQ,QAAQ,SAAS;EAChC,QAAQ;EACR,WAAW,QAAQ,MAAM;EACzB,OAAO,QAAQ,MAAM;EACrB,KAAK,QAAQ,MAAM;EACnB,OAAO,QAAQ,QAAQ,gBAAgB;EACvC,UAAU;GACR,YAAY,QAAQ,MAAM;GAC1B,UAAU,QAAQ,MAAM;GACxB,iBAAiB,QAAQ,MAAM;GAC/B,OAAO,QAAQ,MAAM;GACrB,WAAW,QAAQ,MAAM;GACzB,UAAU,QAAQ,MAAM;GACxB,SAAS,QAAQ,MAAM;GACvB,MAAM,QAAQ,MAAM;GACpB,UAAU,QAAQ,MAAM;GACxB,WAAY,QAAQ,MAAM,WAAW,CAAC,QAAQ,MAAM,QAAQ,IAAI,CAAC;GACjE,SAAS,QAAQ,MAAM;GACvB,QAAQ,QAAQ,MAAM;GACtB,QAAQ,CAAC,GAAG,QAAQ,MAAM,MAAM;GAChC,WAAW,QAAQ,MAAM;GACzB,WAAW,QAAQ,MAAM;EAC3B;CACF;AACF;AAEA,SAAS,gBAAgB,SAAiC;CACxD,IAAI,CAAC,QAAQ,QAAQ,QAAQ,KAAK,WAAW,cAAc;CAG3D,MAAM,UAAU,QAAQ;CACxB,IAAI,CAAC,QAAQ,SAAS,CAAC,WAAW,QAAQ,cAAc;CAExD,MAAM,YAAY,QAAQ,MAAM;CAChC,IAAI,cAAc,eAAe,cAAc,YAAY;CAC3D,MAAM,WAAW,cAAc;CAC/B,MAAM,SAAS,WAAW,QAAQ,WAAW,QAAQ;CACrD,OAAO;EACL,MAAM;EACN,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EACtC,OAAO,QAAQ;EACf,OAAO,OAAO;EACd,SAAS,EACP,MAAM,cAAc,QAAQ,MAAM,WAAW,OAAO,WAAW,aAAa,YAAY,SAAS,QAAQ,WAAW,qBAAqB,OAAO,MAAM,GACxJ;CACF;AACF;AAEA,MAAa,mBAAmB,OAAO,OAAO;CAC5C,eAAe;CACf,aAAa;AACf,CAA0B;AAE1B,SAAgB,iBAAiB,WAA+C;CAC9E,IACE,cAAc,KAAA,MACb,cAAc,QACb,OAAO,cAAc,YACrB,MAAM,QAAQ,SAAS,KACvB,CAAC,CAAC,OAAO,WAAW,IAAI,CAAC,CAAC,SAAS,OAAO,eAAe,SAAS,CAAC,IAErE,MAAM,IAAI,MAAM,oCAAoC;CAEtD,MAAM,QAA2E,EAAE,GAAG,iBAAiB;CACvG,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,kBAAkB,GAAG,GACjE,MAAM,IAAI,MAAM,4BAA4B,OAAO,GAAG,EAAE,EAAE;EAE5D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,aAAa,IAAI,yCAAyC;EAE5E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAqB,SAAS;AACtF"}
1
+ {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/jira/default-rules.ts"],"sourcesContent":["import { closedByRoutes, recordExplicitRuleOverrides } from '../../rules/event-rules.js';\nimport type { FactoryJiraEventName, FactoryJiraRuleContext, FactoryRuleHandler } from '../../rules/types.js';\n\nexport type JiraRuleOverrides = Partial<\n Record<FactoryJiraEventName, FactoryRuleHandler<FactoryJiraRuleContext> | null | undefined>\n>;\nexport type JiraEventRules = Readonly<Record<FactoryJiraEventName, FactoryRuleHandler<FactoryJiraRuleContext> | null>>;\n\nfunction jiraIssueObserved(context: FactoryJiraRuleContext) {\n if (context.item || !context.intake) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-triage`,\n // Filed on the default board's first phase; the project's intake routes place it from there.\n board: context.intake.board,\n source: 'jira-issue',\n sourceKey: context.issue.id,\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake.initialPhase,\n metadata: {\n identifier: context.issue.identifier,\n issueRef: context.issue.id,\n sourceCreatedAt: context.issue.createdAt,\n state: context.issue.state,\n stateType: context.issue.stateType,\n priority: context.issue.priorityLabel,\n project: context.issue.project,\n site: context.issue.site,\n assignee: context.issue.assignee,\n assignees: (context.issue.assignee ? [context.issue.assignee] : []) as string[],\n creator: context.issue.author,\n author: context.issue.author,\n labels: [...context.issue.labels] as string[],\n createdAt: context.issue.createdAt,\n updatedAt: context.issue.updatedAt,\n },\n } as const;\n}\n\nfunction jiraIssueClosed(context: FactoryJiraRuleContext) {\n if (!context.item || context.item.source !== 'jira-issue') return;\n // The project's intake routes decide where a closed source sends the card. The board's\n // `sourceClosed` mapping applies only when no route on the board handles closes; without\n // one the close goes to the routes alone (see `routeEventDecision`).\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // Only terminal state types trigger close.\n const stateType = context.issue.stateType;\n if (stateType !== 'completed' && stateType !== 'canceled') return;\n const canceled = stateType === 'canceled';\n const target = canceled ? closure.canceled : closure.completed;\n return closedByRoutes(canceled, {\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: target.phase,\n message: {\n text: `Jira issue ${context.issue.identifier} was ${canceled ? 'canceled' : 'completed'}; this ${closure.boardTitle} card was moved to ${target.title}.`,\n },\n });\n}\n\nexport const defaultJiraRules = Object.freeze({\n issueObserved: jiraIssueObserved,\n issueClosed: jiraIssueClosed,\n} satisfies JiraEventRules);\n\nexport function resolveJiraRules(overrides?: JiraRuleOverrides): JiraEventRules {\n if (\n overrides !== undefined &&\n (overrides === null ||\n typeof overrides !== 'object' ||\n Array.isArray(overrides) ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(overrides)))\n ) {\n throw new Error('Jira rules must be a plain object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryJiraRuleContext> | null> = { ...defaultJiraRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultJiraRules, key)) {\n throw new Error(`Unknown Jira rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryJiraEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`Jira rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as JiraEventRules, overrides);\n}\n"],"mappings":";;AAQA,SAAS,kBAAkB,SAAiC;CAC1D,IAAI,QAAQ,QAAQ,CAAC,QAAQ,QAAQ;CACrC,OAAO;EACL,MAAM;EACN,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EAEtC,OAAO,QAAQ,OAAO;EACtB,QAAQ;EACR,WAAW,QAAQ,MAAM;EACzB,OAAO,QAAQ,MAAM;EACrB,KAAK,QAAQ,MAAM;EACnB,OAAO,QAAQ,OAAO;EACtB,UAAU;GACR,YAAY,QAAQ,MAAM;GAC1B,UAAU,QAAQ,MAAM;GACxB,iBAAiB,QAAQ,MAAM;GAC/B,OAAO,QAAQ,MAAM;GACrB,WAAW,QAAQ,MAAM;GACzB,UAAU,QAAQ,MAAM;GACxB,SAAS,QAAQ,MAAM;GACvB,MAAM,QAAQ,MAAM;GACpB,UAAU,QAAQ,MAAM;GACx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MAAM,IAAI,MAAM,4BAA4B,OAAO,GAAG,EAAE,EAAE;EAE5D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,aAAa,IAAI,yCAAyC;EAE5E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAqB,SAAS;AACtF"}
@@ -1 +1 @@
1
- {"version":3,"file":"issue-reconciler.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/issue-reconciler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIzD,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAqBlD,wBAAgB,yBAAyB,CACvC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,cAAc,CAAA;CAAE,EAC/C,OAAO,EAAE,kBAAkB,GAC1B,mBAAmB,GAAG,SAAS,CA4CjC"}
1
+ {"version":3,"file":"issue-reconciler.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/issue-reconciler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIzD,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAqBlD,wBAAgB,yBAAyB,CACvC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,cAAc,CAAA;CAAE,EAC/C,OAAO,EAAE,kBAAkB,GAC1B,mBAAmB,GAAG,SAAS,CA4CjC"}
@@ -1,5 +1,6 @@
1
1
  import { workItemPhaseSemantics } from "../../boards/semantics.js";
2
2
  import "../../boards/index.js";
3
+ import { toBoardSource } from "../../boards/project-boards.js";
3
4
  import { createIssueReconciler } from "../issue-reconciler.js";
4
5
  import { JiraRules } from "./rules.js";
5
6
  // src/integrations/jira/issue-reconciler.ts
@@ -36,7 +37,7 @@ function attachJiraIssueReconciler(jira, context) {
36
37
  intake: jira.intake,
37
38
  projects: context.storage.projects,
38
39
  storage: context.runtime.workItems,
39
- isTerminal: (item) => workItemPhaseSemantics(boards, item)?.kind === "terminal",
40
+ isTerminal: (item) => workItemPhaseSemantics(toBoardSource(boards).forProject(item), item)?.kind === "terminal",
40
41
  issueId: (item) => item.externalSource?.externalId,
41
42
  metadata: (item, issue) => ({
42
43
  identifier: issue.identifier,
@@ -1 +1 @@
1
- {"version":3,"file":"issue-reconciler.js","names":[],"sources":["../../../src/integrations/jira/issue-reconciler.ts"],"sourcesContent":["import { workItemPhaseSemantics } from '../../boards/index.js';\nimport type { Intake, IntakeIssue } from '../../capabilities/intake.js';\nimport type { IntegrationContext } from '../base.js';\nimport { createIssueReconciler } from '../issue-reconciler.js';\nimport type { IssueReconciler } from '../issue-reconciler.js';\nimport type { JiraEventRules } from './default-rules.js';\nimport { JiraRules } from './rules.js';\nimport type { JiraIssueIngress } from './rules.js';\n\nexport type JiraIssueReconciler = IssueReconciler;\n\nfunction issueToIngress(issueRef: string, issue: IntakeIssue): JiraIssueIngress {\n return {\n id: issueRef,\n identifier: issue.identifier,\n title: issue.title,\n url: issue.url,\n state: issue.state ?? '',\n stateType: issue.stateType ?? '',\n priorityLabel: issue.priority ?? '',\n assignee: issue.assignee ?? null,\n author: issue.author ?? null,\n project: issue.source ?? null,\n site: null,\n labels: [...(issue.labels ?? [])],\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n };\n}\n\nexport function attachJiraIssueReconciler(\n jira: { intake: Intake; rules: JiraEventRules },\n context: IntegrationContext,\n): JiraIssueReconciler | undefined {\n if (!context.runtime || !jira.intake.resolveIntakeDispatch) return undefined;\n const boards = context.runtime.boards;\n\n const rules = new JiraRules({\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n configVersion: context.runtime.configVersion,\n boards,\n jiraRules: jira.rules,\n });\n\n return createIssueReconciler({\n integrationId: 'jira',\n intake: jira.intake,\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n isTerminal: item => workItemPhaseSemantics(boards, item)?.kind === 'terminal',\n issueId: item => item.externalSource?.externalId,\n metadata: (item, issue) => ({\n identifier: issue.identifier,\n issueRef: item.externalSource?.externalId ?? issue.id,\n autoStartCandidate: issue.stateType === 'unstarted' || issue.stateType === 'started',\n state: issue.state,\n stateType: issue.stateType,\n priority: issue.priority,\n project: issue.source,\n assignee: issue.assignee,\n assignees: issue.assignees ?? [],\n creator: issue.author,\n author: issue.author,\n labels: issue.labels ?? [],\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n }),\n onClosed: async (item, issue, project) => {\n await rules.ingest({\n orgId: project.orgId,\n userId: 'factory-rule-dispatcher',\n factoryProjectId: project.id,\n issues: [issueToIngress(item.externalSource?.externalId ?? issue.id, issue)],\n });\n },\n });\n}\n"],"mappings":";;;;;AAWA,SAAS,eAAe,UAAkB,OAAsC;CAC9E,OAAO;EACL,IAAI;EACJ,YAAY,MAAM;EAClB,OAAO,MAAM;EACb,KAAK,MAAM;EACX,OAAO,MAAM,SAAS;EACtB,WAAW,MAAM,aAAa;EAC9B,eAAe,MAAM,YAAY;EACjC,UAAU,MAAM,YAAY;EAC5B,QAAQ,MAAM,UAAU;EACxB,SAAS,MAAM,UAAU;EACzB,MAAM;EACN,QAAQ,CAAC,GAAI,MAAM,UAAU,CAAC,CAAE;EAChC,WAAW,MAAM;EACjB,WAAW,MAAM;CACnB;AACF;AAEA,SAAgB,0BACd,MACA,SACiC;CACjC,IAAI,CAAC,QAAQ,WAAW,CAAC,KAAK,OAAO,uBAAuB,OAAO,KAAA;CACnE,MAAM,SAAS,QAAQ,QAAQ;CAE/B,MAAM,QAAQ,IAAI,UAAU;EAC1B,UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,QAAQ;EACzB,eAAe,QAAQ,QAAQ;EAC/B;EACA,WAAW,KAAK;CAClB,CAAC;CAED,OAAO,sBAAsB;EAC3B,eAAe;EACf,QAAQ,KAAK;EACb,UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,QAAQ;EACzB,aAAY,SAAQ,uBAAuB,QAAQ,IAAI,CAAC,EAAE,SAAS;EACnE,UAAS,SAAQ,KAAK,gBAAgB;EACtC,WAAW,MAAM,WAAW;GAC1B,YAAY,MAAM;GAClB,UAAU,KAAK,gBAAgB,cAAc,MAAM;GACnD,oBAAoB,MAAM,cAAc,eAAe,MAAM,cAAc;GAC3E,OAAO,MAAM;GACb,WAAW,MAAM;GACjB,UAAU,MAAM;GAChB,SAAS,MAAM;GACf,UAAU,MAAM;GAChB,WAAW,MAAM,aAAa,CAAC;GAC/B,SAAS,MAAM;GACf,QAAQ,MAAM;GACd,QAAQ,MAAM,UAAU,CAAC;GACzB,WAAW,MAAM;GACjB,WAAW,MAAM;EACnB;EACA,UAAU,OAAO,MAAM,OAAO,YAAY;GACxC,MAAM,MAAM,OAAO;IACjB,OAAO,QAAQ;IACf,QAAQ;IACR,kBAAkB,QAAQ;IAC1B,QAAQ,CAAC,eAAe,KAAK,gBAAgB,cAAc,MAAM,IAAI,KAAK,CAAC;GAC7E,CAAC;EACH;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"issue-reconciler.js","names":[],"sources":["../../../src/integrations/jira/issue-reconciler.ts"],"sourcesContent":["import { workItemPhaseSemantics } from '../../boards/index.js';\nimport { toBoardSource } from '../../boards/project-boards.js';\nimport type { Intake, IntakeIssue } from '../../capabilities/intake.js';\nimport type { IntegrationContext } from '../base.js';\nimport { createIssueReconciler } from '../issue-reconciler.js';\nimport type { IssueReconciler } from '../issue-reconciler.js';\nimport type { JiraEventRules } from './default-rules.js';\nimport { JiraRules } from './rules.js';\nimport type { JiraIssueIngress } from './rules.js';\n\nexport type JiraIssueReconciler = IssueReconciler;\n\nfunction issueToIngress(issueRef: string, issue: IntakeIssue): JiraIssueIngress {\n return {\n id: issueRef,\n identifier: issue.identifier,\n title: issue.title,\n url: issue.url,\n state: issue.state ?? '',\n stateType: issue.stateType ?? '',\n priorityLabel: issue.priority ?? '',\n assignee: issue.assignee ?? null,\n author: issue.author ?? null,\n project: issue.source ?? null,\n site: null,\n labels: [...(issue.labels ?? [])],\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n };\n}\n\nexport function attachJiraIssueReconciler(\n jira: { intake: Intake; rules: JiraEventRules },\n context: IntegrationContext,\n): JiraIssueReconciler | undefined {\n if (!context.runtime || !jira.intake.resolveIntakeDispatch) return undefined;\n const boards = context.runtime.boards;\n\n const rules = new JiraRules({\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n configVersion: context.runtime.configVersion,\n boards,\n jiraRules: jira.rules,\n });\n\n return createIssueReconciler({\n integrationId: 'jira',\n intake: jira.intake,\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n isTerminal: item => workItemPhaseSemantics(toBoardSource(boards).forProject(item), item)?.kind === 'terminal',\n issueId: item => item.externalSource?.externalId,\n metadata: (item, issue) => ({\n identifier: issue.identifier,\n issueRef: item.externalSource?.externalId ?? issue.id,\n autoStartCandidate: issue.stateType === 'unstarted' || issue.stateType === 'started',\n state: issue.state,\n stateType: issue.stateType,\n priority: issue.priority,\n project: issue.source,\n assignee: issue.assignee,\n assignees: issue.assignees ?? [],\n creator: issue.author,\n author: issue.author,\n labels: issue.labels ?? [],\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n }),\n onClosed: async (item, issue, project) => {\n await rules.ingest({\n orgId: project.orgId,\n userId: 'factory-rule-dispatcher',\n factoryProjectId: project.id,\n issues: [issueToIngress(item.externalSource?.externalId ?? issue.id, issue)],\n });\n },\n });\n}\n"],"mappings":";;;;;;AAYA,SAAS,eAAe,UAAkB,OAAsC;CAC9E,OAAO;EACL,IAAI;EACJ,YAAY,MAAM;EAClB,OAAO,MAAM;EACb,KAAK,MAAM;EACX,OAAO,MAAM,SAAS;EACtB,WAAW,MAAM,aAAa;EAC9B,eAAe,MAAM,YAAY;EACjC,UAAU,MAAM,YAAY;EAC5B,QAAQ,MAAM,UAAU;EACxB,SAAS,MAAM,UAAU;EACzB,MAAM;EACN,QAAQ,CAAC,GAAI,MAAM,UAAU,CAAC,CAAE;EAChC,WAAW,MAAM;EACjB,WAAW,MAAM;CACnB;AACF;AAEA,SAAgB,0BACd,MACA,SACiC;CACjC,IAAI,CAAC,QAAQ,WAAW,CAAC,KAAK,OAAO,uBAAuB,OAAO,KAAA;CACnE,MAAM,SAAS,QAAQ,QAAQ;CAE/B,MAAM,QAAQ,IAAI,UAAU;EAC1B,UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,QAAQ;EACzB,eAAe,QAAQ,QAAQ;EAC/B;EACA,WAAW,KAAK;CAClB,CAAC;CAED,OAAO,sBAAsB;EAC3B,eAAe;EACf,QAAQ,KAAK;EACb,UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,QAAQ;EACzB,aAAY,SAAQ,uBAAuB,cAAc,MAAM,CAAC,CAAC,WAAW,IAAI,GAAG,IAAI,CAAC,EAAE,SAAS;EACnG,UAAS,SAAQ,KAAK,gBAAgB;EACtC,WAAW,MAAM,WAAW;GAC1B,YAAY,MAAM;GAClB,UAAU,KAAK,gBAAgB,cAAc,MAAM;GACnD,oBAAoB,MAAM,cAAc,eAAe,MAAM,cAAc;GAC3E,OAAO,MAAM;GACb,WAAW,MAAM;GACjB,UAAU,MAAM;GAChB,SAAS,MAAM;GACf,UAA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AAE,CAkO3E"}
@@ -1,3 +1,4 @@
1
+ import { loose } from "../../routes/route.js";
1
2
  import { JiraApiError } from "./api.js";
2
3
  import { scopeJiraSourcesToProject } from "./binding-scope.js";
3
4
  import { unfilteredJiraScopes } from "./intake-jql.js";
@@ -6,10 +7,6 @@ import { registerApiRoute } from "@mastra/core/server";
6
7
  // src/integrations/jira/routes.ts
7
8
  const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
8
9
  const ISSUE_KEY_RE = /^[A-Za-z][A-Za-z0-9_]*-\d+$/;
9
- /** Erase a route handler's path-parameterized context to a plain `Context`. */
10
- function loose(c) {
11
- return c;
12
- }
13
10
  /**
14
11
  * Resolve the org-scoped tenant for a Jira request. Intake selections are
15
12
  * org-owned, so it requires both a signed-in user and an organization — same
@@ -145,7 +142,6 @@ function buildJiraRoutes(options) {
145
142
  factoryProjectId,
146
143
  selectedIds
147
144
  }) : null;
148
- const intakeBoards = projectScope?.intakeBoards ?? null;
149
145
  const scopes = projectScope?.scopes ?? unfilteredJiraScopes(selectedIds);
150
146
  if (scopes.length === 0) return c.json({
151
147
  issues: [],
@@ -169,15 +165,14 @@ function buildJiraRoutes(options) {
169
165
  updatedAt: issue.updatedAt,
170
166
  sourceId: issue.sourceId || null
171
167
  }));
172
- if (factoryProjectId && intakeBoards && options.ingestFactoryIssues) await options.ingestFactoryIssues({
168
+ if (factoryProjectId && projectScope && options.ingestFactoryIssues) await options.ingestFactoryIssues({
173
169
  orgId: resolved.tenant.orgId,
174
170
  userId: resolved.tenant.userId,
175
171
  factoryProjectId,
176
172
  issues: issuePayload.map((issue) => ({
177
173
  ...issue,
178
174
  site: null
179
- })),
180
- intakeBoards
175
+ }))
181
176
  });
182
177
  return c.json({
183
178
  issues: issuePayload,
@@ -221,7 +216,7 @@ function buildJiraRoutes(options) {
221
216
  connection: DEPLOYMENT_CONNECTION,
222
217
  issueId: issueRef
223
218
  });
224
- const routed = issue?.sourceId != null && issue.sourceId in projectScope.intakeBoards && (projectScope.takes(issue.sourceId, issue.labels) || !!await workItems?.getByProjectSource({
219
+ const routed = issue?.sourceId != null && projectScope.sourceIds.includes(issue.sourceId) && (projectScope.takes(issue.sourceId, issue.labels) || !!await workItems?.getByProjectSource({
225
220
  orgId: resolved.tenant.orgId,
226
221
  factoryProjectId,
227
222
  source: {
@@ -1 +1 @@
1
- {"version":3,"file":"routes.js","names":[],"sources":["../../../src/integrations/jira/routes.ts"],"sourcesContent":["/**\n * Mastra `apiRoutes` for the Jira intake feature.\n *\n * Registered alongside the other `/web/*` routes, behind the host auth gate.\n * Mirrors the Linear module minus everything OAuth: there is no\n * connect/callback flow, no state signer, and no per-org connection storage —\n * Jira credentials are deployment-global constructor config on the\n * integration instance. Every route still re-resolves the authenticated user\n * from the request and scopes intake selections by the caller's org.\n *\n * When the feature is disabled (no auth, or no intake storage),\n * `buildJiraRoutes` returns only `GET /web/jira/status`, which reports\n * `enabled:false` so the SPA can cleanly hide all Jira UI.\n */\n\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\n\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { IntakeStorage } from '../../storage/domains/intake/base.js';\nimport type { WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport { JiraApiError } from './api.js';\nimport { scopeJiraSourcesToProject } from './binding-scope.js';\nimport { unfilteredJiraScopes } from './intake-jql.js';\nimport { DEPLOYMENT_CONNECTION } from './integration.js';\nimport type { JiraIntegration } from './integration.js';\nimport type { JiraRulesIngress } from './rules.js';\n\ntype RouteContext = Context;\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nconst ISSUE_KEY_RE = /^[A-Za-z][A-Za-z0-9_]*-\\d+$/;\n\n/** Erase a route handler's path-parameterized context to a plain `Context`. */\nfunction loose(c: unknown): RouteContext {\n return c as RouteContext;\n}\n\n/**\n * Non-secret diagnostic snapshot of every Jira feature gate, mirroring the\n * Linear diagnostics shape. Only booleans — never values.\n */\nexport interface JiraFeatureDiagnostics {\n jiraConfigured: boolean;\n factoryAuthEnabled: boolean;\n appDbConfigured: boolean;\n}\n\nexport interface MountJiraRoutesOptions {\n /**\n * The integration instance providing REST access. Required for everything\n * beyond the disabled `status` route.\n */\n jira?: JiraIntegration;\n /** Host auth seam. Intake selections are org-owned, so the feature is inert without it. */\n auth: RouteAuth;\n /**\n * Cross-integration intake selection domain. Required for the issues route's\n * project filter; when absent, only the disabled `status` route is served.\n */\n intake?: IntakeStorage;\n /**\n * Factory rules ingress for observed issues. When present, a board-scoped\n * issue listing also materializes new cards through the Jira event rules —\n * the same automatic intake Linear has.\n */\n ingestFactoryIssues?: (input: JiraRulesIngress) => Promise<unknown>;\n /** Filed cards, so a Factory keeps reading issues it filed after a label filter moves them to another slice. */\n workItems?: Pick<WorkItemsStorage, 'getByProjectSource'>;\n}\n\n/**\n * Resolve the org-scoped tenant for a Jira request. Intake selections are\n * org-owned, so it requires both a signed-in user and an organization — same\n * tenancy rules as the Linear routes.\n */\nasync function resolveOrgTenant(\n c: RouteContext,\n auth: RouteAuth,\n): Promise<{ tenant: { orgId: string; userId: string } } | { response: Response }> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return { response: c.json({ error: 'unauthorized' }, 401) };\n if (!tenant.orgId) {\n return {\n response: c.json(\n {\n error: 'organization_required',\n message: 'Jira intake requires an organization. Personal accounts cannot use Jira intake.',\n },\n 403,\n ),\n };\n }\n return { tenant: { orgId: tenant.orgId, userId: tenant.userId } };\n}\n\n/**\n * Validate an opaque Jira pagination cursor from the query string. Cursors are\n * server-issued (`nextPageToken`), so anything outside a conservative\n * charset/length is rejected rather than forwarded to Jira.\n */\nfunction parseAfterCursor(raw: string | undefined): string | undefined | null {\n if (raw === undefined || raw === '') return undefined;\n if (raw.length > 512 || !/^[\\w+/=.:-]+$/.test(raw)) return null;\n return raw;\n}\n\n/** Map a Jira read failure to the API response for the SPA. */\nfunction jiraFetchError(c: RouteContext, err: unknown) {\n if (err instanceof JiraApiError && err.code === 'jira_auth_failed') {\n return c.json(\n {\n error: 'jira_auth_failed',\n message: 'Jira rejected the configured credentials. Check JIRA_EMAIL and JIRA_API_TOKEN.',\n },\n 409,\n );\n }\n return c.json({ error: 'jira_fetch_failed', message: err instanceof Error ? err.message : String(err) }, 502);\n}\n\n/**\n * Build the Jira routes as Mastra `apiRoutes`. When the feature is disabled,\n * returns only the `status` route so the SPA can detect the disabled state.\n */\nexport function buildJiraRoutes(options: MountJiraRoutesOptions): ApiRoute[] {\n const routes: ApiRoute[] = [];\n const { jira, auth, intake, workItems } = options;\n const enabled = Boolean(jira) && auth.enabled();\n const diagnostics = (): JiraFeatureDiagnostics => ({\n jiraConfigured: Boolean(jira),\n factoryAuthEnabled: auth.enabled(),\n appDbConfigured: true,\n });\n\n // The status route is always registered so the SPA can detect the disabled state.\n routes.push(\n registerApiRoute('/web/jira/status', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n if (!enabled || !jira || !intake) {\n return c.json({\n enabled: false,\n configured: Boolean(jira),\n mode: 'direct',\n site: null,\n reason: 'missing_config',\n diagnostics: diagnostics(),\n });\n }\n await auth.ensureUser(loose(c));\n const tenant = auth.tenant(loose(c));\n if (!tenant) return c.json({ error: 'unauthorized', reason: 'auth_required' }, 401);\n\n const site = new URL(jira.baseUrl).host;\n if (!tenant.orgId) {\n return c.json({\n enabled: true,\n configured: true,\n mode: 'direct',\n organizationRequired: true,\n site,\n reason: 'organization_required',\n diagnostics: diagnostics(),\n });\n }\n\n // Deployment-global credentials: configured means ready — there is no\n // per-org connection step like Linear's OAuth.\n return c.json({\n enabled: true,\n configured: true,\n mode: 'direct',\n site,\n reason: 'ready',\n diagnostics: diagnostics(),\n });\n },\n }),\n );\n\n // Without the integration instance or the intake domain the feature can't\n // serve org-scoped data — serve only the disabled `status` route.\n if (!enabled || !jira || !intake) {\n return routes;\n }\n\n // ── List the site's projects (Settings intake-source picker) ────────────\n routes.push(\n registerApiRoute('/web/jira/projects', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n\n try {\n const sources = await jira.intake.listSources(resolved.tenant);\n return c.json({\n projects: sources.map(source => ({\n id: source.id,\n name: source.name,\n key: typeof source.metadata?.key === 'string' ? source.metadata.key : null,\n })),\n });\n } catch (err) {\n return jiraFetchError(loose(c), err);\n }\n },\n }),\n );\n\n // ── List the site's active issues (cursor-paged) ────────────────────────\n // Respects the caller's intake config: disabled Jira intake 404s the\n // source, and an explicit project selection narrows the issue filter.\n routes.push(\n registerApiRoute('/web/jira/issues', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n\n const after = parseAfterCursor(c.req.query('after'));\n if (after === null) return c.json({ error: 'invalid_cursor' }, 400);\n const factoryProjectId = c.req.query('factoryProjectId');\n if (factoryProjectId && !UUID_RE.test(factoryProjectId)) {\n return c.json({ error: 'invalid_factory_project_id' }, 400);\n }\n\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId: resolved.tenant.orgId, integrationIds: ['jira'] });\n const selection = config.jira!;\n if (!selection.enabled) {\n return c.json({ error: 'jira_intake_disabled', message: 'Jira intake is turned off in Settings.' }, 404);\n }\n\n // No projects selected means nothing is synced — don't fan out to Jira.\n const selectedIds = selection.sourceIds ?? [];\n // A board request only ever sees the projects routed to a board of\n // that Factory project; unscoped listing stays available to callers\n // that don't view a specific board.\n const projectScope = factoryProjectId\n ? await scopeJiraSourcesToProject({\n intake,\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n selectedIds,\n })\n : null;\n const intakeBoards = projectScope?.intakeBoards ?? null;\n const scopes = projectScope?.scopes ?? unfilteredJiraScopes(selectedIds);\n if (scopes.length === 0) {\n return c.json({ issues: [], nextCursor: null });\n }\n\n try {\n const { issues, nextCursor } = await jira.listActiveIssues(after, scopes);\n const issuePayload = issues.map(issue => ({\n id: issue.id,\n identifier: issue.identifier,\n title: issue.title,\n url: issue.url,\n author: issue.author,\n state: issue.state ?? '',\n stateType: issue.stateType ?? '',\n priorityLabel: issue.priority ?? '',\n assignee: issue.assignee,\n project: issue.source,\n labels: issue.labels,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n sourceId: issue.sourceId || null,\n }));\n if (factoryProjectId && intakeBoards && options.ingestFactoryIssues) {\n await options.ingestFactoryIssues({\n orgId: resolved.tenant.orgId,\n userId: resolved.tenant.userId,\n factoryProjectId,\n issues: issuePayload.map(issue => ({ ...issue, site: null })),\n intakeBoards,\n });\n }\n return c.json({ issues: issuePayload, nextCursor });\n } catch (err) {\n return jiraFetchError(loose(c), err);\n }\n },\n }),\n );\n\n routes.push(\n registerApiRoute('/web/jira/issues/:identifier', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n\n const identifier = c.req.param('identifier');\n const factoryProjectId = c.req.query('factoryProjectId');\n const issueRef = c.req.query('issueRef');\n if (!ISSUE_KEY_RE.test(identifier)) return c.json({ error: 'invalid_issue_identifier' }, 400);\n if (!factoryProjectId || !UUID_RE.test(factoryProjectId)) {\n return c.json({ error: 'invalid_factory_project_id' }, 400);\n }\n if (!issueRef || issueRef.length > 2_048) return c.json({ error: 'invalid_issue_ref' }, 400);\n\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId: resolved.tenant.orgId, integrationIds: ['jira'] });\n const selection = config.jira!;\n if (!selection.enabled) {\n return c.json({ error: 'jira_intake_disabled', message: 'Jira intake is turned off in Settings.' }, 404);\n }\n const projectScope = await scopeJiraSourcesToProject({\n intake,\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n selectedIds: selection.sourceIds ?? [],\n });\n if (projectScope.scopes.length === 0) return c.json({ error: 'issue_not_found' }, 404);\n\n try {\n const issue = await jira.intake.getIssue({ connection: DEPLOYMENT_CONNECTION, issueId: issueRef });\n // An unbound project's issue, or one in another Factory's slice that this\n // Factory never filed, reads like one that doesn't exist (as on Linear).\n const routed =\n issue?.sourceId != null &&\n issue.sourceId in projectScope.intakeBoards &&\n (projectScope.takes(issue.sourceId, issue.labels) ||\n !!(await workItems?.getByProjectSource({\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n source: { integrationId: 'jira', type: 'issue', externalId: issue.id },\n })));\n if (!issue || issue.identifier.toUpperCase() !== identifier.toUpperCase() || !routed) {\n return c.json({ error: 'issue_not_found' }, 404);\n }\n return c.json({\n identifier: issue.identifier,\n title: issue.title,\n url: issue.url,\n description: issue.description,\n });\n } catch (err) {\n return jiraFetchError(loose(c), err);\n }\n },\n }),\n );\n\n return routes;\n}\n"],"mappings":";;;;;;AA+BA,MAAM,UAAU;AAChB,MAAM,eAAe;;AAGrB,SAAS,MAAM,GAA0B;CACvC,OAAO;AACT;;;;;;AAwCA,eAAe,iBACb,GACA,MACiF;CACjF,MAAM,KAAK,WAAW,CAAC;CACvB,MAAM,SAAS,KAAK,OAAO,CAAC;CAC5B,IAAI,CAAC,QAAQ,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,eAAe,GAAG,GAAG,EAAE;CACvE,IAAI,CAAC,OAAO,OACV,OAAO,EACL,UAAU,EAAE,KACV;EACE,OAAO;EACP,SAAS;CACX,GACA,GACF,EACF;CAEF,OAAO,EAAE,QAAQ;EAAE,OAAO,OAAO;EAAO,QAAQ,OAAO;CAAO,EAAE;AAClE;;;;;;AAOA,SAAS,iBAAiB,KAAoD;CAC5E,IAAI,QAAQ,KAAA,KAAa,QAAQ,IAAI,OAAO,KAAA;CAC5C,IAAI,IAAI,SAAS,OAAO,CAAC,gBAAgB,KAAK,GAAG,GAAG,OAAO;CAC3D,OAAO;AACT;;AAGA,SAAS,eAAe,GAAiB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WAAW,YAAY,KAAK,CAAC,QAC5E,OAAO,EAAE,KAAK,EAAE,OAAO,kBAAkB,GAAG,GAAG;IAEjD,OAAO,EAAE,KAAK;KACZ,YAAY,MAAM;KAClB,OAAO,MAAM;KACb,KAAK,MAAM;KACX,aAAa,MAAM;IACrB,CAAC;GACH,SAAS,KAAK;IACZ,OAAO,eAAe,MAAM,CAAC,GAAG,GAAG;GACrC;EACF;CACF,CAAC,CACH;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"routes.js","names":[],"sources":["../../../src/integrations/jira/routes.ts"],"sourcesContent":["/**\n * Mastra `apiRoutes` for the Jira intake feature.\n *\n * Registered alongside the other `/web/*` routes, behind the host auth gate.\n * Mirrors the Linear module minus everything OAuth: there is no\n * connect/callback flow, no state signer, and no per-org connection storage —\n * Jira credentials are deployment-global constructor config on the\n * integration instance. Every route still re-resolves the authenticated user\n * from the request and scopes intake selections by the caller's org.\n *\n * When the feature is disabled (no auth, or no intake storage),\n * `buildJiraRoutes` returns only `GET /web/jira/status`, which reports\n * `enabled:false` so the SPA can cleanly hide all Jira UI.\n */\n\nimport type { ApiRoute } from '@mastra/core/server';\nimport { registerApiRoute } from '@mastra/core/server';\nimport type { Context } from 'hono';\n\nimport { loose } from '../../routes/route.js';\nimport type { RouteAuth } from '../../routes/route.js';\nimport type { IntakeStorage } from '../../storage/domains/intake/base.js';\nimport type { WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport { JiraApiError } from './api.js';\nimport { scopeJiraSourcesToProject } from './binding-scope.js';\nimport { unfilteredJiraScopes } from './intake-jql.js';\nimport { DEPLOYMENT_CONNECTION } from './integration.js';\nimport type { JiraIntegration } from './integration.js';\nimport type { JiraRulesIngress } from './rules.js';\n\ntype RouteContext = Context;\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nconst ISSUE_KEY_RE = /^[A-Za-z][A-Za-z0-9_]*-\\d+$/;\n\n/**\n * Non-secret diagnostic snapshot of every Jira feature gate, mirroring the\n * Linear diagnostics shape. Only booleans — never values.\n */\nexport interface JiraFeatureDiagnostics {\n jiraConfigured: boolean;\n factoryAuthEnabled: boolean;\n appDbConfigured: boolean;\n}\n\nexport interface MountJiraRoutesOptions {\n /**\n * The integration instance providing REST access. Required for everything\n * beyond the disabled `status` route.\n */\n jira?: JiraIntegration;\n /** Host auth seam. Intake selections are org-owned, so the feature is inert without it. */\n auth: RouteAuth;\n /**\n * Cross-integration intake selection domain. Required for the issues route's\n * project filter; when absent, only the disabled `status` route is served.\n */\n intake?: IntakeStorage;\n /**\n * Factory rules ingress for observed issues. When present, a board-scoped\n * issue listing also materializes new cards through the Jira event rules —\n * the same automatic intake Linear has.\n */\n ingestFactoryIssues?: (input: JiraRulesIngress) => Promise<unknown>;\n /** Filed cards, so a Factory keeps reading issues it filed after a label filter moves them to another slice. */\n workItems?: Pick<WorkItemsStorage, 'getByProjectSource'>;\n}\n\n/**\n * Resolve the org-scoped tenant for a Jira request. Intake selections are\n * org-owned, so it requires both a signed-in user and an organization — same\n * tenancy rules as the Linear routes.\n */\nasync function resolveOrgTenant(\n c: RouteContext,\n auth: RouteAuth,\n): Promise<{ tenant: { orgId: string; userId: string } } | { response: Response }> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return { response: c.json({ error: 'unauthorized' }, 401) };\n if (!tenant.orgId) {\n return {\n response: c.json(\n {\n error: 'organization_required',\n message: 'Jira intake requires an organization. Personal accounts cannot use Jira intake.',\n },\n 403,\n ),\n };\n }\n return { tenant: { orgId: tenant.orgId, userId: tenant.userId } };\n}\n\n/**\n * Validate an opaque Jira pagination cursor from the query string. Cursors are\n * server-issued (`nextPageToken`), so anything outside a conservative\n * charset/length is rejected rather than forwarded to Jira.\n */\nfunction parseAfterCursor(raw: string | undefined): string | undefined | null {\n if (raw === undefined || raw === '') return undefined;\n if (raw.length > 512 || !/^[\\w+/=.:-]+$/.test(raw)) return null;\n return raw;\n}\n\n/** Map a Jira read failure to the API response for the SPA. */\nfunction jiraFetchError(c: RouteContext, err: unknown) {\n if (err instanceof JiraApiError && err.code === 'jira_auth_failed') {\n return c.json(\n {\n error: 'jira_auth_failed',\n message: 'Jira rejected the configured credentials. Check JIRA_EMAIL and JIRA_API_TOKEN.',\n },\n 409,\n );\n }\n return c.json({ error: 'jira_fetch_failed', message: err instanceof Error ? err.message : String(err) }, 502);\n}\n\n/**\n * Build the Jira routes as Mastra `apiRoutes`. When the feature is disabled,\n * returns only the `status` route so the SPA can detect the disabled state.\n */\nexport function buildJiraRoutes(options: MountJiraRoutesOptions): ApiRoute[] {\n const routes: ApiRoute[] = [];\n const { jira, auth, intake, workItems } = options;\n const enabled = Boolean(jira) && auth.enabled();\n const diagnostics = (): JiraFeatureDiagnostics => ({\n jiraConfigured: Boolean(jira),\n factoryAuthEnabled: auth.enabled(),\n appDbConfigured: true,\n });\n\n // The status route is always registered so the SPA can detect the disabled state.\n routes.push(\n registerApiRoute('/web/jira/status', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n if (!enabled || !jira || !intake) {\n return c.json({\n enabled: false,\n configured: Boolean(jira),\n mode: 'direct',\n site: null,\n reason: 'missing_config',\n diagnostics: diagnostics(),\n });\n }\n await auth.ensureUser(loose(c));\n const tenant = auth.tenant(loose(c));\n if (!tenant) return c.json({ error: 'unauthorized', reason: 'auth_required' }, 401);\n\n const site = new URL(jira.baseUrl).host;\n if (!tenant.orgId) {\n return c.json({\n enabled: true,\n configured: true,\n mode: 'direct',\n organizationRequired: true,\n site,\n reason: 'organization_required',\n diagnostics: diagnostics(),\n });\n }\n\n // Deployment-global credentials: configured means ready — there is no\n // per-org connection step like Linear's OAuth.\n return c.json({\n enabled: true,\n configured: true,\n mode: 'direct',\n site,\n reason: 'ready',\n diagnostics: diagnostics(),\n });\n },\n }),\n );\n\n // Without the integration instance or the intake domain the feature can't\n // serve org-scoped data — serve only the disabled `status` route.\n if (!enabled || !jira || !intake) {\n return routes;\n }\n\n // ── List the site's projects (Settings intake-source picker) ────────────\n routes.push(\n registerApiRoute('/web/jira/projects', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n\n try {\n const sources = await jira.intake.listSources(resolved.tenant);\n return c.json({\n projects: sources.map(source => ({\n id: source.id,\n name: source.name,\n key: typeof source.metadata?.key === 'string' ? source.metadata.key : null,\n })),\n });\n } catch (err) {\n return jiraFetchError(loose(c), err);\n }\n },\n }),\n );\n\n // ── List the site's active issues (cursor-paged) ────────────────────────\n // Respects the caller's intake config: disabled Jira intake 404s the\n // source, and an explicit project selection narrows the issue filter.\n routes.push(\n registerApiRoute('/web/jira/issues', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n\n const after = parseAfterCursor(c.req.query('after'));\n if (after === null) return c.json({ error: 'invalid_cursor' }, 400);\n const factoryProjectId = c.req.query('factoryProjectId');\n if (factoryProjectId && !UUID_RE.test(factoryProjectId)) {\n return c.json({ error: 'invalid_factory_project_id' }, 400);\n }\n\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId: resolved.tenant.orgId, integrationIds: ['jira'] });\n const selection = config.jira!;\n if (!selection.enabled) {\n return c.json({ error: 'jira_intake_disabled', message: 'Jira intake is turned off in Settings.' }, 404);\n }\n\n // No projects selected means nothing is synced — don't fan out to Jira.\n const selectedIds = selection.sourceIds ?? [];\n // A board request only ever sees the projects routed to a board of\n // that Factory project; unscoped listing stays available to callers\n // that don't view a specific board.\n const projectScope = factoryProjectId\n ? await scopeJiraSourcesToProject({\n intake,\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n selectedIds,\n })\n : null;\n const scopes = projectScope?.scopes ?? unfilteredJiraScopes(selectedIds);\n if (scopes.length === 0) {\n return c.json({ issues: [], nextCursor: null });\n }\n\n try {\n const { issues, nextCursor } = await jira.listActiveIssues(after, scopes);\n const issuePayload = issues.map(issue => ({\n id: issue.id,\n identifier: issue.identifier,\n title: issue.title,\n url: issue.url,\n author: issue.author,\n state: issue.state ?? '',\n stateType: issue.stateType ?? '',\n priorityLabel: issue.priority ?? '',\n assignee: issue.assignee,\n project: issue.source,\n labels: issue.labels,\n createdAt: issue.createdAt,\n updatedAt: issue.updatedAt,\n sourceId: issue.sourceId || null,\n }));\n if (factoryProjectId && projectScope && options.ingestFactoryIssues) {\n await options.ingestFactoryIssues({\n orgId: resolved.tenant.orgId,\n userId: resolved.tenant.userId,\n factoryProjectId,\n issues: issuePayload.map(issue => ({ ...issue, site: null })),\n });\n }\n return c.json({ issues: issuePayload, nextCursor });\n } catch (err) {\n return jiraFetchError(loose(c), err);\n }\n },\n }),\n );\n\n routes.push(\n registerApiRoute('/web/jira/issues/:identifier', {\n method: 'GET',\n requiresAuth: false,\n handler: async c => {\n const resolved = await resolveOrgTenant(loose(c), auth);\n if ('response' in resolved) return resolved.response;\n\n const identifier = c.req.param('identifier');\n const factoryProjectId = c.req.query('factoryProjectId');\n const issueRef = c.req.query('issueRef');\n if (!ISSUE_KEY_RE.test(identifier)) return c.json({ error: 'invalid_issue_identifier' }, 400);\n if (!factoryProjectId || !UUID_RE.test(factoryProjectId)) {\n return c.json({ error: 'invalid_factory_project_id' }, 400);\n }\n if (!issueRef || issueRef.length > 2_048) return c.json({ error: 'invalid_issue_ref' }, 400);\n\n await intake.ensureReady();\n const config = await intake.getConfig({ orgId: resolved.tenant.orgId, integrationIds: ['jira'] });\n const selection = config.jira!;\n if (!selection.enabled) {\n return c.json({ error: 'jira_intake_disabled', message: 'Jira intake is turned off in Settings.' }, 404);\n }\n const projectScope = await scopeJiraSourcesToProject({\n intake,\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n selectedIds: selection.sourceIds ?? [],\n });\n if (projectScope.scopes.length === 0) return c.json({ error: 'issue_not_found' }, 404);\n\n try {\n const issue = await jira.intake.getIssue({ connection: DEPLOYMENT_CONNECTION, issueId: issueRef });\n // An unbound project's issue, or one in another Factory's slice that this\n // Factory never filed, reads like one that doesn't exist (as on Linear).\n const routed =\n issue?.sourceId != null &&\n projectScope.sourceIds.includes(issue.sourceId) &&\n (projectScope.takes(issue.sourceId, issue.labels) ||\n !!(await workItems?.getByProjectSource({\n orgId: resolved.tenant.orgId,\n factoryProjectId,\n source: { integrationId: 'jira', type: 'issue', externalId: issue.id },\n })));\n if (!issue || issue.identifier.toUpperCase() !== identifier.toUpperCase() || !routed) {\n return c.json({ error: 'issue_not_found' }, 404);\n }\n return c.json({\n identifier: issue.identifier,\n title: issue.title,\n url: issue.url,\n description: issue.description,\n });\n } catch (err) {\n return jiraFetchError(loose(c), err);\n }\n },\n }),\n );\n\n return routes;\n}\n"],"mappings":";;;;;;;AAgCA,MAAM,UAAU;AAChB,MAAM,eAAe;;;;;;AAwCrB,eAAe,iBACb,GACA,MACiF;CACjF,MAAM,KAAK,WAAW,CAAC;CACvB,MAAM,SAAS,KAAK,OAAO,CAAC;CAC5B,IAAI,CAAC,QAAQ,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,eAAe,GAAG,GAAG,EAAE;CACvE,IAAI,CAAC,OAAO,OACV,OAAO,EACL,UAAU,EAAE,KACV;EACE,OAAO;EACP,SAAS;CACX,GACA,GACF,EACF;CAEF,OAAO,EAAE,QAAQ;EAAE,OAAO,OAAO;EAAO,QAAQ,OAAO;CAAO,EAAE;AAClE;;;;;;AAOA,SAAS,iBAAiB,KAAoD;CAC5E,IAAI,QAAQ,KAAA,KAAa,QAAQ,IAAI,OAAO,KAAA;CAC5C,IAAI,IAAI,SAAS,OAAO,CAAC,gBAAgB,KAAK,GAAG,GAAG,OAAO;CAC3D,OAAO;AACT;;AAGA,SAAS,eAAe,GAAiB,KAAc;CACrD,IAAI,eAAe,gBAAgB,IAAI,SAAS,oBAC9C,OAAO,EAAE,KACP;EACE,OAAO;EACP,SAAS;CACX,GACA,GACF;CA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O,MAAM;KACb,KAAK,MAAM;KACX,aAAa,MAAM;IACrB,CAAC;GACH,SAAS,KAAK;IACZ,OAAO,eAAe,MAAM,CAAC,GAAG,GAAG;GACrC;EACF;CACF,CAAC,CACH;CAEA,OAAO;AACT"}
@@ -1,4 +1,7 @@
1
+ import type { BoardEventFacts } from '../../boards/board-events.js';
1
2
  import type { BoardRegistry } from '../../boards/index.js';
3
+ import type { ProjectBoardSource } from '../../boards/project-boards.js';
4
+ import type { FactoryJiraRuleContext } from '../../rules/types.js';
2
5
  import type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';
3
6
  import type { WorkItemsStorage } from '../../storage/domains/work-items/base.js';
4
7
  import type { IntegrationContext } from '../base.js';
@@ -22,14 +25,15 @@ export interface JiraIssueIngress {
22
25
  labels: string[];
23
26
  createdAt: string;
24
27
  updatedAt: string;
25
- /** Jira source the issue was read from; resolves the bound board via `intakeBoards`. */
28
+ /** Jira source the issue was read from. */
26
29
  sourceId?: string | null;
27
30
  }
28
31
  export interface JiraRulesOptions {
29
32
  projects: Pick<FactoryProjectsStorage, 'get'>;
30
33
  storage: WorkItemsStorage;
31
34
  configVersion: string;
32
- boards: BoardRegistry;
35
+ /** The code boards, or the per-project source so a project's stored boards run its cards. */
36
+ boards: BoardRegistry | ProjectBoardSource;
33
37
  jiraRules: JiraEventRules;
34
38
  }
35
39
  export interface JiraRulesIngress {
@@ -37,10 +41,13 @@ export interface JiraRulesIngress {
37
41
  userId: string;
38
42
  factoryProjectId: string;
39
43
  issues: JiraIssueIngress[];
40
- /** Board id per bound Jira source id, from the project's intake bindings. */
41
- intakeBoards?: Readonly<Record<string, string>>;
42
44
  }
43
45
  type IngressStatus = 'committed' | 'replayed' | 'missing';
46
+ /**
47
+ * The status change a Jira sync reports: a issue seen for the first time is created, and a
48
+ * completed or canceled one is closed for that reason. Later sightings of an open issue report none.
49
+ */
50
+ export declare function boardEventFor(context: Pick<FactoryJiraRuleContext, 'event' | 'issue' | 'item'>): BoardEventFacts | undefined;
44
51
  export declare class JiraRules {
45
52
  #private;
46
53
  private readonly options;
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/jira/rules.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AACrF,OAAO,KAAK,EAAQ,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAoBzD,MAAM,WAAW,gBAAgB;IAC/B,uFAAuF;IACvF,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,yDAAyD;IACzD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,8DAA8D;IAC9D,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;IAC9C,OAAO,EAAE,gBAAgB,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MA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AG,UAAU,GAAG,SAAS,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC,GAAG,eAAe,GAAG,SAAS,CAK5H;AAED,qBAAa,SAAS;;IACR,OAAO,CAAC,QAAQ,CAAC,OAAO;IAApC,YAA6B,OAAO,EAAE,gBAAgB,EAAI;IAOpD,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,aAAa,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAuB1F;CA4HF;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAA;CAAE,EACxC,OAAO,EAAE,kBAAkB,GAC1B,CAAC,CAAC,KAAK,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAU7D"}
@@ -1,6 +1,8 @@
1
+ import { closeReason } from "../../boards/board-events.js";
1
2
  import "../../boards/index.js";
2
- import { boardEventHandlers, boardForWorkItem, eventBoardId, rulePhaseField, withBoardClosure } from "../../boards/semantics.js";
3
- import { selectEventRule } from "../../rules/event-rules.js";
3
+ import { boardEventHandlers, boardForWorkItem, eventBoardId, rulePhaseField, withBoardClosure, withIntakeTarget } from "../../boards/semantics.js";
4
+ import { toBoardSource } from "../../boards/project-boards.js";
5
+ import { deploymentOwnsEvent, routeEventDecision, selectEventRule, withoutRouteEvent } from "../../rules/event-rules.js";
4
6
  import { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from "../../rules/validation.js";
5
7
  // src/integrations/jira/rules.ts
6
8
  const RULE_TIMEOUT_MS = 5e3;
@@ -15,11 +17,26 @@ async function withRuleTimeout(promise) {
15
17
  }
16
18
  }
17
19
  const MAX_STALE_RULE_ATTEMPTS = 3;
20
+ /**
21
+ * The status change a Jira sync reports: a issue seen for the first time is created, and a
22
+ * completed or canceled one is closed for that reason. Later sightings of an open issue report none.
23
+ */
24
+ function boardEventFor(context) {
25
+ if (context.event === "issueClosed") return {
26
+ type: "work_item.closed",
27
+ reason: closeReason(context.issue.stateType === "canceled")
28
+ };
29
+ return context.item ? void 0 : { type: "work_item.created" };
30
+ }
18
31
  var JiraRules = class {
19
32
  options;
20
33
  constructor(options) {
21
34
  this.options = options;
22
35
  }
36
+ /** The project's boards, loaded at the start of {@link ingest}. */
37
+ #boards(scope) {
38
+ return toBoardSource(this.options.boards).forProject(scope);
39
+ }
23
40
  async ingest(input) {
24
41
  if (!await this.options.projects.get({
25
42
  orgId: input.orgId,
@@ -28,13 +45,26 @@ var JiraRules = class {
28
45
  status: "missing",
29
46
  ingested: 0
30
47
  };
31
- const items = await this.options.storage.list({
48
+ await toBoardSource(this.options.boards).load(input);
49
+ await this.options.storage.copyLegacyCards({
50
+ orgId: input.orgId,
51
+ factoryProjectId: input.factoryProjectId,
52
+ sources: input.issues.map((issue) => ({
53
+ integrationId: "jira",
54
+ type: "issue",
55
+ externalId: issue.id
56
+ }))
57
+ });
58
+ const items = await this.options.storage.listShared({
32
59
  orgId: input.orgId,
33
60
  factoryProjectId: input.factoryProjectId
34
61
  });
35
62
  const itemsBySourceKey = new Map(items.map((item) => [item.externalSource?.externalId, item]));
36
63
  const statuses = [];
37
- for (const issue of input.issues) statuses.push(await this.#ingestIssue(input, issue, itemsBySourceKey.get(issue.id)));
64
+ for (const issue of input.issues) {
65
+ const relatedItem = itemsBySourceKey.get(issue.id);
66
+ statuses.push(await this.#ingestIssue(input, issue, relatedItem && structuredClone(relatedItem)));
67
+ }
38
68
  if (statuses.some((status) => status === "committed")) return {
39
69
  status: "committed",
40
70
  ingested: statuses.length
@@ -57,8 +87,6 @@ var JiraRules = class {
57
87
  const isClosed = issue.stateType === "completed" || issue.stateType === "canceled";
58
88
  if (isClosed && !relatedItem) return "missing";
59
89
  const event = isClosed ? "issueClosed" : "issueObserved";
60
- const boundBoardId = issue.sourceId ? input.intakeBoards?.[issue.sourceId] : void 0;
61
- const boundBoard = boundBoardId ? this.options.boards.get(boundBoardId) : void 0;
62
90
  const context = {
63
91
  tenant: {
64
92
  orgId: input.orgId,
@@ -87,18 +115,18 @@ var JiraRules = class {
87
115
  },
88
116
  board: boardForWorkItem(relatedItem),
89
117
  itemRevision: relatedItem.revision,
90
- ...withBoardClosure(this.options.boards, relatedItem),
91
- ...rulePhaseField(this.options.boards, relatedItem)
118
+ ...withBoardClosure(this.#boards(input), relatedItem),
119
+ ...rulePhaseField(this.#boards(input), relatedItem)
92
120
  } : {},
93
- ...boundBoard ? { intake: {
94
- board: boundBoard.id,
95
- initialPhase: boundBoard.initialPhase
96
- } } : {},
121
+ ...withIntakeTarget(this.#boards(input)),
97
122
  event,
98
123
  issue
99
124
  };
100
- const rule = selectEventRule(this.options.jiraRules, boardEventHandlers(this.options.boards, eventBoardId(context), "jira"), context.event);
101
- let decision;
125
+ const boardEvent = boardEventFor(context);
126
+ if (boardEvent) context.boardEvent = boardEvent;
127
+ const ownedByDeployment = deploymentOwnsEvent(this.options.jiraRules, boardEventHandlers(this.#boards(input), eventBoardId(context), "jira"), context.event);
128
+ const rule = selectEventRule(this.options.jiraRules, boardEventHandlers(this.#boards(input), eventBoardId(context), "jira"), context.event);
129
+ let decision = void 0;
102
130
  let decisions = [];
103
131
  let outcome = { status: "accepted" };
104
132
  try {
@@ -109,7 +137,7 @@ var JiraRules = class {
109
137
  reason: decision.reason
110
138
  };
111
139
  else if (decision) decisions = validateFactoryRuleDecisions([decision]).map((entry) => {
112
- assertFactoryDecisionTarget(entry, this.options.boards, relatedItem ? boardForWorkItem(relatedItem) : void 0);
140
+ assertFactoryDecisionTarget(entry, this.#boards(input), relatedItem ? boardForWorkItem(relatedItem) : void 0);
113
141
  return { ...entry };
114
142
  });
115
143
  } catch (error) {
@@ -120,6 +148,14 @@ var JiraRules = class {
120
148
  reason: timedOut ? "Factory rule evaluation timed out." : error instanceof Error ? error.message.slice(0, 2e3) : "Factory Jira rule failed."
121
149
  };
122
150
  }
151
+ if (ownedByDeployment) decisions = decisions.map(withoutRouteEvent);
152
+ if (!decision && !ownedByDeployment && outcome.status === "accepted") {
153
+ const routed = await routeEventDecision(context, this.options.storage, {
154
+ orgId: input.orgId,
155
+ factoryProjectId: input.factoryProjectId
156
+ });
157
+ if (routed) decisions = [{ ...routed }];
158
+ }
123
159
  const committed = await this.options.storage.commitRuleEvaluation({
124
160
  orgId: input.orgId,
125
161
  factoryProjectId: input.factoryProjectId,
@@ -159,6 +195,6 @@ function attachJiraRules(jira, context) {
159
195
  });
160
196
  return (input) => rules.ingest(input);
161
197
  }
162
- export { JiraRules, attachJiraRules };
198
+ export { JiraRules, attachJiraRules, boardEventFor };
163
199
 
164
200
  //# sourceMappingURL=rules.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rules.js","names":[],"sources":["../../../src/integrations/jira/rules.ts"],"sourcesContent":["import {\n boardEventHandlers,\n boardForWorkItem,\n eventBoardId,\n rulePhaseField,\n withBoardClosure,\n} from '../../boards/index.js';\nimport type { BoardRegistry } from '../../boards/index.js';\nimport { selectEventRule } from '../../rules/event-rules.js';\nimport type { FactoryJiraRuleContext, FactoryRuleDecision } from '../../rules/types.js';\nimport { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from '../../rules/validation.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { Card, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { IntegrationContext } from '../base.js';\nimport type { JiraEventRules } from './default-rules.js';\n\nconst RULE_TIMEOUT_MS = 5_000;\n\nasync function withRuleTimeout<T>(promise: Promise<T>): Promise<T> {\n let timeout: ReturnType<typeof setTimeout> | undefined;\n try {\n return await Promise.race([\n promise,\n new Promise<never>((_, reject) => {\n timeout = setTimeout(() => reject(new Error('FACTORY_RULE_TIMEOUT')), RULE_TIMEOUT_MS);\n }),\n ]);\n } finally {\n if (timeout) clearTimeout(timeout);\n }\n}\n\nconst MAX_STALE_RULE_ATTEMPTS = 3;\n\nexport interface JiraIssueIngress {\n /** Stable issue reference — direct Jira id or the Platform-encoded issue reference. */\n id: string;\n identifier: string;\n title: string;\n url: string;\n state: string;\n stateType: string;\n priorityLabel: string;\n assignee: string | null;\n /** Display name of the Jira reporter, when available. */\n author: string | null;\n /** Jira project key the issue belongs to, when available. */\n project: string | null;\n /** Jira site host the issue was read from, when available. */\n site: string | null;\n labels: string[];\n createdAt: string;\n updatedAt: string;\n /** Jira source the issue was read from; resolves the bound board via `intakeBoards`. */\n sourceId?: string | null;\n}\n\nexport interface JiraRulesOptions {\n projects: Pick<FactoryProjectsStorage, 'get'>;\n storage: WorkItemsStorage;\n configVersion: string;\n boards: BoardRegistry;\n jiraRules: JiraEventRules;\n}\n\nexport interface JiraRulesIngress {\n orgId: string;\n userId: string;\n factoryProjectId: string;\n issues: JiraIssueIngress[];\n /** Board id per bound Jira source id, from the project's intake bindings. */\n intakeBoards?: Readonly<Record<string, string>>;\n}\n\ntype IngressStatus = 'committed' | 'replayed' | 'missing';\n\nexport class JiraRules {\n constructor(private readonly options: JiraRulesOptions) {}\n\n async ingest(input: JiraRulesIngress): Promise<{ status: IngressStatus; ingested: number }> {\n const project = await this.options.projects.get({ orgId: input.orgId, id: input.factoryProjectId });\n if (!project) return { status: 'missing', ingested: 0 };\n\n const items = await this.options.storage.list({ orgId: input.orgId, factoryProjectId: input.factoryProjectId });\n const itemsBySourceKey = new Map(items.map(item => [item.externalSource?.externalId, item]));\n const statuses: IngressStatus[] = [];\n for (const issue of input.issues) {\n // One card per Jira issue per project; other projects may file their own.\n statuses.push(await this.#ingestIssue(input, issue, itemsBySourceKey.get(issue.id)));\n }\n if (statuses.some(status => status === 'committed')) return { status: 'committed', ingested: statuses.length };\n if (statuses.some(status => status === 'replayed')) return { status: 'replayed', ingested: statuses.length };\n return { status: 'missing', ingested: statuses.length };\n }\n\n async #ingestIssue(\n input: JiraRulesIngress,\n issue: JiraIssueIngress,\n relatedItem: Card | undefined,\n attempt = 1,\n ): Promise<IngressStatus> {\n const ingressId = `jira:${issue.id}:${issue.updatedAt}`;\n const actor = { type: 'human' as const, id: input.userId };\n\n // Closed issues without existing work items should not create new ones.\n const isClosed = issue.stateType === 'completed' || issue.stateType === 'canceled';\n if (isClosed && !relatedItem) {\n return 'missing';\n }\n\n const event = isClosed ? 'issueClosed' : 'issueObserved';\n const boundBoardId = issue.sourceId ? input.intakeBoards?.[issue.sourceId] : undefined;\n const boundBoard = boundBoardId ? this.options.boards.get(boundBoardId) : undefined;\n const context: FactoryJiraRuleContext = {\n tenant: { orgId: input.orgId, projectId: input.factoryProjectId },\n actor,\n ingress: { type: 'jira', id: ingressId },\n cause: `jira.${event}`,\n causalChain: [],\n configVersion: this.options.configVersion,\n ...(relatedItem\n ? {\n item: {\n id: relatedItem.id,\n source: 'jira-issue',\n sourceKey: relatedItem.externalSource?.externalId ?? null,\n parentWorkItemId: relatedItem.parentWorkItemId,\n title: relatedItem.title,\n url: relatedItem.externalSource?.url ?? null,\n stages: relatedItem.stages,\n workItem: relatedItem.workItem,\n acceptedAt: relatedItem.acceptedAt,\n metadata: relatedItem.metadata,\n },\n board: boardForWorkItem(relatedItem),\n itemRevision: relatedItem.revision,\n ...withBoardClosure(this.options.boards, relatedItem),\n ...rulePhaseField(this.options.boards, relatedItem),\n }\n : {}),\n ...(boundBoard ? { intake: { board: boundBoard.id, initialPhase: boundBoard.initialPhase } } : {}),\n event,\n issue,\n };\n\n const rule = selectEventRule(\n this.options.jiraRules,\n boardEventHandlers(this.options.boards, eventBoardId(context), 'jira'),\n context.event,\n );\n let decision: FactoryRuleDecision | void;\n let decisions: Record<string, unknown>[] = [];\n let outcome: { status: 'accepted' | 'rejected'; code?: string; reason?: string } = { status: 'accepted' };\n try {\n decision = rule ? await withRuleTimeout(Promise.resolve(rule(Object.freeze(context)))) : undefined;\n if (decision?.type === 'reject') {\n outcome = { status: 'rejected', code: decision.code, reason: decision.reason };\n } else if (decision) {\n decisions = validateFactoryRuleDecisions([decision]).map(entry => {\n assertFactoryDecisionTarget(\n entry,\n this.options.boards,\n relatedItem ? boardForWorkItem(relatedItem) : undefined,\n );\n return { ...entry };\n });\n }\n } catch (error) {\n const timedOut = error instanceof Error && error.message === 'FACTORY_RULE_TIMEOUT';\n outcome = {\n status: 'rejected',\n code: timedOut ? 'timeout' : 'rule_error',\n reason: timedOut\n ? 'Factory rule evaluation timed out.'\n : error instanceof Error\n ? error.message.slice(0, 2_000)\n : 'Factory Jira rule failed.',\n };\n }\n\n const committed = await this.options.storage.commitRuleEvaluation({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n workItemId: relatedItem?.id ?? null,\n ingress: { identity: ingressId, triggerType: 'jira.issueObserved' },\n configVersion: this.options.configVersion,\n expectedRevision: relatedItem?.revision ?? null,\n actor,\n outcome,\n decisions,\n causalChain: [],\n now: new Date(),\n });\n if (committed.status === 'stale') {\n // Nothing was persisted: re-read the item and evaluate again at its fresh revision.\n if (attempt >= MAX_STALE_RULE_ATTEMPTS) {\n throw new Error(`Factory Jira rule evaluation for ${ingressId} kept losing revision races.`);\n }\n const fresh = relatedItem ? await this.options.storage.get({ orgId: input.orgId, id: relatedItem.id }) : null;\n if (relatedItem && !fresh) return 'missing';\n return this.#ingestIssue(input, issue, fresh ?? undefined, attempt + 1);\n }\n return committed.status;\n }\n}\n\nexport function attachJiraRules(\n jira: { readonly rules: JiraEventRules },\n context: IntegrationContext,\n): ((input: JiraRulesIngress) => Promise<unknown>) | undefined {\n if (!context.runtime) return undefined;\n const rules = new JiraRules({\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n configVersion: context.runtime.configVersion,\n boards: context.runtime.boards,\n jiraRules: jira.rules,\n });\n return input => rules.ingest(input);\n}\n"],"mappings":";;;;;AAgBA,MAAM,kBAAkB;AAExB,eAAe,gBAAmB,SAAiC;CACjE,IAAI;CACJ,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CACxB,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,QAAQ;EAC/B,QAAQ,QAAQ,QAAQ;EACxB,WAAW,KAAK;CAClB,CAAC;CACD,QAAO,UAAS,MAAM,OAAO,KAAK;AACpC"}
1
+ {"version":3,"file":"rules.js","names":[],"sources":["../../../src/integrations/jira/rules.ts"],"sourcesContent":["import { closeReason } from '../../boards/board-events.js';\nimport type { BoardEventFacts } from '../../boards/board-events.js';\nimport {\n boardEventHandlers,\n boardForWorkItem,\n eventBoardId,\n rulePhaseField,\n withBoardClosure,\n withIntakeTarget,\n} from '../../boards/index.js';\nimport type { BoardRegistry } from '../../boards/index.js';\nimport { toBoardSource } from '../../boards/project-boards.js';\nimport type { ProjectBoardSource } from '../../boards/project-boards.js';\nimport { deploymentOwnsEvent, routeEventDecision, selectEventRule, withoutRouteEvent } from '../../rules/event-rules.js';\nimport type { FactoryJiraRuleContext, FactoryRuleDecision } from '../../rules/types.js';\nimport { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from '../../rules/validation.js';\nimport type { StoredBoardScope } from '../../storage/domains/boards/base.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { Card, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { IntegrationContext } from '../base.js';\nimport type { JiraEventRules } from './default-rules.js';\n\nconst RULE_TIMEOUT_MS = 5_000;\n\nasync function withRuleTimeout<T>(promise: Promise<T>): Promise<T> {\n let timeout: ReturnType<typeof setTimeout> | undefined;\n try {\n return await Promise.race([\n promise,\n new Promise<never>((_, reject) => {\n timeout = setTimeout(() => reject(new Error('FACTORY_RULE_TIMEOUT')), RULE_TIMEOUT_MS);\n }),\n ]);\n } finally {\n if (timeout) clearTimeout(timeout);\n }\n}\n\nconst MAX_STALE_RULE_ATTEMPTS = 3;\n\nexport interface JiraIssueIngress {\n /** Stable issue reference — direct Jira id or the Platform-encoded issue reference. */\n id: string;\n identifier: string;\n title: string;\n url: string;\n state: string;\n stateType: string;\n priorityLabel: string;\n assignee: string | null;\n /** Display name of the Jira reporter, when available. */\n author: string | null;\n /** Jira project key the issue belongs to, when available. */\n project: string | null;\n /** Jira site host the issue was read from, when available. */\n site: string | null;\n labels: string[];\n createdAt: string;\n updatedAt: string;\n /** Jira source the issue was read from. */\n sourceId?: string | null;\n}\n\nexport interface JiraRulesOptions {\n projects: Pick<FactoryProjectsStorage, 'get'>;\n storage: WorkItemsStorage;\n configVersion: string;\n /** The code boards, or the per-project source so a project's stored boards run its cards. */\n boards: BoardRegistry | ProjectBoardSource;\n jiraRules: JiraEventRules;\n}\n\nexport interface JiraRulesIngress {\n orgId: string;\n userId: string;\n factoryProjectId: string;\n issues: JiraIssueIngress[];\n}\n\ntype IngressStatus = 'committed' | 'replayed' | 'missing';\n\n/**\n * The status change a Jira sync reports: a issue seen for the first time is created, and a\n * completed or canceled one is closed for that reason. Later sightings of an open issue report none.\n */\nexport function boardEventFor(context: Pick<FactoryJiraRuleContext, 'event' | 'issue' | 'item'>): BoardEventFacts | undefined {\n if (context.event === 'issueClosed') {\n return { type: 'work_item.closed', reason: closeReason(context.issue.stateType === 'canceled') };\n }\n return context.item ? undefined : { type: 'work_item.created' };\n}\n\nexport class JiraRules {\n constructor(private readonly options: JiraRulesOptions) {}\n\n /** The project's boards, loaded at the start of {@link ingest}. */\n #boards(scope: StoredBoardScope): BoardRegistry {\n return toBoardSource(this.options.boards).forProject(scope);\n }\n\n async ingest(input: JiraRulesIngress): Promise<{ status: IngressStatus; ingested: number }> {\n const project = await this.options.projects.get({ orgId: input.orgId, id: input.factoryProjectId });\n if (!project) return { status: 'missing', ingested: 0 };\n await toBoardSource(this.options.boards).load(input);\n\n // A finished card may still be only in the legacy table; copy it so the issue finds it.\n await this.options.storage.copyLegacyCards({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n sources: input.issues.map(issue => ({ integrationId: 'jira', type: 'issue', externalId: issue.id })),\n });\n // The shared list is the cache itself: only the card handed on to rules is cloned.\n const items = await this.options.storage.listShared({ orgId: input.orgId, factoryProjectId: input.factoryProjectId });\n const itemsBySourceKey = new Map(items.map(item => [item.externalSource?.externalId, item]));\n const statuses: IngressStatus[] = [];\n for (const issue of input.issues) {\n // One card per Jira issue per project; other projects may file their own.\n const relatedItem = itemsBySourceKey.get(issue.id);\n statuses.push(await this.#ingestIssue(input, issue, relatedItem && structuredClone(relatedItem)));\n }\n if (statuses.some(status => status === 'committed')) return { status: 'committed', ingested: statuses.length };\n if (statuses.some(status => status === 'replayed')) return { status: 'replayed', ingested: statuses.length };\n return { status: 'missing', ingested: statuses.length };\n }\n\n async #ingestIssue(\n input: JiraRulesIngress,\n issue: JiraIssueIngress,\n relatedItem: Card | undefined,\n attempt = 1,\n ): Promise<IngressStatus> {\n const ingressId = `jira:${issue.id}:${issue.updatedAt}`;\n const actor = { type: 'human' as const, id: input.userId };\n\n // Closed issues without existing work items should not create new ones.\n const isClosed = issue.stateType === 'completed' || issue.stateType === 'canceled';\n if (isClosed && !relatedItem) {\n return 'missing';\n }\n\n const event = isClosed ? 'issueClosed' : 'issueObserved';\n const context: FactoryJiraRuleContext = {\n tenant: { orgId: input.orgId, projectId: input.factoryProjectId },\n actor,\n ingress: { type: 'jira', id: ingressId },\n cause: `jira.${event}`,\n causalChain: [],\n configVersion: this.options.configVersion,\n ...(relatedItem\n ? {\n item: {\n id: relatedItem.id,\n source: 'jira-issue',\n sourceKey: relatedItem.externalSource?.externalId ?? null,\n parentWorkItemId: relatedItem.parentWorkItemId,\n title: relatedItem.title,\n url: relatedItem.externalSource?.url ?? null,\n stages: relatedItem.stages,\n workItem: relatedItem.workItem,\n acceptedAt: relatedItem.acceptedAt,\n metadata: relatedItem.metadata,\n },\n board: boardForWorkItem(relatedItem),\n itemRevision: relatedItem.revision,\n ...withBoardClosure(this.#boards(input), relatedItem),\n ...rulePhaseField(this.#boards(input), relatedItem),\n }\n : {}),\n ...withIntakeTarget(this.#boards(input)),\n event,\n issue,\n };\n const boardEvent = boardEventFor(context);\n if (boardEvent) context.boardEvent = boardEvent;\n\n const ownedByDeployment = deploymentOwnsEvent(\n this.options.jiraRules,\n boardEventHandlers(this.#boards(input), eventBoardId(context), 'jira'),\n context.event,\n );\n const rule = selectEventRule(\n this.options.jiraRules,\n boardEventHandlers(this.#boards(input), eventBoardId(context), 'jira'),\n context.event,\n );\n let decision: FactoryRuleDecision | void = undefined;\n let decisions: Record<string, unknown>[] = [];\n let outcome: { status: 'accepted' | 'rejected'; code?: string; reason?: string } = { status: 'accepted' };\n try {\n decision = rule ? await withRuleTimeout(Promise.resolve(rule(Object.freeze(context)))) : undefined;\n if (decision?.type === 'reject') {\n outcome = { status: 'rejected', code: decision.code, reason: decision.reason };\n } else if (decision) {\n decisions = validateFactoryRuleDecisions([decision]).map(entry => {\n assertFactoryDecisionTarget(\n entry,\n this.#boards(input),\n relatedItem ? boardForWorkItem(relatedItem) : undefined,\n );\n return { ...entry };\n });\n }\n } catch (error) {\n const timedOut = error instanceof Error && error.message === 'FACTORY_RULE_TIMEOUT';\n outcome = {\n status: 'rejected',\n code: timedOut ? 'timeout' : 'rule_error',\n reason: timedOut\n ? 'Factory rule evaluation timed out.'\n : error instanceof Error\n ? error.message.slice(0, 2_000)\n : 'Factory Jira rule failed.',\n };\n }\n if (ownedByDeployment) decisions = decisions.map(withoutRouteEvent);\n if (!decision && !ownedByDeployment && outcome.status === 'accepted') {\n const routed = await routeEventDecision(context, this.options.storage, {\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n if (routed) decisions = [{ ...routed }];\n }\n\n const committed = await this.options.storage.commitRuleEvaluation({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n workItemId: relatedItem?.id ?? null,\n ingress: { identity: ingressId, triggerType: 'jira.issueObserved' },\n configVersion: this.options.configVersion,\n expectedRevision: relatedItem?.revision ?? null,\n actor,\n outcome,\n decisions,\n causalChain: [],\n now: new Date(),\n });\n if (committed.status === 'stale') {\n // Nothing was persisted: re-read the item and evaluate again at its fresh revision.\n if (attempt >= MAX_STALE_RULE_ATTEMPTS) {\n throw new Error(`Factory Jira rule evaluation for ${ingressId} kept losing revision races.`);\n }\n const fresh = relatedItem ? await this.options.storage.get({ orgId: input.orgId, id: relatedItem.id }) : null;\n if (relatedItem && !fresh) return 'missing';\n return this.#ingestIssue(input, issue, fresh ?? undefined, attempt + 1);\n }\n return committed.status;\n }\n}\n\nexport function attachJiraRules(\n jira: { readonly rules: JiraEventRules },\n context: IntegrationContext,\n): ((input: JiraRulesIngress) => Promise<unknown>) | undefined {\n if (!context.runtime) return undefined;\n const rules = new JiraRules({\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n configVersion: context.runtime.configVersion,\n boards: context.runtime.boards,\n jiraRules: jira.rules,\n });\n return input => rules.ingest(input);\n}\n"],"mappings":";;;;;;;AAsBA,MAAM,kBAAkB;AAExB,eAAe,gBAAmB,SAAiC;CACjE,IAAI;CACJ,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK,CACxB,SACA,IAAI,SAAgB,GAAG,WAAW;GAChC,UAAU,iBAAiB,uBAAO,IAAI,MAAM,sBAAsB,CAAC,GAAG,eAAe;EACvF,CAAC,CACH,CAAC;CACH,UAAU;EACR,IAAI,SAAS,aAAa,OAAO;CACnC;AACF;AAEA,MAAM,0BAA0B;;;;;AA+ChC,SAAgB,cAAc,SAAgG;CAC5H,IAAI,QAAQ,UAAU,eACpB,OAAO;EAAE,MAAM;EAAoB,QAAQ,YAAY,QAAQ,MAAM,cAAc,UAAU;CAAE;CAEjG,OAAO,QAAQ,OAAO,KAAA,IAAY,EAAE,MAAM,oBAAoB;AAChE;AAEA,IAAa,YAAb,MAAuB;CACQ;CAA7B,YAAY,SAA4C;EAA3B,KAAA,UAAA;CAA4B;;CAGzD,QAAQ,OAAwC;EAC9C,OAAO,cAAc,KAAK,QAAQ,MAAM,CAAC,CAAC,WAAW,KAAK;CAC5D;CAEA,MAAM,OAAO,OAA+E;EAE1F,IAAI,CAAC,MADiB,KAAK,QAAQ,SAAS,IAAI;GAAE,OAAO,MAAM;GA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AAA,GAAW,UAAU,CAAC;EACxE;EACA,OAAO,UAAU;CACnB;AACF;AAEA,SAAgB,gBACd,MACA,SAC6D;CAC7D,IAAI,CAAC,QAAQ,SAAS,OAAO,KAAA;CAC7B,MAAM,QAAQ,IAAI,UAAU;EAC1B,UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,QAAQ;EACzB,eAAe,QAAQ,QAAQ;EAC/B,QAAQ,QAAQ,QAAQ;EACxB,WAAW,KAAK;CAClB,CAAC;CACD,QAAO,UAAS,MAAM,OAAO,KAAK;AACpC"}
@@ -21,6 +21,14 @@ declare function createLinearCommentTool(linear: LinearIntegration, orgId: strin
21
21
  issue: string;
22
22
  body: string;
23
23
  }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "linear_create_comment", unknown>;
24
+ declare function createLinearListProjectsTool(linear: LinearIntegration, orgId: string): import("@mastra/core/tools").Tool<{
25
+ query?: string | undefined;
26
+ }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "linear_list_projects", unknown>;
27
+ declare function createLinearListIssuesTool(linear: LinearIntegration, orgId: string): import("@mastra/core/tools").Tool<{
28
+ source: string;
29
+ labels?: string[] | undefined;
30
+ cursor?: string | undefined;
31
+ }, unknown, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown, unknown>, "linear_list_issues", unknown>;
24
32
  /**
25
33
  * Async `extraTools` provider: expose Linear tools only when the session's
26
34
  * project belongs to an org with an active Linear connection.
@@ -29,6 +37,6 @@ export declare function buildLinearAgentTools({ requestContext, linear, }: {
29
37
  requestContext: RequestContext;
30
38
  /** The integration instance providing the Linear API client. */
31
39
  linear: LinearIntegration;
32
- }): Promise<Record<string, ReturnType<typeof createLinearGetIssueTool> | ReturnType<typeof createLinearCommentTool>>>;
40
+ }): Promise<Record<string, ReturnType<typeof createLinearGetIssueTool> | ReturnType<typeof createLinearCommentTool> | ReturnType<typeof createLinearListProjectsTool> | ReturnType<typeof createLinearListIssuesTool>>>;
33
41
  export {};
34
42
  //# sourceMappingURL=agent-tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-tools.d.ts","sourceRoot":"","sources":["../../../src/integrations/linear/agent-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAInE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,iBAAS,wBAAwB,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI;;yIAkCzG;AAED,iBAAS,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM;;;8IAsCxE;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,EAC1C,cAAc,EACd,MAAM,GACP,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,gEAAgE;IAChE,MAAM,EAAE,iBAAiB,CAAC;CAC3B,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,wBAAwB,CAAC,GAAG,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAAC,CAAC,CAyBpH"}
1
+ {"version":3,"file":"agent-tools.d.ts","sourceRoot":"","sources":["../../../src/integrations/linear/agent-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAInE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,iBAAS,wBAAwB,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI;;yIAkCzG;AAED,iBAAS,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,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