@mastra/factory 0.0.0-aggregate-trace-20261015182851

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 (926) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +671 -0
  3. package/dist/auth.d.ts +201 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +623 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/boards/define-board.d.ts +111 -0
  8. package/dist/boards/define-board.d.ts.map +1 -0
  9. package/dist/boards/define-board.js +156 -0
  10. package/dist/boards/define-board.js.map +1 -0
  11. package/dist/boards/index.d.ts +14 -0
  12. package/dist/boards/index.d.ts.map +1 -0
  13. package/dist/boards/index.js +21 -0
  14. package/dist/boards/index.js.map +1 -0
  15. package/dist/boards/registry.d.ts +16 -0
  16. package/dist/boards/registry.d.ts.map +1 -0
  17. package/dist/boards/registry.js +25 -0
  18. package/dist/boards/registry.js.map +1 -0
  19. package/dist/boards/relocate.d.ts +21 -0
  20. package/dist/boards/relocate.d.ts.map +1 -0
  21. package/dist/boards/relocate.js +58 -0
  22. package/dist/boards/relocate.js.map +1 -0
  23. package/dist/boards/review.d.ts +6 -0
  24. package/dist/boards/review.d.ts.map +1 -0
  25. package/dist/boards/review.js +104 -0
  26. package/dist/boards/review.js.map +1 -0
  27. package/dist/boards/semantics.d.ts +68 -0
  28. package/dist/boards/semantics.d.ts.map +1 -0
  29. package/dist/boards/semantics.js +119 -0
  30. package/dist/boards/semantics.js.map +1 -0
  31. package/dist/boards/transition-policy.d.ts +67 -0
  32. package/dist/boards/transition-policy.d.ts.map +1 -0
  33. package/dist/boards/transition-policy.js +36 -0
  34. package/dist/boards/transition-policy.js.map +1 -0
  35. package/dist/boards/work-tool-rules.d.ts +8 -0
  36. package/dist/boards/work-tool-rules.d.ts.map +1 -0
  37. package/dist/boards/work-tool-rules.js +20 -0
  38. package/dist/boards/work-tool-rules.js.map +1 -0
  39. package/dist/boards/work-transition-policy.d.ts +3 -0
  40. package/dist/boards/work-transition-policy.d.ts.map +1 -0
  41. package/dist/boards/work-transition-policy.js +46 -0
  42. package/dist/boards/work-transition-policy.js.map +1 -0
  43. package/dist/boards/work.d.ts +4 -0
  44. package/dist/boards/work.d.ts.map +1 -0
  45. package/dist/boards/work.js +222 -0
  46. package/dist/boards/work.js.map +1 -0
  47. package/dist/capabilities/connection.d.ts +9 -0
  48. package/dist/capabilities/connection.d.ts.map +1 -0
  49. package/dist/capabilities/connection.js +1 -0
  50. package/dist/capabilities/intake.d.ts +153 -0
  51. package/dist/capabilities/intake.d.ts.map +1 -0
  52. package/dist/capabilities/intake.js +1 -0
  53. package/dist/capabilities/version-control.d.ts +268 -0
  54. package/dist/capabilities/version-control.d.ts.map +1 -0
  55. package/dist/capabilities/version-control.js +1 -0
  56. package/dist/environment/build-runner.d.ts +72 -0
  57. package/dist/environment/build-runner.d.ts.map +1 -0
  58. package/dist/environment/build-runner.js +131 -0
  59. package/dist/environment/build-runner.js.map +1 -0
  60. package/dist/environment/build-schedule.d.ts +40 -0
  61. package/dist/environment/build-schedule.d.ts.map +1 -0
  62. package/dist/environment/build-schedule.js +94 -0
  63. package/dist/environment/build-schedule.js.map +1 -0
  64. package/dist/environment/build-workflow.d.ts +62 -0
  65. package/dist/environment/build-workflow.d.ts.map +1 -0
  66. package/dist/environment/build-workflow.js +149 -0
  67. package/dist/environment/build-workflow.js.map +1 -0
  68. package/dist/environment/build.d.ts +111 -0
  69. package/dist/environment/build.d.ts.map +1 -0
  70. package/dist/environment/build.js +344 -0
  71. package/dist/environment/build.js.map +1 -0
  72. package/dist/environment/heads.d.ts +36 -0
  73. package/dist/environment/heads.d.ts.map +1 -0
  74. package/dist/environment/heads.js +60 -0
  75. package/dist/environment/heads.js.map +1 -0
  76. package/dist/factory.d.ts +225 -0
  77. package/dist/factory.d.ts.map +1 -0
  78. package/dist/factory.js +1006 -0
  79. package/dist/factory.js.map +1 -0
  80. package/dist/feed-events.d.ts +13 -0
  81. package/dist/feed-events.d.ts.map +1 -0
  82. package/dist/feed-events.js +25 -0
  83. package/dist/feed-events.js.map +1 -0
  84. package/dist/index.d.ts +22 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +15 -0
  87. package/dist/integrations/base.d.ts +302 -0
  88. package/dist/integrations/base.d.ts.map +1 -0
  89. package/dist/integrations/base.js +1 -0
  90. package/dist/integrations/github/acceptance-labels.d.ts +16 -0
  91. package/dist/integrations/github/acceptance-labels.d.ts.map +1 -0
  92. package/dist/integrations/github/acceptance-labels.js +55 -0
  93. package/dist/integrations/github/acceptance-labels.js.map +1 -0
  94. package/dist/integrations/github/app-identity.d.ts +43 -0
  95. package/dist/integrations/github/app-identity.d.ts.map +1 -0
  96. package/dist/integrations/github/app-identity.js +62 -0
  97. package/dist/integrations/github/app-identity.js.map +1 -0
  98. package/dist/integrations/github/commits.d.ts +40 -0
  99. package/dist/integrations/github/commits.d.ts.map +1 -0
  100. package/dist/integrations/github/commits.js +48 -0
  101. package/dist/integrations/github/commits.js.map +1 -0
  102. package/dist/integrations/github/config.d.ts +60 -0
  103. package/dist/integrations/github/config.d.ts.map +1 -0
  104. package/dist/integrations/github/config.js +42 -0
  105. package/dist/integrations/github/config.js.map +1 -0
  106. package/dist/integrations/github/default-rules.d.ts +218 -0
  107. package/dist/integrations/github/default-rules.d.ts.map +1 -0
  108. package/dist/integrations/github/default-rules.js +296 -0
  109. package/dist/integrations/github/default-rules.js.map +1 -0
  110. package/dist/integrations/github/integration.d.ts +270 -0
  111. package/dist/integrations/github/integration.d.ts.map +1 -0
  112. package/dist/integrations/github/integration.js +1375 -0
  113. package/dist/integrations/github/integration.js.map +1 -0
  114. package/dist/integrations/github/issue-reconciler.d.ts +28 -0
  115. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -0
  116. package/dist/integrations/github/issue-reconciler.js +138 -0
  117. package/dist/integrations/github/issue-reconciler.js.map +1 -0
  118. package/dist/integrations/github/pat.d.ts +38 -0
  119. package/dist/integrations/github/pat.d.ts.map +1 -0
  120. package/dist/integrations/github/pat.js +59 -0
  121. package/dist/integrations/github/pat.js.map +1 -0
  122. package/dist/integrations/github/provenance.d.ts +34 -0
  123. package/dist/integrations/github/provenance.d.ts.map +1 -0
  124. package/dist/integrations/github/provenance.js +91 -0
  125. package/dist/integrations/github/provenance.js.map +1 -0
  126. package/dist/integrations/github/reconcile-worker.d.ts +45 -0
  127. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -0
  128. package/dist/integrations/github/reconcile-worker.js +189 -0
  129. package/dist/integrations/github/reconcile-worker.js.map +1 -0
  130. package/dist/integrations/github/reconciliation-config.d.ts +3 -0
  131. package/dist/integrations/github/reconciliation-config.d.ts.map +1 -0
  132. package/dist/integrations/github/reconciliation-config.js +19 -0
  133. package/dist/integrations/github/reconciliation-config.js.map +1 -0
  134. package/dist/integrations/github/routes.d.ts +90 -0
  135. package/dist/integrations/github/routes.d.ts.map +1 -0
  136. package/dist/integrations/github/routes.js +1362 -0
  137. package/dist/integrations/github/routes.js.map +1 -0
  138. package/dist/integrations/github/rules.d.ts +173 -0
  139. package/dist/integrations/github/rules.d.ts.map +1 -0
  140. package/dist/integrations/github/rules.js +1021 -0
  141. package/dist/integrations/github/rules.js.map +1 -0
  142. package/dist/integrations/github/sandbox-release.d.ts +25 -0
  143. package/dist/integrations/github/sandbox-release.d.ts.map +1 -0
  144. package/dist/integrations/github/sandbox-release.js +38 -0
  145. package/dist/integrations/github/sandbox-release.js.map +1 -0
  146. package/dist/integrations/github/sandbox.d.ts +234 -0
  147. package/dist/integrations/github/sandbox.d.ts.map +1 -0
  148. package/dist/integrations/github/sandbox.js +947 -0
  149. package/dist/integrations/github/sandbox.js.map +1 -0
  150. package/dist/integrations/github/session-subscriptions.d.ts +28 -0
  151. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -0
  152. package/dist/integrations/github/session-subscriptions.js +283 -0
  153. package/dist/integrations/github/session-subscriptions.js.map +1 -0
  154. package/dist/integrations/github/settle-or-abort.d.ts +7 -0
  155. package/dist/integrations/github/settle-or-abort.d.ts.map +1 -0
  156. package/dist/integrations/github/settle-or-abort.js +25 -0
  157. package/dist/integrations/github/settle-or-abort.js.map +1 -0
  158. package/dist/integrations/github/stale-reviews.d.ts +22 -0
  159. package/dist/integrations/github/stale-reviews.d.ts.map +1 -0
  160. package/dist/integrations/github/stale-reviews.js +70 -0
  161. package/dist/integrations/github/stale-reviews.js.map +1 -0
  162. package/dist/integrations/github/subscriptions.d.ts +54 -0
  163. package/dist/integrations/github/subscriptions.d.ts.map +1 -0
  164. package/dist/integrations/github/subscriptions.js +64 -0
  165. package/dist/integrations/github/subscriptions.js.map +1 -0
  166. package/dist/integrations/github/token-refresh.d.ts +31 -0
  167. package/dist/integrations/github/token-refresh.d.ts.map +1 -0
  168. package/dist/integrations/github/token-refresh.js +42 -0
  169. package/dist/integrations/github/token-refresh.js.map +1 -0
  170. package/dist/integrations/github/webhook.d.ts +139 -0
  171. package/dist/integrations/github/webhook.d.ts.map +1 -0
  172. package/dist/integrations/github/webhook.js +432 -0
  173. package/dist/integrations/github/webhook.js.map +1 -0
  174. package/dist/integrations/gitlab/agent-tools.d.ts +14 -0
  175. package/dist/integrations/gitlab/agent-tools.d.ts.map +1 -0
  176. package/dist/integrations/gitlab/agent-tools.js +42 -0
  177. package/dist/integrations/gitlab/agent-tools.js.map +1 -0
  178. package/dist/integrations/gitlab/api.d.ts +222 -0
  179. package/dist/integrations/gitlab/api.d.ts.map +1 -0
  180. package/dist/integrations/gitlab/api.js +274 -0
  181. package/dist/integrations/gitlab/api.js.map +1 -0
  182. package/dist/integrations/gitlab/default-rules.d.ts +125 -0
  183. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -0
  184. package/dist/integrations/gitlab/default-rules.js +180 -0
  185. package/dist/integrations/gitlab/default-rules.js.map +1 -0
  186. package/dist/integrations/gitlab/integration.d.ts +138 -0
  187. package/dist/integrations/gitlab/integration.d.ts.map +1 -0
  188. package/dist/integrations/gitlab/integration.js +705 -0
  189. package/dist/integrations/gitlab/integration.js.map +1 -0
  190. package/dist/integrations/gitlab/issue-reconciler.d.ts +6 -0
  191. package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -0
  192. package/dist/integrations/gitlab/issue-reconciler.js +123 -0
  193. package/dist/integrations/gitlab/issue-reconciler.js.map +1 -0
  194. package/dist/integrations/gitlab/merge-request-reconciler.d.ts +6 -0
  195. package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -0
  196. package/dist/integrations/gitlab/merge-request-reconciler.js +267 -0
  197. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -0
  198. package/dist/integrations/gitlab/reconciler.d.ts +5 -0
  199. package/dist/integrations/gitlab/reconciler.d.ts.map +1 -0
  200. package/dist/integrations/gitlab/reconciler.js +31 -0
  201. package/dist/integrations/gitlab/reconciler.js.map +1 -0
  202. package/dist/integrations/gitlab/reconciliation-config.d.ts +3 -0
  203. package/dist/integrations/gitlab/reconciliation-config.d.ts.map +1 -0
  204. package/dist/integrations/gitlab/reconciliation-config.js +17 -0
  205. package/dist/integrations/gitlab/reconciliation-config.js.map +1 -0
  206. package/dist/integrations/gitlab/routes.d.ts +20 -0
  207. package/dist/integrations/gitlab/routes.d.ts.map +1 -0
  208. package/dist/integrations/gitlab/routes.js +474 -0
  209. package/dist/integrations/gitlab/routes.js.map +1 -0
  210. package/dist/integrations/gitlab/rules.d.ts +35 -0
  211. package/dist/integrations/gitlab/rules.d.ts.map +1 -0
  212. package/dist/integrations/gitlab/rules.js +502 -0
  213. package/dist/integrations/gitlab/rules.js.map +1 -0
  214. package/dist/integrations/gitlab/session-subscriptions.d.ts +32 -0
  215. package/dist/integrations/gitlab/session-subscriptions.d.ts.map +1 -0
  216. package/dist/integrations/gitlab/session-subscriptions.js +193 -0
  217. package/dist/integrations/gitlab/session-subscriptions.js.map +1 -0
  218. package/dist/integrations/gitlab/subscriptions.d.ts +70 -0
  219. package/dist/integrations/gitlab/subscriptions.d.ts.map +1 -0
  220. package/dist/integrations/gitlab/subscriptions.js +76 -0
  221. package/dist/integrations/gitlab/subscriptions.js.map +1 -0
  222. package/dist/integrations/gitlab/version-control.d.ts +16 -0
  223. package/dist/integrations/gitlab/version-control.d.ts.map +1 -0
  224. package/dist/integrations/gitlab/version-control.js +621 -0
  225. package/dist/integrations/gitlab/version-control.js.map +1 -0
  226. package/dist/integrations/gitlab/webhook-dispatch.d.ts +75 -0
  227. package/dist/integrations/gitlab/webhook-dispatch.d.ts.map +1 -0
  228. package/dist/integrations/gitlab/webhook-dispatch.js +235 -0
  229. package/dist/integrations/gitlab/webhook-dispatch.js.map +1 -0
  230. package/dist/integrations/gitlab/webhook.d.ts +72 -0
  231. package/dist/integrations/gitlab/webhook.d.ts.map +1 -0
  232. package/dist/integrations/gitlab/webhook.js +201 -0
  233. package/dist/integrations/gitlab/webhook.js.map +1 -0
  234. package/dist/integrations/incidentio/agent-tools.d.ts +49 -0
  235. package/dist/integrations/incidentio/agent-tools.d.ts.map +1 -0
  236. package/dist/integrations/incidentio/agent-tools.js +90 -0
  237. package/dist/integrations/incidentio/agent-tools.js.map +1 -0
  238. package/dist/integrations/incidentio/api.d.ts +400 -0
  239. package/dist/integrations/incidentio/api.d.ts.map +1 -0
  240. package/dist/integrations/incidentio/api.js +192 -0
  241. package/dist/integrations/incidentio/api.js.map +1 -0
  242. package/dist/integrations/incidentio/claim.d.ts +8 -0
  243. package/dist/integrations/incidentio/claim.d.ts.map +1 -0
  244. package/dist/integrations/incidentio/claim.js +14 -0
  245. package/dist/integrations/incidentio/claim.js.map +1 -0
  246. package/dist/integrations/incidentio/default-rules.d.ts +46 -0
  247. package/dist/integrations/incidentio/default-rules.d.ts.map +1 -0
  248. package/dist/integrations/incidentio/default-rules.js +68 -0
  249. package/dist/integrations/incidentio/default-rules.js.map +1 -0
  250. package/dist/integrations/incidentio/intake.d.ts +10 -0
  251. package/dist/integrations/incidentio/intake.d.ts.map +1 -0
  252. package/dist/integrations/incidentio/intake.js +307 -0
  253. package/dist/integrations/incidentio/intake.js.map +1 -0
  254. package/dist/integrations/incidentio/integration.d.ts +63 -0
  255. package/dist/integrations/incidentio/integration.d.ts.map +1 -0
  256. package/dist/integrations/incidentio/integration.js +141 -0
  257. package/dist/integrations/incidentio/integration.js.map +1 -0
  258. package/dist/integrations/incidentio/issue-reconciler.d.ts +10 -0
  259. package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -0
  260. package/dist/integrations/incidentio/issue-reconciler.js +75 -0
  261. package/dist/integrations/incidentio/issue-reconciler.js.map +1 -0
  262. package/dist/integrations/incidentio/reconciliation-config.d.ts +3 -0
  263. package/dist/integrations/incidentio/reconciliation-config.d.ts.map +1 -0
  264. package/dist/integrations/incidentio/reconciliation-config.js +17 -0
  265. package/dist/integrations/incidentio/reconciliation-config.js.map +1 -0
  266. package/dist/integrations/incidentio/routes.d.ts +76 -0
  267. package/dist/integrations/incidentio/routes.d.ts.map +1 -0
  268. package/dist/integrations/incidentio/routes.js +249 -0
  269. package/dist/integrations/incidentio/routes.js.map +1 -0
  270. package/dist/integrations/incidentio/rules.d.ts +55 -0
  271. package/dist/integrations/incidentio/rules.d.ts.map +1 -0
  272. package/dist/integrations/incidentio/rules.js +189 -0
  273. package/dist/integrations/incidentio/rules.js.map +1 -0
  274. package/dist/integrations/issue-reconcile-worker.d.ts +19 -0
  275. package/dist/integrations/issue-reconcile-worker.d.ts.map +1 -0
  276. package/dist/integrations/issue-reconcile-worker.js +97 -0
  277. package/dist/integrations/issue-reconcile-worker.js.map +1 -0
  278. package/dist/integrations/issue-reconciler.d.ts +51 -0
  279. package/dist/integrations/issue-reconciler.d.ts.map +1 -0
  280. package/dist/integrations/issue-reconciler.js +158 -0
  281. package/dist/integrations/issue-reconciler.js.map +1 -0
  282. package/dist/integrations/jira/adf.d.ts +26 -0
  283. package/dist/integrations/jira/adf.d.ts.map +1 -0
  284. package/dist/integrations/jira/adf.js +73 -0
  285. package/dist/integrations/jira/adf.js.map +1 -0
  286. package/dist/integrations/jira/agent-tools.d.ts +45 -0
  287. package/dist/integrations/jira/agent-tools.d.ts.map +1 -0
  288. package/dist/integrations/jira/agent-tools.js +87 -0
  289. package/dist/integrations/jira/agent-tools.js.map +1 -0
  290. package/dist/integrations/jira/api.d.ts +157 -0
  291. package/dist/integrations/jira/api.d.ts.map +1 -0
  292. package/dist/integrations/jira/api.js +141 -0
  293. package/dist/integrations/jira/api.js.map +1 -0
  294. package/dist/integrations/jira/claim.d.ts +9 -0
  295. package/dist/integrations/jira/claim.d.ts.map +1 -0
  296. package/dist/integrations/jira/claim.js +15 -0
  297. package/dist/integrations/jira/claim.js.map +1 -0
  298. package/dist/integrations/jira/default-rules.d.ts +47 -0
  299. package/dist/integrations/jira/default-rules.d.ts.map +1 -0
  300. package/dist/integrations/jira/default-rules.js +69 -0
  301. package/dist/integrations/jira/default-rules.js.map +1 -0
  302. package/dist/integrations/jira/integration.d.ts +114 -0
  303. package/dist/integrations/jira/integration.d.ts.map +1 -0
  304. package/dist/integrations/jira/integration.js +407 -0
  305. package/dist/integrations/jira/integration.js.map +1 -0
  306. package/dist/integrations/jira/issue-reconciler.d.ts +10 -0
  307. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -0
  308. package/dist/integrations/jira/issue-reconciler.js +70 -0
  309. package/dist/integrations/jira/issue-reconciler.js.map +1 -0
  310. package/dist/integrations/jira/reconciliation-config.d.ts +3 -0
  311. package/dist/integrations/jira/reconciliation-config.d.ts.map +1 -0
  312. package/dist/integrations/jira/reconciliation-config.js +17 -0
  313. package/dist/integrations/jira/reconciliation-config.js.map +1 -0
  314. package/dist/integrations/jira/routes.d.ts +54 -0
  315. package/dist/integrations/jira/routes.d.ts.map +1 -0
  316. package/dist/integrations/jira/routes.js +260 -0
  317. package/dist/integrations/jira/routes.js.map +1 -0
  318. package/dist/integrations/jira/rules.d.ts +57 -0
  319. package/dist/integrations/jira/rules.d.ts.map +1 -0
  320. package/dist/integrations/jira/rules.js +189 -0
  321. package/dist/integrations/jira/rules.js.map +1 -0
  322. package/dist/integrations/linear/agent-tools.d.ts +34 -0
  323. package/dist/integrations/linear/agent-tools.d.ts.map +1 -0
  324. package/dist/integrations/linear/agent-tools.js +87 -0
  325. package/dist/integrations/linear/agent-tools.js.map +1 -0
  326. package/dist/integrations/linear/claim.d.ts +8 -0
  327. package/dist/integrations/linear/claim.d.ts.map +1 -0
  328. package/dist/integrations/linear/claim.js +14 -0
  329. package/dist/integrations/linear/claim.js.map +1 -0
  330. package/dist/integrations/linear/default-rules.d.ts +46 -0
  331. package/dist/integrations/linear/default-rules.d.ts.map +1 -0
  332. package/dist/integrations/linear/default-rules.js +70 -0
  333. package/dist/integrations/linear/default-rules.js.map +1 -0
  334. package/dist/integrations/linear/integration.d.ts +260 -0
  335. package/dist/integrations/linear/integration.d.ts.map +1 -0
  336. package/dist/integrations/linear/integration.js +900 -0
  337. package/dist/integrations/linear/integration.js.map +1 -0
  338. package/dist/integrations/linear/issue-reconciler.d.ts +8 -0
  339. package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -0
  340. package/dist/integrations/linear/issue-reconciler.js +73 -0
  341. package/dist/integrations/linear/issue-reconciler.js.map +1 -0
  342. package/dist/integrations/linear/reconciliation-config.d.ts +3 -0
  343. package/dist/integrations/linear/reconciliation-config.d.ts.map +1 -0
  344. package/dist/integrations/linear/reconciliation-config.js +21 -0
  345. package/dist/integrations/linear/reconciliation-config.js.map +1 -0
  346. package/dist/integrations/linear/routes.d.ts +81 -0
  347. package/dist/integrations/linear/routes.d.ts.map +1 -0
  348. package/dist/integrations/linear/routes.js +380 -0
  349. package/dist/integrations/linear/routes.js.map +1 -0
  350. package/dist/integrations/linear/rules.d.ts +54 -0
  351. package/dist/integrations/linear/rules.d.ts.map +1 -0
  352. package/dist/integrations/linear/rules.js +189 -0
  353. package/dist/integrations/linear/rules.js.map +1 -0
  354. package/dist/integrations/linear/storage.d.ts +65 -0
  355. package/dist/integrations/linear/storage.d.ts.map +1 -0
  356. package/dist/integrations/linear/storage.js +1 -0
  357. package/dist/integrations/platform/api-client.d.ts +26 -0
  358. package/dist/integrations/platform/api-client.d.ts.map +1 -0
  359. package/dist/integrations/platform/api-client.js +177 -0
  360. package/dist/integrations/platform/api-client.js.map +1 -0
  361. package/dist/integrations/platform/connect/routes.d.ts +39 -0
  362. package/dist/integrations/platform/connect/routes.d.ts.map +1 -0
  363. package/dist/integrations/platform/connect/routes.js +133 -0
  364. package/dist/integrations/platform/connect/routes.js.map +1 -0
  365. package/dist/integrations/platform/github/event-worker.d.ts +58 -0
  366. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -0
  367. package/dist/integrations/platform/github/event-worker.js +449 -0
  368. package/dist/integrations/platform/github/event-worker.js.map +1 -0
  369. package/dist/integrations/platform/github/integration.d.ts +89 -0
  370. package/dist/integrations/platform/github/integration.d.ts.map +1 -0
  371. package/dist/integrations/platform/github/integration.js +1266 -0
  372. package/dist/integrations/platform/github/integration.js.map +1 -0
  373. package/dist/integrations/platform/gitlab/event-worker.d.ts +64 -0
  374. package/dist/integrations/platform/gitlab/event-worker.d.ts.map +1 -0
  375. package/dist/integrations/platform/gitlab/event-worker.js +305 -0
  376. package/dist/integrations/platform/gitlab/event-worker.js.map +1 -0
  377. package/dist/integrations/platform/gitlab/integration.d.ts +57 -0
  378. package/dist/integrations/platform/gitlab/integration.d.ts.map +1 -0
  379. package/dist/integrations/platform/gitlab/integration.js +113 -0
  380. package/dist/integrations/platform/gitlab/integration.js.map +1 -0
  381. package/dist/integrations/platform/incidentio/integration.d.ts +74 -0
  382. package/dist/integrations/platform/incidentio/integration.d.ts.map +1 -0
  383. package/dist/integrations/platform/incidentio/integration.js +406 -0
  384. package/dist/integrations/platform/incidentio/integration.js.map +1 -0
  385. package/dist/integrations/platform/jira/agent-tools.d.ts +36 -0
  386. package/dist/integrations/platform/jira/agent-tools.d.ts.map +1 -0
  387. package/dist/integrations/platform/jira/agent-tools.js +85 -0
  388. package/dist/integrations/platform/jira/agent-tools.js.map +1 -0
  389. package/dist/integrations/platform/jira/integration.d.ts +65 -0
  390. package/dist/integrations/platform/jira/integration.d.ts.map +1 -0
  391. package/dist/integrations/platform/jira/integration.js +546 -0
  392. package/dist/integrations/platform/jira/integration.js.map +1 -0
  393. package/dist/integrations/platform/jira/routes.d.ts +55 -0
  394. package/dist/integrations/platform/jira/routes.d.ts.map +1 -0
  395. package/dist/integrations/platform/jira/routes.js +274 -0
  396. package/dist/integrations/platform/jira/routes.js.map +1 -0
  397. package/dist/integrations/platform/linear/event-worker.d.ts +105 -0
  398. package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -0
  399. package/dist/integrations/platform/linear/event-worker.js +379 -0
  400. package/dist/integrations/platform/linear/event-worker.js.map +1 -0
  401. package/dist/integrations/platform/linear/integration.d.ts +92 -0
  402. package/dist/integrations/platform/linear/integration.d.ts.map +1 -0
  403. package/dist/integrations/platform/linear/integration.js +754 -0
  404. package/dist/integrations/platform/linear/integration.js.map +1 -0
  405. package/dist/integrations/pull-request-head.d.ts +18 -0
  406. package/dist/integrations/pull-request-head.d.ts.map +1 -0
  407. package/dist/integrations/pull-request-head.js +45 -0
  408. package/dist/integrations/pull-request-head.js.map +1 -0
  409. package/dist/integrations/reconciliation-config.d.ts +3 -0
  410. package/dist/integrations/reconciliation-config.d.ts.map +1 -0
  411. package/dist/integrations/reconciliation-config.js +16 -0
  412. package/dist/integrations/reconciliation-config.js.map +1 -0
  413. package/dist/integrations/slack/connect-route.d.ts +46 -0
  414. package/dist/integrations/slack/connect-route.d.ts.map +1 -0
  415. package/dist/integrations/slack/connect-route.js +186 -0
  416. package/dist/integrations/slack/connect-route.js.map +1 -0
  417. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts +8 -0
  418. package/dist/integrations/slack/emoji-shortcodes.generated.d.ts.map +1 -0
  419. package/dist/integrations/slack/emoji-shortcodes.generated.js +1985 -0
  420. package/dist/integrations/slack/emoji-shortcodes.generated.js.map +1 -0
  421. package/dist/integrations/slack/emoji.d.ts +3 -0
  422. package/dist/integrations/slack/emoji.d.ts.map +1 -0
  423. package/dist/integrations/slack/emoji.js +12 -0
  424. package/dist/integrations/slack/emoji.js.map +1 -0
  425. package/dist/integrations/slack/feed-publisher.d.ts +26 -0
  426. package/dist/integrations/slack/feed-publisher.d.ts.map +1 -0
  427. package/dist/integrations/slack/feed-publisher.js +44 -0
  428. package/dist/integrations/slack/feed-publisher.js.map +1 -0
  429. package/dist/integrations/slack/integration.d.ts +80 -0
  430. package/dist/integrations/slack/integration.d.ts.map +1 -0
  431. package/dist/integrations/slack/integration.js +93 -0
  432. package/dist/integrations/slack/integration.js.map +1 -0
  433. package/dist/integrations/slack/slack.d.ts +205 -0
  434. package/dist/integrations/slack/slack.d.ts.map +1 -0
  435. package/dist/integrations/slack/slack.js +653 -0
  436. package/dist/integrations/slack/slack.js.map +1 -0
  437. package/dist/integrations/subscription-session.d.ts +49 -0
  438. package/dist/integrations/subscription-session.d.ts.map +1 -0
  439. package/dist/integrations/subscription-session.js +103 -0
  440. package/dist/integrations/subscription-session.js.map +1 -0
  441. package/dist/integrations/workos/integration.d.ts +39 -0
  442. package/dist/integrations/workos/integration.d.ts.map +1 -0
  443. package/dist/integrations/workos/integration.js +91 -0
  444. package/dist/integrations/workos/integration.js.map +1 -0
  445. package/dist/packages/_internals/workspace/dist/index.js +48 -0
  446. package/dist/packages/_internals/workspace/dist/index.js.map +1 -0
  447. package/dist/platform-auth-host.d.ts +4 -0
  448. package/dist/platform-auth-host.d.ts.map +1 -0
  449. package/dist/platform-auth-host.js +18 -0
  450. package/dist/platform-auth-host.js.map +1 -0
  451. package/dist/review-verdict.d.ts +6 -0
  452. package/dist/review-verdict.d.ts.map +1 -0
  453. package/dist/review-verdict.js +14 -0
  454. package/dist/review-verdict.js.map +1 -0
  455. package/dist/routes/attention-activity.d.ts +23 -0
  456. package/dist/routes/attention-activity.d.ts.map +1 -0
  457. package/dist/routes/attention-activity.js +152 -0
  458. package/dist/routes/attention-activity.js.map +1 -0
  459. package/dist/routes/attention-parked.d.ts +22 -0
  460. package/dist/routes/attention-parked.d.ts.map +1 -0
  461. package/dist/routes/attention-parked.js +136 -0
  462. package/dist/routes/attention-parked.js.map +1 -0
  463. package/dist/routes/attention-proposed.d.ts +3 -0
  464. package/dist/routes/attention-proposed.d.ts.map +1 -0
  465. package/dist/routes/attention-proposed.js +21 -0
  466. package/dist/routes/attention-proposed.js.map +1 -0
  467. package/dist/routes/attention-providers.d.ts +159 -0
  468. package/dist/routes/attention-providers.d.ts.map +1 -0
  469. package/dist/routes/attention-providers.js +524 -0
  470. package/dist/routes/attention-providers.js.map +1 -0
  471. package/dist/routes/attention.d.ts +23 -0
  472. package/dist/routes/attention.d.ts.map +1 -0
  473. package/dist/routes/attention.js +219 -0
  474. package/dist/routes/attention.js.map +1 -0
  475. package/dist/routes/automation-runs.d.ts +37 -0
  476. package/dist/routes/automation-runs.d.ts.map +1 -0
  477. package/dist/routes/automation-runs.js +196 -0
  478. package/dist/routes/automation-runs.js.map +1 -0
  479. package/dist/routes/config.d.ts +238 -0
  480. package/dist/routes/config.d.ts.map +1 -0
  481. package/dist/routes/config.js +1011 -0
  482. package/dist/routes/config.js.map +1 -0
  483. package/dist/routes/contracts.d.ts +1080 -0
  484. package/dist/routes/contracts.d.ts.map +1 -0
  485. package/dist/routes/contracts.js +673 -0
  486. package/dist/routes/contracts.js.map +1 -0
  487. package/dist/routes/custom-provider-source.d.ts +52 -0
  488. package/dist/routes/custom-provider-source.d.ts.map +1 -0
  489. package/dist/routes/custom-provider-source.js +124 -0
  490. package/dist/routes/custom-provider-source.js.map +1 -0
  491. package/dist/routes/fs.d.ts +189 -0
  492. package/dist/routes/fs.d.ts.map +1 -0
  493. package/dist/routes/fs.js +916 -0
  494. package/dist/routes/fs.js.map +1 -0
  495. package/dist/routes/intake.d.ts +64 -0
  496. package/dist/routes/intake.d.ts.map +1 -0
  497. package/dist/routes/intake.js +627 -0
  498. package/dist/routes/intake.js.map +1 -0
  499. package/dist/routes/knowledge.d.ts +247 -0
  500. package/dist/routes/knowledge.d.ts.map +1 -0
  501. package/dist/routes/knowledge.js +1128 -0
  502. package/dist/routes/knowledge.js.map +1 -0
  503. package/dist/routes/oauth.d.ts +43 -0
  504. package/dist/routes/oauth.d.ts.map +1 -0
  505. package/dist/routes/oauth.js +477 -0
  506. package/dist/routes/oauth.js.map +1 -0
  507. package/dist/routes/projects.d.ts +68 -0
  508. package/dist/routes/projects.d.ts.map +1 -0
  509. package/dist/routes/projects.js +919 -0
  510. package/dist/routes/projects.js.map +1 -0
  511. package/dist/routes/provider-credentials.d.ts +82 -0
  512. package/dist/routes/provider-credentials.d.ts.map +1 -0
  513. package/dist/routes/provider-credentials.js +80 -0
  514. package/dist/routes/provider-credentials.js.map +1 -0
  515. package/dist/routes/route.d.ts +48 -0
  516. package/dist/routes/route.d.ts.map +1 -0
  517. package/dist/routes/route.js +15 -0
  518. package/dist/routes/route.js.map +1 -0
  519. package/dist/routes/skills.d.ts +30 -0
  520. package/dist/routes/skills.d.ts.map +1 -0
  521. package/dist/routes/skills.js +198 -0
  522. package/dist/routes/skills.js.map +1 -0
  523. package/dist/routes/source-control-sessions.d.ts +22 -0
  524. package/dist/routes/source-control-sessions.d.ts.map +1 -0
  525. package/dist/routes/source-control-sessions.js +356 -0
  526. package/dist/routes/source-control-sessions.js.map +1 -0
  527. package/dist/routes/source-control-settings.d.ts +10 -0
  528. package/dist/routes/source-control-settings.d.ts.map +1 -0
  529. package/dist/routes/source-control-settings.js +87 -0
  530. package/dist/routes/source-control-settings.js.map +1 -0
  531. package/dist/routes/supervisor.d.ts +25 -0
  532. package/dist/routes/supervisor.d.ts.map +1 -0
  533. package/dist/routes/supervisor.js +35 -0
  534. package/dist/routes/supervisor.js.map +1 -0
  535. package/dist/routes/surface.d.ts +133 -0
  536. package/dist/routes/surface.d.ts.map +1 -0
  537. package/dist/routes/surface.js +518 -0
  538. package/dist/routes/surface.js.map +1 -0
  539. package/dist/routes/telemetry.d.ts +13 -0
  540. package/dist/routes/telemetry.d.ts.map +1 -0
  541. package/dist/routes/telemetry.js +60 -0
  542. package/dist/routes/telemetry.js.map +1 -0
  543. package/dist/routes/tenant-credentials.d.ts +87 -0
  544. package/dist/routes/tenant-credentials.d.ts.map +1 -0
  545. package/dist/routes/tenant-credentials.js +219 -0
  546. package/dist/routes/tenant-credentials.js.map +1 -0
  547. package/dist/routes/work-items.d.ts +49 -0
  548. package/dist/routes/work-items.d.ts.map +1 -0
  549. package/dist/routes/work-items.js +633 -0
  550. package/dist/routes/work-items.js.map +1 -0
  551. package/dist/rules/binding-context.d.ts +59 -0
  552. package/dist/rules/binding-context.d.ts.map +1 -0
  553. package/dist/rules/binding-context.js +134 -0
  554. package/dist/rules/binding-context.js.map +1 -0
  555. package/dist/rules/decision-applicability.d.ts +32 -0
  556. package/dist/rules/decision-applicability.d.ts.map +1 -0
  557. package/dist/rules/decision-applicability.js +56 -0
  558. package/dist/rules/decision-applicability.js.map +1 -0
  559. package/dist/rules/dispatch-errors.d.ts +13 -0
  560. package/dist/rules/dispatch-errors.d.ts.map +1 -0
  561. package/dist/rules/dispatch-errors.js +105 -0
  562. package/dist/rules/dispatch-errors.js.map +1 -0
  563. package/dist/rules/dispatcher.d.ts +86 -0
  564. package/dist/rules/dispatcher.d.ts.map +1 -0
  565. package/dist/rules/dispatcher.js +1159 -0
  566. package/dist/rules/dispatcher.js.map +1 -0
  567. package/dist/rules/event-rules.d.ts +23 -0
  568. package/dist/rules/event-rules.d.ts.map +1 -0
  569. package/dist/rules/event-rules.js +46 -0
  570. package/dist/rules/event-rules.js.map +1 -0
  571. package/dist/rules/index.d.ts +6 -0
  572. package/dist/rules/index.d.ts.map +1 -0
  573. package/dist/rules/index.js +4 -0
  574. package/dist/rules/processor.d.ts +90 -0
  575. package/dist/rules/processor.d.ts.map +1 -0
  576. package/dist/rules/processor.js +486 -0
  577. package/dist/rules/processor.js.map +1 -0
  578. package/dist/rules/resolve.d.ts +15 -0
  579. package/dist/rules/resolve.d.ts.map +1 -0
  580. package/dist/rules/resolve.js +23 -0
  581. package/dist/rules/resolve.js.map +1 -0
  582. package/dist/rules/review-source-tool.d.ts +105 -0
  583. package/dist/rules/review-source-tool.d.ts.map +1 -0
  584. package/dist/rules/review-source-tool.js +109 -0
  585. package/dist/rules/review-source-tool.js.map +1 -0
  586. package/dist/rules/start-coordinator.d.ts +64 -0
  587. package/dist/rules/start-coordinator.d.ts.map +1 -0
  588. package/dist/rules/start-coordinator.js +246 -0
  589. package/dist/rules/start-coordinator.js.map +1 -0
  590. package/dist/rules/terminal-cleanup.d.ts +38 -0
  591. package/dist/rules/terminal-cleanup.d.ts.map +1 -0
  592. package/dist/rules/terminal-cleanup.js +68 -0
  593. package/dist/rules/terminal-cleanup.js.map +1 -0
  594. package/dist/rules/tools.d.ts +15 -0
  595. package/dist/rules/tools.d.ts.map +1 -0
  596. package/dist/rules/tools.js +185 -0
  597. package/dist/rules/tools.js.map +1 -0
  598. package/dist/rules/transition-service.d.ts +93 -0
  599. package/dist/rules/transition-service.d.ts.map +1 -0
  600. package/dist/rules/transition-service.js +402 -0
  601. package/dist/rules/transition-service.js.map +1 -0
  602. package/dist/rules/types.d.ts +553 -0
  603. package/dist/rules/types.d.ts.map +1 -0
  604. package/dist/rules/types.js +154 -0
  605. package/dist/rules/types.js.map +1 -0
  606. package/dist/rules/validation.d.ts +21 -0
  607. package/dist/rules/validation.d.ts.map +1 -0
  608. package/dist/rules/validation.js +327 -0
  609. package/dist/rules/validation.js.map +1 -0
  610. package/dist/sandbox/callback-factory-sandbox.d.ts +15 -0
  611. package/dist/sandbox/callback-factory-sandbox.d.ts.map +1 -0
  612. package/dist/sandbox/callback-factory-sandbox.js +22 -0
  613. package/dist/sandbox/callback-factory-sandbox.js.map +1 -0
  614. package/dist/sandbox/git-ref.d.ts +7 -0
  615. package/dist/sandbox/git-ref.d.ts.map +1 -0
  616. package/dist/sandbox/git-ref.js +15 -0
  617. package/dist/sandbox/git-ref.js.map +1 -0
  618. package/dist/sandbox/local-factory-sandbox.d.ts +20 -0
  619. package/dist/sandbox/local-factory-sandbox.d.ts.map +1 -0
  620. package/dist/sandbox/local-factory-sandbox.js +27 -0
  621. package/dist/sandbox/local-factory-sandbox.js.map +1 -0
  622. package/dist/sandbox/materialization.d.ts +41 -0
  623. package/dist/sandbox/materialization.d.ts.map +1 -0
  624. package/dist/sandbox/materialization.js +18 -0
  625. package/dist/sandbox/materialization.js.map +1 -0
  626. package/dist/sandbox/session-retirement.d.ts +45 -0
  627. package/dist/sandbox/session-retirement.d.ts.map +1 -0
  628. package/dist/sandbox/session-retirement.js +153 -0
  629. package/dist/sandbox/session-retirement.js.map +1 -0
  630. package/dist/sandbox/session-sandbox.d.ts +185 -0
  631. package/dist/sandbox/session-sandbox.d.ts.map +1 -0
  632. package/dist/sandbox/session-sandbox.js +248 -0
  633. package/dist/sandbox/session-sandbox.js.map +1 -0
  634. package/dist/sandbox/workdir.d.ts +45 -0
  635. package/dist/sandbox/workdir.d.ts.map +1 -0
  636. package/dist/sandbox/workdir.js +64 -0
  637. package/dist/sandbox/workdir.js.map +1 -0
  638. package/dist/secret-encryption.d.ts +25 -0
  639. package/dist/secret-encryption.d.ts.map +1 -0
  640. package/dist/secret-encryption.js +107 -0
  641. package/dist/secret-encryption.js.map +1 -0
  642. package/dist/server-error.d.ts +12 -0
  643. package/dist/server-error.d.ts.map +1 -0
  644. package/dist/server-error.js +16 -0
  645. package/dist/server-error.js.map +1 -0
  646. package/dist/session/credential-policy.d.ts +20 -0
  647. package/dist/session/credential-policy.d.ts.map +1 -0
  648. package/dist/session/credential-policy.js +70 -0
  649. package/dist/session/credential-policy.js.map +1 -0
  650. package/dist/session/default-model-hydration.d.ts +46 -0
  651. package/dist/session/default-model-hydration.d.ts.map +1 -0
  652. package/dist/session/default-model-hydration.js +85 -0
  653. package/dist/session/default-model-hydration.js.map +1 -0
  654. package/dist/session/environment-repositories.d.ts +31 -0
  655. package/dist/session/environment-repositories.d.ts.map +1 -0
  656. package/dist/session/environment-repositories.js +89 -0
  657. package/dist/session/environment-repositories.js.map +1 -0
  658. package/dist/session/environment-state-processor.d.ts +59 -0
  659. package/dist/session/environment-state-processor.d.ts.map +1 -0
  660. package/dist/session/environment-state-processor.js +105 -0
  661. package/dist/session/environment-state-processor.js.map +1 -0
  662. package/dist/session/factory-session.d.ts +159 -0
  663. package/dist/session/factory-session.d.ts.map +1 -0
  664. package/dist/session/factory-session.js +226 -0
  665. package/dist/session/factory-session.js.map +1 -0
  666. package/dist/session/filesystem-capture.d.ts +50 -0
  667. package/dist/session/filesystem-capture.d.ts.map +1 -0
  668. package/dist/session/filesystem-capture.js +231 -0
  669. package/dist/session/filesystem-capture.js.map +1 -0
  670. package/dist/session/first-exec-capture.d.ts +38 -0
  671. package/dist/session/first-exec-capture.d.ts.map +1 -0
  672. package/dist/session/first-exec-capture.js +91 -0
  673. package/dist/session/first-exec-capture.js.map +1 -0
  674. package/dist/session/first-message-capture.d.ts +33 -0
  675. package/dist/session/first-message-capture.d.ts.map +1 -0
  676. package/dist/session/first-message-capture.js +35 -0
  677. package/dist/session/first-message-capture.js.map +1 -0
  678. package/dist/session/live-sessions.d.ts +63 -0
  679. package/dist/session/live-sessions.d.ts.map +1 -0
  680. package/dist/session/live-sessions.js +90 -0
  681. package/dist/session/live-sessions.js.map +1 -0
  682. package/dist/session/memory-settings-hydration.d.ts +36 -0
  683. package/dist/session/memory-settings-hydration.d.ts.map +1 -0
  684. package/dist/session/memory-settings-hydration.js +43 -0
  685. package/dist/session/memory-settings-hydration.js.map +1 -0
  686. package/dist/session/org-seed.d.ts +67 -0
  687. package/dist/session/org-seed.d.ts.map +1 -0
  688. package/dist/session/org-seed.js +53 -0
  689. package/dist/session/org-seed.js.map +1 -0
  690. package/dist/session/run-audit.d.ts +54 -0
  691. package/dist/session/run-audit.d.ts.map +1 -0
  692. package/dist/session/run-audit.js +124 -0
  693. package/dist/session/run-audit.js.map +1 -0
  694. package/dist/session/session-title.d.ts +7 -0
  695. package/dist/session/session-title.d.ts.map +1 -0
  696. package/dist/session/session-title.js +14 -0
  697. package/dist/session/session-title.js.map +1 -0
  698. package/dist/session/shell-commands.d.ts +5 -0
  699. package/dist/session/shell-commands.d.ts.map +1 -0
  700. package/dist/session/shell-commands.js +25 -0
  701. package/dist/session/shell-commands.js.map +1 -0
  702. package/dist/session/source-control-tools.d.ts +25 -0
  703. package/dist/session/source-control-tools.d.ts.map +1 -0
  704. package/dist/session/source-control-tools.js +594 -0
  705. package/dist/session/source-control-tools.js.map +1 -0
  706. package/dist/session/thread-title-mirror.d.ts +35 -0
  707. package/dist/session/thread-title-mirror.d.ts.map +1 -0
  708. package/dist/session/thread-title-mirror.js +51 -0
  709. package/dist/session/thread-title-mirror.js.map +1 -0
  710. package/dist/session/work-item-repository.d.ts +21 -0
  711. package/dist/session/work-item-repository.d.ts.map +1 -0
  712. package/dist/session/work-item-repository.js +113 -0
  713. package/dist/session/work-item-repository.js.map +1 -0
  714. package/dist/skills/catalog.d.ts +14 -0
  715. package/dist/skills/catalog.d.ts.map +1 -0
  716. package/dist/skills/catalog.js +62 -0
  717. package/dist/skills/catalog.js.map +1 -0
  718. package/dist/skills/service.d.ts +70 -0
  719. package/dist/skills/service.d.ts.map +1 -0
  720. package/dist/skills/service.js +88 -0
  721. package/dist/skills/service.js.map +1 -0
  722. package/dist/spa-static.d.ts +33 -0
  723. package/dist/spa-static.d.ts.map +1 -0
  724. package/dist/spa-static.js +104 -0
  725. package/dist/spa-static.js.map +1 -0
  726. package/dist/state-signing.d.ts +59 -0
  727. package/dist/state-signing.d.ts.map +1 -0
  728. package/dist/state-signing.js +83 -0
  729. package/dist/state-signing.js.map +1 -0
  730. package/dist/storage/domains/audit/actions.d.ts +24 -0
  731. package/dist/storage/domains/audit/actions.d.ts.map +1 -0
  732. package/dist/storage/domains/audit/actions.js +69 -0
  733. package/dist/storage/domains/audit/actions.js.map +1 -0
  734. package/dist/storage/domains/audit/actors.d.ts +5 -0
  735. package/dist/storage/domains/audit/actors.d.ts.map +1 -0
  736. package/dist/storage/domains/audit/actors.js +25 -0
  737. package/dist/storage/domains/audit/actors.js.map +1 -0
  738. package/dist/storage/domains/audit/agent-audit.d.ts +30 -0
  739. package/dist/storage/domains/audit/agent-audit.d.ts.map +1 -0
  740. package/dist/storage/domains/audit/agent-audit.js +93 -0
  741. package/dist/storage/domains/audit/agent-audit.js.map +1 -0
  742. package/dist/storage/domains/audit/base.d.ts +133 -0
  743. package/dist/storage/domains/audit/base.d.ts.map +1 -0
  744. package/dist/storage/domains/audit/base.js +206 -0
  745. package/dist/storage/domains/audit/base.js.map +1 -0
  746. package/dist/storage/domains/audit/domain.d.ts +79 -0
  747. package/dist/storage/domains/audit/domain.d.ts.map +1 -0
  748. package/dist/storage/domains/audit/domain.js +248 -0
  749. package/dist/storage/domains/audit/domain.js.map +1 -0
  750. package/dist/storage/domains/audit/wire.d.ts +24 -0
  751. package/dist/storage/domains/audit/wire.d.ts.map +1 -0
  752. package/dist/storage/domains/audit/wire.js +16 -0
  753. package/dist/storage/domains/audit/wire.js.map +1 -0
  754. package/dist/storage/domains/channel-identity/base.d.ts +100 -0
  755. package/dist/storage/domains/channel-identity/base.d.ts.map +1 -0
  756. package/dist/storage/domains/channel-identity/base.js +164 -0
  757. package/dist/storage/domains/channel-identity/base.js.map +1 -0
  758. package/dist/storage/domains/comments/activity.d.ts +40 -0
  759. package/dist/storage/domains/comments/activity.d.ts.map +1 -0
  760. package/dist/storage/domains/comments/activity.js +94 -0
  761. package/dist/storage/domains/comments/activity.js.map +1 -0
  762. package/dist/storage/domains/comments/actor.d.ts +51 -0
  763. package/dist/storage/domains/comments/actor.d.ts.map +1 -0
  764. package/dist/storage/domains/comments/actor.js +38 -0
  765. package/dist/storage/domains/comments/actor.js.map +1 -0
  766. package/dist/storage/domains/comments/base.d.ts +245 -0
  767. package/dist/storage/domains/comments/base.d.ts.map +1 -0
  768. package/dist/storage/domains/comments/base.js +533 -0
  769. package/dist/storage/domains/comments/base.js.map +1 -0
  770. package/dist/storage/domains/comments/domain.d.ts +135 -0
  771. package/dist/storage/domains/comments/domain.d.ts.map +1 -0
  772. package/dist/storage/domains/comments/domain.js +285 -0
  773. package/dist/storage/domains/comments/domain.js.map +1 -0
  774. package/dist/storage/domains/comments/feed-context.d.ts +22 -0
  775. package/dist/storage/domains/comments/feed-context.d.ts.map +1 -0
  776. package/dist/storage/domains/comments/feed-context.js +89 -0
  777. package/dist/storage/domains/comments/feed-context.js.map +1 -0
  778. package/dist/storage/domains/comments/feed-sync.d.ts +21 -0
  779. package/dist/storage/domains/comments/feed-sync.d.ts.map +1 -0
  780. package/dist/storage/domains/comments/feed-sync.js +1 -0
  781. package/dist/storage/domains/comments/parse.d.ts +23 -0
  782. package/dist/storage/domains/comments/parse.d.ts.map +1 -0
  783. package/dist/storage/domains/comments/parse.js +90 -0
  784. package/dist/storage/domains/comments/parse.js.map +1 -0
  785. package/dist/storage/domains/comments/routes.d.ts +24 -0
  786. package/dist/storage/domains/comments/routes.d.ts.map +1 -0
  787. package/dist/storage/domains/comments/routes.js +302 -0
  788. package/dist/storage/domains/comments/routes.js.map +1 -0
  789. package/dist/storage/domains/comments/schema.d.ts +5 -0
  790. package/dist/storage/domains/comments/schema.d.ts.map +1 -0
  791. package/dist/storage/domains/comments/schema.js +179 -0
  792. package/dist/storage/domains/comments/schema.js.map +1 -0
  793. package/dist/storage/domains/comments/wire.d.ts +40 -0
  794. package/dist/storage/domains/comments/wire.d.ts.map +1 -0
  795. package/dist/storage/domains/comments/wire.js +37 -0
  796. package/dist/storage/domains/comments/wire.js.map +1 -0
  797. package/dist/storage/domains/credentials/base.d.ts +136 -0
  798. package/dist/storage/domains/credentials/base.d.ts.map +1 -0
  799. package/dist/storage/domains/credentials/base.js +294 -0
  800. package/dist/storage/domains/credentials/base.js.map +1 -0
  801. package/dist/storage/domains/custom-providers/base.d.ts +59 -0
  802. package/dist/storage/domains/custom-providers/base.d.ts.map +1 -0
  803. package/dist/storage/domains/custom-providers/base.js +176 -0
  804. package/dist/storage/domains/custom-providers/base.js.map +1 -0
  805. package/dist/storage/domains/filesystem/base.d.ts +26 -0
  806. package/dist/storage/domains/filesystem/base.d.ts.map +1 -0
  807. package/dist/storage/domains/filesystem/base.js +74 -0
  808. package/dist/storage/domains/filesystem/base.js.map +1 -0
  809. package/dist/storage/domains/intake/base.d.ts +150 -0
  810. package/dist/storage/domains/intake/base.d.ts.map +1 -0
  811. package/dist/storage/domains/intake/base.js +431 -0
  812. package/dist/storage/domains/intake/base.js.map +1 -0
  813. package/dist/storage/domains/integrations/base.d.ts +128 -0
  814. package/dist/storage/domains/integrations/base.d.ts.map +1 -0
  815. package/dist/storage/domains/integrations/base.js +333 -0
  816. package/dist/storage/domains/integrations/base.js.map +1 -0
  817. package/dist/storage/domains/memory-settings/base.d.ts +58 -0
  818. package/dist/storage/domains/memory-settings/base.d.ts.map +1 -0
  819. package/dist/storage/domains/memory-settings/base.js +129 -0
  820. package/dist/storage/domains/memory-settings/base.js.map +1 -0
  821. package/dist/storage/domains/model-defaults/base.d.ts +29 -0
  822. package/dist/storage/domains/model-defaults/base.d.ts.map +1 -0
  823. package/dist/storage/domains/model-defaults/base.js +79 -0
  824. package/dist/storage/domains/model-defaults/base.js.map +1 -0
  825. package/dist/storage/domains/projects/base.d.ts +191 -0
  826. package/dist/storage/domains/projects/base.d.ts.map +1 -0
  827. package/dist/storage/domains/projects/base.js +352 -0
  828. package/dist/storage/domains/projects/base.js.map +1 -0
  829. package/dist/storage/domains/queue-health/base.d.ts +52 -0
  830. package/dist/storage/domains/queue-health/base.d.ts.map +1 -0
  831. package/dist/storage/domains/queue-health/base.js +122 -0
  832. package/dist/storage/domains/queue-health/base.js.map +1 -0
  833. package/dist/storage/domains/source-control/base.d.ts +422 -0
  834. package/dist/storage/domains/source-control/base.d.ts.map +1 -0
  835. package/dist/storage/domains/source-control/base.js +1114 -0
  836. package/dist/storage/domains/source-control/base.js.map +1 -0
  837. package/dist/storage/domains/source-control/inmemory.d.ts +147 -0
  838. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -0
  839. package/dist/storage/domains/source-control/inmemory.js +416 -0
  840. package/dist/storage/domains/source-control/inmemory.js.map +1 -0
  841. package/dist/storage/domains/work-items/base.d.ts +794 -0
  842. package/dist/storage/domains/work-items/base.d.ts.map +1 -0
  843. package/dist/storage/domains/work-items/base.js +2747 -0
  844. package/dist/storage/domains/work-items/base.js.map +1 -0
  845. package/dist/storage/domains/work-items/board-version.d.ts +26 -0
  846. package/dist/storage/domains/work-items/board-version.d.ts.map +1 -0
  847. package/dist/storage/domains/work-items/board-version.js +110 -0
  848. package/dist/storage/domains/work-items/board-version.js.map +1 -0
  849. package/dist/storage/domains/work-items/metrics.d.ts +97 -0
  850. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -0
  851. package/dist/storage/domains/work-items/metrics.js +226 -0
  852. package/dist/storage/domains/work-items/metrics.js.map +1 -0
  853. package/dist/supervisor/health-worker.d.ts +19 -0
  854. package/dist/supervisor/health-worker.d.ts.map +1 -0
  855. package/dist/supervisor/health-worker.js +74 -0
  856. package/dist/supervisor/health-worker.js.map +1 -0
  857. package/dist/supervisor/health.d.ts +79 -0
  858. package/dist/supervisor/health.d.ts.map +1 -0
  859. package/dist/supervisor/health.js +228 -0
  860. package/dist/supervisor/health.js.map +1 -0
  861. package/dist/supervisor/instructions.d.ts +6 -0
  862. package/dist/supervisor/instructions.d.ts.map +1 -0
  863. package/dist/supervisor/instructions.js +66 -0
  864. package/dist/supervisor/instructions.js.map +1 -0
  865. package/dist/supervisor/read-tools.d.ts +43 -0
  866. package/dist/supervisor/read-tools.d.ts.map +1 -0
  867. package/dist/supervisor/read-tools.js +343 -0
  868. package/dist/supervisor/read-tools.js.map +1 -0
  869. package/dist/supervisor/session-messaging.d.ts +26 -0
  870. package/dist/supervisor/session-messaging.d.ts.map +1 -0
  871. package/dist/supervisor/session-messaging.js +21 -0
  872. package/dist/supervisor/session-messaging.js.map +1 -0
  873. package/dist/supervisor/session.d.ts +38 -0
  874. package/dist/supervisor/session.d.ts.map +1 -0
  875. package/dist/supervisor/session.js +79 -0
  876. package/dist/supervisor/session.js.map +1 -0
  877. package/dist/supervisor/write-tools.d.ts +30 -0
  878. package/dist/supervisor/write-tools.d.ts.map +1 -0
  879. package/dist/supervisor/write-tools.js +231 -0
  880. package/dist/supervisor/write-tools.js.map +1 -0
  881. package/dist/telemetry-types.d.ts +7 -0
  882. package/dist/telemetry-types.d.ts.map +1 -0
  883. package/dist/telemetry-types.js +24 -0
  884. package/dist/telemetry-types.js.map +1 -0
  885. package/dist/telemetry.d.ts +9 -0
  886. package/dist/telemetry.d.ts.map +1 -0
  887. package/dist/telemetry.js +47 -0
  888. package/dist/telemetry.js.map +1 -0
  889. package/dist/timing.d.ts +15 -0
  890. package/dist/timing.d.ts.map +1 -0
  891. package/dist/timing.js +34 -0
  892. package/dist/timing.js.map +1 -0
  893. package/dist/work-item-branch.d.ts +33 -0
  894. package/dist/work-item-branch.d.ts.map +1 -0
  895. package/dist/work-item-branch.js +70 -0
  896. package/dist/work-item-branch.js.map +1 -0
  897. package/dist/workspace.d.ts +131 -0
  898. package/dist/workspace.d.ts.map +1 -0
  899. package/dist/workspace.js +995 -0
  900. package/dist/workspace.js.map +1 -0
  901. package/factory-skills/configure-factory-rules/SKILL.md +122 -0
  902. package/factory-skills/factory-complete-issue/SKILL.md +24 -0
  903. package/factory-skills/factory-gitlab-rereview/SKILL.md +22 -0
  904. package/factory-skills/factory-gitlab-review/SKILL.md +48 -0
  905. package/factory-skills/factory-plan/SKILL.md +72 -0
  906. package/factory-skills/factory-rereview/SKILL.md +225 -0
  907. package/factory-skills/factory-review/SKILL.md +214 -0
  908. package/factory-skills/factory-review/references/archaeology.md +225 -0
  909. package/factory-skills/factory-review/references/categories/README.md +34 -0
  910. package/factory-skills/factory-review/references/categories/behavior-change.md +36 -0
  911. package/factory-skills/factory-review/references/categories/bug-fix.md +37 -0
  912. package/factory-skills/factory-review/references/categories/docs.md +32 -0
  913. package/factory-skills/factory-review/references/categories/experimental-flagged.md +34 -0
  914. package/factory-skills/factory-review/references/categories/infra-tooling.md +37 -0
  915. package/factory-skills/factory-review/references/categories/internal-capability.md +35 -0
  916. package/factory-skills/factory-review/references/categories/large-cross-cutting.md +35 -0
  917. package/factory-skills/factory-review/references/categories/mechanical.md +36 -0
  918. package/factory-skills/factory-review/references/categories/performance.md +33 -0
  919. package/factory-skills/factory-review/references/categories/public-api.md +38 -0
  920. package/factory-skills/factory-review/references/categories/refactor.md +35 -0
  921. package/factory-skills/factory-review/references/categories/revert.md +31 -0
  922. package/factory-skills/factory-review/references/categories/schema-storage.md +39 -0
  923. package/factory-skills/factory-review/references/categories/security.md +35 -0
  924. package/factory-skills/factory-review/references/categories/tests-only.md +38 -0
  925. package/factory-skills/factory-triage/SKILL.md +197 -0
  926. package/package.json +92 -0
