@mastra/factory 0.28.0-alpha.2 → 0.28.0-alpha.3

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 (399) hide show
  1. package/README.md +244 -123
  2. package/dist/boards/board-events.d.ts +23 -3
  3. package/dist/boards/board-events.d.ts.map +1 -1
  4. package/dist/boards/board-events.js +44 -7
  5. package/dist/boards/board-events.js.map +1 -1
  6. package/dist/boards/board-writes.d.ts +1 -1
  7. package/dist/boards/board-writes.d.ts.map +1 -1
  8. package/dist/boards/board-writes.js +16 -1
  9. package/dist/boards/board-writes.js.map +1 -1
  10. package/dist/boards/card-facts.d.ts +1 -1
  11. package/dist/boards/card-facts.d.ts.map +1 -1
  12. package/dist/boards/card-facts.js +4 -0
  13. package/dist/boards/card-facts.js.map +1 -1
  14. package/dist/boards/default-board.d.ts +7 -0
  15. package/dist/boards/default-board.d.ts.map +1 -0
  16. package/dist/boards/default-board.js +10 -0
  17. package/dist/boards/default-board.js.map +1 -0
  18. package/dist/boards/define-board.d.ts +39 -17
  19. package/dist/boards/define-board.d.ts.map +1 -1
  20. package/dist/boards/define-board.js +64 -42
  21. package/dist/boards/define-board.js.map +1 -1
  22. package/dist/boards/index.d.ts +5 -8
  23. package/dist/boards/index.d.ts.map +1 -1
  24. package/dist/boards/index.js +5 -19
  25. package/dist/boards/intake-routing.d.ts +27 -5
  26. package/dist/boards/intake-routing.d.ts.map +1 -1
  27. package/dist/boards/intake-routing.js +69 -16
  28. package/dist/boards/intake-routing.js.map +1 -1
  29. package/dist/boards/legacy-plan-role.d.ts.map +1 -1
  30. package/dist/boards/legacy-plan-role.js +7 -2
  31. package/dist/boards/legacy-plan-role.js.map +1 -1
  32. package/dist/boards/phase-automation.d.ts +7 -0
  33. package/dist/boards/phase-automation.d.ts.map +1 -1
  34. package/dist/boards/phase-automation.js +16 -5
  35. package/dist/boards/phase-automation.js.map +1 -1
  36. package/dist/boards/phase-runner.d.ts +18 -10
  37. package/dist/boards/phase-runner.d.ts.map +1 -1
  38. package/dist/boards/phase-runner.js +39 -34
  39. package/dist/boards/phase-runner.js.map +1 -1
  40. package/dist/boards/project-boards.d.ts +9 -6
  41. package/dist/boards/project-boards.d.ts.map +1 -1
  42. package/dist/boards/project-boards.js +56 -18
  43. package/dist/boards/project-boards.js.map +1 -1
  44. package/dist/boards/registry.d.ts.map +1 -1
  45. package/dist/boards/registry.js +3 -1
  46. package/dist/boards/registry.js.map +1 -1
  47. package/dist/boards/relocate.d.ts +1 -1
  48. package/dist/boards/relocate.d.ts.map +1 -1
  49. package/dist/boards/relocate.js +3 -2
  50. package/dist/boards/relocate.js.map +1 -1
  51. package/dist/boards/review.d.ts +5 -2
  52. package/dist/boards/review.d.ts.map +1 -1
  53. package/dist/boards/review.js +12 -11
  54. package/dist/boards/review.js.map +1 -1
  55. package/dist/boards/semantics.d.ts +159 -20
  56. package/dist/boards/semantics.d.ts.map +1 -1
  57. package/dist/boards/semantics.js +256 -23
  58. package/dist/boards/semantics.js.map +1 -1
  59. package/dist/boards/stored-board.d.ts +32 -18
  60. package/dist/boards/stored-board.d.ts.map +1 -1
  61. package/dist/boards/stored-board.js +31 -97
  62. package/dist/boards/stored-board.js.map +1 -1
  63. package/dist/boards/work-migrations.d.ts +19 -0
  64. package/dist/boards/work-migrations.d.ts.map +1 -0
  65. package/dist/boards/work-migrations.js +257 -0
  66. package/dist/boards/work-migrations.js.map +1 -0
  67. package/dist/boards/work-routes.d.ts +53 -0
  68. package/dist/boards/work-routes.d.ts.map +1 -0
  69. package/dist/boards/work-routes.js +256 -0
  70. package/dist/boards/work-routes.js.map +1 -0
  71. package/dist/boards/work.d.ts +8 -19
  72. package/dist/boards/work.d.ts.map +1 -1
  73. package/dist/boards/work.js +38 -270
  74. package/dist/boards/work.js.map +1 -1
  75. package/dist/factory.d.ts +3 -3
  76. package/dist/factory.d.ts.map +1 -1
  77. package/dist/factory.js +58 -30
  78. package/dist/factory.js.map +1 -1
  79. package/dist/index.d.ts +2 -2
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +2 -3
  82. package/dist/integrations/base.d.ts +6 -2
  83. package/dist/integrations/base.d.ts.map +1 -1
  84. package/dist/integrations/closing-references.d.ts +15 -0
  85. package/dist/integrations/closing-references.d.ts.map +1 -0
  86. package/dist/integrations/closing-references.js +69 -0
  87. package/dist/integrations/closing-references.js.map +1 -0
  88. package/dist/integrations/github/default-rules.d.ts +15 -66
  89. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  90. package/dist/integrations/github/default-rules.js +129 -71
  91. package/dist/integrations/github/default-rules.js.map +1 -1
  92. package/dist/integrations/github/issue-reconciler.d.ts.map +1 -1
  93. package/dist/integrations/github/issue-reconciler.js +3 -1
  94. package/dist/integrations/github/issue-reconciler.js.map +1 -1
  95. package/dist/integrations/github/pull-request-source.d.ts +8 -0
  96. package/dist/integrations/github/pull-request-source.d.ts.map +1 -0
  97. package/dist/integrations/github/pull-request-source.js +17 -0
  98. package/dist/integrations/github/pull-request-source.js.map +1 -0
  99. package/dist/integrations/github/review-status-reporter.d.ts.map +1 -1
  100. package/dist/integrations/github/review-status-reporter.js +7 -3
  101. package/dist/integrations/github/review-status-reporter.js.map +1 -1
  102. package/dist/integrations/github/routes.js +1 -1
  103. package/dist/integrations/github/rules.d.ts +13 -2
  104. package/dist/integrations/github/rules.d.ts.map +1 -1
  105. package/dist/integrations/github/rules.js +202 -34
  106. package/dist/integrations/github/rules.js.map +1 -1
  107. package/dist/integrations/github/session-subscriptions.js +2 -2
  108. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  109. package/dist/integrations/github/token-refresh.d.ts +2 -1
  110. package/dist/integrations/github/token-refresh.d.ts.map +1 -1
  111. package/dist/integrations/github/token-refresh.js.map +1 -1
  112. package/dist/integrations/gitlab/agent-tools.js +1 -1
  113. package/dist/integrations/gitlab/default-rules.d.ts +73 -31
  114. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  115. package/dist/integrations/gitlab/default-rules.js +106 -43
  116. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  117. package/dist/integrations/gitlab/issue-reconciler.d.ts.map +1 -1
  118. package/dist/integrations/gitlab/issue-reconciler.js +2 -1
  119. package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
  120. package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
  121. package/dist/integrations/gitlab/merge-request-reconciler.js +11 -4
  122. package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
  123. package/dist/integrations/gitlab/rules.d.ts +6 -1
  124. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  125. package/dist/integrations/gitlab/rules.js +116 -23
  126. package/dist/integrations/gitlab/rules.js.map +1 -1
  127. package/dist/integrations/gitlab/session-subscriptions.js +1 -1
  128. package/dist/integrations/incidentio/agent-tools.js +1 -1
  129. package/dist/integrations/incidentio/default-rules.js +3 -3
  130. package/dist/integrations/incidentio/default-rules.js.map +1 -1
  131. package/dist/integrations/incidentio/issue-reconciler.d.ts.map +1 -1
  132. package/dist/integrations/incidentio/issue-reconciler.js +2 -1
  133. package/dist/integrations/incidentio/issue-reconciler.js.map +1 -1
  134. package/dist/integrations/incidentio/rules.d.ts +3 -1
  135. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  136. package/dist/integrations/incidentio/rules.js +14 -11
  137. package/dist/integrations/incidentio/rules.js.map +1 -1
  138. package/dist/integrations/jira/agent-tools.js +1 -1
  139. package/dist/integrations/jira/default-rules.js +3 -3
  140. package/dist/integrations/jira/default-rules.js.map +1 -1
  141. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
  142. package/dist/integrations/jira/issue-reconciler.js +2 -1
  143. package/dist/integrations/jira/issue-reconciler.js.map +1 -1
  144. package/dist/integrations/jira/rules.d.ts +3 -1
  145. package/dist/integrations/jira/rules.d.ts.map +1 -1
  146. package/dist/integrations/jira/rules.js +14 -11
  147. package/dist/integrations/jira/rules.js.map +1 -1
  148. package/dist/integrations/linear/agent-tools.d.ts +9 -1
  149. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  150. package/dist/integrations/linear/agent-tools.js +80 -2
  151. package/dist/integrations/linear/agent-tools.js.map +1 -1
  152. package/dist/integrations/linear/default-rules.js +3 -3
  153. package/dist/integrations/linear/default-rules.js.map +1 -1
  154. package/dist/integrations/linear/integration.d.ts +4 -1
  155. package/dist/integrations/linear/integration.d.ts.map +1 -1
  156. package/dist/integrations/linear/integration.js +21 -1
  157. package/dist/integrations/linear/integration.js.map +1 -1
  158. package/dist/integrations/linear/issue-reconciler.d.ts.map +1 -1
  159. package/dist/integrations/linear/issue-reconciler.js +2 -1
  160. package/dist/integrations/linear/issue-reconciler.js.map +1 -1
  161. package/dist/integrations/linear/routes.d.ts +2 -1
  162. package/dist/integrations/linear/routes.d.ts.map +1 -1
  163. package/dist/integrations/linear/routes.js +4 -3
  164. package/dist/integrations/linear/routes.js.map +1 -1
  165. package/dist/integrations/linear/rules.d.ts +3 -1
  166. package/dist/integrations/linear/rules.d.ts.map +1 -1
  167. package/dist/integrations/linear/rules.js +15 -12
  168. package/dist/integrations/linear/rules.js.map +1 -1
  169. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  170. package/dist/integrations/platform/github/integration.js +33 -21
  171. package/dist/integrations/platform/github/integration.js.map +1 -1
  172. package/dist/integrations/platform/jira/agent-tools.js +1 -1
  173. package/dist/integrations/platform/linear/integration.d.ts +1 -1
  174. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  175. package/dist/integrations/platform/linear/integration.js +6 -5
  176. package/dist/integrations/platform/linear/integration.js.map +1 -1
  177. package/dist/integrations/slack/chat-tools.js +1 -1
  178. package/dist/integrations/slack/reply-tool.js +1 -1
  179. package/dist/integrations/slack/share-file-tool.js +1 -1
  180. package/dist/integrations/slack/slack.d.ts +10 -4
  181. package/dist/integrations/slack/slack.d.ts.map +1 -1
  182. package/dist/integrations/slack/slack.js +19 -9
  183. package/dist/integrations/slack/slack.js.map +1 -1
  184. package/dist/links.d.ts.map +1 -1
  185. package/dist/links.js +3 -2
  186. package/dist/links.js.map +1 -1
  187. package/dist/mcp/routes.js +2 -2
  188. package/dist/routes/attention-parked.d.ts +1 -0
  189. package/dist/routes/attention-parked.d.ts.map +1 -1
  190. package/dist/routes/attention-parked.js +1 -1
  191. package/dist/routes/attention-parked.js.map +1 -1
  192. package/dist/routes/automation-runs.d.ts +4 -0
  193. package/dist/routes/automation-runs.d.ts.map +1 -1
  194. package/dist/routes/automation-runs.js +15 -0
  195. package/dist/routes/automation-runs.js.map +1 -1
  196. package/dist/routes/boards.d.ts +1 -1
  197. package/dist/routes/boards.d.ts.map +1 -1
  198. package/dist/routes/boards.js +1 -17
  199. package/dist/routes/boards.js.map +1 -1
  200. package/dist/routes/config.d.ts +4 -0
  201. package/dist/routes/config.d.ts.map +1 -1
  202. package/dist/routes/config.js +15 -0
  203. package/dist/routes/config.js.map +1 -1
  204. package/dist/routes/contracts.d.ts +125 -14
  205. package/dist/routes/contracts.d.ts.map +1 -1
  206. package/dist/routes/contracts.js +34 -15
  207. package/dist/routes/contracts.js.map +1 -1
  208. package/dist/routes/fs.d.ts +4 -0
  209. package/dist/routes/fs.d.ts.map +1 -1
  210. package/dist/routes/fs.js +8 -4
  211. package/dist/routes/fs.js.map +1 -1
  212. package/dist/routes/intake-routes.d.ts.map +1 -1
  213. package/dist/routes/intake-routes.js.map +1 -1
  214. package/dist/routes/intake.d.ts.map +1 -1
  215. package/dist/routes/intake.js +1 -0
  216. package/dist/routes/intake.js.map +1 -1
  217. package/dist/routes/projects.d.ts.map +1 -1
  218. package/dist/routes/projects.js +8 -2
  219. package/dist/routes/projects.js.map +1 -1
  220. package/dist/routes/provider-credentials.d.ts.map +1 -1
  221. package/dist/routes/provider-credentials.js +10 -5
  222. package/dist/routes/provider-credentials.js.map +1 -1
  223. package/dist/routes/running-packages.d.ts +13 -0
  224. package/dist/routes/running-packages.d.ts.map +1 -0
  225. package/dist/routes/running-packages.js +45 -0
  226. package/dist/routes/running-packages.js.map +1 -0
  227. package/dist/routes/surface.d.ts +10 -1
  228. package/dist/routes/surface.d.ts.map +1 -1
  229. package/dist/routes/surface.js +104 -35
  230. package/dist/routes/surface.js.map +1 -1
  231. package/dist/routes/work-items.d.ts.map +1 -1
  232. package/dist/routes/work-items.js +23 -3
  233. package/dist/routes/work-items.js.map +1 -1
  234. package/dist/rules/binding-context.d.ts.map +1 -1
  235. package/dist/rules/binding-context.js +1 -0
  236. package/dist/rules/binding-context.js.map +1 -1
  237. package/dist/rules/dispatcher.d.ts +0 -1
  238. package/dist/rules/dispatcher.d.ts.map +1 -1
  239. package/dist/rules/dispatcher.js +340 -42
  240. package/dist/rules/dispatcher.js.map +1 -1
  241. package/dist/rules/event-rules.d.ts +33 -2
  242. package/dist/rules/event-rules.d.ts.map +1 -1
  243. package/dist/rules/event-rules.js +46 -11
  244. package/dist/rules/event-rules.js.map +1 -1
  245. package/dist/rules/index.d.ts +2 -4
  246. package/dist/rules/index.d.ts.map +1 -1
  247. package/dist/rules/index.js +2 -3
  248. package/dist/rules/phase-goal.d.ts +54 -0
  249. package/dist/rules/phase-goal.d.ts.map +1 -0
  250. package/dist/rules/phase-goal.js +70 -0
  251. package/dist/rules/phase-goal.js.map +1 -0
  252. package/dist/rules/phase-tools.d.ts +11 -0
  253. package/dist/rules/phase-tools.d.ts.map +1 -0
  254. package/dist/rules/phase-tools.js +19 -0
  255. package/dist/rules/phase-tools.js.map +1 -0
  256. package/dist/rules/processor.d.ts.map +1 -1
  257. package/dist/rules/processor.js +112 -11
  258. package/dist/rules/processor.js.map +1 -1
  259. package/dist/rules/review-source-tool.d.ts +4 -1
  260. package/dist/rules/review-source-tool.d.ts.map +1 -1
  261. package/dist/rules/review-source-tool.js +24 -4
  262. package/dist/rules/review-source-tool.js.map +1 -1
  263. package/dist/rules/rule-group.d.ts +1 -1
  264. package/dist/rules/rule-group.d.ts.map +1 -1
  265. package/dist/rules/rule-group.js +2 -1
  266. package/dist/rules/rule-group.js.map +1 -1
  267. package/dist/rules/start-coordinator.d.ts +5 -1
  268. package/dist/rules/start-coordinator.d.ts.map +1 -1
  269. package/dist/rules/start-coordinator.js +9 -3
  270. package/dist/rules/start-coordinator.js.map +1 -1
  271. package/dist/rules/tools.d.ts.map +1 -1
  272. package/dist/rules/tools.js +39 -28
  273. package/dist/rules/tools.js.map +1 -1
  274. package/dist/rules/transition-service.d.ts +2 -7
  275. package/dist/rules/transition-service.d.ts.map +1 -1
  276. package/dist/rules/transition-service.js +61 -54
  277. package/dist/rules/transition-service.js.map +1 -1
  278. package/dist/rules/types.d.ts +83 -29
  279. package/dist/rules/types.d.ts.map +1 -1
  280. package/dist/rules/types.js +5 -41
  281. package/dist/rules/types.js.map +1 -1
  282. package/dist/rules/validation.d.ts.map +1 -1
  283. package/dist/rules/validation.js +32 -2
  284. package/dist/rules/validation.js.map +1 -1
  285. package/dist/secret-encryption.d.ts +21 -0
  286. package/dist/secret-encryption.d.ts.map +1 -1
  287. package/dist/secret-encryption.js +31 -4
  288. package/dist/secret-encryption.js.map +1 -1
  289. package/dist/session/self-review-gate.d.ts +6 -2
  290. package/dist/session/self-review-gate.d.ts.map +1 -1
  291. package/dist/session/self-review-gate.js +8 -4
  292. package/dist/session/self-review-gate.js.map +1 -1
  293. package/dist/session/session-threads.d.ts +2 -3
  294. package/dist/session/session-threads.d.ts.map +1 -1
  295. package/dist/session/session-threads.js.map +1 -1
  296. package/dist/session/source-control-tools.js +1 -1
  297. package/dist/session/work-item-state-processor.d.ts +27 -0
  298. package/dist/session/work-item-state-processor.d.ts.map +1 -0
  299. package/dist/session/work-item-state-processor.js +288 -0
  300. package/dist/session/work-item-state-processor.js.map +1 -0
  301. package/dist/storage/domains/boards/base.d.ts +44 -27
  302. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  303. package/dist/storage/domains/boards/base.js +76 -121
  304. package/dist/storage/domains/boards/base.js.map +1 -1
  305. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  306. package/dist/storage/domains/boards/schemas.js +12 -0
  307. package/dist/storage/domains/boards/schemas.js.map +1 -1
  308. package/dist/storage/domains/work-items/base.d.ts +32 -2
  309. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  310. package/dist/storage/domains/work-items/base.js +109 -26
  311. package/dist/storage/domains/work-items/base.js.map +1 -1
  312. package/dist/storage/domains/work-items/cards.d.ts +24 -2
  313. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  314. package/dist/storage/domains/work-items/cards.js +118 -8
  315. package/dist/storage/domains/work-items/cards.js.map +1 -1
  316. package/dist/storage/domains/work-items/legacy-review.d.ts +63 -0
  317. package/dist/storage/domains/work-items/legacy-review.d.ts.map +1 -0
  318. package/dist/storage/domains/work-items/legacy-review.js +95 -0
  319. package/dist/storage/domains/work-items/legacy-review.js.map +1 -0
  320. package/dist/storage/domains/work-items/metrics.d.ts +12 -4
  321. package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
  322. package/dist/storage/domains/work-items/metrics.js +14 -32
  323. package/dist/storage/domains/work-items/metrics.js.map +1 -1
  324. package/dist/storage/domains/work-items/work-item-schema.d.ts +2 -0
  325. package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
  326. package/dist/storage/domains/work-items/work-item-schema.js +5 -0
  327. package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
  328. package/dist/tools/approval-tools.d.ts.map +1 -1
  329. package/dist/tools/approval-tools.js +28 -9
  330. package/dist/tools/approval-tools.js.map +1 -1
  331. package/dist/tools/index.d.ts +1 -1
  332. package/dist/tools/index.js +1 -1
  333. package/dist/tools/index.js.map +1 -1
  334. package/dist/tools/messaging-tools.d.ts +3 -0
  335. package/dist/tools/messaging-tools.d.ts.map +1 -1
  336. package/dist/tools/messaging-tools.js +2 -1
  337. package/dist/tools/messaging-tools.js.map +1 -1
  338. package/dist/tools/read-tools.d.ts +8 -2
  339. package/dist/tools/read-tools.d.ts.map +1 -1
  340. package/dist/tools/read-tools.js +83 -23
  341. package/dist/tools/read-tools.js.map +1 -1
  342. package/dist/tools/reports.d.ts +1 -0
  343. package/dist/tools/reports.d.ts.map +1 -1
  344. package/dist/tools/reports.js +2 -1
  345. package/dist/tools/reports.js.map +1 -1
  346. package/dist/tools/run-watch.d.ts +1 -1
  347. package/dist/tools/run-watch.d.ts.map +1 -1
  348. package/dist/tools/run-watch.js +1 -0
  349. package/dist/tools/run-watch.js.map +1 -1
  350. package/dist/tools/sandbox-tools.js +1 -1
  351. package/dist/tools/session-tools.js +1 -1
  352. package/dist/tools/sessions-state-processor.d.ts +2 -0
  353. package/dist/tools/sessions-state-processor.d.ts.map +1 -1
  354. package/dist/tools/sessions-state-processor.js +4 -2
  355. package/dist/tools/sessions-state-processor.js.map +1 -1
  356. package/dist/tools/side-sessions.d.ts +2 -0
  357. package/dist/tools/side-sessions.d.ts.map +1 -1
  358. package/dist/tools/side-sessions.js +2 -1
  359. package/dist/tools/side-sessions.js.map +1 -1
  360. package/dist/tools/work-item-tools.js +3 -3
  361. package/dist/tools/work-item-tools.js.map +1 -1
  362. package/dist/work-item-branch.d.ts +13 -0
  363. package/dist/work-item-branch.d.ts.map +1 -1
  364. package/dist/work-item-branch.js +16 -1
  365. package/dist/work-item-branch.js.map +1 -1
  366. package/dist/work-items/create-work-item.d.ts +6 -0
  367. package/dist/work-items/create-work-item.d.ts.map +1 -1
  368. package/dist/work-items/create-work-item.js +25 -1
  369. package/dist/work-items/create-work-item.js.map +1 -1
  370. package/dist/work-items/split-migration.d.ts.map +1 -1
  371. package/dist/work-items/split-migration.js +1 -0
  372. package/dist/work-items/split-migration.js.map +1 -1
  373. package/dist/workspace.d.ts.map +1 -1
  374. package/dist/workspace.js +53 -10
  375. package/dist/workspace.js.map +1 -1
  376. package/factory-skills/configure-factory-rules/SKILL.md +11 -9
  377. package/factory-skills/factory-build/SKILL.md +64 -0
  378. package/factory-skills/factory-gitlab-rereview/SKILL.md +1 -1
  379. package/factory-skills/factory-gitlab-review/SKILL.md +2 -2
  380. package/factory-skills/factory-plan/SKILL.md +8 -10
  381. package/factory-skills/factory-rereview/SKILL.md +3 -3
  382. package/factory-skills/factory-review/SKILL.md +14 -4
  383. package/factory-skills/factory-self-review/SKILL.md +31 -11
  384. package/factory-skills/factory-triage/SKILL.md +25 -10
  385. package/package.json +10 -10
  386. package/dist/boards/index.js.map +0 -1
  387. package/dist/boards/pull-request-review.d.ts +0 -14
  388. package/dist/boards/pull-request-review.d.ts.map +0 -1
  389. package/dist/boards/pull-request-review.js +0 -81
  390. package/dist/boards/pull-request-review.js.map +0 -1
  391. package/dist/boards/work-tool-rules.d.ts +0 -8
  392. package/dist/boards/work-tool-rules.d.ts.map +0 -1
  393. package/dist/boards/work-tool-rules.js +0 -19
  394. package/dist/boards/work-tool-rules.js.map +0 -1
  395. package/dist/rules/resolve.d.ts +0 -15
  396. package/dist/rules/resolve.d.ts.map +0 -1
  397. package/dist/rules/resolve.js +0 -22
  398. package/dist/rules/resolve.js.map +0 -1
  399. package/factory-skills/factory-complete-issue/SKILL.md +0 -24
