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

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 (315) hide show
  1. package/README.md +119 -60
  2. package/dist/boards/board-events.d.ts +89 -9
  3. package/dist/boards/board-events.d.ts.map +1 -1
  4. package/dist/boards/board-events.js +176 -13
  5. package/dist/boards/board-events.js.map +1 -1
  6. package/dist/boards/board-writes.d.ts.map +1 -1
  7. package/dist/boards/board-writes.js +14 -1
  8. package/dist/boards/board-writes.js.map +1 -1
  9. package/dist/boards/busy-card.d.ts +11 -0
  10. package/dist/boards/busy-card.d.ts.map +1 -0
  11. package/dist/boards/busy-card.js +15 -0
  12. package/dist/boards/busy-card.js.map +1 -0
  13. package/dist/boards/card-facts.d.ts.map +1 -1
  14. package/dist/boards/card-facts.js +18 -4
  15. package/dist/boards/card-facts.js.map +1 -1
  16. package/dist/boards/index.d.ts +2 -1
  17. package/dist/boards/index.d.ts.map +1 -1
  18. package/dist/boards/index.js +3 -2
  19. package/dist/boards/intake-dry-run.d.ts +109 -0
  20. package/dist/boards/intake-dry-run.d.ts.map +1 -0
  21. package/dist/boards/intake-dry-run.js +158 -0
  22. package/dist/boards/intake-dry-run.js.map +1 -0
  23. package/dist/boards/intake-lookup.d.ts +32 -0
  24. package/dist/boards/intake-lookup.d.ts.map +1 -0
  25. package/dist/boards/intake-lookup.js +12 -0
  26. package/dist/boards/intake-lookup.js.map +1 -0
  27. package/dist/boards/intake-order.d.ts +32 -0
  28. package/dist/boards/intake-order.d.ts.map +1 -0
  29. package/dist/boards/intake-order.js +60 -0
  30. package/dist/boards/intake-order.js.map +1 -0
  31. package/dist/boards/intake-routing.d.ts +246 -35
  32. package/dist/boards/intake-routing.d.ts.map +1 -1
  33. package/dist/boards/intake-routing.js +437 -52
  34. package/dist/boards/intake-routing.js.map +1 -1
  35. package/dist/boards/reroute.d.ts +7 -3
  36. package/dist/boards/reroute.d.ts.map +1 -1
  37. package/dist/boards/reroute.js +21 -4
  38. package/dist/boards/reroute.js.map +1 -1
  39. package/dist/boards/semantics.d.ts +8 -28
  40. package/dist/boards/semantics.d.ts.map +1 -1
  41. package/dist/boards/semantics.js +7 -39
  42. package/dist/boards/semantics.js.map +1 -1
  43. package/dist/boards/work-routes.d.ts +31 -11
  44. package/dist/boards/work-routes.d.ts.map +1 -1
  45. package/dist/boards/work-routes.js +104 -20
  46. package/dist/boards/work-routes.js.map +1 -1
  47. package/dist/factory.d.ts +27 -1
  48. package/dist/factory.d.ts.map +1 -1
  49. package/dist/factory.js +31 -9
  50. package/dist/factory.js.map +1 -1
  51. package/dist/integrations/base.d.ts +9 -0
  52. package/dist/integrations/base.d.ts.map +1 -1
  53. package/dist/integrations/dependabot/rules.js +1 -1
  54. package/dist/integrations/dependabot/rules.js.map +1 -1
  55. package/dist/integrations/github/default-rules.d.ts +22 -1
  56. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  57. package/dist/integrations/github/default-rules.js +23 -5
  58. package/dist/integrations/github/default-rules.js.map +1 -1
  59. package/dist/integrations/github/intake-lookup.d.ts +16 -0
  60. package/dist/integrations/github/intake-lookup.d.ts.map +1 -0
  61. package/dist/integrations/github/intake-lookup.js +76 -0
  62. package/dist/integrations/github/intake-lookup.js.map +1 -0
  63. package/dist/integrations/github/integration.d.ts +19 -5
  64. package/dist/integrations/github/integration.d.ts.map +1 -1
  65. package/dist/integrations/github/integration.js +21 -6
  66. package/dist/integrations/github/integration.js.map +1 -1
  67. package/dist/integrations/github/review-status-reporter.js +1 -1
  68. package/dist/integrations/github/routes.d.ts.map +1 -1
  69. package/dist/integrations/github/routes.js +14 -2
  70. package/dist/integrations/github/routes.js.map +1 -1
  71. package/dist/integrations/github/rules.d.ts +12 -1
  72. package/dist/integrations/github/rules.d.ts.map +1 -1
  73. package/dist/integrations/github/rules.js +218 -30
  74. package/dist/integrations/github/rules.js.map +1 -1
  75. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  76. package/dist/integrations/github/sandbox.js +30 -4
  77. package/dist/integrations/github/sandbox.js.map +1 -1
  78. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  79. package/dist/integrations/gitlab/default-rules.js +19 -3
  80. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  81. package/dist/integrations/gitlab/intake-lookup.d.ts +17 -0
  82. package/dist/integrations/gitlab/intake-lookup.d.ts.map +1 -0
  83. package/dist/integrations/gitlab/intake-lookup.js +85 -0
  84. package/dist/integrations/gitlab/intake-lookup.js.map +1 -0
  85. package/dist/integrations/gitlab/integration.d.ts +5 -0
  86. package/dist/integrations/gitlab/integration.d.ts.map +1 -1
  87. package/dist/integrations/gitlab/integration.js +21 -1
  88. package/dist/integrations/gitlab/integration.js.map +1 -1
  89. package/dist/integrations/gitlab/rules.d.ts +20 -0
  90. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  91. package/dist/integrations/gitlab/rules.js +108 -12
  92. package/dist/integrations/gitlab/rules.js.map +1 -1
  93. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  94. package/dist/integrations/incidentio/rules.js +14 -4
  95. package/dist/integrations/incidentio/rules.js.map +1 -1
  96. package/dist/integrations/jira/rules.d.ts.map +1 -1
  97. package/dist/integrations/jira/rules.js +12 -2
  98. package/dist/integrations/jira/rules.js.map +1 -1
  99. package/dist/integrations/linear/rules.d.ts.map +1 -1
  100. package/dist/integrations/linear/rules.js +13 -2
  101. package/dist/integrations/linear/rules.js.map +1 -1
  102. package/dist/integrations/platform/github/event-worker.js +9 -1
  103. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  104. package/dist/integrations/platform/github/integration.d.ts +6 -6
  105. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  106. package/dist/integrations/platform/github/integration.js +22 -3
  107. package/dist/integrations/platform/github/integration.js.map +1 -1
  108. package/dist/integrations/pull-request-head.d.ts +1 -1
  109. package/dist/integrations/pull-request-head.d.ts.map +1 -1
  110. package/dist/integrations/pull-request-head.js +5 -0
  111. package/dist/integrations/pull-request-head.js.map +1 -1
  112. package/dist/integrations/vanta/rules.js +1 -1
  113. package/dist/integrations/vanta/rules.js.map +1 -1
  114. package/dist/routes/board-snapshot.d.ts +8 -1
  115. package/dist/routes/board-snapshot.d.ts.map +1 -1
  116. package/dist/routes/board-snapshot.js +33 -7
  117. package/dist/routes/board-snapshot.js.map +1 -1
  118. package/dist/routes/boards.js.map +1 -1
  119. package/dist/routes/config.d.ts +6 -0
  120. package/dist/routes/config.d.ts.map +1 -1
  121. package/dist/routes/config.js +5 -2
  122. package/dist/routes/config.js.map +1 -1
  123. package/dist/routes/contracts.d.ts +1258 -0
  124. package/dist/routes/contracts.d.ts.map +1 -1
  125. package/dist/routes/contracts.js +586 -13
  126. package/dist/routes/contracts.js.map +1 -1
  127. package/dist/routes/intake-check.d.ts +92 -0
  128. package/dist/routes/intake-check.d.ts.map +1 -0
  129. package/dist/routes/intake-check.js +322 -0
  130. package/dist/routes/intake-check.js.map +1 -0
  131. package/dist/routes/intake-routes.d.ts +10 -2
  132. package/dist/routes/intake-routes.d.ts.map +1 -1
  133. package/dist/routes/intake-routes.js +292 -11
  134. package/dist/routes/intake-routes.js.map +1 -1
  135. package/dist/routes/mastra-gateway.d.ts.map +1 -1
  136. package/dist/routes/mastra-gateway.js +3 -2
  137. package/dist/routes/mastra-gateway.js.map +1 -1
  138. package/dist/routes/project-sessions.d.ts +49 -0
  139. package/dist/routes/project-sessions.d.ts.map +1 -0
  140. package/dist/routes/project-sessions.js +93 -0
  141. package/dist/routes/project-sessions.js.map +1 -0
  142. package/dist/routes/run-queue.d.ts +6 -6
  143. package/dist/routes/run-queue.d.ts.map +1 -1
  144. package/dist/routes/run-queue.js +28 -8
  145. package/dist/routes/run-queue.js.map +1 -1
  146. package/dist/routes/session-rows.d.ts +30 -0
  147. package/dist/routes/session-rows.d.ts.map +1 -0
  148. package/dist/routes/session-rows.js +98 -0
  149. package/dist/routes/session-rows.js.map +1 -0
  150. package/dist/routes/source-control-sessions.d.ts +4 -5
  151. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  152. package/dist/routes/source-control-sessions.js +8 -87
  153. package/dist/routes/source-control-sessions.js.map +1 -1
  154. package/dist/routes/surface.d.ts +13 -1
  155. package/dist/routes/surface.d.ts.map +1 -1
  156. package/dist/routes/surface.js +24 -26
  157. package/dist/routes/surface.js.map +1 -1
  158. package/dist/routes/work-item-starters.d.ts +1 -0
  159. package/dist/routes/work-item-starters.d.ts.map +1 -1
  160. package/dist/routes/work-item-starters.js +14 -2
  161. package/dist/routes/work-item-starters.js.map +1 -1
  162. package/dist/routes/work-items.d.ts +13 -0
  163. package/dist/routes/work-items.d.ts.map +1 -1
  164. package/dist/routes/work-items.js +87 -34
  165. package/dist/routes/work-items.js.map +1 -1
  166. package/dist/rules/dispatch-errors.js +1 -1
  167. package/dist/rules/dispatch-errors.js.map +1 -1
  168. package/dist/rules/dispatcher.d.ts +39 -7
  169. package/dist/rules/dispatcher.d.ts.map +1 -1
  170. package/dist/rules/dispatcher.js +361 -122
  171. package/dist/rules/dispatcher.js.map +1 -1
  172. package/dist/rules/event-rules.d.ts +69 -1
  173. package/dist/rules/event-rules.d.ts.map +1 -1
  174. package/dist/rules/event-rules.js +151 -5
  175. package/dist/rules/event-rules.js.map +1 -1
  176. package/dist/rules/review-source-tool.js +1 -1
  177. package/dist/rules/rule-group.d.ts +18 -1
  178. package/dist/rules/rule-group.d.ts.map +1 -1
  179. package/dist/rules/rule-group.js +52 -8
  180. package/dist/rules/rule-group.js.map +1 -1
  181. package/dist/rules/run-bearing.d.ts +8 -0
  182. package/dist/rules/run-bearing.d.ts.map +1 -0
  183. package/dist/rules/run-bearing.js +11 -0
  184. package/dist/rules/run-bearing.js.map +1 -0
  185. package/dist/rules/start-coordinator.d.ts +2 -3
  186. package/dist/rules/start-coordinator.d.ts.map +1 -1
  187. package/dist/rules/start-coordinator.js +26 -34
  188. package/dist/rules/start-coordinator.js.map +1 -1
  189. package/dist/rules/tools.js +2 -1
  190. package/dist/rules/tools.js.map +1 -1
  191. package/dist/rules/transition-service.d.ts +16 -0
  192. package/dist/rules/transition-service.d.ts.map +1 -1
  193. package/dist/rules/transition-service.js +34 -10
  194. package/dist/rules/transition-service.js.map +1 -1
  195. package/dist/rules/types.d.ts +18 -5
  196. package/dist/rules/types.d.ts.map +1 -1
  197. package/dist/rules/types.js +2 -1
  198. package/dist/rules/types.js.map +1 -1
  199. package/dist/rules/update-fold.d.ts +32 -0
  200. package/dist/rules/update-fold.d.ts.map +1 -0
  201. package/dist/rules/update-fold.js +60 -0
  202. package/dist/rules/update-fold.js.map +1 -0
  203. package/dist/rules/validation.d.ts.map +1 -1
  204. package/dist/rules/validation.js +54 -6
  205. package/dist/rules/validation.js.map +1 -1
  206. package/dist/session/resource-migration.d.ts.map +1 -1
  207. package/dist/session/resource-migration.js +2 -3
  208. package/dist/session/resource-migration.js.map +1 -1
  209. package/dist/session/run-audit.d.ts +9 -0
  210. package/dist/session/run-audit.d.ts.map +1 -1
  211. package/dist/session/run-audit.js +9 -1
  212. package/dist/session/run-audit.js.map +1 -1
  213. package/dist/session/self-review-gate.d.ts +26 -2
  214. package/dist/session/self-review-gate.d.ts.map +1 -1
  215. package/dist/session/self-review-gate.js +60 -10
  216. package/dist/session/self-review-gate.js.map +1 -1
  217. package/dist/session/session-row-query.d.ts +25 -0
  218. package/dist/session/session-row-query.d.ts.map +1 -0
  219. package/dist/session/session-row-query.js +47 -0
  220. package/dist/session/session-row-query.js.map +1 -0
  221. package/dist/session/session-row-status.d.ts +16 -0
  222. package/dist/session/session-row-status.d.ts.map +1 -0
  223. package/dist/session/session-row-status.js +14 -0
  224. package/dist/session/session-row-status.js.map +1 -0
  225. package/dist/session/session-row-view.d.ts +14 -0
  226. package/dist/session/session-row-view.d.ts.map +1 -0
  227. package/dist/session/session-row-view.js +125 -0
  228. package/dist/session/session-row-view.js.map +1 -0
  229. package/dist/session/session-rows.d.ts +46 -0
  230. package/dist/session/session-rows.d.ts.map +1 -0
  231. package/dist/session/session-rows.js +232 -0
  232. package/dist/session/session-rows.js.map +1 -0
  233. package/dist/session/session-threads.d.ts.map +1 -1
  234. package/dist/session/session-threads.js +1 -0
  235. package/dist/session/session-threads.js.map +1 -1
  236. package/dist/session/source-control-tools.d.ts +14 -7
  237. package/dist/session/source-control-tools.d.ts.map +1 -1
  238. package/dist/session/source-control-tools.js +10 -2
  239. package/dist/session/source-control-tools.js.map +1 -1
  240. package/dist/session/work-item-repository.d.ts +44 -0
  241. package/dist/session/work-item-repository.d.ts.map +1 -1
  242. package/dist/session/work-item-repository.js +80 -1
  243. package/dist/session/work-item-repository.js.map +1 -1
  244. package/dist/session/work-item-state-processor.d.ts.map +1 -1
  245. package/dist/session/work-item-state-processor.js +44 -8
  246. package/dist/session/work-item-state-processor.js.map +1 -1
  247. package/dist/storage/domains/audit/actions.d.ts +2 -1
  248. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  249. package/dist/storage/domains/audit/actions.js +3 -1
  250. package/dist/storage/domains/audit/actions.js.map +1 -1
  251. package/dist/storage/domains/boards/base.d.ts +162 -14
  252. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  253. package/dist/storage/domains/boards/base.js +415 -41
  254. package/dist/storage/domains/boards/base.js.map +1 -1
  255. package/dist/storage/domains/boards/schemas.d.ts +6 -0
  256. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  257. package/dist/storage/domains/boards/schemas.js +95 -1
  258. package/dist/storage/domains/boards/schemas.js.map +1 -1
  259. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  260. package/dist/storage/domains/projects/base.js +19 -10
  261. package/dist/storage/domains/projects/base.js.map +1 -1
  262. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  263. package/dist/storage/domains/source-control/base.js +5 -2
  264. package/dist/storage/domains/source-control/base.js.map +1 -1
  265. package/dist/storage/domains/work-items/base.d.ts +48 -17
  266. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  267. package/dist/storage/domains/work-items/base.js +128 -75
  268. package/dist/storage/domains/work-items/base.js.map +1 -1
  269. package/dist/storage/domains/work-items/cards.d.ts +3 -2
  270. package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
  271. package/dist/storage/domains/work-items/cards.js +4 -2
  272. package/dist/storage/domains/work-items/cards.js.map +1 -1
  273. package/dist/storage/probed-list.d.ts +11 -0
  274. package/dist/storage/probed-list.d.ts.map +1 -0
  275. package/dist/storage/probed-list.js +52 -0
  276. package/dist/storage/probed-list.js.map +1 -0
  277. package/dist/tools/audit-events-tool.d.ts +2 -2
  278. package/dist/tools/read-tools.d.ts +0 -3
  279. package/dist/tools/read-tools.d.ts.map +1 -1
  280. package/dist/tools/read-tools.js +4 -42
  281. package/dist/tools/read-tools.js.map +1 -1
  282. package/dist/tools/session-tools.d.ts.map +1 -1
  283. package/dist/tools/session-tools.js +5 -9
  284. package/dist/tools/session-tools.js.map +1 -1
  285. package/dist/tools/work-item-tools.d.ts +3 -0
  286. package/dist/tools/work-item-tools.d.ts.map +1 -1
  287. package/dist/tools/work-item-tools.js +8 -4
  288. package/dist/tools/work-item-tools.js.map +1 -1
  289. package/dist/work-item-branch.d.ts +4 -0
  290. package/dist/work-item-branch.d.ts.map +1 -1
  291. package/dist/work-item-branch.js +7 -1
  292. package/dist/work-item-branch.js.map +1 -1
  293. package/dist/work-items/card-context-sessions.d.ts +50 -0
  294. package/dist/work-items/card-context-sessions.d.ts.map +1 -0
  295. package/dist/work-items/card-context-sessions.js +84 -0
  296. package/dist/work-items/card-context-sessions.js.map +1 -0
  297. package/dist/work-items/change-requests.d.ts +87 -0
  298. package/dist/work-items/change-requests.d.ts.map +1 -0
  299. package/dist/work-items/change-requests.js +134 -0
  300. package/dist/work-items/change-requests.js.map +1 -0
  301. package/dist/work-items/create-work-item.d.ts +7 -2
  302. package/dist/work-items/create-work-item.d.ts.map +1 -1
  303. package/dist/work-items/create-work-item.js +44 -13
  304. package/dist/work-items/create-work-item.js.map +1 -1
  305. package/dist/work-items/list-related-cards.d.ts.map +1 -1
  306. package/dist/work-items/list-related-cards.js +1 -1
  307. package/dist/work-items/list-related-cards.js.map +1 -1
  308. package/dist/work-items/providers/github.d.ts.map +1 -1
  309. package/dist/work-items/providers/github.js +1 -0
  310. package/dist/work-items/providers/github.js.map +1 -1
  311. package/factory-skills/factory-build/SKILL.md +1 -1
  312. package/factory-skills/factory-plan/SKILL.md +5 -3
  313. package/factory-skills/factory-self-review/SKILL.md +2 -0
  314. package/factory-skills/factory-triage/SKILL.md +1 -1
  315. package/package.json +8 -8