@@ -0,0 +1,1021 @@
1
+ import { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from "../../rules/validation.js";
2
+ import { boardEventHandlers, boardForWorkItem, eventBoardId, rulePhaseField, withBoardClosure, workItemPhaseSemantics } from "../../boards/semantics.js";
3
+ import "../../boards/index.js";
4
+ import { FACTORY_PULL_REQUEST_RECONCILIATION_KEY, WorkItemUpdateConflictError } from "../../storage/domains/work-items/base.js";
5
+ import { cardLabels, moveCardToBoard } from "../../boards/relocate.js";
6
+ import { selectEventRule } from "../../rules/event-rules.js";
7
+ import { resolveIntakeLabelRoute } from "../../storage/domains/intake/base.js";
8
+ import { recordPullRequestHead } from "../pull-request-head.js";
9
+ import { changeRequestTargetKey } from "./subscriptions.js";
10
+ import { createHash } from "crypto";
11
+ //#region src/integrations/github/rules.ts
12
+ const TRUSTED_PERMISSIONS = /* @__PURE__ */ new Set(["write", "admin"]);
13
+ const RULE_TIMEOUT_MS = 5e3;
14
+ const FACTORY_TRIAGE_COMMENT_MARKER = "<!-- mastra-factory-triage -->";
15
+ async function withRuleTimeout(promise) {
16
+ let timeout;
17
+ try {
18
+ return await Promise.race([promise, new Promise((_, reject) => {
19
+ timeout = setTimeout(() => reject(/* @__PURE__ */ new Error("FACTORY_RULE_TIMEOUT")), RULE_TIMEOUT_MS);
20
+ })]);
21
+ } finally {
22
+ if (timeout) clearTimeout(timeout);
23
+ }
24
+ }
25
+ function object(value) {
26
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
27
+ }
28
+ function timestamp(value) {
29
+ const parsed = typeof value === "string" ? Date.parse(value) : NaN;
30
+ return Number.isNaN(parsed) ? void 0 : parsed;
31
+ }
32
+ function string(value) {
33
+ return typeof value === "string" && value.length > 0 ? value : void 0;
34
+ }
35
+ function number(value) {
36
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
37
+ }
38
+ function boolean(value) {
39
+ return typeof value === "boolean" ? value : void 0;
40
+ }
41
+ function actorLogins(value) {
42
+ if (!Array.isArray(value)) return [];
43
+ return value.flatMap((actor) => {
44
+ const login = string(object(actor)?.login);
45
+ return login ? [login] : [];
46
+ });
47
+ }
48
+ function sameLabels(a, b) {
49
+ return a.length === b.length && a.every((label, index) => label === b[index]);
50
+ }
51
+ function labelNames(value) {
52
+ if (!Array.isArray(value)) return [];
53
+ return value.flatMap((label) => {
54
+ if (typeof label === "string") return label ? [label] : [];
55
+ const name = string(object(label)?.name);
56
+ return name ? [name] : [];
57
+ });
58
+ }
59
+ function parseFactoryReviewCommand(body, target) {
60
+ if (!body || !target) return void 0;
61
+ const firstLine = body.split("\n").map((line) => line.trim()).find((line) => line.length > 0)?.toLowerCase();
62
+ if (!firstLine) return void 0;
63
+ const mention = `@${target.toLowerCase().replace(/\[bot\]$/, "")}`;
64
+ if (firstLine === `${mention} review`) return {
65
+ command: "review",
66
+ target
67
+ };
68
+ if (firstLine === `${mention} re-review`) return {
69
+ command: "re-review",
70
+ target
71
+ };
72
+ }
73
+ function eventName(parsed) {
74
+ const action = string(parsed.payload.action);
75
+ if (parsed.event === "issues" && action === "opened") return "issueOpened";
76
+ if (parsed.event === "issues" && action === "edited") {
77
+ const changes = object(parsed.payload.changes);
78
+ return object(changes?.title) || object(changes?.body) ? "issueEdited" : void 0;
79
+ }
80
+ if (parsed.event === "issues" && action === "closed") return "issueClosed";
81
+ if (parsed.event === "issue_comment") {
82
+ if (object(object(parsed.payload.issue)?.pull_request)) return action === "created" ? "pullRequestCommentCreated" : void 0;
83
+ if (action === "created") return "issueCommentCreated";
84
+ if (action === "edited") return "issueCommentEdited";
85
+ if (action === "deleted") return "issueCommentDeleted";
86
+ }
87
+ if (parsed.event === "pull_request" && action === "opened") return "pullRequestOpened";
88
+ if (parsed.event === "pull_request" && action === "synchronize") return "pullRequestUpdated";
89
+ if (parsed.event === "pull_request" && action === "closed") return boolean(object(parsed.payload.pull_request)?.merged) ? "pullRequestMerged" : "pullRequestClosed";
90
+ if (parsed.event === "pull_request" && action === "review_requested") return "pullRequestReviewRequested";
91
+ if (parsed.event === "pull_request_review" && action === "submitted") return "pullRequestReviewSubmitted";
92
+ }
93
+ /**
94
+ * Canonical source keys (`github-issue:N`, `github-pr:N`) do not identify a
95
+ * repository, so a project linked to several repositories could bind repo A's
96
+ * event to repo B's same-numbered card. The card's intake-stamped URL is
97
+ * authoritative; the intake-stamped `githubRepositoryId` covers URL-less
98
+ * cards. A card with neither signal cannot be attributed by number alone.
99
+ */
100
+ const MAX_STALE_RULE_ATTEMPTS = 3;
101
+ function cardBelongsToRepository(item, repositoryId, repositoryFullName) {
102
+ const url = item.externalSource?.url;
103
+ if (url) {
104
+ const match = /^https?:\/\/[^/]+\/(.+)\/(?:issues|pull)\/\d+(?:[/?#]|$)/.exec(url);
105
+ if (match && match[1] === repositoryFullName) return true;
106
+ }
107
+ return item.metadata?.githubRepositoryId === repositoryId;
108
+ }
109
+ function canonicalSourceKey(kind, itemNumber) {
110
+ return kind === "issue" ? `github-issue:${itemNumber}` : `github-pr:${itemNumber}`;
111
+ }
112
+ function legacySourceKey(repositoryId, kind, itemNumber) {
113
+ return `github:${repositoryId}:${kind}:${itemNumber}`;
114
+ }
115
+ function provenanceTarget(repositoryId, pullRequestNumber) {
116
+ return `factory-pr-provenance:${repositoryId}:${pullRequestNumber}`;
117
+ }
118
+ function workItemSource(item) {
119
+ if (!item.externalSource) return "manual";
120
+ return item.externalSource.type === "pull-request" ? "github-pr" : "github-issue";
121
+ }
122
+ function workItemSourceKey(item) {
123
+ return item.externalSource?.externalId ?? null;
124
+ }
125
+ async function trustedCollaborator(github, input) {
126
+ const permission = await github.getRepositoryCollaboratorPermission(input.installationId, input.repository, input.login);
127
+ return permission !== void 0 && TRUSTED_PERMISSIONS.has(permission);
128
+ }
129
+ function authorAwaitingTrust(item, repository) {
130
+ const metadata = item.metadata ?? {};
131
+ if (typeof metadata.author !== "string" || metadata.authorTrusted !== void 0) return void 0;
132
+ if ((reconcilablePullRequestNumber(item, repository) ?? reconcilableIssueNumber(item, repository)) === void 0) return void 0;
133
+ if (!item.externalSource?.url && /^github-(?:pr|issue):\d+$/.test(item.externalSource?.externalId ?? "") && metadata.githubRepositoryId !== repository.id) return void 0;
134
+ return metadata.author;
135
+ }
136
+ function sweepTrustLookup(github, repository) {
137
+ const cache = /* @__PURE__ */ new Map();
138
+ return async (login) => {
139
+ const cached = cache.get(login);
140
+ if (cached !== void 0) return cached;
141
+ const trusted = await trustedCollaborator(github, {
142
+ installationId: repository.installationId,
143
+ repository: repository.fullName,
144
+ login
145
+ });
146
+ cache.set(login, trusted);
147
+ return trusted;
148
+ };
149
+ }
150
+ async function githubActor(github, input) {
151
+ const trusted = await trustedCollaborator(github, input).catch(() => false);
152
+ return {
153
+ type: "github",
154
+ login: input.login,
155
+ trusted,
156
+ factoryAuthored: input.factoryAuthored
157
+ };
158
+ }
159
+ function pullRequestProvenance(data, factoryProjectId) {
160
+ if (!data || data.kind !== "factory-pr-provenance" || typeof data.workItemId !== "string") return null;
161
+ if (data.factoryProjectId !== factoryProjectId) return null;
162
+ return {
163
+ kind: "factory-pr-provenance",
164
+ workItemId: data.workItemId
165
+ };
166
+ }
167
+ /** Identity under which label-driven relocations are recorded. */
168
+ const LABEL_ROUTE_USER_ID = "factory-rule-dispatcher";
169
+ function issueLabelChange(parsed) {
170
+ const action = string(parsed.payload.action);
171
+ return parsed.event === "issues" && (action === "labeled" || action === "unlabeled");
172
+ }
173
+ /**
174
+ * Whether a login is Factory itself. Prefers the resolved identity, which is
175
+ * observed from Factory's own writes, and falls back to the configured slug.
176
+ */
177
+ function isFactoryGithubLogin(github, login) {
178
+ if (github.identity?.known) return github.identity.matches(login);
179
+ const slug = github.slug?.trim();
180
+ if (!slug || !login) return false;
181
+ return login.toLowerCase() === `${slug.toLowerCase()}[bot]`;
182
+ }
183
+ var GithubRules = class {
184
+ options;
185
+ constructor(options) {
186
+ this.options = options;
187
+ }
188
+ /**
189
+ * Whether a login is Factory itself. Prefers the resolved identity, which is
190
+ * observed from Factory's own writes, and falls back to the configured slug.
191
+ * An unset slug must not silently answer "not Factory" — that is what
192
+ * disabled every self-loop guard.
193
+ */
194
+ #isFactoryLogin(login) {
195
+ return isFactoryGithubLogin(this.options.github, login);
196
+ }
197
+ #factoryMentionTarget() {
198
+ const identity = this.options.github.identity;
199
+ if (identity?.known) return identity.login;
200
+ const slug = this.options.github.slug?.trim();
201
+ return slug ? `${slug.toLowerCase()}[bot]` : void 0;
202
+ }
203
+ /**
204
+ * Board an issue lands on: the one its labels select under the project's label routes, else the
205
+ * board the repository's intake source binding names. Only installed boards count. Undefined
206
+ * leaves built-in routing (Work) in charge.
207
+ */
208
+ async #intakeTarget(project, repositoryName, labels) {
209
+ const intake = this.options.intake;
210
+ if (!intake) return void 0;
211
+ const { orgId, factoryProjectId } = project;
212
+ if (labels.length > 0) {
213
+ const route = resolveIntakeLabelRoute(await intake.listLabelRoutes({
214
+ orgId,
215
+ factoryProjectId,
216
+ integrationId: "github"
217
+ }), labels);
218
+ const board = route ? this.options.boards.get(route.board) : void 0;
219
+ if (board) return {
220
+ board: board.id,
221
+ initialPhase: board.initialPhase
222
+ };
223
+ }
224
+ const slug = repositoryName.toLowerCase();
225
+ const binding = (await intake.listBindings({
226
+ orgId,
227
+ integrationId: "github"
228
+ })).find((candidate) => candidate.factoryProjectId === factoryProjectId && (candidate.sourceId === project.projectRepository.repositoryId || candidate.sourceId.toLowerCase() === slug));
229
+ const board = binding?.board ? this.options.boards.get(binding.board) : void 0;
230
+ return board ? {
231
+ board: board.id,
232
+ initialPhase: board.initialPhase
233
+ } : void 0;
234
+ }
235
+ /**
236
+ * `labeled` / `unlabeled` are not rule events: the labels only decide which board the card belongs
237
+ * on, so the card is re-routed here and its label metadata refreshed. Cards a run owns, and
238
+ * finished cards, stay where they are.
239
+ */
240
+ async #relocateLabeledIssue(parsed, repositoryId, repositoryName, project) {
241
+ const issue = object(parsed.payload.issue);
242
+ const issueNumber = issue?.pull_request === void 0 ? number(issue?.number) : void 0;
243
+ if (!issueNumber) return { status: "ignored" };
244
+ const found = await this.#relatedItem(project.orgId, project.factoryProjectId, repositoryId, repositoryName, issueNumber, void 0, void 0, null);
245
+ if (!found || found.externalSource?.type !== "issue") return { status: "ignored" };
246
+ const labels = labelNames(issue?.labels);
247
+ let item = found;
248
+ let changed = false;
249
+ if (!sameLabels(cardLabels(item), labels)) {
250
+ let updated;
251
+ try {
252
+ updated = await this.options.storage.update({
253
+ orgId: item.orgId,
254
+ id: item.id,
255
+ userId: LABEL_ROUTE_USER_ID,
256
+ patch: { metadata: {
257
+ ...item.metadata ?? {},
258
+ labels
259
+ } },
260
+ expectedRevision: item.revision
261
+ });
262
+ } catch (error) {
263
+ if (!(error instanceof WorkItemUpdateConflictError)) throw error;
264
+ return { status: "ignored" };
265
+ }
266
+ if (!updated) return { status: "ignored" };
267
+ item = updated.item;
268
+ changed = true;
269
+ }
270
+ const target = await this.#intakeTarget(project, repositoryName, labels);
271
+ const outcome = await moveCardToBoard({
272
+ workItems: this.options.storage,
273
+ boardRegistry: this.options.boards,
274
+ userId: LABEL_ROUTE_USER_ID,
275
+ item,
276
+ targetBoard: target?.board ?? "work"
277
+ });
278
+ return { status: changed || outcome === "moved" ? "committed" : "ignored" };
279
+ }
280
+ async ingest(parsed) {
281
+ const event = eventName(parsed);
282
+ const labelChange = issueLabelChange(parsed);
283
+ const repository = object(parsed.payload.repository);
284
+ const installationId = number(object(parsed.payload.installation)?.id);
285
+ const repositoryId = number(repository?.id);
286
+ const repositoryName = string(repository?.full_name);
287
+ const login = string(object(parsed.payload.sender)?.login);
288
+ if (parsed.event === "push" && installationId && repositoryId) {
289
+ await this.#handOffPush(parsed, installationId, repositoryId);
290
+ return { status: "ignored" };
291
+ }
292
+ if (!event && !labelChange || !installationId || !repositoryId || !repositoryName || !login) return { status: "ignored" };
293
+ const projects = await this.options.sourceControl.projectRepositories.listByExternalRepository({
294
+ installationExternalId: String(installationId),
295
+ repositoryExternalId: String(repositoryId)
296
+ });
297
+ if (projects.length === 0) return { status: "ignored" };
298
+ const results = [];
299
+ for (const project of projects) results.push(event ? await this.#ingestProject(parsed, event, installationId, repositoryId, repositoryName, login, project) : await this.#relocateLabeledIssue(parsed, repositoryId, repositoryName, project));
300
+ if (results.some((result) => result.status === "committed")) return { status: "committed" };
301
+ if (results.some((result) => result.status === "replayed")) return { status: "replayed" };
302
+ return results[0] ?? { status: "ignored" };
303
+ }
304
+ /**
305
+ * A push is not a work-item event; it only reaches the environment build
306
+ * hand-off, once per project the repository is linked to. The hook decides
307
+ * whether the project builds on push.
308
+ */
309
+ async #handOffPush(parsed, installationId, repositoryId) {
310
+ const onRepositoryPush = this.options.onRepositoryPush;
311
+ const ref = string(parsed.payload.ref);
312
+ const defaultBranch = string(object(parsed.payload.repository)?.default_branch);
313
+ if (!onRepositoryPush || !ref || !defaultBranch) return;
314
+ const projects = await this.options.sourceControl.projectRepositories.listByExternalRepository({
315
+ installationExternalId: String(installationId),
316
+ repositoryExternalId: String(repositoryId)
317
+ });
318
+ for (const project of projects) onRepositoryPush({
319
+ orgId: project.orgId,
320
+ factoryProjectId: project.factoryProjectId,
321
+ projectRepository: {
322
+ id: project.projectRepository.id,
323
+ inEnvironment: project.projectRepository.inEnvironment
324
+ },
325
+ ref,
326
+ defaultBranch
327
+ });
328
+ }
329
+ async #ingestProject(parsed, event, installationId, repositoryId, repositoryName, login, project) {
330
+ const factoryProject = await this.options.projects.get({
331
+ orgId: project.orgId,
332
+ id: project.factoryProjectId
333
+ });
334
+ if (!factoryProject) return { status: "missing" };
335
+ const issue = object(parsed.payload.issue);
336
+ const issueComment = object(parsed.payload.comment);
337
+ const changes = object(parsed.payload.changes);
338
+ const commentOnPullRequest = object(parsed.payload.issue)?.pull_request !== void 0;
339
+ const pullRequest = object(parsed.payload.pull_request) ?? (commentOnPullRequest ? issue : void 0);
340
+ const issueNumber = commentOnPullRequest ? void 0 : number(issue?.number);
341
+ const pullRequestNumber = number(pullRequest?.number);
342
+ const provenance = pullRequestNumber ? pullRequestProvenance((await this.options.integrationStorage.subscriptions.listByTarget(provenanceTarget(repositoryId, pullRequestNumber), { status: "active" })).find((subscription) => subscription.orgId === project.orgId && subscription.data?.factoryProjectId === project.factoryProjectId)?.data, project.factoryProjectId) : null;
343
+ const reviewRequested = event === "pullRequestReviewRequested";
344
+ const reviewCommand = event === "pullRequestCommentCreated" ? parseFactoryReviewCommand(string(issueComment?.body), this.#factoryMentionTarget()) : void 0;
345
+ const reviewEntryRequested = reviewRequested || reviewCommand !== void 0;
346
+ const senderIsResponder = reviewRequested || event === "pullRequestCommentCreated" || event === "pullRequestReviewSubmitted";
347
+ const reReviewEvent = reviewEntryRequested || event === "pullRequestUpdated";
348
+ const requestedReviewer = string(object(parsed.payload.requested_reviewer)?.login);
349
+ const pullRequestAuthor = string(object(pullRequest?.user)?.login);
350
+ const pullRequestFactoryAuthored = provenance !== null || this.#isFactoryLogin(pullRequestAuthor);
351
+ const resolvedItem = await this.#relatedItem(project.orgId, project.factoryProjectId, repositoryId, repositoryName, issueNumber, pullRequestNumber, string(object(pullRequest?.head)?.ref), reReviewEvent ? null : provenance, senderIsResponder && !reviewEntryRequested);
352
+ const relatedItem = reviewEntryRequested && resolvedItem?.externalSource?.type !== "pull-request" ? void 0 : resolvedItem;
353
+ const intake = issueNumber ? await this.#intakeTarget(project, repositoryName, labelNames(issue?.labels)) : void 0;
354
+ const actor = await githubActor(this.options.github, {
355
+ installationId,
356
+ repository: repositoryName,
357
+ login,
358
+ factoryAuthored: !senderIsResponder && provenance !== null || this.#isFactoryLogin(login)
359
+ });
360
+ if (actor.type === "github" && actor.factoryAuthored && (event === "issueCommentCreated" || event === "issueCommentEdited") && string(issueComment?.body)?.includes(FACTORY_TRIAGE_COMMENT_MARKER)) return { status: "ignored" };
361
+ const evaluate = async (item, ingressIdentity, pullRequestIntake = false, attempt = 1) => {
362
+ const context = {
363
+ tenant: {
364
+ orgId: project.orgId,
365
+ projectId: project.factoryProjectId
366
+ },
367
+ actor,
368
+ ingress: {
369
+ type: "github",
370
+ id: ingressIdentity
371
+ },
372
+ cause: `github.${event}`,
373
+ causalChain: [],
374
+ configVersion: this.options.configVersion,
375
+ ...item ? {
376
+ item: {
377
+ id: item.id,
378
+ source: workItemSource(item),
379
+ sourceKey: workItemSourceKey(item),
380
+ parentWorkItemId: item.parentWorkItemId,
381
+ title: item.title,
382
+ url: item.externalSource?.url ?? null,
383
+ stages: item.stages,
384
+ acceptedAt: item.acceptedAt,
385
+ metadata: item.metadata
386
+ },
387
+ board: boardForWorkItem(item),
388
+ itemRevision: item.revision,
389
+ ...withBoardClosure(this.options.boards, item),
390
+ ...rulePhaseField(this.options.boards, item)
391
+ } : {},
392
+ ...intake ? { intake } : {},
393
+ ...pullRequestIntake ? { pullRequestIntake: true } : {},
394
+ event,
395
+ deliveryId: parsed.deliveryId,
396
+ factory: { createdAt: factoryProject.createdAt.toISOString() },
397
+ repository: {
398
+ id: repositoryId,
399
+ fullName: repositoryName,
400
+ installationId
401
+ },
402
+ ...issueNumber && string(issue?.title) && string(issue?.html_url) ? { issue: {
403
+ number: issueNumber,
404
+ title: string(issue?.title),
405
+ url: string(issue?.html_url),
406
+ ...string(issue?.created_at) ? { createdAt: string(issue?.created_at) } : {},
407
+ ...string(issue?.updated_at) ? { updatedAt: string(issue?.updated_at) } : {},
408
+ assignees: actorLogins(issue?.assignees),
409
+ labels: labelNames(issue?.labels),
410
+ ...string(issue?.state) === "closed" || string(issue?.state) === "open" ? { state: string(issue?.state) } : {},
411
+ ...string(issue?.state_reason) ? { stateReason: string(issue?.state_reason) } : {}
412
+ } } : {},
413
+ ...event === "issueEdited" ? { issueChange: {
414
+ title: Boolean(object(changes?.title)),
415
+ body: Boolean(object(changes?.body))
416
+ } } : {},
417
+ ...number(issueComment?.id) ? { issueComment: {
418
+ id: number(issueComment?.id),
419
+ ...string(issueComment?.body) ? { body: string(issueComment?.body) } : {},
420
+ ...string(issueComment?.html_url) ? { url: string(issueComment?.html_url) } : {},
421
+ ...string(object(issueComment?.user)?.login) ? { author: string(object(issueComment?.user)?.login) } : {},
422
+ ...string(object(issueComment?.user)?.type) ? { authorType: string(object(issueComment?.user)?.type) } : {},
423
+ ...string(issueComment?.created_at) ? { createdAt: string(issueComment?.created_at) } : {},
424
+ ...string(issueComment?.updated_at) ? { updatedAt: string(issueComment?.updated_at) } : {}
425
+ } } : {},
426
+ ...pullRequestNumber && string(pullRequest?.title) && string(pullRequest?.html_url) ? { pullRequest: {
427
+ number: pullRequestNumber,
428
+ title: string(pullRequest?.title),
429
+ url: string(pullRequest?.html_url),
430
+ ...string(pullRequest?.created_at) ? { createdAt: string(pullRequest?.created_at) } : {},
431
+ state: string(pullRequest?.state) === "closed" ? "closed" : "open",
432
+ draft: boolean(pullRequest?.draft) ?? false,
433
+ merged: boolean(pullRequest?.merged) ?? false,
434
+ assignees: actorLogins(pullRequest?.assignees),
435
+ requestedReviewers: actorLogins(pullRequest?.requested_reviewers),
436
+ labels: labelNames(pullRequest?.labels),
437
+ ...pullRequestAuthor ? { author: pullRequestAuthor } : {},
438
+ factoryAuthored: pullRequestFactoryAuthored,
439
+ headBranch: string(object(pullRequest?.head)?.ref) ?? "",
440
+ baseBranch: string(object(pullRequest?.base)?.ref) ?? ""
441
+ } } : {},
442
+ ...reviewRequested && requestedReviewer ? { reviewRequest: {
443
+ reviewer: requestedReviewer,
444
+ factoryReviewer: this.#isFactoryLogin(requestedReviewer)
445
+ } } : {},
446
+ ...reviewCommand ? { reviewCommand } : {},
447
+ ...object(parsed.payload.review) ? { review: {
448
+ id: number(object(parsed.payload.review)?.id) ?? 0,
449
+ state: string(object(parsed.payload.review)?.state) ?? "unknown",
450
+ url: string(object(parsed.payload.review)?.html_url) ?? "",
451
+ ...string(object(object(parsed.payload.review)?.user)?.login) ? { author: string(object(object(parsed.payload.review)?.user)?.login) } : {},
452
+ ...string(object(parsed.payload.review)?.body) ? { body: string(object(parsed.payload.review)?.body) } : {}
453
+ } } : {}
454
+ };
455
+ const rule = selectEventRule(this.options.github.rules, boardEventHandlers(this.options.boards, eventBoardId(context), "github"), event);
456
+ let decision;
457
+ let decisions = [];
458
+ let outcome = { status: "accepted" };
459
+ try {
460
+ decision = rule ? await withRuleTimeout(Promise.resolve(rule(Object.freeze(context)))) : void 0;
461
+ if (decision?.type === "reject") outcome = {
462
+ status: "rejected",
463
+ code: decision.code,
464
+ reason: decision.reason
465
+ };
466
+ else if (decision) decisions = validateFactoryRuleDecisions([decision]).map((entry) => {
467
+ assertFactoryDecisionTarget(entry, this.options.boards, item ? boardForWorkItem(item) : void 0);
468
+ return { ...entry };
469
+ });
470
+ } catch (error) {
471
+ const timedOut = error instanceof Error && error.message === "FACTORY_RULE_TIMEOUT";
472
+ outcome = {
473
+ status: "rejected",
474
+ code: timedOut ? "timeout" : "rule_error",
475
+ reason: timedOut ? "Factory rule evaluation timed out." : error instanceof Error ? error.message.slice(0, 2e3) : "Factory GitHub rule failed."
476
+ };
477
+ }
478
+ const committed = await this.options.storage.commitRuleEvaluation({
479
+ orgId: project.orgId,
480
+ factoryProjectId: project.factoryProjectId,
481
+ workItemId: item?.id ?? null,
482
+ ingress: {
483
+ identity: ingressIdentity,
484
+ triggerType: `github.${event}`
485
+ },
486
+ configVersion: this.options.configVersion,
487
+ expectedRevision: item?.revision ?? null,
488
+ actor: { ...actor },
489
+ outcome,
490
+ decisions,
491
+ causalChain: [],
492
+ now: /* @__PURE__ */ new Date()
493
+ });
494
+ if (committed.status === "stale") {
495
+ if (attempt >= MAX_STALE_RULE_ATTEMPTS) throw new Error(`Factory GitHub rule evaluation for ${ingressIdentity} kept losing revision races.`);
496
+ const fresh = item ? await this.options.storage.get({
497
+ orgId: project.orgId,
498
+ id: item.id
499
+ }) : null;
500
+ if (item && !fresh) return { status: "missing" };
501
+ return evaluate(fresh ?? void 0, ingressIdentity, pullRequestIntake, attempt + 1);
502
+ }
503
+ return { status: committed.status };
504
+ };
505
+ const deliveryIdentity = `${installationId}:${parsed.deliveryId}`;
506
+ const pullRequestOpened = event === "pullRequestOpened";
507
+ const primary = await evaluate(relatedItem, deliveryIdentity, pullRequestOpened);
508
+ const linked = (event === "pullRequestMerged" || event === "pullRequestClosed") && relatedItem && pullRequestNumber ? await this.#linkedClosureItem(project.orgId, project.factoryProjectId, repositoryId, repositoryName, pullRequestNumber, relatedItem) : void 0;
509
+ const stampClosed = async (companionStatus) => {
510
+ if (!pullRequestNumber) return;
511
+ if (pullRequestOpened) {
512
+ const trusted = actor.type === "github" && actor.trusted || pullRequestFactoryAuthored;
513
+ const reviewCard = authoringItem && trusted ? await this.#linkedClosureItem(project.orgId, project.factoryProjectId, repositoryId, repositoryName, pullRequestNumber, authoringItem) : void 0;
514
+ const stillOpen = companionStatus === "replayed" ? reviewCard !== void 0 && reviewCard.metadata?.state !== "closed" : reviewCard?.metadata?.state !== "closed";
515
+ if (authoringItem && trusted && stillOpen) {
516
+ const head = authoringItem.metadata?.openPullRequestNumber !== pullRequestNumber ? {
517
+ pullRequestHeadSha: string(object(pullRequest?.head)?.sha)?.toLowerCase() ?? null,
518
+ pullRequestHeadAt: timestamp(pullRequest?.updated_at) ?? null
519
+ } : {};
520
+ await this.options.storage.update({
521
+ orgId: authoringItem.orgId,
522
+ id: authoringItem.id,
523
+ userId: "factory-rule-dispatcher",
524
+ patch: { metadata: {
525
+ openPullRequestNumber: pullRequestNumber,
526
+ ...head
527
+ } }
528
+ });
529
+ }
530
+ return;
531
+ }
532
+ if (event !== "pullRequestMerged" && event !== "pullRequestClosed") return;
533
+ for (const card of [relatedItem, linked]) {
534
+ if (!card) continue;
535
+ if (card.externalSource?.type !== "pull-request") {
536
+ const recorded = card.metadata?.openPullRequestNumber;
537
+ const settled = {
538
+ ...(typeof recorded !== "number" || recorded === pullRequestNumber) && event === "pullRequestMerged" && typeof card.metadata?.reviewVerdict === "string" ? { reviewVerdict: null } : {},
539
+ ...recorded === pullRequestNumber ? { openPullRequestNumber: null } : {}
540
+ };
541
+ if (Object.keys(settled).length > 0) await this.options.storage.update({
542
+ orgId: card.orgId,
543
+ id: card.id,
544
+ userId: "factory-rule-dispatcher",
545
+ patch: { metadata: settled }
546
+ });
547
+ continue;
548
+ }
549
+ await this.options.storage.update({
550
+ orgId: card.orgId,
551
+ id: card.id,
552
+ userId: "factory-rule-dispatcher",
553
+ patch: { metadata: {
554
+ state: "closed",
555
+ merged: event === "pullRequestMerged"
556
+ } }
557
+ });
558
+ }
559
+ };
560
+ const authoringItem = linked === void 0 && pullRequestOpened && relatedItem !== void 0 && relatedItem.externalSource?.type !== "pull-request" ? relatedItem : void 0;
561
+ const stampHead = async () => {
562
+ const headSha = string(object(pullRequest?.head)?.sha)?.toLowerCase();
563
+ if (event !== "pullRequestUpdated" || !headSha || !pullRequestNumber) return;
564
+ const headAt = timestamp(pullRequest?.updated_at);
565
+ if (relatedItem?.externalSource?.type !== "pull-request") return;
566
+ const parent = await this.#linkedClosureItem(project.orgId, project.factoryProjectId, repositoryId, repositoryName, pullRequestNumber, relatedItem);
567
+ await recordPullRequestHead(this.options.storage, {
568
+ orgId: relatedItem.orgId,
569
+ id: relatedItem.id,
570
+ headSha,
571
+ headAt
572
+ });
573
+ if (parent) await recordPullRequestHead(this.options.storage, {
574
+ orgId: parent.orgId,
575
+ id: parent.id,
576
+ headSha,
577
+ headAt,
578
+ ownedPullRequestNumber: pullRequestNumber
579
+ });
580
+ };
581
+ if (linked === void 0 && authoringItem === void 0) {
582
+ await stampClosed();
583
+ await stampHead();
584
+ return primary;
585
+ }
586
+ const companion = linked ?? authoringItem;
587
+ const secondary = await evaluate(companion, `${deliveryIdentity}:${companion?.id ?? "pull-request"}`);
588
+ await stampClosed(secondary.status);
589
+ for (const status of ["committed", "replayed"]) if (primary.status === status || secondary.status === status) return { status };
590
+ return primary;
591
+ }
592
+ /**
593
+ * The other card a closed pull request concerns, joined through the Review
594
+ * card's `parentWorkItemId` — the link `upsertLinkedWorkItem` records when the
595
+ * pull request is opened, and therefore an exact join that needs no branch
596
+ * heuristics. Returns nothing when the pull request has only one card, which
597
+ * is every pull request Factory did not open from a work item's session.
598
+ */
599
+ async #linkedClosureItem(orgId, projectId, repositoryId, repositoryFullName, pullRequestNumber, resolved) {
600
+ const items = await this.options.storage.list({
601
+ orgId,
602
+ factoryProjectId: projectId
603
+ });
604
+ const linked = resolved.externalSource?.type === "pull-request" ? items.find((item) => item.id === resolved.parentWorkItemId) : items.find((item) => item.parentWorkItemId === resolved.id && (item.externalSource?.externalId === canonicalSourceKey("pull-request", pullRequestNumber) || item.externalSource?.externalId === legacySourceKey(repositoryId, "pull-request", pullRequestNumber)) && cardBelongsToRepository(item, repositoryId, repositoryFullName));
605
+ return linked?.id === resolved.id ? void 0 : linked;
606
+ }
607
+ async #relatedItem(orgId, projectId, repositoryId, repositoryFullName, issueNumber, pullRequestNumber, pullRequestHeadBranch, provenance, preferAuthoringItem = false) {
608
+ const items = await this.options.storage.list({
609
+ orgId,
610
+ factoryProjectId: projectId
611
+ });
612
+ const resolved = this.#resolveItem(items, repositoryId, repositoryFullName, issueNumber, pullRequestNumber, pullRequestHeadBranch, provenance);
613
+ if (preferAuthoringItem && resolved?.externalSource?.type === "pull-request" && resolved.parentWorkItemId) return items.find((item) => item.id === resolved.parentWorkItemId) ?? resolved;
614
+ return resolved;
615
+ }
616
+ #resolveItem(items, repositoryId, repositoryFullName, issueNumber, pullRequestNumber, pullRequestHeadBranch, provenance) {
617
+ if (provenance) return items.find((item) => item.id === provenance.workItemId);
618
+ if (issueNumber) return items.find((item) => item.externalSource?.externalId === canonicalSourceKey("issue", issueNumber) && cardBelongsToRepository(item, repositoryId, repositoryFullName)) ?? items.find((item) => item.externalSource?.externalId === legacySourceKey(repositoryId, "issue", issueNumber));
619
+ if (pullRequestNumber) return items.find((item) => item.externalSource?.externalId === canonicalSourceKey("pull-request", pullRequestNumber) && cardBelongsToRepository(item, repositoryId, repositoryFullName)) ?? items.find((item) => item.externalSource?.externalId === legacySourceKey(repositoryId, "pull-request", pullRequestNumber)) ?? (pullRequestHeadBranch ? items.find((item) => item.externalSource?.type !== "pull-request" && Object.values(item.sessions).some((session) => session.branch === pullRequestHeadBranch)) : void 0);
620
+ }
621
+ };
622
+ const RECONCILE_ERROR_SAMPLE_LIMIT = 5;
623
+ function sameStrings(left, right) {
624
+ if (right === void 0) return true;
625
+ if (!Array.isArray(left)) return false;
626
+ const leftValues = new Set(left.flatMap((value) => typeof value === "string" ? [value] : []));
627
+ const rightValues = new Set(right);
628
+ return leftValues.size === rightValues.size && [...leftValues].every((value) => rightValues.has(value));
629
+ }
630
+ /**
631
+ * Extracts the PR number a work item tracks, but only when the item belongs
632
+ * to the given repository. Card URLs pin the repository unambiguously; the
633
+ * legacy source key embeds the repository id. Canonical keys (`github-pr:N`)
634
+ * carry no repository, so they are only trusted when the item has no URL —
635
+ * a project mapped to multiple repositories must not reconcile one repo's
636
+ * card against another repo's PR number.
637
+ */
638
+ function reconcilablePullRequestNumber(item, repository) {
639
+ if (item.externalSource?.type !== "pull-request") return void 0;
640
+ const url = item.externalSource.url;
641
+ if (url) {
642
+ const match = /^https?:\/\/[^/]+\/(.+)\/pull\/(\d+)(?:[/?#]|$)/.exec(url);
643
+ if (!match) return void 0;
644
+ return match[1] === repository.fullName ? Number(match[2]) : void 0;
645
+ }
646
+ const externalId = item.externalSource.externalId;
647
+ const legacy = /^github:(\d+):pull-request:(\d+)$/.exec(externalId);
648
+ if (legacy) return Number(legacy[1]) === repository.id ? Number(legacy[2]) : void 0;
649
+ const canonical = /^github-pr:(\d+)$/.exec(externalId);
650
+ return canonical ? Number(canonical[1]) : void 0;
651
+ }
652
+ /**
653
+ * Extracts the issue number a work item tracks, but only when the item
654
+ * belongs to the given repository. Stricter than
655
+ * {@link reconcilablePullRequestNumber}: a canonical key with no URL is only
656
+ * trusted when the intake-stamped `githubRepositoryId` confirms the
657
+ * repository, because the sweep initiates closes on its own.
658
+ */
659
+ function reconcilableIssueNumber(item, repository) {
660
+ if (item.externalSource?.type !== "issue") return void 0;
661
+ const url = item.externalSource.url;
662
+ if (url) {
663
+ const match = /^https?:\/\/[^/]+\/(.+)\/issues\/(\d+)(?:[/?#]|$)/.exec(url);
664
+ if (!match) return void 0;
665
+ return match[1] === repository.fullName || item.metadata?.githubRepositoryId === repository.id ? Number(match[2]) : void 0;
666
+ }
667
+ const externalId = item.externalSource.externalId;
668
+ const legacy = /^github:(\d+):issue:(\d+)$/.exec(externalId);
669
+ if (legacy) return Number(legacy[1]) === repository.id ? Number(legacy[2]) : void 0;
670
+ const canonical = /^github-issue:(\d+)$/.exec(externalId);
671
+ if (!canonical) return void 0;
672
+ return item.metadata?.githubRepositoryId === repository.id ? Number(canonical[1]) : void 0;
673
+ }
674
+ function reconciledIssueClosedEvent(repository, issueNumber, state) {
675
+ return {
676
+ event: "issues",
677
+ deliveryId: `reconcile:${repository.id}:issue:${issueNumber}:closed`,
678
+ payload: {
679
+ action: "closed",
680
+ installation: { id: repository.installationId },
681
+ repository: {
682
+ id: repository.id,
683
+ full_name: repository.fullName
684
+ },
685
+ sender: { login: state.author ?? "github" },
686
+ issue: {
687
+ number: issueNumber,
688
+ title: state.title,
689
+ html_url: state.url,
690
+ state: "closed",
691
+ ...state.stateReason ? { state_reason: state.stateReason } : {},
692
+ ...state.createdAt ? { created_at: state.createdAt } : {},
693
+ ...state.updatedAt ? { updated_at: state.updatedAt } : {},
694
+ assignees: githubUsers(state.assignees)
695
+ }
696
+ }
697
+ };
698
+ }
699
+ /**
700
+ * The label-drift replay: an open issue whose labels changed without a
701
+ * `labeled`/`unlabeled` webhook ever arriving (Factory was down, the delivery
702
+ * was lost, or the label was applied by something other than a delivery the
703
+ * webhook saw). Synthesized as an `opened` delivery so the deployment's
704
+ * `issueOpened` rule decides placement, exactly as it does at arrival — one
705
+ * source of placement policy for both.
706
+ */
707
+ function reconciledIssueRelabeledEvent(repository, issueNumber, state) {
708
+ const labels = state.labels ?? [];
709
+ const digest = createHash("sha256").update([...labels].sort().join("\n")).digest("hex").slice(0, 16);
710
+ const version = state.updatedAt ? `:${createHash("sha256").update(state.updatedAt).digest("hex").slice(0, 16)}` : "";
711
+ return {
712
+ event: "issues",
713
+ deliveryId: `reconcile:${repository.id}:issue:${issueNumber}:relabeled:${digest}${version}`,
714
+ payload: {
715
+ action: "opened",
716
+ installation: { id: repository.installationId },
717
+ repository: {
718
+ id: repository.id,
719
+ full_name: repository.fullName
720
+ },
721
+ sender: { login: state.author ?? "github" },
722
+ issue: {
723
+ number: issueNumber,
724
+ title: state.title,
725
+ html_url: state.url,
726
+ state: "open",
727
+ ...state.createdAt ? { created_at: state.createdAt } : {},
728
+ ...state.updatedAt ? { updated_at: state.updatedAt } : {},
729
+ assignees: githubUsers(state.assignees),
730
+ labels: githubLabels(labels)
731
+ }
732
+ }
733
+ };
734
+ }
735
+ /**
736
+ * The missed-open replay: an open issue with no Work card, because its
737
+ * `opened` delivery never reached the rules ingress. Synthesized as the same
738
+ * `opened` delivery so the deployment's `issueOpened` rule decides whether and
739
+ * where it lands, exactly as it would have at arrival. The delivery id is
740
+ * stable per issue so repeat sweeps dedupe at the ingress.
741
+ */
742
+ function reconciledIssueOpenedEvent(repository, issueNumber, state) {
743
+ return {
744
+ ...reconciledIssueRelabeledEvent(repository, issueNumber, state),
745
+ deliveryId: `reconcile:${repository.id}:issue:${issueNumber}:opened`
746
+ };
747
+ }
748
+ function polledPullRequestEvent(repository, pullRequestNumber, state) {
749
+ return {
750
+ event: "pull_request",
751
+ deliveryId: `poll:${repository.id}:pull-request:${pullRequestNumber}:${state.createdAt}`,
752
+ payload: {
753
+ action: "opened",
754
+ installation: { id: repository.installationId },
755
+ repository: {
756
+ id: repository.id,
757
+ full_name: repository.fullName
758
+ },
759
+ sender: { login: state.author ?? "__unknown__" },
760
+ pull_request: pullRequestPayload(pullRequestNumber, state)
761
+ }
762
+ };
763
+ }
764
+ function reconciledClosedEvent(repository, pullRequestNumber, state) {
765
+ const outcome = state.merged ? "merged" : "closed";
766
+ return {
767
+ event: "pull_request",
768
+ deliveryId: `reconcile:${repository.id}:pull-request:${pullRequestNumber}:${outcome}`,
769
+ payload: {
770
+ action: "closed",
771
+ installation: { id: repository.installationId },
772
+ repository: {
773
+ id: repository.id,
774
+ full_name: repository.fullName
775
+ },
776
+ sender: { login: state.mergedBy ?? "github" },
777
+ pull_request: pullRequestPayload(pullRequestNumber, {
778
+ ...state,
779
+ state: "closed"
780
+ })
781
+ }
782
+ };
783
+ }
784
+ function pullRequestPayload(pullRequestNumber, state) {
785
+ const payload = {
786
+ number: pullRequestNumber,
787
+ title: state.title,
788
+ html_url: state.url,
789
+ state: state.state,
790
+ draft: state.draft,
791
+ merged: state.merged,
792
+ assignees: githubUsers(state.assignees),
793
+ requested_reviewers: githubUsers(state.requestedReviewers),
794
+ labels: githubLabels(state.labels),
795
+ head: { ref: state.headBranch },
796
+ base: { ref: state.baseBranch }
797
+ };
798
+ if (state.createdAt) payload.created_at = state.createdAt;
799
+ if (state.author) payload.user = { login: state.author };
800
+ return payload;
801
+ }
802
+ function githubUsers(logins = []) {
803
+ return logins.map((login) => ({ login }));
804
+ }
805
+ function githubLabels(names = []) {
806
+ return names.map((name) => ({ name }));
807
+ }
808
+ function reconciledPullRequestMetadata(state, reconciliation, authorTrusted) {
809
+ return {
810
+ state: state.state,
811
+ draft: state.draft,
812
+ merged: state.merged,
813
+ ...state.author ? { author: state.author } : {},
814
+ ...state.assignees ? { assignees: state.assignees } : {},
815
+ ...state.requestedReviewers ? { requestedReviewers: state.requestedReviewers } : {},
816
+ ...state.labels ? { labels: state.labels } : {},
817
+ ...authorTrusted === void 0 ? {} : { authorTrusted },
818
+ [FACTORY_PULL_REQUEST_RECONCILIATION_KEY]: reconciliation === "settled" ? state.merged ? "merged" : "closed" : null
819
+ };
820
+ }
821
+ function reconciledPullRequestOutcome(metadata) {
822
+ if (metadata.state !== "closed" || typeof metadata.merged !== "boolean") return void 0;
823
+ return metadata.merged ? "merged" : "closed";
824
+ }
825
+ /**
826
+ * The webhook handler retires subscriptions itself; the sweep replays only the
827
+ * rules ingress, so without this the thread's PR chip and the workspace row
828
+ * stay `open` forever on a deployment GitHub cannot reach.
829
+ */
830
+ async function retireReconciledSubscriptions(storage, repository, pullRequestNumber, merged) {
831
+ const target = changeRequestTargetKey({
832
+ installationExternalId: String(repository.installationId),
833
+ repositoryExternalId: String(repository.id),
834
+ changeRequestId: String(pullRequestNumber)
835
+ });
836
+ const rows = await storage.subscriptions.listByTarget(target);
837
+ await Promise.all(rows.filter((row) => row.status === "open").map((row) => storage.subscriptions.updateStatus(row.id, merged ? "merged" : "closed")));
838
+ }
839
+ /**
840
+ * State-based safety net for merge signals: webhooks and event-log tailing
841
+ * can miss a merge (cursor gaps, downtime, terminally failed decisions), so
842
+ * this sweep compares still-open PR cards against actual GitHub state and
843
+ * replays the merge through the normal rules ingress when they disagree.
844
+ */
845
+ function createGithubPullRequestReconciler(options, fetchPullRequest) {
846
+ const rules = new GithubRules(options);
847
+ return async (repositories) => {
848
+ const summary = {
849
+ repositories: 0,
850
+ checked: 0,
851
+ merged: 0,
852
+ closed: 0,
853
+ failed: 0,
854
+ errors: []
855
+ };
856
+ const recordFailure = (repository, error, pullRequestNumber) => {
857
+ summary.failed += 1;
858
+ if (summary.errors.length < 5) summary.errors.push({
859
+ repository: repository.fullName,
860
+ ...pullRequestNumber === void 0 ? {} : { pullRequestNumber },
861
+ error: error instanceof Error ? error.message : String(error)
862
+ });
863
+ };
864
+ const configured = new Set((await options.sourceControl.projectRepositories.listConfiguredExternalKeys()).map((key) => `${key.installationExternalId}\u0000${key.repositoryExternalId}`));
865
+ const scoped = repositories.filter((repository) => configured.has(`${repository.installationId}\u0000${repository.id}`));
866
+ summary.repositories = scoped.length;
867
+ for (const repository of scoped) {
868
+ let cardsByNumber;
869
+ let unanswered;
870
+ try {
871
+ const projects = await options.sourceControl.projectRepositories.listByExternalRepository({
872
+ installationExternalId: String(repository.installationId),
873
+ repositoryExternalId: String(repository.id)
874
+ });
875
+ if (projects.length === 0) continue;
876
+ cardsByNumber = /* @__PURE__ */ new Map();
877
+ unanswered = [];
878
+ for (const project of projects) {
879
+ const items = await options.storage.list({
880
+ orgId: project.orgId,
881
+ factoryProjectId: project.factoryProjectId
882
+ });
883
+ for (const item of items) {
884
+ const unansweredAuthor = authorAwaitingTrust(item, repository);
885
+ if (unansweredAuthor) unanswered.push({
886
+ item,
887
+ author: unansweredAuthor
888
+ });
889
+ const pullRequestNumber = reconcilablePullRequestNumber(item, repository);
890
+ if (!pullRequestNumber) continue;
891
+ const metadata = item.metadata ?? {};
892
+ const reconciliation = metadata[FACTORY_PULL_REQUEST_RECONCILIATION_KEY];
893
+ const reconciledOutcome = reconciledPullRequestOutcome(metadata);
894
+ if (workItemPhaseSemantics(options.boards, item)?.kind === "terminal" && reconciledOutcome !== void 0 && reconciliation === reconciledOutcome) continue;
895
+ const cards = cardsByNumber.get(pullRequestNumber) ?? [];
896
+ cards.push(item);
897
+ cardsByNumber.set(pullRequestNumber, cards);
898
+ }
899
+ }
900
+ } catch (error) {
901
+ recordFailure(repository, error);
902
+ continue;
903
+ }
904
+ const authorTrust = sweepTrustLookup(options.github, repository);
905
+ for (const { item, author } of unanswered) try {
906
+ await options.storage.update({
907
+ orgId: item.orgId,
908
+ id: item.id,
909
+ userId: "factory-rule-dispatcher",
910
+ patch: { metadata: { authorTrusted: await authorTrust(author) } }
911
+ });
912
+ } catch (error) {
913
+ recordFailure(repository, error);
914
+ }
915
+ for (const [pullRequestNumber, cards] of cardsByNumber) try {
916
+ const state = await fetchPullRequest({
917
+ installationId: repository.installationId,
918
+ repository: repository.fullName,
919
+ number: pullRequestNumber
920
+ });
921
+ summary.checked += 1;
922
+ if (!state) continue;
923
+ let authorTrusted;
924
+ if (state.author !== void 0) try {
925
+ authorTrusted = await authorTrust(state.author);
926
+ } catch (error) {
927
+ recordFailure(repository, error, pullRequestNumber);
928
+ }
929
+ for (const card of cards) {
930
+ if (state.state === "closed") continue;
931
+ const metadata = card.metadata ?? {};
932
+ const statusChanged = metadata.state !== state.state || metadata.draft !== state.draft || metadata.merged !== state.merged;
933
+ const authorChanged = state.author !== void 0 && metadata.author !== state.author;
934
+ const assigneesChanged = !sameStrings(metadata.assignees, state.assignees);
935
+ const reviewersChanged = !sameStrings(metadata.requestedReviewers, state.requestedReviewers);
936
+ const labelsChanged = !sameStrings(metadata.labels, state.labels);
937
+ const trustStale = authorTrusted !== void 0 && metadata.authorTrusted !== authorTrusted;
938
+ const metadataChanged = statusChanged || authorChanged || assigneesChanged || reviewersChanged || labelsChanged || trustStale;
939
+ const reconciliation = metadata[FACTORY_PULL_REQUEST_RECONCILIATION_KEY];
940
+ if (!metadataChanged && reconciliation !== "merged" && reconciliation !== "closed") continue;
941
+ try {
942
+ await options.storage.update({
943
+ orgId: card.orgId,
944
+ id: card.id,
945
+ userId: "factory-rule-dispatcher",
946
+ patch: { metadata: reconciledPullRequestMetadata(state, "clear", trustStale ? authorTrusted : void 0) }
947
+ });
948
+ } catch (error) {
949
+ recordFailure(repository, error, pullRequestNumber);
950
+ }
951
+ }
952
+ if (state.state !== "closed") continue;
953
+ const cleanupFailures = /* @__PURE__ */ new Set();
954
+ for (const card of cards) {
955
+ if (workItemPhaseSemantics(options.boards, card)?.kind !== "terminal") continue;
956
+ try {
957
+ await options.storage.supersedeDecisionsForWorkItem({
958
+ orgId: card.orgId,
959
+ factoryProjectId: card.factoryProjectId,
960
+ workItemId: card.id,
961
+ supersededAt: /* @__PURE__ */ new Date()
962
+ });
963
+ } catch (error) {
964
+ recordFailure(repository, error, pullRequestNumber);
965
+ cleanupFailures.add(card.id);
966
+ }
967
+ }
968
+ await rules.ingest(reconciledClosedEvent(repository, pullRequestNumber, state));
969
+ await retireReconciledSubscriptions(options.integrationStorage, repository, pullRequestNumber, state.merged);
970
+ for (const card of cards) {
971
+ if (cleanupFailures.has(card.id)) continue;
972
+ const trustStale = authorTrusted !== void 0 && (card.metadata ?? {}).authorTrusted !== authorTrusted;
973
+ try {
974
+ await options.storage.update({
975
+ orgId: card.orgId,
976
+ id: card.id,
977
+ userId: "factory-rule-dispatcher",
978
+ patch: { metadata: reconciledPullRequestMetadata(state, "settled", trustStale ? authorTrusted : void 0) }
979
+ });
980
+ } catch (error) {
981
+ recordFailure(repository, error, pullRequestNumber);
982
+ }
983
+ }
984
+ if (state.merged) summary.merged += 1;
985
+ else summary.closed += 1;
986
+ } catch (error) {
987
+ recordFailure(repository, error, pullRequestNumber);
988
+ }
989
+ }
990
+ return summary;
991
+ };
992
+ }
993
+ function githubRulesOptions(github, context) {
994
+ if (!context.runtime) return void 0;
995
+ return {
996
+ github,
997
+ sourceControl: context.storage.sourceControl,
998
+ integrationStorage: context.storage.generic,
999
+ projects: context.storage.projects,
1000
+ storage: context.runtime.workItems,
1001
+ configVersion: context.runtime.configVersion,
1002
+ boards: context.runtime.boards,
1003
+ intake: context.storage.intake,
1004
+ ...context.hooks?.onRepositoryPush ? { onRepositoryPush: context.hooks.onRepositoryPush } : {}
1005
+ };
1006
+ }
1007
+ function attachGithubRules(github, context) {
1008
+ const options = githubRulesOptions(github, context);
1009
+ if (!options) return void 0;
1010
+ const rules = new GithubRules(options);
1011
+ return (event) => rules.ingest(event);
1012
+ }
1013
+ function attachGithubReconciler(github, context, fetchPullRequest) {
1014
+ const options = githubRulesOptions(github, context);
1015
+ if (!options) return void 0;
1016
+ return createGithubPullRequestReconciler(options, fetchPullRequest);
1017
+ }
1018
+ //#endregion
1019
+ export { GithubRules, RECONCILE_ERROR_SAMPLE_LIMIT, attachGithubReconciler, attachGithubRules, cardBelongsToRepository, createGithubPullRequestReconciler, githubRulesOptions, isFactoryGithubLogin, polledPullRequestEvent, reconcilableIssueNumber, reconciledClosedEvent, reconciledIssueClosedEvent, reconciledIssueOpenedEvent, reconciledIssueRelabeledEvent, sameStrings, sweepTrustLookup, trustedCollaborator };
1020
+
1021
+ //# sourceMappingURL=rules.js.map