@@ -1,8 +1,8 @@
1
1
  import "../../boards/index.js";
2
- import { isPullRequestCard, pullRequestReviewPhase, reviewsPullRequest } from "../../boards/semantics.js";
3
- import { hasRecordedVerdict } from "../../boards/pull-request-review.js";
2
+ import { hasRecordedVerdict, isPullRequestCard, newestOpenPullRequestNumber, pullRequestSources, reviewedPullRequest, reviewsPullRequest } from "../../boards/semantics.js";
4
3
  import { requestsChangesVerdict } from "../../review-verdict.js";
5
- import { closedByRoutes, recordExplicitRuleOverrides } from "../../rules/event-rules.js";
4
+ import { closedByRoutes, pullRequestMoveByRoutes, recordExplicitRuleOverrides, routedOnly, unreviewedPullRequestCard } from "../../rules/event-rules.js";
5
+ import { isRepositoryPullRequest } from "./pull-request-source.js";
6
6
  import { isFactoryApproveVerdict } from "./stale-reviews.js";
7
7
  // src/integrations/github/default-rules.ts
8
8
  function trustedGithubActor(context) {
@@ -11,16 +11,41 @@ function trustedGithubActor(context) {
11
11
  function githubActorLogin(context) {
12
12
  return context.actor.type === "github" ? context.actor.login : void 0;
13
13
  }
14
- /** The Work card whose session authored the pull request, as opposed to the PR's own card. */
14
+ /**
15
+ * The card whose session authored the pull request, as opposed to the PR's own card, on a board
16
+ * that reviews pull requests.
17
+ */
15
18
  function authoringCard(context) {
16
- return context.board === "work" && context.item !== void 0 && !isPullRequestCard(context.item);
19
+ return context.flow?.pullRequestReview !== void 0 && context.item !== void 0 && !isPullRequestCard(context.item);
20
+ }
21
+ /** Whether the card sits in `selfReview` with an approve verdict on the head its pull request opened with. */
22
+ function selfReviewApprovedHead(context, selfReview) {
23
+ const { item, pullRequest } = context;
24
+ const metadata = item?.metadata;
25
+ const approvedHead = metadata?.selfReviewedHeadSha;
26
+ return item?.stages.length === 1 && item.stages[0] === selfReview && metadata?.selfReviewVerdict === "approve" && typeof approvedHead === "string" && pullRequest?.headSha !== void 0 && approvedHead.toLowerCase() === pullRequest.headSha;
27
+ }
28
+ /** Whether the card sits in its board's pull request review phase, alone. */
29
+ function inPullRequestReview(context) {
30
+ const phase = context.flow?.pullRequestReview;
31
+ return phase !== void 0 && context.item?.stages.length === 1 && context.item.stages[0] === phase;
32
+ }
33
+ /** Whether the rule's card carries the event's pull request as one of its sources, attached to its issue. */
34
+ function attachedPullRequest(context) {
35
+ const { item, pullRequest } = context;
36
+ if (!item || !pullRequest || isPullRequestCard(item)) return false;
37
+ return pullRequestSources(item).some((source) => isEventPullRequest(context, source));
17
38
  }
18
- /** The board holding the PR's own card: Work for new cards, Review for cards filed before PRs moved to Work. */
19
- function pullRequestCardBoard(context) {
20
- return context.board === "review" ? "review" : "work";
39
+ /** Whether a source row is the event's pull request: the same number in the same repository. */
40
+ function isEventPullRequest(context, source) {
41
+ return context.pullRequest !== void 0 && isRepositoryPullRequest(source, context.repository.id, context.repository.fullName, context.pullRequest.number);
21
42
  }
22
- function pullRequestCardNoun(context) {
23
- return context.board === "review" ? "Review card" : "pull request card";
43
+ /** Whether the card's PR review covers the event's pull request: its own, or the attached one it reviews. */
44
+ function reviewsThisPullRequest(context) {
45
+ if (!context.item || !context.pullRequest || !reviewsPullRequest(context)) return false;
46
+ if (isPullRequestCard(context.item)) return true;
47
+ const reviewed = reviewedPullRequest(context.item);
48
+ return reviewed !== void 0 && isEventPullRequest(context, reviewed);
24
49
  }
25
50
  function createdAfterFactory(createdAt, factoryCreatedAt) {
26
51
  if (!createdAt) return false;
@@ -40,16 +65,16 @@ function githubSourceKey(context, source, itemNumber) {
40
65
  return `github:${context.repository.id}:${source === "github-issue" ? "issue" : "pull-request"}:${itemNumber}`;
41
66
  }
42
67
  function issueOpened(context) {
43
- if (!context.issue) return;
68
+ if (!context.issue || !context.intake) return;
44
69
  return {
45
70
  type: "upsertLinkedWorkItem",
46
71
  idempotencyKey: `${context.ingress.id}:issue-intake`,
47
- board: context.intake?.board ?? "work",
72
+ board: context.intake.board,
48
73
  source: "github-issue",
49
74
  sourceKey: githubSourceKey(context, "github-issue", context.issue.number),
50
75
  title: context.issue.title,
51
76
  url: context.issue.url,
52
- stage: context.intake?.initialPhase ?? "intake",
77
+ stage: context.intake.initialPhase,
53
78
  metadata: {
54
79
  githubRepositoryId: context.repository.id,
55
80
  githubIssueNumber: context.issue.number,
@@ -76,17 +101,21 @@ function issueClosed(context) {
76
101
  message: { text: `GitHub issue #${context.issue.number} was closed${context.issue.stateReason ? ` (${context.issue.stateReason})` : ""}; this ${closure.boardTitle} card was moved to ${target.title}.` }
77
102
  });
78
103
  }
79
- function materializePullRequestIntake(context, { idempotencyKey, autoStartCandidate, stage = "intake" }) {
80
- if (!context.pullRequest) return;
104
+ function materializePullRequestIntake(context, { idempotencyKey, autoStartCandidate, review = false }) {
105
+ const { intake } = context;
106
+ if (!context.pullRequest || !intake) return;
107
+ const stage = review ? intake.pullRequestReview ?? intake.initialPhase : intake.initialPhase;
108
+ const home = context.pullRequestHome;
81
109
  return {
82
110
  type: "upsertLinkedWorkItem",
83
111
  idempotencyKey,
84
- board: "work",
112
+ board: intake.board,
85
113
  source: "github-pr",
86
114
  sourceKey: githubSourceKey(context, "github-pr", context.pullRequest.number),
87
115
  title: context.pullRequest.title,
88
116
  url: context.pullRequest.url,
89
117
  stage,
118
+ ...home ? home.reason === "closes" ? { closesIssue: { workItemId: home.workItemId } } : { attachTo: { workItemId: home.workItemId } } : {},
90
119
  metadata: {
91
120
  githubRepositoryId: context.repository.id,
92
121
  githubPullRequestNumber: context.pullRequest.number,
@@ -110,14 +139,16 @@ function pullRequestOpened(context) {
110
139
  if (!context.pullRequest) return;
111
140
  if (context.item && context.pullRequestIntake !== true) {
112
141
  if (!authoringCard(context) || context.pullRequest.state !== "open") return;
113
- if (!context.item.stages.includes("execute")) return;
142
+ const { build, selfReview, pullRequestReview } = context.flow ?? {};
143
+ if (!context.board || !build || !pullRequestReview) return;
144
+ if (!context.item.stages.includes(build) && !(selfReview && selfReviewApprovedHead(context, selfReview))) return;
145
+ if (attachedPullRequest(context) && !context.pullRequest.factoryAuthored) return;
114
146
  if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;
115
- return {
116
- type: "transition",
147
+ return pullRequestMoveByRoutes("pull_request.opened", {
117
148
  idempotencyKey: `${context.ingress.id}:out-for-review`,
118
- board: "work",
119
- stage: "review"
120
- };
149
+ board: context.board,
150
+ stage: pullRequestReview
151
+ });
121
152
  }
122
153
  const autoStartCandidate = (trustedGithubActor(context) || context.pullRequest.factoryAuthored) && createdAfterFactory(context.pullRequest.createdAt, context.factory.createdAt);
123
154
  return materializePullRequestIntake(context, {
@@ -126,39 +157,49 @@ function pullRequestOpened(context) {
126
157
  });
127
158
  }
128
159
  function pullRequestMerged(context) {
129
- if (!context.item || !context.pullRequest?.merged) return;
130
- if (reviewsPullRequest(context)) return {
131
- type: "transition",
160
+ if (!context.item || !context.board || !context.pullRequest?.merged) return;
161
+ if (unreviewedPullRequestCard(context)) return routedOnly(context, "pull_request.merged");
162
+ const done = context.boardClosure?.completed ?? context.flow?.completed;
163
+ if (!done) return;
164
+ if (isPullRequestCard(context.item) && reviewsPullRequest(context)) return pullRequestMoveByRoutes("pull_request.merged", {
132
165
  idempotencyKey: `${context.ingress.id}:pull-request-merged`,
133
- board: pullRequestCardBoard(context),
134
- stage: "done",
135
- message: { text: `Pull request #${context.pullRequest.number} merged; this ${pullRequestCardNoun(context)} was moved to Done. No further review is needed unless follow-up work was requested.` }
136
- };
137
- if (context.board !== "work") return;
138
- const openPullRequestNumber = context.item.metadata?.openPullRequestNumber;
139
- if (typeof openPullRequestNumber === "number" && openPullRequestNumber !== context.pullRequest.number) return {
140
- type: "sendMessage",
141
- idempotencyKey: `${context.ingress.id}:work-merged`,
142
- role: "work",
143
- message: `Pull request #${context.pullRequest.number} merged. Pull request #${openPullRequestNumber} is still open, so this Work card stays in Review until it merges.`
144
- };
145
- return {
146
- type: "transition",
166
+ board: context.board,
167
+ stage: done.phase,
168
+ message: { text: `Pull request #${context.pullRequest.number} merged; this pull request card was moved to ${done.title}. No further review is needed unless follow-up work was requested.` }
169
+ });
170
+ if (!authoringCard(context)) return;
171
+ const recorded = context.item.metadata?.openPullRequestNumber;
172
+ const openPullRequestNumber = typeof recorded === "number" ? recorded : newestOpenPullRequestNumber(context.item, context.pullRequest.number);
173
+ if (typeof openPullRequestNumber === "number" && openPullRequestNumber !== context.pullRequest.number) {
174
+ const role = context.flow?.buildRole;
175
+ if (!role) return;
176
+ return {
177
+ type: "sendMessage",
178
+ idempotencyKey: `${context.ingress.id}:work-merged`,
179
+ role,
180
+ message: `Pull request #${context.pullRequest.number} merged. Pull request #${openPullRequestNumber} is still open, so this card stays where it is until it merges.`
181
+ };
182
+ }
183
+ return pullRequestMoveByRoutes("pull_request.merged", {
147
184
  idempotencyKey: `${context.ingress.id}:work-merged`,
148
- board: "work",
149
- stage: "done",
150
- message: { text: `Pull request #${context.pullRequest.number} merged; this Work card was moved to Done.` }
151
- };
185
+ board: context.board,
186
+ stage: done.phase,
187
+ message: { text: `Pull request #${context.pullRequest.number} merged; this card was moved to ${done.title}.` }
188
+ });
152
189
  }
153
190
  function addressReviewFeedback(context) {
154
191
  if (!context.item || !context.pullRequest || !context.review) return;
155
- if (!authoringCard(context)) return;
192
+ const role = context.flow?.buildRole;
193
+ if (!authoringCard(context) || !role) return;
194
+ if (attachedPullRequest(context) && !context.pullRequest.factoryAuthored) return;
156
195
  if (context.pullRequest.state !== "open" || context.pullRequest.merged) return;
157
- if (context.review.state.toLowerCase() !== "changes_requested") return;
196
+ const state = context.review.state.toLowerCase();
197
+ const factoryVerdict = state === "commented" && context.actor.type === "github" && context.actor.factoryAuthored && context.pullRequest.factoryAuthored && requestsChangesVerdict(context.review.body);
198
+ if (state !== "changes_requested" && !factoryVerdict) return;
158
199
  return {
159
200
  type: "sendMessage",
160
201
  idempotencyKey: `${context.ingress.id}:address-review-feedback`,
161
- role: "work",
202
+ role,
162
203
  priority: "high",
163
204
  message: `Changes were requested on pull request #${context.pullRequest.number} (${context.review.url}). Read the review comments on this PR, address the ones you agree with, and push the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.`
164
205
  };
@@ -189,27 +230,42 @@ function pullRequestReviewSubmitted(context) {
189
230
  function addressPullRequestComment(context) {
190
231
  if (context.reviewCommand) return reReviewRequestedPullRequest(context);
191
232
  if (!context.item || !context.pullRequest || !context.issueComment) return;
192
- if (!authoringCard(context)) return;
233
+ const role = context.flow?.buildRole;
234
+ if (!authoringCard(context) || !role) return;
235
+ if (attachedPullRequest(context) && !context.pullRequest.factoryAuthored) return;
193
236
  if (context.pullRequest.state !== "open" || context.pullRequest.merged) return;
194
237
  if (context.actor.type === "github" && context.actor.factoryAuthored && !requestsChangesVerdict(context.issueComment.body)) return;
195
238
  return {
196
239
  type: "sendMessage",
197
240
  idempotencyKey: `${context.ingress.id}:address-pull-request-comment`,
198
- role: "work",
241
+ role,
199
242
  priority: "high",
200
243
  message: `${context.issueComment.author ?? "Someone"} commented on pull request #${context.pullRequest.number} (${context.issueComment.url ?? context.pullRequest.url}). Read the comment, address it if you agree, and push the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.`
201
244
  };
202
245
  }
203
246
  function pullRequestClosed(context) {
204
- if (!context.item || !context.pullRequest || context.pullRequest.merged) return;
247
+ if (!context.item || !context.board || !context.pullRequest || context.pullRequest.merged) return;
248
+ if (unreviewedPullRequestCard(context)) return routedOnly(context, "pull_request.closed");
205
249
  if (!reviewsPullRequest(context)) return;
206
- return {
207
- type: "transition",
250
+ if (!isPullRequestCard(context.item)) {
251
+ const initialPhase = context.flow?.initialPhase;
252
+ if (!initialPhase || !attachedPullRequest(context) || !inPullRequestReview(context)) return;
253
+ if (newestOpenPullRequestNumber(context.item, context.pullRequest.number) !== null) return;
254
+ return pullRequestMoveByRoutes("pull_request.closed", {
255
+ idempotencyKey: `${context.ingress.id}:pull-request-closed`,
256
+ board: context.board,
257
+ stage: initialPhase,
258
+ message: { text: `Pull request #${context.pullRequest.number} was closed without merging; this card was moved back to ${initialPhase}.` }
259
+ });
260
+ }
261
+ const canceled = context.boardClosure?.canceled ?? context.flow?.canceled;
262
+ if (!canceled) return;
263
+ return pullRequestMoveByRoutes("pull_request.closed", {
208
264
  idempotencyKey: `${context.ingress.id}:pull-request-closed`,
209
- board: pullRequestCardBoard(context),
210
- stage: "canceled",
211
- message: { text: `Pull request #${context.pullRequest.number} was closed without merging; this ${pullRequestCardNoun(context)} was moved to Canceled.` }
212
- };
265
+ board: context.board,
266
+ stage: canceled.phase,
267
+ message: { text: `Pull request #${context.pullRequest.number} was closed without merging; this pull request card was moved to ${canceled.title}.` }
268
+ });
213
269
  }
214
270
  function reReviewRequestedPullRequest(context) {
215
271
  const factoryReviewEntry = context.reviewRequest?.factoryReviewer || context.reviewCommand !== void 0;
@@ -220,33 +276,35 @@ function reReviewRequestedPullRequest(context) {
220
276
  if (!context.item) return materializePullRequestIntake(context, {
221
277
  idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,
222
278
  autoStartCandidate: true,
223
- stage: "pr-review"
279
+ review: true
224
280
  });
225
- const stage = pullRequestReviewPhase(context.board);
226
- const reviewing = context.item.stages.length === 1 && context.item.stages[0] === stage;
281
+ const stage = context.flow?.pullRequestReview;
282
+ if (!context.board || !stage) return;
283
+ const reviewing = inPullRequestReview(context);
284
+ if (reviewing && !reviewsThisPullRequest(context)) return;
227
285
  if (reviewing && !hasRecordedVerdict(context.item)) return;
228
- return {
229
- type: "transition",
286
+ return pullRequestMoveByRoutes("pull_request.review_requested", {
230
287
  idempotencyKey: `${context.ingress.id}:re-review-requested`,
231
- board: pullRequestCardBoard(context),
288
+ board: context.board,
232
289
  stage,
233
290
  ...reviewing ? { reenter: true } : {}
234
- };
291
+ });
235
292
  }
236
293
  function reReviewUpdatedPullRequest(context) {
237
- if (!context.item || !reviewsPullRequest(context)) return;
294
+ if (!context.item || !context.board || !reviewsPullRequest(context)) return;
238
295
  if (!context.pullRequest || context.pullRequest.state !== "open" || context.pullRequest.merged) return;
239
- if (context.item.stages.some((stage) => stage === "intake")) return;
296
+ const stage = context.flow?.pullRequestReview;
297
+ if (!stage) return;
298
+ const reviewing = inPullRequestReview(context);
299
+ if (!isPullRequestCard(context.item) && !(reviewing && reviewsThisPullRequest(context))) return;
300
+ if (context.phase?.kind === "resting") return;
240
301
  if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;
241
- const stage = pullRequestReviewPhase(context.board);
242
- const alreadyReviewing = context.item.stages.some((current) => current === stage);
243
- return {
244
- type: "transition",
302
+ return pullRequestMoveByRoutes("pull_request.synchronized", {
245
303
  idempotencyKey: `${context.ingress.id}:re-review-updated`,
246
- board: pullRequestCardBoard(context),
304
+ board: context.board,
247
305
  stage,
248
- ...alreadyReviewing ? { reenter: true } : {}
249
- };
306
+ ...reviewing ? { reenter: true } : {}
307
+ });
250
308
  }
251
309
  const defaultGithubRules = Object.freeze({
252
310
  issueOpened,
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/github/default-rules.ts"],"sourcesContent":["import { isPullRequestCard, pullRequestReviewPhase, reviewsPullRequest } from '../../boards/index.js';\nimport { hasRecordedVerdict } from '../../boards/pull-request-review.js';\nimport { requestsChangesVerdict } from '../../review-verdict.js';\nimport { closedByRoutes, recordExplicitRuleOverrides } from '../../rules/event-rules.js';\nimport type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport { isFactoryApproveVerdict } from './stale-reviews.js';\n\nexport type GithubRuleOverrides = Partial<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null | undefined>\n>;\nexport type GithubEventRules = Readonly<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null>\n>;\n\nfunction trustedGithubActor(context: Pick<FactoryGithubRuleContext, 'actor'>): boolean {\n return context.actor.type === 'github' && context.actor.trusted;\n}\n\nfunction githubActorLogin(context: Pick<FactoryGithubRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'github' ? context.actor.login : undefined;\n}\n\n/** The Work card whose session authored the pull request, as opposed to the PR's own card. */\nfunction authoringCard(context: FactoryGithubRuleContext): boolean {\n return context.board === 'work' && context.item !== undefined && !isPullRequestCard(context.item);\n}\n\n/** The board holding the PR's own card: Work for new cards, Review for cards filed before PRs moved to Work. */\nfunction pullRequestCardBoard(context: FactoryGithubRuleContext): 'work' | 'review' {\n return context.board === 'review' ? 'review' : 'work';\n}\n\nfunction pullRequestCardNoun(context: FactoryGithubRuleContext): string {\n return context.board === 'review' ? 'Review card' : 'pull request card';\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\n/**\n * Issue and pull request numbers repeat across repositories, so new cards are\n * keyed by repository. A card this repository already owns keeps its key —\n * including canonical `github-issue:N` / `github-pr:N` keys from before\n * scoping — but only when it is the same kind of source: pull request intake\n * runs with the authoring issue as `context.item`.\n */\nfunction githubSourceKey(\n context: FactoryGithubRuleContext,\n source: 'github-issue' | 'github-pr',\n itemNumber: number,\n): string {\n if (context.item?.source === source && context.item.sourceKey) return context.item.sourceKey;\n return `github:${context.repository.id}:${source === 'github-issue' ? 'issue' : 'pull-request'}:${itemNumber}`;\n}\n\nfunction issueOpened(context: FactoryGithubRuleContext) {\n if (!context.issue) return;\n // Everything arrives on the routed board's initial phase (Work › Intake when\n // no label route selects another board). Trust/timing stamps remain available\n // to custom board rules.\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake?.board ?? 'work',\n source: 'github-issue',\n sourceKey: githubSourceKey(context, 'github-issue', context.issue.number),\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake?.initialPhase ?? 'intake',\n metadata: {\n githubRepositoryId: context.repository.id,\n githubIssueNumber: context.issue.number,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...(context.issue.author || githubActorLogin(context)\n ? { author: context.issue.author ?? githubActorLogin(context) }\n : {}),\n state: context.issue.state ?? 'open',\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate:\n trustedGithubActor(context) && createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.issue) return;\n // The project's intake routes decide where a closed source sends the card. The board's\n // `sourceClosed` mapping applies only when no route on the board handles closes; without\n // one the close goes to the routes alone (see `routeEventDecision`).\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // Issue closure is a repository fact, not third-party input — no actor trust\n // gate. `not_planned` (and `duplicate`) means abandoned, everything else is\n // completed work.\n const canceled = context.issue.stateReason === 'not_planned' || context.issue.stateReason === 'duplicate';\n const target = canceled ? closure.canceled : closure.completed;\n return closedByRoutes(canceled, {\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: target.phase,\n message: {\n text:\n `GitHub issue #${context.issue.number} was closed` +\n `${context.issue.stateReason ? ` (${context.issue.stateReason})` : ''}; ` +\n `this ${closure.boardTitle} card was moved to ${target.title}.`,\n },\n });\n}\n\nfunction materializePullRequestIntake(\n context: FactoryGithubRuleContext,\n {\n idempotencyKey,\n autoStartCandidate,\n stage = 'intake',\n }: { idempotencyKey: string; autoStartCandidate: boolean; stage?: 'intake' | 'pr-review' },\n) {\n if (!context.pullRequest) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey,\n board: 'work',\n source: 'github-pr',\n sourceKey: githubSourceKey(context, 'github-pr', context.pullRequest.number),\n title: context.pullRequest.title,\n url: context.pullRequest.url,\n stage,\n metadata: {\n githubRepositoryId: context.repository.id,\n githubPullRequestNumber: context.pullRequest.number,\n ...(context.pullRequest.createdAt ? { sourceCreatedAt: context.pullRequest.createdAt } : {}),\n factoryAuthored: context.pullRequest.factoryAuthored,\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate,\n state: context.pullRequest.state,\n draft: context.pullRequest.draft,\n merged: context.pullRequest.merged,\n assignees: context.pullRequest.assignees ?? [],\n requestedReviewers: context.pullRequest.requestedReviewers ?? [],\n labels: context.pullRequest.labels ?? [],\n headBranch: context.pullRequest.headBranch,\n baseBranch: context.pullRequest.baseBranch,\n ...(context.pullRequest.author ? { author: context.pullRequest.author } : {}),\n },\n } as const;\n}\n\nfunction pullRequestOpened(context: FactoryGithubRuleContext) {\n if (!context.pullRequest) return;\n // Opening a pull request is evaluated once per card it concerns. This rule\n // files the pull request's own card, which is the arrival — the\n // evaluation carrying `pullRequestIntake` — so the authoring Work item's own\n // evaluation only moves it out for review: Building means \"no pull request\n // yet\", Review means one is open. The card rests there through every round of\n // feedback — the builder is woken in place — until the merge closes it.\n if (context.item && context.pullRequestIntake !== true) {\n if (!authoringCard(context) || context.pullRequest.state !== 'open') return;\n if (!context.item.stages.includes('execute')) return;\n // Resolution can match a Work item by branch alone, so a fork's pull\n // request must not be able to move it: same bar as auto-starting a review.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:out-for-review`,\n board: 'work',\n stage: 'review',\n } as const;\n }\n // A GitHub App bot is never a collaborator, so Factory's own PRs score\n // untrusted; their authorship is the trust signal.\n const autoStartCandidate =\n (trustedGithubActor(context) || context.pullRequest.factoryAuthored) &&\n createdAfterFactory(context.pullRequest.createdAt, context.factory.createdAt);\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-intake`,\n autoStartCandidate,\n });\n}\n\nfunction pullRequestMerged(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest?.merged) return;\n if (reviewsPullRequest(context)) {\n // The event is bound to the PR's own card: a merged PR is finished\n // review work, so always move the card to Done. The message only reaches\n // an active session (if any) — cards without one just move, instead of\n // failing retries against a binding that never existed.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-merged`,\n board: pullRequestCardBoard(context),\n stage: 'done',\n message: {\n text:\n `Pull request #${context.pullRequest.number} merged; this ${pullRequestCardNoun(context)} was moved to Done. ` +\n 'No further review is needed unless follow-up work was requested.',\n },\n } as const;\n }\n // Custom boards define their own lifecycle and cannot accept a transition\n // targeting the built-in Work board. Let their custom rules handle the merge.\n if (context.board !== 'work') return;\n // Provenance bound the event to the originating Work item instead: the merge\n // is what finishes the work, so it closes the Work card alongside the PR's own card —\n // unless the card has since opened another pull request, which is still out.\n const openPullRequestNumber = context.item.metadata?.openPullRequestNumber;\n if (typeof openPullRequestNumber === 'number' && openPullRequestNumber !== context.pullRequest.number) {\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role: 'work',\n message:\n `Pull request #${context.pullRequest.number} merged. Pull request #${openPullRequestNumber} is still open, ` +\n 'so this Work card stays in Review until it merges.',\n } as const;\n }\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: 'work',\n stage: 'done',\n message: { text: `Pull request #${context.pullRequest.number} merged; this Work card was moved to Done.` },\n } as const;\n}\n\nfunction addressReviewFeedback(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || !context.review) return;\n // Only the Work item that authored the PR can act on the feedback. Provenance\n // binds the event there; the PR's own card seeing its posted review must not\n // react to it (that would loop the reviewer against itself).\n if (!authoringCard(context)) return;\n // A closed or merged pull request has no branch left to push fixes to.\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `approved` needs no work, and `commented` (a review body with no verdict)\n // is how a reviewer leaves notes without blocking — only a verdict that asks\n // for changes should pull the author back in.\n if (context.review.state.toLowerCase() !== 'changes_requested') return;\n // The authoring thread is already subscribed to this PR (`gh pr create`\n // subscribes automatically), so it can read the individual line comments\n // from its own notification inbox — the message only has to wake it and\n // point at the review.\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-review-feedback`,\n role: 'work',\n priority: 'high',\n message:\n `Changes were requested on pull request #${context.pullRequest.number} (${context.review.url}). ` +\n 'Read the review comments on this PR, address the ones you agree with, and push the fixes to the PR branch. ' +\n 'Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\n/**\n * A Factory approval does not clear a change request left by a different\n * Factory identity (an earlier reviewer token, say), so GitHub would keep the\n * pull request blocked. Ask the dispatcher to dismiss those superseded reviews.\n */\nfunction dismissStaleFactoryReviews(context: FactoryGithubRuleContext) {\n const { pullRequest, review, repository } = context;\n if (!pullRequest || !review || !review.author || !repository.installationId) return;\n if (review.state.toLowerCase() !== 'approved' || !isFactoryApproveVerdict(review.body)) return;\n if (!pullRequest.factoryAuthored || pullRequest.state !== 'open' || pullRequest.merged) return;\n return {\n type: 'dismissStaleReviews',\n idempotencyKey: `${context.ingress.id}:dismiss-stale-reviews`,\n installationId: repository.installationId,\n repository: repository.fullName,\n pullRequestNumber: pullRequest.number,\n approvingReviewId: String(review.id),\n approvingAuthor: review.author,\n } as const;\n}\n\nfunction pullRequestReviewSubmitted(context: FactoryGithubRuleContext) {\n return addressReviewFeedback(context) ?? dismissStaleFactoryReviews(context);\n}\n\nfunction addressPullRequestComment(context: FactoryGithubRuleContext) {\n // A validated Factory mention is a review-entry request, not feedback for the\n // authoring Work session. Invalid or unrecognized comments retain the normal\n // feedback route below.\n if (context.reviewCommand) return reReviewRequestedPullRequest(context);\n if (!context.item || !context.pullRequest || !context.issueComment) return;\n // Provenance binds the comment to the Work item that authored the PR — the\n // only session that can act on it. The PR's own card must not react to\n // comments on the PR it is reviewing.\n if (!authoringCard(context)) return;\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `factoryAuthored` is one bit for the whole Factory, so Factory's own\n // comments are indistinguishable between roles — waking on all of them would\n // let the Work agent's own progress comments wake itself in a loop. The one\n // exception is the review verdict the Review run had to post as a comment\n // because GitHub refused a self-review: that is the handoff, and it only ever\n // asks for changes once per review, so it cannot sustain a loop.\n if (\n context.actor.type === 'github' &&\n context.actor.factoryAuthored &&\n !requestsChangesVerdict(context.issueComment.body)\n ) {\n return;\n }\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-pull-request-comment`,\n role: 'work',\n priority: 'high',\n message:\n `${context.issueComment.author ?? 'Someone'} commented on pull request #${context.pullRequest.number} ` +\n `(${context.issueComment.url ?? context.pullRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\nfunction pullRequestClosed(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || context.pullRequest.merged) return;\n if (!reviewsPullRequest(context)) return;\n // A PR closed without merging is abandoned review work: clear the card off\n // the board instead of leaving it in Reviewing forever.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-closed`,\n board: pullRequestCardBoard(context),\n stage: 'canceled',\n message: {\n text:\n `Pull request #${context.pullRequest.number} was closed without merging; ` +\n `this ${pullRequestCardNoun(context)} was moved to Canceled.`,\n },\n } as const;\n}\n\nfunction reReviewRequestedPullRequest(context: FactoryGithubRuleContext) {\n // GitHub reviewer requests and Factory's exact mention command are both\n // explicit requests to enter the same Review lifecycle.\n const factoryReviewEntry = context.reviewRequest?.factoryReviewer || context.reviewCommand !== undefined;\n if ((context.item && !reviewsPullRequest(context)) || !factoryReviewEntry) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Trusted (write/admin) requesters only: creating or re-entering review checks\n // out and executes PR code, the same bar pullRequestOpened applies to auto-review.\n if (!trustedGithubActor(context)) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n if (!context.item) {\n // On this path the actor is the *requester*, so the materialized\n // `authorTrusted` stamp records their trust (always true past the gate\n // above), not the PR author's: a trusted maintainer requesting a Factory\n // review vouches for the PR.\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,\n autoStartCandidate: true,\n stage: 'pr-review',\n });\n }\n // Already in Reviewing with no verdict yet: a pass is pending or running.\n // Once a verdict is recorded the card rests in Reviewing, so a fresh request\n // re-enters the stage to start another pass.\n const stage = pullRequestReviewPhase(context.board);\n const reviewing = context.item.stages.length === 1 && context.item.stages[0] === stage;\n if (reviewing && !hasRecordedVerdict(context.item)) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-requested`,\n board: pullRequestCardBoard(context),\n stage,\n ...(reviewing ? { reenter: true } : {}),\n } as const;\n}\n\nfunction reReviewUpdatedPullRequest(context: FactoryGithubRuleContext) {\n if (!context.item || !reviewsPullRequest(context)) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Intake has not started a review pass yet, so a push there is just more of\n // the code the first pass will read. A push to a card sitting in Reviewing is\n // different: it invalidates whatever that pass is reading, so re-enter the\n // stage to supersede it. `reviewPullRequest` cancels the stale run and picks\n // the right skill for the entry it sees.\n if (context.item.stages.some(stage => stage === 'intake')) return;\n // A fork's author controls its head branch, so an untrusted push must not be\n // able to start review passes on demand; a maintainer can still request one.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n const stage = pullRequestReviewPhase(context.board);\n const alreadyReviewing = context.item.stages.some(current => current === stage);\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: pullRequestCardBoard(context),\n stage,\n // Re-entry is the point when the card is already Reviewing: the stage's\n // entry rule is what cancels the superseded pass and starts one on the code\n // that just landed.\n ...(alreadyReviewing ? { reenter: true } : {}),\n } as const;\n}\n\nexport const defaultGithubRules = Object.freeze({\n issueOpened: issueOpened,\n // Triage runs once, when a person moves the card into Triage or starts the run; later edits and\n // comments on the issue don't run it again.\n issueEdited: null,\n issueClosed: issueClosed,\n issueReopened: null,\n issueCommentCreated: null,\n issueCommentEdited: null,\n issueCommentDeleted: null,\n pullRequestOpened: pullRequestOpened,\n pullRequestUpdated: reReviewUpdatedPullRequest,\n pullRequestCommentCreated: addressPullRequestComment,\n pullRequestReviewRequested: reReviewRequestedPullRequest,\n pullRequestReviewSubmitted: pullRequestReviewSubmitted,\n pullRequestMerged: pullRequestMerged,\n pullRequestClosed: pullRequestClosed,\n} satisfies GithubEventRules);\n\nexport function resolveGithubRules(overrides?: GithubRuleOverrides): GithubEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitHub rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGithubRuleContext> | null> = { ...defaultGithubRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGithubRules, key)) {\n throw new Error(`Unknown GitHub rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGithubEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitHub rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as GithubEventRules, overrides);\n}\n"],"mappings":";;;;;;;AAcA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAEA,SAAS,iBAAiB,SAAsE;CAC9F,OAAO,QAAQ,MAAM,SAAS,WAAW,QAAQ,MAAM,QAAQ,KAAA;AACjE;;AAGA,SAAS,cAAc,SAA4C;CACjE,OAAO,QAAQ,UAAU,UAAU,QAAQ,SAAS,KAAA,KAAa,CAAC,kBAAkB,QAAQ,IAAI;AAClG;;AAGA,SAAS,qBAAqB,SAAsD;CAClF,OAAO,QAAQ,UAAU,WAAW,WAAW;AACjD;AAEA,SAAS,oBAAoB,SAA2C;CACtE,OAAO,QAAQ,UAAU,WAAW,gBAAgB;AACtD;AAEA,SAAS,oBAAoB,WAA+B,kBAAmC;CAC7F,IAAI,CAAC,WAAW,OAAO;CACvB,MAAM,kBAAkB,KAAK,MAAM,SAAS;CAC5C,MAAM,mBAAmB,KAAK,MAAM,gBAAgB;CACpD,OAAO,OAAO,SAAS,eAAe,KAAK,OAAO,SAAS,gBAAgB,KAAK,kBAAkB;AACpG;;;;;;;;AASA,SAAS,gBACP,SACA,QACA,YACQ;CACR,IAAI,QAAQ,MAAM,WAAW,UAAU,QAAQ,KAAK,WAAW,OAAO,QAAQ,KAAK;CACnF,OAAO,UAAU,QAAQ,WAAW,GAAG,GAAG,WAAW,iBAAiB,UAAU,eAAe,GAAG;AACpG;AAEA,SAAS,YAAY,SAAmC;CACtD,IAAI,CAAC,QAAQ,OAAO;CAIpB,OAAO;EACL,MAAM;EACN,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EACtC,OAAO,QAAQ,QAAQ,SAAS;EAChC,QAAQ;EACR,WAAW,gBAAgB,SAAS,gB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CAG3D,IAAI,CAAC,mBAAmB,OAAO,KAAK,CAAC,QAAQ,YAAY,iBAAiB;CAC1E,MAAM,QAAQ,uBAAuB,QAAQ,KAAK;CAClD,MAAM,mBAAmB,QAAQ,KAAK,OAAO,MAAK,YAAW,YAAY,KAAK;CAC9E,OAAO;EACL,MAAM;EACN,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EACtC,OAAO,qBAAqB,OAAO;EACnC;EAIA,GAAI,mBAAmB,EAAE,SAAS,KAAK,IAAI,CAAC;CAC9C;AACF;AAEA,MAAa,qBAAqB,OAAO,OAAO;CACjC;CAGb,aAAa;CACA;CACb,eAAe;CACf,qBAAqB;CACrB,oBAAoB;CACpB,qBAAqB;CACF;CACnB,oBAAoB;CACpB,2BAA2B;CAC3B,4BAA4B;CACA;CACT;CACA;AACrB,CAA4B;AAE5B,SAAgB,mBAAmB,WAAmD;CACpF,IAAI,cAAc,KAAA,MAAc,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IAC5G,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,QAA6E,EAAE,GAAG,mBAAmB;CAC3G,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,oBAAoB,GAAG,GACnE,MAAM,IAAI,MAAM,8BAA8B,OAAO,GAAG,EAAE,EAAE;EAE9D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,eAAe,IAAI,yCAAyC;EAE9E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,4BAA4B,OAAO,OAAO,KAAK,GAAuB,SAAS;AACxF"}
1
+ {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/github/default-rules.ts"],"sourcesContent":["import {\n isPullRequestCard,\n newestOpenPullRequestNumber,\n pullRequestSourceNumber,\n pullRequestSources,\n reviewedPullRequest,\n reviewsPullRequest,\n} from '../../boards/index.js';\nimport { hasRecordedVerdict } from '../../boards/semantics.js';\nimport { requestsChangesVerdict } from '../../review-verdict.js';\nimport {\n closedByRoutes,\n pullRequestMoveByRoutes,\n recordExplicitRuleOverrides,\n routedOnly,\n unreviewedPullRequestCard,\n} from '../../rules/event-rules.js';\nimport type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport type { WorkItemSourceRow } from '../../storage/domains/work-items/work-item-schema.js';\nimport { isRepositoryPullRequest } from './pull-request-source.js';\nimport { isFactoryApproveVerdict } from './stale-reviews.js';\n\nexport type GithubRuleOverrides = Partial<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null | undefined>\n>;\nexport type GithubEventRules = Readonly<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null>\n>;\n\nfunction trustedGithubActor(context: Pick<FactoryGithubRuleContext, 'actor'>): boolean {\n return context.actor.type === 'github' && context.actor.trusted;\n}\n\nfunction githubActorLogin(context: Pick<FactoryGithubRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'github' ? context.actor.login : undefined;\n}\n\n/**\n * The card whose session authored the pull request, as opposed to the PR's own card, on a board\n * that reviews pull requests.\n */\nfunction authoringCard(context: FactoryGithubRuleContext): boolean {\n return (\n context.flow?.pullRequestReview !== undefined && context.item !== undefined && !isPullRequestCard(context.item)\n );\n}\n\n/** Whether the card sits in `selfReview` with an approve verdict on the head its pull request opened with. */\nfunction selfReviewApprovedHead(context: FactoryGithubRuleContext, selfReview: string): boolean {\n const { item, pullRequest } = context;\n const metadata = item?.metadata;\n const approvedHead = metadata?.selfReviewedHeadSha;\n return (\n item?.stages.length === 1 &&\n item.stages[0] === selfReview &&\n metadata?.selfReviewVerdict === 'approve' &&\n typeof approvedHead === 'string' &&\n pullRequest?.headSha !== undefined &&\n approvedHead.toLowerCase() === pullRequest.headSha\n );\n}\n\n/** Whether the card sits in its board's pull request review phase, alone. */\nfunction inPullRequestReview(context: FactoryGithubRuleContext): boolean {\n const phase = context.flow?.pullRequestReview;\n return phase !== undefined && context.item?.stages.length === 1 && context.item.stages[0] === phase;\n}\n\n/** Whether the rule's card carries the event's pull request as one of its sources, attached to its issue. */\nfunction attachedPullRequest(context: FactoryGithubRuleContext): boolean {\n const { item, pullRequest } = context;\n if (!item || !pullRequest || isPullRequestCard(item)) return false;\n return pullRequestSources(item).some(source => isEventPullRequest(context, source));\n}\n\n/** Whether a source row is the event's pull request: the same number in the same repository. */\nfunction isEventPullRequest(context: FactoryGithubRuleContext, source: WorkItemSourceRow): boolean {\n return (\n context.pullRequest !== undefined &&\n isRepositoryPullRequest(source, context.repository.id, context.repository.fullName, context.pullRequest.number)\n );\n}\n\n/** Whether the card's PR review covers the event's pull request: its own, or the attached one it reviews. */\nfunction reviewsThisPullRequest(context: FactoryGithubRuleContext): boolean {\n if (!context.item || !context.pullRequest || !reviewsPullRequest(context)) return false;\n if (isPullRequestCard(context.item)) return true;\n const reviewed = reviewedPullRequest(context.item);\n return reviewed !== undefined && isEventPullRequest(context, reviewed);\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\n/**\n * Issue and pull request numbers repeat across repositories, so new cards are\n * keyed by repository. A card this repository already owns keeps its key —\n * including canonical `github-issue:N` / `github-pr:N` keys from before\n * scoping — but only when it is the same kind of source: pull request intake\n * runs with the authoring issue as `context.item`.\n */\nfunction githubSourceKey(\n context: FactoryGithubRuleContext,\n source: 'github-issue' | 'github-pr',\n itemNumber: number,\n): string {\n if (context.item?.source === source && context.item.sourceKey) return context.item.sourceKey;\n return `github:${context.repository.id}:${source === 'github-issue' ? 'issue' : 'pull-request'}:${itemNumber}`;\n}\n\nfunction issueOpened(context: FactoryGithubRuleContext) {\n if (!context.issue || !context.intake) return;\n // Everything arrives on the routed board's initial phase (the project's default board when no\n // label route or binding selects another). Trust/timing stamps remain available to custom board\n // rules.\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake.board,\n source: 'github-issue',\n sourceKey: githubSourceKey(context, 'github-issue', context.issue.number),\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake.initialPhase,\n metadata: {\n githubRepositoryId: context.repository.id,\n githubIssueNumber: context.issue.number,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...(context.issue.author || githubActorLogin(context)\n ? { author: context.issue.author ?? githubActorLogin(context) }\n : {}),\n state: context.issue.state ?? 'open',\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate:\n trustedGithubActor(context) && createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.issue) return;\n // The project's intake routes decide where a closed source sends the card. The board's\n // `sourceClosed` mapping applies only when no route on the board handles closes; without\n // one the close goes to the routes alone (see `routeEventDecision`).\n const closure = context.boardClosure;\n if (!context.board || !closure || closure.itemTerminal) return;\n // Issue closure is a repository fact, not third-party input — no actor trust\n // gate. `not_planned` (and `duplicate`) means abandoned, everything else is\n // completed work.\n const canceled = context.issue.stateReason === 'not_planned' || context.issue.stateReason === 'duplicate';\n const target = canceled ? closure.canceled : closure.completed;\n return closedByRoutes(canceled, {\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: context.board,\n stage: target.phase,\n message: {\n text:\n `GitHub issue #${context.issue.number} was closed` +\n `${context.issue.stateReason ? ` (${context.issue.stateReason})` : ''}; ` +\n `this ${closure.boardTitle} card was moved to ${target.title}.`,\n },\n });\n}\n\nfunction materializePullRequestIntake(\n context: FactoryGithubRuleContext,\n {\n idempotencyKey,\n autoStartCandidate,\n review = false,\n }: { idempotencyKey: string; autoStartCandidate: boolean; review?: boolean },\n) {\n const { intake } = context;\n if (!context.pullRequest || !intake) return;\n // A requested review lands straight in the board's pull request review phase; a board without\n // one files the pull request where everything else arrives.\n const stage = review ? (intake.pullRequestReview ?? intake.initialPhase) : intake.initialPhase;\n const home = context.pullRequestHome;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey,\n board: intake.board,\n source: 'github-pr',\n sourceKey: githubSourceKey(context, 'github-pr', context.pullRequest.number),\n title: context.pullRequest.title,\n url: context.pullRequest.url,\n stage,\n // A pull request for a card already on the board is filed on that card; the authoring card's\n // own evaluation moves it. For one that closes an issue on the board, the project's intake\n // routes decide whether it joins that card.\n ...(home\n ? home.reason === 'closes'\n ? { closesIssue: { workItemId: home.workItemId } }\n : { attachTo: { workItemId: home.workItemId } }\n : {}),\n metadata: {\n githubRepositoryId: context.repository.id,\n githubPullRequestNumber: context.pullRequest.number,\n ...(context.pullRequest.createdAt ? { sourceCreatedAt: context.pullRequest.createdAt } : {}),\n factoryAuthored: context.pullRequest.factoryAuthored,\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate,\n state: context.pullRequest.state,\n draft: context.pullRequest.draft,\n merged: context.pullRequest.merged,\n assignees: context.pullRequest.assignees ?? [],\n requestedReviewers: context.pullRequest.requestedReviewers ?? [],\n labels: context.pullRequest.labels ?? [],\n headBranch: context.pullRequest.headBranch,\n baseBranch: context.pullRequest.baseBranch,\n ...(context.pullRequest.author ? { author: context.pullRequest.author } : {}),\n },\n } as const;\n}\n\nfunction pullRequestOpened(context: FactoryGithubRuleContext) {\n if (!context.pullRequest) return;\n // Opening a pull request is evaluated once per card it concerns. This rule\n // files the pull request's own card, which is the arrival — the\n // evaluation carrying `pullRequestIntake` — so the authoring card's own\n // evaluation only moves it out for review: from its build phase (a board\n // without self-review, or a pull request opened before self-review ran), or\n // from self-review once it approved the very head the pull request opens\n // with. Opening the pull request writes it onto the card, so the agent's own\n // move at its pre-PR revision always loses that race; the event moves the\n // card instead. It rests in the board's pull request review phase through\n // every round of feedback — the builder is woken in place — until the merge\n // closes it.\n if (context.item && context.pullRequestIntake !== true) {\n if (!authoringCard(context) || context.pullRequest.state !== 'open') return;\n const { build, selfReview, pullRequestReview } = context.flow ?? {};\n if (!context.board || !build || !pullRequestReview) return;\n if (!context.item.stages.includes(build) && !(selfReview && selfReviewApprovedHead(context, selfReview))) return;\n // Someone else's pull request attached to the issue does not mean this card's build is out.\n if (attachedPullRequest(context) && !context.pullRequest.factoryAuthored) return;\n // Resolution can match a card by branch alone, so a fork's pull\n // request must not be able to move it: same bar as auto-starting a review.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n return pullRequestMoveByRoutes('pull_request.opened', {\n idempotencyKey: `${context.ingress.id}:out-for-review`,\n board: context.board,\n stage: pullRequestReview,\n });\n }\n // A GitHub App bot is never a collaborator, so Factory's own PRs score\n // untrusted; their authorship is the trust signal.\n const autoStartCandidate =\n (trustedGithubActor(context) || context.pullRequest.factoryAuthored) &&\n createdAfterFactory(context.pullRequest.createdAt, context.factory.createdAt);\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-intake`,\n autoStartCandidate,\n });\n}\n\nfunction pullRequestMerged(context: FactoryGithubRuleContext) {\n if (!context.item || !context.board || !context.pullRequest?.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.merged');\n const done = context.boardClosure?.completed ?? context.flow?.completed;\n if (!done) return;\n if (isPullRequestCard(context.item) && reviewsPullRequest(context)) {\n // The event is bound to the PR's own card: a merged PR is finished\n // review work, so always move the card to its board's completed phase. The\n // message only reaches an active session (if any) — cards without one just\n // move, instead of failing retries against a binding that never existed.\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:pull-request-merged`,\n board: context.board,\n stage: done.phase,\n message: {\n text:\n `Pull request #${context.pullRequest.number} merged; this pull request card was moved to ${done.title}. ` +\n 'No further review is needed unless follow-up work was requested.',\n },\n });\n }\n if (!authoringCard(context)) return;\n // Provenance bound the event to the card that authored the pull request instead: the merge\n // is what finishes the work, so it closes that card alongside the PR's own card —\n // unless the card has since opened another pull request, which is still out.\n // A card carrying several pull requests waits for the one it has out, else for any still open.\n const recorded = context.item.metadata?.openPullRequestNumber;\n const openPullRequestNumber =\n typeof recorded === 'number'\n ? recorded\n : newestOpenPullRequestNumber(context.item, context.pullRequest.number);\n if (typeof openPullRequestNumber === 'number' && openPullRequestNumber !== context.pullRequest.number) {\n const role = context.flow?.buildRole;\n if (!role) return;\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role,\n message:\n `Pull request #${context.pullRequest.number} merged. Pull request #${openPullRequestNumber} is still open, ` +\n 'so this card stays where it is until it merges.',\n } as const;\n }\n return pullRequestMoveByRoutes('pull_request.merged', {\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: context.board,\n stage: done.phase,\n message: { text: `Pull request #${context.pullRequest.number} merged; this card was moved to ${done.title}.` },\n });\n}\n\nfunction addressReviewFeedback(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || !context.review) return;\n // Only the card that authored the PR can act on the feedback. Provenance\n // binds the event there; the PR's own card seeing its posted review must not\n // react to it (that would loop the reviewer against itself).\n const role = context.flow?.buildRole;\n if (!authoringCard(context) || !role) return;\n // Someone else's pull request attached to the issue is not the builder's to fix.\n if (attachedPullRequest(context) && !context.pullRequest.factoryAuthored) return;\n // A closed or merged pull request has no branch left to push fixes to.\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `approved` needs no work, and `commented` is how a reviewer leaves notes\n // without blocking — only a verdict that asks for changes should pull the\n // author back in. GitHub will not let Factory's app request changes on a pull\n // request it authored, so there Factory's own `commented` review carries the\n // verdict on its first line instead; that one counts too.\n const state = context.review.state.toLowerCase();\n const factoryVerdict =\n state === 'commented' &&\n context.actor.type === 'github' &&\n context.actor.factoryAuthored &&\n context.pullRequest.factoryAuthored &&\n requestsChangesVerdict(context.review.body);\n if (state !== 'changes_requested' && !factoryVerdict) return;\n // The authoring thread is already subscribed to this PR (`gh pr create`\n // subscribes automatically), so it can read the individual line comments\n // from its own notification inbox — the message only has to wake it and\n // point at the review.\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-review-feedback`,\n role,\n priority: 'high',\n message:\n `Changes were requested on pull request #${context.pullRequest.number} (${context.review.url}). ` +\n 'Read the review comments on this PR, address the ones you agree with, and push the fixes to the PR branch. ' +\n 'Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\n/**\n * A Factory approval does not clear a change request left by a different\n * Factory identity (an earlier reviewer token, say), so GitHub would keep the\n * pull request blocked. Ask the dispatcher to dismiss those superseded reviews.\n */\nfunction dismissStaleFactoryReviews(context: FactoryGithubRuleContext) {\n const { pullRequest, review, repository } = context;\n if (!pullRequest || !review || !review.author || !repository.installationId) return;\n if (review.state.toLowerCase() !== 'approved' || !isFactoryApproveVerdict(review.body)) return;\n if (!pullRequest.factoryAuthored || pullRequest.state !== 'open' || pullRequest.merged) return;\n return {\n type: 'dismissStaleReviews',\n idempotencyKey: `${context.ingress.id}:dismiss-stale-reviews`,\n installationId: repository.installationId,\n repository: repository.fullName,\n pullRequestNumber: pullRequest.number,\n approvingReviewId: String(review.id),\n approvingAuthor: review.author,\n } as const;\n}\n\nfunction pullRequestReviewSubmitted(context: FactoryGithubRuleContext) {\n return addressReviewFeedback(context) ?? dismissStaleFactoryReviews(context);\n}\n\nfunction addressPullRequestComment(context: FactoryGithubRuleContext) {\n // A validated Factory mention is a review-entry request, not feedback for the\n // authoring session. Invalid or unrecognized comments retain the normal\n // feedback route below.\n if (context.reviewCommand) return reReviewRequestedPullRequest(context);\n if (!context.item || !context.pullRequest || !context.issueComment) return;\n // Provenance binds the comment to the card that authored the PR — the\n // only session that can act on it. The PR's own card must not react to\n // comments on the PR it is reviewing.\n const role = context.flow?.buildRole;\n if (!authoringCard(context) || !role) return;\n if (attachedPullRequest(context) && !context.pullRequest.factoryAuthored) return;\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `factoryAuthored` is one bit for the whole Factory, so Factory's own\n // comments are indistinguishable between roles — waking on all of them would\n // let the builder's own progress comments wake itself in a loop. The one\n // exception is the review verdict the Review run had to post as a comment\n // because GitHub refused a self-review: that is the handoff, and it only ever\n // asks for changes once per review, so it cannot sustain a loop.\n if (\n context.actor.type === 'github' &&\n context.actor.factoryAuthored &&\n !requestsChangesVerdict(context.issueComment.body)\n ) {\n return;\n }\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-pull-request-comment`,\n role,\n priority: 'high',\n message:\n `${context.issueComment.author ?? 'Someone'} commented on pull request #${context.pullRequest.number} ` +\n `(${context.issueComment.url ?? context.pullRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\nfunction pullRequestClosed(context: FactoryGithubRuleContext) {\n if (!context.item || !context.board || !context.pullRequest || context.pullRequest.merged) return;\n if (unreviewedPullRequestCard(context)) return routedOnly(context, 'pull_request.closed');\n if (!reviewsPullRequest(context)) return;\n if (!isPullRequestCard(context.item)) {\n // An issue card waiting in pull request review on its last open pull request goes back to\n // where its board's cards rest; the issue is still open, and another pull request keeps the\n // review going.\n const initialPhase = context.flow?.initialPhase;\n if (!initialPhase || !attachedPullRequest(context) || !inPullRequestReview(context)) return;\n if (newestOpenPullRequestNumber(context.item, context.pullRequest.number) !== null) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:pull-request-closed`,\n board: context.board,\n stage: initialPhase,\n message: {\n text: `Pull request #${context.pullRequest.number} was closed without merging; this card was moved back to ${initialPhase}.`,\n },\n });\n }\n // A PR closed without merging is abandoned review work: clear the card off\n // the board instead of leaving it in review forever.\n const canceled = context.boardClosure?.canceled ?? context.flow?.canceled;\n if (!canceled) return;\n return pullRequestMoveByRoutes('pull_request.closed', {\n idempotencyKey: `${context.ingress.id}:pull-request-closed`,\n board: context.board,\n stage: canceled.phase,\n message: {\n text:\n `Pull request #${context.pullRequest.number} was closed without merging; ` +\n `this pull request card was moved to ${canceled.title}.`,\n },\n });\n}\n\nfunction reReviewRequestedPullRequest(context: FactoryGithubRuleContext) {\n // GitHub reviewer requests and Factory's exact mention command are both\n // explicit requests to enter the same Review lifecycle.\n const factoryReviewEntry = context.reviewRequest?.factoryReviewer || context.reviewCommand !== undefined;\n if ((context.item && !reviewsPullRequest(context)) || !factoryReviewEntry) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Trusted (write/admin) requesters only: creating or re-entering review checks\n // out and executes PR code, the same bar pullRequestOpened applies to auto-review.\n if (!trustedGithubActor(context)) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n if (!context.item) {\n // On this path the actor is the *requester*, so the materialized\n // `authorTrusted` stamp records their trust (always true past the gate\n // above), not the PR author's: a trusted maintainer requesting a Factory\n // review vouches for the PR.\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,\n autoStartCandidate: true,\n review: true,\n });\n }\n // Already in review with no verdict yet: a pass is pending or running.\n // Once a verdict is recorded the card rests in review, so a fresh request\n // re-enters the phase to start another pass.\n const stage = context.flow?.pullRequestReview;\n if (!context.board || !stage) return;\n const reviewing = inPullRequestReview(context);\n // On an issue card the pass reviews one pull request at a time; a request for another\n // waits until that one is reviewed or settled.\n if (reviewing && !reviewsThisPullRequest(context)) return;\n if (reviewing && !hasRecordedVerdict(context.item)) return;\n return pullRequestMoveByRoutes('pull_request.review_requested', {\n idempotencyKey: `${context.ingress.id}:re-review-requested`,\n board: context.board,\n stage,\n ...(reviewing ? { reenter: true } : {}),\n });\n}\n\nfunction reReviewUpdatedPullRequest(context: FactoryGithubRuleContext) {\n if (!context.item || !context.board || !reviewsPullRequest(context)) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n const stage = context.flow?.pullRequestReview;\n if (!stage) return;\n const reviewing = inPullRequestReview(context);\n // An issue card re-reviews only while its PR review covers this pull request: a push to the\n // builder's own pull request while it builds or self-reviews is the build, not a review cue.\n if (!isPullRequestCard(context.item) && !(reviewing && reviewsThisPullRequest(context))) return;\n // A resting card has not started a review pass yet, so a push there is just\n // more of the code the first pass will read. A push to a card sitting in\n // review is different: it invalidates whatever that pass is reading, so\n // re-enter the phase to supersede it. The phase runner cancels the stale run\n // and the review skill picks the right skill for the entry it sees.\n if (context.phase?.kind === 'resting') return;\n // A fork's author controls its head branch, so an untrusted push must not be\n // able to start review passes on demand; a maintainer can still request one.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n return pullRequestMoveByRoutes('pull_request.synchronized', {\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: context.board,\n stage,\n // Re-entry is the point when the card is already in review: the phase's\n // entry rule is what cancels the superseded pass and starts one on the code\n // that just landed.\n ...(reviewing ? { reenter: true } : {}),\n });\n}\n\nexport const defaultGithubRules = Object.freeze({\n issueOpened: issueOpened,\n // Triage runs once, when a person moves the card into Triage or starts the run; later edits and\n // comments on the issue don't run it again.\n issueEdited: null,\n issueClosed: issueClosed,\n issueReopened: null,\n issueCommentCreated: null,\n issueCommentEdited: null,\n issueCommentDeleted: null,\n pullRequestOpened: pullRequestOpened,\n pullRequestUpdated: reReviewUpdatedPullRequest,\n pullRequestCommentCreated: addressPullRequestComment,\n pullRequestReviewRequested: reReviewRequestedPullRequest,\n pullRequestReviewSubmitted: pullRequestReviewSubmitted,\n pullRequestMerged: pullRequestMerged,\n pullRequestClosed: pullRequestClosed,\n} satisfies GithubEventRules);\n\nexport function resolveGithubRules(overrides?: GithubRuleOverrides): GithubEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitHub rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGithubRuleContext> | null> = { ...defaultGithubRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGithubRules, key)) {\n throw new Error(`Unknown GitHub rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGithubEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitHub rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return recordExplicitRuleOverrides(Object.freeze(rules) as GithubEventRules, overrides);\n}\n"],"mappings":";;;;;;;AA6BA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAEA,SAAS,iBAAiB,SAAsE;CAC9F,OAAO,QAAQ,MAAM,SAAS,WAAW,QAAQ,MAAM,QAAQ,KAAA;AACjE;;;;;AAMA,SAAS,cAAc,SAA4C;CACjE,OACE,QAAQ,MAAM,sBAAsB,KAAA,KAAa,QAAQ,SAAS,KAAA,KAAa,CAAC,kBAAkB,QAAQ,IAAI;AAElH;;AAGA,SAAS,uBAAuB,SAAmC,YAA6B;CAC9F,MAAM,EAAE,MAAM,gBAAgB;CAC9B,MAAM,WAAW,MAAM;CACvB,MAAM,eAAe,UAAU;CAC/B,OACE,MAAM,OAAO,WAAW,KACxB,KAAK,OAAO,OAAO,cACnB,UAAU,sBAAsB,aAChC,OAAO,iBAAiB,YACxB,aAAa,YAAY,KAAA,KACzB,aAAa,YAAY,MAAM,YAAY;AAE/C;;AAGA,SAAS,oBAAoB,SAA4C;CACvE,MAAM,QAAQ,QAAQ,MAAM;CAC5B,OAAO,UAAU,KAAA,KAAa,QAAQ,MAAM,OAAO,WAAW,KAAK,QAAQ,KAAK,OAAO,OAAO;AAChG;;AAGA,SAA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AAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC5E;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,YAAY,EAAE,mBAAmB,EAAE,KAAK,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAElH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,kBAAkB,EAC3B,UAAU,EAAE,kBAAkB,EAC9B,cAAc,CAAC,EAAE,qBAAqB,GACrC,qBAAqB,CA4LvB;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,kBAAkB,EAC3B,UAAU,EAAE,kBAAkB,EAC9B,cAAc,CAAC,EAAE,qBAAqB,GACrC,qBAAqB,GAAG,SAAS,CAKnC"}
1
+ {"version":3,"file":"issue-reconciler.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/issue-reconciler.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAarD,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,2BAA2B;IAC1C,0CAA0C;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAC;IAClB,oFAAoF;IACpF,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,MAAM,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC5E;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,YAAY,EAAE,mBAAmB,EAAE,KAAK,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAElH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,kBAAkB,EAC3B,UAAU,EAAE,kBAAkB,EAC9B,cAAc,CAAC,EAAE,qBAAqB,GACrC,qBAAqB,CA6LvB;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,kBAAkB,EAC3B,UAAU,EAAE,kBAAkB,EAC9B,cAAc,CAAC,EAAE,qBAAqB,GACrC,qBAAqB,GAAG,SAAS,CAKnC"}
@@ -1,5 +1,6 @@
1
1
  import { workItemPhaseSemantics } from "../../boards/semantics.js";
2
2
  import "../../boards/index.js";
3
+ import { toBoardSource } from "../../boards/project-boards.js";
3
4
  import { GithubRules, githubItemSources, githubRulesOptions, reconcilableIssueNumber, reconciledIssueClosedEvent, reconciledIssueOpenedEvent, reconciledIssueRelabeledEvent, sameStrings, sweepTrustLookup } from "./rules.js";
4
5
  // src/integrations/github/issue-reconciler.ts
5
6
  function createGithubIssueReconciler(options, fetchIssue, listOpenIssues) {
@@ -35,6 +36,7 @@ function createGithubIssueReconciler(options, fetchIssue, listOpenIssues) {
35
36
  const itemsByNumber = /* @__PURE__ */ new Map();
36
37
  const carded = /* @__PURE__ */ new Set();
37
38
  for (const project of projects) {
39
+ await rules.loadBoards(project);
38
40
  const items = await options.storage.list({
39
41
  orgId: project.orgId,
40
42
  factoryProjectId: project.factoryProjectId
@@ -43,7 +45,7 @@ function createGithubIssueReconciler(options, fetchIssue, listOpenIssues) {
43
45
  const issueNumber = reconcilableIssueNumber(item, repository);
44
46
  if (!issueNumber) continue;
45
47
  carded.add(issueNumber);
46
- if (workItemPhaseSemantics(options.boards, item)?.kind === "terminal") continue;
48
+ if (workItemPhaseSemantics(toBoardSource(options.boards).forProject(item), item)?.kind === "terminal") continue;
47
49
  let list = itemsByNumber.get(issueNumber);
48
50
  if (!list) {
49
51
  list = [];
@@ -1 +1 @@
1
- {"version":3,"file":"issue-reconciler.js","names":[],"sources":["../../../src/integrations/github/issue-reconciler.ts"],"sourcesContent":["import { workItemPhaseSemantics } from '../../boards/index.js';\nimport type { IntegrationContext } from '../base.js';\nimport {\n githubItemSources,\n githubRulesOptions,\n reconcilableIssueNumber,\n reconciledIssueClosedEvent,\n reconciledIssueOpenedEvent,\n reconciledIssueRelabeledEvent,\n RECONCILE_ERROR_SAMPLE_LIMIT,\n sameStrings,\n sweepTrustLookup,\n GithubRules,\n} from './rules.js';\nimport type {\n GithubIssueFetcher,\n GithubOpenIssueLister,\n GithubRulesIntegration,\n GithubRulesOptions,\n ReconcileRepository,\n} from './rules.js';\n\nexport interface GithubIssueReconcileSummary {\n /** Repositories included in the sweep. */\n repositories: number;\n /** Issue cards whose live state was fetched. */\n checked: number;\n /** Open issues with metadata patches. */\n updated: number;\n /** Closed issues replayed through the rules ingress. */\n closed: number;\n /** Open issues whose changed labels were replayed through the rules ingress. */\n relabeled: number;\n /** Open issues with no Work card replayed as `opened` through the rules ingress. */\n created: number;\n /** Errors encountered during the sweep. */\n failed: number;\n /** Error samples with context. */\n errors: Array<{ repository: string; issueNumber?: number; error: string }>;\n}\n\nexport type GithubIssueReconciler = (repositories: ReconcileRepository[]) => Promise<GithubIssueReconcileSummary>;\n\nexport function createGithubIssueReconciler(\n options: GithubRulesOptions,\n fetchIssue: GithubIssueFetcher,\n listOpenIssues?: GithubOpenIssueLister,\n): GithubIssueReconciler {\n const rules = new GithubRules(options);\n return async repositories => {\n const summary: GithubIssueReconcileSummary = {\n repositories: 0,\n checked: 0,\n updated: 0,\n closed: 0,\n relabeled: 0,\n created: 0,\n failed: 0,\n errors: [],\n };\n const recordFailure = (repository: ReconcileRepository, error: unknown, issueNumber?: number) => {\n summary.failed += 1;\n if (summary.errors.length < RECONCILE_ERROR_SAMPLE_LIMIT) {\n summary.errors.push({\n repository: repository.fullName,\n ...(issueNumber === undefined ? {} : { issueNumber }),\n error: error instanceof Error ? error.message : String(error),\n });\n }\n };\n\n for (const repository of repositories) {\n summary.repositories += 1;\n const authorTrust = sweepTrustLookup(options.github, repository);\n\n try {\n const projects = await options.sourceControl.projectRepositories.listByExternalRepository({\n installationExternalId: String(repository.installationId),\n repositoryExternalId: String(repository.id),\n });\n if (projects.length === 0) continue;\n\n // Collect issue cards: number -> items (skip terminal stages)\n const itemsByNumber = new Map<number, import('../../storage/domains/work-items/base.js').Card[]>();\n // Every issue with any card, terminal included: a finished card must\n // not be re-minted by missed-open discovery.\n const carded = new Set<number>();\n\n for (const project of projects) {\n const items = await options.storage.list({\n orgId: project.orgId,\n factoryProjectId: project.factoryProjectId,\n });\n for (const item of items) {\n const issueNumber = reconcilableIssueNumber(item, repository);\n if (!issueNumber) continue;\n carded.add(issueNumber);\n if (workItemPhaseSemantics(options.boards, item)?.kind === 'terminal') continue;\n let list = itemsByNumber.get(issueNumber);\n if (!list) {\n list = [];\n itemsByNumber.set(issueNumber, list);\n }\n list.push(item);\n }\n }\n\n // Missed-open discovery: an `opened` delivery that never reached the\n // ingress leaves no card for the sweeps above to repair. Only issues\n // filed after the repository was linked are replayed, so linking a\n // repository never backfills its existing backlog.\n if (listOpenIssues) {\n const linkedAt = Math.min(...projects.map(project => project.projectRepository.createdAt.getTime()));\n const openIssues = await listOpenIssues({\n installationId: repository.installationId,\n repository: repository.fullName,\n });\n // A finished card may still be only in the legacy table; copy it so it counts.\n const uncarded = openIssues.filter(issue => !carded.has(issue.number));\n if (uncarded.length && options.storage.legacyBackfillPending) {\n for (const project of projects) {\n await options.storage.copyLegacyCards({\n orgId: project.orgId,\n factoryProjectId: project.factoryProjectId,\n sources: uncarded.flatMap(issue => githubItemSources(repository.id, 'issue', issue.number)),\n });\n const items = await options.storage.list({\n orgId: project.orgId,\n factoryProjectId: project.factoryProjectId,\n });\n for (const item of items) {\n const issueNumber = reconcilableIssueNumber(item, repository);\n if (issueNumber) carded.add(issueNumber);\n }\n }\n }\n for (const issue of openIssues) {\n if (carded.has(issue.number)) continue;\n const createdAt = issue.createdAt ? Date.parse(issue.createdAt) : Number.NaN;\n if (!Number.isFinite(createdAt) || createdAt < linkedAt) continue;\n try {\n const result = await rules.ingest(reconciledIssueOpenedEvent(repository, issue.number, issue));\n if (result.status === 'committed') summary.created += 1;\n } catch (error) {\n recordFailure(repository, error, issue.number);\n }\n }\n }\n\n // Fetch and reconcile each unique issue\n for (const [issueNumber, items] of itemsByNumber) {\n try {\n const state = await fetchIssue({\n installationId: repository.installationId,\n repository: repository.fullName,\n number: issueNumber,\n });\n if (!state) continue; // missing or PR-backed\n summary.checked += 1;\n\n // Close detection: replay through rules ingress\n if (state.state === 'closed') {\n await rules.ingest(reconciledIssueClosedEvent(repository, issueNumber, state));\n summary.closed += 1;\n continue; // card transitions, skip metadata patch\n }\n\n // Metadata sync for open issues\n const desiredMetadata = {\n githubRepositoryId: repository.id,\n githubIssueNumber: issueNumber,\n state: 'open' as const,\n ...(state.author === undefined ? {} : { author: state.author }),\n ...(state.assignees === undefined ? {} : { assignees: state.assignees }),\n ...(state.labels === undefined ? {} : { labels: state.labels }),\n };\n // Re-stamped on every sweep so revoked write access reads untrusted\n // within one cycle; a failed lookup keeps the last stamp and retries.\n let authorTrusted: boolean | undefined;\n if (state.author !== undefined) {\n try {\n authorTrusted = await authorTrust(state.author);\n } catch (error) {\n recordFailure(repository, error, issueNumber);\n }\n }\n\n // Label drift decides where the card belongs, and the rule that owns\n // that decision has to run again — mirrored from the `labeled` /\n // `unlabeled` webhook, replayed here so a label Factory never saw a\n // delivery for still re-places the card. Replayed before the\n // metadata patch, so the ingress sees the drift it acts on.\n if (\n state.labels !== undefined &&\n items.some(\n item => Array.isArray(item.workItem.metadata?.labels) && !sameStrings(item.workItem.labels, state.labels),\n )\n ) {\n await rules.ingest(reconciledIssueRelabeledEvent(repository, issueNumber, state));\n summary.relabeled += 1;\n }\n\n for (const item of items) {\n const current = { ...item.workItem.metadata, ...item.metadata };\n const trustStale = authorTrusted !== undefined && current.authorTrusted !== authorTrusted;\n const metadataChanged =\n trustStale ||\n current.githubRepositoryId !== desiredMetadata.githubRepositoryId ||\n current.githubIssueNumber !== desiredMetadata.githubIssueNumber ||\n current.state !== desiredMetadata.state ||\n (state.author !== undefined && current.author !== state.author) ||\n (state.assignees !== undefined && !sameStrings(current.assignees, state.assignees)) ||\n (state.labels !== undefined && !sameStrings(current.labels, state.labels));\n\n if (!metadataChanged) continue;\n\n await options.storage.syncCard({\n orgId: item.orgId,\n id: item.id,\n userId: 'factory-rule-dispatcher',\n patch: { metadata: { ...desiredMetadata, ...(trustStale ? { authorTrusted } : {}) } },\n });\n summary.updated += 1;\n }\n } catch (error) {\n recordFailure(repository, error, issueNumber);\n }\n }\n } catch (error) {\n recordFailure(repository, error);\n }\n }\n\n return summary;\n };\n}\n\nexport function attachGithubIssueReconciler(\n github: GithubRulesIntegration,\n context: IntegrationContext,\n fetchIssue: GithubIssueFetcher,\n listOpenIssues?: GithubOpenIssueLister,\n): GithubIssueReconciler | undefined {\n if (!context.runtime) return undefined;\n const options = githubRulesOptions(github, context);\n if (!options) return undefined;\n return createGithubIssueReconciler(options, fetchIssue, listOpenIssues);\n}\n"],"mappings":";;;;AA2CA,SAAgB,4BACd,SACA,YACA,gBACuB;CACvB,MAAM,QAAQ,IAAI,YAAY,OAAO;CACrC,OAAO,OAAM,iBAAgB;EAC3B,MAAM,UAAuC;GAC3C,cAAc;GACd,SAAS;GACT,SAAS;GACT,QAAQ;GACR,WAAW;GACX,SAAS;GACT,QAAQ;GACR,QAAQ,CAAC;EACX;EACA,MAAM,iBAAiB,YAAiC,OAAgB,gBAAyB;GAC/F,QAAQ,UAAU;GAClB,IAAI,QAAQ,OAAO,SAAA,GACjB,QAAQ,OAAO,KAAK;IAClB,YAAY,WAAW;IACvB,GAAI,gBAAgB,KAAA,IAAY,CAAC,IAAI,EAAE,Y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,YAAY,KAAK;GACjC;EACF;EAEA,OAAO;CACT;AACF;AAEA,SAAgB,4BACd,QACA,SACA,YACA,gBACmC;CACnC,IAAI,CAAC,QAAQ,SAAS,OAAO,KAAA;CAC7B,MAAM,UAAU,mBAAmB,QAAQ,OAAO;CAClD,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,OAAO,4BAA4B,SAAS,YAAY,cAAc;AACxE"}
1
+ {"version":3,"file":"issue-reconciler.js","names":[],"sources":["../../../src/integrations/github/issue-reconciler.ts"],"sourcesContent":["import { workItemPhaseSemantics } from '../../boards/index.js';\nimport { toBoardSource } from '../../boards/project-boards.js';\nimport type { IntegrationContext } from '../base.js';\nimport {\n githubItemSources,\n githubRulesOptions,\n reconcilableIssueNumber,\n reconciledIssueClosedEvent,\n reconciledIssueOpenedEvent,\n reconciledIssueRelabeledEvent,\n RECONCILE_ERROR_SAMPLE_LIMIT,\n sameStrings,\n sweepTrustLookup,\n GithubRules,\n} from './rules.js';\nimport type {\n GithubIssueFetcher,\n GithubOpenIssueLister,\n GithubRulesIntegration,\n GithubRulesOptions,\n ReconcileRepository,\n} from './rules.js';\n\nexport interface GithubIssueReconcileSummary {\n /** Repositories included in the sweep. */\n repositories: number;\n /** Issue cards whose live state was fetched. */\n checked: number;\n /** Open issues with metadata patches. */\n updated: number;\n /** Closed issues replayed through the rules ingress. */\n closed: number;\n /** Open issues whose changed labels were replayed through the rules ingress. */\n relabeled: number;\n /** Open issues with no Work card replayed as `opened` through the rules ingress. */\n created: number;\n /** Errors encountered during the sweep. */\n failed: number;\n /** Error samples with context. */\n errors: Array<{ repository: string; issueNumber?: number; error: string }>;\n}\n\nexport type GithubIssueReconciler = (repositories: ReconcileRepository[]) => Promise<GithubIssueReconcileSummary>;\n\nexport function createGithubIssueReconciler(\n options: GithubRulesOptions,\n fetchIssue: GithubIssueFetcher,\n listOpenIssues?: GithubOpenIssueLister,\n): GithubIssueReconciler {\n const rules = new GithubRules(options);\n return async repositories => {\n const summary: GithubIssueReconcileSummary = {\n repositories: 0,\n checked: 0,\n updated: 0,\n closed: 0,\n relabeled: 0,\n created: 0,\n failed: 0,\n errors: [],\n };\n const recordFailure = (repository: ReconcileRepository, error: unknown, issueNumber?: number) => {\n summary.failed += 1;\n if (summary.errors.length < RECONCILE_ERROR_SAMPLE_LIMIT) {\n summary.errors.push({\n repository: repository.fullName,\n ...(issueNumber === undefined ? {} : { issueNumber }),\n error: error instanceof Error ? error.message : String(error),\n });\n }\n };\n\n for (const repository of repositories) {\n summary.repositories += 1;\n const authorTrust = sweepTrustLookup(options.github, repository);\n\n try {\n const projects = await options.sourceControl.projectRepositories.listByExternalRepository({\n installationExternalId: String(repository.installationId),\n repositoryExternalId: String(repository.id),\n });\n if (projects.length === 0) continue;\n\n // Collect issue cards: number -> items (skip terminal stages)\n const itemsByNumber = new Map<number, import('../../storage/domains/work-items/base.js').Card[]>();\n // Every issue with any card, terminal included: a finished card must\n // not be re-minted by missed-open discovery.\n const carded = new Set<number>();\n\n for (const project of projects) {\n await rules.loadBoards(project);\n const items = await options.storage.list({\n orgId: project.orgId,\n factoryProjectId: project.factoryProjectId,\n });\n for (const item of items) {\n const issueNumber = reconcilableIssueNumber(item, repository);\n if (!issueNumber) continue;\n carded.add(issueNumber);\n if (workItemPhaseSemantics(toBoardSource(options.boards).forProject(item), item)?.kind === 'terminal') continue;\n let list = itemsByNumber.get(issueNumber);\n if (!list) {\n list = [];\n itemsByNumber.set(issueNumber, list);\n }\n list.push(item);\n }\n }\n\n // Missed-open discovery: an `opened` delivery that never reached the\n // ingress leaves no card for the sweeps above to repair. Only issues\n // filed after the repository was linked are replayed, so linking a\n // repository never backfills its existing backlog.\n if (listOpenIssues) {\n const linkedAt = Math.min(...projects.map(project => project.projectRepository.createdAt.getTime()));\n const openIssues = await listOpenIssues({\n installationId: repository.installationId,\n repository: repository.fullName,\n });\n // A finished card may still be only in the legacy table; copy it so it counts.\n const uncarded = openIssues.filter(issue => !carded.has(issue.number));\n if (uncarded.length && options.storage.legacyBackfillPending) {\n for (const project of projects) {\n await options.storage.copyLegacyCards({\n orgId: project.orgId,\n factoryProjectId: project.factoryProjectId,\n sources: uncarded.flatMap(issue => githubItemSources(repository.id, 'issue', issue.number)),\n });\n const items = await options.storage.list({\n orgId: project.orgId,\n factoryProjectId: project.factoryProjectId,\n });\n for (const item of items) {\n const issueNumber = reconcilableIssueNumber(item, repository);\n if (issueNumber) carded.add(issueNumber);\n }\n }\n }\n for (const issue of openIssues) {\n if (carded.has(issue.number)) continue;\n const createdAt = issue.createdAt ? Date.parse(issue.createdAt) : Number.NaN;\n if (!Number.isFinite(createdAt) || createdAt < linkedAt) continue;\n try {\n const result = await rules.ingest(reconciledIssueOpenedEvent(repository, issue.number, issue));\n if (result.status === 'committed') summary.created += 1;\n } catch (error) {\n recordFailure(repository, error, issue.number);\n }\n }\n }\n\n // Fetch and reconcile each unique issue\n for (const [issueNumber, items] of itemsByNumber) {\n try {\n const state = await fetchIssue({\n installationId: repository.installationId,\n repository: repository.fullName,\n number: issueNumber,\n });\n if (!state) continue; // missing or PR-backed\n summary.checked += 1;\n\n // Close detection: replay through rules ingress\n if (state.state === 'closed') {\n await rules.ingest(reconciledIssueClosedEvent(repository, issueNumber, state));\n summary.closed += 1;\n continue; // card transitions, skip metadata patch\n }\n\n // Metadata sync for open issues\n const desiredMetadata = {\n githubRepositoryId: repository.id,\n githubIssueNumber: issueNumber,\n state: 'open' as const,\n ...(state.author === undefined ? {} : { author: state.author }),\n ...(state.assignees === undefined ? {} : { assignees: state.assignees }),\n ...(state.labels === undefined ? {} : { labels: state.labels }),\n };\n // Re-stamped on every sweep so revoked write access reads untrusted\n // within one cycle; a failed lookup keeps the last stamp and retries.\n let authorTrusted: boolean | undefined;\n if (state.author !== undefined) {\n try {\n authorTrusted = await authorTrust(state.author);\n } catch (error) {\n recordFailure(repository, error, issueNumber);\n }\n }\n\n // Label drift decides where the card belongs, and the rule that owns\n // that decision has to run again — mirrored from the `labeled` /\n // `unlabeled` webhook, replayed here so a label Factory never saw a\n // delivery for still re-places the card. Replayed before the\n // metadata patch, so the ingress sees the drift it acts on.\n if (\n state.labels !== undefined &&\n items.some(\n item => Array.isArray(item.workItem.metadata?.labels) && !sameStrings(item.workItem.labels, state.labels),\n )\n ) {\n await rules.ingest(reconciledIssueRelabeledEvent(repository, issueNumber, state));\n summary.relabeled += 1;\n }\n\n for (const item of items) {\n const current = { ...item.workItem.metadata, ...item.metadata };\n const trustStale = authorTrusted !== undefined && current.authorTrusted !== authorTrusted;\n const metadataChanged =\n trustStale ||\n current.githubRepositoryId !== desiredMetadata.githubRepositoryId ||\n current.githubIssueNumber !== desiredMetadata.githubIssueNumber ||\n current.state !== desiredMetadata.state ||\n (state.author !== undefined && current.author !== state.author) ||\n (state.assignees !== undefined && !sameStrings(current.assignees, state.assignees)) ||\n (state.labels !== undefined && !sameStrings(current.labels, state.labels));\n\n if (!metadataChanged) continue;\n\n await options.storage.syncCard({\n orgId: item.orgId,\n id: item.id,\n userId: 'factory-rule-dispatcher',\n patch: { metadata: { ...desiredMetadata, ...(trustStale ? { authorTrusted } : {}) } },\n });\n summary.updated += 1;\n }\n } catch (error) {\n recordFailure(repository, error, issueNumber);\n }\n }\n } catch (error) {\n recordFailure(repository, error);\n }\n }\n\n return summary;\n };\n}\n\nexport function attachGithubIssueReconciler(\n github: GithubRulesIntegration,\n context: IntegrationContext,\n fetchIssue: GithubIssueFetcher,\n listOpenIssues?: GithubOpenIssueLister,\n): GithubIssueReconciler | undefined {\n if (!context.runtime) return undefined;\n const options = githubRulesOptions(github, context);\n if (!options) return undefined;\n return createGithubIssueReconciler(options, fetchIssue, listOpenIssues);\n}\n"],"mappings":";;;;;AA4CA,SAAgB,4BACd,SACA,YACA,gBACuB;CACvB,MAAM,QAAQ,IAAI,YAAY,OAAO;CACrC,OAAO,OAAM,iBAAgB;EAC3B,MAAM,UAAuC;GAC3C,cAAc;GACd,SAAS;GACT,SAAS;GACT,QAAQ;GACR,WAAW;GACX,SAA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;MAEtB,MAAM,QAAQ,QAAQ,SAAS;OAC7B,OAAO,KAAK;OACZ,IAAI,KAAK;OACT,QAAQ;OACR,OAAO,EAAE,UAAU;QAAE,GAAG;QAAiB,GAAI,aAAa,EAAE,cAAc,IAAI,CAAC;OAAG,EAAE;MACtF,CAAC;MACD,QAAQ,WAAW;KACrB;IACF,SAAS,OAAO;KACd,cAAc,YAAY,OAAO,WAAW;IAC9C;GAEJ,SAAS,OAAO;IACd,cAAc,YAAY,KAAK;GACjC;EACF;EAEA,OAAO;CACT;AACF;AAEA,SAAgB,4BACd,QACA,SACA,YACA,gBACmC;CACnC,IAAI,CAAC,QAAQ,SAAS,OAAO,KAAA;CAC7B,MAAM,UAAU,mBAAmB,QAAQ,OAAO;CAClD,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,OAAO,4BAA4B,SAAS,YAAY,cAAc;AACxE"}
@@ -0,0 +1,8 @@
1
+ import type { WorkItemSourceRow } from '../../storage/domains/work-items/work-item-schema.js';
2
+ /**
3
+ * Whether a card's source row is pull request `pullRequestNumber` of this repository. Numbers
4
+ * repeat across repositories, so the row's URL, or the repository id stamped on it, must name
5
+ * this repository as well.
6
+ */
7
+ export declare function isRepositoryPullRequest(source: WorkItemSourceRow, repositoryId: number, repositoryFullName: string, pullRequestNumber: number): boolean;
8
+ //# sourceMappingURL=pull-request-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull-request-source.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/pull-request-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sDAAsD,CAAC;AAE9F;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,iBAAiB,EACzB,YAAY,EAAE,MAAM,EACpB,kBAAkB,EAAE,MAAM,EAC1B,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAQT"}
@@ -0,0 +1,17 @@
1
+ import { sourceExternalId } from "../../boards/semantics.js";
2
+ // src/integrations/github/pull-request-source.ts
3
+ /**
4
+ * Whether a card's source row is pull request `pullRequestNumber` of this repository. Numbers
5
+ * repeat across repositories, so the row's URL, or the repository id stamped on it, must name
6
+ * this repository as well.
7
+ */
8
+ function isRepositoryPullRequest(source, repositoryId, repositoryFullName, pullRequestNumber) {
9
+ if (source.integrationId !== "github" || source.sourceType !== "pull-request") return false;
10
+ const key = sourceExternalId(source);
11
+ if (key !== `github-pr:${pullRequestNumber}` && key !== `github:${repositoryId}:pull-request:${pullRequestNumber}`) return false;
12
+ const match = source.url ? /^https?:\/\/[^/]+\/(.+)\/pull\/\d+(?:[/?#]|$)/.exec(source.url) : null;
13
+ return match ? match[1] === repositoryFullName : source.metadata?.githubRepositoryId === repositoryId;
14
+ }
15
+ export { isRepositoryPullRequest };
16
+
17
+ //# sourceMappingURL=pull-request-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull-request-source.js","names":[],"sources":["../../../src/integrations/github/pull-request-source.ts"],"sourcesContent":["import { sourceExternalId } from '../../boards/semantics.js';\nimport type { WorkItemSourceRow } from '../../storage/domains/work-items/work-item-schema.js';\n\n/**\n * Whether a card's source row is pull request `pullRequestNumber` of this repository. Numbers\n * repeat across repositories, so the row's URL, or the repository id stamped on it, must name\n * this repository as well.\n */\nexport function isRepositoryPullRequest(\n source: WorkItemSourceRow,\n repositoryId: number,\n repositoryFullName: string,\n pullRequestNumber: number,\n): boolean {\n if (source.integrationId !== 'github' || source.sourceType !== 'pull-request') return false;\n const key = sourceExternalId(source);\n if (key !== `github-pr:${pullRequestNumber}` && key !== `github:${repositoryId}:pull-request:${pullRequestNumber}`) {\n return false;\n }\n const match = source.url ? /^https?:\\/\\/[^/]+\\/(.+)\\/pull\\/\\d+(?:[/?#]|$)/.exec(source.url) : null;\n return match ? match[1] === repositoryFullName : source.metadata?.githubRepositoryId === repositoryId;\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,wBACd,QACA,cACA,oBACA,mBACS;CACT,IAAI,OAAO,kBAAkB,YAAY,OAAO,eAAe,gBAAgB,OAAO;CACtF,MAAM,MAAM,iBAAiB,MAAM;CACnC,IAAI,QAAQ,aAAa,uBAAuB,QAAQ,UAAU,aAAa,gBAAgB,qBAC7F,OAAO;CAET,MAAM,QAAQ,OAAO,MAAM,gDAAgD,KAAK,OAAO,GAAG,IAAI;CAC9F,OAAO,QAAQ,MAAM,OAAO,qBAAqB,OAAO,UAAU,uBAAuB;AAC3F"}