@@ -25,10 +25,12 @@ import type { FactoryStorage } from '@mastra/core/storage';
25
25
  import type { MastraWorker } from '@mastra/core/worker';
26
26
  import type { FactorySandbox } from '@mastra/core/workspace';
27
27
  import type { BoardRegistry } from '../boards/index.js';
28
+ import type { IntakeItemLookup } from '../boards/intake-lookup.js';
28
29
  import type { ProjectBoardSource } from '../boards/project-boards.js';
29
30
  import type { Intake } from '../capabilities/intake.js';
30
31
  import type { VersionControl } from '../capabilities/version-control.js';
31
32
  import type { RouteAuth } from '../routes/route.js';
33
+ import type { NotRoutedLookup } from '../rules/event-rules.js';
32
34
  import type { SessionRetirementCoordinator } from '../sandbox/session-retirement.js';
33
35
  import type { StateSigner } from '../state-signing.js';
34
36
  import type { AuditEventRow } from '../storage/domains/audit/base.js';
@@ -169,6 +171,11 @@ export interface IntegrationContext {
169
171
  * Absent where no sweep runs (route contexts, tests).
170
172
  */
171
173
  keptCards?: CardSource;
174
+ /**
175
+ * Which items intake turned away (Not routed), so a label or assignee change to one runs intake
176
+ * again. Absent where the boards domain isn't available.
177
+ */
178
+ notRouted?: NotRoutedLookup;
172
179
  };
173
180
  /** System hooks integrations may invoke. */
174
181
  hooks?: IntegrationHooks;
@@ -221,6 +228,8 @@ export interface FactoryIntegration {
221
228
  }>;
222
229
  /** Repository, installation, and pull-request capability. */
223
230
  readonly versionControl?: VersionControl;
231
+ /** Reads one item by URL from a source linked to a project, for the intake tester. */
232
+ readonly intakeLookup?: IntakeItemLookup;
224
233
  /** Whether at least one account is connected, for the dev-server startup summary. */
225
234
  hasActiveConnections?(): Promise<boolean>;
226
235
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/integrations/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAChH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,KAAK,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AC,CAAC;IACrH;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,YAAY,EAAE,CAAC;IAClD;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,CAAC,GAAG,EAAE,kBAAkB,GAAG,qBAAqB,CAAC;IAC1D;;;OAGG;IACH,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC;;;OAGG;IACH,KAAK,CAAC,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,aAAa,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD;;;;;OAKG;IACH,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,CAAC;CAC9C"}
@@ -24,7 +24,7 @@ function boardEventFor(context) {
24
24
  type: "work_item.closed",
25
25
  reason: closeReason(context.alert.state !== "fixed")
26
26
  };
27
- return context.item ? { type: "work_item.reopened" } : { type: "work_item.created" };
27
+ return context.item ? { type: "work_item.reopened" } : { type: "work_item.opened" };
28
28
  }
29
29
  var DependabotRules = class {
30
30
  options;
@@ -1 +1 @@
1
- {"version":3,"file":"rules.js","names":[],"sources":["../../../src/integrations/dependabot/rules.ts"],"sourcesContent":["import { closeReason } from '../../boards/board-events.js';\nimport type { BoardEventFacts } from '../../boards/board-events.js';\nimport { boardForWorkItem, rulePhaseField, withBoardClosure, withIntakeTarget } from '../../boards/index.js';\nimport type { BoardRegistry } from '../../boards/index.js';\nimport { toBoardSource } from '../../boards/project-boards.js';\nimport type { ProjectBoardSource } from '../../boards/project-boards.js';\nimport { routeEventDecision } from '../../rules/event-rules.js';\nimport type { FactoryDependabotRuleContext, FactoryRuleDecision } from '../../rules/types.js';\nimport { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from '../../rules/validation.js';\nimport type { StoredBoardScope } from '../../storage/domains/boards/base.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { Card, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { IntegrationContext } from '../base.js';\nimport { defaultDependabotRules, isClosedDependabotState } from './default-rules.js';\nimport type { DependabotEventRules } from './default-rules.js';\n\nconst MAX_STALE_RULE_ATTEMPTS = 3;\n\n/** Labels every Dependabot card carries, so intake routes can match them like any labeled issue. */\nexport function dependabotLabels(severity: string | null): string[] {\n return ['security', 'dependabot', ...(severity ? [`severity:${severity}`] : [])];\n}\n\nexport type DependabotAlertIngress = FactoryDependabotRuleContext['alert'];\n\nexport interface DependabotRulesOptions {\n projects: Pick<FactoryProjectsStorage, 'get'>;\n storage: WorkItemsStorage;\n configVersion: string;\n boards: BoardRegistry | ProjectBoardSource;\n rules?: DependabotEventRules;\n}\n\nexport interface DependabotRulesIngress {\n orgId: string;\n userId: string;\n factoryProjectId: string;\n alerts: DependabotAlertIngress[];\n}\n\ntype IngressStatus = 'committed' | 'replayed' | 'missing';\n\n/**\n * A first sighting of an open alert creates its card; a fixed or dismissed one closes it. An open\n * alert that already has a card reopens it, which the intake routes apply only to a finished card.\n */\nexport function boardEventFor(\n context: Pick<FactoryDependabotRuleContext, 'event' | 'alert' | 'item'>,\n): BoardEventFacts | undefined {\n if (context.event === 'alertClosed') {\n return { type: 'work_item.closed', reason: closeReason(context.alert.state !== 'fixed') };\n }\n return context.item ? { type: 'work_item.reopened' } : { type: 'work_item.created' };\n}\n\nexport class DependabotRules {\n readonly #rules: DependabotEventRules;\n\n constructor(private readonly options: DependabotRulesOptions) {\n this.#rules = options.rules ?? defaultDependabotRules;\n }\n\n #boards(scope: StoredBoardScope): BoardRegistry {\n return toBoardSource(this.options.boards).forProject(scope);\n }\n\n async ingest(input: DependabotRulesIngress): Promise<{ status: IngressStatus; ingested: number }> {\n const project = await this.options.projects.get({ orgId: input.orgId, id: input.factoryProjectId });\n if (!project) return { status: 'missing', ingested: 0 };\n await toBoardSource(this.options.boards).load(input);\n\n const items = await this.options.storage.listShared({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n const itemsBySourceKey = new Map(\n items\n .filter(\n item => item.externalSource?.integrationId === 'github' && item.externalSource.type === 'dependabot-alert',\n )\n .map(item => [item.externalSource?.externalId, item]),\n );\n const statuses: IngressStatus[] = [];\n for (const alert of input.alerts) {\n const relatedItem = itemsBySourceKey.get(alert.id);\n statuses.push(await this.#ingestAlert(input, alert, relatedItem && structuredClone(relatedItem)));\n }\n if (statuses.includes('committed')) return { status: 'committed', ingested: statuses.length };\n if (statuses.includes('replayed')) return { status: 'replayed', ingested: statuses.length };\n return { status: 'missing', ingested: statuses.length };\n }\n\n async #ingestAlert(\n input: DependabotRulesIngress,\n alert: DependabotAlertIngress,\n relatedItem: Card | undefined,\n attempt = 1,\n ): Promise<IngressStatus> {\n const closed = isClosedDependabotState(alert.state);\n // A closed alert Factory never filed stays off the board.\n if (closed && !relatedItem) return 'missing';\n\n const ingressId = `dependabot:${alert.id}:${alert.state}:${alert.updatedAt}`;\n const actor = { type: 'human' as const, id: input.userId };\n const event = closed ? 'alertClosed' : 'alertObserved';\n const boards = this.#boards(input);\n const context: FactoryDependabotRuleContext = {\n tenant: { orgId: input.orgId, projectId: input.factoryProjectId },\n actor,\n ingress: { type: 'github', id: ingressId },\n cause: `dependabot.${event}`,\n causalChain: [],\n configVersion: this.options.configVersion,\n ...(relatedItem\n ? {\n item: {\n id: relatedItem.id,\n source: 'github-dependabot-alert',\n sourceKey: relatedItem.externalSource?.externalId ?? null,\n parentWorkItemId: relatedItem.parentWorkItemId,\n title: relatedItem.title,\n url: relatedItem.externalSource?.url ?? null,\n stages: relatedItem.stages,\n workItem: relatedItem.workItem,\n acceptedAt: relatedItem.acceptedAt,\n metadata: relatedItem.metadata,\n },\n board: boardForWorkItem(relatedItem),\n itemRevision: relatedItem.revision,\n ...withBoardClosure(boards, relatedItem),\n ...rulePhaseField(boards, relatedItem),\n }\n : {}),\n ...withIntakeTarget(boards),\n event,\n alert,\n };\n const boardEvent = boardEventFor(context);\n if (boardEvent) context.boardEvent = boardEvent;\n\n const rule = this.#rules[event];\n let decision: FactoryRuleDecision | void = undefined;\n let decisions: Record<string, unknown>[] = [];\n let outcome: { status: 'accepted' | 'rejected'; code?: string; reason?: string } = { status: 'accepted' };\n try {\n decision = rule ? await rule(Object.freeze(context)) : undefined;\n if (decision?.type === 'reject') {\n outcome = { status: 'rejected', code: decision.code, reason: decision.reason };\n } else if (decision) {\n decisions = validateFactoryRuleDecisions([decision]).map(entry => {\n assertFactoryDecisionTarget(entry, boards, relatedItem ? boardForWorkItem(relatedItem) : undefined);\n return { ...entry };\n });\n }\n } catch (error) {\n outcome = {\n status: 'rejected',\n code: 'rule_error',\n reason: error instanceof Error ? error.message.slice(0, 2_000) : 'Factory Dependabot rule failed.',\n };\n }\n if (!decision && outcome.status === 'accepted') {\n const routed = await routeEventDecision(context, this.options.storage, {\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n if (routed) decisions = [{ ...routed }];\n }\n\n const committed = await this.options.storage.commitRuleEvaluation({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n workItemId: relatedItem?.id ?? null,\n ingress: { identity: ingressId },\n expectedRevision: relatedItem?.revision ?? null,\n actor,\n outcome,\n decisions,\n causalChain: [],\n now: new Date(),\n });\n if (committed.status === 'stale') {\n if (attempt >= MAX_STALE_RULE_ATTEMPTS) {\n throw new Error(`Factory Dependabot rule evaluation for ${ingressId} kept losing revision races.`);\n }\n const fresh = relatedItem ? await this.options.storage.get({ orgId: input.orgId, id: relatedItem.id }) : null;\n if (relatedItem && !fresh) return 'missing';\n return this.#ingestAlert(input, alert, fresh ?? undefined, attempt + 1);\n }\n return committed.status;\n }\n}\n\nexport function attachDependabotRules(\n context: IntegrationContext,\n): ((input: DependabotRulesIngress) => Promise<unknown>) | undefined {\n if (!context.runtime) return undefined;\n const rules = new DependabotRules({\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n configVersion: context.runtime.configVersion,\n boards: context.runtime.boards,\n });\n return input => rules.ingest(input);\n}\n"],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AAY;GAAG,CAAC,IAAI;GACzG,IAAI,eAAe,CAAC,OAAO,OAAO;GAClC,OAAO,KAAK,aAAa,OAAO,OAAO,SAAS,KAAA,GAAW,UAAU,CAAC;EACxE;EACA,OAAO,UAAU;CACnB;AACF;AAEA,SAAgB,sBACd,SACmE;CACnE,IAAI,CAAC,QAAQ,SAAS,OAAO,KAAA;CAC7B,MAAM,QAAQ,IAAI,gBAAgB;EAChC,UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,QAAQ;EACzB,eAAe,QAAQ,QAAQ;EAC/B,QAAQ,QAAQ,QAAQ;CAC1B,CAAC;CACD,QAAO,UAAS,MAAM,OAAO,KAAK;AACpC"}
1
+ {"version":3,"file":"rules.js","names":[],"sources":["../../../src/integrations/dependabot/rules.ts"],"sourcesContent":["import { closeReason } from '../../boards/board-events.js';\nimport type { BoardEventFacts } from '../../boards/board-events.js';\nimport { boardForWorkItem, rulePhaseField, withBoardClosure, withIntakeTarget } from '../../boards/index.js';\nimport type { BoardRegistry } from '../../boards/index.js';\nimport { toBoardSource } from '../../boards/project-boards.js';\nimport type { ProjectBoardSource } from '../../boards/project-boards.js';\nimport { routeEventDecision } from '../../rules/event-rules.js';\nimport type { FactoryDependabotRuleContext, FactoryRuleDecision } from '../../rules/types.js';\nimport { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from '../../rules/validation.js';\nimport type { StoredBoardScope } from '../../storage/domains/boards/base.js';\nimport type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';\nimport type { Card, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { IntegrationContext } from '../base.js';\nimport { defaultDependabotRules, isClosedDependabotState } from './default-rules.js';\nimport type { DependabotEventRules } from './default-rules.js';\n\nconst MAX_STALE_RULE_ATTEMPTS = 3;\n\n/** Labels every Dependabot card carries, so intake routes can match them like any labeled issue. */\nexport function dependabotLabels(severity: string | null): string[] {\n return ['security', 'dependabot', ...(severity ? [`severity:${severity}`] : [])];\n}\n\nexport type DependabotAlertIngress = FactoryDependabotRuleContext['alert'];\n\nexport interface DependabotRulesOptions {\n projects: Pick<FactoryProjectsStorage, 'get'>;\n storage: WorkItemsStorage;\n configVersion: string;\n boards: BoardRegistry | ProjectBoardSource;\n rules?: DependabotEventRules;\n}\n\nexport interface DependabotRulesIngress {\n orgId: string;\n userId: string;\n factoryProjectId: string;\n alerts: DependabotAlertIngress[];\n}\n\ntype IngressStatus = 'committed' | 'replayed' | 'missing';\n\n/**\n * A first sighting of an open alert creates its card; a fixed or dismissed one closes it. An open\n * alert that already has a card reopens it, which the intake routes apply only to a finished card.\n */\nexport function boardEventFor(\n context: Pick<FactoryDependabotRuleContext, 'event' | 'alert' | 'item'>,\n): BoardEventFacts | undefined {\n if (context.event === 'alertClosed') {\n return { type: 'work_item.closed', reason: closeReason(context.alert.state !== 'fixed') };\n }\n return context.item ? { type: 'work_item.reopened' } : { type: 'work_item.opened' };\n}\n\nexport class DependabotRules {\n readonly #rules: DependabotEventRules;\n\n constructor(private readonly options: DependabotRulesOptions) {\n this.#rules = options.rules ?? defaultDependabotRules;\n }\n\n #boards(scope: StoredBoardScope): BoardRegistry {\n return toBoardSource(this.options.boards).forProject(scope);\n }\n\n async ingest(input: DependabotRulesIngress): Promise<{ status: IngressStatus; ingested: number }> {\n const project = await this.options.projects.get({ orgId: input.orgId, id: input.factoryProjectId });\n if (!project) return { status: 'missing', ingested: 0 };\n await toBoardSource(this.options.boards).load(input);\n\n const items = await this.options.storage.listShared({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n const itemsBySourceKey = new Map(\n items\n .filter(\n item => item.externalSource?.integrationId === 'github' && item.externalSource.type === 'dependabot-alert',\n )\n .map(item => [item.externalSource?.externalId, item]),\n );\n const statuses: IngressStatus[] = [];\n for (const alert of input.alerts) {\n const relatedItem = itemsBySourceKey.get(alert.id);\n statuses.push(await this.#ingestAlert(input, alert, relatedItem && structuredClone(relatedItem)));\n }\n if (statuses.includes('committed')) return { status: 'committed', ingested: statuses.length };\n if (statuses.includes('replayed')) return { status: 'replayed', ingested: statuses.length };\n return { status: 'missing', ingested: statuses.length };\n }\n\n async #ingestAlert(\n input: DependabotRulesIngress,\n alert: DependabotAlertIngress,\n relatedItem: Card | undefined,\n attempt = 1,\n ): Promise<IngressStatus> {\n const closed = isClosedDependabotState(alert.state);\n // A closed alert Factory never filed stays off the board.\n if (closed && !relatedItem) return 'missing';\n\n const ingressId = `dependabot:${alert.id}:${alert.state}:${alert.updatedAt}`;\n const actor = { type: 'human' as const, id: input.userId };\n const event = closed ? 'alertClosed' : 'alertObserved';\n const boards = this.#boards(input);\n const context: FactoryDependabotRuleContext = {\n tenant: { orgId: input.orgId, projectId: input.factoryProjectId },\n actor,\n ingress: { type: 'github', id: ingressId },\n cause: `dependabot.${event}`,\n causalChain: [],\n configVersion: this.options.configVersion,\n ...(relatedItem\n ? {\n item: {\n id: relatedItem.id,\n source: 'github-dependabot-alert',\n sourceKey: relatedItem.externalSource?.externalId ?? null,\n parentWorkItemId: relatedItem.parentWorkItemId,\n title: relatedItem.title,\n url: relatedItem.externalSource?.url ?? null,\n stages: relatedItem.stages,\n workItem: relatedItem.workItem,\n acceptedAt: relatedItem.acceptedAt,\n metadata: relatedItem.metadata,\n },\n board: boardForWorkItem(relatedItem),\n itemRevision: relatedItem.revision,\n ...withBoardClosure(boards, relatedItem),\n ...rulePhaseField(boards, relatedItem),\n }\n : {}),\n ...withIntakeTarget(boards),\n event,\n alert,\n };\n const boardEvent = boardEventFor(context);\n if (boardEvent) context.boardEvent = boardEvent;\n\n const rule = this.#rules[event];\n let decision: FactoryRuleDecision | void = undefined;\n let decisions: Record<string, unknown>[] = [];\n let outcome: { status: 'accepted' | 'rejected'; code?: string; reason?: string } = { status: 'accepted' };\n try {\n decision = rule ? await rule(Object.freeze(context)) : undefined;\n if (decision?.type === 'reject') {\n outcome = { status: 'rejected', code: decision.code, reason: decision.reason };\n } else if (decision) {\n decisions = validateFactoryRuleDecisions([decision]).map(entry => {\n assertFactoryDecisionTarget(entry, boards, relatedItem ? boardForWorkItem(relatedItem) : undefined);\n return { ...entry };\n });\n }\n } catch (error) {\n outcome = {\n status: 'rejected',\n code: 'rule_error',\n reason: error instanceof Error ? error.message.slice(0, 2_000) : 'Factory Dependabot rule failed.',\n };\n }\n if (!decision && outcome.status === 'accepted') {\n const routed = await routeEventDecision(context, this.options.storage, {\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n });\n if (routed) decisions = [{ ...routed }];\n }\n\n const committed = await this.options.storage.commitRuleEvaluation({\n orgId: input.orgId,\n factoryProjectId: input.factoryProjectId,\n workItemId: relatedItem?.id ?? null,\n ingress: { identity: ingressId },\n expectedRevision: relatedItem?.revision ?? null,\n actor,\n outcome,\n decisions,\n causalChain: [],\n now: new Date(),\n });\n if (committed.status === 'stale') {\n if (attempt >= MAX_STALE_RULE_ATTEMPTS) {\n throw new Error(`Factory Dependabot rule evaluation for ${ingressId} kept losing revision races.`);\n }\n const fresh = relatedItem ? await this.options.storage.get({ orgId: input.orgId, id: relatedItem.id }) : null;\n if (relatedItem && !fresh) return 'missing';\n return this.#ingestAlert(input, alert, fresh ?? undefined, attempt + 1);\n }\n return committed.status;\n }\n}\n\nexport function attachDependabotRules(\n context: IntegrationContext,\n): ((input: DependabotRulesIngress) => Promise<unknown>) | undefined {\n if (!context.runtime) return undefined;\n const rules = new DependabotRules({\n projects: context.storage.projects,\n storage: context.runtime.workItems,\n configVersion: context.runtime.configVersion,\n boards: context.runtime.boards,\n });\n return input => rules.ingest(input);\n}\n"],"mappings":";;;;;;;;AAgBA,MAAM,0BAA0B;;AAGhC,SAAgB,iBAAiB,UAAmC;CAClE,OAAO;EAAC;EAAY;EAAc,GAAI,WAAW,CAAC,YAAY,UAAU,IAAI,CAAC;CAAE;AACjF;;;;;AAyBA,SAAgB,cACd,SAC6B;CAC7B,IAAI,QAAQ,UAAU,eACpB,OAAO;EAAE,MAAM;EAAoB,QAAQ,YAAY,QAAQ,MAAM,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UAAU,QAAQ,QAAQ;EAC1B,SAAS,QAAQ,QAAQ;EACzB,eAAe,QAAQ,QAAQ;EAC/B,QAAQ,QAAQ,QAAQ;CAC1B,CAAC;CACD,QAAO,UAAS,MAAM,OAAO,KAAK;AACpC"}
@@ -137,7 +137,27 @@ export declare const defaultGithubRules: Readonly<{
137
137
  issueOpened: typeof issueOpened;
138
138
  issueEdited: null;
139
139
  issueClosed: typeof issueClosed;
140
- issueReopened: null;
140
+ issueReopened: (context: Readonly<FactoryGithubRuleContext>) => {
141
+ readonly type: 'upsertLinkedWorkItem';
142
+ readonly idempotencyKey: `${string}:issue-intake`;
143
+ readonly board: string;
144
+ readonly source: 'github-issue';
145
+ readonly sourceKey: string;
146
+ readonly title: string;
147
+ readonly url: string;
148
+ readonly stage: string;
149
+ readonly metadata: {
150
+ readonly githubRepositoryId: number;
151
+ readonly githubIssueNumber: number;
152
+ readonly sourceCreatedAt?: string | undefined;
153
+ readonly author?: string | undefined;
154
+ readonly state: "closed" | "open";
155
+ readonly authorTrusted: boolean;
156
+ readonly autoStartCandidate: boolean;
157
+ readonly assignees: string[];
158
+ readonly labels: string[];
159
+ };
160
+ } | undefined;
141
161
  issueCommentCreated: null;
142
162
  issueCommentEdited: null;
143
163
  issueCommentDeleted: null;
@@ -148,6 +168,7 @@ export declare const defaultGithubRules: Readonly<{
148
168
  pullRequestReviewSubmitted: typeof pullRequestReviewSubmitted;
149
169
  pullRequestMerged: typeof pullRequestMerged;
150
170
  pullRequestClosed: typeof pullRequestClosed;
171
+ pullRequestReopened: null;
151
172
  }>;
152
173
  export declare function resolveGithubRules(overrides?: GithubRuleOverrides): GithubEventRules;
153
174
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/default-rules.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAKjH,MAAM,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AAED,iBAAS,0BAA0B,CAAC,OAAO,EAAE,wBAAwB,wEA2BpE;AAED,eAAO,MAAM,kBAAkB;;;;;uBAhZrB,sBAAsB;;;yBAGpB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiaG,CAAC;AAE9B,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,CAgBpF"}
@@ -1,5 +1,6 @@
1
+ import { isOpenPullRequestSource, isPullRequestCard, pullRequestSourceNumber, pullRequestSources, reviewedPullRequest, trustedPullRequestSource, workingPullRequest } from "../../work-items/change-requests.js";
1
2
  import "../../boards/index.js";
2
- import { hasRecordedVerdict, isPullRequestCard, newestOpenPullRequestNumber, pullRequestSources, reviewedPullRequest, reviewsPullRequest } from "../../boards/semantics.js";
3
+ import { hasRecordedVerdict, reviewsPullRequest } from "../../boards/semantics.js";
3
4
  import { requestsChangesVerdict } from "../../review-verdict.js";
4
5
  import { closedByRoutes, pullRequestMoveByRoutes, recordExplicitRuleOverrides, routedOnly, unreviewedPullRequestCard } from "../../rules/event-rules.js";
5
6
  import { isRepositoryPullRequest } from "./pull-request-source.js";
@@ -40,6 +41,18 @@ function attachedPullRequest(context) {
40
41
  function isEventPullRequest(context, source) {
41
42
  return context.pullRequest !== void 0 && isRepositoryPullRequest(source, context.repository.id, context.repository.fullName, context.pullRequest.number);
42
43
  }
44
+ /**
45
+ * Whether the event's pull request is an outside author's, linked to the card, that no person
46
+ * has made the card's working pull request: nothing on the card may run its code.
47
+ */
48
+ function unpickedOutsiderPullRequest(context) {
49
+ const { item } = context;
50
+ if (!item || !attachedPullRequest(context) || context.pullRequest?.factoryAuthored) return false;
51
+ const source = pullRequestSources(item).find((candidate) => isEventPullRequest(context, candidate));
52
+ if (trustedPullRequestSource(item, source)) return false;
53
+ const working = workingPullRequest(item);
54
+ return working === void 0 || !isEventPullRequest(context, working);
55
+ }
43
56
  /** Whether the card's PR review covers the event's pull request: its own, or the attached one it reviews. */
44
57
  function reviewsThisPullRequest(context) {
45
58
  if (!context.item || !context.pullRequest || !reviewsPullRequest(context)) return false;
@@ -168,7 +181,8 @@ function pullRequestMerged(context) {
168
181
  });
169
182
  if (!authoringCard(context)) return;
170
183
  const recorded = context.item.metadata?.openPullRequestNumber;
171
- const openPullRequestNumber = typeof recorded === "number" ? recorded : newestOpenPullRequestNumber(context.item, context.pullRequest.number);
184
+ const working = workingPullRequest(context.item);
185
+ const openPullRequestNumber = typeof recorded === "number" ? recorded : working && isOpenPullRequestSource(working) ? pullRequestSourceNumber(working) : void 0;
172
186
  if (typeof openPullRequestNumber === "number" && openPullRequestNumber !== context.pullRequest.number) {
173
187
  const role = context.flow?.buildRole;
174
188
  if (!role) return;
@@ -249,7 +263,9 @@ function pullRequestClosed(context) {
249
263
  if (!isPullRequestCard(context.item)) {
250
264
  const initialPhase = context.flow?.initialPhase;
251
265
  if (!initialPhase || !attachedPullRequest(context) || !inPullRequestReview(context)) return;
252
- if (newestOpenPullRequestNumber(context.item, context.pullRequest.number) !== null) return;
266
+ if (unpickedOutsiderPullRequest(context)) return;
267
+ const other = workingPullRequest(context.item, context.pullRequest.number);
268
+ if (other && isOpenPullRequestSource(other)) return;
253
269
  return pullRequestMoveByRoutes("pull_request.closed", {
254
270
  idempotencyKey: `${context.ingress.id}:pull-request-closed`,
255
271
  board: context.board,
@@ -272,6 +288,7 @@ function reReviewRequestedPullRequest(context) {
272
288
  if (!context.pullRequest || context.pullRequest.state !== "open" || context.pullRequest.merged) return;
273
289
  if (!trustedGithubActor(context)) return;
274
290
  if (context.actor.type === "github" && context.actor.factoryAuthored) return;
291
+ if (unpickedOutsiderPullRequest(context)) return;
275
292
  if (!context.item) return materializePullRequestIntake(context, {
276
293
  idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,
277
294
  autoStartCandidate: true
@@ -308,7 +325,7 @@ const defaultGithubRules = Object.freeze({
308
325
  issueOpened,
309
326
  issueEdited: null,
310
327
  issueClosed,
311
- issueReopened: null,
328
+ issueReopened: (context) => context.item ? void 0 : issueOpened(context),
312
329
  issueCommentCreated: null,
313
330
  issueCommentEdited: null,
314
331
  issueCommentDeleted: null,
@@ -318,7 +335,8 @@ const defaultGithubRules = Object.freeze({
318
335
  pullRequestReviewRequested: reReviewRequestedPullRequest,
319
336
  pullRequestReviewSubmitted,
320
337
  pullRequestMerged,
321
- pullRequestClosed
338
+ pullRequestClosed,
339
+ pullRequestReopened: null
322
340
  });
323
341
  function resolveGithubRules(overrides) {
324
342
  if (overrides !== void 0 && (overrides === null || typeof overrides !== "object" || Array.isArray(overrides))) throw new Error("GitHub rules must be an object.");
@@ -1 +1 @@
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 default board's initial phase; the project's intake routes place\n // the card from there. Trust/timing stamps remain available to custom board 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 { idempotencyKey, autoStartCandidate }: { idempotencyKey: string; autoStartCandidate: boolean },\n) {\n const { intake } = context;\n if (!context.pullRequest || !intake) return;\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: intake.initialPhase,\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, so the project's pull request route sends it to review.\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,\n autoStartCandidate: 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,M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AAQ,GAAG;EACtC,OAAO,QAAQ;EACf;EAIA,GAAI,YAAY,EAAE,SAAS,KAAK,IAAI,CAAC;CACvC,CAAC;AACH;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 isOpenPullRequestSource,\n workingPullRequest,\n pullRequestSourceNumber,\n pullRequestSources,\n reviewedPullRequest,\n reviewsPullRequest,\n trustedPullRequestSource,\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/**\n * Whether the event's pull request is an outside author's, linked to the card, that no person\n * has made the card's working pull request: nothing on the card may run its code.\n */\nfunction unpickedOutsiderPullRequest(context: FactoryGithubRuleContext): boolean {\n const { item } = context;\n if (!item || !attachedPullRequest(context) || context.pullRequest?.factoryAuthored) return false;\n const source = pullRequestSources(item).find(candidate => isEventPullRequest(context, candidate))!;\n if (trustedPullRequestSource(item, source)) return false;\n const working = workingPullRequest(item);\n return working === undefined || !isEventPullRequest(context, working);\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 default board's initial phase; the project's intake routes place\n // the card from there. Trust/timing stamps remain available to custom board 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 { idempotencyKey, autoStartCandidate }: { idempotencyKey: string; autoStartCandidate: boolean },\n) {\n const { intake } = context;\n if (!context.pullRequest || !intake) return;\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: intake.initialPhase,\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. One that closes an issue on the board links to 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 its working one: the one it has out, else\n // the first trusted one linked. Merging that one, or any when the card has none, finishes it.\n const recorded = context.item.metadata?.openPullRequestNumber;\n const working = workingPullRequest(context.item);\n const openPullRequestNumber =\n typeof recorded === 'number'\n ? recorded\n : working && isOpenPullRequestSource(working)\n ? pullRequestSourceNumber(working)\n : undefined;\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 // An outsider closing a pull request nobody picked for the card settles nothing about it.\n if (unpickedOutsiderPullRequest(context)) return;\n const other = workingPullRequest(context.item, context.pullRequest.number);\n if (other && isOpenPullRequestSource(other)) 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 // A maintainer vouches for an outsider's pull request on an issue's card by making it the card's\n // working pull request (\"Use this pull request\"); a review request alone does not.\n if (unpickedOutsiderPullRequest(context)) 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, so the project's pull request route sends it to review.\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,\n autoStartCandidate: 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 // A reopened issue with no card is filed the way a new one is; one with a card goes to its routes.\n issueReopened: context => (context.item ? undefined : issueOpened(context)),\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 // A reopened pull request moves a card only where a route on its board names `pull_request.reopened`.\n pullRequestReopened: null,\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":";;;;;;;;AA+BA,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,eA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,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"}
@@ -0,0 +1,16 @@
1
+ import type { IntakeItemLookup } from '../../boards/intake-lookup.js';
2
+ import type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';
3
+ import type { GithubIssueFetcher, GithubPullRequestFetcher, GithubRulesIntegration } from './rules.js';
4
+ export interface GithubIntakeLookupDeps extends Pick<GithubRulesIntegration, 'getRepositoryCollaboratorPermission'> {
5
+ sourceControl(): SourceControlStorageHandle;
6
+ fetchIssueState: GithubIssueFetcher;
7
+ fetchPullRequestState: GithubPullRequestFetcher;
8
+ }
9
+ /**
10
+ * Reads a GitHub issue or pull request for the intake tester, only from a repository linked to the
11
+ * project and only through that link's installation. It builds the facts the webhook arrival would
12
+ * carry, with author trust from the author's repository access. Factory's own pull requests aren't
13
+ * recognized as Factory-authored here; they already have cards, which the tester reads first.
14
+ */
15
+ export declare function githubIntakeLookup(deps: GithubIntakeLookupDeps): IntakeItemLookup;
16
+ //# sourceMappingURL=intake-lookup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intake-lookup.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/intake-lookup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAKvG,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,sBAAsB,EAAE,qCAAqC,CAAC;IACjH,aAAa,IAAI,0BAA0B,CAAC;IAC5C,eAAe,EAAE,kBAAkB,CAAC;IACpC,qBAAqB,EAAE,wBAAwB,CAAC;CACjD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,gBAAgB,CAgEjF"}
@@ -0,0 +1,76 @@
1
+ import { cardRuleFacts } from "../../boards/card-facts.js";
2
+ import { externalSourceForWorkItem } from "../../rules/types.js";
3
+ import { trustedCollaborator } from "./rules.js";
4
+ // src/integrations/github/intake-lookup.ts
5
+ const GITHUB_ITEM_URL = /^https?:\/\/(?:www\.)?github\.com\/([^/]+)\/([^/]+)\/(issues|pull)\/(\d+)(?:[/?#].*)?$/i;
6
+ /**
7
+ * Reads a GitHub issue or pull request for the intake tester, only from a repository linked to the
8
+ * project and only through that link's installation. It builds the facts the webhook arrival would
9
+ * carry, with author trust from the author's repository access. Factory's own pull requests aren't
10
+ * recognized as Factory-authored here; they already have cards, which the tester reads first.
11
+ */
12
+ function githubIntakeLookup(deps) {
13
+ return { async lookup(scope, url) {
14
+ const match = GITHUB_ITEM_URL.exec(url.trim());
15
+ if (!match) return void 0;
16
+ const slug = `${match[1]}/${match[2]}`.toLowerCase();
17
+ const number = Number(match[4]);
18
+ const linked = (await deps.sourceControl().connections.listWithRepositories({
19
+ orgId: scope.orgId,
20
+ factoryProjectIds: [scope.factoryProjectId]
21
+ })).flatMap((connection) => connection.repositories.map((link) => ({
22
+ installation: connection.installation,
23
+ repository: link.repository
24
+ }))).find(({ repository }) => repository?.slug.toLowerCase() === slug);
25
+ if (!linked?.repository) return { status: "not_linked" };
26
+ const installationId = Number(linked.installation.externalId);
27
+ const repository = linked.repository.slug;
28
+ const read = {
29
+ installationId,
30
+ repository,
31
+ number
32
+ };
33
+ const issue = match[3]?.toLowerCase() === "issues" ? await deps.fetchIssueState(read) : void 0;
34
+ const asPullRequest = issue ? void 0 : await deps.fetchPullRequestState(read);
35
+ const item = issue ?? asPullRequest;
36
+ if (!item) return { status: "not_found" };
37
+ const author = item.author;
38
+ const trusted = author ? await trustedCollaborator(deps, {
39
+ installationId,
40
+ repository,
41
+ login: author
42
+ }).catch(() => false) : false;
43
+ const kind = asPullRequest ? "github-pr" : "github-issue";
44
+ const metadata = {
45
+ githubRepositoryId: Number(linked.repository.externalId),
46
+ ...asPullRequest ? { githubPullRequestNumber: number } : { githubIssueNumber: number },
47
+ ...item.createdAt ? { sourceCreatedAt: item.createdAt } : {},
48
+ ...author ? { author } : {},
49
+ state: item.state,
50
+ authorTrusted: trusted,
51
+ assignees: item.assignees ?? [],
52
+ labels: item.labels ?? [],
53
+ ...asPullRequest ? {
54
+ draft: asPullRequest.draft,
55
+ merged: asPullRequest.merged,
56
+ requestedReviewers: asPullRequest.requestedReviewers ?? [],
57
+ headBranch: asPullRequest.headBranch,
58
+ baseBranch: asPullRequest.baseBranch
59
+ } : {}
60
+ };
61
+ const sourceKey = `github:${linked.repository.externalId}:${asPullRequest ? "pull-request" : "issue"}:${number}`;
62
+ return {
63
+ status: "found",
64
+ title: item.title,
65
+ url: item.url,
66
+ facts: cardRuleFacts({
67
+ title: item.title,
68
+ metadata,
69
+ externalSource: externalSourceForWorkItem(kind, sourceKey, item.url)
70
+ })
71
+ };
72
+ } };
73
+ }
74
+ export { githubIntakeLookup };
75
+
76
+ //# sourceMappingURL=intake-lookup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intake-lookup.js","names":[],"sources":["../../../src/integrations/github/intake-lookup.ts"],"sourcesContent":["import { cardRuleFacts } from '../../boards/card-facts.js';\nimport type { IntakeItemLookup } from '../../boards/intake-lookup.js';\nimport { externalSourceForWorkItem } from '../../rules/types.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { GithubIssueFetcher, GithubPullRequestFetcher, GithubRulesIntegration } from './rules.js';\nimport { trustedCollaborator } from './rules.js';\n\nconst GITHUB_ITEM_URL = /^https?:\\/\\/(?:www\\.)?github\\.com\\/([^/]+)\\/([^/]+)\\/(issues|pull)\\/(\\d+)(?:[/?#].*)?$/i;\n\nexport interface GithubIntakeLookupDeps extends Pick<GithubRulesIntegration, 'getRepositoryCollaboratorPermission'> {\n sourceControl(): SourceControlStorageHandle;\n fetchIssueState: GithubIssueFetcher;\n fetchPullRequestState: GithubPullRequestFetcher;\n}\n\n/**\n * Reads a GitHub issue or pull request for the intake tester, only from a repository linked to the\n * project and only through that link's installation. It builds the facts the webhook arrival would\n * carry, with author trust from the author's repository access. Factory's own pull requests aren't\n * recognized as Factory-authored here; they already have cards, which the tester reads first.\n */\nexport function githubIntakeLookup(deps: GithubIntakeLookupDeps): IntakeItemLookup {\n return {\n async lookup(scope, url) {\n const match = GITHUB_ITEM_URL.exec(url.trim());\n if (!match) return undefined;\n const slug = `${match[1]}/${match[2]}`.toLowerCase();\n const number = Number(match[4]);\n const connections = await deps.sourceControl().connections.listWithRepositories({\n orgId: scope.orgId,\n factoryProjectIds: [scope.factoryProjectId],\n });\n const linked = connections\n .flatMap(connection =>\n connection.repositories.map(link => ({ installation: connection.installation, repository: link.repository })),\n )\n .find(({ repository }) => repository?.slug.toLowerCase() === slug);\n if (!linked?.repository) return { status: 'not_linked' };\n const installationId = Number(linked.installation.externalId);\n const repository = linked.repository.slug;\n const read = { installationId, repository, number };\n\n // An issue URL can name a pull request; GitHub redirects it, and the issue read refuses it.\n const issue = match[3]?.toLowerCase() === 'issues' ? await deps.fetchIssueState(read) : undefined;\n const asPullRequest = issue ? undefined : await deps.fetchPullRequestState(read);\n const item = issue ?? asPullRequest;\n if (!item) return { status: 'not_found' };\n\n const author = item.author;\n const trusted = author\n ? await trustedCollaborator(deps, { installationId, repository, login: author }).catch(() => false)\n : false;\n const kind = asPullRequest ? 'github-pr' : 'github-issue';\n const metadata: Record<string, unknown> = {\n githubRepositoryId: Number(linked.repository.externalId),\n ...(asPullRequest ? { githubPullRequestNumber: number } : { githubIssueNumber: number }),\n ...(item.createdAt ? { sourceCreatedAt: item.createdAt } : {}),\n ...(author ? { author } : {}),\n state: item.state,\n authorTrusted: trusted,\n assignees: item.assignees ?? [],\n labels: item.labels ?? [],\n ...(asPullRequest\n ? {\n draft: asPullRequest.draft,\n merged: asPullRequest.merged,\n requestedReviewers: asPullRequest.requestedReviewers ?? [],\n headBranch: asPullRequest.headBranch,\n baseBranch: asPullRequest.baseBranch,\n }\n : {}),\n };\n const sourceKey = `github:${linked.repository.externalId}:${asPullRequest ? 'pull-request' : 'issue'}:${number}`;\n return {\n status: 'found',\n title: item.title,\n url: item.url,\n facts: cardRuleFacts({\n title: item.title,\n metadata,\n externalSource: externalSourceForWorkItem(kind, sourceKey, item.url),\n }),\n };\n },\n };\n}\n"],"mappings":";;;;AAOA,MAAM,kBAAkB;;;;;;;AAcxB,SAAgB,mBAAmB,MAAgD;CACjF,OAAO,EACL,MAAM,OAAO,OAAO,KAAK;EACvB,MAAM,QAAQ,gBAAgB,KAAK,IAAI,KAAK,CAAC;EAC7C,IAAI,CAAC,OAAO,OAAO,KAAA;EACnB,MAAM,OAAO,GAAG,MAAM,GAAG,GAAG,MAAM,KAAK,YAAY;EACnD,MAAM,SAAS,OAAO,MAAM,EAAE;EAK9B,MAAM,UAAS,MAJW,KAAK,cAAc,CAAC,CAAC,YAAY,qBAAqB;GAC9E,OAAO,MAAM;GACb,mBAAmB,CAAC,MAAM,gBAAgB;EAC5C,CAAC,EAAA,CAEE,SAAQ,eACP,WAAW,aAAa,KAAI,UAAS;GAAE,cAAc,WAAW;GAAc,YAAY,KAAK;EAAW,EAAE,CAC9G,CAAC,CACA,MAAM,EAAE,iBAAiB,YAAY,KAAK,YAAY,MAAM,IAAI;EACnE,IAAI,CAAC,QAAQ,YAAY,OAAO,EAAE,QAAQ,aAAa;EACvD,MAAM,iBAAiB,OAAO,OAAO,aAAa,UAAU;EAC5D,MAAM,aAAa,OAAO,WAAW;EACrC,MAAM,OAAO;GAAE;GAAgB;GAAY;EAAO;EAGlD,MAAM,QAAQ,MAAM,EAAE,EAAE,YAAY,MAAM,WAAW,MAAM,KAAK,gBAAgB,IAAI,IAAI,KAAA;EACxF,MAAM,gBAAgB,QAAQ,KAAA,IAAY,MAAM,KAAK,sBAAsB,IAAI;EAC/E,MAAM,OAAO,SAAS;EACtB,IAAI,CAAC,MAAM,OAAO,EAAE,QAAQ,YAAY;EAExC,MAAM,SAAS,KAAK;EACpB,MAAM,UAAU,SACZ,MAAM,oBAAoB,MAAM;GAAE;GAAgB;GAAY,OAAO;EAAO,CAAC,CAAC,CAAC,YAAY,KAAK,IAChG;EACJ,MAAM,OAAO,gBAAgB,cAAc;EAC3C,MAAM,WAAoC;GACxC,oBAAoB,OAAO,OAAO,WAAW,UAAU;GACvD,GAAI,gBAAgB,EAAE,yBAAyB,OAAO,IAAI,EAAE,mBAAmB,OAAO;GACtF,GAAI,KAAK,YAAY,EAAE,iBAAiB,KAAK,UAAU,IAAI,CAAC;GAC5D,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;GAC3B,OAAO,KAAK;GACZ,eAAe;GACf,WAAW,KAAK,aAAa,CAAC;GAC9B,QAAQ,KAAK,UAAU,CAAC;GACxB,GAAI,gBACA;IACE,OAAO,cAAc;IACrB,QAAQ,cAAc;IACtB,oBAAoB,cAAc,sBAAsB,CAAC;IACzD,YAAY,cAAc;IAC1B,YAAY,cAAc;GAC5B,IACA,CAAC;EACP;EACA,MAAM,YAAY,UAAU,OAAO,WAAW,WAAW,GAAG,gBAAgB,iBAAiB,QAAQ,GAAG;EACxG,OAAO;GACL,QAAQ;GACR,OAAO,KAAK;GACZ,KAAK,KAAK;GACV,OAAO,cAAc;IACnB,OAAO,KAAK;IACZ;IACA,gBAAgB,0BAA0B,MAAM,WAAW,KAAK,GAAG;GACrE,CAAC;EACH;CACF,EACF;AACF"}
@@ -26,6 +26,7 @@ import type { RequestContext } from '@mastra/core/request-context';
26
26
  import type { ApiRoute } from '@mastra/core/server';
27
27
  import type { MastraWorker } from '@mastra/core/worker';
28
28
  import { Octokit } from '@octokit/rest';
29
+ import type { IntakeItemLookup } from '../../boards/intake-lookup.js';
29
30
  import type { Intake } from '../../capabilities/intake.js';
30
31
  import type { VersionControl } from '../../capabilities/version-control.js';
31
32
  import type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../base.js';
@@ -55,7 +56,20 @@ export interface RepoSummary {
55
56
  defaultBranch: string;
56
57
  private: boolean;
57
58
  installationId: number;
59
+ /** When the repository last received a push, for "most recent first" ordering. */
60
+ pushedAt?: string | null;
58
61
  }
62
+ /**
63
+ * Narrows a repository listing: `query` keeps names containing it, `limit`
64
+ * returns only that many, most recently pushed first. `fresh` skips caches.
65
+ */
66
+ export interface RepoListOptions {
67
+ fresh?: boolean;
68
+ query?: string;
69
+ limit?: number;
70
+ }
71
+ /** Repositories whose full name contains `query`, most recently pushed first, at most `limit`. */
72
+ export declare function narrowRepos(repos: RepoSummary[], query?: string, limit?: number): RepoSummary[];
59
73
  export interface GithubTriageCommentUpsertInput {
60
74
  installationId: number;
61
75
  repository: string;
@@ -124,6 +138,7 @@ export declare class GithubIntegration implements FactoryIntegration {
124
138
  /** Stable integration identifier (see `../factory-integration.ts`). */
125
139
  readonly id = "github";
126
140
  get rules(): GithubEventRules;
141
+ readonly intakeLookup: IntakeItemLookup;
127
142
  readonly intake: Intake;
128
143
  readonly versionControl: VersionControl;
129
144
  /**
@@ -168,12 +183,11 @@ export declare class GithubIntegration implements FactoryIntegration {
168
183
  */
169
184
  listUserInstallations(userToken: string): Promise<UserInstallation[]>;
170
185
  /**
171
- * List repos accessible to an installation (paginated). Always reads
172
- * GitHub directly, so `fresh` has nothing to bypass here.
186
+ * List repos accessible to an installation (paginated), narrowed by
187
+ * `query`/`limit`. Always reads GitHub directly, so `fresh` has nothing to
188
+ * bypass here.
173
189
  */
174
- listInstallationRepos(installationId: number, _options?: {
175
- fresh?: boolean;
176
- }): Promise<RepoSummary[]>;
190
+ listInstallationRepos(installationId: number, options?: RepoListOptions): Promise<RepoSummary[]>;
177
191
  /**
178
192
  * The authenticated user's permission level on a repo, through the
179
193
  * installation. `undefined` when the repo/user is not accessible.